]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/samsung/smdk5250/exynos5-dt.c
d6ce1337b94ba6f06172ea6459c7162396dbc5ea
[karo-tx-uboot.git] / board / samsung / smdk5250 / exynos5-dt.c
1 /*
2  * Copyright (C) 2012 Samsung Electronics
3  *
4  * SPDX-License-Identifier:     GPL-2.0+
5  */
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>
14 #include <asm/gpio.h>
15 #include <asm/arch/cpu.h>
16 #include <asm/arch/dwmmc.h>
17 #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>
23 #include <power/tps65090_pmic.h>
24 #include <tmu.h>
25
26 DECLARE_GLOBAL_DATA_PTR;
27
28 #ifdef CONFIG_SOUND_MAX98095
29 static void board_enable_audio_codec(void)
30 {
31         /* Enable MAX98095 Codec */
32         gpio_direction_output(EXYNOS5_GPIO_X17, 1);
33         gpio_set_pull(EXYNOS5_GPIO_X17, S5P_GPIO_PULL_NONE);
34 }
35 #endif
36
37 int exynos_init(void)
38 {
39 #ifdef CONFIG_SOUND_MAX98095
40         board_enable_audio_codec();
41 #endif
42         return 0;
43 }
44
45 #if defined(CONFIG_POWER)
46 #ifdef CONFIG_POWER_MAX77686
47 static int pmic_reg_update(struct pmic *p, int reg, uint regval)
48 {
49         u32 val;
50         int ret = 0;
51
52         ret = pmic_reg_read(p, reg, &val);
53         if (ret) {
54                 debug("%s: PMIC %d register read failed\n", __func__, reg);
55                 return -1;
56         }
57         val |= regval;
58         ret = pmic_reg_write(p, reg, val);
59         if (ret) {
60                 debug("%s: PMIC %d register write failed\n", __func__, reg);
61                 return -1;
62         }
63         return 0;
64 }
65
66 static int max77686_init(void)
67 {
68         struct pmic *p;
69
70         if (pmic_init(I2C_PMIC))
71                 return -1;
72
73         p = pmic_get("MAX77686_PMIC");
74         if (!p)
75                 return -ENODEV;
76
77         if (pmic_probe(p))
78                 return -1;
79
80         if (pmic_reg_update(p, MAX77686_REG_PMIC_32KHZ, MAX77686_32KHCP_EN))
81                 return -1;
82
83         if (pmic_reg_update(p, MAX77686_REG_PMIC_BBAT,
84                             MAX77686_BBCHOSTEN | MAX77686_BBCVS_3_5V))
85                 return -1;
86
87         /* VDD_MIF */
88         if (pmic_reg_write(p, MAX77686_REG_PMIC_BUCK1OUT,
89                            MAX77686_BUCK1OUT_1V)) {
90                 debug("%s: PMIC %d register write failed\n", __func__,
91                       MAX77686_REG_PMIC_BUCK1OUT);
92                 return -1;
93         }
94
95         if (pmic_reg_update(p, MAX77686_REG_PMIC_BUCK1CRTL,
96                             MAX77686_BUCK1CTRL_EN))
97                 return -1;
98
99         /* VDD_ARM */
100         if (pmic_reg_write(p, MAX77686_REG_PMIC_BUCK2DVS1,
101                            MAX77686_BUCK2DVS1_1_3V)) {
102                 debug("%s: PMIC %d register write failed\n", __func__,
103                       MAX77686_REG_PMIC_BUCK2DVS1);
104                 return -1;
105         }
106
107         if (pmic_reg_update(p, MAX77686_REG_PMIC_BUCK2CTRL1,
108                             MAX77686_BUCK2CTRL_ON))
109                 return -1;
110
111         /* VDD_INT */
112         if (pmic_reg_write(p, MAX77686_REG_PMIC_BUCK3DVS1,
113                            MAX77686_BUCK3DVS1_1_0125V)) {
114                 debug("%s: PMIC %d register write failed\n", __func__,
115                       MAX77686_REG_PMIC_BUCK3DVS1);
116                 return -1;
117         }
118
119         if (pmic_reg_update(p, MAX77686_REG_PMIC_BUCK3CTRL,
120                             MAX77686_BUCK3CTRL_ON))
121                 return -1;
122
123         /* VDD_G3D */
124         if (pmic_reg_write(p, MAX77686_REG_PMIC_BUCK4DVS1,
125                            MAX77686_BUCK4DVS1_1_2V)) {
126                 debug("%s: PMIC %d register write failed\n", __func__,
127                       MAX77686_REG_PMIC_BUCK4DVS1);
128                 return -1;
129         }
130
131         if (pmic_reg_update(p, MAX77686_REG_PMIC_BUCK4CTRL1,
132                             MAX77686_BUCK3CTRL_ON))
133                 return -1;
134
135         /* VDD_LDO2 */
136         if (pmic_reg_update(p, MAX77686_REG_PMIC_LDO2CTRL1,
137                             MAX77686_LD02CTRL1_1_5V | EN_LDO))
138                 return -1;
139
140         /* VDD_LDO3 */
141         if (pmic_reg_update(p, MAX77686_REG_PMIC_LDO3CTRL1,
142                             MAX77686_LD03CTRL1_1_8V | EN_LDO))
143                 return -1;
144
145         /* VDD_LDO5 */
146         if (pmic_reg_update(p, MAX77686_REG_PMIC_LDO5CTRL1,
147                             MAX77686_LD05CTRL1_1_8V | EN_LDO))
148                 return -1;
149
150         /* VDD_LDO10 */
151         if (pmic_reg_update(p, MAX77686_REG_PMIC_LDO10CTRL1,
152                             MAX77686_LD10CTRL1_1_8V | EN_LDO))
153                 return -1;
154
155         return 0;
156 }
157 #endif  /* CONFIG_POWER_MAX77686 */
158
159 int exynos_power_init(void)
160 {
161         int ret = 0;
162
163 #ifdef CONFIG_POWER_MAX77686
164         ret = max77686_init();
165         if (ret)
166                 return ret;
167 #endif
168 #ifdef CONFIG_POWER_TPS65090
169         /*
170          * The TPS65090 may not be in the device tree. If so, it is not
171          * an error.
172          */
173         ret = tps65090_init();
174         if (ret == 0 || ret == -ENODEV)
175                 return 0;
176 #endif
177
178         return ret;
179 }
180 #endif  /* CONFIG_POWER */
181
182 #ifdef CONFIG_LCD
183 static int board_dp_bridge_setup(void)
184 {
185         const int max_tries = 10;
186         int num_tries, node;
187
188         /*
189          * TODO(sjg): Use device tree for GPIOs when exynos GPIO
190          * numbering patch is in mainline.
191          */
192         debug("%s\n", __func__);
193         node = fdtdec_next_compatible(gd->fdt_blob, 0, COMPAT_NXP_PTN3460);
194         if (node < 0) {
195                 debug("%s: No node for DP bridge in device tree\n", __func__);
196                 return -ENODEV;
197         }
198
199         /* Setup the GPIOs */
200
201         /* PD is ACTIVE_LOW, and initially de-asserted */
202         gpio_set_pull(EXYNOS5_GPIO_Y25, S5P_GPIO_PULL_NONE);
203         gpio_direction_output(EXYNOS5_GPIO_Y25, 1);
204
205         /* Reset is ACTIVE_LOW */
206         gpio_set_pull(EXYNOS5_GPIO_X15, S5P_GPIO_PULL_NONE);
207         gpio_direction_output(EXYNOS5_GPIO_X15, 0);
208
209         udelay(10);
210         gpio_set_value(EXYNOS5_GPIO_X15, 1);
211
212         gpio_direction_input(EXYNOS5_GPIO_X07);
213
214         /*
215          * We need to wait for 90ms after bringing up the bridge since there
216          * is a phantom "high" on the HPD chip during its bootup.  The phantom
217          * high comes within 7ms of de-asserting PD and persists for at least
218          * 15ms.  The real high comes roughly 50ms after PD is de-asserted. The
219          * phantom high makes it hard for us to know when the NXP chip is up.
220          */
221         mdelay(90);
222
223         for (num_tries = 0; num_tries < max_tries; num_tries++) {
224                 /* Check HPD.  If it's high, we're all good. */
225                 if (gpio_get_value(EXYNOS5_GPIO_X07))
226                                 return 0;
227
228                 debug("%s: eDP bridge failed to come up; try %d of %d\n",
229                       __func__, num_tries, max_tries);
230         }
231
232         /* Immediately go into bridge reset if the hp line is not high */
233         return -ENODEV;
234 }
235
236 void exynos_cfg_lcd_gpio(void)
237 {
238         /* For Backlight */
239         gpio_cfg_pin(EXYNOS5_GPIO_B20, S5P_GPIO_OUTPUT);
240         gpio_set_value(EXYNOS5_GPIO_B20, 1);
241
242         /* LCD power on */
243         gpio_cfg_pin(EXYNOS5_GPIO_X15, S5P_GPIO_OUTPUT);
244         gpio_set_value(EXYNOS5_GPIO_X15, 1);
245
246         /* Set Hotplug detect for DP */
247         gpio_cfg_pin(EXYNOS5_GPIO_X07, S5P_GPIO_FUNC(0x3));
248 }
249
250 void exynos_set_dp_phy(unsigned int onoff)
251 {
252         set_dp_phy_ctrl(onoff);
253 }
254
255 void exynos_backlight_on(unsigned int on)
256 {
257         debug("%s(%u)\n", __func__, on);
258
259         if (!on)
260                 return;
261
262 #ifdef CONFIG_POWER_TPS65090
263         int ret;
264
265         ret = tps65090_fet_enable(1); /* Enable FET1, backlight */
266         if (ret)
267                 return;
268
269         /* T5 in the LCD timing spec (defined as > 10ms) */
270         mdelay(10);
271
272         /* board_dp_backlight_pwm */
273         gpio_direction_output(EXYNOS5_GPIO_B20, 1);
274
275         /* T6 in the LCD timing spec (defined as > 10ms) */
276         mdelay(10);
277
278         /* board_dp_backlight_en */
279         gpio_direction_output(EXYNOS5_GPIO_X30, 1);
280 #endif
281 }
282
283 void exynos_lcd_power_on(void)
284 {
285         int ret;
286
287         debug("%s\n", __func__);
288
289 #ifdef CONFIG_POWER_TPS65090
290         /* board_dp_lcd_vdd */
291         tps65090_fet_enable(6); /* Enable FET6, lcd panel */
292 #endif
293
294         ret = board_dp_bridge_setup();
295         if (ret && ret != -ENODEV)
296                 printf("LCD bridge failed to enable: %d\n", ret);
297 }
298
299 #endif