blob: 53ff7061d730c293260acd1f77367ec1d5bb4f16 [file] [log] [blame]
Amar752f4c42013-04-27 11:42:57 +05301/*
2 * Copyright (C) 2012 Samsung Electronics
3 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02004 * SPDX-License-Identifier: GPL-2.0+
Amar752f4c42013-04-27 11:42:57 +05305 */
6
7#include <common.h>
8#include <fdtdec.h>
9#include <asm/io.h>
10#include <errno.h>
11#include <i2c.h>
12#include <netdev.h>
13#include <spi.h>
Simon Glassa9cf6da2014-05-20 06:01:42 -060014#include <asm/gpio.h>
Amar752f4c42013-04-27 11:42:57 +053015#include <asm/arch/cpu.h>
16#include <asm/arch/dwmmc.h>
Amar752f4c42013-04-27 11:42:57 +053017#include <asm/arch/mmc.h>
18#include <asm/arch/pinmux.h>
19#include <asm/arch/power.h>
20#include <asm/arch/sromc.h>
21#include <power/pmic.h>
22#include <power/max77686_pmic.h>
Aaron Durbin0f2e7392014-05-20 06:01:39 -060023#include <power/tps65090_pmic.h>
Amar752f4c42013-04-27 11:42:57 +053024#include <tmu.h>
25
26DECLARE_GLOBAL_DATA_PTR;
27
Amar752f4c42013-04-27 11:42:57 +053028#ifdef CONFIG_SOUND_MAX98095
Rajeshwari Birje71ebb332013-12-26 09:44:17 +053029static void board_enable_audio_codec(void)
Amar752f4c42013-04-27 11:42:57 +053030{
Amar752f4c42013-04-27 11:42:57 +053031 /* Enable MAX98095 Codec */
Simon Glass7f196102014-10-20 19:48:39 -060032 gpio_request(EXYNOS5_GPIO_X17, "max98095_enable");
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +053033 gpio_direction_output(EXYNOS5_GPIO_X17, 1);
34 gpio_set_pull(EXYNOS5_GPIO_X17, S5P_GPIO_PULL_NONE);
Amar752f4c42013-04-27 11:42:57 +053035}
36#endif
37
Rajeshwari Birje71ebb332013-12-26 09:44:17 +053038int exynos_init(void)
Hung-ying Tyaneb28fda2013-05-15 18:27:34 +080039{
Amar752f4c42013-04-27 11:42:57 +053040#ifdef CONFIG_SOUND_MAX98095
41 board_enable_audio_codec();
42#endif
43 return 0;
44}
45
Simon Glass2f7547f2014-05-20 06:01:33 -060046#if defined(CONFIG_POWER)
47#ifdef CONFIG_POWER_MAX77686
48static int pmic_reg_update(struct pmic *p, int reg, uint regval)
49{
50 u32 val;
51 int ret = 0;
52
53 ret = pmic_reg_read(p, reg, &val);
54 if (ret) {
55 debug("%s: PMIC %d register read failed\n", __func__, reg);
56 return -1;
57 }
58 val |= regval;
59 ret = pmic_reg_write(p, reg, val);
60 if (ret) {
61 debug("%s: PMIC %d register write failed\n", __func__, reg);
62 return -1;
63 }
64 return 0;
65}
66
67static int max77686_init(void)
68{
69 struct pmic *p;
70
71 if (pmic_init(I2C_PMIC))
72 return -1;
73
74 p = pmic_get("MAX77686_PMIC");
75 if (!p)
76 return -ENODEV;
77
78 if (pmic_probe(p))
79 return -1;
80
81 if (pmic_reg_update(p, MAX77686_REG_PMIC_32KHZ, MAX77686_32KHCP_EN))
82 return -1;
83
84 if (pmic_reg_update(p, MAX77686_REG_PMIC_BBAT,
85 MAX77686_BBCHOSTEN | MAX77686_BBCVS_3_5V))
86 return -1;
87
88 /* VDD_MIF */
89 if (pmic_reg_write(p, MAX77686_REG_PMIC_BUCK1OUT,
90 MAX77686_BUCK1OUT_1V)) {
91 debug("%s: PMIC %d register write failed\n", __func__,
92 MAX77686_REG_PMIC_BUCK1OUT);
93 return -1;
94 }
95
96 if (pmic_reg_update(p, MAX77686_REG_PMIC_BUCK1CRTL,
97 MAX77686_BUCK1CTRL_EN))
98 return -1;
99
100 /* VDD_ARM */
101 if (pmic_reg_write(p, MAX77686_REG_PMIC_BUCK2DVS1,
102 MAX77686_BUCK2DVS1_1_3V)) {
103 debug("%s: PMIC %d register write failed\n", __func__,
104 MAX77686_REG_PMIC_BUCK2DVS1);
105 return -1;
106 }
107
108 if (pmic_reg_update(p, MAX77686_REG_PMIC_BUCK2CTRL1,
109 MAX77686_BUCK2CTRL_ON))
110 return -1;
111
112 /* VDD_INT */
113 if (pmic_reg_write(p, MAX77686_REG_PMIC_BUCK3DVS1,
114 MAX77686_BUCK3DVS1_1_0125V)) {
115 debug("%s: PMIC %d register write failed\n", __func__,
116 MAX77686_REG_PMIC_BUCK3DVS1);
117 return -1;
118 }
119
120 if (pmic_reg_update(p, MAX77686_REG_PMIC_BUCK3CTRL,
121 MAX77686_BUCK3CTRL_ON))
122 return -1;
123
124 /* VDD_G3D */
125 if (pmic_reg_write(p, MAX77686_REG_PMIC_BUCK4DVS1,
126 MAX77686_BUCK4DVS1_1_2V)) {
127 debug("%s: PMIC %d register write failed\n", __func__,
128 MAX77686_REG_PMIC_BUCK4DVS1);
129 return -1;
130 }
131
132 if (pmic_reg_update(p, MAX77686_REG_PMIC_BUCK4CTRL1,
133 MAX77686_BUCK3CTRL_ON))
134 return -1;
135
136 /* VDD_LDO2 */
137 if (pmic_reg_update(p, MAX77686_REG_PMIC_LDO2CTRL1,
138 MAX77686_LD02CTRL1_1_5V | EN_LDO))
139 return -1;
140
141 /* VDD_LDO3 */
142 if (pmic_reg_update(p, MAX77686_REG_PMIC_LDO3CTRL1,
143 MAX77686_LD03CTRL1_1_8V | EN_LDO))
144 return -1;
145
146 /* VDD_LDO5 */
147 if (pmic_reg_update(p, MAX77686_REG_PMIC_LDO5CTRL1,
148 MAX77686_LD05CTRL1_1_8V | EN_LDO))
149 return -1;
150
151 /* VDD_LDO10 */
152 if (pmic_reg_update(p, MAX77686_REG_PMIC_LDO10CTRL1,
153 MAX77686_LD10CTRL1_1_8V | EN_LDO))
154 return -1;
155
156 return 0;
157}
158#endif /* CONFIG_POWER_MAX77686 */
159
160int exynos_power_init(void)
161{
162 int ret = 0;
163
164#ifdef CONFIG_POWER_MAX77686
165 ret = max77686_init();
Aaron Durbin0f2e7392014-05-20 06:01:39 -0600166 if (ret)
167 return ret;
Simon Glass2f7547f2014-05-20 06:01:33 -0600168#endif
Aaron Durbin0f2e7392014-05-20 06:01:39 -0600169#ifdef CONFIG_POWER_TPS65090
170 /*
171 * The TPS65090 may not be in the device tree. If so, it is not
172 * an error.
173 */
174 ret = tps65090_init();
175 if (ret == 0 || ret == -ENODEV)
176 return 0;
177#endif
178
Simon Glass2f7547f2014-05-20 06:01:33 -0600179 return ret;
180}
181#endif /* CONFIG_POWER */
182
Amar752f4c42013-04-27 11:42:57 +0530183#ifdef CONFIG_LCD
Simon Glassa9cf6da2014-05-20 06:01:42 -0600184static int board_dp_bridge_setup(void)
185{
186 const int max_tries = 10;
187 int num_tries, node;
188
189 /*
190 * TODO(sjg): Use device tree for GPIOs when exynos GPIO
191 * numbering patch is in mainline.
192 */
193 debug("%s\n", __func__);
194 node = fdtdec_next_compatible(gd->fdt_blob, 0, COMPAT_NXP_PTN3460);
195 if (node < 0) {
196 debug("%s: No node for DP bridge in device tree\n", __func__);
197 return -ENODEV;
198 }
199
200 /* Setup the GPIOs */
201
202 /* PD is ACTIVE_LOW, and initially de-asserted */
Simon Glass7f196102014-10-20 19:48:39 -0600203 gpio_request(EXYNOS5_GPIO_Y25, "dp_bridge_pd");
Simon Glassa9cf6da2014-05-20 06:01:42 -0600204 gpio_set_pull(EXYNOS5_GPIO_Y25, S5P_GPIO_PULL_NONE);
205 gpio_direction_output(EXYNOS5_GPIO_Y25, 1);
206
207 /* Reset is ACTIVE_LOW */
Simon Glass7f196102014-10-20 19:48:39 -0600208 gpio_request(EXYNOS5_GPIO_X15, "dp_bridge_reset");
Simon Glassa9cf6da2014-05-20 06:01:42 -0600209 gpio_set_pull(EXYNOS5_GPIO_X15, S5P_GPIO_PULL_NONE);
210 gpio_direction_output(EXYNOS5_GPIO_X15, 0);
211
212 udelay(10);
213 gpio_set_value(EXYNOS5_GPIO_X15, 1);
214
Simon Glass7f196102014-10-20 19:48:39 -0600215 gpio_request(EXYNOS5_GPIO_X07, "dp_bridge_hpd");
Simon Glassa9cf6da2014-05-20 06:01:42 -0600216 gpio_direction_input(EXYNOS5_GPIO_X07);
217
218 /*
219 * We need to wait for 90ms after bringing up the bridge since there
220 * is a phantom "high" on the HPD chip during its bootup. The phantom
221 * high comes within 7ms of de-asserting PD and persists for at least
222 * 15ms. The real high comes roughly 50ms after PD is de-asserted. The
223 * phantom high makes it hard for us to know when the NXP chip is up.
224 */
225 mdelay(90);
226
227 for (num_tries = 0; num_tries < max_tries; num_tries++) {
228 /* Check HPD. If it's high, we're all good. */
229 if (gpio_get_value(EXYNOS5_GPIO_X07))
230 return 0;
231
232 debug("%s: eDP bridge failed to come up; try %d of %d\n",
233 __func__, num_tries, max_tries);
234 }
235
236 /* Immediately go into bridge reset if the hp line is not high */
237 return -ENODEV;
238}
239
Amar752f4c42013-04-27 11:42:57 +0530240void exynos_cfg_lcd_gpio(void)
241{
Amar752f4c42013-04-27 11:42:57 +0530242 /* For Backlight */
Simon Glass7f196102014-10-20 19:48:39 -0600243 gpio_request(EXYNOS5_GPIO_B20, "lcd_backlight");
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530244 gpio_cfg_pin(EXYNOS5_GPIO_B20, S5P_GPIO_OUTPUT);
245 gpio_set_value(EXYNOS5_GPIO_B20, 1);
Amar752f4c42013-04-27 11:42:57 +0530246
247 /* LCD power on */
Simon Glass7f196102014-10-20 19:48:39 -0600248 gpio_request(EXYNOS5_GPIO_X15, "lcd_power");
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530249 gpio_cfg_pin(EXYNOS5_GPIO_X15, S5P_GPIO_OUTPUT);
250 gpio_set_value(EXYNOS5_GPIO_X15, 1);
Amar752f4c42013-04-27 11:42:57 +0530251
252 /* Set Hotplug detect for DP */
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530253 gpio_cfg_pin(EXYNOS5_GPIO_X07, S5P_GPIO_FUNC(0x3));
Amar752f4c42013-04-27 11:42:57 +0530254}
255
256void exynos_set_dp_phy(unsigned int onoff)
257{
258 set_dp_phy_ctrl(onoff);
259}
Simon Glassa9cf6da2014-05-20 06:01:42 -0600260
261void exynos_backlight_on(unsigned int on)
262{
263 debug("%s(%u)\n", __func__, on);
264
265 if (!on)
266 return;
267
268#ifdef CONFIG_POWER_TPS65090
269 int ret;
270
271 ret = tps65090_fet_enable(1); /* Enable FET1, backlight */
272 if (ret)
273 return;
274
275 /* T5 in the LCD timing spec (defined as > 10ms) */
276 mdelay(10);
277
278 /* board_dp_backlight_pwm */
279 gpio_direction_output(EXYNOS5_GPIO_B20, 1);
280
281 /* T6 in the LCD timing spec (defined as > 10ms) */
282 mdelay(10);
283
284 /* board_dp_backlight_en */
Simon Glass7f196102014-10-20 19:48:39 -0600285 gpio_request(EXYNOS5_GPIO_X30, "board_dp_backlight_en");
Simon Glassa9cf6da2014-05-20 06:01:42 -0600286 gpio_direction_output(EXYNOS5_GPIO_X30, 1);
287#endif
288}
289
290void exynos_lcd_power_on(void)
291{
292 int ret;
293
294 debug("%s\n", __func__);
295
296#ifdef CONFIG_POWER_TPS65090
297 /* board_dp_lcd_vdd */
298 tps65090_fet_enable(6); /* Enable FET6, lcd panel */
299#endif
300
301 ret = board_dp_bridge_setup();
302 if (ret && ret != -ENODEV)
303 printf("LCD bridge failed to enable: %d\n", ret);
304}
305
Amar752f4c42013-04-27 11:42:57 +0530306#endif