2 * TI TPS6591x GPIO driver
4 * Copyright 2010 Texas Instruments Inc.
6 * Author: Graeme Gregory <gg@slimlogic.co.uk>
7 * Author: Jorge Eduardo Candelaria jedu@slimlogic.co.uk>
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.
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>
23 static int tps65910_gpio_get(struct gpio_chip *gc, unsigned offset)
25 struct tps65910 *tps65910 = container_of(gc, struct tps65910, gpio);
28 tps65910->read(tps65910, TPS65910_GPIO0 + offset, 1, &val);
30 if (val & GPIO_STS_MASK)
36 static void tps65910_gpio_set(struct gpio_chip *gc, unsigned offset,
39 struct tps65910 *tps65910 = container_of(gc, struct tps65910, gpio);
42 tps65910_set_bits(tps65910, TPS65910_GPIO0 + offset,
45 tps65910_clear_bits(tps65910, TPS65910_GPIO0 + offset,
49 static int tps65910_gpio_output(struct gpio_chip *gc, unsigned offset,
52 struct tps65910 *tps65910 = container_of(gc, struct tps65910, gpio);
54 /* Set the initial value */
55 tps65910_gpio_set(gc, 0, value);
57 return tps65910_set_bits(tps65910, TPS65910_GPIO0 + offset,
61 static int tps65910_gpio_input(struct gpio_chip *gc, unsigned offset)
63 struct tps65910 *tps65910 = container_of(gc, struct tps65910, gpio);
65 return tps65910_clear_bits(tps65910, TPS65910_GPIO0 + offset,
69 void tps65910_gpio_init(struct tps65910 *tps65910, int gpio_base)
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;
81 switch(tps65910_chip_id(tps65910)) {
83 tps65910->gpio.ngpio = 6;
86 tps65910->gpio.ngpio = 9;
91 tps65910->gpio.can_sleep = 1;
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;
98 ret = gpiochip_add(&tps65910->gpio);
101 dev_warn(tps65910->dev, "GPIO registration failed: %d\n", ret);