4 * The is drived from pci.c
7 * Armin Kuster akuster@pacbell.net
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version.
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
20 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * You should have received a copy of the GNU General Public License along
29 * with this program; if not, write to the Free Software Foundation, Inc.,
30 * 675 Mass Ave, Cambridge, MA 02139, USA.
32 * Version 1.0 (02/01/26) - A. Kuster
35 * Version 1.1 (04/19/02) - A. kuster
36 * added the ability to give # of emacs and return count
37 * added the addr & irq routines that were in *_enet.c
38 * improved ocp_register
40 * created ocp_dev_count & get_ocp_dev
42 * Version 1.2 (4/22/02) - Armin
43 * added UART,I2C USB & IDE reg support
44 * vaddr is now ioremapped
46 * Version 1.3 (04/25/02) - Armin/Todd
48 * bug fixes - ifndef's
49 * Vesrion 1.4 (05/03/02) - Armin
50 * fixed ghost reg when ocp_reg fails , Idea from David Mueller
51 * added ocp_get_max used by ocp_dev_count
52 * ocp_reg and get_ocp_dev call ocp_dev_count
53 * removed need for ifndefs
54 * Added use of core_ocp[]
56 * added api descriptions
57 * name change to <class>_<action>_<obj>
58 * added ocp_type_info for name, short desciption and size
60 * Version 1.5 - Armin/David Gibson
61 * added most of David ocp patch to cleanup some of the
66 #include <linux/list.h>
67 #include <linux/module.h>
68 #include <linux/config.h>
69 #include <linux/miscdevice.h>
70 #include <linux/slab.h>
71 #include <linux/types.h>
74 #include <asm/errno.h>
78 extern struct ocp_def core_ocp[];
80 struct type_info ocp_type_info[] = {
82 {"gpt", "General purpose timers"},
83 {"uart", "NS16550 compatable serial device"},
86 {"gpio", "Gernal purpose I/O"},
87 {"emac", "10/100 BaseT ethernet"},
88 {"zmii", "ZMII bridge"},
89 {"ide", "Independent Disk"},
91 {"sci", "Smart card"},
92 {"audio", "Sound interface"},
93 {"ssp", "Sync serail port"},
94 {"scp", "Serial Controller port"},
95 {"scc", "Serial controller"},
96 {"video", "General Video"},
97 {"dma", "Dynamic memory allocation"},
98 {"uic", "Universal Interrupt controller"},
99 {"rtc", "Real Time Clock"},
100 {"led", "Light Emitting diode"}
105 * ocp_get_max - get max for ocp type
106 * @type: OCP type such as PCI, GPT, UART, OPB, IIC, GPIO, EMAC, ZMII,
108 * The routine returns max number of type that a given core supports
111 ocp_get_max(int type)
114 for (i = 0, max = 0; core_ocp[i].type != OCP_NULL_TYPE; i++) {
115 if (type == core_ocp[i].type)
122 * get_ocp_irq - get irq for ocp type and instance of it
123 * @type: OCP type such as PCI, GPT, UART, OPB, IIC, GPIO, EMAC, ZMII,
124 * @dev_num: ocp device number whos paddr you want
126 * The routine returns the valid irq, OCP_IRQ_NA or OCP_IRQ_MUL
127 * of type and instance requested
130 ocp_get_irq(int type, int dev_num)
135 for (i = 0; core_ocp[i].type != OCP_NULL_TYPE; i++) {
136 if (type == core_ocp[i].type) {
138 return (core_ocp[i].irq);
149 * ocp_get_paddr - get phyical address for ocp type and instance of it
150 * @type: OCP type such as PCI, GPT, UART, OPB, IIC, GPIO, EMAC, ZMII
151 * @dev_num: ocp device number whos paddr you want
153 * The routine returns paddr of type requested and it's instance or
157 ocp_get_paddr(int type, int dev_num)
162 for (i = 0; core_ocp[i].type != OCP_NULL_TYPE; i++) {
163 if (type == core_ocp[i].type) {
165 return ((unsigned long) core_ocp[i].paddr);
174 * ocp_get_pm - get pm for ocp type and instance of it
175 * @type: OCP type such as PCI, GPT, UART, OPB, IIC, GPIO, EMAC, ZMII,
176 * @dev_num: ocp device number whos power managment
179 * The routine returns the power management value or OCP_CPM_NA,
180 * of type and instance requested
183 ocp_get_pm(int type, int dev_num)
188 for (i = 0; core_ocp[i].type != OCP_NULL_TYPE; i++) {
189 if (type == core_ocp[i].type) {
191 return (core_ocp[i].cpm);
200 /* this sets the irq,paddr and anme to the device */
202 ocp_set_dev(struct ocp_dev *ocp)
207 strcpy(ocp->name, ocp_type_info[ocp->type].name);
209 for (i = 0; core_ocp[i].type != OCP_NULL_TYPE; i++) {
210 if (ocp->type == core_ocp[i].type) {
212 ocp->paddr = core_ocp[i].paddr;
213 ocp->irq = core_ocp[i].irq;
222 ocp->irq = OCP_IRQ_NA;
227 * ocp_get_numtypes - This determines how many OCP devices of a givrn
228 * type are registered
229 * @type: OCP type such as PCI, GPT, UART, OPB, IIC, GPIO, EMAC, ZMII,
231 * The routine returns number of types are registered
234 ocp_get_numtypes(int type)
238 struct list_head *ocp_l;
240 list_for_each(ocp_l, &ocp_list) {
241 ocp = list_entry(ocp_l, struct ocp_dev, ocp_list);
242 if (type == ocp->type)
250 * ocp_alloc_dev - alloc space for ocp driver
251 * @sizeof_ocpdev: size of the device structure
253 * The routine returns a valid 32 bit aligned
254 * points the sizeof ocp_struct and the
255 * requested device structure
258 ocp_alloc_dev(int sizeof_ocpdev)
263 /* ensure 32-byte alignment of the driver area */
264 alloc_size = sizeof (*drv) + sizeof_ocpdev + 31;
266 drv = (struct ocp_dev *) kmalloc(alloc_size, GFP_KERNEL);
269 "ocp_alloc_dev: Unable to allocate device memory.\n");
273 memset(drv, 0, alloc_size);
276 drv->ocpdev = (void *) (((long) (drv + 1) + 31) & ~31);
282 * ocp_free_dev - frees alloc space for ocp driver
283 * @drv: the driver structure to register
285 * Adds the driver structure to the list of registered drivers
286 * Returns the number of ocp type devices which were claimed by the driver
287 * during registration. The driver remains registered even if the
288 * return value is zero.
291 * ocp_free_dev - frees alloc space for ocp driver
292 * @dev: ocp device as allocated in ocp_alloc_dev
295 ocp_free_dev(void *dev)
301 * ocp_register - register a new ocp driver
302 * @drv: the driver structure to register
304 * Adds the driver structure to the list of registered drivers
305 * Returns the number of ocp type devices which were claimed by the driver
306 * during registration. The driver remains registered even if the
307 * return value is zero.
310 ocp_register(struct ocp_dev *drv)
314 list_add(&drv->ocp_list, &ocp_list);
315 max = ocp_get_max(drv->type);
316 drv->num = ocp_get_numtypes(drv->type) - 1;
318 if (drv->num >= max) {
319 list_del(&drv->ocp_list);
323 if (!ocp_set_dev(drv)) {
324 list_del(&drv->ocp_list);
327 #ifdef CONFIG_OCP_PROC
328 ocp_proc_attach_device(drv);
331 printk("Dev: %s Num:%d @ paddr:0x%x irq:%d\n", drv->name, drv->num,
332 drv->paddr, drv->irq);
338 * ocp_unregister - unregister a ocp driver
339 * @drv: the driver structure to unregister
341 * Deletes the driver structure from the list of registered OCP drivers,
342 * gives it a chance to clean up by calling its remove() function for
343 * each device it was responsible for, and marks those devices as
348 ocp_unregister(struct ocp_dev *drv)
350 list_del(&drv->ocp_list);
351 #ifdef CONFIG_OCP_PROC
352 ocp_proc_detach_device(drv);
357 * ocp_get_dev - get ocp driver pointer for ocp type and instance of it
358 * @type: OCP type such as PCI, GPT, UART, OPB, IIC, GPIO, EMAC, ZMII
359 * @dev_num: ocp device number whos paddr you want
361 * The routine returns ocp device pointer
362 * in list based on type and instance of that device
366 ocp_get_dev(int type, int dev_num)
369 struct list_head *ocp_l;
371 list_for_each(ocp_l, &ocp_list) {
372 ocp = list_entry(ocp_l, struct ocp_dev, ocp_list);
373 if (type == ocp->type) {
374 if (dev_num == count)
383 EXPORT_SYMBOL(ocp_get_irq);
384 EXPORT_SYMBOL(ocp_get_paddr);
385 EXPORT_SYMBOL(ocp_get_pm);
386 EXPORT_SYMBOL(ocp_get_max);
387 EXPORT_SYMBOL(ocp_get_dev);
388 EXPORT_SYMBOL(ocp_alloc_dev);
389 EXPORT_SYMBOL(ocp_free_dev);
390 EXPORT_SYMBOL(ocp_register);
391 EXPORT_SYMBOL(ocp_unregister);