Skip to content

Commit 5c8db3e

Browse files
committed
Merge branch 'i2c/for-5.7' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux
Pull i2c updates from Wolfram Sang: "I2C has: - using defines for bus speeds to avoid mistakes in hardcoded values; lots of small driver updates because of that. Thanks, Andy! - API change: i2c_setup_smbus_alert() was renamed to i2c_new_smbus_alert_device() and returns ERRPTR now. All in-tree users have been converted - in the core, a rare race condition when deleting the cdev has been fixed. Thanks, Kevin! - lots of driver updates. Thanks, everyone! I also want to mention: The amount of review and testing tags given was quite high this time. Thank you to these people, too. I hope we can keep it like this!" * 'i2c/for-5.7' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux: (34 commits) i2c: rcar: clean up after refactoring i2c_timings macintosh: convert to i2c_new_scanned_device i2c: drivers: Use generic definitions for bus frequencies i2c: algo: Use generic definitions for bus frequencies i2c: stm32f7: switch to I²C generic property parsing i2c: rcar: Consolidate timings calls in rcar_i2c_clock_calculate() i2c: core: Allow override timing properties with 0 i2c: core: Provide generic definitions for bus frequencies i2c: mxs: Use dma_request_chan() instead dma_request_slave_channel() i2c: imx: remove duplicate print after platform_get_irq() i2c: designware: Fix spelling typos in the comments i2c: designware: Discard i2c_dw_read_comp_param() function i2c: designware: Detect the FIFO size in the common code i2c: dev: Fix the race between the release of i2c_dev and cdev i2c: qcom-geni: Drop of_platform.h include i2c: qcom-geni: Grow a dev pointer to simplify code i2c: qcom-geni: Let firmware specify irq trigger flags i2c: stm32f7: do not backup read-only PECR register i2c: smbus: remove outdated references to irq level triggers i2c: convert SMBus alert setup function to return an ERRPTR ...
2 parents 848960e + df576be commit 5c8db3e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+855
-520
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
%YAML 1.2
3+
---
4+
$id: http://devicetree.org/schemas/i2c/brcm,brcmstb-i2c.yaml#
5+
$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+
title: Broadcom STB BSC IIC Master Controller
8+
9+
maintainers:
10+
- Kamal Dasu <[email protected]>
11+
12+
allOf:
13+
- $ref: /schemas/i2c/i2c-controller.yaml#
14+
15+
properties:
16+
compatible:
17+
enum:
18+
- brcm,bcm2711-hdmi-i2c
19+
- brcm,brcmstb-i2c
20+
- brcm,brcmper-i2c
21+
22+
reg:
23+
minItems: 1
24+
maxItems: 2
25+
items:
26+
- description: BSC register range
27+
- description: Auto-I2C register range
28+
29+
reg-names:
30+
items:
31+
- const: bsc
32+
- const: auto-i2c
33+
34+
interrupts:
35+
maxItems: 1
36+
37+
interrupt-names:
38+
maxItems: 1
39+
40+
clock-frequency:
41+
enum:
42+
- 46875
43+
- 50000
44+
- 93750
45+
- 97500
46+
- 187500
47+
- 200000
48+
- 375000
49+
- 390000
50+
51+
required:
52+
- compatible
53+
- reg
54+
- clock-frequency
55+
56+
unevaluatedProperties: false
57+
58+
if:
59+
properties:
60+
compatible:
61+
contains:
62+
enum:
63+
- brcm,bcm2711-hdmi-i2c
64+
65+
then:
66+
properties:
67+
reg:
68+
minItems: 2
69+
70+
required:
71+
- reg-names
72+
73+
else:
74+
properties:
75+
reg:
76+
maxItems: 1
77+
78+
examples:
79+
- |
80+
bsca: i2c@f0406200 {
81+
clock-frequency = <390000>;
82+
compatible = "brcm,brcmstb-i2c";
83+
interrupt-parent = <&irq0_intc>;
84+
reg = <0xf0406200 0x58>;
85+
interrupts = <0x18>;
86+
interrupt-names = "upg_bsca";
87+
};
88+
89+
- |
90+
ddc0: i2c@7ef04500 {
91+
compatible = "brcm,bcm2711-hdmi-i2c";
92+
reg = <0x7ef04500 0x100>, <0x7ef00b00 0x300>;
93+
reg-names = "bsc", "auto-i2c";
94+
clock-frequency = <390000>;
95+
};
96+
97+
...

