Commit 56b3054ae1f1bd4778d78054e5068ffdf143bec9

Authored by fang hui
Committed by Ye Li
1 parent acdc5c297a

MA-10052 [iot] Extensions of AXP152 to support stream812

Necessary extensions of axp152 to support stream812.

merge patches from Martin Pietryka <martin.pietryka@streamunlimited.com>

Change-Id: I7708db4e59d6403a3576f17a221b448866f469a0
Signed-off-by: fang hui <hui.fang@nxp.com>
(cherry picked from commit 6f51148d75869415bb4e9920572e8fffb1eb0099)

Showing 2 changed files with 191 additions and 3 deletions Side-by-side Diff

drivers/power/axp152.c
... ... @@ -6,9 +6,27 @@
6 6 */
7 7 #include <common.h>
8 8 #include <command.h>
9   -#include <asm/arch/pmic_bus.h>
  9 +#include <i2c.h>
10 10 #include <axp_pmic.h>
  11 +#include <errno.h>
11 12  
  13 +#define AXP152_I2C_ADDR 0x32
  14 +
  15 +static int pmic_bus_init(void)
  16 +{
  17 + return 0;
  18 +}
  19 +
  20 +static int pmic_bus_read(u8 reg, u8 *data)
  21 +{
  22 + return i2c_read(AXP152_I2C_ADDR, reg, 1, data, 1);
  23 +}
  24 +
  25 +static int pmic_bus_write(u8 reg, u8 data)
  26 +{
  27 + return i2c_write(AXP152_I2C_ADDR, reg, 1, &data, 1);
  28 +}
  29 +
12 30 static u8 axp152_mvolt_to_target(int mvolt, int min, int max, int div)
13 31 {
14 32 if (mvolt < min)
... ... @@ -19,6 +37,14 @@
19 37 return (mvolt - min) / div;
20 38 }
21 39  
  40 +int axp_set_dcdc1(enum axp152_dcdc1_voltages volt)
  41 +{
  42 + if (volt < AXP152_DCDC1_1V7 || volt > AXP152_DCDC1_3V5)
  43 + return -EINVAL;
  44 +
  45 + return pmic_bus_write(AXP152_DCDC1_VOLTAGE, volt);
  46 +}
  47 +
22 48 int axp_set_dcdc2(unsigned int mvolt)
23 49 {
24 50 int rc;
25 51  
26 52  
27 53  
28 54  
... ... @@ -54,17 +80,79 @@
54 80 return pmic_bus_write(AXP152_DCDC4_VOLTAGE, target);
55 81 }
56 82  
57   -int axp_set_aldo2(unsigned int mvolt)
  83 +int axp_set_ldo0(enum axp152_ldo0_volts volt, enum axp152_ldo0_curr_limit curr_limit)
58 84 {
  85 + u8 target = curr_limit | (volt << 4) | (1 << 7);
  86 +
  87 + return pmic_bus_write(AXP152_LDO0_VOLTAGE, target);
  88 +}
  89 +
  90 +int axp_disable_ldo0(void)
  91 +{
  92 + int ret;
  93 + u8 target;
  94 +
  95 + ret = pmic_bus_read(AXP152_LDO0_VOLTAGE, &target);
  96 + if (ret)
  97 + return ret;
  98 +
  99 + target &= ~(1 << 7);
  100 +
  101 + return pmic_bus_write(AXP152_LDO0_VOLTAGE, target);
  102 +}
  103 +
  104 +int axp_set_ldo1(unsigned int mvolt)
  105 +{
59 106 u8 target = axp152_mvolt_to_target(mvolt, 700, 3500, 100);
60 107  
  108 + return pmic_bus_write(AXP152_LDO1_VOLTAGE, target);
  109 +}
  110 +
  111 +
  112 +int axp_set_ldo2(unsigned int mvolt)
  113 +{
  114 + u8 target = axp152_mvolt_to_target(mvolt, 700, 3500, 100);
  115 +
61 116 return pmic_bus_write(AXP152_LDO2_VOLTAGE, target);
62 117 }
63 118  
  119 +int axp_set_aldo1(enum axp152_aldo_voltages volt)
  120 +{
  121 + u8 val;
  122 + int ret;
  123 +
  124 + ret = pmic_bus_read(AXP152_ALDO1_ALDO2_VOLTAGE, &val);
  125 + if (ret)
  126 + return ret;
  127 +
  128 + val |= (volt << 4);
  129 + return pmic_bus_write(AXP152_ALDO1_ALDO2_VOLTAGE, val);
  130 +}
  131 +
  132 +int axp_set_aldo2(enum axp152_aldo_voltages volt)
  133 +{
  134 + u8 val;
  135 + int ret;
  136 +
  137 + ret = pmic_bus_read(AXP152_ALDO1_ALDO2_VOLTAGE, &val);
  138 + if (ret)
  139 + return ret;
  140 +
  141 + val |= volt;
  142 + return pmic_bus_write(AXP152_ALDO1_ALDO2_VOLTAGE, val);
  143 +}
  144 +
  145 +int axp_set_power_output(int val)
  146 +{
  147 + return pmic_bus_write(AXP152_POWER_CONTROL, val);
  148 +}
  149 +
