diff options
author | Linus Walleij <linus.walleij@linaro.org> | 2017-12-20 07:17:49 -0500 |
---|---|---|
committer | Wolfram Sang <wsa@the-dreams.de> | 2017-12-30 18:09:39 -0500 |
commit | e53537653791b4aaa9ec88a9eb5fd187d44ff6ac (patch) | |
tree | a812a43d7b823d3e7ff33669ba2d67a848c0ff65 | |
parent | 7d42762d8cdff2974c3cfddeb480d467018f55fe (diff) |
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>
-rw-r--r-- | arch/arm/mach-davinci/board-dm355-evm.c | 15 | ||||
-rw-r--r-- | arch/arm/mach-davinci/board-dm644x-evm.c | 15 | ||||
-rw-r--r-- | drivers/i2c/busses/i2c-davinci.c | 21 | ||||
-rw-r--r-- | include/linux/platform_data/i2c-davinci.h | 5 |
4 files changed, 39 insertions, 17 deletions
diff --git a/arch/arm/mach-davinci/board-dm355-evm.c b/arch/arm/mach-davinci/board-dm355-evm.c index 62e7bc3018f0..e457f299cd44 100644 --- a/arch/arm/mach-davinci/board-dm355-evm.c +++ b/arch/arm/mach-davinci/board-dm355-evm.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #include <linux/mtd/rawnand.h> | 17 | #include <linux/mtd/rawnand.h> |
18 | #include <linux/i2c.h> | 18 | #include <linux/i2c.h> |
19 | #include <linux/gpio.h> | 19 | #include <linux/gpio.h> |
20 | #include <linux/gpio/machine.h> | ||
20 | #include <linux/clk.h> | 21 | #include <linux/clk.h> |
21 | #include <linux/videodev2.h> | 22 | #include <linux/videodev2.h> |
22 | #include <media/i2c/tvp514x.h> | 23 | #include <media/i2c/tvp514x.h> |
@@ -108,11 +109,20 @@ static struct platform_device davinci_nand_device = { | |||
108 | }, | 109 | }, |
109 | }; | 110 | }; |
110 | 111 | ||
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 | |||
111 | static struct davinci_i2c_platform_data i2c_pdata = { | 122 | static struct davinci_i2c_platform_data i2c_pdata = { |
112 | .bus_freq = 400 /* kHz */, | 123 | .bus_freq = 400 /* kHz */, |
113 | .bus_delay = 0 /* usec */, | 124 | .bus_delay = 0 /* usec */, |
114 | .sda_pin = 15, | 125 | .gpio_recovery = true, |
115 | .scl_pin = 14, | ||
116 | }; | 126 | }; |
117 | 127 | ||
118 | static int dm355evm_mmc_gpios = -EINVAL; | 128 | static int dm355evm_mmc_gpios = -EINVAL; |
@@ -141,6 +151,7 @@ static struct i2c_board_info dm355evm_i2c_info[] = { | |||
141 | 151 | ||
142 | static void __init evm_init_i2c(void) | 152 | static void __init evm_init_i2c(void) |
143 | { | 153 | { |
154 | gpiod_add_lookup_table(&i2c_recovery_gpiod_table); | ||
144 | davinci_init_i2c(&i2c_pdata); | 155 | davinci_init_i2c(&i2c_pdata); |
145 | 156 | ||
146 | gpio_request(5, "dm355evm_msp"); | 157 | gpio_request(5, "dm355evm_msp"); |
diff --git a/arch/arm/mach-davinci/board-dm644x-evm.c b/arch/arm/mach-davinci/board-dm644x-evm.c index b07c9b18d427..85e6fb33b1ee 100644 --- a/arch/arm/mach-davinci/board-dm644x-evm.c +++ b/arch/arm/mach-davinci/board-dm644x-evm.c | |||
@@ -13,6 +13,7 @@ | |||
13 | #include <linux/dma-mapping.h> | 13 | #include <linux/dma-mapping.h> |
14 | #include <linux/platform_device.h> | 14 | #include <linux/platform_device.h> |
15 | #include <linux/gpio.h> | 15 | #include <linux/gpio.h> |
16 | #include <linux/gpio/machine.h> | ||
16 | #include <linux/i2c.h> | 17 | #include <linux/i2c.h> |
17 | #include <linux/platform_data/pcf857x.h> | 18 | #include <linux/platform_data/pcf857x.h> |
18 | #include <linux/platform_data/at24.h> | 19 | #include <linux/platform_data/at24.h> |
@@ -595,18 +596,28 @@ static struct i2c_board_info __initdata i2c_info[] = { | |||
595 | }, | 596 | }, |
596 | }; | 597 | }; |
597 | 598 | ||
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 | |||
598 | /* The msp430 uses a slow bitbanged I2C implementation (ergo 20 KHz), | 609 | /* The msp430 uses a slow bitbanged I2C implementation (ergo 20 KHz), |
599 | * which requires 100 usec of idle bus after i2c writes sent to it. | 610 | * which requires 100 usec of idle bus after i2c writes sent to it. |
600 | */ | 611 | */ |
601 | static struct davinci_i2c_platform_data i2c_pdata = { | 612 | static struct davinci_i2c_platform_data i2c_pdata = { |
602 | .bus_freq = 20 /* kHz */, | 613 | .bus_freq = 20 /* kHz */, |
603 | .bus_delay = 100 /* usec */, | 614 | .bus_delay = 100 /* usec */, |
604 | .sda_pin = 44, | 615 | .gpio_recovery = true, |
605 | .scl_pin = 43, | ||
606 | }; | 616 | }; |
607 | 617 | ||
608 | static void __init evm_init_i2c(void) | 618 | static void __init evm_init_i2c(void) |
609 | { | 619 | { |
620 | gpiod_add_lookup_table(&i2c_recovery_gpiod_table); | ||
610 | davinci_init_i2c(&i2c_pdata); | 621 | davinci_init_i2c(&i2c_pdata); |
611 | i2c_add_driver(&dm6446evm_msp_driver); | 622 | i2c_add_driver(&dm6446evm_msp_driver); |
612 | i2c_register_board_info(1, i2c_info, ARRAY_SIZE(i2c_info)); | 623 | i2c_register_board_info(1, i2c_info, ARRAY_SIZE(i2c_info)); |
diff --git a/drivers/i2c/busses/i2c-davinci.c b/drivers/i2c/busses/i2c-davinci.c index 2afb12a89eb3..cb24a3ffdfa2 100644 --- a/drivers/i2c/busses/i2c-davinci.c +++ b/drivers/i2c/busses/i2c-davinci.c | |||
@@ -33,7 +33,7 @@ | |||
33 | #include <linux/io.h> | 33 | #include <linux/io.h> |
34 | #include <linux/slab.h> | 34 | #include <linux/slab.h> |
35 | #include <linux/cpufreq.h> | 35 | #include <linux/cpufreq.h> |
36 | #include <linux/gpio.h> | 36 | #include <linux/gpio/consumer.h> |
37 | #include <linux/of_device.h> | 37 | #include <linux/of_device.h> |
38 | #include <linux/platform_data/i2c-davinci.h> | 38 | #include <linux/platform_data/i2c-davinci.h> |
39 | #include <linux/pm_runtime.h> | 39 | #include <linux/pm_runtime.h> |
@@ -869,19 +869,20 @@ static int davinci_i2c_probe(struct platform_device *pdev) | |||
869 | 869 | ||
870 | if (dev->pdata->has_pfunc) | 870 | if (dev->pdata->has_pfunc) |
871 | adap->bus_recovery_info = &davinci_i2c_scl_recovery_info; | 871 | adap->bus_recovery_info = &davinci_i2c_scl_recovery_info; |
872 | else if (dev->pdata->scl_pin) { | 872 | else if (dev->pdata->gpio_recovery) { |
873 | rinfo = &davinci_i2c_gpio_recovery_info; | 873 | rinfo = &davinci_i2c_gpio_recovery_info; |
874 | adap->bus_recovery_info = rinfo; | 874 | adap->bus_recovery_info = rinfo; |
875 | r = gpio_request_one(dev->pdata->scl_pin, GPIOF_OPEN_DRAIN | | 875 | rinfo->scl_gpiod = devm_gpiod_get(&pdev->dev, "scl", |
876 | GPIOF_OUT_INIT_HIGH, "i2c-scl"); | 876 | GPIOD_OUT_HIGH_OPEN_DRAIN); |
877 | if (r) | 877 | if (IS_ERR(rinfo->scl_gpiod)) { |
878 | r = PTR_ERR(rinfo->scl_gpiod); | ||
878 | goto err_unuse_clocks; | 879 | goto err_unuse_clocks; |
879 | rinfo->scl_gpiod = gpio_to_desc(dev->pdata->scl_pin); | 880 | } |
880 | 881 | rinfo->sda_gpiod = devm_gpiod_get(&pdev->dev, "sda", GPIOD_IN); | |
881 | r = gpio_request_one(dev->pdata->sda_pin, GPIOF_IN, "i2c-sda"); | 882 | if (IS_ERR(rinfo->sda_gpiod)) { |
882 | if (r) | 883 | r = PTR_ERR(rinfo->sda_gpiod); |
883 | goto err_unuse_clocks; | 884 | goto err_unuse_clocks; |
884 | rinfo->sda_gpiod = gpio_to_desc(dev->pdata->scl_pin); | 885 | } |
885 | } | 886 | } |
886 | 887 | ||
887 | adap->nr = pdev->id; | 888 | adap->nr = pdev->id; |
diff --git a/include/linux/platform_data/i2c-davinci.h b/include/linux/platform_data/i2c-davinci.h index 89fd34727a24..98967df07468 100644 --- a/include/linux/platform_data/i2c-davinci.h +++ b/include/linux/platform_data/i2c-davinci.h | |||
@@ -16,9 +16,8 @@ | |||
16 | struct davinci_i2c_platform_data { | 16 | struct davinci_i2c_platform_data { |
17 | unsigned int bus_freq; /* standard bus frequency (kHz) */ | 17 | unsigned int bus_freq; /* standard bus frequency (kHz) */ |
18 | unsigned int bus_delay; /* post-transaction delay (usec) */ | 18 | unsigned int bus_delay; /* post-transaction delay (usec) */ |
19 | unsigned int sda_pin; /* GPIO pin ID to use for SDA */ | 19 | bool gpio_recovery; /* Use GPIO recovery method */ |
20 | unsigned int scl_pin; /* GPIO pin ID to use for SCL */ | 20 | bool has_pfunc; /* Chip has a ICPFUNC register */ |
21 | bool has_pfunc; /*chip has a ICPFUNC register */ | ||
22 | }; | 21 | }; |
23 | 22 | ||
24 | /* for board setup code */ | 23 | /* for board setup code */ |