Skip to content

Commit 7395de6

Browse files
Linus Walleijdtor
authored andcommitted
Input: as5011 - convert to GPIO descriptor
This driver does not have any in-tree users but is passing a legacy GPIO number through platform data. Convert it to use a GPIO descriptor, new users or outoftree users can easily be implemented using GPIO descriptor tables or software nodes. Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Link: https://lore.kernel.org/r/20231129-descriptors-input-v1-4-9433162914a3@linaro.org Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
1 parent e53c18d commit 7395de6

2 files changed

Lines changed: 11 additions & 14 deletions

File tree

drivers/input/joystick/as5011.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include <linux/i2c.h>
1414
#include <linux/interrupt.h>
1515
#include <linux/input.h>
16-
#include <linux/gpio.h>
16+
#include <linux/gpio/consumer.h>
1717
#include <linux/delay.h>
1818
#include <linux/input/as5011.h>
1919
#include <linux/slab.h>
@@ -61,7 +61,7 @@ MODULE_LICENSE("GPL");
6161
struct as5011_device {
6262
struct input_dev *input_dev;
6363
struct i2c_client *i2c_client;
64-
unsigned int button_gpio;
64+
struct gpio_desc *button_gpiod;
6565
unsigned int button_irq;
6666
unsigned int axis_irq;
6767
};
@@ -114,7 +114,7 @@ static int as5011_i2c_read(struct i2c_client *client,
114114
static irqreturn_t as5011_button_interrupt(int irq, void *dev_id)
115115
{
116116
struct as5011_device *as5011 = dev_id;
117-
int val = gpio_get_value_cansleep(as5011->button_gpio);
117+
int val = gpiod_get_value_cansleep(as5011->button_gpiod);
118118

119119
input_report_key(as5011->input_dev, BTN_JOYSTICK, !val);
120120
input_sync(as5011->input_dev);
@@ -248,7 +248,6 @@ static int as5011_probe(struct i2c_client *client)
248248

249249
as5011->i2c_client = client;
250250
as5011->input_dev = input_dev;
251-
as5011->button_gpio = plat_data->button_gpio;
252251
as5011->axis_irq = plat_data->axis_irq;
253252

254253
input_dev->name = "Austria Microsystem as5011 joystick";
@@ -262,18 +261,20 @@ static int as5011_probe(struct i2c_client *client)
262261
input_set_abs_params(as5011->input_dev, ABS_Y,
263262
AS5011_MIN_AXIS, AS5011_MAX_AXIS, AS5011_FUZZ, AS5011_FLAT);
264263

265-
error = gpio_request(as5011->button_gpio, "AS5011 button");
266-
if (error < 0) {
267-
dev_err(&client->dev, "Failed to request button gpio\n");
264+
as5011->button_gpiod = devm_gpiod_get(&client->dev, NULL, GPIOD_IN);
265+
if (IS_ERR(as5011->button_gpiod)) {
266+
error = PTR_ERR(as5011->button_gpiod);
267+
dev_err(&client->dev, "Failed to request button GPIO\n");
268268
goto err_free_mem;
269269
}
270+
gpiod_set_consumer_name(as5011->button_gpiod, "AS5011 button");
270271

271-
irq = gpio_to_irq(as5011->button_gpio);
272+
irq = gpiod_to_irq(as5011->button_gpiod);
272273
if (irq < 0) {
273274
dev_err(&client->dev,
274275
"Failed to get irq number for button gpio\n");
275276
error = irq;
276-
goto err_free_button_gpio;
277+
goto err_free_mem;
277278
}
278279

279280
as5011->button_irq = irq;
@@ -286,7 +287,7 @@ static int as5011_probe(struct i2c_client *client)
286287
if (error < 0) {
287288
dev_err(&client->dev,
288289
"Can't allocate button irq %d\n", as5011->button_irq);
289-
goto err_free_button_gpio;
290+
goto err_free_mem;
290291
}
291292

292293
error = as5011_configure_chip(as5011, plat_data);
@@ -317,8 +318,6 @@ static int as5011_probe(struct i2c_client *client)
317318
free_irq(as5011->axis_irq, as5011);
318319
err_free_button_irq:
319320
free_irq(as5011->button_irq, as5011);
320-
err_free_button_gpio:
321-
gpio_free(as5011->button_gpio);
322321
err_free_mem:
323322
input_free_device(input_dev);
324323
kfree(as5011);
@@ -332,7 +331,6 @@ static void as5011_remove(struct i2c_client *client)
332331

333332
free_irq(as5011->axis_irq, as5011);
334333
free_irq(as5011->button_irq, as5011);
335-
gpio_free(as5011->button_gpio);
336334

337335
input_unregister_device(as5011->input_dev);
338336
kfree(as5011);

include/linux/input/as5011.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88

99
struct as5011_platform_data {
10-
unsigned int button_gpio;
1110
unsigned int axis_irq; /* irq number */
1211
unsigned long axis_irqflags;
1312
char xp, xn; /* threshold for x axis */

0 commit comments

Comments
 (0)