Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge master.kernel.org:/pub/scm/linux/kernel/git/gregkh/i2c-2.6

* master.kernel.org:/pub/scm/linux/kernel/git/gregkh/i2c-2.6: (30 commits)
i2c: Drop unimplemented slave functions
i2c: Constify i2c_algorithm declarations, part 2
i2c: Constify i2c_algorithm declarations, part 1
i2c: Let drivers constify i2c_algorithm data
i2c-isa: Restore driver owner
i2c-viapro: Add support for the VT8237A and VT8251
i2c: Warn on i2c client creation failure
i2c-core: Drop useless bitmaskings
i2c-algo-pcf: Discard the mdelay data struct member
i2c-algo-bit: Cleanups
i2c-isa: Fail adding driver on attach_adapter error
i2c: __must_check fixes (chip drivers)
i2c-dev: attach/detach_adapter cleanups
i2c-stub: Chip address as a module parameter
i2c: Plan i2c-isa for removal
i2c: New bus driver for TI OMAP boards
i2c-algo-bit: Discard the mdelay data struct member
i2c-matroxfb: Struct init conversion
i2c: Fix copy-n-paste in subsystem Kconfig
i2c-au1550: Add I2C support for Au1200
...

+1221 -484
+9
Documentation/feature-removal-schedule.txt
··· 313 313 Who: Kay Sievers <kay.sievers@suse.de> 314 314 315 315 --------------------------- 316 + 317 + What: i2c-isa 318 + When: December 2006 319 + Why: i2c-isa is a non-sense and doesn't fit in the device driver 320 + model. Drivers relying on it are better implemented as platform 321 + drivers. 322 + Who: Jean Delvare <khali@linux-fr.org> 323 + 324 + ---------------------------
+6 -1
Documentation/i2c/busses/i2c-viapro
··· 7 7 * VIA Technologies, Inc. VT82C686A/B 8 8 Datasheet: Sometimes available at the VIA website 9 9 10 - * VIA Technologies, Inc. VT8231, VT8233, VT8233A, VT8235, VT8237R 10 + * VIA Technologies, Inc. VT8231, VT8233, VT8233A 11 11 Datasheet: available on request from VIA 12 + 13 + * VIA Technologies, Inc. VT8235, VT8237R, VT8237A, VT8251 14 + Datasheet: available on request and under NDA from VIA 12 15 13 16 Authors: 14 17 Ky�sti M�lkki <kmalkki@cc.hut.fi>, ··· 42 39 device 1106:8235 (VT8231 function 4) 43 40 device 1106:3177 (VT8235) 44 41 device 1106:3227 (VT8237R) 42 + device 1106:3337 (VT8237A) 43 + device 1106:3287 (VT8251) 45 44 46 45 If none of these show up, you should look in the BIOS for settings like 47 46 enable ACPI / SMBus or even USB.
+13 -2
Documentation/i2c/i2c-stub
··· 6 6 types of SMBus commands: write quick, (r/w) byte, (r/w) byte data, and 7 7 (r/w) word data. 8 8 9 + You need to provide a chip address as a module parameter when loading 10 + this driver, which will then only react to SMBus commands to this address. 11 + 9 12 No hardware is needed nor associated with this module. It will accept write 10 - quick commands to all addresses; it will respond to the other commands (also 11 - to all addresses) by reading from or writing to an array in memory. It will 13 + quick commands to one address; it will respond to the other commands (also 14 + to one address) by reading from or writing to an array in memory. It will 12 15 also spam the kernel logs for every command it handles. 13 16 14 17 A pointer register with auto-increment is implemented for all byte ··· 24 21 3. load the target sensors chip driver module 25 22 4. observe its behavior in the kernel log 26 23 24 + PARAMETERS: 25 + 26 + int chip_addr: 27 + The SMBus address to emulate a chip at. 28 + 27 29 CAVEATS: 28 30 29 31 There are independent arrays for byte/data and word/data commands. Depending ··· 40 32 If the hardware for your driver has banked registers (e.g. Winbond sensors 41 33 chips) this module will not work well - although it could be extended to 42 34 support that pretty easily. 35 + 36 + Only one chip address is supported - although this module could be 37 + extended to support more. 43 38 44 39 If you spam it hard enough, printk can be lossy. This module really wants 45 40 something like relayfs.
-1
drivers/acorn/char/i2c.c
··· 308 308 .getsda = ioc_getsda, 309 309 .getscl = ioc_getscl, 310 310 .udelay = 80, 311 - .mdelay = 80, 312 311 .timeout = 100 313 312 }; 314 313
+1 -1
drivers/acpi/i2c_ec.c
··· 293 293 I2C_FUNC_SMBUS_I2C_BLOCK | I2C_FUNC_SMBUS_HWPEC_CALC); 294 294 } 295 295 296 - static struct i2c_algorithm acpi_ec_smbus_algorithm = { 296 + static const struct i2c_algorithm acpi_ec_smbus_algorithm = { 297 297 .smbus_xfer = acpi_ec_smb_access, 298 298 .functionality = acpi_ec_smb_func, 299 299 };
+1
drivers/hwmon/it87.c
··· 243 243 244 244 static struct i2c_driver it87_isa_driver = { 245 245 .driver = { 246 + .owner = THIS_MODULE, 246 247 .name = "it87-isa", 247 248 }, 248 249 .attach_adapter = it87_isa_attach_adapter,
+1
drivers/hwmon/lm78.c
··· 175 175 176 176 static struct i2c_driver lm78_isa_driver = { 177 177 .driver = { 178 + .owner = THIS_MODULE, 178 179 .name = "lm78-isa", 179 180 }, 180 181 .attach_adapter = lm78_isa_attach_adapter,
+1
drivers/hwmon/pc87360.c
··· 238 238 239 239 static struct i2c_driver pc87360_driver = { 240 240 .driver = { 241 + .owner = THIS_MODULE, 241 242 .name = "pc87360", 242 243 }, 243 244 .attach_adapter = pc87360_detect,
+1
drivers/hwmon/sis5595.c
··· 200 200 201 201 static struct i2c_driver sis5595_driver = { 202 202 .driver = { 203 + .owner = THIS_MODULE, 203 204 .name = "sis5595", 204 205 }, 205 206 .attach_adapter = sis5595_detect,
+1
drivers/hwmon/smsc47b397.c
··· 228 228 229 229 static struct i2c_driver smsc47b397_driver = { 230 230 .driver = { 231 + .owner = THIS_MODULE, 231 232 .name = "smsc47b397", 232 233 }, 233 234 .attach_adapter = smsc47b397_detect,
+1
drivers/hwmon/smsc47m1.c
··· 128 128 129 129 static struct i2c_driver smsc47m1_driver = { 130 130 .driver = { 131 + .owner = THIS_MODULE, 131 132 .name = "smsc47m1", 132 133 }, 133 134 .attach_adapter = smsc47m1_detect,
+1
drivers/hwmon/via686a.c
··· 574 574 smbus_driver and isa_driver, and clients could be of either kind */ 575 575 static struct i2c_driver via686a_driver = { 576 576 .driver = { 577 + .owner = THIS_MODULE, 577 578 .name = "via686a", 578 579 }, 579 580 .attach_adapter = via686a_detect,
+1
drivers/hwmon/vt8231.c
··· 587 587 588 588 static struct i2c_driver vt8231_driver = { 589 589 .driver = { 590 + .owner = THIS_MODULE, 590 591 .name = "vt8231", 591 592 }, 592 593 .attach_adapter = vt8231_detect,
+1
drivers/hwmon/w83627ehf.c
··· 903 903 904 904 static struct i2c_driver w83627ehf_driver = { 905 905 .driver = { 906 + .owner = THIS_MODULE, 906 907 .name = "w83627ehf", 907 908 }, 908 909 .attach_adapter = w83627ehf_detect,
+1
drivers/hwmon/w83627hf.c
··· 339 339 340 340 static struct i2c_driver w83627hf_driver = { 341 341 .driver = { 342 + .owner = THIS_MODULE, 342 343 .name = "w83627hf", 343 344 }, 344 345 .attach_adapter = w83627hf_detect,
+1
drivers/hwmon/w83781d.c
··· 288 288 289 289 static struct i2c_driver w83781d_isa_driver = { 290 290 .driver = { 291 + .owner = THIS_MODULE, 291 292 .name = "w83781d-isa", 292 293 }, 293 294 .attach_adapter = w83781d_isa_attach_adapter,
+1 -1
drivers/i2c/Kconfig
··· 1 1 # 2 - # Character device configuration 2 + # I2C subsystem configuration 3 3 # 4 4 5 5 menu "I2C support"
-6
drivers/i2c/algos/Kconfig
··· 53 53 tristate "MPC8xx CPM I2C interface" 54 54 depends on 8xx && I2C 55 55 56 - config I2C_ALGO_SIBYTE 57 - tristate "SiByte SMBus interface" 58 - depends on SIBYTE_SB1xxx_SOC && I2C 59 - help 60 - Supports the SiByte SOC on-chip I2C interfaces (2 channels). 61 - 62 56 config I2C_ALGO_SGI 63 57 tristate "I2C SGI interfaces" 64 58 depends on I2C && (SGI_IP22 || SGI_IP32 || X86_VISWS)
-1
drivers/i2c/algos/Makefile
··· 6 6 obj-$(CONFIG_I2C_ALGOPCF) += i2c-algo-pcf.o 7 7 obj-$(CONFIG_I2C_ALGOPCA) += i2c-algo-pca.o 8 8 obj-$(CONFIG_I2C_ALGOITE) += i2c-algo-ite.o 9 - obj-$(CONFIG_I2C_ALGO_SIBYTE) += i2c-algo-sibyte.o 10 9 obj-$(CONFIG_I2C_ALGO_SGI) += i2c-algo-sgi.o 11 10 12 11 ifeq ($(CONFIG_I2C_DEBUG_ALGO),y)
+9 -14
drivers/i2c/algos/i2c-algo-bit.c
··· 76 76 * Raise scl line, and do checking for delays. This is necessary for slower 77 77 * devices. 78 78 */ 79 - static inline int sclhi(struct i2c_algo_bit_data *adap) 79 + static int sclhi(struct i2c_algo_bit_data *adap) 80 80 { 81 81 unsigned long start; 82 82 83 83 setscl(adap,1); 84 84 85 85 /* Not all adapters have scl sense line... */ 86 - if (adap->getscl == NULL ) { 87 - udelay(adap->udelay); 88 - return 0; 89 - } 86 + if (!adap->getscl) 87 + goto done; 90 88 91 89 start=jiffies; 92 90 while (! getscl(adap) ) { ··· 99 101 cond_resched(); 100 102 } 101 103 DEBSTAT(printk(KERN_DEBUG "needed %ld jiffies\n", jiffies-start)); 104 + 105 + done: 102 106 udelay(adap->udelay); 103 107 return 0; 104 108 } ··· 121 121 DEBPROTO(printk(" Sr ")); 122 122 setsda(adap,1); 123 123 sclhi(adap); 124 - udelay(adap->udelay); 125 124 126 125 sdalo(adap); 127 126 scllo(adap); ··· 305 306 * 0 chip did not answer 306 307 * -x transmission error 307 308 */ 308 - static inline int try_address(struct i2c_adapter *i2c_adap, 309 + static int try_address(struct i2c_adapter *i2c_adap, 309 310 unsigned char addr, int retries) 310 311 { 311 312 struct i2c_algo_bit_data *adap = i2c_adap->algo_data; ··· 353 354 return (retval<0)? retval : -EFAULT; 354 355 /* got a better one ?? */ 355 356 } 356 - #if 0 357 - /* from asm/delay.h */ 358 - __delay(adap->mdelay * (loops_per_sec / 1000) ); 359 - #endif 360 357 } 361 358 return wrcount; 362 359 } 363 360 364 - static inline int readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) 361 + static int readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) 365 362 { 366 363 int inval; 367 364 int rdcount=0; /* counts bytes read */ ··· 407 412 * -x an error occurred (like: -EREMOTEIO if the device did not answer, or 408 413 * -ETIMEDOUT, for example if the lines are stuck...) 409 414 */ 410 - static inline int bit_doAddress(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) 415 + static int bit_doAddress(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) 411 416 { 412 417 unsigned short flags = msg->flags; 413 418 unsigned short nak_ok = msg->flags & I2C_M_IGNORE_NAK; ··· 512 517 513 518 /* -----exported algorithm data: ------------------------------------- */ 514 519 515 - static struct i2c_algorithm i2c_bit_algo = { 520 + static const struct i2c_algorithm i2c_bit_algo = { 516 521 .master_xfer = bit_xfer, 517 522 .functionality = bit_func, 518 523 };
+1 -1
drivers/i2c/algos/i2c-algo-pca.c
··· 355 355 return 0; 356 356 } 357 357 358 - static struct i2c_algorithm pca_algo = { 358 + static const struct i2c_algorithm pca_algo = { 359 359 .master_xfer = pca_xfer, 360 360 .functionality = pca_func, 361 361 };
+1 -1
drivers/i2c/algos/i2c-algo-pcf.c
··· 458 458 459 459 /* -----exported algorithm data: ------------------------------------- */ 460 460 461 - static struct i2c_algorithm pcf_algo = { 461 + static const struct i2c_algorithm pcf_algo = { 462 462 .master_xfer = pcf_xfer, 463 463 .functionality = pcf_func, 464 464 };
+1 -1
drivers/i2c/algos/i2c-algo-sgi.c
··· 157 157 return I2C_FUNC_SMBUS_EMUL; 158 158 } 159 159 160 - static struct i2c_algorithm sgi_algo = { 160 + static const struct i2c_algorithm sgi_algo = { 161 161 .master_xfer = sgi_xfer, 162 162 .functionality = sgi_func, 163 163 };
-215
drivers/i2c/algos/i2c-algo-sibyte.c
··· 1 - /* ------------------------------------------------------------------------- */ 2 - /* i2c-algo-sibyte.c i2c driver algorithms for bit-shift adapters */ 3 - /* ------------------------------------------------------------------------- */ 4 - /* Copyright (C) 2001,2002,2003 Broadcom Corporation 5 - Copyright (C) 1995-2000 Simon G. Vogl 6 - 7 - This program is free software; you can redistribute it and/or modify 8 - it under the terms of the GNU General Public License as published by 9 - the Free Software Foundation; either version 2 of the License, or 10 - (at your option) any later version. 11 - 12 - This program is distributed in the hope that it will be useful, 13 - but WITHOUT ANY WARRANTY; without even the implied warranty of 14 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 - GNU General Public License for more details. 16 - 17 - You should have received a copy of the GNU General Public License 18 - along with this program; if not, write to the Free Software 19 - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ 20 - /* ------------------------------------------------------------------------- */ 21 - 22 - /* With some changes from Ky�sti M�lkki <kmalkki@cc.hut.fi> and even 23 - Frodo Looijaard <frodol@dds.nl>. */ 24 - 25 - /* Ported for SiByte SOCs by Broadcom Corporation. */ 26 - 27 - #include <linux/kernel.h> 28 - #include <linux/module.h> 29 - #include <linux/init.h> 30 - 31 - #include <asm/io.h> 32 - #include <asm/sibyte/sb1250_regs.h> 33 - #include <asm/sibyte/sb1250_smbus.h> 34 - 35 - #include <linux/i2c.h> 36 - #include <linux/i2c-algo-sibyte.h> 37 - 38 - /* ----- global defines ----------------------------------------------- */ 39 - #define SMB_CSR(a,r) ((long)(a->reg_base + r)) 40 - 41 - /* ----- global variables --------------------------------------------- */ 42 - 43 - /* module parameters: 44 - */ 45 - static int bit_scan; /* have a look at what's hanging 'round */ 46 - 47 - 48 - static int smbus_xfer(struct i2c_adapter *i2c_adap, u16 addr, 49 - unsigned short flags, char read_write, 50 - u8 command, int size, union i2c_smbus_data * data) 51 - { 52 - struct i2c_algo_sibyte_data *adap = i2c_adap->algo_data; 53 - int data_bytes = 0; 54 - int error; 55 - 56 - while (csr_in32(SMB_CSR(adap, R_SMB_STATUS)) & M_SMB_BUSY) 57 - ; 58 - 59 - switch (size) { 60 - case I2C_SMBUS_QUICK: 61 - csr_out32((V_SMB_ADDR(addr) | (read_write == I2C_SMBUS_READ ? M_SMB_QDATA : 0) | 62 - V_SMB_TT_QUICKCMD), SMB_CSR(adap, R_SMB_START)); 63 - break; 64 - case I2C_SMBUS_BYTE: 65 - if (read_write == I2C_SMBUS_READ) { 66 - csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_RD1BYTE), 67 - SMB_CSR(adap, R_SMB_START)); 68 - data_bytes = 1; 69 - } else { 70 - csr_out32(V_SMB_CMD(command), SMB_CSR(adap, R_SMB_CMD)); 71 - csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_WR1BYTE), 72 - SMB_CSR(adap, R_SMB_START)); 73 - } 74 - break; 75 - case I2C_SMBUS_BYTE_DATA: 76 - csr_out32(V_SMB_CMD(command), SMB_CSR(adap, R_SMB_CMD)); 77 - if (read_write == I2C_SMBUS_READ) { 78 - csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_CMD_RD1BYTE), 79 - SMB_CSR(adap, R_SMB_START)); 80 - data_bytes = 1; 81 - } else { 82 - csr_out32(V_SMB_LB(data->byte), SMB_CSR(adap, R_SMB_DATA)); 83 - csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_WR2BYTE), 84 - SMB_CSR(adap, R_SMB_START)); 85 - } 86 - break; 87 - case I2C_SMBUS_WORD_DATA: 88 - csr_out32(V_SMB_CMD(command), SMB_CSR(adap, R_SMB_CMD)); 89 - if (read_write == I2C_SMBUS_READ) { 90 - csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_CMD_RD2BYTE), 91 - SMB_CSR(adap, R_SMB_START)); 92 - data_bytes = 2; 93 - } else { 94 - csr_out32(V_SMB_LB(data->word & 0xff), SMB_CSR(adap, R_SMB_DATA)); 95 - csr_out32(V_SMB_MB(data->word >> 8), SMB_CSR(adap, R_SMB_DATA)); 96 - csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_WR2BYTE), 97 - SMB_CSR(adap, R_SMB_START)); 98 - } 99 - break; 100 - default: 101 - return -1; /* XXXKW better error code? */ 102 - } 103 - 104 - while (csr_in32(SMB_CSR(adap, R_SMB_STATUS)) & M_SMB_BUSY) 105 - ; 106 - 107 - error = csr_in32(SMB_CSR(adap, R_SMB_STATUS)); 108 - if (error & M_SMB_ERROR) { 109 - /* Clear error bit by writing a 1 */ 110 - csr_out32(M_SMB_ERROR, SMB_CSR(adap, R_SMB_STATUS)); 111 - return -1; /* XXXKW better error code? */ 112 - } 113 - 114 - if (data_bytes == 1) 115 - data->byte = csr_in32(SMB_CSR(adap, R_SMB_DATA)) & 0xff; 116 - if (data_bytes == 2) 117 - data->word = csr_in32(SMB_CSR(adap, R_SMB_DATA)) & 0xffff; 118 - 119 - return 0; 120 - } 121 - 122 - static int algo_control(struct i2c_adapter *adapter, 123 - unsigned int cmd, unsigned long arg) 124 - { 125 - return 0; 126 - } 127 - 128 - static u32 bit_func(struct i2c_adapter *adap) 129 - { 130 - return (I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | 131 - I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA); 132 - } 133 - 134 - 135 - /* -----exported algorithm data: ------------------------------------- */ 136 - 137 - static struct i2c_algorithm i2c_sibyte_algo = { 138 - .smbus_xfer = smbus_xfer, 139 - .algo_control = algo_control, /* ioctl */ 140 - .functionality = bit_func, 141 - }; 142 - 143 - /* 144 - * registering functions to load algorithms at runtime 145 - */ 146 - int i2c_sibyte_add_bus(struct i2c_adapter *i2c_adap, int speed) 147 - { 148 - int i; 149 - struct i2c_algo_sibyte_data *adap = i2c_adap->algo_data; 150 - 151 - /* register new adapter to i2c module... */ 152 - i2c_adap->algo = &i2c_sibyte_algo; 153 - 154 - /* Set the frequency to 100 kHz */ 155 - csr_out32(speed, SMB_CSR(adap,R_SMB_FREQ)); 156 - csr_out32(0, SMB_CSR(adap,R_SMB_CONTROL)); 157 - 158 - /* scan bus */ 159 - if (bit_scan) { 160 - union i2c_smbus_data data; 161 - int rc; 162 - printk(KERN_INFO " i2c-algo-sibyte.o: scanning bus %s.\n", 163 - i2c_adap->name); 164 - for (i = 0x00; i < 0x7f; i++) { 165 - /* XXXKW is this a realistic probe? */ 166 - rc = smbus_xfer(i2c_adap, i, 0, I2C_SMBUS_READ, 0, 167 - I2C_SMBUS_BYTE_DATA, &data); 168 - if (!rc) { 169 - printk("(%02x)",i); 170 - } else 171 - printk("."); 172 - } 173 - printk("\n"); 174 - } 175 - 176 - return i2c_add_adapter(i2c_adap); 177 - } 178 - 179 - 180 - int i2c_sibyte_del_bus(struct i2c_adapter *adap) 181 - { 182 - int res; 183 - 184 - if ((res = i2c_del_adapter(adap)) < 0) 185 - return res; 186 - 187 - return 0; 188 - } 189 - 190 - int __init i2c_algo_sibyte_init (void) 191 - { 192 - printk("i2c-algo-sibyte.o: i2c SiByte algorithm module\n"); 193 - return 0; 194 - } 195 - 196 - 197 - EXPORT_SYMBOL(i2c_sibyte_add_bus); 198 - EXPORT_SYMBOL(i2c_sibyte_del_bus); 199 - 200 - #ifdef MODULE 201 - MODULE_AUTHOR("Kip Walker, Broadcom Corp."); 202 - MODULE_DESCRIPTION("SiByte I2C-Bus algorithm"); 203 - module_param(bit_scan, int, 0); 204 - MODULE_PARM_DESC(bit_scan, "Scan for active chips on the bus"); 205 - MODULE_LICENSE("GPL"); 206 - 207 - int init_module(void) 208 - { 209 - return i2c_algo_sibyte_init(); 210 - } 211 - 212 - void cleanup_module(void) 213 - { 214 - } 215 - #endif
+22 -12
drivers/i2c/busses/Kconfig
··· 75 75 will be called i2c-amd8111. 76 76 77 77 config I2C_AU1550 78 - tristate "Au1550 SMBus interface" 79 - depends on I2C && SOC_AU1550 78 + tristate "Au1550/Au1200 SMBus interface" 79 + depends on I2C && (SOC_AU1550 || SOC_AU1200) 80 80 help 81 81 If you say yes to this option, support will be included for the 82 - Au1550 SMBus interface. 82 + Au1550 and Au1200 SMBus interface. 83 83 84 84 This driver can also be built as a module. If so, the module 85 85 will be called i2c-au1550. ··· 287 287 This driver can also be built as a module. If so, the module 288 288 will be called i2c-ocores. 289 289 290 + config I2C_OMAP 291 + tristate "OMAP I2C adapter" 292 + depends on I2C && ARCH_OMAP 293 + default y if MACH_OMAP_H3 || MACH_OMAP_OSK 294 + help 295 + If you say yes to this option, support will be included for the 296 + I2C interface on the Texas Instruments OMAP1/2 family of processors. 297 + Like OMAP1510/1610/1710/5912 and OMAP242x. 298 + For details see http://www.ti.com/omap. 299 + 290 300 config I2C_PARPORT 291 301 tristate "Parallel port adapter" 292 302 depends on I2C && PARPORT ··· 492 482 will be called i2c-via. 493 483 494 484 config I2C_VIAPRO 495 - tristate "VIA 82C596/82C686/823x" 485 + tristate "VIA 82C596/82C686/82xx" 496 486 depends on I2C && PCI 497 487 help 498 488 If you say yes to this option, support will be included for the VIA 499 - 82C596/82C686/823x I2C interfaces. Specifically, the following 489 + 82C596/82C686/82xx I2C interfaces. Specifically, the following 500 490 chipsets are supported: 501 - 82C596A/B 502 - 82C686A/B 503 - 8231 504 - 8233 505 - 8233A 506 - 8235 507 - 8237 491 + VT82C596A/B 492 + VT82C686A/B 493 + VT8231 494 + VT8233/A 495 + VT8235 496 + VT8237R/A 497 + VT8251 508 498 509 499 This driver can also be built as a module. If so, the module 510 500 will be called i2c-viapro.
+1
drivers/i2c/busses/Makefile
··· 24 24 obj-$(CONFIG_I2C_MV64XXX) += i2c-mv64xxx.o 25 25 obj-$(CONFIG_I2C_NFORCE2) += i2c-nforce2.o 26 26 obj-$(CONFIG_I2C_OCORES) += i2c-ocores.o 27 + obj-$(CONFIG_I2C_OMAP) += i2c-omap.o 27 28 obj-$(CONFIG_I2C_PARPORT) += i2c-parport.o 28 29 obj-$(CONFIG_I2C_PARPORT_LIGHT) += i2c-parport-light.o 29 30 obj-$(CONFIG_I2C_PCA_ISA) += i2c-pca-isa.o
+1 -1
drivers/i2c/busses/i2c-ali1535.c
··· 468 468 I2C_FUNC_SMBUS_BLOCK_DATA; 469 469 } 470 470 471 - static struct i2c_algorithm smbus_algorithm = { 471 + static const struct i2c_algorithm smbus_algorithm = { 472 472 .smbus_xfer = ali1535_access, 473 473 .functionality = ali1535_func, 474 474 };
+1 -1
drivers/i2c/busses/i2c-ali1563.c
··· 367 367 release_region(ali1563_smba,ALI1563_SMB_IOSIZE); 368 368 } 369 369 370 - static struct i2c_algorithm ali1563_algorithm = { 370 + static const struct i2c_algorithm ali1563_algorithm = { 371 371 .smbus_xfer = ali1563_access, 372 372 .functionality = ali1563_func, 373 373 };
+1 -1
drivers/i2c/busses/i2c-ali15x3.c
··· 463 463 I2C_FUNC_SMBUS_BLOCK_DATA; 464 464 } 465 465 466 - static struct i2c_algorithm smbus_algorithm = { 466 + static const struct i2c_algorithm smbus_algorithm = { 467 467 .smbus_xfer = ali15x3_access, 468 468 .functionality = ali15x3_func, 469 469 };
+1 -1
drivers/i2c/busses/i2c-amd756.c
··· 294 294 I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_PROC_CALL; 295 295 } 296 296 297 - static struct i2c_algorithm smbus_algorithm = { 297 + static const struct i2c_algorithm smbus_algorithm = { 298 298 .smbus_xfer = amd756_access, 299 299 .functionality = amd756_func, 300 300 };
+1 -1
drivers/i2c/busses/i2c-amd8111.c
··· 316 316 I2C_FUNC_SMBUS_I2C_BLOCK | I2C_FUNC_SMBUS_HWPEC_CALC; 317 317 } 318 318 319 - static struct i2c_algorithm smbus_algorithm = { 319 + static const struct i2c_algorithm smbus_algorithm = { 320 320 .smbus_xfer = amd8111_access, 321 321 .functionality = amd8111_func, 322 322 };
+13 -8
drivers/i2c/busses/i2c-au1550.c
··· 34 34 #include <linux/errno.h> 35 35 #include <linux/i2c.h> 36 36 37 - #include <asm/mach-au1x00/au1000.h> 38 - #include <asm/mach-pb1x00/pb1550.h> 37 + #include <asm/mach-au1x00/au1xxx.h> 39 38 #include <asm/mach-au1x00/au1xxx_psc.h> 40 39 41 40 #include "i2c-au1550.h" ··· 117 118 118 119 /* Reset the FIFOs, clear events. 119 120 */ 120 - sp->psc_smbpcr = PSC_SMBPCR_DC; 121 + stat = sp->psc_smbstat; 121 122 sp->psc_smbevnt = PSC_SMBEVNT_ALLCLR; 122 123 au_sync(); 123 - do { 124 - stat = sp->psc_smbpcr; 124 + 125 + if (!(stat & PSC_SMBSTAT_TE) || !(stat & PSC_SMBSTAT_RE)) { 126 + sp->psc_smbpcr = PSC_SMBPCR_DC; 125 127 au_sync(); 126 - } while ((stat & PSC_SMBPCR_DC) != 0); 128 + do { 129 + stat = sp->psc_smbpcr; 130 + au_sync(); 131 + } while ((stat & PSC_SMBPCR_DC) != 0); 132 + udelay(50); 133 + } 127 134 128 135 /* Write out the i2c chip address and specify operation 129 136 */ ··· 284 279 static u32 285 280 au1550_func(struct i2c_adapter *adap) 286 281 { 287 - return I2C_FUNC_I2C; 282 + return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; 288 283 } 289 284 290 - static struct i2c_algorithm au1550_algo = { 285 + static const struct i2c_algorithm au1550_algo = { 291 286 .master_xfer = au1550_xfer, 292 287 .functionality = au1550_func, 293 288 };
-1
drivers/i2c/busses/i2c-elektor.c
··· 196 196 .getclock = pcf_isa_getclock, 197 197 .waitforpin = pcf_isa_waitforpin, 198 198 .udelay = 10, 199 - .mdelay = 10, 200 199 .timeout = 100, 201 200 }; 202 201
-1
drivers/i2c/busses/i2c-hydra.c
··· 99 99 .getsda = hydra_bit_getsda, 100 100 .getscl = hydra_bit_getscl, 101 101 .udelay = 5, 102 - .mdelay = 5, 103 102 .timeout = HZ 104 103 }; 105 104
+1 -1
drivers/i2c/busses/i2c-i801.c
··· 434 434 | (isich4 ? I2C_FUNC_SMBUS_HWPEC_CALC : 0); 435 435 } 436 436 437 - static struct i2c_algorithm smbus_algorithm = { 437 + static const struct i2c_algorithm smbus_algorithm = { 438 438 .smbus_xfer = i801_access, 439 439 .functionality = i801_func, 440 440 };
-2
drivers/i2c/busses/i2c-i810.c
··· 166 166 .getsda = bit_i810i2c_getsda, 167 167 .getscl = bit_i810i2c_getscl, 168 168 .udelay = CYCLE_DELAY, 169 - .mdelay = CYCLE_DELAY, 170 169 .timeout = TIMEOUT, 171 170 }; 172 171 ··· 181 182 .getsda = bit_i810ddc_getsda, 182 183 .getscl = bit_i810ddc_getscl, 183 184 .udelay = CYCLE_DELAY, 184 - .mdelay = CYCLE_DELAY, 185 185 .timeout = TIMEOUT, 186 186 }; 187 187
+1 -1
drivers/i2c/busses/i2c-ibm_iic.c
··· 625 625 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR; 626 626 } 627 627 628 - static struct i2c_algorithm iic_algo = { 628 + static const struct i2c_algorithm iic_algo = { 629 629 .master_xfer = iic_xfer, 630 630 .functionality = iic_func 631 631 };
+1 -1
drivers/i2c/busses/i2c-iop3xx.c
··· 401 401 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; 402 402 } 403 403 404 - static struct i2c_algorithm iop3xx_i2c_algo = { 404 + static const struct i2c_algorithm iop3xx_i2c_algo = { 405 405 .master_xfer = iop3xx_i2c_master_xfer, 406 406 .algo_control = iop3xx_i2c_algo_control, 407 407 .functionality = iop3xx_i2c_func,
+35 -7
drivers/i2c/busses/i2c-isa.c
··· 43 43 static u32 isa_func(struct i2c_adapter *adapter); 44 44 45 45 /* This is the actual algorithm we define */ 46 - static struct i2c_algorithm isa_algorithm = { 46 + static const struct i2c_algorithm isa_algorithm = { 47 47 .functionality = isa_func, 48 48 }; 49 49 ··· 89 89 dev_dbg(&isa_adapter.dev, "Driver %s registered\n", driver->driver.name); 90 90 91 91 /* Now look for clients */ 92 - driver->attach_adapter(&isa_adapter); 93 - 94 - return 0; 92 + res = driver->attach_adapter(&isa_adapter); 93 + if (res) { 94 + dev_err(&isa_adapter.dev, 95 + "Driver %s failed to attach adapter, unregistering\n", 96 + driver->driver.name); 97 + driver_unregister(&driver->driver); 98 + } 99 + return res; 95 100 } 96 101 97 102 int i2c_isa_del_driver(struct i2c_driver *driver) ··· 130 125 131 126 static int __init i2c_isa_init(void) 132 127 { 128 + int err; 129 + 133 130 mutex_init(&isa_adapter.clist_lock); 134 131 INIT_LIST_HEAD(&isa_adapter.clients); 135 132 ··· 140 133 sprintf(isa_adapter.dev.bus_id, "i2c-%d", isa_adapter.nr); 141 134 isa_adapter.dev.driver = &i2c_adapter_driver; 142 135 isa_adapter.dev.release = &i2c_adapter_dev_release; 143 - device_register(&isa_adapter.dev); 144 - device_create_file(&isa_adapter.dev, &dev_attr_name); 136 + err = device_register(&isa_adapter.dev); 137 + if (err) { 138 + printk(KERN_ERR "i2c-isa: Failed to register device\n"); 139 + goto exit; 140 + } 141 + err = device_create_file(&isa_adapter.dev, &dev_attr_name); 142 + if (err) { 143 + printk(KERN_ERR "i2c-isa: Failed to create name file\n"); 144 + goto exit_unregister; 145 + } 145 146 146 147 /* Add this adapter to the i2c_adapter class */ 147 148 memset(&isa_adapter.class_dev, 0x00, sizeof(struct class_device)); ··· 157 142 isa_adapter.class_dev.class = &i2c_adapter_class; 158 143 strlcpy(isa_adapter.class_dev.class_id, isa_adapter.dev.bus_id, 159 144 BUS_ID_SIZE); 160 - class_device_register(&isa_adapter.class_dev); 145 + err = class_device_register(&isa_adapter.class_dev); 146 + if (err) { 147 + printk(KERN_ERR "i2c-isa: Failed to register class device\n"); 148 + goto exit_remove_name; 149 + } 161 150 162 151 dev_dbg(&isa_adapter.dev, "%s registered\n", isa_adapter.name); 163 152 164 153 return 0; 154 + 155 + exit_remove_name: 156 + device_remove_file(&isa_adapter.dev, &dev_attr_name); 157 + exit_unregister: 158 + init_completion(&isa_adapter.dev_released); /* Needed? */ 159 + device_unregister(&isa_adapter.dev); 160 + wait_for_completion(&isa_adapter.dev_released); 161 + exit: 162 + return err; 165 163 } 166 164 167 165 static void __exit i2c_isa_exit(void)
-1
drivers/i2c/busses/i2c-ixp2000.c
··· 114 114 drv_data->algo_data.getsda = ixp2000_bit_getsda; 115 115 drv_data->algo_data.getscl = ixp2000_bit_getscl; 116 116 drv_data->algo_data.udelay = 6; 117 - drv_data->algo_data.mdelay = 6; 118 117 drv_data->algo_data.timeout = 100; 119 118 120 119 drv_data->adapter.id = I2C_HW_B_IXP2000,
-1
drivers/i2c/busses/i2c-ixp4xx.c
··· 122 122 drv_data->algo_data.getsda = ixp4xx_bit_getsda; 123 123 drv_data->algo_data.getscl = ixp4xx_bit_getscl; 124 124 drv_data->algo_data.udelay = 10; 125 - drv_data->algo_data.mdelay = 10; 126 125 drv_data->algo_data.timeout = 100; 127 126 128 127 drv_data->adapter.id = I2C_HW_B_IXP4XX;
+1 -1
drivers/i2c/busses/i2c-mpc.c
··· 272 272 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; 273 273 } 274 274 275 - static struct i2c_algorithm mpc_algo = { 275 + static const struct i2c_algorithm mpc_algo = { 276 276 .master_xfer = mpc_xfer, 277 277 .functionality = mpc_functionality, 278 278 };
+1 -1
drivers/i2c/busses/i2c-mv64xxx.c
··· 431 431 return num; 432 432 } 433 433 434 - static struct i2c_algorithm mv64xxx_i2c_algo = { 434 + static const struct i2c_algorithm mv64xxx_i2c_algo = { 435 435 .master_xfer = mv64xxx_i2c_xfer, 436 436 .functionality = mv64xxx_i2c_functionality, 437 437 };
+1 -1
drivers/i2c/busses/i2c-nforce2.c
··· 109 109 static u32 nforce2_func(struct i2c_adapter *adapter); 110 110 111 111 112 - static struct i2c_algorithm smbus_algorithm = { 112 + static const struct i2c_algorithm smbus_algorithm = { 113 113 .smbus_xfer = nforce2_access, 114 114 .functionality = nforce2_func, 115 115 };
+1 -1
drivers/i2c/busses/i2c-ocores.c
··· 199 199 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; 200 200 } 201 201 202 - static struct i2c_algorithm ocores_algorithm = { 202 + static const struct i2c_algorithm ocores_algorithm = { 203 203 .master_xfer = ocores_xfer, 204 204 .functionality = ocores_func, 205 205 };
+676
drivers/i2c/busses/i2c-omap.c
··· 1 + /* 2 + * TI OMAP I2C master mode driver 3 + * 4 + * Copyright (C) 2003 MontaVista Software, Inc. 5 + * Copyright (C) 2004 Texas Instruments. 6 + * 7 + * Updated to work with multiple I2C interfaces on 24xx by 8 + * Tony Lindgren <tony@atomide.com> and Imre Deak <imre.deak@nokia.com> 9 + * Copyright (C) 2005 Nokia Corporation 10 + * 11 + * Cleaned up by Juha Yrj�l� <juha.yrjola@nokia.com> 12 + * 13 + * This program is free software; you can redistribute it and/or modify 14 + * it under the terms of the GNU General Public License as published by 15 + * the Free Software Foundation; either version 2 of the License, or 16 + * (at your option) any later version. 17 + * 18 + * This program is distributed in the hope that it will be useful, 19 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 + * GNU General Public License for more details. 22 + * 23 + * You should have received a copy of the GNU General Public License 24 + * along with this program; if not, write to the Free Software 25 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 26 + */ 27 + 28 + #include <linux/module.h> 29 + #include <linux/delay.h> 30 + #include <linux/i2c.h> 31 + #include <linux/err.h> 32 + #include <linux/interrupt.h> 33 + #include <linux/completion.h> 34 + #include <linux/platform_device.h> 35 + #include <linux/clk.h> 36 + 37 + #include <asm/io.h> 38 + 39 + /* timeout waiting for the controller to respond */ 40 + #define OMAP_I2C_TIMEOUT (msecs_to_jiffies(1000)) 41 + 42 + #define OMAP_I2C_REV_REG 0x00 43 + #define OMAP_I2C_IE_REG 0x04 44 + #define OMAP_I2C_STAT_REG 0x08 45 + #define OMAP_I2C_IV_REG 0x0c 46 + #define OMAP_I2C_SYSS_REG 0x10 47 + #define OMAP_I2C_BUF_REG 0x14 48 + #define OMAP_I2C_CNT_REG 0x18 49 + #define OMAP_I2C_DATA_REG 0x1c 50 + #define OMAP_I2C_SYSC_REG 0x20 51 + #define OMAP_I2C_CON_REG 0x24 52 + #define OMAP_I2C_OA_REG 0x28 53 + #define OMAP_I2C_SA_REG 0x2c 54 + #define OMAP_I2C_PSC_REG 0x30 55 + #define OMAP_I2C_SCLL_REG 0x34 56 + #define OMAP_I2C_SCLH_REG 0x38 57 + #define OMAP_I2C_SYSTEST_REG 0x3c 58 + 59 + /* I2C Interrupt Enable Register (OMAP_I2C_IE): */ 60 + #define OMAP_I2C_IE_XRDY (1 << 4) /* TX data ready int enable */ 61 + #define OMAP_I2C_IE_RRDY (1 << 3) /* RX data ready int enable */ 62 + #define OMAP_I2C_IE_ARDY (1 << 2) /* Access ready int enable */ 63 + #define OMAP_I2C_IE_NACK (1 << 1) /* No ack interrupt enable */ 64 + #define OMAP_I2C_IE_AL (1 << 0) /* Arbitration lost int ena */ 65 + 66 + /* I2C Status Register (OMAP_I2C_STAT): */ 67 + #define OMAP_I2C_STAT_SBD (1 << 15) /* Single byte data */ 68 + #define OMAP_I2C_STAT_BB (1 << 12) /* Bus busy */ 69 + #define OMAP_I2C_STAT_ROVR (1 << 11) /* Receive overrun */ 70 + #define OMAP_I2C_STAT_XUDF (1 << 10) /* Transmit underflow */ 71 + #define OMAP_I2C_STAT_AAS (1 << 9) /* Address as slave */ 72 + #define OMAP_I2C_STAT_AD0 (1 << 8) /* Address zero */ 73 + #define OMAP_I2C_STAT_XRDY (1 << 4) /* Transmit data ready */ 74 + #define OMAP_I2C_STAT_RRDY (1 << 3) /* Receive data ready */ 75 + #define OMAP_I2C_STAT_ARDY (1 << 2) /* Register access ready */ 76 + #define OMAP_I2C_STAT_NACK (1 << 1) /* No ack interrupt enable */ 77 + #define OMAP_I2C_STAT_AL (1 << 0) /* Arbitration lost int ena */ 78 + 79 + /* I2C Buffer Configuration Register (OMAP_I2C_BUF): */ 80 + #define OMAP_I2C_BUF_RDMA_EN (1 << 15) /* RX DMA channel enable */ 81 + #define OMAP_I2C_BUF_XDMA_EN (1 << 7) /* TX DMA channel enable */ 82 + 83 + /* I2C Configuration Register (OMAP_I2C_CON): */ 84 + #define OMAP_I2C_CON_EN (1 << 15) /* I2C module enable */ 85 + #define OMAP_I2C_CON_BE (1 << 14) /* Big endian mode */ 86 + #define OMAP_I2C_CON_STB (1 << 11) /* Start byte mode (master) */ 87 + #define OMAP_I2C_CON_MST (1 << 10) /* Master/slave mode */ 88 + #define OMAP_I2C_CON_TRX (1 << 9) /* TX/RX mode (master only) */ 89 + #define OMAP_I2C_CON_XA (1 << 8) /* Expand address */ 90 + #define OMAP_I2C_CON_RM (1 << 2) /* Repeat mode (master only) */ 91 + #define OMAP_I2C_CON_STP (1 << 1) /* Stop cond (master only) */ 92 + #define OMAP_I2C_CON_STT (1 << 0) /* Start condition (master) */ 93 + 94 + /* I2C System Test Register (OMAP_I2C_SYSTEST): */ 95 + #ifdef DEBUG 96 + #define OMAP_I2C_SYSTEST_ST_EN (1 << 15) /* System test enable */ 97 + #define OMAP_I2C_SYSTEST_FREE (1 << 14) /* Free running mode */ 98 + #define OMAP_I2C_SYSTEST_TMODE_MASK (3 << 12) /* Test mode select */ 99 + #define OMAP_I2C_SYSTEST_TMODE_SHIFT (12) /* Test mode select */ 100 + #define OMAP_I2C_SYSTEST_SCL_I (1 << 3) /* SCL line sense in */ 101 + #define OMAP_I2C_SYSTEST_SCL_O (1 << 2) /* SCL line drive out */ 102 + #define OMAP_I2C_SYSTEST_SDA_I (1 << 1) /* SDA line sense in */ 103 + #define OMAP_I2C_SYSTEST_SDA_O (1 << 0) /* SDA line drive out */ 104 + #endif 105 + 106 + /* I2C System Status register (OMAP_I2C_SYSS): */ 107 + #define OMAP_I2C_SYSS_RDONE (1 << 0) /* Reset Done */ 108 + 109 + /* I2C System Configuration Register (OMAP_I2C_SYSC): */ 110 + #define OMAP_I2C_SYSC_SRST (1 << 1) /* Soft Reset */ 111 + 112 + /* REVISIT: Use platform_data instead of module parameters */ 113 + /* Fast Mode = 400 kHz, Standard = 100 kHz */ 114 + static int clock = 100; /* Default: 100 kHz */ 115 + module_param(clock, int, 0); 116 + MODULE_PARM_DESC(clock, "Set I2C clock in kHz: 400=fast mode (default == 100)"); 117 + 118 + struct omap_i2c_dev { 119 + struct device *dev; 120 + void __iomem *base; /* virtual */ 121 + int irq; 122 + struct clk *iclk; /* Interface clock */ 123 + struct clk *fclk; /* Functional clock */ 124 + struct completion cmd_complete; 125 + struct resource *ioarea; 126 + u16 cmd_err; 127 + u8 *buf; 128 + size_t buf_len; 129 + struct i2c_adapter adapter; 130 + unsigned rev1:1; 131 + }; 132 + 133 + static inline void omap_i2c_write_reg(struct omap_i2c_dev *i2c_dev, 134 + int reg, u16 val) 135 + { 136 + __raw_writew(val, i2c_dev->base + reg); 137 + } 138 + 139 + static inline u16 omap_i2c_read_reg(struct omap_i2c_dev *i2c_dev, int reg) 140 + { 141 + return __raw_readw(i2c_dev->base + reg); 142 + } 143 + 144 + static int omap_i2c_get_clocks(struct omap_i2c_dev *dev) 145 + { 146 + if (cpu_is_omap16xx() || cpu_is_omap24xx()) { 147 + dev->iclk = clk_get(dev->dev, "i2c_ick"); 148 + if (IS_ERR(dev->iclk)) { 149 + dev->iclk = NULL; 150 + return -ENODEV; 151 + } 152 + } 153 + 154 + dev->fclk = clk_get(dev->dev, "i2c_fck"); 155 + if (IS_ERR(dev->fclk)) { 156 + if (dev->iclk != NULL) { 157 + clk_put(dev->iclk); 158 + dev->iclk = NULL; 159 + } 160 + dev->fclk = NULL; 161 + return -ENODEV; 162 + } 163 + 164 + return 0; 165 + } 166 + 167 + static void omap_i2c_put_clocks(struct omap_i2c_dev *dev) 168 + { 169 + clk_put(dev->fclk); 170 + dev->fclk = NULL; 171 + if (dev->iclk != NULL) { 172 + clk_put(dev->iclk); 173 + dev->iclk = NULL; 174 + } 175 + } 176 + 177 + static void omap_i2c_enable_clocks(struct omap_i2c_dev *dev) 178 + { 179 + if (dev->iclk != NULL) 180 + clk_enable(dev->iclk); 181 + clk_enable(dev->fclk); 182 + } 183 + 184 + static void omap_i2c_disable_clocks(struct omap_i2c_dev *dev) 185 + { 186 + if (dev->iclk != NULL) 187 + clk_disable(dev->iclk); 188 + clk_disable(dev->fclk); 189 + } 190 + 191 + static int omap_i2c_init(struct omap_i2c_dev *dev) 192 + { 193 + u16 psc = 0; 194 + unsigned long fclk_rate = 12000000; 195 + unsigned long timeout; 196 + 197 + if (!dev->rev1) { 198 + omap_i2c_write_reg(dev, OMAP_I2C_SYSC_REG, OMAP_I2C_SYSC_SRST); 199 + /* For some reason we need to set the EN bit before the 200 + * reset done bit gets set. */ 201 + timeout = jiffies + OMAP_I2C_TIMEOUT; 202 + omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, OMAP_I2C_CON_EN); 203 + while (!(omap_i2c_read_reg(dev, OMAP_I2C_SYSS_REG) & 204 + OMAP_I2C_SYSS_RDONE)) { 205 + if (time_after(jiffies, timeout)) { 206 + dev_warn(dev->dev, "timeout waiting" 207 + "for controller reset\n"); 208 + return -ETIMEDOUT; 209 + } 210 + msleep(1); 211 + } 212 + } 213 + omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0); 214 + 215 + if (cpu_class_is_omap1()) { 216 + struct clk *armxor_ck; 217 + 218 + armxor_ck = clk_get(NULL, "armxor_ck"); 219 + if (IS_ERR(armxor_ck)) 220 + dev_warn(dev->dev, "Could not get armxor_ck\n"); 221 + else { 222 + fclk_rate = clk_get_rate(armxor_ck); 223 + clk_put(armxor_ck); 224 + } 225 + /* TRM for 5912 says the I2C clock must be prescaled to be 226 + * between 7 - 12 MHz. The XOR input clock is typically 227 + * 12, 13 or 19.2 MHz. So we should have code that produces: 228 + * 229 + * XOR MHz Divider Prescaler 230 + * 12 1 0 231 + * 13 2 1 232 + * 19.2 2 1 233 + */ 234 + if (fclk_rate > 16000000) 235 + psc = (fclk_rate + 8000000) / 12000000; 236 + } 237 + 238 + /* Setup clock prescaler to obtain approx 12MHz I2C module clock: */ 239 + omap_i2c_write_reg(dev, OMAP_I2C_PSC_REG, psc); 240 + 241 + /* Program desired operating rate */ 242 + fclk_rate /= (psc + 1) * 1000; 243 + if (psc > 2) 244 + psc = 2; 245 + 246 + omap_i2c_write_reg(dev, OMAP_I2C_SCLL_REG, 247 + fclk_rate / (clock * 2) - 7 + psc); 248 + omap_i2c_write_reg(dev, OMAP_I2C_SCLH_REG, 249 + fclk_rate / (clock * 2) - 7 + psc); 250 + 251 + /* Take the I2C module out of reset: */ 252 + omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, OMAP_I2C_CON_EN); 253 + 254 + /* Enable interrupts */ 255 + omap_i2c_write_reg(dev, OMAP_I2C_IE_REG, 256 + (OMAP_I2C_IE_XRDY | OMAP_I2C_IE_RRDY | 257 + OMAP_I2C_IE_ARDY | OMAP_I2C_IE_NACK | 258 + OMAP_I2C_IE_AL)); 259 + return 0; 260 + } 261 + 262 + /* 263 + * Waiting on Bus Busy 264 + */ 265 + static int omap_i2c_wait_for_bb(struct omap_i2c_dev *dev) 266 + { 267 + unsigned long timeout; 268 + 269 + timeout = jiffies + OMAP_I2C_TIMEOUT; 270 + while (omap_i2c_read_reg(dev, OMAP_I2C_STAT_REG) & OMAP_I2C_STAT_BB) { 271 + if (time_after(jiffies, timeout)) { 272 + dev_warn(dev->dev, "timeout waiting for bus ready\n"); 273 + return -ETIMEDOUT; 274 + } 275 + msleep(1); 276 + } 277 + 278 + return 0; 279 + } 280 + 281 + /* 282 + * Low level master read/write transaction. 283 + */ 284 + static int omap_i2c_xfer_msg(struct i2c_adapter *adap, 285 + struct i2c_msg *msg, int stop) 286 + { 287 + struct omap_i2c_dev *dev = i2c_get_adapdata(adap); 288 + int r; 289 + u16 w; 290 + 291 + dev_dbg(dev->dev, "addr: 0x%04x, len: %d, flags: 0x%x, stop: %d\n", 292 + msg->addr, msg->len, msg->flags, stop); 293 + 294 + if (msg->len == 0) 295 + return -EINVAL; 296 + 297 + omap_i2c_write_reg(dev, OMAP_I2C_SA_REG, msg->addr); 298 + 299 + /* REVISIT: Could the STB bit of I2C_CON be used with probing? */ 300 + dev->buf = msg->buf; 301 + dev->buf_len = msg->len; 302 + 303 + omap_i2c_write_reg(dev, OMAP_I2C_CNT_REG, dev->buf_len); 304 + 305 + init_completion(&dev->cmd_complete); 306 + dev->cmd_err = 0; 307 + 308 + w = OMAP_I2C_CON_EN | OMAP_I2C_CON_MST | OMAP_I2C_CON_STT; 309 + if (msg->flags & I2C_M_TEN) 310 + w |= OMAP_I2C_CON_XA; 311 + if (!(msg->flags & I2C_M_RD)) 312 + w |= OMAP_I2C_CON_TRX; 313 + if (stop) 314 + w |= OMAP_I2C_CON_STP; 315 + omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, w); 316 + 317 + r = wait_for_completion_interruptible_timeout(&dev->cmd_complete, 318 + OMAP_I2C_TIMEOUT); 319 + dev->buf_len = 0; 320 + if (r < 0) 321 + return r; 322 + if (r == 0) { 323 + dev_err(dev->dev, "controller timed out\n"); 324 + omap_i2c_init(dev); 325 + return -ETIMEDOUT; 326 + } 327 + 328 + if (likely(!dev->cmd_err)) 329 + return 0; 330 + 331 + /* We have an error */ 332 + if (dev->cmd_err & (OMAP_I2C_STAT_AL | OMAP_I2C_STAT_ROVR | 333 + OMAP_I2C_STAT_XUDF)) { 334 + omap_i2c_init(dev); 335 + return -EIO; 336 + } 337 + 338 + if (dev->cmd_err & OMAP_I2C_STAT_NACK) { 339 + if (msg->flags & I2C_M_IGNORE_NAK) 340 + return 0; 341 + if (stop) { 342 + w = omap_i2c_read_reg(dev, OMAP_I2C_CON_REG); 343 + w |= OMAP_I2C_CON_STP; 344 + omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, w); 345 + } 346 + return -EREMOTEIO; 347 + } 348 + return -EIO; 349 + } 350 + 351 + 352 + /* 353 + * Prepare controller for a transaction and call omap_i2c_xfer_msg 354 + * to do the work during IRQ processing. 355 + */ 356 + static int 357 + omap_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) 358 + { 359 + struct omap_i2c_dev *dev = i2c_get_adapdata(adap); 360 + int i; 361 + int r; 362 + 363 + omap_i2c_enable_clocks(dev); 364 + 365 + /* REVISIT: initialize and use adap->retries. This is an optional 366 + * feature */ 367 + if ((r = omap_i2c_wait_for_bb(dev)) < 0) 368 + goto out; 369 + 370 + for (i = 0; i < num; i++) { 371 + r = omap_i2c_xfer_msg(adap, &msgs[i], (i == (num - 1))); 372 + if (r != 0) 373 + break; 374 + } 375 + 376 + if (r == 0) 377 + r = num; 378 + out: 379 + omap_i2c_disable_clocks(dev); 380 + return r; 381 + } 382 + 383 + static u32 384 + omap_i2c_func(struct i2c_adapter *adap) 385 + { 386 + return I2C_FUNC_I2C | (I2C_FUNC_SMBUS_EMUL & ~I2C_FUNC_SMBUS_QUICK); 387 + } 388 + 389 + static inline void 390 + omap_i2c_complete_cmd(struct omap_i2c_dev *dev, u16 err) 391 + { 392 + dev->cmd_err |= err; 393 + complete(&dev->cmd_complete); 394 + } 395 + 396 + static inline void 397 + omap_i2c_ack_stat(struct omap_i2c_dev *dev, u16 stat) 398 + { 399 + omap_i2c_write_reg(dev, OMAP_I2C_STAT_REG, stat); 400 + } 401 + 402 + static irqreturn_t 403 + omap_i2c_rev1_isr(int this_irq, void *dev_id, struct pt_regs *regs) 404 + { 405 + struct omap_i2c_dev *dev = dev_id; 406 + u16 iv, w; 407 + 408 + iv = omap_i2c_read_reg(dev, OMAP_I2C_IV_REG); 409 + switch (iv) { 410 + case 0x00: /* None */ 411 + break; 412 + case 0x01: /* Arbitration lost */ 413 + dev_err(dev->dev, "Arbitration lost\n"); 414 + omap_i2c_complete_cmd(dev, OMAP_I2C_STAT_AL); 415 + break; 416 + case 0x02: /* No acknowledgement */ 417 + omap_i2c_complete_cmd(dev, OMAP_I2C_STAT_NACK); 418 + omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, OMAP_I2C_CON_STP); 419 + break; 420 + case 0x03: /* Register access ready */ 421 + omap_i2c_complete_cmd(dev, 0); 422 + break; 423 + case 0x04: /* Receive data ready */ 424 + if (dev->buf_len) { 425 + w = omap_i2c_read_reg(dev, OMAP_I2C_DATA_REG); 426 + *dev->buf++ = w; 427 + dev->buf_len--; 428 + if (dev->buf_len) { 429 + *dev->buf++ = w >> 8; 430 + dev->buf_len--; 431 + } 432 + } else 433 + dev_err(dev->dev, "RRDY IRQ while no data requested\n"); 434 + break; 435 + case 0x05: /* Transmit data ready */ 436 + if (dev->buf_len) { 437 + w = *dev->buf++; 438 + dev->buf_len--; 439 + if (dev->buf_len) { 440 + w |= *dev->buf++ << 8; 441 + dev->buf_len--; 442 + } 443 + omap_i2c_write_reg(dev, OMAP_I2C_DATA_REG, w); 444 + } else 445 + dev_err(dev->dev, "XRDY IRQ while no data to send\n"); 446 + break; 447 + default: 448 + return IRQ_NONE; 449 + } 450 + 451 + return IRQ_HANDLED; 452 + } 453 + 454 + static irqreturn_t 455 + omap_i2c_isr(int this_irq, void *dev_id, struct pt_regs *regs) 456 + { 457 + struct omap_i2c_dev *dev = dev_id; 458 + u16 bits; 459 + u16 stat, w; 460 + int count = 0; 461 + 462 + bits = omap_i2c_read_reg(dev, OMAP_I2C_IE_REG); 463 + while ((stat = (omap_i2c_read_reg(dev, OMAP_I2C_STAT_REG))) & bits) { 464 + dev_dbg(dev->dev, "IRQ (ISR = 0x%04x)\n", stat); 465 + if (count++ == 100) { 466 + dev_warn(dev->dev, "Too much work in one IRQ\n"); 467 + break; 468 + } 469 + 470 + omap_i2c_write_reg(dev, OMAP_I2C_STAT_REG, stat); 471 + 472 + if (stat & OMAP_I2C_STAT_ARDY) { 473 + omap_i2c_complete_cmd(dev, 0); 474 + continue; 475 + } 476 + if (stat & OMAP_I2C_STAT_RRDY) { 477 + w = omap_i2c_read_reg(dev, OMAP_I2C_DATA_REG); 478 + if (dev->buf_len) { 479 + *dev->buf++ = w; 480 + dev->buf_len--; 481 + if (dev->buf_len) { 482 + *dev->buf++ = w >> 8; 483 + dev->buf_len--; 484 + } 485 + } else 486 + dev_err(dev->dev, "RRDY IRQ while no data" 487 + "requested\n"); 488 + omap_i2c_ack_stat(dev, OMAP_I2C_STAT_RRDY); 489 + continue; 490 + } 491 + if (stat & OMAP_I2C_STAT_XRDY) { 492 + w = 0; 493 + if (dev->buf_len) { 494 + w = *dev->buf++; 495 + dev->buf_len--; 496 + if (dev->buf_len) { 497 + w |= *dev->buf++ << 8; 498 + dev->buf_len--; 499 + } 500 + } else 501 + dev_err(dev->dev, "XRDY IRQ while no" 502 + "data to send\n"); 503 + omap_i2c_write_reg(dev, OMAP_I2C_DATA_REG, w); 504 + omap_i2c_ack_stat(dev, OMAP_I2C_STAT_XRDY); 505 + continue; 506 + } 507 + if (stat & OMAP_I2C_STAT_ROVR) { 508 + dev_err(dev->dev, "Receive overrun\n"); 509 + dev->cmd_err |= OMAP_I2C_STAT_ROVR; 510 + } 511 + if (stat & OMAP_I2C_STAT_XUDF) { 512 + dev_err(dev->dev, "Transmit overflow\n"); 513 + dev->cmd_err |= OMAP_I2C_STAT_XUDF; 514 + } 515 + if (stat & OMAP_I2C_STAT_NACK) { 516 + omap_i2c_complete_cmd(dev, OMAP_I2C_STAT_NACK); 517 + omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 518 + OMAP_I2C_CON_STP); 519 + } 520 + if (stat & OMAP_I2C_STAT_AL) { 521 + dev_err(dev->dev, "Arbitration lost\n"); 522 + omap_i2c_complete_cmd(dev, OMAP_I2C_STAT_AL); 523 + } 524 + } 525 + 526 + return count ? IRQ_HANDLED : IRQ_NONE; 527 + } 528 + 529 + static const struct i2c_algorithm omap_i2c_algo = { 530 + .master_xfer = omap_i2c_xfer, 531 + .functionality = omap_i2c_func, 532 + }; 533 + 534 + static int 535 + omap_i2c_probe(struct platform_device *pdev) 536 + { 537 + struct omap_i2c_dev *dev; 538 + struct i2c_adapter *adap; 539 + struct resource *mem, *irq, *ioarea; 540 + int r; 541 + 542 + /* NOTE: driver uses the static register mapping */ 543 + mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 544 + if (!mem) { 545 + dev_err(&pdev->dev, "no mem resource?\n"); 546 + return -ENODEV; 547 + } 548 + irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 549 + if (!irq) { 550 + dev_err(&pdev->dev, "no irq resource?\n"); 551 + return -ENODEV; 552 + } 553 + 554 + ioarea = request_mem_region(mem->start, (mem->end - mem->start) + 1, 555 + pdev->name); 556 + if (!ioarea) { 557 + dev_err(&pdev->dev, "I2C region already claimed\n"); 558 + return -EBUSY; 559 + } 560 + 561 + if (clock > 200) 562 + clock = 400; /* Fast mode */ 563 + else 564 + clock = 100; /* Standard mode */ 565 + 566 + dev = kzalloc(sizeof(struct omap_i2c_dev), GFP_KERNEL); 567 + if (!dev) { 568 + r = -ENOMEM; 569 + goto err_release_region; 570 + } 571 + 572 + dev->dev = &pdev->dev; 573 + dev->irq = irq->start; 574 + dev->base = (void __iomem *) IO_ADDRESS(mem->start); 575 + platform_set_drvdata(pdev, dev); 576 + 577 + if ((r = omap_i2c_get_clocks(dev)) != 0) 578 + goto err_free_mem; 579 + 580 + omap_i2c_enable_clocks(dev); 581 + 582 + if (cpu_is_omap15xx()) 583 + dev->rev1 = omap_i2c_read_reg(dev, OMAP_I2C_REV_REG) < 0x20; 584 + 585 + /* reset ASAP, clearing any IRQs */ 586 + omap_i2c_init(dev); 587 + 588 + r = request_irq(dev->irq, dev->rev1 ? omap_i2c_rev1_isr : omap_i2c_isr, 589 + 0, pdev->name, dev); 590 + 591 + if (r) { 592 + dev_err(dev->dev, "failure requesting irq %i\n", dev->irq); 593 + goto err_unuse_clocks; 594 + } 595 + r = omap_i2c_read_reg(dev, OMAP_I2C_REV_REG) & 0xff; 596 + dev_info(dev->dev, "bus %d rev%d.%d at %d kHz\n", 597 + pdev->id, r >> 4, r & 0xf, clock); 598 + 599 + adap = &dev->adapter; 600 + i2c_set_adapdata(adap, dev); 601 + adap->owner = THIS_MODULE; 602 + adap->class = I2C_CLASS_HWMON; 603 + strncpy(adap->name, "OMAP I2C adapter", sizeof(adap->name)); 604 + adap->algo = &omap_i2c_algo; 605 + adap->dev.parent = &pdev->dev; 606 + 607 + /* i2c device drivers may be active on return from add_adapter() */ 608 + r = i2c_add_adapter(adap); 609 + if (r) { 610 + dev_err(dev->dev, "failure adding adapter\n"); 611 + goto err_free_irq; 612 + } 613 + 614 + omap_i2c_disable_clocks(dev); 615 + 616 + return 0; 617 + 618 + err_free_irq: 619 + free_irq(dev->irq, dev); 620 + err_unuse_clocks: 621 + omap_i2c_disable_clocks(dev); 622 + omap_i2c_put_clocks(dev); 623 + err_free_mem: 624 + platform_set_drvdata(pdev, NULL); 625 + kfree(dev); 626 + err_release_region: 627 + omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0); 628 + release_mem_region(mem->start, (mem->end - mem->start) + 1); 629 + 630 + return r; 631 + } 632 + 633 + static int 634 + omap_i2c_remove(struct platform_device *pdev) 635 + { 636 + struct omap_i2c_dev *dev = platform_get_drvdata(pdev); 637 + struct resource *mem; 638 + 639 + platform_set_drvdata(pdev, NULL); 640 + 641 + free_irq(dev->irq, dev); 642 + i2c_del_adapter(&dev->adapter); 643 + omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0); 644 + omap_i2c_put_clocks(dev); 645 + kfree(dev); 646 + mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 647 + release_mem_region(mem->start, (mem->end - mem->start) + 1); 648 + return 0; 649 + } 650 + 651 + static struct platform_driver omap_i2c_driver = { 652 + .probe = omap_i2c_probe, 653 + .remove = omap_i2c_remove, 654 + .driver = { 655 + .name = "i2c_omap", 656 + .owner = THIS_MODULE, 657 + }, 658 + }; 659 + 660 + /* I2C may be needed to bring up other drivers */ 661 + static int __init 662 + omap_i2c_init_driver(void) 663 + { 664 + return platform_driver_register(&omap_i2c_driver); 665 + } 666 + subsys_initcall(omap_i2c_init_driver); 667 + 668 + static void __exit omap_i2c_exit_driver(void) 669 + { 670 + platform_driver_unregister(&omap_i2c_driver); 671 + } 672 + module_exit(omap_i2c_exit_driver); 673 + 674 + MODULE_AUTHOR("MontaVista Software, Inc. (and others)"); 675 + MODULE_DESCRIPTION("TI OMAP I2C bus adapter"); 676 + MODULE_LICENSE("GPL");
-1
drivers/i2c/busses/i2c-parport-light.c
··· 103 103 .getsda = parport_getsda, 104 104 .getscl = parport_getscl, 105 105 .udelay = 50, 106 - .mdelay = 50, 107 106 .timeout = HZ, 108 107 }; 109 108
-1
drivers/i2c/busses/i2c-parport.c
··· 138 138 .getsda = parport_getsda, 139 139 .getscl = parport_getscl, 140 140 .udelay = 60, 141 - .mdelay = 60, 142 141 .timeout = HZ, 143 142 }; 144 143
+1 -1
drivers/i2c/busses/i2c-piix4.c
··· 376 376 I2C_FUNC_SMBUS_BLOCK_DATA; 377 377 } 378 378 379 - static struct i2c_algorithm smbus_algorithm = { 379 + static const struct i2c_algorithm smbus_algorithm = { 380 380 .smbus_xfer = piix4_access, 381 381 .functionality = piix4_func, 382 382 };
+1 -1
drivers/i2c/busses/i2c-powermac.c
··· 175 175 } 176 176 177 177 /* For now, we only handle smbus */ 178 - static struct i2c_algorithm i2c_powermac_algorithm = { 178 + static const struct i2c_algorithm i2c_powermac_algorithm = { 179 179 .smbus_xfer = i2c_powermac_smbus_xfer, 180 180 .master_xfer = i2c_powermac_master_xfer, 181 181 .functionality = i2c_powermac_func,
-1
drivers/i2c/busses/i2c-prosavage.c
··· 180 180 p->algo.getsda = bit_s3via_getsda; 181 181 p->algo.getscl = bit_s3via_getscl; 182 182 p->algo.udelay = CYCLE_DELAY; 183 - p->algo.mdelay = CYCLE_DELAY; 184 183 p->algo.timeout = TIMEOUT; 185 184 p->algo.data = p; 186 185 p->mmvga = mmvga;
+1 -1
drivers/i2c/busses/i2c-pxa.c
··· 926 926 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; 927 927 } 928 928 929 - static struct i2c_algorithm i2c_pxa_algorithm = { 929 + static const struct i2c_algorithm i2c_pxa_algorithm = { 930 930 .master_xfer = i2c_pxa_xfer, 931 931 .functionality = i2c_pxa_functionality, 932 932 };
+1 -1
drivers/i2c/busses/i2c-s3c2410.c
··· 566 566 567 567 /* i2c bus registration info */ 568 568 569 - static struct i2c_algorithm s3c24xx_i2c_algorithm = { 569 + static const struct i2c_algorithm s3c24xx_i2c_algorithm = { 570 570 .master_xfer = s3c24xx_i2c_xfer, 571 571 .functionality = s3c24xx_i2c_func, 572 572 };
-1
drivers/i2c/busses/i2c-savage4.c
··· 140 140 .getsda = bit_savi2c_getsda, 141 141 .getscl = bit_savi2c_getscl, 142 142 .udelay = CYCLE_DELAY, 143 - .mdelay = CYCLE_DELAY, 144 143 .timeout = TIMEOUT 145 144 }; 146 145
+156 -4
drivers/i2c/busses/i2c-sibyte.c
··· 1 1 /* 2 2 * Copyright (C) 2004 Steven J. Hill 3 3 * Copyright (C) 2001,2002,2003 Broadcom Corporation 4 + * Copyright (C) 1995-2000 Simon G. Vogl 4 5 * 5 6 * This program is free software; you can redistribute it and/or 6 7 * modify it under the terms of the GNU General Public License ··· 18 17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 18 */ 20 19 20 + #include <linux/kernel.h> 21 21 #include <linux/module.h> 22 - #include <linux/i2c-algo-sibyte.h> 22 + #include <linux/init.h> 23 + #include <linux/i2c.h> 24 + #include <asm/io.h> 23 25 #include <asm/sibyte/sb1250_regs.h> 24 26 #include <asm/sibyte/sb1250_smbus.h> 27 + 28 + 29 + struct i2c_algo_sibyte_data { 30 + void *data; /* private data */ 31 + int bus; /* which bus */ 32 + void *reg_base; /* CSR base */ 33 + }; 34 + 35 + /* ----- global defines ----------------------------------------------- */ 36 + #define SMB_CSR(a,r) ((long)(a->reg_base + r)) 37 + 38 + /* ----- global variables --------------------------------------------- */ 39 + 40 + /* module parameters: 41 + */ 42 + static int bit_scan; /* have a look at what's hanging 'round */ 43 + module_param(bit_scan, int, 0); 44 + MODULE_PARM_DESC(bit_scan, "Scan for active chips on the bus"); 45 + 46 + 47 + static int smbus_xfer(struct i2c_adapter *i2c_adap, u16 addr, 48 + unsigned short flags, char read_write, 49 + u8 command, int size, union i2c_smbus_data * data) 50 + { 51 + struct i2c_algo_sibyte_data *adap = i2c_adap->algo_data; 52 + int data_bytes = 0; 53 + int error; 54 + 55 + while (csr_in32(SMB_CSR(adap, R_SMB_STATUS)) & M_SMB_BUSY) 56 + ; 57 + 58 + switch (size) { 59 + case I2C_SMBUS_QUICK: 60 + csr_out32((V_SMB_ADDR(addr) | 61 + (read_write == I2C_SMBUS_READ ? M_SMB_QDATA : 0) | 62 + V_SMB_TT_QUICKCMD), SMB_CSR(adap, R_SMB_START)); 63 + break; 64 + case I2C_SMBUS_BYTE: 65 + if (read_write == I2C_SMBUS_READ) { 66 + csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_RD1BYTE), 67 + SMB_CSR(adap, R_SMB_START)); 68 + data_bytes = 1; 69 + } else { 70 + csr_out32(V_SMB_CMD(command), SMB_CSR(adap, R_SMB_CMD)); 71 + csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_WR1BYTE), 72 + SMB_CSR(adap, R_SMB_START)); 73 + } 74 + break; 75 + case I2C_SMBUS_BYTE_DATA: 76 + csr_out32(V_SMB_CMD(command), SMB_CSR(adap, R_SMB_CMD)); 77 + if (read_write == I2C_SMBUS_READ) { 78 + csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_CMD_RD1BYTE), 79 + SMB_CSR(adap, R_SMB_START)); 80 + data_bytes = 1; 81 + } else { 82 + csr_out32(V_SMB_LB(data->byte), 83 + SMB_CSR(adap, R_SMB_DATA)); 84 + csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_WR2BYTE), 85 + SMB_CSR(adap, R_SMB_START)); 86 + } 87 + break; 88 + case I2C_SMBUS_WORD_DATA: 89 + csr_out32(V_SMB_CMD(command), SMB_CSR(adap, R_SMB_CMD)); 90 + if (read_write == I2C_SMBUS_READ) { 91 + csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_CMD_RD2BYTE), 92 + SMB_CSR(adap, R_SMB_START)); 93 + data_bytes = 2; 94 + } else { 95 + csr_out32(V_SMB_LB(data->word & 0xff), 96 + SMB_CSR(adap, R_SMB_DATA)); 97 + csr_out32(V_SMB_MB(data->word >> 8), 98 + SMB_CSR(adap, R_SMB_DATA)); 99 + csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_WR2BYTE), 100 + SMB_CSR(adap, R_SMB_START)); 101 + } 102 + break; 103 + default: 104 + return -1; /* XXXKW better error code? */ 105 + } 106 + 107 + while (csr_in32(SMB_CSR(adap, R_SMB_STATUS)) & M_SMB_BUSY) 108 + ; 109 + 110 + error = csr_in32(SMB_CSR(adap, R_SMB_STATUS)); 111 + if (error & M_SMB_ERROR) { 112 + /* Clear error bit by writing a 1 */ 113 + csr_out32(M_SMB_ERROR, SMB_CSR(adap, R_SMB_STATUS)); 114 + return -1; /* XXXKW better error code? */ 115 + } 116 + 117 + if (data_bytes == 1) 118 + data->byte = csr_in32(SMB_CSR(adap, R_SMB_DATA)) & 0xff; 119 + if (data_bytes == 2) 120 + data->word = csr_in32(SMB_CSR(adap, R_SMB_DATA)) & 0xffff; 121 + 122 + return 0; 123 + } 124 + 125 + static u32 bit_func(struct i2c_adapter *adap) 126 + { 127 + return (I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | 128 + I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA); 129 + } 130 + 131 + 132 + /* -----exported algorithm data: ------------------------------------- */ 133 + 134 + static const struct i2c_algorithm i2c_sibyte_algo = { 135 + .smbus_xfer = smbus_xfer, 136 + .functionality = bit_func, 137 + }; 138 + 139 + /* 140 + * registering functions to load algorithms at runtime 141 + */ 142 + int i2c_sibyte_add_bus(struct i2c_adapter *i2c_adap, int speed) 143 + { 144 + int i; 145 + struct i2c_algo_sibyte_data *adap = i2c_adap->algo_data; 146 + 147 + /* register new adapter to i2c module... */ 148 + i2c_adap->algo = &i2c_sibyte_algo; 149 + 150 + /* Set the frequency to 100 kHz */ 151 + csr_out32(speed, SMB_CSR(adap,R_SMB_FREQ)); 152 + csr_out32(0, SMB_CSR(adap,R_SMB_CONTROL)); 153 + 154 + /* scan bus */ 155 + if (bit_scan) { 156 + union i2c_smbus_data data; 157 + int rc; 158 + printk(KERN_INFO " i2c-algo-sibyte.o: scanning bus %s.\n", 159 + i2c_adap->name); 160 + for (i = 0x00; i < 0x7f; i++) { 161 + /* XXXKW is this a realistic probe? */ 162 + rc = smbus_xfer(i2c_adap, i, 0, I2C_SMBUS_READ, 0, 163 + I2C_SMBUS_BYTE_DATA, &data); 164 + if (!rc) { 165 + printk("(%02x)",i); 166 + } else 167 + printk("."); 168 + } 169 + printk("\n"); 170 + } 171 + 172 + return i2c_add_adapter(i2c_adap); 173 + } 174 + 25 175 26 176 static struct i2c_algo_sibyte_data sibyte_board_data[2] = { 27 177 { NULL, 0, (void *) (CKSEG1+A_SMB_BASE(0)) }, ··· 210 58 211 59 static void __exit i2c_sibyte_exit(void) 212 60 { 213 - i2c_sibyte_del_bus(&sibyte_board_adapter[0]); 214 - i2c_sibyte_del_bus(&sibyte_board_adapter[1]); 61 + i2c_del_bus(&sibyte_board_adapter[0]); 62 + i2c_del_bus(&sibyte_board_adapter[1]); 215 63 } 216 64 217 65 module_init(i2c_sibyte_init); 218 66 module_exit(i2c_sibyte_exit); 219 67 220 - MODULE_AUTHOR("Kip Walker <kwalker@broadcom.com>, Steven J. Hill <sjhill@realitydiluted.com>"); 68 + MODULE_AUTHOR("Kip Walker (Broadcom Corp.), Steven J. Hill <sjhill@realitydiluted.com>"); 221 69 MODULE_DESCRIPTION("SMBus adapter routines for SiByte boards"); 222 70 MODULE_LICENSE("GPL");
+1 -1
drivers/i2c/busses/i2c-sis5595.c
··· 358 358 I2C_FUNC_SMBUS_PROC_CALL; 359 359 } 360 360 361 - static struct i2c_algorithm smbus_algorithm = { 361 + static const struct i2c_algorithm smbus_algorithm = { 362 362 .smbus_xfer = sis5595_access, 363 363 .functionality = sis5595_func, 364 364 };
+1 -1
drivers/i2c/busses/i2c-sis630.c
··· 450 450 } 451 451 452 452 453 - static struct i2c_algorithm smbus_algorithm = { 453 + static const struct i2c_algorithm smbus_algorithm = { 454 454 .smbus_xfer = sis630_access, 455 455 .functionality = sis630_func, 456 456 };
+1 -1
drivers/i2c/busses/i2c-sis96x.c
··· 242 242 I2C_FUNC_SMBUS_PROC_CALL; 243 243 } 244 244 245 - static struct i2c_algorithm smbus_algorithm = { 245 + static const struct i2c_algorithm smbus_algorithm = { 246 246 .smbus_xfer = sis96x_access, 247 247 .functionality = sis96x_func, 248 248 };
+19 -2
drivers/i2c/busses/i2c-stub.c
··· 27 27 #include <linux/errno.h> 28 28 #include <linux/i2c.h> 29 29 30 + static unsigned short chip_addr; 31 + module_param(chip_addr, ushort, S_IRUGO); 32 + MODULE_PARM_DESC(chip_addr, "Chip address (between 0x03 and 0x77)\n"); 33 + 30 34 static u8 stub_pointer; 31 35 static u8 stub_bytes[256]; 32 36 static u16 stub_words[256]; ··· 40 36 char read_write, u8 command, int size, union i2c_smbus_data * data) 41 37 { 42 38 s32 ret; 39 + 40 + if (addr != chip_addr) 41 + return -ENODEV; 43 42 44 43 switch (size) { 45 44 ··· 115 108 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA; 116 109 } 117 110 118 - static struct i2c_algorithm smbus_algorithm = { 111 + static const struct i2c_algorithm smbus_algorithm = { 119 112 .functionality = stub_func, 120 113 .smbus_xfer = stub_xfer, 121 114 }; ··· 129 122 130 123 static int __init i2c_stub_init(void) 131 124 { 132 - printk(KERN_INFO "i2c-stub loaded\n"); 125 + if (!chip_addr) { 126 + printk(KERN_ERR "i2c-stub: Please specify a chip address\n"); 127 + return -ENODEV; 128 + } 129 + if (chip_addr < 0x03 || chip_addr > 0x77) { 130 + printk(KERN_ERR "i2c-stub: Invalid chip address 0x%02x\n", 131 + chip_addr); 132 + return -EINVAL; 133 + } 134 + 135 + printk(KERN_INFO "i2c-stub: Virtual chip at 0x%02x\n", chip_addr); 133 136 return i2c_add_adapter(&stub_adapter); 134 137 } 135 138
-1
drivers/i2c/busses/i2c-via.c
··· 81 81 .getsda = bit_via_getsda, 82 82 .getscl = bit_via_getscl, 83 83 .udelay = 5, 84 - .mdelay = 5, 85 84 .timeout = HZ 86 85 }; 87 86
+9 -1
drivers/i2c/busses/i2c-viapro.c
··· 34 34 VT8233A 0x3147 yes? 35 35 VT8235 0x3177 yes 36 36 VT8237R 0x3227 yes 37 + VT8237A 0x3337 yes 38 + VT8251 0x3287 yes 37 39 38 40 Note: we assume there can only be one device, with one SMBus interface. 39 41 */ ··· 299 297 return func; 300 298 } 301 299 302 - static struct i2c_algorithm smbus_algorithm = { 300 + static const struct i2c_algorithm smbus_algorithm = { 303 301 .smbus_xfer = vt596_access, 304 302 .functionality = vt596_func, 305 303 }; ··· 383 381 dev_dbg(&pdev->dev, "VT596_smba = 0x%X\n", vt596_smba); 384 382 385 383 switch (pdev->device) { 384 + case PCI_DEVICE_ID_VIA_8251: 386 385 case PCI_DEVICE_ID_VIA_8237: 386 + case PCI_DEVICE_ID_VIA_8237A: 387 387 case PCI_DEVICE_ID_VIA_8235: 388 388 case PCI_DEVICE_ID_VIA_8233A: 389 389 case PCI_DEVICE_ID_VIA_8233_0: ··· 436 432 .driver_data = SMBBA3 }, 437 433 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237), 438 434 .driver_data = SMBBA3 }, 435 + { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237A), 436 + .driver_data = SMBBA3 }, 439 437 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8231_4), 440 438 .driver_data = SMBBA1 }, 439 + { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8251), 440 + .driver_data = SMBBA3 }, 441 441 { 0, } 442 442 }; 443 443
-2
drivers/i2c/busses/i2c-voodoo3.c
··· 160 160 .getsda = bit_vooi2c_getsda, 161 161 .getscl = bit_vooi2c_getscl, 162 162 .udelay = CYCLE_DELAY, 163 - .mdelay = CYCLE_DELAY, 164 163 .timeout = TIMEOUT 165 164 }; 166 165 ··· 176 177 .getsda = bit_vooddc_getsda, 177 178 .getscl = bit_vooddc_getscl, 178 179 .udelay = CYCLE_DELAY, 179 - .mdelay = CYCLE_DELAY, 180 180 .timeout = TIMEOUT 181 181 }; 182 182
+1 -1
drivers/i2c/busses/scx200_acb.c
··· 383 383 } 384 384 385 385 /* For now, we only handle combined mode (smbus) */ 386 - static struct i2c_algorithm scx200_acb_algorithm = { 386 + static const struct i2c_algorithm scx200_acb_algorithm = { 387 387 .smbus_xfer = scx200_acb_smbus_xfer, 388 388 .functionality = scx200_acb_func, 389 389 };
+6 -6
drivers/i2c/busses/scx200_i2c.c
··· 71 71 */ 72 72 73 73 static struct i2c_algo_bit_data scx200_i2c_data = { 74 - NULL, 75 - scx200_i2c_setsda, 76 - scx200_i2c_setscl, 77 - scx200_i2c_getsda, 78 - scx200_i2c_getscl, 79 - 10, 10, 100, /* waits, timeout */ 74 + .setsda = scx200_i2c_setsda, 75 + .setscl = scx200_i2c_setscl, 76 + .getsda = scx200_i2c_getsda, 77 + .getscl = scx200_i2c_getscl, 78 + .udelay = 10, 79 + .timeout = 100, 80 80 }; 81 81 82 82 static struct i2c_adapter scx200_i2c_ops = {
+7 -1
drivers/i2c/chips/eeprom.c
··· 209 209 } 210 210 211 211 /* create the sysfs eeprom file */ 212 - sysfs_create_bin_file(&new_client->dev.kobj, &eeprom_attr); 212 + err = sysfs_create_bin_file(&new_client->dev.kobj, &eeprom_attr); 213 + if (err) 214 + goto exit_detach; 213 215 214 216 return 0; 215 217 218 + exit_detach: 219 + i2c_detach_client(new_client); 216 220 exit_kfree: 217 221 kfree(data); 218 222 exit: ··· 226 222 static int eeprom_detach_client(struct i2c_client *client) 227 223 { 228 224 int err; 225 + 226 + sysfs_remove_bin_file(&client->dev.kobj, &eeprom_attr); 229 227 230 228 err = i2c_detach_client(client); 231 229 if (err)
+19 -6
drivers/i2c/chips/max6875.c
··· 199 199 mutex_init(&data->update_lock); 200 200 201 201 /* Init fake client data */ 202 - /* set the client data to the i2c_client so that it will get freed */ 203 - i2c_set_clientdata(fake_client, fake_client); 202 + i2c_set_clientdata(fake_client, NULL); 204 203 fake_client->addr = address | 1; 205 204 fake_client->adapter = adapter; 206 205 fake_client->driver = &max6875_driver; ··· 213 214 goto exit_kfree2; 214 215 215 216 if ((err = i2c_attach_client(fake_client)) != 0) 216 - goto exit_detach; 217 + goto exit_detach1; 217 218 218 - sysfs_create_bin_file(&real_client->dev.kobj, &user_eeprom_attr); 219 + err = sysfs_create_bin_file(&real_client->dev.kobj, &user_eeprom_attr); 220 + if (err) 221 + goto exit_detach2; 219 222 220 223 return 0; 221 224 222 - exit_detach: 225 + exit_detach2: 226 + i2c_detach_client(fake_client); 227 + exit_detach1: 223 228 i2c_detach_client(real_client); 224 229 exit_kfree2: 225 230 kfree(fake_client); ··· 232 229 return err; 233 230 } 234 231 232 + /* Will be called for both the real client and the fake client */ 235 233 static int max6875_detach_client(struct i2c_client *client) 236 234 { 237 235 int err; 236 + struct max6875_data *data = i2c_get_clientdata(client); 237 + 238 + /* data is NULL for the fake client */ 239 + if (data) 240 + sysfs_remove_bin_file(&client->dev.kobj, &user_eeprom_attr); 238 241 239 242 err = i2c_detach_client(client); 240 243 if (err) 241 244 return err; 242 - kfree(i2c_get_clientdata(client)); 245 + 246 + if (data) /* real client */ 247 + kfree(data); 248 + else /* fake client */ 249 + kfree(client); 243 250 return 0; 244 251 } 245 252
+9 -2
drivers/i2c/chips/pca9539.c
··· 148 148 if ((err = i2c_attach_client(new_client))) 149 149 goto exit_kfree; 150 150 151 - /* Register sysfs hooks (don't care about failure) */ 152 - sysfs_create_group(&new_client->dev.kobj, &pca9539_defattr_group); 151 + /* Register sysfs hooks */ 152 + err = sysfs_create_group(&new_client->dev.kobj, 153 + &pca9539_defattr_group); 154 + if (err) 155 + goto exit_detach; 153 156 154 157 return 0; 155 158 159 + exit_detach: 160 + i2c_detach_client(new_client); 156 161 exit_kfree: 157 162 kfree(data); 158 163 exit: ··· 167 162 static int pca9539_detach_client(struct i2c_client *client) 168 163 { 169 164 int err; 165 + 166 + sysfs_remove_group(&client->dev.kobj, &pca9539_defattr_group); 170 167 171 168 if ((err = i2c_detach_client(client))) 172 169 return err;
+17 -5
drivers/i2c/chips/pcf8574.c
··· 105 105 106 106 static DEVICE_ATTR(write, S_IWUSR | S_IRUGO, show_write, set_write); 107 107 108 + static struct attribute *pcf8574_attributes[] = { 109 + &dev_attr_read.attr, 110 + &dev_attr_write.attr, 111 + NULL 112 + }; 113 + 114 + static const struct attribute_group pcf8574_attr_group = { 115 + .attrs = pcf8574_attributes, 116 + }; 117 + 108 118 /* 109 119 * Real code 110 120 */ ··· 176 166 pcf8574_init_client(new_client); 177 167 178 168 /* Register sysfs hooks */ 179 - device_create_file(&new_client->dev, &dev_attr_read); 180 - device_create_file(&new_client->dev, &dev_attr_write); 169 + err = sysfs_create_group(&new_client->dev.kobj, &pcf8574_attr_group); 170 + if (err) 171 + goto exit_detach; 181 172 return 0; 182 173 183 - /* OK, this is not exactly good programming practice, usually. But it is 184 - very code-efficient in this case. */ 185 - 174 + exit_detach: 175 + i2c_detach_client(new_client); 186 176 exit_free: 187 177 kfree(data); 188 178 exit: ··· 192 182 static int pcf8574_detach_client(struct i2c_client *client) 193 183 { 194 184 int err; 185 + 186 + sysfs_remove_group(&client->dev.kobj, &pcf8574_attr_group); 195 187 196 188 if ((err = i2c_detach_client(client))) 197 189 return err;
+47 -15
drivers/i2c/chips/pcf8591.c
··· 158 158 static DEVICE_ATTR(out0_enable, S_IWUSR | S_IRUGO, 159 159 show_out0_enable, set_out0_enable); 160 160 161 + static struct attribute *pcf8591_attributes[] = { 162 + &dev_attr_out0_enable.attr, 163 + &dev_attr_out0_output.attr, 164 + &dev_attr_in0_input.attr, 165 + &dev_attr_in1_input.attr, 166 + NULL 167 + }; 168 + 169 + static const struct attribute_group pcf8591_attr_group = { 170 + .attrs = pcf8591_attributes, 171 + }; 172 + 173 + static struct attribute *pcf8591_attributes_opt[] = { 174 + &dev_attr_in2_input.attr, 175 + &dev_attr_in3_input.attr, 176 + NULL 177 + }; 178 + 179 + static const struct attribute_group pcf8591_attr_group_opt = { 180 + .attrs = pcf8591_attributes_opt, 181 + }; 182 + 161 183 /* 162 184 * Real code 163 185 */ ··· 233 211 pcf8591_init_client(new_client); 234 212 235 213 /* Register sysfs hooks */ 236 - device_create_file(&new_client->dev, &dev_attr_out0_enable); 237 - device_create_file(&new_client->dev, &dev_attr_out0_output); 238 - device_create_file(&new_client->dev, &dev_attr_in0_input); 239 - device_create_file(&new_client->dev, &dev_attr_in1_input); 214 + err = sysfs_create_group(&new_client->dev.kobj, &pcf8591_attr_group); 215 + if (err) 216 + goto exit_detach; 240 217 241 218 /* Register input2 if not in "two differential inputs" mode */ 242 - if (input_mode != 3 ) 243 - device_create_file(&new_client->dev, &dev_attr_in2_input); 244 - 245 - /* Register input3 only in "four single ended inputs" mode */ 246 - if (input_mode == 0) 247 - device_create_file(&new_client->dev, &dev_attr_in3_input); 248 - 249 - return 0; 250 - 251 - /* OK, this is not exactly good programming practice, usually. But it is 252 - very code-efficient in this case. */ 219 + if (input_mode != 3) { 220 + if ((err = device_create_file(&new_client->dev, 221 + &dev_attr_in2_input))) 222 + goto exit_sysfs_remove; 223 + } 253 224 225 + /* Register input3 only in "four single ended inputs" mode */ 226 + if (input_mode == 0) { 227 + if ((err = device_create_file(&new_client->dev, 228 + &dev_attr_in3_input))) 229 + goto exit_sysfs_remove; 230 + } 231 + 232 + return 0; 233 + 234 + exit_sysfs_remove: 235 + sysfs_remove_group(&new_client->dev.kobj, &pcf8591_attr_group_opt); 236 + sysfs_remove_group(&new_client->dev.kobj, &pcf8591_attr_group); 237 + exit_detach: 238 + i2c_detach_client(new_client); 254 239 exit_kfree: 255 240 kfree(data); 256 241 exit: ··· 267 238 static int pcf8591_detach_client(struct i2c_client *client) 268 239 { 269 240 int err; 241 + 242 + sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group_opt); 243 + sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group); 270 244 271 245 if ((err = i2c_detach_client(client))) 272 246 return err;
+55 -17
drivers/i2c/i2c-core.c
··· 183 183 sprintf(adap->dev.bus_id, "i2c-%d", adap->nr); 184 184 adap->dev.driver = &i2c_adapter_driver; 185 185 adap->dev.release = &i2c_adapter_dev_release; 186 - device_register(&adap->dev); 187 - device_create_file(&adap->dev, &dev_attr_name); 186 + res = device_register(&adap->dev); 187 + if (res) 188 + goto out_list; 189 + res = device_create_file(&adap->dev, &dev_attr_name); 190 + if (res) 191 + goto out_unregister; 188 192 189 193 /* Add this adapter to the i2c_adapter class */ 190 194 memset(&adap->class_dev, 0x00, sizeof(struct class_device)); 191 195 adap->class_dev.dev = &adap->dev; 192 196 adap->class_dev.class = &i2c_adapter_class; 193 197 strlcpy(adap->class_dev.class_id, adap->dev.bus_id, BUS_ID_SIZE); 194 - class_device_register(&adap->class_dev); 198 + res = class_device_register(&adap->class_dev); 199 + if (res) 200 + goto out_remove_name; 195 201 196 202 dev_dbg(&adap->dev, "adapter [%s] registered\n", adap->name); 197 203 ··· 212 206 out_unlock: 213 207 mutex_unlock(&core_lists); 214 208 return res; 209 + 210 + out_remove_name: 211 + device_remove_file(&adap->dev, &dev_attr_name); 212 + out_unregister: 213 + init_completion(&adap->dev_released); /* Needed? */ 214 + device_unregister(&adap->dev); 215 + wait_for_completion(&adap->dev_released); 216 + out_list: 217 + list_del(&adap->list); 218 + idr_remove(&i2c_adapter_idr, adap->nr); 219 + goto out_unlock; 215 220 } 216 221 217 222 ··· 411 394 int i2c_attach_client(struct i2c_client *client) 412 395 { 413 396 struct i2c_adapter *adapter = client->adapter; 397 + int res = 0; 414 398 415 399 mutex_lock(&adapter->clist_lock); 416 400 if (__i2c_check_addr(client->adapter, client->addr)) { 417 - mutex_unlock(&adapter->clist_lock); 418 - return -EBUSY; 401 + res = -EBUSY; 402 + goto out_unlock; 419 403 } 420 404 list_add_tail(&client->list,&adapter->clients); 421 - mutex_unlock(&adapter->clist_lock); 422 405 423 406 if (adapter->client_register) { 424 407 if (adapter->client_register(client)) { ··· 439 422 "%d-%04x", i2c_adapter_id(adapter), client->addr); 440 423 dev_dbg(&adapter->dev, "client [%s] registered with bus id %s\n", 441 424 client->name, client->dev.bus_id); 442 - device_register(&client->dev); 443 - device_create_file(&client->dev, &dev_attr_client_name); 444 - 445 - return 0; 425 + res = device_register(&client->dev); 426 + if (res) 427 + goto out_list; 428 + res = device_create_file(&client->dev, &dev_attr_client_name); 429 + if (res) 430 + goto out_unregister; 431 + 432 + out_unlock: 433 + mutex_unlock(&adapter->clist_lock); 434 + return res; 435 + 436 + out_unregister: 437 + init_completion(&client->released); /* Needed? */ 438 + device_unregister(&client->dev); 439 + wait_for_completion(&client->released); 440 + out_list: 441 + list_del(&client->list); 442 + dev_err(&adapter->dev, "Failed to attach i2c client %s at 0x%02x " 443 + "(%d)\n", client->name, client->addr, res); 444 + goto out_unlock; 446 445 } 447 446 448 447 ··· 707 674 708 675 /* Finally call the custom detection function */ 709 676 err = found_proc(adapter, addr, kind); 710 - 711 677 /* -ENODEV can be returned if there is a chip at the given address 712 678 but it isn't supported by this chip driver. We catch it here as 713 679 this isn't an error. */ 714 - return (err == -ENODEV) ? 0 : err; 680 + if (err == -ENODEV) 681 + err = 0; 682 + 683 + if (err) 684 + dev_warn(&adapter->dev, "Client creation failed at 0x%x (%d)\n", 685 + addr, err); 686 + return err; 715 687 } 716 688 717 689 int i2c_probe(struct i2c_adapter *adapter, ··· 906 868 I2C_SMBUS_READ,0,I2C_SMBUS_BYTE, &data)) 907 869 return -1; 908 870 else 909 - return 0x0FF & data.byte; 871 + return data.byte; 910 872 } 911 873 912 874 s32 i2c_smbus_write_byte(struct i2c_client *client, u8 value) ··· 922 884 I2C_SMBUS_READ,command, I2C_SMBUS_BYTE_DATA,&data)) 923 885 return -1; 924 886 else 925 - return 0x0FF & data.byte; 887 + return data.byte; 926 888 } 927 889 928 890 s32 i2c_smbus_write_byte_data(struct i2c_client *client, u8 command, u8 value) ··· 941 903 I2C_SMBUS_READ,command, I2C_SMBUS_WORD_DATA, &data)) 942 904 return -1; 943 905 else 944 - return 0x0FFFF & data.word; 906 + return data.word; 945 907 } 946 908 947 909 s32 i2c_smbus_write_word_data(struct i2c_client *client, u8 command, u16 value) ··· 1044 1006 else { 1045 1007 msg[0].len=3; 1046 1008 msgbuf0[1] = data->word & 0xff; 1047 - msgbuf0[2] = (data->word >> 8) & 0xff; 1009 + msgbuf0[2] = data->word >> 8; 1048 1010 } 1049 1011 break; 1050 1012 case I2C_SMBUS_PROC_CALL: ··· 1053 1015 msg[0].len = 3; 1054 1016 msg[1].len = 2; 1055 1017 msgbuf0[1] = data->word & 0xff; 1056 - msgbuf0[2] = (data->word >> 8) & 0xff; 1018 + msgbuf0[2] = data->word >> 8; 1057 1019 break; 1058 1020 case I2C_SMBUS_BLOCK_DATA: 1059 1021 if (read_write == I2C_SMBUS_READ) {
+50 -59
drivers/i2c/i2c-dev.c
··· 32 32 #include <linux/slab.h> 33 33 #include <linux/smp_lock.h> 34 34 #include <linux/init.h> 35 + #include <linux/list.h> 35 36 #include <linux/i2c.h> 36 37 #include <linux/i2c-dev.h> 37 - #include <linux/platform_device.h> 38 38 #include <asm/uaccess.h> 39 39 40 - static struct i2c_client i2cdev_client_template; 40 + static struct i2c_driver i2cdev_driver; 41 41 42 42 struct i2c_dev { 43 - int minor; 43 + struct list_head list; 44 44 struct i2c_adapter *adap; 45 45 struct class_device *class_dev; 46 46 }; 47 - #define to_i2c_dev(d) container_of(d, struct i2c_dev, class_dev) 48 47 49 48 #define I2C_MINORS 256 50 - static struct i2c_dev *i2c_dev_array[I2C_MINORS]; 51 - static DEFINE_SPINLOCK(i2c_dev_array_lock); 49 + static LIST_HEAD(i2c_dev_list); 50 + static DEFINE_SPINLOCK(i2c_dev_list_lock); 52 51 53 52 static struct i2c_dev *i2c_dev_get_by_minor(unsigned index) 54 53 { 55 54 struct i2c_dev *i2c_dev; 56 55 57 - spin_lock(&i2c_dev_array_lock); 58 - i2c_dev = i2c_dev_array[index]; 59 - spin_unlock(&i2c_dev_array_lock); 60 - return i2c_dev; 61 - } 62 - 63 - static struct i2c_dev *i2c_dev_get_by_adapter(struct i2c_adapter *adap) 64 - { 65 - struct i2c_dev *i2c_dev = NULL; 66 - 67 - spin_lock(&i2c_dev_array_lock); 68 - if ((i2c_dev_array[adap->nr]) && 69 - (i2c_dev_array[adap->nr]->adap == adap)) 70 - i2c_dev = i2c_dev_array[adap->nr]; 71 - spin_unlock(&i2c_dev_array_lock); 56 + spin_lock(&i2c_dev_list_lock); 57 + list_for_each_entry(i2c_dev, &i2c_dev_list, list) { 58 + if (i2c_dev->adap->nr == index) 59 + goto found; 60 + } 61 + i2c_dev = NULL; 62 + found: 63 + spin_unlock(&i2c_dev_list_lock); 72 64 return i2c_dev; 73 65 } 74 66 ··· 68 76 { 69 77 struct i2c_dev *i2c_dev; 70 78 79 + if (adap->nr >= I2C_MINORS) { 80 + printk(KERN_ERR "i2c-dev: Out of device minors (%d)\n", 81 + adap->nr); 82 + return ERR_PTR(-ENODEV); 83 + } 84 + 71 85 i2c_dev = kzalloc(sizeof(*i2c_dev), GFP_KERNEL); 72 86 if (!i2c_dev) 73 87 return ERR_PTR(-ENOMEM); 88 + i2c_dev->adap = adap; 74 89 75 - spin_lock(&i2c_dev_array_lock); 76 - if (i2c_dev_array[adap->nr]) { 77 - spin_unlock(&i2c_dev_array_lock); 78 - dev_err(&adap->dev, "i2c-dev already has a device assigned to this adapter\n"); 79 - goto error; 80 - } 81 - i2c_dev->minor = adap->nr; 82 - i2c_dev_array[adap->nr] = i2c_dev; 83 - spin_unlock(&i2c_dev_array_lock); 90 + spin_lock(&i2c_dev_list_lock); 91 + list_add_tail(&i2c_dev->list, &i2c_dev_list); 92 + spin_unlock(&i2c_dev_list_lock); 84 93 return i2c_dev; 85 - error: 86 - kfree(i2c_dev); 87 - return ERR_PTR(-ENODEV); 88 94 } 89 95 90 96 static void return_i2c_dev(struct i2c_dev *i2c_dev) 91 97 { 92 - spin_lock(&i2c_dev_array_lock); 93 - i2c_dev_array[i2c_dev->minor] = NULL; 94 - spin_unlock(&i2c_dev_array_lock); 98 + spin_lock(&i2c_dev_list_lock); 99 + list_del(&i2c_dev->list); 100 + spin_unlock(&i2c_dev_list_lock); 95 101 } 96 102 97 103 static ssize_t show_adapter_name(struct class_device *class_dev, char *buf) ··· 365 375 if (!adap) 366 376 return -ENODEV; 367 377 368 - client = kmalloc(sizeof(*client), GFP_KERNEL); 378 + client = kzalloc(sizeof(*client), GFP_KERNEL); 369 379 if (!client) { 370 380 i2c_put_adapter(adap); 371 381 return -ENOMEM; 372 382 } 373 - memcpy(client, &i2cdev_client_template, sizeof(*client)); 383 + snprintf(client->name, I2C_NAME_SIZE, "i2c-dev %d", adap->nr); 384 + client->driver = &i2cdev_driver; 374 385 375 386 /* registered with adapter, passed as client to user */ 376 387 client->adapter = adap; ··· 406 415 static int i2cdev_attach_adapter(struct i2c_adapter *adap) 407 416 { 408 417 struct i2c_dev *i2c_dev; 409 - struct device *dev; 418 + int res; 410 419 411 420 i2c_dev = get_free_i2c_dev(adap); 412 421 if (IS_ERR(i2c_dev)) 413 422 return PTR_ERR(i2c_dev); 414 423 415 - pr_debug("i2c-dev: adapter [%s] registered as minor %d\n", 416 - adap->name, i2c_dev->minor); 417 - 418 424 /* register this i2c device with the driver core */ 419 - i2c_dev->adap = adap; 420 - dev = &adap->dev; 421 425 i2c_dev->class_dev = class_device_create(i2c_dev_class, NULL, 422 - MKDEV(I2C_MAJOR, i2c_dev->minor), 423 - dev, "i2c-%d", i2c_dev->minor); 424 - if (!i2c_dev->class_dev) 426 + MKDEV(I2C_MAJOR, adap->nr), 427 + &adap->dev, "i2c-%d", 428 + adap->nr); 429 + if (!i2c_dev->class_dev) { 430 + res = -ENODEV; 425 431 goto error; 426 - class_device_create_file(i2c_dev->class_dev, &class_device_attr_name); 432 + } 433 + res = class_device_create_file(i2c_dev->class_dev, &class_device_attr_name); 434 + if (res) 435 + goto error_destroy; 436 + 437 + pr_debug("i2c-dev: adapter [%s] registered as minor %d\n", 438 + adap->name, adap->nr); 427 439 return 0; 440 + error_destroy: 441 + class_device_destroy(i2c_dev_class, MKDEV(I2C_MAJOR, adap->nr)); 428 442 error: 429 443 return_i2c_dev(i2c_dev); 430 444 kfree(i2c_dev); 431 - return -ENODEV; 445 + return res; 432 446 } 433 447 434 448 static int i2cdev_detach_adapter(struct i2c_adapter *adap) 435 449 { 436 450 struct i2c_dev *i2c_dev; 437 451 438 - i2c_dev = i2c_dev_get_by_adapter(adap); 439 - if (!i2c_dev) 440 - return -ENODEV; 452 + i2c_dev = i2c_dev_get_by_minor(adap->nr); 453 + if (!i2c_dev) /* attach_adapter must have failed */ 454 + return 0; 441 455 456 + class_device_remove_file(i2c_dev->class_dev, &class_device_attr_name); 442 457 return_i2c_dev(i2c_dev); 443 - class_device_destroy(i2c_dev_class, MKDEV(I2C_MAJOR, i2c_dev->minor)); 458 + class_device_destroy(i2c_dev_class, MKDEV(I2C_MAJOR, adap->nr)); 444 459 kfree(i2c_dev); 445 460 446 461 pr_debug("i2c-dev: adapter [%s] unregistered\n", adap->name); ··· 466 469 .attach_adapter = i2cdev_attach_adapter, 467 470 .detach_adapter = i2cdev_detach_adapter, 468 471 .detach_client = i2cdev_detach_client, 469 - }; 470 - 471 - static struct i2c_client i2cdev_client_template = { 472 - .name = "I2C /dev entry", 473 - .addr = -1, 474 - .driver = &i2cdev_driver, 475 472 }; 476 473 477 474 static int __init i2c_dev_init(void)
-1
drivers/ieee1394/pcilynx.c
··· 137 137 .getsda = bit_getsda, 138 138 .getscl = bit_getscl, 139 139 .udelay = 5, 140 - .mdelay = 5, 141 140 .timeout = 100, 142 141 }; 143 142
-1
drivers/media/video/bt8xx/bttv-i2c.c
··· 100 100 .getsda = bttv_bit_getsda, 101 101 .getscl = bttv_bit_getscl, 102 102 .udelay = 16, 103 - .mdelay = 10, 104 103 .timeout = 200, 105 104 }; 106 105
-1
drivers/media/video/cx88/cx88-i2c.c
··· 155 155 .getsda = cx8800_bit_getsda, 156 156 .getscl = cx8800_bit_getscl, 157 157 .udelay = 16, 158 - .mdelay = 10, 159 158 .timeout = 200, 160 159 }; 161 160
-1
drivers/media/video/cx88/cx88-vp3054-i2c.c
··· 100 100 .getsda = vp3054_bit_getsda, 101 101 .getscl = vp3054_bit_getscl, 102 102 .udelay = 16, 103 - .mdelay = 10, 104 103 .timeout = 200, 105 104 }; 106 105
-1
drivers/media/video/zoran_card.c
··· 820 820 .getsda = zoran_i2c_getsda, 821 821 .getscl = zoran_i2c_getscl, 822 822 .udelay = 10, 823 - .mdelay = 0, 824 823 .timeout = 100, 825 824 }; 826 825
-1
drivers/video/i810/i810-i2c.c
··· 98 98 chan->algo.getsda = i810i2c_getsda; 99 99 chan->algo.getscl = i810i2c_getscl; 100 100 chan->algo.udelay = 10; 101 - chan->algo.mdelay = 10; 102 101 chan->algo.timeout = (HZ/2); 103 102 chan->algo.data = chan; 104 103
+6 -6
drivers/video/matrox/i2c-matroxfb.c
··· 95 95 96 96 static struct i2c_algo_bit_data matrox_i2c_algo_template = 97 97 { 98 - NULL, 99 - matroxfb_gpio_setsda, 100 - matroxfb_gpio_setscl, 101 - matroxfb_gpio_getsda, 102 - matroxfb_gpio_getscl, 103 - 10, 10, 100, 98 + .setsda = matroxfb_gpio_setsda, 99 + .setscl = matroxfb_gpio_setscl, 100 + .getsda = matroxfb_gpio_getsda, 101 + .getscl = matroxfb_gpio_getscl, 102 + .udelay = 10, 103 + .timeout = 100, 104 104 }; 105 105 106 106 static int i2c_bus_reg(struct i2c_bit_adapter* b, struct matrox_fb_info* minfo,
-1
drivers/video/savage/savagefb-i2c.c
··· 148 148 chan->adapter.algo_data = &chan->algo; 149 149 chan->adapter.dev.parent = &chan->par->pcidev->dev; 150 150 chan->algo.udelay = 40; 151 - chan->algo.mdelay = 5; 152 151 chan->algo.timeout = 20; 153 152 chan->algo.data = chan; 154 153
-1
include/linux/i2c-algo-bit.h
··· 40 40 /* local settings */ 41 41 int udelay; /* half-clock-cycle time in microsecs */ 42 42 /* i.e. clock is (500 / udelay) KHz */ 43 - int mdelay; /* in millisecs, unused */ 44 43 int timeout; /* in jiffies */ 45 44 }; 46 45
-1
include/linux/i2c-algo-pcf.h
··· 35 35 36 36 /* local settings */ 37 37 int udelay; 38 - int mdelay; 39 38 int timeout; 40 39 }; 41 40
-33
include/linux/i2c-algo-sibyte.h
··· 1 - /* 2 - * Copyright (C) 2001,2002,2003 Broadcom Corporation 3 - * 4 - * This program is free software; you can redistribute it and/or 5 - * modify it under the terms of the GNU General Public License 6 - * as published by the Free Software Foundation; either version 2 7 - * of the License, or (at your option) any later version. 8 - * 9 - * This program is distributed in the hope that it will be useful, 10 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 - * GNU General Public License for more details. 13 - * 14 - * You should have received a copy of the GNU General Public License 15 - * along with this program; if not, write to the Free Software 16 - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 - */ 18 - 19 - #ifndef I2C_ALGO_SIBYTE_H 20 - #define I2C_ALGO_SIBYTE_H 1 21 - 22 - #include <linux/i2c.h> 23 - 24 - struct i2c_algo_sibyte_data { 25 - void *data; /* private data */ 26 - int bus; /* which bus */ 27 - void *reg_base; /* CSR base */ 28 - }; 29 - 30 - int i2c_sibyte_add_bus(struct i2c_adapter *, int speed); 31 - int i2c_sibyte_del_bus(struct i2c_adapter *); 32 - 33 - #endif /* I2C_ALGO_SIBYTE_H */
+1 -13
include/linux/i2c.h
··· 64 64 */ 65 65 extern int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num); 66 66 67 - /* 68 - * Some adapter types (i.e. PCF 8584 based ones) may support slave behaviuor. 69 - * This is not tested/implemented yet and will change in the future. 70 - */ 71 - extern int i2c_slave_send(struct i2c_client *,char*,int); 72 - extern int i2c_slave_recv(struct i2c_client *,char*,int); 73 - 74 - 75 67 76 68 /* This is the very generalized SMBus access routine. You probably do not 77 69 want to use this, though; one of the functions below may be much easier, ··· 193 201 unsigned short flags, char read_write, 194 202 u8 command, int size, union i2c_smbus_data * data); 195 203 196 - /* --- these optional/future use for some adapter types.*/ 197 - int (*slave_send)(struct i2c_adapter *,char*,int); 198 - int (*slave_recv)(struct i2c_adapter *,char*,int); 199 - 200 204 /* --- ioctl like call to set div. parameters. */ 201 205 int (*algo_control)(struct i2c_adapter *, unsigned int, unsigned long); 202 206 ··· 208 220 struct module *owner; 209 221 unsigned int id; 210 222 unsigned int class; 211 - struct i2c_algorithm *algo;/* the algorithm to access the bus */ 223 + const struct i2c_algorithm *algo; /* the algorithm to access the bus */ 212 224 void *algo_data; 213 225 214 226 /* --- administration stuff. */