]> git.ipfire.org Git - people/ms/u-boot.git/blame - drivers/power/axp152.c
dm: blk: Use uclass_find_first/next_device() in blk_first/next_device()
[people/ms/u-boot.git] / drivers / power / axp152.c
CommitLineData
24289208
HG
1/*
2 * (C) Copyright 2012
3 * Henrik Nordstrom <henrik@henriknordstrom.net>
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7#include <common.h>
c286cdfe 8#include <command.h>
30490b52 9#include <asm/arch/pmic_bus.h>
6944aff1 10#include <axp_pmic.h>
24289208 11
24289208
HG
12static u8 axp152_mvolt_to_target(int mvolt, int min, int max, int div)
13{
14 if (mvolt < min)
15 mvolt = min;
16 else if (mvolt > max)
17 mvolt = max;
18
19 return (mvolt - min) / div;
20}
21
6944aff1 22int axp_set_dcdc2(unsigned int mvolt)
24289208
HG
23{
24 int rc;
25 u8 current, target;
26
27 target = axp152_mvolt_to_target(mvolt, 700, 2275, 25);
28
29 /* Do we really need to be this gentle? It has built-in voltage slope */
30490b52 30 while ((rc = pmic_bus_read(AXP152_DCDC2_VOLTAGE, &current)) == 0 &&
24289208
HG
31 current != target) {
32 if (current < target)
33 current++;
34 else
35 current--;
30490b52 36 rc = pmic_bus_write(AXP152_DCDC2_VOLTAGE, current);
24289208
HG
37 if (rc)
38 break;
39 }
40 return rc;
41}
42
6944aff1 43int axp_set_dcdc3(unsigned int mvolt)
24289208 44{
74bf7961 45 u8 target = axp152_mvolt_to_target(mvolt, 700, 3500, 50);
24289208 46
30490b52 47 return pmic_bus_write(AXP152_DCDC3_VOLTAGE, target);
24289208
HG
48}
49
6944aff1 50int axp_set_dcdc4(unsigned int mvolt)
24289208
HG
51{
52 u8 target = axp152_mvolt_to_target(mvolt, 700, 3500, 25);
53
30490b52 54 return pmic_bus_write(AXP152_DCDC4_VOLTAGE, target);
24289208
HG
55}
56
6944aff1 57int axp_set_aldo2(unsigned int mvolt)
24289208
HG
58{
59 u8 target = axp152_mvolt_to_target(mvolt, 700, 3500, 100);
60
30490b52 61 return pmic_bus_write(AXP152_LDO2_VOLTAGE, target);
24289208
HG
62}
63
6944aff1 64int axp_init(void)
24289208
HG
65{
66 u8 ver;
67 int rc;
68
30490b52
HG
69 rc = pmic_bus_init();
70 if (rc)
71 return rc;
72
73 rc = pmic_bus_read(AXP152_CHIP_VERSION, &ver);
24289208
HG
74 if (rc)
75 return rc;
76
77 if (ver != 0x05)
505cf475 78 return -EINVAL;
24289208
HG
79
80 return 0;
81}
c286cdfe
HG
82
83int do_poweroff(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
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}