command: Remove the cmd_tbl_t typedef
[oweals/u-boot.git] / drivers / power / axp152.c
index 740a3b41cd31ade7b5a88d11b77986ef4bdef36d..d6e36125c12cfb6f7862a1747fe6db1109f0c090 100644 (file)
@@ -1,22 +1,12 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * (C) Copyright 2012
  * Henrik Nordstrom <henrik@henriknordstrom.net>
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 #include <common.h>
-#include <i2c.h>
-#include <axp152.h>
-
-static int axp152_write(enum axp152_reg reg, u8 val)
-{
-       return i2c_write(0x30, reg, 1, &val, 1);
-}
-
-static int axp152_read(enum axp152_reg reg, u8 *val)
-{
-       return i2c_read(0x30, reg, 1, val, 1);
-}
+#include <command.h>
+#include <asm/arch/pmic_bus.h>
+#include <axp_pmic.h>
 
 static u8 axp152_mvolt_to_target(int mvolt, int min, int max, int div)
 {
@@ -28,7 +18,7 @@ static u8 axp152_mvolt_to_target(int mvolt, int min, int max, int div)
        return (mvolt - min) / div;
 }
 
-int axp152_set_dcdc2(int mvolt)
+int axp_set_dcdc2(unsigned int mvolt)
 {
        int rc;
        u8 current, target;
@@ -36,51 +26,66 @@ int axp152_set_dcdc2(int mvolt)
        target = axp152_mvolt_to_target(mvolt, 700, 2275, 25);
 
        /* Do we really need to be this gentle? It has built-in voltage slope */
-       while ((rc = axp152_read(AXP152_DCDC2_VOLTAGE, &current)) == 0 &&
+       while ((rc = pmic_bus_read(AXP152_DCDC2_VOLTAGE, &current)) == 0 &&
               current != target) {
                if (current < target)
                        current++;
                else
                        current--;
-               rc = axp152_write(AXP152_DCDC2_VOLTAGE, current);
+               rc = pmic_bus_write(AXP152_DCDC2_VOLTAGE, current);
                if (rc)
                        break;
        }
        return rc;
 }
 
-int axp152_set_dcdc3(int mvolt)
+int axp_set_dcdc3(unsigned int mvolt)
 {
        u8 target = axp152_mvolt_to_target(mvolt, 700, 3500, 50);
 
-       return axp152_write(AXP152_DCDC3_VOLTAGE, target);
+       return pmic_bus_write(AXP152_DCDC3_VOLTAGE, target);
 }
 
-int axp152_set_dcdc4(int mvolt)
+int axp_set_dcdc4(unsigned int mvolt)
 {
        u8 target = axp152_mvolt_to_target(mvolt, 700, 3500, 25);
 
-       return axp152_write(AXP152_DCDC4_VOLTAGE, target);
+       return pmic_bus_write(AXP152_DCDC4_VOLTAGE, target);
 }
 
-int axp152_set_ldo2(int mvolt)
+int axp_set_aldo2(unsigned int mvolt)
 {
        u8 target = axp152_mvolt_to_target(mvolt, 700, 3500, 100);
 
-       return axp152_write(AXP152_LDO2_VOLTAGE, target);
+       return pmic_bus_write(AXP152_LDO2_VOLTAGE, target);
 }
 
-int axp152_init(void)
+int axp_init(void)
 {
        u8 ver;
        int rc;
 
-       rc = axp152_read(AXP152_CHIP_VERSION, &ver);
+       rc = pmic_bus_init();
+       if (rc)
+               return rc;
+
+       rc = pmic_bus_read(AXP152_CHIP_VERSION, &ver);
        if (rc)
                return rc;
 
        if (ver != 0x05)
-               return -1;
+               return -EINVAL;
+
+       return 0;
+}
+
+int do_poweroff(struct cmd_tbl *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;
 }