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

i2c: cbus-gpio: Switch to use GPIO descriptors

This augments the CBUS GPIO I2C driver to use GPIO
descriptors for clock, sel and data. We drop the platform
data that was only used for carrying GPIO numbers and
use machine descriptor tables instead.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Tested-by: Aaro Koskinen <aaro.koskinen@iki.fi>
Acked-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>

authored by

Linus Walleij and committed by
Wolfram Sang
2e5a662d d0051ca5

+40 -85
+10 -8
arch/arm/mach-omap1/board-nokia770.c
··· 10 10 #include <linux/clkdev.h> 11 11 #include <linux/irq.h> 12 12 #include <linux/gpio.h> 13 + #include <linux/gpio/machine.h> 13 14 #include <linux/kernel.h> 14 15 #include <linux/init.h> 15 16 #include <linux/mutex.h> ··· 26 25 #include <linux/platform_data/keypad-omap.h> 27 26 #include <linux/platform_data/lcd-mipid.h> 28 27 #include <linux/platform_data/gpio-omap.h> 29 - #include <linux/platform_data/i2c-cbus-gpio.h> 30 28 31 29 #include <asm/mach-types.h> 32 30 #include <asm/mach/arch.h> ··· 217 217 #endif 218 218 219 219 #if IS_ENABLED(CONFIG_I2C_CBUS_GPIO) 220 - static struct i2c_cbus_platform_data nokia770_cbus_data = { 221 - .clk_gpio = OMAP_MPUIO(9), 222 - .dat_gpio = OMAP_MPUIO(10), 223 - .sel_gpio = OMAP_MPUIO(11), 220 + static struct gpiod_lookup_table nokia770_cbus_gpio_table = { 221 + .dev_id = "i2c-cbus-gpio.2", 222 + .table = { 223 + GPIO_LOOKUP_IDX("mpuio", 9, NULL, 0, 0), /* clk */ 224 + GPIO_LOOKUP_IDX("mpuio", 10, NULL, 1, 0), /* dat */ 225 + GPIO_LOOKUP_IDX("mpuio", 11, NULL, 2, 0), /* sel */ 226 + { }, 227 + }, 224 228 }; 225 229 226 230 static struct platform_device nokia770_cbus_device = { 227 231 .name = "i2c-cbus-gpio", 228 232 .id = 2, 229 - .dev = { 230 - .platform_data = &nokia770_cbus_data, 231 - }, 232 233 }; 233 234 234 235 static struct i2c_board_info nokia770_i2c_board_info_2[] __initdata = { ··· 258 257 nokia770_i2c_board_info_2[1].irq = gpio_to_irq(tahvo_irq_gpio); 259 258 i2c_register_board_info(2, nokia770_i2c_board_info_2, 260 259 ARRAY_SIZE(nokia770_i2c_board_info_2)); 260 + gpiod_add_lookup_table(&nokia770_cbus_gpio_table); 261 261 platform_device_register(&nokia770_cbus_device); 262 262 } 263 263 #else /* CONFIG_I2C_CBUS_GPIO */
+30 -50
drivers/i2c/busses/i2c-cbus-gpio.c
··· 18 18 19 19 #include <linux/io.h> 20 20 #include <linux/i2c.h> 21 - #include <linux/gpio.h> 22 21 #include <linux/slab.h> 23 22 #include <linux/delay.h> 24 23 #include <linux/errno.h> 25 24 #include <linux/kernel.h> 26 25 #include <linux/module.h> 27 - #include <linux/of_gpio.h> 26 + #include <linux/gpio/consumer.h> 28 27 #include <linux/interrupt.h> 29 28 #include <linux/platform_device.h> 30 - #include <linux/platform_data/i2c-cbus-gpio.h> 31 29 32 30 /* 33 31 * Bit counts are derived from Nokia implementation. These should be checked ··· 37 39 struct cbus_host { 38 40 spinlock_t lock; /* host lock */ 39 41 struct device *dev; 40 - int clk_gpio; 41 - int dat_gpio; 42 - int sel_gpio; 42 + struct gpio_desc *clk; 43 + struct gpio_desc *dat; 44 + struct gpio_desc *sel; 43 45 }; 44 46 45 47 /** ··· 49 51 */ 50 52 static void cbus_send_bit(struct cbus_host *host, unsigned bit) 51 53 { 52 - gpio_set_value(host->dat_gpio, bit ? 1 : 0); 53 - gpio_set_value(host->clk_gpio, 1); 54 - gpio_set_value(host->clk_gpio, 0); 54 + gpiod_set_value(host->dat, bit ? 1 : 0); 55 + gpiod_set_value(host->clk, 1); 56 + gpiod_set_value(host->clk, 0); 55 57 } 56 58 57 59 /** ··· 76 78 { 77 79 int ret; 78 80 79 - gpio_set_value(host->clk_gpio, 1); 80 - ret = gpio_get_value(host->dat_gpio); 81 - gpio_set_value(host->clk_gpio, 0); 81 + gpiod_set_value(host->clk, 1); 82 + ret = gpiod_get_value(host->dat); 83 + gpiod_set_value(host->clk, 0); 82 84 return ret; 83 85 } 84 86 ··· 121 123 spin_lock_irqsave(&host->lock, flags); 122 124 123 125 /* Reset state and start of transfer, SEL stays down during transfer */ 124 - gpio_set_value(host->sel_gpio, 0); 126 + gpiod_set_value(host->sel, 0); 125 127 126 128 /* Set the DAT pin to output */ 127 - gpio_direction_output(host->dat_gpio, 1); 129 + gpiod_direction_output(host->dat, 1); 128 130 129 131 /* Send the device address */ 130 132 cbus_send_data(host, dev, CBUS_ADDR_BITS); ··· 139 141 cbus_send_data(host, data, 16); 140 142 ret = 0; 141 143 } else { 142 - ret = gpio_direction_input(host->dat_gpio); 144 + ret = gpiod_direction_input(host->dat); 143 145 if (ret) { 144 146 dev_dbg(host->dev, "failed setting direction\n"); 145 147 goto out; 146 148 } 147 - gpio_set_value(host->clk_gpio, 1); 149 + gpiod_set_value(host->clk, 1); 148 150 149 151 ret = cbus_receive_word(host); 150 152 if (ret < 0) { ··· 154 156 } 155 157 156 158 /* Indicate end of transfer, SEL goes up until next transfer */ 157 - gpio_set_value(host->sel_gpio, 1); 158 - gpio_set_value(host->clk_gpio, 1); 159 - gpio_set_value(host->clk_gpio, 0); 159 + gpiod_set_value(host->sel, 1); 160 + gpiod_set_value(host->clk, 1); 161 + gpiod_set_value(host->clk, 0); 160 162 161 163 out: 162 164 spin_unlock_irqrestore(&host->lock, flags); ··· 212 214 { 213 215 struct i2c_adapter *adapter; 214 216 struct cbus_host *chost; 215 - int ret; 216 217 217 218 adapter = devm_kzalloc(&pdev->dev, sizeof(struct i2c_adapter), 218 219 GFP_KERNEL); ··· 222 225 if (!chost) 223 226 return -ENOMEM; 224 227 225 - if (pdev->dev.of_node) { 226 - struct device_node *dnode = pdev->dev.of_node; 227 - if (of_gpio_count(dnode) != 3) 228 - return -ENODEV; 229 - chost->clk_gpio = of_get_gpio(dnode, 0); 230 - chost->dat_gpio = of_get_gpio(dnode, 1); 231 - chost->sel_gpio = of_get_gpio(dnode, 2); 232 - } else if (dev_get_platdata(&pdev->dev)) { 233 - struct i2c_cbus_platform_data *pdata = 234 - dev_get_platdata(&pdev->dev); 235 - chost->clk_gpio = pdata->clk_gpio; 236 - chost->dat_gpio = pdata->dat_gpio; 237 - chost->sel_gpio = pdata->sel_gpio; 238 - } else { 228 + if (gpiod_count(&pdev->dev, NULL) != 3) 239 229 return -ENODEV; 240 - } 230 + chost->clk = devm_gpiod_get_index(&pdev->dev, NULL, 0, GPIOD_OUT_LOW); 231 + if (IS_ERR(chost->clk)) 232 + return PTR_ERR(chost->clk); 233 + chost->dat = devm_gpiod_get_index(&pdev->dev, NULL, 1, GPIOD_IN); 234 + if (IS_ERR(chost->dat)) 235 + return PTR_ERR(chost->dat); 236 + chost->sel = devm_gpiod_get_index(&pdev->dev, NULL, 2, GPIOD_OUT_HIGH); 237 + if (IS_ERR(chost->sel)) 238 + return PTR_ERR(chost->sel); 239 + gpiod_set_consumer_name(chost->clk, "CBUS clk"); 240 + gpiod_set_consumer_name(chost->dat, "CBUS dat"); 241 + gpiod_set_consumer_name(chost->sel, "CBUS sel"); 241 242 242 243 adapter->owner = THIS_MODULE; 243 244 adapter->class = I2C_CLASS_HWMON; ··· 248 253 249 254 spin_lock_init(&chost->lock); 250 255 chost->dev = &pdev->dev; 251 - 252 - ret = devm_gpio_request_one(&pdev->dev, chost->clk_gpio, 253 - GPIOF_OUT_INIT_LOW, "CBUS clk"); 254 - if (ret) 255 - return ret; 256 - 257 - ret = devm_gpio_request_one(&pdev->dev, chost->dat_gpio, GPIOF_IN, 258 - "CBUS data"); 259 - if (ret) 260 - return ret; 261 - 262 - ret = devm_gpio_request_one(&pdev->dev, chost->sel_gpio, 263 - GPIOF_OUT_INIT_HIGH, "CBUS sel"); 264 - if (ret) 265 - return ret; 266 256 267 257 i2c_set_adapdata(adapter, chost); 268 258 platform_set_drvdata(pdev, adapter);
-27
include/linux/platform_data/i2c-cbus-gpio.h
··· 1 - /* 2 - * i2c-cbus-gpio.h - CBUS I2C platform_data definition 3 - * 4 - * Copyright (C) 2004-2009 Nokia Corporation 5 - * 6 - * Written by Felipe Balbi and Aaro Koskinen. 7 - * 8 - * This file is subject to the terms and conditions of the GNU General 9 - * Public License. See the file "COPYING" in the main directory of this 10 - * archive for more details. 11 - * 12 - * This program is distributed in the hope that it will be useful, 13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 - * GNU General Public License for more details. 16 - */ 17 - 18 - #ifndef __INCLUDE_LINUX_I2C_CBUS_GPIO_H 19 - #define __INCLUDE_LINUX_I2C_CBUS_GPIO_H 20 - 21 - struct i2c_cbus_platform_data { 22 - int dat_gpio; 23 - int clk_gpio; 24 - int sel_gpio; 25 - }; 26 - 27 - #endif /* __INCLUDE_LINUX_I2C_CBUS_GPIO_H */