2 * GPIO driver for TI TPS65912x PMICs
4 * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/
5 * Andrew F. Davis <afd@ti.com>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
12 * kind, whether expressed or implied; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License version 2 for more details.
16 * Based on the Arizona GPIO driver and the previous TPS65912 driver by
17 * Margarita Olaya Cabrera <magi@slimlogic.co.uk>
20 #include <linux/gpio.h>
21 #include <linux/module.h>
22 #include <linux/platform_device.h>
24 #include <linux/mfd/tps65912.h>
26 struct tps65912_gpio
{
27 struct gpio_chip gpio_chip
;
31 static int tps65912_gpio_get_direction(struct gpio_chip
*gc
,
34 struct tps65912_gpio
*gpio
= gpiochip_get_data(gc
);
38 ret
= regmap_read(gpio
->tps
->regmap
, TPS65912_GPIO1
+ offset
, &val
);
42 if (val
& GPIO_CFG_MASK
)
48 static int tps65912_gpio_direction_input(struct gpio_chip
*gc
, unsigned offset
)
50 struct tps65912_gpio
*gpio
= gpiochip_get_data(gc
);
52 return regmap_update_bits(gpio
->tps
->regmap
, TPS65912_GPIO1
+ offset
,
56 static int tps65912_gpio_direction_output(struct gpio_chip
*gc
,
57 unsigned offset
, int value
)
59 struct tps65912_gpio
*gpio
= gpiochip_get_data(gc
);
61 /* Set the initial value */
62 regmap_update_bits(gpio
->tps
->regmap
, TPS65912_GPIO1
+ offset
,
63 GPIO_SET_MASK
, value
? GPIO_SET_MASK
: 0);
65 return regmap_update_bits(gpio
->tps
->regmap
, TPS65912_GPIO1
+ offset
,
66 GPIO_CFG_MASK
, GPIO_CFG_MASK
);
69 static int tps65912_gpio_get(struct gpio_chip
*gc
, unsigned offset
)
71 struct tps65912_gpio
*gpio
= gpiochip_get_data(gc
);
74 ret
= regmap_read(gpio
->tps
->regmap
, TPS65912_GPIO1
+ offset
, &val
);
78 if (val
& GPIO_STS_MASK
)
84 static void tps65912_gpio_set(struct gpio_chip
*gc
, unsigned offset
,
87 struct tps65912_gpio
*gpio
= gpiochip_get_data(gc
);
89 regmap_update_bits(gpio
->tps
->regmap
, TPS65912_GPIO1
+ offset
,
90 GPIO_SET_MASK
, value
? GPIO_SET_MASK
: 0);
93 static const struct gpio_chip template_chip
= {
94 .label
= "tps65912-gpio",
96 .get_direction
= tps65912_gpio_get_direction
,
97 .direction_input
= tps65912_gpio_direction_input
,
98 .direction_output
= tps65912_gpio_direction_output
,
99 .get
= tps65912_gpio_get
,
100 .set
= tps65912_gpio_set
,
106 static int tps65912_gpio_probe(struct platform_device
*pdev
)
108 struct tps65912
*tps
= dev_get_drvdata(pdev
->dev
.parent
);
109 struct tps65912_gpio
*gpio
;
112 gpio
= devm_kzalloc(&pdev
->dev
, sizeof(*gpio
), GFP_KERNEL
);
116 gpio
->tps
= dev_get_drvdata(pdev
->dev
.parent
);
117 gpio
->gpio_chip
= template_chip
;
118 gpio
->gpio_chip
.parent
= tps
->dev
;
120 ret
= devm_gpiochip_add_data(&pdev
->dev
, &gpio
->gpio_chip
,
123 dev_err(&pdev
->dev
, "Could not register gpiochip, %d\n", ret
);
127 platform_set_drvdata(pdev
, gpio
);
132 static const struct platform_device_id tps65912_gpio_id_table
[] = {
133 { "tps65912-gpio", },
136 MODULE_DEVICE_TABLE(platform
, tps65912_gpio_id_table
);
138 static struct platform_driver tps65912_gpio_driver
= {
140 .name
= "tps65912-gpio",
142 .probe
= tps65912_gpio_probe
,
143 .id_table
= tps65912_gpio_id_table
,
145 module_platform_driver(tps65912_gpio_driver
);
147 MODULE_AUTHOR("Andrew F. Davis <afd@ti.com>");
148 MODULE_DESCRIPTION("TPS65912 GPIO driver");
149 MODULE_LICENSE("GPL v2");