1 #include <linux/kernel.h>
2 #include <linux/init.h>
4 #include <linux/slab.h>
7 #include <asm/of_device.h>
10 struct sparc_isa_bridge
*isa_chain
;
12 static void __init
fatal_err(const char *reason
)
14 prom_printf("ISA: fatal error, %s.\n", reason
);
17 static void __init
report_dev(struct sparc_isa_device
*isa_dev
, int child
)
20 printk(" (%s)", isa_dev
->prom_node
->name
);
22 printk(" [%s", isa_dev
->prom_node
->name
);
25 static void __init
isa_dev_get_resource(struct sparc_isa_device
*isa_dev
)
27 struct linux_prom_registers
*pregs
;
28 unsigned long base
, len
;
31 pregs
= of_get_property(isa_dev
->prom_node
, "reg", &prop_len
);
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
;
41 isa_dev
->resource
.start
= base
;
42 isa_dev
->resource
.end
= (base
+ len
- 1UL);
43 isa_dev
->resource
.flags
= IORESOURCE_IO
;
44 isa_dev
->resource
.name
= isa_dev
->prom_node
->name
;
46 request_resource(&isa_dev
->bus
->parent
->io_space
,
50 static void __init
isa_dev_get_irq(struct sparc_isa_device
*isa_dev
)
52 struct of_device
*op
= of_find_device_by_node(isa_dev
->prom_node
);
54 if (!op
|| !op
->num_irqs
) {
55 isa_dev
->irq
= PCI_IRQ_NONE
;
57 isa_dev
->irq
= op
->irqs
[0];
61 static void __init
isa_fill_children(struct sparc_isa_device
*parent_isa_dev
)
63 struct device_node
*dp
= parent_isa_dev
->prom_node
->child
;
70 struct sparc_isa_device
*isa_dev
;
72 isa_dev
= kzalloc(sizeof(*isa_dev
), GFP_KERNEL
);
74 fatal_err("cannot allocate child isa_dev");
78 /* Link it in to parent. */
79 isa_dev
->next
= parent_isa_dev
->child
;
80 parent_isa_dev
->child
= isa_dev
;
82 isa_dev
->bus
= parent_isa_dev
->bus
;
83 isa_dev
->prom_node
= dp
;
85 isa_dev_get_resource(isa_dev
);
86 isa_dev_get_irq(isa_dev
);
88 report_dev(isa_dev
, 1);
94 static void __init
isa_fill_devices(struct sparc_isa_bridge
*isa_br
)
96 struct device_node
*dp
= isa_br
->prom_node
->child
;
99 struct sparc_isa_device
*isa_dev
;
101 isa_dev
= kzalloc(sizeof(*isa_dev
), GFP_KERNEL
);
103 printk(KERN_DEBUG
"ISA: cannot allocate isa_dev");
107 isa_dev
->ofdev
.node
= dp
;
108 isa_dev
->ofdev
.dev
.parent
= &isa_br
->ofdev
.dev
;
109 isa_dev
->ofdev
.dev
.bus
= &isa_bus_type
;
110 sprintf(isa_dev
->ofdev
.dev
.bus_id
, "isa[%08x]", dp
->node
);
112 /* Register with core */
113 if (of_device_register(&isa_dev
->ofdev
) != 0) {
114 printk(KERN_DEBUG
"isa: device registration error for %s!\n",
115 dp
->path_component_name
);
121 isa_dev
->next
= NULL
;
122 if (isa_br
->devices
== NULL
) {
123 isa_br
->devices
= isa_dev
;
125 struct sparc_isa_device
*tmp
= isa_br
->devices
;
133 isa_dev
->bus
= isa_br
;
134 isa_dev
->prom_node
= dp
;
136 isa_dev_get_resource(isa_dev
);
137 isa_dev_get_irq(isa_dev
);
139 report_dev(isa_dev
, 0);
141 isa_fill_children(isa_dev
);
150 void __init
isa_init(void)
152 struct pci_dev
*pdev
;
153 unsigned short vendor
, device
;
156 vendor
= PCI_VENDOR_ID_AL
;
157 device
= PCI_DEVICE_ID_AL_M1533
;
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
;
164 struct device_node
*dp
;
166 pdev_cookie
= pdev
->sysdata
;
168 printk("ISA: Warning, ISA bridge ignored due to "
169 "lack of OBP data.\n");
172 pbm
= pdev_cookie
->pbm
;
173 dp
= pdev_cookie
->prom_node
;
175 isa_br
= kzalloc(sizeof(*isa_br
), GFP_KERNEL
);
177 printk(KERN_DEBUG
"isa: cannot allocate sparc_isa_bridge");
181 isa_br
->ofdev
.node
= dp
;
182 isa_br
->ofdev
.dev
.parent
= &pdev
->dev
;
183 isa_br
->ofdev
.dev
.bus
= &isa_bus_type
;
184 sprintf(isa_br
->ofdev
.dev
.bus_id
, "isa%d", index
);
186 /* Register with core */
187 if (of_device_register(&isa_br
->ofdev
) != 0) {
188 printk(KERN_DEBUG
"isa: device registration error for %s!\n",
189 dp
->path_component_name
);
195 isa_br
->next
= isa_chain
;
198 isa_br
->parent
= pbm
;
200 isa_br
->index
= index
++;
201 isa_br
->prom_node
= pdev_cookie
->prom_node
;
203 printk("isa%d:", isa_br
->index
);
205 isa_fill_devices(isa_br
);