aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2017-05-03 15:18:47 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2017-05-03 15:18:47 -0400
commit14b730723aac9cf3ba0a74e830491e9a43bfc80a (patch)
tree2d1591012ce62103a8c9fa0ebc4d002408f4d47f
parentd26f552ebbfb0f2c7fe712f457a038d60ed73daa (diff)
parent889ef45cd4b64cc4fd6dbebecddb8ea4df8cc1e7 (diff)
Merge branch 'i2c/for-4.12' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux
Pull i2c updates from Wilfram Sang: "I2C has the following updates for you: - an immutable cross-subsystem branch fixing PMIC access on Intel Baytrail - bigger driver updates to the designware, meson, exynos5 drivers - new i2c_acpi_new_device() function to create devices from ACPI - struct i2c_driver has now a flag 'disable_i2c_core_irq_mapping' to allow custom IRQ mapping in case the default does not fit - mux subsystem centralized error messages in its core - new driver for ltc4306 i2c mux - usual set of small updates" * 'i2c/for-4.12' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux: (44 commits) i2c: thunderx: Enable HWMON class probing i2c: rcar: clarify PM handling with more comments i2c: rcar: fix resume by always initializing registers before transfer i2c: tegra: fix spelling mistake: "contoller" -> "controller" i2c: exynos5: use core helper to get driver data i2c: exynos5: de-duplicate error logs on clock setup i2c: exynos5: simplify clock frequency handling i2c: exynos5: simplify timings calculation i2c: designware-baytrail: fix potential null pointer dereference on dev i2c: designware: Get selected speed mode sda-hold-time via ACPI [media] cx231xx: stop double error reporting i2c: core: Allow drivers to disable i2c-core irq mapping i2c: core: Add new i2c_acpi_new_device helper function i2c: core: Allow getting ACPI info by index i2c: img-scb: use setup_timer i2c: i2c-scmi: add a MS HID i2c: mux: ltc4306: LTC4306 and LTC4305 I2C multiplexer/switch dt-bindings: i2c: mux: ltc4306: Add dt-bindings for I2C multiplexer/switch i2c: mux: reg: stop double error reporting i2c: mux: pinctrl: stop double error reporting ...
-rw-r--r--Documentation/devicetree/bindings/i2c/i2c-meson.txt2
-rw-r--r--Documentation/devicetree/bindings/i2c/i2c-mux-ltc4306.txt61
-rw-r--r--Documentation/devicetree/bindings/i2c/i2c-rk3x.txt1
-rw-r--r--MAINTAINERS8
-rw-r--r--drivers/i2c/busses/Kconfig3
-rw-r--r--drivers/i2c/busses/i2c-designware-baytrail.c8
-rw-r--r--drivers/i2c/busses/i2c-designware-core.c11
-rw-r--r--drivers/i2c/busses/i2c-designware-core.h4
-rw-r--r--drivers/i2c/busses/i2c-designware-platdrv.c56
-rw-r--r--drivers/i2c/busses/i2c-exynos5.c116
-rw-r--r--drivers/i2c/busses/i2c-img-scb.c5
-rw-r--r--drivers/i2c/busses/i2c-meson.c134
-rw-r--r--drivers/i2c/busses/i2c-mv64xxx.c15
-rw-r--r--drivers/i2c/busses/i2c-rcar.c8
-rw-r--r--drivers/i2c/busses/i2c-scmi.c4
-rw-r--r--drivers/i2c/busses/i2c-tegra-bpmp.c2
-rw-r--r--drivers/i2c/busses/i2c-thunderx-pcidrv.c25
-rw-r--r--drivers/i2c/busses/i2c-xlp9xx.c1
-rw-r--r--drivers/i2c/i2c-core.c62
-rw-r--r--drivers/i2c/i2c-mux.c9
-rw-r--r--drivers/i2c/muxes/Kconfig11
-rw-r--r--drivers/i2c/muxes/Makefile1
-rw-r--r--drivers/i2c/muxes/i2c-arb-gpio-challenge.c4
-rw-r--r--drivers/i2c/muxes/i2c-mux-gpio.c4
-rw-r--r--drivers/i2c/muxes/i2c-mux-ltc4306.c322
-rw-r--r--drivers/i2c/muxes/i2c-mux-pca9541.c4
-rw-r--r--drivers/i2c/muxes/i2c-mux-pca954x.c19
-rw-r--r--drivers/i2c/muxes/i2c-mux-pinctrl.c4
-rw-r--r--drivers/i2c/muxes/i2c-mux-reg.c4
-rw-r--r--drivers/media/usb/cx231xx/cx231xx-i2c.c15
-rw-r--r--include/linux/i2c.h10
31 files changed, 674 insertions, 259 deletions
diff --git a/Documentation/devicetree/bindings/i2c/i2c-meson.txt b/Documentation/devicetree/bindings/i2c/i2c-meson.txt
index 386357d1aab0..611b934c7e10 100644
--- a/Documentation/devicetree/bindings/i2c/i2c-meson.txt
+++ b/Documentation/devicetree/bindings/i2c/i2c-meson.txt
@@ -8,6 +8,8 @@ Required properties:
8 - #address-cells: should be <1> 8 - #address-cells: should be <1>
9 - #size-cells: should be <0> 9 - #size-cells: should be <0>
10 10
11For details regarding the following core I2C bindings see also i2c.txt.
12
11Optional properties: 13Optional properties:
12- clock-frequency: the desired I2C bus clock frequency in Hz; in 14- clock-frequency: the desired I2C bus clock frequency in Hz; in
13 absence of this property the default value is used (100 kHz). 15 absence of this property the default value is used (100 kHz).
diff --git a/Documentation/devicetree/bindings/i2c/i2c-mux-ltc4306.txt b/Documentation/devicetree/bindings/i2c/i2c-mux-ltc4306.txt
new file mode 100644
index 000000000000..1e98c6b3a721
--- /dev/null
+++ b/Documentation/devicetree/bindings/i2c/i2c-mux-ltc4306.txt
@@ -0,0 +1,61 @@
1* Linear Technology / Analog Devices I2C bus switch
2
3Required Properties:
4
5 - compatible: Must contain one of the following.
6 "lltc,ltc4305", "lltc,ltc4306"
7 - reg: The I2C address of the device.
8
9 The following required properties are defined externally:
10
11 - Standard I2C mux properties. See i2c-mux.txt in this directory.
12 - I2C child bus nodes. See i2c-mux.txt in this directory.
13
14Optional Properties:
15
16 - enable-gpios: Reference to the GPIO connected to the enable input.
17 - i2c-mux-idle-disconnect: Boolean; if defined, forces mux to disconnect all
18 children in idle state. This is necessary for example, if there are several
19 multiplexers on the bus and the devices behind them use same I2C addresses.
20 - gpio-controller: Marks the device node as a GPIO Controller.
21 - #gpio-cells: Should be two. The first cell is the pin number and
22 the second cell is used to specify flags.
23 See ../gpio/gpio.txt for more information.
24 - ltc,downstream-accelerators-enable: Enables the rise time accelerators
25 on the downstream port.
26 - ltc,upstream-accelerators-enable: Enables the rise time accelerators
27 on the upstream port.
28
29Example:
30
31 ltc4306: i2c-mux@4a {
32 compatible = "lltc,ltc4306";
33 #address-cells = <1>;
34 #size-cells = <0>;
35 reg = <0x4a>;
36
37 gpio-controller;
38 #gpio-cells = <2>;
39
40 i2c@0 {
41 #address-cells = <1>;
42 #size-cells = <0>;
43 reg = <0>;
44
45 eeprom@50 {
46 compatible = "at,24c02";
47 reg = <0x50>;
48 };
49 };
50
51 i2c@1 {
52 #address-cells = <1>;
53 #size-cells = <0>;
54 reg = <1>;
55
56 eeprom@50 {
57 compatible = "at,24c02";
58 reg = <0x50>;
59 };
60 };
61 };
diff --git a/Documentation/devicetree/bindings/i2c/i2c-rk3x.txt b/Documentation/devicetree/bindings/i2c/i2c-rk3x.txt
index bbc5a1ed5fa1..e18445d0980c 100644
--- a/Documentation/devicetree/bindings/i2c/i2c-rk3x.txt
+++ b/Documentation/devicetree/bindings/i2c/i2c-rk3x.txt
@@ -11,6 +11,7 @@ Required properties :
11 - "rockchip,rk3188-i2c": for rk3188 11 - "rockchip,rk3188-i2c": for rk3188
12 - "rockchip,rk3228-i2c": for rk3228 12 - "rockchip,rk3228-i2c": for rk3228
13 - "rockchip,rk3288-i2c": for rk3288 13 - "rockchip,rk3288-i2c": for rk3288
14 - "rockchip,rk3328-i2c", "rockchip,rk3399-i2c": for rk3328
14 - "rockchip,rk3399-i2c": for rk3399 15 - "rockchip,rk3399-i2c": for rk3399
15 - interrupts : interrupt number 16 - interrupts : interrupt number
16 - clocks: See ../clock/clock-bindings.txt 17 - clocks: See ../clock/clock-bindings.txt
diff --git a/MAINTAINERS b/MAINTAINERS
index 7046de618fdd..95803b7b61be 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -7775,6 +7775,14 @@ S: Maintained
7775F: Documentation/hwmon/ltc4261 7775F: Documentation/hwmon/ltc4261
7776F: drivers/hwmon/ltc4261.c 7776F: drivers/hwmon/ltc4261.c
7777 7777
7778LTC4306 I2C MULTIPLEXER DRIVER
7779M: Michael Hennerich <michael.hennerich@analog.com>
7780W: http://ez.analog.com/community/linux-device-drivers
7781L: linux-i2c@vger.kernel.org
7782S: Supported
7783F: drivers/i2c/muxes/i2c-mux-ltc4306.c
7784F: Documentation/devicetree/bindings/i2c/i2c-mux-ltc4306.txt
7785
7778LTP (Linux Test Project) 7786LTP (Linux Test Project)
7779M: Mike Frysinger <vapier@gentoo.org> 7787M: Mike Frysinger <vapier@gentoo.org>
7780M: Cyril Hrubis <chrubis@suse.cz> 7788M: Cyril Hrubis <chrubis@suse.cz>
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index 8adc0f1d7ad0..144cbadc7c72 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -933,6 +933,7 @@ config I2C_TEGRA
933config I2C_TEGRA_BPMP 933config I2C_TEGRA_BPMP
934 tristate "NVIDIA Tegra BPMP I2C controller" 934 tristate "NVIDIA Tegra BPMP I2C controller"
935 depends on TEGRA_BPMP 935 depends on TEGRA_BPMP
936 default y
936 help 937 help
937 If you say yes to this option, support will be included for the I2C 938 If you say yes to this option, support will be included for the I2C
938 controller embedded in NVIDIA Tegra SoCs accessed via the BPMP. 939 controller embedded in NVIDIA Tegra SoCs accessed via the BPMP.
@@ -1021,7 +1022,7 @@ config I2C_XLR
1021 1022
1022config I2C_XLP9XX 1023config I2C_XLP9XX
1023 tristate "XLP9XX I2C support" 1024 tristate "XLP9XX I2C support"
1024 depends on CPU_XLP || ARCH_VULCAN || COMPILE_TEST 1025 depends on CPU_XLP || ARCH_THUNDER2 || COMPILE_TEST
1025 help 1026 help
1026 This driver enables support for the on-chip I2C interface of 1027 This driver enables support for the on-chip I2C interface of
1027 the Broadcom XLP9xx/XLP5xx MIPS and Vulcan ARM64 processors. 1028 the Broadcom XLP9xx/XLP5xx MIPS and Vulcan ARM64 processors.
diff --git a/drivers/i2c/busses/i2c-designware-baytrail.c b/drivers/i2c/busses/i2c-designware-baytrail.c
index 1749a0f5a9fa..dbda8c9c8a1c 100644
--- a/drivers/i2c/busses/i2c-designware-baytrail.c
+++ b/drivers/i2c/busses/i2c-designware-baytrail.c
@@ -22,7 +22,7 @@
22 22
23#include "i2c-designware-core.h" 23#include "i2c-designware-core.h"
24 24
25#define SEMAPHORE_TIMEOUT 100 25#define SEMAPHORE_TIMEOUT 500
26#define PUNIT_SEMAPHORE 0x7 26#define PUNIT_SEMAPHORE 0x7
27#define PUNIT_SEMAPHORE_CHT 0x10e 27#define PUNIT_SEMAPHORE_CHT 0x10e
28#define PUNIT_SEMAPHORE_BIT BIT(0) 28#define PUNIT_SEMAPHORE_BIT BIT(0)
@@ -70,7 +70,7 @@ static void reset_semaphore(struct dw_i2c_dev *dev)
70 70
71static int baytrail_i2c_acquire(struct dw_i2c_dev *dev) 71static int baytrail_i2c_acquire(struct dw_i2c_dev *dev)
72{ 72{
73 u32 addr = get_sem_addr(dev); 73 u32 addr;
74 u32 sem = PUNIT_SEMAPHORE_ACQUIRE; 74 u32 sem = PUNIT_SEMAPHORE_ACQUIRE;
75 int ret; 75 int ret;
76 unsigned long start, end; 76 unsigned long start, end;
@@ -94,6 +94,8 @@ static int baytrail_i2c_acquire(struct dw_i2c_dev *dev)
94 */ 94 */
95 pm_qos_update_request(&dev->pm_qos, 0); 95 pm_qos_update_request(&dev->pm_qos, 0);
96 96
97 addr = get_sem_addr(dev);
98
97 /* host driver writes to side band semaphore register */ 99 /* host driver writes to side band semaphore register */
98 ret = iosf_mbi_write(BT_MBI_UNIT_PMC, MBI_REG_WRITE, addr, sem); 100 ret = iosf_mbi_write(BT_MBI_UNIT_PMC, MBI_REG_WRITE, addr, sem);
99 if (ret) { 101 if (ret) {
@@ -170,7 +172,7 @@ int i2c_dw_probe_lock_support(struct dw_i2c_dev *dev)
170 dev_info(dev->dev, "I2C bus managed by PUNIT\n"); 172 dev_info(dev->dev, "I2C bus managed by PUNIT\n");
171 dev->acquire_lock = baytrail_i2c_acquire; 173 dev->acquire_lock = baytrail_i2c_acquire;
172 dev->release_lock = baytrail_i2c_release; 174 dev->release_lock = baytrail_i2c_release;
173 dev->pm_runtime_disabled = true; 175 dev->pm_disabled = true;
174 176
175 pm_qos_add_request(&dev->pm_qos, PM_QOS_CPU_DMA_LATENCY, 177 pm_qos_add_request(&dev->pm_qos, PM_QOS_CPU_DMA_LATENCY,
176 PM_QOS_DEFAULT_VALUE); 178 PM_QOS_DEFAULT_VALUE);
diff --git a/drivers/i2c/busses/i2c-designware-core.c b/drivers/i2c/busses/i2c-designware-core.c
index 15a534818d4f..c453717b753b 100644
--- a/drivers/i2c/busses/i2c-designware-core.c
+++ b/drivers/i2c/busses/i2c-designware-core.c
@@ -960,6 +960,7 @@ EXPORT_SYMBOL_GPL(i2c_dw_read_comp_param);
960int i2c_dw_probe(struct dw_i2c_dev *dev) 960int i2c_dw_probe(struct dw_i2c_dev *dev)
961{ 961{
962 struct i2c_adapter *adap = &dev->adapter; 962 struct i2c_adapter *adap = &dev->adapter;
963 unsigned long irq_flags;
963 int r; 964 int r;
964 965
965 init_completion(&dev->cmd_complete); 966 init_completion(&dev->cmd_complete);
@@ -975,9 +976,15 @@ int i2c_dw_probe(struct dw_i2c_dev *dev)
975 adap->dev.parent = dev->dev; 976 adap->dev.parent = dev->dev;
976 i2c_set_adapdata(adap, dev); 977 i2c_set_adapdata(adap, dev);
977 978
979 if (dev->pm_disabled) {
980 dev_pm_syscore_device(dev->dev, true);
981 irq_flags = IRQF_NO_SUSPEND;
982 } else {
983 irq_flags = IRQF_SHARED | IRQF_COND_SUSPEND;
984 }
985
978 i2c_dw_disable_int(dev); 986 i2c_dw_disable_int(dev);
979 r = devm_request_irq(dev->dev, dev->irq, i2c_dw_isr, 987 r = devm_request_irq(dev->dev, dev->irq, i2c_dw_isr, irq_flags,
980 IRQF_SHARED | IRQF_COND_SUSPEND,
981 dev_name(dev->dev), dev); 988 dev_name(dev->dev), dev);
982 if (r) { 989 if (r) {
983 dev_err(dev->dev, "failure requesting irq %i: %d\n", 990 dev_err(dev->dev, "failure requesting irq %i: %d\n",
diff --git a/drivers/i2c/busses/i2c-designware-core.h b/drivers/i2c/busses/i2c-designware-core.h
index 846ea57f85af..a7cf429daf60 100644
--- a/drivers/i2c/busses/i2c-designware-core.h
+++ b/drivers/i2c/busses/i2c-designware-core.h
@@ -79,7 +79,7 @@
79 * @pm_qos: pm_qos_request used while holding a hardware lock on the bus 79 * @pm_qos: pm_qos_request used while holding a hardware lock on the bus
80 * @acquire_lock: function to acquire a hardware lock on the bus 80 * @acquire_lock: function to acquire a hardware lock on the bus
81 * @release_lock: function to release a hardware lock on the bus 81 * @release_lock: function to release a hardware lock on the bus
82 * @pm_runtime_disabled: true if pm runtime is disabled 82 * @pm_disabled: true if power-management should be disabled for this i2c-bus
83 * 83 *
84 * HCNT and LCNT parameters can be used if the platform knows more accurate 84 * HCNT and LCNT parameters can be used if the platform knows more accurate
85 * values than the one computed based only on the input clock frequency. 85 * values than the one computed based only on the input clock frequency.
@@ -128,7 +128,7 @@ struct dw_i2c_dev {
128 struct pm_qos_request pm_qos; 128 struct pm_qos_request pm_qos;
129 int (*acquire_lock)(struct dw_i2c_dev *dev); 129 int (*acquire_lock)(struct dw_i2c_dev *dev);
130 void (*release_lock)(struct dw_i2c_dev *dev); 130 void (*release_lock)(struct dw_i2c_dev *dev);
131 bool pm_runtime_disabled; 131 bool pm_disabled;
132}; 132};
133 133
134#define ACCESS_SWAP 0x00000001 134#define ACCESS_SWAP 0x00000001
diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c
index d8665098dce9..5a4eb6b6bd92 100644
--- a/drivers/i2c/busses/i2c-designware-platdrv.c
+++ b/drivers/i2c/busses/i2c-designware-platdrv.c
@@ -85,8 +85,7 @@ static void dw_i2c_acpi_params(struct platform_device *pdev, char method[],
85 85
86 *hcnt = (u16)objs[0].integer.value; 86 *hcnt = (u16)objs[0].integer.value;
87 *lcnt = (u16)objs[1].integer.value; 87 *lcnt = (u16)objs[1].integer.value;
88 if (sda_hold) 88 *sda_hold = (u32)objs[2].integer.value;
89 *sda_hold = (u32)objs[2].integer.value;
90 } 89 }
91 90
92 kfree(buf.pointer); 91 kfree(buf.pointer);
@@ -95,26 +94,55 @@ static void dw_i2c_acpi_params(struct platform_device *pdev, char method[],
95static int dw_i2c_acpi_configure(struct platform_device *pdev) 94static int dw_i2c_acpi_configure(struct platform_device *pdev)
96{ 95{
97 struct dw_i2c_dev *dev = platform_get_drvdata(pdev); 96 struct dw_i2c_dev *dev = platform_get_drvdata(pdev);
97 acpi_handle handle = ACPI_HANDLE(&pdev->dev);
98 const struct acpi_device_id *id; 98 const struct acpi_device_id *id;
99 struct acpi_device *adev;
100 const char *uid;
99 101
100 dev->adapter.nr = -1; 102 dev->adapter.nr = -1;
101 dev->tx_fifo_depth = 32; 103 dev->tx_fifo_depth = 32;
102 dev->rx_fifo_depth = 32; 104 dev->rx_fifo_depth = 32;
103 105
104 /* 106 /*
105 * Try to get SDA hold time and *CNT values from an ACPI method if 107 * Try to get SDA hold time and *CNT values from an ACPI method for
106 * it exists for both supported speed modes. 108 * selected speed modes.
107 */ 109 */
108 dw_i2c_acpi_params(pdev, "SSCN", &dev->ss_hcnt, &dev->ss_lcnt, NULL); 110 switch (dev->clk_freq) {
109 dw_i2c_acpi_params(pdev, "FMCN", &dev->fs_hcnt, &dev->fs_lcnt, 111 case 100000:
110 &dev->sda_hold_time); 112 dw_i2c_acpi_params(pdev, "SSCN", &dev->ss_hcnt, &dev->ss_lcnt,
111 dw_i2c_acpi_params(pdev, "FPCN", &dev->fp_hcnt, &dev->fp_lcnt, NULL); 113 &dev->sda_hold_time);
112 dw_i2c_acpi_params(pdev, "HSCN", &dev->hs_hcnt, &dev->hs_lcnt, NULL); 114 break;
115 case 1000000:
116 dw_i2c_acpi_params(pdev, "FPCN", &dev->fp_hcnt, &dev->fp_lcnt,
117 &dev->sda_hold_time);
118 break;
119 case 3400000:
120 dw_i2c_acpi_params(pdev, "HSCN", &dev->hs_hcnt, &dev->hs_lcnt,
121 &dev->sda_hold_time);
122 break;
123 case 400000:
124 default:
125 dw_i2c_acpi_params(pdev, "FMCN", &dev->fs_hcnt, &dev->fs_lcnt,
126 &dev->sda_hold_time);
127 break;
128 }
113 129
114 id = acpi_match_device(pdev->dev.driver->acpi_match_table, &pdev->dev); 130 id = acpi_match_device(pdev->dev.driver->acpi_match_table, &pdev->dev);
115 if (id && id->driver_data) 131 if (id && id->driver_data)
116 dev->flags |= (u32)id->driver_data; 132 dev->flags |= (u32)id->driver_data;
117 133
134 if (acpi_bus_get_device(handle, &adev))
135 return -ENODEV;
136
137 /*
138 * Cherrytrail I2C7 gets used for the PMIC which gets accessed
139 * through ACPI opregions during late suspend / early resume
140 * disable pm for it.
141 */
142 uid = adev->pnp.unique_id;
143 if ((dev->flags & MODEL_CHERRYTRAIL) && !strcmp(uid, "7"))
144 dev->pm_disabled = true;
145
118 return 0; 146 return 0;
119} 147}
120 148
@@ -286,7 +314,7 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)
286 ACPI_COMPANION_SET(&adap->dev, ACPI_COMPANION(&pdev->dev)); 314 ACPI_COMPANION_SET(&adap->dev, ACPI_COMPANION(&pdev->dev));
287 adap->dev.of_node = pdev->dev.of_node; 315 adap->dev.of_node = pdev->dev.of_node;
288 316
289 if (dev->pm_runtime_disabled) { 317 if (dev->pm_disabled) {
290 pm_runtime_forbid(&pdev->dev); 318 pm_runtime_forbid(&pdev->dev);
291 } else { 319 } else {
292 pm_runtime_set_autosuspend_delay(&pdev->dev, 1000); 320 pm_runtime_set_autosuspend_delay(&pdev->dev, 1000);
@@ -302,7 +330,7 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)
302 return r; 330 return r;
303 331
304exit_probe: 332exit_probe:
305 if (!dev->pm_runtime_disabled) 333 if (!dev->pm_disabled)
306 pm_runtime_disable(&pdev->dev); 334 pm_runtime_disable(&pdev->dev);
307exit_reset: 335exit_reset:
308 if (!IS_ERR_OR_NULL(dev->rst)) 336 if (!IS_ERR_OR_NULL(dev->rst))
@@ -322,7 +350,7 @@ static int dw_i2c_plat_remove(struct platform_device *pdev)
322 350
323 pm_runtime_dont_use_autosuspend(&pdev->dev); 351 pm_runtime_dont_use_autosuspend(&pdev->dev);
324 pm_runtime_put_sync(&pdev->dev); 352 pm_runtime_put_sync(&pdev->dev);
325 if (!dev->pm_runtime_disabled) 353 if (!dev->pm_disabled)
326 pm_runtime_disable(&pdev->dev); 354 pm_runtime_disable(&pdev->dev);
327 if (!IS_ERR_OR_NULL(dev->rst)) 355 if (!IS_ERR_OR_NULL(dev->rst))
328 reset_control_assert(dev->rst); 356 reset_control_assert(dev->rst);
@@ -374,9 +402,7 @@ static int dw_i2c_plat_resume(struct device *dev)
374 struct dw_i2c_dev *i_dev = platform_get_drvdata(pdev); 402 struct dw_i2c_dev *i_dev = platform_get_drvdata(pdev);
375 403
376 i2c_dw_plat_prepare_clk(i_dev, true); 404 i2c_dw_plat_prepare_clk(i_dev, true);
377 405 i2c_dw_init(i_dev);
378 if (!i_dev->pm_runtime_disabled)
379 i2c_dw_init(i_dev);
380 406
381 return 0; 407 return 0;
382} 408}
diff --git a/drivers/i2c/busses/i2c-exynos5.c b/drivers/i2c/busses/i2c-exynos5.c
index 736a82472101..23ed4d67ecad 100644
--- a/drivers/i2c/busses/i2c-exynos5.c
+++ b/drivers/i2c/busses/i2c-exynos5.c
@@ -22,6 +22,7 @@
22#include <linux/slab.h> 22#include <linux/slab.h>
23#include <linux/io.h> 23#include <linux/io.h>
24#include <linux/of_address.h> 24#include <linux/of_address.h>
25#include <linux/of_device.h>
25#include <linux/of_irq.h> 26#include <linux/of_irq.h>
26#include <linux/spinlock.h> 27#include <linux/spinlock.h>
27 28
@@ -168,8 +169,6 @@
168 */ 169 */
169#define HSI2C_HS_TX_CLOCK 1000000 170#define HSI2C_HS_TX_CLOCK 1000000
170#define HSI2C_FS_TX_CLOCK 100000 171#define HSI2C_FS_TX_CLOCK 100000
171#define HSI2C_HIGH_SPD 1
172#define HSI2C_FAST_SPD 0
173 172
174#define EXYNOS5_I2C_TIMEOUT (msecs_to_jiffies(1000)) 173#define EXYNOS5_I2C_TIMEOUT (msecs_to_jiffies(1000))
175 174
@@ -200,18 +199,10 @@ struct exynos5_i2c {
200 int trans_done; 199 int trans_done;
201 200
202 /* Controller operating frequency */ 201 /* Controller operating frequency */
203 unsigned int fs_clock; 202 unsigned int op_clock;
204 unsigned int hs_clock;
205
206 /*
207 * HSI2C Controller can operate in
208 * 1. High speed upto 3.4Mbps
209 * 2. Fast speed upto 1Mbps
210 */
211 int speed_mode;
212 203
213 /* Version of HS-I2C Hardware */ 204 /* Version of HS-I2C Hardware */
214 struct exynos_hsi2c_variant *variant; 205 const struct exynos_hsi2c_variant *variant;
215}; 206};
216 207
217/** 208/**
@@ -257,15 +248,6 @@ static const struct of_device_id exynos5_i2c_match[] = {
257}; 248};
258MODULE_DEVICE_TABLE(of, exynos5_i2c_match); 249MODULE_DEVICE_TABLE(of, exynos5_i2c_match);
259 250
260static inline struct exynos_hsi2c_variant *exynos5_i2c_get_variant
261 (struct platform_device *pdev)
262{
263 const struct of_device_id *match;
264
265 match = of_match_node(exynos5_i2c_match, pdev->dev.of_node);
266 return (struct exynos_hsi2c_variant *)match->data;
267}
268
269static void exynos5_i2c_clr_pend_irq(struct exynos5_i2c *i2c) 251static void exynos5_i2c_clr_pend_irq(struct exynos5_i2c *i2c)
270{ 252{
271 writel(readl(i2c->regs + HSI2C_INT_STATUS), 253 writel(readl(i2c->regs + HSI2C_INT_STATUS),
@@ -279,7 +261,7 @@ static void exynos5_i2c_clr_pend_irq(struct exynos5_i2c *i2c)
279 * Returns 0 on success, -EINVAL if the cycle length cannot 261 * Returns 0 on success, -EINVAL if the cycle length cannot
280 * be calculated. 262 * be calculated.
281 */ 263 */
282static int exynos5_i2c_set_timing(struct exynos5_i2c *i2c, int mode) 264static int exynos5_i2c_set_timing(struct exynos5_i2c *i2c, bool hs_timings)
283{ 265{
284 u32 i2c_timing_s1; 266 u32 i2c_timing_s1;
285 u32 i2c_timing_s2; 267 u32 i2c_timing_s2;
@@ -292,9 +274,10 @@ static int exynos5_i2c_set_timing(struct exynos5_i2c *i2c, int mode)
292 unsigned int t_sr_release; 274 unsigned int t_sr_release;
293 unsigned int t_ftl_cycle; 275 unsigned int t_ftl_cycle;
294 unsigned int clkin = clk_get_rate(i2c->clk); 276 unsigned int clkin = clk_get_rate(i2c->clk);
295 unsigned int div, utemp0 = 0, utemp1 = 0, clk_cycle; 277 unsigned int op_clk = hs_timings ? i2c->op_clock :
296 unsigned int op_clk = (mode == HSI2C_HIGH_SPD) ? 278 (i2c->op_clock >= HSI2C_HS_TX_CLOCK) ? HSI2C_FS_TX_CLOCK :
297 i2c->hs_clock : i2c->fs_clock; 279 i2c->op_clock;
280 int div, clk_cycle, temp;
298 281
299 /* 282 /*
300 * In case of HSI2C controller in Exynos5 series 283 * In case of HSI2C controller in Exynos5 series
@@ -305,33 +288,22 @@ static int exynos5_i2c_set_timing(struct exynos5_i2c *i2c, int mode)
305 * FPCLK / FI2C = 288 * FPCLK / FI2C =
306 * (CLK_DIV + 1) * (TSCLK_L + TSCLK_H + 2) + 8 + FLT_CYCLE 289 * (CLK_DIV + 1) * (TSCLK_L + TSCLK_H + 2) + 8 + FLT_CYCLE
307 * 290 *
308 * utemp0 = (CLK_DIV + 1) * (TSCLK_L + TSCLK_H + 2) 291 * clk_cycle := TSCLK_L + TSCLK_H
309 * utemp1 = (TSCLK_L + TSCLK_H + 2) 292 * temp := (CLK_DIV + 1) * (clk_cycle + 2)
293 *
294 * Constraints: 4 <= temp, 0 <= CLK_DIV < 256, 2 <= clk_cycle <= 510
295 *
310 */ 296 */
311 t_ftl_cycle = (readl(i2c->regs + HSI2C_CONF) >> 16) & 0x7; 297 t_ftl_cycle = (readl(i2c->regs + HSI2C_CONF) >> 16) & 0x7;
312 utemp0 = (clkin / op_clk) - 8; 298 temp = clkin / op_clk - 8 - t_ftl_cycle;
313 299 if (i2c->variant->hw != HSI2C_EXYNOS7)
314 if (i2c->variant->hw == HSI2C_EXYNOS7) 300 temp -= t_ftl_cycle;
315 utemp0 -= t_ftl_cycle; 301 div = temp / 512;
316 else 302 clk_cycle = temp / (div + 1) - 2;
317 utemp0 -= 2 * t_ftl_cycle; 303 if (temp < 4 || div >= 256 || clk_cycle < 2) {
318 304 dev_err(i2c->dev, "%s clock set-up failed\n",
319 /* CLK_DIV max is 256 */ 305 hs_timings ? "HS" : "FS");
320 for (div = 0; div < 256; div++) { 306 return -EINVAL;
321 utemp1 = utemp0 / (div + 1);
322
323 /*
324 * SCL_L and SCL_H each has max value of 255
325 * Hence, For the clk_cycle to the have right value
326 * utemp1 has to be less then 512 and more than 4.
327 */
328 if ((utemp1 < 512) && (utemp1 > 4)) {
329 clk_cycle = utemp1 - 2;
330 break;
331 } else if (div == 255) {
332 dev_warn(i2c->dev, "Failed to calculate divisor");
333 return -EINVAL;
334 }
335 } 307 }
336 308
337 t_scl_l = clk_cycle / 2; 309 t_scl_l = clk_cycle / 2;
@@ -356,7 +328,7 @@ static int exynos5_i2c_set_timing(struct exynos5_i2c *i2c, int mode)
356 div, t_sr_release); 328 div, t_sr_release);
357 dev_dbg(i2c->dev, "tDATA_HD: %X\n", t_data_hd); 329 dev_dbg(i2c->dev, "tDATA_HD: %X\n", t_data_hd);
358 330
359 if (mode == HSI2C_HIGH_SPD) { 331 if (hs_timings) {
360 writel(i2c_timing_s1, i2c->regs + HSI2C_TIMING_HS1); 332 writel(i2c_timing_s1, i2c->regs + HSI2C_TIMING_HS1);
361 writel(i2c_timing_s2, i2c->regs + HSI2C_TIMING_HS2); 333 writel(i2c_timing_s2, i2c->regs + HSI2C_TIMING_HS2);
362 writel(i2c_timing_s3, i2c->regs + HSI2C_TIMING_HS3); 334 writel(i2c_timing_s3, i2c->regs + HSI2C_TIMING_HS3);
@@ -372,24 +344,13 @@ static int exynos5_i2c_set_timing(struct exynos5_i2c *i2c, int mode)
372 344
373static int exynos5_hsi2c_clock_setup(struct exynos5_i2c *i2c) 345static int exynos5_hsi2c_clock_setup(struct exynos5_i2c *i2c)
374{ 346{
375 /* 347 /* always set Fast Speed timings */
376 * Configure the Fast speed timing values 348 int ret = exynos5_i2c_set_timing(i2c, false);
377 * Even the High Speed mode initially starts with Fast mode
378 */
379 if (exynos5_i2c_set_timing(i2c, HSI2C_FAST_SPD)) {
380 dev_err(i2c->dev, "HSI2C FS Clock set up failed\n");
381 return -EINVAL;
382 }
383 349
384 /* configure the High speed timing values */ 350 if (ret < 0 || i2c->op_clock < HSI2C_HS_TX_CLOCK)
385 if (i2c->speed_mode == HSI2C_HIGH_SPD) { 351 return ret;
386 if (exynos5_i2c_set_timing(i2c, HSI2C_HIGH_SPD)) {
387 dev_err(i2c->dev, "HSI2C HS Clock set up failed\n");
388 return -EINVAL;
389 }
390 }
391 352
392 return 0; 353 return exynos5_i2c_set_timing(i2c, true);
393} 354}
394 355
395/* 356/*
@@ -409,7 +370,7 @@ static void exynos5_i2c_init(struct exynos5_i2c *i2c)
409 i2c->regs + HSI2C_CTL); 370 i2c->regs + HSI2C_CTL);
410 writel(HSI2C_TRAILING_COUNT, i2c->regs + HSI2C_TRAILIG_CTL); 371 writel(HSI2C_TRAILING_COUNT, i2c->regs + HSI2C_TRAILIG_CTL);
411 372
412 if (i2c->speed_mode == HSI2C_HIGH_SPD) { 373 if (i2c->op_clock >= HSI2C_HS_TX_CLOCK) {
413 writel(HSI2C_MASTER_ID(MASTER_ID(i2c->adap.nr)), 374 writel(HSI2C_MASTER_ID(MASTER_ID(i2c->adap.nr)),
414 i2c->regs + HSI2C_ADDR); 375 i2c->regs + HSI2C_ADDR);
415 i2c_conf |= HSI2C_HS_MODE; 376 i2c_conf |= HSI2C_HS_MODE;
@@ -747,26 +708,14 @@ static int exynos5_i2c_probe(struct platform_device *pdev)
747 struct device_node *np = pdev->dev.of_node; 708 struct device_node *np = pdev->dev.of_node;
748 struct exynos5_i2c *i2c; 709 struct exynos5_i2c *i2c;
749 struct resource *mem; 710 struct resource *mem;
750 unsigned int op_clock;
751 int ret; 711 int ret;
752 712
753 i2c = devm_kzalloc(&pdev->dev, sizeof(struct exynos5_i2c), GFP_KERNEL); 713 i2c = devm_kzalloc(&pdev->dev, sizeof(struct exynos5_i2c), GFP_KERNEL);
754 if (!i2c) 714 if (!i2c)
755 return -ENOMEM; 715 return -ENOMEM;
756 716
757 if (of_property_read_u32(np, "clock-frequency", &op_clock)) { 717 if (of_property_read_u32(np, "clock-frequency", &i2c->op_clock))
758 i2c->speed_mode = HSI2C_FAST_SPD; 718 i2c->op_clock = HSI2C_FS_TX_CLOCK;
759 i2c->fs_clock = HSI2C_FS_TX_CLOCK;
760 } else {
761 if (op_clock >= HSI2C_HS_TX_CLOCK) {
762 i2c->speed_mode = HSI2C_HIGH_SPD;
763 i2c->fs_clock = HSI2C_FS_TX_CLOCK;
764 i2c->hs_clock = op_clock;
765 } else {
766 i2c->speed_mode = HSI2C_FAST_SPD;
767 i2c->fs_clock = op_clock;
768 }
769 }
770 719
771 strlcpy(i2c->adap.name, "exynos5-i2c", sizeof(i2c->adap.name)); 720 strlcpy(i2c->adap.name, "exynos5-i2c", sizeof(i2c->adap.name));
772 i2c->adap.owner = THIS_MODULE; 721 i2c->adap.owner = THIS_MODULE;
@@ -817,8 +766,7 @@ static int exynos5_i2c_probe(struct platform_device *pdev)
817 goto err_clk; 766 goto err_clk;
818 } 767 }
819 768
820 /* Need to check the variant before setting up. */ 769 i2c->variant = of_device_get_match_data(&pdev->dev);
821 i2c->variant = exynos5_i2c_get_variant(pdev);
822 770
823 ret = exynos5_hsi2c_clock_setup(i2c); 771 ret = exynos5_hsi2c_clock_setup(i2c);
824 if (ret) 772 if (ret)
diff --git a/drivers/i2c/busses/i2c-img-scb.c b/drivers/i2c/busses/i2c-img-scb.c
index db8e8b40569d..84fb35f6837f 100644
--- a/drivers/i2c/busses/i2c-img-scb.c
+++ b/drivers/i2c/busses/i2c-img-scb.c
@@ -1362,9 +1362,8 @@ static int img_i2c_probe(struct platform_device *pdev)
1362 } 1362 }
1363 1363
1364 /* Set up the exception check timer */ 1364 /* Set up the exception check timer */
1365 init_timer(&i2c->check_timer); 1365 setup_timer(&i2c->check_timer, img_i2c_check_timer,
1366 i2c->check_timer.function = img_i2c_check_timer; 1366 (unsigned long)i2c);
1367 i2c->check_timer.data = (unsigned long)i2c;
1368 1367
1369 i2c->bitrate = timings[0].max_bitrate; 1368 i2c->bitrate = timings[0].max_bitrate;
1370 if (!of_property_read_u32(node, "clock-frequency", &val)) 1369 if (!of_property_read_u32(node, "clock-frequency", &val))
diff --git a/drivers/i2c/busses/i2c-meson.c b/drivers/i2c/busses/i2c-meson.c
index 73b97c71a484..88d15b92ec35 100644
--- a/drivers/i2c/busses/i2c-meson.c
+++ b/drivers/i2c/busses/i2c-meson.c
@@ -35,10 +35,11 @@
35#define REG_CTRL_STATUS BIT(2) 35#define REG_CTRL_STATUS BIT(2)
36#define REG_CTRL_ERROR BIT(3) 36#define REG_CTRL_ERROR BIT(3)
37#define REG_CTRL_CLKDIV_SHIFT 12 37#define REG_CTRL_CLKDIV_SHIFT 12
38#define REG_CTRL_CLKDIV_MASK ((BIT(10) - 1) << REG_CTRL_CLKDIV_SHIFT) 38#define REG_CTRL_CLKDIV_MASK GENMASK(21, 12)
39#define REG_CTRL_CLKDIVEXT_SHIFT 28
40#define REG_CTRL_CLKDIVEXT_MASK GENMASK(29, 28)
39 41
40#define I2C_TIMEOUT_MS 500 42#define I2C_TIMEOUT_MS 500
41#define DEFAULT_FREQ 100000
42 43
43enum { 44enum {
44 TOKEN_END = 0, 45 TOKEN_END = 0,
@@ -54,7 +55,6 @@ enum {
54 STATE_IDLE, 55 STATE_IDLE,
55 STATE_READ, 56 STATE_READ,
56 STATE_WRITE, 57 STATE_WRITE,
57 STATE_STOP,
58}; 58};
59 59
60/** 60/**
@@ -73,7 +73,6 @@ enum {
73 * @error: Flag set when an error is received 73 * @error: Flag set when an error is received
74 * @lock: To avoid race conditions between irq handler and xfer code 74 * @lock: To avoid race conditions between irq handler and xfer code
75 * @done: Completion used to wait for transfer termination 75 * @done: Completion used to wait for transfer termination
76 * @frequency: Operating frequency of I2C bus clock
77 * @tokens: Sequence of tokens to be written to the device 76 * @tokens: Sequence of tokens to be written to the device
78 * @num_tokens: Number of tokens 77 * @num_tokens: Number of tokens
79 */ 78 */
@@ -82,7 +81,6 @@ struct meson_i2c {
82 struct device *dev; 81 struct device *dev;
83 void __iomem *regs; 82 void __iomem *regs;
84 struct clk *clk; 83 struct clk *clk;
85 int irq;
86 84
87 struct i2c_msg *msg; 85 struct i2c_msg *msg;
88 int state; 86 int state;
@@ -93,7 +91,6 @@ struct meson_i2c {
93 91
94 spinlock_t lock; 92 spinlock_t lock;
95 struct completion done; 93 struct completion done;
96 unsigned int frequency;
97 u32 tokens[2]; 94 u32 tokens[2];
98 int num_tokens; 95 int num_tokens;
99}; 96};
@@ -126,23 +123,27 @@ static void meson_i2c_add_token(struct meson_i2c *i2c, int token)
126 i2c->num_tokens++; 123 i2c->num_tokens++;
127} 124}
128 125
129static void meson_i2c_write_tokens(struct meson_i2c *i2c) 126static void meson_i2c_set_clk_div(struct meson_i2c *i2c, unsigned int freq)
130{
131 writel(i2c->tokens[0], i2c->regs + REG_TOK_LIST0);
132 writel(i2c->tokens[1], i2c->regs + REG_TOK_LIST1);
133}
134
135static void meson_i2c_set_clk_div(struct meson_i2c *i2c)
136{ 127{
137 unsigned long clk_rate = clk_get_rate(i2c->clk); 128 unsigned long clk_rate = clk_get_rate(i2c->clk);
138 unsigned int div; 129 unsigned int div;
139 130
140 div = DIV_ROUND_UP(clk_rate, i2c->frequency * 4); 131 div = DIV_ROUND_UP(clk_rate, freq * 4);
132
133 /* clock divider has 12 bits */
134 if (div >= (1 << 12)) {
135 dev_err(i2c->dev, "requested bus frequency too low\n");
136 div = (1 << 12) - 1;
137 }
138
141 meson_i2c_set_mask(i2c, REG_CTRL, REG_CTRL_CLKDIV_MASK, 139 meson_i2c_set_mask(i2c, REG_CTRL, REG_CTRL_CLKDIV_MASK,
142 div << REG_CTRL_CLKDIV_SHIFT); 140 (div & GENMASK(9, 0)) << REG_CTRL_CLKDIV_SHIFT);
141
142 meson_i2c_set_mask(i2c, REG_CTRL, REG_CTRL_CLKDIVEXT_MASK,
143 (div >> 10) << REG_CTRL_CLKDIVEXT_SHIFT);
143 144
144 dev_dbg(i2c->dev, "%s: clk %lu, freq %u, div %u\n", __func__, 145 dev_dbg(i2c->dev, "%s: clk %lu, freq %u, div %u\n", __func__,
145 clk_rate, i2c->frequency, div); 146 clk_rate, freq, div);
146} 147}
147 148
148static void meson_i2c_get_data(struct meson_i2c *i2c, char *buf, int len) 149static void meson_i2c_get_data(struct meson_i2c *i2c, char *buf, int len)
@@ -156,10 +157,10 @@ static void meson_i2c_get_data(struct meson_i2c *i2c, char *buf, int len)
156 dev_dbg(i2c->dev, "%s: data %08x %08x len %d\n", __func__, 157 dev_dbg(i2c->dev, "%s: data %08x %08x len %d\n", __func__,
157 rdata0, rdata1, len); 158 rdata0, rdata1, len);
158 159
159 for (i = 0; i < min_t(int, 4, len); i++) 160 for (i = 0; i < min(4, len); i++)
160 *buf++ = (rdata0 >> i * 8) & 0xff; 161 *buf++ = (rdata0 >> i * 8) & 0xff;
161 162
162 for (i = 4; i < min_t(int, 8, len); i++) 163 for (i = 4; i < min(8, len); i++)
163 *buf++ = (rdata1 >> (i - 4) * 8) & 0xff; 164 *buf++ = (rdata1 >> (i - 4) * 8) & 0xff;
164} 165}
165 166
@@ -168,10 +169,10 @@ static void meson_i2c_put_data(struct meson_i2c *i2c, char *buf, int len)
168 u32 wdata0 = 0, wdata1 = 0; 169 u32 wdata0 = 0, wdata1 = 0;
169 int i; 170 int i;
170 171
171 for (i = 0; i < min_t(int, 4, len); i++) 172 for (i = 0; i < min(4, len); i++)
172 wdata0 |= *buf++ << (i * 8); 173 wdata0 |= *buf++ << (i * 8);
173 174
174 for (i = 4; i < min_t(int, 8, len); i++) 175 for (i = 4; i < min(8, len); i++)
175 wdata1 |= *buf++ << ((i - 4) * 8); 176 wdata1 |= *buf++ << ((i - 4) * 8);
176 177
177 writel(wdata0, i2c->regs + REG_TOK_WDATA0); 178 writel(wdata0, i2c->regs + REG_TOK_WDATA0);
@@ -186,7 +187,7 @@ static void meson_i2c_prepare_xfer(struct meson_i2c *i2c)
186 bool write = !(i2c->msg->flags & I2C_M_RD); 187 bool write = !(i2c->msg->flags & I2C_M_RD);
187 int i; 188 int i;
188 189
189 i2c->count = min_t(int, i2c->msg->len - i2c->pos, 8); 190 i2c->count = min(i2c->msg->len - i2c->pos, 8);
190 191
191 for (i = 0; i < i2c->count - 1; i++) 192 for (i = 0; i < i2c->count - 1; i++)
192 meson_i2c_add_token(i2c, TOKEN_DATA); 193 meson_i2c_add_token(i2c, TOKEN_DATA);
@@ -200,19 +201,12 @@ static void meson_i2c_prepare_xfer(struct meson_i2c *i2c)
200 201
201 if (write) 202 if (write)
202 meson_i2c_put_data(i2c, i2c->msg->buf + i2c->pos, i2c->count); 203 meson_i2c_put_data(i2c, i2c->msg->buf + i2c->pos, i2c->count);
203}
204
205static void meson_i2c_stop(struct meson_i2c *i2c)
206{
207 dev_dbg(i2c->dev, "%s: last %d\n", __func__, i2c->last);
208 204
209 if (i2c->last) { 205 if (i2c->last && i2c->pos + i2c->count >= i2c->msg->len)
210 i2c->state = STATE_STOP;
211 meson_i2c_add_token(i2c, TOKEN_STOP); 206 meson_i2c_add_token(i2c, TOKEN_STOP);
212 } else { 207
213 i2c->state = STATE_IDLE; 208 writel(i2c->tokens[0], i2c->regs + REG_TOK_LIST0);
214 complete(&i2c->done); 209 writel(i2c->tokens[1], i2c->regs + REG_TOK_LIST1);
215 }
216} 210}
217 211
218static irqreturn_t meson_i2c_irq(int irqno, void *dev_id) 212static irqreturn_t meson_i2c_irq(int irqno, void *dev_id)
@@ -223,12 +217,18 @@ static irqreturn_t meson_i2c_irq(int irqno, void *dev_id)
223 spin_lock(&i2c->lock); 217 spin_lock(&i2c->lock);
224 218
225 meson_i2c_reset_tokens(i2c); 219 meson_i2c_reset_tokens(i2c);
220 meson_i2c_set_mask(i2c, REG_CTRL, REG_CTRL_START, 0);
226 ctrl = readl(i2c->regs + REG_CTRL); 221 ctrl = readl(i2c->regs + REG_CTRL);
227 222
228 dev_dbg(i2c->dev, "irq: state %d, pos %d, count %d, ctrl %08x\n", 223 dev_dbg(i2c->dev, "irq: state %d, pos %d, count %d, ctrl %08x\n",
229 i2c->state, i2c->pos, i2c->count, ctrl); 224 i2c->state, i2c->pos, i2c->count, ctrl);
230 225
231 if (ctrl & REG_CTRL_ERROR && i2c->state != STATE_IDLE) { 226 if (i2c->state == STATE_IDLE) {
227 spin_unlock(&i2c->lock);
228 return IRQ_NONE;
229 }
230
231 if (ctrl & REG_CTRL_ERROR) {
232 /* 232 /*
233 * The bit is set when the IGNORE_NAK bit is cleared 233 * The bit is set when the IGNORE_NAK bit is cleared
234 * and the device didn't respond. In this case, the 234 * and the device didn't respond. In this case, the
@@ -242,48 +242,21 @@ static irqreturn_t meson_i2c_irq(int irqno, void *dev_id)
242 goto out; 242 goto out;
243 } 243 }
244 244
245 switch (i2c->state) { 245 if (i2c->state == STATE_READ && i2c->count)
246 case STATE_READ: 246 meson_i2c_get_data(i2c, i2c->msg->buf + i2c->pos, i2c->count);
247 if (i2c->count > 0) {
248 meson_i2c_get_data(i2c, i2c->msg->buf + i2c->pos,
249 i2c->count);
250 i2c->pos += i2c->count;
251 }
252
253 if (i2c->pos >= i2c->msg->len) {
254 meson_i2c_stop(i2c);
255 break;
256 }
257
258 meson_i2c_prepare_xfer(i2c);
259 break;
260 case STATE_WRITE:
261 i2c->pos += i2c->count;
262 247
263 if (i2c->pos >= i2c->msg->len) { 248 i2c->pos += i2c->count;
264 meson_i2c_stop(i2c);
265 break;
266 }
267 249
268 meson_i2c_prepare_xfer(i2c); 250 if (i2c->pos >= i2c->msg->len) {
269 break;
270 case STATE_STOP:
271 i2c->state = STATE_IDLE; 251 i2c->state = STATE_IDLE;
272 complete(&i2c->done); 252 complete(&i2c->done);
273 break; 253 goto out;
274 case STATE_IDLE:
275 break;
276 } 254 }
277 255
256 /* Restart the processing */
257 meson_i2c_prepare_xfer(i2c);
258 meson_i2c_set_mask(i2c, REG_CTRL, REG_CTRL_START, REG_CTRL_START);
278out: 259out:
279 if (i2c->state != STATE_IDLE) {
280 /* Restart the processing */
281 meson_i2c_write_tokens(i2c);
282 meson_i2c_set_mask(i2c, REG_CTRL, REG_CTRL_START, 0);
283 meson_i2c_set_mask(i2c, REG_CTRL, REG_CTRL_START,
284 REG_CTRL_START);
285 }
286
287 spin_unlock(&i2c->lock); 260 spin_unlock(&i2c->lock);
288 261
289 return IRQ_HANDLED; 262 return IRQ_HANDLED;
@@ -323,7 +296,6 @@ static int meson_i2c_xfer_msg(struct meson_i2c *i2c, struct i2c_msg *msg,
323 296
324 i2c->state = (msg->flags & I2C_M_RD) ? STATE_READ : STATE_WRITE; 297 i2c->state = (msg->flags & I2C_M_RD) ? STATE_READ : STATE_WRITE;
325 meson_i2c_prepare_xfer(i2c); 298 meson_i2c_prepare_xfer(i2c);
326 meson_i2c_write_tokens(i2c);
327 reinit_completion(&i2c->done); 299 reinit_completion(&i2c->done);
328 300
329 /* Start the transfer */ 301 /* Start the transfer */
@@ -359,21 +331,19 @@ static int meson_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
359 int num) 331 int num)
360{ 332{
361 struct meson_i2c *i2c = adap->algo_data; 333 struct meson_i2c *i2c = adap->algo_data;
362 int i, ret = 0, count = 0; 334 int i, ret = 0;
363 335
364 clk_enable(i2c->clk); 336 clk_enable(i2c->clk);
365 meson_i2c_set_clk_div(i2c);
366 337
367 for (i = 0; i < num; i++) { 338 for (i = 0; i < num; i++) {
368 ret = meson_i2c_xfer_msg(i2c, msgs + i, i == num - 1); 339 ret = meson_i2c_xfer_msg(i2c, msgs + i, i == num - 1);
369 if (ret) 340 if (ret)
370 break; 341 break;
371 count++;
372 } 342 }
373 343
374 clk_disable(i2c->clk); 344 clk_disable(i2c->clk);
375 345
376 return ret ? ret : count; 346 return ret ?: i;
377} 347}
378 348
379static u32 meson_i2c_func(struct i2c_adapter *adap) 349static u32 meson_i2c_func(struct i2c_adapter *adap)
@@ -391,15 +361,14 @@ static int meson_i2c_probe(struct platform_device *pdev)
391 struct device_node *np = pdev->dev.of_node; 361 struct device_node *np = pdev->dev.of_node;
392 struct meson_i2c *i2c; 362 struct meson_i2c *i2c;
393 struct resource *mem; 363 struct resource *mem;
394 int ret = 0; 364 struct i2c_timings timings;
365 int irq, ret = 0;
395 366
396 i2c = devm_kzalloc(&pdev->dev, sizeof(struct meson_i2c), GFP_KERNEL); 367 i2c = devm_kzalloc(&pdev->dev, sizeof(struct meson_i2c), GFP_KERNEL);
397 if (!i2c) 368 if (!i2c)
398 return -ENOMEM; 369 return -ENOMEM;
399 370
400 if (of_property_read_u32(pdev->dev.of_node, "clock-frequency", 371 i2c_parse_fw_timings(&pdev->dev, &timings, true);
401 &i2c->frequency))
402 i2c->frequency = DEFAULT_FREQ;
403 372
404 i2c->dev = &pdev->dev; 373 i2c->dev = &pdev->dev;
405 platform_set_drvdata(pdev, i2c); 374 platform_set_drvdata(pdev, i2c);
@@ -418,14 +387,13 @@ static int meson_i2c_probe(struct platform_device *pdev)
418 if (IS_ERR(i2c->regs)) 387 if (IS_ERR(i2c->regs))
419 return PTR_ERR(i2c->regs); 388 return PTR_ERR(i2c->regs);
420 389
421 i2c->irq = platform_get_irq(pdev, 0); 390 irq = platform_get_irq(pdev, 0);
422 if (i2c->irq < 0) { 391 if (irq < 0) {
423 dev_err(&pdev->dev, "can't find IRQ\n"); 392 dev_err(&pdev->dev, "can't find IRQ\n");
424 return i2c->irq; 393 return irq;
425 } 394 }
426 395
427 ret = devm_request_irq(&pdev->dev, i2c->irq, meson_i2c_irq, 396 ret = devm_request_irq(&pdev->dev, irq, meson_i2c_irq, 0, NULL, i2c);
428 0, dev_name(&pdev->dev), i2c);
429 if (ret < 0) { 397 if (ret < 0) {
430 dev_err(&pdev->dev, "can't request IRQ\n"); 398 dev_err(&pdev->dev, "can't request IRQ\n");
431 return ret; 399 return ret;
@@ -457,6 +425,8 @@ static int meson_i2c_probe(struct platform_device *pdev)
457 return ret; 425 return ret;
458 } 426 }
459 427
428 meson_i2c_set_clk_div(i2c, timings.bus_freq_hz);
429
460 return 0; 430 return 0;
461} 431}
462 432
diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c
index a50bd6891e27..cf737ec8563b 100644
--- a/drivers/i2c/busses/i2c-mv64xxx.c
+++ b/drivers/i2c/busses/i2c-mv64xxx.c
@@ -823,13 +823,10 @@ mv64xxx_of_config(struct mv64xxx_i2c_data *drv_data,
823 823
824 drv_data->rstc = devm_reset_control_get_optional(dev, NULL); 824 drv_data->rstc = devm_reset_control_get_optional(dev, NULL);
825 if (IS_ERR(drv_data->rstc)) { 825 if (IS_ERR(drv_data->rstc)) {
826 if (PTR_ERR(drv_data->rstc) == -EPROBE_DEFER) { 826 rc = PTR_ERR(drv_data->rstc);
827 rc = -EPROBE_DEFER; 827 goto out;
828 goto out;
829 }
830 } else {
831 reset_control_deassert(drv_data->rstc);
832 } 828 }
829 reset_control_deassert(drv_data->rstc);
833 830
834 /* Its not yet defined how timeouts will be specified in device tree. 831 /* Its not yet defined how timeouts will be specified in device tree.
835 * So hard code the value to 1 second. 832 * So hard code the value to 1 second.
@@ -951,8 +948,7 @@ mv64xxx_i2c_probe(struct platform_device *pd)
951exit_free_irq: 948exit_free_irq:
952 free_irq(drv_data->irq, drv_data); 949 free_irq(drv_data->irq, drv_data);
953exit_reset: 950exit_reset:
954 if (!IS_ERR_OR_NULL(drv_data->rstc)) 951 reset_control_assert(drv_data->rstc);
955 reset_control_assert(drv_data->rstc);
956exit_clk: 952exit_clk:
957 /* Not all platforms have a clk */ 953 /* Not all platforms have a clk */
958 if (!IS_ERR(drv_data->clk)) 954 if (!IS_ERR(drv_data->clk))
@@ -968,8 +964,7 @@ mv64xxx_i2c_remove(struct platform_device *dev)
968 964
969 i2c_del_adapter(&drv_data->adapter); 965 i2c_del_adapter(&drv_data->adapter);
970 free_irq(drv_data->irq, drv_data); 966 free_irq(drv_data->irq, drv_data);
971 if (!IS_ERR_OR_NULL(drv_data->rstc)) 967 reset_control_assert(drv_data->rstc);
972 reset_control_assert(drv_data->rstc);
973 /* Not all platforms have a clk */ 968 /* Not all platforms have a clk */
974 if (!IS_ERR(drv_data->clk)) 969 if (!IS_ERR(drv_data->clk))
975 clk_disable_unprepare(drv_data->clk); 970 clk_disable_unprepare(drv_data->clk);
diff --git a/drivers/i2c/busses/i2c-rcar.c b/drivers/i2c/busses/i2c-rcar.c
index 26f2ff22e97e..214bf2835d1f 100644
--- a/drivers/i2c/busses/i2c-rcar.c
+++ b/drivers/i2c/busses/i2c-rcar.c
@@ -700,6 +700,8 @@ static int rcar_i2c_master_xfer(struct i2c_adapter *adap,
700 700
701 pm_runtime_get_sync(dev); 701 pm_runtime_get_sync(dev);
702 702
703 rcar_i2c_init(priv);
704
703 ret = rcar_i2c_bus_barrier(priv); 705 ret = rcar_i2c_bus_barrier(priv);
704 if (ret < 0) 706 if (ret < 0)
705 goto out; 707 goto out;
@@ -751,6 +753,7 @@ static int rcar_reg_slave(struct i2c_client *slave)
751 if (slave->flags & I2C_CLIENT_TEN) 753 if (slave->flags & I2C_CLIENT_TEN)
752 return -EAFNOSUPPORT; 754 return -EAFNOSUPPORT;
753 755
756 /* Keep device active for slave address detection logic */
754 pm_runtime_get_sync(rcar_i2c_priv_to_dev(priv)); 757 pm_runtime_get_sync(rcar_i2c_priv_to_dev(priv));
755 758
756 priv->slave = slave; 759 priv->slave = slave;
@@ -854,15 +857,14 @@ static int rcar_i2c_probe(struct platform_device *pdev)
854 priv->dma_direction = DMA_NONE; 857 priv->dma_direction = DMA_NONE;
855 priv->dma_rx = priv->dma_tx = ERR_PTR(-EPROBE_DEFER); 858 priv->dma_rx = priv->dma_tx = ERR_PTR(-EPROBE_DEFER);
856 859
860 /* Activate device for clock calculation */
857 pm_runtime_enable(dev); 861 pm_runtime_enable(dev);
858 pm_runtime_get_sync(dev); 862 pm_runtime_get_sync(dev);
859 ret = rcar_i2c_clock_calculate(priv, &i2c_t); 863 ret = rcar_i2c_clock_calculate(priv, &i2c_t);
860 if (ret < 0) 864 if (ret < 0)
861 goto out_pm_put; 865 goto out_pm_put;
862 866
863 rcar_i2c_init(priv); 867 /* Stay always active when multi-master to keep arbitration working */
864
865 /* Don't suspend when multi-master to keep arbitration working */
866 if (of_property_read_bool(dev->of_node, "multi-master")) 868 if (of_property_read_bool(dev->of_node, "multi-master"))
867 priv->flags |= ID_P_PM_BLOCKED; 869 priv->flags |= ID_P_PM_BLOCKED;
868 else 870 else
diff --git a/drivers/i2c/busses/i2c-scmi.c b/drivers/i2c/busses/i2c-scmi.c
index dfc98df7b1b6..7aa7b9cb6203 100644
--- a/drivers/i2c/busses/i2c-scmi.c
+++ b/drivers/i2c/busses/i2c-scmi.c
@@ -18,6 +18,9 @@
18#define ACPI_SMBUS_HC_CLASS "smbus" 18#define ACPI_SMBUS_HC_CLASS "smbus"
19#define ACPI_SMBUS_HC_DEVICE_NAME "cmi" 19#define ACPI_SMBUS_HC_DEVICE_NAME "cmi"
20 20
21/* SMBUS HID definition as supported by Microsoft Windows */
22#define ACPI_SMBUS_MS_HID "SMB0001"
23
21ACPI_MODULE_NAME("smbus_cmi"); 24ACPI_MODULE_NAME("smbus_cmi");
22 25
23struct smbus_methods_t { 26struct smbus_methods_t {
@@ -51,6 +54,7 @@ static const struct smbus_methods_t ibm_smbus_methods = {
51static const struct acpi_device_id acpi_smbus_cmi_ids[] = { 54static const struct acpi_device_id acpi_smbus_cmi_ids[] = {
52 {"SMBUS01", (kernel_ulong_t)&smbus_methods}, 55 {"SMBUS01", (kernel_ulong_t)&smbus_methods},
53 {ACPI_SMBUS_IBM_HID, (kernel_ulong_t)&ibm_smbus_methods}, 56 {ACPI_SMBUS_IBM_HID, (kernel_ulong_t)&ibm_smbus_methods},
57 {ACPI_SMBUS_MS_HID, (kernel_ulong_t)&smbus_methods},
54 {"", 0} 58 {"", 0}
55}; 59};
56MODULE_DEVICE_TABLE(acpi, acpi_smbus_cmi_ids); 60MODULE_DEVICE_TABLE(acpi, acpi_smbus_cmi_ids);
diff --git a/drivers/i2c/busses/i2c-tegra-bpmp.c b/drivers/i2c/busses/i2c-tegra-bpmp.c
index 9eed69d5e17e..f6cd35d0a2ac 100644
--- a/drivers/i2c/busses/i2c-tegra-bpmp.c
+++ b/drivers/i2c/busses/i2c-tegra-bpmp.c
@@ -340,7 +340,7 @@ static struct platform_driver tegra_bpmp_i2c_driver = {
340}; 340};
341module_platform_driver(tegra_bpmp_i2c_driver); 341module_platform_driver(tegra_bpmp_i2c_driver);
342 342
343MODULE_DESCRIPTION("NVIDIA Tegra BPMP I2C bus contoller driver"); 343MODULE_DESCRIPTION("NVIDIA Tegra BPMP I2C bus controller driver");
344MODULE_AUTHOR("Shardar Shariff Md <smohammed@nvidia.com>"); 344MODULE_AUTHOR("Shardar Shariff Md <smohammed@nvidia.com>");
345MODULE_AUTHOR("Juha-Matti Tilli"); 345MODULE_AUTHOR("Juha-Matti Tilli");
346MODULE_LICENSE("GPL v2"); 346MODULE_LICENSE("GPL v2");
diff --git a/drivers/i2c/busses/i2c-thunderx-pcidrv.c b/drivers/i2c/busses/i2c-thunderx-pcidrv.c
index 1d4c2beacf2e..ea35a895b568 100644
--- a/drivers/i2c/busses/i2c-thunderx-pcidrv.c
+++ b/drivers/i2c/busses/i2c-thunderx-pcidrv.c
@@ -85,17 +85,23 @@ static void thunder_i2c_clock_enable(struct device *dev, struct octeon_i2c *i2c)
85{ 85{
86 int ret; 86 int ret;
87 87
88 i2c->clk = clk_get(dev, NULL); 88 if (acpi_disabled) {
89 if (IS_ERR(i2c->clk)) { 89 /* DT */
90 i2c->clk = NULL; 90 i2c->clk = clk_get(dev, NULL);
91 goto skip; 91 if (IS_ERR(i2c->clk)) {
92 i2c->clk = NULL;
93 goto skip;
94 }
95
96 ret = clk_prepare_enable(i2c->clk);
97 if (ret)
98 goto skip;
99 i2c->sys_freq = clk_get_rate(i2c->clk);
100 } else {
101 /* ACPI */
102 device_property_read_u32(dev, "sclk", &i2c->sys_freq);
92 } 103 }
93 104
94 ret = clk_prepare_enable(i2c->clk);
95 if (ret)
96 goto skip;
97 i2c->sys_freq = clk_get_rate(i2c->clk);
98
99skip: 105skip:
100 if (!i2c->sys_freq) 106 if (!i2c->sys_freq)
101 i2c->sys_freq = SYS_FREQ_DEFAULT; 107 i2c->sys_freq = SYS_FREQ_DEFAULT;
@@ -205,6 +211,7 @@ static int thunder_i2c_probe_pci(struct pci_dev *pdev,
205 211
206 i2c->adap = thunderx_i2c_ops; 212 i2c->adap = thunderx_i2c_ops;
207 i2c->adap.retries = 5; 213 i2c->adap.retries = 5;
214 i2c->adap.class = I2C_CLASS_HWMON;
208 i2c->adap.bus_recovery_info = &octeon_i2c_recovery_info; 215 i2c->adap.bus_recovery_info = &octeon_i2c_recovery_info;
209 i2c->adap.dev.parent = dev; 216 i2c->adap.dev.parent = dev;
210 i2c->adap.dev.of_node = pdev->dev.of_node; 217 i2c->adap.dev.of_node = pdev->dev.of_node;
diff --git a/drivers/i2c/busses/i2c-xlp9xx.c b/drivers/i2c/busses/i2c-xlp9xx.c
index 66b464d52c9c..ae80228104e9 100644
--- a/drivers/i2c/busses/i2c-xlp9xx.c
+++ b/drivers/i2c/busses/i2c-xlp9xx.c
@@ -432,6 +432,7 @@ MODULE_DEVICE_TABLE(of, xlp9xx_i2c_of_match);
432#ifdef CONFIG_ACPI 432#ifdef CONFIG_ACPI
433static const struct acpi_device_id xlp9xx_i2c_acpi_ids[] = { 433static const struct acpi_device_id xlp9xx_i2c_acpi_ids[] = {
434 {"BRCM9007", 0}, 434 {"BRCM9007", 0},
435 {"CAV9007", 0},
435 {} 436 {}
436}; 437};
437MODULE_DEVICE_TABLE(acpi, xlp9xx_i2c_acpi_ids); 438MODULE_DEVICE_TABLE(acpi, xlp9xx_i2c_acpi_ids);
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index d2402bbf6729..7a065c4260f3 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -112,6 +112,8 @@ struct i2c_acpi_lookup {
112 acpi_handle adapter_handle; 112 acpi_handle adapter_handle;
113 acpi_handle device_handle; 113 acpi_handle device_handle;
114 acpi_handle search_handle; 114 acpi_handle search_handle;
115 int n;
116 int index;
115 u32 speed; 117 u32 speed;
116 u32 min_speed; 118 u32 min_speed;
117}; 119};
@@ -130,6 +132,9 @@ static int i2c_acpi_fill_info(struct acpi_resource *ares, void *data)
130 if (sb->type != ACPI_RESOURCE_SERIAL_TYPE_I2C) 132 if (sb->type != ACPI_RESOURCE_SERIAL_TYPE_I2C)
131 return 1; 133 return 1;
132 134
135 if (lookup->index != -1 && lookup->n++ != lookup->index)
136 return 1;
137
133 status = acpi_get_handle(lookup->device_handle, 138 status = acpi_get_handle(lookup->device_handle,
134 sb->resource_source.string_ptr, 139 sb->resource_source.string_ptr,
135 &lookup->adapter_handle); 140 &lookup->adapter_handle);
@@ -182,6 +187,7 @@ static int i2c_acpi_get_info(struct acpi_device *adev,
182 187
183 memset(&lookup, 0, sizeof(lookup)); 188 memset(&lookup, 0, sizeof(lookup));
184 lookup.info = info; 189 lookup.info = info;
190 lookup.index = -1;
185 191
186 ret = i2c_acpi_do_lookup(adev, &lookup); 192 ret = i2c_acpi_do_lookup(adev, &lookup);
187 if (ret) 193 if (ret)
@@ -328,6 +334,7 @@ u32 i2c_acpi_find_bus_speed(struct device *dev)
328 lookup.search_handle = ACPI_HANDLE(dev); 334 lookup.search_handle = ACPI_HANDLE(dev);
329 lookup.min_speed = UINT_MAX; 335 lookup.min_speed = UINT_MAX;
330 lookup.info = &dummy; 336 lookup.info = &dummy;
337 lookup.index = -1;
331 338
332 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, 339 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
333 I2C_ACPI_MAX_SCAN_DEPTH, 340 I2C_ACPI_MAX_SCAN_DEPTH,
@@ -414,6 +421,55 @@ static int i2c_acpi_notify(struct notifier_block *nb, unsigned long value,
414static struct notifier_block i2c_acpi_notifier = { 421static struct notifier_block i2c_acpi_notifier = {
415 .notifier_call = i2c_acpi_notify, 422 .notifier_call = i2c_acpi_notify,
416}; 423};
424
425/**
426 * i2c_acpi_new_device - Create i2c-client for the Nth I2cSerialBus resource
427 * @dev: Device owning the ACPI resources to get the client from
428 * @index: Index of ACPI resource to get
429 * @info: describes the I2C device; note this is modified (addr gets set)
430 * Context: can sleep
431 *
432 * By default the i2c subsys creates an i2c-client for the first I2cSerialBus
433 * resource of an acpi_device, but some acpi_devices have multiple I2cSerialBus
434 * resources, in that case this function can be used to create an i2c-client
435 * for other I2cSerialBus resources in the Current Resource Settings table.
436 *
437 * Also see i2c_new_device, which this function calls to create the i2c-client.
438 *
439 * Returns a pointer to the new i2c-client, or NULL if the adapter is not found.
440 */
441struct i2c_client *i2c_acpi_new_device(struct device *dev, int index,
442 struct i2c_board_info *info)
443{
444 struct i2c_acpi_lookup lookup;
445 struct i2c_adapter *adapter;
446 struct acpi_device *adev;
447 LIST_HEAD(resource_list);
448 int ret;
449
450 adev = ACPI_COMPANION(dev);
451 if (!adev)
452 return NULL;
453
454 memset(&lookup, 0, sizeof(lookup));
455 lookup.info = info;
456 lookup.device_handle = acpi_device_handle(adev);
457 lookup.index = index;
458
459 ret = acpi_dev_get_resources(adev, &resource_list,
460 i2c_acpi_fill_info, &lookup);
461 acpi_dev_free_resource_list(&resource_list);
462
463 if (ret < 0 || !info->addr)
464 return NULL;
465
466 adapter = i2c_acpi_find_adapter_by_handle(lookup.adapter_handle);
467 if (!adapter)
468 return NULL;
469
470 return i2c_new_device(adapter, info);
471}
472EXPORT_SYMBOL_GPL(i2c_acpi_new_device);
417#else /* CONFIG_ACPI */ 473#else /* CONFIG_ACPI */
418static inline void i2c_acpi_register_devices(struct i2c_adapter *adap) { } 474static inline void i2c_acpi_register_devices(struct i2c_adapter *adap) { }
419extern struct notifier_block i2c_acpi_notifier; 475extern struct notifier_block i2c_acpi_notifier;
@@ -929,7 +985,9 @@ static int i2c_device_probe(struct device *dev)
929 if (!client) 985 if (!client)
930 return 0; 986 return 0;
931 987
932 if (!client->irq) { 988 driver = to_i2c_driver(dev->driver);
989
990 if (!client->irq && !driver->disable_i2c_core_irq_mapping) {
933 int irq = -ENOENT; 991 int irq = -ENOENT;
934 992
935 if (client->flags & I2C_CLIENT_HOST_NOTIFY) { 993 if (client->flags & I2C_CLIENT_HOST_NOTIFY) {
@@ -951,8 +1009,6 @@ static int i2c_device_probe(struct device *dev)
951 client->irq = irq; 1009 client->irq = irq;
952 } 1010 }
953 1011
954 driver = to_i2c_driver(dev->driver);
955
956 /* 1012 /*
957 * An I2C ID table is not mandatory, if and only if, a suitable Device 1013 * An I2C ID table is not mandatory, if and only if, a suitable Device
958 * Tree match table entry is supplied for the probing device. 1014 * Tree match table entry is supplied for the probing device.
diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
index 2178266bca79..26f7237558ba 100644
--- a/drivers/i2c/i2c-mux.c
+++ b/drivers/i2c/i2c-mux.c
@@ -395,13 +395,16 @@ int i2c_mux_add_adapter(struct i2c_mux_core *muxc,
395 if (force_nr) { 395 if (force_nr) {
396 priv->adap.nr = force_nr; 396 priv->adap.nr = force_nr;
397 ret = i2c_add_numbered_adapter(&priv->adap); 397 ret = i2c_add_numbered_adapter(&priv->adap);
398 dev_err(&parent->dev,
399 "failed to add mux-adapter %u as bus %u (error=%d)\n",
400 chan_id, force_nr, ret);
398 } else { 401 } else {
399 ret = i2c_add_adapter(&priv->adap); 402 ret = i2c_add_adapter(&priv->adap);
403 dev_err(&parent->dev,
404 "failed to add mux-adapter %u (error=%d)\n",
405 chan_id, ret);
400 } 406 }
401 if (ret < 0) { 407 if (ret < 0) {
402 dev_err(&parent->dev,
403 "failed to add mux-adapter (error=%d)\n",
404 ret);
405 kfree(priv); 408 kfree(priv);
406 return ret; 409 return ret;
407 } 410 }
diff --git a/drivers/i2c/muxes/Kconfig b/drivers/i2c/muxes/Kconfig
index 10b3d17ae3ea..1e160fc37ecc 100644
--- a/drivers/i2c/muxes/Kconfig
+++ b/drivers/i2c/muxes/Kconfig
@@ -30,6 +30,17 @@ config I2C_MUX_GPIO
30 This driver can also be built as a module. If so, the module 30 This driver can also be built as a module. If so, the module
31 will be called i2c-mux-gpio. 31 will be called i2c-mux-gpio.
32 32
33config I2C_MUX_LTC4306
34 tristate "LTC LTC4306/5 I2C multiplexer"
35 select GPIOLIB
36 select REGMAP_I2C
37 help
38 If you say yes here you get support for the Analog Devices
39 LTC4306 or LTC4305 I2C mux/switch devices.
40
41 This driver can also be built as a module. If so, the module
42 will be called i2c-mux-ltc4306.
43
33config I2C_MUX_PCA9541 44config I2C_MUX_PCA9541
34 tristate "NXP PCA9541 I2C Master Selector" 45 tristate "NXP PCA9541 I2C Master Selector"
35 help 46 help
diff --git a/drivers/i2c/muxes/Makefile b/drivers/i2c/muxes/Makefile
index 9948fa45037f..ff7618cd5312 100644
--- a/drivers/i2c/muxes/Makefile
+++ b/drivers/i2c/muxes/Makefile
@@ -6,6 +6,7 @@ obj-$(CONFIG_I2C_ARB_GPIO_CHALLENGE) += i2c-arb-gpio-challenge.o
6obj-$(CONFIG_I2C_DEMUX_PINCTRL) += i2c-demux-pinctrl.o 6obj-$(CONFIG_I2C_DEMUX_PINCTRL) += i2c-demux-pinctrl.o
7 7
8obj-$(CONFIG_I2C_MUX_GPIO) += i2c-mux-gpio.o 8obj-$(CONFIG_I2C_MUX_GPIO) += i2c-mux-gpio.o
9obj-$(CONFIG_I2C_MUX_LTC4306) += i2c-mux-ltc4306.o
9obj-$(CONFIG_I2C_MUX_MLXCPLD) += i2c-mux-mlxcpld.o 10obj-$(CONFIG_I2C_MUX_MLXCPLD) += i2c-mux-mlxcpld.o
10obj-$(CONFIG_I2C_MUX_PCA9541) += i2c-mux-pca9541.o 11obj-$(CONFIG_I2C_MUX_PCA9541) += i2c-mux-pca9541.o
11obj-$(CONFIG_I2C_MUX_PCA954x) += i2c-mux-pca954x.o 12obj-$(CONFIG_I2C_MUX_PCA954x) += i2c-mux-pca954x.o
diff --git a/drivers/i2c/muxes/i2c-arb-gpio-challenge.c b/drivers/i2c/muxes/i2c-arb-gpio-challenge.c
index 86fc2d4c081b..812b8cff265f 100644
--- a/drivers/i2c/muxes/i2c-arb-gpio-challenge.c
+++ b/drivers/i2c/muxes/i2c-arb-gpio-challenge.c
@@ -202,10 +202,8 @@ static int i2c_arbitrator_probe(struct platform_device *pdev)
202 202
203 /* Actually add the mux adapter */ 203 /* Actually add the mux adapter */
204 ret = i2c_mux_add_adapter(muxc, 0, 0, 0); 204 ret = i2c_mux_add_adapter(muxc, 0, 0, 0);
205 if (ret) { 205 if (ret)
206 dev_err(dev, "Failed to add adapter\n");
207 i2c_put_adapter(muxc->parent); 206 i2c_put_adapter(muxc->parent);
208 }
209 207
210 return ret; 208 return ret;
211} 209}
diff --git a/drivers/i2c/muxes/i2c-mux-gpio.c b/drivers/i2c/muxes/i2c-mux-gpio.c
index 655684d621a4..1a9973ede443 100644
--- a/drivers/i2c/muxes/i2c-mux-gpio.c
+++ b/drivers/i2c/muxes/i2c-mux-gpio.c
@@ -245,10 +245,8 @@ static int i2c_mux_gpio_probe(struct platform_device *pdev)
245 unsigned int class = mux->data.classes ? mux->data.classes[i] : 0; 245 unsigned int class = mux->data.classes ? mux->data.classes[i] : 0;
246 246
247 ret = i2c_mux_add_adapter(muxc, nr, mux->data.values[i], class); 247 ret = i2c_mux_add_adapter(muxc, nr, mux->data.values[i], class);
248 if (ret) { 248 if (ret)
249 dev_err(&pdev->dev, "Failed to add adapter %d\n", i);
250 goto add_adapter_failed; 249 goto add_adapter_failed;
251 }
252 } 250 }
253 251
254 dev_info(&pdev->dev, "%d port mux on %s adapter\n", 252 dev_info(&pdev->dev, "%d port mux on %s adapter\n",
diff --git a/drivers/i2c/muxes/i2c-mux-ltc4306.c b/drivers/i2c/muxes/i2c-mux-ltc4306.c
new file mode 100644
index 000000000000..311b1cced0c0
--- /dev/null
+++ b/drivers/i2c/muxes/i2c-mux-ltc4306.c
@@ -0,0 +1,322 @@
1/*
2 * Linear Technology LTC4306 and LTC4305 I2C multiplexer/switch
3 *
4 * Copyright (C) 2017 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2.
7 *
8 * Based on: i2c-mux-pca954x.c
9 *
10 * Datasheet: http://cds.linear.com/docs/en/datasheet/4306.pdf
11 */
12
13#include <linux/gpio/consumer.h>
14#include <linux/gpio/driver.h>
15#include <linux/i2c-mux.h>
16#include <linux/i2c.h>
17#include <linux/module.h>
18#include <linux/of.h>
19#include <linux/of_device.h>
20#include <linux/property.h>
21#include <linux/regmap.h>
22#include <linux/slab.h>
23
24#define LTC4305_MAX_NCHANS 2
25#define LTC4306_MAX_NCHANS 4
26
27#define LTC_REG_STATUS 0x0
28#define LTC_REG_CONFIG 0x1
29#define LTC_REG_MODE 0x2
30#define LTC_REG_SWITCH 0x3
31
32#define LTC_DOWNSTREAM_ACCL_EN BIT(6)
33#define LTC_UPSTREAM_ACCL_EN BIT(7)
34
35#define LTC_GPIO_ALL_INPUT 0xC0
36#define LTC_SWITCH_MASK 0xF0
37
38enum ltc_type {
39 ltc_4305,
40 ltc_4306,
41};
42
43struct chip_desc {
44 u8 nchans;
45 u8 num_gpios;
46};
47
48struct ltc4306 {
49 struct regmap *regmap;
50 struct gpio_chip gpiochip;
51 const struct chip_desc *chip;
52};
53
54static const struct chip_desc chips[] = {
55 [ltc_4305] = {
56 .nchans = LTC4305_MAX_NCHANS,
57 },
58 [ltc_4306] = {
59 .nchans = LTC4306_MAX_NCHANS,
60 .num_gpios = 2,
61 },
62};
63
64static bool ltc4306_is_volatile_reg(struct device *dev, unsigned int reg)
65{
66 return (reg == LTC_REG_CONFIG) ? true : false;
67}
68
69static const struct regmap_config ltc4306_regmap_config = {
70 .reg_bits = 8,
71 .val_bits = 8,
72 .max_register = LTC_REG_SWITCH,
73 .volatile_reg = ltc4306_is_volatile_reg,
74 .cache_type = REGCACHE_FLAT,
75};
76
77static int ltc4306_gpio_get(struct gpio_chip *chip, unsigned int offset)
78{
79 struct ltc4306 *data = gpiochip_get_data(chip);
80 unsigned int val;
81 int ret;
82
83 ret = regmap_read(data->regmap, LTC_REG_CONFIG, &val);
84 if (ret < 0)
85 return ret;
86
87 return !!(val & BIT(1 - offset));
88}
89
90static void ltc4306_gpio_set(struct gpio_chip *chip, unsigned int offset,
91 int value)
92{
93 struct ltc4306 *data = gpiochip_get_data(chip);
94
95 regmap_update_bits(data->regmap, LTC_REG_CONFIG, BIT(5 - offset),
96 value ? BIT(5 - offset) : 0);
97}
98
99static int ltc4306_gpio_get_direction(struct gpio_chip *chip,
100 unsigned int offset)
101{
102 struct ltc4306 *data = gpiochip_get_data(chip);
103 unsigned int val;
104 int ret;
105
106 ret = regmap_read(data->regmap, LTC_REG_MODE, &val);
107 if (ret < 0)
108 return ret;
109
110 return !!(val & BIT(7 - offset));
111}
112
113static int ltc4306_gpio_direction_input(struct gpio_chip *chip,
114 unsigned int offset)
115{
116 struct ltc4306 *data = gpiochip_get_data(chip);
117
118 return regmap_update_bits(data->regmap, LTC_REG_MODE,
119 BIT(7 - offset), BIT(7 - offset));
120}
121
122static int ltc4306_gpio_direction_output(struct gpio_chip *chip,
123 unsigned int offset, int value)
124{
125 struct ltc4306 *data = gpiochip_get_data(chip);
126
127 ltc4306_gpio_set(chip, offset, value);
128 return regmap_update_bits(data->regmap, LTC_REG_MODE,
129 BIT(7 - offset), 0);
130}
131
132static int ltc4306_gpio_set_config(struct gpio_chip *chip,
133 unsigned int offset, unsigned long config)
134{
135 struct ltc4306 *data = gpiochip_get_data(chip);
136 unsigned int val;
137
138 switch (pinconf_to_config_param(config)) {
139 case PIN_CONFIG_DRIVE_OPEN_DRAIN:
140 val = 0;
141 break;
142 case PIN_CONFIG_DRIVE_PUSH_PULL:
143 val = BIT(4 - offset);
144 break;
145 default:
146 return -ENOTSUPP;
147 }
148
149 return regmap_update_bits(data->regmap, LTC_REG_MODE,
150 BIT(4 - offset), val);
151}
152
153static int ltc4306_gpio_init(struct ltc4306 *data)
154{
155 struct device *dev = regmap_get_device(data->regmap);
156
157 if (!data->chip->num_gpios)
158 return 0;
159
160 data->gpiochip.label = dev_name(dev);
161 data->gpiochip.base = -1;
162 data->gpiochip.ngpio = data->chip->num_gpios;
163 data->gpiochip.parent = dev;
164 data->gpiochip.can_sleep = true;
165 data->gpiochip.get_direction = ltc4306_gpio_get_direction;
166 data->gpiochip.direction_input = ltc4306_gpio_direction_input;
167 data->gpiochip.direction_output = ltc4306_gpio_direction_output;
168 data->gpiochip.get = ltc4306_gpio_get;
169 data->gpiochip.set = ltc4306_gpio_set;
170 data->gpiochip.set_config = ltc4306_gpio_set_config;
171 data->gpiochip.owner = THIS_MODULE;
172
173 /* gpiolib assumes all GPIOs default input */
174 regmap_write(data->regmap, LTC_REG_MODE, LTC_GPIO_ALL_INPUT);
175
176 return devm_gpiochip_add_data(dev, &data->gpiochip, data);
177}
178
179static int ltc4306_select_mux(struct i2c_mux_core *muxc, u32 chan)
180{
181 struct ltc4306 *data = i2c_mux_priv(muxc);
182
183 return regmap_update_bits(data->regmap, LTC_REG_SWITCH,
184 LTC_SWITCH_MASK, BIT(7 - chan));
185}
186
187static int ltc4306_deselect_mux(struct i2c_mux_core *muxc, u32 chan)
188{
189 struct ltc4306 *data = i2c_mux_priv(muxc);
190
191 return regmap_update_bits(data->regmap, LTC_REG_SWITCH,
192 LTC_SWITCH_MASK, 0);
193}
194
195static const struct i2c_device_id ltc4306_id[] = {
196 { "ltc4305", ltc_4305 },
197 { "ltc4306", ltc_4306 },
198 { }
199};
200MODULE_DEVICE_TABLE(i2c, ltc4306_id);
201
202static const struct of_device_id ltc4306_of_match[] = {
203 { .compatible = "lltc,ltc4305", .data = &chips[ltc_4305] },
204 { .compatible = "lltc,ltc4306", .data = &chips[ltc_4306] },
205 { }
206};
207MODULE_DEVICE_TABLE(of, ltc4306_of_match);
208
209static int ltc4306_probe(struct i2c_client *client,
210 const struct i2c_device_id *id)
211{
212 struct i2c_adapter *adap = to_i2c_adapter(client->dev.parent);
213 const struct chip_desc *chip;
214 struct i2c_mux_core *muxc;
215 struct ltc4306 *data;
216 struct gpio_desc *gpio;
217 bool idle_disc;
218 unsigned int val = 0;
219 int num, ret;
220
221 chip = of_device_get_match_data(&client->dev);
222
223 if (!chip)
224 chip = &chips[id->driver_data];
225
226 idle_disc = device_property_read_bool(&client->dev,
227 "i2c-mux-idle-disconnect");
228
229 muxc = i2c_mux_alloc(adap, &client->dev,
230 chip->nchans, sizeof(*data),
231 I2C_MUX_LOCKED, ltc4306_select_mux,
232 idle_disc ? ltc4306_deselect_mux : NULL);
233 if (!muxc)
234 return -ENOMEM;
235 data = i2c_mux_priv(muxc);
236 data->chip = chip;
237
238 i2c_set_clientdata(client, muxc);
239
240 data->regmap = devm_regmap_init_i2c(client, &ltc4306_regmap_config);
241 if (IS_ERR(data->regmap)) {
242 ret = PTR_ERR(data->regmap);
243 dev_err(&client->dev, "Failed to allocate register map: %d\n",
244 ret);
245 return ret;
246 }
247
248 /* Reset and enable the mux if an enable GPIO is specified. */
249 gpio = devm_gpiod_get_optional(&client->dev, "enable", GPIOD_OUT_LOW);
250 if (IS_ERR(gpio))
251 return PTR_ERR(gpio);
252
253 if (gpio) {
254 udelay(1);
255 gpiod_set_value(gpio, 1);
256 }
257
258 /*
259 * Write the mux register at addr to verify
260 * that the mux is in fact present. This also
261 * initializes the mux to disconnected state.
262 */
263 if (regmap_write(data->regmap, LTC_REG_SWITCH, 0) < 0) {
264 dev_warn(&client->dev, "probe failed\n");
265 return -ENODEV;
266 }
267
268 if (device_property_read_bool(&client->dev,
269 "ltc,downstream-accelerators-enable"))
270 val |= LTC_DOWNSTREAM_ACCL_EN;
271
272 if (device_property_read_bool(&client->dev,
273 "ltc,upstream-accelerators-enable"))
274 val |= LTC_UPSTREAM_ACCL_EN;
275
276 if (regmap_write(data->regmap, LTC_REG_CONFIG, val) < 0)
277 return -ENODEV;
278
279 ret = ltc4306_gpio_init(data);
280 if (ret < 0)
281 return ret;
282
283 /* Now create an adapter for each channel */
284 for (num = 0; num < chip->nchans; num++) {
285 ret = i2c_mux_add_adapter(muxc, 0, num, 0);
286 if (ret) {
287 i2c_mux_del_adapters(muxc);
288 return ret;
289 }
290 }
291
292 dev_info(&client->dev,
293 "registered %d multiplexed busses for I2C switch %s\n",
294 num, client->name);
295
296 return 0;
297}
298
299static int ltc4306_remove(struct i2c_client *client)
300{
301 struct i2c_mux_core *muxc = i2c_get_clientdata(client);
302
303 i2c_mux_del_adapters(muxc);
304
305 return 0;
306}
307
308static struct i2c_driver ltc4306_driver = {
309 .driver = {
310 .name = "ltc4306",
311 .of_match_table = of_match_ptr(ltc4306_of_match),
312 },
313 .probe = ltc4306_probe,
314 .remove = ltc4306_remove,
315 .id_table = ltc4306_id,
316};
317
318module_i2c_driver(ltc4306_driver);
319
320MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
321MODULE_DESCRIPTION("Linear Technology LTC4306, LTC4305 I2C mux/switch driver");
322MODULE_LICENSE("GPL v2");
diff --git a/drivers/i2c/muxes/i2c-mux-pca9541.c b/drivers/i2c/muxes/i2c-mux-pca9541.c
index 77840f7845a1..9e318c9516c7 100644
--- a/drivers/i2c/muxes/i2c-mux-pca9541.c
+++ b/drivers/i2c/muxes/i2c-mux-pca9541.c
@@ -369,10 +369,8 @@ static int pca9541_probe(struct i2c_client *client,
369 i2c_set_clientdata(client, muxc); 369 i2c_set_clientdata(client, muxc);
370 370
371 ret = i2c_mux_add_adapter(muxc, force, 0, 0); 371 ret = i2c_mux_add_adapter(muxc, force, 0, 0);
372 if (ret) { 372 if (ret)
373 dev_err(&client->dev, "failed to register master selector\n");
374 return ret; 373 return ret;
375 }
376 374
377 dev_info(&client->dev, "registered master selector for I2C %s\n", 375 dev_info(&client->dev, "registered master selector for I2C %s\n",
378 client->name); 376 client->name);
diff --git a/drivers/i2c/muxes/i2c-mux-pca954x.c b/drivers/i2c/muxes/i2c-mux-pca954x.c
index ad31d21da316..f1751c290af6 100644
--- a/drivers/i2c/muxes/i2c-mux-pca954x.c
+++ b/drivers/i2c/muxes/i2c-mux-pca954x.c
@@ -84,7 +84,7 @@ struct pca954x {
84 84
85 struct irq_domain *irq; 85 struct irq_domain *irq;
86 unsigned int irq_mask; 86 unsigned int irq_mask;
87 spinlock_t lock; 87 raw_spinlock_t lock;
88}; 88};
89 89
90/* Provide specs for the PCA954x types we know about */ 90/* Provide specs for the PCA954x types we know about */
@@ -252,13 +252,13 @@ static void pca954x_irq_mask(struct irq_data *idata)
252 unsigned int pos = idata->hwirq; 252 unsigned int pos = idata->hwirq;
253 unsigned long flags; 253 unsigned long flags;
254 254
255 spin_lock_irqsave(&data->lock, flags); 255 raw_spin_lock_irqsave(&data->lock, flags);
256 256
257 data->irq_mask &= ~BIT(pos); 257 data->irq_mask &= ~BIT(pos);
258 if (!data->irq_mask) 258 if (!data->irq_mask)
259 disable_irq(data->client->irq); 259 disable_irq(data->client->irq);
260 260
261 spin_unlock_irqrestore(&data->lock, flags); 261 raw_spin_unlock_irqrestore(&data->lock, flags);
262} 262}
263 263
264static void pca954x_irq_unmask(struct irq_data *idata) 264static void pca954x_irq_unmask(struct irq_data *idata)
@@ -267,13 +267,13 @@ static void pca954x_irq_unmask(struct irq_data *idata)
267 unsigned int pos = idata->hwirq; 267 unsigned int pos = idata->hwirq;
268 unsigned long flags; 268 unsigned long flags;
269 269
270 spin_lock_irqsave(&data->lock, flags); 270 raw_spin_lock_irqsave(&data->lock, flags);
271 271
272 if (!data->irq_mask) 272 if (!data->irq_mask)
273 enable_irq(data->client->irq); 273 enable_irq(data->client->irq);
274 data->irq_mask |= BIT(pos); 274 data->irq_mask |= BIT(pos);
275 275
276 spin_unlock_irqrestore(&data->lock, flags); 276 raw_spin_unlock_irqrestore(&data->lock, flags);
277} 277}
278 278
279static int pca954x_irq_set_type(struct irq_data *idata, unsigned int type) 279static int pca954x_irq_set_type(struct irq_data *idata, unsigned int type)
@@ -299,7 +299,7 @@ static int pca954x_irq_setup(struct i2c_mux_core *muxc)
299 if (!data->chip->has_irq || client->irq <= 0) 299 if (!data->chip->has_irq || client->irq <= 0)
300 return 0; 300 return 0;
301 301
302 spin_lock_init(&data->lock); 302 raw_spin_lock_init(&data->lock);
303 303
304 data->irq = irq_domain_add_linear(client->dev.of_node, 304 data->irq = irq_domain_add_linear(client->dev.of_node,
305 data->chip->nchans, 305 data->chip->nchans,
@@ -413,13 +413,8 @@ static int pca954x_probe(struct i2c_client *client,
413 idle_disconnect_dt) << num; 413 idle_disconnect_dt) << num;
414 414
415 ret = i2c_mux_add_adapter(muxc, force, num, class); 415 ret = i2c_mux_add_adapter(muxc, force, num, class);
416 416 if (ret)
417 if (ret) {
418 dev_err(&client->dev,
419 "failed to register multiplexed adapter"
420 " %d as bus %d\n", num, force);
421 goto fail_del_adapters; 417 goto fail_del_adapters;
422 }
423 } 418 }
424 419
425 dev_info(&client->dev, 420 dev_info(&client->dev,
diff --git a/drivers/i2c/muxes/i2c-mux-pinctrl.c b/drivers/i2c/muxes/i2c-mux-pinctrl.c
index 35bb775e1b74..7c0c264b07bc 100644
--- a/drivers/i2c/muxes/i2c-mux-pinctrl.c
+++ b/drivers/i2c/muxes/i2c-mux-pinctrl.c
@@ -245,10 +245,8 @@ static int i2c_mux_pinctrl_probe(struct platform_device *pdev)
245 (mux->pdata->base_bus_num + i) : 0; 245 (mux->pdata->base_bus_num + i) : 0;
246 246
247 ret = i2c_mux_add_adapter(muxc, bus, i, 0); 247 ret = i2c_mux_add_adapter(muxc, bus, i, 0);
248 if (ret) { 248 if (ret)
249 dev_err(&pdev->dev, "Failed to add adapter %d\n", i);
250 goto err_del_adapter; 249 goto err_del_adapter;
251 }
252 } 250 }
253 251
254 return 0; 252 return 0;
diff --git a/drivers/i2c/muxes/i2c-mux-reg.c b/drivers/i2c/muxes/i2c-mux-reg.c
index c6a90b4a9c62..406d5059072c 100644
--- a/drivers/i2c/muxes/i2c-mux-reg.c
+++ b/drivers/i2c/muxes/i2c-mux-reg.c
@@ -222,10 +222,8 @@ static int i2c_mux_reg_probe(struct platform_device *pdev)
222 class = mux->data.classes ? mux->data.classes[i] : 0; 222 class = mux->data.classes ? mux->data.classes[i] : 0;
223 223
224 ret = i2c_mux_add_adapter(muxc, nr, mux->data.values[i], class); 224 ret = i2c_mux_add_adapter(muxc, nr, mux->data.values[i], class);
225 if (ret) { 225 if (ret)
226 dev_err(&pdev->dev, "Failed to add adapter %d\n", i);
227 goto add_adapter_failed; 226 goto add_adapter_failed;
228 }
229 } 227 }
230 228
231 dev_dbg(&pdev->dev, "%d port mux on %s adapter\n", 229 dev_dbg(&pdev->dev, "%d port mux on %s adapter\n",
diff --git a/drivers/media/usb/cx231xx/cx231xx-i2c.c b/drivers/media/usb/cx231xx/cx231xx-i2c.c
index 35e9acfe63d3..dff514e147da 100644
--- a/drivers/media/usb/cx231xx/cx231xx-i2c.c
+++ b/drivers/media/usb/cx231xx/cx231xx-i2c.c
@@ -576,17 +576,10 @@ int cx231xx_i2c_mux_create(struct cx231xx *dev)
576 576
577int cx231xx_i2c_mux_register(struct cx231xx *dev, int mux_no) 577int cx231xx_i2c_mux_register(struct cx231xx *dev, int mux_no)
578{ 578{
579 int rc; 579 return i2c_mux_add_adapter(dev->muxc,
580 580 0,
581 rc = i2c_mux_add_adapter(dev->muxc, 581 mux_no /* chan_id */,
582 0, 582 0 /* class */);
583 mux_no /* chan_id */,
584 0 /* class */);
585 if (rc)
586 dev_warn(dev->dev,
587 "i2c mux %d register FAILED\n", mux_no);
588
589 return rc;
590} 583}
591 584
592void cx231xx_i2c_mux_unregister(struct cx231xx *dev) 585void cx231xx_i2c_mux_unregister(struct cx231xx *dev)
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 6b183521c616..3a57e3dc9bec 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -149,6 +149,7 @@ enum i2c_alert_protocol {
149 * @detect: Callback for device detection 149 * @detect: Callback for device detection
150 * @address_list: The I2C addresses to probe (for detect) 150 * @address_list: The I2C addresses to probe (for detect)
151 * @clients: List of detected clients we created (for i2c-core use only) 151 * @clients: List of detected clients we created (for i2c-core use only)
152 * @disable_i2c_core_irq_mapping: Tell the i2c-core to not do irq-mapping
152 * 153 *
153 * The driver.owner field should be set to the module owner of this driver. 154 * The driver.owner field should be set to the module owner of this driver.
154 * The driver.name field should be set to the name of this driver. 155 * The driver.name field should be set to the name of this driver.
@@ -212,6 +213,8 @@ struct i2c_driver {
212 int (*detect)(struct i2c_client *, struct i2c_board_info *); 213 int (*detect)(struct i2c_client *, struct i2c_board_info *);
213 const unsigned short *address_list; 214 const unsigned short *address_list;
214 struct list_head clients; 215 struct list_head clients;
216
217 bool disable_i2c_core_irq_mapping;
215}; 218};
216#define to_i2c_driver(d) container_of(d, struct i2c_driver, driver) 219#define to_i2c_driver(d) container_of(d, struct i2c_driver, driver)
217 220
@@ -824,11 +827,18 @@ static inline const struct of_device_id
824 827
825#if IS_ENABLED(CONFIG_ACPI) 828#if IS_ENABLED(CONFIG_ACPI)
826u32 i2c_acpi_find_bus_speed(struct device *dev); 829u32 i2c_acpi_find_bus_speed(struct device *dev);
830struct i2c_client *i2c_acpi_new_device(struct device *dev, int index,
831 struct i2c_board_info *info);
827#else 832#else
828static inline u32 i2c_acpi_find_bus_speed(struct device *dev) 833static inline u32 i2c_acpi_find_bus_speed(struct device *dev)
829{ 834{
830 return 0; 835 return 0;
831} 836}
837static inline struct i2c_client *i2c_acpi_new_device(struct device *dev,
838 int index, struct i2c_board_info *info)
839{
840 return NULL;
841}
832#endif /* CONFIG_ACPI */ 842#endif /* CONFIG_ACPI */
833 843
834#endif /* _LINUX_I2C_H */ 844#endif /* _LINUX_I2C_H */