dell-smbios: rename release_buffer() to dell_smbios_release_buffer()
[linux-2.6-block.git] / drivers / gpio / gpio-ucb1400.c
CommitLineData
4cf8e53b
MV
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
4cf8e53b
MV
15static int ucb1400_gpio_dir_in(struct gpio_chip *gc, unsigned off)
16{
17 struct ucb1400_gpio *gpio;
9af4f0ab 18 gpio = gpiochip_get_data(gc);
4cf8e53b
MV
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;
9af4f0ab 26 gpio = gpiochip_get_data(gc);
4cf8e53b
MV
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;
9af4f0ab
LW
35
36 gpio = gpiochip_get_data(gc);
c9d4ab03 37 return !!ucb1400_gpio_get_value(gpio->ac97, off);
4cf8e53b
MV
38}
39
40static void ucb1400_gpio_set(struct gpio_chip *gc, unsigned off, int val)
41{
42 struct ucb1400_gpio *gpio;
9af4f0ab 43 gpio = gpiochip_get_data(gc);
4cf8e53b
MV
44 ucb1400_gpio_set_value(gpio->ac97, off, val);
45}
46
47static int ucb1400_gpio_probe(struct platform_device *dev)
48{
e56aee18 49 struct ucb1400_gpio *ucb = dev_get_platdata(&dev->dev);
4cf8e53b
MV
50 int err = 0;
51
360e64d8 52 if (!(ucb && ucb->gpio_offset)) {
4cf8e53b
MV
53 err = -EINVAL;
54 goto err;
55 }
56
57 platform_set_drvdata(dev, ucb);
58
59 ucb->gc.label = "ucb1400_gpio";
360e64d8 60 ucb->gc.base = ucb->gpio_offset;
4cf8e53b
MV
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;
9fb1f39e 68 ucb->gc.can_sleep = true;
4cf8e53b 69
9af4f0ab 70 err = gpiochip_add_data(&ucb->gc, ucb);
4cf8e53b
MV
71 if (err)
72 goto err;
73
31a3f9da 74 if (ucb->gpio_setup)
360e64d8 75 err = ucb->gpio_setup(&dev->dev, ucb->gc.ngpio);
4cf8e53b
MV
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
360e64d8
MV
87 if (ucb && ucb->gpio_teardown) {
88 err = ucb->gpio_teardown(&dev->dev, ucb->gc.ngpio);
4cf8e53b
MV
89 if (err)
90 return err;
91 }
92
9f5132ae 93 gpiochip_remove(&ucb->gc);
4cf8e53b
MV
94 return err;
95}
96
97static struct platform_driver ucb1400_gpio_driver = {
98 .probe = ucb1400_gpio_probe,
99 .remove = ucb1400_gpio_remove,
100 .driver = {
101 .name = "ucb1400_gpio"
102 },
103};
104
6f61415e 105module_platform_driver(ucb1400_gpio_driver);
4cf8e53b
MV
106
107MODULE_DESCRIPTION("Philips UCB1400 GPIO driver");
108MODULE_LICENSE("GPL");
41ad730e 109MODULE_ALIAS("platform:ucb1400_gpio");