hc
2024-10-12 a5969cabbb4660eab42b6ef0412cbbd1200cf14d
kernel/drivers/i2c/busses/i2c-cbus-gpio.c
....@@ -18,16 +18,14 @@
1818
1919 #include <linux/io.h>
2020 #include <linux/i2c.h>
21
-#include <linux/gpio.h>
2221 #include <linux/slab.h>
2322 #include <linux/delay.h>
2423 #include <linux/errno.h>
2524 #include <linux/kernel.h>
2625 #include <linux/module.h>
27
-#include <linux/of_gpio.h>
26
+#include <linux/gpio/consumer.h>
2827 #include <linux/interrupt.h>
2928 #include <linux/platform_device.h>
30
-#include <linux/platform_data/i2c-cbus-gpio.h>
3129
3230 /*
3331 * Bit counts are derived from Nokia implementation. These should be checked
....@@ -39,9 +37,9 @@
3937 struct cbus_host {
4038 spinlock_t lock; /* host lock */
4139 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;
4543 };
4644
4745 /**
....@@ -51,9 +49,9 @@
5149 */
5250 static void cbus_send_bit(struct cbus_host *host, unsigned bit)
5351 {
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);
5755 }
5856
5957 /**
....@@ -78,9 +76,9 @@
7876 {
7977 int ret;
8078
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);
8482 return ret;
8583 }
8684
....@@ -123,10 +121,10 @@
123121 spin_lock_irqsave(&host->lock, flags);
124122
125123 /* 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);
127125
128126 /* Set the DAT pin to output */
129
- gpio_direction_output(host->dat_gpio, 1);
127
+ gpiod_direction_output(host->dat, 1);
130128
131129 /* Send the device address */
132130 cbus_send_data(host, dev, CBUS_ADDR_BITS);
....@@ -141,12 +139,12 @@
141139 cbus_send_data(host, data, 16);
142140 ret = 0;
143141 } else {
144
- ret = gpio_direction_input(host->dat_gpio);
142
+ ret = gpiod_direction_input(host->dat);
145143 if (ret) {
146144 dev_dbg(host->dev, "failed setting direction\n");
147145 goto out;
148146 }
149
- gpio_set_value(host->clk_gpio, 1);
147
+ gpiod_set_value(host->clk, 1);
150148
151149 ret = cbus_receive_word(host);
152150 if (ret < 0) {
....@@ -156,9 +154,9 @@
156154 }
157155
158156 /* 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);
162160
163161 out:
164162 spin_unlock_irqrestore(&host->lock, flags);
....@@ -197,8 +195,9 @@
197195 }
198196
199197 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,
202201 };
203202
204203 static int cbus_i2c_remove(struct platform_device *pdev)
....@@ -214,7 +213,6 @@
214213 {
215214 struct i2c_adapter *adapter;
216215 struct cbus_host *chost;
217
- int ret;
218216
219217 adapter = devm_kzalloc(&pdev->dev, sizeof(struct i2c_adapter),
220218 GFP_KERNEL);
....@@ -225,22 +223,20 @@
225223 if (!chost)
226224 return -ENOMEM;
227225
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)
242227 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");
244240
245241 adapter->owner = THIS_MODULE;
246242 adapter->class = I2C_CLASS_HWMON;
....@@ -253,21 +249,6 @@
253249
254250 spin_lock_init(&chost->lock);
255251 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;
271252
272253 i2c_set_adapdata(adapter, chost);
273254 platform_set_drvdata(pdev, adapter);