blob: 0d7a94fd232f81ac595bd464096971d716b7b8b6 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Ye.Lia9454db2014-11-06 16:28:59 +08002/*
3 * Copyright 2014 Freescale Semiconductor, Inc.
Ye.Lia9454db2014-11-06 16:28:59 +08004 */
5
Peng Fan962a4172015-01-27 10:14:03 +08006#include <errno.h>
Ye.Lia9454db2014-11-06 16:28:59 +08007#include <power/pmic.h>
8#include <power/pfuze100_pmic.h>
9
Peng Fan6b919082015-08-07 16:43:46 +080010#ifndef CONFIG_DM_PMIC_PFUZE100
Peng Fan962a4172015-01-27 10:14:03 +080011int pfuze_mode_init(struct pmic *p, u32 mode)
12{
13 unsigned char offset, i, switch_num;
Ye.Licd4b9602016-01-04 15:26:30 +080014 u32 id;
15 int ret;
Peng Fan962a4172015-01-27 10:14:03 +080016
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.Lia9454db2014-11-06 16:28:59 +080049struct 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, &reg);
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, &reg);
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 Fan5f234e72015-05-18 13:37:26 +080074 pmic_reg_read(p, PFUZE100_SW1ABCONF, &reg);
Ye.Lia9454db2014-11-06 16:28:59 +080075 reg &= ~SW1xCONF_DVSSPEED_MASK;
76 reg |= SW1xCONF_DVSSPEED_4US;
Peng Fan5f234e72015-05-18 13:37:26 +080077 pmic_reg_write(p, PFUZE100_SW1ABCONF, reg);
Ye.Lia9454db2014-11-06 16:28:59 +080078
79 /* Set SW1C standby voltage to 0.975V */
80 pmic_reg_read(p, PFUZE100_SW1CSTBY, &reg);
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, &reg);
87 reg &= ~SW1xCONF_DVSSPEED_MASK;
88 reg |= SW1xCONF_DVSSPEED_4US;
89 pmic_reg_write(p, PFUZE100_SW1CCONF, reg);
90
91 return p;
92}
Troy Kisky87031cb2023-03-13 14:31:38 -070093#elif defined(CONFIG_DM_PMIC)
Peng Fana7e8fcb2018-01-02 09:32:06 +080094int 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
132struct udevice *pfuze_common_init(void)
133{
134 struct udevice *dev;
135 int ret;
136 unsigned int reg, dev_id, rev_id;
137
Fabio Estevam94cd6902019-12-19 14:59:41 -0300138 ret = pmic_get("pfuze100@8", &dev);
Peng Fana7e8fcb2018-01-02 09:32:06 +0800139 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 Fan6b919082015-08-07 16:43:46 +0800172#endif