blob: d2a8644864c39f02d2bea8c981ad10098de78df1 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Marek Vasut4cf8e532009-09-22 16:46:35 -07002/*
3 * Philips UCB1400 GPIO driver
4 *
5 * Author: Marek Vasut <marek.vasut@gmail.com>
Marek Vasut4cf8e532009-09-22 16:46:35 -07006 */
7
8#include <linux/module.h>
9#include <linux/ucb1400.h>
10
Marek Vasut4cf8e532009-09-22 16:46:35 -070011static int ucb1400_gpio_dir_in(struct gpio_chip *gc, unsigned off)
12{
13 struct ucb1400_gpio *gpio;
Linus Walleij9af4f0a2015-12-07 15:01:14 +010014 gpio = gpiochip_get_data(gc);
Marek Vasut4cf8e532009-09-22 16:46:35 -070015 ucb1400_gpio_set_direction(gpio->ac97, off, 0);
16 return 0;
17}
18
19static int ucb1400_gpio_dir_out(struct gpio_chip *gc, unsigned off, int val)
20{
21 struct ucb1400_gpio *gpio;
Linus Walleij9af4f0a2015-12-07 15:01:14 +010022 gpio = gpiochip_get_data(gc);
Marek Vasut4cf8e532009-09-22 16:46:35 -070023 ucb1400_gpio_set_direction(gpio->ac97, off, 1);
24 ucb1400_gpio_set_value(gpio->ac97, off, val);
25 return 0;
26}
27
28static int ucb1400_gpio_get(struct gpio_chip *gc, unsigned off)
29{
30 struct ucb1400_gpio *gpio;
Linus Walleij9af4f0a2015-12-07 15:01:14 +010031
32 gpio = gpiochip_get_data(gc);
Linus Walleijc9d4ab02015-12-21 14:56:04 +010033 return !!ucb1400_gpio_get_value(gpio->ac97, off);
Marek Vasut4cf8e532009-09-22 16:46:35 -070034}
35
36static void ucb1400_gpio_set(struct gpio_chip *gc, unsigned off, int val)
37{
38 struct ucb1400_gpio *gpio;
Linus Walleij9af4f0a2015-12-07 15:01:14 +010039 gpio = gpiochip_get_data(gc);
Marek Vasut4cf8e532009-09-22 16:46:35 -070040 ucb1400_gpio_set_value(gpio->ac97, off, val);
41}
42
43static int ucb1400_gpio_probe(struct platform_device *dev)
44{
Jingoo Hane56aee12013-07-30 17:08:05 +090045 struct ucb1400_gpio *ucb = dev_get_platdata(&dev->dev);
Marek Vasut4cf8e532009-09-22 16:46:35 -070046 int err = 0;
47
Marek Vasut360e64d2013-04-14 20:35:48 +020048 if (!(ucb && ucb->gpio_offset)) {
Marek Vasut4cf8e532009-09-22 16:46:35 -070049 err = -EINVAL;
50 goto err;
51 }
52
53 platform_set_drvdata(dev, ucb);
54
55 ucb->gc.label = "ucb1400_gpio";
Marek Vasut360e64d2013-04-14 20:35:48 +020056 ucb->gc.base = ucb->gpio_offset;
Marek Vasut4cf8e532009-09-22 16:46:35 -070057 ucb->gc.ngpio = 10;
58 ucb->gc.owner = THIS_MODULE;
59
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;
Linus Walleij9fb1f392013-12-04 14:42:46 +010064 ucb->gc.can_sleep = true;
Marek Vasut4cf8e532009-09-22 16:46:35 -070065
Laxman Dewangan5d61a9e2016-02-22 17:43:28 +053066 err = devm_gpiochip_add_data(&dev->dev, &ucb->gc, ucb);
Marek Vasut4cf8e532009-09-22 16:46:35 -070067 if (err)
68 goto err;
69
Rickard Strandqvist31a3f9d2014-06-26 18:18:51 +020070 if (ucb->gpio_setup)
Marek Vasut360e64d2013-04-14 20:35:48 +020071 err = ucb->gpio_setup(&dev->dev, ucb->gc.ngpio);
Marek Vasut4cf8e532009-09-22 16:46:35 -070072
73err:
74 return err;
75
76}
77
78static int ucb1400_gpio_remove(struct platform_device *dev)
79{
80 int err = 0;
81 struct ucb1400_gpio *ucb = platform_get_drvdata(dev);
82
Marek Vasut360e64d2013-04-14 20:35:48 +020083 if (ucb && ucb->gpio_teardown) {
84 err = ucb->gpio_teardown(&dev->dev, ucb->gc.ngpio);
Marek Vasut4cf8e532009-09-22 16:46:35 -070085 if (err)
86 return err;
87 }
88
Marek Vasut4cf8e532009-09-22 16:46:35 -070089 return err;
90}
91
92static struct platform_driver ucb1400_gpio_driver = {
93 .probe = ucb1400_gpio_probe,
94 .remove = ucb1400_gpio_remove,
95 .driver = {
96 .name = "ucb1400_gpio"
97 },
98};
99
Mark Brown6f614152011-12-08 00:24:00 +0800100module_platform_driver(ucb1400_gpio_driver);
Marek Vasut4cf8e532009-09-22 16:46:35 -0700101
102MODULE_DESCRIPTION("Philips UCB1400 GPIO driver");
103MODULE_LICENSE("GPL");
Axel Lin41ad7302013-11-19 15:31:20 +0800104MODULE_ALIAS("platform:ucb1400_gpio");