ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / include / asm-ppc / ocp.h
1 /*
2  * ocp.h
3  *
4  *
5  *      Current Maintainer
6  *      Armin Kuster akuster@pacbell.net
7  *      Jan, 2002
8  *
9  *
10  *
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.
15  *
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.
26  *
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.
30  */
31
32 #ifdef __KERNEL__
33 #ifndef __OCP_H__
34 #define __OCP_H__
35
36 #include <linux/list.h>
37 #include <linux/config.h>
38 #include <linux/device.h>
39 #include <linux/errno.h>
40
41 #include <asm/ocp_ids.h>
42 #include <asm/mmu.h>            /* For phys_addr_t */
43 #undef DEBUG
44 /* #define DEBUG*/
45
46 #ifdef DEBUG
47 #define DBG(x...) printk(x)
48 #else
49 #define DBG(x...)
50 #endif
51
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 */
55 #define OCP_DEV_NA      -1
56 #define OCP_CPM_NA      0       /* No Clock or Power Management avaliable */
57
58 #define OCP_ANY_ID      (~0)
59
60
61 extern struct list_head ocp_root_buses;
62 extern struct list_head ocp_devices;
63
64 struct ocp_device_id {
65         unsigned int vendor, device;            /* Vendor and device ID or PCI_ANY_ID */
66         char name[16];
67         char desc[50];
68         unsigned long driver_data;              /* Data private to the driver */
69 };
70
71 struct func_info {
72         char name[16];
73         char desc[50];
74 };
75
76 struct ocp_def {
77         unsigned int vendor;
78         unsigned int device;
79         phys_addr_t paddr;
80         int irq;
81         unsigned long pm;
82 };
83
84
85 /* Struct for single ocp device managment */
86 struct ocp_device {
87         struct list_head global_list;
88         unsigned int    num;            /* instance of device */
89         char            name[80];       /* device name */
90         unsigned int vendor;
91         unsigned int device;
92         phys_addr_t paddr;
93         int irq;
94         unsigned long pm;
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,
99                                    and D3 being off. */
100         struct device dev;
101 };
102
103 struct ocp_driver {
104         struct list_head node;
105         char *name;
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;
114 };
115
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)
118
119 extern int ocp_register_driver(struct ocp_driver *drv);
120 extern void ocp_unregister_driver(struct ocp_driver *drv);
121
122 #define ocp_dev_g(n) list_entry(n, struct ocp_device, global_list)
123
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))
126
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.
130  */
131 static inline void *
132 ocp_get_drvdata(struct ocp_device *pdev)
133 {
134         return pdev->ocpdev;
135 }
136
137 static inline void
138 ocp_set_drvdata(struct ocp_device *pdev, void *data)
139 {
140         pdev->ocpdev = data;
141 }
142
143 /*
144  * a helper function which helps ensure correct pci_driver
145  * setup and cleanup for commonly-encountered hotplug/modular cases
146  *
147  * This MUST stay in a header, as it checks for -DMODULE
148  */
149 static inline int ocp_module_init(struct ocp_driver *drv)
150 {
151         int rc = ocp_register_driver(drv);
152
153         if (rc > 0)
154                 return 0;
155
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)
161         if (rc == 0)
162                 return 0;
163 #else
164         if (rc == 0)
165                 rc = -ENODEV;           
166 #endif
167
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);
171         
172         return rc;
173 }
174
175 #if defined (CONFIG_PM)
176 /*
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.
179  */
180 static inline void
181 ocp_force_power_off(struct ocp_device *odev)
182 {
183         mtdcr(DCRN_CPMFR, mfdcr(DCRN_CPMFR) | odev->pm);
184 }
185
186 static inline void
187 ocp_force_power_on(struct ocp_device *odev)
188 {
189         mtdcr(DCRN_CPMFR, mfdcr(DCRN_CPMFR) & ~odev->pm);
190 }
191 #else
192 #define ocp_force_power_off(x)  (void)(x)
193 #define ocp_force_power_on(x)   (void)(x)
194 #endif
195
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);
200
201 extern int ocp_generic_suspend(struct ocp_device *pdev, u32 state);
202 extern int ocp_generic_resume(struct ocp_device *pdev);
203
204 #endif                          /* __OCP_H__ */
205 #endif                          /* __KERNEL__ */