2014-06-13 20:55:51 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2012
|
|
|
|
* Henrik Nordstrom <henrik@henriknordstrom.net>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
|
|
|
*/
|
|
|
|
#include <common.h>
|
2015-12-20 15:10:01 +00:00
|
|
|
#include <command.h>
|
2015-10-03 14:12:27 +00:00
|
|
|
#include <asm/arch/pmic_bus.h>
|
2015-10-03 13:18:33 +00:00
|
|
|
#include <axp_pmic.h>
|
2014-06-13 20:55:51 +00:00
|
|
|
|
|
|
|
static u8 axp152_mvolt_to_target(int mvolt, int min, int max, int div)
|
|
|
|
{
|
|
|
|
if (mvolt < min)
|
|
|
|
mvolt = min;
|
|
|
|
else if (mvolt > max)
|
|
|
|
mvolt = max;
|
|
|
|
|
|
|
|
return (mvolt - min) / div;
|
|
|
|
}
|
|
|
|
|
2015-10-03 13:18:33 +00:00
|
|
|
int axp_set_dcdc2(unsigned int mvolt)
|
2014-06-13 20:55:51 +00:00
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
u8 current, target;
|
|
|
|
|
|
|
|
target = axp152_mvolt_to_target(mvolt, 700, 2275, 25);
|
|
|
|
|
|
|
|
/* Do we really need to be this gentle? It has built-in voltage slope */
|
2015-10-03 14:12:27 +00:00
|
|
|
while ((rc = pmic_bus_read(AXP152_DCDC2_VOLTAGE, ¤t)) == 0 &&
|
2014-06-13 20:55:51 +00:00
|
|
|
current != target) {
|
|
|
|
if (current < target)
|
|
|
|
current++;
|
|
|
|
else
|
|
|
|
current--;
|
2015-10-03 14:12:27 +00:00
|
|
|
rc = pmic_bus_write(AXP152_DCDC2_VOLTAGE, current);
|
2014-06-13 20:55:51 +00:00
|
|
|
if (rc)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2015-10-03 13:18:33 +00:00
|
|
|
int axp_set_dcdc3(unsigned int mvolt)
|
2014-06-13 20:55:51 +00:00
|
|
|
{
|
2014-10-13 12:51:40 +00:00
|
|
|
u8 target = axp152_mvolt_to_target(mvolt, 700, 3500, 50);
|
2014-06-13 20:55:51 +00:00
|
|
|
|
2015-10-03 14:12:27 +00:00
|
|
|
return pmic_bus_write(AXP152_DCDC3_VOLTAGE, target);
|
2014-06-13 20:55:51 +00:00
|
|
|
}
|
|
|
|
|
2015-10-03 13:18:33 +00:00
|
|
|
int axp_set_dcdc4(unsigned int mvolt)
|
2014-06-13 20:55:51 +00:00
|
|
|
{
|
|
|
|
u8 target = axp152_mvolt_to_target(mvolt, 700, 3500, 25);
|
|
|
|
|
2015-10-03 14:12:27 +00:00
|
|
|
return pmic_bus_write(AXP152_DCDC4_VOLTAGE, target);
|
2014-06-13 20:55:51 +00:00
|
|
|
}
|
|
|
|
|
2015-10-03 13:18:33 +00:00
|
|
|
int axp_set_aldo2(unsigned int mvolt)
|
2014-06-13 20:55:51 +00:00
|
|
|
{
|
|
|
|
u8 target = axp152_mvolt_to_target(mvolt, 700, 3500, 100);
|
|
|
|
|
2015-10-03 14:12:27 +00:00
|
|
|
return pmic_bus_write(AXP152_LDO2_VOLTAGE, target);
|
2014-06-13 20:55:51 +00:00
|
|
|
}
|
|
|
|
|
2015-10-03 13:18:33 +00:00
|
|
|
int axp_init(void)
|
2014-06-13 20:55:51 +00:00
|
|
|
{
|
|
|
|
u8 ver;
|
|
|
|
int rc;
|
|
|
|
|
2015-10-03 14:12:27 +00:00
|
|
|
rc = pmic_bus_init();
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
rc = pmic_bus_read(AXP152_CHIP_VERSION, &ver);
|
2014-06-13 20:55:51 +00:00
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
if (ver != 0x05)
|
2016-12-15 11:49:50 +00:00
|
|
|
return -EINVAL;
|
2014-06-13 20:55:51 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2015-12-20 15:10:01 +00:00
|
|
|
|
|
|
|
int do_poweroff(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
|
|
|
{
|
|
|
|
pmic_bus_write(AXP152_SHUTDOWN, AXP152_POWEROFF);
|
|
|
|
|
|
|
|
/* infinite loop during shutdown */
|
|
|
|
while (1) {}
|
|
|
|
|
|
|
|
/* not reached */
|
|
|
|
return 0;
|
|
|
|
}
|