2 * Copyright 2011 Texas Instruments Inc.
4 * Author: Margarita Olaya <magi@slimlogic.co.uk>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
11 * This driver is based on wm8350 implementation.
14 #include <linux/kernel.h>
15 #include <linux/module.h>
16 #include <linux/errno.h>
17 #include <linux/gpio.h>
18 #include <linux/mfd/core.h>
19 #include <linux/platform_device.h>
20 #include <linux/seq_file.h>
21 #include <linux/slab.h>
22 #include <linux/mfd/tps65912.h>
24 struct tps65912_gpio_data
{
25 struct tps65912
*tps65912
;
26 struct gpio_chip gpio_chip
;
29 static int tps65912_gpio_get(struct gpio_chip
*gc
, unsigned offset
)
31 struct tps65912_gpio_data
*tps65912_gpio
= gpiochip_get_data(gc
);
32 struct tps65912
*tps65912
= tps65912_gpio
->tps65912
;
35 val
= tps65912_reg_read(tps65912
, TPS65912_GPIO1
+ offset
);
37 if (val
& GPIO_STS_MASK
)
43 static void tps65912_gpio_set(struct gpio_chip
*gc
, unsigned offset
,
46 struct tps65912_gpio_data
*tps65912_gpio
= gpiochip_get_data(gc
);
47 struct tps65912
*tps65912
= tps65912_gpio
->tps65912
;
50 tps65912_set_bits(tps65912
, TPS65912_GPIO1
+ offset
,
53 tps65912_clear_bits(tps65912
, TPS65912_GPIO1
+ offset
,
57 static int tps65912_gpio_output(struct gpio_chip
*gc
, unsigned offset
,
60 struct tps65912_gpio_data
*tps65912_gpio
= gpiochip_get_data(gc
);
61 struct tps65912
*tps65912
= tps65912_gpio
->tps65912
;
63 /* Set the initial value */
64 tps65912_gpio_set(gc
, offset
, value
);
66 return tps65912_set_bits(tps65912
, TPS65912_GPIO1
+ offset
,
70 static int tps65912_gpio_input(struct gpio_chip
*gc
, unsigned offset
)
72 struct tps65912_gpio_data
*tps65912_gpio
= gpiochip_get_data(gc
);
73 struct tps65912
*tps65912
= tps65912_gpio
->tps65912
;
75 return tps65912_clear_bits(tps65912
, TPS65912_GPIO1
+ offset
,
79 static struct gpio_chip template_chip
= {
82 .direction_input
= tps65912_gpio_input
,
83 .direction_output
= tps65912_gpio_output
,
84 .get
= tps65912_gpio_get
,
85 .set
= tps65912_gpio_set
,
91 static int tps65912_gpio_probe(struct platform_device
*pdev
)
93 struct tps65912
*tps65912
= dev_get_drvdata(pdev
->dev
.parent
);
94 struct tps65912_board
*pdata
= dev_get_platdata(tps65912
->dev
);
95 struct tps65912_gpio_data
*tps65912_gpio
;
98 tps65912_gpio
= devm_kzalloc(&pdev
->dev
, sizeof(*tps65912_gpio
),
100 if (tps65912_gpio
== NULL
)
103 tps65912_gpio
->tps65912
= tps65912
;
104 tps65912_gpio
->gpio_chip
= template_chip
;
105 tps65912_gpio
->gpio_chip
.parent
= &pdev
->dev
;
106 if (pdata
&& pdata
->gpio_base
)
107 tps65912_gpio
->gpio_chip
.base
= pdata
->gpio_base
;
109 ret
= gpiochip_add_data(&tps65912_gpio
->gpio_chip
, tps65912_gpio
);
111 dev_err(&pdev
->dev
, "Failed to register gpiochip, %d\n", ret
);
115 platform_set_drvdata(pdev
, tps65912_gpio
);
120 static int tps65912_gpio_remove(struct platform_device
*pdev
)
122 struct tps65912_gpio_data
*tps65912_gpio
= platform_get_drvdata(pdev
);
124 gpiochip_remove(&tps65912_gpio
->gpio_chip
);
128 static struct platform_driver tps65912_gpio_driver
= {
130 .name
= "tps65912-gpio",
132 .probe
= tps65912_gpio_probe
,
133 .remove
= tps65912_gpio_remove
,
136 static int __init
tps65912_gpio_init(void)
138 return platform_driver_register(&tps65912_gpio_driver
);
140 subsys_initcall(tps65912_gpio_init
);
142 static void __exit
tps65912_gpio_exit(void)
144 platform_driver_unregister(&tps65912_gpio_driver
);
146 module_exit(tps65912_gpio_exit
);
148 MODULE_AUTHOR("Margarita Olaya Cabrera <magi@slimlogic.co.uk>");
149 MODULE_DESCRIPTION("GPIO interface for TPS65912 PMICs");
150 MODULE_LICENSE("GPL v2");
151 MODULE_ALIAS("platform:tps65912-gpio");