Loading...
1/*
2 * Philips UCB1400 GPIO driver
3 *
4 * Author: Marek Vasut <marek.vasut@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 */
11
12#include <linux/module.h>
13#include <linux/ucb1400.h>
14
15struct ucb1400_gpio_data *ucbdata;
16
17static int ucb1400_gpio_dir_in(struct gpio_chip *gc, unsigned off)
18{
19 struct ucb1400_gpio *gpio;
20 gpio = container_of(gc, struct ucb1400_gpio, gc);
21 ucb1400_gpio_set_direction(gpio->ac97, off, 0);
22 return 0;
23}
24
25static int ucb1400_gpio_dir_out(struct gpio_chip *gc, unsigned off, int val)
26{
27 struct ucb1400_gpio *gpio;
28 gpio = container_of(gc, struct ucb1400_gpio, gc);
29 ucb1400_gpio_set_direction(gpio->ac97, off, 1);
30 ucb1400_gpio_set_value(gpio->ac97, off, val);
31 return 0;
32}
33
34static int ucb1400_gpio_get(struct gpio_chip *gc, unsigned off)
35{
36 struct ucb1400_gpio *gpio;
37 gpio = container_of(gc, struct ucb1400_gpio, gc);
38 return ucb1400_gpio_get_value(gpio->ac97, off);
39}
40
41static void ucb1400_gpio_set(struct gpio_chip *gc, unsigned off, int val)
42{
43 struct ucb1400_gpio *gpio;
44 gpio = container_of(gc, struct ucb1400_gpio, gc);
45 ucb1400_gpio_set_value(gpio->ac97, off, val);
46}
47
48static int ucb1400_gpio_probe(struct platform_device *dev)
49{
50 struct ucb1400_gpio *ucb = dev->dev.platform_data;
51 int err = 0;
52
53 if (!(ucbdata && ucbdata->gpio_offset)) {
54 err = -EINVAL;
55 goto err;
56 }
57
58 platform_set_drvdata(dev, ucb);
59
60 ucb->gc.label = "ucb1400_gpio";
61 ucb->gc.base = ucbdata->gpio_offset;
62 ucb->gc.ngpio = 10;
63 ucb->gc.owner = THIS_MODULE;
64
65 ucb->gc.direction_input = ucb1400_gpio_dir_in;
66 ucb->gc.direction_output = ucb1400_gpio_dir_out;
67 ucb->gc.get = ucb1400_gpio_get;
68 ucb->gc.set = ucb1400_gpio_set;
69 ucb->gc.can_sleep = 1;
70
71 err = gpiochip_add(&ucb->gc);
72 if (err)
73 goto err;
74
75 if (ucbdata && ucbdata->gpio_setup)
76 err = ucbdata->gpio_setup(&dev->dev, ucb->gc.ngpio);
77
78err:
79 return err;
80
81}
82
83static int ucb1400_gpio_remove(struct platform_device *dev)
84{
85 int err = 0;
86 struct ucb1400_gpio *ucb = platform_get_drvdata(dev);
87
88 if (ucbdata && ucbdata->gpio_teardown) {
89 err = ucbdata->gpio_teardown(&dev->dev, ucb->gc.ngpio);
90 if (err)
91 return err;
92 }
93
94 err = gpiochip_remove(&ucb->gc);
95 return err;
96}
97
98static struct platform_driver ucb1400_gpio_driver = {
99 .probe = ucb1400_gpio_probe,
100 .remove = ucb1400_gpio_remove,
101 .driver = {
102 .name = "ucb1400_gpio"
103 },
104};
105
106static int __init ucb1400_gpio_init(void)
107{
108 return platform_driver_register(&ucb1400_gpio_driver);
109}
110
111static void __exit ucb1400_gpio_exit(void)
112{
113 platform_driver_unregister(&ucb1400_gpio_driver);
114}
115
116void __init ucb1400_gpio_set_data(struct ucb1400_gpio_data *data)
117{
118 ucbdata = data;
119}
120
121module_init(ucb1400_gpio_init);
122module_exit(ucb1400_gpio_exit);
123
124MODULE_DESCRIPTION("Philips UCB1400 GPIO driver");
125MODULE_LICENSE("GPL");
1/*
2 * Philips UCB1400 GPIO driver
3 *
4 * Author: Marek Vasut <marek.vasut@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 */
11
12#include <linux/module.h>
13#include <linux/ucb1400.h>
14
15static int ucb1400_gpio_dir_in(struct gpio_chip *gc, unsigned off)
16{
17 struct ucb1400_gpio *gpio;
18 gpio = gpiochip_get_data(gc);
19 ucb1400_gpio_set_direction(gpio->ac97, off, 0);
20 return 0;
21}
22
23static int ucb1400_gpio_dir_out(struct gpio_chip *gc, unsigned off, int val)
24{
25 struct ucb1400_gpio *gpio;
26 gpio = gpiochip_get_data(gc);
27 ucb1400_gpio_set_direction(gpio->ac97, off, 1);
28 ucb1400_gpio_set_value(gpio->ac97, off, val);
29 return 0;
30}
31
32static int ucb1400_gpio_get(struct gpio_chip *gc, unsigned off)
33{
34 struct ucb1400_gpio *gpio;
35
36 gpio = gpiochip_get_data(gc);
37 return !!ucb1400_gpio_get_value(gpio->ac97, off);
38}
39
40static void ucb1400_gpio_set(struct gpio_chip *gc, unsigned off, int val)
41{
42 struct ucb1400_gpio *gpio;
43 gpio = gpiochip_get_data(gc);
44 ucb1400_gpio_set_value(gpio->ac97, off, val);
45}
46
47static int ucb1400_gpio_probe(struct platform_device *dev)
48{
49 struct ucb1400_gpio *ucb = dev_get_platdata(&dev->dev);
50 int err = 0;
51
52 if (!(ucb && ucb->gpio_offset)) {
53 err = -EINVAL;
54 goto err;
55 }
56
57 platform_set_drvdata(dev, ucb);
58
59 ucb->gc.label = "ucb1400_gpio";
60 ucb->gc.base = ucb->gpio_offset;
61 ucb->gc.ngpio = 10;
62 ucb->gc.owner = THIS_MODULE;
63
64 ucb->gc.direction_input = ucb1400_gpio_dir_in;
65 ucb->gc.direction_output = ucb1400_gpio_dir_out;
66 ucb->gc.get = ucb1400_gpio_get;
67 ucb->gc.set = ucb1400_gpio_set;
68 ucb->gc.can_sleep = true;
69
70 err = devm_gpiochip_add_data(&dev->dev, &ucb->gc, ucb);
71 if (err)
72 goto err;
73
74 if (ucb->gpio_setup)
75 err = ucb->gpio_setup(&dev->dev, ucb->gc.ngpio);
76
77err:
78 return err;
79
80}
81
82static int ucb1400_gpio_remove(struct platform_device *dev)
83{
84 int err = 0;
85 struct ucb1400_gpio *ucb = platform_get_drvdata(dev);
86
87 if (ucb && ucb->gpio_teardown) {
88 err = ucb->gpio_teardown(&dev->dev, ucb->gc.ngpio);
89 if (err)
90 return err;
91 }
92
93 return err;
94}
95
96static struct platform_driver ucb1400_gpio_driver = {
97 .probe = ucb1400_gpio_probe,
98 .remove = ucb1400_gpio_remove,
99 .driver = {
100 .name = "ucb1400_gpio"
101 },
102};
103
104module_platform_driver(ucb1400_gpio_driver);
105
106MODULE_DESCRIPTION("Philips UCB1400 GPIO driver");
107MODULE_LICENSE("GPL");
108MODULE_ALIAS("platform:ucb1400_gpio");