Skip to content

Commit 0a8c290

Browse files
Ashish JangamSamuel Ortiz
authored andcommitted
mfd: da9052/53 lockup fix
An issue has been reported where the PMIC either locks up or fails to respond following a system Reset. This could result in a second write in which the bus writes the current content of the write buffer to address of the last I2C access. The failure case is where this unwanted write transfers incorrect data to a critical register. This patch fixes this issue to by following any read or write with a dummy read to a safe register address. A safe register address is one where the contents will not affect the operation of the system. Signed-off-by: Ashish Jangam <ashish.jangam@kpitcummins.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
1 parent ab4e8f8 commit 0a8c290

3 files changed

Lines changed: 126 additions & 4 deletions

File tree

‎drivers/mfd/da9052-i2c.c‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,66 @@
2727
#include <linux/of_device.h>
2828
#endif
2929

30+
/* I2C safe register check */
31+
static inline bool i2c_safe_reg(unsigned char reg)
32+
{
33+
switch (reg) {
34+
case DA9052_STATUS_A_REG:
35+
case DA9052_STATUS_B_REG:
36+
case DA9052_STATUS_C_REG:
37+
case DA9052_STATUS_D_REG:
38+
case DA9052_ADC_RES_L_REG:
39+
case DA9052_ADC_RES_H_REG:
40+
case DA9052_VDD_RES_REG:
41+
case DA9052_ICHG_AV_REG:
42+
case DA9052_TBAT_RES_REG:
43+
case DA9052_ADCIN4_RES_REG:
44+
case DA9052_ADCIN5_RES_REG:
45+
case DA9052_ADCIN6_RES_REG:
46+
case DA9052_TJUNC_RES_REG:
47+
case DA9052_TSI_X_MSB_REG:
48+
case DA9052_TSI_Y_MSB_REG:
49+
case DA9052_TSI_LSB_REG:
50+
case DA9052_TSI_Z_MSB_REG:
51+
return true;
52+
default:
53+
return false;
54+
}
55+
}
56+
57+
/*
58+
* There is an issue with DA9052 and DA9053_AA/BA/BB PMIC where the PMIC
59+
* gets lockup up or fails to respond following a system reset.
60+
* This fix is to follow any read or write with a dummy read to a safe
61+
* register.
62+
*/
63+
int da9052_i2c_fix(struct da9052 *da9052, unsigned char reg)
64+
{
65+
int val;
66+
67+
switch (da9052->chip_id) {
68+
case DA9052:
69+
case DA9053_AA:
70+
case DA9053_BA:
71+
case DA9053_BB:
72+
/* A dummy read to a safe register address. */
73+
if (!i2c_safe_reg(reg))
74+
return regmap_read(da9052->regmap,
75+
DA9052_PARK_REGISTER,
76+
&val);
77+
break;
78+
default:
79+
/*
80+
* For other chips parking of I2C register
81+
* to a safe place is not required.
82+
*/
83+
break;
84+
}
85+
86+
return 0;
87+
}
88+
EXPORT_SYMBOL(da9052_i2c_fix);
89+
3090
static int da9052_i2c_enable_multiwrite(struct da9052 *da9052)
3191
{
3292
int reg_val, ret;
@@ -83,6 +143,7 @@ static int da9052_i2c_probe(struct i2c_client *client,
83143

84144
da9052->dev = &client->dev;
85145
da9052->chip_irq = client->irq;
146+
da9052->fix_io = da9052_i2c_fix;
86147

87148
i2c_set_clientdata(client, da9052);
88149

‎include/linux/mfd/da9052/da9052.h‎

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ struct da9052 {
9999
u8 chip_id;
100100

101101
int chip_irq;
102+
103+
/* SOC I/O transfer related fixes for DA9052/53 */
104+
int (*fix_io) (struct da9052 *da9052, unsigned char reg);
102105
};
103106

104107
/* ADC API */
@@ -113,32 +116,87 @@ static inline int da9052_reg_read(struct da9052 *da9052, unsigned char reg)
113116
ret = regmap_read(da9052->regmap, reg, &val);
114117
if (ret < 0)
115118
return ret;
119+
120+
if (da9052->fix_io) {
121+
ret = da9052->fix_io(da9052, reg);
122+
if (ret < 0)
123+
return ret;
124+
}
125+
116126
return val;
117127
}
118128

119129
static inline int da9052_reg_write(struct da9052 *da9052, unsigned char reg,
120130
unsigned char val)
121131
{
122-
return regmap_write(da9052->regmap, reg, val);
132+
int ret;
133+
134+
ret = regmap_write(da9052->regmap, reg, val);
135+
if (ret < 0)
136+
return ret;
137+
138+
if (da9052->fix_io) {
139+
ret = da9052->fix_io(da9052, reg);
140+
if (ret < 0)
141+
return ret;
142+
}
143+
144+
return ret;
123145
}
124146

125147
static inline int da9052_group_read(struct da9052 *da9052, unsigned char reg,
126148
unsigned reg_cnt, unsigned char *val)
127149
{
128-
return regmap_bulk_read(da9052->regmap, reg, val, reg_cnt);
150+
int ret;
151+
152+
ret = regmap_bulk_read(da9052->regmap, reg, val, reg_cnt);
153+
if (ret < 0)
154+
return ret;
155+
156+
if (da9052->fix_io) {
157+
ret = da9052->fix_io(da9052, reg);
158+
if (ret < 0)
159+
return ret;
160+
}
161+
162+
return ret;
129163
}
130164

131165
static inline int da9052_group_write(struct da9052 *da9052, unsigned char reg,
132166
unsigned reg_cnt, unsigned char *val)
133167
{
134-
return regmap_raw_write(da9052->regmap, reg, val, reg_cnt);
168+
int ret;
169+
170+
ret = regmap_raw_write(da9052->regmap, reg, val, reg_cnt);
171+
if (ret < 0)
172+
return ret;
173+
174+
if (da9052->fix_io) {
175+
ret = da9052->fix_io(da9052, reg);
176+
if (ret < 0)
177+
return ret;
178+
}
179+
180+
return ret;
135181
}
136182

137183
static inline int da9052_reg_update(struct da9052 *da9052, unsigned char reg,
138184
unsigned char bit_mask,
139185
unsigned char reg_val)
140186
{
141-
return regmap_update_bits(da9052->regmap, reg, bit_mask, reg_val);
187+
int ret;
188+
189+
ret = regmap_update_bits(da9052->regmap, reg, bit_mask, reg_val);
190+
if (ret < 0)
191+
return ret;
192+
193+
if (da9052->fix_io) {
194+
ret = da9052->fix_io(da9052, reg);
195+
if (ret < 0)
196+
return ret;
197+
}
198+
199+
return ret;
142200
}
143201

144202
int da9052_device_init(struct da9052 *da9052, u8 chip_id);

‎include/linux/mfd/da9052/reg.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
#define DA9052_STATUS_C_REG 3
3535
#define DA9052_STATUS_D_REG 4
3636

37+
/* PARK REGISTER */
38+
#define DA9052_PARK_REGISTER DA9052_STATUS_D_REG
39+
3740
/* EVENT REGISTERS */
3841
#define DA9052_EVENT_A_REG 5
3942
#define DA9052_EVENT_B_REG 6

0 commit comments

Comments
 (0)