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