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

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

Pull i2c updates from Wolfram Sang:

- new drivers for HPE GXP and Loongson 2K/LS7A

- bigger refactorings for i801 and xiic

- gpio driver gained ACPI and SDA-write only support

- the core converted some OF helpers to fwnode helpers

- usual bunch of driver updates

* tag 'i2c-for-6.3-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux: (52 commits)
MAINTAINERS: Add HPE GXP I2C Support
i2c: Add GXP SoC I2C Controller
dt-bindings: i2c: Add hpe,gxp-i2c
i2c: xiic: Remove some dead code
i2c: xiic: Add SCL frequency configuration support
i2c: xiic: Update compatible with new IP version
dt-bindings: i2c: xiic: Add 'xlnx,axi-iic-2.1' to compatible
i2c: i801: Call i801_check_post() from i801_access()
i2c: i801: Call i801_check_pre() from i801_access()
i2c: i801: Centralize configuring block commands in i801_block_transaction
i2c: i801: Centralize configuring non-block commands in i801_simple_transaction
i2c: i801: Handle SMBAUXCTL_E32B in i801_block_transaction_by_block only
i2c: i801: Add i801_simple_transaction(), complementing i801_block_transaction()
Documentation: i2c: correct spelling
dt-bindings: i2c: i2c-st: convert to DT schema
i2c: i801: add helper i801_set_hstadd()
i2c: i801: make FEATURE_BLOCK_PROC dependent on FEATURE_BLOCK_BUFFER
i2c: i801: make FEATURE_HOST_NOTIFY dependent on FEATURE_IRQ
i2c: i801: improve interrupt handler
i2c: st: use pm_sleep_ptr to avoid ifdef CONFIG_PM_SLEEP
...

+2129 -397
+59
Documentation/devicetree/bindings/i2c/hpe,gxp-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/hpe,gxp-i2c.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: HPE GXP SoC I2C Controller 8 + 9 + maintainers: 10 + - Nick Hawkins <nick.hawkins@hpe.com> 11 + 12 + allOf: 13 + - $ref: /schemas/i2c/i2c-controller.yaml# 14 + 15 + properties: 16 + compatible: 17 + const: hpe,gxp-i2c 18 + 19 + reg: 20 + maxItems: 1 21 + 22 + interrupts: 23 + maxItems: 1 24 + 25 + clock-frequency: 26 + default: 100000 27 + 28 + hpe,sysreg: 29 + $ref: /schemas/types.yaml#/definitions/phandle 30 + description: 31 + Phandle to the global status and enable interrupt registers shared 32 + between each I2C engine controller instance. It enables the I2C 33 + engine controller to act as both a master or slave by being able to 34 + arm and respond to interrupts from its engine. Each bit in the 35 + registers represent the respective bit position. 36 + 37 + required: 38 + - compatible 39 + - reg 40 + - interrupts 41 + 42 + unevaluatedProperties: false 43 + 44 + examples: 45 + - | 46 + i2c@2600 { 47 + compatible = "hpe,gxp-i2c"; 48 + reg = <0x2500 0x70>; 49 + interrupts = <9>; 50 + #address-cells = <1>; 51 + #size-cells = <0>; 52 + hpe,sysreg = <&sysreg_system_controller>; 53 + clock-frequency = <10000>; 54 + 55 + eeprom@50 { 56 + compatible = "atmel,24c128"; 57 + reg = <0x50>; 58 + }; 59 + };
+26
Documentation/devicetree/bindings/i2c/i2c-gpio.yaml
··· 33 33 open drain. 34 34 maxItems: 1 35 35 36 + i2c-gpio,sda-output-only: 37 + description: sda as output only 38 + type: boolean 39 + 36 40 i2c-gpio,scl-output-only: 37 41 description: scl as output only 38 42 type: boolean ··· 66 62 description: this means that something outside of our control has put the 67 63 GPIO line used for SCL into open drain mode, and that something is not 68 64 the GPIO chip. It is essentially an inconsistency flag. 65 + 66 + i2c-gpio,sda-has-no-pullup: 67 + type: boolean 68 + description: sda is used in a non-compliant way and has no pull-up. 69 + Therefore disable open-drain. This property is mutually-exclusive 70 + with i2c-gpio,sda-open-drain. 71 + 72 + i2c-gpio,scl-has-no-pullup: 73 + type: boolean 74 + description: scl is used in a non-compliant way and has no pull-up. 75 + Therefore disable open-drain. This property is mutually-exclusive 76 + with i2c-gpio,scl-open-drain. 77 + 78 + dependencies: 79 + i2c-gpio,sda-has-no-pullup: 80 + not: 81 + required: 82 + - i2c-gpio,sda-open-drain 83 + i2c-gpio,scl-has-no-pullup: 84 + not: 85 + required: 86 + - i2c-gpio,scl-open-drain 69 87 70 88 required: 71 89 - compatible
+4
Documentation/devicetree/bindings/i2c/i2c-mt65xx.yaml
··· 43 43 - const: mediatek,mt6577-i2c 44 44 - items: 45 45 - enum: 46 + - mediatek,mt8365-i2c 47 + - const: mediatek,mt8168-i2c 48 + - items: 49 + - enum: 46 50 - mediatek,mt8195-i2c 47 51 - const: mediatek,mt8192-i2c 48 52
-41
Documentation/devicetree/bindings/i2c/i2c-st.txt
··· 1 - ST SSC binding, for I2C mode operation 2 - 3 - Required properties : 4 - - compatible : Must be "st,comms-ssc-i2c" or "st,comms-ssc4-i2c" 5 - - reg : Offset and length of the register set for the device 6 - - interrupts : the interrupt specifier 7 - - clock-names: Must contain "ssc". 8 - - clocks: Must contain an entry for each name in clock-names. See the common 9 - clock bindings. 10 - - A pinctrl state named "default" must be defined to set pins in mode of 11 - operation for I2C transfer. 12 - 13 - Optional properties : 14 - - clock-frequency : Desired I2C bus clock frequency in Hz. If not specified, 15 - the default 100 kHz frequency will be used. As only Normal and Fast modes 16 - are supported, possible values are 100000 and 400000. 17 - - st,i2c-min-scl-pulse-width-us : The minimum valid SCL pulse width that is 18 - allowed through the deglitch circuit. In units of us. 19 - - st,i2c-min-sda-pulse-width-us : The minimum valid SDA pulse width that is 20 - allowed through the deglitch circuit. In units of us. 21 - - A pinctrl state named "idle" could be defined to set pins in idle state 22 - when I2C instance is not performing a transfer. 23 - - A pinctrl state named "sleep" could be defined to set pins in sleep state 24 - when driver enters in suspend. 25 - 26 - 27 - 28 - Example : 29 - 30 - i2c0: i2c@fed40000 { 31 - compatible = "st,comms-ssc4-i2c"; 32 - reg = <0xfed40000 0x110>; 33 - interrupts = <GIC_SPI 187 IRQ_TYPE_LEVEL_HIGH>; 34 - clocks = <&clk_s_a0_ls CLK_ICN_REG>; 35 - clock-names = "ssc"; 36 - clock-frequency = <400000>; 37 - pinctrl-names = "default"; 38 - pinctrl-0 = <&pinctrl_i2c0_default>; 39 - st,i2c-min-scl-pulse-width-us = <0>; 40 - st,i2c-min-sda-pulse-width-us = <5>; 41 - };
+51
Documentation/devicetree/bindings/i2c/loongson,ls2x-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/loongson,ls2x-i2c.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Loongson LS2X I2C Controller 8 + 9 + maintainers: 10 + - Binbin Zhou <zhoubinbin@loongson.cn> 11 + 12 + allOf: 13 + - $ref: /schemas/i2c/i2c-controller.yaml# 14 + 15 + properties: 16 + compatible: 17 + enum: 18 + - loongson,ls2k-i2c 19 + - loongson,ls7a-i2c 20 + 21 + reg: 22 + maxItems: 1 23 + 24 + interrupts: 25 + maxItems: 1 26 + 27 + required: 28 + - compatible 29 + - reg 30 + - interrupts 31 + 32 + unevaluatedProperties: false 33 + 34 + examples: 35 + - | 36 + #include <dt-bindings/interrupt-controller/irq.h> 37 + 38 + i2c0: i2c@1fe21000 { 39 + compatible = "loongson,ls2k-i2c"; 40 + reg = <0x1fe21000 0x8>; 41 + interrupt-parent = <&extioiic>; 42 + interrupts = <22 IRQ_TYPE_LEVEL_LOW>; 43 + #address-cells = <1>; 44 + #size-cells = <0>; 45 + 46 + eeprom@57 { 47 + compatible = "atmel,24c16"; 48 + reg = <0x57>; 49 + pagesize = <16>; 50 + }; 51 + };
+32 -17
Documentation/devicetree/bindings/i2c/qcom,i2c-cci.yaml
··· 12 12 13 13 properties: 14 14 compatible: 15 - enum: 16 - - qcom,msm8226-cci 17 - - qcom,msm8916-cci 18 - - qcom,msm8974-cci 19 - - qcom,msm8996-cci 20 - - qcom,sdm845-cci 21 - - qcom,sm8250-cci 22 - - qcom,sm8450-cci 15 + oneOf: 16 + - enum: 17 + - qcom,msm8226-cci 18 + - qcom,msm8974-cci 19 + - qcom,msm8996-cci 20 + 21 + - items: 22 + - enum: 23 + - qcom,msm8916-cci 24 + - const: qcom,msm8226-cci # CCI v1 25 + 26 + - items: 27 + - enum: 28 + - qcom,sdm845-cci 29 + - qcom,sm6350-cci 30 + - qcom,sm8250-cci 31 + - qcom,sm8450-cci 32 + - const: qcom,msm8996-cci # CCI v2 23 33 24 34 "#address-cells": 25 35 const: 1 ··· 98 88 - if: 99 89 properties: 100 90 compatible: 101 - contains: 102 - enum: 103 - - qcom,msm8226-cci 104 - - qcom,msm8974-cci 91 + oneOf: 92 + - contains: 93 + enum: 94 + - qcom,msm8974-cci 95 + 96 + - const: qcom,msm8226-cci 105 97 then: 106 98 properties: 107 99 clocks: ··· 117 105 - if: 118 106 properties: 119 107 compatible: 120 - contains: 121 - enum: 122 - - qcom,msm8916-cci 123 - - qcom,msm8996-cci 108 + oneOf: 109 + - contains: 110 + enum: 111 + - qcom,msm8916-cci 112 + 113 + - const: qcom,msm8996-cci 124 114 then: 125 115 properties: 126 116 clocks: ··· 140 126 contains: 141 127 enum: 142 128 - qcom,sdm845-cci 129 + - qcom,sm6350-cci 143 130 then: 144 131 properties: 145 132 clocks: ··· 184 169 185 170 cci@ac4a000 { 186 171 reg = <0x0ac4a000 0x4000>; 187 - compatible = "qcom,sdm845-cci"; 172 + compatible = "qcom,sdm845-cci", "qcom,msm8996-cci"; 188 173 #address-cells = <1>; 189 174 #size-cells = <0>; 190 175
+3
Documentation/devicetree/bindings/i2c/socionext,uniphier-fi2c.yaml
··· 29 29 minimum: 100000 30 30 maximum: 400000 31 31 32 + resets: 33 + maxItems: 1 34 + 32 35 required: 33 36 - compatible 34 37 - reg
+3
Documentation/devicetree/bindings/i2c/socionext,uniphier-i2c.yaml
··· 29 29 minimum: 100000 30 30 maximum: 400000 31 31 32 + resets: 33 + maxItems: 1 34 + 32 35 required: 33 36 - compatible 34 37 - reg
+71
Documentation/devicetree/bindings/i2c/st,sti-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/st,sti-i2c.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: I2C controller embedded in STMicroelectronics STi platform 8 + 9 + maintainers: 10 + - Patrice Chotard <patrice.chotard@foss.st.com> 11 + 12 + allOf: 13 + - $ref: /schemas/i2c/i2c-controller.yaml# 14 + 15 + properties: 16 + compatible: 17 + enum: 18 + - st,comms-ssc-i2c 19 + - st,comms-ssc4-i2c 20 + 21 + reg: 22 + maxItems: 1 23 + 24 + interrupts: 25 + maxItems: 1 26 + 27 + clocks: 28 + maxItems: 1 29 + 30 + clock-names: 31 + maxItems: 1 32 + 33 + clock-frequency: 34 + enum: [ 100000, 400000 ] 35 + default: 100000 36 + 37 + st,i2c-min-scl-pulse-width-us: 38 + description: 39 + The minimum valid SCL pulse width that is allowed through the 40 + deglitch circuit. In units of us. 41 + 42 + st,i2c-min-sda-pulse-width-us: 43 + description: 44 + The minimum valid SDA pulse width that is allowed through the 45 + deglitch circuit. In units of us. 46 + 47 + required: 48 + - compatible 49 + - reg 50 + - interrupts 51 + - clocks 52 + - clock-names 53 + 54 + unevaluatedProperties: false 55 + 56 + examples: 57 + - | 58 + #include <dt-bindings/interrupt-controller/arm-gic.h> 59 + #include <dt-bindings/clock/stih407-clks.h> 60 + i2c@fed40000 { 61 + compatible = "st,comms-ssc4-i2c"; 62 + reg = <0xfed40000 0x110>; 63 + interrupts = <GIC_SPI 187 IRQ_TYPE_LEVEL_HIGH>; 64 + clocks = <&clk_s_a0_ls CLK_ICN_REG>; 65 + clock-names = "ssc"; 66 + clock-frequency = <400000>; 67 + pinctrl-names = "default"; 68 + pinctrl-0 = <&pinctrl_i2c0_default>; 69 + st,i2c-min-scl-pulse-width-us = <0>; 70 + st,i2c-min-sda-pulse-width-us = <5>; 71 + };
+10 -1
Documentation/devicetree/bindings/i2c/xlnx,xps-iic-2.00.a.yaml
··· 14 14 15 15 properties: 16 16 compatible: 17 - const: xlnx,xps-iic-2.00.a 17 + enum: 18 + - xlnx,axi-iic-2.1 19 + - xlnx,xps-iic-2.00.a 18 20 19 21 reg: 20 22 maxItems: 1 ··· 31 29 const: pclk 32 30 description: | 33 31 Input clock name. 32 + 33 + clock-frequency: 34 + description: 35 + Optional I2C SCL clock frequency. If not specified, do not configure 36 + in software, rely only on hardware design value. 37 + default: 100000 38 + enum: [ 100000, 400000, 1000000 ] 34 39 35 40 required: 36 41 - compatible
+1 -1
Documentation/i2c/gpio-fault-injection.rst
··· 93 93 ------------------ 94 94 95 95 This file is write only and you need to write the duration of the arbitration 96 - intereference (in µs, maximum is 100ms). The calling process will then sleep 96 + interference (in µs, maximum is 100ms). The calling process will then sleep 97 97 and wait for the next bus clock. The process is interruptible, though. 98 98 99 99 Arbitration lost is achieved by waiting for SCL going down by the master under
+1 -1
Documentation/i2c/smbus-protocol.rst
··· 238 238 * I2C bus drivers trigger SMBus Host Notify by a call to 239 239 i2c_handle_smbus_host_notify(). 240 240 * I2C drivers for devices which can trigger SMBus Host Notify will have 241 - client->irq assigned to a Host Notify IRQ if noone else specified an other. 241 + client->irq assigned to a Host Notify IRQ if no one else specified another. 242 242 243 243 There is currently no way to retrieve the data parameter from the client. 244 244
+10 -1
MAINTAINERS
··· 2240 2240 F: Documentation/hwmon/gxp-fan-ctrl.rst 2241 2241 F: Documentation/devicetree/bindings/arm/hpe,gxp.yaml 2242 2242 F: Documentation/devicetree/bindings/hwmon/hpe,gxp-fan-ctrl.yaml 2243 + F: Documentation/devicetree/bindings/i2c/hpe,gxp-i2c.yaml 2243 2244 F: Documentation/devicetree/bindings/spi/hpe,gxp-spifi.yaml 2244 2245 F: Documentation/devicetree/bindings/timer/hpe,gxp-timer.yaml 2245 2246 F: arch/arm/boot/dts/hpe-bmc* ··· 2248 2247 F: arch/arm/mach-hpe/ 2249 2248 F: drivers/clocksource/timer-gxp.c 2250 2249 F: drivers/hwmon/gxp-fan-ctrl.c 2250 + F: drivers/i2c/busses/i2c-gxp.c 2251 2251 F: drivers/spi/spi-gxp.c 2252 2252 F: drivers/watchdog/gxp-wdt.c 2253 2253 ··· 2797 2795 S: Maintained 2798 2796 W: http://www.stlinux.com 2799 2797 F: Documentation/devicetree/bindings/spi/st,ssc-spi.yaml 2800 - F: Documentation/devicetree/bindings/i2c/i2c-st.txt 2798 + F: Documentation/devicetree/bindings/i2c/st,sti-i2c.yaml 2801 2799 F: arch/arm/boot/dts/sti* 2802 2800 F: arch/arm/mach-sti/ 2803 2801 F: drivers/ata/ahci_st.c ··· 12098 12096 F: drivers/*/*loongarch* 12099 12097 F: Documentation/loongarch/ 12100 12098 F: Documentation/translations/zh_CN/loongarch/ 12099 + 12100 + LOONGSON LS2X I2C DRIVER 12101 + M: Binbin Zhou <zhoubinbin@loongson.cn> 12102 + L: linux-i2c@vger.kernel.org 12103 + S: Maintained 12104 + F: Documentation/devicetree/bindings/i2c/loongson,ls2x-i2c.yaml 12105 + F: drivers/i2c/busses/i2c-ls2x.c 12101 12106 12102 12107 LOONGSON-2 SOC SERIES GUTS DRIVER 12103 12108 M: Yinbo Zhu <zhuyinbo@loongson.cn>
+35 -42
drivers/i2c/algos/i2c-algo-bit.c
··· 184 184 185 185 /* read ack: SDA should be pulled down by slave, or it may 186 186 * NAK (usually to report problems with the data we wrote). 187 + * Always report ACK if SDA is write-only. 187 188 */ 188 - ack = !getsda(adap); /* ack: sda is pulled low -> success */ 189 + ack = !adap->getsda || !getsda(adap); /* ack: sda is pulled low -> success */ 189 190 bit_dbg(2, &i2c_adap->dev, "i2c_outb: 0x%02x %s\n", (int)c, 190 191 ack ? "A" : "NA"); 191 192 ··· 239 238 return -ENODEV; 240 239 } 241 240 241 + if (adap->getsda == NULL) 242 + pr_info("%s: SDA is write-only, testing not possible\n", name); 242 243 if (adap->getscl == NULL) 243 - pr_info("%s: Testing SDA only, SCL is not readable\n", name); 244 + pr_info("%s: SCL is write-only, testing not possible\n", name); 244 245 245 - sda = getsda(adap); 246 - scl = (adap->getscl == NULL) ? 1 : getscl(adap); 246 + sda = adap->getsda ? getsda(adap) : 1; 247 + scl = adap->getscl ? getscl(adap) : 1; 247 248 if (!scl || !sda) { 248 - printk(KERN_WARNING 249 - "%s: bus seems to be busy (scl=%d, sda=%d)\n", 250 - name, scl, sda); 249 + pr_warn("%s: bus seems to be busy (scl=%d, sda=%d)\n", name, scl, sda); 251 250 goto bailout; 252 251 } 253 252 254 253 sdalo(adap); 255 - sda = getsda(adap); 256 - scl = (adap->getscl == NULL) ? 1 : getscl(adap); 257 - if (sda) { 258 - printk(KERN_WARNING "%s: SDA stuck high!\n", name); 254 + if (adap->getsda && getsda(adap)) { 255 + pr_warn("%s: SDA stuck high!\n", name); 259 256 goto bailout; 260 257 } 261 - if (!scl) { 262 - printk(KERN_WARNING 263 - "%s: SCL unexpected low while pulling SDA low!\n", 264 - name); 258 + if (adap->getscl && !getscl(adap)) { 259 + pr_warn("%s: SCL unexpected low while pulling SDA low!\n", name); 265 260 goto bailout; 266 261 } 267 262 268 263 sdahi(adap); 269 - sda = getsda(adap); 270 - scl = (adap->getscl == NULL) ? 1 : getscl(adap); 271 - if (!sda) { 272 - printk(KERN_WARNING "%s: SDA stuck low!\n", name); 264 + if (adap->getsda && !getsda(adap)) { 265 + pr_warn("%s: SDA stuck low!\n", name); 273 266 goto bailout; 274 267 } 275 - if (!scl) { 276 - printk(KERN_WARNING 277 - "%s: SCL unexpected low while pulling SDA high!\n", 278 - name); 268 + if (adap->getscl && !getscl(adap)) { 269 + pr_warn("%s: SCL unexpected low while pulling SDA high!\n", name); 279 270 goto bailout; 280 271 } 281 272 282 273 scllo(adap); 283 - sda = getsda(adap); 284 - scl = (adap->getscl == NULL) ? 0 : getscl(adap); 285 - if (scl) { 286 - printk(KERN_WARNING "%s: SCL stuck high!\n", name); 274 + if (adap->getscl && getscl(adap)) { 275 + pr_warn("%s: SCL stuck high!\n", name); 287 276 goto bailout; 288 277 } 289 - if (!sda) { 290 - printk(KERN_WARNING 291 - "%s: SDA unexpected low while pulling SCL low!\n", 292 - name); 278 + if (adap->getsda && !getsda(adap)) { 279 + pr_warn("%s: SDA unexpected low while pulling SCL low!\n", name); 293 280 goto bailout; 294 281 } 295 282 296 283 sclhi(adap); 297 - sda = getsda(adap); 298 - scl = (adap->getscl == NULL) ? 1 : getscl(adap); 299 - if (!scl) { 300 - printk(KERN_WARNING "%s: SCL stuck low!\n", name); 284 + if (adap->getscl && !getscl(adap)) { 285 + pr_warn("%s: SCL stuck low!\n", name); 301 286 goto bailout; 302 287 } 303 - if (!sda) { 304 - printk(KERN_WARNING 305 - "%s: SDA unexpected low while pulling SCL high!\n", 306 - name); 288 + if (adap->getsda && !getsda(adap)) { 289 + pr_warn("%s: SDA unexpected low while pulling SCL high!\n", name); 307 290 goto bailout; 308 291 } 309 292 ··· 405 420 unsigned char *temp = msg->buf; 406 421 int count = msg->len; 407 422 const unsigned flags = msg->flags; 423 + struct i2c_algo_bit_data *adap = i2c_adap->algo_data; 424 + 425 + if (!adap->getsda) 426 + return -EOPNOTSUPP; 408 427 409 428 while (count > 0) { 410 429 inval = i2c_inb(i2c_adap); ··· 659 670 if (ret < 0) 660 671 return ret; 661 672 662 - /* Complain if SCL can't be read */ 663 - if (bit_adap->getscl == NULL) { 673 + if (bit_adap->getsda == NULL) 674 + dev_warn(&adap->dev, "Not I2C compliant: can't read SDA\n"); 675 + 676 + if (bit_adap->getscl == NULL) 664 677 dev_warn(&adap->dev, "Not I2C compliant: can't read SCL\n"); 678 + 679 + if (bit_adap->getsda == NULL || bit_adap->getscl == NULL) 665 680 dev_warn(&adap->dev, "Bus may be unreliable\n"); 666 - } 681 + 667 682 return 0; 668 683 } 669 684
+18
drivers/i2c/busses/Kconfig
··· 659 659 faults to an I2C bus, so another bus master can be stress-tested. 660 660 This is for debugging. If unsure, say 'no'. 661 661 662 + config I2C_GXP 663 + tristate "GXP I2C Interface" 664 + depends on ARCH_HPE_GXP || COMPILE_TEST 665 + help 666 + This enables support for GXP I2C interface. The I2C engines can be 667 + either I2C master or I2C slaves. 668 + 662 669 config I2C_HIGHLANDER 663 670 tristate "Highlander FPGA SMBus interface" 664 671 depends on SH_HIGHLANDER || COMPILE_TEST ··· 767 760 768 761 This driver can also be built as a module. If so, the module 769 762 will be called i2c-lpc2k. 763 + 764 + config I2C_LS2X 765 + tristate "Loongson LS2X I2C adapter" 766 + depends on MACH_LOONGSON64 || COMPILE_TEST 767 + help 768 + If you say yes to this option, support will be included for the 769 + I2C interface on the Loongson-2K SoCs and Loongson LS7A bridge 770 + chip. 771 + 772 + This driver can also be built as a module. If so, the module 773 + will be called i2c-ls2x. 770 774 771 775 config I2C_MLXBF 772 776 tristate "Mellanox BlueField I2C controller"
+2
drivers/i2c/busses/Makefile
··· 77 77 obj-$(CONFIG_I2C_JZ4780) += i2c-jz4780.o 78 78 obj-$(CONFIG_I2C_KEMPLD) += i2c-kempld.o 79 79 obj-$(CONFIG_I2C_LPC2K) += i2c-lpc2k.o 80 + obj-$(CONFIG_I2C_LS2X) += i2c-ls2x.o 80 81 obj-$(CONFIG_I2C_MESON) += i2c-meson.o 81 82 obj-$(CONFIG_I2C_MICROCHIP_CORE) += i2c-microchip-corei2c.o 82 83 obj-$(CONFIG_I2C_MPC) += i2c-mpc.o ··· 128 127 obj-$(CONFIG_I2C_XILINX) += i2c-xiic.o 129 128 obj-$(CONFIG_I2C_XLP9XX) += i2c-xlp9xx.o 130 129 obj-$(CONFIG_I2C_RCAR) += i2c-rcar.o 130 + obj-$(CONFIG_I2C_GXP) += i2c-gxp.o 131 131 132 132 # External I2C/SMBus adapter drivers 133 133 obj-$(CONFIG_I2C_DIOLAN_U2C) += i2c-diolan-u2c.o
+1 -3
drivers/i2c/busses/i2c-aspeed.c
··· 979 979 const struct of_device_id *match; 980 980 struct aspeed_i2c_bus *bus; 981 981 struct clk *parent_clk; 982 - struct resource *res; 983 982 int irq, ret; 984 983 985 984 bus = devm_kzalloc(&pdev->dev, sizeof(*bus), GFP_KERNEL); 986 985 if (!bus) 987 986 return -ENOMEM; 988 987 989 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 990 - bus->base = devm_ioremap_resource(&pdev->dev, res); 988 + bus->base = devm_platform_get_and_ioremap_resource(pdev, 0, NULL); 991 989 if (IS_ERR(bus->base)) 992 990 return PTR_ERR(bus->base); 993 991
+1 -3
drivers/i2c/busses/i2c-au1550.c
··· 302 302 i2c_au1550_probe(struct platform_device *pdev) 303 303 { 304 304 struct i2c_au1550_data *priv; 305 - struct resource *r; 306 305 int ret; 307 306 308 307 priv = devm_kzalloc(&pdev->dev, sizeof(struct i2c_au1550_data), ··· 309 310 if (!priv) 310 311 return -ENOMEM; 311 312 312 - r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 313 - priv->psc_base = devm_ioremap_resource(&pdev->dev, r); 313 + priv->psc_base = devm_platform_get_and_ioremap_resource(pdev, 0, NULL); 314 314 if (IS_ERR(priv->psc_base)) 315 315 return PTR_ERR(priv->psc_base); 316 316
+1 -3
drivers/i2c/busses/i2c-bcm2835.c
··· 407 407 static int bcm2835_i2c_probe(struct platform_device *pdev) 408 408 { 409 409 struct bcm2835_i2c_dev *i2c_dev; 410 - struct resource *mem; 411 410 int ret; 412 411 struct i2c_adapter *adap; 413 412 struct clk *mclk; ··· 419 420 i2c_dev->dev = &pdev->dev; 420 421 init_completion(&i2c_dev->completion); 421 422 422 - mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 423 - i2c_dev->regs = devm_ioremap_resource(&pdev->dev, mem); 423 + i2c_dev->regs = devm_platform_get_and_ioremap_resource(pdev, 0, NULL); 424 424 if (IS_ERR(i2c_dev->regs)) 425 425 return PTR_ERR(i2c_dev->regs); 426 426
+8 -15
drivers/i2c/busses/i2c-cadence.c
··· 115 115 #define CNDS_I2C_PM_TIMEOUT 1000 /* ms */ 116 116 117 117 #define CDNS_I2C_FIFO_DEPTH 16 118 - /* FIFO depth at which the DATA interrupt occurs */ 119 - #define CDNS_I2C_DATA_INTR_DEPTH (CDNS_I2C_FIFO_DEPTH - 2) 120 118 #define CDNS_I2C_MAX_TRANSFER_SIZE 255 121 119 /* Transfer size in multiples of data interrupt depth */ 122 120 #define CDNS_I2C_TRANSFER_SIZE (CDNS_I2C_MAX_TRANSFER_SIZE - 3) ··· 173 175 * @send_count: Number of bytes still expected to send 174 176 * @recv_count: Number of bytes still expected to receive 175 177 * @curr_recv_count: Number of bytes to be received in current transfer 176 - * @irq: IRQ number 177 178 * @input_clk: Input clock to I2C controller 178 179 * @i2c_clk: Maximum I2C clock speed 179 180 * @bus_hold_flag: Flag used in repeated start for clearing HOLD bit ··· 197 200 unsigned int send_count; 198 201 unsigned int recv_count; 199 202 unsigned int curr_recv_count; 200 - int irq; 201 203 unsigned long input_clk; 202 204 unsigned int i2c_clk; 203 205 unsigned int bus_hold_flag; ··· 612 616 } 613 617 614 618 /* Determine hold_clear based on number of bytes to receive and hold flag */ 615 - if (!id->bus_hold_flag && 616 - ((id->p_msg->flags & I2C_M_RECV_LEN) != I2C_M_RECV_LEN) && 617 - (id->recv_count <= CDNS_I2C_FIFO_DEPTH)) { 619 + if (!id->bus_hold_flag && id->recv_count <= CDNS_I2C_FIFO_DEPTH) { 618 620 if (cdns_i2c_readreg(CDNS_I2C_CR_OFFSET) & CDNS_I2C_CR_HOLD) { 619 621 hold_clear = true; 620 622 if (id->quirks & CDNS_I2C_BROKEN_HOLD_BIT) ··· 1240 1246 { 1241 1247 struct resource *r_mem; 1242 1248 struct cdns_i2c *id; 1243 - int ret; 1249 + int ret, irq; 1244 1250 const struct of_device_id *match; 1245 1251 1246 1252 id = devm_kzalloc(&pdev->dev, sizeof(*id), GFP_KERNEL); ··· 1271 1277 if (IS_ERR(id->membase)) 1272 1278 return PTR_ERR(id->membase); 1273 1279 1274 - ret = platform_get_irq(pdev, 0); 1275 - if (ret < 0) 1276 - return ret; 1277 - id->irq = ret; 1280 + irq = platform_get_irq(pdev, 0); 1281 + if (irq < 0) 1282 + return irq; 1278 1283 1279 1284 id->adap.owner = THIS_MODULE; 1280 1285 id->adap.dev.of_node = pdev->dev.of_node; ··· 1324 1331 goto err_clk_dis; 1325 1332 } 1326 1333 1327 - ret = devm_request_irq(&pdev->dev, id->irq, cdns_i2c_isr, 0, 1334 + ret = devm_request_irq(&pdev->dev, irq, cdns_i2c_isr, 0, 1328 1335 DRIVER_NAME, id); 1329 1336 if (ret) { 1330 - dev_err(&pdev->dev, "cannot get irq %d\n", id->irq); 1337 + dev_err(&pdev->dev, "cannot get irq %d\n", irq); 1331 1338 goto err_clk_dis; 1332 1339 } 1333 1340 cdns_i2c_init(id); ··· 1337 1344 goto err_clk_dis; 1338 1345 1339 1346 dev_info(&pdev->dev, "%u kHz mmio %08lx irq %d\n", 1340 - id->i2c_clk / 1000, (unsigned long)r_mem->start, id->irq); 1347 + id->i2c_clk / 1000, (unsigned long)r_mem->start, irq); 1341 1348 1342 1349 return 0; 1343 1350
+7 -6
drivers/i2c/busses/i2c-designware-common.c
··· 391 391 392 392 int i2c_dw_set_sda_hold(struct dw_i2c_dev *dev) 393 393 { 394 - u32 reg; 394 + unsigned int reg; 395 395 int ret; 396 396 397 397 ret = i2c_dw_acquire_lock(dev); ··· 442 442 void __i2c_dw_disable(struct dw_i2c_dev *dev) 443 443 { 444 444 int timeout = 100; 445 - u32 status; 445 + unsigned int status; 446 446 447 447 do { 448 448 __i2c_dw_disable_nowait(dev); ··· 465 465 dev_warn(dev->dev, "timeout in disabling adapter\n"); 466 466 } 467 467 468 - unsigned long i2c_dw_clk_rate(struct dw_i2c_dev *dev) 468 + u32 i2c_dw_clk_rate(struct dw_i2c_dev *dev) 469 469 { 470 470 /* 471 471 * Clock is not necessary if we got LCNT/HCNT values directly from ··· 527 527 */ 528 528 int i2c_dw_wait_bus_not_busy(struct dw_i2c_dev *dev) 529 529 { 530 - u32 status; 530 + unsigned int status; 531 531 int ret; 532 532 533 533 ret = regmap_read_poll_timeout(dev->map, DW_IC_STATUS, status, ··· 571 571 572 572 int i2c_dw_set_fifo_size(struct dw_i2c_dev *dev) 573 573 { 574 - u32 param, tx_fifo_depth, rx_fifo_depth; 574 + u32 tx_fifo_depth, rx_fifo_depth; 575 + unsigned int param; 575 576 int ret; 576 577 577 578 /* ··· 612 611 613 612 void i2c_dw_disable(struct dw_i2c_dev *dev) 614 613 { 615 - u32 dummy; 614 + unsigned int dummy; 616 615 int ret; 617 616 618 617 ret = i2c_dw_acquire_lock(dev);
+3 -2
drivers/i2c/busses/i2c-designware-core.h
··· 37 37 #define DW_IC_CON_STOP_DET_IFADDRESSED BIT(7) 38 38 #define DW_IC_CON_TX_EMPTY_CTRL BIT(8) 39 39 #define DW_IC_CON_RX_FIFO_FULL_HLD_CTRL BIT(9) 40 + #define DW_IC_CON_BUS_CLEAR_CTRL BIT(11) 40 41 41 42 #define DW_IC_DATA_CMD_DAT GENMASK(7, 0) 42 43 ··· 265 264 u8 *rx_buf; 266 265 int msg_err; 267 266 unsigned int status; 268 - u32 abort_source; 267 + unsigned int abort_source; 269 268 int irq; 270 269 u32 flags; 271 270 struct i2c_adapter adapter; ··· 321 320 u32 i2c_dw_scl_hcnt(u32 ic_clk, u32 tSYMBOL, u32 tf, int cond, int offset); 322 321 u32 i2c_dw_scl_lcnt(u32 ic_clk, u32 tLOW, u32 tf, int offset); 323 322 int i2c_dw_set_sda_hold(struct dw_i2c_dev *dev); 324 - unsigned long i2c_dw_clk_rate(struct dw_i2c_dev *dev); 323 + u32 i2c_dw_clk_rate(struct dw_i2c_dev *dev); 325 324 int i2c_dw_prepare_clk(struct dw_i2c_dev *dev, bool prepare); 326 325 int i2c_dw_acquire_lock(struct dw_i2c_dev *dev); 327 326 void i2c_dw_release_lock(struct dw_i2c_dev *dev);
+27 -6
drivers/i2c/busses/i2c-designware-master.c
··· 39 39 40 40 static int i2c_dw_set_timings_master(struct dw_i2c_dev *dev) 41 41 { 42 - u32 comp_param1; 42 + unsigned int comp_param1; 43 43 u32 sda_falling_time, scl_falling_time; 44 44 struct i2c_timings *t = &dev->timings; 45 45 const char *fp_str = ""; ··· 211 211 { 212 212 struct i2c_msg *msgs = dev->msgs; 213 213 u32 ic_con = 0, ic_tar = 0; 214 - u32 dummy; 214 + unsigned int dummy; 215 215 216 216 /* Disable the adapter */ 217 217 __i2c_dw_disable(dev); ··· 287 287 int msg_wrt_idx, msg_itr_lmt, buf_len, data_idx; 288 288 int cmd = 0, status; 289 289 u8 *tx_buf; 290 - u32 val; 290 + unsigned int val; 291 291 292 292 /* 293 293 * In order to enable the interrupt for UCSI i.e. AMD NAVI GPU card, ··· 505 505 unsigned int rx_valid; 506 506 507 507 for (; dev->msg_read_idx < dev->msgs_num; dev->msg_read_idx++) { 508 - u32 len, tmp; 508 + unsigned int tmp; 509 + u32 len; 509 510 u8 *buf; 510 511 511 512 if (!(msgs[dev->msg_read_idx].flags & I2C_M_RD)) ··· 654 653 655 654 static u32 i2c_dw_read_clear_intrbits(struct dw_i2c_dev *dev) 656 655 { 657 - u32 stat, dummy; 656 + unsigned int stat, dummy; 658 657 659 658 /* 660 659 * The IC_INTR_STAT register just indicates "enabled" interrupts. ··· 715 714 static irqreturn_t i2c_dw_isr(int this_irq, void *dev_id) 716 715 { 717 716 struct dw_i2c_dev *dev = dev_id; 718 - u32 stat, enabled; 717 + unsigned int stat, enabled; 719 718 720 719 regmap_read(dev->map, DW_IC_ENABLE, &enabled); 721 720 regmap_read(dev->map, DW_IC_RAW_INTR_STAT, &stat); ··· 866 865 { 867 866 struct i2c_adapter *adap = &dev->adapter; 868 867 unsigned long irq_flags; 868 + unsigned int ic_con; 869 869 int ret; 870 870 871 871 init_completion(&dev->cmd_complete); ··· 885 883 ret = i2c_dw_set_fifo_size(dev); 886 884 if (ret) 887 885 return ret; 886 + 887 + /* Lock the bus for accessing DW_IC_CON */ 888 + ret = i2c_dw_acquire_lock(dev); 889 + if (ret) 890 + return ret; 891 + 892 + /* 893 + * On AMD platforms BIOS advertises the bus clear feature 894 + * and enables the SCL/SDA stuck low. SMU FW does the 895 + * bus recovery process. Driver should not ignore this BIOS 896 + * advertisement of bus clear feature. 897 + */ 898 + ret = regmap_read(dev->map, DW_IC_CON, &ic_con); 899 + i2c_dw_release_lock(dev); 900 + if (ret) 901 + return ret; 902 + 903 + if (ic_con & DW_IC_CON_BUS_CLEAR_CTRL) 904 + dev->master_cfg |= DW_IC_CON_BUS_CLEAR_CTRL; 888 905 889 906 ret = dev->init(dev); 890 907 if (ret)
+2 -2
drivers/i2c/busses/i2c-designware-slave.c
··· 98 98 99 99 static u32 i2c_dw_read_clear_intrbits_slave(struct dw_i2c_dev *dev) 100 100 { 101 - u32 stat, dummy; 101 + unsigned int stat, dummy; 102 102 103 103 /* 104 104 * The IC_INTR_STAT register just indicates "enabled" interrupts. ··· 150 150 static irqreturn_t i2c_dw_isr_slave(int this_irq, void *dev_id) 151 151 { 152 152 struct dw_i2c_dev *dev = dev_id; 153 - u32 raw_stat, stat, enabled, tmp; 153 + unsigned int raw_stat, stat, enabled, tmp; 154 154 u8 val = 0, slave_activity; 155 155 156 156 regmap_read(dev->map, DW_IC_ENABLE, &enabled);
+31 -16
drivers/i2c/busses/i2c-gpio.c
··· 13 13 #include <linux/init.h> 14 14 #include <linux/interrupt.h> 15 15 #include <linux/module.h> 16 - #include <linux/of.h> 17 16 #include <linux/platform_data/i2c-gpio.h> 18 17 #include <linux/platform_device.h> 18 + #include <linux/property.h> 19 19 #include <linux/slab.h> 20 20 21 21 struct i2c_gpio_private_data { ··· 300 300 static inline void i2c_gpio_fault_injector_exit(struct platform_device *pdev) {} 301 301 #endif /* CONFIG_I2C_GPIO_FAULT_INJECTOR*/ 302 302 303 - static void of_i2c_gpio_get_props(struct device_node *np, 304 - struct i2c_gpio_platform_data *pdata) 303 + /* Get i2c-gpio properties from DT or ACPI table */ 304 + static void i2c_gpio_get_properties(struct device *dev, 305 + struct i2c_gpio_platform_data *pdata) 305 306 { 306 307 u32 reg; 307 308 308 - of_property_read_u32(np, "i2c-gpio,delay-us", &pdata->udelay); 309 + device_property_read_u32(dev, "i2c-gpio,delay-us", &pdata->udelay); 309 310 310 - if (!of_property_read_u32(np, "i2c-gpio,timeout-ms", &reg)) 311 + if (!device_property_read_u32(dev, "i2c-gpio,timeout-ms", &reg)) 311 312 pdata->timeout = msecs_to_jiffies(reg); 312 313 313 314 pdata->sda_is_open_drain = 314 - of_property_read_bool(np, "i2c-gpio,sda-open-drain"); 315 + device_property_read_bool(dev, "i2c-gpio,sda-open-drain"); 315 316 pdata->scl_is_open_drain = 316 - of_property_read_bool(np, "i2c-gpio,scl-open-drain"); 317 + device_property_read_bool(dev, "i2c-gpio,scl-open-drain"); 317 318 pdata->scl_is_output_only = 318 - of_property_read_bool(np, "i2c-gpio,scl-output-only"); 319 + device_property_read_bool(dev, "i2c-gpio,scl-output-only"); 320 + pdata->sda_is_output_only = 321 + device_property_read_bool(dev, "i2c-gpio,sda-output-only"); 322 + pdata->sda_has_no_pullup = 323 + device_property_read_bool(dev, "i2c-gpio,sda-has-no-pullup"); 324 + pdata->scl_has_no_pullup = 325 + device_property_read_bool(dev, "i2c-gpio,scl-has-no-pullup"); 319 326 } 320 327 321 328 static struct gpio_desc *i2c_gpio_get_desc(struct device *dev, ··· 368 361 struct i2c_algo_bit_data *bit_data; 369 362 struct i2c_adapter *adap; 370 363 struct device *dev = &pdev->dev; 371 - struct device_node *np = dev->of_node; 364 + struct fwnode_handle *fwnode = dev_fwnode(dev); 372 365 enum gpiod_flags gflags; 373 366 int ret; 374 367 ··· 380 373 bit_data = &priv->bit_data; 381 374 pdata = &priv->pdata; 382 375 383 - if (np) { 384 - of_i2c_gpio_get_props(np, pdata); 376 + if (fwnode) { 377 + i2c_gpio_get_properties(dev, pdata); 385 378 } else { 386 379 /* 387 380 * If all platform data settings are zero it is OK ··· 399 392 * handle them as we handle any other output. Else we enforce open 400 393 * drain as this is required for an I2C bus. 401 394 */ 402 - if (pdata->sda_is_open_drain) 395 + if (pdata->sda_is_open_drain || pdata->sda_has_no_pullup) 403 396 gflags = GPIOD_OUT_HIGH; 404 397 else 405 398 gflags = GPIOD_OUT_HIGH_OPEN_DRAIN; ··· 407 400 if (IS_ERR(priv->sda)) 408 401 return PTR_ERR(priv->sda); 409 402 410 - if (pdata->scl_is_open_drain) 403 + if (pdata->scl_is_open_drain || pdata->scl_has_no_pullup) 411 404 gflags = GPIOD_OUT_HIGH; 412 405 else 413 406 gflags = GPIOD_OUT_HIGH_OPEN_DRAIN; ··· 425 418 426 419 if (!pdata->scl_is_output_only) 427 420 bit_data->getscl = i2c_gpio_getscl; 428 - bit_data->getsda = i2c_gpio_getsda; 421 + if (!pdata->sda_is_output_only) 422 + bit_data->getsda = i2c_gpio_getsda; 429 423 430 424 if (pdata->udelay) 431 425 bit_data->udelay = pdata->udelay; ··· 443 435 bit_data->data = priv; 444 436 445 437 adap->owner = THIS_MODULE; 446 - if (np) 438 + if (fwnode) 447 439 strscpy(adap->name, dev_name(dev), sizeof(adap->name)); 448 440 else 449 441 snprintf(adap->name, sizeof(adap->name), "i2c-gpio%d", pdev->id); ··· 451 443 adap->algo_data = bit_data; 452 444 adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD; 453 445 adap->dev.parent = dev; 454 - adap->dev.of_node = np; 446 + device_set_node(&adap->dev, fwnode); 455 447 456 448 adap->nr = pdev->id; 457 449 ret = i2c_bit_add_numbered_bus(adap); ··· 497 489 498 490 MODULE_DEVICE_TABLE(of, i2c_gpio_dt_ids); 499 491 492 + static const struct acpi_device_id i2c_gpio_acpi_match[] = { 493 + { "LOON0005" }, /* LoongArch */ 494 + { } 495 + }; 496 + MODULE_DEVICE_TABLE(acpi, i2c_gpio_acpi_match); 497 + 500 498 static struct platform_driver i2c_gpio_driver = { 501 499 .driver = { 502 500 .name = "i2c-gpio", 503 501 .of_match_table = i2c_gpio_dt_ids, 502 + .acpi_match_table = i2c_gpio_acpi_match, 504 503 }, 505 504 .probe = i2c_gpio_probe, 506 505 .remove = i2c_gpio_remove,
+620
drivers/i2c/busses/i2c-gxp.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* Copyright (C) 2022 Hewlett-Packard Enterprise Development Company, L.P. */ 3 + 4 + #include <linux/err.h> 5 + #include <linux/io.h> 6 + #include <linux/i2c.h> 7 + #include <linux/module.h> 8 + #include <linux/of_device.h> 9 + #include <linux/regmap.h> 10 + #include <linux/mfd/syscon.h> 11 + 12 + #define GXP_MAX_I2C_ENGINE 10 13 + static const char * const gxp_i2c_name[] = { 14 + "gxp-i2c0", "gxp-i2c1", "gxp-i2c2", "gxp-i2c3", 15 + "gxp-i2c4", "gxp-i2c5", "gxp-i2c6", "gxp-i2c7", 16 + "gxp-i2c8", "gxp-i2c9" }; 17 + 18 + /* GXP I2C Global interrupt status/enable register*/ 19 + #define GXP_I2CINTSTAT 0x00 20 + #define GXP_I2CINTEN 0x04 21 + 22 + /* GXP I2C registers */ 23 + #define GXP_I2CSTAT 0x00 24 + #define MASK_STOP_EVENT 0x20 25 + #define MASK_ACK 0x08 26 + #define MASK_RW 0x04 27 + #define GXP_I2CEVTERR 0x01 28 + #define MASK_SLAVE_CMD_EVENT 0x01 29 + #define MASK_SLAVE_DATA_EVENT 0x02 30 + #define MASK_MASTER_EVENT 0x10 31 + #define GXP_I2CSNPDAT 0x02 32 + #define GXP_I2CMCMD 0x04 33 + #define GXP_I2CSCMD 0x06 34 + #define GXP_I2CSNPAA 0x09 35 + #define GXP_I2CADVFEAT 0x0A 36 + #define GXP_I2COWNADR 0x0B 37 + #define GXP_I2CFREQDIV 0x0C 38 + #define GXP_I2CFLTFAIR 0x0D 39 + #define GXP_I2CTMOEDG 0x0E 40 + #define GXP_I2CCYCTIM 0x0F 41 + 42 + /* I2CSCMD Bits */ 43 + #define SNOOP_EVT_CLR 0x80 44 + #define SLAVE_EVT_CLR 0x40 45 + #define SNOOP_EVT_MASK 0x20 46 + #define SLAVE_EVT_MASK 0x10 47 + #define SLAVE_ACK_ENAB 0x08 48 + #define SLAVE_EVT_STALL 0x01 49 + 50 + /* I2CMCMD Bits */ 51 + #define MASTER_EVT_CLR 0x80 52 + #define MASTER_ACK_ENAB 0x08 53 + #define RW_CMD 0x04 54 + #define STOP_CMD 0x02 55 + #define START_CMD 0x01 56 + 57 + /* I2CTMOEDG value */ 58 + #define GXP_DATA_EDGE_RST_CTRL 0x0a /* 30ns */ 59 + 60 + /* I2CFLTFAIR Bits */ 61 + #define FILTER_CNT 0x30 62 + #define FAIRNESS_CNT 0x02 63 + 64 + enum { 65 + GXP_I2C_IDLE = 0, 66 + GXP_I2C_ADDR_PHASE, 67 + GXP_I2C_RDATA_PHASE, 68 + GXP_I2C_WDATA_PHASE, 69 + GXP_I2C_ADDR_NACK, 70 + GXP_I2C_DATA_NACK, 71 + GXP_I2C_ERROR, 72 + GXP_I2C_COMP 73 + }; 74 + 75 + struct gxp_i2c_drvdata { 76 + struct device *dev; 77 + void __iomem *base; 78 + struct i2c_timings t; 79 + u32 engine; 80 + int irq; 81 + struct completion completion; 82 + struct i2c_adapter adapter; 83 + struct i2c_msg *curr_msg; 84 + int msgs_remaining; 85 + int msgs_num; 86 + u8 *buf; 87 + size_t buf_remaining; 88 + unsigned char state; 89 + struct i2c_client *slave; 90 + unsigned char stopped; 91 + }; 92 + 93 + static struct regmap *i2cg_map; 94 + 95 + static void gxp_i2c_start(struct gxp_i2c_drvdata *drvdata) 96 + { 97 + u16 value; 98 + 99 + drvdata->buf = drvdata->curr_msg->buf; 100 + drvdata->buf_remaining = drvdata->curr_msg->len; 101 + 102 + /* Note: Address in struct i2c_msg is 7 bits */ 103 + value = drvdata->curr_msg->addr << 9; 104 + 105 + /* Read or Write */ 106 + value |= drvdata->curr_msg->flags & I2C_M_RD ? RW_CMD | START_CMD : START_CMD; 107 + 108 + drvdata->state = GXP_I2C_ADDR_PHASE; 109 + writew(value, drvdata->base + GXP_I2CMCMD); 110 + } 111 + 112 + static int gxp_i2c_master_xfer(struct i2c_adapter *adapter, 113 + struct i2c_msg *msgs, int num) 114 + { 115 + int ret; 116 + struct gxp_i2c_drvdata *drvdata = i2c_get_adapdata(adapter); 117 + unsigned long time_left; 118 + 119 + drvdata->msgs_remaining = num; 120 + drvdata->curr_msg = msgs; 121 + drvdata->msgs_num = num; 122 + reinit_completion(&drvdata->completion); 123 + 124 + gxp_i2c_start(drvdata); 125 + 126 + time_left = wait_for_completion_timeout(&drvdata->completion, 127 + adapter->timeout); 128 + ret = num - drvdata->msgs_remaining; 129 + if (time_left == 0) { 130 + switch (drvdata->state) { 131 + case GXP_I2C_WDATA_PHASE: 132 + break; 133 + case GXP_I2C_RDATA_PHASE: 134 + break; 135 + case GXP_I2C_ADDR_PHASE: 136 + break; 137 + default: 138 + break; 139 + } 140 + return -ETIMEDOUT; 141 + } 142 + 143 + if (drvdata->state == GXP_I2C_ADDR_NACK || 144 + drvdata->state == GXP_I2C_DATA_NACK) 145 + return -EIO; 146 + 147 + return ret; 148 + } 149 + 150 + static u32 gxp_i2c_func(struct i2c_adapter *adap) 151 + { 152 + if (IS_ENABLED(CONFIG_I2C_SLAVE)) 153 + return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_SLAVE; 154 + 155 + return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; 156 + } 157 + 158 + #if IS_ENABLED(CONFIG_I2C_SLAVE) 159 + static int gxp_i2c_reg_slave(struct i2c_client *slave) 160 + { 161 + struct gxp_i2c_drvdata *drvdata = i2c_get_adapdata(slave->adapter); 162 + 163 + if (drvdata->slave) 164 + return -EBUSY; 165 + 166 + if (slave->flags & I2C_CLIENT_TEN) 167 + return -EAFNOSUPPORT; 168 + 169 + drvdata->slave = slave; 170 + 171 + writeb(slave->addr << 1, drvdata->base + GXP_I2COWNADR); 172 + writeb(SLAVE_EVT_CLR | SNOOP_EVT_MASK | SLAVE_ACK_ENAB | 173 + SLAVE_EVT_STALL, drvdata->base + GXP_I2CSCMD); 174 + 175 + return 0; 176 + } 177 + 178 + static int gxp_i2c_unreg_slave(struct i2c_client *slave) 179 + { 180 + struct gxp_i2c_drvdata *drvdata = i2c_get_adapdata(slave->adapter); 181 + 182 + WARN_ON(!drvdata->slave); 183 + 184 + writeb(0x00, drvdata->base + GXP_I2COWNADR); 185 + writeb(SNOOP_EVT_CLR | SLAVE_EVT_CLR | SNOOP_EVT_MASK | 186 + SLAVE_EVT_MASK, drvdata->base + GXP_I2CSCMD); 187 + 188 + drvdata->slave = NULL; 189 + 190 + return 0; 191 + } 192 + #endif 193 + 194 + static const struct i2c_algorithm gxp_i2c_algo = { 195 + .master_xfer = gxp_i2c_master_xfer, 196 + .functionality = gxp_i2c_func, 197 + #if IS_ENABLED(CONFIG_I2C_SLAVE) 198 + .reg_slave = gxp_i2c_reg_slave, 199 + .unreg_slave = gxp_i2c_unreg_slave, 200 + #endif 201 + }; 202 + 203 + static void gxp_i2c_stop(struct gxp_i2c_drvdata *drvdata) 204 + { 205 + /* Clear event and send stop */ 206 + writeb(MASTER_EVT_CLR | STOP_CMD, drvdata->base + GXP_I2CMCMD); 207 + 208 + complete(&drvdata->completion); 209 + } 210 + 211 + static void gxp_i2c_restart(struct gxp_i2c_drvdata *drvdata) 212 + { 213 + u16 value; 214 + 215 + drvdata->buf = drvdata->curr_msg->buf; 216 + drvdata->buf_remaining = drvdata->curr_msg->len; 217 + 218 + value = drvdata->curr_msg->addr << 9; 219 + 220 + if (drvdata->curr_msg->flags & I2C_M_RD) { 221 + /* Read and clear master event */ 222 + value |= MASTER_EVT_CLR | RW_CMD | START_CMD; 223 + } else { 224 + /* Write and clear master event */ 225 + value |= MASTER_EVT_CLR | START_CMD; 226 + } 227 + 228 + drvdata->state = GXP_I2C_ADDR_PHASE; 229 + 230 + writew(value, drvdata->base + GXP_I2CMCMD); 231 + } 232 + 233 + static void gxp_i2c_chk_addr_ack(struct gxp_i2c_drvdata *drvdata) 234 + { 235 + u16 value; 236 + 237 + value = readb(drvdata->base + GXP_I2CSTAT); 238 + if (!(value & MASK_ACK)) { 239 + /* Got no ack, stop */ 240 + drvdata->state = GXP_I2C_ADDR_NACK; 241 + gxp_i2c_stop(drvdata); 242 + return; 243 + } 244 + 245 + if (drvdata->curr_msg->flags & I2C_M_RD) { 246 + /* Start to read data from slave */ 247 + if (drvdata->buf_remaining == 0) { 248 + /* No more data to read, stop */ 249 + drvdata->msgs_remaining--; 250 + drvdata->state = GXP_I2C_COMP; 251 + gxp_i2c_stop(drvdata); 252 + return; 253 + } 254 + drvdata->state = GXP_I2C_RDATA_PHASE; 255 + 256 + if (drvdata->buf_remaining == 1) { 257 + /* The last data, do not ack */ 258 + writeb(MASTER_EVT_CLR | RW_CMD, 259 + drvdata->base + GXP_I2CMCMD); 260 + } else { 261 + /* Read data and ack it */ 262 + writeb(MASTER_EVT_CLR | MASTER_ACK_ENAB | 263 + RW_CMD, drvdata->base + GXP_I2CMCMD); 264 + } 265 + } else { 266 + /* Start to write first data to slave */ 267 + if (drvdata->buf_remaining == 0) { 268 + /* No more data to write, stop */ 269 + drvdata->msgs_remaining--; 270 + drvdata->state = GXP_I2C_COMP; 271 + gxp_i2c_stop(drvdata); 272 + return; 273 + } 274 + value = *drvdata->buf; 275 + value = value << 8; 276 + /* Clear master event */ 277 + value |= MASTER_EVT_CLR; 278 + drvdata->buf++; 279 + drvdata->buf_remaining--; 280 + drvdata->state = GXP_I2C_WDATA_PHASE; 281 + writew(value, drvdata->base + GXP_I2CMCMD); 282 + } 283 + } 284 + 285 + static void gxp_i2c_ack_data(struct gxp_i2c_drvdata *drvdata) 286 + { 287 + u8 value; 288 + 289 + /* Store the data returned */ 290 + value = readb(drvdata->base + GXP_I2CSNPDAT); 291 + *drvdata->buf = value; 292 + drvdata->buf++; 293 + drvdata->buf_remaining--; 294 + 295 + if (drvdata->buf_remaining == 0) { 296 + /* No more data, this message is completed. */ 297 + drvdata->msgs_remaining--; 298 + 299 + if (drvdata->msgs_remaining == 0) { 300 + /* No more messages, stop */ 301 + drvdata->state = GXP_I2C_COMP; 302 + gxp_i2c_stop(drvdata); 303 + return; 304 + } 305 + /* Move to next message and start transfer */ 306 + drvdata->curr_msg++; 307 + gxp_i2c_restart(drvdata); 308 + return; 309 + } 310 + 311 + /* Ack the slave to make it send next byte */ 312 + drvdata->state = GXP_I2C_RDATA_PHASE; 313 + if (drvdata->buf_remaining == 1) { 314 + /* The last data, do not ack */ 315 + writeb(MASTER_EVT_CLR | RW_CMD, 316 + drvdata->base + GXP_I2CMCMD); 317 + } else { 318 + /* Read data and ack it */ 319 + writeb(MASTER_EVT_CLR | MASTER_ACK_ENAB | 320 + RW_CMD, drvdata->base + GXP_I2CMCMD); 321 + } 322 + } 323 + 324 + static void gxp_i2c_chk_data_ack(struct gxp_i2c_drvdata *drvdata) 325 + { 326 + u16 value; 327 + 328 + value = readb(drvdata->base + GXP_I2CSTAT); 329 + if (!(value & MASK_ACK)) { 330 + /* Received No ack, stop */ 331 + drvdata->state = GXP_I2C_DATA_NACK; 332 + gxp_i2c_stop(drvdata); 333 + return; 334 + } 335 + 336 + /* Got ack, check if there is more data to write */ 337 + if (drvdata->buf_remaining == 0) { 338 + /* No more data, this message is completed */ 339 + drvdata->msgs_remaining--; 340 + 341 + if (drvdata->msgs_remaining == 0) { 342 + /* No more messages, stop */ 343 + drvdata->state = GXP_I2C_COMP; 344 + gxp_i2c_stop(drvdata); 345 + return; 346 + } 347 + /* Move to next message and start transfer */ 348 + drvdata->curr_msg++; 349 + gxp_i2c_restart(drvdata); 350 + return; 351 + } 352 + 353 + /* Write data to slave */ 354 + value = *drvdata->buf; 355 + value = value << 8; 356 + 357 + /* Clear master event */ 358 + value |= MASTER_EVT_CLR; 359 + drvdata->buf++; 360 + drvdata->buf_remaining--; 361 + drvdata->state = GXP_I2C_WDATA_PHASE; 362 + writew(value, drvdata->base + GXP_I2CMCMD); 363 + } 364 + 365 + #if IS_ENABLED(CONFIG_I2C_SLAVE) 366 + static bool gxp_i2c_slave_irq_handler(struct gxp_i2c_drvdata *drvdata) 367 + { 368 + u8 value; 369 + u8 buf; 370 + int ret; 371 + 372 + value = readb(drvdata->base + GXP_I2CEVTERR); 373 + 374 + /* Received start or stop event */ 375 + if (value & MASK_SLAVE_CMD_EVENT) { 376 + value = readb(drvdata->base + GXP_I2CSTAT); 377 + /* Master sent stop */ 378 + if (value & MASK_STOP_EVENT) { 379 + if (drvdata->stopped == 0) 380 + i2c_slave_event(drvdata->slave, I2C_SLAVE_STOP, &buf); 381 + writeb(SLAVE_EVT_CLR | SNOOP_EVT_MASK | 382 + SLAVE_ACK_ENAB | SLAVE_EVT_STALL, drvdata->base + GXP_I2CSCMD); 383 + drvdata->stopped = 1; 384 + } else { 385 + /* Master sent start and wants to read */ 386 + drvdata->stopped = 0; 387 + if (value & MASK_RW) { 388 + i2c_slave_event(drvdata->slave, 389 + I2C_SLAVE_READ_REQUESTED, &buf); 390 + value = buf << 8 | (SLAVE_EVT_CLR | SNOOP_EVT_MASK | 391 + SLAVE_EVT_STALL); 392 + writew(value, drvdata->base + GXP_I2CSCMD); 393 + } else { 394 + /* Master wants to write to us */ 395 + ret = i2c_slave_event(drvdata->slave, 396 + I2C_SLAVE_WRITE_REQUESTED, &buf); 397 + if (!ret) { 398 + /* Ack next byte from master */ 399 + writeb(SLAVE_EVT_CLR | SNOOP_EVT_MASK | 400 + SLAVE_ACK_ENAB | SLAVE_EVT_STALL, 401 + drvdata->base + GXP_I2CSCMD); 402 + } else { 403 + /* Nack next byte from master */ 404 + writeb(SLAVE_EVT_CLR | SNOOP_EVT_MASK | 405 + SLAVE_EVT_STALL, drvdata->base + GXP_I2CSCMD); 406 + } 407 + } 408 + } 409 + } else if (value & MASK_SLAVE_DATA_EVENT) { 410 + value = readb(drvdata->base + GXP_I2CSTAT); 411 + /* Master wants to read */ 412 + if (value & MASK_RW) { 413 + /* Master wants another byte */ 414 + if (value & MASK_ACK) { 415 + i2c_slave_event(drvdata->slave, 416 + I2C_SLAVE_READ_PROCESSED, &buf); 417 + value = buf << 8 | (SLAVE_EVT_CLR | SNOOP_EVT_MASK | 418 + SLAVE_EVT_STALL); 419 + writew(value, drvdata->base + GXP_I2CSCMD); 420 + } else { 421 + /* No more bytes needed */ 422 + writew(SLAVE_EVT_CLR | SNOOP_EVT_MASK | 423 + SLAVE_ACK_ENAB | SLAVE_EVT_STALL, 424 + drvdata->base + GXP_I2CSCMD); 425 + } 426 + } else { 427 + /* Master wants to write to us */ 428 + value = readb(drvdata->base + GXP_I2CSNPDAT); 429 + buf = (uint8_t)value; 430 + ret = i2c_slave_event(drvdata->slave, 431 + I2C_SLAVE_WRITE_RECEIVED, &buf); 432 + if (!ret) { 433 + /* Ack next byte from master */ 434 + writeb(SLAVE_EVT_CLR | SNOOP_EVT_MASK | 435 + SLAVE_ACK_ENAB | SLAVE_EVT_STALL, 436 + drvdata->base + GXP_I2CSCMD); 437 + } else { 438 + /* Nack next byte from master */ 439 + writeb(SLAVE_EVT_CLR | SNOOP_EVT_MASK | 440 + SLAVE_EVT_STALL, drvdata->base + GXP_I2CSCMD); 441 + } 442 + } 443 + } else { 444 + return false; 445 + } 446 + 447 + return true; 448 + } 449 + #endif 450 + 451 + static irqreturn_t gxp_i2c_irq_handler(int irq, void *_drvdata) 452 + { 453 + struct gxp_i2c_drvdata *drvdata = (struct gxp_i2c_drvdata *)_drvdata; 454 + u32 value; 455 + 456 + /* Check if the interrupt is for the current engine */ 457 + regmap_read(i2cg_map, GXP_I2CINTSTAT, &value); 458 + if (!(value & BIT(drvdata->engine))) 459 + return IRQ_NONE; 460 + 461 + value = readb(drvdata->base + GXP_I2CEVTERR); 462 + 463 + /* Error */ 464 + if (value & ~(MASK_MASTER_EVENT | MASK_SLAVE_CMD_EVENT | 465 + MASK_SLAVE_DATA_EVENT)) { 466 + /* Clear all events */ 467 + writeb(0x00, drvdata->base + GXP_I2CEVTERR); 468 + drvdata->state = GXP_I2C_ERROR; 469 + gxp_i2c_stop(drvdata); 470 + return IRQ_HANDLED; 471 + } 472 + 473 + if (IS_ENABLED(CONFIG_I2C_SLAVE)) { 474 + /* Slave mode */ 475 + if (value & (MASK_SLAVE_CMD_EVENT | MASK_SLAVE_DATA_EVENT)) { 476 + if (gxp_i2c_slave_irq_handler(drvdata)) 477 + return IRQ_HANDLED; 478 + return IRQ_NONE; 479 + } 480 + } 481 + 482 + /* Master mode */ 483 + switch (drvdata->state) { 484 + case GXP_I2C_ADDR_PHASE: 485 + gxp_i2c_chk_addr_ack(drvdata); 486 + break; 487 + 488 + case GXP_I2C_RDATA_PHASE: 489 + gxp_i2c_ack_data(drvdata); 490 + break; 491 + 492 + case GXP_I2C_WDATA_PHASE: 493 + gxp_i2c_chk_data_ack(drvdata); 494 + break; 495 + } 496 + 497 + return IRQ_HANDLED; 498 + } 499 + 500 + static void gxp_i2c_init(struct gxp_i2c_drvdata *drvdata) 501 + { 502 + drvdata->state = GXP_I2C_IDLE; 503 + writeb(2000000 / drvdata->t.bus_freq_hz, 504 + drvdata->base + GXP_I2CFREQDIV); 505 + writeb(FILTER_CNT | FAIRNESS_CNT, 506 + drvdata->base + GXP_I2CFLTFAIR); 507 + writeb(GXP_DATA_EDGE_RST_CTRL, drvdata->base + GXP_I2CTMOEDG); 508 + writeb(0x00, drvdata->base + GXP_I2CCYCTIM); 509 + writeb(0x00, drvdata->base + GXP_I2CSNPAA); 510 + writeb(0x00, drvdata->base + GXP_I2CADVFEAT); 511 + writeb(SNOOP_EVT_CLR | SLAVE_EVT_CLR | SNOOP_EVT_MASK | 512 + SLAVE_EVT_MASK, drvdata->base + GXP_I2CSCMD); 513 + writeb(MASTER_EVT_CLR, drvdata->base + GXP_I2CMCMD); 514 + writeb(0x00, drvdata->base + GXP_I2CEVTERR); 515 + writeb(0x00, drvdata->base + GXP_I2COWNADR); 516 + } 517 + 518 + static int gxp_i2c_probe(struct platform_device *pdev) 519 + { 520 + struct gxp_i2c_drvdata *drvdata; 521 + int rc; 522 + struct i2c_adapter *adapter; 523 + 524 + if (!i2cg_map) { 525 + i2cg_map = syscon_regmap_lookup_by_phandle(pdev->dev.of_node, 526 + "hpe,sysreg"); 527 + if (IS_ERR(i2cg_map)) { 528 + return dev_err_probe(&pdev->dev, IS_ERR(i2cg_map), 529 + "failed to map i2cg_handle\n"); 530 + } 531 + 532 + /* Disable interrupt */ 533 + regmap_update_bits(i2cg_map, GXP_I2CINTEN, 0x00000FFF, 0); 534 + } 535 + 536 + drvdata = devm_kzalloc(&pdev->dev, sizeof(*drvdata), 537 + GFP_KERNEL); 538 + if (!drvdata) 539 + return -ENOMEM; 540 + 541 + platform_set_drvdata(pdev, drvdata); 542 + drvdata->dev = &pdev->dev; 543 + init_completion(&drvdata->completion); 544 + 545 + drvdata->base = devm_platform_ioremap_resource(pdev, 0); 546 + if (IS_ERR(drvdata->base)) 547 + return PTR_ERR(drvdata->base); 548 + 549 + /* Use physical memory address to determine which I2C engine this is. */ 550 + drvdata->engine = ((size_t)drvdata->base & 0xf00) >> 8; 551 + 552 + if (drvdata->engine >= GXP_MAX_I2C_ENGINE) { 553 + return dev_err_probe(&pdev->dev, -EINVAL, "i2c engine% is unsupported\n", 554 + drvdata->engine); 555 + } 556 + 557 + rc = platform_get_irq(pdev, 0); 558 + if (rc < 0) 559 + return rc; 560 + 561 + drvdata->irq = rc; 562 + rc = devm_request_irq(&pdev->dev, drvdata->irq, gxp_i2c_irq_handler, 563 + IRQF_SHARED, gxp_i2c_name[drvdata->engine], drvdata); 564 + if (rc < 0) 565 + return dev_err_probe(&pdev->dev, rc, "irq request failed\n"); 566 + 567 + i2c_parse_fw_timings(&pdev->dev, &drvdata->t, true); 568 + 569 + gxp_i2c_init(drvdata); 570 + 571 + /* Enable interrupt */ 572 + regmap_update_bits(i2cg_map, GXP_I2CINTEN, BIT(drvdata->engine), 573 + BIT(drvdata->engine)); 574 + 575 + adapter = &drvdata->adapter; 576 + i2c_set_adapdata(adapter, drvdata); 577 + 578 + adapter->owner = THIS_MODULE; 579 + strscpy(adapter->name, "HPE GXP I2C adapter", sizeof(adapter->name)); 580 + adapter->algo = &gxp_i2c_algo; 581 + adapter->dev.parent = &pdev->dev; 582 + adapter->dev.of_node = pdev->dev.of_node; 583 + 584 + rc = i2c_add_adapter(adapter); 585 + if (rc) 586 + return dev_err_probe(&pdev->dev, rc, "i2c add adapter failed\n"); 587 + 588 + return 0; 589 + } 590 + 591 + static int gxp_i2c_remove(struct platform_device *pdev) 592 + { 593 + struct gxp_i2c_drvdata *drvdata = platform_get_drvdata(pdev); 594 + 595 + /* Disable interrupt */ 596 + regmap_update_bits(i2cg_map, GXP_I2CINTEN, BIT(drvdata->engine), 0); 597 + i2c_del_adapter(&drvdata->adapter); 598 + 599 + return 0; 600 + } 601 + 602 + static const struct of_device_id gxp_i2c_of_match[] = { 603 + { .compatible = "hpe,gxp-i2c" }, 604 + {}, 605 + }; 606 + MODULE_DEVICE_TABLE(of, gxp_i2c_of_match); 607 + 608 + static struct platform_driver gxp_i2c_driver = { 609 + .probe = gxp_i2c_probe, 610 + .remove = gxp_i2c_remove, 611 + .driver = { 612 + .name = "gxp-i2c", 613 + .of_match_table = gxp_i2c_of_match, 614 + }, 615 + }; 616 + module_platform_driver(gxp_i2c_driver); 617 + 618 + MODULE_AUTHOR("Nick Hawkins <nick.hawkins@hpe.com>"); 619 + MODULE_DESCRIPTION("HPE GXP I2C bus driver"); 620 + MODULE_LICENSE("GPL");
+152 -158
drivers/i2c/busses/i2c-i801.c
··· 434 434 busy = status & SMBHSTSTS_HOST_BUSY; 435 435 status &= STATUS_ERROR_FLAGS | SMBHSTSTS_INTR; 436 436 if (!busy && status) 437 - return status; 437 + return status & STATUS_ERROR_FLAGS; 438 438 } while (time_is_after_eq_jiffies(timeout)); 439 439 440 440 return -ETIMEDOUT; ··· 458 458 459 459 static int i801_transaction(struct i801_priv *priv, int xact) 460 460 { 461 - int status; 462 461 unsigned long result; 463 462 const struct i2c_adapter *adap = &priv->adapter; 464 - 465 - status = i801_check_pre(priv); 466 - if (status < 0) 467 - return status; 468 463 469 464 if (priv->features & FEATURE_IRQ) { 470 465 reinit_completion(&priv->done); 471 466 outb_p(xact | SMBHSTCNT_INTREN | SMBHSTCNT_START, 472 467 SMBHSTCNT(priv)); 473 468 result = wait_for_completion_timeout(&priv->done, adap->timeout); 474 - return i801_check_post(priv, result ? priv->status : -ETIMEDOUT); 469 + return result ? priv->status : -ETIMEDOUT; 475 470 } 476 471 477 472 outb_p(xact | SMBHSTCNT_START, SMBHSTCNT(priv)); 478 473 479 - status = i801_wait_intr(priv); 480 - return i801_check_post(priv, status); 474 + return i801_wait_intr(priv); 481 475 } 482 476 483 477 static int i801_block_transaction_by_block(struct i801_priv *priv, ··· 505 511 506 512 status = i801_transaction(priv, xact); 507 513 if (status) 508 - return status; 514 + goto out; 509 515 510 516 if (read_write == I2C_SMBUS_READ || 511 517 command == I2C_SMBUS_BLOCK_PROC_CALL) { 512 518 len = inb_p(SMBHSTDAT0(priv)); 513 - if (len < 1 || len > I2C_SMBUS_BLOCK_MAX) 514 - return -EPROTO; 519 + if (len < 1 || len > I2C_SMBUS_BLOCK_MAX) { 520 + status = -EPROTO; 521 + goto out; 522 + } 515 523 516 524 data->block[0] = len; 517 525 for (i = 0; i < len; i++) 518 526 data->block[i + 1] = inb_p(SMBBLKDAT(priv)); 519 527 } 520 - return 0; 528 + out: 529 + outb_p(inb_p(SMBAUXCTL(priv)) & ~SMBAUXCTL_E32B, SMBAUXCTL(priv)); 530 + return status; 521 531 } 522 532 523 533 static void i801_isr_byte_done(struct i801_priv *priv) ··· 556 558 /* Write next byte, except for IRQ after last byte */ 557 559 outb_p(priv->data[++priv->count], SMBBLKDAT(priv)); 558 560 } 559 - 560 - /* Clear BYTE_DONE to continue with next byte */ 561 - outb_p(SMBHSTSTS_BYTE_DONE, SMBHSTSTS(priv)); 562 561 } 563 562 564 563 static irqreturn_t i801_host_notify_isr(struct i801_priv *priv) ··· 585 590 * BUS_ERR - SMI# transaction collision 586 591 * FAILED - transaction was canceled due to a KILL request 587 592 * When any of these occur, update ->status and signal completion. 588 - * ->status must be cleared before kicking off the next transaction. 589 593 * 590 594 * 2) For byte-by-byte (I2C read/write) transactions, one BYTE_DONE interrupt 591 595 * occurs for each byte of a byte-by-byte to prepare the next byte. ··· 609 615 } 610 616 611 617 status = inb_p(SMBHSTSTS(priv)); 612 - if (status & SMBHSTSTS_BYTE_DONE) 618 + if ((status & (SMBHSTSTS_BYTE_DONE | STATUS_ERROR_FLAGS)) == SMBHSTSTS_BYTE_DONE) 613 619 i801_isr_byte_done(priv); 614 620 615 621 /* 616 - * Clear remaining IRQ sources: Completion of last command, errors 617 - * and the SMB_ALERT signal. SMB_ALERT status is set after signal 618 - * assertion independently of the interrupt generation being blocked 619 - * or not so clear it always when the status is set. 622 + * Clear IRQ sources: SMB_ALERT status is set after signal assertion 623 + * independently of the interrupt generation being blocked or not 624 + * so clear it always when the status is set. 620 625 */ 621 - status &= SMBHSTSTS_INTR | STATUS_ERROR_FLAGS | SMBHSTSTS_SMBALERT_STS; 622 - if (status) 623 - outb_p(status, SMBHSTSTS(priv)); 624 - status &= ~SMBHSTSTS_SMBALERT_STS; /* SMB_ALERT not reported */ 625 - /* 626 - * Report transaction result. 627 - * ->status must be cleared before the next transaction is started. 628 - */ 626 + status &= STATUS_FLAGS | SMBHSTSTS_SMBALERT_STS; 627 + outb_p(status, SMBHSTSTS(priv)); 628 + 629 + status &= STATUS_ERROR_FLAGS | SMBHSTSTS_INTR; 629 630 if (status) { 630 - priv->status = status; 631 + priv->status = status & STATUS_ERROR_FLAGS; 631 632 complete(&priv->done); 632 633 } 633 634 ··· 646 657 647 658 if (command == I2C_SMBUS_BLOCK_PROC_CALL) 648 659 return -EOPNOTSUPP; 649 - 650 - status = i801_check_pre(priv); 651 - if (status < 0) 652 - return status; 653 660 654 661 len = data->block[0]; 655 662 ··· 672 687 reinit_completion(&priv->done); 673 688 outb_p(priv->cmd | SMBHSTCNT_START, SMBHSTCNT(priv)); 674 689 result = wait_for_completion_timeout(&priv->done, adap->timeout); 675 - return i801_check_post(priv, result ? priv->status : -ETIMEDOUT); 690 + return result ? priv->status : -ETIMEDOUT; 676 691 } 677 692 678 693 for (i = 1; i <= len; i++) { ··· 686 701 687 702 status = i801_wait_byte_done(priv); 688 703 if (status) 689 - goto exit; 704 + return status; 690 705 691 706 if (i == 1 && read_write == I2C_SMBUS_READ 692 707 && command != I2C_SMBUS_I2C_BLOCK_DATA) { ··· 716 731 outb_p(SMBHSTSTS_BYTE_DONE, SMBHSTSTS(priv)); 717 732 } 718 733 719 - status = i801_wait_intr(priv); 720 - exit: 721 - return i801_check_post(priv, status); 734 + return i801_wait_intr(priv); 735 + } 736 + 737 + static void i801_set_hstadd(struct i801_priv *priv, u8 addr, char read_write) 738 + { 739 + outb_p((addr << 1) | (read_write & 0x01), SMBHSTADD(priv)); 740 + } 741 + 742 + /* Single value transaction function */ 743 + static int i801_simple_transaction(struct i801_priv *priv, union i2c_smbus_data *data, 744 + u8 addr, u8 hstcmd, char read_write, int command) 745 + { 746 + int xact, ret; 747 + 748 + switch (command) { 749 + case I2C_SMBUS_QUICK: 750 + i801_set_hstadd(priv, addr, read_write); 751 + xact = I801_QUICK; 752 + break; 753 + case I2C_SMBUS_BYTE: 754 + i801_set_hstadd(priv, addr, read_write); 755 + if (read_write == I2C_SMBUS_WRITE) 756 + outb_p(hstcmd, SMBHSTCMD(priv)); 757 + xact = I801_BYTE; 758 + break; 759 + case I2C_SMBUS_BYTE_DATA: 760 + i801_set_hstadd(priv, addr, read_write); 761 + if (read_write == I2C_SMBUS_WRITE) 762 + outb_p(data->byte, SMBHSTDAT0(priv)); 763 + outb_p(hstcmd, SMBHSTCMD(priv)); 764 + xact = I801_BYTE_DATA; 765 + break; 766 + case I2C_SMBUS_WORD_DATA: 767 + i801_set_hstadd(priv, addr, read_write); 768 + if (read_write == I2C_SMBUS_WRITE) { 769 + outb_p(data->word & 0xff, SMBHSTDAT0(priv)); 770 + outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1(priv)); 771 + } 772 + outb_p(hstcmd, SMBHSTCMD(priv)); 773 + xact = I801_WORD_DATA; 774 + break; 775 + case I2C_SMBUS_PROC_CALL: 776 + i801_set_hstadd(priv, addr, I2C_SMBUS_WRITE); 777 + outb_p(data->word & 0xff, SMBHSTDAT0(priv)); 778 + outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1(priv)); 779 + outb_p(hstcmd, SMBHSTCMD(priv)); 780 + read_write = I2C_SMBUS_READ; 781 + xact = I801_PROC_CALL; 782 + break; 783 + default: 784 + pci_err(priv->pci_dev, "Unsupported transaction %d\n", command); 785 + return -EOPNOTSUPP; 786 + } 787 + 788 + ret = i801_transaction(priv, xact); 789 + if (ret || read_write == I2C_SMBUS_WRITE) 790 + return ret; 791 + 792 + switch (command) { 793 + case I2C_SMBUS_BYTE: 794 + case I2C_SMBUS_BYTE_DATA: 795 + data->byte = inb_p(SMBHSTDAT0(priv)); 796 + break; 797 + case I2C_SMBUS_WORD_DATA: 798 + case I2C_SMBUS_PROC_CALL: 799 + data->word = inb_p(SMBHSTDAT0(priv)) + 800 + (inb_p(SMBHSTDAT1(priv)) << 8); 801 + break; 802 + } 803 + 804 + return 0; 722 805 } 723 806 724 807 /* Block transaction function */ 725 808 static int i801_block_transaction(struct i801_priv *priv, union i2c_smbus_data *data, 726 - char read_write, int command) 809 + u8 addr, u8 hstcmd, char read_write, int command) 727 810 { 728 811 int result = 0; 729 812 unsigned char hostc; ··· 801 748 else if (data->block[0] < 1 || data->block[0] > I2C_SMBUS_BLOCK_MAX) 802 749 return -EPROTO; 803 750 804 - if (command == I2C_SMBUS_I2C_BLOCK_DATA) { 751 + switch (command) { 752 + case I2C_SMBUS_BLOCK_DATA: 753 + i801_set_hstadd(priv, addr, read_write); 754 + outb_p(hstcmd, SMBHSTCMD(priv)); 755 + break; 756 + case I2C_SMBUS_I2C_BLOCK_DATA: 757 + /* 758 + * NB: page 240 of ICH5 datasheet shows that the R/#W 759 + * bit should be cleared here, even when reading. 760 + * However if SPD Write Disable is set (Lynx Point and later), 761 + * the read will fail if we don't set the R/#W bit. 762 + */ 763 + i801_set_hstadd(priv, addr, 764 + priv->original_hstcfg & SMBHSTCFG_SPD_WD ? 765 + read_write : I2C_SMBUS_WRITE); 766 + if (read_write == I2C_SMBUS_READ) { 767 + /* NB: page 240 of ICH5 datasheet also shows 768 + * that DATA1 is the cmd field when reading 769 + */ 770 + outb_p(hstcmd, SMBHSTDAT1(priv)); 771 + } else 772 + outb_p(hstcmd, SMBHSTCMD(priv)); 773 + 805 774 if (read_write == I2C_SMBUS_WRITE) { 806 775 /* set I2C_EN bit in configuration register */ 807 776 pci_read_config_byte(priv->pci_dev, SMBHSTCFG, &hostc); ··· 834 759 "I2C block read is unsupported!\n"); 835 760 return -EOPNOTSUPP; 836 761 } 762 + break; 763 + case I2C_SMBUS_BLOCK_PROC_CALL: 764 + /* Needs to be flagged as write transaction */ 765 + i801_set_hstadd(priv, addr, I2C_SMBUS_WRITE); 766 + outb_p(hstcmd, SMBHSTCMD(priv)); 767 + break; 837 768 } 838 769 839 770 /* Experience has shown that the block buffer can only be used for ··· 868 787 unsigned short flags, char read_write, u8 command, 869 788 int size, union i2c_smbus_data *data) 870 789 { 871 - int hwpec; 872 - int block = 0; 873 - int ret, xact; 790 + int hwpec, ret; 874 791 struct i801_priv *priv = i2c_get_adapdata(adap); 875 792 876 793 mutex_lock(&priv->acpi_lock); ··· 879 800 880 801 pm_runtime_get_sync(&priv->pci_dev->dev); 881 802 803 + ret = i801_check_pre(priv); 804 + if (ret) 805 + goto out; 806 + 882 807 hwpec = (priv->features & FEATURE_SMBUS_PEC) && (flags & I2C_CLIENT_PEC) 883 808 && size != I2C_SMBUS_QUICK 884 809 && size != I2C_SMBUS_I2C_BLOCK_DATA; 885 - 886 - switch (size) { 887 - case I2C_SMBUS_QUICK: 888 - outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), 889 - SMBHSTADD(priv)); 890 - xact = I801_QUICK; 891 - break; 892 - case I2C_SMBUS_BYTE: 893 - outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), 894 - SMBHSTADD(priv)); 895 - if (read_write == I2C_SMBUS_WRITE) 896 - outb_p(command, SMBHSTCMD(priv)); 897 - xact = I801_BYTE; 898 - break; 899 - case I2C_SMBUS_BYTE_DATA: 900 - outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), 901 - SMBHSTADD(priv)); 902 - outb_p(command, SMBHSTCMD(priv)); 903 - if (read_write == I2C_SMBUS_WRITE) 904 - outb_p(data->byte, SMBHSTDAT0(priv)); 905 - xact = I801_BYTE_DATA; 906 - break; 907 - case I2C_SMBUS_WORD_DATA: 908 - outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), 909 - SMBHSTADD(priv)); 910 - outb_p(command, SMBHSTCMD(priv)); 911 - if (read_write == I2C_SMBUS_WRITE) { 912 - outb_p(data->word & 0xff, SMBHSTDAT0(priv)); 913 - outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1(priv)); 914 - } 915 - xact = I801_WORD_DATA; 916 - break; 917 - case I2C_SMBUS_PROC_CALL: 918 - outb_p((addr & 0x7f) << 1, SMBHSTADD(priv)); 919 - outb_p(command, SMBHSTCMD(priv)); 920 - outb_p(data->word & 0xff, SMBHSTDAT0(priv)); 921 - outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1(priv)); 922 - xact = I801_PROC_CALL; 923 - read_write = I2C_SMBUS_READ; 924 - break; 925 - case I2C_SMBUS_BLOCK_DATA: 926 - outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), 927 - SMBHSTADD(priv)); 928 - outb_p(command, SMBHSTCMD(priv)); 929 - block = 1; 930 - break; 931 - case I2C_SMBUS_I2C_BLOCK_DATA: 932 - /* 933 - * NB: page 240 of ICH5 datasheet shows that the R/#W 934 - * bit should be cleared here, even when reading. 935 - * However if SPD Write Disable is set (Lynx Point and later), 936 - * the read will fail if we don't set the R/#W bit. 937 - */ 938 - outb_p(((addr & 0x7f) << 1) | 939 - ((priv->original_hstcfg & SMBHSTCFG_SPD_WD) ? 940 - (read_write & 0x01) : 0), 941 - SMBHSTADD(priv)); 942 - if (read_write == I2C_SMBUS_READ) { 943 - /* NB: page 240 of ICH5 datasheet also shows 944 - * that DATA1 is the cmd field when reading */ 945 - outb_p(command, SMBHSTDAT1(priv)); 946 - } else 947 - outb_p(command, SMBHSTCMD(priv)); 948 - block = 1; 949 - break; 950 - case I2C_SMBUS_BLOCK_PROC_CALL: 951 - /* 952 - * Bit 0 of the slave address register always indicate a write 953 - * command. 954 - */ 955 - outb_p((addr & 0x7f) << 1, SMBHSTADD(priv)); 956 - outb_p(command, SMBHSTCMD(priv)); 957 - block = 1; 958 - break; 959 - default: 960 - dev_err(&priv->pci_dev->dev, "Unsupported transaction %d\n", 961 - size); 962 - ret = -EOPNOTSUPP; 963 - goto out; 964 - } 965 810 966 811 if (hwpec) /* enable/disable hardware PEC */ 967 812 outb_p(inb_p(SMBAUXCTL(priv)) | SMBAUXCTL_CRC, SMBAUXCTL(priv)); ··· 893 890 outb_p(inb_p(SMBAUXCTL(priv)) & (~SMBAUXCTL_CRC), 894 891 SMBAUXCTL(priv)); 895 892 896 - if (block) 897 - ret = i801_block_transaction(priv, data, read_write, size); 893 + if (size == I2C_SMBUS_BLOCK_DATA || 894 + size == I2C_SMBUS_I2C_BLOCK_DATA || 895 + size == I2C_SMBUS_BLOCK_PROC_CALL) 896 + ret = i801_block_transaction(priv, data, addr, command, read_write, size); 898 897 else 899 - ret = i801_transaction(priv, xact); 898 + ret = i801_simple_transaction(priv, data, addr, command, read_write, size); 899 + 900 + ret = i801_check_post(priv, ret); 900 901 901 902 /* Some BIOSes don't like it when PEC is enabled at reboot or resume 902 - time, so we forcibly disable it after every transaction. Turn off 903 - E32B for the same reason. */ 904 - if (hwpec || block) 905 - outb_p(inb_p(SMBAUXCTL(priv)) & 906 - ~(SMBAUXCTL_CRC | SMBAUXCTL_E32B), SMBAUXCTL(priv)); 907 - 908 - if (block) 909 - goto out; 910 - if (ret) 911 - goto out; 912 - if ((read_write == I2C_SMBUS_WRITE) || (xact == I801_QUICK)) 913 - goto out; 914 - 915 - switch (xact) { 916 - case I801_BYTE: /* Result put in SMBHSTDAT0 */ 917 - case I801_BYTE_DATA: 918 - data->byte = inb_p(SMBHSTDAT0(priv)); 919 - break; 920 - case I801_WORD_DATA: 921 - case I801_PROC_CALL: 922 - data->word = inb_p(SMBHSTDAT0(priv)) + 923 - (inb_p(SMBHSTDAT1(priv)) << 8); 924 - break; 925 - } 926 - 903 + * time, so we forcibly disable it after every transaction. 904 + */ 905 + if (hwpec) 906 + outb_p(inb_p(SMBAUXCTL(priv)) & ~SMBAUXCTL_CRC, SMBAUXCTL(priv)); 927 907 out: 928 908 /* 929 909 * Unlock the SMBus device for use by BIOS/ACPI, ··· 1653 1667 } 1654 1668 priv->features &= ~disable_features; 1655 1669 1670 + /* The block process call uses block buffer mode */ 1671 + if (!(priv->features & FEATURE_BLOCK_BUFFER)) 1672 + priv->features &= ~FEATURE_BLOCK_PROC; 1673 + 1656 1674 err = pcim_enable_device(dev); 1657 1675 if (err) { 1658 1676 dev_err(&dev->dev, "Failed to enable SMBus PCI device (%d)\n", ··· 1704 1714 outb_p(inb_p(SMBAUXCTL(priv)) & 1705 1715 ~(SMBAUXCTL_CRC | SMBAUXCTL_E32B), SMBAUXCTL(priv)); 1706 1716 1707 - /* Remember original Interrupt and Host Notify settings */ 1708 - priv->original_hstcnt = inb_p(SMBHSTCNT(priv)) & ~SMBHSTCNT_KILL; 1709 - if (priv->features & FEATURE_HOST_NOTIFY) 1710 - priv->original_slvcmd = inb_p(SMBSLVCMD(priv)); 1711 - 1712 1717 /* Default timeout in interrupt mode: 200 ms */ 1713 1718 priv->adapter.timeout = HZ / 5; 1714 1719 ··· 1732 1747 } 1733 1748 dev_info(&dev->dev, "SMBus using %s\n", 1734 1749 priv->features & FEATURE_IRQ ? "PCI interrupt" : "polling"); 1750 + 1751 + /* Host notification uses an interrupt */ 1752 + if (!(priv->features & FEATURE_IRQ)) 1753 + priv->features &= ~FEATURE_HOST_NOTIFY; 1754 + 1755 + /* Remember original Interrupt and Host Notify settings */ 1756 + priv->original_hstcnt = inb_p(SMBHSTCNT(priv)) & ~SMBHSTCNT_KILL; 1757 + if (priv->features & FEATURE_HOST_NOTIFY) 1758 + priv->original_slvcmd = inb_p(SMBSLVCMD(priv)); 1735 1759 1736 1760 i801_add_tco(priv); 1737 1761
+370
drivers/i2c/busses/i2c-ls2x.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Loongson-2K/Loongson LS7A I2C master mode driver 4 + * 5 + * Copyright (C) 2013 Loongson Technology Corporation Limited. 6 + * Copyright (C) 2014-2017 Lemote, Inc. 7 + * Copyright (C) 2018-2022 Loongson Technology Corporation Limited. 8 + * 9 + * Originally written by liushaozong 10 + * Rewritten for mainline by Binbin Zhou <zhoubinbin@loongson.cn> 11 + */ 12 + 13 + #include <linux/bits.h> 14 + #include <linux/completion.h> 15 + #include <linux/device.h> 16 + #include <linux/iopoll.h> 17 + #include <linux/i2c.h> 18 + #include <linux/init.h> 19 + #include <linux/interrupt.h> 20 + #include <linux/io.h> 21 + #include <linux/kernel.h> 22 + #include <linux/module.h> 23 + #include <linux/pm_runtime.h> 24 + #include <linux/platform_device.h> 25 + #include <linux/property.h> 26 + #include <linux/units.h> 27 + 28 + /* I2C Registers */ 29 + #define I2C_LS2X_PRER 0x0 /* Freq Division Register(16 bits) */ 30 + #define I2C_LS2X_CTR 0x2 /* Control Register */ 31 + #define I2C_LS2X_TXR 0x3 /* Transport Data Register */ 32 + #define I2C_LS2X_RXR 0x3 /* Receive Data Register */ 33 + #define I2C_LS2X_CR 0x4 /* Command Control Register */ 34 + #define I2C_LS2X_SR 0x4 /* State Register */ 35 + 36 + /* Command Control Register Bit */ 37 + #define LS2X_CR_START BIT(7) /* Start signal */ 38 + #define LS2X_CR_STOP BIT(6) /* Stop signal */ 39 + #define LS2X_CR_READ BIT(5) /* Read signal */ 40 + #define LS2X_CR_WRITE BIT(4) /* Write signal */ 41 + #define LS2X_CR_ACK BIT(3) /* Response signal */ 42 + #define LS2X_CR_IACK BIT(0) /* Interrupt response signal */ 43 + 44 + /* State Register Bit */ 45 + #define LS2X_SR_NOACK BIT(7) /* Receive NACK */ 46 + #define LS2X_SR_BUSY BIT(6) /* Bus busy state */ 47 + #define LS2X_SR_AL BIT(5) /* Arbitration lost */ 48 + #define LS2X_SR_TIP BIT(1) /* Transmission state */ 49 + #define LS2X_SR_IF BIT(0) /* Interrupt flag */ 50 + 51 + /* Control Register Bit */ 52 + #define LS2X_CTR_EN BIT(7) /* 0: I2c frequency setting 1: Normal */ 53 + #define LS2X_CTR_IEN BIT(6) /* Enable i2c interrupt */ 54 + #define LS2X_CTR_MST BIT(5) /* 0: Slave mode 1: Master mode */ 55 + #define CTR_FREQ_MASK GENMASK(7, 6) 56 + #define CTR_READY_MASK GENMASK(7, 5) 57 + 58 + /* The PCLK frequency from LPB */ 59 + #define LS2X_I2C_PCLK_FREQ (50 * HZ_PER_MHZ) 60 + 61 + /* The default bus frequency, which is an empirical value */ 62 + #define LS2X_I2C_FREQ_STD (33 * HZ_PER_KHZ) 63 + 64 + struct ls2x_i2c_priv { 65 + struct i2c_adapter adapter; 66 + void __iomem *base; 67 + struct i2c_timings i2c_t; 68 + struct completion cmd_complete; 69 + }; 70 + 71 + /* 72 + * Interrupt service routine. 73 + * This gets called whenever an I2C interrupt occurs. 74 + */ 75 + static irqreturn_t ls2x_i2c_isr(int this_irq, void *dev_id) 76 + { 77 + struct ls2x_i2c_priv *priv = dev_id; 78 + 79 + if (!(readb(priv->base + I2C_LS2X_SR) & LS2X_SR_IF)) 80 + return IRQ_NONE; 81 + 82 + writeb(LS2X_CR_IACK, priv->base + I2C_LS2X_CR); 83 + complete(&priv->cmd_complete); 84 + return IRQ_HANDLED; 85 + } 86 + 87 + /* 88 + * The ls2x i2c controller supports standard mode and fast mode, so the 89 + * maximum bus frequency is '400kHz'. 90 + * The bus frequency is set to the empirical value of '33KHz' by default, 91 + * but it can also be taken from ACPI or FDT for compatibility with more 92 + * devices. 93 + */ 94 + static void ls2x_i2c_adjust_bus_speed(struct ls2x_i2c_priv *priv) 95 + { 96 + struct i2c_timings *t = &priv->i2c_t; 97 + struct device *dev = priv->adapter.dev.parent; 98 + u32 acpi_speed = i2c_acpi_find_bus_speed(dev); 99 + 100 + i2c_parse_fw_timings(dev, t, false); 101 + 102 + if (acpi_speed || t->bus_freq_hz) 103 + t->bus_freq_hz = max(t->bus_freq_hz, acpi_speed); 104 + else 105 + t->bus_freq_hz = LS2X_I2C_FREQ_STD; 106 + 107 + /* Calculate and set i2c frequency. */ 108 + writew(LS2X_I2C_PCLK_FREQ / (5 * t->bus_freq_hz) - 1, 109 + priv->base + I2C_LS2X_PRER); 110 + } 111 + 112 + static void ls2x_i2c_init(struct ls2x_i2c_priv *priv) 113 + { 114 + /* Set i2c frequency setting mode and disable interrupts. */ 115 + writeb(readb(priv->base + I2C_LS2X_CTR) & ~CTR_FREQ_MASK, 116 + priv->base + I2C_LS2X_CTR); 117 + 118 + ls2x_i2c_adjust_bus_speed(priv); 119 + 120 + /* Set i2c normal operating mode and enable interrupts. */ 121 + writeb(readb(priv->base + I2C_LS2X_CTR) | CTR_READY_MASK, 122 + priv->base + I2C_LS2X_CTR); 123 + } 124 + 125 + static int ls2x_i2c_xfer_byte(struct ls2x_i2c_priv *priv, u8 txdata, u8 *rxdatap) 126 + { 127 + u8 rxdata; 128 + unsigned long time_left; 129 + 130 + writeb(txdata, priv->base + I2C_LS2X_CR); 131 + 132 + time_left = wait_for_completion_timeout(&priv->cmd_complete, 133 + priv->adapter.timeout); 134 + if (!time_left) 135 + return -ETIMEDOUT; 136 + 137 + rxdata = readb(priv->base + I2C_LS2X_SR); 138 + if (rxdatap) 139 + *rxdatap = rxdata; 140 + 141 + return 0; 142 + } 143 + 144 + static int ls2x_i2c_send_byte(struct ls2x_i2c_priv *priv, u8 txdata) 145 + { 146 + int ret; 147 + u8 rxdata; 148 + 149 + ret = ls2x_i2c_xfer_byte(priv, txdata, &rxdata); 150 + if (ret) 151 + return ret; 152 + 153 + if (rxdata & LS2X_SR_AL) 154 + return -EAGAIN; 155 + 156 + if (rxdata & LS2X_SR_NOACK) 157 + return -ENXIO; 158 + 159 + return 0; 160 + } 161 + 162 + static int ls2x_i2c_stop(struct ls2x_i2c_priv *priv) 163 + { 164 + u8 value; 165 + 166 + writeb(LS2X_CR_STOP, priv->base + I2C_LS2X_CR); 167 + return readb_poll_timeout(priv->base + I2C_LS2X_SR, value, 168 + !(value & LS2X_SR_BUSY), 100, 169 + jiffies_to_usecs(priv->adapter.timeout)); 170 + } 171 + 172 + static int ls2x_i2c_start(struct ls2x_i2c_priv *priv, struct i2c_msg *msgs) 173 + { 174 + reinit_completion(&priv->cmd_complete); 175 + 176 + writeb(i2c_8bit_addr_from_msg(msgs), priv->base + I2C_LS2X_TXR); 177 + return ls2x_i2c_send_byte(priv, LS2X_CR_START | LS2X_CR_WRITE); 178 + } 179 + 180 + static int ls2x_i2c_rx(struct ls2x_i2c_priv *priv, struct i2c_msg *msg) 181 + { 182 + int ret; 183 + u8 rxdata, *buf = msg->buf; 184 + u16 len = msg->len; 185 + 186 + /* Contains steps to send start condition and address. */ 187 + ret = ls2x_i2c_start(priv, msg); 188 + if (ret) 189 + return ret; 190 + 191 + while (len--) { 192 + ret = ls2x_i2c_xfer_byte(priv, 193 + LS2X_CR_READ | (len ? 0 : LS2X_CR_ACK), 194 + &rxdata); 195 + if (ret) 196 + return ret; 197 + 198 + *buf++ = readb(priv->base + I2C_LS2X_RXR); 199 + } 200 + 201 + return 0; 202 + } 203 + 204 + static int ls2x_i2c_tx(struct ls2x_i2c_priv *priv, struct i2c_msg *msg) 205 + { 206 + int ret; 207 + u8 *buf = msg->buf; 208 + u16 len = msg->len; 209 + 210 + /* Contains steps to send start condition and address. */ 211 + ret = ls2x_i2c_start(priv, msg); 212 + if (ret) 213 + return ret; 214 + 215 + while (len--) { 216 + writeb(*buf++, priv->base + I2C_LS2X_TXR); 217 + 218 + ret = ls2x_i2c_send_byte(priv, LS2X_CR_WRITE); 219 + if (ret) 220 + return ret; 221 + } 222 + 223 + return 0; 224 + } 225 + 226 + static int ls2x_i2c_xfer_one(struct ls2x_i2c_priv *priv, 227 + struct i2c_msg *msg, bool stop) 228 + { 229 + int ret; 230 + 231 + if (msg->flags & I2C_M_RD) 232 + ret = ls2x_i2c_rx(priv, msg); 233 + else 234 + ret = ls2x_i2c_tx(priv, msg); 235 + 236 + if (ret < 0) { 237 + /* Fatel error. Needs reinit. */ 238 + if (ret == -ETIMEDOUT) 239 + ls2x_i2c_init(priv); 240 + 241 + return ret; 242 + } 243 + 244 + if (stop) { 245 + /* Failed to issue STOP. Needs reinit. */ 246 + ret = ls2x_i2c_stop(priv); 247 + if (ret) 248 + ls2x_i2c_init(priv); 249 + } 250 + 251 + return ret; 252 + } 253 + 254 + static int ls2x_i2c_master_xfer(struct i2c_adapter *adap, 255 + struct i2c_msg *msgs, int num) 256 + { 257 + int ret; 258 + struct i2c_msg *msg, *emsg = msgs + num; 259 + struct ls2x_i2c_priv *priv = i2c_get_adapdata(adap); 260 + 261 + for (msg = msgs; msg < emsg; msg++) { 262 + ret = ls2x_i2c_xfer_one(priv, msg, msg == emsg - 1); 263 + if (ret) 264 + return ret; 265 + } 266 + 267 + return num; 268 + } 269 + 270 + static unsigned int ls2x_i2c_func(struct i2c_adapter *adap) 271 + { 272 + return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; 273 + } 274 + 275 + static const struct i2c_algorithm ls2x_i2c_algo = { 276 + .master_xfer = ls2x_i2c_master_xfer, 277 + .functionality = ls2x_i2c_func, 278 + }; 279 + 280 + static int ls2x_i2c_probe(struct platform_device *pdev) 281 + { 282 + int ret, irq; 283 + struct i2c_adapter *adap; 284 + struct ls2x_i2c_priv *priv; 285 + struct device *dev = &pdev->dev; 286 + 287 + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 288 + if (!priv) 289 + return -ENOMEM; 290 + 291 + /* Map hardware registers */ 292 + priv->base = devm_platform_ioremap_resource(pdev, 0); 293 + if (IS_ERR(priv->base)) 294 + return PTR_ERR(priv->base); 295 + 296 + irq = platform_get_irq(pdev, 0); 297 + if (irq < 0) 298 + return irq; 299 + 300 + /* Add the i2c adapter */ 301 + adap = &priv->adapter; 302 + adap->retries = 5; 303 + adap->nr = pdev->id; 304 + adap->dev.parent = dev; 305 + adap->owner = THIS_MODULE; 306 + adap->algo = &ls2x_i2c_algo; 307 + adap->timeout = msecs_to_jiffies(100); 308 + device_set_node(&adap->dev, dev_fwnode(dev)); 309 + i2c_set_adapdata(adap, priv); 310 + strscpy(adap->name, pdev->name, sizeof(adap->name)); 311 + init_completion(&priv->cmd_complete); 312 + platform_set_drvdata(pdev, priv); 313 + 314 + ls2x_i2c_init(priv); 315 + 316 + ret = devm_request_irq(dev, irq, ls2x_i2c_isr, IRQF_SHARED, "ls2x-i2c", 317 + priv); 318 + if (ret < 0) 319 + return dev_err_probe(dev, ret, "Unable to request irq %d\n", irq); 320 + 321 + return devm_i2c_add_adapter(dev, adap); 322 + } 323 + 324 + static int ls2x_i2c_suspend(struct device *dev) 325 + { 326 + struct ls2x_i2c_priv *priv = dev_get_drvdata(dev); 327 + 328 + /* Disable interrupts */ 329 + writeb(readb(priv->base + I2C_LS2X_CTR) & ~LS2X_CTR_IEN, 330 + priv->base + I2C_LS2X_CTR); 331 + 332 + return 0; 333 + } 334 + 335 + static int ls2x_i2c_resume(struct device *dev) 336 + { 337 + ls2x_i2c_init(dev_get_drvdata(dev)); 338 + return 0; 339 + } 340 + 341 + static DEFINE_RUNTIME_DEV_PM_OPS(ls2x_i2c_pm_ops, 342 + ls2x_i2c_suspend, ls2x_i2c_resume, NULL); 343 + 344 + static const struct of_device_id ls2x_i2c_id_table[] = { 345 + { .compatible = "loongson,ls2k-i2c" }, 346 + { .compatible = "loongson,ls7a-i2c" }, 347 + { /* sentinel */ } 348 + }; 349 + MODULE_DEVICE_TABLE(of, ls2x_i2c_id_table); 350 + 351 + static const struct acpi_device_id ls2x_i2c_acpi_match[] = { 352 + { "LOON0004" }, /* Loongson LS7A */ 353 + { } 354 + }; 355 + MODULE_DEVICE_TABLE(acpi, ls2x_i2c_acpi_match); 356 + 357 + static struct platform_driver ls2x_i2c_driver = { 358 + .probe = ls2x_i2c_probe, 359 + .driver = { 360 + .name = "ls2x-i2c", 361 + .pm = pm_sleep_ptr(&ls2x_i2c_pm_ops), 362 + .of_match_table = ls2x_i2c_id_table, 363 + .acpi_match_table = ls2x_i2c_acpi_match, 364 + }, 365 + }; 366 + module_platform_driver(ls2x_i2c_driver); 367 + 368 + MODULE_DESCRIPTION("Loongson LS2X I2C Bus driver"); 369 + MODULE_AUTHOR("Loongson Technology Corporation Limited"); 370 + MODULE_LICENSE("GPL");
+2 -5
drivers/i2c/busses/i2c-mt65xx.c
··· 1366 1366 { 1367 1367 int ret = 0; 1368 1368 struct mtk_i2c *i2c; 1369 - struct resource *res; 1370 1369 int i, irq, speed_clk; 1371 1370 1372 1371 i2c = devm_kzalloc(&pdev->dev, sizeof(*i2c), GFP_KERNEL); 1373 1372 if (!i2c) 1374 1373 return -ENOMEM; 1375 1374 1376 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1377 - i2c->base = devm_ioremap_resource(&pdev->dev, res); 1375 + i2c->base = devm_platform_get_and_ioremap_resource(pdev, 0, NULL); 1378 1376 if (IS_ERR(i2c->base)) 1379 1377 return PTR_ERR(i2c->base); 1380 1378 1381 - res = platform_get_resource(pdev, IORESOURCE_MEM, 1); 1382 - i2c->pdmabase = devm_ioremap_resource(&pdev->dev, res); 1379 + i2c->pdmabase = devm_platform_get_and_ioremap_resource(pdev, 1, NULL); 1383 1380 if (IS_ERR(i2c->pdmabase)) 1384 1381 return PTR_ERR(i2c->pdmabase); 1385 1382
+7 -1
drivers/i2c/busses/i2c-qcom-cci.c
··· 811 811 812 812 static const struct of_device_id cci_dt_match[] = { 813 813 { .compatible = "qcom,msm8226-cci", .data = &cci_v1_data}, 814 - { .compatible = "qcom,msm8916-cci", .data = &cci_v1_data}, 815 814 { .compatible = "qcom,msm8974-cci", .data = &cci_v1_5_data}, 816 815 { .compatible = "qcom,msm8996-cci", .data = &cci_v2_data}, 816 + 817 + 818 + /* 819 + * Legacy compatibles kept for backwards compatibility. 820 + * Do not add any new ones unless they introduce a new config 821 + */ 822 + { .compatible = "qcom,msm8916-cci", .data = &cci_v1_data}, 817 823 { .compatible = "qcom,sdm845-cci", .data = &cci_v2_data}, 818 824 { .compatible = "qcom,sm8250-cci", .data = &cci_v2_data}, 819 825 { .compatible = "qcom,sm8450-cci", .data = &cci_v2_data},
+1 -1
drivers/i2c/busses/i2c-qcom-geni.c
··· 1025 1025 NULL) 1026 1026 }; 1027 1027 1028 - const struct geni_i2c_desc i2c_master_hub = { 1028 + static const struct geni_i2c_desc i2c_master_hub = { 1029 1029 .has_core_clk = true, 1030 1030 .icc_ddr = NULL, 1031 1031 .no_dma_support = true,
+2 -7
drivers/i2c/busses/i2c-st.c
··· 740 740 return (ret < 0) ? ret : i; 741 741 } 742 742 743 - #ifdef CONFIG_PM_SLEEP 744 743 static int st_i2c_suspend(struct device *dev) 745 744 { 746 745 struct st_i2c_dev *i2c_dev = dev_get_drvdata(dev); ··· 761 762 return 0; 762 763 } 763 764 764 - static SIMPLE_DEV_PM_OPS(st_i2c_pm, st_i2c_suspend, st_i2c_resume); 765 - #define ST_I2C_PM (&st_i2c_pm) 766 - #else 767 - #define ST_I2C_PM NULL 768 - #endif 765 + static DEFINE_SIMPLE_DEV_PM_OPS(st_i2c_pm, st_i2c_suspend, st_i2c_resume); 769 766 770 767 static u32 st_i2c_func(struct i2c_adapter *adap) 771 768 { ··· 896 901 .driver = { 897 902 .name = "st-i2c", 898 903 .of_match_table = st_i2c_match, 899 - .pm = ST_I2C_PM, 904 + .pm = pm_sleep_ptr(&st_i2c_pm), 900 905 }, 901 906 .probe = st_i2c_probe, 902 907 .remove = st_i2c_remove,
+532 -56
drivers/i2c/busses/i2c-xiic.c
··· 32 32 #include <linux/pm_runtime.h> 33 33 34 34 #define DRIVER_NAME "xiic-i2c" 35 + #define DYNAMIC_MODE_READ_BROKEN_BIT BIT(0) 36 + #define SMBUS_BLOCK_READ_MIN_LEN 3 35 37 36 38 enum xilinx_i2c_state { 37 39 STATE_DONE, ··· 44 42 enum xiic_endian { 45 43 LITTLE, 46 44 BIG 45 + }; 46 + 47 + enum i2c_scl_freq { 48 + REG_VALUES_100KHZ = 0, 49 + REG_VALUES_400KHZ = 1, 50 + REG_VALUES_1MHZ = 2 47 51 }; 48 52 49 53 /** ··· 68 60 * @clk: Pointer to AXI4-lite input clock 69 61 * @state: See STATE_ 70 62 * @singlemaster: Indicates bus is single master 63 + * @dynamic: Mode of controller 64 + * @prev_msg_tx: Previous message is Tx 65 + * @quirks: To hold platform specific bug info 66 + * @smbus_block_read: Flag to handle block read 67 + * @input_clk: Input clock to I2C controller 68 + * @i2c_clk: I2C SCL frequency 71 69 */ 72 70 struct xiic_i2c { 73 71 struct device *dev; ··· 90 76 struct clk *clk; 91 77 enum xilinx_i2c_state state; 92 78 bool singlemaster; 79 + bool dynamic; 80 + bool prev_msg_tx; 81 + u32 quirks; 82 + bool smbus_block_read; 83 + unsigned long input_clk; 84 + unsigned int i2c_clk; 85 + }; 86 + 87 + struct xiic_version_data { 88 + u32 quirks; 89 + }; 90 + 91 + /** 92 + * struct timing_regs - AXI I2C timing registers that depend on I2C spec 93 + * @tsusta: setup time for a repeated START condition 94 + * @tsusto: setup time for a STOP condition 95 + * @thdsta: hold time for a repeated START condition 96 + * @tsudat: setup time for data 97 + * @tbuf: bus free time between STOP and START 98 + */ 99 + struct timing_regs { 100 + unsigned int tsusta; 101 + unsigned int tsusto; 102 + unsigned int thdsta; 103 + unsigned int tsudat; 104 + unsigned int tbuf; 105 + }; 106 + 107 + /* Reg values in ns derived from I2C spec and AXI I2C PG for different frequencies */ 108 + static const struct timing_regs timing_reg_values[] = { 109 + { 5700, 5000, 4300, 550, 5000 }, /* Reg values for 100KHz */ 110 + { 900, 900, 900, 400, 1600 }, /* Reg values for 400KHz */ 111 + { 380, 380, 380, 170, 620 }, /* Reg values for 1MHz */ 93 112 }; 94 113 95 114 #define XIIC_MSB_OFFSET 0 ··· 142 95 #define XIIC_TBA_REG_OFFSET (0x1C + XIIC_REG_OFFSET) /* 10 Bit Address reg */ 143 96 #define XIIC_RFD_REG_OFFSET (0x20 + XIIC_REG_OFFSET) /* Rx FIFO Depth reg */ 144 97 #define XIIC_GPO_REG_OFFSET (0x24 + XIIC_REG_OFFSET) /* Output Register */ 98 + 99 + /* 100 + * Timing register offsets from RegisterBase. These are used only for 101 + * setting i2c clock frequency for the line. 102 + */ 103 + #define XIIC_TSUSTA_REG_OFFSET (0x28 + XIIC_REG_OFFSET) /* TSUSTA Register */ 104 + #define XIIC_TSUSTO_REG_OFFSET (0x2C + XIIC_REG_OFFSET) /* TSUSTO Register */ 105 + #define XIIC_THDSTA_REG_OFFSET (0x30 + XIIC_REG_OFFSET) /* THDSTA Register */ 106 + #define XIIC_TSUDAT_REG_OFFSET (0x34 + XIIC_REG_OFFSET) /* TSUDAT Register */ 107 + #define XIIC_TBUF_REG_OFFSET (0x38 + XIIC_REG_OFFSET) /* TBUF Register */ 108 + #define XIIC_THIGH_REG_OFFSET (0x3C + XIIC_REG_OFFSET) /* THIGH Register */ 109 + #define XIIC_TLOW_REG_OFFSET (0x40 + XIIC_REG_OFFSET) /* TLOW Register */ 110 + #define XIIC_THDDAT_REG_OFFSET (0x44 + XIIC_REG_OFFSET) /* THDDAT Register */ 145 111 146 112 /* Control Register masks */ 147 113 #define XIIC_CR_ENABLE_DEVICE_MASK 0x01 /* Device enable = 1 */ ··· 202 142 */ 203 143 #define XIIC_TX_DYN_START_MASK 0x0100 /* 1 = Set dynamic start */ 204 144 #define XIIC_TX_DYN_STOP_MASK 0x0200 /* 1 = Set dynamic stop */ 145 + 146 + /* Dynamic mode constants */ 147 + #define MAX_READ_LENGTH_DYNAMIC 255 /* Max length for dynamic read */ 205 148 206 149 /* 207 150 * The following constants define the register offsets for the Interrupt ··· 338 275 return 0; 339 276 } 340 277 278 + static int xiic_wait_tx_empty(struct xiic_i2c *i2c) 279 + { 280 + u8 isr; 281 + unsigned long timeout; 282 + 283 + timeout = jiffies + XIIC_I2C_TIMEOUT; 284 + for (isr = xiic_getreg32(i2c, XIIC_IISR_OFFSET); 285 + !(isr & XIIC_INTR_TX_EMPTY_MASK); 286 + isr = xiic_getreg32(i2c, XIIC_IISR_OFFSET)) { 287 + if (time_after(jiffies, timeout)) { 288 + dev_err(i2c->dev, "Timeout waiting at Tx empty\n"); 289 + return -ETIMEDOUT; 290 + } 291 + } 292 + 293 + return 0; 294 + } 295 + 296 + /** 297 + * xiic_setclk - Sets the configured clock rate 298 + * @i2c: Pointer to the xiic device structure 299 + * 300 + * The timing register values are calculated according to the input clock 301 + * frequency and configured scl frequency. For details, please refer the 302 + * AXI I2C PG and NXP I2C Spec. 303 + * Supported frequencies are 100KHz, 400KHz and 1MHz. 304 + * 305 + * Return: 0 on success (Supported frequency selected or not configurable in SW) 306 + * -EINVAL on failure (scl frequency not supported or THIGH is 0) 307 + */ 308 + static int xiic_setclk(struct xiic_i2c *i2c) 309 + { 310 + unsigned int clk_in_mhz; 311 + unsigned int index = 0; 312 + u32 reg_val; 313 + 314 + dev_dbg(i2c->adap.dev.parent, 315 + "%s entry, i2c->input_clk: %ld, i2c->i2c_clk: %d\n", 316 + __func__, i2c->input_clk, i2c->i2c_clk); 317 + 318 + /* If not specified in DT, do not configure in SW. Rely only on Vivado design */ 319 + if (!i2c->i2c_clk || !i2c->input_clk) 320 + return 0; 321 + 322 + clk_in_mhz = DIV_ROUND_UP(i2c->input_clk, 1000000); 323 + 324 + switch (i2c->i2c_clk) { 325 + case I2C_MAX_FAST_MODE_PLUS_FREQ: 326 + index = REG_VALUES_1MHZ; 327 + break; 328 + case I2C_MAX_FAST_MODE_FREQ: 329 + index = REG_VALUES_400KHZ; 330 + break; 331 + case I2C_MAX_STANDARD_MODE_FREQ: 332 + index = REG_VALUES_100KHZ; 333 + break; 334 + default: 335 + dev_warn(i2c->adap.dev.parent, "Unsupported scl frequency\n"); 336 + return -EINVAL; 337 + } 338 + 339 + /* 340 + * Value to be stored in a register is the number of clock cycles required 341 + * for the time duration. So the time is divided by the input clock time 342 + * period to get the number of clock cycles required. Refer Xilinx AXI I2C 343 + * PG document and I2C specification for further details. 344 + */ 345 + 346 + /* THIGH - Depends on SCL clock frequency(i2c_clk) as below */ 347 + reg_val = (DIV_ROUND_UP(i2c->input_clk, 2 * i2c->i2c_clk)) - 7; 348 + if (reg_val == 0) 349 + return -EINVAL; 350 + 351 + xiic_setreg32(i2c, XIIC_THIGH_REG_OFFSET, reg_val - 1); 352 + 353 + /* TLOW - Value same as THIGH */ 354 + xiic_setreg32(i2c, XIIC_TLOW_REG_OFFSET, reg_val - 1); 355 + 356 + /* TSUSTA */ 357 + reg_val = (timing_reg_values[index].tsusta * clk_in_mhz) / 1000; 358 + xiic_setreg32(i2c, XIIC_TSUSTA_REG_OFFSET, reg_val - 1); 359 + 360 + /* TSUSTO */ 361 + reg_val = (timing_reg_values[index].tsusto * clk_in_mhz) / 1000; 362 + xiic_setreg32(i2c, XIIC_TSUSTO_REG_OFFSET, reg_val - 1); 363 + 364 + /* THDSTA */ 365 + reg_val = (timing_reg_values[index].thdsta * clk_in_mhz) / 1000; 366 + xiic_setreg32(i2c, XIIC_THDSTA_REG_OFFSET, reg_val - 1); 367 + 368 + /* TSUDAT */ 369 + reg_val = (timing_reg_values[index].tsudat * clk_in_mhz) / 1000; 370 + xiic_setreg32(i2c, XIIC_TSUDAT_REG_OFFSET, reg_val - 1); 371 + 372 + /* TBUF */ 373 + reg_val = (timing_reg_values[index].tbuf * clk_in_mhz) / 1000; 374 + xiic_setreg32(i2c, XIIC_TBUF_REG_OFFSET, reg_val - 1); 375 + 376 + /* THDDAT */ 377 + xiic_setreg32(i2c, XIIC_THDDAT_REG_OFFSET, 1); 378 + 379 + return 0; 380 + } 381 + 341 382 static int xiic_reinit(struct xiic_i2c *i2c) 342 383 { 343 384 int ret; 344 385 345 386 xiic_setreg32(i2c, XIIC_RESETR_OFFSET, XIIC_RESET_MASK); 387 + 388 + ret = xiic_setclk(i2c); 389 + if (ret) 390 + return ret; 346 391 347 392 /* Set receive Fifo depth to maximum (zero based). */ 348 393 xiic_setreg8(i2c, XIIC_RFD_REG_OFFSET, IIC_RX_FIFO_DEPTH - 1); ··· 485 314 xiic_setreg8(i2c, XIIC_CR_REG_OFFSET, cr & ~XIIC_CR_ENABLE_DEVICE_MASK); 486 315 } 487 316 317 + static void xiic_smbus_block_read_setup(struct xiic_i2c *i2c) 318 + { 319 + u8 rxmsg_len, rfd_set = 0; 320 + 321 + /* 322 + * Clear the I2C_M_RECV_LEN flag to avoid setting 323 + * message length again 324 + */ 325 + i2c->rx_msg->flags &= ~I2C_M_RECV_LEN; 326 + 327 + /* Set smbus_block_read flag to identify in isr */ 328 + i2c->smbus_block_read = true; 329 + 330 + /* Read byte from rx fifo and set message length */ 331 + rxmsg_len = xiic_getreg8(i2c, XIIC_DRR_REG_OFFSET); 332 + 333 + i2c->rx_msg->buf[i2c->rx_pos++] = rxmsg_len; 334 + 335 + /* Check if received length is valid */ 336 + if (rxmsg_len <= I2C_SMBUS_BLOCK_MAX) { 337 + /* Set Receive fifo depth */ 338 + if (rxmsg_len > IIC_RX_FIFO_DEPTH) { 339 + /* 340 + * When Rx msg len greater than or equal to Rx fifo capacity 341 + * Receive fifo depth should set to Rx fifo capacity minus 1 342 + */ 343 + rfd_set = IIC_RX_FIFO_DEPTH - 1; 344 + i2c->rx_msg->len = rxmsg_len + 1; 345 + } else if ((rxmsg_len == 1) || 346 + (rxmsg_len == 0)) { 347 + /* 348 + * Minimum of 3 bytes required to exit cleanly. 1 byte 349 + * already received, Second byte is being received. Have 350 + * to set NACK in read_rx before receiving the last byte 351 + */ 352 + rfd_set = 0; 353 + i2c->rx_msg->len = SMBUS_BLOCK_READ_MIN_LEN; 354 + } else { 355 + /* 356 + * When Rx msg len less than Rx fifo capacity 357 + * Receive fifo depth should set to Rx msg len minus 2 358 + */ 359 + rfd_set = rxmsg_len - 2; 360 + i2c->rx_msg->len = rxmsg_len + 1; 361 + } 362 + xiic_setreg8(i2c, XIIC_RFD_REG_OFFSET, rfd_set); 363 + 364 + return; 365 + } 366 + 367 + /* Invalid message length, trigger STATE_ERROR with tx_msg_len in ISR */ 368 + i2c->tx_msg->len = 3; 369 + i2c->smbus_block_read = false; 370 + dev_err(i2c->adap.dev.parent, "smbus_block_read Invalid msg length\n"); 371 + } 372 + 488 373 static void xiic_read_rx(struct xiic_i2c *i2c) 489 374 { 490 - u8 bytes_in_fifo; 375 + u8 bytes_in_fifo, cr = 0, bytes_to_read = 0; 376 + u32 bytes_rem = 0; 491 377 int i; 492 378 493 379 bytes_in_fifo = xiic_getreg8(i2c, XIIC_RFO_REG_OFFSET) + 1; 494 380 495 381 dev_dbg(i2c->adap.dev.parent, 496 - "%s entry, bytes in fifo: %d, msg: %d, SR: 0x%x, CR: 0x%x\n", 382 + "%s entry, bytes in fifo: %d, rem: %d, SR: 0x%x, CR: 0x%x\n", 497 383 __func__, bytes_in_fifo, xiic_rx_space(i2c), 498 384 xiic_getreg8(i2c, XIIC_SR_REG_OFFSET), 499 385 xiic_getreg8(i2c, XIIC_CR_REG_OFFSET)); ··· 558 330 if (bytes_in_fifo > xiic_rx_space(i2c)) 559 331 bytes_in_fifo = xiic_rx_space(i2c); 560 332 561 - for (i = 0; i < bytes_in_fifo; i++) 333 + bytes_to_read = bytes_in_fifo; 334 + 335 + if (!i2c->dynamic) { 336 + bytes_rem = xiic_rx_space(i2c) - bytes_in_fifo; 337 + 338 + /* Set msg length if smbus_block_read */ 339 + if (i2c->rx_msg->flags & I2C_M_RECV_LEN) { 340 + xiic_smbus_block_read_setup(i2c); 341 + return; 342 + } 343 + 344 + if (bytes_rem > IIC_RX_FIFO_DEPTH) { 345 + bytes_to_read = bytes_in_fifo; 346 + } else if (bytes_rem > 1) { 347 + bytes_to_read = bytes_rem - 1; 348 + } else if (bytes_rem == 1) { 349 + bytes_to_read = 1; 350 + /* Set NACK in CR to indicate slave transmitter */ 351 + cr = xiic_getreg8(i2c, XIIC_CR_REG_OFFSET); 352 + xiic_setreg8(i2c, XIIC_CR_REG_OFFSET, cr | 353 + XIIC_CR_NO_ACK_MASK); 354 + } else if (bytes_rem == 0) { 355 + bytes_to_read = bytes_in_fifo; 356 + 357 + /* Generate stop on the bus if it is last message */ 358 + if (i2c->nmsgs == 1) { 359 + cr = xiic_getreg8(i2c, XIIC_CR_REG_OFFSET); 360 + xiic_setreg8(i2c, XIIC_CR_REG_OFFSET, cr & 361 + ~XIIC_CR_MSMS_MASK); 362 + } 363 + 364 + /* Make TXACK=0, clean up for next transaction */ 365 + cr = xiic_getreg8(i2c, XIIC_CR_REG_OFFSET); 366 + xiic_setreg8(i2c, XIIC_CR_REG_OFFSET, cr & 367 + ~XIIC_CR_NO_ACK_MASK); 368 + } 369 + } 370 + 371 + /* Read the fifo */ 372 + for (i = 0; i < bytes_to_read; i++) { 562 373 i2c->rx_msg->buf[i2c->rx_pos++] = 563 374 xiic_getreg8(i2c, XIIC_DRR_REG_OFFSET); 375 + } 564 376 565 - xiic_setreg8(i2c, XIIC_RFD_REG_OFFSET, 566 - (xiic_rx_space(i2c) > IIC_RX_FIFO_DEPTH) ? 567 - IIC_RX_FIFO_DEPTH - 1 : xiic_rx_space(i2c) - 1); 377 + if (i2c->dynamic) { 378 + u8 bytes; 379 + 380 + /* Receive remaining bytes if less than fifo depth */ 381 + bytes = min_t(u8, xiic_rx_space(i2c), IIC_RX_FIFO_DEPTH); 382 + bytes--; 383 + xiic_setreg8(i2c, XIIC_RFD_REG_OFFSET, bytes); 384 + } 568 385 } 569 386 570 387 static int xiic_tx_fifo_space(struct xiic_i2c *i2c) ··· 633 360 634 361 if (!xiic_tx_space(i2c) && i2c->nmsgs == 1) { 635 362 /* last message in transfer -> STOP */ 636 - data |= XIIC_TX_DYN_STOP_MASK; 363 + if (i2c->dynamic) { 364 + data |= XIIC_TX_DYN_STOP_MASK; 365 + } else { 366 + u8 cr; 367 + int status; 368 + 369 + /* Wait till FIFO is empty so STOP is sent last */ 370 + status = xiic_wait_tx_empty(i2c); 371 + if (status) 372 + return; 373 + 374 + /* Write to CR to stop */ 375 + cr = xiic_getreg8(i2c, XIIC_CR_REG_OFFSET); 376 + xiic_setreg8(i2c, XIIC_CR_REG_OFFSET, cr & 377 + ~XIIC_CR_MSMS_MASK); 378 + } 637 379 dev_dbg(i2c->adap.dev.parent, "%s TX STOP\n", __func__); 638 380 } 639 381 xiic_setreg16(i2c, XIIC_DTR_REG_OFFSET, data); ··· 689 401 dev_dbg(i2c->adap.dev.parent, "%s: SR: 0x%x, msg: %p, nmsgs: %d\n", 690 402 __func__, xiic_getreg8(i2c, XIIC_SR_REG_OFFSET), 691 403 i2c->tx_msg, i2c->nmsgs); 692 - 404 + dev_dbg(i2c->adap.dev.parent, "%s, ISR: 0x%x, CR: 0x%x\n", 405 + __func__, xiic_getreg32(i2c, XIIC_IISR_OFFSET), 406 + xiic_getreg8(i2c, XIIC_CR_REG_OFFSET)); 693 407 694 408 /* Service requesting interrupt */ 695 409 if ((pend & XIIC_INTR_ARB_LOST_MASK) || ··· 802 512 /* The bus is not busy, disable BusNotBusy interrupt */ 803 513 xiic_irq_dis(i2c, XIIC_INTR_BNB_MASK); 804 514 515 + if (i2c->tx_msg && i2c->smbus_block_read) { 516 + i2c->smbus_block_read = false; 517 + /* Set requested message len=1 to indicate STATE_DONE */ 518 + i2c->tx_msg->len = 1; 519 + } 520 + 805 521 if (!i2c->tx_msg) 806 522 goto out; 807 523 ··· 875 579 static void xiic_start_recv(struct xiic_i2c *i2c) 876 580 { 877 581 u16 rx_watermark; 582 + u8 cr = 0, rfd_set = 0; 878 583 struct i2c_msg *msg = i2c->rx_msg = i2c->tx_msg; 879 584 880 - /* Clear and enable Rx full interrupt. */ 881 - xiic_irq_clr_en(i2c, XIIC_INTR_RX_FULL_MASK | XIIC_INTR_TX_ERROR_MASK); 585 + dev_dbg(i2c->adap.dev.parent, "%s entry, ISR: 0x%x, CR: 0x%x\n", 586 + __func__, xiic_getreg32(i2c, XIIC_IISR_OFFSET), 587 + xiic_getreg8(i2c, XIIC_CR_REG_OFFSET)); 882 588 883 - /* we want to get all but last byte, because the TX_ERROR IRQ is used 884 - * to inidicate error ACK on the address, and negative ack on the last 885 - * received byte, so to not mix them receive all but last. 886 - * In the case where there is only one byte to receive 887 - * we can check if ERROR and RX full is set at the same time 888 - */ 889 - rx_watermark = msg->len; 890 - if (rx_watermark > IIC_RX_FIFO_DEPTH) 891 - rx_watermark = IIC_RX_FIFO_DEPTH; 892 - xiic_setreg8(i2c, XIIC_RFD_REG_OFFSET, (u8)(rx_watermark - 1)); 589 + /* Disable Tx interrupts */ 590 + xiic_irq_dis(i2c, XIIC_INTR_TX_HALF_MASK | XIIC_INTR_TX_EMPTY_MASK); 893 591 894 - if (!(msg->flags & I2C_M_NOSTART)) 592 + if (i2c->dynamic) { 593 + u8 bytes; 594 + u16 val; 595 + 596 + /* Clear and enable Rx full interrupt. */ 597 + xiic_irq_clr_en(i2c, XIIC_INTR_RX_FULL_MASK | 598 + XIIC_INTR_TX_ERROR_MASK); 599 + 600 + /* 601 + * We want to get all but last byte, because the TX_ERROR IRQ 602 + * is used to indicate error ACK on the address, and 603 + * negative ack on the last received byte, so to not mix 604 + * them receive all but last. 605 + * In the case where there is only one byte to receive 606 + * we can check if ERROR and RX full is set at the same time 607 + */ 608 + rx_watermark = msg->len; 609 + bytes = min_t(u8, rx_watermark, IIC_RX_FIFO_DEPTH); 610 + 611 + if (rx_watermark > 0) 612 + bytes--; 613 + xiic_setreg8(i2c, XIIC_RFD_REG_OFFSET, bytes); 614 + 895 615 /* write the address */ 896 616 xiic_setreg16(i2c, XIIC_DTR_REG_OFFSET, 897 - i2c_8bit_addr_from_msg(msg) | XIIC_TX_DYN_START_MASK); 617 + i2c_8bit_addr_from_msg(msg) | 618 + XIIC_TX_DYN_START_MASK); 898 619 899 - xiic_irq_clr_en(i2c, XIIC_INTR_BNB_MASK); 620 + /* If last message, include dynamic stop bit with length */ 621 + val = (i2c->nmsgs == 1) ? XIIC_TX_DYN_STOP_MASK : 0; 622 + val |= msg->len; 900 623 901 - xiic_setreg16(i2c, XIIC_DTR_REG_OFFSET, 902 - msg->len | ((i2c->nmsgs == 1) ? XIIC_TX_DYN_STOP_MASK : 0)); 624 + xiic_setreg16(i2c, XIIC_DTR_REG_OFFSET, val); 625 + 626 + xiic_irq_clr_en(i2c, XIIC_INTR_BNB_MASK); 627 + } else { 628 + /* 629 + * If previous message is Tx, make sure that Tx FIFO is empty 630 + * before starting a new transfer as the repeated start in 631 + * standard mode can corrupt the transaction if there are 632 + * still bytes to be transmitted in FIFO 633 + */ 634 + if (i2c->prev_msg_tx) { 635 + int status; 636 + 637 + status = xiic_wait_tx_empty(i2c); 638 + if (status) 639 + return; 640 + } 641 + 642 + cr = xiic_getreg8(i2c, XIIC_CR_REG_OFFSET); 643 + 644 + /* Set Receive fifo depth */ 645 + rx_watermark = msg->len; 646 + if (rx_watermark > IIC_RX_FIFO_DEPTH) { 647 + rfd_set = IIC_RX_FIFO_DEPTH - 1; 648 + } else if (rx_watermark == 1) { 649 + rfd_set = rx_watermark - 1; 650 + 651 + /* Set No_ACK, except for smbus_block_read */ 652 + if (!(i2c->rx_msg->flags & I2C_M_RECV_LEN)) { 653 + /* Handle single byte transfer separately */ 654 + cr |= XIIC_CR_NO_ACK_MASK; 655 + } 656 + } else if (rx_watermark == 0) { 657 + rfd_set = rx_watermark; 658 + } else { 659 + rfd_set = rx_watermark - 2; 660 + } 661 + /* Check if RSTA should be set */ 662 + if (cr & XIIC_CR_MSMS_MASK) { 663 + /* Already a master, RSTA should be set */ 664 + xiic_setreg8(i2c, XIIC_CR_REG_OFFSET, (cr | 665 + XIIC_CR_REPEATED_START_MASK) & 666 + ~(XIIC_CR_DIR_IS_TX_MASK)); 667 + } 668 + 669 + xiic_setreg8(i2c, XIIC_RFD_REG_OFFSET, rfd_set); 670 + 671 + /* Clear and enable Rx full and transmit complete interrupts */ 672 + xiic_irq_clr_en(i2c, XIIC_INTR_RX_FULL_MASK | 673 + XIIC_INTR_TX_ERROR_MASK); 674 + 675 + /* Write the address */ 676 + xiic_setreg16(i2c, XIIC_DTR_REG_OFFSET, 677 + i2c_8bit_addr_from_msg(msg)); 678 + 679 + /* Write to Control Register,to start transaction in Rx mode */ 680 + if ((cr & XIIC_CR_MSMS_MASK) == 0) { 681 + xiic_setreg8(i2c, XIIC_CR_REG_OFFSET, (cr | 682 + XIIC_CR_MSMS_MASK) 683 + & ~(XIIC_CR_DIR_IS_TX_MASK)); 684 + } 685 + dev_dbg(i2c->adap.dev.parent, "%s end, ISR: 0x%x, CR: 0x%x\n", 686 + __func__, xiic_getreg32(i2c, XIIC_IISR_OFFSET), 687 + xiic_getreg8(i2c, XIIC_CR_REG_OFFSET)); 688 + } 903 689 904 690 if (i2c->nmsgs == 1) 905 691 /* very last, enable bus not busy as well */ ··· 989 611 990 612 /* the message is tx:ed */ 991 613 i2c->tx_pos = msg->len; 614 + 615 + /* Enable interrupts */ 616 + xiic_setreg32(i2c, XIIC_DGIER_OFFSET, XIIC_GINTR_ENABLE_MASK); 617 + 618 + i2c->prev_msg_tx = false; 992 619 } 993 620 994 621 static void xiic_start_send(struct xiic_i2c *i2c) 995 622 { 623 + u8 cr = 0; 624 + u16 data; 996 625 struct i2c_msg *msg = i2c->tx_msg; 997 626 998 627 dev_dbg(i2c->adap.dev.parent, "%s entry, msg: %p, len: %d", ··· 1008 623 __func__, xiic_getreg32(i2c, XIIC_IISR_OFFSET), 1009 624 xiic_getreg8(i2c, XIIC_CR_REG_OFFSET)); 1010 625 1011 - if (!(msg->flags & I2C_M_NOSTART)) { 626 + if (i2c->dynamic) { 1012 627 /* write the address */ 1013 - u16 data = i2c_8bit_addr_from_msg(msg) | 1014 - XIIC_TX_DYN_START_MASK; 1015 - if ((i2c->nmsgs == 1) && msg->len == 0) 628 + data = i2c_8bit_addr_from_msg(msg) | 629 + XIIC_TX_DYN_START_MASK; 630 + 631 + if (i2c->nmsgs == 1 && msg->len == 0) 1016 632 /* no data and last message -> add STOP */ 1017 633 data |= XIIC_TX_DYN_STOP_MASK; 1018 634 1019 635 xiic_setreg16(i2c, XIIC_DTR_REG_OFFSET, data); 636 + 637 + /* Clear any pending Tx empty, Tx Error and then enable them */ 638 + xiic_irq_clr_en(i2c, XIIC_INTR_TX_EMPTY_MASK | 639 + XIIC_INTR_TX_ERROR_MASK | 640 + XIIC_INTR_BNB_MASK | 641 + ((i2c->nmsgs > 1 || xiic_tx_space(i2c)) ? 642 + XIIC_INTR_TX_HALF_MASK : 0)); 643 + 644 + xiic_fill_tx_fifo(i2c); 645 + } else { 646 + /* 647 + * If previous message is Tx, make sure that Tx FIFO is empty 648 + * before starting a new transfer as the repeated start in 649 + * standard mode can corrupt the transaction if there are 650 + * still bytes to be transmitted in FIFO 651 + */ 652 + if (i2c->prev_msg_tx) { 653 + int status; 654 + 655 + status = xiic_wait_tx_empty(i2c); 656 + if (status) 657 + return; 658 + } 659 + /* Check if RSTA should be set */ 660 + cr = xiic_getreg8(i2c, XIIC_CR_REG_OFFSET); 661 + if (cr & XIIC_CR_MSMS_MASK) { 662 + /* Already a master, RSTA should be set */ 663 + xiic_setreg8(i2c, XIIC_CR_REG_OFFSET, (cr | 664 + XIIC_CR_REPEATED_START_MASK | 665 + XIIC_CR_DIR_IS_TX_MASK) & 666 + ~(XIIC_CR_NO_ACK_MASK)); 667 + } 668 + 669 + /* Write address to FIFO */ 670 + data = i2c_8bit_addr_from_msg(msg); 671 + xiic_setreg16(i2c, XIIC_DTR_REG_OFFSET, data); 672 + 673 + /* Fill fifo */ 674 + xiic_fill_tx_fifo(i2c); 675 + 676 + if ((cr & XIIC_CR_MSMS_MASK) == 0) { 677 + /* Start Tx by writing to CR */ 678 + cr = xiic_getreg8(i2c, XIIC_CR_REG_OFFSET); 679 + xiic_setreg8(i2c, XIIC_CR_REG_OFFSET, cr | 680 + XIIC_CR_MSMS_MASK | 681 + XIIC_CR_DIR_IS_TX_MASK); 682 + } 683 + 684 + /* Clear any pending Tx empty, Tx Error and then enable them */ 685 + xiic_irq_clr_en(i2c, XIIC_INTR_TX_EMPTY_MASK | 686 + XIIC_INTR_TX_ERROR_MASK | 687 + XIIC_INTR_BNB_MASK); 1020 688 } 1021 - 1022 - /* Clear any pending Tx empty, Tx Error and then enable them. */ 1023 - xiic_irq_clr_en(i2c, XIIC_INTR_TX_EMPTY_MASK | XIIC_INTR_TX_ERROR_MASK | 1024 - XIIC_INTR_BNB_MASK | 1025 - ((i2c->nmsgs > 1 || xiic_tx_space(i2c)) ? 1026 - XIIC_INTR_TX_HALF_MASK : 0)); 1027 - 1028 - xiic_fill_tx_fifo(i2c); 689 + i2c->prev_msg_tx = true; 1029 690 } 1030 691 1031 692 static void __xiic_start_xfer(struct xiic_i2c *i2c) ··· 1097 666 1098 667 static int xiic_start_xfer(struct xiic_i2c *i2c, struct i2c_msg *msgs, int num) 1099 668 { 1100 - int ret; 669 + bool broken_read, max_read_len, smbus_blk_read; 670 + int ret, count; 1101 671 1102 672 mutex_lock(&i2c->lock); 1103 673 ··· 1110 678 i2c->rx_msg = NULL; 1111 679 i2c->nmsgs = num; 1112 680 init_completion(&i2c->completion); 681 + 682 + /* Decide standard mode or Dynamic mode */ 683 + i2c->dynamic = true; 684 + 685 + /* Initialize prev message type */ 686 + i2c->prev_msg_tx = false; 687 + 688 + /* 689 + * Scan through nmsgs, use dynamic mode when none of the below three 690 + * conditions occur. We need standard mode even if one condition holds 691 + * true in the entire array of messages in a single transfer. 692 + * If read transaction as dynamic mode is broken for delayed reads 693 + * in xlnx,axi-iic-2.0 / xlnx,xps-iic-2.00.a IP versions. 694 + * If read length is > 255 bytes. 695 + * If smbus_block_read transaction. 696 + */ 697 + for (count = 0; count < i2c->nmsgs; count++) { 698 + broken_read = (i2c->quirks & DYNAMIC_MODE_READ_BROKEN_BIT) && 699 + (i2c->tx_msg[count].flags & I2C_M_RD); 700 + max_read_len = (i2c->tx_msg[count].flags & I2C_M_RD) && 701 + (i2c->tx_msg[count].len > MAX_READ_LENGTH_DYNAMIC); 702 + smbus_blk_read = (i2c->tx_msg[count].flags & I2C_M_RECV_LEN); 703 + 704 + if (broken_read || max_read_len || smbus_blk_read) { 705 + i2c->dynamic = false; 706 + break; 707 + } 708 + } 1113 709 1114 710 ret = xiic_reinit(i2c); 1115 711 if (!ret) ··· 1174 714 i2c->rx_msg = NULL; 1175 715 i2c->nmsgs = 0; 1176 716 err = -ETIMEDOUT; 1177 - } else if (err < 0) { /* Completion error */ 1178 - i2c->tx_msg = NULL; 1179 - i2c->rx_msg = NULL; 1180 - i2c->nmsgs = 0; 1181 717 } else { 1182 718 err = (i2c->state == STATE_DONE) ? num : -EIO; 1183 719 } ··· 1185 729 1186 730 static u32 xiic_func(struct i2c_adapter *adap) 1187 731 { 1188 - return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; 732 + return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_SMBUS_BLOCK_DATA; 1189 733 } 1190 734 1191 735 static const struct i2c_algorithm xiic_algorithm = { ··· 1193 737 .functionality = xiic_func, 1194 738 }; 1195 739 1196 - static const struct i2c_adapter_quirks xiic_quirks = { 1197 - .max_read_len = 255, 1198 - }; 1199 - 1200 740 static const struct i2c_adapter xiic_adapter = { 1201 741 .owner = THIS_MODULE, 1202 742 .class = I2C_CLASS_DEPRECATED, 1203 743 .algo = &xiic_algorithm, 1204 - .quirks = &xiic_quirks, 1205 744 }; 745 + 746 + static const struct xiic_version_data xiic_2_00 = { 747 + .quirks = DYNAMIC_MODE_READ_BROKEN_BIT, 748 + }; 749 + 750 + #if defined(CONFIG_OF) 751 + static const struct of_device_id xiic_of_match[] = { 752 + { .compatible = "xlnx,xps-iic-2.00.a", .data = &xiic_2_00 }, 753 + { .compatible = "xlnx,axi-iic-2.1", }, 754 + {}, 755 + }; 756 + MODULE_DEVICE_TABLE(of, xiic_of_match); 757 + #endif 1206 758 1207 759 static int xiic_i2c_probe(struct platform_device *pdev) 1208 760 { 1209 761 struct xiic_i2c *i2c; 1210 762 struct xiic_i2c_platform_data *pdata; 763 + const struct of_device_id *match; 1211 764 struct resource *res; 1212 765 int ret, irq; 1213 766 u8 i; ··· 1225 760 i2c = devm_kzalloc(&pdev->dev, sizeof(*i2c), GFP_KERNEL); 1226 761 if (!i2c) 1227 762 return -ENOMEM; 763 + 764 + match = of_match_node(xiic_of_match, pdev->dev.of_node); 765 + if (match && match->data) { 766 + const struct xiic_version_data *data = match->data; 767 + 768 + i2c->quirks = data->quirks; 769 + } 1228 770 1229 771 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1230 772 i2c->base = devm_ioremap_resource(&pdev->dev, res); ··· 1270 798 pm_runtime_use_autosuspend(i2c->dev); 1271 799 pm_runtime_set_active(i2c->dev); 1272 800 pm_runtime_enable(i2c->dev); 801 + 802 + /* SCL frequency configuration */ 803 + i2c->input_clk = clk_get_rate(i2c->clk); 804 + ret = of_property_read_u32(pdev->dev.of_node, "clock-frequency", 805 + &i2c->i2c_clk); 806 + /* If clock-frequency not specified in DT, do not configure in SW */ 807 + if (ret || i2c->i2c_clk > I2C_MAX_FAST_MODE_PLUS_FREQ) 808 + i2c->i2c_clk = 0; 809 + 1273 810 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, 1274 811 xiic_process, IRQF_ONESHOT, 1275 812 pdev->name, i2c); ··· 1322 841 i2c_new_client_device(&i2c->adap, pdata->devices + i); 1323 842 } 1324 843 844 + dev_dbg(&pdev->dev, "mmio %08lx irq %d scl clock frequency %d\n", 845 + (unsigned long)res->start, irq, i2c->i2c_clk); 846 + 1325 847 return 0; 1326 848 1327 849 err_clk_dis: ··· 1358 874 1359 875 return 0; 1360 876 } 1361 - 1362 - #if defined(CONFIG_OF) 1363 - static const struct of_device_id xiic_of_match[] = { 1364 - { .compatible = "xlnx,xps-iic-2.00.a", }, 1365 - {}, 1366 - }; 1367 - MODULE_DEVICE_TABLE(of, xiic_of_match); 1368 - #endif 1369 877 1370 878 static int __maybe_unused xiic_i2c_runtime_suspend(struct device *dev) 1371 879 {
+4 -1
drivers/i2c/i2c-core-base.c
··· 34 34 #include <linux/of.h> 35 35 #include <linux/of_irq.h> 36 36 #include <linux/pinctrl/consumer.h> 37 + #include <linux/pinctrl/devinfo.h> 37 38 #include <linux/pm_domain.h> 38 39 #include <linux/pm_runtime.h> 39 40 #include <linux/pm_wakeirq.h> ··· 283 282 { 284 283 struct i2c_bus_recovery_info *bri = adap->bus_recovery_info; 285 284 struct device *dev = &adap->dev; 286 - struct pinctrl *p = bri->pinctrl; 285 + struct pinctrl *p = bri->pinctrl ?: dev_pinctrl(dev->parent); 286 + 287 + bri->pinctrl = p; 287 288 288 289 /* 289 290 * we can't change states without pinctrl, so remove the states if
+8 -8
drivers/i2c/i2c-dev.c
··· 653 653 int res; 654 654 655 655 if (dev->type != &i2c_adapter_type) 656 - return 0; 656 + return NOTIFY_DONE; 657 657 adap = to_i2c_adapter(dev); 658 658 659 659 i2c_dev = get_free_i2c_dev(adap); 660 660 if (IS_ERR(i2c_dev)) 661 - return PTR_ERR(i2c_dev); 661 + return NOTIFY_DONE; 662 662 663 663 cdev_init(&i2c_dev->cdev, &i2cdev_fops); 664 664 i2c_dev->cdev.owner = THIS_MODULE; ··· 678 678 goto err_put_i2c_dev; 679 679 680 680 pr_debug("adapter [%s] registered as minor %d\n", adap->name, adap->nr); 681 - return 0; 681 + return NOTIFY_OK; 682 682 683 683 err_put_i2c_dev: 684 684 put_i2c_dev(i2c_dev, false); 685 - return res; 685 + return NOTIFY_DONE; 686 686 } 687 687 688 688 static int i2cdev_detach_adapter(struct device *dev, void *dummy) ··· 691 691 struct i2c_dev *i2c_dev; 692 692 693 693 if (dev->type != &i2c_adapter_type) 694 - return 0; 694 + return NOTIFY_DONE; 695 695 adap = to_i2c_adapter(dev); 696 696 697 697 i2c_dev = i2c_dev_get_by_minor(adap->nr); 698 698 if (!i2c_dev) /* attach_adapter must have failed */ 699 - return 0; 699 + return NOTIFY_DONE; 700 700 701 701 put_i2c_dev(i2c_dev, true); 702 702 703 703 pr_debug("adapter [%s] unregistered\n", adap->name); 704 - return 0; 704 + return NOTIFY_OK; 705 705 } 706 706 707 707 static int i2cdev_notifier_call(struct notifier_block *nb, unsigned long action, ··· 716 716 return i2cdev_detach_adapter(dev, NULL); 717 717 } 718 718 719 - return 0; 719 + return NOTIFY_DONE; 720 720 } 721 721 722 722 static struct notifier_block i2cdev_notifier = {
+15
include/linux/pinctrl/devinfo.h
··· 18 18 19 19 #ifdef CONFIG_PINCTRL 20 20 21 + #include <linux/device.h> 22 + 21 23 /* The device core acts as a consumer toward pinctrl */ 22 24 #include <linux/pinctrl/consumer.h> 23 25 ··· 46 44 extern int pinctrl_bind_pins(struct device *dev); 47 45 extern int pinctrl_init_done(struct device *dev); 48 46 47 + static inline struct pinctrl *dev_pinctrl(struct device *dev) 48 + { 49 + if (!dev->pins) 50 + return NULL; 51 + 52 + return dev->pins->p; 53 + } 54 + 49 55 #else 50 56 51 57 /* Stubs if we're not using pinctrl */ ··· 66 56 static inline int pinctrl_init_done(struct device *dev) 67 57 { 68 58 return 0; 59 + } 60 + 61 + static inline struct pinctrl *dev_pinctrl(struct device *dev) 62 + { 63 + return NULL; 69 64 } 70 65 71 66 #endif /* CONFIG_PINCTRL */
+9
include/linux/platform_data/i2c-gpio.h
··· 16 16 * isn't actively driven high when setting the output value high. 17 17 * gpio_get_value() must return the actual pin state even if the 18 18 * pin is configured as an output. 19 + * @sda_is_output_only: SDA output drivers can't be turned off. 20 + * This is for clients that can only read SDA/SCL. 21 + * @sda_has_no_pullup: SDA is used in a non-compliant way and has no pull-up. 22 + * Therefore disable open-drain. 19 23 * @scl_is_open_drain: SCL is set up as open drain. Same requirements 20 24 * as for sda_is_open_drain apply. 21 25 * @scl_is_output_only: SCL output drivers cannot be turned off. 26 + * @scl_has_no_pullup: SCL is used in a non-compliant way and has no pull-up. 27 + * Therefore disable open-drain. 22 28 */ 23 29 struct i2c_gpio_platform_data { 24 30 int udelay; 25 31 int timeout; 26 32 unsigned int sda_is_open_drain:1; 33 + unsigned int sda_is_output_only:1; 34 + unsigned int sda_has_no_pullup:1; 27 35 unsigned int scl_is_open_drain:1; 28 36 unsigned int scl_is_output_only:1; 37 + unsigned int scl_has_no_pullup:1; 29 38 }; 30 39 31 40 #endif /* _LINUX_I2C_GPIO_H */