| .. | .. |
|---|
| 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 |
|---|
| .. | .. |
|---|
| 39 | 37 | struct cbus_host { |
|---|
| 40 | 38 | spinlock_t lock; /* host lock */ |
|---|
| 41 | 39 | struct device *dev; |
|---|
| 42 | | - int clk_gpio; |
|---|
| 43 | | - int dat_gpio; |
|---|
| 44 | | - int sel_gpio; |
|---|
| 40 | + struct gpio_desc *clk; |
|---|
| 41 | + struct gpio_desc *dat; |
|---|
| 42 | + struct gpio_desc *sel; |
|---|
| 45 | 43 | }; |
|---|
| 46 | 44 | |
|---|
| 47 | 45 | /** |
|---|
| .. | .. |
|---|
| 51 | 49 | */ |
|---|
| 52 | 50 | static void cbus_send_bit(struct cbus_host *host, unsigned bit) |
|---|
| 53 | 51 | { |
|---|
| 54 | | - gpio_set_value(host->dat_gpio, bit ? 1 : 0); |
|---|
| 55 | | - gpio_set_value(host->clk_gpio, 1); |
|---|
| 56 | | - gpio_set_value(host->clk_gpio, 0); |
|---|
| 52 | + gpiod_set_value(host->dat, bit ? 1 : 0); |
|---|
| 53 | + gpiod_set_value(host->clk, 1); |
|---|
| 54 | + gpiod_set_value(host->clk, 0); |
|---|
| 57 | 55 | } |
|---|
| 58 | 56 | |
|---|
| 59 | 57 | /** |
|---|
| .. | .. |
|---|
| 78 | 76 | { |
|---|
| 79 | 77 | int ret; |
|---|
| 80 | 78 | |
|---|
| 81 | | - gpio_set_value(host->clk_gpio, 1); |
|---|
| 82 | | - ret = gpio_get_value(host->dat_gpio); |
|---|
| 83 | | - gpio_set_value(host->clk_gpio, 0); |
|---|
| 79 | + gpiod_set_value(host->clk, 1); |
|---|
| 80 | + ret = gpiod_get_value(host->dat); |
|---|
| 81 | + gpiod_set_value(host->clk, 0); |
|---|
| 84 | 82 | return ret; |
|---|
| 85 | 83 | } |
|---|
| 86 | 84 | |
|---|
| .. | .. |
|---|
| 123 | 121 | spin_lock_irqsave(&host->lock, flags); |
|---|
| 124 | 122 | |
|---|
| 125 | 123 | /* Reset state and start of transfer, SEL stays down during transfer */ |
|---|
| 126 | | - gpio_set_value(host->sel_gpio, 0); |
|---|
| 124 | + gpiod_set_value(host->sel, 0); |
|---|
| 127 | 125 | |
|---|
| 128 | 126 | /* Set the DAT pin to output */ |
|---|
| 129 | | - gpio_direction_output(host->dat_gpio, 1); |
|---|
| 127 | + gpiod_direction_output(host->dat, 1); |
|---|
| 130 | 128 | |
|---|
| 131 | 129 | /* Send the device address */ |
|---|
| 132 | 130 | cbus_send_data(host, dev, CBUS_ADDR_BITS); |
|---|
| .. | .. |
|---|
| 141 | 139 | cbus_send_data(host, data, 16); |
|---|
| 142 | 140 | ret = 0; |
|---|
| 143 | 141 | } else { |
|---|
| 144 | | - ret = gpio_direction_input(host->dat_gpio); |
|---|
| 142 | + ret = gpiod_direction_input(host->dat); |
|---|
| 145 | 143 | if (ret) { |
|---|
| 146 | 144 | dev_dbg(host->dev, "failed setting direction\n"); |
|---|
| 147 | 145 | goto out; |
|---|
| 148 | 146 | } |
|---|
| 149 | | - gpio_set_value(host->clk_gpio, 1); |
|---|
| 147 | + gpiod_set_value(host->clk, 1); |
|---|
| 150 | 148 | |
|---|
| 151 | 149 | ret = cbus_receive_word(host); |
|---|
| 152 | 150 | if (ret < 0) { |
|---|
| .. | .. |
|---|
| 156 | 154 | } |
|---|
| 157 | 155 | |
|---|
| 158 | 156 | /* Indicate end of transfer, SEL goes up until next transfer */ |
|---|
| 159 | | - gpio_set_value(host->sel_gpio, 1); |
|---|
| 160 | | - gpio_set_value(host->clk_gpio, 1); |
|---|
| 161 | | - gpio_set_value(host->clk_gpio, 0); |
|---|
| 157 | + gpiod_set_value(host->sel, 1); |
|---|
| 158 | + gpiod_set_value(host->clk, 1); |
|---|
| 159 | + gpiod_set_value(host->clk, 0); |
|---|
| 162 | 160 | |
|---|
| 163 | 161 | out: |
|---|
| 164 | 162 | spin_unlock_irqrestore(&host->lock, flags); |
|---|
| .. | .. |
|---|
| 197 | 195 | } |
|---|
| 198 | 196 | |
|---|
| 199 | 197 | static const struct i2c_algorithm cbus_i2c_algo = { |
|---|
| 200 | | - .smbus_xfer = cbus_i2c_smbus_xfer, |
|---|
| 201 | | - .functionality = cbus_i2c_func, |
|---|
| 198 | + .smbus_xfer = cbus_i2c_smbus_xfer, |
|---|
| 199 | + .smbus_xfer_atomic = cbus_i2c_smbus_xfer, |
|---|
| 200 | + .functionality = cbus_i2c_func, |
|---|
| 202 | 201 | }; |
|---|
| 203 | 202 | |
|---|
| 204 | 203 | static int cbus_i2c_remove(struct platform_device *pdev) |
|---|
| .. | .. |
|---|
| 214 | 213 | { |
|---|
| 215 | 214 | struct i2c_adapter *adapter; |
|---|
| 216 | 215 | struct cbus_host *chost; |
|---|
| 217 | | - int ret; |
|---|
| 218 | 216 | |
|---|
| 219 | 217 | adapter = devm_kzalloc(&pdev->dev, sizeof(struct i2c_adapter), |
|---|
| 220 | 218 | GFP_KERNEL); |
|---|
| .. | .. |
|---|
| 225 | 223 | if (!chost) |
|---|
| 226 | 224 | return -ENOMEM; |
|---|
| 227 | 225 | |
|---|
| 228 | | - if (pdev->dev.of_node) { |
|---|
| 229 | | - struct device_node *dnode = pdev->dev.of_node; |
|---|
| 230 | | - if (of_gpio_count(dnode) != 3) |
|---|
| 231 | | - return -ENODEV; |
|---|
| 232 | | - chost->clk_gpio = of_get_gpio(dnode, 0); |
|---|
| 233 | | - chost->dat_gpio = of_get_gpio(dnode, 1); |
|---|
| 234 | | - chost->sel_gpio = of_get_gpio(dnode, 2); |
|---|
| 235 | | - } else if (dev_get_platdata(&pdev->dev)) { |
|---|
| 236 | | - struct i2c_cbus_platform_data *pdata = |
|---|
| 237 | | - dev_get_platdata(&pdev->dev); |
|---|
| 238 | | - chost->clk_gpio = pdata->clk_gpio; |
|---|
| 239 | | - chost->dat_gpio = pdata->dat_gpio; |
|---|
| 240 | | - chost->sel_gpio = pdata->sel_gpio; |
|---|
| 241 | | - } else { |
|---|
| 226 | + if (gpiod_count(&pdev->dev, NULL) != 3) |
|---|
| 242 | 227 | return -ENODEV; |
|---|
| 243 | | - } |
|---|
| 228 | + chost->clk = devm_gpiod_get_index(&pdev->dev, NULL, 0, GPIOD_OUT_LOW); |
|---|
| 229 | + if (IS_ERR(chost->clk)) |
|---|
| 230 | + return PTR_ERR(chost->clk); |
|---|
| 231 | + chost->dat = devm_gpiod_get_index(&pdev->dev, NULL, 1, GPIOD_IN); |
|---|
| 232 | + if (IS_ERR(chost->dat)) |
|---|
| 233 | + return PTR_ERR(chost->dat); |
|---|
| 234 | + chost->sel = devm_gpiod_get_index(&pdev->dev, NULL, 2, GPIOD_OUT_HIGH); |
|---|
| 235 | + if (IS_ERR(chost->sel)) |
|---|
| 236 | + return PTR_ERR(chost->sel); |
|---|
| 237 | + gpiod_set_consumer_name(chost->clk, "CBUS clk"); |
|---|
| 238 | + gpiod_set_consumer_name(chost->dat, "CBUS dat"); |
|---|
| 239 | + gpiod_set_consumer_name(chost->sel, "CBUS sel"); |
|---|
| 244 | 240 | |
|---|
| 245 | 241 | adapter->owner = THIS_MODULE; |
|---|
| 246 | 242 | adapter->class = I2C_CLASS_HWMON; |
|---|
| .. | .. |
|---|
| 253 | 249 | |
|---|
| 254 | 250 | spin_lock_init(&chost->lock); |
|---|
| 255 | 251 | chost->dev = &pdev->dev; |
|---|
| 256 | | - |
|---|
| 257 | | - ret = devm_gpio_request_one(&pdev->dev, chost->clk_gpio, |
|---|
| 258 | | - GPIOF_OUT_INIT_LOW, "CBUS clk"); |
|---|
| 259 | | - if (ret) |
|---|
| 260 | | - return ret; |
|---|
| 261 | | - |
|---|
| 262 | | - ret = devm_gpio_request_one(&pdev->dev, chost->dat_gpio, GPIOF_IN, |
|---|
| 263 | | - "CBUS data"); |
|---|
| 264 | | - if (ret) |
|---|
| 265 | | - return ret; |
|---|
| 266 | | - |
|---|
| 267 | | - ret = devm_gpio_request_one(&pdev->dev, chost->sel_gpio, |
|---|
| 268 | | - GPIOF_OUT_INIT_HIGH, "CBUS sel"); |
|---|
| 269 | | - if (ret) |
|---|
| 270 | | - return ret; |
|---|
| 271 | 252 | |
|---|
| 272 | 253 | i2c_set_adapdata(adapter, chost); |
|---|
| 273 | 254 | platform_set_drvdata(pdev, adapter); |
|---|