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

Merge tag 'i2c-for-6.10-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux

Pull i2c updates from Wolfram Sang:
"i2c core removes an argument from the i2c_mux_add_adapter() call to
further deprecate class based I2C device instantiation. All users are
converted, too.

Other that that, Andi collected a number if I2C host driver patches.
Those merges have their own description"

* tag 'i2c-for-6.10-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux: (72 commits)
power: supply: sbs-manager: Remove class argument from i2c_mux_add_adapter()
i2c: mux: Remove class argument from i2c_mux_add_adapter()
i2c: synquacer: Fix an error handling path in synquacer_i2c_probe()
i2c: acpi: Unbind mux adapters before delete
i2c: designware: Replace MODULE_ALIAS() with MODULE_DEVICE_TABLE()
i2c: pxa: use 'time_left' variable with wait_event_timeout()
i2c: s3c2410: use 'time_left' variable with wait_event_timeout()
i2c: rk3x: use 'time_left' variable with wait_event_timeout()
i2c: qcom-geni: use 'time_left' variable with wait_for_completion_timeout()
i2c: jz4780: use 'time_left' variable with wait_for_completion_timeout()
i2c: synquacer: use 'time_left' variable with wait_for_completion_timeout()
i2c: stm32f7: use 'time_left' variable with wait_for_completion_timeout()
i2c: stm32f4: use 'time_left' variable with wait_for_completion_timeout()
i2c: st: use 'time_left' variable with wait_for_completion_timeout()
i2c: omap: use 'time_left' variable with wait_for_completion_timeout()
i2c: imx-lpi2c: use 'time_left' variable with wait_for_completion_timeout()
i2c: hix5hd2: use 'time_left' variable with wait_for_completion_timeout()
i2c: exynos5: use 'time_left' variable with wait_for_completion_timeout()
i2c: digicolor: use 'time_left' variable with wait_for_completion_timeout()
i2c: amd-mp2-plat: use 'time_left' variable with wait_for_completion_timeout()
...

