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

Pull i2c updates from Wolfram Sang:
"I2C core:

- finally remove the I2C_COMPAT symbol after 15 years of deprecation

- lock client addresses during initialization to prevent race
conditions between different kinds of instantiation

- use scoped foreach OF child loops

- testunit cleanups and documentation improvements, as well as two
new tests, one for repeated start and one for triggering SMBusAlert
interrupts

I2C host drivers:

- DesignWare and Renesas I2C driver updates.

The first has has undergone through a series of cleanups that have
been sent to the mailing list a year ago for the first time and
finally get merged in this pull request. They are many, from typos
(e.g. i2/i2c), to cosmetics, to refactoring (e.g. move inline
functions to librarieas) and many others.

- all the DesignWare Kconfig options have been grouped under the
I2C_DESIGNWARE_CORE and this required some adaptation in many of
the kernel configuration files for different arm and mips boards

Cleanups:

- improve the exit path in the runtime resume function for the
Qualcomm Geni platform

- get rid of the unused "target_addr" parameter in the Intel LJCA
driver

- intialize the restart_flag in the MediaTek controller in one single
place

- constify a few global data structures in the virtio driver

- simplify the bus speed handling in the Renesas driver init function
making it more readable

- improved probe function of the Renesas R-Car driver

- switch the iMX/MXC driver to use RUNTIME_PM_OPS() instead of
SET_RUNTIME_PM_OPS()

- iMX/MXC driver cleanups

- use devm_clk_get_enabled() to simplify the Renesas EMEV2, Ingenic
and MPC drivers

Refactoring:

- Fix a potential out of boundary array access in the Nuvoton driver.

This is not a bug fix because the issue could never occur due to
hardware not having the properties listed in the array. The change
makes the driver more future proof and, at the same time, silences
code analyzers.

Improvements:

- several patches improving the runtime power management handling of
the Renesas I2C (riic) driver

- use a more descriptive adapter name in the Intel i801 driver to
show the presence of the IDF feature

- kill pending transactions when irq's can't complete their handling
in the Intel Denverton (ismt) driver, triggering a timeout

New Feature:

- support fast mode plus in the Renesas I2C (riic) driver

New support:

- Added support for:
- Renesas R9A08G045
- Rockchip RK3576
- KEBA I2C
- Theobroma Systems Mule Multiplexer.

- new i2c-keba.c driver

- new driver for The Mule i2c multiplexer

Core I2C framework:

- move runtime PM functions in order to allow them to be accessed
during device add

Devicetree:

- nVidia and Qualcomm binding improvements

- get rid of redundant "multi-master" property in the aspeed binding

- convert i2c-sprd binding to YAML

AT24 updates:

- document a new model from giantec in DT bindings"

* tag 'i2c-for-6.12-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux: (69 commits)
i2c: designware: Use pci_get_drvdata()
i2c: designware: Propagate firmware node
i2c: designware: Uninline i2c_dw_probe()
i2c: ljca: Remove unused "target_addr" parameter
i2c: keba: Add KEBA I2C controller support
i2c: i801: Use a different adapter-name for IDF adapters
i2c: core: Setup i2c_adapter runtime-pm before calling device_add()
dt-bindings: i2c: i2c-sprd: convert to YAML
i2c: ismt: kill transaction in hardware on timeout
i2c: designware: Group all DesignWare drivers under a single option
net: txgbe: Fix I2C Kconfig dependencies
RISC-V: configs: enable I2C_DESIGNWARE_CORE with I2C_DESIGNWARE_PLATFORM
mips: configs: enable I2C_DESIGNWARE_CORE with I2C_DESIGNWARE_PLATFORM
arm64: defconfig: enable I2C_DESIGNWARE_CORE with I2C_DESIGNWARE_PLATFORM
ARM: configs: enable I2C_DESIGNWARE_CORE with I2C_DESIGNWARE_PLATFORM
ARC: configs: enable I2C_DESIGNWARE_CORE with I2C_DESIGNWARE_PLATFORM
i2c: virtio: Constify struct i2c_algorithm and struct virtio_device_id
i2c: rcar: tidyup priv->devtype handling on rcar_i2c_probe()
i2c: imx: Convert comma to semicolon
i2c: jz4780: Use devm_clk_get_enabled() helpers
...

