Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #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. Miller | 2b1e597 | 2006-06-29 15:07:37 -0700 | [diff] [blame] | 6 | #include <asm/prom.h> |
| 7 | #include <asm/of_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #include <asm/isa.h> |
| 9 | |
| 10 | struct sparc_isa_bridge *isa_chain; |
| 11 | |
| 12 | static void __init fatal_err(const char *reason) |
| 13 | { |
| 14 | prom_printf("ISA: fatal error, %s.\n", reason); |
| 15 | } |
| 16 | |
| 17 | static void __init report_dev(struct sparc_isa_device *isa_dev, int child) |
| 18 | { |
| 19 | if (child) |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 20 | printk(" (%s)", isa_dev->prom_node->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | else |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 22 | printk(" [%s", isa_dev->prom_node->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | } |
| 24 | |
David S. Miller | f4060c0 | 2006-12-28 21:43:51 -0800 | [diff] [blame] | 25 | static void __init isa_dev_get_resource(struct sparc_isa_device *isa_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | { |
David S. Miller | deb66c4 | 2007-02-28 18:01:38 -0800 | [diff] [blame] | 27 | struct of_device *op = of_find_device_by_node(isa_dev->prom_node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | |
David S. Miller | deb66c4 | 2007-02-28 18:01:38 -0800 | [diff] [blame] | 29 | memcpy(&isa_dev->resource, &op->resource[0], sizeof(struct resource)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | } |
| 31 | |
David S. Miller | f4060c0 | 2006-12-28 21:43:51 -0800 | [diff] [blame] | 32 | static void __init isa_dev_get_irq(struct sparc_isa_device *isa_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | { |
David S. Miller | 2b1e597 | 2006-06-29 15:07:37 -0700 | [diff] [blame] | 34 | struct of_device *op = of_find_device_by_node(isa_dev->prom_node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
David S. Miller | 2b1e597 | 2006-06-29 15:07:37 -0700 | [diff] [blame] | 36 | if (!op || !op->num_irqs) { |
| 37 | isa_dev->irq = PCI_IRQ_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | } else { |
David S. Miller | 2b1e597 | 2006-06-29 15:07:37 -0700 | [diff] [blame] | 39 | isa_dev->irq = op->irqs[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | static void __init isa_fill_children(struct sparc_isa_device *parent_isa_dev) |
| 44 | { |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 45 | struct device_node *dp = parent_isa_dev->prom_node->child; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 47 | if (!dp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | return; |
| 49 | |
| 50 | printk(" ->"); |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 51 | while (dp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | struct sparc_isa_device *isa_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
Yan Burman | 982c206 | 2006-11-30 17:13:09 -0800 | [diff] [blame] | 54 | isa_dev = kzalloc(sizeof(*isa_dev), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | if (!isa_dev) { |
| 56 | fatal_err("cannot allocate child isa_dev"); |
| 57 | prom_halt(); |
| 58 | } |
| 59 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | /* Link it in to parent. */ |
| 61 | isa_dev->next = parent_isa_dev->child; |
| 62 | parent_isa_dev->child = isa_dev; |
| 63 | |
| 64 | isa_dev->bus = parent_isa_dev->bus; |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 65 | isa_dev->prom_node = dp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
David S. Miller | f4060c0 | 2006-12-28 21:43:51 -0800 | [diff] [blame] | 67 | isa_dev_get_resource(isa_dev); |
| 68 | isa_dev_get_irq(isa_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
| 70 | report_dev(isa_dev, 1); |
| 71 | |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 72 | dp = dp->sibling; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | } |
| 74 | } |
| 75 | |
| 76 | static void __init isa_fill_devices(struct sparc_isa_bridge *isa_br) |
| 77 | { |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 78 | struct device_node *dp = isa_br->prom_node->child; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 80 | while (dp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | struct sparc_isa_device *isa_dev; |
David S. Miller | 3d6e470 | 2007-07-18 22:03:25 -0700 | [diff] [blame^] | 82 | struct dev_archdata *sd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | |
Yan Burman | 982c206 | 2006-11-30 17:13:09 -0800 | [diff] [blame] | 84 | isa_dev = kzalloc(sizeof(*isa_dev), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | if (!isa_dev) { |
David S. Miller | a2bd4fd | 2006-06-23 01:44:10 -0700 | [diff] [blame] | 86 | printk(KERN_DEBUG "ISA: cannot allocate isa_dev"); |
| 87 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | } |
| 89 | |
David S. Miller | 3d6e470 | 2007-07-18 22:03:25 -0700 | [diff] [blame^] | 90 | sd = &isa_dev->ofdev.dev.archdata; |
| 91 | sd->prom_node = dp; |
| 92 | sd->op = &isa_dev->ofdev; |
| 93 | |
David S. Miller | a2bd4fd | 2006-06-23 01:44:10 -0700 | [diff] [blame] | 94 | isa_dev->ofdev.node = dp; |
| 95 | isa_dev->ofdev.dev.parent = &isa_br->ofdev.dev; |
| 96 | isa_dev->ofdev.dev.bus = &isa_bus_type; |
David S. Miller | f5ef9d1 | 2006-10-27 01:03:31 -0700 | [diff] [blame] | 97 | sprintf(isa_dev->ofdev.dev.bus_id, "isa[%08x]", dp->node); |
David S. Miller | a2bd4fd | 2006-06-23 01:44:10 -0700 | [diff] [blame] | 98 | |
| 99 | /* Register with core */ |
| 100 | if (of_device_register(&isa_dev->ofdev) != 0) { |
| 101 | printk(KERN_DEBUG "isa: device registration error for %s!\n", |
David S. Miller | f5ef9d1 | 2006-10-27 01:03:31 -0700 | [diff] [blame] | 102 | dp->path_component_name); |
David S. Miller | a2bd4fd | 2006-06-23 01:44:10 -0700 | [diff] [blame] | 103 | kfree(isa_dev); |
| 104 | goto next_sibling; |
| 105 | } |
| 106 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | /* Link it in. */ |
| 108 | isa_dev->next = NULL; |
| 109 | if (isa_br->devices == NULL) { |
| 110 | isa_br->devices = isa_dev; |
| 111 | } else { |
| 112 | struct sparc_isa_device *tmp = isa_br->devices; |
| 113 | |
| 114 | while (tmp->next) |
| 115 | tmp = tmp->next; |
| 116 | |
| 117 | tmp->next = isa_dev; |
| 118 | } |
| 119 | |
| 120 | isa_dev->bus = isa_br; |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 121 | isa_dev->prom_node = dp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | |
David S. Miller | f4060c0 | 2006-12-28 21:43:51 -0800 | [diff] [blame] | 123 | isa_dev_get_resource(isa_dev); |
| 124 | isa_dev_get_irq(isa_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | |
| 126 | report_dev(isa_dev, 0); |
| 127 | |
| 128 | isa_fill_children(isa_dev); |
| 129 | |
| 130 | printk("]"); |
| 131 | |
David S. Miller | a2bd4fd | 2006-06-23 01:44:10 -0700 | [diff] [blame] | 132 | next_sibling: |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 133 | dp = dp->sibling; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | } |
| 135 | } |
| 136 | |
| 137 | void __init isa_init(void) |
| 138 | { |
| 139 | struct pci_dev *pdev; |
| 140 | unsigned short vendor, device; |
| 141 | int index = 0; |
| 142 | |
| 143 | vendor = PCI_VENDOR_ID_AL; |
| 144 | device = PCI_DEVICE_ID_AL_M1533; |
| 145 | |
| 146 | pdev = NULL; |
| 147 | while ((pdev = pci_get_device(vendor, device, pdev)) != NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | struct sparc_isa_bridge *isa_br; |
David S. Miller | a2bd4fd | 2006-06-23 01:44:10 -0700 | [diff] [blame] | 149 | struct device_node *dp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | |
David S. Miller | deb66c4 | 2007-02-28 18:01:38 -0800 | [diff] [blame] | 151 | dp = pci_device_to_OF_node(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | |
Yan Burman | 982c206 | 2006-11-30 17:13:09 -0800 | [diff] [blame] | 153 | isa_br = kzalloc(sizeof(*isa_br), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | if (!isa_br) { |
David S. Miller | a2bd4fd | 2006-06-23 01:44:10 -0700 | [diff] [blame] | 155 | printk(KERN_DEBUG "isa: cannot allocate sparc_isa_bridge"); |
| 156 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | } |
| 158 | |
David S. Miller | a2bd4fd | 2006-06-23 01:44:10 -0700 | [diff] [blame] | 159 | isa_br->ofdev.node = dp; |
| 160 | isa_br->ofdev.dev.parent = &pdev->dev; |
| 161 | isa_br->ofdev.dev.bus = &isa_bus_type; |
David S. Miller | f5ef9d1 | 2006-10-27 01:03:31 -0700 | [diff] [blame] | 162 | sprintf(isa_br->ofdev.dev.bus_id, "isa%d", index); |
David S. Miller | a2bd4fd | 2006-06-23 01:44:10 -0700 | [diff] [blame] | 163 | |
| 164 | /* Register with core */ |
| 165 | if (of_device_register(&isa_br->ofdev) != 0) { |
| 166 | printk(KERN_DEBUG "isa: device registration error for %s!\n", |
David S. Miller | f5ef9d1 | 2006-10-27 01:03:31 -0700 | [diff] [blame] | 167 | dp->path_component_name); |
David S. Miller | a2bd4fd | 2006-06-23 01:44:10 -0700 | [diff] [blame] | 168 | kfree(isa_br); |
| 169 | return; |
| 170 | } |
| 171 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | /* Link it in. */ |
| 173 | isa_br->next = isa_chain; |
| 174 | isa_chain = isa_br; |
| 175 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | isa_br->self = pdev; |
| 177 | isa_br->index = index++; |
David S. Miller | deb66c4 | 2007-02-28 18:01:38 -0800 | [diff] [blame] | 178 | isa_br->prom_node = dp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | printk("isa%d:", isa_br->index); |
| 181 | |
| 182 | isa_fill_devices(isa_br); |
| 183 | |
| 184 | printk("\n"); |
| 185 | } |
| 186 | } |