1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2015-2023 Texas Instruments Incorporated - https://www.ti.com/
4 * Andrew Davis <afd@ti.com>
6 * Based on the TPS65912 driver
9 #include <linux/gpio/driver.h>
10 #include <linux/module.h>
11 #include <linux/platform_device.h>
13 #include <linux/mfd/tps65086.h>
15 struct tps65086_gpio
{
16 struct gpio_chip chip
;
20 static int tps65086_gpio_get_direction(struct gpio_chip
*chip
,
23 /* This device is output only */
24 return GPIO_LINE_DIRECTION_OUT
;
27 static int tps65086_gpio_direction_input(struct gpio_chip
*chip
,
30 /* This device is output only */
34 static int tps65086_gpio_direction_output(struct gpio_chip
*chip
,
35 unsigned offset
, int value
)
37 struct tps65086_gpio
*gpio
= gpiochip_get_data(chip
);
39 /* Set the initial value */
40 regmap_update_bits(gpio
->tps
->regmap
, TPS65086_GPOCTRL
,
41 BIT(4 + offset
), value
? BIT(4 + offset
) : 0);
46 static int tps65086_gpio_get(struct gpio_chip
*chip
, unsigned offset
)
48 struct tps65086_gpio
*gpio
= gpiochip_get_data(chip
);
51 ret
= regmap_read(gpio
->tps
->regmap
, TPS65086_GPOCTRL
, &val
);
55 return val
& BIT(4 + offset
);
58 static void tps65086_gpio_set(struct gpio_chip
*chip
, unsigned offset
,
61 struct tps65086_gpio
*gpio
= gpiochip_get_data(chip
);
63 regmap_update_bits(gpio
->tps
->regmap
, TPS65086_GPOCTRL
,
64 BIT(4 + offset
), value
? BIT(4 + offset
) : 0);
67 static const struct gpio_chip template_chip
= {
68 .label
= "tps65086-gpio",
70 .get_direction
= tps65086_gpio_get_direction
,
71 .direction_input
= tps65086_gpio_direction_input
,
72 .direction_output
= tps65086_gpio_direction_output
,
73 .get
= tps65086_gpio_get
,
74 .set
= tps65086_gpio_set
,
80 static int tps65086_gpio_probe(struct platform_device
*pdev
)
82 struct tps65086_gpio
*gpio
;
84 gpio
= devm_kzalloc(&pdev
->dev
, sizeof(*gpio
), GFP_KERNEL
);
88 gpio
->tps
= dev_get_drvdata(pdev
->dev
.parent
);
89 gpio
->chip
= template_chip
;
90 gpio
->chip
.parent
= gpio
->tps
->dev
;
92 return devm_gpiochip_add_data(&pdev
->dev
, &gpio
->chip
, gpio
);
95 static const struct platform_device_id tps65086_gpio_id_table
[] = {
99 MODULE_DEVICE_TABLE(platform
, tps65086_gpio_id_table
);
101 static struct platform_driver tps65086_gpio_driver
= {
103 .name
= "tps65086-gpio",
105 .probe
= tps65086_gpio_probe
,
106 .id_table
= tps65086_gpio_id_table
,
108 module_platform_driver(tps65086_gpio_driver
);
110 MODULE_AUTHOR("Andrew Davis <afd@ti.com>");
111 MODULE_DESCRIPTION("TPS65086 GPIO driver");
112 MODULE_LICENSE("GPL v2");