blob: 3e9e83f3ad06c271d1ceb4f7e3b65dd86b98b659 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Kever Yang0d3d7832016-07-19 21:16:59 +08002/*
3 * (C) Copyright 2016 Rockchip Electronics Co., Ltd
Kever Yang0d3d7832016-07-19 21:16:59 +08004 */
Philipp Tomsich3df66262017-09-29 19:27:54 +02005
Kever Yang0d3d7832016-07-19 21:16:59 +08006#include <common.h>
Kever Yang6d26c062016-08-16 17:58:13 +08007#include <dm.h>
8#include <dm/pinctrl.h>
Kever Yang11c21c52016-09-23 15:57:20 +08009#include <dm/uclass-internal.h>
Kever Yang6d26c062016-08-16 17:58:13 +080010#include <asm/arch/periph.h>
Kever Yangb1395292016-08-24 12:02:22 +080011#include <power/regulator.h>
Philipp Tomsich3df66262017-09-29 19:27:54 +020012#include <spl.h>
Kever Yang0d3d7832016-07-19 21:16:59 +080013
Kever Yang0d3d7832016-07-19 21:16:59 +080014int board_init(void)
15{
Kever Yangb1395292016-08-24 12:02:22 +080016 struct udevice *pinctrl, *regulator;
Kever Yang6d26c062016-08-16 17:58:13 +080017 int ret;
18
19 /*
20 * The PWM do not have decicated interrupt number in dts and can
21 * not get periph_id by pinctrl framework, so let's init them here.
22 * The PWM2 and PWM3 are for pwm regulater.
23 */
24 ret = uclass_get_device(UCLASS_PINCTRL, 0, &pinctrl);
25 if (ret) {
26 debug("%s: Cannot find pinctrl device\n", __func__);
27 goto out;
28 }
29
Eric Gao75058e22017-05-02 18:23:55 +080030 /* Enable pwm0 for panel backlight */
31 ret = pinctrl_request_noflags(pinctrl, PERIPH_ID_PWM0);
32 if (ret) {
33 debug("%s PWM0 pinctrl init fail! (ret=%d)\n", __func__, ret);
34 goto out;
35 }
36
Kever Yang6d26c062016-08-16 17:58:13 +080037 ret = pinctrl_request_noflags(pinctrl, PERIPH_ID_PWM2);
38 if (ret) {
39 debug("%s PWM2 pinctrl init fail!\n", __func__);
40 goto out;
41 }
42
43 ret = pinctrl_request_noflags(pinctrl, PERIPH_ID_PWM3);
44 if (ret) {
45 debug("%s PWM3 pinctrl init fail!\n", __func__);
46 goto out;
47 }
48
Kever Yang9988df72017-04-12 12:00:06 +080049 ret = regulators_enable_boot_on(false);
Kever Yang11c21c52016-09-23 15:57:20 +080050 if (ret)
Kever Yang9988df72017-04-12 12:00:06 +080051 debug("%s: Cannot enable boot on regulator\n", __func__);
Kever Yang11c21c52016-09-23 15:57:20 +080052
Kever Yangb1395292016-08-24 12:02:22 +080053 ret = regulator_get_by_platname("vcc5v0_host", &regulator);
54 if (ret) {
55 debug("%s vcc5v0_host init fail! ret %d\n", __func__, ret);
56 goto out;
57 }
58
59 ret = regulator_set_enable(regulator, true);
60 if (ret) {
61 debug("%s vcc5v0-host-en set fail!\n", __func__);
62 goto out;
63 }
64
Kever Yang6d26c062016-08-16 17:58:13 +080065out:
Kever Yang0d3d7832016-07-19 21:16:59 +080066 return 0;
67}
Philipp Tomsich3df66262017-09-29 19:27:54 +020068
69void spl_board_init(void)
70{
71 struct udevice *pinctrl;
72 int ret;
73
74 ret = uclass_get_device(UCLASS_PINCTRL, 0, &pinctrl);
75 if (ret) {
76 debug("%s: Cannot find pinctrl device\n", __func__);
77 goto err;
78 }
79
80 /* Enable debug UART */
81 ret = pinctrl_request_noflags(pinctrl, PERIPH_ID_UART_DBG);
82 if (ret) {
83 debug("%s: Failed to set up console UART\n", __func__);
84 goto err;
85 }
86
87 preloader_console_init();
88 return;
89err:
90 printf("%s: Error %d\n", __func__, ret);
91
92 /* No way to report error here */
93 hang();
94}