Skip to content

Commit 6327edc

Browse files
committed
Merge branch 'i2c/for-current' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux
Pull i2c fixes from Wolfram Sang: "Two driver bugfixes, a documentation fix, and a removal of a spec violation for the bus recovery algorithm in the core" * 'i2c/for-current' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux: i2c: fix bus recovery stop mode timing i2c: bcm2835: Store pointer to bus clock dt-bindings: i2c: at91: fix i2c-sda-hold-time-ns documentation for sam9x60 i2c: at91: fix clk_offset for sam9x60
2 parents 606e9ad + cf8ce8b commit 6327edc

File tree

4 files changed

+23
-15
lines changed

4 files changed

+23
-15
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ Optional properties:
1818
- dma-names: should contain "tx" and "rx".
1919
- atmel,fifo-size: maximum number of data the RX and TX FIFOs can store for FIFO
2020
capable I2C controllers.
21-
- i2c-sda-hold-time-ns: TWD hold time, only available for "atmel,sama5d4-i2c"
22-
and "atmel,sama5d2-i2c".
21+
- i2c-sda-hold-time-ns: TWD hold time, only available for:
22+
"atmel,sama5d4-i2c",
23+
"atmel,sama5d2-i2c",
24+
"microchip,sam9x60-i2c".
2325
- Child nodes conforming to i2c bus binding
2426

2527
Examples :

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ static struct at91_twi_pdata sama5d2_config = {
174174

175175
static struct at91_twi_pdata sam9x60_config = {
176176
.clk_max_div = 7,
177-
.clk_offset = 4,
177+
.clk_offset = 3,
178178
.has_unre_flag = true,
179179
.has_alt_cmd = true,
180180
.has_hold_field = true,

drivers/i2c/busses/i2c-bcm2835.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ struct bcm2835_i2c_dev {
5858
struct i2c_adapter adapter;
5959
struct completion completion;
6060
struct i2c_msg *curr_msg;
61+
struct clk *bus_clk;
6162
int num_msgs;
6263
u32 msg_err;
6364
u8 *msg_buf;
@@ -404,7 +405,6 @@ static int bcm2835_i2c_probe(struct platform_device *pdev)
404405
struct resource *mem, *irq;
405406
int ret;
406407
struct i2c_adapter *adap;
407-
struct clk *bus_clk;
408408
struct clk *mclk;
409409
u32 bus_clk_rate;
410410

@@ -427,11 +427,11 @@ static int bcm2835_i2c_probe(struct platform_device *pdev)
427427
return PTR_ERR(mclk);
428428
}
429429

430-
bus_clk = bcm2835_i2c_register_div(&pdev->dev, mclk, i2c_dev);
430+
i2c_dev->bus_clk = bcm2835_i2c_register_div(&pdev->dev, mclk, i2c_dev);
431431

432-
if (IS_ERR(bus_clk)) {
432+
if (IS_ERR(i2c_dev->bus_clk)) {
433433
dev_err(&pdev->dev, "Could not register clock\n");
434-
return PTR_ERR(bus_clk);
434+
return PTR_ERR(i2c_dev->bus_clk);
435435
}
436436

437437
ret = of_property_read_u32(pdev->dev.of_node, "clock-frequency",
@@ -442,13 +442,13 @@ static int bcm2835_i2c_probe(struct platform_device *pdev)
442442
bus_clk_rate = 100000;
443443
}
444444

445-
ret = clk_set_rate_exclusive(bus_clk, bus_clk_rate);
445+
ret = clk_set_rate_exclusive(i2c_dev->bus_clk, bus_clk_rate);
446446
if (ret < 0) {
447447
dev_err(&pdev->dev, "Could not set clock frequency\n");
448448
return ret;
449449
}
450450

451-
ret = clk_prepare_enable(bus_clk);
451+
ret = clk_prepare_enable(i2c_dev->bus_clk);
452452
if (ret) {
453453
dev_err(&pdev->dev, "Couldn't prepare clock");
454454
return ret;
@@ -491,10 +491,9 @@ static int bcm2835_i2c_probe(struct platform_device *pdev)
491491
static int bcm2835_i2c_remove(struct platform_device *pdev)
492492
{
493493
struct bcm2835_i2c_dev *i2c_dev = platform_get_drvdata(pdev);
494-
struct clk *bus_clk = devm_clk_get(i2c_dev->dev, "div");
495494

496-
clk_rate_exclusive_put(bus_clk);
497-
clk_disable_unprepare(bus_clk);
495+
clk_rate_exclusive_put(i2c_dev->bus_clk);
496+
clk_disable_unprepare(i2c_dev->bus_clk);
498497

499498
free_irq(i2c_dev->irq, i2c_dev);
500499
i2c_del_adapter(&i2c_dev->adapter);

drivers/i2c/i2c-core-base.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,11 @@ int i2c_generic_scl_recovery(struct i2c_adapter *adap)
186186
* If we can set SDA, we will always create a STOP to ensure additional
187187
* pulses will do no harm. This is achieved by letting SDA follow SCL
188188
* half a cycle later. Check the 'incomplete_write_byte' fault injector
189-
* for details.
189+
* for details. Note that we must honour tsu:sto, 4us, but lets use 5us
190+
* here for simplicity.
190191
*/
191192
bri->set_scl(adap, scl);
192-
ndelay(RECOVERY_NDELAY / 2);
193+
ndelay(RECOVERY_NDELAY);
193194
if (bri->set_sda)
194195
bri->set_sda(adap, scl);
195196
ndelay(RECOVERY_NDELAY / 2);
@@ -211,7 +212,13 @@ int i2c_generic_scl_recovery(struct i2c_adapter *adap)
211212
scl = !scl;
212213
bri->set_scl(adap, scl);
213214
/* Creating STOP again, see above */
214-
ndelay(RECOVERY_NDELAY / 2);
215+
if (scl) {
216+
/* Honour minimum tsu:sto */
217+
ndelay(RECOVERY_NDELAY);
218+
} else {
219+
/* Honour minimum tf and thd:dat */
220+
ndelay(RECOVERY_NDELAY / 2);
221+
}
215222
if (bri->set_sda)
216223
bri->set_sda(adap, scl);
217224
ndelay(RECOVERY_NDELAY / 2);

0 commit comments

Comments
 (0)