Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Linus Walleij and committed by
Wolfram Sang
e5353765 7d42762d

+39 -17
+13 -2
arch/arm/mach-davinci/board-dm355-evm.c
··· 17 17 #include <linux/mtd/rawnand.h> 18 18 #include <linux/i2c.h> 19 19 #include <linux/gpio.h> 20 + #include <linux/gpio/machine.h> 20 21 #include <linux/clk.h> 21 22 #include <linux/videodev2.h> 22 23 #include <media/i2c/tvp514x.h> ··· 109 108 }, 110 109 }; 111 110 111 + static struct gpiod_lookup_table i2c_recovery_gpiod_table = { 112 + .dev_id = "i2c_davinci", 113 + .table = { 114 + GPIO_LOOKUP("davinci_gpio", 15, "sda", 115 + GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 116 + GPIO_LOOKUP("davinci_gpio", 14, "scl", 117 + GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 118 + }, 119 + }; 120 + 112 121 static struct davinci_i2c_platform_data i2c_pdata = { 113 122 .bus_freq = 400 /* kHz */, 114 123 .bus_delay = 0 /* usec */, 115 - .sda_pin = 15, 116 - .scl_pin = 14, 124 + .gpio_recovery = true, 117 125 }; 118 126 119 127 static int dm355evm_mmc_gpios = -EINVAL; ··· 151 141 152 142 static void __init evm_init_i2c(void) 153 143 { 144 + gpiod_add_lookup_table(&i2c_recovery_gpiod_table); 154 145 davinci_init_i2c(&i2c_pdata); 155 146 156 147 gpio_request(5, "dm355evm_msp");
+13 -2
arch/arm/mach-davinci/board-dm644x-evm.c
··· 13 13 #include <linux/dma-mapping.h> 14 14 #include <linux/platform_device.h> 15 15 #include <linux/gpio.h> 16 + #include <linux/gpio/machine.h> 16 17 #include <linux/i2c.h> 17 18 #include <linux/platform_data/pcf857x.h> 18 19 #include <linux/platform_data/at24.h> ··· 596 595 }, 597 596 }; 598 597 598 + static struct gpiod_lookup_table i2c_recovery_gpiod_table = { 599 + .dev_id = "i2c_davinci", 600 + .table = { 601 + GPIO_LOOKUP("davinci_gpio", 44, "sda", 602 + GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 603 + GPIO_LOOKUP("davinci_gpio", 43, "scl", 604 + GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 605 + }, 606 + }; 607 + 599 608 /* The msp430 uses a slow bitbanged I2C implementation (ergo 20 KHz), 600 609 * which requires 100 usec of idle bus after i2c writes sent to it. 601 610 */ 602 611 static struct davinci_i2c_platform_data i2c_pdata = { 603 612 .bus_freq = 20 /* kHz */, 604 613 .bus_delay = 100 /* usec */, 605 - .sda_pin = 44, 606 - .scl_pin = 43, 614 + .gpio_recovery = true, 607 615 }; 608 616 609 617 static void __init evm_init_i2c(void) 610 618 { 619 + gpiod_add_lookup_table(&i2c_recovery_gpiod_table); 611 620 davinci_init_i2c(&i2c_pdata); 612 621 i2c_add_driver(&dm6446evm_msp_driver); 613 622 i2c_register_board_info(1, i2c_info, ARRAY_SIZE(i2c_info));
+11 -10
drivers/i2c/busses/i2c-davinci.c
··· 33 33 #include <linux/io.h> 34 34 #include <linux/slab.h> 35 35 #include <linux/cpufreq.h> 36 - #include <linux/gpio.h> 36 + #include <linux/gpio/consumer.h> 37 37 #include <linux/of_device.h> 38 38 #include <linux/platform_data/i2c-davinci.h> 39 39 #include <linux/pm_runtime.h> ··· 869 869 870 870 if (dev->pdata->has_pfunc) 871 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 873 rinfo = &davinci_i2c_gpio_recovery_info; 874 874 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); 878 879 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); 883 884 goto err_unuse_clocks; 884 - rinfo->sda_gpiod = gpio_to_desc(dev->pdata->scl_pin); 885 + } 885 886 } 886 887 887 888 adap->nr = pdev->id;
+2 -3
include/linux/platform_data/i2c-davinci.h
··· 16 16 struct davinci_i2c_platform_data { 17 17 unsigned int bus_freq; /* standard bus frequency (kHz) */ 18 18 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 */ 22 21 }; 23 22 24 23 /* for board setup code */