aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2018-06-14 03:21:46 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2018-06-14 03:21:46 -0400
commit9bca19a01d50143b736f0f59eb3ccc05b1106172 (patch)
tree3321118b4a6bd4c949634bbdbb3d2c03454ae33b
parent463f202172c31b9c36278001cabfbad4e12da42e (diff)
parent53e39628ac228fada53cc0106be62c6f65f67501 (diff)
Merge branch 'i2c/for-4.18' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux
Pull i2c updates from Wolfram Sang: - mainly feature additions to drivers (stm32f7, qup, xlp9xx, mlxcpld, ...) - conversion to use the i2c_8bit_addr_from_msg macro consistently - move includes to platform_data - core updates to allow the (still in review) I3C subsystem to connect - and the regular share of smaller driver updates * 'i2c/for-4.18' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux: (68 commits) i2c: qup: fix building without CONFIG_ACPI i2c: tegra: Remove suspend-resume i2c: imx-lpi2c: Switch to SPDX identifier i2c: mxs: Switch to SPDX identifier i2c: busses: make use of i2c_8bit_addr_from_msg i2c: algos: make use of i2c_8bit_addr_from_msg i2c: rcar: document R8A77980 bindings i2c: qup: Add command-line parameter to override SCL frequency i2c: qup: Correct duty cycle for FM and FM+ i2c: qup: Add support for Fast Mode Plus i2c: qup: add probe path for Centriq ACPI devices i2c: robotfuzz-osif: drop pointless test i2c: robotfuzz-osif: remove pointless local variable i2c: rk3x: Don't print visible virtual mapping MMIO address i2c: opal: don't check number of messages in the driver i2c: ibm_iic: don't check number of messages in the driver i2c: imx: Switch to SPDX identifier i2c: mux: pca954x: merge calls to of_match_device and of_device_get_match_data i2c: mux: demux-pinctrl: use proper parent device for demux adapter i2c: mux: improve error message for failed symlink ...
-rw-r--r--Documentation/devicetree/bindings/i2c/i2c-davinci.txt2
-rw-r--r--Documentation/devicetree/bindings/i2c/i2c-rcar.txt1
-rw-r--r--Documentation/devicetree/bindings/i2c/i2c-s3c2410.txt4
-rw-r--r--Documentation/i2c/busses/i2c-mlxcpld4
-rw-r--r--Documentation/i2c/busses/i2c-ocores2
-rw-r--r--Documentation/i2c/muxes/i2c-mux-gpio4
-rw-r--r--MAINTAINERS8
-rw-r--r--arch/arm/mach-ks8695/board-acs5k.c2
-rw-r--r--arch/arm/mach-omap1/board-htcherald.c2
-rw-r--r--arch/arm/mach-omap1/common.h2
-rw-r--r--arch/arm/mach-omap1/i2c.c2
-rw-r--r--arch/arm/mach-omap2/common.h2
-rw-r--r--arch/arm/mach-omap2/omap_hwmod_2420_data.c2
-rw-r--r--arch/arm/mach-omap2/omap_hwmod_2430_data.c2
-rw-r--r--arch/arm/mach-omap2/omap_hwmod_33xx_data.c2
-rw-r--r--arch/arm/mach-omap2/omap_hwmod_3xxx_data.c2
-rw-r--r--arch/arm/mach-omap2/omap_hwmod_44xx_data.c2
-rw-r--r--arch/arm/mach-omap2/omap_hwmod_54xx_data.c2
-rw-r--r--arch/arm/mach-omap2/omap_hwmod_7xx_data.c2
-rw-r--r--arch/arm/mach-pxa/palmz72.c2
-rw-r--r--arch/arm/mach-pxa/viper.c2
-rw-r--r--arch/arm/mach-sa1100/simpad.c2
-rw-r--r--arch/mips/alchemy/board-gpr.c2
-rw-r--r--arch/sh/boards/board-sh7785lcr.c2
-rw-r--r--drivers/i2c/algos/i2c-algo-bit.c4
-rw-r--r--drivers/i2c/algos/i2c-algo-pca.c5
-rw-r--r--drivers/i2c/algos/i2c-algo-pcf.c8
-rw-r--r--drivers/i2c/busses/Kconfig1
-rw-r--r--drivers/i2c/busses/Makefile3
-rw-r--r--drivers/i2c/busses/i2c-aspeed.c3
-rw-r--r--drivers/i2c/busses/i2c-at91.c12
-rw-r--r--drivers/i2c/busses/i2c-axxia.c31
-rw-r--r--drivers/i2c/busses/i2c-designware-common.c20
-rw-r--r--drivers/i2c/busses/i2c-designware-core.h14
-rw-r--r--drivers/i2c/busses/i2c-designware-master.c8
-rw-r--r--drivers/i2c/busses/i2c-designware-slave.c6
-rw-r--r--drivers/i2c/busses/i2c-diolan-u2c.c11
-rw-r--r--drivers/i2c/busses/i2c-efm32.c3
-rw-r--r--drivers/i2c/busses/i2c-eg20t.c5
-rw-r--r--drivers/i2c/busses/i2c-emev2.c2
-rw-r--r--drivers/i2c/busses/i2c-exynos5.c29
-rw-r--r--drivers/i2c/busses/i2c-gpio.c2
-rw-r--r--drivers/i2c/busses/i2c-hix5hd2.c22
-rw-r--r--drivers/i2c/busses/i2c-i801.c7
-rw-r--r--drivers/i2c/busses/i2c-ibm_iic.c3
-rw-r--r--drivers/i2c/busses/i2c-imx-lpi2c.c16
-rw-r--r--drivers/i2c/busses/i2c-imx.c21
-rw-r--r--drivers/i2c/busses/i2c-kempld.c7
-rw-r--r--drivers/i2c/busses/i2c-mlxcpld.c68
-rw-r--r--drivers/i2c/busses/i2c-mt65xx.c8
-rw-r--r--drivers/i2c/busses/i2c-mxs.c16
-rw-r--r--drivers/i2c/busses/i2c-nomadik.c2
-rw-r--r--drivers/i2c/busses/i2c-ocores.c7
-rw-r--r--drivers/i2c/busses/i2c-omap.c2
-rw-r--r--drivers/i2c/busses/i2c-opal.c4
-rw-r--r--drivers/i2c/busses/i2c-pasemi.c2
-rw-r--r--drivers/i2c/busses/i2c-pca-platform.c2
-rw-r--r--drivers/i2c/busses/i2c-pnx.c21
-rw-r--r--drivers/i2c/busses/i2c-qup.c59
-rw-r--r--drivers/i2c/busses/i2c-rcar.c4
-rw-r--r--drivers/i2c/busses/i2c-riic.c5
-rw-r--r--drivers/i2c/busses/i2c-rk3x.c2
-rw-r--r--drivers/i2c/busses/i2c-robotfuzz-osif.c21
-rw-r--r--drivers/i2c/busses/i2c-s3c2410.c2
-rw-r--r--drivers/i2c/busses/i2c-sh_mobile.c11
-rw-r--r--drivers/i2c/busses/i2c-stm32.c153
-rw-r--r--drivers/i2c/busses/i2c-stm32.h37
-rw-r--r--drivers/i2c/busses/i2c-stm32f7.c1045
-rw-r--r--drivers/i2c/busses/i2c-stu300.c22
-rw-r--r--drivers/i2c/busses/i2c-synquacer.c2
-rw-r--r--drivers/i2c/busses/i2c-tegra.c33
-rw-r--r--drivers/i2c/busses/i2c-xiic.c17
-rw-r--r--drivers/i2c/busses/i2c-xlp9xx.c89
-rw-r--r--drivers/i2c/i2c-core-base.c10
-rw-r--r--drivers/i2c/i2c-core-of.c51
-rw-r--r--drivers/i2c/i2c-core-smbus.c2
-rw-r--r--drivers/i2c/i2c-mux.c2
-rw-r--r--drivers/i2c/muxes/i2c-demux-pinctrl.c5
-rw-r--r--drivers/i2c/muxes/i2c-mux-gpio.c2
-rw-r--r--drivers/i2c/muxes/i2c-mux-ltc4306.c7
-rw-r--r--drivers/i2c/muxes/i2c-mux-pca954x.c18
-rw-r--r--drivers/i2c/muxes/i2c-mux-reg.c4
-rw-r--r--drivers/media/platform/marvell-ccic/mmp-driver.c2
-rw-r--r--drivers/mfd/sm501.c2
-rw-r--r--drivers/mfd/timberdale.c4
-rw-r--r--drivers/misc/eeprom/at24.c71
-rw-r--r--include/linux/i2c-pnx.h38
-rw-r--r--include/linux/i2c.h12
-rw-r--r--include/linux/platform_data/i2c-gpio.h (renamed from include/linux/i2c-gpio.h)0
-rw-r--r--include/linux/platform_data/i2c-mux-gpio.h (renamed from include/linux/i2c-mux-gpio.h)0
-rw-r--r--include/linux/platform_data/i2c-ocores.h (renamed from include/linux/i2c-ocores.h)0
-rw-r--r--include/linux/platform_data/i2c-omap.h (renamed from include/linux/i2c-omap.h)0
-rw-r--r--include/linux/platform_data/i2c-pca-platform.h (renamed from include/linux/i2c-pca-platform.h)0
-rw-r--r--include/linux/platform_data/i2c-xiic.h (renamed from include/linux/i2c-xiic.h)0
94 files changed, 1683 insertions, 483 deletions
diff --git a/Documentation/devicetree/bindings/i2c/i2c-davinci.txt b/Documentation/devicetree/bindings/i2c/i2c-davinci.txt
index 64e6e656c345..b745f3706120 100644
--- a/Documentation/devicetree/bindings/i2c/i2c-davinci.txt
+++ b/Documentation/devicetree/bindings/i2c/i2c-davinci.txt
@@ -24,7 +24,7 @@ Recommended properties :
24- clock-frequency : desired I2C bus clock frequency in Hz. 24- clock-frequency : desired I2C bus clock frequency in Hz.
25- ti,has-pfunc: boolean; if defined, it indicates that SoC supports PFUNC 25- ti,has-pfunc: boolean; if defined, it indicates that SoC supports PFUNC
26 registers. PFUNC registers allow to switch I2C pins to function as 26 registers. PFUNC registers allow to switch I2C pins to function as
27 GPIOs, so they can by toggled manually. 27 GPIOs, so they can be toggled manually.
28 28
29Example (enbw_cmc board): 29Example (enbw_cmc board):
30 i2c@1c22000 { 30 i2c@1c22000 {
diff --git a/Documentation/devicetree/bindings/i2c/i2c-rcar.txt b/Documentation/devicetree/bindings/i2c/i2c-rcar.txt
index 4a7811ecd954..7ce8fae55537 100644
--- a/Documentation/devicetree/bindings/i2c/i2c-rcar.txt
+++ b/Documentation/devicetree/bindings/i2c/i2c-rcar.txt
@@ -15,6 +15,7 @@ Required properties:
15 "renesas,i2c-r8a7796" if the device is a part of a R8A7796 SoC. 15 "renesas,i2c-r8a7796" if the device is a part of a R8A7796 SoC.
16 "renesas,i2c-r8a77965" if the device is a part of a R8A77965 SoC. 16 "renesas,i2c-r8a77965" if the device is a part of a R8A77965 SoC.
17 "renesas,i2c-r8a77970" if the device is a part of a R8A77970 SoC. 17 "renesas,i2c-r8a77970" if the device is a part of a R8A77970 SoC.
18 "renesas,i2c-r8a77980" if the device is a part of a R8A77980 SoC.
18 "renesas,i2c-r8a77995" if the device is a part of a R8A77995 SoC. 19 "renesas,i2c-r8a77995" if the device is a part of a R8A77995 SoC.
19 "renesas,rcar-gen1-i2c" for a generic R-Car Gen1 compatible device. 20 "renesas,rcar-gen1-i2c" for a generic R-Car Gen1 compatible device.
20 "renesas,rcar-gen2-i2c" for a generic R-Car Gen2 or RZ/G1 compatible 21 "renesas,rcar-gen2-i2c" for a generic R-Car Gen2 or RZ/G1 compatible
diff --git a/Documentation/devicetree/bindings/i2c/i2c-s3c2410.txt b/Documentation/devicetree/bindings/i2c/i2c-s3c2410.txt
index 89b3250f049b..66ae46d3bc2f 100644
--- a/Documentation/devicetree/bindings/i2c/i2c-s3c2410.txt
+++ b/Documentation/devicetree/bindings/i2c/i2c-s3c2410.txt
@@ -8,9 +8,7 @@ Required properties:
8 (b) "samsung, s3c2440-i2c", for i2c compatible with s3c2440 i2c. 8 (b) "samsung, s3c2440-i2c", for i2c compatible with s3c2440 i2c.
9 (c) "samsung, s3c2440-hdmiphy-i2c", for s3c2440-like i2c used 9 (c) "samsung, s3c2440-hdmiphy-i2c", for s3c2440-like i2c used
10 inside HDMIPHY block found on several samsung SoCs 10 inside HDMIPHY block found on several samsung SoCs
11 (d) "samsung, exynos5440-i2c", for s3c2440-like i2c used 11 (d) "samsung, exynos5-sata-phy-i2c", for s3c2440-like i2c used as
12 on EXYNOS5440 which does not need GPIO configuration.
13 (e) "samsung, exynos5-sata-phy-i2c", for s3c2440-like i2c used as
14 a host to SATA PHY controller on an internal bus. 12 a host to SATA PHY controller on an internal bus.
15 - reg: physical base address of the controller and length of memory mapped 13 - reg: physical base address of the controller and length of memory mapped
16 region. 14 region.
diff --git a/Documentation/i2c/busses/i2c-mlxcpld b/Documentation/i2c/busses/i2c-mlxcpld
index 4e46c440b38d..925904aa9b57 100644
--- a/Documentation/i2c/busses/i2c-mlxcpld
+++ b/Documentation/i2c/busses/i2c-mlxcpld
@@ -20,6 +20,10 @@ The next transaction types are supported:
20 - Write Byte/Block. 20 - Write Byte/Block.
21 21
22Registers: 22Registers:
23CPBLTY 0x0 - capability reg.
24 Bits [6:5] - transaction length. b01 - 72B is supported,
25 36B in other case.
26 Bit 7 - SMBus block read support.
23CTRL 0x1 - control reg. 27CTRL 0x1 - control reg.
24 Resets all the registers. 28 Resets all the registers.
25HALF_CYC 0x4 - cycle reg. 29HALF_CYC 0x4 - cycle reg.
diff --git a/Documentation/i2c/busses/i2c-ocores b/Documentation/i2c/busses/i2c-ocores
index 9e1dfe7553ad..4e713f4cdb2f 100644
--- a/Documentation/i2c/busses/i2c-ocores
+++ b/Documentation/i2c/busses/i2c-ocores
@@ -18,7 +18,7 @@ Usage
18i2c-ocores uses the platform bus, so you need to provide a struct 18i2c-ocores uses the platform bus, so you need to provide a struct
19platform_device with the base address and interrupt number. The 19platform_device with the base address and interrupt number. The
20dev.platform_data of the device should also point to a struct 20dev.platform_data of the device should also point to a struct
21ocores_i2c_platform_data (see linux/i2c-ocores.h) describing the 21ocores_i2c_platform_data (see linux/platform_data/i2c-ocores.h) describing the
22distance between registers and the input clock speed. 22distance between registers and the input clock speed.
23There is also a possibility to attach a list of i2c_board_info which 23There is also a possibility to attach a list of i2c_board_info which
24the i2c-ocores driver will add to the bus upon creation. 24the i2c-ocores driver will add to the bus upon creation.
diff --git a/Documentation/i2c/muxes/i2c-mux-gpio b/Documentation/i2c/muxes/i2c-mux-gpio
index 7a8d7d261632..893ecdfe6e43 100644
--- a/Documentation/i2c/muxes/i2c-mux-gpio
+++ b/Documentation/i2c/muxes/i2c-mux-gpio
@@ -30,12 +30,12 @@ i2c-mux-gpio uses the platform bus, so you need to provide a struct
30platform_device with the platform_data pointing to a struct 30platform_device with the platform_data pointing to a struct
31i2c_mux_gpio_platform_data with the I2C adapter number of the master 31i2c_mux_gpio_platform_data with the I2C adapter number of the master
32bus, the number of bus segments to create and the GPIO pins used 32bus, the number of bus segments to create and the GPIO pins used
33to control it. See include/linux/i2c-mux-gpio.h for details. 33to control it. See include/linux/platform_data/i2c-mux-gpio.h for details.
34 34
35E.G. something like this for a MUX providing 4 bus segments 35E.G. something like this for a MUX providing 4 bus segments
36controlled through 3 GPIO pins: 36controlled through 3 GPIO pins:
37 37
38#include <linux/i2c-mux-gpio.h> 38#include <linux/platform_data/i2c-mux-gpio.h>
39#include <linux/platform_device.h> 39#include <linux/platform_device.h>
40 40
41static const unsigned myboard_gpiomux_gpios[] = { 41static const unsigned myboard_gpiomux_gpios[] = {
diff --git a/MAINTAINERS b/MAINTAINERS
index c13b9fb3be0b..cb468a535f32 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -5953,14 +5953,14 @@ GENERIC GPIO I2C DRIVER
5953M: Haavard Skinnemoen <hskinnemoen@gmail.com> 5953M: Haavard Skinnemoen <hskinnemoen@gmail.com>
5954S: Supported 5954S: Supported
5955F: drivers/i2c/busses/i2c-gpio.c 5955F: drivers/i2c/busses/i2c-gpio.c
5956F: include/linux/i2c-gpio.h 5956F: include/linux/platform_data/i2c-gpio.h
5957 5957
5958GENERIC GPIO I2C MULTIPLEXER DRIVER 5958GENERIC GPIO I2C MULTIPLEXER DRIVER
5959M: Peter Korsgaard <peter.korsgaard@barco.com> 5959M: Peter Korsgaard <peter.korsgaard@barco.com>
5960L: linux-i2c@vger.kernel.org 5960L: linux-i2c@vger.kernel.org
5961S: Supported 5961S: Supported
5962F: drivers/i2c/muxes/i2c-mux-gpio.c 5962F: drivers/i2c/muxes/i2c-mux-gpio.c
5963F: include/linux/i2c-mux-gpio.h 5963F: include/linux/platform_data/i2c-mux-gpio.h
5964F: Documentation/i2c/muxes/i2c-mux-gpio 5964F: Documentation/i2c/muxes/i2c-mux-gpio
5965 5965
5966GENERIC HDLC (WAN) DRIVERS 5966GENERIC HDLC (WAN) DRIVERS
@@ -10392,7 +10392,7 @@ F: arch/arm/mach-omap1/
10392F: arch/arm/plat-omap/ 10392F: arch/arm/plat-omap/
10393F: arch/arm/configs/omap1_defconfig 10393F: arch/arm/configs/omap1_defconfig
10394F: drivers/i2c/busses/i2c-omap.c 10394F: drivers/i2c/busses/i2c-omap.c
10395F: include/linux/i2c-omap.h 10395F: include/linux/platform_data/i2c-omap.h
10396 10396
10397OMAP2+ SUPPORT 10397OMAP2+ SUPPORT
10398M: Tony Lindgren <tony@atomide.com> 10398M: Tony Lindgren <tony@atomide.com>
@@ -10424,7 +10424,7 @@ F: drivers/regulator/tps65218-regulator.c
10424F: drivers/regulator/tps65910-regulator.c 10424F: drivers/regulator/tps65910-regulator.c
10425F: drivers/regulator/twl-regulator.c 10425F: drivers/regulator/twl-regulator.c
10426F: drivers/regulator/twl6030-regulator.c 10426F: drivers/regulator/twl6030-regulator.c
10427F: include/linux/i2c-omap.h 10427F: include/linux/platform_data/i2c-omap.h
10428 10428
10429ONION OMEGA2+ BOARD 10429ONION OMEGA2+ BOARD
10430M: Harvey Hunt <harveyhuntnexus@gmail.com> 10430M: Harvey Hunt <harveyhuntnexus@gmail.com>
diff --git a/arch/arm/mach-ks8695/board-acs5k.c b/arch/arm/mach-ks8695/board-acs5k.c
index 937eb1d47e7b..ef835d82cdb9 100644
--- a/arch/arm/mach-ks8695/board-acs5k.c
+++ b/arch/arm/mach-ks8695/board-acs5k.c
@@ -19,7 +19,7 @@
19#include <linux/gpio/machine.h> 19#include <linux/gpio/machine.h>
20#include <linux/i2c.h> 20#include <linux/i2c.h>
21#include <linux/i2c-algo-bit.h> 21#include <linux/i2c-algo-bit.h>
22#include <linux/i2c-gpio.h> 22#include <linux/platform_data/i2c-gpio.h>
23#include <linux/platform_data/pca953x.h> 23#include <linux/platform_data/pca953x.h>
24 24
25#include <linux/mtd/mtd.h> 25#include <linux/mtd/mtd.h>
diff --git a/arch/arm/mach-omap1/board-htcherald.c b/arch/arm/mach-omap1/board-htcherald.c
index 67d46690a56e..da8f3fc3180f 100644
--- a/arch/arm/mach-omap1/board-htcherald.c
+++ b/arch/arm/mach-omap1/board-htcherald.c
@@ -31,7 +31,7 @@
31#include <linux/gpio.h> 31#include <linux/gpio.h>
32#include <linux/gpio_keys.h> 32#include <linux/gpio_keys.h>
33#include <linux/i2c.h> 33#include <linux/i2c.h>
34#include <linux/i2c-gpio.h> 34#include <linux/platform_data/i2c-gpio.h>
35#include <linux/htcpld.h> 35#include <linux/htcpld.h>
36#include <linux/leds.h> 36#include <linux/leds.h>
37#include <linux/spi/spi.h> 37#include <linux/spi/spi.h>
diff --git a/arch/arm/mach-omap1/common.h b/arch/arm/mach-omap1/common.h
index d83ff257eaa8..c6537d2c2859 100644
--- a/arch/arm/mach-omap1/common.h
+++ b/arch/arm/mach-omap1/common.h
@@ -27,7 +27,7 @@
27#define __ARCH_ARM_MACH_OMAP1_COMMON_H 27#define __ARCH_ARM_MACH_OMAP1_COMMON_H
28 28
29#include <linux/mtd/mtd.h> 29#include <linux/mtd/mtd.h>
30#include <linux/i2c-omap.h> 30#include <linux/platform_data/i2c-omap.h>
31#include <linux/reboot.h> 31#include <linux/reboot.h>
32 32
33#include <asm/exception.h> 33#include <asm/exception.h>
diff --git a/arch/arm/mach-omap1/i2c.c b/arch/arm/mach-omap1/i2c.c
index 5bdf3c4190f9..9250f263ac51 100644
--- a/arch/arm/mach-omap1/i2c.c
+++ b/arch/arm/mach-omap1/i2c.c
@@ -20,7 +20,7 @@
20 */ 20 */
21 21
22#include <linux/i2c.h> 22#include <linux/i2c.h>
23#include <linux/i2c-omap.h> 23#include <linux/platform_data/i2c-omap.h>
24#include <mach/mux.h> 24#include <mach/mux.h>
25#include "soc.h" 25#include "soc.h"
26 26
diff --git a/arch/arm/mach-omap2/common.h b/arch/arm/mach-omap2/common.h
index dff3750e432f..129455e822e4 100644
--- a/arch/arm/mach-omap2/common.h
+++ b/arch/arm/mach-omap2/common.h
@@ -30,7 +30,7 @@
30#include <linux/delay.h> 30#include <linux/delay.h>
31#include <linux/i2c.h> 31#include <linux/i2c.h>
32#include <linux/mfd/twl.h> 32#include <linux/mfd/twl.h>
33#include <linux/i2c-omap.h> 33#include <linux/platform_data/i2c-omap.h>
34#include <linux/reboot.h> 34#include <linux/reboot.h>
35#include <linux/irqchip/irq-omap-intc.h> 35#include <linux/irqchip/irq-omap-intc.h>
36 36
diff --git a/arch/arm/mach-omap2/omap_hwmod_2420_data.c b/arch/arm/mach-omap2/omap_hwmod_2420_data.c
index fe66cf247874..d684fac8f592 100644
--- a/arch/arm/mach-omap2/omap_hwmod_2420_data.c
+++ b/arch/arm/mach-omap2/omap_hwmod_2420_data.c
@@ -13,7 +13,7 @@
13 * XXX these should be marked initdata for multi-OMAP kernels 13 * XXX these should be marked initdata for multi-OMAP kernels
14 */ 14 */
15 15
16#include <linux/i2c-omap.h> 16#include <linux/platform_data/i2c-omap.h>
17#include <linux/omap-dma.h> 17#include <linux/omap-dma.h>
18 18
19#include "omap_hwmod.h" 19#include "omap_hwmod.h"
diff --git a/arch/arm/mach-omap2/omap_hwmod_2430_data.c b/arch/arm/mach-omap2/omap_hwmod_2430_data.c
index 74eefd30518c..abef9f6f9bf5 100644
--- a/arch/arm/mach-omap2/omap_hwmod_2430_data.c
+++ b/arch/arm/mach-omap2/omap_hwmod_2430_data.c
@@ -13,7 +13,7 @@
13 * XXX these should be marked initdata for multi-OMAP kernels 13 * XXX these should be marked initdata for multi-OMAP kernels
14 */ 14 */
15 15
16#include <linux/i2c-omap.h> 16#include <linux/platform_data/i2c-omap.h>
17#include <linux/platform_data/hsmmc-omap.h> 17#include <linux/platform_data/hsmmc-omap.h>
18#include <linux/omap-dma.h> 18#include <linux/omap-dma.h>
19 19
diff --git a/arch/arm/mach-omap2/omap_hwmod_33xx_data.c b/arch/arm/mach-omap2/omap_hwmod_33xx_data.c
index 53e1ac3724f2..c9483bc06228 100644
--- a/arch/arm/mach-omap2/omap_hwmod_33xx_data.c
+++ b/arch/arm/mach-omap2/omap_hwmod_33xx_data.c
@@ -14,7 +14,7 @@
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 */ 15 */
16 16
17#include <linux/i2c-omap.h> 17#include <linux/platform_data/i2c-omap.h>
18 18
19#include "omap_hwmod.h" 19#include "omap_hwmod.h"
20#include "omap_hwmod_common_data.h" 20#include "omap_hwmod_common_data.h"
diff --git a/arch/arm/mach-omap2/omap_hwmod_3xxx_data.c b/arch/arm/mach-omap2/omap_hwmod_3xxx_data.c
index d93f9ea4119e..23e6a41a18eb 100644
--- a/arch/arm/mach-omap2/omap_hwmod_3xxx_data.c
+++ b/arch/arm/mach-omap2/omap_hwmod_3xxx_data.c
@@ -15,7 +15,7 @@
15 * XXX these should be marked initdata for multi-OMAP kernels 15 * XXX these should be marked initdata for multi-OMAP kernels
16 */ 16 */
17 17
18#include <linux/i2c-omap.h> 18#include <linux/platform_data/i2c-omap.h>
19#include <linux/power/smartreflex.h> 19#include <linux/power/smartreflex.h>
20#include <linux/platform_data/hsmmc-omap.h> 20#include <linux/platform_data/hsmmc-omap.h>
21 21
diff --git a/arch/arm/mach-omap2/omap_hwmod_44xx_data.c b/arch/arm/mach-omap2/omap_hwmod_44xx_data.c
index 234ee0eec815..a95dbac57a81 100644
--- a/arch/arm/mach-omap2/omap_hwmod_44xx_data.c
+++ b/arch/arm/mach-omap2/omap_hwmod_44xx_data.c
@@ -23,7 +23,7 @@
23#include <linux/io.h> 23#include <linux/io.h>
24#include <linux/platform_data/hsmmc-omap.h> 24#include <linux/platform_data/hsmmc-omap.h>
25#include <linux/power/smartreflex.h> 25#include <linux/power/smartreflex.h>
26#include <linux/i2c-omap.h> 26#include <linux/platform_data/i2c-omap.h>
27 27
28#include <linux/omap-dma.h> 28#include <linux/omap-dma.h>
29 29
diff --git a/arch/arm/mach-omap2/omap_hwmod_54xx_data.c b/arch/arm/mach-omap2/omap_hwmod_54xx_data.c
index 887a30fa775b..115473d441cd 100644
--- a/arch/arm/mach-omap2/omap_hwmod_54xx_data.c
+++ b/arch/arm/mach-omap2/omap_hwmod_54xx_data.c
@@ -20,7 +20,7 @@
20#include <linux/io.h> 20#include <linux/io.h>
21#include <linux/platform_data/hsmmc-omap.h> 21#include <linux/platform_data/hsmmc-omap.h>
22#include <linux/power/smartreflex.h> 22#include <linux/power/smartreflex.h>
23#include <linux/i2c-omap.h> 23#include <linux/platform_data/i2c-omap.h>
24 24
25#include <linux/omap-dma.h> 25#include <linux/omap-dma.h>
26 26
diff --git a/arch/arm/mach-omap2/omap_hwmod_7xx_data.c b/arch/arm/mach-omap2/omap_hwmod_7xx_data.c
index a27c2fed298c..e6c7061a8e73 100644
--- a/arch/arm/mach-omap2/omap_hwmod_7xx_data.c
+++ b/arch/arm/mach-omap2/omap_hwmod_7xx_data.c
@@ -20,7 +20,7 @@
20#include <linux/io.h> 20#include <linux/io.h>
21#include <linux/platform_data/hsmmc-omap.h> 21#include <linux/platform_data/hsmmc-omap.h>
22#include <linux/power/smartreflex.h> 22#include <linux/power/smartreflex.h>
23#include <linux/i2c-omap.h> 23#include <linux/platform_data/i2c-omap.h>
24 24
25#include <linux/omap-dma.h> 25#include <linux/omap-dma.h>
26 26
diff --git a/arch/arm/mach-pxa/palmz72.c b/arch/arm/mach-pxa/palmz72.c
index 0adb1bd6208e..4d475f6f4a77 100644
--- a/arch/arm/mach-pxa/palmz72.c
+++ b/arch/arm/mach-pxa/palmz72.c
@@ -30,7 +30,7 @@
30#include <linux/wm97xx.h> 30#include <linux/wm97xx.h>
31#include <linux/power_supply.h> 31#include <linux/power_supply.h>
32#include <linux/usb/gpio_vbus.h> 32#include <linux/usb/gpio_vbus.h>
33#include <linux/i2c-gpio.h> 33#include <linux/platform_data/i2c-gpio.h>
34#include <linux/gpio/machine.h> 34#include <linux/gpio/machine.h>
35 35
36#include <asm/mach-types.h> 36#include <asm/mach-types.h>
diff --git a/arch/arm/mach-pxa/viper.c b/arch/arm/mach-pxa/viper.c
index 207dcc2e94e7..ab2f89266bbd 100644
--- a/arch/arm/mach-pxa/viper.c
+++ b/arch/arm/mach-pxa/viper.c
@@ -35,7 +35,7 @@
35#include <linux/sched.h> 35#include <linux/sched.h>
36#include <linux/gpio.h> 36#include <linux/gpio.h>
37#include <linux/jiffies.h> 37#include <linux/jiffies.h>
38#include <linux/i2c-gpio.h> 38#include <linux/platform_data/i2c-gpio.h>
39#include <linux/gpio/machine.h> 39#include <linux/gpio/machine.h>
40#include <linux/platform_data/i2c-pxa.h> 40#include <linux/platform_data/i2c-pxa.h>
41#include <linux/serial_8250.h> 41#include <linux/serial_8250.h>
diff --git a/arch/arm/mach-sa1100/simpad.c b/arch/arm/mach-sa1100/simpad.c
index f45aed2519ba..406487e76a5c 100644
--- a/arch/arm/mach-sa1100/simpad.c
+++ b/arch/arm/mach-sa1100/simpad.c
@@ -37,7 +37,7 @@
37#include <linux/input.h> 37#include <linux/input.h>
38#include <linux/gpio_keys.h> 38#include <linux/gpio_keys.h>
39#include <linux/leds.h> 39#include <linux/leds.h>
40#include <linux/i2c-gpio.h> 40#include <linux/platform_data/i2c-gpio.h>
41 41
42#include "generic.h" 42#include "generic.h"
43 43
diff --git a/arch/mips/alchemy/board-gpr.c b/arch/mips/alchemy/board-gpr.c
index 4e79dbd54a33..fa75d75b5ba9 100644
--- a/arch/mips/alchemy/board-gpr.c
+++ b/arch/mips/alchemy/board-gpr.c
@@ -29,7 +29,7 @@
29#include <linux/leds.h> 29#include <linux/leds.h>
30#include <linux/gpio.h> 30#include <linux/gpio.h>
31#include <linux/i2c.h> 31#include <linux/i2c.h>
32#include <linux/i2c-gpio.h> 32#include <linux/platform_data/i2c-gpio.h>
33#include <linux/gpio/machine.h> 33#include <linux/gpio/machine.h>
34#include <asm/bootinfo.h> 34#include <asm/bootinfo.h>
35#include <asm/idle.h> 35#include <asm/idle.h>
diff --git a/arch/sh/boards/board-sh7785lcr.c b/arch/sh/boards/board-sh7785lcr.c
index d7d232dea33e..3cba60ff7aab 100644
--- a/arch/sh/boards/board-sh7785lcr.c
+++ b/arch/sh/boards/board-sh7785lcr.c
@@ -17,7 +17,7 @@
17#include <linux/delay.h> 17#include <linux/delay.h>
18#include <linux/interrupt.h> 18#include <linux/interrupt.h>
19#include <linux/i2c.h> 19#include <linux/i2c.h>
20#include <linux/i2c-pca-platform.h> 20#include <linux/platform_data/i2c-pca-platform.h>
21#include <linux/i2c-algo-pca.h> 21#include <linux/i2c-algo-pca.h>
22#include <linux/usb/r8a66597.h> 22#include <linux/usb/r8a66597.h>
23#include <linux/sh_intc.h> 23#include <linux/sh_intc.h>
diff --git a/drivers/i2c/algos/i2c-algo-bit.c b/drivers/i2c/algos/i2c-algo-bit.c
index 3df0efd69ae3..4a34f311e1ff 100644
--- a/drivers/i2c/algos/i2c-algo-bit.c
+++ b/drivers/i2c/algos/i2c-algo-bit.c
@@ -519,9 +519,7 @@ static int bit_doAddress(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
519 } 519 }
520 } 520 }
521 } else { /* normal 7bit address */ 521 } else { /* normal 7bit address */
522 addr = msg->addr << 1; 522 addr = i2c_8bit_addr_from_msg(msg);
523 if (flags & I2C_M_RD)
524 addr |= 1;
525 if (flags & I2C_M_REV_DIR_ADDR) 523 if (flags & I2C_M_REV_DIR_ADDR)
526 addr ^= 1; 524 addr ^= 1;
527 ret = try_address(i2c_adap, addr, retries); 525 ret = try_address(i2c_adap, addr, retries);
diff --git a/drivers/i2c/algos/i2c-algo-pca.c b/drivers/i2c/algos/i2c-algo-pca.c
index e370804ec8bc..883a290f6a4d 100644
--- a/drivers/i2c/algos/i2c-algo-pca.c
+++ b/drivers/i2c/algos/i2c-algo-pca.c
@@ -112,11 +112,8 @@ static int pca_address(struct i2c_algo_pca_data *adap,
112 struct i2c_msg *msg) 112 struct i2c_msg *msg)
113{ 113{
114 int sta = pca_get_con(adap); 114 int sta = pca_get_con(adap);
115 int addr; 115 int addr = i2c_8bit_addr_from_msg(msg);
116 116
117 addr = ((0x7f & msg->addr) << 1);
118 if (msg->flags & I2C_M_RD)
119 addr |= 1;
120 DEB2("=== SLAVE ADDRESS %#04x+%c=%#04x\n", 117 DEB2("=== SLAVE ADDRESS %#04x+%c=%#04x\n",
121 msg->addr, msg->flags & I2C_M_RD ? 'R' : 'W', addr); 118 msg->addr, msg->flags & I2C_M_RD ? 'R' : 'W', addr);
122 119
diff --git a/drivers/i2c/algos/i2c-algo-pcf.c b/drivers/i2c/algos/i2c-algo-pcf.c
index 270d84bfc2c6..5c29a4d397cf 100644
--- a/drivers/i2c/algos/i2c-algo-pcf.c
+++ b/drivers/i2c/algos/i2c-algo-pcf.c
@@ -291,13 +291,9 @@ static int pcf_readbytes(struct i2c_adapter *i2c_adap, char *buf,
291static int pcf_doAddress(struct i2c_algo_pcf_data *adap, 291static int pcf_doAddress(struct i2c_algo_pcf_data *adap,
292 struct i2c_msg *msg) 292 struct i2c_msg *msg)
293{ 293{
294 unsigned short flags = msg->flags; 294 unsigned char addr = i2c_8bit_addr_from_msg(msg);
295 unsigned char addr;
296 295
297 addr = msg->addr << 1; 296 if (msg->flags & I2C_M_REV_DIR_ADDR)
298 if (flags & I2C_M_RD)
299 addr |= 1;
300 if (flags & I2C_M_REV_DIR_ADDR)
301 addr ^= 1; 297 addr ^= 1;
302 i2c_outb(adap, addr); 298 i2c_outb(adap, addr);
303 299
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index fce9f2ca0570..4f8df2ec87b1 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -943,6 +943,7 @@ config I2C_STM32F4
943config I2C_STM32F7 943config I2C_STM32F7
944 tristate "STMicroelectronics STM32F7 I2C support" 944 tristate "STMicroelectronics STM32F7 I2C support"
945 depends on ARCH_STM32 || COMPILE_TEST 945 depends on ARCH_STM32 || COMPILE_TEST
946 select I2C_SLAVE
946 help 947 help
947 Enable this option to add support for STM32 I2C controller embedded 948 Enable this option to add support for STM32 I2C controller embedded
948 in STM32F7 SoCs. 949 in STM32F7 SoCs.
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
index 189e34ba050f..5a869144a0c5 100644
--- a/drivers/i2c/busses/Makefile
+++ b/drivers/i2c/busses/Makefile
@@ -94,7 +94,8 @@ obj-$(CONFIG_I2C_SIRF) += i2c-sirf.o
94obj-$(CONFIG_I2C_SPRD) += i2c-sprd.o 94obj-$(CONFIG_I2C_SPRD) += i2c-sprd.o
95obj-$(CONFIG_I2C_ST) += i2c-st.o 95obj-$(CONFIG_I2C_ST) += i2c-st.o
96obj-$(CONFIG_I2C_STM32F4) += i2c-stm32f4.o 96obj-$(CONFIG_I2C_STM32F4) += i2c-stm32f4.o
97obj-$(CONFIG_I2C_STM32F7) += i2c-stm32f7.o 97i2c-stm32f7-drv-objs := i2c-stm32f7.o i2c-stm32.o
98obj-$(CONFIG_I2C_STM32F7) += i2c-stm32f7-drv.o
98obj-$(CONFIG_I2C_STU300) += i2c-stu300.o 99obj-$(CONFIG_I2C_STU300) += i2c-stu300.o
99obj-$(CONFIG_I2C_SUN6I_P2WI) += i2c-sun6i-p2wi.o 100obj-$(CONFIG_I2C_SUN6I_P2WI) += i2c-sun6i-p2wi.o
100obj-$(CONFIG_I2C_SYNQUACER) += i2c-synquacer.o 101obj-$(CONFIG_I2C_SYNQUACER) += i2c-synquacer.o
diff --git a/drivers/i2c/busses/i2c-aspeed.c b/drivers/i2c/busses/i2c-aspeed.c
index 7d4aeb4465b3..60e4d0e939a3 100644
--- a/drivers/i2c/busses/i2c-aspeed.c
+++ b/drivers/i2c/busses/i2c-aspeed.c
@@ -335,13 +335,12 @@ static void aspeed_i2c_do_start(struct aspeed_i2c_bus *bus)
335{ 335{
336 u32 command = ASPEED_I2CD_M_START_CMD | ASPEED_I2CD_M_TX_CMD; 336 u32 command = ASPEED_I2CD_M_START_CMD | ASPEED_I2CD_M_TX_CMD;
337 struct i2c_msg *msg = &bus->msgs[bus->msgs_index]; 337 struct i2c_msg *msg = &bus->msgs[bus->msgs_index];
338 u8 slave_addr = msg->addr << 1; 338 u8 slave_addr = i2c_8bit_addr_from_msg(msg);
339 339
340 bus->master_state = ASPEED_I2C_MASTER_START; 340 bus->master_state = ASPEED_I2C_MASTER_START;
341 bus->buf_index = 0; 341 bus->buf_index = 0;
342 342
343 if (msg->flags & I2C_M_RD) { 343 if (msg->flags & I2C_M_RD) {
344 slave_addr |= 1;
345 command |= ASPEED_I2CD_M_RX_CMD; 344 command |= ASPEED_I2CD_M_RX_CMD;
346 /* Need to let the hardware know to NACK after RX. */ 345 /* Need to let the hardware know to NACK after RX. */
347 if (msg->len == 1 && !(msg->flags & I2C_M_RECV_LEN)) 346 if (msg->len == 1 && !(msg->flags & I2C_M_RECV_LEN))
diff --git a/drivers/i2c/busses/i2c-at91.c b/drivers/i2c/busses/i2c-at91.c
index bfd1fdff64a9..3f3e8b3bf5ff 100644
--- a/drivers/i2c/busses/i2c-at91.c
+++ b/drivers/i2c/busses/i2c-at91.c
@@ -518,8 +518,16 @@ static irqreturn_t atmel_twi_interrupt(int irq, void *dev_id)
518 * the RXRDY interrupt first in order to not keep garbage data in the 518 * the RXRDY interrupt first in order to not keep garbage data in the
519 * Receive Holding Register for the next transfer. 519 * Receive Holding Register for the next transfer.
520 */ 520 */
521 if (irqstatus & AT91_TWI_RXRDY) 521 if (irqstatus & AT91_TWI_RXRDY) {
522 at91_twi_read_next_byte(dev); 522 /*
523 * Read all available bytes at once by polling RXRDY usable w/
524 * and w/o FIFO. With FIFO enabled we could also read RXFL and
525 * avoid polling RXRDY.
526 */
527 do {
528 at91_twi_read_next_byte(dev);
529 } while (at91_twi_read(dev, AT91_TWI_SR) & AT91_TWI_RXRDY);
530 }
523 531
524 /* 532 /*
525 * When a NACK condition is detected, the I2C controller sets the NACK, 533 * When a NACK condition is detected, the I2C controller sets the NACK,
diff --git a/drivers/i2c/busses/i2c-axxia.c b/drivers/i2c/busses/i2c-axxia.c
index 13f07482ec68..8e60048a33f8 100644
--- a/drivers/i2c/busses/i2c-axxia.c
+++ b/drivers/i2c/busses/i2c-axxia.c
@@ -351,13 +351,15 @@ static int axxia_i2c_xfer_msg(struct axxia_i2c_dev *idev, struct i2c_msg *msg)
351 * addr_2: addr[7:0] 351 * addr_2: addr[7:0]
352 */ 352 */
353 addr_1 = 0xF0 | ((msg->addr >> 7) & 0x06); 353 addr_1 = 0xF0 | ((msg->addr >> 7) & 0x06);
354 if (i2c_m_rd(msg))
355 addr_1 |= 1; /* Set the R/nW bit of the address */
354 addr_2 = msg->addr & 0xFF; 356 addr_2 = msg->addr & 0xFF;
355 } else { 357 } else {
356 /* 7-bit address 358 /* 7-bit address
357 * addr_1: addr[6:0] | (R/nW) 359 * addr_1: addr[6:0] | (R/nW)
358 * addr_2: dont care 360 * addr_2: dont care
359 */ 361 */
360 addr_1 = (msg->addr << 1) & 0xFF; 362 addr_1 = i2c_8bit_addr_from_msg(msg);
361 addr_2 = 0; 363 addr_2 = 0;
362 } 364 }
363 365
@@ -365,7 +367,6 @@ static int axxia_i2c_xfer_msg(struct axxia_i2c_dev *idev, struct i2c_msg *msg)
365 /* I2C read transfer */ 367 /* I2C read transfer */
366 rx_xfer = i2c_m_recv_len(msg) ? I2C_SMBUS_BLOCK_MAX : msg->len; 368 rx_xfer = i2c_m_recv_len(msg) ? I2C_SMBUS_BLOCK_MAX : msg->len;
367 tx_xfer = 0; 369 tx_xfer = 0;
368 addr_1 |= 1; /* Set the R/nW bit of the address */
369 } else { 370 } else {
370 /* I2C write transfer */ 371 /* I2C write transfer */
371 rx_xfer = 0; 372 rx_xfer = 0;
@@ -532,23 +533,23 @@ static int axxia_i2c_probe(struct platform_device *pdev)
532 if (idev->bus_clk_rate == 0) 533 if (idev->bus_clk_rate == 0)
533 idev->bus_clk_rate = 100000; /* default clock rate */ 534 idev->bus_clk_rate = 100000; /* default clock rate */
534 535
536 ret = clk_prepare_enable(idev->i2c_clk);
537 if (ret) {
538 dev_err(&pdev->dev, "failed to enable clock\n");
539 return ret;
540 }
541
535 ret = axxia_i2c_init(idev); 542 ret = axxia_i2c_init(idev);
536 if (ret) { 543 if (ret) {
537 dev_err(&pdev->dev, "failed to initialize\n"); 544 dev_err(&pdev->dev, "failed to initialize\n");
538 return ret; 545 goto error_disable_clk;
539 } 546 }
540 547
541 ret = devm_request_irq(&pdev->dev, irq, axxia_i2c_isr, 0, 548 ret = devm_request_irq(&pdev->dev, irq, axxia_i2c_isr, 0,
542 pdev->name, idev); 549 pdev->name, idev);
543 if (ret) { 550 if (ret) {
544 dev_err(&pdev->dev, "failed to claim IRQ%d\n", irq); 551 dev_err(&pdev->dev, "failed to claim IRQ%d\n", irq);
545 return ret; 552 goto error_disable_clk;
546 }
547
548 ret = clk_prepare_enable(idev->i2c_clk);
549 if (ret) {
550 dev_err(&pdev->dev, "failed to enable clock\n");
551 return ret;
552 } 553 }
553 554
554 i2c_set_adapdata(&idev->adapter, idev); 555 i2c_set_adapdata(&idev->adapter, idev);
@@ -563,12 +564,14 @@ static int axxia_i2c_probe(struct platform_device *pdev)
563 platform_set_drvdata(pdev, idev); 564 platform_set_drvdata(pdev, idev);
564 565
565 ret = i2c_add_adapter(&idev->adapter); 566 ret = i2c_add_adapter(&idev->adapter);
566 if (ret) { 567 if (ret)
567 clk_disable_unprepare(idev->i2c_clk); 568 goto error_disable_clk;
568 return ret;
569 }
570 569
571 return 0; 570 return 0;
571
572error_disable_clk:
573 clk_disable_unprepare(idev->i2c_clk);
574 return ret;
572} 575}
573 576
574static int axxia_i2c_remove(struct platform_device *pdev) 577static int axxia_i2c_remove(struct platform_device *pdev)
diff --git a/drivers/i2c/busses/i2c-designware-common.c b/drivers/i2c/busses/i2c-designware-common.c
index 27ebd90de43b..48914dfc8ce8 100644
--- a/drivers/i2c/busses/i2c-designware-common.c
+++ b/drivers/i2c/busses/i2c-designware-common.c
@@ -149,18 +149,17 @@ u32 i2c_dw_scl_lcnt(u32 ic_clk, u32 tLOW, u32 tf, int offset)
149 return ((ic_clk * (tLOW + tf) + 500000) / 1000000) - 1 + offset; 149 return ((ic_clk * (tLOW + tf) + 500000) / 1000000) - 1 + offset;
150} 150}
151 151
152void __i2c_dw_enable(struct dw_i2c_dev *dev, bool enable) 152void __i2c_dw_disable(struct dw_i2c_dev *dev)
153{
154 dw_writel(dev, enable, DW_IC_ENABLE);
155}
156
157void __i2c_dw_enable_and_wait(struct dw_i2c_dev *dev, bool enable)
158{ 153{
159 int timeout = 100; 154 int timeout = 100;
160 155
161 do { 156 do {
162 __i2c_dw_enable(dev, enable); 157 __i2c_dw_disable_nowait(dev);
163 if ((dw_readl(dev, DW_IC_ENABLE_STATUS) & 1) == enable) 158 /*
159 * The enable status register may be unimplemented, but
160 * in that case this test reads zero and exits the loop.
161 */
162 if ((dw_readl(dev, DW_IC_ENABLE_STATUS) & 1) == 0)
164 return; 163 return;
165 164
166 /* 165 /*
@@ -171,8 +170,7 @@ void __i2c_dw_enable_and_wait(struct dw_i2c_dev *dev, bool enable)
171 usleep_range(25, 250); 170 usleep_range(25, 250);
172 } while (timeout--); 171 } while (timeout--);
173 172
174 dev_warn(dev->dev, "timeout in %sabling adapter\n", 173 dev_warn(dev->dev, "timeout in disabling adapter\n");
175 enable ? "en" : "dis");
176} 174}
177 175
178unsigned long i2c_dw_clk_rate(struct dw_i2c_dev *dev) 176unsigned long i2c_dw_clk_rate(struct dw_i2c_dev *dev)
@@ -277,7 +275,7 @@ u32 i2c_dw_func(struct i2c_adapter *adap)
277void i2c_dw_disable(struct dw_i2c_dev *dev) 275void i2c_dw_disable(struct dw_i2c_dev *dev)
278{ 276{
279 /* Disable controller */ 277 /* Disable controller */
280 __i2c_dw_enable_and_wait(dev, false); 278 __i2c_dw_disable(dev);
281 279
282 /* Disable all interupts */ 280 /* Disable all interupts */
283 dw_writel(dev, 0, DW_IC_INTR_MASK); 281 dw_writel(dev, 0, DW_IC_INTR_MASK);
diff --git a/drivers/i2c/busses/i2c-designware-core.h b/drivers/i2c/busses/i2c-designware-core.h
index 8707c76b2fee..d690e648bc01 100644
--- a/drivers/i2c/busses/i2c-designware-core.h
+++ b/drivers/i2c/busses/i2c-designware-core.h
@@ -297,8 +297,6 @@ u32 dw_readl(struct dw_i2c_dev *dev, int offset);
297void dw_writel(struct dw_i2c_dev *dev, u32 b, int offset); 297void dw_writel(struct dw_i2c_dev *dev, u32 b, int offset);
298u32 i2c_dw_scl_hcnt(u32 ic_clk, u32 tSYMBOL, u32 tf, int cond, int offset); 298u32 i2c_dw_scl_hcnt(u32 ic_clk, u32 tSYMBOL, u32 tf, int cond, int offset);
299u32 i2c_dw_scl_lcnt(u32 ic_clk, u32 tLOW, u32 tf, int offset); 299u32 i2c_dw_scl_lcnt(u32 ic_clk, u32 tLOW, u32 tf, int offset);
300void __i2c_dw_enable(struct dw_i2c_dev *dev, bool enable);
301void __i2c_dw_enable_and_wait(struct dw_i2c_dev *dev, bool enable);
302unsigned long i2c_dw_clk_rate(struct dw_i2c_dev *dev); 300unsigned long i2c_dw_clk_rate(struct dw_i2c_dev *dev);
303int i2c_dw_prepare_clk(struct dw_i2c_dev *dev, bool prepare); 301int i2c_dw_prepare_clk(struct dw_i2c_dev *dev, bool prepare);
304int i2c_dw_acquire_lock(struct dw_i2c_dev *dev); 302int i2c_dw_acquire_lock(struct dw_i2c_dev *dev);
@@ -309,6 +307,18 @@ u32 i2c_dw_func(struct i2c_adapter *adap);
309void i2c_dw_disable(struct dw_i2c_dev *dev); 307void i2c_dw_disable(struct dw_i2c_dev *dev);
310void i2c_dw_disable_int(struct dw_i2c_dev *dev); 308void i2c_dw_disable_int(struct dw_i2c_dev *dev);
311 309
310static inline void __i2c_dw_enable(struct dw_i2c_dev *dev)
311{
312 dw_writel(dev, 1, DW_IC_ENABLE);
313}
314
315static inline void __i2c_dw_disable_nowait(struct dw_i2c_dev *dev)
316{
317 dw_writel(dev, 0, DW_IC_ENABLE);
318}
319
320void __i2c_dw_disable(struct dw_i2c_dev *dev);
321
312extern u32 i2c_dw_read_comp_param(struct dw_i2c_dev *dev); 322extern u32 i2c_dw_read_comp_param(struct dw_i2c_dev *dev);
313extern int i2c_dw_probe(struct dw_i2c_dev *dev); 323extern int i2c_dw_probe(struct dw_i2c_dev *dev);
314#if IS_ENABLED(CONFIG_I2C_DESIGNWARE_SLAVE) 324#if IS_ENABLED(CONFIG_I2C_DESIGNWARE_SLAVE)
diff --git a/drivers/i2c/busses/i2c-designware-master.c b/drivers/i2c/busses/i2c-designware-master.c
index 0cdba29ae0a9..27436a937492 100644
--- a/drivers/i2c/busses/i2c-designware-master.c
+++ b/drivers/i2c/busses/i2c-designware-master.c
@@ -81,7 +81,7 @@ static int i2c_dw_init_master(struct dw_i2c_dev *dev)
81 comp_param1 = dw_readl(dev, DW_IC_COMP_PARAM_1); 81 comp_param1 = dw_readl(dev, DW_IC_COMP_PARAM_1);
82 82
83 /* Disable the adapter */ 83 /* Disable the adapter */
84 __i2c_dw_enable_and_wait(dev, false); 84 __i2c_dw_disable(dev);
85 85
86 /* Set standard and fast speed deviders for high/low periods */ 86 /* Set standard and fast speed deviders for high/low periods */
87 87
@@ -180,7 +180,7 @@ static void i2c_dw_xfer_init(struct dw_i2c_dev *dev)
180 u32 ic_con, ic_tar = 0; 180 u32 ic_con, ic_tar = 0;
181 181
182 /* Disable the adapter */ 182 /* Disable the adapter */
183 __i2c_dw_enable_and_wait(dev, false); 183 __i2c_dw_disable(dev);
184 184
185 /* If the slave address is ten bit address, enable 10BITADDR */ 185 /* If the slave address is ten bit address, enable 10BITADDR */
186 ic_con = dw_readl(dev, DW_IC_CON); 186 ic_con = dw_readl(dev, DW_IC_CON);
@@ -209,7 +209,7 @@ static void i2c_dw_xfer_init(struct dw_i2c_dev *dev)
209 i2c_dw_disable_int(dev); 209 i2c_dw_disable_int(dev);
210 210
211 /* Enable the adapter */ 211 /* Enable the adapter */
212 __i2c_dw_enable(dev, true); 212 __i2c_dw_enable(dev);
213 213
214 /* Dummy read to avoid the register getting stuck on Bay Trail */ 214 /* Dummy read to avoid the register getting stuck on Bay Trail */
215 dw_readl(dev, DW_IC_ENABLE_STATUS); 215 dw_readl(dev, DW_IC_ENABLE_STATUS);
@@ -462,7 +462,7 @@ i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
462 * additional interrupts are a hardware bug or this driver doesn't 462 * additional interrupts are a hardware bug or this driver doesn't
463 * handle them correctly yet. 463 * handle them correctly yet.
464 */ 464 */
465 __i2c_dw_enable(dev, false); 465 __i2c_dw_disable_nowait(dev);
466 466
467 if (dev->msg_err) { 467 if (dev->msg_err) {
468 ret = dev->msg_err; 468 ret = dev->msg_err;
diff --git a/drivers/i2c/busses/i2c-designware-slave.c b/drivers/i2c/busses/i2c-designware-slave.c
index d42558d1b002..8ce2cd368477 100644
--- a/drivers/i2c/busses/i2c-designware-slave.c
+++ b/drivers/i2c/busses/i2c-designware-slave.c
@@ -75,7 +75,7 @@ static int i2c_dw_init_slave(struct dw_i2c_dev *dev)
75 comp_param1 = dw_readl(dev, DW_IC_COMP_PARAM_1); 75 comp_param1 = dw_readl(dev, DW_IC_COMP_PARAM_1);
76 76
77 /* Disable the adapter. */ 77 /* Disable the adapter. */
78 __i2c_dw_enable_and_wait(dev, false); 78 __i2c_dw_disable(dev);
79 79
80 /* Configure SDA Hold Time if required. */ 80 /* Configure SDA Hold Time if required. */
81 reg = dw_readl(dev, DW_IC_COMP_VERSION); 81 reg = dw_readl(dev, DW_IC_COMP_VERSION);
@@ -119,11 +119,11 @@ static int i2c_dw_reg_slave(struct i2c_client *slave)
119 * Set slave address in the IC_SAR register, 119 * Set slave address in the IC_SAR register,
120 * the address to which the DW_apb_i2c responds. 120 * the address to which the DW_apb_i2c responds.
121 */ 121 */
122 __i2c_dw_enable(dev, false); 122 __i2c_dw_disable_nowait(dev);
123 dw_writel(dev, slave->addr, DW_IC_SAR); 123 dw_writel(dev, slave->addr, DW_IC_SAR);
124 dev->slave = slave; 124 dev->slave = slave;
125 125
126 __i2c_dw_enable(dev, true); 126 __i2c_dw_enable(dev);
127 127
128 dev->cmd_err = 0; 128 dev->cmd_err = 0;
129 dev->msg_write_idx = 0; 129 dev->msg_write_idx = 0;
diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
index f718ee4e3332..3f28317cde39 100644
--- a/drivers/i2c/busses/i2c-diolan-u2c.c
+++ b/drivers/i2c/busses/i2c-diolan-u2c.c
@@ -360,11 +360,11 @@ static int diolan_usb_xfer(struct i2c_adapter *adapter, struct i2c_msg *msgs,
360 if (ret < 0) 360 if (ret < 0)
361 goto abort; 361 goto abort;
362 } 362 }
363 ret = diolan_i2c_put_byte_ack(dev,
364 i2c_8bit_addr_from_msg(pmsg));
365 if (ret < 0)
366 goto abort;
363 if (pmsg->flags & I2C_M_RD) { 367 if (pmsg->flags & I2C_M_RD) {
364 ret =
365 diolan_i2c_put_byte_ack(dev, (pmsg->addr << 1) | 1);
366 if (ret < 0)
367 goto abort;
368 for (j = 0; j < pmsg->len; j++) { 368 for (j = 0; j < pmsg->len; j++) {
369 u8 byte; 369 u8 byte;
370 bool ack = j < pmsg->len - 1; 370 bool ack = j < pmsg->len - 1;
@@ -393,9 +393,6 @@ static int diolan_usb_xfer(struct i2c_adapter *adapter, struct i2c_msg *msgs,
393 pmsg->buf[j] = byte; 393 pmsg->buf[j] = byte;
394 } 394 }
395 } else { 395 } else {
396 ret = diolan_i2c_put_byte_ack(dev, pmsg->addr << 1);
397 if (ret < 0)
398 goto abort;
399 for (j = 0; j < pmsg->len; j++) { 396 for (j = 0; j < pmsg->len; j++) {
400 ret = diolan_i2c_put_byte_ack(dev, 397 ret = diolan_i2c_put_byte_ack(dev,
401 pmsg->buf[j]); 398 pmsg->buf[j]);
diff --git a/drivers/i2c/busses/i2c-efm32.c b/drivers/i2c/busses/i2c-efm32.c
index aa336ba89aa3..5f2bab878b2c 100644
--- a/drivers/i2c/busses/i2c-efm32.c
+++ b/drivers/i2c/busses/i2c-efm32.c
@@ -144,8 +144,7 @@ static void efm32_i2c_send_next_msg(struct efm32_i2c_ddata *ddata)
144 struct i2c_msg *cur_msg = &ddata->msgs[ddata->current_msg]; 144 struct i2c_msg *cur_msg = &ddata->msgs[ddata->current_msg];
145 145
146 efm32_i2c_write32(ddata, REG_CMD, REG_CMD_START); 146 efm32_i2c_write32(ddata, REG_CMD, REG_CMD_START);
147 efm32_i2c_write32(ddata, REG_TXDATA, cur_msg->addr << 1 | 147 efm32_i2c_write32(ddata, REG_TXDATA, i2c_8bit_addr_from_msg(cur_msg));
148 (cur_msg->flags & I2C_M_RD ? 1 : 0));
149} 148}
150 149
151static void efm32_i2c_send_next_byte(struct efm32_i2c_ddata *ddata) 150static void efm32_i2c_send_next_byte(struct efm32_i2c_ddata *ddata)
diff --git a/drivers/i2c/busses/i2c-eg20t.c b/drivers/i2c/busses/i2c-eg20t.c
index bdeab0174fec..835d54ac2971 100644
--- a/drivers/i2c/busses/i2c-eg20t.c
+++ b/drivers/i2c/busses/i2c-eg20t.c
@@ -414,7 +414,7 @@ static s32 pch_i2c_writebytes(struct i2c_adapter *i2c_adap,
414 iowrite32(addr_8_lsb, p + PCH_I2CDR); 414 iowrite32(addr_8_lsb, p + PCH_I2CDR);
415 } else { 415 } else {
416 /* set 7 bit slave address and R/W bit as 0 */ 416 /* set 7 bit slave address and R/W bit as 0 */
417 iowrite32(addr << 1, p + PCH_I2CDR); 417 iowrite32(i2c_8bit_addr_from_msg(msgs), p + PCH_I2CDR);
418 if (first) 418 if (first)
419 pch_i2c_start(adap); 419 pch_i2c_start(adap);
420 } 420 }
@@ -538,8 +538,7 @@ static s32 pch_i2c_readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs,
538 iowrite32(addr_2_msb | TEN_BIT_ADDR_MASK, p + PCH_I2CDR); 538 iowrite32(addr_2_msb | TEN_BIT_ADDR_MASK, p + PCH_I2CDR);
539 } else { 539 } else {
540 /* 7 address bits + R/W bit */ 540 /* 7 address bits + R/W bit */
541 addr = (((addr) << 1) | (I2C_RD)); 541 iowrite32(i2c_8bit_addr_from_msg(msgs), p + PCH_I2CDR);
542 iowrite32(addr, p + PCH_I2CDR);
543 } 542 }
544 543
545 /* check if it is the first message */ 544 /* check if it is the first message */
diff --git a/drivers/i2c/busses/i2c-emev2.c b/drivers/i2c/busses/i2c-emev2.c
index d2e84480fbe9..ba9b6ea48a31 100644
--- a/drivers/i2c/busses/i2c-emev2.c
+++ b/drivers/i2c/busses/i2c-emev2.c
@@ -149,7 +149,7 @@ static int __em_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,
149 em_clear_set_bit(priv, 0, I2C_BIT_STT0, I2C_OFS_IICC0); 149 em_clear_set_bit(priv, 0, I2C_BIT_STT0, I2C_OFS_IICC0);
150 150
151 /* Send slave address and R/W type */ 151 /* Send slave address and R/W type */
152 writeb((msg->addr << 1) | read, priv->base + I2C_OFS_IIC0); 152 writeb(i2c_8bit_addr_from_msg(msg), priv->base + I2C_OFS_IIC0);
153 153
154 /* Wait for transaction */ 154 /* Wait for transaction */
155 status = em_i2c_wait_for_event(priv); 155 status = em_i2c_wait_for_event(priv);
diff --git a/drivers/i2c/busses/i2c-exynos5.c b/drivers/i2c/busses/i2c-exynos5.c
index 12ec8484e653..de82ad8ff534 100644
--- a/drivers/i2c/busses/i2c-exynos5.c
+++ b/drivers/i2c/busses/i2c-exynos5.c
@@ -707,7 +707,7 @@ static int exynos5_i2c_xfer(struct i2c_adapter *adap,
707 struct i2c_msg *msgs, int num) 707 struct i2c_msg *msgs, int num)
708{ 708{
709 struct exynos5_i2c *i2c = adap->algo_data; 709 struct exynos5_i2c *i2c = adap->algo_data;
710 int i = 0, ret = 0, stop = 0; 710 int i, ret;
711 711
712 if (i2c->suspended) { 712 if (i2c->suspended) {
713 dev_err(i2c->dev, "HS-I2C is not initialized.\n"); 713 dev_err(i2c->dev, "HS-I2C is not initialized.\n");
@@ -718,30 +718,15 @@ static int exynos5_i2c_xfer(struct i2c_adapter *adap,
718 if (ret) 718 if (ret)
719 return ret; 719 return ret;
720 720
721 for (i = 0; i < num; i++, msgs++) { 721 for (i = 0; i < num; ++i) {
722 stop = (i == num - 1); 722 ret = exynos5_i2c_xfer_msg(i2c, msgs + i, i + 1 == num);
723 723 if (ret)
724 ret = exynos5_i2c_xfer_msg(i2c, msgs, stop); 724 break;
725
726 if (ret < 0)
727 goto out;
728 }
729
730 if (i == num) {
731 ret = num;
732 } else {
733 /* Only one message, cannot access the device */
734 if (i == 1)
735 ret = -EREMOTEIO;
736 else
737 ret = i;
738
739 dev_warn(i2c->dev, "xfer message failed\n");
740 } 725 }
741 726
742 out:
743 clk_disable(i2c->clk); 727 clk_disable(i2c->clk);
744 return ret; 728
729 return ret ?: num;
745} 730}
746 731
747static u32 exynos5_i2c_func(struct i2c_adapter *adap) 732static u32 exynos5_i2c_func(struct i2c_adapter *adap)
diff --git a/drivers/i2c/busses/i2c-gpio.c b/drivers/i2c/busses/i2c-gpio.c
index 58abb3eced58..005e6e0330c2 100644
--- a/drivers/i2c/busses/i2c-gpio.c
+++ b/drivers/i2c/busses/i2c-gpio.c
@@ -11,7 +11,7 @@
11#include <linux/delay.h> 11#include <linux/delay.h>
12#include <linux/i2c.h> 12#include <linux/i2c.h>
13#include <linux/i2c-algo-bit.h> 13#include <linux/i2c-algo-bit.h>
14#include <linux/i2c-gpio.h> 14#include <linux/platform_data/i2c-gpio.h>
15#include <linux/init.h> 15#include <linux/init.h>
16#include <linux/module.h> 16#include <linux/module.h>
17#include <linux/slab.h> 17#include <linux/slab.h>
diff --git a/drivers/i2c/busses/i2c-hix5hd2.c b/drivers/i2c/busses/i2c-hix5hd2.c
index bb68957d3da5..061a4bfb03f4 100644
--- a/drivers/i2c/busses/i2c-hix5hd2.c
+++ b/drivers/i2c/busses/i2c-hix5hd2.c
@@ -73,7 +73,6 @@
73#define I2C_OVER_INTR BIT(0) 73#define I2C_OVER_INTR BIT(0)
74 74
75#define HIX5I2C_MAX_FREQ 400000 /* 400k */ 75#define HIX5I2C_MAX_FREQ 400000 /* 400k */
76#define HIX5I2C_READ_OPERATION 0x01
77 76
78enum hix5hd2_i2c_state { 77enum hix5hd2_i2c_state {
79 HIX5I2C_STAT_RW_ERR = -1, 78 HIX5I2C_STAT_RW_ERR = -1,
@@ -311,12 +310,8 @@ static void hix5hd2_i2c_message_start(struct hix5hd2_i2c_priv *priv, int stop)
311 hix5hd2_i2c_clr_all_irq(priv); 310 hix5hd2_i2c_clr_all_irq(priv);
312 hix5hd2_i2c_enable_irq(priv); 311 hix5hd2_i2c_enable_irq(priv);
313 312
314 if (priv->msg->flags & I2C_M_RD) 313 writel_relaxed(i2c_8bit_addr_from_msg(priv->msg),
315 writel_relaxed((priv->msg->addr << 1) | HIX5I2C_READ_OPERATION, 314 priv->regs + HIX5I2C_TXR);
316 priv->regs + HIX5I2C_TXR);
317 else
318 writel_relaxed(priv->msg->addr << 1,
319 priv->regs + HIX5I2C_TXR);
320 315
321 writel_relaxed(I2C_WRITE | I2C_START, priv->regs + HIX5I2C_COM); 316 writel_relaxed(I2C_WRITE | I2C_START, priv->regs + HIX5I2C_COM);
322 spin_unlock_irqrestore(&priv->lock, flags); 317 spin_unlock_irqrestore(&priv->lock, flags);
@@ -377,17 +372,7 @@ static int hix5hd2_i2c_xfer(struct i2c_adapter *adap,
377 goto out; 372 goto out;
378 } 373 }
379 374
380 if (i == num) { 375 ret = num;
381 ret = num;
382 } else {
383 /* Only one message, cannot access the device */
384 if (i == 1)
385 ret = -EREMOTEIO;
386 else
387 ret = i;
388
389 dev_warn(priv->dev, "xfer message failed\n");
390 }
391 376
392out: 377out:
393 pm_runtime_mark_last_busy(priv->dev); 378 pm_runtime_mark_last_busy(priv->dev);
@@ -471,7 +456,6 @@ static int hix5hd2_i2c_probe(struct platform_device *pdev)
471 goto err_clk; 456 goto err_clk;
472 } 457 }
473 458
474 pm_suspend_ignore_children(&pdev->dev, true);
475 pm_runtime_set_autosuspend_delay(priv->dev, MSEC_PER_SEC); 459 pm_runtime_set_autosuspend_delay(priv->dev, MSEC_PER_SEC);
476 pm_runtime_use_autosuspend(priv->dev); 460 pm_runtime_use_autosuspend(priv->dev);
477 pm_runtime_set_active(priv->dev); 461 pm_runtime_set_active(priv->dev);
diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index e0d59e9ff3c6..aa726607645e 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -106,7 +106,7 @@
106 106
107#if IS_ENABLED(CONFIG_I2C_MUX_GPIO) && defined CONFIG_DMI 107#if IS_ENABLED(CONFIG_I2C_MUX_GPIO) && defined CONFIG_DMI
108#include <linux/gpio.h> 108#include <linux/gpio.h>
109#include <linux/i2c-mux-gpio.h> 109#include <linux/platform_data/i2c-mux-gpio.h>
110#endif 110#endif
111 111
112/* I801 SMBus address offsets */ 112/* I801 SMBus address offsets */
@@ -1710,7 +1710,7 @@ static void i801_shutdown(struct pci_dev *dev)
1710 pci_write_config_byte(dev, SMBHSTCFG, priv->original_hstcfg); 1710 pci_write_config_byte(dev, SMBHSTCFG, priv->original_hstcfg);
1711} 1711}
1712 1712
1713#ifdef CONFIG_PM 1713#ifdef CONFIG_PM_SLEEP
1714static int i801_suspend(struct device *dev) 1714static int i801_suspend(struct device *dev)
1715{ 1715{
1716 struct pci_dev *pci_dev = to_pci_dev(dev); 1716 struct pci_dev *pci_dev = to_pci_dev(dev);
@@ -1731,8 +1731,7 @@ static int i801_resume(struct device *dev)
1731} 1731}
1732#endif 1732#endif
1733 1733
1734static UNIVERSAL_DEV_PM_OPS(i801_pm_ops, i801_suspend, 1734static SIMPLE_DEV_PM_OPS(i801_pm_ops, i801_suspend, i801_resume);
1735 i801_resume, NULL);
1736 1735
1737static struct pci_driver i801_driver = { 1736static struct pci_driver i801_driver = {
1738 .name = "i801_smbus", 1737 .name = "i801_smbus",
diff --git a/drivers/i2c/busses/i2c-ibm_iic.c b/drivers/i2c/busses/i2c-ibm_iic.c
index 961c5f42d956..6f6e1dfe7cce 100644
--- a/drivers/i2c/busses/i2c-ibm_iic.c
+++ b/drivers/i2c/busses/i2c-ibm_iic.c
@@ -561,9 +561,6 @@ static int iic_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
561 561
562 DBG2("%d: iic_xfer, %d msg(s)\n", dev->idx, num); 562 DBG2("%d: iic_xfer, %d msg(s)\n", dev->idx, num);
563 563
564 if (!num)
565 return 0;
566
567 /* Check the sanity of the passed messages. 564 /* Check the sanity of the passed messages.
568 * Uhh, generic i2c layer is more suitable place for such code... 565 * Uhh, generic i2c layer is more suitable place for such code...
569 */ 566 */
diff --git a/drivers/i2c/busses/i2c-imx-lpi2c.c b/drivers/i2c/busses/i2c-imx-lpi2c.c
index e6da2c7a9a3e..6d975f5221ca 100644
--- a/drivers/i2c/busses/i2c-imx-lpi2c.c
+++ b/drivers/i2c/busses/i2c-imx-lpi2c.c
@@ -1,18 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * This is i.MX low power i2c controller driver. 3 * This is i.MX low power i2c controller driver.
3 * 4 *
4 * Copyright 2016 Freescale Semiconductor, Inc. 5 * Copyright 2016 Freescale Semiconductor, Inc.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 */ 6 */
17 7
18#include <linux/clk.h> 8#include <linux/clk.h>
@@ -180,15 +170,13 @@ static int lpi2c_imx_start(struct lpi2c_imx_struct *lpi2c_imx,
180 struct i2c_msg *msgs) 170 struct i2c_msg *msgs)
181{ 171{
182 unsigned int temp; 172 unsigned int temp;
183 u8 read;
184 173
185 temp = readl(lpi2c_imx->base + LPI2C_MCR); 174 temp = readl(lpi2c_imx->base + LPI2C_MCR);
186 temp |= MCR_RRF | MCR_RTF; 175 temp |= MCR_RRF | MCR_RTF;
187 writel(temp, lpi2c_imx->base + LPI2C_MCR); 176 writel(temp, lpi2c_imx->base + LPI2C_MCR);
188 writel(0x7f00, lpi2c_imx->base + LPI2C_MSR); 177 writel(0x7f00, lpi2c_imx->base + LPI2C_MSR);
189 178
190 read = msgs->flags & I2C_M_RD; 179 temp = i2c_8bit_addr_from_msg(msgs) | (GEN_START << 8);
191 temp = (msgs->addr << 1 | read) | (GEN_START << 8);
192 writel(temp, lpi2c_imx->base + LPI2C_MTDR); 180 writel(temp, lpi2c_imx->base + LPI2C_MTDR);
193 181
194 return lpi2c_imx_bus_busy(lpi2c_imx); 182 return lpi2c_imx_bus_busy(lpi2c_imx);
diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index d7267dd9c7bf..0207e194f84b 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -1,16 +1,7 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (C) 2002 Motorola GSG-China 3 * Copyright (C) 2002 Motorola GSG-China
3 * 4 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * Author: 5 * Author:
15 * Darius Augulis, Teltonika Inc. 6 * Darius Augulis, Teltonika Inc.
16 * 7 *
@@ -630,7 +621,7 @@ static int i2c_imx_dma_write(struct imx_i2c_struct *i2c_imx,
630 * Write slave address. 621 * Write slave address.
631 * The first byte must be transmitted by the CPU. 622 * The first byte must be transmitted by the CPU.
632 */ 623 */
633 imx_i2c_write_reg(msgs->addr << 1, i2c_imx, IMX_I2C_I2DR); 624 imx_i2c_write_reg(i2c_8bit_addr_from_msg(msgs), i2c_imx, IMX_I2C_I2DR);
634 reinit_completion(&i2c_imx->dma->cmd_complete); 625 reinit_completion(&i2c_imx->dma->cmd_complete);
635 time_left = wait_for_completion_timeout( 626 time_left = wait_for_completion_timeout(
636 &i2c_imx->dma->cmd_complete, 627 &i2c_imx->dma->cmd_complete,
@@ -760,10 +751,10 @@ static int i2c_imx_write(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs)
760 int i, result; 751 int i, result;
761 752
762 dev_dbg(&i2c_imx->adapter.dev, "<%s> write slave address: addr=0x%x\n", 753 dev_dbg(&i2c_imx->adapter.dev, "<%s> write slave address: addr=0x%x\n",
763 __func__, msgs->addr << 1); 754 __func__, i2c_8bit_addr_from_msg(msgs));
764 755
765 /* write slave address */ 756 /* write slave address */
766 imx_i2c_write_reg(msgs->addr << 1, i2c_imx, IMX_I2C_I2DR); 757 imx_i2c_write_reg(i2c_8bit_addr_from_msg(msgs), i2c_imx, IMX_I2C_I2DR);
767 result = i2c_imx_trx_complete(i2c_imx); 758 result = i2c_imx_trx_complete(i2c_imx);
768 if (result) 759 if (result)
769 return result; 760 return result;
@@ -796,10 +787,10 @@ static int i2c_imx_read(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs, bo
796 787
797 dev_dbg(&i2c_imx->adapter.dev, 788 dev_dbg(&i2c_imx->adapter.dev,
798 "<%s> write slave address: addr=0x%x\n", 789 "<%s> write slave address: addr=0x%x\n",
799 __func__, (msgs->addr << 1) | 0x01); 790 __func__, i2c_8bit_addr_from_msg(msgs));
800 791
801 /* write slave address */ 792 /* write slave address */
802 imx_i2c_write_reg((msgs->addr << 1) | 0x01, i2c_imx, IMX_I2C_I2DR); 793 imx_i2c_write_reg(i2c_8bit_addr_from_msg(msgs), i2c_imx, IMX_I2C_I2DR);
803 result = i2c_imx_trx_complete(i2c_imx); 794 result = i2c_imx_trx_complete(i2c_imx);
804 if (result) 795 if (result)
805 return result; 796 return result;
diff --git a/drivers/i2c/busses/i2c-kempld.c b/drivers/i2c/busses/i2c-kempld.c
index e879190b5d1d..1c874aaa0447 100644
--- a/drivers/i2c/busses/i2c-kempld.c
+++ b/drivers/i2c/busses/i2c-kempld.c
@@ -124,15 +124,14 @@ static int kempld_i2c_process(struct kempld_i2c_data *i2c)
124 /* 10 bit address? */ 124 /* 10 bit address? */
125 if (i2c->msg->flags & I2C_M_TEN) { 125 if (i2c->msg->flags & I2C_M_TEN) {
126 addr = 0xf0 | ((i2c->msg->addr >> 7) & 0x6); 126 addr = 0xf0 | ((i2c->msg->addr >> 7) & 0x6);
127 /* Set read bit if necessary */
128 addr |= (i2c->msg->flags & I2C_M_RD) ? 1 : 0;
127 i2c->state = STATE_ADDR10; 129 i2c->state = STATE_ADDR10;
128 } else { 130 } else {
129 addr = (i2c->msg->addr << 1); 131 addr = i2c_8bit_addr_from_msg(i2c->msg);
130 i2c->state = STATE_START; 132 i2c->state = STATE_START;
131 } 133 }
132 134
133 /* Set read bit if necessary */
134 addr |= (i2c->msg->flags & I2C_M_RD) ? 1 : 0;
135
136 kempld_write8(pld, KEMPLD_I2C_DATA, addr); 135 kempld_write8(pld, KEMPLD_I2C_DATA, addr);
137 kempld_write8(pld, KEMPLD_I2C_CMD, I2C_CMD_START); 136 kempld_write8(pld, KEMPLD_I2C_CMD, I2C_CMD_START);
138 137
diff --git a/drivers/i2c/busses/i2c-mlxcpld.c b/drivers/i2c/busses/i2c-mlxcpld.c
index 4c28fa28ce76..745ed43a22d6 100644
--- a/drivers/i2c/busses/i2c-mlxcpld.c
+++ b/drivers/i2c/busses/i2c-mlxcpld.c
@@ -45,13 +45,16 @@
45#define MLXCPLD_I2C_VALID_FLAG (I2C_M_RECV_LEN | I2C_M_RD) 45#define MLXCPLD_I2C_VALID_FLAG (I2C_M_RECV_LEN | I2C_M_RD)
46#define MLXCPLD_I2C_BUS_NUM 1 46#define MLXCPLD_I2C_BUS_NUM 1
47#define MLXCPLD_I2C_DATA_REG_SZ 36 47#define MLXCPLD_I2C_DATA_REG_SZ 36
48#define MLXCPLD_I2C_DATA_SZ_BIT BIT(5)
49#define MLXCPLD_I2C_DATA_SZ_MASK GENMASK(6, 5)
50#define MLXCPLD_I2C_SMBUS_BLK_BIT BIT(7)
48#define MLXCPLD_I2C_MAX_ADDR_LEN 4 51#define MLXCPLD_I2C_MAX_ADDR_LEN 4
49#define MLXCPLD_I2C_RETR_NUM 2 52#define MLXCPLD_I2C_RETR_NUM 2
50#define MLXCPLD_I2C_XFER_TO 500000 /* usec */ 53#define MLXCPLD_I2C_XFER_TO 500000 /* usec */
51#define MLXCPLD_I2C_POLL_TIME 2000 /* usec */ 54#define MLXCPLD_I2C_POLL_TIME 2000 /* usec */
52 55
53/* LPC I2C registers */ 56/* LPC I2C registers */
54#define MLXCPLD_LPCI2C_LPF_REG 0x0 57#define MLXCPLD_LPCI2C_CPBLTY_REG 0x0
55#define MLXCPLD_LPCI2C_CTRL_REG 0x1 58#define MLXCPLD_LPCI2C_CTRL_REG 0x1
56#define MLXCPLD_LPCI2C_HALF_CYC_REG 0x4 59#define MLXCPLD_LPCI2C_HALF_CYC_REG 0x4
57#define MLXCPLD_LPCI2C_I2C_HOLD_REG 0x5 60#define MLXCPLD_LPCI2C_I2C_HOLD_REG 0x5
@@ -83,6 +86,7 @@ struct mlxcpld_i2c_priv {
83 struct mutex lock; 86 struct mutex lock;
84 struct mlxcpld_i2c_curr_xfer xfer; 87 struct mlxcpld_i2c_curr_xfer xfer;
85 struct device *dev; 88 struct device *dev;
89 bool smbus_block;
86}; 90};
87 91
88static void mlxcpld_i2c_lpc_write_buf(u8 *data, u8 len, u32 addr) 92static void mlxcpld_i2c_lpc_write_buf(u8 *data, u8 len, u32 addr)
@@ -230,7 +234,7 @@ static void mlxcpld_i2c_set_transf_data(struct mlxcpld_i2c_priv *priv,
230 * All upper layers currently are never use transfer with more than 234 * All upper layers currently are never use transfer with more than
231 * 2 messages. Actually, it's also not so relevant in Mellanox systems 235 * 2 messages. Actually, it's also not so relevant in Mellanox systems
232 * because of HW limitation. Max size of transfer is not more than 32 236 * because of HW limitation. Max size of transfer is not more than 32
233 * bytes in the current x86 LPCI2C bridge. 237 * or 68 bytes in the current x86 LPCI2C bridge.
234 */ 238 */
235 priv->xfer.cmd = msgs[num - 1].flags & I2C_M_RD; 239 priv->xfer.cmd = msgs[num - 1].flags & I2C_M_RD;
236 240
@@ -295,7 +299,7 @@ static int mlxcpld_i2c_wait_for_free(struct mlxcpld_i2c_priv *priv)
295static int mlxcpld_i2c_wait_for_tc(struct mlxcpld_i2c_priv *priv) 299static int mlxcpld_i2c_wait_for_tc(struct mlxcpld_i2c_priv *priv)
296{ 300{
297 int status, i, timeout = 0; 301 int status, i, timeout = 0;
298 u8 datalen; 302 u8 datalen, val;
299 303
300 do { 304 do {
301 usleep_range(MLXCPLD_I2C_POLL_TIME / 2, MLXCPLD_I2C_POLL_TIME); 305 usleep_range(MLXCPLD_I2C_POLL_TIME / 2, MLXCPLD_I2C_POLL_TIME);
@@ -324,9 +328,22 @@ static int mlxcpld_i2c_wait_for_tc(struct mlxcpld_i2c_priv *priv)
324 * Actual read data len will be always the same as 328 * Actual read data len will be always the same as
325 * requested len. 0xff (line pull-up) will be returned 329 * requested len. 0xff (line pull-up) will be returned
326 * if slave has no data to return. Thus don't read 330 * if slave has no data to return. Thus don't read
327 * MLXCPLD_LPCI2C_NUM_DAT_REG reg from CPLD. 331 * MLXCPLD_LPCI2C_NUM_DAT_REG reg from CPLD. Only in case of
332 * SMBus block read transaction data len can be different,
333 * check this case.
328 */ 334 */
329 datalen = priv->xfer.data_len; 335 mlxcpld_i2c_read_comm(priv, MLXCPLD_LPCI2C_NUM_ADDR_REG, &val,
336 1);
337 if (priv->smbus_block && (val & MLXCPLD_I2C_SMBUS_BLK_BIT)) {
338 mlxcpld_i2c_read_comm(priv, MLXCPLD_LPCI2C_NUM_DAT_REG,
339 &datalen, 1);
340 if (unlikely(datalen > (I2C_SMBUS_BLOCK_MAX + 1))) {
341 dev_err(priv->dev, "Incorrect smbus block read message len\n");
342 return -E2BIG;
343 }
344 } else {
345 datalen = priv->xfer.data_len;
346 }
330 347
331 mlxcpld_i2c_read_comm(priv, MLXCPLD_LPCI2C_DATA_REG, 348 mlxcpld_i2c_read_comm(priv, MLXCPLD_LPCI2C_DATA_REG,
332 priv->xfer.msg[i].buf, datalen); 349 priv->xfer.msg[i].buf, datalen);
@@ -344,12 +361,20 @@ static int mlxcpld_i2c_wait_for_tc(struct mlxcpld_i2c_priv *priv)
344static void mlxcpld_i2c_xfer_msg(struct mlxcpld_i2c_priv *priv) 361static void mlxcpld_i2c_xfer_msg(struct mlxcpld_i2c_priv *priv)
345{ 362{
346 int i, len = 0; 363 int i, len = 0;
347 u8 cmd; 364 u8 cmd, val;
348 365
349 mlxcpld_i2c_write_comm(priv, MLXCPLD_LPCI2C_NUM_DAT_REG, 366 mlxcpld_i2c_write_comm(priv, MLXCPLD_LPCI2C_NUM_DAT_REG,
350 &priv->xfer.data_len, 1); 367 &priv->xfer.data_len, 1);
351 mlxcpld_i2c_write_comm(priv, MLXCPLD_LPCI2C_NUM_ADDR_REG, 368
352 &priv->xfer.addr_width, 1); 369 val = priv->xfer.addr_width;
370 /* Notify HW about SMBus block read transaction */
371 if (priv->smbus_block && priv->xfer.msg_num >= 2 &&
372 priv->xfer.msg[1].len == 1 &&
373 (priv->xfer.msg[1].flags & I2C_M_RECV_LEN) &&
374 (priv->xfer.msg[1].flags & I2C_M_RD))
375 val |= MLXCPLD_I2C_SMBUS_BLK_BIT;
376
377 mlxcpld_i2c_write_comm(priv, MLXCPLD_LPCI2C_NUM_ADDR_REG, &val, 1);
353 378
354 for (i = 0; i < priv->xfer.msg_num; i++) { 379 for (i = 0; i < priv->xfer.msg_num; i++) {
355 if ((priv->xfer.msg[i].flags & I2C_M_RD) != I2C_M_RD) { 380 if ((priv->xfer.msg[i].flags & I2C_M_RD) != I2C_M_RD) {
@@ -425,7 +450,14 @@ static int mlxcpld_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
425 450
426static u32 mlxcpld_i2c_func(struct i2c_adapter *adap) 451static u32 mlxcpld_i2c_func(struct i2c_adapter *adap)
427{ 452{
428 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_SMBUS_BLOCK_DATA; 453 struct mlxcpld_i2c_priv *priv = i2c_get_adapdata(adap);
454
455 if (priv->smbus_block)
456 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL |
457 I2C_FUNC_SMBUS_I2C_BLOCK | I2C_FUNC_SMBUS_BLOCK_DATA;
458 else
459 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL |
460 I2C_FUNC_SMBUS_I2C_BLOCK;
429} 461}
430 462
431static const struct i2c_algorithm mlxcpld_i2c_algo = { 463static const struct i2c_algorithm mlxcpld_i2c_algo = {
@@ -440,6 +472,13 @@ static const struct i2c_adapter_quirks mlxcpld_i2c_quirks = {
440 .max_comb_1st_msg_len = 4, 472 .max_comb_1st_msg_len = 4,
441}; 473};
442 474
475static const struct i2c_adapter_quirks mlxcpld_i2c_quirks_ext = {
476 .flags = I2C_AQ_COMB_WRITE_THEN_READ,
477 .max_read_len = MLXCPLD_I2C_DATA_REG_SZ * 2 - MLXCPLD_I2C_MAX_ADDR_LEN,
478 .max_write_len = MLXCPLD_I2C_DATA_REG_SZ * 2,
479 .max_comb_1st_msg_len = 4,
480};
481
443static struct i2c_adapter mlxcpld_i2c_adapter = { 482static struct i2c_adapter mlxcpld_i2c_adapter = {
444 .owner = THIS_MODULE, 483 .owner = THIS_MODULE,
445 .name = "i2c-mlxcpld", 484 .name = "i2c-mlxcpld",
@@ -454,6 +493,7 @@ static int mlxcpld_i2c_probe(struct platform_device *pdev)
454{ 493{
455 struct mlxcpld_i2c_priv *priv; 494 struct mlxcpld_i2c_priv *priv;
456 int err; 495 int err;
496 u8 val;
457 497
458 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); 498 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
459 if (!priv) 499 if (!priv)
@@ -466,6 +506,16 @@ static int mlxcpld_i2c_probe(struct platform_device *pdev)
466 506
467 /* Register with i2c layer */ 507 /* Register with i2c layer */
468 mlxcpld_i2c_adapter.timeout = usecs_to_jiffies(MLXCPLD_I2C_XFER_TO); 508 mlxcpld_i2c_adapter.timeout = usecs_to_jiffies(MLXCPLD_I2C_XFER_TO);
509 /* Read capability register */
510 mlxcpld_i2c_read_comm(priv, MLXCPLD_LPCI2C_CPBLTY_REG, &val, 1);
511 /* Check support for extended transaction length */
512 if ((val & MLXCPLD_I2C_DATA_SZ_MASK) == MLXCPLD_I2C_DATA_SZ_BIT)
513 mlxcpld_i2c_adapter.quirks = &mlxcpld_i2c_quirks_ext;
514 /* Check support for smbus block transaction */
515 if (val & MLXCPLD_I2C_SMBUS_BLK_BIT)
516 priv->smbus_block = true;
517 if (pdev->id >= -1)
518 mlxcpld_i2c_adapter.nr = pdev->id;
469 priv->adap = mlxcpld_i2c_adapter; 519 priv->adap = mlxcpld_i2c_adapter;
470 priv->adap.dev.parent = &pdev->dev; 520 priv->adap.dev.parent = &pdev->dev;
471 priv->base_addr = MLXPLAT_CPLD_LPC_I2C_BASE_ADDR; 521 priv->base_addr = MLXPLAT_CPLD_LPC_I2C_BASE_ADDR;
diff --git a/drivers/i2c/busses/i2c-mt65xx.c b/drivers/i2c/busses/i2c-mt65xx.c
index cf23a746cc17..1e57f58fcb00 100644
--- a/drivers/i2c/busses/i2c-mt65xx.c
+++ b/drivers/i2c/busses/i2c-mt65xx.c
@@ -27,6 +27,7 @@
27#include <linux/mm.h> 27#include <linux/mm.h>
28#include <linux/module.h> 28#include <linux/module.h>
29#include <linux/of_address.h> 29#include <linux/of_address.h>
30#include <linux/of_device.h>
30#include <linux/of_irq.h> 31#include <linux/of_irq.h>
31#include <linux/platform_device.h> 32#include <linux/platform_device.h>
32#include <linux/scatterlist.h> 33#include <linux/scatterlist.h>
@@ -734,7 +735,6 @@ static int mtk_i2c_parse_dt(struct device_node *np, struct mtk_i2c *i2c)
734 735
735static int mtk_i2c_probe(struct platform_device *pdev) 736static int mtk_i2c_probe(struct platform_device *pdev)
736{ 737{
737 const struct of_device_id *of_id;
738 int ret = 0; 738 int ret = 0;
739 struct mtk_i2c *i2c; 739 struct mtk_i2c *i2c;
740 struct clk *clk; 740 struct clk *clk;
@@ -761,11 +761,7 @@ static int mtk_i2c_probe(struct platform_device *pdev)
761 761
762 init_completion(&i2c->msg_complete); 762 init_completion(&i2c->msg_complete);
763 763
764 of_id = of_match_node(mtk_i2c_of_match, pdev->dev.of_node); 764 i2c->dev_comp = of_device_get_match_data(&pdev->dev);
765 if (!of_id)
766 return -EINVAL;
767
768 i2c->dev_comp = of_id->data;
769 i2c->adap.dev.of_node = pdev->dev.of_node; 765 i2c->adap.dev.of_node = pdev->dev.of_node;
770 i2c->dev = &pdev->dev; 766 i2c->dev = &pdev->dev;
771 i2c->adap.dev.parent = &pdev->dev; 767 i2c->adap.dev.parent = &pdev->dev;
diff --git a/drivers/i2c/busses/i2c-mxs.c b/drivers/i2c/busses/i2c-mxs.c
index e617bd600794..642c58946d8d 100644
--- a/drivers/i2c/busses/i2c-mxs.c
+++ b/drivers/i2c/busses/i2c-mxs.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Freescale MXS I2C bus driver 3 * Freescale MXS I2C bus driver
3 * 4 *
@@ -7,12 +8,6 @@
7 * based on a (non-working) driver which was: 8 * based on a (non-working) driver which was:
8 * 9 *
9 * Copyright (C) 2009-2010 Freescale Semiconductor, Inc. All Rights Reserved. 10 * Copyright (C) 2009-2010 Freescale Semiconductor, Inc. All Rights Reserved.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 */ 11 */
17 12
18#include <linux/slab.h> 13#include <linux/slab.h>
@@ -180,9 +175,10 @@ static int mxs_i2c_dma_setup_xfer(struct i2c_adapter *adap,
180 struct dma_async_tx_descriptor *desc; 175 struct dma_async_tx_descriptor *desc;
181 struct mxs_i2c_dev *i2c = i2c_get_adapdata(adap); 176 struct mxs_i2c_dev *i2c = i2c_get_adapdata(adap);
182 177
178 i2c->addr_data = i2c_8bit_addr_from_msg(msg);
179
183 if (msg->flags & I2C_M_RD) { 180 if (msg->flags & I2C_M_RD) {
184 i2c->dma_read = true; 181 i2c->dma_read = true;
185 i2c->addr_data = (msg->addr << 1) | I2C_SMBUS_READ;
186 182
187 /* 183 /*
188 * SELECT command. 184 * SELECT command.
@@ -240,7 +236,6 @@ static int mxs_i2c_dma_setup_xfer(struct i2c_adapter *adap,
240 } 236 }
241 } else { 237 } else {
242 i2c->dma_read = false; 238 i2c->dma_read = false;
243 i2c->addr_data = (msg->addr << 1) | I2C_SMBUS_WRITE;
244 239
245 /* 240 /*
246 * WRITE command. 241 * WRITE command.
@@ -371,7 +366,7 @@ static int mxs_i2c_pio_setup_xfer(struct i2c_adapter *adap,
371 struct i2c_msg *msg, uint32_t flags) 366 struct i2c_msg *msg, uint32_t flags)
372{ 367{
373 struct mxs_i2c_dev *i2c = i2c_get_adapdata(adap); 368 struct mxs_i2c_dev *i2c = i2c_get_adapdata(adap);
374 uint32_t addr_data = msg->addr << 1; 369 uint32_t addr_data = i2c_8bit_addr_from_msg(msg);
375 uint32_t data = 0; 370 uint32_t data = 0;
376 int i, ret, xlen = 0, xmit = 0; 371 int i, ret, xlen = 0, xmit = 0;
377 uint32_t start; 372 uint32_t start;
@@ -411,8 +406,6 @@ static int mxs_i2c_pio_setup_xfer(struct i2c_adapter *adap,
411 */ 406 */
412 BUG_ON(msg->len > 4); 407 BUG_ON(msg->len > 4);
413 408
414 addr_data |= I2C_SMBUS_READ;
415
416 /* SELECT command. */ 409 /* SELECT command. */
417 mxs_i2c_pio_trigger_write_cmd(i2c, MXS_CMD_I2C_SELECT, 410 mxs_i2c_pio_trigger_write_cmd(i2c, MXS_CMD_I2C_SELECT,
418 addr_data); 411 addr_data);
@@ -450,7 +443,6 @@ static int mxs_i2c_pio_setup_xfer(struct i2c_adapter *adap,
450 * fast enough. It is possible to transfer arbitrary amount 443 * fast enough. It is possible to transfer arbitrary amount
451 * of data using PIO write. 444 * of data using PIO write.
452 */ 445 */
453 addr_data |= I2C_SMBUS_WRITE;
454 446
455 /* 447 /*
456 * The LSB of data buffer is the first byte blasted across 448 * The LSB of data buffer is the first byte blasted across
diff --git a/drivers/i2c/busses/i2c-nomadik.c b/drivers/i2c/busses/i2c-nomadik.c
index 49c7c0c91486..0ed5a41804dc 100644
--- a/drivers/i2c/busses/i2c-nomadik.c
+++ b/drivers/i2c/busses/i2c-nomadik.c
@@ -1012,8 +1012,6 @@ static int nmk_i2c_probe(struct amba_device *adev, const struct amba_id *id)
1012 goto err_no_mem; 1012 goto err_no_mem;
1013 } 1013 }
1014 1014
1015 pm_suspend_ignore_children(&adev->dev, true);
1016
1017 dev->clk = devm_clk_get(&adev->dev, NULL); 1015 dev->clk = devm_clk_get(&adev->dev, NULL);
1018 if (IS_ERR(dev->clk)) { 1016 if (IS_ERR(dev->clk)) {
1019 dev_err(&adev->dev, "could not get i2c clock\n"); 1017 dev_err(&adev->dev, "could not get i2c clock\n");
diff --git a/drivers/i2c/busses/i2c-ocores.c b/drivers/i2c/busses/i2c-ocores.c
index 45ae3c025bf6..88444ef74943 100644
--- a/drivers/i2c/busses/i2c-ocores.c
+++ b/drivers/i2c/busses/i2c-ocores.c
@@ -21,7 +21,7 @@
21#include <linux/i2c.h> 21#include <linux/i2c.h>
22#include <linux/interrupt.h> 22#include <linux/interrupt.h>
23#include <linux/wait.h> 23#include <linux/wait.h>
24#include <linux/i2c-ocores.h> 24#include <linux/platform_data/i2c-ocores.h>
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/io.h> 26#include <linux/io.h>
27#include <linux/log2.h> 27#include <linux/log2.h>
@@ -222,10 +222,7 @@ static int ocores_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
222 i2c->nmsgs = num; 222 i2c->nmsgs = num;
223 i2c->state = STATE_START; 223 i2c->state = STATE_START;
224 224
225 oc_setreg(i2c, OCI2C_DATA, 225 oc_setreg(i2c, OCI2C_DATA, i2c_8bit_addr_from_msg(i2c->msg));
226 (i2c->msg->addr << 1) |
227 ((i2c->msg->flags & I2C_M_RD) ? 1:0));
228
229 oc_setreg(i2c, OCI2C_CMD, OCI2C_CMD_START); 226 oc_setreg(i2c, OCI2C_CMD, OCI2C_CMD_START);
230 227
231 if (wait_event_timeout(i2c->wait, (i2c->state == STATE_ERROR) || 228 if (wait_event_timeout(i2c->wait, (i2c->state == STATE_ERROR) ||
diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
index b9172f08fd05..65d06a819307 100644
--- a/drivers/i2c/busses/i2c-omap.c
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -36,7 +36,7 @@
36#include <linux/of.h> 36#include <linux/of.h>
37#include <linux/of_device.h> 37#include <linux/of_device.h>
38#include <linux/slab.h> 38#include <linux/slab.h>
39#include <linux/i2c-omap.h> 39#include <linux/platform_data/i2c-omap.h>
40#include <linux/pm_runtime.h> 40#include <linux/pm_runtime.h>
41#include <linux/pinctrl/consumer.h> 41#include <linux/pinctrl/consumer.h>
42 42
diff --git a/drivers/i2c/busses/i2c-opal.c b/drivers/i2c/busses/i2c-opal.c
index 0aabb7eca0c5..dc2a23f4fb52 100644
--- a/drivers/i2c/busses/i2c-opal.c
+++ b/drivers/i2c/busses/i2c-opal.c
@@ -94,8 +94,6 @@ static int i2c_opal_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
94 */ 94 */
95 memset(&req, 0, sizeof(req)); 95 memset(&req, 0, sizeof(req));
96 switch(num) { 96 switch(num) {
97 case 0:
98 return 0;
99 case 1: 97 case 1:
100 req.type = (msgs[0].flags & I2C_M_RD) ? 98 req.type = (msgs[0].flags & I2C_M_RD) ?
101 OPAL_I2C_RAW_READ : OPAL_I2C_RAW_WRITE; 99 OPAL_I2C_RAW_READ : OPAL_I2C_RAW_WRITE;
@@ -114,8 +112,6 @@ static int i2c_opal_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
114 req.size = cpu_to_be32(msgs[1].len); 112 req.size = cpu_to_be32(msgs[1].len);
115 req.buffer_ra = cpu_to_be64(__pa(msgs[1].buf)); 113 req.buffer_ra = cpu_to_be64(__pa(msgs[1].buf));
116 break; 114 break;
117 default:
118 return -EOPNOTSUPP;
119 } 115 }
120 116
121 rc = i2c_opal_send_request(opal_id, &req); 117 rc = i2c_opal_send_request(opal_id, &req);
diff --git a/drivers/i2c/busses/i2c-pasemi.c b/drivers/i2c/busses/i2c-pasemi.c
index df1dbc92a024..55fd5c6f3cca 100644
--- a/drivers/i2c/busses/i2c-pasemi.c
+++ b/drivers/i2c/busses/i2c-pasemi.c
@@ -121,7 +121,7 @@ static int pasemi_i2c_xfer_msg(struct i2c_adapter *adapter,
121 121
122 read = msg->flags & I2C_M_RD ? 1 : 0; 122 read = msg->flags & I2C_M_RD ? 1 : 0;
123 123
124 TXFIFO_WR(smbus, MTXFIFO_START | (msg->addr << 1) | read); 124 TXFIFO_WR(smbus, MTXFIFO_START | i2c_8bit_addr_from_msg(msg));
125 125
126 if (read) { 126 if (read) {
127 TXFIFO_WR(smbus, msg->len | MTXFIFO_READ | 127 TXFIFO_WR(smbus, msg->len | MTXFIFO_READ |
diff --git a/drivers/i2c/busses/i2c-pca-platform.c b/drivers/i2c/busses/i2c-pca-platform.c
index bc2707ffd409..de3fe6e828cb 100644
--- a/drivers/i2c/busses/i2c-pca-platform.c
+++ b/drivers/i2c/busses/i2c-pca-platform.c
@@ -20,7 +20,7 @@
20#include <linux/interrupt.h> 20#include <linux/interrupt.h>
21#include <linux/platform_device.h> 21#include <linux/platform_device.h>
22#include <linux/i2c-algo-pca.h> 22#include <linux/i2c-algo-pca.h>
23#include <linux/i2c-pca-platform.h> 23#include <linux/platform_data/i2c-pca-platform.h>
24#include <linux/gpio.h> 24#include <linux/gpio.h>
25#include <linux/gpio/consumer.h> 25#include <linux/gpio/consumer.h>
26#include <linux/io.h> 26#include <linux/io.h>
diff --git a/drivers/i2c/busses/i2c-pnx.c b/drivers/i2c/busses/i2c-pnx.c
index a542041df0cd..6e0e546ef83f 100644
--- a/drivers/i2c/busses/i2c-pnx.c
+++ b/drivers/i2c/busses/i2c-pnx.c
@@ -18,7 +18,6 @@
18#include <linux/timer.h> 18#include <linux/timer.h>
19#include <linux/completion.h> 19#include <linux/completion.h>
20#include <linux/platform_device.h> 20#include <linux/platform_device.h>
21#include <linux/i2c-pnx.h>
22#include <linux/io.h> 21#include <linux/io.h>
23#include <linux/err.h> 22#include <linux/err.h>
24#include <linux/clk.h> 23#include <linux/clk.h>
@@ -29,6 +28,26 @@
29#define I2C_PNX_SPEED_KHZ_DEFAULT 100 28#define I2C_PNX_SPEED_KHZ_DEFAULT 100
30#define I2C_PNX_REGION_SIZE 0x100 29#define I2C_PNX_REGION_SIZE 0x100
31 30
31struct i2c_pnx_mif {
32 int ret; /* Return value */
33 int mode; /* Interface mode */
34 struct completion complete; /* I/O completion */
35 struct timer_list timer; /* Timeout */
36 u8 * buf; /* Data buffer */
37 int len; /* Length of data buffer */
38 int order; /* RX Bytes to order via TX */
39};
40
41struct i2c_pnx_algo_data {
42 void __iomem *ioaddr;
43 struct i2c_pnx_mif mif;
44 int last;
45 struct clk *clk;
46 struct i2c_adapter adapter;
47 int irq;
48 u32 timeout;
49};
50
32enum { 51enum {
33 mstatus_tdi = 0x00000001, 52 mstatus_tdi = 0x00000001,
34 mstatus_afi = 0x00000002, 53 mstatus_afi = 0x00000002,
diff --git a/drivers/i2c/busses/i2c-qup.c b/drivers/i2c/busses/i2c-qup.c
index ebbf9cdec86b..c86c3ae1318f 100644
--- a/drivers/i2c/busses/i2c-qup.c
+++ b/drivers/i2c/busses/i2c-qup.c
@@ -136,8 +136,13 @@
136 */ 136 */
137#define TOUT_MIN 2 137#define TOUT_MIN 2
138 138
139/* I2C Frequency Modes */
140#define I2C_STANDARD_FREQ 100000
141#define I2C_FAST_MODE_FREQ 400000
142#define I2C_FAST_MODE_PLUS_FREQ 1000000
143
139/* Default values. Use these if FW query fails */ 144/* Default values. Use these if FW query fails */
140#define DEFAULT_CLK_FREQ 100000 145#define DEFAULT_CLK_FREQ I2C_STANDARD_FREQ
141#define DEFAULT_SRC_CLK 20000000 146#define DEFAULT_SRC_CLK 20000000
142 147
143/* 148/*
@@ -150,6 +155,10 @@
150/* TAG length for DATA READ in RX FIFO */ 155/* TAG length for DATA READ in RX FIFO */
151#define READ_RX_TAGS_LEN 2 156#define READ_RX_TAGS_LEN 2
152 157
158static unsigned int scl_freq;
159module_param_named(scl_freq, scl_freq, uint, 0444);
160MODULE_PARM_DESC(scl_freq, "SCL frequency override");
161
153/* 162/*
154 * count: no of blocks 163 * count: no of blocks
155 * pos: current block number 164 * pos: current block number
@@ -453,7 +462,7 @@ static void qup_i2c_write_tx_fifo_v1(struct qup_i2c_dev *qup)
453{ 462{
454 struct qup_i2c_block *blk = &qup->blk; 463 struct qup_i2c_block *blk = &qup->blk;
455 struct i2c_msg *msg = qup->msg; 464 struct i2c_msg *msg = qup->msg;
456 u32 addr = msg->addr << 1; 465 u32 addr = i2c_8bit_addr_from_msg(msg);
457 u32 qup_tag; 466 u32 qup_tag;
458 int idx; 467 int idx;
459 u32 val; 468 u32 val;
@@ -1648,6 +1657,12 @@ static void qup_i2c_disable_clocks(struct qup_i2c_dev *qup)
1648 clk_disable_unprepare(qup->pclk); 1657 clk_disable_unprepare(qup->pclk);
1649} 1658}
1650 1659
1660static const struct acpi_device_id qup_i2c_acpi_match[] = {
1661 { "QCOM8010"},
1662 { },
1663};
1664MODULE_DEVICE_TABLE(acpi, qup_i2c_acpi_match);
1665
1651static int qup_i2c_probe(struct platform_device *pdev) 1666static int qup_i2c_probe(struct platform_device *pdev)
1652{ 1667{
1653 static const int blk_sizes[] = {4, 16, 32}; 1668 static const int blk_sizes[] = {4, 16, 32};
@@ -1669,10 +1684,15 @@ static int qup_i2c_probe(struct platform_device *pdev)
1669 init_completion(&qup->xfer); 1684 init_completion(&qup->xfer);
1670 platform_set_drvdata(pdev, qup); 1685 platform_set_drvdata(pdev, qup);
1671 1686
1672 ret = device_property_read_u32(qup->dev, "clock-frequency", &clk_freq); 1687 if (scl_freq) {
1673 if (ret) { 1688 dev_notice(qup->dev, "Using override frequency of %u\n", scl_freq);
1674 dev_notice(qup->dev, "using default clock-frequency %d", 1689 clk_freq = scl_freq;
1675 DEFAULT_CLK_FREQ); 1690 } else {
1691 ret = device_property_read_u32(qup->dev, "clock-frequency", &clk_freq);
1692 if (ret) {
1693 dev_notice(qup->dev, "using default clock-frequency %d",
1694 DEFAULT_CLK_FREQ);
1695 }
1676 } 1696 }
1677 1697
1678 if (of_device_is_compatible(pdev->dev.of_node, "qcom,i2c-qup-v1.1.1")) { 1698 if (of_device_is_compatible(pdev->dev.of_node, "qcom,i2c-qup-v1.1.1")) {
@@ -1682,7 +1702,10 @@ static int qup_i2c_probe(struct platform_device *pdev)
1682 } else { 1702 } else {
1683 qup->adap.algo = &qup_i2c_algo_v2; 1703 qup->adap.algo = &qup_i2c_algo_v2;
1684 is_qup_v1 = false; 1704 is_qup_v1 = false;
1685 ret = qup_i2c_req_dma(qup); 1705 if (acpi_match_device(qup_i2c_acpi_match, qup->dev))
1706 goto nodma;
1707 else
1708 ret = qup_i2c_req_dma(qup);
1686 1709
1687 if (ret == -EPROBE_DEFER) 1710 if (ret == -EPROBE_DEFER)
1688 goto fail_dma; 1711 goto fail_dma;
@@ -1734,8 +1757,8 @@ static int qup_i2c_probe(struct platform_device *pdev)
1734 } 1757 }
1735 1758
1736nodma: 1759nodma:
1737 /* We support frequencies up to FAST Mode (400KHz) */ 1760 /* We support frequencies up to FAST Mode Plus (1MHz) */
1738 if (!clk_freq || clk_freq > 400000) { 1761 if (!clk_freq || clk_freq > I2C_FAST_MODE_PLUS_FREQ) {
1739 dev_err(qup->dev, "clock frequency not supported %d\n", 1762 dev_err(qup->dev, "clock frequency not supported %d\n",
1740 clk_freq); 1763 clk_freq);
1741 return -EINVAL; 1764 return -EINVAL;
@@ -1839,9 +1862,15 @@ nodma:
1839 size = QUP_INPUT_FIFO_SIZE(io_mode); 1862 size = QUP_INPUT_FIFO_SIZE(io_mode);
1840 qup->in_fifo_sz = qup->in_blk_sz * (2 << size); 1863 qup->in_fifo_sz = qup->in_blk_sz * (2 << size);
1841 1864
1842 fs_div = ((src_clk_freq / clk_freq) / 2) - 3;
1843 hs_div = 3; 1865 hs_div = 3;
1844 qup->clk_ctl = (hs_div << 8) | (fs_div & 0xff); 1866 if (clk_freq <= I2C_STANDARD_FREQ) {
1867 fs_div = ((src_clk_freq / clk_freq) / 2) - 3;
1868 qup->clk_ctl = (hs_div << 8) | (fs_div & 0xff);
1869 } else {
1870 /* 33%/66% duty cycle */
1871 fs_div = ((src_clk_freq / clk_freq) - 6) * 2 / 3;
1872 qup->clk_ctl = ((fs_div / 2) << 16) | (hs_div << 8) | (fs_div & 0xff);
1873 }
1845 1874
1846 /* 1875 /*
1847 * Time it takes for a byte to be clocked out on the bus. 1876 * Time it takes for a byte to be clocked out on the bus.
@@ -1959,14 +1988,6 @@ static const struct of_device_id qup_i2c_dt_match[] = {
1959}; 1988};
1960MODULE_DEVICE_TABLE(of, qup_i2c_dt_match); 1989MODULE_DEVICE_TABLE(of, qup_i2c_dt_match);
1961 1990
1962#if IS_ENABLED(CONFIG_ACPI)
1963static const struct acpi_device_id qup_i2c_acpi_match[] = {
1964 { "QCOM8010"},
1965 { },
1966};
1967MODULE_DEVICE_TABLE(acpi, qup_i2c_acpi_match);
1968#endif
1969
1970static struct platform_driver qup_i2c_driver = { 1991static struct platform_driver qup_i2c_driver = {
1971 .probe = qup_i2c_probe, 1992 .probe = qup_i2c_probe,
1972 .remove = qup_i2c_remove, 1993 .remove = qup_i2c_remove,
diff --git a/drivers/i2c/busses/i2c-rcar.c b/drivers/i2c/busses/i2c-rcar.c
index c6915b835396..5e310efd9446 100644
--- a/drivers/i2c/busses/i2c-rcar.c
+++ b/drivers/i2c/busses/i2c-rcar.c
@@ -329,7 +329,7 @@ static void rcar_i2c_prepare_msg(struct rcar_i2c_priv *priv)
329 if (priv->msgs_left == 1) 329 if (priv->msgs_left == 1)
330 priv->flags |= ID_LAST_MSG; 330 priv->flags |= ID_LAST_MSG;
331 331
332 rcar_i2c_write(priv, ICMAR, (priv->msg->addr << 1) | read); 332 rcar_i2c_write(priv, ICMAR, i2c_8bit_addr_from_msg(priv->msg));
333 /* 333 /*
334 * We don't have a test case but the HW engineers say that the write order 334 * We don't have a test case but the HW engineers say that the write order
335 * of ICMSR and ICMCR depends on whether we issue START or REP_START. Since 335 * of ICMSR and ICMCR depends on whether we issue START or REP_START. Since
@@ -542,6 +542,8 @@ static void rcar_i2c_irq_recv(struct rcar_i2c_priv *priv, u32 msr)
542 * If next received data is the _LAST_, go to STOP phase. Might be 542 * If next received data is the _LAST_, go to STOP phase. Might be
543 * overwritten by REP START when setting up a new msg. Not elegant 543 * overwritten by REP START when setting up a new msg. Not elegant
544 * but the only stable sequence for REP START I have found so far. 544 * but the only stable sequence for REP START I have found so far.
545 * If you want to change this code, make sure sending one transfer with
546 * four messages (WR-RD-WR-RD) works!
545 */ 547 */
546 if (priv->pos + 1 >= msg->len) 548 if (priv->pos + 1 >= msg->len)
547 rcar_i2c_write(priv, ICMCR, RCAR_BUS_PHASE_STOP); 549 rcar_i2c_write(priv, ICMCR, RCAR_BUS_PHASE_STOP);
diff --git a/drivers/i2c/busses/i2c-riic.c b/drivers/i2c/busses/i2c-riic.c
index 95c2f1ce3cad..5f1fca7880b1 100644
--- a/drivers/i2c/busses/i2c-riic.c
+++ b/drivers/i2c/busses/i2c-riic.c
@@ -167,15 +167,14 @@ static irqreturn_t riic_tdre_isr(int irq, void *data)
167 return IRQ_NONE; 167 return IRQ_NONE;
168 168
169 if (riic->bytes_left == RIIC_INIT_MSG) { 169 if (riic->bytes_left == RIIC_INIT_MSG) {
170 val = !!(riic->msg->flags & I2C_M_RD); 170 if (riic->msg->flags & I2C_M_RD)
171 if (val)
172 /* On read, switch over to receive interrupt */ 171 /* On read, switch over to receive interrupt */
173 riic_clear_set_bit(riic, ICIER_TIE, ICIER_RIE, RIIC_ICIER); 172 riic_clear_set_bit(riic, ICIER_TIE, ICIER_RIE, RIIC_ICIER);
174 else 173 else
175 /* On write, initialize length */ 174 /* On write, initialize length */
176 riic->bytes_left = riic->msg->len; 175 riic->bytes_left = riic->msg->len;
177 176
178 val |= (riic->msg->addr << 1); 177 val = i2c_8bit_addr_from_msg(riic->msg);
179 } else { 178 } else {
180 val = *riic->buf; 179 val = *riic->buf;
181 riic->buf++; 180 riic->buf++;
diff --git a/drivers/i2c/busses/i2c-rk3x.c b/drivers/i2c/busses/i2c-rk3x.c
index e1a18d989f83..b8a2728dd4b6 100644
--- a/drivers/i2c/busses/i2c-rk3x.c
+++ b/drivers/i2c/busses/i2c-rk3x.c
@@ -1326,8 +1326,6 @@ static int rk3x_i2c_probe(struct platform_device *pdev)
1326 if (ret < 0) 1326 if (ret < 0)
1327 goto err_clk_notifier; 1327 goto err_clk_notifier;
1328 1328
1329 dev_info(&pdev->dev, "Initialized RK3xxx I2C bus at %p\n", i2c->regs);
1330
1331 return 0; 1329 return 0;
1332 1330
1333err_clk_notifier: 1331err_clk_notifier:
diff --git a/drivers/i2c/busses/i2c-robotfuzz-osif.c b/drivers/i2c/busses/i2c-robotfuzz-osif.c
index 9c0f52b7ff7e..d848cf515234 100644
--- a/drivers/i2c/busses/i2c-robotfuzz-osif.c
+++ b/drivers/i2c/busses/i2c-robotfuzz-osif.c
@@ -62,27 +62,24 @@ static int osif_xfer(struct i2c_adapter *adapter, struct i2c_msg *msgs,
62{ 62{
63 struct osif_priv *priv = adapter->algo_data; 63 struct osif_priv *priv = adapter->algo_data;
64 struct i2c_msg *pmsg; 64 struct i2c_msg *pmsg;
65 int ret = 0; 65 int ret;
66 int i, cmd; 66 int i;
67 67
68 for (i = 0; ret >= 0 && i < num; i++) { 68 for (i = 0; i < num; i++) {
69 pmsg = &msgs[i]; 69 pmsg = &msgs[i];
70 70
71 if (pmsg->flags & I2C_M_RD) { 71 if (pmsg->flags & I2C_M_RD) {
72 cmd = OSIFI2C_READ; 72 ret = osif_usb_read(adapter, OSIFI2C_READ,
73 73 pmsg->flags, pmsg->addr,
74 ret = osif_usb_read(adapter, cmd, pmsg->flags, 74 pmsg->buf, pmsg->len);
75 pmsg->addr, pmsg->buf,
76 pmsg->len);
77 if (ret != pmsg->len) { 75 if (ret != pmsg->len) {
78 dev_err(&adapter->dev, "failure reading data\n"); 76 dev_err(&adapter->dev, "failure reading data\n");
79 return -EREMOTEIO; 77 return -EREMOTEIO;
80 } 78 }
81 } else { 79 } else {
82 cmd = OSIFI2C_WRITE; 80 ret = osif_usb_write(adapter, OSIFI2C_WRITE,
83 81 pmsg->flags, pmsg->addr,
84 ret = osif_usb_write(adapter, cmd, pmsg->flags, 82 pmsg->buf, pmsg->len);
85 pmsg->addr, pmsg->buf, pmsg->len);
86 if (ret != pmsg->len) { 83 if (ret != pmsg->len) {
87 dev_err(&adapter->dev, "failure writing data\n"); 84 dev_err(&adapter->dev, "failure writing data\n");
88 return -EREMOTEIO; 85 return -EREMOTEIO;
diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c
index 5d97510ee48b..9fe2b6951895 100644
--- a/drivers/i2c/busses/i2c-s3c2410.c
+++ b/drivers/i2c/busses/i2c-s3c2410.c
@@ -154,8 +154,6 @@ static const struct of_device_id s3c24xx_i2c_match[] = {
154 { .compatible = "samsung,s3c2440-i2c", .data = (void *)QUIRK_S3C2440 }, 154 { .compatible = "samsung,s3c2440-i2c", .data = (void *)QUIRK_S3C2440 },
155 { .compatible = "samsung,s3c2440-hdmiphy-i2c", 155 { .compatible = "samsung,s3c2440-hdmiphy-i2c",
156 .data = (void *)(QUIRK_S3C2440 | QUIRK_HDMIPHY | QUIRK_NO_GPIO) }, 156 .data = (void *)(QUIRK_S3C2440 | QUIRK_HDMIPHY | QUIRK_NO_GPIO) },
157 { .compatible = "samsung,exynos5440-i2c",
158 .data = (void *)(QUIRK_S3C2440 | QUIRK_NO_GPIO) },
159 { .compatible = "samsung,exynos5-sata-phy-i2c", 157 { .compatible = "samsung,exynos5-sata-phy-i2c",
160 .data = (void *)(QUIRK_S3C2440 | QUIRK_POLL | QUIRK_NO_GPIO) }, 158 .data = (void *)(QUIRK_S3C2440 | QUIRK_POLL | QUIRK_NO_GPIO) },
161 {}, 159 {},
diff --git a/drivers/i2c/busses/i2c-sh_mobile.c b/drivers/i2c/busses/i2c-sh_mobile.c
index d856bc211715..5fda4188a9e5 100644
--- a/drivers/i2c/busses/i2c-sh_mobile.c
+++ b/drivers/i2c/busses/i2c-sh_mobile.c
@@ -899,17 +899,6 @@ static int sh_mobile_i2c_probe(struct platform_device *dev)
899 if (resource_size(res) > 0x17) 899 if (resource_size(res) > 0x17)
900 pd->flags |= IIC_FLAG_HAS_ICIC67; 900 pd->flags |= IIC_FLAG_HAS_ICIC67;
901 901
902 /* Enable Runtime PM for this device.
903 *
904 * Also tell the Runtime PM core to ignore children
905 * for this device since it is valid for us to suspend
906 * this I2C master driver even though the slave devices
907 * on the I2C bus may not be suspended.
908 *
909 * The state of the I2C hardware bus is unaffected by
910 * the Runtime PM state.
911 */
912 pm_suspend_ignore_children(&dev->dev, true);
913 pm_runtime_enable(&dev->dev); 902 pm_runtime_enable(&dev->dev);
914 pm_runtime_get_sync(&dev->dev); 903 pm_runtime_get_sync(&dev->dev);
915 904
diff --git a/drivers/i2c/busses/i2c-stm32.c b/drivers/i2c/busses/i2c-stm32.c
new file mode 100644
index 000000000000..d75fbcbf02ef
--- /dev/null
+++ b/drivers/i2c/busses/i2c-stm32.c
@@ -0,0 +1,153 @@
1/*
2 * i2c-stm32.c
3 *
4 * Copyright (C) M'boumba Cedric Madianga 2017
5 * Author: M'boumba Cedric Madianga <cedric.madianga@gmail.com>
6 *
7 * License terms: GNU General Public License (GPL), version 2
8 */
9
10#include "i2c-stm32.h"
11
12/* Functions for DMA support */
13struct stm32_i2c_dma *stm32_i2c_dma_request(struct device *dev,
14 dma_addr_t phy_addr,
15 u32 txdr_offset,
16 u32 rxdr_offset)
17{
18 struct stm32_i2c_dma *dma;
19 struct dma_slave_config dma_sconfig;
20 int ret;
21
22 dma = devm_kzalloc(dev, sizeof(*dma), GFP_KERNEL);
23 if (!dma)
24 return NULL;
25
26 /* Request and configure I2C TX dma channel */
27 dma->chan_tx = dma_request_slave_channel(dev, "tx");
28 if (!dma->chan_tx) {
29 dev_dbg(dev, "can't request DMA tx channel\n");
30 ret = -EINVAL;
31 goto fail_al;
32 }
33
34 memset(&dma_sconfig, 0, sizeof(dma_sconfig));
35 dma_sconfig.dst_addr = phy_addr + txdr_offset;
36 dma_sconfig.dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE;
37 dma_sconfig.dst_maxburst = 1;
38 dma_sconfig.direction = DMA_MEM_TO_DEV;
39 ret = dmaengine_slave_config(dma->chan_tx, &dma_sconfig);
40 if (ret < 0) {
41 dev_err(dev, "can't configure tx channel\n");
42 goto fail_tx;
43 }
44
45 /* Request and configure I2C RX dma channel */
46 dma->chan_rx = dma_request_slave_channel(dev, "rx");
47 if (!dma->chan_rx) {
48 dev_err(dev, "can't request DMA rx channel\n");
49 ret = -EINVAL;
50 goto fail_tx;
51 }
52
53 memset(&dma_sconfig, 0, sizeof(dma_sconfig));
54 dma_sconfig.src_addr = phy_addr + rxdr_offset;
55 dma_sconfig.src_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE;
56 dma_sconfig.src_maxburst = 1;
57 dma_sconfig.direction = DMA_DEV_TO_MEM;
58 ret = dmaengine_slave_config(dma->chan_rx, &dma_sconfig);
59 if (ret < 0) {
60 dev_err(dev, "can't configure rx channel\n");
61 goto fail_rx;
62 }
63
64 init_completion(&dma->dma_complete);
65
66 dev_info(dev, "using %s (tx) and %s (rx) for DMA transfers\n",
67 dma_chan_name(dma->chan_tx), dma_chan_name(dma->chan_rx));
68
69 return dma;
70
71fail_rx:
72 dma_release_channel(dma->chan_rx);
73fail_tx:
74 dma_release_channel(dma->chan_tx);
75fail_al:
76 devm_kfree(dev, dma);
77 dev_info(dev, "can't use DMA\n");
78
79 return NULL;
80}
81
82void stm32_i2c_dma_free(struct stm32_i2c_dma *dma)
83{
84 dma->dma_buf = 0;
85 dma->dma_len = 0;
86
87 dma_release_channel(dma->chan_tx);
88 dma->chan_tx = NULL;
89
90 dma_release_channel(dma->chan_rx);
91 dma->chan_rx = NULL;
92
93 dma->chan_using = NULL;
94}
95
96int stm32_i2c_prep_dma_xfer(struct device *dev, struct stm32_i2c_dma *dma,
97 bool rd_wr, u32 len, u8 *buf,
98 dma_async_tx_callback callback,
99 void *dma_async_param)
100{
101 struct dma_async_tx_descriptor *txdesc;
102 struct device *chan_dev;
103 int ret;
104
105 if (rd_wr) {
106 dma->chan_using = dma->chan_rx;
107 dma->dma_transfer_dir = DMA_DEV_TO_MEM;
108 dma->dma_data_dir = DMA_FROM_DEVICE;
109 } else {
110 dma->chan_using = dma->chan_tx;
111 dma->dma_transfer_dir = DMA_MEM_TO_DEV;
112 dma->dma_data_dir = DMA_TO_DEVICE;
113 }
114
115 dma->dma_len = len;
116 chan_dev = dma->chan_using->device->dev;
117
118 dma->dma_buf = dma_map_single(chan_dev, buf, dma->dma_len,
119 dma->dma_data_dir);
120 if (dma_mapping_error(chan_dev, dma->dma_buf)) {
121 dev_err(dev, "DMA mapping failed\n");
122 return -EINVAL;
123 }
124
125 txdesc = dmaengine_prep_slave_single(dma->chan_using, dma->dma_buf,
126 dma->dma_len,
127 dma->dma_transfer_dir,
128 DMA_PREP_INTERRUPT);
129 if (!txdesc) {
130 dev_err(dev, "Not able to get desc for DMA xfer\n");
131 ret = -EINVAL;
132 goto err;
133 }
134
135 reinit_completion(&dma->dma_complete);
136
137 txdesc->callback = callback;
138 txdesc->callback_param = dma_async_param;
139 ret = dma_submit_error(dmaengine_submit(txdesc));
140 if (ret < 0) {
141 dev_err(dev, "DMA submit failed\n");
142 goto err;
143 }
144
145 dma_async_issue_pending(dma->chan_using);
146
147 return 0;
148
149err:
150 dma_unmap_single(chan_dev, dma->dma_buf, dma->dma_len,
151 dma->dma_data_dir);
152 return ret;
153}
diff --git a/drivers/i2c/busses/i2c-stm32.h b/drivers/i2c/busses/i2c-stm32.h
index d4f9cef251ac..868755f82f88 100644
--- a/drivers/i2c/busses/i2c-stm32.h
+++ b/drivers/i2c/busses/i2c-stm32.h
@@ -11,6 +11,10 @@
11#ifndef _I2C_STM32_H 11#ifndef _I2C_STM32_H
12#define _I2C_STM32_H 12#define _I2C_STM32_H
13 13
14#include <linux/dma-direction.h>
15#include <linux/dmaengine.h>
16#include <linux/dma-mapping.h>
17
14enum stm32_i2c_speed { 18enum stm32_i2c_speed {
15 STM32_I2C_SPEED_STANDARD, /* 100 kHz */ 19 STM32_I2C_SPEED_STANDARD, /* 100 kHz */
16 STM32_I2C_SPEED_FAST, /* 400 kHz */ 20 STM32_I2C_SPEED_FAST, /* 400 kHz */
@@ -18,4 +22,37 @@ enum stm32_i2c_speed {
18 STM32_I2C_SPEED_END, 22 STM32_I2C_SPEED_END,
19}; 23};
20 24
25/**
26 * struct stm32_i2c_dma - DMA specific data
27 * @chan_tx: dma channel for TX transfer
28 * @chan_rx: dma channel for RX transfer
29 * @chan_using: dma channel used for the current transfer (TX or RX)
30 * @dma_buf: dma buffer
31 * @dma_len: dma buffer len
32 * @dma_transfer_dir: dma transfer direction indicator
33 * @dma_data_dir: dma transfer mode indicator
34 * @dma_complete: dma transfer completion
35 */
36struct stm32_i2c_dma {
37 struct dma_chan *chan_tx;
38 struct dma_chan *chan_rx;
39 struct dma_chan *chan_using;
40 dma_addr_t dma_buf;
41 unsigned int dma_len;
42 enum dma_transfer_direction dma_transfer_dir;
43 enum dma_data_direction dma_data_dir;
44 struct completion dma_complete;
45};
46
47struct stm32_i2c_dma *stm32_i2c_dma_request(struct device *dev,
48 dma_addr_t phy_addr,
49 u32 txdr_offset, u32 rxdr_offset);
50
51void stm32_i2c_dma_free(struct stm32_i2c_dma *dma);
52
53int stm32_i2c_prep_dma_xfer(struct device *dev, struct stm32_i2c_dma *dma,
54 bool rd_wr, u32 len, u8 *buf,
55 dma_async_tx_callback callback,
56 void *dma_async_param);
57
21#endif /* _I2C_STM32_H */ 58#endif /* _I2C_STM32_H */
diff --git a/drivers/i2c/busses/i2c-stm32f7.c b/drivers/i2c/busses/i2c-stm32f7.c
index f273e28c39db..62d023e737d9 100644
--- a/drivers/i2c/busses/i2c-stm32f7.c
+++ b/drivers/i2c/busses/i2c-stm32f7.c
@@ -35,6 +35,9 @@
35/* STM32F7 I2C registers */ 35/* STM32F7 I2C registers */
36#define STM32F7_I2C_CR1 0x00 36#define STM32F7_I2C_CR1 0x00
37#define STM32F7_I2C_CR2 0x04 37#define STM32F7_I2C_CR2 0x04
38#define STM32F7_I2C_OAR1 0x08
39#define STM32F7_I2C_OAR2 0x0C
40#define STM32F7_I2C_PECR 0x20
38#define STM32F7_I2C_TIMINGR 0x10 41#define STM32F7_I2C_TIMINGR 0x10
39#define STM32F7_I2C_ISR 0x18 42#define STM32F7_I2C_ISR 0x18
40#define STM32F7_I2C_ICR 0x1C 43#define STM32F7_I2C_ICR 0x1C
@@ -42,6 +45,10 @@
42#define STM32F7_I2C_TXDR 0x28 45#define STM32F7_I2C_TXDR 0x28
43 46
44/* STM32F7 I2C control 1 */ 47/* STM32F7 I2C control 1 */
48#define STM32F7_I2C_CR1_PECEN BIT(23)
49#define STM32F7_I2C_CR1_SBC BIT(16)
50#define STM32F7_I2C_CR1_RXDMAEN BIT(15)
51#define STM32F7_I2C_CR1_TXDMAEN BIT(14)
45#define STM32F7_I2C_CR1_ANFOFF BIT(12) 52#define STM32F7_I2C_CR1_ANFOFF BIT(12)
46#define STM32F7_I2C_CR1_ERRIE BIT(7) 53#define STM32F7_I2C_CR1_ERRIE BIT(7)
47#define STM32F7_I2C_CR1_TCIE BIT(6) 54#define STM32F7_I2C_CR1_TCIE BIT(6)
@@ -57,34 +64,77 @@
57 | STM32F7_I2C_CR1_NACKIE \ 64 | STM32F7_I2C_CR1_NACKIE \
58 | STM32F7_I2C_CR1_RXIE \ 65 | STM32F7_I2C_CR1_RXIE \
59 | STM32F7_I2C_CR1_TXIE) 66 | STM32F7_I2C_CR1_TXIE)
67#define STM32F7_I2C_XFER_IRQ_MASK (STM32F7_I2C_CR1_TCIE \
68 | STM32F7_I2C_CR1_STOPIE \
69 | STM32F7_I2C_CR1_NACKIE \
70 | STM32F7_I2C_CR1_RXIE \
71 | STM32F7_I2C_CR1_TXIE)
60 72
61/* STM32F7 I2C control 2 */ 73/* STM32F7 I2C control 2 */
74#define STM32F7_I2C_CR2_PECBYTE BIT(26)
62#define STM32F7_I2C_CR2_RELOAD BIT(24) 75#define STM32F7_I2C_CR2_RELOAD BIT(24)
63#define STM32F7_I2C_CR2_NBYTES_MASK GENMASK(23, 16) 76#define STM32F7_I2C_CR2_NBYTES_MASK GENMASK(23, 16)
64#define STM32F7_I2C_CR2_NBYTES(n) (((n) & 0xff) << 16) 77#define STM32F7_I2C_CR2_NBYTES(n) (((n) & 0xff) << 16)
65#define STM32F7_I2C_CR2_NACK BIT(15) 78#define STM32F7_I2C_CR2_NACK BIT(15)
66#define STM32F7_I2C_CR2_STOP BIT(14) 79#define STM32F7_I2C_CR2_STOP BIT(14)
67#define STM32F7_I2C_CR2_START BIT(13) 80#define STM32F7_I2C_CR2_START BIT(13)
81#define STM32F7_I2C_CR2_HEAD10R BIT(12)
82#define STM32F7_I2C_CR2_ADD10 BIT(11)
68#define STM32F7_I2C_CR2_RD_WRN BIT(10) 83#define STM32F7_I2C_CR2_RD_WRN BIT(10)
84#define STM32F7_I2C_CR2_SADD10_MASK GENMASK(9, 0)
85#define STM32F7_I2C_CR2_SADD10(n) (((n) & \
86 STM32F7_I2C_CR2_SADD10_MASK))
69#define STM32F7_I2C_CR2_SADD7_MASK GENMASK(7, 1) 87#define STM32F7_I2C_CR2_SADD7_MASK GENMASK(7, 1)
70#define STM32F7_I2C_CR2_SADD7(n) (((n) & 0x7f) << 1) 88#define STM32F7_I2C_CR2_SADD7(n) (((n) & 0x7f) << 1)
71 89
90/* STM32F7 I2C Own Address 1 */
91#define STM32F7_I2C_OAR1_OA1EN BIT(15)
92#define STM32F7_I2C_OAR1_OA1MODE BIT(10)
93#define STM32F7_I2C_OAR1_OA1_10_MASK GENMASK(9, 0)
94#define STM32F7_I2C_OAR1_OA1_10(n) (((n) & \
95 STM32F7_I2C_OAR1_OA1_10_MASK))
96#define STM32F7_I2C_OAR1_OA1_7_MASK GENMASK(7, 1)
97#define STM32F7_I2C_OAR1_OA1_7(n) (((n) & 0x7f) << 1)
98#define STM32F7_I2C_OAR1_MASK (STM32F7_I2C_OAR1_OA1_7_MASK \
99 | STM32F7_I2C_OAR1_OA1_10_MASK \
100 | STM32F7_I2C_OAR1_OA1EN \
101 | STM32F7_I2C_OAR1_OA1MODE)
102
103/* STM32F7 I2C Own Address 2 */
104#define STM32F7_I2C_OAR2_OA2EN BIT(15)
105#define STM32F7_I2C_OAR2_OA2MSK_MASK GENMASK(10, 8)
106#define STM32F7_I2C_OAR2_OA2MSK(n) (((n) & 0x7) << 8)
107#define STM32F7_I2C_OAR2_OA2_7_MASK GENMASK(7, 1)
108#define STM32F7_I2C_OAR2_OA2_7(n) (((n) & 0x7f) << 1)
109#define STM32F7_I2C_OAR2_MASK (STM32F7_I2C_OAR2_OA2MSK_MASK \
110 | STM32F7_I2C_OAR2_OA2_7_MASK \
111 | STM32F7_I2C_OAR2_OA2EN)
112
72/* STM32F7 I2C Interrupt Status */ 113/* STM32F7 I2C Interrupt Status */
114#define STM32F7_I2C_ISR_ADDCODE_MASK GENMASK(23, 17)
115#define STM32F7_I2C_ISR_ADDCODE_GET(n) \
116 (((n) & STM32F7_I2C_ISR_ADDCODE_MASK) >> 17)
117#define STM32F7_I2C_ISR_DIR BIT(16)
73#define STM32F7_I2C_ISR_BUSY BIT(15) 118#define STM32F7_I2C_ISR_BUSY BIT(15)
119#define STM32F7_I2C_ISR_PECERR BIT(11)
74#define STM32F7_I2C_ISR_ARLO BIT(9) 120#define STM32F7_I2C_ISR_ARLO BIT(9)
75#define STM32F7_I2C_ISR_BERR BIT(8) 121#define STM32F7_I2C_ISR_BERR BIT(8)
76#define STM32F7_I2C_ISR_TCR BIT(7) 122#define STM32F7_I2C_ISR_TCR BIT(7)
77#define STM32F7_I2C_ISR_TC BIT(6) 123#define STM32F7_I2C_ISR_TC BIT(6)
78#define STM32F7_I2C_ISR_STOPF BIT(5) 124#define STM32F7_I2C_ISR_STOPF BIT(5)
79#define STM32F7_I2C_ISR_NACKF BIT(4) 125#define STM32F7_I2C_ISR_NACKF BIT(4)
126#define STM32F7_I2C_ISR_ADDR BIT(3)
80#define STM32F7_I2C_ISR_RXNE BIT(2) 127#define STM32F7_I2C_ISR_RXNE BIT(2)
81#define STM32F7_I2C_ISR_TXIS BIT(1) 128#define STM32F7_I2C_ISR_TXIS BIT(1)
129#define STM32F7_I2C_ISR_TXE BIT(0)
82 130
83/* STM32F7 I2C Interrupt Clear */ 131/* STM32F7 I2C Interrupt Clear */
132#define STM32F7_I2C_ICR_PECCF BIT(11)
84#define STM32F7_I2C_ICR_ARLOCF BIT(9) 133#define STM32F7_I2C_ICR_ARLOCF BIT(9)
85#define STM32F7_I2C_ICR_BERRCF BIT(8) 134#define STM32F7_I2C_ICR_BERRCF BIT(8)
86#define STM32F7_I2C_ICR_STOPCF BIT(5) 135#define STM32F7_I2C_ICR_STOPCF BIT(5)
87#define STM32F7_I2C_ICR_NACKCF BIT(4) 136#define STM32F7_I2C_ICR_NACKCF BIT(4)
137#define STM32F7_I2C_ICR_ADDRCF BIT(3)
88 138
89/* STM32F7 I2C Timing */ 139/* STM32F7 I2C Timing */
90#define STM32F7_I2C_TIMINGR_PRESC(n) (((n) & 0xf) << 28) 140#define STM32F7_I2C_TIMINGR_PRESC(n) (((n) & 0xf) << 28)
@@ -94,6 +144,8 @@
94#define STM32F7_I2C_TIMINGR_SCLL(n) ((n) & 0xff) 144#define STM32F7_I2C_TIMINGR_SCLL(n) ((n) & 0xff)
95 145
96#define STM32F7_I2C_MAX_LEN 0xff 146#define STM32F7_I2C_MAX_LEN 0xff
147#define STM32F7_I2C_DMA_LEN_MIN 0x16
148#define STM32F7_I2C_MAX_SLAVE 0x2
97 149
98#define STM32F7_I2C_DNF_DEFAULT 0 150#define STM32F7_I2C_DNF_DEFAULT 0
99#define STM32F7_I2C_DNF_MAX 16 151#define STM32F7_I2C_DNF_MAX 16
@@ -159,11 +211,12 @@ struct stm32f7_i2c_setup {
159 211
160/** 212/**
161 * struct stm32f7_i2c_timings - private I2C output parameters 213 * struct stm32f7_i2c_timings - private I2C output parameters
162 * @prec: Prescaler value 214 * @node: List entry
215 * @presc: Prescaler value
163 * @scldel: Data setup time 216 * @scldel: Data setup time
164 * @sdadel: Data hold time 217 * @sdadel: Data hold time
165 * @sclh: SCL high period (master mode) 218 * @sclh: SCL high period (master mode)
166 * @sclh: SCL low period (master mode) 219 * @scll: SCL low period (master mode)
167 */ 220 */
168struct stm32f7_i2c_timings { 221struct stm32f7_i2c_timings {
169 struct list_head node; 222 struct list_head node;
@@ -176,18 +229,30 @@ struct stm32f7_i2c_timings {
176 229
177/** 230/**
178 * struct stm32f7_i2c_msg - client specific data 231 * struct stm32f7_i2c_msg - client specific data
179 * @addr: 8-bit slave addr, including r/w bit 232 * @addr: 8-bit or 10-bit slave addr, including r/w bit
180 * @count: number of bytes to be transferred 233 * @count: number of bytes to be transferred
181 * @buf: data buffer 234 * @buf: data buffer
182 * @result: result of the transfer 235 * @result: result of the transfer
183 * @stop: last I2C msg to be sent, i.e. STOP to be generated 236 * @stop: last I2C msg to be sent, i.e. STOP to be generated
237 * @smbus: boolean to know if the I2C IP is used in SMBus mode
238 * @size: type of SMBus protocol
239 * @read_write: direction of SMBus protocol
240 * SMBus block read and SMBus block write - block read process call protocols
241 * @smbus_buf: buffer to be used for SMBus protocol transfer. It will
242 * contain a maximum of 32 bytes of data + byte command + byte count + PEC
243 * This buffer has to be 32-bit aligned to be compliant with memory address
244 * register in DMA mode.
184 */ 245 */
185struct stm32f7_i2c_msg { 246struct stm32f7_i2c_msg {
186 u8 addr; 247 u16 addr;
187 u32 count; 248 u32 count;
188 u8 *buf; 249 u8 *buf;
189 int result; 250 int result;
190 bool stop; 251 bool stop;
252 bool smbus;
253 int size;
254 char read_write;
255 u8 smbus_buf[I2C_SMBUS_BLOCK_MAX + 3] __aligned(4);
191}; 256};
192 257
193/** 258/**
@@ -204,6 +269,13 @@ struct stm32f7_i2c_msg {
204 * @f7_msg: customized i2c msg for driver usage 269 * @f7_msg: customized i2c msg for driver usage
205 * @setup: I2C timing input setup 270 * @setup: I2C timing input setup
206 * @timing: I2C computed timings 271 * @timing: I2C computed timings
272 * @slave: list of slave devices registered on the I2C bus
273 * @slave_running: slave device currently used
274 * @slave_dir: transfer direction for the current slave device
275 * @master_mode: boolean to know in which mode the I2C is running (master or
276 * slave)
277 * @dma: dma data
278 * @use_dma: boolean to know if dma is used in the current transfer
207 */ 279 */
208struct stm32f7_i2c_dev { 280struct stm32f7_i2c_dev {
209 struct i2c_adapter adap; 281 struct i2c_adapter adap;
@@ -218,6 +290,12 @@ struct stm32f7_i2c_dev {
218 struct stm32f7_i2c_msg f7_msg; 290 struct stm32f7_i2c_msg f7_msg;
219 struct stm32f7_i2c_setup setup; 291 struct stm32f7_i2c_setup setup;
220 struct stm32f7_i2c_timings timing; 292 struct stm32f7_i2c_timings timing;
293 struct i2c_client *slave[STM32F7_I2C_MAX_SLAVE];
294 struct i2c_client *slave_running;
295 u32 slave_dir;
296 bool master_mode;
297 struct stm32_i2c_dma *dma;
298 bool use_dma;
221}; 299};
222 300
223/** 301/**
@@ -283,6 +361,11 @@ static inline void stm32f7_i2c_clr_bits(void __iomem *reg, u32 mask)
283 writel_relaxed(readl_relaxed(reg) & ~mask, reg); 361 writel_relaxed(readl_relaxed(reg) & ~mask, reg);
284} 362}
285 363
364static void stm32f7_i2c_disable_irq(struct stm32f7_i2c_dev *i2c_dev, u32 mask)
365{
366 stm32f7_i2c_clr_bits(i2c_dev->base + STM32F7_I2C_CR1, mask);
367}
368
286static int stm32f7_i2c_compute_timing(struct stm32f7_i2c_dev *i2c_dev, 369static int stm32f7_i2c_compute_timing(struct stm32f7_i2c_dev *i2c_dev,
287 struct stm32f7_i2c_setup *setup, 370 struct stm32f7_i2c_setup *setup,
288 struct stm32f7_i2c_timings *output) 371 struct stm32f7_i2c_timings *output)
@@ -524,6 +607,25 @@ static int stm32f7_i2c_setup_timing(struct stm32f7_i2c_dev *i2c_dev,
524 return 0; 607 return 0;
525} 608}
526 609
610static void stm32f7_i2c_disable_dma_req(struct stm32f7_i2c_dev *i2c_dev)
611{
612 void __iomem *base = i2c_dev->base;
613 u32 mask = STM32F7_I2C_CR1_RXDMAEN | STM32F7_I2C_CR1_TXDMAEN;
614
615 stm32f7_i2c_clr_bits(base + STM32F7_I2C_CR1, mask);
616}
617
618static void stm32f7_i2c_dma_callback(void *arg)
619{
620 struct stm32f7_i2c_dev *i2c_dev = (struct stm32f7_i2c_dev *)arg;
621 struct stm32_i2c_dma *dma = i2c_dev->dma;
622 struct device *dev = dma->chan_using->device->dev;
623
624 stm32f7_i2c_disable_dma_req(i2c_dev);
625 dma_unmap_single(dev, dma->dma_buf, dma->dma_len, dma->dma_data_dir);
626 complete(&dma->dma_complete);
627}
628
527static void stm32f7_i2c_hw_config(struct stm32f7_i2c_dev *i2c_dev) 629static void stm32f7_i2c_hw_config(struct stm32f7_i2c_dev *i2c_dev)
528{ 630{
529 struct stm32f7_i2c_timings *t = &i2c_dev->timing; 631 struct stm32f7_i2c_timings *t = &i2c_dev->timing;
@@ -567,6 +669,9 @@ static void stm32f7_i2c_read_rx_data(struct stm32f7_i2c_dev *i2c_dev)
567 if (f7_msg->count) { 669 if (f7_msg->count) {
568 *f7_msg->buf++ = readb_relaxed(base + STM32F7_I2C_RXDR); 670 *f7_msg->buf++ = readb_relaxed(base + STM32F7_I2C_RXDR);
569 f7_msg->count--; 671 f7_msg->count--;
672 } else {
673 /* Flush RX buffer has no data is expected */
674 readb_relaxed(base + STM32F7_I2C_RXDR);
570 } 675 }
571} 676}
572 677
@@ -575,6 +680,9 @@ static void stm32f7_i2c_reload(struct stm32f7_i2c_dev *i2c_dev)
575 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; 680 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg;
576 u32 cr2; 681 u32 cr2;
577 682
683 if (i2c_dev->use_dma)
684 f7_msg->count -= STM32F7_I2C_MAX_LEN;
685
578 cr2 = readl_relaxed(i2c_dev->base + STM32F7_I2C_CR2); 686 cr2 = readl_relaxed(i2c_dev->base + STM32F7_I2C_CR2);
579 687
580 cr2 &= ~STM32F7_I2C_CR2_NBYTES_MASK; 688 cr2 &= ~STM32F7_I2C_CR2_NBYTES_MASK;
@@ -588,6 +696,43 @@ static void stm32f7_i2c_reload(struct stm32f7_i2c_dev *i2c_dev)
588 writel_relaxed(cr2, i2c_dev->base + STM32F7_I2C_CR2); 696 writel_relaxed(cr2, i2c_dev->base + STM32F7_I2C_CR2);
589} 697}
590 698
699static void stm32f7_i2c_smbus_reload(struct stm32f7_i2c_dev *i2c_dev)
700{
701 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg;
702 u32 cr2;
703 u8 *val;
704
705 /*
706 * For I2C_SMBUS_BLOCK_DATA && I2C_SMBUS_BLOCK_PROC_CALL, the first
707 * data received inform us how many data will follow.
708 */
709 stm32f7_i2c_read_rx_data(i2c_dev);
710
711 /*
712 * Update NBYTES with the value read to continue the transfer
713 */
714 val = f7_msg->buf - sizeof(u8);
715 f7_msg->count = *val;
716 cr2 = readl_relaxed(i2c_dev->base + STM32F7_I2C_CR2);
717 cr2 &= ~(STM32F7_I2C_CR2_NBYTES_MASK | STM32F7_I2C_CR2_RELOAD);
718 cr2 |= STM32F7_I2C_CR2_NBYTES(f7_msg->count);
719 writel_relaxed(cr2, i2c_dev->base + STM32F7_I2C_CR2);
720}
721
722static int stm32f7_i2c_release_bus(struct i2c_adapter *i2c_adap)
723{
724 struct stm32f7_i2c_dev *i2c_dev = i2c_get_adapdata(i2c_adap);
725
726 dev_info(i2c_dev->dev, "Trying to recover bus\n");
727
728 stm32f7_i2c_clr_bits(i2c_dev->base + STM32F7_I2C_CR1,
729 STM32F7_I2C_CR1_PE);
730
731 stm32f7_i2c_hw_config(i2c_dev);
732
733 return 0;
734}
735
591static int stm32f7_i2c_wait_free_bus(struct stm32f7_i2c_dev *i2c_dev) 736static int stm32f7_i2c_wait_free_bus(struct stm32f7_i2c_dev *i2c_dev)
592{ 737{
593 u32 status; 738 u32 status;
@@ -597,12 +742,18 @@ static int stm32f7_i2c_wait_free_bus(struct stm32f7_i2c_dev *i2c_dev)
597 status, 742 status,
598 !(status & STM32F7_I2C_ISR_BUSY), 743 !(status & STM32F7_I2C_ISR_BUSY),
599 10, 1000); 744 10, 1000);
745 if (!ret)
746 return 0;
747
748 dev_info(i2c_dev->dev, "bus busy\n");
749
750 ret = stm32f7_i2c_release_bus(&i2c_dev->adap);
600 if (ret) { 751 if (ret) {
601 dev_dbg(i2c_dev->dev, "bus busy\n"); 752 dev_err(i2c_dev->dev, "Failed to recover the bus (%d)\n", ret);
602 ret = -EBUSY; 753 return ret;
603 } 754 }
604 755
605 return ret; 756 return -EBUSY;
606} 757}
607 758
608static void stm32f7_i2c_xfer_msg(struct stm32f7_i2c_dev *i2c_dev, 759static void stm32f7_i2c_xfer_msg(struct stm32f7_i2c_dev *i2c_dev,
@@ -611,6 +762,7 @@ static void stm32f7_i2c_xfer_msg(struct stm32f7_i2c_dev *i2c_dev,
611 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; 762 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg;
612 void __iomem *base = i2c_dev->base; 763 void __iomem *base = i2c_dev->base;
613 u32 cr1, cr2; 764 u32 cr1, cr2;
765 int ret;
614 766
615 f7_msg->addr = msg->addr; 767 f7_msg->addr = msg->addr;
616 f7_msg->buf = msg->buf; 768 f7_msg->buf = msg->buf;
@@ -629,8 +781,15 @@ static void stm32f7_i2c_xfer_msg(struct stm32f7_i2c_dev *i2c_dev,
629 cr2 |= STM32F7_I2C_CR2_RD_WRN; 781 cr2 |= STM32F7_I2C_CR2_RD_WRN;
630 782
631 /* Set slave address */ 783 /* Set slave address */
632 cr2 &= ~STM32F7_I2C_CR2_SADD7_MASK; 784 cr2 &= ~(STM32F7_I2C_CR2_HEAD10R | STM32F7_I2C_CR2_ADD10);
633 cr2 |= STM32F7_I2C_CR2_SADD7(f7_msg->addr); 785 if (msg->flags & I2C_M_TEN) {
786 cr2 &= ~STM32F7_I2C_CR2_SADD10_MASK;
787 cr2 |= STM32F7_I2C_CR2_SADD10(f7_msg->addr);
788 cr2 |= STM32F7_I2C_CR2_ADD10;
789 } else {
790 cr2 &= ~STM32F7_I2C_CR2_SADD7_MASK;
791 cr2 |= STM32F7_I2C_CR2_SADD7(f7_msg->addr);
792 }
634 793
635 /* Set nb bytes to transfer and reload if needed */ 794 /* Set nb bytes to transfer and reload if needed */
636 cr2 &= ~(STM32F7_I2C_CR2_NBYTES_MASK | STM32F7_I2C_CR2_RELOAD); 795 cr2 &= ~(STM32F7_I2C_CR2_NBYTES_MASK | STM32F7_I2C_CR2_RELOAD);
@@ -645,16 +804,286 @@ static void stm32f7_i2c_xfer_msg(struct stm32f7_i2c_dev *i2c_dev,
645 cr1 |= STM32F7_I2C_CR1_ERRIE | STM32F7_I2C_CR1_TCIE | 804 cr1 |= STM32F7_I2C_CR1_ERRIE | STM32F7_I2C_CR1_TCIE |
646 STM32F7_I2C_CR1_STOPIE | STM32F7_I2C_CR1_NACKIE; 805 STM32F7_I2C_CR1_STOPIE | STM32F7_I2C_CR1_NACKIE;
647 806
648 /* Clear TX/RX interrupt */ 807 /* Clear DMA req and TX/RX interrupt */
808 cr1 &= ~(STM32F7_I2C_CR1_RXIE | STM32F7_I2C_CR1_TXIE |
809 STM32F7_I2C_CR1_RXDMAEN | STM32F7_I2C_CR1_TXDMAEN);
810
811 /* Configure DMA or enable RX/TX interrupt */
812 i2c_dev->use_dma = false;
813 if (i2c_dev->dma && f7_msg->count >= STM32F7_I2C_DMA_LEN_MIN) {
814 ret = stm32_i2c_prep_dma_xfer(i2c_dev->dev, i2c_dev->dma,
815 msg->flags & I2C_M_RD,
816 f7_msg->count, f7_msg->buf,
817 stm32f7_i2c_dma_callback,
818 i2c_dev);
819 if (!ret)
820 i2c_dev->use_dma = true;
821 else
822 dev_warn(i2c_dev->dev, "can't use DMA\n");
823 }
824
825 if (!i2c_dev->use_dma) {
826 if (msg->flags & I2C_M_RD)
827 cr1 |= STM32F7_I2C_CR1_RXIE;
828 else
829 cr1 |= STM32F7_I2C_CR1_TXIE;
830 } else {
831 if (msg->flags & I2C_M_RD)
832 cr1 |= STM32F7_I2C_CR1_RXDMAEN;
833 else
834 cr1 |= STM32F7_I2C_CR1_TXDMAEN;
835 }
836
837 /* Configure Start/Repeated Start */
838 cr2 |= STM32F7_I2C_CR2_START;
839
840 i2c_dev->master_mode = true;
841
842 /* Write configurations registers */
843 writel_relaxed(cr1, base + STM32F7_I2C_CR1);
844 writel_relaxed(cr2, base + STM32F7_I2C_CR2);
845}
846
847static int stm32f7_i2c_smbus_xfer_msg(struct stm32f7_i2c_dev *i2c_dev,
848 unsigned short flags, u8 command,
849 union i2c_smbus_data *data)
850{
851 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg;
852 struct device *dev = i2c_dev->dev;
853 void __iomem *base = i2c_dev->base;
854 u32 cr1, cr2;
855 int i, ret;
856
857 f7_msg->result = 0;
858 reinit_completion(&i2c_dev->complete);
859
860 cr2 = readl_relaxed(base + STM32F7_I2C_CR2);
861 cr1 = readl_relaxed(base + STM32F7_I2C_CR1);
862
863 /* Set transfer direction */
864 cr2 &= ~STM32F7_I2C_CR2_RD_WRN;
865 if (f7_msg->read_write)
866 cr2 |= STM32F7_I2C_CR2_RD_WRN;
867
868 /* Set slave address */
869 cr2 &= ~(STM32F7_I2C_CR2_ADD10 | STM32F7_I2C_CR2_SADD7_MASK);
870 cr2 |= STM32F7_I2C_CR2_SADD7(f7_msg->addr);
871
872 f7_msg->smbus_buf[0] = command;
873 switch (f7_msg->size) {
874 case I2C_SMBUS_QUICK:
875 f7_msg->stop = true;
876 f7_msg->count = 0;
877 break;
878 case I2C_SMBUS_BYTE:
879 f7_msg->stop = true;
880 f7_msg->count = 1;
881 break;
882 case I2C_SMBUS_BYTE_DATA:
883 if (f7_msg->read_write) {
884 f7_msg->stop = false;
885 f7_msg->count = 1;
886 cr2 &= ~STM32F7_I2C_CR2_RD_WRN;
887 } else {
888 f7_msg->stop = true;
889 f7_msg->count = 2;
890 f7_msg->smbus_buf[1] = data->byte;
891 }
892 break;
893 case I2C_SMBUS_WORD_DATA:
894 if (f7_msg->read_write) {
895 f7_msg->stop = false;
896 f7_msg->count = 1;
897 cr2 &= ~STM32F7_I2C_CR2_RD_WRN;
898 } else {
899 f7_msg->stop = true;
900 f7_msg->count = 3;
901 f7_msg->smbus_buf[1] = data->word & 0xff;
902 f7_msg->smbus_buf[2] = data->word >> 8;
903 }
904 break;
905 case I2C_SMBUS_BLOCK_DATA:
906 if (f7_msg->read_write) {
907 f7_msg->stop = false;
908 f7_msg->count = 1;
909 cr2 &= ~STM32F7_I2C_CR2_RD_WRN;
910 } else {
911 f7_msg->stop = true;
912 if (data->block[0] > I2C_SMBUS_BLOCK_MAX ||
913 !data->block[0]) {
914 dev_err(dev, "Invalid block write size %d\n",
915 data->block[0]);
916 return -EINVAL;
917 }
918 f7_msg->count = data->block[0] + 2;
919 for (i = 1; i < f7_msg->count; i++)
920 f7_msg->smbus_buf[i] = data->block[i - 1];
921 }
922 break;
923 case I2C_SMBUS_PROC_CALL:
924 f7_msg->stop = false;
925 f7_msg->count = 3;
926 f7_msg->smbus_buf[1] = data->word & 0xff;
927 f7_msg->smbus_buf[2] = data->word >> 8;
928 cr2 &= ~STM32F7_I2C_CR2_RD_WRN;
929 f7_msg->read_write = I2C_SMBUS_READ;
930 break;
931 case I2C_SMBUS_BLOCK_PROC_CALL:
932 f7_msg->stop = false;
933 if (data->block[0] > I2C_SMBUS_BLOCK_MAX - 1) {
934 dev_err(dev, "Invalid block write size %d\n",
935 data->block[0]);
936 return -EINVAL;
937 }
938 f7_msg->count = data->block[0] + 2;
939 for (i = 1; i < f7_msg->count; i++)
940 f7_msg->smbus_buf[i] = data->block[i - 1];
941 cr2 &= ~STM32F7_I2C_CR2_RD_WRN;
942 f7_msg->read_write = I2C_SMBUS_READ;
943 break;
944 default:
945 dev_err(dev, "Unsupported smbus protocol %d\n", f7_msg->size);
946 return -EOPNOTSUPP;
947 }
948
949 f7_msg->buf = f7_msg->smbus_buf;
950
951 /* Configure PEC */
952 if ((flags & I2C_CLIENT_PEC) && f7_msg->size != I2C_SMBUS_QUICK) {
953 cr1 |= STM32F7_I2C_CR1_PECEN;
954 cr2 |= STM32F7_I2C_CR2_PECBYTE;
955 if (!f7_msg->read_write)
956 f7_msg->count++;
957 } else {
958 cr1 &= ~STM32F7_I2C_CR1_PECEN;
959 cr2 &= ~STM32F7_I2C_CR2_PECBYTE;
960 }
961
962 /* Set number of bytes to be transferred */
963 cr2 &= ~(STM32F7_I2C_CR2_NBYTES_MASK | STM32F7_I2C_CR2_RELOAD);
964 cr2 |= STM32F7_I2C_CR2_NBYTES(f7_msg->count);
965
966 /* Enable NACK, STOP, error and transfer complete interrupts */
967 cr1 |= STM32F7_I2C_CR1_ERRIE | STM32F7_I2C_CR1_TCIE |
968 STM32F7_I2C_CR1_STOPIE | STM32F7_I2C_CR1_NACKIE;
969
970 /* Clear DMA req and TX/RX interrupt */
971 cr1 &= ~(STM32F7_I2C_CR1_RXIE | STM32F7_I2C_CR1_TXIE |
972 STM32F7_I2C_CR1_RXDMAEN | STM32F7_I2C_CR1_TXDMAEN);
973
974 /* Configure DMA or enable RX/TX interrupt */
975 i2c_dev->use_dma = false;
976 if (i2c_dev->dma && f7_msg->count >= STM32F7_I2C_DMA_LEN_MIN) {
977 ret = stm32_i2c_prep_dma_xfer(i2c_dev->dev, i2c_dev->dma,
978 cr2 & STM32F7_I2C_CR2_RD_WRN,
979 f7_msg->count, f7_msg->buf,
980 stm32f7_i2c_dma_callback,
981 i2c_dev);
982 if (!ret)
983 i2c_dev->use_dma = true;
984 else
985 dev_warn(i2c_dev->dev, "can't use DMA\n");
986 }
987
988 if (!i2c_dev->use_dma) {
989 if (cr2 & STM32F7_I2C_CR2_RD_WRN)
990 cr1 |= STM32F7_I2C_CR1_RXIE;
991 else
992 cr1 |= STM32F7_I2C_CR1_TXIE;
993 } else {
994 if (cr2 & STM32F7_I2C_CR2_RD_WRN)
995 cr1 |= STM32F7_I2C_CR1_RXDMAEN;
996 else
997 cr1 |= STM32F7_I2C_CR1_TXDMAEN;
998 }
999
1000 /* Set Start bit */
1001 cr2 |= STM32F7_I2C_CR2_START;
1002
1003 i2c_dev->master_mode = true;
1004
1005 /* Write configurations registers */
1006 writel_relaxed(cr1, base + STM32F7_I2C_CR1);
1007 writel_relaxed(cr2, base + STM32F7_I2C_CR2);
1008
1009 return 0;
1010}
1011
1012static void stm32f7_i2c_smbus_rep_start(struct stm32f7_i2c_dev *i2c_dev)
1013{
1014 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg;
1015 void __iomem *base = i2c_dev->base;
1016 u32 cr1, cr2;
1017 int ret;
1018
1019 cr2 = readl_relaxed(base + STM32F7_I2C_CR2);
1020 cr1 = readl_relaxed(base + STM32F7_I2C_CR1);
1021
1022 /* Set transfer direction */
1023 cr2 |= STM32F7_I2C_CR2_RD_WRN;
1024
1025 switch (f7_msg->size) {
1026 case I2C_SMBUS_BYTE_DATA:
1027 f7_msg->count = 1;
1028 break;
1029 case I2C_SMBUS_WORD_DATA:
1030 case I2C_SMBUS_PROC_CALL:
1031 f7_msg->count = 2;
1032 break;
1033 case I2C_SMBUS_BLOCK_DATA:
1034 case I2C_SMBUS_BLOCK_PROC_CALL:
1035 f7_msg->count = 1;
1036 cr2 |= STM32F7_I2C_CR2_RELOAD;
1037 break;
1038 }
1039
1040 f7_msg->buf = f7_msg->smbus_buf;
1041 f7_msg->stop = true;
1042
1043 /* Add one byte for PEC if needed */
1044 if (cr1 & STM32F7_I2C_CR1_PECEN)
1045 f7_msg->count++;
1046
1047 /* Set number of bytes to be transferred */
1048 cr2 &= ~(STM32F7_I2C_CR2_NBYTES_MASK);
1049 cr2 |= STM32F7_I2C_CR2_NBYTES(f7_msg->count);
1050
1051 /*
1052 * Configure RX/TX interrupt:
1053 */
649 cr1 &= ~(STM32F7_I2C_CR1_RXIE | STM32F7_I2C_CR1_TXIE); 1054 cr1 &= ~(STM32F7_I2C_CR1_RXIE | STM32F7_I2C_CR1_TXIE);
1055 cr1 |= STM32F7_I2C_CR1_RXIE;
650 1056
651 /* Enable RX/TX interrupt according to msg direction */ 1057 /*
652 if (msg->flags & I2C_M_RD) 1058 * Configure DMA or enable RX/TX interrupt:
1059 * For I2C_SMBUS_BLOCK_DATA and I2C_SMBUS_BLOCK_PROC_CALL we don't use
1060 * dma as we don't know in advance how many data will be received
1061 */
1062 cr1 &= ~(STM32F7_I2C_CR1_RXIE | STM32F7_I2C_CR1_TXIE |
1063 STM32F7_I2C_CR1_RXDMAEN | STM32F7_I2C_CR1_TXDMAEN);
1064
1065 i2c_dev->use_dma = false;
1066 if (i2c_dev->dma && f7_msg->count >= STM32F7_I2C_DMA_LEN_MIN &&
1067 f7_msg->size != I2C_SMBUS_BLOCK_DATA &&
1068 f7_msg->size != I2C_SMBUS_BLOCK_PROC_CALL) {
1069 ret = stm32_i2c_prep_dma_xfer(i2c_dev->dev, i2c_dev->dma,
1070 cr2 & STM32F7_I2C_CR2_RD_WRN,
1071 f7_msg->count, f7_msg->buf,
1072 stm32f7_i2c_dma_callback,
1073 i2c_dev);
1074
1075 if (!ret)
1076 i2c_dev->use_dma = true;
1077 else
1078 dev_warn(i2c_dev->dev, "can't use DMA\n");
1079 }
1080
1081 if (!i2c_dev->use_dma)
653 cr1 |= STM32F7_I2C_CR1_RXIE; 1082 cr1 |= STM32F7_I2C_CR1_RXIE;
654 else 1083 else
655 cr1 |= STM32F7_I2C_CR1_TXIE; 1084 cr1 |= STM32F7_I2C_CR1_RXDMAEN;
656 1085
657 /* Configure Start/Repeated Start */ 1086 /* Configure Repeated Start */
658 cr2 |= STM32F7_I2C_CR2_START; 1087 cr2 |= STM32F7_I2C_CR2_START;
659 1088
660 /* Write configurations registers */ 1089 /* Write configurations registers */
@@ -662,9 +1091,278 @@ static void stm32f7_i2c_xfer_msg(struct stm32f7_i2c_dev *i2c_dev,
662 writel_relaxed(cr2, base + STM32F7_I2C_CR2); 1091 writel_relaxed(cr2, base + STM32F7_I2C_CR2);
663} 1092}
664 1093
665static void stm32f7_i2c_disable_irq(struct stm32f7_i2c_dev *i2c_dev, u32 mask) 1094static int stm32f7_i2c_smbus_check_pec(struct stm32f7_i2c_dev *i2c_dev)
666{ 1095{
667 stm32f7_i2c_clr_bits(i2c_dev->base + STM32F7_I2C_CR1, mask); 1096 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg;
1097 u8 count, internal_pec, received_pec;
1098
1099 internal_pec = readl_relaxed(i2c_dev->base + STM32F7_I2C_PECR);
1100
1101 switch (f7_msg->size) {
1102 case I2C_SMBUS_BYTE:
1103 case I2C_SMBUS_BYTE_DATA:
1104 received_pec = f7_msg->smbus_buf[1];
1105 break;
1106 case I2C_SMBUS_WORD_DATA:
1107 case I2C_SMBUS_PROC_CALL:
1108 received_pec = f7_msg->smbus_buf[2];
1109 break;
1110 case I2C_SMBUS_BLOCK_DATA:
1111 case I2C_SMBUS_BLOCK_PROC_CALL:
1112 count = f7_msg->smbus_buf[0];
1113 received_pec = f7_msg->smbus_buf[count];
1114 break;
1115 default:
1116 dev_err(i2c_dev->dev, "Unsupported smbus protocol for PEC\n");
1117 return -EINVAL;
1118 }
1119
1120 if (internal_pec != received_pec) {
1121 dev_err(i2c_dev->dev, "Bad PEC 0x%02x vs. 0x%02x\n",
1122 internal_pec, received_pec);
1123 return -EBADMSG;
1124 }
1125
1126 return 0;
1127}
1128
1129static bool stm32f7_i2c_is_addr_match(struct i2c_client *slave, u32 addcode)
1130{
1131 u32 addr;
1132
1133 if (!slave)
1134 return false;
1135
1136 if (slave->flags & I2C_CLIENT_TEN) {
1137 /*
1138 * For 10-bit addr, addcode = 11110XY with
1139 * X = Bit 9 of slave address
1140 * Y = Bit 8 of slave address
1141 */
1142 addr = slave->addr >> 8;
1143 addr |= 0x78;
1144 if (addr == addcode)
1145 return true;
1146 } else {
1147 addr = slave->addr & 0x7f;
1148 if (addr == addcode)
1149 return true;
1150 }
1151
1152 return false;
1153}
1154
1155static void stm32f7_i2c_slave_start(struct stm32f7_i2c_dev *i2c_dev)
1156{
1157 struct i2c_client *slave = i2c_dev->slave_running;
1158 void __iomem *base = i2c_dev->base;
1159 u32 mask;
1160 u8 value = 0;
1161
1162 if (i2c_dev->slave_dir) {
1163 /* Notify i2c slave that new read transfer is starting */
1164 i2c_slave_event(slave, I2C_SLAVE_READ_REQUESTED, &value);
1165
1166 /*
1167 * Disable slave TX config in case of I2C combined message
1168 * (I2C Write followed by I2C Read)
1169 */
1170 mask = STM32F7_I2C_CR2_RELOAD;
1171 stm32f7_i2c_clr_bits(base + STM32F7_I2C_CR2, mask);
1172 mask = STM32F7_I2C_CR1_SBC | STM32F7_I2C_CR1_RXIE |
1173 STM32F7_I2C_CR1_TCIE;
1174 stm32f7_i2c_clr_bits(base + STM32F7_I2C_CR1, mask);
1175
1176 /* Enable TX empty, STOP, NACK interrupts */
1177 mask = STM32F7_I2C_CR1_STOPIE | STM32F7_I2C_CR1_NACKIE |
1178 STM32F7_I2C_CR1_TXIE;
1179 stm32f7_i2c_set_bits(base + STM32F7_I2C_CR1, mask);
1180
1181 } else {
1182 /* Notify i2c slave that new write transfer is starting */
1183 i2c_slave_event(slave, I2C_SLAVE_WRITE_REQUESTED, &value);
1184
1185 /* Set reload mode to be able to ACK/NACK each received byte */
1186 mask = STM32F7_I2C_CR2_RELOAD;
1187 stm32f7_i2c_set_bits(base + STM32F7_I2C_CR2, mask);
1188
1189 /*
1190 * Set STOP, NACK, RX empty and transfer complete interrupts.*
1191 * Set Slave Byte Control to be able to ACK/NACK each data
1192 * byte received
1193 */
1194 mask = STM32F7_I2C_CR1_STOPIE | STM32F7_I2C_CR1_NACKIE |
1195 STM32F7_I2C_CR1_SBC | STM32F7_I2C_CR1_RXIE |
1196 STM32F7_I2C_CR1_TCIE;
1197 stm32f7_i2c_set_bits(base + STM32F7_I2C_CR1, mask);
1198 }
1199}
1200
1201static void stm32f7_i2c_slave_addr(struct stm32f7_i2c_dev *i2c_dev)
1202{
1203 void __iomem *base = i2c_dev->base;
1204 u32 isr, addcode, dir, mask;
1205 int i;
1206
1207 isr = readl_relaxed(i2c_dev->base + STM32F7_I2C_ISR);
1208 addcode = STM32F7_I2C_ISR_ADDCODE_GET(isr);
1209 dir = isr & STM32F7_I2C_ISR_DIR;
1210
1211 for (i = 0; i < STM32F7_I2C_MAX_SLAVE; i++) {
1212 if (stm32f7_i2c_is_addr_match(i2c_dev->slave[i], addcode)) {
1213 i2c_dev->slave_running = i2c_dev->slave[i];
1214 i2c_dev->slave_dir = dir;
1215
1216 /* Start I2C slave processing */
1217 stm32f7_i2c_slave_start(i2c_dev);
1218
1219 /* Clear ADDR flag */
1220 mask = STM32F7_I2C_ICR_ADDRCF;
1221 writel_relaxed(mask, base + STM32F7_I2C_ICR);
1222 break;
1223 }
1224 }
1225}
1226
1227static int stm32f7_i2c_get_slave_id(struct stm32f7_i2c_dev *i2c_dev,
1228 struct i2c_client *slave, int *id)
1229{
1230 int i;
1231
1232 for (i = 0; i < STM32F7_I2C_MAX_SLAVE; i++) {
1233 if (i2c_dev->slave[i] == slave) {
1234 *id = i;
1235 return 0;
1236 }
1237 }
1238
1239 dev_err(i2c_dev->dev, "Slave 0x%x not registered\n", slave->addr);
1240
1241 return -ENODEV;
1242}
1243
1244static int stm32f7_i2c_get_free_slave_id(struct stm32f7_i2c_dev *i2c_dev,
1245 struct i2c_client *slave, int *id)
1246{
1247 struct device *dev = i2c_dev->dev;
1248 int i;
1249
1250 /*
1251 * slave[0] supports 7-bit and 10-bit slave address
1252 * slave[1] supports 7-bit slave address only
1253 */
1254 for (i = 0; i < STM32F7_I2C_MAX_SLAVE; i++) {
1255 if (i == 1 && (slave->flags & I2C_CLIENT_PEC))
1256 continue;
1257 if (!i2c_dev->slave[i]) {
1258 *id = i;
1259 return 0;
1260 }
1261 }
1262
1263 dev_err(dev, "Slave 0x%x could not be registered\n", slave->addr);
1264
1265 return -EINVAL;
1266}
1267
1268static bool stm32f7_i2c_is_slave_registered(struct stm32f7_i2c_dev *i2c_dev)
1269{
1270 int i;
1271
1272 for (i = 0; i < STM32F7_I2C_MAX_SLAVE; i++) {
1273 if (i2c_dev->slave[i])
1274 return true;
1275 }
1276
1277 return false;
1278}
1279
1280static bool stm32f7_i2c_is_slave_busy(struct stm32f7_i2c_dev *i2c_dev)
1281{
1282 int i, busy;
1283
1284 busy = 0;
1285 for (i = 0; i < STM32F7_I2C_MAX_SLAVE; i++) {
1286 if (i2c_dev->slave[i])
1287 busy++;
1288 }
1289
1290 return i == busy;
1291}
1292
1293static irqreturn_t stm32f7_i2c_slave_isr_event(struct stm32f7_i2c_dev *i2c_dev)
1294{
1295 void __iomem *base = i2c_dev->base;
1296 u32 cr2, status, mask;
1297 u8 val;
1298 int ret;
1299
1300 status = readl_relaxed(i2c_dev->base + STM32F7_I2C_ISR);
1301
1302 /* Slave transmitter mode */
1303 if (status & STM32F7_I2C_ISR_TXIS) {
1304 i2c_slave_event(i2c_dev->slave_running,
1305 I2C_SLAVE_READ_PROCESSED,
1306 &val);
1307
1308 /* Write data byte */
1309 writel_relaxed(val, base + STM32F7_I2C_TXDR);
1310 }
1311
1312 /* Transfer Complete Reload for Slave receiver mode */
1313 if (status & STM32F7_I2C_ISR_TCR || status & STM32F7_I2C_ISR_RXNE) {
1314 /*
1315 * Read data byte then set NBYTES to receive next byte or NACK
1316 * the current received byte
1317 */
1318 val = readb_relaxed(i2c_dev->base + STM32F7_I2C_RXDR);
1319 ret = i2c_slave_event(i2c_dev->slave_running,
1320 I2C_SLAVE_WRITE_RECEIVED,
1321 &val);
1322 if (!ret) {
1323 cr2 = readl_relaxed(i2c_dev->base + STM32F7_I2C_CR2);
1324 cr2 |= STM32F7_I2C_CR2_NBYTES(1);
1325 writel_relaxed(cr2, i2c_dev->base + STM32F7_I2C_CR2);
1326 } else {
1327 mask = STM32F7_I2C_CR2_NACK;
1328 stm32f7_i2c_set_bits(base + STM32F7_I2C_CR2, mask);
1329 }
1330 }
1331
1332 /* NACK received */
1333 if (status & STM32F7_I2C_ISR_NACKF) {
1334 dev_dbg(i2c_dev->dev, "<%s>: Receive NACK\n", __func__);
1335 writel_relaxed(STM32F7_I2C_ICR_NACKCF, base + STM32F7_I2C_ICR);
1336 }
1337
1338 /* STOP received */
1339 if (status & STM32F7_I2C_ISR_STOPF) {
1340 /* Disable interrupts */
1341 stm32f7_i2c_disable_irq(i2c_dev, STM32F7_I2C_XFER_IRQ_MASK);
1342
1343 if (i2c_dev->slave_dir) {
1344 /*
1345 * Flush TX buffer in order to not used the byte in
1346 * TXDR for the next transfer
1347 */
1348 mask = STM32F7_I2C_ISR_TXE;
1349 stm32f7_i2c_set_bits(base + STM32F7_I2C_ISR, mask);
1350 }
1351
1352 /* Clear STOP flag */
1353 writel_relaxed(STM32F7_I2C_ICR_STOPCF, base + STM32F7_I2C_ICR);
1354
1355 /* Notify i2c slave that a STOP flag has been detected */
1356 i2c_slave_event(i2c_dev->slave_running, I2C_SLAVE_STOP, &val);
1357
1358 i2c_dev->slave_running = NULL;
1359 }
1360
1361 /* Address match received */
1362 if (status & STM32F7_I2C_ISR_ADDR)
1363 stm32f7_i2c_slave_addr(i2c_dev);
1364
1365 return IRQ_HANDLED;
668} 1366}
669 1367
670static irqreturn_t stm32f7_i2c_isr_event(int irq, void *data) 1368static irqreturn_t stm32f7_i2c_isr_event(int irq, void *data)
@@ -673,6 +1371,13 @@ static irqreturn_t stm32f7_i2c_isr_event(int irq, void *data)
673 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; 1371 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg;
674 void __iomem *base = i2c_dev->base; 1372 void __iomem *base = i2c_dev->base;
675 u32 status, mask; 1373 u32 status, mask;
1374 int ret = IRQ_HANDLED;
1375
1376 /* Check if the interrupt if for a slave device */
1377 if (!i2c_dev->master_mode) {
1378 ret = stm32f7_i2c_slave_isr_event(i2c_dev);
1379 return ret;
1380 }
676 1381
677 status = readl_relaxed(i2c_dev->base + STM32F7_I2C_ISR); 1382 status = readl_relaxed(i2c_dev->base + STM32F7_I2C_ISR);
678 1383
@@ -694,12 +1399,21 @@ static irqreturn_t stm32f7_i2c_isr_event(int irq, void *data)
694 /* STOP detection flag */ 1399 /* STOP detection flag */
695 if (status & STM32F7_I2C_ISR_STOPF) { 1400 if (status & STM32F7_I2C_ISR_STOPF) {
696 /* Disable interrupts */ 1401 /* Disable interrupts */
697 stm32f7_i2c_disable_irq(i2c_dev, STM32F7_I2C_ALL_IRQ_MASK); 1402 if (stm32f7_i2c_is_slave_registered(i2c_dev))
1403 mask = STM32F7_I2C_XFER_IRQ_MASK;
1404 else
1405 mask = STM32F7_I2C_ALL_IRQ_MASK;
1406 stm32f7_i2c_disable_irq(i2c_dev, mask);
698 1407
699 /* Clear STOP flag */ 1408 /* Clear STOP flag */
700 writel_relaxed(STM32F7_I2C_ICR_STOPCF, base + STM32F7_I2C_ICR); 1409 writel_relaxed(STM32F7_I2C_ICR_STOPCF, base + STM32F7_I2C_ICR);
701 1410
702 complete(&i2c_dev->complete); 1411 if (i2c_dev->use_dma) {
1412 ret = IRQ_WAKE_THREAD;
1413 } else {
1414 i2c_dev->master_mode = false;
1415 complete(&i2c_dev->complete);
1416 }
703 } 1417 }
704 1418
705 /* Transfer complete */ 1419 /* Transfer complete */
@@ -707,6 +1421,10 @@ static irqreturn_t stm32f7_i2c_isr_event(int irq, void *data)
707 if (f7_msg->stop) { 1421 if (f7_msg->stop) {
708 mask = STM32F7_I2C_CR2_STOP; 1422 mask = STM32F7_I2C_CR2_STOP;
709 stm32f7_i2c_set_bits(base + STM32F7_I2C_CR2, mask); 1423 stm32f7_i2c_set_bits(base + STM32F7_I2C_CR2, mask);
1424 } else if (i2c_dev->use_dma) {
1425 ret = IRQ_WAKE_THREAD;
1426 } else if (f7_msg->smbus) {
1427 stm32f7_i2c_smbus_rep_start(i2c_dev);
710 } else { 1428 } else {
711 i2c_dev->msg_id++; 1429 i2c_dev->msg_id++;
712 i2c_dev->msg++; 1430 i2c_dev->msg++;
@@ -714,13 +1432,50 @@ static irqreturn_t stm32f7_i2c_isr_event(int irq, void *data)
714 } 1432 }
715 } 1433 }
716 1434
1435 if (status & STM32F7_I2C_ISR_TCR) {
1436 if (f7_msg->smbus)
1437 stm32f7_i2c_smbus_reload(i2c_dev);
1438 else
1439 stm32f7_i2c_reload(i2c_dev);
1440 }
1441
1442 return ret;
1443}
1444
1445static irqreturn_t stm32f7_i2c_isr_event_thread(int irq, void *data)
1446{
1447 struct stm32f7_i2c_dev *i2c_dev = data;
1448 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg;
1449 struct stm32_i2c_dma *dma = i2c_dev->dma;
1450 u32 status;
1451 int ret;
1452
717 /* 1453 /*
718 * Transfer Complete Reload: 255 data bytes have been transferred 1454 * Wait for dma transfer completion before sending next message or
719 * We have to prepare the I2C controller to transfer the remaining 1455 * notity the end of xfer to the client
720 * data.
721 */ 1456 */
722 if (status & STM32F7_I2C_ISR_TCR) 1457 ret = wait_for_completion_timeout(&i2c_dev->dma->dma_complete, HZ);
723 stm32f7_i2c_reload(i2c_dev); 1458 if (!ret) {
1459 dev_dbg(i2c_dev->dev, "<%s>: Timed out\n", __func__);
1460 stm32f7_i2c_disable_dma_req(i2c_dev);
1461 dmaengine_terminate_all(dma->chan_using);
1462 f7_msg->result = -ETIMEDOUT;
1463 }
1464
1465 status = readl_relaxed(i2c_dev->base + STM32F7_I2C_ISR);
1466
1467 if (status & STM32F7_I2C_ISR_TC) {
1468 if (f7_msg->smbus) {
1469 stm32f7_i2c_smbus_rep_start(i2c_dev);
1470 } else {
1471 i2c_dev->msg_id++;
1472 i2c_dev->msg++;
1473 stm32f7_i2c_xfer_msg(i2c_dev, i2c_dev->msg);
1474 }
1475 } else {
1476 i2c_dev->master_mode = false;
1477 complete(&i2c_dev->complete);
1478 }
724 1479
725 return IRQ_HANDLED; 1480 return IRQ_HANDLED;
726} 1481}
@@ -731,7 +1486,8 @@ static irqreturn_t stm32f7_i2c_isr_error(int irq, void *data)
731 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; 1486 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg;
732 void __iomem *base = i2c_dev->base; 1487 void __iomem *base = i2c_dev->base;
733 struct device *dev = i2c_dev->dev; 1488 struct device *dev = i2c_dev->dev;
734 u32 status; 1489 struct stm32_i2c_dma *dma = i2c_dev->dma;
1490 u32 mask, status;
735 1491
736 status = readl_relaxed(i2c_dev->base + STM32F7_I2C_ISR); 1492 status = readl_relaxed(i2c_dev->base + STM32F7_I2C_ISR);
737 1493
@@ -739,6 +1495,7 @@ static irqreturn_t stm32f7_i2c_isr_error(int irq, void *data)
739 if (status & STM32F7_I2C_ISR_BERR) { 1495 if (status & STM32F7_I2C_ISR_BERR) {
740 dev_err(dev, "<%s>: Bus error\n", __func__); 1496 dev_err(dev, "<%s>: Bus error\n", __func__);
741 writel_relaxed(STM32F7_I2C_ICR_BERRCF, base + STM32F7_I2C_ICR); 1497 writel_relaxed(STM32F7_I2C_ICR_BERRCF, base + STM32F7_I2C_ICR);
1498 stm32f7_i2c_release_bus(&i2c_dev->adap);
742 f7_msg->result = -EIO; 1499 f7_msg->result = -EIO;
743 } 1500 }
744 1501
@@ -749,8 +1506,26 @@ static irqreturn_t stm32f7_i2c_isr_error(int irq, void *data)
749 f7_msg->result = -EAGAIN; 1506 f7_msg->result = -EAGAIN;
750 } 1507 }
751 1508
752 stm32f7_i2c_disable_irq(i2c_dev, STM32F7_I2C_ALL_IRQ_MASK); 1509 if (status & STM32F7_I2C_ISR_PECERR) {
1510 dev_err(dev, "<%s>: PEC error in reception\n", __func__);
1511 writel_relaxed(STM32F7_I2C_ICR_PECCF, base + STM32F7_I2C_ICR);
1512 f7_msg->result = -EINVAL;
1513 }
1514
1515 /* Disable interrupts */
1516 if (stm32f7_i2c_is_slave_registered(i2c_dev))
1517 mask = STM32F7_I2C_XFER_IRQ_MASK;
1518 else
1519 mask = STM32F7_I2C_ALL_IRQ_MASK;
1520 stm32f7_i2c_disable_irq(i2c_dev, mask);
1521
1522 /* Disable dma */
1523 if (i2c_dev->use_dma) {
1524 stm32f7_i2c_disable_dma_req(i2c_dev);
1525 dmaengine_terminate_all(dma->chan_using);
1526 }
753 1527
1528 i2c_dev->master_mode = false;
754 complete(&i2c_dev->complete); 1529 complete(&i2c_dev->complete);
755 1530
756 return IRQ_HANDLED; 1531 return IRQ_HANDLED;
@@ -761,12 +1536,14 @@ static int stm32f7_i2c_xfer(struct i2c_adapter *i2c_adap,
761{ 1536{
762 struct stm32f7_i2c_dev *i2c_dev = i2c_get_adapdata(i2c_adap); 1537 struct stm32f7_i2c_dev *i2c_dev = i2c_get_adapdata(i2c_adap);
763 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; 1538 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg;
1539 struct stm32_i2c_dma *dma = i2c_dev->dma;
764 unsigned long time_left; 1540 unsigned long time_left;
765 int ret; 1541 int ret;
766 1542
767 i2c_dev->msg = msgs; 1543 i2c_dev->msg = msgs;
768 i2c_dev->msg_num = num; 1544 i2c_dev->msg_num = num;
769 i2c_dev->msg_id = 0; 1545 i2c_dev->msg_id = 0;
1546 f7_msg->smbus = false;
770 1547
771 ret = clk_enable(i2c_dev->clk); 1548 ret = clk_enable(i2c_dev->clk);
772 if (ret) { 1549 if (ret) {
@@ -787,6 +1564,8 @@ static int stm32f7_i2c_xfer(struct i2c_adapter *i2c_adap,
787 if (!time_left) { 1564 if (!time_left) {
788 dev_dbg(i2c_dev->dev, "Access to slave 0x%x timed out\n", 1565 dev_dbg(i2c_dev->dev, "Access to slave 0x%x timed out\n",
789 i2c_dev->msg->addr); 1566 i2c_dev->msg->addr);
1567 if (i2c_dev->use_dma)
1568 dmaengine_terminate_all(dma->chan_using);
790 ret = -ETIMEDOUT; 1569 ret = -ETIMEDOUT;
791 } 1570 }
792 1571
@@ -796,14 +1575,209 @@ clk_free:
796 return (ret < 0) ? ret : num; 1575 return (ret < 0) ? ret : num;
797} 1576}
798 1577
1578static int stm32f7_i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
1579 unsigned short flags, char read_write,
1580 u8 command, int size,
1581 union i2c_smbus_data *data)
1582{
1583 struct stm32f7_i2c_dev *i2c_dev = i2c_get_adapdata(adapter);
1584 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg;
1585 struct stm32_i2c_dma *dma = i2c_dev->dma;
1586 struct device *dev = i2c_dev->dev;
1587 unsigned long timeout;
1588 int i, ret;
1589
1590 f7_msg->addr = addr;
1591 f7_msg->size = size;
1592 f7_msg->read_write = read_write;
1593 f7_msg->smbus = true;
1594
1595 ret = clk_enable(i2c_dev->clk);
1596 if (ret) {
1597 dev_err(i2c_dev->dev, "Failed to enable clock\n");
1598 return ret;
1599 }
1600
1601 ret = stm32f7_i2c_wait_free_bus(i2c_dev);
1602 if (ret)
1603 goto clk_free;
1604
1605 ret = stm32f7_i2c_smbus_xfer_msg(i2c_dev, flags, command, data);
1606 if (ret)
1607 goto clk_free;
1608
1609 timeout = wait_for_completion_timeout(&i2c_dev->complete,
1610 i2c_dev->adap.timeout);
1611 ret = f7_msg->result;
1612 if (ret)
1613 goto clk_free;
1614
1615 if (!timeout) {
1616 dev_dbg(dev, "Access to slave 0x%x timed out\n", f7_msg->addr);
1617 if (i2c_dev->use_dma)
1618 dmaengine_terminate_all(dma->chan_using);
1619 ret = -ETIMEDOUT;
1620 goto clk_free;
1621 }
1622
1623 /* Check PEC */
1624 if ((flags & I2C_CLIENT_PEC) && size != I2C_SMBUS_QUICK && read_write) {
1625 ret = stm32f7_i2c_smbus_check_pec(i2c_dev);
1626 if (ret)
1627 goto clk_free;
1628 }
1629
1630 if (read_write && size != I2C_SMBUS_QUICK) {
1631 switch (size) {
1632 case I2C_SMBUS_BYTE:
1633 case I2C_SMBUS_BYTE_DATA:
1634 data->byte = f7_msg->smbus_buf[0];
1635 break;
1636 case I2C_SMBUS_WORD_DATA:
1637 case I2C_SMBUS_PROC_CALL:
1638 data->word = f7_msg->smbus_buf[0] |
1639 (f7_msg->smbus_buf[1] << 8);
1640 break;
1641 case I2C_SMBUS_BLOCK_DATA:
1642 case I2C_SMBUS_BLOCK_PROC_CALL:
1643 for (i = 0; i <= f7_msg->smbus_buf[0]; i++)
1644 data->block[i] = f7_msg->smbus_buf[i];
1645 break;
1646 default:
1647 dev_err(dev, "Unsupported smbus transaction\n");
1648 ret = -EINVAL;
1649 }
1650 }
1651
1652clk_free:
1653 clk_disable(i2c_dev->clk);
1654 return ret;
1655}
1656
1657static int stm32f7_i2c_reg_slave(struct i2c_client *slave)
1658{
1659 struct stm32f7_i2c_dev *i2c_dev = i2c_get_adapdata(slave->adapter);
1660 void __iomem *base = i2c_dev->base;
1661 struct device *dev = i2c_dev->dev;
1662 u32 oar1, oar2, mask;
1663 int id, ret;
1664
1665 if (slave->flags & I2C_CLIENT_PEC) {
1666 dev_err(dev, "SMBus PEC not supported in slave mode\n");
1667 return -EINVAL;
1668 }
1669
1670 if (stm32f7_i2c_is_slave_busy(i2c_dev)) {
1671 dev_err(dev, "Too much slave registered\n");
1672 return -EBUSY;
1673 }
1674
1675 ret = stm32f7_i2c_get_free_slave_id(i2c_dev, slave, &id);
1676 if (ret)
1677 return ret;
1678
1679 if (!(stm32f7_i2c_is_slave_registered(i2c_dev))) {
1680 ret = clk_enable(i2c_dev->clk);
1681 if (ret) {
1682 dev_err(dev, "Failed to enable clock\n");
1683 return ret;
1684 }
1685 }
1686
1687 if (id == 0) {
1688 /* Configure Own Address 1 */
1689 oar1 = readl_relaxed(i2c_dev->base + STM32F7_I2C_OAR1);
1690 oar1 &= ~STM32F7_I2C_OAR1_MASK;
1691 if (slave->flags & I2C_CLIENT_TEN) {
1692 oar1 |= STM32F7_I2C_OAR1_OA1_10(slave->addr);
1693 oar1 |= STM32F7_I2C_OAR1_OA1MODE;
1694 } else {
1695 oar1 |= STM32F7_I2C_OAR1_OA1_7(slave->addr);
1696 }
1697 oar1 |= STM32F7_I2C_OAR1_OA1EN;
1698 i2c_dev->slave[id] = slave;
1699 writel_relaxed(oar1, i2c_dev->base + STM32F7_I2C_OAR1);
1700 } else if (id == 1) {
1701 /* Configure Own Address 2 */
1702 oar2 = readl_relaxed(i2c_dev->base + STM32F7_I2C_OAR2);
1703 oar2 &= ~STM32F7_I2C_OAR2_MASK;
1704 if (slave->flags & I2C_CLIENT_TEN) {
1705 ret = -EOPNOTSUPP;
1706 goto exit;
1707 }
1708
1709 oar2 |= STM32F7_I2C_OAR2_OA2_7(slave->addr);
1710 oar2 |= STM32F7_I2C_OAR2_OA2EN;
1711 i2c_dev->slave[id] = slave;
1712 writel_relaxed(oar2, i2c_dev->base + STM32F7_I2C_OAR2);
1713 } else {
1714 ret = -ENODEV;
1715 goto exit;
1716 }
1717
1718 /* Enable ACK */
1719 stm32f7_i2c_clr_bits(base + STM32F7_I2C_CR2, STM32F7_I2C_CR2_NACK);
1720
1721 /* Enable Address match interrupt, error interrupt and enable I2C */
1722 mask = STM32F7_I2C_CR1_ADDRIE | STM32F7_I2C_CR1_ERRIE |
1723 STM32F7_I2C_CR1_PE;
1724 stm32f7_i2c_set_bits(base + STM32F7_I2C_CR1, mask);
1725
1726 return 0;
1727
1728exit:
1729 if (!(stm32f7_i2c_is_slave_registered(i2c_dev)))
1730 clk_disable(i2c_dev->clk);
1731
1732 return ret;
1733}
1734
1735static int stm32f7_i2c_unreg_slave(struct i2c_client *slave)
1736{
1737 struct stm32f7_i2c_dev *i2c_dev = i2c_get_adapdata(slave->adapter);
1738 void __iomem *base = i2c_dev->base;
1739 u32 mask;
1740 int id, ret;
1741
1742 ret = stm32f7_i2c_get_slave_id(i2c_dev, slave, &id);
1743 if (ret)
1744 return ret;
1745
1746 WARN_ON(!i2c_dev->slave[id]);
1747
1748 if (id == 0) {
1749 mask = STM32F7_I2C_OAR1_OA1EN;
1750 stm32f7_i2c_clr_bits(base + STM32F7_I2C_OAR1, mask);
1751 } else {
1752 mask = STM32F7_I2C_OAR2_OA2EN;
1753 stm32f7_i2c_clr_bits(base + STM32F7_I2C_OAR2, mask);
1754 }
1755
1756 i2c_dev->slave[id] = NULL;
1757
1758 if (!(stm32f7_i2c_is_slave_registered(i2c_dev))) {
1759 stm32f7_i2c_disable_irq(i2c_dev, STM32F7_I2C_ALL_IRQ_MASK);
1760 clk_disable(i2c_dev->clk);
1761 }
1762
1763 return 0;
1764}
1765
799static u32 stm32f7_i2c_func(struct i2c_adapter *adap) 1766static u32 stm32f7_i2c_func(struct i2c_adapter *adap)
800{ 1767{
801 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; 1768 return I2C_FUNC_I2C | I2C_FUNC_10BIT_ADDR | I2C_FUNC_SLAVE |
1769 I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
1770 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
1771 I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_BLOCK_PROC_CALL |
1772 I2C_FUNC_SMBUS_PROC_CALL | I2C_FUNC_SMBUS_PEC;
802} 1773}
803 1774
804static struct i2c_algorithm stm32f7_i2c_algo = { 1775static struct i2c_algorithm stm32f7_i2c_algo = {
805 .master_xfer = stm32f7_i2c_xfer, 1776 .master_xfer = stm32f7_i2c_xfer,
1777 .smbus_xfer = stm32f7_i2c_smbus_xfer,
806 .functionality = stm32f7_i2c_func, 1778 .functionality = stm32f7_i2c_func,
1779 .reg_slave = stm32f7_i2c_reg_slave,
1780 .unreg_slave = stm32f7_i2c_unreg_slave,
807}; 1781};
808 1782
809static int stm32f7_i2c_probe(struct platform_device *pdev) 1783static int stm32f7_i2c_probe(struct platform_device *pdev)
@@ -815,6 +1789,7 @@ static int stm32f7_i2c_probe(struct platform_device *pdev)
815 u32 irq_error, irq_event, clk_rate, rise_time, fall_time; 1789 u32 irq_error, irq_event, clk_rate, rise_time, fall_time;
816 struct i2c_adapter *adap; 1790 struct i2c_adapter *adap;
817 struct reset_control *rst; 1791 struct reset_control *rst;
1792 dma_addr_t phy_addr;
818 int ret; 1793 int ret;
819 1794
820 i2c_dev = devm_kzalloc(&pdev->dev, sizeof(*i2c_dev), GFP_KERNEL); 1795 i2c_dev = devm_kzalloc(&pdev->dev, sizeof(*i2c_dev), GFP_KERNEL);
@@ -825,6 +1800,7 @@ static int stm32f7_i2c_probe(struct platform_device *pdev)
825 i2c_dev->base = devm_ioremap_resource(&pdev->dev, res); 1800 i2c_dev->base = devm_ioremap_resource(&pdev->dev, res);
826 if (IS_ERR(i2c_dev->base)) 1801 if (IS_ERR(i2c_dev->base))
827 return PTR_ERR(i2c_dev->base); 1802 return PTR_ERR(i2c_dev->base);
1803 phy_addr = (dma_addr_t)res->start;
828 1804
829 irq_event = irq_of_parse_and_map(np, 0); 1805 irq_event = irq_of_parse_and_map(np, 0);
830 if (!irq_event) { 1806 if (!irq_event) {
@@ -871,8 +1847,11 @@ static int stm32f7_i2c_probe(struct platform_device *pdev)
871 1847
872 i2c_dev->dev = &pdev->dev; 1848 i2c_dev->dev = &pdev->dev;
873 1849
874 ret = devm_request_irq(&pdev->dev, irq_event, stm32f7_i2c_isr_event, 0, 1850 ret = devm_request_threaded_irq(&pdev->dev, irq_event,
875 pdev->name, i2c_dev); 1851 stm32f7_i2c_isr_event,
1852 stm32f7_i2c_isr_event_thread,
1853 IRQF_ONESHOT,
1854 pdev->name, i2c_dev);
876 if (ret) { 1855 if (ret) {
877 dev_err(&pdev->dev, "Failed to request irq event %i\n", 1856 dev_err(&pdev->dev, "Failed to request irq event %i\n",
878 irq_event); 1857 irq_event);
@@ -924,6 +1903,11 @@ static int stm32f7_i2c_probe(struct platform_device *pdev)
924 1903
925 init_completion(&i2c_dev->complete); 1904 init_completion(&i2c_dev->complete);
926 1905
1906 /* Init DMA config if supported */
1907 i2c_dev->dma = stm32_i2c_dma_request(i2c_dev->dev, phy_addr,
1908 STM32F7_I2C_TXDR,
1909 STM32F7_I2C_RXDR);
1910
927 ret = i2c_add_adapter(adap); 1911 ret = i2c_add_adapter(adap);
928 if (ret) 1912 if (ret)
929 goto clk_free; 1913 goto clk_free;
@@ -946,6 +1930,11 @@ static int stm32f7_i2c_remove(struct platform_device *pdev)
946{ 1930{
947 struct stm32f7_i2c_dev *i2c_dev = platform_get_drvdata(pdev); 1931 struct stm32f7_i2c_dev *i2c_dev = platform_get_drvdata(pdev);
948 1932
1933 if (i2c_dev->dma) {
1934 stm32_i2c_dma_free(i2c_dev->dma);
1935 i2c_dev->dma = NULL;
1936 }
1937
949 i2c_del_adapter(&i2c_dev->adap); 1938 i2c_del_adapter(&i2c_dev->adap);
950 1939
951 clk_unprepare(i2c_dev->clk); 1940 clk_unprepare(i2c_dev->clk);
diff --git a/drivers/i2c/busses/i2c-stu300.c b/drivers/i2c/busses/i2c-stu300.c
index dc63236b45b2..e866c481bfc3 100644
--- a/drivers/i2c/busses/i2c-stu300.c
+++ b/drivers/i2c/busses/i2c-stu300.c
@@ -602,20 +602,24 @@ static int stu300_send_address(struct stu300_dev *dev,
602 u32 val; 602 u32 val;
603 int ret; 603 int ret;
604 604
605 if (msg->flags & I2C_M_TEN) 605 if (msg->flags & I2C_M_TEN) {
606 /* This is probably how 10 bit addresses look */ 606 /* This is probably how 10 bit addresses look */
607 val = (0xf0 | (((u32) msg->addr & 0x300) >> 7)) & 607 val = (0xf0 | (((u32) msg->addr & 0x300) >> 7)) &
608 I2C_DR_D_MASK; 608 I2C_DR_D_MASK;
609 else 609 if (msg->flags & I2C_M_RD)
610 val = ((msg->addr << 1) & I2C_DR_D_MASK); 610 /* This is the direction bit */
611 val |= 0x01;
612 } else {
613 val = i2c_8bit_addr_from_msg(msg);
614 }
611 615
612 if (msg->flags & I2C_M_RD) { 616 if (resend) {
613 /* This is the direction bit */ 617 if (msg->flags & I2C_M_RD)
614 val |= 0x01;
615 if (resend)
616 dev_dbg(&dev->pdev->dev, "read resend\n"); 618 dev_dbg(&dev->pdev->dev, "read resend\n");
617 } else if (resend) 619 else
618 dev_dbg(&dev->pdev->dev, "write resend\n"); 620 dev_dbg(&dev->pdev->dev, "write resend\n");
621 }
622
619 stu300_wr8(val, dev->virtbase + I2C_DR); 623 stu300_wr8(val, dev->virtbase + I2C_DR);
620 624
621 /* For 10bit addressing, await 10bit request (EVENT 9) */ 625 /* For 10bit addressing, await 10bit request (EVENT 9) */
diff --git a/drivers/i2c/busses/i2c-synquacer.c b/drivers/i2c/busses/i2c-synquacer.c
index a021f866d8c2..915f5edbab33 100644
--- a/drivers/i2c/busses/i2c-synquacer.c
+++ b/drivers/i2c/busses/i2c-synquacer.c
@@ -509,7 +509,7 @@ static int synquacer_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
509 509
510 dev_dbg(i2c->dev, "calculated timeout %d ms\n", i2c->timeout_ms); 510 dev_dbg(i2c->dev, "calculated timeout %d ms\n", i2c->timeout_ms);
511 511
512 for (retry = 0; retry < adap->retries; retry++) { 512 for (retry = 0; retry <= adap->retries; retry++) {
513 ret = synquacer_i2c_doxfer(i2c, msgs, num); 513 ret = synquacer_i2c_doxfer(i2c, msgs, num);
514 if (ret != -EAGAIN) 514 if (ret != -EAGAIN)
515 return ret; 515 return ret;
diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c
index 60292d243e24..5fccd1f1bca8 100644
--- a/drivers/i2c/busses/i2c-tegra.c
+++ b/drivers/i2c/busses/i2c-tegra.c
@@ -173,7 +173,6 @@ struct tegra_i2c_hw_feature {
173 * @msg_buf_remaining: size of unsent data in the message buffer 173 * @msg_buf_remaining: size of unsent data in the message buffer
174 * @msg_read: identifies read transfers 174 * @msg_read: identifies read transfers
175 * @bus_clk_rate: current i2c bus clock rate 175 * @bus_clk_rate: current i2c bus clock rate
176 * @is_suspended: prevents i2c controller accesses after suspend is called
177 */ 176 */
178struct tegra_i2c_dev { 177struct tegra_i2c_dev {
179 struct device *dev; 178 struct device *dev;
@@ -194,7 +193,6 @@ struct tegra_i2c_dev {
194 int msg_read; 193 int msg_read;
195 u32 bus_clk_rate; 194 u32 bus_clk_rate;
196 u16 clk_divisor_non_hs_mode; 195 u16 clk_divisor_non_hs_mode;
197 bool is_suspended;
198 bool is_multimaster_mode; 196 bool is_multimaster_mode;
199 spinlock_t xfer_lock; 197 spinlock_t xfer_lock;
200}; 198};
@@ -734,9 +732,6 @@ static int tegra_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[],
734 int i; 732 int i;
735 int ret = 0; 733 int ret = 0;
736 734
737 if (i2c_dev->is_suspended)
738 return -EBUSY;
739
740 ret = pm_runtime_get_sync(i2c_dev->dev); 735 ret = pm_runtime_get_sync(i2c_dev->dev);
741 if (ret < 0) { 736 if (ret < 0) {
742 dev_err(i2c_dev->dev, "runtime resume failed %d\n", ret); 737 dev_err(i2c_dev->dev, "runtime resume failed %d\n", ret);
@@ -1051,37 +1046,9 @@ static int tegra_i2c_remove(struct platform_device *pdev)
1051} 1046}
1052 1047
1053#ifdef CONFIG_PM_SLEEP 1048#ifdef CONFIG_PM_SLEEP
1054static int tegra_i2c_suspend(struct device *dev)
1055{
1056 struct tegra_i2c_dev *i2c_dev = dev_get_drvdata(dev);
1057
1058 i2c_lock_adapter(&i2c_dev->adapter);
1059 i2c_dev->is_suspended = true;
1060 i2c_unlock_adapter(&i2c_dev->adapter);
1061
1062 return 0;
1063}
1064
1065static int tegra_i2c_resume(struct device *dev)
1066{
1067 struct tegra_i2c_dev *i2c_dev = dev_get_drvdata(dev);
1068 int ret;
1069
1070 i2c_lock_adapter(&i2c_dev->adapter);
1071
1072 ret = tegra_i2c_init(i2c_dev);
1073 if (!ret)
1074 i2c_dev->is_suspended = false;
1075
1076 i2c_unlock_adapter(&i2c_dev->adapter);
1077
1078 return ret;
1079}
1080
1081static const struct dev_pm_ops tegra_i2c_pm = { 1049static const struct dev_pm_ops tegra_i2c_pm = {
1082 SET_RUNTIME_PM_OPS(tegra_i2c_runtime_suspend, tegra_i2c_runtime_resume, 1050 SET_RUNTIME_PM_OPS(tegra_i2c_runtime_suspend, tegra_i2c_runtime_resume,
1083 NULL) 1051 NULL)
1084 SET_SYSTEM_SLEEP_PM_OPS(tegra_i2c_suspend, tegra_i2c_resume)
1085}; 1052};
1086#define TEGRA_I2C_PM (&tegra_i2c_pm) 1053#define TEGRA_I2C_PM (&tegra_i2c_pm)
1087#else 1054#else
diff --git a/drivers/i2c/busses/i2c-xiic.c b/drivers/i2c/busses/i2c-xiic.c
index c80527816ad0..9a71e50d21f1 100644
--- a/drivers/i2c/busses/i2c-xiic.c
+++ b/drivers/i2c/busses/i2c-xiic.c
@@ -33,7 +33,7 @@
33#include <linux/i2c.h> 33#include <linux/i2c.h>
34#include <linux/interrupt.h> 34#include <linux/interrupt.h>
35#include <linux/wait.h> 35#include <linux/wait.h>
36#include <linux/i2c-xiic.h> 36#include <linux/platform_data/i2c-xiic.h>
37#include <linux/io.h> 37#include <linux/io.h>
38#include <linux/slab.h> 38#include <linux/slab.h>
39#include <linux/of.h> 39#include <linux/of.h>
@@ -143,12 +143,6 @@ struct xiic_i2c {
143 143
144#define XIIC_TX_RX_INTERRUPTS (XIIC_INTR_RX_FULL_MASK | XIIC_TX_INTERRUPTS) 144#define XIIC_TX_RX_INTERRUPTS (XIIC_INTR_RX_FULL_MASK | XIIC_TX_INTERRUPTS)
145 145
146/* The following constants are used with the following macros to specify the
147 * operation, a read or write operation.
148 */
149#define XIIC_READ_OPERATION 1
150#define XIIC_WRITE_OPERATION 0
151
152/* 146/*
153 * Tx Fifo upper bit masks. 147 * Tx Fifo upper bit masks.
154 */ 148 */
@@ -415,7 +409,7 @@ static irqreturn_t xiic_process(int irq, void *dev_id)
415 clr |= XIIC_INTR_RX_FULL_MASK; 409 clr |= XIIC_INTR_RX_FULL_MASK;
416 if (!i2c->rx_msg) { 410 if (!i2c->rx_msg) {
417 dev_dbg(i2c->adap.dev.parent, 411 dev_dbg(i2c->adap.dev.parent,
418 "%s unexpexted RX IRQ\n", __func__); 412 "%s unexpected RX IRQ\n", __func__);
419 xiic_clear_rx_fifo(i2c); 413 xiic_clear_rx_fifo(i2c);
420 goto out; 414 goto out;
421 } 415 }
@@ -470,7 +464,7 @@ static irqreturn_t xiic_process(int irq, void *dev_id)
470 464
471 if (!i2c->tx_msg) { 465 if (!i2c->tx_msg) {
472 dev_dbg(i2c->adap.dev.parent, 466 dev_dbg(i2c->adap.dev.parent,
473 "%s unexpexted TX IRQ\n", __func__); 467 "%s unexpected TX IRQ\n", __func__);
474 goto out; 468 goto out;
475 } 469 }
476 470
@@ -556,8 +550,7 @@ static void xiic_start_recv(struct xiic_i2c *i2c)
556 if (!(msg->flags & I2C_M_NOSTART)) 550 if (!(msg->flags & I2C_M_NOSTART))
557 /* write the address */ 551 /* write the address */
558 xiic_setreg16(i2c, XIIC_DTR_REG_OFFSET, 552 xiic_setreg16(i2c, XIIC_DTR_REG_OFFSET,
559 (msg->addr << 1) | XIIC_READ_OPERATION | 553 i2c_8bit_addr_from_msg(msg) | XIIC_TX_DYN_START_MASK);
560 XIIC_TX_DYN_START_MASK);
561 554
562 xiic_irq_clr_en(i2c, XIIC_INTR_BNB_MASK); 555 xiic_irq_clr_en(i2c, XIIC_INTR_BNB_MASK);
563 556
@@ -585,7 +578,7 @@ static void xiic_start_send(struct xiic_i2c *i2c)
585 578
586 if (!(msg->flags & I2C_M_NOSTART)) { 579 if (!(msg->flags & I2C_M_NOSTART)) {
587 /* write the address */ 580 /* write the address */
588 u16 data = ((msg->addr << 1) & 0xfe) | XIIC_WRITE_OPERATION | 581 u16 data = i2c_8bit_addr_from_msg(msg) |
589 XIIC_TX_DYN_START_MASK; 582 XIIC_TX_DYN_START_MASK;
590 if ((i2c->nmsgs == 1) && msg->len == 0) 583 if ((i2c->nmsgs == 1) && msg->len == 0)
591 /* no data and last message -> add STOP */ 584 /* no data and last message -> add STOP */
diff --git a/drivers/i2c/busses/i2c-xlp9xx.c b/drivers/i2c/busses/i2c-xlp9xx.c
index eb8913eba0c5..1f41a4f89c08 100644
--- a/drivers/i2c/busses/i2c-xlp9xx.c
+++ b/drivers/i2c/busses/i2c-xlp9xx.c
@@ -10,6 +10,7 @@
10#include <linux/clk.h> 10#include <linux/clk.h>
11#include <linux/completion.h> 11#include <linux/completion.h>
12#include <linux/i2c.h> 12#include <linux/i2c.h>
13#include <linux/i2c-smbus.h>
13#include <linux/init.h> 14#include <linux/init.h>
14#include <linux/interrupt.h> 15#include <linux/interrupt.h>
15#include <linux/io.h> 16#include <linux/io.h>
@@ -84,6 +85,8 @@ struct xlp9xx_i2c_dev {
84 struct device *dev; 85 struct device *dev;
85 struct i2c_adapter adapter; 86 struct i2c_adapter adapter;
86 struct completion msg_complete; 87 struct completion msg_complete;
88 struct i2c_smbus_alert_setup alert_data;
89 struct i2c_client *ara;
87 int irq; 90 int irq;
88 bool msg_read; 91 bool msg_read;
89 bool len_recv; 92 bool len_recv;
@@ -155,9 +158,30 @@ static void xlp9xx_i2c_fill_tx_fifo(struct xlp9xx_i2c_dev *priv)
155 priv->msg_buf += len; 158 priv->msg_buf += len;
156} 159}
157 160
161static void xlp9xx_i2c_update_rlen(struct xlp9xx_i2c_dev *priv)
162{
163 u32 val, len;
164
165 /*
166 * Update receive length. Re-read len to get the latest value,
167 * and then add 4 to have a minimum value that can be safely
168 * written. This is to account for the byte read above, the
169 * transfer in progress and any delays in the register I/O
170 */
171 val = xlp9xx_read_i2c_reg(priv, XLP9XX_I2C_CTRL);
172 len = xlp9xx_read_i2c_reg(priv, XLP9XX_I2C_FIFOWCNT) &
173 XLP9XX_I2C_FIFO_WCNT_MASK;
174 len = max_t(u32, priv->msg_len, len + 4);
175 if (len >= I2C_SMBUS_BLOCK_MAX + 2)
176 return;
177 val = (val & ~XLP9XX_I2C_CTRL_MCTLEN_MASK) |
178 (len << XLP9XX_I2C_CTRL_MCTLEN_SHIFT);
179 xlp9xx_write_i2c_reg(priv, XLP9XX_I2C_CTRL, val);
180}
181
158static void xlp9xx_i2c_drain_rx_fifo(struct xlp9xx_i2c_dev *priv) 182static void xlp9xx_i2c_drain_rx_fifo(struct xlp9xx_i2c_dev *priv)
159{ 183{
160 u32 len, i, val; 184 u32 len, i;
161 u8 rlen, *buf = priv->msg_buf; 185 u8 rlen, *buf = priv->msg_buf;
162 186
163 len = xlp9xx_read_i2c_reg(priv, XLP9XX_I2C_FIFOWCNT) & 187 len = xlp9xx_read_i2c_reg(priv, XLP9XX_I2C_FIFOWCNT) &
@@ -167,21 +191,20 @@ static void xlp9xx_i2c_drain_rx_fifo(struct xlp9xx_i2c_dev *priv)
167 if (priv->len_recv) { 191 if (priv->len_recv) {
168 /* read length byte */ 192 /* read length byte */
169 rlen = xlp9xx_read_i2c_reg(priv, XLP9XX_I2C_MRXFIFO); 193 rlen = xlp9xx_read_i2c_reg(priv, XLP9XX_I2C_MRXFIFO);
170 *buf++ = rlen; 194 if (rlen > I2C_SMBUS_BLOCK_MAX || rlen == 0) {
171 len--; 195 rlen = 0; /*abort transfer */
172 196 priv->msg_buf_remaining = 0;
173 if (priv->client_pec) 197 priv->msg_len = 0;
174 ++rlen; 198 } else {
175 /* update remaining bytes and message length */ 199 *buf++ = rlen;
176 priv->msg_buf_remaining = rlen; 200 if (priv->client_pec)
177 priv->msg_len = rlen + 1; 201 ++rlen; /* account for error check byte */
202 /* update remaining bytes and message length */
203 priv->msg_buf_remaining = rlen;
204 priv->msg_len = rlen + 1;
205 }
206 xlp9xx_i2c_update_rlen(priv);
178 priv->len_recv = false; 207 priv->len_recv = false;
179
180 /* Update transfer length to read only actual data */
181 val = xlp9xx_read_i2c_reg(priv, XLP9XX_I2C_CTRL);
182 val = (val & ~XLP9XX_I2C_CTRL_MCTLEN_MASK) |
183 ((rlen + 1) << XLP9XX_I2C_CTRL_MCTLEN_SHIFT);
184 xlp9xx_write_i2c_reg(priv, XLP9XX_I2C_CTRL, val);
185 } else { 208 } else {
186 len = min(priv->msg_buf_remaining, len); 209 len = min(priv->msg_buf_remaining, len);
187 for (i = 0; i < len; i++, buf++) 210 for (i = 0; i < len; i++, buf++)
@@ -300,10 +323,6 @@ static int xlp9xx_i2c_xfer_msg(struct xlp9xx_i2c_dev *priv, struct i2c_msg *msg,
300 xlp9xx_write_i2c_reg(priv, XLP9XX_I2C_MFIFOCTRL, 323 xlp9xx_write_i2c_reg(priv, XLP9XX_I2C_MFIFOCTRL,
301 XLP9XX_I2C_MFIFOCTRL_RST); 324 XLP9XX_I2C_MFIFOCTRL_RST);
302 325
303 /* set FIFO threshold if reading */
304 if (priv->msg_read)
305 xlp9xx_i2c_update_rx_fifo_thres(priv);
306
307 /* set slave addr */ 326 /* set slave addr */
308 xlp9xx_write_i2c_reg(priv, XLP9XX_I2C_SLAVEADDR, 327 xlp9xx_write_i2c_reg(priv, XLP9XX_I2C_SLAVEADDR,
309 (msg->addr << XLP9XX_I2C_SLAVEADDR_ADDR_SHIFT) | 328 (msg->addr << XLP9XX_I2C_SLAVEADDR_ADDR_SHIFT) |
@@ -322,9 +341,13 @@ static int xlp9xx_i2c_xfer_msg(struct xlp9xx_i2c_dev *priv, struct i2c_msg *msg,
322 val &= ~XLP9XX_I2C_CTRL_ADDMODE; 341 val &= ~XLP9XX_I2C_CTRL_ADDMODE;
323 342
324 priv->len_recv = msg->flags & I2C_M_RECV_LEN; 343 priv->len_recv = msg->flags & I2C_M_RECV_LEN;
325 len = priv->len_recv ? XLP9XX_I2C_FIFO_SIZE : msg->len; 344 len = priv->len_recv ? I2C_SMBUS_BLOCK_MAX + 2 : msg->len;
326 priv->client_pec = msg->flags & I2C_CLIENT_PEC; 345 priv->client_pec = msg->flags & I2C_CLIENT_PEC;
327 346
347 /* set FIFO threshold if reading */
348 if (priv->msg_read)
349 xlp9xx_i2c_update_rx_fifo_thres(priv);
350
328 /* set data length to be transferred */ 351 /* set data length to be transferred */
329 val = (val & ~XLP9XX_I2C_CTRL_MCTLEN_MASK) | 352 val = (val & ~XLP9XX_I2C_CTRL_MCTLEN_MASK) |
330 (len << XLP9XX_I2C_CTRL_MCTLEN_SHIFT); 353 (len << XLP9XX_I2C_CTRL_MCTLEN_SHIFT);
@@ -378,8 +401,11 @@ static int xlp9xx_i2c_xfer_msg(struct xlp9xx_i2c_dev *priv, struct i2c_msg *msg,
378 } 401 }
379 402
380 /* update msg->len with actual received length */ 403 /* update msg->len with actual received length */
381 if (msg->flags & I2C_M_RECV_LEN) 404 if (msg->flags & I2C_M_RECV_LEN) {
405 if (!priv->msg_len)
406 return -EPROTO;
382 msg->len = priv->msg_len; 407 msg->len = priv->msg_len;
408 }
383 return 0; 409 return 0;
384} 410}
385 411
@@ -447,6 +473,19 @@ static int xlp9xx_i2c_get_frequency(struct platform_device *pdev,
447 return 0; 473 return 0;
448} 474}
449 475
476static int xlp9xx_i2c_smbus_setup(struct xlp9xx_i2c_dev *priv,
477 struct platform_device *pdev)
478{
479 if (!priv->alert_data.irq)
480 return -EINVAL;
481
482 priv->ara = i2c_setup_smbus_alert(&priv->adapter, &priv->alert_data);
483 if (!priv->ara)
484 return -ENODEV;
485
486 return 0;
487}
488
450static int xlp9xx_i2c_probe(struct platform_device *pdev) 489static int xlp9xx_i2c_probe(struct platform_device *pdev)
451{ 490{
452 struct xlp9xx_i2c_dev *priv; 491 struct xlp9xx_i2c_dev *priv;
@@ -467,6 +506,10 @@ static int xlp9xx_i2c_probe(struct platform_device *pdev)
467 dev_err(&pdev->dev, "invalid irq!\n"); 506 dev_err(&pdev->dev, "invalid irq!\n");
468 return priv->irq; 507 return priv->irq;
469 } 508 }
509 /* SMBAlert irq */
510 priv->alert_data.irq = platform_get_irq(pdev, 1);
511 if (priv->alert_data.irq <= 0)
512 priv->alert_data.irq = 0;
470 513
471 xlp9xx_i2c_get_frequency(pdev, priv); 514 xlp9xx_i2c_get_frequency(pdev, priv);
472 xlp9xx_i2c_init(priv); 515 xlp9xx_i2c_init(priv);
@@ -493,6 +536,10 @@ static int xlp9xx_i2c_probe(struct platform_device *pdev)
493 if (err) 536 if (err)
494 return err; 537 return err;
495 538
539 err = xlp9xx_i2c_smbus_setup(priv, pdev);
540 if (err)
541 dev_dbg(&pdev->dev, "No active SMBus alert %d\n", err);
542
496 platform_set_drvdata(pdev, priv); 543 platform_set_drvdata(pdev, priv);
497 dev_dbg(&pdev->dev, "I2C bus:%d added\n", priv->adapter.nr); 544 dev_dbg(&pdev->dev, "I2C bus:%d added\n", priv->adapter.nr);
498 545
diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index a17f46a95f73..31d16ada6e7d 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -717,10 +717,6 @@ i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info)
717 client->adapter = adap; 717 client->adapter = adap;
718 718
719 client->dev.platform_data = info->platform_data; 719 client->dev.platform_data = info->platform_data;
720
721 if (info->archdata)
722 client->dev.archdata = *info->archdata;
723
724 client->flags = info->flags; 720 client->flags = info->flags;
725 client->addr = info->addr; 721 client->addr = info->addr;
726 722
@@ -746,7 +742,7 @@ i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info)
746 client->dev.parent = &client->adapter->dev; 742 client->dev.parent = &client->adapter->dev;
747 client->dev.bus = &i2c_bus_type; 743 client->dev.bus = &i2c_bus_type;
748 client->dev.type = &i2c_client_type; 744 client->dev.type = &i2c_client_type;
749 client->dev.of_node = info->of_node; 745 client->dev.of_node = of_node_get(info->of_node);
750 client->dev.fwnode = info->fwnode; 746 client->dev.fwnode = info->fwnode;
751 747
752 i2c_dev_set_name(adap, client, info); 748 i2c_dev_set_name(adap, client, info);
@@ -757,7 +753,7 @@ i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info)
757 dev_err(&adap->dev, 753 dev_err(&adap->dev,
758 "Failed to add properties to client %s: %d\n", 754 "Failed to add properties to client %s: %d\n",
759 client->name, status); 755 client->name, status);
760 goto out_err; 756 goto out_err_put_of_node;
761 } 757 }
762 } 758 }
763 759
@@ -773,6 +769,8 @@ i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info)
773out_free_props: 769out_free_props:
774 if (info->properties) 770 if (info->properties)
775 device_remove_properties(&client->dev); 771 device_remove_properties(&client->dev);
772out_err_put_of_node:
773 of_node_put(info->of_node);
776out_err: 774out_err:
777 dev_err(&adap->dev, 775 dev_err(&adap->dev,
778 "Failed to register i2c client %s at 0x%02x (%d)\n", 776 "Failed to register i2c client %s at 0x%02x (%d)\n",
diff --git a/drivers/i2c/i2c-core-of.c b/drivers/i2c/i2c-core-of.c
index c405270a98b4..6cb7ad608bcd 100644
--- a/drivers/i2c/i2c-core-of.c
+++ b/drivers/i2c/i2c-core-of.c
@@ -22,53 +22,64 @@
22 22
23#include "i2c-core.h" 23#include "i2c-core.h"
24 24
25static struct i2c_client *of_i2c_register_device(struct i2c_adapter *adap, 25int of_i2c_get_board_info(struct device *dev, struct device_node *node,
26 struct device_node *node) 26 struct i2c_board_info *info)
27{ 27{
28 struct i2c_client *client;
29 struct i2c_board_info info = {};
30 struct dev_archdata dev_ad = {};
31 u32 addr; 28 u32 addr;
32 int ret; 29 int ret;
33 30
34 dev_dbg(&adap->dev, "of_i2c: register %pOF\n", node); 31 memset(info, 0, sizeof(*info));
35 32
36 if (of_modalias_node(node, info.type, sizeof(info.type)) < 0) { 33 if (of_modalias_node(node, info->type, sizeof(info->type)) < 0) {
37 dev_err(&adap->dev, "of_i2c: modalias failure on %pOF\n", 34 dev_err(dev, "of_i2c: modalias failure on %pOF\n", node);
38 node); 35 return -EINVAL;
39 return ERR_PTR(-EINVAL);
40 } 36 }
41 37
42 ret = of_property_read_u32(node, "reg", &addr); 38 ret = of_property_read_u32(node, "reg", &addr);
43 if (ret) { 39 if (ret) {
44 dev_err(&adap->dev, "of_i2c: invalid reg on %pOF\n", node); 40 dev_err(dev, "of_i2c: invalid reg on %pOF\n", node);
45 return ERR_PTR(ret); 41 return ret;
46 } 42 }
47 43
48 if (addr & I2C_TEN_BIT_ADDRESS) { 44 if (addr & I2C_TEN_BIT_ADDRESS) {
49 addr &= ~I2C_TEN_BIT_ADDRESS; 45 addr &= ~I2C_TEN_BIT_ADDRESS;
50 info.flags |= I2C_CLIENT_TEN; 46 info->flags |= I2C_CLIENT_TEN;
51 } 47 }
52 48
53 if (addr & I2C_OWN_SLAVE_ADDRESS) { 49 if (addr & I2C_OWN_SLAVE_ADDRESS) {
54 addr &= ~I2C_OWN_SLAVE_ADDRESS; 50 addr &= ~I2C_OWN_SLAVE_ADDRESS;
55 info.flags |= I2C_CLIENT_SLAVE; 51 info->flags |= I2C_CLIENT_SLAVE;
56 } 52 }
57 53
58 info.addr = addr; 54 info->addr = addr;
59 info.archdata = &dev_ad; 55 info->of_node = node;
60 info.of_node = of_node_get(node);
61 56
62 if (of_property_read_bool(node, "host-notify")) 57 if (of_property_read_bool(node, "host-notify"))
63 info.flags |= I2C_CLIENT_HOST_NOTIFY; 58 info->flags |= I2C_CLIENT_HOST_NOTIFY;
64 59
65 if (of_get_property(node, "wakeup-source", NULL)) 60 if (of_get_property(node, "wakeup-source", NULL))
66 info.flags |= I2C_CLIENT_WAKE; 61 info->flags |= I2C_CLIENT_WAKE;
62
63 return 0;
64}
65EXPORT_SYMBOL_GPL(of_i2c_get_board_info);
66
67static struct i2c_client *of_i2c_register_device(struct i2c_adapter *adap,
68 struct device_node *node)
69{
70 struct i2c_client *client;
71 struct i2c_board_info info;
72 int ret;
73
74 dev_dbg(&adap->dev, "of_i2c: register %pOF\n", node);
75
76 ret = of_i2c_get_board_info(&adap->dev, node, &info);
77 if (ret)
78 return ERR_PTR(ret);
67 79
68 client = i2c_new_device(adap, &info); 80 client = i2c_new_device(adap, &info);
69 if (!client) { 81 if (!client) {
70 dev_err(&adap->dev, "of_i2c: Failure registering %pOF\n", node); 82 dev_err(&adap->dev, "of_i2c: Failure registering %pOF\n", node);
71 of_node_put(node);
72 return ERR_PTR(-EINVAL); 83 return ERR_PTR(-EINVAL);
73 } 84 }
74 return client; 85 return client;
diff --git a/drivers/i2c/i2c-core-smbus.c b/drivers/i2c/i2c-core-smbus.c
index b5aec33002c3..f3f683041e7f 100644
--- a/drivers/i2c/i2c-core-smbus.c
+++ b/drivers/i2c/i2c-core-smbus.c
@@ -466,6 +466,8 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr,
466 status = i2c_transfer(adapter, msg, num); 466 status = i2c_transfer(adapter, msg, num);
467 if (status < 0) 467 if (status < 0)
468 return status; 468 return status;
469 if (status != num)
470 return -EIO;
469 471
470 /* Check PEC if last message is a read */ 472 /* Check PEC if last message is a read */
471 if (i && (msg[num-1].flags & I2C_M_RD)) { 473 if (i && (msg[num-1].flags & I2C_M_RD)) {
diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
index 9669ca4937b8..300ab4b672e4 100644
--- a/drivers/i2c/i2c-mux.c
+++ b/drivers/i2c/i2c-mux.c
@@ -418,7 +418,7 @@ int i2c_mux_add_adapter(struct i2c_mux_core *muxc,
418 snprintf(symlink_name, sizeof(symlink_name), "channel-%u", chan_id); 418 snprintf(symlink_name, sizeof(symlink_name), "channel-%u", chan_id);
419 WARN(sysfs_create_link(&muxc->dev->kobj, &priv->adap.dev.kobj, 419 WARN(sysfs_create_link(&muxc->dev->kobj, &priv->adap.dev.kobj,
420 symlink_name), 420 symlink_name),
421 "can't create symlink for channel %u\n", chan_id); 421 "can't create symlink to channel %u\n", chan_id);
422 dev_info(&parent->dev, "Added multiplexed i2c bus %d\n", 422 dev_info(&parent->dev, "Added multiplexed i2c bus %d\n",
423 i2c_adapter_id(&priv->adap)); 423 i2c_adapter_id(&priv->adap));
424 424
diff --git a/drivers/i2c/muxes/i2c-demux-pinctrl.c b/drivers/i2c/muxes/i2c-demux-pinctrl.c
index 33ce032cb701..035032e20327 100644
--- a/drivers/i2c/muxes/i2c-demux-pinctrl.c
+++ b/drivers/i2c/muxes/i2c-demux-pinctrl.c
@@ -18,6 +18,7 @@
18#include <linux/of.h> 18#include <linux/of.h>
19#include <linux/pinctrl/consumer.h> 19#include <linux/pinctrl/consumer.h>
20#include <linux/platform_device.h> 20#include <linux/platform_device.h>
21#include <linux/pm_runtime.h>
21#include <linux/slab.h> 22#include <linux/slab.h>
22#include <linux/sysfs.h> 23#include <linux/sysfs.h>
23 24
@@ -105,7 +106,7 @@ static int i2c_demux_activate_master(struct i2c_demux_pinctrl_priv *priv, u32 ne
105 priv->cur_adap.owner = THIS_MODULE; 106 priv->cur_adap.owner = THIS_MODULE;
106 priv->cur_adap.algo = &priv->algo; 107 priv->cur_adap.algo = &priv->algo;
107 priv->cur_adap.algo_data = priv; 108 priv->cur_adap.algo_data = priv;
108 priv->cur_adap.dev.parent = priv->dev; 109 priv->cur_adap.dev.parent = &adap->dev;
109 priv->cur_adap.class = adap->class; 110 priv->cur_adap.class = adap->class;
110 priv->cur_adap.retries = adap->retries; 111 priv->cur_adap.retries = adap->retries;
111 priv->cur_adap.timeout = adap->timeout; 112 priv->cur_adap.timeout = adap->timeout;
@@ -254,6 +255,8 @@ static int i2c_demux_pinctrl_probe(struct platform_device *pdev)
254 255
255 platform_set_drvdata(pdev, priv); 256 platform_set_drvdata(pdev, priv);
256 257
258 pm_runtime_no_callbacks(&pdev->dev);
259
257 /* switch to first parent as active master */ 260 /* switch to first parent as active master */
258 i2c_demux_activate_master(priv, 0); 261 i2c_demux_activate_master(priv, 0);
259 262
diff --git a/drivers/i2c/muxes/i2c-mux-gpio.c b/drivers/i2c/muxes/i2c-mux-gpio.c
index ddc4bd4ca13b..401308e3d036 100644
--- a/drivers/i2c/muxes/i2c-mux-gpio.c
+++ b/drivers/i2c/muxes/i2c-mux-gpio.c
@@ -10,7 +10,7 @@
10 10
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/i2c-mux-gpio.h> 13#include <linux/platform_data/i2c-mux-gpio.h>
14#include <linux/platform_device.h> 14#include <linux/platform_device.h>
15#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/slab.h> 16#include <linux/slab.h>
diff --git a/drivers/i2c/muxes/i2c-mux-ltc4306.c b/drivers/i2c/muxes/i2c-mux-ltc4306.c
index 311b1cced0c0..a9af93259b19 100644
--- a/drivers/i2c/muxes/i2c-mux-ltc4306.c
+++ b/drivers/i2c/muxes/i2c-mux-ltc4306.c
@@ -206,8 +206,7 @@ static const struct of_device_id ltc4306_of_match[] = {
206}; 206};
207MODULE_DEVICE_TABLE(of, ltc4306_of_match); 207MODULE_DEVICE_TABLE(of, ltc4306_of_match);
208 208
209static int ltc4306_probe(struct i2c_client *client, 209static int ltc4306_probe(struct i2c_client *client)
210 const struct i2c_device_id *id)
211{ 210{
212 struct i2c_adapter *adap = to_i2c_adapter(client->dev.parent); 211 struct i2c_adapter *adap = to_i2c_adapter(client->dev.parent);
213 const struct chip_desc *chip; 212 const struct chip_desc *chip;
@@ -221,7 +220,7 @@ static int ltc4306_probe(struct i2c_client *client,
221 chip = of_device_get_match_data(&client->dev); 220 chip = of_device_get_match_data(&client->dev);
222 221
223 if (!chip) 222 if (!chip)
224 chip = &chips[id->driver_data]; 223 chip = &chips[i2c_match_id(ltc4306_id, client)->driver_data];
225 224
226 idle_disc = device_property_read_bool(&client->dev, 225 idle_disc = device_property_read_bool(&client->dev,
227 "i2c-mux-idle-disconnect"); 226 "i2c-mux-idle-disconnect");
@@ -310,7 +309,7 @@ static struct i2c_driver ltc4306_driver = {
310 .name = "ltc4306", 309 .name = "ltc4306",
311 .of_match_table = of_match_ptr(ltc4306_of_match), 310 .of_match_table = of_match_ptr(ltc4306_of_match),
312 }, 311 },
313 .probe = ltc4306_probe, 312 .probe_new = ltc4306_probe,
314 .remove = ltc4306_remove, 313 .remove = ltc4306_remove,
315 .id_table = ltc4306_id, 314 .id_table = ltc4306_id,
316}; 315};
diff --git a/drivers/i2c/muxes/i2c-mux-pca954x.c b/drivers/i2c/muxes/i2c-mux-pca954x.c
index 09bafd3e68fa..fbc748027087 100644
--- a/drivers/i2c/muxes/i2c-mux-pca954x.c
+++ b/drivers/i2c/muxes/i2c-mux-pca954x.c
@@ -36,6 +36,7 @@
36 */ 36 */
37 37
38#include <linux/device.h> 38#include <linux/device.h>
39#include <linux/delay.h>
39#include <linux/gpio/consumer.h> 40#include <linux/gpio/consumer.h>
40#include <linux/i2c.h> 41#include <linux/i2c.h>
41#include <linux/i2c-mux.h> 42#include <linux/i2c-mux.h>
@@ -373,7 +374,6 @@ static int pca954x_probe(struct i2c_client *client,
373 int num, force, class; 374 int num, force, class;
374 struct i2c_mux_core *muxc; 375 struct i2c_mux_core *muxc;
375 struct pca954x *data; 376 struct pca954x *data;
376 const struct of_device_id *match;
377 int ret; 377 int ret;
378 378
379 if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_BYTE)) 379 if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_BYTE))
@@ -389,15 +389,19 @@ static int pca954x_probe(struct i2c_client *client,
389 i2c_set_clientdata(client, muxc); 389 i2c_set_clientdata(client, muxc);
390 data->client = client; 390 data->client = client;
391 391
392 /* Get the mux out of reset if a reset GPIO is specified. */ 392 /* Reset the mux if a reset GPIO is specified. */
393 gpio = devm_gpiod_get_optional(&client->dev, "reset", GPIOD_OUT_LOW); 393 gpio = devm_gpiod_get_optional(&client->dev, "reset", GPIOD_OUT_HIGH);
394 if (IS_ERR(gpio)) 394 if (IS_ERR(gpio))
395 return PTR_ERR(gpio); 395 return PTR_ERR(gpio);
396 if (gpio) {
397 udelay(1);
398 gpiod_set_value_cansleep(gpio, 0);
399 /* Give the chip some time to recover. */
400 udelay(1);
401 }
396 402
397 match = of_match_device(of_match_ptr(pca954x_of_match), &client->dev); 403 data->chip = of_device_get_match_data(&client->dev);
398 if (match) 404 if (!data->chip)
399 data->chip = of_device_get_match_data(&client->dev);
400 else
401 data->chip = &chips[id->driver_data]; 405 data->chip = &chips[id->driver_data];
402 406
403 if (data->chip->id.manufacturer_id != I2C_DEVICE_ID_NONE) { 407 if (data->chip->id.manufacturer_id != I2C_DEVICE_ID_NONE) {
diff --git a/drivers/i2c/muxes/i2c-mux-reg.c b/drivers/i2c/muxes/i2c-mux-reg.c
index f583f805fee9..5653295b01cd 100644
--- a/drivers/i2c/muxes/i2c-mux-reg.c
+++ b/drivers/i2c/muxes/i2c-mux-reg.c
@@ -127,10 +127,8 @@ static int i2c_mux_reg_probe_dt(struct regmux *mux,
127 values = devm_kcalloc(&pdev->dev, 127 values = devm_kcalloc(&pdev->dev,
128 mux->data.n_values, sizeof(*mux->data.values), 128 mux->data.n_values, sizeof(*mux->data.values),
129 GFP_KERNEL); 129 GFP_KERNEL);
130 if (!values) { 130 if (!values)
131 dev_err(&pdev->dev, "Cannot allocate values array");
132 return -ENOMEM; 131 return -ENOMEM;
133 }
134 132
135 for_each_child_of_node(np, child) { 133 for_each_child_of_node(np, child) {
136 of_property_read_u32(child, "reg", values + i); 134 of_property_read_u32(child, "reg", values + i);
diff --git a/drivers/media/platform/marvell-ccic/mmp-driver.c b/drivers/media/platform/marvell-ccic/mmp-driver.c
index 3cf300072348..6d9f0abb2660 100644
--- a/drivers/media/platform/marvell-ccic/mmp-driver.c
+++ b/drivers/media/platform/marvell-ccic/mmp-driver.c
@@ -12,7 +12,7 @@
12#include <linux/kernel.h> 12#include <linux/kernel.h>
13#include <linux/module.h> 13#include <linux/module.h>
14#include <linux/i2c.h> 14#include <linux/i2c.h>
15#include <linux/i2c-gpio.h> 15#include <linux/platform_data/i2c-gpio.h>
16#include <linux/interrupt.h> 16#include <linux/interrupt.h>
17#include <linux/spinlock.h> 17#include <linux/spinlock.h>
18#include <linux/slab.h> 18#include <linux/slab.h>
diff --git a/drivers/mfd/sm501.c b/drivers/mfd/sm501.c
index 55d19fd0994e..2a87b0d2f21f 100644
--- a/drivers/mfd/sm501.c
+++ b/drivers/mfd/sm501.c
@@ -19,7 +19,7 @@
19#include <linux/device.h> 19#include <linux/device.h>
20#include <linux/platform_device.h> 20#include <linux/platform_device.h>
21#include <linux/pci.h> 21#include <linux/pci.h>
22#include <linux/i2c-gpio.h> 22#include <linux/platform_data/i2c-gpio.h>
23#include <linux/gpio/machine.h> 23#include <linux/gpio/machine.h>
24#include <linux/slab.h> 24#include <linux/slab.h>
25 25
diff --git a/drivers/mfd/timberdale.c b/drivers/mfd/timberdale.c
index 05ecf828b2ab..436e34705af1 100644
--- a/drivers/mfd/timberdale.c
+++ b/drivers/mfd/timberdale.c
@@ -30,8 +30,8 @@
30#include <linux/timb_gpio.h> 30#include <linux/timb_gpio.h>
31 31
32#include <linux/i2c.h> 32#include <linux/i2c.h>
33#include <linux/i2c-ocores.h> 33#include <linux/platform_data/i2c-ocores.h>
34#include <linux/i2c-xiic.h> 34#include <linux/platform_data/i2c-xiic.h>
35 35
36#include <linux/spi/spi.h> 36#include <linux/spi/spi.h>
37#include <linux/spi/xilinx_spi.h> 37#include <linux/spi/xilinx_spi.h>
diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
index 33053b0d1fdf..f5cc517d1131 100644
--- a/drivers/misc/eeprom/at24.c
+++ b/drivers/misc/eeprom/at24.c
@@ -532,6 +532,45 @@ static int at24_get_pdata(struct device *dev, struct at24_platform_data *pdata)
532 return 0; 532 return 0;
533} 533}
534 534
535static void at24_remove_dummy_clients(struct at24_data *at24)
536{
537 int i;
538
539 for (i = 1; i < at24->num_addresses; i++)
540 i2c_unregister_device(at24->client[i].client);
541}
542
543static int at24_make_dummy_client(struct at24_data *at24, unsigned int index,
544 struct regmap_config *regmap_config)
545{
546 struct i2c_client *base_client, *dummy_client;
547 unsigned short int addr;
548 struct regmap *regmap;
549 struct device *dev;
550
551 base_client = at24->client[0].client;
552 dev = &base_client->dev;
553 addr = base_client->addr + index;
554
555 dummy_client = i2c_new_dummy(base_client->adapter,
556 base_client->addr + index);
557 if (!dummy_client) {
558 dev_err(dev, "address 0x%02x unavailable\n", addr);
559 return -EADDRINUSE;
560 }
561
562 regmap = devm_regmap_init_i2c(dummy_client, regmap_config);
563 if (IS_ERR(regmap)) {
564 i2c_unregister_device(dummy_client);
565 return PTR_ERR(regmap);
566 }
567
568 at24->client[index].client = dummy_client;
569 at24->client[index].regmap = regmap;
570
571 return 0;
572}
573
535static unsigned int at24_get_offset_adj(u8 flags, unsigned int byte_len) 574static unsigned int at24_get_offset_adj(u8 flags, unsigned int byte_len)
536{ 575{
537 if (flags & AT24_FLAG_MAC) { 576 if (flags & AT24_FLAG_MAC) {
@@ -637,20 +676,10 @@ static int at24_probe(struct i2c_client *client)
637 676
638 /* use dummy devices for multiple-address chips */ 677 /* use dummy devices for multiple-address chips */
639 for (i = 1; i < num_addresses; i++) { 678 for (i = 1; i < num_addresses; i++) {
640 at24->client[i].client = i2c_new_dummy(client->adapter, 679 err = at24_make_dummy_client(at24, i, &regmap_config);
641 client->addr + i); 680 if (err) {
642 if (!at24->client[i].client) { 681 at24_remove_dummy_clients(at24);
643 dev_err(dev, "address 0x%02x unavailable\n", 682 return err;
644 client->addr + i);
645 err = -EADDRINUSE;
646 goto err_clients;
647 }
648 at24->client[i].regmap = devm_regmap_init_i2c(
649 at24->client[i].client,
650 &regmap_config);
651 if (IS_ERR(at24->client[i].regmap)) {
652 err = PTR_ERR(at24->client[i].regmap);
653 goto err_clients;
654 } 683 }
655 } 684 }
656 685
@@ -685,7 +714,7 @@ static int at24_probe(struct i2c_client *client)
685 nvmem_config.word_size = 1; 714 nvmem_config.word_size = 1;
686 nvmem_config.size = pdata.byte_len; 715 nvmem_config.size = pdata.byte_len;
687 716
688 at24->nvmem = nvmem_register(&nvmem_config); 717 at24->nvmem = devm_nvmem_register(dev, &nvmem_config);
689 if (IS_ERR(at24->nvmem)) { 718 if (IS_ERR(at24->nvmem)) {
690 err = PTR_ERR(at24->nvmem); 719 err = PTR_ERR(at24->nvmem);
691 goto err_clients; 720 goto err_clients;
@@ -702,10 +731,7 @@ static int at24_probe(struct i2c_client *client)
702 return 0; 731 return 0;
703 732
704err_clients: 733err_clients:
705 for (i = 1; i < num_addresses; i++) 734 at24_remove_dummy_clients(at24);
706 if (at24->client[i].client)
707 i2c_unregister_device(at24->client[i].client);
708
709 pm_runtime_disable(dev); 735 pm_runtime_disable(dev);
710 736
711 return err; 737 return err;
@@ -714,15 +740,10 @@ err_clients:
714static int at24_remove(struct i2c_client *client) 740static int at24_remove(struct i2c_client *client)
715{ 741{
716 struct at24_data *at24; 742 struct at24_data *at24;
717 int i;
718 743
719 at24 = i2c_get_clientdata(client); 744 at24 = i2c_get_clientdata(client);
720 745
721 nvmem_unregister(at24->nvmem); 746 at24_remove_dummy_clients(at24);
722
723 for (i = 1; i < at24->num_addresses; i++)
724 i2c_unregister_device(at24->client[i].client);
725
726 pm_runtime_disable(&client->dev); 747 pm_runtime_disable(&client->dev);
727 pm_runtime_set_suspended(&client->dev); 748 pm_runtime_set_suspended(&client->dev);
728 749
diff --git a/include/linux/i2c-pnx.h b/include/linux/i2c-pnx.h
deleted file mode 100644
index 5388326fbbff..000000000000
--- a/include/linux/i2c-pnx.h
+++ /dev/null
@@ -1,38 +0,0 @@
1/*
2 * Header file for I2C support on PNX010x/4008.
3 *
4 * Author: Dennis Kovalev <dkovalev@ru.mvista.com>
5 *
6 * 2004-2006 (c) MontaVista Software, Inc. This file is licensed under
7 * the terms of the GNU General Public License version 2. This program
8 * is licensed "as is" without any warranty of any kind, whether express
9 * or implied.
10 */
11
12#ifndef __I2C_PNX_H__
13#define __I2C_PNX_H__
14
15struct platform_device;
16struct clk;
17
18struct i2c_pnx_mif {
19 int ret; /* Return value */
20 int mode; /* Interface mode */
21 struct completion complete; /* I/O completion */
22 struct timer_list timer; /* Timeout */
23 u8 * buf; /* Data buffer */
24 int len; /* Length of data buffer */
25 int order; /* RX Bytes to order via TX */
26};
27
28struct i2c_pnx_algo_data {
29 void __iomem *ioaddr;
30 struct i2c_pnx_mif mif;
31 int last;
32 struct clk *clk;
33 struct i2c_adapter adapter;
34 int irq;
35 u32 timeout;
36};
37
38#endif /* __I2C_PNX_H__ */
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 44ad14e016b5..254cd34eeae2 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -394,7 +394,6 @@ static inline bool i2c_detect_slave_mode(struct device *dev) { return false; }
394 * @addr: stored in i2c_client.addr 394 * @addr: stored in i2c_client.addr
395 * @dev_name: Overrides the default <busnr>-<addr> dev_name if set 395 * @dev_name: Overrides the default <busnr>-<addr> dev_name if set
396 * @platform_data: stored in i2c_client.dev.platform_data 396 * @platform_data: stored in i2c_client.dev.platform_data
397 * @archdata: copied into i2c_client.dev.archdata
398 * @of_node: pointer to OpenFirmware device node 397 * @of_node: pointer to OpenFirmware device node
399 * @fwnode: device node supplied by the platform firmware 398 * @fwnode: device node supplied by the platform firmware
400 * @properties: additional device properties for the device 399 * @properties: additional device properties for the device
@@ -419,7 +418,6 @@ struct i2c_board_info {
419 unsigned short addr; 418 unsigned short addr;
420 const char *dev_name; 419 const char *dev_name;
421 void *platform_data; 420 void *platform_data;
422 struct dev_archdata *archdata;
423 struct device_node *of_node; 421 struct device_node *of_node;
424 struct fwnode_handle *fwnode; 422 struct fwnode_handle *fwnode;
425 const struct property_entry *properties; 423 const struct property_entry *properties;
@@ -903,6 +901,9 @@ extern const struct of_device_id
903*i2c_of_match_device(const struct of_device_id *matches, 901*i2c_of_match_device(const struct of_device_id *matches,
904 struct i2c_client *client); 902 struct i2c_client *client);
905 903
904int of_i2c_get_board_info(struct device *dev, struct device_node *node,
905 struct i2c_board_info *info);
906
906#else 907#else
907 908
908static inline struct i2c_client *of_find_i2c_device_by_node(struct device_node *node) 909static inline struct i2c_client *of_find_i2c_device_by_node(struct device_node *node)
@@ -927,6 +928,13 @@ static inline const struct of_device_id
927 return NULL; 928 return NULL;
928} 929}
929 930
931static inline int of_i2c_get_board_info(struct device *dev,
932 struct device_node *node,
933 struct i2c_board_info *info)
934{
935 return -ENOTSUPP;
936}
937
930#endif /* CONFIG_OF */ 938#endif /* CONFIG_OF */
931 939
932#if IS_ENABLED(CONFIG_ACPI) 940#if IS_ENABLED(CONFIG_ACPI)
diff --git a/include/linux/i2c-gpio.h b/include/linux/platform_data/i2c-gpio.h
index 352c1426fd4d..352c1426fd4d 100644
--- a/include/linux/i2c-gpio.h
+++ b/include/linux/platform_data/i2c-gpio.h
diff --git a/include/linux/i2c-mux-gpio.h b/include/linux/platform_data/i2c-mux-gpio.h
index 4406108201fe..4406108201fe 100644
--- a/include/linux/i2c-mux-gpio.h
+++ b/include/linux/platform_data/i2c-mux-gpio.h
diff --git a/include/linux/i2c-ocores.h b/include/linux/platform_data/i2c-ocores.h
index 01edd96fe1f7..01edd96fe1f7 100644
--- a/include/linux/i2c-ocores.h
+++ b/include/linux/platform_data/i2c-ocores.h
diff --git a/include/linux/i2c-omap.h b/include/linux/platform_data/i2c-omap.h
index 3444265ee8ee..3444265ee8ee 100644
--- a/include/linux/i2c-omap.h
+++ b/include/linux/platform_data/i2c-omap.h
diff --git a/include/linux/i2c-pca-platform.h b/include/linux/platform_data/i2c-pca-platform.h
index c37329432a8e..c37329432a8e 100644
--- a/include/linux/i2c-pca-platform.h
+++ b/include/linux/platform_data/i2c-pca-platform.h
diff --git a/include/linux/i2c-xiic.h b/include/linux/platform_data/i2c-xiic.h
index 4f9f2256a97e..4f9f2256a97e 100644
--- a/include/linux/i2c-xiic.h
+++ b/include/linux/platform_data/i2c-xiic.h