summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2019-07-16 00:10:39 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2019-07-16 00:10:39 -0400
commit273cbf61c3ddee9574ef1f4959b9bc6db5b24271 (patch)
tree1eb8a54d416453ad7c6adbf57ab05dce2587a012
parent5fe7b600a116187e10317d83fb56922c4ef6b76d (diff)
parentcc6b9dfb2c5769afeb3335048173c730bdf8dbe1 (diff)
Merge branch 'i2c/for-5.3' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux
Pull i2c updates from Wolfram Sang: "New stuff from the I2C world: - in the core, getting irqs from ACPI is now similar to OF - new driver for MediaTek MT7621/7628/7688 SoCs - bcm2835, i801, and tegra drivers got some more attention - GPIO API cleanups - cleanups in the core headers - lots of usual driver updates" * 'i2c/for-5.3' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux: (74 commits) i2c: mt7621: Fix platform_no_drv_owner.cocci warnings i2c: cpm: remove casting dma_alloc dt-bindings: i2c: sun6i-p2wi: Fix the binding example dt-bindings: i2c: mv64xxx: Fix the example compatible i2c: i801: Documentation update i2c: i801: Add support for Intel Tiger Lake i2c: i801: Fix PCI ID sorting dt-bindings: i2c-stm32: document optional dmas i2c: i2c-stm32f7: Add I2C_SMBUS_I2C_BLOCK_DATA support i2c: core: Tidy up handling of init_irq i2c: core: Move ACPI gpio IRQ handling into i2c_acpi_get_irq i2c: core: Move ACPI IRQ handling to probe time i2c: acpi: Factor out getting the IRQ from ACPI i2c: acpi: Use available IRQ helper functions i2c: core: Allow whole core to use i2c_dev_irq_from_resources eeprom: at24: modify a comment referring to platform data dt-bindings: i2c: omap: Add new compatible for J721E SoCs dt-bindings: i2c: mv64xxx: Add YAML schemas dt-bindings: i2c: sun6i-p2wi: Add YAML schemas i2c: mt7621: Add MediaTek MT7621/7628/7688 I2C driver ...
-rw-r--r--Documentation/ABI/testing/sysfs-platform-i2c-demux-pinctrl4
-rw-r--r--Documentation/devicetree/bindings/i2c/allwinner,sun6i-a31-p2wi.yaml65
-rw-r--r--Documentation/devicetree/bindings/i2c/i2c-mt7621.txt25
-rw-r--r--Documentation/devicetree/bindings/i2c/i2c-mv64xxx.txt64
-rw-r--r--Documentation/devicetree/bindings/i2c/i2c-ocores.txt9
-rw-r--r--Documentation/devicetree/bindings/i2c/i2c-omap.txt1
-rw-r--r--Documentation/devicetree/bindings/i2c/i2c-stm32.txt2
-rw-r--r--Documentation/devicetree/bindings/i2c/i2c-sun6i-p2wi.txt41
-rw-r--r--Documentation/devicetree/bindings/i2c/marvell,mv64xxx-i2c.yaml124
-rw-r--r--Documentation/i2c/busses/i2c-i80120
-rw-r--r--MAINTAINERS7
-rw-r--r--arch/arm/include/asm/hardware/iop3xx.h2
-rw-r--r--arch/arm/mach-iop32x/em7210.c3
-rw-r--r--arch/arm/mach-iop32x/glantank.c3
-rw-r--r--arch/arm/mach-iop32x/iq31244.c3
-rw-r--r--arch/arm/mach-iop32x/iq80321.c3
-rw-r--r--arch/arm/mach-iop32x/n2100.c2
-rw-r--r--arch/arm/plat-iop/i2c.c24
-rw-r--r--drivers/gpio/gpio-iop.c1
-rw-r--r--drivers/i2c/busses/Kconfig13
-rw-r--r--drivers/i2c/busses/Makefile1
-rw-r--r--drivers/i2c/busses/i2c-bcm-iproc.c117
-rw-r--r--drivers/i2c/busses/i2c-bcm2835.c135
-rw-r--r--drivers/i2c/busses/i2c-cpm.c4
-rw-r--r--drivers/i2c/busses/i2c-fsi.c32
-rw-r--r--drivers/i2c/busses/i2c-i801.c206
-rw-r--r--drivers/i2c/busses/i2c-imx.c11
-rw-r--r--drivers/i2c/busses/i2c-iop3xx.c32
-rw-r--r--drivers/i2c/busses/i2c-iop3xx.h2
-rw-r--r--drivers/i2c/busses/i2c-mt7621.c356
-rw-r--r--drivers/i2c/busses/i2c-nvidia-gpu.c64
-rw-r--r--drivers/i2c/busses/i2c-ocores.c33
-rw-r--r--drivers/i2c/busses/i2c-qcom-geni.c17
-rw-r--r--drivers/i2c/busses/i2c-s3c2410.c47
-rw-r--r--drivers/i2c/busses/i2c-stm32f7.c32
-rw-r--r--drivers/i2c/busses/i2c-tegra.c136
-rw-r--r--drivers/i2c/i2c-core-acpi.c58
-rw-r--r--drivers/i2c/i2c-core-base.c20
-rw-r--r--drivers/i2c/i2c-core-of.c1
-rw-r--r--drivers/i2c/i2c-core.h9
-rw-r--r--drivers/i2c/i2c-mux.c4
-rw-r--r--drivers/i2c/muxes/i2c-arb-gpio-challenge.c79
-rw-r--r--drivers/i2c/muxes/i2c-mux-gpio.c116
-rw-r--r--drivers/i2c/muxes/i2c-mux-pinctrl.c5
-rw-r--r--drivers/misc/eeprom/at24.c86
-rw-r--r--drivers/platform/x86/dell-smo8800.c1
-rw-r--r--drivers/usb/typec/ucsi/ucsi.c10
-rw-r--r--drivers/usb/typec/ucsi/ucsi.h1
-rw-r--r--drivers/usb/typec/ucsi/ucsi_ccg.c118
-rw-r--r--include/linux/i2c.h93
-rw-r--r--include/linux/platform_data/i2c-mux-gpio.h7
51 files changed, 1605 insertions, 644 deletions
diff --git a/Documentation/ABI/testing/sysfs-platform-i2c-demux-pinctrl b/Documentation/ABI/testing/sysfs-platform-i2c-demux-pinctrl
index 3c3514815cd5..c394b808be19 100644
--- a/Documentation/ABI/testing/sysfs-platform-i2c-demux-pinctrl
+++ b/Documentation/ABI/testing/sysfs-platform-i2c-demux-pinctrl
@@ -1,7 +1,7 @@
1What: /sys/devices/platform/<i2c-demux-name>/available_masters 1What: /sys/devices/platform/<i2c-demux-name>/available_masters
2Date: January 2016 2Date: January 2016
3KernelVersion: 4.6 3KernelVersion: 4.6
4Contact: Wolfram Sang <wsa@the-dreams.de> 4Contact: Wolfram Sang <wsa+renesas@sang-engineering.com>
5Description: 5Description:
6 Reading the file will give you a list of masters which can be 6 Reading the file will give you a list of masters which can be
7 selected for a demultiplexed bus. The format is 7 selected for a demultiplexed bus. The format is
@@ -12,7 +12,7 @@ Description:
12What: /sys/devices/platform/<i2c-demux-name>/current_master 12What: /sys/devices/platform/<i2c-demux-name>/current_master
13Date: January 2016 13Date: January 2016
14KernelVersion: 4.6 14KernelVersion: 4.6
15Contact: Wolfram Sang <wsa@the-dreams.de> 15Contact: Wolfram Sang <wsa+renesas@sang-engineering.com>
16Description: 16Description:
17 This file selects/shows the active I2C master for a demultiplexed 17 This file selects/shows the active I2C master for a demultiplexed
18 bus. It uses the <index> value from the file 'available_masters'. 18 bus. It uses the <index> value from the file 'available_masters'.
diff --git a/Documentation/devicetree/bindings/i2c/allwinner,sun6i-a31-p2wi.yaml b/Documentation/devicetree/bindings/i2c/allwinner,sun6i-a31-p2wi.yaml
new file mode 100644
index 000000000000..f9d526b7da01
--- /dev/null
+++ b/Documentation/devicetree/bindings/i2c/allwinner,sun6i-a31-p2wi.yaml
@@ -0,0 +1,65 @@
1# SPDX-License-Identifier: GPL-2.0
2%YAML 1.2
3---
4$id: http://devicetree.org/schemas/i2c/allwinner,sun6i-a31-p2wi.yaml#
5$schema: http://devicetree.org/meta-schemas/core.yaml#
6
7title: Allwinner A31 P2WI (Push/Pull 2 Wires Interface) Device Tree Bindings
8
9maintainers:
10 - Chen-Yu Tsai <wens@csie.org>
11 - Maxime Ripard <maxime.ripard@bootlin.com>
12
13allOf:
14 - $ref: /schemas/i2c/i2c-controller.yaml#
15
16properties:
17 compatible:
18 const: allwinner,sun6i-a31-p2wi
19
20 reg:
21 maxItems: 1
22
23 interrupts:
24 maxItems: 1
25
26 clocks:
27 maxItems: 1
28
29 resets:
30 maxItems: 1
31
32 clock-frequency:
33 minimum: 1
34 maximum: 6000000
35
36required:
37 - compatible
38 - reg
39 - interrupts
40 - clocks
41 - resets
42
43# FIXME: We should set it, but it would report all the generic
44# properties as additional properties.
45# additionalProperties: false
46
47examples:
48 - |
49 i2c@1f03400 {
50 compatible = "allwinner,sun6i-a31-p2wi";
51 reg = <0x01f03400 0x400>;
52 interrupts = <0 39 4>;
53 clocks = <&apb0_gates 3>;
54 clock-frequency = <100000>;
55 resets = <&apb0_rst 3>;
56 #address-cells = <1>;
57 #size-cells = <0>;
58
59 axp221: pmic@68 {
60 compatible = "x-powers,axp221";
61 reg = <0x68>;
62 };
63 };
64
65...
diff --git a/Documentation/devicetree/bindings/i2c/i2c-mt7621.txt b/Documentation/devicetree/bindings/i2c/i2c-mt7621.txt
new file mode 100644
index 000000000000..bc36f0eb94cd
--- /dev/null
+++ b/Documentation/devicetree/bindings/i2c/i2c-mt7621.txt
@@ -0,0 +1,25 @@
1MediaTek MT7621/MT7628 I2C master controller
2
3Required properties:
4
5- compatible: Should be one of the following:
6 - "mediatek,mt7621-i2c": for MT7621/MT7628/MT7688 platforms
7- #address-cells: should be 1.
8- #size-cells: should be 0.
9- reg: Address and length of the register set for the device
10- resets: phandle to the reset controller asserting this device in
11 reset
12 See ../reset/reset.txt for details.
13
14Optional properties :
15
16Example:
17
18i2c: i2c@900 {
19 compatible = "mediatek,mt7621-i2c";
20 reg = <0x900 0x100>;
21 #address-cells = <1>;
22 #size-cells = <0>;
23 resets = <&rstctrl 16>;
24 reset-names = "i2c";
25};
diff --git a/Documentation/devicetree/bindings/i2c/i2c-mv64xxx.txt b/Documentation/devicetree/bindings/i2c/i2c-mv64xxx.txt
deleted file mode 100644
index 0ffe65a316ae..000000000000
--- a/Documentation/devicetree/bindings/i2c/i2c-mv64xxx.txt
+++ /dev/null
@@ -1,64 +0,0 @@
1
2* Marvell MV64XXX I2C controller
3
4Required properties :
5
6 - reg : Offset and length of the register set for the device
7 - compatible : Should be either:
8 - "allwinner,sun4i-a10-i2c"
9 - "allwinner,sun6i-a31-i2c"
10 - "marvell,mv64xxx-i2c"
11 - "marvell,mv78230-i2c"
12 - "marvell,mv78230-a0-i2c"
13 * Note: Only use "marvell,mv78230-a0-i2c" for a
14 very rare, initial version of the SoC which
15 had broken offload support. Linux
16 auto-detects this and sets it appropriately.
17 - interrupts : The interrupt number
18
19Optional properties :
20
21 - clock-frequency : Desired I2C bus clock frequency in Hz. If not set the
22default frequency is 100kHz
23
24 - resets : phandle to the parent reset controller. Mandatory
25 whenever you're using the "allwinner,sun6i-a31-i2c"
26 compatible.
27
28 - clocks: : pointers to the reference clocks for this device, the
29 first one is the one used for the clock on the i2c bus,
30 the second one is the clock used to acces the registers
31 of the controller
32
33 - clock-names : names of used clocks, mandatory if the second clock is
34 used, the name must be "core", and "reg" (the latter is
35 only for Armada 7K/8K).
36
37Examples:
38
39 i2c@11000 {
40 compatible = "marvell,mv64xxx-i2c";
41 reg = <0x11000 0x20>;
42 interrupts = <29>;
43 clock-frequency = <100000>;
44 };
45
46For the Armada XP:
47
48 i2c@11000 {
49 compatible = "marvell,mv78230-i2c", "marvell,mv64xxx-i2c";
50 reg = <0x11000 0x100>;
51 interrupts = <29>;
52 clock-frequency = <100000>;
53 };
54
55For the Armada 7040:
56
57 i2c@701000 {
58 compatible = "marvell,mv78230-i2c";
59 reg = <0x701000 0x20>;
60 interrupts = <29>;
61 clock-frequency = <100000>;
62 clock-names = "core", "reg";
63 clocks = <&core_clock>, <&reg_clock>;
64 };
diff --git a/Documentation/devicetree/bindings/i2c/i2c-ocores.txt b/Documentation/devicetree/bindings/i2c/i2c-ocores.txt
index 17bef9a34e50..6b25a80ae8d3 100644
--- a/Documentation/devicetree/bindings/i2c/i2c-ocores.txt
+++ b/Documentation/devicetree/bindings/i2c/i2c-ocores.txt
@@ -1,9 +1,13 @@
1Device tree configuration for i2c-ocores 1Device tree configuration for i2c-ocores
2 2
3Required properties: 3Required properties:
4- compatible : "opencores,i2c-ocores" or "aeroflexgaisler,i2cmst" 4- compatible : "opencores,i2c-ocores"
5 "aeroflexgaisler,i2cmst"
6 "sifive,fu540-c000-i2c", "sifive,i2c0"
7 For Opencore based I2C IP block reimplemented in
8 FU540-C000 SoC. Please refer to sifive-blocks-ip-versioning.txt
9 for additional details.
5- reg : bus address start and address range size of device 10- reg : bus address start and address range size of device
6- interrupts : interrupt number
7- clocks : handle to the controller clock; see the note below. 11- clocks : handle to the controller clock; see the note below.
8 Mutually exclusive with opencores,ip-clock-frequency 12 Mutually exclusive with opencores,ip-clock-frequency
9- opencores,ip-clock-frequency: frequency of the controller clock in Hz; 13- opencores,ip-clock-frequency: frequency of the controller clock in Hz;
@@ -12,6 +16,7 @@ Required properties:
12- #size-cells : should be <0> 16- #size-cells : should be <0>
13 17
14Optional properties: 18Optional properties:
19- interrupts : interrupt number.
15- clock-frequency : frequency of bus clock in Hz; see the note below. 20- clock-frequency : frequency of bus clock in Hz; see the note below.
16 Defaults to 100 KHz when the property is not specified 21 Defaults to 100 KHz when the property is not specified
17- reg-shift : device register offsets are shifted by this value 22- reg-shift : device register offsets are shifted by this value
diff --git a/Documentation/devicetree/bindings/i2c/i2c-omap.txt b/Documentation/devicetree/bindings/i2c/i2c-omap.txt
index 4b90ba9f31b7..a44573d7c118 100644
--- a/Documentation/devicetree/bindings/i2c/i2c-omap.txt
+++ b/Documentation/devicetree/bindings/i2c/i2c-omap.txt
@@ -7,6 +7,7 @@ Required properties :
7 "ti,omap3-i2c" for OMAP3 SoCs 7 "ti,omap3-i2c" for OMAP3 SoCs
8 "ti,omap4-i2c" for OMAP4+ SoCs 8 "ti,omap4-i2c" for OMAP4+ SoCs
9 "ti,am654-i2c", "ti,omap4-i2c" for AM654 SoCs 9 "ti,am654-i2c", "ti,omap4-i2c" for AM654 SoCs
10 "ti,j721e-i2c", "ti,omap4-i2c" for J721E SoCs
10- ti,hwmods : Must be "i2c<n>", n being the instance number (1-based) 11- ti,hwmods : Must be "i2c<n>", n being the instance number (1-based)
11- #address-cells = <1>; 12- #address-cells = <1>;
12- #size-cells = <0>; 13- #size-cells = <0>;
diff --git a/Documentation/devicetree/bindings/i2c/i2c-stm32.txt b/Documentation/devicetree/bindings/i2c/i2c-stm32.txt
index f334738f7a35..ce3df2fff6c8 100644
--- a/Documentation/devicetree/bindings/i2c/i2c-stm32.txt
+++ b/Documentation/devicetree/bindings/i2c/i2c-stm32.txt
@@ -21,6 +21,8 @@ Optional properties:
21 100000 and 400000. 21 100000 and 400000.
22 For STM32F7, STM32H7 and STM32MP1 SoCs, Standard-mode, Fast-mode and Fast-mode 22 For STM32F7, STM32H7 and STM32MP1 SoCs, Standard-mode, Fast-mode and Fast-mode
23 Plus are supported, possible values are 100000, 400000 and 1000000. 23 Plus are supported, possible values are 100000, 400000 and 1000000.
24- dmas: List of phandles to rx and tx DMA channels. Refer to stm32-dma.txt.
25- dma-names: List of dma names. Valid names are: "rx" and "tx".
24- i2c-scl-rising-time-ns: I2C SCL Rising time for the board (default: 25) 26- i2c-scl-rising-time-ns: I2C SCL Rising time for the board (default: 25)
25 For STM32F7, STM32H7 and STM32MP1 only. 27 For STM32F7, STM32H7 and STM32MP1 only.
26- i2c-scl-falling-time-ns: I2C SCL Falling time for the board (default: 10) 28- i2c-scl-falling-time-ns: I2C SCL Falling time for the board (default: 10)
diff --git a/Documentation/devicetree/bindings/i2c/i2c-sun6i-p2wi.txt b/Documentation/devicetree/bindings/i2c/i2c-sun6i-p2wi.txt
deleted file mode 100644
index 49df0053347a..000000000000
--- a/Documentation/devicetree/bindings/i2c/i2c-sun6i-p2wi.txt
+++ /dev/null
@@ -1,41 +0,0 @@
1
2* Allwinner P2WI (Push/Pull 2 Wire Interface) controller
3
4Required properties :
5
6 - reg : Offset and length of the register set for the device.
7 - compatible : Should one of the following:
8 - "allwinner,sun6i-a31-p2wi"
9 - interrupts : The interrupt line connected to the P2WI peripheral.
10 - clocks : The gate clk connected to the P2WI peripheral.
11 - resets : The reset line connected to the P2WI peripheral.
12
13Optional properties :
14
15 - clock-frequency : Desired P2WI bus clock frequency in Hz. If not set the
16default frequency is 100kHz
17
18A P2WI may contain one child node encoding a P2WI slave device.
19
20Slave device properties:
21 Required properties:
22 - reg : the I2C slave address used during the initialization
23 process to switch from I2C to P2WI mode
24
25Example:
26
27 p2wi@1f03400 {
28 compatible = "allwinner,sun6i-a31-p2wi";
29 reg = <0x01f03400 0x400>;
30 interrupts = <0 39 4>;
31 clocks = <&apb0_gates 3>;
32 clock-frequency = <6000000>;
33 resets = <&apb0_rst 3>;
34
35 axp221: pmic@68 {
36 compatible = "x-powers,axp221";
37 reg = <0x68>;
38
39 /* ... */
40 };
41 };
diff --git a/Documentation/devicetree/bindings/i2c/marvell,mv64xxx-i2c.yaml b/Documentation/devicetree/bindings/i2c/marvell,mv64xxx-i2c.yaml
new file mode 100644
index 000000000000..001f2b7abad0
--- /dev/null
+++ b/Documentation/devicetree/bindings/i2c/marvell,mv64xxx-i2c.yaml
@@ -0,0 +1,124 @@
1# SPDX-License-Identifier: GPL-2.0
2%YAML 1.2
3---
4$id: http://devicetree.org/schemas/i2c/marvell,mv64xxx-i2c.yaml#
5$schema: http://devicetree.org/meta-schemas/core.yaml#
6
7title: Marvell MV64XXX I2C Controller Device Tree Bindings
8
9maintainers:
10 - Gregory CLEMENT <gregory.clement@bootlin.com>
11
12properties:
13 compatible:
14 oneOf:
15 - const: allwinner,sun4i-a10-i2c
16 - items:
17 - const: allwinner,sun7i-a20-i2c
18 - const: allwinner,sun4i-a10-i2c
19 - const: allwinner,sun6i-a31-i2c
20 - items:
21 - const: allwinner,sun8i-a23-i2c
22 - const: allwinner,sun6i-a31-i2c
23 - items:
24 - const: allwinner,sun8i-a83t-i2c
25 - const: allwinner,sun6i-a31-i2c
26 - items:
27 - const: allwinner,sun50i-a64-i2c
28 - const: allwinner,sun6i-a31-i2c
29
30 - const: marvell,mv64xxx-i2c
31 - const: marvell,mv78230-i2c
32 - const: marvell,mv78230-a0-i2c
33
34 description:
35 Only use "marvell,mv78230-a0-i2c" for a very rare, initial
36 version of the SoC which had broken offload support. Linux
37 auto-detects this and sets it appropriately.
38
39 reg:
40 maxItems: 1
41
42 interrupts:
43 maxItems: 1
44
45 clocks:
46 minItems: 1
47 maxItems: 2
48 items:
49 - description: Reference clock for the I2C bus
50 - description: Bus clock (Only for Armada 7K/8K)
51
52 clock-names:
53 minItems: 1
54 maxItems: 2
55 items:
56 - const: core
57 - const: reg
58 description:
59 Mandatory if two clocks are used (only for Armada 7k and 8k).
60
61 resets:
62 maxItems: 1
63
64required:
65 - compatible
66 - reg
67 - interrupts
68
69allOf:
70 - $ref: /schemas/i2c/i2c-controller.yaml#
71 - if:
72 properties:
73 compatible:
74 contains:
75 enum:
76 - allwinner,sun4i-a10-i2c
77 - allwinner,sun6i-a31-i2c
78
79 then:
80 required:
81 - clocks
82
83 - if:
84 properties:
85 compatible:
86 contains:
87 const: allwinner,sun6i-a31-i2c
88
89 then:
90 required:
91 - resets
92
93# FIXME: We should set it, but it would report all the generic
94# properties as additional properties.
95# additionalProperties: false
96
97examples:
98 - |
99 i2c@11000 {
100 compatible = "marvell,mv64xxx-i2c";
101 reg = <0x11000 0x20>;
102 interrupts = <29>;
103 clock-frequency = <100000>;
104 };
105
106 - |
107 i2c@11000 {
108 compatible = "marvell,mv78230-i2c";
109 reg = <0x11000 0x100>;
110 interrupts = <29>;
111 clock-frequency = <100000>;
112 };
113
114 - |
115 i2c@701000 {
116 compatible = "marvell,mv78230-i2c";
117 reg = <0x701000 0x20>;
118 interrupts = <29>;
119 clock-frequency = <100000>;
120 clock-names = "core", "reg";
121 clocks = <&core_clock>, <&reg_clock>;
122 };
123
124...
diff --git a/Documentation/i2c/busses/i2c-i801 b/Documentation/i2c/busses/i2c-i801
index ee9984f35868..f426c13c63a9 100644
--- a/Documentation/i2c/busses/i2c-i801
+++ b/Documentation/i2c/busses/i2c-i801
@@ -37,6 +37,8 @@ Supported adapters:
37 * Intel Cedar Fork (PCH) 37 * Intel Cedar Fork (PCH)
38 * Intel Ice Lake (PCH) 38 * Intel Ice Lake (PCH)
39 * Intel Comet Lake (PCH) 39 * Intel Comet Lake (PCH)
40 * Intel Elkhart Lake (PCH)
41 * Intel Tiger Lake (PCH)
40 Datasheets: Publicly available at the Intel website 42 Datasheets: Publicly available at the Intel website
41 43
42On Intel Patsburg and later chipsets, both the normal host SMBus controller 44On Intel Patsburg and later chipsets, both the normal host SMBus controller
@@ -58,6 +60,7 @@ question doesn't work as intended for whatever reason. Bit values:
58 0x02 disable the block buffer 60 0x02 disable the block buffer
59 0x08 disable the I2C block read functionality 61 0x08 disable the I2C block read functionality
60 0x10 don't use interrupts 62 0x10 don't use interrupts
63 0x20 disable SMBus Host Notify
61 64
62 65
63Description 66Description
@@ -88,7 +91,7 @@ SMBus controller.
88Process Call Support 91Process Call Support
89-------------------- 92--------------------
90 93
91Not supported. 94Block process call is supported on the 82801EB (ICH5) and later chips.
92 95
93 96
94I2C Block Read Support 97I2C Block Read Support
@@ -118,16 +121,15 @@ BIOS to enable it, it means it has been hidden by the BIOS code. Asus is
118well known for first doing this on their P4B motherboard, and many other 121well known for first doing this on their P4B motherboard, and many other
119boards after that. Some vendor machines are affected as well. 122boards after that. Some vendor machines are affected as well.
120 123
121The first thing to try is the "i2c_ec" ACPI driver. It could be that the 124The first thing to try is the "i2c-scmi" ACPI driver. It could be that the
122SMBus was hidden on purpose because it'll be driven by ACPI. If the 125SMBus was hidden on purpose because it'll be driven by ACPI. If the
123i2c_ec driver works for you, just forget about the i2c-i801 driver and 126i2c-scmi driver works for you, just forget about the i2c-i801 driver and
124don't try to unhide the ICH SMBus. Even if i2c_ec doesn't work, you 127don't try to unhide the ICH SMBus. Even if i2c-scmi doesn't work, you
125better make sure that the SMBus isn't used by the ACPI code. Try loading 128better make sure that the SMBus isn't used by the ACPI code. Try loading
126the "fan" and "thermal" drivers, and check in /proc/acpi/fan and 129the "fan" and "thermal" drivers, and check in /sys/class/thermal. If you
127/proc/acpi/thermal_zone. If you find anything there, it's likely that 130find a thermal zone with type "acpitz", it's likely that the ACPI is
128the ACPI is accessing the SMBus and it's safer not to unhide it. Only 131accessing the SMBus and it's safer not to unhide it. Only once you are
129once you are certain that ACPI isn't using the SMBus, you can attempt 132certain that ACPI isn't using the SMBus, you can attempt to unhide it.
130to unhide it.
131 133
132In order to unhide the SMBus, we need to change the value of a PCI 134In order to unhide the SMBus, we need to change the value of a PCI
133register before the kernel enumerates the PCI devices. This is done in 135register before the kernel enumerates the PCI devices. This is done in
diff --git a/MAINTAINERS b/MAINTAINERS
index 91eed595dc9a..4aee3a1de331 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -10123,6 +10123,13 @@ L: linux-wireless@vger.kernel.org
10123S: Maintained 10123S: Maintained
10124F: drivers/net/wireless/mediatek/mt7601u/ 10124F: drivers/net/wireless/mediatek/mt7601u/
10125 10125
10126MEDIATEK MT7621/28/88 I2C DRIVER
10127M: Stefan Roese <sr@denx.de>
10128L: linux-i2c@vger.kernel.org
10129S: Maintained
10130F: drivers/i2c/busses/i2c-mt7621.c
10131F: Documentation/devicetree/bindings/i2c/i2c-mt7621.txt
10132
10126MEDIATEK NAND CONTROLLER DRIVER 10133MEDIATEK NAND CONTROLLER DRIVER
10127M: Xiaolei Li <xiaolei.li@mediatek.com> 10134M: Xiaolei Li <xiaolei.li@mediatek.com>
10128L: linux-mtd@lists.infradead.org 10135L: linux-mtd@lists.infradead.org
diff --git a/arch/arm/include/asm/hardware/iop3xx.h b/arch/arm/include/asm/hardware/iop3xx.h
index 64714c869f9f..3cb6f22f510b 100644
--- a/arch/arm/include/asm/hardware/iop3xx.h
+++ b/arch/arm/include/asm/hardware/iop3xx.h
@@ -302,6 +302,8 @@ extern struct platform_device iop3xx_dma_1_channel;
302extern struct platform_device iop3xx_aau_channel; 302extern struct platform_device iop3xx_aau_channel;
303extern struct platform_device iop3xx_i2c0_device; 303extern struct platform_device iop3xx_i2c0_device;
304extern struct platform_device iop3xx_i2c1_device; 304extern struct platform_device iop3xx_i2c1_device;
305extern struct gpiod_lookup_table iop3xx_i2c0_gpio_lookup;
306extern struct gpiod_lookup_table iop3xx_i2c1_gpio_lookup;
305 307
306#endif 308#endif
307 309
diff --git a/arch/arm/mach-iop32x/em7210.c b/arch/arm/mach-iop32x/em7210.c
index 493de4fd8b2e..61a1e593f9ec 100644
--- a/arch/arm/mach-iop32x/em7210.c
+++ b/arch/arm/mach-iop32x/em7210.c
@@ -20,6 +20,7 @@
20#include <linux/platform_device.h> 20#include <linux/platform_device.h>
21#include <linux/i2c.h> 21#include <linux/i2c.h>
22#include <linux/gpio.h> 22#include <linux/gpio.h>
23#include <linux/gpio/machine.h>
23#include <mach/hardware.h> 24#include <mach/hardware.h>
24#include <linux/io.h> 25#include <linux/io.h>
25#include <linux/irq.h> 26#include <linux/irq.h>
@@ -207,6 +208,8 @@ static void __init em7210_init_machine(void)
207{ 208{
208 register_iop32x_gpio(); 209 register_iop32x_gpio();
209 platform_device_register(&em7210_serial_device); 210 platform_device_register(&em7210_serial_device);
211 gpiod_add_lookup_table(&iop3xx_i2c0_gpio_lookup);
212 gpiod_add_lookup_table(&iop3xx_i2c1_gpio_lookup);
210 platform_device_register(&iop3xx_i2c0_device); 213 platform_device_register(&iop3xx_i2c0_device);
211 platform_device_register(&iop3xx_i2c1_device); 214 platform_device_register(&iop3xx_i2c1_device);
212 platform_device_register(&em7210_flash_device); 215 platform_device_register(&em7210_flash_device);
diff --git a/arch/arm/mach-iop32x/glantank.c b/arch/arm/mach-iop32x/glantank.c
index 84cdb4587b34..5a45d616d9ac 100644
--- a/arch/arm/mach-iop32x/glantank.c
+++ b/arch/arm/mach-iop32x/glantank.c
@@ -21,6 +21,7 @@
21#include <linux/i2c.h> 21#include <linux/i2c.h>
22#include <linux/platform_device.h> 22#include <linux/platform_device.h>
23#include <linux/io.h> 23#include <linux/io.h>
24#include <linux/gpio/machine.h>
24#include <mach/hardware.h> 25#include <mach/hardware.h>
25#include <asm/irq.h> 26#include <asm/irq.h>
26#include <asm/mach/arch.h> 27#include <asm/mach/arch.h>
@@ -185,6 +186,8 @@ static void glantank_power_off(void)
185static void __init glantank_init_machine(void) 186static void __init glantank_init_machine(void)
186{ 187{
187 register_iop32x_gpio(); 188 register_iop32x_gpio();
189 gpiod_add_lookup_table(&iop3xx_i2c0_gpio_lookup);
190 gpiod_add_lookup_table(&iop3xx_i2c1_gpio_lookup);
188 platform_device_register(&iop3xx_i2c0_device); 191 platform_device_register(&iop3xx_i2c0_device);
189 platform_device_register(&iop3xx_i2c1_device); 192 platform_device_register(&iop3xx_i2c1_device);
190 platform_device_register(&glantank_flash_device); 193 platform_device_register(&glantank_flash_device);
diff --git a/arch/arm/mach-iop32x/iq31244.c b/arch/arm/mach-iop32x/iq31244.c
index b177e3900616..8755aa87e591 100644
--- a/arch/arm/mach-iop32x/iq31244.c
+++ b/arch/arm/mach-iop32x/iq31244.c
@@ -22,6 +22,7 @@
22#include <linux/mtd/physmap.h> 22#include <linux/mtd/physmap.h>
23#include <linux/platform_device.h> 23#include <linux/platform_device.h>
24#include <linux/io.h> 24#include <linux/io.h>
25#include <linux/gpio/machine.h>
25#include <mach/hardware.h> 26#include <mach/hardware.h>
26#include <asm/cputype.h> 27#include <asm/cputype.h>
27#include <asm/irq.h> 28#include <asm/irq.h>
@@ -281,6 +282,8 @@ void ep80219_power_off(void)
281static void __init iq31244_init_machine(void) 282static void __init iq31244_init_machine(void)
282{ 283{
283 register_iop32x_gpio(); 284 register_iop32x_gpio();
285 gpiod_add_lookup_table(&iop3xx_i2c0_gpio_lookup);
286 gpiod_add_lookup_table(&iop3xx_i2c1_gpio_lookup);
284 platform_device_register(&iop3xx_i2c0_device); 287 platform_device_register(&iop3xx_i2c0_device);
285 platform_device_register(&iop3xx_i2c1_device); 288 platform_device_register(&iop3xx_i2c1_device);
286 platform_device_register(&iq31244_flash_device); 289 platform_device_register(&iq31244_flash_device);
diff --git a/arch/arm/mach-iop32x/iq80321.c b/arch/arm/mach-iop32x/iq80321.c
index 815b9f070007..e12699d1c540 100644
--- a/arch/arm/mach-iop32x/iq80321.c
+++ b/arch/arm/mach-iop32x/iq80321.c
@@ -19,6 +19,7 @@
19#include <linux/mtd/physmap.h> 19#include <linux/mtd/physmap.h>
20#include <linux/platform_device.h> 20#include <linux/platform_device.h>
21#include <linux/io.h> 21#include <linux/io.h>
22#include <linux/gpio/machine.h>
22#include <mach/hardware.h> 23#include <mach/hardware.h>
23#include <asm/irq.h> 24#include <asm/irq.h>
24#include <asm/mach/arch.h> 25#include <asm/mach/arch.h>
@@ -168,6 +169,8 @@ static struct platform_device iq80321_serial_device = {
168static void __init iq80321_init_machine(void) 169static void __init iq80321_init_machine(void)
169{ 170{
170 register_iop32x_gpio(); 171 register_iop32x_gpio();
172 gpiod_add_lookup_table(&iop3xx_i2c0_gpio_lookup);
173 gpiod_add_lookup_table(&iop3xx_i2c1_gpio_lookup);
171 platform_device_register(&iop3xx_i2c0_device); 174 platform_device_register(&iop3xx_i2c0_device);
172 platform_device_register(&iop3xx_i2c1_device); 175 platform_device_register(&iop3xx_i2c1_device);
173 platform_device_register(&iq80321_flash_device); 176 platform_device_register(&iq80321_flash_device);
diff --git a/arch/arm/mach-iop32x/n2100.c b/arch/arm/mach-iop32x/n2100.c
index 1948180594f4..26d76b377e79 100644
--- a/arch/arm/mach-iop32x/n2100.c
+++ b/arch/arm/mach-iop32x/n2100.c
@@ -27,6 +27,7 @@
27#include <linux/reboot.h> 27#include <linux/reboot.h>
28#include <linux/io.h> 28#include <linux/io.h>
29#include <linux/gpio.h> 29#include <linux/gpio.h>
30#include <linux/gpio/machine.h>
30#include <mach/hardware.h> 31#include <mach/hardware.h>
31#include <asm/irq.h> 32#include <asm/irq.h>
32#include <asm/mach/arch.h> 33#include <asm/mach/arch.h>
@@ -341,6 +342,7 @@ device_initcall(n2100_request_gpios);
341static void __init n2100_init_machine(void) 342static void __init n2100_init_machine(void)
342{ 343{
343 register_iop32x_gpio(); 344 register_iop32x_gpio();
345 gpiod_add_lookup_table(&iop3xx_i2c0_gpio_lookup);
344 platform_device_register(&iop3xx_i2c0_device); 346 platform_device_register(&iop3xx_i2c0_device);
345 platform_device_register(&n2100_flash_device); 347 platform_device_register(&n2100_flash_device);
346 platform_device_register(&n2100_serial_device); 348 platform_device_register(&n2100_serial_device);
diff --git a/arch/arm/plat-iop/i2c.c b/arch/arm/plat-iop/i2c.c
index 7a79213db3e1..dfbd7c332866 100644
--- a/arch/arm/plat-iop/i2c.c
+++ b/arch/arm/plat-iop/i2c.c
@@ -16,6 +16,7 @@
16#include <linux/tty.h> 16#include <linux/tty.h>
17#include <linux/serial_core.h> 17#include <linux/serial_core.h>
18#include <linux/io.h> 18#include <linux/io.h>
19#include <linux/gpio/machine.h>
19#include <asm/pgtable.h> 20#include <asm/pgtable.h>
20#include <asm/page.h> 21#include <asm/page.h>
21#include <asm/mach/map.h> 22#include <asm/mach/map.h>
@@ -34,6 +35,29 @@
34#define IRQ_IOP3XX_I2C_1 IRQ_IOP33X_I2C_1 35#define IRQ_IOP3XX_I2C_1 IRQ_IOP33X_I2C_1
35#endif 36#endif
36 37
38/*
39 * Each of the I2C busses have corresponding GPIO lines, and the driver
40 * need to access these directly to drive the bus low at times.
41 */
42
43struct gpiod_lookup_table iop3xx_i2c0_gpio_lookup = {
44 .dev_id = "IOP3xx-I2C.0",
45 .table = {
46 GPIO_LOOKUP("gpio-iop", 7, "scl", GPIO_ACTIVE_HIGH),
47 GPIO_LOOKUP("gpio-iop", 6, "sda", GPIO_ACTIVE_HIGH),
48 { }
49 },
50};
51
52struct gpiod_lookup_table iop3xx_i2c1_gpio_lookup = {
53 .dev_id = "IOP3xx-I2C.1",
54 .table = {
55 GPIO_LOOKUP("gpio-iop", 5, "scl", GPIO_ACTIVE_HIGH),
56 GPIO_LOOKUP("gpio-iop", 4, "sda", GPIO_ACTIVE_HIGH),
57 { }
58 },
59};
60
37static struct resource iop3xx_i2c0_resources[] = { 61static struct resource iop3xx_i2c0_resources[] = {
38 [0] = { 62 [0] = {
39 .start = 0xfffff680, 63 .start = 0xfffff680,
diff --git a/drivers/gpio/gpio-iop.c b/drivers/gpio/gpio-iop.c
index e355c5961eb9..7390b5ca09e3 100644
--- a/drivers/gpio/gpio-iop.c
+++ b/drivers/gpio/gpio-iop.c
@@ -36,6 +36,7 @@ static int iop3xx_gpio_probe(struct platform_device *pdev)
36 36
37 gc->base = 0; 37 gc->base = 0;
38 gc->owner = THIS_MODULE; 38 gc->owner = THIS_MODULE;
39 gc->label = "gpio-iop";
39 40
40 return devm_gpiochip_add_data(&pdev->dev, gc, NULL); 41 return devm_gpiochip_add_data(&pdev->dev, gc, NULL);
41} 42}
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index ee5dfb5aee2a..09367fc014c3 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -143,6 +143,8 @@ config I2C_I801
143 Cedar Fork (PCH) 143 Cedar Fork (PCH)
144 Ice Lake (PCH) 144 Ice Lake (PCH)
145 Comet Lake (PCH) 145 Comet Lake (PCH)
146 Elkhart Lake (PCH)
147 Tiger Lake (PCH)
146 148
147 This driver can also be built as a module. If so, the module 149 This driver can also be built as a module. If so, the module
148 will be called i2c-i801. 150 will be called i2c-i801.
@@ -436,7 +438,7 @@ config I2C_AXXIA
436 438
437config I2C_BCM2835 439config I2C_BCM2835
438 tristate "Broadcom BCM2835 I2C controller" 440 tristate "Broadcom BCM2835 I2C controller"
439 depends on ARCH_BCM2835 441 depends on ARCH_BCM2835 || ARCH_BRCMSTB
440 help 442 help
441 If you say yes to this option, support will be included for the 443 If you say yes to this option, support will be included for the
442 BCM2835 I2C controller. 444 BCM2835 I2C controller.
@@ -692,7 +694,7 @@ config I2C_IOP3XX
692 694
693config I2C_JZ4780 695config I2C_JZ4780
694 tristate "JZ4780 I2C controller interface support" 696 tristate "JZ4780 I2C controller interface support"
695 depends on MACH_JZ4780 || COMPILE_TEST 697 depends on MIPS || COMPILE_TEST
696 help 698 help
697 If you say yes to this option, support will be included for the 699 If you say yes to this option, support will be included for the
698 Ingenic JZ4780 I2C controller. 700 Ingenic JZ4780 I2C controller.
@@ -746,6 +748,13 @@ config I2C_MT65XX
746 If you want to use MediaTek(R) I2C interface, say Y or M here. 748 If you want to use MediaTek(R) I2C interface, say Y or M here.
747 If unsure, say N. 749 If unsure, say N.
748 750
751config I2C_MT7621
752 tristate "MT7621/MT7628 I2C Controller"
753 depends on (RALINK && (SOC_MT7620 || SOC_MT7621)) || COMPILE_TEST
754 help
755 Say Y here to include support for I2C controller in the
756 MediaTek MT7621/MT7628 SoCs.
757
749config I2C_MV64XXX 758config I2C_MV64XXX
750 tristate "Marvell mv64xxx I2C Controller" 759 tristate "Marvell mv64xxx I2C Controller"
751 depends on MV64X60 || PLAT_ORION || ARCH_SUNXI || ARCH_MVEBU 760 depends on MV64X60 || PLAT_ORION || ARCH_SUNXI || ARCH_MVEBU
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
index a3245231b0b7..80c23895eaaf 100644
--- a/drivers/i2c/busses/Makefile
+++ b/drivers/i2c/busses/Makefile
@@ -77,6 +77,7 @@ obj-$(CONFIG_I2C_LPC2K) += i2c-lpc2k.o
77obj-$(CONFIG_I2C_MESON) += i2c-meson.o 77obj-$(CONFIG_I2C_MESON) += i2c-meson.o
78obj-$(CONFIG_I2C_MPC) += i2c-mpc.o 78obj-$(CONFIG_I2C_MPC) += i2c-mpc.o
79obj-$(CONFIG_I2C_MT65XX) += i2c-mt65xx.o 79obj-$(CONFIG_I2C_MT65XX) += i2c-mt65xx.o
80obj-$(CONFIG_I2C_MT7621) += i2c-mt7621.o
80obj-$(CONFIG_I2C_MV64XXX) += i2c-mv64xxx.o 81obj-$(CONFIG_I2C_MV64XXX) += i2c-mv64xxx.o
81obj-$(CONFIG_I2C_MXS) += i2c-mxs.o 82obj-$(CONFIG_I2C_MXS) += i2c-mxs.o
82obj-$(CONFIG_I2C_NOMADIK) += i2c-nomadik.o 83obj-$(CONFIG_I2C_NOMADIK) += i2c-nomadik.o
diff --git a/drivers/i2c/busses/i2c-bcm-iproc.c b/drivers/i2c/busses/i2c-bcm-iproc.c
index a845b8decac8..2c7f145a036e 100644
--- a/drivers/i2c/busses/i2c-bcm-iproc.c
+++ b/drivers/i2c/busses/i2c-bcm-iproc.c
@@ -165,12 +165,6 @@ enum i2c_slave_read_status {
165 I2C_SLAVE_RX_END, 165 I2C_SLAVE_RX_END,
166}; 166};
167 167
168enum i2c_slave_xfer_dir {
169 I2C_SLAVE_DIR_READ = 0,
170 I2C_SLAVE_DIR_WRITE,
171 I2C_SLAVE_DIR_NONE,
172};
173
174enum bus_speed_index { 168enum bus_speed_index {
175 I2C_SPD_100K = 0, 169 I2C_SPD_100K = 0,
176 I2C_SPD_400K, 170 I2C_SPD_400K,
@@ -203,7 +197,6 @@ struct bcm_iproc_i2c_dev {
203 struct i2c_msg *msg; 197 struct i2c_msg *msg;
204 198
205 struct i2c_client *slave; 199 struct i2c_client *slave;
206 enum i2c_slave_xfer_dir xfer_dir;
207 200
208 /* bytes that have been transferred */ 201 /* bytes that have been transferred */
209 unsigned int tx_bytes; 202 unsigned int tx_bytes;
@@ -219,7 +212,8 @@ struct bcm_iproc_i2c_dev {
219 | BIT(IS_M_RX_THLD_SHIFT)) 212 | BIT(IS_M_RX_THLD_SHIFT))
220 213
221#define ISR_MASK_SLAVE (BIT(IS_S_START_BUSY_SHIFT)\ 214#define ISR_MASK_SLAVE (BIT(IS_S_START_BUSY_SHIFT)\
222 | BIT(IS_S_RX_EVENT_SHIFT) | BIT(IS_S_RD_EVENT_SHIFT)) 215 | BIT(IS_S_RX_EVENT_SHIFT) | BIT(IS_S_RD_EVENT_SHIFT)\
216 | BIT(IS_S_TX_UNDERRUN_SHIFT))
223 217
224static int bcm_iproc_i2c_reg_slave(struct i2c_client *slave); 218static int bcm_iproc_i2c_reg_slave(struct i2c_client *slave);
225static int bcm_iproc_i2c_unreg_slave(struct i2c_client *slave); 219static int bcm_iproc_i2c_unreg_slave(struct i2c_client *slave);
@@ -297,15 +291,11 @@ static void bcm_iproc_i2c_slave_init(
297 /* clear all pending slave interrupts */ 291 /* clear all pending slave interrupts */
298 iproc_i2c_wr_reg(iproc_i2c, IS_OFFSET, ISR_MASK_SLAVE); 292 iproc_i2c_wr_reg(iproc_i2c, IS_OFFSET, ISR_MASK_SLAVE);
299 293
300 /* Enable interrupt register for any READ event */
301 val = BIT(IE_S_RD_EVENT_SHIFT);
302 /* Enable interrupt register to indicate a valid byte in receive fifo */ 294 /* Enable interrupt register to indicate a valid byte in receive fifo */
303 val |= BIT(IE_S_RX_EVENT_SHIFT); 295 val = BIT(IE_S_RX_EVENT_SHIFT);
304 /* Enable interrupt register for the Slave BUSY command */ 296 /* Enable interrupt register for the Slave BUSY command */
305 val |= BIT(IE_S_START_BUSY_SHIFT); 297 val |= BIT(IE_S_START_BUSY_SHIFT);
306 iproc_i2c_wr_reg(iproc_i2c, IE_OFFSET, val); 298 iproc_i2c_wr_reg(iproc_i2c, IE_OFFSET, val);
307
308 iproc_i2c->xfer_dir = I2C_SLAVE_DIR_NONE;
309} 299}
310 300
311static void bcm_iproc_i2c_check_slave_status( 301static void bcm_iproc_i2c_check_slave_status(
@@ -314,8 +304,11 @@ static void bcm_iproc_i2c_check_slave_status(
314 u32 val; 304 u32 val;
315 305
316 val = iproc_i2c_rd_reg(iproc_i2c, S_CMD_OFFSET); 306 val = iproc_i2c_rd_reg(iproc_i2c, S_CMD_OFFSET);
317 val = (val >> S_CMD_STATUS_SHIFT) & S_CMD_STATUS_MASK; 307 /* status is valid only when START_BUSY is cleared after it was set */
308 if (val & BIT(S_CMD_START_BUSY_SHIFT))
309 return;
318 310
311 val = (val >> S_CMD_STATUS_SHIFT) & S_CMD_STATUS_MASK;
319 if (val == S_CMD_STATUS_TIMEOUT) { 312 if (val == S_CMD_STATUS_TIMEOUT) {
320 dev_err(iproc_i2c->device, "slave random stretch time timeout\n"); 313 dev_err(iproc_i2c->device, "slave random stretch time timeout\n");
321 314
@@ -327,70 +320,66 @@ static void bcm_iproc_i2c_check_slave_status(
327} 320}
328 321
329static bool bcm_iproc_i2c_slave_isr(struct bcm_iproc_i2c_dev *iproc_i2c, 322static bool bcm_iproc_i2c_slave_isr(struct bcm_iproc_i2c_dev *iproc_i2c,
330 u32 status) 323 u32 status)
331{ 324{
332 u8 value;
333 u32 val; 325 u32 val;
334 u32 rd_status; 326 u8 value, rx_status;
335 u32 tmp;
336 327
337 /* Start of transaction. check address and populate the direction */ 328 /* Slave RX byte receive */
338 if (iproc_i2c->xfer_dir == I2C_SLAVE_DIR_NONE) { 329 if (status & BIT(IS_S_RX_EVENT_SHIFT)) {
339 tmp = iproc_i2c_rd_reg(iproc_i2c, S_RX_OFFSET); 330 val = iproc_i2c_rd_reg(iproc_i2c, S_RX_OFFSET);
340 rd_status = (tmp >> S_RX_STATUS_SHIFT) & S_RX_STATUS_MASK; 331 rx_status = (val >> S_RX_STATUS_SHIFT) & S_RX_STATUS_MASK;
341 /* This condition checks whether the request is a new request */ 332 if (rx_status == I2C_SLAVE_RX_START) {
342 if (((rd_status == I2C_SLAVE_RX_START) && 333 /* Start of SMBUS for Master write */
343 (status & BIT(IS_S_RX_EVENT_SHIFT))) || 334 i2c_slave_event(iproc_i2c->slave,
344 ((rd_status == I2C_SLAVE_RX_END) &&
345 (status & BIT(IS_S_RD_EVENT_SHIFT)))) {
346
347 /* Last bit is W/R bit.
348 * If 1 then its a read request(by master).
349 */
350 iproc_i2c->xfer_dir = tmp & SLAVE_READ_WRITE_BIT_MASK;
351 if (iproc_i2c->xfer_dir == I2C_SLAVE_DIR_WRITE)
352 i2c_slave_event(iproc_i2c->slave,
353 I2C_SLAVE_READ_REQUESTED, &value);
354 else
355 i2c_slave_event(iproc_i2c->slave,
356 I2C_SLAVE_WRITE_REQUESTED, &value); 335 I2C_SLAVE_WRITE_REQUESTED, &value);
357 }
358 }
359 336
360 /* read request from master */ 337 val = iproc_i2c_rd_reg(iproc_i2c, S_RX_OFFSET);
361 if ((status & BIT(IS_S_RD_EVENT_SHIFT)) && 338 value = (u8)((val >> S_RX_DATA_SHIFT) & S_RX_DATA_MASK);
362 (iproc_i2c->xfer_dir == I2C_SLAVE_DIR_WRITE)) { 339 i2c_slave_event(iproc_i2c->slave,
363 i2c_slave_event(iproc_i2c->slave, 340 I2C_SLAVE_WRITE_RECEIVED, &value);
364 I2C_SLAVE_READ_PROCESSED, &value); 341 } else if (status & BIT(IS_S_RD_EVENT_SHIFT)) {
365 iproc_i2c_wr_reg(iproc_i2c, S_TX_OFFSET, value); 342 /* Start of SMBUS for Master Read */
343 i2c_slave_event(iproc_i2c->slave,
344 I2C_SLAVE_READ_REQUESTED, &value);
345 iproc_i2c_wr_reg(iproc_i2c, S_TX_OFFSET, value);
366 346
367 val = BIT(S_CMD_START_BUSY_SHIFT); 347 val = BIT(S_CMD_START_BUSY_SHIFT);
368 iproc_i2c_wr_reg(iproc_i2c, S_CMD_OFFSET, val); 348 iproc_i2c_wr_reg(iproc_i2c, S_CMD_OFFSET, val);
369 }
370 349
371 /* write request from master */ 350 /*
372 if ((status & BIT(IS_S_RX_EVENT_SHIFT)) && 351 * Enable interrupt for TX FIFO becomes empty and
373 (iproc_i2c->xfer_dir == I2C_SLAVE_DIR_READ)) { 352 * less than PKT_LENGTH bytes were output on the SMBUS
374 val = iproc_i2c_rd_reg(iproc_i2c, S_RX_OFFSET); 353 */
375 /* Its a write request by Master to Slave. 354 val = iproc_i2c_rd_reg(iproc_i2c, IE_OFFSET);
376 * We read data present in receive FIFO 355 val |= BIT(IE_S_TX_UNDERRUN_SHIFT);
377 */ 356 iproc_i2c_wr_reg(iproc_i2c, IE_OFFSET, val);
378 value = (u8)((val >> S_RX_DATA_SHIFT) & S_RX_DATA_MASK); 357 } else {
358 /* Master write other than start */
359 value = (u8)((val >> S_RX_DATA_SHIFT) & S_RX_DATA_MASK);
360 i2c_slave_event(iproc_i2c->slave,
361 I2C_SLAVE_WRITE_RECEIVED, &value);
362 }
363 } else if (status & BIT(IS_S_TX_UNDERRUN_SHIFT)) {
364 /* Master read other than start */
379 i2c_slave_event(iproc_i2c->slave, 365 i2c_slave_event(iproc_i2c->slave,
380 I2C_SLAVE_WRITE_RECEIVED, &value); 366 I2C_SLAVE_READ_PROCESSED, &value);
381
382 /* check the status for the last byte of the transaction */
383 rd_status = (val >> S_RX_STATUS_SHIFT) & S_RX_STATUS_MASK;
384 if (rd_status == I2C_SLAVE_RX_END)
385 iproc_i2c->xfer_dir = I2C_SLAVE_DIR_NONE;
386 367
387 dev_dbg(iproc_i2c->device, "\nread value = 0x%x\n", value); 368 iproc_i2c_wr_reg(iproc_i2c, S_TX_OFFSET, value);
369 val = BIT(S_CMD_START_BUSY_SHIFT);
370 iproc_i2c_wr_reg(iproc_i2c, S_CMD_OFFSET, val);
388 } 371 }
389 372
390 /* Stop */ 373 /* Stop */
391 if (status & BIT(IS_S_START_BUSY_SHIFT)) { 374 if (status & BIT(IS_S_START_BUSY_SHIFT)) {
392 i2c_slave_event(iproc_i2c->slave, I2C_SLAVE_STOP, &value); 375 i2c_slave_event(iproc_i2c->slave, I2C_SLAVE_STOP, &value);
393 iproc_i2c->xfer_dir = I2C_SLAVE_DIR_NONE; 376 /*
377 * Enable interrupt for TX FIFO becomes empty and
378 * less than PKT_LENGTH bytes were output on the SMBUS
379 */
380 val = iproc_i2c_rd_reg(iproc_i2c, IE_OFFSET);
381 val &= ~BIT(IE_S_TX_UNDERRUN_SHIFT);
382 iproc_i2c_wr_reg(iproc_i2c, IE_OFFSET, val);
394 } 383 }
395 384
396 /* clear interrupt status */ 385 /* clear interrupt status */
diff --git a/drivers/i2c/busses/i2c-bcm2835.c b/drivers/i2c/busses/i2c-bcm2835.c
index d2fbb4bb4a43..67752f7b0371 100644
--- a/drivers/i2c/busses/i2c-bcm2835.c
+++ b/drivers/i2c/busses/i2c-bcm2835.c
@@ -4,6 +4,8 @@
4 */ 4 */
5 5
6#include <linux/clk.h> 6#include <linux/clk.h>
7#include <linux/clkdev.h>
8#include <linux/clk-provider.h>
7#include <linux/completion.h> 9#include <linux/completion.h>
8#include <linux/err.h> 10#include <linux/err.h>
9#include <linux/i2c.h> 11#include <linux/i2c.h>
@@ -51,9 +53,7 @@
51struct bcm2835_i2c_dev { 53struct bcm2835_i2c_dev {
52 struct device *dev; 54 struct device *dev;
53 void __iomem *regs; 55 void __iomem *regs;
54 struct clk *clk;
55 int irq; 56 int irq;
56 u32 bus_clk_rate;
57 struct i2c_adapter adapter; 57 struct i2c_adapter adapter;
58 struct completion completion; 58 struct completion completion;
59 struct i2c_msg *curr_msg; 59 struct i2c_msg *curr_msg;
@@ -74,12 +74,17 @@ static inline u32 bcm2835_i2c_readl(struct bcm2835_i2c_dev *i2c_dev, u32 reg)
74 return readl(i2c_dev->regs + reg); 74 return readl(i2c_dev->regs + reg);
75} 75}
76 76
77static int bcm2835_i2c_set_divider(struct bcm2835_i2c_dev *i2c_dev) 77#define to_clk_bcm2835_i2c(_hw) container_of(_hw, struct clk_bcm2835_i2c, hw)
78struct clk_bcm2835_i2c {
79 struct clk_hw hw;
80 struct bcm2835_i2c_dev *i2c_dev;
81};
82
83static int clk_bcm2835_i2c_calc_divider(unsigned long rate,
84 unsigned long parent_rate)
78{ 85{
79 u32 divider, redl, fedl; 86 u32 divider = DIV_ROUND_UP(parent_rate, rate);
80 87
81 divider = DIV_ROUND_UP(clk_get_rate(i2c_dev->clk),
82 i2c_dev->bus_clk_rate);
83 /* 88 /*
84 * Per the datasheet, the register is always interpreted as an even 89 * Per the datasheet, the register is always interpreted as an even
85 * number, by rounding down. In other words, the LSB is ignored. So, 90 * number, by rounding down. In other words, the LSB is ignored. So,
@@ -88,12 +93,23 @@ static int bcm2835_i2c_set_divider(struct bcm2835_i2c_dev *i2c_dev)
88 if (divider & 1) 93 if (divider & 1)
89 divider++; 94 divider++;
90 if ((divider < BCM2835_I2C_CDIV_MIN) || 95 if ((divider < BCM2835_I2C_CDIV_MIN) ||
91 (divider > BCM2835_I2C_CDIV_MAX)) { 96 (divider > BCM2835_I2C_CDIV_MAX))
92 dev_err_ratelimited(i2c_dev->dev, "Invalid clock-frequency\n");
93 return -EINVAL; 97 return -EINVAL;
94 }
95 98
96 bcm2835_i2c_writel(i2c_dev, BCM2835_I2C_DIV, divider); 99 return divider;
100}
101
102static int clk_bcm2835_i2c_set_rate(struct clk_hw *hw, unsigned long rate,
103 unsigned long parent_rate)
104{
105 struct clk_bcm2835_i2c *div = to_clk_bcm2835_i2c(hw);
106 u32 redl, fedl;
107 u32 divider = clk_bcm2835_i2c_calc_divider(rate, parent_rate);
108
109 if (divider == -EINVAL)
110 return -EINVAL;
111
112 bcm2835_i2c_writel(div->i2c_dev, BCM2835_I2C_DIV, divider);
97 113
98 /* 114 /*
99 * Number of core clocks to wait after falling edge before 115 * Number of core clocks to wait after falling edge before
@@ -108,12 +124,65 @@ static int bcm2835_i2c_set_divider(struct bcm2835_i2c_dev *i2c_dev)
108 */ 124 */
109 redl = max(divider / 4, 1u); 125 redl = max(divider / 4, 1u);
110 126
111 bcm2835_i2c_writel(i2c_dev, BCM2835_I2C_DEL, 127 bcm2835_i2c_writel(div->i2c_dev, BCM2835_I2C_DEL,
112 (fedl << BCM2835_I2C_FEDL_SHIFT) | 128 (fedl << BCM2835_I2C_FEDL_SHIFT) |
113 (redl << BCM2835_I2C_REDL_SHIFT)); 129 (redl << BCM2835_I2C_REDL_SHIFT));
114 return 0; 130 return 0;
115} 131}
116 132
133static long clk_bcm2835_i2c_round_rate(struct clk_hw *hw, unsigned long rate,
134 unsigned long *parent_rate)
135{
136 u32 divider = clk_bcm2835_i2c_calc_divider(rate, *parent_rate);
137
138 return DIV_ROUND_UP(*parent_rate, divider);
139}
140
141static unsigned long clk_bcm2835_i2c_recalc_rate(struct clk_hw *hw,
142 unsigned long parent_rate)
143{
144 struct clk_bcm2835_i2c *div = to_clk_bcm2835_i2c(hw);
145 u32 divider = bcm2835_i2c_readl(div->i2c_dev, BCM2835_I2C_DIV);
146
147 return DIV_ROUND_UP(parent_rate, divider);
148}
149
150static const struct clk_ops clk_bcm2835_i2c_ops = {
151 .set_rate = clk_bcm2835_i2c_set_rate,
152 .round_rate = clk_bcm2835_i2c_round_rate,
153 .recalc_rate = clk_bcm2835_i2c_recalc_rate,
154};
155
156static struct clk *bcm2835_i2c_register_div(struct device *dev,
157 struct clk *mclk,
158 struct bcm2835_i2c_dev *i2c_dev)
159{
160 struct clk_init_data init;
161 struct clk_bcm2835_i2c *priv;
162 char name[32];
163 const char *mclk_name;
164
165 snprintf(name, sizeof(name), "%s_div", dev_name(dev));
166
167 mclk_name = __clk_get_name(mclk);
168
169 init.ops = &clk_bcm2835_i2c_ops;
170 init.name = name;
171 init.parent_names = (const char* []) { mclk_name };
172 init.num_parents = 1;
173 init.flags = 0;
174
175 priv = devm_kzalloc(dev, sizeof(struct clk_bcm2835_i2c), GFP_KERNEL);
176 if (priv == NULL)
177 return ERR_PTR(-ENOMEM);
178
179 priv->hw.init = &init;
180 priv->i2c_dev = i2c_dev;
181
182 clk_hw_register_clkdev(&priv->hw, "div", dev_name(dev));
183 return devm_clk_register(dev, &priv->hw);
184}
185
117static void bcm2835_fill_txfifo(struct bcm2835_i2c_dev *i2c_dev) 186static void bcm2835_fill_txfifo(struct bcm2835_i2c_dev *i2c_dev)
118{ 187{
119 u32 val; 188 u32 val;
@@ -271,7 +340,7 @@ static int bcm2835_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[],
271{ 340{
272 struct bcm2835_i2c_dev *i2c_dev = i2c_get_adapdata(adap); 341 struct bcm2835_i2c_dev *i2c_dev = i2c_get_adapdata(adap);
273 unsigned long time_left; 342 unsigned long time_left;
274 int i, ret; 343 int i;
275 344
276 for (i = 0; i < (num - 1); i++) 345 for (i = 0; i < (num - 1); i++)
277 if (msgs[i].flags & I2C_M_RD) { 346 if (msgs[i].flags & I2C_M_RD) {
@@ -280,10 +349,6 @@ static int bcm2835_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[],
280 return -EOPNOTSUPP; 349 return -EOPNOTSUPP;
281 } 350 }
282 351
283 ret = bcm2835_i2c_set_divider(i2c_dev);
284 if (ret)
285 return ret;
286
287 i2c_dev->curr_msg = msgs; 352 i2c_dev->curr_msg = msgs;
288 i2c_dev->num_msgs = num; 353 i2c_dev->num_msgs = num;
289 reinit_completion(&i2c_dev->completion); 354 reinit_completion(&i2c_dev->completion);
@@ -338,6 +403,9 @@ static int bcm2835_i2c_probe(struct platform_device *pdev)
338 struct resource *mem, *irq; 403 struct resource *mem, *irq;
339 int ret; 404 int ret;
340 struct i2c_adapter *adap; 405 struct i2c_adapter *adap;
406 struct clk *bus_clk;
407 struct clk *mclk;
408 u32 bus_clk_rate;
341 409
342 i2c_dev = devm_kzalloc(&pdev->dev, sizeof(*i2c_dev), GFP_KERNEL); 410 i2c_dev = devm_kzalloc(&pdev->dev, sizeof(*i2c_dev), GFP_KERNEL);
343 if (!i2c_dev) 411 if (!i2c_dev)
@@ -351,19 +419,38 @@ static int bcm2835_i2c_probe(struct platform_device *pdev)
351 if (IS_ERR(i2c_dev->regs)) 419 if (IS_ERR(i2c_dev->regs))
352 return PTR_ERR(i2c_dev->regs); 420 return PTR_ERR(i2c_dev->regs);
353 421
354 i2c_dev->clk = devm_clk_get(&pdev->dev, NULL); 422 mclk = devm_clk_get(&pdev->dev, NULL);
355 if (IS_ERR(i2c_dev->clk)) { 423 if (IS_ERR(mclk)) {
356 if (PTR_ERR(i2c_dev->clk) != -EPROBE_DEFER) 424 if (PTR_ERR(mclk) != -EPROBE_DEFER)
357 dev_err(&pdev->dev, "Could not get clock\n"); 425 dev_err(&pdev->dev, "Could not get clock\n");
358 return PTR_ERR(i2c_dev->clk); 426 return PTR_ERR(mclk);
427 }
428
429 bus_clk = bcm2835_i2c_register_div(&pdev->dev, mclk, i2c_dev);
430
431 if (IS_ERR(bus_clk)) {
432 dev_err(&pdev->dev, "Could not register clock\n");
433 return PTR_ERR(bus_clk);
359 } 434 }
360 435
361 ret = of_property_read_u32(pdev->dev.of_node, "clock-frequency", 436 ret = of_property_read_u32(pdev->dev.of_node, "clock-frequency",
362 &i2c_dev->bus_clk_rate); 437 &bus_clk_rate);
363 if (ret < 0) { 438 if (ret < 0) {
364 dev_warn(&pdev->dev, 439 dev_warn(&pdev->dev,
365 "Could not read clock-frequency property\n"); 440 "Could not read clock-frequency property\n");
366 i2c_dev->bus_clk_rate = 100000; 441 bus_clk_rate = 100000;
442 }
443
444 ret = clk_set_rate_exclusive(bus_clk, bus_clk_rate);
445 if (ret < 0) {
446 dev_err(&pdev->dev, "Could not set clock frequency\n");
447 return ret;
448 }
449
450 ret = clk_prepare_enable(bus_clk);
451 if (ret) {
452 dev_err(&pdev->dev, "Couldn't prepare clock");
453 return ret;
367 } 454 }
368 455
369 irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 456 irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
@@ -402,6 +489,10 @@ static int bcm2835_i2c_probe(struct platform_device *pdev)
402static int bcm2835_i2c_remove(struct platform_device *pdev) 489static int bcm2835_i2c_remove(struct platform_device *pdev)
403{ 490{
404 struct bcm2835_i2c_dev *i2c_dev = platform_get_drvdata(pdev); 491 struct bcm2835_i2c_dev *i2c_dev = platform_get_drvdata(pdev);
492 struct clk *bus_clk = devm_clk_get(i2c_dev->dev, "div");
493
494 clk_rate_exclusive_put(bus_clk);
495 clk_disable_unprepare(bus_clk);
405 496
406 free_irq(i2c_dev->irq, i2c_dev); 497 free_irq(i2c_dev->irq, i2c_dev);
407 i2c_del_adapter(&i2c_dev->adapter); 498 i2c_del_adapter(&i2c_dev->adapter);
diff --git a/drivers/i2c/busses/i2c-cpm.c b/drivers/i2c/busses/i2c-cpm.c
index 187900594e3d..1213e1932ccb 100644
--- a/drivers/i2c/busses/i2c-cpm.c
+++ b/drivers/i2c/busses/i2c-cpm.c
@@ -531,7 +531,9 @@ static int cpm_i2c_setup(struct cpm_i2c *cpm)
531 } 531 }
532 out_be32(&rbdf[i].cbd_bufaddr, ((cpm->rxdma[i] + 1) & ~1)); 532 out_be32(&rbdf[i].cbd_bufaddr, ((cpm->rxdma[i] + 1) & ~1));
533 533
534 cpm->txbuf[i] = (unsigned char *)dma_alloc_coherent(&cpm->ofdev->dev, CPM_MAX_READ + 1, &cpm->txdma[i], GFP_KERNEL); 534 cpm->txbuf[i] = dma_alloc_coherent(&cpm->ofdev->dev,
535 CPM_MAX_READ + 1,
536 &cpm->txdma[i], GFP_KERNEL);
535 if (!cpm->txbuf[i]) { 537 if (!cpm->txbuf[i]) {
536 ret = -ENOMEM; 538 ret = -ENOMEM;
537 goto out_muram; 539 goto out_muram;
diff --git a/drivers/i2c/busses/i2c-fsi.c b/drivers/i2c/busses/i2c-fsi.c
index 1e2be2219a60..da5eb3960def 100644
--- a/drivers/i2c/busses/i2c-fsi.c
+++ b/drivers/i2c/busses/i2c-fsi.c
@@ -658,13 +658,29 @@ static const struct i2c_algorithm fsi_i2c_algorithm = {
658 .functionality = fsi_i2c_functionality, 658 .functionality = fsi_i2c_functionality,
659}; 659};
660 660
661static struct device_node *fsi_i2c_find_port_of_node(struct device_node *fsi,
662 int port)
663{
664 struct device_node *np;
665 u32 port_no;
666 int rc;
667
668 for_each_child_of_node(fsi, np) {
669 rc = of_property_read_u32(np, "reg", &port_no);
670 if (!rc && port_no == port)
671 return np;
672 }
673
674 return NULL;
675}
676
661static int fsi_i2c_probe(struct device *dev) 677static int fsi_i2c_probe(struct device *dev)
662{ 678{
663 struct fsi_i2c_master *i2c; 679 struct fsi_i2c_master *i2c;
664 struct fsi_i2c_port *port; 680 struct fsi_i2c_port *port;
665 struct device_node *np; 681 struct device_node *np;
682 u32 port_no, ports, stat;
666 int rc; 683 int rc;
667 u32 port_no;
668 684
669 i2c = devm_kzalloc(dev, sizeof(*i2c), GFP_KERNEL); 685 i2c = devm_kzalloc(dev, sizeof(*i2c), GFP_KERNEL);
670 if (!i2c) 686 if (!i2c)
@@ -678,10 +694,16 @@ static int fsi_i2c_probe(struct device *dev)
678 if (rc) 694 if (rc)
679 return rc; 695 return rc;
680 696
681 /* Add adapter for each i2c port of the master. */ 697 rc = fsi_i2c_read_reg(i2c->fsi, I2C_FSI_STAT, &stat);
682 for_each_available_child_of_node(dev->of_node, np) { 698 if (rc)
683 rc = of_property_read_u32(np, "reg", &port_no); 699 return rc;
684 if (rc || port_no > USHRT_MAX) 700
701 ports = FIELD_GET(I2C_STAT_MAX_PORT, stat) + 1;
702 dev_dbg(dev, "I2C master has %d ports\n", ports);
703
704 for (port_no = 0; port_no < ports; port_no++) {
705 np = fsi_i2c_find_port_of_node(dev->of_node, port_no);
706 if (np && !of_device_is_available(np))
685 continue; 707 continue;
686 708
687 port = kzalloc(sizeof(*port), GFP_KERNEL); 709 port = kzalloc(sizeof(*port), GFP_KERNEL);
diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index ac7f7817dc89..f2956936c3f2 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -64,12 +64,14 @@
64 * Cedar Fork (PCH) 0x18df 32 hard yes yes yes 64 * Cedar Fork (PCH) 0x18df 32 hard yes yes yes
65 * Ice Lake-LP (PCH) 0x34a3 32 hard yes yes yes 65 * Ice Lake-LP (PCH) 0x34a3 32 hard yes yes yes
66 * Comet Lake (PCH) 0x02a3 32 hard yes yes yes 66 * Comet Lake (PCH) 0x02a3 32 hard yes yes yes
67 * Elkhart Lake (PCH) 0x4b23 32 hard yes yes yes
68 * Tiger Lake-LP (PCH) 0xa0a3 32 hard yes yes yes
67 * 69 *
68 * Features supported by this driver: 70 * Features supported by this driver:
69 * Software PEC no 71 * Software PEC no
70 * Hardware PEC yes 72 * Hardware PEC yes
71 * Block buffer yes 73 * Block buffer yes
72 * Block process call transaction no 74 * Block process call transaction yes
73 * I2C block read transaction yes (doesn't use the block buffer) 75 * I2C block read transaction yes (doesn't use the block buffer)
74 * Slave mode no 76 * Slave mode no
75 * SMBus Host Notify yes 77 * SMBus Host Notify yes
@@ -92,6 +94,7 @@
92#include <linux/io.h> 94#include <linux/io.h>
93#include <linux/dmi.h> 95#include <linux/dmi.h>
94#include <linux/slab.h> 96#include <linux/slab.h>
97#include <linux/string.h>
95#include <linux/wait.h> 98#include <linux/wait.h>
96#include <linux/err.h> 99#include <linux/err.h>
97#include <linux/platform_device.h> 100#include <linux/platform_device.h>
@@ -99,7 +102,7 @@
99#include <linux/pm_runtime.h> 102#include <linux/pm_runtime.h>
100 103
101#if IS_ENABLED(CONFIG_I2C_MUX_GPIO) && defined CONFIG_DMI 104#if IS_ENABLED(CONFIG_I2C_MUX_GPIO) && defined CONFIG_DMI
102#include <linux/gpio.h> 105#include <linux/gpio/machine.h>
103#include <linux/platform_data/i2c-mux-gpio.h> 106#include <linux/platform_data/i2c-mux-gpio.h>
104#endif 107#endif
105 108
@@ -169,6 +172,7 @@
169#define I801_PROC_CALL 0x10 /* unimplemented */ 172#define I801_PROC_CALL 0x10 /* unimplemented */
170#define I801_BLOCK_DATA 0x14 173#define I801_BLOCK_DATA 0x14
171#define I801_I2C_BLOCK_DATA 0x18 /* ICH5 and later */ 174#define I801_I2C_BLOCK_DATA 0x18 /* ICH5 and later */
175#define I801_BLOCK_PROC_CALL 0x1C
172 176
173/* I801 Host Control register bits */ 177/* I801 Host Control register bits */
174#define SMBHSTCNT_INTREN BIT(0) 178#define SMBHSTCNT_INTREN BIT(0)
@@ -200,6 +204,7 @@
200 STATUS_ERROR_FLAGS) 204 STATUS_ERROR_FLAGS)
201 205
202/* Older devices have their ID defined in <linux/pci_ids.h> */ 206/* Older devices have their ID defined in <linux/pci_ids.h> */
207#define PCI_DEVICE_ID_INTEL_COMETLAKE_SMBUS 0x02a3
203#define PCI_DEVICE_ID_INTEL_BAYTRAIL_SMBUS 0x0f12 208#define PCI_DEVICE_ID_INTEL_BAYTRAIL_SMBUS 0x0f12
204#define PCI_DEVICE_ID_INTEL_CDF_SMBUS 0x18df 209#define PCI_DEVICE_ID_INTEL_CDF_SMBUS 0x18df
205#define PCI_DEVICE_ID_INTEL_DNV_SMBUS 0x19df 210#define PCI_DEVICE_ID_INTEL_DNV_SMBUS 0x19df
@@ -217,6 +222,7 @@
217#define PCI_DEVICE_ID_INTEL_GEMINILAKE_SMBUS 0x31d4 222#define PCI_DEVICE_ID_INTEL_GEMINILAKE_SMBUS 0x31d4
218#define PCI_DEVICE_ID_INTEL_ICELAKE_LP_SMBUS 0x34a3 223#define PCI_DEVICE_ID_INTEL_ICELAKE_LP_SMBUS 0x34a3
219#define PCI_DEVICE_ID_INTEL_5_3400_SERIES_SMBUS 0x3b30 224#define PCI_DEVICE_ID_INTEL_5_3400_SERIES_SMBUS 0x3b30
225#define PCI_DEVICE_ID_INTEL_ELKHART_LAKE_SMBUS 0x4b23
220#define PCI_DEVICE_ID_INTEL_BROXTON_SMBUS 0x5ad4 226#define PCI_DEVICE_ID_INTEL_BROXTON_SMBUS 0x5ad4
221#define PCI_DEVICE_ID_INTEL_LYNXPOINT_SMBUS 0x8c22 227#define PCI_DEVICE_ID_INTEL_LYNXPOINT_SMBUS 0x8c22
222#define PCI_DEVICE_ID_INTEL_WILDCATPOINT_SMBUS 0x8ca2 228#define PCI_DEVICE_ID_INTEL_WILDCATPOINT_SMBUS 0x8ca2
@@ -228,12 +234,12 @@
228#define PCI_DEVICE_ID_INTEL_WILDCATPOINT_LP_SMBUS 0x9ca2 234#define PCI_DEVICE_ID_INTEL_WILDCATPOINT_LP_SMBUS 0x9ca2
229#define PCI_DEVICE_ID_INTEL_SUNRISEPOINT_LP_SMBUS 0x9d23 235#define PCI_DEVICE_ID_INTEL_SUNRISEPOINT_LP_SMBUS 0x9d23
230#define PCI_DEVICE_ID_INTEL_CANNONLAKE_LP_SMBUS 0x9da3 236#define PCI_DEVICE_ID_INTEL_CANNONLAKE_LP_SMBUS 0x9da3
237#define PCI_DEVICE_ID_INTEL_TIGERLAKE_LP_SMBUS 0xa0a3
231#define PCI_DEVICE_ID_INTEL_SUNRISEPOINT_H_SMBUS 0xa123 238#define PCI_DEVICE_ID_INTEL_SUNRISEPOINT_H_SMBUS 0xa123
232#define PCI_DEVICE_ID_INTEL_LEWISBURG_SMBUS 0xa1a3 239#define PCI_DEVICE_ID_INTEL_LEWISBURG_SMBUS 0xa1a3
233#define PCI_DEVICE_ID_INTEL_LEWISBURG_SSKU_SMBUS 0xa223 240#define PCI_DEVICE_ID_INTEL_LEWISBURG_SSKU_SMBUS 0xa223
234#define PCI_DEVICE_ID_INTEL_KABYLAKE_PCH_H_SMBUS 0xa2a3 241#define PCI_DEVICE_ID_INTEL_KABYLAKE_PCH_H_SMBUS 0xa2a3
235#define PCI_DEVICE_ID_INTEL_CANNONLAKE_H_SMBUS 0xa323 242#define PCI_DEVICE_ID_INTEL_CANNONLAKE_H_SMBUS 0xa323
236#define PCI_DEVICE_ID_INTEL_COMETLAKE_SMBUS 0x02a3
237 243
238struct i801_mux_config { 244struct i801_mux_config {
239 char *gpio_chip; 245 char *gpio_chip;
@@ -266,6 +272,7 @@ struct i801_priv {
266#if IS_ENABLED(CONFIG_I2C_MUX_GPIO) && defined CONFIG_DMI 272#if IS_ENABLED(CONFIG_I2C_MUX_GPIO) && defined CONFIG_DMI
267 const struct i801_mux_config *mux_drvdata; 273 const struct i801_mux_config *mux_drvdata;
268 struct platform_device *mux_pdev; 274 struct platform_device *mux_pdev;
275 struct gpiod_lookup_table *lookup;
269#endif 276#endif
270 struct platform_device *tco_pdev; 277 struct platform_device *tco_pdev;
271 278
@@ -509,10 +516,23 @@ static int i801_transaction(struct i801_priv *priv, int xact)
509 516
510static int i801_block_transaction_by_block(struct i801_priv *priv, 517static int i801_block_transaction_by_block(struct i801_priv *priv,
511 union i2c_smbus_data *data, 518 union i2c_smbus_data *data,
512 char read_write, int hwpec) 519 char read_write, int command,
520 int hwpec)
513{ 521{
514 int i, len; 522 int i, len;
515 int status; 523 int status;
524 int xact = hwpec ? SMBHSTCNT_PEC_EN : 0;
525
526 switch (command) {
527 case I2C_SMBUS_BLOCK_PROC_CALL:
528 xact |= I801_BLOCK_PROC_CALL;
529 break;
530 case I2C_SMBUS_BLOCK_DATA:
531 xact |= I801_BLOCK_DATA;
532 break;
533 default:
534 return -EOPNOTSUPP;
535 }
516 536
517 inb_p(SMBHSTCNT(priv)); /* reset the data buffer index */ 537 inb_p(SMBHSTCNT(priv)); /* reset the data buffer index */
518 538
@@ -524,12 +544,12 @@ static int i801_block_transaction_by_block(struct i801_priv *priv,
524 outb_p(data->block[i+1], SMBBLKDAT(priv)); 544 outb_p(data->block[i+1], SMBBLKDAT(priv));
525 } 545 }
526 546
527 status = i801_transaction(priv, I801_BLOCK_DATA | 547 status = i801_transaction(priv, xact);
528 (hwpec ? SMBHSTCNT_PEC_EN : 0));
529 if (status) 548 if (status)
530 return status; 549 return status;
531 550
532 if (read_write == I2C_SMBUS_READ) { 551 if (read_write == I2C_SMBUS_READ ||
552 command == I2C_SMBUS_BLOCK_PROC_CALL) {
533 len = inb_p(SMBHSTDAT0(priv)); 553 len = inb_p(SMBHSTDAT0(priv));
534 if (len < 1 || len > I2C_SMBUS_BLOCK_MAX) 554 if (len < 1 || len > I2C_SMBUS_BLOCK_MAX)
535 return -EPROTO; 555 return -EPROTO;
@@ -667,6 +687,9 @@ static int i801_block_transaction_byte_by_byte(struct i801_priv *priv,
667 int result; 687 int result;
668 const struct i2c_adapter *adap = &priv->adapter; 688 const struct i2c_adapter *adap = &priv->adapter;
669 689
690 if (command == I2C_SMBUS_BLOCK_PROC_CALL)
691 return -EOPNOTSUPP;
692
670 result = i801_check_pre(priv); 693 result = i801_check_pre(priv);
671 if (result < 0) 694 if (result < 0)
672 return result; 695 return result;
@@ -798,7 +821,8 @@ static int i801_block_transaction(struct i801_priv *priv,
798 && command != I2C_SMBUS_I2C_BLOCK_DATA 821 && command != I2C_SMBUS_I2C_BLOCK_DATA
799 && i801_set_block_buffer_mode(priv) == 0) 822 && i801_set_block_buffer_mode(priv) == 0)
800 result = i801_block_transaction_by_block(priv, data, 823 result = i801_block_transaction_by_block(priv, data,
801 read_write, hwpec); 824 read_write,
825 command, hwpec);
802 else 826 else
803 result = i801_block_transaction_byte_by_byte(priv, data, 827 result = i801_block_transaction_byte_by_byte(priv, data,
804 read_write, 828 read_write,
@@ -890,6 +914,15 @@ static s32 i801_access(struct i2c_adapter *adap, u16 addr,
890 outb_p(command, SMBHSTCMD(priv)); 914 outb_p(command, SMBHSTCMD(priv));
891 block = 1; 915 block = 1;
892 break; 916 break;
917 case I2C_SMBUS_BLOCK_PROC_CALL:
918 /*
919 * Bit 0 of the slave address register always indicate a write
920 * command.
921 */
922 outb_p((addr & 0x7f) << 1, SMBHSTADD(priv));
923 outb_p(command, SMBHSTCMD(priv));
924 block = 1;
925 break;
893 default: 926 default:
894 dev_err(&priv->pci_dev->dev, "Unsupported transaction %d\n", 927 dev_err(&priv->pci_dev->dev, "Unsupported transaction %d\n",
895 size); 928 size);
@@ -950,6 +983,8 @@ static u32 i801_func(struct i2c_adapter *adapter)
950 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | 983 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
951 I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_WRITE_I2C_BLOCK | 984 I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_WRITE_I2C_BLOCK |
952 ((priv->features & FEATURE_SMBUS_PEC) ? I2C_FUNC_SMBUS_PEC : 0) | 985 ((priv->features & FEATURE_SMBUS_PEC) ? I2C_FUNC_SMBUS_PEC : 0) |
986 ((priv->features & FEATURE_BLOCK_PROC) ?
987 I2C_FUNC_SMBUS_BLOCK_PROC_CALL : 0) |
953 ((priv->features & FEATURE_I2C_BLOCK_READ) ? 988 ((priv->features & FEATURE_I2C_BLOCK_READ) ?
954 I2C_FUNC_SMBUS_READ_I2C_BLOCK : 0) | 989 I2C_FUNC_SMBUS_READ_I2C_BLOCK : 0) |
955 ((priv->features & FEATURE_HOST_NOTIFY) ? 990 ((priv->features & FEATURE_HOST_NOTIFY) ?
@@ -1033,6 +1068,8 @@ static const struct pci_device_id i801_ids[] = {
1033 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CANNONLAKE_LP_SMBUS) }, 1068 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CANNONLAKE_LP_SMBUS) },
1034 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICELAKE_LP_SMBUS) }, 1069 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICELAKE_LP_SMBUS) },
1035 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_COMETLAKE_SMBUS) }, 1070 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_COMETLAKE_SMBUS) },
1071 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ELKHART_LAKE_SMBUS) },
1072 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_TIGERLAKE_LP_SMBUS) },
1036 { 0, } 1073 { 0, }
1037}; 1074};
1038 1075
@@ -1134,6 +1171,118 @@ static void dmi_check_onboard_devices(const struct dmi_header *dm, void *adap)
1134 } 1171 }
1135} 1172}
1136 1173
1174/* NOTE: Keep this list in sync with drivers/platform/x86/dell-smo8800.c */
1175static const char *const acpi_smo8800_ids[] = {
1176 "SMO8800",
1177 "SMO8801",
1178 "SMO8810",
1179 "SMO8811",
1180 "SMO8820",
1181 "SMO8821",
1182 "SMO8830",
1183 "SMO8831",
1184};
1185
1186static acpi_status check_acpi_smo88xx_device(acpi_handle obj_handle,
1187 u32 nesting_level,
1188 void *context,
1189 void **return_value)
1190{
1191 struct acpi_device_info *info;
1192 acpi_status status;
1193 char *hid;
1194 int i;
1195
1196 status = acpi_get_object_info(obj_handle, &info);
1197 if (!ACPI_SUCCESS(status) || !(info->valid & ACPI_VALID_HID))
1198 return AE_OK;
1199
1200 hid = info->hardware_id.string;
1201 if (!hid)
1202 return AE_OK;
1203
1204 i = match_string(acpi_smo8800_ids, ARRAY_SIZE(acpi_smo8800_ids), hid);
1205 if (i < 0)
1206 return AE_OK;
1207
1208 *((bool *)return_value) = true;
1209 return AE_CTRL_TERMINATE;
1210}
1211
1212static bool is_dell_system_with_lis3lv02d(void)
1213{
1214 bool found;
1215 const char *vendor;
1216
1217 vendor = dmi_get_system_info(DMI_SYS_VENDOR);
1218 if (!vendor || strcmp(vendor, "Dell Inc."))
1219 return false;
1220
1221 /*
1222 * Check that ACPI device SMO88xx is present and is functioning.
1223 * Function acpi_get_devices() already filters all ACPI devices
1224 * which are not present or are not functioning.
1225 * ACPI device SMO88xx represents our ST microelectronics lis3lv02d
1226 * accelerometer but unfortunately ACPI does not provide any other
1227 * information (like I2C address).
1228 */
1229 found = false;
1230 acpi_get_devices(NULL, check_acpi_smo88xx_device, NULL,
1231 (void **)&found);
1232
1233 return found;
1234}
1235
1236/*
1237 * Accelerometer's I2C address is not specified in DMI nor ACPI,
1238 * so it is needed to define mapping table based on DMI product names.
1239 */
1240static const struct {
1241 const char *dmi_product_name;
1242 unsigned short i2c_addr;
1243} dell_lis3lv02d_devices[] = {
1244 /*
1245 * Dell platform team told us that these Latitude devices have
1246 * ST microelectronics accelerometer at I2C address 0x29.
1247 */
1248 { "Latitude E5250", 0x29 },
1249 { "Latitude E5450", 0x29 },
1250 { "Latitude E5550", 0x29 },
1251 { "Latitude E6440", 0x29 },
1252 { "Latitude E6440 ATG", 0x29 },
1253 { "Latitude E6540", 0x29 },
1254 /*
1255 * Additional individual entries were added after verification.
1256 */
1257 { "Vostro V131", 0x1d },
1258};
1259
1260static void register_dell_lis3lv02d_i2c_device(struct i801_priv *priv)
1261{
1262 struct i2c_board_info info;
1263 const char *dmi_product_name;
1264 int i;
1265
1266 dmi_product_name = dmi_get_system_info(DMI_PRODUCT_NAME);
1267 for (i = 0; i < ARRAY_SIZE(dell_lis3lv02d_devices); ++i) {
1268 if (strcmp(dmi_product_name,
1269 dell_lis3lv02d_devices[i].dmi_product_name) == 0)
1270 break;
1271 }
1272
1273 if (i == ARRAY_SIZE(dell_lis3lv02d_devices)) {
1274 dev_warn(&priv->pci_dev->dev,
1275 "Accelerometer lis3lv02d is present on SMBus but its"
1276 " address is unknown, skipping registration\n");
1277 return;
1278 }
1279
1280 memset(&info, 0, sizeof(struct i2c_board_info));
1281 info.addr = dell_lis3lv02d_devices[i].i2c_addr;
1282 strlcpy(info.type, "lis3lv02d", I2C_NAME_SIZE);
1283 i2c_new_device(&priv->adapter, &info);
1284}
1285
1137/* Register optional slaves */ 1286/* Register optional slaves */
1138static void i801_probe_optional_slaves(struct i801_priv *priv) 1287static void i801_probe_optional_slaves(struct i801_priv *priv)
1139{ 1288{
@@ -1152,6 +1301,9 @@ static void i801_probe_optional_slaves(struct i801_priv *priv)
1152 1301
1153 if (dmi_name_in_vendors("FUJITSU")) 1302 if (dmi_name_in_vendors("FUJITSU"))
1154 dmi_walk(dmi_check_onboard_devices, &priv->adapter); 1303 dmi_walk(dmi_check_onboard_devices, &priv->adapter);
1304
1305 if (is_dell_system_with_lis3lv02d())
1306 register_dell_lis3lv02d_i2c_device(priv);
1155} 1307}
1156#else 1308#else
1157static void __init input_apanel_init(void) {} 1309static void __init input_apanel_init(void) {}
@@ -1250,7 +1402,8 @@ static int i801_add_mux(struct i801_priv *priv)
1250 struct device *dev = &priv->adapter.dev; 1402 struct device *dev = &priv->adapter.dev;
1251 const struct i801_mux_config *mux_config; 1403 const struct i801_mux_config *mux_config;
1252 struct i2c_mux_gpio_platform_data gpio_data; 1404 struct i2c_mux_gpio_platform_data gpio_data;
1253 int err; 1405 struct gpiod_lookup_table *lookup;
1406 int err, i;
1254 1407
1255 if (!priv->mux_drvdata) 1408 if (!priv->mux_drvdata)
1256 return 0; 1409 return 0;
@@ -1262,17 +1415,36 @@ static int i801_add_mux(struct i801_priv *priv)
1262 gpio_data.values = mux_config->values; 1415 gpio_data.values = mux_config->values;
1263 gpio_data.n_values = mux_config->n_values; 1416 gpio_data.n_values = mux_config->n_values;
1264 gpio_data.classes = mux_config->classes; 1417 gpio_data.classes = mux_config->classes;
1265 gpio_data.gpio_chip = mux_config->gpio_chip;
1266 gpio_data.gpios = mux_config->gpios;
1267 gpio_data.n_gpios = mux_config->n_gpios;
1268 gpio_data.idle = I2C_MUX_GPIO_NO_IDLE; 1418 gpio_data.idle = I2C_MUX_GPIO_NO_IDLE;
1269 1419
1270 /* Register the mux device */ 1420 /* Register GPIO descriptor lookup table */
1421 lookup = devm_kzalloc(dev,
1422 struct_size(lookup, table, mux_config->n_gpios),
1423 GFP_KERNEL);
1424 if (!lookup)
1425 return -ENOMEM;
1426 lookup->dev_id = "i2c-mux-gpio";
1427 for (i = 0; i < mux_config->n_gpios; i++) {
1428 lookup->table[i].chip_label = mux_config->gpio_chip;
1429 lookup->table[i].chip_hwnum = mux_config->gpios[i];
1430 lookup->table[i].con_id = "mux";
1431 }
1432 gpiod_add_lookup_table(lookup);
1433 priv->lookup = lookup;
1434
1435 /*
1436 * Register the mux device, we use PLATFORM_DEVID_NONE here
1437 * because since we are referring to the GPIO chip by name we are
1438 * anyways in deep trouble if there is more than one of these
1439 * devices, and there should likely only be one platform controller
1440 * hub.
1441 */
1271 priv->mux_pdev = platform_device_register_data(dev, "i2c-mux-gpio", 1442 priv->mux_pdev = platform_device_register_data(dev, "i2c-mux-gpio",
1272 PLATFORM_DEVID_AUTO, &gpio_data, 1443 PLATFORM_DEVID_NONE, &gpio_data,
1273 sizeof(struct i2c_mux_gpio_platform_data)); 1444 sizeof(struct i2c_mux_gpio_platform_data));
1274 if (IS_ERR(priv->mux_pdev)) { 1445 if (IS_ERR(priv->mux_pdev)) {
1275 err = PTR_ERR(priv->mux_pdev); 1446 err = PTR_ERR(priv->mux_pdev);
1447 gpiod_remove_lookup_table(lookup);
1276 priv->mux_pdev = NULL; 1448 priv->mux_pdev = NULL;
1277 dev_err(dev, "Failed to register i2c-mux-gpio device\n"); 1449 dev_err(dev, "Failed to register i2c-mux-gpio device\n");
1278 return err; 1450 return err;
@@ -1285,6 +1457,8 @@ static void i801_del_mux(struct i801_priv *priv)
1285{ 1457{
1286 if (priv->mux_pdev) 1458 if (priv->mux_pdev)
1287 platform_device_unregister(priv->mux_pdev); 1459 platform_device_unregister(priv->mux_pdev);
1460 if (priv->lookup)
1461 gpiod_remove_lookup_table(priv->lookup);
1288} 1462}
1289 1463
1290static unsigned int i801_get_adapter_class(struct i801_priv *priv) 1464static unsigned int i801_get_adapter_class(struct i801_priv *priv)
@@ -1530,6 +1704,9 @@ static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id)
1530 case PCI_DEVICE_ID_INTEL_KABYLAKE_PCH_H_SMBUS: 1704 case PCI_DEVICE_ID_INTEL_KABYLAKE_PCH_H_SMBUS:
1531 case PCI_DEVICE_ID_INTEL_ICELAKE_LP_SMBUS: 1705 case PCI_DEVICE_ID_INTEL_ICELAKE_LP_SMBUS:
1532 case PCI_DEVICE_ID_INTEL_COMETLAKE_SMBUS: 1706 case PCI_DEVICE_ID_INTEL_COMETLAKE_SMBUS:
1707 case PCI_DEVICE_ID_INTEL_ELKHART_LAKE_SMBUS:
1708 case PCI_DEVICE_ID_INTEL_TIGERLAKE_LP_SMBUS:
1709 priv->features |= FEATURE_BLOCK_PROC;
1533 priv->features |= FEATURE_I2C_BLOCK_READ; 1710 priv->features |= FEATURE_I2C_BLOCK_READ;
1534 priv->features |= FEATURE_IRQ; 1711 priv->features |= FEATURE_IRQ;
1535 priv->features |= FEATURE_SMBUS_PEC; 1712 priv->features |= FEATURE_SMBUS_PEC;
@@ -1549,6 +1726,7 @@ static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id)
1549 priv->features |= FEATURE_IDF; 1726 priv->features |= FEATURE_IDF;
1550 /* fall through */ 1727 /* fall through */
1551 default: 1728 default:
1729 priv->features |= FEATURE_BLOCK_PROC;
1552 priv->features |= FEATURE_I2C_BLOCK_READ; 1730 priv->features |= FEATURE_I2C_BLOCK_READ;
1553 priv->features |= FEATURE_IRQ; 1731 priv->features |= FEATURE_IRQ;
1554 /* fall through */ 1732 /* fall through */
diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index fd70b110e8f4..b1b8b938d7f4 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -1220,8 +1220,7 @@ static int i2c_imx_remove(struct platform_device *pdev)
1220 return 0; 1220 return 0;
1221} 1221}
1222 1222
1223#ifdef CONFIG_PM 1223static int __maybe_unused i2c_imx_runtime_suspend(struct device *dev)
1224static int i2c_imx_runtime_suspend(struct device *dev)
1225{ 1224{
1226 struct imx_i2c_struct *i2c_imx = dev_get_drvdata(dev); 1225 struct imx_i2c_struct *i2c_imx = dev_get_drvdata(dev);
1227 1226
@@ -1230,7 +1229,7 @@ static int i2c_imx_runtime_suspend(struct device *dev)
1230 return 0; 1229 return 0;
1231} 1230}
1232 1231
1233static int i2c_imx_runtime_resume(struct device *dev) 1232static int __maybe_unused i2c_imx_runtime_resume(struct device *dev)
1234{ 1233{
1235 struct imx_i2c_struct *i2c_imx = dev_get_drvdata(dev); 1234 struct imx_i2c_struct *i2c_imx = dev_get_drvdata(dev);
1236 int ret; 1235 int ret;
@@ -1246,17 +1245,13 @@ static const struct dev_pm_ops i2c_imx_pm_ops = {
1246 SET_RUNTIME_PM_OPS(i2c_imx_runtime_suspend, 1245 SET_RUNTIME_PM_OPS(i2c_imx_runtime_suspend,
1247 i2c_imx_runtime_resume, NULL) 1246 i2c_imx_runtime_resume, NULL)
1248}; 1247};
1249#define I2C_IMX_PM_OPS (&i2c_imx_pm_ops)
1250#else
1251#define I2C_IMX_PM_OPS NULL
1252#endif /* CONFIG_PM */
1253 1248
1254static struct platform_driver i2c_imx_driver = { 1249static struct platform_driver i2c_imx_driver = {
1255 .probe = i2c_imx_probe, 1250 .probe = i2c_imx_probe,
1256 .remove = i2c_imx_remove, 1251 .remove = i2c_imx_remove,
1257 .driver = { 1252 .driver = {
1258 .name = DRIVER_NAME, 1253 .name = DRIVER_NAME,
1259 .pm = I2C_IMX_PM_OPS, 1254 .pm = &i2c_imx_pm_ops,
1260 .of_match_table = i2c_imx_dt_ids, 1255 .of_match_table = i2c_imx_dt_ids,
1261 }, 1256 },
1262 .id_table = imx_i2c_devtype, 1257 .id_table = imx_i2c_devtype,
diff --git a/drivers/i2c/busses/i2c-iop3xx.c b/drivers/i2c/busses/i2c-iop3xx.c
index 87ce788ab90c..38556381f4ca 100644
--- a/drivers/i2c/busses/i2c-iop3xx.c
+++ b/drivers/i2c/busses/i2c-iop3xx.c
@@ -35,7 +35,7 @@
35#include <linux/platform_device.h> 35#include <linux/platform_device.h>
36#include <linux/i2c.h> 36#include <linux/i2c.h>
37#include <linux/io.h> 37#include <linux/io.h>
38#include <linux/gpio.h> 38#include <linux/gpio/consumer.h>
39 39
40#include "i2c-iop3xx.h" 40#include "i2c-iop3xx.h"
41 41
@@ -68,17 +68,16 @@ iop3xx_i2c_enable(struct i2c_algo_iop3xx_data *iop3xx_adap)
68 68
69 /* 69 /*
70 * Every time unit enable is asserted, GPOD needs to be cleared 70 * Every time unit enable is asserted, GPOD needs to be cleared
71 * on IOP3XX to avoid data corruption on the bus. 71 * on IOP3XX to avoid data corruption on the bus. We use the
72 * gpiod_set_raw_value() to make sure the 0 hits the hardware
73 * GPOD register. These descriptors are only passed along to
74 * the device if this is necessary.
72 */ 75 */
73#if defined(CONFIG_ARCH_IOP32X) || defined(CONFIG_ARCH_IOP33X) 76 if (iop3xx_adap->gpio_scl)
74 if (iop3xx_adap->id == 0) { 77 gpiod_set_raw_value(iop3xx_adap->gpio_scl, 0);
75 gpio_set_value(7, 0); 78 if (iop3xx_adap->gpio_sda)
76 gpio_set_value(6, 0); 79 gpiod_set_raw_value(iop3xx_adap->gpio_sda, 0);
77 } else { 80
78 gpio_set_value(5, 0);
79 gpio_set_value(4, 0);
80 }
81#endif
82 /* NB SR bits not same position as CR IE bits :-( */ 81 /* NB SR bits not same position as CR IE bits :-( */
83 iop3xx_adap->SR_enabled = 82 iop3xx_adap->SR_enabled =
84 IOP3XX_ISR_ALD | IOP3XX_ISR_BERRD | 83 IOP3XX_ISR_ALD | IOP3XX_ISR_BERRD |
@@ -431,6 +430,17 @@ iop3xx_i2c_probe(struct platform_device *pdev)
431 goto free_adapter; 430 goto free_adapter;
432 } 431 }
433 432
433 adapter_data->gpio_scl = devm_gpiod_get_optional(&pdev->dev,
434 "scl",
435 GPIOD_ASIS);
436 if (IS_ERR(adapter_data->gpio_scl))
437 return PTR_ERR(adapter_data->gpio_scl);
438 adapter_data->gpio_sda = devm_gpiod_get_optional(&pdev->dev,
439 "sda",
440 GPIOD_ASIS);
441 if (IS_ERR(adapter_data->gpio_sda))
442 return PTR_ERR(adapter_data->gpio_sda);
443
434 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 444 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
435 if (!res) { 445 if (!res) {
436 ret = -ENODEV; 446 ret = -ENODEV;
diff --git a/drivers/i2c/busses/i2c-iop3xx.h b/drivers/i2c/busses/i2c-iop3xx.h
index 53ca1fc9b84c..143548335504 100644
--- a/drivers/i2c/busses/i2c-iop3xx.h
+++ b/drivers/i2c/busses/i2c-iop3xx.h
@@ -92,6 +92,8 @@ struct i2c_algo_iop3xx_data {
92 spinlock_t lock; 92 spinlock_t lock;
93 u32 SR_enabled, SR_received; 93 u32 SR_enabled, SR_received;
94 int id; 94 int id;
95 struct gpio_desc *gpio_scl;
96 struct gpio_desc *gpio_sda;
95}; 97};
96 98
97#endif /* I2C_IOP3XX_H */ 99#endif /* I2C_IOP3XX_H */
diff --git a/drivers/i2c/busses/i2c-mt7621.c b/drivers/i2c/busses/i2c-mt7621.c
new file mode 100644
index 000000000000..62df8379bc89
--- /dev/null
+++ b/drivers/i2c/busses/i2c-mt7621.c
@@ -0,0 +1,356 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * drivers/i2c/busses/i2c-mt7621.c
4 *
5 * Copyright (C) 2013 Steven Liu <steven_liu@mediatek.com>
6 * Copyright (C) 2016 Michael Lee <igvtee@gmail.com>
7 * Copyright (C) 2018 Jan Breuer <jan.breuer@jaybee.cz>
8 *
9 * Improve driver for i2cdetect from i2c-tools to detect i2c devices on the bus.
10 * (C) 2014 Sittisak <sittisaks@hotmail.com>
11 */
12
13#include <linux/clk.h>
14#include <linux/delay.h>
15#include <linux/i2c.h>
16#include <linux/io.h>
17#include <linux/iopoll.h>
18#include <linux/module.h>
19#include <linux/of_platform.h>
20#include <linux/reset.h>
21
22#define REG_SM0CFG2_REG 0x28
23#define REG_SM0CTL0_REG 0x40
24#define REG_SM0CTL1_REG 0x44
25#define REG_SM0D0_REG 0x50
26#define REG_SM0D1_REG 0x54
27#define REG_PINTEN_REG 0x5c
28#define REG_PINTST_REG 0x60
29#define REG_PINTCL_REG 0x64
30
31/* REG_SM0CFG2_REG */
32#define SM0CFG2_IS_AUTOMODE BIT(0)
33
34/* REG_SM0CTL0_REG */
35#define SM0CTL0_ODRAIN BIT(31)
36#define SM0CTL0_CLK_DIV_MASK (0x7ff << 16)
37#define SM0CTL0_CLK_DIV_MAX 0x7ff
38#define SM0CTL0_CS_STATUS BIT(4)
39#define SM0CTL0_SCL_STATE BIT(3)
40#define SM0CTL0_SDA_STATE BIT(2)
41#define SM0CTL0_EN BIT(1)
42#define SM0CTL0_SCL_STRETCH BIT(0)
43
44/* REG_SM0CTL1_REG */
45#define SM0CTL1_ACK_MASK (0xff << 16)
46#define SM0CTL1_PGLEN_MASK (0x7 << 8)
47#define SM0CTL1_PGLEN(x) ((((x) - 1) << 8) & SM0CTL1_PGLEN_MASK)
48#define SM0CTL1_READ (5 << 4)
49#define SM0CTL1_READ_LAST (4 << 4)
50#define SM0CTL1_STOP (3 << 4)
51#define SM0CTL1_WRITE (2 << 4)
52#define SM0CTL1_START (1 << 4)
53#define SM0CTL1_MODE_MASK (0x7 << 4)
54#define SM0CTL1_TRI BIT(0)
55
56/* timeout waiting for I2C devices to respond */
57#define TIMEOUT_MS 1000
58
59struct mtk_i2c {
60 void __iomem *base;
61 struct device *dev;
62 struct i2c_adapter adap;
63 u32 bus_freq;
64 u32 clk_div;
65 u32 flags;
66 struct clk *clk;
67};
68
69static int mtk_i2c_wait_idle(struct mtk_i2c *i2c)
70{
71 int ret;
72 u32 val;
73
74 ret = readl_relaxed_poll_timeout(i2c->base + REG_SM0CTL1_REG,
75 val, !(val & SM0CTL1_TRI),
76 10, TIMEOUT_MS * 1000);
77 if (ret)
78 dev_dbg(i2c->dev, "idle err(%d)\n", ret);
79
80 return ret;
81}
82
83static void mtk_i2c_reset(struct mtk_i2c *i2c)
84{
85 int ret;
86
87 ret = device_reset(i2c->adap.dev.parent);
88 if (ret)
89 dev_err(i2c->dev, "I2C reset failed!\n");
90
91 /*
92 * Don't set SM0CTL0_ODRAIN as its bit meaning is inverted. To
93 * configure open-drain mode, this bit needs to be cleared.
94 */
95 iowrite32(((i2c->clk_div << 16) & SM0CTL0_CLK_DIV_MASK) | SM0CTL0_EN |
96 SM0CTL0_SCL_STRETCH, i2c->base + REG_SM0CTL0_REG);
97 iowrite32(0, i2c->base + REG_SM0CFG2_REG);
98}
99
100static void mtk_i2c_dump_reg(struct mtk_i2c *i2c)
101{
102 dev_dbg(i2c->dev,
103 "SM0CFG2 %08x, SM0CTL0 %08x, SM0CTL1 %08x, SM0D0 %08x, SM0D1 %08x\n",
104 ioread32(i2c->base + REG_SM0CFG2_REG),
105 ioread32(i2c->base + REG_SM0CTL0_REG),
106 ioread32(i2c->base + REG_SM0CTL1_REG),
107 ioread32(i2c->base + REG_SM0D0_REG),
108 ioread32(i2c->base + REG_SM0D1_REG));
109}
110
111static int mtk_i2c_check_ack(struct mtk_i2c *i2c, u32 expected)
112{
113 u32 ack = readl_relaxed(i2c->base + REG_SM0CTL1_REG);
114 u32 ack_expected = (expected << 16) & SM0CTL1_ACK_MASK;
115
116 return ((ack & ack_expected) == ack_expected) ? 0 : -ENXIO;
117}
118
119static int mtk_i2c_master_start(struct mtk_i2c *i2c)
120{
121 iowrite32(SM0CTL1_START | SM0CTL1_TRI, i2c->base + REG_SM0CTL1_REG);
122 return mtk_i2c_wait_idle(i2c);
123}
124
125static int mtk_i2c_master_stop(struct mtk_i2c *i2c)
126{
127 iowrite32(SM0CTL1_STOP | SM0CTL1_TRI, i2c->base + REG_SM0CTL1_REG);
128 return mtk_i2c_wait_idle(i2c);
129}
130
131static int mtk_i2c_master_cmd(struct mtk_i2c *i2c, u32 cmd, int page_len)
132{
133 iowrite32(cmd | SM0CTL1_TRI | SM0CTL1_PGLEN(page_len),
134 i2c->base + REG_SM0CTL1_REG);
135 return mtk_i2c_wait_idle(i2c);
136}
137
138static int mtk_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
139 int num)
140{
141 struct mtk_i2c *i2c;
142 struct i2c_msg *pmsg;
143 u16 addr;
144 int i, j, ret, len, page_len;
145 u32 cmd;
146 u32 data[2];
147
148 i2c = i2c_get_adapdata(adap);
149
150 for (i = 0; i < num; i++) {
151 pmsg = &msgs[i];
152
153 /* wait hardware idle */
154 ret = mtk_i2c_wait_idle(i2c);
155 if (ret)
156 goto err_timeout;
157
158 /* start sequence */
159 ret = mtk_i2c_master_start(i2c);
160 if (ret)
161 goto err_timeout;
162
163 /* write address */
164 if (pmsg->flags & I2C_M_TEN) {
165 /* 10 bits address */
166 addr = 0xf0 | ((pmsg->addr >> 7) & 0x06);
167 addr |= (pmsg->addr & 0xff) << 8;
168 if (pmsg->flags & I2C_M_RD)
169 addr |= 1;
170 iowrite32(addr, i2c->base + REG_SM0D0_REG);
171 ret = mtk_i2c_master_cmd(i2c, SM0CTL1_WRITE, 2);
172 if (ret)
173 goto err_timeout;
174 } else {
175 /* 7 bits address */
176 addr = i2c_8bit_addr_from_msg(pmsg);
177 iowrite32(addr, i2c->base + REG_SM0D0_REG);
178 ret = mtk_i2c_master_cmd(i2c, SM0CTL1_WRITE, 1);
179 if (ret)
180 goto err_timeout;
181 }
182
183 /* check address ACK */
184 if (!(pmsg->flags & I2C_M_IGNORE_NAK)) {
185 ret = mtk_i2c_check_ack(i2c, BIT(0));
186 if (ret)
187 goto err_ack;
188 }
189
190 /* transfer data */
191 for (len = pmsg->len, j = 0; len > 0; len -= 8, j += 8) {
192 page_len = (len >= 8) ? 8 : len;
193
194 if (pmsg->flags & I2C_M_RD) {
195 cmd = (len > 8) ?
196 SM0CTL1_READ : SM0CTL1_READ_LAST;
197 } else {
198 memcpy(data, &pmsg->buf[j], page_len);
199 iowrite32(data[0], i2c->base + REG_SM0D0_REG);
200 iowrite32(data[1], i2c->base + REG_SM0D1_REG);
201 cmd = SM0CTL1_WRITE;
202 }
203
204 ret = mtk_i2c_master_cmd(i2c, cmd, page_len);
205 if (ret)
206 goto err_timeout;
207
208 if (pmsg->flags & I2C_M_RD) {
209 data[0] = ioread32(i2c->base + REG_SM0D0_REG);
210 data[1] = ioread32(i2c->base + REG_SM0D1_REG);
211 memcpy(&pmsg->buf[j], data, page_len);
212 } else {
213 if (!(pmsg->flags & I2C_M_IGNORE_NAK)) {
214 ret = mtk_i2c_check_ack(i2c,
215 (1 << page_len)
216 - 1);
217 if (ret)
218 goto err_ack;
219 }
220 }
221 }
222 }
223
224 ret = mtk_i2c_master_stop(i2c);
225 if (ret)
226 goto err_timeout;
227
228 /* the return value is number of executed messages */
229 return i;
230
231err_ack:
232 ret = mtk_i2c_master_stop(i2c);
233 if (ret)
234 goto err_timeout;
235 return -ENXIO;
236
237err_timeout:
238 mtk_i2c_dump_reg(i2c);
239 mtk_i2c_reset(i2c);
240 return ret;
241}
242
243static u32 mtk_i2c_func(struct i2c_adapter *a)
244{
245 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_PROTOCOL_MANGLING;
246}
247
248static const struct i2c_algorithm mtk_i2c_algo = {
249 .master_xfer = mtk_i2c_master_xfer,
250 .functionality = mtk_i2c_func,
251};
252
253static const struct of_device_id i2c_mtk_dt_ids[] = {
254 { .compatible = "mediatek,mt7621-i2c" },
255 { /* sentinel */ }
256};
257
258MODULE_DEVICE_TABLE(of, i2c_mtk_dt_ids);
259
260static void mtk_i2c_init(struct mtk_i2c *i2c)
261{
262 i2c->clk_div = clk_get_rate(i2c->clk) / i2c->bus_freq - 1;
263 if (i2c->clk_div < 99)
264 i2c->clk_div = 99;
265 if (i2c->clk_div > SM0CTL0_CLK_DIV_MAX)
266 i2c->clk_div = SM0CTL0_CLK_DIV_MAX;
267
268 mtk_i2c_reset(i2c);
269}
270
271static int mtk_i2c_probe(struct platform_device *pdev)
272{
273 struct resource *res;
274 struct mtk_i2c *i2c;
275 struct i2c_adapter *adap;
276 int ret;
277
278 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
279
280 i2c = devm_kzalloc(&pdev->dev, sizeof(struct mtk_i2c), GFP_KERNEL);
281 if (!i2c)
282 return -ENOMEM;
283
284 i2c->base = devm_ioremap_resource(&pdev->dev, res);
285 if (IS_ERR(i2c->base))
286 return PTR_ERR(i2c->base);
287
288 i2c->clk = devm_clk_get(&pdev->dev, NULL);
289 if (IS_ERR(i2c->clk)) {
290 dev_err(&pdev->dev, "no clock defined\n");
291 return PTR_ERR(i2c->clk);
292 }
293 ret = clk_prepare_enable(i2c->clk);
294 if (ret) {
295 dev_err(&pdev->dev, "Unable to enable clock\n");
296 return ret;
297 }
298
299 i2c->dev = &pdev->dev;
300
301 if (of_property_read_u32(pdev->dev.of_node, "clock-frequency",
302 &i2c->bus_freq))
303 i2c->bus_freq = 100000;
304
305 if (i2c->bus_freq == 0) {
306 dev_warn(i2c->dev, "clock-frequency 0 not supported\n");
307 return -EINVAL;
308 }
309
310 adap = &i2c->adap;
311 adap->owner = THIS_MODULE;
312 adap->algo = &mtk_i2c_algo;
313 adap->retries = 3;
314 adap->dev.parent = &pdev->dev;
315 i2c_set_adapdata(adap, i2c);
316 adap->dev.of_node = pdev->dev.of_node;
317 strlcpy(adap->name, dev_name(&pdev->dev), sizeof(adap->name));
318
319 platform_set_drvdata(pdev, i2c);
320
321 mtk_i2c_init(i2c);
322
323 ret = i2c_add_adapter(adap);
324 if (ret < 0)
325 return ret;
326
327 dev_info(&pdev->dev, "clock %u kHz\n", i2c->bus_freq / 1000);
328
329 return ret;
330}
331
332static int mtk_i2c_remove(struct platform_device *pdev)
333{
334 struct mtk_i2c *i2c = platform_get_drvdata(pdev);
335
336 clk_disable_unprepare(i2c->clk);
337 i2c_del_adapter(&i2c->adap);
338
339 return 0;
340}
341
342static struct platform_driver mtk_i2c_driver = {
343 .probe = mtk_i2c_probe,
344 .remove = mtk_i2c_remove,
345 .driver = {
346 .name = "i2c-mt7621",
347 .of_match_table = i2c_mtk_dt_ids,
348 },
349};
350
351module_platform_driver(mtk_i2c_driver);
352
353MODULE_AUTHOR("Steven Liu");
354MODULE_DESCRIPTION("MT7621 I2C host driver");
355MODULE_LICENSE("GPL v2");
356MODULE_ALIAS("platform:MT7621-I2C");
diff --git a/drivers/i2c/busses/i2c-nvidia-gpu.c b/drivers/i2c/busses/i2c-nvidia-gpu.c
index 1c8f708f212b..cfc76b5de726 100644
--- a/drivers/i2c/busses/i2c-nvidia-gpu.c
+++ b/drivers/i2c/busses/i2c-nvidia-gpu.c
@@ -51,6 +51,7 @@ struct gpu_i2c_dev {
51 void __iomem *regs; 51 void __iomem *regs;
52 struct i2c_adapter adapter; 52 struct i2c_adapter adapter;
53 struct i2c_board_info *gpu_ccgx_ucsi; 53 struct i2c_board_info *gpu_ccgx_ucsi;
54 struct i2c_client *ccgx_client;
54}; 55};
55 56
56static void gpu_enable_i2c_bus(struct gpu_i2c_dev *i2cd) 57static void gpu_enable_i2c_bus(struct gpu_i2c_dev *i2cd)
@@ -169,12 +170,14 @@ static int gpu_i2c_master_xfer(struct i2c_adapter *adap,
169{ 170{
170 struct gpu_i2c_dev *i2cd = i2c_get_adapdata(adap); 171 struct gpu_i2c_dev *i2cd = i2c_get_adapdata(adap);
171 int status, status2; 172 int status, status2;
173 bool send_stop = true;
172 int i, j; 174 int i, j;
173 175
174 /* 176 /*
175 * The controller supports maximum 4 byte read due to known 177 * The controller supports maximum 4 byte read due to known
176 * limitation of sending STOP after every read. 178 * limitation of sending STOP after every read.
177 */ 179 */
180 pm_runtime_get_sync(i2cd->dev);
178 for (i = 0; i < num; i++) { 181 for (i = 0; i < num; i++) {
179 if (msgs[i].flags & I2C_M_RD) { 182 if (msgs[i].flags & I2C_M_RD) {
180 /* program client address before starting read */ 183 /* program client address before starting read */
@@ -182,37 +185,42 @@ static int gpu_i2c_master_xfer(struct i2c_adapter *adap,
182 /* gpu_i2c_read has implicit start */ 185 /* gpu_i2c_read has implicit start */
183 status = gpu_i2c_read(i2cd, msgs[i].buf, msgs[i].len); 186 status = gpu_i2c_read(i2cd, msgs[i].buf, msgs[i].len);
184 if (status < 0) 187 if (status < 0)
185 goto stop; 188 goto exit;
186 } else { 189 } else {
187 u8 addr = i2c_8bit_addr_from_msg(msgs + i); 190 u8 addr = i2c_8bit_addr_from_msg(msgs + i);
188 191
189 status = gpu_i2c_start(i2cd); 192 status = gpu_i2c_start(i2cd);
190 if (status < 0) { 193 if (status < 0) {
191 if (i == 0) 194 if (i == 0)
192 return status; 195 send_stop = false;
193 goto stop; 196 goto exit;
194 } 197 }
195 198
196 status = gpu_i2c_write(i2cd, addr); 199 status = gpu_i2c_write(i2cd, addr);
197 if (status < 0) 200 if (status < 0)
198 goto stop; 201 goto exit;
199 202
200 for (j = 0; j < msgs[i].len; j++) { 203 for (j = 0; j < msgs[i].len; j++) {
201 status = gpu_i2c_write(i2cd, msgs[i].buf[j]); 204 status = gpu_i2c_write(i2cd, msgs[i].buf[j]);
202 if (status < 0) 205 if (status < 0)
203 goto stop; 206 goto exit;
204 } 207 }
205 } 208 }
206 } 209 }
210 send_stop = false;
207 status = gpu_i2c_stop(i2cd); 211 status = gpu_i2c_stop(i2cd);
208 if (status < 0) 212 if (status < 0)
209 return status; 213 goto exit;
210 214
211 return i; 215 status = i;
212stop: 216exit:
213 status2 = gpu_i2c_stop(i2cd); 217 if (send_stop) {
214 if (status2 < 0) 218 status2 = gpu_i2c_stop(i2cd);
215 dev_err(i2cd->dev, "i2c stop failed %d\n", status2); 219 if (status2 < 0)
220 dev_err(i2cd->dev, "i2c stop failed %d\n", status2);
221 }
222 pm_runtime_mark_last_busy(i2cd->dev);
223 pm_runtime_put_autosuspend(i2cd->dev);
216 return status; 224 return status;
217} 225}
218 226
@@ -261,8 +269,6 @@ static const struct property_entry ccgx_props[] = {
261 269
262static int gpu_populate_client(struct gpu_i2c_dev *i2cd, int irq) 270static int gpu_populate_client(struct gpu_i2c_dev *i2cd, int irq)
263{ 271{
264 struct i2c_client *ccgx_client;
265
266 i2cd->gpu_ccgx_ucsi = devm_kzalloc(i2cd->dev, 272 i2cd->gpu_ccgx_ucsi = devm_kzalloc(i2cd->dev,
267 sizeof(*i2cd->gpu_ccgx_ucsi), 273 sizeof(*i2cd->gpu_ccgx_ucsi),
268 GFP_KERNEL); 274 GFP_KERNEL);
@@ -274,8 +280,8 @@ static int gpu_populate_client(struct gpu_i2c_dev *i2cd, int irq)
274 i2cd->gpu_ccgx_ucsi->addr = 0x8; 280 i2cd->gpu_ccgx_ucsi->addr = 0x8;
275 i2cd->gpu_ccgx_ucsi->irq = irq; 281 i2cd->gpu_ccgx_ucsi->irq = irq;
276 i2cd->gpu_ccgx_ucsi->properties = ccgx_props; 282 i2cd->gpu_ccgx_ucsi->properties = ccgx_props;
277 ccgx_client = i2c_new_device(&i2cd->adapter, i2cd->gpu_ccgx_ucsi); 283 i2cd->ccgx_client = i2c_new_device(&i2cd->adapter, i2cd->gpu_ccgx_ucsi);
278 if (!ccgx_client) 284 if (!i2cd->ccgx_client)
279 return -ENODEV; 285 return -ENODEV;
280 286
281 return 0; 287 return 0;
@@ -332,6 +338,11 @@ static int gpu_i2c_probe(struct pci_dev *pdev, const struct pci_device_id *id)
332 goto del_adapter; 338 goto del_adapter;
333 } 339 }
334 340
341 pm_runtime_set_autosuspend_delay(&pdev->dev, 3000);
342 pm_runtime_use_autosuspend(&pdev->dev);
343 pm_runtime_put_autosuspend(&pdev->dev);
344 pm_runtime_allow(&pdev->dev);
345
335 return 0; 346 return 0;
336 347
337del_adapter: 348del_adapter:
@@ -345,19 +356,38 @@ static void gpu_i2c_remove(struct pci_dev *pdev)
345{ 356{
346 struct gpu_i2c_dev *i2cd = dev_get_drvdata(&pdev->dev); 357 struct gpu_i2c_dev *i2cd = dev_get_drvdata(&pdev->dev);
347 358
359 pm_runtime_get_noresume(i2cd->dev);
348 i2c_del_adapter(&i2cd->adapter); 360 i2c_del_adapter(&i2cd->adapter);
349 pci_free_irq_vectors(pdev); 361 pci_free_irq_vectors(pdev);
350} 362}
351 363
364/*
365 * We need gpu_i2c_suspend() even if it is stub, for runtime pm to work
366 * correctly. Without it, lspci shows runtime pm status as "D0" for the card.
367 * Documentation/power/pci.txt also insists for driver to provide this.
368 */
369static __maybe_unused int gpu_i2c_suspend(struct device *dev)
370{
371 return 0;
372}
373
352static __maybe_unused int gpu_i2c_resume(struct device *dev) 374static __maybe_unused int gpu_i2c_resume(struct device *dev)
353{ 375{
354 struct gpu_i2c_dev *i2cd = dev_get_drvdata(dev); 376 struct gpu_i2c_dev *i2cd = dev_get_drvdata(dev);
355 377
356 gpu_enable_i2c_bus(i2cd); 378 gpu_enable_i2c_bus(i2cd);
379 /*
380 * Runtime resume ccgx client so that it can see for any
381 * connector change event. Old ccg firmware has known
382 * issue of not triggering interrupt when a device is
383 * connected to runtime resume the controller.
384 */
385 pm_request_resume(&i2cd->ccgx_client->dev);
357 return 0; 386 return 0;
358} 387}
359 388
360static UNIVERSAL_DEV_PM_OPS(gpu_i2c_driver_pm, NULL, gpu_i2c_resume, NULL); 389static UNIVERSAL_DEV_PM_OPS(gpu_i2c_driver_pm, gpu_i2c_suspend, gpu_i2c_resume,
390 NULL);
361 391
362static struct pci_driver gpu_i2c_driver = { 392static struct pci_driver gpu_i2c_driver = {
363 .name = "nvidia-gpu", 393 .name = "nvidia-gpu",
diff --git a/drivers/i2c/busses/i2c-ocores.c b/drivers/i2c/busses/i2c-ocores.c
index c3dabee0aa35..4117f1abc7c6 100644
--- a/drivers/i2c/busses/i2c-ocores.c
+++ b/drivers/i2c/busses/i2c-ocores.c
@@ -35,6 +35,7 @@ struct ocores_i2c {
35 int iobase; 35 int iobase;
36 u32 reg_shift; 36 u32 reg_shift;
37 u32 reg_io_width; 37 u32 reg_io_width;
38 unsigned long flags;
38 wait_queue_head_t wait; 39 wait_queue_head_t wait;
39 struct i2c_adapter adap; 40 struct i2c_adapter adap;
40 struct i2c_msg *msg; 41 struct i2c_msg *msg;
@@ -82,6 +83,9 @@ struct ocores_i2c {
82 83
83#define TYPE_OCORES 0 84#define TYPE_OCORES 0
84#define TYPE_GRLIB 1 85#define TYPE_GRLIB 1
86#define TYPE_SIFIVE_REV0 2
87
88#define OCORES_FLAG_BROKEN_IRQ BIT(1) /* Broken IRQ for FU540-C000 SoC */
85 89
86static void oc_setreg_8(struct ocores_i2c *i2c, int reg, u8 value) 90static void oc_setreg_8(struct ocores_i2c *i2c, int reg, u8 value)
87{ 91{
@@ -235,9 +239,12 @@ static irqreturn_t ocores_isr(int irq, void *dev_id)
235 struct ocores_i2c *i2c = dev_id; 239 struct ocores_i2c *i2c = dev_id;
236 u8 stat = oc_getreg(i2c, OCI2C_STATUS); 240 u8 stat = oc_getreg(i2c, OCI2C_STATUS);
237 241
238 if (!(stat & OCI2C_STAT_IF)) 242 if (i2c->flags & OCORES_FLAG_BROKEN_IRQ) {
243 if ((stat & OCI2C_STAT_IF) && !(stat & OCI2C_STAT_BUSY))
244 return IRQ_NONE;
245 } else if (!(stat & OCI2C_STAT_IF)) {
239 return IRQ_NONE; 246 return IRQ_NONE;
240 247 }
241 ocores_process(i2c, stat); 248 ocores_process(i2c, stat);
242 249
243 return IRQ_HANDLED; 250 return IRQ_HANDLED;
@@ -352,6 +359,11 @@ static void ocores_process_polling(struct ocores_i2c *i2c)
352 ret = ocores_isr(-1, i2c); 359 ret = ocores_isr(-1, i2c);
353 if (ret == IRQ_NONE) 360 if (ret == IRQ_NONE)
354 break; /* all messages have been transferred */ 361 break; /* all messages have been transferred */
362 else {
363 if (i2c->flags & OCORES_FLAG_BROKEN_IRQ)
364 if (i2c->state == STATE_DONE)
365 break;
366 }
355 } 367 }
356} 368}
357 369
@@ -462,6 +474,14 @@ static const struct of_device_id ocores_i2c_match[] = {
462 .compatible = "aeroflexgaisler,i2cmst", 474 .compatible = "aeroflexgaisler,i2cmst",
463 .data = (void *)TYPE_GRLIB, 475 .data = (void *)TYPE_GRLIB,
464 }, 476 },
477 {
478 .compatible = "sifive,fu540-c000-i2c",
479 .data = (void *)TYPE_SIFIVE_REV0,
480 },
481 {
482 .compatible = "sifive,i2c0",
483 .data = (void *)TYPE_SIFIVE_REV0,
484 },
465 {}, 485 {},
466}; 486};
467MODULE_DEVICE_TABLE(of, ocores_i2c_match); 487MODULE_DEVICE_TABLE(of, ocores_i2c_match);
@@ -586,6 +606,7 @@ static int ocores_i2c_probe(struct platform_device *pdev)
586{ 606{
587 struct ocores_i2c *i2c; 607 struct ocores_i2c *i2c;
588 struct ocores_i2c_platform_data *pdata; 608 struct ocores_i2c_platform_data *pdata;
609 const struct of_device_id *match;
589 struct resource *res; 610 struct resource *res;
590 int irq; 611 int irq;
591 int ret; 612 int ret;
@@ -668,6 +689,14 @@ static int ocores_i2c_probe(struct platform_device *pdev)
668 irq = platform_get_irq(pdev, 0); 689 irq = platform_get_irq(pdev, 0);
669 if (irq == -ENXIO) { 690 if (irq == -ENXIO) {
670 ocores_algorithm.master_xfer = ocores_xfer_polling; 691 ocores_algorithm.master_xfer = ocores_xfer_polling;
692
693 /*
694 * Set in OCORES_FLAG_BROKEN_IRQ to enable workaround for
695 * FU540-C000 SoC in polling mode.
696 */
697 match = of_match_node(ocores_i2c_match, pdev->dev.of_node);
698 if (match && (long)match->data == TYPE_SIFIVE_REV0)
699 i2c->flags |= OCORES_FLAG_BROKEN_IRQ;
671 } else { 700 } else {
672 if (irq < 0) 701 if (irq < 0)
673 return irq; 702 return irq;
diff --git a/drivers/i2c/busses/i2c-qcom-geni.c b/drivers/i2c/busses/i2c-qcom-geni.c
index db075bc0d952..a89bfce5388e 100644
--- a/drivers/i2c/busses/i2c-qcom-geni.c
+++ b/drivers/i2c/busses/i2c-qcom-geni.c
@@ -1,6 +1,7 @@
1// SPDX-License-Identifier: GPL-2.0 1// SPDX-License-Identifier: GPL-2.0
2// Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. 2// Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.
3 3
4#include <linux/acpi.h>
4#include <linux/clk.h> 5#include <linux/clk.h>
5#include <linux/dma-mapping.h> 6#include <linux/dma-mapping.h>
6#include <linux/err.h> 7#include <linux/err.h>
@@ -483,6 +484,14 @@ static const struct i2c_algorithm geni_i2c_algo = {
483 .functionality = geni_i2c_func, 484 .functionality = geni_i2c_func,
484}; 485};
485 486
487#ifdef CONFIG_ACPI
488static const struct acpi_device_id geni_i2c_acpi_match[] = {
489 { "QCOM0220"},
490 { },
491};
492MODULE_DEVICE_TABLE(acpi, geni_i2c_acpi_match);
493#endif
494
486static int geni_i2c_probe(struct platform_device *pdev) 495static int geni_i2c_probe(struct platform_device *pdev)
487{ 496{
488 struct geni_i2c_dev *gi2c; 497 struct geni_i2c_dev *gi2c;
@@ -502,7 +511,7 @@ static int geni_i2c_probe(struct platform_device *pdev)
502 return PTR_ERR(gi2c->se.base); 511 return PTR_ERR(gi2c->se.base);
503 512
504 gi2c->se.clk = devm_clk_get(&pdev->dev, "se"); 513 gi2c->se.clk = devm_clk_get(&pdev->dev, "se");
505 if (IS_ERR(gi2c->se.clk)) { 514 if (IS_ERR(gi2c->se.clk) && !has_acpi_companion(&pdev->dev)) {
506 ret = PTR_ERR(gi2c->se.clk); 515 ret = PTR_ERR(gi2c->se.clk);
507 dev_err(&pdev->dev, "Err getting SE Core clk %d\n", ret); 516 dev_err(&pdev->dev, "Err getting SE Core clk %d\n", ret);
508 return ret; 517 return ret;
@@ -516,6 +525,9 @@ static int geni_i2c_probe(struct platform_device *pdev)
516 gi2c->clk_freq_out = KHZ(100); 525 gi2c->clk_freq_out = KHZ(100);
517 } 526 }
518 527
528 if (has_acpi_companion(&pdev->dev))
529 ACPI_COMPANION_SET(&gi2c->adap.dev, ACPI_COMPANION(&pdev->dev));
530
519 gi2c->irq = platform_get_irq(pdev, 0); 531 gi2c->irq = platform_get_irq(pdev, 0);
520 if (gi2c->irq < 0) { 532 if (gi2c->irq < 0) {
521 dev_err(&pdev->dev, "IRQ error for i2c-geni\n"); 533 dev_err(&pdev->dev, "IRQ error for i2c-geni\n");
@@ -584,6 +596,8 @@ static int geni_i2c_probe(struct platform_device *pdev)
584 return ret; 596 return ret;
585 } 597 }
586 598
599 dev_dbg(&pdev->dev, "Geni-I2C adaptor successfully added\n");
600
587 return 0; 601 return 0;
588} 602}
589 603
@@ -660,6 +674,7 @@ static struct platform_driver geni_i2c_driver = {
660 .name = "geni_i2c", 674 .name = "geni_i2c",
661 .pm = &geni_i2c_pm_ops, 675 .pm = &geni_i2c_pm_ops,
662 .of_match_table = geni_i2c_dt_match, 676 .of_match_table = geni_i2c_dt_match,
677 .acpi_match_table = ACPI_PTR(geni_i2c_acpi_match),
663 }, 678 },
664}; 679};
665 680
diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c
index c9510d085c34..d97fb857b0ea 100644
--- a/drivers/i2c/busses/i2c-s3c2410.c
+++ b/drivers/i2c/busses/i2c-s3c2410.c
@@ -24,7 +24,7 @@
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/io.h> 25#include <linux/io.h>
26#include <linux/of.h> 26#include <linux/of.h>
27#include <linux/of_gpio.h> 27#include <linux/gpio/consumer.h>
28#include <linux/pinctrl/consumer.h> 28#include <linux/pinctrl/consumer.h>
29#include <linux/mfd/syscon.h> 29#include <linux/mfd/syscon.h>
30#include <linux/regmap.h> 30#include <linux/regmap.h>
@@ -113,7 +113,7 @@ struct s3c24xx_i2c {
113 struct i2c_adapter adap; 113 struct i2c_adapter adap;
114 114
115 struct s3c2410_platform_i2c *pdata; 115 struct s3c2410_platform_i2c *pdata;
116 int gpios[2]; 116 struct gpio_desc *gpios[2];
117 struct pinctrl *pctrl; 117 struct pinctrl *pctrl;
118#if defined(CONFIG_ARM_S3C24XX_CPUFREQ) 118#if defined(CONFIG_ARM_S3C24XX_CPUFREQ)
119 struct notifier_block freq_transition; 119 struct notifier_block freq_transition;
@@ -947,53 +947,27 @@ static inline void s3c24xx_i2c_deregister_cpufreq(struct s3c24xx_i2c *i2c)
947#ifdef CONFIG_OF 947#ifdef CONFIG_OF
948static int s3c24xx_i2c_parse_dt_gpio(struct s3c24xx_i2c *i2c) 948static int s3c24xx_i2c_parse_dt_gpio(struct s3c24xx_i2c *i2c)
949{ 949{
950 int idx, gpio, ret; 950 int i;
951 951
952 if (i2c->quirks & QUIRK_NO_GPIO) 952 if (i2c->quirks & QUIRK_NO_GPIO)
953 return 0; 953 return 0;
954 954
955 for (idx = 0; idx < 2; idx++) { 955 for (i = 0; i < 2; i++) {
956 gpio = of_get_gpio(i2c->dev->of_node, idx); 956 i2c->gpios[i] = devm_gpiod_get_index(i2c->dev, NULL,
957 if (!gpio_is_valid(gpio)) { 957 i, GPIOD_ASIS);
958 dev_err(i2c->dev, "invalid gpio[%d]: %d\n", idx, gpio); 958 if (IS_ERR(i2c->gpios[i])) {
959 goto free_gpio; 959 dev_err(i2c->dev, "i2c gpio invalid at index %d\n", i);
960 } 960 return -EINVAL;
961 i2c->gpios[idx] = gpio;
962
963 ret = gpio_request(gpio, "i2c-bus");
964 if (ret) {
965 dev_err(i2c->dev, "gpio [%d] request failed (%d)\n",
966 gpio, ret);
967 goto free_gpio;
968 } 961 }
969 } 962 }
970 return 0; 963 return 0;
971
972free_gpio:
973 while (--idx >= 0)
974 gpio_free(i2c->gpios[idx]);
975 return -EINVAL;
976} 964}
977 965
978static void s3c24xx_i2c_dt_gpio_free(struct s3c24xx_i2c *i2c)
979{
980 unsigned int idx;
981
982 if (i2c->quirks & QUIRK_NO_GPIO)
983 return;
984
985 for (idx = 0; idx < 2; idx++)
986 gpio_free(i2c->gpios[idx]);
987}
988#else 966#else
989static int s3c24xx_i2c_parse_dt_gpio(struct s3c24xx_i2c *i2c) 967static int s3c24xx_i2c_parse_dt_gpio(struct s3c24xx_i2c *i2c)
990{ 968{
991 return 0; 969 return 0;
992} 970}
993
994static void s3c24xx_i2c_dt_gpio_free(struct s3c24xx_i2c *i2c)
995{
996}
997#endif 971#endif
998 972
999/* 973/*
@@ -1222,9 +1196,6 @@ static int s3c24xx_i2c_remove(struct platform_device *pdev)
1222 1196
1223 i2c_del_adapter(&i2c->adap); 1197 i2c_del_adapter(&i2c->adap);
1224 1198
1225 if (pdev->dev.of_node && IS_ERR(i2c->pctrl))
1226 s3c24xx_i2c_dt_gpio_free(i2c);
1227
1228 return 0; 1199 return 0;
1229} 1200}
1230 1201
diff --git a/drivers/i2c/busses/i2c-stm32f7.c b/drivers/i2c/busses/i2c-stm32f7.c
index 48337bef5b87..266d1c269b83 100644
--- a/drivers/i2c/busses/i2c-stm32f7.c
+++ b/drivers/i2c/busses/i2c-stm32f7.c
@@ -25,7 +25,6 @@
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/of.h> 26#include <linux/of.h>
27#include <linux/of_address.h> 27#include <linux/of_address.h>
28#include <linux/of_irq.h>
29#include <linux/of_platform.h> 28#include <linux/of_platform.h>
30#include <linux/platform_device.h> 29#include <linux/platform_device.h>
31#include <linux/pinctrl/consumer.h> 30#include <linux/pinctrl/consumer.h>
@@ -953,6 +952,9 @@ static int stm32f7_i2c_smbus_xfer_msg(struct stm32f7_i2c_dev *i2c_dev,
953 cr2 &= ~STM32F7_I2C_CR2_RD_WRN; 952 cr2 &= ~STM32F7_I2C_CR2_RD_WRN;
954 f7_msg->read_write = I2C_SMBUS_READ; 953 f7_msg->read_write = I2C_SMBUS_READ;
955 break; 954 break;
955 case I2C_SMBUS_I2C_BLOCK_DATA:
956 /* Rely on emulated i2c transfer (through master_xfer) */
957 return -EOPNOTSUPP;
956 default: 958 default:
957 dev_err(dev, "Unsupported smbus protocol %d\n", f7_msg->size); 959 dev_err(dev, "Unsupported smbus protocol %d\n", f7_msg->size);
958 return -EOPNOTSUPP; 960 return -EOPNOTSUPP;
@@ -1803,7 +1805,8 @@ static u32 stm32f7_i2c_func(struct i2c_adapter *adap)
1803 I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | 1805 I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
1804 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | 1806 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
1805 I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_BLOCK_PROC_CALL | 1807 I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_BLOCK_PROC_CALL |
1806 I2C_FUNC_SMBUS_PROC_CALL | I2C_FUNC_SMBUS_PEC; 1808 I2C_FUNC_SMBUS_PROC_CALL | I2C_FUNC_SMBUS_PEC |
1809 I2C_FUNC_SMBUS_I2C_BLOCK;
1807} 1810}
1808 1811
1809static struct i2c_algorithm stm32f7_i2c_algo = { 1812static struct i2c_algorithm stm32f7_i2c_algo = {
@@ -1816,15 +1819,14 @@ static struct i2c_algorithm stm32f7_i2c_algo = {
1816 1819
1817static int stm32f7_i2c_probe(struct platform_device *pdev) 1820static int stm32f7_i2c_probe(struct platform_device *pdev)
1818{ 1821{
1819 struct device_node *np = pdev->dev.of_node;
1820 struct stm32f7_i2c_dev *i2c_dev; 1822 struct stm32f7_i2c_dev *i2c_dev;
1821 const struct stm32f7_i2c_setup *setup; 1823 const struct stm32f7_i2c_setup *setup;
1822 struct resource *res; 1824 struct resource *res;
1823 u32 irq_error, irq_event, clk_rate, rise_time, fall_time; 1825 u32 clk_rate, rise_time, fall_time;
1824 struct i2c_adapter *adap; 1826 struct i2c_adapter *adap;
1825 struct reset_control *rst; 1827 struct reset_control *rst;
1826 dma_addr_t phy_addr; 1828 dma_addr_t phy_addr;
1827 int ret; 1829 int irq_error, irq_event, ret;
1828 1830
1829 i2c_dev = devm_kzalloc(&pdev->dev, sizeof(*i2c_dev), GFP_KERNEL); 1831 i2c_dev = devm_kzalloc(&pdev->dev, sizeof(*i2c_dev), GFP_KERNEL);
1830 if (!i2c_dev) 1832 if (!i2c_dev)
@@ -1836,16 +1838,20 @@ static int stm32f7_i2c_probe(struct platform_device *pdev)
1836 return PTR_ERR(i2c_dev->base); 1838 return PTR_ERR(i2c_dev->base);
1837 phy_addr = (dma_addr_t)res->start; 1839 phy_addr = (dma_addr_t)res->start;
1838 1840
1839 irq_event = irq_of_parse_and_map(np, 0); 1841 irq_event = platform_get_irq(pdev, 0);
1840 if (!irq_event) { 1842 if (irq_event <= 0) {
1841 dev_err(&pdev->dev, "IRQ event missing or invalid\n"); 1843 if (irq_event != -EPROBE_DEFER)
1842 return -EINVAL; 1844 dev_err(&pdev->dev, "Failed to get IRQ event: %d\n",
1845 irq_event);
1846 return irq_event ? : -ENOENT;
1843 } 1847 }
1844 1848
1845 irq_error = irq_of_parse_and_map(np, 1); 1849 irq_error = platform_get_irq(pdev, 1);
1846 if (!irq_error) { 1850 if (irq_error <= 0) {
1847 dev_err(&pdev->dev, "IRQ error missing or invalid\n"); 1851 if (irq_error != -EPROBE_DEFER)
1848 return -EINVAL; 1852 dev_err(&pdev->dev, "Failed to get IRQ error: %d\n",
1853 irq_error);
1854 return irq_error ? : -ENOENT;
1849 } 1855 }
1850 1856
1851 i2c_dev->clk = devm_clk_get(&pdev->dev, NULL); 1857 i2c_dev->clk = devm_clk_get(&pdev->dev, NULL);
diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c
index ebaa78d17d6e..9fcb13beeb8f 100644
--- a/drivers/i2c/busses/i2c-tegra.c
+++ b/drivers/i2c/busses/i2c-tegra.c
@@ -54,20 +54,15 @@
54#define I2C_INT_STATUS 0x068 54#define I2C_INT_STATUS 0x068
55#define I2C_INT_BUS_CLR_DONE BIT(11) 55#define I2C_INT_BUS_CLR_DONE BIT(11)
56#define I2C_INT_PACKET_XFER_COMPLETE BIT(7) 56#define I2C_INT_PACKET_XFER_COMPLETE BIT(7)
57#define I2C_INT_ALL_PACKETS_XFER_COMPLETE BIT(6)
58#define I2C_INT_TX_FIFO_OVERFLOW BIT(5)
59#define I2C_INT_RX_FIFO_UNDERFLOW BIT(4)
60#define I2C_INT_NO_ACK BIT(3) 57#define I2C_INT_NO_ACK BIT(3)
61#define I2C_INT_ARBITRATION_LOST BIT(2) 58#define I2C_INT_ARBITRATION_LOST BIT(2)
62#define I2C_INT_TX_FIFO_DATA_REQ BIT(1) 59#define I2C_INT_TX_FIFO_DATA_REQ BIT(1)
63#define I2C_INT_RX_FIFO_DATA_REQ BIT(0) 60#define I2C_INT_RX_FIFO_DATA_REQ BIT(0)
64#define I2C_CLK_DIVISOR 0x06c 61#define I2C_CLK_DIVISOR 0x06c
65#define I2C_CLK_DIVISOR_STD_FAST_MODE_SHIFT 16 62#define I2C_CLK_DIVISOR_STD_FAST_MODE_SHIFT 16
66#define I2C_CLK_MULTIPLIER_STD_FAST_MODE 8
67 63
68#define DVC_CTRL_REG1 0x000 64#define DVC_CTRL_REG1 0x000
69#define DVC_CTRL_REG1_INTR_EN BIT(10) 65#define DVC_CTRL_REG1_INTR_EN BIT(10)
70#define DVC_CTRL_REG2 0x004
71#define DVC_CTRL_REG3 0x008 66#define DVC_CTRL_REG3 0x008
72#define DVC_CTRL_REG3_SW_PROG BIT(26) 67#define DVC_CTRL_REG3_SW_PROG BIT(26)
73#define DVC_CTRL_REG3_I2C_DONE_INTR_EN BIT(30) 68#define DVC_CTRL_REG3_I2C_DONE_INTR_EN BIT(30)
@@ -75,24 +70,22 @@
75#define DVC_STATUS_I2C_DONE_INTR BIT(30) 70#define DVC_STATUS_I2C_DONE_INTR BIT(30)
76 71
77#define I2C_ERR_NONE 0x00 72#define I2C_ERR_NONE 0x00
78#define I2C_ERR_NO_ACK 0x01 73#define I2C_ERR_NO_ACK BIT(0)
79#define I2C_ERR_ARBITRATION_LOST 0x02 74#define I2C_ERR_ARBITRATION_LOST BIT(1)
80#define I2C_ERR_UNKNOWN_INTERRUPT 0x04 75#define I2C_ERR_UNKNOWN_INTERRUPT BIT(2)
76#define I2C_ERR_RX_BUFFER_OVERFLOW BIT(3)
81 77
82#define PACKET_HEADER0_HEADER_SIZE_SHIFT 28 78#define PACKET_HEADER0_HEADER_SIZE_SHIFT 28
83#define PACKET_HEADER0_PACKET_ID_SHIFT 16 79#define PACKET_HEADER0_PACKET_ID_SHIFT 16
84#define PACKET_HEADER0_CONT_ID_SHIFT 12 80#define PACKET_HEADER0_CONT_ID_SHIFT 12
85#define PACKET_HEADER0_PROTOCOL_I2C BIT(4) 81#define PACKET_HEADER0_PROTOCOL_I2C BIT(4)
86 82
87#define I2C_HEADER_HIGHSPEED_MODE BIT(22)
88#define I2C_HEADER_CONT_ON_NAK BIT(21) 83#define I2C_HEADER_CONT_ON_NAK BIT(21)
89#define I2C_HEADER_SEND_START_BYTE BIT(20)
90#define I2C_HEADER_READ BIT(19) 84#define I2C_HEADER_READ BIT(19)
91#define I2C_HEADER_10BIT_ADDR BIT(18) 85#define I2C_HEADER_10BIT_ADDR BIT(18)
92#define I2C_HEADER_IE_ENABLE BIT(17) 86#define I2C_HEADER_IE_ENABLE BIT(17)
93#define I2C_HEADER_REPEAT_START BIT(16) 87#define I2C_HEADER_REPEAT_START BIT(16)
94#define I2C_HEADER_CONTINUE_XFER BIT(15) 88#define I2C_HEADER_CONTINUE_XFER BIT(15)
95#define I2C_HEADER_MASTER_ADDR_SHIFT 12
96#define I2C_HEADER_SLAVE_ADDR_SHIFT 1 89#define I2C_HEADER_SLAVE_ADDR_SHIFT 1
97 90
98#define I2C_BUS_CLEAR_CNFG 0x084 91#define I2C_BUS_CLEAR_CNFG 0x084
@@ -106,8 +99,6 @@
106 99
107#define I2C_CONFIG_LOAD 0x08C 100#define I2C_CONFIG_LOAD 0x08C
108#define I2C_MSTR_CONFIG_LOAD BIT(0) 101#define I2C_MSTR_CONFIG_LOAD BIT(0)
109#define I2C_SLV_CONFIG_LOAD BIT(1)
110#define I2C_TIMEOUT_CONFIG_LOAD BIT(2)
111 102
112#define I2C_CLKEN_OVERRIDE 0x090 103#define I2C_CLKEN_OVERRIDE 0x090
113#define I2C_MST_CORE_CLKEN_OVR BIT(0) 104#define I2C_MST_CORE_CLKEN_OVR BIT(0)
@@ -133,7 +124,6 @@
133#define I2C_STANDARD_MODE 100000 124#define I2C_STANDARD_MODE 100000
134#define I2C_FAST_MODE 400000 125#define I2C_FAST_MODE 400000
135#define I2C_FAST_PLUS_MODE 1000000 126#define I2C_FAST_PLUS_MODE 1000000
136#define I2C_HS_MODE 3500000
137 127
138/* Packet header size in bytes */ 128/* Packet header size in bytes */
139#define I2C_PACKET_HEADER_SIZE 12 129#define I2C_PACKET_HEADER_SIZE 12
@@ -280,6 +270,7 @@ struct tegra_i2c_dev {
280 u32 bus_clk_rate; 270 u32 bus_clk_rate;
281 u16 clk_divisor_non_hs_mode; 271 u16 clk_divisor_non_hs_mode;
282 bool is_multimaster_mode; 272 bool is_multimaster_mode;
273 /* xfer_lock: lock to serialize transfer submission and processing */
283 spinlock_t xfer_lock; 274 spinlock_t xfer_lock;
284 struct dma_chan *tx_dma_chan; 275 struct dma_chan *tx_dma_chan;
285 struct dma_chan *rx_dma_chan; 276 struct dma_chan *rx_dma_chan;
@@ -306,7 +297,7 @@ static u32 dvc_readl(struct tegra_i2c_dev *i2c_dev, unsigned long reg)
306 * to the I2C block inside the DVC block 297 * to the I2C block inside the DVC block
307 */ 298 */
308static unsigned long tegra_i2c_reg_addr(struct tegra_i2c_dev *i2c_dev, 299static unsigned long tegra_i2c_reg_addr(struct tegra_i2c_dev *i2c_dev,
309 unsigned long reg) 300 unsigned long reg)
310{ 301{
311 if (i2c_dev->is_dvc) 302 if (i2c_dev->is_dvc)
312 reg += (reg >= I2C_TX_FIFO) ? 0x10 : 0x40; 303 reg += (reg >= I2C_TX_FIFO) ? 0x10 : 0x40;
@@ -314,7 +305,7 @@ static unsigned long tegra_i2c_reg_addr(struct tegra_i2c_dev *i2c_dev,
314} 305}
315 306
316static void i2c_writel(struct tegra_i2c_dev *i2c_dev, u32 val, 307static void i2c_writel(struct tegra_i2c_dev *i2c_dev, u32 val,
317 unsigned long reg) 308 unsigned long reg)
318{ 309{
319 writel(val, i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg)); 310 writel(val, i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg));
320 311
@@ -329,13 +320,13 @@ static u32 i2c_readl(struct tegra_i2c_dev *i2c_dev, unsigned long reg)
329} 320}
330 321
331static void i2c_writesl(struct tegra_i2c_dev *i2c_dev, void *data, 322static void i2c_writesl(struct tegra_i2c_dev *i2c_dev, void *data,
332 unsigned long reg, int len) 323 unsigned long reg, int len)
333{ 324{
334 writesl(i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg), data, len); 325 writesl(i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg), data, len);
335} 326}
336 327
337static void i2c_readsl(struct tegra_i2c_dev *i2c_dev, void *data, 328static void i2c_readsl(struct tegra_i2c_dev *i2c_dev, void *data,
338 unsigned long reg, int len) 329 unsigned long reg, int len)
339{ 330{
340 readsl(i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg), data, len); 331 readsl(i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg), data, len);
341} 332}
@@ -486,7 +477,7 @@ static int tegra_i2c_flush_fifos(struct tegra_i2c_dev *i2c_dev)
486 dev_warn(i2c_dev->dev, "timeout waiting for fifo flush\n"); 477 dev_warn(i2c_dev->dev, "timeout waiting for fifo flush\n");
487 return -ETIMEDOUT; 478 return -ETIMEDOUT;
488 } 479 }
489 msleep(1); 480 usleep_range(1000, 2000);
490 } 481 }
491 return 0; 482 return 0;
492} 483}
@@ -499,6 +490,13 @@ static int tegra_i2c_empty_rx_fifo(struct tegra_i2c_dev *i2c_dev)
499 size_t buf_remaining = i2c_dev->msg_buf_remaining; 490 size_t buf_remaining = i2c_dev->msg_buf_remaining;
500 int words_to_transfer; 491 int words_to_transfer;
501 492
493 /*
494 * Catch overflow due to message fully sent
495 * before the check for RX FIFO availability.
496 */
497 if (WARN_ON_ONCE(!(i2c_dev->msg_buf_remaining)))
498 return -EINVAL;
499
502 if (i2c_dev->hw->has_mst_fifo) { 500 if (i2c_dev->hw->has_mst_fifo) {
503 val = i2c_readl(i2c_dev, I2C_MST_FIFO_STATUS); 501 val = i2c_readl(i2c_dev, I2C_MST_FIFO_STATUS);
504 rx_fifo_avail = (val & I2C_MST_FIFO_STATUS_RX_MASK) >> 502 rx_fifo_avail = (val & I2C_MST_FIFO_STATUS_RX_MASK) >>
@@ -525,7 +523,11 @@ static int tegra_i2c_empty_rx_fifo(struct tegra_i2c_dev *i2c_dev)
525 * prevent overwriting past the end of buf 523 * prevent overwriting past the end of buf
526 */ 524 */
527 if (rx_fifo_avail > 0 && buf_remaining > 0) { 525 if (rx_fifo_avail > 0 && buf_remaining > 0) {
528 BUG_ON(buf_remaining > 3); 526 /*
527 * buf_remaining > 3 check not needed as rx_fifo_avail == 0
528 * when (words_to_transfer was > rx_fifo_avail) earlier
529 * in this function.
530 */
529 val = i2c_readl(i2c_dev, I2C_RX_FIFO); 531 val = i2c_readl(i2c_dev, I2C_RX_FIFO);
530 val = cpu_to_le32(val); 532 val = cpu_to_le32(val);
531 memcpy(buf, &val, buf_remaining); 533 memcpy(buf, &val, buf_remaining);
@@ -533,7 +535,10 @@ static int tegra_i2c_empty_rx_fifo(struct tegra_i2c_dev *i2c_dev)
533 rx_fifo_avail--; 535 rx_fifo_avail--;
534 } 536 }
535 537
536 BUG_ON(rx_fifo_avail > 0 && buf_remaining > 0); 538 /* RX FIFO must be drained, otherwise it's an Overflow case. */
539 if (WARN_ON_ONCE(rx_fifo_avail))
540 return -EINVAL;
541
537 i2c_dev->msg_buf_remaining = buf_remaining; 542 i2c_dev->msg_buf_remaining = buf_remaining;
538 i2c_dev->msg_buf = buf; 543 i2c_dev->msg_buf = buf;
539 544
@@ -591,7 +596,11 @@ static int tegra_i2c_fill_tx_fifo(struct tegra_i2c_dev *i2c_dev)
591 * boundary and fault. 596 * boundary and fault.
592 */ 597 */
593 if (tx_fifo_avail > 0 && buf_remaining > 0) { 598 if (tx_fifo_avail > 0 && buf_remaining > 0) {
594 BUG_ON(buf_remaining > 3); 599 /*
600 * buf_remaining > 3 check not needed as tx_fifo_avail == 0
601 * when (words_to_transfer was > tx_fifo_avail) earlier
602 * in this function for non-zero words_to_transfer.
603 */
595 memcpy(&val, buf, buf_remaining); 604 memcpy(&val, buf, buf_remaining);
596 val = le32_to_cpu(val); 605 val = le32_to_cpu(val);
597 606
@@ -680,10 +689,11 @@ static int tegra_i2c_wait_for_config_load(struct tegra_i2c_dev *i2c_dev)
680 i2c_writel(i2c_dev, I2C_MSTR_CONFIG_LOAD, I2C_CONFIG_LOAD); 689 i2c_writel(i2c_dev, I2C_MSTR_CONFIG_LOAD, I2C_CONFIG_LOAD);
681 if (in_interrupt()) 690 if (in_interrupt())
682 err = readl_poll_timeout_atomic(addr, val, val == 0, 691 err = readl_poll_timeout_atomic(addr, val, val == 0,
683 1000, I2C_CONFIG_LOAD_TIMEOUT); 692 1000,
693 I2C_CONFIG_LOAD_TIMEOUT);
684 else 694 else
685 err = readl_poll_timeout(addr, val, val == 0, 695 err = readl_poll_timeout(addr, val, val == 0, 1000,
686 1000, I2C_CONFIG_LOAD_TIMEOUT); 696 I2C_CONFIG_LOAD_TIMEOUT);
687 697
688 if (err) { 698 if (err) {
689 dev_warn(i2c_dev->dev, 699 dev_warn(i2c_dev->dev,
@@ -700,7 +710,7 @@ static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev, bool clk_reinit)
700 u32 val; 710 u32 val;
701 int err; 711 int err;
702 u32 clk_divisor, clk_multiplier; 712 u32 clk_divisor, clk_multiplier;
703 u32 tsu_thd = 0; 713 u32 tsu_thd;
704 u8 tlow, thigh; 714 u8 tlow, thigh;
705 715
706 err = pm_runtime_get_sync(i2c_dev->dev); 716 err = pm_runtime_get_sync(i2c_dev->dev);
@@ -856,10 +866,15 @@ static irqreturn_t tegra_i2c_isr(int irq, void *dev_id)
856 866
857 if (!i2c_dev->is_curr_dma_xfer) { 867 if (!i2c_dev->is_curr_dma_xfer) {
858 if (i2c_dev->msg_read && (status & I2C_INT_RX_FIFO_DATA_REQ)) { 868 if (i2c_dev->msg_read && (status & I2C_INT_RX_FIFO_DATA_REQ)) {
859 if (i2c_dev->msg_buf_remaining) 869 if (tegra_i2c_empty_rx_fifo(i2c_dev)) {
860 tegra_i2c_empty_rx_fifo(i2c_dev); 870 /*
861 else 871 * Overflow error condition: message fully sent,
862 BUG(); 872 * with no XFER_COMPLETE interrupt but hardware
873 * asks to transfer more.
874 */
875 i2c_dev->msg_err |= I2C_ERR_RX_BUFFER_OVERFLOW;
876 goto err;
877 }
863 } 878 }
864 879
865 if (!i2c_dev->msg_read && (status & I2C_INT_TX_FIFO_DATA_REQ)) { 880 if (!i2c_dev->msg_read && (status & I2C_INT_TX_FIFO_DATA_REQ)) {
@@ -885,7 +900,14 @@ static irqreturn_t tegra_i2c_isr(int irq, void *dev_id)
885 if (status & I2C_INT_PACKET_XFER_COMPLETE) { 900 if (status & I2C_INT_PACKET_XFER_COMPLETE) {
886 if (i2c_dev->is_curr_dma_xfer) 901 if (i2c_dev->is_curr_dma_xfer)
887 i2c_dev->msg_buf_remaining = 0; 902 i2c_dev->msg_buf_remaining = 0;
888 BUG_ON(i2c_dev->msg_buf_remaining); 903 /*
904 * Underflow error condition: XFER_COMPLETE before message
905 * fully sent.
906 */
907 if (WARN_ON_ONCE(i2c_dev->msg_buf_remaining)) {
908 i2c_dev->msg_err |= I2C_ERR_UNKNOWN_INTERRUPT;
909 goto err;
910 }
889 complete(&i2c_dev->msg_complete); 911 complete(&i2c_dev->msg_complete);
890 } 912 }
891 goto done; 913 goto done;
@@ -1024,7 +1046,8 @@ static int tegra_i2c_issue_bus_clear(struct i2c_adapter *adap)
1024} 1046}
1025 1047
1026static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, 1048static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev,
1027 struct i2c_msg *msg, enum msg_end_type end_state) 1049 struct i2c_msg *msg,
1050 enum msg_end_type end_state)
1028{ 1051{
1029 u32 packet_header; 1052 u32 packet_header;
1030 u32 int_mask; 1053 u32 int_mask;
@@ -1161,9 +1184,8 @@ unlock:
1161 if (err) 1184 if (err)
1162 return err; 1185 return err;
1163 1186
1164 time_left = wait_for_completion_timeout( 1187 time_left = wait_for_completion_timeout(&i2c_dev->dma_complete,
1165 &i2c_dev->dma_complete, 1188 msecs_to_jiffies(xfer_time));
1166 msecs_to_jiffies(xfer_time));
1167 if (time_left == 0) { 1189 if (time_left == 0) {
1168 dev_err(i2c_dev->dev, "DMA transfer timeout\n"); 1190 dev_err(i2c_dev->dev, "DMA transfer timeout\n");
1169 dmaengine_terminate_sync(i2c_dev->msg_read ? 1191 dmaengine_terminate_sync(i2c_dev->msg_read ?
@@ -1225,11 +1247,11 @@ unlock:
1225} 1247}
1226 1248
1227static int tegra_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], 1249static int tegra_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[],
1228 int num) 1250 int num)
1229{ 1251{
1230 struct tegra_i2c_dev *i2c_dev = i2c_get_adapdata(adap); 1252 struct tegra_i2c_dev *i2c_dev = i2c_get_adapdata(adap);
1231 int i; 1253 int i;
1232 int ret = 0; 1254 int ret;
1233 1255
1234 ret = pm_runtime_get_sync(i2c_dev->dev); 1256 ret = pm_runtime_get_sync(i2c_dev->dev);
1235 if (ret < 0) { 1257 if (ret < 0) {
@@ -1271,14 +1293,15 @@ static void tegra_i2c_parse_dt(struct tegra_i2c_dev *i2c_dev)
1271{ 1293{
1272 struct device_node *np = i2c_dev->dev->of_node; 1294 struct device_node *np = i2c_dev->dev->of_node;
1273 int ret; 1295 int ret;
1296 bool multi_mode;
1274 1297
1275 ret = of_property_read_u32(np, "clock-frequency", 1298 ret = of_property_read_u32(np, "clock-frequency",
1276 &i2c_dev->bus_clk_rate); 1299 &i2c_dev->bus_clk_rate);
1277 if (ret) 1300 if (ret)
1278 i2c_dev->bus_clk_rate = 100000; /* default clock rate */ 1301 i2c_dev->bus_clk_rate = 100000; /* default clock rate */
1279 1302
1280 i2c_dev->is_multimaster_mode = of_property_read_bool(np, 1303 multi_mode = of_property_read_bool(np, "multi-master");
1281 "multi-master"); 1304 i2c_dev->is_multimaster_mode = multi_mode;
1282} 1305}
1283 1306
1284static const struct i2c_algorithm tegra_i2c_algo = { 1307static const struct i2c_algorithm tegra_i2c_algo = {
@@ -1500,7 +1523,7 @@ static int tegra_i2c_probe(struct platform_device *pdev)
1500 void __iomem *base; 1523 void __iomem *base;
1501 phys_addr_t base_phys; 1524 phys_addr_t base_phys;
1502 int irq; 1525 int irq;
1503 int ret = 0; 1526 int ret;
1504 1527
1505 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1528 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1506 base_phys = res->start; 1529 base_phys = res->start;
@@ -1517,7 +1540,9 @@ static int tegra_i2c_probe(struct platform_device *pdev)
1517 1540
1518 div_clk = devm_clk_get(&pdev->dev, "div-clk"); 1541 div_clk = devm_clk_get(&pdev->dev, "div-clk");
1519 if (IS_ERR(div_clk)) { 1542 if (IS_ERR(div_clk)) {
1520 dev_err(&pdev->dev, "missing controller clock\n"); 1543 if (PTR_ERR(div_clk) != -EPROBE_DEFER)
1544 dev_err(&pdev->dev, "missing controller clock\n");
1545
1521 return PTR_ERR(div_clk); 1546 return PTR_ERR(div_clk);
1522 } 1547 }
1523 1548
@@ -1622,7 +1647,7 @@ static int tegra_i2c_probe(struct platform_device *pdev)
1622 } 1647 }
1623 1648
1624 ret = devm_request_irq(&pdev->dev, i2c_dev->irq, 1649 ret = devm_request_irq(&pdev->dev, i2c_dev->irq,
1625 tegra_i2c_isr, 0, dev_name(&pdev->dev), i2c_dev); 1650 tegra_i2c_isr, 0, dev_name(&pdev->dev), i2c_dev);
1626 if (ret) { 1651 if (ret) {
1627 dev_err(&pdev->dev, "Failed to request irq %i\n", i2c_dev->irq); 1652 dev_err(&pdev->dev, "Failed to request irq %i\n", i2c_dev->irq);
1628 goto release_dma; 1653 goto release_dma;
@@ -1687,10 +1712,35 @@ static int tegra_i2c_remove(struct platform_device *pdev)
1687} 1712}
1688 1713
1689#ifdef CONFIG_PM_SLEEP 1714#ifdef CONFIG_PM_SLEEP
1715static int tegra_i2c_suspend(struct device *dev)
1716{
1717 struct tegra_i2c_dev *i2c_dev = dev_get_drvdata(dev);
1718
1719 i2c_mark_adapter_suspended(&i2c_dev->adapter);
1720
1721 return 0;
1722}
1723
1724static int tegra_i2c_resume(struct device *dev)
1725{
1726 struct tegra_i2c_dev *i2c_dev = dev_get_drvdata(dev);
1727 int err;
1728
1729 err = tegra_i2c_init(i2c_dev, false);
1730 if (err)
1731 return err;
1732
1733 i2c_mark_adapter_resumed(&i2c_dev->adapter);
1734
1735 return 0;
1736}
1737
1690static const struct dev_pm_ops tegra_i2c_pm = { 1738static const struct dev_pm_ops tegra_i2c_pm = {
1739 SET_SYSTEM_SLEEP_PM_OPS(tegra_i2c_suspend, tegra_i2c_resume)
1691 SET_RUNTIME_PM_OPS(tegra_i2c_runtime_suspend, tegra_i2c_runtime_resume, 1740 SET_RUNTIME_PM_OPS(tegra_i2c_runtime_suspend, tegra_i2c_runtime_resume,
1692 NULL) 1741 NULL)
1693}; 1742};
1743
1694#define TEGRA_I2C_PM (&tegra_i2c_pm) 1744#define TEGRA_I2C_PM (&tegra_i2c_pm)
1695#else 1745#else
1696#define TEGRA_I2C_PM NULL 1746#define TEGRA_I2C_PM NULL
diff --git a/drivers/i2c/i2c-core-acpi.c b/drivers/i2c/i2c-core-acpi.c
index 428a82c3a35f..4dbbc9a35f65 100644
--- a/drivers/i2c/i2c-core-acpi.c
+++ b/drivers/i2c/i2c-core-acpi.c
@@ -132,13 +132,52 @@ static int i2c_acpi_do_lookup(struct acpi_device *adev,
132 return 0; 132 return 0;
133} 133}
134 134
135static int i2c_acpi_add_resource(struct acpi_resource *ares, void *data)
136{
137 int *irq = data;
138 struct resource r;
139
140 if (*irq <= 0 && acpi_dev_resource_interrupt(ares, 0, &r))
141 *irq = i2c_dev_irq_from_resources(&r, 1);
142
143 return 1; /* No need to add resource to the list */
144}
145
146/**
147 * i2c_acpi_get_irq - get device IRQ number from ACPI
148 * @client: Pointer to the I2C client device
149 *
150 * Find the IRQ number used by a specific client device.
151 *
152 * Return: The IRQ number or an error code.
153 */
154int i2c_acpi_get_irq(struct i2c_client *client)
155{
156 struct acpi_device *adev = ACPI_COMPANION(&client->dev);
157 struct list_head resource_list;
158 int irq = -ENOENT;
159 int ret;
160
161 INIT_LIST_HEAD(&resource_list);
162
163 ret = acpi_dev_get_resources(adev, &resource_list,
164 i2c_acpi_add_resource, &irq);
165 if (ret < 0)
166 return ret;
167
168 acpi_dev_free_resource_list(&resource_list);
169
170 if (irq == -ENOENT)
171 irq = acpi_dev_gpio_irq_get(adev, 0);
172
173 return irq;
174}
175
135static int i2c_acpi_get_info(struct acpi_device *adev, 176static int i2c_acpi_get_info(struct acpi_device *adev,
136 struct i2c_board_info *info, 177 struct i2c_board_info *info,
137 struct i2c_adapter *adapter, 178 struct i2c_adapter *adapter,
138 acpi_handle *adapter_handle) 179 acpi_handle *adapter_handle)
139{ 180{
140 struct list_head resource_list;
141 struct resource_entry *entry;
142 struct i2c_acpi_lookup lookup; 181 struct i2c_acpi_lookup lookup;
143 int ret; 182 int ret;
144 183
@@ -172,21 +211,6 @@ static int i2c_acpi_get_info(struct acpi_device *adev,
172 if (adapter_handle) 211 if (adapter_handle)
173 *adapter_handle = lookup.adapter_handle; 212 *adapter_handle = lookup.adapter_handle;
174 213
175 /* Then fill IRQ number if any */
176 INIT_LIST_HEAD(&resource_list);
177 ret = acpi_dev_get_resources(adev, &resource_list, NULL, NULL);
178 if (ret < 0)
179 return -EINVAL;
180
181 resource_list_for_each_entry(entry, &resource_list) {
182 if (resource_type(entry->res) == IORESOURCE_IRQ) {
183 info->irq = entry->res->start;
184 break;
185 }
186 }
187
188 acpi_dev_free_resource_list(&resource_list);
189
190 acpi_set_modalias(adev, dev_name(&adev->dev), info->type, 214 acpi_set_modalias(adev, dev_name(&adev->dev), info->type,
191 sizeof(info->type)); 215 sizeof(info->type));
192 216
diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index 9e43508d4567..f26ed495d384 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -314,6 +314,8 @@ static int i2c_device_probe(struct device *dev)
314 314
315 driver = to_i2c_driver(dev->driver); 315 driver = to_i2c_driver(dev->driver);
316 316
317 client->irq = client->init_irq;
318
317 if (!client->irq && !driver->disable_i2c_core_irq_mapping) { 319 if (!client->irq && !driver->disable_i2c_core_irq_mapping) {
318 int irq = -ENOENT; 320 int irq = -ENOENT;
319 321
@@ -327,7 +329,7 @@ static int i2c_device_probe(struct device *dev)
327 if (irq == -EINVAL || irq == -ENODATA) 329 if (irq == -EINVAL || irq == -ENODATA)
328 irq = of_irq_get(dev->of_node, 0); 330 irq = of_irq_get(dev->of_node, 0);
329 } else if (ACPI_COMPANION(dev)) { 331 } else if (ACPI_COMPANION(dev)) {
330 irq = acpi_dev_gpio_irq_get(ACPI_COMPANION(dev), 0); 332 irq = i2c_acpi_get_irq(client);
331 } 333 }
332 if (irq == -EPROBE_DEFER) 334 if (irq == -EPROBE_DEFER)
333 return irq; 335 return irq;
@@ -424,7 +426,7 @@ static int i2c_device_remove(struct device *dev)
424 dev_pm_clear_wake_irq(&client->dev); 426 dev_pm_clear_wake_irq(&client->dev);
425 device_init_wakeup(&client->dev, false); 427 device_init_wakeup(&client->dev, false);
426 428
427 client->irq = client->init_irq; 429 client->irq = 0;
428 if (client->flags & I2C_CLIENT_HOST_NOTIFY) 430 if (client->flags & I2C_CLIENT_HOST_NOTIFY)
429 pm_runtime_put(&client->adapter->dev); 431 pm_runtime_put(&client->adapter->dev);
430 432
@@ -679,8 +681,8 @@ static void i2c_dev_set_name(struct i2c_adapter *adap,
679 i2c_encode_flags_to_addr(client)); 681 i2c_encode_flags_to_addr(client));
680} 682}
681 683
682static int i2c_dev_irq_from_resources(const struct resource *resources, 684int i2c_dev_irq_from_resources(const struct resource *resources,
683 unsigned int num_resources) 685 unsigned int num_resources)
684{ 686{
685 struct irq_data *irqd; 687 struct irq_data *irqd;
686 int i; 688 int i;
@@ -721,7 +723,7 @@ static int i2c_dev_irq_from_resources(const struct resource *resources,
721 * This returns the new i2c client, which may be saved for later use with 723 * This returns the new i2c client, which may be saved for later use with
722 * i2c_unregister_device(); or an ERR_PTR to describe the error. 724 * i2c_unregister_device(); or an ERR_PTR to describe the error.
723 */ 725 */
724static struct i2c_client * 726struct i2c_client *
725i2c_new_client_device(struct i2c_adapter *adap, struct i2c_board_info const *info) 727i2c_new_client_device(struct i2c_adapter *adap, struct i2c_board_info const *info)
726{ 728{
727 struct i2c_client *client; 729 struct i2c_client *client;
@@ -741,7 +743,6 @@ i2c_new_client_device(struct i2c_adapter *adap, struct i2c_board_info const *inf
741 if (!client->init_irq) 743 if (!client->init_irq)
742 client->init_irq = i2c_dev_irq_from_resources(info->resources, 744 client->init_irq = i2c_dev_irq_from_resources(info->resources,
743 info->num_resources); 745 info->num_resources);
744 client->irq = client->init_irq;
745 746
746 strlcpy(client->name, info->type, sizeof(client->name)); 747 strlcpy(client->name, info->type, sizeof(client->name));
747 748
@@ -887,8 +888,7 @@ static struct i2c_driver dummy_driver = {
887 * This returns the new i2c client, which should be saved for later use with 888 * This returns the new i2c client, which should be saved for later use with
888 * i2c_unregister_device(); or an ERR_PTR to describe the error. 889 * i2c_unregister_device(); or an ERR_PTR to describe the error.
889 */ 890 */
890static struct i2c_client * 891struct i2c_client *i2c_new_dummy_device(struct i2c_adapter *adapter, u16 address)
891i2c_new_dummy_device(struct i2c_adapter *adapter, u16 address)
892{ 892{
893 struct i2c_board_info info = { 893 struct i2c_board_info info = {
894 I2C_BOARD_INFO("dummy", address), 894 I2C_BOARD_INFO("dummy", address),
@@ -1663,7 +1663,7 @@ EXPORT_SYMBOL_GPL(i2c_parse_fw_timings);
1663 1663
1664/* ------------------------------------------------------------------------- */ 1664/* ------------------------------------------------------------------------- */
1665 1665
1666int i2c_for_each_dev(void *data, int (*fn)(struct device *, void *)) 1666int i2c_for_each_dev(void *data, int (*fn)(struct device *dev, void *data))
1667{ 1667{
1668 int res; 1668 int res;
1669 1669
@@ -2276,7 +2276,7 @@ struct i2c_client *
2276i2c_new_probed_device(struct i2c_adapter *adap, 2276i2c_new_probed_device(struct i2c_adapter *adap,
2277 struct i2c_board_info *info, 2277 struct i2c_board_info *info,
2278 unsigned short const *addr_list, 2278 unsigned short const *addr_list,
2279 int (*probe)(struct i2c_adapter *, unsigned short addr)) 2279 int (*probe)(struct i2c_adapter *adap, unsigned short addr))
2280{ 2280{
2281 int i; 2281 int i;
2282 2282
diff --git a/drivers/i2c/i2c-core-of.c b/drivers/i2c/i2c-core-of.c
index 2eb59a260ad4..d1c48dec7118 100644
--- a/drivers/i2c/i2c-core-of.c
+++ b/drivers/i2c/i2c-core-of.c
@@ -15,6 +15,7 @@
15#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/of.h> 16#include <linux/of.h>
17#include <linux/of_device.h> 17#include <linux/of_device.h>
18#include <linux/sysfs.h>
18 19
19#include "i2c-core.h" 20#include "i2c-core.h"
20 21
diff --git a/drivers/i2c/i2c-core.h b/drivers/i2c/i2c-core.h
index 851c11b4c0f3..517d98be68d2 100644
--- a/drivers/i2c/i2c-core.h
+++ b/drivers/i2c/i2c-core.h
@@ -19,6 +19,8 @@ extern struct list_head __i2c_board_list;
19extern int __i2c_first_dynamic_bus_num; 19extern int __i2c_first_dynamic_bus_num;
20 20
21int i2c_check_7bit_addr_validity_strict(unsigned short addr); 21int i2c_check_7bit_addr_validity_strict(unsigned short addr);
22int i2c_dev_irq_from_resources(const struct resource *resources,
23 unsigned int num_resources);
22 24
23/* 25/*
24 * We only allow atomic transfers for very late communication, e.g. to send 26 * We only allow atomic transfers for very late communication, e.g. to send
@@ -61,6 +63,8 @@ const struct acpi_device_id *
61i2c_acpi_match_device(const struct acpi_device_id *matches, 63i2c_acpi_match_device(const struct acpi_device_id *matches,
62 struct i2c_client *client); 64 struct i2c_client *client);
63void i2c_acpi_register_devices(struct i2c_adapter *adap); 65void i2c_acpi_register_devices(struct i2c_adapter *adap);
66
67int i2c_acpi_get_irq(struct i2c_client *client);
64#else /* CONFIG_ACPI */ 68#else /* CONFIG_ACPI */
65static inline void i2c_acpi_register_devices(struct i2c_adapter *adap) { } 69static inline void i2c_acpi_register_devices(struct i2c_adapter *adap) { }
66static inline const struct acpi_device_id * 70static inline const struct acpi_device_id *
@@ -69,6 +73,11 @@ i2c_acpi_match_device(const struct acpi_device_id *matches,
69{ 73{
70 return NULL; 74 return NULL;
71} 75}
76
77static inline int i2c_acpi_get_irq(struct i2c_client *client)
78{
79 return 0;
80}
72#endif /* CONFIG_ACPI */ 81#endif /* CONFIG_ACPI */
73extern struct notifier_block i2c_acpi_notifier; 82extern struct notifier_block i2c_acpi_notifier;
74 83
diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
index 603252fa1284..774507b54b57 100644
--- a/drivers/i2c/i2c-mux.c
+++ b/drivers/i2c/i2c-mux.c
@@ -26,6 +26,7 @@
26#include <linux/module.h> 26#include <linux/module.h>
27#include <linux/of.h> 27#include <linux/of.h>
28#include <linux/slab.h> 28#include <linux/slab.h>
29#include <linux/sysfs.h>
29 30
30/* multiplexer per channel data */ 31/* multiplexer per channel data */
31struct i2c_mux_priv { 32struct i2c_mux_priv {
@@ -243,8 +244,7 @@ struct i2c_mux_core *i2c_mux_alloc(struct i2c_adapter *parent,
243{ 244{
244 struct i2c_mux_core *muxc; 245 struct i2c_mux_core *muxc;
245 246
246 muxc = devm_kzalloc(dev, sizeof(*muxc) 247 muxc = devm_kzalloc(dev, struct_size(muxc, adapter, max_adapters)
247 + max_adapters * sizeof(muxc->adapter[0])
248 + sizeof_priv, GFP_KERNEL); 248 + sizeof_priv, GFP_KERNEL);
249 if (!muxc) 249 if (!muxc)
250 return NULL; 250 return NULL;
diff --git a/drivers/i2c/muxes/i2c-arb-gpio-challenge.c b/drivers/i2c/muxes/i2c-arb-gpio-challenge.c
index 255c598dcfc8..6dc88902c189 100644
--- a/drivers/i2c/muxes/i2c-arb-gpio-challenge.c
+++ b/drivers/i2c/muxes/i2c-arb-gpio-challenge.c
@@ -6,12 +6,11 @@
6 */ 6 */
7 7
8#include <linux/delay.h> 8#include <linux/delay.h>
9#include <linux/gpio.h> 9#include <linux/gpio/consumer.h>
10#include <linux/kernel.h> 10#include <linux/kernel.h>
11#include <linux/i2c.h> 11#include <linux/i2c.h>
12#include <linux/i2c-mux.h> 12#include <linux/i2c-mux.h>
13#include <linux/module.h> 13#include <linux/module.h>
14#include <linux/of_gpio.h>
15#include <linux/platform_device.h> 14#include <linux/platform_device.h>
16#include <linux/slab.h> 15#include <linux/slab.h>
17 16
@@ -19,22 +18,16 @@
19/** 18/**
20 * struct i2c_arbitrator_data - Driver data for I2C arbitrator 19 * struct i2c_arbitrator_data - Driver data for I2C arbitrator
21 * 20 *
22 * @our_gpio: GPIO we'll use to claim. 21 * @our_gpio: GPIO descriptor we'll use to claim.
23 * @our_gpio_release: 0 if active high; 1 if active low; AKA if the GPIO == 22 * @their_gpio: GPIO descriptor that the other side will use to claim.
24 * this then consider it released.
25 * @their_gpio: GPIO that the other side will use to claim.
26 * @their_gpio_release: 0 if active high; 1 if active low; AKA if the GPIO ==
27 * this then consider it released.
28 * @slew_delay_us: microseconds to wait for a GPIO to go high. 23 * @slew_delay_us: microseconds to wait for a GPIO to go high.
29 * @wait_retry_us: we'll attempt another claim after this many microseconds. 24 * @wait_retry_us: we'll attempt another claim after this many microseconds.
30 * @wait_free_us: we'll give up after this many microseconds. 25 * @wait_free_us: we'll give up after this many microseconds.
31 */ 26 */
32 27
33struct i2c_arbitrator_data { 28struct i2c_arbitrator_data {
34 int our_gpio; 29 struct gpio_desc *our_gpio;
35 int our_gpio_release; 30 struct gpio_desc *their_gpio;
36 int their_gpio;
37 int their_gpio_release;
38 unsigned int slew_delay_us; 31 unsigned int slew_delay_us;
39 unsigned int wait_retry_us; 32 unsigned int wait_retry_us;
40 unsigned int wait_free_us; 33 unsigned int wait_free_us;
@@ -55,15 +48,15 @@ static int i2c_arbitrator_select(struct i2c_mux_core *muxc, u32 chan)
55 stop_time = jiffies + usecs_to_jiffies(arb->wait_free_us) + 1; 48 stop_time = jiffies + usecs_to_jiffies(arb->wait_free_us) + 1;
56 do { 49 do {
57 /* Indicate that we want to claim the bus */ 50 /* Indicate that we want to claim the bus */
58 gpio_set_value(arb->our_gpio, !arb->our_gpio_release); 51 gpiod_set_value(arb->our_gpio, 1);
59 udelay(arb->slew_delay_us); 52 udelay(arb->slew_delay_us);
60 53
61 /* Wait for the other master to release it */ 54 /* Wait for the other master to release it */
62 stop_retry = jiffies + usecs_to_jiffies(arb->wait_retry_us) + 1; 55 stop_retry = jiffies + usecs_to_jiffies(arb->wait_retry_us) + 1;
63 while (time_before(jiffies, stop_retry)) { 56 while (time_before(jiffies, stop_retry)) {
64 int gpio_val = !!gpio_get_value(arb->their_gpio); 57 int gpio_val = gpiod_get_value(arb->their_gpio);
65 58
66 if (gpio_val == arb->their_gpio_release) { 59 if (!gpio_val) {
67 /* We got it, so return */ 60 /* We got it, so return */
68 return 0; 61 return 0;
69 } 62 }
@@ -72,13 +65,13 @@ static int i2c_arbitrator_select(struct i2c_mux_core *muxc, u32 chan)
72 } 65 }
73 66
74 /* It didn't release, so give up, wait, and try again */ 67 /* It didn't release, so give up, wait, and try again */
75 gpio_set_value(arb->our_gpio, arb->our_gpio_release); 68 gpiod_set_value(arb->our_gpio, 0);
76 69
77 usleep_range(arb->wait_retry_us, arb->wait_retry_us * 2); 70 usleep_range(arb->wait_retry_us, arb->wait_retry_us * 2);
78 } while (time_before(jiffies, stop_time)); 71 } while (time_before(jiffies, stop_time));
79 72
80 /* Give up, release our claim */ 73 /* Give up, release our claim */
81 gpio_set_value(arb->our_gpio, arb->our_gpio_release); 74 gpiod_set_value(arb->our_gpio, 0);
82 udelay(arb->slew_delay_us); 75 udelay(arb->slew_delay_us);
83 dev_err(muxc->dev, "Could not claim bus, timeout\n"); 76 dev_err(muxc->dev, "Could not claim bus, timeout\n");
84 return -EBUSY; 77 return -EBUSY;
@@ -94,7 +87,7 @@ static int i2c_arbitrator_deselect(struct i2c_mux_core *muxc, u32 chan)
94 const struct i2c_arbitrator_data *arb = i2c_mux_priv(muxc); 87 const struct i2c_arbitrator_data *arb = i2c_mux_priv(muxc);
95 88
96 /* Release the bus and wait for the other master to notice */ 89 /* Release the bus and wait for the other master to notice */
97 gpio_set_value(arb->our_gpio, arb->our_gpio_release); 90 gpiod_set_value(arb->our_gpio, 0);
98 udelay(arb->slew_delay_us); 91 udelay(arb->slew_delay_us);
99 92
100 return 0; 93 return 0;
@@ -107,8 +100,7 @@ static int i2c_arbitrator_probe(struct platform_device *pdev)
107 struct device_node *parent_np; 100 struct device_node *parent_np;
108 struct i2c_mux_core *muxc; 101 struct i2c_mux_core *muxc;
109 struct i2c_arbitrator_data *arb; 102 struct i2c_arbitrator_data *arb;
110 enum of_gpio_flags gpio_flags; 103 struct gpio_desc *dummy;
111 unsigned long out_init;
112 int ret; 104 int ret;
113 105
114 /* We only support probing from device tree; no platform_data */ 106 /* We only support probing from device tree; no platform_data */
@@ -129,45 +121,28 @@ static int i2c_arbitrator_probe(struct platform_device *pdev)
129 121
130 platform_set_drvdata(pdev, muxc); 122 platform_set_drvdata(pdev, muxc);
131 123
132 /* Request GPIOs */ 124 /* Request GPIOs, our GPIO as unclaimed to begin with */
133 ret = of_get_named_gpio_flags(np, "our-claim-gpio", 0, &gpio_flags); 125 arb->our_gpio = devm_gpiod_get(dev, "our-claim", GPIOD_OUT_LOW);
134 if (!gpio_is_valid(ret)) { 126 if (IS_ERR(arb->our_gpio)) {
135 if (ret != -EPROBE_DEFER) 127 dev_err(dev, "could not get \"our-claim\" GPIO (%ld)\n",
136 dev_err(dev, "Error getting our-claim-gpio\n"); 128 PTR_ERR(arb->our_gpio));
137 return ret; 129 return PTR_ERR(arb->our_gpio);
138 }
139 arb->our_gpio = ret;
140 arb->our_gpio_release = !!(gpio_flags & OF_GPIO_ACTIVE_LOW);
141 out_init = (gpio_flags & OF_GPIO_ACTIVE_LOW) ?
142 GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW;
143 ret = devm_gpio_request_one(dev, arb->our_gpio, out_init,
144 "our-claim-gpio");
145 if (ret) {
146 if (ret != -EPROBE_DEFER)
147 dev_err(dev, "Error requesting our-claim-gpio\n");
148 return ret;
149 } 130 }
150 131
151 ret = of_get_named_gpio_flags(np, "their-claim-gpios", 0, &gpio_flags); 132 arb->their_gpio = devm_gpiod_get(dev, "their-claim", GPIOD_IN);
152 if (!gpio_is_valid(ret)) { 133 if (IS_ERR(arb->their_gpio)) {
153 if (ret != -EPROBE_DEFER) 134 dev_err(dev, "could not get \"their-claim\" GPIO (%ld)\n",
154 dev_err(dev, "Error getting their-claim-gpio\n"); 135 PTR_ERR(arb->their_gpio));
155 return ret; 136 return PTR_ERR(arb->their_gpio);
156 }
157 arb->their_gpio = ret;
158 arb->their_gpio_release = !!(gpio_flags & OF_GPIO_ACTIVE_LOW);
159 ret = devm_gpio_request_one(dev, arb->their_gpio, GPIOF_IN,
160 "their-claim-gpio");
161 if (ret) {
162 if (ret != -EPROBE_DEFER)
163 dev_err(dev, "Error requesting their-claim-gpio\n");
164 return ret;
165 } 137 }
166 138
167 /* At the moment we only support a single two master (us + 1 other) */ 139 /* At the moment we only support a single two master (us + 1 other) */
168 if (gpio_is_valid(of_get_named_gpio(np, "their-claim-gpios", 1))) { 140 dummy = devm_gpiod_get_index(dev, "their-claim", 1, GPIOD_IN);
141 if (!IS_ERR(dummy)) {
169 dev_err(dev, "Only one other master is supported\n"); 142 dev_err(dev, "Only one other master is supported\n");
170 return -EINVAL; 143 return -EINVAL;
144 } else if (PTR_ERR(dummy) == -EPROBE_DEFER) {
145 return -EPROBE_DEFER;
171 } 146 }
172 147
173 /* Arbitration parameters */ 148 /* Arbitration parameters */
diff --git a/drivers/i2c/muxes/i2c-mux-gpio.c b/drivers/i2c/muxes/i2c-mux-gpio.c
index 14dc2deba283..4effe563e9e8 100644
--- a/drivers/i2c/muxes/i2c-mux-gpio.c
+++ b/drivers/i2c/muxes/i2c-mux-gpio.c
@@ -11,13 +11,14 @@
11#include <linux/platform_device.h> 11#include <linux/platform_device.h>
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/slab.h> 13#include <linux/slab.h>
14#include <linux/gpio.h> 14#include <linux/bits.h>
15#include <linux/gpio/consumer.h>
16/* FIXME: stop poking around inside gpiolib */
15#include "../../gpio/gpiolib.h" 17#include "../../gpio/gpiolib.h"
16#include <linux/of_gpio.h>
17 18
18struct gpiomux { 19struct gpiomux {
19 struct i2c_mux_gpio_platform_data data; 20 struct i2c_mux_gpio_platform_data data;
20 unsigned gpio_base; 21 int ngpios;
21 struct gpio_desc **gpios; 22 struct gpio_desc **gpios;
22}; 23};
23 24
@@ -27,8 +28,7 @@ static void i2c_mux_gpio_set(const struct gpiomux *mux, unsigned val)
27 28
28 values[0] = val; 29 values[0] = val;
29 30
30 gpiod_set_array_value_cansleep(mux->data.n_gpios, mux->gpios, NULL, 31 gpiod_set_array_value_cansleep(mux->ngpios, mux->gpios, NULL, values);
31 values);
32} 32}
33 33
34static int i2c_mux_gpio_select(struct i2c_mux_core *muxc, u32 chan) 34static int i2c_mux_gpio_select(struct i2c_mux_core *muxc, u32 chan)
@@ -49,12 +49,6 @@ static int i2c_mux_gpio_deselect(struct i2c_mux_core *muxc, u32 chan)
49 return 0; 49 return 0;
50} 50}
51 51
52static int match_gpio_chip_by_label(struct gpio_chip *chip,
53 void *data)
54{
55 return !strcmp(chip->label, data);
56}
57
58#ifdef CONFIG_OF 52#ifdef CONFIG_OF
59static int i2c_mux_gpio_probe_dt(struct gpiomux *mux, 53static int i2c_mux_gpio_probe_dt(struct gpiomux *mux,
60 struct platform_device *pdev) 54 struct platform_device *pdev)
@@ -62,8 +56,8 @@ static int i2c_mux_gpio_probe_dt(struct gpiomux *mux,
62 struct device_node *np = pdev->dev.of_node; 56 struct device_node *np = pdev->dev.of_node;
63 struct device_node *adapter_np, *child; 57 struct device_node *adapter_np, *child;
64 struct i2c_adapter *adapter; 58 struct i2c_adapter *adapter;
65 unsigned *values, *gpios; 59 unsigned *values;
66 int i = 0, ret; 60 int i = 0;
67 61
68 if (!np) 62 if (!np)
69 return -ENODEV; 63 return -ENODEV;
@@ -100,29 +94,6 @@ static int i2c_mux_gpio_probe_dt(struct gpiomux *mux,
100 if (of_property_read_u32(np, "idle-state", &mux->data.idle)) 94 if (of_property_read_u32(np, "idle-state", &mux->data.idle))
101 mux->data.idle = I2C_MUX_GPIO_NO_IDLE; 95 mux->data.idle = I2C_MUX_GPIO_NO_IDLE;
102 96
103 mux->data.n_gpios = of_gpio_named_count(np, "mux-gpios");
104 if (mux->data.n_gpios < 0) {
105 dev_err(&pdev->dev, "Missing mux-gpios property in the DT.\n");
106 return -EINVAL;
107 }
108
109 gpios = devm_kcalloc(&pdev->dev,
110 mux->data.n_gpios, sizeof(*mux->data.gpios),
111 GFP_KERNEL);
112 if (!gpios) {
113 dev_err(&pdev->dev, "Cannot allocate gpios array");
114 return -ENOMEM;
115 }
116
117 for (i = 0; i < mux->data.n_gpios; i++) {
118 ret = of_get_named_gpio(np, "mux-gpios", i);
119 if (ret < 0)
120 return ret;
121 gpios[i] = ret;
122 }
123
124 mux->data.gpios = gpios;
125
126 return 0; 97 return 0;
127} 98}
128#else 99#else
@@ -139,8 +110,8 @@ static int i2c_mux_gpio_probe(struct platform_device *pdev)
139 struct gpiomux *mux; 110 struct gpiomux *mux;
140 struct i2c_adapter *parent; 111 struct i2c_adapter *parent;
141 struct i2c_adapter *root; 112 struct i2c_adapter *root;
142 unsigned initial_state, gpio_base; 113 unsigned initial_state;
143 int i, ret; 114 int i, ngpios, ret;
144 115
145 mux = devm_kzalloc(&pdev->dev, sizeof(*mux), GFP_KERNEL); 116 mux = devm_kzalloc(&pdev->dev, sizeof(*mux), GFP_KERNEL);
146 if (!mux) 117 if (!mux)
@@ -155,29 +126,19 @@ static int i2c_mux_gpio_probe(struct platform_device *pdev)
155 sizeof(mux->data)); 126 sizeof(mux->data));
156 } 127 }
157 128
158 /* 129 ngpios = gpiod_count(&pdev->dev, "mux");
159 * If a GPIO chip name is provided, the GPIO pin numbers provided are 130 if (ngpios <= 0) {
160 * relative to its base GPIO number. Otherwise they are absolute. 131 dev_err(&pdev->dev, "no valid gpios provided\n");
161 */ 132 return ngpios ?: -EINVAL;
162 if (mux->data.gpio_chip) {
163 struct gpio_chip *gpio;
164
165 gpio = gpiochip_find(mux->data.gpio_chip,
166 match_gpio_chip_by_label);
167 if (!gpio)
168 return -EPROBE_DEFER;
169
170 gpio_base = gpio->base;
171 } else {
172 gpio_base = 0;
173 } 133 }
134 mux->ngpios = ngpios;
174 135
175 parent = i2c_get_adapter(mux->data.parent); 136 parent = i2c_get_adapter(mux->data.parent);
176 if (!parent) 137 if (!parent)
177 return -EPROBE_DEFER; 138 return -EPROBE_DEFER;
178 139
179 muxc = i2c_mux_alloc(parent, &pdev->dev, mux->data.n_values, 140 muxc = i2c_mux_alloc(parent, &pdev->dev, mux->data.n_values,
180 mux->data.n_gpios * sizeof(*mux->gpios), 0, 141 ngpios * sizeof(*mux->gpios), 0,
181 i2c_mux_gpio_select, NULL); 142 i2c_mux_gpio_select, NULL);
182 if (!muxc) { 143 if (!muxc) {
183 ret = -ENOMEM; 144 ret = -ENOMEM;
@@ -191,7 +152,6 @@ static int i2c_mux_gpio_probe(struct platform_device *pdev)
191 root = i2c_root_adapter(&parent->dev); 152 root = i2c_root_adapter(&parent->dev);
192 153
193 muxc->mux_locked = true; 154 muxc->mux_locked = true;
194 mux->gpio_base = gpio_base;
195 155
196 if (mux->data.idle != I2C_MUX_GPIO_NO_IDLE) { 156 if (mux->data.idle != I2C_MUX_GPIO_NO_IDLE) {
197 initial_state = mux->data.idle; 157 initial_state = mux->data.idle;
@@ -200,34 +160,28 @@ static int i2c_mux_gpio_probe(struct platform_device *pdev)
200 initial_state = mux->data.values[0]; 160 initial_state = mux->data.values[0];
201 } 161 }
202 162
203 for (i = 0; i < mux->data.n_gpios; i++) { 163 for (i = 0; i < ngpios; i++) {
204 struct device *gpio_dev; 164 struct device *gpio_dev;
205 struct gpio_desc *gpio_desc; 165 struct gpio_desc *gpiod;
206 166 enum gpiod_flags flag;
207 ret = gpio_request(gpio_base + mux->data.gpios[i], "i2c-mux-gpio"); 167
208 if (ret) { 168 if (initial_state & BIT(i))
209 dev_err(&pdev->dev, "Failed to request GPIO %d\n", 169 flag = GPIOD_OUT_HIGH;
210 mux->data.gpios[i]); 170 else
211 goto err_request_gpio; 171 flag = GPIOD_OUT_LOW;
172 gpiod = devm_gpiod_get_index(&pdev->dev, "mux", i, flag);
173 if (IS_ERR(gpiod)) {
174 ret = PTR_ERR(gpiod);
175 goto alloc_failed;
212 } 176 }
213 177
214 ret = gpio_direction_output(gpio_base + mux->data.gpios[i], 178 mux->gpios[i] = gpiod;
215 initial_state & (1 << i));
216 if (ret) {
217 dev_err(&pdev->dev,
218 "Failed to set direction of GPIO %d to output\n",
219 mux->data.gpios[i]);
220 i++; /* gpio_request above succeeded, so must free */
221 goto err_request_gpio;
222 }
223
224 gpio_desc = gpio_to_desc(gpio_base + mux->data.gpios[i]);
225 mux->gpios[i] = gpio_desc;
226 179
227 if (!muxc->mux_locked) 180 if (!muxc->mux_locked)
228 continue; 181 continue;
229 182
230 gpio_dev = &gpio_desc->gdev->dev; 183 /* FIXME: find a proper way to access the GPIO device */
184 gpio_dev = &gpiod->gdev->dev;
231 muxc->mux_locked = i2c_root_adapter(gpio_dev) == root; 185 muxc->mux_locked = i2c_root_adapter(gpio_dev) == root;
232 } 186 }
233 187
@@ -250,10 +204,6 @@ static int i2c_mux_gpio_probe(struct platform_device *pdev)
250 204
251add_adapter_failed: 205add_adapter_failed:
252 i2c_mux_del_adapters(muxc); 206 i2c_mux_del_adapters(muxc);
253 i = mux->data.n_gpios;
254err_request_gpio:
255 for (; i > 0; i--)
256 gpio_free(gpio_base + mux->data.gpios[i - 1]);
257alloc_failed: 207alloc_failed:
258 i2c_put_adapter(parent); 208 i2c_put_adapter(parent);
259 209
@@ -263,14 +213,8 @@ alloc_failed:
263static int i2c_mux_gpio_remove(struct platform_device *pdev) 213static int i2c_mux_gpio_remove(struct platform_device *pdev)
264{ 214{
265 struct i2c_mux_core *muxc = platform_get_drvdata(pdev); 215 struct i2c_mux_core *muxc = platform_get_drvdata(pdev);
266 struct gpiomux *mux = i2c_mux_priv(muxc);
267 int i;
268 216
269 i2c_mux_del_adapters(muxc); 217 i2c_mux_del_adapters(muxc);
270
271 for (i = 0; i < mux->data.n_gpios; i++)
272 gpio_free(mux->gpio_base + mux->data.gpios[i]);
273
274 i2c_put_adapter(muxc->parent); 218 i2c_put_adapter(muxc->parent);
275 219
276 return 0; 220 return 0;
diff --git a/drivers/i2c/muxes/i2c-mux-pinctrl.c b/drivers/i2c/muxes/i2c-mux-pinctrl.c
index 41603586f8fa..f1bb00a11ad6 100644
--- a/drivers/i2c/muxes/i2c-mux-pinctrl.c
+++ b/drivers/i2c/muxes/i2c-mux-pinctrl.c
@@ -16,7 +16,7 @@
16 16
17struct i2c_mux_pinctrl { 17struct i2c_mux_pinctrl {
18 struct pinctrl *pinctrl; 18 struct pinctrl *pinctrl;
19 struct pinctrl_state **states; 19 struct pinctrl_state *states[];
20}; 20};
21 21
22static int i2c_mux_pinctrl_select(struct i2c_mux_core *muxc, u32 chan) 22static int i2c_mux_pinctrl_select(struct i2c_mux_core *muxc, u32 chan)
@@ -93,14 +93,13 @@ static int i2c_mux_pinctrl_probe(struct platform_device *pdev)
93 return PTR_ERR(parent); 93 return PTR_ERR(parent);
94 94
95 muxc = i2c_mux_alloc(parent, dev, num_names, 95 muxc = i2c_mux_alloc(parent, dev, num_names,
96 sizeof(*mux) + num_names * sizeof(*mux->states), 96 struct_size(mux, states, num_names),
97 0, i2c_mux_pinctrl_select, NULL); 97 0, i2c_mux_pinctrl_select, NULL);
98 if (!muxc) { 98 if (!muxc) {
99 ret = -ENOMEM; 99 ret = -ENOMEM;
100 goto err_put_parent; 100 goto err_put_parent;
101 } 101 }
102 mux = i2c_mux_priv(muxc); 102 mux = i2c_mux_priv(muxc);
103 mux->states = (struct pinctrl_state **)(mux + 1);
104 103
105 platform_set_drvdata(pdev, muxc); 104 platform_set_drvdata(pdev, muxc);
106 105
diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
index 63aa541c9608..35bf2477693d 100644
--- a/drivers/misc/eeprom/at24.c
+++ b/drivers/misc/eeprom/at24.c
@@ -507,38 +507,24 @@ static const struct at24_chip_data *at24_get_chip_data(struct device *dev)
507 return cdata; 507 return cdata;
508} 508}
509 509
510static void at24_remove_dummy_clients(struct at24_data *at24)
511{
512 int i;
513
514 for (i = 1; i < at24->num_addresses; i++)
515 i2c_unregister_device(at24->client[i].client);
516}
517
518static int at24_make_dummy_client(struct at24_data *at24, unsigned int index, 510static int at24_make_dummy_client(struct at24_data *at24, unsigned int index,
519 struct regmap_config *regmap_config) 511 struct regmap_config *regmap_config)
520{ 512{
521 struct i2c_client *base_client, *dummy_client; 513 struct i2c_client *base_client, *dummy_client;
522 unsigned short int addr;
523 struct regmap *regmap; 514 struct regmap *regmap;
524 struct device *dev; 515 struct device *dev;
525 516
526 base_client = at24->client[0].client; 517 base_client = at24->client[0].client;
527 dev = &base_client->dev; 518 dev = &base_client->dev;
528 addr = base_client->addr + index;
529 519
530 dummy_client = i2c_new_dummy(base_client->adapter, 520 dummy_client = devm_i2c_new_dummy_device(dev, base_client->adapter,
531 base_client->addr + index); 521 base_client->addr + index);
532 if (!dummy_client) { 522 if (IS_ERR(dummy_client))
533 dev_err(dev, "address 0x%02x unavailable\n", addr); 523 return PTR_ERR(dummy_client);
534 return -EADDRINUSE;
535 }
536 524
537 regmap = devm_regmap_init_i2c(dummy_client, regmap_config); 525 regmap = devm_regmap_init_i2c(dummy_client, regmap_config);
538 if (IS_ERR(regmap)) { 526 if (IS_ERR(regmap))
539 i2c_unregister_device(dummy_client);
540 return PTR_ERR(regmap); 527 return PTR_ERR(regmap);
541 }
542 528
543 at24->client[index].client = dummy_client; 529 at24->client[index].client = dummy_client;
544 at24->client[index].regmap = regmap; 530 at24->client[index].regmap = regmap;
@@ -580,7 +566,6 @@ static int at24_probe(struct i2c_client *client)
580 unsigned int i, num_addresses; 566 unsigned int i, num_addresses;
581 struct at24_data *at24; 567 struct at24_data *at24;
582 struct regmap *regmap; 568 struct regmap *regmap;
583 size_t at24_size;
584 bool writable; 569 bool writable;
585 u8 test_byte; 570 u8 test_byte;
586 int err; 571 int err;
@@ -597,8 +582,8 @@ static int at24_probe(struct i2c_client *client)
597 if (err) 582 if (err)
598 /* 583 /*
599 * This is slow, but we can't know all eeproms, so we better 584 * This is slow, but we can't know all eeproms, so we better
600 * play safe. Specifying custom eeprom-types via platform_data 585 * play safe. Specifying custom eeprom-types via device tree
601 * is recommended anyhow. 586 * or properties is recommended anyhow.
602 */ 587 */
603 page_size = 1; 588 page_size = 1;
604 589
@@ -664,8 +649,8 @@ static int at24_probe(struct i2c_client *client)
664 if (IS_ERR(regmap)) 649 if (IS_ERR(regmap))
665 return PTR_ERR(regmap); 650 return PTR_ERR(regmap);
666 651
667 at24_size = sizeof(*at24) + num_addresses * sizeof(struct at24_client); 652 at24 = devm_kzalloc(dev, struct_size(at24, client, num_addresses),
668 at24 = devm_kzalloc(dev, at24_size, GFP_KERNEL); 653 GFP_KERNEL);
669 if (!at24) 654 if (!at24)
670 return -ENOMEM; 655 return -ENOMEM;
671 656
@@ -693,27 +678,8 @@ static int at24_probe(struct i2c_client *client)
693 /* use dummy devices for multiple-address chips */ 678 /* use dummy devices for multiple-address chips */
694 for (i = 1; i < num_addresses; i++) { 679 for (i = 1; i < num_addresses; i++) {
695 err = at24_make_dummy_client(at24, i, &regmap_config); 680 err = at24_make_dummy_client(at24, i, &regmap_config);
696 if (err) { 681 if (err)
697 at24_remove_dummy_clients(at24);
698 return err; 682 return err;
699 }
700 }
701
702 i2c_set_clientdata(client, at24);
703
704 /* enable runtime pm */
705 pm_runtime_set_active(dev);
706 pm_runtime_enable(dev);
707
708 /*
709 * Perform a one-byte test read to verify that the
710 * chip is functional.
711 */
712 err = at24_read(at24, 0, &test_byte, 1);
713 pm_runtime_idle(dev);
714 if (err) {
715 err = -ENODEV;
716 goto err_clients;
717 } 683 }
718 684
719 nvmem_config.name = dev_name(dev); 685 nvmem_config.name = dev_name(dev);
@@ -731,9 +697,24 @@ static int at24_probe(struct i2c_client *client)
731 nvmem_config.size = byte_len; 697 nvmem_config.size = byte_len;
732 698
733 at24->nvmem = devm_nvmem_register(dev, &nvmem_config); 699 at24->nvmem = devm_nvmem_register(dev, &nvmem_config);
734 if (IS_ERR(at24->nvmem)) { 700 if (IS_ERR(at24->nvmem))
735 err = PTR_ERR(at24->nvmem); 701 return PTR_ERR(at24->nvmem);
736 goto err_clients; 702
703 i2c_set_clientdata(client, at24);
704
705 /* enable runtime pm */
706 pm_runtime_set_active(dev);
707 pm_runtime_enable(dev);
708
709 /*
710 * Perform a one-byte test read to verify that the
711 * chip is functional.
712 */
713 err = at24_read(at24, 0, &test_byte, 1);
714 pm_runtime_idle(dev);
715 if (err) {
716 pm_runtime_disable(dev);
717 return -ENODEV;
737 } 718 }
738 719
739 dev_info(dev, "%u byte %s EEPROM, %s, %u bytes/write\n", 720 dev_info(dev, "%u byte %s EEPROM, %s, %u bytes/write\n",
@@ -741,21 +722,10 @@ static int at24_probe(struct i2c_client *client)
741 writable ? "writable" : "read-only", at24->write_max); 722 writable ? "writable" : "read-only", at24->write_max);
742 723
743 return 0; 724 return 0;
744
745err_clients:
746 at24_remove_dummy_clients(at24);
747 pm_runtime_disable(dev);
748
749 return err;
750} 725}
751 726
752static int at24_remove(struct i2c_client *client) 727static int at24_remove(struct i2c_client *client)
753{ 728{
754 struct at24_data *at24;
755
756 at24 = i2c_get_clientdata(client);
757
758 at24_remove_dummy_clients(at24);
759 pm_runtime_disable(&client->dev); 729 pm_runtime_disable(&client->dev);
760 pm_runtime_set_suspended(&client->dev); 730 pm_runtime_set_suspended(&client->dev);
761 731
diff --git a/drivers/platform/x86/dell-smo8800.c b/drivers/platform/x86/dell-smo8800.c
index 5cdb09cba077..bfcc1d1b9b96 100644
--- a/drivers/platform/x86/dell-smo8800.c
+++ b/drivers/platform/x86/dell-smo8800.c
@@ -198,6 +198,7 @@ static int smo8800_remove(struct acpi_device *device)
198 return 0; 198 return 0;
199} 199}
200 200
201/* NOTE: Keep this list in sync with drivers/i2c/busses/i2c-i801.c */
201static const struct acpi_device_id smo8800_ids[] = { 202static const struct acpi_device_id smo8800_ids[] = {
202 { "SMO8800", 0 }, 203 { "SMO8800", 0 },
203 { "SMO8801", 0 }, 204 { "SMO8801", 0 },
diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
index 7850b851cecd..ba288b964dc8 100644
--- a/drivers/usb/typec/ucsi/ucsi.c
+++ b/drivers/usb/typec/ucsi/ucsi.c
@@ -206,7 +206,17 @@ int ucsi_send_command(struct ucsi *ucsi, struct ucsi_control *ctrl,
206 206
207 return ret; 207 return ret;
208} 208}
209EXPORT_SYMBOL_GPL(ucsi_send_command);
209 210
211int ucsi_resume(struct ucsi *ucsi)
212{
213 struct ucsi_control ctrl;
214
215 /* Restore UCSI notification enable mask after system resume */
216 UCSI_CMD_SET_NTFY_ENABLE(ctrl, UCSI_ENABLE_NTFY_ALL);
217 return ucsi_send_command(ucsi, &ctrl, NULL, 0);
218}
219EXPORT_SYMBOL_GPL(ucsi_resume);
210/* -------------------------------------------------------------------------- */ 220/* -------------------------------------------------------------------------- */
211 221
212void ucsi_altmode_update_active(struct ucsi_connector *con) 222void ucsi_altmode_update_active(struct ucsi_connector *con)
diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h
index 1e2981aef629..de87d0b8319d 100644
--- a/drivers/usb/typec/ucsi/ucsi.h
+++ b/drivers/usb/typec/ucsi/ucsi.h
@@ -430,6 +430,7 @@ int ucsi_send_command(struct ucsi *ucsi, struct ucsi_control *ctrl,
430 void *retval, size_t size); 430 void *retval, size_t size);
431 431
432void ucsi_altmode_update_active(struct ucsi_connector *con); 432void ucsi_altmode_update_active(struct ucsi_connector *con);
433int ucsi_resume(struct ucsi *ucsi);
433 434
434#if IS_ENABLED(CONFIG_TYPEC_DP_ALTMODE) 435#if IS_ENABLED(CONFIG_TYPEC_DP_ALTMODE)
435struct typec_altmode * 436struct typec_altmode *
diff --git a/drivers/usb/typec/ucsi/ucsi_ccg.c b/drivers/usb/typec/ucsi/ucsi_ccg.c
index bf63074675fc..f7a79a23ebed 100644
--- a/drivers/usb/typec/ucsi/ucsi_ccg.c
+++ b/drivers/usb/typec/ucsi/ucsi_ccg.c
@@ -14,6 +14,8 @@
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/pci.h> 15#include <linux/pci.h>
16#include <linux/platform_device.h> 16#include <linux/platform_device.h>
17#include <linux/pm.h>
18#include <linux/pm_runtime.h>
17 19
18#include <asm/unaligned.h> 20#include <asm/unaligned.h>
19#include "ucsi.h" 21#include "ucsi.h"
@@ -107,12 +109,21 @@ struct version_format {
107 __le16 build; 109 __le16 build;
108 u8 patch; 110 u8 patch;
109 u8 ver; 111 u8 ver;
112#define CCG_VERSION_PATCH(x) ((x) << 16)
113#define CCG_VERSION(x) ((x) << 24)
110#define CCG_VERSION_MIN_SHIFT (0) 114#define CCG_VERSION_MIN_SHIFT (0)
111#define CCG_VERSION_MIN_MASK (0xf << CCG_VERSION_MIN_SHIFT) 115#define CCG_VERSION_MIN_MASK (0xf << CCG_VERSION_MIN_SHIFT)
112#define CCG_VERSION_MAJ_SHIFT (4) 116#define CCG_VERSION_MAJ_SHIFT (4)
113#define CCG_VERSION_MAJ_MASK (0xf << CCG_VERSION_MAJ_SHIFT) 117#define CCG_VERSION_MAJ_MASK (0xf << CCG_VERSION_MAJ_SHIFT)
114} __packed; 118} __packed;
115 119
120/*
121 * Firmware version 3.1.10 or earlier, built for NVIDIA has known issue
122 * of missing interrupt when a device is connected for runtime resume
123 */
124#define CCG_FW_BUILD_NVIDIA (('n' << 8) | 'v')
125#define CCG_OLD_FW_VERSION (CCG_VERSION(0x31) | CCG_VERSION_PATCH(10))
126
116struct version_info { 127struct version_info {
117 struct version_format base; 128 struct version_format base;
118 struct version_format app; 129 struct version_format app;
@@ -170,6 +181,7 @@ struct ucsi_ccg {
170 struct ccg_dev_info info; 181 struct ccg_dev_info info;
171 /* version info for boot, primary and secondary */ 182 /* version info for boot, primary and secondary */
172 struct version_info version[FW2 + 1]; 183 struct version_info version[FW2 + 1];
184 u32 fw_version;
173 /* CCG HPI communication flags */ 185 /* CCG HPI communication flags */
174 unsigned long flags; 186 unsigned long flags;
175#define RESET_PENDING 0 187#define RESET_PENDING 0
@@ -183,6 +195,8 @@ struct ucsi_ccg {
183 195
184 /* fw build with vendor information */ 196 /* fw build with vendor information */
185 u16 fw_build; 197 u16 fw_build;
198 bool run_isr; /* flag to call ISR routine during resume */
199 struct work_struct pm_work;
186}; 200};
187 201
188static int ccg_read(struct ucsi_ccg *uc, u16 rab, u8 *data, u32 len) 202static int ccg_read(struct ucsi_ccg *uc, u16 rab, u8 *data, u32 len)
@@ -210,6 +224,19 @@ static int ccg_read(struct ucsi_ccg *uc, u16 rab, u8 *data, u32 len)
210 if (quirks && quirks->max_read_len) 224 if (quirks && quirks->max_read_len)
211 max_read_len = quirks->max_read_len; 225 max_read_len = quirks->max_read_len;
212 226
227 if (uc->fw_build == CCG_FW_BUILD_NVIDIA &&
228 uc->fw_version <= CCG_OLD_FW_VERSION) {
229 mutex_lock(&uc->lock);
230 /*
231 * Do not schedule pm_work to run ISR in
232 * ucsi_ccg_runtime_resume() after pm_runtime_get_sync()
233 * since we are already in ISR path.
234 */
235 uc->run_isr = false;
236 mutex_unlock(&uc->lock);
237 }
238
239 pm_runtime_get_sync(uc->dev);
213 while (rem_len > 0) { 240 while (rem_len > 0) {
214 msgs[1].buf = &data[len - rem_len]; 241 msgs[1].buf = &data[len - rem_len];
215 rlen = min_t(u16, rem_len, max_read_len); 242 rlen = min_t(u16, rem_len, max_read_len);
@@ -218,12 +245,14 @@ static int ccg_read(struct ucsi_ccg *uc, u16 rab, u8 *data, u32 len)
218 status = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); 245 status = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
219 if (status < 0) { 246 if (status < 0) {
220 dev_err(uc->dev, "i2c_transfer failed %d\n", status); 247 dev_err(uc->dev, "i2c_transfer failed %d\n", status);
248 pm_runtime_put_sync(uc->dev);
221 return status; 249 return status;
222 } 250 }
223 rab += rlen; 251 rab += rlen;
224 rem_len -= rlen; 252 rem_len -= rlen;
225 } 253 }
226 254
255 pm_runtime_put_sync(uc->dev);
227 return 0; 256 return 0;
228} 257}
229 258
@@ -249,13 +278,28 @@ static int ccg_write(struct ucsi_ccg *uc, u16 rab, u8 *data, u32 len)
249 msgs[0].len = len + sizeof(rab); 278 msgs[0].len = len + sizeof(rab);
250 msgs[0].buf = buf; 279 msgs[0].buf = buf;
251 280
281 if (uc->fw_build == CCG_FW_BUILD_NVIDIA &&
282 uc->fw_version <= CCG_OLD_FW_VERSION) {
283 mutex_lock(&uc->lock);
284 /*
285 * Do not schedule pm_work to run ISR in
286 * ucsi_ccg_runtime_resume() after pm_runtime_get_sync()
287 * since we are already in ISR path.
288 */
289 uc->run_isr = false;
290 mutex_unlock(&uc->lock);
291 }
292
293 pm_runtime_get_sync(uc->dev);
252 status = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); 294 status = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
253 if (status < 0) { 295 if (status < 0) {
254 dev_err(uc->dev, "i2c_transfer failed %d\n", status); 296 dev_err(uc->dev, "i2c_transfer failed %d\n", status);
297 pm_runtime_put_sync(uc->dev);
255 kfree(buf); 298 kfree(buf);
256 return status; 299 return status;
257 } 300 }
258 301
302 pm_runtime_put_sync(uc->dev);
259 kfree(buf); 303 kfree(buf);
260 return 0; 304 return 0;
261} 305}
@@ -375,6 +419,13 @@ static irqreturn_t ccg_irq_handler(int irq, void *data)
375 return IRQ_HANDLED; 419 return IRQ_HANDLED;
376} 420}
377 421
422static void ccg_pm_workaround_work(struct work_struct *pm_work)
423{
424 struct ucsi_ccg *uc = container_of(pm_work, struct ucsi_ccg, pm_work);
425
426 ucsi_notify(uc->ucsi);
427}
428
378static int get_fw_info(struct ucsi_ccg *uc) 429static int get_fw_info(struct ucsi_ccg *uc)
379{ 430{
380 int err; 431 int err;
@@ -384,6 +435,9 @@ static int get_fw_info(struct ucsi_ccg *uc)
384 if (err < 0) 435 if (err < 0)
385 return err; 436 return err;
386 437
438 uc->fw_version = CCG_VERSION(uc->version[FW2].app.ver) |
439 CCG_VERSION_PATCH(uc->version[FW2].app.patch);
440
387 err = ccg_read(uc, CCGX_RAB_DEVICE_MODE, (u8 *)(&uc->info), 441 err = ccg_read(uc, CCGX_RAB_DEVICE_MODE, (u8 *)(&uc->info),
388 sizeof(uc->info)); 442 sizeof(uc->info));
389 if (err < 0) 443 if (err < 0)
@@ -732,11 +786,12 @@ static bool ccg_check_fw_version(struct ucsi_ccg *uc, const char *fw_name,
732 } 786 }
733 787
734 /* compare input version with FWCT version */ 788 /* compare input version with FWCT version */
735 cur_version = le16_to_cpu(app->build) | app->patch << 16 | 789 cur_version = le16_to_cpu(app->build) | CCG_VERSION_PATCH(app->patch) |
736 app->ver << 24; 790 CCG_VERSION(app->ver);
737 791
738 new_version = le16_to_cpu(fw_cfg.app.build) | fw_cfg.app.patch << 16 | 792 new_version = le16_to_cpu(fw_cfg.app.build) |
739 fw_cfg.app.ver << 24; 793 CCG_VERSION_PATCH(fw_cfg.app.patch) |
794 CCG_VERSION(fw_cfg.app.ver);
740 795
741 if (!ccg_check_vendor_version(uc, app, &fw_cfg)) 796 if (!ccg_check_vendor_version(uc, app, &fw_cfg))
742 goto out_release_firmware; 797 goto out_release_firmware;
@@ -1078,8 +1133,10 @@ static int ucsi_ccg_probe(struct i2c_client *client,
1078 uc->ppm.sync = ucsi_ccg_sync; 1133 uc->ppm.sync = ucsi_ccg_sync;
1079 uc->dev = dev; 1134 uc->dev = dev;
1080 uc->client = client; 1135 uc->client = client;
1136 uc->run_isr = true;
1081 mutex_init(&uc->lock); 1137 mutex_init(&uc->lock);
1082 INIT_WORK(&uc->work, ccg_update_firmware); 1138 INIT_WORK(&uc->work, ccg_update_firmware);
1139 INIT_WORK(&uc->pm_work, ccg_pm_workaround_work);
1083 1140
1084 /* Only fail FW flashing when FW build information is not provided */ 1141 /* Only fail FW flashing when FW build information is not provided */
1085 status = device_property_read_u16(dev, "ccgx,firmware-build", 1142 status = device_property_read_u16(dev, "ccgx,firmware-build",
@@ -1136,6 +1193,10 @@ static int ucsi_ccg_probe(struct i2c_client *client,
1136 if (status) 1193 if (status)
1137 dev_err(uc->dev, "cannot create sysfs group: %d\n", status); 1194 dev_err(uc->dev, "cannot create sysfs group: %d\n", status);
1138 1195
1196 pm_runtime_set_active(uc->dev);
1197 pm_runtime_enable(uc->dev);
1198 pm_runtime_idle(uc->dev);
1199
1139 return 0; 1200 return 0;
1140} 1201}
1141 1202
@@ -1143,8 +1204,10 @@ static int ucsi_ccg_remove(struct i2c_client *client)
1143{ 1204{
1144 struct ucsi_ccg *uc = i2c_get_clientdata(client); 1205 struct ucsi_ccg *uc = i2c_get_clientdata(client);
1145 1206
1207 cancel_work_sync(&uc->pm_work);
1146 cancel_work_sync(&uc->work); 1208 cancel_work_sync(&uc->work);
1147 ucsi_unregister_ppm(uc->ucsi); 1209 ucsi_unregister_ppm(uc->ucsi);
1210 pm_runtime_disable(uc->dev);
1148 free_irq(uc->irq, uc); 1211 free_irq(uc->irq, uc);
1149 sysfs_remove_group(&uc->dev->kobj, &ucsi_ccg_attr_group); 1212 sysfs_remove_group(&uc->dev->kobj, &ucsi_ccg_attr_group);
1150 1213
@@ -1157,9 +1220,56 @@ static const struct i2c_device_id ucsi_ccg_device_id[] = {
1157}; 1220};
1158MODULE_DEVICE_TABLE(i2c, ucsi_ccg_device_id); 1221MODULE_DEVICE_TABLE(i2c, ucsi_ccg_device_id);
1159 1222
1223static int ucsi_ccg_resume(struct device *dev)
1224{
1225 struct i2c_client *client = to_i2c_client(dev);
1226 struct ucsi_ccg *uc = i2c_get_clientdata(client);
1227
1228 return ucsi_resume(uc->ucsi);
1229}
1230
1231static int ucsi_ccg_runtime_suspend(struct device *dev)
1232{
1233 return 0;
1234}
1235
1236static int ucsi_ccg_runtime_resume(struct device *dev)
1237{
1238 struct i2c_client *client = to_i2c_client(dev);
1239 struct ucsi_ccg *uc = i2c_get_clientdata(client);
1240 bool schedule = true;
1241
1242 /*
1243 * Firmware version 3.1.10 or earlier, built for NVIDIA has known issue
1244 * of missing interrupt when a device is connected for runtime resume.
1245 * Schedule a work to call ISR as a workaround.
1246 */
1247 if (uc->fw_build == CCG_FW_BUILD_NVIDIA &&
1248 uc->fw_version <= CCG_OLD_FW_VERSION) {
1249 mutex_lock(&uc->lock);
1250 if (!uc->run_isr) {
1251 uc->run_isr = true;
1252 schedule = false;
1253 }
1254 mutex_unlock(&uc->lock);
1255
1256 if (schedule)
1257 schedule_work(&uc->pm_work);
1258 }
1259
1260 return 0;
1261}
1262
1263static const struct dev_pm_ops ucsi_ccg_pm = {
1264 .resume = ucsi_ccg_resume,
1265 .runtime_suspend = ucsi_ccg_runtime_suspend,
1266 .runtime_resume = ucsi_ccg_runtime_resume,
1267};
1268
1160static struct i2c_driver ucsi_ccg_driver = { 1269static struct i2c_driver ucsi_ccg_driver = {
1161 .driver = { 1270 .driver = {
1162 .name = "ucsi_ccg", 1271 .name = "ucsi_ccg",
1272 .pm = &ucsi_ccg_pm,
1163 }, 1273 },
1164 .probe = ucsi_ccg_probe, 1274 .probe = ucsi_ccg_probe,
1165 .remove = ucsi_ccg_remove, 1275 .remove = ucsi_ccg_remove,
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index e982b8913b73..fa5552c2307b 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -1,16 +1,12 @@
1/* SPDX-License-Identifier: GPL-2.0-or-later */ 1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/* ------------------------------------------------------------------------- */ 2/*
3/* */ 3 * i2c.h - definitions for the Linux i2c bus interface
4/* i2c.h - definitions for the i2c-bus interface */ 4 * Copyright (C) 1995-2000 Simon G. Vogl
5/* */ 5 * Copyright (C) 2013-2019 Wolfram Sang <wsa@the-dreams.de>
6/* ------------------------------------------------------------------------- */ 6 *
7/* Copyright (C) 1995-2000 Simon G. Vogl 7 * With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and
8 8 * Frodo Looijaard <frodol@dds.nl>
9 */ 9 */
10/* ------------------------------------------------------------------------- */
11
12/* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and
13 Frodo Looijaard <frodol@dds.nl> */
14#ifndef _LINUX_I2C_H 10#ifndef _LINUX_I2C_H
15#define _LINUX_I2C_H 11#define _LINUX_I2C_H
16 12
@@ -40,7 +36,8 @@ struct i2c_device_identity;
40union i2c_smbus_data; 36union i2c_smbus_data;
41struct i2c_board_info; 37struct i2c_board_info;
42enum i2c_slave_event; 38enum i2c_slave_event;
43typedef int (*i2c_slave_cb_t)(struct i2c_client *, enum i2c_slave_event, u8 *); 39typedef int (*i2c_slave_cb_t)(struct i2c_client *client,
40 enum i2c_slave_event event, u8 *val);
44 41
45struct module; 42struct module;
46struct property_entry; 43struct property_entry;
@@ -257,16 +254,16 @@ struct i2c_driver {
257 unsigned int class; 254 unsigned int class;
258 255
259 /* Standard driver model interfaces */ 256 /* Standard driver model interfaces */
260 int (*probe)(struct i2c_client *, const struct i2c_device_id *); 257 int (*probe)(struct i2c_client *client, const struct i2c_device_id *id);
261 int (*remove)(struct i2c_client *); 258 int (*remove)(struct i2c_client *client);
262 259
263 /* New driver model interface to aid the seamless removal of the 260 /* New driver model interface to aid the seamless removal of the
264 * current probe()'s, more commonly unused than used second parameter. 261 * current probe()'s, more commonly unused than used second parameter.
265 */ 262 */
266 int (*probe_new)(struct i2c_client *); 263 int (*probe_new)(struct i2c_client *client);
267 264
268 /* driver model interfaces that don't relate to enumeration */ 265 /* driver model interfaces that don't relate to enumeration */
269 void (*shutdown)(struct i2c_client *); 266 void (*shutdown)(struct i2c_client *client);
270 267
271 /* Alert callback, for example for the SMBus alert protocol. 268 /* Alert callback, for example for the SMBus alert protocol.
272 * The format and meaning of the data value depends on the protocol. 269 * The format and meaning of the data value depends on the protocol.
@@ -275,7 +272,7 @@ struct i2c_driver {
275 * For the SMBus Host Notify protocol, the data corresponds to the 272 * For the SMBus Host Notify protocol, the data corresponds to the
276 * 16-bit payload data reported by the slave device acting as master. 273 * 16-bit payload data reported by the slave device acting as master.
277 */ 274 */
278 void (*alert)(struct i2c_client *, enum i2c_alert_protocol protocol, 275 void (*alert)(struct i2c_client *client, enum i2c_alert_protocol protocol,
279 unsigned int data); 276 unsigned int data);
280 277
281 /* a ioctl like command that can be used to perform specific functions 278 /* a ioctl like command that can be used to perform specific functions
@@ -287,7 +284,7 @@ struct i2c_driver {
287 const struct i2c_device_id *id_table; 284 const struct i2c_device_id *id_table;
288 285
289 /* Device detection callback for automatic device creation */ 286 /* Device detection callback for automatic device creation */
290 int (*detect)(struct i2c_client *, struct i2c_board_info *); 287 int (*detect)(struct i2c_client *client, struct i2c_board_info *info);
291 const unsigned short *address_list; 288 const unsigned short *address_list;
292 struct list_head clients; 289 struct list_head clients;
293 290
@@ -297,8 +294,7 @@ struct i2c_driver {
297 294
298/** 295/**
299 * struct i2c_client - represent an I2C slave device 296 * struct i2c_client - represent an I2C slave device
300 * @flags: I2C_CLIENT_TEN indicates the device uses a ten bit chip address; 297 * @flags: see I2C_CLIENT_* for possible flags
301 * I2C_CLIENT_PEC indicates it uses SMBus Packet Error Checking
302 * @addr: Address used on the I2C bus connected to the parent adapter. 298 * @addr: Address used on the I2C bus connected to the parent adapter.
303 * @name: Indicates the type of the device, usually a chip name that's 299 * @name: Indicates the type of the device, usually a chip name that's
304 * generic enough to hide second-sourcing and compatible revisions. 300 * generic enough to hide second-sourcing and compatible revisions.
@@ -316,6 +312,15 @@ struct i2c_driver {
316 */ 312 */
317struct i2c_client { 313struct i2c_client {
318 unsigned short flags; /* div., see below */ 314 unsigned short flags; /* div., see below */
315#define I2C_CLIENT_PEC 0x04 /* Use Packet Error Checking */
316#define I2C_CLIENT_TEN 0x10 /* we have a ten bit chip address */
317 /* Must equal I2C_M_TEN below */
318#define I2C_CLIENT_SLAVE 0x20 /* we are the slave */
319#define I2C_CLIENT_HOST_NOTIFY 0x40 /* We want to use I2C host notify */
320#define I2C_CLIENT_WAKE 0x80 /* for board_info; true iff can wake */
321#define I2C_CLIENT_SCCB 0x9000 /* Use Omnivision SCCB protocol */
322 /* Must match I2C_M_STOP|IGNORE_NAK */
323
319 unsigned short addr; /* chip address - NOTE: 7bit */ 324 unsigned short addr; /* chip address - NOTE: 7bit */
320 /* addresses are stored in the */ 325 /* addresses are stored in the */
321 /* _LOWER_ 7 bits */ 326 /* _LOWER_ 7 bits */
@@ -437,6 +442,9 @@ struct i2c_board_info {
437extern struct i2c_client * 442extern struct i2c_client *
438i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info); 443i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info);
439 444
445extern struct i2c_client *
446i2c_new_client_device(struct i2c_adapter *adap, struct i2c_board_info const *info);
447
440/* If you don't know the exact address of an I2C device, use this variant 448/* If you don't know the exact address of an I2C device, use this variant
441 * instead, which can probe for device presence in a list of possible 449 * instead, which can probe for device presence in a list of possible
442 * addresses. The "probe" callback function is optional. If it is provided, 450 * addresses. The "probe" callback function is optional. If it is provided,
@@ -447,10 +455,10 @@ extern struct i2c_client *
447i2c_new_probed_device(struct i2c_adapter *adap, 455i2c_new_probed_device(struct i2c_adapter *adap,
448 struct i2c_board_info *info, 456 struct i2c_board_info *info,
449 unsigned short const *addr_list, 457 unsigned short const *addr_list,
450 int (*probe)(struct i2c_adapter *, unsigned short addr)); 458 int (*probe)(struct i2c_adapter *adap, unsigned short addr));
451 459
452/* Common custom probe functions */ 460/* Common custom probe functions */
453extern int i2c_probe_func_quick_read(struct i2c_adapter *, unsigned short addr); 461extern int i2c_probe_func_quick_read(struct i2c_adapter *adap, unsigned short addr);
454 462
455/* For devices that use several addresses, use i2c_new_dummy() to make 463/* For devices that use several addresses, use i2c_new_dummy() to make
456 * client handles for the extra addresses. 464 * client handles for the extra addresses.
@@ -459,6 +467,9 @@ extern struct i2c_client *
459i2c_new_dummy(struct i2c_adapter *adap, u16 address); 467i2c_new_dummy(struct i2c_adapter *adap, u16 address);
460 468
461extern struct i2c_client * 469extern struct i2c_client *
470i2c_new_dummy_device(struct i2c_adapter *adapter, u16 address);
471
472extern struct i2c_client *
462devm_i2c_new_dummy_device(struct device *dev, struct i2c_adapter *adap, u16 address); 473devm_i2c_new_dummy_device(struct device *dev, struct i2c_adapter *adap, u16 address);
463 474
464extern struct i2c_client * 475extern struct i2c_client *
@@ -466,7 +477,7 @@ i2c_new_secondary_device(struct i2c_client *client,
466 const char *name, 477 const char *name,
467 u16 default_addr); 478 u16 default_addr);
468 479
469extern void i2c_unregister_device(struct i2c_client *); 480extern void i2c_unregister_device(struct i2c_client *client);
470#endif /* I2C */ 481#endif /* I2C */
471 482
472/* Mainboard arch_initcall() code should register all its I2C devices. 483/* Mainboard arch_initcall() code should register all its I2C devices.
@@ -551,9 +562,9 @@ struct i2c_algorithm {
551 * The main operations are wrapped by i2c_lock_bus and i2c_unlock_bus. 562 * The main operations are wrapped by i2c_lock_bus and i2c_unlock_bus.
552 */ 563 */
553struct i2c_lock_operations { 564struct i2c_lock_operations {
554 void (*lock_bus)(struct i2c_adapter *, unsigned int flags); 565 void (*lock_bus)(struct i2c_adapter *adapter, unsigned int flags);
555 int (*trylock_bus)(struct i2c_adapter *, unsigned int flags); 566 int (*trylock_bus)(struct i2c_adapter *adapter, unsigned int flags);
556 void (*unlock_bus)(struct i2c_adapter *, unsigned int flags); 567 void (*unlock_bus)(struct i2c_adapter *adapter, unsigned int flags);
557}; 568};
558 569
559/** 570/**
@@ -703,14 +714,14 @@ struct i2c_adapter {
703}; 714};
704#define to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev) 715#define to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev)
705 716
706static inline void *i2c_get_adapdata(const struct i2c_adapter *dev) 717static inline void *i2c_get_adapdata(const struct i2c_adapter *adap)
707{ 718{
708 return dev_get_drvdata(&dev->dev); 719 return dev_get_drvdata(&adap->dev);
709} 720}
710 721
711static inline void i2c_set_adapdata(struct i2c_adapter *dev, void *data) 722static inline void i2c_set_adapdata(struct i2c_adapter *adap, void *data)
712{ 723{
713 dev_set_drvdata(&dev->dev, data); 724 dev_set_drvdata(&adap->dev, data);
714} 725}
715 726
716static inline struct i2c_adapter * 727static inline struct i2c_adapter *
@@ -726,7 +737,7 @@ i2c_parent_is_i2c_adapter(const struct i2c_adapter *adapter)
726 return NULL; 737 return NULL;
727} 738}
728 739
729int i2c_for_each_dev(void *data, int (*fn)(struct device *, void *)); 740int i2c_for_each_dev(void *data, int (*fn)(struct device *dev, void *data));
730 741
731/* Adapter locking functions, exported for shared pin cases */ 742/* Adapter locking functions, exported for shared pin cases */
732#define I2C_LOCK_ROOT_ADAPTER BIT(0) 743#define I2C_LOCK_ROOT_ADAPTER BIT(0)
@@ -802,16 +813,6 @@ static inline void i2c_mark_adapter_resumed(struct i2c_adapter *adap)
802 i2c_unlock_bus(adap, I2C_LOCK_ROOT_ADAPTER); 813 i2c_unlock_bus(adap, I2C_LOCK_ROOT_ADAPTER);
803} 814}
804 815
805/*flags for the client struct: */
806#define I2C_CLIENT_PEC 0x04 /* Use Packet Error Checking */
807#define I2C_CLIENT_TEN 0x10 /* we have a ten bit chip address */
808 /* Must equal I2C_M_TEN below */
809#define I2C_CLIENT_SLAVE 0x20 /* we are the slave */
810#define I2C_CLIENT_HOST_NOTIFY 0x40 /* We want to use I2C host notify */
811#define I2C_CLIENT_WAKE 0x80 /* for board_info; true iff can wake */
812#define I2C_CLIENT_SCCB 0x9000 /* Use Omnivision SCCB protocol */
813 /* Must match I2C_M_STOP|IGNORE_NAK */
814
815/* i2c adapter classes (bitmask) */ 816/* i2c adapter classes (bitmask) */
816#define I2C_CLASS_HWMON (1<<0) /* lm_sensors, ... */ 817#define I2C_CLASS_HWMON (1<<0) /* lm_sensors, ... */
817#define I2C_CLASS_DDC (1<<3) /* DDC bus on graphics adapters */ 818#define I2C_CLASS_DDC (1<<3) /* DDC bus on graphics adapters */
@@ -832,12 +833,12 @@ static inline void i2c_mark_adapter_resumed(struct i2c_adapter *adap)
832/* administration... 833/* administration...
833 */ 834 */
834#if IS_ENABLED(CONFIG_I2C) 835#if IS_ENABLED(CONFIG_I2C)
835extern int i2c_add_adapter(struct i2c_adapter *); 836extern int i2c_add_adapter(struct i2c_adapter *adap);
836extern void i2c_del_adapter(struct i2c_adapter *); 837extern void i2c_del_adapter(struct i2c_adapter *adap);
837extern int i2c_add_numbered_adapter(struct i2c_adapter *); 838extern int i2c_add_numbered_adapter(struct i2c_adapter *adap);
838 839
839extern int i2c_register_driver(struct module *, struct i2c_driver *); 840extern int i2c_register_driver(struct module *owner, struct i2c_driver *driver);
840extern void i2c_del_driver(struct i2c_driver *); 841extern void i2c_del_driver(struct i2c_driver *driver);
841 842
842/* use a define to avoid include chaining to get THIS_MODULE */ 843/* use a define to avoid include chaining to get THIS_MODULE */
843#define i2c_add_driver(driver) \ 844#define i2c_add_driver(driver) \
diff --git a/include/linux/platform_data/i2c-mux-gpio.h b/include/linux/platform_data/i2c-mux-gpio.h
index 9f6ca406505b..5e4c2c272a73 100644
--- a/include/linux/platform_data/i2c-mux-gpio.h
+++ b/include/linux/platform_data/i2c-mux-gpio.h
@@ -19,10 +19,6 @@
19 * position 19 * position
20 * @n_values: Number of multiplexer positions (busses to instantiate) 20 * @n_values: Number of multiplexer positions (busses to instantiate)
21 * @classes: Optional I2C auto-detection classes 21 * @classes: Optional I2C auto-detection classes
22 * @gpio_chip: Optional GPIO chip name; if set, GPIO pin numbers are given
23 * relative to the base GPIO number of that chip
24 * @gpios: Array of GPIO numbers used to control MUX
25 * @n_gpios: Number of GPIOs used to control MUX
26 * @idle: Bitmask to write to MUX when idle or GPIO_I2CMUX_NO_IDLE if not used 22 * @idle: Bitmask to write to MUX when idle or GPIO_I2CMUX_NO_IDLE if not used
27 */ 23 */
28struct i2c_mux_gpio_platform_data { 24struct i2c_mux_gpio_platform_data {
@@ -31,9 +27,6 @@ struct i2c_mux_gpio_platform_data {
31 const unsigned *values; 27 const unsigned *values;
32 int n_values; 28 int n_values;
33 const unsigned *classes; 29 const unsigned *classes;
34 char *gpio_chip;
35 const unsigned *gpios;
36 int n_gpios;
37 unsigned idle; 30 unsigned idle;
38}; 31};
39 32