+1340 -798
-34
Documentation/devicetree/bindings/i2c/i2c-pnx.txt
··· 1 - * NXP PNX I2C Controller 2 - 3 - Required properties: 4 - 5 - - reg: Offset and length of the register set for the device 6 - - compatible: should be "nxp,pnx-i2c" 7 - - interrupts: configure one interrupt line 8 - - #address-cells: always 1 (for i2c addresses) 9 - - #size-cells: always 0 10 - 11 - Optional properties: 12 - 13 - - clock-frequency: desired I2C bus clock frequency in Hz, Default: 100000 Hz 14 - 15 - Examples: 16 - 17 - i2c1: i2c@400a0000 { 18 - compatible = "nxp,pnx-i2c"; 19 - reg = <0x400a0000 0x100>; 20 - interrupt-parent = <&mic>; 21 - interrupts = <51 0>; 22 - #address-cells = <1>; 23 - #size-cells = <0>; 24 - }; 25 - 26 - i2c2: i2c@400a8000 { 27 - compatible = "nxp,pnx-i2c"; 28 - reg = <0x400a8000 0x100>; 29 - interrupt-parent = <&mic>; 30 - interrupts = <50 0>; 31 - #address-cells = <1>; 32 - #size-cells = <0>; 33 - clock-frequency = <100000>; 34 - };
+46
Documentation/devicetree/bindings/i2c/nxp,pnx-i2c.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/i2c/nxp,pnx-i2c.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: NXP PNX I2C Controller 8 + 9 + maintainers: 10 + - Animesh Agarwal <animeshagarwal28@gmail.com> 11 + 12 + allOf: 13 + - $ref: /schemas/i2c/i2c-controller.yaml# 14 + 15 + properties: 16 + compatible: 17 + const: nxp,pnx-i2c 18 + 19 + reg: 20 + maxItems: 1 21 + 22 + interrupts: 23 + maxItems: 1 24 + 25 + clock-frequency: 26 + default: 100000 27 + 28 + required: 29 + - compatible 30 + - reg 31 + - interrupts 32 + - "#address-cells" 33 + - "#size-cells" 34 + 35 + unevaluatedProperties: false 36 + 37 + examples: 38 + - | 39 + i2c@400a0000 { 40 + compatible = "nxp,pnx-i2c"; 41 + reg = <0x400a0000 0x100>; 42 + interrupt-parent = <&mic>; 43 + interrupts = <51 0>; 44 + #address-cells = <1>; 45 + #size-cells = <0>; 46 + };
+19
Documentation/devicetree/bindings/i2c/qcom,i2c-cci.yaml
··· 26 26 - items: 27 27 - enum: 28 28 - qcom,sc7280-cci 29 + - qcom,sc8280xp-cci 29 30 - qcom,sdm845-cci 30 31 - qcom,sm6350-cci 31 32 - qcom,sm8250-cci ··· 176 175 - const: cpas_ahb 177 176 - const: cci 178 177 - const: cci_src 178 + 179 + - if: 180 + properties: 181 + compatible: 182 + contains: 183 + enum: 184 + - qcom,sc8280xp-cci 185 + then: 186 + properties: 187 + clocks: 188 + minItems: 4 189 + maxItems: 4 190 + clock-names: 191 + items: 192 + - const: camnoc_axi 193 + - const: slow_ahb_src 194 + - const: cpas_ahb 195 + - const: cci 179 196 180 197 additionalProperties: false 181 198
+11 -8
Documentation/devicetree/bindings/i2c/renesas,riic.yaml
··· 15 15 16 16 properties: 17 17 compatible: 18 - items: 19 - - enum: 20 - - renesas,riic-r7s72100 # RZ/A1H 21 - - renesas,riic-r7s9210 # RZ/A2M 22 - - renesas,riic-r9a07g043 # RZ/G2UL and RZ/Five 23 - - renesas,riic-r9a07g044 # RZ/G2{L,LC} 24 - - renesas,riic-r9a07g054 # RZ/V2L 25 - - const: renesas,riic-rz # RZ/A or RZ/G2L 18 + oneOf: 19 + - items: 20 + - enum: 21 + - renesas,riic-r7s72100 # RZ/A1H 22 + - renesas,riic-r7s9210 # RZ/A2M 23 + - renesas,riic-r9a07g043 # RZ/G2UL and RZ/Five 24 + - renesas,riic-r9a07g044 # RZ/G2{L,LC} 25 + - renesas,riic-r9a07g054 # RZ/V2L 26 + - const: renesas,riic-rz # RZ/A or RZ/G2L 27 + 28 + - const: renesas,riic-r9a09g057 # RZ/V2H(P) 26 29 27 30 reg: 28 31 maxItems: 1
+10 -2
MAINTAINERS
··· 2362 2362 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 2363 2363 S: Maintained 2364 2364 T: git git://github.com/vzapolskiy/linux-lpc32xx.git 2365 - F: Documentation/devicetree/bindings/i2c/i2c-pnx.txt 2365 + F: Documentation/devicetree/bindings/i2c/nxp,pnx-i2c.yaml 2366 2366 F: arch/arm/boot/dts/nxp/lpc/lpc32* 2367 2367 F: arch/arm/mach-lpc32xx/ 2368 2368 F: drivers/i2c/busses/i2c-pnx.c ··· 3082 3082 F: Documentation/devicetree/bindings/i2c/i2c-wmt.txt 3083 3083 F: arch/arm/mach-vt8500/ 3084 3084 F: drivers/clocksource/timer-vt8500.c 3085 - F: drivers/i2c/busses/i2c-wmt.c 3085 + F: drivers/i2c/busses/i2c-viai2c-wmt.c 3086 3086 F: drivers/mmc/host/wmt-sdmmc.c 3087 3087 F: drivers/pwm/pwm-vt8500.c 3088 3088 F: drivers/rtc/rtc-vt8500.c ··· 10399 10399 L: linux-i2c@vger.kernel.org 10400 10400 F: Documentation/i2c/busses/i2c-ismt.rst 10401 10401 F: drivers/i2c/busses/i2c-ismt.c 10402 + 10403 + I2C/SMBUS ZHAOXIN DRIVER 10404 + M: Hans Hu <hanshu@zhaoxin.com> 10405 + L: linux-i2c@vger.kernel.org 10406 + S: Maintained 10407 + W: https://www.zhaoxin.com 10408 + F: drivers/i2c/busses/i2c-viai2c-common.c 10409 + F: drivers/i2c/busses/i2c-viai2c-zhaoxin.c 10402 10410 10403 10411 I2C/SMBUS STUB DRIVER 10404 10412 M: Jean Delvare <jdelvare@suse.com>
+1 -1
drivers/gpu/drm/bridge/sii902x.c
··· 1092 1092 } 1093 1093 1094 1094 sii902x->i2cmux->priv = sii902x; 1095 - ret = i2c_mux_add_adapter(sii902x->i2cmux, 0, 0, 0); 1095 + ret = i2c_mux_add_adapter(sii902x->i2cmux, 0, 0); 1096 1096 if (ret) 1097 1097 goto err_unreg_audio; 1098 1098
+34 -15
drivers/i2c/busses/Kconfig
··· 18 18 19 19 config I2C_ALI1535 20 20 tristate "ALI 1535" 21 - depends on PCI 21 + depends on PCI && HAS_IOPORT 22 22 help 23 23 If you say yes to this option, support will be included for the SMB 24 24 Host controller on Acer Labs Inc. (ALI) M1535 South Bridges. The SMB ··· 30 30 31 31 config I2C_ALI1563 32 32 tristate "ALI 1563" 33 - depends on PCI 33 + depends on PCI && HAS_IOPORT 34 34 help 35 35 If you say yes to this option, support will be included for the SMB 36 36 Host controller on Acer Labs Inc. (ALI) M1563 South Bridges. The SMB ··· 42 42 43 43 config I2C_ALI15X3 44 44 tristate "ALI 15x3" 45 - depends on PCI 45 + depends on PCI && HAS_IOPORT 46 46 help 47 47 If you say yes to this option, support will be included for the 48 48 Acer Labs Inc. (ALI) M1514 and M1543 motherboard I2C interfaces. ··· 52 52 53 53 config I2C_AMD756 54 54 tristate "AMD 756/766/768/8111 and nVidia nForce" 55 - depends on PCI 55 + depends on PCI && HAS_IOPORT 56 56 help 57 57 If you say yes to this option, support will be included for the AMD 58 58 756/766/768 mainboard I2C interfaces. The driver also includes ··· 77 77 78 78 config I2C_AMD8111 79 79 tristate "AMD 8111" 80 - depends on PCI 80 + depends on PCI && HAS_IOPORT 81 81 help 82 82 If you say yes to this option, support will be included for the 83 83 second (SMBus 2.0) AMD 8111 mainboard I2C interface. ··· 107 107 108 108 config I2C_I801 109 109 tristate "Intel 82801 (ICH/PCH)" 110 - depends on PCI 110 + depends on PCI && HAS_IOPORT 111 111 select P2SB if X86 112 112 select CHECK_SIGNATURE if X86 && DMI 113 113 select I2C_SMBUS ··· 163 163 This driver can also be built as a module. If so, the module 164 164 will be called i2c-i801. 165 165 166 + config I2C_I801_MUX 167 + def_bool I2C_I801 168 + depends on DMI && I2C_MUX_GPIO 169 + depends on !(I2C_I801=y && I2C_MUX=m) 170 + help 171 + Optional support for multiplexed SMBUS on certain systems with 172 + more than 8 memory slots. 173 + 166 174 config I2C_ISCH 167 175 tristate "Intel SCH SMBus 1.0" 168 - depends on PCI 176 + depends on PCI && HAS_IOPORT 169 177 select LPC_SCH 170 178 help 171 179 Say Y here if you want to use SMBus controller on the Intel SCH ··· 194 186 195 187 config I2C_PIIX4 196 188 tristate "Intel PIIX4 and compatible (ATI/AMD/Serverworks/Broadcom/SMSC)" 197 - depends on PCI 189 + depends on PCI && HAS_IOPORT 198 190 help 199 191 If you say yes to this option, support will be included for the Intel 200 192 PIIX4 family of mainboard I2C interfaces. Specifically, the following ··· 240 232 241 233 config I2C_NFORCE2 242 234 tristate "Nvidia nForce2, nForce3 and nForce4" 243 - depends on PCI 235 + depends on PCI && HAS_IOPORT 244 236 help 245 237 If you say yes to this option, support will be included for the Nvidia 246 238 nForce2, nForce3 and nForce4 families of mainboard I2C interfaces. ··· 273 265 274 266 config I2C_SIS5595 275 267 tristate "SiS 5595" 276 - depends on PCI 268 + depends on PCI && HAS_IOPORT 277 269 help 278 270 If you say yes to this option, support will be included for the 279 271 SiS5595 SMBus (a subset of I2C) interface. ··· 283 275 284 276 config I2C_SIS630 285 277 tristate "SiS 630/730/964" 286 - depends on PCI 278 + depends on PCI && HAS_IOPORT 287 279 help 288 280 If you say yes to this option, support will be included for the 289 281 SiS630, SiS730 and SiS964 SMBus (a subset of I2C) interface. ··· 293 285 294 286 config I2C_SIS96X 295 287 tristate "SiS 96x" 296 - depends on PCI 288 + depends on PCI && HAS_IOPORT 297 289 help 298 290 If you say yes to this option, support will be included for the SiS 299 291 96x SMBus (a subset of I2C) interfaces. Specifically, the following ··· 311 303 312 304 config I2C_VIA 313 305 tristate "VIA VT82C586B" 314 - depends on PCI 306 + depends on PCI && HAS_IOPORT 315 307 select I2C_ALGOBIT 316 308 help 317 309 If you say yes to this option, support will be included for the VIA ··· 322 314 323 315 config I2C_VIAPRO 324 316 tristate "VIA VT82C596/82C686/82xx and CX700/VX8xx/VX900" 325 - depends on PCI 317 + depends on PCI && HAS_IOPORT 326 318 help 327 319 If you say yes to this option, support will be included for the VIA 328 320 VT82C596 and later SMBus interface. Specifically, the following ··· 343 335 will be called i2c-viapro. 344 336 345 337 if ACPI 338 + 339 + config I2C_ZHAOXIN 340 + tristate "Zhaoxin I2C Interface" 341 + depends on PCI || COMPILE_TEST 342 + help 343 + If you say yes to this option, support will be included for the 344 + ZHAOXIN I2C interface 345 + 346 + This driver can also be built as a module. If so, the module 347 + will be called i2c-zhaoxin. 346 348 347 349 comment "ACPI drivers" 348 350 ··· 518 500 519 501 config I2C_CADENCE 520 502 tristate "Cadence I2C Controller" 521 - depends on ARCH_ZYNQ || ARM64 || XTENSA || COMPILE_TEST 503 + depends on ARCH_ZYNQ || ARM64 || XTENSA || RISCV || COMPILE_TEST 522 504 help 523 505 Say yes here to select Cadence I2C Host Controller. This controller is 524 506 e.g. used by Xilinx Zynq. ··· 1415 1397 config I2C_MLXCPLD 1416 1398 tristate "Mellanox I2C driver" 1417 1399 depends on X86_64 || (ARM64 && ACPI) || COMPILE_TEST 1400 + depends on HAS_IOPORT 1418 1401 help 1419 1402 This exposes the Mellanox platform I2C busses to the linux I2C layer 1420 1403 for X86 and ARM64/ACPI based systems.
+3
drivers/i2c/busses/Makefile
··· 29 29 obj-$(CONFIG_I2C_SIS96X) += i2c-sis96x.o 30 30 obj-$(CONFIG_I2C_VIA) += i2c-via.o 31 31 obj-$(CONFIG_I2C_VIAPRO) += i2c-viapro.o 32 + i2c-zhaoxin-objs := i2c-viai2c-zhaoxin.o i2c-viai2c-common.o 33 + obj-$(CONFIG_I2C_ZHAOXIN) += i2c-zhaoxin.o 32 34 33 35 # Mac SMBus host controller drivers 34 36 obj-$(CONFIG_I2C_HYDRA) += i2c-hydra.o ··· 120 118 obj-$(CONFIG_I2C_UNIPHIER) += i2c-uniphier.o 121 119 obj-$(CONFIG_I2C_UNIPHIER_F) += i2c-uniphier-f.o 122 120 obj-$(CONFIG_I2C_VERSATILE) += i2c-versatile.o 121 + i2c-wmt-objs := i2c-viai2c-wmt.o i2c-viai2c-common.o 123 122 obj-$(CONFIG_I2C_WMT) += i2c-wmt.o 124 123 i2c-octeon-objs := i2c-octeon-core.o i2c-octeon-platdrv.o 125 124 obj-$(CONFIG_I2C_OCTEON) += i2c-octeon.o
+2 -6
drivers/i2c/busses/i2c-ali1535.c
··· 285 285 && (timeout++ < MAX_TIMEOUT)); 286 286 287 287 /* If the SMBus is still busy, we give up */ 288 - if (timeout > MAX_TIMEOUT) { 288 + if (timeout > MAX_TIMEOUT) 289 289 result = -ETIMEDOUT; 290 - dev_err(&adap->dev, "SMBus Timeout!\n"); 291 - } 292 290 293 291 if (temp & ALI1535_STS_FAIL) { 294 292 result = -EIO; ··· 311 313 } 312 314 313 315 /* check to see if the "command complete" indication is set */ 314 - if (!(temp & ALI1535_STS_DONE)) { 316 + if (!(temp & ALI1535_STS_DONE)) 315 317 result = -ETIMEDOUT; 316 - dev_err(&adap->dev, "Error: command never completed\n"); 317 - } 318 318 319 319 dev_dbg(&adap->dev, "Transaction (post): STS=%02x, TYP=%02x, " 320 320 "CMD=%02x, ADD=%02x, DAT0=%02x, DAT1=%02x\n",
-1
drivers/i2c/busses/i2c-ali1563.c
··· 99 99 return 0; 100 100 101 101 if (!timeout) { 102 - dev_err(&a->dev, "Timeout - Trying to KILL transaction!\n"); 103 102 /* Issue 'kill' to host controller */ 104 103 outb_p(HST_CNTL2_KILL, SMB_HST_CNTL2); 105 104 data = inb_p(SMB_HST_STS);
+1 -3
drivers/i2c/busses/i2c-ali15x3.c
··· 294 294 && (timeout++ < MAX_TIMEOUT)); 295 295 296 296 /* If the SMBus is still busy, we give up */ 297 - if (timeout > MAX_TIMEOUT) { 297 + if (timeout > MAX_TIMEOUT) 298 298 result = -ETIMEDOUT; 299 - dev_err(&adap->dev, "SMBus Timeout!\n"); 300 - } 301 299 302 300 if (temp & ALI15X3_STS_TERM) { 303 301 result = -EIO;
+4 -4
drivers/i2c/busses/i2c-amd-mp2-plat.c
··· 97 97 static int i2c_amd_check_cmd_completion(struct amd_i2c_dev *i2c_dev) 98 98 { 99 99 struct amd_i2c_common *i2c_common = &i2c_dev->common; 100 - unsigned long timeout; 100 + unsigned long time_left; 101 101 102 - timeout = wait_for_completion_timeout(&i2c_dev->cmd_complete, 103 - i2c_dev->adap.timeout); 102 + time_left = wait_for_completion_timeout(&i2c_dev->cmd_complete, 103 + i2c_dev->adap.timeout); 104 104 105 105 if ((i2c_common->reqcmd == i2c_read || 106 106 i2c_common->reqcmd == i2c_write) && 107 107 i2c_common->msg->len > 32) 108 108 i2c_amd_dma_unmap(i2c_common); 109 109 110 - if (timeout == 0) { 110 + if (time_left == 0) { 111 111 amd_mp2_rw_timeout(i2c_common); 112 112 return -ETIMEDOUT; 113 113 }
-1
drivers/i2c/busses/i2c-at91-master.c
··· 591 591 dev->adapter.timeout); 592 592 if (time_left == 0) { 593 593 dev->transfer_status |= at91_twi_read(dev, AT91_TWI_SR); 594 - dev_err(dev->dev, "controller timed out\n"); 595 594 at91_init_twi_bus(dev); 596 595 ret = -ETIMEDOUT; 597 596 goto error;
-2
drivers/i2c/busses/i2c-bcm-iproc.c
··· 811 811 } 812 812 813 813 if (!time_left && !iproc_i2c->xfer_is_done) { 814 - dev_err(iproc_i2c->device, "transaction timed out\n"); 815 - 816 814 /* flush both TX/RX FIFOs */ 817 815 val = BIT(M_FIFO_RX_FLUSH_SHIFT) | BIT(M_FIFO_TX_FLUSH_SHIFT); 818 816 iproc_i2c_wr_reg(iproc_i2c, M_FIFO_CTRL_OFFSET, val);
-1
drivers/i2c/busses/i2c-bcm2835.c
··· 370 370 if (!time_left) { 371 371 bcm2835_i2c_writel(i2c_dev, BCM2835_I2C_C, 372 372 BCM2835_I2C_C_CLEAR); 373 - dev_err(i2c_dev->dev, "i2c transfer timed out\n"); 374 373 return -ETIMEDOUT; 375 374 } 376 375
+1 -2
drivers/i2c/busses/i2c-cadence.c
··· 633 633 634 634 if (hold_clear) { 635 635 ctrl_reg &= ~CDNS_I2C_CR_HOLD; 636 + ctrl_reg &= ~CDNS_I2C_CR_CLR_FIFO; 636 637 /* 637 638 * In case of Xilinx Zynq SOC, clear the HOLD bit before transfer size 638 639 * register reaches '0'. This is an IP bug which causes transfer size ··· 790 789 time_left = wait_for_completion_timeout(&id->xfer_done, msg_timeout); 791 790 if (time_left == 0) { 792 791 cdns_i2c_master_reset(adap); 793 - dev_err(id->adap.dev.parent, 794 - "timeout waiting on completion\n"); 795 792 return -ETIMEDOUT; 796 793 } 797 794
-1
drivers/i2c/busses/i2c-davinci.c
··· 489 489 time_left = wait_for_completion_timeout(&dev->cmd_complete, 490 490 dev->adapter.timeout); 491 491 if (!time_left) { 492 - dev_err(dev->dev, "controller timed out\n"); 493 492 i2c_recover_bus(adap); 494 493 dev->buf_len = 0; 495 494 return -ETIMEDOUT;
-2
drivers/i2c/busses/i2c-designware-pcidrv.c
··· 424 424 }; 425 425 module_pci_driver(dw_i2c_driver); 426 426 427 - /* Work with hotplug and coldplug */ 428 - MODULE_ALIAS("i2c_designware-pci"); 429 427 MODULE_AUTHOR("Baruch Siach <baruch@tkos.co.il>"); 430 428 MODULE_DESCRIPTION("Synopsys DesignWare PCI I2C bus adapter"); 431 429 MODULE_LICENSE("GPL");
+7 -2
drivers/i2c/busses/i2c-designware-platdrv.c
··· 46 46 { "INT33C3", 0 }, 47 47 { "INT3432", 0 }, 48 48 { "INT3433", 0 }, 49 + { "INTC10EF", 0 }, 49 50 { "80860F41", ACCESS_NO_IRQ_SUSPEND }, 50 51 { "808622C1", ACCESS_NO_IRQ_SUSPEND }, 51 52 { "AMD0010", ACCESS_INTR_MASK }, ··· 480 479 RUNTIME_PM_OPS(dw_i2c_plat_runtime_suspend, dw_i2c_plat_runtime_resume, NULL) 481 480 }; 482 481 483 - /* Work with hotplug and coldplug */ 484 - MODULE_ALIAS("platform:i2c_designware"); 482 + static const struct platform_device_id dw_i2c_platform_ids[] = { 483 + { "i2c_designware" }, 484 + {} 485 + }; 486 + MODULE_DEVICE_TABLE(platform, dw_i2c_platform_ids); 485 487 486 488 static struct platform_driver dw_i2c_driver = { 487 489 .probe = dw_i2c_plat_probe, ··· 495 491 .acpi_match_table = ACPI_PTR(dw_i2c_acpi_match), 496 492 .pm = pm_ptr(&dw_i2c_dev_pm_ops), 497 493 }, 494 + .id_table = dw_i2c_platform_ids, 498 495 }; 499 496 500 497 static int __init dw_i2c_init_driver(void)
+3 -3
drivers/i2c/busses/i2c-digicolor.c
··· 213 213 static int dc_i2c_xfer_msg(struct dc_i2c *i2c, struct i2c_msg *msg, int first, 214 214 int last) 215 215 { 216 - unsigned long timeout = msecs_to_jiffies(TIMEOUT_MS); 216 + unsigned long time_left = msecs_to_jiffies(TIMEOUT_MS); 217 217 unsigned long flags; 218 218 219 219 spin_lock_irqsave(&i2c->lock, flags); ··· 227 227 dc_i2c_start_msg(i2c, first); 228 228 spin_unlock_irqrestore(&i2c->lock, flags); 229 229 230 - timeout = wait_for_completion_timeout(&i2c->done, timeout); 230 + time_left = wait_for_completion_timeout(&i2c->done, time_left); 231 231 dc_i2c_set_irq(i2c, 0); 232 - if (timeout == 0) { 232 + if (time_left == 0) { 233 233 i2c->state = STATE_IDLE; 234 234 return -ETIMEDOUT; 235 235 }
+6 -6
drivers/i2c/busses/i2c-exynos5.c
··· 763 763 static int exynos5_i2c_xfer_msg(struct exynos5_i2c *i2c, 764 764 struct i2c_msg *msgs, int stop) 765 765 { 766 - unsigned long timeout; 766 + unsigned long time_left; 767 767 int ret; 768 768 769 769 i2c->msg = msgs; ··· 775 775 exynos5_i2c_message_start(i2c, stop); 776 776 777 777 if (!i2c->atomic) 778 - timeout = wait_for_completion_timeout(&i2c->msg_complete, 779 - EXYNOS5_I2C_TIMEOUT); 780 - else 781 - timeout = exynos5_i2c_poll_irqs_timeout(i2c, 778 + time_left = wait_for_completion_timeout(&i2c->msg_complete, 782 779 EXYNOS5_I2C_TIMEOUT); 780 + else 781 + time_left = exynos5_i2c_poll_irqs_timeout(i2c, 782 + EXYNOS5_I2C_TIMEOUT); 783 783 784 - if (timeout == 0) 784 + if (time_left == 0) 785 785 ret = -ETIMEDOUT; 786 786 else 787 787 ret = i2c->state;
+4 -4
drivers/i2c/busses/i2c-hix5hd2.c
··· 314 314 static int hix5hd2_i2c_xfer_msg(struct hix5hd2_i2c_priv *priv, 315 315 struct i2c_msg *msgs, int stop) 316 316 { 317 - unsigned long timeout; 317 + unsigned long time_left; 318 318 int ret; 319 319 320 320 priv->msg = msgs; ··· 327 327 reinit_completion(&priv->msg_complete); 328 328 hix5hd2_i2c_message_start(priv, stop); 329 329 330 - timeout = wait_for_completion_timeout(&priv->msg_complete, 331 - priv->adap.timeout); 332 - if (timeout == 0) { 330 + time_left = wait_for_completion_timeout(&priv->msg_complete, 331 + priv->adap.timeout); 332 + if (time_left == 0) { 333 333 priv->state = HIX5I2C_STAT_RW_ERR; 334 334 priv->err = -ETIMEDOUT; 335 335 dev_warn(priv->dev, "%s timeout=%d\n",
+29 -12
drivers/i2c/busses/i2c-i801.c
··· 105 105 #include <linux/ioport.h> 106 106 #include <linux/init.h> 107 107 #include <linux/i2c.h> 108 + #include <linux/i2c-mux.h> 108 109 #include <linux/i2c-smbus.h> 109 110 #include <linux/acpi.h> 110 111 #include <linux/io.h> ··· 120 119 #include <linux/pm_runtime.h> 121 120 #include <linux/mutex.h> 122 121 123 - #if IS_ENABLED(CONFIG_I2C_MUX_GPIO) && defined CONFIG_DMI 122 + #ifdef CONFIG_I2C_I801_MUX 124 123 #include <linux/gpio/machine.h> 125 124 #include <linux/platform_data/i2c-mux-gpio.h> 126 125 #endif ··· 264 263 char *gpio_chip; 265 264 unsigned values[3]; 266 265 int n_values; 267 - unsigned classes[3]; 268 266 unsigned gpios[2]; /* Relative to gpio_chip->base */ 269 267 int n_gpios; 270 268 }; ··· 288 288 int len; 289 289 u8 *data; 290 290 291 - #if IS_ENABLED(CONFIG_I2C_MUX_GPIO) && defined CONFIG_DMI 291 + #ifdef CONFIG_I2C_I801_MUX 292 292 struct platform_device *mux_pdev; 293 293 struct gpiod_lookup_table *lookup; 294 + struct notifier_block mux_notifier_block; 294 295 #endif 295 296 struct platform_device *tco_pdev; 296 297 ··· 399 398 * If the SMBus is still busy, we give up 400 399 */ 401 400 if (unlikely(status < 0)) { 402 - dev_err(&priv->pci_dev->dev, "Transaction timeout\n"); 403 401 /* try to stop the current command */ 404 - dev_dbg(&priv->pci_dev->dev, "Terminating the current operation\n"); 405 402 outb_p(SMBHSTCNT_KILL, SMBHSTCNT(priv)); 406 403 usleep_range(1000, 2000); 407 404 outb_p(0, SMBHSTCNT(priv)); ··· 408 409 status = inb_p(SMBHSTSTS(priv)); 409 410 if ((status & SMBHSTSTS_HOST_BUSY) || 410 411 !(status & SMBHSTSTS_FAILED)) 411 - dev_err(&priv->pci_dev->dev, 412 + dev_dbg(&priv->pci_dev->dev, 412 413 "Failed terminating the transaction\n"); 413 414 return -ETIMEDOUT; 414 415 } ··· 1058 1059 MODULE_DEVICE_TABLE(pci, i801_ids); 1059 1060 1060 1061 #if defined CONFIG_X86 && defined CONFIG_DMI 1061 - static unsigned char apanel_addr; 1062 + static unsigned char apanel_addr __ro_after_init; 1062 1063 1063 1064 /* Scan the system ROM for the signature "FJKEYINF" */ 1064 1065 static __init const void __iomem *bios_signature(const void __iomem *bios) ··· 1297 1298 register_dell_lis3lv02d_i2c_device(priv); 1298 1299 1299 1300 /* Instantiate SPD EEPROMs unless the SMBus is multiplexed */ 1300 - #if IS_ENABLED(CONFIG_I2C_MUX_GPIO) 1301 + #ifdef CONFIG_I2C_I801_MUX 1301 1302 if (!priv->mux_pdev) 1302 1303 #endif 1303 1304 i2c_register_spd(&priv->adapter); ··· 1307 1308 static void i801_probe_optional_slaves(struct i801_priv *priv) {} 1308 1309 #endif /* CONFIG_X86 && CONFIG_DMI */ 1309 1310 1310 - #if IS_ENABLED(CONFIG_I2C_MUX_GPIO) && defined CONFIG_DMI 1311 + #ifdef CONFIG_I2C_I801_MUX 1311 1312 static struct i801_mux_config i801_mux_config_asus_z8_d12 = { 1312 1313 .gpio_chip = "gpio_ich", 1313 1314 .values = { 0x02, 0x03 }, 1314 1315 .n_values = 2, 1315 - .classes = { I2C_CLASS_SPD, I2C_CLASS_SPD }, 1316 1316 .gpios = { 52, 53 }, 1317 1317 .n_gpios = 2, 1318 1318 }; ··· 1320 1322 .gpio_chip = "gpio_ich", 1321 1323 .values = { 0x02, 0x03, 0x01 }, 1322 1324 .n_values = 3, 1323 - .classes = { I2C_CLASS_SPD, I2C_CLASS_SPD, I2C_CLASS_SPD }, 1324 1325 .gpios = { 52, 53 }, 1325 1326 .n_gpios = 2, 1326 1327 }; ··· 1391 1394 { } 1392 1395 }; 1393 1396 1397 + static int i801_notifier_call(struct notifier_block *nb, unsigned long action, 1398 + void *data) 1399 + { 1400 + struct i801_priv *priv = container_of(nb, struct i801_priv, mux_notifier_block); 1401 + struct device *dev = data; 1402 + 1403 + if (action != BUS_NOTIFY_ADD_DEVICE || 1404 + dev->type != &i2c_adapter_type || 1405 + i2c_root_adapter(dev) != &priv->adapter) 1406 + return NOTIFY_DONE; 1407 + 1408 + /* Call i2c_register_spd for muxed child segments */ 1409 + i2c_register_spd(to_i2c_adapter(dev)); 1410 + 1411 + return NOTIFY_OK; 1412 + } 1413 + 1394 1414 /* Setup multiplexing if needed */ 1395 1415 static void i801_add_mux(struct i801_priv *priv) 1396 1416 { ··· 1429 1415 gpio_data.parent = priv->adapter.nr; 1430 1416 gpio_data.values = mux_config->values; 1431 1417 gpio_data.n_values = mux_config->n_values; 1432 - gpio_data.classes = mux_config->classes; 1433 1418 gpio_data.idle = I2C_MUX_GPIO_NO_IDLE; 1434 1419 1435 1420 /* Register GPIO descriptor lookup table */ ··· 1443 1430 mux_config->gpios[i], "mux", 0); 1444 1431 gpiod_add_lookup_table(lookup); 1445 1432 1433 + priv->mux_notifier_block.notifier_call = i801_notifier_call; 1434 + if (bus_register_notifier(&i2c_bus_type, &priv->mux_notifier_block)) 1435 + return; 1446 1436 /* 1447 1437 * Register the mux device, we use PLATFORM_DEVID_NONE here 1448 1438 * because since we are referring to the GPIO chip by name we are ··· 1467 1451 1468 1452 static void i801_del_mux(struct i801_priv *priv) 1469 1453 { 1454 + bus_unregister_notifier(&i2c_bus_type, &priv->mux_notifier_block); 1470 1455 platform_device_unregister(priv->mux_pdev); 1471 1456 gpiod_remove_lookup_table(priv->lookup); 1472 1457 }
+1 -4
drivers/i2c/busses/i2c-img-scb.c
··· 1124 1124 IMG_I2C_TIMEOUT); 1125 1125 del_timer_sync(&i2c->check_timer); 1126 1126 1127 - if (time_left == 0) { 1128 - dev_err(adap->dev.parent, "i2c transfer timed out\n"); 1127 + if (time_left == 0) 1129 1128 i2c->msg_status = -ETIMEDOUT; 1130 - break; 1131 - } 1132 1129 1133 1130 if (i2c->msg_status) 1134 1131 break;
+19 -6
drivers/i2c/busses/i2c-imx-lpi2c.c
··· 99 99 __u8 *rx_buf; 100 100 __u8 *tx_buf; 101 101 struct completion complete; 102 + unsigned long rate_per; 102 103 unsigned int msglen; 103 104 unsigned int delivered; 104 105 unsigned int block_data; ··· 213 212 214 213 lpi2c_imx_set_mode(lpi2c_imx); 215 214 216 - clk_rate = clk_get_rate(lpi2c_imx->clks[0].clk); 217 - if (!clk_rate) 218 - return -EINVAL; 215 + clk_rate = lpi2c_imx->rate_per; 219 216 220 217 if (lpi2c_imx->mode == HS || lpi2c_imx->mode == ULTRA_FAST) 221 218 filt = 0; ··· 307 308 308 309 static int lpi2c_imx_msg_complete(struct lpi2c_imx_struct *lpi2c_imx) 309 310 { 310 - unsigned long timeout; 311 + unsigned long time_left; 311 312 312 - timeout = wait_for_completion_timeout(&lpi2c_imx->complete, HZ); 313 + time_left = wait_for_completion_timeout(&lpi2c_imx->complete, HZ); 313 314 314 - return timeout ? 0 : -ETIMEDOUT; 315 + return time_left ? 0 : -ETIMEDOUT; 315 316 } 316 317 317 318 static int lpi2c_imx_txfifo_empty(struct lpi2c_imx_struct *lpi2c_imx) ··· 609 610 ret = clk_bulk_prepare_enable(lpi2c_imx->num_clks, lpi2c_imx->clks); 610 611 if (ret) 611 612 return ret; 613 + 614 + /* 615 + * Lock the parent clock rate to avoid getting parent clock upon 616 + * each transfer 617 + */ 618 + ret = devm_clk_rate_exclusive_get(&pdev->dev, lpi2c_imx->clks[0].clk); 619 + if (ret) 620 + return dev_err_probe(&pdev->dev, ret, 621 + "can't lock I2C peripheral clock rate\n"); 622 + 623 + lpi2c_imx->rate_per = clk_get_rate(lpi2c_imx->clks[0].clk); 624 + if (!lpi2c_imx->rate_per) 625 + return dev_err_probe(&pdev->dev, -EINVAL, 626 + "can't get I2C peripheral clock rate\n"); 612 627 613 628 pm_runtime_set_autosuspend_delay(&pdev->dev, I2C_PM_TIMEOUT); 614 629 pm_runtime_use_autosuspend(&pdev->dev);
-1
drivers/i2c/busses/i2c-ismt.c
··· 623 623 dma_unmap_single(dev, dma_addr, dma_size, dma_direction); 624 624 625 625 if (unlikely(!time_left)) { 626 - dev_err(dev, "completion wait timed out\n"); 627 626 ret = -ETIMEDOUT; 628 627 goto out; 629 628 }
+11 -11
drivers/i2c/busses/i2c-jz4780.c
··· 565 565 int idx) 566 566 { 567 567 int ret = 0; 568 - long timeout; 568 + unsigned long time_left; 569 569 int wait_time = JZ4780_I2C_TIMEOUT * (len + 5); 570 570 unsigned short tmp; 571 571 unsigned long flags; ··· 600 600 601 601 spin_unlock_irqrestore(&i2c->lock, flags); 602 602 603 - timeout = wait_for_completion_timeout(&i2c->trans_waitq, 604 - msecs_to_jiffies(wait_time)); 603 + time_left = wait_for_completion_timeout(&i2c->trans_waitq, 604 + msecs_to_jiffies(wait_time)); 605 605 606 - if (!timeout) { 606 + if (!time_left) { 607 607 dev_err(&i2c->adap.dev, "irq read timeout\n"); 608 608 dev_dbg(&i2c->adap.dev, "send cmd count:%d %d\n", 609 609 i2c->cmd, i2c->cmd_buf[i2c->cmd]); ··· 627 627 { 628 628 int ret = 0; 629 629 int wait_time = JZ4780_I2C_TIMEOUT * (len + 5); 630 - long timeout; 630 + unsigned long time_left; 631 631 unsigned short tmp; 632 632 unsigned long flags; 633 633 ··· 655 655 656 656 spin_unlock_irqrestore(&i2c->lock, flags); 657 657 658 - timeout = wait_for_completion_timeout(&i2c->trans_waitq, 659 - msecs_to_jiffies(wait_time)); 660 - if (timeout && !i2c->stop_hold) { 658 + time_left = wait_for_completion_timeout(&i2c->trans_waitq, 659 + msecs_to_jiffies(wait_time)); 660 + if (time_left && !i2c->stop_hold) { 661 661 unsigned short i2c_sta; 662 662 int write_in_process; 663 663 664 - timeout = JZ4780_I2C_TIMEOUT * 100; 665 - for (; timeout > 0; timeout--) { 664 + time_left = JZ4780_I2C_TIMEOUT * 100; 665 + for (; time_left > 0; time_left--) { 666 666 i2c_sta = jz4780_i2c_readw(i2c, JZ4780_I2C_STA); 667 667 668 668 write_in_process = (i2c_sta & JZ4780_I2C_STA_MSTACT) || ··· 673 673 } 674 674 } 675 675 676 - if (!timeout) { 676 + if (!time_left) { 677 677 dev_err(&i2c->adap.dev, "write wait timeout\n"); 678 678 ret = -EIO; 679 679 }
+4 -7
drivers/i2c/busses/i2c-mpc.c
··· 304 304 struct mpc_i2c *i2c, 305 305 u32 clock) 306 306 { 307 - struct device_node *node_ctrl; 308 307 void __iomem *ctrl; 309 308 u32 idx; 310 309 311 310 /* Enable I2C interrupts for mpc5121 */ 312 - node_ctrl = of_find_compatible_node(NULL, NULL, 313 - "fsl,mpc5121-i2c-ctrl"); 311 + struct device_node *node_ctrl __free(device_node) = 312 + of_find_compatible_node(NULL, NULL, "fsl,mpc5121-i2c-ctrl"); 314 313 if (node_ctrl) { 315 314 ctrl = of_iomap(node_ctrl, 0); 316 315 if (ctrl) { ··· 320 321 setbits32(ctrl, 1 << (24 + idx * 2)); 321 322 iounmap(ctrl); 322 323 } 323 - of_node_put(node_ctrl); 324 324 } 325 325 326 326 /* The clock setup for the 52xx works also fine for the 512x */ ··· 356 358 357 359 static u32 mpc_i2c_get_sec_cfg_8xxx(void) 358 360 { 359 - struct device_node *node; 360 361 u32 __iomem *reg; 361 362 u32 val = 0; 362 363 363 - node = of_find_node_by_name(NULL, "global-utilities"); 364 + struct device_node *node __free(device_node) = 365 + of_find_node_by_name(NULL, "global-utilities"); 364 366 if (node) { 365 367 const u32 *prop = of_get_property(node, "reg", NULL); 366 368 if (prop) { ··· 381 383 iounmap(reg); 382 384 } 383 385 } 384 - of_node_put(node); 385 386 386 387 return val; 387 388 }
+2 -5
drivers/i2c/busses/i2c-nomadik.c
··· 542 542 543 543 xfer_done = nmk_i2c_wait_xfer_done(priv); 544 544 545 - if (!xfer_done) { 546 - /* Controller timed out */ 547 - dev_err(&priv->adev->dev, "read from slave 0x%x timed out\n", 548 - priv->cli.slave_adr); 545 + if (!xfer_done) 549 546 status = -ETIMEDOUT; 550 - } 547 + 551 548 return status; 552 549 } 553 550
+7 -14
drivers/i2c/busses/i2c-ocores.c
··· 32 32 */ 33 33 struct ocores_i2c { 34 34 void __iomem *base; 35 - int iobase; 36 35 u32 reg_shift; 37 36 u32 reg_io_width; 38 37 unsigned long flags; ··· 133 134 static inline u8 oc_getreg_32be(struct ocores_i2c *i2c, int reg) 134 135 { 135 136 return ioread32be(i2c->base + (reg << i2c->reg_shift)); 136 - } 137 - 138 - static void oc_setreg_io_8(struct ocores_i2c *i2c, int reg, u8 value) 139 - { 140 - outb(value, i2c->iobase + reg); 141 - } 142 - 143 - static inline u8 oc_getreg_io_8(struct ocores_i2c *i2c, int reg) 144 - { 145 - return inb(i2c->iobase + reg); 146 137 } 147 138 148 139 static inline void oc_setreg(struct ocores_i2c *i2c, int reg, u8 value) ··· 607 618 res = platform_get_resource(pdev, IORESOURCE_IO, 0); 608 619 if (!res) 609 620 return -EINVAL; 610 - i2c->iobase = res->start; 611 621 if (!devm_request_region(&pdev->dev, res->start, 612 622 resource_size(res), 613 623 pdev->name)) { 614 624 dev_err(&pdev->dev, "Can't get I/O resource.\n"); 615 625 return -EBUSY; 616 626 } 617 - i2c->setreg = oc_setreg_io_8; 618 - i2c->getreg = oc_getreg_io_8; 627 + i2c->base = devm_ioport_map(&pdev->dev, res->start, 628 + resource_size(res)); 629 + if (!i2c->base) { 630 + dev_err(&pdev->dev, "Can't map I/O resource.\n"); 631 + return -EBUSY; 632 + } 633 + i2c->reg_io_width = 1; 619 634 } 620 635 621 636 pdata = dev_get_platdata(&pdev->dev);
+100 -41
drivers/i2c/busses/i2c-octeon-core.c
··· 17 17 #include <linux/interrupt.h> 18 18 #include <linux/kernel.h> 19 19 #include <linux/module.h> 20 + #include <linux/pci.h> 20 21 21 22 #include "i2c-octeon-core.h" 23 + 24 + #define INITIAL_DELTA_HZ 1000000 25 + #define TWSI_MASTER_CLK_REG_DEF_VAL 0x18 26 + #define TWSI_MASTER_CLK_REG_OTX2_VAL 0x3 22 27 23 28 /* interrupt service routine */ 24 29 irqreturn_t octeon_i2c_isr(int irq, void *dev_id) ··· 85 80 86 81 static bool octeon_i2c_hlc_test_valid(struct octeon_i2c *i2c) 87 82 { 88 - return (__raw_readq(i2c->twsi_base + SW_TWSI(i2c)) & SW_TWSI_V) == 0; 83 + return (__raw_readq(i2c->twsi_base + OCTEON_REG_SW_TWSI(i2c)) & SW_TWSI_V) == 0; 89 84 } 90 85 91 86 static void octeon_i2c_hlc_int_clear(struct octeon_i2c *i2c) ··· 182 177 static int octeon_i2c_check_status(struct octeon_i2c *i2c, int final_read) 183 178 { 184 179 u8 stat; 180 + u64 mode; 185 181 186 182 /* 187 183 * This is ugly... in HLC mode the status is not in the status register 188 - * but in the lower 8 bits of SW_TWSI. 184 + * but in the lower 8 bits of OCTEON_REG_SW_TWSI. 189 185 */ 190 186 if (i2c->hlc_enabled) 191 - stat = __raw_readq(i2c->twsi_base + SW_TWSI(i2c)); 187 + stat = __raw_readq(i2c->twsi_base + OCTEON_REG_SW_TWSI(i2c)); 192 188 else 193 189 stat = octeon_i2c_stat_read(i2c); 194 190 ··· 245 239 case STAT_RXADDR_NAK: 246 240 case STAT_AD2W_NAK: 247 241 return -ENXIO; 242 + 243 + case STAT_WDOG_TOUT: 244 + mode = __raw_readq(i2c->twsi_base + OCTEON_REG_MODE(i2c)); 245 + /* Set BUS_MON_RST to reset bus monitor */ 246 + mode |= BUS_MON_RST_MASK; 247 + octeon_i2c_writeq_flush(mode, i2c->twsi_base + OCTEON_REG_MODE(i2c)); 248 + return -EIO; 248 249 default: 249 250 dev_err(i2c->dev, "unhandled state: %d\n", stat); 250 251 return -EIO; ··· 432 419 else 433 420 cmd |= SW_TWSI_OP_7; 434 421 435 - octeon_i2c_writeq_flush(cmd, i2c->twsi_base + SW_TWSI(i2c)); 422 + octeon_i2c_writeq_flush(cmd, i2c->twsi_base + OCTEON_REG_SW_TWSI(i2c)); 436 423 ret = octeon_i2c_hlc_wait(i2c); 437 424 if (ret) 438 425 goto err; 439 426 440 - cmd = __raw_readq(i2c->twsi_base + SW_TWSI(i2c)); 427 + cmd = __raw_readq(i2c->twsi_base + OCTEON_REG_SW_TWSI(i2c)); 441 428 if ((cmd & SW_TWSI_R) == 0) 442 429 return octeon_i2c_check_status(i2c, false); 443 430 ··· 445 432 msgs[0].buf[j] = (cmd >> (8 * i)) & 0xff; 446 433 447 434 if (msgs[0].len > 4) { 448 - cmd = __raw_readq(i2c->twsi_base + SW_TWSI_EXT(i2c)); 435 + cmd = __raw_readq(i2c->twsi_base + OCTEON_REG_SW_TWSI_EXT(i2c)); 449 436 for (i = 0; i < msgs[0].len - 4 && i < 4; i++, j--) 450 437 msgs[0].buf[j] = (cmd >> (8 * i)) & 0xff; 451 438 } ··· 482 469 483 470 for (i = 0; i < msgs[0].len - 4 && i < 4; i++, j--) 484 471 ext |= (u64)msgs[0].buf[j] << (8 * i); 485 - octeon_i2c_writeq_flush(ext, i2c->twsi_base + SW_TWSI_EXT(i2c)); 472 + octeon_i2c_writeq_flush(ext, i2c->twsi_base + OCTEON_REG_SW_TWSI_EXT(i2c)); 486 473 } 487 474 488 - octeon_i2c_writeq_flush(cmd, i2c->twsi_base + SW_TWSI(i2c)); 475 + octeon_i2c_writeq_flush(cmd, i2c->twsi_base + OCTEON_REG_SW_TWSI(i2c)); 489 476 ret = octeon_i2c_hlc_wait(i2c); 490 477 if (ret) 491 478 goto err; 492 479 493 - cmd = __raw_readq(i2c->twsi_base + SW_TWSI(i2c)); 480 + cmd = __raw_readq(i2c->twsi_base + OCTEON_REG_SW_TWSI(i2c)); 494 481 if ((cmd & SW_TWSI_R) == 0) 495 482 return octeon_i2c_check_status(i2c, false); 496 483 ··· 523 510 cmd |= SW_TWSI_EIA; 524 511 ext = (u64)msgs[0].buf[0] << SW_TWSI_IA_SHIFT; 525 512 cmd |= (u64)msgs[0].buf[1] << SW_TWSI_IA_SHIFT; 526 - octeon_i2c_writeq_flush(ext, i2c->twsi_base + SW_TWSI_EXT(i2c)); 513 + octeon_i2c_writeq_flush(ext, i2c->twsi_base + OCTEON_REG_SW_TWSI_EXT(i2c)); 527 514 } else { 528 515 cmd |= (u64)msgs[0].buf[0] << SW_TWSI_IA_SHIFT; 529 516 } 530 517 531 518 octeon_i2c_hlc_int_clear(i2c); 532 - octeon_i2c_writeq_flush(cmd, i2c->twsi_base + SW_TWSI(i2c)); 519 + octeon_i2c_writeq_flush(cmd, i2c->twsi_base + OCTEON_REG_SW_TWSI(i2c)); 533 520 534 521 ret = octeon_i2c_hlc_wait(i2c); 535 522 if (ret) 536 523 goto err; 537 524 538 - cmd = __raw_readq(i2c->twsi_base + SW_TWSI(i2c)); 525 + cmd = __raw_readq(i2c->twsi_base + OCTEON_REG_SW_TWSI(i2c)); 539 526 if ((cmd & SW_TWSI_R) == 0) 540 527 return octeon_i2c_check_status(i2c, false); 541 528 ··· 543 530 msgs[1].buf[j] = (cmd >> (8 * i)) & 0xff; 544 531 545 532 if (msgs[1].len > 4) { 546 - cmd = __raw_readq(i2c->twsi_base + SW_TWSI_EXT(i2c)); 533 + cmd = __raw_readq(i2c->twsi_base + OCTEON_REG_SW_TWSI_EXT(i2c)); 547 534 for (i = 0; i < msgs[1].len - 4 && i < 4; i++, j--) 548 535 msgs[1].buf[j] = (cmd >> (8 * i)) & 0xff; 549 536 } ··· 590 577 set_ext = true; 591 578 } 592 579 if (set_ext) 593 - octeon_i2c_writeq_flush(ext, i2c->twsi_base + SW_TWSI_EXT(i2c)); 580 + octeon_i2c_writeq_flush(ext, i2c->twsi_base + OCTEON_REG_SW_TWSI_EXT(i2c)); 594 581 595 582 octeon_i2c_hlc_int_clear(i2c); 596 - octeon_i2c_writeq_flush(cmd, i2c->twsi_base + SW_TWSI(i2c)); 583 + octeon_i2c_writeq_flush(cmd, i2c->twsi_base + OCTEON_REG_SW_TWSI(i2c)); 597 584 598 585 ret = octeon_i2c_hlc_wait(i2c); 599 586 if (ret) 600 587 goto err; 601 588 602 - cmd = __raw_readq(i2c->twsi_base + SW_TWSI(i2c)); 589 + cmd = __raw_readq(i2c->twsi_base + OCTEON_REG_SW_TWSI(i2c)); 603 590 if ((cmd & SW_TWSI_R) == 0) 604 591 return octeon_i2c_check_status(i2c, false); 605 592 ··· 620 607 struct octeon_i2c *i2c = i2c_get_adapdata(adap); 621 608 int i, ret = 0; 622 609 623 - if (num == 1) { 624 - if (msgs[0].len > 0 && msgs[0].len <= 8) { 625 - if (msgs[0].flags & I2C_M_RD) 626 - ret = octeon_i2c_hlc_read(i2c, msgs); 627 - else 628 - ret = octeon_i2c_hlc_write(i2c, msgs); 629 - goto out; 630 - } 631 - } else if (num == 2) { 632 - if ((msgs[0].flags & I2C_M_RD) == 0 && 633 - (msgs[1].flags & I2C_M_RECV_LEN) == 0 && 634 - msgs[0].len > 0 && msgs[0].len <= 2 && 635 - msgs[1].len > 0 && msgs[1].len <= 8 && 636 - msgs[0].addr == msgs[1].addr) { 637 - if (msgs[1].flags & I2C_M_RD) 638 - ret = octeon_i2c_hlc_comp_read(i2c, msgs); 639 - else 640 - ret = octeon_i2c_hlc_comp_write(i2c, msgs); 641 - goto out; 610 + if (IS_LS_FREQ(i2c->twsi_freq)) { 611 + if (num == 1) { 612 + if (msgs[0].len > 0 && msgs[0].len <= 8) { 613 + if (msgs[0].flags & I2C_M_RD) 614 + ret = octeon_i2c_hlc_read(i2c, msgs); 615 + else 616 + ret = octeon_i2c_hlc_write(i2c, msgs); 617 + goto out; 618 + } 619 + } else if (num == 2) { 620 + if ((msgs[0].flags & I2C_M_RD) == 0 && 621 + (msgs[1].flags & I2C_M_RECV_LEN) == 0 && 622 + msgs[0].len > 0 && msgs[0].len <= 2 && 623 + msgs[1].len > 0 && msgs[1].len <= 8 && 624 + msgs[0].addr == msgs[1].addr) { 625 + if (msgs[1].flags & I2C_M_RD) 626 + ret = octeon_i2c_hlc_comp_read(i2c, msgs); 627 + else 628 + ret = octeon_i2c_hlc_comp_write(i2c, msgs); 629 + goto out; 630 + } 642 631 } 643 632 } 644 633 ··· 673 658 void octeon_i2c_set_clock(struct octeon_i2c *i2c) 674 659 { 675 660 int tclk, thp_base, inc, thp_idx, mdiv_idx, ndiv_idx, foscl, diff; 676 - int thp = 0x18, mdiv = 2, ndiv = 0, delta_hz = 1000000; 661 + bool is_plat_otx2; 662 + /* 663 + * Find divisors to produce target frequency, start with large delta 664 + * to cover wider range of divisors, note thp = TCLK half period and 665 + * ds is OSCL output frequency divisor. 666 + */ 667 + unsigned int thp, mdiv_min, mdiv = 2, ndiv = 0, ds = 10; 668 + unsigned int delta_hz = INITIAL_DELTA_HZ; 669 + 670 + is_plat_otx2 = octeon_i2c_is_otx2(to_pci_dev(i2c->dev)); 671 + 672 + if (is_plat_otx2) { 673 + thp = TWSI_MASTER_CLK_REG_OTX2_VAL; 674 + mdiv_min = 0; 675 + if (!IS_LS_FREQ(i2c->twsi_freq)) 676 + ds = 15; 677 + } else { 678 + thp = TWSI_MASTER_CLK_REG_DEF_VAL; 679 + mdiv_min = 2; 680 + } 677 681 678 682 for (ndiv_idx = 0; ndiv_idx < 8 && delta_hz != 0; ndiv_idx++) { 679 683 /* 680 684 * An mdiv value of less than 2 seems to not work well 681 685 * with ds1337 RTCs, so we constrain it to larger values. 682 686 */ 683 - for (mdiv_idx = 15; mdiv_idx >= 2 && delta_hz != 0; mdiv_idx--) { 687 + for (mdiv_idx = 15; mdiv_idx >= mdiv_min && delta_hz != 0; mdiv_idx--) { 684 688 /* 685 689 * For given ndiv and mdiv values check the 686 690 * two closest thp values. 687 691 */ 688 - tclk = i2c->twsi_freq * (mdiv_idx + 1) * 10; 692 + tclk = i2c->twsi_freq * (mdiv_idx + 1) * ds; 689 693 tclk *= (1 << ndiv_idx); 690 - thp_base = (i2c->sys_freq / (tclk * 2)) - 1; 694 + if (is_plat_otx2) 695 + thp_base = (i2c->sys_freq / tclk) - 2; 696 + else 697 + thp_base = (i2c->sys_freq / (tclk * 2)) - 1; 691 698 692 699 for (inc = 0; inc <= 1; inc++) { 693 700 thp_idx = thp_base + inc; 694 701 if (thp_idx < 5 || thp_idx > 0xff) 695 702 continue; 696 703 697 - foscl = i2c->sys_freq / (2 * (thp_idx + 1)); 704 + if (is_plat_otx2) 705 + foscl = i2c->sys_freq / (thp_idx + 2); 706 + else 707 + foscl = i2c->sys_freq / 708 + (2 * (thp_idx + 1)); 698 709 foscl = foscl / (1 << ndiv_idx); 699 - foscl = foscl / (mdiv_idx + 1) / 10; 710 + foscl = foscl / (mdiv_idx + 1) / ds; 711 + if (foscl > i2c->twsi_freq) 712 + continue; 700 713 diff = abs(foscl - i2c->twsi_freq); 714 + /* 715 + * Diff holds difference between calculated frequency 716 + * value vs desired frequency. 717 + * Delta_hz is updated with last minimum diff. 718 + */ 701 719 if (diff < delta_hz) { 702 720 delta_hz = diff; 703 721 thp = thp_idx; ··· 742 694 } 743 695 octeon_i2c_reg_write(i2c, SW_TWSI_OP_TWSI_CLK, thp); 744 696 octeon_i2c_reg_write(i2c, SW_TWSI_EOP_TWSI_CLKCTL, (mdiv << 3) | ndiv); 697 + if (is_plat_otx2) { 698 + u64 mode; 699 + 700 + mode = __raw_readq(i2c->twsi_base + OCTEON_REG_MODE(i2c)); 701 + /* Set REFCLK_SRC and HS_MODE in TWSX_MODE register */ 702 + if (!IS_LS_FREQ(i2c->twsi_freq)) 703 + mode |= TWSX_MODE_HS_MASK; 704 + else 705 + mode &= ~TWSX_MODE_HS_MASK; 706 + octeon_i2c_writeq_flush(mode, i2c->twsi_base + OCTEON_REG_MODE(i2c)); 707 + } 745 708 } 746 709 747 710 int octeon_i2c_init_lowlevel(struct octeon_i2c *i2c)
+41 -12
drivers/i2c/busses/i2c-octeon-core.h
··· 1 1 /* SPDX-License-Identifier: GPL-2.0 */ 2 2 #include <linux/atomic.h> 3 + #include <linux/bitfield.h> 3 4 #include <linux/clk.h> 4 5 #include <linux/delay.h> 5 6 #include <linux/device.h> ··· 8 7 #include <linux/i2c-smbus.h> 9 8 #include <linux/io.h> 10 9 #include <linux/kernel.h> 10 + #include <linux/pci.h> 11 11 12 12 /* Controller command patterns */ 13 13 #define SW_TWSI_V BIT_ULL(63) /* Valid bit */ ··· 73 71 #define STAT_SLAVE_ACK 0xC8 74 72 #define STAT_AD2W_ACK 0xD0 75 73 #define STAT_AD2W_NAK 0xD8 74 + #define STAT_WDOG_TOUT 0xF0 76 75 #define STAT_IDLE 0xF8 77 76 78 77 /* TWSI_INT values */ ··· 95 92 unsigned int sw_twsi; 96 93 unsigned int twsi_int; 97 94 unsigned int sw_twsi_ext; 95 + unsigned int mode; 98 96 }; 99 97 100 - #define SW_TWSI(x) (x->roff.sw_twsi) 101 - #define TWSI_INT(x) (x->roff.twsi_int) 102 - #define SW_TWSI_EXT(x) (x->roff.sw_twsi_ext) 98 + #define OCTEON_REG_SW_TWSI(x) ((x)->roff.sw_twsi) 99 + #define OCTEON_REG_TWSI_INT(x) ((x)->roff.twsi_int) 100 + #define OCTEON_REG_SW_TWSI_EXT(x) ((x)->roff.sw_twsi_ext) 101 + #define OCTEON_REG_MODE(x) ((x)->roff.mode) 102 + 103 + /* Set REFCLK_SRC and HS_MODE in TWSX_MODE register */ 104 + #define TWSX_MODE_REFCLK_SRC BIT(4) 105 + #define TWSX_MODE_HS_MODE BIT(0) 106 + #define TWSX_MODE_HS_MASK (TWSX_MODE_REFCLK_SRC | TWSX_MODE_HS_MODE) 107 + 108 + /* Set BUS_MON_RST to reset bus monitor */ 109 + #define BUS_MON_RST_MASK BIT(3) 103 110 104 111 struct octeon_i2c { 105 112 wait_queue_head_t queue; ··· 147 134 * @eop_reg: Register selector 148 135 * @data: Value to be written 149 136 * 150 - * The I2C core registers are accessed indirectly via the SW_TWSI CSR. 137 + * The I2C core registers are accessed indirectly via the OCTEON_REG_SW_TWSI CSR. 151 138 */ 152 139 static inline void octeon_i2c_reg_write(struct octeon_i2c *i2c, u64 eop_reg, u8 data) 153 140 { 154 141 int tries = 1000; 155 142 u64 tmp; 156 143 157 - __raw_writeq(SW_TWSI_V | eop_reg | data, i2c->twsi_base + SW_TWSI(i2c)); 144 + __raw_writeq(SW_TWSI_V | eop_reg | data, i2c->twsi_base + OCTEON_REG_SW_TWSI(i2c)); 158 145 do { 159 - tmp = __raw_readq(i2c->twsi_base + SW_TWSI(i2c)); 146 + tmp = __raw_readq(i2c->twsi_base + OCTEON_REG_SW_TWSI(i2c)); 160 147 if (--tries < 0) 161 148 return; 162 149 } while ((tmp & SW_TWSI_V) != 0); ··· 182 169 int tries = 1000; 183 170 u64 tmp; 184 171 185 - __raw_writeq(SW_TWSI_V | eop_reg | SW_TWSI_R, i2c->twsi_base + SW_TWSI(i2c)); 172 + __raw_writeq(SW_TWSI_V | eop_reg | SW_TWSI_R, i2c->twsi_base + OCTEON_REG_SW_TWSI(i2c)); 186 173 do { 187 - tmp = __raw_readq(i2c->twsi_base + SW_TWSI(i2c)); 174 + tmp = __raw_readq(i2c->twsi_base + OCTEON_REG_SW_TWSI(i2c)); 188 175 if (--tries < 0) { 189 176 /* signal that the returned data is invalid */ 190 177 if (error) ··· 204 191 octeon_i2c_reg_read(i2c, SW_TWSI_EOP_TWSI_STAT, NULL) 205 192 206 193 /** 207 - * octeon_i2c_read_int - read the TWSI_INT register 194 + * octeon_i2c_read_int - read the OCTEON_REG_TWSI_INT register 208 195 * @i2c: The struct octeon_i2c 209 196 * 210 197 * Returns the value of the register. 211 198 */ 212 199 static inline u64 octeon_i2c_read_int(struct octeon_i2c *i2c) 213 200 { 214 - return __raw_readq(i2c->twsi_base + TWSI_INT(i2c)); 201 + return __raw_readq(i2c->twsi_base + OCTEON_REG_TWSI_INT(i2c)); 215 202 } 216 203 217 204 /** 218 - * octeon_i2c_write_int - write the TWSI_INT register 205 + * octeon_i2c_write_int - write the OCTEON_REG_TWSI_INT register 219 206 * @i2c: The struct octeon_i2c 220 207 * @data: Value to be written 221 208 */ 222 209 static inline void octeon_i2c_write_int(struct octeon_i2c *i2c, u64 data) 223 210 { 224 - octeon_i2c_writeq_flush(data, i2c->twsi_base + TWSI_INT(i2c)); 211 + octeon_i2c_writeq_flush(data, i2c->twsi_base + OCTEON_REG_TWSI_INT(i2c)); 212 + } 213 + 214 + #define IS_LS_FREQ(twsi_freq) ((twsi_freq) <= 400000) 215 + #define PCI_SUBSYS_DEVID_9XXX 0xB 216 + #define PCI_SUBSYS_MASK GENMASK(15, 12) 217 + /** 218 + * octeon_i2c_is_otx2 - check for chip ID 219 + * @pdev: PCI dev structure 220 + * 221 + * Returns true if the device is an OcteonTX2, false otherwise. 222 + */ 223 + static inline bool octeon_i2c_is_otx2(struct pci_dev *pdev) 224 + { 225 + u32 chip_id = FIELD_GET(PCI_SUBSYS_MASK, pdev->subsystem_device); 226 + 227 + return (chip_id == PCI_SUBSYS_DEVID_9XXX); 225 228 } 226 229 227 230 /* Prototypes */
+5 -6
drivers/i2c/busses/i2c-omap.c
··· 660 660 struct i2c_msg *msg, int stop, bool polling) 661 661 { 662 662 struct omap_i2c_dev *omap = i2c_get_adapdata(adap); 663 - unsigned long timeout; 663 + unsigned long time_left; 664 664 u16 w; 665 665 int ret; 666 666 ··· 740 740 * into arbitration and we're currently unable to recover from it. 741 741 */ 742 742 if (!polling) { 743 - timeout = wait_for_completion_timeout(&omap->cmd_complete, 744 - OMAP_I2C_TIMEOUT); 743 + time_left = wait_for_completion_timeout(&omap->cmd_complete, 744 + OMAP_I2C_TIMEOUT); 745 745 } else { 746 746 do { 747 747 omap_i2c_wait(omap); 748 748 ret = omap_i2c_xfer_data(omap); 749 749 } while (ret == -EAGAIN); 750 750 751 - timeout = !ret; 751 + time_left = !ret; 752 752 } 753 753 754 - if (timeout == 0) { 755 - dev_err(omap->dev, "controller timed out\n"); 754 + if (time_left == 0) { 756 755 omap_i2c_reset(omap); 757 756 __omap_i2c_init(omap); 758 757 return -ETIMEDOUT;
+7 -7
drivers/i2c/busses/i2c-pxa.c
··· 826 826 static int i2c_pxa_send_mastercode(struct pxa_i2c *i2c) 827 827 { 828 828 u32 icr; 829 - long timeout; 829 + long time_left; 830 830 831 831 spin_lock_irq(&i2c->lock); 832 832 i2c->highmode_enter = true; ··· 837 837 writel(icr, _ICR(i2c)); 838 838 839 839 spin_unlock_irq(&i2c->lock); 840 - timeout = wait_event_timeout(i2c->wait, 841 - i2c->highmode_enter == false, HZ * 1); 840 + time_left = wait_event_timeout(i2c->wait, 841 + i2c->highmode_enter == false, HZ * 1); 842 842 843 843 i2c->highmode_enter = false; 844 844 845 - return (timeout == 0) ? I2C_RETRY : 0; 845 + return (time_left == 0) ? I2C_RETRY : 0; 846 846 } 847 847 848 848 /* ··· 1050 1050 */ 1051 1051 static int i2c_pxa_do_xfer(struct pxa_i2c *i2c, struct i2c_msg *msg, int num) 1052 1052 { 1053 - long timeout; 1053 + long time_left; 1054 1054 int ret; 1055 1055 1056 1056 /* ··· 1095 1095 /* 1096 1096 * The rest of the processing occurs in the interrupt handler. 1097 1097 */ 1098 - timeout = wait_event_timeout(i2c->wait, i2c->msg_num == 0, HZ * 5); 1098 + time_left = wait_event_timeout(i2c->wait, i2c->msg_num == 0, HZ * 5); 1099 1099 i2c_pxa_stop_message(i2c); 1100 1100 1101 1101 /* ··· 1103 1103 */ 1104 1104 ret = i2c->msg_idx; 1105 1105 1106 - if (!timeout && i2c->msg_num) { 1106 + if (!time_left && i2c->msg_num) { 1107 1107 i2c_pxa_scream_blue_murder(i2c, "timeout with active message"); 1108 1108 i2c_recover_bus(&i2c->adap); 1109 1109 ret = I2C_RETRY;
+4 -6
drivers/i2c/busses/i2c-qcom-geni.c
··· 586 586 { 587 587 struct dma_slave_config config = {}; 588 588 struct gpi_i2c_config peripheral = {}; 589 - int i, ret = 0, timeout; 589 + int i, ret = 0; 590 + unsigned long time_left; 590 591 dma_addr_t tx_addr, rx_addr; 591 592 void *tx_buf = NULL, *rx_buf = NULL; 592 593 const struct geni_i2c_clk_fld *itr = gi2c->clk_fld; ··· 630 629 631 630 dma_async_issue_pending(gi2c->tx_c); 632 631 633 - timeout = wait_for_completion_timeout(&gi2c->done, XFER_TIMEOUT); 634 - if (!timeout) { 635 - dev_err(gi2c->se.dev, "I2C timeout gpi flags:%d addr:0x%x\n", 636 - gi2c->cur->flags, gi2c->cur->addr); 632 + time_left = wait_for_completion_timeout(&gi2c->done, XFER_TIMEOUT); 633 + if (!time_left) 637 634 gi2c->err = -ETIMEDOUT; 638 - } 639 635 640 636 if (gi2c->err) { 641 637 ret = gi2c->err;
+1 -3
drivers/i2c/busses/i2c-qup.c
··· 793 793 dma_async_issue_pending(qup->brx.dma); 794 794 } 795 795 796 - if (!wait_for_completion_timeout(&qup->xfer, qup->xfer_timeout)) { 797 - dev_err(qup->dev, "normal trans timed out\n"); 796 + if (!wait_for_completion_timeout(&qup->xfer, qup->xfer_timeout)) 798 797 ret = -ETIMEDOUT; 799 - } 800 798 801 799 if (ret || qup->bus_err || qup->qup_err) { 802 800 reinit_completion(&qup->xfer);
+89 -36
drivers/i2c/busses/i2c-riic.c
··· 46 46 #include <linux/pm_runtime.h> 47 47 #include <linux/reset.h> 48 48 49 - #define RIIC_ICCR1 0x00 50 - #define RIIC_ICCR2 0x04 51 - #define RIIC_ICMR1 0x08 52 - #define RIIC_ICMR3 0x10 53 - #define RIIC_ICSER 0x18 54 - #define RIIC_ICIER 0x1c 55 - #define RIIC_ICSR2 0x24 56 - #define RIIC_ICBRL 0x34 57 - #define RIIC_ICBRH 0x38 58 - #define RIIC_ICDRT 0x3c 59 - #define RIIC_ICDRR 0x40 60 - 61 49 #define ICCR1_ICE 0x80 62 50 #define ICCR1_IICRST 0x40 63 51 #define ICCR1_SOWP 0x10 ··· 75 87 76 88 #define RIIC_INIT_MSG -1 77 89 90 + enum riic_reg_list { 91 + RIIC_ICCR1 = 0, 92 + RIIC_ICCR2, 93 + RIIC_ICMR1, 94 + RIIC_ICMR3, 95 + RIIC_ICSER, 96 + RIIC_ICIER, 97 + RIIC_ICSR2, 98 + RIIC_ICBRL, 99 + RIIC_ICBRH, 100 + RIIC_ICDRT, 101 + RIIC_ICDRR, 102 + RIIC_REG_END, 103 + }; 104 + 105 + struct riic_of_data { 106 + u8 regs[RIIC_REG_END]; 107 + }; 108 + 78 109 struct riic_dev { 79 110 void __iomem *base; 80 111 u8 *buf; ··· 101 94 int bytes_left; 102 95 int err; 103 96 int is_last; 97 + const struct riic_of_data *info; 104 98 struct completion msg_done; 105 99 struct i2c_adapter adapter; 106 100 struct clk *clk; ··· 113 105 char *name; 114 106 }; 115 107 108 + static inline void riic_writeb(struct riic_dev *riic, u8 val, u8 offset) 109 + { 110 + writeb(val, riic->base + riic->info->regs[offset]); 111 + } 112 + 113 + static inline u8 riic_readb(struct riic_dev *riic, u8 offset) 114 + { 115 + return readb(riic->base + riic->info->regs[offset]); 116 + } 117 + 116 118 static inline void riic_clear_set_bit(struct riic_dev *riic, u8 clear, u8 set, u8 reg) 117 119 { 118 - writeb((readb(riic->base + reg) & ~clear) | set, riic->base + reg); 120 + riic_writeb(riic, (riic_readb(riic, reg) & ~clear) | set, reg); 119 121 } 120 122 121 123 static int riic_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) ··· 137 119 138 120 pm_runtime_get_sync(adap->dev.parent); 139 121 140 - if (readb(riic->base + RIIC_ICCR2) & ICCR2_BBSY) { 122 + if (riic_readb(riic, RIIC_ICCR2) & ICCR2_BBSY) { 141 123 riic->err = -EBUSY; 142 124 goto out; 143 125 } ··· 145 127 reinit_completion(&riic->msg_done); 146 128 riic->err = 0; 147 129 148 - writeb(0, riic->base + RIIC_ICSR2); 130 + riic_writeb(riic, 0, RIIC_ICSR2); 149 131 150 132 for (i = 0, start_bit = ICCR2_ST; i < num; i++) { 151 133 riic->bytes_left = RIIC_INIT_MSG; ··· 153 135 riic->msg = &msgs[i]; 154 136 riic->is_last = (i == num - 1); 155 137 156 - writeb(ICIER_NAKIE | ICIER_TIE, riic->base + RIIC_ICIER); 138 + riic_writeb(riic, ICIER_NAKIE | ICIER_TIE, RIIC_ICIER); 157 139 158 - writeb(start_bit, riic->base + RIIC_ICCR2); 140 + riic_writeb(riic, start_bit, RIIC_ICCR2); 159 141 160 142 time_left = wait_for_completion_timeout(&riic->msg_done, riic->adapter.timeout); 161 143 if (time_left == 0) ··· 209 191 * value could be moved to the shadow shift register right away. So 210 192 * this must be after updates to ICIER (where we want to disable TIE)! 211 193 */ 212 - writeb(val, riic->base + RIIC_ICDRT); 194 + riic_writeb(riic, val, RIIC_ICDRT); 213 195 214 196 return IRQ_HANDLED; 215 197 } ··· 218 200 { 219 201 struct riic_dev *riic = data; 220 202 221 - if (readb(riic->base + RIIC_ICSR2) & ICSR2_NACKF) { 203 + if (riic_readb(riic, RIIC_ICSR2) & ICSR2_NACKF) { 222 204 /* We got a NACKIE */ 223 - readb(riic->base + RIIC_ICDRR); /* dummy read */ 205 + riic_readb(riic, RIIC_ICDRR); /* dummy read */ 224 206 riic_clear_set_bit(riic, ICSR2_NACKF, 0, RIIC_ICSR2); 225 207 riic->err = -ENXIO; 226 208 } else if (riic->bytes_left) { ··· 229 211 230 212 if (riic->is_last || riic->err) { 231 213 riic_clear_set_bit(riic, ICIER_TEIE, ICIER_SPIE, RIIC_ICIER); 232 - writeb(ICCR2_SP, riic->base + RIIC_ICCR2); 214 + riic_writeb(riic, ICCR2_SP, RIIC_ICCR2); 233 215 } else { 234 216 /* Transfer is complete, but do not send STOP */ 235 217 riic_clear_set_bit(riic, ICIER_TEIE, 0, RIIC_ICIER); ··· 248 230 249 231 if (riic->bytes_left == RIIC_INIT_MSG) { 250 232 riic->bytes_left = riic->msg->len; 251 - readb(riic->base + RIIC_ICDRR); /* dummy read */ 233 + riic_readb(riic, RIIC_ICDRR); /* dummy read */ 252 234 return IRQ_HANDLED; 253 235 } 254 236 ··· 256 238 /* STOP must come before we set ACKBT! */ 257 239 if (riic->is_last) { 258 240 riic_clear_set_bit(riic, 0, ICIER_SPIE, RIIC_ICIER); 259 - writeb(ICCR2_SP, riic->base + RIIC_ICCR2); 241 + riic_writeb(riic, ICCR2_SP, RIIC_ICCR2); 260 242 } 261 243 262 244 riic_clear_set_bit(riic, 0, ICMR3_ACKBT, RIIC_ICMR3); ··· 266 248 } 267 249 268 250 /* Reading acks the RIE interrupt */ 269 - *riic->buf = readb(riic->base + RIIC_ICDRR); 251 + *riic->buf = riic_readb(riic, RIIC_ICDRR); 270 252 riic->buf++; 271 253 riic->bytes_left--; 272 254 ··· 278 260 struct riic_dev *riic = data; 279 261 280 262 /* read back registers to confirm writes have fully propagated */ 281 - writeb(0, riic->base + RIIC_ICSR2); 282 - readb(riic->base + RIIC_ICSR2); 283 - writeb(0, riic->base + RIIC_ICIER); 284 - readb(riic->base + RIIC_ICIER); 263 + riic_writeb(riic, 0, RIIC_ICSR2); 264 + riic_readb(riic, RIIC_ICSR2); 265 + riic_writeb(riic, 0, RIIC_ICIER); 266 + riic_readb(riic, RIIC_ICIER); 285 267 286 268 complete(&riic->msg_done); 287 269 ··· 383 365 t->scl_rise_ns / (1000000000 / rate), cks, brl, brh); 384 366 385 367 /* Changing the order of accessing IICRST and ICE may break things! */ 386 - writeb(ICCR1_IICRST | ICCR1_SOWP, riic->base + RIIC_ICCR1); 368 + riic_writeb(riic, ICCR1_IICRST | ICCR1_SOWP, RIIC_ICCR1); 387 369 riic_clear_set_bit(riic, 0, ICCR1_ICE, RIIC_ICCR1); 388 370 389 - writeb(ICMR1_CKS(cks), riic->base + RIIC_ICMR1); 390 - writeb(brh | ICBR_RESERVED, riic->base + RIIC_ICBRH); 391 - writeb(brl | ICBR_RESERVED, riic->base + RIIC_ICBRL); 371 + riic_writeb(riic, ICMR1_CKS(cks), RIIC_ICMR1); 372 + riic_writeb(riic, brh | ICBR_RESERVED, RIIC_ICBRH); 373 + riic_writeb(riic, brl | ICBR_RESERVED, RIIC_ICBRL); 392 374 393 - writeb(0, riic->base + RIIC_ICSER); 394 - writeb(ICMR3_ACKWP | ICMR3_RDRFS, riic->base + RIIC_ICMR3); 375 + riic_writeb(riic, 0, RIIC_ICSER); 376 + riic_writeb(riic, ICMR3_ACKWP | ICMR3_RDRFS, RIIC_ICMR3); 395 377 396 378 riic_clear_set_bit(riic, ICCR1_IICRST, 0, RIIC_ICCR1); 397 379 ··· 461 443 } 462 444 } 463 445 446 + riic->info = of_device_get_match_data(&pdev->dev); 447 + 464 448 adap = &riic->adapter; 465 449 i2c_set_adapdata(adap, riic); 466 450 strscpy(adap->name, "Renesas RIIC adapter", sizeof(adap->name)); ··· 501 481 struct riic_dev *riic = platform_get_drvdata(pdev); 502 482 503 483 pm_runtime_get_sync(&pdev->dev); 504 - writeb(0, riic->base + RIIC_ICIER); 484 + riic_writeb(riic, 0, RIIC_ICIER); 505 485 pm_runtime_put(&pdev->dev); 506 486 i2c_del_adapter(&riic->adapter); 507 487 pm_runtime_disable(&pdev->dev); 508 488 } 509 489 490 + static const struct riic_of_data riic_rz_a_info = { 491 + .regs = { 492 + [RIIC_ICCR1] = 0x00, 493 + [RIIC_ICCR2] = 0x04, 494 + [RIIC_ICMR1] = 0x08, 495 + [RIIC_ICMR3] = 0x10, 496 + [RIIC_ICSER] = 0x18, 497 + [RIIC_ICIER] = 0x1c, 498 + [RIIC_ICSR2] = 0x24, 499 + [RIIC_ICBRL] = 0x34, 500 + [RIIC_ICBRH] = 0x38, 501 + [RIIC_ICDRT] = 0x3c, 502 + [RIIC_ICDRR] = 0x40, 503 + }, 504 + }; 505 + 506 + static const struct riic_of_data riic_rz_v2h_info = { 507 + .regs = { 508 + [RIIC_ICCR1] = 0x00, 509 + [RIIC_ICCR2] = 0x01, 510 + [RIIC_ICMR1] = 0x02, 511 + [RIIC_ICMR3] = 0x04, 512 + [RIIC_ICSER] = 0x06, 513 + [RIIC_ICIER] = 0x07, 514 + [RIIC_ICSR2] = 0x09, 515 + [RIIC_ICBRL] = 0x10, 516 + [RIIC_ICBRH] = 0x11, 517 + [RIIC_ICDRT] = 0x12, 518 + [RIIC_ICDRR] = 0x13, 519 + }, 520 + }; 521 + 510 522 static const struct of_device_id riic_i2c_dt_ids[] = { 511 - { .compatible = "renesas,riic-rz", }, 523 + { .compatible = "renesas,riic-rz", .data = &riic_rz_a_info }, 524 + { .compatible = "renesas,riic-r9a09g057", .data = &riic_rz_v2h_info }, 512 525 { /* Sentinel */ }, 513 526 }; 514 527
+6 -8
drivers/i2c/busses/i2c-rk3x.c
··· 1060 1060 struct i2c_msg *msgs, int num, bool polling) 1061 1061 { 1062 1062 struct rk3x_i2c *i2c = (struct rk3x_i2c *)adap->algo_data; 1063 - unsigned long timeout, flags; 1063 + unsigned long flags; 1064 + long time_left; 1064 1065 u32 val; 1065 1066 int ret = 0; 1066 1067 int i; ··· 1093 1092 if (!polling) { 1094 1093 rk3x_i2c_start(i2c); 1095 1094 1096 - timeout = wait_event_timeout(i2c->wait, !i2c->busy, 1097 - msecs_to_jiffies(WAIT_TIMEOUT)); 1095 + time_left = wait_event_timeout(i2c->wait, !i2c->busy, 1096 + msecs_to_jiffies(WAIT_TIMEOUT)); 1098 1097 } else { 1099 1098 disable_irq(i2c->irq); 1100 1099 rk3x_i2c_start(i2c); 1101 1100 1102 - timeout = rk3x_i2c_wait_xfer_poll(i2c); 1101 + time_left = rk3x_i2c_wait_xfer_poll(i2c); 1103 1102 1104 1103 enable_irq(i2c->irq); 1105 1104 } 1106 1105 1107 1106 spin_lock_irqsave(&i2c->lock, flags); 1108 1107 1109 - if (timeout == 0) { 1110 - dev_err(i2c->dev, "timeout, ipd: 0x%02x, state: %d\n", 1111 - i2c_readl(i2c, REG_IPD), i2c->state); 1112 - 1108 + if (time_left == 0) { 1113 1109 /* Force a STOP condition without interrupt */ 1114 1110 i2c_writel(i2c, 0, REG_IEN); 1115 1111 val = i2c_readl(i2c, REG_CON) & REG_CON_TUNING_MASK;
+3 -3
drivers/i2c/busses/i2c-s3c2410.c
··· 685 685 static int s3c24xx_i2c_doxfer(struct s3c24xx_i2c *i2c, 686 686 struct i2c_msg *msgs, int num) 687 687 { 688 - unsigned long timeout = 0; 688 + long time_left = 0; 689 689 int ret; 690 690 691 691 ret = s3c24xx_i2c_set_master(i2c); ··· 715 715 dev_err(i2c->dev, "deal with arbitration loss\n"); 716 716 } 717 717 } else { 718 - timeout = wait_event_timeout(i2c->wait, i2c->msg_num == 0, HZ * 5); 718 + time_left = wait_event_timeout(i2c->wait, i2c->msg_num == 0, HZ * 5); 719 719 } 720 720 721 721 ret = i2c->msg_idx; ··· 724 724 * Having these next two as dev_err() makes life very 725 725 * noisy when doing an i2cdetect 726 726 */ 727 - if (timeout == 0) 727 + if (time_left == 0) 728 728 dev_dbg(i2c->dev, "timeout\n"); 729 729 else if (ret != num) 730 730 dev_dbg(i2c->dev, "incomplete xfer (%d)\n", ret);
-1
drivers/i2c/busses/i2c-sh_mobile.c
··· 688 688 } 689 689 690 690 if (!time_left) { 691 - dev_err(pd->dev, "Transfer request timed out\n"); 692 691 if (pd->dma_direction != DMA_NONE) 693 692 sh_mobile_i2c_cleanup_dma(pd, true); 694 693
+4 -7
drivers/i2c/busses/i2c-st.c
··· 647 647 { 648 648 struct st_i2c_client *c = &i2c_dev->client; 649 649 u32 ctl, i2c, it; 650 - unsigned long timeout; 650 + unsigned long time_left; 651 651 int ret; 652 652 653 653 c->addr = i2c_8bit_addr_from_msg(msg); ··· 685 685 st_i2c_set_bits(i2c_dev->base + SSC_I2C, SSC_I2C_STRTG); 686 686 } 687 687 688 - timeout = wait_for_completion_timeout(&i2c_dev->complete, 689 - i2c_dev->adap.timeout); 688 + time_left = wait_for_completion_timeout(&i2c_dev->complete, 689 + i2c_dev->adap.timeout); 690 690 ret = c->result; 691 691 692 - if (!timeout) { 693 - dev_err(i2c_dev->dev, "Write to slave 0x%x timed out\n", 694 - c->addr); 692 + if (!time_left) 695 693 ret = -ETIMEDOUT; 696 - } 697 694 698 695 i2c = SSC_I2C_STOPG | SSC_I2C_REPSTRTG; 699 696 st_i2c_clr_bits(i2c_dev->base + SSC_I2C, i2c);
+4 -4
drivers/i2c/busses/i2c-stm32f4.c
··· 681 681 { 682 682 struct stm32f4_i2c_msg *f4_msg = &i2c_dev->msg; 683 683 void __iomem *reg = i2c_dev->base + STM32F4_I2C_CR1; 684 - unsigned long timeout; 684 + unsigned long time_left; 685 685 u32 mask; 686 686 int ret; 687 687 ··· 706 706 stm32f4_i2c_set_bits(reg, STM32F4_I2C_CR1_START); 707 707 } 708 708 709 - timeout = wait_for_completion_timeout(&i2c_dev->complete, 710 - i2c_dev->adap.timeout); 709 + time_left = wait_for_completion_timeout(&i2c_dev->complete, 710 + i2c_dev->adap.timeout); 711 711 ret = f4_msg->result; 712 712 713 - if (!timeout) 713 + if (!time_left) 714 714 ret = -ETIMEDOUT; 715 715 716 716 return ret;
+4 -4
drivers/i2c/busses/i2c-stm32f7.c
··· 1789 1789 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; 1790 1790 struct stm32_i2c_dma *dma = i2c_dev->dma; 1791 1791 struct device *dev = i2c_dev->dev; 1792 - unsigned long timeout; 1792 + unsigned long time_left; 1793 1793 int i, ret; 1794 1794 1795 1795 f7_msg->addr = addr; ··· 1809 1809 if (ret) 1810 1810 goto pm_free; 1811 1811 1812 - timeout = wait_for_completion_timeout(&i2c_dev->complete, 1813 - i2c_dev->adap.timeout); 1812 + time_left = wait_for_completion_timeout(&i2c_dev->complete, 1813 + i2c_dev->adap.timeout); 1814 1814 ret = f7_msg->result; 1815 1815 if (ret) { 1816 1816 if (i2c_dev->use_dma) ··· 1826 1826 goto pm_free; 1827 1827 } 1828 1828 1829 - if (!timeout) { 1829 + if (!time_left) { 1830 1830 dev_dbg(dev, "Access to slave 0x%x timed out\n", f7_msg->addr); 1831 1831 if (i2c_dev->use_dma) 1832 1832 dmaengine_terminate_sync(dma->chan_using);
+10 -16
drivers/i2c/busses/i2c-synquacer.c
··· 311 311 struct i2c_msg *msgs, int num) 312 312 { 313 313 unsigned char bsr; 314 - unsigned long timeout; 314 + unsigned long time_left; 315 315 int ret; 316 316 317 317 synquacer_i2c_hw_init(i2c); ··· 335 335 return ret; 336 336 } 337 337 338 - timeout = wait_for_completion_timeout(&i2c->completion, 339 - msecs_to_jiffies(i2c->timeout_ms)); 340 - if (timeout == 0) { 338 + time_left = wait_for_completion_timeout(&i2c->completion, 339 + msecs_to_jiffies(i2c->timeout_ms)); 340 + if (time_left == 0) { 341 341 dev_dbg(i2c->dev, "timeout\n"); 342 342 return -EAGAIN; 343 343 } ··· 550 550 device_property_read_u32(&pdev->dev, "socionext,pclk-rate", 551 551 &i2c->pclkrate); 552 552 553 - i2c->pclk = devm_clk_get(&pdev->dev, "pclk"); 554 - if (PTR_ERR(i2c->pclk) == -EPROBE_DEFER) 555 - return -EPROBE_DEFER; 556 - if (!IS_ERR_OR_NULL(i2c->pclk)) { 557 - dev_dbg(&pdev->dev, "clock source %p\n", i2c->pclk); 553 + i2c->pclk = devm_clk_get_enabled(&pdev->dev, "pclk"); 554 + if (IS_ERR(i2c->pclk)) 555 + return dev_err_probe(&pdev->dev, PTR_ERR(i2c->pclk), 556 + "failed to get and enable clock\n"); 558 557 559 - ret = clk_prepare_enable(i2c->pclk); 560 - if (ret) 561 - return dev_err_probe(&pdev->dev, ret, "failed to enable clock\n"); 562 - i2c->pclkrate = clk_get_rate(i2c->pclk); 563 - } 558 + dev_dbg(&pdev->dev, "clock source %p\n", i2c->pclk); 559 + i2c->pclkrate = clk_get_rate(i2c->pclk); 564 560 565 561 if (i2c->pclkrate < SYNQUACER_I2C_MIN_CLK_RATE || 566 562 i2c->pclkrate > SYNQUACER_I2C_MAX_CLK_RATE) ··· 611 615 struct synquacer_i2c *i2c = platform_get_drvdata(pdev); 612 616 613 617 i2c_del_adapter(&i2c->adapter); 614 - if (!IS_ERR(i2c->pclk)) 615 - clk_disable_unprepare(i2c->pclk); 616 618 }; 617 619 618 620 static const struct of_device_id synquacer_i2c_dt_ids[] __maybe_unused = {
-2
drivers/i2c/busses/i2c-tegra.c
··· 1331 1331 dmaengine_terminate_sync(i2c_dev->dma_chan); 1332 1332 1333 1333 if (!time_left && !completion_done(&i2c_dev->dma_complete)) { 1334 - dev_err(i2c_dev->dev, "DMA transfer timed out\n"); 1335 1334 tegra_i2c_init(i2c_dev); 1336 1335 return -ETIMEDOUT; 1337 1336 } ··· 1350 1351 tegra_i2c_mask_irq(i2c_dev, int_mask); 1351 1352 1352 1353 if (time_left == 0) { 1353 - dev_err(i2c_dev->dev, "I2C transfer timed out\n"); 1354 1354 tegra_i2c_init(i2c_dev); 1355 1355 return -ETIMEDOUT; 1356 1356 }
+11 -2
drivers/i2c/busses/i2c-thunderx-pcidrv.c
··· 27 27 28 28 #define PCI_DEVICE_ID_THUNDER_TWSI 0xa012 29 29 30 - #define SYS_FREQ_DEFAULT 700000000 30 + #define SYS_FREQ_DEFAULT 800000000 31 + #define OTX2_REF_FREQ_DEFAULT 100000000 31 32 32 33 #define TWSI_INT_ENA_W1C 0x1028 33 34 #define TWSI_INT_ENA_W1S 0x1030 ··· 100 99 i2c->sys_freq = clk_get_rate(i2c->clk); 101 100 } else { 102 101 /* ACPI */ 103 - device_property_read_u32(dev, "sclk", &i2c->sys_freq); 102 + if (device_property_read_u32(dev, "sclk", &i2c->sys_freq)) 103 + device_property_read_u32(dev, "ioclk", &i2c->sys_freq); 104 104 } 105 105 106 106 skip: ··· 167 165 i2c->roff.sw_twsi = 0x1000; 168 166 i2c->roff.twsi_int = 0x1010; 169 167 i2c->roff.sw_twsi_ext = 0x1018; 168 + i2c->roff.mode = 0x1038; 170 169 171 170 i2c->dev = dev; 172 171 pci_set_drvdata(pdev, i2c); ··· 208 205 if (ret) 209 206 goto error; 210 207 208 + /* 209 + * For OcteonTX2 chips, set reference frequency to 100MHz 210 + * as refclk_src in TWSI_MODE register defaults to 100MHz. 211 + */ 212 + if (octeon_i2c_is_otx2(pdev) && IS_LS_FREQ(i2c->twsi_freq)) 213 + i2c->sys_freq = OTX2_REF_FREQ_DEFAULT; 211 214 octeon_i2c_set_clock(i2c); 212 215 213 216 i2c->adap = thunderx_i2c_ops;
-1
drivers/i2c/busses/i2c-uniphier-f.c
··· 358 358 spin_unlock_irqrestore(&priv->lock, flags); 359 359 360 360 if (!time_left) { 361 - dev_err(&adap->dev, "transaction timeout.\n"); 362 361 uniphier_fi2c_recover(priv); 363 362 return -ETIMEDOUT; 364 363 }
+1 -3
drivers/i2c/busses/i2c-uniphier.c
··· 71 71 writel(txdata, priv->membase + UNIPHIER_I2C_DTRM); 72 72 73 73 time_left = wait_for_completion_timeout(&priv->comp, adap->timeout); 74 - if (unlikely(!time_left)) { 75 - dev_err(&adap->dev, "transaction timeout\n"); 74 + if (unlikely(!time_left)) 76 75 return -ETIMEDOUT; 77 - } 78 76 79 77 rxdata = readl(priv->membase + UNIPHIER_I2C_DREC); 80 78 if (rxdatap)
+256
drivers/i2c/busses/i2c-viai2c-common.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + #include <linux/of_irq.h> 3 + #include "i2c-viai2c-common.h" 4 + 5 + int viai2c_wait_bus_not_busy(struct viai2c *i2c) 6 + { 7 + unsigned long timeout; 8 + 9 + timeout = jiffies + VIAI2C_TIMEOUT; 10 + while (!(readw(i2c->base + VIAI2C_REG_CSR) & VIAI2C_CSR_READY_MASK)) { 11 + if (time_after(jiffies, timeout)) { 12 + dev_warn(i2c->dev, "timeout waiting for bus ready\n"); 13 + return -EBUSY; 14 + } 15 + msleep(20); 16 + } 17 + 18 + return 0; 19 + } 20 + 21 + static int viai2c_write(struct viai2c *i2c, struct i2c_msg *pmsg, int last) 22 + { 23 + u16 val, tcr_val = i2c->tcr; 24 + 25 + i2c->last = last; 26 + 27 + if (pmsg->len == 0) { 28 + /* 29 + * We still need to run through the while (..) once, so 30 + * start at -1 and break out early from the loop 31 + */ 32 + i2c->xfered_len = -1; 33 + writew(0, i2c->base + VIAI2C_REG_CDR); 34 + } else { 35 + writew(pmsg->buf[0] & 0xFF, i2c->base + VIAI2C_REG_CDR); 36 + } 37 + 38 + if (i2c->platform == VIAI2C_PLAT_WMT && !(pmsg->flags & I2C_M_NOSTART)) { 39 + val = readw(i2c->base + VIAI2C_REG_CR); 40 + val &= ~VIAI2C_CR_TX_END; 41 + val |= VIAI2C_CR_CPU_RDY; 42 + writew(val, i2c->base + VIAI2C_REG_CR); 43 + } 44 + 45 + reinit_completion(&i2c->complete); 46 + 47 + tcr_val |= pmsg->addr & VIAI2C_TCR_ADDR_MASK; 48 + 49 + writew(tcr_val, i2c->base + VIAI2C_REG_TCR); 50 + 51 + if (i2c->platform == VIAI2C_PLAT_WMT && pmsg->flags & I2C_M_NOSTART) { 52 + val = readw(i2c->base + VIAI2C_REG_CR); 53 + val |= VIAI2C_CR_CPU_RDY; 54 + writew(val, i2c->base + VIAI2C_REG_CR); 55 + } 56 + 57 + if (!wait_for_completion_timeout(&i2c->complete, VIAI2C_TIMEOUT)) 58 + return -ETIMEDOUT; 59 + 60 + return i2c->ret; 61 + } 62 + 63 + static int viai2c_read(struct viai2c *i2c, struct i2c_msg *pmsg, bool first) 64 + { 65 + u16 val, tcr_val = i2c->tcr; 66 + 67 + val = readw(i2c->base + VIAI2C_REG_CR); 68 + val &= ~(VIAI2C_CR_TX_END | VIAI2C_CR_RX_END); 69 + 70 + if (i2c->platform == VIAI2C_PLAT_WMT && !(pmsg->flags & I2C_M_NOSTART)) 71 + val |= VIAI2C_CR_CPU_RDY; 72 + 73 + if (pmsg->len == 1) 74 + val |= VIAI2C_CR_RX_END; 75 + 76 + writew(val, i2c->base + VIAI2C_REG_CR); 77 + 78 + reinit_completion(&i2c->complete); 79 + 80 + tcr_val |= VIAI2C_TCR_READ | (pmsg->addr & VIAI2C_TCR_ADDR_MASK); 81 + 82 + writew(tcr_val, i2c->base + VIAI2C_REG_TCR); 83 + 84 + if ((i2c->platform == VIAI2C_PLAT_WMT && (pmsg->flags & I2C_M_NOSTART)) || 85 + (i2c->platform == VIAI2C_PLAT_ZHAOXIN && !first)) { 86 + val = readw(i2c->base + VIAI2C_REG_CR); 87 + val |= VIAI2C_CR_CPU_RDY; 88 + writew(val, i2c->base + VIAI2C_REG_CR); 89 + } 90 + 91 + if (!wait_for_completion_timeout(&i2c->complete, VIAI2C_TIMEOUT)) 92 + return -ETIMEDOUT; 93 + 94 + return i2c->ret; 95 + } 96 + 97 + int viai2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) 98 + { 99 + struct i2c_msg *pmsg; 100 + int i; 101 + int ret = 0; 102 + struct viai2c *i2c = i2c_get_adapdata(adap); 103 + 104 + i2c->mode = VIAI2C_BYTE_MODE; 105 + for (i = 0; ret >= 0 && i < num; i++) { 106 + pmsg = &msgs[i]; 107 + if (i2c->platform == VIAI2C_PLAT_WMT && !(pmsg->flags & I2C_M_NOSTART)) { 108 + ret = viai2c_wait_bus_not_busy(i2c); 109 + if (ret < 0) 110 + return ret; 111 + } 112 + 113 + i2c->msg = pmsg; 114 + i2c->xfered_len = 0; 115 + 116 + if (pmsg->flags & I2C_M_RD) 117 + ret = viai2c_read(i2c, pmsg, i == 0); 118 + else 119 + ret = viai2c_write(i2c, pmsg, (i + 1) == num); 120 + } 121 + 122 + return (ret < 0) ? ret : i; 123 + } 124 + 125 + /* 126 + * Main process of the byte mode xfer 127 + * 128 + * Return value indicates whether the transfer is complete 129 + * 1: all the data has been successfully transferred 130 + * 0: there is still data that needs to be transferred 131 + * -EIO: error occurred 132 + */ 133 + static int viai2c_irq_xfer(struct viai2c *i2c) 134 + { 135 + u16 val; 136 + struct i2c_msg *msg = i2c->msg; 137 + u8 read = msg->flags & I2C_M_RD; 138 + void __iomem *base = i2c->base; 139 + 140 + if (read) { 141 + msg->buf[i2c->xfered_len] = readw(base + VIAI2C_REG_CDR) >> 8; 142 + 143 + val = readw(base + VIAI2C_REG_CR) | VIAI2C_CR_CPU_RDY; 144 + if (i2c->xfered_len == msg->len - 2) 145 + val |= VIAI2C_CR_RX_END; 146 + writew(val, base + VIAI2C_REG_CR); 147 + } else { 148 + val = readw(base + VIAI2C_REG_CSR); 149 + if (val & VIAI2C_CSR_RCV_NOT_ACK) 150 + return -EIO; 151 + 152 + /* I2C_SMBUS_QUICK */ 153 + if (msg->len == 0) { 154 + val = VIAI2C_CR_TX_END | VIAI2C_CR_CPU_RDY | VIAI2C_CR_ENABLE; 155 + writew(val, base + VIAI2C_REG_CR); 156 + return 1; 157 + } 158 + 159 + if ((i2c->xfered_len + 1) == msg->len) { 160 + if (i2c->platform == VIAI2C_PLAT_WMT && !i2c->last) 161 + writew(VIAI2C_CR_ENABLE, base + VIAI2C_REG_CR); 162 + else if (i2c->platform == VIAI2C_PLAT_ZHAOXIN && i2c->last) 163 + writeb(VIAI2C_CR_TX_END, base + VIAI2C_REG_CR); 164 + } else { 165 + writew(msg->buf[i2c->xfered_len + 1] & 0xFF, base + VIAI2C_REG_CDR); 166 + writew(VIAI2C_CR_CPU_RDY | VIAI2C_CR_ENABLE, base + VIAI2C_REG_CR); 167 + } 168 + } 169 + 170 + i2c->xfered_len++; 171 + 172 + return i2c->xfered_len == msg->len; 173 + } 174 + 175 + int __weak viai2c_fifo_irq_xfer(struct viai2c *i2c, bool irq) 176 + { 177 + return 0; 178 + } 179 + 180 + static irqreturn_t viai2c_isr(int irq, void *data) 181 + { 182 + struct viai2c *i2c = data; 183 + u8 status; 184 + 185 + /* save the status and write-clear it */ 186 + status = readw(i2c->base + VIAI2C_REG_ISR); 187 + if (!status && i2c->platform == VIAI2C_PLAT_ZHAOXIN) 188 + return IRQ_NONE; 189 + 190 + writew(status, i2c->base + VIAI2C_REG_ISR); 191 + 192 + i2c->ret = 0; 193 + if (status & VIAI2C_ISR_NACK_ADDR) 194 + i2c->ret = -EIO; 195 + 196 + if (i2c->platform == VIAI2C_PLAT_WMT && (status & VIAI2C_ISR_SCL_TIMEOUT)) 197 + i2c->ret = -ETIMEDOUT; 198 + 199 + if (!i2c->ret) { 200 + if (i2c->mode == VIAI2C_BYTE_MODE) 201 + i2c->ret = viai2c_irq_xfer(i2c); 202 + else 203 + i2c->ret = viai2c_fifo_irq_xfer(i2c, true); 204 + } 205 + 206 + /* All the data has been successfully transferred or error occurred */ 207 + if (i2c->ret) 208 + complete(&i2c->complete); 209 + 210 + return IRQ_HANDLED; 211 + } 212 + 213 + int viai2c_init(struct platform_device *pdev, struct viai2c **pi2c, int plat) 214 + { 215 + int err; 216 + int irq_flags; 217 + struct viai2c *i2c; 218 + struct device_node *np = pdev->dev.of_node; 219 + 220 + i2c = devm_kzalloc(&pdev->dev, sizeof(*i2c), GFP_KERNEL); 221 + if (!i2c) 222 + return -ENOMEM; 223 + 224 + i2c->base = devm_platform_get_and_ioremap_resource(pdev, 0, NULL); 225 + if (IS_ERR(i2c->base)) 226 + return PTR_ERR(i2c->base); 227 + 228 + if (plat == VIAI2C_PLAT_WMT) { 229 + irq_flags = 0; 230 + i2c->irq = irq_of_parse_and_map(np, 0); 231 + if (!i2c->irq) 232 + return -EINVAL; 233 + } else if (plat == VIAI2C_PLAT_ZHAOXIN) { 234 + irq_flags = IRQF_SHARED; 235 + i2c->irq = platform_get_irq(pdev, 0); 236 + if (i2c->irq < 0) 237 + return i2c->irq; 238 + } else { 239 + return dev_err_probe(&pdev->dev, -EINVAL, "wrong platform type\n"); 240 + } 241 + 242 + i2c->platform = plat; 243 + 244 + err = devm_request_irq(&pdev->dev, i2c->irq, viai2c_isr, 245 + irq_flags, pdev->name, i2c); 246 + if (err) 247 + return dev_err_probe(&pdev->dev, err, 248 + "failed to request irq %i\n", i2c->irq); 249 + 250 + i2c->dev = &pdev->dev; 251 + init_completion(&i2c->complete); 252 + platform_set_drvdata(pdev, i2c); 253 + 254 + *pi2c = i2c; 255 + return 0; 256 + }
+85
drivers/i2c/busses/i2c-viai2c-common.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 + #ifndef __I2C_VIAI2C_COMMON_H_ 3 + #define __I2C_VIAI2C_COMMON_H_ 4 + 5 + #include <linux/delay.h> 6 + #include <linux/err.h> 7 + #include <linux/i2c.h> 8 + #include <linux/interrupt.h> 9 + #include <linux/io.h> 10 + #include <linux/module.h> 11 + #include <linux/of_irq.h> 12 + #include <linux/platform_device.h> 13 + 14 + /* REG_CR Bit fields */ 15 + #define VIAI2C_REG_CR 0x00 16 + #define VIAI2C_CR_ENABLE BIT(0) 17 + #define VIAI2C_CR_RX_END BIT(1) 18 + #define VIAI2C_CR_TX_END BIT(2) 19 + #define VIAI2C_CR_CPU_RDY BIT(3) 20 + #define VIAI2C_CR_END_MASK GENMASK(2, 1) 21 + 22 + /* REG_TCR Bit fields */ 23 + #define VIAI2C_REG_TCR 0x02 24 + #define VIAI2C_TCR_HS_MODE BIT(13) 25 + #define VIAI2C_TCR_READ BIT(14) 26 + #define VIAI2C_TCR_FAST BIT(15) 27 + #define VIAI2C_TCR_ADDR_MASK GENMASK(6, 0) 28 + 29 + /* REG_CSR Bit fields */ 30 + #define VIAI2C_REG_CSR 0x04 31 + #define VIAI2C_CSR_RCV_NOT_ACK BIT(0) 32 + #define VIAI2C_CSR_RCV_ACK_MASK BIT(0) 33 + #define VIAI2C_CSR_READY_MASK BIT(1) 34 + 35 + /* REG_ISR Bit fields */ 36 + #define VIAI2C_REG_ISR 0x06 37 + #define VIAI2C_ISR_NACK_ADDR BIT(0) 38 + #define VIAI2C_ISR_BYTE_END BIT(1) 39 + #define VIAI2C_ISR_SCL_TIMEOUT BIT(2) 40 + #define VIAI2C_ISR_MASK_ALL GENMASK(2, 0) 41 + 42 + /* REG_IMR Bit fields */ 43 + #define VIAI2C_REG_IMR 0x08 44 + #define VIAI2C_IMR_BYTE BIT(1) 45 + #define VIAI2C_IMR_ENABLE_ALL GENMASK(2, 0) 46 + 47 + #define VIAI2C_REG_CDR 0x0A 48 + #define VIAI2C_REG_TR 0x0C 49 + #define VIAI2C_REG_MCR 0x0E 50 + 51 + #define VIAI2C_TIMEOUT (msecs_to_jiffies(1000)) 52 + 53 + enum { 54 + VIAI2C_PLAT_WMT, 55 + VIAI2C_PLAT_ZHAOXIN 56 + }; 57 + 58 + enum { 59 + VIAI2C_BYTE_MODE, 60 + VIAI2C_FIFO_MODE 61 + }; 62 + 63 + struct viai2c { 64 + struct i2c_adapter adapter; 65 + struct completion complete; 66 + struct device *dev; 67 + void __iomem *base; 68 + struct clk *clk; 69 + u16 tcr; 70 + int irq; 71 + u16 xfered_len; 72 + struct i2c_msg *msg; 73 + int ret; 74 + bool last; 75 + unsigned int mode; 76 + unsigned int platform; 77 + void *pltfm_priv; 78 + }; 79 + 80 + int viai2c_wait_bus_not_busy(struct viai2c *i2c); 81 + int viai2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num); 82 + int viai2c_init(struct platform_device *pdev, struct viai2c **pi2c, int plat); 83 + int viai2c_fifo_irq_xfer(struct viai2c *i2c, bool irq); 84 + 85 + #endif
+148
drivers/i2c/busses/i2c-viai2c-wmt.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + /* 3 + * Wondermedia I2C Master Mode Driver 4 + * 5 + * Copyright (C) 2012 Tony Prisk <linux@prisktech.co.nz> 6 + * 7 + * Derived from GPLv2+ licensed source: 8 + * - Copyright (C) 2008 WonderMedia Technologies, Inc. 9 + */ 10 + 11 + #include <linux/clk.h> 12 + #include <linux/of.h> 13 + #include <linux/of_address.h> 14 + #include "i2c-viai2c-common.h" 15 + 16 + #define REG_SLAVE_CR 0x10 17 + #define REG_SLAVE_SR 0x12 18 + #define REG_SLAVE_ISR 0x14 19 + #define REG_SLAVE_IMR 0x16 20 + #define REG_SLAVE_DR 0x18 21 + #define REG_SLAVE_TR 0x1A 22 + 23 + /* REG_TR */ 24 + #define SCL_TIMEOUT(x) (((x) & 0xFF) << 8) 25 + #define TR_STD 0x0064 26 + #define TR_HS 0x0019 27 + 28 + /* REG_MCR */ 29 + #define MCR_APB_96M 7 30 + #define MCR_APB_166M 12 31 + 32 + static u32 wmt_i2c_func(struct i2c_adapter *adap) 33 + { 34 + return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_NOSTART; 35 + } 36 + 37 + static const struct i2c_algorithm wmt_i2c_algo = { 38 + .master_xfer = viai2c_xfer, 39 + .functionality = wmt_i2c_func, 40 + }; 41 + 42 + static int wmt_i2c_reset_hardware(struct viai2c *i2c) 43 + { 44 + int err; 45 + 46 + err = clk_prepare_enable(i2c->clk); 47 + if (err) { 48 + dev_err(i2c->dev, "failed to enable clock\n"); 49 + return err; 50 + } 51 + 52 + err = clk_set_rate(i2c->clk, 20000000); 53 + if (err) { 54 + dev_err(i2c->dev, "failed to set clock = 20Mhz\n"); 55 + clk_disable_unprepare(i2c->clk); 56 + return err; 57 + } 58 + 59 + writew(0, i2c->base + VIAI2C_REG_CR); 60 + writew(MCR_APB_166M, i2c->base + VIAI2C_REG_MCR); 61 + writew(VIAI2C_ISR_MASK_ALL, i2c->base + VIAI2C_REG_ISR); 62 + writew(VIAI2C_IMR_ENABLE_ALL, i2c->base + VIAI2C_REG_IMR); 63 + writew(VIAI2C_CR_ENABLE, i2c->base + VIAI2C_REG_CR); 64 + readw(i2c->base + VIAI2C_REG_CSR); /* read clear */ 65 + writew(VIAI2C_ISR_MASK_ALL, i2c->base + VIAI2C_REG_ISR); 66 + 67 + if (i2c->tcr == VIAI2C_TCR_FAST) 68 + writew(SCL_TIMEOUT(128) | TR_HS, i2c->base + VIAI2C_REG_TR); 69 + else 70 + writew(SCL_TIMEOUT(128) | TR_STD, i2c->base + VIAI2C_REG_TR); 71 + 72 + return 0; 73 + } 74 + 75 + static int wmt_i2c_probe(struct platform_device *pdev) 76 + { 77 + struct device_node *np = pdev->dev.of_node; 78 + struct viai2c *i2c; 79 + struct i2c_adapter *adap; 80 + int err; 81 + u32 clk_rate; 82 + 83 + err = viai2c_init(pdev, &i2c, VIAI2C_PLAT_WMT); 84 + if (err) 85 + return err; 86 + 87 + i2c->clk = of_clk_get(np, 0); 88 + if (IS_ERR(i2c->clk)) { 89 + dev_err(&pdev->dev, "unable to request clock\n"); 90 + return PTR_ERR(i2c->clk); 91 + } 92 + 93 + err = of_property_read_u32(np, "clock-frequency", &clk_rate); 94 + if (!err && clk_rate == I2C_MAX_FAST_MODE_FREQ) 95 + i2c->tcr = VIAI2C_TCR_FAST; 96 + 97 + adap = &i2c->adapter; 98 + i2c_set_adapdata(adap, i2c); 99 + strscpy(adap->name, "WMT I2C adapter", sizeof(adap->name)); 100 + adap->owner = THIS_MODULE; 101 + adap->algo = &wmt_i2c_algo; 102 + adap->dev.parent = &pdev->dev; 103 + adap->dev.of_node = pdev->dev.of_node; 104 + 105 + err = wmt_i2c_reset_hardware(i2c); 106 + if (err) { 107 + dev_err(&pdev->dev, "error initializing hardware\n"); 108 + return err; 109 + } 110 + 111 + err = i2c_add_adapter(adap); 112 + if (err) 113 + /* wmt_i2c_reset_hardware() enables i2c_dev->clk */ 114 + clk_disable_unprepare(i2c->clk); 115 + 116 + return err; 117 + } 118 + 119 + static void wmt_i2c_remove(struct platform_device *pdev) 120 + { 121 + struct viai2c *i2c = platform_get_drvdata(pdev); 122 + 123 + /* Disable interrupts, clock and delete adapter */ 124 + writew(0, i2c->base + VIAI2C_REG_IMR); 125 + clk_disable_unprepare(i2c->clk); 126 + i2c_del_adapter(&i2c->adapter); 127 + } 128 + 129 + static const struct of_device_id wmt_i2c_dt_ids[] = { 130 + { .compatible = "wm,wm8505-i2c" }, 131 + { /* Sentinel */ }, 132 + }; 133 + 134 + static struct platform_driver wmt_i2c_driver = { 135 + .probe = wmt_i2c_probe, 136 + .remove_new = wmt_i2c_remove, 137 + .driver = { 138 + .name = "wmt-i2c", 139 + .of_match_table = wmt_i2c_dt_ids, 140 + }, 141 + }; 142 + 143 + module_platform_driver(wmt_i2c_driver); 144 + 145 + MODULE_DESCRIPTION("Wondermedia I2C master-mode bus adapter"); 146 + MODULE_AUTHOR("Tony Prisk <linux@prisktech.co.nz>"); 147 + MODULE_LICENSE("GPL"); 148 + MODULE_DEVICE_TABLE(of, wmt_i2c_dt_ids);
+298
drivers/i2c/busses/i2c-viai2c-zhaoxin.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + /* 3 + * Copyright(c) 2024 Shanghai Zhaoxin Semiconductor Corporation. 4 + * All rights reserved. 5 + */ 6 + 7 + #include <linux/acpi.h> 8 + #include "i2c-viai2c-common.h" 9 + 10 + /* 11 + * registers 12 + */ 13 + /* Zhaoxin specific register bit fields */ 14 + /* REG_CR Bit fields */ 15 + #define ZXI2C_CR_MST_RST BIT(7) 16 + #define ZXI2C_CR_FIFO_MODE BIT(14) 17 + /* REG_ISR/IMR Bit fields */ 18 + #define ZXI2C_IRQ_FIFONACK BIT(4) 19 + #define ZXI2C_IRQ_FIFOEND BIT(3) 20 + #define ZXI2C_IRQ_MASK (VIAI2C_ISR_MASK_ALL \ 21 + | ZXI2C_IRQ_FIFOEND \ 22 + | ZXI2C_IRQ_FIFONACK) 23 + /* Zhaoxin specific registers */ 24 + #define ZXI2C_REG_CLK 0x10 25 + #define ZXI2C_CLK_50M BIT(0) 26 + #define ZXI2C_REG_REV 0x11 27 + #define ZXI2C_REG_HCR 0x12 28 + #define ZXI2C_HCR_RST_FIFO GENMASK(1, 0) 29 + #define ZXI2C_REG_HTDR 0x13 30 + #define ZXI2C_REG_HRDR 0x14 31 + #define ZXI2C_REG_HTLR 0x15 32 + #define ZXI2C_REG_HRLR 0x16 33 + #define ZXI2C_REG_HWCNTR 0x18 34 + #define ZXI2C_REG_HRCNTR 0x19 35 + 36 + /* parameters Constants */ 37 + #define ZXI2C_GOLD_FSTP_100K 0xF3 38 + #define ZXI2C_GOLD_FSTP_400K 0x38 39 + #define ZXI2C_GOLD_FSTP_1M 0x13 40 + #define ZXI2C_GOLD_FSTP_3400K 0x37 41 + #define ZXI2C_HS_MASTER_CODE (0x08 << 8) 42 + 43 + #define ZXI2C_FIFO_SIZE 32 44 + 45 + struct viai2c_zhaoxin { 46 + u8 hrv; 47 + u16 tr; 48 + u16 mcr; 49 + u16 xfer_len; 50 + }; 51 + 52 + /* 'irq == true' means in interrupt context */ 53 + int viai2c_fifo_irq_xfer(struct viai2c *i2c, bool irq) 54 + { 55 + u16 i; 56 + u8 tmp; 57 + struct i2c_msg *msg = i2c->msg; 58 + void __iomem *base = i2c->base; 59 + bool read = !!(msg->flags & I2C_M_RD); 60 + struct viai2c_zhaoxin *priv = i2c->pltfm_priv; 61 + 62 + if (irq) { 63 + /* get the received data */ 64 + if (read) 65 + for (i = 0; i < priv->xfer_len; i++) 66 + msg->buf[i2c->xfered_len + i] = ioread8(base + ZXI2C_REG_HRDR); 67 + 68 + i2c->xfered_len += priv->xfer_len; 69 + if (i2c->xfered_len == msg->len) 70 + return 1; 71 + } 72 + 73 + /* reset fifo buffer */ 74 + tmp = ioread8(base + ZXI2C_REG_HCR); 75 + iowrite8(tmp | ZXI2C_HCR_RST_FIFO, base + ZXI2C_REG_HCR); 76 + 77 + /* set xfer len */ 78 + priv->xfer_len = min_t(u16, msg->len - i2c->xfered_len, ZXI2C_FIFO_SIZE); 79 + if (read) { 80 + iowrite8(priv->xfer_len - 1, base + ZXI2C_REG_HRLR); 81 + } else { 82 + iowrite8(priv->xfer_len - 1, base + ZXI2C_REG_HTLR); 83 + /* set write data */ 84 + for (i = 0; i < priv->xfer_len; i++) 85 + iowrite8(msg->buf[i2c->xfered_len + i], base + ZXI2C_REG_HTDR); 86 + } 87 + 88 + /* prepare to stop transmission */ 89 + if (priv->hrv && msg->len == (i2c->xfered_len + priv->xfer_len)) { 90 + tmp = ioread8(base + VIAI2C_REG_CR); 91 + tmp |= read ? VIAI2C_CR_RX_END : VIAI2C_CR_TX_END; 92 + iowrite8(tmp, base + VIAI2C_REG_CR); 93 + } 94 + 95 + if (irq) { 96 + /* continue transmission */ 97 + tmp = ioread8(base + VIAI2C_REG_CR); 98 + iowrite8(tmp |= VIAI2C_CR_CPU_RDY, base + VIAI2C_REG_CR); 99 + } else { 100 + u16 tcr_val = i2c->tcr; 101 + 102 + /* start transmission */ 103 + tcr_val |= read ? VIAI2C_TCR_READ : 0; 104 + writew(tcr_val | msg->addr, base + VIAI2C_REG_TCR); 105 + } 106 + 107 + return 0; 108 + } 109 + 110 + static int zxi2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) 111 + { 112 + u8 tmp; 113 + int ret; 114 + struct viai2c *i2c = (struct viai2c *)i2c_get_adapdata(adap); 115 + struct viai2c_zhaoxin *priv = i2c->pltfm_priv; 116 + void __iomem *base = i2c->base; 117 + 118 + ret = viai2c_wait_bus_not_busy(i2c); 119 + if (ret) 120 + return ret; 121 + 122 + tmp = ioread8(base + VIAI2C_REG_CR); 123 + tmp &= ~(VIAI2C_CR_RX_END | VIAI2C_CR_TX_END); 124 + 125 + if (num == 1 && msgs->len >= 2 && (priv->hrv || msgs->len <= ZXI2C_FIFO_SIZE)) { 126 + /* enable fifo mode */ 127 + iowrite16(ZXI2C_CR_FIFO_MODE | tmp, base + VIAI2C_REG_CR); 128 + /* clear irq status */ 129 + iowrite8(ZXI2C_IRQ_MASK, base + VIAI2C_REG_ISR); 130 + /* enable fifo irq */ 131 + iowrite8(VIAI2C_ISR_NACK_ADDR | ZXI2C_IRQ_FIFOEND, base + VIAI2C_REG_IMR); 132 + 133 + i2c->msg = msgs; 134 + i2c->mode = VIAI2C_FIFO_MODE; 135 + priv->xfer_len = 0; 136 + i2c->xfered_len = 0; 137 + 138 + viai2c_fifo_irq_xfer(i2c, 0); 139 + 140 + if (!wait_for_completion_timeout(&i2c->complete, VIAI2C_TIMEOUT)) 141 + return -ETIMEDOUT; 142 + 143 + ret = i2c->ret; 144 + } else { 145 + /* enable byte mode */ 146 + iowrite16(tmp, base + VIAI2C_REG_CR); 147 + /* clear irq status */ 148 + iowrite8(ZXI2C_IRQ_MASK, base + VIAI2C_REG_ISR); 149 + /* enable byte irq */ 150 + iowrite8(VIAI2C_ISR_NACK_ADDR | VIAI2C_IMR_BYTE, base + VIAI2C_REG_IMR); 151 + 152 + ret = viai2c_xfer(adap, msgs, num); 153 + if (ret == -ETIMEDOUT) 154 + iowrite16(tmp | VIAI2C_CR_END_MASK, base + VIAI2C_REG_CR); 155 + } 156 + /* dis interrupt */ 157 + iowrite8(0, base + VIAI2C_REG_IMR); 158 + 159 + return ret; 160 + } 161 + 162 + static u32 zxi2c_func(struct i2c_adapter *adap) 163 + { 164 + return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; 165 + } 166 + 167 + static const struct i2c_algorithm zxi2c_algorithm = { 168 + .master_xfer = zxi2c_master_xfer, 169 + .functionality = zxi2c_func, 170 + }; 171 + 172 + static const struct i2c_adapter_quirks zxi2c_quirks = { 173 + .flags = I2C_AQ_NO_ZERO_LEN | I2C_AQ_COMB_WRITE_THEN_READ, 174 + }; 175 + 176 + static const u32 zxi2c_speed_params_table[][3] = { 177 + /* speed, ZXI2C_TCR, ZXI2C_FSTP */ 178 + { I2C_MAX_STANDARD_MODE_FREQ, 0, ZXI2C_GOLD_FSTP_100K }, 179 + { I2C_MAX_FAST_MODE_FREQ, VIAI2C_TCR_FAST, ZXI2C_GOLD_FSTP_400K }, 180 + { I2C_MAX_FAST_MODE_PLUS_FREQ, VIAI2C_TCR_FAST, ZXI2C_GOLD_FSTP_1M }, 181 + { I2C_MAX_HIGH_SPEED_MODE_FREQ, VIAI2C_TCR_HS_MODE | VIAI2C_TCR_FAST, 182 + ZXI2C_GOLD_FSTP_3400K }, 183 + }; 184 + 185 + static void zxi2c_set_bus_speed(struct viai2c *i2c) 186 + { 187 + struct viai2c_zhaoxin *priv = i2c->pltfm_priv; 188 + 189 + iowrite16(priv->tr, i2c->base + VIAI2C_REG_TR); 190 + iowrite8(ZXI2C_CLK_50M, i2c->base + ZXI2C_REG_CLK); 191 + iowrite16(priv->mcr, i2c->base + VIAI2C_REG_MCR); 192 + } 193 + 194 + static void zxi2c_get_bus_speed(struct viai2c *i2c) 195 + { 196 + u8 i, count; 197 + u8 fstp; 198 + const u32 *params; 199 + struct viai2c_zhaoxin *priv = i2c->pltfm_priv; 200 + u32 acpi_speed = i2c_acpi_find_bus_speed(i2c->dev); 201 + 202 + count = ARRAY_SIZE(zxi2c_speed_params_table); 203 + for (i = 0; i < count; i++) 204 + if (acpi_speed == zxi2c_speed_params_table[i][0]) 205 + break; 206 + /* if not found, use 400k as default */ 207 + i = i < count ? i : 1; 208 + 209 + params = zxi2c_speed_params_table[i]; 210 + fstp = ioread8(i2c->base + VIAI2C_REG_TR); 211 + if (abs(fstp - params[2]) > 0x10) { 212 + /* 213 + * if BIOS setting value far from golden value, 214 + * use golden value and warn user 215 + */ 216 + dev_warn(i2c->dev, "FW FSTP[%x] might cause wrong timings, dropped\n", fstp); 217 + priv->tr = params[2] | 0xff00; 218 + } else { 219 + priv->tr = fstp | 0xff00; 220 + } 221 + 222 + i2c->tcr = params[1]; 223 + priv->mcr = ioread16(i2c->base + VIAI2C_REG_MCR); 224 + /* for Hs-mode, use 0x80 as master code */ 225 + if (params[0] == I2C_MAX_HIGH_SPEED_MODE_FREQ) 226 + priv->mcr |= ZXI2C_HS_MASTER_CODE; 227 + 228 + dev_info(i2c->dev, "speed mode is %s\n", i2c_freq_mode_string(params[0])); 229 + } 230 + 231 + static int zxi2c_probe(struct platform_device *pdev) 232 + { 233 + int error; 234 + struct viai2c *i2c; 235 + struct i2c_adapter *adap; 236 + struct viai2c_zhaoxin *priv; 237 + 238 + error = viai2c_init(pdev, &i2c, VIAI2C_PLAT_ZHAOXIN); 239 + if (error) 240 + return error; 241 + 242 + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); 243 + if (!priv) 244 + return -ENOMEM; 245 + i2c->pltfm_priv = priv; 246 + 247 + zxi2c_get_bus_speed(i2c); 248 + zxi2c_set_bus_speed(i2c); 249 + 250 + priv->hrv = ioread8(i2c->base + ZXI2C_REG_REV); 251 + 252 + adap = &i2c->adapter; 253 + adap->owner = THIS_MODULE; 254 + adap->algo = &zxi2c_algorithm; 255 + adap->quirks = &zxi2c_quirks; 256 + adap->dev.parent = &pdev->dev; 257 + ACPI_COMPANION_SET(&adap->dev, ACPI_COMPANION(&pdev->dev)); 258 + snprintf(adap->name, sizeof(adap->name), "zhaoxin-%s-%s", 259 + dev_name(pdev->dev.parent), dev_name(i2c->dev)); 260 + i2c_set_adapdata(adap, i2c); 261 + 262 + return devm_i2c_add_adapter(&pdev->dev, adap); 263 + } 264 + 265 + static int __maybe_unused zxi2c_resume(struct device *dev) 266 + { 267 + struct viai2c *i2c = dev_get_drvdata(dev); 268 + 269 + iowrite8(ZXI2C_CR_MST_RST, i2c->base + VIAI2C_REG_CR); 270 + zxi2c_set_bus_speed(i2c); 271 + 272 + return 0; 273 + } 274 + 275 + static const struct dev_pm_ops zxi2c_pm = { 276 + SET_SYSTEM_SLEEP_PM_OPS(NULL, zxi2c_resume) 277 + }; 278 + 279 + static const struct acpi_device_id zxi2c_acpi_match[] = { 280 + {"IIC1D17", 0 }, 281 + { } 282 + }; 283 + MODULE_DEVICE_TABLE(acpi, zxi2c_acpi_match); 284 + 285 + static struct platform_driver zxi2c_driver = { 286 + .probe = zxi2c_probe, 287 + .driver = { 288 + .name = "i2c_zhaoxin", 289 + .acpi_match_table = zxi2c_acpi_match, 290 + .pm = &zxi2c_pm, 291 + }, 292 + }; 293 + 294 + module_platform_driver(zxi2c_driver); 295 + 296 + MODULE_AUTHOR("HansHu@zhaoxin.com"); 297 + MODULE_DESCRIPTION("Shanghai Zhaoxin IIC driver"); 298 + MODULE_LICENSE("GPL");
-1
drivers/i2c/busses/i2c-viperboard.c
··· 416 416 417 417 static struct platform_driver vprbrd_i2c_driver = { 418 418 .driver.name = "viperboard-i2c", 419 - .driver.owner = THIS_MODULE, 420 419 .probe = vprbrd_i2c_probe, 421 420 .remove_new = vprbrd_i2c_remove, 422 421 };
-421
drivers/i2c/busses/i2c-wmt.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-or-later 2 - /* 3 - * Wondermedia I2C Master Mode Driver 4 - * 5 - * Copyright (C) 2012 Tony Prisk <linux@prisktech.co.nz> 6 - * 7 - * Derived from GPLv2+ licensed source: 8 - * - Copyright (C) 2008 WonderMedia Technologies, Inc. 9 - */ 10 - 11 - #include <linux/clk.h> 12 - #include <linux/delay.h> 13 - #include <linux/err.h> 14 - #include <linux/i2c.h> 15 - #include <linux/interrupt.h> 16 - #include <linux/io.h> 17 - #include <linux/module.h> 18 - #include <linux/of.h> 19 - #include <linux/of_address.h> 20 - #include <linux/of_irq.h> 21 - #include <linux/platform_device.h> 22 - 23 - #define REG_CR 0x00 24 - #define REG_TCR 0x02 25 - #define REG_CSR 0x04 26 - #define REG_ISR 0x06 27 - #define REG_IMR 0x08 28 - #define REG_CDR 0x0A 29 - #define REG_TR 0x0C 30 - #define REG_MCR 0x0E 31 - #define REG_SLAVE_CR 0x10 32 - #define REG_SLAVE_SR 0x12 33 - #define REG_SLAVE_ISR 0x14 34 - #define REG_SLAVE_IMR 0x16 35 - #define REG_SLAVE_DR 0x18 36 - #define REG_SLAVE_TR 0x1A 37 - 38 - /* REG_CR Bit fields */ 39 - #define CR_TX_NEXT_ACK 0x0000 40 - #define CR_ENABLE 0x0001 41 - #define CR_TX_NEXT_NO_ACK 0x0002 42 - #define CR_TX_END 0x0004 43 - #define CR_CPU_RDY 0x0008 44 - #define SLAV_MODE_SEL 0x8000 45 - 46 - /* REG_TCR Bit fields */ 47 - #define TCR_STANDARD_MODE 0x0000 48 - #define TCR_MASTER_WRITE 0x0000 49 - #define TCR_HS_MODE 0x2000 50 - #define TCR_MASTER_READ 0x4000 51 - #define TCR_FAST_MODE 0x8000 52 - #define TCR_SLAVE_ADDR_MASK 0x007F 53 - 54 - /* REG_ISR Bit fields */ 55 - #define ISR_NACK_ADDR 0x0001 56 - #define ISR_BYTE_END 0x0002 57 - #define ISR_SCL_TIMEOUT 0x0004 58 - #define ISR_WRITE_ALL 0x0007 59 - 60 - /* REG_IMR Bit fields */ 61 - #define IMR_ENABLE_ALL 0x0007 62 - 63 - /* REG_CSR Bit fields */ 64 - #define CSR_RCV_NOT_ACK 0x0001 65 - #define CSR_RCV_ACK_MASK 0x0001 66 - #define CSR_READY_MASK 0x0002 67 - 68 - /* REG_TR */ 69 - #define SCL_TIMEOUT(x) (((x) & 0xFF) << 8) 70 - #define TR_STD 0x0064 71 - #define TR_HS 0x0019 72 - 73 - /* REG_MCR */ 74 - #define MCR_APB_96M 7 75 - #define MCR_APB_166M 12 76 - 77 - #define WMT_I2C_TIMEOUT (msecs_to_jiffies(1000)) 78 - 79 - struct wmt_i2c_dev { 80 - struct i2c_adapter adapter; 81 - struct completion complete; 82 - struct device *dev; 83 - void __iomem *base; 84 - struct clk *clk; 85 - u16 tcr; 86 - int irq; 87 - u16 cmd_status; 88 - }; 89 - 90 - static int wmt_i2c_wait_bus_not_busy(struct wmt_i2c_dev *i2c_dev) 91 - { 92 - unsigned long timeout; 93 - 94 - timeout = jiffies + WMT_I2C_TIMEOUT; 95 - while (!(readw(i2c_dev->base + REG_CSR) & CSR_READY_MASK)) { 96 - if (time_after(jiffies, timeout)) { 97 - dev_warn(i2c_dev->dev, "timeout waiting for bus ready\n"); 98 - return -EBUSY; 99 - } 100 - msleep(20); 101 - } 102 - 103 - return 0; 104 - } 105 - 106 - static int wmt_check_status(struct wmt_i2c_dev *i2c_dev) 107 - { 108 - int ret = 0; 109 - unsigned long wait_result; 110 - 111 - wait_result = wait_for_completion_timeout(&i2c_dev->complete, 112 - msecs_to_jiffies(500)); 113 - if (!wait_result) 114 - return -ETIMEDOUT; 115 - 116 - if (i2c_dev->cmd_status & ISR_NACK_ADDR) 117 - ret = -EIO; 118 - 119 - if (i2c_dev->cmd_status & ISR_SCL_TIMEOUT) 120 - ret = -ETIMEDOUT; 121 - 122 - return ret; 123 - } 124 - 125 - static int wmt_i2c_write(struct wmt_i2c_dev *i2c_dev, struct i2c_msg *pmsg, 126 - int last) 127 - { 128 - u16 val, tcr_val = i2c_dev->tcr; 129 - int ret; 130 - int xfer_len = 0; 131 - 132 - if (pmsg->len == 0) { 133 - /* 134 - * We still need to run through the while (..) once, so 135 - * start at -1 and break out early from the loop 136 - */ 137 - xfer_len = -1; 138 - writew(0, i2c_dev->base + REG_CDR); 139 - } else { 140 - writew(pmsg->buf[0] & 0xFF, i2c_dev->base + REG_CDR); 141 - } 142 - 143 - if (!(pmsg->flags & I2C_M_NOSTART)) { 144 - val = readw(i2c_dev->base + REG_CR); 145 - val &= ~CR_TX_END; 146 - val |= CR_CPU_RDY; 147 - writew(val, i2c_dev->base + REG_CR); 148 - } 149 - 150 - reinit_completion(&i2c_dev->complete); 151 - 152 - tcr_val |= (TCR_MASTER_WRITE | (pmsg->addr & TCR_SLAVE_ADDR_MASK)); 153 - 154 - writew(tcr_val, i2c_dev->base + REG_TCR); 155 - 156 - if (pmsg->flags & I2C_M_NOSTART) { 157 - val = readw(i2c_dev->base + REG_CR); 158 - val |= CR_CPU_RDY; 159 - writew(val, i2c_dev->base + REG_CR); 160 - } 161 - 162 - while (xfer_len < pmsg->len) { 163 - ret = wmt_check_status(i2c_dev); 164 - if (ret) 165 - return ret; 166 - 167 - xfer_len++; 168 - 169 - val = readw(i2c_dev->base + REG_CSR); 170 - if ((val & CSR_RCV_ACK_MASK) == CSR_RCV_NOT_ACK) { 171 - dev_dbg(i2c_dev->dev, "write RCV NACK error\n"); 172 - return -EIO; 173 - } 174 - 175 - if (pmsg->len == 0) { 176 - val = CR_TX_END | CR_CPU_RDY | CR_ENABLE; 177 - writew(val, i2c_dev->base + REG_CR); 178 - break; 179 - } 180 - 181 - if (xfer_len == pmsg->len) { 182 - if (last != 1) 183 - writew(CR_ENABLE, i2c_dev->base + REG_CR); 184 - } else { 185 - writew(pmsg->buf[xfer_len] & 0xFF, i2c_dev->base + 186 - REG_CDR); 187 - writew(CR_CPU_RDY | CR_ENABLE, i2c_dev->base + REG_CR); 188 - } 189 - } 190 - 191 - return 0; 192 - } 193 - 194 - static int wmt_i2c_read(struct wmt_i2c_dev *i2c_dev, struct i2c_msg *pmsg) 195 - { 196 - u16 val, tcr_val = i2c_dev->tcr; 197 - int ret; 198 - u32 xfer_len = 0; 199 - 200 - val = readw(i2c_dev->base + REG_CR); 201 - val &= ~(CR_TX_END | CR_TX_NEXT_NO_ACK); 202 - 203 - if (!(pmsg->flags & I2C_M_NOSTART)) 204 - val |= CR_CPU_RDY; 205 - 206 - if (pmsg->len == 1) 207 - val |= CR_TX_NEXT_NO_ACK; 208 - 209 - writew(val, i2c_dev->base + REG_CR); 210 - 211 - reinit_completion(&i2c_dev->complete); 212 - 213 - tcr_val |= TCR_MASTER_READ | (pmsg->addr & TCR_SLAVE_ADDR_MASK); 214 - 215 - writew(tcr_val, i2c_dev->base + REG_TCR); 216 - 217 - if (pmsg->flags & I2C_M_NOSTART) { 218 - val = readw(i2c_dev->base + REG_CR); 219 - val |= CR_CPU_RDY; 220 - writew(val, i2c_dev->base + REG_CR); 221 - } 222 - 223 - while (xfer_len < pmsg->len) { 224 - ret = wmt_check_status(i2c_dev); 225 - if (ret) 226 - return ret; 227 - 228 - pmsg->buf[xfer_len] = readw(i2c_dev->base + REG_CDR) >> 8; 229 - xfer_len++; 230 - 231 - val = readw(i2c_dev->base + REG_CR) | CR_CPU_RDY; 232 - if (xfer_len == pmsg->len - 1) 233 - val |= CR_TX_NEXT_NO_ACK; 234 - writew(val, i2c_dev->base + REG_CR); 235 - } 236 - 237 - return 0; 238 - } 239 - 240 - static int wmt_i2c_xfer(struct i2c_adapter *adap, 241 - struct i2c_msg msgs[], 242 - int num) 243 - { 244 - struct i2c_msg *pmsg; 245 - int i; 246 - int ret = 0; 247 - struct wmt_i2c_dev *i2c_dev = i2c_get_adapdata(adap); 248 - 249 - for (i = 0; ret >= 0 && i < num; i++) { 250 - pmsg = &msgs[i]; 251 - if (!(pmsg->flags & I2C_M_NOSTART)) { 252 - ret = wmt_i2c_wait_bus_not_busy(i2c_dev); 253 - if (ret < 0) 254 - return ret; 255 - } 256 - 257 - if (pmsg->flags & I2C_M_RD) 258 - ret = wmt_i2c_read(i2c_dev, pmsg); 259 - else 260 - ret = wmt_i2c_write(i2c_dev, pmsg, (i + 1) == num); 261 - } 262 - 263 - return (ret < 0) ? ret : i; 264 - } 265 - 266 - static u32 wmt_i2c_func(struct i2c_adapter *adap) 267 - { 268 - return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_NOSTART; 269 - } 270 - 271 - static const struct i2c_algorithm wmt_i2c_algo = { 272 - .master_xfer = wmt_i2c_xfer, 273 - .functionality = wmt_i2c_func, 274 - }; 275 - 276 - static irqreturn_t wmt_i2c_isr(int irq, void *data) 277 - { 278 - struct wmt_i2c_dev *i2c_dev = data; 279 - 280 - /* save the status and write-clear it */ 281 - i2c_dev->cmd_status = readw(i2c_dev->base + REG_ISR); 282 - writew(i2c_dev->cmd_status, i2c_dev->base + REG_ISR); 283 - 284 - complete(&i2c_dev->complete); 285 - 286 - return IRQ_HANDLED; 287 - } 288 - 289 - static int wmt_i2c_reset_hardware(struct wmt_i2c_dev *i2c_dev) 290 - { 291 - int err; 292 - 293 - err = clk_prepare_enable(i2c_dev->clk); 294 - if (err) { 295 - dev_err(i2c_dev->dev, "failed to enable clock\n"); 296 - return err; 297 - } 298 - 299 - err = clk_set_rate(i2c_dev->clk, 20000000); 300 - if (err) { 301 - dev_err(i2c_dev->dev, "failed to set clock = 20Mhz\n"); 302 - clk_disable_unprepare(i2c_dev->clk); 303 - return err; 304 - } 305 - 306 - writew(0, i2c_dev->base + REG_CR); 307 - writew(MCR_APB_166M, i2c_dev->base + REG_MCR); 308 - writew(ISR_WRITE_ALL, i2c_dev->base + REG_ISR); 309 - writew(IMR_ENABLE_ALL, i2c_dev->base + REG_IMR); 310 - writew(CR_ENABLE, i2c_dev->base + REG_CR); 311 - readw(i2c_dev->base + REG_CSR); /* read clear */ 312 - writew(ISR_WRITE_ALL, i2c_dev->base + REG_ISR); 313 - 314 - if (i2c_dev->tcr == TCR_FAST_MODE) 315 - writew(SCL_TIMEOUT(128) | TR_HS, i2c_dev->base + REG_TR); 316 - else 317 - writew(SCL_TIMEOUT(128) | TR_STD, i2c_dev->base + REG_TR); 318 - 319 - return 0; 320 - } 321 - 322 - static int wmt_i2c_probe(struct platform_device *pdev) 323 - { 324 - struct device_node *np = pdev->dev.of_node; 325 - struct wmt_i2c_dev *i2c_dev; 326 - struct i2c_adapter *adap; 327 - int err; 328 - u32 clk_rate; 329 - 330 - i2c_dev = devm_kzalloc(&pdev->dev, sizeof(*i2c_dev), GFP_KERNEL); 331 - if (!i2c_dev) 332 - return -ENOMEM; 333 - 334 - i2c_dev->base = devm_platform_get_and_ioremap_resource(pdev, 0, NULL); 335 - if (IS_ERR(i2c_dev->base)) 336 - return PTR_ERR(i2c_dev->base); 337 - 338 - i2c_dev->irq = irq_of_parse_and_map(np, 0); 339 - if (!i2c_dev->irq) { 340 - dev_err(&pdev->dev, "irq missing or invalid\n"); 341 - return -EINVAL; 342 - } 343 - 344 - i2c_dev->clk = of_clk_get(np, 0); 345 - if (IS_ERR(i2c_dev->clk)) { 346 - dev_err(&pdev->dev, "unable to request clock\n"); 347 - return PTR_ERR(i2c_dev->clk); 348 - } 349 - 350 - err = of_property_read_u32(np, "clock-frequency", &clk_rate); 351 - if (!err && (clk_rate == I2C_MAX_FAST_MODE_FREQ)) 352 - i2c_dev->tcr = TCR_FAST_MODE; 353 - 354 - i2c_dev->dev = &pdev->dev; 355 - 356 - err = devm_request_irq(&pdev->dev, i2c_dev->irq, wmt_i2c_isr, 0, 357 - "i2c", i2c_dev); 358 - if (err) { 359 - dev_err(&pdev->dev, "failed to request irq %i\n", i2c_dev->irq); 360 - return err; 361 - } 362 - 363 - adap = &i2c_dev->adapter; 364 - i2c_set_adapdata(adap, i2c_dev); 365 - strscpy(adap->name, "WMT I2C adapter", sizeof(adap->name)); 366 - adap->owner = THIS_MODULE; 367 - adap->algo = &wmt_i2c_algo; 368 - adap->dev.parent = &pdev->dev; 369 - adap->dev.of_node = pdev->dev.of_node; 370 - 371 - init_completion(&i2c_dev->complete); 372 - 373 - err = wmt_i2c_reset_hardware(i2c_dev); 374 - if (err) { 375 - dev_err(&pdev->dev, "error initializing hardware\n"); 376 - return err; 377 - } 378 - 379 - err = i2c_add_adapter(adap); 380 - if (err) 381 - goto err_disable_clk; 382 - 383 - platform_set_drvdata(pdev, i2c_dev); 384 - 385 - return 0; 386 - 387 - err_disable_clk: 388 - clk_disable_unprepare(i2c_dev->clk); 389 - return err; 390 - } 391 - 392 - static void wmt_i2c_remove(struct platform_device *pdev) 393 - { 394 - struct wmt_i2c_dev *i2c_dev = platform_get_drvdata(pdev); 395 - 396 - /* Disable interrupts, clock and delete adapter */ 397 - writew(0, i2c_dev->base + REG_IMR); 398 - clk_disable_unprepare(i2c_dev->clk); 399 - i2c_del_adapter(&i2c_dev->adapter); 400 - } 401 - 402 - static const struct of_device_id wmt_i2c_dt_ids[] = { 403 - { .compatible = "wm,wm8505-i2c" }, 404 - { /* Sentinel */ }, 405 - }; 406 - 407 - static struct platform_driver wmt_i2c_driver = { 408 - .probe = wmt_i2c_probe, 409 - .remove_new = wmt_i2c_remove, 410 - .driver = { 411 - .name = "wmt-i2c", 412 - .of_match_table = wmt_i2c_dt_ids, 413 - }, 414 - }; 415 - 416 - module_platform_driver(wmt_i2c_driver); 417 - 418 - MODULE_DESCRIPTION("Wondermedia I2C master-mode bus adapter"); 419 - MODULE_AUTHOR("Tony Prisk <linux@prisktech.co.nz>"); 420 - MODULE_LICENSE("GPL"); 421 - MODULE_DEVICE_TABLE(of, wmt_i2c_dt_ids);
+15 -4
drivers/i2c/i2c-core-acpi.c
··· 445 445 return i2c_find_device_by_fwnode(acpi_fwnode_handle(adev)); 446 446 } 447 447 448 + static struct i2c_adapter *i2c_acpi_find_adapter_by_adev(struct acpi_device *adev) 449 + { 450 + return i2c_find_adapter_by_fwnode(acpi_fwnode_handle(adev)); 451 + } 452 + 448 453 static int i2c_acpi_notify(struct notifier_block *nb, unsigned long value, 449 454 void *arg) 450 455 { ··· 476 471 break; 477 472 478 473 client = i2c_acpi_find_client_by_adev(adev); 479 - if (!client) 480 - break; 474 + if (client) { 475 + i2c_unregister_device(client); 476 + put_device(&client->dev); 477 + } 481 478 482 - i2c_unregister_device(client); 483 - put_device(&client->dev); 479 + adapter = i2c_acpi_find_adapter_by_adev(adev); 480 + if (adapter) { 481 + acpi_unbind_one(&adapter->dev); 482 + put_device(&adapter->dev); 483 + } 484 + 484 485 break; 485 486 } 486 487
+1 -23
drivers/i2c/i2c-mux.c
··· 127 127 return parent->algo->functionality(parent); 128 128 } 129 129 130 - /* Return all parent classes, merged */ 131 - static unsigned int i2c_mux_parent_classes(struct i2c_adapter *parent) 132 - { 133 - unsigned int class = 0; 134 - 135 - do { 136 - class |= parent->class; 137 - parent = i2c_parent_is_i2c_adapter(parent); 138 - } while (parent); 139 - 140 - return class; 141 - } 142 - 143 130 static void i2c_mux_lock_bus(struct i2c_adapter *adapter, unsigned int flags) 144 131 { 145 132 struct i2c_mux_priv *priv = adapter->algo_data; ··· 268 281 }; 269 282 270 283 int i2c_mux_add_adapter(struct i2c_mux_core *muxc, 271 - u32 force_nr, u32 chan_id, 272 - unsigned int class) 284 + u32 force_nr, u32 chan_id) 273 285 { 274 286 struct i2c_adapter *parent = muxc->parent; 275 287 struct i2c_mux_priv *priv; ··· 325 339 priv->adap.lock_ops = &i2c_mux_lock_ops; 326 340 else 327 341 priv->adap.lock_ops = &i2c_parent_lock_ops; 328 - 329 - /* Sanity check on class */ 330 - if (i2c_mux_parent_classes(parent) & class & ~I2C_CLASS_DEPRECATED) 331 - dev_err(&parent->dev, 332 - "Segment %d behind mux can't share classes with ancestors\n", 333 - chan_id); 334 - else 335 - priv->adap.class = class; 336 342 337 343 /* 338 344 * Try to populate the mux adapter's of_node, expands to
+1 -1
drivers/i2c/muxes/i2c-arb-gpio-challenge.c
··· 167 167 } 168 168 169 169 /* Actually add the mux adapter */ 170 - ret = i2c_mux_add_adapter(muxc, 0, 0, 0); 170 + ret = i2c_mux_add_adapter(muxc, 0, 0); 171 171 if (ret) 172 172 i2c_put_adapter(muxc->parent); 173 173
+1 -2
drivers/i2c/muxes/i2c-mux-gpio.c
··· 206 206 207 207 for (i = 0; i < mux->data.n_values; i++) { 208 208 u32 nr = mux->data.base_nr ? (mux->data.base_nr + i) : 0; 209 - unsigned int class = mux->data.classes ? mux->data.classes[i] : 0; 210 209 211 - ret = i2c_mux_add_adapter(muxc, nr, mux->data.values[i], class); 210 + ret = i2c_mux_add_adapter(muxc, nr, mux->data.values[i]); 212 211 if (ret) 213 212 goto add_adapter_failed; 214 213 }
+1 -1
drivers/i2c/muxes/i2c-mux-gpmux.c
··· 124 124 goto err_children; 125 125 } 126 126 127 - ret = i2c_mux_add_adapter(muxc, 0, chan, 0); 127 + ret = i2c_mux_add_adapter(muxc, 0, chan); 128 128 if (ret) 129 129 goto err_children; 130 130 }
+1 -1
drivers/i2c/muxes/i2c-mux-ltc4306.c
··· 279 279 280 280 /* Now create an adapter for each channel */ 281 281 for (num = 0; num < chip->nchans; num++) { 282 - ret = i2c_mux_add_adapter(muxc, 0, num, 0); 282 + ret = i2c_mux_add_adapter(muxc, 0, num); 283 283 if (ret) { 284 284 i2c_mux_del_adapters(muxc); 285 285 return ret;
+1 -1
drivers/i2c/muxes/i2c-mux-mlxcpld.c
··· 154 154 155 155 /* Create an adapter for each channel. */ 156 156 for (num = 0; num < pdata->num_adaps; num++) { 157 - err = i2c_mux_add_adapter(muxc, 0, pdata->chan_ids[num], 0); 157 + err = i2c_mux_add_adapter(muxc, 0, pdata->chan_ids[num]); 158 158 if (err) 159 159 goto virt_reg_failed; 160 160 }
+1 -1
drivers/i2c/muxes/i2c-mux-pca9541.c
··· 314 314 315 315 i2c_set_clientdata(client, muxc); 316 316 317 - ret = i2c_mux_add_adapter(muxc, 0, 0, 0); 317 + ret = i2c_mux_add_adapter(muxc, 0, 0); 318 318 if (ret) 319 319 return ret; 320 320
+1 -1
drivers/i2c/muxes/i2c-mux-pca954x.c
··· 644 644 645 645 /* Now create an adapter for each channel */ 646 646 for (num = 0; num < data->chip->nchans; num++) { 647 - ret = i2c_mux_add_adapter(muxc, 0, num, 0); 647 + ret = i2c_mux_add_adapter(muxc, 0, num); 648 648 if (ret) 649 649 goto fail_cleanup; 650 650 }
+1 -1
drivers/i2c/muxes/i2c-mux-pinctrl.c
··· 151 151 152 152 /* Do not add any adapter for the idle state (if it's there at all). */ 153 153 for (i = 0; i < num_names - !!muxc->deselect; i++) { 154 - ret = i2c_mux_add_adapter(muxc, 0, i, 0); 154 + ret = i2c_mux_add_adapter(muxc, 0, i); 155 155 if (ret) 156 156 goto err_del_adapter; 157 157 }
+1 -1
drivers/i2c/muxes/i2c-mux-reg.c
··· 213 213 for (i = 0; i < mux->data.n_values; i++) { 214 214 nr = mux->data.base_nr ? (mux->data.base_nr + i) : 0; 215 215 216 - ret = i2c_mux_add_adapter(muxc, nr, mux->data.values[i], 0); 216 + ret = i2c_mux_add_adapter(muxc, nr, mux->data.values[i]); 217 217 if (ret) 218 218 goto err_del_mux_adapters; 219 219 }
+1 -1
drivers/iio/gyro/mpu3050-i2c.c
··· 72 72 else { 73 73 mpu3050->i2cmux->priv = mpu3050; 74 74 /* Ignore failure, not critical */ 75 - i2c_mux_add_adapter(mpu3050->i2cmux, 0, 0, 0); 75 + i2c_mux_add_adapter(mpu3050->i2cmux, 0, 0); 76 76 } 77 77 78 78 return 0;
+1 -1
drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
··· 142 142 if (!st->muxc) 143 143 return -ENOMEM; 144 144 st->muxc->priv = dev_get_drvdata(&client->dev); 145 - result = i2c_mux_add_adapter(st->muxc, 0, 0, 0); 145 + result = i2c_mux_add_adapter(st->muxc, 0, 0); 146 146 if (result) 147 147 return result; 148 148 result = inv_mpu_acpi_create_mux_client(client);
+1 -1
drivers/media/dvb-frontends/af9013.c
··· 1480 1480 goto err_regmap_exit; 1481 1481 } 1482 1482 state->muxc->priv = state; 1483 - ret = i2c_mux_add_adapter(state->muxc, 0, 0, 0); 1483 + ret = i2c_mux_add_adapter(state->muxc, 0, 0); 1484 1484 if (ret) 1485 1485 goto err_regmap_exit; 1486 1486
+1 -1
drivers/media/dvb-frontends/lgdt3306a.c
··· 2208 2208 goto err_kfree; 2209 2209 } 2210 2210 state->muxc->priv = client; 2211 - ret = i2c_mux_add_adapter(state->muxc, 0, 0, 0); 2211 + ret = i2c_mux_add_adapter(state->muxc, 0, 0); 2212 2212 if (ret) 2213 2213 goto err_kfree; 2214 2214
+1 -1
drivers/media/dvb-frontends/m88ds3103.c
··· 1873 1873 goto err_kfree; 1874 1874 } 1875 1875 dev->muxc->priv = dev; 1876 - ret = i2c_mux_add_adapter(dev->muxc, 0, 0, 0); 1876 + ret = i2c_mux_add_adapter(dev->muxc, 0, 0); 1877 1877 if (ret) 1878 1878 goto err_kfree; 1879 1879
+1 -1
drivers/media/dvb-frontends/rtl2830.c
··· 838 838 goto err_regmap_exit; 839 839 } 840 840 dev->muxc->priv = client; 841 - ret = i2c_mux_add_adapter(dev->muxc, 0, 0, 0); 841 + ret = i2c_mux_add_adapter(dev->muxc, 0, 0); 842 842 if (ret) 843 843 goto err_regmap_exit; 844 844
+1 -1
drivers/media/dvb-frontends/rtl2832.c
··· 1082 1082 goto err_regmap_exit; 1083 1083 } 1084 1084 dev->muxc->priv = dev; 1085 - ret = i2c_mux_add_adapter(dev->muxc, 0, 0, 0); 1085 + ret = i2c_mux_add_adapter(dev->muxc, 0, 0); 1086 1086 if (ret) 1087 1087 goto err_regmap_exit; 1088 1088
+1 -1
drivers/media/dvb-frontends/si2168.c
··· 744 744 goto err_kfree; 745 745 } 746 746 dev->muxc->priv = client; 747 - ret = i2c_mux_add_adapter(dev->muxc, 0, 0, 0); 747 + ret = i2c_mux_add_adapter(dev->muxc, 0, 0); 748 748 if (ret) 749 749 goto err_kfree; 750 750
+1 -1
drivers/media/i2c/max9286.c
··· 383 383 for_each_source(priv, source) { 384 384 unsigned int index = to_index(priv, source); 385 385 386 - ret = i2c_mux_add_adapter(priv->mux, 0, index, 0); 386 + ret = i2c_mux_add_adapter(priv->mux, 0, index); 387 387 if (ret < 0) 388 388 goto error; 389 389 }
+1 -4
drivers/media/usb/cx231xx/cx231xx-i2c.c
··· 567 567 568 568 int cx231xx_i2c_mux_register(struct cx231xx *dev, int mux_no) 569 569 { 570 - return i2c_mux_add_adapter(dev->muxc, 571 - 0, 572 - mux_no /* chan_id */, 573 - 0 /* class */); 570 + return i2c_mux_add_adapter(dev->muxc, 0, mux_no); 574 571 } 575 572 576 573 void cx231xx_i2c_mux_unregister(struct cx231xx *dev)
+1 -1
drivers/of/unittest.c
··· 2811 2811 if (!muxc) 2812 2812 return -ENOMEM; 2813 2813 for (i = 0; i < nchans; i++) { 2814 - if (i2c_mux_add_adapter(muxc, 0, i, 0)) { 2814 + if (i2c_mux_add_adapter(muxc, 0, i)) { 2815 2815 dev_err(dev, "Failed to register mux #%d\n", i); 2816 2816 i2c_mux_del_adapters(muxc); 2817 2817 return -ENODEV;
+1 -1
drivers/power/supply/sbs-manager.c
··· 358 358 /* register muxed i2c channels. One for each supported battery */ 359 359 for (i = 0; i < SBSM_MAX_BATS; ++i) { 360 360 if (data->supported_bats & BIT(i)) { 361 - ret = i2c_mux_add_adapter(data->muxc, 0, i + 1, 0); 361 + ret = i2c_mux_add_adapter(data->muxc, 0, i + 1); 362 362 if (ret) 363 363 break; 364 364 }
+1 -2
include/linux/i2c-mux.h
··· 56 56 * callback functions to perform hardware-specific mux control. 57 57 */ 58 58 int i2c_mux_add_adapter(struct i2c_mux_core *muxc, 59 - u32 force_nr, u32 chan_id, 60 - unsigned int class); 59 + u32 force_nr, u32 chan_id); 61 60 62 61 void i2c_mux_del_adapters(struct i2c_mux_core *muxc); 63 62
-2
include/linux/platform_data/i2c-mux-gpio.h
··· 18 18 * @values: Array of bitmasks of GPIO settings (low/high) for each 19 19 * position 20 20 * @n_values: Number of multiplexer positions (busses to instantiate) 21 - * @classes: Optional I2C auto-detection classes 22 21 * @idle: Bitmask to write to MUX when idle or GPIO_I2CMUX_NO_IDLE if not used 23 22 */ 24 23 struct i2c_mux_gpio_platform_data { ··· 25 26 int base_nr; 26 27 const unsigned *values; 27 28 int n_values; 28 - const unsigned *classes; 29 29 unsigned idle; 30 30 }; 31 31