diff options
Diffstat (limited to 'include/linux/i2c.h')
-rw-r--r-- | include/linux/i2c.h | 206 |
1 files changed, 161 insertions, 45 deletions
diff --git a/include/linux/i2c.h b/include/linux/i2c.h index be837b13f297..be35332b67e6 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h | |||
@@ -34,6 +34,13 @@ | |||
34 | #include <linux/device.h> /* for struct device */ | 34 | #include <linux/device.h> /* for struct device */ |
35 | #include <asm/semaphore.h> | 35 | #include <asm/semaphore.h> |
36 | 36 | ||
37 | /* --- For i2c-isa ---------------------------------------------------- */ | ||
38 | |||
39 | extern void i2c_adapter_dev_release(struct device *dev); | ||
40 | extern struct device_driver i2c_adapter_driver; | ||
41 | extern struct class i2c_adapter_class; | ||
42 | extern struct bus_type i2c_bus_type; | ||
43 | |||
37 | /* --- General options ------------------------------------------------ */ | 44 | /* --- General options ------------------------------------------------ */ |
38 | 45 | ||
39 | struct i2c_msg; | 46 | struct i2c_msg; |
@@ -41,7 +48,6 @@ struct i2c_algorithm; | |||
41 | struct i2c_adapter; | 48 | struct i2c_adapter; |
42 | struct i2c_client; | 49 | struct i2c_client; |
43 | struct i2c_driver; | 50 | struct i2c_driver; |
44 | struct i2c_client_address_data; | ||
45 | union i2c_smbus_data; | 51 | union i2c_smbus_data; |
46 | 52 | ||
47 | /* | 53 | /* |
@@ -143,12 +149,9 @@ struct i2c_driver { | |||
143 | */ | 149 | */ |
144 | struct i2c_client { | 150 | struct i2c_client { |
145 | unsigned int flags; /* div., see below */ | 151 | unsigned int flags; /* div., see below */ |
146 | unsigned int addr; /* chip address - NOTE: 7bit */ | 152 | unsigned short addr; /* chip address - NOTE: 7bit */ |
147 | /* addresses are stored in the */ | 153 | /* addresses are stored in the */ |
148 | /* _LOWER_ 7 bits of this char */ | 154 | /* _LOWER_ 7 bits */ |
149 | /* addr: unsigned int to make lm_sensors i2c-isa adapter work | ||
150 | more cleanly. It does not take any more memory space, due to | ||
151 | alignment considerations */ | ||
152 | struct i2c_adapter *adapter; /* the adapter we sit on */ | 155 | struct i2c_adapter *adapter; /* the adapter we sit on */ |
153 | struct i2c_driver *driver; /* and our access routines */ | 156 | struct i2c_driver *driver; /* and our access routines */ |
154 | int usage_count; /* How many accesses currently */ | 157 | int usage_count; /* How many accesses currently */ |
@@ -160,6 +163,11 @@ struct i2c_client { | |||
160 | }; | 163 | }; |
161 | #define to_i2c_client(d) container_of(d, struct i2c_client, dev) | 164 | #define to_i2c_client(d) container_of(d, struct i2c_client, dev) |
162 | 165 | ||
166 | static inline struct i2c_client *kobj_to_i2c_client(struct kobject *kobj) | ||
167 | { | ||
168 | return to_i2c_client(container_of(kobj, struct device, kobj)); | ||
169 | } | ||
170 | |||
163 | static inline void *i2c_get_clientdata (struct i2c_client *dev) | 171 | static inline void *i2c_get_clientdata (struct i2c_client *dev) |
164 | { | 172 | { |
165 | return dev_get_drvdata (&dev->dev); | 173 | return dev_get_drvdata (&dev->dev); |
@@ -170,13 +178,6 @@ static inline void i2c_set_clientdata (struct i2c_client *dev, void *data) | |||
170 | dev_set_drvdata (&dev->dev, data); | 178 | dev_set_drvdata (&dev->dev, data); |
171 | } | 179 | } |
172 | 180 | ||
173 | #define I2C_DEVNAME(str) .name = str | ||
174 | |||
175 | static inline char *i2c_clientname(struct i2c_client *c) | ||
176 | { | ||
177 | return &c->name[0]; | ||
178 | } | ||
179 | |||
180 | /* | 181 | /* |
181 | * The following structs are for those who like to implement new bus drivers: | 182 | * The following structs are for those who like to implement new bus drivers: |
182 | * i2c_algorithm is the interface to a class of hardware solutions which can | 183 | * i2c_algorithm is the interface to a class of hardware solutions which can |
@@ -184,9 +185,6 @@ static inline char *i2c_clientname(struct i2c_client *c) | |||
184 | * to name two of the most common. | 185 | * to name two of the most common. |
185 | */ | 186 | */ |
186 | struct i2c_algorithm { | 187 | struct i2c_algorithm { |
187 | char name[32]; /* textual description */ | ||
188 | unsigned int id; | ||
189 | |||
190 | /* If an adapter algorithm can't do I2C-level access, set master_xfer | 188 | /* If an adapter algorithm can't do I2C-level access, set master_xfer |
191 | to NULL. If an adapter algorithm can do SMBus access, set | 189 | to NULL. If an adapter algorithm can do SMBus access, set |
192 | smbus_xfer. If set to NULL, the SMBus protocol is simulated | 190 | smbus_xfer. If set to NULL, the SMBus protocol is simulated |
@@ -214,8 +212,7 @@ struct i2c_algorithm { | |||
214 | */ | 212 | */ |
215 | struct i2c_adapter { | 213 | struct i2c_adapter { |
216 | struct module *owner; | 214 | struct module *owner; |
217 | unsigned int id;/* == is algo->id | hwdep.struct->id, */ | 215 | unsigned int id; |
218 | /* for registered values see below */ | ||
219 | unsigned int class; | 216 | unsigned int class; |
220 | struct i2c_algorithm *algo;/* the algorithm to access the bus */ | 217 | struct i2c_algorithm *algo;/* the algorithm to access the bus */ |
221 | void *algo_data; | 218 | void *algo_data; |
@@ -292,12 +289,11 @@ struct i2c_client_address_data { | |||
292 | unsigned short *normal_i2c; | 289 | unsigned short *normal_i2c; |
293 | unsigned short *probe; | 290 | unsigned short *probe; |
294 | unsigned short *ignore; | 291 | unsigned short *ignore; |
295 | unsigned short *force; | 292 | unsigned short **forces; |
296 | }; | 293 | }; |
297 | 294 | ||
298 | /* Internal numbers to terminate lists */ | 295 | /* Internal numbers to terminate lists */ |
299 | #define I2C_CLIENT_END 0xfffeU | 296 | #define I2C_CLIENT_END 0xfffeU |
300 | #define I2C_CLIENT_ISA_END 0xfffefffeU | ||
301 | 297 | ||
302 | /* The numbers to use to set I2C bus address */ | 298 | /* The numbers to use to set I2C bus address */ |
303 | #define ANY_I2C_BUS 0xffff | 299 | #define ANY_I2C_BUS 0xffff |
@@ -356,10 +352,6 @@ extern int i2c_probe(struct i2c_adapter *adapter, | |||
356 | */ | 352 | */ |
357 | extern int i2c_control(struct i2c_client *,unsigned int, unsigned long); | 353 | extern int i2c_control(struct i2c_client *,unsigned int, unsigned long); |
358 | 354 | ||
359 | /* This call returns a unique low identifier for each registered adapter, | ||
360 | * or -1 if the adapter was not registered. | ||
361 | */ | ||
362 | extern int i2c_adapter_id(struct i2c_adapter *adap); | ||
363 | extern struct i2c_adapter* i2c_get_adapter(int id); | 355 | extern struct i2c_adapter* i2c_get_adapter(int id); |
364 | extern void i2c_put_adapter(struct i2c_adapter *adap); | 356 | extern void i2c_put_adapter(struct i2c_adapter *adap); |
365 | 357 | ||
@@ -376,6 +368,12 @@ static inline int i2c_check_functionality(struct i2c_adapter *adap, u32 func) | |||
376 | return (func & i2c_get_functionality(adap)) == func; | 368 | return (func & i2c_get_functionality(adap)) == func; |
377 | } | 369 | } |
378 | 370 | ||
371 | /* Return id number for a specific adapter */ | ||
372 | static inline int i2c_adapter_id(struct i2c_adapter *adap) | ||
373 | { | ||
374 | return adap->nr; | ||
375 | } | ||
376 | |||
379 | /* | 377 | /* |
380 | * I2C Message - used for pure i2c transaction, also from /dev interface | 378 | * I2C Message - used for pure i2c transaction, also from /dev interface |
381 | */ | 379 | */ |
@@ -510,9 +508,6 @@ union i2c_smbus_data { | |||
510 | #define I2C_FUNCS 0x0705 /* Get the adapter functionality */ | 508 | #define I2C_FUNCS 0x0705 /* Get the adapter functionality */ |
511 | #define I2C_RDWR 0x0707 /* Combined R/W transfer (one stop only)*/ | 509 | #define I2C_RDWR 0x0707 /* Combined R/W transfer (one stop only)*/ |
512 | #define I2C_PEC 0x0708 /* != 0 for SMBus PEC */ | 510 | #define I2C_PEC 0x0708 /* != 0 for SMBus PEC */ |
513 | #if 0 | ||
514 | #define I2C_ACK_TEST 0x0710 /* See if a slave is at a specific address */ | ||
515 | #endif | ||
516 | 511 | ||
517 | #define I2C_SMBUS 0x0720 /* SMBus-level access */ | 512 | #define I2C_SMBUS 0x0720 /* SMBus-level access */ |
518 | 513 | ||
@@ -556,27 +551,148 @@ union i2c_smbus_data { | |||
556 | module_param_array(var, short, &var##_num, 0); \ | 551 | module_param_array(var, short, &var##_num, 0); \ |
557 | MODULE_PARM_DESC(var,desc) | 552 | MODULE_PARM_DESC(var,desc) |
558 | 553 | ||
559 | /* This is the one you want to use in your own modules */ | 554 | #define I2C_CLIENT_MODULE_PARM_FORCE(name) \ |
555 | I2C_CLIENT_MODULE_PARM(force_##name, \ | ||
556 | "List of adapter,address pairs which are " \ | ||
557 | "unquestionably assumed to contain a `" \ | ||
558 | # name "' chip") | ||
559 | |||
560 | |||
561 | #define I2C_CLIENT_INSMOD_COMMON \ | ||
562 | I2C_CLIENT_MODULE_PARM(probe, "List of adapter,address pairs to scan " \ | ||
563 | "additionally"); \ | ||
564 | I2C_CLIENT_MODULE_PARM(ignore, "List of adapter,address pairs not to " \ | ||
565 | "scan"); \ | ||
566 | static struct i2c_client_address_data addr_data = { \ | ||
567 | .normal_i2c = normal_i2c, \ | ||
568 | .probe = probe, \ | ||
569 | .ignore = ignore, \ | ||
570 | .forces = forces, \ | ||
571 | } | ||
572 | |||
573 | /* These are the ones you want to use in your own drivers. Pick the one | ||
574 | which matches the number of devices the driver differenciates between. */ | ||
560 | #define I2C_CLIENT_INSMOD \ | 575 | #define I2C_CLIENT_INSMOD \ |
561 | I2C_CLIENT_MODULE_PARM(probe, \ | ||
562 | "List of adapter,address pairs to scan additionally"); \ | ||
563 | I2C_CLIENT_MODULE_PARM(ignore, \ | ||
564 | "List of adapter,address pairs not to scan"); \ | ||
565 | I2C_CLIENT_MODULE_PARM(force, \ | 576 | I2C_CLIENT_MODULE_PARM(force, \ |
566 | "List of adapter,address pairs to boldly assume " \ | 577 | "List of adapter,address pairs to boldly assume " \ |
567 | "to be present"); \ | 578 | "to be present"); \ |
568 | static struct i2c_client_address_data addr_data = { \ | 579 | static unsigned short *forces[] = { \ |
569 | .normal_i2c = normal_i2c, \ | 580 | force, \ |
570 | .probe = probe, \ | 581 | NULL \ |
571 | .ignore = ignore, \ | 582 | }; \ |
572 | .force = force, \ | 583 | I2C_CLIENT_INSMOD_COMMON |
573 | } | 584 | |
574 | 585 | #define I2C_CLIENT_INSMOD_1(chip1) \ | |
575 | /* Detect whether we are on the isa bus. If this returns true, all i2c | 586 | enum chips { any_chip, chip1 }; \ |
576 | access will fail! */ | 587 | I2C_CLIENT_MODULE_PARM(force, "List of adapter,address pairs to " \ |
577 | #define i2c_is_isa_client(clientptr) \ | 588 | "boldly assume to be present"); \ |
578 | ((clientptr)->adapter->algo->id == I2C_ALGO_ISA) | 589 | I2C_CLIENT_MODULE_PARM_FORCE(chip1); \ |
579 | #define i2c_is_isa_adapter(adapptr) \ | 590 | static unsigned short *forces[] = { force, force_##chip1, NULL }; \ |
580 | ((adapptr)->algo->id == I2C_ALGO_ISA) | 591 | I2C_CLIENT_INSMOD_COMMON |
592 | |||
593 | #define I2C_CLIENT_INSMOD_2(chip1, chip2) \ | ||
594 | enum chips { any_chip, chip1, chip2 }; \ | ||
595 | I2C_CLIENT_MODULE_PARM(force, "List of adapter,address pairs to " \ | ||
596 | "boldly assume to be present"); \ | ||
597 | I2C_CLIENT_MODULE_PARM_FORCE(chip1); \ | ||
598 | I2C_CLIENT_MODULE_PARM_FORCE(chip2); \ | ||
599 | static unsigned short *forces[] = { force, force_##chip1, \ | ||
600 | force_##chip2, NULL }; \ | ||
601 | I2C_CLIENT_INSMOD_COMMON | ||
602 | |||
603 | #define I2C_CLIENT_INSMOD_3(chip1, chip2, chip3) \ | ||
604 | enum chips { any_chip, chip1, chip2, chip3 }; \ | ||
605 | I2C_CLIENT_MODULE_PARM(force, "List of adapter,address pairs to " \ | ||
606 | "boldly assume to be present"); \ | ||
607 | I2C_CLIENT_MODULE_PARM_FORCE(chip1); \ | ||
608 | I2C_CLIENT_MODULE_PARM_FORCE(chip2); \ | ||
609 | I2C_CLIENT_MODULE_PARM_FORCE(chip3); \ | ||
610 | static unsigned short *forces[] = { force, force_##chip1, \ | ||
611 | force_##chip2, force_##chip3, \ | ||
612 | NULL }; \ | ||
613 | I2C_CLIENT_INSMOD_COMMON | ||
614 | |||
615 | #define I2C_CLIENT_INSMOD_4(chip1, chip2, chip3, chip4) \ | ||
616 | enum chips { any_chip, chip1, chip2, chip3, chip4 }; \ | ||
617 | I2C_CLIENT_MODULE_PARM(force, "List of adapter,address pairs to " \ | ||
618 | "boldly assume to be present"); \ | ||
619 | I2C_CLIENT_MODULE_PARM_FORCE(chip1); \ | ||
620 | I2C_CLIENT_MODULE_PARM_FORCE(chip2); \ | ||
621 | I2C_CLIENT_MODULE_PARM_FORCE(chip3); \ | ||
622 | I2C_CLIENT_MODULE_PARM_FORCE(chip4); \ | ||
623 | static unsigned short *forces[] = { force, force_##chip1, \ | ||
624 | force_##chip2, force_##chip3, \ | ||
625 | force_##chip4, NULL}; \ | ||
626 | I2C_CLIENT_INSMOD_COMMON | ||
627 | |||
628 | #define I2C_CLIENT_INSMOD_5(chip1, chip2, chip3, chip4, chip5) \ | ||
629 | enum chips { any_chip, chip1, chip2, chip3, chip4, chip5 }; \ | ||
630 | I2C_CLIENT_MODULE_PARM(force, "List of adapter,address pairs to " \ | ||
631 | "boldly assume to be present"); \ | ||
632 | I2C_CLIENT_MODULE_PARM_FORCE(chip1); \ | ||
633 | I2C_CLIENT_MODULE_PARM_FORCE(chip2); \ | ||
634 | I2C_CLIENT_MODULE_PARM_FORCE(chip3); \ | ||
635 | I2C_CLIENT_MODULE_PARM_FORCE(chip4); \ | ||
636 | I2C_CLIENT_MODULE_PARM_FORCE(chip5); \ | ||
637 | static unsigned short *forces[] = { force, force_##chip1, \ | ||
638 | force_##chip2, force_##chip3, \ | ||
639 | force_##chip4, force_##chip5, \ | ||
640 | NULL }; \ | ||
641 | I2C_CLIENT_INSMOD_COMMON | ||
642 | |||
643 | #define I2C_CLIENT_INSMOD_6(chip1, chip2, chip3, chip4, chip5, chip6) \ | ||
644 | enum chips { any_chip, chip1, chip2, chip3, chip4, chip5, chip6 }; \ | ||
645 | I2C_CLIENT_MODULE_PARM(force, "List of adapter,address pairs to " \ | ||
646 | "boldly assume to be present"); \ | ||
647 | I2C_CLIENT_MODULE_PARM_FORCE(chip1); \ | ||
648 | I2C_CLIENT_MODULE_PARM_FORCE(chip2); \ | ||
649 | I2C_CLIENT_MODULE_PARM_FORCE(chip3); \ | ||
650 | I2C_CLIENT_MODULE_PARM_FORCE(chip4); \ | ||
651 | I2C_CLIENT_MODULE_PARM_FORCE(chip5); \ | ||
652 | I2C_CLIENT_MODULE_PARM_FORCE(chip6); \ | ||
653 | static unsigned short *forces[] = { force, force_##chip1, \ | ||
654 | force_##chip2, force_##chip3, \ | ||
655 | force_##chip4, force_##chip5, \ | ||
656 | force_##chip6, NULL }; \ | ||
657 | I2C_CLIENT_INSMOD_COMMON | ||
658 | |||
659 | #define I2C_CLIENT_INSMOD_7(chip1, chip2, chip3, chip4, chip5, chip6, chip7) \ | ||
660 | enum chips { any_chip, chip1, chip2, chip3, chip4, chip5, chip6, \ | ||
661 | chip7 }; \ | ||
662 | I2C_CLIENT_MODULE_PARM(force, "List of adapter,address pairs to " \ | ||
663 | "boldly assume to be present"); \ | ||
664 | I2C_CLIENT_MODULE_PARM_FORCE(chip1); \ | ||
665 | I2C_CLIENT_MODULE_PARM_FORCE(chip2); \ | ||
666 | I2C_CLIENT_MODULE_PARM_FORCE(chip3); \ | ||
667 | I2C_CLIENT_MODULE_PARM_FORCE(chip4); \ | ||
668 | I2C_CLIENT_MODULE_PARM_FORCE(chip5); \ | ||
669 | I2C_CLIENT_MODULE_PARM_FORCE(chip6); \ | ||
670 | I2C_CLIENT_MODULE_PARM_FORCE(chip7); \ | ||
671 | static unsigned short *forces[] = { force, force_##chip1, \ | ||
672 | force_##chip2, force_##chip3, \ | ||
673 | force_##chip4, force_##chip5, \ | ||
674 | force_##chip6, force_##chip7, \ | ||
675 | NULL }; \ | ||
676 | I2C_CLIENT_INSMOD_COMMON | ||
677 | |||
678 | #define I2C_CLIENT_INSMOD_8(chip1, chip2, chip3, chip4, chip5, chip6, chip7, chip8) \ | ||
679 | enum chips { any_chip, chip1, chip2, chip3, chip4, chip5, chip6, \ | ||
680 | chip7, chip8 }; \ | ||
681 | I2C_CLIENT_MODULE_PARM(force, "List of adapter,address pairs to " \ | ||
682 | "boldly assume to be present"); \ | ||
683 | I2C_CLIENT_MODULE_PARM_FORCE(chip1); \ | ||
684 | I2C_CLIENT_MODULE_PARM_FORCE(chip2); \ | ||
685 | I2C_CLIENT_MODULE_PARM_FORCE(chip3); \ | ||
686 | I2C_CLIENT_MODULE_PARM_FORCE(chip4); \ | ||
687 | I2C_CLIENT_MODULE_PARM_FORCE(chip5); \ | ||
688 | I2C_CLIENT_MODULE_PARM_FORCE(chip6); \ | ||
689 | I2C_CLIENT_MODULE_PARM_FORCE(chip7); \ | ||
690 | I2C_CLIENT_MODULE_PARM_FORCE(chip8); \ | ||
691 | static unsigned short *forces[] = { force, force_##chip1, \ | ||
692 | force_##chip2, force_##chip3, \ | ||
693 | force_##chip4, force_##chip5, \ | ||
694 | force_##chip6, force_##chip7, \ | ||
695 | force_##chip8, NULL }; \ | ||
696 | I2C_CLIENT_INSMOD_COMMON | ||
581 | 697 | ||
582 | #endif /* _LINUX_I2C_H */ | 698 | #endif /* _LINUX_I2C_H */ |