blob: 98721a8f8619122b56852f7f8e99c1200a9cfada [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#include <linux/kernel.h>
2#include <linux/init.h>
3#include <linux/pci.h>
4#include <linux/slab.h>
5#include <asm/oplib.h>
David S. Miller2b1e5972006-06-29 15:07:37 -07006#include <asm/prom.h>
7#include <asm/of_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#include <asm/isa.h>
9
10struct sparc_isa_bridge *isa_chain;
11
12static void __init fatal_err(const char *reason)
13{
14 prom_printf("ISA: fatal error, %s.\n", reason);
15}
16
17static void __init report_dev(struct sparc_isa_device *isa_dev, int child)
18{
19 if (child)
David S. Miller690c8fd2006-06-22 19:12:03 -070020 printk(" (%s)", isa_dev->prom_node->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -070021 else
David S. Miller690c8fd2006-06-22 19:12:03 -070022 printk(" [%s", isa_dev->prom_node->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -070023}
24
David S. Millerf4060c02006-12-28 21:43:51 -080025static void __init isa_dev_get_resource(struct sparc_isa_device *isa_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070026{
David S. Miller690c8fd2006-06-22 19:12:03 -070027 struct linux_prom_registers *pregs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 unsigned long base, len;
29 int prop_len;
30
David S. Miller690c8fd2006-06-22 19:12:03 -070031 pregs = of_get_property(isa_dev->prom_node, "reg", &prop_len);
David S. Millerf4060c02006-12-28 21:43:51 -080032 if (!pregs)
33 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
35 /* Only the first one is interesting. */
36 len = pregs[0].reg_size;
37 base = (((unsigned long)pregs[0].which_io << 32) |
38 (unsigned long)pregs[0].phys_addr);
39 base += isa_dev->bus->parent->io_space.start;
40
41 isa_dev->resource.start = base;
42 isa_dev->resource.end = (base + len - 1UL);
43 isa_dev->resource.flags = IORESOURCE_IO;
David S. Miller690c8fd2006-06-22 19:12:03 -070044 isa_dev->resource.name = isa_dev->prom_node->name;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
46 request_resource(&isa_dev->bus->parent->io_space,
47 &isa_dev->resource);
48}
49
David S. Millerf4060c02006-12-28 21:43:51 -080050static void __init isa_dev_get_irq(struct sparc_isa_device *isa_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070051{
David S. Miller2b1e5972006-06-29 15:07:37 -070052 struct of_device *op = of_find_device_by_node(isa_dev->prom_node);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
David S. Miller2b1e5972006-06-29 15:07:37 -070054 if (!op || !op->num_irqs) {
55 isa_dev->irq = PCI_IRQ_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 } else {
David S. Miller2b1e5972006-06-29 15:07:37 -070057 isa_dev->irq = op->irqs[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070059}
60
61static void __init isa_fill_children(struct sparc_isa_device *parent_isa_dev)
62{
David S. Miller690c8fd2006-06-22 19:12:03 -070063 struct device_node *dp = parent_isa_dev->prom_node->child;
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
David S. Miller690c8fd2006-06-22 19:12:03 -070065 if (!dp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 return;
67
68 printk(" ->");
David S. Miller690c8fd2006-06-22 19:12:03 -070069 while (dp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 struct sparc_isa_device *isa_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
Yan Burman982c2062006-11-30 17:13:09 -080072 isa_dev = kzalloc(sizeof(*isa_dev), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 if (!isa_dev) {
74 fatal_err("cannot allocate child isa_dev");
75 prom_halt();
76 }
77
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 /* Link it in to parent. */
79 isa_dev->next = parent_isa_dev->child;
80 parent_isa_dev->child = isa_dev;
81
82 isa_dev->bus = parent_isa_dev->bus;
David S. Miller690c8fd2006-06-22 19:12:03 -070083 isa_dev->prom_node = dp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
David S. Millerf4060c02006-12-28 21:43:51 -080085 isa_dev_get_resource(isa_dev);
86 isa_dev_get_irq(isa_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
88 report_dev(isa_dev, 1);
89
David S. Miller690c8fd2006-06-22 19:12:03 -070090 dp = dp->sibling;
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 }
92}
93
94static void __init isa_fill_devices(struct sparc_isa_bridge *isa_br)
95{
David S. Miller690c8fd2006-06-22 19:12:03 -070096 struct device_node *dp = isa_br->prom_node->child;
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
David S. Miller690c8fd2006-06-22 19:12:03 -070098 while (dp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 struct sparc_isa_device *isa_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
Yan Burman982c2062006-11-30 17:13:09 -0800101 isa_dev = kzalloc(sizeof(*isa_dev), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 if (!isa_dev) {
David S. Millera2bd4fd2006-06-23 01:44:10 -0700103 printk(KERN_DEBUG "ISA: cannot allocate isa_dev");
104 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 }
106
David S. Millera2bd4fd2006-06-23 01:44:10 -0700107 isa_dev->ofdev.node = dp;
108 isa_dev->ofdev.dev.parent = &isa_br->ofdev.dev;
109 isa_dev->ofdev.dev.bus = &isa_bus_type;
David S. Millerf5ef9d12006-10-27 01:03:31 -0700110 sprintf(isa_dev->ofdev.dev.bus_id, "isa[%08x]", dp->node);
David S. Millera2bd4fd2006-06-23 01:44:10 -0700111
112 /* Register with core */
113 if (of_device_register(&isa_dev->ofdev) != 0) {
114 printk(KERN_DEBUG "isa: device registration error for %s!\n",
David S. Millerf5ef9d12006-10-27 01:03:31 -0700115 dp->path_component_name);
David S. Millera2bd4fd2006-06-23 01:44:10 -0700116 kfree(isa_dev);
117 goto next_sibling;
118 }
119
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 /* Link it in. */
121 isa_dev->next = NULL;
122 if (isa_br->devices == NULL) {
123 isa_br->devices = isa_dev;
124 } else {
125 struct sparc_isa_device *tmp = isa_br->devices;
126
127 while (tmp->next)
128 tmp = tmp->next;
129
130 tmp->next = isa_dev;
131 }
132
133 isa_dev->bus = isa_br;
David S. Miller690c8fd2006-06-22 19:12:03 -0700134 isa_dev->prom_node = dp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
David S. Millerf4060c02006-12-28 21:43:51 -0800136 isa_dev_get_resource(isa_dev);
137 isa_dev_get_irq(isa_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
139 report_dev(isa_dev, 0);
140
141 isa_fill_children(isa_dev);
142
143 printk("]");
144
David S. Millera2bd4fd2006-06-23 01:44:10 -0700145 next_sibling:
David S. Miller690c8fd2006-06-22 19:12:03 -0700146 dp = dp->sibling;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 }
148}
149
150void __init isa_init(void)
151{
152 struct pci_dev *pdev;
153 unsigned short vendor, device;
154 int index = 0;
155
156 vendor = PCI_VENDOR_ID_AL;
157 device = PCI_DEVICE_ID_AL_M1533;
158
159 pdev = NULL;
160 while ((pdev = pci_get_device(vendor, device, pdev)) != NULL) {
161 struct pcidev_cookie *pdev_cookie;
162 struct pci_pbm_info *pbm;
163 struct sparc_isa_bridge *isa_br;
David S. Millera2bd4fd2006-06-23 01:44:10 -0700164 struct device_node *dp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
166 pdev_cookie = pdev->sysdata;
167 if (!pdev_cookie) {
168 printk("ISA: Warning, ISA bridge ignored due to "
169 "lack of OBP data.\n");
170 continue;
171 }
172 pbm = pdev_cookie->pbm;
David S. Millera2bd4fd2006-06-23 01:44:10 -0700173 dp = pdev_cookie->prom_node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
Yan Burman982c2062006-11-30 17:13:09 -0800175 isa_br = kzalloc(sizeof(*isa_br), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 if (!isa_br) {
David S. Millera2bd4fd2006-06-23 01:44:10 -0700177 printk(KERN_DEBUG "isa: cannot allocate sparc_isa_bridge");
178 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 }
180
David S. Millera2bd4fd2006-06-23 01:44:10 -0700181 isa_br->ofdev.node = dp;
182 isa_br->ofdev.dev.parent = &pdev->dev;
183 isa_br->ofdev.dev.bus = &isa_bus_type;
David S. Millerf5ef9d12006-10-27 01:03:31 -0700184 sprintf(isa_br->ofdev.dev.bus_id, "isa%d", index);
David S. Millera2bd4fd2006-06-23 01:44:10 -0700185
186 /* Register with core */
187 if (of_device_register(&isa_br->ofdev) != 0) {
188 printk(KERN_DEBUG "isa: device registration error for %s!\n",
David S. Millerf5ef9d12006-10-27 01:03:31 -0700189 dp->path_component_name);
David S. Millera2bd4fd2006-06-23 01:44:10 -0700190 kfree(isa_br);
191 return;
192 }
193
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 /* Link it in. */
195 isa_br->next = isa_chain;
196 isa_chain = isa_br;
197
198 isa_br->parent = pbm;
199 isa_br->self = pdev;
200 isa_br->index = index++;
David S. Miller690c8fd2006-06-22 19:12:03 -0700201 isa_br->prom_node = pdev_cookie->prom_node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 printk("isa%d:", isa_br->index);
204
205 isa_fill_devices(isa_br);
206
207 printk("\n");
208 }
209}