2 * PS3 device registration routines.
4 * Copyright (C) 2007 Sony Computer Entertainment Inc.
5 * Copyright 2007 Sony Corp.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <linux/delay.h>
22 #include <linux/freezer.h>
23 #include <linux/kernel.h>
24 #include <linux/kthread.h>
25 #include <linux/init.h>
27 #include <asm/firmware.h>
28 #include <asm/lv1call.h>
33 * ps3_setup_gelic_device - Setup and register a gelic device instance.
35 * Allocates memory for a struct ps3_system_bus_device instance, initialises the
36 * structure members, and registers the device instance with the system bus.
39 static int __init ps3_setup_gelic_device(
40 const struct ps3_repository_device *repo)
44 struct ps3_system_bus_device dev;
45 struct ps3_dma_region d_region;
48 pr_debug(" -> %s:%d\n", __func__, __LINE__);
50 BUG_ON(repo->bus_type != PS3_BUS_TYPE_SB);
51 BUG_ON(repo->dev_type != PS3_DEV_TYPE_SB_GELIC);
53 p = kzalloc(sizeof(struct layout), GFP_KERNEL);
60 p->dev.match_id = PS3_MATCH_ID_GELIC;
61 p->dev.dev_type = PS3_DEVICE_TYPE_SB;
62 p->dev.bus_id = repo->bus_id;
63 p->dev.dev_id = repo->dev_id;
64 p->dev.d_region = &p->d_region;
66 result = ps3_repository_find_interrupt(repo,
67 PS3_INTERRUPT_TYPE_EVENT_PORT, &p->dev.interrupt_id);
70 pr_debug("%s:%d ps3_repository_find_interrupt failed\n",
72 goto fail_find_interrupt;
75 BUG_ON(p->dev.interrupt_id != 0);
77 result = ps3_dma_region_init(&p->dev, p->dev.d_region, PS3_DMA_64K,
78 PS3_DMA_OTHER, NULL, 0);
81 pr_debug("%s:%d ps3_dma_region_init failed\n",
86 result = ps3_system_bus_device_register(&p->dev);
89 pr_debug("%s:%d ps3_system_bus_device_register failed\n",
91 goto fail_device_register;
94 pr_debug(" <- %s:%d\n", __func__, __LINE__);
102 pr_debug(" <- %s:%d: fail.\n", __func__, __LINE__);
106 static int __init_refok ps3_setup_uhc_device(
107 const struct ps3_repository_device *repo, enum ps3_match_id match_id,
108 enum ps3_interrupt_type interrupt_type, enum ps3_reg_type reg_type)
112 struct ps3_system_bus_device dev;
113 struct ps3_dma_region d_region;
114 struct ps3_mmio_region m_region;
119 pr_debug(" -> %s:%d\n", __func__, __LINE__);
121 BUG_ON(repo->bus_type != PS3_BUS_TYPE_SB);
122 BUG_ON(repo->dev_type != PS3_DEV_TYPE_SB_USB);
124 p = kzalloc(sizeof(struct layout), GFP_KERNEL);
131 p->dev.match_id = match_id;
132 p->dev.dev_type = PS3_DEVICE_TYPE_SB;
133 p->dev.bus_id = repo->bus_id;
134 p->dev.dev_id = repo->dev_id;
135 p->dev.d_region = &p->d_region;
136 p->dev.m_region = &p->m_region;
138 result = ps3_repository_find_interrupt(repo,
139 interrupt_type, &p->dev.interrupt_id);
142 pr_debug("%s:%d ps3_repository_find_interrupt failed\n",
144 goto fail_find_interrupt;
147 result = ps3_repository_find_reg(repo, reg_type,
151 pr_debug("%s:%d ps3_repository_find_reg failed\n",
156 result = ps3_dma_region_init(&p->dev, p->dev.d_region, PS3_DMA_64K,
157 PS3_DMA_INTERNAL, NULL, 0);
160 pr_debug("%s:%d ps3_dma_region_init failed\n",
165 result = ps3_mmio_region_init(&p->dev, p->dev.m_region, bus_addr, len,
169 pr_debug("%s:%d ps3_mmio_region_init failed\n",
174 result = ps3_system_bus_device_register(&p->dev);
177 pr_debug("%s:%d ps3_system_bus_device_register failed\n",
179 goto fail_device_register;
182 pr_debug(" <- %s:%d\n", __func__, __LINE__);
185 fail_device_register:
192 pr_debug(" <- %s:%d: fail.\n", __func__, __LINE__);
196 static int __init ps3_setup_ehci_device(
197 const struct ps3_repository_device *repo)
199 return ps3_setup_uhc_device(repo, PS3_MATCH_ID_EHCI,
200 PS3_INTERRUPT_TYPE_SB_EHCI, PS3_REG_TYPE_SB_EHCI);
203 static int __init ps3_setup_ohci_device(
204 const struct ps3_repository_device *repo)
206 return ps3_setup_uhc_device(repo, PS3_MATCH_ID_OHCI,
207 PS3_INTERRUPT_TYPE_SB_OHCI, PS3_REG_TYPE_SB_OHCI);
210 static int __init ps3_setup_vuart_device(enum ps3_match_id match_id,
211 unsigned int port_number)
215 struct ps3_system_bus_device dev;
218 pr_debug(" -> %s:%d: match_id %u, port %u\n", __func__, __LINE__,
219 match_id, port_number);
221 p = kzalloc(sizeof(struct layout), GFP_KERNEL);
226 p->dev.match_id = match_id;
227 p->dev.dev_type = PS3_DEVICE_TYPE_VUART;
228 p->dev.port_number = port_number;
230 result = ps3_system_bus_device_register(&p->dev);
233 pr_debug("%s:%d ps3_system_bus_device_register failed\n",
236 pr_debug(" <- %s:%d\n", __func__, __LINE__);
240 static int __init ps3_register_vuart_devices(void)
243 unsigned int port_number;
245 pr_debug(" -> %s:%d\n", __func__, __LINE__);
247 result = ps3_repository_read_vuart_av_port(&port_number);
249 port_number = 0; /* av default */
251 result = ps3_setup_vuart_device(PS3_MATCH_ID_AV_SETTINGS, port_number);
254 result = ps3_repository_read_vuart_sysmgr_port(&port_number);
256 port_number = 2; /* sysmgr default */
258 result = ps3_setup_vuart_device(PS3_MATCH_ID_SYSTEM_MANAGER,
262 pr_debug(" <- %s:%d\n", __func__, __LINE__);
266 static int __init ps3_register_sound_devices(void)
270 struct ps3_system_bus_device dev;
271 struct ps3_dma_region d_region;
272 struct ps3_mmio_region m_region;
275 pr_debug(" -> %s:%d\n", __func__, __LINE__);
277 p = kzalloc(sizeof(*p), GFP_KERNEL);
281 p->dev.match_id = PS3_MATCH_ID_SOUND;
282 p->dev.dev_type = PS3_DEVICE_TYPE_IOC0;
283 p->dev.d_region = &p->d_region;
284 p->dev.m_region = &p->m_region;
286 result = ps3_system_bus_device_register(&p->dev);
289 pr_debug("%s:%d ps3_system_bus_device_register failed\n",
292 pr_debug(" <- %s:%d\n", __func__, __LINE__);
296 static int __init ps3_register_graphics_devices(void)
300 struct ps3_system_bus_device dev;
303 pr_debug(" -> %s:%d\n", __func__, __LINE__);
305 p = kzalloc(sizeof(struct layout), GFP_KERNEL);
310 p->dev.match_id = PS3_MATCH_ID_GRAPHICS;
311 p->dev.dev_type = PS3_DEVICE_TYPE_IOC0;
313 result = ps3_system_bus_device_register(&p->dev);
316 pr_debug("%s:%d ps3_system_bus_device_register failed\n",
319 pr_debug(" <- %s:%d\n", __func__, __LINE__);
324 * ps3_register_repository_device - Register a device from the repositiory info.
328 static int ps3_register_repository_device(
329 const struct ps3_repository_device *repo)
333 switch (repo->dev_type) {
334 case PS3_DEV_TYPE_SB_GELIC:
335 result = ps3_setup_gelic_device(repo);
337 pr_debug("%s:%d ps3_setup_gelic_device failed\n",
341 case PS3_DEV_TYPE_SB_USB:
343 /* Each USB device has both an EHCI and an OHCI HC */
345 result = ps3_setup_ehci_device(repo);
348 pr_debug("%s:%d ps3_setup_ehci_device failed\n",
352 result = ps3_setup_ohci_device(repo);
355 pr_debug("%s:%d ps3_setup_ohci_device failed\n",
361 pr_debug("%s:%u: unsupported dev_type %u\n", __func__, __LINE__,
369 * ps3_probe_thread - Background repository probing at system startup.
371 * This implementation only supports background probing on a single bus.
374 static int ps3_probe_thread(void *data)
376 struct ps3_repository_device *repo = data;
378 unsigned int ms = 250;
380 pr_debug(" -> %s:%u: kthread started\n", __func__, __LINE__);
385 pr_debug("%s:%u: probing...\n", __func__, __LINE__);
388 result = ps3_repository_find_device(repo);
390 if (result == -ENODEV)
391 pr_debug("%s:%u: nothing new\n", __func__,
394 pr_debug("%s:%u: find device error.\n",
397 pr_debug("%s:%u: found device\n", __func__,
399 ps3_register_repository_device(repo);
400 ps3_repository_bump_device(repo);
405 pr_debug("%s:%u: ms %u\n", __func__, __LINE__, ms);
410 msleep_interruptible(ms);
412 /* An exponential backoff. */
415 } while (!kthread_should_stop());
417 pr_debug(" <- %s:%u: kthread finished\n", __func__, __LINE__);
423 * ps3_start_probe_thread - Starts the background probe thread.
427 static int __init ps3_start_probe_thread(enum ps3_bus_type bus_type)
430 struct task_struct *task;
431 static struct ps3_repository_device repo; /* must be static */
433 pr_debug(" -> %s:%d\n", __func__, __LINE__);
435 memset(&repo, 0, sizeof(repo));
437 repo.bus_type = bus_type;
439 result = ps3_repository_find_bus(repo.bus_type, 0, &repo.bus_index);
442 printk(KERN_ERR "%s: Cannot find bus (%d)\n", __func__, result);
446 result = ps3_repository_read_bus_id(repo.bus_index, &repo.bus_id);
449 printk(KERN_ERR "%s: read_bus_id failed %d\n", __func__,
454 task = kthread_run(ps3_probe_thread, &repo, "ps3-probe-%u", bus_type);
457 result = PTR_ERR(task);
458 printk(KERN_ERR "%s: kthread_run failed %d\n", __func__,
463 pr_debug(" <- %s:%d\n", __func__, __LINE__);
468 * ps3_register_devices - Probe the system and register devices found.
470 * A device_initcall() routine.
473 static int __init ps3_register_devices(void)
477 if (!firmware_has_feature(FW_FEATURE_PS3_LV1))
480 pr_debug(" -> %s:%d\n", __func__, __LINE__);
482 /* ps3_repository_dump_bus_info(); */
484 result = ps3_start_probe_thread(PS3_BUS_TYPE_STORAGE);
486 ps3_register_vuart_devices();
488 ps3_register_graphics_devices();
490 ps3_repository_find_devices(PS3_BUS_TYPE_SB,
491 ps3_register_repository_device);
493 ps3_register_sound_devices();
495 pr_debug(" <- %s:%d\n", __func__, __LINE__);
499 device_initcall(ps3_register_devices);