aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/devicetree/bindings/i2c/i2c-at91.txt2
-rw-r--r--Documentation/devicetree/bindings/i2c/i2c-cadence.txt24
-rw-r--r--Documentation/devicetree/bindings/i2c/i2c-designware.txt8
-rw-r--r--Documentation/devicetree/bindings/i2c/i2c-efm32.txt34
-rw-r--r--Documentation/devicetree/bindings/i2c/i2c-mv64xxx.txt20
-rw-r--r--Documentation/devicetree/bindings/i2c/i2c-rcar.txt14
-rw-r--r--Documentation/devicetree/bindings/i2c/qcom,i2c-qup.txt40
-rw-r--r--Documentation/i2c/busses/i2c-i8011
-rw-r--r--Documentation/i2c/functionality2
-rw-r--r--Documentation/i2c/i2c-protocol35
-rw-r--r--MAINTAINERS4
-rw-r--r--arch/blackfin/include/asm/bfin_twi.h143
-rw-r--r--arch/blackfin/kernel/debug-mmrs.c1
-rw-r--r--drivers/i2c/busses/Kconfig27
-rw-r--r--drivers/i2c/busses/Makefile3
-rw-r--r--drivers/i2c/busses/i2c-ali1535.c2
-rw-r--r--drivers/i2c/busses/i2c-ali1563.c2
-rw-r--r--drivers/i2c/busses/i2c-ali15x3.c2
-rw-r--r--drivers/i2c/busses/i2c-amd756.c2
-rw-r--r--drivers/i2c/busses/i2c-amd8111.c2
-rw-r--r--drivers/i2c/busses/i2c-at91.c12
-rw-r--r--drivers/i2c/busses/i2c-bcm2835.c26
-rw-r--r--drivers/i2c/busses/i2c-bfin-twi.c20
-rw-r--r--drivers/i2c/busses/i2c-cadence.c905
-rw-r--r--drivers/i2c/busses/i2c-davinci.c2
-rw-r--r--drivers/i2c/busses/i2c-designware-core.c27
-rw-r--r--drivers/i2c/busses/i2c-designware-core.h2
-rw-r--r--drivers/i2c/busses/i2c-designware-pcidrv.c125
-rw-r--r--drivers/i2c/busses/i2c-designware-platdrv.c9
-rw-r--r--drivers/i2c/busses/i2c-efm32.c481
-rw-r--r--drivers/i2c/busses/i2c-eg20t.c2
-rw-r--r--drivers/i2c/busses/i2c-exynos5.c4
-rw-r--r--drivers/i2c/busses/i2c-gpio.c3
-rw-r--r--drivers/i2c/busses/i2c-hydra.c2
-rw-r--r--drivers/i2c/busses/i2c-i801.c5
-rw-r--r--drivers/i2c/busses/i2c-ismt.c2
-rw-r--r--drivers/i2c/busses/i2c-mv64xxx.c83
-rw-r--r--drivers/i2c/busses/i2c-mxs.c18
-rw-r--r--drivers/i2c/busses/i2c-nforce2.c2
-rw-r--r--drivers/i2c/busses/i2c-nomadik.c253
-rw-r--r--drivers/i2c/busses/i2c-ocores.c2
-rw-r--r--drivers/i2c/busses/i2c-omap.c8
-rw-r--r--drivers/i2c/busses/i2c-pasemi.c2
-rw-r--r--drivers/i2c/busses/i2c-piix4.c2
-rw-r--r--drivers/i2c/busses/i2c-pxa-pci.c2
-rw-r--r--drivers/i2c/busses/i2c-qup.c768
-rw-r--r--drivers/i2c/busses/i2c-rcar.c3
-rw-r--r--drivers/i2c/busses/i2c-s3c2410.c39
-rw-r--r--drivers/i2c/busses/i2c-sirf.c2
-rw-r--r--drivers/i2c/busses/i2c-sis5595.c2
-rw-r--r--drivers/i2c/busses/i2c-sis630.c2
-rw-r--r--drivers/i2c/busses/i2c-sis96x.c2
-rw-r--r--drivers/i2c/busses/i2c-st.c2
-rw-r--r--drivers/i2c/busses/i2c-stu300.c2
-rw-r--r--drivers/i2c/busses/i2c-tegra.c2
-rw-r--r--drivers/i2c/busses/i2c-via.c2
-rw-r--r--drivers/i2c/busses/i2c-viapro.c2
-rw-r--r--drivers/i2c/busses/i2c-xiic.c2
-rw-r--r--drivers/i2c/busses/scx200_acb.c2
-rw-r--r--drivers/i2c/i2c-core.c67
-rw-r--r--include/linux/i2c.h1
-rw-r--r--include/linux/i2c/bfin_twi.h145
-rw-r--r--include/linux/platform_data/i2c-s3c2410.h9
-rw-r--r--include/trace/events/i2c.h372
64 files changed, 3292 insertions, 501 deletions
diff --git a/Documentation/devicetree/bindings/i2c/i2c-at91.txt b/Documentation/devicetree/bindings/i2c/i2c-at91.txt
index 4fade84bea16..388f0a275fba 100644
--- a/Documentation/devicetree/bindings/i2c/i2c-at91.txt
+++ b/Documentation/devicetree/bindings/i2c/i2c-at91.txt
@@ -12,6 +12,7 @@ Required properties :
12- clocks: phandles to input clocks. 12- clocks: phandles to input clocks.
13 13
14Optional properties: 14Optional properties:
15- clock-frequency: Desired I2C bus frequency in Hz, otherwise defaults to 100000
15- Child nodes conforming to i2c bus binding 16- Child nodes conforming to i2c bus binding
16 17
17Examples : 18Examples :
@@ -23,6 +24,7 @@ i2c0: i2c@fff84000 {
23 #address-cells = <1>; 24 #address-cells = <1>;
24 #size-cells = <0>; 25 #size-cells = <0>;
25 clocks = <&twi0_clk>; 26 clocks = <&twi0_clk>;
27 clock-frequency = <400000>;
26 28
27 24c512@50 { 29 24c512@50 {
28 compatible = "24c512"; 30 compatible = "24c512";
diff --git a/Documentation/devicetree/bindings/i2c/i2c-cadence.txt b/Documentation/devicetree/bindings/i2c/i2c-cadence.txt
new file mode 100644
index 000000000000..7cb0b5608f49
--- /dev/null
+++ b/Documentation/devicetree/bindings/i2c/i2c-cadence.txt
@@ -0,0 +1,24 @@
1Binding for the Cadence I2C controller
2
3Required properties:
4 - reg: Physical base address and size of the controller's register area.
5 - compatible: Compatibility string. Must be 'cdns,i2c-r1p10'.
6 - clocks: Input clock specifier. Refer to common clock bindings.
7 - interrupts: Interrupt specifier. Refer to interrupt bindings.
8 - #address-cells: Should be 1.
9 - #size-cells: Should be 0.
10
11Optional properties:
12 - clock-frequency: Desired operating frequency, in Hz, of the bus.
13 - clock-names: Input clock name, should be 'pclk'.
14
15Example:
16 i2c@e0004000 {
17 compatible = "cdns,i2c-r1p10";
18 clocks = <&clkc 38>;
19 interrupts = <GIC_SPI 25 IRQ_TYPE_LEVEL_HIGH>;
20 reg = <0xe0004000 0x1000>;
21 clock-frequency = <400000>;
22 #address-cells = <1>;
23 #size-cells = <0>;
24 };
diff --git a/Documentation/devicetree/bindings/i2c/i2c-designware.txt b/Documentation/devicetree/bindings/i2c/i2c-designware.txt
index 7fd7fa25e9b0..5199b0c8cf7a 100644
--- a/Documentation/devicetree/bindings/i2c/i2c-designware.txt
+++ b/Documentation/devicetree/bindings/i2c/i2c-designware.txt
@@ -14,6 +14,12 @@ Optional properties :
14 - i2c-sda-hold-time-ns : should contain the SDA hold time in nanoseconds. 14 - i2c-sda-hold-time-ns : should contain the SDA hold time in nanoseconds.
15 This option is only supported in hardware blocks version 1.11a or newer. 15 This option is only supported in hardware blocks version 1.11a or newer.
16 16
17 - i2c-scl-falling-time : should contain the SCL falling time in nanoseconds.
18 This value which is by default 300ns is used to compute the tLOW period.
19
20 - i2c-sda-falling-time : should contain the SDA falling time in nanoseconds.
21 This value which is by default 300ns is used to compute the tHIGH period.
22
17Example : 23Example :
18 24
19 i2c@f0000 { 25 i2c@f0000 {
@@ -34,4 +40,6 @@ Example :
34 interrupts = <12 1>; 40 interrupts = <12 1>;
35 clock-frequency = <400000>; 41 clock-frequency = <400000>;
36 i2c-sda-hold-time-ns = <300>; 42 i2c-sda-hold-time-ns = <300>;
43 i2c-sda-falling-time-ns = <300>;
44 i2c-scl-falling-time-ns = <300>;
37 }; 45 };
diff --git a/Documentation/devicetree/bindings/i2c/i2c-efm32.txt b/Documentation/devicetree/bindings/i2c/i2c-efm32.txt
new file mode 100644
index 000000000000..fc15ac519437
--- /dev/null
+++ b/Documentation/devicetree/bindings/i2c/i2c-efm32.txt
@@ -0,0 +1,34 @@
1* Energymicro efm32 i2c controller
2
3Required properties :
4
5 - reg : Offset and length of the register set for the device
6 - compatible : should be "energymicro,efm32-i2c"
7 - interrupts : the interrupt number
8 - clocks : reference to the module clock
9
10Recommended properties :
11
12 - clock-frequency : maximal I2C bus clock frequency in Hz.
13 - efm32,location : Decides the location of the USART I/O pins.
14 Allowed range : [0 .. 6]
15
16Example:
17 i2c0: i2c@4000a000 {
18 #address-cells = <1>;
19 #size-cells = <0>;
20 compatible = "energymicro,efm32-i2c";
21 reg = <0x4000a000 0x400>;
22 interrupts = <9>;
23 clocks = <&cmu clk_HFPERCLKI2C0>;
24 clock-frequency = <100000>;
25 status = "ok";
26 efm32,location = <3>;
27
28 eeprom@50 {
29 compatible = "microchip,24c02";
30 reg = <0x50>;
31 pagesize = <16>;
32 };
33 };
34
diff --git a/Documentation/devicetree/bindings/i2c/i2c-mv64xxx.txt b/Documentation/devicetree/bindings/i2c/i2c-mv64xxx.txt
index 582b4652a82a..befd4fb4764f 100644
--- a/Documentation/devicetree/bindings/i2c/i2c-mv64xxx.txt
+++ b/Documentation/devicetree/bindings/i2c/i2c-mv64xxx.txt
@@ -4,12 +4,16 @@
4Required properties : 4Required properties :
5 5
6 - reg : Offset and length of the register set for the device 6 - reg : Offset and length of the register set for the device
7 - compatible : Should be "marvell,mv64xxx-i2c" or "allwinner,sun4i-i2c" 7 - compatible : Should be either:
8 or "marvell,mv78230-i2c" or "marvell,mv78230-a0-i2c" 8 - "allwinner,sun4i-i2c"
9 Note: Only use "marvell,mv78230-a0-i2c" for a very rare, 9 - "allwinner,sun6i-a31-i2c"
10 initial version of the SoC which had broken offload 10 - "marvell,mv64xxx-i2c"
11 support. Linux auto-detects this and sets it 11 - "marvell,mv78230-i2c"
12 appropriately. 12 - "marvell,mv78230-a0-i2c"
13 * Note: Only use "marvell,mv78230-a0-i2c" for a
14 very rare, initial version of the SoC which
15 had broken offload support. Linux
16 auto-detects this and sets it appropriately.
13 - interrupts : The interrupt number 17 - interrupts : The interrupt number
14 18
15Optional properties : 19Optional properties :
@@ -17,6 +21,10 @@ Optional properties :
17 - clock-frequency : Desired I2C bus clock frequency in Hz. If not set the 21 - clock-frequency : Desired I2C bus clock frequency in Hz. If not set the
18default frequency is 100kHz 22default frequency is 100kHz
19 23
24 - resets : phandle to the parent reset controller. Mandatory
25 whenever you're using the "allwinner,sun6i-a31-i2c"
26 compatible.
27
20Examples: 28Examples:
21 29
22 i2c@11000 { 30 i2c@11000 {
diff --git a/Documentation/devicetree/bindings/i2c/i2c-rcar.txt b/Documentation/devicetree/bindings/i2c/i2c-rcar.txt
index 897cfcd5ce92..dd8b2dd1edeb 100644
--- a/Documentation/devicetree/bindings/i2c/i2c-rcar.txt
+++ b/Documentation/devicetree/bindings/i2c/i2c-rcar.txt
@@ -6,6 +6,7 @@ Required properties:
6 "renesas,i2c-r8a7778" 6 "renesas,i2c-r8a7778"
7 "renesas,i2c-r8a7779" 7 "renesas,i2c-r8a7779"
8 "renesas,i2c-r8a7790" 8 "renesas,i2c-r8a7790"
9 "renesas,i2c-r8a7791"
9- reg: physical base address of the controller and length of memory mapped 10- reg: physical base address of the controller and length of memory mapped
10 region. 11 region.
11- interrupts: interrupt specifier. 12- interrupts: interrupt specifier.
@@ -13,11 +14,16 @@ Required properties:
13Optional properties: 14Optional properties:
14- clock-frequency: desired I2C bus clock frequency in Hz. The absence of this 15- clock-frequency: desired I2C bus clock frequency in Hz. The absence of this
15 propoerty indicates the default frequency 100 kHz. 16 propoerty indicates the default frequency 100 kHz.
17- clocks: clock specifier.
16 18
17Examples : 19Examples :
18 20
19i2c0: i2c@e6500000 { 21i2c0: i2c@e6508000 {
20 compatible = "renesas,i2c-rcar-h2"; 22 #address-cells = <1>;
21 reg = <0 0xe6500000 0 0x428>; 23 #size-cells = <0>;
22 interrupts = <0 174 0x4>; 24 compatible = "renesas,i2c-r8a7791";
25 reg = <0 0xe6508000 0 0x40>;
26 interrupts = <0 287 IRQ_TYPE_LEVEL_HIGH>;
27 clocks = <&mstp9_clks R8A7791_CLK_I2C0>;
28 clock-frequency = <400000>;
23}; 29};
diff --git a/Documentation/devicetree/bindings/i2c/qcom,i2c-qup.txt b/Documentation/devicetree/bindings/i2c/qcom,i2c-qup.txt
new file mode 100644
index 000000000000..dc71754a56af
--- /dev/null
+++ b/Documentation/devicetree/bindings/i2c/qcom,i2c-qup.txt
@@ -0,0 +1,40 @@
1Qualcomm Universal Peripheral (QUP) I2C controller
2
3Required properties:
4 - compatible: Should be:
5 * "qcom,i2c-qup-v1.1.1" for 8660, 8960 and 8064.
6 * "qcom,i2c-qup-v2.1.1" for 8974 v1.
7 * "qcom,i2c-qup-v2.2.1" for 8974 v2 and later.
8 - reg: Should contain QUP register address and length.
9 - interrupts: Should contain I2C interrupt.
10
11 - clocks: A list of phandles + clock-specifiers, one for each entry in
12 clock-names.
13 - clock-names: Should contain:
14 * "core" for the core clock
15 * "iface" for the AHB clock
16
17 - #address-cells: Should be <1> Address cells for i2c device address
18 - #size-cells: Should be <0> as i2c addresses have no size component
19
20Optional properties:
21 - clock-frequency: Should specify the desired i2c bus clock frequency in Hz,
22 defaults to 100kHz if omitted.
23
24Child nodes should conform to i2c bus binding.
25
26Example:
27
28 i2c@f9924000 {
29 compatible = "qcom,i2c-qup-v2.2.1";
30 reg = <0xf9924000 0x1000>;
31 interrupts = <0 96 0>;
32
33 clocks = <&gcc GCC_BLSP1_QUP2_I2C_APPS_CLK>, <&gcc GCC_BLSP1_AHB_CLK>;
34 clock-names = "core", "iface";
35
36 clock-frequency = <355000>;
37
38 #address-cells = <1>;
39 #size-cells = <0>;
40 };
diff --git a/Documentation/i2c/busses/i2c-i801 b/Documentation/i2c/busses/i2c-i801
index aaaf069306a3..adf5e33e8312 100644
--- a/Documentation/i2c/busses/i2c-i801
+++ b/Documentation/i2c/busses/i2c-i801
@@ -26,6 +26,7 @@ Supported adapters:
26 * Intel Wellsburg (PCH) 26 * Intel Wellsburg (PCH)
27 * Intel Coleto Creek (PCH) 27 * Intel Coleto Creek (PCH)
28 * Intel Wildcat Point-LP (PCH) 28 * Intel Wildcat Point-LP (PCH)
29 * Intel BayTrail (SOC)
29 Datasheets: Publicly available at the Intel website 30 Datasheets: Publicly available at the Intel website
30 31
31On Intel Patsburg and later chipsets, both the normal host SMBus controller 32On Intel Patsburg and later chipsets, both the normal host SMBus controller
diff --git a/Documentation/i2c/functionality b/Documentation/i2c/functionality
index b0ff2ab596ce..4556a3eb87c4 100644
--- a/Documentation/i2c/functionality
+++ b/Documentation/i2c/functionality
@@ -46,7 +46,7 @@ A few combinations of the above flags are also defined for your convenience:
46 and write_block_data commands 46 and write_block_data commands
47 I2C_FUNC_SMBUS_I2C_BLOCK Handles the SMBus read_i2c_block_data 47 I2C_FUNC_SMBUS_I2C_BLOCK Handles the SMBus read_i2c_block_data
48 and write_i2c_block_data commands 48 and write_i2c_block_data commands
49 I2C_FUNC_SMBUS_EMUL Handles all SMBus commands than can be 49 I2C_FUNC_SMBUS_EMUL Handles all SMBus commands that can be
50 emulated by a real I2C adapter (using 50 emulated by a real I2C adapter (using
51 the transparent emulation layer) 51 the transparent emulation layer)
52 52
diff --git a/Documentation/i2c/i2c-protocol b/Documentation/i2c/i2c-protocol
index 0b3e62d1f77a..ff6d6cee6c7e 100644
--- a/Documentation/i2c/i2c-protocol
+++ b/Documentation/i2c/i2c-protocol
@@ -6,8 +6,8 @@ Key to symbols
6S (1 bit) : Start bit 6S (1 bit) : Start bit
7P (1 bit) : Stop bit 7P (1 bit) : Stop bit
8Rd/Wr (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0. 8Rd/Wr (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0.
9A, NA (1 bit) : Accept and reverse accept bit. 9A, NA (1 bit) : Accept and reverse accept bit.
10Addr (7 bits): I2C 7 bit address. Note that this can be expanded as usual to 10Addr (7 bits): I2C 7 bit address. Note that this can be expanded as usual to
11 get a 10 bit I2C address. 11 get a 10 bit I2C address.
12Comm (8 bits): Command byte, a data byte which often selects a register on 12Comm (8 bits): Command byte, a data byte which often selects a register on
13 the device. 13 the device.
@@ -49,11 +49,20 @@ a byte read, followed by a byte write:
49Modified transactions 49Modified transactions
50===================== 50=====================
51 51
52The following modifications to the I2C protocol can also be generated, 52The following modifications to the I2C protocol can also be generated by
53with the exception of I2C_M_NOSTART these are usually only needed to 53setting these flags for i2c messages. With the exception of I2C_M_NOSTART, they
54work around device issues: 54are usually only needed to work around device issues:
55 55
56 Flag I2C_M_NOSTART: 56I2C_M_IGNORE_NAK:
57 Normally message is interrupted immediately if there is [NA] from the
58 client. Setting this flag treats any [NA] as [A], and all of
59 message is sent.
60 These messages may still fail to SCL lo->hi timeout.
61
62I2C_M_NO_RD_ACK:
63 In a read message, master A/NA bit is skipped.
64
65I2C_M_NOSTART:
57 In a combined transaction, no 'S Addr Wr/Rd [A]' is generated at some 66 In a combined transaction, no 'S Addr Wr/Rd [A]' is generated at some
58 point. For example, setting I2C_M_NOSTART on the second partial message 67 point. For example, setting I2C_M_NOSTART on the second partial message
59 generates something like: 68 generates something like:
@@ -67,17 +76,13 @@ work around device issues:
67 I2C device but may also be used between direction changes by some 76 I2C device but may also be used between direction changes by some
68 rare devices. 77 rare devices.
69 78
70 Flags I2C_M_REV_DIR_ADDR 79I2C_M_REV_DIR_ADDR:
71 This toggles the Rd/Wr flag. That is, if you want to do a write, but 80 This toggles the Rd/Wr flag. That is, if you want to do a write, but
72 need to emit an Rd instead of a Wr, or vice versa, you set this 81 need to emit an Rd instead of a Wr, or vice versa, you set this
73 flag. For example: 82 flag. For example:
74 S Addr Rd [A] Data [A] Data [A] ... [A] Data [A] P 83 S Addr Rd [A] Data [A] Data [A] ... [A] Data [A] P
75 84
76 Flags I2C_M_IGNORE_NAK 85I2C_M_STOP:
77 Normally message is interrupted immediately if there is [NA] from the 86 Force a stop condition (P) after the message. Some I2C related protocols
78 client. Setting this flag treats any [NA] as [A], and all of 87 like SCCB require that. Normally, you really don't want to get interrupted
79 message is sent. 88 between the messages of one transfer.
80 These messages may still fail to SCL lo->hi timeout.
81
82 Flags I2C_M_NO_RD_ACK
83 In a read message, master A/NA bit is skipped.
diff --git a/MAINTAINERS b/MAINTAINERS
index a769432bddbe..beaa87a6e7fa 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1427,6 +1427,7 @@ F: drivers/cpuidle/cpuidle-zynq.c
1427N: zynq 1427N: zynq
1428N: xilinx 1428N: xilinx
1429F: drivers/clocksource/cadence_ttc_timer.c 1429F: drivers/clocksource/cadence_ttc_timer.c
1430F: drivers/i2c/busses/i2c-cadence.c
1430F: drivers/mmc/host/sdhci-of-arasan.c 1431F: drivers/mmc/host/sdhci-of-arasan.c
1431 1432
1432ARM SMMU DRIVER 1433ARM SMMU DRIVER
@@ -4308,7 +4309,8 @@ F: drivers/i2c/i2c-stub.c
4308I2C SUBSYSTEM 4309I2C SUBSYSTEM
4309M: Wolfram Sang <wsa@the-dreams.de> 4310M: Wolfram Sang <wsa@the-dreams.de>
4310L: linux-i2c@vger.kernel.org 4311L: linux-i2c@vger.kernel.org
4311W: http://i2c.wiki.kernel.org/ 4312W: https://i2c.wiki.kernel.org/
4313Q: https://patchwork.ozlabs.org/project/linux-i2c/list/
4312T: git git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git 4314T: git git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git
4313S: Maintained 4315S: Maintained
4314F: Documentation/i2c/ 4316F: Documentation/i2c/
diff --git a/arch/blackfin/include/asm/bfin_twi.h b/arch/blackfin/include/asm/bfin_twi.h
index 90c3c006557d..aaa0834d34aa 100644
--- a/arch/blackfin/include/asm/bfin_twi.h
+++ b/arch/blackfin/include/asm/bfin_twi.h
@@ -9,60 +9,7 @@
9#ifndef __ASM_BFIN_TWI_H__ 9#ifndef __ASM_BFIN_TWI_H__
10#define __ASM_BFIN_TWI_H__ 10#define __ASM_BFIN_TWI_H__
11 11
12#include <linux/types.h> 12#include <asm/blackfin.h>
13#include <linux/i2c.h>
14
15/*
16 * All Blackfin system MMRs are padded to 32bits even if the register
17 * itself is only 16bits. So use a helper macro to streamline this.
18 */
19#define __BFP(m) u16 m; u16 __pad_##m
20
21/*
22 * bfin twi registers layout
23 */
24struct bfin_twi_regs {
25 __BFP(clkdiv);
26 __BFP(control);
27 __BFP(slave_ctl);
28 __BFP(slave_stat);
29 __BFP(slave_addr);
30 __BFP(master_ctl);
31 __BFP(master_stat);
32 __BFP(master_addr);
33 __BFP(int_stat);
34 __BFP(int_mask);
35 __BFP(fifo_ctl);
36 __BFP(fifo_stat);
37 u32 __pad[20];
38 __BFP(xmt_data8);
39 __BFP(xmt_data16);
40 __BFP(rcv_data8);
41 __BFP(rcv_data16);
42};
43
44#undef __BFP
45
46struct bfin_twi_iface {
47 int irq;
48 spinlock_t lock;
49 char read_write;
50 u8 command;
51 u8 *transPtr;
52 int readNum;
53 int writeNum;
54 int cur_mode;
55 int manual_stop;
56 int result;
57 struct i2c_adapter adap;
58 struct completion complete;
59 struct i2c_msg *pmsg;
60 int msg_num;
61 int cur_msg;
62 u16 saved_clkdiv;
63 u16 saved_control;
64 struct bfin_twi_regs __iomem *regs_base;
65};
66 13
67#define DEFINE_TWI_REG(reg_name, reg) \ 14#define DEFINE_TWI_REG(reg_name, reg) \
68static inline u16 read_##reg_name(struct bfin_twi_iface *iface) \ 15static inline u16 read_##reg_name(struct bfin_twi_iface *iface) \
@@ -71,7 +18,6 @@ static inline void write_##reg_name(struct bfin_twi_iface *iface, u16 v) \
71 { bfin_write16(&iface->regs_base->reg, v); } 18 { bfin_write16(&iface->regs_base->reg, v); }
72 19
73DEFINE_TWI_REG(CLKDIV, clkdiv) 20DEFINE_TWI_REG(CLKDIV, clkdiv)
74DEFINE_TWI_REG(CONTROL, control)
75DEFINE_TWI_REG(SLAVE_CTL, slave_ctl) 21DEFINE_TWI_REG(SLAVE_CTL, slave_ctl)
76DEFINE_TWI_REG(SLAVE_STAT, slave_stat) 22DEFINE_TWI_REG(SLAVE_STAT, slave_stat)
77DEFINE_TWI_REG(SLAVE_ADDR, slave_addr) 23DEFINE_TWI_REG(SLAVE_ADDR, slave_addr)
@@ -80,7 +26,6 @@ DEFINE_TWI_REG(MASTER_STAT, master_stat)
80DEFINE_TWI_REG(MASTER_ADDR, master_addr) 26DEFINE_TWI_REG(MASTER_ADDR, master_addr)
81DEFINE_TWI_REG(INT_STAT, int_stat) 27DEFINE_TWI_REG(INT_STAT, int_stat)
82DEFINE_TWI_REG(INT_MASK, int_mask) 28DEFINE_TWI_REG(INT_MASK, int_mask)
83DEFINE_TWI_REG(FIFO_CTL, fifo_ctl)
84DEFINE_TWI_REG(FIFO_STAT, fifo_stat) 29DEFINE_TWI_REG(FIFO_STAT, fifo_stat)
85DEFINE_TWI_REG(XMT_DATA8, xmt_data8) 30DEFINE_TWI_REG(XMT_DATA8, xmt_data8)
86DEFINE_TWI_REG(XMT_DATA16, xmt_data16) 31DEFINE_TWI_REG(XMT_DATA16, xmt_data16)
@@ -113,75 +58,25 @@ static inline u16 read_RCV_DATA16(struct bfin_twi_iface *iface)
113} 58}
114#endif 59#endif
115 60
61static inline u16 read_FIFO_CTL(struct bfin_twi_iface *iface)
62{
63 return bfin_read16(&iface->regs_base->fifo_ctl);
64}
116 65
117/* ******************** TWO-WIRE INTERFACE (TWI) MASKS ***********************/ 66static inline void write_FIFO_CTL(struct bfin_twi_iface *iface, u16 v)
118/* TWI_CLKDIV Macros (Use: *pTWI_CLKDIV = CLKLOW(x)|CLKHI(y); ) */ 67{
119#define CLKLOW(x) ((x) & 0xFF) /* Periods Clock Is Held Low */ 68 bfin_write16(&iface->regs_base->fifo_ctl, v);
120#define CLKHI(y) (((y)&0xFF)<<0x8) /* Periods Before New Clock Low */ 69 SSYNC();
121 70}
122/* TWI_PRESCALE Masks */
123#define PRESCALE 0x007F /* SCLKs Per Internal Time Reference (10MHz) */
124#define TWI_ENA 0x0080 /* TWI Enable */
125#define SCCB 0x0200 /* SCCB Compatibility Enable */
126
127/* TWI_SLAVE_CTL Masks */
128#define SEN 0x0001 /* Slave Enable */
129#define SADD_LEN 0x0002 /* Slave Address Length */
130#define STDVAL 0x0004 /* Slave Transmit Data Valid */
131#define NAK 0x0008 /* NAK/ACK* Generated At Conclusion Of Transfer */
132#define GEN 0x0010 /* General Call Address Matching Enabled */
133
134/* TWI_SLAVE_STAT Masks */
135#define SDIR 0x0001 /* Slave Transfer Direction (Transmit/Receive*) */
136#define GCALL 0x0002 /* General Call Indicator */
137
138/* TWI_MASTER_CTL Masks */
139#define MEN 0x0001 /* Master Mode Enable */
140#define MADD_LEN 0x0002 /* Master Address Length */
141#define MDIR 0x0004 /* Master Transmit Direction (RX/TX*) */
142#define FAST 0x0008 /* Use Fast Mode Timing Specs */
143#define STOP 0x0010 /* Issue Stop Condition */
144#define RSTART 0x0020 /* Repeat Start or Stop* At End Of Transfer */
145#define DCNT 0x3FC0 /* Data Bytes To Transfer */
146#define SDAOVR 0x4000 /* Serial Data Override */
147#define SCLOVR 0x8000 /* Serial Clock Override */
148
149/* TWI_MASTER_STAT Masks */
150#define MPROG 0x0001 /* Master Transfer In Progress */
151#define LOSTARB 0x0002 /* Lost Arbitration Indicator (Xfer Aborted) */
152#define ANAK 0x0004 /* Address Not Acknowledged */
153#define DNAK 0x0008 /* Data Not Acknowledged */
154#define BUFRDERR 0x0010 /* Buffer Read Error */
155#define BUFWRERR 0x0020 /* Buffer Write Error */
156#define SDASEN 0x0040 /* Serial Data Sense */
157#define SCLSEN 0x0080 /* Serial Clock Sense */
158#define BUSBUSY 0x0100 /* Bus Busy Indicator */
159
160/* TWI_INT_SRC and TWI_INT_ENABLE Masks */
161#define SINIT 0x0001 /* Slave Transfer Initiated */
162#define SCOMP 0x0002 /* Slave Transfer Complete */
163#define SERR 0x0004 /* Slave Transfer Error */
164#define SOVF 0x0008 /* Slave Overflow */
165#define MCOMP 0x0010 /* Master Transfer Complete */
166#define MERR 0x0020 /* Master Transfer Error */
167#define XMTSERV 0x0040 /* Transmit FIFO Service */
168#define RCVSERV 0x0080 /* Receive FIFO Service */
169
170/* TWI_FIFO_CTRL Masks */
171#define XMTFLUSH 0x0001 /* Transmit Buffer Flush */
172#define RCVFLUSH 0x0002 /* Receive Buffer Flush */
173#define XMTINTLEN 0x0004 /* Transmit Buffer Interrupt Length */
174#define RCVINTLEN 0x0008 /* Receive Buffer Interrupt Length */
175
176/* TWI_FIFO_STAT Masks */
177#define XMTSTAT 0x0003 /* Transmit FIFO Status */
178#define XMT_EMPTY 0x0000 /* Transmit FIFO Empty */
179#define XMT_HALF 0x0001 /* Transmit FIFO Has 1 Byte To Write */
180#define XMT_FULL 0x0003 /* Transmit FIFO Full (2 Bytes To Write) */
181 71
182#define RCVSTAT 0x000C /* Receive FIFO Status */ 72static inline u16 read_CONTROL(struct bfin_twi_iface *iface)
183#define RCV_EMPTY 0x0000 /* Receive FIFO Empty */ 73{
184#define RCV_HALF 0x0004 /* Receive FIFO Has 1 Byte To Read */ 74 return bfin_read16(&iface->regs_base->control);
185#define RCV_FULL 0x000C /* Receive FIFO Full (2 Bytes To Read) */ 75}
186 76
77static inline void write_CONTROL(struct bfin_twi_iface *iface, u16 v)
78{
79 SSYNC();
80 bfin_write16(&iface->regs_base->control, v);
81}
187#endif 82#endif
diff --git a/arch/blackfin/kernel/debug-mmrs.c b/arch/blackfin/kernel/debug-mmrs.c
index 01232a13470d..947ad0832338 100644
--- a/arch/blackfin/kernel/debug-mmrs.c
+++ b/arch/blackfin/kernel/debug-mmrs.c
@@ -10,6 +10,7 @@
10#include <linux/fs.h> 10#include <linux/fs.h>
11#include <linux/kernel.h> 11#include <linux/kernel.h>
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/i2c/bfin_twi.h>
13 14
14#include <asm/blackfin.h> 15#include <asm/blackfin.h>
15#include <asm/gpio.h> 16#include <asm/gpio.h>
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index 014afab1d551..c94db1c5e353 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -110,6 +110,7 @@ config I2C_I801
110 Wellsburg (PCH) 110 Wellsburg (PCH)
111 Coleto Creek (PCH) 111 Coleto Creek (PCH)
112 Wildcat Point-LP (PCH) 112 Wildcat Point-LP (PCH)
113 BayTrail (SOC)
113 114
114 This driver can also be built as a module. If so, the module 115 This driver can also be built as a module. If so, the module
115 will be called i2c-i801. 116 will be called i2c-i801.
@@ -375,6 +376,13 @@ config I2C_BLACKFIN_TWI_CLK_KHZ
375 help 376 help
376 The unit of the TWI clock is kHz. 377 The unit of the TWI clock is kHz.
377 378
379config I2C_CADENCE
380 tristate "Cadence I2C Controller"
381 depends on ARCH_ZYNQ
382 help
383 Say yes here to select Cadence I2C Host Controller. This controller is
384 e.g. used by Xilinx Zynq.
385
378config I2C_CBUS_GPIO 386config I2C_CBUS_GPIO
379 tristate "CBUS I2C driver" 387 tristate "CBUS I2C driver"
380 depends on GPIOLIB 388 depends on GPIOLIB
@@ -432,6 +440,13 @@ config I2C_DESIGNWARE_PCI
432 This driver can also be built as a module. If so, the module 440 This driver can also be built as a module. If so, the module
433 will be called i2c-designware-pci. 441 will be called i2c-designware-pci.
434 442
443config I2C_EFM32
444 tristate "EFM32 I2C controller"
445 depends on ARCH_EFM32 || COMPILE_TEST
446 help
447 This driver supports the i2c block found in Energy Micro's EFM32
448 SoCs.
449
435config I2C_EG20T 450config I2C_EG20T
436 tristate "Intel EG20T PCH/LAPIS Semicon IOH(ML7213/ML7223/ML7831) I2C" 451 tristate "Intel EG20T PCH/LAPIS Semicon IOH(ML7213/ML7223/ML7831) I2C"
437 depends on PCI 452 depends on PCI
@@ -527,7 +542,7 @@ config I2C_MPC
527 542
528config I2C_MV64XXX 543config I2C_MV64XXX
529 tristate "Marvell mv64xxx I2C Controller" 544 tristate "Marvell mv64xxx I2C Controller"
530 depends on (MV64X60 || PLAT_ORION || ARCH_SUNXI) 545 depends on MV64X60 || PLAT_ORION || ARCH_SUNXI
531 help 546 help
532 If you say yes to this option, support will be included for the 547 If you say yes to this option, support will be included for the
533 built-in I2C interface on the Marvell 64xxx line of host bridges. 548 built-in I2C interface on the Marvell 64xxx line of host bridges.
@@ -648,6 +663,16 @@ config I2C_PXA_SLAVE
648 is necessary for systems where the PXA may be a target on the 663 is necessary for systems where the PXA may be a target on the
649 I2C bus. 664 I2C bus.
650 665
666config I2C_QUP
667 tristate "Qualcomm QUP based I2C controller"
668 depends on ARCH_QCOM
669 help
670 If you say yes to this option, support will be included for the
671 built-in I2C interface on the Qualcomm SoCs.
672
673 This driver can also be built as a module. If so, the module
674 will be called i2c-qup.
675
651config I2C_RIIC 676config I2C_RIIC
652 tristate "Renesas RIIC adapter" 677 tristate "Renesas RIIC adapter"
653 depends on ARCH_SHMOBILE || COMPILE_TEST 678 depends on ARCH_SHMOBILE || COMPILE_TEST
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
index a08931fe73e1..18d18ff9db93 100644
--- a/drivers/i2c/busses/Makefile
+++ b/drivers/i2c/busses/Makefile
@@ -33,6 +33,7 @@ obj-$(CONFIG_I2C_AT91) += i2c-at91.o
33obj-$(CONFIG_I2C_AU1550) += i2c-au1550.o 33obj-$(CONFIG_I2C_AU1550) += i2c-au1550.o
34obj-$(CONFIG_I2C_BCM2835) += i2c-bcm2835.o 34obj-$(CONFIG_I2C_BCM2835) += i2c-bcm2835.o
35obj-$(CONFIG_I2C_BLACKFIN_TWI) += i2c-bfin-twi.o 35obj-$(CONFIG_I2C_BLACKFIN_TWI) += i2c-bfin-twi.o
36obj-$(CONFIG_I2C_CADENCE) += i2c-cadence.o
36obj-$(CONFIG_I2C_CBUS_GPIO) += i2c-cbus-gpio.o 37obj-$(CONFIG_I2C_CBUS_GPIO) += i2c-cbus-gpio.o
37obj-$(CONFIG_I2C_CPM) += i2c-cpm.o 38obj-$(CONFIG_I2C_CPM) += i2c-cpm.o
38obj-$(CONFIG_I2C_DAVINCI) += i2c-davinci.o 39obj-$(CONFIG_I2C_DAVINCI) += i2c-davinci.o
@@ -41,6 +42,7 @@ obj-$(CONFIG_I2C_DESIGNWARE_PLATFORM) += i2c-designware-platform.o
41i2c-designware-platform-objs := i2c-designware-platdrv.o 42i2c-designware-platform-objs := i2c-designware-platdrv.o
42obj-$(CONFIG_I2C_DESIGNWARE_PCI) += i2c-designware-pci.o 43obj-$(CONFIG_I2C_DESIGNWARE_PCI) += i2c-designware-pci.o
43i2c-designware-pci-objs := i2c-designware-pcidrv.o 44i2c-designware-pci-objs := i2c-designware-pcidrv.o
45obj-$(CONFIG_I2C_EFM32) += i2c-efm32.o
44obj-$(CONFIG_I2C_EG20T) += i2c-eg20t.o 46obj-$(CONFIG_I2C_EG20T) += i2c-eg20t.o
45obj-$(CONFIG_I2C_EXYNOS5) += i2c-exynos5.o 47obj-$(CONFIG_I2C_EXYNOS5) += i2c-exynos5.o
46obj-$(CONFIG_I2C_GPIO) += i2c-gpio.o 48obj-$(CONFIG_I2C_GPIO) += i2c-gpio.o
@@ -63,6 +65,7 @@ obj-$(CONFIG_I2C_PNX) += i2c-pnx.o
63obj-$(CONFIG_I2C_PUV3) += i2c-puv3.o 65obj-$(CONFIG_I2C_PUV3) += i2c-puv3.o
64obj-$(CONFIG_I2C_PXA) += i2c-pxa.o 66obj-$(CONFIG_I2C_PXA) += i2c-pxa.o
65obj-$(CONFIG_I2C_PXA_PCI) += i2c-pxa-pci.o 67obj-$(CONFIG_I2C_PXA_PCI) += i2c-pxa-pci.o
68obj-$(CONFIG_I2C_QUP) += i2c-qup.o
66obj-$(CONFIG_I2C_RIIC) += i2c-riic.o 69obj-$(CONFIG_I2C_RIIC) += i2c-riic.o
67obj-$(CONFIG_I2C_S3C2410) += i2c-s3c2410.o 70obj-$(CONFIG_I2C_S3C2410) += i2c-s3c2410.o
68obj-$(CONFIG_I2C_S6000) += i2c-s6000.o 71obj-$(CONFIG_I2C_S6000) += i2c-s6000.o
diff --git a/drivers/i2c/busses/i2c-ali1535.c b/drivers/i2c/busses/i2c-ali1535.c
index 7d60d3a1f621..451e305f7971 100644
--- a/drivers/i2c/busses/i2c-ali1535.c
+++ b/drivers/i2c/busses/i2c-ali1535.c
@@ -494,7 +494,7 @@ static struct i2c_adapter ali1535_adapter = {
494 .algo = &smbus_algorithm, 494 .algo = &smbus_algorithm,
495}; 495};
496 496
497static DEFINE_PCI_DEVICE_TABLE(ali1535_ids) = { 497static const struct pci_device_id ali1535_ids[] = {
498 { PCI_DEVICE(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M7101) }, 498 { PCI_DEVICE(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M7101) },
499 { }, 499 { },
500}; 500};
diff --git a/drivers/i2c/busses/i2c-ali1563.c b/drivers/i2c/busses/i2c-ali1563.c
index 4611e4754a67..98a1c97739ba 100644
--- a/drivers/i2c/busses/i2c-ali1563.c
+++ b/drivers/i2c/busses/i2c-ali1563.c
@@ -416,7 +416,7 @@ static void ali1563_remove(struct pci_dev *dev)
416 ali1563_shutdown(dev); 416 ali1563_shutdown(dev);
417} 417}
418 418
419static DEFINE_PCI_DEVICE_TABLE(ali1563_id_table) = { 419static const struct pci_device_id ali1563_id_table[] = {
420 { PCI_DEVICE(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1563) }, 420 { PCI_DEVICE(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1563) },
421 {}, 421 {},
422}; 422};
diff --git a/drivers/i2c/busses/i2c-ali15x3.c b/drivers/i2c/busses/i2c-ali15x3.c
index 4823206a4870..2fa21ce9682b 100644
--- a/drivers/i2c/busses/i2c-ali15x3.c
+++ b/drivers/i2c/busses/i2c-ali15x3.c
@@ -476,7 +476,7 @@ static struct i2c_adapter ali15x3_adapter = {
476 .algo = &smbus_algorithm, 476 .algo = &smbus_algorithm,
477}; 477};
478 478
479static DEFINE_PCI_DEVICE_TABLE(ali15x3_ids) = { 479static const struct pci_device_id ali15x3_ids[] = {
480 { PCI_DEVICE(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M7101) }, 480 { PCI_DEVICE(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M7101) },
481 { 0, } 481 { 0, }
482}; 482};
diff --git a/drivers/i2c/busses/i2c-amd756.c b/drivers/i2c/busses/i2c-amd756.c
index 819d3c1062a7..a16f72891358 100644
--- a/drivers/i2c/busses/i2c-amd756.c
+++ b/drivers/i2c/busses/i2c-amd756.c
@@ -307,7 +307,7 @@ static const char* chipname[] = {
307 "nVidia nForce", "AMD8111", 307 "nVidia nForce", "AMD8111",
308}; 308};
309 309
310static DEFINE_PCI_DEVICE_TABLE(amd756_ids) = { 310static const struct pci_device_id amd756_ids[] = {
311 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_VIPER_740B), 311 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_VIPER_740B),
312 .driver_data = AMD756 }, 312 .driver_data = AMD756 },
313 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_VIPER_7413), 313 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_VIPER_7413),
diff --git a/drivers/i2c/busses/i2c-amd8111.c b/drivers/i2c/busses/i2c-amd8111.c
index f3d4d79855b5..95a80a8f81b5 100644
--- a/drivers/i2c/busses/i2c-amd8111.c
+++ b/drivers/i2c/busses/i2c-amd8111.c
@@ -414,7 +414,7 @@ static const struct i2c_algorithm smbus_algorithm = {
414}; 414};
415 415
416 416
417static DEFINE_PCI_DEVICE_TABLE(amd8111_ids) = { 417static const struct pci_device_id amd8111_ids[] = {
418 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8111_SMBUS2) }, 418 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8111_SMBUS2) },
419 { 0, } 419 { 0, }
420}; 420};
diff --git a/drivers/i2c/busses/i2c-at91.c b/drivers/i2c/busses/i2c-at91.c
index 843d01268ae9..e95f9ba96790 100644
--- a/drivers/i2c/busses/i2c-at91.c
+++ b/drivers/i2c/busses/i2c-at91.c
@@ -32,7 +32,7 @@
32#include <linux/slab.h> 32#include <linux/slab.h>
33#include <linux/platform_data/dma-atmel.h> 33#include <linux/platform_data/dma-atmel.h>
34 34
35#define TWI_CLK_HZ 100000 /* max 400 Kbits/s */ 35#define DEFAULT_TWI_CLK_HZ 100000 /* max 400 Kbits/s */
36#define AT91_I2C_TIMEOUT msecs_to_jiffies(100) /* transfer timeout */ 36#define AT91_I2C_TIMEOUT msecs_to_jiffies(100) /* transfer timeout */
37#define AT91_I2C_DMA_THRESHOLD 8 /* enable DMA if transfer size is bigger than this threshold */ 37#define AT91_I2C_DMA_THRESHOLD 8 /* enable DMA if transfer size is bigger than this threshold */
38 38
@@ -711,6 +711,7 @@ static int at91_twi_probe(struct platform_device *pdev)
711 struct resource *mem; 711 struct resource *mem;
712 int rc; 712 int rc;
713 u32 phy_addr; 713 u32 phy_addr;
714 u32 bus_clk_rate;
714 715
715 dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); 716 dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
716 if (!dev) 717 if (!dev)
@@ -756,13 +757,18 @@ static int at91_twi_probe(struct platform_device *pdev)
756 dev->use_dma = true; 757 dev->use_dma = true;
757 } 758 }
758 759
759 at91_calc_twi_clock(dev, TWI_CLK_HZ); 760 rc = of_property_read_u32(dev->dev->of_node, "clock-frequency",
761 &bus_clk_rate);
762 if (rc)
763 bus_clk_rate = DEFAULT_TWI_CLK_HZ;
764
765 at91_calc_twi_clock(dev, bus_clk_rate);
760 at91_init_twi_bus(dev); 766 at91_init_twi_bus(dev);
761 767
762 snprintf(dev->adapter.name, sizeof(dev->adapter.name), "AT91"); 768 snprintf(dev->adapter.name, sizeof(dev->adapter.name), "AT91");
763 i2c_set_adapdata(&dev->adapter, dev); 769 i2c_set_adapdata(&dev->adapter, dev);
764 dev->adapter.owner = THIS_MODULE; 770 dev->adapter.owner = THIS_MODULE;
765 dev->adapter.class = I2C_CLASS_HWMON; 771 dev->adapter.class = I2C_CLASS_HWMON | I2C_CLASS_DEPRECATED;
766 dev->adapter.algo = &at91_twi_algorithm; 772 dev->adapter.algo = &at91_twi_algorithm;
767 dev->adapter.dev.parent = dev->dev; 773 dev->adapter.dev.parent = dev->dev;
768 dev->adapter.nr = pdev->id; 774 dev->adapter.nr = pdev->id;
diff --git a/drivers/i2c/busses/i2c-bcm2835.c b/drivers/i2c/busses/i2c-bcm2835.c
index 77df97b932af..c60719577fc3 100644
--- a/drivers/i2c/busses/i2c-bcm2835.c
+++ b/drivers/i2c/busses/i2c-bcm2835.c
@@ -219,7 +219,7 @@ static const struct i2c_algorithm bcm2835_i2c_algo = {
219static int bcm2835_i2c_probe(struct platform_device *pdev) 219static int bcm2835_i2c_probe(struct platform_device *pdev)
220{ 220{
221 struct bcm2835_i2c_dev *i2c_dev; 221 struct bcm2835_i2c_dev *i2c_dev;
222 struct resource *mem, *requested, *irq; 222 struct resource *mem, *irq;
223 u32 bus_clk_rate, divider; 223 u32 bus_clk_rate, divider;
224 int ret; 224 int ret;
225 struct i2c_adapter *adap; 225 struct i2c_adapter *adap;
@@ -234,25 +234,9 @@ static int bcm2835_i2c_probe(struct platform_device *pdev)
234 init_completion(&i2c_dev->completion); 234 init_completion(&i2c_dev->completion);
235 235
236 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 236 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
237 if (!mem) { 237 i2c_dev->regs = devm_ioremap_resource(&pdev->dev, mem);
238 dev_err(&pdev->dev, "No mem resource\n"); 238 if (IS_ERR(i2c_dev->regs))
239 return -ENODEV; 239 return PTR_ERR(i2c_dev->regs);
240 }
241
242 requested = devm_request_mem_region(&pdev->dev, mem->start,
243 resource_size(mem),
244 dev_name(&pdev->dev));
245 if (!requested) {
246 dev_err(&pdev->dev, "Could not claim register region\n");
247 return -EBUSY;
248 }
249
250 i2c_dev->regs = devm_ioremap(&pdev->dev, mem->start,
251 resource_size(mem));
252 if (!i2c_dev->regs) {
253 dev_err(&pdev->dev, "Could not map registers\n");
254 return -ENOMEM;
255 }
256 240
257 i2c_dev->clk = devm_clk_get(&pdev->dev, NULL); 241 i2c_dev->clk = devm_clk_get(&pdev->dev, NULL);
258 if (IS_ERR(i2c_dev->clk)) { 242 if (IS_ERR(i2c_dev->clk)) {
@@ -295,7 +279,7 @@ static int bcm2835_i2c_probe(struct platform_device *pdev)
295 adap = &i2c_dev->adapter; 279 adap = &i2c_dev->adapter;
296 i2c_set_adapdata(adap, i2c_dev); 280 i2c_set_adapdata(adap, i2c_dev);
297 adap->owner = THIS_MODULE; 281 adap->owner = THIS_MODULE;
298 adap->class = I2C_CLASS_HWMON; 282 adap->class = I2C_CLASS_HWMON | I2C_CLASS_DEPRECATED;
299 strlcpy(adap->name, "bcm2835 I2C adapter", sizeof(adap->name)); 283 strlcpy(adap->name, "bcm2835 I2C adapter", sizeof(adap->name));
300 adap->algo = &bcm2835_i2c_algo; 284 adap->algo = &bcm2835_i2c_algo;
301 adap->dev.parent = &pdev->dev; 285 adap->dev.parent = &pdev->dev;
diff --git a/drivers/i2c/busses/i2c-bfin-twi.c b/drivers/i2c/busses/i2c-bfin-twi.c
index 3b9bd9a3f2b0..e6d5162b6379 100644
--- a/drivers/i2c/busses/i2c-bfin-twi.c
+++ b/drivers/i2c/busses/i2c-bfin-twi.c
@@ -21,10 +21,10 @@
21#include <linux/interrupt.h> 21#include <linux/interrupt.h>
22#include <linux/platform_device.h> 22#include <linux/platform_device.h>
23#include <linux/delay.h> 23#include <linux/delay.h>
24#include <linux/i2c/bfin_twi.h>
24 25
25#include <asm/blackfin.h>
26#include <asm/portmux.h>
27#include <asm/irq.h> 26#include <asm/irq.h>
27#include <asm/portmux.h>
28#include <asm/bfin_twi.h> 28#include <asm/bfin_twi.h>
29 29
30/* SMBus mode*/ 30/* SMBus mode*/
@@ -65,7 +65,6 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface,
65 /* Transmit next data */ 65 /* Transmit next data */
66 while (iface->writeNum > 0 && 66 while (iface->writeNum > 0 &&
67 (read_FIFO_STAT(iface) & XMTSTAT) != XMT_FULL) { 67 (read_FIFO_STAT(iface) & XMTSTAT) != XMT_FULL) {
68 SSYNC();
69 write_XMT_DATA8(iface, *(iface->transPtr++)); 68 write_XMT_DATA8(iface, *(iface->transPtr++));
70 iface->writeNum--; 69 iface->writeNum--;
71 } 70 }
@@ -248,7 +247,6 @@ static irqreturn_t bfin_twi_interrupt_entry(int irq, void *dev_id)
248 /* Clear interrupt status */ 247 /* Clear interrupt status */
249 write_INT_STAT(iface, twi_int_status); 248 write_INT_STAT(iface, twi_int_status);
250 bfin_twi_handle_interrupt(iface, twi_int_status); 249 bfin_twi_handle_interrupt(iface, twi_int_status);
251 SSYNC();
252 } 250 }
253 spin_unlock_irqrestore(&iface->lock, flags); 251 spin_unlock_irqrestore(&iface->lock, flags);
254 return IRQ_HANDLED; 252 return IRQ_HANDLED;
@@ -294,9 +292,7 @@ static int bfin_twi_do_master_xfer(struct i2c_adapter *adap,
294 * discarded before start a new operation. 292 * discarded before start a new operation.
295 */ 293 */
296 write_FIFO_CTL(iface, 0x3); 294 write_FIFO_CTL(iface, 0x3);
297 SSYNC();
298 write_FIFO_CTL(iface, 0); 295 write_FIFO_CTL(iface, 0);
299 SSYNC();
300 296
301 if (pmsg->flags & I2C_M_RD) 297 if (pmsg->flags & I2C_M_RD)
302 iface->read_write = I2C_SMBUS_READ; 298 iface->read_write = I2C_SMBUS_READ;
@@ -306,7 +302,6 @@ static int bfin_twi_do_master_xfer(struct i2c_adapter *adap,
306 if (iface->writeNum > 0) { 302 if (iface->writeNum > 0) {
307 write_XMT_DATA8(iface, *(iface->transPtr++)); 303 write_XMT_DATA8(iface, *(iface->transPtr++));
308 iface->writeNum--; 304 iface->writeNum--;
309 SSYNC();
310 } 305 }
311 } 306 }
312 307
@@ -315,7 +310,6 @@ static int bfin_twi_do_master_xfer(struct i2c_adapter *adap,
315 310
316 /* Interrupt mask . Enable XMT, RCV interrupt */ 311 /* Interrupt mask . Enable XMT, RCV interrupt */
317 write_INT_MASK(iface, MCOMP | MERR | RCVSERV | XMTSERV); 312 write_INT_MASK(iface, MCOMP | MERR | RCVSERV | XMTSERV);
318 SSYNC();
319 313
320 if (pmsg->len <= 255) 314 if (pmsg->len <= 255)
321 write_MASTER_CTL(iface, pmsg->len << 6); 315 write_MASTER_CTL(iface, pmsg->len << 6);
@@ -329,7 +323,6 @@ static int bfin_twi_do_master_xfer(struct i2c_adapter *adap,
329 (iface->msg_num > 1 ? RSTART : 0) | 323 (iface->msg_num > 1 ? RSTART : 0) |
330 ((iface->read_write == I2C_SMBUS_READ) ? MDIR : 0) | 324 ((iface->read_write == I2C_SMBUS_READ) ? MDIR : 0) |
331 ((CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ > 100) ? FAST : 0)); 325 ((CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ > 100) ? FAST : 0));
332 SSYNC();
333 326
334 while (!iface->result) { 327 while (!iface->result) {
335 if (!wait_for_completion_timeout(&iface->complete, 328 if (!wait_for_completion_timeout(&iface->complete,
@@ -453,7 +446,6 @@ int bfin_twi_do_smbus_xfer(struct i2c_adapter *adap, u16 addr,
453 * start a new operation. 446 * start a new operation.
454 */ 447 */
455 write_FIFO_CTL(iface, 0x3); 448 write_FIFO_CTL(iface, 0x3);
456 SSYNC();
457 write_FIFO_CTL(iface, 0); 449 write_FIFO_CTL(iface, 0);
458 450
459 /* clear int stat */ 451 /* clear int stat */
@@ -461,7 +453,6 @@ int bfin_twi_do_smbus_xfer(struct i2c_adapter *adap, u16 addr,
461 453
462 /* Set Transmit device address */ 454 /* Set Transmit device address */
463 write_MASTER_ADDR(iface, addr); 455 write_MASTER_ADDR(iface, addr);
464 SSYNC();
465 456
466 switch (iface->cur_mode) { 457 switch (iface->cur_mode) {
467 case TWI_I2C_MODE_STANDARDSUB: 458 case TWI_I2C_MODE_STANDARDSUB:
@@ -469,7 +460,6 @@ int bfin_twi_do_smbus_xfer(struct i2c_adapter *adap, u16 addr,
469 write_INT_MASK(iface, MCOMP | MERR | 460 write_INT_MASK(iface, MCOMP | MERR |
470 ((iface->read_write == I2C_SMBUS_READ) ? 461 ((iface->read_write == I2C_SMBUS_READ) ?
471 RCVSERV : XMTSERV)); 462 RCVSERV : XMTSERV));
472 SSYNC();
473 463
474 if (iface->writeNum + 1 <= 255) 464 if (iface->writeNum + 1 <= 255)
475 write_MASTER_CTL(iface, (iface->writeNum + 1) << 6); 465 write_MASTER_CTL(iface, (iface->writeNum + 1) << 6);
@@ -484,7 +474,6 @@ int bfin_twi_do_smbus_xfer(struct i2c_adapter *adap, u16 addr,
484 case TWI_I2C_MODE_COMBINED: 474 case TWI_I2C_MODE_COMBINED:
485 write_XMT_DATA8(iface, iface->command); 475 write_XMT_DATA8(iface, iface->command);
486 write_INT_MASK(iface, MCOMP | MERR | RCVSERV | XMTSERV); 476 write_INT_MASK(iface, MCOMP | MERR | RCVSERV | XMTSERV);
487 SSYNC();
488 477
489 if (iface->writeNum > 0) 478 if (iface->writeNum > 0)
490 write_MASTER_CTL(iface, (iface->writeNum + 1) << 6); 479 write_MASTER_CTL(iface, (iface->writeNum + 1) << 6);
@@ -531,7 +520,6 @@ int bfin_twi_do_smbus_xfer(struct i2c_adapter *adap, u16 addr,
531 write_INT_MASK(iface, MCOMP | MERR | 520 write_INT_MASK(iface, MCOMP | MERR |
532 ((iface->read_write == I2C_SMBUS_READ) ? 521 ((iface->read_write == I2C_SMBUS_READ) ?
533 RCVSERV : XMTSERV)); 522 RCVSERV : XMTSERV));
534 SSYNC();
535 523
536 /* Master enable */ 524 /* Master enable */
537 write_MASTER_CTL(iface, read_MASTER_CTL(iface) | MEN | 525 write_MASTER_CTL(iface, read_MASTER_CTL(iface) | MEN |
@@ -539,7 +527,6 @@ int bfin_twi_do_smbus_xfer(struct i2c_adapter *adap, u16 addr,
539 ((CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ > 100) ? FAST : 0)); 527 ((CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ > 100) ? FAST : 0));
540 break; 528 break;
541 } 529 }
542 SSYNC();
543 530
544 while (!iface->result) { 531 while (!iface->result) {
545 if (!wait_for_completion_timeout(&iface->complete, 532 if (!wait_for_completion_timeout(&iface->complete,
@@ -669,7 +656,7 @@ static int i2c_bfin_twi_probe(struct platform_device *pdev)
669 strlcpy(p_adap->name, pdev->name, sizeof(p_adap->name)); 656 strlcpy(p_adap->name, pdev->name, sizeof(p_adap->name));
670 p_adap->algo = &bfin_twi_algorithm; 657 p_adap->algo = &bfin_twi_algorithm;
671 p_adap->algo_data = iface; 658 p_adap->algo_data = iface;
672 p_adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD; 659 p_adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD | I2C_CLASS_DEPRECATED;
673 p_adap->dev.parent = &pdev->dev; 660 p_adap->dev.parent = &pdev->dev;
674 p_adap->timeout = 5 * HZ; 661 p_adap->timeout = 5 * HZ;
675 p_adap->retries = 3; 662 p_adap->retries = 3;
@@ -704,7 +691,6 @@ static int i2c_bfin_twi_probe(struct platform_device *pdev)
704 691
705 /* Enable TWI */ 692 /* Enable TWI */
706 write_CONTROL(iface, read_CONTROL(iface) | TWI_ENA); 693 write_CONTROL(iface, read_CONTROL(iface) | TWI_ENA);
707 SSYNC();
708 694
709 rc = i2c_add_numbered_adapter(p_adap); 695 rc = i2c_add_numbered_adapter(p_adap);
710 if (rc < 0) { 696 if (rc < 0) {
diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c
new file mode 100644
index 000000000000..63f3f03ecc9b
--- /dev/null
+++ b/drivers/i2c/busses/i2c-cadence.c
@@ -0,0 +1,905 @@
1/*
2 * I2C bus driver for the Cadence I2C controller.
3 *
4 * Copyright (C) 2009 - 2014 Xilinx, Inc.
5 *
6 * This program is free software; you can redistribute it
7 * and/or modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation;
9 * either version 2 of the License, or (at your option) any
10 * later version.
11 */
12
13#include <linux/clk.h>
14#include <linux/delay.h>
15#include <linux/i2c.h>
16#include <linux/interrupt.h>
17#include <linux/io.h>
18#include <linux/module.h>
19#include <linux/platform_device.h>
20
21/* Register offsets for the I2C device. */
22#define CDNS_I2C_CR_OFFSET 0x00 /* Control Register, RW */
23#define CDNS_I2C_SR_OFFSET 0x04 /* Status Register, RO */
24#define CDNS_I2C_ADDR_OFFSET 0x08 /* I2C Address Register, RW */
25#define CDNS_I2C_DATA_OFFSET 0x0C /* I2C Data Register, RW */
26#define CDNS_I2C_ISR_OFFSET 0x10 /* IRQ Status Register, RW */
27#define CDNS_I2C_XFER_SIZE_OFFSET 0x14 /* Transfer Size Register, RW */
28#define CDNS_I2C_TIME_OUT_OFFSET 0x1C /* Time Out Register, RW */
29#define CDNS_I2C_IER_OFFSET 0x24 /* IRQ Enable Register, WO */
30#define CDNS_I2C_IDR_OFFSET 0x28 /* IRQ Disable Register, WO */
31
32/* Control Register Bit mask definitions */
33#define CDNS_I2C_CR_HOLD BIT(4) /* Hold Bus bit */
34#define CDNS_I2C_CR_ACK_EN BIT(3)
35#define CDNS_I2C_CR_NEA BIT(2)
36#define CDNS_I2C_CR_MS BIT(1)
37/* Read or Write Master transfer 0 = Transmitter, 1 = Receiver */
38#define CDNS_I2C_CR_RW BIT(0)
39/* 1 = Auto init FIFO to zeroes */
40#define CDNS_I2C_CR_CLR_FIFO BIT(6)
41#define CDNS_I2C_CR_DIVA_SHIFT 14
42#define CDNS_I2C_CR_DIVA_MASK (3 << CDNS_I2C_CR_DIVA_SHIFT)
43#define CDNS_I2C_CR_DIVB_SHIFT 8
44#define CDNS_I2C_CR_DIVB_MASK (0x3f << CDNS_I2C_CR_DIVB_SHIFT)
45
46/* Status Register Bit mask definitions */
47#define CDNS_I2C_SR_BA BIT(8)
48#define CDNS_I2C_SR_RXDV BIT(5)
49
50/*
51 * I2C Address Register Bit mask definitions
52 * Normal addressing mode uses [6:0] bits. Extended addressing mode uses [9:0]
53 * bits. A write access to this register always initiates a transfer if the I2C
54 * is in master mode.
55 */
56#define CDNS_I2C_ADDR_MASK 0x000003FF /* I2C Address Mask */
57
58/*
59 * I2C Interrupt Registers Bit mask definitions
60 * All the four interrupt registers (Status/Mask/Enable/Disable) have the same
61 * bit definitions.
62 */
63#define CDNS_I2C_IXR_ARB_LOST BIT(9)
64#define CDNS_I2C_IXR_RX_UNF BIT(7)
65#define CDNS_I2C_IXR_TX_OVF BIT(6)
66#define CDNS_I2C_IXR_RX_OVF BIT(5)
67#define CDNS_I2C_IXR_SLV_RDY BIT(4)
68#define CDNS_I2C_IXR_TO BIT(3)
69#define CDNS_I2C_IXR_NACK BIT(2)
70#define CDNS_I2C_IXR_DATA BIT(1)
71#define CDNS_I2C_IXR_COMP BIT(0)
72
73#define CDNS_I2C_IXR_ALL_INTR_MASK (CDNS_I2C_IXR_ARB_LOST | \
74 CDNS_I2C_IXR_RX_UNF | \
75 CDNS_I2C_IXR_TX_OVF | \
76 CDNS_I2C_IXR_RX_OVF | \
77 CDNS_I2C_IXR_SLV_RDY | \
78 CDNS_I2C_IXR_TO | \
79 CDNS_I2C_IXR_NACK | \
80 CDNS_I2C_IXR_DATA | \
81 CDNS_I2C_IXR_COMP)
82
83#define CDNS_I2C_IXR_ERR_INTR_MASK (CDNS_I2C_IXR_ARB_LOST | \
84 CDNS_I2C_IXR_RX_UNF | \
85 CDNS_I2C_IXR_TX_OVF | \
86 CDNS_I2C_IXR_RX_OVF | \
87 CDNS_I2C_IXR_NACK)
88
89#define CDNS_I2C_ENABLED_INTR_MASK (CDNS_I2C_IXR_ARB_LOST | \
90 CDNS_I2C_IXR_RX_UNF | \
91 CDNS_I2C_IXR_TX_OVF | \
92 CDNS_I2C_IXR_RX_OVF | \
93 CDNS_I2C_IXR_NACK | \
94 CDNS_I2C_IXR_DATA | \
95 CDNS_I2C_IXR_COMP)
96
97#define CDNS_I2C_TIMEOUT msecs_to_jiffies(1000)
98
99#define CDNS_I2C_FIFO_DEPTH 16
100/* FIFO depth at which the DATA interrupt occurs */
101#define CDNS_I2C_DATA_INTR_DEPTH (CDNS_I2C_FIFO_DEPTH - 2)
102#define CDNS_I2C_MAX_TRANSFER_SIZE 255
103/* Transfer size in multiples of data interrupt depth */
104#define CDNS_I2C_TRANSFER_SIZE (CDNS_I2C_MAX_TRANSFER_SIZE - 3)
105
106#define DRIVER_NAME "cdns-i2c"
107
108#define CDNS_I2C_SPEED_MAX 400000
109#define CDNS_I2C_SPEED_DEFAULT 100000
110
111#define CDNS_I2C_DIVA_MAX 4
112#define CDNS_I2C_DIVB_MAX 64
113
114#define cdns_i2c_readreg(offset) readl_relaxed(id->membase + offset)
115#define cdns_i2c_writereg(val, offset) writel_relaxed(val, id->membase + offset)
116
117/**
118 * struct cdns_i2c - I2C device private data structure
119 * @membase: Base address of the I2C device
120 * @adap: I2C adapter instance
121 * @p_msg: Message pointer
122 * @err_status: Error status in Interrupt Status Register
123 * @xfer_done: Transfer complete status
124 * @p_send_buf: Pointer to transmit buffer
125 * @p_recv_buf: Pointer to receive buffer
126 * @suspended: Flag holding the device's PM status
127 * @send_count: Number of bytes still expected to send
128 * @recv_count: Number of bytes still expected to receive
129 * @irq: IRQ number
130 * @input_clk: Input clock to I2C controller
131 * @i2c_clk: Maximum I2C clock speed
132 * @bus_hold_flag: Flag used in repeated start for clearing HOLD bit
133 * @clk: Pointer to struct clk
134 * @clk_rate_change_nb: Notifier block for clock rate changes
135 */
136struct cdns_i2c {
137 void __iomem *membase;
138 struct i2c_adapter adap;
139 struct i2c_msg *p_msg;
140 int err_status;
141 struct completion xfer_done;
142 unsigned char *p_send_buf;
143 unsigned char *p_recv_buf;
144 u8 suspended;
145 unsigned int send_count;
146 unsigned int recv_count;
147 int irq;
148 unsigned long input_clk;
149 unsigned int i2c_clk;
150 unsigned int bus_hold_flag;
151 struct clk *clk;
152 struct notifier_block clk_rate_change_nb;
153};
154
155#define to_cdns_i2c(_nb) container_of(_nb, struct cdns_i2c, \
156 clk_rate_change_nb)
157
158/**
159 * cdns_i2c_clear_bus_hold() - Clear bus hold bit
160 * @id: Pointer to driver data struct
161 *
162 * Helper to clear the controller's bus hold bit.
163 */
164static void cdns_i2c_clear_bus_hold(struct cdns_i2c *id)
165{
166 u32 reg = cdns_i2c_readreg(CDNS_I2C_CR_OFFSET);
167 if (reg & CDNS_I2C_CR_HOLD)
168 cdns_i2c_writereg(reg & ~CDNS_I2C_CR_HOLD, CDNS_I2C_CR_OFFSET);
169}
170
171/**
172 * cdns_i2c_isr - Interrupt handler for the I2C device
173 * @irq: irq number for the I2C device
174 * @ptr: void pointer to cdns_i2c structure
175 *
176 * This function handles the data interrupt, transfer complete interrupt and
177 * the error interrupts of the I2C device.
178 *
179 * Return: IRQ_HANDLED always
180 */
181static irqreturn_t cdns_i2c_isr(int irq, void *ptr)
182{
183 unsigned int isr_status, avail_bytes;
184 unsigned int bytes_to_recv, bytes_to_send;
185 struct cdns_i2c *id = ptr;
186 /* Signal completion only after everything is updated */
187 int done_flag = 0;
188 irqreturn_t status = IRQ_NONE;
189
190 isr_status = cdns_i2c_readreg(CDNS_I2C_ISR_OFFSET);
191
192 /* Handling nack and arbitration lost interrupt */
193 if (isr_status & (CDNS_I2C_IXR_NACK | CDNS_I2C_IXR_ARB_LOST)) {
194 done_flag = 1;
195 status = IRQ_HANDLED;
196 }
197
198 /* Handling Data interrupt */
199 if ((isr_status & CDNS_I2C_IXR_DATA) &&
200 (id->recv_count >= CDNS_I2C_DATA_INTR_DEPTH)) {
201 /* Always read data interrupt threshold bytes */
202 bytes_to_recv = CDNS_I2C_DATA_INTR_DEPTH;
203 id->recv_count -= CDNS_I2C_DATA_INTR_DEPTH;
204 avail_bytes = cdns_i2c_readreg(CDNS_I2C_XFER_SIZE_OFFSET);
205
206 /*
207 * if the tranfer size register value is zero, then
208 * check for the remaining bytes and update the
209 * transfer size register.
210 */
211 if (!avail_bytes) {
212 if (id->recv_count > CDNS_I2C_TRANSFER_SIZE)
213 cdns_i2c_writereg(CDNS_I2C_TRANSFER_SIZE,
214 CDNS_I2C_XFER_SIZE_OFFSET);
215 else
216 cdns_i2c_writereg(id->recv_count,
217 CDNS_I2C_XFER_SIZE_OFFSET);
218 }
219
220 /* Process the data received */
221 while (bytes_to_recv--)
222 *(id->p_recv_buf)++ =
223 cdns_i2c_readreg(CDNS_I2C_DATA_OFFSET);
224
225 if (!id->bus_hold_flag &&
226 (id->recv_count <= CDNS_I2C_FIFO_DEPTH))
227 cdns_i2c_clear_bus_hold(id);
228
229 status = IRQ_HANDLED;
230 }
231
232 /* Handling Transfer Complete interrupt */
233 if (isr_status & CDNS_I2C_IXR_COMP) {
234 if (!id->p_recv_buf) {
235 /*
236 * If the device is sending data If there is further
237 * data to be sent. Calculate the available space
238 * in FIFO and fill the FIFO with that many bytes.
239 */
240 if (id->send_count) {
241 avail_bytes = CDNS_I2C_FIFO_DEPTH -
242 cdns_i2c_readreg(CDNS_I2C_XFER_SIZE_OFFSET);
243 if (id->send_count > avail_bytes)
244 bytes_to_send = avail_bytes;
245 else
246 bytes_to_send = id->send_count;
247
248 while (bytes_to_send--) {
249 cdns_i2c_writereg(
250 (*(id->p_send_buf)++),
251 CDNS_I2C_DATA_OFFSET);
252 id->send_count--;
253 }
254 } else {
255 /*
256 * Signal the completion of transaction and
257 * clear the hold bus bit if there are no
258 * further messages to be processed.
259 */
260 done_flag = 1;
261 }
262 if (!id->send_count && !id->bus_hold_flag)
263 cdns_i2c_clear_bus_hold(id);
264 } else {
265 if (!id->bus_hold_flag)
266 cdns_i2c_clear_bus_hold(id);
267 /*
268 * If the device is receiving data, then signal
269 * the completion of transaction and read the data
270 * present in the FIFO. Signal the completion of
271 * transaction.
272 */
273 while (cdns_i2c_readreg(CDNS_I2C_SR_OFFSET) &
274 CDNS_I2C_SR_RXDV) {
275 *(id->p_recv_buf)++ =
276 cdns_i2c_readreg(CDNS_I2C_DATA_OFFSET);
277 id->recv_count--;
278 }
279 done_flag = 1;
280 }
281
282 status = IRQ_HANDLED;
283 }
284
285 /* Update the status for errors */
286 id->err_status = isr_status & CDNS_I2C_IXR_ERR_INTR_MASK;
287 if (id->err_status)
288 status = IRQ_HANDLED;
289
290 cdns_i2c_writereg(isr_status, CDNS_I2C_ISR_OFFSET);
291
292 if (done_flag)
293 complete(&id->xfer_done);
294
295 return status;
296}
297
298/**
299 * cdns_i2c_mrecv - Prepare and start a master receive operation
300 * @id: pointer to the i2c device structure
301 */
302static void cdns_i2c_mrecv(struct cdns_i2c *id)
303{
304 unsigned int ctrl_reg;
305 unsigned int isr_status;
306
307 id->p_recv_buf = id->p_msg->buf;
308 id->recv_count = id->p_msg->len;
309
310 /* Put the controller in master receive mode and clear the FIFO */
311 ctrl_reg = cdns_i2c_readreg(CDNS_I2C_CR_OFFSET);
312 ctrl_reg |= CDNS_I2C_CR_RW | CDNS_I2C_CR_CLR_FIFO;
313
314 if (id->p_msg->flags & I2C_M_RECV_LEN)
315 id->recv_count = I2C_SMBUS_BLOCK_MAX + 1;
316
317 /*
318 * Check for the message size against FIFO depth and set the
319 * 'hold bus' bit if it is greater than FIFO depth.
320 */
321 if (id->recv_count > CDNS_I2C_FIFO_DEPTH)
322 ctrl_reg |= CDNS_I2C_CR_HOLD;
323
324 cdns_i2c_writereg(ctrl_reg, CDNS_I2C_CR_OFFSET);
325
326 /* Clear the interrupts in interrupt status register */
327 isr_status = cdns_i2c_readreg(CDNS_I2C_ISR_OFFSET);
328 cdns_i2c_writereg(isr_status, CDNS_I2C_ISR_OFFSET);
329
330 /*
331 * The no. of bytes to receive is checked against the limit of
332 * max transfer size. Set transfer size register with no of bytes
333 * receive if it is less than transfer size and transfer size if
334 * it is more. Enable the interrupts.
335 */
336 if (id->recv_count > CDNS_I2C_TRANSFER_SIZE)
337 cdns_i2c_writereg(CDNS_I2C_TRANSFER_SIZE,
338 CDNS_I2C_XFER_SIZE_OFFSET);
339 else
340 cdns_i2c_writereg(id->recv_count, CDNS_I2C_XFER_SIZE_OFFSET);
341 /* Clear the bus hold flag if bytes to receive is less than FIFO size */
342 if (!id->bus_hold_flag &&
343 ((id->p_msg->flags & I2C_M_RECV_LEN) != I2C_M_RECV_LEN) &&
344 (id->recv_count <= CDNS_I2C_FIFO_DEPTH))
345 cdns_i2c_clear_bus_hold(id);
346 /* Set the slave address in address register - triggers operation */
347 cdns_i2c_writereg(id->p_msg->addr & CDNS_I2C_ADDR_MASK,
348 CDNS_I2C_ADDR_OFFSET);
349 cdns_i2c_writereg(CDNS_I2C_ENABLED_INTR_MASK, CDNS_I2C_IER_OFFSET);
350}
351
352/**
353 * cdns_i2c_msend - Prepare and start a master send operation
354 * @id: pointer to the i2c device
355 */
356static void cdns_i2c_msend(struct cdns_i2c *id)
357{
358 unsigned int avail_bytes;
359 unsigned int bytes_to_send;
360 unsigned int ctrl_reg;
361 unsigned int isr_status;
362
363 id->p_recv_buf = NULL;
364 id->p_send_buf = id->p_msg->buf;
365 id->send_count = id->p_msg->len;
366
367 /* Set the controller in Master transmit mode and clear the FIFO. */
368 ctrl_reg = cdns_i2c_readreg(CDNS_I2C_CR_OFFSET);
369 ctrl_reg &= ~CDNS_I2C_CR_RW;
370 ctrl_reg |= CDNS_I2C_CR_CLR_FIFO;
371
372 /*
373 * Check for the message size against FIFO depth and set the
374 * 'hold bus' bit if it is greater than FIFO depth.
375 */
376 if (id->send_count > CDNS_I2C_FIFO_DEPTH)
377 ctrl_reg |= CDNS_I2C_CR_HOLD;
378 cdns_i2c_writereg(ctrl_reg, CDNS_I2C_CR_OFFSET);
379
380 /* Clear the interrupts in interrupt status register. */
381 isr_status = cdns_i2c_readreg(CDNS_I2C_ISR_OFFSET);
382 cdns_i2c_writereg(isr_status, CDNS_I2C_ISR_OFFSET);
383
384 /*
385 * Calculate the space available in FIFO. Check the message length
386 * against the space available, and fill the FIFO accordingly.
387 * Enable the interrupts.
388 */
389 avail_bytes = CDNS_I2C_FIFO_DEPTH -
390 cdns_i2c_readreg(CDNS_I2C_XFER_SIZE_OFFSET);
391
392 if (id->send_count > avail_bytes)
393 bytes_to_send = avail_bytes;
394 else
395 bytes_to_send = id->send_count;
396
397 while (bytes_to_send--) {
398 cdns_i2c_writereg((*(id->p_send_buf)++), CDNS_I2C_DATA_OFFSET);
399 id->send_count--;
400 }
401
402 /*
403 * Clear the bus hold flag if there is no more data
404 * and if it is the last message.
405 */
406 if (!id->bus_hold_flag && !id->send_count)
407 cdns_i2c_clear_bus_hold(id);
408 /* Set the slave address in address register - triggers operation. */
409 cdns_i2c_writereg(id->p_msg->addr & CDNS_I2C_ADDR_MASK,
410 CDNS_I2C_ADDR_OFFSET);
411
412 cdns_i2c_writereg(CDNS_I2C_ENABLED_INTR_MASK, CDNS_I2C_IER_OFFSET);
413}
414
415/**
416 * cdns_i2c_master_reset - Reset the interface
417 * @adap: pointer to the i2c adapter driver instance
418 *
419 * This function cleanup the fifos, clear the hold bit and status
420 * and disable the interrupts.
421 */
422static void cdns_i2c_master_reset(struct i2c_adapter *adap)
423{
424 struct cdns_i2c *id = adap->algo_data;
425 u32 regval;
426
427 /* Disable the interrupts */
428 cdns_i2c_writereg(CDNS_I2C_IXR_ALL_INTR_MASK, CDNS_I2C_IDR_OFFSET);
429 /* Clear the hold bit and fifos */
430 regval = cdns_i2c_readreg(CDNS_I2C_CR_OFFSET);
431 regval &= ~CDNS_I2C_CR_HOLD;
432 regval |= CDNS_I2C_CR_CLR_FIFO;
433 cdns_i2c_writereg(regval, CDNS_I2C_CR_OFFSET);
434 /* Update the transfercount register to zero */
435 cdns_i2c_writereg(0, CDNS_I2C_XFER_SIZE_OFFSET);
436 /* Clear the interupt status register */
437 regval = cdns_i2c_readreg(CDNS_I2C_ISR_OFFSET);
438 cdns_i2c_writereg(regval, CDNS_I2C_ISR_OFFSET);
439 /* Clear the status register */
440 regval = cdns_i2c_readreg(CDNS_I2C_SR_OFFSET);
441 cdns_i2c_writereg(regval, CDNS_I2C_SR_OFFSET);
442}
443
444static int cdns_i2c_process_msg(struct cdns_i2c *id, struct i2c_msg *msg,
445 struct i2c_adapter *adap)
446{
447 int ret;
448 u32 reg;
449
450 id->p_msg = msg;
451 id->err_status = 0;
452 reinit_completion(&id->xfer_done);
453
454 /* Check for the TEN Bit mode on each msg */
455 reg = cdns_i2c_readreg(CDNS_I2C_CR_OFFSET);
456 if (msg->flags & I2C_M_TEN) {
457 if (reg & CDNS_I2C_CR_NEA)
458 cdns_i2c_writereg(reg & ~CDNS_I2C_CR_NEA,
459 CDNS_I2C_CR_OFFSET);
460 } else {
461 if (!(reg & CDNS_I2C_CR_NEA))
462 cdns_i2c_writereg(reg | CDNS_I2C_CR_NEA,
463 CDNS_I2C_CR_OFFSET);
464 }
465
466 /* Check for the R/W flag on each msg */
467 if (msg->flags & I2C_M_RD)
468 cdns_i2c_mrecv(id);
469 else
470 cdns_i2c_msend(id);
471
472 /* Wait for the signal of completion */
473 ret = wait_for_completion_timeout(&id->xfer_done, adap->timeout);
474 if (!ret) {
475 cdns_i2c_master_reset(adap);
476 dev_err(id->adap.dev.parent,
477 "timeout waiting on completion\n");
478 return -ETIMEDOUT;
479 }
480
481 cdns_i2c_writereg(CDNS_I2C_IXR_ALL_INTR_MASK,
482 CDNS_I2C_IDR_OFFSET);
483
484 /* If it is bus arbitration error, try again */
485 if (id->err_status & CDNS_I2C_IXR_ARB_LOST)
486 return -EAGAIN;
487
488 return 0;
489}
490
491/**
492 * cdns_i2c_master_xfer - The main i2c transfer function
493 * @adap: pointer to the i2c adapter driver instance
494 * @msgs: pointer to the i2c message structure
495 * @num: the number of messages to transfer
496 *
497 * Initiates the send/recv activity based on the transfer message received.
498 *
499 * Return: number of msgs processed on success, negative error otherwise
500 */
501static int cdns_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
502 int num)
503{
504 int ret, count;
505 u32 reg;
506 struct cdns_i2c *id = adap->algo_data;
507
508 /* Check if the bus is free */
509 if (cdns_i2c_readreg(CDNS_I2C_SR_OFFSET) & CDNS_I2C_SR_BA)
510 return -EAGAIN;
511
512 /*
513 * Set the flag to one when multiple messages are to be
514 * processed with a repeated start.
515 */
516 if (num > 1) {
517 id->bus_hold_flag = 1;
518 reg = cdns_i2c_readreg(CDNS_I2C_CR_OFFSET);
519 reg |= CDNS_I2C_CR_HOLD;
520 cdns_i2c_writereg(reg, CDNS_I2C_CR_OFFSET);
521 } else {
522 id->bus_hold_flag = 0;
523 }
524
525 /* Process the msg one by one */
526 for (count = 0; count < num; count++, msgs++) {
527 if (count == (num - 1))
528 id->bus_hold_flag = 0;
529
530 ret = cdns_i2c_process_msg(id, msgs, adap);
531 if (ret)
532 return ret;
533
534 /* Report the other error interrupts to application */
535 if (id->err_status) {
536 cdns_i2c_master_reset(adap);
537
538 if (id->err_status & CDNS_I2C_IXR_NACK)
539 return -ENXIO;
540
541 return -EIO;
542 }
543 }
544
545 return num;
546}
547
548/**
549 * cdns_i2c_func - Returns the supported features of the I2C driver
550 * @adap: pointer to the i2c adapter structure
551 *
552 * Return: 32 bit value, each bit corresponding to a feature
553 */
554static u32 cdns_i2c_func(struct i2c_adapter *adap)
555{
556 return I2C_FUNC_I2C | I2C_FUNC_10BIT_ADDR |
557 (I2C_FUNC_SMBUS_EMUL & ~I2C_FUNC_SMBUS_QUICK) |
558 I2C_FUNC_SMBUS_BLOCK_DATA;
559}
560
561static const struct i2c_algorithm cdns_i2c_algo = {
562 .master_xfer = cdns_i2c_master_xfer,
563 .functionality = cdns_i2c_func,
564};
565
566/**
567 * cdns_i2c_calc_divs - Calculate clock dividers
568 * @f: I2C clock frequency
569 * @input_clk: Input clock frequency
570 * @a: First divider (return value)
571 * @b: Second divider (return value)
572 *
573 * f is used as input and output variable. As input it is used as target I2C
574 * frequency. On function exit f holds the actually resulting I2C frequency.
575 *
576 * Return: 0 on success, negative errno otherwise.
577 */
578static int cdns_i2c_calc_divs(unsigned long *f, unsigned long input_clk,
579 unsigned int *a, unsigned int *b)
580{
581 unsigned long fscl = *f, best_fscl = *f, actual_fscl, temp;
582 unsigned int div_a, div_b, calc_div_a = 0, calc_div_b = 0;
583 unsigned int last_error, current_error;
584
585 /* calculate (divisor_a+1) x (divisor_b+1) */
586 temp = input_clk / (22 * fscl);
587
588 /*
589 * If the calculated value is negative or 0, the fscl input is out of
590 * range. Return error.
591 */
592 if (!temp || (temp > (CDNS_I2C_DIVA_MAX * CDNS_I2C_DIVB_MAX)))
593 return -EINVAL;
594
595 last_error = -1;
596 for (div_a = 0; div_a < CDNS_I2C_DIVA_MAX; div_a++) {
597 div_b = DIV_ROUND_UP(input_clk, 22 * fscl * (div_a + 1));
598
599 if ((div_b < 1) || (div_b > CDNS_I2C_DIVB_MAX))
600 continue;
601 div_b--;
602
603 actual_fscl = input_clk / (22 * (div_a + 1) * (div_b + 1));
604
605 if (actual_fscl > fscl)
606 continue;
607
608 current_error = ((actual_fscl > fscl) ? (actual_fscl - fscl) :
609 (fscl - actual_fscl));
610
611 if (last_error > current_error) {
612 calc_div_a = div_a;
613 calc_div_b = div_b;
614 best_fscl = actual_fscl;
615 last_error = current_error;
616 }
617 }
618
619 *a = calc_div_a;
620 *b = calc_div_b;
621 *f = best_fscl;
622
623 return 0;
624}
625
626/**
627 * cdns_i2c_setclk - This function sets the serial clock rate for the I2C device
628 * @clk_in: I2C clock input frequency in Hz
629 * @id: Pointer to the I2C device structure
630 *
631 * The device must be idle rather than busy transferring data before setting
632 * these device options.
633 * The data rate is set by values in the control register.
634 * The formula for determining the correct register values is
635 * Fscl = Fpclk/(22 x (divisor_a+1) x (divisor_b+1))
636 * See the hardware data sheet for a full explanation of setting the serial
637 * clock rate. The clock can not be faster than the input clock divide by 22.
638 * The two most common clock rates are 100KHz and 400KHz.
639 *
640 * Return: 0 on success, negative error otherwise
641 */
642static int cdns_i2c_setclk(unsigned long clk_in, struct cdns_i2c *id)
643{
644 unsigned int div_a, div_b;
645 unsigned int ctrl_reg;
646 int ret = 0;
647 unsigned long fscl = id->i2c_clk;
648
649 ret = cdns_i2c_calc_divs(&fscl, clk_in, &div_a, &div_b);
650 if (ret)
651 return ret;
652
653 ctrl_reg = cdns_i2c_readreg(CDNS_I2C_CR_OFFSET);
654 ctrl_reg &= ~(CDNS_I2C_CR_DIVA_MASK | CDNS_I2C_CR_DIVB_MASK);
655 ctrl_reg |= ((div_a << CDNS_I2C_CR_DIVA_SHIFT) |
656 (div_b << CDNS_I2C_CR_DIVB_SHIFT));
657 cdns_i2c_writereg(ctrl_reg, CDNS_I2C_CR_OFFSET);
658
659 return 0;
660}
661
662/**
663 * cdns_i2c_clk_notifier_cb - Clock rate change callback
664 * @nb: Pointer to notifier block
665 * @event: Notification reason
666 * @data: Pointer to notification data object
667 *
668 * This function is called when the cdns_i2c input clock frequency changes.
669 * The callback checks whether a valid bus frequency can be generated after the
670 * change. If so, the change is acknowledged, otherwise the change is aborted.
671 * New dividers are written to the HW in the pre- or post change notification
672 * depending on the scaling direction.
673 *
674 * Return: NOTIFY_STOP if the rate change should be aborted, NOTIFY_OK
675 * to acknowedge the change, NOTIFY_DONE if the notification is
676 * considered irrelevant.
677 */
678static int cdns_i2c_clk_notifier_cb(struct notifier_block *nb, unsigned long
679 event, void *data)
680{
681 struct clk_notifier_data *ndata = data;
682 struct cdns_i2c *id = to_cdns_i2c(nb);
683
684 if (id->suspended)
685 return NOTIFY_OK;
686
687 switch (event) {
688 case PRE_RATE_CHANGE:
689 {
690 unsigned long input_clk = ndata->new_rate;
691 unsigned long fscl = id->i2c_clk;
692 unsigned int div_a, div_b;
693 int ret;
694
695 ret = cdns_i2c_calc_divs(&fscl, input_clk, &div_a, &div_b);
696 if (ret) {
697 dev_warn(id->adap.dev.parent,
698 "clock rate change rejected\n");
699 return NOTIFY_STOP;
700 }
701
702 /* scale up */
703 if (ndata->new_rate > ndata->old_rate)
704 cdns_i2c_setclk(ndata->new_rate, id);
705
706 return NOTIFY_OK;
707 }
708 case POST_RATE_CHANGE:
709 id->input_clk = ndata->new_rate;
710 /* scale down */
711 if (ndata->new_rate < ndata->old_rate)
712 cdns_i2c_setclk(ndata->new_rate, id);
713 return NOTIFY_OK;
714 case ABORT_RATE_CHANGE:
715 /* scale up */
716 if (ndata->new_rate > ndata->old_rate)
717 cdns_i2c_setclk(ndata->old_rate, id);
718 return NOTIFY_OK;
719 default:
720 return NOTIFY_DONE;
721 }
722}
723
724/**
725 * cdns_i2c_suspend - Suspend method for the driver
726 * @_dev: Address of the platform_device structure
727 *
728 * Put the driver into low power mode.
729 *
730 * Return: 0 always
731 */
732static int __maybe_unused cdns_i2c_suspend(struct device *_dev)
733{
734 struct platform_device *pdev = container_of(_dev,
735 struct platform_device, dev);
736 struct cdns_i2c *xi2c = platform_get_drvdata(pdev);
737
738 clk_disable(xi2c->clk);
739 xi2c->suspended = 1;
740
741 return 0;
742}
743
744/**
745 * cdns_i2c_resume - Resume from suspend
746 * @_dev: Address of the platform_device structure
747 *
748 * Resume operation after suspend.
749 *
750 * Return: 0 on success and error value on error
751 */
752static int __maybe_unused cdns_i2c_resume(struct device *_dev)
753{
754 struct platform_device *pdev = container_of(_dev,
755 struct platform_device, dev);
756 struct cdns_i2c *xi2c = platform_get_drvdata(pdev);
757 int ret;
758
759 ret = clk_enable(xi2c->clk);
760 if (ret) {
761 dev_err(_dev, "Cannot enable clock.\n");
762 return ret;
763 }
764
765 xi2c->suspended = 0;
766
767 return 0;
768}
769
770static SIMPLE_DEV_PM_OPS(cdns_i2c_dev_pm_ops, cdns_i2c_suspend,
771 cdns_i2c_resume);
772
773/**
774 * cdns_i2c_probe - Platform registration call
775 * @pdev: Handle to the platform device structure
776 *
777 * This function does all the memory allocation and registration for the i2c
778 * device. User can modify the address mode to 10 bit address mode using the
779 * ioctl call with option I2C_TENBIT.
780 *
781 * Return: 0 on success, negative error otherwise
782 */
783static int cdns_i2c_probe(struct platform_device *pdev)
784{
785 struct resource *r_mem;
786 struct cdns_i2c *id;
787 int ret;
788
789 id = devm_kzalloc(&pdev->dev, sizeof(*id), GFP_KERNEL);
790 if (!id)
791 return -ENOMEM;
792
793 platform_set_drvdata(pdev, id);
794
795 r_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
796 id->membase = devm_ioremap_resource(&pdev->dev, r_mem);
797 if (IS_ERR(id->membase))
798 return PTR_ERR(id->membase);
799
800 id->irq = platform_get_irq(pdev, 0);
801
802 id->adap.dev.of_node = pdev->dev.of_node;
803 id->adap.algo = &cdns_i2c_algo;
804 id->adap.timeout = CDNS_I2C_TIMEOUT;
805 id->adap.retries = 3; /* Default retry value. */
806 id->adap.algo_data = id;
807 id->adap.dev.parent = &pdev->dev;
808 init_completion(&id->xfer_done);
809 snprintf(id->adap.name, sizeof(id->adap.name),
810 "Cadence I2C at %08lx", (unsigned long)r_mem->start);
811
812 id->clk = devm_clk_get(&pdev->dev, NULL);
813 if (IS_ERR(id->clk)) {
814 dev_err(&pdev->dev, "input clock not found.\n");
815 return PTR_ERR(id->clk);
816 }
817 ret = clk_prepare_enable(id->clk);
818 if (ret) {
819 dev_err(&pdev->dev, "Unable to enable clock.\n");
820 return ret;
821 }
822 id->clk_rate_change_nb.notifier_call = cdns_i2c_clk_notifier_cb;
823 if (clk_notifier_register(id->clk, &id->clk_rate_change_nb))
824 dev_warn(&pdev->dev, "Unable to register clock notifier.\n");
825 id->input_clk = clk_get_rate(id->clk);
826
827 ret = of_property_read_u32(pdev->dev.of_node, "clock-frequency",
828 &id->i2c_clk);
829 if (ret || (id->i2c_clk > CDNS_I2C_SPEED_MAX))
830 id->i2c_clk = CDNS_I2C_SPEED_DEFAULT;
831
832 cdns_i2c_writereg(CDNS_I2C_CR_ACK_EN | CDNS_I2C_CR_NEA | CDNS_I2C_CR_MS,
833 CDNS_I2C_CR_OFFSET);
834
835 ret = cdns_i2c_setclk(id->input_clk, id);
836 if (ret) {
837 dev_err(&pdev->dev, "invalid SCL clock: %u Hz\n", id->i2c_clk);
838 ret = -EINVAL;
839 goto err_clk_dis;
840 }
841
842 ret = devm_request_irq(&pdev->dev, id->irq, cdns_i2c_isr, 0,
843 DRIVER_NAME, id);
844 if (ret) {
845 dev_err(&pdev->dev, "cannot get irq %d\n", id->irq);
846 goto err_clk_dis;
847 }
848
849 ret = i2c_add_adapter(&id->adap);
850 if (ret < 0) {
851 dev_err(&pdev->dev, "reg adap failed: %d\n", ret);
852 goto err_clk_dis;
853 }
854
855 dev_info(&pdev->dev, "%u kHz mmio %08lx irq %d\n",
856 id->i2c_clk / 1000, (unsigned long)r_mem->start, id->irq);
857
858 return 0;
859
860err_clk_dis:
861 clk_disable_unprepare(id->clk);
862 return ret;
863}
864
865/**
866 * cdns_i2c_remove - Unregister the device after releasing the resources
867 * @pdev: Handle to the platform device structure
868 *
869 * This function frees all the resources allocated to the device.
870 *
871 * Return: 0 always
872 */
873static int cdns_i2c_remove(struct platform_device *pdev)
874{
875 struct cdns_i2c *id = platform_get_drvdata(pdev);
876
877 i2c_del_adapter(&id->adap);
878 clk_notifier_unregister(id->clk, &id->clk_rate_change_nb);
879 clk_disable_unprepare(id->clk);
880
881 return 0;
882}
883
884static const struct of_device_id cdns_i2c_of_match[] = {
885 { .compatible = "cdns,i2c-r1p10", },
886 { /* end of table */ }
887};
888MODULE_DEVICE_TABLE(of, cdns_i2c_of_match);
889
890static struct platform_driver cdns_i2c_drv = {
891 .driver = {
892 .name = DRIVER_NAME,
893 .owner = THIS_MODULE,
894 .of_match_table = cdns_i2c_of_match,
895 .pm = &cdns_i2c_dev_pm_ops,
896 },
897 .probe = cdns_i2c_probe,
898 .remove = cdns_i2c_remove,
899};
900
901module_platform_driver(cdns_i2c_drv);
902
903MODULE_AUTHOR("Xilinx Inc.");
904MODULE_DESCRIPTION("Cadence I2C bus driver");
905MODULE_LICENSE("GPL");
diff --git a/drivers/i2c/busses/i2c-davinci.c b/drivers/i2c/busses/i2c-davinci.c
index af0b5830303d..389bc68c55ad 100644
--- a/drivers/i2c/busses/i2c-davinci.c
+++ b/drivers/i2c/busses/i2c-davinci.c
@@ -712,7 +712,7 @@ static int davinci_i2c_probe(struct platform_device *pdev)
712 adap = &dev->adapter; 712 adap = &dev->adapter;
713 i2c_set_adapdata(adap, dev); 713 i2c_set_adapdata(adap, dev);
714 adap->owner = THIS_MODULE; 714 adap->owner = THIS_MODULE;
715 adap->class = I2C_CLASS_HWMON; 715 adap->class = I2C_CLASS_HWMON | I2C_CLASS_DEPRECATED;
716 strlcpy(adap->name, "DaVinci I2C adapter", sizeof(adap->name)); 716 strlcpy(adap->name, "DaVinci I2C adapter", sizeof(adap->name));
717 adap->algo = &i2c_davinci_algo; 717 adap->algo = &i2c_davinci_algo;
718 adap->dev.parent = &pdev->dev; 718 adap->dev.parent = &pdev->dev;
diff --git a/drivers/i2c/busses/i2c-designware-core.c b/drivers/i2c/busses/i2c-designware-core.c
index 14c4b30d4ccc..22e92c3d3d07 100644
--- a/drivers/i2c/busses/i2c-designware-core.c
+++ b/drivers/i2c/busses/i2c-designware-core.c
@@ -218,7 +218,7 @@ i2c_dw_scl_hcnt(u32 ic_clk, u32 tSYMBOL, u32 tf, int cond, int offset)
218 * 218 *
219 * If your hardware is free from tHD;STA issue, try this one. 219 * If your hardware is free from tHD;STA issue, try this one.
220 */ 220 */
221 return (ic_clk * tSYMBOL + 5000) / 10000 - 8 + offset; 221 return (ic_clk * tSYMBOL + 500000) / 1000000 - 8 + offset;
222 else 222 else
223 /* 223 /*
224 * Conditional expression: 224 * Conditional expression:
@@ -234,7 +234,8 @@ i2c_dw_scl_hcnt(u32 ic_clk, u32 tSYMBOL, u32 tf, int cond, int offset)
234 * The reason why we need to take into account "tf" here, 234 * The reason why we need to take into account "tf" here,
235 * is the same as described in i2c_dw_scl_lcnt(). 235 * is the same as described in i2c_dw_scl_lcnt().
236 */ 236 */
237 return (ic_clk * (tSYMBOL + tf) + 5000) / 10000 - 3 + offset; 237 return (ic_clk * (tSYMBOL + tf) + 500000) / 1000000
238 - 3 + offset;
238} 239}
239 240
240static u32 i2c_dw_scl_lcnt(u32 ic_clk, u32 tLOW, u32 tf, int offset) 241static u32 i2c_dw_scl_lcnt(u32 ic_clk, u32 tLOW, u32 tf, int offset)
@@ -250,7 +251,7 @@ static u32 i2c_dw_scl_lcnt(u32 ic_clk, u32 tLOW, u32 tf, int offset)
250 * account the fall time of SCL signal (tf). Default tf value 251 * account the fall time of SCL signal (tf). Default tf value
251 * should be 0.3 us, for safety. 252 * should be 0.3 us, for safety.
252 */ 253 */
253 return ((ic_clk * (tLOW + tf) + 5000) / 10000) - 1 + offset; 254 return ((ic_clk * (tLOW + tf) + 500000) / 1000000) - 1 + offset;
254} 255}
255 256
256static void __i2c_dw_enable(struct dw_i2c_dev *dev, bool enable) 257static void __i2c_dw_enable(struct dw_i2c_dev *dev, bool enable)
@@ -287,6 +288,7 @@ int i2c_dw_init(struct dw_i2c_dev *dev)
287 u32 input_clock_khz; 288 u32 input_clock_khz;
288 u32 hcnt, lcnt; 289 u32 hcnt, lcnt;
289 u32 reg; 290 u32 reg;
291 u32 sda_falling_time, scl_falling_time;
290 292
291 input_clock_khz = dev->get_clk_rate_khz(dev); 293 input_clock_khz = dev->get_clk_rate_khz(dev);
292 294
@@ -308,15 +310,18 @@ int i2c_dw_init(struct dw_i2c_dev *dev)
308 310
309 /* set standard and fast speed deviders for high/low periods */ 311 /* set standard and fast speed deviders for high/low periods */
310 312
313 sda_falling_time = dev->sda_falling_time ?: 300; /* ns */
314 scl_falling_time = dev->scl_falling_time ?: 300; /* ns */
315
311 /* Standard-mode */ 316 /* Standard-mode */
312 hcnt = i2c_dw_scl_hcnt(input_clock_khz, 317 hcnt = i2c_dw_scl_hcnt(input_clock_khz,
313 40, /* tHD;STA = tHIGH = 4.0 us */ 318 4000, /* tHD;STA = tHIGH = 4.0 us */
314 3, /* tf = 0.3 us */ 319 sda_falling_time,
315 0, /* 0: DW default, 1: Ideal */ 320 0, /* 0: DW default, 1: Ideal */
316 0); /* No offset */ 321 0); /* No offset */
317 lcnt = i2c_dw_scl_lcnt(input_clock_khz, 322 lcnt = i2c_dw_scl_lcnt(input_clock_khz,
318 47, /* tLOW = 4.7 us */ 323 4700, /* tLOW = 4.7 us */
319 3, /* tf = 0.3 us */ 324 scl_falling_time,
320 0); /* No offset */ 325 0); /* No offset */
321 326
322 /* Allow platforms to specify the ideal HCNT and LCNT values */ 327 /* Allow platforms to specify the ideal HCNT and LCNT values */
@@ -330,13 +335,13 @@ int i2c_dw_init(struct dw_i2c_dev *dev)
330 335
331 /* Fast-mode */ 336 /* Fast-mode */
332 hcnt = i2c_dw_scl_hcnt(input_clock_khz, 337 hcnt = i2c_dw_scl_hcnt(input_clock_khz,
333 6, /* tHD;STA = tHIGH = 0.6 us */ 338 600, /* tHD;STA = tHIGH = 0.6 us */
334 3, /* tf = 0.3 us */ 339 sda_falling_time,
335 0, /* 0: DW default, 1: Ideal */ 340 0, /* 0: DW default, 1: Ideal */
336 0); /* No offset */ 341 0); /* No offset */
337 lcnt = i2c_dw_scl_lcnt(input_clock_khz, 342 lcnt = i2c_dw_scl_lcnt(input_clock_khz,
338 13, /* tLOW = 1.3 us */ 343 1300, /* tLOW = 1.3 us */
339 3, /* tf = 0.3 us */ 344 scl_falling_time,
340 0); /* No offset */ 345 0); /* No offset */
341 346
342 if (dev->fs_hcnt && dev->fs_lcnt) { 347 if (dev->fs_hcnt && dev->fs_lcnt) {
diff --git a/drivers/i2c/busses/i2c-designware-core.h b/drivers/i2c/busses/i2c-designware-core.h
index e8a756537ed0..d66b6cbc9edc 100644
--- a/drivers/i2c/busses/i2c-designware-core.h
+++ b/drivers/i2c/busses/i2c-designware-core.h
@@ -99,6 +99,8 @@ struct dw_i2c_dev {
99 unsigned int rx_fifo_depth; 99 unsigned int rx_fifo_depth;
100 int rx_outstanding; 100 int rx_outstanding;
101 u32 sda_hold_time; 101 u32 sda_hold_time;
102 u32 sda_falling_time;
103 u32 scl_falling_time;
102 u16 ss_hcnt; 104 u16 ss_hcnt;
103 u16 ss_lcnt; 105 u16 ss_lcnt;
104 u16 fs_hcnt; 106 u16 fs_hcnt;
diff --git a/drivers/i2c/busses/i2c-designware-pcidrv.c b/drivers/i2c/busses/i2c-designware-pcidrv.c
index f6ed06c966ee..85056c22d21e 100644
--- a/drivers/i2c/busses/i2c-designware-pcidrv.c
+++ b/drivers/i2c/busses/i2c-designware-pcidrv.c
@@ -54,6 +54,16 @@ enum dw_pci_ctl_id_t {
54 medfield_3, 54 medfield_3,
55 medfield_4, 55 medfield_4,
56 medfield_5, 56 medfield_5,
57
58 baytrail,
59};
60
61struct dw_scl_sda_cfg {
62 u32 ss_hcnt;
63 u32 fs_hcnt;
64 u32 ss_lcnt;
65 u32 fs_lcnt;
66 u32 sda_hold;
57}; 67};
58 68
59struct dw_pci_controller { 69struct dw_pci_controller {
@@ -62,12 +72,29 @@ struct dw_pci_controller {
62 u32 tx_fifo_depth; 72 u32 tx_fifo_depth;
63 u32 rx_fifo_depth; 73 u32 rx_fifo_depth;
64 u32 clk_khz; 74 u32 clk_khz;
75 u32 functionality;
76 struct dw_scl_sda_cfg *scl_sda_cfg;
65}; 77};
66 78
67#define INTEL_MID_STD_CFG (DW_IC_CON_MASTER | \ 79#define INTEL_MID_STD_CFG (DW_IC_CON_MASTER | \
68 DW_IC_CON_SLAVE_DISABLE | \ 80 DW_IC_CON_SLAVE_DISABLE | \
69 DW_IC_CON_RESTART_EN) 81 DW_IC_CON_RESTART_EN)
70 82
83#define DW_DEFAULT_FUNCTIONALITY (I2C_FUNC_I2C | \
84 I2C_FUNC_SMBUS_BYTE | \
85 I2C_FUNC_SMBUS_BYTE_DATA | \
86 I2C_FUNC_SMBUS_WORD_DATA | \
87 I2C_FUNC_SMBUS_I2C_BLOCK)
88
89/* BayTrail HCNT/LCNT/SDA hold time */
90static struct dw_scl_sda_cfg byt_config = {
91 .ss_hcnt = 0x200,
92 .fs_hcnt = 0x55,
93 .ss_lcnt = 0x200,
94 .fs_lcnt = 0x99,
95 .sda_hold = 0x6,
96};
97
71static struct dw_pci_controller dw_pci_controllers[] = { 98static struct dw_pci_controller dw_pci_controllers[] = {
72 [moorestown_0] = { 99 [moorestown_0] = {
73 .bus_num = 0, 100 .bus_num = 0,
@@ -132,75 +159,40 @@ static struct dw_pci_controller dw_pci_controllers[] = {
132 .rx_fifo_depth = 32, 159 .rx_fifo_depth = 32,
133 .clk_khz = 25000, 160 .clk_khz = 25000,
134 }, 161 },
162 [baytrail] = {
163 .bus_num = -1,
164 .bus_cfg = INTEL_MID_STD_CFG | DW_IC_CON_SPEED_FAST,
165 .tx_fifo_depth = 32,
166 .rx_fifo_depth = 32,
167 .clk_khz = 100000,
168 .functionality = I2C_FUNC_10BIT_ADDR,
169 .scl_sda_cfg = &byt_config,
170 },
135}; 171};
136static struct i2c_algorithm i2c_dw_algo = { 172static struct i2c_algorithm i2c_dw_algo = {
137 .master_xfer = i2c_dw_xfer, 173 .master_xfer = i2c_dw_xfer,
138 .functionality = i2c_dw_func, 174 .functionality = i2c_dw_func,
139}; 175};
140 176
177#ifdef CONFIG_PM
141static int i2c_dw_pci_suspend(struct device *dev) 178static int i2c_dw_pci_suspend(struct device *dev)
142{ 179{
143 struct pci_dev *pdev = container_of(dev, struct pci_dev, dev); 180 struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
144 struct dw_i2c_dev *i2c = pci_get_drvdata(pdev);
145 int err;
146
147
148 i2c_dw_disable(i2c);
149
150 err = pci_save_state(pdev);
151 if (err) {
152 dev_err(&pdev->dev, "pci_save_state failed\n");
153 return err;
154 }
155
156 err = pci_set_power_state(pdev, PCI_D3hot);
157 if (err) {
158 dev_err(&pdev->dev, "pci_set_power_state failed\n");
159 return err;
160 }
161 181
182 i2c_dw_disable(pci_get_drvdata(pdev));
162 return 0; 183 return 0;
163} 184}
164 185
165static int i2c_dw_pci_resume(struct device *dev) 186static int i2c_dw_pci_resume(struct device *dev)
166{ 187{
167 struct pci_dev *pdev = container_of(dev, struct pci_dev, dev); 188 struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
168 struct dw_i2c_dev *i2c = pci_get_drvdata(pdev);
169 int err;
170 u32 enabled;
171
172 enabled = i2c_dw_is_enabled(i2c);
173 if (enabled)
174 return 0;
175
176 err = pci_set_power_state(pdev, PCI_D0);
177 if (err) {
178 dev_err(&pdev->dev, "pci_set_power_state() failed\n");
179 return err;
180 }
181
182 pci_restore_state(pdev);
183
184 i2c_dw_init(i2c);
185 return 0;
186}
187 189
188static int i2c_dw_pci_runtime_idle(struct device *dev) 190 return i2c_dw_init(pci_get_drvdata(pdev));
189{
190 int err = pm_schedule_suspend(dev, 500);
191 dev_dbg(dev, "runtime_idle called\n");
192
193 if (err != 0)
194 return 0;
195 return -EBUSY;
196} 191}
192#endif
197 193
198static const struct dev_pm_ops i2c_dw_pm_ops = { 194static UNIVERSAL_DEV_PM_OPS(i2c_dw_pm_ops, i2c_dw_pci_suspend,
199 .resume = i2c_dw_pci_resume, 195 i2c_dw_pci_resume, NULL);
200 .suspend = i2c_dw_pci_suspend,
201 SET_RUNTIME_PM_OPS(i2c_dw_pci_suspend, i2c_dw_pci_resume,
202 i2c_dw_pci_runtime_idle)
203};
204 196
205static u32 i2c_dw_get_clk_rate_khz(struct dw_i2c_dev *dev) 197static u32 i2c_dw_get_clk_rate_khz(struct dw_i2c_dev *dev)
206{ 198{
@@ -214,6 +206,7 @@ static int i2c_dw_pci_probe(struct pci_dev *pdev,
214 struct i2c_adapter *adap; 206 struct i2c_adapter *adap;
215 int r; 207 int r;
216 struct dw_pci_controller *controller; 208 struct dw_pci_controller *controller;
209 struct dw_scl_sda_cfg *cfg;
217 210
218 if (id->driver_data >= ARRAY_SIZE(dw_pci_controllers)) { 211 if (id->driver_data >= ARRAY_SIZE(dw_pci_controllers)) {
219 dev_err(&pdev->dev, "%s: invalid driver data %ld\n", __func__, 212 dev_err(&pdev->dev, "%s: invalid driver data %ld\n", __func__,
@@ -247,13 +240,18 @@ static int i2c_dw_pci_probe(struct pci_dev *pdev,
247 dev->get_clk_rate_khz = i2c_dw_get_clk_rate_khz; 240 dev->get_clk_rate_khz = i2c_dw_get_clk_rate_khz;
248 dev->base = pcim_iomap_table(pdev)[0]; 241 dev->base = pcim_iomap_table(pdev)[0];
249 dev->dev = &pdev->dev; 242 dev->dev = &pdev->dev;
250 dev->functionality = 243 dev->functionality = controller->functionality |
251 I2C_FUNC_I2C | 244 DW_DEFAULT_FUNCTIONALITY;
252 I2C_FUNC_SMBUS_BYTE | 245
253 I2C_FUNC_SMBUS_BYTE_DATA |
254 I2C_FUNC_SMBUS_WORD_DATA |
255 I2C_FUNC_SMBUS_I2C_BLOCK;
256 dev->master_cfg = controller->bus_cfg; 246 dev->master_cfg = controller->bus_cfg;
247 if (controller->scl_sda_cfg) {
248 cfg = controller->scl_sda_cfg;
249 dev->ss_hcnt = cfg->ss_hcnt;
250 dev->fs_hcnt = cfg->fs_hcnt;
251 dev->ss_lcnt = cfg->ss_lcnt;
252 dev->fs_lcnt = cfg->fs_lcnt;
253 dev->sda_hold_time = cfg->sda_hold;
254 }
257 255
258 pci_set_drvdata(pdev, dev); 256 pci_set_drvdata(pdev, dev);
259 257
@@ -270,8 +268,8 @@ static int i2c_dw_pci_probe(struct pci_dev *pdev,
270 adap->algo = &i2c_dw_algo; 268 adap->algo = &i2c_dw_algo;
271 adap->dev.parent = &pdev->dev; 269 adap->dev.parent = &pdev->dev;
272 adap->nr = controller->bus_num; 270 adap->nr = controller->bus_num;
273 snprintf(adap->name, sizeof(adap->name), "i2c-designware-pci-%d", 271
274 adap->nr); 272 snprintf(adap->name, sizeof(adap->name), "i2c-designware-pci");
275 273
276 r = devm_request_irq(&pdev->dev, pdev->irq, i2c_dw_isr, IRQF_SHARED, 274 r = devm_request_irq(&pdev->dev, pdev->irq, i2c_dw_isr, IRQF_SHARED,
277 adap->name, dev); 275 adap->name, dev);
@@ -290,6 +288,7 @@ static int i2c_dw_pci_probe(struct pci_dev *pdev,
290 288
291 pm_runtime_set_autosuspend_delay(&pdev->dev, 1000); 289 pm_runtime_set_autosuspend_delay(&pdev->dev, 1000);
292 pm_runtime_use_autosuspend(&pdev->dev); 290 pm_runtime_use_autosuspend(&pdev->dev);
291 pm_runtime_put_autosuspend(&pdev->dev);
293 pm_runtime_allow(&pdev->dev); 292 pm_runtime_allow(&pdev->dev);
294 293
295 return 0; 294 return 0;
@@ -309,7 +308,7 @@ static void i2c_dw_pci_remove(struct pci_dev *pdev)
309/* work with hotplug and coldplug */ 308/* work with hotplug and coldplug */
310MODULE_ALIAS("i2c_designware-pci"); 309MODULE_ALIAS("i2c_designware-pci");
311 310
312static DEFINE_PCI_DEVICE_TABLE(i2_designware_pci_ids) = { 311static const struct pci_device_id i2_designware_pci_ids[] = {
313 /* Moorestown */ 312 /* Moorestown */
314 { PCI_VDEVICE(INTEL, 0x0802), moorestown_0 }, 313 { PCI_VDEVICE(INTEL, 0x0802), moorestown_0 },
315 { PCI_VDEVICE(INTEL, 0x0803), moorestown_1 }, 314 { PCI_VDEVICE(INTEL, 0x0803), moorestown_1 },
@@ -321,6 +320,14 @@ static DEFINE_PCI_DEVICE_TABLE(i2_designware_pci_ids) = {
321 { PCI_VDEVICE(INTEL, 0x082C), medfield_0 }, 320 { PCI_VDEVICE(INTEL, 0x082C), medfield_0 },
322 { PCI_VDEVICE(INTEL, 0x082D), medfield_1 }, 321 { PCI_VDEVICE(INTEL, 0x082D), medfield_1 },
323 { PCI_VDEVICE(INTEL, 0x082E), medfield_2 }, 322 { PCI_VDEVICE(INTEL, 0x082E), medfield_2 },
323 /* Baytrail */
324 { PCI_VDEVICE(INTEL, 0x0F41), baytrail },
325 { PCI_VDEVICE(INTEL, 0x0F42), baytrail },
326 { PCI_VDEVICE(INTEL, 0x0F43), baytrail },
327 { PCI_VDEVICE(INTEL, 0x0F44), baytrail },
328 { PCI_VDEVICE(INTEL, 0x0F45), baytrail },
329 { PCI_VDEVICE(INTEL, 0x0F46), baytrail },
330 { PCI_VDEVICE(INTEL, 0x0F47), baytrail },
324 { 0,} 331 { 0,}
325}; 332};
326MODULE_DEVICE_TABLE(pci, i2_designware_pci_ids); 333MODULE_DEVICE_TABLE(pci, i2_designware_pci_ids);
diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c
index d0bdac0498ce..9c7802614342 100644
--- a/drivers/i2c/busses/i2c-designware-platdrv.c
+++ b/drivers/i2c/busses/i2c-designware-platdrv.c
@@ -159,6 +159,13 @@ static int dw_i2c_probe(struct platform_device *pdev)
159 "i2c-sda-hold-time-ns", &ht); 159 "i2c-sda-hold-time-ns", &ht);
160 dev->sda_hold_time = div_u64((u64)ic_clk * ht + 500000, 160 dev->sda_hold_time = div_u64((u64)ic_clk * ht + 500000,
161 1000000); 161 1000000);
162
163 of_property_read_u32(pdev->dev.of_node,
164 "i2c-sda-falling-time-ns",
165 &dev->sda_falling_time);
166 of_property_read_u32(pdev->dev.of_node,
167 "i2c-scl-falling-time-ns",
168 &dev->scl_falling_time);
162 } 169 }
163 170
164 dev->functionality = 171 dev->functionality =
@@ -195,7 +202,7 @@ static int dw_i2c_probe(struct platform_device *pdev)
195 adap = &dev->adapter; 202 adap = &dev->adapter;
196 i2c_set_adapdata(adap, dev); 203 i2c_set_adapdata(adap, dev);
197 adap->owner = THIS_MODULE; 204 adap->owner = THIS_MODULE;
198 adap->class = I2C_CLASS_HWMON; 205 adap->class = I2C_CLASS_HWMON | I2C_CLASS_DEPRECATED;
199 strlcpy(adap->name, "Synopsys DesignWare I2C adapter", 206 strlcpy(adap->name, "Synopsys DesignWare I2C adapter",
200 sizeof(adap->name)); 207 sizeof(adap->name));
201 adap->algo = &i2c_dw_algo; 208 adap->algo = &i2c_dw_algo;
diff --git a/drivers/i2c/busses/i2c-efm32.c b/drivers/i2c/busses/i2c-efm32.c
new file mode 100644
index 000000000000..777ed409a24a
--- /dev/null
+++ b/drivers/i2c/busses/i2c-efm32.c
@@ -0,0 +1,481 @@
1/*
2 * Copyright (C) 2014 Uwe Kleine-Koenig for Pengutronix
3 *
4 * This program is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU General Public License version 2 as published by the
6 * Free Software Foundation.
7 */
8#include <linux/module.h>
9#include <linux/platform_device.h>
10#include <linux/i2c.h>
11#include <linux/io.h>
12#include <linux/interrupt.h>
13#include <linux/err.h>
14#include <linux/clk.h>
15
16#define DRIVER_NAME "efm32-i2c"
17
18#define MASK_VAL(mask, val) ((val << __ffs(mask)) & mask)
19
20#define REG_CTRL 0x00
21#define REG_CTRL_EN 0x00001
22#define REG_CTRL_SLAVE 0x00002
23#define REG_CTRL_AUTOACK 0x00004
24#define REG_CTRL_AUTOSE 0x00008
25#define REG_CTRL_AUTOSN 0x00010
26#define REG_CTRL_ARBDIS 0x00020
27#define REG_CTRL_GCAMEN 0x00040
28#define REG_CTRL_CLHR__MASK 0x00300
29#define REG_CTRL_BITO__MASK 0x03000
30#define REG_CTRL_BITO_OFF 0x00000
31#define REG_CTRL_BITO_40PCC 0x01000
32#define REG_CTRL_BITO_80PCC 0x02000
33#define REG_CTRL_BITO_160PCC 0x03000
34#define REG_CTRL_GIBITO 0x08000
35#define REG_CTRL_CLTO__MASK 0x70000
36#define REG_CTRL_CLTO_OFF 0x00000
37
38#define REG_CMD 0x04
39#define REG_CMD_START 0x00001
40#define REG_CMD_STOP 0x00002
41#define REG_CMD_ACK 0x00004
42#define REG_CMD_NACK 0x00008
43#define REG_CMD_CONT 0x00010
44#define REG_CMD_ABORT 0x00020
45#define REG_CMD_CLEARTX 0x00040
46#define REG_CMD_CLEARPC 0x00080
47
48#define REG_STATE 0x08
49#define REG_STATE_BUSY 0x00001
50#define REG_STATE_MASTER 0x00002
51#define REG_STATE_TRANSMITTER 0x00004
52#define REG_STATE_NACKED 0x00008
53#define REG_STATE_BUSHOLD 0x00010
54#define REG_STATE_STATE__MASK 0x000e0
55#define REG_STATE_STATE_IDLE 0x00000
56#define REG_STATE_STATE_WAIT 0x00020
57#define REG_STATE_STATE_START 0x00040
58#define REG_STATE_STATE_ADDR 0x00060
59#define REG_STATE_STATE_ADDRACK 0x00080
60#define REG_STATE_STATE_DATA 0x000a0
61#define REG_STATE_STATE_DATAACK 0x000c0
62
63#define REG_STATUS 0x0c
64#define REG_STATUS_PSTART 0x00001
65#define REG_STATUS_PSTOP 0x00002
66#define REG_STATUS_PACK 0x00004
67#define REG_STATUS_PNACK 0x00008
68#define REG_STATUS_PCONT 0x00010
69#define REG_STATUS_PABORT 0x00020
70#define REG_STATUS_TXC 0x00040
71#define REG_STATUS_TXBL 0x00080
72#define REG_STATUS_RXDATAV 0x00100
73
74#define REG_CLKDIV 0x10
75#define REG_CLKDIV_DIV__MASK 0x001ff
76#define REG_CLKDIV_DIV(div) MASK_VAL(REG_CLKDIV_DIV__MASK, (div))
77
78#define REG_SADDR 0x14
79#define REG_SADDRMASK 0x18
80#define REG_RXDATA 0x1c
81#define REG_RXDATAP 0x20
82#define REG_TXDATA 0x24
83#define REG_IF 0x28
84#define REG_IF_START 0x00001
85#define REG_IF_RSTART 0x00002
86#define REG_IF_ADDR 0x00004
87#define REG_IF_TXC 0x00008
88#define REG_IF_TXBL 0x00010
89#define REG_IF_RXDATAV 0x00020
90#define REG_IF_ACK 0x00040
91#define REG_IF_NACK 0x00080
92#define REG_IF_MSTOP 0x00100
93#define REG_IF_ARBLOST 0x00200
94#define REG_IF_BUSERR 0x00400
95#define REG_IF_BUSHOLD 0x00800
96#define REG_IF_TXOF 0x01000
97#define REG_IF_RXUF 0x02000
98#define REG_IF_BITO 0x04000
99#define REG_IF_CLTO 0x08000
100#define REG_IF_SSTOP 0x10000
101
102#define REG_IFS 0x2c
103#define REG_IFC 0x30
104#define REG_IFC__MASK 0x1ffcf
105
106#define REG_IEN 0x34
107
108#define REG_ROUTE 0x38
109#define REG_ROUTE_SDAPEN 0x00001
110#define REG_ROUTE_SCLPEN 0x00002
111#define REG_ROUTE_LOCATION__MASK 0x00700
112#define REG_ROUTE_LOCATION(n) MASK_VAL(REG_ROUTE_LOCATION__MASK, (n))
113
114struct efm32_i2c_ddata {
115 struct i2c_adapter adapter;
116
117 struct clk *clk;
118 void __iomem *base;
119 unsigned int irq;
120 u8 location;
121 unsigned long frequency;
122
123 /* transfer data */
124 struct completion done;
125 struct i2c_msg *msgs;
126 size_t num_msgs;
127 size_t current_word, current_msg;
128 int retval;
129};
130
131static u32 efm32_i2c_read32(struct efm32_i2c_ddata *ddata, unsigned offset)
132{
133 return readl(ddata->base + offset);
134}
135
136static void efm32_i2c_write32(struct efm32_i2c_ddata *ddata,
137 unsigned offset, u32 value)
138{
139 writel(value, ddata->base + offset);
140}
141
142static void efm32_i2c_send_next_msg(struct efm32_i2c_ddata *ddata)
143{
144 struct i2c_msg *cur_msg = &ddata->msgs[ddata->current_msg];
145
146 efm32_i2c_write32(ddata, REG_CMD, REG_CMD_START);
147 efm32_i2c_write32(ddata, REG_TXDATA, cur_msg->addr << 1 |
148 (cur_msg->flags & I2C_M_RD ? 1 : 0));
149}
150
151static void efm32_i2c_send_next_byte(struct efm32_i2c_ddata *ddata)
152{
153 struct i2c_msg *cur_msg = &ddata->msgs[ddata->current_msg];
154
155 if (ddata->current_word >= cur_msg->len) {
156 /* cur_msg completely transferred */
157 ddata->current_word = 0;
158 ddata->current_msg += 1;
159
160 if (ddata->current_msg >= ddata->num_msgs) {
161 efm32_i2c_write32(ddata, REG_CMD, REG_CMD_STOP);
162 complete(&ddata->done);
163 } else {
164 efm32_i2c_send_next_msg(ddata);
165 }
166 } else {
167 efm32_i2c_write32(ddata, REG_TXDATA,
168 cur_msg->buf[ddata->current_word++]);
169 }
170}
171
172static void efm32_i2c_recv_next_byte(struct efm32_i2c_ddata *ddata)
173{
174 struct i2c_msg *cur_msg = &ddata->msgs[ddata->current_msg];
175
176 cur_msg->buf[ddata->current_word] = efm32_i2c_read32(ddata, REG_RXDATA);
177 ddata->current_word += 1;
178 if (ddata->current_word >= cur_msg->len) {
179 /* cur_msg completely transferred */
180 ddata->current_word = 0;
181 ddata->current_msg += 1;
182
183 efm32_i2c_write32(ddata, REG_CMD, REG_CMD_NACK);
184
185 if (ddata->current_msg >= ddata->num_msgs) {
186 efm32_i2c_write32(ddata, REG_CMD, REG_CMD_STOP);
187 complete(&ddata->done);
188 } else {
189 efm32_i2c_send_next_msg(ddata);
190 }
191 } else {
192 efm32_i2c_write32(ddata, REG_CMD, REG_CMD_ACK);
193 }
194}
195
196static irqreturn_t efm32_i2c_irq(int irq, void *dev_id)
197{
198 struct efm32_i2c_ddata *ddata = dev_id;
199 struct i2c_msg *cur_msg = &ddata->msgs[ddata->current_msg];
200 u32 irqflag = efm32_i2c_read32(ddata, REG_IF);
201 u32 state = efm32_i2c_read32(ddata, REG_STATE);
202
203 efm32_i2c_write32(ddata, REG_IFC, irqflag & REG_IFC__MASK);
204
205 switch (state & REG_STATE_STATE__MASK) {
206 case REG_STATE_STATE_IDLE:
207 /* arbitration lost? */
208 ddata->retval = -EAGAIN;
209 complete(&ddata->done);
210 break;
211 case REG_STATE_STATE_WAIT:
212 /*
213 * huh, this shouldn't happen.
214 * Reset hardware state and get out
215 */
216 ddata->retval = -EIO;
217 efm32_i2c_write32(ddata, REG_CMD,
218 REG_CMD_STOP | REG_CMD_ABORT |
219 REG_CMD_CLEARTX | REG_CMD_CLEARPC);
220 complete(&ddata->done);
221 break;
222 case REG_STATE_STATE_START:
223 /* "caller" is expected to send an address */
224 break;
225 case REG_STATE_STATE_ADDR:
226 /* wait for Ack or NAck of slave */
227 break;
228 case REG_STATE_STATE_ADDRACK:
229 if (state & REG_STATE_NACKED) {
230 efm32_i2c_write32(ddata, REG_CMD, REG_CMD_STOP);
231 ddata->retval = -ENXIO;
232 complete(&ddata->done);
233 } else if (cur_msg->flags & I2C_M_RD) {
234 /* wait for slave to send first data byte */
235 } else {
236 efm32_i2c_send_next_byte(ddata);
237 }
238 break;
239 case REG_STATE_STATE_DATA:
240 if (cur_msg->flags & I2C_M_RD) {
241 efm32_i2c_recv_next_byte(ddata);
242 } else {
243 /* wait for Ack or Nack of slave */
244 }
245 break;
246 case REG_STATE_STATE_DATAACK:
247 if (state & REG_STATE_NACKED) {
248 efm32_i2c_write32(ddata, REG_CMD, REG_CMD_STOP);
249 complete(&ddata->done);
250 } else {
251 efm32_i2c_send_next_byte(ddata);
252 }
253 }
254
255 return IRQ_HANDLED;
256}
257
258static int efm32_i2c_master_xfer(struct i2c_adapter *adap,
259 struct i2c_msg *msgs, int num)
260{
261 struct efm32_i2c_ddata *ddata = i2c_get_adapdata(adap);
262 int ret;
263
264 if (ddata->msgs)
265 return -EBUSY;
266
267 ddata->msgs = msgs;
268 ddata->num_msgs = num;
269 ddata->current_word = 0;
270 ddata->current_msg = 0;
271 ddata->retval = -EIO;
272
273 reinit_completion(&ddata->done);
274
275 dev_dbg(&ddata->adapter.dev, "state: %08x, status: %08x\n",
276 efm32_i2c_read32(ddata, REG_STATE),
277 efm32_i2c_read32(ddata, REG_STATUS));
278
279 efm32_i2c_send_next_msg(ddata);
280
281 wait_for_completion(&ddata->done);
282
283 if (ddata->current_msg >= ddata->num_msgs)
284 ret = ddata->num_msgs;
285 else
286 ret = ddata->retval;
287
288 return ret;
289}
290
291static u32 efm32_i2c_functionality(struct i2c_adapter *adap)
292{
293 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
294}
295
296static const struct i2c_algorithm efm32_i2c_algo = {
297 .master_xfer = efm32_i2c_master_xfer,
298 .functionality = efm32_i2c_functionality,
299};
300
301static u32 efm32_i2c_get_configured_location(struct efm32_i2c_ddata *ddata)
302{
303 u32 reg = efm32_i2c_read32(ddata, REG_ROUTE);
304
305 return (reg & REG_ROUTE_LOCATION__MASK) >>
306 __ffs(REG_ROUTE_LOCATION__MASK);
307}
308
309static int efm32_i2c_probe(struct platform_device *pdev)
310{
311 struct efm32_i2c_ddata *ddata;
312 struct resource *res;
313 unsigned long rate;
314 struct device_node *np = pdev->dev.of_node;
315 u32 location, frequency;
316 int ret;
317 u32 clkdiv;
318
319 if (!np)
320 return -EINVAL;
321
322 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
323 if (!ddata) {
324 dev_dbg(&pdev->dev, "failed to allocate private data\n");
325 return -ENOMEM;
326 }
327 platform_set_drvdata(pdev, ddata);
328
329 init_completion(&ddata->done);
330 strlcpy(ddata->adapter.name, pdev->name, sizeof(ddata->adapter.name));
331 ddata->adapter.owner = THIS_MODULE;
332 ddata->adapter.algo = &efm32_i2c_algo;
333 ddata->adapter.dev.parent = &pdev->dev;
334 ddata->adapter.dev.of_node = pdev->dev.of_node;
335 i2c_set_adapdata(&ddata->adapter, ddata);
336
337 ddata->clk = devm_clk_get(&pdev->dev, NULL);
338 if (IS_ERR(ddata->clk)) {
339 ret = PTR_ERR(ddata->clk);
340 dev_err(&pdev->dev, "failed to get clock: %d\n", ret);
341 return ret;
342 }
343
344 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
345 if (!res) {
346 dev_err(&pdev->dev, "failed to determine base address\n");
347 return -ENODEV;
348 }
349
350 if (resource_size(res) < 0x42) {
351 dev_err(&pdev->dev, "memory resource too small\n");
352 return -EINVAL;
353 }
354
355 ddata->base = devm_ioremap_resource(&pdev->dev, res);
356 if (IS_ERR(ddata->base))
357 return PTR_ERR(ddata->base);
358
359 ret = platform_get_irq(pdev, 0);
360 if (ret <= 0) {
361 dev_err(&pdev->dev, "failed to get irq (%d)\n", ret);
362 if (!ret)
363 ret = -EINVAL;
364 return ret;
365 }
366
367 ddata->irq = ret;
368
369 ret = clk_prepare_enable(ddata->clk);
370 if (ret < 0) {
371 dev_err(&pdev->dev, "failed to enable clock (%d)\n", ret);
372 return ret;
373 }
374
375 ret = of_property_read_u32(np, "efm32,location", &location);
376 if (!ret) {
377 dev_dbg(&pdev->dev, "using location %u\n", location);
378 } else {
379 /* default to location configured in hardware */
380 location = efm32_i2c_get_configured_location(ddata);
381
382 dev_info(&pdev->dev, "fall back to location %u\n", location);
383 }
384
385 ddata->location = location;
386
387 ret = of_property_read_u32(np, "clock-frequency", &frequency);
388 if (!ret) {
389 dev_dbg(&pdev->dev, "using frequency %u\n", frequency);
390 } else {
391 frequency = 100000;
392 dev_info(&pdev->dev, "defaulting to 100 kHz\n");
393 }
394 ddata->frequency = frequency;
395
396 rate = clk_get_rate(ddata->clk);
397 if (!rate) {
398 dev_err(&pdev->dev, "there is no input clock available\n");
399 ret = -EINVAL;
400 goto err_disable_clk;
401 }
402 clkdiv = DIV_ROUND_UP(rate, 8 * ddata->frequency) - 1;
403 if (clkdiv >= 0x200) {
404 dev_err(&pdev->dev,
405 "input clock too fast (%lu) to divide down to bus freq (%lu)",
406 rate, ddata->frequency);
407 ret = -EINVAL;
408 goto err_disable_clk;
409 }
410
411 dev_dbg(&pdev->dev, "input clock = %lu, bus freq = %lu, clkdiv = %lu\n",
412 rate, ddata->frequency, (unsigned long)clkdiv);
413 efm32_i2c_write32(ddata, REG_CLKDIV, REG_CLKDIV_DIV(clkdiv));
414
415 efm32_i2c_write32(ddata, REG_ROUTE, REG_ROUTE_SDAPEN |
416 REG_ROUTE_SCLPEN |
417 REG_ROUTE_LOCATION(ddata->location));
418
419 efm32_i2c_write32(ddata, REG_CTRL, REG_CTRL_EN |
420 REG_CTRL_BITO_160PCC | 0 * REG_CTRL_GIBITO);
421
422 efm32_i2c_write32(ddata, REG_IFC, REG_IFC__MASK);
423 efm32_i2c_write32(ddata, REG_IEN, REG_IF_TXC | REG_IF_ACK | REG_IF_NACK
424 | REG_IF_ARBLOST | REG_IF_BUSERR | REG_IF_RXDATAV);
425
426 /* to make bus idle */
427 efm32_i2c_write32(ddata, REG_CMD, REG_CMD_ABORT);
428
429 ret = request_irq(ddata->irq, efm32_i2c_irq, 0, DRIVER_NAME, ddata);
430 if (ret < 0) {
431 dev_err(&pdev->dev, "failed to request irq (%d)\n", ret);
432 return ret;
433 }
434
435 ret = i2c_add_adapter(&ddata->adapter);
436 if (ret) {
437 dev_err(&pdev->dev, "failed to add i2c adapter (%d)\n", ret);
438 free_irq(ddata->irq, ddata);
439
440err_disable_clk:
441 clk_disable_unprepare(ddata->clk);
442 }
443 return ret;
444}
445
446static int efm32_i2c_remove(struct platform_device *pdev)
447{
448 struct efm32_i2c_ddata *ddata = platform_get_drvdata(pdev);
449
450 i2c_del_adapter(&ddata->adapter);
451 free_irq(ddata->irq, ddata);
452 clk_disable_unprepare(ddata->clk);
453
454 return 0;
455}
456
457static const struct of_device_id efm32_i2c_dt_ids[] = {
458 {
459 .compatible = "energymicro,efm32-i2c",
460 }, {
461 /* sentinel */
462 }
463};
464MODULE_DEVICE_TABLE(of, efm32_i2c_dt_ids);
465
466static struct platform_driver efm32_i2c_driver = {
467 .probe = efm32_i2c_probe,
468 .remove = efm32_i2c_remove,
469
470 .driver = {
471 .name = DRIVER_NAME,
472 .owner = THIS_MODULE,
473 .of_match_table = efm32_i2c_dt_ids,
474 },
475};
476module_platform_driver(efm32_i2c_driver);
477
478MODULE_AUTHOR("Uwe Kleine-Koenig <u.kleine-koenig@pengutronix.de>");
479MODULE_DESCRIPTION("EFM32 i2c driver");
480MODULE_LICENSE("GPL v2");
481MODULE_ALIAS("platform:" DRIVER_NAME);
diff --git a/drivers/i2c/busses/i2c-eg20t.c b/drivers/i2c/busses/i2c-eg20t.c
index e08e458bab02..ff775ac29e49 100644
--- a/drivers/i2c/busses/i2c-eg20t.c
+++ b/drivers/i2c/busses/i2c-eg20t.c
@@ -186,7 +186,7 @@ static DEFINE_MUTEX(pch_mutex);
186#define PCI_DEVICE_ID_ML7223_I2C 0x8010 186#define PCI_DEVICE_ID_ML7223_I2C 0x8010
187#define PCI_DEVICE_ID_ML7831_I2C 0x8817 187#define PCI_DEVICE_ID_ML7831_I2C 0x8817
188 188
189static DEFINE_PCI_DEVICE_TABLE(pch_pcidev_id) = { 189static const struct pci_device_id pch_pcidev_id[] = {
190 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_PCH_I2C), 1, }, 190 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_PCH_I2C), 1, },
191 { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ML7213_I2C), 2, }, 191 { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ML7213_I2C), 2, },
192 { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ML7223_I2C), 1, }, 192 { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ML7223_I2C), 1, },
diff --git a/drivers/i2c/busses/i2c-exynos5.c b/drivers/i2c/busses/i2c-exynos5.c
index 9fd711c03dd2..00af0a0a3361 100644
--- a/drivers/i2c/busses/i2c-exynos5.c
+++ b/drivers/i2c/busses/i2c-exynos5.c
@@ -566,7 +566,7 @@ static int exynos5_i2c_xfer_msg(struct exynos5_i2c *i2c,
566static int exynos5_i2c_xfer(struct i2c_adapter *adap, 566static int exynos5_i2c_xfer(struct i2c_adapter *adap,
567 struct i2c_msg *msgs, int num) 567 struct i2c_msg *msgs, int num)
568{ 568{
569 struct exynos5_i2c *i2c = (struct exynos5_i2c *)adap->algo_data; 569 struct exynos5_i2c *i2c = adap->algo_data;
570 int i = 0, ret = 0, stop = 0; 570 int i = 0, ret = 0, stop = 0;
571 571
572 if (i2c->suspended) { 572 if (i2c->suspended) {
@@ -715,6 +715,7 @@ static int exynos5_i2c_remove(struct platform_device *pdev)
715 return 0; 715 return 0;
716} 716}
717 717
718#ifdef CONFIG_PM_SLEEP
718static int exynos5_i2c_suspend_noirq(struct device *dev) 719static int exynos5_i2c_suspend_noirq(struct device *dev)
719{ 720{
720 struct platform_device *pdev = to_platform_device(dev); 721 struct platform_device *pdev = to_platform_device(dev);
@@ -745,6 +746,7 @@ static int exynos5_i2c_resume_noirq(struct device *dev)
745 746
746 return 0; 747 return 0;
747} 748}
749#endif
748 750
749static SIMPLE_DEV_PM_OPS(exynos5_i2c_dev_pm_ops, exynos5_i2c_suspend_noirq, 751static SIMPLE_DEV_PM_OPS(exynos5_i2c_dev_pm_ops, exynos5_i2c_suspend_noirq,
750 exynos5_i2c_resume_noirq); 752 exynos5_i2c_resume_noirq);
diff --git a/drivers/i2c/busses/i2c-gpio.c b/drivers/i2c/busses/i2c-gpio.c
index d9f7e186a4c7..02d2d4abb9dd 100644
--- a/drivers/i2c/busses/i2c-gpio.c
+++ b/drivers/i2c/busses/i2c-gpio.c
@@ -94,6 +94,9 @@ static int of_i2c_gpio_get_pins(struct device_node *np,
94 *sda_pin = of_get_gpio(np, 0); 94 *sda_pin = of_get_gpio(np, 0);
95 *scl_pin = of_get_gpio(np, 1); 95 *scl_pin = of_get_gpio(np, 1);
96 96
97 if (*sda_pin == -EPROBE_DEFER || *scl_pin == -EPROBE_DEFER)
98 return -EPROBE_DEFER;
99
97 if (!gpio_is_valid(*sda_pin) || !gpio_is_valid(*scl_pin)) { 100 if (!gpio_is_valid(*sda_pin) || !gpio_is_valid(*scl_pin)) {
98 pr_err("%s: invalid GPIO pins, sda=%d/scl=%d\n", 101 pr_err("%s: invalid GPIO pins, sda=%d/scl=%d\n",
99 np->full_name, *sda_pin, *scl_pin); 102 np->full_name, *sda_pin, *scl_pin);
diff --git a/drivers/i2c/busses/i2c-hydra.c b/drivers/i2c/busses/i2c-hydra.c
index e248257fe517..14d2b76de25f 100644
--- a/drivers/i2c/busses/i2c-hydra.c
+++ b/drivers/i2c/busses/i2c-hydra.c
@@ -104,7 +104,7 @@ static struct i2c_adapter hydra_adap = {
104 .algo_data = &hydra_bit_data, 104 .algo_data = &hydra_bit_data,
105}; 105};
106 106
107static DEFINE_PCI_DEVICE_TABLE(hydra_ids) = { 107static const struct pci_device_id hydra_ids[] = {
108 { PCI_DEVICE(PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_HYDRA) }, 108 { PCI_DEVICE(PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_HYDRA) },
109 { 0, } 109 { 0, }
110}; 110};
diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index 349c2d35e792..6777cd6f8776 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -60,6 +60,7 @@
60 Wellsburg (PCH) MS 0x8d7f 32 hard yes yes yes 60 Wellsburg (PCH) MS 0x8d7f 32 hard yes yes yes
61 Coleto Creek (PCH) 0x23b0 32 hard yes yes yes 61 Coleto Creek (PCH) 0x23b0 32 hard yes yes yes
62 Wildcat Point-LP (PCH) 0x9ca2 32 hard yes yes yes 62 Wildcat Point-LP (PCH) 0x9ca2 32 hard yes yes yes
63 BayTrail (SOC) 0x0f12 32 hard yes yes yes
63 64
64 Features supported by this driver: 65 Features supported by this driver:
65 Software PEC no 66 Software PEC no
@@ -161,6 +162,7 @@
161 STATUS_ERROR_FLAGS) 162 STATUS_ERROR_FLAGS)
162 163
163/* Older devices have their ID defined in <linux/pci_ids.h> */ 164/* Older devices have their ID defined in <linux/pci_ids.h> */
165#define PCI_DEVICE_ID_INTEL_BAYTRAIL_SMBUS 0x0f12
164#define PCI_DEVICE_ID_INTEL_COUGARPOINT_SMBUS 0x1c22 166#define PCI_DEVICE_ID_INTEL_COUGARPOINT_SMBUS 0x1c22
165#define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS 0x1d22 167#define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS 0x1d22
166/* Patsburg also has three 'Integrated Device Function' SMBus controllers */ 168/* Patsburg also has three 'Integrated Device Function' SMBus controllers */
@@ -789,7 +791,7 @@ static const struct i2c_algorithm smbus_algorithm = {
789 .functionality = i801_func, 791 .functionality = i801_func,
790}; 792};
791 793
792static DEFINE_PCI_DEVICE_TABLE(i801_ids) = { 794static const struct pci_device_id i801_ids[] = {
793 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_3) }, 795 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_3) },
794 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_3) }, 796 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_3) },
795 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_2) }, 797 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_2) },
@@ -822,6 +824,7 @@ static DEFINE_PCI_DEVICE_TABLE(i801_ids) = {
822 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS2) }, 824 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS2) },
823 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_COLETOCREEK_SMBUS) }, 825 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_COLETOCREEK_SMBUS) },
824 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WILDCATPOINT_LP_SMBUS) }, 826 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WILDCATPOINT_LP_SMBUS) },
827 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BAYTRAIL_SMBUS) },
825 { 0, } 828 { 0, }
826}; 829};
827 830
diff --git a/drivers/i2c/busses/i2c-ismt.c b/drivers/i2c/busses/i2c-ismt.c
index 8ce4f517fc56..984492553e95 100644
--- a/drivers/i2c/busses/i2c-ismt.c
+++ b/drivers/i2c/busses/i2c-ismt.c
@@ -182,7 +182,7 @@ struct ismt_priv {
182/** 182/**
183 * ismt_ids - PCI device IDs supported by this driver 183 * ismt_ids - PCI device IDs supported by this driver
184 */ 184 */
185static DEFINE_PCI_DEVICE_TABLE(ismt_ids) = { 185static const struct pci_device_id ismt_ids[] = {
186 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_S1200_SMT0) }, 186 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_S1200_SMT0) },
187 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_S1200_SMT1) }, 187 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_S1200_SMT1) },
188 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_AVOTON_SMT) }, 188 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_AVOTON_SMT) },
diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c
index d52d84937ad3..540ea692bf79 100644
--- a/drivers/i2c/busses/i2c-mv64xxx.c
+++ b/drivers/i2c/busses/i2c-mv64xxx.c
@@ -17,6 +17,7 @@
17#include <linux/interrupt.h> 17#include <linux/interrupt.h>
18#include <linux/mv643xx_i2c.h> 18#include <linux/mv643xx_i2c.h>
19#include <linux/platform_device.h> 19#include <linux/platform_device.h>
20#include <linux/reset.h>
20#include <linux/io.h> 21#include <linux/io.h>
21#include <linux/of.h> 22#include <linux/of.h>
22#include <linux/of_device.h> 23#include <linux/of_device.h>
@@ -97,7 +98,6 @@ enum {
97enum { 98enum {
98 MV64XXX_I2C_ACTION_INVALID, 99 MV64XXX_I2C_ACTION_INVALID,
99 MV64XXX_I2C_ACTION_CONTINUE, 100 MV64XXX_I2C_ACTION_CONTINUE,
100 MV64XXX_I2C_ACTION_SEND_START,
101 MV64XXX_I2C_ACTION_SEND_RESTART, 101 MV64XXX_I2C_ACTION_SEND_RESTART,
102 MV64XXX_I2C_ACTION_OFFLOAD_RESTART, 102 MV64XXX_I2C_ACTION_OFFLOAD_RESTART,
103 MV64XXX_I2C_ACTION_SEND_ADDR_1, 103 MV64XXX_I2C_ACTION_SEND_ADDR_1,
@@ -148,6 +148,8 @@ struct mv64xxx_i2c_data {
148 bool offload_enabled; 148 bool offload_enabled;
149/* 5us delay in order to avoid repeated start timing violation */ 149/* 5us delay in order to avoid repeated start timing violation */
150 bool errata_delay; 150 bool errata_delay;
151 struct reset_control *rstc;
152 bool irq_clear_inverted;
151}; 153};
152 154
153static struct mv64xxx_i2c_regs mv64xxx_i2c_regs_mv64xxx = { 155static struct mv64xxx_i2c_regs mv64xxx_i2c_regs_mv64xxx = {
@@ -176,11 +178,6 @@ mv64xxx_i2c_prepare_for_io(struct mv64xxx_i2c_data *drv_data,
176{ 178{
177 u32 dir = 0; 179 u32 dir = 0;
178 180
179 drv_data->msg = msg;
180 drv_data->byte_posn = 0;
181 drv_data->bytes_left = msg->len;
182 drv_data->aborting = 0;
183 drv_data->rc = 0;
184 drv_data->cntl_bits = MV64XXX_I2C_REG_CONTROL_ACK | 181 drv_data->cntl_bits = MV64XXX_I2C_REG_CONTROL_ACK |
185 MV64XXX_I2C_REG_CONTROL_INTEN | MV64XXX_I2C_REG_CONTROL_TWSIEN; 182 MV64XXX_I2C_REG_CONTROL_INTEN | MV64XXX_I2C_REG_CONTROL_TWSIEN;
186 183
@@ -206,11 +203,6 @@ static int mv64xxx_i2c_offload_msg(struct mv64xxx_i2c_data *drv_data)
206 if (!drv_data->offload_enabled) 203 if (!drv_data->offload_enabled)
207 return -EOPNOTSUPP; 204 return -EOPNOTSUPP;
208 205
209 drv_data->msg = msg;
210 drv_data->byte_posn = 0;
211 drv_data->bytes_left = msg->len;
212 drv_data->aborting = 0;
213 drv_data->rc = 0;
214 /* Only regular transactions can be offloaded */ 206 /* Only regular transactions can be offloaded */
215 if ((msg->flags & ~(I2C_M_TEN | I2C_M_RD)) != 0) 207 if ((msg->flags & ~(I2C_M_TEN | I2C_M_RD)) != 0)
216 return -EINVAL; 208 return -EINVAL;
@@ -419,6 +411,23 @@ mv64xxx_i2c_fsm(struct mv64xxx_i2c_data *drv_data, u32 status)
419 } 411 }
420} 412}
421 413
414static void mv64xxx_i2c_send_start(struct mv64xxx_i2c_data *drv_data)
415{
416 drv_data->msg = drv_data->msgs;
417 drv_data->byte_posn = 0;
418 drv_data->bytes_left = drv_data->msg->len;
419 drv_data->aborting = 0;
420 drv_data->rc = 0;
421
422 /* Can we offload this msg ? */
423 if (mv64xxx_i2c_offload_msg(drv_data) < 0) {
424 /* No, switch to standard path */
425 mv64xxx_i2c_prepare_for_io(drv_data, drv_data->msgs);
426 writel(drv_data->cntl_bits | MV64XXX_I2C_REG_CONTROL_START,
427 drv_data->reg_base + drv_data->reg_offsets.control);
428 }
429}
430
422static void 431static void
423mv64xxx_i2c_do_action(struct mv64xxx_i2c_data *drv_data) 432mv64xxx_i2c_do_action(struct mv64xxx_i2c_data *drv_data)
424{ 433{
@@ -435,14 +444,8 @@ mv64xxx_i2c_do_action(struct mv64xxx_i2c_data *drv_data)
435 444
436 drv_data->msgs++; 445 drv_data->msgs++;
437 drv_data->num_msgs--; 446 drv_data->num_msgs--;
438 if (mv64xxx_i2c_offload_msg(drv_data) < 0) { 447 mv64xxx_i2c_send_start(drv_data);
439 drv_data->cntl_bits |= MV64XXX_I2C_REG_CONTROL_START;
440 writel(drv_data->cntl_bits,
441 drv_data->reg_base + drv_data->reg_offsets.control);
442 448
443 /* Setup for the next message */
444 mv64xxx_i2c_prepare_for_io(drv_data, drv_data->msgs);
445 }
446 if (drv_data->errata_delay) 449 if (drv_data->errata_delay)
447 udelay(5); 450 udelay(5);
448 451
@@ -459,16 +462,6 @@ mv64xxx_i2c_do_action(struct mv64xxx_i2c_data *drv_data)
459 drv_data->reg_base + drv_data->reg_offsets.control); 462 drv_data->reg_base + drv_data->reg_offsets.control);
460 break; 463 break;
461 464
462 case MV64XXX_I2C_ACTION_SEND_START:
463 /* Can we offload this msg ? */
464 if (mv64xxx_i2c_offload_msg(drv_data) < 0) {
465 /* No, switch to standard path */
466 mv64xxx_i2c_prepare_for_io(drv_data, drv_data->msgs);
467 writel(drv_data->cntl_bits | MV64XXX_I2C_REG_CONTROL_START,
468 drv_data->reg_base + drv_data->reg_offsets.control);
469 }
470 break;
471
472 case MV64XXX_I2C_ACTION_SEND_ADDR_1: 465 case MV64XXX_I2C_ACTION_SEND_ADDR_1:
473 writel(drv_data->addr1, 466 writel(drv_data->addr1,
474 drv_data->reg_base + drv_data->reg_offsets.data); 467 drv_data->reg_base + drv_data->reg_offsets.data);
@@ -566,6 +559,11 @@ mv64xxx_i2c_intr(int irq, void *dev_id)
566 status = readl(drv_data->reg_base + drv_data->reg_offsets.status); 559 status = readl(drv_data->reg_base + drv_data->reg_offsets.status);
567 mv64xxx_i2c_fsm(drv_data, status); 560 mv64xxx_i2c_fsm(drv_data, status);
568 mv64xxx_i2c_do_action(drv_data); 561 mv64xxx_i2c_do_action(drv_data);
562
563 if (drv_data->irq_clear_inverted)
564 writel(drv_data->cntl_bits | MV64XXX_I2C_REG_CONTROL_IFLG,
565 drv_data->reg_base + drv_data->reg_offsets.control);
566
569 rc = IRQ_HANDLED; 567 rc = IRQ_HANDLED;
570 } 568 }
571 spin_unlock_irqrestore(&drv_data->lock, flags); 569 spin_unlock_irqrestore(&drv_data->lock, flags);
@@ -626,12 +624,11 @@ mv64xxx_i2c_execute_msg(struct mv64xxx_i2c_data *drv_data, struct i2c_msg *msg,
626 624
627 spin_lock_irqsave(&drv_data->lock, flags); 625 spin_lock_irqsave(&drv_data->lock, flags);
628 626
629 drv_data->action = MV64XXX_I2C_ACTION_SEND_START;
630 drv_data->state = MV64XXX_I2C_STATE_WAITING_FOR_START_COND; 627 drv_data->state = MV64XXX_I2C_STATE_WAITING_FOR_START_COND;
631 628
632 drv_data->send_stop = is_last; 629 drv_data->send_stop = is_last;
633 drv_data->block = 1; 630 drv_data->block = 1;
634 mv64xxx_i2c_do_action(drv_data); 631 mv64xxx_i2c_send_start(drv_data);
635 spin_unlock_irqrestore(&drv_data->lock, flags); 632 spin_unlock_irqrestore(&drv_data->lock, flags);
636 633
637 mv64xxx_i2c_wait_for_completion(drv_data); 634 mv64xxx_i2c_wait_for_completion(drv_data);
@@ -685,6 +682,7 @@ static const struct i2c_algorithm mv64xxx_i2c_algo = {
685 */ 682 */
686static const struct of_device_id mv64xxx_i2c_of_match_table[] = { 683static const struct of_device_id mv64xxx_i2c_of_match_table[] = {
687 { .compatible = "allwinner,sun4i-i2c", .data = &mv64xxx_i2c_regs_sun4i}, 684 { .compatible = "allwinner,sun4i-i2c", .data = &mv64xxx_i2c_regs_sun4i},
685 { .compatible = "allwinner,sun6i-a31-i2c", .data = &mv64xxx_i2c_regs_sun4i},
688 { .compatible = "marvell,mv64xxx-i2c", .data = &mv64xxx_i2c_regs_mv64xxx}, 686 { .compatible = "marvell,mv64xxx-i2c", .data = &mv64xxx_i2c_regs_mv64xxx},
689 { .compatible = "marvell,mv78230-i2c", .data = &mv64xxx_i2c_regs_mv64xxx}, 687 { .compatible = "marvell,mv78230-i2c", .data = &mv64xxx_i2c_regs_mv64xxx},
690 { .compatible = "marvell,mv78230-a0-i2c", .data = &mv64xxx_i2c_regs_mv64xxx}, 688 { .compatible = "marvell,mv78230-a0-i2c", .data = &mv64xxx_i2c_regs_mv64xxx},
@@ -759,6 +757,16 @@ mv64xxx_of_config(struct mv64xxx_i2c_data *drv_data,
759 } 757 }
760 drv_data->irq = irq_of_parse_and_map(np, 0); 758 drv_data->irq = irq_of_parse_and_map(np, 0);
761 759
760 drv_data->rstc = devm_reset_control_get_optional(dev, NULL);
761 if (IS_ERR(drv_data->rstc)) {
762 if (PTR_ERR(drv_data->rstc) == -EPROBE_DEFER) {
763 rc = -EPROBE_DEFER;
764 goto out;
765 }
766 } else {
767 reset_control_deassert(drv_data->rstc);
768 }
769
762 /* Its not yet defined how timeouts will be specified in device tree. 770 /* Its not yet defined how timeouts will be specified in device tree.
763 * So hard code the value to 1 second. 771 * So hard code the value to 1 second.
764 */ 772 */
@@ -783,6 +791,10 @@ mv64xxx_of_config(struct mv64xxx_i2c_data *drv_data,
783 drv_data->offload_enabled = false; 791 drv_data->offload_enabled = false;
784 drv_data->errata_delay = true; 792 drv_data->errata_delay = true;
785 } 793 }
794
795 if (of_device_is_compatible(np, "allwinner,sun6i-a31-i2c"))
796 drv_data->irq_clear_inverted = true;
797
786out: 798out:
787 return rc; 799 return rc;
788#endif 800#endif
@@ -845,13 +857,13 @@ mv64xxx_i2c_probe(struct platform_device *pd)
845 } 857 }
846 if (drv_data->irq < 0) { 858 if (drv_data->irq < 0) {
847 rc = -ENXIO; 859 rc = -ENXIO;
848 goto exit_clk; 860 goto exit_reset;
849 } 861 }
850 862
851 drv_data->adapter.dev.parent = &pd->dev; 863 drv_data->adapter.dev.parent = &pd->dev;
852 drv_data->adapter.algo = &mv64xxx_i2c_algo; 864 drv_data->adapter.algo = &mv64xxx_i2c_algo;
853 drv_data->adapter.owner = THIS_MODULE; 865 drv_data->adapter.owner = THIS_MODULE;
854 drv_data->adapter.class = I2C_CLASS_HWMON | I2C_CLASS_SPD; 866 drv_data->adapter.class = I2C_CLASS_HWMON | I2C_CLASS_SPD | I2C_CLASS_DEPRECATED;
855 drv_data->adapter.nr = pd->id; 867 drv_data->adapter.nr = pd->id;
856 drv_data->adapter.dev.of_node = pd->dev.of_node; 868 drv_data->adapter.dev.of_node = pd->dev.of_node;
857 platform_set_drvdata(pd, drv_data); 869 platform_set_drvdata(pd, drv_data);
@@ -865,7 +877,7 @@ mv64xxx_i2c_probe(struct platform_device *pd)
865 dev_err(&drv_data->adapter.dev, 877 dev_err(&drv_data->adapter.dev,
866 "mv64xxx: Can't register intr handler irq%d: %d\n", 878 "mv64xxx: Can't register intr handler irq%d: %d\n",
867 drv_data->irq, rc); 879 drv_data->irq, rc);
868 goto exit_clk; 880 goto exit_reset;
869 } else if ((rc = i2c_add_numbered_adapter(&drv_data->adapter)) != 0) { 881 } else if ((rc = i2c_add_numbered_adapter(&drv_data->adapter)) != 0) {
870 dev_err(&drv_data->adapter.dev, 882 dev_err(&drv_data->adapter.dev,
871 "mv64xxx: Can't add i2c adapter, rc: %d\n", -rc); 883 "mv64xxx: Can't add i2c adapter, rc: %d\n", -rc);
@@ -876,6 +888,9 @@ mv64xxx_i2c_probe(struct platform_device *pd)
876 888
877exit_free_irq: 889exit_free_irq:
878 free_irq(drv_data->irq, drv_data); 890 free_irq(drv_data->irq, drv_data);
891exit_reset:
892 if (!IS_ERR_OR_NULL(drv_data->rstc))
893 reset_control_assert(drv_data->rstc);
879exit_clk: 894exit_clk:
880#if defined(CONFIG_HAVE_CLK) 895#if defined(CONFIG_HAVE_CLK)
881 /* Not all platforms have a clk */ 896 /* Not all platforms have a clk */
@@ -894,6 +909,8 @@ mv64xxx_i2c_remove(struct platform_device *dev)
894 909
895 i2c_del_adapter(&drv_data->adapter); 910 i2c_del_adapter(&drv_data->adapter);
896 free_irq(drv_data->irq, drv_data); 911 free_irq(drv_data->irq, drv_data);
912 if (!IS_ERR_OR_NULL(drv_data->rstc))
913 reset_control_assert(drv_data->rstc);
897#if defined(CONFIG_HAVE_CLK) 914#if defined(CONFIG_HAVE_CLK)
898 /* Not all platforms have a clk */ 915 /* Not all platforms have a clk */
899 if (!IS_ERR(drv_data->clk)) { 916 if (!IS_ERR(drv_data->clk)) {
diff --git a/drivers/i2c/busses/i2c-mxs.c b/drivers/i2c/busses/i2c-mxs.c
index 0cde4e6ab2b2..7170fc892829 100644
--- a/drivers/i2c/busses/i2c-mxs.c
+++ b/drivers/i2c/busses/i2c-mxs.c
@@ -806,7 +806,6 @@ static int mxs_i2c_probe(struct platform_device *pdev)
806 struct mxs_i2c_dev *i2c; 806 struct mxs_i2c_dev *i2c;
807 struct i2c_adapter *adap; 807 struct i2c_adapter *adap;
808 struct resource *res; 808 struct resource *res;
809 resource_size_t res_size;
810 int err, irq; 809 int err, irq;
811 810
812 i2c = devm_kzalloc(dev, sizeof(struct mxs_i2c_dev), GFP_KERNEL); 811 i2c = devm_kzalloc(dev, sizeof(struct mxs_i2c_dev), GFP_KERNEL);
@@ -819,18 +818,13 @@ static int mxs_i2c_probe(struct platform_device *pdev)
819 } 818 }
820 819
821 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 820 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
822 irq = platform_get_irq(pdev, 0); 821 i2c->regs = devm_ioremap_resource(&pdev->dev, res);
823 822 if (IS_ERR(i2c->regs))
824 if (!res || irq < 0) 823 return PTR_ERR(i2c->regs);
825 return -ENOENT;
826 824
827 res_size = resource_size(res); 825 irq = platform_get_irq(pdev, 0);
828 if (!devm_request_mem_region(dev, res->start, res_size, res->name)) 826 if (irq < 0)
829 return -EBUSY; 827 return irq;
830
831 i2c->regs = devm_ioremap_nocache(dev, res->start, res_size);
832 if (!i2c->regs)
833 return -EBUSY;
834 828
835 err = devm_request_irq(dev, irq, mxs_i2c_isr, 0, dev_name(dev), i2c); 829 err = devm_request_irq(dev, irq, mxs_i2c_isr, 0, dev_name(dev), i2c);
836 if (err) 830 if (err)
diff --git a/drivers/i2c/busses/i2c-nforce2.c b/drivers/i2c/busses/i2c-nforce2.c
index 0038c451095c..ee3a76c7ae97 100644
--- a/drivers/i2c/busses/i2c-nforce2.c
+++ b/drivers/i2c/busses/i2c-nforce2.c
@@ -306,7 +306,7 @@ static struct i2c_algorithm smbus_algorithm = {
306}; 306};
307 307
308 308
309static DEFINE_PCI_DEVICE_TABLE(nforce2_ids) = { 309static const struct pci_device_id nforce2_ids[] = {
310 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2_SMBUS) }, 310 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2_SMBUS) },
311 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2S_SMBUS) }, 311 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2S_SMBUS) },
312 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3_SMBUS) }, 312 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3_SMBUS) },
diff --git a/drivers/i2c/busses/i2c-nomadik.c b/drivers/i2c/busses/i2c-nomadik.c
index 4443613514ee..28cbe1b2a2ec 100644
--- a/drivers/i2c/busses/i2c-nomadik.c
+++ b/drivers/i2c/busses/i2c-nomadik.c
@@ -111,22 +111,6 @@ enum i2c_freq_mode {
111}; 111};
112 112
113/** 113/**
114 * struct nmk_i2c_controller - client specific controller configuration
115 * @clk_freq: clock frequency for the operation mode
116 * @tft: Tx FIFO Threshold in bytes
117 * @rft: Rx FIFO Threshold in bytes
118 * @timeout Slave response timeout(ms)
119 * @sm: speed mode
120 */
121struct nmk_i2c_controller {
122 u32 clk_freq;
123 unsigned char tft;
124 unsigned char rft;
125 int timeout;
126 enum i2c_freq_mode sm;
127};
128
129/**
130 * struct i2c_vendor_data - per-vendor variations 114 * struct i2c_vendor_data - per-vendor variations
131 * @has_mtdws: variant has the MTDWS bit 115 * @has_mtdws: variant has the MTDWS bit
132 * @fifodepth: variant FIFO depth 116 * @fifodepth: variant FIFO depth
@@ -174,12 +158,15 @@ struct i2c_nmk_client {
174 * @irq: interrupt line for the controller. 158 * @irq: interrupt line for the controller.
175 * @virtbase: virtual io memory area. 159 * @virtbase: virtual io memory area.
176 * @clk: hardware i2c block clock. 160 * @clk: hardware i2c block clock.
177 * @cfg: machine provided controller configuration.
178 * @cli: holder of client specific data. 161 * @cli: holder of client specific data.
162 * @clk_freq: clock frequency for the operation mode
163 * @tft: Tx FIFO Threshold in bytes
164 * @rft: Rx FIFO Threshold in bytes
165 * @timeout Slave response timeout (ms)
166 * @sm: speed mode
179 * @stop: stop condition. 167 * @stop: stop condition.
180 * @xfer_complete: acknowledge completion for a I2C message. 168 * @xfer_complete: acknowledge completion for a I2C message.
181 * @result: controller propogated result. 169 * @result: controller propogated result.
182 * @busy: Busy doing transfer.
183 */ 170 */
184struct nmk_i2c_dev { 171struct nmk_i2c_dev {
185 struct i2c_vendor_data *vendor; 172 struct i2c_vendor_data *vendor;
@@ -188,12 +175,15 @@ struct nmk_i2c_dev {
188 int irq; 175 int irq;
189 void __iomem *virtbase; 176 void __iomem *virtbase;
190 struct clk *clk; 177 struct clk *clk;
191 struct nmk_i2c_controller cfg;
192 struct i2c_nmk_client cli; 178 struct i2c_nmk_client cli;
179 u32 clk_freq;
180 unsigned char tft;
181 unsigned char rft;
182 int timeout;
183 enum i2c_freq_mode sm;
193 int stop; 184 int stop;
194 struct completion xfer_complete; 185 struct completion xfer_complete;
195 int result; 186 int result;
196 bool busy;
197}; 187};
198 188
199/* controller's abort causes */ 189/* controller's abort causes */
@@ -386,7 +376,7 @@ static void setup_i2c_controller(struct nmk_i2c_dev *dev)
386 * slsu = cycles / (1000000000 / f) + 1 376 * slsu = cycles / (1000000000 / f) + 1
387 */ 377 */
388 ns = DIV_ROUND_UP_ULL(1000000000ULL, i2c_clk); 378 ns = DIV_ROUND_UP_ULL(1000000000ULL, i2c_clk);
389 switch (dev->cfg.sm) { 379 switch (dev->sm) {
390 case I2C_FREQ_MODE_FAST: 380 case I2C_FREQ_MODE_FAST:
391 case I2C_FREQ_MODE_FAST_PLUS: 381 case I2C_FREQ_MODE_FAST_PLUS:
392 slsu = DIV_ROUND_UP(100, ns); /* Fast */ 382 slsu = DIV_ROUND_UP(100, ns); /* Fast */
@@ -409,7 +399,7 @@ static void setup_i2c_controller(struct nmk_i2c_dev *dev)
409 * 2 whereas it is 3 for fast and fastplus mode of 399 * 2 whereas it is 3 for fast and fastplus mode of
410 * operation. TODO - high speed support. 400 * operation. TODO - high speed support.
411 */ 401 */
412 div = (dev->cfg.clk_freq > 100000) ? 3 : 2; 402 div = (dev->clk_freq > 100000) ? 3 : 2;
413 403
414 /* 404 /*
415 * generate the mask for baud rate counters. The controller 405 * generate the mask for baud rate counters. The controller
@@ -419,7 +409,7 @@ static void setup_i2c_controller(struct nmk_i2c_dev *dev)
419 * so set brcr1 to 0. 409 * so set brcr1 to 0.
420 */ 410 */
421 brcr1 = 0 << 16; 411 brcr1 = 0 << 16;
422 brcr2 = (i2c_clk/(dev->cfg.clk_freq * div)) & 0xffff; 412 brcr2 = (i2c_clk/(dev->clk_freq * div)) & 0xffff;
423 413
424 /* set the baud rate counter register */ 414 /* set the baud rate counter register */
425 writel((brcr1 | brcr2), dev->virtbase + I2C_BRCR); 415 writel((brcr1 | brcr2), dev->virtbase + I2C_BRCR);
@@ -430,7 +420,7 @@ static void setup_i2c_controller(struct nmk_i2c_dev *dev)
430 * TODO - support for fast mode plus (up to 1Mb/s) 420 * TODO - support for fast mode plus (up to 1Mb/s)
431 * and high speed (up to 3.4 Mb/s) 421 * and high speed (up to 3.4 Mb/s)
432 */ 422 */
433 if (dev->cfg.sm > I2C_FREQ_MODE_FAST) { 423 if (dev->sm > I2C_FREQ_MODE_FAST) {
434 dev_err(&dev->adev->dev, 424 dev_err(&dev->adev->dev,
435 "do not support this mode defaulting to std. mode\n"); 425 "do not support this mode defaulting to std. mode\n");
436 brcr2 = i2c_clk/(100000 * 2) & 0xffff; 426 brcr2 = i2c_clk/(100000 * 2) & 0xffff;
@@ -438,11 +428,11 @@ static void setup_i2c_controller(struct nmk_i2c_dev *dev)
438 writel(I2C_FREQ_MODE_STANDARD << 4, 428 writel(I2C_FREQ_MODE_STANDARD << 4,
439 dev->virtbase + I2C_CR); 429 dev->virtbase + I2C_CR);
440 } 430 }
441 writel(dev->cfg.sm << 4, dev->virtbase + I2C_CR); 431 writel(dev->sm << 4, dev->virtbase + I2C_CR);
442 432
443 /* set the Tx and Rx FIFO threshold */ 433 /* set the Tx and Rx FIFO threshold */
444 writel(dev->cfg.tft, dev->virtbase + I2C_TFTR); 434 writel(dev->tft, dev->virtbase + I2C_TFTR);
445 writel(dev->cfg.rft, dev->virtbase + I2C_RFTR); 435 writel(dev->rft, dev->virtbase + I2C_RFTR);
446} 436}
447 437
448/** 438/**
@@ -674,28 +664,13 @@ static int nmk_i2c_xfer_one(struct nmk_i2c_dev *dev, u16 flags)
674static int nmk_i2c_xfer(struct i2c_adapter *i2c_adap, 664static int nmk_i2c_xfer(struct i2c_adapter *i2c_adap,
675 struct i2c_msg msgs[], int num_msgs) 665 struct i2c_msg msgs[], int num_msgs)
676{ 666{
677 int status; 667 int status = 0;
678 int i; 668 int i;
679 struct nmk_i2c_dev *dev = i2c_get_adapdata(i2c_adap); 669 struct nmk_i2c_dev *dev = i2c_get_adapdata(i2c_adap);
680 int j; 670 int j;
681 671
682 dev->busy = true;
683
684 pm_runtime_get_sync(&dev->adev->dev); 672 pm_runtime_get_sync(&dev->adev->dev);
685 673
686 status = clk_prepare_enable(dev->clk);
687 if (status) {
688 dev_err(&dev->adev->dev, "can't prepare_enable clock\n");
689 goto out_clk;
690 }
691
692 /* Optionaly enable pins to be muxed in and configured */
693 pinctrl_pm_select_default_state(&dev->adev->dev);
694
695 status = init_hw(dev);
696 if (status)
697 goto out;
698
699 /* Attempt three times to send the message queue */ 674 /* Attempt three times to send the message queue */
700 for (j = 0; j < 3; j++) { 675 for (j = 0; j < 3; j++) {
701 /* setup the i2c controller */ 676 /* setup the i2c controller */
@@ -716,16 +691,8 @@ static int nmk_i2c_xfer(struct i2c_adapter *i2c_adap,
716 break; 691 break;
717 } 692 }
718 693
719out:
720 clk_disable_unprepare(dev->clk);
721out_clk:
722 /* Optionally let pins go into idle state */
723 pinctrl_pm_select_idle_state(&dev->adev->dev);
724
725 pm_runtime_put_sync(&dev->adev->dev); 694 pm_runtime_put_sync(&dev->adev->dev);
726 695
727 dev->busy = false;
728
729 /* return the no. messages processed */ 696 /* return the no. messages processed */
730 if (status) 697 if (status)
731 return status; 698 return status;
@@ -909,22 +876,15 @@ static irqreturn_t i2c_irq_handler(int irq, void *arg)
909 return IRQ_HANDLED; 876 return IRQ_HANDLED;
910} 877}
911 878
912 879#ifdef CONFIG_PM_SLEEP
913#ifdef CONFIG_PM 880static int nmk_i2c_suspend_late(struct device *dev)
914static int nmk_i2c_suspend(struct device *dev)
915{ 881{
916 struct amba_device *adev = to_amba_device(dev);
917 struct nmk_i2c_dev *nmk_i2c = amba_get_drvdata(adev);
918
919 if (nmk_i2c->busy)
920 return -EBUSY;
921
922 pinctrl_pm_select_sleep_state(dev); 882 pinctrl_pm_select_sleep_state(dev);
923 883
924 return 0; 884 return 0;
925} 885}
926 886
927static int nmk_i2c_resume(struct device *dev) 887static int nmk_i2c_resume_early(struct device *dev)
928{ 888{
929 /* First go to the default state */ 889 /* First go to the default state */
930 pinctrl_pm_select_default_state(dev); 890 pinctrl_pm_select_default_state(dev);
@@ -933,19 +893,48 @@ static int nmk_i2c_resume(struct device *dev)
933 893
934 return 0; 894 return 0;
935} 895}
936#else
937#define nmk_i2c_suspend NULL
938#define nmk_i2c_resume NULL
939#endif 896#endif
940 897
941/* 898#ifdef CONFIG_PM
942 * We use noirq so that we suspend late and resume before the wakeup interrupt 899static int nmk_i2c_runtime_suspend(struct device *dev)
943 * to ensure that we do the !pm_runtime_suspended() check in resume before 900{
944 * there has been a regular pm runtime resume (via pm_runtime_get_sync()). 901 struct amba_device *adev = to_amba_device(dev);
945 */ 902 struct nmk_i2c_dev *nmk_i2c = amba_get_drvdata(adev);
903
904 clk_disable_unprepare(nmk_i2c->clk);
905 pinctrl_pm_select_idle_state(dev);
906 return 0;
907}
908
909static int nmk_i2c_runtime_resume(struct device *dev)
910{
911 struct amba_device *adev = to_amba_device(dev);
912 struct nmk_i2c_dev *nmk_i2c = amba_get_drvdata(adev);
913 int ret;
914
915 ret = clk_prepare_enable(nmk_i2c->clk);
916 if (ret) {
917 dev_err(dev, "can't prepare_enable clock\n");
918 return ret;
919 }
920
921 pinctrl_pm_select_default_state(dev);
922
923 ret = init_hw(nmk_i2c);
924 if (ret) {
925 clk_disable_unprepare(nmk_i2c->clk);
926 pinctrl_pm_select_idle_state(dev);
927 }
928
929 return ret;
930}
931#endif
932
946static const struct dev_pm_ops nmk_i2c_pm = { 933static const struct dev_pm_ops nmk_i2c_pm = {
947 .suspend_noirq = nmk_i2c_suspend, 934 SET_LATE_SYSTEM_SLEEP_PM_OPS(nmk_i2c_suspend_late, nmk_i2c_resume_early)
948 .resume_noirq = nmk_i2c_resume, 935 SET_PM_RUNTIME_PM_OPS(nmk_i2c_runtime_suspend,
936 nmk_i2c_runtime_resume,
937 NULL)
949}; 938};
950 939
951static unsigned int nmk_i2c_functionality(struct i2c_adapter *adap) 940static unsigned int nmk_i2c_functionality(struct i2c_adapter *adap)
@@ -958,118 +947,98 @@ static const struct i2c_algorithm nmk_i2c_algo = {
958 .functionality = nmk_i2c_functionality 947 .functionality = nmk_i2c_functionality
959}; 948};
960 949
961static struct nmk_i2c_controller u8500_i2c = {
962 .tft = 1, /* Tx FIFO threshold */
963 .rft = 8, /* Rx FIFO threshold */
964 .clk_freq = 400000, /* fast mode operation */
965 .timeout = 200, /* Slave response timeout(ms) */
966 .sm = I2C_FREQ_MODE_FAST,
967};
968
969static void nmk_i2c_of_probe(struct device_node *np, 950static void nmk_i2c_of_probe(struct device_node *np,
970 struct nmk_i2c_controller *pdata) 951 struct nmk_i2c_dev *nmk)
971{ 952{
972 of_property_read_u32(np, "clock-frequency", &pdata->clk_freq); 953 /* Default to 100 kHz if no frequency is given in the node */
954 if (of_property_read_u32(np, "clock-frequency", &nmk->clk_freq))
955 nmk->clk_freq = 100000;
973 956
974 /* This driver only supports 'standard' and 'fast' modes of operation. */ 957 /* This driver only supports 'standard' and 'fast' modes of operation. */
975 if (pdata->clk_freq <= 100000) 958 if (nmk->clk_freq <= 100000)
976 pdata->sm = I2C_FREQ_MODE_STANDARD; 959 nmk->sm = I2C_FREQ_MODE_STANDARD;
977 else 960 else
978 pdata->sm = I2C_FREQ_MODE_FAST; 961 nmk->sm = I2C_FREQ_MODE_FAST;
962 nmk->tft = 1; /* Tx FIFO threshold */
963 nmk->rft = 8; /* Rx FIFO threshold */
964 nmk->timeout = 200; /* Slave response timeout(ms) */
979} 965}
980 966
981static int nmk_i2c_probe(struct amba_device *adev, const struct amba_id *id) 967static int nmk_i2c_probe(struct amba_device *adev, const struct amba_id *id)
982{ 968{
983 int ret = 0; 969 int ret = 0;
984 struct nmk_i2c_controller *pdata = dev_get_platdata(&adev->dev);
985 struct device_node *np = adev->dev.of_node; 970 struct device_node *np = adev->dev.of_node;
986 struct nmk_i2c_dev *dev; 971 struct nmk_i2c_dev *dev;
987 struct i2c_adapter *adap; 972 struct i2c_adapter *adap;
988 struct i2c_vendor_data *vendor = id->data; 973 struct i2c_vendor_data *vendor = id->data;
989 u32 max_fifo_threshold = (vendor->fifodepth / 2) - 1; 974 u32 max_fifo_threshold = (vendor->fifodepth / 2) - 1;
990 975
991 if (!pdata) { 976 dev = devm_kzalloc(&adev->dev, sizeof(struct nmk_i2c_dev), GFP_KERNEL);
992 if (np) { 977 if (!dev) {
993 pdata = devm_kzalloc(&adev->dev, sizeof(*pdata), GFP_KERNEL); 978 dev_err(&adev->dev, "cannot allocate memory\n");
994 if (!pdata) { 979 ret = -ENOMEM;
995 ret = -ENOMEM; 980 goto err_no_mem;
996 goto err_no_mem;
997 }
998 /* Provide the default configuration as a base. */
999 memcpy(pdata, &u8500_i2c, sizeof(struct nmk_i2c_controller));
1000 nmk_i2c_of_probe(np, pdata);
1001 } else
1002 /* No i2c configuration found, using the default. */
1003 pdata = &u8500_i2c;
1004 } 981 }
982 dev->vendor = vendor;
983 dev->adev = adev;
984 nmk_i2c_of_probe(np, dev);
1005 985
1006 if (pdata->tft > max_fifo_threshold) { 986 if (dev->tft > max_fifo_threshold) {
1007 dev_warn(&adev->dev, "requested TX FIFO threshold %u, adjusted down to %u\n", 987 dev_warn(&adev->dev, "requested TX FIFO threshold %u, adjusted down to %u\n",
1008 pdata->tft, max_fifo_threshold); 988 dev->tft, max_fifo_threshold);
1009 pdata->tft = max_fifo_threshold; 989 dev->tft = max_fifo_threshold;
1010 } 990 }
1011 991
1012 if (pdata->rft > max_fifo_threshold) { 992 if (dev->rft > max_fifo_threshold) {
1013 dev_warn(&adev->dev, "requested RX FIFO threshold %u, adjusted down to %u\n", 993 dev_warn(&adev->dev, "requested RX FIFO threshold %u, adjusted down to %u\n",
1014 pdata->rft, max_fifo_threshold); 994 dev->rft, max_fifo_threshold);
1015 pdata->rft = max_fifo_threshold; 995 dev->rft = max_fifo_threshold;
1016 } 996 }
1017 997
1018 dev = kzalloc(sizeof(struct nmk_i2c_dev), GFP_KERNEL);
1019 if (!dev) {
1020 dev_err(&adev->dev, "cannot allocate memory\n");
1021 ret = -ENOMEM;
1022 goto err_no_mem;
1023 }
1024 dev->vendor = vendor;
1025 dev->busy = false;
1026 dev->adev = adev;
1027 amba_set_drvdata(adev, dev); 998 amba_set_drvdata(adev, dev);
1028 999
1029 /* Select default pin state */ 1000 dev->virtbase = devm_ioremap(&adev->dev, adev->res.start,
1030 pinctrl_pm_select_default_state(&adev->dev); 1001 resource_size(&adev->res));
1031 /* If possible, let's go to idle until the first transfer */ 1002 if (IS_ERR(dev->virtbase)) {
1032 pinctrl_pm_select_idle_state(&adev->dev);
1033
1034 dev->virtbase = ioremap(adev->res.start, resource_size(&adev->res));
1035 if (!dev->virtbase) {
1036 ret = -ENOMEM; 1003 ret = -ENOMEM;
1037 goto err_no_ioremap; 1004 goto err_no_mem;
1038 } 1005 }
1039 1006
1040 dev->irq = adev->irq[0]; 1007 dev->irq = adev->irq[0];
1041 ret = request_irq(dev->irq, i2c_irq_handler, 0, 1008 ret = devm_request_irq(&adev->dev, dev->irq, i2c_irq_handler, 0,
1042 DRIVER_NAME, dev); 1009 DRIVER_NAME, dev);
1043 if (ret) { 1010 if (ret) {
1044 dev_err(&adev->dev, "cannot claim the irq %d\n", dev->irq); 1011 dev_err(&adev->dev, "cannot claim the irq %d\n", dev->irq);
1045 goto err_irq; 1012 goto err_no_mem;
1046 } 1013 }
1047 1014
1048 pm_suspend_ignore_children(&adev->dev, true); 1015 pm_suspend_ignore_children(&adev->dev, true);
1049 1016
1050 dev->clk = clk_get(&adev->dev, NULL); 1017 dev->clk = devm_clk_get(&adev->dev, NULL);
1051 if (IS_ERR(dev->clk)) { 1018 if (IS_ERR(dev->clk)) {
1052 dev_err(&adev->dev, "could not get i2c clock\n"); 1019 dev_err(&adev->dev, "could not get i2c clock\n");
1053 ret = PTR_ERR(dev->clk); 1020 ret = PTR_ERR(dev->clk);
1054 goto err_no_clk; 1021 goto err_no_mem;
1022 }
1023
1024 ret = clk_prepare_enable(dev->clk);
1025 if (ret) {
1026 dev_err(&adev->dev, "can't prepare_enable clock\n");
1027 goto err_no_mem;
1055 } 1028 }
1056 1029
1030 init_hw(dev);
1031
1057 adap = &dev->adap; 1032 adap = &dev->adap;
1058 adap->dev.of_node = np; 1033 adap->dev.of_node = np;
1059 adap->dev.parent = &adev->dev; 1034 adap->dev.parent = &adev->dev;
1060 adap->owner = THIS_MODULE; 1035 adap->owner = THIS_MODULE;
1061 adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD; 1036 adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD | I2C_CLASS_DEPRECATED;
1062 adap->algo = &nmk_i2c_algo; 1037 adap->algo = &nmk_i2c_algo;
1063 adap->timeout = msecs_to_jiffies(pdata->timeout); 1038 adap->timeout = msecs_to_jiffies(dev->timeout);
1064 snprintf(adap->name, sizeof(adap->name), 1039 snprintf(adap->name, sizeof(adap->name),
1065 "Nomadik I2C at %pR", &adev->res); 1040 "Nomadik I2C at %pR", &adev->res);
1066 1041
1067 /* fetch the controller configuration from machine */
1068 dev->cfg.clk_freq = pdata->clk_freq;
1069 dev->cfg.tft = pdata->tft;
1070 dev->cfg.rft = pdata->rft;
1071 dev->cfg.sm = pdata->sm;
1072
1073 i2c_set_adapdata(adap, dev); 1042 i2c_set_adapdata(adap, dev);
1074 1043
1075 dev_info(&adev->dev, 1044 dev_info(&adev->dev,
@@ -1079,21 +1048,15 @@ static int nmk_i2c_probe(struct amba_device *adev, const struct amba_id *id)
1079 ret = i2c_add_adapter(adap); 1048 ret = i2c_add_adapter(adap);
1080 if (ret) { 1049 if (ret) {
1081 dev_err(&adev->dev, "failed to add adapter\n"); 1050 dev_err(&adev->dev, "failed to add adapter\n");
1082 goto err_add_adap; 1051 goto err_no_adap;
1083 } 1052 }
1084 1053
1085 pm_runtime_put(&adev->dev); 1054 pm_runtime_put(&adev->dev);
1086 1055
1087 return 0; 1056 return 0;
1088 1057
1089 err_add_adap: 1058 err_no_adap:
1090 clk_put(dev->clk); 1059 clk_disable_unprepare(dev->clk);
1091 err_no_clk:
1092 free_irq(dev->irq, dev);
1093 err_irq:
1094 iounmap(dev->virtbase);
1095 err_no_ioremap:
1096 kfree(dev);
1097 err_no_mem: 1060 err_no_mem:
1098 1061
1099 return ret; 1062 return ret;
@@ -1110,13 +1073,9 @@ static int nmk_i2c_remove(struct amba_device *adev)
1110 clear_all_interrupts(dev); 1073 clear_all_interrupts(dev);
1111 /* disable the controller */ 1074 /* disable the controller */
1112 i2c_clr_bit(dev->virtbase + I2C_CR, I2C_CR_PE); 1075 i2c_clr_bit(dev->virtbase + I2C_CR, I2C_CR_PE);
1113 free_irq(dev->irq, dev); 1076 clk_disable_unprepare(dev->clk);
1114 iounmap(dev->virtbase);
1115 if (res) 1077 if (res)
1116 release_mem_region(res->start, resource_size(res)); 1078 release_mem_region(res->start, resource_size(res));
1117 clk_put(dev->clk);
1118 pm_runtime_disable(&adev->dev);
1119 kfree(dev);
1120 1079
1121 return 0; 1080 return 0;
1122} 1081}
diff --git a/drivers/i2c/busses/i2c-ocores.c b/drivers/i2c/busses/i2c-ocores.c
index 80e06fa45720..1f6369f14fb6 100644
--- a/drivers/i2c/busses/i2c-ocores.c
+++ b/drivers/i2c/busses/i2c-ocores.c
@@ -246,7 +246,7 @@ static const struct i2c_algorithm ocores_algorithm = {
246static struct i2c_adapter ocores_adapter = { 246static struct i2c_adapter ocores_adapter = {
247 .owner = THIS_MODULE, 247 .owner = THIS_MODULE,
248 .name = "i2c-ocores", 248 .name = "i2c-ocores",
249 .class = I2C_CLASS_HWMON | I2C_CLASS_SPD, 249 .class = I2C_CLASS_HWMON | I2C_CLASS_SPD | I2C_CLASS_DEPRECATED,
250 .algo = &ocores_algorithm, 250 .algo = &ocores_algorithm,
251}; 251};
252 252
diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
index 90dcc2eaac5f..85f8eac9ba18 100644
--- a/drivers/i2c/busses/i2c-omap.c
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -636,7 +636,7 @@ omap_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
636 int r; 636 int r;
637 637
638 r = pm_runtime_get_sync(dev->dev); 638 r = pm_runtime_get_sync(dev->dev);
639 if (IS_ERR_VALUE(r)) 639 if (r < 0)
640 goto out; 640 goto out;
641 641
642 r = omap_i2c_wait_for_bb(dev); 642 r = omap_i2c_wait_for_bb(dev);
@@ -1155,7 +1155,7 @@ omap_i2c_probe(struct platform_device *pdev)
1155 pm_runtime_use_autosuspend(dev->dev); 1155 pm_runtime_use_autosuspend(dev->dev);
1156 1156
1157 r = pm_runtime_get_sync(dev->dev); 1157 r = pm_runtime_get_sync(dev->dev);
1158 if (IS_ERR_VALUE(r)) 1158 if (r < 0)
1159 goto err_free_mem; 1159 goto err_free_mem;
1160 1160
1161 /* 1161 /*
@@ -1238,7 +1238,7 @@ omap_i2c_probe(struct platform_device *pdev)
1238 adap = &dev->adapter; 1238 adap = &dev->adapter;
1239 i2c_set_adapdata(adap, dev); 1239 i2c_set_adapdata(adap, dev);
1240 adap->owner = THIS_MODULE; 1240 adap->owner = THIS_MODULE;
1241 adap->class = I2C_CLASS_HWMON; 1241 adap->class = I2C_CLASS_HWMON | I2C_CLASS_DEPRECATED;
1242 strlcpy(adap->name, "OMAP I2C adapter", sizeof(adap->name)); 1242 strlcpy(adap->name, "OMAP I2C adapter", sizeof(adap->name));
1243 adap->algo = &omap_i2c_algo; 1243 adap->algo = &omap_i2c_algo;
1244 adap->dev.parent = &pdev->dev; 1244 adap->dev.parent = &pdev->dev;
@@ -1276,7 +1276,7 @@ static int omap_i2c_remove(struct platform_device *pdev)
1276 1276
1277 i2c_del_adapter(&dev->adapter); 1277 i2c_del_adapter(&dev->adapter);
1278 ret = pm_runtime_get_sync(&pdev->dev); 1278 ret = pm_runtime_get_sync(&pdev->dev);
1279 if (IS_ERR_VALUE(ret)) 1279 if (ret < 0)
1280 return ret; 1280 return ret;
1281 1281
1282 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0); 1282 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0);
diff --git a/drivers/i2c/busses/i2c-pasemi.c b/drivers/i2c/busses/i2c-pasemi.c
index 615f632c846f..7a9dce43e115 100644
--- a/drivers/i2c/busses/i2c-pasemi.c
+++ b/drivers/i2c/busses/i2c-pasemi.c
@@ -401,7 +401,7 @@ static void pasemi_smb_remove(struct pci_dev *dev)
401 kfree(smbus); 401 kfree(smbus);
402} 402}
403 403
404static DEFINE_PCI_DEVICE_TABLE(pasemi_smb_ids) = { 404static const struct pci_device_id pasemi_smb_ids[] = {
405 { PCI_DEVICE(0x1959, 0xa003) }, 405 { PCI_DEVICE(0x1959, 0xa003) },
406 { 0, } 406 { 0, }
407}; 407};
diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c
index 39dd8ec60dfd..a6f54ba27e2a 100644
--- a/drivers/i2c/busses/i2c-piix4.c
+++ b/drivers/i2c/busses/i2c-piix4.c
@@ -540,7 +540,7 @@ static const struct i2c_algorithm smbus_algorithm = {
540 .functionality = piix4_func, 540 .functionality = piix4_func,
541}; 541};
542 542
543static DEFINE_PCI_DEVICE_TABLE(piix4_ids) = { 543static const struct pci_device_id piix4_ids[] = {
544 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_3) }, 544 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_3) },
545 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443MX_3) }, 545 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443MX_3) },
546 { PCI_DEVICE(PCI_VENDOR_ID_EFAR, PCI_DEVICE_ID_EFAR_SLC90E66_3) }, 546 { PCI_DEVICE(PCI_VENDOR_ID_EFAR, PCI_DEVICE_ID_EFAR_SLC90E66_3) },
diff --git a/drivers/i2c/busses/i2c-pxa-pci.c b/drivers/i2c/busses/i2c-pxa-pci.c
index 9639be86e53f..417464e9ea2a 100644
--- a/drivers/i2c/busses/i2c-pxa-pci.c
+++ b/drivers/i2c/busses/i2c-pxa-pci.c
@@ -148,7 +148,7 @@ static void ce4100_i2c_remove(struct pci_dev *dev)
148 kfree(sds); 148 kfree(sds);
149} 149}
150 150
151static DEFINE_PCI_DEVICE_TABLE(ce4100_i2c_devices) = { 151static const struct pci_device_id ce4100_i2c_devices[] = {
152 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x2e68)}, 152 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x2e68)},
153 { }, 153 { },
154}; 154};
diff --git a/drivers/i2c/busses/i2c-qup.c b/drivers/i2c/busses/i2c-qup.c
new file mode 100644
index 000000000000..1b4cf14f1106
--- /dev/null
+++ b/drivers/i2c/busses/i2c-qup.c
@@ -0,0 +1,768 @@
1/*
2 * Copyright (c) 2009-2013, The Linux Foundation. All rights reserved.
3 * Copyright (c) 2014, Sony Mobile Communications AB.
4 *
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 and
8 * only version 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 */
16
17#include <linux/clk.h>
18#include <linux/delay.h>
19#include <linux/err.h>
20#include <linux/i2c.h>
21#include <linux/interrupt.h>
22#include <linux/io.h>
23#include <linux/module.h>
24#include <linux/of.h>
25#include <linux/platform_device.h>
26#include <linux/pm_runtime.h>
27
28/* QUP Registers */
29#define QUP_CONFIG 0x000
30#define QUP_STATE 0x004
31#define QUP_IO_MODE 0x008
32#define QUP_SW_RESET 0x00c
33#define QUP_OPERATIONAL 0x018
34#define QUP_ERROR_FLAGS 0x01c
35#define QUP_ERROR_FLAGS_EN 0x020
36#define QUP_HW_VERSION 0x030
37#define QUP_MX_OUTPUT_CNT 0x100
38#define QUP_OUT_FIFO_BASE 0x110
39#define QUP_MX_WRITE_CNT 0x150
40#define QUP_MX_INPUT_CNT 0x200
41#define QUP_MX_READ_CNT 0x208
42#define QUP_IN_FIFO_BASE 0x218
43#define QUP_I2C_CLK_CTL 0x400
44#define QUP_I2C_STATUS 0x404
45
46/* QUP States and reset values */
47#define QUP_RESET_STATE 0
48#define QUP_RUN_STATE 1
49#define QUP_PAUSE_STATE 3
50#define QUP_STATE_MASK 3
51
52#define QUP_STATE_VALID BIT(2)
53#define QUP_I2C_MAST_GEN BIT(4)
54
55#define QUP_OPERATIONAL_RESET 0x000ff0
56#define QUP_I2C_STATUS_RESET 0xfffffc
57
58/* QUP OPERATIONAL FLAGS */
59#define QUP_I2C_NACK_FLAG BIT(3)
60#define QUP_OUT_NOT_EMPTY BIT(4)
61#define QUP_IN_NOT_EMPTY BIT(5)
62#define QUP_OUT_FULL BIT(6)
63#define QUP_OUT_SVC_FLAG BIT(8)
64#define QUP_IN_SVC_FLAG BIT(9)
65#define QUP_MX_OUTPUT_DONE BIT(10)
66#define QUP_MX_INPUT_DONE BIT(11)
67
68/* I2C mini core related values */
69#define QUP_CLOCK_AUTO_GATE BIT(13)
70#define I2C_MINI_CORE (2 << 8)
71#define I2C_N_VAL 15
72/* Most significant word offset in FIFO port */
73#define QUP_MSW_SHIFT (I2C_N_VAL + 1)
74
75/* Packing/Unpacking words in FIFOs, and IO modes */
76#define QUP_OUTPUT_BLK_MODE (1 << 10)
77#define QUP_INPUT_BLK_MODE (1 << 12)
78#define QUP_UNPACK_EN BIT(14)
79#define QUP_PACK_EN BIT(15)
80
81#define QUP_REPACK_EN (QUP_UNPACK_EN | QUP_PACK_EN)
82
83#define QUP_OUTPUT_BLOCK_SIZE(x)(((x) >> 0) & 0x03)
84#define QUP_OUTPUT_FIFO_SIZE(x) (((x) >> 2) & 0x07)
85#define QUP_INPUT_BLOCK_SIZE(x) (((x) >> 5) & 0x03)
86#define QUP_INPUT_FIFO_SIZE(x) (((x) >> 7) & 0x07)
87
88/* QUP tags */
89#define QUP_TAG_START (1 << 8)
90#define QUP_TAG_DATA (2 << 8)
91#define QUP_TAG_STOP (3 << 8)
92#define QUP_TAG_REC (4 << 8)
93
94/* Status, Error flags */
95#define I2C_STATUS_WR_BUFFER_FULL BIT(0)
96#define I2C_STATUS_BUS_ACTIVE BIT(8)
97#define I2C_STATUS_ERROR_MASK 0x38000fc
98#define QUP_STATUS_ERROR_FLAGS 0x7c
99
100#define QUP_READ_LIMIT 256
101
102struct qup_i2c_dev {
103 struct device *dev;
104 void __iomem *base;
105 int irq;
106 struct clk *clk;
107 struct clk *pclk;
108 struct i2c_adapter adap;
109
110 int clk_ctl;
111 int out_fifo_sz;
112 int in_fifo_sz;
113 int out_blk_sz;
114 int in_blk_sz;
115
116 unsigned long one_byte_t;
117
118 struct i2c_msg *msg;
119 /* Current posion in user message buffer */
120 int pos;
121 /* I2C protocol errors */
122 u32 bus_err;
123 /* QUP core errors */
124 u32 qup_err;
125
126 struct completion xfer;
127};
128
129static irqreturn_t qup_i2c_interrupt(int irq, void *dev)
130{
131 struct qup_i2c_dev *qup = dev;
132 u32 bus_err;
133 u32 qup_err;
134 u32 opflags;
135
136 bus_err = readl(qup->base + QUP_I2C_STATUS);
137 qup_err = readl(qup->base + QUP_ERROR_FLAGS);
138 opflags = readl(qup->base + QUP_OPERATIONAL);
139
140 if (!qup->msg) {
141 /* Clear Error interrupt */
142 writel(QUP_RESET_STATE, qup->base + QUP_STATE);
143 return IRQ_HANDLED;
144 }
145
146 bus_err &= I2C_STATUS_ERROR_MASK;
147 qup_err &= QUP_STATUS_ERROR_FLAGS;
148
149 if (qup_err) {
150 /* Clear Error interrupt */
151 writel(qup_err, qup->base + QUP_ERROR_FLAGS);
152 goto done;
153 }
154
155 if (bus_err) {
156 /* Clear Error interrupt */
157 writel(QUP_RESET_STATE, qup->base + QUP_STATE);
158 goto done;
159 }
160
161 if (opflags & QUP_IN_SVC_FLAG)
162 writel(QUP_IN_SVC_FLAG, qup->base + QUP_OPERATIONAL);
163
164 if (opflags & QUP_OUT_SVC_FLAG)
165 writel(QUP_OUT_SVC_FLAG, qup->base + QUP_OPERATIONAL);
166
167done:
168 qup->qup_err = qup_err;
169 qup->bus_err = bus_err;
170 complete(&qup->xfer);
171 return IRQ_HANDLED;
172}
173
174static int qup_i2c_poll_state_mask(struct qup_i2c_dev *qup,
175 u32 req_state, u32 req_mask)
176{
177 int retries = 1;
178 u32 state;
179
180 /*
181 * State transition takes 3 AHB clocks cycles + 3 I2C master clock
182 * cycles. So retry once after a 1uS delay.
183 */
184 do {
185 state = readl(qup->base + QUP_STATE);
186
187 if (state & QUP_STATE_VALID &&
188 (state & req_mask) == req_state)
189 return 0;
190
191 udelay(1);
192 } while (retries--);
193
194 return -ETIMEDOUT;
195}
196
197static int qup_i2c_poll_state(struct qup_i2c_dev *qup, u32 req_state)
198{
199 return qup_i2c_poll_state_mask(qup, req_state, QUP_STATE_MASK);
200}
201
202static int qup_i2c_poll_state_valid(struct qup_i2c_dev *qup)
203{
204 return qup_i2c_poll_state_mask(qup, 0, 0);
205}
206
207static int qup_i2c_poll_state_i2c_master(struct qup_i2c_dev *qup)
208{
209 return qup_i2c_poll_state_mask(qup, QUP_I2C_MAST_GEN, QUP_I2C_MAST_GEN);
210}
211
212static int qup_i2c_change_state(struct qup_i2c_dev *qup, u32 state)
213{
214 if (qup_i2c_poll_state_valid(qup) != 0)
215 return -EIO;
216
217 writel(state, qup->base + QUP_STATE);
218
219 if (qup_i2c_poll_state(qup, state) != 0)
220 return -EIO;
221 return 0;
222}
223
224static int qup_i2c_wait_writeready(struct qup_i2c_dev *qup)
225{
226 unsigned long timeout;
227 u32 opflags;
228 u32 status;
229
230 timeout = jiffies + HZ;
231
232 for (;;) {
233 opflags = readl(qup->base + QUP_OPERATIONAL);
234 status = readl(qup->base + QUP_I2C_STATUS);
235
236 if (!(opflags & QUP_OUT_NOT_EMPTY) &&
237 !(status & I2C_STATUS_BUS_ACTIVE))
238 return 0;
239
240 if (time_after(jiffies, timeout))
241 return -ETIMEDOUT;
242
243 usleep_range(qup->one_byte_t, qup->one_byte_t * 2);
244 }
245}
246
247static void qup_i2c_set_write_mode(struct qup_i2c_dev *qup, struct i2c_msg *msg)
248{
249 /* Number of entries to shift out, including the start */
250 int total = msg->len + 1;
251
252 if (total < qup->out_fifo_sz) {
253 /* FIFO mode */
254 writel(QUP_REPACK_EN, qup->base + QUP_IO_MODE);
255 writel(total, qup->base + QUP_MX_WRITE_CNT);
256 } else {
257 /* BLOCK mode (transfer data on chunks) */
258 writel(QUP_OUTPUT_BLK_MODE | QUP_REPACK_EN,
259 qup->base + QUP_IO_MODE);
260 writel(total, qup->base + QUP_MX_OUTPUT_CNT);
261 }
262}
263
264static void qup_i2c_issue_write(struct qup_i2c_dev *qup, struct i2c_msg *msg)
265{
266 u32 addr = msg->addr << 1;
267 u32 qup_tag;
268 u32 opflags;
269 int idx;
270 u32 val;
271
272 if (qup->pos == 0) {
273 val = QUP_TAG_START | addr;
274 idx = 1;
275 } else {
276 val = 0;
277 idx = 0;
278 }
279
280 while (qup->pos < msg->len) {
281 /* Check that there's space in the FIFO for our pair */
282 opflags = readl(qup->base + QUP_OPERATIONAL);
283 if (opflags & QUP_OUT_FULL)
284 break;
285
286 if (qup->pos == msg->len - 1)
287 qup_tag = QUP_TAG_STOP;
288 else
289 qup_tag = QUP_TAG_DATA;
290
291 if (idx & 1)
292 val |= (qup_tag | msg->buf[qup->pos]) << QUP_MSW_SHIFT;
293 else
294 val = qup_tag | msg->buf[qup->pos];
295
296 /* Write out the pair and the last odd value */
297 if (idx & 1 || qup->pos == msg->len - 1)
298 writel(val, qup->base + QUP_OUT_FIFO_BASE);
299
300 qup->pos++;
301 idx++;
302 }
303}
304
305static int qup_i2c_write_one(struct qup_i2c_dev *qup, struct i2c_msg *msg)
306{
307 unsigned long left;
308 int ret;
309
310 qup->msg = msg;
311 qup->pos = 0;
312
313 enable_irq(qup->irq);
314
315 qup_i2c_set_write_mode(qup, msg);
316
317 ret = qup_i2c_change_state(qup, QUP_RUN_STATE);
318 if (ret)
319 goto err;
320
321 writel(qup->clk_ctl, qup->base + QUP_I2C_CLK_CTL);
322
323 do {
324 ret = qup_i2c_change_state(qup, QUP_PAUSE_STATE);
325 if (ret)
326 goto err;
327
328 qup_i2c_issue_write(qup, msg);
329
330 ret = qup_i2c_change_state(qup, QUP_RUN_STATE);
331 if (ret)
332 goto err;
333
334 left = wait_for_completion_timeout(&qup->xfer, HZ);
335 if (!left) {
336 writel(1, qup->base + QUP_SW_RESET);
337 ret = -ETIMEDOUT;
338 goto err;
339 }
340
341 if (qup->bus_err || qup->qup_err) {
342 if (qup->bus_err & QUP_I2C_NACK_FLAG)
343 dev_err(qup->dev, "NACK from %x\n", msg->addr);
344 ret = -EIO;
345 goto err;
346 }
347 } while (qup->pos < msg->len);
348
349 /* Wait for the outstanding data in the fifo to drain */
350 ret = qup_i2c_wait_writeready(qup);
351
352err:
353 disable_irq(qup->irq);
354 qup->msg = NULL;
355
356 return ret;
357}
358
359static void qup_i2c_set_read_mode(struct qup_i2c_dev *qup, int len)
360{
361 if (len < qup->in_fifo_sz) {
362 /* FIFO mode */
363 writel(QUP_REPACK_EN, qup->base + QUP_IO_MODE);
364 writel(len, qup->base + QUP_MX_READ_CNT);
365 } else {
366 /* BLOCK mode (transfer data on chunks) */
367 writel(QUP_INPUT_BLK_MODE | QUP_REPACK_EN,
368 qup->base + QUP_IO_MODE);
369 writel(len, qup->base + QUP_MX_INPUT_CNT);
370 }
371}
372
373static void qup_i2c_issue_read(struct qup_i2c_dev *qup, struct i2c_msg *msg)
374{
375 u32 addr, len, val;
376
377 addr = (msg->addr << 1) | 1;
378
379 /* 0 is used to specify a length 256 (QUP_READ_LIMIT) */
380 len = (msg->len == QUP_READ_LIMIT) ? 0 : msg->len;
381
382 val = ((QUP_TAG_REC | len) << QUP_MSW_SHIFT) | QUP_TAG_START | addr;
383 writel(val, qup->base + QUP_OUT_FIFO_BASE);
384}
385
386
387static void qup_i2c_read_fifo(struct qup_i2c_dev *qup, struct i2c_msg *msg)
388{
389 u32 opflags;
390 u32 val = 0;
391 int idx;
392
393 for (idx = 0; qup->pos < msg->len; idx++) {
394 if ((idx & 1) == 0) {
395 /* Check that FIFO have data */
396 opflags = readl(qup->base + QUP_OPERATIONAL);
397 if (!(opflags & QUP_IN_NOT_EMPTY))
398 break;
399
400 /* Reading 2 words at time */
401 val = readl(qup->base + QUP_IN_FIFO_BASE);
402
403 msg->buf[qup->pos++] = val & 0xFF;
404 } else {
405 msg->buf[qup->pos++] = val >> QUP_MSW_SHIFT;
406 }
407 }
408}
409
410static int qup_i2c_read_one(struct qup_i2c_dev *qup, struct i2c_msg *msg)
411{
412 unsigned long left;
413 int ret;
414
415 /*
416 * The QUP block will issue a NACK and STOP on the bus when reaching
417 * the end of the read, the length of the read is specified as one byte
418 * which limits the possible read to 256 (QUP_READ_LIMIT) bytes.
419 */
420 if (msg->len > QUP_READ_LIMIT) {
421 dev_err(qup->dev, "HW not capable of reads over %d bytes\n",
422 QUP_READ_LIMIT);
423 return -EINVAL;
424 }
425
426 qup->msg = msg;
427 qup->pos = 0;
428
429 enable_irq(qup->irq);
430
431 qup_i2c_set_read_mode(qup, msg->len);
432
433 ret = qup_i2c_change_state(qup, QUP_RUN_STATE);
434 if (ret)
435 goto err;
436
437 writel(qup->clk_ctl, qup->base + QUP_I2C_CLK_CTL);
438
439 ret = qup_i2c_change_state(qup, QUP_PAUSE_STATE);
440 if (ret)
441 goto err;
442
443 qup_i2c_issue_read(qup, msg);
444
445 ret = qup_i2c_change_state(qup, QUP_RUN_STATE);
446 if (ret)
447 goto err;
448
449 do {
450 left = wait_for_completion_timeout(&qup->xfer, HZ);
451 if (!left) {
452 writel(1, qup->base + QUP_SW_RESET);
453 ret = -ETIMEDOUT;
454 goto err;
455 }
456
457 if (qup->bus_err || qup->qup_err) {
458 if (qup->bus_err & QUP_I2C_NACK_FLAG)
459 dev_err(qup->dev, "NACK from %x\n", msg->addr);
460 ret = -EIO;
461 goto err;
462 }
463
464 qup_i2c_read_fifo(qup, msg);
465 } while (qup->pos < msg->len);
466
467err:
468 disable_irq(qup->irq);
469 qup->msg = NULL;
470
471 return ret;
472}
473
474static int qup_i2c_xfer(struct i2c_adapter *adap,
475 struct i2c_msg msgs[],
476 int num)
477{
478 struct qup_i2c_dev *qup = i2c_get_adapdata(adap);
479 int ret, idx;
480
481 ret = pm_runtime_get_sync(qup->dev);
482 if (ret)
483 goto out;
484
485 writel(1, qup->base + QUP_SW_RESET);
486 ret = qup_i2c_poll_state(qup, QUP_RESET_STATE);
487 if (ret)
488 goto out;
489
490 /* Configure QUP as I2C mini core */
491 writel(I2C_MINI_CORE | I2C_N_VAL, qup->base + QUP_CONFIG);
492
493 for (idx = 0; idx < num; idx++) {
494 if (msgs[idx].len == 0) {
495 ret = -EINVAL;
496 goto out;
497 }
498
499 if (qup_i2c_poll_state_i2c_master(qup)) {
500 ret = -EIO;
501 goto out;
502 }
503
504 if (msgs[idx].flags & I2C_M_RD)
505 ret = qup_i2c_read_one(qup, &msgs[idx]);
506 else
507 ret = qup_i2c_write_one(qup, &msgs[idx]);
508
509 if (ret)
510 break;
511
512 ret = qup_i2c_change_state(qup, QUP_RESET_STATE);
513 if (ret)
514 break;
515 }
516
517 if (ret == 0)
518 ret = num;
519out:
520
521 pm_runtime_mark_last_busy(qup->dev);
522 pm_runtime_put_autosuspend(qup->dev);
523
524 return ret;
525}
526
527static u32 qup_i2c_func(struct i2c_adapter *adap)
528{
529 return I2C_FUNC_I2C | (I2C_FUNC_SMBUS_EMUL & ~I2C_FUNC_SMBUS_QUICK);
530}
531
532static const struct i2c_algorithm qup_i2c_algo = {
533 .master_xfer = qup_i2c_xfer,
534 .functionality = qup_i2c_func,
535};
536
537static void qup_i2c_enable_clocks(struct qup_i2c_dev *qup)
538{
539 clk_prepare_enable(qup->clk);
540 clk_prepare_enable(qup->pclk);
541}
542
543static void qup_i2c_disable_clocks(struct qup_i2c_dev *qup)
544{
545 u32 config;
546
547 qup_i2c_change_state(qup, QUP_RESET_STATE);
548 clk_disable_unprepare(qup->clk);
549 config = readl(qup->base + QUP_CONFIG);
550 config |= QUP_CLOCK_AUTO_GATE;
551 writel(config, qup->base + QUP_CONFIG);
552 clk_disable_unprepare(qup->pclk);
553}
554
555static int qup_i2c_probe(struct platform_device *pdev)
556{
557 static const int blk_sizes[] = {4, 16, 32};
558 struct device_node *node = pdev->dev.of_node;
559 struct qup_i2c_dev *qup;
560 unsigned long one_bit_t;
561 struct resource *res;
562 u32 io_mode, hw_ver, size;
563 int ret, fs_div, hs_div;
564 int src_clk_freq;
565 u32 clk_freq = 100000;
566
567 qup = devm_kzalloc(&pdev->dev, sizeof(*qup), GFP_KERNEL);
568 if (!qup)
569 return -ENOMEM;
570
571 qup->dev = &pdev->dev;
572 init_completion(&qup->xfer);
573 platform_set_drvdata(pdev, qup);
574
575 of_property_read_u32(node, "clock-frequency", &clk_freq);
576
577 /* We support frequencies up to FAST Mode (400KHz) */
578 if (!clk_freq || clk_freq > 400000) {
579 dev_err(qup->dev, "clock frequency not supported %d\n",
580 clk_freq);
581 return -EINVAL;
582 }
583
584 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
585 qup->base = devm_ioremap_resource(qup->dev, res);
586 if (IS_ERR(qup->base))
587 return PTR_ERR(qup->base);
588
589 qup->irq = platform_get_irq(pdev, 0);
590 if (qup->irq < 0) {
591 dev_err(qup->dev, "No IRQ defined\n");
592 return qup->irq;
593 }
594
595 qup->clk = devm_clk_get(qup->dev, "core");
596 if (IS_ERR(qup->clk)) {
597 dev_err(qup->dev, "Could not get core clock\n");
598 return PTR_ERR(qup->clk);
599 }
600
601 qup->pclk = devm_clk_get(qup->dev, "iface");
602 if (IS_ERR(qup->pclk)) {
603 dev_err(qup->dev, "Could not get iface clock\n");
604 return PTR_ERR(qup->pclk);
605 }
606
607 qup_i2c_enable_clocks(qup);
608
609 /*
610 * Bootloaders might leave a pending interrupt on certain QUP's,
611 * so we reset the core before registering for interrupts.
612 */
613 writel(1, qup->base + QUP_SW_RESET);
614 ret = qup_i2c_poll_state_valid(qup);
615 if (ret)
616 goto fail;
617
618 ret = devm_request_irq(qup->dev, qup->irq, qup_i2c_interrupt,
619 IRQF_TRIGGER_HIGH, "i2c_qup", qup);
620 if (ret) {
621 dev_err(qup->dev, "Request %d IRQ failed\n", qup->irq);
622 goto fail;
623 }
624 disable_irq(qup->irq);
625
626 hw_ver = readl(qup->base + QUP_HW_VERSION);
627 dev_dbg(qup->dev, "Revision %x\n", hw_ver);
628
629 io_mode = readl(qup->base + QUP_IO_MODE);
630
631 /*
632 * The block/fifo size w.r.t. 'actual data' is 1/2 due to 'tag'
633 * associated with each byte written/received
634 */
635 size = QUP_OUTPUT_BLOCK_SIZE(io_mode);
636 if (size >= ARRAY_SIZE(blk_sizes))
637 return -EIO;
638 qup->out_blk_sz = blk_sizes[size] / 2;
639
640 size = QUP_INPUT_BLOCK_SIZE(io_mode);
641 if (size >= ARRAY_SIZE(blk_sizes))
642 return -EIO;
643 qup->in_blk_sz = blk_sizes[size] / 2;
644
645 size = QUP_OUTPUT_FIFO_SIZE(io_mode);
646 qup->out_fifo_sz = qup->out_blk_sz * (2 << size);
647
648 size = QUP_INPUT_FIFO_SIZE(io_mode);
649 qup->in_fifo_sz = qup->in_blk_sz * (2 << size);
650
651 src_clk_freq = clk_get_rate(qup->clk);
652 fs_div = ((src_clk_freq / clk_freq) / 2) - 3;
653 hs_div = 3;
654 qup->clk_ctl = (hs_div << 8) | (fs_div & 0xff);
655
656 /*
657 * Time it takes for a byte to be clocked out on the bus.
658 * Each byte takes 9 clock cycles (8 bits + 1 ack).
659 */
660 one_bit_t = (USEC_PER_SEC / clk_freq) + 1;
661 qup->one_byte_t = one_bit_t * 9;
662
663 dev_dbg(qup->dev, "IN:block:%d, fifo:%d, OUT:block:%d, fifo:%d\n",
664 qup->in_blk_sz, qup->in_fifo_sz,
665 qup->out_blk_sz, qup->out_fifo_sz);
666
667 i2c_set_adapdata(&qup->adap, qup);
668 qup->adap.algo = &qup_i2c_algo;
669 qup->adap.dev.parent = qup->dev;
670 qup->adap.dev.of_node = pdev->dev.of_node;
671 strlcpy(qup->adap.name, "QUP I2C adapter", sizeof(qup->adap.name));
672
673 ret = i2c_add_adapter(&qup->adap);
674 if (ret)
675 goto fail;
676
677 pm_runtime_set_autosuspend_delay(qup->dev, MSEC_PER_SEC);
678 pm_runtime_use_autosuspend(qup->dev);
679 pm_runtime_set_active(qup->dev);
680 pm_runtime_enable(qup->dev);
681 return 0;
682
683fail:
684 qup_i2c_disable_clocks(qup);
685 return ret;
686}
687
688static int qup_i2c_remove(struct platform_device *pdev)
689{
690 struct qup_i2c_dev *qup = platform_get_drvdata(pdev);
691
692 disable_irq(qup->irq);
693 qup_i2c_disable_clocks(qup);
694 i2c_del_adapter(&qup->adap);
695 pm_runtime_disable(qup->dev);
696 pm_runtime_set_suspended(qup->dev);
697 return 0;
698}
699
700#ifdef CONFIG_PM
701static int qup_i2c_pm_suspend_runtime(struct device *device)
702{
703 struct qup_i2c_dev *qup = dev_get_drvdata(device);
704
705 dev_dbg(device, "pm_runtime: suspending...\n");
706 qup_i2c_disable_clocks(qup);
707 return 0;
708}
709
710static int qup_i2c_pm_resume_runtime(struct device *device)
711{
712 struct qup_i2c_dev *qup = dev_get_drvdata(device);
713
714 dev_dbg(device, "pm_runtime: resuming...\n");
715 qup_i2c_enable_clocks(qup);
716 return 0;
717}
718#endif
719
720#ifdef CONFIG_PM_SLEEP
721static int qup_i2c_suspend(struct device *device)
722{
723 qup_i2c_pm_suspend_runtime(device);
724 return 0;
725}
726
727static int qup_i2c_resume(struct device *device)
728{
729 qup_i2c_pm_resume_runtime(device);
730 pm_runtime_mark_last_busy(device);
731 pm_request_autosuspend(device);
732 return 0;
733}
734#endif
735
736static const struct dev_pm_ops qup_i2c_qup_pm_ops = {
737 SET_SYSTEM_SLEEP_PM_OPS(
738 qup_i2c_suspend,
739 qup_i2c_resume)
740 SET_RUNTIME_PM_OPS(
741 qup_i2c_pm_suspend_runtime,
742 qup_i2c_pm_resume_runtime,
743 NULL)
744};
745
746static const struct of_device_id qup_i2c_dt_match[] = {
747 { .compatible = "qcom,i2c-qup-v1.1.1" },
748 { .compatible = "qcom,i2c-qup-v2.1.1" },
749 { .compatible = "qcom,i2c-qup-v2.2.1" },
750 {}
751};
752MODULE_DEVICE_TABLE(of, qup_i2c_dt_match);
753
754static struct platform_driver qup_i2c_driver = {
755 .probe = qup_i2c_probe,
756 .remove = qup_i2c_remove,
757 .driver = {
758 .name = "i2c_qup",
759 .owner = THIS_MODULE,
760 .pm = &qup_i2c_qup_pm_ops,
761 .of_match_table = qup_i2c_dt_match,
762 },
763};
764
765module_platform_driver(qup_i2c_driver);
766
767MODULE_LICENSE("GPL v2");
768MODULE_ALIAS("platform:i2c_qup");
diff --git a/drivers/i2c/busses/i2c-rcar.c b/drivers/i2c/busses/i2c-rcar.c
index 0282d4d42805..d4fa8eba6e9d 100644
--- a/drivers/i2c/busses/i2c-rcar.c
+++ b/drivers/i2c/busses/i2c-rcar.c
@@ -638,6 +638,7 @@ static const struct of_device_id rcar_i2c_dt_ids[] = {
638 { .compatible = "renesas,i2c-r8a7778", .data = (void *)I2C_RCAR_GEN1 }, 638 { .compatible = "renesas,i2c-r8a7778", .data = (void *)I2C_RCAR_GEN1 },
639 { .compatible = "renesas,i2c-r8a7779", .data = (void *)I2C_RCAR_GEN1 }, 639 { .compatible = "renesas,i2c-r8a7779", .data = (void *)I2C_RCAR_GEN1 },
640 { .compatible = "renesas,i2c-r8a7790", .data = (void *)I2C_RCAR_GEN2 }, 640 { .compatible = "renesas,i2c-r8a7790", .data = (void *)I2C_RCAR_GEN2 },
641 { .compatible = "renesas,i2c-r8a7791", .data = (void *)I2C_RCAR_GEN2 },
641 {}, 642 {},
642}; 643};
643MODULE_DEVICE_TABLE(of, rcar_i2c_dt_ids); 644MODULE_DEVICE_TABLE(of, rcar_i2c_dt_ids);
@@ -691,7 +692,7 @@ static int rcar_i2c_probe(struct platform_device *pdev)
691 adap = &priv->adap; 692 adap = &priv->adap;
692 adap->nr = pdev->id; 693 adap->nr = pdev->id;
693 adap->algo = &rcar_i2c_algo; 694 adap->algo = &rcar_i2c_algo;
694 adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD; 695 adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD | I2C_CLASS_DEPRECATED;
695 adap->retries = 3; 696 adap->retries = 3;
696 adap->dev.parent = dev; 697 adap->dev.parent = dev;
697 adap->dev.of_node = dev->of_node; 698 adap->dev.of_node = dev->of_node;
diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c
index 684d21e71e4a..ae4491062e41 100644
--- a/drivers/i2c/busses/i2c-s3c2410.c
+++ b/drivers/i2c/busses/i2c-s3c2410.c
@@ -601,6 +601,31 @@ static irqreturn_t s3c24xx_i2c_irq(int irqno, void *dev_id)
601 return IRQ_HANDLED; 601 return IRQ_HANDLED;
602} 602}
603 603
604/*
605 * Disable the bus so that we won't get any interrupts from now on, or try
606 * to drive any lines. This is the default state when we don't have
607 * anything to send/receive.
608 *
609 * If there is an event on the bus, or we have a pre-existing event at
610 * kernel boot time, we may not notice the event and the I2C controller
611 * will lock the bus with the I2C clock line low indefinitely.
612 */
613static inline void s3c24xx_i2c_disable_bus(struct s3c24xx_i2c *i2c)
614{
615 unsigned long tmp;
616
617 /* Stop driving the I2C pins */
618 tmp = readl(i2c->regs + S3C2410_IICSTAT);
619 tmp &= ~S3C2410_IICSTAT_TXRXEN;
620 writel(tmp, i2c->regs + S3C2410_IICSTAT);
621
622 /* We don't expect any interrupts now, and don't want send acks */
623 tmp = readl(i2c->regs + S3C2410_IICCON);
624 tmp &= ~(S3C2410_IICCON_IRQEN | S3C2410_IICCON_IRQPEND |
625 S3C2410_IICCON_ACKEN);
626 writel(tmp, i2c->regs + S3C2410_IICCON);
627}
628
604 629
605/* s3c24xx_i2c_set_master 630/* s3c24xx_i2c_set_master
606 * 631 *
@@ -735,7 +760,11 @@ static int s3c24xx_i2c_doxfer(struct s3c24xx_i2c *i2c,
735 760
736 s3c24xx_i2c_wait_idle(i2c); 761 s3c24xx_i2c_wait_idle(i2c);
737 762
763 s3c24xx_i2c_disable_bus(i2c);
764
738 out: 765 out:
766 i2c->state = STATE_IDLE;
767
739 return ret; 768 return ret;
740} 769}
741 770
@@ -1004,7 +1033,6 @@ static void s3c24xx_i2c_dt_gpio_free(struct s3c24xx_i2c *i2c)
1004 1033
1005static int s3c24xx_i2c_init(struct s3c24xx_i2c *i2c) 1034static int s3c24xx_i2c_init(struct s3c24xx_i2c *i2c)
1006{ 1035{
1007 unsigned long iicon = S3C2410_IICCON_IRQEN | S3C2410_IICCON_ACKEN;
1008 struct s3c2410_platform_i2c *pdata; 1036 struct s3c2410_platform_i2c *pdata;
1009 unsigned int freq; 1037 unsigned int freq;
1010 1038
@@ -1018,12 +1046,12 @@ static int s3c24xx_i2c_init(struct s3c24xx_i2c *i2c)
1018 1046
1019 dev_info(i2c->dev, "slave address 0x%02x\n", pdata->slave_addr); 1047 dev_info(i2c->dev, "slave address 0x%02x\n", pdata->slave_addr);
1020 1048
1021 writel(iicon, i2c->regs + S3C2410_IICCON); 1049 writel(0, i2c->regs + S3C2410_IICCON);
1050 writel(0, i2c->regs + S3C2410_IICSTAT);
1022 1051
1023 /* we need to work out the divisors for the clock... */ 1052 /* we need to work out the divisors for the clock... */
1024 1053
1025 if (s3c24xx_i2c_clockrate(i2c, &freq) != 0) { 1054 if (s3c24xx_i2c_clockrate(i2c, &freq) != 0) {
1026 writel(0, i2c->regs + S3C2410_IICCON);
1027 dev_err(i2c->dev, "cannot meet bus frequency required\n"); 1055 dev_err(i2c->dev, "cannot meet bus frequency required\n");
1028 return -EINVAL; 1056 return -EINVAL;
1029 } 1057 }
@@ -1031,7 +1059,8 @@ static int s3c24xx_i2c_init(struct s3c24xx_i2c *i2c)
1031 /* todo - check that the i2c lines aren't being dragged anywhere */ 1059 /* todo - check that the i2c lines aren't being dragged anywhere */
1032 1060
1033 dev_info(i2c->dev, "bus frequency set to %d KHz\n", freq); 1061 dev_info(i2c->dev, "bus frequency set to %d KHz\n", freq);
1034 dev_dbg(i2c->dev, "S3C2410_IICCON=0x%02lx\n", iicon); 1062 dev_dbg(i2c->dev, "S3C2410_IICCON=0x%02x\n",
1063 readl(i2c->regs + S3C2410_IICCON));
1035 1064
1036 return 0; 1065 return 0;
1037} 1066}
@@ -1106,7 +1135,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
1106 i2c->adap.owner = THIS_MODULE; 1135 i2c->adap.owner = THIS_MODULE;
1107 i2c->adap.algo = &s3c24xx_i2c_algorithm; 1136 i2c->adap.algo = &s3c24xx_i2c_algorithm;
1108 i2c->adap.retries = 2; 1137 i2c->adap.retries = 2;
1109 i2c->adap.class = I2C_CLASS_HWMON | I2C_CLASS_SPD; 1138 i2c->adap.class = I2C_CLASS_HWMON | I2C_CLASS_SPD | I2C_CLASS_DEPRECATED;
1110 i2c->tx_setup = 50; 1139 i2c->tx_setup = 50;
1111 1140
1112 init_waitqueue_head(&i2c->wait); 1141 init_waitqueue_head(&i2c->wait);
diff --git a/drivers/i2c/busses/i2c-sirf.c b/drivers/i2c/busses/i2c-sirf.c
index 6784f7f527a4..8e3be7ed0586 100644
--- a/drivers/i2c/busses/i2c-sirf.c
+++ b/drivers/i2c/busses/i2c-sirf.c
@@ -312,7 +312,7 @@ static int i2c_sirfsoc_probe(struct platform_device *pdev)
312 goto out; 312 goto out;
313 } 313 }
314 adap = &siic->adapter; 314 adap = &siic->adapter;
315 adap->class = I2C_CLASS_HWMON; 315 adap->class = I2C_CLASS_HWMON | I2C_CLASS_DEPRECATED;
316 316
317 mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 317 mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
318 siic->base = devm_ioremap_resource(&pdev->dev, mem_res); 318 siic->base = devm_ioremap_resource(&pdev->dev, mem_res);
diff --git a/drivers/i2c/busses/i2c-sis5595.c b/drivers/i2c/busses/i2c-sis5595.c
index 79fd96a04386..ac9bc33acef4 100644
--- a/drivers/i2c/busses/i2c-sis5595.c
+++ b/drivers/i2c/busses/i2c-sis5595.c
@@ -369,7 +369,7 @@ static struct i2c_adapter sis5595_adapter = {
369 .algo = &smbus_algorithm, 369 .algo = &smbus_algorithm,
370}; 370};
371 371
372static DEFINE_PCI_DEVICE_TABLE(sis5595_ids) = { 372static const struct pci_device_id sis5595_ids[] = {
373 { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503) }, 373 { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503) },
374 { 0, } 374 { 0, }
375}; 375};
diff --git a/drivers/i2c/busses/i2c-sis630.c b/drivers/i2c/busses/i2c-sis630.c
index 19b8505d0cdd..c6366733008d 100644
--- a/drivers/i2c/busses/i2c-sis630.c
+++ b/drivers/i2c/busses/i2c-sis630.c
@@ -510,7 +510,7 @@ static struct i2c_adapter sis630_adapter = {
510 .retries = 3 510 .retries = 3
511}; 511};
512 512
513static DEFINE_PCI_DEVICE_TABLE(sis630_ids) = { 513static const struct pci_device_id sis630_ids[] = {
514 { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503) }, 514 { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503) },
515 { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_LPC) }, 515 { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_LPC) },
516 { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_964) }, 516 { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_964) },
diff --git a/drivers/i2c/busses/i2c-sis96x.c b/drivers/i2c/busses/i2c-sis96x.c
index f8aa0c29f02b..8dc2fc5f74ff 100644
--- a/drivers/i2c/busses/i2c-sis96x.c
+++ b/drivers/i2c/busses/i2c-sis96x.c
@@ -244,7 +244,7 @@ static struct i2c_adapter sis96x_adapter = {
244 .algo = &smbus_algorithm, 244 .algo = &smbus_algorithm,
245}; 245};
246 246
247static DEFINE_PCI_DEVICE_TABLE(sis96x_ids) = { 247static const struct pci_device_id sis96x_ids[] = {
248 { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_SMBUS) }, 248 { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_SMBUS) },
249 { 0, } 249 { 0, }
250}; 250};
diff --git a/drivers/i2c/busses/i2c-st.c b/drivers/i2c/busses/i2c-st.c
index 9cf715d69551..872016196ef3 100644
--- a/drivers/i2c/busses/i2c-st.c
+++ b/drivers/i2c/busses/i2c-st.c
@@ -574,7 +574,7 @@ static irqreturn_t st_i2c_isr_thread(int irq, void *data)
574 writel_relaxed(it, i2c_dev->base + SSC_IEN); 574 writel_relaxed(it, i2c_dev->base + SSC_IEN);
575 575
576 st_i2c_set_bits(i2c_dev->base + SSC_I2C, SSC_I2C_STOPG); 576 st_i2c_set_bits(i2c_dev->base + SSC_I2C, SSC_I2C_STOPG);
577 c->result = -EIO; 577 c->result = -EAGAIN;
578 break; 578 break;
579 579
580 default: 580 default:
diff --git a/drivers/i2c/busses/i2c-stu300.c b/drivers/i2c/busses/i2c-stu300.c
index 5b80ef310841..29b1fb778943 100644
--- a/drivers/i2c/busses/i2c-stu300.c
+++ b/drivers/i2c/busses/i2c-stu300.c
@@ -911,7 +911,7 @@ static int stu300_probe(struct platform_device *pdev)
911 adap = &dev->adapter; 911 adap = &dev->adapter;
912 adap->owner = THIS_MODULE; 912 adap->owner = THIS_MODULE;
913 /* DDC class but actually often used for more generic I2C */ 913 /* DDC class but actually often used for more generic I2C */
914 adap->class = I2C_CLASS_DDC; 914 adap->class = I2C_CLASS_DDC | I2C_CLASS_DEPRECATED;
915 strlcpy(adap->name, "ST Microelectronics DDC I2C adapter", 915 strlcpy(adap->name, "ST Microelectronics DDC I2C adapter",
916 sizeof(adap->name)); 916 sizeof(adap->name));
917 adap->nr = bus_nr; 917 adap->nr = bus_nr;
diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c
index 9704537aee3c..00f04cb5b4eb 100644
--- a/drivers/i2c/busses/i2c-tegra.c
+++ b/drivers/i2c/busses/i2c-tegra.c
@@ -794,7 +794,7 @@ static int tegra_i2c_probe(struct platform_device *pdev)
794 794
795 i2c_set_adapdata(&i2c_dev->adapter, i2c_dev); 795 i2c_set_adapdata(&i2c_dev->adapter, i2c_dev);
796 i2c_dev->adapter.owner = THIS_MODULE; 796 i2c_dev->adapter.owner = THIS_MODULE;
797 i2c_dev->adapter.class = I2C_CLASS_HWMON; 797 i2c_dev->adapter.class = I2C_CLASS_HWMON | I2C_CLASS_DEPRECATED;
798 strlcpy(i2c_dev->adapter.name, "Tegra I2C adapter", 798 strlcpy(i2c_dev->adapter.name, "Tegra I2C adapter",
799 sizeof(i2c_dev->adapter.name)); 799 sizeof(i2c_dev->adapter.name));
800 i2c_dev->adapter.algo = &tegra_i2c_algo; 800 i2c_dev->adapter.algo = &tegra_i2c_algo;
diff --git a/drivers/i2c/busses/i2c-via.c b/drivers/i2c/busses/i2c-via.c
index 49d7f14b9d27..f4a1ed757612 100644
--- a/drivers/i2c/busses/i2c-via.c
+++ b/drivers/i2c/busses/i2c-via.c
@@ -88,7 +88,7 @@ static struct i2c_adapter vt586b_adapter = {
88}; 88};
89 89
90 90
91static DEFINE_PCI_DEVICE_TABLE(vt586b_ids) = { 91static const struct pci_device_id vt586b_ids[] = {
92 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_3) }, 92 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_3) },
93 { 0, } 93 { 0, }
94}; 94};
diff --git a/drivers/i2c/busses/i2c-viapro.c b/drivers/i2c/busses/i2c-viapro.c
index 40d36df678de..6841200b6e50 100644
--- a/drivers/i2c/busses/i2c-viapro.c
+++ b/drivers/i2c/busses/i2c-viapro.c
@@ -442,7 +442,7 @@ release_region:
442 return error; 442 return error;
443} 443}
444 444
445static DEFINE_PCI_DEVICE_TABLE(vt596_ids) = { 445static const struct pci_device_id vt596_ids[] = {
446 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C596_3), 446 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C596_3),
447 .driver_data = SMBBA1 }, 447 .driver_data = SMBBA1 },
448 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C596B_3), 448 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C596B_3),
diff --git a/drivers/i2c/busses/i2c-xiic.c b/drivers/i2c/busses/i2c-xiic.c
index 28107502517f..7731f1795869 100644
--- a/drivers/i2c/busses/i2c-xiic.c
+++ b/drivers/i2c/busses/i2c-xiic.c
@@ -684,7 +684,7 @@ static const struct i2c_algorithm xiic_algorithm = {
684static struct i2c_adapter xiic_adapter = { 684static struct i2c_adapter xiic_adapter = {
685 .owner = THIS_MODULE, 685 .owner = THIS_MODULE,
686 .name = DRIVER_NAME, 686 .name = DRIVER_NAME,
687 .class = I2C_CLASS_HWMON | I2C_CLASS_SPD, 687 .class = I2C_CLASS_HWMON | I2C_CLASS_SPD | I2C_CLASS_DEPRECATED,
688 .algo = &xiic_algorithm, 688 .algo = &xiic_algorithm,
689}; 689};
690 690
diff --git a/drivers/i2c/busses/scx200_acb.c b/drivers/i2c/busses/scx200_acb.c
index 2d1d2c5653fb..cb66f9586f76 100644
--- a/drivers/i2c/busses/scx200_acb.c
+++ b/drivers/i2c/busses/scx200_acb.c
@@ -556,7 +556,7 @@ static struct platform_driver scx200_pci_driver = {
556 .remove = scx200_remove, 556 .remove = scx200_remove,
557}; 557};
558 558
559static DEFINE_PCI_DEVICE_TABLE(scx200_isa) = { 559static const struct pci_device_id scx200_isa[] = {
560 { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_SCx200_BRIDGE) }, 560 { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_SCx200_BRIDGE) },
561 { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_SC1100_BRIDGE) }, 561 { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_SC1100_BRIDGE) },
562 { 0, } 562 { 0, }
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 5fb80b8962a2..7c7f4b856bad 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -48,10 +48,13 @@
48#include <linux/rwsem.h> 48#include <linux/rwsem.h>
49#include <linux/pm_runtime.h> 49#include <linux/pm_runtime.h>
50#include <linux/acpi.h> 50#include <linux/acpi.h>
51#include <linux/jump_label.h>
51#include <asm/uaccess.h> 52#include <asm/uaccess.h>
52 53
53#include "i2c-core.h" 54#include "i2c-core.h"
54 55
56#define CREATE_TRACE_POINTS
57#include <trace/events/i2c.h>
55 58
56/* core_lock protects i2c_adapter_idr, and guarantees 59/* core_lock protects i2c_adapter_idr, and guarantees
57 that device detection, deletion of detected devices, and attach_adapter 60 that device detection, deletion of detected devices, and attach_adapter
@@ -62,6 +65,18 @@ static DEFINE_IDR(i2c_adapter_idr);
62static struct device_type i2c_client_type; 65static struct device_type i2c_client_type;
63static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver); 66static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver);
64 67
68static struct static_key i2c_trace_msg = STATIC_KEY_INIT_FALSE;
69
70void i2c_transfer_trace_reg(void)
71{
72 static_key_slow_inc(&i2c_trace_msg);
73}
74
75void i2c_transfer_trace_unreg(void)
76{
77 static_key_slow_dec(&i2c_trace_msg);
78}
79
65/* ------------------------------------------------------------------------- */ 80/* ------------------------------------------------------------------------- */
66 81
67static const struct i2c_device_id *i2c_match_id(const struct i2c_device_id *id, 82static const struct i2c_device_id *i2c_match_id(const struct i2c_device_id *id,
@@ -1686,6 +1701,7 @@ static void __exit i2c_exit(void)
1686 class_compat_unregister(i2c_adapter_compat_class); 1701 class_compat_unregister(i2c_adapter_compat_class);
1687#endif 1702#endif
1688 bus_unregister(&i2c_bus_type); 1703 bus_unregister(&i2c_bus_type);
1704 tracepoint_synchronize_unregister();
1689} 1705}
1690 1706
1691/* We must initialize early, because some subsystems register i2c drivers 1707/* We must initialize early, because some subsystems register i2c drivers
@@ -1716,6 +1732,19 @@ int __i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
1716 unsigned long orig_jiffies; 1732 unsigned long orig_jiffies;
1717 int ret, try; 1733 int ret, try;
1718 1734
1735 /* i2c_trace_msg gets enabled when tracepoint i2c_transfer gets
1736 * enabled. This is an efficient way of keeping the for-loop from
1737 * being executed when not needed.
1738 */
1739 if (static_key_false(&i2c_trace_msg)) {
1740 int i;
1741 for (i = 0; i < num; i++)
1742 if (msgs[i].flags & I2C_M_RD)
1743 trace_i2c_read(adap, &msgs[i], i);
1744 else
1745 trace_i2c_write(adap, &msgs[i], i);
1746 }
1747
1719 /* Retry automatically on arbitration loss */ 1748 /* Retry automatically on arbitration loss */
1720 orig_jiffies = jiffies; 1749 orig_jiffies = jiffies;
1721 for (ret = 0, try = 0; try <= adap->retries; try++) { 1750 for (ret = 0, try = 0; try <= adap->retries; try++) {
@@ -1726,6 +1755,14 @@ int __i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
1726 break; 1755 break;
1727 } 1756 }
1728 1757
1758 if (static_key_false(&i2c_trace_msg)) {
1759 int i;
1760 for (i = 0; i < ret; i++)
1761 if (msgs[i].flags & I2C_M_RD)
1762 trace_i2c_reply(adap, &msgs[i], i);
1763 trace_i2c_result(adap, i, ret);
1764 }
1765
1729 return ret; 1766 return ret;
1730} 1767}
1731EXPORT_SYMBOL(__i2c_transfer); 1768EXPORT_SYMBOL(__i2c_transfer);
@@ -1941,6 +1978,13 @@ static int i2c_detect_address(struct i2c_client *temp_client,
1941 struct i2c_client *client; 1978 struct i2c_client *client;
1942 1979
1943 /* Detection succeeded, instantiate the device */ 1980 /* Detection succeeded, instantiate the device */
1981 if (adapter->class & I2C_CLASS_DEPRECATED)
1982 dev_warn(&adapter->dev,
1983 "This adapter will soon drop class based instantiation of devices. "
1984 "Please make sure client 0x%02x gets instantiated by other means. "
1985 "Check 'Documentation/i2c/instantiating-devices' for details.\n",
1986 info.addr);
1987
1944 dev_dbg(&adapter->dev, "Creating %s at 0x%02x\n", 1988 dev_dbg(&adapter->dev, "Creating %s at 0x%02x\n",
1945 info.type, info.addr); 1989 info.type, info.addr);
1946 client = i2c_new_device(adapter, &info); 1990 client = i2c_new_device(adapter, &info);
@@ -2521,6 +2565,14 @@ s32 i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr, unsigned short flags,
2521 int try; 2565 int try;
2522 s32 res; 2566 s32 res;
2523 2567
2568 /* If enabled, the following two tracepoints are conditional on
2569 * read_write and protocol.
2570 */
2571 trace_smbus_write(adapter, addr, flags, read_write,
2572 command, protocol, data);
2573 trace_smbus_read(adapter, addr, flags, read_write,
2574 command, protocol);
2575
2524 flags &= I2C_M_TEN | I2C_CLIENT_PEC | I2C_CLIENT_SCCB; 2576 flags &= I2C_M_TEN | I2C_CLIENT_PEC | I2C_CLIENT_SCCB;
2525 2577
2526 if (adapter->algo->smbus_xfer) { 2578 if (adapter->algo->smbus_xfer) {
@@ -2541,15 +2593,24 @@ s32 i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr, unsigned short flags,
2541 i2c_unlock_adapter(adapter); 2593 i2c_unlock_adapter(adapter);
2542 2594
2543 if (res != -EOPNOTSUPP || !adapter->algo->master_xfer) 2595 if (res != -EOPNOTSUPP || !adapter->algo->master_xfer)
2544 return res; 2596 goto trace;
2545 /* 2597 /*
2546 * Fall back to i2c_smbus_xfer_emulated if the adapter doesn't 2598 * Fall back to i2c_smbus_xfer_emulated if the adapter doesn't
2547 * implement native support for the SMBus operation. 2599 * implement native support for the SMBus operation.
2548 */ 2600 */
2549 } 2601 }
2550 2602
2551 return i2c_smbus_xfer_emulated(adapter, addr, flags, read_write, 2603 res = i2c_smbus_xfer_emulated(adapter, addr, flags, read_write,
2552 command, protocol, data); 2604 command, protocol, data);
2605
2606trace:
2607 /* If enabled, the reply tracepoint is conditional on read_write. */
2608 trace_smbus_reply(adapter, addr, flags, read_write,
2609 command, protocol, data);
2610 trace_smbus_result(adapter, addr, flags, read_write,
2611 command, protocol, res);
2612
2613 return res;
2553} 2614}
2554EXPORT_SYMBOL(i2c_smbus_xfer); 2615EXPORT_SYMBOL(i2c_smbus_xfer);
2555 2616
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index deddeb8c337c..b556e0ab946f 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -487,6 +487,7 @@ void i2c_unlock_adapter(struct i2c_adapter *);
487#define I2C_CLASS_HWMON (1<<0) /* lm_sensors, ... */ 487#define I2C_CLASS_HWMON (1<<0) /* lm_sensors, ... */
488#define I2C_CLASS_DDC (1<<3) /* DDC bus on graphics adapters */ 488#define I2C_CLASS_DDC (1<<3) /* DDC bus on graphics adapters */
489#define I2C_CLASS_SPD (1<<7) /* Memory modules */ 489#define I2C_CLASS_SPD (1<<7) /* Memory modules */
490#define I2C_CLASS_DEPRECATED (1<<8) /* Warn users that adapter will stop using classes */
490 491
491/* Internal numbers to terminate lists */ 492/* Internal numbers to terminate lists */
492#define I2C_CLIENT_END 0xfffeU 493#define I2C_CLIENT_END 0xfffeU
diff --git a/include/linux/i2c/bfin_twi.h b/include/linux/i2c/bfin_twi.h
new file mode 100644
index 000000000000..135a4e0876ae
--- /dev/null
+++ b/include/linux/i2c/bfin_twi.h
@@ -0,0 +1,145 @@
1/*
2 * i2c-bfin-twi.h - interface to ADI TWI controller
3 *
4 * Copyright 2005-2014 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9#ifndef __I2C_BFIN_TWI_H__
10#define __I2C_BFIN_TWI_H__
11
12#include <linux/types.h>
13#include <linux/i2c.h>
14
15/*
16 * ADI twi registers layout
17 */
18struct bfin_twi_regs {
19 u16 clkdiv;
20 u16 dummy1;
21 u16 control;
22 u16 dummy2;
23 u16 slave_ctl;
24 u16 dummy3;
25 u16 slave_stat;
26 u16 dummy4;
27 u16 slave_addr;
28 u16 dummy5;
29 u16 master_ctl;
30 u16 dummy6;
31 u16 master_stat;
32 u16 dummy7;
33 u16 master_addr;
34 u16 dummy8;
35 u16 int_stat;
36 u16 dummy9;
37 u16 int_mask;
38 u16 dummy10;
39 u16 fifo_ctl;
40 u16 dummy11;
41 u16 fifo_stat;
42 u16 dummy12;
43 u32 __pad[20];
44 u16 xmt_data8;
45 u16 dummy13;
46 u16 xmt_data16;
47 u16 dummy14;
48 u16 rcv_data8;
49 u16 dummy15;
50 u16 rcv_data16;
51 u16 dummy16;
52};
53
54struct bfin_twi_iface {
55 int irq;
56 spinlock_t lock;
57 char read_write;
58 u8 command;
59 u8 *transPtr;
60 int readNum;
61 int writeNum;
62 int cur_mode;
63 int manual_stop;
64 int result;
65 struct i2c_adapter adap;
66 struct completion complete;
67 struct i2c_msg *pmsg;
68 int msg_num;
69 int cur_msg;
70 u16 saved_clkdiv;
71 u16 saved_control;
72 struct bfin_twi_regs __iomem *regs_base;
73};
74
75/* ******************** TWO-WIRE INTERFACE (TWI) MASKS ********************/
76/* TWI_CLKDIV Macros (Use: *pTWI_CLKDIV = CLKLOW(x)|CLKHI(y); ) */
77#define CLKLOW(x) ((x) & 0xFF) /* Periods Clock Is Held Low */
78#define CLKHI(y) (((y)&0xFF)<<0x8) /* Periods Before New Clock Low */
79
80/* TWI_PRESCALE Masks */
81#define PRESCALE 0x007F /* SCLKs Per Internal Time Reference (10MHz) */
82#define TWI_ENA 0x0080 /* TWI Enable */
83#define SCCB 0x0200 /* SCCB Compatibility Enable */
84
85/* TWI_SLAVE_CTL Masks */
86#define SEN 0x0001 /* Slave Enable */
87#define SADD_LEN 0x0002 /* Slave Address Length */
88#define STDVAL 0x0004 /* Slave Transmit Data Valid */
89#define NAK 0x0008 /* NAK Generated At Conclusion Of Transfer */
90#define GEN 0x0010 /* General Call Address Matching Enabled */
91
92/* TWI_SLAVE_STAT Masks */
93#define SDIR 0x0001 /* Slave Transfer Direction (RX/TX*) */
94#define GCALL 0x0002 /* General Call Indicator */
95
96/* TWI_MASTER_CTL Masks */
97#define MEN 0x0001 /* Master Mode Enable */
98#define MADD_LEN 0x0002 /* Master Address Length */
99#define MDIR 0x0004 /* Master Transmit Direction (RX/TX*) */
100#define FAST 0x0008 /* Use Fast Mode Timing Specs */
101#define STOP 0x0010 /* Issue Stop Condition */
102#define RSTART 0x0020 /* Repeat Start or Stop* At End Of Transfer */
103#define DCNT 0x3FC0 /* Data Bytes To Transfer */
104#define SDAOVR 0x4000 /* Serial Data Override */
105#define SCLOVR 0x8000 /* Serial Clock Override */
106
107/* TWI_MASTER_STAT Masks */
108#define MPROG 0x0001 /* Master Transfer In Progress */
109#define LOSTARB 0x0002 /* Lost Arbitration Indicator (Xfer Aborted) */
110#define ANAK 0x0004 /* Address Not Acknowledged */
111#define DNAK 0x0008 /* Data Not Acknowledged */
112#define BUFRDERR 0x0010 /* Buffer Read Error */
113#define BUFWRERR 0x0020 /* Buffer Write Error */
114#define SDASEN 0x0040 /* Serial Data Sense */
115#define SCLSEN 0x0080 /* Serial Clock Sense */
116#define BUSBUSY 0x0100 /* Bus Busy Indicator */
117
118/* TWI_INT_SRC and TWI_INT_ENABLE Masks */
119#define SINIT 0x0001 /* Slave Transfer Initiated */
120#define SCOMP 0x0002 /* Slave Transfer Complete */
121#define SERR 0x0004 /* Slave Transfer Error */
122#define SOVF 0x0008 /* Slave Overflow */
123#define MCOMP 0x0010 /* Master Transfer Complete */
124#define MERR 0x0020 /* Master Transfer Error */
125#define XMTSERV 0x0040 /* Transmit FIFO Service */
126#define RCVSERV 0x0080 /* Receive FIFO Service */
127
128/* TWI_FIFO_CTRL Masks */
129#define XMTFLUSH 0x0001 /* Transmit Buffer Flush */
130#define RCVFLUSH 0x0002 /* Receive Buffer Flush */
131#define XMTINTLEN 0x0004 /* Transmit Buffer Interrupt Length */
132#define RCVINTLEN 0x0008 /* Receive Buffer Interrupt Length */
133
134/* TWI_FIFO_STAT Masks */
135#define XMTSTAT 0x0003 /* Transmit FIFO Status */
136#define XMT_EMPTY 0x0000 /* Transmit FIFO Empty */
137#define XMT_HALF 0x0001 /* Transmit FIFO Has 1 Byte To Write */
138#define XMT_FULL 0x0003 /* Transmit FIFO Full (2 Bytes To Write) */
139
140#define RCVSTAT 0x000C /* Receive FIFO Status */
141#define RCV_EMPTY 0x0000 /* Receive FIFO Empty */
142#define RCV_HALF 0x0004 /* Receive FIFO Has 1 Byte To Read */
143#define RCV_FULL 0x000C /* Receive FIFO Full (2 Bytes To Read) */
144
145#endif
diff --git a/include/linux/platform_data/i2c-s3c2410.h b/include/linux/platform_data/i2c-s3c2410.h
index 2a50048c1c44..05af66b840b9 100644
--- a/include/linux/platform_data/i2c-s3c2410.h
+++ b/include/linux/platform_data/i2c-s3c2410.h
@@ -1,5 +1,4 @@
1/* arch/arm/plat-s3c/include/plat/iic.h 1/*
2 *
3 * Copyright 2004-2009 Simtec Electronics 2 * Copyright 2004-2009 Simtec Electronics
4 * Ben Dooks <ben@simtec.co.uk> 3 * Ben Dooks <ben@simtec.co.uk>
5 * 4 *
@@ -10,8 +9,8 @@
10 * published by the Free Software Foundation. 9 * published by the Free Software Foundation.
11*/ 10*/
12 11
13#ifndef __ASM_ARCH_IIC_H 12#ifndef __I2C_S3C2410_H
14#define __ASM_ARCH_IIC_H __FILE__ 13#define __I2C_S3C2410_H __FILE__
15 14
16#define S3C_IICFLG_FILTER (1<<0) /* enable s3c2440 filter */ 15#define S3C_IICFLG_FILTER (1<<0) /* enable s3c2440 filter */
17 16
@@ -76,4 +75,4 @@ extern void s3c_i2c7_cfg_gpio(struct platform_device *dev);
76 75
77extern struct s3c2410_platform_i2c default_i2c_data; 76extern struct s3c2410_platform_i2c default_i2c_data;
78 77
79#endif /* __ASM_ARCH_IIC_H */ 78#endif /* __I2C_S3C2410_H */
diff --git a/include/trace/events/i2c.h b/include/trace/events/i2c.h
new file mode 100644
index 000000000000..fe17187df65d
--- /dev/null
+++ b/include/trace/events/i2c.h
@@ -0,0 +1,372 @@
1/* I2C and SMBUS message transfer tracepoints
2 *
3 * Copyright (C) 2013 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public Licence
8 * as published by the Free Software Foundation; either version
9 * 2 of the Licence, or (at your option) any later version.
10 */
11#undef TRACE_SYSTEM
12#define TRACE_SYSTEM i2c
13
14#if !defined(_TRACE_I2C_H) || defined(TRACE_HEADER_MULTI_READ)
15#define _TRACE_I2C_H
16
17#include <linux/i2c.h>
18#include <linux/tracepoint.h>
19
20/*
21 * drivers/i2c/i2c-core.c
22 */
23extern void i2c_transfer_trace_reg(void);
24extern void i2c_transfer_trace_unreg(void);
25
26/*
27 * __i2c_transfer() write request
28 */
29TRACE_EVENT_FN(i2c_write,
30 TP_PROTO(const struct i2c_adapter *adap, const struct i2c_msg *msg,
31 int num),
32 TP_ARGS(adap, msg, num),
33 TP_STRUCT__entry(
34 __field(int, adapter_nr )
35 __field(__u16, msg_nr )
36 __field(__u16, addr )
37 __field(__u16, flags )
38 __field(__u16, len )
39 __dynamic_array(__u8, buf, msg->len) ),
40 TP_fast_assign(
41 __entry->adapter_nr = adap->nr;
42 __entry->msg_nr = num;
43 __entry->addr = msg->addr;
44 __entry->flags = msg->flags;
45 __entry->len = msg->len;
46 memcpy(__get_dynamic_array(buf), msg->buf, msg->len);
47 ),
48 TP_printk("i2c-%d #%u a=%03x f=%04x l=%u [%*phD]",
49 __entry->adapter_nr,
50 __entry->msg_nr,
51 __entry->addr,
52 __entry->flags,
53 __entry->len,
54 __entry->len, __get_dynamic_array(buf)
55 ),
56 i2c_transfer_trace_reg,
57 i2c_transfer_trace_unreg);
58
59/*
60 * __i2c_transfer() read request
61 */
62TRACE_EVENT_FN(i2c_read,
63 TP_PROTO(const struct i2c_adapter *adap, const struct i2c_msg *msg,
64 int num),
65 TP_ARGS(adap, msg, num),
66 TP_STRUCT__entry(
67 __field(int, adapter_nr )
68 __field(__u16, msg_nr )
69 __field(__u16, addr )
70 __field(__u16, flags )
71 __field(__u16, len )
72 ),
73 TP_fast_assign(
74 __entry->adapter_nr = adap->nr;
75 __entry->msg_nr = num;
76 __entry->addr = msg->addr;
77 __entry->flags = msg->flags;
78 __entry->len = msg->len;
79 ),
80 TP_printk("i2c-%d #%u a=%03x f=%04x l=%u",
81 __entry->adapter_nr,
82 __entry->msg_nr,
83 __entry->addr,
84 __entry->flags,
85 __entry->len
86 ),
87 i2c_transfer_trace_reg,
88 i2c_transfer_trace_unreg);
89
90/*
91 * __i2c_transfer() read reply
92 */
93TRACE_EVENT_FN(i2c_reply,
94 TP_PROTO(const struct i2c_adapter *adap, const struct i2c_msg *msg,
95 int num),
96 TP_ARGS(adap, msg, num),
97 TP_STRUCT__entry(
98 __field(int, adapter_nr )
99 __field(__u16, msg_nr )
100 __field(__u16, addr )
101 __field(__u16, flags )
102 __field(__u16, len )
103 __dynamic_array(__u8, buf, msg->len) ),
104 TP_fast_assign(
105 __entry->adapter_nr = adap->nr;
106 __entry->msg_nr = num;
107 __entry->addr = msg->addr;
108 __entry->flags = msg->flags;
109 __entry->len = msg->len;
110 memcpy(__get_dynamic_array(buf), msg->buf, msg->len);
111 ),
112 TP_printk("i2c-%d #%u a=%03x f=%04x l=%u [%*phD]",
113 __entry->adapter_nr,
114 __entry->msg_nr,
115 __entry->addr,
116 __entry->flags,
117 __entry->len,
118 __entry->len, __get_dynamic_array(buf)
119 ),
120 i2c_transfer_trace_reg,
121 i2c_transfer_trace_unreg);
122
123/*
124 * __i2c_transfer() result
125 */
126TRACE_EVENT_FN(i2c_result,
127 TP_PROTO(const struct i2c_adapter *adap, int num, int ret),
128 TP_ARGS(adap, num, ret),
129 TP_STRUCT__entry(
130 __field(int, adapter_nr )
131 __field(__u16, nr_msgs )
132 __field(__s16, ret )
133 ),
134 TP_fast_assign(
135 __entry->adapter_nr = adap->nr;
136 __entry->nr_msgs = num;
137 __entry->ret = ret;
138 ),
139 TP_printk("i2c-%d n=%u ret=%d",
140 __entry->adapter_nr,
141 __entry->nr_msgs,
142 __entry->ret
143 ),
144 i2c_transfer_trace_reg,
145 i2c_transfer_trace_unreg);
146
147/*
148 * i2c_smbus_xfer() write data or procedure call request
149 */
150TRACE_EVENT_CONDITION(smbus_write,
151 TP_PROTO(const struct i2c_adapter *adap,
152 u16 addr, unsigned short flags,
153 char read_write, u8 command, int protocol,
154 const union i2c_smbus_data *data),
155 TP_ARGS(adap, addr, flags, read_write, command, protocol, data),
156 TP_CONDITION(read_write == I2C_SMBUS_WRITE ||
157 protocol == I2C_SMBUS_PROC_CALL ||
158 protocol == I2C_SMBUS_BLOCK_PROC_CALL),
159 TP_STRUCT__entry(
160 __field(int, adapter_nr )
161 __field(__u16, addr )
162 __field(__u16, flags )
163 __field(__u8, command )
164 __field(__u8, len )
165 __field(__u32, protocol )
166 __array(__u8, buf, I2C_SMBUS_BLOCK_MAX + 2) ),
167 TP_fast_assign(
168 __entry->adapter_nr = adap->nr;
169 __entry->addr = addr;
170 __entry->flags = flags;
171 __entry->command = command;
172 __entry->protocol = protocol;
173
174 switch (protocol) {
175 case I2C_SMBUS_BYTE_DATA:
176 __entry->len = 1;
177 goto copy;
178 case I2C_SMBUS_WORD_DATA:
179 case I2C_SMBUS_PROC_CALL:
180 __entry->len = 2;
181 goto copy;
182 case I2C_SMBUS_BLOCK_DATA:
183 case I2C_SMBUS_BLOCK_PROC_CALL:
184 case I2C_SMBUS_I2C_BLOCK_DATA:
185 __entry->len = data->block[0] + 1;
186 copy:
187 memcpy(__entry->buf, data->block, __entry->len);
188 break;
189 case I2C_SMBUS_QUICK:
190 case I2C_SMBUS_BYTE:
191 case I2C_SMBUS_I2C_BLOCK_BROKEN:
192 default:
193 __entry->len = 0;
194 }
195 ),
196 TP_printk("i2c-%d a=%03x f=%04x c=%x %s l=%u [%*phD]",
197 __entry->adapter_nr,
198 __entry->addr,
199 __entry->flags,
200 __entry->command,
201 __print_symbolic(__entry->protocol,
202 { I2C_SMBUS_QUICK, "QUICK" },
203 { I2C_SMBUS_BYTE, "BYTE" },
204 { I2C_SMBUS_BYTE_DATA, "BYTE_DATA" },
205 { I2C_SMBUS_WORD_DATA, "WORD_DATA" },
206 { I2C_SMBUS_PROC_CALL, "PROC_CALL" },
207 { I2C_SMBUS_BLOCK_DATA, "BLOCK_DATA" },
208 { I2C_SMBUS_I2C_BLOCK_BROKEN, "I2C_BLOCK_BROKEN" },
209 { I2C_SMBUS_BLOCK_PROC_CALL, "BLOCK_PROC_CALL" },
210 { I2C_SMBUS_I2C_BLOCK_DATA, "I2C_BLOCK_DATA" }),
211 __entry->len,
212 __entry->len, __entry->buf
213 ));
214
215/*
216 * i2c_smbus_xfer() read data request
217 */
218TRACE_EVENT_CONDITION(smbus_read,
219 TP_PROTO(const struct i2c_adapter *adap,
220 u16 addr, unsigned short flags,
221 char read_write, u8 command, int protocol),
222 TP_ARGS(adap, addr, flags, read_write, command, protocol),
223 TP_CONDITION(!(read_write == I2C_SMBUS_WRITE ||
224 protocol == I2C_SMBUS_PROC_CALL ||
225 protocol == I2C_SMBUS_BLOCK_PROC_CALL)),
226 TP_STRUCT__entry(
227 __field(int, adapter_nr )
228 __field(__u16, flags )
229 __field(__u16, addr )
230 __field(__u8, command )
231 __field(__u32, protocol )
232 __array(__u8, buf, I2C_SMBUS_BLOCK_MAX + 2) ),
233 TP_fast_assign(
234 __entry->adapter_nr = adap->nr;
235 __entry->addr = addr;
236 __entry->flags = flags;
237 __entry->command = command;
238 __entry->protocol = protocol;
239 ),
240 TP_printk("i2c-%d a=%03x f=%04x c=%x %s",
241 __entry->adapter_nr,
242 __entry->addr,
243 __entry->flags,
244 __entry->command,
245 __print_symbolic(__entry->protocol,
246 { I2C_SMBUS_QUICK, "QUICK" },
247 { I2C_SMBUS_BYTE, "BYTE" },
248 { I2C_SMBUS_BYTE_DATA, "BYTE_DATA" },
249 { I2C_SMBUS_WORD_DATA, "WORD_DATA" },
250 { I2C_SMBUS_PROC_CALL, "PROC_CALL" },
251 { I2C_SMBUS_BLOCK_DATA, "BLOCK_DATA" },
252 { I2C_SMBUS_I2C_BLOCK_BROKEN, "I2C_BLOCK_BROKEN" },
253 { I2C_SMBUS_BLOCK_PROC_CALL, "BLOCK_PROC_CALL" },
254 { I2C_SMBUS_I2C_BLOCK_DATA, "I2C_BLOCK_DATA" })
255 ));
256
257/*
258 * i2c_smbus_xfer() read data or procedure call reply
259 */
260TRACE_EVENT_CONDITION(smbus_reply,
261 TP_PROTO(const struct i2c_adapter *adap,
262 u16 addr, unsigned short flags,
263 char read_write, u8 command, int protocol,
264 const union i2c_smbus_data *data),
265 TP_ARGS(adap, addr, flags, read_write, command, protocol, data),
266 TP_CONDITION(read_write == I2C_SMBUS_READ),
267 TP_STRUCT__entry(
268 __field(int, adapter_nr )
269 __field(__u16, addr )
270 __field(__u16, flags )
271 __field(__u8, command )
272 __field(__u8, len )
273 __field(__u32, protocol )
274 __array(__u8, buf, I2C_SMBUS_BLOCK_MAX + 2) ),
275 TP_fast_assign(
276 __entry->adapter_nr = adap->nr;
277 __entry->addr = addr;
278 __entry->flags = flags;
279 __entry->command = command;
280 __entry->protocol = protocol;
281
282 switch (protocol) {
283 case I2C_SMBUS_BYTE:
284 case I2C_SMBUS_BYTE_DATA:
285 __entry->len = 1;
286 goto copy;
287 case I2C_SMBUS_WORD_DATA:
288 case I2C_SMBUS_PROC_CALL:
289 __entry->len = 2;
290 goto copy;
291 case I2C_SMBUS_BLOCK_DATA:
292 case I2C_SMBUS_BLOCK_PROC_CALL:
293 case I2C_SMBUS_I2C_BLOCK_DATA:
294 __entry->len = data->block[0] + 1;
295 copy:
296 memcpy(__entry->buf, data->block, __entry->len);
297 break;
298 case I2C_SMBUS_QUICK:
299 case I2C_SMBUS_I2C_BLOCK_BROKEN:
300 default:
301 __entry->len = 0;
302 }
303 ),
304 TP_printk("i2c-%d a=%03x f=%04x c=%x %s l=%u [%*phD]",
305 __entry->adapter_nr,
306 __entry->addr,
307 __entry->flags,
308 __entry->command,
309 __print_symbolic(__entry->protocol,
310 { I2C_SMBUS_QUICK, "QUICK" },
311 { I2C_SMBUS_BYTE, "BYTE" },
312 { I2C_SMBUS_BYTE_DATA, "BYTE_DATA" },
313 { I2C_SMBUS_WORD_DATA, "WORD_DATA" },
314 { I2C_SMBUS_PROC_CALL, "PROC_CALL" },
315 { I2C_SMBUS_BLOCK_DATA, "BLOCK_DATA" },
316 { I2C_SMBUS_I2C_BLOCK_BROKEN, "I2C_BLOCK_BROKEN" },
317 { I2C_SMBUS_BLOCK_PROC_CALL, "BLOCK_PROC_CALL" },
318 { I2C_SMBUS_I2C_BLOCK_DATA, "I2C_BLOCK_DATA" }),
319 __entry->len,
320 __entry->len, __entry->buf
321 ));
322
323/*
324 * i2c_smbus_xfer() result
325 */
326TRACE_EVENT(smbus_result,
327 TP_PROTO(const struct i2c_adapter *adap,
328 u16 addr, unsigned short flags,
329 char read_write, u8 command, int protocol,
330 int res),
331 TP_ARGS(adap, addr, flags, read_write, command, protocol, res),
332 TP_STRUCT__entry(
333 __field(int, adapter_nr )
334 __field(__u16, addr )
335 __field(__u16, flags )
336 __field(__u8, read_write )
337 __field(__u8, command )
338 __field(__s16, res )
339 __field(__u32, protocol )
340 ),
341 TP_fast_assign(
342 __entry->adapter_nr = adap->nr;
343 __entry->addr = addr;
344 __entry->flags = flags;
345 __entry->read_write = read_write;
346 __entry->command = command;
347 __entry->protocol = protocol;
348 __entry->res = res;
349 ),
350 TP_printk("i2c-%d a=%03x f=%04x c=%x %s %s res=%d",
351 __entry->adapter_nr,
352 __entry->addr,
353 __entry->flags,
354 __entry->command,
355 __print_symbolic(__entry->protocol,
356 { I2C_SMBUS_QUICK, "QUICK" },
357 { I2C_SMBUS_BYTE, "BYTE" },
358 { I2C_SMBUS_BYTE_DATA, "BYTE_DATA" },
359 { I2C_SMBUS_WORD_DATA, "WORD_DATA" },
360 { I2C_SMBUS_PROC_CALL, "PROC_CALL" },
361 { I2C_SMBUS_BLOCK_DATA, "BLOCK_DATA" },
362 { I2C_SMBUS_I2C_BLOCK_BROKEN, "I2C_BLOCK_BROKEN" },
363 { I2C_SMBUS_BLOCK_PROC_CALL, "BLOCK_PROC_CALL" },
364 { I2C_SMBUS_I2C_BLOCK_DATA, "I2C_BLOCK_DATA" }),
365 __entry->read_write == I2C_SMBUS_WRITE ? "wr" : "rd",
366 __entry->res
367 ));
368
369#endif /* _TRACE_I2C_H */
370
371/* This part must be outside protection */
372#include <trace/define_trace.h>