]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
pmic: pmic_mc34vr500: Add APIs to set/get SWx volt
authorHou Zhiqiang <Zhiqiang.Hou@nxp.com>
Fri, 9 Dec 2016 08:08:58 +0000 (16:08 +0800)
committerYork Sun <york.sun@nxp.com>
Wed, 18 Jan 2017 17:28:57 +0000 (09:28 -0800)
Signed-off-by: Hou Zhiqiang <Zhiqiang.Hou@nxp.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>
Reviewed-by: York Sun <york.sun@nxp.com>
board/freescale/common/Makefile
board/freescale/common/mc34vr500.c [new file with mode: 0644]
include/power/mc34vr500_pmic.h

index e9419492bc3dafb156be8d9a63c9a4c3f3e2aebe..1c53fb605b974215c64c8d06a8bf91d0a20fb0aa 100644 (file)
@@ -61,6 +61,7 @@ obj-$(CONFIG_VSC_CROSSBAR)    += vsc3316_3308.o
 obj-$(CONFIG_IDT8T49N222A)     += idt8t49n222a_serdes_clk.o
 obj-$(CONFIG_ZM7300)           += zm7300.o
 obj-$(CONFIG_POWER_PFUZE100)   += pfuze.o
+obj-$(CONFIG_POWER_MC34VR500)  += mc34vr500.o
 
 obj-$(CONFIG_LS102XA_STREAM_ID)        += ls102xa_stream_id.o
 
diff --git a/board/freescale/common/mc34vr500.c b/board/freescale/common/mc34vr500.c
new file mode 100644 (file)
index 0000000..9c57569
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+ * Copyright 2016 Freescale Semiconductor, Inc.
+ * Hou Zhiqiang <Zhiqiang.Hou@freescale.com>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <errno.h>
+#include <i2c.h>
+#include <power/pmic.h>
+#include <power/mc34vr500_pmic.h>
+
+static uint8_t swxvolt_addr[4] = { MC34VR500_SW1VOLT,
+                                  MC34VR500_SW2VOLT,
+                                  MC34VR500_SW3VOLT,
+                                  MC34VR500_SW4VOLT };
+
+static uint8_t swx_set_point_base[4] = { 13, 9, 9, 9 };
+
+int mc34vr500_get_sw_volt(uint8_t sw)
+{
+       struct pmic *p;
+       u32 swxvolt;
+       uint8_t spb;
+       int sw_volt;
+       int ret;
+
+       debug("%s: Get SW%u volt from swxvolt_addr = 0x%x\n",
+             __func__, sw + 1, swxvolt_addr[sw]);
+       if (sw > SW4) {
+               printf("%s: Unsupported SW(sw%d)\n", __func__, sw + 1);
+               return -EINVAL;
+       }
+
+       p = pmic_get("MC34VR500");
+       if (!p) {
+               printf("%s: Did NOT find PMIC MC34VR500\n", __func__);
+               return -ENODEV;
+       }
+
+       ret = pmic_probe(p);
+       if (ret)
+               return ret;
+
+       ret = pmic_reg_read(p, swxvolt_addr[sw], &swxvolt);
+       if (ret) {
+               printf("%s: Failed to get SW%u volt\n", __func__, sw + 1);
+               return ret;
+       }
+
+       debug("%s: SW%d step point swxvolt = %u\n", __func__, sw + 1, swxvolt);
+       spb = swx_set_point_base[sw];
+       /* The base of SW volt is 625mV and increase by step 25mV */
+       sw_volt = 625 + (swxvolt - spb) * 25;
+
+       debug("%s: SW%u volt = %dmV\n", __func__, sw + 1, sw_volt);
+       return sw_volt;
+}
+
+int mc34vr500_set_sw_volt(uint8_t sw, int sw_volt)
+{
+       struct pmic *p;
+       u32 swxvolt;
+       uint8_t spb;
+       int ret;
+
+       debug("%s: Set SW%u volt to %dmV\n", __func__, sw + 1, sw_volt);
+       /* The least SW volt is 625mV, and only 4 SW outputs */
+       if (sw > SW4 || sw_volt < 625)
+               return -EINVAL;
+
+       p = pmic_get("MC34VR500");
+       if (!p) {
+               printf("%s: Did NOT find PMIC MC34VR500\n", __func__);
+               return -ENODEV;
+       }
+
+       ret = pmic_probe(p);
+       if (ret)
+               return ret;
+
+       spb = swx_set_point_base[sw];
+       /* The base of SW volt is 625mV and increase by step 25mV */
+       swxvolt = (sw_volt - 625) / 25 + spb;
+       debug("%s: SW%d step point swxvolt = %u\n", __func__, sw + 1, swxvolt);
+       if (swxvolt > 63)
+               return -EINVAL;
+
+       ret = pmic_reg_write(p, swxvolt_addr[sw], swxvolt);
+       if (ret)
+               return ret;
+
+       return 0;
+}
index df4985ace74561f9d8c194277fa83f535f01efb3..b0b143a591901fab91d74ded5dd1347c963d0888 100644 (file)
@@ -162,5 +162,14 @@ enum {
 #define APS_PFM                0xc
 #define PWM_PFM                0xd
 
+enum swx {
+       SW1 = 0,
+       SW2,
+       SW3,
+       SW4,
+};
+
+int mc34vr500_get_sw_volt(uint8_t sw);
+int mc34vr500_set_sw_volt(uint8_t sw, int sw_volt);
 int power_mc34vr500_init(unsigned char bus);
 #endif /* __MC34VR500_PMIC_H_ */