Skip to content

Commit 58b9242

Browse files
Shubhrajyoti Dattawsakernel
authored andcommitted
i2c: cadence: Add standard bus recovery support
Hook up the standard GPIO/pinctrl-based recovery support. We are doing the recovery at the beginning on a timeout. Multiple people have contributed to the series. Original patch from Cirag and another one from Robert. Signed-off-by: Shubhrajyoti Datta <shubhrajyoti.datta@xilinx.com> Acked-by: Michal Simek <michal.simek@amd.com> Signed-off-by: Wolfram Sang <wsa@kernel.org>
1 parent bdc4af2 commit 58b9242

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

drivers/i2c/busses/i2c-cadence.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
#include <linux/i2c.h>
1111
#include <linux/interrupt.h>
1212
#include <linux/io.h>
13+
#include <linux/iopoll.h>
1314
#include <linux/module.h>
1415
#include <linux/platform_device.h>
1516
#include <linux/of.h>
1617
#include <linux/pm_runtime.h>
18+
#include <linux/pinctrl/consumer.h>
1719

1820
/* Register offsets for the I2C device. */
1921
#define CDNS_I2C_CR_OFFSET 0x00 /* Control Register, RW */
@@ -127,6 +129,8 @@
127129
#define CDNS_I2C_TIMEOUT_MAX 0xFF
128130

129131
#define CDNS_I2C_BROKEN_HOLD_BIT BIT(0)
132+
#define CDNS_I2C_POLL_US 100000
133+
#define CDNS_I2C_TIMEOUT_US 500000
130134

131135
#define cdns_i2c_readreg(offset) readl_relaxed(id->membase + offset)
132136
#define cdns_i2c_writereg(val, offset) writel_relaxed(val, id->membase + offset)
@@ -204,6 +208,7 @@ struct cdns_i2c {
204208
struct notifier_block clk_rate_change_nb;
205209
u32 quirks;
206210
u32 ctrl_reg;
211+
struct i2c_bus_recovery_info rinfo;
207212
#if IS_ENABLED(CONFIG_I2C_SLAVE)
208213
u16 ctrl_reg_diva_divb;
209214
struct i2c_client *slave;
@@ -840,8 +845,14 @@ static int cdns_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
840845
#endif
841846

842847
/* Check if the bus is free */
843-
if (cdns_i2c_readreg(CDNS_I2C_SR_OFFSET) & CDNS_I2C_SR_BA) {
848+
849+
ret = readl_relaxed_poll_timeout(id->membase + CDNS_I2C_SR_OFFSET,
850+
reg,
851+
!(reg & CDNS_I2C_SR_BA),
852+
CDNS_I2C_POLL_US, CDNS_I2C_TIMEOUT_US);
853+
if (ret) {
844854
ret = -EAGAIN;
855+
i2c_recover_bus(adap);
845856
goto out;
846857
}
847858

@@ -1250,6 +1261,12 @@ static int cdns_i2c_probe(struct platform_device *pdev)
12501261
id->quirks = data->quirks;
12511262
}
12521263

1264+
id->rinfo.pinctrl = devm_pinctrl_get(&pdev->dev);
1265+
if (IS_ERR(id->rinfo.pinctrl)) {
1266+
dev_info(&pdev->dev, "can't get pinctrl, bus recovery not supported\n");
1267+
return PTR_ERR(id->rinfo.pinctrl);
1268+
}
1269+
12531270
id->membase = devm_platform_get_and_ioremap_resource(pdev, 0, &r_mem);
12541271
if (IS_ERR(id->membase))
12551272
return PTR_ERR(id->membase);
@@ -1266,6 +1283,7 @@ static int cdns_i2c_probe(struct platform_device *pdev)
12661283
id->adap.retries = 3; /* Default retry value. */
12671284
id->adap.algo_data = id;
12681285
id->adap.dev.parent = &pdev->dev;
1286+
id->adap.bus_recovery_info = &id->rinfo;
12691287
init_completion(&id->xfer_done);
12701288
snprintf(id->adap.name, sizeof(id->adap.name),
12711289
"Cadence I2C at %08lx", (unsigned long)r_mem->start);

0 commit comments

Comments
 (0)