blob: d0016ba469edeed10c58fd1ce93c5615dc2735c4 [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>
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020017
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 Gonsalvez3b86bb22012-05-25 10:03:01 +020021static DEFINE_IDA(ipack_ida);
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020022
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +020023static void ipack_device_release(struct device *dev)
24{
25 struct ipack_device *device = to_ipack_dev(dev);
Jens Taprogge187e4782012-09-04 17:01:14 +020026 kfree(device->id);
Jens Taprogge1e917952012-09-27 12:37:26 +020027 device->release(device);
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +020028}
29
Jens Taprogge4aa09d42012-09-04 17:01:19 +020030static inline const struct ipack_device_id *
31ipack_match_one_device(const struct ipack_device_id *id,
32 const struct ipack_device *device)
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020033{
Jens Taprogge5948ae22012-09-07 10:29:19 +020034 if ((id->format == IPACK_ANY_FORMAT ||
35 id->format == device->id_format) &&
Jens Taprogge4aa09d42012-09-04 17:01:19 +020036 (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 Gonsalvezd3465872012-05-09 15:27:19 +020041
Jens Taprogge4aa09d42012-09-04 17:01:19 +020042static const struct ipack_device_id *
43ipack_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 Gonsalvezd3465872012-05-09 15:27:19 +020054
Jens Taprogge4aa09d42012-09-04 17:01:19 +020055static 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 Gonsalvezd3465872012-05-09 15:27:19 +020060
Jens Taprogge4aa09d42012-09-04 17:01:19 +020061 found_id = ipack_match_id(idrv->id_table, idev);
Jens Taprogge3bea7fc2012-09-11 13:34:59 +020062 return found_id ? 1 : 0;
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020063}
64
65static int ipack_bus_probe(struct device *device)
66{
67 struct ipack_device *dev = to_ipack_dev(device);
Jens Taprogge3bea7fc2012-09-11 13:34:59 +020068 struct ipack_driver *drv = to_ipack_driver(device->driver);
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020069
Jens Taprogge3bea7fc2012-09-11 13:34:59 +020070 if (!drv->ops->probe)
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020071 return -EINVAL;
72
Jens Taprogge3bea7fc2012-09-11 13:34:59 +020073 return drv->ops->probe(dev);
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020074}
75
76static int ipack_bus_remove(struct device *device)
77{
78 struct ipack_device *dev = to_ipack_dev(device);
Jens Taprogge3bea7fc2012-09-11 13:34:59 +020079 struct ipack_driver *drv = to_ipack_driver(device->driver);
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020080
Jens Taprogge3bea7fc2012-09-11 13:34:59 +020081 if (!drv->ops->remove)
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020082 return -EINVAL;
83
Jens Taprogge3bea7fc2012-09-11 13:34:59 +020084 drv->ops->remove(dev);
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020085 return 0;
86}
87
Jens Taprogge35eb97b2012-09-04 17:01:20 +020088static int ipack_uevent(struct device *dev, struct kobj_uevent_env *env)
89{
90 struct ipack_device *idev;
91
92 if (!dev)
93 return -ENODEV;
94
95 idev = to_ipack_dev(dev);
96
97 if (add_uevent_var(env,
98 "MODALIAS=ipack:f%02Xv%08Xd%08X", idev->id_format,
99 idev->id_vendor, idev->id_device))
100 return -ENOMEM;
101
102 return 0;
103}
104
Jens Taproggee8ed3272012-09-04 17:01:15 +0200105#define ipack_device_attr(field, format_string) \
106static ssize_t \
107field##_show(struct device *dev, struct device_attribute *attr, \
108 char *buf) \
109{ \
110 struct ipack_device *idev = to_ipack_dev(dev); \
111 return sprintf(buf, format_string, idev->field); \
112}
113
Jens Taprogge5d72c8482012-09-04 17:01:21 +0200114static ssize_t id_show(struct device *dev,
115 struct device_attribute *attr, char *buf)
116{
117 unsigned int i, c, l, s;
118 struct ipack_device *idev = to_ipack_dev(dev);
119
120
121 switch (idev->id_format) {
122 case IPACK_ID_VERSION_1:
123 l = 0x7; s = 1; break;
124 case IPACK_ID_VERSION_2:
125 l = 0xf; s = 2; break;
126 default:
127 return -EIO;
128 }
129 c = 0;
130 for (i = 0; i < idev->id_avail; i++) {
131 if (i > 0) {
132 if ((i & l) == 0)
133 buf[c++] = '\n';
134 else if ((i & s) == 0)
135 buf[c++] = ' ';
136 }
137 sprintf(&buf[c], "%02x", idev->id[i]);
138 c += 2;
139 }
140 buf[c++] = '\n';
141 return c;
142}
143
Jens Taproggee8ed3272012-09-04 17:01:15 +0200144static ssize_t
145id_vendor_show(struct device *dev, struct device_attribute *attr, char *buf)
146{
147 struct ipack_device *idev = to_ipack_dev(dev);
148 switch (idev->id_format) {
149 case IPACK_ID_VERSION_1:
150 return sprintf(buf, "0x%02x\n", idev->id_vendor);
151 case IPACK_ID_VERSION_2:
152 return sprintf(buf, "0x%06x\n", idev->id_vendor);
153 default:
154 return -EIO;
155 }
156}
157
158static ssize_t
159id_device_show(struct device *dev, struct device_attribute *attr, char *buf)
160{
161 struct ipack_device *idev = to_ipack_dev(dev);
162 switch (idev->id_format) {
163 case IPACK_ID_VERSION_1:
164 return sprintf(buf, "0x%02x\n", idev->id_device);
165 case IPACK_ID_VERSION_2:
166 return sprintf(buf, "0x%04x\n", idev->id_device);
167 default:
168 return -EIO;
169 }
170}
171
Jens Taprogge35eb97b2012-09-04 17:01:20 +0200172static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
173 char *buf)
174{
175 struct ipack_device *idev = to_ipack_dev(dev);
176
177 return sprintf(buf, "ipac:f%02Xv%08Xd%08X", idev->id_format,
178 idev->id_vendor, idev->id_device);
179}
180
Jens Taproggee8ed3272012-09-04 17:01:15 +0200181ipack_device_attr(id_format, "0x%hhu\n");
182
Greg Kroah-Hartman5152a502013-10-07 18:27:36 -0700183static DEVICE_ATTR_RO(id);
184static DEVICE_ATTR_RO(id_device);
185static DEVICE_ATTR_RO(id_format);
186static DEVICE_ATTR_RO(id_vendor);
187static DEVICE_ATTR_RO(modalias);
188
189static struct attribute *ipack_attrs[] = {
190 &dev_attr_id.attr,
191 &dev_attr_id_device.attr,
192 &dev_attr_id_format.attr,
193 &dev_attr_id_vendor.attr,
194 &dev_attr_modalias.attr,
195 NULL,
Jens Taproggee8ed3272012-09-04 17:01:15 +0200196};
Greg Kroah-Hartman5152a502013-10-07 18:27:36 -0700197ATTRIBUTE_GROUPS(ipack);
Jens Taproggee8ed3272012-09-04 17:01:15 +0200198
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200199static struct bus_type ipack_bus_type = {
Jens Taproggee8ed3272012-09-04 17:01:15 +0200200 .name = "ipack",
201 .probe = ipack_bus_probe,
202 .match = ipack_bus_match,
203 .remove = ipack_bus_remove,
Greg Kroah-Hartman5152a502013-10-07 18:27:36 -0700204 .dev_groups = ipack_groups,
Jens Taprogge35eb97b2012-09-04 17:01:20 +0200205 .uevent = ipack_uevent,
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200206};
207
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +0200208struct ipack_bus_device *ipack_bus_register(struct device *parent, int slots,
Stephen Hemminger9869a932012-09-10 11:14:01 -0700209 const struct ipack_bus_ops *ops)
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200210{
211 int bus_nr;
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +0200212 struct ipack_bus_device *bus;
213
214 bus = kzalloc(sizeof(struct ipack_bus_device), GFP_KERNEL);
215 if (!bus)
216 return NULL;
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200217
Samuel Iglesias Gonsalvez3b86bb22012-05-25 10:03:01 +0200218 bus_nr = ida_simple_get(&ipack_ida, 0, 0, GFP_KERNEL);
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +0200219 if (bus_nr < 0) {
220 kfree(bus);
221 return NULL;
222 }
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200223
224 bus->bus_nr = bus_nr;
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +0200225 bus->parent = parent;
226 bus->slots = slots;
227 bus->ops = ops;
228 return bus;
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200229}
230EXPORT_SYMBOL_GPL(ipack_bus_register);
231
Samuel Iglesias Gonsálvezbffe0fd2012-09-11 13:35:09 +0200232static int ipack_unregister_bus_member(struct device *dev, void *data)
233{
234 struct ipack_device *idev = to_ipack_dev(dev);
235 struct ipack_bus_device *bus = data;
236
Jens Taproggef9e314d2012-09-27 12:37:25 +0200237 if (idev->bus == bus)
Samuel Iglesias Gonsalveze9263012013-03-08 09:21:47 +0100238 ipack_device_del(idev);
Samuel Iglesias Gonsálvezbffe0fd2012-09-11 13:35:09 +0200239
240 return 1;
241}
242
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200243int ipack_bus_unregister(struct ipack_bus_device *bus)
244{
Johan Meiring0a8f4a02012-11-11 22:41:12 +0200245 bus_for_each_dev(&ipack_bus_type, NULL, bus,
246 ipack_unregister_bus_member);
Samuel Iglesias Gonsalvez3b86bb22012-05-25 10:03:01 +0200247 ida_simple_remove(&ipack_ida, bus->bus_nr);
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +0200248 kfree(bus);
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200249 return 0;
250}
251EXPORT_SYMBOL_GPL(ipack_bus_unregister);
252
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +0200253int ipack_driver_register(struct ipack_driver *edrv, struct module *owner,
Stephen Hemminger9869a932012-09-10 11:14:01 -0700254 const char *name)
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200255{
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +0200256 edrv->driver.owner = owner;
257 edrv->driver.name = name;
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200258 edrv->driver.bus = &ipack_bus_type;
259 return driver_register(&edrv->driver);
260}
261EXPORT_SYMBOL_GPL(ipack_driver_register);
262
263void ipack_driver_unregister(struct ipack_driver *edrv)
264{
265 driver_unregister(&edrv->driver);
266}
267EXPORT_SYMBOL_GPL(ipack_driver_unregister);
268
Jens Taproggea92caeb2012-09-11 13:35:03 +0200269static u16 ipack_crc_byte(u16 crc, u8 c)
270{
271 int i;
272
273 crc ^= c << 8;
274 for (i = 0; i < 8; i++)
275 crc = (crc << 1) ^ ((crc & 0x8000) ? 0x1021 : 0);
276 return crc;
277}
278
279/*
280 * The algorithm in lib/crc-ccitt.c does not seem to apply since it uses the
281 * opposite bit ordering.
282 */
283static u8 ipack_calc_crc1(struct ipack_device *dev)
284{
285 u8 c;
286 u16 crc;
287 unsigned int i;
288
289 crc = 0xffff;
290 for (i = 0; i < dev->id_avail; i++) {
291 c = (i != 11) ? dev->id[i] : 0;
292 crc = ipack_crc_byte(crc, c);
293 }
294 crc = ~crc;
295 return crc & 0xff;
296}
297
298static u16 ipack_calc_crc2(struct ipack_device *dev)
299{
300 u8 c;
301 u16 crc;
302 unsigned int i;
303
304 crc = 0xffff;
305 for (i = 0; i < dev->id_avail; i++) {
306 c = ((i != 0x18) && (i != 0x19)) ? dev->id[i] : 0;
307 crc = ipack_crc_byte(crc, c);
308 }
309 crc = ~crc;
310 return crc;
311}
312
Jens Taproggee8ed3272012-09-04 17:01:15 +0200313static void ipack_parse_id1(struct ipack_device *dev)
314{
315 u8 *id = dev->id;
Jens Taproggea92caeb2012-09-11 13:35:03 +0200316 u8 crc;
Jens Taproggee8ed3272012-09-04 17:01:15 +0200317
318 dev->id_vendor = id[4];
319 dev->id_device = id[5];
Jens Taprogge0b0f3a12012-09-11 13:34:57 +0200320 dev->speed_8mhz = 1;
321 dev->speed_32mhz = (id[7] == 'H');
Jens Taproggea92caeb2012-09-11 13:35:03 +0200322 crc = ipack_calc_crc1(dev);
323 dev->id_crc_correct = (crc == id[11]);
324 if (!dev->id_crc_correct) {
325 dev_warn(&dev->dev, "ID CRC invalid found 0x%x, expected 0x%x.\n",
326 id[11], crc);
327 }
Jens Taproggee8ed3272012-09-04 17:01:15 +0200328}
329
330static void ipack_parse_id2(struct ipack_device *dev)
331{
332 __be16 *id = (__be16 *) dev->id;
Jens Taproggea92caeb2012-09-11 13:35:03 +0200333 u16 flags, crc;
Jens Taproggee8ed3272012-09-04 17:01:15 +0200334
335 dev->id_vendor = ((be16_to_cpu(id[3]) & 0xff) << 16)
336 + be16_to_cpu(id[4]);
337 dev->id_device = be16_to_cpu(id[5]);
Jens Taprogge0b0f3a12012-09-11 13:34:57 +0200338 flags = be16_to_cpu(id[10]);
339 dev->speed_8mhz = !!(flags & 2);
340 dev->speed_32mhz = !!(flags & 4);
Jens Taproggea92caeb2012-09-11 13:35:03 +0200341 crc = ipack_calc_crc2(dev);
342 dev->id_crc_correct = (crc == be16_to_cpu(id[12]));
343 if (!dev->id_crc_correct) {
344 dev_warn(&dev->dev, "ID CRC invalid found 0x%x, expected 0x%x.\n",
345 id[11], crc);
346 }
Jens Taproggee8ed3272012-09-04 17:01:15 +0200347}
348
Jens Taprogge187e4782012-09-04 17:01:14 +0200349static int ipack_device_read_id(struct ipack_device *dev)
350{
351 u8 __iomem *idmem;
352 int i;
353 int ret = 0;
354
Jens Taprogge402228d2012-09-27 12:37:34 +0200355 idmem = ioremap(dev->region[IPACK_ID_SPACE].start,
356 dev->region[IPACK_ID_SPACE].size);
357 if (!idmem) {
Jens Taprogge187e4782012-09-04 17:01:14 +0200358 dev_err(&dev->dev, "error mapping memory\n");
Samuel Iglesias Gonsalvez58b2c0c2012-09-27 12:37:41 +0200359 return -ENOMEM;
Jens Taprogge187e4782012-09-04 17:01:14 +0200360 }
Jens Taprogge187e4782012-09-04 17:01:14 +0200361
362 /* Determine ID PROM Data Format. If we find the ids "IPAC" or "IPAH"
363 * we are dealing with a IndustryPack format 1 device. If we detect
364 * "VITA4 " (16 bit big endian formatted) we are dealing with a
365 * IndustryPack format 2 device */
366 if ((ioread8(idmem + 1) == 'I') &&
367 (ioread8(idmem + 3) == 'P') &&
368 (ioread8(idmem + 5) == 'A') &&
369 ((ioread8(idmem + 7) == 'C') ||
370 (ioread8(idmem + 7) == 'H'))) {
371 dev->id_format = IPACK_ID_VERSION_1;
372 dev->id_avail = ioread8(idmem + 0x15);
373 if ((dev->id_avail < 0x0c) || (dev->id_avail > 0x40)) {
374 dev_warn(&dev->dev, "invalid id size");
375 dev->id_avail = 0x0c;
376 }
377 } else if ((ioread8(idmem + 0) == 'I') &&
378 (ioread8(idmem + 1) == 'V') &&
379 (ioread8(idmem + 2) == 'A') &&
380 (ioread8(idmem + 3) == 'T') &&
381 (ioread8(idmem + 4) == ' ') &&
382 (ioread8(idmem + 5) == '4')) {
383 dev->id_format = IPACK_ID_VERSION_2;
384 dev->id_avail = ioread16be(idmem + 0x16);
385 if ((dev->id_avail < 0x1a) || (dev->id_avail > 0x40)) {
386 dev_warn(&dev->dev, "invalid id size");
387 dev->id_avail = 0x1a;
388 }
389 } else {
390 dev->id_format = IPACK_ID_VERSION_INVALID;
391 dev->id_avail = 0;
392 }
393
394 if (!dev->id_avail) {
395 ret = -ENODEV;
396 goto out;
397 }
398
399 /* Obtain the amount of memory required to store a copy of the complete
400 * ID ROM contents */
401 dev->id = kmalloc(dev->id_avail, GFP_KERNEL);
402 if (!dev->id) {
403 dev_err(&dev->dev, "dev->id alloc failed.\n");
404 ret = -ENOMEM;
405 goto out;
406 }
407 for (i = 0; i < dev->id_avail; i++) {
408 if (dev->id_format == IPACK_ID_VERSION_1)
409 dev->id[i] = ioread8(idmem + (i << 1) + 1);
410 else
411 dev->id[i] = ioread8(idmem + i);
412 }
413
Jens Taproggee8ed3272012-09-04 17:01:15 +0200414 /* now we can finally work with the copy */
415 switch (dev->id_format) {
416 case IPACK_ID_VERSION_1:
417 ipack_parse_id1(dev);
418 break;
419 case IPACK_ID_VERSION_2:
420 ipack_parse_id2(dev);
421 break;
422 }
423
Jens Taprogge187e4782012-09-04 17:01:14 +0200424out:
Jens Taprogge402228d2012-09-27 12:37:34 +0200425 iounmap(idmem);
Jens Taprogge187e4782012-09-04 17:01:14 +0200426
427 return ret;
428}
429
Samuel Iglesias Gonsalveze9263012013-03-08 09:21:47 +0100430int ipack_device_init(struct ipack_device *dev)
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200431{
432 int ret;
433
434 dev->dev.bus = &ipack_bus_type;
435 dev->dev.release = ipack_device_release;
Jens Taprogge1e917952012-09-27 12:37:26 +0200436 dev->dev.parent = dev->bus->parent;
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200437 dev_set_name(&dev->dev,
Jens Taproggef9e314d2012-09-27 12:37:25 +0200438 "ipack-dev.%u.%u", dev->bus->bus_nr, dev->slot);
Samuel Iglesias Gonsalveze9263012013-03-08 09:21:47 +0100439 device_initialize(&dev->dev);
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200440
Jens Taprogge1e917952012-09-27 12:37:26 +0200441 if (dev->bus->ops->set_clockrate(dev, 8))
Jens Taprogge07766ab2012-09-11 13:35:01 +0200442 dev_warn(&dev->dev, "failed to switch to 8 MHz operation for reading of device ID.\n");
Jens Taprogge1e917952012-09-27 12:37:26 +0200443 if (dev->bus->ops->reset_timeout(dev))
Jens Taprogge8a3ae162012-09-11 13:35:02 +0200444 dev_warn(&dev->dev, "failed to reset potential timeout.");
Jens Taprogge07766ab2012-09-11 13:35:01 +0200445
Jens Taprogge187e4782012-09-04 17:01:14 +0200446 ret = ipack_device_read_id(dev);
447 if (ret < 0) {
448 dev_err(&dev->dev, "error reading device id section.\n");
Jens Taprogge1e917952012-09-27 12:37:26 +0200449 return ret;
Jens Taprogge187e4782012-09-04 17:01:14 +0200450 }
451
Jens Taprogge90cb6192012-09-11 13:34:58 +0200452 /* if the device supports 32 MHz operation, use it. */
Jens Taprogge07766ab2012-09-11 13:35:01 +0200453 if (dev->speed_32mhz) {
Jens Taprogge1e917952012-09-27 12:37:26 +0200454 ret = dev->bus->ops->set_clockrate(dev, 32);
Jens Taprogge07766ab2012-09-11 13:35:01 +0200455 if (ret < 0)
456 dev_err(&dev->dev, "failed to switch to 32 MHz operation.\n");
457 }
Jens Taprogge90cb6192012-09-11 13:34:58 +0200458
Samuel Iglesias Gonsalveze9263012013-03-08 09:21:47 +0100459 return 0;
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200460}
Samuel Iglesias Gonsalveze9263012013-03-08 09:21:47 +0100461EXPORT_SYMBOL_GPL(ipack_device_init);
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200462
Samuel Iglesias Gonsalveze9263012013-03-08 09:21:47 +0100463int ipack_device_add(struct ipack_device *dev)
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200464{
Samuel Iglesias Gonsalveze9263012013-03-08 09:21:47 +0100465 return device_add(&dev->dev);
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200466}
Samuel Iglesias Gonsalveze9263012013-03-08 09:21:47 +0100467EXPORT_SYMBOL_GPL(ipack_device_add);
468
469void ipack_device_del(struct ipack_device *dev)
470{
471 device_del(&dev->dev);
472 ipack_put_device(dev);
473}
474EXPORT_SYMBOL_GPL(ipack_device_del);
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200475
Samuel Iglesias Gonsalvezfa882862013-03-08 09:21:46 +0100476void ipack_get_device(struct ipack_device *dev)
477{
478 get_device(&dev->dev);
479}
480EXPORT_SYMBOL_GPL(ipack_get_device);
481
482void ipack_put_device(struct ipack_device *dev)
483{
484 put_device(&dev->dev);
485}
486EXPORT_SYMBOL_GPL(ipack_put_device);
487
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200488static int __init ipack_init(void)
489{
Samuel Iglesias Gonsalvez3b86bb22012-05-25 10:03:01 +0200490 ida_init(&ipack_ida);
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200491 return bus_register(&ipack_bus_type);
492}
493
494static void __exit ipack_exit(void)
495{
496 bus_unregister(&ipack_bus_type);
Samuel Iglesias Gonsalvez3b86bb22012-05-25 10:03:01 +0200497 ida_destroy(&ipack_ida);
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200498}
499
500module_init(ipack_init);
501module_exit(ipack_exit);
502
503MODULE_AUTHOR("Samuel Iglesias Gonsalvez <siglesias@igalia.com>");
504MODULE_LICENSE("GPL");
505MODULE_DESCRIPTION("Industry-pack bus core");