blob: 59e6fbf4b002e9af9535405c491124cdb7a216c3 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Piotr Wilczek4d6c9672013-09-20 15:01:27 +02002/*
3 * Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved.
4 * Sanghee Kim <sh0130.kim@samsung.com>
5 * Piotr Wilczek <p.wilczek@samsung.com>
Piotr Wilczek4d6c9672013-09-20 15:01:27 +02006 */
7
8#include <common.h>
9#include <lcd.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060010#include <log.h>
Simon Glass903fd792014-10-20 19:48:37 -060011#include <asm/gpio.h>
Piotr Wilczek4d6c9672013-09-20 15:01:27 +020012#include <asm/arch/pinmux.h>
13#include <asm/arch/power.h>
Piotr Wilczek1ecab0f2014-03-07 14:59:49 +010014#include <asm/arch/mipi_dsim.h>
Simon Glassc05ed002020-05-10 11:40:11 -060015#include <linux/delay.h>
Piotr Wilczek4d6c9672013-09-20 15:01:27 +020016#include <power/pmic.h>
17#include <power/max77686_pmic.h>
18#include <power/battery.h>
19#include <power/max77693_pmic.h>
20#include <power/max77693_muic.h>
21#include <power/max77693_fg.h>
22#include <libtizen.h>
23#include <errno.h>
Piotr Wilczekab8efbb2013-11-21 15:46:45 +010024#include <usb.h>
Marek Vasut5d5716e2015-12-04 02:51:20 +010025#include <usb/dwc2_udc.h>
Piotr Wilczekab8efbb2013-11-21 15:46:45 +010026#include <usb_mass_storage.h>
Piotr Wilczek4d6c9672013-09-20 15:01:27 +020027
Piotr Wilczek4d6c9672013-09-20 15:01:27 +020028static unsigned int board_rev = -1;
29
30static inline u32 get_model_rev(void);
31
32static void check_hw_revision(void)
33{
34 int modelrev = 0;
Simon Glass7f196102014-10-20 19:48:39 -060035 char str[12];
Piotr Wilczek4d6c9672013-09-20 15:01:27 +020036 int i;
37
Piotr Wilczek4d6c9672013-09-20 15:01:27 +020038 /*
39 * GPM1[1:0]: MODEL_REV[1:0]
40 * Don't set as pull-none for these N/C pin.
41 * TRM say that it may cause unexcepted state and leakage current.
42 * and pull-none is only for output function.
43 */
Simon Glass7f196102014-10-20 19:48:39 -060044 for (i = 0; i < 2; i++) {
45 int pin = i + EXYNOS4X12_GPIO_M10;
46
47 sprintf(str, "model_rev%d", i);
48 gpio_request(pin, str);
49 gpio_cfg_pin(pin, S5P_GPIO_INPUT);
50 }
Piotr Wilczek4d6c9672013-09-20 15:01:27 +020051
52 /* GPM1[5:2]: HW_REV[3:0] */
Simon Glass7f196102014-10-20 19:48:39 -060053 for (i = 0; i < 4; i++) {
54 int pin = i + EXYNOS4X12_GPIO_M12;
55
56 sprintf(str, "hw_rev%d", i);
57 gpio_request(pin, str);
58 gpio_cfg_pin(pin, S5P_GPIO_INPUT);
59 gpio_set_pull(pin, S5P_GPIO_PULL_NONE);
Piotr Wilczek4d6c9672013-09-20 15:01:27 +020060 }
61
62 /* GPM1[1:0]: MODEL_REV[1:0] */
63 for (i = 0; i < 2; i++)
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +053064 modelrev |= (gpio_get_value(EXYNOS4X12_GPIO_M10 + i) << i);
Piotr Wilczek4d6c9672013-09-20 15:01:27 +020065
66 /* board_rev[15:8] = model */
67 board_rev = modelrev << 8;
68}
69
Piotr Wilczek4d6c9672013-09-20 15:01:27 +020070u32 get_board_rev(void)
71{
72 return board_rev;
73}
74
75static inline u32 get_model_rev(void)
76{
77 return (board_rev >> 8) & 0xff;
78}
79
80static void board_external_gpio_init(void)
81{
Piotr Wilczek4d6c9672013-09-20 15:01:27 +020082 /*
83 * some pins which in alive block are connected with external pull-up
84 * but it's default setting is pull-down.
85 * if that pin set as input then that floated
86 */
87
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +053088 gpio_set_pull(EXYNOS4X12_GPIO_X02, S5P_GPIO_PULL_NONE); /* PS_ALS_INT */
89 gpio_set_pull(EXYNOS4X12_GPIO_X04, S5P_GPIO_PULL_NONE); /* TSP_nINT */
90 gpio_set_pull(EXYNOS4X12_GPIO_X07, S5P_GPIO_PULL_NONE); /* AP_PMIC_IRQ*/
91 gpio_set_pull(EXYNOS4X12_GPIO_X15, S5P_GPIO_PULL_NONE); /* IF_PMIC_IRQ*/
92 gpio_set_pull(EXYNOS4X12_GPIO_X20, S5P_GPIO_PULL_NONE); /* VOL_UP */
93 gpio_set_pull(EXYNOS4X12_GPIO_X21, S5P_GPIO_PULL_NONE); /* VOL_DOWN */
94 gpio_set_pull(EXYNOS4X12_GPIO_X23, S5P_GPIO_PULL_NONE); /* FUEL_ALERT */
95 gpio_set_pull(EXYNOS4X12_GPIO_X24, S5P_GPIO_PULL_NONE); /* ADC_INT */
96 gpio_set_pull(EXYNOS4X12_GPIO_X27, S5P_GPIO_PULL_NONE); /* nPOWER */
97 gpio_set_pull(EXYNOS4X12_GPIO_X30, S5P_GPIO_PULL_NONE); /* WPC_INT */
98 gpio_set_pull(EXYNOS4X12_GPIO_X35, S5P_GPIO_PULL_NONE); /* OK_KEY */
99 gpio_set_pull(EXYNOS4X12_GPIO_X37, S5P_GPIO_PULL_NONE); /* HDMI_HPD */
Piotr Wilczek4d6c9672013-09-20 15:01:27 +0200100}
101
Piotr Wilczek1ecab0f2014-03-07 14:59:49 +0100102int exynos_early_init_f(void)
Piotr Wilczek4d6c9672013-09-20 15:01:27 +0200103{
Piotr Wilczek4d6c9672013-09-20 15:01:27 +0200104 board_external_gpio_init();
105
Piotr Wilczek4d6c9672013-09-20 15:01:27 +0200106 return 0;
107}
108
Piotr Wilczek1ecab0f2014-03-07 14:59:49 +0100109int exynos_init(void)
Piotr Wilczek4d6c9672013-09-20 15:01:27 +0200110{
Łukasz Majewski24542522014-04-09 15:09:44 +0200111 struct exynos4_power *pwr =
112 (struct exynos4_power *)samsung_get_base_power();
113
Piotr Wilczek1ecab0f2014-03-07 14:59:49 +0100114 check_hw_revision();
115 printf("HW Revision:\t0x%04x\n", board_rev);
Piotr Wilczek4d6c9672013-09-20 15:01:27 +0200116
Łukasz Majewski24542522014-04-09 15:09:44 +0200117 /*
118 * First bootloader on the TRATS2 platform uses
119 * INFORM4 and INFORM5 registers for recovery
120 *
121 * To indicate correct boot chain - those two
122 * registers must be cleared out
123 */
124 writel(0, &pwr->inform4);
125 writel(0, &pwr->inform5);
126
Piotr Wilczek4d6c9672013-09-20 15:01:27 +0200127 return 0;
128}
129
Piotr Wilczek1ecab0f2014-03-07 14:59:49 +0100130int exynos_power_init(void)
Piotr Wilczek4d6c9672013-09-20 15:01:27 +0200131{
Igor Opaniuk2147a162021-02-09 13:52:45 +0200132#if !CONFIG_IS_ENABLED(DM_I2C) /* TODO(maintainer): Convert to driver model */
Piotr Wilczek4d6c9672013-09-20 15:01:27 +0200133 int chrg;
134 struct power_battery *pb;
135 struct pmic *p_chrg, *p_muic, *p_fg, *p_bat;
136
Piotr Wilczekef23b992013-12-18 15:43:37 +0100137 pmic_init_max77693(I2C_10); /* I2C adapter 10 - bus name soft1 */
138 power_muic_init(I2C_10); /* I2C adapter 10 - bus name soft1 */
139 power_fg_init(I2C_9); /* I2C adapter 9 - bus name soft0 */
Piotr Wilczek4d6c9672013-09-20 15:01:27 +0200140 power_bat_init(0);
141
142 p_chrg = pmic_get("MAX77693_PMIC");
143 if (!p_chrg) {
144 puts("MAX77693_PMIC: Not found\n");
145 return -ENODEV;
146 }
147
148 p_muic = pmic_get("MAX77693_MUIC");
149 if (!p_muic) {
150 puts("MAX77693_MUIC: Not found\n");
151 return -ENODEV;
152 }
153
154 p_fg = pmic_get("MAX77693_FG");
155 if (!p_fg) {
156 puts("MAX17042_FG: Not found\n");
157 return -ENODEV;
158 }
159
160 if (p_chrg->chrg->chrg_bat_present(p_chrg) == 0)
161 puts("No battery detected\n");
162
163 p_bat = pmic_get("BAT_TRATS2");
164 if (!p_bat) {
165 puts("BAT_TRATS2: Not found\n");
166 return -ENODEV;
167 }
168
169 p_fg->parent = p_bat;
170 p_chrg->parent = p_bat;
171 p_muic->parent = p_bat;
172
173 p_bat->pbat->battery_init(p_bat, p_fg, p_chrg, p_muic);
174
175 pb = p_bat->pbat;
176 chrg = p_muic->chrg->chrg_type(p_muic);
177 debug("CHARGER TYPE: %d\n", chrg);
178
179 if (!p_chrg->chrg->chrg_bat_present(p_chrg)) {
180 puts("No battery detected\n");
Przemyslaw Marczak4a188362014-06-10 16:55:08 +0200181 return 0;
Piotr Wilczek4d6c9672013-09-20 15:01:27 +0200182 }
183
184 p_fg->fg->fg_battery_check(p_fg, p_bat);
185
186 if (pb->bat->state == CHARGE && chrg == CHARGER_USB)
187 puts("CHARGE Battery !\n");
Simon Glassfc47cf92016-11-23 06:34:40 -0700188#endif
Piotr Wilczek4d6c9672013-09-20 15:01:27 +0200189 return 0;
190}
191
Piotr Wilczekab8efbb2013-11-21 15:46:45 +0100192#ifdef CONFIG_USB_GADGET
193static int s5pc210_phy_control(int on)
194{
Igor Opaniuk2147a162021-02-09 13:52:45 +0200195#if !CONFIG_IS_ENABLED(DM_I2C) /* TODO(maintainer): Convert to driver model */
Piotr Wilczekab8efbb2013-11-21 15:46:45 +0100196 int ret = 0;
197 unsigned int val;
198 struct pmic *p, *p_pmic, *p_muic;
199
200 p_pmic = pmic_get("MAX77686_PMIC");
201 if (!p_pmic)
202 return -ENODEV;
203
204 if (pmic_probe(p_pmic))
205 return -1;
206
207 p_muic = pmic_get("MAX77693_MUIC");
208 if (!p_muic)
209 return -ENODEV;
210
211 if (pmic_probe(p_muic))
212 return -1;
213
214 if (on) {
215 ret = max77686_set_ldo_mode(p_pmic, 12, OPMODE_ON);
216 if (ret)
217 return -1;
218
219 p = pmic_get("MAX77693_PMIC");
220 if (!p)
221 return -ENODEV;
222
223 if (pmic_probe(p))
224 return -1;
225
226 /* SAFEOUT */
227 ret = pmic_reg_read(p, MAX77693_SAFEOUT, &val);
228 if (ret)
229 return -1;
230
231 val |= MAX77693_ENSAFEOUT1;
232 ret = pmic_reg_write(p, MAX77693_SAFEOUT, val);
233 if (ret)
234 return -1;
235
236 /* PATH: USB */
237 ret = pmic_reg_write(p_muic, MAX77693_MUIC_CONTROL1,
238 MAX77693_MUIC_CTRL1_DN1DP2);
239
240 } else {
241 ret = max77686_set_ldo_mode(p_pmic, 12, OPMODE_LPM);
242 if (ret)
243 return -1;
244
245 /* PATH: UART */
246 ret = pmic_reg_write(p_muic, MAX77693_MUIC_CONTROL1,
247 MAX77693_MUIC_CTRL1_UT1UR2);
248 }
249
250 if (ret)
251 return -1;
Simon Glassfc47cf92016-11-23 06:34:40 -0700252#endif
Piotr Wilczekab8efbb2013-11-21 15:46:45 +0100253 return 0;
254}
255
Marek Vasutc0982872015-12-04 02:23:29 +0100256struct dwc2_plat_otg_data s5pc210_otg_data = {
Piotr Wilczekab8efbb2013-11-21 15:46:45 +0100257 .phy_control = s5pc210_phy_control,
258 .regs_phy = EXYNOS4X12_USBPHY_BASE,
259 .regs_otg = EXYNOS4X12_USBOTG_BASE,
260 .usb_phy_ctrl = EXYNOS4X12_USBPHY_CONTROL,
261 .usb_flags = PHY0_SLEEP,
262};
263
264int board_usb_init(int index, enum usb_init_type init)
265{
266 debug("USB_udc_probe\n");
Marek Vasuta4bb9b32015-12-04 02:26:33 +0100267 return dwc2_udc_probe(&s5pc210_otg_data);
Piotr Wilczekab8efbb2013-11-21 15:46:45 +0100268}
269
Mateusz Zalega75504e92014-04-30 13:07:48 +0200270int g_dnl_board_usb_cable_connected(void)
Piotr Wilczekab8efbb2013-11-21 15:46:45 +0100271{
Igor Opaniuk2147a162021-02-09 13:52:45 +0200272#if !CONFIG_IS_ENABLED(DM_I2C) /* TODO(maintainer): Convert to driver model */
Piotr Wilczekab8efbb2013-11-21 15:46:45 +0100273 struct pmic *muic = pmic_get("MAX77693_MUIC");
274 if (!muic)
275 return 0;
276
277 return !!muic->chrg->chrg_type(muic);
Simon Glassfc47cf92016-11-23 06:34:40 -0700278#else
279 return false;
280#endif
Piotr Wilczekab8efbb2013-11-21 15:46:45 +0100281}
282#endif
Piotr Wilczekab8efbb2013-11-21 15:46:45 +0100283
Piotr Wilczek4d6c9672013-09-20 15:01:27 +0200284/*
285 * LCD
286 */
287
288#ifdef CONFIG_LCD
Piotr Wilczek1ecab0f2014-03-07 14:59:49 +0100289int mipi_power(void)
Piotr Wilczek4d6c9672013-09-20 15:01:27 +0200290{
Igor Opaniuk2147a162021-02-09 13:52:45 +0200291#if !CONFIG_IS_ENABLED(DM_I2C) /* TODO(maintainer): Convert to driver model */
Piotr Wilczek4d6c9672013-09-20 15:01:27 +0200292 struct pmic *p = pmic_get("MAX77686_PMIC");
293
294 /* LDO8 VMIPI_1.0V_AP */
295 max77686_set_ldo_mode(p, 8, OPMODE_ON);
296 /* LDO10 VMIPI_1.8V_AP */
297 max77686_set_ldo_mode(p, 10, OPMODE_ON);
Simon Glassfc47cf92016-11-23 06:34:40 -0700298#endif
Piotr Wilczek4d6c9672013-09-20 15:01:27 +0200299
300 return 0;
301}
302
303void exynos_lcd_power_on(void)
304{
Igor Opaniuk2147a162021-02-09 13:52:45 +0200305#if !CONFIG_IS_ENABLED(DM_I2C) /* TODO(maintainer): Convert to driver model */
Piotr Wilczek4d6c9672013-09-20 15:01:27 +0200306 struct pmic *p = pmic_get("MAX77686_PMIC");
307
Piotr Wilczek4d6c9672013-09-20 15:01:27 +0200308 /* LCD_2.2V_EN: GPC0[1] */
Simon Glass7f196102014-10-20 19:48:39 -0600309 gpio_request(EXYNOS4X12_GPIO_C01, "lcd_2v2_en");
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530310 gpio_set_pull(EXYNOS4X12_GPIO_C01, S5P_GPIO_PULL_UP);
311 gpio_direction_output(EXYNOS4X12_GPIO_C01, 1);
Piotr Wilczek4d6c9672013-09-20 15:01:27 +0200312
313 /* LDO25 VCC_3.1V_LCD */
314 pmic_probe(p);
315 max77686_set_ldo_voltage(p, 25, 3100000);
316 max77686_set_ldo_mode(p, 25, OPMODE_LPM);
Simon Glassfc47cf92016-11-23 06:34:40 -0700317#endif
Piotr Wilczek4d6c9672013-09-20 15:01:27 +0200318}
319
320void exynos_reset_lcd(void)
321{
Piotr Wilczek4d6c9672013-09-20 15:01:27 +0200322 /* reset lcd */
Simon Glass7f196102014-10-20 19:48:39 -0600323 gpio_request(EXYNOS4X12_GPIO_F21, "lcd_reset");
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530324 gpio_direction_output(EXYNOS4X12_GPIO_F21, 0);
Piotr Wilczek4d6c9672013-09-20 15:01:27 +0200325 udelay(10);
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530326 gpio_set_value(EXYNOS4X12_GPIO_F21, 1);
Piotr Wilczek4d6c9672013-09-20 15:01:27 +0200327}
328
Piotr Wilczek1ecab0f2014-03-07 14:59:49 +0100329void exynos_lcd_misc_init(vidinfo_t *vid)
Piotr Wilczek4d6c9672013-09-20 15:01:27 +0200330{
Piotr Wilczek4d6c9672013-09-20 15:01:27 +0200331#ifdef CONFIG_TIZEN
332 get_tizen_logo_info(vid);
333#endif
Piotr Wilczek1ecab0f2014-03-07 14:59:49 +0100334#ifdef CONFIG_S6E8AX0
Piotr Wilczek4d6c9672013-09-20 15:01:27 +0200335 s6e8ax0_init();
Piotr Wilczek1ecab0f2014-03-07 14:59:49 +0100336#endif
Piotr Wilczek4d6c9672013-09-20 15:01:27 +0200337}
338#endif /* LCD */