diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2011-07-22 17:50:57 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-07-22 17:50:57 -0400 |
commit | c7c8518498e82591d7784452f5674c3aeb4d079c (patch) | |
tree | 790ff7e6b6741daf32ec686b9a302b957b07c0f4 /drivers/gpio/gpio-tps65910.c | |
parent | ece236ce2fad9c27a6fd2530f899289025194bce (diff) | |
parent | 591567a5ea25852f20b7ef2953f6f72020121199 (diff) |
Merge branch 'gpio/next' of git://git.secretlab.ca/git/linux-2.6
* 'gpio/next' of git://git.secretlab.ca/git/linux-2.6: (61 commits)
gpio/mxc/mxs: fix build error introduced by the irq_gc_ack() renaming
mcp23s08: add i2c support
mcp23s08: isolate spi specific parts
mcp23s08: get rid of setup/teardown callbacks
gpio/tegra: dt: add binding for gpio polarity
mcp23s08: remove unused work queue
gpio/da9052: remove a redundant assignment for gpio->da9052
gpio/mxc: add device tree probe support
ARM: mxc: use ARCH_NR_GPIOS to define gpio number
gpio/mxc: get rid of the uses of cpu_is_mx()
gpio/mxc: add missing initialization of basic_mmio_gpio shadow variables
gpio: Move mpc5200 gpio driver to drivers/gpio
GPIO: DA9052 GPIO module v3
gpio/tegra: Use engineering names in DT compatible property
of/gpio: Add new method for getting gpios under different property names
gpio/dt: Refine GPIO device tree binding
gpio/ml-ioh: fix off-by-one for displaying variable i in dev_err
gpio/pca953x: Deprecate meaningless device-tree bindings
gpio/pca953x: Remove dynamic platform data pointer
gpio/pca953x: Fix IRQ support.
...
Diffstat (limited to 'drivers/gpio/gpio-tps65910.c')
-rw-r--r-- | drivers/gpio/gpio-tps65910.c | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/drivers/gpio/gpio-tps65910.c b/drivers/gpio/gpio-tps65910.c new file mode 100644 index 000000000000..b9c1c297669e --- /dev/null +++ b/drivers/gpio/gpio-tps65910.c | |||
@@ -0,0 +1,102 @@ | |||
1 | /* | ||
2 | * TI TPS6591x GPIO driver | ||
3 | * | ||
4 | * Copyright 2010 Texas Instruments Inc. | ||
5 | * | ||
6 | * Author: Graeme Gregory <gg@slimlogic.co.uk> | ||
7 | * Author: Jorge Eduardo Candelaria jedu@slimlogic.co.uk> | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify it | ||
10 | * under the terms of the GNU General Public License as published by the | ||
11 | * Free Software Foundation; either version 2 of the License, or (at your | ||
12 | * option) any later version. | ||
13 | * | ||
14 | */ | ||
15 | |||
16 | #include <linux/kernel.h> | ||
17 | #include <linux/module.h> | ||
18 | #include <linux/errno.h> | ||
19 | #include <linux/gpio.h> | ||
20 | #include <linux/i2c.h> | ||
21 | #include <linux/mfd/tps65910.h> | ||
22 | |||
23 | static int tps65910_gpio_get(struct gpio_chip *gc, unsigned offset) | ||
24 | { | ||
25 | struct tps65910 *tps65910 = container_of(gc, struct tps65910, gpio); | ||
26 | uint8_t val; | ||
27 | |||
28 | tps65910->read(tps65910, TPS65910_GPIO0 + offset, 1, &val); | ||
29 | |||
30 | if (val & GPIO_STS_MASK) | ||
31 | return 1; | ||
32 | |||
33 | return 0; | ||
34 | } | ||
35 | |||
36 | static void tps65910_gpio_set(struct gpio_chip *gc, unsigned offset, | ||
37 | int value) | ||
38 | { | ||
39 | struct tps65910 *tps65910 = container_of(gc, struct tps65910, gpio); | ||
40 | |||
41 | if (value) | ||
42 | tps65910_set_bits(tps65910, TPS65910_GPIO0 + offset, | ||
43 | GPIO_SET_MASK); | ||
44 | else | ||
45 | tps65910_clear_bits(tps65910, TPS65910_GPIO0 + offset, | ||
46 | GPIO_SET_MASK); | ||
47 | } | ||
48 | |||
49 | static int tps65910_gpio_output(struct gpio_chip *gc, unsigned offset, | ||
50 | int value) | ||
51 | { | ||
52 | struct tps65910 *tps65910 = container_of(gc, struct tps65910, gpio); | ||
53 | |||
54 | /* Set the initial value */ | ||
55 | tps65910_gpio_set(gc, 0, value); | ||
56 | |||
57 | return tps65910_set_bits(tps65910, TPS65910_GPIO0 + offset, | ||
58 | GPIO_CFG_MASK); | ||
59 | } | ||
60 | |||
61 | static int tps65910_gpio_input(struct gpio_chip *gc, unsigned offset) | ||
62 | { | ||
63 | struct tps65910 *tps65910 = container_of(gc, struct tps65910, gpio); | ||
64 | |||
65 | return tps65910_clear_bits(tps65910, TPS65910_GPIO0 + offset, | ||
66 | GPIO_CFG_MASK); | ||
67 | } | ||
68 | |||
69 | void tps65910_gpio_init(struct tps65910 *tps65910, int gpio_base) | ||
70 | { | ||
71 | int ret; | ||
72 | |||
73 | if (!gpio_base) | ||
74 | return; | ||
75 | |||
76 | tps65910->gpio.owner = THIS_MODULE; | ||
77 | tps65910->gpio.label = tps65910->i2c_client->name; | ||
78 | tps65910->gpio.dev = tps65910->dev; | ||
79 | tps65910->gpio.base = gpio_base; | ||
80 | |||
81 | switch(tps65910_chip_id(tps65910)) { | ||
82 | case TPS65910: | ||
83 | tps65910->gpio.ngpio = 6; | ||
84 | break; | ||
85 | case TPS65911: | ||
86 | tps65910->gpio.ngpio = 9; | ||
87 | break; | ||
88 | default: | ||
89 | return; | ||
90 | } | ||
91 | tps65910->gpio.can_sleep = 1; | ||
92 | |||
93 | tps65910->gpio.direction_input = tps65910_gpio_input; | ||
94 | tps65910->gpio.direction_output = tps65910_gpio_output; | ||
95 | tps65910->gpio.set = tps65910_gpio_set; | ||
96 | tps65910->gpio.get = tps65910_gpio_get; | ||
97 | |||
98 | ret = gpiochip_add(&tps65910->gpio); | ||
99 | |||
100 | if (ret) | ||
101 | dev_warn(tps65910->dev, "GPIO registration failed: %d\n", ret); | ||
102 | } | ||