aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2017-11-14 20:52:21 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2017-11-14 20:52:21 -0500
commit4008e6a9bcee2f3b61bb11951de0fb0ed764cb91 (patch)
treee7e3202d6d156acb57845a1824c9a8249f288c53
parent6aa2f9441f1ef21f10c41f45e6453b135e9cd736 (diff)
parentd82e99a6f9b38cb1a044b4cd979bd49fd3f67cd2 (diff)
Merge branch 'i2c/for-4.15' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/wsa/linux
Pull i2c updates from Wolfram Sang: "This contains two bigger than usual tree-wide changes this time. They all have proper acks, caused no merge conflicts in linux-next where they have been for a while. They are namely: - to-gpiod conversion of the i2c-gpio driver and its users (touching arch/* and drivers/mfd/*) - adding a sbs-manager based on I2C core updates to SMBus alerts (touching drivers/power/*) Other notable changes: - i2c_boardinfo can now carry a dev_name to be used when the device is created. This is because some devices in ACPI world need fixed names to find the regulators. - the designware driver got a long discussed overhaul of its PM handling. img-scb and davinci got PM support, too. - at24 driver has way better OF support. And it has a new maintainer. Thanks Bartosz for stepping up! The rest is regular driver updates and fixes" * 'i2c/for-4.15' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/wsa/linux: (55 commits) ARM: sa1100: simpad: Correct I2C GPIO offsets i2c: aspeed: Deassert reset in probe eeprom: at24: Add OF device ID table MAINTAINERS: new maintainer for AT24 driver i2c: nuc900: remove platform_data, too i2c: thunderx: Remove duplicate NULL check i2c: taos-evm: Remove duplicate NULL check i2c: Make i2c_unregister_device() NULL-aware i2c: xgene-slimpro: Support v2 i2c: mpc: remove useless variable initialization i2c: omap: Trigger bus recovery in lockup case i2c: gpio: Add support for named gpios in DT dt-bindings: i2c: i2c-gpio: Add support for named gpios i2c: gpio: Local vars in probe i2c: gpio: Augment all boardfiles to use open drain i2c: gpio: Enforce open drain through gpiolib gpio: Make it possible for consumers to enforce open drain i2c: gpio: Convert to use descriptors power: supply: sbs-message: fix some code style issues power: supply: sbs-battery: remove unchecked return var ...
-rw-r--r--Documentation/devicetree/bindings/eeprom/eeprom.txt2
-rw-r--r--Documentation/devicetree/bindings/i2c/i2c-aspeed.txt7
-rw-r--r--Documentation/devicetree/bindings/i2c/i2c-davinci.txt12
-rw-r--r--Documentation/devicetree/bindings/i2c/i2c-gpio.txt32
-rw-r--r--Documentation/devicetree/bindings/i2c/i2c-mux.txt4
-rw-r--r--Documentation/devicetree/bindings/i2c/i2c-rcar.txt1
-rw-r--r--Documentation/devicetree/bindings/i2c/i2c.txt4
-rw-r--r--Documentation/devicetree/bindings/power/supply/sbs,sbs-manager.txt66
-rw-r--r--MAINTAINERS2
-rw-r--r--arch/arm/mach-ep93xx/core.c41
-rw-r--r--arch/arm/mach-ep93xx/edb93xx.c15
-rw-r--r--arch/arm/mach-ep93xx/include/mach/platform.h4
-rw-r--r--arch/arm/mach-ep93xx/simone.c12
-rw-r--r--arch/arm/mach-ep93xx/snappercl15.c12
-rw-r--r--arch/arm/mach-ep93xx/vision_ep9307.c7
-rw-r--r--arch/arm/mach-ixp4xx/avila-setup.c17
-rw-r--r--arch/arm/mach-ixp4xx/dsmg600-setup.c16
-rw-r--r--arch/arm/mach-ixp4xx/fsg-setup.c16
-rw-r--r--arch/arm/mach-ixp4xx/goramo_mlr.c24
-rw-r--r--arch/arm/mach-ixp4xx/ixdp425-setup.c16
-rw-r--r--arch/arm/mach-ixp4xx/nas100d-setup.c16
-rw-r--r--arch/arm/mach-ixp4xx/nslu2-setup.c16
-rw-r--r--arch/arm/mach-ks8695/board-acs5k.c15
-rw-r--r--arch/arm/mach-pxa/palmz72.c14
-rw-r--r--arch/arm/mach-pxa/viper.c27
-rw-r--r--arch/arm/mach-sa1100/simpad.c14
-rw-r--r--arch/blackfin/mach-bf533/boards/blackstamp.c19
-rw-r--r--arch/blackfin/mach-bf533/boards/ezkit.c18
-rw-r--r--arch/blackfin/mach-bf533/boards/stamp.c18
-rw-r--r--arch/blackfin/mach-bf561/boards/ezkit.c18
-rw-r--r--arch/mips/alchemy/board-gpr.c23
-rw-r--r--arch/mips/ath79/mach-pb44.c16
-rw-r--r--drivers/acpi/acpi_apd.c5
-rw-r--r--drivers/gpio/gpiolib.c13
-rw-r--r--drivers/i2c/busses/Kconfig5
-rw-r--r--drivers/i2c/busses/i2c-aspeed.c12
-rw-r--r--drivers/i2c/busses/i2c-cht-wc.c51
-rw-r--r--drivers/i2c/busses/i2c-davinci.c69
-rw-r--r--drivers/i2c/busses/i2c-designware-core.h2
-rw-r--r--drivers/i2c/busses/i2c-designware-platdrv.c71
-rw-r--r--drivers/i2c/busses/i2c-gpio.c212
-rw-r--r--drivers/i2c/busses/i2c-img-scb.c104
-rw-r--r--drivers/i2c/busses/i2c-mpc.c4
-rw-r--r--drivers/i2c/busses/i2c-omap.c25
-rw-r--r--drivers/i2c/busses/i2c-parport-light.c1
-rw-r--r--drivers/i2c/busses/i2c-parport.c1
-rw-r--r--drivers/i2c/busses/i2c-pnx.c8
-rw-r--r--drivers/i2c/busses/i2c-riic.c115
-rw-r--r--drivers/i2c/busses/i2c-sh_mobile.c8
-rw-r--r--drivers/i2c/busses/i2c-taos-evm.c3
-rw-r--r--drivers/i2c/busses/i2c-thunderx-pcidrv.c9
-rw-r--r--drivers/i2c/busses/i2c-xgene-slimpro.c30
-rw-r--r--drivers/i2c/busses/i2c-xlp9xx.c44
-rw-r--r--drivers/i2c/i2c-core-base.c34
-rw-r--r--drivers/i2c/i2c-core-smbus.c55
-rw-r--r--drivers/i2c/i2c-smbus.c81
-rw-r--r--drivers/i2c/muxes/i2c-mux-pca954x.c95
-rw-r--r--drivers/i2c/muxes/i2c-mux-reg.c9
-rw-r--r--drivers/mfd/intel-lpss.h7
-rw-r--r--drivers/mfd/sm501.c49
-rw-r--r--drivers/misc/eeprom/at24.c112
-rw-r--r--drivers/power/supply/Kconfig14
-rw-r--r--drivers/power/supply/Makefile1
-rw-r--r--drivers/power/supply/sbs-battery.c35
-rw-r--r--drivers/power/supply/sbs-manager.c445
-rw-r--r--include/linux/gpio/consumer.h6
-rw-r--r--include/linux/i2c-gpio.h4
-rw-r--r--include/linux/i2c-smbus.h10
-rw-r--r--include/linux/i2c.h2
-rw-r--r--include/linux/platform_data/i2c-nuc900.h10
70 files changed, 1685 insertions, 600 deletions
diff --git a/Documentation/devicetree/bindings/eeprom/eeprom.txt b/Documentation/devicetree/bindings/eeprom/eeprom.txt
index afc04589eadf..27f2bc15298a 100644
--- a/Documentation/devicetree/bindings/eeprom/eeprom.txt
+++ b/Documentation/devicetree/bindings/eeprom/eeprom.txt
@@ -36,6 +36,8 @@ Optional properties:
36 36
37 - read-only: this parameterless property disables writes to the eeprom 37 - read-only: this parameterless property disables writes to the eeprom
38 38
39 - size: total eeprom size in bytes
40
39Example: 41Example:
40 42
41eeprom@52 { 43eeprom@52 {
diff --git a/Documentation/devicetree/bindings/i2c/i2c-aspeed.txt b/Documentation/devicetree/bindings/i2c/i2c-aspeed.txt
index bd6480b19535..e7106bfc1f13 100644
--- a/Documentation/devicetree/bindings/i2c/i2c-aspeed.txt
+++ b/Documentation/devicetree/bindings/i2c/i2c-aspeed.txt
@@ -7,7 +7,9 @@ Required Properties:
7- compatible : should be "aspeed,ast2400-i2c-bus" 7- compatible : should be "aspeed,ast2400-i2c-bus"
8 or "aspeed,ast2500-i2c-bus" 8 or "aspeed,ast2500-i2c-bus"
9- clocks : root clock of bus, should reference the APB 9- clocks : root clock of bus, should reference the APB
10 clock 10 clock in the second cell
11- resets : phandle to reset controller with the reset number in
12 the second cell
11- interrupts : interrupt number 13- interrupts : interrupt number
12- interrupt-parent : interrupt controller for bus, should reference a 14- interrupt-parent : interrupt controller for bus, should reference a
13 aspeed,ast2400-i2c-ic or aspeed,ast2500-i2c-ic 15 aspeed,ast2400-i2c-ic or aspeed,ast2500-i2c-ic
@@ -40,7 +42,8 @@ i2c {
40 #interrupt-cells = <1>; 42 #interrupt-cells = <1>;
41 reg = <0x40 0x40>; 43 reg = <0x40 0x40>;
42 compatible = "aspeed,ast2400-i2c-bus"; 44 compatible = "aspeed,ast2400-i2c-bus";
43 clocks = <&clk_apb>; 45 clocks = <&syscon ASPEED_CLK_APB>;
46 resets = <&syscon ASPEED_RESET_I2C>;
44 bus-frequency = <100000>; 47 bus-frequency = <100000>;
45 interrupts = <0>; 48 interrupts = <0>;
46 interrupt-parent = <&i2c_ic>; 49 interrupt-parent = <&i2c_ic>;
diff --git a/Documentation/devicetree/bindings/i2c/i2c-davinci.txt b/Documentation/devicetree/bindings/i2c/i2c-davinci.txt
index 5b123e0e4cc2..64e6e656c345 100644
--- a/Documentation/devicetree/bindings/i2c/i2c-davinci.txt
+++ b/Documentation/devicetree/bindings/i2c/i2c-davinci.txt
@@ -6,6 +6,18 @@ davinci/keystone i2c interface contains.
6Required properties: 6Required properties:
7- compatible: "ti,davinci-i2c" or "ti,keystone-i2c"; 7- compatible: "ti,davinci-i2c" or "ti,keystone-i2c";
8- reg : Offset and length of the register set for the device 8- reg : Offset and length of the register set for the device
9- clocks: I2C functional clock phandle.
10 For 66AK2G this property should be set per binding,
11 Documentation/devicetree/bindings/clock/ti,sci-clk.txt
12
13SoC-specific Required Properties:
14
15The following are mandatory properties for Keystone 2 66AK2G SoCs only:
16
17- power-domains: Should contain a phandle to a PM domain provider node
18 and an args specifier containing the I2C device id
19 value. This property is as per the binding,
20 Documentation/devicetree/bindings/soc/ti/sci-pm-domain.txt
9 21
10Recommended properties : 22Recommended properties :
11- interrupts : standard interrupt property. 23- interrupts : standard interrupt property.
diff --git a/Documentation/devicetree/bindings/i2c/i2c-gpio.txt b/Documentation/devicetree/bindings/i2c/i2c-gpio.txt
index 4f8ec947c6bd..38a05562d1d2 100644
--- a/Documentation/devicetree/bindings/i2c/i2c-gpio.txt
+++ b/Documentation/devicetree/bindings/i2c/i2c-gpio.txt
@@ -2,25 +2,39 @@ Device-Tree bindings for i2c gpio driver
2 2
3Required properties: 3Required properties:
4 - compatible = "i2c-gpio"; 4 - compatible = "i2c-gpio";
5 - gpios: sda and scl gpio 5 - sda-gpios: gpio used for the sda signal, this should be flagged as
6 6 active high using open drain with (GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN)
7 from <dt-bindings/gpio/gpio.h> since the signal is by definition
8 open drain.
9 - scl-gpios: gpio used for the scl signal, this should be flagged as
10 active high using open drain with (GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN)
11 from <dt-bindings/gpio/gpio.h> since the signal is by definition
12 open drain.
7 13
8Optional properties: 14Optional properties:
9 - i2c-gpio,sda-open-drain: sda as open drain
10 - i2c-gpio,scl-open-drain: scl as open drain
11 - i2c-gpio,scl-output-only: scl as output only 15 - i2c-gpio,scl-output-only: scl as output only
12 - i2c-gpio,delay-us: delay between GPIO operations (may depend on each platform) 16 - i2c-gpio,delay-us: delay between GPIO operations (may depend on each platform)
13 - i2c-gpio,timeout-ms: timeout to get data 17 - i2c-gpio,timeout-ms: timeout to get data
14 18
19Deprecated properties, do not use in new device tree sources:
20 - gpios: sda and scl gpio, alternative for {sda,scl}-gpios
21 - i2c-gpio,sda-open-drain: this means that something outside of our
22 control has put the GPIO line used for SDA into open drain mode, and
23 that something is not the GPIO chip. It is essentially an
24 inconsistency flag.
25 - i2c-gpio,scl-open-drain: this means that something outside of our
26 control has put the GPIO line used for SCL into open drain mode, and
27 that something is not the GPIO chip. It is essentially an
28 inconsistency flag.
29
15Example nodes: 30Example nodes:
16 31
32#include <dt-bindings/gpio/gpio.h>
33
17i2c@0 { 34i2c@0 {
18 compatible = "i2c-gpio"; 35 compatible = "i2c-gpio";
19 gpios = <&pioA 23 0 /* sda */ 36 sda-gpios = <&pioA 23 (GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN)>;
20 &pioA 24 0 /* scl */ 37 scl-gpios = <&pioA 24 (GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN)>;
21 >;
22 i2c-gpio,sda-open-drain;
23 i2c-gpio,scl-open-drain;
24 i2c-gpio,delay-us = <2>; /* ~100 kHz */ 38 i2c-gpio,delay-us = <2>; /* ~100 kHz */
25 #address-cells = <1>; 39 #address-cells = <1>;
26 #size-cells = <0>; 40 #size-cells = <0>;
diff --git a/Documentation/devicetree/bindings/i2c/i2c-mux.txt b/Documentation/devicetree/bindings/i2c/i2c-mux.txt
index 212e6779dc5c..b38f58a1c878 100644
--- a/Documentation/devicetree/bindings/i2c/i2c-mux.txt
+++ b/Documentation/devicetree/bindings/i2c/i2c-mux.txt
@@ -6,10 +6,10 @@ multiplexer/switch will have one child node for each child bus.
6 6
7Optional properties: 7Optional properties:
8- #address-cells = <1>; 8- #address-cells = <1>;
9 This property is required is the i2c-mux child node does not exist. 9 This property is required if the i2c-mux child node does not exist.
10 10
11- #size-cells = <0>; 11- #size-cells = <0>;
12 This property is required is the i2c-mux child node does not exist. 12 This property is required if the i2c-mux child node does not exist.
13 13
14- i2c-mux 14- i2c-mux
15 For i2c multiplexers/switches that have child nodes that are a mixture 15 For i2c multiplexers/switches that have child nodes that are a mixture
diff --git a/Documentation/devicetree/bindings/i2c/i2c-rcar.txt b/Documentation/devicetree/bindings/i2c/i2c-rcar.txt
index cad39aee9f73..a777477e4547 100644
--- a/Documentation/devicetree/bindings/i2c/i2c-rcar.txt
+++ b/Documentation/devicetree/bindings/i2c/i2c-rcar.txt
@@ -13,6 +13,7 @@ Required properties:
13 "renesas,i2c-r8a7794" if the device is a part of a R8A7794 SoC. 13 "renesas,i2c-r8a7794" if the device is a part of a R8A7794 SoC.
14 "renesas,i2c-r8a7795" if the device is a part of a R8A7795 SoC. 14 "renesas,i2c-r8a7795" if the device is a part of a R8A7795 SoC.
15 "renesas,i2c-r8a7796" if the device is a part of a R8A7796 SoC. 15 "renesas,i2c-r8a7796" if the device is a part of a R8A7796 SoC.
16 "renesas,i2c-r8a77970" if the device is a part of a R8A77970 SoC.
16 "renesas,rcar-gen1-i2c" for a generic R-Car Gen1 compatible device. 17 "renesas,rcar-gen1-i2c" for a generic R-Car Gen1 compatible device.
17 "renesas,rcar-gen2-i2c" for a generic R-Car Gen2 or RZ/G1 compatible 18 "renesas,rcar-gen2-i2c" for a generic R-Car Gen2 or RZ/G1 compatible
18 device. 19 device.
diff --git a/Documentation/devicetree/bindings/i2c/i2c.txt b/Documentation/devicetree/bindings/i2c/i2c.txt
index cee9d5055fa2..11263982470e 100644
--- a/Documentation/devicetree/bindings/i2c/i2c.txt
+++ b/Documentation/devicetree/bindings/i2c/i2c.txt
@@ -59,8 +59,8 @@ wants to support one of the below features, it should adapt the bindings below.
59 interrupts used by the device. 59 interrupts used by the device.
60 60
61- interrupt-names 61- interrupt-names
62 "irq" and "wakeup" names are recognized by I2C core, other names are 62 "irq", "wakeup" and "smbus_alert" names are recognized by I2C core,
63 left to individual drivers. 63 other names are left to individual drivers.
64 64
65- host-notify 65- host-notify
66 device uses SMBus host notify protocol instead of interrupt line. 66 device uses SMBus host notify protocol instead of interrupt line.
diff --git a/Documentation/devicetree/bindings/power/supply/sbs,sbs-manager.txt b/Documentation/devicetree/bindings/power/supply/sbs,sbs-manager.txt
new file mode 100644
index 000000000000..4b2195571a49
--- /dev/null
+++ b/Documentation/devicetree/bindings/power/supply/sbs,sbs-manager.txt
@@ -0,0 +1,66 @@
1Binding for sbs-manager
2
3Required properties:
4- compatible: "<vendor>,<part-number>", "sbs,sbs-charger" as fallback. The part
5 number compatible string might be used in order to take care of vendor
6 specific registers.
7- reg: integer, i2c address of the device. Should be <0xa>.
8Optional properties:
9- gpio-controller: Marks the port as GPIO controller.
10 See "gpio-specifier" in .../devicetree/bindings/gpio/gpio.txt.
11- #gpio-cells: Should be <2>. The first cell is the pin number, the second cell
12 is used to specify optional parameters:
13 See "gpio-specifier" in .../devicetree/bindings/gpio/gpio.txt.
14
15From OS view the device is basically an i2c-mux used to communicate with up to
16four smart battery devices at address 0xb. The driver actually implements this
17behaviour. So standard i2c-mux nodes can be used to register up to four slave
18batteries. Channels will be numerated starting from 1 to 4.
19
20Example:
21
22batman@a {
23 compatible = "lltc,ltc1760", "sbs,sbs-manager";
24 reg = <0x0a>;
25 #address-cells = <1>;
26 #size-cells = <0>;
27
28 gpio-controller;
29 #gpio-cells = <2>;
30
31 i2c@1 {
32 #address-cells = <1>;
33 #size-cells = <0>;
34 reg = <1>;
35
36 battery@b {
37 compatible = "ti,bq2060", "sbs,sbs-battery";
38 reg = <0x0b>;
39 sbs,battery-detect-gpios = <&batman 1 1>;
40 };
41 };
42
43 i2c@2 {
44 #address-cells = <1>;
45 #size-cells = <0>;
46 reg = <2>;
47
48 battery@b {
49 compatible = "ti,bq2060", "sbs,sbs-battery";
50 reg = <0x0b>;
51 sbs,battery-detect-gpios = <&batman 2 1>;
52 };
53 };
54
55 i2c@3 {
56 #address-cells = <1>;
57 #size-cells = <0>;
58 reg = <3>;
59
60 battery@b {
61 compatible = "ti,bq2060", "sbs,sbs-battery";
62 reg = <0x0b>;
63 sbs,battery-detect-gpios = <&batman 3 1>;
64 };
65 };
66};
diff --git a/MAINTAINERS b/MAINTAINERS
index bb8eba5e9e4f..a76f02f64469 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2249,7 +2249,7 @@ F: include/linux/dmaengine.h
2249F: include/linux/async_tx.h 2249F: include/linux/async_tx.h
2250 2250
2251AT24 EEPROM DRIVER 2251AT24 EEPROM DRIVER
2252M: Wolfram Sang <wsa@the-dreams.de> 2252M: Bartosz Golaszewski <brgl@bgdev.pl>
2253L: linux-i2c@vger.kernel.org 2253L: linux-i2c@vger.kernel.org
2254S: Maintained 2254S: Maintained
2255F: drivers/misc/eeprom/at24.c 2255F: drivers/misc/eeprom/at24.c
diff --git a/arch/arm/mach-ep93xx/core.c b/arch/arm/mach-ep93xx/core.c
index f53c61813998..e70feec6fad5 100644
--- a/arch/arm/mach-ep93xx/core.c
+++ b/arch/arm/mach-ep93xx/core.c
@@ -31,7 +31,7 @@
31#include <linux/amba/serial.h> 31#include <linux/amba/serial.h>
32#include <linux/mtd/physmap.h> 32#include <linux/mtd/physmap.h>
33#include <linux/i2c.h> 33#include <linux/i2c.h>
34#include <linux/i2c-gpio.h> 34#include <linux/gpio/machine.h>
35#include <linux/spi/spi.h> 35#include <linux/spi/spi.h>
36#include <linux/export.h> 36#include <linux/export.h>
37#include <linux/irqchip/arm-vic.h> 37#include <linux/irqchip/arm-vic.h>
@@ -320,42 +320,47 @@ void __init ep93xx_register_eth(struct ep93xx_eth_data *data, int copy_addr)
320/************************************************************************* 320/*************************************************************************
321 * EP93xx i2c peripheral handling 321 * EP93xx i2c peripheral handling
322 *************************************************************************/ 322 *************************************************************************/
323static struct i2c_gpio_platform_data ep93xx_i2c_data; 323
324/* All EP93xx devices use the same two GPIO pins for I2C bit-banging */
325static struct gpiod_lookup_table ep93xx_i2c_gpiod_table = {
326 .dev_id = "i2c-gpio",
327 .table = {
328 /* Use local offsets on gpiochip/port "G" */
329 GPIO_LOOKUP_IDX("G", 1, NULL, 0,
330 GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
331 GPIO_LOOKUP_IDX("G", 0, NULL, 1,
332 GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
333 },
334};
324 335
325static struct platform_device ep93xx_i2c_device = { 336static struct platform_device ep93xx_i2c_device = {
326 .name = "i2c-gpio", 337 .name = "i2c-gpio",
327 .id = 0, 338 .id = 0,
328 .dev = { 339 .dev = {
329 .platform_data = &ep93xx_i2c_data, 340 .platform_data = NULL,
330 }, 341 },
331}; 342};
332 343
333/** 344/**
334 * ep93xx_register_i2c - Register the i2c platform device. 345 * ep93xx_register_i2c - Register the i2c platform device.
335 * @data: platform specific i2c-gpio configuration (__initdata)
336 * @devices: platform specific i2c bus device information (__initdata) 346 * @devices: platform specific i2c bus device information (__initdata)
337 * @num: the number of devices on the i2c bus 347 * @num: the number of devices on the i2c bus
338 */ 348 */
339void __init ep93xx_register_i2c(struct i2c_gpio_platform_data *data, 349void __init ep93xx_register_i2c(struct i2c_board_info *devices, int num)
340 struct i2c_board_info *devices, int num)
341{ 350{
342 /* 351 /*
343 * Set the EEPROM interface pin drive type control. 352 * FIXME: this just sets the two pins as non-opendrain, as no
344 * Defines the driver type for the EECLK and EEDAT pins as either 353 * platforms tries to do that anyway. Flag the applicable lines
345 * open drain, which will require an external pull-up, or a normal 354 * as open drain in the GPIO_LOOKUP above and the driver or
346 * CMOS driver. 355 * gpiolib will handle open drain/open drain emulation as need
356 * be. Right now i2c-gpio emulates open drain which is not
357 * optimal.
347 */ 358 */
348 if (data->sda_is_open_drain && data->sda_pin != EP93XX_GPIO_LINE_EEDAT) 359 __raw_writel((0 << 1) | (0 << 0),
349 pr_warning("sda != EEDAT, open drain has no effect\n");
350 if (data->scl_is_open_drain && data->scl_pin != EP93XX_GPIO_LINE_EECLK)
351 pr_warning("scl != EECLK, open drain has no effect\n");
352
353 __raw_writel((data->sda_is_open_drain << 1) |
354 (data->scl_is_open_drain << 0),
355 EP93XX_GPIO_EEDRIVE); 360 EP93XX_GPIO_EEDRIVE);
356 361
357 ep93xx_i2c_data = *data;
358 i2c_register_board_info(0, devices, num); 362 i2c_register_board_info(0, devices, num);
363 gpiod_add_lookup_table(&ep93xx_i2c_gpiod_table);
359 platform_device_register(&ep93xx_i2c_device); 364 platform_device_register(&ep93xx_i2c_device);
360} 365}
361 366
diff --git a/arch/arm/mach-ep93xx/edb93xx.c b/arch/arm/mach-ep93xx/edb93xx.c
index 7a7f280b07d7..8e89ec8b6f0f 100644
--- a/arch/arm/mach-ep93xx/edb93xx.c
+++ b/arch/arm/mach-ep93xx/edb93xx.c
@@ -28,7 +28,6 @@
28#include <linux/init.h> 28#include <linux/init.h>
29#include <linux/platform_device.h> 29#include <linux/platform_device.h>
30#include <linux/i2c.h> 30#include <linux/i2c.h>
31#include <linux/i2c-gpio.h>
32#include <linux/spi/spi.h> 31#include <linux/spi/spi.h>
33 32
34#include <sound/cs4271.h> 33#include <sound/cs4271.h>
@@ -61,14 +60,6 @@ static struct ep93xx_eth_data __initdata edb93xx_eth_data = {
61/************************************************************************* 60/*************************************************************************
62 * EDB93xx i2c peripheral handling 61 * EDB93xx i2c peripheral handling
63 *************************************************************************/ 62 *************************************************************************/
64static struct i2c_gpio_platform_data __initdata edb93xx_i2c_gpio_data = {
65 .sda_pin = EP93XX_GPIO_LINE_EEDAT,
66 .sda_is_open_drain = 0,
67 .scl_pin = EP93XX_GPIO_LINE_EECLK,
68 .scl_is_open_drain = 0,
69 .udelay = 0, /* default to 100 kHz */
70 .timeout = 0, /* default to 100 ms */
71};
72 63
73static struct i2c_board_info __initdata edb93xxa_i2c_board_info[] = { 64static struct i2c_board_info __initdata edb93xxa_i2c_board_info[] = {
74 { 65 {
@@ -86,13 +77,11 @@ static void __init edb93xx_register_i2c(void)
86{ 77{
87 if (machine_is_edb9302a() || machine_is_edb9307a() || 78 if (machine_is_edb9302a() || machine_is_edb9307a() ||
88 machine_is_edb9315a()) { 79 machine_is_edb9315a()) {
89 ep93xx_register_i2c(&edb93xx_i2c_gpio_data, 80 ep93xx_register_i2c(edb93xxa_i2c_board_info,
90 edb93xxa_i2c_board_info,
91 ARRAY_SIZE(edb93xxa_i2c_board_info)); 81 ARRAY_SIZE(edb93xxa_i2c_board_info));
92 } else if (machine_is_edb9302() || machine_is_edb9307() 82 } else if (machine_is_edb9302() || machine_is_edb9307()
93 || machine_is_edb9312() || machine_is_edb9315()) { 83 || machine_is_edb9312() || machine_is_edb9315()) {
94 ep93xx_register_i2c(&edb93xx_i2c_gpio_data, 84 ep93xx_register_i2c(edb93xx_i2c_board_info,
95 edb93xx_i2c_board_info,
96 ARRAY_SIZE(edb93xx_i2c_board_info)); 85 ARRAY_SIZE(edb93xx_i2c_board_info));
97 } 86 }
98} 87}
diff --git a/arch/arm/mach-ep93xx/include/mach/platform.h b/arch/arm/mach-ep93xx/include/mach/platform.h
index 3bbe1591013e..6c41c794bed5 100644
--- a/arch/arm/mach-ep93xx/include/mach/platform.h
+++ b/arch/arm/mach-ep93xx/include/mach/platform.h
@@ -8,7 +8,6 @@
8#include <linux/reboot.h> 8#include <linux/reboot.h>
9 9
10struct device; 10struct device;
11struct i2c_gpio_platform_data;
12struct i2c_board_info; 11struct i2c_board_info;
13struct spi_board_info; 12struct spi_board_info;
14struct platform_device; 13struct platform_device;
@@ -37,8 +36,7 @@ void ep93xx_register_flash(unsigned int width,
37 resource_size_t start, resource_size_t size); 36 resource_size_t start, resource_size_t size);
38 37
39void ep93xx_register_eth(struct ep93xx_eth_data *data, int copy_addr); 38void ep93xx_register_eth(struct ep93xx_eth_data *data, int copy_addr);
40void ep93xx_register_i2c(struct i2c_gpio_platform_data *data, 39void ep93xx_register_i2c(struct i2c_board_info *devices, int num);
41 struct i2c_board_info *devices, int num);
42void ep93xx_register_spi(struct ep93xx_spi_info *info, 40void ep93xx_register_spi(struct ep93xx_spi_info *info,
43 struct spi_board_info *devices, int num); 41 struct spi_board_info *devices, int num);
44void ep93xx_register_fb(struct ep93xxfb_mach_info *data); 42void ep93xx_register_fb(struct ep93xxfb_mach_info *data);
diff --git a/arch/arm/mach-ep93xx/simone.c b/arch/arm/mach-ep93xx/simone.c
index c7a40f245892..e61f3dee24c2 100644
--- a/arch/arm/mach-ep93xx/simone.c
+++ b/arch/arm/mach-ep93xx/simone.c
@@ -19,7 +19,6 @@
19#include <linux/init.h> 19#include <linux/init.h>
20#include <linux/platform_device.h> 20#include <linux/platform_device.h>
21#include <linux/i2c.h> 21#include <linux/i2c.h>
22#include <linux/i2c-gpio.h>
23#include <linux/mmc/host.h> 22#include <linux/mmc/host.h>
24#include <linux/spi/spi.h> 23#include <linux/spi/spi.h>
25#include <linux/spi/mmc_spi.h> 24#include <linux/spi/mmc_spi.h>
@@ -129,15 +128,6 @@ static struct ep93xx_spi_info simone_spi_info __initdata = {
129 .use_dma = 1, 128 .use_dma = 1,
130}; 129};
131 130
132static struct i2c_gpio_platform_data __initdata simone_i2c_gpio_data = {
133 .sda_pin = EP93XX_GPIO_LINE_EEDAT,
134 .sda_is_open_drain = 0,
135 .scl_pin = EP93XX_GPIO_LINE_EECLK,
136 .scl_is_open_drain = 0,
137 .udelay = 0,
138 .timeout = 0,
139};
140
141static struct i2c_board_info __initdata simone_i2c_board_info[] = { 131static struct i2c_board_info __initdata simone_i2c_board_info[] = {
142 { 132 {
143 I2C_BOARD_INFO("ds1337", 0x68), 133 I2C_BOARD_INFO("ds1337", 0x68),
@@ -161,7 +151,7 @@ static void __init simone_init_machine(void)
161 ep93xx_register_flash(2, EP93XX_CS6_PHYS_BASE, SZ_8M); 151 ep93xx_register_flash(2, EP93XX_CS6_PHYS_BASE, SZ_8M);
162 ep93xx_register_eth(&simone_eth_data, 1); 152 ep93xx_register_eth(&simone_eth_data, 1);
163 ep93xx_register_fb(&simone_fb_info); 153 ep93xx_register_fb(&simone_fb_info);
164 ep93xx_register_i2c(&simone_i2c_gpio_data, simone_i2c_board_info, 154 ep93xx_register_i2c(simone_i2c_board_info,
165 ARRAY_SIZE(simone_i2c_board_info)); 155 ARRAY_SIZE(simone_i2c_board_info));
166 ep93xx_register_spi(&simone_spi_info, simone_spi_devices, 156 ep93xx_register_spi(&simone_spi_info, simone_spi_devices,
167 ARRAY_SIZE(simone_spi_devices)); 157 ARRAY_SIZE(simone_spi_devices));
diff --git a/arch/arm/mach-ep93xx/snappercl15.c b/arch/arm/mach-ep93xx/snappercl15.c
index 8b29398f4dc7..45940c1d7787 100644
--- a/arch/arm/mach-ep93xx/snappercl15.c
+++ b/arch/arm/mach-ep93xx/snappercl15.c
@@ -21,7 +21,6 @@
21#include <linux/init.h> 21#include <linux/init.h>
22#include <linux/io.h> 22#include <linux/io.h>
23#include <linux/i2c.h> 23#include <linux/i2c.h>
24#include <linux/i2c-gpio.h>
25#include <linux/fb.h> 24#include <linux/fb.h>
26 25
27#include <linux/mtd/partitions.h> 26#include <linux/mtd/partitions.h>
@@ -127,15 +126,6 @@ static struct ep93xx_eth_data __initdata snappercl15_eth_data = {
127 .phy_id = 1, 126 .phy_id = 1,
128}; 127};
129 128
130static struct i2c_gpio_platform_data __initdata snappercl15_i2c_gpio_data = {
131 .sda_pin = EP93XX_GPIO_LINE_EEDAT,
132 .sda_is_open_drain = 0,
133 .scl_pin = EP93XX_GPIO_LINE_EECLK,
134 .scl_is_open_drain = 0,
135 .udelay = 0,
136 .timeout = 0,
137};
138
139static struct i2c_board_info __initdata snappercl15_i2c_data[] = { 129static struct i2c_board_info __initdata snappercl15_i2c_data[] = {
140 { 130 {
141 /* Audio codec */ 131 /* Audio codec */
@@ -161,7 +151,7 @@ static void __init snappercl15_init_machine(void)
161{ 151{
162 ep93xx_init_devices(); 152 ep93xx_init_devices();
163 ep93xx_register_eth(&snappercl15_eth_data, 1); 153 ep93xx_register_eth(&snappercl15_eth_data, 1);
164 ep93xx_register_i2c(&snappercl15_i2c_gpio_data, snappercl15_i2c_data, 154 ep93xx_register_i2c(snappercl15_i2c_data,
165 ARRAY_SIZE(snappercl15_i2c_data)); 155 ARRAY_SIZE(snappercl15_i2c_data));
166 ep93xx_register_fb(&snappercl15_fb_info); 156 ep93xx_register_fb(&snappercl15_fb_info);
167 snappercl15_register_audio(); 157 snappercl15_register_audio();
diff --git a/arch/arm/mach-ep93xx/vision_ep9307.c b/arch/arm/mach-ep93xx/vision_ep9307.c
index 1daf9441058c..5a0b6187990a 100644
--- a/arch/arm/mach-ep93xx/vision_ep9307.c
+++ b/arch/arm/mach-ep93xx/vision_ep9307.c
@@ -22,7 +22,6 @@
22#include <linux/io.h> 22#include <linux/io.h>
23#include <linux/mtd/partitions.h> 23#include <linux/mtd/partitions.h>
24#include <linux/i2c.h> 24#include <linux/i2c.h>
25#include <linux/i2c-gpio.h>
26#include <linux/platform_data/pca953x.h> 25#include <linux/platform_data/pca953x.h>
27#include <linux/spi/spi.h> 26#include <linux/spi/spi.h>
28#include <linux/spi/flash.h> 27#include <linux/spi/flash.h>
@@ -144,10 +143,6 @@ static struct pca953x_platform_data pca953x_77_gpio_data = {
144/************************************************************************* 143/*************************************************************************
145 * I2C Bus 144 * I2C Bus
146 *************************************************************************/ 145 *************************************************************************/
147static struct i2c_gpio_platform_data vision_i2c_gpio_data __initdata = {
148 .sda_pin = EP93XX_GPIO_LINE_EEDAT,
149 .scl_pin = EP93XX_GPIO_LINE_EECLK,
150};
151 146
152static struct i2c_board_info vision_i2c_info[] __initdata = { 147static struct i2c_board_info vision_i2c_info[] __initdata = {
153 { 148 {
@@ -289,7 +284,7 @@ static void __init vision_init_machine(void)
289 284
290 vision_i2c_info[1].irq = gpio_to_irq(EP93XX_GPIO_LINE_F(7)); 285 vision_i2c_info[1].irq = gpio_to_irq(EP93XX_GPIO_LINE_F(7));
291 286
292 ep93xx_register_i2c(&vision_i2c_gpio_data, vision_i2c_info, 287 ep93xx_register_i2c(vision_i2c_info,
293 ARRAY_SIZE(vision_i2c_info)); 288 ARRAY_SIZE(vision_i2c_info));
294 ep93xx_register_spi(&vision_spi_master, vision_spi_board_info, 289 ep93xx_register_spi(&vision_spi_master, vision_spi_board_info,
295 ARRAY_SIZE(vision_spi_board_info)); 290 ARRAY_SIZE(vision_spi_board_info));
diff --git a/arch/arm/mach-ixp4xx/avila-setup.c b/arch/arm/mach-ixp4xx/avila-setup.c
index 186df64ceae7..77def6169f50 100644
--- a/arch/arm/mach-ixp4xx/avila-setup.c
+++ b/arch/arm/mach-ixp4xx/avila-setup.c
@@ -18,7 +18,7 @@
18#include <linux/serial.h> 18#include <linux/serial.h>
19#include <linux/tty.h> 19#include <linux/tty.h>
20#include <linux/serial_8250.h> 20#include <linux/serial_8250.h>
21#include <linux/i2c-gpio.h> 21#include <linux/gpio/machine.h>
22#include <asm/types.h> 22#include <asm/types.h>
23#include <asm/setup.h> 23#include <asm/setup.h>
24#include <asm/memory.h> 24#include <asm/memory.h>
@@ -50,16 +50,21 @@ static struct platform_device avila_flash = {
50 .resource = &avila_flash_resource, 50 .resource = &avila_flash_resource,
51}; 51};
52 52
53static struct i2c_gpio_platform_data avila_i2c_gpio_data = { 53static struct gpiod_lookup_table avila_i2c_gpiod_table = {
54 .sda_pin = AVILA_SDA_PIN, 54 .dev_id = "i2c-gpio",
55 .scl_pin = AVILA_SCL_PIN, 55 .table = {
56 GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", AVILA_SDA_PIN,
57 NULL, 0, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
58 GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", AVILA_SCL_PIN,
59 NULL, 1, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
60 },
56}; 61};
57 62
58static struct platform_device avila_i2c_gpio = { 63static struct platform_device avila_i2c_gpio = {
59 .name = "i2c-gpio", 64 .name = "i2c-gpio",
60 .id = 0, 65 .id = 0,
61 .dev = { 66 .dev = {
62 .platform_data = &avila_i2c_gpio_data, 67 .platform_data = NULL,
63 }, 68 },
64}; 69};
65 70
@@ -148,6 +153,8 @@ static void __init avila_init(void)
148 avila_flash_resource.end = 153 avila_flash_resource.end =
149 IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1; 154 IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1;
150 155
156 gpiod_add_lookup_table(&avila_i2c_gpiod_table);
157
151 platform_add_devices(avila_devices, ARRAY_SIZE(avila_devices)); 158 platform_add_devices(avila_devices, ARRAY_SIZE(avila_devices));
152 159
153 avila_pata_resources[0].start = IXP4XX_EXP_BUS_BASE(1); 160 avila_pata_resources[0].start = IXP4XX_EXP_BUS_BASE(1);
diff --git a/arch/arm/mach-ixp4xx/dsmg600-setup.c b/arch/arm/mach-ixp4xx/dsmg600-setup.c
index 19839bba7f17..ac97a4599034 100644
--- a/arch/arm/mach-ixp4xx/dsmg600-setup.c
+++ b/arch/arm/mach-ixp4xx/dsmg600-setup.c
@@ -26,7 +26,7 @@
26#include <linux/leds.h> 26#include <linux/leds.h>
27#include <linux/reboot.h> 27#include <linux/reboot.h>
28#include <linux/i2c.h> 28#include <linux/i2c.h>
29#include <linux/i2c-gpio.h> 29#include <linux/gpio/machine.h>
30 30
31#include <mach/hardware.h> 31#include <mach/hardware.h>
32 32
@@ -69,16 +69,21 @@ static struct platform_device dsmg600_flash = {
69 .resource = &dsmg600_flash_resource, 69 .resource = &dsmg600_flash_resource,
70}; 70};
71 71
72static struct i2c_gpio_platform_data dsmg600_i2c_gpio_data = { 72static struct gpiod_lookup_table dsmg600_i2c_gpiod_table = {
73 .sda_pin = DSMG600_SDA_PIN, 73 .dev_id = "i2c-gpio",
74 .scl_pin = DSMG600_SCL_PIN, 74 .table = {
75 GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", DSMG600_SDA_PIN,
76 NULL, 0, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
77 GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", DSMG600_SCL_PIN,
78 NULL, 1, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
79 },
75}; 80};
76 81
77static struct platform_device dsmg600_i2c_gpio = { 82static struct platform_device dsmg600_i2c_gpio = {
78 .name = "i2c-gpio", 83 .name = "i2c-gpio",
79 .id = 0, 84 .id = 0,
80 .dev = { 85 .dev = {
81 .platform_data = &dsmg600_i2c_gpio_data, 86 .platform_data = NULL,
82 }, 87 },
83}; 88};
84 89
@@ -270,6 +275,7 @@ static void __init dsmg600_init(void)
270 dsmg600_flash_resource.end = 275 dsmg600_flash_resource.end =
271 IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1; 276 IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1;
272 277
278 gpiod_add_lookup_table(&dsmg600_i2c_gpiod_table);
273 i2c_register_board_info(0, dsmg600_i2c_board_info, 279 i2c_register_board_info(0, dsmg600_i2c_board_info,
274 ARRAY_SIZE(dsmg600_i2c_board_info)); 280 ARRAY_SIZE(dsmg600_i2c_board_info));
275 281
diff --git a/arch/arm/mach-ixp4xx/fsg-setup.c b/arch/arm/mach-ixp4xx/fsg-setup.c
index 6e32cbc4f590..033f79b35d51 100644
--- a/arch/arm/mach-ixp4xx/fsg-setup.c
+++ b/arch/arm/mach-ixp4xx/fsg-setup.c
@@ -23,7 +23,7 @@
23#include <linux/leds.h> 23#include <linux/leds.h>
24#include <linux/reboot.h> 24#include <linux/reboot.h>
25#include <linux/i2c.h> 25#include <linux/i2c.h>
26#include <linux/i2c-gpio.h> 26#include <linux/gpio/machine.h>
27#include <linux/io.h> 27#include <linux/io.h>
28#include <asm/mach-types.h> 28#include <asm/mach-types.h>
29#include <asm/mach/arch.h> 29#include <asm/mach/arch.h>
@@ -55,16 +55,21 @@ static struct platform_device fsg_flash = {
55 .resource = &fsg_flash_resource, 55 .resource = &fsg_flash_resource,
56}; 56};
57 57
58static struct i2c_gpio_platform_data fsg_i2c_gpio_data = { 58static struct gpiod_lookup_table fsg_i2c_gpiod_table = {
59 .sda_pin = FSG_SDA_PIN, 59 .dev_id = "i2c-gpio",
60 .scl_pin = FSG_SCL_PIN, 60 .table = {
61 GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", FSG_SDA_PIN,
62 NULL, 0, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
63 GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", FSG_SCL_PIN,
64 NULL, 1, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
65 },
61}; 66};
62 67
63static struct platform_device fsg_i2c_gpio = { 68static struct platform_device fsg_i2c_gpio = {
64 .name = "i2c-gpio", 69 .name = "i2c-gpio",
65 .id = 0, 70 .id = 0,
66 .dev = { 71 .dev = {
67 .platform_data = &fsg_i2c_gpio_data, 72 .platform_data = NULL,
68 }, 73 },
69}; 74};
70 75
@@ -197,6 +202,7 @@ static void __init fsg_init(void)
197 /* Configure CS2 for operation, 8bit and writable */ 202 /* Configure CS2 for operation, 8bit and writable */
198 *IXP4XX_EXP_CS2 = 0xbfff0002; 203 *IXP4XX_EXP_CS2 = 0xbfff0002;
199 204
205 gpiod_add_lookup_table(&fsg_i2c_gpiod_table);
200 i2c_register_board_info(0, fsg_i2c_board_info, 206 i2c_register_board_info(0, fsg_i2c_board_info,
201 ARRAY_SIZE(fsg_i2c_board_info)); 207 ARRAY_SIZE(fsg_i2c_board_info));
202 208
diff --git a/arch/arm/mach-ixp4xx/goramo_mlr.c b/arch/arm/mach-ixp4xx/goramo_mlr.c
index 145ec5c1b0eb..4d805080020e 100644
--- a/arch/arm/mach-ixp4xx/goramo_mlr.c
+++ b/arch/arm/mach-ixp4xx/goramo_mlr.c
@@ -7,7 +7,6 @@
7#include <linux/delay.h> 7#include <linux/delay.h>
8#include <linux/gpio.h> 8#include <linux/gpio.h>
9#include <linux/hdlc.h> 9#include <linux/hdlc.h>
10#include <linux/i2c-gpio.h>
11#include <linux/io.h> 10#include <linux/io.h>
12#include <linux/irq.h> 11#include <linux/irq.h>
13#include <linux/kernel.h> 12#include <linux/kernel.h>
@@ -79,6 +78,12 @@
79static u32 hw_bits = 0xFFFFFFFD; /* assume all hardware present */; 78static u32 hw_bits = 0xFFFFFFFD; /* assume all hardware present */;
80static u8 control_value; 79static u8 control_value;
81 80
81/*
82 * FIXME: this is reimplementing I2C bit-bangining. Move this
83 * over to using driver/i2c/busses/i2c-gpio.c like all other boards
84 * and register proper I2C device(s) on the bus for this. (See
85 * other IXP4xx boards for examples.)
86 */
82static void set_scl(u8 value) 87static void set_scl(u8 value)
83{ 88{
84 gpio_set_value(GPIO_SCL, !!value); 89 gpio_set_value(GPIO_SCL, !!value);
@@ -217,20 +222,6 @@ static struct platform_device device_flash = {
217 .resource = &flash_resource, 222 .resource = &flash_resource,
218}; 223};
219 224
220
221/* I^2C interface */
222static struct i2c_gpio_platform_data i2c_data = {
223 .sda_pin = GPIO_SDA,
224 .scl_pin = GPIO_SCL,
225};
226
227static struct platform_device device_i2c = {
228 .name = "i2c-gpio",
229 .id = 0,
230 .dev = { .platform_data = &i2c_data },
231};
232
233
234/* IXP425 2 UART ports */ 225/* IXP425 2 UART ports */
235static struct resource uart_resources[] = { 226static struct resource uart_resources[] = {
236 { 227 {
@@ -412,9 +403,6 @@ static void __init gmlr_init(void)
412 if (hw_bits & CFG_HW_HAS_HSS1) 403 if (hw_bits & CFG_HW_HAS_HSS1)
413 device_tab[devices++] = &device_hss_tab[1]; /* max index 5 */ 404 device_tab[devices++] = &device_hss_tab[1]; /* max index 5 */
414 405
415 if (hw_bits & CFG_HW_HAS_EEPROM)
416 device_tab[devices++] = &device_i2c; /* max index 6 */
417
418 gpio_request(GPIO_SCL, "SCL/clock"); 406 gpio_request(GPIO_SCL, "SCL/clock");
419 gpio_request(GPIO_SDA, "SDA/data"); 407 gpio_request(GPIO_SDA, "SDA/data");
420 gpio_request(GPIO_STR, "strobe"); 408 gpio_request(GPIO_STR, "strobe");
diff --git a/arch/arm/mach-ixp4xx/ixdp425-setup.c b/arch/arm/mach-ixp4xx/ixdp425-setup.c
index 8f5e01527b1b..b168e2fbdbeb 100644
--- a/arch/arm/mach-ixp4xx/ixdp425-setup.c
+++ b/arch/arm/mach-ixp4xx/ixdp425-setup.c
@@ -15,7 +15,7 @@
15#include <linux/serial.h> 15#include <linux/serial.h>
16#include <linux/tty.h> 16#include <linux/tty.h>
17#include <linux/serial_8250.h> 17#include <linux/serial_8250.h>
18#include <linux/i2c-gpio.h> 18#include <linux/gpio/machine.h>
19#include <linux/io.h> 19#include <linux/io.h>
20#include <linux/mtd/mtd.h> 20#include <linux/mtd/mtd.h>
21#include <linux/mtd/rawnand.h> 21#include <linux/mtd/rawnand.h>
@@ -123,16 +123,21 @@ static struct platform_device ixdp425_flash_nand = {
123}; 123};
124#endif /* CONFIG_MTD_NAND_PLATFORM */ 124#endif /* CONFIG_MTD_NAND_PLATFORM */
125 125
126static struct i2c_gpio_platform_data ixdp425_i2c_gpio_data = { 126static struct gpiod_lookup_table ixdp425_i2c_gpiod_table = {
127 .sda_pin = IXDP425_SDA_PIN, 127 .dev_id = "i2c-gpio",
128 .scl_pin = IXDP425_SCL_PIN, 128 .table = {
129 GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", IXDP425_SDA_PIN,
130 NULL, 0, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
131 GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", IXDP425_SCL_PIN,
132 NULL, 1, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
133 },
129}; 134};
130 135
131static struct platform_device ixdp425_i2c_gpio = { 136static struct platform_device ixdp425_i2c_gpio = {
132 .name = "i2c-gpio", 137 .name = "i2c-gpio",
133 .id = 0, 138 .id = 0,
134 .dev = { 139 .dev = {
135 .platform_data = &ixdp425_i2c_gpio_data, 140 .platform_data = NULL,
136 }, 141 },
137}; 142};
138 143
@@ -246,6 +251,7 @@ static void __init ixdp425_init(void)
246 ixdp425_uart_data[1].flags = 0; 251 ixdp425_uart_data[1].flags = 0;
247 } 252 }
248 253
254 gpiod_add_lookup_table(&ixdp425_i2c_gpiod_table);
249 platform_add_devices(ixdp425_devices, ARRAY_SIZE(ixdp425_devices)); 255 platform_add_devices(ixdp425_devices, ARRAY_SIZE(ixdp425_devices));
250} 256}
251 257
diff --git a/arch/arm/mach-ixp4xx/nas100d-setup.c b/arch/arm/mach-ixp4xx/nas100d-setup.c
index b6d731241317..435602085408 100644
--- a/arch/arm/mach-ixp4xx/nas100d-setup.c
+++ b/arch/arm/mach-ixp4xx/nas100d-setup.c
@@ -28,7 +28,7 @@
28#include <linux/leds.h> 28#include <linux/leds.h>
29#include <linux/reboot.h> 29#include <linux/reboot.h>
30#include <linux/i2c.h> 30#include <linux/i2c.h>
31#include <linux/i2c-gpio.h> 31#include <linux/gpio/machine.h>
32#include <linux/io.h> 32#include <linux/io.h>
33#include <asm/mach-types.h> 33#include <asm/mach-types.h>
34#include <asm/mach/arch.h> 34#include <asm/mach/arch.h>
@@ -101,16 +101,21 @@ static struct platform_device nas100d_leds = {
101 .dev.platform_data = &nas100d_led_data, 101 .dev.platform_data = &nas100d_led_data,
102}; 102};
103 103
104static struct i2c_gpio_platform_data nas100d_i2c_gpio_data = { 104static struct gpiod_lookup_table nas100d_i2c_gpiod_table = {
105 .sda_pin = NAS100D_SDA_PIN, 105 .dev_id = "i2c-gpio",
106 .scl_pin = NAS100D_SCL_PIN, 106 .table = {
107 GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", NAS100D_SDA_PIN,
108 NULL, 0, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
109 GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", NAS100D_SCL_PIN,
110 NULL, 1, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
111 },
107}; 112};
108 113
109static struct platform_device nas100d_i2c_gpio = { 114static struct platform_device nas100d_i2c_gpio = {
110 .name = "i2c-gpio", 115 .name = "i2c-gpio",
111 .id = 0, 116 .id = 0,
112 .dev = { 117 .dev = {
113 .platform_data = &nas100d_i2c_gpio_data, 118 .platform_data = NULL,
114 }, 119 },
115}; 120};
116 121
@@ -281,6 +286,7 @@ static void __init nas100d_init(void)
281 nas100d_flash_resource.end = 286 nas100d_flash_resource.end =
282 IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1; 287 IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1;
283 288
289 gpiod_add_lookup_table(&nas100d_i2c_gpiod_table);
284 i2c_register_board_info(0, nas100d_i2c_board_info, 290 i2c_register_board_info(0, nas100d_i2c_board_info,
285 ARRAY_SIZE(nas100d_i2c_board_info)); 291 ARRAY_SIZE(nas100d_i2c_board_info));
286 292
diff --git a/arch/arm/mach-ixp4xx/nslu2-setup.c b/arch/arm/mach-ixp4xx/nslu2-setup.c
index bd8dc65b4ffc..91da63a7d7b5 100644
--- a/arch/arm/mach-ixp4xx/nslu2-setup.c
+++ b/arch/arm/mach-ixp4xx/nslu2-setup.c
@@ -25,7 +25,7 @@
25#include <linux/leds.h> 25#include <linux/leds.h>
26#include <linux/reboot.h> 26#include <linux/reboot.h>
27#include <linux/i2c.h> 27#include <linux/i2c.h>
28#include <linux/i2c-gpio.h> 28#include <linux/gpio/machine.h>
29#include <linux/io.h> 29#include <linux/io.h>
30#include <asm/mach-types.h> 30#include <asm/mach-types.h>
31#include <asm/mach/arch.h> 31#include <asm/mach/arch.h>
@@ -69,9 +69,14 @@ static struct platform_device nslu2_flash = {
69 .resource = &nslu2_flash_resource, 69 .resource = &nslu2_flash_resource,
70}; 70};
71 71
72static struct i2c_gpio_platform_data nslu2_i2c_gpio_data = { 72static struct gpiod_lookup_table nslu2_i2c_gpiod_table = {
73 .sda_pin = NSLU2_SDA_PIN, 73 .dev_id = "i2c-gpio",
74 .scl_pin = NSLU2_SCL_PIN, 74 .table = {
75 GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", NSLU2_SDA_PIN,
76 NULL, 0, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
77 GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", NSLU2_SCL_PIN,
78 NULL, 1, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
79 },
75}; 80};
76 81
77static struct i2c_board_info __initdata nslu2_i2c_board_info [] = { 82static struct i2c_board_info __initdata nslu2_i2c_board_info [] = {
@@ -116,7 +121,7 @@ static struct platform_device nslu2_i2c_gpio = {
116 .name = "i2c-gpio", 121 .name = "i2c-gpio",
117 .id = 0, 122 .id = 0,
118 .dev = { 123 .dev = {
119 .platform_data = &nslu2_i2c_gpio_data, 124 .platform_data = NULL,
120 }, 125 },
121}; 126};
122 127
@@ -251,6 +256,7 @@ static void __init nslu2_init(void)
251 nslu2_flash_resource.end = 256 nslu2_flash_resource.end =
252 IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1; 257 IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1;
253 258
259 gpiod_add_lookup_table(&nslu2_i2c_gpiod_table);
254 i2c_register_board_info(0, nslu2_i2c_board_info, 260 i2c_register_board_info(0, nslu2_i2c_board_info,
255 ARRAY_SIZE(nslu2_i2c_board_info)); 261 ARRAY_SIZE(nslu2_i2c_board_info));
256 262
diff --git a/arch/arm/mach-ks8695/board-acs5k.c b/arch/arm/mach-ks8695/board-acs5k.c
index e4d709c8ed32..937eb1d47e7b 100644
--- a/arch/arm/mach-ks8695/board-acs5k.c
+++ b/arch/arm/mach-ks8695/board-acs5k.c
@@ -16,7 +16,7 @@
16#include <linux/interrupt.h> 16#include <linux/interrupt.h>
17#include <linux/init.h> 17#include <linux/init.h>
18#include <linux/platform_device.h> 18#include <linux/platform_device.h>
19 19#include <linux/gpio/machine.h>
20#include <linux/i2c.h> 20#include <linux/i2c.h>
21#include <linux/i2c-algo-bit.h> 21#include <linux/i2c-algo-bit.h>
22#include <linux/i2c-gpio.h> 22#include <linux/i2c-gpio.h>
@@ -38,9 +38,17 @@
38 38
39#include "generic.h" 39#include "generic.h"
40 40
41static struct gpiod_lookup_table acs5k_i2c_gpiod_table = {
42 .dev_id = "i2c-gpio",
43 .table = {
44 GPIO_LOOKUP_IDX("KS8695", 4, NULL, 0,
45 GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
46 GPIO_LOOKUP_IDX("KS8695", 5, NULL, 1,
47 GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
48 },
49};
50
41static struct i2c_gpio_platform_data acs5k_i2c_device_platdata = { 51static struct i2c_gpio_platform_data acs5k_i2c_device_platdata = {
42 .sda_pin = 4,
43 .scl_pin = 5,
44 .udelay = 10, 52 .udelay = 10,
45}; 53};
46 54
@@ -95,6 +103,7 @@ static struct i2c_board_info acs5k_i2c_devs[] __initdata = {
95static void acs5k_i2c_init(void) 103static void acs5k_i2c_init(void)
96{ 104{
97 /* The gpio interface */ 105 /* The gpio interface */
106 gpiod_add_lookup_table(&acs5k_i2c_gpiod_table);
98 platform_device_register(&acs5k_i2c_device); 107 platform_device_register(&acs5k_i2c_device);
99 /* I2C devices */ 108 /* I2C devices */
100 i2c_register_board_info(0, acs5k_i2c_devs, 109 i2c_register_board_info(0, acs5k_i2c_devs,
diff --git a/arch/arm/mach-pxa/palmz72.c b/arch/arm/mach-pxa/palmz72.c
index 29630061e700..5877e547cecd 100644
--- a/arch/arm/mach-pxa/palmz72.c
+++ b/arch/arm/mach-pxa/palmz72.c
@@ -31,6 +31,7 @@
31#include <linux/power_supply.h> 31#include <linux/power_supply.h>
32#include <linux/usb/gpio_vbus.h> 32#include <linux/usb/gpio_vbus.h>
33#include <linux/i2c-gpio.h> 33#include <linux/i2c-gpio.h>
34#include <linux/gpio/machine.h>
34 35
35#include <asm/mach-types.h> 36#include <asm/mach-types.h>
36#include <asm/suspend.h> 37#include <asm/suspend.h>
@@ -320,9 +321,17 @@ static struct soc_camera_link palmz72_iclink = {
320 .flags = SOCAM_DATAWIDTH_8, 321 .flags = SOCAM_DATAWIDTH_8,
321}; 322};
322 323
324static struct gpiod_lookup_table palmz72_i2c_gpiod_table = {
325 .dev_id = "i2c-gpio",
326 .table = {
327 GPIO_LOOKUP_IDX("gpio-pxa", 118, NULL, 0,
328 GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
329 GPIO_LOOKUP_IDX("gpio-pxa", 117, NULL, 1,
330 GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
331 },
332};
333
323static struct i2c_gpio_platform_data palmz72_i2c_bus_data = { 334static struct i2c_gpio_platform_data palmz72_i2c_bus_data = {
324 .sda_pin = 118,
325 .scl_pin = 117,
326 .udelay = 10, 335 .udelay = 10,
327 .timeout = 100, 336 .timeout = 100,
328}; 337};
@@ -369,6 +378,7 @@ static void __init palmz72_camera_init(void)
369{ 378{
370 palmz72_cam_gpio_init(); 379 palmz72_cam_gpio_init();
371 pxa_set_camera_info(&palmz72_pxacamera_platform_data); 380 pxa_set_camera_info(&palmz72_pxacamera_platform_data);
381 gpiod_add_lookup_table(&palmz72_i2c_gpiod_table);
372 platform_device_register(&palmz72_i2c_bus_device); 382 platform_device_register(&palmz72_i2c_bus_device);
373 platform_device_register(&palmz72_camera); 383 platform_device_register(&palmz72_camera);
374} 384}
diff --git a/arch/arm/mach-pxa/viper.c b/arch/arm/mach-pxa/viper.c
index 8e89d91b206b..4185e7ff073f 100644
--- a/arch/arm/mach-pxa/viper.c
+++ b/arch/arm/mach-pxa/viper.c
@@ -36,6 +36,7 @@
36#include <linux/gpio.h> 36#include <linux/gpio.h>
37#include <linux/jiffies.h> 37#include <linux/jiffies.h>
38#include <linux/i2c-gpio.h> 38#include <linux/i2c-gpio.h>
39#include <linux/gpio/machine.h>
39#include <linux/i2c/pxa-i2c.h> 40#include <linux/i2c/pxa-i2c.h>
40#include <linux/serial_8250.h> 41#include <linux/serial_8250.h>
41#include <linux/smc91x.h> 42#include <linux/smc91x.h>
@@ -458,9 +459,17 @@ static struct platform_device smc91x_device = {
458}; 459};
459 460
460/* i2c */ 461/* i2c */
462static struct gpiod_lookup_table viper_i2c_gpiod_table = {
463 .dev_id = "i2c-gpio",
464 .table = {
465 GPIO_LOOKUP_IDX("gpio-pxa", VIPER_RTC_I2C_SDA_GPIO,
466 NULL, 0, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
467 GPIO_LOOKUP_IDX("gpio-pxa", VIPER_RTC_I2C_SCL_GPIO,
468 NULL, 1, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
469 },
470};
471
461static struct i2c_gpio_platform_data i2c_bus_data = { 472static struct i2c_gpio_platform_data i2c_bus_data = {
462 .sda_pin = VIPER_RTC_I2C_SDA_GPIO,
463 .scl_pin = VIPER_RTC_I2C_SCL_GPIO,
464 .udelay = 10, 473 .udelay = 10,
465 .timeout = HZ, 474 .timeout = HZ,
466}; 475};
@@ -779,12 +788,20 @@ static int __init viper_tpm_setup(char *str)
779 788
780__setup("tpm=", viper_tpm_setup); 789__setup("tpm=", viper_tpm_setup);
781 790
791struct gpiod_lookup_table viper_tpm_i2c_gpiod_table = {
792 .dev_id = "i2c-gpio",
793 .table = {
794 GPIO_LOOKUP_IDX("gpio-pxa", VIPER_TPM_I2C_SDA_GPIO,
795 NULL, 0, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
796 GPIO_LOOKUP_IDX("gpio-pxa", VIPER_TPM_I2C_SCL_GPIO,
797 NULL, 1, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
798 },
799};
800
782static void __init viper_tpm_init(void) 801static void __init viper_tpm_init(void)
783{ 802{
784 struct platform_device *tpm_device; 803 struct platform_device *tpm_device;
785 struct i2c_gpio_platform_data i2c_tpm_data = { 804 struct i2c_gpio_platform_data i2c_tpm_data = {
786 .sda_pin = VIPER_TPM_I2C_SDA_GPIO,
787 .scl_pin = VIPER_TPM_I2C_SCL_GPIO,
788 .udelay = 10, 805 .udelay = 10,
789 .timeout = HZ, 806 .timeout = HZ,
790 }; 807 };
@@ -794,6 +811,7 @@ static void __init viper_tpm_init(void)
794 if (!viper_tpm) 811 if (!viper_tpm)
795 return; 812 return;
796 813
814 gpiod_add_lookup_table(&viper_tpm_i2c_gpiod_table);
797 tpm_device = platform_device_alloc("i2c-gpio", 2); 815 tpm_device = platform_device_alloc("i2c-gpio", 2);
798 if (tpm_device) { 816 if (tpm_device) {
799 if (!platform_device_add_data(tpm_device, 817 if (!platform_device_add_data(tpm_device,
@@ -943,6 +961,7 @@ static void __init viper_init(void)
943 smc91x_device.num_resources--; 961 smc91x_device.num_resources--;
944 962
945 pxa_set_i2c_info(NULL); 963 pxa_set_i2c_info(NULL);
964 gpiod_add_lookup_table(&viper_i2c_gpiod_table);
946 pwm_add_table(viper_pwm_lookup, ARRAY_SIZE(viper_pwm_lookup)); 965 pwm_add_table(viper_pwm_lookup, ARRAY_SIZE(viper_pwm_lookup));
947 platform_add_devices(viper_devs, ARRAY_SIZE(viper_devs)); 966 platform_add_devices(viper_devs, ARRAY_SIZE(viper_devs));
948 967
diff --git a/arch/arm/mach-sa1100/simpad.c b/arch/arm/mach-sa1100/simpad.c
index e8d25a7bbcb8..7d4feb8a49ac 100644
--- a/arch/arm/mach-sa1100/simpad.c
+++ b/arch/arm/mach-sa1100/simpad.c
@@ -17,6 +17,7 @@
17#include <linux/mtd/partitions.h> 17#include <linux/mtd/partitions.h>
18#include <linux/io.h> 18#include <linux/io.h>
19#include <linux/gpio/driver.h> 19#include <linux/gpio/driver.h>
20#include <linux/gpio/machine.h>
20 21
21#include <mach/hardware.h> 22#include <mach/hardware.h>
22#include <asm/setup.h> 23#include <asm/setup.h>
@@ -324,9 +325,17 @@ static struct platform_device simpad_gpio_leds = {
324/* 325/*
325 * i2c 326 * i2c
326 */ 327 */
328static struct gpiod_lookup_table simpad_i2c_gpiod_table = {
329 .dev_id = "i2c-gpio",
330 .table = {
331 GPIO_LOOKUP_IDX("gpio", 21, NULL, 0,
332 GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
333 GPIO_LOOKUP_IDX("gpio", 25, NULL, 1,
334 GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
335 },
336};
337
327static struct i2c_gpio_platform_data simpad_i2c_data = { 338static struct i2c_gpio_platform_data simpad_i2c_data = {
328 .sda_pin = GPIO_GPIO21,
329 .scl_pin = GPIO_GPIO25,
330 .udelay = 10, 339 .udelay = 10,
331 .timeout = HZ, 340 .timeout = HZ,
332}; 341};
@@ -381,6 +390,7 @@ static int __init simpad_init(void)
381 ARRAY_SIZE(simpad_flash_resources)); 390 ARRAY_SIZE(simpad_flash_resources));
382 sa11x0_register_mcp(&simpad_mcp_data); 391 sa11x0_register_mcp(&simpad_mcp_data);
383 392
393 gpiod_add_lookup_table(&simpad_i2c_gpiod_table);
384 ret = platform_add_devices(devices, ARRAY_SIZE(devices)); 394 ret = platform_add_devices(devices, ARRAY_SIZE(devices));
385 if(ret) 395 if(ret)
386 printk(KERN_WARNING "simpad: Unable to register mq200 framebuffer device"); 396 printk(KERN_WARNING "simpad: Unable to register mq200 framebuffer device");
diff --git a/arch/blackfin/mach-bf533/boards/blackstamp.c b/arch/blackfin/mach-bf533/boards/blackstamp.c
index 0ccf0cf4daaf..fab69c736515 100644
--- a/arch/blackfin/mach-bf533/boards/blackstamp.c
+++ b/arch/blackfin/mach-bf533/boards/blackstamp.c
@@ -22,6 +22,7 @@
22#include <linux/irq.h> 22#include <linux/irq.h>
23#include <linux/gpio.h> 23#include <linux/gpio.h>
24#include <linux/i2c.h> 24#include <linux/i2c.h>
25#include <linux/gpio/machine.h>
25#include <asm/dma.h> 26#include <asm/dma.h>
26#include <asm/bfin5xx_spi.h> 27#include <asm/bfin5xx_spi.h>
27#include <asm/portmux.h> 28#include <asm/portmux.h>
@@ -362,11 +363,17 @@ static struct platform_device bfin_device_gpiokeys = {
362#if IS_ENABLED(CONFIG_I2C_GPIO) 363#if IS_ENABLED(CONFIG_I2C_GPIO)
363#include <linux/i2c-gpio.h> 364#include <linux/i2c-gpio.h>
364 365
366static struct gpiod_lookup_table bfin_i2c_gpiod_table = {
367 .dev_id = "i2c-gpio",
368 .table = {
369 GPIO_LOOKUP_IDX("BFIN-GPIO", GPIO_PF8, NULL, 0,
370 GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
371 GPIO_LOOKUP_IDX("BFIN-GPIO", GPIO_PF9, NULL, 1,
372 GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
373 },
374};
375
365static struct i2c_gpio_platform_data i2c_gpio_data = { 376static struct i2c_gpio_platform_data i2c_gpio_data = {
366 .sda_pin = GPIO_PF8,
367 .scl_pin = GPIO_PF9,
368 .sda_is_open_drain = 0,
369 .scl_is_open_drain = 0,
370 .udelay = 40, 377 .udelay = 40,
371}; /* This hasn't actually been used these pins 378}; /* This hasn't actually been used these pins
372 * are (currently) free pins on the expansion connector */ 379 * are (currently) free pins on the expansion connector */
@@ -462,7 +469,9 @@ static int __init blackstamp_init(void)
462 int ret; 469 int ret;
463 470
464 printk(KERN_INFO "%s(): registering device resources\n", __func__); 471 printk(KERN_INFO "%s(): registering device resources\n", __func__);
465 472#if IS_ENABLED(CONFIG_I2C_GPIO)
473 gpiod_add_lookup_table(&bfin_i2c_gpiod_table);
474#endif
466 i2c_register_board_info(0, bfin_i2c_board_info, 475 i2c_register_board_info(0, bfin_i2c_board_info,
467 ARRAY_SIZE(bfin_i2c_board_info)); 476 ARRAY_SIZE(bfin_i2c_board_info));
468 477
diff --git a/arch/blackfin/mach-bf533/boards/ezkit.c b/arch/blackfin/mach-bf533/boards/ezkit.c
index 3625e9eaa8a8..d64d270e9e62 100644
--- a/arch/blackfin/mach-bf533/boards/ezkit.c
+++ b/arch/blackfin/mach-bf533/boards/ezkit.c
@@ -19,6 +19,7 @@
19#endif 19#endif
20#include <linux/irq.h> 20#include <linux/irq.h>
21#include <linux/i2c.h> 21#include <linux/i2c.h>
22#include <linux/gpio/machine.h>
22#include <asm/dma.h> 23#include <asm/dma.h>
23#include <asm/bfin5xx_spi.h> 24#include <asm/bfin5xx_spi.h>
24#include <asm/portmux.h> 25#include <asm/portmux.h>
@@ -390,11 +391,17 @@ static struct platform_device bfin_device_gpiokeys = {
390#if IS_ENABLED(CONFIG_I2C_GPIO) 391#if IS_ENABLED(CONFIG_I2C_GPIO)
391#include <linux/i2c-gpio.h> 392#include <linux/i2c-gpio.h>
392 393
394static struct gpiod_lookup_table bfin_i2c_gpiod_table = {
395 .dev_id = "i2c-gpio",
396 .table = {
397 GPIO_LOOKUP_IDX("BFIN-GPIO", GPIO_PF1, NULL, 0,
398 GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
399 GPIO_LOOKUP_IDX("BFIN-GPIO", GPIO_PF0, NULL, 1,
400 GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
401 },
402};
403
393static struct i2c_gpio_platform_data i2c_gpio_data = { 404static struct i2c_gpio_platform_data i2c_gpio_data = {
394 .sda_pin = GPIO_PF1,
395 .scl_pin = GPIO_PF0,
396 .sda_is_open_drain = 0,
397 .scl_is_open_drain = 0,
398 .udelay = 40, 405 .udelay = 40,
399}; 406};
400 407
@@ -516,6 +523,9 @@ static struct platform_device *ezkit_devices[] __initdata = {
516static int __init ezkit_init(void) 523static int __init ezkit_init(void)
517{ 524{
518 printk(KERN_INFO "%s(): registering device resources\n", __func__); 525 printk(KERN_INFO "%s(): registering device resources\n", __func__);
526#if IS_ENABLED(CONFIG_I2C_GPIO)
527 gpiod_add_lookup_table(&bfin_i2c_gpiod_table);
528#endif
519 platform_add_devices(ezkit_devices, ARRAY_SIZE(ezkit_devices)); 529 platform_add_devices(ezkit_devices, ARRAY_SIZE(ezkit_devices));
520 spi_register_board_info(bfin_spi_board_info, ARRAY_SIZE(bfin_spi_board_info)); 530 spi_register_board_info(bfin_spi_board_info, ARRAY_SIZE(bfin_spi_board_info));
521 i2c_register_board_info(0, bfin_i2c_board_info, 531 i2c_register_board_info(0, bfin_i2c_board_info,
diff --git a/arch/blackfin/mach-bf533/boards/stamp.c b/arch/blackfin/mach-bf533/boards/stamp.c
index 23eada79439c..27cbf2fa2c62 100644
--- a/arch/blackfin/mach-bf533/boards/stamp.c
+++ b/arch/blackfin/mach-bf533/boards/stamp.c
@@ -21,6 +21,7 @@
21#include <linux/gpio.h> 21#include <linux/gpio.h>
22#include <linux/irq.h> 22#include <linux/irq.h>
23#include <linux/i2c.h> 23#include <linux/i2c.h>
24#include <linux/gpio/machine.h>
24#include <asm/dma.h> 25#include <asm/dma.h>
25#include <asm/bfin5xx_spi.h> 26#include <asm/bfin5xx_spi.h>
26#include <asm/reboot.h> 27#include <asm/reboot.h>
@@ -512,11 +513,17 @@ static struct platform_device bfin_device_gpiokeys = {
512#if IS_ENABLED(CONFIG_I2C_GPIO) 513#if IS_ENABLED(CONFIG_I2C_GPIO)
513#include <linux/i2c-gpio.h> 514#include <linux/i2c-gpio.h>
514 515
516static struct gpiod_lookup_table bfin_i2c_gpiod_table = {
517 .dev_id = "i2c-gpio",
518 .table = {
519 GPIO_LOOKUP_IDX("BFIN-GPIO", GPIO_PF2, NULL, 0,
520 GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
521 GPIO_LOOKUP_IDX("BFIN-GPIO", GPIO_PF3, NULL, 1,
522 GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
523 },
524};
525
515static struct i2c_gpio_platform_data i2c_gpio_data = { 526static struct i2c_gpio_platform_data i2c_gpio_data = {
516 .sda_pin = GPIO_PF2,
517 .scl_pin = GPIO_PF3,
518 .sda_is_open_drain = 0,
519 .scl_is_open_drain = 0,
520 .udelay = 10, 527 .udelay = 10,
521}; 528};
522 529
@@ -848,6 +855,9 @@ static int __init stamp_init(void)
848 855
849 printk(KERN_INFO "%s(): registering device resources\n", __func__); 856 printk(KERN_INFO "%s(): registering device resources\n", __func__);
850 857
858#if IS_ENABLED(CONFIG_I2C_GPIO)
859 gpiod_add_lookup_table(&bfin_i2c_gpiod_table);
860#endif
851 i2c_register_board_info(0, bfin_i2c_board_info, 861 i2c_register_board_info(0, bfin_i2c_board_info,
852 ARRAY_SIZE(bfin_i2c_board_info)); 862 ARRAY_SIZE(bfin_i2c_board_info));
853 863
diff --git a/arch/blackfin/mach-bf561/boards/ezkit.c b/arch/blackfin/mach-bf561/boards/ezkit.c
index 57d1c43726d9..acc5363f60c6 100644
--- a/arch/blackfin/mach-bf561/boards/ezkit.c
+++ b/arch/blackfin/mach-bf561/boards/ezkit.c
@@ -16,6 +16,7 @@
16#include <linux/interrupt.h> 16#include <linux/interrupt.h>
17#include <linux/gpio.h> 17#include <linux/gpio.h>
18#include <linux/delay.h> 18#include <linux/delay.h>
19#include <linux/gpio/machine.h>
19#include <asm/dma.h> 20#include <asm/dma.h>
20#include <asm/bfin5xx_spi.h> 21#include <asm/bfin5xx_spi.h>
21#include <asm/portmux.h> 22#include <asm/portmux.h>
@@ -379,11 +380,17 @@ static struct platform_device bfin_device_gpiokeys = {
379#if IS_ENABLED(CONFIG_I2C_GPIO) 380#if IS_ENABLED(CONFIG_I2C_GPIO)
380#include <linux/i2c-gpio.h> 381#include <linux/i2c-gpio.h>
381 382
383static struct gpiod_lookup_table bfin_i2c_gpiod_table = {
384 .dev_id = "i2c-gpio",
385 .table = {
386 GPIO_LOOKUP_IDX("BFIN-GPIO", GPIO_PF1, NULL, 0,
387 GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
388 GPIO_LOOKUP_IDX("BFIN-GPIO", GPIO_PF0, NULL, 1,
389 GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
390 },
391};
392
382static struct i2c_gpio_platform_data i2c_gpio_data = { 393static struct i2c_gpio_platform_data i2c_gpio_data = {
383 .sda_pin = GPIO_PF1,
384 .scl_pin = GPIO_PF0,
385 .sda_is_open_drain = 0,
386 .scl_is_open_drain = 0,
387 .udelay = 10, 394 .udelay = 10,
388}; 395};
389 396
@@ -633,6 +640,9 @@ static int __init ezkit_init(void)
633 640
634 printk(KERN_INFO "%s(): registering device resources\n", __func__); 641 printk(KERN_INFO "%s(): registering device resources\n", __func__);
635 642
643#if IS_ENABLED(CONFIG_I2C_GPIO)
644 gpiod_add_lookup_table(&bfin_i2c_gpiod_table);
645#endif
636 ret = platform_add_devices(ezkit_devices, ARRAY_SIZE(ezkit_devices)); 646 ret = platform_add_devices(ezkit_devices, ARRAY_SIZE(ezkit_devices));
637 if (ret < 0) 647 if (ret < 0)
638 return ret; 648 return ret;
diff --git a/arch/mips/alchemy/board-gpr.c b/arch/mips/alchemy/board-gpr.c
index 6fb6b3faa158..328d697e72b4 100644
--- a/arch/mips/alchemy/board-gpr.c
+++ b/arch/mips/alchemy/board-gpr.c
@@ -30,6 +30,7 @@
30#include <linux/gpio.h> 30#include <linux/gpio.h>
31#include <linux/i2c.h> 31#include <linux/i2c.h>
32#include <linux/i2c-gpio.h> 32#include <linux/i2c-gpio.h>
33#include <linux/gpio/machine.h>
33#include <asm/bootinfo.h> 34#include <asm/bootinfo.h>
34#include <asm/idle.h> 35#include <asm/idle.h>
35#include <asm/reboot.h> 36#include <asm/reboot.h>
@@ -218,10 +219,27 @@ static struct platform_device gpr_led_devices = {
218/* 219/*
219 * I2C 220 * I2C
220 */ 221 */
222static struct gpiod_lookup_table gpr_i2c_gpiod_table = {
223 .dev_id = "i2c-gpio",
224 .table = {
225 /*
226 * This should be on "GPIO2" which has base at 200 so
227 * the global numbers 209 and 210 should correspond to
228 * local offsets 9 and 10.
229 */
230 GPIO_LOOKUP_IDX("alchemy-gpio2", 9, NULL, 0,
231 GPIO_ACTIVE_HIGH),
232 GPIO_LOOKUP_IDX("alchemy-gpio2", 10, NULL, 1,
233 GPIO_ACTIVE_HIGH),
234 },
235};
236
221static struct i2c_gpio_platform_data gpr_i2c_data = { 237static struct i2c_gpio_platform_data gpr_i2c_data = {
222 .sda_pin = 209, 238 /*
239 * The open drain mode is hardwired somewhere or an electrical
240 * property of the alchemy GPIO controller.
241 */
223 .sda_is_open_drain = 1, 242 .sda_is_open_drain = 1,
224 .scl_pin = 210,
225 .scl_is_open_drain = 1, 243 .scl_is_open_drain = 1,
226 .udelay = 2, /* ~100 kHz */ 244 .udelay = 2, /* ~100 kHz */
227 .timeout = HZ, 245 .timeout = HZ,
@@ -295,6 +313,7 @@ arch_initcall(gpr_pci_init);
295 313
296static int __init gpr_dev_init(void) 314static int __init gpr_dev_init(void)
297{ 315{
316 gpiod_add_lookup_table(&gpr_i2c_gpiod_table);
298 i2c_register_board_info(0, gpr_i2c_info, ARRAY_SIZE(gpr_i2c_info)); 317 i2c_register_board_info(0, gpr_i2c_info, ARRAY_SIZE(gpr_i2c_info));
299 318
300 return platform_add_devices(gpr_devices, ARRAY_SIZE(gpr_devices)); 319 return platform_add_devices(gpr_devices, ARRAY_SIZE(gpr_devices));
diff --git a/arch/mips/ath79/mach-pb44.c b/arch/mips/ath79/mach-pb44.c
index be78298dffb4..6b2c6f3baefa 100644
--- a/arch/mips/ath79/mach-pb44.c
+++ b/arch/mips/ath79/mach-pb44.c
@@ -11,7 +11,7 @@
11#include <linux/init.h> 11#include <linux/init.h>
12#include <linux/platform_device.h> 12#include <linux/platform_device.h>
13#include <linux/i2c.h> 13#include <linux/i2c.h>
14#include <linux/i2c-gpio.h> 14#include <linux/gpio/machine.h>
15#include <linux/platform_data/pcf857x.h> 15#include <linux/platform_data/pcf857x.h>
16 16
17#include "machtypes.h" 17#include "machtypes.h"
@@ -33,16 +33,21 @@
33#define PB44_KEYS_POLL_INTERVAL 20 /* msecs */ 33#define PB44_KEYS_POLL_INTERVAL 20 /* msecs */
34#define PB44_KEYS_DEBOUNCE_INTERVAL (3 * PB44_KEYS_POLL_INTERVAL) 34#define PB44_KEYS_DEBOUNCE_INTERVAL (3 * PB44_KEYS_POLL_INTERVAL)
35 35
36static struct i2c_gpio_platform_data pb44_i2c_gpio_data = { 36static struct gpiod_lookup_table pb44_i2c_gpiod_table = {
37 .sda_pin = PB44_GPIO_I2C_SDA, 37 .dev_id = "i2c-gpio",
38 .scl_pin = PB44_GPIO_I2C_SCL, 38 .table = {
39 GPIO_LOOKUP_IDX("ath79-gpio", PB44_GPIO_I2C_SDA,
40 NULL, 0, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
41 GPIO_LOOKUP_IDX("ath79-gpio", PB44_GPIO_I2C_SCL,
42 NULL, 1, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
43 },
39}; 44};
40 45
41static struct platform_device pb44_i2c_gpio_device = { 46static struct platform_device pb44_i2c_gpio_device = {
42 .name = "i2c-gpio", 47 .name = "i2c-gpio",
43 .id = 0, 48 .id = 0,
44 .dev = { 49 .dev = {
45 .platform_data = &pb44_i2c_gpio_data, 50 .platform_data = NULL,
46 } 51 }
47}; 52};
48 53
@@ -103,6 +108,7 @@ static struct ath79_spi_platform_data pb44_spi_data = {
103 108
104static void __init pb44_init(void) 109static void __init pb44_init(void)
105{ 110{
111 gpiod_add_lookup_table(&pb44_i2c_gpiod_table);
106 i2c_register_board_info(0, pb44_i2c_board_info, 112 i2c_register_board_info(0, pb44_i2c_board_info,
107 ARRAY_SIZE(pb44_i2c_board_info)); 113 ARRAY_SIZE(pb44_i2c_board_info));
108 platform_device_register(&pb44_i2c_gpio_device); 114 platform_device_register(&pb44_i2c_gpio_device);
diff --git a/drivers/acpi/acpi_apd.c b/drivers/acpi/acpi_apd.c
index d5999eb41c00..d553b0087947 100644
--- a/drivers/acpi/acpi_apd.c
+++ b/drivers/acpi/acpi_apd.c
@@ -116,6 +116,10 @@ static const struct apd_device_desc hip08_i2c_desc = {
116 .setup = acpi_apd_setup, 116 .setup = acpi_apd_setup,
117 .fixed_clk_rate = 250000000, 117 .fixed_clk_rate = 250000000,
118}; 118};
119static const struct apd_device_desc thunderx2_i2c_desc = {
120 .setup = acpi_apd_setup,
121 .fixed_clk_rate = 125000000,
122};
119#endif 123#endif
120 124
121#else 125#else
@@ -180,6 +184,7 @@ static const struct acpi_device_id acpi_apd_device_ids[] = {
180 { "APMC0D0F", APD_ADDR(xgene_i2c_desc) }, 184 { "APMC0D0F", APD_ADDR(xgene_i2c_desc) },
181 { "BRCM900D", APD_ADDR(vulcan_spi_desc) }, 185 { "BRCM900D", APD_ADDR(vulcan_spi_desc) },
182 { "CAV900D", APD_ADDR(vulcan_spi_desc) }, 186 { "CAV900D", APD_ADDR(vulcan_spi_desc) },
187 { "CAV9007", APD_ADDR(thunderx2_i2c_desc) },
183 { "HISI02A1", APD_ADDR(hip07_i2c_desc) }, 188 { "HISI02A1", APD_ADDR(hip07_i2c_desc) },
184 { "HISI02A2", APD_ADDR(hip08_i2c_desc) }, 189 { "HISI02A2", APD_ADDR(hip08_i2c_desc) },
185#endif 190#endif
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 86dcd02cf602..641a5eb552cb 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -3528,8 +3528,21 @@ int gpiod_configure_flags(struct gpio_desc *desc, const char *con_id,
3528 3528
3529 if (lflags & GPIO_ACTIVE_LOW) 3529 if (lflags & GPIO_ACTIVE_LOW)
3530 set_bit(FLAG_ACTIVE_LOW, &desc->flags); 3530 set_bit(FLAG_ACTIVE_LOW, &desc->flags);
3531
3531 if (lflags & GPIO_OPEN_DRAIN) 3532 if (lflags & GPIO_OPEN_DRAIN)
3532 set_bit(FLAG_OPEN_DRAIN, &desc->flags); 3533 set_bit(FLAG_OPEN_DRAIN, &desc->flags);
3534 else if (dflags & GPIOD_FLAGS_BIT_OPEN_DRAIN) {
3535 /*
3536 * This enforces open drain mode from the consumer side.
3537 * This is necessary for some busses like I2C, but the lookup
3538 * should *REALLY* have specified them as open drain in the
3539 * first place, so print a little warning here.
3540 */
3541 set_bit(FLAG_OPEN_DRAIN, &desc->flags);
3542 gpiod_warn(desc,
3543 "enforced open drain please flag it properly in DT/ACPI DSDT/board file\n");
3544 }
3545
3533 if (lflags & GPIO_OPEN_SOURCE) 3546 if (lflags & GPIO_OPEN_SOURCE)
3534 set_bit(FLAG_OPEN_SOURCE, &desc->flags); 3547 set_bit(FLAG_OPEN_SOURCE, &desc->flags);
3535 if (lflags & GPIO_SLEEP_MAY_LOSE_VALUE) 3548 if (lflags & GPIO_SLEEP_MAY_LOSE_VALUE)
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index 45a3f3ca29b3..009345d8f49d 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -198,6 +198,11 @@ config I2C_CHT_WC
198 SMBus controller found in the Intel Cherry Trail Whiskey Cove PMIC 198 SMBus controller found in the Intel Cherry Trail Whiskey Cove PMIC
199 found on some Intel Cherry Trail systems. 199 found on some Intel Cherry Trail systems.
200 200
201 Note this controller is hooked up to a TI bq24292i charger-IC,
202 combined with a FUSB302 Type-C port-controller as such it is advised
203 to also select CONFIG_CHARGER_BQ24190=m and CONFIG_TYPEC_FUSB302=m
204 (the fusb302 driver currently is in drivers/staging).
205
201config I2C_NFORCE2 206config I2C_NFORCE2
202 tristate "Nvidia nForce2, nForce3 and nForce4" 207 tristate "Nvidia nForce2, nForce3 and nForce4"
203 depends on PCI 208 depends on PCI
diff --git a/drivers/i2c/busses/i2c-aspeed.c b/drivers/i2c/busses/i2c-aspeed.c
index 284f8670dbeb..7d4aeb4465b3 100644
--- a/drivers/i2c/busses/i2c-aspeed.c
+++ b/drivers/i2c/busses/i2c-aspeed.c
@@ -27,6 +27,7 @@
27#include <linux/of_irq.h> 27#include <linux/of_irq.h>
28#include <linux/of_platform.h> 28#include <linux/of_platform.h>
29#include <linux/platform_device.h> 29#include <linux/platform_device.h>
30#include <linux/reset.h>
30#include <linux/slab.h> 31#include <linux/slab.h>
31 32
32/* I2C Register */ 33/* I2C Register */
@@ -132,6 +133,7 @@ struct aspeed_i2c_bus {
132 struct i2c_adapter adap; 133 struct i2c_adapter adap;
133 struct device *dev; 134 struct device *dev;
134 void __iomem *base; 135 void __iomem *base;
136 struct reset_control *rst;
135 /* Synchronizes I/O mem access to base. */ 137 /* Synchronizes I/O mem access to base. */
136 spinlock_t lock; 138 spinlock_t lock;
137 struct completion cmd_complete; 139 struct completion cmd_complete;
@@ -847,6 +849,14 @@ static int aspeed_i2c_probe_bus(struct platform_device *pdev)
847 /* We just need the clock rate, we don't actually use the clk object. */ 849 /* We just need the clock rate, we don't actually use the clk object. */
848 devm_clk_put(&pdev->dev, parent_clk); 850 devm_clk_put(&pdev->dev, parent_clk);
849 851
852 bus->rst = devm_reset_control_get_shared(&pdev->dev, NULL);
853 if (IS_ERR(bus->rst)) {
854 dev_err(&pdev->dev,
855 "missing or invalid reset controller device tree entry");
856 return PTR_ERR(bus->rst);
857 }
858 reset_control_deassert(bus->rst);
859
850 ret = of_property_read_u32(pdev->dev.of_node, 860 ret = of_property_read_u32(pdev->dev.of_node,
851 "bus-frequency", &bus->bus_frequency); 861 "bus-frequency", &bus->bus_frequency);
852 if (ret < 0) { 862 if (ret < 0) {
@@ -917,6 +927,8 @@ static int aspeed_i2c_remove_bus(struct platform_device *pdev)
917 927
918 spin_unlock_irqrestore(&bus->lock, flags); 928 spin_unlock_irqrestore(&bus->lock, flags);
919 929
930 reset_control_assert(bus->rst);
931
920 i2c_del_adapter(&bus->adap); 932 i2c_del_adapter(&bus->adap);
921 933
922 return 0; 934 return 0;
diff --git a/drivers/i2c/busses/i2c-cht-wc.c b/drivers/i2c/busses/i2c-cht-wc.c
index 190bbbc7bfee..0d05dadb2dc5 100644
--- a/drivers/i2c/busses/i2c-cht-wc.c
+++ b/drivers/i2c/busses/i2c-cht-wc.c
@@ -16,6 +16,7 @@
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 */ 17 */
18 18
19#include <linux/acpi.h>
19#include <linux/completion.h> 20#include <linux/completion.h>
20#include <linux/delay.h> 21#include <linux/delay.h>
21#include <linux/i2c.h> 22#include <linux/i2c.h>
@@ -25,6 +26,7 @@
25#include <linux/mfd/intel_soc_pmic.h> 26#include <linux/mfd/intel_soc_pmic.h>
26#include <linux/module.h> 27#include <linux/module.h>
27#include <linux/platform_device.h> 28#include <linux/platform_device.h>
29#include <linux/power/bq24190_charger.h>
28#include <linux/slab.h> 30#include <linux/slab.h>
29 31
30#define CHT_WC_I2C_CTRL 0x5e24 32#define CHT_WC_I2C_CTRL 0x5e24
@@ -232,13 +234,35 @@ static const struct irq_chip cht_wc_i2c_irq_chip = {
232 .name = "cht_wc_ext_chrg_irq_chip", 234 .name = "cht_wc_ext_chrg_irq_chip",
233}; 235};
234 236
237static const char * const bq24190_suppliers[] = { "fusb302-typec-source" };
238
235static const struct property_entry bq24190_props[] = { 239static const struct property_entry bq24190_props[] = {
236 PROPERTY_ENTRY_STRING("extcon-name", "cht_wcove_pwrsrc"), 240 PROPERTY_ENTRY_STRING_ARRAY("supplied-from", bq24190_suppliers),
237 PROPERTY_ENTRY_BOOL("omit-battery-class"), 241 PROPERTY_ENTRY_BOOL("omit-battery-class"),
238 PROPERTY_ENTRY_BOOL("disable-reset"), 242 PROPERTY_ENTRY_BOOL("disable-reset"),
239 { } 243 { }
240}; 244};
241 245
246static struct regulator_consumer_supply fusb302_consumer = {
247 .supply = "vbus",
248 /* Must match fusb302 dev_name in intel_cht_int33fe.c */
249 .dev_name = "i2c-fusb302",
250};
251
252static const struct regulator_init_data bq24190_vbus_init_data = {
253 .constraints = {
254 /* The name is used in intel_cht_int33fe.c do not change. */
255 .name = "cht_wc_usb_typec_vbus",
256 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
257 },
258 .consumer_supplies = &fusb302_consumer,
259 .num_consumer_supplies = 1,
260};
261
262static struct bq24190_platform_data bq24190_pdata = {
263 .regulator_init_data = &bq24190_vbus_init_data,
264};
265
242static int cht_wc_i2c_adap_i2c_probe(struct platform_device *pdev) 266static int cht_wc_i2c_adap_i2c_probe(struct platform_device *pdev)
243{ 267{
244 struct intel_soc_pmic *pmic = dev_get_drvdata(pdev->dev.parent); 268 struct intel_soc_pmic *pmic = dev_get_drvdata(pdev->dev.parent);
@@ -246,7 +270,9 @@ static int cht_wc_i2c_adap_i2c_probe(struct platform_device *pdev)
246 struct i2c_board_info board_info = { 270 struct i2c_board_info board_info = {
247 .type = "bq24190", 271 .type = "bq24190",
248 .addr = 0x6b, 272 .addr = 0x6b,
273 .dev_name = "bq24190",
249 .properties = bq24190_props, 274 .properties = bq24190_props,
275 .platform_data = &bq24190_pdata,
250 }; 276 };
251 int ret, reg, irq; 277 int ret, reg, irq;
252 278
@@ -314,11 +340,21 @@ static int cht_wc_i2c_adap_i2c_probe(struct platform_device *pdev)
314 if (ret) 340 if (ret)
315 goto remove_irq_domain; 341 goto remove_irq_domain;
316 342
317 board_info.irq = adap->client_irq; 343 /*
318 adap->client = i2c_new_device(&adap->adapter, &board_info); 344 * Normally the Whiskey Cove PMIC is paired with a TI bq24292i charger,
319 if (!adap->client) { 345 * connected to this i2c bus, and a max17047 fuel-gauge and a fusb302
320 ret = -ENOMEM; 346 * USB Type-C controller connected to another i2c bus. In this setup
321 goto del_adapter; 347 * the max17047 and fusb302 devices are enumerated through an INT33FE
348 * ACPI device. If this device is present register an i2c-client for
349 * the TI bq24292i charger.
350 */
351 if (acpi_dev_present("INT33FE", NULL, -1)) {
352 board_info.irq = adap->client_irq;
353 adap->client = i2c_new_device(&adap->adapter, &board_info);
354 if (!adap->client) {
355 ret = -ENOMEM;
356 goto del_adapter;
357 }
322 } 358 }
323 359
324 platform_set_drvdata(pdev, adap); 360 platform_set_drvdata(pdev, adap);
@@ -335,7 +371,8 @@ static int cht_wc_i2c_adap_i2c_remove(struct platform_device *pdev)
335{ 371{
336 struct cht_wc_i2c_adap *adap = platform_get_drvdata(pdev); 372 struct cht_wc_i2c_adap *adap = platform_get_drvdata(pdev);
337 373
338 i2c_unregister_device(adap->client); 374 if (adap->client)
375 i2c_unregister_device(adap->client);
339 i2c_del_adapter(&adap->adapter); 376 i2c_del_adapter(&adap->adapter);
340 irq_domain_remove(adap->irq_domain); 377 irq_domain_remove(adap->irq_domain);
341 378
diff --git a/drivers/i2c/busses/i2c-davinci.c b/drivers/i2c/busses/i2c-davinci.c
index b8c43535f16c..2ead9b9eebb7 100644
--- a/drivers/i2c/busses/i2c-davinci.c
+++ b/drivers/i2c/busses/i2c-davinci.c
@@ -36,6 +36,7 @@
36#include <linux/gpio.h> 36#include <linux/gpio.h>
37#include <linux/of_device.h> 37#include <linux/of_device.h>
38#include <linux/platform_data/i2c-davinci.h> 38#include <linux/platform_data/i2c-davinci.h>
39#include <linux/pm_runtime.h>
39 40
40/* ----- global defines ----------------------------------------------- */ 41/* ----- global defines ----------------------------------------------- */
41 42
@@ -122,6 +123,9 @@
122/* set the SDA GPIO low */ 123/* set the SDA GPIO low */
123#define DAVINCI_I2C_DCLR_PDCLR1 BIT(1) 124#define DAVINCI_I2C_DCLR_PDCLR1 BIT(1)
124 125
126/* timeout for pm runtime autosuspend */
127#define DAVINCI_I2C_PM_TIMEOUT 1000 /* ms */
128
125struct davinci_i2c_dev { 129struct davinci_i2c_dev {
126 struct device *dev; 130 struct device *dev;
127 void __iomem *base; 131 void __iomem *base;
@@ -500,7 +504,7 @@ i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop)
500 /* This should be 0 if all bytes were transferred 504 /* This should be 0 if all bytes were transferred
501 * or dev->cmd_err denotes an error. 505 * or dev->cmd_err denotes an error.
502 */ 506 */
503 dev_err(dev->dev, "abnormal termination buf_len=%i\n", 507 dev_err(dev->dev, "abnormal termination buf_len=%zu\n",
504 dev->buf_len); 508 dev->buf_len);
505 dev->terminate = 1; 509 dev->terminate = 1;
506 wmb(); 510 wmb();
@@ -541,10 +545,17 @@ i2c_davinci_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
541 545
542 dev_dbg(dev->dev, "%s: msgs: %d\n", __func__, num); 546 dev_dbg(dev->dev, "%s: msgs: %d\n", __func__, num);
543 547
548 ret = pm_runtime_get_sync(dev->dev);
549 if (ret < 0) {
550 dev_err(dev->dev, "Failed to runtime_get device: %d\n", ret);
551 pm_runtime_put_noidle(dev->dev);
552 return ret;
553 }
554
544 ret = i2c_davinci_wait_bus_not_busy(dev); 555 ret = i2c_davinci_wait_bus_not_busy(dev);
545 if (ret < 0) { 556 if (ret < 0) {
546 dev_warn(dev->dev, "timeout waiting for bus ready\n"); 557 dev_warn(dev->dev, "timeout waiting for bus ready\n");
547 return ret; 558 goto out;
548 } 559 }
549 560
550 for (i = 0; i < num; i++) { 561 for (i = 0; i < num; i++) {
@@ -552,14 +563,19 @@ i2c_davinci_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
552 dev_dbg(dev->dev, "%s [%d/%d] ret: %d\n", __func__, i + 1, num, 563 dev_dbg(dev->dev, "%s [%d/%d] ret: %d\n", __func__, i + 1, num,
553 ret); 564 ret);
554 if (ret < 0) 565 if (ret < 0)
555 return ret; 566 goto out;
556 } 567 }
557 568
569 ret = num;
558#ifdef CONFIG_CPU_FREQ 570#ifdef CONFIG_CPU_FREQ
559 complete(&dev->xfr_complete); 571 complete(&dev->xfr_complete);
560#endif 572#endif
561 573
562 return num; 574out:
575 pm_runtime_mark_last_busy(dev->dev);
576 pm_runtime_put_autosuspend(dev->dev);
577
578 return ret;
563} 579}
564 580
565static u32 i2c_davinci_func(struct i2c_adapter *adap) 581static u32 i2c_davinci_func(struct i2c_adapter *adap)
@@ -599,6 +615,9 @@ static irqreturn_t i2c_davinci_isr(int this_irq, void *dev_id)
599 int count = 0; 615 int count = 0;
600 u16 w; 616 u16 w;
601 617
618 if (pm_runtime_suspended(dev->dev))
619 return IRQ_NONE;
620
602 while ((stat = davinci_i2c_read_reg(dev, DAVINCI_I2C_IVR_REG))) { 621 while ((stat = davinci_i2c_read_reg(dev, DAVINCI_I2C_IVR_REG))) {
603 dev_dbg(dev->dev, "%s: stat=0x%x\n", __func__, stat); 622 dev_dbg(dev->dev, "%s: stat=0x%x\n", __func__, stat);
604 if (count++ == 100) { 623 if (count++ == 100) {
@@ -802,13 +821,24 @@ static int davinci_i2c_probe(struct platform_device *pdev)
802 dev->clk = devm_clk_get(&pdev->dev, NULL); 821 dev->clk = devm_clk_get(&pdev->dev, NULL);
803 if (IS_ERR(dev->clk)) 822 if (IS_ERR(dev->clk))
804 return PTR_ERR(dev->clk); 823 return PTR_ERR(dev->clk);
805 clk_prepare_enable(dev->clk);
806 824
807 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 825 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
808 dev->base = devm_ioremap_resource(&pdev->dev, mem); 826 dev->base = devm_ioremap_resource(&pdev->dev, mem);
809 if (IS_ERR(dev->base)) { 827 if (IS_ERR(dev->base)) {
810 r = PTR_ERR(dev->base); 828 return PTR_ERR(dev->base);
811 goto err_unuse_clocks; 829 }
830
831 pm_runtime_set_autosuspend_delay(dev->dev,
832 DAVINCI_I2C_PM_TIMEOUT);
833 pm_runtime_use_autosuspend(dev->dev);
834
835 pm_runtime_enable(dev->dev);
836
837 r = pm_runtime_get_sync(dev->dev);
838 if (r < 0) {
839 dev_err(dev->dev, "failed to runtime_get device: %d\n", r);
840 pm_runtime_put_noidle(dev->dev);
841 return r;
812 } 842 }
813 843
814 i2c_davinci_init(dev); 844 i2c_davinci_init(dev);
@@ -849,27 +879,40 @@ static int davinci_i2c_probe(struct platform_device *pdev)
849 if (r) 879 if (r)
850 goto err_unuse_clocks; 880 goto err_unuse_clocks;
851 881
882 pm_runtime_mark_last_busy(dev->dev);
883 pm_runtime_put_autosuspend(dev->dev);
884
852 return 0; 885 return 0;
853 886
854err_unuse_clocks: 887err_unuse_clocks:
855 clk_disable_unprepare(dev->clk); 888 pm_runtime_dont_use_autosuspend(dev->dev);
856 dev->clk = NULL; 889 pm_runtime_put_sync(dev->dev);
890 pm_runtime_disable(dev->dev);
891
857 return r; 892 return r;
858} 893}
859 894
860static int davinci_i2c_remove(struct platform_device *pdev) 895static int davinci_i2c_remove(struct platform_device *pdev)
861{ 896{
862 struct davinci_i2c_dev *dev = platform_get_drvdata(pdev); 897 struct davinci_i2c_dev *dev = platform_get_drvdata(pdev);
898 int ret;
863 899
864 i2c_davinci_cpufreq_deregister(dev); 900 i2c_davinci_cpufreq_deregister(dev);
865 901
866 i2c_del_adapter(&dev->adapter); 902 i2c_del_adapter(&dev->adapter);
867 903
868 clk_disable_unprepare(dev->clk); 904 ret = pm_runtime_get_sync(&pdev->dev);
869 dev->clk = NULL; 905 if (ret < 0) {
906 pm_runtime_put_noidle(&pdev->dev);
907 return ret;
908 }
870 909
871 davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, 0); 910 davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, 0);
872 911
912 pm_runtime_dont_use_autosuspend(dev->dev);
913 pm_runtime_put_sync(dev->dev);
914 pm_runtime_disable(dev->dev);
915
873 return 0; 916 return 0;
874} 917}
875 918
@@ -880,7 +923,6 @@ static int davinci_i2c_suspend(struct device *dev)
880 923
881 /* put I2C into reset */ 924 /* put I2C into reset */
882 davinci_i2c_reset_ctrl(i2c_dev, 0); 925 davinci_i2c_reset_ctrl(i2c_dev, 0);
883 clk_disable_unprepare(i2c_dev->clk);
884 926
885 return 0; 927 return 0;
886} 928}
@@ -889,7 +931,6 @@ static int davinci_i2c_resume(struct device *dev)
889{ 931{
890 struct davinci_i2c_dev *i2c_dev = dev_get_drvdata(dev); 932 struct davinci_i2c_dev *i2c_dev = dev_get_drvdata(dev);
891 933
892 clk_prepare_enable(i2c_dev->clk);
893 /* take I2C out of reset */ 934 /* take I2C out of reset */
894 davinci_i2c_reset_ctrl(i2c_dev, 1); 935 davinci_i2c_reset_ctrl(i2c_dev, 1);
895 936
@@ -899,6 +940,8 @@ static int davinci_i2c_resume(struct device *dev)
899static const struct dev_pm_ops davinci_i2c_pm = { 940static const struct dev_pm_ops davinci_i2c_pm = {
900 .suspend = davinci_i2c_suspend, 941 .suspend = davinci_i2c_suspend,
901 .resume = davinci_i2c_resume, 942 .resume = davinci_i2c_resume,
943 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
944 pm_runtime_force_resume)
902}; 945};
903 946
904#define davinci_i2c_pm_ops (&davinci_i2c_pm) 947#define davinci_i2c_pm_ops (&davinci_i2c_pm)
diff --git a/drivers/i2c/busses/i2c-designware-core.h b/drivers/i2c/busses/i2c-designware-core.h
index 9fee4c054d3d..21bf619a86c5 100644
--- a/drivers/i2c/busses/i2c-designware-core.h
+++ b/drivers/i2c/busses/i2c-designware-core.h
@@ -280,6 +280,8 @@ struct dw_i2c_dev {
280 int (*acquire_lock)(struct dw_i2c_dev *dev); 280 int (*acquire_lock)(struct dw_i2c_dev *dev);
281 void (*release_lock)(struct dw_i2c_dev *dev); 281 void (*release_lock)(struct dw_i2c_dev *dev);
282 bool pm_disabled; 282 bool pm_disabled;
283 bool suspended;
284 bool skip_resume;
283 void (*disable)(struct dw_i2c_dev *dev); 285 void (*disable)(struct dw_i2c_dev *dev);
284 void (*disable_int)(struct dw_i2c_dev *dev); 286 void (*disable_int)(struct dw_i2c_dev *dev);
285 int (*init)(struct dw_i2c_dev *dev); 287 int (*init)(struct dw_i2c_dev *dev);
diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c
index 0e65b97842b4..58add69a441c 100644
--- a/drivers/i2c/busses/i2c-designware-platdrv.c
+++ b/drivers/i2c/busses/i2c-designware-platdrv.c
@@ -249,6 +249,14 @@ static void dw_i2c_set_fifo_size(struct dw_i2c_dev *dev, int id)
249 } 249 }
250} 250}
251 251
252static void dw_i2c_plat_pm_cleanup(struct dw_i2c_dev *dev)
253{
254 pm_runtime_disable(dev->dev);
255
256 if (dev->pm_disabled)
257 pm_runtime_put_noidle(dev->dev);
258}
259
252static int dw_i2c_plat_probe(struct platform_device *pdev) 260static int dw_i2c_plat_probe(struct platform_device *pdev)
253{ 261{
254 struct dw_i2c_platform_data *pdata = dev_get_platdata(&pdev->dev); 262 struct dw_i2c_platform_data *pdata = dev_get_platdata(&pdev->dev);
@@ -257,7 +265,9 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)
257 u32 acpi_speed, ht = 0; 265 u32 acpi_speed, ht = 0;
258 struct resource *mem; 266 struct resource *mem;
259 int i, irq, ret; 267 int i, irq, ret;
260 const int supported_speeds[] = { 0, 100000, 400000, 1000000, 3400000 }; 268 static const int supported_speeds[] = {
269 0, 100000, 400000, 1000000, 3400000
270 };
261 271
262 irq = platform_get_irq(pdev, 0); 272 irq = platform_get_irq(pdev, 0);
263 if (irq < 0) 273 if (irq < 0)
@@ -362,14 +372,17 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)
362 ACPI_COMPANION_SET(&adap->dev, ACPI_COMPANION(&pdev->dev)); 372 ACPI_COMPANION_SET(&adap->dev, ACPI_COMPANION(&pdev->dev));
363 adap->dev.of_node = pdev->dev.of_node; 373 adap->dev.of_node = pdev->dev.of_node;
364 374
365 if (dev->pm_disabled) { 375 /* The code below assumes runtime PM to be disabled. */
366 pm_runtime_forbid(&pdev->dev); 376 WARN_ON(pm_runtime_enabled(&pdev->dev));
367 } else { 377
368 pm_runtime_set_autosuspend_delay(&pdev->dev, 1000); 378 pm_runtime_set_autosuspend_delay(&pdev->dev, 1000);
369 pm_runtime_use_autosuspend(&pdev->dev); 379 pm_runtime_use_autosuspend(&pdev->dev);
370 pm_runtime_set_active(&pdev->dev); 380 pm_runtime_set_active(&pdev->dev);
371 pm_runtime_enable(&pdev->dev); 381
372 } 382 if (dev->pm_disabled)
383 pm_runtime_get_noresume(&pdev->dev);
384
385 pm_runtime_enable(&pdev->dev);
373 386
374 if (dev->mode == DW_IC_SLAVE) 387 if (dev->mode == DW_IC_SLAVE)
375 ret = i2c_dw_probe_slave(dev); 388 ret = i2c_dw_probe_slave(dev);
@@ -382,8 +395,7 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)
382 return ret; 395 return ret;
383 396
384exit_probe: 397exit_probe:
385 if (!dev->pm_disabled) 398 dw_i2c_plat_pm_cleanup(dev);
386 pm_runtime_disable(&pdev->dev);
387exit_reset: 399exit_reset:
388 if (!IS_ERR_OR_NULL(dev->rst)) 400 if (!IS_ERR_OR_NULL(dev->rst))
389 reset_control_assert(dev->rst); 401 reset_control_assert(dev->rst);
@@ -402,8 +414,8 @@ static int dw_i2c_plat_remove(struct platform_device *pdev)
402 414
403 pm_runtime_dont_use_autosuspend(&pdev->dev); 415 pm_runtime_dont_use_autosuspend(&pdev->dev);
404 pm_runtime_put_sync(&pdev->dev); 416 pm_runtime_put_sync(&pdev->dev);
405 if (!dev->pm_disabled) 417 dw_i2c_plat_pm_cleanup(dev);
406 pm_runtime_disable(&pdev->dev); 418
407 if (!IS_ERR_OR_NULL(dev->rst)) 419 if (!IS_ERR_OR_NULL(dev->rst))
408 reset_control_assert(dev->rst); 420 reset_control_assert(dev->rst);
409 421
@@ -437,13 +449,20 @@ static void dw_i2c_plat_complete(struct device *dev)
437#endif 449#endif
438 450
439#ifdef CONFIG_PM 451#ifdef CONFIG_PM
440static int dw_i2c_plat_runtime_suspend(struct device *dev) 452static int dw_i2c_plat_suspend(struct device *dev)
441{ 453{
442 struct dw_i2c_dev *i_dev = dev_get_drvdata(dev); 454 struct dw_i2c_dev *i_dev = dev_get_drvdata(dev);
443 455
456 if (i_dev->suspended) {
457 i_dev->skip_resume = true;
458 return 0;
459 }
460
444 i_dev->disable(i_dev); 461 i_dev->disable(i_dev);
445 i2c_dw_plat_prepare_clk(i_dev, false); 462 i2c_dw_plat_prepare_clk(i_dev, false);
446 463
464 i_dev->suspended = true;
465
447 return 0; 466 return 0;
448} 467}
449 468
@@ -451,27 +470,27 @@ static int dw_i2c_plat_resume(struct device *dev)
451{ 470{
452 struct dw_i2c_dev *i_dev = dev_get_drvdata(dev); 471 struct dw_i2c_dev *i_dev = dev_get_drvdata(dev);
453 472
473 if (!i_dev->suspended)
474 return 0;
475
476 if (i_dev->skip_resume) {
477 i_dev->skip_resume = false;
478 return 0;
479 }
480
454 i2c_dw_plat_prepare_clk(i_dev, true); 481 i2c_dw_plat_prepare_clk(i_dev, true);
455 i_dev->init(i_dev); 482 i_dev->init(i_dev);
456 483
457 return 0; 484 i_dev->suspended = false;
458}
459 485
460#ifdef CONFIG_PM_SLEEP 486 return 0;
461static int dw_i2c_plat_suspend(struct device *dev)
462{
463 pm_runtime_resume(dev);
464 return dw_i2c_plat_runtime_suspend(dev);
465} 487}
466#endif
467 488
468static const struct dev_pm_ops dw_i2c_dev_pm_ops = { 489static const struct dev_pm_ops dw_i2c_dev_pm_ops = {
469 .prepare = dw_i2c_plat_prepare, 490 .prepare = dw_i2c_plat_prepare,
470 .complete = dw_i2c_plat_complete, 491 .complete = dw_i2c_plat_complete,
471 SET_SYSTEM_SLEEP_PM_OPS(dw_i2c_plat_suspend, dw_i2c_plat_resume) 492 SET_LATE_SYSTEM_SLEEP_PM_OPS(dw_i2c_plat_suspend, dw_i2c_plat_resume)
472 SET_RUNTIME_PM_OPS(dw_i2c_plat_runtime_suspend, 493 SET_RUNTIME_PM_OPS(dw_i2c_plat_suspend, dw_i2c_plat_resume, NULL)
473 dw_i2c_plat_resume,
474 NULL)
475}; 494};
476 495
477#define DW_I2C_DEV_PMOPS (&dw_i2c_dev_pm_ops) 496#define DW_I2C_DEV_PMOPS (&dw_i2c_dev_pm_ops)
diff --git a/drivers/i2c/busses/i2c-gpio.c b/drivers/i2c/busses/i2c-gpio.c
index 0ef8fcc6ac3a..d80ea6ce91bb 100644
--- a/drivers/i2c/busses/i2c-gpio.c
+++ b/drivers/i2c/busses/i2c-gpio.c
@@ -14,27 +14,17 @@
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/slab.h> 15#include <linux/slab.h>
16#include <linux/platform_device.h> 16#include <linux/platform_device.h>
17#include <linux/gpio.h> 17#include <linux/gpio/consumer.h>
18#include <linux/of.h> 18#include <linux/of.h>
19#include <linux/of_gpio.h>
20 19
21struct i2c_gpio_private_data { 20struct i2c_gpio_private_data {
21 struct gpio_desc *sda;
22 struct gpio_desc *scl;
22 struct i2c_adapter adap; 23 struct i2c_adapter adap;
23 struct i2c_algo_bit_data bit_data; 24 struct i2c_algo_bit_data bit_data;
24 struct i2c_gpio_platform_data pdata; 25 struct i2c_gpio_platform_data pdata;
25}; 26};
26 27
27/* Toggle SDA by changing the direction of the pin */
28static void i2c_gpio_setsda_dir(void *data, int state)
29{
30 struct i2c_gpio_platform_data *pdata = data;
31
32 if (state)
33 gpio_direction_input(pdata->sda_pin);
34 else
35 gpio_direction_output(pdata->sda_pin, 0);
36}
37
38/* 28/*
39 * Toggle SDA by changing the output value of the pin. This is only 29 * Toggle SDA by changing the output value of the pin. This is only
40 * valid for pins configured as open drain (i.e. setting the value 30 * valid for pins configured as open drain (i.e. setting the value
@@ -42,20 +32,9 @@ static void i2c_gpio_setsda_dir(void *data, int state)
42 */ 32 */
43static void i2c_gpio_setsda_val(void *data, int state) 33static void i2c_gpio_setsda_val(void *data, int state)
44{ 34{
45 struct i2c_gpio_platform_data *pdata = data; 35 struct i2c_gpio_private_data *priv = data;
46
47 gpio_set_value(pdata->sda_pin, state);
48}
49
50/* Toggle SCL by changing the direction of the pin. */
51static void i2c_gpio_setscl_dir(void *data, int state)
52{
53 struct i2c_gpio_platform_data *pdata = data;
54 36
55 if (state) 37 gpiod_set_value(priv->sda, state);
56 gpio_direction_input(pdata->scl_pin);
57 else
58 gpio_direction_output(pdata->scl_pin, 0);
59} 38}
60 39
61/* 40/*
@@ -66,44 +45,23 @@ static void i2c_gpio_setscl_dir(void *data, int state)
66 */ 45 */
67static void i2c_gpio_setscl_val(void *data, int state) 46static void i2c_gpio_setscl_val(void *data, int state)
68{ 47{
69 struct i2c_gpio_platform_data *pdata = data; 48 struct i2c_gpio_private_data *priv = data;
70 49
71 gpio_set_value(pdata->scl_pin, state); 50 gpiod_set_value(priv->scl, state);
72} 51}
73 52
74static int i2c_gpio_getsda(void *data) 53static int i2c_gpio_getsda(void *data)
75{ 54{
76 struct i2c_gpio_platform_data *pdata = data; 55 struct i2c_gpio_private_data *priv = data;
77 56
78 return gpio_get_value(pdata->sda_pin); 57 return gpiod_get_value(priv->sda);
79} 58}
80 59
81static int i2c_gpio_getscl(void *data) 60static int i2c_gpio_getscl(void *data)
82{ 61{
83 struct i2c_gpio_platform_data *pdata = data; 62 struct i2c_gpio_private_data *priv = data;
84
85 return gpio_get_value(pdata->scl_pin);
86}
87
88static int of_i2c_gpio_get_pins(struct device_node *np,
89 unsigned int *sda_pin, unsigned int *scl_pin)
90{
91 if (of_gpio_count(np) < 2)
92 return -ENODEV;
93
94 *sda_pin = of_get_gpio(np, 0);
95 *scl_pin = of_get_gpio(np, 1);
96
97 if (*sda_pin == -EPROBE_DEFER || *scl_pin == -EPROBE_DEFER)
98 return -EPROBE_DEFER;
99
100 if (!gpio_is_valid(*sda_pin) || !gpio_is_valid(*scl_pin)) {
101 pr_err("%pOF: invalid GPIO pins, sda=%d/scl=%d\n",
102 np, *sda_pin, *scl_pin);
103 return -ENODEV;
104 }
105 63
106 return 0; 64 return gpiod_get_value(priv->scl);
107} 65}
108 66
109static void of_i2c_gpio_get_props(struct device_node *np, 67static void of_i2c_gpio_get_props(struct device_node *np,
@@ -124,72 +82,105 @@ static void of_i2c_gpio_get_props(struct device_node *np,
124 of_property_read_bool(np, "i2c-gpio,scl-output-only"); 82 of_property_read_bool(np, "i2c-gpio,scl-output-only");
125} 83}
126 84
85static struct gpio_desc *i2c_gpio_get_desc(struct device *dev,
86 const char *con_id,
87 unsigned int index,
88 enum gpiod_flags gflags)
89{
90 struct gpio_desc *retdesc;
91 int ret;
92
93 retdesc = devm_gpiod_get(dev, con_id, gflags);
94 if (!IS_ERR(retdesc)) {
95 dev_dbg(dev, "got GPIO from name %s\n", con_id);
96 return retdesc;
97 }
98
99 retdesc = devm_gpiod_get_index(dev, NULL, index, gflags);
100 if (!IS_ERR(retdesc)) {
101 dev_dbg(dev, "got GPIO from index %u\n", index);
102 return retdesc;
103 }
104
105 ret = PTR_ERR(retdesc);
106
107 /* FIXME: hack in the old code, is this really necessary? */
108 if (ret == -EINVAL)
109 retdesc = ERR_PTR(-EPROBE_DEFER);
110
111 /* This happens if the GPIO driver is not yet probed, let's defer */
112 if (ret == -ENOENT)
113 retdesc = ERR_PTR(-EPROBE_DEFER);
114
115 if (ret != -EPROBE_DEFER)
116 dev_err(dev, "error trying to get descriptor: %d\n", ret);
117
118 return retdesc;
119}
120
127static int i2c_gpio_probe(struct platform_device *pdev) 121static int i2c_gpio_probe(struct platform_device *pdev)
128{ 122{
129 struct i2c_gpio_private_data *priv; 123 struct i2c_gpio_private_data *priv;
130 struct i2c_gpio_platform_data *pdata; 124 struct i2c_gpio_platform_data *pdata;
131 struct i2c_algo_bit_data *bit_data; 125 struct i2c_algo_bit_data *bit_data;
132 struct i2c_adapter *adap; 126 struct i2c_adapter *adap;
133 unsigned int sda_pin, scl_pin; 127 struct device *dev = &pdev->dev;
128 struct device_node *np = dev->of_node;
129 enum gpiod_flags gflags;
134 int ret; 130 int ret;
135 131
136 /* First get the GPIO pins; if it fails, we'll defer the probe. */ 132 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
137 if (pdev->dev.of_node) {
138 ret = of_i2c_gpio_get_pins(pdev->dev.of_node,
139 &sda_pin, &scl_pin);
140 if (ret)
141 return ret;
142 } else {
143 if (!dev_get_platdata(&pdev->dev))
144 return -ENXIO;
145 pdata = dev_get_platdata(&pdev->dev);
146 sda_pin = pdata->sda_pin;
147 scl_pin = pdata->scl_pin;
148 }
149
150 ret = devm_gpio_request(&pdev->dev, sda_pin, "sda");
151 if (ret) {
152 if (ret == -EINVAL)
153 ret = -EPROBE_DEFER; /* Try again later */
154 return ret;
155 }
156 ret = devm_gpio_request(&pdev->dev, scl_pin, "scl");
157 if (ret) {
158 if (ret == -EINVAL)
159 ret = -EPROBE_DEFER; /* Try again later */
160 return ret;
161 }
162
163 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
164 if (!priv) 133 if (!priv)
165 return -ENOMEM; 134 return -ENOMEM;
135
166 adap = &priv->adap; 136 adap = &priv->adap;
167 bit_data = &priv->bit_data; 137 bit_data = &priv->bit_data;
168 pdata = &priv->pdata; 138 pdata = &priv->pdata;
169 139
170 if (pdev->dev.of_node) { 140 if (np) {
171 pdata->sda_pin = sda_pin; 141 of_i2c_gpio_get_props(np, pdata);
172 pdata->scl_pin = scl_pin;
173 of_i2c_gpio_get_props(pdev->dev.of_node, pdata);
174 } else { 142 } else {
175 memcpy(pdata, dev_get_platdata(&pdev->dev), sizeof(*pdata)); 143 /*
144 * If all platform data settings are zero it is OK
145 * to not provide any platform data from the board.
146 */
147 if (dev_get_platdata(dev))
148 memcpy(pdata, dev_get_platdata(dev), sizeof(*pdata));
176 } 149 }
177 150
178 if (pdata->sda_is_open_drain) { 151 /*
179 gpio_direction_output(pdata->sda_pin, 1); 152 * First get the GPIO pins; if it fails, we'll defer the probe.
180 bit_data->setsda = i2c_gpio_setsda_val; 153 * If the SDA line is marked from platform data or device tree as
181 } else { 154 * "open drain" it means something outside of our control is making
182 gpio_direction_input(pdata->sda_pin); 155 * this line being handled as open drain, and we should just handle
183 bit_data->setsda = i2c_gpio_setsda_dir; 156 * it as any other output. Else we enforce open drain as this is
184 } 157 * required for an I2C bus.
158 */
159 if (pdata->sda_is_open_drain)
160 gflags = GPIOD_OUT_HIGH;
161 else
162 gflags = GPIOD_OUT_HIGH_OPEN_DRAIN;
163 priv->sda = i2c_gpio_get_desc(dev, "sda", 0, gflags);
164 if (IS_ERR(priv->sda))
165 return PTR_ERR(priv->sda);
166
167 /*
168 * If the SCL line is marked from platform data or device tree as
169 * "open drain" it means something outside of our control is making
170 * this line being handled as open drain, and we should just handle
171 * it as any other output. Else we enforce open drain as this is
172 * required for an I2C bus.
173 */
174 if (pdata->scl_is_open_drain)
175 gflags = GPIOD_OUT_LOW;
176 else
177 gflags = GPIOD_OUT_LOW_OPEN_DRAIN;
178 priv->scl = i2c_gpio_get_desc(dev, "scl", 1, gflags);
179 if (IS_ERR(priv->scl))
180 return PTR_ERR(priv->scl);
185 181
186 if (pdata->scl_is_open_drain || pdata->scl_is_output_only) { 182 bit_data->setsda = i2c_gpio_setsda_val;
187 gpio_direction_output(pdata->scl_pin, 1); 183 bit_data->setscl = i2c_gpio_setscl_val;
188 bit_data->setscl = i2c_gpio_setscl_val;
189 } else {
190 gpio_direction_input(pdata->scl_pin);
191 bit_data->setscl = i2c_gpio_setscl_dir;
192 }
193 184
194 if (!pdata->scl_is_output_only) 185 if (!pdata->scl_is_output_only)
195 bit_data->getscl = i2c_gpio_getscl; 186 bit_data->getscl = i2c_gpio_getscl;
@@ -207,18 +198,18 @@ static int i2c_gpio_probe(struct platform_device *pdev)
207 else 198 else
208 bit_data->timeout = HZ / 10; /* 100 ms */ 199 bit_data->timeout = HZ / 10; /* 100 ms */
209 200
210 bit_data->data = pdata; 201 bit_data->data = priv;
211 202
212 adap->owner = THIS_MODULE; 203 adap->owner = THIS_MODULE;
213 if (pdev->dev.of_node) 204 if (np)
214 strlcpy(adap->name, dev_name(&pdev->dev), sizeof(adap->name)); 205 strlcpy(adap->name, dev_name(dev), sizeof(adap->name));
215 else 206 else
216 snprintf(adap->name, sizeof(adap->name), "i2c-gpio%d", pdev->id); 207 snprintf(adap->name, sizeof(adap->name), "i2c-gpio%d", pdev->id);
217 208
218 adap->algo_data = bit_data; 209 adap->algo_data = bit_data;
219 adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD; 210 adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
220 adap->dev.parent = &pdev->dev; 211 adap->dev.parent = dev;
221 adap->dev.of_node = pdev->dev.of_node; 212 adap->dev.of_node = np;
222 213
223 adap->nr = pdev->id; 214 adap->nr = pdev->id;
224 ret = i2c_bit_add_numbered_bus(adap); 215 ret = i2c_bit_add_numbered_bus(adap);
@@ -227,8 +218,13 @@ static int i2c_gpio_probe(struct platform_device *pdev)
227 218
228 platform_set_drvdata(pdev, priv); 219 platform_set_drvdata(pdev, priv);
229 220
230 dev_info(&pdev->dev, "using pins %u (SDA) and %u (SCL%s)\n", 221 /*
231 pdata->sda_pin, pdata->scl_pin, 222 * FIXME: using global GPIO numbers is not helpful. If/when we
223 * get accessors to get the actual name of the GPIO line,
224 * from the descriptor, then provide that instead.
225 */
226 dev_info(dev, "using lines %u (SDA) and %u (SCL%s)\n",
227 desc_to_gpio(priv->sda), desc_to_gpio(priv->scl),
232 pdata->scl_is_output_only 228 pdata->scl_is_output_only
233 ? ", no clock stretching" : ""); 229 ? ", no clock stretching" : "");
234 230
diff --git a/drivers/i2c/busses/i2c-img-scb.c b/drivers/i2c/busses/i2c-img-scb.c
index eb1d91b986fd..f038858b6c54 100644
--- a/drivers/i2c/busses/i2c-img-scb.c
+++ b/drivers/i2c/busses/i2c-img-scb.c
@@ -82,6 +82,7 @@
82#include <linux/module.h> 82#include <linux/module.h>
83#include <linux/of_platform.h> 83#include <linux/of_platform.h>
84#include <linux/platform_device.h> 84#include <linux/platform_device.h>
85#include <linux/pm_runtime.h>
85#include <linux/slab.h> 86#include <linux/slab.h>
86#include <linux/timer.h> 87#include <linux/timer.h>
87 88
@@ -280,6 +281,8 @@
280#define ISR_COMPLETE(err) (ISR_COMPLETE_M | (ISR_STATUS_M & (err))) 281#define ISR_COMPLETE(err) (ISR_COMPLETE_M | (ISR_STATUS_M & (err)))
281#define ISR_FATAL(err) (ISR_COMPLETE(err) | ISR_FATAL_M) 282#define ISR_FATAL(err) (ISR_COMPLETE(err) | ISR_FATAL_M)
282 283
284#define IMG_I2C_PM_TIMEOUT 1000 /* ms */
285
283enum img_i2c_mode { 286enum img_i2c_mode {
284 MODE_INACTIVE, 287 MODE_INACTIVE,
285 MODE_RAW, 288 MODE_RAW,
@@ -408,6 +411,9 @@ struct img_i2c {
408 unsigned int raw_timeout; 411 unsigned int raw_timeout;
409}; 412};
410 413
414static int img_i2c_runtime_suspend(struct device *dev);
415static int img_i2c_runtime_resume(struct device *dev);
416
411static void img_i2c_writel(struct img_i2c *i2c, u32 offset, u32 value) 417static void img_i2c_writel(struct img_i2c *i2c, u32 offset, u32 value)
412{ 418{
413 writel(value, i2c->base + offset); 419 writel(value, i2c->base + offset);
@@ -826,9 +832,9 @@ next_atomic_cmd:
826 * Timer function to check if something has gone wrong in automatic mode (so we 832 * Timer function to check if something has gone wrong in automatic mode (so we
827 * don't have to handle so many interrupts just to catch an exception). 833 * don't have to handle so many interrupts just to catch an exception).
828 */ 834 */
829static void img_i2c_check_timer(unsigned long arg) 835static void img_i2c_check_timer(struct timer_list *t)
830{ 836{
831 struct img_i2c *i2c = (struct img_i2c *)arg; 837 struct img_i2c *i2c = from_timer(i2c, t, check_timer);
832 unsigned long flags; 838 unsigned long flags;
833 unsigned int line_status; 839 unsigned int line_status;
834 840
@@ -1054,8 +1060,8 @@ static int img_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
1054 atomic = true; 1060 atomic = true;
1055 } 1061 }
1056 1062
1057 ret = clk_prepare_enable(i2c->scb_clk); 1063 ret = pm_runtime_get_sync(adap->dev.parent);
1058 if (ret) 1064 if (ret < 0)
1059 return ret; 1065 return ret;
1060 1066
1061 for (i = 0; i < num; i++) { 1067 for (i = 0; i < num; i++) {
@@ -1131,7 +1137,8 @@ static int img_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
1131 break; 1137 break;
1132 } 1138 }
1133 1139
1134 clk_disable_unprepare(i2c->scb_clk); 1140 pm_runtime_mark_last_busy(adap->dev.parent);
1141 pm_runtime_put_autosuspend(adap->dev.parent);
1135 1142
1136 return i2c->msg_status ? i2c->msg_status : num; 1143 return i2c->msg_status ? i2c->msg_status : num;
1137} 1144}
@@ -1149,12 +1156,13 @@ static const struct i2c_algorithm img_i2c_algo = {
1149static int img_i2c_init(struct img_i2c *i2c) 1156static int img_i2c_init(struct img_i2c *i2c)
1150{ 1157{
1151 unsigned int clk_khz, bitrate_khz, clk_period, tckh, tckl, tsdh; 1158 unsigned int clk_khz, bitrate_khz, clk_period, tckh, tckl, tsdh;
1152 unsigned int i, ret, data, prescale, inc, int_bitrate, filt; 1159 unsigned int i, data, prescale, inc, int_bitrate, filt;
1153 struct img_i2c_timings timing; 1160 struct img_i2c_timings timing;
1154 u32 rev; 1161 u32 rev;
1162 int ret;
1155 1163
1156 ret = clk_prepare_enable(i2c->scb_clk); 1164 ret = pm_runtime_get_sync(i2c->adap.dev.parent);
1157 if (ret) 1165 if (ret < 0)
1158 return ret; 1166 return ret;
1159 1167
1160 rev = img_i2c_readl(i2c, SCB_CORE_REV_REG); 1168 rev = img_i2c_readl(i2c, SCB_CORE_REV_REG);
@@ -1163,7 +1171,8 @@ static int img_i2c_init(struct img_i2c *i2c)
1163 "Unknown hardware revision (%d.%d.%d.%d)\n", 1171 "Unknown hardware revision (%d.%d.%d.%d)\n",
1164 (rev >> 24) & 0xff, (rev >> 16) & 0xff, 1172 (rev >> 24) & 0xff, (rev >> 16) & 0xff,
1165 (rev >> 8) & 0xff, rev & 0xff); 1173 (rev >> 8) & 0xff, rev & 0xff);
1166 clk_disable_unprepare(i2c->scb_clk); 1174 pm_runtime_mark_last_busy(i2c->adap.dev.parent);
1175 pm_runtime_put_autosuspend(i2c->adap.dev.parent);
1167 return -EINVAL; 1176 return -EINVAL;
1168 } 1177 }
1169 1178
@@ -1314,7 +1323,8 @@ static int img_i2c_init(struct img_i2c *i2c)
1314 /* Perform a synchronous sequence to reset the bus */ 1323 /* Perform a synchronous sequence to reset the bus */
1315 ret = img_i2c_reset_bus(i2c); 1324 ret = img_i2c_reset_bus(i2c);
1316 1325
1317 clk_disable_unprepare(i2c->scb_clk); 1326 pm_runtime_mark_last_busy(i2c->adap.dev.parent);
1327 pm_runtime_put_autosuspend(i2c->adap.dev.parent);
1318 1328
1319 return ret; 1329 return ret;
1320} 1330}
@@ -1362,8 +1372,7 @@ static int img_i2c_probe(struct platform_device *pdev)
1362 } 1372 }
1363 1373
1364 /* Set up the exception check timer */ 1374 /* Set up the exception check timer */
1365 setup_timer(&i2c->check_timer, img_i2c_check_timer, 1375 timer_setup(&i2c->check_timer, img_i2c_check_timer, 0);
1366 (unsigned long)i2c);
1367 1376
1368 i2c->bitrate = timings[0].max_bitrate; 1377 i2c->bitrate = timings[0].max_bitrate;
1369 if (!of_property_read_u32(node, "clock-frequency", &val)) 1378 if (!of_property_read_u32(node, "clock-frequency", &val))
@@ -1384,22 +1393,30 @@ static int img_i2c_probe(struct platform_device *pdev)
1384 1393
1385 platform_set_drvdata(pdev, i2c); 1394 platform_set_drvdata(pdev, i2c);
1386 1395
1387 ret = clk_prepare_enable(i2c->sys_clk); 1396 pm_runtime_set_autosuspend_delay(&pdev->dev, IMG_I2C_PM_TIMEOUT);
1388 if (ret) 1397 pm_runtime_use_autosuspend(&pdev->dev);
1389 return ret; 1398 pm_runtime_enable(&pdev->dev);
1399 if (!pm_runtime_enabled(&pdev->dev)) {
1400 ret = img_i2c_runtime_resume(&pdev->dev);
1401 if (ret)
1402 return ret;
1403 }
1390 1404
1391 ret = img_i2c_init(i2c); 1405 ret = img_i2c_init(i2c);
1392 if (ret) 1406 if (ret)
1393 goto disable_clk; 1407 goto rpm_disable;
1394 1408
1395 ret = i2c_add_numbered_adapter(&i2c->adap); 1409 ret = i2c_add_numbered_adapter(&i2c->adap);
1396 if (ret < 0) 1410 if (ret < 0)
1397 goto disable_clk; 1411 goto rpm_disable;
1398 1412
1399 return 0; 1413 return 0;
1400 1414
1401disable_clk: 1415rpm_disable:
1402 clk_disable_unprepare(i2c->sys_clk); 1416 if (!pm_runtime_enabled(&pdev->dev))
1417 img_i2c_runtime_suspend(&pdev->dev);
1418 pm_runtime_disable(&pdev->dev);
1419 pm_runtime_dont_use_autosuspend(&pdev->dev);
1403 return ret; 1420 return ret;
1404} 1421}
1405 1422
@@ -1408,19 +1425,55 @@ static int img_i2c_remove(struct platform_device *dev)
1408 struct img_i2c *i2c = platform_get_drvdata(dev); 1425 struct img_i2c *i2c = platform_get_drvdata(dev);
1409 1426
1410 i2c_del_adapter(&i2c->adap); 1427 i2c_del_adapter(&i2c->adap);
1428 pm_runtime_disable(&dev->dev);
1429 if (!pm_runtime_status_suspended(&dev->dev))
1430 img_i2c_runtime_suspend(&dev->dev);
1431
1432 return 0;
1433}
1434
1435static int img_i2c_runtime_suspend(struct device *dev)
1436{
1437 struct img_i2c *i2c = dev_get_drvdata(dev);
1438
1439 clk_disable_unprepare(i2c->scb_clk);
1411 clk_disable_unprepare(i2c->sys_clk); 1440 clk_disable_unprepare(i2c->sys_clk);
1412 1441
1413 return 0; 1442 return 0;
1414} 1443}
1415 1444
1445static int img_i2c_runtime_resume(struct device *dev)
1446{
1447 struct img_i2c *i2c = dev_get_drvdata(dev);
1448 int ret;
1449
1450 ret = clk_prepare_enable(i2c->sys_clk);
1451 if (ret) {
1452 dev_err(dev, "Unable to enable sys clock\n");
1453 return ret;
1454 }
1455
1456 ret = clk_prepare_enable(i2c->scb_clk);
1457 if (ret) {
1458 dev_err(dev, "Unable to enable scb clock\n");
1459 clk_disable_unprepare(i2c->sys_clk);
1460 return ret;
1461 }
1462
1463 return 0;
1464}
1465
1416#ifdef CONFIG_PM_SLEEP 1466#ifdef CONFIG_PM_SLEEP
1417static int img_i2c_suspend(struct device *dev) 1467static int img_i2c_suspend(struct device *dev)
1418{ 1468{
1419 struct img_i2c *i2c = dev_get_drvdata(dev); 1469 struct img_i2c *i2c = dev_get_drvdata(dev);
1470 int ret;
1420 1471
1421 img_i2c_switch_mode(i2c, MODE_SUSPEND); 1472 ret = pm_runtime_force_suspend(dev);
1473 if (ret)
1474 return ret;
1422 1475
1423 clk_disable_unprepare(i2c->sys_clk); 1476 img_i2c_switch_mode(i2c, MODE_SUSPEND);
1424 1477
1425 return 0; 1478 return 0;
1426} 1479}
@@ -1430,7 +1483,7 @@ static int img_i2c_resume(struct device *dev)
1430 struct img_i2c *i2c = dev_get_drvdata(dev); 1483 struct img_i2c *i2c = dev_get_drvdata(dev);
1431 int ret; 1484 int ret;
1432 1485
1433 ret = clk_prepare_enable(i2c->sys_clk); 1486 ret = pm_runtime_force_resume(dev);
1434 if (ret) 1487 if (ret)
1435 return ret; 1488 return ret;
1436 1489
@@ -1440,7 +1493,12 @@ static int img_i2c_resume(struct device *dev)
1440} 1493}
1441#endif /* CONFIG_PM_SLEEP */ 1494#endif /* CONFIG_PM_SLEEP */
1442 1495
1443static SIMPLE_DEV_PM_OPS(img_i2c_pm, img_i2c_suspend, img_i2c_resume); 1496static const struct dev_pm_ops img_i2c_pm = {
1497 SET_RUNTIME_PM_OPS(img_i2c_runtime_suspend,
1498 img_i2c_runtime_resume,
1499 NULL)
1500 SET_SYSTEM_SLEEP_PM_OPS(img_i2c_suspend, img_i2c_resume)
1501};
1444 1502
1445static const struct of_device_id img_scb_i2c_match[] = { 1503static const struct of_device_id img_scb_i2c_match[] = {
1446 { .compatible = "img,scb-i2c" }, 1504 { .compatible = "img,scb-i2c" },
diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c
index 96caf378b1dc..950a9d74f54d 100644
--- a/drivers/i2c/busses/i2c-mpc.c
+++ b/drivers/i2c/busses/i2c-mpc.c
@@ -322,7 +322,7 @@ static const struct mpc_i2c_divider mpc_i2c_dividers_8xxx[] = {
322 322
323static u32 mpc_i2c_get_sec_cfg_8xxx(void) 323static u32 mpc_i2c_get_sec_cfg_8xxx(void)
324{ 324{
325 struct device_node *node = NULL; 325 struct device_node *node;
326 u32 __iomem *reg; 326 u32 __iomem *reg;
327 u32 val = 0; 327 u32 val = 0;
328 328
@@ -700,7 +700,7 @@ static int fsl_i2c_probe(struct platform_device *op)
700 } 700 }
701 } 701 }
702 702
703 if (of_get_property(op->dev.of_node, "fsl,preserve-clocking", NULL)) { 703 if (of_property_read_bool(op->dev.of_node, "fsl,preserve-clocking")) {
704 clock = MPC_I2C_CLOCK_PRESERVE; 704 clock = MPC_I2C_CLOCK_PRESERVE;
705 } else { 705 } else {
706 prop = of_get_property(op->dev.of_node, "clock-frequency", 706 prop = of_get_property(op->dev.of_node, "clock-frequency",
diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
index 23c2ea2baedc..b9172f08fd05 100644
--- a/drivers/i2c/busses/i2c-omap.c
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -487,6 +487,22 @@ static int omap_i2c_init(struct omap_i2c_dev *omap)
487} 487}
488 488
489/* 489/*
490 * Try bus recovery, but only if SDA is actually low.
491 */
492static int omap_i2c_recover_bus(struct omap_i2c_dev *omap)
493{
494 u16 systest;
495
496 systest = omap_i2c_read_reg(omap, OMAP_I2C_SYSTEST_REG);
497 if ((systest & OMAP_I2C_SYSTEST_SCL_I_FUNC) &&
498 (systest & OMAP_I2C_SYSTEST_SDA_I_FUNC))
499 return 0; /* bus seems to already be fine */
500 if (!(systest & OMAP_I2C_SYSTEST_SCL_I_FUNC))
501 return -EBUSY; /* recovery would not fix SCL */
502 return i2c_recover_bus(&omap->adapter);
503}
504
505/*
490 * Waiting on Bus Busy 506 * Waiting on Bus Busy
491 */ 507 */
492static int omap_i2c_wait_for_bb(struct omap_i2c_dev *omap) 508static int omap_i2c_wait_for_bb(struct omap_i2c_dev *omap)
@@ -496,7 +512,7 @@ static int omap_i2c_wait_for_bb(struct omap_i2c_dev *omap)
496 timeout = jiffies + OMAP_I2C_TIMEOUT; 512 timeout = jiffies + OMAP_I2C_TIMEOUT;
497 while (omap_i2c_read_reg(omap, OMAP_I2C_STAT_REG) & OMAP_I2C_STAT_BB) { 513 while (omap_i2c_read_reg(omap, OMAP_I2C_STAT_REG) & OMAP_I2C_STAT_BB) {
498 if (time_after(jiffies, timeout)) 514 if (time_after(jiffies, timeout))
499 return i2c_recover_bus(&omap->adapter); 515 return omap_i2c_recover_bus(omap);
500 msleep(1); 516 msleep(1);
501 } 517 }
502 518
@@ -577,8 +593,13 @@ static int omap_i2c_wait_for_bb_valid(struct omap_i2c_dev *omap)
577 } 593 }
578 594
579 if (time_after(jiffies, timeout)) { 595 if (time_after(jiffies, timeout)) {
596 /*
597 * SDA or SCL were low for the entire timeout without
598 * any activity detected. Most likely, a slave is
599 * locking up the bus with no master driving the clock.
600 */
580 dev_warn(omap->dev, "timeout waiting for bus ready\n"); 601 dev_warn(omap->dev, "timeout waiting for bus ready\n");
581 return -ETIMEDOUT; 602 return omap_i2c_recover_bus(omap);
582 } 603 }
583 604
584 msleep(1); 605 msleep(1);
diff --git a/drivers/i2c/busses/i2c-parport-light.c b/drivers/i2c/busses/i2c-parport-light.c
index faa8fb8f2b8f..fa41ff799533 100644
--- a/drivers/i2c/busses/i2c-parport-light.c
+++ b/drivers/i2c/busses/i2c-parport-light.c
@@ -123,7 +123,6 @@ static struct i2c_adapter parport_adapter = {
123 123
124/* SMBus alert support */ 124/* SMBus alert support */
125static struct i2c_smbus_alert_setup alert_data = { 125static struct i2c_smbus_alert_setup alert_data = {
126 .alert_edge_triggered = 1,
127}; 126};
128static struct i2c_client *ara; 127static struct i2c_client *ara;
129static struct lineop parport_ctrl_irq = { 128static struct lineop parport_ctrl_irq = {
diff --git a/drivers/i2c/busses/i2c-parport.c b/drivers/i2c/busses/i2c-parport.c
index a8e54df4aed6..319209a07353 100644
--- a/drivers/i2c/busses/i2c-parport.c
+++ b/drivers/i2c/busses/i2c-parport.c
@@ -237,7 +237,6 @@ static void i2c_parport_attach(struct parport *port)
237 237
238 /* Setup SMBus alert if supported */ 238 /* Setup SMBus alert if supported */
239 if (adapter_parm[type].smbus_alert) { 239 if (adapter_parm[type].smbus_alert) {
240 adapter->alert_data.alert_edge_triggered = 1;
241 adapter->ara = i2c_setup_smbus_alert(&adapter->adapter, 240 adapter->ara = i2c_setup_smbus_alert(&adapter->adapter,
242 &adapter->alert_data); 241 &adapter->alert_data);
243 if (adapter->ara) 242 if (adapter->ara)
diff --git a/drivers/i2c/busses/i2c-pnx.c b/drivers/i2c/busses/i2c-pnx.c
index 42d6b3a226f8..a542041df0cd 100644
--- a/drivers/i2c/busses/i2c-pnx.c
+++ b/drivers/i2c/busses/i2c-pnx.c
@@ -112,7 +112,6 @@ static inline void i2c_pnx_arm_timer(struct i2c_pnx_algo_data *alg_data)
112 jiffies, expires); 112 jiffies, expires);
113 113
114 timer->expires = jiffies + expires; 114 timer->expires = jiffies + expires;
115 timer->data = (unsigned long)alg_data;
116 115
117 add_timer(timer); 116 add_timer(timer);
118} 117}
@@ -435,9 +434,9 @@ static irqreturn_t i2c_pnx_interrupt(int irq, void *dev_id)
435 return IRQ_HANDLED; 434 return IRQ_HANDLED;
436} 435}
437 436
438static void i2c_pnx_timeout(unsigned long data) 437static void i2c_pnx_timeout(struct timer_list *t)
439{ 438{
440 struct i2c_pnx_algo_data *alg_data = (struct i2c_pnx_algo_data *)data; 439 struct i2c_pnx_algo_data *alg_data = from_timer(alg_data, t, mif.timer);
441 u32 ctl; 440 u32 ctl;
442 441
443 dev_err(&alg_data->adapter.dev, 442 dev_err(&alg_data->adapter.dev,
@@ -659,8 +658,7 @@ static int i2c_pnx_probe(struct platform_device *pdev)
659 if (IS_ERR(alg_data->clk)) 658 if (IS_ERR(alg_data->clk))
660 return PTR_ERR(alg_data->clk); 659 return PTR_ERR(alg_data->clk);
661 660
662 setup_timer(&alg_data->mif.timer, i2c_pnx_timeout, 661 timer_setup(&alg_data->mif.timer, i2c_pnx_timeout, 0);
663 (unsigned long)alg_data);
664 662
665 snprintf(alg_data->adapter.name, sizeof(alg_data->adapter.name), 663 snprintf(alg_data->adapter.name, sizeof(alg_data->adapter.name),
666 "%s", pdev->name); 664 "%s", pdev->name);
diff --git a/drivers/i2c/busses/i2c-riic.c b/drivers/i2c/busses/i2c-riic.c
index c811af4c8d81..95c2f1ce3cad 100644
--- a/drivers/i2c/busses/i2c-riic.c
+++ b/drivers/i2c/busses/i2c-riic.c
@@ -84,12 +84,7 @@
84 84
85#define ICSR2_NACKF 0x10 85#define ICSR2_NACKF 0x10
86 86
87/* ICBRx (@ PCLK 33MHz) */
88#define ICBR_RESERVED 0xe0 /* Should be 1 on writes */ 87#define ICBR_RESERVED 0xe0 /* Should be 1 on writes */
89#define ICBRL_SP100K (19 | ICBR_RESERVED)
90#define ICBRH_SP100K (16 | ICBR_RESERVED)
91#define ICBRL_SP400K (21 | ICBR_RESERVED)
92#define ICBRH_SP400K (9 | ICBR_RESERVED)
93 88
94#define RIIC_INIT_MSG -1 89#define RIIC_INIT_MSG -1
95 90
@@ -288,48 +283,99 @@ static const struct i2c_algorithm riic_algo = {
288 .functionality = riic_func, 283 .functionality = riic_func,
289}; 284};
290 285
291static int riic_init_hw(struct riic_dev *riic, u32 spd) 286static int riic_init_hw(struct riic_dev *riic, struct i2c_timings *t)
292{ 287{
293 int ret; 288 int ret;
294 unsigned long rate; 289 unsigned long rate;
290 int total_ticks, cks, brl, brh;
295 291
296 ret = clk_prepare_enable(riic->clk); 292 ret = clk_prepare_enable(riic->clk);
297 if (ret) 293 if (ret)
298 return ret; 294 return ret;
299 295
296 if (t->bus_freq_hz > 400000) {
297 dev_err(&riic->adapter.dev,
298 "unsupported bus speed (%dHz). 400000 max\n",
299 t->bus_freq_hz);
300 clk_disable_unprepare(riic->clk);
301 return -EINVAL;
302 }
303
304 rate = clk_get_rate(riic->clk);
305
300 /* 306 /*
301 * TODO: Implement formula to calculate the timing values depending on 307 * Assume the default register settings:
302 * variable parent clock rate and arbitrary bus speed 308 * FER.SCLE = 1 (SCL sync circuit enabled, adds 2 or 3 cycles)
309 * FER.NFE = 1 (noise circuit enabled)
310 * MR3.NF = 0 (1 cycle of noise filtered out)
311 *
312 * Freq (CKS=000) = (I2CCLK + tr + tf)/ (BRH + 3 + 1) + (BRL + 3 + 1)
313 * Freq (CKS!=000) = (I2CCLK + tr + tf)/ (BRH + 2 + 1) + (BRL + 2 + 1)
303 */ 314 */
304 rate = clk_get_rate(riic->clk); 315
305 if (rate != 33325000) { 316 /*
306 dev_err(&riic->adapter.dev, 317 * Determine reference clock rate. We must be able to get the desired
307 "invalid parent clk (%lu). Must be 33325000Hz\n", rate); 318 * frequency with only 62 clock ticks max (31 high, 31 low).
319 * Aim for a duty of 60% LOW, 40% HIGH.
320 */
321 total_ticks = DIV_ROUND_UP(rate, t->bus_freq_hz);
322
323 for (cks = 0; cks < 7; cks++) {
324 /*
325 * 60% low time must be less than BRL + 2 + 1
326 * BRL max register value is 0x1F.
327 */
328 brl = ((total_ticks * 6) / 10);
329 if (brl <= (0x1F + 3))
330 break;
331
332 total_ticks /= 2;
333 rate /= 2;
334 }
335
336 if (brl > (0x1F + 3)) {
337 dev_err(&riic->adapter.dev, "invalid speed (%lu). Too slow.\n",
338 (unsigned long)t->bus_freq_hz);
308 clk_disable_unprepare(riic->clk); 339 clk_disable_unprepare(riic->clk);
309 return -EINVAL; 340 return -EINVAL;
310 } 341 }
311 342
343 brh = total_ticks - brl;
344
345 /* Remove automatic clock ticks for sync circuit and NF */
346 if (cks == 0) {
347 brl -= 4;
348 brh -= 4;
349 } else {
350 brl -= 3;
351 brh -= 3;
352 }
353
354 /*
355 * Remove clock ticks for rise and fall times. Convert ns to clock
356 * ticks.
357 */
358 brl -= t->scl_fall_ns / (1000000000 / rate);
359 brh -= t->scl_rise_ns / (1000000000 / rate);
360
361 /* Adjust for min register values for when SCLE=1 and NFE=1 */
362 if (brl < 1)
363 brl = 1;
364 if (brh < 1)
365 brh = 1;
366
367 pr_debug("i2c-riic: freq=%lu, duty=%d, fall=%lu, rise=%lu, cks=%d, brl=%d, brh=%d\n",
368 rate / total_ticks, ((brl + 3) * 100) / (brl + brh + 6),
369 t->scl_fall_ns / (1000000000 / rate),
370 t->scl_rise_ns / (1000000000 / rate), cks, brl, brh);
371
312 /* Changing the order of accessing IICRST and ICE may break things! */ 372 /* Changing the order of accessing IICRST and ICE may break things! */
313 writeb(ICCR1_IICRST | ICCR1_SOWP, riic->base + RIIC_ICCR1); 373 writeb(ICCR1_IICRST | ICCR1_SOWP, riic->base + RIIC_ICCR1);
314 riic_clear_set_bit(riic, 0, ICCR1_ICE, RIIC_ICCR1); 374 riic_clear_set_bit(riic, 0, ICCR1_ICE, RIIC_ICCR1);
315 375
316 switch (spd) { 376 writeb(ICMR1_CKS(cks), riic->base + RIIC_ICMR1);
317 case 100000: 377 writeb(brh | ICBR_RESERVED, riic->base + RIIC_ICBRH);
318 writeb(ICMR1_CKS(3), riic->base + RIIC_ICMR1); 378 writeb(brl | ICBR_RESERVED, riic->base + RIIC_ICBRL);
319 writeb(ICBRH_SP100K, riic->base + RIIC_ICBRH);
320 writeb(ICBRL_SP100K, riic->base + RIIC_ICBRL);
321 break;
322 case 400000:
323 writeb(ICMR1_CKS(1), riic->base + RIIC_ICMR1);
324 writeb(ICBRH_SP400K, riic->base + RIIC_ICBRH);
325 writeb(ICBRL_SP400K, riic->base + RIIC_ICBRL);
326 break;
327 default:
328 dev_err(&riic->adapter.dev,
329 "unsupported bus speed (%dHz). Use 100000 or 400000\n", spd);
330 clk_disable_unprepare(riic->clk);
331 return -EINVAL;
332 }
333 379
334 writeb(0, riic->base + RIIC_ICSER); 380 writeb(0, riic->base + RIIC_ICSER);
335 writeb(ICMR3_ACKWP | ICMR3_RDRFS, riic->base + RIIC_ICMR3); 381 writeb(ICMR3_ACKWP | ICMR3_RDRFS, riic->base + RIIC_ICMR3);
@@ -351,11 +397,10 @@ static struct riic_irq_desc riic_irqs[] = {
351 397
352static int riic_i2c_probe(struct platform_device *pdev) 398static int riic_i2c_probe(struct platform_device *pdev)
353{ 399{
354 struct device_node *np = pdev->dev.of_node;
355 struct riic_dev *riic; 400 struct riic_dev *riic;
356 struct i2c_adapter *adap; 401 struct i2c_adapter *adap;
357 struct resource *res; 402 struct resource *res;
358 u32 bus_rate = 0; 403 struct i2c_timings i2c_t;
359 int i, ret; 404 int i, ret;
360 405
361 riic = devm_kzalloc(&pdev->dev, sizeof(*riic), GFP_KERNEL); 406 riic = devm_kzalloc(&pdev->dev, sizeof(*riic), GFP_KERNEL);
@@ -396,8 +441,9 @@ static int riic_i2c_probe(struct platform_device *pdev)
396 441
397 init_completion(&riic->msg_done); 442 init_completion(&riic->msg_done);
398 443
399 of_property_read_u32(np, "clock-frequency", &bus_rate); 444 i2c_parse_fw_timings(&pdev->dev, &i2c_t, true);
400 ret = riic_init_hw(riic, bus_rate); 445
446 ret = riic_init_hw(riic, &i2c_t);
401 if (ret) 447 if (ret)
402 return ret; 448 return ret;
403 449
@@ -408,7 +454,8 @@ static int riic_i2c_probe(struct platform_device *pdev)
408 454
409 platform_set_drvdata(pdev, riic); 455 platform_set_drvdata(pdev, riic);
410 456
411 dev_info(&pdev->dev, "registered with %dHz bus speed\n", bus_rate); 457 dev_info(&pdev->dev, "registered with %dHz bus speed\n",
458 i2c_t.bus_freq_hz);
412 return 0; 459 return 0;
413} 460}
414 461
diff --git a/drivers/i2c/busses/i2c-sh_mobile.c b/drivers/i2c/busses/i2c-sh_mobile.c
index 6f2aaeb7c4fa..c03acdf71397 100644
--- a/drivers/i2c/busses/i2c-sh_mobile.c
+++ b/drivers/i2c/busses/i2c-sh_mobile.c
@@ -881,7 +881,7 @@ static int sh_mobile_i2c_probe(struct platform_device *dev)
881 struct sh_mobile_i2c_data *pd; 881 struct sh_mobile_i2c_data *pd;
882 struct i2c_adapter *adap; 882 struct i2c_adapter *adap;
883 struct resource *res; 883 struct resource *res;
884 const struct of_device_id *match; 884 const struct sh_mobile_dt_config *config;
885 int ret; 885 int ret;
886 u32 bus_speed; 886 u32 bus_speed;
887 887
@@ -913,10 +913,8 @@ static int sh_mobile_i2c_probe(struct platform_device *dev)
913 pd->bus_speed = ret ? STANDARD_MODE : bus_speed; 913 pd->bus_speed = ret ? STANDARD_MODE : bus_speed;
914 pd->clks_per_count = 1; 914 pd->clks_per_count = 1;
915 915
916 match = of_match_device(sh_mobile_i2c_dt_ids, &dev->dev); 916 config = of_device_get_match_data(&dev->dev);
917 if (match) { 917 if (config) {
918 const struct sh_mobile_dt_config *config = match->data;
919
920 pd->clks_per_count = config->clks_per_count; 918 pd->clks_per_count = config->clks_per_count;
921 919
922 if (config->setup) 920 if (config->setup)
diff --git a/drivers/i2c/busses/i2c-taos-evm.c b/drivers/i2c/busses/i2c-taos-evm.c
index addd90a8cb59..7c7fc01116a1 100644
--- a/drivers/i2c/busses/i2c-taos-evm.c
+++ b/drivers/i2c/busses/i2c-taos-evm.c
@@ -282,8 +282,7 @@ static void taos_disconnect(struct serio *serio)
282{ 282{
283 struct taos_data *taos = serio_get_drvdata(serio); 283 struct taos_data *taos = serio_get_drvdata(serio);
284 284
285 if (taos->client) 285 i2c_unregister_device(taos->client);
286 i2c_unregister_device(taos->client);
287 i2c_del_adapter(&taos->adapter); 286 i2c_del_adapter(&taos->adapter);
288 serio_close(serio); 287 serio_close(serio);
289 kfree(taos); 288 kfree(taos);
diff --git a/drivers/i2c/busses/i2c-thunderx-pcidrv.c b/drivers/i2c/busses/i2c-thunderx-pcidrv.c
index df0976f4432a..19f8eec38717 100644
--- a/drivers/i2c/busses/i2c-thunderx-pcidrv.c
+++ b/drivers/i2c/busses/i2c-thunderx-pcidrv.c
@@ -118,8 +118,6 @@ static void thunder_i2c_clock_disable(struct device *dev, struct clk *clk)
118static int thunder_i2c_smbus_setup_of(struct octeon_i2c *i2c, 118static int thunder_i2c_smbus_setup_of(struct octeon_i2c *i2c,
119 struct device_node *node) 119 struct device_node *node)
120{ 120{
121 u32 type;
122
123 if (!node) 121 if (!node)
124 return -EINVAL; 122 return -EINVAL;
125 123
@@ -127,10 +125,6 @@ static int thunder_i2c_smbus_setup_of(struct octeon_i2c *i2c,
127 if (!i2c->alert_data.irq) 125 if (!i2c->alert_data.irq)
128 return -EINVAL; 126 return -EINVAL;
129 127
130 type = irqd_get_trigger_type(irq_get_irq_data(i2c->alert_data.irq));
131 i2c->alert_data.alert_edge_triggered =
132 (type & IRQ_TYPE_LEVEL_MASK) ? 1 : 0;
133
134 i2c->ara = i2c_setup_smbus_alert(&i2c->adap, &i2c->alert_data); 128 i2c->ara = i2c_setup_smbus_alert(&i2c->adap, &i2c->alert_data);
135 if (!i2c->ara) 129 if (!i2c->ara)
136 return -ENODEV; 130 return -ENODEV;
@@ -149,8 +143,7 @@ static int thunder_i2c_smbus_setup(struct octeon_i2c *i2c,
149 143
150static void thunder_i2c_smbus_remove(struct octeon_i2c *i2c) 144static void thunder_i2c_smbus_remove(struct octeon_i2c *i2c)
151{ 145{
152 if (i2c->ara) 146 i2c_unregister_device(i2c->ara);
153 i2c_unregister_device(i2c->ara);
154} 147}
155 148
156static int thunder_i2c_probe_pci(struct pci_dev *pdev, 149static int thunder_i2c_probe_pci(struct pci_dev *pdev,
diff --git a/drivers/i2c/busses/i2c-xgene-slimpro.c b/drivers/i2c/busses/i2c-xgene-slimpro.c
index 7e89ba6fcf6f..a7ac746018ad 100644
--- a/drivers/i2c/busses/i2c-xgene-slimpro.c
+++ b/drivers/i2c/busses/i2c-xgene-slimpro.c
@@ -129,6 +129,11 @@ struct slimpro_i2c_dev {
129#define to_slimpro_i2c_dev(cl) \ 129#define to_slimpro_i2c_dev(cl) \
130 container_of(cl, struct slimpro_i2c_dev, mbox_client) 130 container_of(cl, struct slimpro_i2c_dev, mbox_client)
131 131
132enum slimpro_i2c_version {
133 XGENE_SLIMPRO_I2C_V1 = 0,
134 XGENE_SLIMPRO_I2C_V2 = 1,
135};
136
132/* 137/*
133 * This function tests and clears a bitmask then returns its old value 138 * This function tests and clears a bitmask then returns its old value
134 */ 139 */
@@ -476,6 +481,15 @@ static int xgene_slimpro_i2c_probe(struct platform_device *pdev)
476 } 481 }
477 } else { 482 } else {
478 struct acpi_pcct_hw_reduced *cppc_ss; 483 struct acpi_pcct_hw_reduced *cppc_ss;
484 const struct acpi_device_id *acpi_id;
485 int version = XGENE_SLIMPRO_I2C_V1;
486
487 acpi_id = acpi_match_device(pdev->dev.driver->acpi_match_table,
488 &pdev->dev);
489 if (!acpi_id)
490 return -EINVAL;
491
492 version = (int)acpi_id->driver_data;
479 493
480 if (device_property_read_u32(&pdev->dev, "pcc-channel", 494 if (device_property_read_u32(&pdev->dev, "pcc-channel",
481 &ctx->mbox_idx)) 495 &ctx->mbox_idx))
@@ -514,9 +528,16 @@ static int xgene_slimpro_i2c_probe(struct platform_device *pdev)
514 */ 528 */
515 ctx->comm_base_addr = cppc_ss->base_address; 529 ctx->comm_base_addr = cppc_ss->base_address;
516 if (ctx->comm_base_addr) { 530 if (ctx->comm_base_addr) {
517 ctx->pcc_comm_addr = memremap(ctx->comm_base_addr, 531 if (version == XGENE_SLIMPRO_I2C_V2)
518 cppc_ss->length, 532 ctx->pcc_comm_addr = memremap(
519 MEMREMAP_WB); 533 ctx->comm_base_addr,
534 cppc_ss->length,
535 MEMREMAP_WT);
536 else
537 ctx->pcc_comm_addr = memremap(
538 ctx->comm_base_addr,
539 cppc_ss->length,
540 MEMREMAP_WB);
520 } else { 541 } else {
521 dev_err(&pdev->dev, "Failed to get PCC comm region\n"); 542 dev_err(&pdev->dev, "Failed to get PCC comm region\n");
522 rc = -ENOENT; 543 rc = -ENOENT;
@@ -581,7 +602,8 @@ MODULE_DEVICE_TABLE(of, xgene_slimpro_i2c_dt_ids);
581 602
582#ifdef CONFIG_ACPI 603#ifdef CONFIG_ACPI
583static const struct acpi_device_id xgene_slimpro_i2c_acpi_ids[] = { 604static const struct acpi_device_id xgene_slimpro_i2c_acpi_ids[] = {
584 {"APMC0D40", 0}, 605 {"APMC0D40", XGENE_SLIMPRO_I2C_V1},
606 {"APMC0D8B", XGENE_SLIMPRO_I2C_V2},
585 {} 607 {}
586}; 608};
587MODULE_DEVICE_TABLE(acpi, xgene_slimpro_i2c_acpi_ids); 609MODULE_DEVICE_TABLE(acpi, xgene_slimpro_i2c_acpi_ids);
diff --git a/drivers/i2c/busses/i2c-xlp9xx.c b/drivers/i2c/busses/i2c-xlp9xx.c
index 6b106e94bc09..b970bf8f38e5 100644
--- a/drivers/i2c/busses/i2c-xlp9xx.c
+++ b/drivers/i2c/busses/i2c-xlp9xx.c
@@ -7,6 +7,7 @@
7 */ 7 */
8 8
9#include <linux/acpi.h> 9#include <linux/acpi.h>
10#include <linux/clk.h>
10#include <linux/completion.h> 11#include <linux/completion.h>
11#include <linux/i2c.h> 12#include <linux/i2c.h>
12#include <linux/init.h> 13#include <linux/init.h>
@@ -81,9 +82,12 @@ struct xlp9xx_i2c_dev {
81 struct completion msg_complete; 82 struct completion msg_complete;
82 int irq; 83 int irq;
83 bool msg_read; 84 bool msg_read;
85 bool len_recv;
86 bool client_pec;
84 u32 __iomem *base; 87 u32 __iomem *base;
85 u32 msg_buf_remaining; 88 u32 msg_buf_remaining;
86 u32 msg_len; 89 u32 msg_len;
90 u32 ip_clk_hz;
87 u32 clk_hz; 91 u32 clk_hz;
88 u32 msg_err; 92 u32 msg_err;
89 u8 *msg_buf; 93 u8 *msg_buf;
@@ -141,10 +145,25 @@ static void xlp9xx_i2c_fill_tx_fifo(struct xlp9xx_i2c_dev *priv)
141static void xlp9xx_i2c_drain_rx_fifo(struct xlp9xx_i2c_dev *priv) 145static void xlp9xx_i2c_drain_rx_fifo(struct xlp9xx_i2c_dev *priv)
142{ 146{
143 u32 len, i; 147 u32 len, i;
144 u8 *buf = priv->msg_buf; 148 u8 rlen, *buf = priv->msg_buf;
145 149
146 len = xlp9xx_read_i2c_reg(priv, XLP9XX_I2C_FIFOWCNT) & 150 len = xlp9xx_read_i2c_reg(priv, XLP9XX_I2C_FIFOWCNT) &
147 XLP9XX_I2C_FIFO_WCNT_MASK; 151 XLP9XX_I2C_FIFO_WCNT_MASK;
152 if (!len)
153 return;
154 if (priv->len_recv) {
155 /* read length byte */
156 rlen = xlp9xx_read_i2c_reg(priv, XLP9XX_I2C_MRXFIFO);
157 *buf++ = rlen;
158 len--;
159 if (priv->client_pec)
160 ++rlen;
161 /* update remaining bytes and message length */
162 priv->msg_buf_remaining = rlen;
163 priv->msg_len = rlen + 1;
164 priv->len_recv = false;
165 }
166
148 len = min(priv->msg_buf_remaining, len); 167 len = min(priv->msg_buf_remaining, len);
149 for (i = 0; i < len; i++, buf++) 168 for (i = 0; i < len; i++, buf++)
150 *buf = xlp9xx_read_i2c_reg(priv, XLP9XX_I2C_MRXFIFO); 169 *buf = xlp9xx_read_i2c_reg(priv, XLP9XX_I2C_MRXFIFO);
@@ -213,7 +232,7 @@ static int xlp9xx_i2c_init(struct xlp9xx_i2c_dev *priv)
213 * The controller uses 5 * SCL clock internally. 232 * The controller uses 5 * SCL clock internally.
214 * So prescale value should be divided by 5. 233 * So prescale value should be divided by 5.
215 */ 234 */
216 prescale = DIV_ROUND_UP(XLP9XX_I2C_IP_CLK_FREQ, priv->clk_hz); 235 prescale = DIV_ROUND_UP(priv->ip_clk_hz, priv->clk_hz);
217 prescale = ((prescale - 8) / 5) - 1; 236 prescale = ((prescale - 8) / 5) - 1;
218 xlp9xx_write_i2c_reg(priv, XLP9XX_I2C_CTRL, XLP9XX_I2C_CTRL_RST); 237 xlp9xx_write_i2c_reg(priv, XLP9XX_I2C_CTRL, XLP9XX_I2C_CTRL_RST);
219 xlp9xx_write_i2c_reg(priv, XLP9XX_I2C_CTRL, XLP9XX_I2C_CTRL_EN | 238 xlp9xx_write_i2c_reg(priv, XLP9XX_I2C_CTRL, XLP9XX_I2C_CTRL_EN |
@@ -228,7 +247,7 @@ static int xlp9xx_i2c_xfer_msg(struct xlp9xx_i2c_dev *priv, struct i2c_msg *msg,
228 int last_msg) 247 int last_msg)
229{ 248{
230 unsigned long timeleft; 249 unsigned long timeleft;
231 u32 intr_mask, cmd, val; 250 u32 intr_mask, cmd, val, len;
232 251
233 priv->msg_buf = msg->buf; 252 priv->msg_buf = msg->buf;
234 priv->msg_buf_remaining = priv->msg_len = msg->len; 253 priv->msg_buf_remaining = priv->msg_len = msg->len;
@@ -261,9 +280,13 @@ static int xlp9xx_i2c_xfer_msg(struct xlp9xx_i2c_dev *priv, struct i2c_msg *msg,
261 else 280 else
262 val &= ~XLP9XX_I2C_CTRL_ADDMODE; 281 val &= ~XLP9XX_I2C_CTRL_ADDMODE;
263 282
283 priv->len_recv = msg->flags & I2C_M_RECV_LEN;
284 len = priv->len_recv ? XLP9XX_I2C_FIFO_SIZE : msg->len;
285 priv->client_pec = msg->flags & I2C_CLIENT_PEC;
286
264 /* set data length to be transferred */ 287 /* set data length to be transferred */
265 val = (val & ~XLP9XX_I2C_CTRL_MCTLEN_MASK) | 288 val = (val & ~XLP9XX_I2C_CTRL_MCTLEN_MASK) |
266 (msg->len << XLP9XX_I2C_CTRL_MCTLEN_SHIFT); 289 (len << XLP9XX_I2C_CTRL_MCTLEN_SHIFT);
267 xlp9xx_write_i2c_reg(priv, XLP9XX_I2C_CTRL, val); 290 xlp9xx_write_i2c_reg(priv, XLP9XX_I2C_CTRL, val);
268 291
269 /* fill fifo during tx */ 292 /* fill fifo during tx */
@@ -310,6 +333,9 @@ static int xlp9xx_i2c_xfer_msg(struct xlp9xx_i2c_dev *priv, struct i2c_msg *msg,
310 return -ETIMEDOUT; 333 return -ETIMEDOUT;
311 } 334 }
312 335
336 /* update msg->len with actual received length */
337 if (msg->flags & I2C_M_RECV_LEN)
338 msg->len = priv->msg_len;
313 return 0; 339 return 0;
314} 340}
315 341
@@ -342,9 +368,19 @@ static const struct i2c_algorithm xlp9xx_i2c_algo = {
342static int xlp9xx_i2c_get_frequency(struct platform_device *pdev, 368static int xlp9xx_i2c_get_frequency(struct platform_device *pdev,
343 struct xlp9xx_i2c_dev *priv) 369 struct xlp9xx_i2c_dev *priv)
344{ 370{
371 struct clk *clk;
345 u32 freq; 372 u32 freq;
346 int err; 373 int err;
347 374
375 clk = devm_clk_get(&pdev->dev, NULL);
376 if (IS_ERR(clk)) {
377 priv->ip_clk_hz = XLP9XX_I2C_IP_CLK_FREQ;
378 dev_dbg(&pdev->dev, "using default input frequency %u\n",
379 priv->ip_clk_hz);
380 } else {
381 priv->ip_clk_hz = clk_get_rate(clk);
382 }
383
348 err = device_property_read_u32(&pdev->dev, "clock-frequency", &freq); 384 err = device_property_read_u32(&pdev->dev, "clock-frequency", &freq);
349 if (err) { 385 if (err) {
350 freq = XLP9XX_I2C_DEFAULT_FREQ; 386 freq = XLP9XX_I2C_DEFAULT_FREQ;
diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index 56e46581b84b..706164b4c5be 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -29,6 +29,7 @@
29#include <linux/errno.h> 29#include <linux/errno.h>
30#include <linux/gpio.h> 30#include <linux/gpio.h>
31#include <linux/i2c.h> 31#include <linux/i2c.h>
32#include <linux/i2c-smbus.h>
32#include <linux/idr.h> 33#include <linux/idr.h>
33#include <linux/init.h> 34#include <linux/init.h>
34#include <linux/irqflags.h> 35#include <linux/irqflags.h>
@@ -205,9 +206,6 @@ static int i2c_generic_recovery(struct i2c_adapter *adap)
205 */ 206 */
206 while (i++ < RECOVERY_CLK_CNT * 2) { 207 while (i++ < RECOVERY_CLK_CNT * 2) {
207 if (val) { 208 if (val) {
208 /* Break if SDA is high */
209 if (bri->get_sda && bri->get_sda(adap))
210 break;
211 /* SCL shouldn't be low here */ 209 /* SCL shouldn't be low here */
212 if (!bri->get_scl(adap)) { 210 if (!bri->get_scl(adap)) {
213 dev_err(&adap->dev, 211 dev_err(&adap->dev,
@@ -215,6 +213,9 @@ static int i2c_generic_recovery(struct i2c_adapter *adap)
215 ret = -EBUSY; 213 ret = -EBUSY;
216 break; 214 break;
217 } 215 }
216 /* Break if SDA is high */
217 if (bri->get_sda && bri->get_sda(adap))
218 break;
218 } 219 }
219 220
220 val = !val; 221 val = !val;
@@ -222,6 +223,10 @@ static int i2c_generic_recovery(struct i2c_adapter *adap)
222 ndelay(RECOVERY_NDELAY); 223 ndelay(RECOVERY_NDELAY);
223 } 224 }
224 225
226 /* check if recovery actually succeeded */
227 if (bri->get_sda && !bri->get_sda(adap))
228 ret = -EBUSY;
229
225 if (bri->unprepare_recovery) 230 if (bri->unprepare_recovery)
226 bri->unprepare_recovery(adap); 231 bri->unprepare_recovery(adap);
227 232
@@ -666,10 +671,16 @@ static void i2c_adapter_unlock_bus(struct i2c_adapter *adapter,
666} 671}
667 672
668static void i2c_dev_set_name(struct i2c_adapter *adap, 673static void i2c_dev_set_name(struct i2c_adapter *adap,
669 struct i2c_client *client) 674 struct i2c_client *client,
675 struct i2c_board_info const *info)
670{ 676{
671 struct acpi_device *adev = ACPI_COMPANION(&client->dev); 677 struct acpi_device *adev = ACPI_COMPANION(&client->dev);
672 678
679 if (info && info->dev_name) {
680 dev_set_name(&client->dev, "i2c-%s", info->dev_name);
681 return;
682 }
683
673 if (adev) { 684 if (adev) {
674 dev_set_name(&client->dev, "i2c-%s", acpi_dev_name(adev)); 685 dev_set_name(&client->dev, "i2c-%s", acpi_dev_name(adev));
675 return; 686 return;
@@ -766,7 +777,7 @@ i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info)
766 client->dev.of_node = info->of_node; 777 client->dev.of_node = info->of_node;
767 client->dev.fwnode = info->fwnode; 778 client->dev.fwnode = info->fwnode;
768 779
769 i2c_dev_set_name(adap, client); 780 i2c_dev_set_name(adap, client, info);
770 781
771 if (info->properties) { 782 if (info->properties) {
772 status = device_add_properties(&client->dev, info->properties); 783 status = device_add_properties(&client->dev, info->properties);
@@ -808,6 +819,8 @@ EXPORT_SYMBOL_GPL(i2c_new_device);
808 */ 819 */
809void i2c_unregister_device(struct i2c_client *client) 820void i2c_unregister_device(struct i2c_client *client)
810{ 821{
822 if (!client)
823 return;
811 if (client->dev.of_node) 824 if (client->dev.of_node)
812 of_node_clear_flag(client->dev.of_node, OF_POPULATED); 825 of_node_clear_flag(client->dev.of_node, OF_POPULATED);
813 if (ACPI_COMPANION(&client->dev)) 826 if (ACPI_COMPANION(&client->dev))
@@ -1259,6 +1272,10 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
1259 goto out_list; 1272 goto out_list;
1260 } 1273 }
1261 1274
1275 res = of_i2c_setup_smbus_alert(adap);
1276 if (res)
1277 goto out_reg;
1278
1262 dev_dbg(&adap->dev, "adapter [%s] registered\n", adap->name); 1279 dev_dbg(&adap->dev, "adapter [%s] registered\n", adap->name);
1263 1280
1264 pm_runtime_no_callbacks(&adap->dev); 1281 pm_runtime_no_callbacks(&adap->dev);
@@ -1290,6 +1307,10 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
1290 1307
1291 return 0; 1308 return 0;
1292 1309
1310out_reg:
1311 init_completion(&adap->dev_released);
1312 device_unregister(&adap->dev);
1313 wait_for_completion(&adap->dev_released);
1293out_list: 1314out_list:
1294 mutex_lock(&core_lock); 1315 mutex_lock(&core_lock);
1295 idr_remove(&i2c_adapter_idr, adap->nr); 1316 idr_remove(&i2c_adapter_idr, adap->nr);
@@ -1417,8 +1438,7 @@ static int __unregister_client(struct device *dev, void *dummy)
1417static int __unregister_dummy(struct device *dev, void *dummy) 1438static int __unregister_dummy(struct device *dev, void *dummy)
1418{ 1439{
1419 struct i2c_client *client = i2c_verify_client(dev); 1440 struct i2c_client *client = i2c_verify_client(dev);
1420 if (client) 1441 i2c_unregister_device(client);
1421 i2c_unregister_device(client);
1422 return 0; 1442 return 0;
1423} 1443}
1424 1444
diff --git a/drivers/i2c/i2c-core-smbus.c b/drivers/i2c/i2c-core-smbus.c
index 10f00a82ec9d..4bb9927afd01 100644
--- a/drivers/i2c/i2c-core-smbus.c
+++ b/drivers/i2c/i2c-core-smbus.c
@@ -17,6 +17,7 @@
17#include <linux/device.h> 17#include <linux/device.h>
18#include <linux/err.h> 18#include <linux/err.h>
19#include <linux/i2c.h> 19#include <linux/i2c.h>
20#include <linux/i2c-smbus.h>
20 21
21#define CREATE_TRACE_POINTS 22#define CREATE_TRACE_POINTS
22#include <trace/events/smbus.h> 23#include <trace/events/smbus.h>
@@ -592,3 +593,57 @@ s32 i2c_smbus_read_i2c_block_data_or_emulated(const struct i2c_client *client,
592 return i; 593 return i;
593} 594}
594EXPORT_SYMBOL(i2c_smbus_read_i2c_block_data_or_emulated); 595EXPORT_SYMBOL(i2c_smbus_read_i2c_block_data_or_emulated);
596
597/**
598 * i2c_setup_smbus_alert - Setup SMBus alert support
599 * @adapter: the target adapter
600 * @setup: setup data for the SMBus alert handler
601 * Context: can sleep
602 *
603 * Setup handling of the SMBus alert protocol on a given I2C bus segment.
604 *
605 * Handling can be done either through our IRQ handler, or by the
606 * adapter (from its handler, periodic polling, or whatever).
607 *
608 * NOTE that if we manage the IRQ, we *MUST* know if it's level or
609 * edge triggered in order to hand it to the workqueue correctly.
610 * If triggering the alert seems to wedge the system, you probably
611 * should have said it's level triggered.
612 *
613 * This returns the ara client, which should be saved for later use with
614 * i2c_handle_smbus_alert() and ultimately i2c_unregister_device(); or NULL
615 * to indicate an error.
616 */
617struct i2c_client *i2c_setup_smbus_alert(struct i2c_adapter *adapter,
618 struct i2c_smbus_alert_setup *setup)
619{
620 struct i2c_board_info ara_board_info = {
621 I2C_BOARD_INFO("smbus_alert", 0x0c),
622 .platform_data = setup,
623 };
624
625 return i2c_new_device(adapter, &ara_board_info);
626}
627EXPORT_SYMBOL_GPL(i2c_setup_smbus_alert);
628
629#if IS_ENABLED(CONFIG_I2C_SMBUS) && IS_ENABLED(CONFIG_OF)
630int of_i2c_setup_smbus_alert(struct i2c_adapter *adapter)
631{
632 struct i2c_client *client;
633 int irq;
634
635 irq = of_property_match_string(adapter->dev.of_node, "interrupt-names",
636 "smbus_alert");
637 if (irq == -EINVAL || irq == -ENODATA)
638 return 0;
639 else if (irq < 0)
640 return irq;
641
642 client = i2c_setup_smbus_alert(adapter, NULL);
643 if (!client)
644 return -ENODEV;
645
646 return 0;
647}
648EXPORT_SYMBOL_GPL(of_i2c_setup_smbus_alert);
649#endif
diff --git a/drivers/i2c/i2c-smbus.c b/drivers/i2c/i2c-smbus.c
index f9271c713d20..5a1dd7f13bac 100644
--- a/drivers/i2c/i2c-smbus.c
+++ b/drivers/i2c/i2c-smbus.c
@@ -21,12 +21,11 @@
21#include <linux/interrupt.h> 21#include <linux/interrupt.h>
22#include <linux/kernel.h> 22#include <linux/kernel.h>
23#include <linux/module.h> 23#include <linux/module.h>
24#include <linux/of_irq.h>
24#include <linux/slab.h> 25#include <linux/slab.h>
25#include <linux/workqueue.h> 26#include <linux/workqueue.h>
26 27
27struct i2c_smbus_alert { 28struct i2c_smbus_alert {
28 unsigned int alert_edge_triggered:1;
29 int irq;
30 struct work_struct alert; 29 struct work_struct alert;
31 struct i2c_client *ara; /* Alert response address */ 30 struct i2c_client *ara; /* Alert response address */
32}; 31};
@@ -72,13 +71,12 @@ static int smbus_do_alert(struct device *dev, void *addrp)
72 * The alert IRQ handler needs to hand work off to a task which can issue 71 * The alert IRQ handler needs to hand work off to a task which can issue
73 * SMBus calls, because those sleeping calls can't be made in IRQ context. 72 * SMBus calls, because those sleeping calls can't be made in IRQ context.
74 */ 73 */
75static void smbus_alert(struct work_struct *work) 74static irqreturn_t smbus_alert(int irq, void *d)
76{ 75{
77 struct i2c_smbus_alert *alert; 76 struct i2c_smbus_alert *alert = d;
78 struct i2c_client *ara; 77 struct i2c_client *ara;
79 unsigned short prev_addr = 0; /* Not a valid address */ 78 unsigned short prev_addr = 0; /* Not a valid address */
80 79
81 alert = container_of(work, struct i2c_smbus_alert, alert);
82 ara = alert->ara; 80 ara = alert->ara;
83 81
84 for (;;) { 82 for (;;) {
@@ -115,21 +113,17 @@ static void smbus_alert(struct work_struct *work)
115 prev_addr = data.addr; 113 prev_addr = data.addr;
116 } 114 }
117 115
118 /* We handled all alerts; re-enable level-triggered IRQs */ 116 return IRQ_HANDLED;
119 if (!alert->alert_edge_triggered)
120 enable_irq(alert->irq);
121} 117}
122 118
123static irqreturn_t smbalert_irq(int irq, void *d) 119static void smbalert_work(struct work_struct *work)
124{ 120{
125 struct i2c_smbus_alert *alert = d; 121 struct i2c_smbus_alert *alert;
126 122
127 /* Disable level-triggered IRQs until we handle them */ 123 alert = container_of(work, struct i2c_smbus_alert, alert);
128 if (!alert->alert_edge_triggered) 124
129 disable_irq_nosync(irq); 125 smbus_alert(0, alert);
130 126
131 schedule_work(&alert->alert);
132 return IRQ_HANDLED;
133} 127}
134 128
135/* Setup SMBALERT# infrastructure */ 129/* Setup SMBALERT# infrastructure */
@@ -139,28 +133,35 @@ static int smbalert_probe(struct i2c_client *ara,
139 struct i2c_smbus_alert_setup *setup = dev_get_platdata(&ara->dev); 133 struct i2c_smbus_alert_setup *setup = dev_get_platdata(&ara->dev);
140 struct i2c_smbus_alert *alert; 134 struct i2c_smbus_alert *alert;
141 struct i2c_adapter *adapter = ara->adapter; 135 struct i2c_adapter *adapter = ara->adapter;
142 int res; 136 int res, irq;
143 137
144 alert = devm_kzalloc(&ara->dev, sizeof(struct i2c_smbus_alert), 138 alert = devm_kzalloc(&ara->dev, sizeof(struct i2c_smbus_alert),
145 GFP_KERNEL); 139 GFP_KERNEL);
146 if (!alert) 140 if (!alert)
147 return -ENOMEM; 141 return -ENOMEM;
148 142
149 alert->alert_edge_triggered = setup->alert_edge_triggered; 143 if (setup) {
150 alert->irq = setup->irq; 144 irq = setup->irq;
151 INIT_WORK(&alert->alert, smbus_alert); 145 } else {
146 irq = of_irq_get_byname(adapter->dev.of_node, "smbus_alert");
147 if (irq <= 0)
148 return irq;
149 }
150
151 INIT_WORK(&alert->alert, smbalert_work);
152 alert->ara = ara; 152 alert->ara = ara;
153 153
154 if (setup->irq > 0) { 154 if (irq > 0) {
155 res = devm_request_irq(&ara->dev, setup->irq, smbalert_irq, 155 res = devm_request_threaded_irq(&ara->dev, irq,
156 0, "smbus_alert", alert); 156 NULL, smbus_alert,
157 IRQF_SHARED | IRQF_ONESHOT,
158 "smbus_alert", alert);
157 if (res) 159 if (res)
158 return res; 160 return res;
159 } 161 }
160 162
161 i2c_set_clientdata(ara, alert); 163 i2c_set_clientdata(ara, alert);
162 dev_info(&adapter->dev, "supports SMBALERT#, %s trigger\n", 164 dev_info(&adapter->dev, "supports SMBALERT#\n");
163 setup->alert_edge_triggered ? "edge" : "level");
164 165
165 return 0; 166 return 0;
166} 167}
@@ -190,38 +191,6 @@ static struct i2c_driver smbalert_driver = {
190}; 191};
191 192
192/** 193/**
193 * i2c_setup_smbus_alert - Setup SMBus alert support
194 * @adapter: the target adapter
195 * @setup: setup data for the SMBus alert handler
196 * Context: can sleep
197 *
198 * Setup handling of the SMBus alert protocol on a given I2C bus segment.
199 *
200 * Handling can be done either through our IRQ handler, or by the
201 * adapter (from its handler, periodic polling, or whatever).
202 *
203 * NOTE that if we manage the IRQ, we *MUST* know if it's level or
204 * edge triggered in order to hand it to the workqueue correctly.
205 * If triggering the alert seems to wedge the system, you probably
206 * should have said it's level triggered.
207 *
208 * This returns the ara client, which should be saved for later use with
209 * i2c_handle_smbus_alert() and ultimately i2c_unregister_device(); or NULL
210 * to indicate an error.
211 */
212struct i2c_client *i2c_setup_smbus_alert(struct i2c_adapter *adapter,
213 struct i2c_smbus_alert_setup *setup)
214{
215 struct i2c_board_info ara_board_info = {
216 I2C_BOARD_INFO("smbus_alert", 0x0c),
217 .platform_data = setup,
218 };
219
220 return i2c_new_device(adapter, &ara_board_info);
221}
222EXPORT_SYMBOL_GPL(i2c_setup_smbus_alert);
223
224/**
225 * i2c_handle_smbus_alert - Handle an SMBus alert 194 * i2c_handle_smbus_alert - Handle an SMBus alert
226 * @ara: the ARA client on the relevant adapter 195 * @ara: the ARA client on the relevant adapter
227 * Context: can't sleep 196 * Context: can't sleep
diff --git a/drivers/i2c/muxes/i2c-mux-pca954x.c b/drivers/i2c/muxes/i2c-mux-pca954x.c
index 7b992db38021..2ca068d8b92d 100644
--- a/drivers/i2c/muxes/i2c-mux-pca954x.c
+++ b/drivers/i2c/muxes/i2c-mux-pca954x.c
@@ -246,36 +246,6 @@ static irqreturn_t pca954x_irq_handler(int irq, void *dev_id)
246 return handled ? IRQ_HANDLED : IRQ_NONE; 246 return handled ? IRQ_HANDLED : IRQ_NONE;
247} 247}
248 248
249static void pca954x_irq_mask(struct irq_data *idata)
250{
251 struct pca954x *data = irq_data_get_irq_chip_data(idata);
252 unsigned int pos = idata->hwirq;
253 unsigned long flags;
254
255 raw_spin_lock_irqsave(&data->lock, flags);
256
257 data->irq_mask &= ~BIT(pos);
258 if (!data->irq_mask)
259 disable_irq(data->client->irq);
260
261 raw_spin_unlock_irqrestore(&data->lock, flags);
262}
263
264static void pca954x_irq_unmask(struct irq_data *idata)
265{
266 struct pca954x *data = irq_data_get_irq_chip_data(idata);
267 unsigned int pos = idata->hwirq;
268 unsigned long flags;
269
270 raw_spin_lock_irqsave(&data->lock, flags);
271
272 if (!data->irq_mask)
273 enable_irq(data->client->irq);
274 data->irq_mask |= BIT(pos);
275
276 raw_spin_unlock_irqrestore(&data->lock, flags);
277}
278
279static int pca954x_irq_set_type(struct irq_data *idata, unsigned int type) 249static int pca954x_irq_set_type(struct irq_data *idata, unsigned int type)
280{ 250{
281 if ((type & IRQ_TYPE_SENSE_MASK) != IRQ_TYPE_LEVEL_LOW) 251 if ((type & IRQ_TYPE_SENSE_MASK) != IRQ_TYPE_LEVEL_LOW)
@@ -285,8 +255,6 @@ static int pca954x_irq_set_type(struct irq_data *idata, unsigned int type)
285 255
286static struct irq_chip pca954x_irq_chip = { 256static struct irq_chip pca954x_irq_chip = {
287 .name = "i2c-mux-pca954x", 257 .name = "i2c-mux-pca954x",
288 .irq_mask = pca954x_irq_mask,
289 .irq_unmask = pca954x_irq_unmask,
290 .irq_set_type = pca954x_irq_set_type, 258 .irq_set_type = pca954x_irq_set_type,
291}; 259};
292 260
@@ -294,7 +262,7 @@ static int pca954x_irq_setup(struct i2c_mux_core *muxc)
294{ 262{
295 struct pca954x *data = i2c_mux_priv(muxc); 263 struct pca954x *data = i2c_mux_priv(muxc);
296 struct i2c_client *client = data->client; 264 struct i2c_client *client = data->client;
297 int c, err, irq; 265 int c, irq;
298 266
299 if (!data->chip->has_irq || client->irq <= 0) 267 if (!data->chip->has_irq || client->irq <= 0)
300 return 0; 268 return 0;
@@ -309,29 +277,31 @@ static int pca954x_irq_setup(struct i2c_mux_core *muxc)
309 277
310 for (c = 0; c < data->chip->nchans; c++) { 278 for (c = 0; c < data->chip->nchans; c++) {
311 irq = irq_create_mapping(data->irq, c); 279 irq = irq_create_mapping(data->irq, c);
280 if (!irq) {
281 dev_err(&client->dev, "failed irq create map\n");
282 return -EINVAL;
283 }
312 irq_set_chip_data(irq, data); 284 irq_set_chip_data(irq, data);
313 irq_set_chip_and_handler(irq, &pca954x_irq_chip, 285 irq_set_chip_and_handler(irq, &pca954x_irq_chip,
314 handle_simple_irq); 286 handle_simple_irq);
315 } 287 }
316 288
317 err = devm_request_threaded_irq(&client->dev, data->client->irq, NULL, 289 return 0;
318 pca954x_irq_handler, 290}
319 IRQF_ONESHOT | IRQF_SHARED,
320 "pca954x", data);
321 if (err)
322 goto err_req_irq;
323 291
324 disable_irq(data->client->irq); 292static void pca954x_cleanup(struct i2c_mux_core *muxc)
293{
294 struct pca954x *data = i2c_mux_priv(muxc);
295 int c, irq;
325 296
326 return 0; 297 if (data->irq) {
327err_req_irq: 298 for (c = 0; c < data->chip->nchans; c++) {
328 for (c = 0; c < data->chip->nchans; c++) { 299 irq = irq_find_mapping(data->irq, c);
329 irq = irq_find_mapping(data->irq, c); 300 irq_dispose_mapping(irq);
330 irq_dispose_mapping(irq); 301 }
302 irq_domain_remove(data->irq);
331 } 303 }
332 irq_domain_remove(data->irq); 304 i2c_mux_del_adapters(muxc);
333
334 return err;
335} 305}
336 306
337/* 307/*
@@ -391,7 +361,7 @@ static int pca954x_probe(struct i2c_client *client,
391 361
392 ret = pca954x_irq_setup(muxc); 362 ret = pca954x_irq_setup(muxc);
393 if (ret) 363 if (ret)
394 goto fail_del_adapters; 364 goto fail_cleanup;
395 365
396 /* Now create an adapter for each channel */ 366 /* Now create an adapter for each channel */
397 for (num = 0; num < data->chip->nchans; num++) { 367 for (num = 0; num < data->chip->nchans; num++) {
@@ -414,7 +384,16 @@ static int pca954x_probe(struct i2c_client *client,
414 384
415 ret = i2c_mux_add_adapter(muxc, force, num, class); 385 ret = i2c_mux_add_adapter(muxc, force, num, class);
416 if (ret) 386 if (ret)
417 goto fail_del_adapters; 387 goto fail_cleanup;
388 }
389
390 if (data->irq) {
391 ret = devm_request_threaded_irq(&client->dev, data->client->irq,
392 NULL, pca954x_irq_handler,
393 IRQF_ONESHOT | IRQF_SHARED,
394 "pca954x", data);
395 if (ret)
396 goto fail_cleanup;
418 } 397 }
419 398
420 dev_info(&client->dev, 399 dev_info(&client->dev,
@@ -424,26 +403,16 @@ static int pca954x_probe(struct i2c_client *client,
424 403
425 return 0; 404 return 0;
426 405
427fail_del_adapters: 406fail_cleanup:
428 i2c_mux_del_adapters(muxc); 407 pca954x_cleanup(muxc);
429 return ret; 408 return ret;
430} 409}
431 410
432static int pca954x_remove(struct i2c_client *client) 411static int pca954x_remove(struct i2c_client *client)
433{ 412{
434 struct i2c_mux_core *muxc = i2c_get_clientdata(client); 413 struct i2c_mux_core *muxc = i2c_get_clientdata(client);
435 struct pca954x *data = i2c_mux_priv(muxc);
436 int c, irq;
437 414
438 if (data->irq) { 415 pca954x_cleanup(muxc);
439 for (c = 0; c < data->chip->nchans; c++) {
440 irq = irq_find_mapping(data->irq, c);
441 irq_dispose_mapping(irq);
442 }
443 irq_domain_remove(data->irq);
444 }
445
446 i2c_mux_del_adapters(muxc);
447 return 0; 416 return 0;
448} 417}
449 418
diff --git a/drivers/i2c/muxes/i2c-mux-reg.c b/drivers/i2c/muxes/i2c-mux-reg.c
index d97031804de8..f6c9c3dc6cad 100644
--- a/drivers/i2c/muxes/i2c-mux-reg.c
+++ b/drivers/i2c/muxes/i2c-mux-reg.c
@@ -107,9 +107,9 @@ static int i2c_mux_reg_probe_dt(struct regmux *mux,
107 put_device(&adapter->dev); 107 put_device(&adapter->dev);
108 108
109 mux->data.n_values = of_get_child_count(np); 109 mux->data.n_values = of_get_child_count(np);
110 if (of_find_property(np, "little-endian", NULL)) { 110 if (of_property_read_bool(np, "little-endian")) {
111 mux->data.little_endian = true; 111 mux->data.little_endian = true;
112 } else if (of_find_property(np, "big-endian", NULL)) { 112 } else if (of_property_read_bool(np, "big-endian")) {
113 mux->data.little_endian = false; 113 mux->data.little_endian = false;
114 } else { 114 } else {
115#if defined(__BYTE_ORDER) ? __BYTE_ORDER == __LITTLE_ENDIAN : \ 115#if defined(__BYTE_ORDER) ? __BYTE_ORDER == __LITTLE_ENDIAN : \
@@ -122,10 +122,7 @@ static int i2c_mux_reg_probe_dt(struct regmux *mux,
122#error Endianness not defined? 122#error Endianness not defined?
123#endif 123#endif
124 } 124 }
125 if (of_find_property(np, "write-only", NULL)) 125 mux->data.write_only = of_property_read_bool(np, "write-only");
126 mux->data.write_only = true;
127 else
128 mux->data.write_only = false;
129 126
130 values = devm_kzalloc(&pdev->dev, 127 values = devm_kzalloc(&pdev->dev,
131 sizeof(*mux->data.values) * mux->data.n_values, 128 sizeof(*mux->data.values) * mux->data.n_values,
diff --git a/drivers/mfd/intel-lpss.h b/drivers/mfd/intel-lpss.h
index 694116630ffa..865bbeaaf00c 100644
--- a/drivers/mfd/intel-lpss.h
+++ b/drivers/mfd/intel-lpss.h
@@ -38,12 +38,7 @@ int intel_lpss_resume(struct device *dev);
38#ifdef CONFIG_PM_SLEEP 38#ifdef CONFIG_PM_SLEEP
39#define INTEL_LPSS_SLEEP_PM_OPS \ 39#define INTEL_LPSS_SLEEP_PM_OPS \
40 .prepare = intel_lpss_prepare, \ 40 .prepare = intel_lpss_prepare, \
41 .suspend = intel_lpss_suspend, \ 41 SET_LATE_SYSTEM_SLEEP_PM_OPS(intel_lpss_suspend, intel_lpss_resume)
42 .resume = intel_lpss_resume, \
43 .freeze = intel_lpss_suspend, \
44 .thaw = intel_lpss_resume, \
45 .poweroff = intel_lpss_suspend, \
46 .restore = intel_lpss_resume,
47#else 42#else
48#define INTEL_LPSS_SLEEP_PM_OPS 43#define INTEL_LPSS_SLEEP_PM_OPS
49#endif 44#endif
diff --git a/drivers/mfd/sm501.c b/drivers/mfd/sm501.c
index 40534352e574..ad774161a22d 100644
--- a/drivers/mfd/sm501.c
+++ b/drivers/mfd/sm501.c
@@ -20,6 +20,7 @@
20#include <linux/platform_device.h> 20#include <linux/platform_device.h>
21#include <linux/pci.h> 21#include <linux/pci.h>
22#include <linux/i2c-gpio.h> 22#include <linux/i2c-gpio.h>
23#include <linux/gpio/machine.h>
23#include <linux/slab.h> 24#include <linux/slab.h>
24 25
25#include <linux/sm501.h> 26#include <linux/sm501.h>
@@ -1107,14 +1108,6 @@ static void sm501_gpio_remove(struct sm501_devdata *sm)
1107 kfree(gpio->regs_res); 1108 kfree(gpio->regs_res);
1108} 1109}
1109 1110
1110static inline int sm501_gpio_pin2nr(struct sm501_devdata *sm, unsigned int pin)
1111{
1112 struct sm501_gpio *gpio = &sm->gpio;
1113 int base = (pin < 32) ? gpio->low.gpio.base : gpio->high.gpio.base;
1114
1115 return (pin % 32) + base;
1116}
1117
1118static inline int sm501_gpio_isregistered(struct sm501_devdata *sm) 1111static inline int sm501_gpio_isregistered(struct sm501_devdata *sm)
1119{ 1112{
1120 return sm->gpio.registered; 1113 return sm->gpio.registered;
@@ -1129,11 +1122,6 @@ static inline void sm501_gpio_remove(struct sm501_devdata *sm)
1129{ 1122{
1130} 1123}
1131 1124
1132static inline int sm501_gpio_pin2nr(struct sm501_devdata *sm, unsigned int pin)
1133{
1134 return -1;
1135}
1136
1137static inline int sm501_gpio_isregistered(struct sm501_devdata *sm) 1125static inline int sm501_gpio_isregistered(struct sm501_devdata *sm)
1138{ 1126{
1139 return 0; 1127 return 0;
@@ -1145,20 +1133,37 @@ static int sm501_register_gpio_i2c_instance(struct sm501_devdata *sm,
1145{ 1133{
1146 struct i2c_gpio_platform_data *icd; 1134 struct i2c_gpio_platform_data *icd;
1147 struct platform_device *pdev; 1135 struct platform_device *pdev;
1136 struct gpiod_lookup_table *lookup;
1148 1137
1149 pdev = sm501_create_subdev(sm, "i2c-gpio", 0, 1138 pdev = sm501_create_subdev(sm, "i2c-gpio", 0,
1150 sizeof(struct i2c_gpio_platform_data)); 1139 sizeof(struct i2c_gpio_platform_data));
1151 if (!pdev) 1140 if (!pdev)
1152 return -ENOMEM; 1141 return -ENOMEM;
1153 1142
1154 icd = dev_get_platdata(&pdev->dev); 1143 /* Create a gpiod lookup using gpiochip-local offsets */
1155 1144 lookup = devm_kzalloc(&pdev->dev,
1156 /* We keep the pin_sda and pin_scl fields relative in case the 1145 sizeof(*lookup) + 3 * sizeof(struct gpiod_lookup),
1157 * same platform data is passed to >1 SM501. 1146 GFP_KERNEL);
1158 */ 1147 lookup->dev_id = "i2c-gpio";
1148 if (iic->pin_sda < 32)
1149 lookup->table[0].chip_label = "SM501-LOW";
1150 else
1151 lookup->table[0].chip_label = "SM501-HIGH";
1152 lookup->table[0].chip_hwnum = iic->pin_sda % 32;
1153 lookup->table[0].con_id = NULL;
1154 lookup->table[0].idx = 0;
1155 lookup->table[0].flags = GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN;
1156 if (iic->pin_scl < 32)
1157 lookup->table[1].chip_label = "SM501-LOW";
1158 else
1159 lookup->table[1].chip_label = "SM501-HIGH";
1160 lookup->table[1].chip_hwnum = iic->pin_scl % 32;
1161 lookup->table[1].con_id = NULL;
1162 lookup->table[1].idx = 1;
1163 lookup->table[1].flags = GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN;
1164 gpiod_add_lookup_table(lookup);
1159 1165
1160 icd->sda_pin = sm501_gpio_pin2nr(sm, iic->pin_sda); 1166 icd = dev_get_platdata(&pdev->dev);
1161 icd->scl_pin = sm501_gpio_pin2nr(sm, iic->pin_scl);
1162 icd->timeout = iic->timeout; 1167 icd->timeout = iic->timeout;
1163 icd->udelay = iic->udelay; 1168 icd->udelay = iic->udelay;
1164 1169
@@ -1170,9 +1175,9 @@ static int sm501_register_gpio_i2c_instance(struct sm501_devdata *sm,
1170 1175
1171 pdev->id = iic->bus_num; 1176 pdev->id = iic->bus_num;
1172 1177
1173 dev_info(sm->dev, "registering i2c-%d: sda=%d (%d), scl=%d (%d)\n", 1178 dev_info(sm->dev, "registering i2c-%d: sda=%d, scl=%d\n",
1174 iic->bus_num, 1179 iic->bus_num,
1175 icd->sda_pin, iic->pin_sda, icd->scl_pin, iic->pin_scl); 1180 iic->pin_sda, iic->pin_scl);
1176 1181
1177 return sm501_register_device(sm, pdev); 1182 return sm501_register_device(sm, pdev);
1178} 1183}
diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
index 764ff5df0dbc..e0b4b36ef010 100644
--- a/drivers/misc/eeprom/at24.c
+++ b/drivers/misc/eeprom/at24.c
@@ -12,6 +12,7 @@
12#include <linux/kernel.h> 12#include <linux/kernel.h>
13#include <linux/init.h> 13#include <linux/init.h>
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/of_device.h>
15#include <linux/slab.h> 16#include <linux/slab.h>
16#include <linux/delay.h> 17#include <linux/delay.h>
17#include <linux/mutex.h> 18#include <linux/mutex.h>
@@ -24,6 +25,7 @@
24#include <linux/i2c.h> 25#include <linux/i2c.h>
25#include <linux/nvmem-provider.h> 26#include <linux/nvmem-provider.h>
26#include <linux/platform_data/at24.h> 27#include <linux/platform_data/at24.h>
28#include <linux/pm_runtime.h>
27 29
28/* 30/*
29 * I2C EEPROMs from most vendors are inexpensive and mostly interchangeable. 31 * I2C EEPROMs from most vendors are inexpensive and mostly interchangeable.
@@ -175,6 +177,64 @@ static const struct i2c_device_id at24_ids[] = {
175}; 177};
176MODULE_DEVICE_TABLE(i2c, at24_ids); 178MODULE_DEVICE_TABLE(i2c, at24_ids);
177 179
180static const struct of_device_id at24_of_match[] = {
181 {
182 .compatible = "atmel,24c00",
183 .data = (void *)AT24_DEVICE_MAGIC(128 / 8, AT24_FLAG_TAKE8ADDR)
184 },
185 {
186 .compatible = "atmel,24c01",
187 .data = (void *)AT24_DEVICE_MAGIC(1024 / 8, 0)
188 },
189 {
190 .compatible = "atmel,24c02",
191 .data = (void *)AT24_DEVICE_MAGIC(2048 / 8, 0)
192 },
193 {
194 .compatible = "atmel,spd",
195 .data = (void *)AT24_DEVICE_MAGIC(2048 / 8,
196 AT24_FLAG_READONLY | AT24_FLAG_IRUGO)
197 },
198 {
199 .compatible = "atmel,24c04",
200 .data = (void *)AT24_DEVICE_MAGIC(4096 / 8, 0)
201 },
202 {
203 .compatible = "atmel,24c08",
204 .data = (void *)AT24_DEVICE_MAGIC(8192 / 8, 0)
205 },
206 {
207 .compatible = "atmel,24c16",
208 .data = (void *)AT24_DEVICE_MAGIC(16384 / 8, 0)
209 },
210 {
211 .compatible = "atmel,24c32",
212 .data = (void *)AT24_DEVICE_MAGIC(32768 / 8, AT24_FLAG_ADDR16)
213 },
214 {
215 .compatible = "atmel,24c64",
216 .data = (void *)AT24_DEVICE_MAGIC(65536 / 8, AT24_FLAG_ADDR16)
217 },
218 {
219 .compatible = "atmel,24c128",
220 .data = (void *)AT24_DEVICE_MAGIC(131072 / 8, AT24_FLAG_ADDR16)
221 },
222 {
223 .compatible = "atmel,24c256",
224 .data = (void *)AT24_DEVICE_MAGIC(262144 / 8, AT24_FLAG_ADDR16)
225 },
226 {
227 .compatible = "atmel,24c512",
228 .data = (void *)AT24_DEVICE_MAGIC(524288 / 8, AT24_FLAG_ADDR16)
229 },
230 {
231 .compatible = "atmel,24c1024",
232 .data = (void *)AT24_DEVICE_MAGIC(1048576 / 8, AT24_FLAG_ADDR16)
233 },
234 { },
235};
236MODULE_DEVICE_TABLE(of, at24_of_match);
237
178static const struct acpi_device_id at24_acpi_ids[] = { 238static const struct acpi_device_id at24_acpi_ids[] = {
179 { "INT3499", AT24_DEVICE_MAGIC(8192 / 8, 0) }, 239 { "INT3499", AT24_DEVICE_MAGIC(8192 / 8, 0) },
180 { } 240 { }
@@ -501,11 +561,21 @@ static ssize_t at24_eeprom_write_i2c(struct at24_data *at24, const char *buf,
501static int at24_read(void *priv, unsigned int off, void *val, size_t count) 561static int at24_read(void *priv, unsigned int off, void *val, size_t count)
502{ 562{
503 struct at24_data *at24 = priv; 563 struct at24_data *at24 = priv;
564 struct i2c_client *client;
504 char *buf = val; 565 char *buf = val;
566 int ret;
505 567
506 if (unlikely(!count)) 568 if (unlikely(!count))
507 return count; 569 return count;
508 570
571 client = at24_translate_offset(at24, &off);
572
573 ret = pm_runtime_get_sync(&client->dev);
574 if (ret < 0) {
575 pm_runtime_put_noidle(&client->dev);
576 return ret;
577 }
578
509 /* 579 /*
510 * Read data from chip, protecting against concurrent updates 580 * Read data from chip, protecting against concurrent updates
511 * from this host, but not from other I2C masters. 581 * from this host, but not from other I2C masters.
@@ -518,6 +588,7 @@ static int at24_read(void *priv, unsigned int off, void *val, size_t count)
518 status = at24->read_func(at24, buf, off, count); 588 status = at24->read_func(at24, buf, off, count);
519 if (status < 0) { 589 if (status < 0) {
520 mutex_unlock(&at24->lock); 590 mutex_unlock(&at24->lock);
591 pm_runtime_put(&client->dev);
521 return status; 592 return status;
522 } 593 }
523 buf += status; 594 buf += status;
@@ -527,17 +598,29 @@ static int at24_read(void *priv, unsigned int off, void *val, size_t count)
527 598
528 mutex_unlock(&at24->lock); 599 mutex_unlock(&at24->lock);
529 600
601 pm_runtime_put(&client->dev);
602
530 return 0; 603 return 0;
531} 604}
532 605
533static int at24_write(void *priv, unsigned int off, void *val, size_t count) 606static int at24_write(void *priv, unsigned int off, void *val, size_t count)
534{ 607{
535 struct at24_data *at24 = priv; 608 struct at24_data *at24 = priv;
609 struct i2c_client *client;
536 char *buf = val; 610 char *buf = val;
611 int ret;
537 612
538 if (unlikely(!count)) 613 if (unlikely(!count))
539 return -EINVAL; 614 return -EINVAL;
540 615
616 client = at24_translate_offset(at24, &off);
617
618 ret = pm_runtime_get_sync(&client->dev);
619 if (ret < 0) {
620 pm_runtime_put_noidle(&client->dev);
621 return ret;
622 }
623
541 /* 624 /*
542 * Write data to chip, protecting against concurrent updates 625 * Write data to chip, protecting against concurrent updates
543 * from this host, but not from other I2C masters. 626 * from this host, but not from other I2C masters.
@@ -550,6 +633,7 @@ static int at24_write(void *priv, unsigned int off, void *val, size_t count)
550 status = at24->write_func(at24, buf, off, count); 633 status = at24->write_func(at24, buf, off, count);
551 if (status < 0) { 634 if (status < 0) {
552 mutex_unlock(&at24->lock); 635 mutex_unlock(&at24->lock);
636 pm_runtime_put(&client->dev);
553 return status; 637 return status;
554 } 638 }
555 buf += status; 639 buf += status;
@@ -559,6 +643,8 @@ static int at24_write(void *priv, unsigned int off, void *val, size_t count)
559 643
560 mutex_unlock(&at24->lock); 644 mutex_unlock(&at24->lock);
561 645
646 pm_runtime_put(&client->dev);
647
562 return 0; 648 return 0;
563} 649}
564 650
@@ -570,6 +656,10 @@ static void at24_get_pdata(struct device *dev, struct at24_platform_data *chip)
570 if (device_property_present(dev, "read-only")) 656 if (device_property_present(dev, "read-only"))
571 chip->flags |= AT24_FLAG_READONLY; 657 chip->flags |= AT24_FLAG_READONLY;
572 658
659 err = device_property_read_u32(dev, "size", &val);
660 if (!err)
661 chip->byte_len = val;
662
573 err = device_property_read_u32(dev, "pagesize", &val); 663 err = device_property_read_u32(dev, "pagesize", &val);
574 if (!err) { 664 if (!err) {
575 chip->page_size = val; 665 chip->page_size = val;
@@ -598,7 +688,16 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
598 if (client->dev.platform_data) { 688 if (client->dev.platform_data) {
599 chip = *(struct at24_platform_data *)client->dev.platform_data; 689 chip = *(struct at24_platform_data *)client->dev.platform_data;
600 } else { 690 } else {
601 if (id) { 691 /*
692 * The I2C core allows OF nodes compatibles to match against the
693 * I2C device ID table as a fallback, so check not only if an OF
694 * node is present but also if it matches an OF device ID entry.
695 */
696 if (client->dev.of_node &&
697 of_match_device(at24_of_match, &client->dev)) {
698 magic = (kernel_ulong_t)
699 of_device_get_match_data(&client->dev);
700 } else if (id) {
602 magic = id->driver_data; 701 magic = id->driver_data;
603 } else { 702 } else {
604 const struct acpi_device_id *aid; 703 const struct acpi_device_id *aid;
@@ -739,11 +838,16 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
739 838
740 i2c_set_clientdata(client, at24); 839 i2c_set_clientdata(client, at24);
741 840
841 /* enable runtime pm */
842 pm_runtime_set_active(&client->dev);
843 pm_runtime_enable(&client->dev);
844
742 /* 845 /*
743 * Perform a one-byte test read to verify that the 846 * Perform a one-byte test read to verify that the
744 * chip is functional. 847 * chip is functional.
745 */ 848 */
746 err = at24_read(at24, 0, &test_byte, 1); 849 err = at24_read(at24, 0, &test_byte, 1);
850 pm_runtime_idle(&client->dev);
747 if (err) { 851 if (err) {
748 err = -ENODEV; 852 err = -ENODEV;
749 goto err_clients; 853 goto err_clients;
@@ -791,6 +895,8 @@ err_clients:
791 if (at24->client[i]) 895 if (at24->client[i])
792 i2c_unregister_device(at24->client[i]); 896 i2c_unregister_device(at24->client[i]);
793 897
898 pm_runtime_disable(&client->dev);
899
794 return err; 900 return err;
795} 901}
796 902
@@ -806,6 +912,9 @@ static int at24_remove(struct i2c_client *client)
806 for (i = 1; i < at24->num_addresses; i++) 912 for (i = 1; i < at24->num_addresses; i++)
807 i2c_unregister_device(at24->client[i]); 913 i2c_unregister_device(at24->client[i]);
808 914
915 pm_runtime_disable(&client->dev);
916 pm_runtime_set_suspended(&client->dev);
917
809 return 0; 918 return 0;
810} 919}
811 920
@@ -814,6 +923,7 @@ static int at24_remove(struct i2c_client *client)
814static struct i2c_driver at24_driver = { 923static struct i2c_driver at24_driver = {
815 .driver = { 924 .driver = {
816 .name = "at24", 925 .name = "at24",
926 .of_match_table = at24_of_match,
817 .acpi_match_table = ACPI_PTR(at24_acpi_ids), 927 .acpi_match_table = ACPI_PTR(at24_acpi_ids),
818 }, 928 },
819 .probe = at24_probe, 929 .probe = at24_probe,
diff --git a/drivers/power/supply/Kconfig b/drivers/power/supply/Kconfig
index 5ab90c1f3f7c..fbca0ba7fc52 100644
--- a/drivers/power/supply/Kconfig
+++ b/drivers/power/supply/Kconfig
@@ -184,6 +184,20 @@ config CHARGER_SBS
184 help 184 help
185 Say Y to include support for SBS compilant battery chargers. 185 Say Y to include support for SBS compilant battery chargers.
186 186
187config MANAGER_SBS
188 tristate "Smart Battery System Manager"
189 depends on I2C && I2C_MUX && GPIOLIB
190 select I2C_SMBUS
191 help
192 Say Y here to include support for Smart Battery System Manager
193 ICs. The driver reports online and charging status via sysfs.
194 It presents itself also as I2C mux which allows to bind
195 smart battery driver to its ports.
196 Supported is for example LTC1760.
197
198 This driver can also be built as a module. If so, the module will be
199 called sbs-manager.
200
187config BATTERY_BQ27XXX 201config BATTERY_BQ27XXX
188 tristate "BQ27xxx battery driver" 202 tristate "BQ27xxx battery driver"
189 help 203 help
diff --git a/drivers/power/supply/Makefile b/drivers/power/supply/Makefile
index aae4e4a8bbb3..e83aa843bcc6 100644
--- a/drivers/power/supply/Makefile
+++ b/drivers/power/supply/Makefile
@@ -37,6 +37,7 @@ obj-$(CONFIG_BATTERY_IPAQ_MICRO) += ipaq_micro_battery.o
37obj-$(CONFIG_BATTERY_WM97XX) += wm97xx_battery.o 37obj-$(CONFIG_BATTERY_WM97XX) += wm97xx_battery.o
38obj-$(CONFIG_BATTERY_SBS) += sbs-battery.o 38obj-$(CONFIG_BATTERY_SBS) += sbs-battery.o
39obj-$(CONFIG_CHARGER_SBS) += sbs-charger.o 39obj-$(CONFIG_CHARGER_SBS) += sbs-charger.o
40obj-$(CONFIG_MANAGER_SBS) += sbs-manager.o
40obj-$(CONFIG_BATTERY_BQ27XXX) += bq27xxx_battery.o 41obj-$(CONFIG_BATTERY_BQ27XXX) += bq27xxx_battery.o
41obj-$(CONFIG_BATTERY_BQ27XXX_I2C) += bq27xxx_battery_i2c.o 42obj-$(CONFIG_BATTERY_BQ27XXX_I2C) += bq27xxx_battery_i2c.o
42obj-$(CONFIG_BATTERY_BQ27XXX_HDQ) += bq27xxx_battery_hdq.o 43obj-$(CONFIG_BATTERY_BQ27XXX_HDQ) += bq27xxx_battery_hdq.o
diff --git a/drivers/power/supply/sbs-battery.c b/drivers/power/supply/sbs-battery.c
index b19a73176910..83d7b4115857 100644
--- a/drivers/power/supply/sbs-battery.c
+++ b/drivers/power/supply/sbs-battery.c
@@ -177,10 +177,8 @@ static bool force_load;
177static int sbs_read_word_data(struct i2c_client *client, u8 address) 177static int sbs_read_word_data(struct i2c_client *client, u8 address)
178{ 178{
179 struct sbs_info *chip = i2c_get_clientdata(client); 179 struct sbs_info *chip = i2c_get_clientdata(client);
180 int retries = chip->i2c_retry_count;
180 s32 ret = 0; 181 s32 ret = 0;
181 int retries = 1;
182
183 retries = chip->i2c_retry_count;
184 182
185 while (retries > 0) { 183 while (retries > 0) {
186 ret = i2c_smbus_read_word_data(client, address); 184 ret = i2c_smbus_read_word_data(client, address);
@@ -204,7 +202,7 @@ static int sbs_read_string_data(struct i2c_client *client, u8 address,
204{ 202{
205 struct sbs_info *chip = i2c_get_clientdata(client); 203 struct sbs_info *chip = i2c_get_clientdata(client);
206 s32 ret = 0, block_length = 0; 204 s32 ret = 0, block_length = 0;
207 int retries_length = 1, retries_block = 1; 205 int retries_length, retries_block;
208 u8 block_buffer[I2C_SMBUS_BLOCK_MAX + 1]; 206 u8 block_buffer[I2C_SMBUS_BLOCK_MAX + 1];
209 207
210 retries_length = chip->i2c_retry_count; 208 retries_length = chip->i2c_retry_count;
@@ -269,10 +267,8 @@ static int sbs_write_word_data(struct i2c_client *client, u8 address,
269 u16 value) 267 u16 value)
270{ 268{
271 struct sbs_info *chip = i2c_get_clientdata(client); 269 struct sbs_info *chip = i2c_get_clientdata(client);
270 int retries = chip->i2c_retry_count;
272 s32 ret = 0; 271 s32 ret = 0;
273 int retries = 1;
274
275 retries = chip->i2c_retry_count;
276 272
277 while (retries > 0) { 273 while (retries > 0) {
278 ret = i2c_smbus_write_word_data(client, address, value); 274 ret = i2c_smbus_write_word_data(client, address, value);
@@ -321,16 +317,6 @@ static int sbs_get_battery_presence_and_health(
321 union power_supply_propval *val) 317 union power_supply_propval *val)
322{ 318{
323 s32 ret; 319 s32 ret;
324 struct sbs_info *chip = i2c_get_clientdata(client);
325
326 if (psp == POWER_SUPPLY_PROP_PRESENT && chip->gpio_detect) {
327 ret = gpiod_get_value_cansleep(chip->gpio_detect);
328 if (ret < 0)
329 return ret;
330 val->intval = ret;
331 chip->is_present = val->intval;
332 return ret;
333 }
334 320
335 /* 321 /*
336 * Write to ManufacturerAccess with ManufacturerAccess command 322 * Write to ManufacturerAccess with ManufacturerAccess command
@@ -570,7 +556,7 @@ static int sbs_get_battery_serial_number(struct i2c_client *client,
570 if (ret < 0) 556 if (ret < 0)
571 return ret; 557 return ret;
572 558
573 ret = sprintf(sbs_serial, "%04x", ret); 559 sprintf(sbs_serial, "%04x", ret);
574 val->strval = sbs_serial; 560 val->strval = sbs_serial;
575 561
576 return 0; 562 return 0;
@@ -598,6 +584,19 @@ static int sbs_get_property(struct power_supply *psy,
598 struct sbs_info *chip = power_supply_get_drvdata(psy); 584 struct sbs_info *chip = power_supply_get_drvdata(psy);
599 struct i2c_client *client = chip->client; 585 struct i2c_client *client = chip->client;
600 586
587 if (chip->gpio_detect) {
588 ret = gpiod_get_value_cansleep(chip->gpio_detect);
589 if (ret < 0)
590 return ret;
591 if (psp == POWER_SUPPLY_PROP_PRESENT) {
592 val->intval = ret;
593 chip->is_present = val->intval;
594 return 0;
595 }
596 if (ret == 0)
597 return -ENODATA;
598 }
599
601 switch (psp) { 600 switch (psp) {
602 case POWER_SUPPLY_PROP_PRESENT: 601 case POWER_SUPPLY_PROP_PRESENT:
603 case POWER_SUPPLY_PROP_HEALTH: 602 case POWER_SUPPLY_PROP_HEALTH:
diff --git a/drivers/power/supply/sbs-manager.c b/drivers/power/supply/sbs-manager.c
new file mode 100644
index 000000000000..ccb4217b9638
--- /dev/null
+++ b/drivers/power/supply/sbs-manager.c
@@ -0,0 +1,445 @@
1/*
2 * Driver for SBS compliant Smart Battery System Managers
3 *
4 * The device communicates via i2c at address 0x0a and multiplexes access to up
5 * to four smart batteries at address 0x0b.
6 *
7 * Via sysfs interface the online state and charge type are presented.
8 *
9 * Datasheet SBSM: http://sbs-forum.org/specs/sbsm100b.pdf
10 * Datasheet LTC1760: http://cds.linear.com/docs/en/datasheet/1760fb.pdf
11 *
12 * Karl-Heinz Schneider <karl-heinz@schneider-inet.de>
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License version 2 as
16 * published by the Free Software Foundation.
17 */
18
19#include <linux/gpio.h>
20#include <linux/module.h>
21#include <linux/i2c.h>
22#include <linux/i2c-mux.h>
23#include <linux/power_supply.h>
24#include <linux/property.h>
25
26#define SBSM_MAX_BATS 4
27#define SBSM_RETRY_CNT 3
28
29/* registers addresses */
30#define SBSM_CMD_BATSYSSTATE 0x01
31#define SBSM_CMD_BATSYSSTATECONT 0x02
32#define SBSM_CMD_BATSYSINFO 0x04
33#define SBSM_CMD_LTC 0x3c
34
35#define SBSM_MASK_BAT_SUPPORTED GENMASK(3, 0)
36#define SBSM_MASK_CHARGE_BAT GENMASK(7, 4)
37#define SBSM_BIT_AC_PRESENT BIT(0)
38#define SBSM_BIT_TURBO BIT(7)
39
40#define SBSM_SMB_BAT_OFFSET 11
41struct sbsm_data {
42 struct i2c_client *client;
43 struct i2c_mux_core *muxc;
44
45 struct power_supply *psy;
46
47 u8 cur_chan; /* currently selected channel */
48 struct gpio_chip chip;
49 bool is_ltc1760; /* special capabilities */
50
51 unsigned int supported_bats;
52 unsigned int last_state;
53 unsigned int last_state_cont;
54};
55
56static enum power_supply_property sbsm_props[] = {
57 POWER_SUPPLY_PROP_ONLINE,
58 POWER_SUPPLY_PROP_CHARGE_TYPE,
59};
60
61static int sbsm_read_word(struct i2c_client *client, u8 address)
62{
63 int reg, retries;
64
65 for (retries = SBSM_RETRY_CNT; retries > 0; retries--) {
66 reg = i2c_smbus_read_word_data(client, address);
67 if (reg >= 0)
68 break;
69 }
70
71 if (reg < 0) {
72 dev_err(&client->dev, "failed to read register 0x%02x\n",
73 address);
74 }
75
76 return reg;
77}
78
79static int sbsm_write_word(struct i2c_client *client, u8 address, u16 word)
80{
81 int ret, retries;
82
83 for (retries = SBSM_RETRY_CNT; retries > 0; retries--) {
84 ret = i2c_smbus_write_word_data(client, address, word);
85 if (ret >= 0)
86 break;
87 }
88 if (ret < 0)
89 dev_err(&client->dev, "failed to write to register 0x%02x\n",
90 address);
91
92 return ret;
93}
94
95static int sbsm_get_property(struct power_supply *psy,
96 enum power_supply_property psp,
97 union power_supply_propval *val)
98{
99 struct sbsm_data *data = power_supply_get_drvdata(psy);
100 int regval = 0;
101
102 switch (psp) {
103 case POWER_SUPPLY_PROP_ONLINE:
104 regval = sbsm_read_word(data->client, SBSM_CMD_BATSYSSTATECONT);
105 if (regval < 0)
106 return regval;
107 val->intval = !!(regval & SBSM_BIT_AC_PRESENT);
108 break;
109
110 case POWER_SUPPLY_PROP_CHARGE_TYPE:
111 regval = sbsm_read_word(data->client, SBSM_CMD_BATSYSSTATE);
112 if (regval < 0)
113 return regval;
114
115 if ((regval & SBSM_MASK_CHARGE_BAT) == 0) {
116 val->intval = POWER_SUPPLY_CHARGE_TYPE_NONE;
117 return 0;
118 }
119 val->intval = POWER_SUPPLY_CHARGE_TYPE_TRICKLE;
120
121 if (data->is_ltc1760) {
122 /* charge mode fast if turbo is active */
123 regval = sbsm_read_word(data->client, SBSM_CMD_LTC);
124 if (regval < 0)
125 return regval;
126 else if (regval & SBSM_BIT_TURBO)
127 val->intval = POWER_SUPPLY_CHARGE_TYPE_FAST;
128 }
129 break;
130
131 default:
132 return -EINVAL;
133 }
134
135 return 0;
136}
137
138static int sbsm_prop_is_writeable(struct power_supply *psy,
139 enum power_supply_property psp)
140{
141 struct sbsm_data *data = power_supply_get_drvdata(psy);
142
143 return (psp == POWER_SUPPLY_PROP_CHARGE_TYPE) && data->is_ltc1760;
144}
145
146static int sbsm_set_property(struct power_supply *psy,
147 enum power_supply_property psp,
148 const union power_supply_propval *val)
149{
150 struct sbsm_data *data = power_supply_get_drvdata(psy);
151 int ret = -EINVAL;
152 u16 regval;
153
154 switch (psp) {
155 case POWER_SUPPLY_PROP_CHARGE_TYPE:
156 /* write 1 to TURBO if type fast is given */
157 if (!data->is_ltc1760)
158 break;
159 regval = val->intval ==
160 POWER_SUPPLY_CHARGE_TYPE_FAST ? SBSM_BIT_TURBO : 0;
161 ret = sbsm_write_word(data->client, SBSM_CMD_LTC, regval);
162 break;
163
164 default:
165 break;
166 }
167
168 return ret;
169}
170
171/*
172 * Switch to battery
173 * Parameter chan is directly the content of SMB_BAT* nibble
174 */
175static int sbsm_select(struct i2c_mux_core *muxc, u32 chan)
176{
177 struct sbsm_data *data = i2c_mux_priv(muxc);
178 struct device *dev = &data->client->dev;
179 int ret = 0;
180 u16 reg;
181
182 if (data->cur_chan == chan)
183 return ret;
184
185 /* chan goes from 1 ... 4 */
186 reg = 1 << BIT(SBSM_SMB_BAT_OFFSET + chan);
187 ret = sbsm_write_word(data->client, SBSM_CMD_BATSYSSTATE, reg);
188 if (ret)
189 dev_err(dev, "Failed to select channel %i\n", chan);
190 else
191 data->cur_chan = chan;
192
193 return ret;
194}
195
196static int sbsm_gpio_get_value(struct gpio_chip *gc, unsigned int off)
197{
198 struct sbsm_data *data = gpiochip_get_data(gc);
199 int ret;
200
201 ret = sbsm_read_word(data->client, SBSM_CMD_BATSYSSTATE);
202 if (ret < 0)
203 return ret;
204
205 return ret & BIT(off);
206}
207
208/*
209 * This needs to be defined or the GPIO lib fails to register the pin.
210 * But the 'gpio' is always an input.
211 */
212static int sbsm_gpio_direction_input(struct gpio_chip *gc, unsigned int off)
213{
214 return 0;
215}
216
217static int sbsm_do_alert(struct device *dev, void *d)
218{
219 struct i2c_client *client = i2c_verify_client(dev);
220 struct i2c_driver *driver;
221
222 if (!client || client->addr != 0x0b)
223 return 0;
224
225 device_lock(dev);
226 if (client->dev.driver) {
227 driver = to_i2c_driver(client->dev.driver);
228 if (driver->alert)
229 driver->alert(client, I2C_PROTOCOL_SMBUS_ALERT, 0);
230 else
231 dev_warn(&client->dev, "no driver alert()!\n");
232 } else {
233 dev_dbg(&client->dev, "alert with no driver\n");
234 }
235 device_unlock(dev);
236
237 return -EBUSY;
238}
239
240static void sbsm_alert(struct i2c_client *client, enum i2c_alert_protocol prot,
241 unsigned int d)
242{
243 struct sbsm_data *sbsm = i2c_get_clientdata(client);
244
245 int ret, i, irq_bat = 0, state = 0;
246
247 ret = sbsm_read_word(sbsm->client, SBSM_CMD_BATSYSSTATE);
248 if (ret >= 0) {
249 irq_bat = ret ^ sbsm->last_state;
250 sbsm->last_state = ret;
251 state = ret;
252 }
253
254 ret = sbsm_read_word(sbsm->client, SBSM_CMD_BATSYSSTATECONT);
255 if ((ret >= 0) &&
256 ((ret ^ sbsm->last_state_cont) & SBSM_BIT_AC_PRESENT)) {
257 irq_bat |= sbsm->supported_bats & state;
258 power_supply_changed(sbsm->psy);
259 }
260 sbsm->last_state_cont = ret;
261
262 for (i = 0; i < SBSM_MAX_BATS; i++) {
263 if (irq_bat & BIT(i)) {
264 device_for_each_child(&sbsm->muxc->adapter[i]->dev,
265 NULL, sbsm_do_alert);
266 }
267 }
268}
269
270static int sbsm_gpio_setup(struct sbsm_data *data)
271{
272 struct gpio_chip *gc = &data->chip;
273 struct i2c_client *client = data->client;
274 struct device *dev = &client->dev;
275 int ret;
276
277 if (!device_property_present(dev, "gpio-controller"))
278 return 0;
279
280 ret = sbsm_read_word(client, SBSM_CMD_BATSYSSTATE);
281 if (ret < 0)
282 return ret;
283 data->last_state = ret;
284
285 ret = sbsm_read_word(client, SBSM_CMD_BATSYSSTATECONT);
286 if (ret < 0)
287 return ret;
288 data->last_state_cont = ret;
289
290 gc->get = sbsm_gpio_get_value;
291 gc->direction_input = sbsm_gpio_direction_input;
292 gc->can_sleep = true;
293 gc->base = -1;
294 gc->ngpio = SBSM_MAX_BATS;
295 gc->label = client->name;
296 gc->parent = dev;
297 gc->owner = THIS_MODULE;
298
299 ret = devm_gpiochip_add_data(dev, gc, data);
300 if (ret) {
301 dev_err(dev, "devm_gpiochip_add_data failed: %d\n", ret);
302 return ret;
303 }
304
305 return ret;
306}
307
308static const struct power_supply_desc sbsm_default_psy_desc = {
309 .type = POWER_SUPPLY_TYPE_MAINS,
310 .properties = sbsm_props,
311 .num_properties = ARRAY_SIZE(sbsm_props),
312 .get_property = &sbsm_get_property,
313 .set_property = &sbsm_set_property,
314 .property_is_writeable = &sbsm_prop_is_writeable,
315};
316
317static int sbsm_probe(struct i2c_client *client,
318 const struct i2c_device_id *id)
319{
320 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
321 struct sbsm_data *data;
322 struct device *dev = &client->dev;
323 struct power_supply_desc *psy_desc;
324 struct power_supply_config psy_cfg = {};
325 int ret = 0, i;
326
327 /* Device listens only at address 0x0a */
328 if (client->addr != 0x0a)
329 return -EINVAL;
330
331 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA))
332 return -EPFNOSUPPORT;
333
334 data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
335 if (!data)
336 return -ENOMEM;
337
338 i2c_set_clientdata(client, data);
339
340 data->client = client;
341 data->is_ltc1760 = !!strstr(id->name, "ltc1760");
342
343 ret = sbsm_read_word(client, SBSM_CMD_BATSYSINFO);
344 if (ret < 0)
345 return ret;
346 data->supported_bats = ret & SBSM_MASK_BAT_SUPPORTED;
347 data->muxc = i2c_mux_alloc(adapter, dev, SBSM_MAX_BATS, 0,
348 I2C_MUX_LOCKED, &sbsm_select, NULL);
349 if (!data->muxc) {
350 dev_err(dev, "failed to alloc i2c mux\n");
351 ret = -ENOMEM;
352 goto err_mux_alloc;
353 }
354 data->muxc->priv = data;
355
356 /* register muxed i2c channels. One for each supported battery */
357 for (i = 0; i < SBSM_MAX_BATS; ++i) {
358 if (data->supported_bats & BIT(i)) {
359 ret = i2c_mux_add_adapter(data->muxc, 0, i + 1, 0);
360 if (ret)
361 break;
362 }
363 }
364 if (ret) {
365 dev_err(dev, "failed to register i2c mux channel %d\n", i + 1);
366 goto err_mux_register;
367 }
368
369 psy_desc = devm_kmemdup(dev, &sbsm_default_psy_desc,
370 sizeof(struct power_supply_desc),
371 GFP_KERNEL);
372 if (!psy_desc) {
373 ret = -ENOMEM;
374 goto err_psy;
375 }
376
377 psy_desc->name = devm_kasprintf(dev, GFP_KERNEL, "sbsm-%s",
378 dev_name(&client->dev));
379 if (!psy_desc->name) {
380 ret = -ENOMEM;
381 goto err_psy;
382 }
383 ret = sbsm_gpio_setup(data);
384 if (ret < 0)
385 goto err_psy;
386
387 psy_cfg.drv_data = data;
388 psy_cfg.of_node = dev->of_node;
389 data->psy = devm_power_supply_register(dev, psy_desc, &psy_cfg);
390 if (IS_ERR(data->psy)) {
391 ret = PTR_ERR(data->psy);
392 dev_err(dev, "failed to register power supply %s\n",
393 psy_desc->name);
394 goto err_psy;
395 }
396
397 return 0;
398
399err_psy:
400err_mux_register:
401 i2c_mux_del_adapters(data->muxc);
402
403err_mux_alloc:
404 return ret;
405}
406
407static int sbsm_remove(struct i2c_client *client)
408{
409 struct sbsm_data *data = i2c_get_clientdata(client);
410
411 i2c_mux_del_adapters(data->muxc);
412 return 0;
413}
414
415static const struct i2c_device_id sbsm_ids[] = {
416 { "sbs-manager", 0 },
417 { "ltc1760", 0 },
418 { }
419};
420MODULE_DEVICE_TABLE(i2c, sbsm_ids);
421
422#ifdef CONFIG_OF
423static const struct of_device_id sbsm_dt_ids[] = {
424 { .compatible = "sbs,sbs-manager" },
425 { .compatible = "lltc,ltc1760" },
426 { }
427};
428MODULE_DEVICE_TABLE(of, sbsm_dt_ids);
429#endif
430
431static struct i2c_driver sbsm_driver = {
432 .driver = {
433 .name = "sbsm",
434 .of_match_table = of_match_ptr(sbsm_dt_ids),
435 },
436 .probe = sbsm_probe,
437 .remove = sbsm_remove,
438 .alert = sbsm_alert,
439 .id_table = sbsm_ids
440};
441module_i2c_driver(sbsm_driver);
442
443MODULE_LICENSE("GPL");
444MODULE_AUTHOR("Karl-Heinz Schneider <karl-heinz@schneider-inet.de>");
445MODULE_DESCRIPTION("SBSM Smart Battery System Manager");
diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h
index 6d236656aaef..7447d85dbe2f 100644
--- a/include/linux/gpio/consumer.h
+++ b/include/linux/gpio/consumer.h
@@ -29,6 +29,7 @@ struct gpio_descs {
29#define GPIOD_FLAGS_BIT_DIR_SET BIT(0) 29#define GPIOD_FLAGS_BIT_DIR_SET BIT(0)
30#define GPIOD_FLAGS_BIT_DIR_OUT BIT(1) 30#define GPIOD_FLAGS_BIT_DIR_OUT BIT(1)
31#define GPIOD_FLAGS_BIT_DIR_VAL BIT(2) 31#define GPIOD_FLAGS_BIT_DIR_VAL BIT(2)
32#define GPIOD_FLAGS_BIT_OPEN_DRAIN BIT(3)
32 33
33/** 34/**
34 * Optional flags that can be passed to one of gpiod_* to configure direction 35 * Optional flags that can be passed to one of gpiod_* to configure direction
@@ -40,6 +41,11 @@ enum gpiod_flags {
40 GPIOD_OUT_LOW = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT, 41 GPIOD_OUT_LOW = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT,
41 GPIOD_OUT_HIGH = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT | 42 GPIOD_OUT_HIGH = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT |
42 GPIOD_FLAGS_BIT_DIR_VAL, 43 GPIOD_FLAGS_BIT_DIR_VAL,
44 GPIOD_OUT_LOW_OPEN_DRAIN = GPIOD_FLAGS_BIT_DIR_SET |
45 GPIOD_FLAGS_BIT_DIR_OUT | GPIOD_FLAGS_BIT_OPEN_DRAIN,
46 GPIOD_OUT_HIGH_OPEN_DRAIN = GPIOD_FLAGS_BIT_DIR_SET |
47 GPIOD_FLAGS_BIT_DIR_OUT | GPIOD_FLAGS_BIT_DIR_VAL |
48 GPIOD_FLAGS_BIT_OPEN_DRAIN,
43}; 49};
44 50
45#ifdef CONFIG_GPIOLIB 51#ifdef CONFIG_GPIOLIB
diff --git a/include/linux/i2c-gpio.h b/include/linux/i2c-gpio.h
index c1bcb1f1d73b..352c1426fd4d 100644
--- a/include/linux/i2c-gpio.h
+++ b/include/linux/i2c-gpio.h
@@ -12,8 +12,6 @@
12 12
13/** 13/**
14 * struct i2c_gpio_platform_data - Platform-dependent data for i2c-gpio 14 * struct i2c_gpio_platform_data - Platform-dependent data for i2c-gpio
15 * @sda_pin: GPIO pin ID to use for SDA
16 * @scl_pin: GPIO pin ID to use for SCL
17 * @udelay: signal toggle delay. SCL frequency is (500 / udelay) kHz 15 * @udelay: signal toggle delay. SCL frequency is (500 / udelay) kHz
18 * @timeout: clock stretching timeout in jiffies. If the slave keeps 16 * @timeout: clock stretching timeout in jiffies. If the slave keeps
19 * SCL low for longer than this, the transfer will time out. 17 * SCL low for longer than this, the transfer will time out.
@@ -26,8 +24,6 @@
26 * @scl_is_output_only: SCL output drivers cannot be turned off. 24 * @scl_is_output_only: SCL output drivers cannot be turned off.
27 */ 25 */
28struct i2c_gpio_platform_data { 26struct i2c_gpio_platform_data {
29 unsigned int sda_pin;
30 unsigned int scl_pin;
31 int udelay; 27 int udelay;
32 int timeout; 28 int timeout;
33 unsigned int sda_is_open_drain:1; 29 unsigned int sda_is_open_drain:1;
diff --git a/include/linux/i2c-smbus.h b/include/linux/i2c-smbus.h
index a1385023a29b..fb0e040b1abb 100644
--- a/include/linux/i2c-smbus.h
+++ b/include/linux/i2c-smbus.h
@@ -42,7 +42,6 @@
42 * properly set. 42 * properly set.
43 */ 43 */
44struct i2c_smbus_alert_setup { 44struct i2c_smbus_alert_setup {
45 unsigned int alert_edge_triggered:1;
46 int irq; 45 int irq;
47}; 46};
48 47
@@ -50,4 +49,13 @@ struct i2c_client *i2c_setup_smbus_alert(struct i2c_adapter *adapter,
50 struct i2c_smbus_alert_setup *setup); 49 struct i2c_smbus_alert_setup *setup);
51int i2c_handle_smbus_alert(struct i2c_client *ara); 50int i2c_handle_smbus_alert(struct i2c_client *ara);
52 51
52#if IS_ENABLED(CONFIG_I2C_SMBUS) && IS_ENABLED(CONFIG_OF)
53int of_i2c_setup_smbus_alert(struct i2c_adapter *adap);
54#else
55static inline int of_i2c_setup_smbus_alert(struct i2c_adapter *adap)
56{
57 return 0;
58}
59#endif
60
53#endif /* _LINUX_I2C_SMBUS_H */ 61#endif /* _LINUX_I2C_SMBUS_H */
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index d501d3956f13..0f774406fad0 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -304,6 +304,7 @@ static inline bool i2c_detect_slave_mode(struct device *dev) { return false; }
304 * @type: chip type, to initialize i2c_client.name 304 * @type: chip type, to initialize i2c_client.name
305 * @flags: to initialize i2c_client.flags 305 * @flags: to initialize i2c_client.flags
306 * @addr: stored in i2c_client.addr 306 * @addr: stored in i2c_client.addr
307 * @dev_name: Overrides the default <busnr>-<addr> dev_name if set
307 * @platform_data: stored in i2c_client.dev.platform_data 308 * @platform_data: stored in i2c_client.dev.platform_data
308 * @archdata: copied into i2c_client.dev.archdata 309 * @archdata: copied into i2c_client.dev.archdata
309 * @of_node: pointer to OpenFirmware device node 310 * @of_node: pointer to OpenFirmware device node
@@ -328,6 +329,7 @@ struct i2c_board_info {
328 char type[I2C_NAME_SIZE]; 329 char type[I2C_NAME_SIZE];
329 unsigned short flags; 330 unsigned short flags;
330 unsigned short addr; 331 unsigned short addr;
332 const char *dev_name;
331 void *platform_data; 333 void *platform_data;
332 struct dev_archdata *archdata; 334 struct dev_archdata *archdata;
333 struct device_node *of_node; 335 struct device_node *of_node;
diff --git a/include/linux/platform_data/i2c-nuc900.h b/include/linux/platform_data/i2c-nuc900.h
deleted file mode 100644
index 23036273a97e..000000000000
--- a/include/linux/platform_data/i2c-nuc900.h
+++ /dev/null
@@ -1,10 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef __ASM_ARCH_NUC900_I2C_H
3#define __ASM_ARCH_NUC900_I2C_H
4
5struct nuc900_platform_i2c {
6 int bus_num;
7 unsigned long bus_freq;
8};
9
10#endif /* __ASM_ARCH_NUC900_I2C_H */