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

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

Pull i2c updates from Wolfram Sang:
"Core:

- drivers can now use a GPIO as a side channel for SMBus Alerts using
a generic binding

- regular stuff like mem leak fix, Makefile maintenance...

Host improvements and refactoring:

- All controllers using the 'remove_new' callback have been reverted
to use the 'remove' callback

- Intel SCH controller underwent significant refactoring, this brings
love and a modern look to the driver

- PIIX4 driver refactored to enable usage by other drivers (e.g., AMD
ASF)

- iMX/MXC improved message handling to reduce protocol overhead:
Refactored DMA/non-DMA read/write and bus polling mechanisms to
achieve this.

- ACPI documentation for PIIX4

New host features:

- i2c-cadence support for atomic transfers

- Qualcomm CII support for a 32MHz serial engine clock

Deprecated features:

- Dropped outdated support for AMD756 S4882 and NFORCE2 S4985. If
somebody misses this, Jean will rewrite support using the proper
i2c mux framework.

New hardware IDs for existing drivers:

- Intel Panther Lake

- S32G2/S32G3 SoCs

- HJMC01 DesignWare ACPI HID

- PIC64GX to Microchip Core

- Qualcomm SDM670 to Qualcomm CCI

New drivers:

- AMD ASF

- Realtek RTL I2C Controller

at24 updates:

- add support for the lockable page on ST M24256E"

* tag 'i2c-for-6.13-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux: (59 commits)
docs: i2c: piix4: Add ACPI section
i2c: Add driver for the RTL9300 I2C controller
i2c: qcom-cci: Remove unused struct member cci_clk_rate
dt-bindings: i2c: Add Realtek RTL I2C Controller
i2c: busses: Use *-y instead of *-objs in Makefile
i2c: imx: add support for S32G2/S32G3 SoCs
dt-bindings: i2c: imx: add SoC specific compatible strings for S32G
i2c: qcom-cci: Remove the unused variable cci_clk_rate
i2c: Drop legacy muxing pseudo-drivers
i2c: imx: prevent rescheduling in non dma mode
i2c: imx: separate atomic, dma and non-dma use case
i2c: imx: do not poll for bus busy in single master mode
i2c: designware: Add a new ACPI HID for HJMC01 I2C controller
i2c: qcom-geni: Keep comment why interrupts start disabled
dt-bindings: i2c: microchip: corei2c: Add PIC64GX as compatible with driver
i2c: designware: constify abort_sources
i2c: Switch back to struct platform_driver::remove()
i2c: qcom-geni: Support systems with 32MHz serial engine clock
i2c: qcom-cci: Stop complaining about DT set clock rate
dt-bindings: i2c: qcom-cci: Document SDM670 compatible
...