Documentation/devicetree/bindings/i2c/i2c-at91.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,13 @@ Optional properties:
2828
"atmel,sama5d4-i2c",
2929
"atmel,sama5d2-i2c",
3030
"microchip,sam9x60-i2c".
31+
- scl-gpios: specify the gpio related to SCL pin
32+
- sda-gpios: specify the gpio related to SDA pin
33+
- pinctrl: add extra pinctrl to configure i2c pins to gpio function for i2c
34+
bus recovery, call it "gpio" state
3135
- Child nodes conforming to i2c bus binding
3236

37+
3338
Examples :
3439

3540
i2c0: i2c@fff84000 {
@@ -64,6 +69,11 @@ i2c0: i2c@f8034600 {
6469
clocks = <&flx0>;
6570
atmel,fifo-size = <16>;
6671
i2c-sda-hold-time-ns = <336>;
72+
pinctrl-names = "default", "gpio";
73+
pinctrl-0 = <&pinctrl_i2c0>;
74+
pinctrl-1 = <&pinctrl_i2c0_gpio>;
75+
sda-gpios = <&pioA 30 GPIO_ACTIVE_HIGH>;
76+
scl-gpios = <&pioA 31 GPIO_ACTIVE_HIGH>;
6777

6878
wm8731: wm8731@1a {
6979
compatible = "wm8731";

Documentation/devicetree/bindings/i2c/i2c-brcmstb.txt

Lines changed: 0 additions & 26 deletions
This file was deleted.

Documentation/i2c/smbus-protocol.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ to know which slave triggered the interrupt.
274274
This is implemented the following way in the Linux kernel:
275275

276276
* I2C bus drivers which support SMBus alert should call
277-
i2c_setup_smbus_alert() to setup SMBus alert support.
277+
i2c_new_smbus_alert_device() to install SMBus alert support.
278278
* I2C drivers for devices which can trigger SMBus alerts should implement
279279
the optional alert() callback.
280280

MAINTAINERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3470,7 +3470,7 @@ L: [email protected]
34703470
34713471
S: Supported
34723472
F: drivers/i2c/busses/i2c-brcmstb.c
3473-
F: Documentation/devicetree/bindings/i2c/i2c-brcmstb.txt
3473+
F: Documentation/devicetree/bindings/i2c/brcm,brcmstb-i2c.yaml
34743474

34753475
BROADCOM BRCMSTB USB2 and USB3 PHY DRIVER
34763476
M: Al Cooper <[email protected]>

drivers/i2c/algos/i2c-algo-pca.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,17 +459,17 @@ static int pca_init(struct i2c_adapter *adap)
459459
/* To avoid integer overflow, use clock/100 for calculations */
460460
clock = pca_clock(pca_data) / 100;
461461

462-
if (pca_data->i2c_clock > 1000000) {
462+
if (pca_data->i2c_clock > I2C_MAX_FAST_MODE_PLUS_FREQ) {
463463
mode = I2C_PCA_MODE_TURBO;
464464
min_tlow = 14;
465465
min_thi = 5;
466466
raise_fall_time = 22; /* Raise 11e-8s, Fall 11e-8s */
467-
} else if (pca_data->i2c_clock > 400000) {
467+
} else if (pca_data->i2c_clock > I2C_MAX_FAST_MODE_FREQ) {
468468
mode = I2C_PCA_MODE_FASTP;
469469
min_tlow = 17;
470470
min_thi = 9;
471471
raise_fall_time = 22; /* Raise 11e-8s, Fall 11e-8s */
472-
} else if (pca_data->i2c_clock > 100000) {
472+
} else if (pca_data->i2c_clock > I2C_MAX_STANDARD_MODE_FREQ) {
473473
mode = I2C_PCA_MODE_FAST;
474474
min_tlow = 44;
475475
min_thi = 20;

drivers/i2c/busses/i2c-altera.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ static void altr_i2c_init(struct altr_i2c_dev *idev)
147147
(ALTR_I2C_THRESHOLD << ALTR_I2C_CTRL_TCT_SHFT);
148148
u32 t_high, t_low;
149149

150-
if (idev->bus_clk_rate <= 100000) {
150+
if (idev->bus_clk_rate <= I2C_MAX_STANDARD_MODE_FREQ) {
151151
tmp &= ~ALTR_I2C_CTRL_BSPEED;
152152
/* Standard mode SCL 50/50 */
153153
t_high = divisor * 1 / 2;
@@ -423,10 +423,10 @@ static int altr_i2c_probe(struct platform_device *pdev)
423423
&idev->bus_clk_rate);
424424
if (val) {
425425
dev_err(&pdev->dev, "Default to 100kHz\n");
426-
idev->bus_clk_rate = 100000; /* default clock rate */
426+
idev->bus_clk_rate = I2C_MAX_STANDARD_MODE_FREQ; /* default clock rate */
427427
}
428428

429-
if (idev->bus_clk_rate > 400000) {
429+
if (idev->bus_clk_rate > I2C_MAX_FAST_MODE_FREQ) {
430430
dev_err(&pdev->dev, "invalid clock-frequency %d\n",
431431
idev->bus_clk_rate);
432432
return -EINVAL;

drivers/i2c/busses/i2c-amd-mp2-plat.c

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -201,32 +201,37 @@ static int i2c_amd_resume(struct amd_i2c_common *i2c_common)
201201
}
202202
#endif
203203

204+
static const u32 supported_speeds[] = {
205+
I2C_MAX_HIGH_SPEED_MODE_FREQ,
206+
I2C_MAX_TURBO_MODE_FREQ,
207+
I2C_MAX_FAST_MODE_PLUS_FREQ,
208+
I2C_MAX_FAST_MODE_FREQ,
209+
I2C_MAX_STANDARD_MODE_FREQ,
210+
};
211+
204212
static enum speed_enum i2c_amd_get_bus_speed(struct platform_device *pdev)
205213
{
206214
u32 acpi_speed;
207215
int i;
208-
static const u32 supported_speeds[] = {
209-
0, 100000, 400000, 1000000, 1400000, 3400000
210-
};
211216

212217
acpi_speed = i2c_acpi_find_bus_speed(&pdev->dev);
213218
/* round down to the lowest standard speed */
214-
for (i = 1; i < ARRAY_SIZE(supported_speeds); i++) {
215-
if (acpi_speed < supported_speeds[i])
219+
for (i = 0; i < ARRAY_SIZE(supported_speeds); i++) {
220+
if (acpi_speed >= supported_speeds[i])
216221
break;
217222
}
218-
acpi_speed = supported_speeds[i - 1];
223+
acpi_speed = i < ARRAY_SIZE(supported_speeds) ? supported_speeds[i] : 0;
219224

220225
switch (acpi_speed) {
221-
case 100000:
226+
case I2C_MAX_STANDARD_MODE_FREQ:
222227
return speed100k;
223-
case 400000:
228+
case I2C_MAX_FAST_MODE_FREQ:
224229
return speed400k;
225-
case 1000000:
230+
case I2C_MAX_FAST_MODE_PLUS_FREQ:
226231
return speed1000k;
227-
case 1400000:
232+
case I2C_MAX_TURBO_MODE_FREQ:
228233
return speed1400k;
229-
case 3400000:
234+
case I2C_MAX_HIGH_SPEED_MODE_FREQ:
230235
return speed3400k;
231236
default:
232237
return speed400k;

drivers/i2c/busses/i2c-aspeed.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,7 @@ static int aspeed_i2c_probe_bus(struct platform_device *pdev)
997997
if (ret < 0) {
998998
dev_err(&pdev->dev,
999999
"Could not read bus-frequency property\n");
1000-
bus->bus_frequency = 100000;
1000+
bus->bus_frequency = I2C_MAX_STANDARD_MODE_FREQ;
10011001
}
10021002

10031003
match = of_match_node(aspeed_i2c_bus_of_table, pdev->dev.of_node);

drivers/i2c/busses/i2c-at91-master.c

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818
#include <linux/dma-mapping.h>
1919
#include <linux/dmaengine.h>
2020
#include <linux/err.h>
21+
#include <linux/gpio/consumer.h>
2122
#include <linux/i2c.h>
2223
#include <linux/interrupt.h>
2324
#include <linux/io.h>
2425
#include <linux/of.h>
2526
#include <linux/of_device.h>
27+
#include <linux/pinctrl/consumer.h>
2628
#include <linux/platform_device.h>
2729
#include <linux/platform_data/dma-atmel.h>
2830
#include <linux/pm_runtime.h>
@@ -478,6 +480,7 @@ static int at91_do_twi_transfer(struct at91_twi_dev *dev)
478480
unsigned long time_left;
479481
bool has_unre_flag = dev->pdata->has_unre_flag;
480482
bool has_alt_cmd = dev->pdata->has_alt_cmd;
483+
struct i2c_bus_recovery_info *rinfo = &dev->rinfo;
481484

482485
/*
483486
* WARNING: the TXCOMP bit in the Status Register is NOT a clear on
@@ -637,6 +640,13 @@ static int at91_do_twi_transfer(struct at91_twi_dev *dev)
637640
at91_twi_write(dev, AT91_TWI_CR,
638641
AT91_TWI_THRCLR | AT91_TWI_LOCKCLR);
639642
}
643+
644+
if (rinfo->get_sda && !(rinfo->get_sda(&dev->adapter))) {
645+
dev_dbg(dev->dev,
646+
"SDA is down; clear bus using gpio\n");
647+
i2c_recover_bus(&dev->adapter);
648+
}
649+
640650
return ret;
641651
}
642652

@@ -806,6 +816,70 @@ static int at91_twi_configure_dma(struct at91_twi_dev *dev, u32 phy_addr)
806816
return ret;
807817
}
808818

819+
static void at91_prepare_twi_recovery(struct i2c_adapter *adap)
820+
{
821+
struct at91_twi_dev *dev = i2c_get_adapdata(adap);
822+
823+
pinctrl_select_state(dev->pinctrl, dev->pinctrl_pins_gpio);
824+
}
825+
826+
static void at91_unprepare_twi_recovery(struct i2c_adapter *adap)
827+
{
828+
struct at91_twi_dev *dev = i2c_get_adapdata(adap);
829+
830+
pinctrl_select_state(dev->pinctrl, dev->pinctrl_pins_default);
831+
}
832+
833+
static int at91_init_twi_recovery_info(struct platform_device *pdev,
834+
struct at91_twi_dev *dev)
835+
{
836+
struct i2c_bus_recovery_info *rinfo = &dev->rinfo;
837+
838+
dev->pinctrl = devm_pinctrl_get(&pdev->dev);
839+
if (!dev->pinctrl || IS_ERR(dev->pinctrl)) {
840+
dev_info(dev->dev, "can't get pinctrl, bus recovery not supported\n");
841+
return PTR_ERR(dev->pinctrl);
842+
}
843+
844+
dev->pinctrl_pins_default = pinctrl_lookup_state(dev->pinctrl,
845+
PINCTRL_STATE_DEFAULT);
846+
dev->pinctrl_pins_gpio = pinctrl_lookup_state(dev->pinctrl,
847+
"gpio");
848+
rinfo->sda_gpiod = devm_gpiod_get(&pdev->dev, "sda", GPIOD_IN);
849+
if (PTR_ERR(rinfo->sda_gpiod) == -EPROBE_DEFER)
850+
return -EPROBE_DEFER;
851+
852+
rinfo->scl_gpiod = devm_gpiod_get(&pdev->dev, "scl",
853+
GPIOD_OUT_HIGH_OPEN_DRAIN);
854+
if (PTR_ERR(rinfo->scl_gpiod) == -EPROBE_DEFER)
855+
return -EPROBE_DEFER;
856+
857+
if (IS_ERR(rinfo->sda_gpiod) ||
858+
IS_ERR(rinfo->scl_gpiod) ||
859+
IS_ERR(dev->pinctrl_pins_default) ||
860+
IS_ERR(dev->pinctrl_pins_gpio)) {
861+
dev_info(&pdev->dev, "recovery information incomplete\n");
862+
if (!IS_ERR(rinfo->sda_gpiod)) {
863+
gpiod_put(rinfo->sda_gpiod);
864+
rinfo->sda_gpiod = NULL;
865+
}
866+
if (!IS_ERR(rinfo->scl_gpiod)) {
867+
gpiod_put(rinfo->scl_gpiod);
868+
rinfo->scl_gpiod = NULL;
869+
}
870+
return -EINVAL;
871+
}
872+
873+
dev_info(&pdev->dev, "using scl, sda for recovery\n");
874+
875+
rinfo->prepare_recovery = at91_prepare_twi_recovery;
876+
rinfo->unprepare_recovery = at91_unprepare_twi_recovery;
877+
rinfo->recover_bus = i2c_generic_scl_recovery;
878+
dev->adapter.bus_recovery_info = rinfo;
879+
880+
return 0;
881+
}
882+
809883
int at91_twi_probe_master(struct platform_device *pdev,
810884
u32 phy_addr, struct at91_twi_dev *dev)
811885
{
@@ -838,6 +912,10 @@ int at91_twi_probe_master(struct platform_device *pdev,
838912
"i2c-analog-filter");
839913
at91_calc_twi_clock(dev);
840914

915+
rc = at91_init_twi_recovery_info(pdev, dev);
916+
if (rc == -EPROBE_DEFER)
917+
return rc;
918+
841919
dev->adapter.algo = &at91_twi_algorithm;
842920
dev->adapter.quirks = &at91_twi_quirks;
843921

0 commit comments

Comments
 (0)