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>
44 #include <asm/mach/irq.h>
46 #include <asm/arch/bus.h>
48 static int omap_bus_match(struct device *_dev, struct device_driver *_drv);
49 static int omap_bus_suspend(struct device *dev, u32 state);
50 static int omap_bus_resume(struct device *dev);
53 * OMAP bus definitions
55 * NOTE: Most devices should use TIPB. LBUS does automatic address mapping
56 * to Local Bus addresses, and should only be used for Local Bus devices.
57 * We may add new buses later on for power management reasons. Basically
58 * we want to be able to turn off any bus if it's not used by device
61 static struct device omap_bus_devices[OMAP_NR_BUSES] = {
63 .bus_id = OMAP_BUS_NAME_TIPB
65 .bus_id = OMAP_BUS_NAME_LBUS
69 static struct bus_type omap_bus_types[OMAP_NR_BUSES] = {
71 .name = OMAP_BUS_NAME_TIPB,
72 .match = omap_bus_match,
73 .suspend = omap_bus_suspend,
74 .resume = omap_bus_resume,
76 .name = OMAP_BUS_NAME_LBUS, /* Local bus on 1510 */
77 .match = omap_bus_match,
78 .suspend = omap_bus_suspend,
79 .resume = omap_bus_resume,
83 #ifdef CONFIG_ARCH_OMAP1510
85 * NOTE: This code _should_ go somewhere else. But let's wait for the
86 * dma-mapping code to settle down first.
90 * Test for Local Bus device in order to do address translation between
91 * dma_handle and Local Bus address.
93 inline int dmadev_uses_omap_lbus(struct device * dev)
95 if (dev == NULL || !cpu_is_omap1510())
97 return dev->bus == &omap_bus_types[OMAP_BUS_LBUS] ? 1 : 0;
101 * Translate bus address to Local Bus address for dma-mapping
103 inline int dmadev_to_lbus(dma_addr_t addr)
105 return bus_to_lbus(addr);
109 * Translate Local Bus address to bus address for dma-mapping
111 inline int lbus_to_dmadev(dma_addr_t addr)
113 return lbus_to_bus(addr);
117 static int omap_bus_match(struct device *dev, struct device_driver *drv)
119 struct omap_dev *omapdev = OMAP_DEV(dev);
120 struct omap_driver *omapdrv = OMAP_DRV(drv);
122 return omapdev->devid == omapdrv->devid;
125 static int omap_bus_suspend(struct device *dev, u32 state)
127 struct omap_dev *omapdev = OMAP_DEV(dev);
128 struct omap_driver *omapdrv = OMAP_DRV(dev->driver);
131 if (omapdrv && omapdrv->suspend)
132 ret = omapdrv->suspend(omapdev, state);
136 static int omap_bus_resume(struct device *dev)
138 struct omap_dev *omapdev = OMAP_DEV(dev);
139 struct omap_driver *omapdrv = OMAP_DRV(dev->driver);
142 if (omapdrv && omapdrv->resume)
143 ret = omapdrv->resume(omapdev);
147 static int omap_device_probe(struct device *dev)
149 struct omap_dev *omapdev = OMAP_DEV(dev);
150 struct omap_driver *omapdrv = OMAP_DRV(dev->driver);
153 if (omapdrv && omapdrv->probe)
154 ret = omapdrv->probe(omapdev);
159 static int omap_device_remove(struct device *dev)
161 struct omap_dev *omapdev = OMAP_DEV(dev);
162 struct omap_driver *omapdrv = OMAP_DRV(dev->driver);
165 if (omapdrv && omapdrv->remove)
166 ret = omapdrv->remove(omapdev);
170 int omap_device_register(struct omap_dev *odev)
175 if (odev->busid < 0 || odev->busid >= OMAP_NR_BUSES) {
176 printk(KERN_ERR "%s: busid invalid: %s: bus: %i\n",
177 __FUNCTION__, odev->name, odev->busid);
181 odev->dev.parent = &omap_bus_devices[odev->busid];
182 odev->dev.bus = &omap_bus_types[odev->busid];
184 /* This is needed for USB OHCI to work */
186 odev->dev.dma_mask = odev->dma_mask;
188 if (odev->coherent_dma_mask)
189 odev->dev.coherent_dma_mask = odev->coherent_dma_mask;
191 snprintf(odev->dev.bus_id, BUS_ID_SIZE, "%s%u",
192 odev->name, odev->devid);
194 printk("Registering OMAP device '%s'. Parent at %s\n",
195 odev->dev.bus_id, odev->dev.parent->bus_id);
197 return device_register(&odev->dev);
200 void omap_device_unregister(struct omap_dev *odev)
203 device_unregister(&odev->dev);
206 int omap_driver_register(struct omap_driver *driver)
210 if (driver->busid < 0 || driver->busid >= OMAP_NR_BUSES) {
211 printk(KERN_ERR "%s: busid invalid: bus: %i device: %i\n",
212 __FUNCTION__, driver->busid, driver->devid);
216 driver->drv.probe = omap_device_probe;
217 driver->drv.remove = omap_device_remove;
218 driver->drv.bus = &omap_bus_types[driver->busid];
221 * driver_register calls bus_add_driver
223 ret = driver_register(&driver->drv);
228 void omap_driver_unregister(struct omap_driver *driver)
230 driver_unregister(&driver->drv);
233 static int __init omap_bus_init(void)
237 /* Initialize all OMAP virtual buses */
238 for (i = 0; i < OMAP_NR_BUSES; i++) {
239 ret = device_register(&omap_bus_devices[i]);
241 printk(KERN_ERR "Unable to register bus device %s\n",
242 omap_bus_devices[i].bus_id);
245 ret = bus_register(&omap_bus_types[i]);
247 printk(KERN_ERR "Unable to register bus %s\n",
248 omap_bus_types[i].name);
249 device_unregister(&omap_bus_devices[i]);
252 printk("OMAP virtual buses initialized\n");
257 static void __exit omap_bus_exit(void)
261 /* Unregister all OMAP virtual buses */
262 for (i = 0; i < OMAP_NR_BUSES; i++) {
263 bus_unregister(&omap_bus_types[i]);
264 device_unregister(&omap_bus_devices[i]);
268 module_init(omap_bus_init);
269 module_exit(omap_bus_exit);
271 MODULE_DESCRIPTION("Virtual bus for OMAP");
272 MODULE_LICENSE("GPL");
274 EXPORT_SYMBOL(omap_bus_types);
275 EXPORT_SYMBOL(omap_driver_register);
276 EXPORT_SYMBOL(omap_driver_unregister);
277 EXPORT_SYMBOL(omap_device_register);
278 EXPORT_SYMBOL(omap_device_unregister);
280 #ifdef CONFIG_ARCH_OMAP1510
281 EXPORT_SYMBOL(dmadev_uses_omap_lbus);
282 EXPORT_SYMBOL(dmadev_to_lbus);
283 EXPORT_SYMBOL(lbus_to_dmadev);