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

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

Pull i2c updates from Wolfram Sang:
"I2C has the following updates for 3.16:

- major cleanups to the rcar and sh_mobile drivers
- removal of nuc900 driver which had a compile error for years
- usual bunch of driver updates, bugfixes and cleanups"

* 'i2c/for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux: (44 commits)
i2c: pca954x: Fix compilation without CONFIG_GPIOLIB
i2c: mux: pca954x: Use the descriptor-based GPIO API
i2c: mpc: insert DR read in i2c_fixup()
i2c: bfin: turn to Resource-managed API in probe function
i2c: Make of_device_id array const
i2c: remove unnecessary OOM messages
i2c: designware-pci: Add Haswell PCI IDs
i2c: designware: Add runtime PM hooks
i2c: designware: Disable device on system suspend
i2c: nuc900: remove driver
i2c: imx: update i2c clock divider for each transaction
i2c: imx: fix the i2c bus hang issue when do repeat restart
i2c: rcar: update copyright and license information
i2c: rcar: janitorial cleanup after refactoring
i2c: rcar: reuse status bits as enable bits
i2c: rcar: remove spinlock
i2c: rcar: refactor status bit handling
i2c: rcar: refactor setting up msg
i2c: rcar: check bus free before first message
i2c: rcar: refactor irq state machine
...

