blob: eef46b0dc447597e4fb8be2bcf12b8105d343a86 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glassdc4d5e52015-08-03 08:19:27 -06002/*
3 * Copyright (C) 2012 Samsung Electronics
Simon Glassdc4d5e52015-08-03 08:19:27 -06004 */
5
6#include <common.h>
7#include <dm.h>
8#include <dwc3-uboot.h>
Simon Glass0af6e2d2019-08-01 09:46:52 -06009#include <env.h>
Simon Glassdc4d5e52015-08-03 08:19:27 -060010#include <fdtdec.h>
11#include <asm/io.h>
12#include <errno.h>
13#include <i2c.h>
14#include <mmc.h>
15#include <netdev.h>
16#include <samsung-usb-phy-uboot.h>
17#include <spi.h>
18#include <usb.h>
19#include <video_bridge.h>
20#include <asm/gpio.h>
21#include <asm/arch/cpu.h>
22#include <asm/arch/dwmmc.h>
23#include <asm/arch/mmc.h>
24#include <asm/arch/pinmux.h>
25#include <asm/arch/power.h>
26#include <asm/arch/sromc.h>
27#include <power/pmic.h>
28#include <power/max77686_pmic.h>
29#include <power/regulator.h>
Przemyslaw Marczaka6e12d32015-10-27 13:08:05 +010030#include <power/s2mps11.h>
Simon Glassdc4d5e52015-08-03 08:19:27 -060031#include <power/s5m8767.h>
Przemyslaw Marczaka6e12d32015-10-27 13:08:05 +010032#include <samsung/exynos5-dt-types.h>
33#include <samsung/misc.h>
Simon Glassdc4d5e52015-08-03 08:19:27 -060034#include <tmu.h>
35
36DECLARE_GLOBAL_DATA_PTR;
37
Simon Glassdc4d5e52015-08-03 08:19:27 -060038int exynos_init(void)
39{
Simon Glassdc4d5e52015-08-03 08:19:27 -060040 return 0;
41}
42
43static int exynos_set_regulator(const char *name, uint uv)
44{
45 struct udevice *dev;
46 int ret;
47
48 ret = regulator_get_by_platname(name, &dev);
49 if (ret) {
50 debug("%s: Cannot find regulator %s\n", __func__, name);
51 return ret;
52 }
53 ret = regulator_set_value(dev, uv);
54 if (ret) {
55 debug("%s: Cannot set regulator %s\n", __func__, name);
56 return ret;
57 }
58
59 return 0;
60}
61
62int exynos_power_init(void)
63{
64 struct udevice *dev;
65 int ret;
66
Jaehoon Chunga47a6bb2018-01-29 13:53:19 +090067#ifdef CONFIG_PMIC_S2MPS11
Marek Szyprowskia436d702020-01-16 14:46:04 +010068 ret = pmic_get("s2mps11_pmic@66", &dev);
Jaehoon Chunga47a6bb2018-01-29 13:53:19 +090069#else
Marek Szyprowskia436d702020-01-16 14:46:04 +010070 ret = pmic_get("max77686_pmic@09", &dev);
Simon Glassdc4d5e52015-08-03 08:19:27 -060071 if (!ret) {
72 /* TODO(sjg@chromium.org): Move into the clock/pmic API */
73 ret = pmic_clrsetbits(dev, MAX77686_REG_PMIC_32KHZ, 0,
74 MAX77686_32KHCP_EN);
75 if (ret)
76 return ret;
77 ret = pmic_clrsetbits(dev, MAX77686_REG_PMIC_BBAT, 0,
78 MAX77686_BBCHOSTEN | MAX77686_BBCVS_3_5V);
79 if (ret)
80 return ret;
81 } else {
Marek Szyprowskia436d702020-01-16 14:46:04 +010082 ret = pmic_get("s5m8767_pmic@66", &dev);
Simon Glassdc4d5e52015-08-03 08:19:27 -060083 /* TODO(sjg@chromium.org): Use driver model to access clock */
84#ifdef CONFIG_PMIC_S5M8767
85 if (!ret)
86 s5m8767_enable_32khz_cp(dev);
87#endif
88 }
Jaehoon Chunga47a6bb2018-01-29 13:53:19 +090089#endif /* CONFIG_PMIC_S2MPS11 */
Simon Glassdc4d5e52015-08-03 08:19:27 -060090 if (ret == -ENODEV)
91 return 0;
92
93 ret = regulators_enable_boot_on(false);
94 if (ret)
95 return ret;
96
97 ret = exynos_set_regulator("vdd_mif", 1100000);
98 if (ret)
99 return ret;
100
Sjoerd Simons9526fc42017-01-10 12:28:57 +0100101 ret = exynos_set_regulator("vdd_arm", 1300000);
Simon Glassdc4d5e52015-08-03 08:19:27 -0600102 if (ret)
103 return ret;
104 ret = exynos_set_regulator("vdd_int", 1012500);
105 if (ret)
106 return ret;
107 ret = exynos_set_regulator("vdd_g3d", 1200000);
108 if (ret)
109 return ret;
110
111 return 0;
112}
113
114int board_get_revision(void)
115{
116 return 0;
117}
118
Simon Glassdc4d5e52015-08-03 08:19:27 -0600119#ifdef CONFIG_USB_DWC3
120static struct dwc3_device dwc3_device_data = {
121 .maximum_speed = USB_SPEED_SUPER,
122 .base = 0x12400000,
123 .dr_mode = USB_DR_MODE_PERIPHERAL,
124 .index = 0,
125};
126
127int usb_gadget_handle_interrupts(void)
128{
129 dwc3_uboot_handle_interrupt(0);
130 return 0;
131}
132
133int board_usb_init(int index, enum usb_init_type init)
134{
135 struct exynos_usb3_phy *phy = (struct exynos_usb3_phy *)
136 samsung_get_base_usb3_phy();
137
138 if (!phy) {
Seung-Woo Kimca211662018-06-04 16:03:05 +0900139 pr_err("usb3 phy not supported\n");
Simon Glassdc4d5e52015-08-03 08:19:27 -0600140 return -ENODEV;
141 }
142
143 set_usbdrd_phy_ctrl(POWER_USB_DRD_PHY_CTRL_EN);
144 exynos5_usb3_phy_init(phy);
145
146 return dwc3_uboot_init(&dwc3_device_data);
147}
148#endif
149#ifdef CONFIG_SET_DFU_ALT_INFO
150char *get_dfu_alt_system(char *interface, char *devstr)
151{
Przemyslaw Marczaka6e12d32015-10-27 13:08:05 +0100152 char *info = "Not supported!";
153
Dirk Meul738805d2018-10-14 17:14:17 +0200154 if (board_is_odroidxu4() || board_is_odroidhc1() || board_is_odroidhc2())
Przemyslaw Marczaka6e12d32015-10-27 13:08:05 +0100155 return info;
156
Simon Glass64b723f2017-08-03 12:22:12 -0600157 return env_get("dfu_alt_system");
Simon Glassdc4d5e52015-08-03 08:19:27 -0600158}
159
160char *get_dfu_alt_boot(char *interface, char *devstr)
161{
Przemyslaw Marczaka6e12d32015-10-27 13:08:05 +0100162 char *info = "Not supported!";
Simon Glassdc4d5e52015-08-03 08:19:27 -0600163 struct mmc *mmc;
164 char *alt_boot;
165 int dev_num;
166
Dirk Meul738805d2018-10-14 17:14:17 +0200167 if (board_is_odroidxu4() || board_is_odroidhc1() || board_is_odroidhc2())
Przemyslaw Marczaka6e12d32015-10-27 13:08:05 +0100168 return info;
169
Simon Glassdc4d5e52015-08-03 08:19:27 -0600170 dev_num = simple_strtoul(devstr, NULL, 10);
171
172 mmc = find_mmc_device(dev_num);
173 if (!mmc)
174 return NULL;
175
176 if (mmc_init(mmc))
177 return NULL;
178
179 if (IS_SD(mmc))
180 alt_boot = CONFIG_DFU_ALT_BOOT_SD;
181 else
182 alt_boot = CONFIG_DFU_ALT_BOOT_EMMC;
183
184 return alt_boot;
185}
186#endif