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

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>

authored by

Linus Walleij and committed by
Dmitry Torokhov
7395de64 e53c18da

+11 -14
+11 -13
drivers/input/joystick/as5011.c
··· 13 13 #include <linux/i2c.h> 14 14 #include <linux/interrupt.h> 15 15 #include <linux/input.h> 16 - #include <linux/gpio.h> 16 + #include <linux/gpio/consumer.h> 17 17 #include <linux/delay.h> 18 18 #include <linux/input/as5011.h> 19 19 #include <linux/slab.h> ··· 61 61 struct as5011_device { 62 62 struct input_dev *input_dev; 63 63 struct i2c_client *i2c_client; 64 - unsigned int button_gpio; 64 + struct gpio_desc *button_gpiod; 65 65 unsigned int button_irq; 66 66 unsigned int axis_irq; 67 67 }; ··· 114 114 static irqreturn_t as5011_button_interrupt(int irq, void *dev_id) 115 115 { 116 116 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); 118 118 119 119 input_report_key(as5011->input_dev, BTN_JOYSTICK, !val); 120 120 input_sync(as5011->input_dev); ··· 248 248 249 249 as5011->i2c_client = client; 250 250 as5011->input_dev = input_dev; 251 - as5011->button_gpio = plat_data->button_gpio; 252 251 as5011->axis_irq = plat_data->axis_irq; 253 252 254 253 input_dev->name = "Austria Microsystem as5011 joystick"; ··· 261 262 input_set_abs_params(as5011->input_dev, ABS_Y, 262 263 AS5011_MIN_AXIS, AS5011_MAX_AXIS, AS5011_FUZZ, AS5011_FLAT); 263 264 264 - error = gpio_request(as5011->button_gpio, "AS5011 button"); 265 - if (error < 0) { 266 - dev_err(&client->dev, "Failed to request button gpio\n"); 265 + as5011->button_gpiod = devm_gpiod_get(&client->dev, NULL, GPIOD_IN); 266 + if (IS_ERR(as5011->button_gpiod)) { 267 + error = PTR_ERR(as5011->button_gpiod); 268 + dev_err(&client->dev, "Failed to request button GPIO\n"); 267 269 goto err_free_mem; 268 270 } 271 + gpiod_set_consumer_name(as5011->button_gpiod, "AS5011 button"); 269 272 270 - irq = gpio_to_irq(as5011->button_gpio); 273 + irq = gpiod_to_irq(as5011->button_gpiod); 271 274 if (irq < 0) { 272 275 dev_err(&client->dev, 273 276 "Failed to get irq number for button gpio\n"); 274 277 error = irq; 275 - goto err_free_button_gpio; 278 + goto err_free_mem; 276 279 } 277 280 278 281 as5011->button_irq = irq; ··· 287 286 if (error < 0) { 288 287 dev_err(&client->dev, 289 288 "Can't allocate button irq %d\n", as5011->button_irq); 290 - goto err_free_button_gpio; 289 + goto err_free_mem; 291 290 } 292 291 293 292 error = as5011_configure_chip(as5011, plat_data); ··· 318 317 free_irq(as5011->axis_irq, as5011); 319 318 err_free_button_irq: 320 319 free_irq(as5011->button_irq, as5011); 321 - err_free_button_gpio: 322 - gpio_free(as5011->button_gpio); 323 320 err_free_mem: 324 321 input_free_device(input_dev); 325 322 kfree(as5011); ··· 331 332 332 333 free_irq(as5011->axis_irq, as5011); 333 334 free_irq(as5011->button_irq, as5011); 334 - gpio_free(as5011->button_gpio); 335 335 336 336 input_unregister_device(as5011->input_dev); 337 337 kfree(as5011);
-1
include/linux/input/as5011.h
··· 7 7 */ 8 8 9 9 struct as5011_platform_data { 10 - unsigned int button_gpio; 11 10 unsigned int axis_irq; /* irq number */ 12 11 unsigned long axis_irqflags; 13 12 char xp, xn; /* threshold for x axis */