1 // SPDX-License-Identifier: GPL-2.0-only
3 * Philips UCB1400 GPIO driver
5 * Author: Marek Vasut <marek.vasut@gmail.com>
8 #include <linux/module.h>
9 #include <linux/ucb1400.h>
10 #include <linux/gpio/driver.h>
12 static int ucb1400_gpio_dir_in(struct gpio_chip *gc, unsigned off)
14 struct ucb1400_gpio *gpio;
15 gpio = gpiochip_get_data(gc);
16 ucb1400_gpio_set_direction(gpio->ac97, off, 0);
20 static int ucb1400_gpio_dir_out(struct gpio_chip *gc, unsigned off, int val)
22 struct ucb1400_gpio *gpio;
23 gpio = gpiochip_get_data(gc);
24 ucb1400_gpio_set_direction(gpio->ac97, off, 1);
25 ucb1400_gpio_set_value(gpio->ac97, off, val);
29 static int ucb1400_gpio_get(struct gpio_chip *gc, unsigned off)
31 struct ucb1400_gpio *gpio;
33 gpio = gpiochip_get_data(gc);
34 return !!ucb1400_gpio_get_value(gpio->ac97, off);
37 static void ucb1400_gpio_set(struct gpio_chip *gc, unsigned off, int val)
39 struct ucb1400_gpio *gpio;
40 gpio = gpiochip_get_data(gc);
41 ucb1400_gpio_set_value(gpio->ac97, off, val);
44 static int ucb1400_gpio_probe(struct platform_device *dev)
46 struct ucb1400_gpio *ucb = dev_get_platdata(&dev->dev);
49 if (!(ucb && ucb->gpio_offset)) {
54 platform_set_drvdata(dev, ucb);
56 ucb->gc.label = "ucb1400_gpio";
57 ucb->gc.base = ucb->gpio_offset;
59 ucb->gc.owner = THIS_MODULE;
61 ucb->gc.direction_input = ucb1400_gpio_dir_in;
62 ucb->gc.direction_output = ucb1400_gpio_dir_out;
63 ucb->gc.get = ucb1400_gpio_get;
64 ucb->gc.set = ucb1400_gpio_set;
65 ucb->gc.can_sleep = true;
67 err = devm_gpiochip_add_data(&dev->dev, &ucb->gc, ucb);
74 static struct platform_driver ucb1400_gpio_driver = {
75 .probe = ucb1400_gpio_probe,
77 .name = "ucb1400_gpio"
81 module_platform_driver(ucb1400_gpio_driver);
83 MODULE_DESCRIPTION("Philips UCB1400 GPIO driver");
84 MODULE_LICENSE("GPL");
85 MODULE_ALIAS("platform:ucb1400_gpio");