Skip to content

Commit

Permalink
Merge branch 'i2c/for-5.7' of git://git.kernel.org/pub/scm/linux/kern…
Browse files Browse the repository at this point in the history
…el/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
  ...
  • Loading branch information
torvalds committed Apr 2, 2020
2 parents 848960e + df576be commit 5c8db3e
Show file tree
Hide file tree
Showing 74 changed files with 855 additions and 520 deletions.
97 changes: 97 additions & 0 deletions Documentation/devicetree/bindings/i2c/brcm,brcmstb-i2c.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# SPDX-License-Identifier: GPL-2.0
%YAML 1.2
---
$id: http://devicetree.org/schemas/i2c/brcm,brcmstb-i2c.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#

title: Broadcom STB BSC IIC Master Controller

maintainers:
- Kamal Dasu <[email protected]>

allOf:
- $ref: /schemas/i2c/i2c-controller.yaml#

properties:
compatible:
enum:
- brcm,bcm2711-hdmi-i2c
- brcm,brcmstb-i2c
- brcm,brcmper-i2c

reg:
minItems: 1
maxItems: 2
items:
- description: BSC register range
- description: Auto-I2C register range

reg-names:
items:
- const: bsc
- const: auto-i2c

interrupts:
maxItems: 1

interrupt-names:
maxItems: 1

clock-frequency:
enum:
- 46875
- 50000
- 93750
- 97500
- 187500
- 200000
- 375000
- 390000

required:
- compatible
- reg
- clock-frequency

unevaluatedProperties: false

if:
properties:
compatible:
contains:
enum:
- brcm,bcm2711-hdmi-i2c

then:
properties:
reg:
minItems: 2

required:
- reg-names

else:
properties:
reg:
maxItems: 1

examples:
- |
bsca: i2c@f0406200 {
clock-frequency = <390000>;
compatible = "brcm,brcmstb-i2c";
interrupt-parent = <&irq0_intc>;
reg = <0xf0406200 0x58>;
interrupts = <0x18>;
interrupt-names = "upg_bsca";
};
- |
ddc0: i2c@7ef04500 {
compatible = "brcm,bcm2711-hdmi-i2c";
reg = <0x7ef04500 0x100>, <0x7ef00b00 0x300>;
reg-names = "bsc", "auto-i2c";
clock-frequency = <390000>;
};
...
10 changes: 10 additions & 0 deletions Documentation/devicetree/bindings/i2c/i2c-at91.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@ Optional properties:
"atmel,sama5d4-i2c",
"atmel,sama5d2-i2c",
"microchip,sam9x60-i2c".
- scl-gpios: specify the gpio related to SCL pin
- sda-gpios: specify the gpio related to SDA pin
- pinctrl: add extra pinctrl to configure i2c pins to gpio function for i2c
bus recovery, call it "gpio" state
- Child nodes conforming to i2c bus binding


Examples :

