Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Industry-pack bus support functions. |
| 3 | * |
| 4 | * (C) 2011 Samuel Iglesias Gonsalvez <siglesia@cern.ch>, CERN |
| 5 | * (C) 2012 Samuel Iglesias Gonsalvez <siglesias@igalia.com>, Igalia |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License as published by the Free |
Samuel Iglesias Gonsalvez | 416289b | 2012-05-11 10:17:13 +0200 | [diff] [blame] | 9 | * Software Foundation; version 2 of the License. |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 10 | */ |
| 11 | |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 12 | #include <linux/module.h> |
Samuel Iglesias Gonsalvez | ec44033 | 2012-05-18 11:10:05 +0200 | [diff] [blame] | 13 | #include <linux/slab.h> |
Samuel Iglesias Gonsalvez | 3b86bb2 | 2012-05-25 10:03:01 +0200 | [diff] [blame] | 14 | #include <linux/idr.h> |
Samuel Iglesias Gonsálvez | b9f789f | 2012-09-05 09:08:17 +0200 | [diff] [blame] | 15 | #include <asm/io.h> |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 16 | #include "ipack.h" |
| 17 | |
| 18 | #define to_ipack_dev(device) container_of(device, struct ipack_device, dev) |
| 19 | #define to_ipack_driver(drv) container_of(drv, struct ipack_driver, driver) |
| 20 | |
Samuel Iglesias Gonsalvez | 3b86bb2 | 2012-05-25 10:03:01 +0200 | [diff] [blame] | 21 | static DEFINE_IDA(ipack_ida); |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 22 | |
Samuel Iglesias Gonsalvez | ec44033 | 2012-05-18 11:10:05 +0200 | [diff] [blame] | 23 | static void ipack_device_release(struct device *dev) |
| 24 | { |
| 25 | struct ipack_device *device = to_ipack_dev(dev); |
Jens Taprogge | 187e478 | 2012-09-04 17:01:14 +0200 | [diff] [blame] | 26 | kfree(device->id); |
Samuel Iglesias Gonsalvez | ec44033 | 2012-05-18 11:10:05 +0200 | [diff] [blame] | 27 | kfree(device); |
| 28 | } |
| 29 | |
Jens Taprogge | 4aa09d4 | 2012-09-04 17:01:19 +0200 | [diff] [blame] | 30 | static inline const struct ipack_device_id * |
| 31 | ipack_match_one_device(const struct ipack_device_id *id, |
| 32 | const struct ipack_device *device) |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 33 | { |
Jens Taprogge | 5948ae2 | 2012-09-07 10:29:19 +0200 | [diff] [blame] | 34 | if ((id->format == IPACK_ANY_FORMAT || |
| 35 | id->format == device->id_format) && |
Jens Taprogge | 4aa09d4 | 2012-09-04 17:01:19 +0200 | [diff] [blame] | 36 | (id->vendor == IPACK_ANY_ID || id->vendor == device->id_vendor) && |
| 37 | (id->device == IPACK_ANY_ID || id->device == device->id_device)) |
| 38 | return id; |
| 39 | return NULL; |
| 40 | } |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 41 | |
Jens Taprogge | 4aa09d4 | 2012-09-04 17:01:19 +0200 | [diff] [blame] | 42 | static const struct ipack_device_id * |
| 43 | ipack_match_id(const struct ipack_device_id *ids, struct ipack_device *idev) |
| 44 | { |
| 45 | if (ids) { |
| 46 | while (ids->vendor || ids->device) { |
| 47 | if (ipack_match_one_device(ids, idev)) |
| 48 | return ids; |
| 49 | ids++; |
| 50 | } |
| 51 | } |
| 52 | return NULL; |
| 53 | } |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 54 | |
Jens Taprogge | 4aa09d4 | 2012-09-04 17:01:19 +0200 | [diff] [blame] | 55 | static int ipack_bus_match(struct device *dev, struct device_driver *drv) |
| 56 | { |
| 57 | struct ipack_device *idev = to_ipack_dev(dev); |
| 58 | struct ipack_driver *idrv = to_ipack_driver(drv); |
| 59 | const struct ipack_device_id *found_id; |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 60 | |
Jens Taprogge | 4aa09d4 | 2012-09-04 17:01:19 +0200 | [diff] [blame] | 61 | found_id = ipack_match_id(idrv->id_table, idev); |
| 62 | if (found_id) { |
| 63 | idev->driver = idrv; |
| 64 | return 1; |
| 65 | } |
| 66 | |
| 67 | return 0; |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | static int ipack_bus_probe(struct device *device) |
| 71 | { |
| 72 | struct ipack_device *dev = to_ipack_dev(device); |
| 73 | |
| 74 | if (!dev->driver->ops->probe) |
| 75 | return -EINVAL; |
| 76 | |
| 77 | return dev->driver->ops->probe(dev); |
| 78 | } |
| 79 | |
| 80 | static int ipack_bus_remove(struct device *device) |
| 81 | { |
| 82 | struct ipack_device *dev = to_ipack_dev(device); |
| 83 | |
| 84 | if (!dev->driver->ops->remove) |
| 85 | return -EINVAL; |
| 86 | |
| 87 | dev->driver->ops->remove(dev); |
| 88 | return 0; |
| 89 | } |
| 90 | |
Jens Taprogge | 35eb97b | 2012-09-04 17:01:20 +0200 | [diff] [blame] | 91 | #ifdef CONFIG_HOTPLUG |
| 92 | |
| 93 | static int ipack_uevent(struct device *dev, struct kobj_uevent_env *env) |
| 94 | { |
| 95 | struct ipack_device *idev; |
| 96 | |
| 97 | if (!dev) |
| 98 | return -ENODEV; |
| 99 | |
| 100 | idev = to_ipack_dev(dev); |
| 101 | |
| 102 | if (add_uevent_var(env, |
| 103 | "MODALIAS=ipack:f%02Xv%08Xd%08X", idev->id_format, |
| 104 | idev->id_vendor, idev->id_device)) |
| 105 | return -ENOMEM; |
| 106 | |
| 107 | return 0; |
| 108 | } |
| 109 | |
| 110 | #else /* !CONFIG_HOTPLUG */ |
| 111 | |
| 112 | #define ipack_uevent NULL |
| 113 | |
| 114 | #endif /* !CONFIG_HOTPLUG */ |
| 115 | |
Jens Taprogge | e8ed327 | 2012-09-04 17:01:15 +0200 | [diff] [blame] | 116 | #define ipack_device_attr(field, format_string) \ |
| 117 | static ssize_t \ |
| 118 | field##_show(struct device *dev, struct device_attribute *attr, \ |
| 119 | char *buf) \ |
| 120 | { \ |
| 121 | struct ipack_device *idev = to_ipack_dev(dev); \ |
| 122 | return sprintf(buf, format_string, idev->field); \ |
| 123 | } |
| 124 | |
Jens Taprogge | 5d72c848 | 2012-09-04 17:01:21 +0200 | [diff] [blame] | 125 | static ssize_t id_show(struct device *dev, |
| 126 | struct device_attribute *attr, char *buf) |
| 127 | { |
| 128 | unsigned int i, c, l, s; |
| 129 | struct ipack_device *idev = to_ipack_dev(dev); |
| 130 | |
| 131 | |
| 132 | switch (idev->id_format) { |
| 133 | case IPACK_ID_VERSION_1: |
| 134 | l = 0x7; s = 1; break; |
| 135 | case IPACK_ID_VERSION_2: |
| 136 | l = 0xf; s = 2; break; |
| 137 | default: |
| 138 | return -EIO; |
| 139 | } |
| 140 | c = 0; |
| 141 | for (i = 0; i < idev->id_avail; i++) { |
| 142 | if (i > 0) { |
| 143 | if ((i & l) == 0) |
| 144 | buf[c++] = '\n'; |
| 145 | else if ((i & s) == 0) |
| 146 | buf[c++] = ' '; |
| 147 | } |
| 148 | sprintf(&buf[c], "%02x", idev->id[i]); |
| 149 | c += 2; |
| 150 | } |
| 151 | buf[c++] = '\n'; |
| 152 | return c; |
| 153 | } |
| 154 | |
Jens Taprogge | e8ed327 | 2012-09-04 17:01:15 +0200 | [diff] [blame] | 155 | static ssize_t |
| 156 | id_vendor_show(struct device *dev, struct device_attribute *attr, char *buf) |
| 157 | { |
| 158 | struct ipack_device *idev = to_ipack_dev(dev); |
| 159 | switch (idev->id_format) { |
| 160 | case IPACK_ID_VERSION_1: |
| 161 | return sprintf(buf, "0x%02x\n", idev->id_vendor); |
| 162 | case IPACK_ID_VERSION_2: |
| 163 | return sprintf(buf, "0x%06x\n", idev->id_vendor); |
| 164 | default: |
| 165 | return -EIO; |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | static ssize_t |
| 170 | id_device_show(struct device *dev, struct device_attribute *attr, char *buf) |
| 171 | { |
| 172 | struct ipack_device *idev = to_ipack_dev(dev); |
| 173 | switch (idev->id_format) { |
| 174 | case IPACK_ID_VERSION_1: |
| 175 | return sprintf(buf, "0x%02x\n", idev->id_device); |
| 176 | case IPACK_ID_VERSION_2: |
| 177 | return sprintf(buf, "0x%04x\n", idev->id_device); |
| 178 | default: |
| 179 | return -EIO; |
| 180 | } |
| 181 | } |
| 182 | |
Jens Taprogge | 35eb97b | 2012-09-04 17:01:20 +0200 | [diff] [blame] | 183 | static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, |
| 184 | char *buf) |
| 185 | { |
| 186 | struct ipack_device *idev = to_ipack_dev(dev); |
| 187 | |
| 188 | return sprintf(buf, "ipac:f%02Xv%08Xd%08X", idev->id_format, |
| 189 | idev->id_vendor, idev->id_device); |
| 190 | } |
| 191 | |
Jens Taprogge | e8ed327 | 2012-09-04 17:01:15 +0200 | [diff] [blame] | 192 | ipack_device_attr(id_format, "0x%hhu\n"); |
| 193 | |
| 194 | static struct device_attribute ipack_dev_attrs[] = { |
Jens Taprogge | 5d72c848 | 2012-09-04 17:01:21 +0200 | [diff] [blame] | 195 | __ATTR_RO(id), |
Jens Taprogge | e8ed327 | 2012-09-04 17:01:15 +0200 | [diff] [blame] | 196 | __ATTR_RO(id_device), |
| 197 | __ATTR_RO(id_format), |
| 198 | __ATTR_RO(id_vendor), |
Jens Taprogge | 35eb97b | 2012-09-04 17:01:20 +0200 | [diff] [blame] | 199 | __ATTR_RO(modalias), |
Jens Taprogge | e8ed327 | 2012-09-04 17:01:15 +0200 | [diff] [blame] | 200 | }; |
| 201 | |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 202 | static struct bus_type ipack_bus_type = { |
Jens Taprogge | e8ed327 | 2012-09-04 17:01:15 +0200 | [diff] [blame] | 203 | .name = "ipack", |
| 204 | .probe = ipack_bus_probe, |
| 205 | .match = ipack_bus_match, |
| 206 | .remove = ipack_bus_remove, |
| 207 | .dev_attrs = ipack_dev_attrs, |
Jens Taprogge | 35eb97b | 2012-09-04 17:01:20 +0200 | [diff] [blame] | 208 | .uevent = ipack_uevent, |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 209 | }; |
| 210 | |
Samuel Iglesias Gonsalvez | ec44033 | 2012-05-18 11:10:05 +0200 | [diff] [blame] | 211 | struct ipack_bus_device *ipack_bus_register(struct device *parent, int slots, |
Stephen Hemminger | 9869a937 | 2012-09-10 11:14:01 -0700 | [diff] [blame^] | 212 | const struct ipack_bus_ops *ops) |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 213 | { |
| 214 | int bus_nr; |
Samuel Iglesias Gonsalvez | ec44033 | 2012-05-18 11:10:05 +0200 | [diff] [blame] | 215 | struct ipack_bus_device *bus; |
| 216 | |
| 217 | bus = kzalloc(sizeof(struct ipack_bus_device), GFP_KERNEL); |
| 218 | if (!bus) |
| 219 | return NULL; |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 220 | |
Samuel Iglesias Gonsalvez | 3b86bb2 | 2012-05-25 10:03:01 +0200 | [diff] [blame] | 221 | bus_nr = ida_simple_get(&ipack_ida, 0, 0, GFP_KERNEL); |
Samuel Iglesias Gonsalvez | ec44033 | 2012-05-18 11:10:05 +0200 | [diff] [blame] | 222 | if (bus_nr < 0) { |
| 223 | kfree(bus); |
| 224 | return NULL; |
| 225 | } |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 226 | |
| 227 | bus->bus_nr = bus_nr; |
Samuel Iglesias Gonsalvez | ec44033 | 2012-05-18 11:10:05 +0200 | [diff] [blame] | 228 | bus->parent = parent; |
| 229 | bus->slots = slots; |
| 230 | bus->ops = ops; |
| 231 | return bus; |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 232 | } |
| 233 | EXPORT_SYMBOL_GPL(ipack_bus_register); |
| 234 | |
| 235 | int ipack_bus_unregister(struct ipack_bus_device *bus) |
| 236 | { |
Samuel Iglesias Gonsalvez | 3b86bb2 | 2012-05-25 10:03:01 +0200 | [diff] [blame] | 237 | ida_simple_remove(&ipack_ida, bus->bus_nr); |
Samuel Iglesias Gonsalvez | ec44033 | 2012-05-18 11:10:05 +0200 | [diff] [blame] | 238 | kfree(bus); |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 239 | return 0; |
| 240 | } |
| 241 | EXPORT_SYMBOL_GPL(ipack_bus_unregister); |
| 242 | |
Samuel Iglesias Gonsalvez | ec44033 | 2012-05-18 11:10:05 +0200 | [diff] [blame] | 243 | int ipack_driver_register(struct ipack_driver *edrv, struct module *owner, |
Stephen Hemminger | 9869a937 | 2012-09-10 11:14:01 -0700 | [diff] [blame^] | 244 | const char *name) |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 245 | { |
Samuel Iglesias Gonsalvez | ec44033 | 2012-05-18 11:10:05 +0200 | [diff] [blame] | 246 | edrv->driver.owner = owner; |
| 247 | edrv->driver.name = name; |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 248 | edrv->driver.bus = &ipack_bus_type; |
| 249 | return driver_register(&edrv->driver); |
| 250 | } |
| 251 | EXPORT_SYMBOL_GPL(ipack_driver_register); |
| 252 | |
| 253 | void ipack_driver_unregister(struct ipack_driver *edrv) |
| 254 | { |
| 255 | driver_unregister(&edrv->driver); |
| 256 | } |
| 257 | EXPORT_SYMBOL_GPL(ipack_driver_unregister); |
| 258 | |
Jens Taprogge | e8ed327 | 2012-09-04 17:01:15 +0200 | [diff] [blame] | 259 | static void ipack_parse_id1(struct ipack_device *dev) |
| 260 | { |
| 261 | u8 *id = dev->id; |
| 262 | |
| 263 | dev->id_vendor = id[4]; |
| 264 | dev->id_device = id[5]; |
| 265 | } |
| 266 | |
| 267 | static void ipack_parse_id2(struct ipack_device *dev) |
| 268 | { |
| 269 | __be16 *id = (__be16 *) dev->id; |
| 270 | |
| 271 | dev->id_vendor = ((be16_to_cpu(id[3]) & 0xff) << 16) |
| 272 | + be16_to_cpu(id[4]); |
| 273 | dev->id_device = be16_to_cpu(id[5]); |
| 274 | } |
| 275 | |
Jens Taprogge | 187e478 | 2012-09-04 17:01:14 +0200 | [diff] [blame] | 276 | static int ipack_device_read_id(struct ipack_device *dev) |
| 277 | { |
| 278 | u8 __iomem *idmem; |
| 279 | int i; |
| 280 | int ret = 0; |
| 281 | |
| 282 | ret = dev->bus->ops->map_space(dev, 0, IPACK_ID_SPACE); |
| 283 | if (ret) { |
| 284 | dev_err(&dev->dev, "error mapping memory\n"); |
| 285 | return ret; |
| 286 | } |
| 287 | idmem = dev->id_space.address; |
| 288 | |
| 289 | /* Determine ID PROM Data Format. If we find the ids "IPAC" or "IPAH" |
| 290 | * we are dealing with a IndustryPack format 1 device. If we detect |
| 291 | * "VITA4 " (16 bit big endian formatted) we are dealing with a |
| 292 | * IndustryPack format 2 device */ |
| 293 | if ((ioread8(idmem + 1) == 'I') && |
| 294 | (ioread8(idmem + 3) == 'P') && |
| 295 | (ioread8(idmem + 5) == 'A') && |
| 296 | ((ioread8(idmem + 7) == 'C') || |
| 297 | (ioread8(idmem + 7) == 'H'))) { |
| 298 | dev->id_format = IPACK_ID_VERSION_1; |
| 299 | dev->id_avail = ioread8(idmem + 0x15); |
| 300 | if ((dev->id_avail < 0x0c) || (dev->id_avail > 0x40)) { |
| 301 | dev_warn(&dev->dev, "invalid id size"); |
| 302 | dev->id_avail = 0x0c; |
| 303 | } |
| 304 | } else if ((ioread8(idmem + 0) == 'I') && |
| 305 | (ioread8(idmem + 1) == 'V') && |
| 306 | (ioread8(idmem + 2) == 'A') && |
| 307 | (ioread8(idmem + 3) == 'T') && |
| 308 | (ioread8(idmem + 4) == ' ') && |
| 309 | (ioread8(idmem + 5) == '4')) { |
| 310 | dev->id_format = IPACK_ID_VERSION_2; |
| 311 | dev->id_avail = ioread16be(idmem + 0x16); |
| 312 | if ((dev->id_avail < 0x1a) || (dev->id_avail > 0x40)) { |
| 313 | dev_warn(&dev->dev, "invalid id size"); |
| 314 | dev->id_avail = 0x1a; |
| 315 | } |
| 316 | } else { |
| 317 | dev->id_format = IPACK_ID_VERSION_INVALID; |
| 318 | dev->id_avail = 0; |
| 319 | } |
| 320 | |
| 321 | if (!dev->id_avail) { |
| 322 | ret = -ENODEV; |
| 323 | goto out; |
| 324 | } |
| 325 | |
| 326 | /* Obtain the amount of memory required to store a copy of the complete |
| 327 | * ID ROM contents */ |
| 328 | dev->id = kmalloc(dev->id_avail, GFP_KERNEL); |
| 329 | if (!dev->id) { |
| 330 | dev_err(&dev->dev, "dev->id alloc failed.\n"); |
| 331 | ret = -ENOMEM; |
| 332 | goto out; |
| 333 | } |
| 334 | for (i = 0; i < dev->id_avail; i++) { |
| 335 | if (dev->id_format == IPACK_ID_VERSION_1) |
| 336 | dev->id[i] = ioread8(idmem + (i << 1) + 1); |
| 337 | else |
| 338 | dev->id[i] = ioread8(idmem + i); |
| 339 | } |
| 340 | |
Jens Taprogge | e8ed327 | 2012-09-04 17:01:15 +0200 | [diff] [blame] | 341 | /* now we can finally work with the copy */ |
| 342 | switch (dev->id_format) { |
| 343 | case IPACK_ID_VERSION_1: |
| 344 | ipack_parse_id1(dev); |
| 345 | break; |
| 346 | case IPACK_ID_VERSION_2: |
| 347 | ipack_parse_id2(dev); |
| 348 | break; |
| 349 | } |
| 350 | |
Jens Taprogge | 187e478 | 2012-09-04 17:01:14 +0200 | [diff] [blame] | 351 | out: |
| 352 | dev->bus->ops->unmap_space(dev, IPACK_ID_SPACE); |
| 353 | |
| 354 | return ret; |
| 355 | } |
| 356 | |
Samuel Iglesias Gonsalvez | ec44033 | 2012-05-18 11:10:05 +0200 | [diff] [blame] | 357 | struct ipack_device *ipack_device_register(struct ipack_bus_device *bus, |
| 358 | int slot, int irqv) |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 359 | { |
| 360 | int ret; |
Samuel Iglesias Gonsalvez | ec44033 | 2012-05-18 11:10:05 +0200 | [diff] [blame] | 361 | struct ipack_device *dev; |
| 362 | |
| 363 | dev = kzalloc(sizeof(struct ipack_device), GFP_KERNEL); |
| 364 | if (!dev) |
| 365 | return NULL; |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 366 | |
| 367 | dev->dev.bus = &ipack_bus_type; |
| 368 | dev->dev.release = ipack_device_release; |
Samuel Iglesias Gonsalvez | ec44033 | 2012-05-18 11:10:05 +0200 | [diff] [blame] | 369 | dev->dev.parent = bus->parent; |
| 370 | dev->slot = slot; |
| 371 | dev->bus_nr = bus->bus_nr; |
| 372 | dev->irq = irqv; |
| 373 | dev->bus = bus; |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 374 | dev_set_name(&dev->dev, |
Samuel Iglesias Gonsalvez | ec44033 | 2012-05-18 11:10:05 +0200 | [diff] [blame] | 375 | "ipack-dev.%u.%u", dev->bus_nr, dev->slot); |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 376 | |
Jens Taprogge | 187e478 | 2012-09-04 17:01:14 +0200 | [diff] [blame] | 377 | ret = ipack_device_read_id(dev); |
| 378 | if (ret < 0) { |
| 379 | dev_err(&dev->dev, "error reading device id section.\n"); |
| 380 | kfree(dev); |
| 381 | return NULL; |
| 382 | } |
| 383 | |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 384 | ret = device_register(&dev->dev); |
| 385 | if (ret < 0) { |
Jens Taprogge | 187e478 | 2012-09-04 17:01:14 +0200 | [diff] [blame] | 386 | kfree(dev->id); |
Samuel Iglesias Gonsalvez | ec44033 | 2012-05-18 11:10:05 +0200 | [diff] [blame] | 387 | kfree(dev); |
| 388 | return NULL; |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 389 | } |
| 390 | |
Samuel Iglesias Gonsalvez | ec44033 | 2012-05-18 11:10:05 +0200 | [diff] [blame] | 391 | return dev; |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 392 | } |
| 393 | EXPORT_SYMBOL_GPL(ipack_device_register); |
| 394 | |
| 395 | void ipack_device_unregister(struct ipack_device *dev) |
| 396 | { |
| 397 | device_unregister(&dev->dev); |
| 398 | } |
| 399 | EXPORT_SYMBOL_GPL(ipack_device_unregister); |
| 400 | |
| 401 | static int __init ipack_init(void) |
| 402 | { |
Samuel Iglesias Gonsalvez | 3b86bb2 | 2012-05-25 10:03:01 +0200 | [diff] [blame] | 403 | ida_init(&ipack_ida); |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 404 | return bus_register(&ipack_bus_type); |
| 405 | } |
| 406 | |
| 407 | static void __exit ipack_exit(void) |
| 408 | { |
| 409 | bus_unregister(&ipack_bus_type); |
Samuel Iglesias Gonsalvez | 3b86bb2 | 2012-05-25 10:03:01 +0200 | [diff] [blame] | 410 | ida_destroy(&ipack_ida); |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | module_init(ipack_init); |
| 414 | module_exit(ipack_exit); |
| 415 | |
| 416 | MODULE_AUTHOR("Samuel Iglesias Gonsalvez <siglesias@igalia.com>"); |
| 417 | MODULE_LICENSE("GPL"); |
| 418 | MODULE_DESCRIPTION("Industry-pack bus core"); |