Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / gpio / gpio-ucb1400.c
blobd2a8644864c39f02d2bea8c981ad10098de78df1
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Philips UCB1400 GPIO driver
5 * Author: Marek Vasut <marek.vasut@gmail.com>
6 */
8 #include <linux/module.h>
9 #include <linux/ucb1400.h>
11 static int ucb1400_gpio_dir_in(struct gpio_chip *gc, unsigned off)
13 struct ucb1400_gpio *gpio;
14 gpio = gpiochip_get_data(gc);
15 ucb1400_gpio_set_direction(gpio->ac97, off, 0);
16 return 0;
19 static int ucb1400_gpio_dir_out(struct gpio_chip *gc, unsigned off, int val)
21 struct ucb1400_gpio *gpio;
22 gpio = gpiochip_get_data(gc);
23 ucb1400_gpio_set_direction(gpio->ac97, off, 1);
24 ucb1400_gpio_set_value(gpio->ac97, off, val);
25 return 0;
28 static int ucb1400_gpio_get(struct gpio_chip *gc, unsigned off)
30 struct ucb1400_gpio *gpio;
32 gpio = gpiochip_get_data(gc);
33 return !!ucb1400_gpio_get_value(gpio->ac97, off);
36 static void ucb1400_gpio_set(struct gpio_chip *gc, unsigned off, int val)
38 struct ucb1400_gpio *gpio;
39 gpio = gpiochip_get_data(gc);
40 ucb1400_gpio_set_value(gpio->ac97, off, val);
43 static int ucb1400_gpio_probe(struct platform_device *dev)
45 struct ucb1400_gpio *ucb = dev_get_platdata(&dev->dev);
46 int err = 0;
48 if (!(ucb && ucb->gpio_offset)) {
49 err = -EINVAL;
50 goto err;
53 platform_set_drvdata(dev, ucb);
55 ucb->gc.label = "ucb1400_gpio";
56 ucb->gc.base = ucb->gpio_offset;
57 ucb->gc.ngpio = 10;
58 ucb->gc.owner = THIS_MODULE;
60 ucb->gc.direction_input = ucb1400_gpio_dir_in;
61 ucb->gc.direction_output = ucb1400_gpio_dir_out;
62 ucb->gc.get = ucb1400_gpio_get;
63 ucb->gc.set = ucb1400_gpio_set;
64 ucb->gc.can_sleep = true;
66 err = devm_gpiochip_add_data(&dev->dev, &ucb->gc, ucb);
67 if (err)
68 goto err;
70 if (ucb->gpio_setup)
71 err = ucb->gpio_setup(&dev->dev, ucb->gc.ngpio);
73 err:
74 return err;
78 static int ucb1400_gpio_remove(struct platform_device *dev)
80 int err = 0;
81 struct ucb1400_gpio *ucb = platform_get_drvdata(dev);
83 if (ucb && ucb->gpio_teardown) {
84 err = ucb->gpio_teardown(&dev->dev, ucb->gc.ngpio);
85 if (err)
86 return err;
89 return err;
92 static struct platform_driver ucb1400_gpio_driver = {
93 .probe = ucb1400_gpio_probe,
94 .remove = ucb1400_gpio_remove,
95 .driver = {
96 .name = "ucb1400_gpio"
100 module_platform_driver(ucb1400_gpio_driver);
102 MODULE_DESCRIPTION("Philips UCB1400 GPIO driver");
103 MODULE_LICENSE("GPL");
104 MODULE_ALIAS("platform:ucb1400_gpio");