2019-06-04 16:11:33 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2009-09-23 07:46:35 +08:00
|
|
|
/*
|
|
|
|
* Philips UCB1400 GPIO driver
|
|
|
|
*
|
|
|
|
* Author: Marek Vasut <marek.vasut@gmail.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/ucb1400.h>
|
2022-08-31 16:47:50 +08:00
|
|
|
#include <linux/gpio/driver.h>
|
2009-09-23 07:46:35 +08:00
|
|
|
|
|
|
|
static int ucb1400_gpio_dir_in(struct gpio_chip *gc, unsigned off)
|
|
|
|
{
|
|
|
|
struct ucb1400_gpio *gpio;
|
2015-12-07 22:01:14 +08:00
|
|
|
gpio = gpiochip_get_data(gc);
|
2009-09-23 07:46:35 +08:00
|
|
|
ucb1400_gpio_set_direction(gpio->ac97, off, 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ucb1400_gpio_dir_out(struct gpio_chip *gc, unsigned off, int val)
|
|
|
|
{
|
|
|
|
struct ucb1400_gpio *gpio;
|
2015-12-07 22:01:14 +08:00
|
|
|
gpio = gpiochip_get_data(gc);
|
2009-09-23 07:46:35 +08:00
|
|
|
ucb1400_gpio_set_direction(gpio->ac97, off, 1);
|
|
|
|
ucb1400_gpio_set_value(gpio->ac97, off, val);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ucb1400_gpio_get(struct gpio_chip *gc, unsigned off)
|
|
|
|
{
|
|
|
|
struct ucb1400_gpio *gpio;
|
2015-12-07 22:01:14 +08:00
|
|
|
|
|
|
|
gpio = gpiochip_get_data(gc);
|
2015-12-21 21:56:04 +08:00
|
|
|
return !!ucb1400_gpio_get_value(gpio->ac97, off);
|
2009-09-23 07:46:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ucb1400_gpio_set(struct gpio_chip *gc, unsigned off, int val)
|
|
|
|
{
|
|
|
|
struct ucb1400_gpio *gpio;
|
2015-12-07 22:01:14 +08:00
|
|
|
gpio = gpiochip_get_data(gc);
|
2009-09-23 07:46:35 +08:00
|
|
|
ucb1400_gpio_set_value(gpio->ac97, off, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ucb1400_gpio_probe(struct platform_device *dev)
|
|
|
|
{
|
2013-07-30 16:08:05 +08:00
|
|
|
struct ucb1400_gpio *ucb = dev_get_platdata(&dev->dev);
|
2009-09-23 07:46:35 +08:00
|
|
|
int err = 0;
|
|
|
|
|
2013-04-15 02:35:48 +08:00
|
|
|
if (!(ucb && ucb->gpio_offset)) {
|
2009-09-23 07:46:35 +08:00
|
|
|
err = -EINVAL;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
platform_set_drvdata(dev, ucb);
|
|
|
|
|
|
|
|
ucb->gc.label = "ucb1400_gpio";
|
2013-04-15 02:35:48 +08:00
|
|
|
ucb->gc.base = ucb->gpio_offset;
|
2009-09-23 07:46:35 +08:00
|
|
|
ucb->gc.ngpio = 10;
|
|
|
|
ucb->gc.owner = THIS_MODULE;
|
|
|
|
|
|
|
|
ucb->gc.direction_input = ucb1400_gpio_dir_in;
|
|
|
|
ucb->gc.direction_output = ucb1400_gpio_dir_out;
|
|
|
|
ucb->gc.get = ucb1400_gpio_get;
|
|
|
|
ucb->gc.set = ucb1400_gpio_set;
|
2013-12-04 21:42:46 +08:00
|
|
|
ucb->gc.can_sleep = true;
|
2009-09-23 07:46:35 +08:00
|
|
|
|
2016-02-22 20:13:28 +08:00
|
|
|
err = devm_gpiochip_add_data(&dev->dev, &ucb->gc, ucb);
|
2009-09-23 07:46:35 +08:00
|
|
|
|
|
|
|
err:
|
|
|
|
return err;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct platform_driver ucb1400_gpio_driver = {
|
|
|
|
.probe = ucb1400_gpio_probe,
|
|
|
|
.driver = {
|
|
|
|
.name = "ucb1400_gpio"
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2011-12-08 00:24:00 +08:00
|
|
|
module_platform_driver(ucb1400_gpio_driver);
|
2009-09-23 07:46:35 +08:00
|
|
|
|
|
|
|
MODULE_DESCRIPTION("Philips UCB1400 GPIO driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
2013-11-19 15:31:20 +08:00
|
|
|
MODULE_ALIAS("platform:ucb1400_gpio");
|