+1748 -606
+1
Documentation/devicetree/bindings/eeprom/at24.yaml
··· 116 116 - const: atmel,24c02 117 117 - items: 118 118 - enum: 119 + - giantec,gt24c04a 119 120 - onnn,cat24c04 120 121 - onnn,cat24c05 121 122 - rohm,br24g04
-5
Documentation/devicetree/bindings/i2c/aspeed,i2c.yaml
··· 44 44 description: frequency of the bus clock in Hz defaults to 100 kHz when not 45 45 specified 46 46 47 - multi-master: 48 - type: boolean 49 - description: 50 - states that there is another master active on this bus 51 - 52 47 required: 53 48 - reg 54 49 - compatible
+1
Documentation/devicetree/bindings/i2c/i2c-rk3x.yaml
··· 38 38 - rockchip,rk3308-i2c 39 39 - rockchip,rk3328-i2c 40 40 - rockchip,rk3568-i2c 41 + - rockchip,rk3576-i2c 41 42 - rockchip,rk3588-i2c 42 43 - rockchip,rv1126-i2c 43 44 - const: rockchip,rk3399-i2c
-31
Documentation/devicetree/bindings/i2c/i2c-sprd.txt
··· 1 - I2C for Spreadtrum platforms 2 - 3 - Required properties: 4 - - compatible: Should be "sprd,sc9860-i2c". 5 - - reg: Specify the physical base address of the controller and length 6 - of memory mapped region. 7 - - interrupts: Should contain I2C interrupt. 8 - - clock-names: Should contain following entries: 9 - "i2c" for I2C clock, 10 - "source" for I2C source (parent) clock, 11 - "enable" for I2C module enable clock. 12 - - clocks: Should contain a clock specifier for each entry in clock-names. 13 - - clock-frequency: Contains desired I2C bus clock frequency in Hz. 14 - - #address-cells: Should be 1 to describe address cells for I2C device address. 15 - - #size-cells: Should be 0 means no size cell for I2C device address. 16 - 17 - Optional properties: 18 - - Child nodes conforming to I2C bus binding 19 - 20 - Examples: 21 - i2c0: i2c@70500000 { 22 - compatible = "sprd,sc9860-i2c"; 23 - reg = <0 0x70500000 0 0x1000>; 24 - interrupts = <GIC_SPI 11 IRQ_TYPE_LEVEL_HIGH>; 25 - clock-names = "i2c", "source", "enable"; 26 - clocks = <&clk_i2c3>, <&ext_26m>, <&clk_ap_apb_gates 11>; 27 - clock-frequency = <400000>; 28 - #address-cells = <1>; 29 - #size-cells = <0>; 30 - }; 31 -
+15 -12
Documentation/devicetree/bindings/i2c/nvidia,tegra20-i2c.yaml
··· 103 103 items: 104 104 - const: i2c 105 105 106 + power-domains: 107 + maxItems: 1 108 + 106 109 dmas: 107 110 items: 108 111 - description: DMA channel for the reception FIFO ··· 127 124 - nvidia,tegra30-i2c 128 125 then: 129 126 properties: 127 + clocks: 128 + minItems: 2 130 129 clock-names: 131 130 items: 132 131 - const: div-clk ··· 138 133 properties: 139 134 compatible: 140 135 contains: 141 - const: nvidia,tegra114-i2c 136 + enum: 137 + - nvidia,tegra114-i2c 138 + - nvidia,tegra210-i2c 142 139 then: 143 140 properties: 144 - clock-names: 145 - items: 146 - - const: div-clk 147 - 148 - - if: 149 - properties: 150 - compatible: 151 - contains: 152 - const: nvidia,tegra210-i2c 153 - then: 154 - properties: 141 + clocks: 142 + maxItems: 1 155 143 clock-names: 156 144 items: 157 145 - const: div-clk ··· 156 158 const: nvidia,tegra210-i2c-vi 157 159 then: 158 160 properties: 161 + clocks: 162 + minItems: 2 159 163 clock-names: 160 164 items: 161 165 - const: div-clk ··· 165 165 power-domains: 166 166 items: 167 167 - description: phandle to the VENC power domain 168 + else: 169 + properties: 170 + power-domains: false 168 171 169 172 unevaluatedProperties: false 170 173
+1
Documentation/devicetree/bindings/i2c/qcom,i2c-cci.yaml
··· 130 130 then: 131 131 properties: 132 132 clocks: 133 + minItems: 4 133 134 maxItems: 4 134 135 clock-names: 135 136 items:
+4
Documentation/devicetree/bindings/i2c/renesas,riic.yaml
··· 25 25 - renesas,riic-r9a07g054 # RZ/V2L 26 26 - const: renesas,riic-rz # RZ/A or RZ/G2L 27 27 28 + - items: 29 + - const: renesas,riic-r9a08g045 # RZ/G3S 30 + - const: renesas,riic-r9a09g057 # RZ/V2H(P) 31 + 28 32 - const: renesas,riic-r9a09g057 # RZ/V2H(P) 29 33 30 34 reg:
+65
Documentation/devicetree/bindings/i2c/sprd,sc9860-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/sprd,sc9860-i2c.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Spreadtrum SC9860 I2C controller 8 + 9 + maintainers: 10 + - Orson Zhai <orsonzhai@gmail.com> 11 + - Baolin Wang <baolin.wang7@gmail.com> 12 + - Chunyan Zhang <zhang.lyra@gmail.com> 13 + 14 + allOf: 15 + - $ref: /schemas/i2c/i2c-controller.yaml# 16 + 17 + properties: 18 + compatible: 19 + const: sprd,sc9860-i2c 20 + 21 + reg: 22 + maxItems: 1 23 + 24 + interrupts: 25 + maxItems: 1 26 + 27 + clocks: 28 + items: 29 + - description: I2C clock 30 + - description: I2C source (parent) clock 31 + - description: I2C module enable clock 32 + 33 + clock-names: 34 + items: 35 + - const: i2c 36 + - const: source 37 + - const: enable 38 + 39 + clock-frequency: true 40 + 41 + required: 42 + - compatible 43 + - reg 44 + - interrupts 45 + - clocks 46 + - clock-names 47 + - clock-frequency 48 + 49 + unevaluatedProperties: false 50 + 51 + examples: 52 + - | 53 + #include <dt-bindings/interrupt-controller/arm-gic.h> 54 + #include <dt-bindings/interrupt-controller/irq.h> 55 + 56 + i2c@70500000 { 57 + compatible = "sprd,sc9860-i2c"; 58 + reg = <0x70500000 0x1000>; 59 + interrupts = <GIC_SPI 11 IRQ_TYPE_LEVEL_HIGH>; 60 + clocks = <&clk_i2c3>, <&ext_26m>, <&clk_ap_apb_gates 11>; 61 + clock-names = "i2c", "source", "enable"; 62 + clock-frequency = <400000>; 63 + #address-cells = <1>; 64 + #size-cells = <0>; 65 + };
+69
Documentation/devicetree/bindings/i2c/tsd,mule-i2c-mux.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/tsd,mule-i2c-mux.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Theobroma Systems Mule I2C multiplexer 8 + 9 + maintainers: 10 + - Farouk Bouabid <farouk.bouabid@cherry.de> 11 + - Quentin Schulz <quentin.schulz@cherry.de> 12 + 13 + description: | 14 + Theobroma Systems Mule is an MCU that emulates a set of I2C devices, among 15 + which devices that are reachable through an I2C-mux. The devices on the mux 16 + can be selected by writing the appropriate device number to an I2C config 17 + register. 18 + 19 + 20 + +--------------------------------------------------+ 21 + | Mule | 22 + 0x18| +---------------+ | 23 + -------->|Config register|----+ | 24 + | +---------------+ | | 25 + | V_ | 26 + | | \ +--------+ | 27 + | | \-------->| dev #0 | | 28 + | | | +--------+ | 29 + 0x6f| | M |-------->| dev #1 | | 30 + ---------------------------->| U | +--------+ | 31 + | | X |-------->| dev #2 | | 32 + | | | +--------+ | 33 + | | /-------->| dev #3 | | 34 + | |__/ +--------+ | 35 + +--------------------------------------------------+ 36 + 37 + 38 + allOf: 39 + - $ref: /schemas/i2c/i2c-mux.yaml# 40 + 41 + properties: 42 + compatible: 43 + const: tsd,mule-i2c-mux 44 + 45 + required: 46 + - compatible 47 + 48 + unevaluatedProperties: false 49 + 50 + examples: 51 + - | 52 + i2c-mux { 53 + compatible = "tsd,mule-i2c-mux"; 54 + #address-cells = <1>; 55 + #size-cells = <0>; 56 + 57 + i2c@0 { 58 + reg = <0x0>; 59 + #address-cells = <1>; 60 + #size-cells = <0>; 61 + 62 + rtc@6f { 63 + compatible = "isil,isl1208"; 64 + reg = <0x6f>; 65 + }; 66 + }; 67 + }; 68 + ... 69 +
+110 -10
Documentation/i2c/slave-testunit-backend.rst
··· 20 20 21 21 # echo "slave-testunit 0x1030" > /sys/bus/i2c/devices/i2c-0/new_device 22 22 23 - After that, you will have a write-only device listening. Reads will just return 24 - an 8-bit version number of the testunit. When writing, the device consists of 4 25 - 8-bit registers and, except for some "partial" commands, all registers must be 26 - written to start a testcase, i.e. you usually write 4 bytes to the device. The 27 - registers are: 23 + Or using firmware nodes. Here is a devicetree example (note this is only a 24 + debug device, so there are no official DT bindings):: 25 + 26 + &i2c0 { 27 + ... 28 + 29 + testunit@30 { 30 + compatible = "slave-testunit"; 31 + reg = <(0x30 | I2C_OWN_SLAVE_ADDRESS)>; 32 + }; 33 + }; 34 + 35 + After that, you will have the device listening. Reading will return a single 36 + byte. Its value is 0 if the testunit is idle, otherwise the command number of 37 + the currently running command. 38 + 39 + When writing, the device consists of 4 8-bit registers and, except for some 40 + "partial" commands, all registers must be written to start a testcase, i.e. you 41 + usually write 4 bytes to the device. The registers are: 28 42 29 43 .. csv-table:: 30 44 :header: "Offset", "Name", "Description" ··· 89 75 access the bus at the same time, the bus will be busy. Example to read 128 90 76 bytes from device 0x50 after 50ms of delay:: 91 77 92 - # i2cset -y 0 0x30 0x01 0x50 0x80 0x05 i 78 + # i2cset -y 0 0x30 1 0x50 0x80 5 i 93 79 94 80 0x02 SMBUS_HOST_NOTIFY 95 81 ~~~~~~~~~~~~~~~~~~~~~~ ··· 109 95 110 96 Also needs master mode. This test will send an SMBUS_HOST_NOTIFY message to the 111 97 host. Note that the status word is currently ignored in the Linux Kernel. 112 - Example to send a notification after 10ms:: 98 + Example to send a notification with status word 0x6442 after 10ms:: 113 99 114 - # i2cset -y 0 0x30 0x02 0x42 0x64 0x01 i 100 + # i2cset -y 0 0x30 2 0x42 0x64 1 i 115 101 116 102 If the host controller supports HostNotify, this message with debug level 117 103 should appear (Linux 6.11 and later):: ··· 130 116 - DELAY 131 117 132 118 * - 0x03 133 - - must be '1', i.e. one further byte will be written 119 + - 0x01 (i.e. one further byte will be written) 134 120 - number of bytes to be sent back 135 121 - leave out, partial command! 136 122 ··· 145 131 i2c_smbus_block_process_call() using i2ctransfer (you need i2c-tools v4.2 or 146 132 later):: 147 133 148 - # i2ctransfer -y 0 w3@0x30 0x03 0x01 0x10 r? 134 + # i2ctransfer -y 0 w3@0x30 3 1 0x10 r? 149 135 0x10 0x0f 0x0e 0x0d 0x0c 0x0b 0x0a 0x09 0x08 0x07 0x06 0x05 0x04 0x03 0x02 0x01 0x00 136 + 137 + 0x04 GET_VERSION_WITH_REP_START 138 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 139 + 140 + .. list-table:: 141 + :header-rows: 1 142 + 143 + * - CMD 144 + - DATAL 145 + - DATAH 146 + - DELAY 147 + 148 + * - 0x04 149 + - currently unused 150 + - currently unused 151 + - leave out, partial command! 152 + 153 + Partial command. After sending this command, the testunit will reply to a read 154 + message with a NUL terminated version string based on UTS_RELEASE. The first 155 + character is always a 'v' and the length of the version string is at maximum 156 + 128 bytes. However, it will only respond if the read message is connected to 157 + the write message via repeated start. If your controller driver handles 158 + repeated start correctly, this will work:: 159 + 160 + # i2ctransfer -y 0 w3@0x30 4 0 0 r128 161 + 0x76 0x36 0x2e 0x31 0x31 0x2e 0x30 0x2d 0x72 0x63 0x31 0x2d 0x30 0x30 0x30 0x30 ... 162 + 163 + If you have i2c-tools 4.4 or later, you can print out the data right away:: 164 + 165 + # i2ctransfer -y -b 0 w3@0x30 4 0 0 r128 166 + v6.11.0-rc1-00009-gd37a1b4d3fd0 167 + 168 + STOP/START combinations between the two messages will *not* work because they 169 + are not equivalent to a REPEATED START. As an example, this returns just the 170 + default response:: 171 + 172 + # i2cset -y 0 0x30 4 0 0 i; i2cget -y 0 0x30 173 + 0x00 174 + 175 + 0x05 SMBUS_ALERT_REQUEST 176 + ~~~~~~~~~~~~~~~~~~~~~~~~ 177 + 178 + .. list-table:: 179 + :header-rows: 1 180 + 181 + * - CMD 182 + - DATAL 183 + - DATAH 184 + - DELAY 185 + 186 + * - 0x05 187 + - response value (7 MSBs interpreted as I2C address) 188 + - currently unused 189 + - n * 10ms 190 + 191 + This test raises an interrupt via the SMBAlert pin which the host controller 192 + must handle. The pin must be connected to the testunit as a GPIO. GPIO access 193 + is not allowed to sleep. Currently, this can only be described using firmware 194 + nodes. So, for devicetree, you would add something like this to the testunit 195 + node:: 196 + 197 + gpios = <&gpio1 24 GPIO_ACTIVE_LOW>; 198 + 199 + The following command will trigger the alert with a response of 0xc9 after 1 200 + second of delay:: 201 + 202 + # i2cset -y 0 0x30 5 0xc9 0x00 100 i 203 + 204 + If the host controller supports SMBusAlert, this message with debug level 205 + should appear:: 206 + 207 + smbus_alert 0-000c: SMBALERT# from dev 0x64, flag 1 208 + 209 + This message may appear more than once because the testunit is software not 210 + hardware and, thus, may not be able to react to the response of the host fast 211 + enough. The interrupt count should increase only by one, though:: 212 + 213 + # cat /proc/interrupts | grep smbus_alert 214 + 93: 1 gpio-rcar 26 Edge smbus_alert 215 + 216 + If the host does not respond to the alert within 1 second, the test will be 217 + aborted and the testunit will report an error. 218 + 219 + For this test, the testunit will shortly drop its assigned address and listen 220 + on the SMBus Alert Response Address (0x0c). It will reassign its original 221 + address afterwards.
+1
arch/arc/configs/axs101_defconfig
··· 66 66 # CONFIG_HW_RANDOM is not set 67 67 CONFIG_I2C=y 68 68 CONFIG_I2C_CHARDEV=y 69 + CONFIG_I2C_DESIGNWARE_CORE=y 69 70 CONFIG_I2C_DESIGNWARE_PLATFORM=y 70 71 # CONFIG_HWMON is not set 71 72 CONFIG_DRM=m
+1
arch/arc/configs/axs103_defconfig
··· 66 66 # CONFIG_HW_RANDOM is not set 67 67 CONFIG_I2C=y 68 68 CONFIG_I2C_CHARDEV=y 69 + CONFIG_I2C_DESIGNWARE_CORE=y 69 70 CONFIG_I2C_DESIGNWARE_PLATFORM=y 70 71 # CONFIG_HWMON is not set 71 72 CONFIG_FB=y
+1
arch/arc/configs/axs103_smp_defconfig
··· 66 66 # CONFIG_HW_RANDOM is not set 67 67 CONFIG_I2C=y 68 68 CONFIG_I2C_CHARDEV=y 69 + CONFIG_I2C_DESIGNWARE_CORE=y 69 70 CONFIG_I2C_DESIGNWARE_PLATFORM=y 70 71 # CONFIG_HWMON is not set 71 72 CONFIG_DRM=m
+1
arch/arc/configs/tb10x_defconfig
··· 60 60 # CONFIG_HW_RANDOM is not set 61 61 CONFIG_I2C=y 62 62 # CONFIG_I2C_COMPAT is not set 63 + CONFIG_I2C_DESIGNWARE_CORE=y 63 64 CONFIG_I2C_DESIGNWARE_PLATFORM=y 64 65 CONFIG_GPIO_SYSFS=y 65 66 # CONFIG_HWMON is not set
+1
arch/arm/configs/hisi_defconfig
··· 43 43 CONFIG_SERIAL_OF_PLATFORM=y 44 44 CONFIG_SERIAL_AMBA_PL011=y 45 45 CONFIG_SERIAL_AMBA_PL011_CONSOLE=y 46 + CONFIG_I2C_DESIGNWARE_CORE=y 46 47 CONFIG_I2C_DESIGNWARE_PLATFORM=y 47 48 CONFIG_SPI=y 48 49 CONFIG_SPI_PL022=y
+1
arch/arm/configs/multi_v7_defconfig
··· 413 413 CONFIG_I2C_BCM2835=y 414 414 CONFIG_I2C_CADENCE=y 415 415 CONFIG_I2C_DAVINCI=y 416 + CONFIG_I2C_DESIGNWARE_CORE=y 416 417 CONFIG_I2C_DESIGNWARE_PLATFORM=y 417 418 CONFIG_I2C_DIGICOLOR=m 418 419 CONFIG_I2C_EMEV2=m
+1
arch/arm/configs/pxa_defconfig
··· 277 277 CONFIG_I2C_CHARDEV=m 278 278 CONFIG_I2C_MUX_PCA954x=m 279 279 CONFIG_I2C_MUX_PINCTRL=m 280 + CONFIG_I2C_DESIGNWARE_CORE=m 280 281 CONFIG_I2C_DESIGNWARE_PLATFORM=m 281 282 CONFIG_I2C_GPIO=y 282 283 CONFIG_I2C_PXA_SLAVE=y
+1
arch/arm/configs/socfpga_defconfig
··· 83 83 CONFIG_SERIAL_8250_DW=y 84 84 CONFIG_I2C=y 85 85 CONFIG_I2C_CHARDEV=y 86 + CONFIG_I2C_DESIGNWARE_CORE=y 86 87 CONFIG_I2C_DESIGNWARE_PLATFORM=y 87 88 CONFIG_SPI=y 88 89 CONFIG_SPI_CADENCE_QUADSPI=y
+1
arch/arm/configs/spear13xx_defconfig
··· 62 62 # CONFIG_HW_RANDOM is not set 63 63 CONFIG_RAW_DRIVER=y 64 64 CONFIG_I2C=y 65 + CONFIG_I2C_DESIGNWARE_CORE=y 65 66 CONFIG_I2C_DESIGNWARE_PLATFORM=y 66 67 CONFIG_SPI=y 67 68 CONFIG_SPI_PL022=y
+1
arch/arm/configs/spear3xx_defconfig
··· 42 42 # CONFIG_HW_RANDOM is not set 43 43 CONFIG_RAW_DRIVER=y 44 44 CONFIG_I2C=y 45 + CONFIG_I2C_DESIGNWARE_CORE=y 45 46 CONFIG_I2C_DESIGNWARE_PLATFORM=y 46 47 CONFIG_SPI=y 47 48 CONFIG_SPI_PL022=y
+1
arch/arm/configs/spear6xx_defconfig
··· 33 33 CONFIG_SERIAL_AMBA_PL011=y 34 34 CONFIG_SERIAL_AMBA_PL011_CONSOLE=y 35 35 CONFIG_I2C=y 36 + CONFIG_I2C_DESIGNWARE_CORE=y 36 37 CONFIG_I2C_DESIGNWARE_PLATFORM=y 37 38 CONFIG_SPI=y 38 39 CONFIG_SPI_PL022=y
+1
arch/arm64/configs/defconfig
··· 518 518 CONFIG_I2C_MUX_PCA954x=y 519 519 CONFIG_I2C_BCM2835=m 520 520 CONFIG_I2C_CADENCE=m 521 + CONFIG_I2C_DESIGNWARE_CORE=y 521 522 CONFIG_I2C_DESIGNWARE_PLATFORM=y 522 523 CONFIG_I2C_GPIO=m 523 524 CONFIG_I2C_IMX=y
+1
arch/mips/configs/generic/board-ocelot.config
··· 31 31 CONFIG_I2C=y 32 32 CONFIG_I2C_CHARDEV=y 33 33 CONFIG_I2C_MUX=y 34 + CONFIG_I2C_DESIGNWARE_CORE=y 34 35 CONFIG_I2C_DESIGNWARE_PLATFORM=y 35 36 36 37 CONFIG_SPI=y
+1
arch/riscv/configs/defconfig
··· 157 157 CONFIG_HW_RANDOM_JH7110=m 158 158 CONFIG_I2C=y 159 159 CONFIG_I2C_CHARDEV=m 160 + CONFIG_I2C_DESIGNWARE_CORE=y 160 161 CONFIG_I2C_DESIGNWARE_PLATFORM=y 161 162 CONFIG_I2C_MV64XXX=m 162 163 CONFIG_I2C_RIIC=y
+1
arch/riscv/configs/nommu_k210_defconfig
··· 58 58 # CONFIG_I2C_COMPAT is not set 59 59 CONFIG_I2C_CHARDEV=y 60 60 # CONFIG_I2C_HELPER_AUTO is not set 61 + CONFIG_I2C_DESIGNWARE_CORE=y 61 62 CONFIG_I2C_DESIGNWARE_PLATFORM=y 62 63 CONFIG_SPI=y 63 64 # CONFIG_SPI_MEM is not set
+1
arch/riscv/configs/nommu_k210_sdcard_defconfig
··· 50 50 CONFIG_I2C=y 51 51 CONFIG_I2C_CHARDEV=y 52 52 # CONFIG_I2C_HELPER_AUTO is not set 53 + CONFIG_I2C_DESIGNWARE_CORE=y 53 54 CONFIG_I2C_DESIGNWARE_PLATFORM=y 54 55 CONFIG_SPI=y 55 56 # CONFIG_SPI_MEM is not set
-8
drivers/i2c/Kconfig
··· 40 40 bool 41 41 default y 42 42 43 - config I2C_COMPAT 44 - bool "Enable compatibility bits for old user-space" 45 - default y 46 - help 47 - Say Y here if you intend to run lm-sensors 3.1.1 or older, or any 48 - other user-space package which expects i2c adapters to be class 49 - devices. If you don't know, say Y. 50 - 51 43 config I2C_CHARDEV 52 44 tristate "I2C device interface" 53 45 help
+29 -11
drivers/i2c/busses/Kconfig
··· 559 559 For details please see http://www.ti.com/davinci 560 560 561 561 config I2C_DESIGNWARE_CORE 562 - tristate 562 + tristate "Synopsys DesignWare I2C adapter" 563 563 select REGMAP 564 + help 565 + This option enables support for the Synopsys DesignWare I2C adapter. 566 + This driver includes support for the I2C host on the Synopsys 567 + Designware I2C adapter. 568 + 569 + To compile the driver as a module, choose M here: the module will be 570 + called i2c-designware-core. 571 + 572 + if I2C_DESIGNWARE_CORE 564 573 565 574 config I2C_DESIGNWARE_SLAVE 566 575 bool "Synopsys DesignWare Slave" 567 - depends on I2C_DESIGNWARE_CORE 568 576 select I2C_SLAVE 569 577 help 570 578 If you say yes to this option, support will be included for the 571 579 Synopsys DesignWare I2C slave adapter. 572 580 573 - This is not a standalone module, this module compiles together with 574 - i2c-designware-core. 575 - 576 581 config I2C_DESIGNWARE_PLATFORM 577 - tristate "Synopsys DesignWare Platform" 582 + tristate "Synopsys DesignWare Platform driver" 578 583 depends on (ACPI && COMMON_CLK) || !ACPI 579 - select I2C_DESIGNWARE_CORE 580 584 select MFD_SYSCON if MIPS_BAIKAL_T1 585 + default I2C_DESIGNWARE_CORE 581 586 help 582 587 If you say yes to this option, support will be included for the 583 - Synopsys DesignWare I2C adapter. 588 + Synopsys DesignWare I2C adapters on the platform bus. 584 589 585 590 This driver can also be built as a module. If so, the module 586 591 will be called i2c-designware-platform. ··· 618 613 a BayTrail system using the AXP288. 619 614 620 615 config I2C_DESIGNWARE_PCI 621 - tristate "Synopsys DesignWare PCI" 616 + tristate "Synopsys DesignWare PCI driver" 622 617 depends on PCI 623 - select I2C_DESIGNWARE_CORE 624 618 select I2C_CCGX_UCSI 625 619 help 626 620 If you say yes to this option, support will be included for the 627 - Synopsys DesignWare I2C adapter. Only master mode is supported. 621 + Synopsys DesignWare I2C adapters on the PCI bus. Only master mode is 622 + supported. 628 623 629 624 This driver can also be built as a module. If so, the module 630 625 will be called i2c-designware-pci. 626 + 627 + endif 631 628 632 629 config I2C_DIGICOLOR 633 630 tristate "Conexant Digicolor I2C driver" ··· 778 771 Ingenic JZ4780 I2C controller. 779 772 780 773 If you don't know what to do here, say N. 774 + 775 + config I2C_KEBA 776 + tristate "KEBA I2C controller support" 777 + depends on HAS_IOMEM 778 + select AUXILIARY_BUS 779 + help 780 + This driver supports the I2C controller found in KEBA system FPGA 781 + devices. 782 + 783 + This driver can also be built as a module. If so, the module 784 + will be called i2c-keba. 781 785 782 786 config I2C_KEMPLD 783 787 tristate "Kontron COM I2C Controller"
+1
drivers/i2c/busses/Makefile
··· 76 76 obj-$(CONFIG_I2C_IMX_LPI2C) += i2c-imx-lpi2c.o 77 77 obj-$(CONFIG_I2C_IOP3XX) += i2c-iop3xx.o 78 78 obj-$(CONFIG_I2C_JZ4780) += i2c-jz4780.o 79 + obj-$(CONFIG_I2C_KEBA) += i2c-keba.o 79 80 obj-$(CONFIG_I2C_KEMPLD) += i2c-kempld.o 80 81 obj-$(CONFIG_I2C_LPC2K) += i2c-lpc2k.o 81 82 obj-$(CONFIG_I2C_LS2X) += i2c-ls2x.o
+1 -2
drivers/i2c/busses/i2c-ali1535.c
··· 479 479 480 480 static const struct pci_device_id ali1535_ids[] = { 481 481 { PCI_DEVICE(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M7101) }, 482 - { }, 482 + { } 483 483 }; 484 - 485 484 MODULE_DEVICE_TABLE(pci, ali1535_ids); 486 485 487 486 static int ali1535_probe(struct pci_dev *dev, const struct pci_device_id *id)
+1 -1
drivers/i2c/busses/i2c-amd-mp2-plat.c
··· 340 340 341 341 static const struct acpi_device_id i2c_amd_acpi_match[] = { 342 342 { "AMDI0011" }, 343 - { }, 343 + { } 344 344 }; 345 345 MODULE_DEVICE_TABLE(acpi, i2c_amd_acpi_match); 346 346
+1 -1
drivers/i2c/busses/i2c-aspeed.c
··· 991 991 .compatible = "aspeed,ast2600-i2c-bus", 992 992 .data = aspeed_i2c_25xx_get_clk_reg_val, 993 993 }, 994 - { }, 994 + { } 995 995 }; 996 996 MODULE_DEVICE_TABLE(of, aspeed_i2c_bus_of_table); 997 997
+170 -10
drivers/i2c/busses/i2c-designware-common.c
··· 20 20 #include <linux/io.h> 21 21 #include <linux/kernel.h> 22 22 #include <linux/module.h> 23 + #include <linux/of.h> 24 + #include <linux/pm.h> 23 25 #include <linux/pm_runtime.h> 26 + #include <linux/property.h> 24 27 #include <linux/regmap.h> 25 28 #include <linux/swab.h> 26 29 #include <linux/types.h> 27 30 #include <linux/units.h> 31 + 32 + #define DEFAULT_SYMBOL_NAMESPACE I2C_DW_COMMON 28 33 29 34 #include "i2c-designware-core.h" 30 35 ··· 193 188 I2C_MAX_STANDARD_MODE_FREQ, 194 189 }; 195 190 196 - int i2c_dw_validate_speed(struct dw_i2c_dev *dev) 191 + static int i2c_dw_validate_speed(struct dw_i2c_dev *dev) 197 192 { 198 193 struct i2c_timings *t = &dev->timings; 199 194 unsigned int i; ··· 213 208 214 209 return -EINVAL; 215 210 } 216 - EXPORT_SYMBOL_GPL(i2c_dw_validate_speed); 211 + 212 + #ifdef CONFIG_OF 213 + 214 + #include <linux/platform_device.h> 215 + 216 + #define MSCC_ICPU_CFG_TWI_DELAY 0x0 217 + #define MSCC_ICPU_CFG_TWI_DELAY_ENABLE BIT(0) 218 + #define MSCC_ICPU_CFG_TWI_SPIKE_FILTER 0x4 219 + 220 + static int mscc_twi_set_sda_hold_time(struct dw_i2c_dev *dev) 221 + { 222 + writel((dev->sda_hold_time << 1) | MSCC_ICPU_CFG_TWI_DELAY_ENABLE, 223 + dev->ext + MSCC_ICPU_CFG_TWI_DELAY); 224 + 225 + return 0; 226 + } 227 + 228 + static void i2c_dw_of_configure(struct device *device) 229 + { 230 + struct platform_device *pdev = to_platform_device(device); 231 + struct dw_i2c_dev *dev = dev_get_drvdata(device); 232 + 233 + switch (dev->flags & MODEL_MASK) { 234 + case MODEL_MSCC_OCELOT: 235 + dev->ext = devm_platform_ioremap_resource(pdev, 1); 236 + if (!IS_ERR(dev->ext)) 237 + dev->set_sda_hold_time = mscc_twi_set_sda_hold_time; 238 + break; 239 + default: 240 + break; 241 + } 242 + } 243 + 244 + #else /* CONFIG_OF */ 245 + 246 + static inline void i2c_dw_of_configure(struct device *device) { } 247 + 248 + #endif /* CONFIG_OF */ 217 249 218 250 #ifdef CONFIG_ACPI 219 251 ··· 297 255 kfree(buf.pointer); 298 256 } 299 257 300 - int i2c_dw_acpi_configure(struct device *device) 258 + static void i2c_dw_acpi_configure(struct device *device) 301 259 { 302 260 struct dw_i2c_dev *dev = dev_get_drvdata(device); 303 261 struct i2c_timings *t = &dev->timings; ··· 327 285 dev->sda_hold_time = fs_ht; 328 286 break; 329 287 } 330 - 331 - return 0; 332 288 } 333 - EXPORT_SYMBOL_GPL(i2c_dw_acpi_configure); 334 289 335 290 static u32 i2c_dw_acpi_round_bus_speed(struct device *device) 336 291 { ··· 349 310 350 311 #else /* CONFIG_ACPI */ 351 312 313 + static inline void i2c_dw_acpi_configure(struct device *device) { } 314 + 352 315 static inline u32 i2c_dw_acpi_round_bus_speed(struct device *device) { return 0; } 353 316 354 317 #endif /* CONFIG_ACPI */ 355 318 356 - void i2c_dw_adjust_bus_speed(struct dw_i2c_dev *dev) 319 + static void i2c_dw_adjust_bus_speed(struct dw_i2c_dev *dev) 357 320 { 358 321 u32 acpi_speed = i2c_dw_acpi_round_bus_speed(dev->dev); 359 322 struct i2c_timings *t = &dev->timings; ··· 371 330 else 372 331 t->bus_freq_hz = I2C_MAX_FAST_MODE_FREQ; 373 332 } 374 - EXPORT_SYMBOL_GPL(i2c_dw_adjust_bus_speed); 375 333 376 - u32 i2c_dw_scl_hcnt(u32 ic_clk, u32 tSYMBOL, u32 tf, int cond, int offset) 334 + int i2c_dw_fw_parse_and_configure(struct dw_i2c_dev *dev) 377 335 { 336 + struct i2c_timings *t = &dev->timings; 337 + struct device *device = dev->dev; 338 + struct fwnode_handle *fwnode = dev_fwnode(device); 339 + 340 + i2c_parse_fw_timings(device, t, false); 341 + 342 + i2c_dw_adjust_bus_speed(dev); 343 + 344 + if (is_of_node(fwnode)) 345 + i2c_dw_of_configure(device); 346 + else if (is_acpi_node(fwnode)) 347 + i2c_dw_acpi_configure(device); 348 + 349 + return i2c_dw_validate_speed(dev); 350 + } 351 + EXPORT_SYMBOL_GPL(i2c_dw_fw_parse_and_configure); 352 + 353 + static u32 i2c_dw_read_scl_reg(struct dw_i2c_dev *dev, u32 reg) 354 + { 355 + u32 val; 356 + int ret; 357 + 358 + ret = i2c_dw_acquire_lock(dev); 359 + if (ret) 360 + return 0; 361 + 362 + ret = regmap_read(dev->map, reg, &val); 363 + i2c_dw_release_lock(dev); 364 + 365 + return ret ? 0 : val; 366 + } 367 + 368 + u32 i2c_dw_scl_hcnt(struct dw_i2c_dev *dev, unsigned int reg, u32 ic_clk, 369 + u32 tSYMBOL, u32 tf, int cond, int offset) 370 + { 371 + if (!ic_clk) 372 + return i2c_dw_read_scl_reg(dev, reg); 373 + 378 374 /* 379 375 * DesignWare I2C core doesn't seem to have solid strategy to meet 380 376 * the tHD;STA timing spec. Configuring _HCNT based on tHIGH spec ··· 450 372 3 + offset; 451 373 } 452 374 453 - u32 i2c_dw_scl_lcnt(u32 ic_clk, u32 tLOW, u32 tf, int offset) 375 + u32 i2c_dw_scl_lcnt(struct dw_i2c_dev *dev, unsigned int reg, u32 ic_clk, 376 + u32 tLOW, u32 tf, int offset) 454 377 { 378 + if (!ic_clk) 379 + return i2c_dw_read_scl_reg(dev, reg); 380 + 455 381 /* 456 382 * Conditional expression: 457 383 * ··· 735 653 736 654 i2c_dw_release_lock(dev); 737 655 } 656 + EXPORT_SYMBOL_GPL(i2c_dw_disable); 657 + 658 + int i2c_dw_probe(struct dw_i2c_dev *dev) 659 + { 660 + device_set_node(&dev->adapter.dev, dev_fwnode(dev->dev)); 661 + 662 + switch (dev->mode) { 663 + case DW_IC_SLAVE: 664 + return i2c_dw_probe_slave(dev); 665 + case DW_IC_MASTER: 666 + return i2c_dw_probe_master(dev); 667 + default: 668 + dev_err(dev->dev, "Wrong operation mode: %d\n", dev->mode); 669 + return -EINVAL; 670 + } 671 + } 672 + EXPORT_SYMBOL_GPL(i2c_dw_probe); 673 + 674 + static int i2c_dw_prepare(struct device *device) 675 + { 676 + /* 677 + * If the ACPI companion device object is present for this device, 678 + * it may be accessed during suspend and resume of other devices via 679 + * I2C operation regions, so tell the PM core and middle layers to 680 + * avoid skipping system suspend/resume callbacks for it in that case. 681 + */ 682 + return !has_acpi_companion(device); 683 + } 684 + 685 + static int i2c_dw_runtime_suspend(struct device *device) 686 + { 687 + struct dw_i2c_dev *dev = dev_get_drvdata(device); 688 + 689 + if (dev->shared_with_punit) 690 + return 0; 691 + 692 + i2c_dw_disable(dev); 693 + i2c_dw_prepare_clk(dev, false); 694 + 695 + return 0; 696 + } 697 + 698 + static int i2c_dw_suspend(struct device *device) 699 + { 700 + struct dw_i2c_dev *dev = dev_get_drvdata(device); 701 + 702 + i2c_mark_adapter_suspended(&dev->adapter); 703 + 704 + return i2c_dw_runtime_suspend(device); 705 + } 706 + 707 + static int i2c_dw_runtime_resume(struct device *device) 708 + { 709 + struct dw_i2c_dev *dev = dev_get_drvdata(device); 710 + 711 + if (!dev->shared_with_punit) 712 + i2c_dw_prepare_clk(dev, true); 713 + 714 + dev->init(dev); 715 + 716 + return 0; 717 + } 718 + 719 + static int i2c_dw_resume(struct device *device) 720 + { 721 + struct dw_i2c_dev *dev = dev_get_drvdata(device); 722 + 723 + i2c_dw_runtime_resume(device); 724 + i2c_mark_adapter_resumed(&dev->adapter); 725 + 726 + return 0; 727 + } 728 + 729 + EXPORT_GPL_DEV_PM_OPS(i2c_dw_dev_pm_ops) = { 730 + .prepare = pm_sleep_ptr(i2c_dw_prepare), 731 + LATE_SYSTEM_SLEEP_PM_OPS(i2c_dw_suspend, i2c_dw_resume) 732 + RUNTIME_PM_OPS(i2c_dw_runtime_suspend, i2c_dw_runtime_resume, NULL) 733 + }; 738 734 739 735 MODULE_DESCRIPTION("Synopsys DesignWare I2C bus adapter core"); 740 736 MODULE_LICENSE("GPL");
+11 -28
drivers/i2c/busses/i2c-designware-core.h
··· 10 10 */ 11 11 12 12 #include <linux/bits.h> 13 - #include <linux/compiler_types.h> 14 13 #include <linux/completion.h> 15 - #include <linux/dev_printk.h> 16 14 #include <linux/errno.h> 17 15 #include <linux/i2c.h> 16 + #include <linux/pm.h> 18 17 #include <linux/regmap.h> 19 18 #include <linux/types.h> 20 19 ··· 236 237 * @semaphore_idx: Index of table with semaphore type attached to the bus. It's 237 238 * -1 if there is no semaphore. 238 239 * @shared_with_punit: true if this bus is shared with the SoCs PUNIT 239 - * @disable: function to disable the controller 240 240 * @init: function to initialize the I2C hardware 241 241 * @set_sda_hold_time: callback to retrieve IP specific SDA hold timing 242 242 * @mode: operation mode - DW_IC_MASTER or DW_IC_SLAVE ··· 293 295 void (*release_lock)(void); 294 296 int semaphore_idx; 295 297 bool shared_with_punit; 296 - void (*disable)(struct dw_i2c_dev *dev); 297 298 int (*init)(struct dw_i2c_dev *dev); 298 299 int (*set_sda_hold_time)(struct dw_i2c_dev *dev); 299 300 int mode; ··· 326 329 }; 327 330 328 331 int i2c_dw_init_regmap(struct dw_i2c_dev *dev); 329 - u32 i2c_dw_scl_hcnt(u32 ic_clk, u32 tSYMBOL, u32 tf, int cond, int offset); 330 - u32 i2c_dw_scl_lcnt(u32 ic_clk, u32 tLOW, u32 tf, int offset); 332 + u32 i2c_dw_scl_hcnt(struct dw_i2c_dev *dev, unsigned int reg, u32 ic_clk, 333 + u32 tSYMBOL, u32 tf, int cond, int offset); 334 + u32 i2c_dw_scl_lcnt(struct dw_i2c_dev *dev, unsigned int reg, u32 ic_clk, 335 + u32 tLOW, u32 tf, int offset); 331 336 int i2c_dw_set_sda_hold(struct dw_i2c_dev *dev); 332 337 u32 i2c_dw_clk_rate(struct dw_i2c_dev *dev); 333 338 int i2c_dw_prepare_clk(struct dw_i2c_dev *dev, bool prepare); ··· 339 340 int i2c_dw_handle_tx_abort(struct dw_i2c_dev *dev); 340 341 int i2c_dw_set_fifo_size(struct dw_i2c_dev *dev); 341 342 u32 i2c_dw_func(struct i2c_adapter *adap); 342 - void i2c_dw_disable(struct dw_i2c_dev *dev); 343 + 344 + extern const struct dev_pm_ops i2c_dw_dev_pm_ops; 343 345 344 346 static inline void __i2c_dw_enable(struct dw_i2c_dev *dev) 345 347 { ··· 373 373 } 374 374 375 375 void __i2c_dw_disable(struct dw_i2c_dev *dev); 376 + void i2c_dw_disable(struct dw_i2c_dev *dev); 376 377 377 378 extern void i2c_dw_configure_master(struct dw_i2c_dev *dev); 378 379 extern int i2c_dw_probe_master(struct dw_i2c_dev *dev); ··· 386 385 static inline int i2c_dw_probe_slave(struct dw_i2c_dev *dev) { return -EINVAL; } 387 386 #endif 388 387 389 - static inline int i2c_dw_probe(struct dw_i2c_dev *dev) 390 - { 391 - switch (dev->mode) { 392 - case DW_IC_SLAVE: 393 - return i2c_dw_probe_slave(dev); 394 - case DW_IC_MASTER: 395 - return i2c_dw_probe_master(dev); 396 - default: 397 - dev_err(dev->dev, "Wrong operation mode: %d\n", dev->mode); 398 - return -EINVAL; 399 - } 400 - } 401 - 402 388 static inline void i2c_dw_configure(struct dw_i2c_dev *dev) 403 389 { 404 390 if (i2c_detect_slave_mode(dev->dev)) ··· 393 405 else 394 406 i2c_dw_configure_master(dev); 395 407 } 408 + 409 + int i2c_dw_probe(struct dw_i2c_dev *dev); 396 410 397 411 #if IS_ENABLED(CONFIG_I2C_DESIGNWARE_BAYTRAIL) 398 412 int i2c_dw_baytrail_probe_lock_support(struct dw_i2c_dev *dev); ··· 404 414 int i2c_dw_amdpsp_probe_lock_support(struct dw_i2c_dev *dev); 405 415 #endif 406 416 407 - int i2c_dw_validate_speed(struct dw_i2c_dev *dev); 408 - void i2c_dw_adjust_bus_speed(struct dw_i2c_dev *dev); 409 - 410 - #if IS_ENABLED(CONFIG_ACPI) 411 - int i2c_dw_acpi_configure(struct device *device); 412 - #else 413 - static inline int i2c_dw_acpi_configure(struct device *device) { return -ENODEV; } 414 - #endif 417 + int i2c_dw_fw_parse_and_configure(struct dw_i2c_dev *dev);
+27 -9
drivers/i2c/busses/i2c-designware-master.c
··· 22 22 #include <linux/regmap.h> 23 23 #include <linux/reset.h> 24 24 25 + #define DEFAULT_SYMBOL_NAMESPACE I2C_DW 26 + 25 27 #include "i2c-designware-core.h" 26 28 27 29 #define AMD_TIMEOUT_MIN_US 25 ··· 66 64 if (!dev->ss_hcnt || !dev->ss_lcnt) { 67 65 ic_clk = i2c_dw_clk_rate(dev); 68 66 dev->ss_hcnt = 69 - i2c_dw_scl_hcnt(ic_clk, 67 + i2c_dw_scl_hcnt(dev, 68 + DW_IC_SS_SCL_HCNT, 69 + ic_clk, 70 70 4000, /* tHD;STA = tHIGH = 4.0 us */ 71 71 sda_falling_time, 72 72 0, /* 0: DW default, 1: Ideal */ 73 73 0); /* No offset */ 74 74 dev->ss_lcnt = 75 - i2c_dw_scl_lcnt(ic_clk, 75 + i2c_dw_scl_lcnt(dev, 76 + DW_IC_SS_SCL_LCNT, 77 + ic_clk, 76 78 4700, /* tLOW = 4.7 us */ 77 79 scl_falling_time, 78 80 0); /* No offset */ ··· 100 94 } else { 101 95 ic_clk = i2c_dw_clk_rate(dev); 102 96 dev->fs_hcnt = 103 - i2c_dw_scl_hcnt(ic_clk, 97 + i2c_dw_scl_hcnt(dev, 98 + DW_IC_FS_SCL_HCNT, 99 + ic_clk, 104 100 260, /* tHIGH = 260 ns */ 105 101 sda_falling_time, 106 102 0, /* DW default */ 107 103 0); /* No offset */ 108 104 dev->fs_lcnt = 109 - i2c_dw_scl_lcnt(ic_clk, 105 + i2c_dw_scl_lcnt(dev, 106 + DW_IC_FS_SCL_LCNT, 107 + ic_clk, 110 108 500, /* tLOW = 500 ns */ 111 109 scl_falling_time, 112 110 0); /* No offset */ ··· 124 114 if (!dev->fs_hcnt || !dev->fs_lcnt) { 125 115 ic_clk = i2c_dw_clk_rate(dev); 126 116 dev->fs_hcnt = 127 - i2c_dw_scl_hcnt(ic_clk, 117 + i2c_dw_scl_hcnt(dev, 118 + DW_IC_FS_SCL_HCNT, 119 + ic_clk, 128 120 600, /* tHD;STA = tHIGH = 0.6 us */ 129 121 sda_falling_time, 130 122 0, /* 0: DW default, 1: Ideal */ 131 123 0); /* No offset */ 132 124 dev->fs_lcnt = 133 - i2c_dw_scl_lcnt(ic_clk, 125 + i2c_dw_scl_lcnt(dev, 126 + DW_IC_FS_SCL_LCNT, 127 + ic_clk, 134 128 1300, /* tLOW = 1.3 us */ 135 129 scl_falling_time, 136 130 0); /* No offset */ ··· 156 142 } else if (!dev->hs_hcnt || !dev->hs_lcnt) { 157 143 ic_clk = i2c_dw_clk_rate(dev); 158 144 dev->hs_hcnt = 159 - i2c_dw_scl_hcnt(ic_clk, 145 + i2c_dw_scl_hcnt(dev, 146 + DW_IC_HS_SCL_HCNT, 147 + ic_clk, 160 148 160, /* tHIGH = 160 ns */ 161 149 sda_falling_time, 162 150 0, /* DW default */ 163 151 0); /* No offset */ 164 152 dev->hs_lcnt = 165 - i2c_dw_scl_lcnt(ic_clk, 153 + i2c_dw_scl_lcnt(dev, 154 + DW_IC_HS_SCL_LCNT, 155 + ic_clk, 166 156 320, /* tLOW = 320 ns */ 167 157 scl_falling_time, 168 158 0); /* No offset */ ··· 949 931 init_completion(&dev->cmd_complete); 950 932 951 933 dev->init = i2c_dw_init_master; 952 - dev->disable = i2c_dw_disable; 953 934 954 935 ret = i2c_dw_init_regmap(dev); 955 936 if (ret) ··· 1038 1021 1039 1022 MODULE_DESCRIPTION("Synopsys DesignWare I2C bus master adapter"); 1040 1023 MODULE_LICENSE("GPL"); 1024 + MODULE_IMPORT_NS(I2C_DW_COMMON);
+16 -72
drivers/i2c/busses/i2c-designware-pcidrv.c
··· 9 9 * Copyright (C) 2009 Provigent Ltd. 10 10 * Copyright (C) 2011, 2015, 2016 Intel Corporation. 11 11 */ 12 - #include <linux/acpi.h> 13 12 #include <linux/delay.h> 14 13 #include <linux/err.h> 15 14 #include <linux/errno.h> ··· 18 19 #include <linux/kernel.h> 19 20 #include <linux/module.h> 20 21 #include <linux/pci.h> 22 + #include <linux/pm.h> 21 23 #include <linux/pm_runtime.h> 22 24 #include <linux/power_supply.h> 23 25 #include <linux/sched.h> ··· 102 102 103 103 static int mfld_setup(struct pci_dev *pdev, struct dw_pci_controller *c) 104 104 { 105 - struct dw_i2c_dev *dev = dev_get_drvdata(&pdev->dev); 105 + struct dw_i2c_dev *dev = pci_get_drvdata(pdev); 106 106 107 107 switch (pdev->device) { 108 108 case 0x0817: ··· 152 152 153 153 static int navi_amd_setup(struct pci_dev *pdev, struct dw_pci_controller *c) 154 154 { 155 - struct dw_i2c_dev *dev = dev_get_drvdata(&pdev->dev); 155 + struct dw_i2c_dev *dev = pci_get_drvdata(pdev); 156 156 157 157 dev->flags |= MODEL_AMD_NAVI_GPU | ACCESS_POLLING; 158 158 dev->timings.bus_freq_hz = I2C_MAX_STANDARD_MODE_FREQ; ··· 194 194 }, 195 195 }; 196 196 197 - static int __maybe_unused i2c_dw_pci_runtime_suspend(struct device *dev) 198 - { 199 - struct dw_i2c_dev *i_dev = dev_get_drvdata(dev); 200 - 201 - i_dev->disable(i_dev); 202 - return 0; 203 - } 204 - 205 - static int __maybe_unused i2c_dw_pci_suspend(struct device *dev) 206 - { 207 - struct dw_i2c_dev *i_dev = dev_get_drvdata(dev); 208 - 209 - i2c_mark_adapter_suspended(&i_dev->adapter); 210 - 211 - return i2c_dw_pci_runtime_suspend(dev); 212 - } 213 - 214 - static int __maybe_unused i2c_dw_pci_runtime_resume(struct device *dev) 215 - { 216 - struct dw_i2c_dev *i_dev = dev_get_drvdata(dev); 217 - 218 - return i_dev->init(i_dev); 219 - } 220 - 221 - static int __maybe_unused i2c_dw_pci_resume(struct device *dev) 222 - { 223 - struct dw_i2c_dev *i_dev = dev_get_drvdata(dev); 224 - int ret; 225 - 226 - ret = i2c_dw_pci_runtime_resume(dev); 227 - 228 - i2c_mark_adapter_resumed(&i_dev->adapter); 229 - 230 - return ret; 231 - } 232 - 233 - static const struct dev_pm_ops i2c_dw_pm_ops = { 234 - SET_SYSTEM_SLEEP_PM_OPS(i2c_dw_pci_suspend, i2c_dw_pci_resume) 235 - SET_RUNTIME_PM_OPS(i2c_dw_pci_runtime_suspend, i2c_dw_pci_runtime_resume, NULL) 236 - }; 237 - 238 197 static const struct property_entry dgpu_properties[] = { 239 198 /* USB-C doesn't power the system */ 240 199 PROPERTY_ENTRY_U8("scope", POWER_SUPPLY_SCOPE_DEVICE), ··· 212 253 int r; 213 254 struct dw_pci_controller *controller; 214 255 struct dw_scl_sda_cfg *cfg; 215 - struct i2c_timings *t; 216 256 217 257 if (id->driver_data >= ARRAY_SIZE(dw_pci_controllers)) 218 258 return dev_err_probe(&pdev->dev, -EINVAL, ··· 246 288 dev->irq = pci_irq_vector(pdev, 0); 247 289 dev->flags |= controller->flags; 248 290 249 - t = &dev->timings; 250 - i2c_parse_fw_timings(&pdev->dev, t, false); 251 - 252 291 pci_set_drvdata(pdev, dev); 253 292 254 293 if (controller->setup) { 255 294 r = controller->setup(pdev, controller); 256 - if (r) { 257 - pci_free_irq_vectors(pdev); 295 + if (r) 258 296 return r; 259 - } 260 297 } 261 298 262 - i2c_dw_adjust_bus_speed(dev); 263 - 264 - if (has_acpi_companion(&pdev->dev)) 265 - i2c_dw_acpi_configure(&pdev->dev); 266 - 267 - r = i2c_dw_validate_speed(dev); 268 - if (r) { 269 - pci_free_irq_vectors(pdev); 299 + r = i2c_dw_fw_parse_and_configure(dev); 300 + if (r) 270 301 return r; 271 - } 272 302 273 303 i2c_dw_configure(dev); 274 304 ··· 272 326 adap = &dev->adapter; 273 327 adap->owner = THIS_MODULE; 274 328 adap->class = 0; 275 - ACPI_COMPANION_SET(&adap->dev, ACPI_COMPANION(&pdev->dev)); 276 329 adap->nr = controller->bus_num; 277 330 278 331 r = i2c_dw_probe(dev); 279 - if (r) { 280 - pci_free_irq_vectors(pdev); 332 + if (r) 281 333 return r; 282 - } 283 334 284 335 if ((dev->flags & MODEL_MASK) == MODEL_AMD_NAVI_GPU) { 285 336 dev->slave = i2c_new_ccgx_ucsi(&dev->adapter, dev->irq, &dgpu_node); ··· 297 354 { 298 355 struct dw_i2c_dev *dev = pci_get_drvdata(pdev); 299 356 300 - dev->disable(dev); 357 + i2c_dw_disable(dev); 358 + 301 359 pm_runtime_forbid(&pdev->dev); 302 360 pm_runtime_get_noresume(&pdev->dev); 303 361 304 362 i2c_del_adapter(&dev->adapter); 305 - devm_free_irq(&pdev->dev, dev->irq, dev); 306 - pci_free_irq_vectors(pdev); 307 363 } 308 364 309 - static const struct pci_device_id i2_designware_pci_ids[] = { 365 + static const struct pci_device_id i2c_designware_pci_ids[] = { 310 366 /* Medfield */ 311 367 { PCI_VDEVICE(INTEL, 0x0817), medfield }, 312 368 { PCI_VDEVICE(INTEL, 0x0818), medfield }, ··· 351 409 { PCI_VDEVICE(ATI, 0x73c4), navi_amd }, 352 410 { PCI_VDEVICE(ATI, 0x7444), navi_amd }, 353 411 { PCI_VDEVICE(ATI, 0x7464), navi_amd }, 354 - { 0,} 412 + {} 355 413 }; 356 - MODULE_DEVICE_TABLE(pci, i2_designware_pci_ids); 414 + MODULE_DEVICE_TABLE(pci, i2c_designware_pci_ids); 357 415 358 416 static struct pci_driver dw_i2c_driver = { 359 417 .name = DRIVER_NAME, 360 - .id_table = i2_designware_pci_ids, 361 418 .probe = i2c_dw_pci_probe, 362 419 .remove = i2c_dw_pci_remove, 363 420 .driver = { 364 - .pm = &i2c_dw_pm_ops, 421 + .pm = pm_ptr(&i2c_dw_dev_pm_ops), 365 422 }, 423 + .id_table = i2c_designware_pci_ids, 366 424 }; 367 425 module_pci_driver(dw_i2c_driver); 368 426 369 427 MODULE_AUTHOR("Baruch Siach <baruch@tkos.co.il>"); 370 428 MODULE_DESCRIPTION("Synopsys DesignWare PCI I2C bus adapter"); 371 429 MODULE_LICENSE("GPL"); 430 + MODULE_IMPORT_NS(I2C_DW); 431 + MODULE_IMPORT_NS(I2C_DW_COMMON);
+36 -150
drivers/i2c/busses/i2c-designware-platdrv.c
··· 8 8 * Copyright (C) 2007 MontaVista Software Inc. 9 9 * Copyright (C) 2009 Provigent Ltd. 10 10 */ 11 - #include <linux/acpi.h> 12 11 #include <linux/clk-provider.h> 13 12 #include <linux/clk.h> 14 13 #include <linux/delay.h> ··· 20 21 #include <linux/kernel.h> 21 22 #include <linux/mfd/syscon.h> 22 23 #include <linux/module.h> 23 - #include <linux/of.h> 24 24 #include <linux/platform_device.h> 25 25 #include <linux/pm.h> 26 26 #include <linux/pm_runtime.h> ··· 28 30 #include <linux/reset.h> 29 31 #include <linux/sched.h> 30 32 #include <linux/slab.h> 31 - #include <linux/suspend.h> 32 33 #include <linux/units.h> 33 34 34 35 #include "i2c-designware-core.h" ··· 36 39 { 37 40 return clk_get_rate(dev->clk) / KILO; 38 41 } 39 - 40 - #ifdef CONFIG_ACPI 41 - static const struct acpi_device_id dw_i2c_acpi_match[] = { 42 - { "INT33C2", 0 }, 43 - { "INT33C3", 0 }, 44 - { "INT3432", 0 }, 45 - { "INT3433", 0 }, 46 - { "INTC10EF", 0 }, 47 - { "80860F41", ACCESS_NO_IRQ_SUSPEND }, 48 - { "808622C1", ACCESS_NO_IRQ_SUSPEND }, 49 - { "AMD0010", ACCESS_INTR_MASK }, 50 - { "AMDI0010", ACCESS_INTR_MASK }, 51 - { "AMDI0019", ACCESS_INTR_MASK | ARBITRATION_SEMAPHORE }, 52 - { "AMDI0510", 0 }, 53 - { "APMC0D0F", 0 }, 54 - { "HISI02A1", 0 }, 55 - { "HISI02A2", 0 }, 56 - { "HISI02A3", 0 }, 57 - { "HYGO0010", ACCESS_INTR_MASK }, 58 - { } 59 - }; 60 - MODULE_DEVICE_TABLE(acpi, dw_i2c_acpi_match); 61 - #endif 62 42 63 43 #ifdef CONFIG_OF 64 44 #define BT1_I2C_CTL 0x100 ··· 94 120 dev->map = devm_regmap_init(dev->dev, NULL, dev, &bt1_i2c_cfg); 95 121 return PTR_ERR_OR_ZERO(dev->map); 96 122 } 97 - 98 - #define MSCC_ICPU_CFG_TWI_DELAY 0x0 99 - #define MSCC_ICPU_CFG_TWI_DELAY_ENABLE BIT(0) 100 - #define MSCC_ICPU_CFG_TWI_SPIKE_FILTER 0x4 101 - 102 - static int mscc_twi_set_sda_hold_time(struct dw_i2c_dev *dev) 103 - { 104 - writel((dev->sda_hold_time << 1) | MSCC_ICPU_CFG_TWI_DELAY_ENABLE, 105 - dev->ext + MSCC_ICPU_CFG_TWI_DELAY); 106 - 107 - return 0; 108 - } 109 - 110 - static int dw_i2c_of_configure(struct platform_device *pdev) 111 - { 112 - struct dw_i2c_dev *dev = platform_get_drvdata(pdev); 113 - 114 - switch (dev->flags & MODEL_MASK) { 115 - case MODEL_MSCC_OCELOT: 116 - dev->ext = devm_platform_ioremap_resource(pdev, 1); 117 - if (!IS_ERR(dev->ext)) 118 - dev->set_sda_hold_time = mscc_twi_set_sda_hold_time; 119 - break; 120 - default: 121 - break; 122 - } 123 - 124 - return 0; 125 - } 126 - 127 - static const struct of_device_id dw_i2c_of_match[] = { 128 - { .compatible = "snps,designware-i2c", }, 129 - { .compatible = "mscc,ocelot-i2c", .data = (void *)MODEL_MSCC_OCELOT }, 130 - { .compatible = "baikal,bt1-sys-i2c", .data = (void *)MODEL_BAIKAL_BT1 }, 131 - {}, 132 - }; 133 - MODULE_DEVICE_TABLE(of, dw_i2c_of_match); 134 123 #else 135 124 static int bt1_i2c_request_regs(struct dw_i2c_dev *dev) 136 - { 137 - return -ENODEV; 138 - } 139 - 140 - static inline int dw_i2c_of_configure(struct platform_device *pdev) 141 125 { 142 126 return -ENODEV; 143 127 } ··· 170 238 int i = 0; 171 239 int ret; 172 240 173 - ptr = i2c_dw_semaphore_cb_table; 174 - 175 241 dev->semaphore_idx = -1; 176 242 177 - while (ptr->probe) { 243 + for (ptr = i2c_dw_semaphore_cb_table; ptr->probe; ptr++) { 178 244 ret = ptr->probe(dev); 179 245 if (ret) { 180 246 /* ··· 184 254 return ret; 185 255 186 256 i++; 187 - ptr++; 188 257 continue; 189 258 } 190 259 ··· 207 278 { 208 279 struct i2c_adapter *adap; 209 280 struct dw_i2c_dev *dev; 210 - struct i2c_timings *t; 211 281 int irq, ret; 212 282 213 283 irq = platform_get_irq(pdev, 0); ··· 235 307 236 308 reset_control_deassert(dev->rst); 237 309 238 - t = &dev->timings; 239 - i2c_parse_fw_timings(&pdev->dev, t, false); 240 - 241 - i2c_dw_adjust_bus_speed(dev); 242 - 243 - if (pdev->dev.of_node) 244 - dw_i2c_of_configure(pdev); 245 - 246 - if (has_acpi_companion(&pdev->dev)) 247 - i2c_dw_acpi_configure(&pdev->dev); 248 - 249 - ret = i2c_dw_validate_speed(dev); 310 + ret = i2c_dw_fw_parse_and_configure(dev); 250 311 if (ret) 251 312 goto exit_reset; 252 313 ··· 263 346 goto exit_reset; 264 347 265 348 if (dev->clk) { 349 + struct i2c_timings *t = &dev->timings; 266 350 u64 clk_khz; 267 351 268 352 dev->get_clk_rate_khz = i2c_dw_get_clk_rate_khz; ··· 278 360 adap->owner = THIS_MODULE; 279 361 adap->class = dmi_check_system(dw_i2c_hwmon_class_dmi) ? 280 362 I2C_CLASS_HWMON : I2C_CLASS_DEPRECATED; 281 - ACPI_COMPANION_SET(&adap->dev, ACPI_COMPANION(&pdev->dev)); 282 - adap->dev.of_node = pdev->dev.of_node; 283 363 adap->nr = -1; 284 364 285 365 if (dev->flags & ACCESS_NO_IRQ_SUSPEND) { ··· 324 408 325 409 i2c_del_adapter(&dev->adapter); 326 410 327 - dev->disable(dev); 411 + i2c_dw_disable(dev); 328 412 329 413 pm_runtime_dont_use_autosuspend(&pdev->dev); 330 414 pm_runtime_put_sync(&pdev->dev); ··· 335 419 reset_control_assert(dev->rst); 336 420 } 337 421 338 - static int dw_i2c_plat_prepare(struct device *dev) 339 - { 340 - /* 341 - * If the ACPI companion device object is present for this device, it 342 - * may be accessed during suspend and resume of other devices via I2C 343 - * operation regions, so tell the PM core and middle layers to avoid 344 - * skipping system suspend/resume callbacks for it in that case. 345 - */ 346 - return !has_acpi_companion(dev); 347 - } 348 - 349 - static int dw_i2c_plat_runtime_suspend(struct device *dev) 350 - { 351 - struct dw_i2c_dev *i_dev = dev_get_drvdata(dev); 352 - 353 - if (i_dev->shared_with_punit) 354 - return 0; 355 - 356 - i_dev->disable(i_dev); 357 - i2c_dw_prepare_clk(i_dev, false); 358 - 359 - return 0; 360 - } 361 - 362 - static int dw_i2c_plat_suspend(struct device *dev) 363 - { 364 - struct dw_i2c_dev *i_dev = dev_get_drvdata(dev); 365 - 366 - i2c_mark_adapter_suspended(&i_dev->adapter); 367 - 368 - return dw_i2c_plat_runtime_suspend(dev); 369 - } 370 - 371 - static int dw_i2c_plat_runtime_resume(struct device *dev) 372 - { 373 - struct dw_i2c_dev *i_dev = dev_get_drvdata(dev); 374 - 375 - if (!i_dev->shared_with_punit) 376 - i2c_dw_prepare_clk(i_dev, true); 377 - 378 - i_dev->init(i_dev); 379 - 380 - return 0; 381 - } 382 - 383 - static int dw_i2c_plat_resume(struct device *dev) 384 - { 385 - struct dw_i2c_dev *i_dev = dev_get_drvdata(dev); 386 - 387 - dw_i2c_plat_runtime_resume(dev); 388 - i2c_mark_adapter_resumed(&i_dev->adapter); 389 - 390 - return 0; 391 - } 392 - 393 - static const struct dev_pm_ops dw_i2c_dev_pm_ops = { 394 - .prepare = pm_sleep_ptr(dw_i2c_plat_prepare), 395 - LATE_SYSTEM_SLEEP_PM_OPS(dw_i2c_plat_suspend, dw_i2c_plat_resume) 396 - RUNTIME_PM_OPS(dw_i2c_plat_runtime_suspend, dw_i2c_plat_runtime_resume, NULL) 422 + static const struct of_device_id dw_i2c_of_match[] = { 423 + { .compatible = "snps,designware-i2c", }, 424 + { .compatible = "mscc,ocelot-i2c", .data = (void *)MODEL_MSCC_OCELOT }, 425 + { .compatible = "baikal,bt1-sys-i2c", .data = (void *)MODEL_BAIKAL_BT1 }, 426 + {} 397 427 }; 428 + MODULE_DEVICE_TABLE(of, dw_i2c_of_match); 429 + 430 + static const struct acpi_device_id dw_i2c_acpi_match[] = { 431 + { "80860F41", ACCESS_NO_IRQ_SUSPEND }, 432 + { "808622C1", ACCESS_NO_IRQ_SUSPEND }, 433 + { "AMD0010", ACCESS_INTR_MASK }, 434 + { "AMDI0010", ACCESS_INTR_MASK }, 435 + { "AMDI0019", ACCESS_INTR_MASK | ARBITRATION_SEMAPHORE }, 436 + { "AMDI0510", 0 }, 437 + { "APMC0D0F", 0 }, 438 + { "HISI02A1", 0 }, 439 + { "HISI02A2", 0 }, 440 + { "HISI02A3", 0 }, 441 + { "HYGO0010", ACCESS_INTR_MASK }, 442 + { "INT33C2", 0 }, 443 + { "INT33C3", 0 }, 444 + { "INT3432", 0 }, 445 + { "INT3433", 0 }, 446 + { "INTC10EF", 0 }, 447 + {} 448 + }; 449 + MODULE_DEVICE_TABLE(acpi, dw_i2c_acpi_match); 398 450 399 451 static const struct platform_device_id dw_i2c_platform_ids[] = { 400 452 { "i2c_designware" }, ··· 375 491 .remove_new = dw_i2c_plat_remove, 376 492 .driver = { 377 493 .name = "i2c_designware", 378 - .of_match_table = of_match_ptr(dw_i2c_of_match), 379 - .acpi_match_table = ACPI_PTR(dw_i2c_acpi_match), 380 - .pm = pm_ptr(&dw_i2c_dev_pm_ops), 494 + .of_match_table = dw_i2c_of_match, 495 + .acpi_match_table = dw_i2c_acpi_match, 496 + .pm = pm_ptr(&i2c_dw_dev_pm_ops), 381 497 }, 382 498 .id_table = dw_i2c_platform_ids, 383 499 }; ··· 397 513 MODULE_AUTHOR("Baruch Siach <baruch@tkos.co.il>"); 398 514 MODULE_DESCRIPTION("Synopsys DesignWare I2C bus adapter"); 399 515 MODULE_LICENSE("GPL"); 516 + MODULE_IMPORT_NS(I2C_DW); 517 + MODULE_IMPORT_NS(I2C_DW_COMMON);
+4 -2
drivers/i2c/busses/i2c-designware-slave.c
··· 16 16 #include <linux/pm_runtime.h> 17 17 #include <linux/regmap.h> 18 18 19 + #define DEFAULT_SYMBOL_NAMESPACE I2C_DW 20 + 19 21 #include "i2c-designware-core.h" 20 22 21 23 static void i2c_dw_configure_fifo_slave(struct dw_i2c_dev *dev) ··· 90 88 struct dw_i2c_dev *dev = i2c_get_adapdata(slave->adapter); 91 89 92 90 regmap_write(dev->map, DW_IC_INTR_MASK, 0); 93 - dev->disable(dev); 91 + i2c_dw_disable(dev); 94 92 synchronize_irq(dev->irq); 95 93 dev->slave = NULL; 96 94 pm_runtime_put(dev->dev); ··· 237 235 int ret; 238 236 239 237 dev->init = i2c_dw_init_slave; 240 - dev->disable = i2c_dw_disable; 241 238 242 239 ret = i2c_dw_init_regmap(dev); 243 240 if (ret) ··· 280 279 MODULE_AUTHOR("Luis Oliveira <lolivei@synopsys.com>"); 281 280 MODULE_DESCRIPTION("Synopsys DesignWare I2C bus slave adapter"); 282 281 MODULE_LICENSE("GPL v2"); 282 + MODULE_IMPORT_NS(I2C_DW_COMMON);
+1 -1
drivers/i2c/busses/i2c-digicolor.c
··· 357 357 358 358 static const struct of_device_id dc_i2c_match[] = { 359 359 { .compatible = "cnxt,cx92755-i2c" }, 360 - { }, 360 + { } 361 361 }; 362 362 MODULE_DEVICE_TABLE(of, dc_i2c_match); 363 363
+8 -17
drivers/i2c/busses/i2c-emev2.c
··· 67 67 void __iomem *base; 68 68 struct i2c_adapter adap; 69 69 struct completion msg_done; 70 - struct clk *sclk; 71 70 struct i2c_client *slave; 72 71 int irq; 73 72 }; ··· 360 361 static int em_i2c_probe(struct platform_device *pdev) 361 362 { 362 363 struct em_i2c_device *priv; 364 + struct clk *sclk; 363 365 int ret; 364 366 365 367 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); ··· 373 373 374 374 strscpy(priv->adap.name, "EMEV2 I2C", sizeof(priv->adap.name)); 375 375 376 - priv->sclk = devm_clk_get(&pdev->dev, "sclk"); 377 - if (IS_ERR(priv->sclk)) 378 - return PTR_ERR(priv->sclk); 379 - 380 - ret = clk_prepare_enable(priv->sclk); 381 - if (ret) 382 - return ret; 376 + sclk = devm_clk_get_enabled(&pdev->dev, "sclk"); 377 + if (IS_ERR(sclk)) 378 + return PTR_ERR(sclk); 383 379 384 380 priv->adap.timeout = msecs_to_jiffies(100); 385 381 priv->adap.retries = 5; ··· 393 397 394 398 ret = platform_get_irq(pdev, 0); 395 399 if (ret < 0) 396 - goto err_clk; 400 + return ret; 397 401 priv->irq = ret; 402 + 398 403 ret = devm_request_irq(&pdev->dev, priv->irq, em_i2c_irq_handler, 0, 399 404 "em_i2c", priv); 400 405 if (ret) 401 - goto err_clk; 406 + return ret; 402 407 403 408 ret = i2c_add_adapter(&priv->adap); 404 - 405 409 if (ret) 406 - goto err_clk; 410 + return ret; 407 411 408 412 dev_info(&pdev->dev, "Added i2c controller %d, irq %d\n", priv->adap.nr, 409 413 priv->irq); 410 414 411 415 return 0; 412 - 413 - err_clk: 414 - clk_disable_unprepare(priv->sclk); 415 - return ret; 416 416 } 417 417 418 418 static void em_i2c_remove(struct platform_device *dev) ··· 416 424 struct em_i2c_device *priv = platform_get_drvdata(dev); 417 425 418 426 i2c_del_adapter(&priv->adap); 419 - clk_disable_unprepare(priv->sclk); 420 427 } 421 428 422 429 static const struct of_device_id em_i2c_ids[] = {
+8 -1
drivers/i2c/busses/i2c-i801.c
··· 1763 1763 1764 1764 i801_add_tco(priv); 1765 1765 1766 + /* 1767 + * adapter.name is used by platform code to find the main I801 adapter 1768 + * to instantiante i2c_clients, do not change. 1769 + */ 1766 1770 snprintf(priv->adapter.name, sizeof(priv->adapter.name), 1767 - "SMBus I801 adapter at %04lx", priv->smba); 1771 + "SMBus %s adapter at %04lx", 1772 + (priv->features & FEATURE_IDF) ? "I801 IDF" : "I801", 1773 + priv->smba); 1774 + 1768 1775 err = i2c_add_adapter(&priv->adapter); 1769 1776 if (err) { 1770 1777 platform_device_unregister(priv->tco_pdev);
+1 -1
drivers/i2c/busses/i2c-imx-lpi2c.c
··· 559 559 560 560 static const struct of_device_id lpi2c_imx_of_match[] = { 561 561 { .compatible = "fsl,imx7ulp-lpi2c" }, 562 - { }, 562 + { } 563 563 }; 564 564 MODULE_DEVICE_TABLE(of, lpi2c_imx_of_match); 565 565
+5 -6
drivers/i2c/busses/i2c-imx.c
··· 687 687 i2c_imx_bus_busy(i2c_imx, 0, atomic); 688 688 689 689 /* Disable I2C controller */ 690 - temp = i2c_imx->hwdata->i2cr_ien_opcode ^ I2CR_IEN, 690 + temp = i2c_imx->hwdata->i2cr_ien_opcode ^ I2CR_IEN; 691 691 imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR); 692 692 } 693 693 ··· 1549 1549 pm_runtime_disable(&pdev->dev); 1550 1550 } 1551 1551 1552 - static int __maybe_unused i2c_imx_runtime_suspend(struct device *dev) 1552 + static int i2c_imx_runtime_suspend(struct device *dev) 1553 1553 { 1554 1554 struct imx_i2c_struct *i2c_imx = dev_get_drvdata(dev); 1555 1555 ··· 1558 1558 return 0; 1559 1559 } 1560 1560 1561 - static int __maybe_unused i2c_imx_runtime_resume(struct device *dev) 1561 + static int i2c_imx_runtime_resume(struct device *dev) 1562 1562 { 1563 1563 struct imx_i2c_struct *i2c_imx = dev_get_drvdata(dev); 1564 1564 int ret; ··· 1571 1571 } 1572 1572 1573 1573 static const struct dev_pm_ops i2c_imx_pm_ops = { 1574 - SET_RUNTIME_PM_OPS(i2c_imx_runtime_suspend, 1575 - i2c_imx_runtime_resume, NULL) 1574 + RUNTIME_PM_OPS(i2c_imx_runtime_suspend, i2c_imx_runtime_resume, NULL) 1576 1575 }; 1577 1576 1578 1577 static struct platform_driver i2c_imx_driver = { ··· 1579 1580 .remove_new = i2c_imx_remove, 1580 1581 .driver = { 1581 1582 .name = DRIVER_NAME, 1582 - .pm = &i2c_imx_pm_ops, 1583 + .pm = pm_ptr(&i2c_imx_pm_ops), 1583 1584 .of_match_table = i2c_imx_dt_ids, 1584 1585 .acpi_match_table = i2c_imx_acpi_ids, 1585 1586 },
+10
drivers/i2c/busses/i2c-ismt.c
··· 382 382 } 383 383 384 384 /** 385 + * ismt_kill_transaction() - kill current transaction 386 + * @priv: iSMT private data 387 + */ 388 + static void ismt_kill_transaction(struct ismt_priv *priv) 389 + { 390 + writel(ISMT_GCTRL_KILL, priv->smba + ISMT_GR_GCTRL); 391 + } 392 + 393 + /** 385 394 * ismt_access() - process an SMBus command 386 395 * @adap: the i2c host adapter 387 396 * @addr: address of the i2c/SMBus target ··· 632 623 dma_unmap_single(dev, dma_addr, dma_size, dma_direction); 633 624 634 625 if (unlikely(!time_left)) { 626 + ismt_kill_transaction(priv); 635 627 ret = -ETIMEDOUT; 636 628 goto out; 637 629 }
+7 -15
drivers/i2c/busses/i2c-jz4780.c
··· 792 792 793 793 platform_set_drvdata(pdev, i2c); 794 794 795 - i2c->clk = devm_clk_get(&pdev->dev, NULL); 795 + i2c->clk = devm_clk_get_enabled(&pdev->dev, NULL); 796 796 if (IS_ERR(i2c->clk)) 797 797 return PTR_ERR(i2c->clk); 798 - 799 - ret = clk_prepare_enable(i2c->clk); 800 - if (ret) 801 - return ret; 802 798 803 799 ret = of_property_read_u32(pdev->dev.of_node, "clock-frequency", 804 800 &clk_freq); 805 801 if (ret) { 806 802 dev_err(&pdev->dev, "clock-frequency not specified in DT\n"); 807 - goto err; 803 + return ret; 808 804 } 809 805 810 806 i2c->speed = clk_freq / 1000; 811 807 if (i2c->speed == 0) { 812 808 ret = -EINVAL; 813 809 dev_err(&pdev->dev, "clock-frequency minimum is 1000\n"); 814 - goto err; 810 + return ret; 815 811 } 816 812 jz4780_i2c_set_speed(i2c); 817 813 ··· 823 827 824 828 ret = platform_get_irq(pdev, 0); 825 829 if (ret < 0) 826 - goto err; 830 + return ret; 827 831 i2c->irq = ret; 832 + 828 833 ret = devm_request_irq(&pdev->dev, i2c->irq, jz4780_i2c_irq, 0, 829 834 dev_name(&pdev->dev), i2c); 830 835 if (ret) 831 - goto err; 836 + return ret; 832 837 833 838 ret = i2c_add_adapter(&i2c->adap); 834 839 if (ret < 0) 835 - goto err; 840 + return ret; 836 841 837 842 return 0; 838 - 839 - err: 840 - clk_disable_unprepare(i2c->clk); 841 - return ret; 842 843 } 843 844 844 845 static void jz4780_i2c_remove(struct platform_device *pdev) 845 846 { 846 847 struct jz4780_i2c *i2c = platform_get_drvdata(pdev); 847 848 848 - clk_disable_unprepare(i2c->clk); 849 849 i2c_del_adapter(&i2c->adap); 850 850 } 851 851
+598
drivers/i2c/busses/i2c-keba.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Copyright (C) KEBA Industrial Automation Gmbh 2024 4 + * 5 + * Driver for KEBA I2C controller FPGA IP core 6 + */ 7 + 8 + #include <linux/i2c.h> 9 + #include <linux/io.h> 10 + #include <linux/iopoll.h> 11 + #include <linux/module.h> 12 + #include <linux/misc/keba.h> 13 + 14 + #define KI2C "i2c-keba" 15 + 16 + #define KI2C_CAPABILITY_REG 0x02 17 + #define KI2C_CAPABILITY_CRYPTO 0x01 18 + #define KI2C_CAPABILITY_DC 0x02 19 + 20 + #define KI2C_CONTROL_REG 0x04 21 + #define KI2C_CONTROL_MEN 0x01 22 + #define KI2C_CONTROL_MSTA 0x02 23 + #define KI2C_CONTROL_RSTA 0x04 24 + #define KI2C_CONTROL_MTX 0x08 25 + #define KI2C_CONTROL_TXAK 0x10 26 + #define KI2C_CONTROL_DISABLE 0x00 27 + 28 + #define KI2C_CONTROL_DC_REG 0x05 29 + #define KI2C_CONTROL_DC_SDA 0x01 30 + #define KI2C_CONTROL_DC_SCL 0x02 31 + 32 + #define KI2C_STATUS_REG 0x08 33 + #define KI2C_STATUS_IN_USE 0x01 34 + #define KI2C_STATUS_ACK_CYC 0x02 35 + #define KI2C_STATUS_RXAK 0x04 36 + #define KI2C_STATUS_MCF 0x08 37 + 38 + #define KI2C_STATUS_DC_REG 0x09 39 + #define KI2C_STATUS_DC_SDA 0x01 40 + #define KI2C_STATUS_DC_SCL 0x02 41 + 42 + #define KI2C_DATA_REG 0x0c 43 + 44 + #define KI2C_INUSE_SLEEP_US (2 * USEC_PER_MSEC) 45 + #define KI2C_INUSE_TIMEOUT_US (10 * USEC_PER_SEC) 46 + 47 + #define KI2C_POLL_DELAY_US 5 48 + 49 + struct ki2c { 50 + struct keba_i2c_auxdev *auxdev; 51 + void __iomem *base; 52 + struct i2c_adapter adapter; 53 + 54 + struct i2c_client **client; 55 + int client_size; 56 + }; 57 + 58 + static int ki2c_inuse_lock(struct ki2c *ki2c) 59 + { 60 + u8 sts; 61 + int ret; 62 + 63 + /* 64 + * The I2C controller has an IN_USE bit for locking access to the 65 + * controller. This enables the use of I2C controller by other none 66 + * Linux processors. 67 + * 68 + * If the I2C controller is free, then the first read returns 69 + * IN_USE == 0. After that the I2C controller is locked and further 70 + * reads of IN_USE return 1. 71 + * 72 + * The I2C controller is unlocked by writing 1 into IN_USE. 73 + * 74 + * The IN_USE bit acts as a hardware semaphore for the I2C controller. 75 + * Poll for semaphore, but sleep while polling to free the CPU. 76 + */ 77 + ret = readb_poll_timeout(ki2c->base + KI2C_STATUS_REG, 78 + sts, (sts & KI2C_STATUS_IN_USE) == 0, 79 + KI2C_INUSE_SLEEP_US, KI2C_INUSE_TIMEOUT_US); 80 + if (ret) 81 + dev_err(&ki2c->auxdev->auxdev.dev, "%s err!\n", __func__); 82 + 83 + return ret; 84 + } 85 + 86 + static void ki2c_inuse_unlock(struct ki2c *ki2c) 87 + { 88 + /* unlock the controller by writing 1 into IN_USE */ 89 + iowrite8(KI2C_STATUS_IN_USE, ki2c->base + KI2C_STATUS_REG); 90 + } 91 + 92 + static int ki2c_wait_for_bit(void __iomem *addr, u8 mask, unsigned long timeout) 93 + { 94 + u8 val; 95 + 96 + return readb_poll_timeout(addr, val, (val & mask), KI2C_POLL_DELAY_US, 97 + jiffies_to_usecs(timeout)); 98 + } 99 + 100 + static int ki2c_wait_for_mcf(struct ki2c *ki2c) 101 + { 102 + return ki2c_wait_for_bit(ki2c->base + KI2C_STATUS_REG, KI2C_STATUS_MCF, 103 + ki2c->adapter.timeout); 104 + } 105 + 106 + static int ki2c_wait_for_data(struct ki2c *ki2c) 107 + { 108 + int ret; 109 + 110 + ret = ki2c_wait_for_mcf(ki2c); 111 + if (ret < 0) 112 + return ret; 113 + 114 + return ki2c_wait_for_bit(ki2c->base + KI2C_STATUS_REG, 115 + KI2C_STATUS_ACK_CYC, 116 + ki2c->adapter.timeout); 117 + } 118 + 119 + static int ki2c_wait_for_data_ack(struct ki2c *ki2c) 120 + { 121 + unsigned int reg; 122 + int ret; 123 + 124 + ret = ki2c_wait_for_data(ki2c); 125 + if (ret < 0) 126 + return ret; 127 + 128 + /* RXAK == 0 means ACK reveived */ 129 + reg = ioread8(ki2c->base + KI2C_STATUS_REG); 130 + if (reg & KI2C_STATUS_RXAK) 131 + return -EIO; 132 + 133 + return 0; 134 + } 135 + 136 + static int ki2c_has_capability(struct ki2c *ki2c, unsigned int cap) 137 + { 138 + unsigned int reg = ioread8(ki2c->base + KI2C_CAPABILITY_REG); 139 + 140 + return (reg & cap) != 0; 141 + } 142 + 143 + static int ki2c_get_scl(struct ki2c *ki2c) 144 + { 145 + unsigned int reg = ioread8(ki2c->base + KI2C_STATUS_DC_REG); 146 + 147 + /* capability KI2C_CAPABILITY_DC required */ 148 + return (reg & KI2C_STATUS_DC_SCL) != 0; 149 + } 150 + 151 + static int ki2c_get_sda(struct ki2c *ki2c) 152 + { 153 + unsigned int reg = ioread8(ki2c->base + KI2C_STATUS_DC_REG); 154 + 155 + /* capability KI2C_CAPABILITY_DC required */ 156 + return (reg & KI2C_STATUS_DC_SDA) != 0; 157 + } 158 + 159 + static void ki2c_set_scl(struct ki2c *ki2c, int val) 160 + { 161 + u8 control_dc; 162 + 163 + /* capability KI2C_CAPABILITY_DC and KI2C_CONTROL_MEN = 0 reqired */ 164 + control_dc = ioread8(ki2c->base + KI2C_CONTROL_DC_REG); 165 + if (val) 166 + control_dc |= KI2C_CONTROL_DC_SCL; 167 + else 168 + control_dc &= ~KI2C_CONTROL_DC_SCL; 169 + iowrite8(control_dc, ki2c->base + KI2C_CONTROL_DC_REG); 170 + } 171 + 172 + /* 173 + * Resetting bus bitwise is done by checking SDA and applying clock cycles as 174 + * long as SDA is low. 9 clock cycles are applied at most. 175 + * 176 + * Clock cycles are generated and udelay() determines the duration of clock 177 + * cycles. Generated clock rate is 100 KHz and so duration of both clock levels 178 + * is: delay in ns = (10^6 / 100) / 2 179 + */ 180 + #define KI2C_RECOVERY_CLK_CNT (9 * 2) 181 + #define KI2C_RECOVERY_UDELAY 5 182 + static int ki2c_reset_bus_bitwise(struct ki2c *ki2c) 183 + { 184 + int val = 1; 185 + int ret = 0; 186 + int i; 187 + 188 + /* disable I2C controller (MEN = 0) to get direct access to SCL/SDA */ 189 + iowrite8(0, ki2c->base + KI2C_CONTROL_REG); 190 + 191 + /* generate clock cycles */ 192 + ki2c_set_scl(ki2c, val); 193 + udelay(KI2C_RECOVERY_UDELAY); 194 + for (i = 0; i < KI2C_RECOVERY_CLK_CNT; i++) { 195 + if (val) { 196 + /* SCL shouldn't be low here */ 197 + if (!ki2c_get_scl(ki2c)) { 198 + dev_err(&ki2c->auxdev->auxdev.dev, 199 + "SCL is stuck low!\n"); 200 + ret = -EBUSY; 201 + break; 202 + } 203 + 204 + /* break if SDA is high */ 205 + if (ki2c_get_sda(ki2c)) 206 + break; 207 + } 208 + 209 + val = !val; 210 + ki2c_set_scl(ki2c, val); 211 + udelay(KI2C_RECOVERY_UDELAY); 212 + } 213 + 214 + if (!ki2c_get_sda(ki2c)) { 215 + dev_err(&ki2c->auxdev->auxdev.dev, "SDA is still low!\n"); 216 + ret = -EBUSY; 217 + } 218 + 219 + /* reenable controller */ 220 + iowrite8(KI2C_CONTROL_MEN, ki2c->base + KI2C_CONTROL_REG); 221 + 222 + return ret; 223 + } 224 + 225 + /* 226 + * Resetting bus bytewise is done by writing start bit, 9 data bits and stop 227 + * bit. 228 + * 229 + * This is not 100% safe. If target is an EEPROM and a write access was 230 + * interrupted during the ACK cycle, this approach might not be able to recover 231 + * the bus. The reason is, that after the 9 clock cycles the EEPROM will be in 232 + * ACK cycle again and will hold SDA low like it did before the start of the 233 + * routine. Furthermore the EEPROM might get written one additional byte with 234 + * 0xff into it. Thus, use bitwise approach whenever possible, especially when 235 + * EEPROMs are on the bus. 236 + */ 237 + static int ki2c_reset_bus_bytewise(struct ki2c *ki2c) 238 + { 239 + int ret; 240 + 241 + /* hold data line high for 9 clock cycles */ 242 + iowrite8(0xFF, ki2c->base + KI2C_DATA_REG); 243 + 244 + /* create start condition */ 245 + iowrite8(KI2C_CONTROL_MEN | KI2C_CONTROL_MTX | KI2C_CONTROL_MSTA | KI2C_CONTROL_TXAK, 246 + ki2c->base + KI2C_CONTROL_REG); 247 + ret = ki2c_wait_for_mcf(ki2c); 248 + if (ret < 0) { 249 + dev_err(&ki2c->auxdev->auxdev.dev, "Start condition failed\n"); 250 + 251 + return ret; 252 + } 253 + 254 + /* create stop condition */ 255 + iowrite8(KI2C_CONTROL_MEN | KI2C_CONTROL_MTX | KI2C_CONTROL_TXAK, 256 + ki2c->base + KI2C_CONTROL_REG); 257 + ret = ki2c_wait_for_mcf(ki2c); 258 + if (ret < 0) 259 + dev_err(&ki2c->auxdev->auxdev.dev, "Stop condition failed\n"); 260 + 261 + return ret; 262 + } 263 + 264 + static int ki2c_reset_bus(struct ki2c *ki2c) 265 + { 266 + int ret; 267 + 268 + ret = ki2c_inuse_lock(ki2c); 269 + if (ret < 0) 270 + return ret; 271 + 272 + /* 273 + * If the I2C controller is capable of direct control of SCL/SDA, then a 274 + * bitwise reset is used. Otherwise fall back to bytewise reset. 275 + */ 276 + if (ki2c_has_capability(ki2c, KI2C_CAPABILITY_DC)) 277 + ret = ki2c_reset_bus_bitwise(ki2c); 278 + else 279 + ret = ki2c_reset_bus_bytewise(ki2c); 280 + 281 + ki2c_inuse_unlock(ki2c); 282 + 283 + return ret; 284 + } 285 + 286 + static void ki2c_write_target_addr(struct ki2c *ki2c, struct i2c_msg *m) 287 + { 288 + u8 addr; 289 + 290 + addr = m->addr << 1; 291 + /* Bit 0 signals RD/WR */ 292 + if (m->flags & I2C_M_RD) 293 + addr |= 0x01; 294 + 295 + iowrite8(addr, ki2c->base + KI2C_DATA_REG); 296 + } 297 + 298 + static int ki2c_start_addr(struct ki2c *ki2c, struct i2c_msg *m) 299 + { 300 + int ret; 301 + 302 + /* 303 + * Store target address byte in the controller. This has to be done 304 + * before sending START condition. 305 + */ 306 + ki2c_write_target_addr(ki2c, m); 307 + 308 + /* enable controller for TX */ 309 + iowrite8(KI2C_CONTROL_MEN | KI2C_CONTROL_MTX, 310 + ki2c->base + KI2C_CONTROL_REG); 311 + 312 + /* send START condition and target address byte */ 313 + iowrite8(KI2C_CONTROL_MEN | KI2C_CONTROL_MTX | KI2C_CONTROL_MSTA, 314 + ki2c->base + KI2C_CONTROL_REG); 315 + 316 + ret = ki2c_wait_for_data_ack(ki2c); 317 + if (ret < 0) 318 + /* 319 + * For EEPROMs this is normal behavior during internal write 320 + * operation. 321 + */ 322 + dev_dbg(&ki2c->auxdev->auxdev.dev, 323 + "%s wait for ACK err at 0x%02x!\n", __func__, m->addr); 324 + 325 + return ret; 326 + } 327 + 328 + static int ki2c_repstart_addr(struct ki2c *ki2c, struct i2c_msg *m) 329 + { 330 + int ret; 331 + 332 + /* repeated start and write is not supported */ 333 + if ((m->flags & I2C_M_RD) == 0) { 334 + dev_err(&ki2c->auxdev->auxdev.dev, 335 + "Repeated start not supported for writes\n"); 336 + return -EINVAL; 337 + } 338 + 339 + /* send repeated start */ 340 + iowrite8(KI2C_CONTROL_MEN | KI2C_CONTROL_MSTA | KI2C_CONTROL_RSTA, 341 + ki2c->base + KI2C_CONTROL_REG); 342 + 343 + ret = ki2c_wait_for_mcf(ki2c); 344 + if (ret < 0) { 345 + dev_err(&ki2c->auxdev->auxdev.dev, 346 + "%s wait for MCF err at 0x%02x!\n", __func__, m->addr); 347 + return ret; 348 + } 349 + 350 + /* write target-address byte */ 351 + ki2c_write_target_addr(ki2c, m); 352 + 353 + ret = ki2c_wait_for_data_ack(ki2c); 354 + if (ret < 0) 355 + dev_err(&ki2c->auxdev->auxdev.dev, 356 + "%s wait for ACK err at 0x%02x!\n", __func__, m->addr); 357 + 358 + return ret; 359 + } 360 + 361 + static void ki2c_stop(struct ki2c *ki2c) 362 + { 363 + iowrite8(KI2C_CONTROL_MEN, ki2c->base + KI2C_CONTROL_REG); 364 + ki2c_wait_for_mcf(ki2c); 365 + } 366 + 367 + static int ki2c_write(struct ki2c *ki2c, const u8 *data, int len) 368 + { 369 + int ret; 370 + int i; 371 + 372 + for (i = 0; i < len; i++) { 373 + /* write data byte */ 374 + iowrite8(data[i], ki2c->base + KI2C_DATA_REG); 375 + 376 + ret = ki2c_wait_for_data_ack(ki2c); 377 + if (ret < 0) 378 + return ret; 379 + } 380 + 381 + return 0; 382 + } 383 + 384 + static int ki2c_read(struct ki2c *ki2c, u8 *data, int len) 385 + { 386 + u8 control; 387 + int ret; 388 + int i; 389 + 390 + if (len == 0) 391 + return 0; /* nothing to do */ 392 + 393 + control = KI2C_CONTROL_MEN | KI2C_CONTROL_MSTA; 394 + 395 + /* if just one byte => send tx-nack after transfer */ 396 + if (len == 1) 397 + control |= KI2C_CONTROL_TXAK; 398 + 399 + iowrite8(control, ki2c->base + KI2C_CONTROL_REG); 400 + 401 + /* dummy read to start transfer on bus */ 402 + ioread8(ki2c->base + KI2C_DATA_REG); 403 + 404 + for (i = 0; i < len; i++) { 405 + ret = ki2c_wait_for_data(ki2c); 406 + if (ret < 0) 407 + return ret; 408 + 409 + if (i == len - 2) 410 + /* send tx-nack after transfer of last byte */ 411 + iowrite8(KI2C_CONTROL_MEN | KI2C_CONTROL_MSTA | KI2C_CONTROL_TXAK, 412 + ki2c->base + KI2C_CONTROL_REG); 413 + else if (i == len - 1) 414 + /* 415 + * switch to TX on last byte, so that reading DATA 416 + * register does not trigger another read transfer 417 + */ 418 + iowrite8(KI2C_CONTROL_MEN | KI2C_CONTROL_MSTA | KI2C_CONTROL_MTX, 419 + ki2c->base + KI2C_CONTROL_REG); 420 + 421 + /* read byte and start next transfer (if not last byte) */ 422 + data[i] = ioread8(ki2c->base + KI2C_DATA_REG); 423 + } 424 + 425 + return len; 426 + } 427 + 428 + static int ki2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) 429 + { 430 + struct ki2c *ki2c = i2c_get_adapdata(adap); 431 + int ret; 432 + int i; 433 + 434 + ret = ki2c_inuse_lock(ki2c); 435 + if (ret < 0) 436 + return ret; 437 + 438 + for (i = 0; i < num; i++) { 439 + struct i2c_msg *m = &msgs[i]; 440 + 441 + if (i == 0) 442 + ret = ki2c_start_addr(ki2c, m); 443 + else 444 + ret = ki2c_repstart_addr(ki2c, m); 445 + if (ret < 0) 446 + break; 447 + 448 + if (m->flags & I2C_M_RD) 449 + ret = ki2c_read(ki2c, m->buf, m->len); 450 + else 451 + ret = ki2c_write(ki2c, m->buf, m->len); 452 + if (ret < 0) 453 + break; 454 + } 455 + 456 + ki2c_stop(ki2c); 457 + 458 + ki2c_inuse_unlock(ki2c); 459 + 460 + return ret < 0 ? ret : num; 461 + } 462 + 463 + static void ki2c_unregister_devices(struct ki2c *ki2c) 464 + { 465 + int i; 466 + 467 + for (i = 0; i < ki2c->client_size; i++) { 468 + struct i2c_client *client = ki2c->client[i]; 469 + 470 + if (client) 471 + i2c_unregister_device(client); 472 + } 473 + } 474 + 475 + static int ki2c_register_devices(struct ki2c *ki2c) 476 + { 477 + struct i2c_board_info *info = ki2c->auxdev->info; 478 + int i; 479 + 480 + /* register all known I2C devices */ 481 + for (i = 0; i < ki2c->client_size; i++) { 482 + struct i2c_client *client; 483 + unsigned short const addr_list[2] = { info[i].addr, 484 + I2C_CLIENT_END }; 485 + 486 + client = i2c_new_scanned_device(&ki2c->adapter, &info[i], 487 + addr_list, NULL); 488 + if (!IS_ERR(client)) { 489 + ki2c->client[i] = client; 490 + } else if (PTR_ERR(client) != -ENODEV) { 491 + ki2c->client_size = i; 492 + ki2c_unregister_devices(ki2c); 493 + 494 + return PTR_ERR(client); 495 + } 496 + } 497 + 498 + return 0; 499 + } 500 + 501 + static u32 ki2c_func(struct i2c_adapter *adap) 502 + { 503 + return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; 504 + } 505 + 506 + static const struct i2c_algorithm ki2c_algo = { 507 + .master_xfer = ki2c_xfer, 508 + .functionality = ki2c_func, 509 + }; 510 + 511 + static int ki2c_probe(struct auxiliary_device *auxdev, 512 + const struct auxiliary_device_id *id) 513 + { 514 + struct device *dev = &auxdev->dev; 515 + struct i2c_adapter *adap; 516 + struct ki2c *ki2c; 517 + int ret; 518 + 519 + ki2c = devm_kzalloc(dev, sizeof(*ki2c), GFP_KERNEL); 520 + if (!ki2c) 521 + return -ENOMEM; 522 + ki2c->auxdev = container_of(auxdev, struct keba_i2c_auxdev, auxdev); 523 + ki2c->client = devm_kcalloc(dev, ki2c->auxdev->info_size, 524 + sizeof(*ki2c->client), GFP_KERNEL); 525 + if (!ki2c->client) 526 + return -ENOMEM; 527 + ki2c->client_size = ki2c->auxdev->info_size; 528 + auxiliary_set_drvdata(auxdev, ki2c); 529 + 530 + ki2c->base = devm_ioremap_resource(dev, &ki2c->auxdev->io); 531 + if (IS_ERR(ki2c->base)) 532 + return PTR_ERR(ki2c->base); 533 + 534 + adap = &ki2c->adapter; 535 + strscpy(adap->name, "KEBA I2C adapter", sizeof(adap->name)); 536 + adap->owner = THIS_MODULE; 537 + adap->class = I2C_CLASS_HWMON; 538 + adap->algo = &ki2c_algo; 539 + adap->dev.parent = dev; 540 + 541 + i2c_set_adapdata(adap, ki2c); 542 + 543 + /* enable controller */ 544 + iowrite8(KI2C_CONTROL_MEN, ki2c->base + KI2C_CONTROL_REG); 545 + 546 + /* reset bus before probing I2C devices */ 547 + ret = ki2c_reset_bus(ki2c); 548 + if (ret) 549 + goto out; 550 + 551 + ret = devm_i2c_add_adapter(dev, adap); 552 + if (ret) { 553 + dev_err(dev, "Failed to add adapter (%d)!\n", ret); 554 + goto out; 555 + } 556 + 557 + ret = ki2c_register_devices(ki2c); 558 + if (ret) { 559 + dev_err(dev, "Failed to register devices (%d)!\n", ret); 560 + goto out; 561 + } 562 + 563 + return 0; 564 + 565 + out: 566 + iowrite8(KI2C_CONTROL_DISABLE, ki2c->base + KI2C_CONTROL_REG); 567 + return ret; 568 + } 569 + 570 + static void ki2c_remove(struct auxiliary_device *auxdev) 571 + { 572 + struct ki2c *ki2c = auxiliary_get_drvdata(auxdev); 573 + 574 + ki2c_unregister_devices(ki2c); 575 + 576 + /* disable controller */ 577 + iowrite8(KI2C_CONTROL_DISABLE, ki2c->base + KI2C_CONTROL_REG); 578 + 579 + auxiliary_set_drvdata(auxdev, NULL); 580 + } 581 + 582 + static const struct auxiliary_device_id ki2c_devtype_aux[] = { 583 + { .name = "keba.i2c" }, 584 + { } 585 + }; 586 + MODULE_DEVICE_TABLE(auxiliary, ki2c_devtype_aux); 587 + 588 + static struct auxiliary_driver ki2c_driver_aux = { 589 + .name = KI2C, 590 + .id_table = ki2c_devtype_aux, 591 + .probe = ki2c_probe, 592 + .remove = ki2c_remove, 593 + }; 594 + module_auxiliary_driver(ki2c_driver_aux); 595 + 596 + MODULE_AUTHOR("Gerhard Engleder <eg@keba.com>"); 597 + MODULE_DESCRIPTION("KEBA I2C bus controller driver"); 598 + MODULE_LICENSE("GPL");
+3 -3
drivers/i2c/busses/i2c-ljca.c
··· 107 107 return 0; 108 108 } 109 109 110 - static void ljca_i2c_stop(struct ljca_i2c_dev *ljca_i2c, u8 target_addr) 110 + static void ljca_i2c_stop(struct ljca_i2c_dev *ljca_i2c) 111 111 { 112 112 struct ljca_i2c_rw_packet *w_packet = 113 113 (struct ljca_i2c_rw_packet *)ljca_i2c->obuf; ··· 178 178 if (!ret) 179 179 ret = ljca_i2c_pure_read(ljca_i2c, data, len); 180 180 181 - ljca_i2c_stop(ljca_i2c, target_addr); 181 + ljca_i2c_stop(ljca_i2c); 182 182 183 183 return ret; 184 184 } ··· 222 222 if (!ret) 223 223 ret = ljca_i2c_pure_write(ljca_i2c, data, len); 224 224 225 - ljca_i2c_stop(ljca_i2c, target_addr); 225 + ljca_i2c_stop(ljca_i2c); 226 226 227 227 return ret; 228 228 }
+4 -19
drivers/i2c/busses/i2c-mpc.c
··· 88 88 int irq; 89 89 u32 real_clk; 90 90 u8 fdr, dfsrr; 91 - struct clk *clk_per; 92 91 u32 cntl_bits; 93 92 enum mpc_i2c_action action; 94 93 struct i2c_msg *msgs; ··· 778 779 struct clk *clk; 779 780 int result; 780 781 u32 clock; 781 - int err; 782 782 783 783 i2c = devm_kzalloc(&op->dev, sizeof(*i2c), GFP_KERNEL); 784 784 if (!i2c) ··· 807 809 * enable clock for the I2C peripheral (non fatal), 808 810 * keep a reference upon successful allocation 809 811 */ 810 - clk = devm_clk_get_optional(&op->dev, NULL); 811 - if (IS_ERR(clk)) 812 - return PTR_ERR(clk); 813 - 814 - err = clk_prepare_enable(clk); 815 - if (err) { 812 + clk = devm_clk_get_optional_enabled(&op->dev, NULL); 813 + if (IS_ERR(clk)) { 816 814 dev_err(&op->dev, "failed to enable clock\n"); 817 - return err; 815 + return PTR_ERR(clk); 818 816 } 819 - 820 - i2c->clk_per = clk; 821 817 822 818 if (of_property_read_bool(op->dev.of_node, "fsl,preserve-clocking")) { 823 819 clock = MPC_I2C_CLOCK_PRESERVE; ··· 868 876 869 877 result = i2c_add_numbered_adapter(&i2c->adap); 870 878 if (result) 871 - goto fail_add; 879 + return result; 872 880 873 881 return 0; 874 - 875 - fail_add: 876 - clk_disable_unprepare(i2c->clk_per); 877 - 878 - return result; 879 882 }; 880 883 881 884 static void fsl_i2c_remove(struct platform_device *op) ··· 878 891 struct mpc_i2c *i2c = platform_get_drvdata(op); 879 892 880 893 i2c_del_adapter(&i2c->adap); 881 - 882 - clk_disable_unprepare(i2c->clk_per); 883 894 }; 884 895 885 896 static int __maybe_unused mpc_i2c_suspend(struct device *dev)
+1 -4
drivers/i2c/busses/i2c-mt65xx.c
··· 1306 1306 static irqreturn_t mtk_i2c_irq(int irqno, void *dev_id) 1307 1307 { 1308 1308 struct mtk_i2c *i2c = dev_id; 1309 - u16 restart_flag = 0; 1309 + u16 restart_flag = i2c->auto_restart ? I2C_RS_TRANSFER : 0; 1310 1310 u16 intr_stat; 1311 - 1312 - if (i2c->auto_restart) 1313 - restart_flag = I2C_RS_TRANSFER; 1314 1311 1315 1312 intr_stat = mtk_i2c_readw(i2c, OFFSET_INTR_STAT); 1316 1313 mtk_i2c_writew(i2c, intr_stat, OFFSET_INTR_STAT);
+4 -2
drivers/i2c/busses/i2c-npcm7xx.c
··· 136 136 * Since the addr regs are sprinkled all over the address space, 137 137 * use this array to get the address or each register. 138 138 */ 139 - #define I2C_NUM_OWN_ADDR 2 139 + #define I2C_NUM_OWN_ADDR 10 140 140 #define I2C_NUM_OWN_ADDR_SUPPORTED 2 141 141 142 142 static const int npcm_i2caddr[I2C_NUM_OWN_ADDR] = { 143 - NPCM_I2CADDR1, NPCM_I2CADDR2, 143 + NPCM_I2CADDR1, NPCM_I2CADDR2, NPCM_I2CADDR3, NPCM_I2CADDR4, 144 + NPCM_I2CADDR5, NPCM_I2CADDR6, NPCM_I2CADDR7, NPCM_I2CADDR8, 145 + NPCM_I2CADDR9, NPCM_I2CADDR10, 144 146 }; 145 147 #endif 146 148
+1 -1
drivers/i2c/busses/i2c-omap.c
··· 1261 1261 .compatible = "ti,omap2420-i2c", 1262 1262 .data = &omap2420_pdata, 1263 1263 }, 1264 - { }, 1264 + { } 1265 1265 }; 1266 1266 MODULE_DEVICE_TABLE(of, omap_i2c_of_match); 1267 1267 #endif
+1 -1
drivers/i2c/busses/i2c-piix4.c
··· 146 146 .ident = "IBM", 147 147 .matches = { DMI_MATCH(DMI_SYS_VENDOR, "IBM"), }, 148 148 }, 149 - { }, 149 + { } 150 150 }; 151 151 152 152 /*
+1 -1
drivers/i2c/busses/i2c-pnx.c
··· 721 721 #ifdef CONFIG_OF 722 722 static const struct of_device_id i2c_pnx_of_match[] = { 723 723 { .compatible = "nxp,pnx-i2c" }, 724 - { }, 724 + { } 725 725 }; 726 726 MODULE_DEVICE_TABLE(of, i2c_pnx_of_match); 727 727 #endif
+1 -1
drivers/i2c/busses/i2c-pxa-pci.c
··· 135 135 136 136 static const struct pci_device_id ce4100_i2c_devices[] = { 137 137 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x2e68)}, 138 - { }, 138 + { } 139 139 }; 140 140 141 141 static struct pci_driver ce4100_i2c_driver = {
+1 -1
drivers/i2c/busses/i2c-pxa.c
··· 218 218 { "ce4100-i2c", REGS_CE4100 }, 219 219 { "pxa910-i2c", REGS_PXA910 }, 220 220 { "armada-3700-i2c", REGS_A3700 }, 221 - { }, 221 + { } 222 222 }; 223 223 MODULE_DEVICE_TABLE(platform, i2c_pxa_id_table); 224 224
+13 -10
drivers/i2c/busses/i2c-qcom-geni.c
··· 721 721 static const struct acpi_device_id geni_i2c_acpi_match[] = { 722 722 { "QCOM0220"}, 723 723 { "QCOM0411" }, 724 - { }, 724 + { } 725 725 }; 726 726 MODULE_DEVICE_TABLE(acpi, geni_i2c_acpi_match); 727 727 #endif ··· 984 984 return ret; 985 985 986 986 ret = clk_prepare_enable(gi2c->core_clk); 987 - if (ret) { 988 - geni_icc_disable(&gi2c->se); 989 - return ret; 990 - } 987 + if (ret) 988 + goto out_icc_disable; 991 989 992 990 ret = geni_se_resources_on(&gi2c->se); 993 - if (ret) { 994 - clk_disable_unprepare(gi2c->core_clk); 995 - geni_icc_disable(&gi2c->se); 996 - return ret; 997 - } 991 + if (ret) 992 + goto out_clk_disable; 998 993 999 994 enable_irq(gi2c->irq); 1000 995 gi2c->suspended = 0; 996 + 1001 997 return 0; 998 + 999 + out_clk_disable: 1000 + clk_disable_unprepare(gi2c->core_clk); 1001 + out_icc_disable: 1002 + geni_icc_disable(&gi2c->se); 1003 + 1004 + return ret; 1002 1005 } 1003 1006 1004 1007 static int __maybe_unused geni_i2c_suspend_noirq(struct device *dev)
+1 -1
drivers/i2c/busses/i2c-qup.c
··· 1648 1648 1649 1649 static const struct acpi_device_id qup_i2c_acpi_match[] = { 1650 1650 { "QCOM8010"}, 1651 - { }, 1651 + { } 1652 1652 }; 1653 1653 MODULE_DEVICE_TABLE(acpi, qup_i2c_acpi_match); 1654 1654
+5 -7
drivers/i2c/busses/i2c-rcar.c
··· 1164 1164 rcar_i2c_init(priv); 1165 1165 rcar_i2c_reset_slave(priv); 1166 1166 1167 - if (priv->devtype < I2C_RCAR_GEN3) { 1168 - irqflags |= IRQF_NO_THREAD; 1169 - irqhandler = rcar_i2c_gen2_irq; 1170 - } 1171 - 1172 1167 /* Stay always active when multi-master to keep arbitration working */ 1173 1168 if (of_property_read_bool(dev->of_node, "multi-master")) 1174 1169 priv->flags |= ID_P_PM_BLOCKED; ··· 1173 1178 if (of_property_read_bool(dev->of_node, "smbus")) 1174 1179 priv->flags |= ID_P_HOST_NOTIFY; 1175 1180 1176 - /* R-Car Gen3+ needs a reset before every transfer */ 1177 - if (priv->devtype >= I2C_RCAR_GEN3) { 1181 + if (priv->devtype < I2C_RCAR_GEN3) { 1182 + irqflags |= IRQF_NO_THREAD; 1183 + irqhandler = rcar_i2c_gen2_irq; 1184 + } else { 1185 + /* R-Car Gen3+ needs a reset before every transfer */ 1178 1186 priv->rstc = devm_reset_control_get_exclusive(&pdev->dev, NULL); 1179 1187 if (IS_ERR(priv->rstc)) { 1180 1188 ret = PTR_ERR(priv->rstc);
+157 -71
drivers/i2c/busses/i2c-riic.c
··· 63 63 #define ICMR3_ACKWP 0x10 64 64 #define ICMR3_ACKBT 0x08 65 65 66 + #define ICFER_FMPE 0x80 67 + 66 68 #define ICIER_TIE 0x80 67 69 #define ICIER_TEIE 0x40 68 70 #define ICIER_RIE 0x20 ··· 82 80 RIIC_ICCR2, 83 81 RIIC_ICMR1, 84 82 RIIC_ICMR3, 83 + RIIC_ICFER, 85 84 RIIC_ICSER, 86 85 RIIC_ICIER, 87 86 RIIC_ICSR2, ··· 94 91 }; 95 92 96 93 struct riic_of_data { 97 - u8 regs[RIIC_REG_END]; 94 + const u8 *regs; 95 + bool fast_mode_plus; 98 96 }; 99 97 100 98 struct riic_dev { ··· 109 105 struct completion msg_done; 110 106 struct i2c_adapter adapter; 111 107 struct clk *clk; 108 + struct reset_control *rstc; 109 + struct i2c_timings i2c_t; 112 110 }; 113 111 114 112 struct riic_irq_desc { ··· 137 131 static int riic_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) 138 132 { 139 133 struct riic_dev *riic = i2c_get_adapdata(adap); 134 + struct device *dev = adap->dev.parent; 140 135 unsigned long time_left; 141 - int i; 136 + int i, ret; 142 137 u8 start_bit; 143 138 144 - pm_runtime_get_sync(adap->dev.parent); 139 + ret = pm_runtime_resume_and_get(dev); 140 + if (ret) 141 + return ret; 145 142 146 143 if (riic_readb(riic, RIIC_ICCR2) & ICCR2_BBSY) { 147 144 riic->err = -EBUSY; ··· 177 168 } 178 169 179 170 out: 180 - pm_runtime_put(adap->dev.parent); 171 + pm_runtime_mark_last_busy(dev); 172 + pm_runtime_put_autosuspend(dev); 181 173 182 174 return riic->err ?: num; 183 175 } ··· 308 298 .functionality = riic_func, 309 299 }; 310 300 311 - static int riic_init_hw(struct riic_dev *riic, struct i2c_timings *t) 301 + static int riic_init_hw(struct riic_dev *riic) 312 302 { 313 - int ret = 0; 303 + int ret; 314 304 unsigned long rate; 315 305 int total_ticks, cks, brl, brh; 306 + struct i2c_timings *t = &riic->i2c_t; 307 + struct device *dev = riic->adapter.dev.parent; 308 + bool fast_mode_plus = riic->info->fast_mode_plus; 309 + u32 max_freq = fast_mode_plus ? I2C_MAX_FAST_MODE_PLUS_FREQ 310 + : I2C_MAX_FAST_MODE_FREQ; 316 311 317 - pm_runtime_get_sync(riic->adapter.dev.parent); 318 - 319 - if (t->bus_freq_hz > I2C_MAX_FAST_MODE_FREQ) { 320 - dev_err(&riic->adapter.dev, 321 - "unsupported bus speed (%dHz). %d max\n", 322 - t->bus_freq_hz, I2C_MAX_FAST_MODE_FREQ); 323 - ret = -EINVAL; 324 - goto out; 325 - } 312 + if (t->bus_freq_hz > max_freq) 313 + return dev_err_probe(&riic->adapter.dev, -EINVAL, 314 + "unsupported bus speed %uHz (%u max)\n", 315 + t->bus_freq_hz, max_freq); 326 316 327 317 rate = clk_get_rate(riic->clk); 328 318 ··· 359 349 if (brl > (0x1F + 3)) { 360 350 dev_err(&riic->adapter.dev, "invalid speed (%lu). Too slow.\n", 361 351 (unsigned long)t->bus_freq_hz); 362 - ret = -EINVAL; 363 - goto out; 352 + return -EINVAL; 364 353 } 365 354 366 355 brh = total_ticks - brl; ··· 391 382 t->scl_fall_ns / (1000000000 / rate), 392 383 t->scl_rise_ns / (1000000000 / rate), cks, brl, brh); 393 384 385 + ret = pm_runtime_resume_and_get(dev); 386 + if (ret) 387 + return ret; 388 + 394 389 /* Changing the order of accessing IICRST and ICE may break things! */ 395 390 riic_writeb(riic, ICCR1_IICRST | ICCR1_SOWP, RIIC_ICCR1); 396 391 riic_clear_set_bit(riic, 0, ICCR1_ICE, RIIC_ICCR1); ··· 406 393 riic_writeb(riic, 0, RIIC_ICSER); 407 394 riic_writeb(riic, ICMR3_ACKWP | ICMR3_RDRFS, RIIC_ICMR3); 408 395 396 + if (fast_mode_plus && t->bus_freq_hz > I2C_MAX_FAST_MODE_FREQ) 397 + riic_clear_set_bit(riic, 0, ICFER_FMPE, RIIC_ICFER); 398 + 409 399 riic_clear_set_bit(riic, ICCR1_IICRST, 0, RIIC_ICCR1); 410 400 411 - out: 412 - pm_runtime_put(riic->adapter.dev.parent); 413 - return ret; 401 + pm_runtime_mark_last_busy(dev); 402 + pm_runtime_put_autosuspend(dev); 403 + return 0; 414 404 } 415 405 416 406 static struct riic_irq_desc riic_irqs[] = { ··· 431 415 432 416 static int riic_i2c_probe(struct platform_device *pdev) 433 417 { 418 + struct device *dev = &pdev->dev; 434 419 struct riic_dev *riic; 435 420 struct i2c_adapter *adap; 436 - struct i2c_timings i2c_t; 437 - struct reset_control *rstc; 438 421 int i, ret; 439 422 440 - riic = devm_kzalloc(&pdev->dev, sizeof(*riic), GFP_KERNEL); 423 + riic = devm_kzalloc(dev, sizeof(*riic), GFP_KERNEL); 441 424 if (!riic) 442 425 return -ENOMEM; 443 426 ··· 444 429 if (IS_ERR(riic->base)) 445 430 return PTR_ERR(riic->base); 446 431 447 - riic->clk = devm_clk_get(&pdev->dev, NULL); 432 + riic->clk = devm_clk_get(dev, NULL); 448 433 if (IS_ERR(riic->clk)) { 449 - dev_err(&pdev->dev, "missing controller clock"); 434 + dev_err(dev, "missing controller clock"); 450 435 return PTR_ERR(riic->clk); 451 436 } 452 437 453 - rstc = devm_reset_control_get_optional_exclusive(&pdev->dev, NULL); 454 - if (IS_ERR(rstc)) 455 - return dev_err_probe(&pdev->dev, PTR_ERR(rstc), 438 + riic->rstc = devm_reset_control_get_optional_exclusive(dev, NULL); 439 + if (IS_ERR(riic->rstc)) 440 + return dev_err_probe(dev, PTR_ERR(riic->rstc), 456 441 "Error: missing reset ctrl\n"); 457 442 458 - ret = reset_control_deassert(rstc); 443 + ret = reset_control_deassert(riic->rstc); 459 444 if (ret) 460 445 return ret; 461 446 462 - ret = devm_add_action_or_reset(&pdev->dev, riic_reset_control_assert, rstc); 447 + ret = devm_add_action_or_reset(dev, riic_reset_control_assert, riic->rstc); 463 448 if (ret) 464 449 return ret; 465 450 ··· 468 453 if (ret < 0) 469 454 return ret; 470 455 471 - ret = devm_request_irq(&pdev->dev, ret, riic_irqs[i].isr, 456 + ret = devm_request_irq(dev, ret, riic_irqs[i].isr, 472 457 0, riic_irqs[i].name, riic); 473 458 if (ret) { 474 - dev_err(&pdev->dev, "failed to request irq %s\n", riic_irqs[i].name); 459 + dev_err(dev, "failed to request irq %s\n", riic_irqs[i].name); 475 460 return ret; 476 461 } 477 462 } 478 463 479 - riic->info = of_device_get_match_data(&pdev->dev); 464 + riic->info = of_device_get_match_data(dev); 480 465 481 466 adap = &riic->adapter; 482 467 i2c_set_adapdata(adap, riic); 483 468 strscpy(adap->name, "Renesas RIIC adapter", sizeof(adap->name)); 484 469 adap->owner = THIS_MODULE; 485 470 adap->algo = &riic_algo; 486 - adap->dev.parent = &pdev->dev; 487 - adap->dev.of_node = pdev->dev.of_node; 471 + adap->dev.parent = dev; 472 + adap->dev.of_node = dev->of_node; 488 473 489 474 init_completion(&riic->msg_done); 490 475 491 - i2c_parse_fw_timings(&pdev->dev, &i2c_t, true); 476 + i2c_parse_fw_timings(dev, &riic->i2c_t, true); 492 477 493 - pm_runtime_enable(&pdev->dev); 478 + /* Default 0 to save power. Can be overridden via sysfs for lower latency. */ 479 + pm_runtime_set_autosuspend_delay(dev, 0); 480 + pm_runtime_use_autosuspend(dev); 481 + pm_runtime_enable(dev); 494 482 495 - ret = riic_init_hw(riic, &i2c_t); 483 + ret = riic_init_hw(riic); 496 484 if (ret) 497 485 goto out; 498 486 ··· 505 487 506 488 platform_set_drvdata(pdev, riic); 507 489 508 - dev_info(&pdev->dev, "registered with %dHz bus speed\n", 509 - i2c_t.bus_freq_hz); 490 + dev_info(dev, "registered with %dHz bus speed\n", riic->i2c_t.bus_freq_hz); 510 491 return 0; 511 492 512 493 out: 513 - pm_runtime_disable(&pdev->dev); 494 + pm_runtime_disable(dev); 495 + pm_runtime_dont_use_autosuspend(dev); 514 496 return ret; 515 497 } 516 498 517 499 static void riic_i2c_remove(struct platform_device *pdev) 518 500 { 519 501 struct riic_dev *riic = platform_get_drvdata(pdev); 502 + struct device *dev = &pdev->dev; 503 + int ret; 520 504 521 - pm_runtime_get_sync(&pdev->dev); 522 - riic_writeb(riic, 0, RIIC_ICIER); 523 - pm_runtime_put(&pdev->dev); 505 + ret = pm_runtime_resume_and_get(dev); 506 + if (!ret) { 507 + riic_writeb(riic, 0, RIIC_ICIER); 508 + pm_runtime_put(dev); 509 + } 524 510 i2c_del_adapter(&riic->adapter); 525 - pm_runtime_disable(&pdev->dev); 511 + pm_runtime_disable(dev); 512 + pm_runtime_dont_use_autosuspend(dev); 526 513 } 527 514 515 + static const u8 riic_rz_a_regs[RIIC_REG_END] = { 516 + [RIIC_ICCR1] = 0x00, 517 + [RIIC_ICCR2] = 0x04, 518 + [RIIC_ICMR1] = 0x08, 519 + [RIIC_ICMR3] = 0x10, 520 + [RIIC_ICFER] = 0x14, 521 + [RIIC_ICSER] = 0x18, 522 + [RIIC_ICIER] = 0x1c, 523 + [RIIC_ICSR2] = 0x24, 524 + [RIIC_ICBRL] = 0x34, 525 + [RIIC_ICBRH] = 0x38, 526 + [RIIC_ICDRT] = 0x3c, 527 + [RIIC_ICDRR] = 0x40, 528 + }; 529 + 528 530 static const struct riic_of_data riic_rz_a_info = { 529 - .regs = { 530 - [RIIC_ICCR1] = 0x00, 531 - [RIIC_ICCR2] = 0x04, 532 - [RIIC_ICMR1] = 0x08, 533 - [RIIC_ICMR3] = 0x10, 534 - [RIIC_ICSER] = 0x18, 535 - [RIIC_ICIER] = 0x1c, 536 - [RIIC_ICSR2] = 0x24, 537 - [RIIC_ICBRL] = 0x34, 538 - [RIIC_ICBRH] = 0x38, 539 - [RIIC_ICDRT] = 0x3c, 540 - [RIIC_ICDRR] = 0x40, 541 - }, 531 + .regs = riic_rz_a_regs, 532 + .fast_mode_plus = true, 533 + }; 534 + 535 + static const struct riic_of_data riic_rz_a1h_info = { 536 + .regs = riic_rz_a_regs, 537 + }; 538 + 539 + static const u8 riic_rz_v2h_regs[RIIC_REG_END] = { 540 + [RIIC_ICCR1] = 0x00, 541 + [RIIC_ICCR2] = 0x01, 542 + [RIIC_ICMR1] = 0x02, 543 + [RIIC_ICMR3] = 0x04, 544 + [RIIC_ICFER] = 0x05, 545 + [RIIC_ICSER] = 0x06, 546 + [RIIC_ICIER] = 0x07, 547 + [RIIC_ICSR2] = 0x09, 548 + [RIIC_ICBRL] = 0x10, 549 + [RIIC_ICBRH] = 0x11, 550 + [RIIC_ICDRT] = 0x12, 551 + [RIIC_ICDRR] = 0x13, 542 552 }; 543 553 544 554 static const struct riic_of_data riic_rz_v2h_info = { 545 - .regs = { 546 - [RIIC_ICCR1] = 0x00, 547 - [RIIC_ICCR2] = 0x01, 548 - [RIIC_ICMR1] = 0x02, 549 - [RIIC_ICMR3] = 0x04, 550 - [RIIC_ICSER] = 0x06, 551 - [RIIC_ICIER] = 0x07, 552 - [RIIC_ICSR2] = 0x09, 553 - [RIIC_ICBRL] = 0x10, 554 - [RIIC_ICBRH] = 0x11, 555 - [RIIC_ICDRT] = 0x12, 556 - [RIIC_ICDRR] = 0x13, 557 - }, 555 + .regs = riic_rz_v2h_regs, 556 + .fast_mode_plus = true, 557 + }; 558 + 559 + static int riic_i2c_suspend(struct device *dev) 560 + { 561 + struct riic_dev *riic = dev_get_drvdata(dev); 562 + int ret; 563 + 564 + ret = pm_runtime_resume_and_get(dev); 565 + if (ret) 566 + return ret; 567 + 568 + i2c_mark_adapter_suspended(&riic->adapter); 569 + 570 + /* Disable output on SDA, SCL pins. */ 571 + riic_clear_set_bit(riic, ICCR1_ICE, 0, RIIC_ICCR1); 572 + 573 + pm_runtime_mark_last_busy(dev); 574 + pm_runtime_put_sync(dev); 575 + 576 + return reset_control_assert(riic->rstc); 577 + } 578 + 579 + static int riic_i2c_resume(struct device *dev) 580 + { 581 + struct riic_dev *riic = dev_get_drvdata(dev); 582 + int ret; 583 + 584 + ret = reset_control_deassert(riic->rstc); 585 + if (ret) 586 + return ret; 587 + 588 + ret = riic_init_hw(riic); 589 + if (ret) { 590 + /* 591 + * In case this happens there is no way to recover from this 592 + * state. The driver will remain loaded. We want to avoid 593 + * keeping the reset line de-asserted for no reason. 594 + */ 595 + reset_control_assert(riic->rstc); 596 + return ret; 597 + } 598 + 599 + i2c_mark_adapter_resumed(&riic->adapter); 600 + 601 + return 0; 602 + } 603 + 604 + static const struct dev_pm_ops riic_i2c_pm_ops = { 605 + SYSTEM_SLEEP_PM_OPS(riic_i2c_suspend, riic_i2c_resume) 558 606 }; 559 607 560 608 static const struct of_device_id riic_i2c_dt_ids[] = { 561 609 { .compatible = "renesas,riic-rz", .data = &riic_rz_a_info }, 610 + { .compatible = "renesas,riic-r7s72100", .data = &riic_rz_a1h_info, }, 562 611 { .compatible = "renesas,riic-r9a09g057", .data = &riic_rz_v2h_info }, 563 612 { /* Sentinel */ }, 564 613 }; ··· 636 551 .driver = { 637 552 .name = "i2c-riic", 638 553 .of_match_table = riic_i2c_dt_ids, 554 + .pm = pm_ptr(&riic_i2c_pm_ops), 639 555 }, 640 556 }; 641 557
+1 -1
drivers/i2c/busses/i2c-s3c2410.c
··· 130 130 }, { 131 131 .name = "s3c2440-hdmiphy-i2c", 132 132 .driver_data = QUIRK_S3C2440 | QUIRK_HDMIPHY | QUIRK_NO_GPIO, 133 - }, { }, 133 + }, { } 134 134 }; 135 135 MODULE_DEVICE_TABLE(platform, s3c24xx_driver_ids); 136 136
+2 -2
drivers/i2c/busses/i2c-virtio.c
··· 182 182 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; 183 183 } 184 184 185 - static struct i2c_algorithm virtio_algorithm = { 185 + static const struct i2c_algorithm virtio_algorithm = { 186 186 .xfer = virtio_i2c_xfer, 187 187 .functionality = virtio_i2c_func, 188 188 }; ··· 237 237 virtio_i2c_del_vqs(vdev); 238 238 } 239 239 240 - static struct virtio_device_id id_table[] = { 240 + static const struct virtio_device_id id_table[] = { 241 241 { VIRTIO_ID_I2C_ADAPTER, VIRTIO_DEV_ANY_ID }, 242 242 {} 243 243 };
+41 -38
drivers/i2c/i2c-core-base.c
··· 915 915 return 0; 916 916 } 917 917 918 + /* 919 + * Serialize device instantiation in case it can be instantiated explicitly 920 + * and by auto-detection 921 + */ 922 + static int i2c_lock_addr(struct i2c_adapter *adap, unsigned short addr, 923 + unsigned short flags) 924 + { 925 + if (!(flags & I2C_CLIENT_TEN) && 926 + test_and_set_bit(addr, adap->addrs_in_instantiation)) 927 + return -EBUSY; 928 + 929 + return 0; 930 + } 931 + 932 + static void i2c_unlock_addr(struct i2c_adapter *adap, unsigned short addr, 933 + unsigned short flags) 934 + { 935 + if (!(flags & I2C_CLIENT_TEN)) 936 + clear_bit(addr, adap->addrs_in_instantiation); 937 + } 938 + 918 939 /** 919 940 * i2c_new_client_device - instantiate an i2c device 920 941 * @adap: the adapter managing the device ··· 983 962 goto out_err_silent; 984 963 } 985 964 965 + status = i2c_lock_addr(adap, client->addr, client->flags); 966 + if (status) 967 + goto out_err_silent; 968 + 986 969 /* Check for address business */ 987 970 status = i2c_check_addr_busy(adap, i2c_encode_flags_to_addr(client)); 988 971 if (status) ··· 1018 993 dev_dbg(&adap->dev, "client [%s] registered with bus id %s\n", 1019 994 client->name, dev_name(&client->dev)); 1020 995 996 + i2c_unlock_addr(adap, client->addr, client->flags); 997 + 1021 998 return client; 1022 999 1023 1000 out_remove_swnode: ··· 1031 1004 dev_err(&adap->dev, 1032 1005 "Failed to register i2c client %s at 0x%02x (%d)\n", 1033 1006 client->name, client->addr, status); 1007 + i2c_unlock_addr(adap, client->addr, client->flags); 1034 1008 out_err_silent: 1035 1009 if (need_put) 1036 1010 put_device(&client->dev); ··· 1096 1068 static const struct i2c_device_id dummy_id[] = { 1097 1069 { "dummy", }, 1098 1070 { "smbus_host_notify", }, 1099 - { }, 1071 + { } 1100 1072 }; 1101 1073 1102 1074 static int dummy_probe(struct i2c_client *client) ··· 1395 1367 } 1396 1368 EXPORT_SYMBOL(i2c_verify_adapter); 1397 1369 1398 - #ifdef CONFIG_I2C_COMPAT 1399 - static struct class_compat *i2c_adapter_compat_class; 1400 - #endif 1401 - 1402 1370 static void i2c_scan_static_board_info(struct i2c_adapter *adapter) 1403 1371 { 1404 1372 struct i2c_devinfo *devinfo; ··· 1548 1524 dev_set_name(&adap->dev, "i2c-%d", adap->nr); 1549 1525 adap->dev.bus = &i2c_bus_type; 1550 1526 adap->dev.type = &i2c_adapter_type; 1551 - res = device_register(&adap->dev); 1527 + device_initialize(&adap->dev); 1528 + 1529 + /* 1530 + * This adapter can be used as a parent immediately after device_add(), 1531 + * setup runtime-pm (especially ignore-children) before hand. 1532 + */ 1533 + device_enable_async_suspend(&adap->dev); 1534 + pm_runtime_no_callbacks(&adap->dev); 1535 + pm_suspend_ignore_children(&adap->dev, true); 1536 + pm_runtime_enable(&adap->dev); 1537 + 1538 + res = device_add(&adap->dev); 1552 1539 if (res) { 1553 1540 pr_err("adapter '%s': can't register device (%d)\n", adap->name, res); 1554 1541 goto out_list; ··· 1571 1536 if (res) 1572 1537 goto out_reg; 1573 1538 1574 - device_enable_async_suspend(&adap->dev); 1575 - pm_runtime_no_callbacks(&adap->dev); 1576 - pm_suspend_ignore_children(&adap->dev, true); 1577 - pm_runtime_enable(&adap->dev); 1578 - 1579 1539 res = i2c_init_recovery(adap); 1580 1540 if (res == -EPROBE_DEFER) 1581 1541 goto out_reg; 1582 1542 1583 1543 dev_dbg(&adap->dev, "adapter [%s] registered\n", adap->name); 1584 - 1585 - #ifdef CONFIG_I2C_COMPAT 1586 - res = class_compat_create_link(i2c_adapter_compat_class, &adap->dev, 1587 - adap->dev.parent); 1588 - if (res) 1589 - dev_warn(&adap->dev, 1590 - "Failed to create compatibility class link\n"); 1591 - #endif 1592 1544 1593 1545 /* create pre-declared device nodes */ 1594 1546 of_i2c_register_devices(adap); ··· 1782 1760 * them up properly, so we give them a chance to do that first. */ 1783 1761 device_for_each_child(&adap->dev, NULL, __unregister_client); 1784 1762 device_for_each_child(&adap->dev, NULL, __unregister_dummy); 1785 - 1786 - #ifdef CONFIG_I2C_COMPAT 1787 - class_compat_remove_link(i2c_adapter_compat_class, &adap->dev, 1788 - adap->dev.parent); 1789 - #endif 1790 1763 1791 1764 /* device name is gone after device_unregister */ 1792 1765 dev_dbg(&adap->dev, "adapter [%s] unregistered\n", adap->name); ··· 2091 2074 2092 2075 i2c_debugfs_root = debugfs_create_dir("i2c", NULL); 2093 2076 2094 - #ifdef CONFIG_I2C_COMPAT 2095 - i2c_adapter_compat_class = class_compat_register("i2c-adapter"); 2096 - if (!i2c_adapter_compat_class) { 2097 - retval = -ENOMEM; 2098 - goto bus_err; 2099 - } 2100 - #endif 2101 2077 retval = i2c_add_driver(&dummy_driver); 2102 2078 if (retval) 2103 2079 goto class_err; ··· 2103 2093 return 0; 2104 2094 2105 2095 class_err: 2106 - #ifdef CONFIG_I2C_COMPAT 2107 - class_compat_unregister(i2c_adapter_compat_class); 2108 - bus_err: 2109 - #endif 2110 2096 is_registered = false; 2111 2097 bus_unregister(&i2c_bus_type); 2112 2098 return retval; ··· 2115 2109 if (IS_ENABLED(CONFIG_OF_DYNAMIC)) 2116 2110 WARN_ON(of_reconfig_notifier_unregister(&i2c_of_notifier)); 2117 2111 i2c_del_driver(&dummy_driver); 2118 - #ifdef CONFIG_I2C_COMPAT 2119 - class_compat_unregister(i2c_adapter_compat_class); 2120 - #endif 2121 2112 debugfs_remove_recursive(i2c_debugfs_root); 2122 2113 bus_unregister(&i2c_bus_type); 2123 2114 tracepoint_synchronize_unregister();
+2 -5
drivers/i2c/i2c-core-slave.c
··· 109 109 bool i2c_detect_slave_mode(struct device *dev) 110 110 { 111 111 if (IS_BUILTIN(CONFIG_OF) && dev->of_node) { 112 - struct device_node *child; 113 112 u32 reg; 114 113 115 - for_each_child_of_node(dev->of_node, child) { 114 + for_each_child_of_node_scoped(dev->of_node, child) { 116 115 of_property_read_u32(child, "reg", &reg); 117 - if (reg & I2C_OWN_SLAVE_ADDRESS) { 118 - of_node_put(child); 116 + if (reg & I2C_OWN_SLAVE_ADDRESS) 119 117 return true; 120 - } 121 118 } 122 119 } else if (IS_BUILTIN(CONFIG_ACPI) && ACPI_HANDLE(dev)) { 123 120 dev_dbg(dev, "ACPI slave is not supported yet\n");
+123 -43
drivers/i2c/i2c-slave-testunit.c
··· 6 6 * Copyright (C) 2020 by Renesas Electronics Corporation 7 7 */ 8 8 9 + #include <generated/utsrelease.h> 9 10 #include <linux/bitops.h> 11 + #include <linux/completion.h> 12 + #include <linux/gpio/consumer.h> 10 13 #include <linux/i2c.h> 11 14 #include <linux/init.h> 12 15 #include <linux/module.h> ··· 17 14 #include <linux/slab.h> 18 15 #include <linux/workqueue.h> /* FIXME: is system_long_wq the best choice? */ 19 16 20 - #define TU_CUR_VERSION 0x01 17 + #define TU_VERSION_MAX_LENGTH 128 21 18 22 19 enum testunit_cmds { 23 20 TU_CMD_READ_BYTES = 1, /* save 0 for ABORT, RESET or similar */ 24 21 TU_CMD_SMBUS_HOST_NOTIFY, 25 22 TU_CMD_SMBUS_BLOCK_PROC_CALL, 23 + TU_CMD_GET_VERSION_WITH_REP_START, 24 + TU_CMD_SMBUS_ALERT_REQUEST, 26 25 TU_NUM_CMDS 27 26 }; 28 27 ··· 44 39 unsigned long flags; 45 40 u8 regs[TU_NUM_REGS]; 46 41 u8 reg_idx; 42 + u8 read_idx; 47 43 struct i2c_client *client; 48 44 struct delayed_work worker; 45 + struct gpio_desc *gpio; 46 + struct completion alert_done; 49 47 }; 50 48 51 - static void i2c_slave_testunit_work(struct work_struct *work) 49 + static char tu_version_info[] = "v" UTS_RELEASE "\n\0"; 50 + 51 + static int i2c_slave_testunit_smbalert_cb(struct i2c_client *client, 52 + enum i2c_slave_event event, u8 *val) 52 53 { 53 - struct testunit_data *tu = container_of(work, struct testunit_data, worker.work); 54 - struct i2c_msg msg; 55 - u8 msgbuf[256]; 56 - int ret = 0; 54 + struct testunit_data *tu = i2c_get_clientdata(client); 57 55 58 - msg.addr = I2C_CLIENT_END; 59 - msg.buf = msgbuf; 60 - 61 - switch (tu->regs[TU_REG_CMD]) { 62 - case TU_CMD_READ_BYTES: 63 - msg.addr = tu->regs[TU_REG_DATAL]; 64 - msg.flags = I2C_M_RD; 65 - msg.len = tu->regs[TU_REG_DATAH]; 56 + switch (event) { 57 + case I2C_SLAVE_READ_PROCESSED: 58 + gpiod_set_value(tu->gpio, 0); 59 + fallthrough; 60 + case I2C_SLAVE_READ_REQUESTED: 61 + *val = tu->regs[TU_REG_DATAL]; 66 62 break; 67 63 68 - case TU_CMD_SMBUS_HOST_NOTIFY: 69 - msg.addr = 0x08; 70 - msg.flags = 0; 71 - msg.len = 3; 72 - msgbuf[0] = tu->client->addr; 73 - msgbuf[1] = tu->regs[TU_REG_DATAL]; 74 - msgbuf[2] = tu->regs[TU_REG_DATAH]; 64 + case I2C_SLAVE_STOP: 65 + complete(&tu->alert_done); 75 66 break; 76 67 77 - default: 78 - break; 68 + case I2C_SLAVE_WRITE_REQUESTED: 69 + case I2C_SLAVE_WRITE_RECEIVED: 70 + return -EOPNOTSUPP; 79 71 } 80 72 81 - if (msg.addr != I2C_CLIENT_END) { 82 - ret = i2c_transfer(tu->client->adapter, &msg, 1); 83 - /* convert '0 msgs transferred' to errno */ 84 - ret = (ret == 0) ? -EIO : ret; 85 - } 86 - 87 - if (ret < 0) 88 - dev_err(&tu->client->dev, "CMD%02X failed (%d)\n", tu->regs[TU_REG_CMD], ret); 89 - 90 - clear_bit(TU_FLAG_IN_PROCESS, &tu->flags); 73 + return 0; 91 74 } 92 75 93 76 static int i2c_slave_testunit_slave_cb(struct i2c_client *client, ··· 84 91 struct testunit_data *tu = i2c_get_clientdata(client); 85 92 bool is_proc_call = tu->reg_idx == 3 && tu->regs[TU_REG_DATAL] == 1 && 86 93 tu->regs[TU_REG_CMD] == TU_CMD_SMBUS_BLOCK_PROC_CALL; 94 + bool is_get_version = tu->reg_idx == 3 && 95 + tu->regs[TU_REG_CMD] == TU_CMD_GET_VERSION_WITH_REP_START; 87 96 int ret = 0; 88 97 89 98 switch (event) { 99 + case I2C_SLAVE_WRITE_REQUESTED: 100 + if (test_bit(TU_FLAG_IN_PROCESS, &tu->flags)) 101 + return -EBUSY; 102 + 103 + memset(tu->regs, 0, TU_NUM_REGS); 104 + tu->reg_idx = 0; 105 + tu->read_idx = 0; 106 + break; 107 + 90 108 case I2C_SLAVE_WRITE_RECEIVED: 91 109 if (test_bit(TU_FLAG_IN_PROCESS, &tu->flags)) 92 110 return -EBUSY; ··· 131 127 tu->reg_idx = 0; 132 128 break; 133 129 134 - case I2C_SLAVE_WRITE_REQUESTED: 135 - if (test_bit(TU_FLAG_IN_PROCESS, &tu->flags)) 136 - return -EBUSY; 137 - 138 - memset(tu->regs, 0, TU_NUM_REGS); 139 - tu->reg_idx = 0; 140 - break; 141 - 142 130 case I2C_SLAVE_READ_PROCESSED: 143 - if (is_proc_call && tu->regs[TU_REG_DATAH]) 131 + /* Advance until we reach the NUL character */ 132 + if (is_get_version && tu_version_info[tu->read_idx] != 0) 133 + tu->read_idx++; 134 + else if (is_proc_call && tu->regs[TU_REG_DATAH]) 144 135 tu->regs[TU_REG_DATAH]--; 136 + 145 137 fallthrough; 146 138 147 139 case I2C_SLAVE_READ_REQUESTED: 148 - *val = is_proc_call ? tu->regs[TU_REG_DATAH] : TU_CUR_VERSION; 140 + if (is_get_version) 141 + *val = tu_version_info[tu->read_idx]; 142 + else if (is_proc_call) 143 + *val = tu->regs[TU_REG_DATAH]; 144 + else 145 + *val = test_bit(TU_FLAG_IN_PROCESS, &tu->flags) ? 146 + tu->regs[TU_REG_CMD] : 0; 149 147 break; 150 148 } 151 149 152 150 return ret; 151 + } 152 + 153 + static void i2c_slave_testunit_work(struct work_struct *work) 154 + { 155 + struct testunit_data *tu = container_of(work, struct testunit_data, worker.work); 156 + unsigned long time_left; 157 + struct i2c_msg msg; 158 + u8 msgbuf[256]; 159 + u16 orig_addr; 160 + int ret = 0; 161 + 162 + msg.addr = I2C_CLIENT_END; 163 + msg.buf = msgbuf; 164 + 165 + switch (tu->regs[TU_REG_CMD]) { 166 + case TU_CMD_READ_BYTES: 167 + msg.addr = tu->regs[TU_REG_DATAL]; 168 + msg.flags = I2C_M_RD; 169 + msg.len = tu->regs[TU_REG_DATAH]; 170 + break; 171 + 172 + case TU_CMD_SMBUS_HOST_NOTIFY: 173 + msg.addr = 0x08; 174 + msg.flags = 0; 175 + msg.len = 3; 176 + msgbuf[0] = tu->client->addr; 177 + msgbuf[1] = tu->regs[TU_REG_DATAL]; 178 + msgbuf[2] = tu->regs[TU_REG_DATAH]; 179 + break; 180 + 181 + case TU_CMD_SMBUS_ALERT_REQUEST: 182 + i2c_slave_unregister(tu->client); 183 + orig_addr = tu->client->addr; 184 + tu->client->addr = 0x0c; 185 + ret = i2c_slave_register(tu->client, i2c_slave_testunit_smbalert_cb); 186 + if (ret) 187 + goto out_smbalert; 188 + 189 + reinit_completion(&tu->alert_done); 190 + gpiod_set_value(tu->gpio, 1); 191 + time_left = wait_for_completion_timeout(&tu->alert_done, HZ); 192 + if (!time_left) 193 + ret = -ETIMEDOUT; 194 + 195 + i2c_slave_unregister(tu->client); 196 + out_smbalert: 197 + tu->client->addr = orig_addr; 198 + i2c_slave_register(tu->client, i2c_slave_testunit_slave_cb); 199 + break; 200 + 201 + default: 202 + break; 203 + } 204 + 205 + if (msg.addr != I2C_CLIENT_END) { 206 + ret = i2c_transfer(tu->client->adapter, &msg, 1); 207 + /* convert '0 msgs transferred' to errno */ 208 + ret = (ret == 0) ? -EIO : ret; 209 + } 210 + 211 + if (ret < 0) 212 + dev_err(&tu->client->dev, "CMD%02X failed (%d)\n", tu->regs[TU_REG_CMD], ret); 213 + 214 + clear_bit(TU_FLAG_IN_PROCESS, &tu->flags); 153 215 } 154 216 155 217 static int i2c_slave_testunit_probe(struct i2c_client *client) ··· 228 158 229 159 tu->client = client; 230 160 i2c_set_clientdata(client, tu); 161 + init_completion(&tu->alert_done); 231 162 INIT_DELAYED_WORK(&tu->worker, i2c_slave_testunit_work); 163 + 164 + tu->gpio = devm_gpiod_get_index_optional(&client->dev, NULL, 0, GPIOD_OUT_LOW); 165 + if (gpiod_cansleep(tu->gpio)) { 166 + dev_err(&client->dev, "GPIO access which may sleep is not allowed\n"); 167 + return -EDEADLK; 168 + } 169 + 170 + if (sizeof(tu_version_info) > TU_VERSION_MAX_LENGTH) 171 + tu_version_info[TU_VERSION_MAX_LENGTH - 1] = 0; 232 172 233 173 return i2c_slave_register(client, i2c_slave_testunit_slave_cb); 234 174 };
+16
drivers/i2c/muxes/Kconfig
··· 119 119 This driver can also be built as a module. If so, the module 120 120 will be called i2c-mux-mlxcpld. 121 121 122 + config I2C_MUX_MULE 123 + tristate "Theobroma Systems Mule I2C device multiplexer" 124 + depends on OF && SENSORS_AMC6821 125 + help 126 + Mule is an MCU that emulates a set of I2C devices, among which 127 + devices that are reachable through an I2C-mux. The devices on the mux 128 + can be selected by writing the appropriate device number to an I2C 129 + configuration register. 130 + 131 + If you say yes to this option, support will be included for a 132 + Theobroma Systems Mule I2C multiplexer. This driver provides access to 133 + I2C devices connected on this mux. 134 + 135 + This driver can also be built as a module. If so, the module 136 + will be called i2c-mux-mule. 137 + 122 138 endmenu
+1
drivers/i2c/muxes/Makefile
··· 10 10 obj-$(CONFIG_I2C_MUX_GPMUX) += i2c-mux-gpmux.o 11 11 obj-$(CONFIG_I2C_MUX_LTC4306) += i2c-mux-ltc4306.o 12 12 obj-$(CONFIG_I2C_MUX_MLXCPLD) += i2c-mux-mlxcpld.o 13 + obj-$(CONFIG_I2C_MUX_MULE) += i2c-mux-mule.o 13 14 obj-$(CONFIG_I2C_MUX_PCA9541) += i2c-mux-pca9541.o 14 15 obj-$(CONFIG_I2C_MUX_PCA954x) += i2c-mux-pca954x.o 15 16 obj-$(CONFIG_I2C_MUX_PINCTRL) += i2c-mux-pinctrl.o
+148
drivers/i2c/muxes/i2c-mux-mule.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Theobroma Systems Mule I2C device multiplexer 4 + * 5 + * Copyright (C) 2024 Theobroma Systems Design und Consulting GmbH 6 + */ 7 + 8 + #include <linux/i2c-mux.h> 9 + #include <linux/i2c.h> 10 + #include <linux/module.h> 11 + #include <linux/of.h> 12 + #include <linux/platform_device.h> 13 + #include <linux/property.h> 14 + #include <linux/regmap.h> 15 + 16 + #define MULE_I2C_MUX_CONFIG_REG 0xff 17 + #define MULE_I2C_MUX_DEFAULT_DEV 0x0 18 + 19 + struct mule_i2c_reg_mux { 20 + struct regmap *regmap; 21 + }; 22 + 23 + static int mule_i2c_mux_select(struct i2c_mux_core *muxc, u32 dev) 24 + { 25 + struct mule_i2c_reg_mux *mux = muxc->priv; 26 + 27 + return regmap_write(mux->regmap, MULE_I2C_MUX_CONFIG_REG, dev); 28 + } 29 + 30 + static int mule_i2c_mux_deselect(struct i2c_mux_core *muxc, u32 dev) 31 + { 32 + return mule_i2c_mux_select(muxc, MULE_I2C_MUX_DEFAULT_DEV); 33 + } 34 + 35 + static void mule_i2c_mux_remove(void *data) 36 + { 37 + struct i2c_mux_core *muxc = data; 38 + 39 + i2c_mux_del_adapters(muxc); 40 + 41 + mule_i2c_mux_deselect(muxc, MULE_I2C_MUX_DEFAULT_DEV); 42 + } 43 + 44 + static int mule_i2c_mux_probe(struct platform_device *pdev) 45 + { 46 + struct device *mux_dev = &pdev->dev; 47 + struct mule_i2c_reg_mux *priv; 48 + struct i2c_client *client; 49 + struct i2c_mux_core *muxc; 50 + struct device_node *dev; 51 + unsigned int readback; 52 + int ndev, ret; 53 + bool old_fw; 54 + 55 + /* Count devices on the mux */ 56 + ndev = of_get_child_count(mux_dev->of_node); 57 + dev_dbg(mux_dev, "%d devices on the mux\n", ndev); 58 + 59 + client = to_i2c_client(mux_dev->parent); 60 + 61 + muxc = i2c_mux_alloc(client->adapter, mux_dev, ndev, sizeof(*priv), 62 + I2C_MUX_LOCKED, mule_i2c_mux_select, mule_i2c_mux_deselect); 63 + if (!muxc) 64 + return -ENOMEM; 65 + 66 + priv = i2c_mux_priv(muxc); 67 + 68 + priv->regmap = dev_get_regmap(mux_dev->parent, NULL); 69 + if (IS_ERR(priv->regmap)) 70 + return dev_err_probe(mux_dev, PTR_ERR(priv->regmap), 71 + "No parent i2c register map\n"); 72 + 73 + platform_set_drvdata(pdev, muxc); 74 + 75 + /* 76 + * MULE_I2C_MUX_DEFAULT_DEV is guaranteed to exist on all old and new 77 + * mule fw. Mule fw without mux support will accept write ops to the 78 + * config register, but readback returns 0xff (register not updated). 79 + */ 80 + ret = mule_i2c_mux_select(muxc, MULE_I2C_MUX_DEFAULT_DEV); 81 + if (ret) 82 + return dev_err_probe(mux_dev, ret, 83 + "Failed to write config register\n"); 84 + 85 + ret = regmap_read(priv->regmap, MULE_I2C_MUX_CONFIG_REG, &readback); 86 + if (ret) 87 + return dev_err_probe(mux_dev, ret, 88 + "Failed to read config register\n"); 89 + 90 + old_fw = (readback != MULE_I2C_MUX_DEFAULT_DEV); 91 + 92 + ret = devm_add_action_or_reset(mux_dev, mule_i2c_mux_remove, muxc); 93 + if (ret) 94 + return dev_err_probe(mux_dev, ret, 95 + "Failed to register mux remove\n"); 96 + 97 + /* Create device adapters */ 98 + for_each_child_of_node(mux_dev->of_node, dev) { 99 + u32 reg; 100 + 101 + ret = of_property_read_u32(dev, "reg", &reg); 102 + if (ret) 103 + return dev_err_probe(mux_dev, ret, 104 + "No reg property found for %s\n", 105 + of_node_full_name(dev)); 106 + 107 + if (old_fw && reg != 0) { 108 + dev_warn(mux_dev, 109 + "Mux is not supported, please update Mule FW\n"); 110 + continue; 111 + } 112 + 113 + ret = mule_i2c_mux_select(muxc, reg); 114 + if (ret) { 115 + dev_warn(mux_dev, 116 + "Device %d not supported, please update Mule FW\n", reg); 117 + continue; 118 + } 119 + 120 + ret = i2c_mux_add_adapter(muxc, 0, reg); 121 + if (ret) 122 + return ret; 123 + } 124 + 125 + mule_i2c_mux_deselect(muxc, MULE_I2C_MUX_DEFAULT_DEV); 126 + 127 + return 0; 128 + } 129 + 130 + static const struct of_device_id mule_i2c_mux_of_match[] = { 131 + { .compatible = "tsd,mule-i2c-mux", }, 132 + {}, 133 + }; 134 + MODULE_DEVICE_TABLE(of, mule_i2c_mux_of_match); 135 + 136 + static struct platform_driver mule_i2c_mux_driver = { 137 + .driver = { 138 + .name = "mule-i2c-mux", 139 + .of_match_table = mule_i2c_mux_of_match, 140 + }, 141 + .probe = mule_i2c_mux_probe, 142 + }; 143 + 144 + module_platform_driver(mule_i2c_mux_driver); 145 + 146 + MODULE_AUTHOR("Farouk Bouabid <farouk.bouabid@cherry.de>"); 147 + MODULE_DESCRIPTION("I2C mux driver for Theobroma Systems Mule"); 148 + MODULE_LICENSE("GPL");
+1 -2
drivers/net/ethernet/wangxun/Kconfig
··· 41 41 tristate "Wangxun(R) 10GbE PCI Express adapters support" 42 42 depends on PCI 43 43 depends on COMMON_CLK 44 + depends on I2C_DESIGNWARE_PLATFORM 44 45 select MARVELL_10G_PHY 45 46 select REGMAP 46 - select I2C 47 - select I2C_DESIGNWARE_PLATFORM 48 47 select PHYLINK 49 48 select HWMON if TXGBE=y 50 49 select SFP
+3
include/linux/i2c.h
··· 761 761 struct regulator *bus_regulator; 762 762 763 763 struct dentry *debugfs; 764 + 765 + /* 7bit address space */ 766 + DECLARE_BITMAP(addrs_in_instantiation, 1 << 7); 764 767 }; 765 768 #define to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev) 766 769