Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Kever Yang | 0d3d783 | 2016-07-19 21:16:59 +0800 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2016 Rockchip Electronics Co., Ltd |
Kever Yang | 0d3d783 | 2016-07-19 21:16:59 +0800 | [diff] [blame] | 4 | */ |
Philipp Tomsich | 3df6626 | 2017-09-29 19:27:54 +0200 | [diff] [blame] | 5 | |
Kever Yang | 0d3d783 | 2016-07-19 21:16:59 +0800 | [diff] [blame] | 6 | #include <common.h> |
Kever Yang | 6d26c06 | 2016-08-16 17:58:13 +0800 | [diff] [blame] | 7 | #include <dm.h> |
| 8 | #include <dm/pinctrl.h> |
Kever Yang | 11c21c5 | 2016-09-23 15:57:20 +0800 | [diff] [blame] | 9 | #include <dm/uclass-internal.h> |
Kever Yang | 6d26c06 | 2016-08-16 17:58:13 +0800 | [diff] [blame] | 10 | #include <asm/arch/periph.h> |
Kever Yang | b139529 | 2016-08-24 12:02:22 +0800 | [diff] [blame] | 11 | #include <power/regulator.h> |
Philipp Tomsich | 3df6626 | 2017-09-29 19:27:54 +0200 | [diff] [blame] | 12 | #include <spl.h> |
Kever Yang | 0d3d783 | 2016-07-19 21:16:59 +0800 | [diff] [blame] | 13 | |
Kever Yang | 0d3d783 | 2016-07-19 21:16:59 +0800 | [diff] [blame] | 14 | int board_init(void) |
| 15 | { |
Kever Yang | b139529 | 2016-08-24 12:02:22 +0800 | [diff] [blame] | 16 | struct udevice *pinctrl, *regulator; |
Kever Yang | 6d26c06 | 2016-08-16 17:58:13 +0800 | [diff] [blame] | 17 | 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 Gao | 75058e2 | 2017-05-02 18:23:55 +0800 | [diff] [blame] | 30 | /* 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 Yang | 6d26c06 | 2016-08-16 17:58:13 +0800 | [diff] [blame] | 37 | 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 Yang | 9988df7 | 2017-04-12 12:00:06 +0800 | [diff] [blame] | 49 | ret = regulators_enable_boot_on(false); |
Kever Yang | 11c21c5 | 2016-09-23 15:57:20 +0800 | [diff] [blame] | 50 | if (ret) |
Kever Yang | 9988df7 | 2017-04-12 12:00:06 +0800 | [diff] [blame] | 51 | debug("%s: Cannot enable boot on regulator\n", __func__); |
Kever Yang | 11c21c5 | 2016-09-23 15:57:20 +0800 | [diff] [blame] | 52 | |
Kever Yang | b139529 | 2016-08-24 12:02:22 +0800 | [diff] [blame] | 53 | ret = regulator_get_by_platname("vcc5v0_host", ®ulator); |
| 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 Yang | 6d26c06 | 2016-08-16 17:58:13 +0800 | [diff] [blame] | 65 | out: |
Kever Yang | 0d3d783 | 2016-07-19 21:16:59 +0800 | [diff] [blame] | 66 | return 0; |
| 67 | } |
Philipp Tomsich | 3df6626 | 2017-09-29 19:27:54 +0200 | [diff] [blame] | 68 | |
| 69 | void 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; |
| 89 | err: |
| 90 | printf("%s: Error %d\n", __func__, ret); |
| 91 | |
| 92 | /* No way to report error here */ |
| 93 | hang(); |
| 94 | } |