blob: 69aa2120e126f517c84820288f5601a142ede1b4 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glassc65dc7d2015-08-03 08:19:27 -06002/*
3 * Copyright (C) 2012 Samsung Electronics
Simon Glassc65dc7d2015-08-03 08:19:27 -06004 */
5
6#include <common.h>
7#include <dm.h>
8#include <dwc3-uboot.h>
Simon Glass7b51b572019-08-01 09:46:52 -06009#include <env.h>
Simon Glassc65dc7d2015-08-03 08:19:27 -060010#include <fdtdec.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060011#include <log.h>
Simon Glassc65dc7d2015-08-03 08:19:27 -060012#include <asm/io.h>
13#include <errno.h>
14#include <i2c.h>
15#include <mmc.h>
16#include <netdev.h>
17#include <samsung-usb-phy-uboot.h>
18#include <spi.h>
19#include <usb.h>
20#include <video_bridge.h>
21#include <asm/gpio.h>
22#include <asm/arch/cpu.h>
23#include <asm/arch/dwmmc.h>
24#include <asm/arch/mmc.h>
25#include <asm/arch/pinmux.h>
26#include <asm/arch/power.h>
27#include <asm/arch/sromc.h>
28#include <power/pmic.h>
29#include <power/max77686_pmic.h>
30#include <power/regulator.h>
Przemyslaw Marczak1611c8c2015-10-27 13:08:05 +010031#include <power/s2mps11.h>
Simon Glassc65dc7d2015-08-03 08:19:27 -060032#include <power/s5m8767.h>
Przemyslaw Marczak1611c8c2015-10-27 13:08:05 +010033#include <samsung/exynos5-dt-types.h>
34#include <samsung/misc.h>
Simon Glassc65dc7d2015-08-03 08:19:27 -060035#include <tmu.h>
36
37DECLARE_GLOBAL_DATA_PTR;
38
Simon Glassc65dc7d2015-08-03 08:19:27 -060039int exynos_init(void)
40{
Simon Glassc65dc7d2015-08-03 08:19:27 -060041 return 0;
42}
43
44static int exynos_set_regulator(const char *name, uint uv)
45{
46 struct udevice *dev;
47 int ret;
48
49 ret = regulator_get_by_platname(name, &dev);
50 if (ret) {
51 debug("%s: Cannot find regulator %s\n", __func__, name);
52 return ret;
53 }
54 ret = regulator_set_value(dev, uv);
55 if (ret) {
56 debug("%s: Cannot set regulator %s\n", __func__, name);
57 return ret;
58 }
59
60 return 0;
61}
62
63int exynos_power_init(void)
64{
65 struct udevice *dev;
66 int ret;
67
Jaehoon Chung4f0a8bf2018-01-29 13:53:19 +090068#ifdef CONFIG_PMIC_S2MPS11
Marek Szyprowski4b8984e2020-01-16 14:46:04 +010069 ret = pmic_get("s2mps11_pmic@66", &dev);
Jaehoon Chung4f0a8bf2018-01-29 13:53:19 +090070#else
Marek Szyprowski4b8984e2020-01-16 14:46:04 +010071 ret = pmic_get("max77686_pmic@09", &dev);
Simon Glassc65dc7d2015-08-03 08:19:27 -060072 if (!ret) {
73 /* TODO(sjg@chromium.org): Move into the clock/pmic API */
74 ret = pmic_clrsetbits(dev, MAX77686_REG_PMIC_32KHZ, 0,
75 MAX77686_32KHCP_EN);
76 if (ret)
77 return ret;
78 ret = pmic_clrsetbits(dev, MAX77686_REG_PMIC_BBAT, 0,
79 MAX77686_BBCHOSTEN | MAX77686_BBCVS_3_5V);
80 if (ret)
81 return ret;
82 } else {
Marek Szyprowski4b8984e2020-01-16 14:46:04 +010083 ret = pmic_get("s5m8767_pmic@66", &dev);
Simon Glassc65dc7d2015-08-03 08:19:27 -060084 /* TODO(sjg@chromium.org): Use driver model to access clock */
85#ifdef CONFIG_PMIC_S5M8767
86 if (!ret)
87 s5m8767_enable_32khz_cp(dev);
88#endif
89 }
Jaehoon Chung4f0a8bf2018-01-29 13:53:19 +090090#endif /* CONFIG_PMIC_S2MPS11 */
Simon Glassc65dc7d2015-08-03 08:19:27 -060091 if (ret == -ENODEV)
92 return 0;
93
94 ret = regulators_enable_boot_on(false);
95 if (ret)
96 return ret;
97
98 ret = exynos_set_regulator("vdd_mif", 1100000);
99 if (ret)
100 return ret;
101
Sjoerd Simons701e7402017-01-10 12:28:57 +0100102 ret = exynos_set_regulator("vdd_arm", 1300000);
Simon Glassc65dc7d2015-08-03 08:19:27 -0600103 if (ret)
104 return ret;
105 ret = exynos_set_regulator("vdd_int", 1012500);
106 if (ret)
107 return ret;
108 ret = exynos_set_regulator("vdd_g3d", 1200000);
109 if (ret)
110 return ret;
111
112 return 0;
113}
114
115int board_get_revision(void)
116{
117 return 0;
118}
119
Simon Glassc65dc7d2015-08-03 08:19:27 -0600120#ifdef CONFIG_USB_DWC3
121static struct dwc3_device dwc3_device_data = {
122 .maximum_speed = USB_SPEED_SUPER,
123 .base = 0x12400000,
124 .dr_mode = USB_DR_MODE_PERIPHERAL,
125 .index = 0,
126};
127
128int usb_gadget_handle_interrupts(void)
129{
130 dwc3_uboot_handle_interrupt(0);
131 return 0;
132}
133
134int board_usb_init(int index, enum usb_init_type init)
135{
136 struct exynos_usb3_phy *phy = (struct exynos_usb3_phy *)
137 samsung_get_base_usb3_phy();
138
139 if (!phy) {
Seung-Woo Kim5c890b12018-06-04 16:03:05 +0900140 pr_err("usb3 phy not supported\n");
Simon Glassc65dc7d2015-08-03 08:19:27 -0600141 return -ENODEV;
142 }
143
144 set_usbdrd_phy_ctrl(POWER_USB_DRD_PHY_CTRL_EN);
145 exynos5_usb3_phy_init(phy);
146
147 return dwc3_uboot_init(&dwc3_device_data);
148}
149#endif
150#ifdef CONFIG_SET_DFU_ALT_INFO
151char *get_dfu_alt_system(char *interface, char *devstr)
152{
Przemyslaw Marczak1611c8c2015-10-27 13:08:05 +0100153 char *info = "Not supported!";
154
Dirk Meul9cd97c52018-10-14 17:14:17 +0200155 if (board_is_odroidxu4() || board_is_odroidhc1() || board_is_odroidhc2())
Przemyslaw Marczak1611c8c2015-10-27 13:08:05 +0100156 return info;
157
Simon Glass00caae62017-08-03 12:22:12 -0600158 return env_get("dfu_alt_system");
Simon Glassc65dc7d2015-08-03 08:19:27 -0600159}
160
161char *get_dfu_alt_boot(char *interface, char *devstr)
162{
Przemyslaw Marczak1611c8c2015-10-27 13:08:05 +0100163 char *info = "Not supported!";
Simon Glassc65dc7d2015-08-03 08:19:27 -0600164 struct mmc *mmc;
165 char *alt_boot;
166 int dev_num;
167
Dirk Meul9cd97c52018-10-14 17:14:17 +0200168 if (board_is_odroidxu4() || board_is_odroidhc1() || board_is_odroidhc2())
Przemyslaw Marczak1611c8c2015-10-27 13:08:05 +0100169 return info;
170
Simon Glassc65dc7d2015-08-03 08:19:27 -0600171 dev_num = simple_strtoul(devstr, NULL, 10);
172
173 mmc = find_mmc_device(dev_num);
174 if (!mmc)
175 return NULL;
176
177 if (mmc_init(mmc))
178 return NULL;
179
180 if (IS_SD(mmc))
181 alt_boot = CONFIG_DFU_ALT_BOOT_SD;
182 else
183 alt_boot = CONFIG_DFU_ALT_BOOT_EMMC;
184
185 return alt_boot;
186}
187#endif