Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * EISA bus support functions for sysfs. |
| 3 | * |
| 4 | * (C) 2002, 2003 Marc Zyngier <maz@wild-wind.fr.eu.org> |
| 5 | * |
| 6 | * This code is released under the GPL version 2. |
| 7 | */ |
| 8 | |
| 9 | #include <linux/kernel.h> |
| 10 | #include <linux/device.h> |
| 11 | #include <linux/eisa.h> |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/moduleparam.h> |
| 14 | #include <linux/init.h> |
| 15 | #include <linux/slab.h> |
| 16 | #include <linux/ioport.h> |
| 17 | #include <asm/io.h> |
| 18 | |
| 19 | #define SLOT_ADDRESS(r,n) (r->bus_base_addr + (0x1000 * n)) |
| 20 | |
| 21 | #define EISA_DEVINFO(i,s) { .id = { .sig = i }, .name = s } |
| 22 | |
| 23 | struct eisa_device_info { |
| 24 | struct eisa_device_id id; |
Kay Sievers | ca52a49 | 2008-05-02 06:02:41 +0200 | [diff] [blame] | 25 | char name[50]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | }; |
| 27 | |
| 28 | #ifdef CONFIG_EISA_NAMES |
| 29 | static struct eisa_device_info __initdata eisa_table[] = { |
| 30 | #include "devlist.h" |
| 31 | }; |
| 32 | #define EISA_INFOS (sizeof (eisa_table) / (sizeof (struct eisa_device_info))) |
| 33 | #endif |
| 34 | |
| 35 | #define EISA_MAX_FORCED_DEV 16 |
| 36 | |
| 37 | static int enable_dev[EISA_MAX_FORCED_DEV]; |
Al Viro | 64a6f95 | 2007-10-14 19:35:30 +0100 | [diff] [blame] | 38 | static unsigned int enable_dev_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | static int disable_dev[EISA_MAX_FORCED_DEV]; |
Al Viro | 64a6f95 | 2007-10-14 19:35:30 +0100 | [diff] [blame] | 40 | static unsigned int disable_dev_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 42 | static int is_forced_dev(int *forced_tab, |
| 43 | int forced_count, |
| 44 | struct eisa_root_device *root, |
| 45 | struct eisa_device *edev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | { |
| 47 | int i, x; |
| 48 | |
| 49 | for (i = 0; i < forced_count; i++) { |
| 50 | x = (root->bus_nr << 8) | edev->slot; |
| 51 | if (forced_tab[i] == x) |
| 52 | return 1; |
| 53 | } |
| 54 | |
| 55 | return 0; |
| 56 | } |
| 57 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 58 | static void __init eisa_name_device(struct eisa_device *edev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | { |
| 60 | #ifdef CONFIG_EISA_NAMES |
| 61 | int i; |
| 62 | for (i = 0; i < EISA_INFOS; i++) { |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 63 | if (!strcmp(edev->id.sig, eisa_table[i].id.sig)) { |
| 64 | strlcpy(edev->pretty_name, |
| 65 | eisa_table[i].name, |
| 66 | sizeof(edev->pretty_name)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | return; |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | /* No name was found */ |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 72 | sprintf(edev->pretty_name, "EISA device %.7s", edev->id.sig); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | #endif |
| 74 | } |
| 75 | |
| 76 | static char __init *decode_eisa_sig(unsigned long addr) |
| 77 | { |
| 78 | static char sig_str[EISA_SIG_LEN]; |
| 79 | u8 sig[4]; |
| 80 | u16 rev; |
| 81 | int i; |
| 82 | |
| 83 | for (i = 0; i < 4; i++) { |
| 84 | #ifdef CONFIG_EISA_VLB_PRIMING |
| 85 | /* |
| 86 | * This ugly stuff is used to wake up VL-bus cards |
| 87 | * (AHA-284x is the only known example), so we can |
| 88 | * read the EISA id. |
| 89 | * |
| 90 | * Thankfully, this only exists on x86... |
| 91 | */ |
| 92 | outb(0x80 + i, addr); |
| 93 | #endif |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 94 | sig[i] = inb(addr + i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
| 96 | if (!i && (sig[0] & 0x80)) |
| 97 | return NULL; |
| 98 | } |
| 99 | |
| 100 | sig_str[0] = ((sig[0] >> 2) & 0x1f) + ('A' - 1); |
| 101 | sig_str[1] = (((sig[0] & 3) << 3) | (sig[1] >> 5)) + ('A' - 1); |
| 102 | sig_str[2] = (sig[1] & 0x1f) + ('A' - 1); |
| 103 | rev = (sig[2] << 8) | sig[3]; |
| 104 | sprintf(sig_str + 3, "%04X", rev); |
| 105 | |
| 106 | return sig_str; |
| 107 | } |
| 108 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 109 | static int eisa_bus_match(struct device *dev, struct device_driver *drv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | { |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 111 | struct eisa_device *edev = to_eisa_device(dev); |
| 112 | struct eisa_driver *edrv = to_eisa_driver(drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | const struct eisa_device_id *eids = edrv->id_table; |
| 114 | |
| 115 | if (!eids) |
| 116 | return 0; |
| 117 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 118 | while (strlen(eids->sig)) { |
| 119 | if (!strcmp(eids->sig, edev->id.sig) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | edev->state & EISA_CONFIG_ENABLED) { |
| 121 | edev->id.driver_data = eids->driver_data; |
| 122 | return 1; |
| 123 | } |
| 124 | |
| 125 | eids++; |
| 126 | } |
| 127 | |
| 128 | return 0; |
| 129 | } |
| 130 | |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 131 | static int eisa_bus_uevent(struct device *dev, struct kobj_uevent_env *env) |
Michael Tokarev | 07563c7 | 2006-09-27 01:50:56 -0700 | [diff] [blame] | 132 | { |
| 133 | struct eisa_device *edev = to_eisa_device(dev); |
Michael Tokarev | 07563c7 | 2006-09-27 01:50:56 -0700 | [diff] [blame] | 134 | |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 135 | add_uevent_var(env, "MODALIAS=" EISA_DEVICE_MODALIAS_FMT, edev->id.sig); |
Michael Tokarev | 07563c7 | 2006-09-27 01:50:56 -0700 | [diff] [blame] | 136 | return 0; |
| 137 | } |
| 138 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | struct bus_type eisa_bus_type = { |
| 140 | .name = "eisa", |
| 141 | .match = eisa_bus_match, |
Michael Tokarev | 07563c7 | 2006-09-27 01:50:56 -0700 | [diff] [blame] | 142 | .uevent = eisa_bus_uevent, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | }; |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 144 | EXPORT_SYMBOL(eisa_bus_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 146 | int eisa_driver_register(struct eisa_driver *edrv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | edrv->driver.bus = &eisa_bus_type; |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 149 | return driver_register(&edrv->driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | } |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 151 | EXPORT_SYMBOL(eisa_driver_register); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 153 | void eisa_driver_unregister(struct eisa_driver *edrv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | { |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 155 | driver_unregister(&edrv->driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | } |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 157 | EXPORT_SYMBOL(eisa_driver_unregister); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 159 | static ssize_t eisa_show_sig(struct device *dev, struct device_attribute *attr, |
| 160 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | { |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 162 | struct eisa_device *edev = to_eisa_device(dev); |
| 163 | return sprintf(buf, "%s\n", edev->id.sig); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | static DEVICE_ATTR(signature, S_IRUGO, eisa_show_sig, NULL); |
| 167 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 168 | static ssize_t eisa_show_state(struct device *dev, |
| 169 | struct device_attribute *attr, |
| 170 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | { |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 172 | struct eisa_device *edev = to_eisa_device(dev); |
| 173 | return sprintf(buf, "%d\n", edev->state & EISA_CONFIG_ENABLED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | static DEVICE_ATTR(enabled, S_IRUGO, eisa_show_state, NULL); |
| 177 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 178 | static ssize_t eisa_show_modalias(struct device *dev, |
| 179 | struct device_attribute *attr, |
| 180 | char *buf) |
Michael Tokarev | 07563c7 | 2006-09-27 01:50:56 -0700 | [diff] [blame] | 181 | { |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 182 | struct eisa_device *edev = to_eisa_device(dev); |
| 183 | return sprintf(buf, EISA_DEVICE_MODALIAS_FMT "\n", edev->id.sig); |
Michael Tokarev | 07563c7 | 2006-09-27 01:50:56 -0700 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | static DEVICE_ATTR(modalias, S_IRUGO, eisa_show_modalias, NULL); |
| 187 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 188 | static int __init eisa_init_device(struct eisa_root_device *root, |
| 189 | struct eisa_device *edev, |
| 190 | int slot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | { |
| 192 | char *sig; |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 193 | unsigned long sig_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | int i; |
| 195 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 196 | sig_addr = SLOT_ADDRESS(root, slot) + EISA_VENDOR_ID_OFFSET; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 198 | sig = decode_eisa_sig(sig_addr); |
| 199 | if (!sig) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | return -1; /* No EISA device here */ |
| 201 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 202 | memcpy(edev->id.sig, sig, EISA_SIG_LEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | edev->slot = slot; |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 204 | edev->state = inb(SLOT_ADDRESS(root, slot) + EISA_CONFIG_OFFSET) |
| 205 | & EISA_CONFIG_ENABLED; |
| 206 | edev->base_addr = SLOT_ADDRESS(root, slot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | edev->dma_mask = root->dma_mask; /* Default DMA mask */ |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 208 | eisa_name_device(edev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | edev->dev.parent = root->dev; |
| 210 | edev->dev.bus = &eisa_bus_type; |
| 211 | edev->dev.dma_mask = &edev->dma_mask; |
| 212 | edev->dev.coherent_dma_mask = edev->dma_mask; |
Kay Sievers | e537b24 | 2009-03-24 16:38:22 -0700 | [diff] [blame] | 213 | dev_set_name(&edev->dev, "%02X:%02X", root->bus_nr, slot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | |
| 215 | for (i = 0; i < EISA_MAX_RESOURCES; i++) { |
| 216 | #ifdef CONFIG_EISA_NAMES |
| 217 | edev->res[i].name = edev->pretty_name; |
| 218 | #else |
| 219 | edev->res[i].name = edev->id.sig; |
| 220 | #endif |
| 221 | } |
| 222 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 223 | if (is_forced_dev(enable_dev, enable_dev_count, root, edev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | edev->state = EISA_CONFIG_ENABLED | EISA_CONFIG_FORCED; |
| 225 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 226 | if (is_forced_dev(disable_dev, disable_dev_count, root, edev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | edev->state = EISA_CONFIG_FORCED; |
| 228 | |
| 229 | return 0; |
| 230 | } |
| 231 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 232 | static int __init eisa_register_device(struct eisa_device *edev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | { |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 234 | int rc = device_register(&edev->dev); |
Jeff Garzik | 42ddfd6 | 2006-10-11 01:22:22 -0700 | [diff] [blame] | 235 | if (rc) |
| 236 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 238 | rc = device_create_file(&edev->dev, &dev_attr_signature); |
| 239 | if (rc) |
| 240 | goto err_devreg; |
| 241 | rc = device_create_file(&edev->dev, &dev_attr_enabled); |
| 242 | if (rc) |
| 243 | goto err_sig; |
| 244 | rc = device_create_file(&edev->dev, &dev_attr_modalias); |
| 245 | if (rc) |
| 246 | goto err_enab; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | |
| 248 | return 0; |
Jeff Garzik | 42ddfd6 | 2006-10-11 01:22:22 -0700 | [diff] [blame] | 249 | |
| 250 | err_enab: |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 251 | device_remove_file(&edev->dev, &dev_attr_enabled); |
Jeff Garzik | 42ddfd6 | 2006-10-11 01:22:22 -0700 | [diff] [blame] | 252 | err_sig: |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 253 | device_remove_file(&edev->dev, &dev_attr_signature); |
Jeff Garzik | 42ddfd6 | 2006-10-11 01:22:22 -0700 | [diff] [blame] | 254 | err_devreg: |
| 255 | device_unregister(&edev->dev); |
| 256 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | } |
| 258 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 259 | static int __init eisa_request_resources(struct eisa_root_device *root, |
| 260 | struct eisa_device *edev, |
| 261 | int slot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | { |
| 263 | int i; |
| 264 | |
| 265 | for (i = 0; i < EISA_MAX_RESOURCES; i++) { |
| 266 | /* Don't register resource for slot 0, since this is |
| 267 | * very likely to fail... :-( Instead, grab the EISA |
| 268 | * id, now we can display something in /proc/ioports. |
| 269 | */ |
| 270 | |
| 271 | /* Only one region for mainboard */ |
| 272 | if (!slot && i > 0) { |
| 273 | edev->res[i].start = edev->res[i].end = 0; |
| 274 | continue; |
| 275 | } |
| 276 | |
| 277 | if (slot) { |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 278 | edev->res[i].start = SLOT_ADDRESS(root, slot) |
| 279 | + (i * 0x400); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | edev->res[i].end = edev->res[i].start + 0xff; |
| 281 | edev->res[i].flags = IORESOURCE_IO; |
| 282 | } else { |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 283 | edev->res[i].start = SLOT_ADDRESS(root, slot) |
| 284 | + EISA_VENDOR_ID_OFFSET; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | edev->res[i].end = edev->res[i].start + 3; |
Bjorn Helgaas | 7666825 | 2013-04-15 14:33:56 -0600 | [diff] [blame] | 286 | edev->res[i].flags = IORESOURCE_IO | IORESOURCE_BUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | } |
| 288 | |
Bjorn Helgaas | a2080d0 | 2013-04-15 14:34:07 -0600 | [diff] [blame] | 289 | dev_printk(KERN_DEBUG, &edev->dev, "%pR\n", &edev->res[i]); |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 290 | if (request_resource(root->res, &edev->res[i])) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | goto failed; |
| 292 | } |
| 293 | |
| 294 | return 0; |
| 295 | |
| 296 | failed: |
| 297 | while (--i >= 0) |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 298 | release_resource(&edev->res[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | |
| 300 | return -1; |
| 301 | } |
| 302 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 303 | static void __init eisa_release_resources(struct eisa_device *edev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | { |
| 305 | int i; |
| 306 | |
| 307 | for (i = 0; i < EISA_MAX_RESOURCES; i++) |
| 308 | if (edev->res[i].start || edev->res[i].end) |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 309 | release_resource(&edev->res[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | } |
| 311 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 312 | static int __init eisa_probe(struct eisa_root_device *root) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | { |
| 314 | int i, c; |
| 315 | struct eisa_device *edev; |
Bjorn Helgaas | 4cf9f24 | 2013-04-15 14:33:42 -0600 | [diff] [blame] | 316 | char *enabled_str; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | |
Bjorn Helgaas | 4cf9f24 | 2013-04-15 14:33:42 -0600 | [diff] [blame] | 318 | dev_info(root->dev, "Probing EISA bus %d\n", root->bus_nr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | |
| 320 | /* First try to get hold of slot 0. If there is no device |
| 321 | * here, simply fail, unless root->force_probe is set. */ |
| 322 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 323 | edev = kzalloc(sizeof(*edev), GFP_KERNEL); |
| 324 | if (!edev) { |
Bjorn Helgaas | 4cf9f24 | 2013-04-15 14:33:42 -0600 | [diff] [blame] | 325 | dev_err(root->dev, "EISA: Couldn't allocate mainboard slot\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | return -ENOMEM; |
| 327 | } |
| 328 | |
Bjorn Helgaas | 26abfee | 2013-04-15 14:34:02 -0600 | [diff] [blame] | 329 | if (eisa_init_device(root, edev, 0)) { |
| 330 | kfree(edev); |
| 331 | if (!root->force_probe) |
| 332 | return -ENODEV; |
| 333 | goto force_probe; |
| 334 | } |
| 335 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 336 | if (eisa_request_resources(root, edev, 0)) { |
Bjorn Helgaas | 4cf9f24 | 2013-04-15 14:33:42 -0600 | [diff] [blame] | 337 | dev_warn(root->dev, |
| 338 | "EISA: Cannot allocate resource for mainboard\n"); |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 339 | kfree(edev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | if (!root->force_probe) |
| 341 | return -EBUSY; |
| 342 | goto force_probe; |
| 343 | } |
| 344 | |
Bjorn Helgaas | 4cf9f24 | 2013-04-15 14:33:42 -0600 | [diff] [blame] | 345 | dev_info(&edev->dev, "EISA: Mainboard %s detected\n", edev->id.sig); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 347 | if (eisa_register_device(edev)) { |
Bjorn Helgaas | 4cf9f24 | 2013-04-15 14:33:42 -0600 | [diff] [blame] | 348 | dev_err(&edev->dev, "EISA: Failed to register %s\n", |
| 349 | edev->id.sig); |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 350 | eisa_release_resources(edev); |
| 351 | kfree(edev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | force_probe: |
| 355 | |
| 356 | for (c = 0, i = 1; i <= root->slots; i++) { |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 357 | edev = kzalloc(sizeof(*edev), GFP_KERNEL); |
| 358 | if (!edev) { |
Bjorn Helgaas | 4cf9f24 | 2013-04-15 14:33:42 -0600 | [diff] [blame] | 359 | dev_err(root->dev, "EISA: Out of memory for slot %d\n", |
| 360 | i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | continue; |
| 362 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | |
Bjorn Helgaas | 26abfee | 2013-04-15 14:34:02 -0600 | [diff] [blame] | 364 | if (eisa_init_device(root, edev, i)) { |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 365 | kfree(edev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | continue; |
| 367 | } |
| 368 | |
Bjorn Helgaas | 26abfee | 2013-04-15 14:34:02 -0600 | [diff] [blame] | 369 | if (eisa_request_resources(root, edev, i)) { |
| 370 | dev_warn(root->dev, |
| 371 | "Cannot allocate resource for EISA slot %d\n", |
| 372 | i); |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 373 | kfree(edev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | continue; |
| 375 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | |
Bjorn Helgaas | 4cf9f24 | 2013-04-15 14:33:42 -0600 | [diff] [blame] | 377 | if (edev->state == (EISA_CONFIG_ENABLED | EISA_CONFIG_FORCED)) |
| 378 | enabled_str = " (forced enabled)"; |
| 379 | else if (edev->state == EISA_CONFIG_FORCED) |
| 380 | enabled_str = " (forced disabled)"; |
| 381 | else if (edev->state == 0) |
| 382 | enabled_str = " (disabled)"; |
| 383 | else |
| 384 | enabled_str = ""; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | |
Bjorn Helgaas | 4cf9f24 | 2013-04-15 14:33:42 -0600 | [diff] [blame] | 386 | dev_info(&edev->dev, "EISA: slot %d: %s detected%s\n", i, |
| 387 | edev->id.sig, enabled_str); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | |
| 389 | c++; |
| 390 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 391 | if (eisa_register_device(edev)) { |
Bjorn Helgaas | 4cf9f24 | 2013-04-15 14:33:42 -0600 | [diff] [blame] | 392 | dev_err(&edev->dev, "EISA: Failed to register %s\n", |
| 393 | edev->id.sig); |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 394 | eisa_release_resources(edev); |
| 395 | kfree(edev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | } |
| 397 | } |
| 398 | |
Bjorn Helgaas | 4cf9f24 | 2013-04-15 14:33:42 -0600 | [diff] [blame] | 399 | dev_info(root->dev, "EISA: Detected %d card%s\n", c, c == 1 ? "" : "s"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | return 0; |
| 401 | } |
| 402 | |
| 403 | static struct resource eisa_root_res = { |
| 404 | .name = "EISA root resource", |
| 405 | .start = 0, |
| 406 | .end = 0xffffffff, |
| 407 | .flags = IORESOURCE_IO, |
| 408 | }; |
| 409 | |
| 410 | static int eisa_bus_count; |
| 411 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 412 | int __init eisa_root_register(struct eisa_root_device *root) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | { |
| 414 | int err; |
| 415 | |
| 416 | /* Use our own resources to check if this bus base address has |
| 417 | * been already registered. This prevents the virtual root |
| 418 | * device from registering after the real one has, for |
| 419 | * example... */ |
| 420 | |
| 421 | root->eisa_root_res.name = eisa_root_res.name; |
| 422 | root->eisa_root_res.start = root->res->start; |
| 423 | root->eisa_root_res.end = root->res->end; |
| 424 | root->eisa_root_res.flags = IORESOURCE_BUSY; |
| 425 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 426 | err = request_resource(&eisa_root_res, &root->eisa_root_res); |
| 427 | if (err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | return err; |
| 429 | |
| 430 | root->bus_nr = eisa_bus_count++; |
| 431 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 432 | err = eisa_probe(root); |
| 433 | if (err) |
| 434 | release_resource(&root->eisa_root_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | |
| 436 | return err; |
| 437 | } |
| 438 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 439 | static int __init eisa_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | { |
| 441 | int r; |
| 442 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 443 | r = bus_register(&eisa_bus_type); |
| 444 | if (r) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | return r; |
| 446 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 447 | printk(KERN_INFO "EISA bus registered\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | return 0; |
| 449 | } |
| 450 | |
| 451 | module_param_array(enable_dev, int, &enable_dev_count, 0444); |
| 452 | module_param_array(disable_dev, int, &disable_dev_count, 0444); |
| 453 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 454 | postcore_initcall(eisa_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | |
| 456 | int EISA_bus; /* for legacy drivers */ |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 457 | EXPORT_SYMBOL(EISA_bus); |