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

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

Pull i2c updates from Wolfram Sang:
"Core updates:
- move towards using the 'fwnode' handle instead of 'of_node'
(meaning 'of_node' even gets removed from i2c_board_info)
- add support for Write Disable-aware SPD eeproms
- minor stuff (use new helpers, typo fixes)

i2c-atr (address translator) updates:
- support per-channel alias pools
- added support for dynamic address translation (also adds FPC202
driver as its user)
- add 'static' and 'passthrough' flags

Cleanups and refactorings
- Many drivers switched to dev_err_probe()
- Generic cleanups applied to designware, iproc, ismt, mlxbf,
npcm7xx, qcom-geni, pasemi, and thunderx
- davinci: declare I2C mangling support among I2C features
- designware: clean up DTS handling
- designware: fix PM runtime on driver unregister
- imx: improve error logging during probe
- lpc2k: improve checks in probe error path
- xgene-slimpro: improve PCC shared memory handling
- pasemi: improve error handling in reset, smbus clear, timeouts
- tegra: validate buffer length during transfers
- wmt: convert binding to YAML format

Improvements and extended support:
- microchip-core: add SMBus support
- mlxbf: add support for repeated start in block transfers
- mlxbf: improve timer configuration
- npcm: attempt clock toggle recovery before failing init
- octeon: add support for block mode operations
- pasemi: add support for unjam device feature
- riic: add support for bus recovery

New device support:
- MediaTek Dimensity 1200 (MT6893)
- Sophgo SG2044
- Renesas RZ/V2N (R9A09G056)
- Rockchip RK3528
- AMD ISP (new driver)"

* tag 'i2c-for-6.16-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux: (89 commits)
i2c: Use str_read_write() helper
i2c: mlxbf: avoid 64-bit division
i2c: viai2c-wmt: Replace dev_err() with dev_err_probe() in probe function
i2c: designware: Don't warn about missing get_clk_rate_khz
i2c: designware: Invoke runtime suspend on quick slave re-registration
i2c-mlxbf: Improve I2C bus timing configuration
i2c-mlxbf: Add repeated start condition support
i2c: xgene-slimpro: Replace dev_err() with dev_err_probe() in probe function
dt-bindings: i2c: i2c-wmt: Convert to YAML
i2c: microchip-corei2c: add smbus support
i2c: mlxbf: Allow build with COMPILE_TEST
i2c: I2C_DESIGNWARE_AMDISP should depend on DRM_AMD_ISP
i2c: atr: add passthrough flag
i2c: atr: add static flag
i2c: atr: allow replacing mappings in attach_addr()
i2c: atr: deduplicate logic in attach_addr()
i2c: atr: do not create mapping in detach_addr()
i2c: atr: split up i2c_atr_get_mapping_by_addr()
i2c: atr: find_mapping() -> get_mapping()
i2c: atr: Fix lockdep for nested ATRs
...

