2 * linux/arch/arm/mach-omap/bus.c
4 * Virtual bus for OMAP. Allows better power management, such as managing
5 * shared clocks, and mapping of bus addresses to Local Bus addresses.
7 * See drivers/usb/host/ohci-omap.c or drivers/video/omap/omapfb.c for
8 * examples on how to register drivers to this bus.
10 * Copyright (C) 2003 - 2004 Nokia Corporation
11 * Written by Tony Lindgren <tony@atomide.com>
12 * Portions of code based on sa1111.c.
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include <linux/config.h>
30 #include <linux/module.h>
31 #include <linux/init.h>
32 #include <linux/kernel.h>
33 #include <linux/delay.h>
34 #include <linux/ptrace.h>
35 #include <linux/errno.h>
36 #include <linux/ioport.h>
37 #include <linux/device.h>
38 #include <linux/slab.h>
39 #include <linux/spinlock.h>
41 #include <asm/hardware.h>
42 #include <asm/mach-types.h>
45 #include <asm/mach/irq.h>
47 #include <asm/arch/bus.h>
49 static int omap_bus_match(struct device *_dev, struct device_driver *_drv);
50 static int omap_bus_suspend(struct device *dev, u32 state);
51 static int omap_bus_resume(struct device *dev);
54 * OMAP bus definitions
56 * NOTE: Most devices should use TIPB. LBUS does automatic address mapping
57 * to Local Bus addresses, and should only be used for Local Bus devices.
58 * We may add new buses later on for power management reasons. Basically
59 * we want to be able to turn off any bus if it's not used by device
62 static struct device omap_bus_devices[OMAP_NR_BUSES] = {
64 .bus_id = OMAP_BUS_NAME_TIPB
66 .bus_id = OMAP_BUS_NAME_LBUS
70 static struct bus_type omap_bus_types[OMAP_NR_BUSES] = {
72 .name = OMAP_BUS_NAME_TIPB,
73 .match = omap_bus_match,
74 .suspend = omap_bus_suspend,
75 .resume = omap_bus_resume,
77 .name = OMAP_BUS_NAME_LBUS, /* Local bus on 1510 */
78 .match = omap_bus_match,
79 .suspend = omap_bus_suspend,
80 .resume = omap_bus_resume,
84 #ifdef CONFIG_ARCH_OMAP1510
86 * NOTE: This code _should_ go somewhere else. But let's wait for the
87 * dma-mapping code to settle down first.
91 * Test for Local Bus device in order to do address translation between
92 * dma_handle and Local Bus address.
94 inline int dmadev_uses_omap_lbus(struct device * dev)
96 if (dev == NULL || !cpu_is_omap1510())
98 return dev->bus == &omap_bus_types[OMAP_BUS_LBUS] ? 1 : 0;
102 * Translate bus address to Local Bus address for dma-mapping
104 inline int dmadev_to_lbus(dma_addr_t addr)
106 return bus_to_lbus(addr);
110 * Translate Local Bus address to bus address for dma-mapping
112 inline int lbus_to_dmadev(dma_addr_t addr)
114 return lbus_to_bus(addr);
118 static int omap_bus_match(struct device *dev, struct device_driver *drv)
120 struct omap_dev *omapdev = OMAP_DEV(dev);
121 struct omap_driver *omapdrv = OMAP_DRV(drv);
123 return omapdev->devid == omapdrv->devid;
126 static int omap_bus_suspend(struct device *dev, u32 state)
128 struct omap_dev *omapdev = OMAP_DEV(dev);
129 struct omap_driver *omapdrv = OMAP_DRV(dev->driver);
132 if (omapdrv && omapdrv->suspend)
133 ret = omapdrv->suspend(omapdev, state);
137 static int omap_bus_resume(struct device *dev)
139 struct omap_dev *omapdev = OMAP_DEV(dev);
140 struct omap_driver *omapdrv = OMAP_DRV(dev->driver);
143 if (omapdrv && omapdrv->resume)
144 ret = omapdrv->resume(omapdev);
148 static int omap_device_probe(struct device *dev)
150 struct omap_dev *omapdev = OMAP_DEV(dev);
151 struct omap_driver *omapdrv = OMAP_DRV(dev->driver);
154 if (omapdrv && omapdrv->probe)
155 ret = omapdrv->probe(omapdev);
160 static int omap_device_remove(struct device *dev)
162 struct omap_dev *omapdev = OMAP_DEV(dev);
163 struct omap_driver *omapdrv = OMAP_DRV(dev->driver);
166 if (omapdrv && omapdrv->remove)
167 ret = omapdrv->remove(omapdev);
171 int omap_device_register(struct omap_dev *odev)
176 if (odev->busid < 0 || odev->busid >= OMAP_NR_BUSES) {
177 printk(KERN_ERR "%s: busid invalid: %s: bus: %i\n",
178 __FUNCTION__, odev->name, odev->busid);
182 odev->dev.parent = &omap_bus_devices[odev->busid];
183 odev->dev.bus = &omap_bus_types[odev->busid];
185 /* This is needed for USB OHCI to work */
187 odev->dev.dma_mask = odev->dma_mask;
189 if (odev->coherent_dma_mask)
190 odev->dev.coherent_dma_mask = odev->coherent_dma_mask;
192 snprintf(odev->dev.bus_id, BUS_ID_SIZE, "%s%u",
193 odev->name, odev->devid);
195 printk("Registering OMAP device '%s'. Parent at %s\n",
196 odev->dev.bus_id, odev->dev.parent->bus_id);
198 return device_register(&odev->dev);
201 void omap_device_unregister(struct omap_dev *odev)
204 device_unregister(&odev->dev);
207 int omap_driver_register(struct omap_driver *driver)
211 if (driver->busid < 0 || driver->busid >= OMAP_NR_BUSES) {
212 printk(KERN_ERR "%s: busid invalid: bus: %i device: %i\n",
213 __FUNCTION__, driver->busid, driver->devid);
217 driver->drv.probe = omap_device_probe;
218 driver->drv.remove = omap_device_remove;
219 driver->drv.bus = &omap_bus_types[driver->busid];
222 * driver_register calls bus_add_driver
224 ret = driver_register(&driver->drv);
229 void omap_driver_unregister(struct omap_driver *driver)
231 driver_unregister(&driver->drv);
234 static int __init omap_bus_init(void)
238 /* Initialize all OMAP virtual buses */
239 for (i = 0; i < OMAP_NR_BUSES; i++) {
240 ret = device_register(&omap_bus_devices[i]);
242 printk(KERN_ERR "Unable to register bus device %s\n",
243 omap_bus_devices[i].bus_id);
246 ret = bus_register(&omap_bus_types[i]);
248 printk(KERN_ERR "Unable to register bus %s\n",
249 omap_bus_types[i].name);
250 device_unregister(&omap_bus_devices[i]);
253 printk("OMAP virtual buses initialized\n");
258 static void __exit omap_bus_exit(void)
262 /* Unregister all OMAP virtual buses */
263 for (i = 0; i < OMAP_NR_BUSES; i++) {
264 bus_unregister(&omap_bus_types[i]);
265 device_unregister(&omap_bus_devices[i]);
269 postcore_initcall(omap_bus_init);
270 module_exit(omap_bus_exit);
272 MODULE_DESCRIPTION("Virtual bus for OMAP");
273 MODULE_LICENSE("GPL");
275 EXPORT_SYMBOL(omap_bus_types);
276 EXPORT_SYMBOL(omap_driver_register);
277 EXPORT_SYMBOL(omap_driver_unregister);
278 EXPORT_SYMBOL(omap_device_register);
279 EXPORT_SYMBOL(omap_device_unregister);
281 #ifdef CONFIG_ARCH_OMAP1510
282 EXPORT_SYMBOL(dmadev_uses_omap_lbus);
283 EXPORT_SYMBOL(dmadev_to_lbus);
284 EXPORT_SYMBOL(lbus_to_dmadev);