Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

regulator: pca9450: Add support for setting debounce settings

Make the different debounce timers configurable from the devicetree.
Depending on the board design, these have to be set different than the
default register values.

Signed-off-by: Martijn de Gouw <martijn.de.gouw@prodrive-technologies.com>
Link: https://patch.msgid.link/20251117202215.1936139-2-martijn.de.gouw@prodrive-technologies.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Martijn de Gouw and committed by
Mark Brown
d9d0be59 93218e3f

+171 -19
+139 -19
drivers/regulator/pca9450-regulator.c
··· 1147 1147 return 0; 1148 1148 } 1149 1149 1150 + static int pca9450_of_init(struct pca9450 *pca9450) 1151 + { 1152 + struct i2c_client *i2c = container_of(pca9450->dev, struct i2c_client, dev); 1153 + int ret; 1154 + unsigned int val; 1155 + unsigned int reset_ctrl; 1156 + unsigned int rstb_deb_ctrl; 1157 + unsigned int t_on_deb, t_off_deb; 1158 + unsigned int t_on_step, t_off_step; 1159 + unsigned int t_restart; 1160 + 1161 + if (of_property_read_bool(i2c->dev.of_node, "nxp,wdog_b-warm-reset")) 1162 + reset_ctrl = WDOG_B_CFG_WARM; 1163 + else 1164 + reset_ctrl = WDOG_B_CFG_COLD_LDO12; 1165 + 1166 + /* Set reset behavior on assertion of WDOG_B signal */ 1167 + ret = regmap_update_bits(pca9450->regmap, PCA9450_REG_RESET_CTRL, 1168 + WDOG_B_CFG_MASK, reset_ctrl); 1169 + if (ret) 1170 + return dev_err_probe(&i2c->dev, ret, "Failed to set WDOG_B reset behavior\n"); 1171 + 1172 + ret = of_property_read_u32(i2c->dev.of_node, "npx,pmic-rst-b-debounce-ms", &val); 1173 + if (ret == -EINVAL) 1174 + rstb_deb_ctrl = T_PMIC_RST_DEB_50MS; 1175 + else if (ret) 1176 + return ret; 1177 + else { 1178 + switch (val) { 1179 + case 10: rstb_deb_ctrl = T_PMIC_RST_DEB_10MS; break; 1180 + case 50: rstb_deb_ctrl = T_PMIC_RST_DEB_50MS; break; 1181 + case 100: rstb_deb_ctrl = T_PMIC_RST_DEB_100MS; break; 1182 + case 500: rstb_deb_ctrl = T_PMIC_RST_DEB_500MS; break; 1183 + case 1000: rstb_deb_ctrl = T_PMIC_RST_DEB_1S; break; 1184 + case 2000: rstb_deb_ctrl = T_PMIC_RST_DEB_2S; break; 1185 + case 4000: rstb_deb_ctrl = T_PMIC_RST_DEB_4S; break; 1186 + case 8000: rstb_deb_ctrl = T_PMIC_RST_DEB_8S; break; 1187 + default: return -EINVAL; 1188 + } 1189 + } 1190 + ret = regmap_update_bits(pca9450->regmap, PCA9450_REG_RESET_CTRL, 1191 + T_PMIC_RST_DEB_MASK, rstb_deb_ctrl); 1192 + if (ret) 1193 + return dev_err_probe(&i2c->dev, ret, "Failed to set PMIC_RST_B debounce time\n"); 1194 + 1195 + ret = of_property_read_u32(i2c->dev.of_node, "nxp,pmic-on-req-on-debounce-us", &val); 1196 + if (ret == -EINVAL) 1197 + t_on_deb = T_ON_DEB_20MS; 1198 + else if (ret) 1199 + return ret; 1200 + else { 1201 + switch (val) { 1202 + case 120: t_on_deb = T_ON_DEB_120US; break; 1203 + case 20000: t_on_deb = T_ON_DEB_20MS; break; 1204 + case 100000: t_on_deb = T_ON_DEB_100MS; break; 1205 + case 750000: t_on_deb = T_ON_DEB_750MS; break; 1206 + default: return -EINVAL; 1207 + } 1208 + } 1209 + 1210 + ret = of_property_read_u32(i2c->dev.of_node, "nxp,pmic-on-req-off-debounce-us", &val); 1211 + if (ret == -EINVAL) 1212 + t_off_deb = T_OFF_DEB_120US; 1213 + else if (ret) 1214 + return ret; 1215 + else { 1216 + switch (val) { 1217 + case 120: t_off_deb = T_OFF_DEB_120US; break; 1218 + case 2000: t_off_deb = T_OFF_DEB_2MS; break; 1219 + default: return -EINVAL; 1220 + } 1221 + } 1222 + 1223 + ret = of_property_read_u32(i2c->dev.of_node, "nxp,power-on-step-ms", &val); 1224 + if (ret == -EINVAL) 1225 + t_on_step = T_ON_STEP_2MS; 1226 + else if (ret) 1227 + return ret; 1228 + else { 1229 + switch (val) { 1230 + case 1: t_on_step = T_ON_STEP_1MS; break; 1231 + case 2: t_on_step = T_ON_STEP_2MS; break; 1232 + case 4: t_on_step = T_ON_STEP_4MS; break; 1233 + case 8: t_on_step = T_ON_STEP_8MS; break; 1234 + default: return -EINVAL; 1235 + } 1236 + } 1237 + 1238 + ret = of_property_read_u32(i2c->dev.of_node, "nxp,power-down-step-ms", &val); 1239 + if (ret == -EINVAL) 1240 + t_off_step = T_OFF_STEP_8MS; 1241 + else if (ret) 1242 + return ret; 1243 + else { 1244 + switch (val) { 1245 + case 2: t_off_step = T_OFF_STEP_2MS; break; 1246 + case 4: t_off_step = T_OFF_STEP_4MS; break; 1247 + case 8: t_off_step = T_OFF_STEP_8MS; break; 1248 + case 16: t_off_step = T_OFF_STEP_16MS; break; 1249 + default: return -EINVAL; 1250 + } 1251 + } 1252 + 1253 + ret = of_property_read_u32(i2c->dev.of_node, "nxp,restart-ms", &val); 1254 + if (ret == -EINVAL) 1255 + t_restart = T_RESTART_250MS; 1256 + else if (ret) 1257 + return ret; 1258 + else { 1259 + switch (val) { 1260 + case 250: t_restart = T_RESTART_250MS; break; 1261 + case 500: t_restart = T_RESTART_500MS; break; 1262 + default: return -EINVAL; 1263 + } 1264 + } 1265 + 1266 + ret = regmap_update_bits(pca9450->regmap, PCA9450_REG_PWRCTRL, 1267 + T_ON_DEB_MASK | T_OFF_DEB_MASK | T_ON_STEP_MASK | 1268 + T_OFF_STEP_MASK | T_RESTART_MASK, 1269 + t_on_deb | t_off_deb | t_on_step | 1270 + t_off_step | t_restart); 1271 + if (ret) 1272 + return dev_err_probe(&i2c->dev, ret, 1273 + "Failed to set PWR_CTRL debounce configuration\n"); 1274 + 1275 + if (of_property_read_bool(i2c->dev.of_node, "nxp,i2c-lt-enable")) { 1276 + /* Enable I2C Level Translator */ 1277 + ret = regmap_update_bits(pca9450->regmap, PCA9450_REG_CONFIG2, 1278 + I2C_LT_MASK, I2C_LT_ON_STANDBY_RUN); 1279 + if (ret) 1280 + return dev_err_probe(&i2c->dev, ret, 1281 + "Failed to enable I2C level translator\n"); 1282 + } 1283 + 1284 + return 0; 1285 + } 1286 + 1150 1287 static int pca9450_i2c_probe(struct i2c_client *i2c) 1151 1288 { 1152 1289 enum pca9450_chip_type type = (unsigned int)(uintptr_t) ··· 1293 1156 struct regulator_dev *ldo5; 1294 1157 struct pca9450 *pca9450; 1295 1158 unsigned int device_id, i; 1296 - unsigned int reset_ctrl; 1297 1159 int ret; 1298 1160 1299 1161 pca9450 = devm_kzalloc(&i2c->dev, sizeof(struct pca9450), GFP_KERNEL); ··· 1390 1254 if (ret) 1391 1255 return dev_err_probe(&i2c->dev, ret, "Failed to clear PRESET_EN bit\n"); 1392 1256 1393 - if (of_property_read_bool(i2c->dev.of_node, "nxp,wdog_b-warm-reset")) 1394 - reset_ctrl = WDOG_B_CFG_WARM; 1395 - else 1396 - reset_ctrl = WDOG_B_CFG_COLD_LDO12; 1397 - 1398 - /* Set reset behavior on assertion of WDOG_B signal */ 1399 - ret = regmap_update_bits(pca9450->regmap, PCA9450_REG_RESET_CTRL, 1400 - WDOG_B_CFG_MASK, reset_ctrl); 1257 + ret = pca9450_of_init(pca9450); 1401 1258 if (ret) 1402 - return dev_err_probe(&i2c->dev, ret, "Failed to set WDOG_B reset behavior\n"); 1403 - 1404 - if (of_property_read_bool(i2c->dev.of_node, "nxp,i2c-lt-enable")) { 1405 - /* Enable I2C Level Translator */ 1406 - ret = regmap_update_bits(pca9450->regmap, PCA9450_REG_CONFIG2, 1407 - I2C_LT_MASK, I2C_LT_ON_STANDBY_RUN); 1408 - if (ret) 1409 - return dev_err_probe(&i2c->dev, ret, 1410 - "Failed to enable I2C level translator\n"); 1411 - } 1259 + return dev_err_probe(&i2c->dev, ret, "Unable to parse OF data\n"); 1412 1260 1413 1261 /* 1414 1262 * For LDO5 we need to be able to check the status of the SD_VSEL input in
+32
include/linux/regulator/pca9450.h
··· 223 223 #define IRQ_THERM_105 0x02 224 224 #define IRQ_THERM_125 0x01 225 225 226 + /* PCA9450_REG_PWRCTRL bits */ 227 + #define T_ON_DEB_MASK 0xC0 228 + #define T_ON_DEB_120US (0 << 6) 229 + #define T_ON_DEB_20MS (1 << 6) 230 + #define T_ON_DEB_100MS (2 << 6) 231 + #define T_ON_DEB_750MS (3 << 6) 232 + #define T_OFF_DEB_MASK 0x20 233 + #define T_OFF_DEB_120US (0 << 5) 234 + #define T_OFF_DEB_2MS (1 << 5) 235 + #define T_ON_STEP_MASK 0x18 236 + #define T_ON_STEP_1MS (0 << 3) 237 + #define T_ON_STEP_2MS (1 << 3) 238 + #define T_ON_STEP_4MS (2 << 3) 239 + #define T_ON_STEP_8MS (3 << 3) 240 + #define T_OFF_STEP_MASK 0x06 241 + #define T_OFF_STEP_2MS (0 << 1) 242 + #define T_OFF_STEP_4MS (1 << 1) 243 + #define T_OFF_STEP_8MS (2 << 1) 244 + #define T_OFF_STEP_16MS (3 << 1) 245 + #define T_RESTART_MASK 0x01 246 + #define T_RESTART_250MS 0 247 + #define T_RESTART_500MS 1 248 + 226 249 /* PCA9450_REG_RESET_CTRL bits */ 227 250 #define WDOG_B_CFG_MASK 0xC0 228 251 #define WDOG_B_CFG_NONE 0x00 229 252 #define WDOG_B_CFG_WARM 0x40 230 253 #define WDOG_B_CFG_COLD_LDO12 0x80 231 254 #define WDOG_B_CFG_COLD 0xC0 255 + #define T_PMIC_RST_DEB_MASK 0x07 256 + #define T_PMIC_RST_DEB_10MS 0x00 257 + #define T_PMIC_RST_DEB_50MS 0x01 258 + #define T_PMIC_RST_DEB_100MS 0x02 259 + #define T_PMIC_RST_DEB_500MS 0x03 260 + #define T_PMIC_RST_DEB_1S 0x04 261 + #define T_PMIC_RST_DEB_2S 0x05 262 + #define T_PMIC_RST_DEB_4S 0x06 263 + #define T_PMIC_RST_DEB_8S 0x07 232 264 233 265 /* PCA9450_REG_CONFIG2 bits */ 234 266 #define I2C_LT_MASK 0x03