]> git.ipfire.org Git - thirdparty/u-boot.git/blame - drivers/power/axp152.c
Revert "Merge patch series "arm: dts: am62-beagleplay: Fix Beagleplay Ethernet""
[thirdparty/u-boot.git] / drivers / power / axp152.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0+
24289208
HG
2/*
3 * (C) Copyright 2012
4 * Henrik Nordstrom <henrik@henriknordstrom.net>
24289208 5 */
d678a59d 6#include <common.h>
c286cdfe 7#include <command.h>
30490b52 8#include <asm/arch/pmic_bus.h>
6944aff1 9#include <axp_pmic.h>
24289208 10
24289208
HG
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
6944aff1 21int axp_set_dcdc2(unsigned int mvolt)
24289208
HG
22{
23 int rc;
24 u8 current, target;
25
26 target = axp152_mvolt_to_target(mvolt, 700, 2275, 25);
27
28 /* Do we really need to be this gentle? It has built-in voltage slope */
30490b52 29 while ((rc = pmic_bus_read(AXP152_DCDC2_VOLTAGE, &current)) == 0 &&
24289208
HG
30 current != target) {
31 if (current < target)
32 current++;
33 else
34 current--;
30490b52 35 rc = pmic_bus_write(AXP152_DCDC2_VOLTAGE, current);
24289208
HG
36 if (rc)
37 break;
38 }
39 return rc;
40}
41
6944aff1 42int axp_set_dcdc3(unsigned int mvolt)
24289208 43{
74bf7961 44 u8 target = axp152_mvolt_to_target(mvolt, 700, 3500, 50);
24289208 45
30490b52 46 return pmic_bus_write(AXP152_DCDC3_VOLTAGE, target);
24289208
HG
47}
48
6944aff1 49int axp_set_dcdc4(unsigned int mvolt)
24289208
HG
50{
51 u8 target = axp152_mvolt_to_target(mvolt, 700, 3500, 25);
52
30490b52 53 return pmic_bus_write(AXP152_DCDC4_VOLTAGE, target);
24289208
HG
54}
55
6944aff1 56int axp_set_aldo2(unsigned int mvolt)
24289208
HG
57{
58 u8 target = axp152_mvolt_to_target(mvolt, 700, 3500, 100);
59
30490b52 60 return pmic_bus_write(AXP152_LDO2_VOLTAGE, target);
24289208
HG
61}
62
6944aff1 63int axp_init(void)
24289208
HG
64{
65 u8 ver;
66 int rc;
67
30490b52
HG
68 rc = pmic_bus_init();
69 if (rc)
70 return rc;
71
72 rc = pmic_bus_read(AXP152_CHIP_VERSION, &ver);
24289208
HG
73 if (rc)
74 return rc;
75
76 if (ver != 0x05)
505cf475 77 return -EINVAL;
24289208
HG
78
79 return 0;
80}
c286cdfe 81
830e161e 82#if !IS_ENABLED(CONFIG_SYSRESET_CMD_POWEROFF)
09140113 83int do_poweroff(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
c286cdfe
HG
84{
85 pmic_bus_write(AXP152_SHUTDOWN, AXP152_POWEROFF);
86
87 /* infinite loop during shutdown */
88 while (1) {}
89
90 /* not reached */
91 return 0;
92}
830e161e 93#endif