1 /* 2 * Copyright 2014 Freescale Semiconductor, Inc. 3 * 4 * SPDX-License-Identifier: GPL-2.0+ 5 */ 6 7 #include <common.h> 8 #include <errno.h> 9 #include <power/pmic.h> 10 #include <power/pfuze100_pmic.h> 11 12 #ifndef CONFIG_DM_PMIC_PFUZE100 13 int pfuze_mode_init(struct pmic *p, u32 mode) 14 { 15 unsigned char offset, i, switch_num; 16 u32 id; 17 int ret; 18 19 pmic_reg_read(p, PFUZE100_DEVICEID, &id); 20 id = id & 0xf; 21 22 if (id == 0) { 23 switch_num = 6; 24 offset = PFUZE100_SW1CMODE; 25 } else if (id == 1) { 26 switch_num = 4; 27 offset = PFUZE100_SW2MODE; 28 } else { 29 printf("Not supported, id=%d\n", id); 30 return -EINVAL; 31 } 32 33 ret = pmic_reg_write(p, PFUZE100_SW1ABMODE, mode); 34 if (ret < 0) { 35 printf("Set SW1AB mode error!\n"); 36 return ret; 37 } 38 39 for (i = 0; i < switch_num - 1; i++) { 40 ret = pmic_reg_write(p, offset + i * SWITCH_SIZE, mode); 41 if (ret < 0) { 42 printf("Set switch 0x%x mode error!\n", 43 offset + i * SWITCH_SIZE); 44 return ret; 45 } 46 } 47 48 return ret; 49 } 50 51 struct pmic *pfuze_common_init(unsigned char i2cbus) 52 { 53 struct pmic *p; 54 int ret; 55 unsigned int reg; 56 57 ret = power_pfuze100_init(i2cbus); 58 if (ret) 59 return NULL; 60 61 p = pmic_get("PFUZE100"); 62 ret = pmic_probe(p); 63 if (ret) 64 return NULL; 65 66 pmic_reg_read(p, PFUZE100_DEVICEID, ®); 67 printf("PMIC: PFUZE100 ID=0x%02x\n", reg); 68 69 /* Set SW1AB stanby volage to 0.975V */ 70 pmic_reg_read(p, PFUZE100_SW1ABSTBY, ®); 71 reg &= ~SW1x_STBY_MASK; 72 reg |= SW1x_0_975V; 73 pmic_reg_write(p, PFUZE100_SW1ABSTBY, reg); 74 75 /* Set SW1AB/VDDARM step ramp up time from 16us to 4us/25mV */ 76 pmic_reg_read(p, PFUZE100_SW1ABCONF, ®); 77 reg &= ~SW1xCONF_DVSSPEED_MASK; 78 reg |= SW1xCONF_DVSSPEED_4US; 79 pmic_reg_write(p, PFUZE100_SW1ABCONF, reg); 80 81 /* Set SW1C standby voltage to 0.975V */ 82 pmic_reg_read(p, PFUZE100_SW1CSTBY, ®); 83 reg &= ~SW1x_STBY_MASK; 84 reg |= SW1x_0_975V; 85 pmic_reg_write(p, PFUZE100_SW1CSTBY, reg); 86 87 /* Set SW1C/VDDSOC step ramp up time from 16us to 4us/25mV */ 88 pmic_reg_read(p, PFUZE100_SW1CCONF, ®); 89 reg &= ~SW1xCONF_DVSSPEED_MASK; 90 reg |= SW1xCONF_DVSSPEED_4US; 91 pmic_reg_write(p, PFUZE100_SW1CCONF, reg); 92 93 return p; 94 } 95 #else 96 int pfuze_mode_init(struct udevice *dev, u32 mode) 97 { 98 unsigned char offset, i, switch_num; 99 u32 id; 100 int ret; 101 102 id = pmic_reg_read(dev, PFUZE100_DEVICEID); 103 id = id & 0xf; 104 105 if (id == 0) { 106 switch_num = 6; 107 offset = PFUZE100_SW1CMODE; 108 } else if (id == 1) { 109 switch_num = 4; 110 offset = PFUZE100_SW2MODE; 111 } else { 112 printf("Not supported, id=%d\n", id); 113 return -EINVAL; 114 } 115 116 ret = pmic_reg_write(dev, PFUZE100_SW1ABMODE, mode); 117 if (ret < 0) { 118 printf("Set SW1AB mode error!\n"); 119 return ret; 120 } 121 122 for (i = 0; i < switch_num - 1; i++) { 123 ret = pmic_reg_write(dev, offset + i * SWITCH_SIZE, mode); 124 if (ret < 0) { 125 printf("Set switch 0x%x mode error!\n", 126 offset + i * SWITCH_SIZE); 127 return ret; 128 } 129 } 130 131 return ret; 132 } 133 134 struct udevice *pfuze_common_init(void) 135 { 136 struct udevice *dev; 137 int ret; 138 unsigned int reg, dev_id, rev_id; 139 140 ret = pmic_get("pfuze100", &dev); 141 if (ret == -ENODEV) 142 return NULL; 143 144 dev_id = pmic_reg_read(dev, PFUZE100_DEVICEID); 145 rev_id = pmic_reg_read(dev, PFUZE100_REVID); 146 printf("PMIC: PFUZE100! DEV_ID=0x%x REV_ID=0x%x\n", dev_id, rev_id); 147 148 /* Set SW1AB stanby volage to 0.975V */ 149 reg = pmic_reg_read(dev, PFUZE100_SW1ABSTBY); 150 reg &= ~SW1x_STBY_MASK; 151 reg |= SW1x_0_975V; 152 pmic_reg_write(dev, PFUZE100_SW1ABSTBY, reg); 153 154 /* Set SW1AB/VDDARM step ramp up time from 16us to 4us/25mV */ 155 reg = pmic_reg_read(dev, PFUZE100_SW1ABCONF); 156 reg &= ~SW1xCONF_DVSSPEED_MASK; 157 reg |= SW1xCONF_DVSSPEED_4US; 158 pmic_reg_write(dev, PFUZE100_SW1ABCONF, reg); 159 160 /* Set SW1C standby voltage to 0.975V */ 161 reg = pmic_reg_read(dev, PFUZE100_SW1CSTBY); 162 reg &= ~SW1x_STBY_MASK; 163 reg |= SW1x_0_975V; 164 pmic_reg_write(dev, PFUZE100_SW1CSTBY, reg); 165 166 /* Set SW1C/VDDSOC step ramp up time from 16us to 4us/25mV */ 167 reg = pmic_reg_read(dev, PFUZE100_SW1CCONF); 168 reg &= ~SW1xCONF_DVSSPEED_MASK; 169 reg |= SW1xCONF_DVSSPEED_4US; 170 pmic_reg_write(dev, PFUZE100_SW1CCONF, reg); 171 172 return dev; 173 } 174 #endif 175