forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-02-20 ea08eeccae9297f7aabd2ef7f0c2517ac4549acc
kernel/drivers/regulator/act8865-regulator.c
....@@ -1,19 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * act8865-regulator.c - Voltage regulation for active-semi ACT88xx PMUs
34 *
45 * http://www.active-semi.com/products/power-management-units/act88xx/
56 *
67 * Copyright (C) 2013 Atmel Corporation
7
- *
8
- * This program is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License as published by
10
- * the Free Software Foundation; either version 2 of the License, or
11
- * (at your option) any later version.
12
- *
13
- * This program is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- * GNU General Public License for more details.
178 */
189
1910 #include <linux/module.h>
....@@ -25,8 +16,10 @@
2516 #include <linux/regulator/act8865.h>
2617 #include <linux/of.h>
2718 #include <linux/of_device.h>
19
+#include <linux/power_supply.h>
2820 #include <linux/regulator/of_regulator.h>
2921 #include <linux/regmap.h>
22
+#include <dt-bindings/regulator/active-semi,8865-regulator.h>
3023
3124 /*
3225 * ACT8600 Global Register Map.
....@@ -98,34 +91,49 @@
9891 */
9992 #define ACT8865_SYS_MODE 0x00
10093 #define ACT8865_SYS_CTRL 0x01
94
+#define ACT8865_SYS_UNLK_REGS 0x0b
10195 #define ACT8865_DCDC1_VSET1 0x20
10296 #define ACT8865_DCDC1_VSET2 0x21
10397 #define ACT8865_DCDC1_CTRL 0x22
98
+#define ACT8865_DCDC1_SUS 0x24
10499 #define ACT8865_DCDC2_VSET1 0x30
105100 #define ACT8865_DCDC2_VSET2 0x31
106101 #define ACT8865_DCDC2_CTRL 0x32
102
+#define ACT8865_DCDC2_SUS 0x34
107103 #define ACT8865_DCDC3_VSET1 0x40
108104 #define ACT8865_DCDC3_VSET2 0x41
109105 #define ACT8865_DCDC3_CTRL 0x42
106
+#define ACT8865_DCDC3_SUS 0x44
110107 #define ACT8865_LDO1_VSET 0x50
111108 #define ACT8865_LDO1_CTRL 0x51
109
+#define ACT8865_LDO1_SUS 0x52
112110 #define ACT8865_LDO2_VSET 0x54
113111 #define ACT8865_LDO2_CTRL 0x55
112
+#define ACT8865_LDO2_SUS 0x56
114113 #define ACT8865_LDO3_VSET 0x60
115114 #define ACT8865_LDO3_CTRL 0x61
115
+#define ACT8865_LDO3_SUS 0x62
116116 #define ACT8865_LDO4_VSET 0x64
117117 #define ACT8865_LDO4_CTRL 0x65
118
+#define ACT8865_LDO4_SUS 0x66
118119 #define ACT8865_MSTROFF 0x20
119120
120121 /*
121122 * Field Definitions.
122123 */
123124 #define ACT8865_ENA 0x80 /* ON - [7] */
125
+#define ACT8865_DIS 0x40 /* DIS - [6] */
126
+
124127 #define ACT8865_VSEL_MASK 0x3F /* VSET - [5:0] */
125128
126129
127130 #define ACT8600_LDO10_ENA 0x40 /* ON - [6] */
128131 #define ACT8600_SUDCDC_VSEL_MASK 0xFF /* SUDCDC VSET - [7:0] */
132
+
133
+#define ACT8600_APCH_CHG_ACIN BIT(7)
134
+#define ACT8600_APCH_CHG_USB BIT(6)
135
+#define ACT8600_APCH_CSTATE0 BIT(5)
136
+#define ACT8600_APCH_CSTATE1 BIT(4)
129137
130138 /*
131139 * ACT8865 voltage number
....@@ -212,13 +220,13 @@
212220 .val_bits = 8,
213221 };
214222
215
-static const struct regulator_linear_range act8865_voltage_ranges[] = {
223
+static const struct linear_range act8865_voltage_ranges[] = {
216224 REGULATOR_LINEAR_RANGE(600000, 0, 23, 25000),
217225 REGULATOR_LINEAR_RANGE(1200000, 24, 47, 50000),
218226 REGULATOR_LINEAR_RANGE(2400000, 48, 63, 100000),
219227 };
220228
221
-static const struct regulator_linear_range act8600_sudcdc_voltage_ranges[] = {
229
+static const struct linear_range act8600_sudcdc_voltage_ranges[] = {
222230 REGULATOR_LINEAR_RANGE(3000000, 0, 63, 0),
223231 REGULATOR_LINEAR_RANGE(3000000, 64, 159, 100000),
224232 REGULATOR_LINEAR_RANGE(12600000, 160, 191, 200000),
....@@ -226,29 +234,216 @@
226234 REGULATOR_LINEAR_RANGE(41400000, 248, 255, 0),
227235 };
228236
229
-static struct regulator_ops act8865_ops = {
237
+static int act8865_set_suspend_state(struct regulator_dev *rdev, bool enable)
238
+{
239
+ struct regmap *regmap = rdev->regmap;
240
+ int id = rdev->desc->id, reg, val;
241
+
242
+ switch (id) {
243
+ case ACT8865_ID_DCDC1:
244
+ reg = ACT8865_DCDC1_SUS;
245
+ val = 0xa8;
246
+ break;
247
+ case ACT8865_ID_DCDC2:
248
+ reg = ACT8865_DCDC2_SUS;
249
+ val = 0xa8;
250
+ break;
251
+ case ACT8865_ID_DCDC3:
252
+ reg = ACT8865_DCDC3_SUS;
253
+ val = 0xa8;
254
+ break;
255
+ case ACT8865_ID_LDO1:
256
+ reg = ACT8865_LDO1_SUS;
257
+ val = 0xe8;
258
+ break;
259
+ case ACT8865_ID_LDO2:
260
+ reg = ACT8865_LDO2_SUS;
261
+ val = 0xe8;
262
+ break;
263
+ case ACT8865_ID_LDO3:
264
+ reg = ACT8865_LDO3_SUS;
265
+ val = 0xe8;
266
+ break;
267
+ case ACT8865_ID_LDO4:
268
+ reg = ACT8865_LDO4_SUS;
269
+ val = 0xe8;
270
+ break;
271
+ default:
272
+ return -EINVAL;
273
+ }
274
+
275
+ if (enable)
276
+ val |= BIT(4);
277
+
278
+ /*
279
+ * Ask the PMIC to enable/disable this output when entering hibernate
280
+ * mode.
281
+ */
282
+ return regmap_write(regmap, reg, val);
283
+}
284
+
285
+static int act8865_set_suspend_enable(struct regulator_dev *rdev)
286
+{
287
+ return act8865_set_suspend_state(rdev, true);
288
+}
289
+
290
+static int act8865_set_suspend_disable(struct regulator_dev *rdev)
291
+{
292
+ return act8865_set_suspend_state(rdev, false);
293
+}
294
+
295
+static unsigned int act8865_of_map_mode(unsigned int mode)
296
+{
297
+ switch (mode) {
298
+ case ACT8865_REGULATOR_MODE_FIXED:
299
+ return REGULATOR_MODE_FAST;
300
+ case ACT8865_REGULATOR_MODE_NORMAL:
301
+ return REGULATOR_MODE_NORMAL;
302
+ case ACT8865_REGULATOR_MODE_LOWPOWER:
303
+ return REGULATOR_MODE_STANDBY;
304
+ default:
305
+ return REGULATOR_MODE_INVALID;
306
+ }
307
+}
308
+
309
+static int act8865_set_mode(struct regulator_dev *rdev, unsigned int mode)
310
+{
311
+ struct regmap *regmap = rdev->regmap;
312
+ int id = rdev_get_id(rdev);
313
+ int reg, val = 0;
314
+
315
+ switch (id) {
316
+ case ACT8865_ID_DCDC1:
317
+ reg = ACT8865_DCDC1_CTRL;
318
+ break;
319
+ case ACT8865_ID_DCDC2:
320
+ reg = ACT8865_DCDC2_CTRL;
321
+ break;
322
+ case ACT8865_ID_DCDC3:
323
+ reg = ACT8865_DCDC3_CTRL;
324
+ break;
325
+ case ACT8865_ID_LDO1:
326
+ reg = ACT8865_LDO1_CTRL;
327
+ break;
328
+ case ACT8865_ID_LDO2:
329
+ reg = ACT8865_LDO2_CTRL;
330
+ break;
331
+ case ACT8865_ID_LDO3:
332
+ reg = ACT8865_LDO3_CTRL;
333
+ break;
334
+ case ACT8865_ID_LDO4:
335
+ reg = ACT8865_LDO4_CTRL;
336
+ break;
337
+ default:
338
+ return -EINVAL;
339
+ }
340
+
341
+ switch (mode) {
342
+ case REGULATOR_MODE_FAST:
343
+ case REGULATOR_MODE_NORMAL:
344
+ if (id <= ACT8865_ID_DCDC3)
345
+ val = BIT(5);
346
+ break;
347
+ case REGULATOR_MODE_STANDBY:
348
+ if (id > ACT8865_ID_DCDC3)
349
+ val = BIT(5);
350
+ break;
351
+ default:
352
+ return -EINVAL;
353
+ }
354
+
355
+ return regmap_update_bits(regmap, reg, BIT(5), val);
356
+}
357
+
358
+static unsigned int act8865_get_mode(struct regulator_dev *rdev)
359
+{
360
+ struct regmap *regmap = rdev->regmap;
361
+ int id = rdev_get_id(rdev);
362
+ int reg, ret, val = 0;
363
+
364
+ switch (id) {
365
+ case ACT8865_ID_DCDC1:
366
+ reg = ACT8865_DCDC1_CTRL;
367
+ break;
368
+ case ACT8865_ID_DCDC2:
369
+ reg = ACT8865_DCDC2_CTRL;
370
+ break;
371
+ case ACT8865_ID_DCDC3:
372
+ reg = ACT8865_DCDC3_CTRL;
373
+ break;
374
+ case ACT8865_ID_LDO1:
375
+ reg = ACT8865_LDO1_CTRL;
376
+ break;
377
+ case ACT8865_ID_LDO2:
378
+ reg = ACT8865_LDO2_CTRL;
379
+ break;
380
+ case ACT8865_ID_LDO3:
381
+ reg = ACT8865_LDO3_CTRL;
382
+ break;
383
+ case ACT8865_ID_LDO4:
384
+ reg = ACT8865_LDO4_CTRL;
385
+ break;
386
+ default:
387
+ return -EINVAL;
388
+ }
389
+
390
+ ret = regmap_read(regmap, reg, &val);
391
+ if (ret)
392
+ return ret;
393
+
394
+ if (id <= ACT8865_ID_DCDC3 && (val & BIT(5)))
395
+ return REGULATOR_MODE_FAST;
396
+ else if (id > ACT8865_ID_DCDC3 && !(val & BIT(5)))
397
+ return REGULATOR_MODE_NORMAL;
398
+ else
399
+ return REGULATOR_MODE_STANDBY;
400
+}
401
+
402
+static const struct regulator_ops act8865_ops = {
230403 .list_voltage = regulator_list_voltage_linear_range,
231404 .map_voltage = regulator_map_voltage_linear_range,
232405 .get_voltage_sel = regulator_get_voltage_sel_regmap,
233406 .set_voltage_sel = regulator_set_voltage_sel_regmap,
234407 .enable = regulator_enable_regmap,
235408 .disable = regulator_disable_regmap,
409
+ .set_mode = act8865_set_mode,
410
+ .get_mode = act8865_get_mode,
236411 .is_enabled = regulator_is_enabled_regmap,
412
+ .set_suspend_enable = act8865_set_suspend_enable,
413
+ .set_suspend_disable = act8865_set_suspend_disable,
237414 };
238415
239
-static struct regulator_ops act8865_ldo_ops = {
416
+static const struct regulator_ops act8865_ldo_ops = {
417
+ .list_voltage = regulator_list_voltage_linear_range,
418
+ .map_voltage = regulator_map_voltage_linear_range,
419
+ .get_voltage_sel = regulator_get_voltage_sel_regmap,
420
+ .set_voltage_sel = regulator_set_voltage_sel_regmap,
421
+ .enable = regulator_enable_regmap,
422
+ .disable = regulator_disable_regmap,
423
+ .set_mode = act8865_set_mode,
424
+ .get_mode = act8865_get_mode,
425
+ .is_enabled = regulator_is_enabled_regmap,
426
+ .set_suspend_enable = act8865_set_suspend_enable,
427
+ .set_suspend_disable = act8865_set_suspend_disable,
428
+ .set_pull_down = regulator_set_pull_down_regmap,
429
+};
430
+
431
+static const struct regulator_ops act8865_fixed_ldo_ops = {
240432 .enable = regulator_enable_regmap,
241433 .disable = regulator_disable_regmap,
242434 .is_enabled = regulator_is_enabled_regmap,
243435 };
244436
245
-#define ACT88xx_REG(_name, _family, _id, _vsel_reg, _supply) \
437
+#define ACT88xx_REG_(_name, _family, _id, _vsel_reg, _supply, _ops) \
246438 [_family##_ID_##_id] = { \
247439 .name = _name, \
440
+ .of_match = of_match_ptr(_name), \
441
+ .of_map_mode = act8865_of_map_mode, \
442
+ .regulators_node = of_match_ptr("regulators"), \
248443 .supply_name = _supply, \
249444 .id = _family##_ID_##_id, \
250445 .type = REGULATOR_VOLTAGE, \
251
- .ops = &act8865_ops, \
446
+ .ops = _ops, \
252447 .n_voltages = ACT8865_VOLTAGE_NUM, \
253448 .linear_ranges = act8865_voltage_ranges, \
254449 .n_linear_ranges = ARRAY_SIZE(act8865_voltage_ranges), \
....@@ -256,8 +451,16 @@
256451 .vsel_mask = ACT8865_VSEL_MASK, \
257452 .enable_reg = _family##_##_id##_CTRL, \
258453 .enable_mask = ACT8865_ENA, \
454
+ .pull_down_reg = _family##_##_id##_CTRL, \
455
+ .pull_down_mask = ACT8865_DIS, \
259456 .owner = THIS_MODULE, \
260457 }
458
+
459
+#define ACT88xx_REG(_name, _family, _id, _vsel_reg, _supply) \
460
+ ACT88xx_REG_(_name, _family, _id, _vsel_reg, _supply, &act8865_ops)
461
+
462
+#define ACT88xx_LDO(_name, _family, _id, _vsel_reg, _supply) \
463
+ ACT88xx_REG_(_name, _family, _id, _vsel_reg, _supply, &act8865_ldo_ops)
261464
262465 static const struct regulator_desc act8600_regulators[] = {
263466 ACT88xx_REG("DCDC1", ACT8600, DCDC1, VSET, "vp1"),
....@@ -265,6 +468,8 @@
265468 ACT88xx_REG("DCDC3", ACT8600, DCDC3, VSET, "vp3"),
266469 {
267470 .name = "SUDCDC_REG4",
471
+ .of_match = of_match_ptr("SUDCDC_REG4"),
472
+ .regulators_node = of_match_ptr("regulators"),
268473 .id = ACT8600_ID_SUDCDC4,
269474 .ops = &act8865_ops,
270475 .type = REGULATOR_VOLTAGE,
....@@ -283,8 +488,10 @@
283488 ACT88xx_REG("LDO8", ACT8600, LDO8, VSET, "inl"),
284489 {
285490 .name = "LDO_REG9",
491
+ .of_match = of_match_ptr("LDO_REG9"),
492
+ .regulators_node = of_match_ptr("regulators"),
286493 .id = ACT8600_ID_LDO9,
287
- .ops = &act8865_ldo_ops,
494
+ .ops = &act8865_fixed_ldo_ops,
288495 .type = REGULATOR_VOLTAGE,
289496 .n_voltages = 1,
290497 .fixed_uV = 3300000,
....@@ -294,8 +501,10 @@
294501 },
295502 {
296503 .name = "LDO_REG10",
504
+ .of_match = of_match_ptr("LDO_REG10"),
505
+ .regulators_node = of_match_ptr("regulators"),
297506 .id = ACT8600_ID_LDO10,
298
- .ops = &act8865_ldo_ops,
507
+ .ops = &act8865_fixed_ldo_ops,
299508 .type = REGULATOR_VOLTAGE,
300509 .n_voltages = 1,
301510 .fixed_uV = 1200000,
....@@ -324,20 +533,20 @@
324533 ACT88xx_REG("DCDC_REG1", ACT8865, DCDC1, VSET1, "vp1"),
325534 ACT88xx_REG("DCDC_REG2", ACT8865, DCDC2, VSET1, "vp2"),
326535 ACT88xx_REG("DCDC_REG3", ACT8865, DCDC3, VSET1, "vp3"),
327
- ACT88xx_REG("LDO_REG1", ACT8865, LDO1, VSET, "inl45"),
328
- ACT88xx_REG("LDO_REG2", ACT8865, LDO2, VSET, "inl45"),
329
- ACT88xx_REG("LDO_REG3", ACT8865, LDO3, VSET, "inl67"),
330
- ACT88xx_REG("LDO_REG4", ACT8865, LDO4, VSET, "inl67"),
536
+ ACT88xx_LDO("LDO_REG1", ACT8865, LDO1, VSET, "inl45"),
537
+ ACT88xx_LDO("LDO_REG2", ACT8865, LDO2, VSET, "inl45"),
538
+ ACT88xx_LDO("LDO_REG3", ACT8865, LDO3, VSET, "inl67"),
539
+ ACT88xx_LDO("LDO_REG4", ACT8865, LDO4, VSET, "inl67"),
331540 };
332541
333542 static const struct regulator_desc act8865_alt_regulators[] = {
334543 ACT88xx_REG("DCDC_REG1", ACT8865, DCDC1, VSET2, "vp1"),
335544 ACT88xx_REG("DCDC_REG2", ACT8865, DCDC2, VSET2, "vp2"),
336545 ACT88xx_REG("DCDC_REG3", ACT8865, DCDC3, VSET2, "vp3"),
337
- ACT88xx_REG("LDO_REG1", ACT8865, LDO1, VSET, "inl45"),
338
- ACT88xx_REG("LDO_REG2", ACT8865, LDO2, VSET, "inl45"),
339
- ACT88xx_REG("LDO_REG3", ACT8865, LDO3, VSET, "inl67"),
340
- ACT88xx_REG("LDO_REG4", ACT8865, LDO4, VSET, "inl67"),
546
+ ACT88xx_LDO("LDO_REG1", ACT8865, LDO1, VSET, "inl45"),
547
+ ACT88xx_LDO("LDO_REG2", ACT8865, LDO2, VSET, "inl45"),
548
+ ACT88xx_LDO("LDO_REG3", ACT8865, LDO3, VSET, "inl67"),
549
+ ACT88xx_LDO("LDO_REG4", ACT8865, LDO4, VSET, "inl67"),
341550 };
342551
343552 #ifdef CONFIG_OF
....@@ -348,119 +557,12 @@
348557 { }
349558 };
350559 MODULE_DEVICE_TABLE(of, act8865_dt_ids);
351
-
352
-static struct of_regulator_match act8846_matches[] = {
353
- [ACT8846_ID_REG1] = { .name = "REG1" },
354
- [ACT8846_ID_REG2] = { .name = "REG2" },
355
- [ACT8846_ID_REG3] = { .name = "REG3" },
356
- [ACT8846_ID_REG4] = { .name = "REG4" },
357
- [ACT8846_ID_REG5] = { .name = "REG5" },
358
- [ACT8846_ID_REG6] = { .name = "REG6" },
359
- [ACT8846_ID_REG7] = { .name = "REG7" },
360
- [ACT8846_ID_REG8] = { .name = "REG8" },
361
- [ACT8846_ID_REG9] = { .name = "REG9" },
362
- [ACT8846_ID_REG10] = { .name = "REG10" },
363
- [ACT8846_ID_REG11] = { .name = "REG11" },
364
- [ACT8846_ID_REG12] = { .name = "REG12" },
365
-};
366
-
367
-static struct of_regulator_match act8865_matches[] = {
368
- [ACT8865_ID_DCDC1] = { .name = "DCDC_REG1"},
369
- [ACT8865_ID_DCDC2] = { .name = "DCDC_REG2"},
370
- [ACT8865_ID_DCDC3] = { .name = "DCDC_REG3"},
371
- [ACT8865_ID_LDO1] = { .name = "LDO_REG1"},
372
- [ACT8865_ID_LDO2] = { .name = "LDO_REG2"},
373
- [ACT8865_ID_LDO3] = { .name = "LDO_REG3"},
374
- [ACT8865_ID_LDO4] = { .name = "LDO_REG4"},
375
-};
376
-
377
-static struct of_regulator_match act8600_matches[] = {
378
- [ACT8600_ID_DCDC1] = { .name = "DCDC_REG1"},
379
- [ACT8600_ID_DCDC2] = { .name = "DCDC_REG2"},
380
- [ACT8600_ID_DCDC3] = { .name = "DCDC_REG3"},
381
- [ACT8600_ID_SUDCDC4] = { .name = "SUDCDC_REG4"},
382
- [ACT8600_ID_LDO5] = { .name = "LDO_REG5"},
383
- [ACT8600_ID_LDO6] = { .name = "LDO_REG6"},
384
- [ACT8600_ID_LDO7] = { .name = "LDO_REG7"},
385
- [ACT8600_ID_LDO8] = { .name = "LDO_REG8"},
386
- [ACT8600_ID_LDO9] = { .name = "LDO_REG9"},
387
- [ACT8600_ID_LDO10] = { .name = "LDO_REG10"},
388
-};
389
-
390
-static int act8865_pdata_from_dt(struct device *dev,
391
- struct act8865_platform_data *pdata,
392
- unsigned long type)
393
-{
394
- int matched, i, num_matches;
395
- struct device_node *np;
396
- struct act8865_regulator_data *regulator;
397
- struct of_regulator_match *matches;
398
-
399
- switch (type) {
400
- case ACT8600:
401
- matches = act8600_matches;
402
- num_matches = ARRAY_SIZE(act8600_matches);
403
- break;
404
- case ACT8846:
405
- matches = act8846_matches;
406
- num_matches = ARRAY_SIZE(act8846_matches);
407
- break;
408
- case ACT8865:
409
- matches = act8865_matches;
410
- num_matches = ARRAY_SIZE(act8865_matches);
411
- break;
412
- default:
413
- dev_err(dev, "invalid device id %lu\n", type);
414
- return -EINVAL;
415
- }
416
-
417
- np = of_get_child_by_name(dev->of_node, "regulators");
418
- if (!np) {
419
- dev_err(dev, "missing 'regulators' subnode in DT\n");
420
- return -EINVAL;
421
- }
422
-
423
- matched = of_regulator_match(dev, np, matches, num_matches);
424
- of_node_put(np);
425
- if (matched <= 0)
426
- return matched;
427
-
428
- pdata->regulators = devm_kcalloc(dev,
429
- num_matches,
430
- sizeof(struct act8865_regulator_data),
431
- GFP_KERNEL);
432
- if (!pdata->regulators)
433
- return -ENOMEM;
434
-
435
- pdata->num_regulators = num_matches;
436
- regulator = pdata->regulators;
437
-
438
- for (i = 0; i < num_matches; i++) {
439
- regulator->id = i;
440
- regulator->name = matches[i].name;
441
- regulator->init_data = matches[i].init_data;
442
- regulator->of_node = matches[i].of_node;
443
- regulator++;
444
- }
445
-
446
- return 0;
447
-}
448
-#else
449
-static inline int act8865_pdata_from_dt(struct device *dev,
450
- struct act8865_platform_data *pdata,
451
- unsigned long type)
452
-{
453
- return 0;
454
-}
455560 #endif
456561
457562 static struct act8865_regulator_data *act8865_get_regulator_data(
458563 int id, struct act8865_platform_data *pdata)
459564 {
460565 int i;
461
-
462
- if (!pdata)
463
- return NULL;
464566
465567 for (i = 0; i < pdata->num_regulators; i++) {
466568 if (pdata->regulators[i].id == id)
....@@ -480,11 +582,80 @@
480582 while (1);
481583 }
482584
585
+static int act8600_charger_get_status(struct regmap *map)
586
+{
587
+ unsigned int val;
588
+ int ret;
589
+ u8 state0, state1;
590
+
591
+ ret = regmap_read(map, ACT8600_APCH_STAT, &val);
592
+ if (ret < 0)
593
+ return ret;
594
+
595
+ state0 = val & ACT8600_APCH_CSTATE0;
596
+ state1 = val & ACT8600_APCH_CSTATE1;
597
+
598
+ if (state0 && !state1)
599
+ return POWER_SUPPLY_STATUS_CHARGING;
600
+ if (!state0 && state1)
601
+ return POWER_SUPPLY_STATUS_NOT_CHARGING;
602
+ if (!state0 && !state1)
603
+ return POWER_SUPPLY_STATUS_DISCHARGING;
604
+
605
+ return POWER_SUPPLY_STATUS_UNKNOWN;
606
+}
607
+
608
+static int act8600_charger_get_property(struct power_supply *psy,
609
+ enum power_supply_property psp, union power_supply_propval *val)
610
+{
611
+ struct regmap *map = power_supply_get_drvdata(psy);
612
+ int ret;
613
+
614
+ switch (psp) {
615
+ case POWER_SUPPLY_PROP_STATUS:
616
+ ret = act8600_charger_get_status(map);
617
+ if (ret < 0)
618
+ return ret;
619
+
620
+ val->intval = ret;
621
+ break;
622
+ default:
623
+ return -EINVAL;
624
+ }
625
+
626
+ return 0;
627
+}
628
+
629
+static enum power_supply_property act8600_charger_properties[] = {
630
+ POWER_SUPPLY_PROP_STATUS,
631
+};
632
+
633
+static const struct power_supply_desc act8600_charger_desc = {
634
+ .name = "act8600-charger",
635
+ .type = POWER_SUPPLY_TYPE_BATTERY,
636
+ .properties = act8600_charger_properties,
637
+ .num_properties = ARRAY_SIZE(act8600_charger_properties),
638
+ .get_property = act8600_charger_get_property,
639
+};
640
+
641
+static int act8600_charger_probe(struct device *dev, struct regmap *regmap)
642
+{
643
+ struct power_supply *charger;
644
+ struct power_supply_config cfg = {
645
+ .drv_data = regmap,
646
+ .of_node = dev->of_node,
647
+ };
648
+
649
+ charger = devm_power_supply_register(dev, &act8600_charger_desc, &cfg);
650
+
651
+ return PTR_ERR_OR_ZERO(charger);
652
+}
653
+
483654 static int act8865_pmic_probe(struct i2c_client *client,
484655 const struct i2c_device_id *i2c_id)
485656 {
486657 const struct regulator_desc *regulators;
487
- struct act8865_platform_data pdata_of, *pdata;
658
+ struct act8865_platform_data *pdata = NULL;
488659 struct device *dev = &client->dev;
489660 int i, ret, num_regulators;
490661 struct act8865 *act8865;
....@@ -493,9 +664,7 @@
493664 int off_reg, off_mask;
494665 int voltage_select = 0;
495666
496
- pdata = dev_get_platdata(dev);
497
-
498
- if (dev->of_node && !pdata) {
667
+ if (dev->of_node) {
499668 const struct of_device_id *id;
500669
501670 id = of_match_device(of_match_ptr(act8865_dt_ids), dev);
....@@ -509,6 +678,7 @@
509678 NULL);
510679 } else {
511680 type = i2c_id->driver_data;
681
+ pdata = dev_get_platdata(dev);
512682 }
513683
514684 switch (type) {
....@@ -543,14 +713,6 @@
543713 return -EINVAL;
544714 }
545715
546
- if (dev->of_node && !pdata) {
547
- ret = act8865_pdata_from_dt(dev, &pdata_of, type);
548
- if (ret < 0)
549
- return ret;
550
-
551
- pdata = &pdata_of;
552
- }
553
-
554716 act8865 = devm_kzalloc(dev, sizeof(struct act8865), GFP_KERNEL);
555717 if (!act8865)
556718 return -ENOMEM;
....@@ -577,17 +739,20 @@
577739 for (i = 0; i < num_regulators; i++) {
578740 const struct regulator_desc *desc = &regulators[i];
579741 struct regulator_config config = { };
580
- struct act8865_regulator_data *rdata;
581742 struct regulator_dev *rdev;
582743
583744 config.dev = dev;
584745 config.driver_data = act8865;
585746 config.regmap = act8865->regmap;
586747
587
- rdata = act8865_get_regulator_data(desc->id, pdata);
588
- if (rdata) {
589
- config.init_data = rdata->init_data;
590
- config.of_node = rdata->of_node;
748
+ if (pdata) {
749
+ struct act8865_regulator_data *rdata;
750
+
751
+ rdata = act8865_get_regulator_data(desc->id, pdata);
752
+ if (rdata) {
753
+ config.init_data = rdata->init_data;
754
+ config.of_node = rdata->of_node;
755
+ }
591756 }
592757
593758 rdev = devm_regulator_register(dev, desc, &config);
....@@ -597,9 +762,20 @@
597762 }
598763 }
599764
765
+ if (type == ACT8600) {
766
+ ret = act8600_charger_probe(dev, act8865->regmap);
767
+ if (ret < 0) {
768
+ if (ret != -EPROBE_DEFER)
769
+ dev_err(dev, "Failed to probe charger");
770
+ return ret;
771
+ }
772
+ }
773
+
600774 i2c_set_clientdata(client, act8865);
601775
602
- return 0;
776
+ /* Unlock expert registers for ACT8865. */
777
+ return type != ACT8865 ? 0 : regmap_write(act8865->regmap,
778
+ ACT8865_SYS_UNLK_REGS, 0xef);
603779 }
604780
605781 static const struct i2c_device_id act8865_ids[] = {