12 #include <linux/module.h>
13 #include <linux/slab.h>
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)
23 static void ipack_device_release(
struct device *
dev)
47 if (ipack_match_one_device(ids, idev))
61 found_id = ipack_match_id(idrv->
id_table, idev);
62 return found_id ? 1 : 0;
65 static int ipack_bus_probe(
struct device *device)
73 return drv->
ops->probe(dev);
76 static int ipack_bus_remove(
struct device *device)
81 if (!drv->
ops->remove)
84 drv->
ops->remove(dev);
100 "MODALIAS=ipack:f%02Xv%08Xd%08X", idev->
id_format,
109 #define ipack_uevent NULL
113 #define ipack_device_attr(field, format_string) \
115 field##_show(struct device *dev, struct device_attribute *attr, \
118 struct ipack_device *idev = to_ipack_dev(dev); \
119 return sprintf(buf, format_string, idev->field); \
122 static ssize_t id_show(
struct device *dev,
125 unsigned int i,
c,
l,
s;
131 l = 0x7; s = 1;
break;
133 l = 0xf; s = 2;
break;
138 for (i = 0; i < idev->
id_avail; i++) {
142 else if ((i & s) == 0)
167 id_device_show(
struct device *dev,
struct device_attribute *attr,
char *buf)
199 static struct bus_type ipack_bus_type = {
201 .probe = ipack_bus_probe,
202 .match = ipack_bus_match,
203 .remove = ipack_bus_remove,
204 .dev_attrs = ipack_dev_attrs,
232 static int ipack_unregister_bus_member(
struct device *dev,
void *
data)
257 edrv->
driver.bus = &ipack_bus_type;
273 for (i = 0; i < 8; i++)
274 crc = (crc << 1) ^ ((crc & 0x8000) ? 0x1021 : 0);
289 for (i = 0; i < dev->
id_avail; i++) {
290 c = (i != 11) ? dev->
id[i] : 0;
291 crc = ipack_crc_byte(crc, c);
304 for (i = 0; i < dev->
id_avail; i++) {
305 c = ((i != 0x18) && (i != 0x19)) ? dev->
id[i] : 0;
306 crc = ipack_crc_byte(crc, c);
321 crc = ipack_calc_crc1(dev);
324 dev_warn(&dev->
dev,
"ID CRC invalid found 0x%x, expected 0x%x.\n",
340 crc = ipack_calc_crc2(dev);
343 dev_warn(&dev->
dev,
"ID CRC invalid found 0x%x, expected 0x%x.\n",
348 static int ipack_device_read_id(
struct ipack_device *dev)
365 if ((
ioread8(idmem + 1) ==
'I') &&
368 ((
ioread8(idmem + 7) ==
'C') ||
369 (
ioread8(idmem + 7) ==
'H'))) {
376 }
else if ((
ioread8(idmem + 0) ==
'I') &&
402 dev_err(&dev->
dev,
"dev->id alloc failed.\n");
406 for (i = 0; i < dev->
id_avail; i++) {
416 ipack_parse_id1(dev);
419 ipack_parse_id2(dev);
439 dev->
dev.bus = &ipack_bus_type;
440 dev->
dev.release = ipack_device_release;
448 if (bus->
ops->set_clockrate(dev, 8))
449 dev_warn(&dev->
dev,
"failed to switch to 8 MHz operation for reading of device ID.\n");
450 if (bus->
ops->reset_timeout(dev))
451 dev_warn(&dev->
dev,
"failed to reset potential timeout.");
453 ret = ipack_device_read_id(dev);
455 dev_err(&dev->
dev,
"error reading device id section.\n");
462 ret = bus->
ops->set_clockrate(dev, 32);
464 dev_err(&dev->
dev,
"failed to switch to 32 MHz operation.\n");
484 static int __init ipack_init(
void)
490 static void __exit ipack_exit(
void)