+2184 -1178
+2
Documentation/devicetree/bindings/eeprom/at24.yaml
··· 141 141 - const: microchip,24aa025e48 142 142 - items: 143 143 - const: microchip,24aa025e64 144 + - items: 145 + - const: st,24256e-wl 144 146 - pattern: '^atmel,24c(32|64)d-wl$' # Actual vendor is st 145 147 146 148 label:
+4
Documentation/devicetree/bindings/i2c/i2c-imx.yaml
··· 18 18 - const: fsl,imx1-i2c 19 19 - const: fsl,imx21-i2c 20 20 - const: fsl,vf610-i2c 21 + - const: nxp,s32g2-i2c 21 22 - items: 22 23 - enum: 23 24 - fsl,ls1012a-i2c ··· 55 54 - fsl,imx8mn-i2c 56 55 - fsl,imx8mp-i2c 57 56 - const: fsl,imx21-i2c 57 + - items: 58 + - const: nxp,s32g3-i2c 59 + - const: nxp,s32g2-i2c 58 60 59 61 reg: 60 62 maxItems: 1
+3 -1
Documentation/devicetree/bindings/i2c/microchip,corei2c.yaml
··· 16 16 compatible: 17 17 oneOf: 18 18 - items: 19 - - const: microchip,mpfs-i2c # Microchip PolarFire SoC compatible SoCs 19 + - enum: 20 + - microchip,pic64gx-i2c 21 + - microchip,mpfs-i2c # Microchip PolarFire SoC compatible SoCs 20 22 - const: microchip,corei2c-rtl-v7 # Microchip Fabric based i2c IP core 21 23 - const: microchip,corei2c-rtl-v7 # Microchip Fabric based i2c IP core 22 24
+19
Documentation/devicetree/bindings/i2c/qcom,i2c-cci.yaml
··· 27 27 - enum: 28 28 - qcom,sc7280-cci 29 29 - qcom,sc8280xp-cci 30 + - qcom,sdm670-cci 30 31 - qcom,sdm845-cci 31 32 - qcom,sm6350-cci 32 33 - qcom,sm8250-cci ··· 139 138 - const: cci_ahb 140 139 - const: cci 141 140 - const: camss_ahb 141 + 142 + - if: 143 + properties: 144 + compatible: 145 + contains: 146 + enum: 147 + - qcom,sdm670-cci 148 + then: 149 + properties: 150 + clocks: 151 + minItems: 4 152 + maxItems: 4 153 + clock-names: 154 + items: 155 + - const: camnoc_axi 156 + - const: soc_ahb 157 + - const: cpas_ahb 158 + - const: cci 142 159 143 160 - if: 144 161 properties:
+69
Documentation/devicetree/bindings/i2c/realtek,rtl9301-i2c.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/i2c/realtek,rtl9301-i2c.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Realtek RTL I2C Controller 8 + 9 + maintainers: 10 + - Chris Packham <chris.packham@alliedtelesis.co.nz> 11 + 12 + description: 13 + The RTL9300 SoC has two I2C controllers. Each of these has an SCL line (which 14 + if not-used for SCL can be a GPIO). There are 8 common SDA lines that can be 15 + assigned to either I2C controller. 16 + 17 + properties: 18 + compatible: 19 + oneOf: 20 + - items: 21 + - enum: 22 + - realtek,rtl9302b-i2c 23 + - realtek,rtl9302c-i2c 24 + - realtek,rtl9303-i2c 25 + - const: realtek,rtl9301-i2c 26 + - const: realtek,rtl9301-i2c 27 + 28 + reg: 29 + description: Register offset and size this I2C controller. 30 + 31 + "#address-cells": 32 + const: 1 33 + 34 + "#size-cells": 35 + const: 0 36 + 37 + patternProperties: 38 + '^i2c@[0-7]$': 39 + $ref: /schemas/i2c/i2c-controller.yaml 40 + unevaluatedProperties: false 41 + 42 + properties: 43 + reg: 44 + description: The SDA pin associated with the I2C bus. 45 + maxItems: 1 46 + 47 + required: 48 + - reg 49 + 50 + required: 51 + - compatible 52 + - reg 53 + 54 + additionalProperties: false 55 + 56 + examples: 57 + - | 58 + i2c@36c { 59 + compatible = "realtek,rtl9301-i2c"; 60 + reg = <0x36c 0x14>; 61 + #address-cells = <1>; 62 + #size-cells = <0>; 63 + 64 + i2c@2 { 65 + reg = <2>; 66 + #address-cells = <1>; 67 + #size-cells = <0>; 68 + }; 69 + };
+1
Documentation/i2c/busses/i2c-i801.rst
··· 49 49 * Intel Meteor Lake (SOC and PCH) 50 50 * Intel Birch Stream (SOC) 51 51 * Intel Arrow Lake (SOC) 52 + * Intel Panther Lake (SOC) 52 53 53 54 Datasheets: Publicly available at the Intel website 54 55
+63
Documentation/i2c/busses/i2c-piix4.rst
··· 109 109 Thinkpad laptops, but desktop systems may also be affected. We have no list 110 110 of all affected systems, so the only safe solution was to prevent access to 111 111 the SMBus on all IBM systems (detected using DMI data.) 112 + 113 + 114 + Description in the ACPI code 115 + ---------------------------- 116 + 117 + Device driver for the PIIX4 chip creates a separate I2C bus for each of its 118 + ports:: 119 + 120 + $ i2cdetect -l 121 + ... 122 + i2c-7 unknown SMBus PIIX4 adapter port 0 at 0b00 N/A 123 + i2c-8 unknown SMBus PIIX4 adapter port 2 at 0b00 N/A 124 + i2c-9 unknown SMBus PIIX4 adapter port 1 at 0b20 N/A 125 + ... 126 + 127 + Therefore if you want to access one of these busses in the ACPI code, port 128 + subdevices are needed to be declared inside the PIIX device:: 129 + 130 + Scope (\_SB_.PCI0.SMBS) 131 + { 132 + Name (_ADR, 0x00140000) 133 + 134 + Device (SMB0) { 135 + Name (_ADR, 0) 136 + } 137 + Device (SMB1) { 138 + Name (_ADR, 1) 139 + } 140 + Device (SMB2) { 141 + Name (_ADR, 2) 142 + } 143 + } 144 + 145 + If this is not the case for your UEFI firmware and you don't have access to the 146 + source code, you can use ACPI SSDT Overlays to provide the missing parts. Just 147 + keep in mind that in this case you would need to load your extra SSDT table 148 + before the piix4 driver starts, i.e. you should provide SSDT via initrd or EFI 149 + variable methods and not via configfs. 150 + 151 + As an example of usage here is the ACPI snippet code that would assign jc42 152 + driver to the 0x1C device on the I2C bus created by the PIIX port 0:: 153 + 154 + Device (JC42) { 155 + Name (_HID, "PRP0001") 156 + Name (_DDN, "JC42 Temperature sensor") 157 + Name (_CRS, ResourceTemplate () { 158 + I2cSerialBusV2 ( 159 + 0x001c, 160 + ControllerInitiated, 161 + 100000, 162 + AddressingMode7Bit, 163 + "\\_SB.PCI0.SMBS.SMB0", 164 + 0 165 + ) 166 + }) 167 + 168 + Name (_DSD, Package () { 169 + ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"), 170 + Package () { 171 + Package () { "compatible", Package() { "jedec,jc-42.4-temp" } }, 172 + } 173 + }) 174 + }
+1 -2
Documentation/i2c/writing-clients.rst
··· 31 31 32 32 :: 33 33 34 - static struct i2c_device_id foo_idtable[] = { 34 + static const struct i2c_device_id foo_idtable[] = { 35 35 { "foo", my_id_for_foo }, 36 36 { "bar", my_id_for_bar }, 37 37 { } 38 38 }; 39 - 40 39 MODULE_DEVICE_TABLE(i2c, foo_idtable); 41 40 42 41 static struct i2c_driver foo_driver = {
+14 -3
MAINTAINERS
··· 1115 1115 S: Maintained 1116 1116 F: drivers/i2c/busses/i2c-amd-mp2* 1117 1117 1118 + AMD ASF I2C DRIVER 1119 + M: Shyam Sundar S K <shyam-sundar.s-k@amd.com> 1120 + L: linux-i2c@vger.kernel.org 1121 + S: Supported 1122 + F: drivers/i2c/busses/i2c-amd-asf-plat.c 1123 + 1118 1124 AMD PDS CORE DRIVER 1119 1125 M: Shannon Nelson <shannon.nelson@amd.com> 1120 1126 M: Brett Creeley <brett.creeley@amd.com> ··· 10756 10750 F: drivers/i2c/busses/i2c-ali1535.c 10757 10751 F: drivers/i2c/busses/i2c-ali1563.c 10758 10752 F: drivers/i2c/busses/i2c-ali15x3.c 10759 - F: drivers/i2c/busses/i2c-amd756-s4882.c 10760 10753 F: drivers/i2c/busses/i2c-amd756.c 10761 10754 F: drivers/i2c/busses/i2c-amd8111.c 10762 10755 F: drivers/i2c/busses/i2c-i801.c 10763 10756 F: drivers/i2c/busses/i2c-isch.c 10764 - F: drivers/i2c/busses/i2c-nforce2-s4985.c 10765 10757 F: drivers/i2c/busses/i2c-nforce2.c 10766 - F: drivers/i2c/busses/i2c-piix4.c 10758 + F: drivers/i2c/busses/i2c-piix4.* 10767 10759 F: drivers/i2c/busses/i2c-sis5595.c 10768 10760 F: drivers/i2c/busses/i2c-sis630.c 10769 10761 F: drivers/i2c/busses/i2c-sis96x.c ··· 20221 20217 S: Maintained 20222 20218 T: git https://github.com/pkshih/rtw.git 20223 20219 F: drivers/net/wireless/realtek/rtl8xxxu/ 20220 + 20221 + RTL9300 I2C DRIVER (rtl9300-i2c) 20222 + M: Chris Packham <chris.packham@alliedtelesis.co.nz> 20223 + L: linux-i2c@vger.kernel.org 20224 + S: Maintained 20225 + F: Documentation/devicetree/bindings/i2c/realtek,rtl9301-i2c.yaml 20226 + F: drivers/i2c/busses/i2c-rtl9300.c 20224 20227 20225 20228 RTRS TRANSPORT DRIVERS 20226 20229 M: Md. Haris Iqbal <haris.iqbal@ionos.com>
+3 -3
drivers/i2c/Makefile
··· 5 5 6 6 obj-$(CONFIG_I2C_BOARDINFO) += i2c-boardinfo.o 7 7 obj-$(CONFIG_I2C) += i2c-core.o 8 - i2c-core-objs := i2c-core-base.o i2c-core-smbus.o 8 + i2c-core-y := i2c-core-base.o i2c-core-smbus.o 9 9 i2c-core-$(CONFIG_ACPI) += i2c-core-acpi.o 10 - i2c-core-$(CONFIG_I2C_SLAVE) += i2c-core-slave.o 11 - i2c-core-$(CONFIG_OF) += i2c-core-of.o 10 + i2c-core-$(CONFIG_I2C_SLAVE) += i2c-core-slave.o 11 + i2c-core-$(CONFIG_OF) += i2c-core-of.o 12 12 13 13 obj-$(CONFIG_I2C_SMBUS) += i2c-smbus.o 14 14 obj-$(CONFIG_I2C_CHARDEV) += i2c-dev.o
+34 -31
drivers/i2c/busses/Kconfig
··· 62 62 This driver can also be built as a module. If so, the module 63 63 will be called i2c-amd756. 64 64 65 - config I2C_AMD756_S4882 66 - tristate "SMBus multiplexing on the Tyan S4882" 67 - depends on I2C_AMD756 && X86 68 - help 69 - Enabling this option will add specific SMBus support for the Tyan 70 - S4882 motherboard. On this 4-CPU board, the SMBus is multiplexed 71 - over 8 different channels, where the various memory module EEPROMs 72 - and temperature sensors live. Saying yes here will give you access 73 - to these in addition to the trunk. 74 - 75 - This driver can also be built as a module. If so, the module 76 - will be called i2c-amd756-s4882. 77 - 78 65 config I2C_AMD8111 79 66 tristate "AMD 8111" 80 67 depends on PCI && HAS_IOPORT ··· 81 94 82 95 This driver can also be built as modules. If so, the modules will 83 96 be called i2c-amd-mp2-pci and i2c-amd-mp2-plat. 97 + 98 + config I2C_AMD_ASF 99 + tristate "AMD ASF I2C Controller Support" 100 + depends on I2C_PIIX4 101 + select I2C_SLAVE 102 + help 103 + This option enables support for the AMD ASF (Alert Standard Format) 104 + I2C controller. The AMD ASF controller is an SMBus controller with 105 + built-in ASF functionality, allowing it to issue generic SMBus 106 + packets and communicate with the DASH controller using MCTP over 107 + ASF. 108 + 109 + If you have an AMD system with ASF support and want to enable this 110 + functionality, say Y or M here. If unsure, say N. 111 + 112 + To compile this driver as a module, choose M here: the module will 113 + be called i2c_amd_asf_plat. 84 114 85 115 config I2C_HIX5HD2 86 116 tristate "Hix5hd2 high-speed I2C driver" ··· 164 160 Meteor Lake (SOC and PCH) 165 161 Birch Stream (SOC) 166 162 Arrow Lake (SOC) 163 + Panther Lake (SOC) 167 164 168 165 This driver can also be built as a module. If so, the module 169 166 will be called i2c-i801. ··· 254 249 255 250 This driver can also be built as a module. If so, the module 256 251 will be called i2c-nforce2. 257 - 258 - config I2C_NFORCE2_S4985 259 - tristate "SMBus multiplexing on the Tyan S4985" 260 - depends on I2C_NFORCE2 && X86 261 - help 262 - Enabling this option will add specific SMBus support for the Tyan 263 - S4985 motherboard. On this 4-CPU board, the SMBus is multiplexed 264 - over 4 different channels, where the various memory module EEPROMs 265 - live. Saying yes here will give you access to these in addition 266 - to the trunk. 267 - 268 - This driver can also be built as a module. If so, the module 269 - will be called i2c-nforce2-s4985. 270 252 271 253 config I2C_NVIDIA_GPU 272 254 tristate "NVIDIA GPU I2C controller" ··· 431 439 are facing this situation, use the i2c-gpio driver. 432 440 433 441 config I2C_AT91_SLAVE_EXPERIMENTAL 434 - tristate "Microchip AT91 I2C experimental slave mode" 442 + bool "Microchip AT91 I2C experimental slave mode" 435 443 depends on I2C_AT91 436 444 select I2C_SLAVE 437 445 help ··· 440 448 been tested in a heavy way, help wanted. 441 449 There are known bugs: 442 450 - It can hang, on a SAMA5D4, after several transfers. 443 - - There are some mismtaches with a SAMA5D4 as slave and a SAMA5D2 as 451 + - There are some mismatches with a SAMA5D4 as slave and a SAMA5D2 as 444 452 master. 445 453 446 454 config I2C_AU1550 ··· 743 751 744 752 config I2C_IMX 745 753 tristate "IMX I2C interface" 746 - depends on ARCH_MXC || ARCH_LAYERSCAPE || COLDFIRE || COMPILE_TEST 754 + depends on ARCH_MXC || ARCH_LAYERSCAPE || ARCH_S32 || COLDFIRE \ 755 + || COMPILE_TEST 747 756 select I2C_SLAVE 748 757 help 749 758 Say Y here if you want to use the IIC bus controller on 750 - the Freescale i.MX/MXC, Layerscape or ColdFire processors. 759 + the Freescale i.MX/MXC/S32G, Layerscape or ColdFire processors. 751 760 752 - This driver can also be built as a module. If so, the module 761 + This driver can also be built as a module. If so, the module 753 762 will be called i2c-imx. 754 763 755 764 config I2C_IMX_LPI2C ··· 1062 1069 1063 1070 This driver can also be built as a module. If so, the module will 1064 1071 be called i2c-rk3x. 1072 + 1073 + config I2C_RTL9300 1074 + tristate "Realtek RTL9300 I2C controller" 1075 + depends on MACH_REALTEK_RTL || COMPILE_TEST 1076 + help 1077 + Say Y here to include support for the I2C controller in Realtek 1078 + RTL9300 SoCs. 1079 + 1080 + This driver can also be built as a module. If so, the module will 1081 + be called i2c-rtl9300. 1065 1082 1066 1083 config I2C_RZV2M 1067 1084 tristate "Renesas RZ/V2M adapter"
+7 -9
drivers/i2c/busses/Makefile
··· 14 14 obj-$(CONFIG_I2C_ALI1563) += i2c-ali1563.o 15 15 obj-$(CONFIG_I2C_ALI15X3) += i2c-ali15x3.o 16 16 obj-$(CONFIG_I2C_AMD756) += i2c-amd756.o 17 - obj-$(CONFIG_I2C_AMD756_S4882) += i2c-amd756-s4882.o 18 17 obj-$(CONFIG_I2C_AMD8111) += i2c-amd8111.o 19 18 obj-$(CONFIG_I2C_CHT_WC) += i2c-cht-wc.o 20 19 obj-$(CONFIG_I2C_I801) += i2c-i801.o 21 20 obj-$(CONFIG_I2C_ISCH) += i2c-isch.o 22 21 obj-$(CONFIG_I2C_ISMT) += i2c-ismt.o 23 22 obj-$(CONFIG_I2C_NFORCE2) += i2c-nforce2.o 24 - obj-$(CONFIG_I2C_NFORCE2_S4985) += i2c-nforce2-s4985.o 25 23 obj-$(CONFIG_I2C_NVIDIA_GPU) += i2c-nvidia-gpu.o 26 24 obj-$(CONFIG_I2C_PIIX4) += i2c-piix4.o 27 25 obj-$(CONFIG_I2C_SIS5595) += i2c-sis5595.o ··· 36 38 # Embedded system I2C/SMBus host controller drivers 37 39 obj-$(CONFIG_I2C_ALTERA) += i2c-altera.o 38 40 obj-$(CONFIG_I2C_AMD_MP2) += i2c-amd-mp2-pci.o i2c-amd-mp2-plat.o 41 + obj-$(CONFIG_I2C_AMD_ASF) += i2c-amd-asf-plat.o 39 42 obj-$(CONFIG_I2C_ASPEED) += i2c-aspeed.o 40 43 obj-$(CONFIG_I2C_AT91) += i2c-at91.o 41 - i2c-at91-objs := i2c-at91-core.o i2c-at91-master.o 42 - ifeq ($(CONFIG_I2C_AT91_SLAVE_EXPERIMENTAL),y) 43 - i2c-at91-objs += i2c-at91-slave.o 44 - endif 44 + i2c-at91-y := i2c-at91-core.o i2c-at91-master.o 45 + i2c-at91-$(CONFIG_I2C_AT91_SLAVE_EXPERIMENTAL) += i2c-at91-slave.o 45 46 obj-$(CONFIG_I2C_AU1550) += i2c-au1550.o 46 47 obj-$(CONFIG_I2C_AXXIA) += i2c-axxia.o 47 48 obj-$(CONFIG_I2C_BCM2835) += i2c-bcm2835.o ··· 101 104 obj-$(CONFIG_I2C_QUP) += i2c-qup.o 102 105 obj-$(CONFIG_I2C_RIIC) += i2c-riic.o 103 106 obj-$(CONFIG_I2C_RK3X) += i2c-rk3x.o 107 + obj-$(CONFIG_I2C_RTL9300) += i2c-rtl9300.o 104 108 obj-$(CONFIG_I2C_RZV2M) += i2c-rzv2m.o 105 109 obj-$(CONFIG_I2C_S3C2410) += i2c-s3c2410.o 106 110 obj-$(CONFIG_I2C_SH7760) += i2c-sh7760.o ··· 110 112 obj-$(CONFIG_I2C_SPRD) += i2c-sprd.o 111 113 obj-$(CONFIG_I2C_ST) += i2c-st.o 112 114 obj-$(CONFIG_I2C_STM32F4) += i2c-stm32f4.o 113 - i2c-stm32f7-drv-objs := i2c-stm32f7.o i2c-stm32.o 114 115 obj-$(CONFIG_I2C_STM32F7) += i2c-stm32f7-drv.o 116 + i2c-stm32f7-drv-y := i2c-stm32f7.o i2c-stm32.o 115 117 obj-$(CONFIG_I2C_SUN6I_P2WI) += i2c-sun6i-p2wi.o 116 118 obj-$(CONFIG_I2C_SYNQUACER) += i2c-synquacer.o 117 119 obj-$(CONFIG_I2C_TEGRA) += i2c-tegra.o ··· 120 122 obj-$(CONFIG_I2C_UNIPHIER_F) += i2c-uniphier-f.o 121 123 obj-$(CONFIG_I2C_VERSATILE) += i2c-versatile.o 122 124 obj-$(CONFIG_I2C_WMT) += i2c-viai2c-wmt.o i2c-viai2c-common.o 123 - i2c-octeon-objs := i2c-octeon-core.o i2c-octeon-platdrv.o 124 125 obj-$(CONFIG_I2C_OCTEON) += i2c-octeon.o 125 - i2c-thunderx-objs := i2c-octeon-core.o i2c-thunderx-pcidrv.o 126 + i2c-octeon-y := i2c-octeon-core.o i2c-octeon-platdrv.o 126 127 obj-$(CONFIG_I2C_THUNDERX) += i2c-thunderx.o 128 + i2c-thunderx-y := i2c-octeon-core.o i2c-thunderx-pcidrv.o 127 129 obj-$(CONFIG_I2C_XILINX) += i2c-xiic.o 128 130 obj-$(CONFIG_I2C_XLP9XX) += i2c-xlp9xx.o 129 131 obj-$(CONFIG_I2C_RCAR) += i2c-rcar.o
+1 -1
drivers/i2c/busses/i2c-altera.c
··· 482 482 483 483 static struct platform_driver altr_i2c_driver = { 484 484 .probe = altr_i2c_probe, 485 - .remove_new = altr_i2c_remove, 485 + .remove = altr_i2c_remove, 486 486 .driver = { 487 487 .name = "altera-i2c", 488 488 .of_match_table = altr_i2c_of_match,
+369
drivers/i2c/busses/i2c-amd-asf-plat.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + /* 3 + * AMD Alert Standard Format Platform Driver 4 + * 5 + * Copyright (c) 2024, Advanced Micro Devices, Inc. 6 + * All Rights Reserved. 7 + * 8 + * Authors: Shyam Sundar S K <Shyam-sundar.S-k@amd.com> 9 + * Sanket Goswami <Sanket.Goswami@amd.com> 10 + */ 11 + 12 + #include <linux/bitops.h> 13 + #include <linux/device.h> 14 + #include <linux/devm-helpers.h> 15 + #include <linux/errno.h> 16 + #include <linux/gfp_types.h> 17 + #include <linux/i2c.h> 18 + #include <linux/io.h> 19 + #include <linux/ioport.h> 20 + #include <linux/module.h> 21 + #include <linux/mod_devicetable.h> 22 + #include <linux/platform_device.h> 23 + #include <linux/sprintf.h> 24 + 25 + #include "i2c-piix4.h" 26 + 27 + /* ASF register bits */ 28 + #define ASF_SLV_LISTN 0 29 + #define ASF_SLV_INTR 1 30 + #define ASF_SLV_RST 4 31 + #define ASF_PEC_SP 5 32 + #define ASF_DATA_EN 7 33 + #define ASF_MSTR_EN 16 34 + #define ASF_CLK_EN 17 35 + 36 + /* ASF address offsets */ 37 + #define ASFINDEX (0x07 + piix4_smba) 38 + #define ASFLISADDR (0x09 + piix4_smba) 39 + #define ASFSTA (0x0A + piix4_smba) 40 + #define ASFSLVSTA (0x0D + piix4_smba) 41 + #define ASFDATARWPTR (0x11 + piix4_smba) 42 + #define ASFSETDATARDPTR (0x12 + piix4_smba) 43 + #define ASFDATABNKSEL (0x13 + piix4_smba) 44 + #define ASFSLVEN (0x15 + piix4_smba) 45 + 46 + #define ASF_BLOCK_MAX_BYTES 72 47 + #define ASF_ERROR_STATUS GENMASK(3, 1) 48 + 49 + struct amd_asf_dev { 50 + struct i2c_adapter adap; 51 + void __iomem *eoi_base; 52 + struct i2c_client *target; 53 + struct delayed_work work_buf; 54 + struct sb800_mmio_cfg mmio_cfg; 55 + struct resource *port_addr; 56 + }; 57 + 58 + static void amd_asf_process_target(struct work_struct *work) 59 + { 60 + struct amd_asf_dev *dev = container_of(work, struct amd_asf_dev, work_buf.work); 61 + unsigned short piix4_smba = dev->port_addr->start; 62 + u8 data[ASF_BLOCK_MAX_BYTES]; 63 + u8 bank, reg, cmd; 64 + u8 len = 0, idx, val; 65 + 66 + /* Read target status register */ 67 + reg = inb_p(ASFSLVSTA); 68 + 69 + /* Check if no error bits are set in target status register */ 70 + if (reg & ASF_ERROR_STATUS) { 71 + /* Set bank as full */ 72 + cmd = 0; 73 + reg |= GENMASK(3, 2); 74 + outb_p(reg, ASFDATABNKSEL); 75 + } else { 76 + /* Read data bank */ 77 + reg = inb_p(ASFDATABNKSEL); 78 + bank = (reg & BIT(3)) ? 1 : 0; 79 + 80 + /* Set read data bank */ 81 + if (bank) { 82 + reg |= BIT(4); 83 + reg &= ~BIT(3); 84 + } else { 85 + reg &= ~BIT(4); 86 + reg &= ~BIT(2); 87 + } 88 + 89 + /* Read command register */ 90 + outb_p(reg, ASFDATABNKSEL); 91 + cmd = inb_p(ASFINDEX); 92 + len = inb_p(ASFDATARWPTR); 93 + for (idx = 0; idx < len; idx++) 94 + data[idx] = inb_p(ASFINDEX); 95 + 96 + /* Clear data bank status */ 97 + if (bank) { 98 + reg |= BIT(3); 99 + outb_p(reg, ASFDATABNKSEL); 100 + } else { 101 + reg |= BIT(2); 102 + outb_p(reg, ASFDATABNKSEL); 103 + } 104 + } 105 + 106 + outb_p(0, ASFSETDATARDPTR); 107 + if (cmd & BIT(0)) 108 + return; 109 + 110 + /* 111 + * Although i2c_slave_event() returns an appropriate error code, we 112 + * don't check it here because we're operating in the workqueue context. 113 + */ 114 + i2c_slave_event(dev->target, I2C_SLAVE_WRITE_REQUESTED, &val); 115 + for (idx = 0; idx < len; idx++) { 116 + val = data[idx]; 117 + i2c_slave_event(dev->target, I2C_SLAVE_WRITE_RECEIVED, &val); 118 + } 119 + i2c_slave_event(dev->target, I2C_SLAVE_STOP, &val); 120 + } 121 + 122 + static void amd_asf_update_ioport_target(unsigned short piix4_smba, u8 bit, 123 + unsigned long offset, bool set) 124 + { 125 + unsigned long reg; 126 + 127 + reg = inb_p(offset); 128 + __assign_bit(bit, &reg, set); 129 + outb_p(reg, offset); 130 + } 131 + 132 + static void amd_asf_update_mmio_target(struct amd_asf_dev *dev, u8 bit, bool set) 133 + { 134 + unsigned long reg; 135 + 136 + reg = ioread32(dev->mmio_cfg.addr); 137 + __assign_bit(bit, &reg, set); 138 + iowrite32(reg, dev->mmio_cfg.addr); 139 + } 140 + 141 + static void amd_asf_setup_target(struct amd_asf_dev *dev) 142 + { 143 + unsigned short piix4_smba = dev->port_addr->start; 144 + 145 + /* Reset both host and target before setting up */ 146 + outb_p(0, SMBHSTSTS); 147 + outb_p(0, ASFSLVSTA); 148 + outb_p(0, ASFSTA); 149 + 150 + /* Update target address */ 151 + amd_asf_update_ioport_target(piix4_smba, ASF_SLV_LISTN, ASFLISADDR, true); 152 + /* Enable target and set the clock */ 153 + amd_asf_update_mmio_target(dev, ASF_MSTR_EN, false); 154 + amd_asf_update_mmio_target(dev, ASF_CLK_EN, true); 155 + /* Enable target interrupt */ 156 + amd_asf_update_ioport_target(piix4_smba, ASF_SLV_INTR, ASFSLVEN, true); 157 + amd_asf_update_ioport_target(piix4_smba, ASF_SLV_RST, ASFSLVEN, false); 158 + /* Enable PEC and PEC append */ 159 + amd_asf_update_ioport_target(piix4_smba, ASF_DATA_EN, SMBHSTCNT, true); 160 + amd_asf_update_ioport_target(piix4_smba, ASF_PEC_SP, SMBHSTCNT, true); 161 + } 162 + 163 + static int amd_asf_access(struct i2c_adapter *adap, u16 addr, u8 command, u8 *data) 164 + { 165 + struct amd_asf_dev *dev = i2c_get_adapdata(adap); 166 + unsigned short piix4_smba = dev->port_addr->start; 167 + u8 i, len; 168 + 169 + outb_p((addr << 1), SMBHSTADD); 170 + outb_p(command, SMBHSTCMD); 171 + len = data[0]; 172 + if (len == 0 || len > ASF_BLOCK_MAX_BYTES) 173 + return -EINVAL; 174 + 175 + outb_p(len, SMBHSTDAT0); 176 + /* Reset SMBBLKDAT */ 177 + inb_p(SMBHSTCNT); 178 + for (i = 1; i <= len; i++) 179 + outb_p(data[i], SMBBLKDAT); 180 + 181 + outb_p(PIIX4_BLOCK_DATA, SMBHSTCNT); 182 + /* Enable PEC and PEC append */ 183 + amd_asf_update_ioport_target(piix4_smba, ASF_DATA_EN, SMBHSTCNT, true); 184 + amd_asf_update_ioport_target(piix4_smba, ASF_PEC_SP, SMBHSTCNT, true); 185 + 186 + return piix4_transaction(adap, piix4_smba); 187 + } 188 + 189 + static int amd_asf_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) 190 + { 191 + struct amd_asf_dev *dev = i2c_get_adapdata(adap); 192 + unsigned short piix4_smba = dev->port_addr->start; 193 + u8 asf_data[ASF_BLOCK_MAX_BYTES]; 194 + struct i2c_msg *dev_msgs = msgs; 195 + u8 prev_port; 196 + int ret; 197 + 198 + if (msgs->flags & I2C_M_RD) { 199 + dev_err(&adap->dev, "ASF: Read not supported\n"); 200 + return -EOPNOTSUPP; 201 + } 202 + 203 + /* Exclude the receive header and PEC */ 204 + if (msgs->len > ASF_BLOCK_MAX_BYTES - 3) { 205 + dev_warn(&adap->dev, "ASF: max message length exceeded\n"); 206 + return -EOPNOTSUPP; 207 + } 208 + 209 + asf_data[0] = dev_msgs->len; 210 + memcpy(asf_data + 1, dev_msgs[0].buf, dev_msgs->len); 211 + 212 + ret = piix4_sb800_region_request(&adap->dev, &dev->mmio_cfg); 213 + if (ret) 214 + return ret; 215 + 216 + amd_asf_update_ioport_target(piix4_smba, ASF_SLV_RST, ASFSLVEN, true); 217 + amd_asf_update_ioport_target(piix4_smba, ASF_SLV_LISTN, ASFLISADDR, false); 218 + /* Clear ASF target status */ 219 + outb_p(0, ASFSLVSTA); 220 + 221 + /* Enable ASF SMBus controller function */ 222 + amd_asf_update_mmio_target(dev, ASF_MSTR_EN, true); 223 + prev_port = piix4_sb800_port_sel(0, &dev->mmio_cfg); 224 + ret = amd_asf_access(adap, msgs->addr, msgs[0].buf[0], asf_data); 225 + piix4_sb800_port_sel(prev_port, &dev->mmio_cfg); 226 + amd_asf_setup_target(dev); 227 + piix4_sb800_region_release(&adap->dev, &dev->mmio_cfg); 228 + return ret; 229 + } 230 + 231 + static int amd_asf_reg_target(struct i2c_client *target) 232 + { 233 + struct amd_asf_dev *dev = i2c_get_adapdata(target->adapter); 234 + unsigned short piix4_smba = dev->port_addr->start; 235 + int ret; 236 + u8 reg; 237 + 238 + if (dev->target) 239 + return -EBUSY; 240 + 241 + ret = piix4_sb800_region_request(&target->dev, &dev->mmio_cfg); 242 + if (ret) 243 + return ret; 244 + 245 + reg = (target->addr << 1) | I2C_M_RD; 246 + outb_p(reg, ASFLISADDR); 247 + 248 + amd_asf_setup_target(dev); 249 + dev->target = target; 250 + amd_asf_update_ioport_target(piix4_smba, ASF_DATA_EN, ASFDATABNKSEL, false); 251 + piix4_sb800_region_release(&target->dev, &dev->mmio_cfg); 252 + 253 + return 0; 254 + } 255 + 256 + static int amd_asf_unreg_target(struct i2c_client *target) 257 + { 258 + struct amd_asf_dev *dev = i2c_get_adapdata(target->adapter); 259 + unsigned short piix4_smba = dev->port_addr->start; 260 + 261 + amd_asf_update_ioport_target(piix4_smba, ASF_SLV_INTR, ASFSLVEN, false); 262 + amd_asf_update_ioport_target(piix4_smba, ASF_SLV_RST, ASFSLVEN, true); 263 + dev->target = NULL; 264 + 265 + return 0; 266 + } 267 + 268 + static u32 amd_asf_func(struct i2c_adapter *adapter) 269 + { 270 + return I2C_FUNC_SMBUS_WRITE_BLOCK_DATA | I2C_FUNC_SMBUS_BLOCK_DATA | 271 + I2C_FUNC_SMBUS_BYTE | I2C_FUNC_SMBUS_PEC | I2C_FUNC_SLAVE; 272 + } 273 + 274 + static const struct i2c_algorithm amd_asf_smbus_algorithm = { 275 + .master_xfer = amd_asf_xfer, 276 + .reg_slave = amd_asf_reg_target, 277 + .unreg_slave = amd_asf_unreg_target, 278 + .functionality = amd_asf_func, 279 + }; 280 + 281 + static irqreturn_t amd_asf_irq_handler(int irq, void *ptr) 282 + { 283 + struct amd_asf_dev *dev = ptr; 284 + unsigned short piix4_smba = dev->port_addr->start; 285 + u8 target_int = inb_p(ASFSTA); 286 + 287 + if (target_int & BIT(6)) { 288 + /* Target Interrupt */ 289 + outb_p(target_int | BIT(6), ASFSTA); 290 + schedule_delayed_work(&dev->work_buf, HZ); 291 + } else { 292 + /* Controller Interrupt */ 293 + amd_asf_update_ioport_target(piix4_smba, ASF_SLV_INTR, SMBHSTSTS, true); 294 + } 295 + 296 + return IRQ_HANDLED; 297 + } 298 + 299 + static int amd_asf_probe(struct platform_device *pdev) 300 + { 301 + struct device *dev = &pdev->dev; 302 + struct amd_asf_dev *asf_dev; 303 + struct resource *eoi_addr; 304 + int ret, irq; 305 + 306 + asf_dev = devm_kzalloc(dev, sizeof(*asf_dev), GFP_KERNEL); 307 + if (!asf_dev) 308 + return dev_err_probe(dev, -ENOMEM, "Failed to allocate memory\n"); 309 + 310 + asf_dev->mmio_cfg.use_mmio = true; 311 + asf_dev->port_addr = platform_get_resource(pdev, IORESOURCE_IO, 0); 312 + if (!asf_dev->port_addr) 313 + return dev_err_probe(dev, -EINVAL, "missing IO resources\n"); 314 + 315 + /* 316 + * The resource obtained via ACPI might not belong to the ASF device address space. Instead, 317 + * it could be within other IP blocks of the ASIC, which are crucial for generating 318 + * subsequent interrupts. Therefore, we avoid using devm_platform_ioremap_resource() and 319 + * use platform_get_resource() and devm_ioremap() separately to prevent any address space 320 + * conflicts. 321 + */ 322 + eoi_addr = platform_get_resource(pdev, IORESOURCE_MEM, 0); 323 + if (!eoi_addr) 324 + return dev_err_probe(dev, -EINVAL, "missing MEM resources\n"); 325 + 326 + asf_dev->eoi_base = devm_ioremap(dev, eoi_addr->start, resource_size(eoi_addr)); 327 + if (!asf_dev->eoi_base) 328 + return dev_err_probe(dev, -EBUSY, "failed mapping IO region\n"); 329 + 330 + ret = devm_delayed_work_autocancel(dev, &asf_dev->work_buf, amd_asf_process_target); 331 + if (ret) 332 + return dev_err_probe(dev, ret, "failed to create work queue\n"); 333 + 334 + irq = platform_get_irq(pdev, 0); 335 + if (irq < 0) 336 + return dev_err_probe(dev, irq, "missing IRQ resources\n"); 337 + 338 + ret = devm_request_irq(dev, irq, amd_asf_irq_handler, IRQF_SHARED, "amd_asf", asf_dev); 339 + if (ret) 340 + return dev_err_probe(dev, ret, "Unable to request irq: %d for use\n", irq); 341 + 342 + asf_dev->adap.owner = THIS_MODULE; 343 + asf_dev->adap.algo = &amd_asf_smbus_algorithm; 344 + asf_dev->adap.dev.parent = dev; 345 + 346 + i2c_set_adapdata(&asf_dev->adap, asf_dev); 347 + snprintf(asf_dev->adap.name, sizeof(asf_dev->adap.name), "AMD ASF adapter"); 348 + 349 + return devm_i2c_add_adapter(dev, &asf_dev->adap); 350 + } 351 + 352 + static const struct acpi_device_id amd_asf_acpi_ids[] = { 353 + { "AMDI001A" }, 354 + { } 355 + }; 356 + MODULE_DEVICE_TABLE(acpi, amd_asf_acpi_ids); 357 + 358 + static struct platform_driver amd_asf_driver = { 359 + .driver = { 360 + .name = "i2c-amd-asf", 361 + .acpi_match_table = amd_asf_acpi_ids, 362 + }, 363 + .probe = amd_asf_probe, 364 + }; 365 + module_platform_driver(amd_asf_driver); 366 + 367 + MODULE_IMPORT_NS(PIIX4_SMBUS); 368 + MODULE_LICENSE("GPL"); 369 + MODULE_DESCRIPTION("AMD Alert Standard Format Driver");
+1 -1
drivers/i2c/busses/i2c-amd-mp2-plat.c
··· 346 346 347 347 static struct platform_driver i2c_amd_plat_driver = { 348 348 .probe = i2c_amd_probe, 349 - .remove_new = i2c_amd_remove, 349 + .remove = i2c_amd_remove, 350 350 .driver = { 351 351 .name = "i2c_amd_mp2", 352 352 .acpi_match_table = ACPI_PTR(i2c_amd_acpi_match),
-245
drivers/i2c/busses/i2c-amd756-s4882.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-or-later 2 - /* 3 - * i2c-amd756-s4882.c - i2c-amd756 extras for the Tyan S4882 motherboard 4 - * 5 - * Copyright (C) 2004, 2008 Jean Delvare <jdelvare@suse.de> 6 - */ 7 - 8 - /* 9 - * We select the channels by sending commands to the Philips 10 - * PCA9556 chip at I2C address 0x18. The main adapter is used for 11 - * the non-multiplexed part of the bus, and 4 virtual adapters 12 - * are defined for the multiplexed addresses: 0x50-0x53 (memory 13 - * module EEPROM) located on channels 1-4, and 0x4c (LM63) 14 - * located on multiplexed channels 0 and 5-7. We define one 15 - * virtual adapter per CPU, which corresponds to two multiplexed 16 - * channels: 17 - * CPU0: virtual adapter 1, channels 1 and 0 18 - * CPU1: virtual adapter 2, channels 2 and 5 19 - * CPU2: virtual adapter 3, channels 3 and 6 20 - * CPU3: virtual adapter 4, channels 4 and 7 21 - */ 22 - 23 - #include <linux/module.h> 24 - #include <linux/kernel.h> 25 - #include <linux/slab.h> 26 - #include <linux/init.h> 27 - #include <linux/i2c.h> 28 - #include <linux/mutex.h> 29 - 30 - extern struct i2c_adapter amd756_smbus; 31 - 32 - static struct i2c_adapter *s4882_adapter; 33 - static struct i2c_algorithm *s4882_algo; 34 - 35 - /* Wrapper access functions for multiplexed SMBus */ 36 - static DEFINE_MUTEX(amd756_lock); 37 - 38 - static s32 amd756_access_virt0(struct i2c_adapter * adap, u16 addr, 39 - unsigned short flags, char read_write, 40 - u8 command, int size, 41 - union i2c_smbus_data * data) 42 - { 43 - int error; 44 - 45 - /* We exclude the multiplexed addresses */ 46 - if (addr == 0x4c || (addr & 0xfc) == 0x50 || (addr & 0xfc) == 0x30 47 - || addr == 0x18) 48 - return -ENXIO; 49 - 50 - mutex_lock(&amd756_lock); 51 - 52 - error = amd756_smbus.algo->smbus_xfer(adap, addr, flags, read_write, 53 - command, size, data); 54 - 55 - mutex_unlock(&amd756_lock); 56 - 57 - return error; 58 - } 59 - 60 - /* We remember the last used channels combination so as to only switch 61 - channels when it is really needed. This greatly reduces the SMBus 62 - overhead, but also assumes that nobody will be writing to the PCA9556 63 - in our back. */ 64 - static u8 last_channels; 65 - 66 - static inline s32 amd756_access_channel(struct i2c_adapter * adap, u16 addr, 67 - unsigned short flags, char read_write, 68 - u8 command, int size, 69 - union i2c_smbus_data * data, 70 - u8 channels) 71 - { 72 - int error; 73 - 74 - /* We exclude the non-multiplexed addresses */ 75 - if (addr != 0x4c && (addr & 0xfc) != 0x50 && (addr & 0xfc) != 0x30) 76 - return -ENXIO; 77 - 78 - mutex_lock(&amd756_lock); 79 - 80 - if (last_channels != channels) { 81 - union i2c_smbus_data mplxdata; 82 - mplxdata.byte = channels; 83 - 84 - error = amd756_smbus.algo->smbus_xfer(adap, 0x18, 0, 85 - I2C_SMBUS_WRITE, 0x01, 86 - I2C_SMBUS_BYTE_DATA, 87 - &mplxdata); 88 - if (error) 89 - goto UNLOCK; 90 - last_channels = channels; 91 - } 92 - error = amd756_smbus.algo->smbus_xfer(adap, addr, flags, read_write, 93 - command, size, data); 94 - 95 - UNLOCK: 96 - mutex_unlock(&amd756_lock); 97 - return error; 98 - } 99 - 100 - static s32 amd756_access_virt1(struct i2c_adapter * adap, u16 addr, 101 - unsigned short flags, char read_write, 102 - u8 command, int size, 103 - union i2c_smbus_data * data) 104 - { 105 - /* CPU0: channels 1 and 0 enabled */ 106 - return amd756_access_channel(adap, addr, flags, read_write, command, 107 - size, data, 0x03); 108 - } 109 - 110 - static s32 amd756_access_virt2(struct i2c_adapter * adap, u16 addr, 111 - unsigned short flags, char read_write, 112 - u8 command, int size, 113 - union i2c_smbus_data * data) 114 - { 115 - /* CPU1: channels 2 and 5 enabled */ 116 - return amd756_access_channel(adap, addr, flags, read_write, command, 117 - size, data, 0x24); 118 - } 119 - 120 - static s32 amd756_access_virt3(struct i2c_adapter * adap, u16 addr, 121 - unsigned short flags, char read_write, 122 - u8 command, int size, 123 - union i2c_smbus_data * data) 124 - { 125 - /* CPU2: channels 3 and 6 enabled */ 126 - return amd756_access_channel(adap, addr, flags, read_write, command, 127 - size, data, 0x48); 128 - } 129 - 130 - static s32 amd756_access_virt4(struct i2c_adapter * adap, u16 addr, 131 - unsigned short flags, char read_write, 132 - u8 command, int size, 133 - union i2c_smbus_data * data) 134 - { 135 - /* CPU3: channels 4 and 7 enabled */ 136 - return amd756_access_channel(adap, addr, flags, read_write, command, 137 - size, data, 0x90); 138 - } 139 - 140 - static int __init amd756_s4882_init(void) 141 - { 142 - int i, error; 143 - union i2c_smbus_data ioconfig; 144 - 145 - if (!amd756_smbus.dev.parent) 146 - return -ENODEV; 147 - 148 - /* Configure the PCA9556 multiplexer */ 149 - ioconfig.byte = 0x00; /* All I/O to output mode */ 150 - error = i2c_smbus_xfer(&amd756_smbus, 0x18, 0, I2C_SMBUS_WRITE, 0x03, 151 - I2C_SMBUS_BYTE_DATA, &ioconfig); 152 - if (error) { 153 - dev_err(&amd756_smbus.dev, "PCA9556 configuration failed\n"); 154 - error = -EIO; 155 - goto ERROR0; 156 - } 157 - 158 - /* Unregister physical bus */ 159 - i2c_del_adapter(&amd756_smbus); 160 - 161 - printk(KERN_INFO "Enabling SMBus multiplexing for Tyan S4882\n"); 162 - /* Define the 5 virtual adapters and algorithms structures */ 163 - if (!(s4882_adapter = kcalloc(5, sizeof(struct i2c_adapter), 164 - GFP_KERNEL))) { 165 - error = -ENOMEM; 166 - goto ERROR1; 167 - } 168 - if (!(s4882_algo = kcalloc(5, sizeof(struct i2c_algorithm), 169 - GFP_KERNEL))) { 170 - error = -ENOMEM; 171 - goto ERROR2; 172 - } 173 - 174 - /* Fill in the new structures */ 175 - s4882_algo[0] = *(amd756_smbus.algo); 176 - s4882_algo[0].smbus_xfer = amd756_access_virt0; 177 - s4882_adapter[0] = amd756_smbus; 178 - s4882_adapter[0].algo = s4882_algo; 179 - s4882_adapter[0].dev.parent = amd756_smbus.dev.parent; 180 - for (i = 1; i < 5; i++) { 181 - s4882_algo[i] = *(amd756_smbus.algo); 182 - s4882_adapter[i] = amd756_smbus; 183 - snprintf(s4882_adapter[i].name, sizeof(s4882_adapter[i].name), 184 - "SMBus 8111 adapter (CPU%d)", i-1); 185 - s4882_adapter[i].algo = s4882_algo+i; 186 - s4882_adapter[i].dev.parent = amd756_smbus.dev.parent; 187 - } 188 - s4882_algo[1].smbus_xfer = amd756_access_virt1; 189 - s4882_algo[2].smbus_xfer = amd756_access_virt2; 190 - s4882_algo[3].smbus_xfer = amd756_access_virt3; 191 - s4882_algo[4].smbus_xfer = amd756_access_virt4; 192 - 193 - /* Register virtual adapters */ 194 - for (i = 0; i < 5; i++) { 195 - error = i2c_add_adapter(s4882_adapter+i); 196 - if (error) { 197 - printk(KERN_ERR "i2c-amd756-s4882: " 198 - "Virtual adapter %d registration " 199 - "failed, module not inserted\n", i); 200 - for (i--; i >= 0; i--) 201 - i2c_del_adapter(s4882_adapter+i); 202 - goto ERROR3; 203 - } 204 - } 205 - 206 - return 0; 207 - 208 - ERROR3: 209 - kfree(s4882_algo); 210 - s4882_algo = NULL; 211 - ERROR2: 212 - kfree(s4882_adapter); 213 - s4882_adapter = NULL; 214 - ERROR1: 215 - /* Restore physical bus */ 216 - i2c_add_adapter(&amd756_smbus); 217 - ERROR0: 218 - return error; 219 - } 220 - 221 - static void __exit amd756_s4882_exit(void) 222 - { 223 - if (s4882_adapter) { 224 - int i; 225 - 226 - for (i = 0; i < 5; i++) 227 - i2c_del_adapter(s4882_adapter+i); 228 - kfree(s4882_adapter); 229 - s4882_adapter = NULL; 230 - } 231 - kfree(s4882_algo); 232 - s4882_algo = NULL; 233 - 234 - /* Restore physical bus */ 235 - if (i2c_add_adapter(&amd756_smbus)) 236 - printk(KERN_ERR "i2c-amd756-s4882: " 237 - "Physical bus restoration failed\n"); 238 - } 239 - 240 - MODULE_AUTHOR("Jean Delvare <jdelvare@suse.de>"); 241 - MODULE_DESCRIPTION("S4882 SMBus multiplexing"); 242 - MODULE_LICENSE("GPL"); 243 - 244 - module_init(amd756_s4882_init); 245 - module_exit(amd756_s4882_exit);
+1 -3
drivers/i2c/busses/i2c-amd756.c
··· 283 283 .functionality = amd756_func, 284 284 }; 285 285 286 - struct i2c_adapter amd756_smbus = { 286 + static struct i2c_adapter amd756_smbus = { 287 287 .owner = THIS_MODULE, 288 288 .class = I2C_CLASS_HWMON, 289 289 .algo = &smbus_algorithm, ··· 398 398 MODULE_AUTHOR("Merlin Hughes <merlin@merlin.org>"); 399 399 MODULE_DESCRIPTION("AMD756/766/768/8111 and nVidia nForce SMBus driver"); 400 400 MODULE_LICENSE("GPL"); 401 - 402 - EXPORT_SYMBOL(amd756_smbus);
+1 -1
drivers/i2c/busses/i2c-aspeed.c
··· 1102 1102 1103 1103 static struct platform_driver aspeed_i2c_bus_driver = { 1104 1104 .probe = aspeed_i2c_probe_bus, 1105 - .remove_new = aspeed_i2c_remove_bus, 1105 + .remove = aspeed_i2c_remove_bus, 1106 1106 .driver = { 1107 1107 .name = "aspeed-i2c-bus", 1108 1108 .of_match_table = aspeed_i2c_bus_of_table,
+1 -1
drivers/i2c/busses/i2c-at91-core.c
··· 330 330 331 331 static struct platform_driver at91_twi_driver = { 332 332 .probe = at91_twi_probe, 333 - .remove_new = at91_twi_remove, 333 + .remove = at91_twi_remove, 334 334 .id_table = at91_twi_devtypes, 335 335 .driver = { 336 336 .name = "at91_i2c",
+1 -1
drivers/i2c/busses/i2c-au1550.c
··· 368 368 .pm = pm_sleep_ptr(&i2c_au1550_pmops), 369 369 }, 370 370 .probe = i2c_au1550_probe, 371 - .remove_new = i2c_au1550_remove, 371 + .remove = i2c_au1550_remove, 372 372 }; 373 373 374 374 module_platform_driver(au1xpsc_smbus_driver);
+1 -1
drivers/i2c/busses/i2c-axxia.c
··· 824 824 825 825 static struct platform_driver axxia_i2c_driver = { 826 826 .probe = axxia_i2c_probe, 827 - .remove_new = axxia_i2c_remove, 827 + .remove = axxia_i2c_remove, 828 828 .driver = { 829 829 .name = "axxia-i2c", 830 830 .of_match_table = axxia_i2c_of_match,
+1 -1
drivers/i2c/busses/i2c-bcm-iproc.c
··· 1264 1264 .pm = pm_sleep_ptr(&bcm_iproc_i2c_pm_ops), 1265 1265 }, 1266 1266 .probe = bcm_iproc_i2c_probe, 1267 - .remove_new = bcm_iproc_i2c_remove, 1267 + .remove = bcm_iproc_i2c_remove, 1268 1268 }; 1269 1269 module_platform_driver(bcm_iproc_i2c_driver); 1270 1270
+1 -1
drivers/i2c/busses/i2c-bcm-kona.c
··· 877 877 .of_match_table = bcm_kona_i2c_of_match, 878 878 }, 879 879 .probe = bcm_kona_i2c_probe, 880 - .remove_new = bcm_kona_i2c_remove, 880 + .remove = bcm_kona_i2c_remove, 881 881 }; 882 882 module_platform_driver(bcm_kona_i2c_driver); 883 883
+1 -1
drivers/i2c/busses/i2c-bcm2835.c
··· 520 520 521 521 static struct platform_driver bcm2835_i2c_driver = { 522 522 .probe = bcm2835_i2c_probe, 523 - .remove_new = bcm2835_i2c_remove, 523 + .remove = bcm2835_i2c_remove, 524 524 .driver = { 525 525 .name = "i2c-bcm2835", 526 526 .of_match_table = bcm2835_i2c_of_match,
+1 -1
drivers/i2c/busses/i2c-brcmstb.c
··· 744 744 .pm = pm_sleep_ptr(&brcmstb_i2c_pm), 745 745 }, 746 746 .probe = brcmstb_i2c_probe, 747 - .remove_new = brcmstb_i2c_remove, 747 + .remove = brcmstb_i2c_remove, 748 748 }; 749 749 module_platform_driver(brcmstb_i2c_driver); 750 750
+322 -139
drivers/i2c/busses/i2c-cadence.c
··· 129 129 130 130 #define CDNS_I2C_BROKEN_HOLD_BIT BIT(0) 131 131 #define CDNS_I2C_POLL_US 100000 132 + #define CDNS_I2C_POLL_US_ATOMIC 10 132 133 #define CDNS_I2C_TIMEOUT_US 500000 133 134 134 135 #define cdns_i2c_readreg(offset) readl_relaxed(id->membase + offset) ··· 190 189 * @slave_state: I2C Slave state(idle/read/write). 191 190 * @fifo_depth: The depth of the transfer FIFO 192 191 * @transfer_size: The maximum number of bytes in one transfer 192 + * @atomic: Mode of transfer 193 + * @err_status_atomic: Error status in atomic mode 193 194 */ 194 195 struct cdns_i2c { 195 196 struct device *dev; ··· 222 219 #endif 223 220 u32 fifo_depth; 224 221 unsigned int transfer_size; 222 + bool atomic; 223 + int err_status_atomic; 225 224 }; 226 225 227 226 struct cdns_platform_data { ··· 232 227 233 228 #define to_cdns_i2c(_nb) container_of(_nb, struct cdns_i2c, \ 234 229 clk_rate_change_nb) 230 + 231 + /** 232 + * cdns_i2c_init - Controller initialisation 233 + * @id: Device private data structure 234 + * 235 + * Initialise the i2c controller. 236 + * 237 + */ 238 + static void cdns_i2c_init(struct cdns_i2c *id) 239 + { 240 + cdns_i2c_writereg(id->ctrl_reg, CDNS_I2C_CR_OFFSET); 241 + /* 242 + * Cadence I2C controller has a bug wherein it generates 243 + * invalid read transaction after HW timeout in master receiver mode. 244 + * HW timeout is not used by this driver and the interrupt is disabled. 245 + * But the feature itself cannot be disabled. Hence maximum value 246 + * is written to this register to reduce the chances of error. 247 + */ 248 + cdns_i2c_writereg(CDNS_I2C_TIMEOUT_MAX, CDNS_I2C_TIME_OUT_OFFSET); 249 + } 250 + 251 + /** 252 + * cdns_i2c_runtime_suspend - Runtime suspend method for the driver 253 + * @dev: Address of the platform_device structure 254 + * 255 + * Put the driver into low power mode. 256 + * 257 + * Return: 0 always 258 + */ 259 + static int cdns_i2c_runtime_suspend(struct device *dev) 260 + { 261 + struct cdns_i2c *xi2c = dev_get_drvdata(dev); 262 + 263 + clk_disable(xi2c->clk); 264 + 265 + return 0; 266 + } 267 + 268 + /** 269 + * cdns_i2c_runtime_resume - Runtime resume 270 + * @dev: Address of the platform_device structure 271 + * 272 + * Runtime resume callback. 273 + * 274 + * Return: 0 on success and error value on error 275 + */ 276 + static int cdns_i2c_runtime_resume(struct device *dev) 277 + { 278 + struct cdns_i2c *xi2c = dev_get_drvdata(dev); 279 + int ret; 280 + 281 + ret = clk_enable(xi2c->clk); 282 + if (ret) { 283 + dev_err(dev, "Cannot enable clock.\n"); 284 + return ret; 285 + } 286 + cdns_i2c_init(xi2c); 287 + 288 + return 0; 289 + } 235 290 236 291 /** 237 292 * cdns_i2c_clear_bus_hold - Clear bus hold bit ··· 626 561 return cdns_i2c_master_isr(ptr); 627 562 } 628 563 564 + static bool cdns_i2c_error_check(struct cdns_i2c *id) 565 + { 566 + unsigned int isr_status; 567 + 568 + id->err_status = 0; 569 + 570 + isr_status = cdns_i2c_readreg(CDNS_I2C_ISR_OFFSET); 571 + cdns_i2c_writereg(isr_status & CDNS_I2C_IXR_ERR_INTR_MASK, CDNS_I2C_ISR_OFFSET); 572 + 573 + id->err_status = isr_status & CDNS_I2C_IXR_ERR_INTR_MASK; 574 + 575 + return !!id->err_status; 576 + } 577 + 578 + static void cdns_i2c_mrecv_atomic(struct cdns_i2c *id) 579 + { 580 + while (id->recv_count > 0) { 581 + bool updatetx; 582 + 583 + /* 584 + * Check if transfer size register needs to be updated again for a 585 + * large data receive operation. 586 + */ 587 + updatetx = id->recv_count > id->curr_recv_count; 588 + 589 + while (id->curr_recv_count > 0) { 590 + if (cdns_i2c_readreg(CDNS_I2C_SR_OFFSET) & CDNS_I2C_SR_RXDV) { 591 + *id->p_recv_buf = cdns_i2c_readreg(CDNS_I2C_DATA_OFFSET); 592 + id->p_recv_buf++; 593 + id->recv_count--; 594 + id->curr_recv_count--; 595 + 596 + /* 597 + * Clear the hold bit that was set for FIFO control, 598 + * if the remaining RX data is less than or equal to 599 + * the FIFO depth, unless a repeated start is selected. 600 + */ 601 + if (id->recv_count <= id->fifo_depth && !id->bus_hold_flag) 602 + cdns_i2c_clear_bus_hold(id); 603 + } 604 + if (cdns_i2c_error_check(id)) 605 + return; 606 + if (cdns_is_holdquirk(id, updatetx)) 607 + break; 608 + } 609 + 610 + /* 611 + * The controller sends NACK to the slave/target when transfer size 612 + * register reaches zero without considering the HOLD bit. 613 + * This workaround is implemented for large data transfers to 614 + * maintain transfer size non-zero while performing a large 615 + * receive operation. 616 + */ 617 + if (cdns_is_holdquirk(id, updatetx)) { 618 + /* wait while fifo is full */ 619 + while (cdns_i2c_readreg(CDNS_I2C_XFER_SIZE_OFFSET) != 620 + (id->curr_recv_count - id->fifo_depth)) 621 + ; 622 + 623 + /* 624 + * Check number of bytes to be received against maximum 625 + * transfer size and update register accordingly. 626 + */ 627 + if ((id->recv_count - id->fifo_depth) > 628 + id->transfer_size) { 629 + cdns_i2c_writereg(id->transfer_size, 630 + CDNS_I2C_XFER_SIZE_OFFSET); 631 + id->curr_recv_count = id->transfer_size + 632 + id->fifo_depth; 633 + } else { 634 + cdns_i2c_writereg(id->recv_count - 635 + id->fifo_depth, 636 + CDNS_I2C_XFER_SIZE_OFFSET); 637 + id->curr_recv_count = id->recv_count; 638 + } 639 + } 640 + } 641 + 642 + /* Clear hold (if not repeated start) */ 643 + if (!id->recv_count && !id->bus_hold_flag) 644 + cdns_i2c_clear_bus_hold(id); 645 + } 646 + 629 647 /** 630 648 * cdns_i2c_mrecv - Prepare and start a master receive operation 631 649 * @id: pointer to the i2c device structure ··· 803 655 cdns_i2c_writereg(addr, CDNS_I2C_ADDR_OFFSET); 804 656 } 805 657 806 - cdns_i2c_writereg(CDNS_I2C_ENABLED_INTR_MASK, CDNS_I2C_IER_OFFSET); 658 + if (!id->atomic) 659 + cdns_i2c_writereg(CDNS_I2C_ENABLED_INTR_MASK, CDNS_I2C_IER_OFFSET); 660 + else 661 + cdns_i2c_mrecv_atomic(id); 662 + } 663 + 664 + static void cdns_i2c_msend_rem_atomic(struct cdns_i2c *id) 665 + { 666 + while (id->send_count) { 667 + unsigned int avail_bytes; 668 + unsigned int bytes_to_send; 669 + 670 + avail_bytes = id->fifo_depth - cdns_i2c_readreg(CDNS_I2C_XFER_SIZE_OFFSET); 671 + if (id->send_count > avail_bytes) 672 + bytes_to_send = avail_bytes; 673 + else 674 + bytes_to_send = id->send_count; 675 + 676 + while (bytes_to_send--) { 677 + cdns_i2c_writereg((*id->p_send_buf++), CDNS_I2C_DATA_OFFSET); 678 + id->send_count--; 679 + } 680 + if (cdns_i2c_error_check(id)) 681 + return; 682 + } 683 + 684 + if (!id->send_count && !id->bus_hold_flag) 685 + cdns_i2c_clear_bus_hold(id); 807 686 } 808 687 809 688 /** ··· 893 718 cdns_i2c_writereg(id->p_msg->addr & CDNS_I2C_ADDR_MASK, 894 719 CDNS_I2C_ADDR_OFFSET); 895 720 896 - cdns_i2c_writereg(CDNS_I2C_ENABLED_INTR_MASK, CDNS_I2C_IER_OFFSET); 721 + if (!id->atomic) 722 + cdns_i2c_writereg(CDNS_I2C_ENABLED_INTR_MASK, CDNS_I2C_IER_OFFSET); 723 + else if (id->send_count > 0) 724 + cdns_i2c_msend_rem_atomic(id); 897 725 } 898 726 899 727 /** ··· 936 758 937 759 id->p_msg = msg; 938 760 id->err_status = 0; 939 - reinit_completion(&id->xfer_done); 761 + if (!id->atomic) 762 + reinit_completion(&id->xfer_done); 940 763 941 764 /* Check for the TEN Bit mode on each msg */ 942 765 reg = cdns_i2c_readreg(CDNS_I2C_CR_OFFSET); ··· 959 780 960 781 /* Minimal time to execute this message */ 961 782 msg_timeout = msecs_to_jiffies((1000 * msg->len * BITS_PER_BYTE) / id->i2c_clk); 962 - /* Plus some wiggle room */ 963 - msg_timeout += msecs_to_jiffies(500); 783 + 784 + /* 785 + * Plus some wiggle room. 786 + * For non-atomic contexts, 500 ms is added to the timeout. 787 + * For atomic contexts, 2000 ms is added because transfers happen in polled 788 + * mode, requiring more time to account for the polling overhead. 789 + */ 790 + if (!id->atomic) 791 + msg_timeout += msecs_to_jiffies(500); 792 + else 793 + msg_timeout += msecs_to_jiffies(2000); 964 794 965 795 if (msg_timeout < adap->timeout) 966 796 msg_timeout = adap->timeout; 967 797 968 - /* Wait for the signal of completion */ 969 - time_left = wait_for_completion_timeout(&id->xfer_done, msg_timeout); 798 + if (!id->atomic) { 799 + /* Wait for the signal of completion */ 800 + time_left = wait_for_completion_timeout(&id->xfer_done, msg_timeout); 801 + } else { 802 + /* 0 is success, -ETIMEDOUT is error */ 803 + time_left = !readl_poll_timeout_atomic(id->membase + CDNS_I2C_ISR_OFFSET, 804 + reg, (reg & CDNS_I2C_IXR_COMP), 805 + CDNS_I2C_POLL_US_ATOMIC, msg_timeout); 806 + } 807 + 970 808 if (time_left == 0) { 971 809 cdns_i2c_master_reset(adap); 972 810 return -ETIMEDOUT; ··· 1002 806 return 0; 1003 807 } 1004 808 809 + static int cdns_i2c_master_common_xfer(struct i2c_adapter *adap, 810 + struct i2c_msg *msgs, 811 + int num) 812 + { 813 + int ret, count; 814 + u32 reg; 815 + struct cdns_i2c *id = adap->algo_data; 816 + bool hold_quirk; 817 + 818 + /* Check if the bus is free */ 819 + if (!id->atomic) 820 + ret = readl_relaxed_poll_timeout(id->membase + CDNS_I2C_SR_OFFSET, 821 + reg, 822 + !(reg & CDNS_I2C_SR_BA), 823 + CDNS_I2C_POLL_US, CDNS_I2C_TIMEOUT_US); 824 + else 825 + ret = readl_poll_timeout_atomic(id->membase + CDNS_I2C_SR_OFFSET, 826 + reg, 827 + !(reg & CDNS_I2C_SR_BA), 828 + CDNS_I2C_POLL_US_ATOMIC, CDNS_I2C_TIMEOUT_US); 829 + if (ret) { 830 + ret = -EAGAIN; 831 + if (id->adap.bus_recovery_info) 832 + i2c_recover_bus(adap); 833 + return ret; 834 + } 835 + 836 + hold_quirk = !!(id->quirks & CDNS_I2C_BROKEN_HOLD_BIT); 837 + /* 838 + * Set the flag to one when multiple messages are to be 839 + * processed with a repeated start. 840 + */ 841 + if (num > 1) { 842 + /* 843 + * This controller does not give completion interrupt after a 844 + * master receive message if HOLD bit is set (repeated start), 845 + * resulting in SW timeout. Hence, if a receive message is 846 + * followed by any other message, an error is returned 847 + * indicating that this sequence is not supported. 848 + */ 849 + for (count = 0; (count < num - 1 && hold_quirk); count++) { 850 + if (msgs[count].flags & I2C_M_RD) { 851 + dev_warn(adap->dev.parent, 852 + "Can't do repeated start after a receive message\n"); 853 + return -EOPNOTSUPP; 854 + } 855 + } 856 + id->bus_hold_flag = 1; 857 + reg = cdns_i2c_readreg(CDNS_I2C_CR_OFFSET); 858 + reg |= CDNS_I2C_CR_HOLD; 859 + cdns_i2c_writereg(reg, CDNS_I2C_CR_OFFSET); 860 + } else { 861 + id->bus_hold_flag = 0; 862 + } 863 + 864 + /* Process the msg one by one */ 865 + for (count = 0; count < num; count++, msgs++) { 866 + if (count == (num - 1)) 867 + id->bus_hold_flag = 0; 868 + 869 + ret = cdns_i2c_process_msg(id, msgs, adap); 870 + if (ret) 871 + return ret; 872 + 873 + /* Report the other error interrupts to application */ 874 + if (id->err_status || id->err_status_atomic) { 875 + cdns_i2c_master_reset(adap); 876 + 877 + if (id->err_status & CDNS_I2C_IXR_NACK) 878 + return -ENXIO; 879 + 880 + return -EIO; 881 + } 882 + } 883 + return 0; 884 + } 885 + 1005 886 /** 1006 887 * cdns_i2c_master_xfer - The main i2c transfer function 1007 888 * @adap: pointer to the i2c adapter driver instance ··· 1092 819 static int cdns_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, 1093 820 int num) 1094 821 { 1095 - int ret, count; 1096 - u32 reg; 822 + int ret; 1097 823 struct cdns_i2c *id = adap->algo_data; 1098 - bool hold_quirk; 1099 824 #if IS_ENABLED(CONFIG_I2C_SLAVE) 1100 825 bool change_role = false; 1101 826 #endif ··· 1118 847 } 1119 848 #endif 1120 849 1121 - /* Check if the bus is free */ 1122 - 1123 - ret = readl_relaxed_poll_timeout(id->membase + CDNS_I2C_SR_OFFSET, 1124 - reg, 1125 - !(reg & CDNS_I2C_SR_BA), 1126 - CDNS_I2C_POLL_US, CDNS_I2C_TIMEOUT_US); 1127 - if (ret) { 1128 - ret = -EAGAIN; 1129 - if (id->adap.bus_recovery_info) 1130 - i2c_recover_bus(adap); 1131 - goto out; 1132 - } 1133 - 1134 - hold_quirk = !!(id->quirks & CDNS_I2C_BROKEN_HOLD_BIT); 1135 - /* 1136 - * Set the flag to one when multiple messages are to be 1137 - * processed with a repeated start. 1138 - */ 1139 - if (num > 1) { 1140 - /* 1141 - * This controller does not give completion interrupt after a 1142 - * master receive message if HOLD bit is set (repeated start), 1143 - * resulting in SW timeout. Hence, if a receive message is 1144 - * followed by any other message, an error is returned 1145 - * indicating that this sequence is not supported. 1146 - */ 1147 - for (count = 0; (count < num - 1 && hold_quirk); count++) { 1148 - if (msgs[count].flags & I2C_M_RD) { 1149 - dev_warn(adap->dev.parent, 1150 - "Can't do repeated start after a receive message\n"); 1151 - ret = -EOPNOTSUPP; 1152 - goto out; 1153 - } 1154 - } 1155 - id->bus_hold_flag = 1; 1156 - reg = cdns_i2c_readreg(CDNS_I2C_CR_OFFSET); 1157 - reg |= CDNS_I2C_CR_HOLD; 1158 - cdns_i2c_writereg(reg, CDNS_I2C_CR_OFFSET); 1159 - } else { 1160 - id->bus_hold_flag = 0; 1161 - } 1162 - 1163 - /* Process the msg one by one */ 1164 - for (count = 0; count < num; count++, msgs++) { 1165 - if (count == (num - 1)) 1166 - id->bus_hold_flag = 0; 1167 - 1168 - ret = cdns_i2c_process_msg(id, msgs, adap); 1169 - if (ret) 1170 - goto out; 1171 - 1172 - /* Report the other error interrupts to application */ 1173 - if (id->err_status) { 1174 - cdns_i2c_master_reset(adap); 1175 - 1176 - if (id->err_status & CDNS_I2C_IXR_NACK) { 1177 - ret = -ENXIO; 1178 - goto out; 1179 - } 1180 - ret = -EIO; 1181 - goto out; 1182 - } 1183 - } 1184 - 1185 - ret = num; 1186 - 1187 - out: 1188 - 850 + ret = cdns_i2c_master_common_xfer(adap, msgs, num); 851 + if (!ret) 852 + ret = num; 1189 853 #if IS_ENABLED(CONFIG_I2C_SLAVE) 854 + out: 1190 855 /* Switch i2c mode to slave */ 1191 856 if (change_role) 1192 857 cdns_i2c_set_mode(CDNS_I2C_MODE_SLAVE, id); ··· 1130 923 1131 924 pm_runtime_mark_last_busy(id->dev); 1132 925 pm_runtime_put_autosuspend(id->dev); 926 + return ret; 927 + } 928 + 929 + /** 930 + * cdns_i2c_master_xfer_atomic - The i2c transfer function in atomic mode 931 + * @adap: pointer to the i2c adapter driver instance 932 + * @msgs: pointer to the i2c message structure 933 + * @num: the number of messages to transfer 934 + * 935 + * Return: number of msgs processed on success, negative error otherwise 936 + */ 937 + static int cdns_i2c_master_xfer_atomic(struct i2c_adapter *adap, struct i2c_msg *msgs, 938 + int num) 939 + { 940 + int ret; 941 + struct cdns_i2c *id = adap->algo_data; 942 + 943 + ret = cdns_i2c_runtime_resume(id->dev); 944 + if (ret) 945 + return ret; 946 + 947 + if (id->quirks & CDNS_I2C_BROKEN_HOLD_BIT) { 948 + dev_warn(id->adap.dev.parent, 949 + "Atomic xfer not supported for version 1.0\n"); 950 + return 0; 951 + } 952 + 953 + id->atomic = true; 954 + ret = cdns_i2c_master_common_xfer(adap, msgs, num); 955 + if (!ret) 956 + ret = num; 957 + 958 + id->atomic = false; 959 + cdns_i2c_runtime_suspend(id->dev); 960 + 1133 961 return ret; 1134 962 } 1135 963 ··· 1232 990 1233 991 static const struct i2c_algorithm cdns_i2c_algo = { 1234 992 .master_xfer = cdns_i2c_master_xfer, 993 + .master_xfer_atomic = cdns_i2c_master_xfer_atomic, 1235 994 .functionality = cdns_i2c_func, 1236 995 #if IS_ENABLED(CONFIG_I2C_SLAVE) 1237 996 .reg_slave = cdns_reg_slave, ··· 1401 1158 } 1402 1159 } 1403 1160 1404 - /** 1405 - * cdns_i2c_runtime_suspend - Runtime suspend method for the driver 1406 - * @dev: Address of the platform_device structure 1407 - * 1408 - * Put the driver into low power mode. 1409 - * 1410 - * Return: 0 always 1411 - */ 1412 - static int __maybe_unused cdns_i2c_runtime_suspend(struct device *dev) 1413 - { 1414 - struct cdns_i2c *xi2c = dev_get_drvdata(dev); 1415 - 1416 - clk_disable(xi2c->clk); 1417 - 1418 - return 0; 1419 - } 1420 - 1421 1161 static int __maybe_unused cdns_i2c_suspend(struct device *dev) 1422 1162 { 1423 1163 struct cdns_i2c *xi2c = dev_get_drvdata(dev); ··· 1409 1183 1410 1184 if (!pm_runtime_status_suspended(dev)) 1411 1185 return cdns_i2c_runtime_suspend(dev); 1412 - 1413 - return 0; 1414 - } 1415 - 1416 - /** 1417 - * cdns_i2c_init - Controller initialisation 1418 - * @id: Device private data structure 1419 - * 1420 - * Initialise the i2c controller. 1421 - * 1422 - */ 1423 - static void cdns_i2c_init(struct cdns_i2c *id) 1424 - { 1425 - cdns_i2c_writereg(id->ctrl_reg, CDNS_I2C_CR_OFFSET); 1426 - /* 1427 - * Cadence I2C controller has a bug wherein it generates 1428 - * invalid read transaction after HW timeout in master receiver mode. 1429 - * HW timeout is not used by this driver and the interrupt is disabled. 1430 - * But the feature itself cannot be disabled. Hence maximum value 1431 - * is written to this register to reduce the chances of error. 1432 - */ 1433 - cdns_i2c_writereg(CDNS_I2C_TIMEOUT_MAX, CDNS_I2C_TIME_OUT_OFFSET); 1434 - } 1435 - 1436 - /** 1437 - * cdns_i2c_runtime_resume - Runtime resume 1438 - * @dev: Address of the platform_device structure 1439 - * 1440 - * Runtime resume callback. 1441 - * 1442 - * Return: 0 on success and error value on error 1443 - */ 1444 - static int __maybe_unused cdns_i2c_runtime_resume(struct device *dev) 1445 - { 1446 - struct cdns_i2c *xi2c = dev_get_drvdata(dev); 1447 - int ret; 1448 - 1449 - ret = clk_enable(xi2c->clk); 1450 - if (ret) { 1451 - dev_err(dev, "Cannot enable clock.\n"); 1452 - return ret; 1453 - } 1454 - cdns_i2c_init(xi2c); 1455 1186 1456 1187 return 0; 1457 1188 } ··· 1652 1469 .pm = &cdns_i2c_dev_pm_ops, 1653 1470 }, 1654 1471 .probe = cdns_i2c_probe, 1655 - .remove_new = cdns_i2c_remove, 1472 + .remove = cdns_i2c_remove, 1656 1473 }; 1657 1474 1658 1475 module_platform_driver(cdns_i2c_drv);
+1 -1
drivers/i2c/busses/i2c-cbus-gpio.c
··· 264 264 265 265 static struct platform_driver cbus_i2c_driver = { 266 266 .probe = cbus_i2c_probe, 267 - .remove_new = cbus_i2c_remove, 267 + .remove = cbus_i2c_remove, 268 268 .driver = { 269 269 .name = "i2c-cbus-gpio", 270 270 .of_match_table = of_match_ptr(i2c_cbus_dt_ids),
+1 -1
drivers/i2c/busses/i2c-cht-wc.c
··· 546 546 547 547 static struct platform_driver cht_wc_i2c_adap_driver = { 548 548 .probe = cht_wc_i2c_adap_i2c_probe, 549 - .remove_new = cht_wc_i2c_adap_i2c_remove, 549 + .remove = cht_wc_i2c_adap_i2c_remove, 550 550 .driver = { 551 551 .name = "cht_wcove_ext_chgr", 552 552 },
+1 -1
drivers/i2c/busses/i2c-cpm.c
··· 701 701 702 702 static struct platform_driver cpm_i2c_driver = { 703 703 .probe = cpm_i2c_probe, 704 - .remove_new = cpm_i2c_remove, 704 + .remove = cpm_i2c_remove, 705 705 .driver = { 706 706 .name = "fsl-i2c-cpm", 707 707 .of_match_table = cpm_i2c_match,
+1 -1
drivers/i2c/busses/i2c-cros-ec-tunnel.c
··· 304 304 305 305 static struct platform_driver ec_i2c_tunnel_driver = { 306 306 .probe = ec_i2c_probe, 307 - .remove_new = ec_i2c_remove, 307 + .remove = ec_i2c_remove, 308 308 .driver = { 309 309 .name = "cros-ec-i2c-tunnel", 310 310 .acpi_match_table = ACPI_PTR(cros_ec_i2c_tunnel_acpi_id),
+1 -1
drivers/i2c/busses/i2c-davinci.c
··· 935 935 936 936 static struct platform_driver davinci_i2c_driver = { 937 937 .probe = davinci_i2c_probe, 938 - .remove_new = davinci_i2c_remove, 938 + .remove = davinci_i2c_remove, 939 939 .id_table = davinci_i2c_driver_ids, 940 940 .driver = { 941 941 .name = "i2c_davinci",
+5 -5
drivers/i2c/busses/i2c-designware-amdpsp.c
··· 155 155 156 156 /* 157 157 * If there is any pending transaction, cannot release the bus here. 158 - * psp_release_i2c_bus will take care of this later. 158 + * psp_release_i2c_bus() will take care of this later. 159 159 */ 160 160 if (psp_i2c_access_count) 161 161 goto cleanup; ··· 210 210 { 211 211 mutex_lock(&psp_i2c_access_mutex); 212 212 213 - /* Return early if mailbox was malfunctional */ 213 + /* Return early if mailbox was malfunctioned */ 214 214 if (psp_i2c_mbox_fail) 215 215 goto cleanup; 216 216 217 217 /* 218 - * If we are last owner of PSP semaphore, need to release aribtration 218 + * If we are last owner of PSP semaphore, need to release arbitration 219 219 * via mailbox. 220 220 */ 221 221 psp_i2c_access_count--; ··· 235 235 236 236 /* 237 237 * Locking methods are based on the default implementation from 238 - * drivers/i2c/i2c-core-base.c, but with psp acquire and release operations 238 + * drivers/i2c/i2c-core-base.c, but with PSP acquire and release operations 239 239 * added. With this in place we can ensure that i2c clients on the bus shared 240 - * with psp are able to lock HW access to the bus for arbitrary number of 240 + * with PSP are able to lock HW access to the bus for arbitrary number of 241 241 * operations - that is e.g. write-wait-read. 242 242 */ 243 243 static void i2c_adapter_dw_psp_lock_bus(struct i2c_adapter *adapter,
+24 -44
drivers/i2c/busses/i2c-designware-common.c
··· 33 33 34 34 #include "i2c-designware-core.h" 35 35 36 - static char *abort_sources[] = { 36 + static const char *const abort_sources[] = { 37 37 [ABRT_7B_ADDR_NOACK] = 38 38 "slave address not acknowledged (7bit mode)", 39 39 [ABRT_10ADDR1_NOACK] = ··· 127 127 * Autodetects needed register access mode and creates the regmap with 128 128 * corresponding read/write callbacks. This must be called before doing any 129 129 * other register access. 130 + * 131 + * Return: 0 on success, or negative errno otherwise. 130 132 */ 131 133 int i2c_dw_init_regmap(struct dw_i2c_dev *dev) 132 134 { ··· 176 174 /* 177 175 * Note we'll check the return value of the regmap IO accessors only 178 176 * at the probe stage. The rest of the code won't do this because 179 - * basically we have MMIO-based regmap so non of the read/write methods 177 + * basically we have MMIO-based regmap, so none of the read/write methods 180 178 * can fail. 181 179 */ 182 180 dev->map = devm_regmap_init(dev->dev, NULL, dev, &map_cfg); ··· 338 336 339 337 acpi_speed = i2c_acpi_find_bus_speed(device); 340 338 /* 341 - * Some DSTDs use a non standard speed, round down to the lowest 339 + * Some DSDTs use a non standard speed, round down to the lowest 342 340 * standard speed. 343 341 */ 344 342 for (i = 0; i < ARRAY_SIZE(supported_speeds); i++) { ··· 409 407 } 410 408 411 409 u32 i2c_dw_scl_hcnt(struct dw_i2c_dev *dev, unsigned int reg, u32 ic_clk, 412 - u32 tSYMBOL, u32 tf, int cond, int offset) 410 + u32 tSYMBOL, u32 tf, int offset) 413 411 { 414 412 if (!ic_clk) 415 413 return i2c_dw_read_scl_reg(dev, reg); 416 414 417 415 /* 418 - * DesignWare I2C core doesn't seem to have solid strategy to meet 419 - * the tHD;STA timing spec. Configuring _HCNT based on tHIGH spec 420 - * will result in violation of the tHD;STA spec. 416 + * Conditional expression: 417 + * 418 + * IC_[FS]S_SCL_HCNT + 3 >= IC_CLK * (tHD;STA + tf) 419 + * 420 + * This is just experimental rule; the tHD;STA period turned 421 + * out to be proportinal to (_HCNT + 3). With this setting, 422 + * we could meet both tHIGH and tHD;STA timing specs. 423 + * 424 + * If unsure, you'd better to take this alternative. 425 + * 426 + * The reason why we need to take into account "tf" here, 427 + * is the same as described in i2c_dw_scl_lcnt(). 421 428 */ 422 - if (cond) 423 - /* 424 - * Conditional expression: 425 - * 426 - * IC_[FS]S_SCL_HCNT + (1+4+3) >= IC_CLK * tHIGH 427 - * 428 - * This is based on the DW manuals, and represents an ideal 429 - * configuration. The resulting I2C bus speed will be 430 - * faster than any of the others. 431 - * 432 - * If your hardware is free from tHD;STA issue, try this one. 433 - */ 434 - return DIV_ROUND_CLOSEST_ULL((u64)ic_clk * tSYMBOL, MICRO) - 435 - 8 + offset; 436 - else 437 - /* 438 - * Conditional expression: 439 - * 440 - * IC_[FS]S_SCL_HCNT + 3 >= IC_CLK * (tHD;STA + tf) 441 - * 442 - * This is just experimental rule; the tHD;STA period turned 443 - * out to be proportinal to (_HCNT + 3). With this setting, 444 - * we could meet both tHIGH and tHD;STA timing specs. 445 - * 446 - * If unsure, you'd better to take this alternative. 447 - * 448 - * The reason why we need to take into account "tf" here, 449 - * is the same as described in i2c_dw_scl_lcnt(). 450 - */ 451 - return DIV_ROUND_CLOSEST_ULL((u64)ic_clk * (tSYMBOL + tf), MICRO) - 452 - 3 + offset; 429 + return DIV_ROUND_CLOSEST_ULL((u64)ic_clk * (tSYMBOL + tf), MICRO) - 3 + offset; 453 430 } 454 431 455 432 u32 i2c_dw_scl_lcnt(struct dw_i2c_dev *dev, unsigned int reg, u32 ic_clk, ··· 448 467 * account the fall time of SCL signal (tf). Default tf value 449 468 * should be 0.3 us, for safety. 450 469 */ 451 - return DIV_ROUND_CLOSEST_ULL((u64)ic_clk * (tLOW + tf), MICRO) - 452 - 1 + offset; 470 + return DIV_ROUND_CLOSEST_ULL((u64)ic_clk * (tLOW + tf), MICRO) - 1 + offset; 453 471 } 454 472 455 473 int i2c_dw_set_sda_hold(struct dw_i2c_dev *dev) ··· 551 571 552 572 /* 553 573 * Wait 10 times the signaling period of the highest I2C 554 - * transfer supported by the driver (for 400KHz this is 574 + * transfer supported by the driver (for 400kHz this is 555 575 * 25us) as described in the DesignWare I2C databook. 556 576 */ 557 577 usleep_range(25, 250); ··· 658 678 659 679 if (abort_source & DW_IC_TX_ARB_LOST) 660 680 return -EAGAIN; 661 - else if (abort_source & DW_IC_TX_ABRT_GCALL_READ) 681 + if (abort_source & DW_IC_TX_ABRT_GCALL_READ) 662 682 return -EINVAL; /* wrong msgs[] data */ 663 - else 664 - return -EIO; 683 + 684 + return -EIO; 665 685 } 666 686 667 687 int i2c_dw_set_fifo_size(struct dw_i2c_dev *dev)
+6 -6
drivers/i2c/busses/i2c-designware-core.h
··· 143 143 #define DW_IC_SLAVE 1 144 144 145 145 /* 146 - * Hardware abort codes from the DW_IC_TX_ABRT_SOURCE register 146 + * Hardware abort codes from the DW_IC_TX_ABRT_SOURCE register. 147 147 * 148 - * Only expected abort codes are listed here 149 - * refer to the datasheet for the full list 148 + * Only expected abort codes are listed here, 149 + * refer to the datasheet for the full list. 150 150 */ 151 151 #define ABRT_7B_ADDR_NOACK 0 152 152 #define ABRT_10ADDR1_NOACK 1 ··· 201 201 * @rst: optional reset for the controller 202 202 * @slave: represent an I2C slave device 203 203 * @get_clk_rate_khz: callback to retrieve IP specific bus speed 204 - * @cmd_err: run time hadware error code 204 + * @cmd_err: run time hardware error code 205 205 * @msgs: points to an array of messages currently being transferred 206 206 * @msgs_num: the number of elements in msgs 207 207 * @msg_write_idx: the element index of the current tx message in the msgs array ··· 237 237 * @release_lock: function to release a hardware lock on the bus 238 238 * @semaphore_idx: Index of table with semaphore type attached to the bus. It's 239 239 * -1 if there is no semaphore. 240 - * @shared_with_punit: true if this bus is shared with the SoCs PUNIT 240 + * @shared_with_punit: true if this bus is shared with the SoC's PUNIT 241 241 * @init: function to initialize the I2C hardware 242 242 * @set_sda_hold_time: callback to retrieve IP specific SDA hold timing 243 243 * @mode: operation mode - DW_IC_MASTER or DW_IC_SLAVE ··· 329 329 330 330 int i2c_dw_init_regmap(struct dw_i2c_dev *dev); 331 331 u32 i2c_dw_scl_hcnt(struct dw_i2c_dev *dev, unsigned int reg, u32 ic_clk, 332 - u32 tSYMBOL, u32 tf, int cond, int offset); 332 + u32 tSYMBOL, u32 tf, int offset); 333 333 u32 i2c_dw_scl_lcnt(struct dw_i2c_dev *dev, unsigned int reg, u32 ic_clk, 334 334 u32 tLOW, u32 tf, int offset); 335 335 int i2c_dw_set_sda_hold(struct dw_i2c_dev *dev);
+8 -9
drivers/i2c/busses/i2c-designware-master.c
··· 71 71 ic_clk, 72 72 4000, /* tHD;STA = tHIGH = 4.0 us */ 73 73 sda_falling_time, 74 - 0, /* 0: DW default, 1: Ideal */ 75 74 0); /* No offset */ 76 75 dev->ss_lcnt = 77 76 i2c_dw_scl_lcnt(dev, ··· 104 105 ic_clk, 105 106 260, /* tHIGH = 260 ns */ 106 107 sda_falling_time, 107 - 0, /* DW default */ 108 108 0); /* No offset */ 109 109 dev->fs_lcnt = 110 110 i2c_dw_scl_lcnt(dev, ··· 127 129 ic_clk, 128 130 600, /* tHD;STA = tHIGH = 0.6 us */ 129 131 sda_falling_time, 130 - 0, /* 0: DW default, 1: Ideal */ 131 132 0); /* No offset */ 132 133 dev->fs_lcnt = 133 134 i2c_dw_scl_lcnt(dev, ··· 158 161 ic_clk, 159 162 160, /* tHIGH = 160 ns */ 160 163 sda_falling_time, 161 - 0, /* DW default */ 162 164 0); /* No offset */ 163 165 dev->hs_lcnt = 164 166 i2c_dw_scl_lcnt(dev, ··· 180 184 } 181 185 182 186 /** 183 - * i2c_dw_init_master() - Initialize the designware I2C master hardware 187 + * i2c_dw_init_master() - Initialize the DesignWare I2C master hardware 184 188 * @dev: device private data 185 189 * 186 190 * This functions configures and enables the I2C master. 187 191 * This function is called during I2C init function, and in case of timeout at 188 192 * run time. 193 + * 194 + * Return: 0 on success, or negative errno otherwise. 189 195 */ 190 196 static int i2c_dw_init_master(struct dw_i2c_dev *dev) 191 197 { ··· 355 357 /* 356 358 * Initiate the i2c read/write transaction of buffer length, 357 359 * and poll for bus busy status. For the last message transfer, 358 - * update the command with stopbit enable. 360 + * update the command with stop bit enable. 359 361 */ 360 362 for (msg_itr_lmt = buf_len; msg_itr_lmt > 0; msg_itr_lmt--) { 361 363 if (msg_wrt_idx == num_msgs - 1 && msg_itr_lmt == 1) ··· 400 402 401 403 /* 402 404 * Initiate (and continue) low level master read/write transaction. 403 - * This function is only called from i2c_dw_isr, and pumping i2c_msg 405 + * This function is only called from i2c_dw_isr(), and pumping i2c_msg 404 406 * messages into the tx buffer. Even if the size of i2c_msg data is 405 407 * longer than the size of the tx buffer, it handles everything. 406 408 */ ··· 438 440 buf = msgs[dev->msg_write_idx].buf; 439 441 buf_len = msgs[dev->msg_write_idx].len; 440 442 441 - /* If both IC_EMPTYFIFO_HOLD_MASTER_EN and 443 + /* 444 + * If both IC_EMPTYFIFO_HOLD_MASTER_EN and 442 445 * IC_RESTART_EN are set, we must manually 443 446 * set restart bit between messages. 444 447 */ ··· 970 971 rinfo->unprepare_recovery = i2c_dw_unprepare_recovery; 971 972 adap->bus_recovery_info = rinfo; 972 973 973 - dev_info(dev->dev, "running with gpio recovery mode! scl%s", 974 + dev_info(dev->dev, "running with GPIO recovery mode! scl%s", 974 975 rinfo->sda_gpiod ? ",sda" : ""); 975 976 976 977 return 0;
+19 -20
drivers/i2c/busses/i2c-designware-pcidrv.c
··· 51 51 u16 fs_hcnt; 52 52 u16 ss_lcnt; 53 53 u16 fs_lcnt; 54 - u32 sda_hold; 54 + u32 sda_hold_time; 55 55 }; 56 56 57 57 struct dw_pci_controller { ··· 76 76 .fs_hcnt = 0x55, 77 77 .ss_lcnt = 0x200, 78 78 .fs_lcnt = 0x99, 79 - .sda_hold = 0x6, 79 + .sda_hold_time = 0x6, 80 80 }; 81 81 82 82 /* Haswell HCNT/LCNT/SDA hold time */ ··· 85 85 .fs_hcnt = 0x48, 86 86 .ss_lcnt = 0x01fb, 87 87 .fs_lcnt = 0xa0, 88 - .sda_hold = 0x9, 88 + .sda_hold_time = 0x9, 89 89 }; 90 90 91 91 /* NAVI-AMD HCNT/LCNT/SDA hold time */ 92 92 static struct dw_scl_sda_cfg navi_amd_config = { 93 93 .ss_hcnt = 0x1ae, 94 94 .ss_lcnt = 0x23a, 95 - .sda_hold = 0x9, 95 + .sda_hold_time = 0x9, 96 96 }; 97 97 98 98 static u32 mfld_get_clk_rate_khz(struct dw_i2c_dev *dev) ··· 207 207 static int i2c_dw_pci_probe(struct pci_dev *pdev, 208 208 const struct pci_device_id *id) 209 209 { 210 + struct device *device = &pdev->dev; 210 211 struct dw_i2c_dev *dev; 211 212 struct i2c_adapter *adap; 212 213 int r; ··· 215 214 struct dw_scl_sda_cfg *cfg; 216 215 217 216 if (id->driver_data >= ARRAY_SIZE(dw_pci_controllers)) 218 - return dev_err_probe(&pdev->dev, -EINVAL, 219 - "Invalid driver data %ld\n", 217 + return dev_err_probe(device, -EINVAL, "Invalid driver data %ld\n", 220 218 id->driver_data); 221 219 222 220 controller = &dw_pci_controllers[id->driver_data]; 223 221 224 222 r = pcim_enable_device(pdev); 225 223 if (r) 226 - return dev_err_probe(&pdev->dev, r, 227 - "Failed to enable I2C PCI device\n"); 224 + return dev_err_probe(device, r, "Failed to enable I2C PCI device\n"); 228 225 229 226 pci_set_master(pdev); 230 227 231 228 r = pcim_iomap_regions(pdev, 1 << 0, pci_name(pdev)); 232 229 if (r) 233 - return dev_err_probe(&pdev->dev, r, 234 - "I/O memory remapping failed\n"); 230 + return dev_err_probe(device, r, "I/O memory remapping failed\n"); 235 231 236 - dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); 232 + dev = devm_kzalloc(device, sizeof(*dev), GFP_KERNEL); 237 233 if (!dev) 238 234 return -ENOMEM; 239 235 ··· 240 242 241 243 dev->get_clk_rate_khz = controller->get_clk_rate_khz; 242 244 dev->base = pcim_iomap_table(pdev)[0]; 243 - dev->dev = &pdev->dev; 245 + dev->dev = device; 244 246 dev->irq = pci_irq_vector(pdev, 0); 245 247 dev->flags |= controller->flags; 246 248 ··· 264 266 dev->fs_hcnt = cfg->fs_hcnt; 265 267 dev->ss_lcnt = cfg->ss_lcnt; 266 268 dev->fs_lcnt = cfg->fs_lcnt; 267 - dev->sda_hold_time = cfg->sda_hold; 269 + dev->sda_hold_time = cfg->sda_hold_time; 268 270 } 269 271 270 272 adap = &dev->adapter; ··· 279 281 if ((dev->flags & MODEL_MASK) == MODEL_AMD_NAVI_GPU) { 280 282 dev->slave = i2c_new_ccgx_ucsi(&dev->adapter, dev->irq, &dgpu_node); 281 283 if (IS_ERR(dev->slave)) 282 - return dev_err_probe(dev->dev, PTR_ERR(dev->slave), 284 + return dev_err_probe(device, PTR_ERR(dev->slave), 283 285 "register UCSI failed\n"); 284 286 } 285 287 286 - pm_runtime_set_autosuspend_delay(&pdev->dev, 1000); 287 - pm_runtime_use_autosuspend(&pdev->dev); 288 - pm_runtime_put_autosuspend(&pdev->dev); 289 - pm_runtime_allow(&pdev->dev); 288 + pm_runtime_set_autosuspend_delay(device, 1000); 289 + pm_runtime_use_autosuspend(device); 290 + pm_runtime_put_autosuspend(device); 291 + pm_runtime_allow(device); 290 292 291 293 return 0; 292 294 } ··· 294 296 static void i2c_dw_pci_remove(struct pci_dev *pdev) 295 297 { 296 298 struct dw_i2c_dev *dev = pci_get_drvdata(pdev); 299 + struct device *device = &pdev->dev; 297 300 298 301 i2c_dw_disable(dev); 299 302 300 - pm_runtime_forbid(&pdev->dev); 301 - pm_runtime_get_noresume(&pdev->dev); 303 + pm_runtime_forbid(device); 304 + pm_runtime_get_noresume(device); 302 305 303 306 i2c_del_adapter(&dev->adapter); 304 307 }
+27 -28
drivers/i2c/busses/i2c-designware-platdrv.c
··· 72 72 return ret; 73 73 74 74 return regmap_write(dev->sysmap, BT1_I2C_CTL, 75 - BT1_I2C_CTL_GO | BT1_I2C_CTL_WR | (reg & BT1_I2C_CTL_ADDR_MASK)); 75 + BT1_I2C_CTL_GO | BT1_I2C_CTL_WR | (reg & BT1_I2C_CTL_ADDR_MASK)); 76 76 } 77 77 78 78 static const struct regmap_config bt1_i2c_cfg = { ··· 205 205 206 206 static int dw_i2c_plat_probe(struct platform_device *pdev) 207 207 { 208 + struct device *device = &pdev->dev; 208 209 struct i2c_adapter *adap; 209 210 struct dw_i2c_dev *dev; 210 211 int irq, ret; ··· 214 213 if (irq < 0) 215 214 return irq; 216 215 217 - dev = devm_kzalloc(&pdev->dev, sizeof(struct dw_i2c_dev), GFP_KERNEL); 216 + dev = devm_kzalloc(device, sizeof(*dev), GFP_KERNEL); 218 217 if (!dev) 219 218 return -ENOMEM; 220 219 221 - dev->flags = (uintptr_t)device_get_match_data(&pdev->dev); 222 - if (device_property_present(&pdev->dev, "wx,i2c-snps-model")) 220 + dev->flags = (uintptr_t)device_get_match_data(device); 221 + if (device_property_present(device, "wx,i2c-snps-model")) 223 222 dev->flags = MODEL_WANGXUN_SP | ACCESS_POLLING; 224 223 225 - dev->dev = &pdev->dev; 224 + dev->dev = device; 226 225 dev->irq = irq; 227 226 platform_set_drvdata(pdev, dev); 228 227 ··· 230 229 if (ret) 231 230 return ret; 232 231 233 - dev->rst = devm_reset_control_get_optional_exclusive(&pdev->dev, NULL); 232 + dev->rst = devm_reset_control_get_optional_exclusive(device, NULL); 234 233 if (IS_ERR(dev->rst)) 235 234 return PTR_ERR(dev->rst); 236 235 ··· 247 246 i2c_dw_configure(dev); 248 247 249 248 /* Optional interface clock */ 250 - dev->pclk = devm_clk_get_optional(&pdev->dev, "pclk"); 249 + dev->pclk = devm_clk_get_optional(device, "pclk"); 251 250 if (IS_ERR(dev->pclk)) { 252 251 ret = PTR_ERR(dev->pclk); 253 252 goto exit_reset; 254 253 } 255 254 256 - dev->clk = devm_clk_get_optional(&pdev->dev, NULL); 255 + dev->clk = devm_clk_get_optional(device, NULL); 257 256 if (IS_ERR(dev->clk)) { 258 257 ret = PTR_ERR(dev->clk); 259 258 goto exit_reset; ··· 278 277 adap = &dev->adapter; 279 278 adap->owner = THIS_MODULE; 280 279 adap->class = dmi_check_system(dw_i2c_hwmon_class_dmi) ? 281 - I2C_CLASS_HWMON : I2C_CLASS_DEPRECATED; 280 + I2C_CLASS_HWMON : I2C_CLASS_DEPRECATED; 282 281 adap->nr = -1; 283 282 284 - if (dev->flags & ACCESS_NO_IRQ_SUSPEND) { 285 - dev_pm_set_driver_flags(&pdev->dev, 286 - DPM_FLAG_SMART_PREPARE); 287 - } else { 288 - dev_pm_set_driver_flags(&pdev->dev, 289 - DPM_FLAG_SMART_PREPARE | 290 - DPM_FLAG_SMART_SUSPEND); 291 - } 283 + if (dev->flags & ACCESS_NO_IRQ_SUSPEND) 284 + dev_pm_set_driver_flags(device, DPM_FLAG_SMART_PREPARE); 285 + else 286 + dev_pm_set_driver_flags(device, DPM_FLAG_SMART_PREPARE | DPM_FLAG_SMART_SUSPEND); 292 287 293 - device_enable_async_suspend(&pdev->dev); 288 + device_enable_async_suspend(device); 294 289 295 290 /* The code below assumes runtime PM to be disabled. */ 296 - WARN_ON(pm_runtime_enabled(&pdev->dev)); 291 + WARN_ON(pm_runtime_enabled(device)); 297 292 298 - pm_runtime_set_autosuspend_delay(&pdev->dev, 1000); 299 - pm_runtime_use_autosuspend(&pdev->dev); 300 - pm_runtime_set_active(&pdev->dev); 293 + pm_runtime_set_autosuspend_delay(device, 1000); 294 + pm_runtime_use_autosuspend(device); 295 + pm_runtime_set_active(device); 301 296 302 297 if (dev->shared_with_punit) 303 - pm_runtime_get_noresume(&pdev->dev); 298 + pm_runtime_get_noresume(device); 304 299 305 - pm_runtime_enable(&pdev->dev); 300 + pm_runtime_enable(device); 306 301 307 302 ret = i2c_dw_probe(dev); 308 303 if (ret) ··· 316 319 static void dw_i2c_plat_remove(struct platform_device *pdev) 317 320 { 318 321 struct dw_i2c_dev *dev = platform_get_drvdata(pdev); 322 + struct device *device = &pdev->dev; 319 323 320 - pm_runtime_get_sync(&pdev->dev); 324 + pm_runtime_get_sync(device); 321 325 322 326 i2c_del_adapter(&dev->adapter); 323 327 324 328 i2c_dw_disable(dev); 325 329 326 - pm_runtime_dont_use_autosuspend(&pdev->dev); 327 - pm_runtime_put_sync(&pdev->dev); 330 + pm_runtime_dont_use_autosuspend(device); 331 + pm_runtime_put_sync(device); 328 332 dw_i2c_plat_pm_cleanup(dev); 329 333 330 334 i2c_dw_remove_lock_support(dev); ··· 352 354 { "HISI02A1", 0 }, 353 355 { "HISI02A2", 0 }, 354 356 { "HISI02A3", 0 }, 357 + { "HJMC3001", 0 }, 355 358 { "HYGO0010", ACCESS_INTR_MASK }, 356 359 { "INT33C2", 0 }, 357 360 { "INT33C3", 0 }, ··· 371 372 372 373 static struct platform_driver dw_i2c_driver = { 373 374 .probe = dw_i2c_plat_probe, 374 - .remove_new = dw_i2c_plat_remove, 375 + .remove = dw_i2c_plat_remove, 375 376 .driver = { 376 377 .name = "i2c_designware", 377 378 .of_match_table = dw_i2c_of_match,
+4 -2
drivers/i2c/busses/i2c-designware-slave.c
··· 32 32 } 33 33 34 34 /** 35 - * i2c_dw_init_slave() - Initialize the designware i2c slave hardware 35 + * i2c_dw_init_slave() - Initialize the DesignWare i2c slave hardware 36 36 * @dev: device private data 37 37 * 38 38 * This function configures and enables the I2C in slave mode. 39 39 * This function is called during I2C init function, and in case of timeout at 40 40 * run time. 41 + * 42 + * Return: 0 on success, or negative errno otherwise. 41 43 */ 42 44 static int i2c_dw_init_slave(struct dw_i2c_dev *dev) 43 45 { ··· 266 264 ret = devm_request_irq(dev->dev, dev->irq, i2c_dw_isr_slave, 267 265 IRQF_SHARED, dev_name(dev->dev), dev); 268 266 if (ret) { 269 - dev_err(dev->dev, "failure requesting irq %i: %d\n", 267 + dev_err(dev->dev, "failure requesting IRQ %i: %d\n", 270 268 dev->irq, ret); 271 269 return ret; 272 270 }
+1 -1
drivers/i2c/busses/i2c-digicolor.c
··· 363 363 364 364 static struct platform_driver dc_i2c_driver = { 365 365 .probe = dc_i2c_probe, 366 - .remove_new = dc_i2c_remove, 366 + .remove = dc_i2c_remove, 367 367 .driver = { 368 368 .name = "digicolor-i2c", 369 369 .of_match_table = dc_i2c_match,
+1 -1
drivers/i2c/busses/i2c-dln2.c
··· 245 245 static struct platform_driver dln2_i2c_driver = { 246 246 .driver.name = "dln2-i2c", 247 247 .probe = dln2_i2c_probe, 248 - .remove_new = dln2_i2c_remove, 248 + .remove = dln2_i2c_remove, 249 249 }; 250 250 251 251 module_platform_driver(dln2_i2c_driver);
+1 -1
drivers/i2c/busses/i2c-emev2.c
··· 425 425 426 426 static struct platform_driver em_i2c_driver = { 427 427 .probe = em_i2c_probe, 428 - .remove_new = em_i2c_remove, 428 + .remove = em_i2c_remove, 429 429 .driver = { 430 430 .name = "em-i2c", 431 431 .of_match_table = em_i2c_ids,
+1 -1
drivers/i2c/busses/i2c-exynos5.c
··· 1009 1009 1010 1010 static struct platform_driver exynos5_i2c_driver = { 1011 1011 .probe = exynos5_i2c_probe, 1012 - .remove_new = exynos5_i2c_remove, 1012 + .remove = exynos5_i2c_remove, 1013 1013 .driver = { 1014 1014 .name = "exynos5-hsi2c", 1015 1015 .pm = pm_sleep_ptr(&exynos5_i2c_dev_pm_ops),
+1 -1
drivers/i2c/busses/i2c-gpio.c
··· 481 481 .acpi_match_table = i2c_gpio_acpi_match, 482 482 }, 483 483 .probe = i2c_gpio_probe, 484 - .remove_new = i2c_gpio_remove, 484 + .remove = i2c_gpio_remove, 485 485 }; 486 486 487 487 static int __init i2c_gpio_init(void)
+1 -1
drivers/i2c/busses/i2c-gxp.c
··· 595 595 596 596 static struct platform_driver gxp_i2c_driver = { 597 597 .probe = gxp_i2c_probe, 598 - .remove_new = gxp_i2c_remove, 598 + .remove = gxp_i2c_remove, 599 599 .driver = { 600 600 .name = "gxp-i2c", 601 601 .of_match_table = gxp_i2c_of_match,
+1 -1
drivers/i2c/busses/i2c-highlander.c
··· 454 454 }, 455 455 456 456 .probe = highlander_i2c_probe, 457 - .remove_new = highlander_i2c_remove, 457 + .remove = highlander_i2c_remove, 458 458 }; 459 459 460 460 module_platform_driver(highlander_i2c_driver);
+1 -1
drivers/i2c/busses/i2c-hix5hd2.c
··· 508 508 509 509 static struct platform_driver hix5hd2_i2c_driver = { 510 510 .probe = hix5hd2_i2c_probe, 511 - .remove_new = hix5hd2_i2c_remove, 511 + .remove = hix5hd2_i2c_remove, 512 512 .driver = { 513 513 .name = "hix5hd2-i2c", 514 514 .pm = pm_ptr(&hix5hd2_i2c_pm_ops),
+6
drivers/i2c/busses/i2c-i801.c
··· 81 81 * Meteor Lake PCH-S (PCH) 0x7f23 32 hard yes yes yes 82 82 * Birch Stream (SOC) 0x5796 32 hard yes yes yes 83 83 * Arrow Lake-H (SOC) 0x7722 32 hard yes yes yes 84 + * Panther Lake-H (SOC) 0xe322 32 hard yes yes yes 85 + * Panther Lake-P (SOC) 0xe422 32 hard yes yes yes 84 86 * 85 87 * Features supported by this driver: 86 88 * Software PEC no ··· 263 261 #define PCI_DEVICE_ID_INTEL_CANNONLAKE_H_SMBUS 0xa323 264 262 #define PCI_DEVICE_ID_INTEL_COMETLAKE_V_SMBUS 0xa3a3 265 263 #define PCI_DEVICE_ID_INTEL_METEOR_LAKE_SOC_S_SMBUS 0xae22 264 + #define PCI_DEVICE_ID_INTEL_PANTHER_LAKE_H_SMBUS 0xe322 265 + #define PCI_DEVICE_ID_INTEL_PANTHER_LAKE_P_SMBUS 0xe422 266 266 267 267 struct i801_mux_config { 268 268 char *gpio_chip; ··· 1059 1055 { PCI_DEVICE_DATA(INTEL, METEOR_LAKE_PCH_S_SMBUS, FEATURES_ICH5 | FEATURE_TCO_CNL) }, 1060 1056 { PCI_DEVICE_DATA(INTEL, BIRCH_STREAM_SMBUS, FEATURES_ICH5 | FEATURE_TCO_CNL) }, 1061 1057 { PCI_DEVICE_DATA(INTEL, ARROW_LAKE_H_SMBUS, FEATURES_ICH5 | FEATURE_TCO_CNL) }, 1058 + { PCI_DEVICE_DATA(INTEL, PANTHER_LAKE_H_SMBUS, FEATURES_ICH5 | FEATURE_TCO_CNL) }, 1059 + { PCI_DEVICE_DATA(INTEL, PANTHER_LAKE_P_SMBUS, FEATURES_ICH5 | FEATURE_TCO_CNL) }, 1062 1060 { 0, } 1063 1061 }; 1064 1062
+1 -1
drivers/i2c/busses/i2c-ibm_iic.c
··· 790 790 .of_match_table = ibm_iic_match, 791 791 }, 792 792 .probe = iic_probe, 793 - .remove_new = iic_remove, 793 + .remove = iic_remove, 794 794 }; 795 795 796 796 module_platform_driver(ibm_iic_driver);
+1 -1
drivers/i2c/busses/i2c-img-scb.c
··· 1497 1497 .pm = pm_ptr(&img_i2c_pm), 1498 1498 }, 1499 1499 .probe = img_i2c_probe, 1500 - .remove_new = img_i2c_remove, 1500 + .remove = img_i2c_remove, 1501 1501 }; 1502 1502 module_platform_driver(img_scb_i2c_driver); 1503 1503
+1 -1
drivers/i2c/busses/i2c-imx-lpi2c.c
··· 703 703 704 704 static struct platform_driver lpi2c_imx_driver = { 705 705 .probe = lpi2c_imx_probe, 706 - .remove_new = lpi2c_imx_remove, 706 + .remove = lpi2c_imx_remove, 707 707 .driver = { 708 708 .name = DRIVER_NAME, 709 709 .of_match_table = lpi2c_imx_of_match,
+357 -52
drivers/i2c/busses/i2c-imx.c
··· 17 17 * Copyright (C) 2008 Darius Augulis <darius.augulis at teltonika.lt> 18 18 * 19 19 * Copyright 2013 Freescale Semiconductor, Inc. 20 - * Copyright 2020 NXP 20 + * Copyright 2020, 2024 NXP 21 21 * 22 22 */ 23 23 ··· 84 84 85 85 #define IMX_I2C_REGSHIFT 2 86 86 #define VF610_I2C_REGSHIFT 0 87 + #define S32G_I2C_REGSHIFT 0 87 88 88 89 /* Bits of IMX I2C registers */ 89 90 #define I2SR_RXAK 0x01 ··· 166 165 { 3840, 0x3F }, { 4096, 0x7B }, { 5120, 0x7D }, { 6144, 0x7E }, 167 166 }; 168 167 168 + /* S32G2/S32G3 clock divider, register value pairs */ 169 + static struct imx_i2c_clk_pair s32g2_i2c_clk_div[] = { 170 + { 34, 0x00 }, { 36, 0x01 }, { 38, 0x02 }, { 40, 0x03 }, 171 + { 42, 0x04 }, { 44, 0x05 }, { 46, 0x06 }, { 48, 0x09 }, 172 + { 52, 0x0A }, { 54, 0x07 }, { 56, 0x0B }, { 60, 0x0C }, 173 + { 64, 0x0D }, { 68, 0x40 }, { 72, 0x0E }, { 76, 0x42 }, 174 + { 80, 0x12 }, { 84, 0x0F }, { 88, 0x13 }, { 96, 0x14 }, 175 + { 104, 0x15 }, { 108, 0x47 }, { 112, 0x19 }, { 120, 0x16 }, 176 + { 128, 0x1A }, { 136, 0x80 }, { 144, 0x17 }, { 152, 0x82 }, 177 + { 160, 0x1C }, { 168, 0x84 }, { 176, 0x1D }, { 192, 0x21 }, 178 + { 208, 0x1E }, { 216, 0x87 }, { 224, 0x22 }, { 240, 0x56 }, 179 + { 256, 0x1F }, { 288, 0x24 }, { 320, 0x25 }, { 336, 0x8F }, 180 + { 352, 0x93 }, { 356, 0x5D }, { 358, 0x98 }, { 384, 0x26 }, 181 + { 416, 0x56 }, { 448, 0x2A }, { 480, 0x27 }, { 512, 0x2B }, 182 + { 576, 0x2C }, { 640, 0x2D }, { 704, 0x9D }, { 768, 0x2E }, 183 + { 832, 0x9D }, { 896, 0x32 }, { 960, 0x2F }, { 1024, 0x33 }, 184 + { 1152, 0x34 }, { 1280, 0x35 }, { 1536, 0x36 }, { 1792, 0x3A }, 185 + { 1920, 0x37 }, { 2048, 0x3B }, { 2304, 0x74 }, { 2560, 0x3D }, 186 + { 3072, 0x3E }, { 3584, 0x7A }, { 3840, 0x3F }, { 4096, 0x7B }, 187 + { 4608, 0x7C }, { 5120, 0x7D }, { 6144, 0x7E }, { 7168, 0xBA }, 188 + { 7680, 0x7F }, { 8192, 0xBB }, { 9216, 0xBC }, { 10240, 0xBD }, 189 + { 12288, 0xBE }, { 15360, 0xBF }, 190 + }; 191 + 169 192 enum imx_i2c_type { 170 193 IMX1_I2C, 171 194 IMX21_I2C, 195 + S32G_I2C, 172 196 VF610_I2C, 173 197 }; 174 198 ··· 223 197 enum dma_data_direction dma_data_dir; 224 198 }; 225 199 200 + enum imx_i2c_state { 201 + IMX_I2C_STATE_DONE, 202 + IMX_I2C_STATE_FAILED, 203 + IMX_I2C_STATE_WRITE, 204 + IMX_I2C_STATE_DMA, 205 + IMX_I2C_STATE_READ, 206 + IMX_I2C_STATE_READ_CONTINUE, 207 + IMX_I2C_STATE_READ_BLOCK_DATA, 208 + IMX_I2C_STATE_READ_BLOCK_DATA_LEN, 209 + }; 210 + 226 211 struct imx_i2c_struct { 227 212 struct i2c_adapter adapter; 228 213 struct clk *clk; ··· 252 215 struct imx_i2c_dma *dma; 253 216 struct i2c_client *slave; 254 217 enum i2c_slave_event last_slave_event; 218 + 219 + struct i2c_msg *msg; 220 + unsigned int msg_buf_idx; 221 + int isr_result; 222 + bool is_lastmsg; 223 + enum imx_i2c_state state; 224 + 225 + bool multi_master; 255 226 256 227 /* For checking slave events. */ 257 228 spinlock_t slave_lock; ··· 303 258 .ndivs = ARRAY_SIZE(vf610_i2c_clk_div), 304 259 .i2sr_clr_opcode = I2SR_CLR_OPCODE_W1C, 305 260 .i2cr_ien_opcode = I2CR_IEN_OPCODE_0, 261 + }; 306 262 263 + static const struct imx_i2c_hwdata s32g2_i2c_hwdata = { 264 + .devtype = S32G_I2C, 265 + .regshift = S32G_I2C_REGSHIFT, 266 + .clk_div = s32g2_i2c_clk_div, 267 + .ndivs = ARRAY_SIZE(s32g2_i2c_clk_div), 268 + .i2sr_clr_opcode = I2SR_CLR_OPCODE_W1C, 269 + .i2cr_ien_opcode = I2CR_IEN_OPCODE_0, 307 270 }; 308 271 309 272 static const struct platform_device_id imx_i2c_devtype[] = { ··· 341 288 { .compatible = "fsl,imx8mp-i2c", .data = &imx6_i2c_hwdata, }, 342 289 { .compatible = "fsl,imx8mq-i2c", .data = &imx6_i2c_hwdata, }, 343 290 { .compatible = "fsl,vf610-i2c", .data = &vf610_i2c_hwdata, }, 291 + { .compatible = "nxp,s32g2-i2c", .data = &s32g2_i2c_hwdata, }, 344 292 { /* sentinel */ } 345 293 }; 346 294 MODULE_DEVICE_TABLE(of, i2c_imx_dt_ids); ··· 535 481 unsigned long orig_jiffies = jiffies; 536 482 unsigned int temp; 537 483 484 + if (!i2c_imx->multi_master) 485 + return 0; 486 + 538 487 while (1) { 539 488 temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2SR); 540 489 ··· 597 540 return -ETIMEDOUT; 598 541 } 599 542 600 - /* check for arbitration lost */ 601 - if (i2c_imx->i2csr & I2SR_IAL) { 543 + /* In multi-master mode check for arbitration lost */ 544 + if (i2c_imx->multi_master && (i2c_imx->i2csr & I2SR_IAL)) { 602 545 dev_dbg(&i2c_imx->adapter.dev, "<%s> Arbitration lost\n", __func__); 603 546 i2c_imx_clear_irq(i2c_imx, I2SR_IAL); 604 547 ··· 960 903 return ret; 961 904 } 962 905 906 + static inline int i2c_imx_isr_acked(struct imx_i2c_struct *i2c_imx) 907 + { 908 + i2c_imx->isr_result = 0; 909 + 910 + if (imx_i2c_read_reg(i2c_imx, IMX_I2C_I2SR) & I2SR_RXAK) { 911 + i2c_imx->state = IMX_I2C_STATE_FAILED; 912 + i2c_imx->isr_result = -ENXIO; 913 + wake_up(&i2c_imx->queue); 914 + } 915 + 916 + return i2c_imx->isr_result; 917 + } 918 + 919 + static inline int i2c_imx_isr_write(struct imx_i2c_struct *i2c_imx) 920 + { 921 + int result; 922 + 923 + result = i2c_imx_isr_acked(i2c_imx); 924 + if (result) 925 + return result; 926 + 927 + if (i2c_imx->msg->len == i2c_imx->msg_buf_idx) 928 + return 0; 929 + 930 + imx_i2c_write_reg(i2c_imx->msg->buf[i2c_imx->msg_buf_idx++], i2c_imx, IMX_I2C_I2DR); 931 + 932 + return 1; 933 + } 934 + 935 + static inline int i2c_imx_isr_read(struct imx_i2c_struct *i2c_imx) 936 + { 937 + int result; 938 + unsigned int temp; 939 + 940 + result = i2c_imx_isr_acked(i2c_imx); 941 + if (result) 942 + return result; 943 + 944 + /* setup bus to read data */ 945 + temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR); 946 + temp &= ~I2CR_MTX; 947 + if (i2c_imx->msg->len - 1) 948 + temp &= ~I2CR_TXAK; 949 + 950 + imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR); 951 + imx_i2c_read_reg(i2c_imx, IMX_I2C_I2DR); /* dummy read */ 952 + 953 + return 0; 954 + } 955 + 956 + static inline void i2c_imx_isr_read_continue(struct imx_i2c_struct *i2c_imx) 957 + { 958 + unsigned int temp; 959 + 960 + if ((i2c_imx->msg->len - 1) == i2c_imx->msg_buf_idx) { 961 + if (i2c_imx->is_lastmsg) { 962 + /* 963 + * It must generate STOP before read I2DR to prevent 964 + * controller from generating another clock cycle 965 + */ 966 + temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR); 967 + if (!(temp & I2CR_MSTA)) 968 + i2c_imx->stopped = 1; 969 + temp &= ~(I2CR_MSTA | I2CR_MTX); 970 + imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR); 971 + } else { 972 + /* 973 + * For i2c master receiver repeat restart operation like: 974 + * read -> repeat MSTA -> read/write 975 + * The controller must set MTX before read the last byte in 976 + * the first read operation, otherwise the first read cost 977 + * one extra clock cycle. 978 + */ 979 + temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR); 980 + temp |= I2CR_MTX; 981 + imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR); 982 + } 983 + } else if (i2c_imx->msg_buf_idx == (i2c_imx->msg->len - 2)) { 984 + temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR); 985 + temp |= I2CR_TXAK; 986 + imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR); 987 + } 988 + 989 + i2c_imx->msg->buf[i2c_imx->msg_buf_idx++] = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2DR); 990 + } 991 + 992 + static inline void i2c_imx_isr_read_block_data_len(struct imx_i2c_struct *i2c_imx) 993 + { 994 + u8 len = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2DR); 995 + 996 + if (len == 0 || len > I2C_SMBUS_BLOCK_MAX) { 997 + i2c_imx->isr_result = -EPROTO; 998 + i2c_imx->state = IMX_I2C_STATE_FAILED; 999 + wake_up(&i2c_imx->queue); 1000 + } 1001 + i2c_imx->msg->len += len; 1002 + } 1003 + 963 1004 static irqreturn_t i2c_imx_master_isr(struct imx_i2c_struct *i2c_imx, unsigned int status) 964 1005 { 965 - /* save status register */ 966 - i2c_imx->i2csr = status; 967 - wake_up(&i2c_imx->queue); 1006 + /* 1007 + * This state machine handles I2C reception and transmission in non-DMA 1008 + * mode. We must process all the data in the ISR to reduce the delay 1009 + * between two consecutive messages. If the data is not processed in 1010 + * the ISR, SMBus devices may timeout, leading to a bus error. 1011 + */ 1012 + switch (i2c_imx->state) { 1013 + case IMX_I2C_STATE_DMA: 1014 + i2c_imx->i2csr = status; 1015 + wake_up(&i2c_imx->queue); 1016 + break; 1017 + 1018 + case IMX_I2C_STATE_READ: 1019 + if (i2c_imx_isr_read(i2c_imx)) 1020 + break; 1021 + i2c_imx->state = IMX_I2C_STATE_READ_CONTINUE; 1022 + break; 1023 + 1024 + case IMX_I2C_STATE_READ_CONTINUE: 1025 + i2c_imx_isr_read_continue(i2c_imx); 1026 + if (i2c_imx->msg_buf_idx == i2c_imx->msg->len) { 1027 + i2c_imx->state = IMX_I2C_STATE_DONE; 1028 + wake_up(&i2c_imx->queue); 1029 + } 1030 + break; 1031 + 1032 + case IMX_I2C_STATE_READ_BLOCK_DATA: 1033 + if (i2c_imx_isr_read(i2c_imx)) 1034 + break; 1035 + i2c_imx->state = IMX_I2C_STATE_READ_BLOCK_DATA_LEN; 1036 + break; 1037 + 1038 + case IMX_I2C_STATE_READ_BLOCK_DATA_LEN: 1039 + i2c_imx_isr_read_block_data_len(i2c_imx); 1040 + i2c_imx->state = IMX_I2C_STATE_READ_CONTINUE; 1041 + break; 1042 + 1043 + case IMX_I2C_STATE_WRITE: 1044 + if (i2c_imx_isr_write(i2c_imx)) 1045 + break; 1046 + i2c_imx->state = IMX_I2C_STATE_DONE; 1047 + wake_up(&i2c_imx->queue); 1048 + break; 1049 + 1050 + default: 1051 + i2c_imx->i2csr = status; 1052 + i2c_imx->state = IMX_I2C_STATE_FAILED; 1053 + i2c_imx->isr_result = -EINVAL; 1054 + wake_up(&i2c_imx->queue); 1055 + } 968 1056 969 1057 return IRQ_HANDLED; 970 1058 } ··· 1155 953 unsigned long orig_jiffies = jiffies; 1156 954 struct imx_i2c_dma *dma = i2c_imx->dma; 1157 955 struct device *dev = &i2c_imx->adapter.dev; 956 + 957 + i2c_imx->state = IMX_I2C_STATE_DMA; 1158 958 1159 959 dma->chan_using = dma->chan_tx; 1160 960 dma->dma_transfer_dir = DMA_MEM_TO_DEV; ··· 1210 1006 return i2c_imx_acked(i2c_imx); 1211 1007 } 1212 1008 1009 + static int i2c_imx_prepare_read(struct imx_i2c_struct *i2c_imx, 1010 + struct i2c_msg *msgs, bool use_dma) 1011 + { 1012 + int result; 1013 + unsigned int temp = 0; 1014 + 1015 + /* write slave address */ 1016 + imx_i2c_write_reg(i2c_8bit_addr_from_msg(msgs), i2c_imx, IMX_I2C_I2DR); 1017 + result = i2c_imx_trx_complete(i2c_imx, !use_dma); 1018 + if (result) 1019 + return result; 1020 + result = i2c_imx_acked(i2c_imx); 1021 + if (result) 1022 + return result; 1023 + 1024 + dev_dbg(&i2c_imx->adapter.dev, "<%s> setup bus\n", __func__); 1025 + 1026 + /* setup bus to read data */ 1027 + temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR); 1028 + temp &= ~I2CR_MTX; 1029 + 1030 + /* 1031 + * Reset the I2CR_TXAK flag initially for SMBus block read since the 1032 + * length is unknown 1033 + */ 1034 + if (msgs->len - 1) 1035 + temp &= ~I2CR_TXAK; 1036 + if (use_dma) 1037 + temp |= I2CR_DMAEN; 1038 + 1039 + imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR); 1040 + imx_i2c_read_reg(i2c_imx, IMX_I2C_I2DR); /* dummy read */ 1041 + 1042 + return 0; 1043 + } 1044 + 1213 1045 static int i2c_imx_dma_read(struct imx_i2c_struct *i2c_imx, 1214 1046 struct i2c_msg *msgs, bool is_lastmsg) 1215 1047 { ··· 1256 1016 struct imx_i2c_dma *dma = i2c_imx->dma; 1257 1017 struct device *dev = &i2c_imx->adapter.dev; 1258 1018 1019 + i2c_imx->state = IMX_I2C_STATE_DMA; 1020 + 1021 + result = i2c_imx_prepare_read(i2c_imx, msgs, true); 1022 + if (result) 1023 + return result; 1024 + 1025 + dev_dbg(&i2c_imx->adapter.dev, "<%s> read data\n", __func__); 1259 1026 1260 1027 dma->chan_using = dma->chan_rx; 1261 1028 dma->dma_transfer_dir = DMA_DEV_TO_MEM; ··· 1339 1092 return 0; 1340 1093 } 1341 1094 1342 - static int i2c_imx_write(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs, 1343 - bool atomic) 1095 + static int i2c_imx_atomic_write(struct imx_i2c_struct *i2c_imx, 1096 + struct i2c_msg *msgs) 1344 1097 { 1345 1098 int i, result; 1346 1099 ··· 1349 1102 1350 1103 /* write slave address */ 1351 1104 imx_i2c_write_reg(i2c_8bit_addr_from_msg(msgs), i2c_imx, IMX_I2C_I2DR); 1352 - result = i2c_imx_trx_complete(i2c_imx, atomic); 1105 + result = i2c_imx_trx_complete(i2c_imx, true); 1353 1106 if (result) 1354 1107 return result; 1355 1108 result = i2c_imx_acked(i2c_imx); ··· 1363 1116 "<%s> write byte: B%d=0x%X\n", 1364 1117 __func__, i, msgs->buf[i]); 1365 1118 imx_i2c_write_reg(msgs->buf[i], i2c_imx, IMX_I2C_I2DR); 1366 - result = i2c_imx_trx_complete(i2c_imx, atomic); 1119 + result = i2c_imx_trx_complete(i2c_imx, true); 1367 1120 if (result) 1368 1121 return result; 1369 1122 result = i2c_imx_acked(i2c_imx); ··· 1373 1126 return 0; 1374 1127 } 1375 1128 1376 - static int i2c_imx_read(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs, 1377 - bool is_lastmsg, bool atomic) 1129 + static int i2c_imx_write(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs) 1130 + { 1131 + dev_dbg(&i2c_imx->adapter.dev, "<%s> write slave address: addr=0x%x\n", 1132 + __func__, i2c_8bit_addr_from_msg(msgs)); 1133 + 1134 + i2c_imx->state = IMX_I2C_STATE_WRITE; 1135 + i2c_imx->msg = msgs; 1136 + i2c_imx->msg_buf_idx = 0; 1137 + 1138 + /* 1139 + * By writing the device address we start the state machine in the ISR. 1140 + * The ISR will report when it is done or when it fails. 1141 + */ 1142 + imx_i2c_write_reg(i2c_8bit_addr_from_msg(msgs), i2c_imx, IMX_I2C_I2DR); 1143 + wait_event_timeout(i2c_imx->queue, 1144 + i2c_imx->state == IMX_I2C_STATE_DONE || 1145 + i2c_imx->state == IMX_I2C_STATE_FAILED, 1146 + (msgs->len + 1) * HZ / 10); 1147 + if (i2c_imx->state == IMX_I2C_STATE_FAILED) { 1148 + dev_dbg(&i2c_imx->adapter.dev, "<%s> write failed with %d\n", 1149 + __func__, i2c_imx->isr_result); 1150 + return i2c_imx->isr_result; 1151 + } 1152 + if (i2c_imx->state != IMX_I2C_STATE_DONE) { 1153 + dev_err(&i2c_imx->adapter.dev, "<%s> write timedout\n", __func__); 1154 + return -ETIMEDOUT; 1155 + } 1156 + return 0; 1157 + } 1158 + 1159 + static int i2c_imx_atomic_read(struct imx_i2c_struct *i2c_imx, 1160 + struct i2c_msg *msgs, bool is_lastmsg) 1378 1161 { 1379 1162 int i, result; 1380 1163 unsigned int temp; 1381 1164 int block_data = msgs->flags & I2C_M_RECV_LEN; 1382 - int use_dma = i2c_imx->dma && msgs->flags & I2C_M_DMA_SAFE && 1383 - msgs->len >= DMA_THRESHOLD && !block_data; 1384 1165 1385 - dev_dbg(&i2c_imx->adapter.dev, 1386 - "<%s> write slave address: addr=0x%x\n", 1387 - __func__, i2c_8bit_addr_from_msg(msgs)); 1388 - 1389 - /* write slave address */ 1390 - imx_i2c_write_reg(i2c_8bit_addr_from_msg(msgs), i2c_imx, IMX_I2C_I2DR); 1391 - result = i2c_imx_trx_complete(i2c_imx, atomic); 1166 + result = i2c_imx_prepare_read(i2c_imx, msgs, false); 1392 1167 if (result) 1393 1168 return result; 1394 - result = i2c_imx_acked(i2c_imx); 1395 - if (result) 1396 - return result; 1397 - 1398 - dev_dbg(&i2c_imx->adapter.dev, "<%s> setup bus\n", __func__); 1399 - 1400 - /* setup bus to read data */ 1401 - temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR); 1402 - temp &= ~I2CR_MTX; 1403 - 1404 - /* 1405 - * Reset the I2CR_TXAK flag initially for SMBus block read since the 1406 - * length is unknown 1407 - */ 1408 - if ((msgs->len - 1) || block_data) 1409 - temp &= ~I2CR_TXAK; 1410 - if (use_dma) 1411 - temp |= I2CR_DMAEN; 1412 - imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR); 1413 - imx_i2c_read_reg(i2c_imx, IMX_I2C_I2DR); /* dummy read */ 1414 1169 1415 1170 dev_dbg(&i2c_imx->adapter.dev, "<%s> read data\n", __func__); 1416 - 1417 - if (use_dma) 1418 - return i2c_imx_dma_read(i2c_imx, msgs, is_lastmsg); 1419 1171 1420 1172 /* read data */ 1421 1173 for (i = 0; i < msgs->len; i++) { 1422 1174 u8 len = 0; 1423 1175 1424 - result = i2c_imx_trx_complete(i2c_imx, atomic); 1176 + result = i2c_imx_trx_complete(i2c_imx, true); 1425 1177 if (result) 1426 1178 return result; 1427 1179 /* ··· 1451 1205 temp &= ~(I2CR_MSTA | I2CR_MTX); 1452 1206 imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR); 1453 1207 if (!i2c_imx->stopped) 1454 - i2c_imx_bus_busy(i2c_imx, 0, atomic); 1208 + i2c_imx_bus_busy(i2c_imx, 0, true); 1455 1209 } else { 1456 1210 /* 1457 1211 * For i2c master receiver repeat restart operation like: ··· 1482 1236 return 0; 1483 1237 } 1484 1238 1239 + static int i2c_imx_read(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs, 1240 + bool is_lastmsg) 1241 + { 1242 + int block_data = msgs->flags & I2C_M_RECV_LEN; 1243 + 1244 + dev_dbg(&i2c_imx->adapter.dev, 1245 + "<%s> write slave address: addr=0x%x\n", 1246 + __func__, i2c_8bit_addr_from_msg(msgs)); 1247 + 1248 + i2c_imx->is_lastmsg = is_lastmsg; 1249 + 1250 + if (block_data) 1251 + i2c_imx->state = IMX_I2C_STATE_READ_BLOCK_DATA; 1252 + else 1253 + i2c_imx->state = IMX_I2C_STATE_READ; 1254 + i2c_imx->msg = msgs; 1255 + i2c_imx->msg_buf_idx = 0; 1256 + 1257 + /* 1258 + * By writing the device address we start the state machine in the ISR. 1259 + * The ISR will report when it is done or when it fails. 1260 + */ 1261 + imx_i2c_write_reg(i2c_8bit_addr_from_msg(msgs), i2c_imx, IMX_I2C_I2DR); 1262 + wait_event_timeout(i2c_imx->queue, 1263 + i2c_imx->state == IMX_I2C_STATE_DONE || 1264 + i2c_imx->state == IMX_I2C_STATE_FAILED, 1265 + (msgs->len + 1) * HZ / 10); 1266 + if (i2c_imx->state == IMX_I2C_STATE_FAILED) { 1267 + dev_dbg(&i2c_imx->adapter.dev, "<%s> read failed with %d\n", 1268 + __func__, i2c_imx->isr_result); 1269 + return i2c_imx->isr_result; 1270 + } 1271 + if (i2c_imx->state != IMX_I2C_STATE_DONE) { 1272 + dev_err(&i2c_imx->adapter.dev, "<%s> read timedout\n", __func__); 1273 + return -ETIMEDOUT; 1274 + } 1275 + if (!i2c_imx->stopped) 1276 + return i2c_imx_bus_busy(i2c_imx, 0, false); 1277 + 1278 + return 0; 1279 + } 1280 + 1485 1281 static int i2c_imx_xfer_common(struct i2c_adapter *adapter, 1486 1282 struct i2c_msg *msgs, int num, bool atomic) 1487 1283 { ··· 1531 1243 int result; 1532 1244 bool is_lastmsg = false; 1533 1245 struct imx_i2c_struct *i2c_imx = i2c_get_adapdata(adapter); 1246 + int use_dma = 0; 1534 1247 1535 1248 /* Start I2C transfer */ 1536 1249 result = i2c_imx_start(i2c_imx, atomic); ··· 1584 1295 (temp & I2SR_SRW ? 1 : 0), (temp & I2SR_IIF ? 1 : 0), 1585 1296 (temp & I2SR_RXAK ? 1 : 0)); 1586 1297 #endif 1298 + 1299 + use_dma = i2c_imx->dma && msgs[i].len >= DMA_THRESHOLD && 1300 + msgs[i].flags & I2C_M_DMA_SAFE; 1587 1301 if (msgs[i].flags & I2C_M_RD) { 1588 - result = i2c_imx_read(i2c_imx, &msgs[i], is_lastmsg, atomic); 1302 + int block_data = msgs->flags & I2C_M_RECV_LEN; 1303 + 1304 + if (atomic) 1305 + result = i2c_imx_atomic_read(i2c_imx, &msgs[i], is_lastmsg); 1306 + else if (use_dma && !block_data) 1307 + result = i2c_imx_dma_read(i2c_imx, &msgs[i], is_lastmsg); 1308 + else 1309 + result = i2c_imx_read(i2c_imx, &msgs[i], is_lastmsg); 1589 1310 } else { 1590 - if (!atomic && 1591 - i2c_imx->dma && msgs[i].len >= DMA_THRESHOLD && 1592 - msgs[i].flags & I2C_M_DMA_SAFE) 1311 + if (atomic) 1312 + result = i2c_imx_atomic_write(i2c_imx, &msgs[i]); 1313 + else if (use_dma) 1593 1314 result = i2c_imx_dma_write(i2c_imx, &msgs[i]); 1594 1315 else 1595 - result = i2c_imx_write(i2c_imx, &msgs[i], atomic); 1316 + result = i2c_imx_write(i2c_imx, &msgs[i]); 1596 1317 } 1597 1318 if (result) 1598 1319 goto fail0; ··· 1767 1468 goto rpm_disable; 1768 1469 } 1769 1470 1471 + /* 1472 + * We use the single-master property for backward compatibility. 1473 + * By default multi master mode is enabled. 1474 + */ 1475 + i2c_imx->multi_master = !of_property_read_bool(pdev->dev.of_node, "single-master"); 1476 + 1770 1477 /* Set up clock divider */ 1771 1478 i2c_imx->bitrate = I2C_MAX_STANDARD_MODE_FREQ; 1772 1479 ret = of_property_read_u32(pdev->dev.of_node, ··· 1881 1576 1882 1577 static struct platform_driver i2c_imx_driver = { 1883 1578 .probe = i2c_imx_probe, 1884 - .remove_new = i2c_imx_remove, 1579 + .remove = i2c_imx_remove, 1885 1580 .driver = { 1886 1581 .name = DRIVER_NAME, 1887 1582 .pm = pm_ptr(&i2c_imx_pm_ops),
+1 -1
drivers/i2c/busses/i2c-iop3xx.c
··· 524 524 525 525 static struct platform_driver iop3xx_i2c_driver = { 526 526 .probe = iop3xx_i2c_probe, 527 - .remove_new = iop3xx_i2c_remove, 527 + .remove = iop3xx_i2c_remove, 528 528 .driver = { 529 529 .name = "IOP3xx-I2C", 530 530 .of_match_table = i2c_iop3xx_match,
+164 -157
drivers/i2c/busses/i2c-isch.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0-only 2 2 /* 3 - i2c-isch.c - Linux kernel driver for Intel SCH chipset SMBus 4 - - Based on i2c-piix4.c 5 - Copyright (c) 1998 - 2002 Frodo Looijaard <frodol@dds.nl> and 6 - Philip Edelbrock <phil@netroedge.com> 7 - - Intel SCH support 8 - Copyright (c) 2007 - 2008 Jacob Jun Pan <jacob.jun.pan@intel.com> 3 + * Linux kernel driver for Intel SCH chipset SMBus 4 + * - Based on i2c-piix4.c 5 + * Copyright (c) 1998 - 2002 Frodo Looijaard <frodol@dds.nl> and 6 + * Philip Edelbrock <phil@netroedge.com> 7 + * - Intel SCH support 8 + * Copyright (c) 2007 - 2008 Jacob Jun Pan <jacob.jun.pan@intel.com> 9 + */ 9 10 10 - */ 11 + /* Supports: Intel SCH chipsets (AF82US15W, AF82US15L, AF82UL11L) */ 11 12 12 - /* 13 - Supports: 14 - Intel SCH chipsets (AF82US15W, AF82US15L, AF82UL11L) 15 - Note: we assume there can only be one device, with one SMBus interface. 16 - */ 17 - 13 + #include <linux/container_of.h> 14 + #include <linux/delay.h> 15 + #include <linux/device.h> 16 + #include <linux/errno.h> 17 + #include <linux/gfp_types.h> 18 + #include <linux/i2c.h> 19 + #include <linux/iopoll.h> 20 + #include <linux/ioport.h> 18 21 #include <linux/module.h> 19 22 #include <linux/platform_device.h> 20 - #include <linux/kernel.h> 21 - #include <linux/delay.h> 23 + #include <linux/sprintf.h> 22 24 #include <linux/stddef.h> 23 - #include <linux/ioport.h> 24 - #include <linux/i2c.h> 25 - #include <linux/io.h> 25 + #include <linux/string_choices.h> 26 + #include <linux/types.h> 26 27 27 28 /* SCH SMBus address offsets */ 28 - #define SMBHSTCNT (0 + sch_smba) 29 - #define SMBHSTSTS (1 + sch_smba) 30 - #define SMBHSTCLK (2 + sch_smba) 31 - #define SMBHSTADD (4 + sch_smba) /* TSA */ 32 - #define SMBHSTCMD (5 + sch_smba) 33 - #define SMBHSTDAT0 (6 + sch_smba) 34 - #define SMBHSTDAT1 (7 + sch_smba) 35 - #define SMBBLKDAT (0x20 + sch_smba) 36 - 37 - /* Other settings */ 38 - #define MAX_RETRIES 5000 29 + #define SMBHSTCNT 0x00 30 + #define SMBHSTSTS 0x01 31 + #define SMBHSTCLK 0x02 32 + #define SMBHSTADD 0x04 /* TSA */ 33 + #define SMBHSTCMD 0x05 34 + #define SMBHSTDAT0 0x06 35 + #define SMBHSTDAT1 0x07 36 + #define SMBBLKDAT 0x20 39 37 40 38 /* I2C constants */ 41 39 #define SCH_QUICK 0x00 ··· 42 44 #define SCH_WORD_DATA 0x03 43 45 #define SCH_BLOCK_DATA 0x05 44 46 45 - static unsigned short sch_smba; 46 - static struct i2c_adapter sch_adapter; 47 + struct sch_i2c { 48 + struct i2c_adapter adapter; 49 + void __iomem *smba; 50 + }; 51 + 47 52 static int backbone_speed = 33000; /* backbone speed in kHz */ 48 - module_param(backbone_speed, int, S_IRUSR | S_IWUSR); 53 + module_param(backbone_speed, int, 0600); 49 54 MODULE_PARM_DESC(backbone_speed, "Backbone speed in kHz, (default = 33000)"); 50 55 51 - /* 52 - * Start the i2c transaction -- the i2c_access will prepare the transaction 53 - * and this function will execute it. 54 - * return 0 for success and others for failure. 55 - */ 56 - static int sch_transaction(void) 56 + static inline u8 sch_io_rd8(struct sch_i2c *priv, unsigned int offset) 57 57 { 58 - int temp; 59 - int result = 0; 60 - int retries = 0; 58 + return ioread8(priv->smba + offset); 59 + } 61 60 62 - dev_dbg(&sch_adapter.dev, "Transaction (pre): CNT=%02x, CMD=%02x, " 63 - "ADD=%02x, DAT0=%02x, DAT1=%02x\n", inb(SMBHSTCNT), 64 - inb(SMBHSTCMD), inb(SMBHSTADD), inb(SMBHSTDAT0), 65 - inb(SMBHSTDAT1)); 61 + static inline void sch_io_wr8(struct sch_i2c *priv, unsigned int offset, u8 value) 62 + { 63 + iowrite8(value, priv->smba + offset); 64 + } 65 + 66 + static inline u16 sch_io_rd16(struct sch_i2c *priv, unsigned int offset) 67 + { 68 + return ioread16(priv->smba + offset); 69 + } 70 + 71 + static inline void sch_io_wr16(struct sch_i2c *priv, unsigned int offset, u16 value) 72 + { 73 + iowrite16(value, priv->smba + offset); 74 + } 75 + 76 + /** 77 + * sch_transaction - Start the i2c transaction 78 + * @adap: the i2c adapter pointer 79 + * 80 + * The sch_access() will prepare the transaction and 81 + * this function will execute it. 82 + * 83 + * Return: 0 for success and others for failure. 84 + */ 85 + static int sch_transaction(struct i2c_adapter *adap) 86 + { 87 + struct sch_i2c *priv = container_of(adap, struct sch_i2c, adapter); 88 + int temp; 89 + int rc; 90 + 91 + dev_dbg(&adap->dev, 92 + "Transaction (pre): CNT=%02x, CMD=%02x, ADD=%02x, DAT0=%02x, DAT1=%02x\n", 93 + sch_io_rd8(priv, SMBHSTCNT), sch_io_rd8(priv, SMBHSTCMD), 94 + sch_io_rd8(priv, SMBHSTADD), 95 + sch_io_rd8(priv, SMBHSTDAT0), sch_io_rd8(priv, SMBHSTDAT1)); 66 96 67 97 /* Make sure the SMBus host is ready to start transmitting */ 68 - temp = inb(SMBHSTSTS) & 0x0f; 98 + temp = sch_io_rd8(priv, SMBHSTSTS) & 0x0f; 69 99 if (temp) { 70 100 /* Can not be busy since we checked it in sch_access */ 71 - if (temp & 0x01) { 72 - dev_dbg(&sch_adapter.dev, "Completion (%02x). " 73 - "Clear...\n", temp); 74 - } 75 - if (temp & 0x06) { 76 - dev_dbg(&sch_adapter.dev, "SMBus error (%02x). " 77 - "Resetting...\n", temp); 78 - } 79 - outb(temp, SMBHSTSTS); 80 - temp = inb(SMBHSTSTS) & 0x0f; 101 + if (temp & 0x01) 102 + dev_dbg(&adap->dev, "Completion (%02x). Clear...\n", temp); 103 + if (temp & 0x06) 104 + dev_dbg(&adap->dev, "SMBus error (%02x). Resetting...\n", temp); 105 + sch_io_wr8(priv, SMBHSTSTS, temp); 106 + temp = sch_io_rd8(priv, SMBHSTSTS) & 0x0f; 81 107 if (temp) { 82 - dev_err(&sch_adapter.dev, 83 - "SMBus is not ready: (%02x)\n", temp); 108 + dev_err(&adap->dev, "SMBus is not ready: (%02x)\n", temp); 84 109 return -EAGAIN; 85 110 } 86 111 } 87 112 88 - /* start the transaction by setting bit 4 */ 89 - outb(inb(SMBHSTCNT) | 0x10, SMBHSTCNT); 113 + /* Start the transaction by setting bit 4 */ 114 + temp = sch_io_rd8(priv, SMBHSTCNT); 115 + temp |= 0x10; 116 + sch_io_wr8(priv, SMBHSTCNT, temp); 90 117 91 - do { 92 - usleep_range(100, 200); 93 - temp = inb(SMBHSTSTS) & 0x0f; 94 - } while ((temp & 0x08) && (retries++ < MAX_RETRIES)); 95 - 118 + rc = read_poll_timeout(sch_io_rd8, temp, !(temp & 0x08), 200, 500000, true, priv, SMBHSTSTS); 96 119 /* If the SMBus is still busy, we give up */ 97 - if (retries > MAX_RETRIES) { 98 - dev_err(&sch_adapter.dev, "SMBus Timeout!\n"); 99 - result = -ETIMEDOUT; 120 + if (rc) { 121 + dev_err(&adap->dev, "SMBus Timeout!\n"); 100 122 } else if (temp & 0x04) { 101 - result = -EIO; 102 - dev_dbg(&sch_adapter.dev, "Bus collision! SMBus may be " 103 - "locked until next hard reset. (sorry!)\n"); 123 + rc = -EIO; 124 + dev_dbg(&adap->dev, "Bus collision! SMBus may be locked until next hard reset. (sorry!)\n"); 104 125 /* Clock stops and target is stuck in mid-transmission */ 105 126 } else if (temp & 0x02) { 106 - result = -EIO; 107 - dev_err(&sch_adapter.dev, "Error: no response!\n"); 127 + rc = -EIO; 128 + dev_err(&adap->dev, "Error: no response!\n"); 108 129 } else if (temp & 0x01) { 109 - dev_dbg(&sch_adapter.dev, "Post complete!\n"); 110 - outb(temp, SMBHSTSTS); 111 - temp = inb(SMBHSTSTS) & 0x07; 130 + dev_dbg(&adap->dev, "Post complete!\n"); 131 + sch_io_wr8(priv, SMBHSTSTS, temp & 0x0f); 132 + temp = sch_io_rd8(priv, SMBHSTSTS) & 0x07; 112 133 if (temp & 0x06) { 113 134 /* Completion clear failed */ 114 - dev_dbg(&sch_adapter.dev, "Failed reset at end of " 115 - "transaction (%02x), Bus error!\n", temp); 135 + dev_dbg(&adap->dev, 136 + "Failed reset at end of transaction (%02x), Bus error!\n", temp); 116 137 } 117 138 } else { 118 - result = -ENXIO; 119 - dev_dbg(&sch_adapter.dev, "No such address.\n"); 139 + rc = -ENXIO; 140 + dev_dbg(&adap->dev, "No such address.\n"); 120 141 } 121 - dev_dbg(&sch_adapter.dev, "Transaction (post): CNT=%02x, CMD=%02x, " 122 - "ADD=%02x, DAT0=%02x, DAT1=%02x\n", inb(SMBHSTCNT), 123 - inb(SMBHSTCMD), inb(SMBHSTADD), inb(SMBHSTDAT0), 124 - inb(SMBHSTDAT1)); 125 - return result; 142 + dev_dbg(&adap->dev, "Transaction (post): CNT=%02x, CMD=%02x, ADD=%02x, DAT0=%02x, DAT1=%02x\n", 143 + sch_io_rd8(priv, SMBHSTCNT), sch_io_rd8(priv, SMBHSTCMD), 144 + sch_io_rd8(priv, SMBHSTADD), 145 + sch_io_rd8(priv, SMBHSTDAT0), sch_io_rd8(priv, SMBHSTDAT1)); 146 + return rc; 126 147 } 127 148 128 - /* 129 - * This is the main access entry for i2c-sch access 130 - * adap is i2c_adapter pointer, addr is the i2c device bus address, read_write 131 - * (0 for read and 1 for write), size is i2c transaction type and data is the 132 - * union of transaction for data to be transferred or data read from bus. 133 - * return 0 for success and others for failure. 149 + /** 150 + * sch_access - the main access entry for i2c-sch access 151 + * @adap: the i2c adapter pointer 152 + * @addr: the i2c device bus address 153 + * @flags: I2C_CLIENT_* flags (usually zero or I2C_CLIENT_PEC) 154 + * @read_write: 0 for read and 1 for write 155 + * @command: Byte interpreted by slave, for protocols which use such bytes 156 + * @size: the i2c transaction type 157 + * @data: the union of transaction for data to be transferred or data read from bus 158 + * 159 + * Return: 0 for success and others for failure. 134 160 */ 135 161 static s32 sch_access(struct i2c_adapter *adap, u16 addr, 136 162 unsigned short flags, char read_write, 137 163 u8 command, int size, union i2c_smbus_data *data) 138 164 { 165 + struct sch_i2c *priv = container_of(adap, struct sch_i2c, adapter); 139 166 int i, len, temp, rc; 140 167 141 168 /* Make sure the SMBus host is not busy */ 142 - temp = inb(SMBHSTSTS) & 0x0f; 169 + temp = sch_io_rd8(priv, SMBHSTSTS) & 0x0f; 143 170 if (temp & 0x08) { 144 - dev_dbg(&sch_adapter.dev, "SMBus busy (%02x)\n", temp); 171 + dev_dbg(&adap->dev, "SMBus busy (%02x)\n", temp); 145 172 return -EAGAIN; 146 173 } 147 - temp = inw(SMBHSTCLK); 174 + temp = sch_io_rd16(priv, SMBHSTCLK); 148 175 if (!temp) { 149 176 /* 150 177 * We can't determine if we have 33 or 25 MHz clock for ··· 177 154 * 100 kHz. If we actually run at 25 MHz the bus will be 178 155 * run ~75 kHz instead which should do no harm. 179 156 */ 180 - dev_notice(&sch_adapter.dev, 181 - "Clock divider uninitialized. Setting defaults\n"); 182 - outw(backbone_speed / (4 * 100), SMBHSTCLK); 157 + dev_notice(&adap->dev, "Clock divider uninitialized. Setting defaults\n"); 158 + sch_io_wr16(priv, SMBHSTCLK, backbone_speed / (4 * 100)); 183 159 } 184 160 185 - dev_dbg(&sch_adapter.dev, "access size: %d %s\n", size, 186 - (read_write)?"READ":"WRITE"); 161 + dev_dbg(&adap->dev, "access size: %d %s\n", size, str_read_write(read_write)); 187 162 switch (size) { 188 163 case I2C_SMBUS_QUICK: 189 - outb((addr << 1) | read_write, SMBHSTADD); 164 + sch_io_wr8(priv, SMBHSTADD, (addr << 1) | read_write); 190 165 size = SCH_QUICK; 191 166 break; 192 167 case I2C_SMBUS_BYTE: 193 - outb((addr << 1) | read_write, SMBHSTADD); 168 + sch_io_wr8(priv, SMBHSTADD, (addr << 1) | read_write); 194 169 if (read_write == I2C_SMBUS_WRITE) 195 - outb(command, SMBHSTCMD); 170 + sch_io_wr8(priv, SMBHSTCMD, command); 196 171 size = SCH_BYTE; 197 172 break; 198 173 case I2C_SMBUS_BYTE_DATA: 199 - outb((addr << 1) | read_write, SMBHSTADD); 200 - outb(command, SMBHSTCMD); 174 + sch_io_wr8(priv, SMBHSTADD, (addr << 1) | read_write); 175 + sch_io_wr8(priv, SMBHSTCMD, command); 201 176 if (read_write == I2C_SMBUS_WRITE) 202 - outb(data->byte, SMBHSTDAT0); 177 + sch_io_wr8(priv, SMBHSTDAT0, data->byte); 203 178 size = SCH_BYTE_DATA; 204 179 break; 205 180 case I2C_SMBUS_WORD_DATA: 206 - outb((addr << 1) | read_write, SMBHSTADD); 207 - outb(command, SMBHSTCMD); 181 + sch_io_wr8(priv, SMBHSTADD, (addr << 1) | read_write); 182 + sch_io_wr8(priv, SMBHSTCMD, command); 208 183 if (read_write == I2C_SMBUS_WRITE) { 209 - outb(data->word & 0xff, SMBHSTDAT0); 210 - outb((data->word & 0xff00) >> 8, SMBHSTDAT1); 184 + sch_io_wr8(priv, SMBHSTDAT0, data->word >> 0); 185 + sch_io_wr8(priv, SMBHSTDAT1, data->word >> 8); 211 186 } 212 187 size = SCH_WORD_DATA; 213 188 break; 214 189 case I2C_SMBUS_BLOCK_DATA: 215 - outb((addr << 1) | read_write, SMBHSTADD); 216 - outb(command, SMBHSTCMD); 190 + sch_io_wr8(priv, SMBHSTADD, (addr << 1) | read_write); 191 + sch_io_wr8(priv, SMBHSTCMD, command); 217 192 if (read_write == I2C_SMBUS_WRITE) { 218 193 len = data->block[0]; 219 194 if (len == 0 || len > I2C_SMBUS_BLOCK_MAX) 220 195 return -EINVAL; 221 - outb(len, SMBHSTDAT0); 196 + sch_io_wr8(priv, SMBHSTDAT0, len); 222 197 for (i = 1; i <= len; i++) 223 - outb(data->block[i], SMBBLKDAT+i-1); 198 + sch_io_wr8(priv, SMBBLKDAT + i - 1, data->block[i]); 224 199 } 225 200 size = SCH_BLOCK_DATA; 226 201 break; ··· 226 205 dev_warn(&adap->dev, "Unsupported transaction %d\n", size); 227 206 return -EOPNOTSUPP; 228 207 } 229 - dev_dbg(&sch_adapter.dev, "write size %d to 0x%04x\n", size, SMBHSTCNT); 230 - outb((inb(SMBHSTCNT) & 0xb0) | (size & 0x7), SMBHSTCNT); 208 + dev_dbg(&adap->dev, "write size %d to 0x%04x\n", size, SMBHSTCNT); 231 209 232 - rc = sch_transaction(); 210 + temp = sch_io_rd8(priv, SMBHSTCNT); 211 + temp = (temp & 0xb0) | (size & 0x7); 212 + sch_io_wr8(priv, SMBHSTCNT, temp); 213 + 214 + rc = sch_transaction(adap); 233 215 if (rc) /* Error in transaction */ 234 216 return rc; 235 217 ··· 242 218 switch (size) { 243 219 case SCH_BYTE: 244 220 case SCH_BYTE_DATA: 245 - data->byte = inb(SMBHSTDAT0); 221 + data->byte = sch_io_rd8(priv, SMBHSTDAT0); 246 222 break; 247 223 case SCH_WORD_DATA: 248 - data->word = inb(SMBHSTDAT0) + (inb(SMBHSTDAT1) << 8); 224 + data->word = (sch_io_rd8(priv, SMBHSTDAT0) << 0) + 225 + (sch_io_rd8(priv, SMBHSTDAT1) << 8); 249 226 break; 250 227 case SCH_BLOCK_DATA: 251 - data->block[0] = inb(SMBHSTDAT0); 228 + data->block[0] = sch_io_rd8(priv, SMBHSTDAT0); 252 229 if (data->block[0] == 0 || data->block[0] > I2C_SMBUS_BLOCK_MAX) 253 230 return -EPROTO; 254 231 for (i = 1; i <= data->block[0]; i++) 255 - data->block[i] = inb(SMBBLKDAT+i-1); 232 + data->block[i] = sch_io_rd8(priv, SMBBLKDAT + i - 1); 256 233 break; 257 234 } 258 235 return 0; ··· 271 246 .functionality = sch_func, 272 247 }; 273 248 274 - static struct i2c_adapter sch_adapter = { 275 - .owner = THIS_MODULE, 276 - .class = I2C_CLASS_HWMON, 277 - .algo = &smbus_algorithm, 278 - }; 279 - 280 - static int smbus_sch_probe(struct platform_device *dev) 249 + static int smbus_sch_probe(struct platform_device *pdev) 281 250 { 251 + struct device *dev = &pdev->dev; 252 + struct sch_i2c *priv; 282 253 struct resource *res; 283 - int retval; 284 254 285 - res = platform_get_resource(dev, IORESOURCE_IO, 0); 255 + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 256 + if (!priv) 257 + return -ENOMEM; 258 + 259 + res = platform_get_resource(pdev, IORESOURCE_IO, 0); 286 260 if (!res) 287 261 return -EBUSY; 288 262 289 - if (!devm_request_region(&dev->dev, res->start, resource_size(res), 290 - dev->name)) { 291 - dev_err(&dev->dev, "SMBus region 0x%x already in use!\n", 292 - sch_smba); 293 - return -EBUSY; 294 - } 263 + priv->smba = devm_ioport_map(dev, res->start, resource_size(res)); 264 + if (!priv->smba) 265 + return dev_err_probe(dev, -EBUSY, "SMBus region %pR already in use!\n", res); 295 266 296 - sch_smba = res->start; 267 + /* Set up the sysfs linkage to our parent device */ 268 + priv->adapter.dev.parent = dev; 269 + priv->adapter.owner = THIS_MODULE, 270 + priv->adapter.class = I2C_CLASS_HWMON, 271 + priv->adapter.algo = &smbus_algorithm, 297 272 298 - dev_dbg(&dev->dev, "SMBA = 0x%X\n", sch_smba); 273 + snprintf(priv->adapter.name, sizeof(priv->adapter.name), 274 + "SMBus SCH adapter at %04x", (unsigned short)res->start); 299 275 300 - /* set up the sysfs linkage to our parent device */ 301 - sch_adapter.dev.parent = &dev->dev; 302 - 303 - snprintf(sch_adapter.name, sizeof(sch_adapter.name), 304 - "SMBus SCH adapter at %04x", sch_smba); 305 - 306 - retval = i2c_add_adapter(&sch_adapter); 307 - if (retval) 308 - sch_smba = 0; 309 - 310 - return retval; 311 - } 312 - 313 - static void smbus_sch_remove(struct platform_device *pdev) 314 - { 315 - if (sch_smba) { 316 - i2c_del_adapter(&sch_adapter); 317 - sch_smba = 0; 318 - } 276 + return devm_i2c_add_adapter(dev, &priv->adapter); 319 277 } 320 278 321 279 static struct platform_driver smbus_sch_driver = { ··· 306 298 .name = "isch_smbus", 307 299 }, 308 300 .probe = smbus_sch_probe, 309 - .remove_new = smbus_sch_remove, 310 301 }; 311 302 312 303 module_platform_driver(smbus_sch_driver);
+1 -1
drivers/i2c/busses/i2c-jz4780.c
··· 847 847 848 848 static struct platform_driver jz4780_i2c_driver = { 849 849 .probe = jz4780_i2c_probe, 850 - .remove_new = jz4780_i2c_remove, 850 + .remove = jz4780_i2c_remove, 851 851 .driver = { 852 852 .name = "jz4780-i2c", 853 853 .of_match_table = jz4780_i2c_of_matches,
+1 -1
drivers/i2c/busses/i2c-kempld.c
··· 385 385 .pm = pm_sleep_ptr(&kempld_i2c_pm_ops), 386 386 }, 387 387 .probe = kempld_i2c_probe, 388 - .remove_new = kempld_i2c_remove, 388 + .remove = kempld_i2c_remove, 389 389 }; 390 390 391 391 module_platform_driver(kempld_i2c_driver);
+1 -1
drivers/i2c/busses/i2c-lpc2k.c
··· 462 462 463 463 static struct platform_driver i2c_lpc2k_driver = { 464 464 .probe = i2c_lpc2k_probe, 465 - .remove_new = i2c_lpc2k_remove, 465 + .remove = i2c_lpc2k_remove, 466 466 .driver = { 467 467 .name = "lpc2k-i2c", 468 468 .pm = pm_sleep_ptr(&i2c_lpc2k_dev_pm_ops),
+1 -1
drivers/i2c/busses/i2c-meson.c
··· 565 565 566 566 static struct platform_driver meson_i2c_driver = { 567 567 .probe = meson_i2c_probe, 568 - .remove_new = meson_i2c_remove, 568 + .remove = meson_i2c_remove, 569 569 .driver = { 570 570 .name = "meson-i2c", 571 571 .of_match_table = meson_i2c_match,
+1 -1
drivers/i2c/busses/i2c-microchip-corei2c.c
··· 462 462 463 463 static struct platform_driver mchp_corei2c_driver = { 464 464 .probe = mchp_corei2c_probe, 465 - .remove_new = mchp_corei2c_remove, 465 + .remove = mchp_corei2c_remove, 466 466 .driver = { 467 467 .name = "microchip-corei2c", 468 468 .of_match_table = mchp_corei2c_of_match,
+1 -1
drivers/i2c/busses/i2c-mlxbf.c
··· 2456 2456 2457 2457 static struct platform_driver mlxbf_i2c_driver = { 2458 2458 .probe = mlxbf_i2c_probe, 2459 - .remove_new = mlxbf_i2c_remove, 2459 + .remove = mlxbf_i2c_remove, 2460 2460 .driver = { 2461 2461 .name = "i2c-mlxbf", 2462 2462 .acpi_match_table = ACPI_PTR(mlxbf_i2c_acpi_ids),
+1 -1
drivers/i2c/busses/i2c-mlxcpld.c
··· 591 591 592 592 static struct platform_driver mlxcpld_i2c_driver = { 593 593 .probe = mlxcpld_i2c_probe, 594 - .remove_new = mlxcpld_i2c_remove, 594 + .remove = mlxcpld_i2c_remove, 595 595 .driver = { 596 596 .name = MLXCPLD_I2C_DEVICE_NAME, 597 597 },
+1 -1
drivers/i2c/busses/i2c-mpc.c
··· 938 938 /* Structure for a device driver */ 939 939 static struct platform_driver mpc_i2c_driver = { 940 940 .probe = fsl_i2c_probe, 941 - .remove_new = fsl_i2c_remove, 941 + .remove = fsl_i2c_remove, 942 942 .driver = { 943 943 .name = "mpc-i2c", 944 944 .of_match_table = mpc_i2c_of_match,
+1 -1
drivers/i2c/busses/i2c-mt65xx.c
··· 1550 1550 1551 1551 static struct platform_driver mtk_i2c_driver = { 1552 1552 .probe = mtk_i2c_probe, 1553 - .remove_new = mtk_i2c_remove, 1553 + .remove = mtk_i2c_remove, 1554 1554 .driver = { 1555 1555 .name = I2C_DRV_NAME, 1556 1556 .pm = pm_sleep_ptr(&mtk_i2c_pm),
+1 -1
drivers/i2c/busses/i2c-mt7621.c
··· 331 331 332 332 static struct platform_driver mtk_i2c_driver = { 333 333 .probe = mtk_i2c_probe, 334 - .remove_new = mtk_i2c_remove, 334 + .remove = mtk_i2c_remove, 335 335 .driver = { 336 336 .name = "i2c-mt7621", 337 337 .of_match_table = i2c_mtk_dt_ids,
+1 -1
drivers/i2c/busses/i2c-mv64xxx.c
··· 1104 1104 1105 1105 static struct platform_driver mv64xxx_i2c_driver = { 1106 1106 .probe = mv64xxx_i2c_probe, 1107 - .remove_new = mv64xxx_i2c_remove, 1107 + .remove = mv64xxx_i2c_remove, 1108 1108 .driver = { 1109 1109 .name = MV64XXX_I2C_CTLR_NAME, 1110 1110 .pm = &mv64xxx_i2c_pm_ops,
+1 -1
drivers/i2c/busses/i2c-mxs.c
··· 881 881 .of_match_table = mxs_i2c_dt_ids, 882 882 }, 883 883 .probe = mxs_i2c_probe, 884 - .remove_new = mxs_i2c_remove, 884 + .remove = mxs_i2c_remove, 885 885 }; 886 886 887 887 static int __init mxs_i2c_init(void)
-240
drivers/i2c/busses/i2c-nforce2-s4985.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-or-later 2 - /* 3 - * i2c-nforce2-s4985.c - i2c-nforce2 extras for the Tyan S4985 motherboard 4 - * 5 - * Copyright (C) 2008 Jean Delvare <jdelvare@suse.de> 6 - */ 7 - 8 - /* 9 - * We select the channels by sending commands to the Philips 10 - * PCA9556 chip at I2C address 0x18. The main adapter is used for 11 - * the non-multiplexed part of the bus, and 4 virtual adapters 12 - * are defined for the multiplexed addresses: 0x50-0x53 (memory 13 - * module EEPROM) located on channels 1-4. We define one virtual 14 - * adapter per CPU, which corresponds to one multiplexed channel: 15 - * CPU0: virtual adapter 1, channel 1 16 - * CPU1: virtual adapter 2, channel 2 17 - * CPU2: virtual adapter 3, channel 3 18 - * CPU3: virtual adapter 4, channel 4 19 - */ 20 - 21 - #include <linux/module.h> 22 - #include <linux/kernel.h> 23 - #include <linux/slab.h> 24 - #include <linux/init.h> 25 - #include <linux/i2c.h> 26 - #include <linux/mutex.h> 27 - 28 - extern struct i2c_adapter *nforce2_smbus; 29 - 30 - static struct i2c_adapter *s4985_adapter; 31 - static struct i2c_algorithm *s4985_algo; 32 - 33 - /* Wrapper access functions for multiplexed SMBus */ 34 - static DEFINE_MUTEX(nforce2_lock); 35 - 36 - static s32 nforce2_access_virt0(struct i2c_adapter *adap, u16 addr, 37 - unsigned short flags, char read_write, 38 - u8 command, int size, 39 - union i2c_smbus_data *data) 40 - { 41 - int error; 42 - 43 - /* We exclude the multiplexed addresses */ 44 - if ((addr & 0xfc) == 0x50 || (addr & 0xfc) == 0x30 45 - || addr == 0x18) 46 - return -ENXIO; 47 - 48 - mutex_lock(&nforce2_lock); 49 - error = nforce2_smbus->algo->smbus_xfer(adap, addr, flags, read_write, 50 - command, size, data); 51 - mutex_unlock(&nforce2_lock); 52 - 53 - return error; 54 - } 55 - 56 - /* We remember the last used channels combination so as to only switch 57 - channels when it is really needed. This greatly reduces the SMBus 58 - overhead, but also assumes that nobody will be writing to the PCA9556 59 - in our back. */ 60 - static u8 last_channels; 61 - 62 - static inline s32 nforce2_access_channel(struct i2c_adapter *adap, u16 addr, 63 - unsigned short flags, char read_write, 64 - u8 command, int size, 65 - union i2c_smbus_data *data, 66 - u8 channels) 67 - { 68 - int error; 69 - 70 - /* We exclude the non-multiplexed addresses */ 71 - if ((addr & 0xfc) != 0x50 && (addr & 0xfc) != 0x30) 72 - return -ENXIO; 73 - 74 - mutex_lock(&nforce2_lock); 75 - if (last_channels != channels) { 76 - union i2c_smbus_data mplxdata; 77 - mplxdata.byte = channels; 78 - 79 - error = nforce2_smbus->algo->smbus_xfer(adap, 0x18, 0, 80 - I2C_SMBUS_WRITE, 0x01, 81 - I2C_SMBUS_BYTE_DATA, 82 - &mplxdata); 83 - if (error) 84 - goto UNLOCK; 85 - last_channels = channels; 86 - } 87 - error = nforce2_smbus->algo->smbus_xfer(adap, addr, flags, read_write, 88 - command, size, data); 89 - 90 - UNLOCK: 91 - mutex_unlock(&nforce2_lock); 92 - return error; 93 - } 94 - 95 - static s32 nforce2_access_virt1(struct i2c_adapter *adap, u16 addr, 96 - unsigned short flags, char read_write, 97 - u8 command, int size, 98 - union i2c_smbus_data *data) 99 - { 100 - /* CPU0: channel 1 enabled */ 101 - return nforce2_access_channel(adap, addr, flags, read_write, command, 102 - size, data, 0x02); 103 - } 104 - 105 - static s32 nforce2_access_virt2(struct i2c_adapter *adap, u16 addr, 106 - unsigned short flags, char read_write, 107 - u8 command, int size, 108 - union i2c_smbus_data *data) 109 - { 110 - /* CPU1: channel 2 enabled */ 111 - return nforce2_access_channel(adap, addr, flags, read_write, command, 112 - size, data, 0x04); 113 - } 114 - 115 - static s32 nforce2_access_virt3(struct i2c_adapter *adap, u16 addr, 116 - unsigned short flags, char read_write, 117 - u8 command, int size, 118 - union i2c_smbus_data *data) 119 - { 120 - /* CPU2: channel 3 enabled */ 121 - return nforce2_access_channel(adap, addr, flags, read_write, command, 122 - size, data, 0x08); 123 - } 124 - 125 - static s32 nforce2_access_virt4(struct i2c_adapter *adap, u16 addr, 126 - unsigned short flags, char read_write, 127 - u8 command, int size, 128 - union i2c_smbus_data *data) 129 - { 130 - /* CPU3: channel 4 enabled */ 131 - return nforce2_access_channel(adap, addr, flags, read_write, command, 132 - size, data, 0x10); 133 - } 134 - 135 - static int __init nforce2_s4985_init(void) 136 - { 137 - int i, error; 138 - union i2c_smbus_data ioconfig; 139 - 140 - if (!nforce2_smbus) 141 - return -ENODEV; 142 - 143 - /* Configure the PCA9556 multiplexer */ 144 - ioconfig.byte = 0x00; /* All I/O to output mode */ 145 - error = i2c_smbus_xfer(nforce2_smbus, 0x18, 0, I2C_SMBUS_WRITE, 0x03, 146 - I2C_SMBUS_BYTE_DATA, &ioconfig); 147 - if (error) { 148 - dev_err(&nforce2_smbus->dev, "PCA9556 configuration failed\n"); 149 - error = -EIO; 150 - goto ERROR0; 151 - } 152 - 153 - /* Unregister physical bus */ 154 - i2c_del_adapter(nforce2_smbus); 155 - 156 - printk(KERN_INFO "Enabling SMBus multiplexing for Tyan S4985\n"); 157 - /* Define the 5 virtual adapters and algorithms structures */ 158 - s4985_adapter = kcalloc(5, sizeof(struct i2c_adapter), GFP_KERNEL); 159 - if (!s4985_adapter) { 160 - error = -ENOMEM; 161 - goto ERROR1; 162 - } 163 - s4985_algo = kcalloc(5, sizeof(struct i2c_algorithm), GFP_KERNEL); 164 - if (!s4985_algo) { 165 - error = -ENOMEM; 166 - goto ERROR2; 167 - } 168 - 169 - /* Fill in the new structures */ 170 - s4985_algo[0] = *(nforce2_smbus->algo); 171 - s4985_algo[0].smbus_xfer = nforce2_access_virt0; 172 - s4985_adapter[0] = *nforce2_smbus; 173 - s4985_adapter[0].algo = s4985_algo; 174 - s4985_adapter[0].dev.parent = nforce2_smbus->dev.parent; 175 - for (i = 1; i < 5; i++) { 176 - s4985_algo[i] = *(nforce2_smbus->algo); 177 - s4985_adapter[i] = *nforce2_smbus; 178 - snprintf(s4985_adapter[i].name, sizeof(s4985_adapter[i].name), 179 - "SMBus nForce2 adapter (CPU%d)", i - 1); 180 - s4985_adapter[i].algo = s4985_algo + i; 181 - s4985_adapter[i].dev.parent = nforce2_smbus->dev.parent; 182 - } 183 - s4985_algo[1].smbus_xfer = nforce2_access_virt1; 184 - s4985_algo[2].smbus_xfer = nforce2_access_virt2; 185 - s4985_algo[3].smbus_xfer = nforce2_access_virt3; 186 - s4985_algo[4].smbus_xfer = nforce2_access_virt4; 187 - 188 - /* Register virtual adapters */ 189 - for (i = 0; i < 5; i++) { 190 - error = i2c_add_adapter(s4985_adapter + i); 191 - if (error) { 192 - printk(KERN_ERR "i2c-nforce2-s4985: " 193 - "Virtual adapter %d registration " 194 - "failed, module not inserted\n", i); 195 - for (i--; i >= 0; i--) 196 - i2c_del_adapter(s4985_adapter + i); 197 - goto ERROR3; 198 - } 199 - } 200 - 201 - return 0; 202 - 203 - ERROR3: 204 - kfree(s4985_algo); 205 - s4985_algo = NULL; 206 - ERROR2: 207 - kfree(s4985_adapter); 208 - s4985_adapter = NULL; 209 - ERROR1: 210 - /* Restore physical bus */ 211 - i2c_add_adapter(nforce2_smbus); 212 - ERROR0: 213 - return error; 214 - } 215 - 216 - static void __exit nforce2_s4985_exit(void) 217 - { 218 - if (s4985_adapter) { 219 - int i; 220 - 221 - for (i = 0; i < 5; i++) 222 - i2c_del_adapter(s4985_adapter+i); 223 - kfree(s4985_adapter); 224 - s4985_adapter = NULL; 225 - } 226 - kfree(s4985_algo); 227 - s4985_algo = NULL; 228 - 229 - /* Restore physical bus */ 230 - if (i2c_add_adapter(nforce2_smbus)) 231 - printk(KERN_ERR "i2c-nforce2-s4985: " 232 - "Physical bus restoration failed\n"); 233 - } 234 - 235 - MODULE_AUTHOR("Jean Delvare <jdelvare@suse.de>"); 236 - MODULE_DESCRIPTION("S4985 SMBus multiplexing"); 237 - MODULE_LICENSE("GPL"); 238 - 239 - module_init(nforce2_s4985_init); 240 - module_exit(nforce2_s4985_exit);
-16
drivers/i2c/busses/i2c-nforce2.c
··· 117 117 118 118 static struct pci_driver nforce2_driver; 119 119 120 - /* For multiplexing support, we need a global reference to the 1st 121 - SMBus channel */ 122 - #if IS_ENABLED(CONFIG_I2C_NFORCE2_S4985) 123 - struct i2c_adapter *nforce2_smbus; 124 - EXPORT_SYMBOL_GPL(nforce2_smbus); 125 - 126 - static void nforce2_set_reference(struct i2c_adapter *adap) 127 - { 128 - nforce2_smbus = adap; 129 - } 130 - #else 131 - static inline void nforce2_set_reference(struct i2c_adapter *adap) { } 132 - #endif 133 - 134 120 static void nforce2_abort(struct i2c_adapter *adap) 135 121 { 136 122 struct nforce2_smbus *smbus = adap->algo_data; ··· 397 411 return -ENODEV; 398 412 } 399 413 400 - nforce2_set_reference(&smbuses[0].adapter); 401 414 return 0; 402 415 } 403 416 ··· 405 420 { 406 421 struct nforce2_smbus *smbuses = pci_get_drvdata(dev); 407 422 408 - nforce2_set_reference(NULL); 409 423 if (smbuses[0].base) { 410 424 i2c_del_adapter(&smbuses[0].adapter); 411 425 release_region(smbuses[0].base, smbuses[0].size);
+17 -7
drivers/i2c/busses/i2c-npcm7xx.c
··· 334 334 u64 nack_cnt; 335 335 u64 timeout_cnt; 336 336 u64 tx_complete_cnt; 337 + bool ber_state; /* Indicate the bus error state */ 337 338 }; 338 339 339 340 static inline void npcm_i2c_select_bank(struct npcm_i2c *bus, ··· 1522 1521 if (npcm_i2c_is_master(bus)) { 1523 1522 npcm_i2c_master_abort(bus); 1524 1523 } else { 1524 + bus->ber_state = true; 1525 1525 npcm_i2c_clear_master_status(bus); 1526 1526 1527 1527 /* Clear BB (BUS BUSY) bit */ ··· 1630 1628 npcm_i2c_wr_byte(bus, bus->dest_addr | BIT(0)); 1631 1629 /* SDA interrupt, after start\restart */ 1632 1630 } else { 1633 - if (NPCM_I2CST_XMIT & i2cst) { 1634 - bus->operation = I2C_WRITE_OPER; 1631 + if (bus->operation == I2C_WRITE_OPER) 1635 1632 npcm_i2c_irq_master_handler_write(bus); 1636 - } else { 1637 - bus->operation = I2C_READ_OPER; 1633 + else if (bus->operation == I2C_READ_OPER) 1638 1634 npcm_i2c_irq_master_handler_read(bus); 1639 - } 1640 1635 } 1641 1636 } 1642 1637 ··· 1701 1702 dev_dbg(bus->dev, "bus%d-0x%x recovery skipped, bus not stuck", 1702 1703 bus->num, bus->dest_addr); 1703 1704 npcm_i2c_reset(bus); 1705 + bus->ber_state = false; 1704 1706 return 0; 1705 1707 } 1706 1708 ··· 1766 1766 if (bus->rec_succ_cnt < ULLONG_MAX) 1767 1767 bus->rec_succ_cnt++; 1768 1768 } 1769 + bus->ber_state = false; 1769 1770 return status; 1770 1771 } 1771 1772 ··· 2162 2161 2163 2162 } while (time_is_after_jiffies(time_left) && bus_busy); 2164 2163 2165 - if (bus_busy) { 2164 + /* 2165 + * Check the BER (bus error) state, when ber_state is true, it means that the module 2166 + * detects the bus error which is caused by some factor like that the electricity 2167 + * noise occurs on the bus. Under this condition, the module is reset and the bus 2168 + * gets recovered. 2169 + * 2170 + * While ber_state is false, the module reset and bus recovery also get done as the 2171 + * bus is busy. 2172 + */ 2173 + if (bus_busy || bus->ber_state) { 2166 2174 iowrite8(NPCM_I2CCST_BB, bus->reg + NPCM_I2CCST); 2167 2175 npcm_i2c_reset(bus); 2168 2176 i2c_recover_bus(adap); ··· 2373 2363 2374 2364 static struct platform_driver npcm_i2c_bus_driver = { 2375 2365 .probe = npcm_i2c_probe_bus, 2376 - .remove_new = npcm_i2c_remove_bus, 2366 + .remove = npcm_i2c_remove_bus, 2377 2367 .driver = { 2378 2368 .name = "nuvoton-i2c", 2379 2369 .of_match_table = npcm_i2c_bus_of_table,
+1 -1
drivers/i2c/busses/i2c-ocores.c
··· 769 769 770 770 static struct platform_driver ocores_i2c_driver = { 771 771 .probe = ocores_i2c_probe, 772 - .remove_new = ocores_i2c_remove, 772 + .remove = ocores_i2c_remove, 773 773 .driver = { 774 774 .name = "ocores-i2c", 775 775 .of_match_table = ocores_i2c_match,
+1 -1
drivers/i2c/busses/i2c-octeon-platdrv.c
··· 269 269 270 270 static struct platform_driver octeon_i2c_driver = { 271 271 .probe = octeon_i2c_probe, 272 - .remove_new = octeon_i2c_remove, 272 + .remove = octeon_i2c_remove, 273 273 .driver = { 274 274 .name = DRV_NAME, 275 275 .of_match_table = octeon_i2c_match,
+1 -1
drivers/i2c/busses/i2c-omap.c
··· 1605 1605 1606 1606 static struct platform_driver omap_i2c_driver = { 1607 1607 .probe = omap_i2c_probe, 1608 - .remove_new = omap_i2c_remove, 1608 + .remove = omap_i2c_remove, 1609 1609 .driver = { 1610 1610 .name = "omap_i2c", 1611 1611 .pm = pm_ptr(&omap_i2c_pm_ops),
+1 -1
drivers/i2c/busses/i2c-opal.c
··· 249 249 250 250 static struct platform_driver i2c_opal_driver = { 251 251 .probe = i2c_opal_probe, 252 - .remove_new = i2c_opal_remove, 252 + .remove = i2c_opal_remove, 253 253 .driver = { 254 254 .name = "i2c-opal", 255 255 .of_match_table = i2c_opal_of_match,
+1 -1
drivers/i2c/busses/i2c-pasemi-platform.c
··· 104 104 .of_match_table = pasemi_platform_i2c_of_match, 105 105 }, 106 106 .probe = pasemi_platform_i2c_probe, 107 - .remove_new = pasemi_platform_i2c_remove, 107 + .remove = pasemi_platform_i2c_remove, 108 108 }; 109 109 module_platform_driver(pasemi_platform_i2c_driver); 110 110
+1 -1
drivers/i2c/busses/i2c-pca-platform.c
··· 238 238 239 239 static struct platform_driver i2c_pca_pf_driver = { 240 240 .probe = i2c_pca_pf_probe, 241 - .remove_new = i2c_pca_pf_remove, 241 + .remove = i2c_pca_pf_remove, 242 242 .driver = { 243 243 .name = "i2c-pca-platform", 244 244 .of_match_table = of_match_ptr(i2c_pca_of_match_table),
+21 -30
drivers/i2c/busses/i2c-piix4.c
··· 35 35 #include <linux/acpi.h> 36 36 #include <linux/io.h> 37 37 38 - 39 - /* PIIX4 SMBus address offsets */ 40 - #define SMBHSTSTS (0 + piix4_smba) 41 - #define SMBHSLVSTS (1 + piix4_smba) 42 - #define SMBHSTCNT (2 + piix4_smba) 43 - #define SMBHSTCMD (3 + piix4_smba) 44 - #define SMBHSTADD (4 + piix4_smba) 45 - #define SMBHSTDAT0 (5 + piix4_smba) 46 - #define SMBHSTDAT1 (6 + piix4_smba) 47 - #define SMBBLKDAT (7 + piix4_smba) 48 - #define SMBSLVCNT (8 + piix4_smba) 49 - #define SMBSHDWCMD (9 + piix4_smba) 50 - #define SMBSLVEVT (0xA + piix4_smba) 51 - #define SMBSLVDAT (0xC + piix4_smba) 38 + #include "i2c-piix4.h" 52 39 53 40 /* count for request_region */ 54 41 #define SMBIOSIZE 9 ··· 57 70 #define PIIX4_BYTE 0x04 58 71 #define PIIX4_BYTE_DATA 0x08 59 72 #define PIIX4_WORD_DATA 0x0C 60 - #define PIIX4_BLOCK_DATA 0x14 61 73 62 74 /* Multi-port constants */ 63 75 #define PIIX4_MAX_ADAPTERS 4 ··· 87 101 88 102 #define SB800_PIIX4_FCH_PM_ADDR 0xFED80300 89 103 #define SB800_PIIX4_FCH_PM_SIZE 8 104 + #define SB800_ASF_ACPI_PATH "\\_SB.ASFC" 90 105 91 106 /* insmod parameters */ 92 107 ··· 147 160 }; 148 161 static const char *piix4_aux_port_name_sb800 = " port 1"; 149 162 150 - struct sb800_mmio_cfg { 151 - void __iomem *addr; 152 - bool use_mmio; 153 - }; 154 - 155 163 struct i2c_piix4_adapdata { 156 164 unsigned short smba; 157 165 ··· 157 175 struct sb800_mmio_cfg mmio_cfg; 158 176 }; 159 177 160 - static int piix4_sb800_region_request(struct device *dev, 161 - struct sb800_mmio_cfg *mmio_cfg) 178 + int piix4_sb800_region_request(struct device *dev, struct sb800_mmio_cfg *mmio_cfg) 162 179 { 163 180 if (mmio_cfg->use_mmio) { 164 181 void __iomem *addr; ··· 195 214 196 215 return 0; 197 216 } 217 + EXPORT_SYMBOL_NS_GPL(piix4_sb800_region_request, PIIX4_SMBUS); 198 218 199 - static void piix4_sb800_region_release(struct device *dev, 200 - struct sb800_mmio_cfg *mmio_cfg) 219 + void piix4_sb800_region_release(struct device *dev, struct sb800_mmio_cfg *mmio_cfg) 201 220 { 202 221 if (mmio_cfg->use_mmio) { 203 222 iounmap(mmio_cfg->addr); ··· 208 227 209 228 release_region(SB800_PIIX4_SMB_IDX, SB800_PIIX4_SMB_MAP_SIZE); 210 229 } 230 + EXPORT_SYMBOL_NS_GPL(piix4_sb800_region_release, PIIX4_SMBUS); 211 231 212 232 static bool piix4_sb800_use_mmio(struct pci_dev *PIIX4_dev) 213 233 { ··· 518 536 return piix4_smba; 519 537 } 520 538 521 - static int piix4_transaction(struct i2c_adapter *piix4_adapter) 539 + int piix4_transaction(struct i2c_adapter *piix4_adapter, unsigned short piix4_smba) 522 540 { 523 - struct i2c_piix4_adapdata *adapdata = i2c_get_adapdata(piix4_adapter); 524 - unsigned short piix4_smba = adapdata->smba; 525 541 int temp; 526 542 int result = 0; 527 543 int timeout = 0; ··· 591 611 inb_p(SMBHSTDAT1)); 592 612 return result; 593 613 } 614 + EXPORT_SYMBOL_NS_GPL(piix4_transaction, PIIX4_SMBUS); 594 615 595 616 /* Return negative errno on error. */ 596 617 static s32 piix4_access(struct i2c_adapter * adap, u16 addr, ··· 656 675 657 676 outb_p((size & 0x1C) + (ENABLE_INT9 & 1), SMBHSTCNT); 658 677 659 - status = piix4_transaction(adap); 678 + status = piix4_transaction(adap, piix4_smba); 660 679 if (status) 661 680 return status; 662 681 ··· 745 764 release_region(KERNCZ_IMC_IDX, 2); 746 765 } 747 766 748 - static int piix4_sb800_port_sel(u8 port, struct sb800_mmio_cfg *mmio_cfg) 767 + int piix4_sb800_port_sel(u8 port, struct sb800_mmio_cfg *mmio_cfg) 749 768 { 750 769 u8 smba_en_lo, val; 751 770 ··· 767 786 768 787 return (smba_en_lo & piix4_port_mask_sb800); 769 788 } 789 + EXPORT_SYMBOL_NS_GPL(piix4_sb800_port_sel, PIIX4_SMBUS); 770 790 771 791 /* 772 792 * Handles access to multiple SMBus ports on the SB800. ··· 1025 1043 { 1026 1044 int retval; 1027 1045 bool is_sb800 = false; 1046 + bool is_asf = false; 1047 + acpi_status status; 1048 + acpi_handle handle; 1028 1049 1029 1050 if ((dev->vendor == PCI_VENDOR_ID_ATI && 1030 1051 dev->device == PCI_DEVICE_ID_ATI_SBX00_SMBUS && ··· 1090 1105 } 1091 1106 } 1092 1107 1108 + status = acpi_get_handle(NULL, (acpi_string)SB800_ASF_ACPI_PATH, &handle); 1109 + if (ACPI_SUCCESS(status)) 1110 + is_asf = true; 1111 + 1093 1112 if (dev->vendor == PCI_VENDOR_ID_AMD && 1094 1113 (dev->device == PCI_DEVICE_ID_AMD_HUDSON2_SMBUS || 1095 1114 dev->device == PCI_DEVICE_ID_AMD_KERNCZ_SMBUS)) { 1096 - retval = piix4_setup_sb800(dev, id, 1); 1115 + /* Do not setup AUX port if ASF is enabled */ 1116 + if (!is_asf) 1117 + retval = piix4_setup_sb800(dev, id, 1); 1097 1118 } 1098 1119 1099 1120 if (retval > 0) {
+44
drivers/i2c/busses/i2c-piix4.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 + /* 3 + * PIIX4/SB800 SMBus Interfaces 4 + * 5 + * Copyright (c) 2024, Advanced Micro Devices, Inc. 6 + * All Rights Reserved. 7 + * 8 + * Authors: Shyam Sundar S K <Shyam-sundar.S-k@amd.com> 9 + * Sanket Goswami <Sanket.Goswami@amd.com> 10 + */ 11 + 12 + #ifndef I2C_PIIX4_H 13 + #define I2C_PIIX4_H 14 + 15 + #include <linux/types.h> 16 + 17 + /* PIIX4 SMBus address offsets */ 18 + #define SMBHSTSTS (0x00 + piix4_smba) 19 + #define SMBHSLVSTS (0x01 + piix4_smba) 20 + #define SMBHSTCNT (0x02 + piix4_smba) 21 + #define SMBHSTCMD (0x03 + piix4_smba) 22 + #define SMBHSTADD (0x04 + piix4_smba) 23 + #define SMBHSTDAT0 (0x05 + piix4_smba) 24 + #define SMBHSTDAT1 (0x06 + piix4_smba) 25 + #define SMBBLKDAT (0x07 + piix4_smba) 26 + #define SMBSLVCNT (0x08 + piix4_smba) 27 + #define SMBSHDWCMD (0x09 + piix4_smba) 28 + #define SMBSLVEVT (0x0A + piix4_smba) 29 + #define SMBSLVDAT (0x0C + piix4_smba) 30 + 31 + /* PIIX4 constants */ 32 + #define PIIX4_BLOCK_DATA 0x14 33 + 34 + struct sb800_mmio_cfg { 35 + void __iomem *addr; 36 + bool use_mmio; 37 + }; 38 + 39 + int piix4_sb800_port_sel(u8 port, struct sb800_mmio_cfg *mmio_cfg); 40 + int piix4_transaction(struct i2c_adapter *piix4_adapter, unsigned short piix4_smba); 41 + int piix4_sb800_region_request(struct device *dev, struct sb800_mmio_cfg *mmio_cfg); 42 + void piix4_sb800_region_release(struct device *dev, struct sb800_mmio_cfg *mmio_cfg); 43 + 44 + #endif /* I2C_PIIX4_H */
+1 -1
drivers/i2c/busses/i2c-pnx.c
··· 733 733 .pm = pm_sleep_ptr(&i2c_pnx_pm), 734 734 }, 735 735 .probe = i2c_pnx_probe, 736 - .remove_new = i2c_pnx_remove, 736 + .remove = i2c_pnx_remove, 737 737 }; 738 738 739 739 static int __init i2c_adap_pnx_init(void)
+1 -1
drivers/i2c/busses/i2c-powermac.c
··· 437 437 438 438 static struct platform_driver i2c_powermac_driver = { 439 439 .probe = i2c_powermac_probe, 440 - .remove_new = i2c_powermac_remove, 440 + .remove = i2c_powermac_remove, 441 441 .driver = { 442 442 .name = "i2c-powermac", 443 443 .bus = &platform_bus_type,
+1 -1
drivers/i2c/busses/i2c-pxa.c
··· 1574 1574 1575 1575 static struct platform_driver i2c_pxa_driver = { 1576 1576 .probe = i2c_pxa_probe, 1577 - .remove_new = i2c_pxa_remove, 1577 + .remove = i2c_pxa_remove, 1578 1578 .driver = { 1579 1579 .name = "pxa2xx-i2c", 1580 1580 .pm = pm_sleep_ptr(&i2c_pxa_dev_pm_ops),
+1 -22
drivers/i2c/busses/i2c-qcom-cci.c
··· 120 120 unsigned int num_masters; 121 121 struct i2c_adapter_quirks quirks; 122 122 u16 queue_size[NUM_QUEUES]; 123 - unsigned long cci_clk_rate; 124 123 struct hw_params params[3]; 125 124 }; 126 125 ··· 522 523 static int cci_probe(struct platform_device *pdev) 523 524 { 524 525 struct device *dev = &pdev->dev; 525 - unsigned long cci_clk_rate = 0; 526 526 struct device_node *child; 527 527 struct resource *r; 528 528 struct cci *cci; ··· 591 593 else if (!ret) 592 594 return dev_err_probe(dev, -EINVAL, "not enough clocks in DT\n"); 593 595 cci->nclocks = ret; 594 - 595 - /* Retrieve CCI clock rate */ 596 - for (i = 0; i < cci->nclocks; i++) { 597 - if (!strcmp(cci->clocks[i].id, "cci")) { 598 - cci_clk_rate = clk_get_rate(cci->clocks[i].clk); 599 - break; 600 - } 601 - } 602 - 603 - if (cci_clk_rate != cci->data->cci_clk_rate) { 604 - /* cci clock set by the bootloader or via assigned clock rate 605 - * in DT. 606 - */ 607 - dev_warn(dev, "Found %lu cci clk rate while %lu was expected\n", 608 - cci_clk_rate, cci->data->cci_clk_rate); 609 - } 610 596 611 597 ret = cci_enable_clocks(cci); 612 598 if (ret < 0) ··· 681 699 .max_write_len = 10, 682 700 .max_read_len = 12, 683 701 }, 684 - .cci_clk_rate = 19200000, 685 702 .params[I2C_MODE_STANDARD] = { 686 703 .thigh = 78, 687 704 .tlow = 114, ··· 714 733 .max_write_len = 10, 715 734 .max_read_len = 12, 716 735 }, 717 - .cci_clk_rate = 19200000, 718 736 .params[I2C_MODE_STANDARD] = { 719 737 .thigh = 78, 720 738 .tlow = 114, ··· 747 767 .max_write_len = 11, 748 768 .max_read_len = 12, 749 769 }, 750 - .cci_clk_rate = 37500000, 751 770 .params[I2C_MODE_STANDARD] = { 752 771 .thigh = 201, 753 772 .tlow = 174, ··· 805 826 806 827 static struct platform_driver qcom_cci_driver = { 807 828 .probe = cci_probe, 808 - .remove_new = cci_remove, 829 + .remove = cci_remove, 809 830 .driver = { 810 831 .name = "i2c-qcom-cci", 811 832 .of_match_table = cci_dt_match,
+22 -5
drivers/i2c/busses/i2c-qcom-geni.c
··· 16 16 #include <linux/pm_runtime.h> 17 17 #include <linux/soc/qcom/geni-se.h> 18 18 #include <linux/spinlock.h> 19 + #include <linux/units.h> 19 20 20 21 #define SE_I2C_TX_TRANS_LEN 0x26c 21 22 #define SE_I2C_RX_TRANS_LEN 0x270 ··· 147 146 * clk_freq_out = t / t_cycle 148 147 * source_clock = 19.2 MHz 149 148 */ 150 - static const struct geni_i2c_clk_fld geni_i2c_clk_map[] = { 149 + static const struct geni_i2c_clk_fld geni_i2c_clk_map_19p2mhz[] = { 151 150 {KHZ(100), 7, 10, 11, 26}, 152 151 {KHZ(400), 2, 5, 12, 24}, 153 152 {KHZ(1000), 1, 3, 9, 18}, 153 + {}, 154 + }; 155 + 156 + /* source_clock = 32 MHz */ 157 + 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 + {}, 154 162 }; 155 163 156 164 static int geni_i2c_clk_map_idx(struct geni_i2c_dev *gi2c) 157 165 { 158 - int i; 159 - const struct geni_i2c_clk_fld *itr = geni_i2c_clk_map; 166 + const struct geni_i2c_clk_fld *itr; 160 167 161 - for (i = 0; i < ARRAY_SIZE(geni_i2c_clk_map); i++, itr++) { 168 + if (clk_get_rate(gi2c->se.clk) == 32 * HZ_PER_MHZ) 169 + itr = geni_i2c_clk_map_32mhz; 170 + else 171 + itr = geni_i2c_clk_map_19p2mhz; 172 + 173 + while (itr->clk_freq_out != 0) { 162 174 if (itr->clk_freq_out == gi2c->clk_freq_out) { 163 175 gi2c->clk_fld = itr; 164 176 return 0; 165 177 } 178 + itr++; 166 179 } 167 180 return -EINVAL; 168 181 } ··· 833 818 init_completion(&gi2c->done); 834 819 spin_lock_init(&gi2c->lock); 835 820 platform_set_drvdata(pdev, gi2c); 821 + 822 + /* Keep interrupts disabled initially to allow for low-power modes */ 836 823 ret = devm_request_irq(dev, gi2c->irq, geni_i2c_irq, IRQF_NO_AUTOEN, 837 824 dev_name(dev), gi2c); 838 825 if (ret) { ··· 1066 1049 1067 1050 static struct platform_driver geni_i2c_driver = { 1068 1051 .probe = geni_i2c_probe, 1069 - .remove_new = geni_i2c_remove, 1052 + .remove = geni_i2c_remove, 1070 1053 .shutdown = geni_i2c_shutdown, 1071 1054 .driver = { 1072 1055 .name = "geni_i2c",
+1 -1
drivers/i2c/busses/i2c-qup.c
··· 1974 1974 1975 1975 static struct platform_driver qup_i2c_driver = { 1976 1976 .probe = qup_i2c_probe, 1977 - .remove_new = qup_i2c_remove, 1977 + .remove = qup_i2c_remove, 1978 1978 .driver = { 1979 1979 .name = "i2c_qup", 1980 1980 .pm = pm_ptr(&qup_i2c_qup_pm_ops),
+1 -1
drivers/i2c/busses/i2c-rcar.c
··· 1271 1271 .pm = pm_sleep_ptr(&rcar_i2c_pm_ops), 1272 1272 }, 1273 1273 .probe = rcar_i2c_probe, 1274 - .remove_new = rcar_i2c_remove, 1274 + .remove = rcar_i2c_remove, 1275 1275 }; 1276 1276 1277 1277 module_platform_driver(rcar_i2c_driver);
+1 -1
drivers/i2c/busses/i2c-riic.c
··· 632 632 633 633 static struct platform_driver riic_i2c_driver = { 634 634 .probe = riic_i2c_probe, 635 - .remove_new = riic_i2c_remove, 635 + .remove = riic_i2c_remove, 636 636 .driver = { 637 637 .name = "i2c-riic", 638 638 .of_match_table = riic_i2c_dt_ids,
+1 -1
drivers/i2c/busses/i2c-rk3x.c
··· 1398 1398 1399 1399 static struct platform_driver rk3x_i2c_driver = { 1400 1400 .probe = rk3x_i2c_probe, 1401 - .remove_new = rk3x_i2c_remove, 1401 + .remove = rk3x_i2c_remove, 1402 1402 .driver = { 1403 1403 .name = "rk3x-i2c", 1404 1404 .of_match_table = rk3x_i2c_match,
+423
drivers/i2c/busses/i2c-rtl9300.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + 3 + #include <linux/bits.h> 4 + #include <linux/i2c.h> 5 + #include <linux/i2c-mux.h> 6 + #include <linux/mod_devicetable.h> 7 + #include <linux/mfd/syscon.h> 8 + #include <linux/mutex.h> 9 + #include <linux/platform_device.h> 10 + #include <linux/regmap.h> 11 + 12 + enum rtl9300_bus_freq { 13 + RTL9300_I2C_STD_FREQ, 14 + RTL9300_I2C_FAST_FREQ, 15 + }; 16 + 17 + struct rtl9300_i2c; 18 + 19 + struct rtl9300_i2c_chan { 20 + struct i2c_adapter adap; 21 + struct rtl9300_i2c *i2c; 22 + enum rtl9300_bus_freq bus_freq; 23 + u8 sda_pin; 24 + }; 25 + 26 + #define RTL9300_I2C_MUX_NCHAN 8 27 + 28 + struct rtl9300_i2c { 29 + struct regmap *regmap; 30 + struct device *dev; 31 + struct rtl9300_i2c_chan chans[RTL9300_I2C_MUX_NCHAN]; 32 + u32 reg_base; 33 + u8 sda_pin; 34 + struct mutex lock; 35 + }; 36 + 37 + #define RTL9300_I2C_MST_CTRL1 0x0 38 + #define RTL9300_I2C_MST_CTRL1_MEM_ADDR_OFS 8 39 + #define RTL9300_I2C_MST_CTRL1_MEM_ADDR_MASK GENMASK(31, 8) 40 + #define RTL9300_I2C_MST_CTRL1_SDA_OUT_SEL_OFS 4 41 + #define RTL9300_I2C_MST_CTRL1_SDA_OUT_SEL_MASK GENMASK(6, 4) 42 + #define RTL9300_I2C_MST_CTRL1_GPIO_SCL_SEL BIT(3) 43 + #define RTL9300_I2C_MST_CTRL1_RWOP BIT(2) 44 + #define RTL9300_I2C_MST_CTRL1_I2C_FAIL BIT(1) 45 + #define RTL9300_I2C_MST_CTRL1_I2C_TRIG BIT(0) 46 + #define RTL9300_I2C_MST_CTRL2 0x4 47 + #define RTL9300_I2C_MST_CTRL2_RD_MODE BIT(15) 48 + #define RTL9300_I2C_MST_CTRL2_DEV_ADDR_OFS 8 49 + #define RTL9300_I2C_MST_CTRL2_DEV_ADDR_MASK GENMASK(14, 8) 50 + #define RTL9300_I2C_MST_CTRL2_DATA_WIDTH_OFS 4 51 + #define RTL9300_I2C_MST_CTRL2_DATA_WIDTH_MASK GENMASK(7, 4) 52 + #define RTL9300_I2C_MST_CTRL2_MEM_ADDR_WIDTH_OFS 2 53 + #define RTL9300_I2C_MST_CTRL2_MEM_ADDR_WIDTH_MASK GENMASK(3, 2) 54 + #define RTL9300_I2C_MST_CTRL2_SCL_FREQ_OFS 0 55 + #define RTL9300_I2C_MST_CTRL2_SCL_FREQ_MASK GENMASK(1, 0) 56 + #define RTL9300_I2C_MST_DATA_WORD0 0x8 57 + #define RTL9300_I2C_MST_DATA_WORD1 0xc 58 + #define RTL9300_I2C_MST_DATA_WORD2 0x10 59 + #define RTL9300_I2C_MST_DATA_WORD3 0x14 60 + 61 + #define RTL9300_I2C_MST_GLB_CTRL 0x384 62 + 63 + static int rtl9300_i2c_reg_addr_set(struct rtl9300_i2c *i2c, u32 reg, u16 len) 64 + { 65 + u32 val, mask; 66 + int ret; 67 + 68 + val = len << RTL9300_I2C_MST_CTRL2_MEM_ADDR_WIDTH_OFS; 69 + mask = RTL9300_I2C_MST_CTRL2_MEM_ADDR_WIDTH_MASK; 70 + 71 + ret = regmap_update_bits(i2c->regmap, i2c->reg_base + RTL9300_I2C_MST_CTRL2, mask, val); 72 + if (ret) 73 + return ret; 74 + 75 + val = reg << RTL9300_I2C_MST_CTRL1_MEM_ADDR_OFS; 76 + mask = RTL9300_I2C_MST_CTRL1_MEM_ADDR_MASK; 77 + 78 + return regmap_update_bits(i2c->regmap, i2c->reg_base + RTL9300_I2C_MST_CTRL1, mask, val); 79 + } 80 + 81 + static int rtl9300_i2c_config_io(struct rtl9300_i2c *i2c, u8 sda_pin) 82 + { 83 + int ret; 84 + u32 val, mask; 85 + 86 + ret = regmap_update_bits(i2c->regmap, RTL9300_I2C_MST_GLB_CTRL, BIT(sda_pin), BIT(sda_pin)); 87 + if (ret) 88 + return ret; 89 + 90 + val = (sda_pin << RTL9300_I2C_MST_CTRL1_SDA_OUT_SEL_OFS) | 91 + RTL9300_I2C_MST_CTRL1_GPIO_SCL_SEL; 92 + mask = RTL9300_I2C_MST_CTRL1_SDA_OUT_SEL_MASK | RTL9300_I2C_MST_CTRL1_GPIO_SCL_SEL; 93 + 94 + return regmap_update_bits(i2c->regmap, i2c->reg_base + RTL9300_I2C_MST_CTRL1, mask, val); 95 + } 96 + 97 + static int rtl9300_i2c_config_xfer(struct rtl9300_i2c *i2c, struct rtl9300_i2c_chan *chan, 98 + u16 addr, u16 len) 99 + { 100 + u32 val, mask; 101 + 102 + val = chan->bus_freq << RTL9300_I2C_MST_CTRL2_SCL_FREQ_OFS; 103 + mask = RTL9300_I2C_MST_CTRL2_SCL_FREQ_MASK; 104 + 105 + val |= addr << RTL9300_I2C_MST_CTRL2_DEV_ADDR_OFS; 106 + mask |= RTL9300_I2C_MST_CTRL2_DEV_ADDR_MASK; 107 + 108 + val |= ((len - 1) & 0xf) << RTL9300_I2C_MST_CTRL2_DATA_WIDTH_OFS; 109 + mask |= RTL9300_I2C_MST_CTRL2_DATA_WIDTH_MASK; 110 + 111 + mask |= RTL9300_I2C_MST_CTRL2_RD_MODE; 112 + 113 + return regmap_update_bits(i2c->regmap, i2c->reg_base + RTL9300_I2C_MST_CTRL2, mask, val); 114 + } 115 + 116 + static int rtl9300_i2c_read(struct rtl9300_i2c *i2c, u8 *buf, int len) 117 + { 118 + u32 vals[4] = {}; 119 + int i, ret; 120 + 121 + if (len > 16) 122 + return -EIO; 123 + 124 + ret = regmap_bulk_read(i2c->regmap, i2c->reg_base + RTL9300_I2C_MST_DATA_WORD0, 125 + vals, ARRAY_SIZE(vals)); 126 + if (ret) 127 + return ret; 128 + 129 + for (i = 0; i < len; i++) { 130 + buf[i] = vals[i/4] & 0xff; 131 + vals[i/4] >>= 8; 132 + } 133 + 134 + return 0; 135 + } 136 + 137 + static int rtl9300_i2c_write(struct rtl9300_i2c *i2c, u8 *buf, int len) 138 + { 139 + u32 vals[4] = {}; 140 + int i; 141 + 142 + if (len > 16) 143 + return -EIO; 144 + 145 + for (i = 0; i < len; i++) { 146 + if (i % 4 == 0) 147 + vals[i/4] = 0; 148 + vals[i/4] <<= 8; 149 + vals[i/4] |= buf[i]; 150 + } 151 + 152 + return regmap_bulk_write(i2c->regmap, i2c->reg_base + RTL9300_I2C_MST_DATA_WORD0, 153 + vals, ARRAY_SIZE(vals)); 154 + } 155 + 156 + static int rtl9300_i2c_writel(struct rtl9300_i2c *i2c, u32 data) 157 + { 158 + return regmap_write(i2c->regmap, i2c->reg_base + RTL9300_I2C_MST_DATA_WORD0, data); 159 + } 160 + 161 + static int rtl9300_i2c_execute_xfer(struct rtl9300_i2c *i2c, char read_write, 162 + int size, union i2c_smbus_data *data, int len) 163 + { 164 + u32 val, mask; 165 + int ret; 166 + 167 + val = read_write == I2C_SMBUS_WRITE ? RTL9300_I2C_MST_CTRL1_RWOP : 0; 168 + mask = RTL9300_I2C_MST_CTRL1_RWOP; 169 + 170 + val |= RTL9300_I2C_MST_CTRL1_I2C_TRIG; 171 + mask |= RTL9300_I2C_MST_CTRL1_I2C_TRIG; 172 + 173 + ret = regmap_update_bits(i2c->regmap, i2c->reg_base + RTL9300_I2C_MST_CTRL1, mask, val); 174 + if (ret) 175 + return ret; 176 + 177 + ret = regmap_read_poll_timeout(i2c->regmap, i2c->reg_base + RTL9300_I2C_MST_CTRL1, 178 + val, !(val & RTL9300_I2C_MST_CTRL1_I2C_TRIG), 100, 2000); 179 + if (ret) 180 + return ret; 181 + 182 + if (val & RTL9300_I2C_MST_CTRL1_I2C_FAIL) 183 + return -EIO; 184 + 185 + if (read_write == I2C_SMBUS_READ) { 186 + if (size == I2C_SMBUS_BYTE || size == I2C_SMBUS_BYTE_DATA) { 187 + ret = regmap_read(i2c->regmap, 188 + i2c->reg_base + RTL9300_I2C_MST_DATA_WORD0, &val); 189 + if (ret) 190 + return ret; 191 + data->byte = val & 0xff; 192 + } else if (size == I2C_SMBUS_WORD_DATA) { 193 + ret = regmap_read(i2c->regmap, 194 + i2c->reg_base + RTL9300_I2C_MST_DATA_WORD0, &val); 195 + if (ret) 196 + return ret; 197 + data->word = val & 0xffff; 198 + } else { 199 + ret = rtl9300_i2c_read(i2c, &data->block[0], len); 200 + if (ret) 201 + return ret; 202 + } 203 + } 204 + 205 + return 0; 206 + } 207 + 208 + static int rtl9300_i2c_smbus_xfer(struct i2c_adapter *adap, u16 addr, unsigned short flags, 209 + char read_write, u8 command, int size, 210 + union i2c_smbus_data *data) 211 + { 212 + struct rtl9300_i2c_chan *chan = i2c_get_adapdata(adap); 213 + struct rtl9300_i2c *i2c = chan->i2c; 214 + int len = 0, ret; 215 + 216 + mutex_lock(&i2c->lock); 217 + if (chan->sda_pin != i2c->sda_pin) { 218 + ret = rtl9300_i2c_config_io(i2c, chan->sda_pin); 219 + if (ret) 220 + goto out_unlock; 221 + i2c->sda_pin = chan->sda_pin; 222 + } 223 + 224 + switch (size) { 225 + case I2C_SMBUS_QUICK: 226 + ret = rtl9300_i2c_config_xfer(i2c, chan, addr, 0); 227 + if (ret) 228 + goto out_unlock; 229 + ret = rtl9300_i2c_reg_addr_set(i2c, 0, 0); 230 + if (ret) 231 + goto out_unlock; 232 + break; 233 + 234 + case I2C_SMBUS_BYTE: 235 + if (read_write == I2C_SMBUS_WRITE) { 236 + ret = rtl9300_i2c_config_xfer(i2c, chan, addr, 0); 237 + if (ret) 238 + goto out_unlock; 239 + ret = rtl9300_i2c_reg_addr_set(i2c, command, 1); 240 + if (ret) 241 + goto out_unlock; 242 + } else { 243 + ret = rtl9300_i2c_config_xfer(i2c, chan, addr, 1); 244 + if (ret) 245 + goto out_unlock; 246 + ret = rtl9300_i2c_reg_addr_set(i2c, 0, 0); 247 + if (ret) 248 + goto out_unlock; 249 + } 250 + break; 251 + 252 + case I2C_SMBUS_BYTE_DATA: 253 + ret = rtl9300_i2c_reg_addr_set(i2c, command, 1); 254 + if (ret) 255 + goto out_unlock; 256 + ret = rtl9300_i2c_config_xfer(i2c, chan, addr, 1); 257 + if (ret) 258 + goto out_unlock; 259 + if (read_write == I2C_SMBUS_WRITE) { 260 + ret = rtl9300_i2c_writel(i2c, data->byte); 261 + if (ret) 262 + goto out_unlock; 263 + } 264 + break; 265 + 266 + case I2C_SMBUS_WORD_DATA: 267 + ret = rtl9300_i2c_reg_addr_set(i2c, command, 1); 268 + if (ret) 269 + goto out_unlock; 270 + ret = rtl9300_i2c_config_xfer(i2c, chan, addr, 2); 271 + if (ret) 272 + goto out_unlock; 273 + if (read_write == I2C_SMBUS_WRITE) { 274 + ret = rtl9300_i2c_writel(i2c, data->word); 275 + if (ret) 276 + goto out_unlock; 277 + } 278 + break; 279 + 280 + case I2C_SMBUS_BLOCK_DATA: 281 + ret = rtl9300_i2c_reg_addr_set(i2c, command, 1); 282 + if (ret) 283 + goto out_unlock; 284 + ret = rtl9300_i2c_config_xfer(i2c, chan, addr, data->block[0]); 285 + if (ret) 286 + goto out_unlock; 287 + if (read_write == I2C_SMBUS_WRITE) { 288 + ret = rtl9300_i2c_write(i2c, &data->block[1], data->block[0]); 289 + if (ret) 290 + goto out_unlock; 291 + } 292 + len = data->block[0]; 293 + break; 294 + 295 + default: 296 + dev_err(&adap->dev, "Unsupported transaction %d\n", size); 297 + ret = -EOPNOTSUPP; 298 + goto out_unlock; 299 + } 300 + 301 + ret = rtl9300_i2c_execute_xfer(i2c, read_write, size, data, len); 302 + 303 + out_unlock: 304 + mutex_unlock(&i2c->lock); 305 + 306 + return ret; 307 + } 308 + 309 + static u32 rtl9300_i2c_func(struct i2c_adapter *a) 310 + { 311 + return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | 312 + I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | 313 + I2C_FUNC_SMBUS_BLOCK_DATA; 314 + } 315 + 316 + static const struct i2c_algorithm rtl9300_i2c_algo = { 317 + .smbus_xfer = rtl9300_i2c_smbus_xfer, 318 + .functionality = rtl9300_i2c_func, 319 + }; 320 + 321 + static struct i2c_adapter_quirks rtl9300_i2c_quirks = { 322 + .flags = I2C_AQ_NO_CLK_STRETCH, 323 + .max_read_len = 16, 324 + .max_write_len = 16, 325 + }; 326 + 327 + static int rtl9300_i2c_probe(struct platform_device *pdev) 328 + { 329 + struct device *dev = &pdev->dev; 330 + struct rtl9300_i2c *i2c; 331 + u32 clock_freq, sda_pin; 332 + int ret, i = 0; 333 + struct fwnode_handle *child; 334 + 335 + i2c = devm_kzalloc(dev, sizeof(*i2c), GFP_KERNEL); 336 + if (!i2c) 337 + return -ENOMEM; 338 + 339 + i2c->regmap = syscon_node_to_regmap(dev->parent->of_node); 340 + if (IS_ERR(i2c->regmap)) 341 + return PTR_ERR(i2c->regmap); 342 + i2c->dev = dev; 343 + 344 + mutex_init(&i2c->lock); 345 + 346 + ret = device_property_read_u32(dev, "reg", &i2c->reg_base); 347 + if (ret) 348 + return ret; 349 + 350 + platform_set_drvdata(pdev, i2c); 351 + 352 + if (device_get_child_node_count(dev) >= RTL9300_I2C_MUX_NCHAN) 353 + return dev_err_probe(dev, -EINVAL, "Too many channels\n"); 354 + 355 + device_for_each_child_node(dev, child) { 356 + struct rtl9300_i2c_chan *chan = &i2c->chans[i]; 357 + struct i2c_adapter *adap = &chan->adap; 358 + 359 + ret = fwnode_property_read_u32(child, "reg", &sda_pin); 360 + if (ret) 361 + return ret; 362 + 363 + ret = fwnode_property_read_u32(child, "clock-frequency", &clock_freq); 364 + if (ret) 365 + clock_freq = I2C_MAX_STANDARD_MODE_FREQ; 366 + 367 + switch (clock_freq) { 368 + case I2C_MAX_STANDARD_MODE_FREQ: 369 + chan->bus_freq = RTL9300_I2C_STD_FREQ; 370 + break; 371 + 372 + case I2C_MAX_FAST_MODE_FREQ: 373 + chan->bus_freq = RTL9300_I2C_FAST_FREQ; 374 + break; 375 + default: 376 + dev_warn(i2c->dev, "SDA%d clock-frequency %d not supported using default\n", 377 + sda_pin, clock_freq); 378 + break; 379 + } 380 + 381 + chan->sda_pin = sda_pin; 382 + chan->i2c = i2c; 383 + adap = &i2c->chans[i].adap; 384 + adap->owner = THIS_MODULE; 385 + adap->algo = &rtl9300_i2c_algo; 386 + adap->quirks = &rtl9300_i2c_quirks; 387 + adap->retries = 3; 388 + adap->dev.parent = dev; 389 + i2c_set_adapdata(adap, chan); 390 + adap->dev.of_node = to_of_node(child); 391 + snprintf(adap->name, sizeof(adap->name), "%s SDA%d\n", dev_name(dev), sda_pin); 392 + i++; 393 + 394 + ret = devm_i2c_add_adapter(dev, adap); 395 + if (ret) 396 + return ret; 397 + } 398 + i2c->sda_pin = 0xff; 399 + 400 + return 0; 401 + } 402 + 403 + static const struct of_device_id i2c_rtl9300_dt_ids[] = { 404 + { .compatible = "realtek,rtl9301-i2c" }, 405 + { .compatible = "realtek,rtl9302b-i2c" }, 406 + { .compatible = "realtek,rtl9302c-i2c" }, 407 + { .compatible = "realtek,rtl9303-i2c" }, 408 + {} 409 + }; 410 + MODULE_DEVICE_TABLE(of, i2c_rtl9300_dt_ids); 411 + 412 + static struct platform_driver rtl9300_i2c_driver = { 413 + .probe = rtl9300_i2c_probe, 414 + .driver = { 415 + .name = "i2c-rtl9300", 416 + .of_match_table = i2c_rtl9300_dt_ids, 417 + }, 418 + }; 419 + 420 + module_platform_driver(rtl9300_i2c_driver); 421 + 422 + MODULE_DESCRIPTION("RTL9300 I2C controller driver"); 423 + MODULE_LICENSE("GPL");
+1 -1
drivers/i2c/busses/i2c-rzv2m.c
··· 536 536 .pm = pm_sleep_ptr(&rzv2m_i2c_pm_ops), 537 537 }, 538 538 .probe = rzv2m_i2c_probe, 539 - .remove_new = rzv2m_i2c_remove, 539 + .remove = rzv2m_i2c_remove, 540 540 }; 541 541 module_platform_driver(rzv2m_i2c_driver); 542 542
+1 -1
drivers/i2c/busses/i2c-s3c2410.c
··· 1176 1176 1177 1177 static struct platform_driver s3c24xx_i2c_driver = { 1178 1178 .probe = s3c24xx_i2c_probe, 1179 - .remove_new = s3c24xx_i2c_remove, 1179 + .remove = s3c24xx_i2c_remove, 1180 1180 .id_table = s3c24xx_driver_ids, 1181 1181 .driver = { 1182 1182 .name = "s3c-i2c",
+1 -1
drivers/i2c/busses/i2c-scmi.c
··· 411 411 412 412 static struct platform_driver smbus_cmi_driver = { 413 413 .probe = smbus_cmi_probe, 414 - .remove_new = smbus_cmi_remove, 414 + .remove = smbus_cmi_remove, 415 415 .driver = { 416 416 .name = "smbus_cmi", 417 417 .acpi_match_table = acpi_smbus_cmi_ids,
+1 -1
drivers/i2c/busses/i2c-sh7760.c
··· 552 552 .name = SH7760_I2C_DEVNAME, 553 553 }, 554 554 .probe = sh7760_i2c_probe, 555 - .remove_new = sh7760_i2c_remove, 555 + .remove = sh7760_i2c_remove, 556 556 }; 557 557 558 558 module_platform_driver(sh7760_i2c_drv);
+1 -1
drivers/i2c/busses/i2c-sh_mobile.c
··· 983 983 .pm = pm_sleep_ptr(&sh_mobile_i2c_pm_ops), 984 984 }, 985 985 .probe = sh_mobile_i2c_probe, 986 - .remove_new = sh_mobile_i2c_remove, 986 + .remove = sh_mobile_i2c_remove, 987 987 }; 988 988 989 989 static int __init sh_mobile_i2c_adap_init(void)
+1 -1
drivers/i2c/busses/i2c-simtec.c
··· 144 144 .name = "simtec-i2c", 145 145 }, 146 146 .probe = simtec_i2c_probe, 147 - .remove_new = simtec_i2c_remove, 147 + .remove = simtec_i2c_remove, 148 148 }; 149 149 150 150 module_platform_driver(simtec_i2c_driver);
+1 -1
drivers/i2c/busses/i2c-sprd.c
··· 643 643 644 644 static struct platform_driver sprd_i2c_driver = { 645 645 .probe = sprd_i2c_probe, 646 - .remove_new = sprd_i2c_remove, 646 + .remove = sprd_i2c_remove, 647 647 .driver = { 648 648 .name = "sprd-i2c", 649 649 .of_match_table = sprd_i2c_of_match,
+1 -1
drivers/i2c/busses/i2c-st.c
··· 893 893 .pm = pm_sleep_ptr(&st_i2c_pm), 894 894 }, 895 895 .probe = st_i2c_probe, 896 - .remove_new = st_i2c_remove, 896 + .remove = st_i2c_remove, 897 897 }; 898 898 899 899 module_platform_driver(st_i2c_driver);
+1 -1
drivers/i2c/busses/i2c-stm32f4.c
··· 869 869 .of_match_table = stm32f4_i2c_match, 870 870 }, 871 871 .probe = stm32f4_i2c_probe, 872 - .remove_new = stm32f4_i2c_remove, 872 + .remove = stm32f4_i2c_remove, 873 873 }; 874 874 875 875 module_platform_driver(stm32f4_i2c_driver);
+1 -1
drivers/i2c/busses/i2c-stm32f7.c
··· 2532 2532 .pm = &stm32f7_i2c_pm_ops, 2533 2533 }, 2534 2534 .probe = stm32f7_i2c_probe, 2535 - .remove_new = stm32f7_i2c_remove, 2535 + .remove = stm32f7_i2c_remove, 2536 2536 }; 2537 2537 2538 2538 module_platform_driver(stm32f7_i2c_driver);
+1 -1
drivers/i2c/busses/i2c-sun6i-p2wi.c
··· 319 319 320 320 static struct platform_driver p2wi_driver = { 321 321 .probe = p2wi_probe, 322 - .remove_new = p2wi_remove, 322 + .remove = p2wi_remove, 323 323 .driver = { 324 324 .name = "i2c-sunxi-p2wi", 325 325 .of_match_table = p2wi_of_match_table,
+1 -1
drivers/i2c/busses/i2c-synquacer.c
··· 629 629 630 630 static struct platform_driver synquacer_i2c_driver = { 631 631 .probe = synquacer_i2c_probe, 632 - .remove_new = synquacer_i2c_remove, 632 + .remove = synquacer_i2c_remove, 633 633 .driver = { 634 634 .name = "synquacer_i2c", 635 635 .of_match_table = of_match_ptr(synquacer_i2c_dt_ids),
+1 -1
drivers/i2c/busses/i2c-tegra-bpmp.c
··· 335 335 .of_match_table = tegra_bpmp_i2c_of_match, 336 336 }, 337 337 .probe = tegra_bpmp_i2c_probe, 338 - .remove_new = tegra_bpmp_i2c_remove, 338 + .remove = tegra_bpmp_i2c_remove, 339 339 }; 340 340 module_platform_driver(tegra_bpmp_i2c_driver); 341 341
+1 -1
drivers/i2c/busses/i2c-tegra.c
··· 1964 1964 1965 1965 static struct platform_driver tegra_i2c_driver = { 1966 1966 .probe = tegra_i2c_probe, 1967 - .remove_new = tegra_i2c_remove, 1967 + .remove = tegra_i2c_remove, 1968 1968 .driver = { 1969 1969 .name = "tegra-i2c", 1970 1970 .of_match_table = tegra_i2c_of_match,
+1 -1
drivers/i2c/busses/i2c-uniphier-f.c
··· 615 615 616 616 static struct platform_driver uniphier_fi2c_drv = { 617 617 .probe = uniphier_fi2c_probe, 618 - .remove_new = uniphier_fi2c_remove, 618 + .remove = uniphier_fi2c_remove, 619 619 .driver = { 620 620 .name = "uniphier-fi2c", 621 621 .of_match_table = uniphier_fi2c_match,
+1 -1
drivers/i2c/busses/i2c-uniphier.c
··· 409 409 410 410 static struct platform_driver uniphier_i2c_drv = { 411 411 .probe = uniphier_i2c_probe, 412 - .remove_new = uniphier_i2c_remove, 412 + .remove = uniphier_i2c_remove, 413 413 .driver = { 414 414 .name = "uniphier-i2c", 415 415 .of_match_table = uniphier_i2c_match,
+1 -1
drivers/i2c/busses/i2c-versatile.c
··· 109 109 110 110 static struct platform_driver i2c_versatile_driver = { 111 111 .probe = i2c_versatile_probe, 112 - .remove_new = i2c_versatile_remove, 112 + .remove = i2c_versatile_remove, 113 113 .driver = { 114 114 .name = "versatile-i2c", 115 115 .of_match_table = i2c_versatile_match,
+1 -1
drivers/i2c/busses/i2c-viai2c-wmt.c
··· 169 169 170 170 static struct platform_driver wmt_i2c_driver = { 171 171 .probe = wmt_i2c_probe, 172 - .remove_new = wmt_i2c_remove, 172 + .remove = wmt_i2c_remove, 173 173 .driver = { 174 174 .name = "wmt-i2c", 175 175 .of_match_table = wmt_i2c_dt_ids,
+1 -1
drivers/i2c/busses/i2c-viperboard.c
··· 415 415 static struct platform_driver vprbrd_i2c_driver = { 416 416 .driver.name = "viperboard-i2c", 417 417 .probe = vprbrd_i2c_probe, 418 - .remove_new = vprbrd_i2c_remove, 418 + .remove = vprbrd_i2c_remove, 419 419 }; 420 420 421 421 static int __init vprbrd_i2c_init(void)
+1 -1
drivers/i2c/busses/i2c-xgene-slimpro.c
··· 581 581 582 582 static struct platform_driver xgene_slimpro_i2c_driver = { 583 583 .probe = xgene_slimpro_i2c_probe, 584 - .remove_new = xgene_slimpro_i2c_remove, 584 + .remove = xgene_slimpro_i2c_remove, 585 585 .driver = { 586 586 .name = "xgene-slimpro-i2c", 587 587 .of_match_table = of_match_ptr(xgene_slimpro_i2c_dt_ids),
+1 -1
drivers/i2c/busses/i2c-xiic.c
··· 1395 1395 1396 1396 static struct platform_driver xiic_i2c_driver = { 1397 1397 .probe = xiic_i2c_probe, 1398 - .remove_new = xiic_i2c_remove, 1398 + .remove = xiic_i2c_remove, 1399 1399 .driver = { 1400 1400 .name = DRIVER_NAME, 1401 1401 .of_match_table = of_match_ptr(xiic_of_match),
+1 -1
drivers/i2c/busses/i2c-xlp9xx.c
··· 579 579 580 580 static struct platform_driver xlp9xx_i2c_driver = { 581 581 .probe = xlp9xx_i2c_probe, 582 - .remove_new = xlp9xx_i2c_remove, 582 + .remove = xlp9xx_i2c_remove, 583 583 .driver = { 584 584 .name = "xlp9xx-i2c", 585 585 .acpi_match_table = ACPI_PTR(xlp9xx_i2c_acpi_ids),
+1 -1
drivers/i2c/busses/scx200_acb.c
··· 536 536 .name = "cs5535-smb", 537 537 }, 538 538 .probe = scx200_probe, 539 - .remove_new = scx200_remove, 539 + .remove = scx200_remove, 540 540 }; 541 541 542 542 static const struct pci_device_id scx200_isa[] = {
+6 -3
drivers/i2c/i2c-core-smbus.c
··· 712 712 if (!parent) 713 713 return 0; 714 714 715 + /* Report serious errors */ 715 716 irq = device_property_match_string(parent, "interrupt-names", "smbus_alert"); 716 - if (irq == -EINVAL || irq == -ENODATA) 717 - return 0; 718 - else if (irq < 0) 717 + if (irq < 0 && irq != -EINVAL && irq != -ENODATA) 719 718 return irq; 719 + 720 + /* Skip setup when no irq was found */ 721 + if (irq < 0 && !device_property_present(parent, "smbalert-gpios")) 722 + return 0; 720 723 721 724 return PTR_ERR_OR_ZERO(i2c_new_smbus_alert_device(adapter, NULL)); 722 725 }
+9 -8
drivers/i2c/i2c-dev.c
··· 251 251 return -EOPNOTSUPP; 252 252 253 253 data_ptrs = kmalloc_array(nmsgs, sizeof(u8 __user *), GFP_KERNEL); 254 - if (data_ptrs == NULL) { 255 - kfree(msgs); 254 + if (!data_ptrs) 256 255 return -ENOMEM; 257 - } 258 256 259 257 res = 0; 260 258 for (i = 0; i < nmsgs; i++) { ··· 300 302 for (j = 0; j < i; ++j) 301 303 kfree(msgs[j].buf); 302 304 kfree(data_ptrs); 303 - kfree(msgs); 304 305 return res; 305 306 } 306 307 ··· 313 316 kfree(msgs[i].buf); 314 317 } 315 318 kfree(data_ptrs); 316 - kfree(msgs); 317 319 return res; 318 320 } 319 321 ··· 442 446 case I2C_RDWR: { 443 447 struct i2c_rdwr_ioctl_data rdwr_arg; 444 448 struct i2c_msg *rdwr_pa; 449 + int res; 445 450 446 451 if (copy_from_user(&rdwr_arg, 447 452 (struct i2c_rdwr_ioctl_data __user *)arg, ··· 464 467 if (IS_ERR(rdwr_pa)) 465 468 return PTR_ERR(rdwr_pa); 466 469 467 - return i2cdev_ioctl_rdwr(client, rdwr_arg.nmsgs, rdwr_pa); 470 + res = i2cdev_ioctl_rdwr(client, rdwr_arg.nmsgs, rdwr_pa); 471 + kfree(rdwr_pa); 472 + return res; 468 473 } 469 474 470 475 case I2C_SMBUS: { ··· 539 540 struct i2c_rdwr_ioctl_data32 rdwr_arg; 540 541 struct i2c_msg32 __user *p; 541 542 struct i2c_msg *rdwr_pa; 542 - int i; 543 + int i, res; 543 544 544 545 if (copy_from_user(&rdwr_arg, 545 546 (struct i2c_rdwr_ioctl_data32 __user *)arg, ··· 572 573 }; 573 574 } 574 575 575 - return i2cdev_ioctl_rdwr(client, rdwr_arg.nmsgs, rdwr_pa); 576 + res = i2cdev_ioctl_rdwr(client, rdwr_arg.nmsgs, rdwr_pa); 577 + kfree(rdwr_pa); 578 + return res; 576 579 } 577 580 case I2C_SMBUS: { 578 581 struct i2c_smbus_ioctl_data32 data32;
+7
drivers/i2c/i2c-slave-testunit.c
··· 183 183 break; 184 184 185 185 case TU_CMD_SMBUS_ALERT_REQUEST: 186 + if (!tu->gpio) { 187 + ret = -ENOENT; 188 + break; 189 + } 186 190 i2c_slave_unregister(tu->client); 187 191 orig_addr = tu->client->addr; 188 192 tu->client->addr = 0x0c; ··· 236 232 INIT_DELAYED_WORK(&tu->worker, i2c_slave_testunit_work); 237 233 238 234 tu->gpio = devm_gpiod_get_index_optional(&client->dev, NULL, 0, GPIOD_OUT_LOW); 235 + if (IS_ERR(tu->gpio)) 236 + return PTR_ERR(tu->gpio); 237 + 239 238 if (gpiod_cansleep(tu->gpio)) { 240 239 dev_err(&client->dev, "GPIO access which may sleep is not allowed\n"); 241 240 return -EDEADLK;
+16 -6
drivers/i2c/i2c-smbus.c
··· 8 8 9 9 #include <linux/device.h> 10 10 #include <linux/dmi.h> 11 + #include <linux/gpio/consumer.h> 11 12 #include <linux/i2c.h> 12 13 #include <linux/i2c-smbus.h> 13 14 #include <linux/interrupt.h> ··· 168 167 struct i2c_smbus_alert_setup *setup = dev_get_platdata(&ara->dev); 169 168 struct i2c_smbus_alert *alert; 170 169 struct i2c_adapter *adapter = ara->adapter; 170 + unsigned long irqflags = IRQF_SHARED | IRQF_ONESHOT; 171 + struct gpio_desc *gpiod; 171 172 int res, irq; 172 173 173 174 alert = devm_kzalloc(&ara->dev, sizeof(struct i2c_smbus_alert), ··· 182 179 } else { 183 180 irq = fwnode_irq_get_byname(dev_fwnode(adapter->dev.parent), 184 181 "smbus_alert"); 185 - if (irq <= 0) 186 - return irq; 182 + if (irq <= 0) { 183 + gpiod = devm_gpiod_get(adapter->dev.parent, "smbalert", GPIOD_IN); 184 + if (IS_ERR(gpiod)) 185 + return PTR_ERR(gpiod); 186 + 187 + irq = gpiod_to_irq(gpiod); 188 + if (irq <= 0) 189 + return irq; 190 + 191 + irqflags |= IRQF_TRIGGER_FALLING; 192 + } 187 193 } 188 194 189 195 INIT_WORK(&alert->alert, smbalert_work); 190 196 alert->ara = ara; 191 197 192 198 if (irq > 0) { 193 - res = devm_request_threaded_irq(&ara->dev, irq, 194 - NULL, smbus_alert, 195 - IRQF_SHARED | IRQF_ONESHOT, 196 - "smbus_alert", alert); 199 + res = devm_request_threaded_irq(&ara->dev, irq, NULL, smbus_alert, 200 + irqflags, "smbus_alert", alert); 197 201 if (res) 198 202 return res; 199 203 }
+1 -1
drivers/i2c/muxes/i2c-arb-gpio-challenge.c
··· 190 190 191 191 static struct platform_driver i2c_arbitrator_driver = { 192 192 .probe = i2c_arbitrator_probe, 193 - .remove_new = i2c_arbitrator_remove, 193 + .remove = i2c_arbitrator_remove, 194 194 .driver = { 195 195 .name = "i2c-arb-gpio-challenge", 196 196 .of_match_table = i2c_arbitrator_of_match,
+1 -1
drivers/i2c/muxes/i2c-demux-pinctrl.c
··· 314 314 .of_match_table = i2c_demux_pinctrl_of_match, 315 315 }, 316 316 .probe = i2c_demux_pinctrl_probe, 317 - .remove_new = i2c_demux_pinctrl_remove, 317 + .remove = i2c_demux_pinctrl_remove, 318 318 }; 319 319 module_platform_driver(i2c_demux_pinctrl_driver); 320 320
+1 -1
drivers/i2c/muxes/i2c-mux-gpio.c
··· 247 247 248 248 static struct platform_driver i2c_mux_gpio_driver = { 249 249 .probe = i2c_mux_gpio_probe, 250 - .remove_new = i2c_mux_gpio_remove, 250 + .remove = i2c_mux_gpio_remove, 251 251 .driver = { 252 252 .name = "i2c-mux-gpio", 253 253 .of_match_table = i2c_mux_gpio_of_match,
+1 -1
drivers/i2c/muxes/i2c-mux-gpmux.c
··· 152 152 153 153 static struct platform_driver i2c_mux_driver = { 154 154 .probe = i2c_mux_probe, 155 - .remove_new = i2c_mux_remove, 155 + .remove = i2c_mux_remove, 156 156 .driver = { 157 157 .name = "i2c-mux-gpmux", 158 158 .of_match_table = i2c_mux_of_match,
+1 -1
drivers/i2c/muxes/i2c-mux-mlxcpld.c
··· 182 182 .name = "i2c-mux-mlxcpld", 183 183 }, 184 184 .probe = mlxcpld_mux_probe, 185 - .remove_new = mlxcpld_mux_remove, 185 + .remove = mlxcpld_mux_remove, 186 186 }; 187 187 188 188 module_platform_driver(mlxcpld_mux_driver);
+1 -1
drivers/i2c/muxes/i2c-mux-pinctrl.c
··· 186 186 .of_match_table = i2c_mux_pinctrl_of_match, 187 187 }, 188 188 .probe = i2c_mux_pinctrl_probe, 189 - .remove_new = i2c_mux_pinctrl_remove, 189 + .remove = i2c_mux_pinctrl_remove, 190 190 }; 191 191 module_platform_driver(i2c_mux_pinctrl_driver); 192 192
+1 -1
drivers/i2c/muxes/i2c-mux-reg.c
··· 247 247 248 248 static struct platform_driver i2c_mux_reg_driver = { 249 249 .probe = i2c_mux_reg_probe, 250 - .remove_new = i2c_mux_reg_remove, 250 + .remove = i2c_mux_reg_remove, 251 251 .driver = { 252 252 .name = "i2c-mux-reg", 253 253 .of_match_table = of_match_ptr(i2c_mux_reg_of_match),
+4
drivers/misc/eeprom/at24.c
··· 207 207 AT24_FLAG_ADDR16 | AT24_FLAG_SERIAL | AT24_FLAG_READONLY); 208 208 AT24_CHIP_DATA(at24_data_24c128, 131072 / 8, AT24_FLAG_ADDR16); 209 209 AT24_CHIP_DATA(at24_data_24c256, 262144 / 8, AT24_FLAG_ADDR16); 210 + /* M24256E Additional Write lockable page (M24256E-F order codes) */ 211 + AT24_CHIP_DATA(at24_data_24256e_wlp, 64, AT24_FLAG_ADDR16); 210 212 AT24_CHIP_DATA(at24_data_24c512, 524288 / 8, AT24_FLAG_ADDR16); 211 213 AT24_CHIP_DATA(at24_data_24c1024, 1048576 / 8, AT24_FLAG_ADDR16); 212 214 AT24_CHIP_DATA_BS(at24_data_24c1025, 1048576 / 8, AT24_FLAG_ADDR16, 2); ··· 242 240 { "24cs64", (kernel_ulong_t)&at24_data_24cs64 }, 243 241 { "24c128", (kernel_ulong_t)&at24_data_24c128 }, 244 242 { "24c256", (kernel_ulong_t)&at24_data_24c256 }, 243 + { "24256e-wl", (kernel_ulong_t)&at24_data_24256e_wlp }, 245 244 { "24c512", (kernel_ulong_t)&at24_data_24c512 }, 246 245 { "24c1024", (kernel_ulong_t)&at24_data_24c1024 }, 247 246 { "24c1025", (kernel_ulong_t)&at24_data_24c1025 }, ··· 281 278 { .compatible = "atmel,24c2048", .data = &at24_data_24c2048 }, 282 279 { .compatible = "microchip,24aa025e48", .data = &at24_data_24aa025e48 }, 283 280 { .compatible = "microchip,24aa025e64", .data = &at24_data_24aa025e64 }, 281 + { .compatible = "st,24256e-wl", .data = &at24_data_24256e_wlp }, 284 282 { /* END OF LIST */ }, 285 283 }; 286 284 MODULE_DEVICE_TABLE(of, at24_of_match);