Changeset 3765
- Timestamp:
- 01/21/03 09:08:16 (10 years ago)
- Location:
- i2c/trunk
- Files:
-
- 33 modified
-
kernel/Module.mk (modified) (2 diffs)
-
kernel/i2c-adap-ibm_ocp.c (modified) (3 diffs)
-
kernel/i2c-algo-8xx.c (modified) (14 diffs)
-
kernel/i2c-algo-8xx.h (modified) (2 diffs)
-
kernel/i2c-algo-bit.c (modified) (12 diffs)
-
kernel/i2c-algo-bit.h (modified) (2 diffs)
-
kernel/i2c-algo-biths.c (modified) (22 diffs)
-
kernel/i2c-algo-biths.h (modified) (2 diffs)
-
kernel/i2c-algo-ibm_ocp.c (modified) (6 diffs)
-
kernel/i2c-algo-ibm_ocp.h (modified) (2 diffs)
-
kernel/i2c-algo-pcf.c (modified) (6 diffs)
-
kernel/i2c-algo-pcf.h (modified) (2 diffs)
-
kernel/i2c-core.c (modified) (40 diffs)
-
kernel/i2c-dev.c (modified) (5 diffs)
-
kernel/i2c-dev.h (modified) (2 diffs)
-
kernel/i2c-elektor.c (modified) (1 diff)
-
kernel/i2c-elv.c (modified) (1 diff)
-
kernel/i2c-frodo.c (modified) (1 diff)
-
kernel/i2c-id.h (modified) (2 diffs)
-
kernel/i2c-pcf-epp.c (modified) (1 diff)
-
kernel/i2c-pcf8584.h (modified) (2 diffs)
-
kernel/i2c-philips-par.c (modified) (1 diff)
-
kernel/i2c-pport.c (modified) (2 diffs)
-
kernel/i2c-proc.c (modified) (14 diffs)
-
kernel/i2c-proc.h (modified) (5 diffs)
-
kernel/i2c-rpx.c (modified) (1 diff)
-
kernel/i2c-velleman.c (modified) (1 diff)
-
kernel/i2c.h (modified) (10 diffs)
-
mkpatch/Config.in (modified) (1 diff)
-
mkpatch/FILES (modified) (2 diffs)
-
mkpatch/INCLUDES (modified) (1 diff)
-
mkpatch/OLDI2C (modified) (1 diff)
-
mkpatch/mkpatch.pl (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
i2c/trunk/kernel/Module.mk
r3758 r3765 59 59 KERNELINCLUDES += $(MODULE_DIR)/i2c-algo-pcf.h 60 60 endif 61 # will not build outside kernel tree 61 62 ifneq ($(shell if grep -q '^CONFIG_I2C_ELEKTOR=y' $(LINUX)/.config; then echo 1; fi),1) 62 KERNELTARGETS += $(MODULE_DIR)/i2c-elektor.o63 KERNELINCLUDES += $(MODULE_DIR)/i2c-pcf8584.h63 #KERNELTARGETS += $(MODULE_DIR)/i2c-elektor.o 64 #KERNELINCLUDES += $(MODULE_DIR)/i2c-pcf8584.h 64 65 endif 65 66 ifneq ($(shell if grep -q '^CONFIG_I2C_PROC=y' $(LINUX)/.config; then echo 1; fi),1) … … 73 74 # No CONFIG option for this yet (not in mkpatch) 74 75 # 75 KERNELTARGETS += $(MODULE_DIR)/i2c-pcf-epp.o 76 # will not build outside kernel tree 77 #KERNELTARGETS += $(MODULE_DIR)/i2c-pcf-epp.o 76 78 # 77 # following require kernel 2.4.3 or higher... 79 # following require kernel 2.4.3 or higher... and PPC 78 80 # 79 81 #ifneq ($(shell if grep -q '^CONFIG_I2C_ALGO8XX=y' $(LINUX)/.config; then echo 1; fi),1) 80 KERNELTARGETS += $(MODULE_DIR)/i2c-algo-8xx.o81 KERNELINCLUDES += $(MODULE_DIR)/i2c-algo-8xx.h82 #KERNELTARGETS += $(MODULE_DIR)/i2c-algo-8xx.o 83 #KERNELINCLUDES += $(MODULE_DIR)/i2c-algo-8xx.h 82 84 #endif 83 85 #ifneq ($(shell if grep -q '^CONFIG_I2C_RPXLITE=y' $(LINUX)/.config; then echo 1; fi),1) 84 KERNELTARGETS += $(MODULE_DIR)/i2c-rpx.o86 #KERNELTARGETS += $(MODULE_DIR)/i2c-rpx.o 85 87 #endif 86 88 -
i2c/trunk/kernel/i2c-adap-ibm_ocp.c
r3759 r3765 58 58 #include <linux/delay.h> 59 59 #include <linux/slab.h> 60 #include <linux/version.h>61 60 #include <linux/init.h> 61 #include "i2c.h" 62 #include "i2c-algo-ibm_ocp.h" 62 63 #include <asm/irq.h> 63 64 #include <asm/io.h> 64 65 #include <asm/ocp.h> 65 66 #include "i2c.h"67 #include "i2c-algo-ibm_ocp.h"68 69 MODULE_LICENSE("GPL");70 66 71 67 /* … … 144 140 } 145 141 146 147 #if 0148 static void iic_ibmocp_sleep(unsigned long timeout)149 {150 schedule_timeout( timeout * HZ);151 }152 #endif153 142 154 143 … … 345 334 MODULE_AUTHOR("MontaVista Software <www.mvista.com>"); 346 335 MODULE_DESCRIPTION("I2C-Bus adapter routines for PPC 405 IIC bus adapter"); 336 MODULE_LICENSE("GPL"); 337 347 338 MODULE_PARM(base, "i"); 348 339 MODULE_PARM(irq, "i"); -
i2c/trunk/kernel/i2c-algo-8xx.c
r3761 r3765 31 31 #include <linux/delay.h> 32 32 #include <linux/slab.h> 33 #include <linux/version.h>34 33 #include <linux/init.h> 35 #include <asm/uaccess.h>36 #include <linux/ioport.h>37 34 #include <linux/errno.h> 38 35 #include <linux/sched.h> 39 36 #include "i2c.h" 37 #include "i2c-algo-8xx.h" 40 38 #include <asm/mpc8xx.h> 41 39 #include <asm/commproc.h> 42 40 43 #include "i2c.h"44 #include "i2c-algo-8xx.h"45 41 46 42 #define CPM_MAX_READ 513 … … 49 45 static ushort r_tbase, r_rbase; 50 46 51 int cpm_scan = 0;52 47 int cpm_debug = 0; 53 48 … … 74 69 75 70 static void 76 cpm_iic_init(struct i2c_algo_8xx_data *cpm _adap)77 { 78 volatile iic_t *iip = cpm _adap->iip;79 volatile i2c8xx_t *i2c = cpm _adap->i2c;71 cpm_iic_init(struct i2c_algo_8xx_data *cpm) 72 { 73 volatile iic_t *iip = cpm->iip; 74 volatile i2c8xx_t *i2c = cpm->i2c; 80 75 unsigned char brg; 81 76 bd_t *bd = (bd_t *)__res; … … 100 95 /* Set up the IIC parameters in the parameter ram. 101 96 */ 102 iip->iic_tbase = r_tbase = cpm _adap->dp_addr;103 iip->iic_rbase = r_rbase = cpm _adap->dp_addr + sizeof(cbd_t)*2;97 iip->iic_tbase = r_tbase = cpm->dp_addr; 98 iip->iic_rbase = r_rbase = cpm->dp_addr + sizeof(cbd_t)*2; 104 99 105 100 iip->iic_tfcr = SMC_EB; … … 112 107 /* Initialize Tx/Rx parameters. 113 108 */ 114 if (cpm _adap->reloc == 0) {115 volatile cpm8xx_t *cp = cpm _adap->cp;109 if (cpm->reloc == 0) { 110 volatile cpm8xx_t *cp = cpm->cp; 116 111 117 112 cp->cp_cpcr = … … 150 145 __func__,__LINE__, CPMVEC_I2C); 151 146 } 152 (*cpm _adap->setisr)(CPMVEC_I2C, cpm_iic_interrupt, (void *)i2c);147 (*cpm->setisr)(CPMVEC_I2C, cpm_iic_interrupt, (void *)i2c); 153 148 } 154 149 155 150 156 151 static int 157 cpm_iic_shutdown(struct i2c_algo_8xx_data *cpm _adap)158 { 159 volatile i2c8xx_t *i2c = cpm _adap->i2c;152 cpm_iic_shutdown(struct i2c_algo_8xx_data *cpm) 153 { 154 volatile i2c8xx_t *i2c = cpm->i2c; 160 155 161 156 /* Shut down IIC. … … 521 516 } 522 517 523 static int cpm_xfer(struct i2c_adapter * i2c_adap,518 static int cpm_xfer(struct i2c_adapter *adap, 524 519 struct i2c_msg msgs[], 525 520 int num) 526 521 { 527 struct i2c_algo_8xx_data * adap = i2c_adap->algo_data;522 struct i2c_algo_8xx_data *cpm = adap->algo_data; 528 523 struct i2c_msg *pmsg; 529 524 int i, ret; … … 548 543 if (pmsg->flags & I2C_M_RD ) { 549 544 /* read bytes into buffer*/ 550 ret = cpm_iic_read( adap, addr, pmsg->buf, pmsg->len);545 ret = cpm_iic_read(cpm, addr, pmsg->buf, pmsg->len); 551 546 if (cpm_debug) 552 547 printk("i2c-algo-8xx.o: read %d bytes\n", ret); … … 556 551 } else { 557 552 /* write bytes from buffer */ 558 ret = cpm_iic_write( adap, addr, pmsg->buf, pmsg->len);553 ret = cpm_iic_write(cpm, addr, pmsg->buf, pmsg->len); 559 554 if (cpm_debug) 560 555 printk("i2c-algo-8xx.o: wrote %d\n", ret); … … 567 562 } 568 563 569 static int algo_control(struct i2c_adapter *adapter,570 unsigned int cmd, unsigned long arg)571 {572 return 0;573 }574 575 564 static u32 cpm_func(struct i2c_adapter *adap) 576 565 { … … 582 571 583 572 static struct i2c_algorithm cpm_algo = { 573 .owner = THIS_MODULE, 584 574 .name = "MPC8xx CPM algorithm", 585 575 .id = I2C_ALGO_MPC8XX, 586 576 .master_xfer = cpm_xfer, 587 .algo_control = algo_control,588 577 .functionality = cpm_func, 589 578 }; … … 595 584 { 596 585 int i; 597 struct i2c_algo_8xx_data *cpm _adap= adap->algo_data;586 struct i2c_algo_8xx_data *cpm = adap->algo_data; 598 587 599 588 if (cpm_debug) … … 607 596 608 597 i2c_add_adapter(adap); 609 cpm_iic_init(cpm_adap); 610 611 /* scan bus */ 612 if (cpm_scan) { 613 printk(KERN_INFO " i2c-algo-8xx.o: scanning bus %s...\n", 614 adap->name); 615 for (i = 0; i < 128; i++) { 616 if (cpm_iic_tryaddress(cpm_adap, i)) { 617 printk("(%02x)",i<<1); 618 } 619 } 620 printk("\n"); 621 } 622 return 0; 598 cpm_iic_init(cpm); 623 599 } 624 600 … … 626 602 int i2c_8xx_del_bus(struct i2c_adapter *adap) 627 603 { 628 int res; 629 struct i2c_algo_8xx_data *cpm_adap = adap->algo_data; 630 631 cpm_iic_shutdown(cpm_adap); 632 633 if ((res = i2c_del_adapter(adap)) < 0) 634 return res; 635 636 printk("i2c-algo-8xx.o: adapter unregistered: %s\n",adap->name); 637 638 return 0; 604 struct i2c_algo_8xx_data *cpm = adap->algo_data; 605 606 cpm_iic_shutdown(cpm); 607 608 return i2c_del_adapter(adap); 639 609 } 640 610 -
i2c/trunk/kernel/i2c-algo-8xx.h
r3759 r3765 19 19 /* $Id$ */ 20 20 21 #ifndef I2C_ALGO_8XX_H 22 #define I2C_ALGO_8XX_H 1 23 24 #include "i2c.h" 21 #ifndef _LINUX_I2C_ALGO_8XX_H 22 #define _LINUX_I2C_ALGO_8XX_H 25 23 26 24 struct i2c_algo_8xx_data { … … 41 39 int i2c_8xx_del_bus(struct i2c_adapter *); 42 40 43 #endif /* I2C_ALGO_8XX_H */41 #endif /* _LINUX_I2C_ALGO_8XX_H */ -
i2c/trunk/kernel/i2c-algo-bit.c
r3758 r3765 28 28 #include <linux/delay.h> 29 29 #include <linux/slab.h> 30 #include <linux/version.h>31 30 #include <linux/init.h> 32 #include <asm/uaccess.h>33 #include <linux/ioport.h>34 31 #include <linux/errno.h> 35 32 #include <linux/sched.h> 36 37 33 #include "i2c.h" 38 34 #include "i2c-algo-bit.h" 35 39 36 40 37 /* ----- global defines ----------------------------------------------- */ … … 45 42 /* debug the protocol by showing transferred bits */ 46 43 47 /* debugging - slow down transfer to have a look at the data .. */48 /* I use this with two leds&resistors, each one connected to sda,scl */49 /* respectively. This makes sure that the algorithm works. Some chips */50 /* might not like this, as they have an internal timeout of some mils */51 /*52 #define SLO_IO jif=jiffies;while(time_before_eq(jiffies, jif+i2c_table[minor].veryslow))\53 cond_resched();54 */55 56 44 57 45 /* ----- global variables --------------------------------------------- */ 58 59 #ifdef SLO_IO60 int jif;61 #endif62 46 63 47 /* module parameters: … … 65 49 static int i2c_debug; 66 50 static int bit_test; /* see if the line-setting functions work */ 67 static int bit_scan; /* have a look at what's hanging 'round */68 51 69 52 /* --- setting states on the bus with the right timing: --------------- */ … … 90 73 setscl(adap,0); 91 74 udelay(adap->udelay); 92 #ifdef SLO_IO93 SLO_IO94 #endif95 75 } 96 76 … … 116 96 * while they are processing data internally. 117 97 */ 118 if ( time_after_eq(jiffies, start+adap->timeout)) {98 if (time_after_eq(jiffies, start+adap->timeout)) { 119 99 return -ETIMEDOUT; 120 100 } … … 123 103 DEBSTAT(printk(KERN_DEBUG "needed %ld jiffies\n", jiffies-start)); 124 104 udelay(adap->udelay); 125 #ifdef SLO_IO126 SLO_IO127 #endif128 105 return 0; 129 106 } … … 465 442 ret = try_address(i2c_adap, addr, retries); 466 443 if ((ret!=1) && !nak_ok) { 467 printk(KERN_ERR "died at extended address code.\n");468 return -EREMOTEIO;444 printk(KERN_ERR "died at extended address code.\n"); 445 return -EREMOTEIO; 469 446 } 470 447 } … … 527 504 } 528 505 529 static int algo_control(struct i2c_adapter *i2c_adap, 530 unsigned int cmd, unsigned long arg) 531 { 532 return 0; 533 } 534 535 static u32 bit_func(struct i2c_adapter *i2c_adap) 506 static u32 bit_func(struct i2c_adapter *adap) 536 507 { 537 508 return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR | … … 543 514 544 515 static struct i2c_algorithm i2c_bit_algo = { 516 .owner = THIS_MODULE, 545 517 .name = "Bit-shift algorithm", 546 518 .id = I2C_ALGO_BIT, 547 519 .master_xfer = bit_xfer, 548 .algo_control = algo_control,549 520 .functionality = bit_func, 550 521 }; … … 553 524 * registering functions to load algorithms at runtime 554 525 */ 555 int i2c_bit_add_bus(struct i2c_adapter * i2c_adap)526 int i2c_bit_add_bus(struct i2c_adapter *adap) 556 527 { 557 528 int i; 558 struct i2c_algo_bit_data * adap = i2c_adap->algo_data;529 struct i2c_algo_bit_data *bit_adap = adap->algo_data; 559 530 560 531 if (bit_test) { 561 int ret = test_bus( adap, i2c_adap->name);532 int ret = test_bus(bit_adap, adap->name); 562 533 if (ret<0) 563 534 return -ENODEV; … … 565 536 566 537 DEB2(printk(KERN_DEBUG "i2c-algo-bit.o: hw routines for %s registered.\n", 567 i2c_adap->name));538 adap->name)); 568 539 569 540 /* register new adapter to i2c module... */ 570 541 571 i2c_adap->id |= i2c_bit_algo.id; 572 i2c_adap->algo = &i2c_bit_algo; 573 574 i2c_adap->timeout = HZ; /* default values, should */ 575 i2c_adap->retries = 3; /* be replaced by defines */ 576 577 /* scan bus */ 578 if (bit_scan) { 579 int ack; 580 printk(KERN_INFO " i2c-algo-bit.o: scanning bus %s.\n", 581 i2c_adap->name); 582 for (i = 0x00; i < 0xff; i+=2) { 583 i2c_start(adap); 584 ack = i2c_outb(i2c_adap,i); 585 i2c_stop(adap); 586 if (ack>0) { 587 printk("(%02x)",i>>1); 588 } else 589 printk("."); 590 } 591 printk("\n"); 592 } 593 594 i2c_add_adapter(i2c_adap); 542 adap->id |= i2c_bit_algo.id; 543 adap->algo = &i2c_bit_algo; 544 545 adap->timeout = 100; /* default values, should */ 546 adap->retries = 3; /* be replaced by defines */ 547 548 i2c_add_adapter(adap); 595 549 return 0; 596 550 } 597 551 598 552 599 int i2c_bit_del_bus(struct i2c_adapter *i2c_adap) 600 { 601 int res; 602 603 if ((res = i2c_del_adapter(i2c_adap)) < 0) 604 return res; 605 606 DEB2(printk(KERN_DEBUG "i2c-algo-bit.o: adapter unregistered: %s\n",i2c_adap->name)); 607 608 return 0; 609 } 610 553 int i2c_bit_del_bus(struct i2c_adapter *adap) 554 { 555 return i2c_del_adapter(adap); 556 } 611 557 612 558 EXPORT_SYMBOL(i2c_bit_add_bus); … … 618 564 619 565 MODULE_PARM(bit_test, "i"); 620 MODULE_PARM(bit_scan, "i");621 566 MODULE_PARM(i2c_debug,"i"); 622 567 623 568 MODULE_PARM_DESC(bit_test, "Test the lines of the bus to see if it is stuck"); 624 MODULE_PARM_DESC(bit_scan, "Scan for active chips on the bus");625 569 MODULE_PARM_DESC(i2c_debug, 626 "debug level - 0 off; 1 normal; 2,3 more verbose; 9 bit-protocol");570 "debug level - 0 off; 1 normal; 2,3 more verbose; 9 bit-protocol"); -
i2c/trunk/kernel/i2c-algo-bit.h
r3731 r3765 24 24 /* $Id$ */ 25 25 26 #ifndef I2C_ALGO_BIT_H 27 #define I2C_ALGO_BIT_H 1 28 29 #include "i2c.h" 26 #ifndef _LINUX_I2C_ALGO_BIT_H 27 #define _LINUX_I2C_ALGO_BIT_H 30 28 31 29 /* --- Defines for bit-adapters --------------------------------------- */ … … 54 52 int i2c_bit_del_bus(struct i2c_adapter *); 55 53 56 #endif /* I2C_ALGO_BIT_H */54 #endif /* _LINUX_I2C_ALGO_BIT_H */ -
i2c/trunk/kernel/i2c-algo-biths.c
r3759 r3765 26 26 #include <linux/delay.h> 27 27 #include <linux/slab.h> 28 #include <linux/version.h>29 28 #include <linux/init.h> 30 #include <asm/uaccess.h>31 #include <linux/ioport.h>32 29 #include <linux/errno.h> 33 30 #include <linux/sched.h> … … 105 102 static int i2c_sda_set(struct i2c_algo_biths_data *adap, int rdcount) 106 103 { 107 int sda;108 /* allow some rise/fall time */109 while ( rdcount-- ) {110 sda = adap->getsda(adap->hw_data);111 if (adap->ctrl & _HS_SDA) {112 if (sda)113 return 0;114 if (!rdcount) {115 adap->errors |= _HS_SDA_ARB;116 return -1;117 }118 } else { /* !(adap->ctrl & _HS_SDA) */119 if (!sda)120 return 0;121 if (!rdcount) {122 adap->errors |= _HS_HW_FAIL;123 return -1;124 }125 }126 }127 return 0;104 int sda; 105 /* allow some rise/fall time */ 106 while ( rdcount-- ) { 107 sda = adap->getsda(adap->hw_data); 108 if (adap->ctrl & _HS_SDA) { 109 if (sda) 110 return 0; 111 if (!rdcount) { 112 adap->errors |= _HS_SDA_ARB; 113 return -1; 114 } 115 } else { /* !(adap->ctrl & _HS_SDA) */ 116 if (!sda) 117 return 0; 118 if (!rdcount) { 119 adap->errors |= _HS_HW_FAIL; 120 return -1; 121 } 122 } 123 } 124 return 0; 128 125 } 129 126 130 127 static void i2c_setsda(struct i2c_algo_biths_data *adap) 131 128 { 132 adap->setstate(adap);133 adap->setsda(adap->hw_data, adap->hw_state);134 if ( !(adap->ctrl & _HS_SDA_FREE) && ! i2c_sda_set(adap, 10)) {135 return;136 }137 adap->set_timer(adap);138 adap->run_timer(adap);129 adap->setstate(adap); 130 adap->setsda(adap->hw_data, adap->hw_state); 131 if ( !(adap->ctrl & _HS_SDA_FREE) && ! i2c_sda_set(adap, 10)) { 132 return; 133 } 134 adap->set_timer(adap); 135 adap->run_timer(adap); 139 136 } 140 137 141 138 static int i2c_getscl(struct i2c_algo_biths_data *adap) 142 139 { 143 return adap->getscl(adap->hw_data);140 return adap->getscl(adap->hw_data); 144 141 } 145 142 146 143 static int i2c_getsda(struct i2c_algo_biths_data *adap) 147 144 { 148 return adap->getsda(adap->hw_data);145 return adap->getsda(adap->hw_data); 149 146 } 150 147 /* … … 156 153 { 157 154 #ifndef HW_CANNOT_READ_SCL /* Not all adapters have scl sense line... */ 158 int rdcount = 10; 159 adap->setstate(adap); 160 adap->setscl(adap->hw_data, adap->hw_state); 161 if (adap->ctrl & _HS_SCL) { 162 unsigned long start; 163 /* allow some rise time */ 164 while (rdcount && !adap->getscl(adap->hw_data)) rdcount--; 165 /* else clock synchronisation, give more time */ 166 start = jiffies; 167 while (!rdcount && !adap->getscl(adap->hw_data)) { 168 if ( time_after(jiffies, start+adap->timeout) ) { 169 adap->errors |= _HS_TIMEOUT; /* scl undef */ 170 return; 171 } 172 cond_resched(); 173 } 155 int rdcount = 10; 156 adap->setstate(adap); 157 adap->setscl(adap->hw_data, adap->hw_state); 158 if (adap->ctrl & _HS_SCL) { 159 unsigned long start; 160 /* allow some rise time */ 161 while (rdcount && !adap->getscl(adap->hw_data)) rdcount--; 162 /* else clock synchronisation, give more time */ 163 start = jiffies; 164 while (!rdcount && !adap->getscl(adap->hw_data)) { 165 if ( time_after(jiffies, start+adap->timeout) ) { 166 adap->errors |= _HS_TIMEOUT; /* scl undef */ 167 return; 168 } 169 cond_resched(); 170 } 171 adap->set_timer(adap); 172 /* test for SDA arbitration when SCL is high */ 173 if ( !(adap->ctrl & _HS_SDA_FREE) && ! i2c_sda_set(adap, 1)) { 174 return; 175 } 176 } else { 177 /* allow some fall time */ 178 while (rdcount && adap->getscl(adap->hw_data)) rdcount--; 179 if ( !rdcount ) { 180 adap->errors |= _HS_HW_FAIL; 181 return; 182 } 183 adap->set_timer(adap); 184 } 185 #else 186 adap->setstate(adap); 187 adap->setscl(adap->hw_data, adap->hw_state); 174 188 adap->set_timer(adap); 175 /* test for SDA arbitration when SCL is high */176 if ( !(adap->ctrl & _HS_SDA_FREE) && ! i2c_sda_set(adap, 1)) {177 return;178 }179 } else {180 /* allow some fall time */181 while (rdcount && adap->getscl(adap->hw_data)) rdcount--;182 if ( !rdcount ) {183 adap->errors |= _HS_HW_FAIL;184 return;185 }186 adap->set_timer(adap);187 }188 #else189 adap->setstate(adap);190 adap->setscl(adap->hw_data, adap->hw_state);191 adap->set_timer(adap);192 189 #endif /* HW_CANNOT_READ_SCL */ 193 adap->run_timer(adap);190 adap->run_timer(adap); 194 191 } 195 192 … … 214 211 adap->ctrl &= ~(_HS_SDA_FREE | _HS_DBL_DT); 215 212 if (adap->errors) { 216 adap->errors = 0;217 _scllo(T_hold);213 adap->errors = 0; 214 _scllo(T_hold); 218 215 } 219 216 /* assert: scl low, sda undef */ … … 230 227 PROTO_B("."); 231 228 while (i--) { 232 PROTO_B("o");233 _setsda(adap->shiftreg & 0x80, T_setup);234 _sclhi(T_sclhi);235 _scllo(T_hold);236 adap->shiftreg<<=1;229 PROTO_B("o"); 230 _setsda(adap->shiftreg & 0x80, T_setup); 231 _sclhi(T_sclhi); 232 _scllo(T_hold); 233 adap->shiftreg<<=1; 237 234 } 238 235 /* assert: scl is low */ … … 245 242 PROTO_B("."); 246 243 while (i--) { 247 PROTO_B("i");248 _sdahi(T_setup);249 _sclhi(T_sclhi);250 adap->shiftreg<<=1;251 if (_getsda())252 adap->shiftreg |= 0x01;253 _scllo(T_hold);244 PROTO_B("i"); 245 _sdahi(T_setup); 246 _sclhi(T_sclhi); 247 adap->shiftreg<<=1; 248 if (_getsda()) 249 adap->shiftreg |= 0x01; 250 _scllo(T_hold); 254 251 } 255 252 adap->ctrl &= ~_HS_SDA_FREE; … … 261 258 { 262 259 while (*count) { 263 adap->shiftreg = *buf;264 TRY(i2c_outbits(adap, 8));265 PROTO_X(" %02X ", *buf);266 buf++;260 adap->shiftreg = *buf; 261 TRY(i2c_outbits(adap, 8)); 262 PROTO_X(" %02X ", *buf); 263 buf++; 267 264 268 /* read ack: SDA should be pulled down by slave */269 TRY(i2c_inbits(adap, 1));265 /* read ack: SDA should be pulled down by slave */ 266 TRY(i2c_inbits(adap, 1)); 270 267 271 if (! (adap->shiftreg & 0x01)) {272 PROTO_S("[A]");273 } else if (flags & I2C_M_IGNORE_NAK) {274 PROTO_S("[NA]");275 } else {276 PROTO_S("[NA]");277 adap->errors |= _HS_NAK;278 }279 if (adap->errors) return;280 (*count)--;268 if (! (adap->shiftreg & 0x01)) { 269 PROTO_S("[A]"); 270 } else if (flags & I2C_M_IGNORE_NAK) { 271 PROTO_S("[NA]"); 272 } else { 273 PROTO_S("[NA]"); 274 adap->errors |= _HS_NAK; 275 } 276 if (adap->errors) return; 277 (*count)--; 281 278 } 282 279 } … … 286 283 { 287 284 while (*count) { 288 TRY(i2c_inbits(adap, 8));289 *buf = adap->shiftreg;290 PROTO_X(" [%02X] ", *buf);291 buf++;285 TRY(i2c_inbits(adap, 8)); 286 *buf = adap->shiftreg; 287 PROTO_X(" [%02X] ", *buf); 288 buf++; 292 289 293 if (! (flags & I2C_M_NO_RD_ACK)) { 294 if (*count == 1) /* was last */ 295 adap->shiftreg = 0x80; 296 else 297 adap->shiftreg = 0x00; 298 TRY(i2c_outbits(adap,1)); 299 300 if (*count == 1) { 301 PROTO_S("NA"); 302 } else { 303 PROTO_S("A"); 290 if (! (flags & I2C_M_NO_RD_ACK)) { 291 if (*count == 1) /* was last */ 292 adap->shiftreg = 0x80; 293 else 294 adap->shiftreg = 0x00; 295 TRY(i2c_outbits(adap,1)); 296 297 if (*count == 1) { 298 PROTO_S("NA"); 299 } else { 300 PROTO_S("A"); 301 } 304 302 } 305 } 306 (*count)--; 303 (*count)--; 307 304 } 308 305 } … … 311 308 static void debug_protocol(struct i2c_algo_biths_data *adap, int retval) 312 309 { 313 if (! adap->dstr) return;314 315 if ( ((retval<0) && (i2c_debug>=FATAL_PROTOCOL)) ||316 (i2c_debug>=ALL_PROTOCOL) ) {317 printk(KERN_DEBUG "i2c-algo-biths.o: %s: %s\n", adap->name, adap->dstr);318 }319 *adap->dstr = 0;310 if (! adap->dstr) return; 311 312 if ( ((retval<0) && (i2c_debug>=FATAL_PROTOCOL)) || 313 (i2c_debug>=ALL_PROTOCOL) ) { 314 printk(KERN_DEBUG "i2c-algo-biths.o: %s: %s\n", adap->name, adap->dstr); 315 } 316 *adap->dstr = 0; 320 317 } 321 318 322 319 static const char * i2c_strerr(int retval) 323 320 { 324 switch (retval) {325 case 2:326 return "ack";321 switch (retval) { 322 case 2: 323 return "ack"; 327 324 328 case 1:329 return "no ack (ignored)";330 331 case 0:332 return "not reached";333 334 case -EREMOTEIO:335 return "no ack";336 337 case -ETIMEDOUT:338 return "SCL rise timeout";325 case 1: 326 return "no ack (ignored)"; 327 328 case 0: 329 return "not reached"; 330 331 case -EREMOTEIO: 332 return "no ack"; 333 334 case -ETIMEDOUT: 335 return "SCL rise timeout"; 339 336 340 case -ECOMM:341 return "SDA arbitration";342 343 case -ENODEV:344 return "SCL/SDA failure";345 346 default:347 return "unknown";348 }337 case -ECOMM: 338 return "SDA arbitration"; 339 340 case -ENODEV: 341 return "SCL/SDA failure"; 342 343 default: 344 return "unknown"; 345 } 349 346 } 350 347 351 348 static int errflag(int flags) 352 349 { 353 if (! flags)354 return 2;355 if (flags & _HS_HW_FAIL)356 return -ENODEV;357 if (flags & _HS_SDA_ARB)358 return -ECOMM;359 if (flags & _HS_TIMEOUT)360 return -ETIMEDOUT;361 if (flags & _HS_NAK)362 return -EREMOTEIO;363 364 return -1;350 if (! flags) 351 return 2; 352 if (flags & _HS_HW_FAIL) 353 return -ENODEV; 354 if (flags & _HS_SDA_ARB) 355 return -ECOMM; 356 if (flags & _HS_TIMEOUT) 357 return -ETIMEDOUT; 358 if (flags & _HS_NAK) 359 return -EREMOTEIO; 360 361 return -1; 365 362 } 366 363 367 364 static void debug_printout(struct i2c_adapter *i2c_adap, int num, int retval) 368 365 { 369 if ( ((retval<0) && (i2c_debug>=FATAL_MSG)) ||370 (i2c_debug>=ALL_MSG) ) {371 printk(KERN_ERR "i2c-algo-biths.o: %s: msg #%d %s\n", i2c_adap->name, num, i2c_strerr(retval));372 }366 if ( ((retval<0) && (i2c_debug>=FATAL_MSG)) || 367 (i2c_debug>=ALL_MSG) ) { 368 printk(KERN_ERR "i2c-algo-biths.o: %s: msg #%d %s\n", i2c_adap->name, num, i2c_strerr(retval)); 369 } 373 370 } 374 371 … … 379 376 { 380 377 381 int sscl, ssda, gscl, gsda, i=0; 382 int errors; 383 int test[][2] = {{1,1}, {0,1}, {1,1}, {1,0}, {1,1}, {-1,-1}}; // SDA, SCL pair 384 385 printk(KERN_INFO "i2c-algo-biths.o: %s bus test\n", adap->name); 386 387 while ( test[i][0]!=-1 ) { 388 ssda = test[i][0]; 389 sscl = test[i][1]; 390 378 int sscl, ssda, gscl, gsda, i=0; 379 int errors; 380 int test[][2] = {{1,1}, {0,1}, {1,1}, {1,0}, {1,1}, {-1,-1}}; // SDA, SCL pair 381 382 printk(KERN_INFO "i2c-algo-biths.o: %s bus test\n", adap->name); 383 384 while ( test[i][0]!=-1 ) { 385 ssda = test[i][0]; 386 sscl = test[i][1]; 387 388 adap->errors = 0; 389 __setsda(ssda, T_min); 390 gsda = __getsda() ? 1 : 0; 391 errors = adap->errors & (_HS_HW_FAIL | _HS_SDA_ARB); 392 if (errors) 393 printk(KERN_WARNING "i2c-algo-biths.o: %s %s\n", adap->name, 394 i2c_strerr(errflag(errors))); 395 396 __setscl(sscl, T_min); 397 gscl = __getscl() ? 1 : 0; 398 errors = adap->errors & (_HS_HW_FAIL | _HS_TIMEOUT); 399 if (errors) 400 printk(KERN_WARNING "i2c-algo-biths.o: %s %s\n", adap->name, 401 i2c_strerr(errflag(errors))); 402 403 printk(KERN_DEBUG "i2c-algo-biths.o: %s SCL: %d SDA: %d\n", adap->name, gscl, gsda); 404 if ( sscl!=gscl ) 405 printk(KERN_WARNING "i2c-algo-biths.o: %s SCL set %d, got %d!\n", adap->name, sscl, gscl); 406 if ( ssda!=gsda ) 407 printk(KERN_WARNING "i2c-algo-biths.o: %s SDA set %d, got %d!\n", adap->name, ssda, gsda); 408 if ( (adap->errors) || sscl!=gscl || ssda!=gsda ) 409 break; 410 i++; 411 } 412 413 __setsda(1,0); 414 __setscl(1,0); 391 415 adap->errors = 0; 392 __setsda(ssda, T_min); 393 gsda = __getsda() ? 1 : 0; 394 errors = adap->errors & (_HS_HW_FAIL | _HS_SDA_ARB); 395 if (errors) 396 printk(KERN_WARNING "i2c-algo-biths.o: %s %s\n", adap->name, 397 i2c_strerr(errflag(errors))); 398 399 __setscl(sscl, T_min); 400 gscl = __getscl() ? 1 : 0; 401 errors = adap->errors & (_HS_HW_FAIL | _HS_TIMEOUT); 402 if (errors) 403 printk(KERN_WARNING "i2c-algo-biths.o: %s %s\n", adap->name, 404 i2c_strerr(errflag(errors))); 405 406 printk(KERN_DEBUG "i2c-algo-biths.o: %s SCL: %d SDA: %d\n", adap->name, gscl, gsda); 407 if ( sscl!=gscl ) 408 printk(KERN_WARNING "i2c-algo-biths.o: %s SCL set %d, got %d!\n", adap->name, sscl, gscl); 409 if ( ssda!=gsda ) 410 printk(KERN_WARNING "i2c-algo-biths.o: %s SDA set %d, got %d!\n", adap->name, ssda, gsda); 411 if ( (adap->errors) || sscl!=gscl || ssda!=gsda ) 412 break; 413 i++; 414 } 415 416 __setsda(1,0); 417 __setscl(1,0); 418 adap->errors = 0; 419 420 if (test[i][0]==-1) { 421 printk(KERN_INFO "i2c-algo-biths.o: %s passed bus test.\n",adap->name); 422 return 0; 423 } else { 424 printk(KERN_INFO "i2c-algo-biths.o: %s failed bus test.\n",adap->name); 425 return -ENODEV; 426 } 416 417 if (test[i][0]==-1) { 418 printk(KERN_INFO "i2c-algo-biths.o: %s passed bus test.\n",adap->name); 419 return 0; 420 } else { 421 printk(KERN_INFO "i2c-algo-biths.o: %s failed bus test.\n",adap->name); 422 return -ENODEV; 423 } 427 424 } 428 425 … … 487 484 adap->dstr=NULL; 488 485 if (i2c_debug>=FATAL_PROTOCOL) { 489 adap->dstr = kmalloc(PROTO_MAX_DUMP, GFP_KERNEL);490 if (adap->dstr) {491 *adap->dstr = 0;492 } else {493 printk(KERN_DEBUG "i2c-algo-biths.o %s: missing protocol dump (-ENOMEM)\n", adap->name);494 }486 adap->dstr = kmalloc(PROTO_MAX_DUMP, GFP_KERNEL); 487 if (adap->dstr) { 488 *adap->dstr = 0; 489 } else { 490 printk(KERN_DEBUG "i2c-algo-biths.o %s: missing protocol dump (-ENOMEM)\n", adap->name); 491 } 495 492 } 496 493 … … 500 497 501 498 case MSG_INIT: 502 msg = &msgs[mn];503 if ((msg->flags & I2C_M_NOSTART) && (mn)) {504 state = MSG_DATA;505 break;506 }499 msg = &msgs[mn]; 500 if ((msg->flags & I2C_M_NOSTART) && (mn)) { 501 state = MSG_DATA; 502 break; 503 } 507 504 508 505 case MSG_START: 509 i2c_start(adap);510 if (adap->errors) {511 state = MSG_STOP;512 break;513 }506 i2c_start(adap); 507 if (adap->errors) { 508 state = MSG_STOP; 509 break; 510 } 514 511 515 512 case MSG_ADDRESS: 516 doAddress(adap, msg);517 if (adap->errors) {518 state = MSG_STOP;519 break;520 }513 doAddress(adap, msg); 514 if (adap->errors) { 515 state = MSG_STOP; 516 break; 517 } 521 518 522 519 case MSG_DATA: 523 j = msg->len;524 if ( msg->flags & I2C_M_RD ) {525 i2c_inb(adap, msg->flags, msg->buf, &j);526 } else {527 i2c_outb(adap, msg->flags, msg->buf, &j);528 }529 msg->done = msg->len - j;530 if (adap->errors) {531 state = MSG_STOP;532 break;533 }520 j = msg->len; 521 if ( msg->flags & I2C_M_RD ) { 522 i2c_inb(adap, msg->flags, msg->buf, &j); 523 } else { 524 i2c_outb(adap, msg->flags, msg->buf, &j); 525 } 526 msg->done = msg->len - j; 527 if (adap->errors) { 528 state = MSG_STOP; 529 break; 530 } 534 531 535 532 case MSG_READY: 536 mn++; 537 if (mn<num) { 533 mn++; 534 if (mn<num) { 535 msg->err = errflag(adap->errors); 536 debug_protocol(adap, msg->err); 537 state = MSG_INIT; 538 break; 539 } 540 541 case MSG_STOP: 538 542 msg->err = errflag(adap->errors); 543 i2c_stop(adap); 544 j = 0; 545 while (adap->errors) { 546 if ( ++j > 10) { 547 msg->err = -ENODEV; 548 break; 549 } 550 i2c_stop(adap); 551 } 539 552 debug_protocol(adap, msg->err); 540 state = MSG_ INIT;553 state = MSG_EXIT; 541 554 break; 542 }543 544 case MSG_STOP:545 msg->err = errflag(adap->errors);546 i2c_stop(adap);547 j = 0;548 while (adap->errors) {549 if ( ++j > 10) {550 msg->err = -ENODEV;551 break;552 }553 i2c_stop(adap);554 }555 debug_protocol(adap, msg->err);556 state = MSG_EXIT;557 break;558 555 559 556 default: /* not reached */ 560 state = MSG_EXIT;561 msg->err = -EINVAL;562 break;557 state = MSG_EXIT; 558 msg->err = -EINVAL; 559 break; 563 560 564 561 } while (state != MSG_EXIT); … … 567 564 568 565 for (j=0; j<num; j++) 569 debug_printout(i2c_adap, j, msgs[j].err);566 debug_printout(i2c_adap, j, msgs[j].err); 570 567 571 568 return (msg->err < 0) ? msg->err : mn; 572 569 } 573 570 574 static int algo_control(struct i2c_adapter *i2c_adap,575 unsigned int cmd, unsigned long arg)576 {577 return 0;578 }579 580 571 static u32 bit_func(struct i2c_adapter *i2c_adap) 581 572 { 582 573 return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR | 583 I2C_FUNC_PROTOCOL_MANGLING;574 I2C_FUNC_PROTOCOL_MANGLING; 584 575 } 585 576 … … 588 579 589 580 static struct i2c_algorithm i2c_algo_biths = { 581 .owner = THIS_MODULE, 590 582 .name = "Bit-shift algorithm", 591 583 .id = I2C_ALGO_BIT, 592 584 .master_xfer = bit_xfer, 593 .algo_control = algo_control,594 585 .functionality = bit_func, 595 586 }; … … 644 635 adap = kmalloc(sizeof(struct i2c_algo_biths_data), GFP_KERNEL); 645 636 if (adap==NULL) 646 return -ENOMEM;637 return -ENOMEM; 647 638 648 639 memcpy(adap, &_old_template, sizeof(struct i2c_algo_biths_data)); … … 661 652 662 653 if ((res = i2c_biths_del_bus(i2c_adap)) < 0) 663 return res;654 return res; 664 655 665 656 kfree(i2c_adap->algo_data); … … 677 668 static _HS_ATTR_ void i2c_tsc_set(struct i2c_algo_biths_data *adap) 678 669 { 679 rdtscl(adap->bclock);670 rdtscl(adap->bclock); 680 671 } 681 672 682 673 static _HS_ATTR_ void i2c_tsc_run(struct i2c_algo_biths_data *adap) 683 674 { 684 unsigned long now, loops, xloops;685 int d0;686 xloops = adap->xloops;687 __asm__("mull %0"688 :"=d" (xloops), "=&a" (d0)689 :"1" (xloops),"0" (current_cpu_data.loops_per_jiffy));690 loops = xloops * HZ;691 do692 {693 rep_nop();694 rdtscl(now);695 } while ( (now - adap->bclock) < loops );675 unsigned long now, loops, xloops; 676 int d0; 677 xloops = adap->xloops; 678 __asm__("mull %0" 679 :"=d" (xloops), "=&a" (d0) 680 :"1" (xloops),"0" (current_cpu_data.loops_per_jiffy)); 681 loops = xloops * HZ; 682 do 683 { 684 rep_nop(); 685 rdtscl(now); 686 } while ( (now - adap->bclock) < loops ); 696 687 } 697 688 … … 702 693 static _HS_ATTR_ void i2c_udelay_run(struct i2c_algo_biths_data *adap) 703 694 { 704 int usecs;705 /* adap->xloops = usecs * 0x000010c6 / 2; */706 usecs = ((adap->xloops + 0x0863) >> 12);707 if (adap->ctrl & _HS_DBL_DT)708 usecs<<=1;709 udelay(usecs);695 int usecs; 696 /* adap->xloops = usecs * 0x000010c6 / 2; */ 697 usecs = ((adap->xloops + 0x0863) >> 12); 698 if (adap->ctrl & _HS_DBL_DT) 699 usecs<<=1; 700 udelay(usecs); 710 701 } 711 702 … … 735 726 736 727 if (bit_test) { 737 int ret = test_bus(adap);738 if (ret<0)739 return ret;728 int ret = test_bus(adap); 729 if (ret<0) 730 return ret; 740 731 } 741 732 … … 757 748 758 749 i2c_add_adapter(i2c_adap); 759 760 750 return 0; 761 751 } … … 764 754 int i2c_biths_del_bus(struct i2c_adapter *i2c_adap) 765 755 { 766 int res; 767 768 if ((res = i2c_del_adapter(i2c_adap)) < 0) 769 return res; 770 771 DEB1(printk(KERN_DEBUG "i2c-algo-biths.o: adapter unregistered: %s\n",i2c_adap->name)); 772 773 return 0; 756 return i2c_del_adapter(i2c_adap); 774 757 } 775 758 … … 785 768 786 769 MODULE_PARM_DESC(bit_test, "Test the lines of the bus to see if it is stuck"); 787 MODULE_PARM_DESC(i2c_debug, 788 "debug level - 1 use; 2 fatal, 3 +proto; 4 all, 5 +proto"); 770 MODULE_PARM_DESC(i2c_debug, "debug level - 1 use; 2 fatal, 3 +proto; 4 all, 5 +proto"); -
i2c/trunk/kernel/i2c-algo-biths.h
r3750 r3765 24 24 /* $Id$ */ 25 25 26 #ifndef I2C_ALGO_BITHS_H 27 #define I2C_ALGO_BITHS_H 1 28 29 #include "i2c.h" 30 #include <linux/sched.h> 26 #ifndef _LINUX_I2C_ALGO_BITHS_H 27 #define _LINUX_I2C_ALGO_BITHS_H 31 28 32 29 #if 1 … … 90 87 int i2c_biths_del_bus(struct i2c_adapter *); 91 88 92 #endif /* I2C_ALGO_BITHS_H */89 #endif /* _LINUX_I2C_ALGO_BITHS_H */ -
i2c/trunk/kernel/i2c-algo-ibm_ocp.c
r3759 r3765 56 56 #include <linux/delay.h> 57 57 #include <linux/slab.h> 58 #include <linux/version.h>59 58 #include <linux/init.h> 60 #include <asm/uaccess.h>61 #include <linux/ioport.h>62 59 #include <linux/errno.h> 63 60 #include <linux/sched.h> 64 65 61 #include "i2c.h" 66 62 #include "i2c-algo-ibm_ocp.h" 67 63 #include <asm/ocp.h> 68 69 MODULE_LICENSE("GPL");70 64 71 65 … … 78 72 #define DEF_TIMEOUT 5 79 73 80 /* debugging - slow down transfer to have a look at the data .. */81 /* I use this with two leds&resistors, each one connected to sda,scl */82 /* respectively. This makes sure that the algorithm works. Some chips */83 /* might not like this, as they have an internal timeout of some mils */84 /*85 #define SLO_IO jif=jiffies;while(jiffies<=jif+i2c_table[minor].veryslow)\86 if (need_resched) schedule();87 */88 89 74 90 75 /* ----- global variables --------------------------------------------- */ 91 76 92 #ifdef SLO_IO93 int jif;94 #endif95 77 96 78 /* module parameters: 97 79 */ 98 80 static int i2c_debug=0; 99 static int iic_scan=0; /* have a look at what's hanging 'round */100 81 101 82 /* --- setting states on the bus with the right timing: --------------- */ … … 857 838 858 839 static struct i2c_algorithm iic_algo = { 840 .owner = THIS_MODULE, 859 841 .name = "IBM on-chip IIC algorithm", 860 842 .id = I2C_ALGO_OCP, … … 889 871 iic_init(iic_adap); 890 872 i2c_add_adapter(adap); 891 892 /* scan bus */893 /* By default scanning the bus is turned off. */894 if (iic_scan) {895 printk(KERN_INFO " i2c-algo-iic.o: scanning bus %s.\n",896 adap->name);897 }898 873 return 0; 899 874 } … … 905 880 int i2c_ocp_del_bus(struct i2c_adapter *adap) 906 881 { 907 int res; 908 if ((res = i2c_del_adapter(adap)) < 0) 909 return res; 910 DEB2(printk(KERN_DEBUG "i2c-algo-iic.o: adapter unregistered: %s\n",adap->name)); 911 912 return 0; 882 return i2c_del_adapter(adap); 913 883 } 914 884 … … 923 893 MODULE_AUTHOR("MontaVista Software <www.mvista.com>"); 924 894 MODULE_DESCRIPTION("PPC 405 iic algorithm"); 925 926 MODULE_PARM(iic_test, "i"); 927 MODULE_PARM(iic_scan, "i"); 895 MODULE_LICENSE("GPL"); 896 928 897 MODULE_PARM(i2c_debug,"i"); 929 898 930 MODULE_PARM_DESC(iic_test, "Test if the I2C bus is available");931 MODULE_PARM_DESC(iic_scan, "Scan for active chips on the bus");932 899 MODULE_PARM_DESC(i2c_debug, 933 900 "debug level - 0 off; 1 normal; 2,3 more verbose; 9 iic-protocol"); -
i2c/trunk/kernel/i2c-algo-ibm_ocp.h
r3759 r3765 26 26 Changes made to support the IIC peripheral on the IBM PPC 405 */ 27 27 28 #ifndef I2C_ALGO_IBM_OCP_H 29 #define I2C_ALGO_IBM_OCP_H 1 30 31 /* --- Defines for pcf-adapters --------------------------------------- */ 32 #include "i2c.h" 28 #ifndef _LINUX_I2C_ALGO_IBM_OCP_H 29 #define _LINUX_I2C_ALGO_IBM_OCP_H 33 30 34 31 struct i2c_algo_iic_data { … … 53 50 int i2c_ocp_del_bus(struct i2c_adapter *); 54 51 55 #endif /* I2C_ALGO_IBM_OCP_H */52 #endif /* _LINUX_I2C_ALGO_IBM_OCP_H */ -
i2c/trunk/kernel/i2c-algo-pcf.c
r3761 r3765 32 32 #include <linux/delay.h> 33 33 #include <linux/slab.h> 34 #include <linux/version.h>35 34 #include <linux/init.h> 36 #include <asm/uaccess.h>37 #include <linux/ioport.h>38 35 #include <linux/errno.h> 39 #include <linux/sched.h>40 41 36 #include "i2c.h" 42 37 #include "i2c-algo-pcf.h" 43 #include "i2c-pcf8584.h" 38 44 39 45 40 /* ----- global defines ----------------------------------------------- */ … … 54 49 */ 55 50 static int i2c_debug=0; 56 static int pcf_scan=0; /* have a look at what's hanging 'round */57 51 58 52 /* --- setting states on the bus with the right timing: --------------- */ … … 428 422 } 429 423 430 static int algo_control(struct i2c_adapter *adapter,431 unsigned int cmd, unsigned long arg)432 {433 return 0;434 }435 436 424 static u32 pcf_func(struct i2c_adapter *adap) 437 425 { … … 443 431 444 432 static struct i2c_algorithm pcf_algo = { 433 .owner = THIS_MODULE, 445 434 .name = "PCF8584 algorithm", 446 435 .id = I2C_ALGO_PCF, 447 436 .master_xfer = pcf_xfer, 448 .algo_control = algo_control,449 437 .functionality = pcf_func, 450 438 }; … … 474 462 475 463 i2c_add_adapter(adap); 476 477 /* scan bus */478 if (pcf_scan) {479 printk(KERN_INFO " i2c-algo-pcf.o: scanning bus %s.\n",480 adap->name);481 for (i = 0x00; i < 0xff; i+=2) {482 if (wait_for_bb(pcf_adap)) {483 printk(KERN_INFO " i2c-algo-pcf.o: scanning bus %s - TIMEOUTed.\n",484 adap->name);485 break;486 }487 i2c_outb(pcf_adap, i);488 i2c_start(pcf_adap);489 if ((wait_for_pin(pcf_adap, &status) >= 0) &&490 ((status & I2C_PCF_LRB) == 0)) {491 printk("(%02x)",i>>1);492 } else {493 printk(".");494 }495 i2c_stop(pcf_adap);496 udelay(pcf_adap->udelay);497 }498 printk("\n");499 }500 464 return 0; 501 465 } … … 514 478 MODULE_LICENSE("GPL"); 515 479 516 MODULE_PARM(pcf_scan, "i");517 480 MODULE_PARM(i2c_debug,"i"); 518 519 MODULE_PARM_DESC(pcf_scan, "Scan for active chips on the bus");520 481 MODULE_PARM_DESC(i2c_debug, 521 482 "debug level - 0 off; 1 normal; 2,3 more verbose; 9 pcf-protocol"); -
i2c/trunk/kernel/i2c-algo-pcf.h
r3457 r3765 25 25 /* $Id$ */ 26 26 27 #ifndef I2C_ALGO_PCF_H28 #define I2C_ALGO_PCF_H 127 #ifndef _LINUX_I2C_ALGO_PCF_H 28 #define _LINUX_I2C_ALGO_PCF_H 29 29 30 /* --- Defines for pcf-adapters --------------------------------------- */ 31 #include "i2c.h" 30 #include "i2c-pcf8584.h" 32 31 33 32 struct i2c_algo_pcf_data { … … 50 49 int i2c_pcf_del_bus(struct i2c_adapter *); 51 50 52 #endif /* I2C_ALGO_PCF_H */51 #endif /* _LINUX_I2C_ALGO_PCF_H */ -
i2c/trunk/kernel/i2c-core.c
r3759 r3765 29 29 #include <linux/slab.h> 30 30 #include <linux/proc_fs.h> 31 #include <linux/ config.h>31 #include <linux/init.h> 32 32 #include "i2c.h" 33 33 34 /* ----- compatibility stuff ----------------------------------------------- */35 36 #include <linux/version.h>37 #include <linux/init.h>38 39 #include <asm/uaccess.h>40 41 34 /* ----- global defines ---------------------------------------------------- */ 42 43 /* exclusive access to the bus */44 #define I2C_LOCK(adap) down(&adap->lock)45 #define I2C_UNLOCK(adap) up(&adap->lock)46 47 #define ADAP_LOCK() down(&adap_lock)48 #define ADAP_UNLOCK() up(&adap_lock)49 50 #define DRV_LOCK() down(&driver_lock)51 #define DRV_UNLOCK() up(&driver_lock)52 35 53 36 #define DEB(x) if (i2c_debug>=1) x; … … 56 39 /* ----- global variables -------------------------------------------------- */ 57 40 58 /**** lock for writing to global variables: the adapter & driver list */ 59 DECLARE_MUTEX(adap_lock); 60 DECLARE_MUTEX(driver_lock); 61 62 /**** adapter list */ 41 DECLARE_MUTEX(core_lists); 63 42 static struct i2c_adapter *adapters[I2C_ADAP_MAX]; 64 static int adap_count;65 66 /**** drivers list */67 43 static struct i2c_driver *drivers[I2C_DRIVER_MAX]; 68 static int driver_count;69 44 70 45 /**** debug level */ … … 82 57 int *eof , void *private); 83 58 84 static int i2cproc_register(struct i2c_adapter *adap, int bus);85 static void i2cproc_remove(int bus);86 59 /* To implement the dynamic /proc/bus/i2c-? files, we need our own 87 60 implementation of the read hook */ … … 89 62 .read = i2cproc_bus_read, 90 63 }; 64 65 static int i2cproc_register(struct i2c_adapter *adap, int bus); 66 static void i2cproc_remove(int bus); 67 91 68 #endif /* CONFIG_PROC_FS */ 92 69 … … 104 81 int i2c_add_adapter(struct i2c_adapter *adap) 105 82 { 106 int i,j,res ;107 108 ADAP_LOCK();83 int i,j,res = 0; 84 85 down(&core_lists); 109 86 for (i = 0; i < I2C_ADAP_MAX; i++) 110 87 if (NULL == adapters[i]) … … 117 94 goto ERROR0; 118 95 } 119 120 adapters[i] = adap; 121 adap_count++; 122 ADAP_UNLOCK(); 123 124 /* init data types */ 125 init_MUTEX(&adap->lock); 126 96 127 97 #ifdef CONFIG_PROC_FS 128 98 res = i2cproc_register(adap, i); 129 99 if (res<0) 130 goto ERROR 1;100 goto ERROR0; 131 101 #endif /* def CONFIG_PROC_FS */ 132 102 103 adapters[i] = adap; 104 105 /* init data types */ 106 init_MUTEX(&adap->bus); 107 init_MUTEX(&adap->list); 108 133 109 /* inform drivers of new adapters */ 134 DRV_LOCK();135 110 for (j=0;j<I2C_DRIVER_MAX;j++) 136 111 if (drivers[j]!=NULL && … … 138 113 /* We ignore the return code; if it fails, too bad */ 139 114 drivers[j]->attach_adapter(adap); 140 DRV_UNLOCK();141 115 142 116 DEB(printk(KERN_DEBUG "i2c-core.o: adapter %s registered as adapter %d.\n", 143 117 adap->name,i)); 144 145 return 0; 146 147 148 ERROR1: 149 ADAP_LOCK(); 150 adapters[i] = NULL; 151 adap_count--; 152 ERROR0: 153 ADAP_UNLOCK(); 118 ERROR0: 119 up(&core_lists); 154 120 return res; 155 121 } … … 158 124 int i2c_del_adapter(struct i2c_adapter *adap) 159 125 { 160 int i,j,res; 161 162 ADAP_LOCK(); 163 126 int i,j, res=0; 127 128 down(&core_lists); 164 129 for (i = 0; i < I2C_ADAP_MAX; i++) 165 130 if (adap == adapters[i]) … … 177 142 * this or hell will break loose... 178 143 */ 179 DRV_LOCK();180 144 for (j = 0; j < I2C_DRIVER_MAX; j++) 181 145 if (drivers[j] && (drivers[j]->flags & I2C_DF_DUMMY)) … … 184 148 "while detaching driver %s: driver not " 185 149 "detached!",adap->name,drivers[j]->name); 186 goto ERROR 1;150 goto ERROR0; 187 151 } 188 DRV_UNLOCK();189 190 152 191 153 /* detach any active clients. This must be done first, because … … 206 168 } 207 169 } 170 208 171 #ifdef CONFIG_PROC_FS 209 172 i2cproc_remove(i); … … 211 174 212 175 adapters[i] = NULL; 213 adap_count--; 214 215 ADAP_UNLOCK(); 216 DEB(printk(KERN_DEBUG "i2c-core.o: adapter unregistered: %s\n",adap->name)); 217 return 0; 218 219 ERROR0: 220 ADAP_UNLOCK(); 221 return res; 222 ERROR1: 223 DRV_UNLOCK(); 176 DEB(printk(KERN_DEBUG "i2c-core.o: adapter unregistered: %s\n",adap->name)); 177 ERROR0: 178 up(&core_lists); 224 179 return res; 225 180 } … … 235 190 { 236 191 int i; 237 DRV_LOCK(); 192 193 down(&core_lists); 238 194 for (i = 0; i < I2C_DRIVER_MAX; i++) 239 195 if (NULL == drivers[i]) … … 244 200 "- enlarge I2C_DRIVER_MAX.\n", 245 201 driver->name); 246 DRV_UNLOCK();202 up(&core_lists); 247 203 return -ENOMEM; 248 204 } 249 250 drivers[i] = driver; 251 driver_count++; 252 253 DRV_UNLOCK(); /* driver was successfully added */ 254 205 drivers[i] = driver; 255 206 DEB(printk(KERN_DEBUG "i2c-core.o: driver %s registered.\n",driver->name)); 256 207 257 ADAP_LOCK();258 259 208 /* now look for instances of driver on our adapters 260 209 */ … … 265 214 driver->attach_adapter(adapters[i]); 266 215 } 267 ADAP_UNLOCK();216 up(&core_lists); 268 217 return 0; 269 218 } … … 271 220 int i2c_del_driver(struct i2c_driver *driver) 272 221 { 273 int i,j,k,res ;274 275 DRV_LOCK();222 int i,j,k,res = 0; 223 224 down(&core_lists); 276 225 for (i = 0; i < I2C_DRIVER_MAX; i++) 277 226 if (driver == drivers[i]) … … 281 230 "[%s] not found\n", 282 231 driver->name); 283 DRV_UNLOCK();232 up(&core_lists); 284 233 return -ENODEV; 285 234 } … … 293 242 * pointers. 294 243 */ 295 ADAP_LOCK(); /* should be moved inside the if statement... */296 244 for (k=0;k<I2C_ADAP_MAX;k++) { 297 245 struct i2c_adapter *adap = adapters[k]; … … 312 260 "not unloaded!",driver->name, 313 261 adap->name); 314 ADAP_UNLOCK(); 315 return res; 262 goto ERROR0; 316 263 } 317 264 } else { … … 329 276 "unregistering driver " 330 277 "`%s', the client at " 331 "address %02x of adapter `%s' could not be " 332 "detached; driver not unloaded!", 278 "address %02x of " 279 "adapter `%s' could not " 280 "be detached; driver " 281 "not unloaded!", 333 282 driver->name, 334 283 client->addr, 335 284 adap->name); 336 ADAP_UNLOCK(); 337 return res; 285 goto ERROR0; 338 286 } 339 287 } … … 341 289 } 342 290 } 343 ADAP_UNLOCK();344 291 drivers[i] = NULL; 345 driver_count--;346 DRV_UNLOCK();347 348 292 DEB(printk(KERN_DEBUG "i2c-core.o: driver unregistered: %s\n",driver->name)); 349 return 0; 293 294 ERROR0: 295 up(&core_lists); 296 return res; 350 297 } 351 298 … … 353 300 { 354 301 int i; 302 down(&adapter->list); 355 303 for (i = 0; i < I2C_CLIENT_MAX ; i++) 356 304 if (adapter->clients[i] && (adapter->clients[i]->addr == addr)) 357 305 return -EBUSY; 306 up(&adapter->list); 358 307 return 0; 359 308 } … … 367 316 return -EBUSY; 368 317 318 down(&adapter->list); 369 319 for (i = 0; i < I2C_CLIENT_MAX; i++) 370 320 if (NULL == adapter->clients[i]) … … 374 324 " i2c-core.o: attach_client(%s) - enlarge I2C_CLIENT_MAX.\n", 375 325 client->name); 326 up(&adapter->list); 376 327 return -ENOMEM; 377 328 } 378 379 329 adapter->clients[i] = client; 380 adapter->client_count++;330 up(&adapter->list); 381 331 382 332 if (adapter->client_register) … … 400 350 int i,res; 401 351 402 for (i = 0; i < I2C_CLIENT_MAX; i++)403 if (client == adapter->clients[i])404 break;405 if (I2C_CLIENT_MAX == i) {406 printk(KERN_WARNING " i2c-core.o: unregister_client "407 "[%s] not found\n",408 client->name);409 return -ENODEV;410 }411 412 352 if( (client->flags & I2C_CLIENT_ALLOW_USE) && 413 353 (client->usage_count>0)) … … 421 361 } 422 362 363 down(&adapter->list); 364 for (i = 0; i < I2C_CLIENT_MAX; i++) 365 if (client == adapter->clients[i]) 366 break; 367 if (I2C_CLIENT_MAX == i) { 368 printk(KERN_WARNING " i2c-core.o: unregister_client " 369 "[%s] not found\n", 370 client->name); 371 up(&adapter->list); 372 return -ENODEV; 373 } 423 374 adapter->clients[i] = NULL; 424 adapter->client_count--;375 up(&adapter->list); 425 376 426 377 DEB(printk(KERN_DEBUG "i2c-core.o: client [%s] unregistered.\n",client->name)); … … 447 398 } 448 399 400 #if 0 /* just forget about this for now --km */ 449 401 struct i2c_client *i2c_get_client(int driver_id, int adapter_id, 450 402 struct i2c_client *prev) … … 513 465 return 0; 514 466 } 467 #endif 515 468 516 469 int i2c_use_client(struct i2c_client *client) … … 559 512 560 513 /* This function generates the output for /proc/bus/i2c */ 561 int read_bus_i2c(char *buf, char **start, off_t offset, int len, int *eof,514 static int read_bus_i2c(char *buf, char **start, off_t offset, int len, int *eof, 562 515 void *private) 563 516 { … … 565 518 int nr = 0; 566 519 /* Note that it is safe to write a `little' beyond len. Yes, really. */ 520 down(&core_lists); 567 521 for (i = 0; (i < I2C_ADAP_MAX) && (nr < len); i++) 568 522 if (adapters[i]) { … … 581 535 adapters[i]->algo->name); 582 536 } 537 up(&core_lists); 583 538 return nr; 584 539 } … … 591 546 char *kbuf; 592 547 struct i2c_client *client; 548 struct i2c_adapter *adap; 593 549 int i,j,k,order_nr,len=0; 594 550 size_t len_total; … … 600 556 /* adjust to maximum file size */ 601 557 len_total = (I2C_CLIENT_MAX * OUTPUT_LENGTH_PER_LINE); 558 559 down(&core_lists); 560 /* adap = file->private_data; ?? --km */ 602 561 for (i = 0; i < I2C_ADAP_MAX; i++) 603 if (adapters[i]->inode == inode->i_ino) { 604 /* We need a bit of slack in the kernel buffer; this makes the 605 sprintf safe. */ 606 if (! (kbuf = kmalloc(len_total + 607 OUTPUT_LENGTH_PER_LINE, 608 GFP_KERNEL))) 609 return -ENOMEM; 610 /* Order will hold the indexes of the clients 611 sorted by address */ 612 order_nr=0; 613 for (j = 0; j < I2C_CLIENT_MAX; j++) { 614 if ((client = adapters[i]->clients[j]) && 615 (client->driver->id != I2C_DRIVERID_I2CDEV)) { 616 for(k = order_nr; 617 (k > 0) && 618 adapters[i]->clients[order[k-1]]-> 619 addr > client->addr; 620 k--) 621 order[k] = order[k-1]; 622 order[k] = j; 623 order_nr++; 624 } 625 } 626 627 628 for (j = 0; (j < order_nr) && (len < len_total); j++) { 629 client = adapters[i]->clients[order[j]]; 630 len += sprintf(kbuf+len,"%02x\t%-32s\t%-32s\n", 631 client->addr, 632 client->name, 633 client->driver->name); 634 } 635 len = len - file->f_pos; 636 if (len > count) 637 len = count; 638 if (len < 0) 639 len = 0; 640 if (copy_to_user (buf,kbuf+file->f_pos, len)) { 641 kfree(kbuf); 642 return -EFAULT; 643 } 644 file->f_pos += len; 645 kfree(kbuf); 646 return len; 647 } 648 return -ENOENT; 649 } 650 562 if (adapters[i] && (adapters[i]->inode == inode->i_ino)) { 563 adap = adapters[i]; 564 break; 565 } 566 if ( I2C_ADAP_MAX == i ) { 567 up(&core_lists); 568 return -ENOENT; 569 } 570 571 /* We need a bit of slack in the kernel buffer; this makes the 572 sprintf safe. */ 573 if (! (kbuf = kmalloc(len_total + 574 OUTPUT_LENGTH_PER_LINE, 575 GFP_KERNEL))) 576 return -ENOMEM; 577 578 /* Order will hold the indexes of the clients 579 sorted by address */ 580 order_nr=0; 581 down(&adap->list); 582 for (j = 0; j < I2C_CLIENT_MAX; j++) { 583 if ((client = adap->clients[j]) && 584 (client->driver->id != I2C_DRIVERID_I2CDEV)) { 585 for(k = order_nr; 586 (k > 0) && 587 adap->clients[order[k-1]]-> 588 addr > client->addr; 589 k--) 590 order[k] = order[k-1]; 591 order[k] = j; 592 order_nr++; 593 } 594 } 595 596 597 for (j = 0; (j < order_nr) && (len < len_total); j++) { 598 client = adap->clients[order[j]]; 599 len += sprintf(kbuf+len,"%02x\t%-32s\t%-32s\n", 600 client->addr, 601 client->name, 602 client->driver->name); 603 } 604 up(&adap->list); 605 up(&core_lists); 606 607 len = len - file->f_pos; 608 if (len > count) 609 len = count; 610 if (len < 0) 611 len = 0; 612 if (copy_to_user (buf,kbuf+file->f_pos, len)) { 613 kfree(kbuf); 614 return -EFAULT; 615 } 616 file->f_pos += len; 617 kfree(kbuf); 618 return len; 619 } 651 620 652 621 static int i2cproc_register(struct i2c_adapter *adap, int bus) … … 664 633 665 634 proc_entry->proc_fops = &i2cproc_operations; 666 proc_entry->owner = THIS_MODULE;635 proc_entry->owner = adap->owner; 667 636 adap->inode = proc_entry->low_ino; 668 637 return 0; … … 695 664 remove_proc_entry("i2c",proc_bus); 696 665 } 666 697 667 #endif /* def CONFIG_PROC_FS */ 698 699 668 700 669 /* ---------------------------------------------------- … … 711 680 adap->name,num)); 712 681 713 I2C_LOCK(adap);682 down(&adap->bus); 714 683 ret = adap->algo->master_xfer(adap,msgs,num); 715 I2C_UNLOCK(adap);684 up(&adap->bus); 716 685 717 686 return ret; … … 738 707 count,client->adapter->name)); 739 708 740 I2C_LOCK(adap);709 down(&adap->bus); 741 710 ret = adap->algo->master_xfer(adap,&msg,1); 742 I2C_UNLOCK(adap);711 up(&adap->bus); 743 712 744 713 /* if everything went ok (i.e. 1 msg transmitted), return #bytes … … 768 737 count,client->adapter->name)); 769 738 770 I2C_LOCK(adap);739 down(&adap->bus); 771 740 ret = adap->algo->master_xfer(adap,&msg,1); 772 I2C_UNLOCK(adap);741 up(&adap->bus); 773 742 774 743 DEB2(printk(KERN_DEBUG "i2c-core.o: master_recv: return:%d (count:%d, addr:0x%02x)\n", … … 1426 1395 memset(adapters,0,sizeof(adapters)); 1427 1396 memset(drivers,0,sizeof(drivers)); 1428 adap_count=0; 1429 driver_count=0; 1430 1431 init_MUTEX(&adap_lock); 1432 init_MUTEX(&driver_lock); 1433 1397 1434 1398 #ifdef CONFIG_PROC_FS 1435 i2cproc_init(); 1399 return i2cproc_init(); 1400 #else 1401 return 0; 1436 1402 #endif 1437 1403 1438 return 0;1439 1404 } 1440 1405 … … 1452 1417 EXPORT_SYMBOL(i2c_attach_client); 1453 1418 EXPORT_SYMBOL(i2c_detach_client); 1454 EXPORT_SYMBOL(i2c_get_client);1455 1419 EXPORT_SYMBOL(i2c_use_client); 1456 1420 EXPORT_SYMBOL(i2c_release_client); -
i2c/trunk/kernel/i2c-dev.c
r3758 r3765 31 31 /* $Id$ */ 32 32 33 #include <linux/config.h>34 33 #include <linux/kernel.h> 35 34 #include <linux/module.h> 36 35 #include <linux/fs.h> 37 36 #include <linux/slab.h> 38 #include <linux/version.h>39 37 #include <linux/smp_lock.h> 40 38 #include <linux/devfs_fs_kernel.h> 41 39 #include <linux/init.h> 40 #include "i2c.h" 41 #include "i2c-dev.h" 42 #include <asm/uaccess.h> 42 43 43 44 /* If you want debugging uncomment: */ 44 45 /* #define DEBUG */ 45 46 46 #include <linux/init.h>47 #include <asm/uaccess.h>48 #include "i2c.h"49 #include "i2c-dev.h"50 47 51 48 /* struct file_operations changed too often in the 2.1 series for nice code */ … … 81 78 82 79 static struct i2c_driver i2cdev_driver = { 80 .owner = THIS_MODULE, /* not really used */ 83 81 .name = "i2c-dev dummy driver", 84 82 .id = I2C_DRIVERID_I2CDEV, … … 362 360 return -ENOMEM; 363 361 memcpy(client,&i2cdev_client_template,sizeof(struct i2c_client)); 364 client->adapter = i2cdev_adaps[minor]; 362 363 /* registered with adapter, passed as client to user */ 364 client->adapter = file->private_data; 365 365 file->private_data = client; 366 366 367 if (!try_module_get(i2cdev_adaps[minor]->owner)) { 367 /* use adapter module, i2c-dev handled with fops */ 368 if (!try_module_get(client->adapter->owner)) { 368 369 kfree(client); 369 370 return -ENODEV; … … 378 379 static int i2cdev_release (struct inode *inode, struct file *file) 379 380 { 381 struct i2c_client *client; 382 #ifdef DEBUG 380 383 unsigned int minor = minor(inode->i_rdev); 381 kfree(file->private_data); 382 file->private_data=NULL; 384 #endif 385 386 client = file->private_data; 387 file->private_data = NULL; 388 module_put(client->adapter->owner); 389 kfree(client); 383 390 #ifdef DEBUG 384 391 printk(KERN_DEBUG "i2c-dev.o: Closed: i2c-%d\n", minor); 385 392 #endif 386 module_put(i2cdev_adaps[minor]->owner);387 393 return 0; 388 394 } … … 408 414 DEVFS_FL_DEFAULT, I2C_MAJOR, i, 409 415 S_IFCHR | S_IRUSR | S_IWUSR, 410 &i2cdev_fops, NULL);416 &i2cdev_fops, adap); 411 417 printk(KERN_DEBUG "i2c-dev.o: Registered '%s' as minor %d\n",adap->name,i); 412 418 } else { -
i2c/trunk/kernel/i2c-dev.h
r3758 r3765 26 26 27 27 #include <linux/types.h> 28 #include "i2c.h"29 28 30 29 /* Some IOCTL commands are defined in <linux/i2c.h> */ … … 45 44 }; 46 45 47 #ifndef __KERNEL__48 49 #include <sys/ioctl.h>50 51 static inline __s32 i2c_smbus_access(int file, char read_write, __u8 command,52 int size, union i2c_smbus_data *data)53 {54 struct i2c_smbus_ioctl_data args;55 56 args.read_write = read_write;57 args.command = command;58 args.size = size;59 args.data = data;60 return ioctl(file,I2C_SMBUS,&args);61 }62 63 64 static inline __s32 i2c_smbus_write_quick(int file, __u8 value)65 {66 return i2c_smbus_access(file,value,0,I2C_SMBUS_QUICK,NULL);67 }68 69 static inline __s32 i2c_smbus_read_byte(int file)70 {71 union i2c_smbus_data data;72 if (i2c_smbus_access(file,I2C_SMBUS_READ,0,I2C_SMBUS_BYTE,&data))73 return -1;74 else75 return 0x0FF & data.byte;76 }77 78 static inline __s32 i2c_smbus_write_byte(int file, __u8 value)79 {80 return i2c_smbus_access(file,I2C_SMBUS_WRITE,value,81 I2C_SMBUS_BYTE,NULL);82 }83 84 static inline __s32 i2c_smbus_read_byte_data(int file, __u8 command)85 {86 union i2c_smbus_data data;87 if (i2c_smbus_access(file,I2C_SMBUS_READ,command,88 I2C_SMBUS_BYTE_DATA,&data))89 return -1;90 else91 return 0x0FF & data.byte;92 }93 94 static inline __s32 i2c_smbus_write_byte_data(int file, __u8 command,95 __u8 value)96 {97 union i2c_smbus_data data;98 data.byte = value;99 return i2c_smbus_access(file,I2C_SMBUS_WRITE,command,100 I2C_SMBUS_BYTE_DATA, &data);101 }102 103 static inline __s32 i2c_smbus_read_word_data(int file, __u8 command)104 {105 union i2c_smbus_data data;106 if (i2c_smbus_access(file,I2C_SMBUS_READ,command,107 I2C_SMBUS_WORD_DATA,&data))108 return -1;109 else110 return 0x0FFFF & data.word;111 }112 113 static inline __s32 i2c_smbus_write_word_data(int file, __u8 command,114 __u16 value)115 {116 union i2c_smbus_data data;117 data.word = value;118 return i2c_smbus_access(file,I2C_SMBUS_WRITE,command,119 I2C_SMBUS_WORD_DATA, &data);120 }121 122 static inline __s32 i2c_smbus_process_call(int file, __u8 command, __u16 value)123 {124 union i2c_smbus_data data;125 data.word = value;126 if (i2c_smbus_access(file,I2C_SMBUS_WRITE,command,127 I2C_SMBUS_PROC_CALL,&data))128 return -1;129 else130 return 0x0FFFF & data.word;131 }132 133 134 /* Returns the number of read bytes */135 static inline __s32 i2c_smbus_read_block_data(int file, __u8 command,136 __u8 *values)137 {138 union i2c_smbus_data data;139 int i;140 if (i2c_smbus_access(file,I2C_SMBUS_READ,command,141 I2C_SMBUS_BLOCK_DATA,&data))142 return -1;143 else {144 for (i = 1; i <= data.block[0]; i++)145 values[i-1] = data.block[i];146 return data.block[0];147 }148 }149 150 static inline __s32 i2c_smbus_write_block_data(int file, __u8 command,151 __u8 length, __u8 *values)152 {153 union i2c_smbus_data data;154 int i;155 if (length > 32)156 length = 32;157 for (i = 1; i <= length; i++)158 data.block[i] = values[i-1];159 data.block[0] = length;160 return i2c_smbus_access(file,I2C_SMBUS_WRITE,command,161 I2C_SMBUS_BLOCK_DATA, &data);162 }163 164 /* Returns the number of read bytes */165 static inline __s32 i2c_smbus_read_i2c_block_data(int file, __u8 command,166 __u8 *values)167 {168 union i2c_smbus_data data;169 int i;170 if (i2c_smbus_access(file,I2C_SMBUS_READ,command,171 I2C_SMBUS_I2C_BLOCK_DATA,&data))172 return -1;173 else {174 for (i = 1; i <= data.block[0]; i++)175 values[i-1] = data.block[i];176 return data.block[0];177 }178 }179 180 static inline __s32 i2c_smbus_write_i2c_block_data(int file, __u8 command,181 __u8 length, __u8 *values)182 {183 union i2c_smbus_data data;184 int i;185 if (length > 32)186 length = 32;187 for (i = 1; i <= length; i++)188 data.block[i] = values[i-1];189 data.block[0] = length;190 return i2c_smbus_access(file,I2C_SMBUS_WRITE,command,191 I2C_SMBUS_I2C_BLOCK_DATA, &data);192 }193 194 /* Returns the number of read bytes */195 static inline __s32 i2c_smbus_block_process_call(int file, __u8 command,196 __u8 length, __u8 *values)197 {198 union i2c_smbus_data data;199 int i;200 if (length > 32)201 length = 32;202 for (i = 1; i <= length; i++)203 data.block[i] = values[i-1];204 data.block[0] = length;205 if (i2c_smbus_access(file,I2C_SMBUS_WRITE,command,206 I2C_SMBUS_BLOCK_PROC_CALL,&data))207 return -1;208 else {209 for (i = 1; i <= data.block[0]; i++)210 values[i-1] = data.block[i];211 return data.block[0];212 }213 }214 215 #endif /* ndef __KERNEL__ */216 217 46 #endif /* _LINUX_I2C_DEV_H */ -
i2c/trunk/kernel/i2c-elektor.c
r3758 r3765 31 31 #include <linux/delay.h> 32 32 #include <linux/slab.h> 33 #include <linux/version.h>34 33 #include <linux/init.h> 35 34 #include <linux/interrupt.h> 36 35 #include <linux/pci.h> 37 36 #include <linux/wait.h> 38 39 37 #include "i2c.h" 40 38 #include "i2c-algo-pcf.h" 41 42 39 #include <asm/io.h> 43 40 #include <asm/irq.h> 44 45 #include "i2c-pcf8584.h"46 41 47 42 #define DEFAULT_BASE 0x330 -
i2c/trunk/kernel/i2c-elv.c
r3759 r3765 28 28 #include <linux/delay.h> 29 29 #include <linux/slab.h> 30 #include <linux/version.h>31 30 #include <linux/init.h> 32 #include <asm/uaccess.h>33 31 #include <linux/ioport.h> 34 #include <asm/io.h>35 32 #include <linux/errno.h> 36 33 #include "i2c.h" 37 34 #include "i2c-algo-bit.h" 35 #include <asm/io.h> 38 36 39 37 #define DEFAULT_BASE 0x378 -
i2c/trunk/kernel/i2c-frodo.c
r3759 r3765 13 13 */ 14 14 15 #include <linux/config.h>16 #include <linux/version.h>17 15 #include <linux/module.h> 18 19 16 #include <linux/kernel.h> 20 17 #include <linux/init.h> 21 18 #include <linux/delay.h> 22 19 #include "i2c.h" 20 #include "i2c-algo-bit.h" 23 21 #include <asm/hardware.h> 24 22 25 #include "i2c.h"26 #include "i2c-algo-bit.h"27 23 28 24 static void frodo_setsda (void *data,int state) -
i2c/trunk/kernel/i2c-id.h
r3751 r3765 23 23 /* $Id$ */ 24 24 25 #ifndef I2C_ID_H 26 #define I2C_ID_H 25 #ifndef LINUX_I2C_ID_H 26 #define LINUX_I2C_ID_H 27 27 28 /* 28 29 * This file is part of the i2c-bus package and contains the identifier … … 254 255 #define I2C_HW_IPMB 0x00 255 256 256 #endif /* I2C_ID_H */257 #endif /* LINUX_I2C_ID_H */ -
i2c/trunk/kernel/i2c-pcf-epp.c
r3759 r3765 8 8 #include <linux/delay.h> 9 9 #include <linux/slab.h> 10 #include <linux/version.h>11 10 #include <linux/init.h> 12 11 #include <linux/parport.h> 12 #include "i2c.h" 13 #include "i2c-algo-pcf.h" 13 14 #include <asm/irq.h> 14 15 #include <asm/io.h> 15 16 16 #include "i2c.h"17 #include "i2c-algo-pcf.h"18 #include "i2c-pcf8584.h"19 17 20 18 struct i2c_pcf_epp { -
i2c/trunk/kernel/i2c-pcf8584.h
r3582 r3765 24 24 /* $Id$ */ 25 25 26 #ifndef I2C_PCF8584_H27 #define I2C_PCF8584_H 126 #ifndef _LINUX_I2C_PCF8584_H 27 #define _LINUX_I2C_PCF8584_H 28 28 29 29 /* ----- Control register bits ---------------------------------------- */ … … 76 76 #define I2C_PCF_CLKREG I2C_PCF_ES1 77 77 78 #endif /* I2C_PCF8584_H */78 #endif /* _LINUX_I2C_PCF8584_H */ -
i2c/trunk/kernel/i2c-philips-par.c
r3759 r3765 32 32 #include "i2c.h" 33 33 #include "i2c-algo-bit.h" 34 35 #ifndef __exit36 #define __exit __init37 #endif38 34 39 35 static int type; -
i2c/trunk/kernel/i2c-pport.c
r3759 r3765 31 31 #include <linux/delay.h> 32 32 #include <linux/slab.h> 33 #include <linux/version.h>34 33 #include <linux/init.h> 35 #include <asm/uaccess.h>36 34 #include <linux/ioport.h> 37 #include <asm/io.h>38 35 #include <linux/errno.h> 39 36 #include "i2c.h" 40 37 #include "i2c-algo-bit.h" 41 42 MODULE_LICENSE("GPL"); 38 #include <asm/io.h> 39 43 40 44 41 #define DEFAULT_BASE 0x378 … … 201 198 MODULE_AUTHOR("Daniel Smolik <marvin@sitour.cz>"); 202 199 MODULE_DESCRIPTION("I2C-Bus adapter routines for Primitive parallel port adapter"); 200 MODULE_LICENSE("GPL"); 201 203 202 MODULE_PARM(base, "i"); 204 203 -
i2c/trunk/kernel/i2c-proc.c
r3758 r3765 30 30 #include <linux/sysctl.h> 31 31 #include <linux/proc_fs.h> 32 #include <linux/i oport.h>32 #include <linux/init.h> 33 33 #include "i2c.h" 34 34 #include "i2c-proc.h" 35 #include <linux/init.h>36 #include <asm/uaccess.h>37 35 38 36 static int i2c_create_name(char **name, const char *prefix, … … 71 69 72 70 static ctl_table i2c_proc_dev[] = { 73 {DEV_SENSORS, "sensors", NULL, 0, 0555, i2c_proc_dev_sensors },71 {DEV_SENSORS, "sensors", NULL, 0, 0555, i2c_proc_dev_sensors, NULL}, 74 72 {0}, 75 73 }; … … 77 75 78 76 static ctl_table i2c_proc[] = { 79 {CTL_DEV, "dev", NULL, 0, 0555, i2c_proc_dev },77 {CTL_DEV, "dev", NULL, 0, 0555, i2c_proc_dev, NULL}, 80 78 {0} 81 79 }; … … 88 86 a LM75 chip on the third i2c bus at address 0x4e). 89 87 name is allocated first. */ 90 int i2c_create_name(char **name, const char *prefix,88 static int i2c_create_name(char **name, const char *prefix, 91 89 struct i2c_adapter *adapter, int addr) 92 90 { … … 126 124 copied in memory. The extra2 field of each file is set to point to client. 127 125 If any driver wants subdirectories within the newly created directory, 128 this function must be updated! 129 controlling_mod is the controlling module. It should usually be 130 THIS_MODULE when calling. Note that this symbol is not defined in 131 kernels before 2.3.13; define it to NULL in that case. We will not use it 132 for anything older than 2.3.27 anyway. */ 126 this function must be updated! */ 133 127 int i2c_register_entry(struct i2c_client *client, const char *prefix, 134 ctl_table * ctl_template, 135 struct module *controlling_mod) 136 { 137 int i, res, len, id; 138 ctl_table *new_table; 128 ctl_table * ctl_template) 129 { 130 int i, res, len, id, adap_id; 131 ctl_table *new_table, *client_tbl, *tbl; 139 132 char *name; 140 133 struct ctl_table_header *new_header; … … 151 144 return -ENOMEM; 152 145 } 146 153 147 id += 256; 154 148 155 149 len = 0; 156 150 while (ctl_template[len].procname) 157 151 len++; 158 len += 7;159 if (!(new_table = kmalloc(sizeof(ctl_table) * len,GFP_KERNEL))) {152 if (!(new_table = kmalloc(sizeof(sysctl_table) + sizeof(ctl_table) * (len + 1), 153 GFP_KERNEL))) { 160 154 kfree(name); 161 155 return -ENOMEM; 162 156 } 163 157 164 memcpy(new_table, sysctl_table, 6 * sizeof(ctl_table)); 165 new_table[0].child = &new_table[2]; 166 new_table[2].child = &new_table[4]; 167 new_table[4].child = &new_table[6]; 168 new_table[4].procname = name; 169 new_table[4].ctl_name = id; 170 memcpy(new_table + 6, ctl_template, (len - 6) * sizeof(ctl_table)); 171 for (i = 6; i < len; i++) 172 new_table[i].extra2 = client; 158 memcpy(new_table, sysctl_table, sizeof(sysctl_table)); 159 tbl = new_table; /* sys/ */ 160 tbl = tbl->child = tbl + 2; /* dev/ */ 161 tbl = tbl->child = tbl + 2; /* sensors/ */ 162 client_tbl = tbl->child = tbl + 2; /* XX-chip-YY-ZZ/ */ 163 164 client_tbl->procname = name; 165 client_tbl->ctl_name = id; 166 client_tbl->child = client_tbl + 2; 167 168 /* Next the client sysctls. --km */ 169 tbl = client_tbl->child; 170 memcpy(tbl, ctl_template, sizeof(ctl_table) * len); 171 for (i = 0; i < len; i++) 172 tbl[i].extra2 = client; 173 173 174 174 if (!(new_header = register_sysctl_table(new_table, 0))) { … … 179 179 } 180 180 181 i2c_entries[id - 256] = new_header;181 i2c_entries[id - 256] = new_header; 182 182 183 183 i2c_clients[id - 256] = client; 184 184 185 #ifdef DEBUG 185 186 if (!new_header || !new_header->ctl_table || 186 187 !new_header->ctl_table->child || 187 188 !new_header->ctl_table->child->child || 188 !new_header->ctl_table->child->child->de ) {189 !new_header->ctl_table->child->child->de ) { 189 190 printk 190 191 (KERN_ERR "i2c-proc.o: NULL pointer when trying to install fill_inode fix!\n"); … … 192 193 } 193 194 #endif /* DEBUG */ 194 new_header->ctl_table->child->child->de->owner = controlling_mod; 195 195 client_tbl->de->owner = client->driver->owner; 196 196 return id; 197 197 } … … 201 201 ctl_table *table; 202 202 char *temp; 203 id -= 256; 203 204 id -= 256; 204 205 if (i2c_entries[id]) { 205 206 table = i2c_entries[id]->ctl_table; 206 207 unregister_sysctl_table(i2c_entries[id]); 207 208 /* 2-step kfree needed to keep gcc happy about const points */ 208 (const char *) temp = table[ 4].procname;209 (const char *) temp = table[6].procname; 209 210 kfree(temp); 210 211 kfree(table); … … 214 215 } 215 216 216 int i2c_proc_chips(ctl_table * ctl, int write, struct file *filp,217 static int i2c_proc_chips(ctl_table * ctl, int write, struct file *filp, 217 218 void *buffer, size_t * lenp) 218 219 { … … 252 253 } 253 254 254 int i2c_sysctl_chips(ctl_table * table, int *name, int nlen,255 static int i2c_sysctl_chips(ctl_table * table, int *name, int nlen, 255 256 void *oldval, size_t * oldlenp, void *newval, 256 257 size_t newlen, void **context) … … 414 415 hidden bugs in it, even leading to crashes and things! 415 416 */ 416 int i2c_parse_reals(int *nrels, void *buffer, int bufsize,417 static int i2c_parse_reals(int *nrels, void *buffer, int bufsize, 417 418 long *results, int magnitude) 418 419 { … … 515 516 } 516 517 517 int i2c_write_reals(int nrels, void *buffer, int *bufsize,518 static int i2c_write_reals(int nrels, void *buffer, int *bufsize, 518 519 long *results, int magnitude) 519 520 { … … 823 824 } 824 825 826 EXPORT_SYMBOL(i2c_register_entry); 825 827 EXPORT_SYMBOL(i2c_deregister_entry); 828 EXPORT_SYMBOL(i2c_proc_real); 829 EXPORT_SYMBOL(i2c_sysctl_real); 826 830 EXPORT_SYMBOL(i2c_detect); 827 EXPORT_SYMBOL(i2c_proc_real);828 EXPORT_SYMBOL(i2c_register_entry);829 EXPORT_SYMBOL(i2c_sysctl_real);830 831 831 832 MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>"); -
i2c/trunk/kernel/i2c-proc.h
r3753 r3765 20 20 */ 21 21 22 #ifndef SENSORS_SENSORS_H 23 #define SENSORS_SENSORS_H 24 25 #ifdef __KERNEL__ 26 27 /* Next two must be included before sysctl.h can be included, in 2.0 kernels */ 28 #include <linux/types.h> 29 #include <linux/fs.h> 22 #ifndef _LINUX_I2C_PROC_H 23 #define _LINUX_I2C_PROC_H 24 30 25 #include <linux/sysctl.h> 31 26 … … 75 70 extern int i2c_register_entry(struct i2c_client *client, 76 71 const char *prefix, 77 ctl_table * ctl_template, 78 struct module *controlling_mod); 72 ctl_table * ctl_template); 79 73 80 74 extern void i2c_deregister_entry(int id); … … 389 383 /* This macro is used to scale user-input to sensible values in almost all 390 384 chip drivers. */ 391 externinline int SENSORS_LIMIT(long value, long low, long high)385 static inline int SENSORS_LIMIT(long value, long low, long high) 392 386 { 393 387 if (value < low) … … 399 393 } 400 394 401 #endif /* def __KERNEL__ */402 403 395 404 396 /* The maximum length of the prefix */ … … 419 411 }; 420 412 421 #endif /* def SENSORS_SENSORS_H */422 413 #endif /* def _LINUX_I2C_PROC_H */ 414 -
i2c/trunk/kernel/i2c-rpx.c
r3759 r3765 18 18 #include <linux/stddef.h> 19 19 #include <linux/parport.h> 20 20 #include "i2c.h" 21 #include "i2c-algo-8xx.h" 21 22 #include <asm/mpc8xx.h> 22 23 #include <asm/commproc.h> 23 24 24 #include "i2c.h"25 #include "i2c-algo-8xx.h"26 25 27 26 static void -
i2c/trunk/kernel/i2c-velleman.c
r3759 r3765 26 26 #include <linux/init.h> 27 27 #include <linux/delay.h> 28 #include <linux/string.h> /* for 2.0 kernels to get NULL */29 #include <asm/errno.h> /* for 2.0 kernels to get ENODEV */30 #include <asm/io.h>31 28 #include "i2c.h" 32 29 #include "i2c-algo-bit.h" 30 #include <asm/io.h> 33 31 34 32 /* ----- global defines ----------------------------------------------- */ -
i2c/trunk/kernel/i2c.h
r3758 r3765 32 32 #define I2C_VERSION "2.7.0" 33 33 34 #include "i2c-id.h" /* id values of adapters et. al. */34 #include <linux/module.h> 35 35 #include <linux/types.h> 36 37 38 struct i2c_msg; 39 40 41 #ifdef __KERNEL__ 42 43 #include <linux/config.h> 36 #include "i2c-id.h" 44 37 #include <asm/semaphore.h> 45 46 38 47 39 /* --- General options ------------------------------------------------ */ … … 53 45 #define I2C_DUMMY_MAX 4 54 46 47 struct i2c_msg; 55 48 struct i2c_algorithm; 56 49 struct i2c_adapter; … … 59 52 struct i2c_client_address_data; 60 53 union i2c_smbus_data; 61 62 54 63 55 /* … … 183 175 */ 184 176 struct i2c_algorithm { 177 struct module *owner; /* future use --km */ 185 178 char name[32]; /* textual description */ 186 179 unsigned int id; … … 207 200 }; 208 201 209 210 202 /* 211 203 * i2c_adapter is the structure used to identify a physical i2c bus along … … 230 222 231 223 /* data fields that are valid for all devices */ 232 struct semaphore lock; 224 struct semaphore bus; 225 struct semaphore list; 233 226 unsigned int flags;/* flags specifying div. data */ 234 227 235 228 struct i2c_client *clients[I2C_CLIENT_MAX]; 236 int client_count;237 229 238 230 int timeout; … … 327 319 i2c_client_found_addr_proc *found_proc); 328 320 321 static inline int i2c_client_command(struct i2c_client *client, 322 unsigned int cmd, void *arg) 323 { 324 if (client->driver && client->driver->command) 325 return client->driver->command(client, cmd, arg); 326 else 327 return -EINVAL; 328 } 329 329 330 /* An ioctl like call to set div. parameters of the adapter. 330 331 */ … … 343 344 /* Return 1 if adapter supports everything we need, 0 if not. */ 344 345 extern int i2c_check_functionality (struct i2c_adapter *adap, u32 func); 345 346 #endif /* __KERNEL__ */347 346 348 347 /* … … 497 496 #define I2C_MAJOR 89 /* Device major number */ 498 497 499 #ifdef __KERNEL__500 501 # ifndef NULL502 # define NULL ( (void *) 0 )503 # endif504 505 # ifndef ENODEV506 # include <asm/errno.h>507 # endif508 509 498 /* These defines are used for probing i2c client addresses */ 510 499 /* Default fill of many variables */ … … 568 557 ((adapptr)->algo->id == I2C_ALGO_ISA) 569 558 570 #endif /* def __KERNEL__ */571 559 #endif /* _LINUX_I2C_H */ -
i2c/trunk/mkpatch/Config.in
r3695 r3765 45 45 fi 46 46 47 # This is needed for automatic patch generation: sensors code starts here48 # This is needed for automatic patch generation: sensors code ends here49 50 47 dep_tristate 'I2C device interface' CONFIG_I2C_CHARDEV $CONFIG_I2C 51 48 dep_tristate 'I2C /proc interface (required for hardware sensors)' CONFIG_I2C_PROC $CONFIG_I2C $CONFIG_SYSCTL -
i2c/trunk/mkpatch/FILES
r3695 r3765 1 kernel/i2c-adap-ibm_ocp.c drivers/i2c/i2c-adap-ibm_ocp.c 1 kernel/i2c-core.c drivers/i2c/i2c-core.c 2 kernel/i2c-dev.c drivers/i2c/i2c-dev.c 3 kernel/i2c-proc.c drivers/i2c/i2c-proc.c 2 4 kernel/i2c-algo-8xx.c drivers/i2c/i2c-algo-8xx.c 3 5 kernel/i2c-algo-bit.c drivers/i2c/i2c-algo-bit.c 6 kernel/i2c-algo-biths.c drivers/i2c/i2c-algo-biths.c 4 7 kernel/i2c-algo-ibm_ocp.c drivers/i2c/i2c-algo-ibm_ocp.c 5 8 kernel/i2c-algo-pcf.c drivers/i2c/i2c-algo-pcf.c 6 kernel/i2c-core.c drivers/i2c/i2c-core.c7 kernel/i2c-dev.c drivers/i2c/i2c-dev.c8 9 kernel/i2c-elektor.c drivers/i2c/i2c-elektor.c 9 10 kernel/i2c-elv.c drivers/i2c/i2c-elv.c … … 12 13 kernel/i2c-philips-par.c drivers/i2c/i2c-philips-par.c 13 14 kernel/i2c-pport.c drivers/i2c/i2c-pport.c 14 kernel/i2c-proc.c drivers/i2c/i2c-proc.c15 15 kernel/i2c-rpx.c drivers/i2c/i2c-rpx.c 16 16 kernel/i2c-velleman.c drivers/i2c/i2c-velleman.c 17 17 kernel/i2c.h include/linux/i2c.h 18 kernel/i2c-id.h include/linux/i2c-id.h 18 19 kernel/i2c-dev.h include/linux/i2c-dev.h 20 kernel/i2c-proc.h include/linux/i2c-proc.h 19 21 kernel/i2c-algo-8xx.h include/linux/i2c-algo-8xx.h 20 22 kernel/i2c-algo-bit.h include/linux/i2c-algo-bit.h 23 kernel/i2c-algo-biths.h include/linux/i2c-algo-biths.h 21 24 kernel/i2c-algo-ibm_ocp.h include/linux/i2c-algo-ibm_ocp.h 22 25 kernel/i2c-algo-pcf.h include/linux/i2c-algo-pcf.h 23 kernel/i2c-elektor.h include/linux/i2c-elektor.h 24 kernel/i2c-id.h include/linux/i2c-id.h 25 kernel/i2c-pcf8584.h drivers/i2c/i2c-pcf8584.h 26 kernel/i2c-proc.h include/linux/i2c-proc.h 27 mkpatch/Config.in drivers/i2c/Config.in 26 kernel/i2c-pcf8584.h include/linux/i2c-pcf8584.h 28 27 doc/dev-interface Documentation/i2c/dev-interface 29 28 doc/functionality Documentation/i2c/functionality -
i2c/trunk/mkpatch/INCLUDES
r3694 r3765 1 1 "i2c.h" <linux/i2c.h> 2 "i2c-id.h" <linux/i2c-id.h> 2 3 "i2c-dev.h" <linux/i2c-dev.h> 4 "i2c-proc.h" <linux/i2c-proc.h> 3 5 "i2c-algo-bit.h" <linux/i2c-algo-bit.h> 6 "i2c-algo-biths.h" <linux/i2c-algo-biths.h> 4 7 "i2c-algo-pcf.h" <linux/i2c-algo-pcf.h> 5 "i2c-elektor.h" <linux/i2c-elektor.h> 6 "i2c-id.h" <linux/i2c-id.h> 7 "i2c-proc.h" <linux/i2c-proc.h> 8 "i2c-pcf8584.h" <linux/i2c-pcf8584.h> 8 9 "i2c-algo-8xx.h" <linux/i2c-algo-8xx.h> 9 10 "i2c-algo-ibm_ocp.h" <linux/i2c-algo-ibm_ocp.h> -
i2c/trunk/mkpatch/OLDI2C
r3398 r3765 1 drivers/char/bttv.c2 drivers/char/bttv.h3 drivers/char/buz.c4 drivers/char/msp3400.c5 drivers/char/saa5249.c6 drivers/char/saa7111.c7 drivers/char/saa7185.c8 drivers/char/tuner.c9 drivers/char/i2c-parport.c -
i2c/trunk/mkpatch/mkpatch.pl
r3757 r3765 38 38 my ($diff_command,$dummy); 39 39 40 $diff_command = "diff -u2"; 41 if ( -e "$kernel_root/$kernel_file") { 42 $diff_command .= " $kernel_root/$kernel_file "; 43 } else { 44 $diff_command .= " /dev/null "; 45 } 46 if ( -e "$package_root/$package_file") { 47 $diff_command .= " $package_root/$package_file "; 48 } else { 49 $diff_command .= " /dev/null"; 50 } 40 $diff_command = "diff -u"; 41 $diff_command .= " $kernel_root/$kernel_file "; 42 $diff_command .= " $package_root/$package_file "; 51 43 open INPUT, "$diff_command|" or die "Can't call `$diff_command'"; 52 $dummy = <INPUT>; 53 $dummy = <INPUT>; 54 print "--- linux-old/$kernel_file\t".`date`; 55 print "+++ linux/$kernel_file\t".`date`; 56 44 if (<INPUT>) { 45 print "--- linux-old/$kernel_file\t".`date`; 46 } 47 if (<INPUT>) { 48 print "+++ linux/$kernel_file\t".`date`; 49 } 57 50 while (<INPUT>) { 58 51 print; … … 61 54 } 62 55 63 # Find all the lm_sensors code in a file64 # $_[0]: Linux kernel tree (like /usr/src/linux)65 # $_[1]: Name of the kernel file66 # Returns a list of strings with the sensors codes67 sub find_sensors_code68 {69 my ($kernel_root,$kernel_file) = @_;70 my @res;71 open INPUT, "$kernel_root/$kernel_file"72 or return @res;73 while (<INPUT>) {74 if (m@sensors code starts here@) {75 push @res,"";76 while (<INPUT>) {77 last if m@sensors code ends here@;78 $res[$#res] .= $_;79 }80 }81 }82 return @res;83 }84 85 # Here we generate diffs for all kernel files mentioned in OLDI2C86 # which change the invocation # `#include <linux/i2c.h>' to87 # `#include <linux/i2c-old.h>'. But first, we generate diffs to copy88 # file <linux/i2c.h> to <linux/i2c-old.h>, if the kernel does not have89 # this file yet.90 # $_[0]: sensors package root (like /tmp/sensors)91 # $_[1]: Linux kernel tree (like /usr/src/linux)92 sub patch_old_i2c93 {94 my ($package_root,$kernel_root) = @_;95 my (@files,$file,$f);96 # If i2c.c does not exist, either we renamed it earlier, or there is no97 # i2c support in this kernel at all.98 return if not -e "$kernel_root/drivers/char/i2c.c";99 100 print_diff $kernel_root,$kernel_root,"include/linux/i2c-old.h",101 "include/linux/i2c.h";102 103 104 open INPUT, "$package_root/mkpatch/OLDI2C"105 or die "Can't open `$package_root/mkpatch/OLDI2C'";106 @files = <INPUT>;107 close INPUT;108 109 foreach $f (@files,"drivers/char/i2c-old.c") {110 $file = $f; # Ugly, but seemingly needed to run on Perl 5.6.111 chomp $file;112 if ($file eq "drivers/char/i2c-old.c") {113 open INPUT, "$kernel_root/drivers/char/i2c.c"114 or next;115 } else {116 open INPUT, "$kernel_root/$file"117 or next;118 }119 open OUTPUT, ">$package_root/$temp"120 or die "Can't open `$package_root/$temp'";121 while (<INPUT>) {122 s@(\s*#\s*include\s*)<linux/i2c.h>@\1<linux/i2c-old.h>@;123 print OUTPUT;124 }125 close INPUT;126 close OUTPUT;127 print_diff $package_root,$kernel_root,$file,$temp;128 }129 print_diff "/dev",$kernel_root,"drivers/char/i2c.c","null";130 gen_drivers_char_Makefile $package_root, $kernel_root;131 }132 56 133 57 # This generates diffs for kernel file Documentation/Configure.help. This … … 350 274 } 351 275 352 # This generates diffs for the main Linux Makefile.353 # Three lines which add drivers/i2c/i2.a to the DRIVERS list are put just354 # before the place where the architecture Makefile is included.355 # Of course, care is taken old lines are removed.356 # $_[0]: i2c package root (like /tmp/i2c)357 # $_[1]: Linux kernel tree (like /usr/src/linux)358 sub gen_Makefile359 {360 my ($package_root,$kernel_root) = @_;361 my $kernel_file = "Makefile";362 my $package_file = $temp;363 my $printed = 0;364 my $new_style = 0;365 366 open INPUT,"$kernel_root/$kernel_file"367 or die "Can't open `$kernel_root/$kernel_file'";368 open OUTPUT,">$package_root/$package_file"369 or die "Can't open $package_root/$package_file";370 MAIN: while(<INPUT>) {371 if (m@^DRIVERS :=@) {372 $new_style = 1;373 }374 if (m@DRIVERS-\$\(CONFIG_I2C\)@) {375 $_ = <INPUT>;376 redo MAIN;377 } elsif (m@CONFIG_I2C@) {378 $_ = <INPUT> while not m@endif@;379 $_ = <INPUT>;380 $_ = <INPUT> if m@^$@;381 redo MAIN;382 }383 if (not $printed and m@DRIVERS-\$\(CONFIG_PHONE\)@) {384 if ($new_style) {385 print OUTPUT << 'EOF';386 DRIVERS-$(CONFIG_I2C) += drivers/i2c/i2c.a387 EOF388 } else {389 print OUTPUT << 'EOF';390 DRIVERS-$(CONFIG_I2C) += drivers/i2c/i2c.o391 EOF392 }393 $printed = 1;394 } elsif (not $printed and395 (m@include arch/\$\(ARCH\)/Makefile@ or m@CONFIG_SENSORS@ or396 m@CONFIG_PHONE@ )) {397 print OUTPUT <<'EOF';398 ifeq ($(CONFIG_I2C),y)399 DRIVERS := $(DRIVERS) drivers/i2c/i2c.a400 endif401 402 EOF403 $printed = 1;404 }405 print OUTPUT;406 }407 close INPUT;408 close OUTPUT;409 die "Automatic patch generation for main `Makefile' failed.\n".410 "See our home page http://www.lm-sensors.nu for assistance!" if $printed == 0;411 print_diff $package_root,$kernel_root,$kernel_file,$package_file;412 }413 414 276 # This generates diffs for drivers/Makefile 415 # First, `i2c' is added to the ALL_SUB_DIRS list. Next, a couple of lines416 # to add i2c to the SUB_DIRS and/or MOD_SUB_DIRS lists is put right before417 # Rules.make is included.418 # Of course, care is taken old lines are removed.419 277 # $_[0]: i2c package root (like /tmp/i2c) 420 278 # $_[1]: Linux kernel tree (like /usr/src/linux) … … 427 285 my $printed = 0; 428 286 my $added = 0; 429 my $new_style = 0;430 287 431 288 open INPUT,"$kernel_root/$kernel_file" … … 434 291 or die "Can't open $package_root/$package_file"; 435 292 MAIN: while(<INPUT>) { 436 if (m@^mod-subdirs\s*:=@) {437 $new_style = 1;438 }439 if ((! $new_style and m@^ALL_SUB_DIRS\s*:=@) or m@^mod-subdirs\s*:=@ ) {440 $added = 1;441 $i2c_present = 0;442 while (m@\\$@) {443 $i2c_present = 1 if m@i2c@;444 print OUTPUT;445 $_ = <INPUT>;446 }447 $i2c_present = 1 if m@i2c@;448 s@$@ i2c@ if (not $i2c_present);449 print OUTPUT;450 $_ = <INPUT>;451 redo MAIN;452 }453 293 if (m@^ifeq.*CONFIG_I2C@) { 454 294 $_ = <INPUT> while not m@^endif@; … … 461 301 redo MAIN; 462 302 } 463 # 2.5 kernels464 # if (m@^obj.*CONFIG_I2C@) {465 # }466 303 if (not $printed and 467 (m@^include \$\(TOPDIR\)/Rules.make$@ or 468 m@^ifeq \(\$\(CONFIG_ACPI\),y\)$@ or 304 (m@^ifeq \(\$\(CONFIG_ACPI\),y\)$@ or 469 305 m@^ifeq \(\$\(CONFIG_SENSORS\),y\)@) or 470 306 m@^subdir-\$\(CONFIG_ACPI\)@) { 471 if ($new_style) {472 307 print OUTPUT <<'EOF'; 473 308 subdir-$(CONFIG_I2C) += i2c 474 309 EOF 475 } else { 476 print OUTPUT <<'EOF'; 477 ifeq ($(CONFIG_I2C),y) 478 SUB_DIRS += i2c 479 MOD_SUB_DIRS += i2c 480 else 481 ifeq ($(CONFIG_I2C),m) 482 MOD_SUB_DIRS += i2c 483 endif 484 endif 485 486 EOF 487 } 488 $printed = 1; 310 $printed = 1; 489 311 } 490 312 print OUTPUT; … … 497 319 } 498 320 499 # This generates diffs for drivers/char/Makefile500 # It changes all occurences of `i2c.o' to `i2c-old.o'.501 # $_[0]: i2c package root (like /tmp/i2c)502 # $_[1]: Linux kernel tree (like /usr/src/linux)503 sub gen_drivers_char_Makefile504 {505 my ($package_root,$kernel_root) = @_;506 my $kernel_file = "drivers/char/Makefile";507 my $package_file = $temp;508 open INPUT,"$kernel_root/$kernel_file"509 or die "Can't open `$kernel_root/$kernel_file'";510 open OUTPUT,">$package_root/$package_file"511 or die "Can't open $package_root/$package_file";512 while(<INPUT>) {513 s@i2c\.o@i2c-old\.o@;514 print OUTPUT;515 }516 close INPUT;517 close OUTPUT;518 print_diff $package_root,$kernel_root,$kernel_file,$package_file;519 }520 321 521 322 # This generates diffs for drivers/i2c/Makefile 522 # for either 'old style' or 'new style'.523 # Don't bother putting in 'old style' support for new architectures524 # like 8xx, IBM405, or StrongARM since they aren't supported525 # in old kernels anyway.526 323 sub gen_drivers_i2c_Makefile 527 324 { … … 530 327 my $package_file = $temp; 531 328 my $use_new_format = 0; 532 if (-e "$kernel_root/$kernel_file") {533 `grep -q -s 'i2c\.o' "$kernel_root/$kernel_file"`;534 $use_new_format = ! $?;535 }536 329 537 330 open OUTPUT,">$package_root/$package_file" 538 331 or die "Can't open $package_root/$package_file"; 539 if ($use_new_format) { 540 print OUTPUT <<'EOF'; 332 print OUTPUT <<'EOF'; 541 333 # 542 334 # Makefile for the kernel i2c bus driver. … … 565 357 obj-$(CONFIG_I2C_FRODO) += i2c-frodo.o 566 358 567 # This is needed for automatic patch generation: sensors code starts here568 # This is needed for automatic patch generation: sensors code ends here569 570 include $(TOPDIR)/Rules.make571 572 359 EOF 573 } else { 574 print OUTPUT <<'EOF'; 575 # 576 # Makefile for the kernel i2c bus driver. 577 # 578 579 SUB_DIRS := 580 MOD_SUB_DIRS := $(SUB_DIRS) 581 ALL_SUB_DIRS := $(SUB_DIRS) 582 MOD_LIST_NAME := I2C_MODULES 583 584 L_TARGET := i2c.a 585 MX_OBJS := 586 M_OBJS := 587 LX_OBJS := 588 L_OBJS := 589 590 # ----- 591 # i2c core components 592 # ----- 593 594 ifeq ($(CONFIG_I2C),y) 595 LX_OBJS += i2c-core.o 596 else 597 ifeq ($(CONFIG_I2C),m) 598 MX_OBJS += i2c-core.o 599 endif 600 endif 601 602 ifeq ($(CONFIG_I2C_CHARDEV),y) 603 L_OBJS += i2c-dev.o 604 else 605 ifeq ($(CONFIG_I2C_CHARDEV),m) 606 M_OBJS += i2c-dev.o 607 endif 608 endif 609 610 ifeq ($(CONFIG_I2C_PROC),y) 611 LX_OBJS += i2c-proc.o 612 else 613 ifeq ($(CONFIG_I2C_PROC),m) 614 MX_OBJS += i2c-proc.o 615 endif 616 endif 617 618 # ----- 619 # Bit banging adapters... 620 # ----- 621 622 ifeq ($(CONFIG_I2C_ALGOBIT),y) 623 LX_OBJS += i2c-algo-bit.o 624 else 625 ifeq ($(CONFIG_I2C_ALGOBIT),m) 626 MX_OBJS += i2c-algo-bit.o 627 endif 628 endif 629 630 ifeq ($(CONFIG_I2C_PHILIPSPAR),y) 631 L_OBJS += i2c-philips-par.o 632 else 633 ifeq ($(CONFIG_I2C_PHILIPSPAR),m) 634 M_OBJS += i2c-philips-par.o 635 endif 636 endif 637 638 ifeq ($(CONFIG_I2C_ELV),y) 639 L_OBJS += i2c-elv.o 640 else 641 ifeq ($(CONFIG_I2C_ELV),m) 642 M_OBJS += i2c-elv.o 643 endif 644 endif 645 646 ifeq ($(CONFIG_I2C_VELLEMAN),y) 647 L_OBJS += i2c-velleman.o 648 else 649 ifeq ($(CONFIG_I2C_VELLEMAN),m) 650 M_OBJS += i2c-velleman.o 651 endif 652 endif 653 654 655 656 # ----- 657 # PCF components 658 # ----- 659 660 ifeq ($(CONFIG_I2C_ALGOPCF),y) 661 LX_OBJS += i2c-algo-pcf.o 662 else 663 ifeq ($(CONFIG_I2C_ALGOPCF),m) 664 MX_OBJS += i2c-algo-pcf.o 665 endif 666 endif 667 668 ifeq ($(CONFIG_I2C_ELEKTOR),y) 669 L_OBJS += i2c-elektor.o 670 else 671 ifeq ($(CONFIG_I2C_ELEKTOR),m) 672 M_OBJS += i2c-elektor.o 673 endif 674 endif 675 676 # This is needed for automatic patch generation: sensors code starts here 677 # This is needed for automatic patch generation: sensors code ends here 678 679 include $(TOPDIR)/Rules.make 680 681 EOF 682 } 360 683 361 close OUTPUT; 684 362 print_diff $package_root,$kernel_root,$kernel_file,$package_file; 685 363 } 686 364 687 # This generates diffs for drivers/char/Config.in688 # It adds a line just before CONFIG_APM or main_menu_option lines to include689 # the I2C Config.in.690 # Of course, care is taken old lines are removed.691 # $_[0]: i2c package root (like /tmp/i2c)692 # $_[1]: Linux kernel tree (like /usr/src/linux)693 sub gen_drivers_char_Config_in694 {695 my ($package_root,$kernel_root) = @_;696 my $kernel_file = "drivers/char/Config.in";697 my $package_file = $temp;698 my $ready = 0;699 my $printed = 0;700 701 open INPUT,"$kernel_root/$kernel_file"702 or die "Can't open `$kernel_root/$kernel_file'";703 open OUTPUT,">$package_root/$package_file"704 or die "Can't open $package_root/$package_file";705 MAIN: while(<INPUT>) {706 if (m@i2c@) {707 $_ = <INPUT>;708 $_ = <INPUT> if (m@^$@);709 redo MAIN;710 }711 if ($ready and not $printed and712 (m@^mainmenu_option@ or m@CONFIG_APM@ or m@CONFIG_ALPHA_BOOK1@ or713 m@source drivers/sensors/Config.in@)) {714 $printed = 1;715 print OUTPUT <<'EOF';716 source drivers/i2c/Config.in717 718 EOF719 }720 $ready = 1 if (m@^mainmenu_option@);721 print OUTPUT;722 }723 close INPUT;724 close OUTPUT;725 die "Automatic patch generation for `drivers/char/Config.in' failed.\n".726 "See our home page http://www.lm-sensors.nu for assistance!" if $printed == 0;727 print_diff $package_root,$kernel_root,$kernel_file,$package_file;728 }729 730 731 # This generates diffs for drivers/char/mem.c They are a bit intricate.732 # Lines are generated at the beginning to declare i2c_init and i2c_init_all.733 # The first is the invocation for the old I2C driver, the second for the734 # new driver. At the bottom, a call to i2c_init_all is added when the735 # new I2C stuff is configured in.736 # Of course, care is taken old lines are removed.737 # $_[0]: i2c package root (like /tmp/i2c)738 # $_[1]: Linux kernel tree (like /usr/src/linux)739 sub gen_drivers_char_mem_c740 {741 my ($package_root,$kernel_root) = @_;742 my $kernel_file = "drivers/char/mem.c";743 my $package_file = $temp;744 my $right_place = 0;745 my $done = 0;746 my $atstart = 1;747 my $pr1 = 0;748 my $pr2 = 0;749 750 open INPUT,"$kernel_root/$kernel_file"751 or die "Can't open `$kernel_root/$kernel_file'";752 open OUTPUT,">$package_root/$package_file"753 or die "Can't open $package_root/$package_file";754 MAIN: while(<INPUT>) {755 if (m@#include <linux/i2c.h>@) {756 $_=<INPUT>;757 redo MAIN;758 }759 if ($atstart and m@#ifdef@) {760 print OUTPUT << 'EOF';761 #ifdef CONFIG_I2C762 extern int i2c_init_all(void);763 #endif764 EOF765 $atstart = 0;766 $pr1 = 1;767 }768 while (not $right_place and (m@CONFIG_I2C@ or m@CONFIG_VIDEO_BT848@)) {769 $_ = <INPUT> while not m@#endif@;770 $_ = <INPUT>;771 redo MAIN;772 }773 $right_place = 1 if (m@chr_dev_init@);774 if ($right_place and m@CONFIG_I2C@) {775 $_ = <INPUT> while not m@#endif@;776 $_ = <INPUT>;777 $_ = <INPUT> if m@^$@;778 redo MAIN;779 }780 if ($right_place and not $done and781 (m@CONFIG_VIDEO_BT848@ or m@return 0;@ or m@CONFIG_SENSORS@ or782 m@CONFIG_FB@)) {783 print OUTPUT <<'EOF';784 #ifdef CONFIG_I2C785 i2c_init_all();786 #endif787 EOF788 $done = 1;789 $pr2 = 1;790 }791 print OUTPUT;792 }793 close INPUT;794 close OUTPUT;795 die "Automatic patch generation for `drivers/char/mem.c' failed.\n".796 "See our home page http://www.lm-sensors.nu for assistance!" if $pr1 == 0 or $pr2 == 0;797 print_diff $package_root,$kernel_root,$kernel_file,$package_file;798 }799 365 800 366 # Generate the diffs for the list of MAINTAINERS … … 852 418 unless -d "$package_root/mkpatch"; 853 419 $kernel_root = $ARGV[1]; 854 # die "Kernel root `$kernel_root' is not found\n"855 # unless -f "$kernel_root/Rules.make";856 857 patch_old_i2c $package_root, $kernel_root;858 859 420 860 421 # --> Read FILES … … 880 441 foreach $package_file (sort keys %files) { 881 442 $kernel_file = $files{$package_file}; 882 @sensors_subs = find_sensors_code "$kernel_root","$kernel_file";883 443 open INPUT, "$package_root/$package_file" 884 444 or die "Can't open `$package_root/$package_file'"; … … 887 447 while (<INPUT>) { 888 448 eval $sedscript; 889 if (m@sensors code starts here@) {890 print OUTPUT;891 while (<INPUT>) {892 last if m@sensors code ends here@;893 }894 print OUTPUT $sensors_subs[0];895 shift @sensors_subs896 }897 449 print OUTPUT; 898 450 } … … 902 454 } 903 455 904 gen_Makefile $package_root, $kernel_root; 905 gen_drivers_Makefile $package_root, $kernel_root; 906 gen_drivers_i2c_Makefile $package_root, $kernel_root; 907 gen_drivers_char_Config_in $package_root, $kernel_root; 908 gen_drivers_char_mem_c $package_root, $kernel_root; 909 gen_Documentation_Configure_help $package_root, $kernel_root; 910 gen_MAINTAINERS $package_root, $kernel_root; 456 # gen_Makefile $package_root, $kernel_root; 457 # gen_drivers_Makefile $package_root, $kernel_root; 458 # gen_drivers_i2c_Makefile $package_root, $kernel_root; 459 # gen_Documentation_Configure_help $package_root, $kernel_root; 911 460 } 912 461
