2 * Copyright 2016 Freescale Semiconductor, Inc.
3 * Hou Zhiqiang <Zhiqiang.Hou@freescale.com>
5 * SPDX-License-Identifier: GPL-2.0+
11 #include <power/pmic.h>
12 #include <power/mc34vr500_pmic.h>
14 static uint8_t swxvolt_addr[4] = { MC34VR500_SW1VOLT,
19 static uint8_t swx_set_point_base[4] = { 13, 9, 9, 9 };
21 int mc34vr500_get_sw_volt(uint8_t sw)
29 debug("%s: Get SW%u volt from swxvolt_addr = 0x%x\n",
30 __func__, sw + 1, swxvolt_addr[sw]);
32 printf("%s: Unsupported SW(sw%d)\n", __func__, sw + 1);
36 p = pmic_get("MC34VR500");
38 printf("%s: Did NOT find PMIC MC34VR500\n", __func__);
46 ret = pmic_reg_read(p, swxvolt_addr[sw], &swxvolt);
48 printf("%s: Failed to get SW%u volt\n", __func__, sw + 1);
52 debug("%s: SW%d step point swxvolt = %u\n", __func__, sw + 1, swxvolt);
53 spb = swx_set_point_base[sw];
54 /* The base of SW volt is 625mV and increase by step 25mV */
55 sw_volt = 625 + (swxvolt - spb) * 25;
57 debug("%s: SW%u volt = %dmV\n", __func__, sw + 1, sw_volt);
61 int mc34vr500_set_sw_volt(uint8_t sw, int sw_volt)
68 debug("%s: Set SW%u volt to %dmV\n", __func__, sw + 1, sw_volt);
69 /* The least SW volt is 625mV, and only 4 SW outputs */
70 if (sw > SW4 || sw_volt < 625)
73 p = pmic_get("MC34VR500");
75 printf("%s: Did NOT find PMIC MC34VR500\n", __func__);
83 spb = swx_set_point_base[sw];
84 /* The base of SW volt is 625mV and increase by step 25mV */
85 swxvolt = (sw_volt - 625) / 25 + spb;
86 debug("%s: SW%d step point swxvolt = %u\n", __func__, sw + 1, swxvolt);
90 ret = pmic_reg_write(p, swxvolt_addr[sw], swxvolt);