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