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

Input: gpio-beeper - simplify GPIO handling

This patch simplifies GPIO handling in the driver by using GPIO functions
based on descriptors. As a result this driver now can be used for boards
without DT support.

Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

authored by

Alexander Shiyan and committed by
Dmitry Torokhov
c95dc011 99e8325f

+13 -16
+1 -1
drivers/input/misc/Kconfig
··· 224 224 225 225 config INPUT_GPIO_BEEPER 226 226 tristate "Generic GPIO Beeper support" 227 - depends on OF_GPIO 227 + depends on GPIOLIB 228 228 help 229 229 Say Y here if you have a beeper connected to a GPIO pin. 230 230
+12 -15
drivers/input/misc/gpio-beeper.c
··· 1 1 /* 2 2 * Generic GPIO beeper driver 3 3 * 4 - * Copyright (C) 2013 Alexander Shiyan <shc_work@mail.ru> 4 + * Copyright (C) 2013-2014 Alexander Shiyan <shc_work@mail.ru> 5 5 * 6 6 * This program is free software; you can redistribute it and/or modify 7 7 * it under the terms of the GNU General Public License as published by ··· 11 11 12 12 #include <linux/input.h> 13 13 #include <linux/module.h> 14 - #include <linux/of_gpio.h> 14 + #include <linux/gpio/consumer.h> 15 + #include <linux/of.h> 15 16 #include <linux/workqueue.h> 16 17 #include <linux/platform_device.h> 17 18 ··· 20 19 21 20 struct gpio_beeper { 22 21 struct work_struct work; 23 - int gpio; 24 - bool active_low; 22 + struct gpio_desc *desc; 25 23 bool beeping; 26 24 }; 27 25 28 26 static void gpio_beeper_toggle(struct gpio_beeper *beep, bool on) 29 27 { 30 - gpio_set_value_cansleep(beep->gpio, on ^ beep->active_low); 28 + gpiod_set_value_cansleep(beep->desc, on); 31 29 } 32 30 33 31 static void gpio_beeper_work(struct work_struct *work) ··· 65 65 static int gpio_beeper_probe(struct platform_device *pdev) 66 66 { 67 67 struct gpio_beeper *beep; 68 - enum of_gpio_flags flags; 69 68 struct input_dev *input; 70 - unsigned long gflags; 71 69 int err; 72 70 73 71 beep = devm_kzalloc(&pdev->dev, sizeof(*beep), GFP_KERNEL); 74 72 if (!beep) 75 73 return -ENOMEM; 76 74 77 - beep->gpio = of_get_gpio_flags(pdev->dev.of_node, 0, &flags); 78 - if (!gpio_is_valid(beep->gpio)) 79 - return beep->gpio; 75 + beep->desc = devm_gpiod_get(&pdev->dev, NULL); 76 + if (IS_ERR(beep->desc)) 77 + return PTR_ERR(beep->desc); 80 78 81 79 input = devm_input_allocate_device(&pdev->dev); 82 80 if (!input) ··· 92 94 93 95 input_set_capability(input, EV_SND, SND_BELL); 94 96 95 - beep->active_low = flags & OF_GPIO_ACTIVE_LOW; 96 - gflags = beep->active_low ? GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW; 97 - 98 - err = devm_gpio_request_one(&pdev->dev, beep->gpio, gflags, pdev->name); 97 + err = gpiod_direction_output(beep->desc, 0); 99 98 if (err) 100 99 return err; 101 100 ··· 101 106 return input_register_device(input); 102 107 } 103 108 109 + #ifdef CONFIG_OF 104 110 static struct of_device_id gpio_beeper_of_match[] = { 105 111 { .compatible = BEEPER_MODNAME, }, 106 112 { } 107 113 }; 108 114 MODULE_DEVICE_TABLE(of, gpio_beeper_of_match); 115 + #endif 109 116 110 117 static struct platform_driver gpio_beeper_platform_driver = { 111 118 .driver = { 112 119 .name = BEEPER_MODNAME, 113 120 .owner = THIS_MODULE, 114 - .of_match_table = gpio_beeper_of_match, 121 + .of_match_table = of_match_ptr(gpio_beeper_of_match), 115 122 }, 116 123 .probe = gpio_beeper_probe, 117 124 };