Skip to content

Commit e535376

Browse files
Linus WalleijWolfram Sang
authored andcommitted
i2c/ARM: davinci: Deep refactoring of I2C recovery
Alter the DaVinci GPIO recovery fetch to use descriptors all the way down into the board files. Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Acked-by: Sekhar Nori <nsekhar@ti.com> Tested-by: Sekhar Nori <nsekhar@ti.com> Acked-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
1 parent 7d42762 commit e535376

4 files changed

Lines changed: 39 additions & 17 deletions

File tree

‎arch/arm/mach-davinci/board-dm355-evm.c‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <linux/mtd/rawnand.h>
1818
#include <linux/i2c.h>
1919
#include <linux/gpio.h>
20+
#include <linux/gpio/machine.h>
2021
#include <linux/clk.h>
2122
#include <linux/videodev2.h>
2223
#include <media/i2c/tvp514x.h>
@@ -108,11 +109,20 @@ static struct platform_device davinci_nand_device = {
108109
},
109110
};
110111

112+
static struct gpiod_lookup_table i2c_recovery_gpiod_table = {
113+
.dev_id = "i2c_davinci",
114+
.table = {
115+
GPIO_LOOKUP("davinci_gpio", 15, "sda",
116+
GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
117+
GPIO_LOOKUP("davinci_gpio", 14, "scl",
118+
GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
119+
},
120+
};
121+
111122
static struct davinci_i2c_platform_data i2c_pdata = {
112123
.bus_freq = 400 /* kHz */,
113124
.bus_delay = 0 /* usec */,
114-
.sda_pin = 15,
115-
.scl_pin = 14,
125+
.gpio_recovery = true,
116126
};
117127

118128
static int dm355evm_mmc_gpios = -EINVAL;
@@ -141,6 +151,7 @@ static struct i2c_board_info dm355evm_i2c_info[] = {
141151

142152
static void __init evm_init_i2c(void)
143153
{
154+
gpiod_add_lookup_table(&i2c_recovery_gpiod_table);
144155
davinci_init_i2c(&i2c_pdata);
145156

146157
gpio_request(5, "dm355evm_msp");

‎arch/arm/mach-davinci/board-dm644x-evm.c‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/dma-mapping.h>
1414
#include <linux/platform_device.h>
1515
#include <linux/gpio.h>
16+
#include <linux/gpio/machine.h>
1617
#include <linux/i2c.h>
1718
#include <linux/platform_data/pcf857x.h>
1819
#include <linux/platform_data/at24.h>
@@ -595,18 +596,28 @@ static struct i2c_board_info __initdata i2c_info[] = {
595596
},
596597
};
597598

599+
static struct gpiod_lookup_table i2c_recovery_gpiod_table = {
600+
.dev_id = "i2c_davinci",
601+
.table = {
602+
GPIO_LOOKUP("davinci_gpio", 44, "sda",
603+
GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
604+
GPIO_LOOKUP("davinci_gpio", 43, "scl",
605+
GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
606+
},
607+
};
608+
598609
/* The msp430 uses a slow bitbanged I2C implementation (ergo 20 KHz),
599610
* which requires 100 usec of idle bus after i2c writes sent to it.
600611
*/
601612
static struct davinci_i2c_platform_data i2c_pdata = {
602613
.bus_freq = 20 /* kHz */,
603614
.bus_delay = 100 /* usec */,
604-
.sda_pin = 44,
605-
.scl_pin = 43,
615+
.gpio_recovery = true,
606616
};
607617

608618
static void __init evm_init_i2c(void)
609619
{
620+
gpiod_add_lookup_table(&i2c_recovery_gpiod_table);
610621
davinci_init_i2c(&i2c_pdata);
611622
i2c_add_driver(&dm6446evm_msp_driver);
612623
i2c_register_board_info(1, i2c_info, ARRAY_SIZE(i2c_info));

‎drivers/i2c/busses/i2c-davinci.c‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#include <linux/io.h>
3434
#include <linux/slab.h>
3535
#include <linux/cpufreq.h>
36-
#include <linux/gpio.h>
36+
#include <linux/gpio/consumer.h>
3737
#include <linux/of_device.h>
3838
#include <linux/platform_data/i2c-davinci.h>
3939
#include <linux/pm_runtime.h>
@@ -869,19 +869,20 @@ static int davinci_i2c_probe(struct platform_device *pdev)
869869

870870
if (dev->pdata->has_pfunc)
871871
adap->bus_recovery_info = &davinci_i2c_scl_recovery_info;
872-
else if (dev->pdata->scl_pin) {
872+
else if (dev->pdata->gpio_recovery) {
873873
rinfo = &davinci_i2c_gpio_recovery_info;
874874
adap->bus_recovery_info = rinfo;
875-
r = gpio_request_one(dev->pdata->scl_pin, GPIOF_OPEN_DRAIN |
876-
GPIOF_OUT_INIT_HIGH, "i2c-scl");
877-
if (r)
875+
rinfo->scl_gpiod = devm_gpiod_get(&pdev->dev, "scl",
876+
GPIOD_OUT_HIGH_OPEN_DRAIN);
877+
if (IS_ERR(rinfo->scl_gpiod)) {
878+
r = PTR_ERR(rinfo->scl_gpiod);
878879
goto err_unuse_clocks;
879-
rinfo->scl_gpiod = gpio_to_desc(dev->pdata->scl_pin);
880-
881-
r = gpio_request_one(dev->pdata->sda_pin, GPIOF_IN, "i2c-sda");
882-
if (r)
880+
}
881+
rinfo->sda_gpiod = devm_gpiod_get(&pdev->dev, "sda", GPIOD_IN);
882+
if (IS_ERR(rinfo->sda_gpiod)) {
883+
r = PTR_ERR(rinfo->sda_gpiod);
883884
goto err_unuse_clocks;
884-
rinfo->sda_gpiod = gpio_to_desc(dev->pdata->scl_pin);
885+
}
885886
}
886887

887888
adap->nr = pdev->id;

‎include/linux/platform_data/i2c-davinci.h‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616
struct davinci_i2c_platform_data {
1717
unsigned int bus_freq; /* standard bus frequency (kHz) */
1818
unsigned int bus_delay; /* post-transaction delay (usec) */
19-
unsigned int sda_pin; /* GPIO pin ID to use for SDA */
20-
unsigned int scl_pin; /* GPIO pin ID to use for SCL */
21-
bool has_pfunc; /*chip has a ICPFUNC register */
19+
bool gpio_recovery; /* Use GPIO recovery method */
20+
bool has_pfunc; /* Chip has a ICPFUNC register */
2221
};
2322

2423
/* for board setup code */

0 commit comments

Comments
 (0)