blob: 6bcc883b100c5212ee40e932eb0d656fd0dec718 [file] [log] [blame]
Amarbb54b752013-04-27 11:42:57 +05301/*
2 * Copyright (C) 2012 Samsung Electronics
3 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02004 * SPDX-License-Identifier: GPL-2.0+
Amarbb54b752013-04-27 11:42:57 +05305 */
6
7#include <common.h>
Hung-ying Tyana4ed85d2013-05-15 18:27:34 +08008#include <cros_ec.h>
Amarbb54b752013-04-27 11:42:57 +05309#include <fdtdec.h>
10#include <asm/io.h>
11#include <errno.h>
12#include <i2c.h>
13#include <netdev.h>
14#include <spi.h>
15#include <asm/arch/cpu.h>
16#include <asm/arch/dwmmc.h>
17#include <asm/arch/gpio.h>
18#include <asm/arch/mmc.h>
19#include <asm/arch/pinmux.h>
20#include <asm/arch/power.h>
21#include <asm/arch/sromc.h>
22#include <power/pmic.h>
23#include <power/max77686_pmic.h>
24#include <tmu.h>
25
26DECLARE_GLOBAL_DATA_PTR;
27
28#if defined CONFIG_EXYNOS_TMU
29/*
30 * Boot Time Thermal Analysis for SoC temperature threshold breach
31 */
32static void boot_temp_check(void)
33{
34 int temp;
35
36 switch (tmu_monitor(&temp)) {
37 /* Status TRIPPED ans WARNING means corresponding threshold breach */
38 case TMU_STATUS_TRIPPED:
39 puts("EXYNOS_TMU: TRIPPING! Device power going down ...\n");
40 set_ps_hold_ctrl();
41 hang();
42 break;
43 case TMU_STATUS_WARNING:
44 puts("EXYNOS_TMU: WARNING! Temperature very high\n");
45 break;
46 /*
47 * TMU_STATUS_INIT means something is wrong with temperature sensing
48 * and TMU status was changed back from NORMAL to INIT.
49 */
50 case TMU_STATUS_INIT:
51 default:
52 debug("EXYNOS_TMU: Unknown TMU state\n");
53 }
54}
55#endif
56
Hung-ying Tyana4ed85d2013-05-15 18:27:34 +080057struct local_info {
58 struct cros_ec_dev *cros_ec_dev; /* Pointer to cros_ec device */
59 int cros_ec_err; /* Error for cros_ec, 0 if ok */
60};
61
62static struct local_info local;
63
Amarbb54b752013-04-27 11:42:57 +053064#ifdef CONFIG_SOUND_MAX98095
65static void board_enable_audio_codec(void)
66{
67 struct exynos5_gpio_part1 *gpio1 = (struct exynos5_gpio_part1 *)
68 samsung_get_base_gpio_part1();
69
70 /* Enable MAX98095 Codec */
71 s5p_gpio_direction_output(&gpio1->x1, 7, 1);
72 s5p_gpio_set_pull(&gpio1->x1, 7, GPIO_PULL_NONE);
73}
74#endif
75
Hung-ying Tyana4ed85d2013-05-15 18:27:34 +080076struct cros_ec_dev *board_get_cros_ec_dev(void)
77{
78 return local.cros_ec_dev;
79}
80
81static int board_init_cros_ec_devices(const void *blob)
82{
83 local.cros_ec_err = cros_ec_init(blob, &local.cros_ec_dev);
84 if (local.cros_ec_err)
85 return -1; /* Will report in board_late_init() */
86
87 return 0;
88}
89
Amarbb54b752013-04-27 11:42:57 +053090int board_init(void)
91{
92 gd->bd->bi_boot_params = (PHYS_SDRAM_1 + 0x100UL);
93
94#if defined CONFIG_EXYNOS_TMU
95 if (tmu_init(gd->fdt_blob) != TMU_STATUS_NORMAL) {
96 debug("%s: Failed to init TMU\n", __func__);
97 return -1;
98 }
99 boot_temp_check();
100#endif
101
102#ifdef CONFIG_EXYNOS_SPI
103 spi_init();
104#endif
Hung-ying Tyana4ed85d2013-05-15 18:27:34 +0800105
106 if (board_init_cros_ec_devices(gd->fdt_blob))
107 return -1;
108
Amarbb54b752013-04-27 11:42:57 +0530109#ifdef CONFIG_SOUND_MAX98095
110 board_enable_audio_codec();
111#endif
112 return 0;
113}
114
115int dram_init(void)
116{
117 int i;
118 u32 addr;
119
120 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
121 addr = CONFIG_SYS_SDRAM_BASE + (i * SDRAM_BANK_SIZE);
122 gd->ram_size += get_ram_size((long *)addr, SDRAM_BANK_SIZE);
123 }
124 return 0;
125}
126
127#if defined(CONFIG_POWER)
128static int pmic_reg_update(struct pmic *p, int reg, uint regval)
129{
130 u32 val;
131 int ret = 0;
132
133 ret = pmic_reg_read(p, reg, &val);
134 if (ret) {
135 debug("%s: PMIC %d register read failed\n", __func__, reg);
136 return -1;
137 }
138 val |= regval;
139 ret = pmic_reg_write(p, reg, val);
140 if (ret) {
141 debug("%s: PMIC %d register write failed\n", __func__, reg);
142 return -1;
143 }
144 return 0;
145}
146
147int power_init_board(void)
148{
149 struct pmic *p;
150
151 set_ps_hold_ctrl();
152
153 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
154
155 if (pmic_init(I2C_PMIC))
156 return -1;
157
158 p = pmic_get("MAX77686_PMIC");
159 if (!p)
160 return -ENODEV;
161
162 if (pmic_probe(p))
163 return -1;
164
165 if (pmic_reg_update(p, MAX77686_REG_PMIC_32KHZ, MAX77686_32KHCP_EN))
166 return -1;
167
168 if (pmic_reg_update(p, MAX77686_REG_PMIC_BBAT,
169 MAX77686_BBCHOSTEN | MAX77686_BBCVS_3_5V))
170 return -1;
171
172 /* VDD_MIF */
173 if (pmic_reg_write(p, MAX77686_REG_PMIC_BUCK1OUT,
174 MAX77686_BUCK1OUT_1V)) {
175 debug("%s: PMIC %d register write failed\n", __func__,
176 MAX77686_REG_PMIC_BUCK1OUT);
177 return -1;
178 }
179
180 if (pmic_reg_update(p, MAX77686_REG_PMIC_BUCK1CRTL,
181 MAX77686_BUCK1CTRL_EN))
182 return -1;
183
184 /* VDD_ARM */
185 if (pmic_reg_write(p, MAX77686_REG_PMIC_BUCK2DVS1,
186 MAX77686_BUCK2DVS1_1_3V)) {
187 debug("%s: PMIC %d register write failed\n", __func__,
188 MAX77686_REG_PMIC_BUCK2DVS1);
189 return -1;
190 }
191
192 if (pmic_reg_update(p, MAX77686_REG_PMIC_BUCK2CTRL1,
193 MAX77686_BUCK2CTRL_ON))
194 return -1;
195
196 /* VDD_INT */
197 if (pmic_reg_write(p, MAX77686_REG_PMIC_BUCK3DVS1,
198 MAX77686_BUCK3DVS1_1_0125V)) {
199 debug("%s: PMIC %d register write failed\n", __func__,
200 MAX77686_REG_PMIC_BUCK3DVS1);
201 return -1;
202 }
203
204 if (pmic_reg_update(p, MAX77686_REG_PMIC_BUCK3CTRL,
205 MAX77686_BUCK3CTRL_ON))
206 return -1;
207
208 /* VDD_G3D */
209 if (pmic_reg_write(p, MAX77686_REG_PMIC_BUCK4DVS1,
210 MAX77686_BUCK4DVS1_1_2V)) {
211 debug("%s: PMIC %d register write failed\n", __func__,
212 MAX77686_REG_PMIC_BUCK4DVS1);
213 return -1;
214 }
215
216 if (pmic_reg_update(p, MAX77686_REG_PMIC_BUCK4CTRL1,
217 MAX77686_BUCK3CTRL_ON))
218 return -1;
219
220 /* VDD_LDO2 */
221 if (pmic_reg_update(p, MAX77686_REG_PMIC_LDO2CTRL1,
222 MAX77686_LD02CTRL1_1_5V | EN_LDO))
223 return -1;
224
225 /* VDD_LDO3 */
226 if (pmic_reg_update(p, MAX77686_REG_PMIC_LDO3CTRL1,
227 MAX77686_LD03CTRL1_1_8V | EN_LDO))
228 return -1;
229
230 /* VDD_LDO5 */
231 if (pmic_reg_update(p, MAX77686_REG_PMIC_LDO5CTRL1,
232 MAX77686_LD05CTRL1_1_8V | EN_LDO))
233 return -1;
234
235 /* VDD_LDO10 */
236 if (pmic_reg_update(p, MAX77686_REG_PMIC_LDO10CTRL1,
237 MAX77686_LD10CTRL1_1_8V | EN_LDO))
238 return -1;
239
240 return 0;
241}
242#endif
243
244void dram_init_banksize(void)
245{
246 int i;
247 u32 addr, size;
248
249 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
250 addr = CONFIG_SYS_SDRAM_BASE + (i * SDRAM_BANK_SIZE);
251 size = get_ram_size((long *)addr, SDRAM_BANK_SIZE);
252
253 gd->bd->bi_dram[i].start = addr;
254 gd->bd->bi_dram[i].size = size;
255 }
256}
257
258static int decode_sromc(const void *blob, struct fdt_sromc *config)
259{
260 int err;
261 int node;
262
263 node = fdtdec_next_compatible(blob, 0, COMPAT_SAMSUNG_EXYNOS5_SROMC);
264 if (node < 0) {
265 debug("Could not find SROMC node\n");
266 return node;
267 }
268
269 config->bank = fdtdec_get_int(blob, node, "bank", 0);
270 config->width = fdtdec_get_int(blob, node, "width", 2);
271
272 err = fdtdec_get_int_array(blob, node, "srom-timing", config->timing,
273 FDT_SROM_TIMING_COUNT);
274 if (err < 0) {
275 debug("Could not decode SROMC configuration Error: %s\n",
276 fdt_strerror(err));
277 return -FDT_ERR_NOTFOUND;
278 }
279 return 0;
280}
281
282int board_eth_init(bd_t *bis)
283{
284#ifdef CONFIG_SMC911X
285 u32 smc_bw_conf, smc_bc_conf;
286 struct fdt_sromc config;
287 fdt_addr_t base_addr;
288 int node;
289
290 node = decode_sromc(gd->fdt_blob, &config);
291 if (node < 0) {
292 debug("%s: Could not find sromc configuration\n", __func__);
293 return 0;
294 }
295 node = fdtdec_next_compatible(gd->fdt_blob, node, COMPAT_SMSC_LAN9215);
296 if (node < 0) {
297 debug("%s: Could not find lan9215 configuration\n", __func__);
298 return 0;
299 }
300
301 /* We now have a node, so any problems from now on are errors */
302 base_addr = fdtdec_get_addr(gd->fdt_blob, node, "reg");
303 if (base_addr == FDT_ADDR_T_NONE) {
304 debug("%s: Could not find lan9215 address\n", __func__);
305 return -1;
306 }
307
308 /* Ethernet needs data bus width of 16 bits */
309 if (config.width != 2) {
310 debug("%s: Unsupported bus width %d\n", __func__,
311 config.width);
312 return -1;
313 }
314 smc_bw_conf = SROMC_DATA16_WIDTH(config.bank)
315 | SROMC_BYTE_ENABLE(config.bank);
316
317 smc_bc_conf = SROMC_BC_TACS(config.timing[FDT_SROM_TACS]) |
318 SROMC_BC_TCOS(config.timing[FDT_SROM_TCOS]) |
319 SROMC_BC_TACC(config.timing[FDT_SROM_TACC]) |
320 SROMC_BC_TCOH(config.timing[FDT_SROM_TCOH]) |
321 SROMC_BC_TAH(config.timing[FDT_SROM_TAH]) |
322 SROMC_BC_TACP(config.timing[FDT_SROM_TACP]) |
323 SROMC_BC_PMC(config.timing[FDT_SROM_PMC]);
324
325 /* Select and configure the SROMC bank */
326 exynos_pinmux_config(PERIPH_ID_SROMC, config.bank);
327 s5p_config_sromc(config.bank, smc_bw_conf, smc_bc_conf);
328 return smc911x_initialize(0, base_addr);
329#endif
330 return 0;
331}
332
333#ifdef CONFIG_DISPLAY_BOARDINFO
334int checkboard(void)
335{
336 const char *board_name;
337
338 board_name = fdt_getprop(gd->fdt_blob, 0, "model", NULL);
339 if (board_name == NULL)
340 printf("\nUnknown Board\n");
341 else
342 printf("\nBoard: %s\n", board_name);
343
344 return 0;
345}
346#endif
347
348#ifdef CONFIG_GENERIC_MMC
349int board_mmc_init(bd_t *bis)
350{
351 int ret;
352 /* dwmmc initializattion for available channels */
353 ret = exynos_dwmmc_init(gd->fdt_blob);
354 if (ret)
355 debug("dwmmc init failed\n");
356
357 return ret;
358}
359#endif
360
361static int board_uart_init(void)
362{
363 int err, uart_id, ret = 0;
364
365 for (uart_id = PERIPH_ID_UART0; uart_id <= PERIPH_ID_UART3; uart_id++) {
366 err = exynos_pinmux_config(uart_id, PINMUX_FLAG_NONE);
367 if (err) {
368 debug("UART%d not configured\n",
369 (uart_id - PERIPH_ID_UART0));
370 ret |= err;
371 }
372 }
373 return ret;
374}
375
376#ifdef CONFIG_BOARD_EARLY_INIT_F
377int board_early_init_f(void)
378{
379 int err;
380 err = board_uart_init();
381 if (err) {
382 debug("UART init failed\n");
383 return err;
384 }
385#ifdef CONFIG_SYS_I2C_INIT_BOARD
386 board_i2c_init(gd->fdt_blob);
387#endif
388 return err;
389}
390#endif
391
392#ifdef CONFIG_LCD
393void exynos_cfg_lcd_gpio(void)
394{
395 struct exynos5_gpio_part1 *gpio1 =
396 (struct exynos5_gpio_part1 *)samsung_get_base_gpio_part1();
397
398 /* For Backlight */
399 s5p_gpio_cfg_pin(&gpio1->b2, 0, GPIO_OUTPUT);
400 s5p_gpio_set_value(&gpio1->b2, 0, 1);
401
402 /* LCD power on */
403 s5p_gpio_cfg_pin(&gpio1->x1, 5, GPIO_OUTPUT);
404 s5p_gpio_set_value(&gpio1->x1, 5, 1);
405
406 /* Set Hotplug detect for DP */
407 s5p_gpio_cfg_pin(&gpio1->x0, 7, GPIO_FUNC(0x3));
408}
409
410void exynos_set_dp_phy(unsigned int onoff)
411{
412 set_dp_phy_ctrl(onoff);
413}
414#endif
Hung-ying Tyana4ed85d2013-05-15 18:27:34 +0800415
416#ifdef CONFIG_BOARD_LATE_INIT
417int board_late_init(void)
418{
419 stdio_print_current_devices();
420
421 if (local.cros_ec_err) {
422 /* Force console on */
423 gd->flags &= ~GD_FLG_SILENT;
424
425 printf("cros-ec communications failure %d\n",
426 local.cros_ec_err);
427 puts("\nPlease reset with Power+Refresh\n\n");
428 panic("Cannot init cros-ec device");
429 return -1;
430 }
431 return 0;
432}
433#endif