2 * Philips UCB1400 GPIO driver
4 * Author: Marek Vasut <marek.vasut@gmail.com>
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.
12 #include <linux/module.h>
13 #include <linux/ucb1400.h>
15 struct ucb1400_gpio_data *ucbdata;
17 static int ucb1400_gpio_dir_in(struct gpio_chip *gc, unsigned off)
19 struct ucb1400_gpio *gpio;
20 gpio = container_of(gc, struct ucb1400_gpio, gc);
21 ucb1400_gpio_set_direction(gpio->ac97, off, 0);
25 static int ucb1400_gpio_dir_out(struct gpio_chip *gc, unsigned off, int val)
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);
34 static int ucb1400_gpio_get(struct gpio_chip *gc, unsigned off)
36 struct ucb1400_gpio *gpio;
37 gpio = container_of(gc, struct ucb1400_gpio, gc);
38 return ucb1400_gpio_get_value(gpio->ac97, off);
41 static void ucb1400_gpio_set(struct gpio_chip *gc, unsigned off, int val)
43 struct ucb1400_gpio *gpio;
44 gpio = container_of(gc, struct ucb1400_gpio, gc);
45 ucb1400_gpio_set_value(gpio->ac97, off, val);
48 static int ucb1400_gpio_probe(struct platform_device *dev)
50 struct ucb1400_gpio *ucb = dev->dev.platform_data;
53 if (!(ucbdata && ucbdata->gpio_offset)) {
58 platform_set_drvdata(dev, ucb);
60 ucb->gc.label = "ucb1400_gpio";
61 ucb->gc.base = ucbdata->gpio_offset;
63 ucb->gc.owner = THIS_MODULE;
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;
71 err = gpiochip_add(&ucb->gc);
75 if (ucbdata && ucbdata->gpio_setup)
76 err = ucbdata->gpio_setup(&dev->dev, ucb->gc.ngpio);
83 static int ucb1400_gpio_remove(struct platform_device *dev)
86 struct ucb1400_gpio *ucb = platform_get_drvdata(dev);
88 if (ucbdata && ucbdata->gpio_teardown) {
89 err = ucbdata->gpio_teardown(&dev->dev, ucb->gc.ngpio);
94 err = gpiochip_remove(&ucb->gc);
98 static struct platform_driver ucb1400_gpio_driver = {
99 .probe = ucb1400_gpio_probe,
100 .remove = ucb1400_gpio_remove,
102 .name = "ucb1400_gpio"
106 void __init ucb1400_gpio_set_data(struct ucb1400_gpio_data *data)
111 module_platform_driver(ucb1400_gpio_driver);
113 MODULE_DESCRIPTION("Philips UCB1400 GPIO driver");
114 MODULE_LICENSE("GPL");