+2126 -664
+1
Documentation/devicetree/bindings/i2c/i2c-mt65xx.yaml
··· 52 52 - const: mediatek,mt8173-i2c 53 53 - items: 54 54 - enum: 55 + - mediatek,mt6893-i2c 55 56 - mediatek,mt8195-i2c 56 57 - const: mediatek,mt8192-i2c 57 58
+1
Documentation/devicetree/bindings/i2c/i2c-rk3x.yaml
··· 37 37 - rockchip,px30-i2c 38 38 - rockchip,rk3308-i2c 39 39 - rockchip,rk3328-i2c 40 + - rockchip,rk3528-i2c 40 41 - rockchip,rk3562-i2c 41 42 - rockchip,rk3568-i2c 42 43 - rockchip,rk3576-i2c
-24
Documentation/devicetree/bindings/i2c/i2c-wmt.txt
··· 1 - * Wondermedia I2C Controller 2 - 3 - Required properties : 4 - 5 - - compatible : should be "wm,wm8505-i2c" 6 - - reg : Offset and length of the register set for the device 7 - - interrupts : <IRQ> where IRQ is the interrupt number 8 - - clocks : phandle to the I2C clock source 9 - 10 - Optional properties : 11 - 12 - - clock-frequency : desired I2C bus clock frequency in Hz. 13 - Valid values are 100000 and 400000. 14 - Default to 100000 if not specified, or invalid value. 15 - 16 - Example : 17 - 18 - i2c_0: i2c@d8280000 { 19 - compatible = "wm,wm8505-i2c"; 20 - reg = <0xd8280000 0x1000>; 21 - interrupts = <19>; 22 - clocks = <&clki2c0>; 23 - clock-frequency = <400000>; 24 - };
+1
Documentation/devicetree/bindings/i2c/renesas,riic.yaml
··· 29 29 - enum: 30 30 - renesas,riic-r9a08g045 # RZ/G3S 31 31 - renesas,riic-r9a09g047 # RZ/G3E 32 + - renesas,riic-r9a09g056 # RZ/V2N 32 33 - const: renesas,riic-r9a09g057 # RZ/V2H(P) 33 34 34 35 - const: renesas,riic-r9a09g057 # RZ/V2H(P)
+5 -7
Documentation/devicetree/bindings/i2c/snps,designware-i2c.yaml
··· 32 32 - const: renesas,r9a06g032-i2c # RZ/N1D 33 33 - const: renesas,rzn1-i2c # RZ/N1 34 34 - const: snps,designware-i2c 35 - - description: Microsemi Ocelot SoCs I2C controller 36 - items: 37 - - const: mscc,ocelot-i2c 38 - - const: snps,designware-i2c 39 35 - description: Baikal-T1 SoC System I2C controller 40 36 const: baikal,bt1-sys-i2c 41 - - description: T-HEAD TH1520 SoCs I2C controller 42 - items: 43 - - const: thead,th1520-i2c 37 + - items: 38 + - enum: 39 + - mscc,ocelot-i2c 40 + - sophgo,sg2044-i2c 41 + - thead,th1520-i2c 44 42 - const: snps,designware-i2c 45 43 46 44 reg:
+47
Documentation/devicetree/bindings/i2c/wm,wm8505-i2c.yaml
··· 1 + # SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/i2c/wm,wm8505-i2c.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: I2C Controller on WonderMedia WM8505 and related SoCs 8 + 9 + maintainers: 10 + - Alexey Charkov <alchark@gmail.com> 11 + 12 + allOf: 13 + - $ref: /schemas/i2c/i2c-controller.yaml# 14 + 15 + properties: 16 + compatible: 17 + const: wm,wm8505-i2c 18 + 19 + reg: 20 + maxItems: 1 21 + 22 + interrupts: 23 + maxItems: 1 24 + 25 + clocks: 26 + maxItems: 1 27 + 28 + clock-frequency: 29 + enum: [100000, 400000] 30 + 31 + required: 32 + - compatible 33 + - reg 34 + - interrupts 35 + - clocks 36 + 37 + unevaluatedProperties: false 38 + 39 + examples: 40 + - | 41 + i2c_0: i2c@d8280000 { 42 + compatible = "wm,wm8505-i2c"; 43 + reg = <0xd8280000 0x1000>; 44 + interrupts = <19>; 45 + clocks = <&clki2c0>; 46 + clock-frequency = <400000>; 47 + };
+94
Documentation/devicetree/bindings/misc/ti,fpc202.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/misc/ti,fpc202.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: TI FPC202 dual port controller with expanded IOs 8 + 9 + maintainers: 10 + - Romain Gantois <romain.gantois@bootlin.com> 11 + 12 + allOf: 13 + - $ref: /schemas/i2c/i2c-atr.yaml# 14 + 15 + properties: 16 + compatible: 17 + const: ti,fpc202 18 + 19 + reg: 20 + maxItems: 1 21 + 22 + gpio-controller: true 23 + 24 + "#gpio-cells": 25 + const: 2 26 + 27 + enable-gpios: 28 + description: 29 + Specifier for the GPIO connected to the EN pin. 30 + maxItems: 1 31 + 32 + '#address-cells': 33 + const: 1 34 + 35 + '#size-cells': 36 + const: 0 37 + 38 + patternProperties: 39 + "^i2c@[0-1]$": 40 + $ref: /schemas/i2c/i2c-controller.yaml# 41 + description: Downstream device ports 0 and 1 42 + 43 + properties: 44 + reg: 45 + maxItems: 1 46 + description: 47 + Downstream port ID 48 + 49 + required: 50 + - "#address-cells" 51 + - "#size-cells" 52 + - reg 53 + 54 + unevaluatedProperties: false 55 + 56 + required: 57 + - compatible 58 + - reg 59 + - gpio-controller 60 + - "#gpio-cells" 61 + - "#address-cells" 62 + - "#size-cells" 63 + 64 + unevaluatedProperties: false 65 + 66 + examples: 67 + - | 68 + i2c { 69 + #address-cells = <1>; 70 + #size-cells = <0>; 71 + 72 + i2c-atr@f { 73 + compatible = "ti,fpc202"; 74 + reg = <0xf>; 75 + #address-cells = <1>; 76 + #size-cells = <0>; 77 + 78 + gpio-controller; 79 + #gpio-cells = <2>; 80 + 81 + i2c@0 { 82 + #address-cells = <1>; 83 + #size-cells = <0>; 84 + reg = <0>; 85 + }; 86 + 87 + i2c@1 { 88 + #address-cells = <1>; 89 + #size-cells = <0>; 90 + reg = <1>; 91 + }; 92 + }; 93 + }; 94 + ...
+1 -1
Documentation/i2c/busses/i2c-parport.rst
··· 84 84 \| 85 85 86 86 must be 74HC05, they must be open collector output. 87 - - All resitors are 10k. 87 + - All resistors are 10k. 88 88 - Pins 18-25 of the parallel port connected to GND. 89 89 - Pins 4-9 (D2-D7) could be used as VDD is the driver drives them high. 90 90 The ADM1032 evaluation board uses D4-D7. Beware that the amount of
+15 -1
MAINTAINERS
··· 3480 3480 M: Krzysztof Kozlowski <krzk@kernel.org> 3481 3481 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 3482 3482 S: Odd Fixes 3483 - F: Documentation/devicetree/bindings/i2c/i2c-wmt.txt 3483 + F: Documentation/devicetree/bindings/i2c/wm,wm8505-i2c.yaml 3484 3484 F: Documentation/devicetree/bindings/interrupt-controller/via,vt8500-intc.yaml 3485 3485 F: Documentation/devicetree/bindings/pwm/via,vt8500-pwm.yaml 3486 3486 F: arch/arm/boot/dts/vt8500/ ··· 23872 23872 S: Supported 23873 23873 F: drivers/i2c/busses/i2c-designware-* 23874 23874 23875 + SYNOPSYS DESIGNWARE I2C DRIVER - AMDISP 23876 + M: Nirujogi Pratap <pratap.nirujogi@amd.com> 23877 + M: Bin Du <bin.du@amd.com> 23878 + L: linux-i2c@vger.kernel.org 23879 + S: Maintained 23880 + F: drivers/i2c/busses/i2c-designware-amdisp.c 23881 + 23875 23882 SYNOPSYS DESIGNWARE MMC/SD/SDIO DRIVER 23876 23883 M: Jaehoon Chung <jh80.chung@samsung.com> 23877 23884 L: linux-mmc@vger.kernel.org ··· 24630 24623 F: drivers/misc/tifm* 24631 24624 F: drivers/mmc/host/tifm_sd.c 24632 24625 F: include/linux/tifm.h 24626 + 24627 + TI FPC202 DUAL PORT CONTROLLER 24628 + M: Romain Gantois <romain.gantois@bootlin.com> 24629 + L: linux-kernel@vger.kernel.org 24630 + S: Maintained 24631 + F: Documentation/devicetree/bindings/misc/ti,fpc202.yaml 24632 + F: drivers/misc/ti_fpc202.c 24633 24633 24634 24634 TI FPD-LINK DRIVERS 24635 24635 M: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
+2 -1
drivers/i2c/algos/i2c-algo-pcf.c
··· 19 19 #include <linux/errno.h> 20 20 #include <linux/i2c.h> 21 21 #include <linux/i2c-algo-pcf.h> 22 + #include <linux/string_choices.h> 22 23 #include "i2c-algo-pcf.h" 23 24 24 25 ··· 317 316 pmsg = &msgs[i]; 318 317 319 318 DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: Doing %s %d bytes to 0x%02x - %d of %d messages\n", 320 - pmsg->flags & I2C_M_RD ? "read" : "write", 319 + str_read_write(pmsg->flags & I2C_M_RD), 321 320 pmsg->len, pmsg->addr, i + 1, num);) 322 321 323 322 ret = pcf_doAddress(adap, pmsg);
+12 -1
drivers/i2c/busses/Kconfig
··· 592 592 This driver can also be built as a module. If so, the module 593 593 will be called i2c-designware-platform. 594 594 595 + config I2C_DESIGNWARE_AMDISP 596 + tristate "Synopsys DesignWare Platform for AMDISP" 597 + depends on DRM_AMD_ISP || COMPILE_TEST 598 + depends on I2C_DESIGNWARE_CORE 599 + help 600 + If you say yes to this option, support will be included for the 601 + AMDISP Synopsys DesignWare I2C adapter. 602 + 603 + This driver can also be built as a module. If so, the module 604 + will be called amd_isp_i2c_designware. 605 + 595 606 config I2C_DESIGNWARE_AMDPSP 596 607 bool "AMD PSP I2C semaphore support" 597 608 depends on ACPI ··· 856 845 857 846 config I2C_MLXBF 858 847 tristate "Mellanox BlueField I2C controller" 859 - depends on MELLANOX_PLATFORM && ARM64 848 + depends on (MELLANOX_PLATFORM && ARM64) || COMPILE_TEST 860 849 depends on ACPI 861 850 select I2C_SLAVE 862 851 help
+1
drivers/i2c/busses/Makefile
··· 58 58 i2c-designware-platform-y := i2c-designware-platdrv.o 59 59 i2c-designware-platform-$(CONFIG_I2C_DESIGNWARE_AMDPSP) += i2c-designware-amdpsp.o 60 60 i2c-designware-platform-$(CONFIG_I2C_DESIGNWARE_BAYTRAIL) += i2c-designware-baytrail.o 61 + obj-$(CONFIG_I2C_DESIGNWARE_AMDISP) += i2c-designware-amdisp.o 61 62 obj-$(CONFIG_I2C_DESIGNWARE_PCI) += i2c-designware-pci.o 62 63 i2c-designware-pci-y := i2c-designware-pcidrv.o 63 64 obj-$(CONFIG_I2C_DIGICOLOR) += i2c-digicolor.o
+2 -1
drivers/i2c/busses/i2c-at91-master.c
··· 26 26 #include <linux/pinctrl/consumer.h> 27 27 #include <linux/platform_device.h> 28 28 #include <linux/pm_runtime.h> 29 + #include <linux/string_choices.h> 29 30 30 31 #include "i2c-at91.h" 31 32 ··· 524 523 */ 525 524 526 525 dev_dbg(dev->dev, "transfer: %s %zu bytes.\n", 527 - (dev->msg->flags & I2C_M_RD) ? "read" : "write", dev->buf_len); 526 + str_read_write(dev->msg->flags & I2C_M_RD), dev->buf_len); 528 527 529 528 reinit_completion(&dev->cmd_complete); 530 529 dev->transfer_status = 0;
+105 -118
drivers/i2c/busses/i2c-bcm-iproc.c
··· 224 224 | BIT(IS_S_TX_UNDERRUN_SHIFT) | BIT(IS_S_RX_FIFO_FULL_SHIFT)\ 225 225 | BIT(IS_S_RX_THLD_SHIFT)) 226 226 227 - static int bcm_iproc_i2c_reg_slave(struct i2c_client *slave); 228 - static int bcm_iproc_i2c_unreg_slave(struct i2c_client *slave); 229 - static void bcm_iproc_i2c_enable_disable(struct bcm_iproc_i2c_dev *iproc_i2c, 230 - bool enable); 231 - 232 227 static inline u32 iproc_i2c_rd_reg(struct bcm_iproc_i2c_dev *iproc_i2c, 233 228 u32 offset) 234 229 { ··· 259 264 } 260 265 } 261 266 262 - static void bcm_iproc_i2c_slave_init( 263 - struct bcm_iproc_i2c_dev *iproc_i2c, bool need_reset) 267 + static void bcm_iproc_i2c_slave_init(struct bcm_iproc_i2c_dev *iproc_i2c, 268 + bool need_reset) 264 269 { 265 270 u32 val; 266 271 ··· 271 276 val |= BIT(CFG_RESET_SHIFT); 272 277 iproc_i2c_wr_reg(iproc_i2c, CFG_OFFSET, val); 273 278 274 - /* wait 100 usec per spec */ 275 - udelay(100); 279 + /* wait approximately 100 usec as per spec */ 280 + usleep_range(100, 200); 276 281 277 282 /* bring controller out of reset */ 278 283 val &= ~(BIT(CFG_RESET_SHIFT)); ··· 309 314 val |= BIT(IE_S_START_BUSY_SHIFT); 310 315 iproc_i2c->slave_int_mask = val; 311 316 iproc_i2c_wr_reg(iproc_i2c, IE_OFFSET, val); 317 + } 318 + 319 + static void bcm_iproc_i2c_enable_disable(struct bcm_iproc_i2c_dev *iproc_i2c, 320 + bool enable) 321 + { 322 + u32 val; 323 + 324 + val = iproc_i2c_rd_reg(iproc_i2c, CFG_OFFSET); 325 + if (enable) 326 + val |= BIT(CFG_EN_SHIFT); 327 + else 328 + val &= ~BIT(CFG_EN_SHIFT); 329 + iproc_i2c_wr_reg(iproc_i2c, CFG_OFFSET, val); 312 330 } 313 331 314 332 static bool bcm_iproc_i2c_check_slave_status ··· 446 438 u32 val; 447 439 u8 value; 448 440 449 - 450 441 if (status & BIT(IS_S_TX_UNDERRUN_SHIFT)) { 451 442 iproc_i2c->tx_underrun++; 452 443 if (iproc_i2c->tx_underrun == 1) ··· 549 542 static void bcm_iproc_i2c_read_valid_bytes(struct bcm_iproc_i2c_dev *iproc_i2c) 550 543 { 551 544 struct i2c_msg *msg = iproc_i2c->msg; 552 - uint32_t val; 545 + u32 val; 553 546 554 547 /* Read valid data from RX FIFO */ 555 548 while (iproc_i2c->rx_bytes < msg->len) { ··· 695 688 val &= ~(BIT(CFG_EN_SHIFT)); 696 689 iproc_i2c_wr_reg(iproc_i2c, CFG_OFFSET, val); 697 690 698 - /* wait 100 usec per spec */ 699 - udelay(100); 691 + /* wait approximately 100 usec as per spec */ 692 + usleep_range(100, 200); 700 693 701 694 /* bring controller out of reset */ 702 695 val &= ~(BIT(CFG_RESET_SHIFT)); ··· 715 708 iproc_i2c_wr_reg(iproc_i2c, IS_OFFSET, 0xffffffff); 716 709 } 717 710 718 - static void bcm_iproc_i2c_enable_disable(struct bcm_iproc_i2c_dev *iproc_i2c, 719 - bool enable) 720 - { 721 - u32 val; 722 - 723 - val = iproc_i2c_rd_reg(iproc_i2c, CFG_OFFSET); 724 - if (enable) 725 - val |= BIT(CFG_EN_SHIFT); 726 - else 727 - val &= ~BIT(CFG_EN_SHIFT); 728 - iproc_i2c_wr_reg(iproc_i2c, CFG_OFFSET, val); 729 - } 730 - 731 711 static int bcm_iproc_i2c_check_status(struct bcm_iproc_i2c_dev *iproc_i2c, 732 712 struct i2c_msg *msg) 733 713 { ··· 728 734 return 0; 729 735 730 736 case M_CMD_STATUS_LOST_ARB: 731 - dev_dbg(iproc_i2c->device, "lost bus arbitration\n"); 737 + dev_err(iproc_i2c->device, "lost bus arbitration\n"); 732 738 return -EAGAIN; 733 739 734 740 case M_CMD_STATUS_NACK_ADDR: 735 - dev_dbg(iproc_i2c->device, "NAK addr:0x%02x\n", msg->addr); 741 + dev_err(iproc_i2c->device, "NAK addr:0x%02x\n", msg->addr); 736 742 return -ENXIO; 737 743 738 744 case M_CMD_STATUS_NACK_DATA: 739 - dev_dbg(iproc_i2c->device, "NAK data\n"); 745 + dev_err(iproc_i2c->device, "NAK data\n"); 740 746 return -ENXIO; 741 747 742 748 case M_CMD_STATUS_TIMEOUT: 743 - dev_dbg(iproc_i2c->device, "bus timeout\n"); 749 + dev_err(iproc_i2c->device, "bus timeout\n"); 744 750 return -ETIMEDOUT; 745 751 746 752 case M_CMD_STATUS_FIFO_UNDERRUN: 747 - dev_dbg(iproc_i2c->device, "FIFO under-run\n"); 753 + dev_err(iproc_i2c->device, "FIFO under-run\n"); 748 754 return -ENXIO; 749 755 750 756 case M_CMD_STATUS_RX_FIFO_FULL: 751 - dev_dbg(iproc_i2c->device, "RX FIFO full\n"); 757 + dev_err(iproc_i2c->device, "RX FIFO full\n"); 752 758 return -ETIMEDOUT; 753 759 754 760 default: 755 - dev_dbg(iproc_i2c->device, "unknown error code=%d\n", val); 761 + dev_err(iproc_i2c->device, "unknown error code=%d\n", val); 756 762 757 763 /* re-initialize i2c for recovery */ 758 764 bcm_iproc_i2c_enable_disable(iproc_i2c, false); ··· 827 833 * The i2c quirks are set to enforce this rule. 828 834 */ 829 835 static int bcm_iproc_i2c_xfer_internal(struct bcm_iproc_i2c_dev *iproc_i2c, 830 - struct i2c_msg *msgs, bool process_call) 836 + struct i2c_msg *msgs, bool process_call) 831 837 { 832 838 int i; 833 839 u8 addr; ··· 836 842 struct i2c_msg *msg = &msgs[0]; 837 843 838 844 /* check if bus is busy */ 839 - if (!!(iproc_i2c_rd_reg(iproc_i2c, 840 - M_CMD_OFFSET) & BIT(M_CMD_START_BUSY_SHIFT))) { 845 + if (iproc_i2c_rd_reg(iproc_i2c, 846 + M_CMD_OFFSET) & BIT(M_CMD_START_BUSY_SHIFT)) { 841 847 dev_warn(iproc_i2c->device, "bus is busy\n"); 842 848 return -EBUSY; 843 849 } ··· 964 970 965 971 ret = bcm_iproc_i2c_xfer_internal(iproc_i2c, msgs, process_call); 966 972 if (ret) { 967 - dev_dbg(iproc_i2c->device, "xfer failed\n"); 973 + dev_err(iproc_i2c->device, "xfer failed\n"); 968 974 return ret; 969 975 } 970 976 971 977 return num; 972 978 } 973 979 974 - static uint32_t bcm_iproc_i2c_functionality(struct i2c_adapter *adap) 980 + static u32 bcm_iproc_i2c_functionality(struct i2c_adapter *adap) 975 981 { 976 982 u32 val; 977 983 ··· 981 987 val |= I2C_FUNC_SLAVE; 982 988 983 989 return val; 990 + } 991 + 992 + static int bcm_iproc_i2c_reg_slave(struct i2c_client *slave) 993 + { 994 + struct bcm_iproc_i2c_dev *iproc_i2c = i2c_get_adapdata(slave->adapter); 995 + 996 + if (iproc_i2c->slave) 997 + return -EBUSY; 998 + 999 + if (slave->flags & I2C_CLIENT_TEN) 1000 + return -EAFNOSUPPORT; 1001 + 1002 + iproc_i2c->slave = slave; 1003 + 1004 + tasklet_init(&iproc_i2c->slave_rx_tasklet, slave_rx_tasklet_fn, 1005 + (unsigned long)iproc_i2c); 1006 + 1007 + bcm_iproc_i2c_slave_init(iproc_i2c, false); 1008 + 1009 + return 0; 1010 + } 1011 + 1012 + static int bcm_iproc_i2c_unreg_slave(struct i2c_client *slave) 1013 + { 1014 + struct bcm_iproc_i2c_dev *iproc_i2c = i2c_get_adapdata(slave->adapter); 1015 + u32 tmp; 1016 + 1017 + if (!iproc_i2c->slave) 1018 + return -EINVAL; 1019 + 1020 + disable_irq(iproc_i2c->irq); 1021 + 1022 + tasklet_kill(&iproc_i2c->slave_rx_tasklet); 1023 + 1024 + /* disable all slave interrupts */ 1025 + tmp = iproc_i2c_rd_reg(iproc_i2c, IE_OFFSET); 1026 + tmp &= ~(IE_S_ALL_INTERRUPT_MASK << 1027 + IE_S_ALL_INTERRUPT_SHIFT); 1028 + iproc_i2c_wr_reg(iproc_i2c, IE_OFFSET, tmp); 1029 + 1030 + /* Erase the slave address programmed */ 1031 + tmp = iproc_i2c_rd_reg(iproc_i2c, S_CFG_SMBUS_ADDR_OFFSET); 1032 + tmp &= ~BIT(S_CFG_EN_NIC_SMB_ADDR3_SHIFT); 1033 + iproc_i2c_wr_reg(iproc_i2c, S_CFG_SMBUS_ADDR_OFFSET, tmp); 1034 + 1035 + /* flush TX/RX FIFOs */ 1036 + tmp = (BIT(S_FIFO_RX_FLUSH_SHIFT) | BIT(S_FIFO_TX_FLUSH_SHIFT)); 1037 + iproc_i2c_wr_reg(iproc_i2c, S_FIFO_CTRL_OFFSET, tmp); 1038 + 1039 + /* clear all pending slave interrupts */ 1040 + iproc_i2c_wr_reg(iproc_i2c, IS_OFFSET, ISR_MASK_SLAVE); 1041 + 1042 + iproc_i2c->slave = NULL; 1043 + 1044 + enable_irq(iproc_i2c->irq); 1045 + 1046 + return 0; 984 1047 } 985 1048 986 1049 static struct i2c_algorithm bcm_iproc_algo = { ··· 1061 1010 "clock-frequency", &bus_speed); 1062 1011 if (ret < 0) { 1063 1012 dev_info(iproc_i2c->device, 1064 - "unable to interpret clock-frequency DT property\n"); 1013 + "unable to interpret clock-frequency DT property\n"); 1065 1014 bus_speed = I2C_MAX_STANDARD_MODE_FREQ; 1066 1015 } 1067 1016 1068 - if (bus_speed < I2C_MAX_STANDARD_MODE_FREQ) { 1069 - dev_err(iproc_i2c->device, "%d Hz bus speed not supported\n", 1070 - bus_speed); 1071 - dev_err(iproc_i2c->device, 1072 - "valid speeds are 100khz and 400khz\n"); 1073 - return -EINVAL; 1074 - } else if (bus_speed < I2C_MAX_FAST_MODE_FREQ) { 1017 + if (bus_speed < I2C_MAX_STANDARD_MODE_FREQ) 1018 + return dev_err_probe(iproc_i2c->device, -EINVAL, 1019 + "%d Hz not supported (out of 100-400 kHz range)\n", 1020 + bus_speed); 1021 + else if (bus_speed < I2C_MAX_FAST_MODE_FREQ) 1075 1022 bus_speed = I2C_MAX_STANDARD_MODE_FREQ; 1076 - } else { 1023 + else 1077 1024 bus_speed = I2C_MAX_FAST_MODE_FREQ; 1078 - } 1079 1025 1080 1026 iproc_i2c->bus_speed = bus_speed; 1081 1027 val = iproc_i2c_rd_reg(iproc_i2c, TIM_CFG_OFFSET); ··· 1087 1039 1088 1040 static int bcm_iproc_i2c_probe(struct platform_device *pdev) 1089 1041 { 1090 - int irq, ret = 0; 1091 1042 struct bcm_iproc_i2c_dev *iproc_i2c; 1092 1043 struct i2c_adapter *adap; 1044 + int irq, ret; 1093 1045 1094 1046 iproc_i2c = devm_kzalloc(&pdev->dev, sizeof(*iproc_i2c), 1095 1047 GFP_KERNEL); ··· 1114 1066 ret = of_property_read_u32(iproc_i2c->device->of_node, 1115 1067 "brcm,ape-hsls-addr-mask", 1116 1068 &iproc_i2c->ape_addr_mask); 1117 - if (ret < 0) { 1118 - dev_err(iproc_i2c->device, 1119 - "'brcm,ape-hsls-addr-mask' missing\n"); 1120 - return -EINVAL; 1121 - } 1069 + if (ret < 0) 1070 + return dev_err_probe(iproc_i2c->device, ret, 1071 + "'brcm,ape-hsls-addr-mask' missing\n"); 1122 1072 1123 1073 spin_lock_init(&iproc_i2c->idm_lock); 1124 1074 ··· 1136 1090 ret = devm_request_irq(iproc_i2c->device, irq, 1137 1091 bcm_iproc_i2c_isr, 0, pdev->name, 1138 1092 iproc_i2c); 1139 - if (ret < 0) { 1140 - dev_err(iproc_i2c->device, 1141 - "unable to request irq %i\n", irq); 1142 - return ret; 1143 - } 1093 + if (ret < 0) 1094 + return dev_err_probe(iproc_i2c->device, ret, 1095 + "unable to request irq %i\n", irq); 1144 1096 1145 1097 iproc_i2c->irq = irq; 1146 1098 } else { ··· 1150 1106 1151 1107 adap = &iproc_i2c->adapter; 1152 1108 i2c_set_adapdata(adap, iproc_i2c); 1153 - snprintf(adap->name, sizeof(adap->name), 1154 - "Broadcom iProc (%s)", 1155 - of_node_full_name(iproc_i2c->device->of_node)); 1109 + snprintf(adap->name, sizeof(adap->name), "Broadcom iProc (%s)", 1110 + of_node_full_name(iproc_i2c->device->of_node)); 1156 1111 adap->algo = &bcm_iproc_algo; 1157 1112 adap->quirks = &bcm_iproc_i2c_quirks; 1158 1113 adap->dev.parent = &pdev->dev; ··· 1224 1181 .suspend_late = &bcm_iproc_i2c_suspend, 1225 1182 .resume_early = &bcm_iproc_i2c_resume 1226 1183 }; 1227 - 1228 - static int bcm_iproc_i2c_reg_slave(struct i2c_client *slave) 1229 - { 1230 - struct bcm_iproc_i2c_dev *iproc_i2c = i2c_get_adapdata(slave->adapter); 1231 - 1232 - if (iproc_i2c->slave) 1233 - return -EBUSY; 1234 - 1235 - if (slave->flags & I2C_CLIENT_TEN) 1236 - return -EAFNOSUPPORT; 1237 - 1238 - iproc_i2c->slave = slave; 1239 - 1240 - tasklet_init(&iproc_i2c->slave_rx_tasklet, slave_rx_tasklet_fn, 1241 - (unsigned long)iproc_i2c); 1242 - 1243 - bcm_iproc_i2c_slave_init(iproc_i2c, false); 1244 - return 0; 1245 - } 1246 - 1247 - static int bcm_iproc_i2c_unreg_slave(struct i2c_client *slave) 1248 - { 1249 - u32 tmp; 1250 - struct bcm_iproc_i2c_dev *iproc_i2c = i2c_get_adapdata(slave->adapter); 1251 - 1252 - if (!iproc_i2c->slave) 1253 - return -EINVAL; 1254 - 1255 - disable_irq(iproc_i2c->irq); 1256 - 1257 - tasklet_kill(&iproc_i2c->slave_rx_tasklet); 1258 - 1259 - /* disable all slave interrupts */ 1260 - tmp = iproc_i2c_rd_reg(iproc_i2c, IE_OFFSET); 1261 - tmp &= ~(IE_S_ALL_INTERRUPT_MASK << 1262 - IE_S_ALL_INTERRUPT_SHIFT); 1263 - iproc_i2c_wr_reg(iproc_i2c, IE_OFFSET, tmp); 1264 - 1265 - /* Erase the slave address programmed */ 1266 - tmp = iproc_i2c_rd_reg(iproc_i2c, S_CFG_SMBUS_ADDR_OFFSET); 1267 - tmp &= ~BIT(S_CFG_EN_NIC_SMB_ADDR3_SHIFT); 1268 - iproc_i2c_wr_reg(iproc_i2c, S_CFG_SMBUS_ADDR_OFFSET, tmp); 1269 - 1270 - /* flush TX/RX FIFOs */ 1271 - tmp = (BIT(S_FIFO_RX_FLUSH_SHIFT) | BIT(S_FIFO_TX_FLUSH_SHIFT)); 1272 - iproc_i2c_wr_reg(iproc_i2c, S_FIFO_CTRL_OFFSET, tmp); 1273 - 1274 - /* clear all pending slave interrupts */ 1275 - iproc_i2c_wr_reg(iproc_i2c, IS_OFFSET, ISR_MASK_SLAVE); 1276 - 1277 - iproc_i2c->slave = NULL; 1278 - 1279 - enable_irq(iproc_i2c->irq); 1280 - 1281 - return 0; 1282 - } 1283 1184 1284 1185 static const struct of_device_id bcm_iproc_i2c_of_match[] = { 1285 1186 {
+2 -1
drivers/i2c/busses/i2c-davinci.c
··· 551 551 552 552 static u32 i2c_davinci_func(struct i2c_adapter *adap) 553 553 { 554 - return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; 554 + return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | 555 + I2C_FUNC_PROTOCOL_MANGLING; 555 556 } 556 557 557 558 static void terminate_read(struct davinci_i2c_dev *dev)
+205
drivers/i2c/busses/i2c-designware-amdisp.c
··· 1 + // SPDX-License-Identifier: GPL-2.0+ 2 + /* 3 + * Based on Synopsys DesignWare I2C adapter driver. 4 + * 5 + * Copyright (C) 2025 Advanced Micro Devices, Inc. 6 + */ 7 + 8 + #include <linux/module.h> 9 + #include <linux/platform_device.h> 10 + #include <linux/pm_runtime.h> 11 + 12 + #include "i2c-designware-core.h" 13 + 14 + #define DRV_NAME "amd_isp_i2c_designware" 15 + #define AMD_ISP_I2C_INPUT_CLK 100 /* Mhz */ 16 + 17 + static void amd_isp_dw_i2c_plat_pm_cleanup(struct dw_i2c_dev *i2c_dev) 18 + { 19 + pm_runtime_disable(i2c_dev->dev); 20 + 21 + if (i2c_dev->shared_with_punit) 22 + pm_runtime_put_noidle(i2c_dev->dev); 23 + } 24 + 25 + static inline u32 amd_isp_dw_i2c_get_clk_rate(struct dw_i2c_dev *i2c_dev) 26 + { 27 + return AMD_ISP_I2C_INPUT_CLK * 1000; 28 + } 29 + 30 + static int amd_isp_dw_i2c_plat_probe(struct platform_device *pdev) 31 + { 32 + struct dw_i2c_dev *isp_i2c_dev; 33 + struct i2c_adapter *adap; 34 + int ret; 35 + 36 + isp_i2c_dev = devm_kzalloc(&pdev->dev, sizeof(*isp_i2c_dev), GFP_KERNEL); 37 + if (!isp_i2c_dev) 38 + return -ENOMEM; 39 + isp_i2c_dev->dev = &pdev->dev; 40 + 41 + pdev->dev.init_name = DRV_NAME; 42 + 43 + /* 44 + * Use the polling mode to send/receive the data, because 45 + * no IRQ connection from ISP I2C 46 + */ 47 + isp_i2c_dev->flags |= ACCESS_POLLING; 48 + platform_set_drvdata(pdev, isp_i2c_dev); 49 + 50 + isp_i2c_dev->base = devm_platform_ioremap_resource(pdev, 0); 51 + if (IS_ERR(isp_i2c_dev->base)) 52 + return dev_err_probe(&pdev->dev, PTR_ERR(isp_i2c_dev->base), 53 + "failed to get IOMEM resource\n"); 54 + 55 + isp_i2c_dev->get_clk_rate_khz = amd_isp_dw_i2c_get_clk_rate; 56 + ret = i2c_dw_fw_parse_and_configure(isp_i2c_dev); 57 + if (ret) 58 + return dev_err_probe(&pdev->dev, ret, 59 + "failed to parse i2c dw fwnode and configure\n"); 60 + 61 + i2c_dw_configure(isp_i2c_dev); 62 + 63 + adap = &isp_i2c_dev->adapter; 64 + adap->owner = THIS_MODULE; 65 + ACPI_COMPANION_SET(&adap->dev, ACPI_COMPANION(&pdev->dev)); 66 + adap->dev.of_node = pdev->dev.of_node; 67 + /* use dynamically allocated adapter id */ 68 + adap->nr = -1; 69 + 70 + if (isp_i2c_dev->flags & ACCESS_NO_IRQ_SUSPEND) 71 + dev_pm_set_driver_flags(&pdev->dev, 72 + DPM_FLAG_SMART_PREPARE); 73 + else 74 + dev_pm_set_driver_flags(&pdev->dev, 75 + DPM_FLAG_SMART_PREPARE | 76 + DPM_FLAG_SMART_SUSPEND); 77 + 78 + device_enable_async_suspend(&pdev->dev); 79 + 80 + if (isp_i2c_dev->shared_with_punit) 81 + pm_runtime_get_noresume(&pdev->dev); 82 + 83 + pm_runtime_enable(&pdev->dev); 84 + pm_runtime_get_sync(&pdev->dev); 85 + 86 + ret = i2c_dw_probe(isp_i2c_dev); 87 + if (ret) { 88 + dev_err_probe(&pdev->dev, ret, "i2c_dw_probe failed\n"); 89 + goto error_release_rpm; 90 + } 91 + 92 + pm_runtime_put_sync(&pdev->dev); 93 + 94 + return 0; 95 + 96 + error_release_rpm: 97 + amd_isp_dw_i2c_plat_pm_cleanup(isp_i2c_dev); 98 + pm_runtime_put_sync(&pdev->dev); 99 + return ret; 100 + } 101 + 102 + static void amd_isp_dw_i2c_plat_remove(struct platform_device *pdev) 103 + { 104 + struct dw_i2c_dev *isp_i2c_dev = platform_get_drvdata(pdev); 105 + 106 + pm_runtime_get_sync(&pdev->dev); 107 + 108 + i2c_del_adapter(&isp_i2c_dev->adapter); 109 + 110 + i2c_dw_disable(isp_i2c_dev); 111 + 112 + pm_runtime_put_sync(&pdev->dev); 113 + amd_isp_dw_i2c_plat_pm_cleanup(isp_i2c_dev); 114 + } 115 + 116 + static int amd_isp_dw_i2c_plat_prepare(struct device *dev) 117 + { 118 + /* 119 + * If the ACPI companion device object is present for this device, it 120 + * may be accessed during suspend and resume of other devices via I2C 121 + * operation regions, so tell the PM core and middle layers to avoid 122 + * skipping system suspend/resume callbacks for it in that case. 123 + */ 124 + return !has_acpi_companion(dev); 125 + } 126 + 127 + static int amd_isp_dw_i2c_plat_runtime_suspend(struct device *dev) 128 + { 129 + struct dw_i2c_dev *i_dev = dev_get_drvdata(dev); 130 + 131 + if (i_dev->shared_with_punit) 132 + return 0; 133 + 134 + i2c_dw_disable(i_dev); 135 + i2c_dw_prepare_clk(i_dev, false); 136 + 137 + return 0; 138 + } 139 + 140 + static int amd_isp_dw_i2c_plat_suspend(struct device *dev) 141 + { 142 + struct dw_i2c_dev *i_dev = dev_get_drvdata(dev); 143 + int ret; 144 + 145 + if (!i_dev) 146 + return -ENODEV; 147 + 148 + ret = amd_isp_dw_i2c_plat_runtime_suspend(dev); 149 + if (!ret) 150 + i2c_mark_adapter_suspended(&i_dev->adapter); 151 + 152 + return ret; 153 + } 154 + 155 + static int amd_isp_dw_i2c_plat_runtime_resume(struct device *dev) 156 + { 157 + struct dw_i2c_dev *i_dev = dev_get_drvdata(dev); 158 + 159 + if (!i_dev) 160 + return -ENODEV; 161 + 162 + if (!i_dev->shared_with_punit) 163 + i2c_dw_prepare_clk(i_dev, true); 164 + if (i_dev->init) 165 + i_dev->init(i_dev); 166 + 167 + return 0; 168 + } 169 + 170 + static int amd_isp_dw_i2c_plat_resume(struct device *dev) 171 + { 172 + struct dw_i2c_dev *i_dev = dev_get_drvdata(dev); 173 + 174 + amd_isp_dw_i2c_plat_runtime_resume(dev); 175 + i2c_mark_adapter_resumed(&i_dev->adapter); 176 + 177 + return 0; 178 + } 179 + 180 + static const struct dev_pm_ops amd_isp_dw_i2c_dev_pm_ops = { 181 + .prepare = pm_sleep_ptr(amd_isp_dw_i2c_plat_prepare), 182 + LATE_SYSTEM_SLEEP_PM_OPS(amd_isp_dw_i2c_plat_suspend, amd_isp_dw_i2c_plat_resume) 183 + RUNTIME_PM_OPS(amd_isp_dw_i2c_plat_runtime_suspend, amd_isp_dw_i2c_plat_runtime_resume, NULL) 184 + }; 185 + 186 + /* Work with hotplug and coldplug */ 187 + MODULE_ALIAS("platform:amd_isp_i2c_designware"); 188 + 189 + static struct platform_driver amd_isp_dw_i2c_driver = { 190 + .probe = amd_isp_dw_i2c_plat_probe, 191 + .remove = amd_isp_dw_i2c_plat_remove, 192 + .driver = { 193 + .name = DRV_NAME, 194 + .pm = pm_ptr(&amd_isp_dw_i2c_dev_pm_ops), 195 + }, 196 + }; 197 + module_platform_driver(amd_isp_dw_i2c_driver); 198 + 199 + MODULE_DESCRIPTION("Synopsys DesignWare I2C bus adapter in AMD ISP"); 200 + MODULE_IMPORT_NS("I2C_DW"); 201 + MODULE_IMPORT_NS("I2C_DW_COMMON"); 202 + MODULE_AUTHOR("Venkata Narendra Kumar Gutta <vengutta@amd.com>"); 203 + MODULE_AUTHOR("Pratap Nirujogi <pratap.nirujogi@amd.com>"); 204 + MODULE_AUTHOR("Bin Du <bin.du@amd.com>"); 205 + MODULE_LICENSE("GPL");
+3 -1
drivers/i2c/busses/i2c-designware-common.c
··· 572 572 * Clock is not necessary if we got LCNT/HCNT values directly from 573 573 * the platform code. 574 574 */ 575 - if (WARN_ON_ONCE(!dev->get_clk_rate_khz)) 575 + if (!dev->get_clk_rate_khz) { 576 + dev_dbg_once(dev->dev, "Callback get_clk_rate_khz() is not defined\n"); 576 577 return 0; 578 + } 577 579 return dev->get_clk_rate_khz(dev); 578 580 } 579 581
+1 -1
drivers/i2c/busses/i2c-designware-platdrv.c
··· 34 34 35 35 static u32 i2c_dw_get_clk_rate_khz(struct dw_i2c_dev *dev) 36 36 { 37 - return clk_get_rate(dev->clk) / KILO; 37 + return clk_get_rate(dev->clk) / HZ_PER_KHZ; 38 38 } 39 39 40 40 #ifdef CONFIG_OF
+1 -1
drivers/i2c/busses/i2c-designware-slave.c
··· 96 96 i2c_dw_disable(dev); 97 97 synchronize_irq(dev->irq); 98 98 dev->slave = NULL; 99 - pm_runtime_put(dev->dev); 99 + pm_runtime_put_sync_suspend(dev->dev); 100 100 101 101 return 0; 102 102 }
+2 -2
drivers/i2c/busses/i2c-i801.c
··· 1180 1180 #ifdef CONFIG_I2C_I801_MUX 1181 1181 if (!priv->mux_pdev) 1182 1182 #endif 1183 - i2c_register_spd(&priv->adapter); 1183 + i2c_register_spd_write_enable(&priv->adapter); 1184 1184 } 1185 1185 #else 1186 1186 static void __init input_apanel_init(void) {} ··· 1283 1283 return NOTIFY_DONE; 1284 1284 1285 1285 /* Call i2c_register_spd for muxed child segments */ 1286 - i2c_register_spd(to_i2c_adapter(dev)); 1286 + i2c_register_spd_write_enable(to_i2c_adapter(dev)); 1287 1287 1288 1288 return NOTIFY_OK; 1289 1289 }
+7 -5
drivers/i2c/busses/i2c-imx.c
··· 1711 1711 1712 1712 irq = platform_get_irq(pdev, 0); 1713 1713 if (irq < 0) 1714 - return irq; 1714 + return dev_err_probe(&pdev->dev, irq, "can't get IRQ\n"); 1715 1715 1716 1716 base = devm_platform_get_and_ioremap_resource(pdev, 0, &res); 1717 1717 if (IS_ERR(base)) 1718 - return PTR_ERR(base); 1718 + return dev_err_probe(&pdev->dev, PTR_ERR(base), "can't get IO memory\n"); 1719 1719 1720 1720 phy_addr = (dma_addr_t)res->start; 1721 1721 i2c_imx = devm_kzalloc(&pdev->dev, sizeof(*i2c_imx), GFP_KERNEL); ··· 1810 1810 */ 1811 1811 ret = i2c_imx_dma_request(i2c_imx, phy_addr); 1812 1812 if (ret) { 1813 - if (ret == -EPROBE_DEFER) 1813 + if (ret == -EPROBE_DEFER) { 1814 + dev_err_probe(&pdev->dev, ret, "can't get DMA channels\n"); 1814 1815 goto clk_notifier_unregister; 1815 - else if (ret == -ENODEV) 1816 + } else if (ret == -ENODEV) { 1816 1817 dev_dbg(&pdev->dev, "Only use PIO mode\n"); 1817 - else 1818 + } else { 1818 1819 dev_warn(&pdev->dev, "Failed to setup DMA (%pe), only use PIO mode\n", 1819 1820 ERR_PTR(ret)); 1821 + } 1820 1822 } 1821 1823 1822 1824 /* Add I2C adapter */
+1 -1
drivers/i2c/busses/i2c-ismt.c
··· 933 933 return err; 934 934 } 935 935 936 - err = pci_request_region(pdev, SMBBAR, ismt_driver.name); 936 + err = pcim_request_region(pdev, SMBBAR, ismt_driver.name); 937 937 if (err) { 938 938 dev_err(&pdev->dev, 939 939 "Failed to request SMBus region 0x%lx-0x%lx\n",
+6 -1
drivers/i2c/busses/i2c-lpc2k.c
··· 442 442 static int i2c_lpc2k_resume(struct device *dev) 443 443 { 444 444 struct lpc2k_i2c *i2c = dev_get_drvdata(dev); 445 + int ret; 445 446 446 - clk_enable(i2c->clk); 447 + ret = clk_enable(i2c->clk); 448 + if (ret) { 449 + dev_err(dev, "failed to enable clock.\n"); 450 + return ret; 451 + } 447 452 i2c_lpc2k_reset(i2c); 448 453 449 454 return 0;
+102
drivers/i2c/busses/i2c-microchip-corei2c.c
··· 76 76 #define CORE_I2C_FREQ (0x14) 77 77 #define CORE_I2C_GLITCHREG (0x18) 78 78 #define CORE_I2C_SLAVE1_ADDR (0x1c) 79 + #define CORE_I2C_SMBUS_MSG_WR (0x0) 80 + #define CORE_I2C_SMBUS_MSG_RD (0x1) 79 81 80 82 #define PCLK_DIV_960 (CTRL_CR2) 81 83 #define PCLK_DIV_256 (0) ··· 426 424 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; 427 425 } 428 426 427 + static int mchp_corei2c_smbus_xfer(struct i2c_adapter *adap, u16 addr, unsigned short flags, 428 + char read_write, u8 command, 429 + int size, union i2c_smbus_data *data) 430 + { 431 + struct i2c_msg msgs[2]; 432 + struct mchp_corei2c_dev *idev = i2c_get_adapdata(adap); 433 + u8 tx_buf[I2C_SMBUS_BLOCK_MAX + 2]; 434 + u8 rx_buf[I2C_SMBUS_BLOCK_MAX + 1]; 435 + int num_msgs = 1; 436 + 437 + msgs[CORE_I2C_SMBUS_MSG_WR].addr = addr; 438 + msgs[CORE_I2C_SMBUS_MSG_WR].flags = 0; 439 + 440 + if (read_write == I2C_SMBUS_READ && size <= I2C_SMBUS_BYTE) 441 + msgs[CORE_I2C_SMBUS_MSG_WR].flags = I2C_M_RD; 442 + 443 + if (read_write == I2C_SMBUS_WRITE && size <= I2C_SMBUS_WORD_DATA) 444 + msgs[CORE_I2C_SMBUS_MSG_WR].len = size; 445 + 446 + if (read_write == I2C_SMBUS_WRITE && size > I2C_SMBUS_BYTE) { 447 + msgs[CORE_I2C_SMBUS_MSG_WR].buf = tx_buf; 448 + msgs[CORE_I2C_SMBUS_MSG_WR].buf[0] = command; 449 + } 450 + 451 + if (read_write == I2C_SMBUS_READ && size >= I2C_SMBUS_BYTE_DATA) { 452 + msgs[CORE_I2C_SMBUS_MSG_WR].buf = tx_buf; 453 + msgs[CORE_I2C_SMBUS_MSG_WR].buf[0] = command; 454 + msgs[CORE_I2C_SMBUS_MSG_RD].addr = addr; 455 + msgs[CORE_I2C_SMBUS_MSG_RD].flags = I2C_M_RD; 456 + num_msgs = 2; 457 + } 458 + 459 + if (read_write == I2C_SMBUS_READ && size > I2C_SMBUS_QUICK) 460 + msgs[CORE_I2C_SMBUS_MSG_WR].len = 1; 461 + 462 + switch (size) { 463 + case I2C_SMBUS_QUICK: 464 + msgs[CORE_I2C_SMBUS_MSG_WR].buf = NULL; 465 + return 0; 466 + case I2C_SMBUS_BYTE: 467 + if (read_write == I2C_SMBUS_WRITE) 468 + msgs[CORE_I2C_SMBUS_MSG_WR].buf = &command; 469 + else 470 + msgs[CORE_I2C_SMBUS_MSG_WR].buf = &data->byte; 471 + break; 472 + case I2C_SMBUS_BYTE_DATA: 473 + if (read_write == I2C_SMBUS_WRITE) { 474 + msgs[CORE_I2C_SMBUS_MSG_WR].buf[1] = data->byte; 475 + } else { 476 + msgs[CORE_I2C_SMBUS_MSG_RD].len = size - 1; 477 + msgs[CORE_I2C_SMBUS_MSG_RD].buf = &data->byte; 478 + } 479 + break; 480 + case I2C_SMBUS_WORD_DATA: 481 + if (read_write == I2C_SMBUS_WRITE) { 482 + msgs[CORE_I2C_SMBUS_MSG_WR].buf[1] = data->word & 0xFF; 483 + msgs[CORE_I2C_SMBUS_MSG_WR].buf[2] = (data->word >> 8) & 0xFF; 484 + } else { 485 + msgs[CORE_I2C_SMBUS_MSG_RD].len = size - 1; 486 + msgs[CORE_I2C_SMBUS_MSG_RD].buf = rx_buf; 487 + } 488 + break; 489 + case I2C_SMBUS_BLOCK_DATA: 490 + if (read_write == I2C_SMBUS_WRITE) { 491 + int data_len; 492 + 493 + data_len = data->block[0]; 494 + msgs[CORE_I2C_SMBUS_MSG_WR].len = data_len + 2; 495 + for (int i = 0; i <= data_len; i++) 496 + msgs[CORE_I2C_SMBUS_MSG_WR].buf[i + 1] = data->block[i]; 497 + } else { 498 + msgs[CORE_I2C_SMBUS_MSG_RD].len = I2C_SMBUS_BLOCK_MAX + 1; 499 + msgs[CORE_I2C_SMBUS_MSG_RD].buf = rx_buf; 500 + } 501 + break; 502 + default: 503 + return -EOPNOTSUPP; 504 + } 505 + 506 + mchp_corei2c_xfer(&idev->adapter, msgs, num_msgs); 507 + if (read_write == I2C_SMBUS_WRITE || size <= I2C_SMBUS_BYTE_DATA) 508 + return 0; 509 + 510 + switch (size) { 511 + case I2C_SMBUS_WORD_DATA: 512 + data->word = (rx_buf[0] | (rx_buf[1] << 8)); 513 + break; 514 + case I2C_SMBUS_BLOCK_DATA: 515 + if (rx_buf[0] > I2C_SMBUS_BLOCK_MAX) 516 + rx_buf[0] = I2C_SMBUS_BLOCK_MAX; 517 + /* As per protocol first member of block is size of the block. */ 518 + for (int i = 0; i <= rx_buf[0]; i++) 519 + data->block[i] = rx_buf[i]; 520 + break; 521 + } 522 + 523 + return 0; 524 + } 525 + 429 526 static const struct i2c_algorithm mchp_corei2c_algo = { 430 527 .master_xfer = mchp_corei2c_xfer, 431 528 .functionality = mchp_corei2c_func, 529 + .smbus_xfer = mchp_corei2c_smbus_xfer, 432 530 }; 433 531 434 532 static int mchp_corei2c_probe(struct platform_device *pdev)
+51 -36
drivers/i2c/busses/i2c-mlxbf.c
··· 19 19 #include <linux/of.h> 20 20 #include <linux/platform_device.h> 21 21 #include <linux/string.h> 22 + #include <linux/string_choices.h> 22 23 23 24 /* Defines what functionality is present. */ 24 25 #define MLXBF_I2C_FUNC_SMBUS_BLOCK \ ··· 198 197 199 198 #define MLXBF_I2C_MASK_8 GENMASK(7, 0) 200 199 #define MLXBF_I2C_MASK_16 GENMASK(15, 0) 200 + #define MLXBF_I2C_MASK_32 GENMASK(31, 0) 201 201 202 202 #define MLXBF_I2C_MST_ADDR_OFFSET 0x200 203 203 ··· 225 223 226 224 #define MLXBF_I2C_MASTER_ENABLE \ 227 225 (MLXBF_I2C_MASTER_LOCK_BIT | MLXBF_I2C_MASTER_BUSY_BIT | \ 228 - MLXBF_I2C_MASTER_START_BIT | MLXBF_I2C_MASTER_STOP_BIT) 226 + MLXBF_I2C_MASTER_START_BIT) 229 227 230 228 #define MLXBF_I2C_MASTER_ENABLE_WRITE \ 231 229 (MLXBF_I2C_MASTER_ENABLE | MLXBF_I2C_MASTER_CTL_WRITE_BIT) ··· 339 337 MLXBF_I2C_F_SMBUS_BLOCK = BIT(5), 340 338 MLXBF_I2C_F_SMBUS_PEC = BIT(6), 341 339 MLXBF_I2C_F_SMBUS_PROCESS_CALL = BIT(7), 340 + MLXBF_I2C_F_WRITE_WITHOUT_STOP = BIT(8), 342 341 }; 343 342 344 343 /* Mellanox BlueField chip type. */ ··· 640 637 } 641 638 642 639 static int mlxbf_i2c_smbus_enable(struct mlxbf_i2c_priv *priv, u8 slave, 643 - u8 len, u8 block_en, u8 pec_en, bool read) 640 + u8 len, u8 block_en, u8 pec_en, bool read, 641 + bool stop) 644 642 { 645 - u32 command; 643 + u32 command = 0; 646 644 647 645 /* Set Master GW control word. */ 646 + if (stop) 647 + command |= MLXBF_I2C_MASTER_STOP_BIT; 648 648 if (read) { 649 - command = MLXBF_I2C_MASTER_ENABLE_READ; 649 + command |= MLXBF_I2C_MASTER_ENABLE_READ; 650 650 command |= rol32(len, MLXBF_I2C_MASTER_READ_SHIFT); 651 651 } else { 652 - command = MLXBF_I2C_MASTER_ENABLE_WRITE; 652 + command |= MLXBF_I2C_MASTER_ENABLE_WRITE; 653 653 command |= rol32(len, MLXBF_I2C_MASTER_WRITE_SHIFT); 654 654 } 655 655 command |= rol32(slave, MLXBF_I2C_MASTER_SLV_ADDR_SHIFT); ··· 687 681 u8 op_idx, data_idx, data_len, write_len, read_len; 688 682 struct mlxbf_i2c_smbus_operation *operation; 689 683 u8 read_en, write_en, block_en, pec_en; 690 - u8 slave, flags, addr; 684 + bool stop_after_write = true; 685 + u8 slave, addr; 691 686 u8 *read_buf; 687 + u32 flags; 692 688 u32 bits; 693 689 int ret; 694 690 ··· 762 754 memcpy(data_desc + data_idx, 763 755 operation->buffer, operation->length); 764 756 data_idx += operation->length; 757 + 758 + /* 759 + * The stop condition can be skipped when writing on the bus 760 + * to implement a repeated start condition on the next read 761 + * as required for several SMBus and I2C operations. 762 + */ 763 + if (flags & MLXBF_I2C_F_WRITE_WITHOUT_STOP) 764 + stop_after_write = false; 765 765 } 766 + 766 767 /* 767 768 * We assume that read operations are performed only once per 768 769 * SMBus transaction. *TBD* protect this statement so it won't ··· 797 780 798 781 if (write_en) { 799 782 ret = mlxbf_i2c_smbus_enable(priv, slave, write_len, block_en, 800 - pec_en, 0); 783 + pec_en, 0, stop_after_write); 801 784 if (ret) 802 785 goto out_unlock; 803 786 } ··· 807 790 mlxbf_i2c_smbus_write_data(priv, (const u8 *)&addr, 1, 808 791 MLXBF_I2C_MASTER_DATA_DESC_ADDR, true); 809 792 ret = mlxbf_i2c_smbus_enable(priv, slave, read_len, block_en, 810 - pec_en, 1); 793 + pec_en, 1, true); 811 794 if (!ret) { 812 795 /* Get Master GW data descriptor. */ 813 796 mlxbf_i2c_smbus_read_data(priv, data_desc, read_len + 1, ··· 912 895 MLXBF_I2C_F_SMBUS_OPERATION | MLXBF_I2C_F_WRITE; 913 896 request->operation[0].flags |= pec_check ? MLXBF_I2C_F_SMBUS_PEC : 0; 914 897 request->operation[0].buffer = command; 898 + 899 + if (read) 900 + request->operation[0].flags |= MLXBF_I2C_F_WRITE_WITHOUT_STOP; 915 901 916 902 /* 917 903 * As specified in the standard, the max number of bytes to read/write ··· 1083 1063 * Frequency 1084 1064 */ 1085 1065 frequency = priv->frequency; 1086 - ticks = (nanoseconds * frequency) / MLXBF_I2C_FREQUENCY_1GHZ; 1066 + ticks = div_u64(nanoseconds * frequency, MLXBF_I2C_FREQUENCY_1GHZ); 1087 1067 /* 1088 1068 * The number of ticks is rounded down and if minimum is equal to 1 1089 1069 * then add one tick. ··· 1150 1130 MLXBF_I2C_MASK_16, MLXBF_I2C_SHIFT_16); 1151 1131 writel(timer, priv->timer->io + MLXBF_I2C_SMBUS_THIGH_MAX_TBUF); 1152 1132 1153 - timer = timings->timeout; 1133 + timer = mlxbf_i2c_set_timer(priv, timings->timeout, false, 1134 + MLXBF_I2C_MASK_32, MLXBF_I2C_SHIFT_0); 1154 1135 writel(timer, priv->timer->io + MLXBF_I2C_SMBUS_SCL_LOW_TIMEOUT); 1155 1136 } 1156 1137 ··· 1161 1140 MLXBF_I2C_TIMING_CONFIG_1000KHZ, 1162 1141 }; 1163 1142 1164 - /* 1165 - * Note that the mlxbf_i2c_timings->timeout value is not related to the 1166 - * bus frequency, it is impacted by the time it takes the driver to 1167 - * complete data transmission before transaction abort. 1168 - */ 1143 + /* Timing values are in nanoseconds */ 1169 1144 static const struct mlxbf_i2c_timings mlxbf_i2c_timings[] = { 1170 1145 [MLXBF_I2C_TIMING_CONFIG_100KHZ] = { 1171 1146 .scl_high = 4810, ··· 1176 1159 .scl_fall = 50, 1177 1160 .hold_data = 300, 1178 1161 .buf = 20000, 1179 - .thigh_max = 5000, 1180 - .timeout = 106500 1162 + .thigh_max = 50000, 1163 + .timeout = 35000000 1181 1164 }, 1182 1165 [MLXBF_I2C_TIMING_CONFIG_400KHZ] = { 1183 1166 .scl_high = 1011, ··· 1192 1175 .scl_fall = 50, 1193 1176 .hold_data = 300, 1194 1177 .buf = 20000, 1195 - .thigh_max = 5000, 1196 - .timeout = 106500 1178 + .thigh_max = 50000, 1179 + .timeout = 35000000 1197 1180 }, 1198 1181 [MLXBF_I2C_TIMING_CONFIG_1000KHZ] = { 1199 - .scl_high = 600, 1200 - .scl_low = 1300, 1182 + .scl_high = 383, 1183 + .scl_low = 460, 1201 1184 .hold_start = 600, 1202 - .setup_start = 600, 1203 - .setup_stop = 600, 1204 - .setup_data = 100, 1185 + .setup_start = 260, 1186 + .setup_stop = 260, 1187 + .setup_data = 50, 1205 1188 .sda_rise = 50, 1206 1189 .sda_fall = 50, 1207 1190 .scl_rise = 50, 1208 1191 .scl_fall = 50, 1209 1192 .hold_data = 300, 1210 - .buf = 20000, 1211 - .thigh_max = 5000, 1212 - .timeout = 106500 1193 + .buf = 500, 1194 + .thigh_max = 50000, 1195 + .timeout = 35000000 1213 1196 } 1214 1197 }; 1215 1198 ··· 1460 1443 * and PadFrequency, respectively. 1461 1444 */ 1462 1445 core_frequency = MLXBF_I2C_PLL_IN_FREQ * (++core_f); 1463 - core_frequency /= (++core_r) * (++core_od); 1464 1446 1465 - return core_frequency; 1447 + return div_u64(core_frequency, (++core_r) * (++core_od)); 1466 1448 } 1467 1449 1468 1450 static u64 mlxbf_i2c_calculate_freq_from_yu(struct mlxbf_i2c_resource *corepll_res) ··· 1490 1474 * and PadFrequency, respectively. 1491 1475 */ 1492 1476 corepll_frequency = (MLXBF_I2C_PLL_IN_FREQ * core_f) / MLNXBF_I2C_COREPLL_CONST; 1493 - corepll_frequency /= (++core_r) * (++core_od); 1494 1477 1495 - return corepll_frequency; 1478 + return div_u64(corepll_frequency, (++core_r) * (++core_od)); 1496 1479 } 1497 1480 1498 1481 static int mlxbf_i2c_calculate_corepll_freq(struct platform_device *pdev, ··· 2053 2038 read ? &data->byte : &command, read, 2054 2039 pec); 2055 2040 dev_dbg(&adap->dev, "smbus %s byte, slave 0x%02x.\n", 2056 - read ? "read" : "write", addr); 2041 + str_read_write(read), addr); 2057 2042 break; 2058 2043 2059 2044 case I2C_SMBUS_BYTE_DATA: 2060 2045 mlxbf_i2c_smbus_data_byte_func(&request, &command, &data->byte, 2061 2046 read, pec); 2062 2047 dev_dbg(&adap->dev, "smbus %s byte data at 0x%02x, slave 0x%02x.\n", 2063 - read ? "read" : "write", command, addr); 2048 + str_read_write(read), command, addr); 2064 2049 break; 2065 2050 2066 2051 case I2C_SMBUS_WORD_DATA: 2067 2052 mlxbf_i2c_smbus_data_word_func(&request, &command, 2068 2053 (u8 *)&data->word, read, pec); 2069 2054 dev_dbg(&adap->dev, "smbus %s word data at 0x%02x, slave 0x%02x.\n", 2070 - read ? "read" : "write", command, addr); 2055 + str_read_write(read), command, addr); 2071 2056 break; 2072 2057 2073 2058 case I2C_SMBUS_I2C_BLOCK_DATA: ··· 2075 2060 mlxbf_i2c_smbus_i2c_block_func(&request, &command, data->block, 2076 2061 &byte_cnt, read, pec); 2077 2062 dev_dbg(&adap->dev, "i2c %s block data, %d bytes at 0x%02x, slave 0x%02x.\n", 2078 - read ? "read" : "write", byte_cnt, command, addr); 2063 + str_read_write(read), byte_cnt, command, addr); 2079 2064 break; 2080 2065 2081 2066 case I2C_SMBUS_BLOCK_DATA: ··· 2083 2068 mlxbf_i2c_smbus_block_func(&request, &command, data->block, 2084 2069 &byte_cnt, read, pec); 2085 2070 dev_dbg(&adap->dev, "smbus %s block data, %d bytes at 0x%02x, slave 0x%02x.\n", 2086 - read ? "read" : "write", byte_cnt, command, addr); 2071 + str_read_write(read), byte_cnt, command, addr); 2087 2072 break; 2088 2073 2089 2074 case I2C_FUNC_SMBUS_PROC_CALL:
+9 -9
drivers/i2c/busses/i2c-npcm7xx.c
··· 1115 1115 #if IS_ENABLED(CONFIG_I2C_SLAVE) 1116 1116 static u8 npcm_i2c_get_slave_addr(struct npcm_i2c *bus, enum i2c_addr addr_type) 1117 1117 { 1118 - u8 slave_add; 1119 - 1120 1118 if (addr_type > I2C_SLAVE_ADDR2 && addr_type <= I2C_SLAVE_ADDR10) 1121 1119 dev_err(bus->dev, "get slave: try to use more than 2 SA not supported\n"); 1122 1120 1123 - slave_add = ioread8(bus->reg + npcm_i2caddr[(int)addr_type]); 1124 - 1125 - return slave_add; 1121 + return ioread8(bus->reg + npcm_i2caddr[addr_type]); 1126 1122 } 1127 1123 1128 1124 static int npcm_i2c_remove_slave_addr(struct npcm_i2c *bus, u8 slave_add) ··· 2174 2178 2175 2179 /* Check HW is OK: SDA and SCL should be high at this point. */ 2176 2180 if ((npcm_i2c_get_SDA(&bus->adap) == 0) || (npcm_i2c_get_SCL(&bus->adap) == 0)) { 2177 - dev_err(bus->dev, "I2C%d init fail: lines are low\n", bus->num); 2178 - dev_err(bus->dev, "SDA=%d SCL=%d\n", npcm_i2c_get_SDA(&bus->adap), 2179 - npcm_i2c_get_SCL(&bus->adap)); 2180 - return -ENXIO; 2181 + dev_warn(bus->dev, " I2C%d SDA=%d SCL=%d, attempting to recover\n", bus->num, 2182 + npcm_i2c_get_SDA(&bus->adap), npcm_i2c_get_SCL(&bus->adap)); 2183 + if (npcm_i2c_recovery_tgclk(&bus->adap)) { 2184 + dev_err(bus->dev, "I2C%d init fail: SDA=%d SCL=%d\n", 2185 + bus->num, npcm_i2c_get_SDA(&bus->adap), 2186 + npcm_i2c_get_SCL(&bus->adap)); 2187 + return -ENXIO; 2188 + } 2181 2189 } 2182 2190 2183 2191 npcm_i2c_int_enable(bus, true);
+160 -6
drivers/i2c/busses/i2c-octeon-core.c
··· 135 135 octeon_i2c_ctl_write(i2c, TWSI_CTL_ENAB); 136 136 } 137 137 138 + static void octeon_i2c_block_enable(struct octeon_i2c *i2c) 139 + { 140 + u64 mode; 141 + 142 + if (i2c->block_enabled || !OCTEON_REG_BLOCK_CTL(i2c)) 143 + return; 144 + 145 + i2c->block_enabled = true; 146 + mode = __raw_readq(i2c->twsi_base + OCTEON_REG_MODE(i2c)); 147 + mode |= TWSX_MODE_BLOCK_MODE; 148 + octeon_i2c_writeq_flush(mode, i2c->twsi_base + OCTEON_REG_MODE(i2c)); 149 + } 150 + 151 + static void octeon_i2c_block_disable(struct octeon_i2c *i2c) 152 + { 153 + u64 mode; 154 + 155 + if (!i2c->block_enabled || !OCTEON_REG_BLOCK_CTL(i2c)) 156 + return; 157 + 158 + i2c->block_enabled = false; 159 + mode = __raw_readq(i2c->twsi_base + OCTEON_REG_MODE(i2c)); 160 + mode &= ~TWSX_MODE_BLOCK_MODE; 161 + octeon_i2c_writeq_flush(mode, i2c->twsi_base + OCTEON_REG_MODE(i2c)); 162 + } 163 + 138 164 /** 139 165 * octeon_i2c_hlc_wait - wait for an HLC operation to complete 140 166 * @i2c: The struct octeon_i2c ··· 307 281 u8 stat; 308 282 309 283 octeon_i2c_hlc_disable(i2c); 284 + octeon_i2c_block_disable(i2c); 310 285 311 286 octeon_i2c_ctl_write(i2c, TWSI_CTL_ENAB | TWSI_CTL_STA); 312 287 ret = octeon_i2c_wait(i2c); ··· 632 605 } 633 606 634 607 /** 608 + * octeon_i2c_hlc_block_comp_read - high-level-controller composite block read 609 + * @i2c: The struct octeon_i2c 610 + * @msgs: msg[0] contains address, place read data into msg[1] 611 + * 612 + * i2c core command is constructed and written into the SW_TWSI register. 613 + * The execution of the command will result in requested data being 614 + * placed into a FIFO buffer, ready to be read. 615 + * Used in the case where the i2c xfer is for greater than 8 bytes of read data. 616 + * 617 + * Returns: 0 on success, otherwise a negative errno. 618 + */ 619 + static int octeon_i2c_hlc_block_comp_read(struct octeon_i2c *i2c, struct i2c_msg *msgs) 620 + { 621 + int ret; 622 + u16 len, i; 623 + u64 cmd; 624 + 625 + octeon_i2c_hlc_enable(i2c); 626 + octeon_i2c_block_enable(i2c); 627 + 628 + /* Write (size - 1) into block control register */ 629 + len = msgs[1].len - 1; 630 + octeon_i2c_writeq_flush((u64)len, i2c->twsi_base + OCTEON_REG_BLOCK_CTL(i2c)); 631 + 632 + /* Prepare core command */ 633 + cmd = SW_TWSI_V | SW_TWSI_R | SW_TWSI_SOVR | SW_TWSI_OP_7_IA; 634 + cmd |= (u64)(msgs[0].addr & 0x7full) << SW_TWSI_ADDR_SHIFT; 635 + 636 + /* Send core command */ 637 + ret = octeon_i2c_hlc_read_cmd(i2c, msgs[0], cmd); 638 + if (ret) 639 + goto err; 640 + 641 + cmd = __raw_readq(i2c->twsi_base + OCTEON_REG_SW_TWSI(i2c)); 642 + if ((cmd & SW_TWSI_R) == 0) { 643 + octeon_i2c_block_disable(i2c); 644 + return octeon_i2c_check_status(i2c, false); 645 + } 646 + 647 + /* read data in FIFO */ 648 + octeon_i2c_writeq_flush(TWSX_BLOCK_STS_RESET_PTR, 649 + i2c->twsi_base + OCTEON_REG_BLOCK_STS(i2c)); 650 + for (i = 0; i <= len; i += 8) { 651 + /* Byte-swap FIFO data and copy into msg buffer */ 652 + __be64 rd = cpu_to_be64(__raw_readq(i2c->twsi_base + OCTEON_REG_BLOCK_FIFO(i2c))); 653 + 654 + memcpy(&msgs[1].buf[i], &rd, min(8, msgs[1].len - i)); 655 + } 656 + 657 + err: 658 + octeon_i2c_block_disable(i2c); 659 + return ret; 660 + } 661 + 662 + /** 663 + * octeon_i2c_hlc_block_comp_write - high-level-controller composite block write 664 + * @i2c: The struct octeon_i2c 665 + * @msgs: msg[0] contains address, msg[1] contains data to be written 666 + * 667 + * i2c core command is constructed and write data is written into the FIFO buffer. 668 + * The execution of the command will result in HW write, using the data in FIFO. 669 + * Used in the case where the i2c xfer is for greater than 8 bytes of write data. 670 + * 671 + * Returns: 0 on success, otherwise a negative errno. 672 + */ 673 + static int octeon_i2c_hlc_block_comp_write(struct octeon_i2c *i2c, struct i2c_msg *msgs) 674 + { 675 + bool set_ext; 676 + int ret; 677 + u16 len, i; 678 + u64 cmd, ext = 0; 679 + 680 + octeon_i2c_hlc_enable(i2c); 681 + octeon_i2c_block_enable(i2c); 682 + 683 + /* Write (size - 1) into block control register */ 684 + len = msgs[1].len - 1; 685 + octeon_i2c_writeq_flush((u64)len, i2c->twsi_base + OCTEON_REG_BLOCK_CTL(i2c)); 686 + 687 + /* Prepare core command */ 688 + cmd = SW_TWSI_V | SW_TWSI_SOVR | SW_TWSI_OP_7_IA; 689 + cmd |= (u64)(msgs[0].addr & 0x7full) << SW_TWSI_ADDR_SHIFT; 690 + 691 + /* Set parameters for extended message (if required) */ 692 + set_ext = octeon_i2c_hlc_ext(i2c, msgs[0], &cmd, &ext); 693 + 694 + /* Write msg into FIFO buffer */ 695 + octeon_i2c_writeq_flush(TWSX_BLOCK_STS_RESET_PTR, 696 + i2c->twsi_base + OCTEON_REG_BLOCK_STS(i2c)); 697 + for (i = 0; i <= len; i += 8) { 698 + __be64 buf = 0; 699 + 700 + /* Copy 8 bytes or remaining bytes from message buffer */ 701 + memcpy(&buf, &msgs[1].buf[i], min(8, msgs[1].len - i)); 702 + 703 + /* Byte-swap message data and write into FIFO */ 704 + buf = cpu_to_be64(buf); 705 + octeon_i2c_writeq_flush((u64)buf, i2c->twsi_base + OCTEON_REG_BLOCK_FIFO(i2c)); 706 + } 707 + if (set_ext) 708 + octeon_i2c_writeq_flush(ext, i2c->twsi_base + OCTEON_REG_SW_TWSI_EXT(i2c)); 709 + 710 + /* Send command to core (send data in FIFO) */ 711 + ret = octeon_i2c_hlc_cmd_send(i2c, cmd); 712 + if (ret) 713 + goto err; 714 + 715 + cmd = __raw_readq(i2c->twsi_base + OCTEON_REG_SW_TWSI(i2c)); 716 + if ((cmd & SW_TWSI_R) == 0) { 717 + octeon_i2c_block_disable(i2c); 718 + return octeon_i2c_check_status(i2c, false); 719 + } 720 + 721 + err: 722 + octeon_i2c_block_disable(i2c); 723 + return ret; 724 + } 725 + 726 + /** 635 727 * octeon_i2c_xfer - The driver's xfer function 636 728 * @adap: Pointer to the i2c_adapter structure 637 729 * @msgs: Pointer to the messages to be processed ··· 776 630 if ((msgs[0].flags & I2C_M_RD) == 0 && 777 631 (msgs[1].flags & I2C_M_RECV_LEN) == 0 && 778 632 msgs[0].len > 0 && msgs[0].len <= 2 && 779 - msgs[1].len > 0 && msgs[1].len <= 8 && 633 + msgs[1].len > 0 && 780 634 msgs[0].addr == msgs[1].addr) { 781 - if (msgs[1].flags & I2C_M_RD) 782 - ret = octeon_i2c_hlc_comp_read(i2c, msgs); 783 - else 784 - ret = octeon_i2c_hlc_comp_write(i2c, msgs); 785 - goto out; 635 + if (msgs[1].len <= 8) { 636 + if (msgs[1].flags & I2C_M_RD) 637 + ret = octeon_i2c_hlc_comp_read(i2c, msgs); 638 + else 639 + ret = octeon_i2c_hlc_comp_write(i2c, msgs); 640 + goto out; 641 + } else if (msgs[1].len <= 1024 && OCTEON_REG_BLOCK_CTL(i2c)) { 642 + if (msgs[1].flags & I2C_M_RD) 643 + ret = octeon_i2c_hlc_block_comp_read(i2c, msgs); 644 + else 645 + ret = octeon_i2c_hlc_block_comp_write(i2c, msgs); 646 + goto out; 647 + } 786 648 } 787 649 } 788 650 }
+12 -1
drivers/i2c/busses/i2c-octeon-core.h
··· 96 96 unsigned int twsi_int; 97 97 unsigned int sw_twsi_ext; 98 98 unsigned int mode; 99 + unsigned int block_ctl; 100 + unsigned int block_sts; 101 + unsigned int block_fifo; 99 102 }; 100 103 101 104 #define OCTEON_REG_SW_TWSI(x) ((x)->roff.sw_twsi) 102 105 #define OCTEON_REG_TWSI_INT(x) ((x)->roff.twsi_int) 103 106 #define OCTEON_REG_SW_TWSI_EXT(x) ((x)->roff.sw_twsi_ext) 104 107 #define OCTEON_REG_MODE(x) ((x)->roff.mode) 108 + #define OCTEON_REG_BLOCK_CTL(x) ((x)->roff.block_ctl) 109 + #define OCTEON_REG_BLOCK_STS(x) ((x)->roff.block_sts) 110 + #define OCTEON_REG_BLOCK_FIFO(x) ((x)->roff.block_fifo) 105 111 106 - /* Set REFCLK_SRC and HS_MODE in TWSX_MODE register */ 112 + /* TWSX_MODE register */ 107 113 #define TWSX_MODE_REFCLK_SRC BIT(4) 114 + #define TWSX_MODE_BLOCK_MODE BIT(2) 108 115 #define TWSX_MODE_HS_MODE BIT(0) 109 116 #define TWSX_MODE_HS_MASK (TWSX_MODE_REFCLK_SRC | TWSX_MODE_HS_MODE) 117 + 118 + /* TWSX_BLOCK_STS register */ 119 + #define TWSX_BLOCK_STS_RESET_PTR BIT(0) 110 120 111 121 /* Set BUS_MON_RST to reset bus monitor */ 112 122 #define BUS_MON_RST_MASK BIT(3) ··· 133 123 void __iomem *twsi_base; 134 124 struct device *dev; 135 125 bool hlc_enabled; 126 + bool block_enabled; 136 127 bool broken_irq_mode; 137 128 bool broken_irq_check; 138 129 void (*int_enable)(struct octeon_i2c *);
+94 -25
drivers/i2c/busses/i2c-pasemi-core.c
··· 5 5 * SMBus host driver for PA Semi PWRficient 6 6 */ 7 7 8 - #include <linux/bitfield.h> 8 + #include <linux/bits.h> 9 + #include <linux/delay.h> 10 + #include <linux/i2c.h> 11 + #include <linux/io.h> 12 + #include <linux/iopoll.h> 13 + #include <linux/kernel.h> 9 14 #include <linux/module.h> 10 15 #include <linux/pci.h> 11 - #include <linux/kernel.h> 12 - #include <linux/stddef.h> 13 16 #include <linux/sched.h> 14 - #include <linux/i2c.h> 15 - #include <linux/delay.h> 16 17 #include <linux/slab.h> 17 - #include <linux/io.h> 18 + #include <linux/stddef.h> 18 19 19 20 #include "i2c-pasemi-core.h" 20 21 21 22 /* Register offsets */ 22 23 #define REG_MTXFIFO 0x00 23 24 #define REG_MRXFIFO 0x04 25 + #define REG_XFSTA 0x0c 24 26 #define REG_SMSTA 0x14 25 27 #define REG_IMASK 0x18 26 28 #define REG_CTL 0x1c ··· 54 52 #define CTL_UJM BIT(8) 55 53 #define CTL_CLK_M GENMASK(7, 0) 56 54 55 + /* 56 + * The hardware (supposedly) has a 25ms timeout for clock stretching, thus 57 + * use 100ms here which should be plenty. 58 + */ 59 + #define PASEMI_TRANSFER_TIMEOUT_MS 100 60 + 57 61 static inline void reg_write(struct pasemi_smbus *smbus, int reg, int val) 58 62 { 59 63 dev_dbg(smbus->dev, "smbus write reg %x val %08x\n", reg, val); ··· 79 71 80 72 static void pasemi_reset(struct pasemi_smbus *smbus) 81 73 { 82 - u32 val = (CTL_MTR | CTL_MRR | (smbus->clk_div & CTL_CLK_M)); 74 + u32 val = (CTL_MTR | CTL_MRR | CTL_UJM | (smbus->clk_div & CTL_CLK_M)); 83 75 84 76 if (smbus->hw_rev >= 6) 85 77 val |= CTL_EN; ··· 88 80 reinit_completion(&smbus->irq_completion); 89 81 } 90 82 91 - static void pasemi_smb_clear(struct pasemi_smbus *smbus) 83 + static int pasemi_smb_clear(struct pasemi_smbus *smbus) 92 84 { 93 85 unsigned int status; 86 + int ret; 94 87 95 - status = reg_read(smbus, REG_SMSTA); 88 + /* First wait for the bus to go idle */ 89 + ret = readx_poll_timeout(ioread32, smbus->ioaddr + REG_SMSTA, 90 + status, !(status & (SMSTA_XIP | SMSTA_JAM)), 91 + USEC_PER_MSEC, 92 + USEC_PER_MSEC * PASEMI_TRANSFER_TIMEOUT_MS); 93 + 94 + if (ret < 0) { 95 + dev_err(smbus->dev, "Bus is still stuck (status 0x%08x xfstatus 0x%08x)\n", 96 + status, reg_read(smbus, REG_XFSTA)); 97 + return -EIO; 98 + } 99 + 100 + /* If any badness happened or there is data in the FIFOs, reset the FIFOs */ 101 + if ((status & (SMSTA_MRNE | SMSTA_JMD | SMSTA_MTO | SMSTA_TOM | SMSTA_MTN | SMSTA_MTA)) || 102 + !(status & SMSTA_MTE)) { 103 + dev_warn(smbus->dev, "Issuing reset due to status 0x%08x (xfstatus 0x%08x)\n", 104 + status, reg_read(smbus, REG_XFSTA)); 105 + pasemi_reset(smbus); 106 + } 107 + 108 + /* Clear the flags */ 96 109 reg_write(smbus, REG_SMSTA, status); 110 + 111 + return 0; 97 112 } 98 113 99 114 static int pasemi_smb_waitready(struct pasemi_smbus *smbus) 100 115 { 101 - int timeout = 100; 102 116 unsigned int status; 103 117 104 118 if (smbus->use_irq) { 105 119 reinit_completion(&smbus->irq_completion); 106 120 reg_write(smbus, REG_IMASK, SMSTA_XEN | SMSTA_MTN); 107 - wait_for_completion_timeout(&smbus->irq_completion, msecs_to_jiffies(100)); 121 + int ret = wait_for_completion_timeout( 122 + &smbus->irq_completion, 123 + msecs_to_jiffies(PASEMI_TRANSFER_TIMEOUT_MS)); 108 124 reg_write(smbus, REG_IMASK, 0); 109 125 status = reg_read(smbus, REG_SMSTA); 126 + 127 + if (ret < 0) { 128 + dev_err(smbus->dev, 129 + "Completion wait failed with %d, status 0x%08x\n", 130 + ret, status); 131 + return ret; 132 + } else if (ret == 0) { 133 + dev_err(smbus->dev, "Timeout, status 0x%08x\n", status); 134 + return -ETIME; 135 + } 110 136 } else { 111 - status = reg_read(smbus, REG_SMSTA); 112 - while (!(status & SMSTA_XEN) && timeout--) { 113 - msleep(1); 114 - status = reg_read(smbus, REG_SMSTA); 137 + int ret = readx_poll_timeout( 138 + ioread32, smbus->ioaddr + REG_SMSTA, 139 + status, status & SMSTA_XEN, 140 + USEC_PER_MSEC, 141 + USEC_PER_MSEC * PASEMI_TRANSFER_TIMEOUT_MS); 142 + 143 + if (ret < 0) { 144 + dev_err(smbus->dev, "Timeout, status 0x%08x\n", status); 145 + return -ETIME; 115 146 } 116 147 } 117 148 118 - /* Got NACK? */ 119 - if (status & SMSTA_MTN) 120 - return -ENXIO; 149 + /* Controller timeout? */ 150 + if (status & SMSTA_TOM) { 151 + dev_err(smbus->dev, "Controller timeout, status 0x%08x\n", status); 152 + return -EIO; 153 + } 121 154 122 - if (timeout < 0) { 123 - dev_warn(smbus->dev, "Timeout, status 0x%08x\n", status); 124 - reg_write(smbus, REG_SMSTA, status); 155 + /* Peripheral timeout? */ 156 + if (status & SMSTA_MTO) { 157 + dev_err(smbus->dev, "Peripheral timeout, status 0x%08x\n", status); 125 158 return -ETIME; 159 + } 160 + 161 + /* Still stuck in a transaction? */ 162 + if (status & SMSTA_XIP) { 163 + dev_err(smbus->dev, "Bus stuck, status 0x%08x\n", status); 164 + return -EIO; 165 + } 166 + 167 + /* Arbitration loss? */ 168 + if (status & SMSTA_MTA) { 169 + dev_err(smbus->dev, "Arbitration loss, status 0x%08x\n", status); 170 + return -EBUSY; 171 + } 172 + 173 + /* Got NACK? */ 174 + if (status & SMSTA_MTN) { 175 + dev_err(smbus->dev, "NACK, status 0x%08x\n", status); 176 + return -ENXIO; 126 177 } 127 178 128 179 /* Clear XEN */ ··· 244 177 struct pasemi_smbus *smbus = adapter->algo_data; 245 178 int ret, i; 246 179 247 - pasemi_smb_clear(smbus); 248 - 249 - ret = 0; 180 + ret = pasemi_smb_clear(smbus); 181 + if (ret) 182 + return ret; 250 183 251 184 for (i = 0; i < num && !ret; i++) 252 185 ret = pasemi_i2c_xfer_msg(adapter, &msgs[i], (i == (num - 1))); ··· 267 200 addr <<= 1; 268 201 read_flag = read_write == I2C_SMBUS_READ; 269 202 270 - pasemi_smb_clear(smbus); 203 + err = pasemi_smb_clear(smbus); 204 + if (err) 205 + return err; 271 206 272 207 switch (size) { 273 208 case I2C_SMBUS_QUICK:
+5 -5
drivers/i2c/busses/i2c-pasemi-pci.c
··· 5 5 * SMBus host driver for PA Semi PWRficient 6 6 */ 7 7 8 + #include <linux/delay.h> 9 + #include <linux/i2c.h> 10 + #include <linux/io.h> 11 + #include <linux/kernel.h> 8 12 #include <linux/module.h> 9 13 #include <linux/pci.h> 10 - #include <linux/kernel.h> 11 - #include <linux/stddef.h> 12 14 #include <linux/sched.h> 13 - #include <linux/i2c.h> 14 - #include <linux/delay.h> 15 15 #include <linux/slab.h> 16 - #include <linux/io.h> 16 + #include <linux/stddef.h> 17 17 18 18 #include "i2c-pasemi-core.h" 19 19
+1 -1
drivers/i2c/busses/i2c-piix4.c
··· 971 971 * This would allow the ee1004 to be probed incorrectly. 972 972 */ 973 973 if (port == 0) 974 - i2c_register_spd(adap); 974 + i2c_register_spd_write_enable(adap); 975 975 976 976 *padap = adap; 977 977 return 0;
+1 -1
drivers/i2c/busses/i2c-powermac.c
··· 349 349 /* Fill out the rest of the info structure */ 350 350 info.addr = addr; 351 351 info.irq = irq_of_parse_and_map(node, 0); 352 - info.of_node = of_node_get(node); 352 + info.fwnode = of_fwnode_handle(of_node_get(node)); 353 353 354 354 newdev = i2c_new_client_device(adap, &info); 355 355 if (IS_ERR(newdev)) {
+9 -10
drivers/i2c/busses/i2c-qcom-geni.c
··· 71 71 << 5) 72 72 73 73 #define I2C_AUTO_SUSPEND_DELAY 250 74 - #define KHZ(freq) (1000 * freq) 75 74 #define PACKING_BYTES_PW 4 76 75 77 76 #define ABORT_TIMEOUT HZ ··· 147 148 * source_clock = 19.2 MHz 148 149 */ 149 150 static const struct geni_i2c_clk_fld geni_i2c_clk_map_19p2mhz[] = { 150 - {KHZ(100), 7, 10, 12, 26}, 151 - {KHZ(400), 2, 5, 11, 22}, 152 - {KHZ(1000), 1, 2, 8, 18}, 153 - {}, 151 + { I2C_MAX_STANDARD_MODE_FREQ, 7, 10, 12, 26 }, 152 + { I2C_MAX_FAST_MODE_FREQ, 2, 5, 11, 22 }, 153 + { I2C_MAX_FAST_MODE_PLUS_FREQ, 1, 2, 8, 18 }, 154 + {} 154 155 }; 155 156 156 157 /* source_clock = 32 MHz */ 157 158 static const struct geni_i2c_clk_fld geni_i2c_clk_map_32mhz[] = { 158 - {KHZ(100), 8, 14, 18, 40}, 159 - {KHZ(400), 4, 3, 11, 20}, 160 - {KHZ(1000), 2, 3, 6, 15}, 161 - {}, 159 + { I2C_MAX_STANDARD_MODE_FREQ, 8, 14, 18, 40 }, 160 + { I2C_MAX_FAST_MODE_FREQ, 4, 3, 11, 20 }, 161 + { I2C_MAX_FAST_MODE_PLUS_FREQ, 2, 3, 6, 15 }, 162 + {} 162 163 }; 163 164 164 165 static int geni_i2c_clk_map_idx(struct geni_i2c_dev *gi2c) ··· 811 812 &gi2c->clk_freq_out); 812 813 if (ret) { 813 814 dev_info(dev, "Bus frequency not specified, default to 100kHz.\n"); 814 - gi2c->clk_freq_out = KHZ(100); 815 + gi2c->clk_freq_out = I2C_MAX_STANDARD_MODE_FREQ; 815 816 } 816 817 817 818 if (has_acpi_companion(dev))
+51 -2
drivers/i2c/busses/i2c-riic.c
··· 52 52 #define ICCR1_ICE BIT(7) 53 53 #define ICCR1_IICRST BIT(6) 54 54 #define ICCR1_SOWP BIT(4) 55 + #define ICCR1_SCLO BIT(3) 56 + #define ICCR1_SDAO BIT(2) 55 57 #define ICCR1_SCLI BIT(1) 56 58 #define ICCR1_SDAI BIT(0) 57 59 ··· 153 151 ret = readb_poll_timeout(riic->base + riic->info->regs[RIIC_ICCR2], val, 154 152 !(val & ICCR2_BBSY), 10, riic->adapter.timeout); 155 153 if (ret) 156 - return ret; 154 + return i2c_recover_bus(&riic->adapter); 157 155 158 156 if ((riic_readb(riic, RIIC_ICCR1) & (ICCR1_SDAI | ICCR1_SCLI)) != 159 157 (ICCR1_SDAI | ICCR1_SCLI)) 160 - return -EBUSY; 158 + return i2c_recover_bus(&riic->adapter); 161 159 162 160 return 0; 163 161 } ··· 441 439 return 0; 442 440 } 443 441 442 + static int riic_get_scl(struct i2c_adapter *adap) 443 + { 444 + struct riic_dev *riic = i2c_get_adapdata(adap); 445 + 446 + return !!(riic_readb(riic, RIIC_ICCR1) & ICCR1_SCLI); 447 + } 448 + 449 + static int riic_get_sda(struct i2c_adapter *adap) 450 + { 451 + struct riic_dev *riic = i2c_get_adapdata(adap); 452 + 453 + return !!(riic_readb(riic, RIIC_ICCR1) & ICCR1_SDAI); 454 + } 455 + 456 + static void riic_set_scl(struct i2c_adapter *adap, int val) 457 + { 458 + struct riic_dev *riic = i2c_get_adapdata(adap); 459 + 460 + if (val) 461 + riic_clear_set_bit(riic, ICCR1_SOWP, ICCR1_SCLO, RIIC_ICCR1); 462 + else 463 + riic_clear_set_bit(riic, ICCR1_SOWP | ICCR1_SCLO, 0, RIIC_ICCR1); 464 + 465 + riic_clear_set_bit(riic, 0, ICCR1_SOWP, RIIC_ICCR1); 466 + } 467 + 468 + static void riic_set_sda(struct i2c_adapter *adap, int val) 469 + { 470 + struct riic_dev *riic = i2c_get_adapdata(adap); 471 + 472 + if (val) 473 + riic_clear_set_bit(riic, ICCR1_SOWP, ICCR1_SDAO, RIIC_ICCR1); 474 + else 475 + riic_clear_set_bit(riic, ICCR1_SOWP | ICCR1_SDAO, 0, RIIC_ICCR1); 476 + 477 + riic_clear_set_bit(riic, 0, ICCR1_SOWP, RIIC_ICCR1); 478 + } 479 + 480 + static struct i2c_bus_recovery_info riic_bri = { 481 + .recover_bus = i2c_generic_scl_recovery, 482 + .get_scl = riic_get_scl, 483 + .set_scl = riic_set_scl, 484 + .get_sda = riic_get_sda, 485 + .set_sda = riic_set_sda, 486 + }; 487 + 444 488 static const struct riic_irq_desc riic_irqs[] = { 445 489 { .res_num = 0, .isr = riic_tend_isr, .name = "riic-tend" }, 446 490 { .res_num = 1, .isr = riic_rdrf_isr, .name = "riic-rdrf" }, ··· 543 495 adap->algo = &riic_algo; 544 496 adap->dev.parent = dev; 545 497 adap->dev.of_node = dev->of_node; 498 + adap->bus_recovery_info = &riic_bri; 546 499 547 500 init_completion(&riic->msg_done); 548 501
+1 -1
drivers/i2c/busses/i2c-rzv2m.c
··· 402 402 .flags = I2C_AQ_NO_ZERO_LEN, 403 403 }; 404 404 405 - static struct i2c_algorithm rzv2m_i2c_algo = { 405 + static const struct i2c_algorithm rzv2m_i2c_algo = { 406 406 .xfer = rzv2m_i2c_xfer, 407 407 .functionality = rzv2m_i2c_func, 408 408 };
+2 -1
drivers/i2c/busses/i2c-sh_mobile.c
··· 24 24 #include <linux/platform_device.h> 25 25 #include <linux/pm_runtime.h> 26 26 #include <linux/slab.h> 27 + #include <linux/string_choices.h> 27 28 28 29 /* Transmit operation: */ 29 30 /* */ ··· 410 409 pd->sr |= sr; /* remember state */ 411 410 412 411 dev_dbg(pd->dev, "i2c_isr 0x%02x 0x%02x %s %d %d!\n", sr, pd->sr, 413 - (pd->msg->flags & I2C_M_RD) ? "read" : "write", 412 + str_read_write(pd->msg->flags & I2C_M_RD), 414 413 pd->pos, pd->msg->len); 415 414 416 415 /* Kick off TxDMA after preface was done */
+5
drivers/i2c/busses/i2c-tegra.c
··· 1395 1395 ret = tegra_i2c_xfer_msg(i2c_dev, &msgs[i], MSG_END_CONTINUE); 1396 1396 if (ret) 1397 1397 break; 1398 + 1399 + /* Validate message length before proceeding */ 1400 + if (msgs[i].buf[0] == 0 || msgs[i].buf[0] > I2C_SMBUS_BLOCK_MAX) 1401 + break; 1402 + 1398 1403 /* Set the msg length from first byte */ 1399 1404 msgs[i].len += msgs[i].buf[0]; 1400 1405 dev_dbg(i2c_dev->dev, "reading %d bytes\n", msgs[i].len);
+4 -1
drivers/i2c/busses/i2c-thunderx-pcidrv.c
··· 168 168 i2c->roff.twsi_int = 0x1010; 169 169 i2c->roff.sw_twsi_ext = 0x1018; 170 170 i2c->roff.mode = 0x1038; 171 + i2c->roff.block_ctl = 0x1048; 172 + i2c->roff.block_sts = 0x1050; 173 + i2c->roff.block_fifo = 0x1058; 171 174 172 175 i2c->dev = dev; 173 176 pci_set_drvdata(pdev, i2c); ··· 178 175 if (ret) 179 176 return ret; 180 177 181 - ret = pci_request_regions(pdev, DRV_NAME); 178 + ret = pcim_request_all_regions(pdev, DRV_NAME); 182 179 if (ret) 183 180 return ret; 184 181
+2 -1
drivers/i2c/busses/i2c-tiny-usb.c
··· 10 10 #include <linux/errno.h> 11 11 #include <linux/module.h> 12 12 #include <linux/slab.h> 13 + #include <linux/string_choices.h> 13 14 #include <linux/types.h> 14 15 15 16 /* include interfaces to usb layer */ ··· 72 71 73 72 dev_dbg(&adapter->dev, 74 73 " %d: %s (flags %d) %d bytes to 0x%02x\n", 75 - i, pmsg->flags & I2C_M_RD ? "read" : "write", 74 + i, str_read_write(pmsg->flags & I2C_M_RD), 76 75 pmsg->flags, pmsg->len, pmsg->addr); 77 76 78 77 /* and directly send the message */
+8 -16
drivers/i2c/busses/i2c-uniphier-f.c
··· 532 532 if (of_property_read_u32(dev->of_node, "clock-frequency", &bus_speed)) 533 533 bus_speed = I2C_MAX_STANDARD_MODE_FREQ; 534 534 535 - if (!bus_speed || bus_speed > I2C_MAX_FAST_MODE_FREQ) { 536 - dev_err(dev, "invalid clock-frequency %d\n", bus_speed); 537 - return -EINVAL; 538 - } 535 + if (!bus_speed || bus_speed > I2C_MAX_FAST_MODE_FREQ) 536 + return dev_err_probe(dev, -EINVAL, "invalid clock-frequency %d\n", bus_speed); 539 537 540 538 priv->clk = devm_clk_get_enabled(dev, NULL); 541 - if (IS_ERR(priv->clk)) { 542 - dev_err(dev, "failed to enable clock\n"); 543 - return PTR_ERR(priv->clk); 544 - } 539 + if (IS_ERR(priv->clk)) 540 + return dev_err_probe(dev, PTR_ERR(priv->clk), "failed to enable clock\n"); 545 541 546 542 clk_rate = clk_get_rate(priv->clk); 547 - if (!clk_rate) { 548 - dev_err(dev, "input clock rate should not be zero\n"); 549 - return -EINVAL; 550 - } 543 + if (!clk_rate) 544 + return dev_err_probe(dev, -EINVAL, "input clock rate should not be zero\n"); 551 545 552 546 priv->clk_cycle = clk_rate / bus_speed; 553 547 init_completion(&priv->comp); ··· 559 565 560 566 ret = devm_request_irq(dev, irq, uniphier_fi2c_interrupt, 0, 561 567 pdev->name, priv); 562 - if (ret) { 563 - dev_err(dev, "failed to request irq %d\n", irq); 564 - return ret; 565 - } 568 + if (ret) 569 + return dev_err_probe(dev, ret, "failed to request irq %d\n", irq); 566 570 567 571 return i2c_add_adapter(&priv->adap); 568 572 }
+8 -16
drivers/i2c/busses/i2c-uniphier.c
··· 327 327 if (of_property_read_u32(dev->of_node, "clock-frequency", &bus_speed)) 328 328 bus_speed = I2C_MAX_STANDARD_MODE_FREQ; 329 329 330 - if (!bus_speed || bus_speed > I2C_MAX_FAST_MODE_FREQ) { 331 - dev_err(dev, "invalid clock-frequency %d\n", bus_speed); 332 - return -EINVAL; 333 - } 330 + if (!bus_speed || bus_speed > I2C_MAX_FAST_MODE_FREQ) 331 + return dev_err_probe(dev, -EINVAL, "invalid clock-frequency %d\n", bus_speed); 334 332 335 333 priv->clk = devm_clk_get_enabled(dev, NULL); 336 - if (IS_ERR(priv->clk)) { 337 - dev_err(dev, "failed to enable clock\n"); 338 - return PTR_ERR(priv->clk); 339 - } 334 + if (IS_ERR(priv->clk)) 335 + return dev_err_probe(dev, PTR_ERR(priv->clk), "failed to enable clock\n"); 340 336 341 337 clk_rate = clk_get_rate(priv->clk); 342 - if (!clk_rate) { 343 - dev_err(dev, "input clock rate should not be zero\n"); 344 - return -EINVAL; 345 - } 338 + if (!clk_rate) 339 + return dev_err_probe(dev, -EINVAL, "input clock rate should not be zero\n"); 346 340 347 341 priv->clk_cycle = clk_rate / bus_speed; 348 342 init_completion(&priv->comp); ··· 353 359 354 360 ret = devm_request_irq(dev, irq, uniphier_i2c_interrupt, 0, pdev->name, 355 361 priv); 356 - if (ret) { 357 - dev_err(dev, "failed to request irq %d\n", irq); 358 - return ret; 359 - } 362 + if (ret) 363 + return dev_err_probe(dev, ret, "failed to request irq %d\n", irq); 360 364 361 365 return i2c_add_adapter(&priv->adap); 362 366 }
+7 -8
drivers/i2c/busses/i2c-via.c
··· 89 89 u8 rev; 90 90 int res; 91 91 92 - if (pm_io_base) { 93 - dev_err(&dev->dev, "i2c-via: Will only support one host\n"); 94 - return -ENODEV; 95 - } 92 + if (pm_io_base) 93 + return dev_err_probe(&dev->dev, -ENODEV, 94 + "Will only support one host\n"); 96 95 97 96 pci_read_config_byte(dev, PM_CFG_REVID, &rev); 98 97 ··· 112 113 pci_read_config_word(dev, base, &pm_io_base); 113 114 pm_io_base &= (0xff << 8); 114 115 115 - if (!request_region(I2C_DIR, IOSPACE, vt586b_driver.name)) { 116 - dev_err(&dev->dev, "IO 0x%x-0x%x already in use\n", I2C_DIR, I2C_DIR + IOSPACE); 117 - return -ENODEV; 118 - } 116 + if (!request_region(I2C_DIR, IOSPACE, vt586b_driver.name)) 117 + return dev_err_probe(&dev->dev, -ENODEV, 118 + "IO 0x%x-0x%x already in use\n", 119 + I2C_DIR, I2C_DIR + IOSPACE); 119 120 120 121 outb(inb(I2C_DIR) & ~(I2C_SDA | I2C_SCL), I2C_DIR); 121 122 outb(inb(I2C_OUT) & ~(I2C_SDA | I2C_SCL), I2C_OUT);
+7 -13
drivers/i2c/busses/i2c-viai2c-wmt.c
··· 44 44 int err; 45 45 46 46 err = clk_prepare_enable(i2c->clk); 47 - if (err) { 48 - dev_err(i2c->dev, "failed to enable clock\n"); 49 - return err; 50 - } 47 + if (err) 48 + return dev_err_probe(i2c->dev, err, "failed to enable clock\n"); 51 49 52 50 err = clk_set_rate(i2c->clk, 20000000); 53 51 if (err) { 54 - dev_err(i2c->dev, "failed to set clock = 20Mhz\n"); 55 52 clk_disable_unprepare(i2c->clk); 56 - return err; 53 + return dev_err_probe(i2c->dev, err, "failed to set clock = 20Mhz\n"); 57 54 } 58 55 59 56 writew(0, i2c->base + VIAI2C_REG_CR); ··· 118 121 "failed to request irq %i\n", i2c->irq); 119 122 120 123 i2c->clk = of_clk_get(np, 0); 121 - if (IS_ERR(i2c->clk)) { 122 - dev_err(&pdev->dev, "unable to request clock\n"); 123 - return PTR_ERR(i2c->clk); 124 - } 124 + if (IS_ERR(i2c->clk)) 125 + return dev_err_probe(&pdev->dev, PTR_ERR(i2c->clk), 126 + "unable to request clock\n"); 125 127 126 128 err = of_property_read_u32(np, "clock-frequency", &clk_rate); 127 129 if (!err && clk_rate == I2C_MAX_FAST_MODE_FREQ) ··· 135 139 adap->dev.of_node = pdev->dev.of_node; 136 140 137 141 err = wmt_i2c_reset_hardware(i2c); 138 - if (err) { 139 - dev_err(&pdev->dev, "error initializing hardware\n"); 142 + if (err) 140 143 return err; 141 - } 142 144 143 145 err = i2c_add_adapter(adap); 144 146 if (err)
+15 -18
drivers/i2c/busses/i2c-viapro.c
··· 330 330 SMBHSTCFG = 0x84; 331 331 } else { 332 332 /* no matches at all */ 333 - dev_err(&pdev->dev, "Cannot configure " 334 - "SMBus I/O Base address\n"); 335 - return -ENODEV; 333 + return dev_err_probe(&pdev->dev, -ENODEV, 334 + "Cannot configure " 335 + "SMBus I/O Base address\n"); 336 336 } 337 337 } 338 338 339 339 vt596_smba &= 0xfff0; 340 - if (vt596_smba == 0) { 341 - dev_err(&pdev->dev, "SMBus base address " 342 - "uninitialized - upgrade BIOS or use " 343 - "force_addr=0xaddr\n"); 344 - return -ENODEV; 345 - } 340 + if (vt596_smba == 0) 341 + return dev_err_probe(&pdev->dev, -ENODEV, "SMBus base address " 342 + "uninitialized - upgrade BIOS or use " 343 + "force_addr=0xaddr\n"); 346 344 347 345 found: 348 346 error = acpi_check_region(vt596_smba, 8, vt596_driver.name); 349 347 if (error) 350 348 return -ENODEV; 351 349 352 - if (!request_region(vt596_smba, 8, vt596_driver.name)) { 353 - dev_err(&pdev->dev, "SMBus region 0x%x already in use!\n", 354 - vt596_smba); 355 - return -ENODEV; 356 - } 350 + if (!request_region(vt596_smba, 8, vt596_driver.name)) 351 + return dev_err_probe(&pdev->dev, -ENODEV, 352 + "SMBus region 0x%x already in use!\n", 353 + vt596_smba); 357 354 358 355 pci_read_config_byte(pdev, SMBHSTCFG, &temp); 359 356 /* If force_addr is set, we program the new address here. Just to make ··· 372 375 pci_write_config_byte(pdev, SMBHSTCFG, temp | 0x01); 373 376 dev_info(&pdev->dev, "Enabling SMBus device\n"); 374 377 } else { 375 - dev_err(&pdev->dev, "SMBUS: Error: Host SMBus " 376 - "controller not enabled! - upgrade BIOS or " 377 - "use force=1\n"); 378 - error = -ENODEV; 378 + error = dev_err_probe(&pdev->dev, -ENODEV, 379 + "SMBUS: Error: Host SMBus " 380 + "controller not enabled! - " 381 + "upgrade BIOS or use force=1\n"); 379 382 goto release_region; 380 383 } 381 384 }
+8 -9
drivers/i2c/busses/i2c-viperboard.c
··· 11 11 #include <linux/errno.h> 12 12 #include <linux/module.h> 13 13 #include <linux/slab.h> 14 + #include <linux/string_choices.h> 14 15 #include <linux/types.h> 15 16 #include <linux/mutex.h> 16 17 #include <linux/platform_device.h> ··· 279 278 280 279 dev_dbg(&i2c->dev, 281 280 " %d: %s (flags %d) %d bytes to 0x%02x\n", 282 - i, pmsg->flags & I2C_M_RD ? "read" : "write", 281 + i, str_read_write(pmsg->flags & I2C_M_RD), 283 282 pmsg->flags, pmsg->len, pmsg->addr); 284 283 285 284 mutex_lock(&vb->lock); ··· 385 384 VPRBRD_USB_REQUEST_I2C_FREQ, VPRBRD_USB_TYPE_OUT, 386 385 0x0000, 0x0000, &vb_i2c->bus_freq_param, 1, 387 386 VPRBRD_USB_TIMEOUT_MS); 388 - if (ret != 1) { 389 - dev_err(&pdev->dev, "failure setting i2c_bus_freq to %d\n", 390 - i2c_bus_freq); 391 - return -EIO; 392 - } 387 + if (ret != 1) 388 + return dev_err_probe(&pdev->dev, -EIO, 389 + "failure setting i2c_bus_freq to %d\n", 390 + i2c_bus_freq); 393 391 } else { 394 - dev_err(&pdev->dev, 395 - "invalid i2c_bus_freq setting:%d\n", i2c_bus_freq); 396 - return -EIO; 392 + return dev_err_probe(&pdev->dev, -EIO, 393 + "invalid i2c_bus_freq setting:%d\n", i2c_bus_freq); 397 394 } 398 395 399 396 vb_i2c->i2c.dev.parent = &pdev->dev;
+3 -4
drivers/i2c/busses/i2c-virtio.c
··· 192 192 struct virtio_i2c *vi; 193 193 int ret; 194 194 195 - if (!virtio_has_feature(vdev, VIRTIO_I2C_F_ZERO_LENGTH_REQUEST)) { 196 - dev_err(&vdev->dev, "Zero-length request feature is mandatory\n"); 197 - return -EINVAL; 198 - } 195 + if (!virtio_has_feature(vdev, VIRTIO_I2C_F_ZERO_LENGTH_REQUEST)) 196 + return dev_err_probe(&vdev->dev, -EINVAL, 197 + "Zero-length request feature is mandatory\n"); 199 198 200 199 vi = devm_kzalloc(&vdev->dev, sizeof(*vi), GFP_KERNEL); 201 200 if (!vi)
+12 -45
drivers/i2c/busses/i2c-xgene-slimpro.c
··· 101 101 struct completion rd_complete; 102 102 u8 dma_buffer[I2C_SMBUS_BLOCK_MAX + 1]; /* dma_buffer[0] is used for length */ 103 103 u32 *resp_msg; 104 - phys_addr_t comm_base_addr; 105 - void *pcc_comm_addr; 106 104 }; 107 105 108 106 #define to_slimpro_i2c_dev(cl) \ ··· 146 148 static void slimpro_i2c_pcc_rx_cb(struct mbox_client *cl, void *msg) 147 149 { 148 150 struct slimpro_i2c_dev *ctx = to_slimpro_i2c_dev(cl); 149 - struct acpi_pcct_shared_memory *generic_comm_base = ctx->pcc_comm_addr; 151 + struct acpi_pcct_shared_memory __iomem *generic_comm_base = 152 + ctx->pcc_chan->shmem; 150 153 151 154 /* Check if platform sends interrupt */ 152 155 if (!xgene_word_tst_and_clr(&generic_comm_base->status, ··· 168 169 169 170 static void slimpro_i2c_pcc_tx_prepare(struct slimpro_i2c_dev *ctx, u32 *msg) 170 171 { 171 - struct acpi_pcct_shared_memory *generic_comm_base = ctx->pcc_comm_addr; 172 + struct acpi_pcct_shared_memory __iomem *generic_comm_base = 173 + ctx->pcc_chan->shmem; 172 174 u32 *ptr = (void *)(generic_comm_base + 1); 173 175 u16 status; 174 176 int i; ··· 457 457 cl->tx_block = true; 458 458 cl->rx_callback = slimpro_i2c_rx_cb; 459 459 ctx->mbox_chan = mbox_request_channel(cl, MAILBOX_I2C_INDEX); 460 - if (IS_ERR(ctx->mbox_chan)) { 461 - dev_err(&pdev->dev, "i2c mailbox channel request failed\n"); 462 - return PTR_ERR(ctx->mbox_chan); 463 - } 460 + if (IS_ERR(ctx->mbox_chan)) 461 + return dev_err_probe(&pdev->dev, PTR_ERR(ctx->mbox_chan), 462 + "i2c mailbox channel request failed\n"); 464 463 } else { 465 464 struct pcc_mbox_chan *pcc_chan; 466 465 const struct acpi_device_id *acpi_id; 467 - int version = XGENE_SLIMPRO_I2C_V1; 468 466 469 467 acpi_id = acpi_match_device(pdev->dev.driver->acpi_match_table, 470 468 &pdev->dev); 471 469 if (!acpi_id) 472 470 return -EINVAL; 473 - 474 - version = (int)acpi_id->driver_data; 475 471 476 472 if (device_property_read_u32(&pdev->dev, "pcc-channel", 477 473 &ctx->mbox_idx)) ··· 476 480 cl->tx_block = false; 477 481 cl->rx_callback = slimpro_i2c_pcc_rx_cb; 478 482 pcc_chan = pcc_mbox_request_channel(cl, ctx->mbox_idx); 479 - if (IS_ERR(pcc_chan)) { 480 - dev_err(&pdev->dev, "PCC mailbox channel request failed\n"); 481 - return PTR_ERR(pcc_chan); 482 - } 483 + if (IS_ERR(pcc_chan)) 484 + return dev_err_probe(&pdev->dev, PTR_ERR(pcc_chan), 485 + "PCC mailbox channel request failed\n"); 483 486 484 487 ctx->pcc_chan = pcc_chan; 485 488 ctx->mbox_chan = pcc_chan->mchan; 486 489 487 490 if (!ctx->mbox_chan->mbox->txdone_irq) { 488 - dev_err(&pdev->dev, "PCC IRQ not supported\n"); 489 - rc = -ENOENT; 491 + rc = dev_err_probe(&pdev->dev, -ENOENT, 492 + "PCC IRQ not supported\n"); 490 493 goto mbox_err; 491 494 } 492 495 493 - /* 494 - * This is the shared communication region 495 - * for the OS and Platform to communicate over. 496 - */ 497 - ctx->comm_base_addr = pcc_chan->shmem_base_addr; 498 - if (ctx->comm_base_addr) { 499 - if (version == XGENE_SLIMPRO_I2C_V2) 500 - ctx->pcc_comm_addr = memremap( 501 - ctx->comm_base_addr, 502 - pcc_chan->shmem_size, 503 - MEMREMAP_WT); 504 - else 505 - ctx->pcc_comm_addr = memremap( 506 - ctx->comm_base_addr, 507 - pcc_chan->shmem_size, 508 - MEMREMAP_WB); 509 - } else { 510 - dev_err(&pdev->dev, "Failed to get PCC comm region\n"); 511 - rc = -ENOENT; 512 - goto mbox_err; 513 - } 514 - 515 - if (!ctx->pcc_comm_addr) { 516 - dev_err(&pdev->dev, 517 - "Failed to ioremap PCC comm region\n"); 518 - rc = -ENOMEM; 519 - goto mbox_err; 520 - } 521 496 } 522 497 rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); 523 498 if (rc)
+2 -2
drivers/i2c/busses/i2c-xiic.c
··· 1489 1489 pdev->name, i2c); 1490 1490 1491 1491 if (ret < 0) { 1492 - dev_err(&pdev->dev, "Cannot claim IRQ\n"); 1492 + dev_err_probe(&pdev->dev, ret, "Cannot claim IRQ\n"); 1493 1493 goto err_pm_disable; 1494 1494 } 1495 1495 ··· 1510 1510 1511 1511 ret = xiic_reinit(i2c); 1512 1512 if (ret < 0) { 1513 - dev_err(&pdev->dev, "Cannot xiic_reinit\n"); 1513 + dev_err_probe(&pdev->dev, ret, "Cannot xiic_reinit\n"); 1514 1514 goto err_pm_disable; 1515 1515 } 1516 1516
+2 -4
drivers/i2c/busses/scx200_acb.c
··· 500 500 struct resource *res; 501 501 502 502 res = platform_get_resource(pdev, IORESOURCE_IO, 0); 503 - if (!res) { 504 - dev_err(&pdev->dev, "can't fetch device resource info\n"); 505 - return -ENODEV; 506 - } 503 + if (!res) 504 + return dev_err_probe(&pdev->dev, -ENODEV, "can't fetch device resource info\n"); 507 505 508 506 iface = scx200_create_dev("CS5535", res->start, 0, &pdev->dev); 509 507 if (!iface)
+409 -165
drivers/i2c/i2c-atr.c
··· 16 16 #include <linux/property.h> 17 17 #include <linux/slab.h> 18 18 #include <linux/spinlock.h> 19 + #include <linux/lockdep.h> 19 20 20 21 #define ATR_MAX_ADAPTERS 100 /* Just a sanity limit */ 21 22 #define ATR_MAX_SYMLINK_LEN 11 /* Longest name is 10 chars: "channel-99" */ 22 23 23 24 /** 24 - * struct i2c_atr_alias_pair - Holds the alias assigned to a client. 25 + * struct i2c_atr_alias_pair - Holds the alias assigned to a client address. 25 26 * @node: List node 26 - * @client: Pointer to the client on the child bus 27 + * @addr: Address of the client on the child bus. 27 28 * @alias: I2C alias address assigned by the driver. 28 29 * This is the address that will be used to issue I2C transactions 29 30 * on the parent (physical) bus. 31 + * @fixed: Alias pair cannot be replaced during dynamic address attachment. 32 + * This flag is necessary for situations where a single I2C transaction 33 + * contains more distinct target addresses than the ATR channel can handle. 34 + * It marks addresses that have already been attached to an alias so 35 + * that their alias pair is not evicted by a subsequent address in the same 36 + * transaction. 37 + * 30 38 */ 31 39 struct i2c_atr_alias_pair { 32 40 struct list_head node; 33 - const struct i2c_client *client; 41 + bool fixed; 42 + u16 addr; 34 43 u16 alias; 44 + }; 45 + 46 + /** 47 + * struct i2c_atr_alias_pool - Pool of client aliases available for an ATR. 48 + * @size: Total number of aliases 49 + * @shared: Indicates if this alias pool is shared by multiple channels 50 + * 51 + * @lock: Lock protecting @aliases and @use_mask 52 + * @aliases: Array of aliases, must hold exactly @size elements 53 + * @use_mask: Mask of used aliases 54 + */ 55 + struct i2c_atr_alias_pool { 56 + size_t size; 57 + bool shared; 58 + 59 + /* Protects aliases and use_mask */ 60 + spinlock_t lock; 61 + u16 *aliases; 62 + unsigned long *use_mask; 35 63 }; 36 64 37 65 /** ··· 67 39 * @adap: The &struct i2c_adapter for the channel 68 40 * @atr: The parent I2C ATR 69 41 * @chan_id: The ID of this channel 70 - * @alias_list: List of @struct i2c_atr_alias_pair containing the 42 + * @alias_pairs_lock: Mutex protecting @alias_pairs 43 + * @alias_pairs_lock_key: Lock key for @alias_pairs_lock 44 + * @alias_pairs: List of @struct i2c_atr_alias_pair containing the 71 45 * assigned aliases 46 + * @alias_pool: Pool of available client aliases 47 + * 72 48 * @orig_addrs_lock: Mutex protecting @orig_addrs 49 + * @orig_addrs_lock_key: Lock key for @orig_addrs_lock 73 50 * @orig_addrs: Buffer used to store the original addresses during transmit 74 51 * @orig_addrs_size: Size of @orig_addrs 75 52 */ ··· 83 50 struct i2c_atr *atr; 84 51 u32 chan_id; 85 52 86 - struct list_head alias_list; 53 + /* Lock alias_pairs during attach/detach */ 54 + struct mutex alias_pairs_lock; 55 + struct lock_class_key alias_pairs_lock_key; 56 + struct list_head alias_pairs; 57 + struct i2c_atr_alias_pool *alias_pool; 87 58 88 59 /* Lock orig_addrs during xfer */ 89 60 struct mutex orig_addrs_lock; 61 + struct lock_class_key orig_addrs_lock_key; 90 62 u16 *orig_addrs; 91 63 unsigned int orig_addrs_size; 92 64 }; ··· 104 66 * @priv: Private driver data, set with i2c_atr_set_driver_data() 105 67 * @algo: The &struct i2c_algorithm for adapters 106 68 * @lock: Lock for the I2C bus segment (see &struct i2c_lock_operations) 69 + * @lock_key: Lock key for @lock 107 70 * @max_adapters: Maximum number of adapters this I2C ATR can have 108 - * @num_aliases: Number of aliases in the aliases array 109 - * @aliases: The aliases array 110 - * @alias_mask_lock: Lock protecting alias_use_mask 111 - * @alias_use_mask: Bitmask for used aliases in aliases array 71 + * @flags: Flags for ATR 72 + * @alias_pool: Optional common pool of available client aliases 112 73 * @i2c_nb: Notifier for remote client add & del events 113 74 * @adapter: Array of adapters 114 75 */ ··· 121 84 struct i2c_algorithm algo; 122 85 /* lock for the I2C bus segment (see struct i2c_lock_operations) */ 123 86 struct mutex lock; 87 + struct lock_class_key lock_key; 124 88 int max_adapters; 89 + u32 flags; 125 90 126 - size_t num_aliases; 127 - const u16 *aliases; 128 - /* Protects alias_use_mask */ 129 - spinlock_t alias_mask_lock; 130 - unsigned long *alias_use_mask; 91 + struct i2c_atr_alias_pool *alias_pool; 131 92 132 93 struct notifier_block i2c_nb; 133 94 134 95 struct i2c_adapter *adapter[] __counted_by(max_adapters); 135 96 }; 136 97 137 - static struct i2c_atr_alias_pair * 138 - i2c_atr_find_mapping_by_client(const struct list_head *list, 139 - const struct i2c_client *client) 98 + static struct i2c_atr_alias_pool *i2c_atr_alloc_alias_pool(size_t num_aliases, bool shared) 99 + { 100 + struct i2c_atr_alias_pool *alias_pool; 101 + int ret; 102 + 103 + alias_pool = kzalloc(sizeof(*alias_pool), GFP_KERNEL); 104 + if (!alias_pool) 105 + return ERR_PTR(-ENOMEM); 106 + 107 + alias_pool->size = num_aliases; 108 + 109 + alias_pool->aliases = kcalloc(num_aliases, sizeof(*alias_pool->aliases), GFP_KERNEL); 110 + if (!alias_pool->aliases) { 111 + ret = -ENOMEM; 112 + goto err_free_alias_pool; 113 + } 114 + 115 + alias_pool->use_mask = bitmap_zalloc(num_aliases, GFP_KERNEL); 116 + if (!alias_pool->use_mask) { 117 + ret = -ENOMEM; 118 + goto err_free_aliases; 119 + } 120 + 121 + alias_pool->shared = shared; 122 + 123 + spin_lock_init(&alias_pool->lock); 124 + 125 + return alias_pool; 126 + 127 + err_free_aliases: 128 + kfree(alias_pool->aliases); 129 + err_free_alias_pool: 130 + kfree(alias_pool); 131 + return ERR_PTR(ret); 132 + } 133 + 134 + static void i2c_atr_free_alias_pool(struct i2c_atr_alias_pool *alias_pool) 135 + { 136 + bitmap_free(alias_pool->use_mask); 137 + kfree(alias_pool->aliases); 138 + kfree(alias_pool); 139 + } 140 + 141 + /* Must be called with alias_pairs_lock held */ 142 + static struct i2c_atr_alias_pair *i2c_atr_create_c2a(struct i2c_atr_chan *chan, 143 + u16 alias, u16 addr) 140 144 { 141 145 struct i2c_atr_alias_pair *c2a; 142 146 143 - list_for_each_entry(c2a, list, node) { 144 - if (c2a->client == client) 147 + lockdep_assert_held(&chan->alias_pairs_lock); 148 + 149 + c2a = kzalloc(sizeof(*c2a), GFP_KERNEL); 150 + if (!c2a) 151 + return NULL; 152 + 153 + c2a->addr = addr; 154 + c2a->alias = alias; 155 + 156 + list_add(&c2a->node, &chan->alias_pairs); 157 + 158 + return c2a; 159 + } 160 + 161 + /* Must be called with alias_pairs_lock held */ 162 + static void i2c_atr_destroy_c2a(struct i2c_atr_alias_pair **pc2a) 163 + { 164 + list_del(&(*pc2a)->node); 165 + kfree(*pc2a); 166 + *pc2a = NULL; 167 + } 168 + 169 + static int i2c_atr_reserve_alias(struct i2c_atr_alias_pool *alias_pool) 170 + { 171 + unsigned long idx; 172 + u16 alias; 173 + 174 + spin_lock(&alias_pool->lock); 175 + 176 + idx = find_first_zero_bit(alias_pool->use_mask, alias_pool->size); 177 + if (idx >= alias_pool->size) { 178 + spin_unlock(&alias_pool->lock); 179 + return -EBUSY; 180 + } 181 + 182 + set_bit(idx, alias_pool->use_mask); 183 + 184 + alias = alias_pool->aliases[idx]; 185 + 186 + spin_unlock(&alias_pool->lock); 187 + return alias; 188 + } 189 + 190 + static void i2c_atr_release_alias(struct i2c_atr_alias_pool *alias_pool, u16 alias) 191 + { 192 + unsigned int idx; 193 + 194 + spin_lock(&alias_pool->lock); 195 + 196 + for (idx = 0; idx < alias_pool->size; ++idx) { 197 + if (alias_pool->aliases[idx] == alias) { 198 + clear_bit(idx, alias_pool->use_mask); 199 + spin_unlock(&alias_pool->lock); 200 + return; 201 + } 202 + } 203 + 204 + spin_unlock(&alias_pool->lock); 205 + } 206 + 207 + static struct i2c_atr_alias_pair * 208 + i2c_atr_find_mapping_by_addr(struct i2c_atr_chan *chan, u16 addr) 209 + { 210 + struct i2c_atr_alias_pair *c2a; 211 + 212 + lockdep_assert_held(&chan->alias_pairs_lock); 213 + 214 + list_for_each_entry(c2a, &chan->alias_pairs, node) { 215 + if (c2a->addr == addr) 145 216 return c2a; 146 217 } 147 218 ··· 257 112 } 258 113 259 114 static struct i2c_atr_alias_pair * 260 - i2c_atr_find_mapping_by_addr(const struct list_head *list, u16 phys_addr) 115 + i2c_atr_create_mapping_by_addr(struct i2c_atr_chan *chan, u16 addr) 261 116 { 117 + struct i2c_atr *atr = chan->atr; 262 118 struct i2c_atr_alias_pair *c2a; 119 + u16 alias; 120 + int ret; 263 121 264 - list_for_each_entry(c2a, list, node) { 265 - if (c2a->client->addr == phys_addr) 266 - return c2a; 122 + lockdep_assert_held(&chan->alias_pairs_lock); 123 + 124 + ret = i2c_atr_reserve_alias(chan->alias_pool); 125 + if (ret < 0) 126 + return NULL; 127 + 128 + alias = ret; 129 + 130 + c2a = i2c_atr_create_c2a(chan, alias, addr); 131 + if (!c2a) 132 + goto err_release_alias; 133 + 134 + ret = atr->ops->attach_addr(atr, chan->chan_id, c2a->addr, c2a->alias); 135 + if (ret) { 136 + dev_err(atr->dev, "failed to attach 0x%02x on channel %d: err %d\n", 137 + addr, chan->chan_id, ret); 138 + goto err_del_c2a; 267 139 } 268 140 141 + return c2a; 142 + 143 + err_del_c2a: 144 + i2c_atr_destroy_c2a(&c2a); 145 + err_release_alias: 146 + i2c_atr_release_alias(chan->alias_pool, alias); 269 147 return NULL; 148 + } 149 + 150 + static struct i2c_atr_alias_pair * 151 + i2c_atr_replace_mapping_by_addr(struct i2c_atr_chan *chan, u16 addr) 152 + { 153 + struct i2c_atr *atr = chan->atr; 154 + struct i2c_atr_alias_pair *c2a; 155 + struct list_head *alias_pairs; 156 + bool found = false; 157 + u16 alias; 158 + int ret; 159 + 160 + lockdep_assert_held(&chan->alias_pairs_lock); 161 + 162 + alias_pairs = &chan->alias_pairs; 163 + 164 + if (unlikely(list_empty(alias_pairs))) 165 + return NULL; 166 + 167 + list_for_each_entry_reverse(c2a, alias_pairs, node) { 168 + if (!c2a->fixed) { 169 + found = true; 170 + break; 171 + } 172 + } 173 + 174 + if (!found) 175 + return NULL; 176 + 177 + atr->ops->detach_addr(atr, chan->chan_id, c2a->addr); 178 + c2a->addr = addr; 179 + 180 + list_move(&c2a->node, alias_pairs); 181 + 182 + alias = c2a->alias; 183 + 184 + ret = atr->ops->attach_addr(atr, chan->chan_id, c2a->addr, c2a->alias); 185 + if (ret) { 186 + dev_err(atr->dev, "failed to attach 0x%02x on channel %d: err %d\n", 187 + addr, chan->chan_id, ret); 188 + i2c_atr_destroy_c2a(&c2a); 189 + i2c_atr_release_alias(chan->alias_pool, alias); 190 + return NULL; 191 + } 192 + 193 + return c2a; 194 + } 195 + 196 + static struct i2c_atr_alias_pair * 197 + i2c_atr_get_mapping_by_addr(struct i2c_atr_chan *chan, u16 addr) 198 + { 199 + struct i2c_atr *atr = chan->atr; 200 + struct i2c_atr_alias_pair *c2a; 201 + 202 + c2a = i2c_atr_find_mapping_by_addr(chan, addr); 203 + if (c2a) 204 + return c2a; 205 + 206 + if (atr->flags & I2C_ATR_F_STATIC) 207 + return NULL; 208 + 209 + c2a = i2c_atr_create_mapping_by_addr(chan, addr); 210 + if (c2a) 211 + return c2a; 212 + 213 + return i2c_atr_replace_mapping_by_addr(chan, addr); 270 214 } 271 215 272 216 /* ··· 370 136 { 371 137 struct i2c_atr *atr = chan->atr; 372 138 static struct i2c_atr_alias_pair *c2a; 373 - int i; 139 + int i, ret = 0; 374 140 375 141 /* Ensure we have enough room to save the original addresses */ 376 142 if (unlikely(chan->orig_addrs_size < num)) { ··· 386 152 chan->orig_addrs_size = num; 387 153 } 388 154 155 + mutex_lock(&chan->alias_pairs_lock); 156 + 389 157 for (i = 0; i < num; i++) { 390 158 chan->orig_addrs[i] = msgs[i].addr; 391 159 392 - c2a = i2c_atr_find_mapping_by_addr(&chan->alias_list, 393 - msgs[i].addr); 160 + c2a = i2c_atr_get_mapping_by_addr(chan, msgs[i].addr); 161 + 394 162 if (!c2a) { 163 + if (atr->flags & I2C_ATR_F_PASSTHROUGH) 164 + continue; 165 + 395 166 dev_err(atr->dev, "client 0x%02x not mapped!\n", 396 167 msgs[i].addr); 397 168 398 169 while (i--) 399 170 msgs[i].addr = chan->orig_addrs[i]; 400 171 401 - return -ENXIO; 172 + ret = -ENXIO; 173 + goto out_unlock; 402 174 } 175 + 176 + // Prevent c2a from being overwritten by another client in this transaction 177 + c2a->fixed = true; 403 178 404 179 msgs[i].addr = c2a->alias; 405 180 } 406 181 407 - return 0; 182 + out_unlock: 183 + mutex_unlock(&chan->alias_pairs_lock); 184 + return ret; 408 185 } 409 186 410 187 /* ··· 428 183 static void i2c_atr_unmap_msgs(struct i2c_atr_chan *chan, struct i2c_msg *msgs, 429 184 int num) 430 185 { 186 + struct i2c_atr_alias_pair *c2a; 431 187 int i; 432 188 433 189 for (i = 0; i < num; i++) 434 190 msgs[i].addr = chan->orig_addrs[i]; 191 + 192 + mutex_lock(&chan->alias_pairs_lock); 193 + 194 + if (unlikely(list_empty(&chan->alias_pairs))) 195 + goto out_unlock; 196 + 197 + // unfix c2a entries so that subsequent transfers can reuse their aliases 198 + list_for_each_entry(c2a, &chan->alias_pairs, node) { 199 + c2a->fixed = false; 200 + } 201 + 202 + out_unlock: 203 + mutex_unlock(&chan->alias_pairs_lock); 435 204 } 436 205 437 206 static int i2c_atr_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, ··· 483 224 struct i2c_atr *atr = chan->atr; 484 225 struct i2c_adapter *parent = atr->parent; 485 226 struct i2c_atr_alias_pair *c2a; 227 + u16 alias; 486 228 487 - c2a = i2c_atr_find_mapping_by_addr(&chan->alias_list, addr); 488 - if (!c2a) { 229 + mutex_lock(&chan->alias_pairs_lock); 230 + 231 + c2a = i2c_atr_get_mapping_by_addr(chan, addr); 232 + 233 + if (!c2a && !(atr->flags & I2C_ATR_F_PASSTHROUGH)) { 489 234 dev_err(atr->dev, "client 0x%02x not mapped!\n", addr); 235 + mutex_unlock(&chan->alias_pairs_lock); 490 236 return -ENXIO; 491 237 } 492 238 493 - return i2c_smbus_xfer(parent, c2a->alias, flags, read_write, command, 239 + alias = c2a ? c2a->alias : addr; 240 + 241 + mutex_unlock(&chan->alias_pairs_lock); 242 + 243 + return i2c_smbus_xfer(parent, alias, flags, read_write, command, 494 244 size, data); 495 245 } 496 246 ··· 541 273 .unlock_bus = i2c_atr_unlock_bus, 542 274 }; 543 275 544 - static int i2c_atr_reserve_alias(struct i2c_atr *atr) 545 - { 546 - unsigned long idx; 547 - 548 - spin_lock(&atr->alias_mask_lock); 549 - 550 - idx = find_first_zero_bit(atr->alias_use_mask, atr->num_aliases); 551 - if (idx >= atr->num_aliases) { 552 - spin_unlock(&atr->alias_mask_lock); 553 - dev_err(atr->dev, "failed to find a free alias\n"); 554 - return -EBUSY; 555 - } 556 - 557 - set_bit(idx, atr->alias_use_mask); 558 - 559 - spin_unlock(&atr->alias_mask_lock); 560 - 561 - return atr->aliases[idx]; 562 - } 563 - 564 - static void i2c_atr_release_alias(struct i2c_atr *atr, u16 alias) 565 - { 566 - unsigned int idx; 567 - 568 - spin_lock(&atr->alias_mask_lock); 569 - 570 - for (idx = 0; idx < atr->num_aliases; ++idx) { 571 - if (atr->aliases[idx] == alias) { 572 - clear_bit(idx, atr->alias_use_mask); 573 - spin_unlock(&atr->alias_mask_lock); 574 - return; 575 - } 576 - } 577 - 578 - spin_unlock(&atr->alias_mask_lock); 579 - 580 - /* This should never happen */ 581 - dev_warn(atr->dev, "Unable to find mapped alias\n"); 582 - } 583 - 584 - static int i2c_atr_attach_client(struct i2c_adapter *adapter, 585 - const struct i2c_client *client) 276 + static int i2c_atr_attach_addr(struct i2c_adapter *adapter, 277 + u16 addr) 586 278 { 587 279 struct i2c_atr_chan *chan = adapter->algo_data; 588 280 struct i2c_atr *atr = chan->atr; 589 281 struct i2c_atr_alias_pair *c2a; 590 - u16 alias; 591 - int ret; 282 + int ret = 0; 592 283 593 - ret = i2c_atr_reserve_alias(atr); 594 - if (ret < 0) 595 - return ret; 284 + mutex_lock(&chan->alias_pairs_lock); 596 285 597 - alias = ret; 286 + c2a = i2c_atr_create_mapping_by_addr(chan, addr); 287 + if (!c2a && !(atr->flags & I2C_ATR_F_STATIC)) 288 + c2a = i2c_atr_replace_mapping_by_addr(chan, addr); 598 289 599 - c2a = kzalloc(sizeof(*c2a), GFP_KERNEL); 600 290 if (!c2a) { 601 - ret = -ENOMEM; 602 - goto err_release_alias; 291 + dev_err(atr->dev, "failed to find a free alias\n"); 292 + ret = -EBUSY; 293 + goto out_unlock; 603 294 } 604 295 605 - ret = atr->ops->attach_client(atr, chan->chan_id, client, alias); 606 - if (ret) 607 - goto err_free; 296 + dev_dbg(atr->dev, "chan%u: using alias 0x%02x for addr 0x%02x\n", 297 + chan->chan_id, c2a->alias, addr); 608 298 609 - dev_dbg(atr->dev, "chan%u: client 0x%02x mapped at alias 0x%02x (%s)\n", 610 - chan->chan_id, client->addr, alias, client->name); 611 - 612 - c2a->client = client; 613 - c2a->alias = alias; 614 - list_add(&c2a->node, &chan->alias_list); 615 - 616 - return 0; 617 - 618 - err_free: 619 - kfree(c2a); 620 - err_release_alias: 621 - i2c_atr_release_alias(atr, alias); 622 - 299 + out_unlock: 300 + mutex_unlock(&chan->alias_pairs_lock); 623 301 return ret; 624 302 } 625 303 626 - static void i2c_atr_detach_client(struct i2c_adapter *adapter, 627 - const struct i2c_client *client) 304 + static void i2c_atr_detach_addr(struct i2c_adapter *adapter, 305 + u16 addr) 628 306 { 629 307 struct i2c_atr_chan *chan = adapter->algo_data; 630 308 struct i2c_atr *atr = chan->atr; 631 309 struct i2c_atr_alias_pair *c2a; 632 310 633 - atr->ops->detach_client(atr, chan->chan_id, client); 311 + atr->ops->detach_addr(atr, chan->chan_id, addr); 634 312 635 - c2a = i2c_atr_find_mapping_by_client(&chan->alias_list, client); 313 + mutex_lock(&chan->alias_pairs_lock); 314 + 315 + c2a = i2c_atr_find_mapping_by_addr(chan, addr); 636 316 if (!c2a) { 637 - /* This should never happen */ 638 - dev_warn(atr->dev, "Unable to find address mapping\n"); 317 + mutex_unlock(&chan->alias_pairs_lock); 639 318 return; 640 319 } 641 320 642 - i2c_atr_release_alias(atr, c2a->alias); 321 + i2c_atr_release_alias(chan->alias_pool, c2a->alias); 643 322 644 323 dev_dbg(atr->dev, 645 - "chan%u: client 0x%02x unmapped from alias 0x%02x (%s)\n", 646 - chan->chan_id, client->addr, c2a->alias, client->name); 324 + "chan%u: detached alias 0x%02x from addr 0x%02x\n", 325 + chan->chan_id, c2a->alias, addr); 647 326 648 - list_del(&c2a->node); 649 - kfree(c2a); 327 + i2c_atr_destroy_c2a(&c2a); 328 + 329 + mutex_unlock(&chan->alias_pairs_lock); 650 330 } 651 331 652 332 static int i2c_atr_bus_notifier_call(struct notifier_block *nb, ··· 621 405 622 406 switch (event) { 623 407 case BUS_NOTIFY_ADD_DEVICE: 624 - ret = i2c_atr_attach_client(client->adapter, client); 408 + ret = i2c_atr_attach_addr(client->adapter, client->addr); 625 409 if (ret) 626 410 dev_err(atr->dev, 627 411 "Failed to attach remote client '%s': %d\n", ··· 629 413 break; 630 414 631 415 case BUS_NOTIFY_REMOVED_DEVICE: 632 - i2c_atr_detach_client(client->adapter, client); 416 + i2c_atr_detach_addr(client->adapter, client->addr); 633 417 break; 634 418 635 419 default: ··· 641 425 642 426 static int i2c_atr_parse_alias_pool(struct i2c_atr *atr) 643 427 { 428 + struct i2c_atr_alias_pool *alias_pool; 644 429 struct device *dev = atr->dev; 645 - unsigned long *alias_use_mask; 646 430 size_t num_aliases; 647 431 unsigned int i; 648 432 u32 *aliases32; 649 - u16 *aliases16; 650 433 int ret; 651 434 652 - ret = fwnode_property_count_u32(dev_fwnode(dev), "i2c-alias-pool"); 653 - if (ret < 0) { 654 - dev_err(dev, "Failed to count 'i2c-alias-pool' property: %d\n", 655 - ret); 435 + if (!fwnode_property_present(dev_fwnode(dev), "i2c-alias-pool")) { 436 + num_aliases = 0; 437 + } else { 438 + ret = fwnode_property_count_u32(dev_fwnode(dev), "i2c-alias-pool"); 439 + if (ret < 0) { 440 + dev_err(dev, "Failed to count 'i2c-alias-pool' property: %d\n", 441 + ret); 442 + return ret; 443 + } 444 + 445 + num_aliases = ret; 446 + } 447 + 448 + alias_pool = i2c_atr_alloc_alias_pool(num_aliases, true); 449 + if (IS_ERR(alias_pool)) { 450 + ret = PTR_ERR(alias_pool); 451 + dev_err(dev, "Failed to allocate alias pool, err %d\n", ret); 656 452 return ret; 657 453 } 658 454 659 - num_aliases = ret; 455 + atr->alias_pool = alias_pool; 660 456 661 - if (!num_aliases) 457 + if (!alias_pool->size) 662 458 return 0; 663 459 664 460 aliases32 = kcalloc(num_aliases, sizeof(*aliases32), GFP_KERNEL); 665 - if (!aliases32) 666 - return -ENOMEM; 461 + if (!aliases32) { 462 + ret = -ENOMEM; 463 + goto err_free_alias_pool; 464 + } 667 465 668 466 ret = fwnode_property_read_u32_array(dev_fwnode(dev), "i2c-alias-pool", 669 467 aliases32, num_aliases); ··· 687 457 goto err_free_aliases32; 688 458 } 689 459 690 - aliases16 = kcalloc(num_aliases, sizeof(*aliases16), GFP_KERNEL); 691 - if (!aliases16) { 692 - ret = -ENOMEM; 693 - goto err_free_aliases32; 694 - } 695 - 696 460 for (i = 0; i < num_aliases; i++) { 697 461 if (!(aliases32[i] & 0xffff0000)) { 698 - aliases16[i] = aliases32[i]; 462 + alias_pool->aliases[i] = aliases32[i]; 699 463 continue; 700 464 } 701 465 702 466 dev_err(dev, "Failed to parse 'i2c-alias-pool' property: I2C flags are not supported\n"); 703 467 ret = -EINVAL; 704 - goto err_free_aliases16; 705 - } 706 - 707 - alias_use_mask = bitmap_zalloc(num_aliases, GFP_KERNEL); 708 - if (!alias_use_mask) { 709 - ret = -ENOMEM; 710 - goto err_free_aliases16; 468 + goto err_free_aliases32; 711 469 } 712 470 713 471 kfree(aliases32); 714 472 715 - atr->num_aliases = num_aliases; 716 - atr->aliases = aliases16; 717 - atr->alias_use_mask = alias_use_mask; 718 - 719 - dev_dbg(dev, "i2c-alias-pool has %zu aliases", atr->num_aliases); 473 + dev_dbg(dev, "i2c-alias-pool has %zu aliases\n", alias_pool->size); 720 474 721 475 return 0; 722 476 723 - err_free_aliases16: 724 - kfree(aliases16); 725 477 err_free_aliases32: 726 478 kfree(aliases32); 479 + err_free_alias_pool: 480 + i2c_atr_free_alias_pool(alias_pool); 727 481 return ret; 728 482 } 729 483 730 484 struct i2c_atr *i2c_atr_new(struct i2c_adapter *parent, struct device *dev, 731 - const struct i2c_atr_ops *ops, int max_adapters) 485 + const struct i2c_atr_ops *ops, int max_adapters, 486 + u32 flags) 732 487 { 733 488 struct i2c_atr *atr; 734 489 int ret; ··· 721 506 if (max_adapters > ATR_MAX_ADAPTERS) 722 507 return ERR_PTR(-EINVAL); 723 508 724 - if (!ops || !ops->attach_client || !ops->detach_client) 509 + if (!ops || !ops->attach_addr || !ops->detach_addr) 725 510 return ERR_PTR(-EINVAL); 726 511 727 512 atr = kzalloc(struct_size(atr, adapter, max_adapters), GFP_KERNEL); 728 513 if (!atr) 729 514 return ERR_PTR(-ENOMEM); 730 515 731 - mutex_init(&atr->lock); 732 - spin_lock_init(&atr->alias_mask_lock); 516 + lockdep_register_key(&atr->lock_key); 517 + mutex_init_with_key(&atr->lock, &atr->lock_key); 733 518 734 519 atr->parent = parent; 735 520 atr->dev = dev; 736 521 atr->ops = ops; 737 522 atr->max_adapters = max_adapters; 523 + atr->flags = flags; 738 524 739 525 if (parent->algo->master_xfer) 740 526 atr->algo.master_xfer = i2c_atr_master_xfer; ··· 750 534 atr->i2c_nb.notifier_call = i2c_atr_bus_notifier_call; 751 535 ret = bus_register_notifier(&i2c_bus_type, &atr->i2c_nb); 752 536 if (ret) 753 - goto err_free_aliases; 537 + goto err_free_alias_pool; 754 538 755 539 return atr; 756 540 757 - err_free_aliases: 758 - bitmap_free(atr->alias_use_mask); 759 - kfree(atr->aliases); 541 + err_free_alias_pool: 542 + i2c_atr_free_alias_pool(atr->alias_pool); 760 543 err_destroy_mutex: 761 544 mutex_destroy(&atr->lock); 545 + lockdep_unregister_key(&atr->lock_key); 762 546 kfree(atr); 763 547 764 548 return ERR_PTR(ret); ··· 773 557 WARN_ON(atr->adapter[i]); 774 558 775 559 bus_unregister_notifier(&i2c_bus_type, &atr->i2c_nb); 776 - bitmap_free(atr->alias_use_mask); 777 - kfree(atr->aliases); 560 + i2c_atr_free_alias_pool(atr->alias_pool); 778 561 mutex_destroy(&atr->lock); 562 + lockdep_unregister_key(&atr->lock_key); 779 563 kfree(atr); 780 564 } 781 565 EXPORT_SYMBOL_NS_GPL(i2c_atr_delete, "I2C_ATR"); 782 566 783 - int i2c_atr_add_adapter(struct i2c_atr *atr, u32 chan_id, 784 - struct device *adapter_parent, 785 - struct fwnode_handle *bus_handle) 567 + int i2c_atr_add_adapter(struct i2c_atr *atr, struct i2c_atr_adap_desc *desc) 786 568 { 569 + struct fwnode_handle *bus_handle = desc->bus_handle; 787 570 struct i2c_adapter *parent = atr->parent; 788 - struct device *dev = atr->dev; 789 - struct i2c_atr_chan *chan; 790 571 char symlink_name[ATR_MAX_SYMLINK_LEN]; 791 - int ret; 572 + struct device *dev = atr->dev; 573 + u32 chan_id = desc->chan_id; 574 + struct i2c_atr_chan *chan; 575 + int ret, idx; 792 576 793 577 if (chan_id >= atr->max_adapters) { 794 578 dev_err(dev, "No room for more i2c-atr adapters\n"); ··· 804 588 if (!chan) 805 589 return -ENOMEM; 806 590 807 - if (!adapter_parent) 808 - adapter_parent = dev; 591 + if (!desc->parent) 592 + desc->parent = dev; 809 593 810 594 chan->atr = atr; 811 595 chan->chan_id = chan_id; 812 - INIT_LIST_HEAD(&chan->alias_list); 813 - mutex_init(&chan->orig_addrs_lock); 596 + INIT_LIST_HEAD(&chan->alias_pairs); 597 + lockdep_register_key(&chan->alias_pairs_lock_key); 598 + lockdep_register_key(&chan->orig_addrs_lock_key); 599 + mutex_init_with_key(&chan->alias_pairs_lock, &chan->alias_pairs_lock_key); 600 + mutex_init_with_key(&chan->orig_addrs_lock, &chan->orig_addrs_lock_key); 814 601 815 602 snprintf(chan->adap.name, sizeof(chan->adap.name), "i2c-%d-atr-%d", 816 603 i2c_adapter_id(parent), chan_id); 817 604 chan->adap.owner = THIS_MODULE; 818 605 chan->adap.algo = &atr->algo; 819 606 chan->adap.algo_data = chan; 820 - chan->adap.dev.parent = adapter_parent; 607 + chan->adap.dev.parent = desc->parent; 821 608 chan->adap.retries = parent->retries; 822 609 chan->adap.timeout = parent->timeout; 823 610 chan->adap.quirks = parent->quirks; ··· 847 628 fwnode_handle_put(atr_node); 848 629 } 849 630 631 + if (desc->num_aliases > 0) { 632 + chan->alias_pool = i2c_atr_alloc_alias_pool(desc->num_aliases, false); 633 + if (IS_ERR(chan->alias_pool)) { 634 + ret = PTR_ERR(chan->alias_pool); 635 + goto err_fwnode_put; 636 + } 637 + 638 + for (idx = 0; idx < desc->num_aliases; idx++) 639 + chan->alias_pool->aliases[idx] = desc->aliases[idx]; 640 + } else { 641 + chan->alias_pool = atr->alias_pool; 642 + } 643 + 850 644 atr->adapter[chan_id] = &chan->adap; 851 645 852 646 ret = i2c_add_adapter(&chan->adap); 853 647 if (ret) { 854 648 dev_err(dev, "failed to add atr-adapter %u (error=%d)\n", 855 649 chan_id, ret); 856 - goto err_fwnode_put; 650 + goto err_free_alias_pool; 857 651 } 858 652 859 653 snprintf(symlink_name, sizeof(symlink_name), "channel-%u", ··· 883 651 884 652 return 0; 885 653 654 + err_free_alias_pool: 655 + if (!chan->alias_pool->shared) 656 + i2c_atr_free_alias_pool(chan->alias_pool); 886 657 err_fwnode_put: 887 658 fwnode_handle_put(dev_fwnode(&chan->adap.dev)); 888 659 mutex_destroy(&chan->orig_addrs_lock); 660 + mutex_destroy(&chan->alias_pairs_lock); 661 + lockdep_unregister_key(&chan->orig_addrs_lock_key); 662 + lockdep_unregister_key(&chan->alias_pairs_lock_key); 889 663 kfree(chan); 890 664 return ret; 891 665 } ··· 921 683 922 684 i2c_del_adapter(adap); 923 685 686 + if (!chan->alias_pool->shared) 687 + i2c_atr_free_alias_pool(chan->alias_pool); 688 + 924 689 atr->adapter[chan_id] = NULL; 925 690 926 691 fwnode_handle_put(fwnode); 927 692 mutex_destroy(&chan->orig_addrs_lock); 693 + mutex_destroy(&chan->alias_pairs_lock); 694 + lockdep_unregister_key(&chan->orig_addrs_lock_key); 695 + lockdep_unregister_key(&chan->alias_pairs_lock_key); 928 696 kfree(chan->orig_addrs); 929 697 kfree(chan); 930 698 }
+33 -34
drivers/i2c/i2c-core-base.c
··· 26 26 #include <linux/idr.h> 27 27 #include <linux/init.h> 28 28 #include <linux/interrupt.h> 29 - #include <linux/irqflags.h> 29 + #include <linux/irq.h> 30 30 #include <linux/jump_label.h> 31 31 #include <linux/kernel.h> 32 32 #include <linux/module.h> 33 33 #include <linux/mutex.h> 34 34 #include <linux/of_device.h> 35 35 #include <linux/of.h> 36 - #include <linux/of_irq.h> 37 36 #include <linux/pinctrl/consumer.h> 38 37 #include <linux/pinctrl/devinfo.h> 39 38 #include <linux/pm_domain.h> ··· 41 42 #include <linux/property.h> 42 43 #include <linux/rwsem.h> 43 44 #include <linux/slab.h> 45 + #include <linux/string_choices.h> 44 46 45 47 #include "i2c-core.h" 46 48 ··· 490 490 491 491 static int i2c_device_probe(struct device *dev) 492 492 { 493 + struct fwnode_handle *fwnode = dev_fwnode(dev); 493 494 struct i2c_client *client = i2c_verify_client(dev); 494 495 struct i2c_driver *driver; 495 496 bool do_power_on; ··· 509 508 /* Keep adapter active when Host Notify is required */ 510 509 pm_runtime_get_sync(&client->adapter->dev); 511 510 irq = i2c_smbus_host_notify_to_irq(client); 512 - } else if (dev->of_node) { 513 - irq = of_irq_get_byname(dev->of_node, "irq"); 511 + } else if (is_of_node(fwnode)) { 512 + irq = fwnode_irq_get_byname(fwnode, "irq"); 514 513 if (irq == -EINVAL || irq == -ENODATA) 515 - irq = of_irq_get(dev->of_node, 0); 516 - } else if (ACPI_COMPANION(dev)) { 514 + irq = fwnode_irq_get(fwnode, 0); 515 + } else if (is_acpi_device_node(fwnode)) { 517 516 bool wake_capable; 518 517 519 518 irq = i2c_acpi_get_irq(client, &wake_capable); ··· 521 520 client->flags |= I2C_CLIENT_WAKE; 522 521 } 523 522 if (irq == -EPROBE_DEFER) { 524 - status = irq; 523 + status = dev_err_probe(dev, irq, "can't get irq\n"); 525 524 goto put_sync_adapter; 526 525 } 527 526 ··· 547 546 if (client->flags & I2C_CLIENT_WAKE) { 548 547 int wakeirq; 549 548 550 - wakeirq = of_irq_get_byname(dev->of_node, "wakeup"); 549 + wakeirq = fwnode_irq_get_byname(fwnode, "wakeup"); 551 550 if (wakeirq == -EPROBE_DEFER) { 552 - status = wakeirq; 551 + status = dev_err_probe(dev, wakeirq, "can't get wakeirq\n"); 553 552 goto put_sync_adapter; 554 553 } 555 554 ··· 568 567 569 568 dev_dbg(dev, "probe\n"); 570 569 571 - status = of_clk_set_defaults(dev->of_node, false); 570 + status = of_clk_set_defaults(to_of_node(fwnode), false); 572 571 if (status < 0) 573 572 goto err_clear_wakeup_irq; 574 573 ··· 962 961 struct i2c_client * 963 962 i2c_new_client_device(struct i2c_adapter *adap, struct i2c_board_info const *info) 964 963 { 964 + struct fwnode_handle *fwnode = info->fwnode; 965 965 struct i2c_client *client; 966 966 bool need_put = false; 967 967 int status; ··· 1003 1001 client->dev.parent = &client->adapter->dev; 1004 1002 client->dev.bus = &i2c_bus_type; 1005 1003 client->dev.type = &i2c_client_type; 1006 - client->dev.of_node = of_node_get(info->of_node); 1007 - client->dev.fwnode = info->fwnode; 1008 1004 1009 1005 device_enable_async_suspend(&client->dev); 1006 + 1007 + device_set_node(&client->dev, fwnode_handle_get(fwnode)); 1010 1008 1011 1009 if (info->swnode) { 1012 1010 status = device_add_software_node(&client->dev, info->swnode); ··· 1014 1012 dev_err(&adap->dev, 1015 1013 "Failed to add software node to client %s: %d\n", 1016 1014 client->name, status); 1017 - goto out_err_put_of_node; 1015 + goto out_err_put_fwnode; 1018 1016 } 1019 1017 } 1020 1018 ··· 1033 1031 out_remove_swnode: 1034 1032 device_remove_software_node(&client->dev); 1035 1033 need_put = true; 1036 - out_err_put_of_node: 1037 - of_node_put(info->of_node); 1034 + out_err_put_fwnode: 1035 + fwnode_handle_put(fwnode); 1038 1036 out_err: 1039 1037 dev_err(&adap->dev, 1040 1038 "Failed to register i2c client %s at 0x%02x (%d)\n", ··· 1056 1054 */ 1057 1055 void i2c_unregister_device(struct i2c_client *client) 1058 1056 { 1057 + struct fwnode_handle *fwnode; 1058 + 1059 1059 if (IS_ERR_OR_NULL(client)) 1060 1060 return; 1061 1061 1062 - if (client->dev.of_node) { 1063 - of_node_clear_flag(client->dev.of_node, OF_POPULATED); 1064 - of_node_put(client->dev.of_node); 1065 - } 1066 - 1067 - if (ACPI_COMPANION(&client->dev)) 1068 - acpi_device_clear_enumerated(ACPI_COMPANION(&client->dev)); 1062 + fwnode = dev_fwnode(&client->dev); 1063 + if (is_of_node(fwnode)) 1064 + of_node_clear_flag(to_of_node(fwnode), OF_POPULATED); 1065 + else if (is_acpi_device_node(fwnode)) 1066 + acpi_device_clear_enumerated(to_acpi_device_node(fwnode)); 1067 + fwnode_handle_put(fwnode); 1069 1068 1070 1069 device_remove_software_node(&client->dev); 1071 1070 device_unregister(&client->dev); ··· 1212 1209 u32 addr = default_addr; 1213 1210 int i; 1214 1211 1215 - if (np) { 1216 - i = of_property_match_string(np, "reg-names", name); 1217 - if (i >= 0) 1218 - of_property_read_u32_index(np, "reg", i, &addr); 1219 - } 1212 + i = of_property_match_string(np, "reg-names", name); 1213 + if (i >= 0) 1214 + of_property_read_u32_index(np, "reg", i, &addr); 1220 1215 1221 1216 dev_dbg(&client->adapter->dev, "Address for %s : 0x%x\n", name, addr); 1222 1217 return i2c_new_dummy_device(client->adapter, addr); ··· 1652 1651 struct device *dev = &adapter->dev; 1653 1652 int id; 1654 1653 1655 - if (dev->of_node) { 1656 - id = of_alias_get_id(dev->of_node, "i2c"); 1657 - if (id >= 0) { 1658 - adapter->nr = id; 1659 - return __i2c_add_numbered_adapter(adapter); 1660 - } 1654 + id = of_alias_get_id(dev->of_node, "i2c"); 1655 + if (id >= 0) { 1656 + adapter->nr = id; 1657 + return __i2c_add_numbered_adapter(adapter); 1661 1658 } 1662 1659 1663 1660 mutex_lock(&core_lock); ··· 2145 2146 { 2146 2147 dev_err_ratelimited(&adap->dev, "adapter quirk: %s (addr 0x%04x, size %u, %s)\n", 2147 2148 err_msg, msg->addr, msg->len, 2148 - msg->flags & I2C_M_RD ? "read" : "write"); 2149 + str_read_write(msg->flags & I2C_M_RD)); 2149 2150 return -EOPNOTSUPP; 2150 2151 } 2151 2152
-1
drivers/i2c/i2c-core-of.c
··· 49 49 } 50 50 51 51 info->addr = addr; 52 - info->of_node = node; 53 52 info->fwnode = of_fwnode_handle(node); 54 53 55 54 if (of_property_read_bool(node, "host-notify"))
+8 -4
drivers/i2c/i2c-core-slave.c
··· 11 11 #include <linux/err.h> 12 12 #include <linux/i2c.h> 13 13 #include <linux/of.h> 14 + #include <linux/property.h> 14 15 15 16 #include "i2c-core.h" 16 17 ··· 109 108 */ 110 109 bool i2c_detect_slave_mode(struct device *dev) 111 110 { 112 - if (IS_BUILTIN(CONFIG_OF) && dev->of_node) { 111 + struct fwnode_handle *fwnode = dev_fwnode(dev); 112 + 113 + if (is_of_node(fwnode)) { 114 + struct fwnode_handle *child __free(fwnode_handle) = NULL; 113 115 u32 reg; 114 116 115 - for_each_child_of_node_scoped(dev->of_node, child) { 116 - of_property_read_u32(child, "reg", &reg); 117 + fwnode_for_each_child_node(fwnode, child) { 118 + fwnode_property_read_u32(child, "reg", &reg); 117 119 if (reg & I2C_OWN_SLAVE_ADDRESS) 118 120 return true; 119 121 } 120 - } else if (IS_BUILTIN(CONFIG_ACPI) && ACPI_HANDLE(dev)) { 122 + } else if (is_acpi_device_node(fwnode)) { 121 123 dev_dbg(dev, "ACPI slave is not supported yet\n"); 122 124 } 123 125 return false;
+2 -1
drivers/i2c/i2c-core-smbus.c
··· 16 16 #include <linux/i2c-smbus.h> 17 17 #include <linux/property.h> 18 18 #include <linux/slab.h> 19 + #include <linux/string_choices.h> 19 20 20 21 #include "i2c-core.h" 21 22 ··· 434 433 case I2C_SMBUS_I2C_BLOCK_DATA: 435 434 if (data->block[0] > I2C_SMBUS_BLOCK_MAX) { 436 435 dev_err(&adapter->dev, "Invalid block %s size %d\n", 437 - read_write == I2C_SMBUS_READ ? "read" : "write", 436 + str_read_write(read_write == I2C_SMBUS_READ), 438 437 data->block[0]); 439 438 return -EINVAL; 440 439 }
+19 -2
drivers/i2c/i2c-smbus.c
··· 372 372 * - Only works on systems with 1 to 8 memory slots 373 373 */ 374 374 #if IS_ENABLED(CONFIG_DMI) 375 - void i2c_register_spd(struct i2c_adapter *adap) 375 + static void i2c_register_spd(struct i2c_adapter *adap, bool write_disabled) 376 376 { 377 377 int n, slot_count = 0, dimm_count = 0; 378 378 u16 handle; 379 379 u8 common_mem_type = 0x0, mem_type; 380 380 u64 mem_size; 381 + bool instantiate = true; 381 382 const char *name; 382 383 383 384 while ((handle = dmi_memdev_handle(slot_count)) != 0xffff) { ··· 439 438 case 0x22: /* DDR5 */ 440 439 case 0x23: /* LPDDR5 */ 441 440 name = "spd5118"; 441 + instantiate = !write_disabled; 442 442 break; 443 443 default: 444 444 dev_info(&adap->dev, ··· 463 461 addr_list[0] = 0x50 + n; 464 462 addr_list[1] = I2C_CLIENT_END; 465 463 464 + if (!instantiate) 465 + continue; 466 + 466 467 if (!IS_ERR(i2c_new_scanned_device(adap, &info, addr_list, NULL))) { 467 468 dev_info(&adap->dev, 468 469 "Successfully instantiated SPD at 0x%hx\n", ··· 474 469 } 475 470 } 476 471 } 477 - EXPORT_SYMBOL_GPL(i2c_register_spd); 472 + 473 + void i2c_register_spd_write_disable(struct i2c_adapter *adap) 474 + { 475 + i2c_register_spd(adap, true); 476 + } 477 + EXPORT_SYMBOL_GPL(i2c_register_spd_write_disable); 478 + 479 + void i2c_register_spd_write_enable(struct i2c_adapter *adap) 480 + { 481 + i2c_register_spd(adap, false); 482 + } 483 + EXPORT_SYMBOL_GPL(i2c_register_spd_write_enable); 484 + 478 485 #endif 479 486 480 487 MODULE_AUTHOR("Jean Delvare <jdelvare@suse.de>");
+5 -5
drivers/i2c/muxes/i2c-mux-ltc4306.c
··· 85 85 return !!(val & BIT(1 - offset)); 86 86 } 87 87 88 - static void ltc4306_gpio_set(struct gpio_chip *chip, unsigned int offset, 89 - int value) 88 + static int ltc4306_gpio_set(struct gpio_chip *chip, unsigned int offset, 89 + int value) 90 90 { 91 91 struct ltc4306 *data = gpiochip_get_data(chip); 92 92 93 - regmap_update_bits(data->regmap, LTC_REG_CONFIG, BIT(5 - offset), 94 - value ? BIT(5 - offset) : 0); 93 + return regmap_update_bits(data->regmap, LTC_REG_CONFIG, 94 + BIT(5 - offset), value ? BIT(5 - offset) : 0); 95 95 } 96 96 97 97 static int ltc4306_gpio_get_direction(struct gpio_chip *chip, ··· 164 164 data->gpiochip.direction_input = ltc4306_gpio_direction_input; 165 165 data->gpiochip.direction_output = ltc4306_gpio_direction_output; 166 166 data->gpiochip.get = ltc4306_gpio_get; 167 - data->gpiochip.set = ltc4306_gpio_set; 167 + data->gpiochip.set_rv = ltc4306_gpio_set; 168 168 data->gpiochip.set_config = ltc4306_gpio_set_config; 169 169 data->gpiochip.owner = THIS_MODULE; 170 170
+7 -2
drivers/media/i2c/ds90ub913.c
··· 707 707 static int ub913_add_i2c_adapter(struct ub913_data *priv) 708 708 { 709 709 struct device *dev = &priv->client->dev; 710 + struct i2c_atr_adap_desc desc = { }; 710 711 struct fwnode_handle *i2c_handle; 711 712 int ret; 712 713 ··· 715 714 if (!i2c_handle) 716 715 return 0; 717 716 718 - ret = i2c_atr_add_adapter(priv->plat_data->atr, priv->plat_data->port, 719 - dev, i2c_handle); 717 + desc.chan_id = priv->plat_data->port; 718 + desc.parent = dev; 719 + desc.bus_handle = i2c_handle; 720 + desc.num_aliases = 0; 721 + 722 + ret = i2c_atr_add_adapter(priv->plat_data->atr, &desc); 720 723 721 724 fwnode_handle_put(i2c_handle); 722 725
+7 -2
drivers/media/i2c/ds90ub953.c
··· 1102 1102 static int ub953_add_i2c_adapter(struct ub953_data *priv) 1103 1103 { 1104 1104 struct device *dev = &priv->client->dev; 1105 + struct i2c_atr_adap_desc desc = { }; 1105 1106 struct fwnode_handle *i2c_handle; 1106 1107 int ret; 1107 1108 ··· 1110 1109 if (!i2c_handle) 1111 1110 return 0; 1112 1111 1113 - ret = i2c_atr_add_adapter(priv->plat_data->atr, priv->plat_data->port, 1114 - dev, i2c_handle); 1112 + desc.chan_id = priv->plat_data->port; 1113 + desc.parent = dev; 1114 + desc.bus_handle = i2c_handle; 1115 + desc.num_aliases = 0; 1116 + 1117 + ret = i2c_atr_add_adapter(priv->plat_data->atr, &desc); 1115 1118 1116 1119 fwnode_handle_put(i2c_handle); 1117 1120
+32 -22
drivers/media/i2c/ds90ub960.c
··· 27 27 */ 28 28 29 29 #include <linux/bitops.h> 30 + #include <linux/cleanup.h> 30 31 #include <linux/clk.h> 31 32 #include <linux/delay.h> 32 33 #include <linux/fwnode.h> ··· 522 521 }; 523 522 } eq; 524 523 525 - const struct i2c_client *aliased_clients[UB960_MAX_PORT_ALIASES]; 524 + /* lock for aliased_addrs and associated registers */ 525 + struct mutex aliased_addrs_lock; 526 + u16 aliased_addrs[UB960_MAX_PORT_ALIASES]; 526 527 }; 527 528 528 529 struct ub960_asd { ··· 1267 1264 * I2C-ATR (address translator) 1268 1265 */ 1269 1266 1270 - static int ub960_atr_attach_client(struct i2c_atr *atr, u32 chan_id, 1271 - const struct i2c_client *client, u16 alias) 1267 + static int ub960_atr_attach_addr(struct i2c_atr *atr, u32 chan_id, 1268 + u16 addr, u16 alias) 1272 1269 { 1273 1270 struct ub960_data *priv = i2c_atr_get_driver_data(atr); 1274 1271 struct ub960_rxport *rxport = priv->rxports[chan_id]; ··· 1276 1273 unsigned int reg_idx; 1277 1274 int ret = 0; 1278 1275 1279 - for (reg_idx = 0; reg_idx < ARRAY_SIZE(rxport->aliased_clients); reg_idx++) { 1280 - if (!rxport->aliased_clients[reg_idx]) 1276 + guard(mutex)(&rxport->aliased_addrs_lock); 1277 + 1278 + for (reg_idx = 0; reg_idx < ARRAY_SIZE(rxport->aliased_addrs); reg_idx++) { 1279 + if (!rxport->aliased_addrs[reg_idx]) 1281 1280 break; 1282 1281 } 1283 1282 1284 - if (reg_idx == ARRAY_SIZE(rxport->aliased_clients)) { 1283 + if (reg_idx == ARRAY_SIZE(rxport->aliased_addrs)) { 1285 1284 dev_err(dev, "rx%u: alias pool exhausted\n", rxport->nport); 1286 1285 return -EADDRNOTAVAIL; 1287 1286 } 1288 1287 1289 - rxport->aliased_clients[reg_idx] = client; 1288 + rxport->aliased_addrs[reg_idx] = addr; 1290 1289 1291 1290 ub960_rxport_write(priv, chan_id, UB960_RR_SLAVE_ID(reg_idx), 1292 - client->addr << 1, &ret); 1291 + addr << 1, &ret); 1293 1292 ub960_rxport_write(priv, chan_id, UB960_RR_SLAVE_ALIAS(reg_idx), 1294 1293 alias << 1, &ret); 1295 1294 ··· 1299 1294 return ret; 1300 1295 1301 1296 dev_dbg(dev, "rx%u: client 0x%02x assigned alias 0x%02x at slot %u\n", 1302 - rxport->nport, client->addr, alias, reg_idx); 1297 + rxport->nport, addr, alias, reg_idx); 1303 1298 1304 1299 return 0; 1305 1300 } 1306 1301 1307 - static void ub960_atr_detach_client(struct i2c_atr *atr, u32 chan_id, 1308 - const struct i2c_client *client) 1302 + static void ub960_atr_detach_addr(struct i2c_atr *atr, u32 chan_id, 1303 + u16 addr) 1309 1304 { 1310 1305 struct ub960_data *priv = i2c_atr_get_driver_data(atr); 1311 1306 struct ub960_rxport *rxport = priv->rxports[chan_id]; ··· 1313 1308 unsigned int reg_idx; 1314 1309 int ret; 1315 1310 1316 - for (reg_idx = 0; reg_idx < ARRAY_SIZE(rxport->aliased_clients); reg_idx++) { 1317 - if (rxport->aliased_clients[reg_idx] == client) 1311 + guard(mutex)(&rxport->aliased_addrs_lock); 1312 + 1313 + for (reg_idx = 0; reg_idx < ARRAY_SIZE(rxport->aliased_addrs); reg_idx++) { 1314 + if (rxport->aliased_addrs[reg_idx] == addr) 1318 1315 break; 1319 1316 } 1320 1317 1321 - if (reg_idx == ARRAY_SIZE(rxport->aliased_clients)) { 1318 + if (reg_idx == ARRAY_SIZE(rxport->aliased_addrs)) { 1322 1319 dev_err(dev, "rx%u: client 0x%02x is not mapped!\n", 1323 - rxport->nport, client->addr); 1320 + rxport->nport, addr); 1324 1321 return; 1325 1322 } 1326 1323 1327 - rxport->aliased_clients[reg_idx] = NULL; 1324 + rxport->aliased_addrs[reg_idx] = 0; 1328 1325 1329 1326 ret = ub960_rxport_write(priv, chan_id, UB960_RR_SLAVE_ALIAS(reg_idx), 1330 1327 0, NULL); 1331 1328 if (ret) { 1332 1329 dev_err(dev, "rx%u: unable to fully unmap client 0x%02x: %d\n", 1333 - rxport->nport, client->addr, ret); 1330 + rxport->nport, addr, ret); 1334 1331 return; 1335 1332 } 1336 1333 1337 1334 dev_dbg(dev, "rx%u: client 0x%02x released at slot %u\n", rxport->nport, 1338 - client->addr, reg_idx); 1335 + addr, reg_idx); 1339 1336 } 1340 1337 1341 1338 static const struct i2c_atr_ops ub960_atr_ops = { 1342 - .attach_client = ub960_atr_attach_client, 1343 - .detach_client = ub960_atr_detach_client, 1339 + .attach_addr = ub960_atr_attach_addr, 1340 + .detach_addr = ub960_atr_detach_addr, 1344 1341 }; 1345 1342 1346 1343 static int ub960_init_atr(struct ub960_data *priv) ··· 1351 1344 struct i2c_adapter *parent_adap = priv->client->adapter; 1352 1345 1353 1346 priv->atr = i2c_atr_new(parent_adap, dev, &ub960_atr_ops, 1354 - priv->hw_data->num_rxports); 1347 + priv->hw_data->num_rxports, 0); 1355 1348 if (IS_ERR(priv->atr)) 1356 1349 return PTR_ERR(priv->atr); 1357 1350 ··· 2180 2173 struct device *dev = &priv->client->dev; 2181 2174 struct ds90ub9xx_platform_data *ser_pdata = &rxport->ser.pdata; 2182 2175 struct i2c_board_info ser_info = { 2183 - .of_node = to_of_node(rxport->ser.fwnode), 2184 2176 .fwnode = rxport->ser.fwnode, 2185 2177 .platform_data = ser_pdata, 2186 2178 }; ··· 4380 4374 fwnode_handle_put(it.rxport->source.ep_fwnode); 4381 4375 fwnode_handle_put(it.rxport->ser.fwnode); 4382 4376 4377 + mutex_destroy(&it.rxport->aliased_addrs_lock); 4378 + 4383 4379 kfree(it.rxport); 4384 4380 priv->rxports[it.nport] = NULL; 4385 4381 } ··· 4609 4601 ret = ub960_parse_dt_rxport_ep_properties(priv, ep_fwnode, rxport); 4610 4602 if (ret) 4611 4603 goto err_put_remote_fwnode; 4604 + 4605 + mutex_init(&rxport->aliased_addrs_lock); 4612 4606 4613 4607 return 0; 4614 4608
+12
drivers/misc/Kconfig
··· 114 114 115 115 If unsure, select N. 116 116 117 + config TI_FPC202 118 + tristate "TI FPC202 Dual Port Controller" 119 + depends on I2C 120 + select GPIOLIB 121 + select I2C_ATR 122 + help 123 + If you say yes here you get support for the Texas Instruments FPC202 124 + Dual Port Controller. 125 + 126 + This driver can also be built as a module. If so, the module will be 127 + called fpc202. 128 + 117 129 config TIFM_CORE 118 130 tristate "TI Flash Media interface support" 119 131 depends on PCI
+1
drivers/misc/Makefile
··· 12 12 obj-$(CONFIG_DUMMY_IRQ) += dummy-irq.o 13 13 obj-$(CONFIG_ICS932S401) += ics932s401.o 14 14 obj-$(CONFIG_LKDTM) += lkdtm/ 15 + obj-$(CONFIG_TI_FPC202) += ti_fpc202.o 15 16 obj-$(CONFIG_TIFM_CORE) += tifm_core.o 16 17 obj-$(CONFIG_TIFM_7XX1) += tifm_7xx1.o 17 18 obj-$(CONFIG_PHANTOM) += phantom.o
+438
drivers/misc/ti_fpc202.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * ti_fpc202.c - FPC202 Dual Port Controller driver 4 + * 5 + * Copyright (C) 2024 Bootlin 6 + * 7 + */ 8 + 9 + #include <linux/cleanup.h> 10 + #include <linux/err.h> 11 + #include <linux/i2c.h> 12 + #include <linux/i2c-atr.h> 13 + #include <linux/gpio/consumer.h> 14 + #include <linux/gpio/driver.h> 15 + #include <linux/module.h> 16 + 17 + #define FPC202_NUM_PORTS 2 18 + #define FPC202_ALIASES_PER_PORT 2 19 + 20 + /* 21 + * GPIO: port mapping 22 + * 23 + * 0: P0_S0_IN_A 24 + * 1: P0_S1_IN_A 25 + * 2: P1_S0_IN_A 26 + * 3: P1_S1_IN_A 27 + * 4: P0_S0_IN_B 28 + * ... 29 + * 8: P0_S0_IN_C 30 + * ... 31 + * 12: P0_S0_OUT_A 32 + * ... 33 + * 16: P0_S0_OUT_B 34 + * ... 35 + * 19: P1_S1_OUT_B 36 + * 37 + */ 38 + 39 + #define FPC202_GPIO_COUNT 20 40 + #define FPC202_GPIO_P0_S0_IN_B 4 41 + #define FPC202_GPIO_P0_S0_OUT_A 12 42 + 43 + #define FPC202_REG_IN_A_INT 0x6 44 + #define FPC202_REG_IN_C_IN_B 0x7 45 + #define FPC202_REG_OUT_A_OUT_B 0x8 46 + 47 + #define FPC202_REG_OUT_A_OUT_B_VAL 0xa 48 + 49 + #define FPC202_REG_MOD_DEV(port, dev) (0xb4 + ((port) * 4) + (dev)) 50 + #define FPC202_REG_AUX_DEV(port, dev) (0xb6 + ((port) * 4) + (dev)) 51 + 52 + /* 53 + * The FPC202 doesn't support turning off address translation on a single port. 54 + * So just set an invalid I2C address as the translation target when no client 55 + * address is attached. 56 + */ 57 + #define FPC202_REG_DEV_INVALID 0 58 + 59 + /* Even aliases are assigned to device 0 and odd aliases to device 1 */ 60 + #define fpc202_dev_num_from_alias(alias) ((alias) % 2) 61 + 62 + struct fpc202_priv { 63 + struct i2c_client *client; 64 + struct i2c_atr *atr; 65 + struct gpio_desc *en_gpio; 66 + struct gpio_chip gpio; 67 + 68 + /* Lock REG_MOD/AUX_DEV and addr_caches during attach/detach */ 69 + struct mutex reg_dev_lock; 70 + 71 + /* Cached device addresses for both ports and their devices */ 72 + u8 addr_caches[2][2]; 73 + 74 + /* Keep track of which ports were probed */ 75 + DECLARE_BITMAP(probed_ports, FPC202_NUM_PORTS); 76 + }; 77 + 78 + static void fpc202_fill_alias_table(struct i2c_client *client, u16 *aliases, int port_id) 79 + { 80 + u16 first_alias; 81 + int i; 82 + 83 + /* 84 + * There is a predefined list of aliases for each FPC202 I2C 85 + * self-address. This allows daisy-chained FPC202 units to 86 + * automatically take on different sets of aliases. 87 + * Each port of an FPC202 unit is assigned two aliases from this list. 88 + */ 89 + first_alias = 0x10 + 4 * port_id + 8 * ((u16)client->addr - 2); 90 + 91 + for (i = 0; i < FPC202_ALIASES_PER_PORT; i++) 92 + aliases[i] = first_alias + i; 93 + } 94 + 95 + static int fpc202_gpio_get_dir(int offset) 96 + { 97 + return offset < FPC202_GPIO_P0_S0_OUT_A ? GPIO_LINE_DIRECTION_IN : GPIO_LINE_DIRECTION_OUT; 98 + } 99 + 100 + static int fpc202_read(struct fpc202_priv *priv, u8 reg) 101 + { 102 + int val; 103 + 104 + val = i2c_smbus_read_byte_data(priv->client, reg); 105 + return val; 106 + } 107 + 108 + static int fpc202_write(struct fpc202_priv *priv, u8 reg, u8 value) 109 + { 110 + return i2c_smbus_write_byte_data(priv->client, reg, value); 111 + } 112 + 113 + static void fpc202_set_enable(struct fpc202_priv *priv, int enable) 114 + { 115 + if (!priv->en_gpio) 116 + return; 117 + 118 + gpiod_set_value(priv->en_gpio, enable); 119 + } 120 + 121 + static void fpc202_gpio_set(struct gpio_chip *chip, unsigned int offset, 122 + int value) 123 + { 124 + struct fpc202_priv *priv = gpiochip_get_data(chip); 125 + int ret; 126 + u8 val; 127 + 128 + if (fpc202_gpio_get_dir(offset) == GPIO_LINE_DIRECTION_IN) 129 + return; 130 + 131 + ret = fpc202_read(priv, FPC202_REG_OUT_A_OUT_B_VAL); 132 + if (ret < 0) { 133 + dev_err(&priv->client->dev, "Failed to set GPIO %d value! err %d\n", offset, ret); 134 + return; 135 + } 136 + 137 + val = (u8)ret; 138 + 139 + if (value) 140 + val |= BIT(offset - FPC202_GPIO_P0_S0_OUT_A); 141 + else 142 + val &= ~BIT(offset - FPC202_GPIO_P0_S0_OUT_A); 143 + 144 + fpc202_write(priv, FPC202_REG_OUT_A_OUT_B_VAL, val); 145 + } 146 + 147 + static int fpc202_gpio_get(struct gpio_chip *chip, unsigned int offset) 148 + { 149 + struct fpc202_priv *priv = gpiochip_get_data(chip); 150 + u8 reg, bit; 151 + int ret; 152 + 153 + if (offset < FPC202_GPIO_P0_S0_IN_B) { 154 + reg = FPC202_REG_IN_A_INT; 155 + bit = BIT(4 + offset); 156 + } else if (offset < FPC202_GPIO_P0_S0_OUT_A) { 157 + reg = FPC202_REG_IN_C_IN_B; 158 + bit = BIT(offset - FPC202_GPIO_P0_S0_IN_B); 159 + } else { 160 + reg = FPC202_REG_OUT_A_OUT_B_VAL; 161 + bit = BIT(offset - FPC202_GPIO_P0_S0_OUT_A); 162 + } 163 + 164 + ret = fpc202_read(priv, reg); 165 + if (ret < 0) 166 + return ret; 167 + 168 + return !!(((u8)ret) & bit); 169 + } 170 + 171 + static int fpc202_gpio_direction_input(struct gpio_chip *chip, unsigned int offset) 172 + { 173 + if (fpc202_gpio_get_dir(offset) == GPIO_LINE_DIRECTION_OUT) 174 + return -EINVAL; 175 + 176 + return 0; 177 + } 178 + 179 + static int fpc202_gpio_direction_output(struct gpio_chip *chip, unsigned int offset, 180 + int value) 181 + { 182 + struct fpc202_priv *priv = gpiochip_get_data(chip); 183 + int ret; 184 + u8 val; 185 + 186 + if (fpc202_gpio_get_dir(offset) == GPIO_LINE_DIRECTION_IN) 187 + return -EINVAL; 188 + 189 + fpc202_gpio_set(chip, offset, value); 190 + 191 + ret = fpc202_read(priv, FPC202_REG_OUT_A_OUT_B); 192 + if (ret < 0) 193 + return ret; 194 + 195 + val = (u8)ret | BIT(offset - FPC202_GPIO_P0_S0_OUT_A); 196 + 197 + return fpc202_write(priv, FPC202_REG_OUT_A_OUT_B, val); 198 + } 199 + 200 + /* 201 + * Set the translation table entry associated with a port and device number. 202 + * 203 + * Each downstream port of the FPC202 has two fixed aliases corresponding to 204 + * device numbers 0 and 1. If one of these aliases is found in an incoming I2C 205 + * transfer, it will be translated to the address given by the corresponding 206 + * translation table entry. 207 + */ 208 + static int fpc202_write_dev_addr(struct fpc202_priv *priv, u32 port_id, int dev_num, u16 addr) 209 + { 210 + int ret, reg_mod, reg_aux; 211 + u8 val; 212 + 213 + guard(mutex)(&priv->reg_dev_lock); 214 + 215 + reg_mod = FPC202_REG_MOD_DEV(port_id, dev_num); 216 + reg_aux = FPC202_REG_AUX_DEV(port_id, dev_num); 217 + val = addr & 0x7f; 218 + 219 + ret = fpc202_write(priv, reg_mod, val); 220 + if (ret) 221 + return ret; 222 + 223 + /* 224 + * The FPC202 datasheet is unclear about the role of the AUX registers. 225 + * Empirically, writing to them as well seems to be necessary for 226 + * address translation to function properly. 227 + */ 228 + ret = fpc202_write(priv, reg_aux, val); 229 + 230 + priv->addr_caches[port_id][dev_num] = val; 231 + 232 + return ret; 233 + } 234 + 235 + static int fpc202_attach_addr(struct i2c_atr *atr, u32 chan_id, 236 + u16 addr, u16 alias) 237 + { 238 + struct fpc202_priv *priv = i2c_atr_get_driver_data(atr); 239 + 240 + dev_dbg(&priv->client->dev, "attaching address 0x%02x to alias 0x%02x\n", addr, alias); 241 + 242 + return fpc202_write_dev_addr(priv, chan_id, fpc202_dev_num_from_alias(alias), addr); 243 + } 244 + 245 + static void fpc202_detach_addr(struct i2c_atr *atr, u32 chan_id, 246 + u16 addr) 247 + { 248 + struct fpc202_priv *priv = i2c_atr_get_driver_data(atr); 249 + int dev_num, reg_mod, val; 250 + 251 + for (dev_num = 0; dev_num < 2; dev_num++) { 252 + reg_mod = FPC202_REG_MOD_DEV(chan_id, dev_num); 253 + 254 + mutex_lock(&priv->reg_dev_lock); 255 + 256 + val = priv->addr_caches[chan_id][dev_num]; 257 + 258 + mutex_unlock(&priv->reg_dev_lock); 259 + 260 + if (val < 0) { 261 + dev_err(&priv->client->dev, "failed to read register 0x%x while detaching address 0x%02x\n", 262 + reg_mod, addr); 263 + return; 264 + } 265 + 266 + if (val == (addr & 0x7f)) { 267 + fpc202_write_dev_addr(priv, chan_id, dev_num, FPC202_REG_DEV_INVALID); 268 + return; 269 + } 270 + } 271 + } 272 + 273 + static const struct i2c_atr_ops fpc202_atr_ops = { 274 + .attach_addr = fpc202_attach_addr, 275 + .detach_addr = fpc202_detach_addr, 276 + }; 277 + 278 + static int fpc202_probe_port(struct fpc202_priv *priv, struct device_node *i2c_handle, int port_id) 279 + { 280 + u16 aliases[FPC202_ALIASES_PER_PORT] = { }; 281 + struct device *dev = &priv->client->dev; 282 + struct i2c_atr_adap_desc desc = { }; 283 + int ret = 0; 284 + 285 + desc.chan_id = port_id; 286 + desc.parent = dev; 287 + desc.bus_handle = of_node_to_fwnode(i2c_handle); 288 + desc.num_aliases = FPC202_ALIASES_PER_PORT; 289 + 290 + fpc202_fill_alias_table(priv->client, aliases, port_id); 291 + desc.aliases = aliases; 292 + 293 + ret = i2c_atr_add_adapter(priv->atr, &desc); 294 + if (ret) 295 + return ret; 296 + 297 + set_bit(port_id, priv->probed_ports); 298 + 299 + ret = fpc202_write_dev_addr(priv, port_id, 0, FPC202_REG_DEV_INVALID); 300 + if (ret) 301 + return ret; 302 + 303 + return fpc202_write_dev_addr(priv, port_id, 1, FPC202_REG_DEV_INVALID); 304 + } 305 + 306 + static void fpc202_remove_port(struct fpc202_priv *priv, int port_id) 307 + { 308 + i2c_atr_del_adapter(priv->atr, port_id); 309 + clear_bit(port_id, priv->probed_ports); 310 + } 311 + 312 + static int fpc202_probe(struct i2c_client *client) 313 + { 314 + struct device *dev = &client->dev; 315 + struct device_node *i2c_handle; 316 + struct fpc202_priv *priv; 317 + int ret, port_id; 318 + 319 + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 320 + if (!priv) 321 + return -ENOMEM; 322 + 323 + mutex_init(&priv->reg_dev_lock); 324 + 325 + priv->client = client; 326 + i2c_set_clientdata(client, priv); 327 + 328 + priv->en_gpio = devm_gpiod_get_optional(dev, "enable", GPIOD_OUT_HIGH); 329 + if (IS_ERR(priv->en_gpio)) { 330 + ret = PTR_ERR(priv->en_gpio); 331 + dev_err(dev, "failed to fetch enable GPIO! err %d\n", ret); 332 + goto destroy_mutex; 333 + } 334 + 335 + priv->gpio.label = "gpio-fpc202"; 336 + priv->gpio.base = -1; 337 + priv->gpio.direction_input = fpc202_gpio_direction_input; 338 + priv->gpio.direction_output = fpc202_gpio_direction_output; 339 + priv->gpio.set = fpc202_gpio_set; 340 + priv->gpio.get = fpc202_gpio_get; 341 + priv->gpio.ngpio = FPC202_GPIO_COUNT; 342 + priv->gpio.parent = dev; 343 + priv->gpio.owner = THIS_MODULE; 344 + 345 + ret = gpiochip_add_data(&priv->gpio, priv); 346 + if (ret) { 347 + priv->gpio.parent = NULL; 348 + dev_err(dev, "failed to add gpiochip err %d\n", ret); 349 + goto disable_gpio; 350 + } 351 + 352 + priv->atr = i2c_atr_new(client->adapter, dev, &fpc202_atr_ops, 2, 0); 353 + if (IS_ERR(priv->atr)) { 354 + ret = PTR_ERR(priv->atr); 355 + dev_err(dev, "failed to create i2c atr err %d\n", ret); 356 + goto disable_gpio; 357 + } 358 + 359 + i2c_atr_set_driver_data(priv->atr, priv); 360 + 361 + bitmap_zero(priv->probed_ports, FPC202_NUM_PORTS); 362 + 363 + for_each_child_of_node(dev->of_node, i2c_handle) { 364 + ret = of_property_read_u32(i2c_handle, "reg", &port_id); 365 + if (ret) { 366 + if (ret == -EINVAL) 367 + continue; 368 + 369 + dev_err(dev, "failed to read 'reg' property of child node, err %d\n", ret); 370 + goto unregister_chans; 371 + } 372 + 373 + if (port_id > FPC202_NUM_PORTS) { 374 + dev_err(dev, "port ID %d is out of range!\n", port_id); 375 + ret = -EINVAL; 376 + goto unregister_chans; 377 + } 378 + 379 + ret = fpc202_probe_port(priv, i2c_handle, port_id); 380 + if (ret) { 381 + dev_err(dev, "Failed to probe port %d, err %d\n", port_id, ret); 382 + goto unregister_chans; 383 + } 384 + } 385 + 386 + goto out; 387 + 388 + unregister_chans: 389 + for_each_set_bit(port_id, priv->probed_ports, FPC202_NUM_PORTS) 390 + fpc202_remove_port(priv, port_id); 391 + 392 + i2c_atr_delete(priv->atr); 393 + disable_gpio: 394 + fpc202_set_enable(priv, 0); 395 + gpiochip_remove(&priv->gpio); 396 + destroy_mutex: 397 + mutex_destroy(&priv->reg_dev_lock); 398 + out: 399 + return ret; 400 + } 401 + 402 + static void fpc202_remove(struct i2c_client *client) 403 + { 404 + struct fpc202_priv *priv = i2c_get_clientdata(client); 405 + int port_id; 406 + 407 + for_each_set_bit(port_id, priv->probed_ports, FPC202_NUM_PORTS) 408 + fpc202_remove_port(priv, port_id); 409 + 410 + mutex_destroy(&priv->reg_dev_lock); 411 + 412 + i2c_atr_delete(priv->atr); 413 + 414 + fpc202_set_enable(priv, 0); 415 + gpiochip_remove(&priv->gpio); 416 + } 417 + 418 + static const struct of_device_id fpc202_of_match[] = { 419 + { .compatible = "ti,fpc202" }, 420 + {} 421 + }; 422 + MODULE_DEVICE_TABLE(of, fpc202_of_match); 423 + 424 + static struct i2c_driver fpc202_driver = { 425 + .driver = { 426 + .name = "fpc202", 427 + .of_match_table = fpc202_of_match, 428 + }, 429 + .probe = fpc202_probe, 430 + .remove = fpc202_remove, 431 + }; 432 + 433 + module_i2c_driver(fpc202_driver); 434 + 435 + MODULE_AUTHOR("Romain Gantois <romain.gantois@bootlin.com>"); 436 + MODULE_DESCRIPTION("TI FPC202 Dual Port Controller driver"); 437 + MODULE_LICENSE("GPL"); 438 + MODULE_IMPORT_NS("I2C_ATR");
+53 -20
include/linux/i2c-atr.h
··· 19 19 struct i2c_atr; 20 20 21 21 /** 22 + * enum i2c_atr_flags - Flags for an I2C ATR driver 23 + * 24 + * @I2C_ATR_F_STATIC: ATR does not support dynamic mapping, use static mapping. 25 + * Mappings will only be added or removed as a result of 26 + * devices being added or removed from a child bus. 27 + * The ATR pool will have to be big enough to accomodate all 28 + * devices expected to be added to the child buses. 29 + * @I2C_ATR_F_PASSTHROUGH: Allow unmapped incoming addresses to pass through 30 + */ 31 + enum i2c_atr_flags { 32 + I2C_ATR_F_STATIC = BIT(0), 33 + I2C_ATR_F_PASSTHROUGH = BIT(1), 34 + }; 35 + 36 + /** 22 37 * struct i2c_atr_ops - Callbacks from ATR to the device driver. 23 - * @attach_client: Notify the driver of a new device connected on a child 24 - * bus, with the alias assigned to it. The driver must 25 - * configure the hardware to use the alias. 26 - * @detach_client: Notify the driver of a device getting disconnected. The 27 - * driver must configure the hardware to stop using the 28 - * alias. 38 + * @attach_addr: Notify the driver of a new device connected on a child 39 + * bus, with the alias assigned to it. The driver must 40 + * configure the hardware to use the alias. 41 + * @detach_addr: Notify the driver of a device getting disconnected. The 42 + * driver must configure the hardware to stop using the 43 + * alias. 29 44 * 30 45 * All these functions return 0 on success, a negative error code otherwise. 31 46 */ 32 47 struct i2c_atr_ops { 33 - int (*attach_client)(struct i2c_atr *atr, u32 chan_id, 34 - const struct i2c_client *client, u16 alias); 35 - void (*detach_client)(struct i2c_atr *atr, u32 chan_id, 36 - const struct i2c_client *client); 48 + int (*attach_addr)(struct i2c_atr *atr, u32 chan_id, 49 + u16 addr, u16 alias); 50 + void (*detach_addr)(struct i2c_atr *atr, u32 chan_id, 51 + u16 addr); 52 + }; 53 + 54 + /** 55 + * struct i2c_atr_adap_desc - An ATR downstream bus descriptor 56 + * @chan_id: Index of the new adapter (0 .. max_adapters-1). This value is 57 + * passed to the callbacks in `struct i2c_atr_ops`. 58 + * @parent: The device used as the parent of the new i2c adapter, or NULL 59 + * to use the i2c-atr device as the parent. 60 + * @bus_handle: The fwnode handle that points to the adapter's i2c 61 + * peripherals, or NULL. 62 + * @num_aliases: The number of aliases in this adapter's private alias pool. Set 63 + * to zero if this adapter uses the ATR's global alias pool. 64 + * @aliases: An optional array of private aliases used by the adapter 65 + * instead of the ATR's global pool of aliases. Must contain 66 + * exactly num_aliases entries if num_aliases > 0, is ignored 67 + * otherwise. 68 + */ 69 + struct i2c_atr_adap_desc { 70 + u32 chan_id; 71 + struct device *parent; 72 + struct fwnode_handle *bus_handle; 73 + size_t num_aliases; 74 + u16 *aliases; 37 75 }; 38 76 39 77 /** ··· 80 42 * @dev: The device acting as an ATR 81 43 * @ops: Driver-specific callbacks 82 44 * @max_adapters: Maximum number of child adapters 45 + * @flags: Flags for ATR 83 46 * 84 47 * The new ATR helper is connected to the parent adapter but has no child 85 48 * adapters. Call i2c_atr_add_adapter() to add some. ··· 90 51 * Return: pointer to the new ATR helper object, or ERR_PTR 91 52 */ 92 53 struct i2c_atr *i2c_atr_new(struct i2c_adapter *parent, struct device *dev, 93 - const struct i2c_atr_ops *ops, int max_adapters); 54 + const struct i2c_atr_ops *ops, int max_adapters, 55 + u32 flags); 94 56 95 57 /** 96 58 * i2c_atr_delete - Delete an I2C ATR helper. ··· 105 65 /** 106 66 * i2c_atr_add_adapter - Create a child ("downstream") I2C bus. 107 67 * @atr: The I2C ATR 108 - * @chan_id: Index of the new adapter (0 .. max_adapters-1). This value is 109 - * passed to the callbacks in `struct i2c_atr_ops`. 110 - * @adapter_parent: The device used as the parent of the new i2c adapter, or NULL 111 - * to use the i2c-atr device as the parent. 112 - * @bus_handle: The fwnode handle that points to the adapter's i2c 113 - * peripherals, or NULL. 68 + * @desc: An ATR adapter descriptor 114 69 * 115 70 * After calling this function a new i2c bus will appear. Adding and removing 116 71 * devices on the downstream bus will result in calls to the ··· 120 85 * 121 86 * Return: 0 on success, a negative error code otherwise. 122 87 */ 123 - int i2c_atr_add_adapter(struct i2c_atr *atr, u32 chan_id, 124 - struct device *adapter_parent, 125 - struct fwnode_handle *bus_handle); 88 + int i2c_atr_add_adapter(struct i2c_atr *atr, struct i2c_atr_adap_desc *desc); 126 89 127 90 /** 128 91 * i2c_atr_del_adapter - Remove a child ("downstream") I2C bus added by
+4 -2
include/linux/i2c-smbus.h
··· 44 44 #endif 45 45 46 46 #if IS_ENABLED(CONFIG_I2C_SMBUS) && IS_ENABLED(CONFIG_DMI) 47 - void i2c_register_spd(struct i2c_adapter *adap); 47 + void i2c_register_spd_write_disable(struct i2c_adapter *adap); 48 + void i2c_register_spd_write_enable(struct i2c_adapter *adap); 48 49 #else 49 - static inline void i2c_register_spd(struct i2c_adapter *adap) { } 50 + static inline void i2c_register_spd_write_disable(struct i2c_adapter *adap) { } 51 + static inline void i2c_register_spd_write_enable(struct i2c_adapter *adap) { } 50 52 #endif 51 53 52 54 #endif /* _LINUX_I2C_SMBUS_H */
-2
include/linux/i2c.h
··· 405 405 * @addr: stored in i2c_client.addr 406 406 * @dev_name: Overrides the default <busnr>-<addr> dev_name if set 407 407 * @platform_data: stored in i2c_client.dev.platform_data 408 - * @of_node: pointer to OpenFirmware device node 409 408 * @fwnode: device node supplied by the platform firmware 410 409 * @swnode: software node for the device 411 410 * @resources: resources associated with the device ··· 428 429 unsigned short addr; 429 430 const char *dev_name; 430 431 void *platform_data; 431 - struct device_node *of_node; 432 432 struct fwnode_handle *fwnode; 433 433 const struct software_node *swnode; 434 434 const struct resource *resources;