1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-or-later
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * Bus & driver management routines for devices within
4*4882a593Smuzhiyun * a MacIO ASIC. Interface to new driver model mostly
5*4882a593Smuzhiyun * stolen from the PCI version.
6*4882a593Smuzhiyun *
7*4882a593Smuzhiyun * Copyright (C) 2005 Ben. Herrenschmidt (benh@kernel.crashing.org)
8*4882a593Smuzhiyun *
9*4882a593Smuzhiyun * TODO:
10*4882a593Smuzhiyun *
11*4882a593Smuzhiyun * - Don't probe below media bay by default, but instead provide
12*4882a593Smuzhiyun * some hooks for media bay to dynamically add/remove it's own
13*4882a593Smuzhiyun * sub-devices.
14*4882a593Smuzhiyun */
15*4882a593Smuzhiyun
16*4882a593Smuzhiyun #include <linux/string.h>
17*4882a593Smuzhiyun #include <linux/kernel.h>
18*4882a593Smuzhiyun #include <linux/pci.h>
19*4882a593Smuzhiyun #include <linux/pci_ids.h>
20*4882a593Smuzhiyun #include <linux/init.h>
21*4882a593Smuzhiyun #include <linux/module.h>
22*4882a593Smuzhiyun #include <linux/slab.h>
23*4882a593Smuzhiyun #include <linux/of_address.h>
24*4882a593Smuzhiyun #include <linux/of_irq.h>
25*4882a593Smuzhiyun
26*4882a593Smuzhiyun #include <asm/machdep.h>
27*4882a593Smuzhiyun #include <asm/macio.h>
28*4882a593Smuzhiyun #include <asm/pmac_feature.h>
29*4882a593Smuzhiyun #include <asm/prom.h>
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun #undef DEBUG
32*4882a593Smuzhiyun
33*4882a593Smuzhiyun #define MAX_NODE_NAME_SIZE (20 - 12)
34*4882a593Smuzhiyun
35*4882a593Smuzhiyun static struct macio_chip *macio_on_hold;
36*4882a593Smuzhiyun
macio_bus_match(struct device * dev,struct device_driver * drv)37*4882a593Smuzhiyun static int macio_bus_match(struct device *dev, struct device_driver *drv)
38*4882a593Smuzhiyun {
39*4882a593Smuzhiyun const struct of_device_id * matches = drv->of_match_table;
40*4882a593Smuzhiyun
41*4882a593Smuzhiyun if (!matches)
42*4882a593Smuzhiyun return 0;
43*4882a593Smuzhiyun
44*4882a593Smuzhiyun return of_match_device(matches, dev) != NULL;
45*4882a593Smuzhiyun }
46*4882a593Smuzhiyun
macio_dev_get(struct macio_dev * dev)47*4882a593Smuzhiyun struct macio_dev *macio_dev_get(struct macio_dev *dev)
48*4882a593Smuzhiyun {
49*4882a593Smuzhiyun struct device *tmp;
50*4882a593Smuzhiyun
51*4882a593Smuzhiyun if (!dev)
52*4882a593Smuzhiyun return NULL;
53*4882a593Smuzhiyun tmp = get_device(&dev->ofdev.dev);
54*4882a593Smuzhiyun if (tmp)
55*4882a593Smuzhiyun return to_macio_device(tmp);
56*4882a593Smuzhiyun else
57*4882a593Smuzhiyun return NULL;
58*4882a593Smuzhiyun }
59*4882a593Smuzhiyun
macio_dev_put(struct macio_dev * dev)60*4882a593Smuzhiyun void macio_dev_put(struct macio_dev *dev)
61*4882a593Smuzhiyun {
62*4882a593Smuzhiyun if (dev)
63*4882a593Smuzhiyun put_device(&dev->ofdev.dev);
64*4882a593Smuzhiyun }
65*4882a593Smuzhiyun
66*4882a593Smuzhiyun
macio_device_probe(struct device * dev)67*4882a593Smuzhiyun static int macio_device_probe(struct device *dev)
68*4882a593Smuzhiyun {
69*4882a593Smuzhiyun int error = -ENODEV;
70*4882a593Smuzhiyun struct macio_driver *drv;
71*4882a593Smuzhiyun struct macio_dev *macio_dev;
72*4882a593Smuzhiyun const struct of_device_id *match;
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun drv = to_macio_driver(dev->driver);
75*4882a593Smuzhiyun macio_dev = to_macio_device(dev);
76*4882a593Smuzhiyun
77*4882a593Smuzhiyun if (!drv->probe)
78*4882a593Smuzhiyun return error;
79*4882a593Smuzhiyun
80*4882a593Smuzhiyun macio_dev_get(macio_dev);
81*4882a593Smuzhiyun
82*4882a593Smuzhiyun match = of_match_device(drv->driver.of_match_table, dev);
83*4882a593Smuzhiyun if (match)
84*4882a593Smuzhiyun error = drv->probe(macio_dev, match);
85*4882a593Smuzhiyun if (error)
86*4882a593Smuzhiyun macio_dev_put(macio_dev);
87*4882a593Smuzhiyun
88*4882a593Smuzhiyun return error;
89*4882a593Smuzhiyun }
90*4882a593Smuzhiyun
macio_device_remove(struct device * dev)91*4882a593Smuzhiyun static int macio_device_remove(struct device *dev)
92*4882a593Smuzhiyun {
93*4882a593Smuzhiyun struct macio_dev * macio_dev = to_macio_device(dev);
94*4882a593Smuzhiyun struct macio_driver * drv = to_macio_driver(dev->driver);
95*4882a593Smuzhiyun
96*4882a593Smuzhiyun if (dev->driver && drv->remove)
97*4882a593Smuzhiyun drv->remove(macio_dev);
98*4882a593Smuzhiyun macio_dev_put(macio_dev);
99*4882a593Smuzhiyun
100*4882a593Smuzhiyun return 0;
101*4882a593Smuzhiyun }
102*4882a593Smuzhiyun
macio_device_shutdown(struct device * dev)103*4882a593Smuzhiyun static void macio_device_shutdown(struct device *dev)
104*4882a593Smuzhiyun {
105*4882a593Smuzhiyun struct macio_dev * macio_dev = to_macio_device(dev);
106*4882a593Smuzhiyun struct macio_driver * drv = to_macio_driver(dev->driver);
107*4882a593Smuzhiyun
108*4882a593Smuzhiyun if (dev->driver && drv->shutdown)
109*4882a593Smuzhiyun drv->shutdown(macio_dev);
110*4882a593Smuzhiyun }
111*4882a593Smuzhiyun
macio_device_suspend(struct device * dev,pm_message_t state)112*4882a593Smuzhiyun static int macio_device_suspend(struct device *dev, pm_message_t state)
113*4882a593Smuzhiyun {
114*4882a593Smuzhiyun struct macio_dev * macio_dev = to_macio_device(dev);
115*4882a593Smuzhiyun struct macio_driver * drv = to_macio_driver(dev->driver);
116*4882a593Smuzhiyun
117*4882a593Smuzhiyun if (dev->driver && drv->suspend)
118*4882a593Smuzhiyun return drv->suspend(macio_dev, state);
119*4882a593Smuzhiyun return 0;
120*4882a593Smuzhiyun }
121*4882a593Smuzhiyun
macio_device_resume(struct device * dev)122*4882a593Smuzhiyun static int macio_device_resume(struct device * dev)
123*4882a593Smuzhiyun {
124*4882a593Smuzhiyun struct macio_dev * macio_dev = to_macio_device(dev);
125*4882a593Smuzhiyun struct macio_driver * drv = to_macio_driver(dev->driver);
126*4882a593Smuzhiyun
127*4882a593Smuzhiyun if (dev->driver && drv->resume)
128*4882a593Smuzhiyun return drv->resume(macio_dev);
129*4882a593Smuzhiyun return 0;
130*4882a593Smuzhiyun }
131*4882a593Smuzhiyun
132*4882a593Smuzhiyun extern const struct attribute_group *macio_dev_groups[];
133*4882a593Smuzhiyun
134*4882a593Smuzhiyun struct bus_type macio_bus_type = {
135*4882a593Smuzhiyun .name = "macio",
136*4882a593Smuzhiyun .match = macio_bus_match,
137*4882a593Smuzhiyun .uevent = of_device_uevent_modalias,
138*4882a593Smuzhiyun .probe = macio_device_probe,
139*4882a593Smuzhiyun .remove = macio_device_remove,
140*4882a593Smuzhiyun .shutdown = macio_device_shutdown,
141*4882a593Smuzhiyun .suspend = macio_device_suspend,
142*4882a593Smuzhiyun .resume = macio_device_resume,
143*4882a593Smuzhiyun .dev_groups = macio_dev_groups,
144*4882a593Smuzhiyun };
145*4882a593Smuzhiyun
macio_bus_driver_init(void)146*4882a593Smuzhiyun static int __init macio_bus_driver_init(void)
147*4882a593Smuzhiyun {
148*4882a593Smuzhiyun return bus_register(&macio_bus_type);
149*4882a593Smuzhiyun }
150*4882a593Smuzhiyun
151*4882a593Smuzhiyun postcore_initcall(macio_bus_driver_init);
152*4882a593Smuzhiyun
153*4882a593Smuzhiyun
154*4882a593Smuzhiyun /**
155*4882a593Smuzhiyun * macio_release_dev - free a macio device structure when all users of it are
156*4882a593Smuzhiyun * finished.
157*4882a593Smuzhiyun * @dev: device that's been disconnected
158*4882a593Smuzhiyun *
159*4882a593Smuzhiyun * Will be called only by the device core when all users of this macio device
160*4882a593Smuzhiyun * are done. This currently means never as we don't hot remove any macio
161*4882a593Smuzhiyun * device yet, though that will happen with mediabay based devices in a later
162*4882a593Smuzhiyun * implementation.
163*4882a593Smuzhiyun */
macio_release_dev(struct device * dev)164*4882a593Smuzhiyun static void macio_release_dev(struct device *dev)
165*4882a593Smuzhiyun {
166*4882a593Smuzhiyun struct macio_dev *mdev;
167*4882a593Smuzhiyun
168*4882a593Smuzhiyun mdev = to_macio_device(dev);
169*4882a593Smuzhiyun kfree(mdev);
170*4882a593Smuzhiyun }
171*4882a593Smuzhiyun
172*4882a593Smuzhiyun /**
173*4882a593Smuzhiyun * macio_resource_quirks - tweak or skip some resources for a device
174*4882a593Smuzhiyun * @np: pointer to the device node
175*4882a593Smuzhiyun * @res: resulting resource
176*4882a593Smuzhiyun * @index: index of resource in node
177*4882a593Smuzhiyun *
178*4882a593Smuzhiyun * If this routine returns non-null, then the resource is completely
179*4882a593Smuzhiyun * skipped.
180*4882a593Smuzhiyun */
macio_resource_quirks(struct device_node * np,struct resource * res,int index)181*4882a593Smuzhiyun static int macio_resource_quirks(struct device_node *np, struct resource *res,
182*4882a593Smuzhiyun int index)
183*4882a593Smuzhiyun {
184*4882a593Smuzhiyun /* Only quirks for memory resources for now */
185*4882a593Smuzhiyun if ((res->flags & IORESOURCE_MEM) == 0)
186*4882a593Smuzhiyun return 0;
187*4882a593Smuzhiyun
188*4882a593Smuzhiyun /* Grand Central has too large resource 0 on some machines */
189*4882a593Smuzhiyun if (index == 0 && of_node_name_eq(np, "gc"))
190*4882a593Smuzhiyun res->end = res->start + 0x1ffff;
191*4882a593Smuzhiyun
192*4882a593Smuzhiyun /* Airport has bogus resource 2 */
193*4882a593Smuzhiyun if (index >= 2 && of_node_name_eq(np, "radio"))
194*4882a593Smuzhiyun return 1;
195*4882a593Smuzhiyun
196*4882a593Smuzhiyun #ifndef CONFIG_PPC64
197*4882a593Smuzhiyun /* DBDMAs may have bogus sizes */
198*4882a593Smuzhiyun if ((res->start & 0x0001f000) == 0x00008000)
199*4882a593Smuzhiyun res->end = res->start + 0xff;
200*4882a593Smuzhiyun #endif /* CONFIG_PPC64 */
201*4882a593Smuzhiyun
202*4882a593Smuzhiyun /* ESCC parent eats child resources. We could have added a
203*4882a593Smuzhiyun * level of hierarchy, but I don't really feel the need
204*4882a593Smuzhiyun * for it
205*4882a593Smuzhiyun */
206*4882a593Smuzhiyun if (of_node_name_eq(np, "escc"))
207*4882a593Smuzhiyun return 1;
208*4882a593Smuzhiyun
209*4882a593Smuzhiyun /* ESCC has bogus resources >= 3 */
210*4882a593Smuzhiyun if (index >= 3 && (of_node_name_eq(np, "ch-a") ||
211*4882a593Smuzhiyun of_node_name_eq(np, "ch-b")))
212*4882a593Smuzhiyun return 1;
213*4882a593Smuzhiyun
214*4882a593Smuzhiyun /* Media bay has too many resources, keep only first one */
215*4882a593Smuzhiyun if (index > 0 && of_node_name_eq(np, "media-bay"))
216*4882a593Smuzhiyun return 1;
217*4882a593Smuzhiyun
218*4882a593Smuzhiyun /* Some older IDE resources have bogus sizes */
219*4882a593Smuzhiyun if (of_node_name_eq(np, "IDE") || of_node_name_eq(np, "ATA") ||
220*4882a593Smuzhiyun of_node_is_type(np, "ide") || of_node_is_type(np, "ata")) {
221*4882a593Smuzhiyun if (index == 0 && (res->end - res->start) > 0xfff)
222*4882a593Smuzhiyun res->end = res->start + 0xfff;
223*4882a593Smuzhiyun if (index == 1 && (res->end - res->start) > 0xff)
224*4882a593Smuzhiyun res->end = res->start + 0xff;
225*4882a593Smuzhiyun }
226*4882a593Smuzhiyun return 0;
227*4882a593Smuzhiyun }
228*4882a593Smuzhiyun
macio_create_fixup_irq(struct macio_dev * dev,int index,unsigned int line)229*4882a593Smuzhiyun static void macio_create_fixup_irq(struct macio_dev *dev, int index,
230*4882a593Smuzhiyun unsigned int line)
231*4882a593Smuzhiyun {
232*4882a593Smuzhiyun unsigned int irq;
233*4882a593Smuzhiyun
234*4882a593Smuzhiyun irq = irq_create_mapping(NULL, line);
235*4882a593Smuzhiyun if (!irq) {
236*4882a593Smuzhiyun dev->interrupt[index].start = irq;
237*4882a593Smuzhiyun dev->interrupt[index].flags = IORESOURCE_IRQ;
238*4882a593Smuzhiyun dev->interrupt[index].name = dev_name(&dev->ofdev.dev);
239*4882a593Smuzhiyun }
240*4882a593Smuzhiyun if (dev->n_interrupts <= index)
241*4882a593Smuzhiyun dev->n_interrupts = index + 1;
242*4882a593Smuzhiyun }
243*4882a593Smuzhiyun
macio_add_missing_resources(struct macio_dev * dev)244*4882a593Smuzhiyun static void macio_add_missing_resources(struct macio_dev *dev)
245*4882a593Smuzhiyun {
246*4882a593Smuzhiyun struct device_node *np = dev->ofdev.dev.of_node;
247*4882a593Smuzhiyun unsigned int irq_base;
248*4882a593Smuzhiyun
249*4882a593Smuzhiyun /* Gatwick has some missing interrupts on child nodes */
250*4882a593Smuzhiyun if (dev->bus->chip->type != macio_gatwick)
251*4882a593Smuzhiyun return;
252*4882a593Smuzhiyun
253*4882a593Smuzhiyun /* irq_base is always 64 on gatwick. I have no cleaner way to get
254*4882a593Smuzhiyun * that value from here at this point
255*4882a593Smuzhiyun */
256*4882a593Smuzhiyun irq_base = 64;
257*4882a593Smuzhiyun
258*4882a593Smuzhiyun /* Fix SCC */
259*4882a593Smuzhiyun if (of_node_name_eq(np, "ch-a")) {
260*4882a593Smuzhiyun macio_create_fixup_irq(dev, 0, 15 + irq_base);
261*4882a593Smuzhiyun macio_create_fixup_irq(dev, 1, 4 + irq_base);
262*4882a593Smuzhiyun macio_create_fixup_irq(dev, 2, 5 + irq_base);
263*4882a593Smuzhiyun printk(KERN_INFO "macio: fixed SCC irqs on gatwick\n");
264*4882a593Smuzhiyun }
265*4882a593Smuzhiyun
266*4882a593Smuzhiyun /* Fix media-bay */
267*4882a593Smuzhiyun if (of_node_name_eq(np, "media-bay")) {
268*4882a593Smuzhiyun macio_create_fixup_irq(dev, 0, 29 + irq_base);
269*4882a593Smuzhiyun printk(KERN_INFO "macio: fixed media-bay irq on gatwick\n");
270*4882a593Smuzhiyun }
271*4882a593Smuzhiyun
272*4882a593Smuzhiyun /* Fix left media bay childs */
273*4882a593Smuzhiyun if (dev->media_bay != NULL && of_node_name_eq(np, "floppy")) {
274*4882a593Smuzhiyun macio_create_fixup_irq(dev, 0, 19 + irq_base);
275*4882a593Smuzhiyun macio_create_fixup_irq(dev, 1, 1 + irq_base);
276*4882a593Smuzhiyun printk(KERN_INFO "macio: fixed left floppy irqs\n");
277*4882a593Smuzhiyun }
278*4882a593Smuzhiyun if (dev->media_bay != NULL && of_node_name_eq(np, "ata4")) {
279*4882a593Smuzhiyun macio_create_fixup_irq(dev, 0, 14 + irq_base);
280*4882a593Smuzhiyun macio_create_fixup_irq(dev, 0, 3 + irq_base);
281*4882a593Smuzhiyun printk(KERN_INFO "macio: fixed left ide irqs\n");
282*4882a593Smuzhiyun }
283*4882a593Smuzhiyun }
284*4882a593Smuzhiyun
macio_setup_interrupts(struct macio_dev * dev)285*4882a593Smuzhiyun static void macio_setup_interrupts(struct macio_dev *dev)
286*4882a593Smuzhiyun {
287*4882a593Smuzhiyun struct device_node *np = dev->ofdev.dev.of_node;
288*4882a593Smuzhiyun unsigned int irq;
289*4882a593Smuzhiyun int i = 0, j = 0;
290*4882a593Smuzhiyun
291*4882a593Smuzhiyun for (;;) {
292*4882a593Smuzhiyun struct resource *res;
293*4882a593Smuzhiyun
294*4882a593Smuzhiyun if (j >= MACIO_DEV_COUNT_IRQS)
295*4882a593Smuzhiyun break;
296*4882a593Smuzhiyun res = &dev->interrupt[j];
297*4882a593Smuzhiyun irq = irq_of_parse_and_map(np, i++);
298*4882a593Smuzhiyun if (!irq)
299*4882a593Smuzhiyun break;
300*4882a593Smuzhiyun res->start = irq;
301*4882a593Smuzhiyun res->flags = IORESOURCE_IRQ;
302*4882a593Smuzhiyun res->name = dev_name(&dev->ofdev.dev);
303*4882a593Smuzhiyun if (macio_resource_quirks(np, res, i - 1)) {
304*4882a593Smuzhiyun memset(res, 0, sizeof(struct resource));
305*4882a593Smuzhiyun continue;
306*4882a593Smuzhiyun } else
307*4882a593Smuzhiyun j++;
308*4882a593Smuzhiyun }
309*4882a593Smuzhiyun dev->n_interrupts = j;
310*4882a593Smuzhiyun }
311*4882a593Smuzhiyun
macio_setup_resources(struct macio_dev * dev,struct resource * parent_res)312*4882a593Smuzhiyun static void macio_setup_resources(struct macio_dev *dev,
313*4882a593Smuzhiyun struct resource *parent_res)
314*4882a593Smuzhiyun {
315*4882a593Smuzhiyun struct device_node *np = dev->ofdev.dev.of_node;
316*4882a593Smuzhiyun struct resource r;
317*4882a593Smuzhiyun int index;
318*4882a593Smuzhiyun
319*4882a593Smuzhiyun for (index = 0; of_address_to_resource(np, index, &r) == 0; index++) {
320*4882a593Smuzhiyun struct resource *res;
321*4882a593Smuzhiyun if (index >= MACIO_DEV_COUNT_RESOURCES)
322*4882a593Smuzhiyun break;
323*4882a593Smuzhiyun res = &dev->resource[index];
324*4882a593Smuzhiyun *res = r;
325*4882a593Smuzhiyun res->name = dev_name(&dev->ofdev.dev);
326*4882a593Smuzhiyun
327*4882a593Smuzhiyun if (macio_resource_quirks(np, res, index)) {
328*4882a593Smuzhiyun memset(res, 0, sizeof(struct resource));
329*4882a593Smuzhiyun continue;
330*4882a593Smuzhiyun }
331*4882a593Smuzhiyun /* Currently, we consider failure as harmless, this may
332*4882a593Smuzhiyun * change in the future, once I've found all the device
333*4882a593Smuzhiyun * tree bugs in older machines & worked around them
334*4882a593Smuzhiyun */
335*4882a593Smuzhiyun if (insert_resource(parent_res, res)) {
336*4882a593Smuzhiyun printk(KERN_WARNING "Can't request resource "
337*4882a593Smuzhiyun "%d for MacIO device %s\n",
338*4882a593Smuzhiyun index, dev_name(&dev->ofdev.dev));
339*4882a593Smuzhiyun }
340*4882a593Smuzhiyun }
341*4882a593Smuzhiyun dev->n_resources = index;
342*4882a593Smuzhiyun }
343*4882a593Smuzhiyun
344*4882a593Smuzhiyun /**
345*4882a593Smuzhiyun * macio_add_one_device - Add one device from OF node to the device tree
346*4882a593Smuzhiyun * @chip: pointer to the macio_chip holding the device
347*4882a593Smuzhiyun * @np: pointer to the device node in the OF tree
348*4882a593Smuzhiyun * @in_bay: set to 1 if device is part of a media-bay
349*4882a593Smuzhiyun *
350*4882a593Smuzhiyun * When media-bay is changed to hotswap drivers, this function will
351*4882a593Smuzhiyun * be exposed to the bay driver some way...
352*4882a593Smuzhiyun */
macio_add_one_device(struct macio_chip * chip,struct device * parent,struct device_node * np,struct macio_dev * in_bay,struct resource * parent_res)353*4882a593Smuzhiyun static struct macio_dev * macio_add_one_device(struct macio_chip *chip,
354*4882a593Smuzhiyun struct device *parent,
355*4882a593Smuzhiyun struct device_node *np,
356*4882a593Smuzhiyun struct macio_dev *in_bay,
357*4882a593Smuzhiyun struct resource *parent_res)
358*4882a593Smuzhiyun {
359*4882a593Smuzhiyun char name[MAX_NODE_NAME_SIZE + 1];
360*4882a593Smuzhiyun struct macio_dev *dev;
361*4882a593Smuzhiyun const u32 *reg;
362*4882a593Smuzhiyun
363*4882a593Smuzhiyun if (np == NULL)
364*4882a593Smuzhiyun return NULL;
365*4882a593Smuzhiyun
366*4882a593Smuzhiyun dev = kzalloc(sizeof(*dev), GFP_KERNEL);
367*4882a593Smuzhiyun if (!dev)
368*4882a593Smuzhiyun return NULL;
369*4882a593Smuzhiyun
370*4882a593Smuzhiyun dev->bus = &chip->lbus;
371*4882a593Smuzhiyun dev->media_bay = in_bay;
372*4882a593Smuzhiyun dev->ofdev.dev.of_node = np;
373*4882a593Smuzhiyun dev->ofdev.archdata.dma_mask = 0xffffffffUL;
374*4882a593Smuzhiyun dev->ofdev.dev.dma_mask = &dev->ofdev.archdata.dma_mask;
375*4882a593Smuzhiyun dev->ofdev.dev.coherent_dma_mask = dev->ofdev.archdata.dma_mask;
376*4882a593Smuzhiyun dev->ofdev.dev.parent = parent;
377*4882a593Smuzhiyun dev->ofdev.dev.bus = &macio_bus_type;
378*4882a593Smuzhiyun dev->ofdev.dev.release = macio_release_dev;
379*4882a593Smuzhiyun dev->ofdev.dev.dma_parms = &dev->dma_parms;
380*4882a593Smuzhiyun
381*4882a593Smuzhiyun /* Standard DMA paremeters */
382*4882a593Smuzhiyun dma_set_max_seg_size(&dev->ofdev.dev, 65536);
383*4882a593Smuzhiyun dma_set_seg_boundary(&dev->ofdev.dev, 0xffffffff);
384*4882a593Smuzhiyun
385*4882a593Smuzhiyun #if defined(CONFIG_PCI) && defined(CONFIG_DMA_OPS)
386*4882a593Smuzhiyun /* Set the DMA ops to the ones from the PCI device, this could be
387*4882a593Smuzhiyun * fishy if we didn't know that on PowerMac it's always direct ops
388*4882a593Smuzhiyun * or iommu ops that will work fine
389*4882a593Smuzhiyun *
390*4882a593Smuzhiyun * To get all the fields, copy all archdata
391*4882a593Smuzhiyun */
392*4882a593Smuzhiyun dev->ofdev.dev.archdata = chip->lbus.pdev->dev.archdata;
393*4882a593Smuzhiyun dev->ofdev.dev.dma_ops = chip->lbus.pdev->dev.dma_ops;
394*4882a593Smuzhiyun #endif /* CONFIG_PCI && CONFIG_DMA_OPS */
395*4882a593Smuzhiyun
396*4882a593Smuzhiyun #ifdef DEBUG
397*4882a593Smuzhiyun printk("preparing mdev @%p, ofdev @%p, dev @%p, kobj @%p\n",
398*4882a593Smuzhiyun dev, &dev->ofdev, &dev->ofdev.dev, &dev->ofdev.dev.kobj);
399*4882a593Smuzhiyun #endif
400*4882a593Smuzhiyun
401*4882a593Smuzhiyun /* MacIO itself has a different reg, we use it's PCI base */
402*4882a593Smuzhiyun snprintf(name, sizeof(name), "%pOFn", np);
403*4882a593Smuzhiyun if (np == chip->of_node) {
404*4882a593Smuzhiyun dev_set_name(&dev->ofdev.dev, "%1d.%08x:%.*s",
405*4882a593Smuzhiyun chip->lbus.index,
406*4882a593Smuzhiyun #ifdef CONFIG_PCI
407*4882a593Smuzhiyun (unsigned int)pci_resource_start(chip->lbus.pdev, 0),
408*4882a593Smuzhiyun #else
409*4882a593Smuzhiyun 0, /* NuBus may want to do something better here */
410*4882a593Smuzhiyun #endif
411*4882a593Smuzhiyun MAX_NODE_NAME_SIZE, name);
412*4882a593Smuzhiyun } else {
413*4882a593Smuzhiyun reg = of_get_property(np, "reg", NULL);
414*4882a593Smuzhiyun dev_set_name(&dev->ofdev.dev, "%1d.%08x:%.*s",
415*4882a593Smuzhiyun chip->lbus.index,
416*4882a593Smuzhiyun reg ? *reg : 0, MAX_NODE_NAME_SIZE, name);
417*4882a593Smuzhiyun }
418*4882a593Smuzhiyun
419*4882a593Smuzhiyun /* Setup interrupts & resources */
420*4882a593Smuzhiyun macio_setup_interrupts(dev);
421*4882a593Smuzhiyun macio_setup_resources(dev, parent_res);
422*4882a593Smuzhiyun macio_add_missing_resources(dev);
423*4882a593Smuzhiyun
424*4882a593Smuzhiyun /* Register with core */
425*4882a593Smuzhiyun if (of_device_register(&dev->ofdev) != 0) {
426*4882a593Smuzhiyun printk(KERN_DEBUG"macio: device registration error for %s!\n",
427*4882a593Smuzhiyun dev_name(&dev->ofdev.dev));
428*4882a593Smuzhiyun kfree(dev);
429*4882a593Smuzhiyun return NULL;
430*4882a593Smuzhiyun }
431*4882a593Smuzhiyun
432*4882a593Smuzhiyun return dev;
433*4882a593Smuzhiyun }
434*4882a593Smuzhiyun
macio_skip_device(struct device_node * np)435*4882a593Smuzhiyun static int macio_skip_device(struct device_node *np)
436*4882a593Smuzhiyun {
437*4882a593Smuzhiyun return of_node_name_prefix(np, "battery") ||
438*4882a593Smuzhiyun of_node_name_prefix(np, "escc-legacy");
439*4882a593Smuzhiyun }
440*4882a593Smuzhiyun
441*4882a593Smuzhiyun /**
442*4882a593Smuzhiyun * macio_pci_add_devices - Adds sub-devices of mac-io to the device tree
443*4882a593Smuzhiyun * @chip: pointer to the macio_chip holding the devices
444*4882a593Smuzhiyun *
445*4882a593Smuzhiyun * This function will do the job of extracting devices from the
446*4882a593Smuzhiyun * Open Firmware device tree, build macio_dev structures and add
447*4882a593Smuzhiyun * them to the Linux device tree.
448*4882a593Smuzhiyun *
449*4882a593Smuzhiyun * For now, childs of media-bay are added now as well. This will
450*4882a593Smuzhiyun * change rsn though.
451*4882a593Smuzhiyun */
macio_pci_add_devices(struct macio_chip * chip)452*4882a593Smuzhiyun static void macio_pci_add_devices(struct macio_chip *chip)
453*4882a593Smuzhiyun {
454*4882a593Smuzhiyun struct device_node *np, *pnode;
455*4882a593Smuzhiyun struct macio_dev *rdev, *mdev, *mbdev = NULL, *sdev = NULL;
456*4882a593Smuzhiyun struct device *parent = NULL;
457*4882a593Smuzhiyun struct resource *root_res = &iomem_resource;
458*4882a593Smuzhiyun
459*4882a593Smuzhiyun /* Add a node for the macio bus itself */
460*4882a593Smuzhiyun #ifdef CONFIG_PCI
461*4882a593Smuzhiyun if (chip->lbus.pdev) {
462*4882a593Smuzhiyun parent = &chip->lbus.pdev->dev;
463*4882a593Smuzhiyun root_res = &chip->lbus.pdev->resource[0];
464*4882a593Smuzhiyun }
465*4882a593Smuzhiyun #endif
466*4882a593Smuzhiyun pnode = of_node_get(chip->of_node);
467*4882a593Smuzhiyun if (pnode == NULL)
468*4882a593Smuzhiyun return;
469*4882a593Smuzhiyun
470*4882a593Smuzhiyun /* Add macio itself to hierarchy */
471*4882a593Smuzhiyun rdev = macio_add_one_device(chip, parent, pnode, NULL, root_res);
472*4882a593Smuzhiyun if (rdev == NULL)
473*4882a593Smuzhiyun return;
474*4882a593Smuzhiyun root_res = &rdev->resource[0];
475*4882a593Smuzhiyun
476*4882a593Smuzhiyun /* First scan 1st level */
477*4882a593Smuzhiyun for (np = NULL; (np = of_get_next_child(pnode, np)) != NULL;) {
478*4882a593Smuzhiyun if (macio_skip_device(np))
479*4882a593Smuzhiyun continue;
480*4882a593Smuzhiyun of_node_get(np);
481*4882a593Smuzhiyun mdev = macio_add_one_device(chip, &rdev->ofdev.dev, np, NULL,
482*4882a593Smuzhiyun root_res);
483*4882a593Smuzhiyun if (mdev == NULL)
484*4882a593Smuzhiyun of_node_put(np);
485*4882a593Smuzhiyun else if (of_node_name_prefix(np, "media-bay"))
486*4882a593Smuzhiyun mbdev = mdev;
487*4882a593Smuzhiyun else if (of_node_name_prefix(np, "escc"))
488*4882a593Smuzhiyun sdev = mdev;
489*4882a593Smuzhiyun }
490*4882a593Smuzhiyun
491*4882a593Smuzhiyun /* Add media bay devices if any */
492*4882a593Smuzhiyun if (mbdev) {
493*4882a593Smuzhiyun pnode = mbdev->ofdev.dev.of_node;
494*4882a593Smuzhiyun for (np = NULL; (np = of_get_next_child(pnode, np)) != NULL;) {
495*4882a593Smuzhiyun if (macio_skip_device(np))
496*4882a593Smuzhiyun continue;
497*4882a593Smuzhiyun of_node_get(np);
498*4882a593Smuzhiyun if (macio_add_one_device(chip, &mbdev->ofdev.dev, np,
499*4882a593Smuzhiyun mbdev, root_res) == NULL)
500*4882a593Smuzhiyun of_node_put(np);
501*4882a593Smuzhiyun }
502*4882a593Smuzhiyun }
503*4882a593Smuzhiyun
504*4882a593Smuzhiyun /* Add serial ports if any */
505*4882a593Smuzhiyun if (sdev) {
506*4882a593Smuzhiyun pnode = sdev->ofdev.dev.of_node;
507*4882a593Smuzhiyun for (np = NULL; (np = of_get_next_child(pnode, np)) != NULL;) {
508*4882a593Smuzhiyun if (macio_skip_device(np))
509*4882a593Smuzhiyun continue;
510*4882a593Smuzhiyun of_node_get(np);
511*4882a593Smuzhiyun if (macio_add_one_device(chip, &sdev->ofdev.dev, np,
512*4882a593Smuzhiyun NULL, root_res) == NULL)
513*4882a593Smuzhiyun of_node_put(np);
514*4882a593Smuzhiyun }
515*4882a593Smuzhiyun }
516*4882a593Smuzhiyun }
517*4882a593Smuzhiyun
518*4882a593Smuzhiyun
519*4882a593Smuzhiyun /**
520*4882a593Smuzhiyun * macio_register_driver - Registers a new MacIO device driver
521*4882a593Smuzhiyun * @drv: pointer to the driver definition structure
522*4882a593Smuzhiyun */
macio_register_driver(struct macio_driver * drv)523*4882a593Smuzhiyun int macio_register_driver(struct macio_driver *drv)
524*4882a593Smuzhiyun {
525*4882a593Smuzhiyun /* initialize common driver fields */
526*4882a593Smuzhiyun drv->driver.bus = &macio_bus_type;
527*4882a593Smuzhiyun
528*4882a593Smuzhiyun /* register with core */
529*4882a593Smuzhiyun return driver_register(&drv->driver);
530*4882a593Smuzhiyun }
531*4882a593Smuzhiyun
532*4882a593Smuzhiyun /**
533*4882a593Smuzhiyun * macio_unregister_driver - Unregisters a new MacIO device driver
534*4882a593Smuzhiyun * @drv: pointer to the driver definition structure
535*4882a593Smuzhiyun */
macio_unregister_driver(struct macio_driver * drv)536*4882a593Smuzhiyun void macio_unregister_driver(struct macio_driver *drv)
537*4882a593Smuzhiyun {
538*4882a593Smuzhiyun driver_unregister(&drv->driver);
539*4882a593Smuzhiyun }
540*4882a593Smuzhiyun
541*4882a593Smuzhiyun /* Managed MacIO resources */
542*4882a593Smuzhiyun struct macio_devres {
543*4882a593Smuzhiyun u32 res_mask;
544*4882a593Smuzhiyun };
545*4882a593Smuzhiyun
maciom_release(struct device * gendev,void * res)546*4882a593Smuzhiyun static void maciom_release(struct device *gendev, void *res)
547*4882a593Smuzhiyun {
548*4882a593Smuzhiyun struct macio_dev *dev = to_macio_device(gendev);
549*4882a593Smuzhiyun struct macio_devres *dr = res;
550*4882a593Smuzhiyun int i, max;
551*4882a593Smuzhiyun
552*4882a593Smuzhiyun max = min(dev->n_resources, 32);
553*4882a593Smuzhiyun for (i = 0; i < max; i++) {
554*4882a593Smuzhiyun if (dr->res_mask & (1 << i))
555*4882a593Smuzhiyun macio_release_resource(dev, i);
556*4882a593Smuzhiyun }
557*4882a593Smuzhiyun }
558*4882a593Smuzhiyun
macio_enable_devres(struct macio_dev * dev)559*4882a593Smuzhiyun int macio_enable_devres(struct macio_dev *dev)
560*4882a593Smuzhiyun {
561*4882a593Smuzhiyun struct macio_devres *dr;
562*4882a593Smuzhiyun
563*4882a593Smuzhiyun dr = devres_find(&dev->ofdev.dev, maciom_release, NULL, NULL);
564*4882a593Smuzhiyun if (!dr) {
565*4882a593Smuzhiyun dr = devres_alloc(maciom_release, sizeof(*dr), GFP_KERNEL);
566*4882a593Smuzhiyun if (!dr)
567*4882a593Smuzhiyun return -ENOMEM;
568*4882a593Smuzhiyun }
569*4882a593Smuzhiyun return devres_get(&dev->ofdev.dev, dr, NULL, NULL) != NULL;
570*4882a593Smuzhiyun }
571*4882a593Smuzhiyun
find_macio_dr(struct macio_dev * dev)572*4882a593Smuzhiyun static struct macio_devres * find_macio_dr(struct macio_dev *dev)
573*4882a593Smuzhiyun {
574*4882a593Smuzhiyun return devres_find(&dev->ofdev.dev, maciom_release, NULL, NULL);
575*4882a593Smuzhiyun }
576*4882a593Smuzhiyun
577*4882a593Smuzhiyun /**
578*4882a593Smuzhiyun * macio_request_resource - Request an MMIO resource
579*4882a593Smuzhiyun * @dev: pointer to the device holding the resource
580*4882a593Smuzhiyun * @resource_no: resource number to request
581*4882a593Smuzhiyun * @name: resource name
582*4882a593Smuzhiyun *
583*4882a593Smuzhiyun * Mark memory region number @resource_no associated with MacIO
584*4882a593Smuzhiyun * device @dev as being reserved by owner @name. Do not access
585*4882a593Smuzhiyun * any address inside the memory regions unless this call returns
586*4882a593Smuzhiyun * successfully.
587*4882a593Smuzhiyun *
588*4882a593Smuzhiyun * Returns 0 on success, or %EBUSY on error. A warning
589*4882a593Smuzhiyun * message is also printed on failure.
590*4882a593Smuzhiyun */
macio_request_resource(struct macio_dev * dev,int resource_no,const char * name)591*4882a593Smuzhiyun int macio_request_resource(struct macio_dev *dev, int resource_no,
592*4882a593Smuzhiyun const char *name)
593*4882a593Smuzhiyun {
594*4882a593Smuzhiyun struct macio_devres *dr = find_macio_dr(dev);
595*4882a593Smuzhiyun
596*4882a593Smuzhiyun if (macio_resource_len(dev, resource_no) == 0)
597*4882a593Smuzhiyun return 0;
598*4882a593Smuzhiyun
599*4882a593Smuzhiyun if (!request_mem_region(macio_resource_start(dev, resource_no),
600*4882a593Smuzhiyun macio_resource_len(dev, resource_no),
601*4882a593Smuzhiyun name))
602*4882a593Smuzhiyun goto err_out;
603*4882a593Smuzhiyun
604*4882a593Smuzhiyun if (dr && resource_no < 32)
605*4882a593Smuzhiyun dr->res_mask |= 1 << resource_no;
606*4882a593Smuzhiyun
607*4882a593Smuzhiyun return 0;
608*4882a593Smuzhiyun
609*4882a593Smuzhiyun err_out:
610*4882a593Smuzhiyun printk (KERN_WARNING "MacIO: Unable to reserve resource #%d:%lx@%lx"
611*4882a593Smuzhiyun " for device %s\n",
612*4882a593Smuzhiyun resource_no,
613*4882a593Smuzhiyun macio_resource_len(dev, resource_no),
614*4882a593Smuzhiyun macio_resource_start(dev, resource_no),
615*4882a593Smuzhiyun dev_name(&dev->ofdev.dev));
616*4882a593Smuzhiyun return -EBUSY;
617*4882a593Smuzhiyun }
618*4882a593Smuzhiyun
619*4882a593Smuzhiyun /**
620*4882a593Smuzhiyun * macio_release_resource - Release an MMIO resource
621*4882a593Smuzhiyun * @dev: pointer to the device holding the resource
622*4882a593Smuzhiyun * @resource_no: resource number to release
623*4882a593Smuzhiyun */
macio_release_resource(struct macio_dev * dev,int resource_no)624*4882a593Smuzhiyun void macio_release_resource(struct macio_dev *dev, int resource_no)
625*4882a593Smuzhiyun {
626*4882a593Smuzhiyun struct macio_devres *dr = find_macio_dr(dev);
627*4882a593Smuzhiyun
628*4882a593Smuzhiyun if (macio_resource_len(dev, resource_no) == 0)
629*4882a593Smuzhiyun return;
630*4882a593Smuzhiyun release_mem_region(macio_resource_start(dev, resource_no),
631*4882a593Smuzhiyun macio_resource_len(dev, resource_no));
632*4882a593Smuzhiyun if (dr && resource_no < 32)
633*4882a593Smuzhiyun dr->res_mask &= ~(1 << resource_no);
634*4882a593Smuzhiyun }
635*4882a593Smuzhiyun
636*4882a593Smuzhiyun /**
637*4882a593Smuzhiyun * macio_request_resources - Reserve all memory resources
638*4882a593Smuzhiyun * @dev: MacIO device whose resources are to be reserved
639*4882a593Smuzhiyun * @name: Name to be associated with resource.
640*4882a593Smuzhiyun *
641*4882a593Smuzhiyun * Mark all memory regions associated with MacIO device @dev as
642*4882a593Smuzhiyun * being reserved by owner @name. Do not access any address inside
643*4882a593Smuzhiyun * the memory regions unless this call returns successfully.
644*4882a593Smuzhiyun *
645*4882a593Smuzhiyun * Returns 0 on success, or %EBUSY on error. A warning
646*4882a593Smuzhiyun * message is also printed on failure.
647*4882a593Smuzhiyun */
macio_request_resources(struct macio_dev * dev,const char * name)648*4882a593Smuzhiyun int macio_request_resources(struct macio_dev *dev, const char *name)
649*4882a593Smuzhiyun {
650*4882a593Smuzhiyun int i;
651*4882a593Smuzhiyun
652*4882a593Smuzhiyun for (i = 0; i < dev->n_resources; i++)
653*4882a593Smuzhiyun if (macio_request_resource(dev, i, name))
654*4882a593Smuzhiyun goto err_out;
655*4882a593Smuzhiyun return 0;
656*4882a593Smuzhiyun
657*4882a593Smuzhiyun err_out:
658*4882a593Smuzhiyun while(--i >= 0)
659*4882a593Smuzhiyun macio_release_resource(dev, i);
660*4882a593Smuzhiyun
661*4882a593Smuzhiyun return -EBUSY;
662*4882a593Smuzhiyun }
663*4882a593Smuzhiyun
664*4882a593Smuzhiyun /**
665*4882a593Smuzhiyun * macio_release_resources - Release reserved memory resources
666*4882a593Smuzhiyun * @dev: MacIO device whose resources were previously reserved
667*4882a593Smuzhiyun */
668*4882a593Smuzhiyun
macio_release_resources(struct macio_dev * dev)669*4882a593Smuzhiyun void macio_release_resources(struct macio_dev *dev)
670*4882a593Smuzhiyun {
671*4882a593Smuzhiyun int i;
672*4882a593Smuzhiyun
673*4882a593Smuzhiyun for (i = 0; i < dev->n_resources; i++)
674*4882a593Smuzhiyun macio_release_resource(dev, i);
675*4882a593Smuzhiyun }
676*4882a593Smuzhiyun
677*4882a593Smuzhiyun
678*4882a593Smuzhiyun #ifdef CONFIG_PCI
679*4882a593Smuzhiyun
macio_pci_probe(struct pci_dev * pdev,const struct pci_device_id * ent)680*4882a593Smuzhiyun static int macio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
681*4882a593Smuzhiyun {
682*4882a593Smuzhiyun struct device_node* np;
683*4882a593Smuzhiyun struct macio_chip* chip;
684*4882a593Smuzhiyun
685*4882a593Smuzhiyun if (ent->vendor != PCI_VENDOR_ID_APPLE)
686*4882a593Smuzhiyun return -ENODEV;
687*4882a593Smuzhiyun
688*4882a593Smuzhiyun /* Note regarding refcounting: We assume pci_device_to_OF_node() is
689*4882a593Smuzhiyun * ported to new OF APIs and returns a node with refcount incremented.
690*4882a593Smuzhiyun */
691*4882a593Smuzhiyun np = pci_device_to_OF_node(pdev);
692*4882a593Smuzhiyun if (np == NULL)
693*4882a593Smuzhiyun return -ENODEV;
694*4882a593Smuzhiyun
695*4882a593Smuzhiyun /* The above assumption is wrong !!!
696*4882a593Smuzhiyun * fix that here for now until I fix the arch code
697*4882a593Smuzhiyun */
698*4882a593Smuzhiyun of_node_get(np);
699*4882a593Smuzhiyun
700*4882a593Smuzhiyun /* We also assume that pmac_feature will have done a get() on nodes
701*4882a593Smuzhiyun * stored in the macio chips array
702*4882a593Smuzhiyun */
703*4882a593Smuzhiyun chip = macio_find(np, macio_unknown);
704*4882a593Smuzhiyun of_node_put(np);
705*4882a593Smuzhiyun if (chip == NULL)
706*4882a593Smuzhiyun return -ENODEV;
707*4882a593Smuzhiyun
708*4882a593Smuzhiyun /* XXX Need locking ??? */
709*4882a593Smuzhiyun if (chip->lbus.pdev == NULL) {
710*4882a593Smuzhiyun chip->lbus.pdev = pdev;
711*4882a593Smuzhiyun chip->lbus.chip = chip;
712*4882a593Smuzhiyun pci_set_drvdata(pdev, &chip->lbus);
713*4882a593Smuzhiyun pci_set_master(pdev);
714*4882a593Smuzhiyun }
715*4882a593Smuzhiyun
716*4882a593Smuzhiyun printk(KERN_INFO "MacIO PCI driver attached to %s chipset\n",
717*4882a593Smuzhiyun chip->name);
718*4882a593Smuzhiyun
719*4882a593Smuzhiyun /*
720*4882a593Smuzhiyun * HACK ALERT: The WallStreet PowerBook and some OHare based machines
721*4882a593Smuzhiyun * have 2 macio ASICs. I must probe the "main" one first or IDE
722*4882a593Smuzhiyun * ordering will be incorrect. So I put on "hold" the second one since
723*4882a593Smuzhiyun * it seem to appear first on PCI
724*4882a593Smuzhiyun */
725*4882a593Smuzhiyun if (chip->type == macio_gatwick || chip->type == macio_ohareII)
726*4882a593Smuzhiyun if (macio_chips[0].lbus.pdev == NULL) {
727*4882a593Smuzhiyun macio_on_hold = chip;
728*4882a593Smuzhiyun return 0;
729*4882a593Smuzhiyun }
730*4882a593Smuzhiyun
731*4882a593Smuzhiyun macio_pci_add_devices(chip);
732*4882a593Smuzhiyun if (macio_on_hold && macio_chips[0].lbus.pdev != NULL) {
733*4882a593Smuzhiyun macio_pci_add_devices(macio_on_hold);
734*4882a593Smuzhiyun macio_on_hold = NULL;
735*4882a593Smuzhiyun }
736*4882a593Smuzhiyun
737*4882a593Smuzhiyun return 0;
738*4882a593Smuzhiyun }
739*4882a593Smuzhiyun
macio_pci_remove(struct pci_dev * pdev)740*4882a593Smuzhiyun static void macio_pci_remove(struct pci_dev* pdev)
741*4882a593Smuzhiyun {
742*4882a593Smuzhiyun panic("removing of macio-asic not supported !\n");
743*4882a593Smuzhiyun }
744*4882a593Smuzhiyun
745*4882a593Smuzhiyun /*
746*4882a593Smuzhiyun * MacIO is matched against any Apple ID, it's probe() function
747*4882a593Smuzhiyun * will then decide wether it applies or not
748*4882a593Smuzhiyun */
749*4882a593Smuzhiyun static const struct pci_device_id pci_ids[] = { {
750*4882a593Smuzhiyun .vendor = PCI_VENDOR_ID_APPLE,
751*4882a593Smuzhiyun .device = PCI_ANY_ID,
752*4882a593Smuzhiyun .subvendor = PCI_ANY_ID,
753*4882a593Smuzhiyun .subdevice = PCI_ANY_ID,
754*4882a593Smuzhiyun
755*4882a593Smuzhiyun }, { /* end: all zeroes */ }
756*4882a593Smuzhiyun };
757*4882a593Smuzhiyun MODULE_DEVICE_TABLE (pci, pci_ids);
758*4882a593Smuzhiyun
759*4882a593Smuzhiyun /* pci driver glue; this is a "new style" PCI driver module */
760*4882a593Smuzhiyun static struct pci_driver macio_pci_driver = {
761*4882a593Smuzhiyun .name = (char *) "macio",
762*4882a593Smuzhiyun .id_table = pci_ids,
763*4882a593Smuzhiyun
764*4882a593Smuzhiyun .probe = macio_pci_probe,
765*4882a593Smuzhiyun .remove = macio_pci_remove,
766*4882a593Smuzhiyun };
767*4882a593Smuzhiyun
768*4882a593Smuzhiyun #endif /* CONFIG_PCI */
769*4882a593Smuzhiyun
macio_module_init(void)770*4882a593Smuzhiyun static int __init macio_module_init (void)
771*4882a593Smuzhiyun {
772*4882a593Smuzhiyun #ifdef CONFIG_PCI
773*4882a593Smuzhiyun int rc;
774*4882a593Smuzhiyun
775*4882a593Smuzhiyun rc = pci_register_driver(&macio_pci_driver);
776*4882a593Smuzhiyun if (rc)
777*4882a593Smuzhiyun return rc;
778*4882a593Smuzhiyun #endif /* CONFIG_PCI */
779*4882a593Smuzhiyun return 0;
780*4882a593Smuzhiyun }
781*4882a593Smuzhiyun
782*4882a593Smuzhiyun module_init(macio_module_init);
783*4882a593Smuzhiyun
784*4882a593Smuzhiyun EXPORT_SYMBOL(macio_register_driver);
785*4882a593Smuzhiyun EXPORT_SYMBOL(macio_unregister_driver);
786*4882a593Smuzhiyun EXPORT_SYMBOL(macio_dev_get);
787*4882a593Smuzhiyun EXPORT_SYMBOL(macio_dev_put);
788*4882a593Smuzhiyun EXPORT_SYMBOL(macio_request_resource);
789*4882a593Smuzhiyun EXPORT_SYMBOL(macio_release_resource);
790*4882a593Smuzhiyun EXPORT_SYMBOL(macio_request_resources);
791*4882a593Smuzhiyun EXPORT_SYMBOL(macio_release_resources);
792*4882a593Smuzhiyun EXPORT_SYMBOL(macio_enable_devres);
793*4882a593Smuzhiyun
794