Commit c95dc011 authored by Alexander Shiyan's avatar Alexander Shiyan Committed by Dmitry Torokhov

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: default avatarAlexander Shiyan <shc_work@mail.ru>
Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent 99e8325f
...@@ -224,7 +224,7 @@ config INPUT_GP2A ...@@ -224,7 +224,7 @@ config INPUT_GP2A
config INPUT_GPIO_BEEPER config INPUT_GPIO_BEEPER
tristate "Generic GPIO Beeper support" tristate "Generic GPIO Beeper support"
depends on OF_GPIO depends on GPIOLIB
help help
Say Y here if you have a beeper connected to a GPIO pin. Say Y here if you have a beeper connected to a GPIO pin.
......
/* /*
* Generic GPIO beeper driver * Generic GPIO beeper driver
* *
* Copyright (C) 2013 Alexander Shiyan <shc_work@mail.ru> * Copyright (C) 2013-2014 Alexander Shiyan <shc_work@mail.ru>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -11,7 +11,8 @@ ...@@ -11,7 +11,8 @@
#include <linux/input.h> #include <linux/input.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/of_gpio.h> #include <linux/gpio/consumer.h>
#include <linux/of.h>
#include <linux/workqueue.h> #include <linux/workqueue.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
...@@ -19,14 +20,13 @@ ...@@ -19,14 +20,13 @@
struct gpio_beeper { struct gpio_beeper {
struct work_struct work; struct work_struct work;
int gpio; struct gpio_desc *desc;
bool active_low;
bool beeping; bool beeping;
}; };
static void gpio_beeper_toggle(struct gpio_beeper *beep, bool on) static void gpio_beeper_toggle(struct gpio_beeper *beep, bool on)
{ {
gpio_set_value_cansleep(beep->gpio, on ^ beep->active_low); gpiod_set_value_cansleep(beep->desc, on);
} }
static void gpio_beeper_work(struct work_struct *work) static void gpio_beeper_work(struct work_struct *work)
...@@ -65,18 +65,16 @@ static void gpio_beeper_close(struct input_dev *input) ...@@ -65,18 +65,16 @@ static void gpio_beeper_close(struct input_dev *input)
static int gpio_beeper_probe(struct platform_device *pdev) static int gpio_beeper_probe(struct platform_device *pdev)
{ {
struct gpio_beeper *beep; struct gpio_beeper *beep;
enum of_gpio_flags flags;
struct input_dev *input; struct input_dev *input;
unsigned long gflags;
int err; int err;
beep = devm_kzalloc(&pdev->dev, sizeof(*beep), GFP_KERNEL); beep = devm_kzalloc(&pdev->dev, sizeof(*beep), GFP_KERNEL);
if (!beep) if (!beep)
return -ENOMEM; return -ENOMEM;
beep->gpio = of_get_gpio_flags(pdev->dev.of_node, 0, &flags); beep->desc = devm_gpiod_get(&pdev->dev, NULL);
if (!gpio_is_valid(beep->gpio)) if (IS_ERR(beep->desc))
return beep->gpio; return PTR_ERR(beep->desc);
input = devm_input_allocate_device(&pdev->dev); input = devm_input_allocate_device(&pdev->dev);
if (!input) if (!input)
...@@ -94,10 +92,7 @@ static int gpio_beeper_probe(struct platform_device *pdev) ...@@ -94,10 +92,7 @@ static int gpio_beeper_probe(struct platform_device *pdev)
input_set_capability(input, EV_SND, SND_BELL); input_set_capability(input, EV_SND, SND_BELL);
beep->active_low = flags & OF_GPIO_ACTIVE_LOW; err = gpiod_direction_output(beep->desc, 0);
gflags = beep->active_low ? GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW;
err = devm_gpio_request_one(&pdev->dev, beep->gpio, gflags, pdev->name);
if (err) if (err)
return err; return err;
...@@ -106,17 +101,19 @@ static int gpio_beeper_probe(struct platform_device *pdev) ...@@ -106,17 +101,19 @@ static int gpio_beeper_probe(struct platform_device *pdev)
return input_register_device(input); return input_register_device(input);
} }
#ifdef CONFIG_OF
static struct of_device_id gpio_beeper_of_match[] = { static struct of_device_id gpio_beeper_of_match[] = {
{ .compatible = BEEPER_MODNAME, }, { .compatible = BEEPER_MODNAME, },
{ } { }
}; };
MODULE_DEVICE_TABLE(of, gpio_beeper_of_match); MODULE_DEVICE_TABLE(of, gpio_beeper_of_match);
#endif
static struct platform_driver gpio_beeper_platform_driver = { static struct platform_driver gpio_beeper_platform_driver = {
.driver = { .driver = {
.name = BEEPER_MODNAME, .name = BEEPER_MODNAME,
.owner = THIS_MODULE, .owner = THIS_MODULE,
.of_match_table = gpio_beeper_of_match, .of_match_table = of_match_ptr(gpio_beeper_of_match),
}, },
.probe = gpio_beeper_probe, .probe = gpio_beeper_probe,
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment