hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/mfd/tps65218.c
....@@ -1,7 +1,7 @@
11 /*
22 * Driver for TPS65218 Integrated power management chipsets
33 *
4
- * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
4
+ * Copyright (C) 2014 Texas Instruments Incorporated - https://www.ti.com/
55 *
66 * This program is free software; you can redistribute it and/or
77 * modify it under the terms of the GNU General Public License version 2 as
....@@ -48,7 +48,7 @@
4848 /**
4949 * tps65218_reg_write: Write a single tps65218 register.
5050 *
51
- * @tps65218: Device to write to.
51
+ * @tps: Device to write to.
5252 * @reg: Register to write to.
5353 * @val: Value to write.
5454 * @level: Password protected level
....@@ -79,7 +79,7 @@
7979 /**
8080 * tps65218_update_bits: Modify bits w.r.t mask, val and level.
8181 *
82
- * @tps65218: Device to write to.
82
+ * @tps: Device to write to.
8383 * @reg: Register to read-write to.
8484 * @mask: Mask.
8585 * @val: Value to write.
....@@ -211,6 +211,83 @@
211211 };
212212 MODULE_DEVICE_TABLE(of, of_tps65218_match_table);
213213
214
+static int tps65218_voltage_set_strict(struct tps65218 *tps)
215
+{
216
+ u32 strict;
217
+
218
+ if (of_property_read_u32(tps->dev->of_node,
219
+ "ti,strict-supply-voltage-supervision",
220
+ &strict))
221
+ return 0;
222
+
223
+ if (strict != 0 && strict != 1) {
224
+ dev_err(tps->dev,
225
+ "Invalid ti,strict-supply-voltage-supervision value\n");
226
+ return -EINVAL;
227
+ }
228
+
229
+ tps65218_update_bits(tps, TPS65218_REG_CONFIG1,
230
+ TPS65218_CONFIG1_STRICT,
231
+ strict ? TPS65218_CONFIG1_STRICT : 0,
232
+ TPS65218_PROTECT_L1);
233
+ return 0;
234
+}
235
+
236
+static int tps65218_voltage_set_uv_hyst(struct tps65218 *tps)
237
+{
238
+ u32 hyst;
239
+
240
+ if (of_property_read_u32(tps->dev->of_node,
241
+ "ti,under-voltage-hyst-microvolt", &hyst))
242
+ return 0;
243
+
244
+ if (hyst != 400000 && hyst != 200000) {
245
+ dev_err(tps->dev,
246
+ "Invalid ti,under-voltage-hyst-microvolt value\n");
247
+ return -EINVAL;
248
+ }
249
+
250
+ tps65218_update_bits(tps, TPS65218_REG_CONFIG2,
251
+ TPS65218_CONFIG2_UVLOHYS,
252
+ hyst == 400000 ? TPS65218_CONFIG2_UVLOHYS : 0,
253
+ TPS65218_PROTECT_L1);
254
+ return 0;
255
+}
256
+
257
+static int tps65218_voltage_set_uvlo(struct tps65218 *tps)
258
+{
259
+ u32 uvlo;
260
+ int uvloval;
261
+
262
+ if (of_property_read_u32(tps->dev->of_node,
263
+ "ti,under-voltage-limit-microvolt", &uvlo))
264
+ return 0;
265
+
266
+ switch (uvlo) {
267
+ case 2750000:
268
+ uvloval = TPS65218_CONFIG1_UVLO_2750000;
269
+ break;
270
+ case 2950000:
271
+ uvloval = TPS65218_CONFIG1_UVLO_2950000;
272
+ break;
273
+ case 3250000:
274
+ uvloval = TPS65218_CONFIG1_UVLO_3250000;
275
+ break;
276
+ case 3350000:
277
+ uvloval = TPS65218_CONFIG1_UVLO_3350000;
278
+ break;
279
+ default:
280
+ dev_err(tps->dev,
281
+ "Invalid ti,under-voltage-limit-microvolt value\n");
282
+ return -EINVAL;
283
+ }
284
+
285
+ tps65218_update_bits(tps, TPS65218_REG_CONFIG1,
286
+ TPS65218_CONFIG1_UVLO_MASK, uvloval,
287
+ TPS65218_PROTECT_L1);
288
+ return 0;
289
+}
290
+
214291 static int tps65218_probe(struct i2c_client *client,
215292 const struct i2c_device_id *ids)
216293 {
....@@ -249,6 +326,18 @@
249326
250327 tps->rev = chipid & TPS65218_CHIPID_REV_MASK;
251328
329
+ ret = tps65218_voltage_set_strict(tps);
330
+ if (ret)
331
+ return ret;
332
+
333
+ ret = tps65218_voltage_set_uvlo(tps);
334
+ if (ret)
335
+ return ret;
336
+
337
+ ret = tps65218_voltage_set_uv_hyst(tps);
338
+ if (ret)
339
+ return ret;
340
+
252341 ret = mfd_add_devices(tps->dev, PLATFORM_DEVID_AUTO, tps65218_cells,
253342 ARRAY_SIZE(tps65218_cells), NULL, 0,
254343 regmap_irq_get_domain(tps->irq_data));