2 * FILE NAME: ocp-probe.c
4 * BRIEF MODULE DESCRIPTION:
5 * Device scanning & bus set routines
6 * Based on drivers/pci/probe, Copyright (c) 1997--1999 Martin Mares
8 * Maintained by: Armin <akuster@mvista.com>
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.
32 #include <linux/init.h>
33 #include <linux/slab.h>
34 #include <linux/module.h>
35 #include <linux/device.h>
38 LIST_HEAD(ocp_devices);
39 struct device *ocp_bus;
41 static struct ocp_device * __devinit
42 ocp_setup_dev(struct ocp_def *odef, unsigned int index)
44 struct ocp_device *dev;
46 dev = kmalloc(sizeof(*dev), GFP_KERNEL);
49 memset(dev, 0, sizeof(*dev));
51 dev->vendor = odef->vendor;
52 dev->device = odef->device;
53 dev->num = ocp_get_num(dev->device);
54 dev->paddr = odef->paddr;
57 dev->current_state = 4;
59 sprintf(dev->name, "OCP device %04x:%04x", dev->vendor, dev->device);
61 DBG("%s %s 0x%lx irq:%d pm:0x%lx \n", dev->slot_name, dev->name,
62 (unsigned long) dev->paddr, dev->irq, dev->pm);
64 /* now put in global tree */
65 sprintf(dev->dev.bus_id, "%d", index);
66 dev->dev.parent = ocp_bus;
67 dev->dev.bus = &ocp_bus_type;
68 device_register(&dev->dev);
73 static struct device * __devinit ocp_alloc_primary_bus(void)
77 b = kmalloc(sizeof(struct device), GFP_KERNEL);
80 memset(b, 0, sizeof(struct device));
81 strcpy(b->bus_id, "ocp");
88 void __devinit ocp_setup_devices(struct ocp_def *odef)
91 struct ocp_device *dev;
94 ocp_bus = ocp_alloc_primary_bus();
95 for (index = 0; odef->vendor != OCP_VENDOR_INVALID; ++index, ++odef) {
96 dev = ocp_setup_dev(odef, index);
98 list_add_tail(&dev->global_list, &ocp_devices);
102 extern struct ocp_def core_ocp[];
107 ocp_setup_devices(core_ocp);
111 subsys_initcall(ocparch_init);
113 EXPORT_SYMBOL(ocp_devices);