6 * Armin Kuster akuster@pacbell.net
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
19 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
22 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
23 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 * You should have received a copy of the GNU General Public License along
28 * with this program; if not, write to the Free Software Foundation, Inc.,
29 * 675 Mass Ave, Cambridge, MA 02139, USA.
36 #include <linux/list.h>
37 #include <linux/config.h>
38 #include <linux/device.h>
39 #include <linux/errno.h>
41 #include <asm/ocp_ids.h>
42 #include <asm/mmu.h> /* For phys_addr_t */
47 #define DBG(x...) printk(x)
52 #define OCP_IRQ_NA -1 /* used when ocp device does not have an irq */
53 #define OCP_IRQ_MUL -2 /* used for ocp devices with multiple irqs */
54 #define OCP_NULL_TYPE 0 /* used to mark end of list */
56 #define OCP_CPM_NA 0 /* No Clock or Power Management avaliable */
58 #define OCP_ANY_ID (~0)
61 extern struct list_head ocp_root_buses;
62 extern struct list_head ocp_devices;
64 struct ocp_device_id {
65 unsigned int vendor, device; /* Vendor and device ID or PCI_ANY_ID */
68 unsigned long driver_data; /* Data private to the driver */
85 /* Struct for single ocp device managment */
87 struct list_head global_list;
88 unsigned int num; /* instance of device */
89 char name[80]; /* device name */
95 void *ocpdev; /* driver data for this device */
96 struct ocp_driver *driver;
97 u32 current_state; /* Current operating state. In ACPI-speak,
98 this is D0-D3, D0 being fully functional,
104 struct list_head node;
106 const struct ocp_device_id *id_table; /* NULL if wants all devices */
107 int (*probe) (struct ocp_device *dev); /* New device inserted */
108 void (*remove) (struct ocp_device *dev); /* Device removed (NULL if not a hot-plug capable driver) */
109 int (*save_state) (struct ocp_device *dev, u32 state); /* Save Device Context */
110 int (*suspend) (struct ocp_device *dev, u32 state); /* Device suspended */
111 int (*resume) (struct ocp_device *dev); /* Device woken up */
112 int (*enable_wake) (struct ocp_device *dev, u32 state, int enable); /* Enable wake event */
113 struct device_driver driver;
116 #define to_ocp_dev(n) container_of(n, struct ocp_device, dev)
117 #define to_ocp_driver(n) container_of(n, struct ocp_driver, driver)
119 extern int ocp_register_driver(struct ocp_driver *drv);
120 extern void ocp_unregister_driver(struct ocp_driver *drv);
122 #define ocp_dev_g(n) list_entry(n, struct ocp_device, global_list)
124 #define ocp_for_each_dev(dev) \
125 for(dev = ocp_dev_g(ocp_devices.next); dev != ocp_dev_g(&ocp_devices); dev = ocp_dev_g(dev->global_list.next))
127 /* Similar to the helpers above, these manipulate per-ocp_dev
128 * driver-specific data. Currently stored as ocp_dev::ocpdev,
129 * a void pointer, but it is not present on older kernels.
132 ocp_get_drvdata(struct ocp_device *pdev)
138 ocp_set_drvdata(struct ocp_device *pdev, void *data)
144 * a helper function which helps ensure correct pci_driver
145 * setup and cleanup for commonly-encountered hotplug/modular cases
147 * This MUST stay in a header, as it checks for -DMODULE
149 static inline int ocp_module_init(struct ocp_driver *drv)
151 int rc = ocp_register_driver(drv);
156 /* iff CONFIG_HOTPLUG and built into kernel, we should
157 * leave the driver around for future hotplug events.
158 * For the module case, a hotplug daemon of some sort
159 * should load a module in response to an insert event. */
160 #if defined(CONFIG_HOTPLUG) && !defined(MODULE)
168 /* if we get here, we need to clean up pci driver instance
169 * and return some sort of error */
170 ocp_unregister_driver (drv);
175 #if defined (CONFIG_PM)
177 * This is right for the IBM 405 and 440 but will need to be
178 * generalized if the OCP stuff gets used on other processors.
181 ocp_force_power_off(struct ocp_device *odev)
183 mtdcr(DCRN_CPMFR, mfdcr(DCRN_CPMFR) | odev->pm);
187 ocp_force_power_on(struct ocp_device *odev)
189 mtdcr(DCRN_CPMFR, mfdcr(DCRN_CPMFR) & ~odev->pm);
192 #define ocp_force_power_off(x) (void)(x)
193 #define ocp_force_power_on(x) (void)(x)
196 extern void ocp_init(void);
197 extern struct bus_type ocp_bus_type;
198 extern struct ocp_device *ocp_get_dev(unsigned int device, int index);
199 extern unsigned int ocp_get_num(unsigned int device);
201 extern int ocp_generic_suspend(struct ocp_device *pdev, u32 state);
202 extern int ocp_generic_resume(struct ocp_device *pdev);
204 #endif /* __OCP_H__ */
205 #endif /* __KERNEL__ */