Skip to content

Commit 50e4d7a

Browse files
lucaceresoliLee Jones
authored andcommitted
mfd: lp87565: Handle optional reset pin
Optionally handle the NRST pin (active low reset) in order to start from a known state during boot and to shut down the chip when rebooting. Signed-off-by: Luca Ceresoli <luca@lucaceresoli.net> Signed-off-by: Lee Jones <lee.jones@linaro.org>
1 parent 4700ef3 commit 50e4d7a

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

‎drivers/mfd/lp87565.c‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Author: Keerthy <j-keerthy@ti.com>
66
*/
77

8+
#include <linux/gpio/consumer.h>
89
#include <linux/interrupt.h>
910
#include <linux/mfd/core.h>
1011
#include <linux/module.h>
@@ -64,6 +65,24 @@ static int lp87565_probe(struct i2c_client *client,
6465
return ret;
6566
}
6667

68+
lp87565->reset_gpio = devm_gpiod_get_optional(lp87565->dev, "reset",
69+
GPIOD_OUT_LOW);
70+
if (IS_ERR(lp87565->reset_gpio)) {
71+
ret = PTR_ERR(lp87565->reset_gpio);
72+
if (ret == -EPROBE_DEFER)
73+
return ret;
74+
}
75+
76+
if (lp87565->reset_gpio) {
77+
gpiod_set_value_cansleep(lp87565->reset_gpio, 1);
78+
/* The minimum assertion time is undocumented, just guess */
79+
usleep_range(2000, 4000);
80+
81+
gpiod_set_value_cansleep(lp87565->reset_gpio, 0);
82+
/* Min 1.2 ms before first I2C transaction */
83+
usleep_range(1500, 3000);
84+
}
85+
6786
ret = regmap_read(lp87565->regmap, LP87565_REG_OTP_REV, &otpid);
6887
if (ret) {
6988
dev_err(lp87565->dev, "Failed to read OTP ID\n");
@@ -83,6 +102,13 @@ static int lp87565_probe(struct i2c_client *client,
83102
NULL, 0, NULL);
84103
}
85104

105+
static void lp87565_shutdown(struct i2c_client *client)
106+
{
107+
struct lp87565 *lp87565 = i2c_get_clientdata(client);
108+
109+
gpiod_set_value_cansleep(lp87565->reset_gpio, 1);
110+
}
111+
86112
static const struct i2c_device_id lp87565_id_table[] = {
87113
{ "lp87565-q1", 0 },
88114
{ },
@@ -95,6 +121,7 @@ static struct i2c_driver lp87565_driver = {
95121
.of_match_table = of_lp87565_match_table,
96122
},
97123
.probe = lp87565_probe,
124+
.shutdown = lp87565_shutdown,
98125
.id_table = lp87565_id_table,
99126
};
100127
module_i2c_driver(lp87565_driver);

‎include/linux/mfd/lp87565.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,5 +252,6 @@ struct lp87565 {
252252
u8 rev;
253253
u8 dev_type;
254254
struct regmap *regmap;
255+
struct gpio_desc *reset_gpio;
255256
};
256257
#endif /* __LINUX_MFD_LP87565_H */

0 commit comments

Comments
 (0)