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

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'i2c/for-current' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux

Pull i2c fixes from Wolfram Sang:

- two driver fixes

- better parameter check for the core

- Documentation updates

- part of a tree-wide HAS_DMA cleanup

* 'i2c/for-current' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux:
i2c: sprd: Fix the i2c count issue
i2c: sprd: Prevent i2c accesses after suspend is called
i2c: dev: prevent ZERO_SIZE_PTR deref in i2cdev_ioctl_rdwr()
Documentation/i2c: adopt kernel commenting style in examples
Documentation/i2c: sync docs with current state of i2c-tools
Documentation/i2c: whitespace cleanup
i2c: Remove depends on HAS_DMA in case of platform dependency

+33 -26
+14 -18
Documentation/i2c/dev-interface
··· 9 9 the i2c-tools package. 10 10 11 11 I2C device files are character device files with major device number 89 12 - and a minor device number corresponding to the number assigned as 13 - explained above. They should be called "i2c-%d" (i2c-0, i2c-1, ..., 12 + and a minor device number corresponding to the number assigned as 13 + explained above. They should be called "i2c-%d" (i2c-0, i2c-1, ..., 14 14 i2c-10, ...). All 256 minor device numbers are reserved for i2c. 15 15 16 16 ··· 23 23 #include <linux/i2c-dev.h> 24 24 #include <i2c/smbus.h> 25 25 26 - (Please note that there are two files named "i2c-dev.h" out there. One is 27 - distributed with the Linux kernel and the other one is included in the 28 - source tree of i2c-tools. They used to be different in content but since 2012 29 - they're identical. You should use "linux/i2c-dev.h"). 30 - 31 26 Now, you have to decide which adapter you want to access. You should 32 27 inspect /sys/class/i2c-dev/ or run "i2cdetect -l" to decide this. 33 28 Adapter numbers are assigned somewhat dynamically, so you can not ··· 33 38 int file; 34 39 int adapter_nr = 2; /* probably dynamically determined */ 35 40 char filename[20]; 36 - 41 + 37 42 snprintf(filename, 19, "/dev/i2c-%d", adapter_nr); 38 43 file = open(filename, O_RDWR); 39 44 if (file < 0) { ··· 67 72 /* res contains the read word */ 68 73 } 69 74 70 - /* Using I2C Write, equivalent of 71 - i2c_smbus_write_word_data(file, reg, 0x6543) */ 75 + /* 76 + * Using I2C Write, equivalent of 77 + * i2c_smbus_write_word_data(file, reg, 0x6543) 78 + */ 72 79 buf[0] = reg; 73 80 buf[1] = 0x43; 74 81 buf[2] = 0x65; ··· 137 140 set in each message, overriding the values set with the above ioctl's. 138 141 139 142 ioctl(file, I2C_SMBUS, struct i2c_smbus_ioctl_data *args) 140 - Not meant to be called directly; instead, use the access functions 141 - below. 143 + If possible, use the provided i2c_smbus_* methods described below instead 144 + of issuing direct ioctls. 142 145 143 146 You can do plain i2c transactions by using read(2) and write(2) calls. 144 147 You do not need to pass the address byte; instead, set it through 145 148 ioctl I2C_SLAVE before you try to access the device. 146 149 147 - You can do SMBus level transactions (see documentation file smbus-protocol 150 + You can do SMBus level transactions (see documentation file smbus-protocol 148 151 for details) through the following functions: 149 152 __s32 i2c_smbus_write_quick(int file, __u8 value); 150 153 __s32 i2c_smbus_read_byte(int file); ··· 155 158 __s32 i2c_smbus_write_word_data(int file, __u8 command, __u16 value); 156 159 __s32 i2c_smbus_process_call(int file, __u8 command, __u16 value); 157 160 __s32 i2c_smbus_read_block_data(int file, __u8 command, __u8 *values); 158 - __s32 i2c_smbus_write_block_data(int file, __u8 command, __u8 length, 161 + __s32 i2c_smbus_write_block_data(int file, __u8 command, __u8 length, 159 162 __u8 *values); 160 163 All these transactions return -1 on failure; you can read errno to see 161 164 what happened. The 'write' transactions return 0 on success; the ··· 163 166 returns the number of values read. The block buffers need not be longer 164 167 than 32 bytes. 165 168 166 - The above functions are all inline functions, that resolve to calls to 167 - the i2c_smbus_access function, that on its turn calls a specific ioctl 168 - with the data in a specific format. Read the source code if you 169 - want to know what happens behind the screens. 169 + The above functions are made available by linking against the libi2c library, 170 + which is provided by the i2c-tools project. See: 171 + https://git.kernel.org/pub/scm/utils/i2c-tools/i2c-tools.git/. 170 172 171 173 172 174 Implementation details
-3
drivers/i2c/busses/Kconfig
··· 707 707 config I2C_MT65XX 708 708 tristate "MediaTek I2C adapter" 709 709 depends on ARCH_MEDIATEK || COMPILE_TEST 710 - depends on HAS_DMA 711 710 help 712 711 This selects the MediaTek(R) Integrated Inter Circuit bus driver 713 712 for MT65xx and MT81xx. ··· 884 885 885 886 config I2C_SH_MOBILE 886 887 tristate "SuperH Mobile I2C Controller" 887 - depends on HAS_DMA 888 888 depends on ARCH_SHMOBILE || ARCH_RENESAS || COMPILE_TEST 889 889 help 890 890 If you say yes to this option, support will be included for the ··· 1096 1098 1097 1099 config I2C_RCAR 1098 1100 tristate "Renesas R-Car I2C Controller" 1099 - depends on HAS_DMA 1100 1101 depends on ARCH_RENESAS || COMPILE_TEST 1101 1102 select I2C_SLAVE 1102 1103 help
+18 -4
drivers/i2c/busses/i2c-sprd.c
··· 86 86 u32 count; 87 87 int irq; 88 88 int err; 89 + bool is_suspended; 89 90 }; 90 91 91 92 static void sprd_i2c_set_count(struct sprd_i2c *i2c_dev, u32 count) ··· 284 283 struct sprd_i2c *i2c_dev = i2c_adap->algo_data; 285 284 int im, ret; 286 285 286 + if (i2c_dev->is_suspended) 287 + return -EBUSY; 288 + 287 289 ret = pm_runtime_get_sync(i2c_dev->dev); 288 290 if (ret < 0) 289 291 return ret; ··· 368 364 struct sprd_i2c *i2c_dev = dev_id; 369 365 struct i2c_msg *msg = i2c_dev->msg; 370 366 bool ack = !(readl(i2c_dev->base + I2C_STATUS) & I2C_RX_ACK); 371 - u32 i2c_count = readl(i2c_dev->base + I2C_COUNT); 372 367 u32 i2c_tran; 373 368 374 369 if (msg->flags & I2C_M_RD) 375 370 i2c_tran = i2c_dev->count >= I2C_FIFO_FULL_THLD; 376 371 else 377 - i2c_tran = i2c_count; 372 + i2c_tran = i2c_dev->count; 378 373 379 374 /* 380 375 * If we got one ACK from slave when writing data, and we did not ··· 411 408 { 412 409 struct sprd_i2c *i2c_dev = dev_id; 413 410 struct i2c_msg *msg = i2c_dev->msg; 414 - u32 i2c_count = readl(i2c_dev->base + I2C_COUNT); 415 411 bool ack = !(readl(i2c_dev->base + I2C_STATUS) & I2C_RX_ACK); 416 412 u32 i2c_tran; 417 413 418 414 if (msg->flags & I2C_M_RD) 419 415 i2c_tran = i2c_dev->count >= I2C_FIFO_FULL_THLD; 420 416 else 421 - i2c_tran = i2c_count; 417 + i2c_tran = i2c_dev->count; 422 418 423 419 /* 424 420 * If we did not get one ACK from slave when writing data, then we ··· 588 586 589 587 static int __maybe_unused sprd_i2c_suspend_noirq(struct device *pdev) 590 588 { 589 + struct sprd_i2c *i2c_dev = dev_get_drvdata(pdev); 590 + 591 + i2c_lock_adapter(&i2c_dev->adap); 592 + i2c_dev->is_suspended = true; 593 + i2c_unlock_adapter(&i2c_dev->adap); 594 + 591 595 return pm_runtime_force_suspend(pdev); 592 596 } 593 597 594 598 static int __maybe_unused sprd_i2c_resume_noirq(struct device *pdev) 595 599 { 600 + struct sprd_i2c *i2c_dev = dev_get_drvdata(pdev); 601 + 602 + i2c_lock_adapter(&i2c_dev->adap); 603 + i2c_dev->is_suspended = false; 604 + i2c_unlock_adapter(&i2c_dev->adap); 605 + 596 606 return pm_runtime_force_resume(pdev); 597 607 } 598 608
+1 -1
drivers/i2c/i2c-dev.c
··· 280 280 */ 281 281 if (msgs[i].flags & I2C_M_RECV_LEN) { 282 282 if (!(msgs[i].flags & I2C_M_RD) || 283 - msgs[i].buf[0] < 1 || 283 + msgs[i].len < 1 || msgs[i].buf[0] < 1 || 284 284 msgs[i].len < msgs[i].buf[0] + 285 285 I2C_SMBUS_BLOCK_MAX) { 286 286 res = -EINVAL;