blob: 68edd1ec2826841c74702fd8f16f8e98b7519a18 [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
Tom Rinidec7ea02024-05-20 13:35:03 -06006#include <config.h>
Simon Glassdc4d5e52015-08-03 08:19:27 -06007#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>
Simon Glass0f2af882020-05-10 11:40:05 -060011#include <log.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060012#include <asm/global_data.h>
Simon Glassdc4d5e52015-08-03 08:19:27 -060013#include <asm/io.h>
14#include <errno.h>
15#include <i2c.h>
16#include <mmc.h>
17#include <netdev.h>
18#include <samsung-usb-phy-uboot.h>
19#include <spi.h>
20#include <usb.h>
21#include <video_bridge.h>
22#include <asm/gpio.h>
23#include <asm/arch/cpu.h>
24#include <asm/arch/dwmmc.h>
25#include <asm/arch/mmc.h>
26#include <asm/arch/pinmux.h>
27#include <asm/arch/power.h>
28#include <asm/arch/sromc.h>
Simon Glassbdd5f812023-09-14 18:21:46 -060029#include <linux/printk.h>
Simon Glassdc4d5e52015-08-03 08:19:27 -060030#include <power/pmic.h>
31#include <power/max77686_pmic.h>
32#include <power/regulator.h>
Przemyslaw Marczaka6e12d32015-10-27 13:08:05 +010033#include <power/s2mps11.h>
Simon Glassdc4d5e52015-08-03 08:19:27 -060034#include <power/s5m8767.h>
Przemyslaw Marczaka6e12d32015-10-27 13:08:05 +010035#include <samsung/exynos5-dt-types.h>
36#include <samsung/misc.h>
Simon Glassdc4d5e52015-08-03 08:19:27 -060037#include <tmu.h>
38
39DECLARE_GLOBAL_DATA_PTR;
40
Simon Glassdc4d5e52015-08-03 08:19:27 -060041static int exynos_set_regulator(const char *name, uint uv)
42{
43 struct udevice *dev;
44 int ret;
45
46 ret = regulator_get_by_platname(name, &dev);
47 if (ret) {
48 debug("%s: Cannot find regulator %s\n", __func__, name);
49 return ret;
50 }
51 ret = regulator_set_value(dev, uv);
52 if (ret) {
53 debug("%s: Cannot set regulator %s\n", __func__, name);
54 return ret;
55 }
56
57 return 0;
58}
59
60int exynos_power_init(void)
61{
62 struct udevice *dev;
63 int ret;
64
Jaehoon Chunga47a6bb2018-01-29 13:53:19 +090065#ifdef CONFIG_PMIC_S2MPS11
Marek Szyprowskia436d702020-01-16 14:46:04 +010066 ret = pmic_get("s2mps11_pmic@66", &dev);
Jaehoon Chunga47a6bb2018-01-29 13:53:19 +090067#else
Marek Szyprowskia436d702020-01-16 14:46:04 +010068 ret = pmic_get("max77686_pmic@09", &dev);
Simon Glassdc4d5e52015-08-03 08:19:27 -060069 if (!ret) {
70 /* TODO(sjg@chromium.org): Move into the clock/pmic API */
71 ret = pmic_clrsetbits(dev, MAX77686_REG_PMIC_32KHZ, 0,
72 MAX77686_32KHCP_EN);
73 if (ret)
74 return ret;
75 ret = pmic_clrsetbits(dev, MAX77686_REG_PMIC_BBAT, 0,
76 MAX77686_BBCHOSTEN | MAX77686_BBCVS_3_5V);
77 if (ret)
78 return ret;
79 } else {
Marek Szyprowskia436d702020-01-16 14:46:04 +010080 ret = pmic_get("s5m8767_pmic@66", &dev);
Simon Glassdc4d5e52015-08-03 08:19:27 -060081 /* TODO(sjg@chromium.org): Use driver model to access clock */
82#ifdef CONFIG_PMIC_S5M8767
83 if (!ret)
84 s5m8767_enable_32khz_cp(dev);
85#endif
86 }
Jaehoon Chunga47a6bb2018-01-29 13:53:19 +090087#endif /* CONFIG_PMIC_S2MPS11 */
Simon Glassdc4d5e52015-08-03 08:19:27 -060088 if (ret == -ENODEV)
89 return 0;
90
Simon Glassdc4d5e52015-08-03 08:19:27 -060091 ret = exynos_set_regulator("vdd_mif", 1100000);
92 if (ret)
93 return ret;
94
Sjoerd Simons9526fc42017-01-10 12:28:57 +010095 ret = exynos_set_regulator("vdd_arm", 1300000);
Simon Glassdc4d5e52015-08-03 08:19:27 -060096 if (ret)
97 return ret;
98 ret = exynos_set_regulator("vdd_int", 1012500);
99 if (ret)
100 return ret;
101 ret = exynos_set_regulator("vdd_g3d", 1200000);
102 if (ret)
103 return ret;
104
105 return 0;
106}
107
108int board_get_revision(void)
109{
110 return 0;
111}
112
Simon Glassdc4d5e52015-08-03 08:19:27 -0600113#ifdef CONFIG_USB_DWC3
114static struct dwc3_device dwc3_device_data = {
115 .maximum_speed = USB_SPEED_SUPER,
116 .base = 0x12400000,
117 .dr_mode = USB_DR_MODE_PERIPHERAL,
118 .index = 0,
119};
120
Simon Glassdc4d5e52015-08-03 08:19:27 -0600121int board_usb_init(int index, enum usb_init_type init)
122{
123 struct exynos_usb3_phy *phy = (struct exynos_usb3_phy *)
124 samsung_get_base_usb3_phy();
125
126 if (!phy) {
Seung-Woo Kimca211662018-06-04 16:03:05 +0900127 pr_err("usb3 phy not supported\n");
Simon Glassdc4d5e52015-08-03 08:19:27 -0600128 return -ENODEV;
129 }
130
131 set_usbdrd_phy_ctrl(POWER_USB_DRD_PHY_CTRL_EN);
132 exynos5_usb3_phy_init(phy);
133
134 return dwc3_uboot_init(&dwc3_device_data);
135}
136#endif
137#ifdef CONFIG_SET_DFU_ALT_INFO
138char *get_dfu_alt_system(char *interface, char *devstr)
139{
Przemyslaw Marczaka6e12d32015-10-27 13:08:05 +0100140 char *info = "Not supported!";
141
Dirk Meul738805d2018-10-14 17:14:17 +0200142 if (board_is_odroidxu4() || board_is_odroidhc1() || board_is_odroidhc2())
Przemyslaw Marczaka6e12d32015-10-27 13:08:05 +0100143 return info;
144
Simon Glass64b723f2017-08-03 12:22:12 -0600145 return env_get("dfu_alt_system");
Simon Glassdc4d5e52015-08-03 08:19:27 -0600146}
147
148char *get_dfu_alt_boot(char *interface, char *devstr)
149{
Przemyslaw Marczaka6e12d32015-10-27 13:08:05 +0100150 char *info = "Not supported!";
Simon Glassdc4d5e52015-08-03 08:19:27 -0600151 struct mmc *mmc;
152 char *alt_boot;
153 int dev_num;
154
Dirk Meul738805d2018-10-14 17:14:17 +0200155 if (board_is_odroidxu4() || board_is_odroidhc1() || board_is_odroidhc2())
Przemyslaw Marczaka6e12d32015-10-27 13:08:05 +0100156 return info;
157
Simon Glassff9b9032021-07-24 09:03:30 -0600158 dev_num = dectoul(devstr, NULL);
Simon Glassdc4d5e52015-08-03 08:19:27 -0600159
160 mmc = find_mmc_device(dev_num);
161 if (!mmc)
162 return NULL;
163
164 if (mmc_init(mmc))
165 return NULL;
166
167 if (IS_SD(mmc))
Tom Rini3aef00d2022-12-04 10:03:38 -0500168 alt_boot = CFG_DFU_ALT_BOOT_SD;
Simon Glassdc4d5e52015-08-03 08:19:27 -0600169 else
Tom Rini3aef00d2022-12-04 10:03:38 -0500170 alt_boot = CFG_DFU_ALT_BOOT_EMMC;
Simon Glassdc4d5e52015-08-03 08:19:27 -0600171
172 return alt_boot;
173}
174#endif