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 static int omap_bus_match(struct device *dev, struct device_driver *drv)
86 struct omap_dev *omapdev = OMAP_DEV(dev);
87 struct omap_driver *omapdrv = OMAP_DRV(drv);
89 return omapdev->devid == omapdrv->devid;
92 static int omap_bus_suspend(struct device *dev, u32 state)
94 struct omap_dev *omapdev = OMAP_DEV(dev);
95 struct omap_driver *omapdrv = OMAP_DRV(dev->driver);
98 if (omapdrv && omapdrv->suspend)
99 ret = omapdrv->suspend(omapdev, state);
103 static int omap_bus_resume(struct device *dev)
105 struct omap_dev *omapdev = OMAP_DEV(dev);
106 struct omap_driver *omapdrv = OMAP_DRV(dev->driver);
109 if (omapdrv && omapdrv->resume)
110 ret = omapdrv->resume(omapdev);
114 static int omap_device_probe(struct device *dev)
116 struct omap_dev *omapdev = OMAP_DEV(dev);
117 struct omap_driver *omapdrv = OMAP_DRV(dev->driver);
120 if (omapdrv && omapdrv->probe)
121 ret = omapdrv->probe(omapdev);
126 static int omap_device_remove(struct device *dev)
128 struct omap_dev *omapdev = OMAP_DEV(dev);
129 struct omap_driver *omapdrv = OMAP_DRV(dev->driver);
132 if (omapdrv && omapdrv->remove)
133 ret = omapdrv->remove(omapdev);
137 int omap_device_register(struct omap_dev *odev)
142 if (odev->busid < 0 || odev->busid >= OMAP_NR_BUSES) {
143 printk(KERN_ERR "%s: busid invalid: %s: bus: %i\n",
144 __FUNCTION__, odev->name, odev->busid);
148 odev->dev.parent = &omap_bus_devices[odev->busid];
149 odev->dev.bus = &omap_bus_types[odev->busid];
151 /* This is needed for USB OHCI to work */
153 odev->dev.dma_mask = odev->dma_mask;
155 if (odev->coherent_dma_mask)
156 odev->dev.coherent_dma_mask = odev->coherent_dma_mask;
158 snprintf(odev->dev.bus_id, BUS_ID_SIZE, "%s%u",
159 odev->name, odev->devid);
161 printk("Registering OMAP device '%s'. Parent at %s\n",
162 odev->dev.bus_id, odev->dev.parent->bus_id);
164 return device_register(&odev->dev);
167 void omap_device_unregister(struct omap_dev *odev)
170 device_unregister(&odev->dev);
173 int omap_driver_register(struct omap_driver *driver)
177 if (driver->busid < 0 || driver->busid >= OMAP_NR_BUSES) {
178 printk(KERN_ERR "%s: busid invalid: bus: %i device: %i\n",
179 __FUNCTION__, driver->busid, driver->devid);
183 driver->drv.probe = omap_device_probe;
184 driver->drv.remove = omap_device_remove;
185 driver->drv.bus = &omap_bus_types[driver->busid];
188 * driver_register calls bus_add_driver
190 ret = driver_register(&driver->drv);
195 void omap_driver_unregister(struct omap_driver *driver)
197 driver_unregister(&driver->drv);
200 static int __init omap_bus_init(void)
204 /* Initialize all OMAP virtual buses */
205 for (i = 0; i < OMAP_NR_BUSES; i++) {
206 ret = device_register(&omap_bus_devices[i]);
208 printk(KERN_ERR "Unable to register bus device %s\n",
209 omap_bus_devices[i].bus_id);
212 ret = bus_register(&omap_bus_types[i]);
214 printk(KERN_ERR "Unable to register bus %s\n",
215 omap_bus_types[i].name);
216 device_unregister(&omap_bus_devices[i]);
219 printk("OMAP virtual buses initialized\n");
224 static void __exit omap_bus_exit(void)
228 /* Unregister all OMAP virtual buses */
229 for (i = 0; i < OMAP_NR_BUSES; i++) {
230 bus_unregister(&omap_bus_types[i]);
231 device_unregister(&omap_bus_devices[i]);
235 postcore_initcall(omap_bus_init);
236 module_exit(omap_bus_exit);
238 MODULE_DESCRIPTION("Virtual bus for OMAP");
239 MODULE_LICENSE("GPL");
241 EXPORT_SYMBOL(omap_bus_types);
242 EXPORT_SYMBOL(omap_driver_register);
243 EXPORT_SYMBOL(omap_driver_unregister);
244 EXPORT_SYMBOL(omap_device_register);
245 EXPORT_SYMBOL(omap_device_unregister);