64 150 int axp_init(void)
65 151 {
66 152 u8 ver;
67 153 int rc;
  154 + int ret;
  155 + u8 reg;
68 156  
69 157 rc = pmic_bus_init();
70 158 if (rc)
... ... @@ -77,7 +165,24 @@
77 165 if (ver != 0x05)
78 166 return -EINVAL;
79 167  
80   - return 0;
  168 + /* Set the power off sequence to `reverse of power on sequence` */
  169 + ret = pmic_bus_read(AXP152_SHUTDOWN, &reg);
  170 + if (ret)
  171 + return ret;
  172 + reg |= AXP152_POWEROFF_SEQ;
  173 + ret = pmic_bus_write(AXP152_SHUTDOWN, reg);
  174 + if (ret)
  175 + return ret;
  176 +
  177 +
  178 + /* Enable the power recovery */
  179 + ret = pmic_bus_read(AXP152_POWER_RECOVERY, &reg);
  180 + if (ret)
  181 + return ret;
  182 + reg |= AXP152_POWER_RECOVERY_EN;
  183 + ret = pmic_bus_write(AXP152_POWER_RECOVERY, reg);
  184 + return ret;
  185 +
81 186 }
82 187  
83 188 int do_poweroff(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
... ... @@ -6,14 +6,84 @@
6 6  
7 7 enum axp152_reg {
8 8 AXP152_CHIP_VERSION = 0x3,
  9 + AXP152_POWER_CONTROL = 0x12,
  10 + AXP152_LDO0_VOLTAGE = 0x15,
9 11 AXP152_DCDC2_VOLTAGE = 0x23,
  12 + AXP152_DCDC1_VOLTAGE = 0x26,
10 13 AXP152_DCDC3_VOLTAGE = 0x27,
11 14 AXP152_DCDC4_VOLTAGE = 0x2B,
  15 + AXP152_LDO1_VOLTAGE = 0x29,
12 16 AXP152_LDO2_VOLTAGE = 0x2A,
  17 + AXP152_ALDO1_ALDO2_VOLTAGE = 0x28,
  18 + AXP152_POWER_RECOVERY = 0x31,
13 19 AXP152_SHUTDOWN = 0x32,
  20 + AXP152_GPIO0 = 0x90,
14 21 };
15 22  
  23 +enum axp152_ldo0_volts {
  24 + AXP152_LDO0_5V = 0,
  25 + AXP152_LDO0_3V3 = 1,
  26 + AXP152_LDO0_2V8 = 2,
  27 + AXP152_LDO0_2V5 = 3,
  28 +};
  29 +
  30 +enum axp152_ldo0_curr_limit {
  31 + AXP152_LDO0_CURR_NOLMIT = 0,
  32 + AXP152_LDO0_CURR_1500MA = 1,
  33 + AXP152_LDO0_CURR_900MA = 2,
  34 + AXP152_LDO0_CURR_500MA = 3,
  35 +};
  36 +
  37 +enum axp152_dcdc1_voltages {
  38 + AXP152_DCDC1_1V7 = 0,
  39 + AXP152_DCDC1_1V8 = 1,
  40 + AXP152_DCDC1_1V9 = 2,
  41 + AXP152_DCDC1_2V0 = 3,
  42 + AXP152_DCDC1_2V1 = 4,
  43 + AXP152_DCDC1_2V4 = 5,
  44 + AXP152_DCDC1_2V5 = 6,
  45 + AXP152_DCDC1_2V6 = 7,
  46 + AXP152_DCDC1_2V7 = 8,
  47 + AXP152_DCDC1_2V8 = 9,
  48 + AXP152_DCDC1_3V0 = 10,
  49 + AXP152_DCDC1_3V1 = 11,
  50 + AXP152_DCDC1_3V2 = 12,
  51 + AXP152_DCDC1_3V3 = 13,
  52 + AXP152_DCDC1_3V4 = 14,
  53 + AXP152_DCDC1_3V5 = 15,
  54 +};
  55 +
  56 +enum axp152_aldo_voltages {
  57 + AXP152_ALDO_1V2 = 0,
  58 + AXP152_ALDO_1V3 = 1,
  59 + AXP152_ALDO_1V4 = 2,
  60 + AXP152_ALDO_1V5 = 3,
  61 + AXP152_ALDO_1V6 = 4,
  62 + AXP152_ALDO_1V7 = 5,
  63 + AXP152_ALDO_1V8 = 6,
  64 + AXP152_ALDO_1V9 = 7,
  65 + AXP152_ALDO_2V0 = 8,
  66 + AXP152_ALDO_2V5 = 9,
  67 + AXP152_ALDO_2V7 = 10,
  68 + AXP152_ALDO_2V8 = 11,
  69 + AXP152_ALDO_3V0 = 12,
  70 + AXP152_ALDO_3V1 = 13,
  71 + AXP152_ALDO_3V2 = 14,
  72 + AXP152_ALDO_3V3 = 15,
  73 +};
  74 +
  75 +#define AXP152_POWEROUT_DC_DC1 BIT(7)
  76 +#define AXP152_POWEROUT_DC_DC2 BIT(6)
  77 +#define AXP152_POWEROUT_DC_DC3 BIT(5)
  78 +#define AXP152_POWEROUT_DC_DC4 BIT(4)
  79 +#define AXP152_POWEROUT_ALDO1 BIT(3)
  80 +#define AXP152_POWEROUT_ALDO2 BIT(2)
  81 +#define AXP152_POWEROUT_DLDO1 BIT(1)
  82 +#define AXP152_POWEROUT_DLDO2 BIT(0)
  83 +
16 84 #define AXP152_POWEROFF (1 << 7)
  85 +#define AXP152_POWEROFF_SEQ (1 << 2)
  86 +#define AXP152_POWER_RECOVERY_EN (1 << 3)
17 87  
18 88 /* For axp_gpio.c */
19 89 #define AXP_GPIO0_CTRL 0x90
... ... @@ -25,4 +95,17 @@
25 95 #define AXP_GPIO_CTRL_INPUT 0x02 /* Input */
26 96 #define AXP_GPIO_STATE 0x97
27 97 #define AXP_GPIO_STATE_OFFSET 0
  98 +
  99 +int axp_set_dcdc1(enum axp152_dcdc1_voltages volt);
  100 +int axp_set_dcdc2(unsigned int mvolt);
  101 +int axp_set_dcdc3(unsigned int mvolt);
  102 +int axp_set_dcdc4(unsigned int mvolt);
  103 +int axp_set_ldo0(enum axp152_ldo0_volts volt, enum axp152_ldo0_curr_limit curr_limit);
  104 +int axp_disable_ldo0(void);
  105 +int axp_set_ldo1(unsigned int mvolt);
  106 +int axp_set_ldo2(unsigned int mvolt);
  107 +int axp_set_aldo1(enum axp152_aldo_voltages volt);
  108 +int axp_set_aldo2(enum axp152_aldo_voltages volt);
  109 +int axp_set_power_output(int val);
  110 +int axp_init(void);