1
2
3
4
5
6#include <common.h>
7#include <command.h>
8#include <asm/arch/pmic_bus.h>
9#include <axp_pmic.h>
10
11static u8 axp152_mvolt_to_target(int mvolt, int min, int max, int div)
12{
13 if (mvolt < min)
14 mvolt = min;
15 else if (mvolt > max)
16 mvolt = max;
17
18 return (mvolt - min) / div;
19}
20
21int axp_set_dcdc2(unsigned int mvolt)
22{
23 int rc;
24 u8 current, target;
25
26 target = axp152_mvolt_to_target(mvolt, 700, 2275, 25);
27
28
29 while ((rc = pmic_bus_read(AXP152_DCDC2_VOLTAGE, ¤t)) == 0 &&
30 current != target) {
31 if (current < target)
32 current++;
33 else
34 current--;
35 rc = pmic_bus_write(AXP152_DCDC2_VOLTAGE, current);
36 if (rc)
37 break;
38 }
39 return rc;
40}
41
42int axp_set_dcdc3(unsigned int mvolt)
43{
44 u8 target = axp152_mvolt_to_target(mvolt, 700, 3500, 50);
45
46 return pmic_bus_write(AXP152_DCDC3_VOLTAGE, target);
47}
48
49int axp_set_dcdc4(unsigned int mvolt)
50{
51 u8 target = axp152_mvolt_to_target(mvolt, 700, 3500, 25);
52
53 return pmic_bus_write(AXP152_DCDC4_VOLTAGE, target);
54}
55
56int axp_set_aldo2(unsigned int mvolt)
57{
58 u8 target = axp152_mvolt_to_target(mvolt, 700, 3500, 100);
59
60 return pmic_bus_write(AXP152_LDO2_VOLTAGE, target);
61}
62
63int axp_init(void)
64{
65 u8 ver;
66 int rc;
67
68 rc = pmic_bus_init();
69 if (rc)
70 return rc;
71
72 rc = pmic_bus_read(AXP152_CHIP_VERSION, &ver);
73 if (rc)
74 return rc;
75
76 if (ver != 0x05)
77 return -EINVAL;
78
79 return 0;
80}
81
82int do_poweroff(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
83{
84 pmic_bus_write(AXP152_SHUTDOWN, AXP152_POWEROFF);
85
86
87 while (1) {}
88
89
90 return 0;
91}
92