Pull regulator fixes from Mark Brown: "One driver specific fix where one of the MediaTek drivers duplicated some core code buggily, and a core fix for an ordering issue on startup where we could end up configuring a voltage outside of constraints due to the order in which we applied constraints" * tag 'regulator-fix-v7.2-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator: regulator: core: clamp voltage constraints before applying apply_uV regulator: mt6358: use regmap helper to read fixed LDO calibration
Unified · Split
| @@ -1220,10 +1220,98 @@ static int machine_constraints_voltage(struct regulator_dev *rdev, · 1219 unmodified lines | ||
| 1220 | 1220 | { |
| 1221 | 1221 | const struct regulator_ops *ops = rdev->desc->ops; |
| 1222 | 1222 | int ret; |
| 1223 | + bool apply_uV; | |
| 1224 | + | |
| 1225 | + /* | |
| 1226 | + * Decide up front, from the constraints as handed to us, whether | |
| 1227 | + * apply_uV needs to run below. The clamping pass right after this | |
| 1228 | + * may rewrite constraints->min_uV/max_uV (e.g. the fixed-voltage | |
| 1229 | + * autoconfigure case), and we don't want that to change whether | |
| 1230 | + * apply_uV fires. | |
| 1231 | + */ | |
| 1232 | + apply_uV = rdev->constraints->apply_uV && | |
| 1233 | + rdev->constraints->min_uV && rdev->constraints->max_uV; | |
| 1234 | + | |
| 1235 | + /* | |
| 1236 | + * Constrain machine-level voltage specs to fit the actual range | |
| 1237 | + * supported by this regulator before apply_uV (below) tries to | |
| 1238 | + * force hardware to a value from that range: otherwise apply_uV | |
| 1239 | + * can target a constraint value that doesn't correspond to any | |
| 1240 | + * real voltage selector and fail registration outright, even | |
| 1241 | + * though the clamping pass would have narrowed it to a value | |
| 1242 | + * the regulator can actually hit. | |
| 1243 | + */ | |
| 1244 | + if (ops->list_voltage && rdev->desc->n_voltages) { | |
| 1245 | + int count = rdev->desc->n_voltages; | |
| 1246 | + int i; | |
| 1247 | + int min_uV = INT_MAX; | |
| 1248 | + int max_uV = INT_MIN; | |
| 1249 | + int cmin = constraints->min_uV; | |
| 1250 | + int cmax = constraints->max_uV; | |
| 1251 | + | |
| 1252 | + /* it's safe to autoconfigure fixed-voltage supplies | |
| 1253 | + * and the constraints are used by list_voltage. | |
| 1254 | + */ | |
| 1255 | + if (count == 1 && !cmin) { | |
| 1256 | + cmin = 1; | |
| 1257 | + cmax = INT_MAX; | |
| 1258 | + constraints->min_uV = cmin; | |
| 1259 | + constraints->max_uV = cmax; | |
| 1260 | + } | |
| 1261 | + | |
| 1262 | + /* voltage constraints are optional */ | |
| 1263 | + if ((cmin == 0) && (cmax == 0)) { | |
| 1264 | + /* nothing more to do */ | |
| 1265 | + | |
| 1266 | + /* else require explicit machine-level constraints */ | |
| 1267 | + } else if (cmin <= 0 || cmax <= 0 || cmax < cmin) { | |
| 1268 | + rdev_err(rdev, "invalid voltage constraints\n"); | |
| 1269 | + return -EINVAL; | |
| 1270 | + | |
| 1271 | + /* no need to loop voltages if range is continuous */ | |
| 1272 | + } else if (rdev->desc->continuous_voltage_range) { | |
| 1273 | + /* nothing more to do */ | |
| 1274 | + | |
| 1275 | + } else { | |
| 1276 | + /* initial: [cmin..cmax] valid, [min_uV..max_uV] not */ | |
| 1277 | + for (i = 0; i < count; i++) { | |
| 1278 | + int value; | |
| 1279 | + | |
| 1280 | + value = ops->list_voltage(rdev, i); | |
| 1281 | + if (value <= 0) | |
| 1282 | + continue; | |
| 1283 | + | |
| 1284 | + /* maybe adjust [min_uV..max_uV] */ | |
| 1285 | + if (value >= cmin && value < min_uV) | |
| 1286 | + min_uV = value; | |
| 1287 | + if (value <= cmax && value > max_uV) | |
| 1288 | + max_uV = value; | |
| 1289 | + } | |
| 1290 | + | |
| 1291 | + /* final: [min_uV..max_uV] valid iff constraints valid */ | |
| 1292 | + if (max_uV < min_uV) { | |
| 1293 | + rdev_err(rdev, | |
| 1294 | + "unsupportable voltage constraints %u-%uuV\n", | |
| 1295 | + min_uV, max_uV); | |
| 1296 | + return -EINVAL; | |
| 1297 | + } | |
| 1298 | + | |
| 1299 | + /* use regulator's subset of machine constraints */ | |
| 1300 | + if (constraints->min_uV < min_uV) { | |
| 1301 | + rdev_dbg(rdev, "override min_uV, %d -> %d\n", | |
| 1302 | + constraints->min_uV, min_uV); | |
| 1303 | + constraints->min_uV = min_uV; | |
| 1304 | + } | |
| 1305 | + if (constraints->max_uV > max_uV) { | |
| 1306 | + rdev_dbg(rdev, "override max_uV, %d -> %d\n", | |
| 1307 | + constraints->max_uV, max_uV); | |
| 1308 | + constraints->max_uV = max_uV; | |
| 1309 | + } | |
| 1310 | + } | |
| 1311 | + } | |
| 1223 | 1312 | |
| 1224 | 1313 | /* do we need to apply the constraint voltage */ |
| 1225 | − if (rdev->constraints->apply_uV && | |
| 1226 | − rdev->constraints->min_uV && rdev->constraints->max_uV) { | |
| 1314 | + if (apply_uV) { | |
| 1227 | 1315 | int target_min, target_max; |
| 1228 | 1316 | int current_uV = regulator_get_voltage_rdev(rdev); |
| 1229 | 1317 | |
| @@ -1278,77 +1366,6 @@ static int machine_constraints_voltage(struct regulator_dev *rdev, · 48 unmodified lines | ||
| 1278 | 1366 | } |
| 1279 | 1367 | } |
| 1280 | 1368 | |
| 1281 | − /* constrain machine-level voltage specs to fit | |
| 1282 | − * the actual range supported by this regulator. | |
| 1283 | − */ | |
| 1284 | − if (ops->list_voltage && rdev->desc->n_voltages) { | |
| 1285 | − int count = rdev->desc->n_voltages; | |
| 1286 | − int i; | |
| 1287 | − int min_uV = INT_MAX; | |
| 1288 | − int max_uV = INT_MIN; | |
| 1289 | − int cmin = constraints->min_uV; | |
| 1290 | − int cmax = constraints->max_uV; | |
| 1291 | − | |
| 1292 | − /* it's safe to autoconfigure fixed-voltage supplies | |
| 1293 | − * and the constraints are used by list_voltage. | |
| 1294 | − */ | |
| 1295 | − if (count == 1 && !cmin) { | |
| 1296 | − cmin = 1; | |
| 1297 | − cmax = INT_MAX; | |
| 1298 | − constraints->min_uV = cmin; | |
| 1299 | − constraints->max_uV = cmax; | |
| 1300 | − } | |
| 1301 | − | |
| 1302 | − /* voltage constraints are optional */ | |
| 1303 | − if ((cmin == 0) && (cmax == 0)) | |
| 1304 | − return 0; | |
| 1305 | − | |
| 1306 | − /* else require explicit machine-level constraints */ | |
| 1307 | − if (cmin <= 0 || cmax <= 0 || cmax < cmin) { | |
| 1308 | − rdev_err(rdev, "invalid voltage constraints\n"); | |
| 1309 | − return -EINVAL; | |
| 1310 | − } | |
| 1311 | − | |
| 1312 | − /* no need to loop voltages if range is continuous */ | |
| 1313 | − if (rdev->desc->continuous_voltage_range) | |
| 1314 | − return 0; | |
| 1315 | − | |
| 1316 | − /* initial: [cmin..cmax] valid, [min_uV..max_uV] not */ | |
| 1317 | − for (i = 0; i < count; i++) { | |
| 1318 | − int value; | |
| 1319 | − | |
| 1320 | − value = ops->list_voltage(rdev, i); | |
| 1321 | − if (value <= 0) | |
| 1322 | − continue; | |
| 1323 | − | |
| 1324 | − /* maybe adjust [min_uV..max_uV] */ | |
| 1325 | − if (value >= cmin && value < min_uV) | |
| 1326 | − min_uV = value; | |
| 1327 | − if (value <= cmax && value > max_uV) | |
| 1328 | − max_uV = value; | |
| 1329 | − } | |
| 1330 | − | |
| 1331 | − /* final: [min_uV..max_uV] valid iff constraints valid */ | |
| 1332 | − if (max_uV < min_uV) { | |
| 1333 | − rdev_err(rdev, | |
| 1334 | − "unsupportable voltage constraints %u-%uuV\n", | |
| 1335 | − min_uV, max_uV); | |
| 1336 | − return -EINVAL; | |
| 1337 | − } | |
| 1338 | − | |
| 1339 | − /* use regulator's subset of machine constraints */ | |
| 1340 | − if (constraints->min_uV < min_uV) { | |
| 1341 | − rdev_dbg(rdev, "override min_uV, %d -> %d\n", | |
| 1342 | − constraints->min_uV, min_uV); | |
| 1343 | − constraints->min_uV = min_uV; | |
| 1344 | − } | |
| 1345 | − if (constraints->max_uV > max_uV) { | |
| 1346 | − rdev_dbg(rdev, "override max_uV, %d -> %d\n", | |
| 1347 | − constraints->max_uV, max_uV); | |
| 1348 | − constraints->max_uV = max_uV; | |
| 1349 | − } | |
| 1350 | − } | |
| 1351 | − | |
| 1352 | 1369 | return 0; |
| 1353 | 1370 | } |
| 1354 | 1371 | |
| @@ -492,7 +492,7 @@ static const struct regulator_ops mt6358_volt_fixed_ops = { · 491 unmodified lines | ||
| 492 | 492 | .list_voltage = regulator_list_voltage_linear, |
| 493 | 493 | .map_voltage = regulator_map_voltage_linear, |
| 494 | 494 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
| 495 | − .get_voltage_sel = mt6358_get_buck_voltage_sel, | |
| 495 | + .get_voltage_sel = regulator_get_voltage_sel_regmap, | |
| 496 | 496 | .set_voltage_time_sel = regulator_set_voltage_time_sel, |
| 497 | 497 | .enable = regulator_enable_regmap, |
| 498 | 498 | .disable = regulator_disable_regmap, |