Ye.Li | 5051ff5 | 2014-11-06 16:28:59 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Freescale Semiconductor, Inc. |
| 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Peng Fan | 7428f55 | 2015-01-27 10:14:03 +0800 | [diff] [blame] | 8 | #include <errno.h> |
Ye.Li | 5051ff5 | 2014-11-06 16:28:59 +0800 | [diff] [blame] | 9 | #include <power/pmic.h> |
| 10 | #include <power/pfuze100_pmic.h> |
| 11 | |
Peng Fan | 125914d | 2015-08-07 16:43:46 +0800 | [diff] [blame] | 12 | #ifndef CONFIG_DM_PMIC_PFUZE100 |
Peng Fan | 7428f55 | 2015-01-27 10:14:03 +0800 | [diff] [blame] | 13 | int pfuze_mode_init(struct pmic *p, u32 mode) |
| 14 | { |
| 15 | unsigned char offset, i, switch_num; |
Ye.Li | 7ea191a | 2016-01-04 15:26:30 +0800 | [diff] [blame] | 16 | u32 id; |
| 17 | int ret; |
Peng Fan | 7428f55 | 2015-01-27 10:14:03 +0800 | [diff] [blame] | 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 | |
Ye.Li | 5051ff5 | 2014-11-06 16:28:59 +0800 | [diff] [blame] | 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 */ |
Peng Fan | 3fd10f3 | 2015-05-18 13:37:26 +0800 | [diff] [blame] | 76 | pmic_reg_read(p, PFUZE100_SW1ABCONF, ®); |
Ye.Li | 5051ff5 | 2014-11-06 16:28:59 +0800 | [diff] [blame] | 77 | reg &= ~SW1xCONF_DVSSPEED_MASK; |
| 78 | reg |= SW1xCONF_DVSSPEED_4US; |
Peng Fan | 3fd10f3 | 2015-05-18 13:37:26 +0800 | [diff] [blame] | 79 | pmic_reg_write(p, PFUZE100_SW1ABCONF, reg); |
Ye.Li | 5051ff5 | 2014-11-06 16:28:59 +0800 | [diff] [blame] | 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 | } |
Peng Fan | f8e450a | 2018-01-02 09:32:06 +0800 | [diff] [blame] | 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 | } |
Peng Fan | 125914d | 2015-08-07 16:43:46 +0800 | [diff] [blame] | 174 | #endif |