clk: sunxi-ng: add support for DE2 CCU
[linux-2.6/btrfs-unstable.git] / drivers / gpio / gpio-tps65086.c
blobb23c4d2429be51f47035f1920554e3bf77e122ae
1 /*
2 * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/
3 * Andrew F. Davis <afd@ti.com>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
10 * kind, whether expressed or implied; without even the implied warranty
11 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License version 2 for more details.
14 * Based on the TPS65912 driver
17 #include <linux/gpio.h>
18 #include <linux/module.h>
19 #include <linux/platform_device.h>
21 #include <linux/mfd/tps65086.h>
23 struct tps65086_gpio {
24 struct gpio_chip chip;
25 struct tps65086 *tps;
28 static int tps65086_gpio_get_direction(struct gpio_chip *chip,
29 unsigned offset)
31 /* This device is output only */
32 return 0;
35 static int tps65086_gpio_direction_input(struct gpio_chip *chip,
36 unsigned offset)
38 /* This device is output only */
39 return -EINVAL;
42 static int tps65086_gpio_direction_output(struct gpio_chip *chip,
43 unsigned offset, int value)
45 struct tps65086_gpio *gpio = gpiochip_get_data(chip);
47 /* Set the initial value */
48 regmap_update_bits(gpio->tps->regmap, TPS65086_GPOCTRL,
49 BIT(4 + offset), value ? BIT(4 + offset) : 0);
51 return 0;
54 static int tps65086_gpio_get(struct gpio_chip *chip, unsigned offset)
56 struct tps65086_gpio *gpio = gpiochip_get_data(chip);
57 int ret, val;
59 ret = regmap_read(gpio->tps->regmap, TPS65086_GPOCTRL, &val);
60 if (ret < 0)
61 return ret;
63 return val & BIT(4 + offset);
66 static void tps65086_gpio_set(struct gpio_chip *chip, unsigned offset,
67 int value)
69 struct tps65086_gpio *gpio = gpiochip_get_data(chip);
71 regmap_update_bits(gpio->tps->regmap, TPS65086_GPOCTRL,
72 BIT(4 + offset), value ? BIT(4 + offset) : 0);
75 static const struct gpio_chip template_chip = {
76 .label = "tps65086-gpio",
77 .owner = THIS_MODULE,
78 .get_direction = tps65086_gpio_get_direction,
79 .direction_input = tps65086_gpio_direction_input,
80 .direction_output = tps65086_gpio_direction_output,
81 .get = tps65086_gpio_get,
82 .set = tps65086_gpio_set,
83 .base = -1,
84 .ngpio = 4,
85 .can_sleep = true,
88 static int tps65086_gpio_probe(struct platform_device *pdev)
90 struct tps65086_gpio *gpio;
91 int ret;
93 gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL);
94 if (!gpio)
95 return -ENOMEM;
97 platform_set_drvdata(pdev, gpio);
99 gpio->tps = dev_get_drvdata(pdev->dev.parent);
100 gpio->chip = template_chip;
101 gpio->chip.parent = gpio->tps->dev;
103 ret = gpiochip_add_data(&gpio->chip, gpio);
104 if (ret < 0) {
105 dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret);
106 return ret;
109 return 0;
112 static int tps65086_gpio_remove(struct platform_device *pdev)
114 struct tps65086_gpio *gpio = platform_get_drvdata(pdev);
116 gpiochip_remove(&gpio->chip);
118 return 0;
121 static const struct platform_device_id tps65086_gpio_id_table[] = {
122 { "tps65086-gpio", },
123 { /* sentinel */ }
125 MODULE_DEVICE_TABLE(platform, tps65086_gpio_id_table);
127 static struct platform_driver tps65086_gpio_driver = {
128 .driver = {
129 .name = "tps65086-gpio",
131 .probe = tps65086_gpio_probe,
132 .remove = tps65086_gpio_remove,
133 .id_table = tps65086_gpio_id_table,
135 module_platform_driver(tps65086_gpio_driver);
137 MODULE_AUTHOR("Andrew F. Davis <afd@ti.com>");
138 MODULE_DESCRIPTION("TPS65086 GPIO driver");
139 MODULE_LICENSE("GPL v2");