Kever Yang | 0d3d783 | 2016-07-19 21:16:59 +0800 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2016 Rockchip Electronics Co., Ltd |
| 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 5 | */ |
Philipp Tomsich | 3df6626 | 2017-09-29 19:27:54 +0200 | [diff] [blame] | 6 | |
Kever Yang | 0d3d783 | 2016-07-19 21:16:59 +0800 | [diff] [blame] | 7 | #include <common.h> |
Kever Yang | 6d26c06 | 2016-08-16 17:58:13 +0800 | [diff] [blame] | 8 | #include <dm.h> |
| 9 | #include <dm/pinctrl.h> |
Kever Yang | 11c21c5 | 2016-09-23 15:57:20 +0800 | [diff] [blame] | 10 | #include <dm/uclass-internal.h> |
Kever Yang | 6d26c06 | 2016-08-16 17:58:13 +0800 | [diff] [blame] | 11 | #include <asm/arch/periph.h> |
Kever Yang | b139529 | 2016-08-24 12:02:22 +0800 | [diff] [blame] | 12 | #include <power/regulator.h> |
Philipp Tomsich | 3df6626 | 2017-09-29 19:27:54 +0200 | [diff] [blame] | 13 | #include <spl.h> |
Kever Yang | 0d3d783 | 2016-07-19 21:16:59 +0800 | [diff] [blame] | 14 | |
| 15 | DECLARE_GLOBAL_DATA_PTR; |
| 16 | |
| 17 | int board_init(void) |
| 18 | { |
Kever Yang | b139529 | 2016-08-24 12:02:22 +0800 | [diff] [blame] | 19 | struct udevice *pinctrl, *regulator; |
Kever Yang | 6d26c06 | 2016-08-16 17:58:13 +0800 | [diff] [blame] | 20 | int ret; |
| 21 | |
| 22 | /* |
| 23 | * The PWM do not have decicated interrupt number in dts and can |
| 24 | * not get periph_id by pinctrl framework, so let's init them here. |
| 25 | * The PWM2 and PWM3 are for pwm regulater. |
| 26 | */ |
| 27 | ret = uclass_get_device(UCLASS_PINCTRL, 0, &pinctrl); |
| 28 | if (ret) { |
| 29 | debug("%s: Cannot find pinctrl device\n", __func__); |
| 30 | goto out; |
| 31 | } |
| 32 | |
Eric Gao | 75058e2 | 2017-05-02 18:23:55 +0800 | [diff] [blame] | 33 | /* Enable pwm0 for panel backlight */ |
| 34 | ret = pinctrl_request_noflags(pinctrl, PERIPH_ID_PWM0); |
| 35 | if (ret) { |
| 36 | debug("%s PWM0 pinctrl init fail! (ret=%d)\n", __func__, ret); |
| 37 | goto out; |
| 38 | } |
| 39 | |
Kever Yang | 6d26c06 | 2016-08-16 17:58:13 +0800 | [diff] [blame] | 40 | ret = pinctrl_request_noflags(pinctrl, PERIPH_ID_PWM2); |
| 41 | if (ret) { |
| 42 | debug("%s PWM2 pinctrl init fail!\n", __func__); |
| 43 | goto out; |
| 44 | } |
| 45 | |
| 46 | ret = pinctrl_request_noflags(pinctrl, PERIPH_ID_PWM3); |
| 47 | if (ret) { |
| 48 | debug("%s PWM3 pinctrl init fail!\n", __func__); |
| 49 | goto out; |
| 50 | } |
| 51 | |
Kever Yang | 9988df7 | 2017-04-12 12:00:06 +0800 | [diff] [blame] | 52 | ret = regulators_enable_boot_on(false); |
Kever Yang | 11c21c5 | 2016-09-23 15:57:20 +0800 | [diff] [blame] | 53 | if (ret) |
Kever Yang | 9988df7 | 2017-04-12 12:00:06 +0800 | [diff] [blame] | 54 | debug("%s: Cannot enable boot on regulator\n", __func__); |
Kever Yang | 11c21c5 | 2016-09-23 15:57:20 +0800 | [diff] [blame] | 55 | |
Kever Yang | b139529 | 2016-08-24 12:02:22 +0800 | [diff] [blame] | 56 | ret = regulator_get_by_platname("vcc5v0_host", ®ulator); |
| 57 | if (ret) { |
| 58 | debug("%s vcc5v0_host init fail! ret %d\n", __func__, ret); |
| 59 | goto out; |
| 60 | } |
| 61 | |
| 62 | ret = regulator_set_enable(regulator, true); |
| 63 | if (ret) { |
| 64 | debug("%s vcc5v0-host-en set fail!\n", __func__); |
| 65 | goto out; |
| 66 | } |
| 67 | |
Kever Yang | 6d26c06 | 2016-08-16 17:58:13 +0800 | [diff] [blame] | 68 | out: |
Kever Yang | 0d3d783 | 2016-07-19 21:16:59 +0800 | [diff] [blame] | 69 | return 0; |
| 70 | } |
Philipp Tomsich | 3df6626 | 2017-09-29 19:27:54 +0200 | [diff] [blame] | 71 | |
| 72 | void spl_board_init(void) |
| 73 | { |
| 74 | struct udevice *pinctrl; |
| 75 | int ret; |
| 76 | |
| 77 | ret = uclass_get_device(UCLASS_PINCTRL, 0, &pinctrl); |
| 78 | if (ret) { |
| 79 | debug("%s: Cannot find pinctrl device\n", __func__); |
| 80 | goto err; |
| 81 | } |
| 82 | |
| 83 | /* Enable debug UART */ |
| 84 | ret = pinctrl_request_noflags(pinctrl, PERIPH_ID_UART_DBG); |
| 85 | if (ret) { |
| 86 | debug("%s: Failed to set up console UART\n", __func__); |
| 87 | goto err; |
| 88 | } |
| 89 | |
| 90 | preloader_console_init(); |
| 91 | return; |
| 92 | err: |
| 93 | printf("%s: Error %d\n", __func__, ret); |
| 94 | |
| 95 | /* No way to report error here */ |
| 96 | hang(); |
| 97 | } |