1
2
3
4
5
6
7
8#include <common.h>
9#include <lcd.h>
10#include <asm/gpio.h>
11#include <asm/arch/pinmux.h>
12#include <asm/arch/power.h>
13#include <asm/arch/mipi_dsim.h>
14#include <power/pmic.h>
15#include <power/max77686_pmic.h>
16#include <power/battery.h>
17#include <power/max77693_pmic.h>
18#include <power/max77693_muic.h>
19#include <power/max77693_fg.h>
20#include <libtizen.h>
21#include <errno.h>
22#include <usb.h>
23#include <usb/dwc2_udc.h>
24#include <usb_mass_storage.h>
25
26static unsigned int board_rev = -1;
27
28static inline u32 get_model_rev(void);
29
30static void check_hw_revision(void)
31{
32 int modelrev = 0;
33 char str[12];
34 int i;
35
36
37
38
39
40
41
42 for (i = 0; i < 2; i++) {
43 int pin = i + EXYNOS4X12_GPIO_M10;
44
45 sprintf(str, "model_rev%d", i);
46 gpio_request(pin, str);
47 gpio_cfg_pin(pin, S5P_GPIO_INPUT);
48 }
49
50
51 for (i = 0; i < 4; i++) {
52 int pin = i + EXYNOS4X12_GPIO_M12;
53
54 sprintf(str, "hw_rev%d", i);
55 gpio_request(pin, str);
56 gpio_cfg_pin(pin, S5P_GPIO_INPUT);
57 gpio_set_pull(pin, S5P_GPIO_PULL_NONE);
58 }
59
60
61 for (i = 0; i < 2; i++)
62 modelrev |= (gpio_get_value(EXYNOS4X12_GPIO_M10 + i) << i);
63
64
65 board_rev = modelrev << 8;
66}
67
68u32 get_board_rev(void)
69{
70 return board_rev;
71}
72
73static inline u32 get_model_rev(void)
74{
75 return (board_rev >> 8) & 0xff;
76}
77
78static void board_external_gpio_init(void)
79{
80
81
82
83
84
85
86 gpio_set_pull(EXYNOS4X12_GPIO_X02, S5P_GPIO_PULL_NONE);
87 gpio_set_pull(EXYNOS4X12_GPIO_X04, S5P_GPIO_PULL_NONE);
88 gpio_set_pull(EXYNOS4X12_GPIO_X07, S5P_GPIO_PULL_NONE);
89 gpio_set_pull(EXYNOS4X12_GPIO_X15, S5P_GPIO_PULL_NONE);
90 gpio_set_pull(EXYNOS4X12_GPIO_X20, S5P_GPIO_PULL_NONE);
91 gpio_set_pull(EXYNOS4X12_GPIO_X21, S5P_GPIO_PULL_NONE);
92 gpio_set_pull(EXYNOS4X12_GPIO_X23, S5P_GPIO_PULL_NONE);
93 gpio_set_pull(EXYNOS4X12_GPIO_X24, S5P_GPIO_PULL_NONE);
94 gpio_set_pull(EXYNOS4X12_GPIO_X27, S5P_GPIO_PULL_NONE);
95 gpio_set_pull(EXYNOS4X12_GPIO_X30, S5P_GPIO_PULL_NONE);
96 gpio_set_pull(EXYNOS4X12_GPIO_X35, S5P_GPIO_PULL_NONE);
97 gpio_set_pull(EXYNOS4X12_GPIO_X37, S5P_GPIO_PULL_NONE);
98}
99
100int exynos_early_init_f(void)
101{
102 board_external_gpio_init();
103
104 return 0;
105}
106
107int exynos_init(void)
108{
109 struct exynos4_power *pwr =
110 (struct exynos4_power *)samsung_get_base_power();
111
112 check_hw_revision();
113 printf("HW Revision:\t0x%04x\n", board_rev);
114
115
116
117
118
119
120
121
122 writel(0, &pwr->inform4);
123 writel(0, &pwr->inform5);
124
125 return 0;
126}
127
128int exynos_power_init(void)
129{
130#ifndef CONFIG_DM_I2C
131 int chrg;
132 struct power_battery *pb;
133 struct pmic *p_chrg, *p_muic, *p_fg, *p_bat;
134
135 pmic_init_max77693(I2C_10);
136 power_muic_init(I2C_10);
137 power_fg_init(I2C_9);
138 power_bat_init(0);
139
140 p_chrg = pmic_get("MAX77693_PMIC");
141 if (!p_chrg) {
142 puts("MAX77693_PMIC: Not found\n");
143 return -ENODEV;
144 }
145
146 p_muic = pmic_get("MAX77693_MUIC");
147 if (!p_muic) {
148 puts("MAX77693_MUIC: Not found\n");
149 return -ENODEV;
150 }
151
152 p_fg = pmic_get("MAX77693_FG");
153 if (!p_fg) {
154 puts("MAX17042_FG: Not found\n");
155 return -ENODEV;
156 }
157
158 if (p_chrg->chrg->chrg_bat_present(p_chrg) == 0)
159 puts("No battery detected\n");
160
161 p_bat = pmic_get("BAT_TRATS2");
162 if (!p_bat) {
163 puts("BAT_TRATS2: Not found\n");
164 return -ENODEV;
165 }
166
167 p_fg->parent = p_bat;
168 p_chrg->parent = p_bat;
169 p_muic->parent = p_bat;
170
171 p_bat->pbat->battery_init(p_bat, p_fg, p_chrg, p_muic);
172
173 pb = p_bat->pbat;
174 chrg = p_muic->chrg->chrg_type(p_muic);
175 debug("CHARGER TYPE: %d\n", chrg);
176
177 if (!p_chrg->chrg->chrg_bat_present(p_chrg)) {
178 puts("No battery detected\n");
179 return 0;
180 }
181
182 p_fg->fg->fg_battery_check(p_fg, p_bat);
183
184 if (pb->bat->state == CHARGE && chrg == CHARGER_USB)
185 puts("CHARGE Battery !\n");
186#endif
187 return 0;
188}
189
190#ifdef CONFIG_USB_GADGET
191static int s5pc210_phy_control(int on)
192{
193#ifndef CONFIG_DM_I2C
194 int ret = 0;
195 unsigned int val;
196 struct pmic *p, *p_pmic, *p_muic;
197
198 p_pmic = pmic_get("MAX77686_PMIC");
199 if (!p_pmic)
200 return -ENODEV;
201
202 if (pmic_probe(p_pmic))
203 return -1;
204
205 p_muic = pmic_get("MAX77693_MUIC");
206 if (!p_muic)
207 return -ENODEV;
208
209 if (pmic_probe(p_muic))
210 return -1;
211
212 if (on) {
213 ret = max77686_set_ldo_mode(p_pmic, 12, OPMODE_ON);
214 if (ret)
215 return -1;
216
217 p = pmic_get("MAX77693_PMIC");
218 if (!p)
219 return -ENODEV;
220
221 if (pmic_probe(p))
222 return -1;
223
224
225 ret = pmic_reg_read(p, MAX77693_SAFEOUT, &val);
226 if (ret)
227 return -1;
228
229 val |= MAX77693_ENSAFEOUT1;
230 ret = pmic_reg_write(p, MAX77693_SAFEOUT, val);
231 if (ret)
232 return -1;
233
234
235 ret = pmic_reg_write(p_muic, MAX77693_MUIC_CONTROL1,
236 MAX77693_MUIC_CTRL1_DN1DP2);
237
238 } else {
239 ret = max77686_set_ldo_mode(p_pmic, 12, OPMODE_LPM);
240 if (ret)
241 return -1;
242
243
244 ret = pmic_reg_write(p_muic, MAX77693_MUIC_CONTROL1,
245 MAX77693_MUIC_CTRL1_UT1UR2);
246 }
247
248 if (ret)
249 return -1;
250#endif
251 return 0;
252}
253
254struct dwc2_plat_otg_data s5pc210_otg_data = {
255 .phy_control = s5pc210_phy_control,
256 .regs_phy = EXYNOS4X12_USBPHY_BASE,
257 .regs_otg = EXYNOS4X12_USBOTG_BASE,
258 .usb_phy_ctrl = EXYNOS4X12_USBPHY_CONTROL,
259 .usb_flags = PHY0_SLEEP,
260};
261
262int board_usb_init(int index, enum usb_init_type init)
263{
264 debug("USB_udc_probe\n");
265 return dwc2_udc_probe(&s5pc210_otg_data);
266}
267
268int g_dnl_board_usb_cable_connected(void)
269{
270#ifndef CONFIG_DM_I2C
271 struct pmic *muic = pmic_get("MAX77693_MUIC");
272 if (!muic)
273 return 0;
274
275 return !!muic->chrg->chrg_type(muic);
276#else
277 return false;
278#endif
279}
280#endif
281
282
283
284
285
286#ifdef CONFIG_LCD
287int mipi_power(void)
288{
289#ifndef CONFIG_DM_I2C
290 struct pmic *p = pmic_get("MAX77686_PMIC");
291
292
293 max77686_set_ldo_mode(p, 8, OPMODE_ON);
294
295 max77686_set_ldo_mode(p, 10, OPMODE_ON);
296#endif
297
298 return 0;
299}
300
301void exynos_lcd_power_on(void)
302{
303#ifndef CONFIG_DM_I2C
304 struct pmic *p = pmic_get("MAX77686_PMIC");
305
306
307 gpio_request(EXYNOS4X12_GPIO_C01, "lcd_2v2_en");
308 gpio_set_pull(EXYNOS4X12_GPIO_C01, S5P_GPIO_PULL_UP);
309 gpio_direction_output(EXYNOS4X12_GPIO_C01, 1);
310
311
312 pmic_probe(p);
313 max77686_set_ldo_voltage(p, 25, 3100000);
314 max77686_set_ldo_mode(p, 25, OPMODE_LPM);
315#endif
316}
317
318void exynos_reset_lcd(void)
319{
320
321 gpio_request(EXYNOS4X12_GPIO_F21, "lcd_reset");
322 gpio_direction_output(EXYNOS4X12_GPIO_F21, 0);
323 udelay(10);
324 gpio_set_value(EXYNOS4X12_GPIO_F21, 1);
325}
326
327void exynos_lcd_misc_init(vidinfo_t *vid)
328{
329#ifdef CONFIG_TIZEN
330 get_tizen_logo_info(vid);
331#endif
332#ifdef CONFIG_S6E8AX0
333 s6e8ax0_init();
334#endif
335}
336#endif
337