blob: cc5498347acb414e2ca456e0d5b08d962444a7a5 [file] [log] [blame]
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +02001/*
2 * Industry-pack bus support functions.
3 *
Samuel Iglesias Gonsalvez76859722012-11-16 16:19:58 +01004 * Copyright (C) 2011-2012 CERN (www.cern.ch)
5 * Author: Samuel Iglesias Gonsalvez <siglesias@igalia.com>
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +02006 *
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 Gonsalvez416289b2012-05-11 10:17:13 +02009 * Software Foundation; version 2 of the License.
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020010 */
11
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020012#include <linux/module.h>
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +020013#include <linux/slab.h>
Samuel Iglesias Gonsalvez3b86bb22012-05-25 10:03:01 +020014#include <linux/idr.h>
Johan Meiring0a8f4a02012-11-11 22:41:12 +020015#include <linux/io.h>
Samuel Iglesias Gonsalvez7dbce022012-11-16 19:33:45 +010016#include <linux/ipack.h>
17#include "ipack_ids.h"
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020018
19#define to_ipack_dev(device) container_of(device, struct ipack_device, dev)
20#define to_ipack_driver(drv) container_of(drv, struct ipack_driver, driver)
21
Samuel Iglesias Gonsalvez3b86bb22012-05-25 10:03:01 +020022static DEFINE_IDA(ipack_ida);
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020023
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +020024static void ipack_device_release(struct device *dev)
25{
26 struct ipack_device *device = to_ipack_dev(dev);
Jens Taprogge187e4782012-09-04 17:01:14 +020027 kfree(device->id);
Jens Taprogge1e917952012-09-27 12:37:26 +020028 device->release(device);
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +020029}
30
Jens Taprogge4aa09d42012-09-04 17:01:19 +020031static inline const struct ipack_device_id *
32ipack_match_one_device(const struct ipack_device_id *id,
33 const struct ipack_device *device)
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020034{
Jens Taprogge5948ae22012-09-07 10:29:19 +020035 if ((id->format == IPACK_ANY_FORMAT ||
36 id->format == device->id_format) &&
Jens Taprogge4aa09d42012-09-04 17:01:19 +020037 (id->vendor == IPACK_ANY_ID || id->vendor == device->id_vendor) &&
38 (id->device == IPACK_ANY_ID || id->device == device->id_device))
39 return id;
40 return NULL;
41}
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020042
Jens Taprogge4aa09d42012-09-04 17:01:19 +020043static const struct ipack_device_id *
44ipack_match_id(const struct ipack_device_id *ids, struct ipack_device *idev)
45{
46 if (ids) {
47 while (ids->vendor || ids->device) {
48 if (ipack_match_one_device(ids, idev))
49 return ids;
50 ids++;
51 }
52 }
53 return NULL;
54}
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020055
Jens Taprogge4aa09d42012-09-04 17:01:19 +020056static int ipack_bus_match(struct device *dev, struct device_driver *drv)
57{
58 struct ipack_device *idev = to_ipack_dev(dev);
59 struct ipack_driver *idrv = to_ipack_driver(drv);
60 const struct ipack_device_id *found_id;
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020061
Jens Taprogge4aa09d42012-09-04 17:01:19 +020062 found_id = ipack_match_id(idrv->id_table, idev);
Jens Taprogge3bea7fc2012-09-11 13:34:59 +020063 return found_id ? 1 : 0;
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020064}
65
66static int ipack_bus_probe(struct device *device)
67{
68 struct ipack_device *dev = to_ipack_dev(device);
Jens Taprogge3bea7fc2012-09-11 13:34:59 +020069 struct ipack_driver *drv = to_ipack_driver(device->driver);
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020070
Jens Taprogge3bea7fc2012-09-11 13:34:59 +020071 if (!drv->ops->probe)
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020072 return -EINVAL;
73
Jens Taprogge3bea7fc2012-09-11 13:34:59 +020074 return drv->ops->probe(dev);
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020075}
76
77static int ipack_bus_remove(struct device *device)
78{
79 struct ipack_device *dev = to_ipack_dev(device);
Jens Taprogge3bea7fc2012-09-11 13:34:59 +020080 struct ipack_driver *drv = to_ipack_driver(device->driver);
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020081
Jens Taprogge3bea7fc2012-09-11 13:34:59 +020082 if (!drv->ops->remove)
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020083 return -EINVAL;
84
Jens Taprogge3bea7fc2012-09-11 13:34:59 +020085 drv->ops->remove(dev);
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020086 return 0;
87}
88
Jens Taprogge35eb97b2012-09-04 17:01:20 +020089static int ipack_uevent(struct device *dev, struct kobj_uevent_env *env)
90{
91 struct ipack_device *idev;
92
93 if (!dev)
94 return -ENODEV;
95
96 idev = to_ipack_dev(dev);
97
98 if (add_uevent_var(env,
99 "MODALIAS=ipack:f%02Xv%08Xd%08X", idev->id_format,
100 idev->id_vendor, idev->id_device))
101 return -ENOMEM;
102
103 return 0;
104}
105
Jens Taproggee8ed3272012-09-04 17:01:15 +0200106#define ipack_device_attr(field, format_string) \
107static ssize_t \
108field##_show(struct device *dev, struct device_attribute *attr, \
109 char *buf) \
110{ \
111 struct ipack_device *idev = to_ipack_dev(dev); \
112 return sprintf(buf, format_string, idev->field); \
113}
114
Jens Taprogge5d72c8482012-09-04 17:01:21 +0200115static ssize_t id_show(struct device *dev,
116 struct device_attribute *attr, char *buf)
117{
118 unsigned int i, c, l, s;
119 struct ipack_device *idev = to_ipack_dev(dev);
120
121
122 switch (idev->id_format) {
123 case IPACK_ID_VERSION_1:
124 l = 0x7; s = 1; break;
125 case IPACK_ID_VERSION_2:
126 l = 0xf; s = 2; break;
127 default:
128 return -EIO;
129 }
130 c = 0;
131 for (i = 0; i < idev->id_avail; i++) {
132 if (i > 0) {
133 if ((i & l) == 0)
134 buf[c++] = '\n';
135 else if ((i & s) == 0)
136 buf[c++] = ' ';
137 }
138 sprintf(&buf[c], "%02x", idev->id[i]);
139 c += 2;
140 }
141 buf[c++] = '\n';
142 return c;
143}
144
Jens Taproggee8ed3272012-09-04 17:01:15 +0200145static ssize_t
146id_vendor_show(struct device *dev, struct device_attribute *attr, char *buf)
147{
148 struct ipack_device *idev = to_ipack_dev(dev);
149 switch (idev->id_format) {
150 case IPACK_ID_VERSION_1:
151 return sprintf(buf, "0x%02x\n", idev->id_vendor);
152 case IPACK_ID_VERSION_2:
153 return sprintf(buf, "0x%06x\n", idev->id_vendor);
154 default:
155 return -EIO;
156 }
157}
158
159static ssize_t
160id_device_show(struct device *dev, struct device_attribute *attr, char *buf)
161{
162 struct ipack_device *idev = to_ipack_dev(dev);
163 switch (idev->id_format) {
164 case IPACK_ID_VERSION_1:
165 return sprintf(buf, "0x%02x\n", idev->id_device);
166 case IPACK_ID_VERSION_2:
167 return sprintf(buf, "0x%04x\n", idev->id_device);
168 default:
169 return -EIO;
170 }
171}
172
Jens Taprogge35eb97b2012-09-04 17:01:20 +0200173static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
174 char *buf)
175{
176 struct ipack_device *idev = to_ipack_dev(dev);
177
178 return sprintf(buf, "ipac:f%02Xv%08Xd%08X", idev->id_format,
179 idev->id_vendor, idev->id_device);
180}
181
Jens Taproggee8ed3272012-09-04 17:01:15 +0200182ipack_device_attr(id_format, "0x%hhu\n");
183
184static struct device_attribute ipack_dev_attrs[] = {
Jens Taprogge5d72c8482012-09-04 17:01:21 +0200185 __ATTR_RO(id),
Jens Taproggee8ed3272012-09-04 17:01:15 +0200186 __ATTR_RO(id_device),
187 __ATTR_RO(id_format),
188 __ATTR_RO(id_vendor),
Jens Taprogge35eb97b2012-09-04 17:01:20 +0200189 __ATTR_RO(modalias),
Jens Taproggee8ed3272012-09-04 17:01:15 +0200190};
191
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200192static struct bus_type ipack_bus_type = {
Jens Taproggee8ed3272012-09-04 17:01:15 +0200193 .name = "ipack",
194 .probe = ipack_bus_probe,
195 .match = ipack_bus_match,
196 .remove = ipack_bus_remove,
197 .dev_attrs = ipack_dev_attrs,
Jens Taprogge35eb97b2012-09-04 17:01:20 +0200198 .uevent = ipack_uevent,
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200199};
200
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +0200201struct ipack_bus_device *ipack_bus_register(struct device *parent, int slots,
Stephen Hemminger9869a932012-09-10 11:14:01 -0700202 const struct ipack_bus_ops *ops)
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200203{
204 int bus_nr;
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +0200205 struct ipack_bus_device *bus;
206
207 bus = kzalloc(sizeof(struct ipack_bus_device), GFP_KERNEL);
208 if (!bus)
209 return NULL;
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200210
Samuel Iglesias Gonsalvez3b86bb22012-05-25 10:03:01 +0200211 bus_nr = ida_simple_get(&ipack_ida, 0, 0, GFP_KERNEL);
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +0200212 if (bus_nr < 0) {
213 kfree(bus);
214 return NULL;
215 }
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200216
217 bus->bus_nr = bus_nr;
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +0200218 bus->parent = parent;
219 bus->slots = slots;
220 bus->ops = ops;
221 return bus;
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200222}
223EXPORT_SYMBOL_GPL(ipack_bus_register);
224
Samuel Iglesias Gonsálvezbffe0fd2012-09-11 13:35:09 +0200225static int ipack_unregister_bus_member(struct device *dev, void *data)
226{
227 struct ipack_device *idev = to_ipack_dev(dev);
228 struct ipack_bus_device *bus = data;
229
Jens Taproggef9e314d2012-09-27 12:37:25 +0200230 if (idev->bus == bus)
Samuel Iglesias Gonsálvezbffe0fd2012-09-11 13:35:09 +0200231 ipack_device_unregister(idev);
232
233 return 1;
234}
235
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200236int ipack_bus_unregister(struct ipack_bus_device *bus)
237{
Johan Meiring0a8f4a02012-11-11 22:41:12 +0200238 bus_for_each_dev(&ipack_bus_type, NULL, bus,
239 ipack_unregister_bus_member);
Samuel Iglesias Gonsalvez3b86bb22012-05-25 10:03:01 +0200240 ida_simple_remove(&ipack_ida, bus->bus_nr);
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +0200241 kfree(bus);
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200242 return 0;
243}
244EXPORT_SYMBOL_GPL(ipack_bus_unregister);
245
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +0200246int ipack_driver_register(struct ipack_driver *edrv, struct module *owner,
Stephen Hemminger9869a932012-09-10 11:14:01 -0700247 const char *name)
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200248{
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +0200249 edrv->driver.owner = owner;
250 edrv->driver.name = name;
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200251 edrv->driver.bus = &ipack_bus_type;
252 return driver_register(&edrv->driver);
253}
254EXPORT_SYMBOL_GPL(ipack_driver_register);
255
256void ipack_driver_unregister(struct ipack_driver *edrv)
257{
258 driver_unregister(&edrv->driver);
259}
260EXPORT_SYMBOL_GPL(ipack_driver_unregister);
261
Jens Taproggea92caeb2012-09-11 13:35:03 +0200262static u16 ipack_crc_byte(u16 crc, u8 c)
263{
264 int i;
265
266 crc ^= c << 8;
267 for (i = 0; i < 8; i++)
268 crc = (crc << 1) ^ ((crc & 0x8000) ? 0x1021 : 0);
269 return crc;
270}
271
272/*
273 * The algorithm in lib/crc-ccitt.c does not seem to apply since it uses the
274 * opposite bit ordering.
275 */
276static u8 ipack_calc_crc1(struct ipack_device *dev)
277{
278 u8 c;
279 u16 crc;
280 unsigned int i;
281
282 crc = 0xffff;
283 for (i = 0; i < dev->id_avail; i++) {
284 c = (i != 11) ? dev->id[i] : 0;
285 crc = ipack_crc_byte(crc, c);
286 }
287 crc = ~crc;
288 return crc & 0xff;
289}
290
291static u16 ipack_calc_crc2(struct ipack_device *dev)
292{
293 u8 c;
294 u16 crc;
295 unsigned int i;
296
297 crc = 0xffff;
298 for (i = 0; i < dev->id_avail; i++) {
299 c = ((i != 0x18) && (i != 0x19)) ? dev->id[i] : 0;
300 crc = ipack_crc_byte(crc, c);
301 }
302 crc = ~crc;
303 return crc;
304}
305
Jens Taproggee8ed3272012-09-04 17:01:15 +0200306static void ipack_parse_id1(struct ipack_device *dev)
307{
308 u8 *id = dev->id;
Jens Taproggea92caeb2012-09-11 13:35:03 +0200309 u8 crc;
Jens Taproggee8ed3272012-09-04 17:01:15 +0200310
311 dev->id_vendor = id[4];
312 dev->id_device = id[5];
Jens Taprogge0b0f3a12012-09-11 13:34:57 +0200313 dev->speed_8mhz = 1;
314 dev->speed_32mhz = (id[7] == 'H');
Jens Taproggea92caeb2012-09-11 13:35:03 +0200315 crc = ipack_calc_crc1(dev);
316 dev->id_crc_correct = (crc == id[11]);
317 if (!dev->id_crc_correct) {
318 dev_warn(&dev->dev, "ID CRC invalid found 0x%x, expected 0x%x.\n",
319 id[11], crc);
320 }
Jens Taproggee8ed3272012-09-04 17:01:15 +0200321}
322
323static void ipack_parse_id2(struct ipack_device *dev)
324{
325 __be16 *id = (__be16 *) dev->id;
Jens Taproggea92caeb2012-09-11 13:35:03 +0200326 u16 flags, crc;
Jens Taproggee8ed3272012-09-04 17:01:15 +0200327
328 dev->id_vendor = ((be16_to_cpu(id[3]) & 0xff) << 16)
329 + be16_to_cpu(id[4]);
330 dev->id_device = be16_to_cpu(id[5]);
Jens Taprogge0b0f3a12012-09-11 13:34:57 +0200331 flags = be16_to_cpu(id[10]);
332 dev->speed_8mhz = !!(flags & 2);
333 dev->speed_32mhz = !!(flags & 4);
Jens Taproggea92caeb2012-09-11 13:35:03 +0200334 crc = ipack_calc_crc2(dev);
335 dev->id_crc_correct = (crc == be16_to_cpu(id[12]));
336 if (!dev->id_crc_correct) {
337 dev_warn(&dev->dev, "ID CRC invalid found 0x%x, expected 0x%x.\n",
338 id[11], crc);
339 }
Jens Taproggee8ed3272012-09-04 17:01:15 +0200340}
341
Jens Taprogge187e4782012-09-04 17:01:14 +0200342static int ipack_device_read_id(struct ipack_device *dev)
343{
344 u8 __iomem *idmem;
345 int i;
346 int ret = 0;
347
Jens Taprogge402228d2012-09-27 12:37:34 +0200348 idmem = ioremap(dev->region[IPACK_ID_SPACE].start,
349 dev->region[IPACK_ID_SPACE].size);
350 if (!idmem) {
Jens Taprogge187e4782012-09-04 17:01:14 +0200351 dev_err(&dev->dev, "error mapping memory\n");
Samuel Iglesias Gonsalvez58b2c0c2012-09-27 12:37:41 +0200352 return -ENOMEM;
Jens Taprogge187e4782012-09-04 17:01:14 +0200353 }
Jens Taprogge187e4782012-09-04 17:01:14 +0200354
355 /* Determine ID PROM Data Format. If we find the ids "IPAC" or "IPAH"
356 * we are dealing with a IndustryPack format 1 device. If we detect
357 * "VITA4 " (16 bit big endian formatted) we are dealing with a
358 * IndustryPack format 2 device */
359 if ((ioread8(idmem + 1) == 'I') &&
360 (ioread8(idmem + 3) == 'P') &&
361 (ioread8(idmem + 5) == 'A') &&
362 ((ioread8(idmem + 7) == 'C') ||
363 (ioread8(idmem + 7) == 'H'))) {
364 dev->id_format = IPACK_ID_VERSION_1;
365 dev->id_avail = ioread8(idmem + 0x15);
366 if ((dev->id_avail < 0x0c) || (dev->id_avail > 0x40)) {
367 dev_warn(&dev->dev, "invalid id size");
368 dev->id_avail = 0x0c;
369 }
370 } else if ((ioread8(idmem + 0) == 'I') &&
371 (ioread8(idmem + 1) == 'V') &&
372 (ioread8(idmem + 2) == 'A') &&
373 (ioread8(idmem + 3) == 'T') &&
374 (ioread8(idmem + 4) == ' ') &&
375 (ioread8(idmem + 5) == '4')) {
376 dev->id_format = IPACK_ID_VERSION_2;
377 dev->id_avail = ioread16be(idmem + 0x16);
378 if ((dev->id_avail < 0x1a) || (dev->id_avail > 0x40)) {
379 dev_warn(&dev->dev, "invalid id size");
380 dev->id_avail = 0x1a;
381 }
382 } else {
383 dev->id_format = IPACK_ID_VERSION_INVALID;
384 dev->id_avail = 0;
385 }
386
387 if (!dev->id_avail) {
388 ret = -ENODEV;
389 goto out;
390 }
391
392 /* Obtain the amount of memory required to store a copy of the complete
393 * ID ROM contents */
394 dev->id = kmalloc(dev->id_avail, GFP_KERNEL);
395 if (!dev->id) {
396 dev_err(&dev->dev, "dev->id alloc failed.\n");
397 ret = -ENOMEM;
398 goto out;
399 }
400 for (i = 0; i < dev->id_avail; i++) {
401 if (dev->id_format == IPACK_ID_VERSION_1)
402 dev->id[i] = ioread8(idmem + (i << 1) + 1);
403 else
404 dev->id[i] = ioread8(idmem + i);
405 }
406
Jens Taproggee8ed3272012-09-04 17:01:15 +0200407 /* now we can finally work with the copy */
408 switch (dev->id_format) {
409 case IPACK_ID_VERSION_1:
410 ipack_parse_id1(dev);
411 break;
412 case IPACK_ID_VERSION_2:
413 ipack_parse_id2(dev);
414 break;
415 }
416
Jens Taprogge187e4782012-09-04 17:01:14 +0200417out:
Jens Taprogge402228d2012-09-27 12:37:34 +0200418 iounmap(idmem);
Jens Taprogge187e4782012-09-04 17:01:14 +0200419
420 return ret;
421}
422
Jens Taprogge1e917952012-09-27 12:37:26 +0200423int ipack_device_register(struct ipack_device *dev)
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200424{
425 int ret;
426
427 dev->dev.bus = &ipack_bus_type;
428 dev->dev.release = ipack_device_release;
Jens Taprogge1e917952012-09-27 12:37:26 +0200429 dev->dev.parent = dev->bus->parent;
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200430 dev_set_name(&dev->dev,
Jens Taproggef9e314d2012-09-27 12:37:25 +0200431 "ipack-dev.%u.%u", dev->bus->bus_nr, dev->slot);
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200432
Jens Taprogge1e917952012-09-27 12:37:26 +0200433 if (dev->bus->ops->set_clockrate(dev, 8))
Jens Taprogge07766ab2012-09-11 13:35:01 +0200434 dev_warn(&dev->dev, "failed to switch to 8 MHz operation for reading of device ID.\n");
Jens Taprogge1e917952012-09-27 12:37:26 +0200435 if (dev->bus->ops->reset_timeout(dev))
Jens Taprogge8a3ae162012-09-11 13:35:02 +0200436 dev_warn(&dev->dev, "failed to reset potential timeout.");
Jens Taprogge07766ab2012-09-11 13:35:01 +0200437
Jens Taprogge187e4782012-09-04 17:01:14 +0200438 ret = ipack_device_read_id(dev);
439 if (ret < 0) {
440 dev_err(&dev->dev, "error reading device id section.\n");
Jens Taprogge1e917952012-09-27 12:37:26 +0200441 return ret;
Jens Taprogge187e4782012-09-04 17:01:14 +0200442 }
443
Jens Taprogge90cb6192012-09-11 13:34:58 +0200444 /* if the device supports 32 MHz operation, use it. */
Jens Taprogge07766ab2012-09-11 13:35:01 +0200445 if (dev->speed_32mhz) {
Jens Taprogge1e917952012-09-27 12:37:26 +0200446 ret = dev->bus->ops->set_clockrate(dev, 32);
Jens Taprogge07766ab2012-09-11 13:35:01 +0200447 if (ret < 0)
448 dev_err(&dev->dev, "failed to switch to 32 MHz operation.\n");
449 }
Jens Taprogge90cb6192012-09-11 13:34:58 +0200450
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200451 ret = device_register(&dev->dev);
Jens Taprogge1e917952012-09-27 12:37:26 +0200452 if (ret < 0)
Jens Taprogge187e4782012-09-04 17:01:14 +0200453 kfree(dev->id);
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200454
Jens Taprogge1e917952012-09-27 12:37:26 +0200455 return ret;
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200456}
457EXPORT_SYMBOL_GPL(ipack_device_register);
458
459void ipack_device_unregister(struct ipack_device *dev)
460{
461 device_unregister(&dev->dev);
462}
463EXPORT_SYMBOL_GPL(ipack_device_unregister);
464
465static int __init ipack_init(void)
466{
Samuel Iglesias Gonsalvez3b86bb22012-05-25 10:03:01 +0200467 ida_init(&ipack_ida);
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200468 return bus_register(&ipack_bus_type);
469}
470
471static void __exit ipack_exit(void)
472{
473 bus_unregister(&ipack_bus_type);
Samuel Iglesias Gonsalvez3b86bb22012-05-25 10:03:01 +0200474 ida_destroy(&ipack_ida);
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200475}
476
477module_init(ipack_init);
478module_exit(ipack_exit);
479
480MODULE_AUTHOR("Samuel Iglesias Gonsalvez <siglesias@igalia.com>");
481MODULE_LICENSE("GPL");
482MODULE_DESCRIPTION("Industry-pack bus core");