+506 -1297
+6
Documentation/devicetree/bindings/i2c/i2c-arb-gpio-challenge.txt
··· 8 8 the case where there is a device on the bus that has errata and/or bugs 9 9 that makes standard multimaster mode not feasible. 10 10 11 + Note that this scheme works well enough but has some downsides: 12 + * It is nonstandard (not using standard I2C multimaster) 13 + * Having two masters on a bus in general makes it relatively hard to debug 14 + problems (hard to tell if i2c issues were caused by one master, another, or 15 + some device on the bus). 16 + 11 17 12 18 Algorithm: 13 19
+9 -2
Documentation/devicetree/bindings/i2c/i2c-exynos5.txt
··· 5 5 6 6 Required properties: 7 7 - compatible: value should be. 8 - -> "samsung,exynos5-hsi2c", for i2c compatible with exynos5 hsi2c. 8 + -> "samsung,exynos5-hsi2c", (DEPRECATED) 9 + for i2c compatible with HSI2C available 10 + on Exynos5250 and Exynos5420 SoCs. 11 + -> "samsung,exynos5250-hsi2c", for i2c compatible with HSI2C available 12 + on Exynos5250 and Exynos5420 SoCs. 13 + -> "samsung,exynos5260-hsi2c", for i2c compatible with HSI2C available 14 + on Exynos5260 SoCs. 15 + 9 16 - reg: physical base address of the controller and length of memory mapped 10 17 region. 11 18 - interrupts: interrupt number to the cpu. ··· 33 26 Example: 34 27 35 28 hsi2c@12ca0000 { 36 - compatible = "samsung,exynos5-hsi2c"; 29 + compatible = "samsung,exynos5250-hsi2c"; 37 30 reg = <0x12ca0000 0x100>; 38 31 interrupts = <56>; 39 32 clock-frequency = <100000>;
+1 -1
Documentation/devicetree/bindings/i2c/i2c-mv64xxx.txt
··· 5 5 6 6 - reg : Offset and length of the register set for the device 7 7 - compatible : Should be either: 8 - - "allwinner,sun4i-i2c" 8 + - "allwinner,sun4i-a10-i2c" 9 9 - "allwinner,sun6i-a31-i2c" 10 10 - "marvell,mv64xxx-i2c" 11 11 - "marvell,mv78230-i2c"
+3
Documentation/devicetree/bindings/i2c/i2c-rcar.txt
··· 7 7 "renesas,i2c-r8a7779" 8 8 "renesas,i2c-r8a7790" 9 9 "renesas,i2c-r8a7791" 10 + "renesas,i2c-r8a7792" 11 + "renesas,i2c-r8a7793" 12 + "renesas,i2c-r8a7794" 10 13 - reg: physical base address of the controller and length of memory mapped 11 14 region. 12 15 - interrupts: interrupt specifier.
+26
Documentation/devicetree/bindings/i2c/i2c-sh_mobile.txt
··· 1 + Device tree configuration for Renesas IIC (sh_mobile) driver 2 + 3 + Required properties: 4 + - compatible : "renesas,iic-<soctype>". "renesas,rmobile-iic" as fallback 5 + - reg : address start and address range size of device 6 + - interrupts : interrupt of device 7 + - clocks : clock for device 8 + - #address-cells : should be <1> 9 + - #size-cells : should be <0> 10 + 11 + Optional properties: 12 + - clock-frequency : frequency of bus clock in Hz. Default 100kHz if unset. 13 + 14 + Pinctrl properties might be needed, too. See there. 15 + 16 + Example: 17 + 18 + iic0: i2c@e6500000 { 19 + compatible = "renesas,iic-r8a7790", "renesas,rmobile-iic"; 20 + reg = <0 0xe6500000 0 0x425>; 21 + interrupts = <0 174 IRQ_TYPE_LEVEL_HIGH>; 22 + clocks = <&mstp3_clks R8A7790_CLK_IIC0>; 23 + clock-frequency = <400000>; 24 + #address-cells = <1>; 25 + #size-cells = <0>; 26 + };
+3 -3
arch/arm/boot/dts/sun4i-a10.dtsi
··· 713 713 }; 714 714 715 715 i2c0: i2c@01c2ac00 { 716 - compatible = "allwinner,sun4i-i2c"; 716 + compatible = "allwinner,sun4i-a10-i2c"; 717 717 reg = <0x01c2ac00 0x400>; 718 718 interrupts = <7>; 719 719 clocks = <&apb1_gates 0>; ··· 724 724 }; 725 725 726 726 i2c1: i2c@01c2b000 { 727 - compatible = "allwinner,sun4i-i2c"; 727 + compatible = "allwinner,sun4i-a10-i2c"; 728 728 reg = <0x01c2b000 0x400>; 729 729 interrupts = <8>; 730 730 clocks = <&apb1_gates 1>; ··· 735 735 }; 736 736 737 737 i2c2: i2c@01c2b400 { 738 - compatible = "allwinner,sun4i-i2c"; 738 + compatible = "allwinner,sun4i-a10-i2c"; 739 739 reg = <0x01c2b400 0x400>; 740 740 interrupts = <9>; 741 741 clocks = <&apb1_gates 2>;
+3 -3
arch/arm/boot/dts/sun5i-a10s.dtsi
··· 560 560 i2c0: i2c@01c2ac00 { 561 561 #address-cells = <1>; 562 562 #size-cells = <0>; 563 - compatible = "allwinner,sun4i-i2c"; 563 + compatible = "allwinner,sun5i-a10s-i2c", "allwinner,sun4i-a10-i2c"; 564 564 reg = <0x01c2ac00 0x400>; 565 565 interrupts = <7>; 566 566 clocks = <&apb1_gates 0>; ··· 571 571 i2c1: i2c@01c2b000 { 572 572 #address-cells = <1>; 573 573 #size-cells = <0>; 574 - compatible = "allwinner,sun4i-i2c"; 574 + compatible = "allwinner,sun5i-a10s-i2c", "allwinner,sun4i-a10-i2c"; 575 575 reg = <0x01c2b000 0x400>; 576 576 interrupts = <8>; 577 577 clocks = <&apb1_gates 1>; ··· 582 582 i2c2: i2c@01c2b400 { 583 583 #address-cells = <1>; 584 584 #size-cells = <0>; 585 - compatible = "allwinner,sun4i-i2c"; 585 + compatible = "allwinner,sun5i-a10s-i2c", "allwinner,sun4i-a10-i2c"; 586 586 reg = <0x01c2b400 0x400>; 587 587 interrupts = <9>; 588 588 clocks = <&apb1_gates 2>;
+3 -3
arch/arm/boot/dts/sun5i-a13.dtsi
··· 486 486 }; 487 487 488 488 i2c0: i2c@01c2ac00 { 489 - compatible = "allwinner,sun4i-i2c"; 489 + compatible = "allwinner,sun5i-a13-i2c", "allwinner,sun4i-a10-i2c"; 490 490 reg = <0x01c2ac00 0x400>; 491 491 interrupts = <7>; 492 492 clocks = <&apb1_gates 0>; ··· 497 497 }; 498 498 499 499 i2c1: i2c@01c2b000 { 500 - compatible = "allwinner,sun4i-i2c"; 500 + compatible = "allwinner,sun5i-a13-i2c", "allwinner,sun4i-a10-i2c"; 501 501 reg = <0x01c2b000 0x400>; 502 502 interrupts = <8>; 503 503 clocks = <&apb1_gates 1>; ··· 508 508 }; 509 509 510 510 i2c2: i2c@01c2b400 { 511 - compatible = "allwinner,sun4i-i2c"; 511 + compatible = "allwinner,sun5i-a13-i2c", "allwinner,sun4i-a10-i2c"; 512 512 reg = <0x01c2b400 0x400>; 513 513 interrupts = <9>; 514 514 clocks = <&apb1_gates 2>;
+5 -5
arch/arm/boot/dts/sun7i-a20.dtsi
··· 863 863 }; 864 864 865 865 i2c0: i2c@01c2ac00 { 866 - compatible = "allwinner,sun4i-i2c"; 866 + compatible = "allwinner,sun7i-a20-i2c", "allwinner,sun4i-a10-i2c"; 867 867 reg = <0x01c2ac00 0x400>; 868 868 interrupts = <0 7 4>; 869 869 clocks = <&apb1_gates 0>; ··· 874 874 }; 875 875 876 876 i2c1: i2c@01c2b000 { 877 - compatible = "allwinner,sun4i-i2c"; 877 + compatible = "allwinner,sun7i-a20-i2c", "allwinner,sun4i-a10-i2c"; 878 878 reg = <0x01c2b000 0x400>; 879 879 interrupts = <0 8 4>; 880 880 clocks = <&apb1_gates 1>; ··· 885 885 }; 886 886 887 887 i2c2: i2c@01c2b400 { 888 - compatible = "allwinner,sun4i-i2c"; 888 + compatible = "allwinner,sun7i-a20-i2c", "allwinner,sun4i-a10-i2c"; 889 889 reg = <0x01c2b400 0x400>; 890 890 interrupts = <0 9 4>; 891 891 clocks = <&apb1_gates 2>; ··· 896 896 }; 897 897 898 898 i2c3: i2c@01c2b800 { 899 - compatible = "allwinner,sun4i-i2c"; 899 + compatible = "allwinner,sun7i-a20-i2c", "allwinner,sun4i-a10-i2c"; 900 900 reg = <0x01c2b800 0x400>; 901 901 interrupts = <0 88 4>; 902 902 clocks = <&apb1_gates 3>; ··· 907 907 }; 908 908 909 909 i2c4: i2c@01c2c000 { 910 - compatible = "allwinner,sun4i-i2c"; 910 + compatible = "allwinner,sun7i-a20-i2c", "allwinner,sun4i-a10-i2c"; 911 911 reg = <0x01c2c000 0x400>; 912 912 interrupts = <0 89 4>; 913 913 clocks = <&apb1_gates 15>;
+1 -8
drivers/i2c/busses/Kconfig
··· 449 449 450 450 config I2C_EG20T 451 451 tristate "Intel EG20T PCH/LAPIS Semicon IOH(ML7213/ML7223/ML7831) I2C" 452 - depends on PCI 452 + depends on PCI && (X86_32 || COMPILE_TEST) 453 453 help 454 454 This driver is for PCH(Platform controller Hub) I2C of EG20T which 455 455 is an IOH(Input/Output Hub) for x86 embedded processor. ··· 569 569 If you say yes to this option, support will be included for the 570 570 I2C interface from ST-Ericsson's Nomadik and Ux500 architectures, 571 571 as well as the STA2X11 PCIe I/O HUB. 572 - 573 - config I2C_NUC900 574 - tristate "NUC900 I2C Driver" 575 - depends on ARCH_W90X900 576 - help 577 - Say Y here to include support for I2C controller in the 578 - Winbond/Nuvoton NUC900 based System-on-Chip devices. 579 572 580 573 config I2C_OCORES 581 574 tristate "OpenCores I2C Controller"
-1
drivers/i2c/busses/Makefile
··· 55 55 obj-$(CONFIG_I2C_MV64XXX) += i2c-mv64xxx.o 56 56 obj-$(CONFIG_I2C_MXS) += i2c-mxs.o 57 57 obj-$(CONFIG_I2C_NOMADIK) += i2c-nomadik.o 58 - obj-$(CONFIG_I2C_NUC900) += i2c-nuc900.o 59 58 obj-$(CONFIG_I2C_OCORES) += i2c-ocores.o 60 59 obj-$(CONFIG_I2C_OMAP) += i2c-omap.o 61 60 obj-$(CONFIG_I2C_PASEMI) += i2c-pasemi.o
+45 -37
drivers/i2c/busses/i2c-ali1563.c
··· 63 63 static struct pci_driver ali1563_pci_driver; 64 64 static unsigned short ali1563_smba; 65 65 66 - static int ali1563_transaction(struct i2c_adapter * a, int size) 66 + static int ali1563_transaction(struct i2c_adapter *a, int size) 67 67 { 68 68 u32 data; 69 69 int timeout; ··· 78 78 data = inb_p(SMB_HST_STS); 79 79 if (data & HST_STS_BAD) { 80 80 dev_err(&a->dev, "ali1563: Trying to reset busy device\n"); 81 - outb_p(data | HST_STS_BAD,SMB_HST_STS); 81 + outb_p(data | HST_STS_BAD, SMB_HST_STS); 82 82 data = inb_p(SMB_HST_STS); 83 83 if (data & HST_STS_BAD) 84 84 return -EBUSY; ··· 102 102 if (!timeout) { 103 103 dev_err(&a->dev, "Timeout - Trying to KILL transaction!\n"); 104 104 /* Issue 'kill' to host controller */ 105 - outb_p(HST_CNTL2_KILL,SMB_HST_CNTL2); 105 + outb_p(HST_CNTL2_KILL, SMB_HST_CNTL2); 106 106 data = inb_p(SMB_HST_STS); 107 107 status = -ETIMEDOUT; 108 - } 108 + } 109 109 110 110 /* device error - no response, ignore the autodetection case */ 111 111 if (data & HST_STS_DEVERR) { ··· 117 117 if (data & HST_STS_BUSERR) { 118 118 dev_err(&a->dev, "Bus collision!\n"); 119 119 /* Issue timeout, hoping it helps */ 120 - outb_p(HST_CNTL1_TIMEOUT,SMB_HST_CNTL1); 120 + outb_p(HST_CNTL1_TIMEOUT, SMB_HST_CNTL1); 121 121 } 122 122 123 123 if (data & HST_STS_FAIL) { 124 124 dev_err(&a->dev, "Cleaning fail after KILL!\n"); 125 - outb_p(0x0,SMB_HST_CNTL2); 125 + outb_p(0x0, SMB_HST_CNTL2); 126 126 } 127 127 128 128 return status; 129 129 } 130 130 131 - static int ali1563_block_start(struct i2c_adapter * a) 131 + static int ali1563_block_start(struct i2c_adapter *a) 132 132 { 133 133 u32 data; 134 134 int timeout; ··· 142 142 143 143 data = inb_p(SMB_HST_STS); 144 144 if (data & HST_STS_BAD) { 145 - dev_warn(&a->dev,"ali1563: Trying to reset busy device\n"); 146 - outb_p(data | HST_STS_BAD,SMB_HST_STS); 145 + dev_warn(&a->dev, "ali1563: Trying to reset busy device\n"); 146 + outb_p(data | HST_STS_BAD, SMB_HST_STS); 147 147 data = inb_p(SMB_HST_STS); 148 148 if (data & HST_STS_BAD) 149 149 return -EBUSY; ··· 184 184 return status; 185 185 } 186 186 187 - static int ali1563_block(struct i2c_adapter * a, union i2c_smbus_data * data, u8 rw) 187 + static int ali1563_block(struct i2c_adapter *a, 188 + union i2c_smbus_data *data, u8 rw) 188 189 { 189 190 int i, len; 190 191 int error = 0; 191 192 192 193 /* Do we need this? */ 193 - outb_p(HST_CNTL1_LAST,SMB_HST_CNTL1); 194 + outb_p(HST_CNTL1_LAST, SMB_HST_CNTL1); 194 195 195 196 if (rw == I2C_SMBUS_WRITE) { 196 197 len = data->block[0]; ··· 199 198 len = 1; 200 199 else if (len > 32) 201 200 len = 32; 202 - outb_p(len,SMB_HST_DAT0); 203 - outb_p(data->block[1],SMB_BLK_DAT); 201 + outb_p(len, SMB_HST_DAT0); 202 + outb_p(data->block[1], SMB_BLK_DAT); 204 203 } else 205 204 len = 32; 206 205 ··· 209 208 for (i = 0; i < len; i++) { 210 209 if (rw == I2C_SMBUS_WRITE) { 211 210 outb_p(data->block[i + 1], SMB_BLK_DAT); 212 - if ((error = ali1563_block_start(a))) 211 + error = ali1563_block_start(a); 212 + if (error) 213 213 break; 214 214 } else { 215 - if ((error = ali1563_block_start(a))) 215 + error = ali1563_block_start(a); 216 + if (error) 216 217 break; 217 218 if (i == 0) { 218 219 len = inb_p(SMB_HST_DAT0); ··· 227 224 } 228 225 } 229 226 /* Do we need this? */ 230 - outb_p(HST_CNTL1_LAST,SMB_HST_CNTL1); 227 + outb_p(HST_CNTL1_LAST, SMB_HST_CNTL1); 231 228 return error; 232 229 } 233 230 234 - static s32 ali1563_access(struct i2c_adapter * a, u16 addr, 231 + static s32 ali1563_access(struct i2c_adapter *a, u16 addr, 235 232 unsigned short flags, char rw, u8 cmd, 236 - int size, union i2c_smbus_data * data) 233 + int size, union i2c_smbus_data *data) 237 234 { 238 235 int error = 0; 239 236 int timeout; 240 237 u32 reg; 241 238 242 239 for (timeout = ALI1563_MAX_TIMEOUT; timeout; timeout--) { 243 - if (!(reg = inb_p(SMB_HST_STS) & HST_STS_BUSY)) 240 + reg = inb_p(SMB_HST_STS); 241 + if (!(reg & HST_STS_BUSY)) 244 242 break; 245 243 } 246 244 if (!timeout) 247 - dev_warn(&a->dev,"SMBus not idle. HST_STS = %02x\n",reg); 248 - outb_p(0xff,SMB_HST_STS); 245 + dev_warn(&a->dev, "SMBus not idle. HST_STS = %02x\n", reg); 246 + outb_p(0xff, SMB_HST_STS); 249 247 250 248 /* Map the size to what the chip understands */ 251 249 switch (size) { ··· 272 268 } 273 269 274 270 outb_p(((addr & 0x7f) << 1) | (rw & 0x01), SMB_HST_ADD); 275 - outb_p((inb_p(SMB_HST_CNTL2) & ~HST_CNTL2_SIZEMASK) | (size << 3), SMB_HST_CNTL2); 271 + outb_p((inb_p(SMB_HST_CNTL2) & ~HST_CNTL2_SIZEMASK) | 272 + (size << 3), SMB_HST_CNTL2); 276 273 277 274 /* Write the command register */ 278 275 279 - switch(size) { 276 + switch (size) { 280 277 case HST_CNTL2_BYTE: 281 - if (rw== I2C_SMBUS_WRITE) 278 + if (rw == I2C_SMBUS_WRITE) 282 279 /* Beware it uses DAT0 register and not CMD! */ 283 280 outb_p(cmd, SMB_HST_DAT0); 284 281 break; ··· 297 292 break; 298 293 case HST_CNTL2_BLOCK: 299 294 outb_p(cmd, SMB_HST_CMD); 300 - error = ali1563_block(a,data,rw); 295 + error = ali1563_block(a, data, rw); 301 296 goto Done; 302 297 } 303 298 304 - if ((error = ali1563_transaction(a, size))) 299 + error = ali1563_transaction(a, size); 300 + if (error) 305 301 goto Done; 306 302 307 303 if ((rw == I2C_SMBUS_WRITE) || (size == HST_CNTL2_QUICK)) ··· 323 317 return error; 324 318 } 325 319 326 - static u32 ali1563_func(struct i2c_adapter * a) 320 + static u32 ali1563_func(struct i2c_adapter *a) 327 321 { 328 322 return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | 329 323 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | ··· 335 329 { 336 330 u16 ctrl; 337 331 338 - pci_read_config_word(dev,ALI1563_SMBBA,&ctrl); 332 + pci_read_config_word(dev, ALI1563_SMBBA, &ctrl); 339 333 340 334 /* SMB I/O Base in high 12 bits and must be aligned with the 341 335 * size of the I/O space. */ 342 336 ali1563_smba = ctrl & ~(ALI1563_SMB_IOSIZE - 1); 343 337 if (!ali1563_smba) { 344 - dev_warn(&dev->dev,"ali1563_smba Uninitialized\n"); 338 + dev_warn(&dev->dev, "ali1563_smba Uninitialized\n"); 345 339 goto Err; 346 340 } 347 341 ··· 356 350 ctrl | ALI1563_SMB_IOEN); 357 351 pci_read_config_word(dev, ALI1563_SMBBA, &ctrl); 358 352 if (!(ctrl & ALI1563_SMB_IOEN)) { 359 - dev_err(&dev->dev, "I/O space still not enabled, " 360 - "giving up\n"); 353 + dev_err(&dev->dev, 354 + "I/O space still not enabled, giving up\n"); 361 355 goto Err; 362 356 } 363 357 } ··· 381 375 382 376 static void ali1563_shutdown(struct pci_dev *dev) 383 377 { 384 - release_region(ali1563_smba,ALI1563_SMB_IOSIZE); 378 + release_region(ali1563_smba, ALI1563_SMB_IOSIZE); 385 379 } 386 380 387 381 static const struct i2c_algorithm ali1563_algorithm = { ··· 400 394 { 401 395 int error; 402 396 403 - if ((error = ali1563_setup(dev))) 397 + error = ali1563_setup(dev); 398 + if (error) 404 399 goto exit; 405 400 ali1563_adapter.dev.parent = &dev->dev; 406 401 snprintf(ali1563_adapter.name, sizeof(ali1563_adapter.name), 407 402 "SMBus ALi 1563 Adapter @ %04x", ali1563_smba); 408 - if ((error = i2c_add_adapter(&ali1563_adapter))) 403 + error = i2c_add_adapter(&ali1563_adapter); 404 + if (error) 409 405 goto exit_shutdown; 410 406 return 0; 411 407 ··· 429 421 {}, 430 422 }; 431 423 432 - MODULE_DEVICE_TABLE (pci, ali1563_id_table); 424 + MODULE_DEVICE_TABLE(pci, ali1563_id_table); 433 425 434 426 static struct pci_driver ali1563_pci_driver = { 435 - .name = "ali1563_smbus", 427 + .name = "ali1563_smbus", 436 428 .id_table = ali1563_id_table, 437 - .probe = ali1563_probe, 429 + .probe = ali1563_probe, 438 430 .remove = ali1563_remove, 439 431 }; 440 432
+1 -3
drivers/i2c/busses/i2c-bcm2835.c
··· 225 225 struct i2c_adapter *adap; 226 226 227 227 i2c_dev = devm_kzalloc(&pdev->dev, sizeof(*i2c_dev), GFP_KERNEL); 228 - if (!i2c_dev) { 229 - dev_err(&pdev->dev, "Cannot allocate i2c_dev\n"); 228 + if (!i2c_dev) 230 229 return -ENOMEM; 231 - } 232 230 platform_set_drvdata(pdev, i2c_dev); 233 231 i2c_dev->dev = &pdev->dev; 234 232 init_completion(&i2c_dev->completion);
+12 -32
drivers/i2c/busses/i2c-bfin-twi.c
··· 620 620 int rc; 621 621 unsigned int clkhilow; 622 622 623 - iface = kzalloc(sizeof(struct bfin_twi_iface), GFP_KERNEL); 623 + iface = devm_kzalloc(&pdev->dev, sizeof(struct bfin_twi_iface), 624 + GFP_KERNEL); 624 625 if (!iface) { 625 626 dev_err(&pdev->dev, "Cannot allocate memory\n"); 626 - rc = -ENOMEM; 627 - goto out_error_nomem; 627 + return -ENOMEM; 628 628 } 629 629 630 630 spin_lock_init(&(iface->lock)); 631 631 632 632 /* Find and map our resources */ 633 633 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 634 - if (res == NULL) { 635 - dev_err(&pdev->dev, "Cannot get IORESOURCE_MEM\n"); 636 - rc = -ENOENT; 637 - goto out_error_get_res; 638 - } 639 - 640 - iface->regs_base = ioremap(res->start, resource_size(res)); 641 - if (iface->regs_base == NULL) { 634 + iface->regs_base = devm_ioremap_resource(&pdev->dev, res); 635 + if (IS_ERR(iface->regs_base)) { 642 636 dev_err(&pdev->dev, "Cannot map IO\n"); 643 - rc = -ENXIO; 644 - goto out_error_ioremap; 637 + return PTR_ERR(iface->regs_base); 645 638 } 646 639 647 640 iface->irq = platform_get_irq(pdev, 0); 648 641 if (iface->irq < 0) { 649 642 dev_err(&pdev->dev, "No IRQ specified\n"); 650 - rc = -ENOENT; 651 - goto out_error_no_irq; 643 + return -ENOENT; 652 644 } 653 645 654 646 p_adap = &iface->adap; ··· 658 666 "i2c-bfin-twi"); 659 667 if (rc) { 660 668 dev_err(&pdev->dev, "Can't setup pin mux!\n"); 661 - goto out_error_pin_mux; 669 + return -EBUSY; 662 670 } 663 671 664 - rc = request_irq(iface->irq, bfin_twi_interrupt_entry, 672 + rc = devm_request_irq(&pdev->dev, iface->irq, bfin_twi_interrupt_entry, 665 673 0, pdev->name, iface); 666 674 if (rc) { 667 675 dev_err(&pdev->dev, "Can't get IRQ %d !\n", iface->irq); 668 676 rc = -ENODEV; 669 - goto out_error_req_irq; 677 + goto out_error; 670 678 } 671 679 672 680 /* Set TWI internal clock as 10MHz */ ··· 687 695 rc = i2c_add_numbered_adapter(p_adap); 688 696 if (rc < 0) { 689 697 dev_err(&pdev->dev, "Can't add i2c adapter!\n"); 690 - goto out_error_add_adapter; 698 + goto out_error; 691 699 } 692 700 693 701 platform_set_drvdata(pdev, iface); ··· 697 705 698 706 return 0; 699 707 700 - out_error_add_adapter: 701 - free_irq(iface->irq, iface); 702 - out_error_req_irq: 703 - out_error_no_irq: 708 + out_error: 704 709 peripheral_free_list(dev_get_platdata(&pdev->dev)); 705 - out_error_pin_mux: 706 - iounmap(iface->regs_base); 707 - out_error_ioremap: 708 - out_error_get_res: 709 - kfree(iface); 710 - out_error_nomem: 711 710 return rc; 712 711 } 713 712 ··· 707 724 struct bfin_twi_iface *iface = platform_get_drvdata(pdev); 708 725 709 726 i2c_del_adapter(&(iface->adap)); 710 - free_irq(iface->irq, iface); 711 727 peripheral_free_list(dev_get_platdata(&pdev->dev)); 712 - iounmap(iface->regs_base); 713 - kfree(iface); 714 728 715 729 return 0; 716 730 }
+22
drivers/i2c/busses/i2c-designware-pcidrv.c
··· 56 56 medfield_5, 57 57 58 58 baytrail, 59 + haswell, 59 60 }; 60 61 61 62 struct dw_scl_sda_cfg { ··· 94 93 .ss_lcnt = 0x200, 95 94 .fs_lcnt = 0x99, 96 95 .sda_hold = 0x6, 96 + }; 97 + 98 + /* Haswell HCNT/LCNT/SDA hold time */ 99 + static struct dw_scl_sda_cfg hsw_config = { 100 + .ss_hcnt = 0x01b0, 101 + .fs_hcnt = 0x48, 102 + .ss_lcnt = 0x01fb, 103 + .fs_lcnt = 0xa0, 104 + .sda_hold = 0x9, 97 105 }; 98 106 99 107 static struct dw_pci_controller dw_pci_controllers[] = { ··· 177 167 .clk_khz = 100000, 178 168 .functionality = I2C_FUNC_10BIT_ADDR, 179 169 .scl_sda_cfg = &byt_config, 170 + }, 171 + [haswell] = { 172 + .bus_num = -1, 173 + .bus_cfg = INTEL_MID_STD_CFG | DW_IC_CON_SPEED_FAST, 174 + .tx_fifo_depth = 32, 175 + .rx_fifo_depth = 32, 176 + .clk_khz = 100000, 177 + .functionality = I2C_FUNC_10BIT_ADDR, 178 + .scl_sda_cfg = &hsw_config, 180 179 }, 181 180 }; 182 181 static struct i2c_algorithm i2c_dw_algo = { ··· 347 328 { PCI_VDEVICE(INTEL, 0x0F45), baytrail }, 348 329 { PCI_VDEVICE(INTEL, 0x0F46), baytrail }, 349 330 { PCI_VDEVICE(INTEL, 0x0F47), baytrail }, 331 + /* Haswell */ 332 + { PCI_VDEVICE(INTEL, 0x9c61), haswell }, 333 + { PCI_VDEVICE(INTEL, 0x9c62), haswell }, 350 334 { 0,} 351 335 }; 352 336 MODULE_DEVICE_TABLE(pci, i2_designware_pci_ids);
+6 -7
drivers/i2c/busses/i2c-designware-platdrv.c
··· 247 247 MODULE_DEVICE_TABLE(of, dw_i2c_of_match); 248 248 #endif 249 249 250 - #ifdef CONFIG_PM_SLEEP 250 + #ifdef CONFIG_PM 251 251 static int dw_i2c_suspend(struct device *dev) 252 252 { 253 253 struct platform_device *pdev = to_platform_device(dev); 254 254 struct dw_i2c_dev *i_dev = platform_get_drvdata(pdev); 255 255 256 + i2c_dw_disable(i_dev); 256 257 clk_disable_unprepare(i_dev->clk); 257 258 258 259 return 0; ··· 269 268 270 269 return 0; 271 270 } 272 - 273 - static SIMPLE_DEV_PM_OPS(dw_i2c_dev_pm_ops, dw_i2c_suspend, dw_i2c_resume); 274 - #define DW_I2C_DEV_PM_OPS (&dw_i2c_dev_pm_ops) 275 - #else 276 - #define DW_I2C_DEV_PM_OPS NULL 277 271 #endif 272 + 273 + static UNIVERSAL_DEV_PM_OPS(dw_i2c_dev_pm_ops, dw_i2c_suspend, 274 + dw_i2c_resume, NULL); 278 275 279 276 /* work with hotplug and coldplug */ 280 277 MODULE_ALIAS("platform:i2c_designware"); ··· 285 286 .owner = THIS_MODULE, 286 287 .of_match_table = of_match_ptr(dw_i2c_of_match), 287 288 .acpi_match_table = ACPI_PTR(dw_i2c_acpi_match), 288 - .pm = DW_I2C_DEV_PM_OPS, 289 + .pm = &dw_i2c_dev_pm_ops, 289 290 }, 290 291 }; 291 292
-1
drivers/i2c/busses/i2c-diolan-u2c.c
··· 455 455 /* allocate memory for our device state and initialize it */ 456 456 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 457 457 if (dev == NULL) { 458 - dev_err(&interface->dev, "no memory for device state\n"); 459 458 ret = -ENOMEM; 460 459 goto error; 461 460 }
+1 -3
drivers/i2c/busses/i2c-efm32.c
··· 320 320 return -EINVAL; 321 321 322 322 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL); 323 - if (!ddata) { 324 - dev_dbg(&pdev->dev, "failed to allocate private data\n"); 323 + if (!ddata) 325 324 return -ENOMEM; 326 - } 327 325 platform_set_drvdata(pdev, ddata); 328 326 329 327 init_completion(&ddata->done);
+1 -3
drivers/i2c/busses/i2c-eg20t.c
··· 751 751 pch_pci_dbg(pdev, "Entered.\n"); 752 752 753 753 adap_info = kzalloc((sizeof(struct adapter_info)), GFP_KERNEL); 754 - if (adap_info == NULL) { 755 - pch_pci_err(pdev, "Memory allocation FAILED\n"); 754 + if (adap_info == NULL) 756 755 return -ENOMEM; 757 - } 758 756 759 757 ret = pci_enable_device(pdev); 760 758 if (ret) {
+56 -15
drivers/i2c/busses/i2c-exynos5.c
··· 76 76 #define HSI2C_RXFIFO_TRIGGER_LEVEL(x) ((x) << 4) 77 77 #define HSI2C_TXFIFO_TRIGGER_LEVEL(x) ((x) << 16) 78 78 79 - /* As per user manual FIFO max depth is 64bytes */ 80 - #define HSI2C_FIFO_MAX 0x40 81 - /* default trigger levels for Tx and Rx FIFOs */ 82 - #define HSI2C_DEF_TXFIFO_LVL (HSI2C_FIFO_MAX - 0x30) 83 - #define HSI2C_DEF_RXFIFO_LVL (HSI2C_FIFO_MAX - 0x10) 84 - 85 79 /* I2C_TRAILING_CTL Register bits */ 86 80 #define HSI2C_TRAILING_COUNT (0xf) 87 81 ··· 177 183 * 2. Fast speed upto 1Mbps 178 184 */ 179 185 int speed_mode; 186 + 187 + /* Version of HS-I2C Hardware */ 188 + struct exynos_hsi2c_variant *variant; 189 + }; 190 + 191 + /** 192 + * struct exynos_hsi2c_variant - platform specific HSI2C driver data 193 + * @fifo_depth: the fifo depth supported by the HSI2C module 194 + * 195 + * Specifies platform specific configuration of HSI2C module. 196 + * Note: A structure for driver specific platform data is used for future 197 + * expansion of its usage. 198 + */ 199 + struct exynos_hsi2c_variant { 200 + unsigned int fifo_depth; 201 + }; 202 + 203 + static const struct exynos_hsi2c_variant exynos5250_hsi2c_data = { 204 + .fifo_depth = 64, 205 + }; 206 + 207 + static const struct exynos_hsi2c_variant exynos5260_hsi2c_data = { 208 + .fifo_depth = 16, 180 209 }; 181 210 182 211 static const struct of_device_id exynos5_i2c_match[] = { 183 - { .compatible = "samsung,exynos5-hsi2c" }, 184 - {}, 212 + { 213 + .compatible = "samsung,exynos5-hsi2c", 214 + .data = &exynos5250_hsi2c_data 215 + }, { 216 + .compatible = "samsung,exynos5250-hsi2c", 217 + .data = &exynos5250_hsi2c_data 218 + }, { 219 + .compatible = "samsung,exynos5260-hsi2c", 220 + .data = &exynos5260_hsi2c_data 221 + }, {}, 185 222 }; 186 223 MODULE_DEVICE_TABLE(of, exynos5_i2c_match); 224 + 225 + static inline struct exynos_hsi2c_variant *exynos5_i2c_get_variant 226 + (struct platform_device *pdev) 227 + { 228 + const struct of_device_id *match; 229 + 230 + match = of_match_node(exynos5_i2c_match, pdev->dev.of_node); 231 + return (struct exynos_hsi2c_variant *)match->data; 232 + } 187 233 188 234 static void exynos5_i2c_clr_pend_irq(struct exynos5_i2c *i2c) 189 235 { ··· 449 415 fifo_status = readl(i2c->regs + HSI2C_FIFO_STATUS); 450 416 fifo_level = HSI2C_TX_FIFO_LVL(fifo_status); 451 417 452 - len = HSI2C_FIFO_MAX - fifo_level; 418 + len = i2c->variant->fifo_depth - fifo_level; 453 419 if (len > (i2c->msg->len - i2c->msg_ptr)) 454 420 len = i2c->msg->len - i2c->msg_ptr; 455 421 ··· 517 483 u32 i2c_auto_conf = 0; 518 484 u32 fifo_ctl; 519 485 unsigned long flags; 486 + unsigned short trig_lvl; 520 487 521 488 i2c_ctl = readl(i2c->regs + HSI2C_CTL); 522 489 i2c_ctl &= ~(HSI2C_TXCHON | HSI2C_RXCHON); ··· 528 493 529 494 i2c_auto_conf = HSI2C_READ_WRITE; 530 495 531 - fifo_ctl |= HSI2C_RXFIFO_TRIGGER_LEVEL(HSI2C_DEF_TXFIFO_LVL); 496 + trig_lvl = (i2c->msg->len > i2c->variant->fifo_depth) ? 497 + (i2c->variant->fifo_depth * 3 / 4) : i2c->msg->len; 498 + fifo_ctl |= HSI2C_RXFIFO_TRIGGER_LEVEL(trig_lvl); 499 + 532 500 int_en |= (HSI2C_INT_RX_ALMOSTFULL_EN | 533 501 HSI2C_INT_TRAILING_EN); 534 502 } else { 535 503 i2c_ctl |= HSI2C_TXCHON; 536 504 537 - fifo_ctl |= HSI2C_TXFIFO_TRIGGER_LEVEL(HSI2C_DEF_RXFIFO_LVL); 505 + trig_lvl = (i2c->msg->len > i2c->variant->fifo_depth) ? 506 + (i2c->variant->fifo_depth * 1 / 4) : i2c->msg->len; 507 + fifo_ctl |= HSI2C_TXFIFO_TRIGGER_LEVEL(trig_lvl); 508 + 538 509 int_en |= HSI2C_INT_TX_ALMOSTEMPTY_EN; 539 510 } 540 511 ··· 662 621 int ret; 663 622 664 623 i2c = devm_kzalloc(&pdev->dev, sizeof(struct exynos5_i2c), GFP_KERNEL); 665 - if (!i2c) { 666 - dev_err(&pdev->dev, "no memory for state\n"); 624 + if (!i2c) 667 625 return -ENOMEM; 668 - } 669 626 670 627 if (of_property_read_u32(np, "clock-frequency", &op_clock)) { 671 628 i2c->speed_mode = HSI2C_FAST_SPD; ··· 730 691 if (ret) 731 692 goto err_clk; 732 693 733 - exynos5_i2c_init(i2c); 694 + i2c->variant = exynos5_i2c_get_variant(pdev); 695 + 696 + exynos5_i2c_reset(i2c); 734 697 735 698 ret = i2c_add_adapter(&i2c->adap); 736 699 if (ret < 0) {
+7 -18
drivers/i2c/busses/i2c-gpio.c
··· 147 147 scl_pin = pdata->scl_pin; 148 148 } 149 149 150 - ret = gpio_request(sda_pin, "sda"); 150 + ret = devm_gpio_request(&pdev->dev, sda_pin, "sda"); 151 151 if (ret) { 152 152 if (ret == -EINVAL) 153 153 ret = -EPROBE_DEFER; /* Try again later */ 154 - goto err_request_sda; 154 + return ret; 155 155 } 156 - ret = gpio_request(scl_pin, "scl"); 156 + ret = devm_gpio_request(&pdev->dev, scl_pin, "scl"); 157 157 if (ret) { 158 158 if (ret == -EINVAL) 159 159 ret = -EPROBE_DEFER; /* Try again later */ 160 - goto err_request_scl; 160 + return ret; 161 161 } 162 162 163 163 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); 164 - if (!priv) { 165 - ret = -ENOMEM; 166 - goto err_add_bus; 167 - } 164 + if (!priv) 165 + return -ENOMEM; 168 166 adap = &priv->adap; 169 167 bit_data = &priv->bit_data; 170 168 pdata = &priv->pdata; ··· 223 225 adap->nr = pdev->id; 224 226 ret = i2c_bit_add_numbered_bus(adap); 225 227 if (ret) 226 - goto err_add_bus; 228 + return ret; 227 229 228 230 platform_set_drvdata(pdev, priv); 229 231 ··· 233 235 ? ", no clock stretching" : ""); 234 236 235 237 return 0; 236 - 237 - err_add_bus: 238 - gpio_free(scl_pin); 239 - err_request_scl: 240 - gpio_free(sda_pin); 241 - err_request_sda: 242 - return ret; 243 238 } 244 239 245 240 static int i2c_gpio_remove(struct platform_device *pdev) ··· 246 255 pdata = &priv->pdata; 247 256 248 257 i2c_del_adapter(adap); 249 - gpio_free(pdata->scl_pin); 250 - gpio_free(pdata->sda_pin); 251 258 252 259 return 0; 253 260 }
+108 -61
drivers/i2c/busses/i2c-imx.c
··· 183 183 unsigned int disable_delay; 184 184 int stopped; 185 185 unsigned int ifdr; /* IMX_I2C_IFDR */ 186 + unsigned int cur_clk; 187 + unsigned int bitrate; 186 188 const struct imx_i2c_hwdata *hwdata; 187 189 }; 188 190 ··· 307 305 return 0; 308 306 } 309 307 308 + static void i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx) 309 + { 310 + struct imx_i2c_clk_pair *i2c_clk_div = i2c_imx->hwdata->clk_div; 311 + unsigned int i2c_clk_rate; 312 + unsigned int div; 313 + int i; 314 + 315 + /* Divider value calculation */ 316 + i2c_clk_rate = clk_get_rate(i2c_imx->clk); 317 + if (i2c_imx->cur_clk == i2c_clk_rate) 318 + return; 319 + else 320 + i2c_imx->cur_clk = i2c_clk_rate; 321 + 322 + div = (i2c_clk_rate + i2c_imx->bitrate - 1) / i2c_imx->bitrate; 323 + if (div < i2c_clk_div[0].div) 324 + i = 0; 325 + else if (div > i2c_clk_div[i2c_imx->hwdata->ndivs - 1].div) 326 + i = i2c_imx->hwdata->ndivs - 1; 327 + else 328 + for (i = 0; i2c_clk_div[i].div < div; i++); 329 + 330 + /* Store divider value */ 331 + i2c_imx->ifdr = i2c_clk_div[i].val; 332 + 333 + /* 334 + * There dummy delay is calculated. 335 + * It should be about one I2C clock period long. 336 + * This delay is used in I2C bus disable function 337 + * to fix chip hardware bug. 338 + */ 339 + i2c_imx->disable_delay = (500000U * i2c_clk_div[i].div 340 + + (i2c_clk_rate / 2) - 1) / (i2c_clk_rate / 2); 341 + 342 + #ifdef CONFIG_I2C_DEBUG_BUS 343 + dev_dbg(&i2c_imx->adapter.dev, "I2C_CLK=%d, REQ DIV=%d\n", 344 + i2c_clk_rate, div); 345 + dev_dbg(&i2c_imx->adapter.dev, "IFDR[IC]=0x%x, REAL DIV=%d\n", 346 + i2c_clk_div[i].val, i2c_clk_div[i].div); 347 + #endif 348 + } 349 + 310 350 static int i2c_imx_start(struct imx_i2c_struct *i2c_imx) 311 351 { 312 352 unsigned int temp = 0; 313 353 int result; 314 354 315 355 dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__); 356 + 357 + i2c_imx_set_clk(i2c_imx); 316 358 317 359 result = clk_prepare_enable(i2c_imx->clk); 318 360 if (result) ··· 413 367 clk_disable_unprepare(i2c_imx->clk); 414 368 } 415 369 416 - static void i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx, 417 - unsigned int rate) 418 - { 419 - struct imx_i2c_clk_pair *i2c_clk_div = i2c_imx->hwdata->clk_div; 420 - unsigned int i2c_clk_rate; 421 - unsigned int div; 422 - int i; 423 - 424 - /* Divider value calculation */ 425 - i2c_clk_rate = clk_get_rate(i2c_imx->clk); 426 - div = (i2c_clk_rate + rate - 1) / rate; 427 - if (div < i2c_clk_div[0].div) 428 - i = 0; 429 - else if (div > i2c_clk_div[i2c_imx->hwdata->ndivs - 1].div) 430 - i = i2c_imx->hwdata->ndivs - 1; 431 - else 432 - for (i = 0; i2c_clk_div[i].div < div; i++); 433 - 434 - /* Store divider value */ 435 - i2c_imx->ifdr = i2c_clk_div[i].val; 436 - 437 - /* 438 - * There dummy delay is calculated. 439 - * It should be about one I2C clock period long. 440 - * This delay is used in I2C bus disable function 441 - * to fix chip hardware bug. 442 - */ 443 - i2c_imx->disable_delay = (500000U * i2c_clk_div[i].div 444 - + (i2c_clk_rate / 2) - 1) / (i2c_clk_rate / 2); 445 - 446 - /* dev_dbg() can't be used, because adapter is not yet registered */ 447 - #ifdef CONFIG_I2C_DEBUG_BUS 448 - dev_dbg(&i2c_imx->adapter.dev, "<%s> I2C_CLK=%d, REQ DIV=%d\n", 449 - __func__, i2c_clk_rate, div); 450 - dev_dbg(&i2c_imx->adapter.dev, "<%s> IFDR[IC]=0x%x, REAL DIV=%d\n", 451 - __func__, i2c_clk_div[i].val, i2c_clk_div[i].div); 452 - #endif 453 - } 454 - 455 370 static irqreturn_t i2c_imx_isr(int irq, void *dev_id) 456 371 { 457 372 struct imx_i2c_struct *i2c_imx = dev_id; ··· 465 458 return 0; 466 459 } 467 460 468 - static int i2c_imx_read(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs) 461 + static int i2c_imx_read(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs, bool is_lastmsg) 469 462 { 470 463 int i, result; 471 464 unsigned int temp; 465 + int block_data = msgs->flags & I2C_M_RECV_LEN; 472 466 473 467 dev_dbg(&i2c_imx->adapter.dev, 474 468 "<%s> write slave address: addr=0x%x\n", ··· 489 481 /* setup bus to read data */ 490 482 temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR); 491 483 temp &= ~I2CR_MTX; 492 - if (msgs->len - 1) 484 + 485 + /* 486 + * Reset the I2CR_TXAK flag initially for SMBus block read since the 487 + * length is unknown 488 + */ 489 + if ((msgs->len - 1) || block_data) 493 490 temp &= ~I2CR_TXAK; 494 491 imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR); 495 492 imx_i2c_read_reg(i2c_imx, IMX_I2C_I2DR); /* dummy read */ ··· 503 490 504 491 /* read data */ 505 492 for (i = 0; i < msgs->len; i++) { 493 + u8 len = 0; 506 494 result = i2c_imx_trx_complete(i2c_imx); 507 495 if (result) 508 496 return result; 509 - if (i == (msgs->len - 1)) { 510 - /* It must generate STOP before read I2DR to prevent 511 - controller from generating another clock cycle */ 497 + /* 498 + * First byte is the length of remaining packet 499 + * in the SMBus block data read. Add it to 500 + * msgs->len. 501 + */ 502 + if ((!i) && block_data) { 503 + len = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2DR); 504 + if ((len == 0) || (len > I2C_SMBUS_BLOCK_MAX)) 505 + return -EPROTO; 512 506 dev_dbg(&i2c_imx->adapter.dev, 513 - "<%s> clear MSTA\n", __func__); 514 - temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR); 515 - temp &= ~(I2CR_MSTA | I2CR_MTX); 516 - imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR); 517 - i2c_imx_bus_busy(i2c_imx, 0); 518 - i2c_imx->stopped = 1; 507 + "<%s> read length: 0x%X\n", 508 + __func__, len); 509 + msgs->len += len; 510 + } 511 + if (i == (msgs->len - 1)) { 512 + if (is_lastmsg) { 513 + /* 514 + * It must generate STOP before read I2DR to prevent 515 + * controller from generating another clock cycle 516 + */ 517 + dev_dbg(&i2c_imx->adapter.dev, 518 + "<%s> clear MSTA\n", __func__); 519 + temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR); 520 + temp &= ~(I2CR_MSTA | I2CR_MTX); 521 + imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR); 522 + i2c_imx_bus_busy(i2c_imx, 0); 523 + i2c_imx->stopped = 1; 524 + } else { 525 + /* 526 + * For i2c master receiver repeat restart operation like: 527 + * read -> repeat MSTA -> read/write 528 + * The controller must set MTX before read the last byte in 529 + * the first read operation, otherwise the first read cost 530 + * one extra clock cycle. 531 + */ 532 + temp = readb(i2c_imx->base + IMX_I2C_I2CR); 533 + temp |= I2CR_MTX; 534 + writeb(temp, i2c_imx->base + IMX_I2C_I2CR); 535 + } 519 536 } else if (i == (msgs->len - 2)) { 520 537 dev_dbg(&i2c_imx->adapter.dev, 521 538 "<%s> set TXAK\n", __func__); ··· 553 510 temp |= I2CR_TXAK; 554 511 imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR); 555 512 } 556 - msgs->buf[i] = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2DR); 513 + if ((!i) && block_data) 514 + msgs->buf[0] = len; 515 + else 516 + msgs->buf[i] = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2DR); 557 517 dev_dbg(&i2c_imx->adapter.dev, 558 518 "<%s> read byte: B%d=0x%X\n", 559 519 __func__, i, msgs->buf[i]); ··· 569 523 { 570 524 unsigned int i, temp; 571 525 int result; 526 + bool is_lastmsg = false; 572 527 struct imx_i2c_struct *i2c_imx = i2c_get_adapdata(adapter); 573 528 574 529 dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__); ··· 581 534 582 535 /* read/write data */ 583 536 for (i = 0; i < num; i++) { 537 + if (i == num - 1) 538 + is_lastmsg = true; 539 + 584 540 if (i) { 585 541 dev_dbg(&i2c_imx->adapter.dev, 586 542 "<%s> repeated start\n", __func__); ··· 614 564 (temp & I2SR_RXAK ? 1 : 0)); 615 565 #endif 616 566 if (msgs[i].flags & I2C_M_RD) 617 - result = i2c_imx_read(i2c_imx, &msgs[i]); 567 + result = i2c_imx_read(i2c_imx, &msgs[i], is_lastmsg); 618 568 else 619 569 result = i2c_imx_write(i2c_imx, &msgs[i]); 620 570 if (result) ··· 633 583 634 584 static u32 i2c_imx_func(struct i2c_adapter *adapter) 635 585 { 636 - return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; 586 + return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL 587 + | I2C_FUNC_SMBUS_READ_BLOCK_DATA; 637 588 } 638 589 639 590 static struct i2c_algorithm i2c_imx_algo = { ··· 651 600 struct imxi2c_platform_data *pdata = dev_get_platdata(&pdev->dev); 652 601 void __iomem *base; 653 602 int irq, ret; 654 - u32 bitrate; 655 603 656 604 dev_dbg(&pdev->dev, "<%s>\n", __func__); 657 605 ··· 667 617 668 618 i2c_imx = devm_kzalloc(&pdev->dev, sizeof(struct imx_i2c_struct), 669 619 GFP_KERNEL); 670 - if (!i2c_imx) { 671 - dev_err(&pdev->dev, "can't allocate interface\n"); 620 + if (!i2c_imx) 672 621 return -ENOMEM; 673 - } 674 622 675 623 if (of_id) 676 624 i2c_imx->hwdata = of_id->data; ··· 712 664 i2c_set_adapdata(&i2c_imx->adapter, i2c_imx); 713 665 714 666 /* Set up clock divider */ 715 - bitrate = IMX_I2C_BIT_RATE; 667 + i2c_imx->bitrate = IMX_I2C_BIT_RATE; 716 668 ret = of_property_read_u32(pdev->dev.of_node, 717 - "clock-frequency", &bitrate); 669 + "clock-frequency", &i2c_imx->bitrate); 718 670 if (ret < 0 && pdata && pdata->bitrate) 719 - bitrate = pdata->bitrate; 720 - i2c_imx_set_clk(i2c_imx, bitrate); 671 + i2c_imx->bitrate = pdata->bitrate; 721 672 722 673 /* Set up chip registers to defaults */ 723 674 imx_i2c_write_reg(i2c_imx->hwdata->i2cr_ien_opcode ^ I2CR_IEN,
+1 -1
drivers/i2c/busses/i2c-mpc.c
··· 115 115 for (k = 9; k; k--) { 116 116 writeccr(i2c, 0); 117 117 writeccr(i2c, CCR_MSTA | CCR_MTX | CCR_MEN); 118 - udelay(delay_val); 118 + readb(i2c->base + MPC_I2C_DR); 119 119 writeccr(i2c, CCR_MEN); 120 120 udelay(delay_val << 1); 121 121 }
+1 -1
drivers/i2c/busses/i2c-mv64xxx.c
··· 681 681 ***************************************************************************** 682 682 */ 683 683 static const struct of_device_id mv64xxx_i2c_of_match_table[] = { 684 - { .compatible = "allwinner,sun4i-i2c", .data = &mv64xxx_i2c_regs_sun4i}, 684 + { .compatible = "allwinner,sun4i-a10-i2c", .data = &mv64xxx_i2c_regs_sun4i}, 685 685 { .compatible = "allwinner,sun6i-a31-i2c", .data = &mv64xxx_i2c_regs_sun4i}, 686 686 { .compatible = "marvell,mv64xxx-i2c", .data = &mv64xxx_i2c_regs_mv64xxx}, 687 687 { .compatible = "marvell,mv78230-i2c", .data = &mv64xxx_i2c_regs_mv64xxx},
+7 -7
drivers/i2c/busses/i2c-nomadik.c
··· 879 879 #ifdef CONFIG_PM_SLEEP 880 880 static int nmk_i2c_suspend_late(struct device *dev) 881 881 { 882 - pinctrl_pm_select_sleep_state(dev); 882 + int ret; 883 883 884 + ret = pm_runtime_force_suspend(dev); 885 + if (ret) 886 + return ret; 887 + 888 + pinctrl_pm_select_sleep_state(dev); 884 889 return 0; 885 890 } 886 891 887 892 static int nmk_i2c_resume_early(struct device *dev) 888 893 { 889 - /* First go to the default state */ 890 - pinctrl_pm_select_default_state(dev); 891 - /* Then let's idle the pins until the next transfer happens */ 892 - pinctrl_pm_select_idle_state(dev); 893 - 894 - return 0; 894 + return pm_runtime_force_resume(dev); 895 895 } 896 896 #endif 897 897
-709
drivers/i2c/busses/i2c-nuc900.c
··· 1 - /* 2 - * linux/drivers/i2c/busses/i2c-nuc900.c 3 - * 4 - * Copyright (c) 2010 Nuvoton technology corporation. 5 - * 6 - * This driver based on S3C2410 I2C driver of Ben Dooks <ben-Y5A6D6n0/KfQXOPxS62xeg@public.gmane.org>. 7 - * Written by Wan ZongShun <mcuos.com-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 8 - * 9 - * This program is free software; you can redistribute it and/or modify 10 - * it under the terms of the GNU General Public License as published by 11 - * the Free Software Foundation;version 2 of the License. 12 - * 13 - */ 14 - 15 - #include <linux/kernel.h> 16 - #include <linux/module.h> 17 - 18 - #include <linux/i2c.h> 19 - #include <linux/init.h> 20 - #include <linux/time.h> 21 - #include <linux/interrupt.h> 22 - #include <linux/delay.h> 23 - #include <linux/errno.h> 24 - #include <linux/err.h> 25 - #include <linux/platform_device.h> 26 - #include <linux/clk.h> 27 - #include <linux/cpufreq.h> 28 - #include <linux/slab.h> 29 - #include <linux/io.h> 30 - 31 - #include <mach/mfp.h> 32 - #include <linux/platform_data/i2c-nuc900.h> 33 - 34 - /* nuc900 i2c registers offset */ 35 - 36 - #define CSR 0x00 37 - #define DIVIDER 0x04 38 - #define CMDR 0x08 39 - #define SWR 0x0C 40 - #define RXR 0x10 41 - #define TXR 0x14 42 - 43 - /* nuc900 i2c CSR register bits */ 44 - 45 - #define IRQEN 0x003 46 - #define I2CBUSY 0x400 47 - #define I2CSTART 0x018 48 - #define IRQFLAG 0x004 49 - #define ARBIT_LOST 0x200 50 - #define SLAVE_ACK 0x800 51 - 52 - /* nuc900 i2c CMDR register bits */ 53 - 54 - #define I2C_CMD_START 0x10 55 - #define I2C_CMD_STOP 0x08 56 - #define I2C_CMD_READ 0x04 57 - #define I2C_CMD_WRITE 0x02 58 - #define I2C_CMD_NACK 0x01 59 - 60 - /* i2c controller state */ 61 - 62 - enum nuc900_i2c_state { 63 - STATE_IDLE, 64 - STATE_START, 65 - STATE_READ, 66 - STATE_WRITE, 67 - STATE_STOP 68 - }; 69 - 70 - /* i2c controller private data */ 71 - 72 - struct nuc900_i2c { 73 - spinlock_t lock; 74 - wait_queue_head_t wait; 75 - 76 - struct i2c_msg *msg; 77 - unsigned int msg_num; 78 - unsigned int msg_idx; 79 - unsigned int msg_ptr; 80 - unsigned int irq; 81 - 82 - enum nuc900_i2c_state state; 83 - 84 - void __iomem *regs; 85 - struct clk *clk; 86 - struct device *dev; 87 - struct resource *ioarea; 88 - struct i2c_adapter adap; 89 - }; 90 - 91 - /* nuc900_i2c_master_complete 92 - * 93 - * complete the message and wake up the caller, using the given return code, 94 - * or zero to mean ok. 95 - */ 96 - 97 - static inline void nuc900_i2c_master_complete(struct nuc900_i2c *i2c, int ret) 98 - { 99 - dev_dbg(i2c->dev, "master_complete %d\n", ret); 100 - 101 - i2c->msg_ptr = 0; 102 - i2c->msg = NULL; 103 - i2c->msg_idx++; 104 - i2c->msg_num = 0; 105 - if (ret) 106 - i2c->msg_idx = ret; 107 - 108 - wake_up(&i2c->wait); 109 - } 110 - 111 - /* irq enable/disable functions */ 112 - 113 - static inline void nuc900_i2c_disable_irq(struct nuc900_i2c *i2c) 114 - { 115 - unsigned long tmp; 116 - 117 - tmp = readl(i2c->regs + CSR); 118 - writel(tmp & ~IRQEN, i2c->regs + CSR); 119 - } 120 - 121 - static inline void nuc900_i2c_enable_irq(struct nuc900_i2c *i2c) 122 - { 123 - unsigned long tmp; 124 - 125 - tmp = readl(i2c->regs + CSR); 126 - writel(tmp | IRQEN, i2c->regs + CSR); 127 - } 128 - 129 - 130 - /* nuc900_i2c_message_start 131 - * 132 - * put the start of a message onto the bus 133 - */ 134 - 135 - static void nuc900_i2c_message_start(struct nuc900_i2c *i2c, 136 - struct i2c_msg *msg) 137 - { 138 - unsigned int addr = (msg->addr & 0x7f) << 1; 139 - 140 - if (msg->flags & I2C_M_RD) 141 - addr |= 0x1; 142 - writel(addr & 0xff, i2c->regs + TXR); 143 - writel(I2C_CMD_START | I2C_CMD_WRITE, i2c->regs + CMDR); 144 - } 145 - 146 - static inline void nuc900_i2c_stop(struct nuc900_i2c *i2c, int ret) 147 - { 148 - 149 - dev_dbg(i2c->dev, "STOP\n"); 150 - 151 - /* stop the transfer */ 152 - i2c->state = STATE_STOP; 153 - writel(I2C_CMD_STOP, i2c->regs + CMDR); 154 - 155 - nuc900_i2c_master_complete(i2c, ret); 156 - nuc900_i2c_disable_irq(i2c); 157 - } 158 - 159 - /* helper functions to determine the current state in the set of 160 - * messages we are sending 161 - */ 162 - 163 - /* is_lastmsg() 164 - * 165 - * returns TRUE if the current message is the last in the set 166 - */ 167 - 168 - static inline int is_lastmsg(struct nuc900_i2c *i2c) 169 - { 170 - return i2c->msg_idx >= (i2c->msg_num - 1); 171 - } 172 - 173 - /* is_msglast 174 - * 175 - * returns TRUE if we this is the last byte in the current message 176 - */ 177 - 178 - static inline int is_msglast(struct nuc900_i2c *i2c) 179 - { 180 - return i2c->msg_ptr == i2c->msg->len-1; 181 - } 182 - 183 - /* is_msgend 184 - * 185 - * returns TRUE if we reached the end of the current message 186 - */ 187 - 188 - static inline int is_msgend(struct nuc900_i2c *i2c) 189 - { 190 - return i2c->msg_ptr >= i2c->msg->len; 191 - } 192 - 193 - /* i2c_nuc900_irq_nextbyte 194 - * 195 - * process an interrupt and work out what to do 196 - */ 197 - 198 - static void i2c_nuc900_irq_nextbyte(struct nuc900_i2c *i2c, 199 - unsigned long iicstat) 200 - { 201 - unsigned char byte; 202 - 203 - switch (i2c->state) { 204 - 205 - case STATE_IDLE: 206 - dev_err(i2c->dev, "%s: called in STATE_IDLE\n", __func__); 207 - break; 208 - 209 - case STATE_STOP: 210 - dev_err(i2c->dev, "%s: called in STATE_STOP\n", __func__); 211 - nuc900_i2c_disable_irq(i2c); 212 - break; 213 - 214 - case STATE_START: 215 - /* last thing we did was send a start condition on the 216 - * bus, or started a new i2c message 217 - */ 218 - 219 - if (iicstat & SLAVE_ACK && 220 - !(i2c->msg->flags & I2C_M_IGNORE_NAK)) { 221 - /* ack was not received... */ 222 - 223 - dev_dbg(i2c->dev, "ack was not received\n"); 224 - nuc900_i2c_stop(i2c, -ENXIO); 225 - break; 226 - } 227 - 228 - if (i2c->msg->flags & I2C_M_RD) 229 - i2c->state = STATE_READ; 230 - else 231 - i2c->state = STATE_WRITE; 232 - 233 - /* terminate the transfer if there is nothing to do 234 - * as this is used by the i2c probe to find devices. 235 - */ 236 - 237 - if (is_lastmsg(i2c) && i2c->msg->len == 0) { 238 - nuc900_i2c_stop(i2c, 0); 239 - break; 240 - } 241 - 242 - if (i2c->state == STATE_READ) 243 - goto prepare_read; 244 - 245 - /* fall through to the write state, as we will need to 246 - * send a byte as well 247 - */ 248 - 249 - case STATE_WRITE: 250 - /* we are writing data to the device... check for the 251 - * end of the message, and if so, work out what to do 252 - */ 253 - 254 - if (!(i2c->msg->flags & I2C_M_IGNORE_NAK)) { 255 - if (iicstat & SLAVE_ACK) { 256 - dev_dbg(i2c->dev, "WRITE: No Ack\n"); 257 - 258 - nuc900_i2c_stop(i2c, -ECONNREFUSED); 259 - break; 260 - } 261 - } 262 - 263 - retry_write: 264 - 265 - if (!is_msgend(i2c)) { 266 - byte = i2c->msg->buf[i2c->msg_ptr++]; 267 - writeb(byte, i2c->regs + TXR); 268 - writel(I2C_CMD_WRITE, i2c->regs + CMDR); 269 - 270 - } else if (!is_lastmsg(i2c)) { 271 - /* we need to go to the next i2c message */ 272 - 273 - dev_dbg(i2c->dev, "WRITE: Next Message\n"); 274 - 275 - i2c->msg_ptr = 0; 276 - i2c->msg_idx++; 277 - i2c->msg++; 278 - 279 - /* check to see if we need to do another message */ 280 - if (i2c->msg->flags & I2C_M_NOSTART) { 281 - 282 - if (i2c->msg->flags & I2C_M_RD) { 283 - /* cannot do this, the controller 284 - * forces us to send a new START 285 - * when we change direction 286 - */ 287 - 288 - nuc900_i2c_stop(i2c, -EINVAL); 289 - } 290 - 291 - goto retry_write; 292 - } else { 293 - /* send the new start */ 294 - nuc900_i2c_message_start(i2c, i2c->msg); 295 - i2c->state = STATE_START; 296 - } 297 - 298 - } else { 299 - /* send stop */ 300 - 301 - nuc900_i2c_stop(i2c, 0); 302 - } 303 - break; 304 - 305 - case STATE_READ: 306 - /* we have a byte of data in the data register, do 307 - * something with it, and then work out whether we are 308 - * going to do any more read/write 309 - */ 310 - 311 - byte = readb(i2c->regs + RXR); 312 - i2c->msg->buf[i2c->msg_ptr++] = byte; 313 - 314 - prepare_read: 315 - if (is_msglast(i2c)) { 316 - /* last byte of buffer */ 317 - 318 - if (is_lastmsg(i2c)) 319 - writel(I2C_CMD_READ | I2C_CMD_NACK, 320 - i2c->regs + CMDR); 321 - 322 - } else if (is_msgend(i2c)) { 323 - /* ok, we've read the entire buffer, see if there 324 - * is anything else we need to do 325 - */ 326 - 327 - if (is_lastmsg(i2c)) { 328 - /* last message, send stop and complete */ 329 - dev_dbg(i2c->dev, "READ: Send Stop\n"); 330 - 331 - nuc900_i2c_stop(i2c, 0); 332 - } else { 333 - /* go to the next transfer */ 334 - dev_dbg(i2c->dev, "READ: Next Transfer\n"); 335 - 336 - i2c->msg_ptr = 0; 337 - i2c->msg_idx++; 338 - i2c->msg++; 339 - 340 - writel(I2C_CMD_READ, i2c->regs + CMDR); 341 - } 342 - 343 - } else { 344 - writel(I2C_CMD_READ, i2c->regs + CMDR); 345 - } 346 - 347 - break; 348 - } 349 - } 350 - 351 - /* nuc900_i2c_irq 352 - * 353 - * top level IRQ servicing routine 354 - */ 355 - 356 - static irqreturn_t nuc900_i2c_irq(int irqno, void *dev_id) 357 - { 358 - struct nuc900_i2c *i2c = dev_id; 359 - unsigned long status; 360 - 361 - status = readl(i2c->regs + CSR); 362 - writel(status | IRQFLAG, i2c->regs + CSR); 363 - 364 - if (status & ARBIT_LOST) { 365 - /* deal with arbitration loss */ 366 - dev_err(i2c->dev, "deal with arbitration loss\n"); 367 - goto out; 368 - } 369 - 370 - if (i2c->state == STATE_IDLE) { 371 - dev_dbg(i2c->dev, "IRQ: error i2c->state == IDLE\n"); 372 - goto out; 373 - } 374 - 375 - /* pretty much this leaves us with the fact that we've 376 - * transmitted or received whatever byte we last sent 377 - */ 378 - 379 - i2c_nuc900_irq_nextbyte(i2c, status); 380 - 381 - out: 382 - return IRQ_HANDLED; 383 - } 384 - 385 - 386 - /* nuc900_i2c_set_master 387 - * 388 - * get the i2c bus for a master transaction 389 - */ 390 - 391 - static int nuc900_i2c_set_master(struct nuc900_i2c *i2c) 392 - { 393 - int timeout = 400; 394 - 395 - while (timeout-- > 0) { 396 - if (((readl(i2c->regs + SWR) & I2CSTART) == I2CSTART) && 397 - ((readl(i2c->regs + CSR) & I2CBUSY) == 0)) { 398 - return 0; 399 - } 400 - 401 - msleep(1); 402 - } 403 - 404 - return -ETIMEDOUT; 405 - } 406 - 407 - /* nuc900_i2c_doxfer 408 - * 409 - * this starts an i2c transfer 410 - */ 411 - 412 - static int nuc900_i2c_doxfer(struct nuc900_i2c *i2c, 413 - struct i2c_msg *msgs, int num) 414 - { 415 - unsigned long iicstat, timeout; 416 - int spins = 20; 417 - int ret; 418 - 419 - ret = nuc900_i2c_set_master(i2c); 420 - if (ret != 0) { 421 - dev_err(i2c->dev, "cannot get bus (error %d)\n", ret); 422 - ret = -EAGAIN; 423 - goto out; 424 - } 425 - 426 - spin_lock_irq(&i2c->lock); 427 - 428 - i2c->msg = msgs; 429 - i2c->msg_num = num; 430 - i2c->msg_ptr = 0; 431 - i2c->msg_idx = 0; 432 - i2c->state = STATE_START; 433 - 434 - nuc900_i2c_message_start(i2c, msgs); 435 - spin_unlock_irq(&i2c->lock); 436 - 437 - timeout = wait_event_timeout(i2c->wait, i2c->msg_num == 0, HZ * 5); 438 - 439 - ret = i2c->msg_idx; 440 - 441 - /* having these next two as dev_err() makes life very 442 - * noisy when doing an i2cdetect 443 - */ 444 - 445 - if (timeout == 0) 446 - dev_dbg(i2c->dev, "timeout\n"); 447 - else if (ret != num) 448 - dev_dbg(i2c->dev, "incomplete xfer (%d)\n", ret); 449 - 450 - /* ensure the stop has been through the bus */ 451 - 452 - dev_dbg(i2c->dev, "waiting for bus idle\n"); 453 - 454 - /* first, try busy waiting briefly */ 455 - do { 456 - iicstat = readl(i2c->regs + CSR); 457 - } while ((iicstat & I2CBUSY) && --spins); 458 - 459 - /* if that timed out sleep */ 460 - if (!spins) { 461 - msleep(1); 462 - iicstat = readl(i2c->regs + CSR); 463 - } 464 - 465 - if (iicstat & I2CBUSY) 466 - dev_warn(i2c->dev, "timeout waiting for bus idle\n"); 467 - 468 - out: 469 - return ret; 470 - } 471 - 472 - /* nuc900_i2c_xfer 473 - * 474 - * first port of call from the i2c bus code when an message needs 475 - * transferring across the i2c bus. 476 - */ 477 - 478 - static int nuc900_i2c_xfer(struct i2c_adapter *adap, 479 - struct i2c_msg *msgs, int num) 480 - { 481 - struct nuc900_i2c *i2c = (struct nuc900_i2c *)adap->algo_data; 482 - int retry; 483 - int ret; 484 - 485 - nuc900_i2c_enable_irq(i2c); 486 - 487 - for (retry = 0; retry < adap->retries; retry++) { 488 - 489 - ret = nuc900_i2c_doxfer(i2c, msgs, num); 490 - 491 - if (ret != -EAGAIN) 492 - return ret; 493 - 494 - dev_dbg(i2c->dev, "Retrying transmission (%d)\n", retry); 495 - 496 - udelay(100); 497 - } 498 - 499 - return -EREMOTEIO; 500 - } 501 - 502 - /* declare our i2c functionality */ 503 - static u32 nuc900_i2c_func(struct i2c_adapter *adap) 504 - { 505 - return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_NOSTART | 506 - I2C_FUNC_PROTOCOL_MANGLING; 507 - } 508 - 509 - /* i2c bus registration info */ 510 - 511 - static const struct i2c_algorithm nuc900_i2c_algorithm = { 512 - .master_xfer = nuc900_i2c_xfer, 513 - .functionality = nuc900_i2c_func, 514 - }; 515 - 516 - /* nuc900_i2c_probe 517 - * 518 - * called by the bus driver when a suitable device is found 519 - */ 520 - 521 - static int nuc900_i2c_probe(struct platform_device *pdev) 522 - { 523 - struct nuc900_i2c *i2c; 524 - struct nuc900_platform_i2c *pdata; 525 - struct resource *res; 526 - int ret; 527 - 528 - pdata = dev_get_platdata(&pdev->dev); 529 - if (!pdata) { 530 - dev_err(&pdev->dev, "no platform data\n"); 531 - return -EINVAL; 532 - } 533 - 534 - i2c = kzalloc(sizeof(struct nuc900_i2c), GFP_KERNEL); 535 - if (!i2c) { 536 - dev_err(&pdev->dev, "no memory for state\n"); 537 - return -ENOMEM; 538 - } 539 - 540 - strlcpy(i2c->adap.name, "nuc900-i2c0", sizeof(i2c->adap.name)); 541 - i2c->adap.owner = THIS_MODULE; 542 - i2c->adap.algo = &nuc900_i2c_algorithm; 543 - i2c->adap.retries = 2; 544 - i2c->adap.class = I2C_CLASS_HWMON | I2C_CLASS_SPD; 545 - 546 - spin_lock_init(&i2c->lock); 547 - init_waitqueue_head(&i2c->wait); 548 - 549 - /* find the clock and enable it */ 550 - 551 - i2c->dev = &pdev->dev; 552 - i2c->clk = clk_get(&pdev->dev, NULL); 553 - if (IS_ERR(i2c->clk)) { 554 - dev_err(&pdev->dev, "cannot get clock\n"); 555 - ret = -ENOENT; 556 - goto err_noclk; 557 - } 558 - 559 - dev_dbg(&pdev->dev, "clock source %p\n", i2c->clk); 560 - 561 - clk_enable(i2c->clk); 562 - 563 - /* map the registers */ 564 - 565 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 566 - if (res == NULL) { 567 - dev_err(&pdev->dev, "cannot find IO resource\n"); 568 - ret = -ENOENT; 569 - goto err_clk; 570 - } 571 - 572 - i2c->ioarea = request_mem_region(res->start, resource_size(res), 573 - pdev->name); 574 - 575 - if (i2c->ioarea == NULL) { 576 - dev_err(&pdev->dev, "cannot request IO\n"); 577 - ret = -ENXIO; 578 - goto err_clk; 579 - } 580 - 581 - i2c->regs = ioremap(res->start, resource_size(res)); 582 - 583 - if (i2c->regs == NULL) { 584 - dev_err(&pdev->dev, "cannot map IO\n"); 585 - ret = -ENXIO; 586 - goto err_ioarea; 587 - } 588 - 589 - dev_dbg(&pdev->dev, "registers %p (%p, %p)\n", 590 - i2c->regs, i2c->ioarea, res); 591 - 592 - /* setup info block for the i2c core */ 593 - 594 - i2c->adap.algo_data = i2c; 595 - i2c->adap.dev.parent = &pdev->dev; 596 - 597 - mfp_set_groupg(&pdev->dev, NULL); 598 - 599 - clk_get_rate(i2c->clk); 600 - 601 - ret = (i2c->clk.apbfreq)/(pdata->bus_freq * 5) - 1; 602 - writel(ret & 0xffff, i2c->regs + DIVIDER); 603 - 604 - /* find the IRQ for this unit (note, this relies on the init call to 605 - * ensure no current IRQs pending 606 - */ 607 - 608 - i2c->irq = ret = platform_get_irq(pdev, 0); 609 - if (ret <= 0) { 610 - dev_err(&pdev->dev, "cannot find IRQ\n"); 611 - goto err_iomap; 612 - } 613 - 614 - ret = request_irq(i2c->irq, nuc900_i2c_irq, IRQF_SHARED, 615 - dev_name(&pdev->dev), i2c); 616 - 617 - if (ret != 0) { 618 - dev_err(&pdev->dev, "cannot claim IRQ %d\n", i2c->irq); 619 - goto err_iomap; 620 - } 621 - 622 - /* Note, previous versions of the driver used i2c_add_adapter() 623 - * to add the bus at any number. We now pass the bus number via 624 - * the platform data, so if unset it will now default to always 625 - * being bus 0. 626 - */ 627 - 628 - i2c->adap.nr = pdata->bus_num; 629 - 630 - ret = i2c_add_numbered_adapter(&i2c->adap); 631 - if (ret < 0) { 632 - dev_err(&pdev->dev, "failed to add bus to i2c core\n"); 633 - goto err_irq; 634 - } 635 - 636 - platform_set_drvdata(pdev, i2c); 637 - 638 - dev_info(&pdev->dev, "%s: NUC900 I2C adapter\n", 639 - dev_name(&i2c->adap.dev)); 640 - return 0; 641 - 642 - err_irq: 643 - free_irq(i2c->irq, i2c); 644 - 645 - err_iomap: 646 - iounmap(i2c->regs); 647 - 648 - err_ioarea: 649 - release_resource(i2c->ioarea); 650 - kfree(i2c->ioarea); 651 - 652 - err_clk: 653 - clk_disable(i2c->clk); 654 - clk_put(i2c->clk); 655 - 656 - err_noclk: 657 - kfree(i2c); 658 - return ret; 659 - } 660 - 661 - /* nuc900_i2c_remove 662 - * 663 - * called when device is removed from the bus 664 - */ 665 - 666 - static int nuc900_i2c_remove(struct platform_device *pdev) 667 - { 668 - struct nuc900_i2c *i2c = platform_get_drvdata(pdev); 669 - 670 - i2c_del_adapter(&i2c->adap); 671 - free_irq(i2c->irq, i2c); 672 - 673 - clk_disable(i2c->clk); 674 - clk_put(i2c->clk); 675 - 676 - iounmap(i2c->regs); 677 - 678 - release_resource(i2c->ioarea); 679 - kfree(i2c->ioarea); 680 - kfree(i2c); 681 - 682 - return 0; 683 - } 684 - 685 - static struct platform_driver nuc900_i2c_driver = { 686 - .probe = nuc900_i2c_probe, 687 - .remove = nuc900_i2c_remove, 688 - .driver = { 689 - .owner = THIS_MODULE, 690 - .name = "nuc900-i2c0", 691 - }, 692 - }; 693 - 694 - static int __init i2c_adap_nuc900_init(void) 695 - { 696 - return platform_driver_register(&nuc900_i2c_driver); 697 - } 698 - 699 - static void __exit i2c_adap_nuc900_exit(void) 700 - { 701 - platform_driver_unregister(&nuc900_i2c_driver); 702 - } 703 - subsys_initcall(i2c_adap_nuc900_init); 704 - module_exit(i2c_adap_nuc900_exit); 705 - 706 - MODULE_DESCRIPTION("NUC900 I2C Bus driver"); 707 - MODULE_AUTHOR("Wan ZongShun, <mcuos.com-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>"); 708 - MODULE_LICENSE("GPL"); 709 - MODULE_ALIAS("platform:nuc900-i2c0");
+1 -1
drivers/i2c/busses/i2c-ocores.c
··· 250 250 .algo = &ocores_algorithm, 251 251 }; 252 252 253 - static struct of_device_id ocores_i2c_match[] = { 253 + static const struct of_device_id ocores_i2c_match[] = { 254 254 { 255 255 .compatible = "opencores,i2c-ocores", 256 256 .data = (void *)TYPE_OCORES,
+1 -3
drivers/i2c/busses/i2c-omap.c
··· 1114 1114 } 1115 1115 1116 1116 dev = devm_kzalloc(&pdev->dev, sizeof(struct omap_i2c_dev), GFP_KERNEL); 1117 - if (!dev) { 1118 - dev_err(&pdev->dev, "Menory allocation failed\n"); 1117 + if (!dev) 1119 1118 return -ENOMEM; 1120 - } 1121 1119 1122 1120 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1123 1121 dev->base = devm_ioremap_resource(&pdev->dev, mem);
+1 -1
drivers/i2c/busses/i2c-pxa.c
··· 1084 1084 .functionality = i2c_pxa_functionality, 1085 1085 }; 1086 1086 1087 - static struct of_device_id i2c_pxa_dt_ids[] = { 1087 + static const struct of_device_id i2c_pxa_dt_ids[] = { 1088 1088 { .compatible = "mrvl,pxa-i2c", .data = (void *)REGS_PXA2XX }, 1089 1089 { .compatible = "mrvl,pwri2c", .data = (void *)REGS_PXA3XX }, 1090 1090 { .compatible = "mrvl,mmp-twsi", .data = (void *)REGS_PXA2XX },
+52 -207
drivers/i2c/busses/i2c-rcar.c
··· 1 1 /* 2 - * drivers/i2c/busses/i2c-rcar.c 2 + * Driver for the Renesas RCar I2C unit 3 3 * 4 - * Copyright (C) 2012 Renesas Solutions Corp. 4 + * Copyright (C) 2014 Wolfram Sang <wsa@sang-engineering.com> 5 + * 6 + * Copyright (C) 2012-14 Renesas Solutions Corp. 5 7 * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> 6 8 * 7 9 * This file is based on the drivers/i2c/busses/i2c-sh7760.c ··· 14 12 * 15 13 * This program is free software; you can redistribute it and/or modify 16 14 * it under the terms of the GNU General Public License as published by 17 - * the Free Software Foundation; either version 2 of the License 15 + * the Free Software Foundation; version 2 of the License. 18 16 * 19 17 * This program is distributed in the hope that it will be useful, 20 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of 21 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 20 * GNU General Public License for more details. 23 - * 24 - * You should have received a copy of the GNU General Public License 25 - * along with this program; if not, write to the Free Software 26 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 27 21 */ 28 22 #include <linux/clk.h> 29 23 #include <linux/delay.h> ··· 34 36 #include <linux/platform_device.h> 35 37 #include <linux/pm_runtime.h> 36 38 #include <linux/slab.h> 37 - #include <linux/spinlock.h> 38 39 39 40 /* register offsets */ 40 41 #define ICSCR 0x00 /* slave ctrl */ ··· 57 60 #define FSB (1 << 1) /* force stop bit */ 58 61 #define ESG (1 << 0) /* en startbit gen */ 59 62 60 - /* ICMSR */ 63 + /* ICMSR (also for ICMIE) */ 61 64 #define MNR (1 << 6) /* nack received */ 62 65 #define MAL (1 << 5) /* arbitration lost */ 63 66 #define MST (1 << 4) /* sent a stop */ ··· 66 69 #define MDR (1 << 1) 67 70 #define MAT (1 << 0) /* slave addr xfer done */ 68 71 69 - /* ICMIE */ 70 - #define MNRE (1 << 6) /* nack irq en */ 71 - #define MALE (1 << 5) /* arblos irq en */ 72 - #define MSTE (1 << 4) /* stop irq en */ 73 - #define MDEE (1 << 3) 74 - #define MDTE (1 << 2) 75 - #define MDRE (1 << 1) 76 - #define MATE (1 << 0) /* address sent irq en */ 77 72 73 + #define RCAR_BUS_PHASE_START (MDBS | MIE | ESG) 74 + #define RCAR_BUS_PHASE_DATA (MDBS | MIE) 75 + #define RCAR_BUS_PHASE_STOP (MDBS | MIE | FSB) 78 76 79 - enum { 80 - RCAR_BUS_PHASE_ADDR, 81 - RCAR_BUS_PHASE_DATA, 82 - RCAR_BUS_PHASE_STOP, 83 - }; 77 + #define RCAR_IRQ_SEND (MNR | MAL | MST | MAT | MDE) 78 + #define RCAR_IRQ_RECV (MNR | MAL | MST | MAT | MDR) 79 + #define RCAR_IRQ_STOP (MST) 84 80 85 - enum { 86 - RCAR_IRQ_CLOSE, 87 - RCAR_IRQ_OPEN_FOR_SEND, 88 - RCAR_IRQ_OPEN_FOR_RECV, 89 - RCAR_IRQ_OPEN_FOR_STOP, 90 - }; 81 + #define RCAR_IRQ_ACK_SEND (~(MAT | MDE)) 82 + #define RCAR_IRQ_ACK_RECV (~(MAT | MDR)) 91 83 92 - /* 93 - * flags 94 - */ 95 84 #define ID_LAST_MSG (1 << 0) 96 85 #define ID_IOERROR (1 << 1) 97 86 #define ID_DONE (1 << 2) ··· 95 112 struct i2c_msg *msg; 96 113 struct clk *clk; 97 114 98 - spinlock_t lock; 99 115 wait_queue_head_t wait; 100 116 101 117 int pos; 102 - int irq; 103 118 u32 icccr; 104 119 u32 flags; 105 - enum rcar_i2c_type devtype; 120 + enum rcar_i2c_type devtype; 106 121 }; 107 122 108 123 #define rcar_i2c_priv_to_dev(p) ((p)->adap.dev.parent) ··· 111 130 112 131 #define LOOP_TIMEOUT 1024 113 132 114 - /* 115 - * basic functions 116 - */ 133 + 117 134 static void rcar_i2c_write(struct rcar_i2c_priv *priv, int reg, u32 val) 118 135 { 119 136 writel(val, priv->io + reg); ··· 140 161 rcar_i2c_write(priv, ICMAR, 0); 141 162 } 142 163 143 - static void rcar_i2c_irq_mask(struct rcar_i2c_priv *priv, int open) 144 - { 145 - u32 val = MNRE | MALE | MSTE | MATE; /* default */ 146 - 147 - switch (open) { 148 - case RCAR_IRQ_OPEN_FOR_SEND: 149 - val |= MDEE; /* default + send */ 150 - break; 151 - case RCAR_IRQ_OPEN_FOR_RECV: 152 - val |= MDRE; /* default + read */ 153 - break; 154 - case RCAR_IRQ_OPEN_FOR_STOP: 155 - val = MSTE; /* stop irq only */ 156 - break; 157 - case RCAR_IRQ_CLOSE: 158 - default: 159 - val = 0; /* all close */ 160 - break; 161 - } 162 - rcar_i2c_write(priv, ICMIER, val); 163 - } 164 - 165 - static void rcar_i2c_set_addr(struct rcar_i2c_priv *priv, u32 recv) 166 - { 167 - rcar_i2c_write(priv, ICMAR, (priv->msg->addr << 1) | recv); 168 - } 169 - 170 - /* 171 - * bus control functions 172 - */ 173 164 static int rcar_i2c_bus_barrier(struct rcar_i2c_priv *priv) 174 165 { 175 166 int i; ··· 154 205 return -EBUSY; 155 206 } 156 207 157 - static void rcar_i2c_bus_phase(struct rcar_i2c_priv *priv, int phase) 158 - { 159 - switch (phase) { 160 - case RCAR_BUS_PHASE_ADDR: 161 - rcar_i2c_write(priv, ICMCR, MDBS | MIE | ESG); 162 - break; 163 - case RCAR_BUS_PHASE_DATA: 164 - rcar_i2c_write(priv, ICMCR, MDBS | MIE); 165 - break; 166 - case RCAR_BUS_PHASE_STOP: 167 - rcar_i2c_write(priv, ICMCR, MDBS | MIE | FSB); 168 - break; 169 - } 170 - } 171 - 172 - /* 173 - * clock function 174 - */ 175 208 static int rcar_i2c_clock_calculate(struct rcar_i2c_priv *priv, 176 209 u32 bus_speed, 177 210 struct device *dev) ··· 243 312 return 0; 244 313 } 245 314 246 - static void rcar_i2c_clock_start(struct rcar_i2c_priv *priv) 315 + static int rcar_i2c_prepare_msg(struct rcar_i2c_priv *priv) 247 316 { 248 - rcar_i2c_write(priv, ICCCR, priv->icccr); 249 - } 317 + int read = !!rcar_i2c_is_recv(priv); 250 318 251 - /* 252 - * status functions 253 - */ 254 - static u32 rcar_i2c_status_get(struct rcar_i2c_priv *priv) 255 - { 256 - return rcar_i2c_read(priv, ICMSR); 257 - } 258 - 259 - #define rcar_i2c_status_clear(priv) rcar_i2c_status_bit_clear(priv, 0xffffffff) 260 - static void rcar_i2c_status_bit_clear(struct rcar_i2c_priv *priv, u32 bit) 261 - { 262 - rcar_i2c_write(priv, ICMSR, ~bit); 263 - } 264 - 265 - /* 266 - * recv/send functions 267 - */ 268 - static int rcar_i2c_recv(struct rcar_i2c_priv *priv) 269 - { 270 - rcar_i2c_set_addr(priv, 1); 271 - rcar_i2c_status_clear(priv); 272 - rcar_i2c_bus_phase(priv, RCAR_BUS_PHASE_ADDR); 273 - rcar_i2c_irq_mask(priv, RCAR_IRQ_OPEN_FOR_RECV); 319 + rcar_i2c_write(priv, ICMAR, (priv->msg->addr << 1) | read); 320 + rcar_i2c_write(priv, ICMSR, 0); 321 + rcar_i2c_write(priv, ICMCR, RCAR_BUS_PHASE_START); 322 + rcar_i2c_write(priv, ICMIER, read ? RCAR_IRQ_RECV : RCAR_IRQ_SEND); 274 323 275 324 return 0; 276 325 } 277 - 278 - static int rcar_i2c_send(struct rcar_i2c_priv *priv) 279 - { 280 - int ret; 281 - 282 - /* 283 - * It should check bus status when send case 284 - */ 285 - ret = rcar_i2c_bus_barrier(priv); 286 - if (ret < 0) 287 - return ret; 288 - 289 - rcar_i2c_set_addr(priv, 0); 290 - rcar_i2c_status_clear(priv); 291 - rcar_i2c_bus_phase(priv, RCAR_BUS_PHASE_ADDR); 292 - rcar_i2c_irq_mask(priv, RCAR_IRQ_OPEN_FOR_SEND); 293 - 294 - return 0; 295 - } 296 - 297 - #define rcar_i2c_send_restart(priv) rcar_i2c_status_bit_clear(priv, (MAT | MDE)) 298 - #define rcar_i2c_recv_restart(priv) rcar_i2c_status_bit_clear(priv, (MAT | MDR)) 299 326 300 327 /* 301 328 * interrupt functions ··· 275 386 * goto data phase. 276 387 */ 277 388 if (msr & MAT) 278 - rcar_i2c_bus_phase(priv, RCAR_BUS_PHASE_DATA); 389 + rcar_i2c_write(priv, ICMCR, RCAR_BUS_PHASE_DATA); 279 390 280 391 if (priv->pos < msg->len) { 281 392 /* ··· 303 414 * prepare stop condition here. 304 415 * ID_DONE will be set on STOP irq. 305 416 */ 306 - rcar_i2c_bus_phase(priv, RCAR_BUS_PHASE_STOP); 417 + rcar_i2c_write(priv, ICMCR, RCAR_BUS_PHASE_STOP); 307 418 else 308 419 /* 309 420 * If current msg is _NOT_ last msg, ··· 314 425 return ID_DONE; 315 426 } 316 427 317 - rcar_i2c_send_restart(priv); 428 + rcar_i2c_write(priv, ICMSR, RCAR_IRQ_ACK_SEND); 318 429 319 430 return 0; 320 431 } ··· 351 462 * otherwise, go to DATA phase. 352 463 */ 353 464 if (priv->pos + 1 >= msg->len) 354 - rcar_i2c_bus_phase(priv, RCAR_BUS_PHASE_STOP); 465 + rcar_i2c_write(priv, ICMCR, RCAR_BUS_PHASE_STOP); 355 466 else 356 - rcar_i2c_bus_phase(priv, RCAR_BUS_PHASE_DATA); 467 + rcar_i2c_write(priv, ICMCR, RCAR_BUS_PHASE_DATA); 357 468 358 - rcar_i2c_recv_restart(priv); 469 + rcar_i2c_write(priv, ICMSR, RCAR_IRQ_ACK_RECV); 359 470 360 471 return 0; 361 472 } ··· 363 474 static irqreturn_t rcar_i2c_irq(int irq, void *ptr) 364 475 { 365 476 struct rcar_i2c_priv *priv = ptr; 366 - struct device *dev = rcar_i2c_priv_to_dev(priv); 367 477 u32 msr; 368 478 369 - /*-------------- spin lock -----------------*/ 370 - spin_lock(&priv->lock); 479 + msr = rcar_i2c_read(priv, ICMSR); 371 480 372 - msr = rcar_i2c_status_get(priv); 373 - 374 - /* 375 - * Arbitration lost 376 - */ 481 + /* Arbitration lost */ 377 482 if (msr & MAL) { 378 - /* 379 - * CAUTION 380 - * 381 - * When arbitration lost, device become _slave_ mode. 382 - */ 383 - dev_dbg(dev, "Arbitration Lost\n"); 384 483 rcar_i2c_flags_set(priv, (ID_DONE | ID_ARBLOST)); 385 484 goto out; 386 485 } 387 486 388 - /* 389 - * Stop 390 - */ 487 + /* Stop */ 391 488 if (msr & MST) { 392 - dev_dbg(dev, "Stop\n"); 393 489 rcar_i2c_flags_set(priv, ID_DONE); 394 490 goto out; 395 491 } 396 492 397 - /* 398 - * Nack 399 - */ 493 + /* Nack */ 400 494 if (msr & MNR) { 401 - dev_dbg(dev, "Nack\n"); 402 - 403 495 /* go to stop phase */ 404 - rcar_i2c_bus_phase(priv, RCAR_BUS_PHASE_STOP); 405 - rcar_i2c_irq_mask(priv, RCAR_IRQ_OPEN_FOR_STOP); 496 + rcar_i2c_write(priv, ICMCR, RCAR_BUS_PHASE_STOP); 497 + rcar_i2c_write(priv, ICMIER, RCAR_IRQ_STOP); 406 498 rcar_i2c_flags_set(priv, ID_NACK); 407 499 goto out; 408 500 } 409 501 410 - /* 411 - * recv/send 412 - */ 413 502 if (rcar_i2c_is_recv(priv)) 414 503 rcar_i2c_flags_set(priv, rcar_i2c_irq_recv(priv, msr)); 415 504 else ··· 395 528 396 529 out: 397 530 if (rcar_i2c_flags_has(priv, ID_DONE)) { 398 - rcar_i2c_irq_mask(priv, RCAR_IRQ_CLOSE); 399 - rcar_i2c_status_clear(priv); 531 + rcar_i2c_write(priv, ICMIER, 0); 532 + rcar_i2c_write(priv, ICMSR, 0); 400 533 wake_up(&priv->wait); 401 534 } 402 - 403 - spin_unlock(&priv->lock); 404 - /*-------------- spin unlock -----------------*/ 405 535 406 536 return IRQ_HANDLED; 407 537 } ··· 409 545 { 410 546 struct rcar_i2c_priv *priv = i2c_get_adapdata(adap); 411 547 struct device *dev = rcar_i2c_priv_to_dev(priv); 412 - unsigned long flags; 413 548 int i, ret, timeout; 414 549 415 550 pm_runtime_get_sync(dev); 416 551 417 - /*-------------- spin lock -----------------*/ 418 - spin_lock_irqsave(&priv->lock, flags); 419 - 420 552 rcar_i2c_init(priv); 421 - rcar_i2c_clock_start(priv); 553 + /* start clock */ 554 + rcar_i2c_write(priv, ICCCR, priv->icccr); 422 555 423 - spin_unlock_irqrestore(&priv->lock, flags); 424 - /*-------------- spin unlock -----------------*/ 556 + ret = rcar_i2c_bus_barrier(priv); 557 + if (ret < 0) 558 + goto out; 425 559 426 - ret = -EINVAL; 427 560 for (i = 0; i < num; i++) { 428 561 /* This HW can't send STOP after address phase */ 429 562 if (msgs[i].len == 0) { 430 563 ret = -EOPNOTSUPP; 431 564 break; 432 565 } 433 - 434 - /*-------------- spin lock -----------------*/ 435 - spin_lock_irqsave(&priv->lock, flags); 436 566 437 567 /* init each data */ 438 568 priv->msg = &msgs[i]; ··· 435 577 if (priv->msg == &msgs[num - 1]) 436 578 rcar_i2c_flags_set(priv, ID_LAST_MSG); 437 579 438 - /* start send/recv */ 439 - if (rcar_i2c_is_recv(priv)) 440 - ret = rcar_i2c_recv(priv); 441 - else 442 - ret = rcar_i2c_send(priv); 443 - 444 - spin_unlock_irqrestore(&priv->lock, flags); 445 - /*-------------- spin unlock -----------------*/ 580 + ret = rcar_i2c_prepare_msg(priv); 446 581 447 582 if (ret < 0) 448 583 break; 449 584 450 - /* 451 - * wait result 452 - */ 453 585 timeout = wait_event_timeout(priv->wait, 454 586 rcar_i2c_flags_has(priv, ID_DONE), 455 587 5 * HZ); ··· 448 600 break; 449 601 } 450 602 451 - /* 452 - * error handling 453 - */ 454 603 if (rcar_i2c_flags_has(priv, ID_NACK)) { 455 604 ret = -ENXIO; 456 605 break; ··· 465 620 466 621 ret = i + 1; /* The number of transfer */ 467 622 } 468 - 623 + out: 469 624 pm_runtime_put(dev); 470 625 471 626 if (ret < 0 && ret != -ENXIO) ··· 491 646 { .compatible = "renesas,i2c-r8a7779", .data = (void *)I2C_RCAR_GEN1 }, 492 647 { .compatible = "renesas,i2c-r8a7790", .data = (void *)I2C_RCAR_GEN2 }, 493 648 { .compatible = "renesas,i2c-r8a7791", .data = (void *)I2C_RCAR_GEN2 }, 649 + { .compatible = "renesas,i2c-r8a7792", .data = (void *)I2C_RCAR_GEN2 }, 650 + { .compatible = "renesas,i2c-r8a7793", .data = (void *)I2C_RCAR_GEN2 }, 651 + { .compatible = "renesas,i2c-r8a7794", .data = (void *)I2C_RCAR_GEN2 }, 494 652 {}, 495 653 }; 496 654 MODULE_DEVICE_TABLE(of, rcar_i2c_dt_ids); ··· 506 658 struct resource *res; 507 659 struct device *dev = &pdev->dev; 508 660 u32 bus_speed; 509 - int ret; 661 + int irq, ret; 510 662 511 663 priv = devm_kzalloc(dev, sizeof(struct rcar_i2c_priv), GFP_KERNEL); 512 - if (!priv) { 513 - dev_err(dev, "no mem for private data\n"); 664 + if (!priv) 514 665 return -ENOMEM; 515 - } 516 666 517 667 priv->clk = devm_clk_get(dev, NULL); 518 668 if (IS_ERR(priv->clk)) { ··· 538 692 if (IS_ERR(priv->io)) 539 693 return PTR_ERR(priv->io); 540 694 541 - priv->irq = platform_get_irq(pdev, 0); 695 + irq = platform_get_irq(pdev, 0); 542 696 init_waitqueue_head(&priv->wait); 543 - spin_lock_init(&priv->lock); 544 697 545 698 adap = &priv->adap; 546 699 adap->nr = pdev->id; ··· 551 706 i2c_set_adapdata(adap, priv); 552 707 strlcpy(adap->name, pdev->name, sizeof(adap->name)); 553 708 554 - ret = devm_request_irq(dev, priv->irq, rcar_i2c_irq, 0, 709 + ret = devm_request_irq(dev, irq, rcar_i2c_irq, 0, 555 710 dev_name(dev), priv); 556 711 if (ret < 0) { 557 - dev_err(dev, "cannot get irq %d\n", priv->irq); 712 + dev_err(dev, "cannot get irq %d\n", irq); 558 713 return ret; 559 714 } 560 715 ··· 604 759 605 760 module_platform_driver(rcar_i2c_driver); 606 761 607 - MODULE_LICENSE("GPL"); 762 + MODULE_LICENSE("GPL v2"); 608 763 MODULE_DESCRIPTION("Renesas R-Car I2C bus driver"); 609 764 MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>");
+1 -1
drivers/i2c/busses/i2c-riic.c
··· 404 404 return 0; 405 405 } 406 406 407 - static struct of_device_id riic_i2c_dt_ids[] = { 407 + static const struct of_device_id riic_i2c_dt_ids[] = { 408 408 { .compatible = "renesas,riic-rz" }, 409 409 { /* Sentinel */ }, 410 410 };
+2 -6
drivers/i2c/busses/i2c-s3c2410.c
··· 1114 1114 } 1115 1115 1116 1116 i2c = devm_kzalloc(&pdev->dev, sizeof(struct s3c24xx_i2c), GFP_KERNEL); 1117 - if (!i2c) { 1118 - dev_err(&pdev->dev, "no memory for state\n"); 1117 + if (!i2c) 1119 1118 return -ENOMEM; 1120 - } 1121 1119 1122 1120 i2c->pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); 1123 - if (!i2c->pdata) { 1124 - dev_err(&pdev->dev, "no memory for platform data\n"); 1121 + if (!i2c->pdata) 1125 1122 return -ENOMEM; 1126 - } 1127 1123 1128 1124 i2c->quirks = s3c24xx_get_device_quirks(pdev); 1129 1125 if (pdata)
+107 -118
drivers/i2c/busses/i2c-sh_mobile.c
··· 32 32 #include <linux/clk.h> 33 33 #include <linux/io.h> 34 34 #include <linux/slab.h> 35 + #include <linux/of_device.h> 35 36 #include <linux/i2c/i2c-sh_mobile.h> 36 37 37 38 /* Transmit operation: */ ··· 140 139 bool send_stop; 141 140 }; 142 141 142 + struct sh_mobile_dt_config { 143 + int clks_per_count; 144 + }; 145 + 143 146 #define IIC_FLAG_HAS_ICIC67 (1 << 0) 144 147 145 148 #define STANDARD_MODE 100000 ··· 199 194 iic_wr(pd, offs, (iic_rd(pd, offs) | set) & ~clr); 200 195 } 201 196 202 - static u32 sh_mobile_i2c_iccl(unsigned long count_khz, u32 tLOW, u32 tf, int offset) 197 + static u32 sh_mobile_i2c_iccl(unsigned long count_khz, u32 tLOW, u32 tf) 203 198 { 204 199 /* 205 200 * Conditional expression: ··· 211 206 * account the fall time of SCL signal (tf). Default tf value 212 207 * should be 0.3 us, for safety. 213 208 */ 214 - return (((count_khz * (tLOW + tf)) + 5000) / 10000) + offset; 209 + return (((count_khz * (tLOW + tf)) + 5000) / 10000); 215 210 } 216 211 217 - static u32 sh_mobile_i2c_icch(unsigned long count_khz, u32 tHIGH, u32 tf, int offset) 212 + static u32 sh_mobile_i2c_icch(unsigned long count_khz, u32 tHIGH, u32 tf) 218 213 { 219 214 /* 220 215 * Conditional expression: ··· 230 225 * to take into account the fall time of SDA signal (tf) at START 231 226 * condition, in order to meet both tHIGH and tHD;STA specs. 232 227 */ 233 - return (((count_khz * (tHIGH + tf)) + 5000) / 10000) + offset; 228 + return (((count_khz * (tHIGH + tf)) + 5000) / 10000); 234 229 } 235 230 236 - static void sh_mobile_i2c_init(struct sh_mobile_i2c_data *pd) 231 + static int sh_mobile_i2c_init(struct sh_mobile_i2c_data *pd) 237 232 { 238 233 unsigned long i2c_clk_khz; 239 234 u32 tHIGH, tLOW, tf; 240 - int offset; 235 + uint16_t max_val; 241 236 242 237 /* Get clock rate after clock is enabled */ 243 238 clk_prepare_enable(pd->clk); 244 239 i2c_clk_khz = clk_get_rate(pd->clk) / 1000; 240 + clk_disable_unprepare(pd->clk); 245 241 i2c_clk_khz /= pd->clks_per_count; 246 242 247 243 if (pd->bus_speed == STANDARD_MODE) { 248 244 tLOW = 47; /* tLOW = 4.7 us */ 249 245 tHIGH = 40; /* tHD;STA = tHIGH = 4.0 us */ 250 246 tf = 3; /* tf = 0.3 us */ 251 - offset = 0; /* No offset */ 252 247 } else if (pd->bus_speed == FAST_MODE) { 253 248 tLOW = 13; /* tLOW = 1.3 us */ 254 249 tHIGH = 6; /* tHD;STA = tHIGH = 0.6 us */ 255 250 tf = 3; /* tf = 0.3 us */ 256 - offset = 0; /* No offset */ 257 251 } else { 258 252 dev_err(pd->dev, "unrecognized bus speed %lu Hz\n", 259 253 pd->bus_speed); 260 - goto out; 254 + return -EINVAL; 261 255 } 262 256 263 - pd->iccl = sh_mobile_i2c_iccl(i2c_clk_khz, tLOW, tf, offset); 257 + pd->iccl = sh_mobile_i2c_iccl(i2c_clk_khz, tLOW, tf); 258 + pd->icch = sh_mobile_i2c_icch(i2c_clk_khz, tHIGH, tf); 259 + 260 + max_val = pd->flags & IIC_FLAG_HAS_ICIC67 ? 0x1ff : 0xff; 261 + if (pd->iccl > max_val || pd->icch > max_val) { 262 + dev_err(pd->dev, "timing values out of range: L/H=0x%x/0x%x\n", 263 + pd->iccl, pd->icch); 264 + return -EINVAL; 265 + } 266 + 264 267 /* one more bit of ICCL in ICIC */ 265 - if ((pd->iccl > 0xff) && (pd->flags & IIC_FLAG_HAS_ICIC67)) 268 + if (pd->iccl & 0x100) 266 269 pd->icic |= ICIC_ICCLB8; 267 270 else 268 271 pd->icic &= ~ICIC_ICCLB8; 269 272 270 - pd->icch = sh_mobile_i2c_icch(i2c_clk_khz, tHIGH, tf, offset); 271 273 /* one more bit of ICCH in ICIC */ 272 - if ((pd->icch > 0xff) && (pd->flags & IIC_FLAG_HAS_ICIC67)) 274 + if (pd->icch & 0x100) 273 275 pd->icic |= ICIC_ICCHB8; 274 276 else 275 277 pd->icic &= ~ICIC_ICCHB8; 276 278 277 - out: 278 - clk_disable_unprepare(pd->clk); 279 + return 0; 279 280 } 280 281 281 282 static void activate_ch(struct sh_mobile_i2c_data *pd) ··· 327 316 328 317 switch (op) { 329 318 case OP_START: /* issue start and trigger DTE interrupt */ 330 - iic_wr(pd, ICCR, 0x94); 319 + iic_wr(pd, ICCR, ICCR_ICE | ICCR_TRS | ICCR_BBSY); 331 320 break; 332 321 case OP_TX_FIRST: /* disable DTE interrupt and write data */ 333 322 iic_wr(pd, ICIC, ICIC_WAITE | ICIC_ALE | ICIC_TACKE); ··· 338 327 break; 339 328 case OP_TX_STOP: /* write data and issue a stop afterwards */ 340 329 iic_wr(pd, ICDR, data); 341 - iic_wr(pd, ICCR, pd->send_stop ? 0x90 : 0x94); 330 + iic_wr(pd, ICCR, pd->send_stop ? ICCR_ICE | ICCR_TRS 331 + : ICCR_ICE | ICCR_TRS | ICCR_BBSY); 342 332 break; 343 333 case OP_TX_TO_RX: /* select read mode */ 344 - iic_wr(pd, ICCR, 0x81); 334 + iic_wr(pd, ICCR, ICCR_ICE | ICCR_SCP); 345 335 break; 346 336 case OP_RX: /* just read data */ 347 337 ret = iic_rd(pd, ICDR); ··· 350 338 case OP_RX_STOP: /* enable DTE interrupt, issue stop */ 351 339 iic_wr(pd, ICIC, 352 340 ICIC_DTEE | ICIC_WAITE | ICIC_ALE | ICIC_TACKE); 353 - iic_wr(pd, ICCR, 0xc0); 341 + iic_wr(pd, ICCR, ICCR_ICE | ICCR_RACK); 354 342 break; 355 343 case OP_RX_STOP_DATA: /* enable DTE interrupt, read data, issue stop */ 356 344 iic_wr(pd, ICIC, 357 345 ICIC_DTEE | ICIC_WAITE | ICIC_ALE | ICIC_TACKE); 358 346 ret = iic_rd(pd, ICDR); 359 - iic_wr(pd, ICCR, 0xc0); 347 + iic_wr(pd, ICCR, ICCR_ICE | ICCR_RACK); 360 348 break; 361 349 } 362 350 ··· 491 479 { 492 480 if (usr_msg->len == 0 && (usr_msg->flags & I2C_M_RD)) { 493 481 dev_err(pd->dev, "Unsupported zero length i2c read\n"); 494 - return -EIO; 482 + return -EOPNOTSUPP; 495 483 } 496 484 497 485 if (do_init) { ··· 526 514 break; 527 515 528 516 if (val & ICSR_TACK) 529 - return -EIO; 517 + return -ENXIO; 530 518 531 519 udelay(10); 532 520 } 533 521 534 - if (!i) { 535 - dev_warn(pd->dev, "Timeout polling for DTE!\n"); 536 - return -ETIMEDOUT; 537 - } 538 - 539 - return 0; 522 + return i ? 0 : -ETIMEDOUT; 540 523 } 541 524 542 525 static int poll_busy(struct sh_mobile_i2c_data *pd) ··· 549 542 */ 550 543 if (!(val & ICSR_BUSY)) { 551 544 /* handle missing acknowledge and arbitration lost */ 552 - if ((val | pd->sr) & (ICSR_TACK | ICSR_AL)) 553 - return -EIO; 545 + val |= pd->sr; 546 + if (val & ICSR_TACK) 547 + return -ENXIO; 548 + if (val & ICSR_AL) 549 + return -EAGAIN; 554 550 break; 555 551 } 556 552 557 553 udelay(10); 558 554 } 559 555 560 - if (!i) { 561 - dev_err(pd->dev, "Polling timed out\n"); 562 - return -ETIMEDOUT; 563 - } 564 - 565 - return 0; 556 + return i ? 0 : -ETIMEDOUT; 566 557 } 567 558 568 559 static int sh_mobile_i2c_xfer(struct i2c_adapter *adapter, ··· 622 617 .master_xfer = sh_mobile_i2c_xfer, 623 618 }; 624 619 625 - static int sh_mobile_i2c_hook_irqs(struct platform_device *dev, int hook) 620 + static const struct sh_mobile_dt_config default_dt_config = { 621 + .clks_per_count = 1, 622 + }; 623 + 624 + static const struct sh_mobile_dt_config rcar_gen2_dt_config = { 625 + .clks_per_count = 2, 626 + }; 627 + 628 + static const struct of_device_id sh_mobile_i2c_dt_ids[] = { 629 + { .compatible = "renesas,rmobile-iic", .data = &default_dt_config }, 630 + { .compatible = "renesas,iic-r8a7790", .data = &rcar_gen2_dt_config }, 631 + { .compatible = "renesas,iic-r8a7791", .data = &rcar_gen2_dt_config }, 632 + { .compatible = "renesas,iic-r8a7792", .data = &rcar_gen2_dt_config }, 633 + { .compatible = "renesas,iic-r8a7793", .data = &rcar_gen2_dt_config }, 634 + { .compatible = "renesas,iic-r8a7794", .data = &rcar_gen2_dt_config }, 635 + {}, 636 + }; 637 + MODULE_DEVICE_TABLE(of, sh_mobile_i2c_dt_ids); 638 + 639 + static int sh_mobile_i2c_hook_irqs(struct platform_device *dev) 626 640 { 627 641 struct resource *res; 628 - int ret = -ENXIO; 629 - int n, k = 0; 642 + resource_size_t n; 643 + int k = 0, ret; 630 644 631 645 while ((res = platform_get_resource(dev, IORESOURCE_IRQ, k))) { 632 - for (n = res->start; hook && n <= res->end; n++) { 633 - if (request_irq(n, sh_mobile_i2c_isr, 0, 634 - dev_name(&dev->dev), dev)) { 635 - for (n--; n >= res->start; n--) 636 - free_irq(n, dev); 637 - 638 - goto rollback; 646 + for (n = res->start; n <= res->end; n++) { 647 + ret = devm_request_irq(&dev->dev, n, sh_mobile_i2c_isr, 648 + 0, dev_name(&dev->dev), dev); 649 + if (ret) { 650 + dev_err(&dev->dev, "cannot request IRQ %pa\n", &n); 651 + return ret; 639 652 } 640 653 } 641 654 k++; 642 655 } 643 656 644 - if (hook) 645 - return k > 0 ? 0 : -ENOENT; 646 - 647 - ret = 0; 648 - 649 - rollback: 650 - k--; 651 - 652 - while (k >= 0) { 653 - res = platform_get_resource(dev, IORESOURCE_IRQ, k); 654 - for (n = res->start; n <= res->end; n++) 655 - free_irq(n, dev); 656 - 657 - k--; 658 - } 659 - 660 - return ret; 657 + return k > 0 ? 0 : -ENOENT; 661 658 } 662 659 663 660 static int sh_mobile_i2c_probe(struct platform_device *dev) ··· 668 661 struct sh_mobile_i2c_data *pd; 669 662 struct i2c_adapter *adap; 670 663 struct resource *res; 671 - int size; 672 664 int ret; 665 + u32 bus_speed; 673 666 674 - pd = kzalloc(sizeof(struct sh_mobile_i2c_data), GFP_KERNEL); 675 - if (pd == NULL) { 676 - dev_err(&dev->dev, "cannot allocate private data\n"); 667 + pd = devm_kzalloc(&dev->dev, sizeof(struct sh_mobile_i2c_data), GFP_KERNEL); 668 + if (!pd) 677 669 return -ENOMEM; 678 - } 679 670 680 - pd->clk = clk_get(&dev->dev, NULL); 671 + pd->clk = devm_clk_get(&dev->dev, NULL); 681 672 if (IS_ERR(pd->clk)) { 682 673 dev_err(&dev->dev, "cannot get clock\n"); 683 - ret = PTR_ERR(pd->clk); 684 - goto err; 674 + return PTR_ERR(pd->clk); 685 675 } 686 676 687 - ret = sh_mobile_i2c_hook_irqs(dev, 1); 688 - if (ret) { 689 - dev_err(&dev->dev, "cannot request IRQ\n"); 690 - goto err_clk; 691 - } 677 + ret = sh_mobile_i2c_hook_irqs(dev); 678 + if (ret) 679 + return ret; 692 680 693 681 pd->dev = &dev->dev; 694 682 platform_set_drvdata(dev, pd); 695 683 696 684 res = platform_get_resource(dev, IORESOURCE_MEM, 0); 697 - if (res == NULL) { 698 - dev_err(&dev->dev, "cannot find IO resource\n"); 699 - ret = -ENOENT; 700 - goto err_irq; 701 - } 702 685 703 - size = resource_size(res); 704 - 705 - pd->reg = ioremap(res->start, size); 706 - if (pd->reg == NULL) { 707 - dev_err(&dev->dev, "cannot map IO\n"); 708 - ret = -ENXIO; 709 - goto err_irq; 710 - } 686 + pd->reg = devm_ioremap_resource(&dev->dev, res); 687 + if (IS_ERR(pd->reg)) 688 + return PTR_ERR(pd->reg); 711 689 712 690 /* Use platform data bus speed or STANDARD_MODE */ 713 - pd->bus_speed = STANDARD_MODE; 714 - if (pdata && pdata->bus_speed) 715 - pd->bus_speed = pdata->bus_speed; 691 + ret = of_property_read_u32(dev->dev.of_node, "clock-frequency", &bus_speed); 692 + pd->bus_speed = ret ? STANDARD_MODE : bus_speed; 693 + 716 694 pd->clks_per_count = 1; 717 - if (pdata && pdata->clks_per_count) 718 - pd->clks_per_count = pdata->clks_per_count; 695 + 696 + if (dev->dev.of_node) { 697 + const struct of_device_id *match; 698 + 699 + match = of_match_device(sh_mobile_i2c_dt_ids, &dev->dev); 700 + if (match) { 701 + const struct sh_mobile_dt_config *config; 702 + 703 + config = match->data; 704 + pd->clks_per_count = config->clks_per_count; 705 + } 706 + } else { 707 + if (pdata && pdata->bus_speed) 708 + pd->bus_speed = pdata->bus_speed; 709 + if (pdata && pdata->clks_per_count) 710 + pd->clks_per_count = pdata->clks_per_count; 711 + } 719 712 720 713 /* The IIC blocks on SH-Mobile ARM processors 721 714 * come with two new bits in ICIC. 722 715 */ 723 - if (size > 0x17) 716 + if (resource_size(res) > 0x17) 724 717 pd->flags |= IIC_FLAG_HAS_ICIC67; 725 718 726 - sh_mobile_i2c_init(pd); 719 + ret = sh_mobile_i2c_init(pd); 720 + if (ret) 721 + return ret; 727 722 728 723 /* Enable Runtime PM for this device. 729 724 * ··· 759 750 ret = i2c_add_numbered_adapter(adap); 760 751 if (ret < 0) { 761 752 dev_err(&dev->dev, "cannot add numbered adapter\n"); 762 - goto err_all; 753 + return ret; 763 754 } 764 755 765 756 dev_info(&dev->dev, 766 - "I2C adapter %d with bus speed %lu Hz (L/H=%x/%x)\n", 757 + "I2C adapter %d with bus speed %lu Hz (L/H=0x%x/0x%x)\n", 767 758 adap->nr, pd->bus_speed, pd->iccl, pd->icch); 768 759 769 760 return 0; 770 - 771 - err_all: 772 - iounmap(pd->reg); 773 - err_irq: 774 - sh_mobile_i2c_hook_irqs(dev, 0); 775 - err_clk: 776 - clk_put(pd->clk); 777 - err: 778 - kfree(pd); 779 - return ret; 780 761 } 781 762 782 763 static int sh_mobile_i2c_remove(struct platform_device *dev) ··· 774 775 struct sh_mobile_i2c_data *pd = platform_get_drvdata(dev); 775 776 776 777 i2c_del_adapter(&pd->adap); 777 - iounmap(pd->reg); 778 - sh_mobile_i2c_hook_irqs(dev, 0); 779 - clk_put(pd->clk); 780 778 pm_runtime_disable(&dev->dev); 781 - kfree(pd); 782 779 return 0; 783 780 } 784 781 ··· 794 799 .runtime_suspend = sh_mobile_i2c_runtime_nop, 795 800 .runtime_resume = sh_mobile_i2c_runtime_nop, 796 801 }; 797 - 798 - static const struct of_device_id sh_mobile_i2c_dt_ids[] = { 799 - { .compatible = "renesas,rmobile-iic", }, 800 - {}, 801 - }; 802 - MODULE_DEVICE_TABLE(of, sh_mobile_i2c_dt_ids); 803 802 804 803 static struct platform_driver sh_mobile_i2c_driver = { 805 804 .driver = {
+1 -3
drivers/i2c/busses/i2c-simtec.c
··· 77 77 int ret; 78 78 79 79 pd = kzalloc(sizeof(struct simtec_i2c_data), GFP_KERNEL); 80 - if (pd == NULL) { 81 - dev_err(&dev->dev, "cannot allocate private data\n"); 80 + if (pd == NULL) 82 81 return -ENOMEM; 83 - } 84 82 85 83 platform_set_drvdata(dev, pd); 86 84
-1
drivers/i2c/busses/i2c-sirf.c
··· 307 307 308 308 siic = devm_kzalloc(&pdev->dev, sizeof(*siic), GFP_KERNEL); 309 309 if (!siic) { 310 - dev_err(&pdev->dev, "Can't allocate driver data\n"); 311 310 err = -ENOMEM; 312 311 goto out; 313 312 }
+1 -1
drivers/i2c/busses/i2c-st.c
··· 847 847 return 0; 848 848 } 849 849 850 - static struct of_device_id st_i2c_match[] = { 850 + static const struct of_device_id st_i2c_match[] = { 851 851 { .compatible = "st,comms-ssc-i2c", }, 852 852 { .compatible = "st,comms-ssc4-i2c", }, 853 853 {},
+1 -3
drivers/i2c/busses/i2c-stu300.c
··· 868 868 int ret = 0; 869 869 870 870 dev = devm_kzalloc(&pdev->dev, sizeof(struct stu300_dev), GFP_KERNEL); 871 - if (!dev) { 872 - dev_err(&pdev->dev, "could not allocate device struct\n"); 871 + if (!dev) 873 872 return -ENOMEM; 874 - } 875 873 876 874 bus_nr = pdev->id; 877 875 dev->clk = devm_clk_get(&pdev->dev, NULL);
+1 -3
drivers/i2c/busses/i2c-tegra.c
··· 732 732 } 733 733 734 734 i2c_dev = devm_kzalloc(&pdev->dev, sizeof(*i2c_dev), GFP_KERNEL); 735 - if (!i2c_dev) { 736 - dev_err(&pdev->dev, "Could not allocate struct tegra_i2c_dev"); 735 + if (!i2c_dev) 737 736 return -ENOMEM; 738 - } 739 737 740 738 i2c_dev->base = base; 741 739 i2c_dev->div_clk = div_clk;
+2 -4
drivers/i2c/busses/i2c-wmt.c
··· 379 379 u32 clk_rate; 380 380 381 381 i2c_dev = devm_kzalloc(&pdev->dev, sizeof(*i2c_dev), GFP_KERNEL); 382 - if (!i2c_dev) { 383 - dev_err(&pdev->dev, "device memory allocation failed\n"); 382 + if (!i2c_dev) 384 383 return -ENOMEM; 385 - } 386 384 387 385 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 388 386 i2c_dev->base = devm_ioremap_resource(&pdev->dev, res); ··· 452 454 return 0; 453 455 } 454 456 455 - static struct of_device_id wmt_i2c_dt_ids[] = { 457 + static const struct of_device_id wmt_i2c_dt_ids[] = { 456 458 { .compatible = "wm,wm8505-i2c" }, 457 459 { /* Sentinel */ }, 458 460 };
+1 -3
drivers/i2c/busses/scx200_acb.c
··· 431 431 struct i2c_adapter *adapter; 432 432 433 433 iface = kzalloc(sizeof(*iface), GFP_KERNEL); 434 - if (!iface) { 435 - pr_err("can't allocate memory\n"); 434 + if (!iface) 436 435 return NULL; 437 - } 438 436 439 437 adapter = &iface->adapter; 440 438 i2c_set_adapdata(adapter, iface);
+6 -18
drivers/i2c/muxes/i2c-mux-pca954x.c
··· 36 36 */ 37 37 38 38 #include <linux/device.h> 39 - #include <linux/gpio.h> 39 + #include <linux/gpio/consumer.h> 40 40 #include <linux/i2c.h> 41 41 #include <linux/i2c-mux.h> 42 42 #include <linux/i2c/pca954x.h> 43 43 #include <linux/module.h> 44 - #include <linux/of_gpio.h> 45 44 #include <linux/slab.h> 46 45 47 46 #define PCA954X_MAX_NCHANS 8 ··· 185 186 { 186 187 struct i2c_adapter *adap = to_i2c_adapter(client->dev.parent); 187 188 struct pca954x_platform_data *pdata = dev_get_platdata(&client->dev); 188 - struct device_node *np = client->dev.of_node; 189 + struct gpio_desc *gpio; 189 190 int num, force, class; 190 191 struct pca954x *data; 191 192 int ret; ··· 199 200 200 201 i2c_set_clientdata(client, data); 201 202 202 - if (IS_ENABLED(CONFIG_OF) && np) { 203 - enum of_gpio_flags flags; 204 - int gpio; 205 - 206 - /* Get the mux out of reset if a reset GPIO is specified. */ 207 - gpio = of_get_named_gpio_flags(np, "reset-gpio", 0, &flags); 208 - if (gpio_is_valid(gpio)) { 209 - ret = devm_gpio_request_one(&client->dev, gpio, 210 - flags & OF_GPIO_ACTIVE_LOW ? 211 - GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW, 212 - "pca954x reset"); 213 - if (ret < 0) 214 - return ret; 215 - } 216 - } 203 + /* Get the mux out of reset if a reset GPIO is specified. */ 204 + gpio = devm_gpiod_get(&client->dev, "reset"); 205 + if (!IS_ERR(gpio)) 206 + gpiod_direction_output(gpio, 0); 217 207 218 208 /* Write the mux register at addr to verify 219 209 * that the mux is in fact present. This also