i2c0: i2c@fff84000 {
Expand Down Expand Up @@ -64,6 +69,11 @@ i2c0: i2c@f8034600 {
clocks = <&flx0>;
atmel,fifo-size = <16>;
i2c-sda-hold-time-ns = <336>;
pinctrl-names = "default", "gpio";
pinctrl-0 = <&pinctrl_i2c0>;
pinctrl-1 = <&pinctrl_i2c0_gpio>;
sda-gpios = <&pioA 30 GPIO_ACTIVE_HIGH>;
scl-gpios = <&pioA 31 GPIO_ACTIVE_HIGH>;

wm8731: wm8731@1a {
compatible = "wm8731";
Expand Down
26 changes: 0 additions & 26 deletions Documentation/devicetree/bindings/i2c/i2c-brcmstb.txt

This file was deleted.

2 changes: 1 addition & 1 deletion Documentation/i2c/smbus-protocol.rst
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ to know which slave triggered the interrupt.
This is implemented the following way in the Linux kernel:

* I2C bus drivers which support SMBus alert should call
i2c_setup_smbus_alert() to setup SMBus alert support.
i2c_new_smbus_alert_device() to install SMBus alert support.
* I2C drivers for devices which can trigger SMBus alerts should implement
the optional alert() callback.

Expand Down
2 changes: 1 addition & 1 deletion MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -3470,7 +3470,7 @@ L: [email protected]
L: [email protected]
S: Supported
F: drivers/i2c/busses/i2c-brcmstb.c
F: Documentation/devicetree/bindings/i2c/i2c-brcmstb.txt
F: Documentation/devicetree/bindings/i2c/brcm,brcmstb-i2c.yaml

BROADCOM BRCMSTB USB2 and USB3 PHY DRIVER
M: Al Cooper <[email protected]>
Expand Down
6 changes: 3 additions & 3 deletions drivers/i2c/algos/i2c-algo-pca.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,17 +459,17 @@ static int pca_init(struct i2c_adapter *adap)
/* To avoid integer overflow, use clock/100 for calculations */
clock = pca_clock(pca_data) / 100;

if (pca_data->i2c_clock > 1000000) {
if (pca_data->i2c_clock > I2C_MAX_FAST_MODE_PLUS_FREQ) {
mode = I2C_PCA_MODE_TURBO;
min_tlow = 14;
min_thi = 5;
raise_fall_time = 22; /* Raise 11e-8s, Fall 11e-8s */
} else if (pca_data->i2c_clock > 400000) {
} else if (pca_data->i2c_clock > I2C_MAX_FAST_MODE_FREQ) {
mode = I2C_PCA_MODE_FASTP;
min_tlow = 17;
min_thi = 9;
raise_fall_time = 22; /* Raise 11e-8s, Fall 11e-8s */
} else if (pca_data->i2c_clock > 100000) {
} else if (pca_data->i2c_clock > I2C_MAX_STANDARD_MODE_FREQ) {
mode = I2C_PCA_MODE_FAST;
min_tlow = 44;
min_thi = 20;
Expand Down
6 changes: 3 additions & 3 deletions drivers/i2c/busses/i2c-altera.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ static void altr_i2c_init(struct altr_i2c_dev *idev)
(ALTR_I2C_THRESHOLD << ALTR_I2C_CTRL_TCT_SHFT);
u32 t_high, t_low;

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

if (idev->bus_clk_rate > 400000) {
if (idev->bus_clk_rate > I2C_MAX_FAST_MODE_FREQ) {
dev_err(&pdev->dev, "invalid clock-frequency %d\n",
idev->bus_clk_rate);
return -EINVAL;
Expand Down
27 changes: 16 additions & 11 deletions drivers/i2c/busses/i2c-amd-mp2-plat.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,32 +201,37 @@ static int i2c_amd_resume(struct amd_i2c_common *i2c_common)
}
#endif

static const u32 supported_speeds[] = {
I2C_MAX_HIGH_SPEED_MODE_FREQ,
I2C_MAX_TURBO_MODE_FREQ,
I2C_MAX_FAST_MODE_PLUS_FREQ,
I2C_MAX_FAST_MODE_FREQ,
I2C_MAX_STANDARD_MODE_FREQ,
};

static enum speed_enum i2c_amd_get_bus_speed(struct platform_device *pdev)
{
u32 acpi_speed;
int i;
static const u32 supported_speeds[] = {
0, 100000, 400000, 1000000, 1400000, 3400000
};

acpi_speed = i2c_acpi_find_bus_speed(&pdev->dev);
/* round down to the lowest standard speed */
for (i = 1; i < ARRAY_SIZE(supported_speeds); i++) {
if (acpi_speed < supported_speeds[i])
for (i = 0; i < ARRAY_SIZE(supported_speeds); i++) {
if (acpi_speed >= supported_speeds[i])
break;
}
acpi_speed = supported_speeds[i - 1];
acpi_speed = i < ARRAY_SIZE(supported_speeds) ? supported_speeds[i] : 0;

switch (acpi_speed) {
case 100000:
case I2C_MAX_STANDARD_MODE_FREQ:
return speed100k;
case 400000:
case I2C_MAX_FAST_MODE_FREQ:
return speed400k;
case 1000000:
case I2C_MAX_FAST_MODE_PLUS_FREQ:
return speed1000k;
case 1400000:
case I2C_MAX_TURBO_MODE_FREQ:
return speed1400k;
case 3400000:
case I2C_MAX_HIGH_SPEED_MODE_FREQ:
return speed3400k;
default:
return speed400k;
Expand Down
2 changes: 1 addition & 1 deletion drivers/i2c/busses/i2c-aspeed.c
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ static int aspeed_i2c_probe_bus(struct platform_device *pdev)
if (ret < 0) {
dev_err(&pdev->dev,
"Could not read bus-frequency property\n");
bus->bus_frequency = 100000;
bus->bus_frequency = I2C_MAX_STANDARD_MODE_FREQ;
}

match = of_match_node(aspeed_i2c_bus_of_table, pdev->dev.of_node);
Expand Down
78 changes: 78 additions & 0 deletions drivers/i2c/busses/i2c-at91-master.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
#include <linux/dma-mapping.h>
#include <linux/dmaengine.h>
#include <linux/err.h>
#include <linux/gpio/consumer.h>
#include <linux/i2c.h>
#include <linux/interrupt.h>
#include <linux/io.h>
#include <linux/of.h>
#include <linux/of_device.h>
#include <linux/pinctrl/consumer.h>
#include <linux/platform_device.h>
#include <linux/platform_data/dma-atmel.h>
#include <linux/pm_runtime.h>
Expand Down Expand Up @@ -478,6 +480,7 @@ static int at91_do_twi_transfer(struct at91_twi_dev *dev)
unsigned long time_left;
bool has_unre_flag = dev->pdata->has_unre_flag;
bool has_alt_cmd = dev->pdata->has_alt_cmd;
struct i2c_bus_recovery_info *rinfo = &dev->rinfo;

/*
* WARNING: the TXCOMP bit in the Status Register is NOT a clear on
Expand Down Expand Up @@ -637,6 +640,13 @@ static int at91_do_twi_transfer(struct at91_twi_dev *dev)
at91_twi_write(dev, AT91_TWI_CR,
AT91_TWI_THRCLR | AT91_TWI_LOCKCLR);
}

if (rinfo->get_sda && !(rinfo->get_sda(&dev->adapter))) {
dev_dbg(dev->dev,
"SDA is down; clear bus using gpio\n");
i2c_recover_bus(&dev->adapter);
}

return ret;
}

Expand Down Expand Up @@ -806,6 +816,70 @@ static int at91_twi_configure_dma(struct at91_twi_dev *dev, u32 phy_addr)
return ret;
}

static void at91_prepare_twi_recovery(struct i2c_adapter *adap)
{
struct at91_twi_dev *dev = i2c_get_adapdata(adap);

pinctrl_select_state(dev->pinctrl, dev->pinctrl_pins_gpio);
}

static void at91_unprepare_twi_recovery(struct i2c_adapter *adap)
{
struct at91_twi_dev *dev = i2c_get_adapdata(adap);

pinctrl_select_state(dev->pinctrl, dev->pinctrl_pins_default);
}

static int at91_init_twi_recovery_info(struct platform_device *pdev,
struct at91_twi_dev *dev)
{
struct i2c_bus_recovery_info *rinfo = &dev->rinfo;

dev->pinctrl = devm_pinctrl_get(&pdev->dev);
if (!dev->pinctrl || IS_ERR(dev->pinctrl)) {
dev_info(dev->dev, "can't get pinctrl, bus recovery not supported\n");
return PTR_ERR(dev->pinctrl);
}

dev->pinctrl_pins_default = pinctrl_lookup_state(dev->pinctrl,
PINCTRL_STATE_DEFAULT);
dev->pinctrl_pins_gpio = pinctrl_lookup_state(dev->pinctrl,
"gpio");
rinfo->sda_gpiod = devm_gpiod_get(&pdev->dev, "sda", GPIOD_IN);
if (PTR_ERR(rinfo->sda_gpiod) == -EPROBE_DEFER)
return -EPROBE_DEFER;

rinfo->scl_gpiod = devm_gpiod_get(&pdev->dev, "scl",
GPIOD_OUT_HIGH_OPEN_DRAIN);
if (PTR_ERR(rinfo->scl_gpiod) == -EPROBE_DEFER)
return -EPROBE_DEFER;

if (IS_ERR(rinfo->sda_gpiod) ||
IS_ERR(rinfo->scl_gpiod) ||
IS_ERR(dev->pinctrl_pins_default) ||
IS_ERR(dev->pinctrl_pins_gpio)) {
dev_info(&pdev->dev, "recovery information incomplete\n");
if (!IS_ERR(rinfo->sda_gpiod)) {
gpiod_put(rinfo->sda_gpiod);
rinfo->sda_gpiod = NULL;
}
if (!IS_ERR(rinfo->scl_gpiod)) {
gpiod_put(rinfo->scl_gpiod);
rinfo->scl_gpiod = NULL;
}
return -EINVAL;
}

dev_info(&pdev->dev, "using scl, sda for recovery\n");

rinfo->prepare_recovery = at91_prepare_twi_recovery;
rinfo->unprepare_recovery = at91_unprepare_twi_recovery;
rinfo->recover_bus = i2c_generic_scl_recovery;
dev->adapter.bus_recovery_info = rinfo;

return 0;
}

int at91_twi_probe_master(struct platform_device *pdev,
u32 phy_addr, struct at91_twi_dev *dev)
{
Expand Down Expand Up @@ -838,6 +912,10 @@ int at91_twi_probe_master(struct platform_device *pdev,
"i2c-analog-filter");
at91_calc_twi_clock(dev);

rc = at91_init_twi_recovery_info(pdev, dev);
if (rc == -EPROBE_DEFER)
return rc;

dev->adapter.algo = &at91_twi_algorithm;
dev->adapter.quirks = &at91_twi_quirks;

Expand Down
4 changes: 4 additions & 0 deletions drivers/i2c/busses/i2c-at91.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ struct at91_twi_dev {
u32 fifo_size;
struct at91_twi_dma dma;
bool slave_detected;
struct i2c_bus_recovery_info rinfo;
struct pinctrl *pinctrl;
struct pinctrl_state *pinctrl_pins_default;
struct pinctrl_state *pinctrl_pins_gpio;
#ifdef CONFIG_I2C_AT91_SLAVE_EXPERIMENTAL
unsigned smr;
struct i2c_client *slave;
Expand Down
Loading

0 comments on commit 5c8db3e

Please sign in to comment.