blob: f63f003209a0ec381eedcf401e244434dfe7c745 [file] [log] [blame]
Kever Yang0d3d7832016-07-19 21:16:59 +08001/*
2 * (C) Copyright 2016 Rockchip Electronics Co., Ltd
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6#include <common.h>
Kever Yang6d26c062016-08-16 17:58:13 +08007#include <dm.h>
Kever Yangea61d142017-04-19 16:01:14 +08008#include <ram.h>
Kever Yang6d26c062016-08-16 17:58:13 +08009#include <dm/pinctrl.h>
Kever Yang11c21c52016-09-23 15:57:20 +080010#include <dm/uclass-internal.h>
Kever Yang6d26c062016-08-16 17:58:13 +080011#include <asm/arch/periph.h>
Kever Yangb1395292016-08-24 12:02:22 +080012#include <power/regulator.h>
Kever Yang0d3d7832016-07-19 21:16:59 +080013
14DECLARE_GLOBAL_DATA_PTR;
15
16int board_init(void)
17{
Kever Yangb1395292016-08-24 12:02:22 +080018 struct udevice *pinctrl, *regulator;
Kever Yang6d26c062016-08-16 17:58:13 +080019 int ret;
20
21 /*
22 * The PWM do not have decicated interrupt number in dts and can
23 * not get periph_id by pinctrl framework, so let's init them here.
24 * The PWM2 and PWM3 are for pwm regulater.
25 */
26 ret = uclass_get_device(UCLASS_PINCTRL, 0, &pinctrl);
27 if (ret) {
28 debug("%s: Cannot find pinctrl device\n", __func__);
29 goto out;
30 }
31
Eric Gao75058e22017-05-02 18:23:55 +080032 /* Enable pwm0 for panel backlight */
33 ret = pinctrl_request_noflags(pinctrl, PERIPH_ID_PWM0);
34 if (ret) {
35 debug("%s PWM0 pinctrl init fail! (ret=%d)\n", __func__, ret);
36 goto out;
37 }
38
Kever Yang6d26c062016-08-16 17:58:13 +080039 ret = pinctrl_request_noflags(pinctrl, PERIPH_ID_PWM2);
40 if (ret) {
41 debug("%s PWM2 pinctrl init fail!\n", __func__);
42 goto out;
43 }
44
45 ret = pinctrl_request_noflags(pinctrl, PERIPH_ID_PWM3);
46 if (ret) {
47 debug("%s PWM3 pinctrl init fail!\n", __func__);
48 goto out;
49 }
50
Kever Yang9988df72017-04-12 12:00:06 +080051 ret = regulators_enable_boot_on(false);
Kever Yang11c21c52016-09-23 15:57:20 +080052 if (ret)
Kever Yang9988df72017-04-12 12:00:06 +080053 debug("%s: Cannot enable boot on regulator\n", __func__);
Kever Yang11c21c52016-09-23 15:57:20 +080054
Kever Yangb1395292016-08-24 12:02:22 +080055 ret = regulator_get_by_platname("vcc5v0_host", &regulator);
56 if (ret) {
57 debug("%s vcc5v0_host init fail! ret %d\n", __func__, ret);
58 goto out;
59 }
60
61 ret = regulator_set_enable(regulator, true);
62 if (ret) {
63 debug("%s vcc5v0-host-en set fail!\n", __func__);
64 goto out;
65 }
66
Kever Yang6d26c062016-08-16 17:58:13 +080067out:
Kever Yang0d3d7832016-07-19 21:16:59 +080068 return 0;
69}
70
71int dram_init(void)
72{
Kever Yangea61d142017-04-19 16:01:14 +080073 struct ram_info ram;
74 struct udevice *dev;
75 int ret;
76
77 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
78 if (ret) {
79 debug("DRAM init failed: %d\n", ret);
80 return ret;
81 }
82 ret = ram_get_info(dev, &ram);
83 if (ret) {
84 debug("Cannot get DRAM size: %d\n", ret);
85 return ret;
86 }
87 debug("SDRAM base=%llx, size=%x\n", ram.base, (unsigned int)ram.size);
88 gd->ram_size = ram.size;
89
Kever Yang0d3d7832016-07-19 21:16:59 +080090 return 0;
91}
92
Simon Glass2f949c32017-03-31 08:40:32 -060093int dram_init_banksize(void)
Kever Yang0d3d7832016-07-19 21:16:59 +080094{
Kever Yange6181f52016-07-25 11:45:54 +080095 /* Reserve 0x200000 for ATF bl31 */
96 gd->bd->bi_dram[0].start = 0x200000;
Kever Yangb6eda402016-11-07 16:30:34 +080097 gd->bd->bi_dram[0].size = 0x7e000000;
Simon Glass2f949c32017-03-31 08:40:32 -060098
99 return 0;
Kever Yang0d3d7832016-07-19 21:16:59 +0800100}