1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2016 Freescale Semiconductor, Inc.
4 * Hou Zhiqiang <Zhiqiang.Hou@freescale.com>
10 #include <power/pmic.h>
11 #include <power/mc34vr500_pmic.h>
13 static uint8_t swxvolt_addr[4] = { MC34VR500_SW1VOLT,
18 static uint8_t swx_set_point_base[4] = { 13, 9, 9, 9 };
20 int mc34vr500_get_sw_volt(uint8_t sw)
28 debug("%s: Get SW%u volt from swxvolt_addr = 0x%x\n",
29 __func__, sw + 1, swxvolt_addr[sw]);
31 printf("%s: Unsupported SW(sw%d)\n", __func__, sw + 1);
35 p = pmic_get("MC34VR500");
37 printf("%s: Did NOT find PMIC MC34VR500\n", __func__);
45 ret = pmic_reg_read(p, swxvolt_addr[sw], &swxvolt);
47 printf("%s: Failed to get SW%u volt\n", __func__, sw + 1);
51 debug("%s: SW%d step point swxvolt = %u\n", __func__, sw + 1, swxvolt);
52 spb = swx_set_point_base[sw];
53 /* The base of SW volt is 625mV and increase by step 25mV */
54 sw_volt = 625 + (swxvolt - spb) * 25;
56 debug("%s: SW%u volt = %dmV\n", __func__, sw + 1, sw_volt);
60 int mc34vr500_set_sw_volt(uint8_t sw, int sw_volt)
67 debug("%s: Set SW%u volt to %dmV\n", __func__, sw + 1, sw_volt);
68 /* The least SW volt is 625mV, and only 4 SW outputs */
69 if (sw > SW4 || sw_volt < 625)
72 p = pmic_get("MC34VR500");
74 printf("%s: Did NOT find PMIC MC34VR500\n", __func__);
82 spb = swx_set_point_base[sw];
83 /* The base of SW volt is 625mV and increase by step 25mV */
84 swxvolt = (sw_volt - 625) / 25 + spb;
85 debug("%s: SW%d step point swxvolt = %u\n", __func__, sw + 1, swxvolt);
89 ret = pmic_reg_write(p, swxvolt_addr[sw], swxvolt);