2 * Copyright (C) 2012 Samsung Electronics
4 * SPDX-License-Identifier: GPL-2.0+
9 #include <dwc3-uboot.h>
16 #include <samsung-usb-phy-uboot.h>
19 #include <video_bridge.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>
30 #include <power/s5m8767.h>
33 DECLARE_GLOBAL_DATA_PTR;
35 static void board_enable_audio_codec(void)
38 struct gpio_desc en_gpio;
40 node = fdtdec_next_compatible(gd->fdt_blob, 0,
41 COMPAT_SAMSUNG_EXYNOS5_SOUND);
45 ret = gpio_request_by_name_nodev(gd->fdt_blob, node,
46 "codec-enable-gpio", 0, &en_gpio,
47 GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
48 if (ret == -FDT_ERR_NOTFOUND)
51 /* Turn on the GPIO which connects to the codec's "enable" line. */
52 gpio_set_pull(gpio_get_number(&en_gpio), S5P_GPIO_PULL_NONE);
54 #ifdef CONFIG_SOUND_MAX98095
55 /* Enable MAX98095 Codec */
56 gpio_request(EXYNOS5_GPIO_X17, "max98095_enable");
57 gpio_direction_output(EXYNOS5_GPIO_X17, 1);
58 gpio_set_pull(EXYNOS5_GPIO_X17, S5P_GPIO_PULL_NONE);
64 board_enable_audio_codec();
69 static int exynos_set_regulator(const char *name, uint uv)
74 ret = regulator_get_by_platname(name, &dev);
76 debug("%s: Cannot find regulator %s\n", __func__, name);
79 ret = regulator_set_value(dev, uv);
81 debug("%s: Cannot set regulator %s\n", __func__, name);
88 int exynos_power_init(void)
93 ret = pmic_get("max77686", &dev);
96 ret = pmic_clrsetbits(dev, MAX77686_REG_PMIC_32KHZ, 0,
100 ret = pmic_clrsetbits(dev, MAX77686_REG_PMIC_BBAT, 0,
101 MAX77686_BBCHOSTEN | MAX77686_BBCVS_3_5V);
105 ret = pmic_get("s5m8767-pmic", &dev);
107 #ifdef CONFIG_PMIC_S5M8767
109 s5m8767_enable_32khz_cp(dev);
115 ret = regulators_enable_boot_on(false);
119 ret = exynos_set_regulator("vdd_mif", 1100000);
124 * This would normally be 1.3V, but since we are running slowly 1V
125 * is enough. For spring it helps reduce CPU temperature and avoid
126 * hangs with the case open.
128 ret = exynos_set_regulator("vdd_arm", 1000000);
131 ret = exynos_set_regulator("vdd_int", 1012500);
134 ret = exynos_set_regulator("vdd_g3d", 1200000);
141 int board_get_revision(void)
148 static int board_dp_bridge_init(struct udevice *dev)
150 const int max_tries = 10;
154 debug("%s\n", __func__);
155 ret = video_bridge_attach(dev);
157 debug("video bridge init failed: %d\n", ret);
162 * We need to wait for 90ms after bringing up the bridge since there
163 * is a phantom "high" on the HPD chip during its bootup. The phantom
164 * high comes within 7ms of de-asserting PD and persists for at least
165 * 15ms. The real high comes roughly 50ms after PD is de-asserted. The
166 * phantom high makes it hard for us to know when the NXP chip is up.
170 for (num_tries = 0; num_tries < max_tries; num_tries++) {
171 /* Check HPD. If it's high, or we don't have it, all is well */
172 ret = video_bridge_check_attached(dev);
173 if (!ret || ret == -ENOENT)
176 debug("%s: eDP bridge failed to come up; try %d of %d\n",
177 __func__, num_tries, max_tries);
180 /* Immediately go into bridge reset if the hp line is not high */
184 static int board_dp_bridge_setup(const void *blob)
186 const int max_tries = 2;
191 /* Configure I2C registers for Parade bridge */
192 ret = uclass_get_device(UCLASS_VIDEO_BRIDGE, 0, &dev);
194 debug("video bridge init failed: %d\n", ret);
198 if (strncmp(dev->driver->name, "parade", 6)) {
199 /* Mux HPHPD to the special hotplug detect mode */
200 exynos_pinmux_config(PERIPH_ID_DPHPD, 0);
203 for (num_tries = 0; num_tries < max_tries; num_tries++) {
204 ret = board_dp_bridge_init(dev);
207 if (num_tries == max_tries - 1)
211 * If we're here, the bridge chip failed to initialise.
212 * Power down the bridge in an attempt to reset.
214 video_bridge_set_active(dev, false);
217 * Arbitrarily wait 300ms here with DP_N low. Don't know for
218 * sure how long we should wait, but we're being paranoid.
226 void exynos_cfg_lcd_gpio(void)
229 gpio_request(EXYNOS5_GPIO_B20, "lcd_backlight");
230 gpio_cfg_pin(EXYNOS5_GPIO_B20, S5P_GPIO_OUTPUT);
231 gpio_set_value(EXYNOS5_GPIO_B20, 1);
234 void exynos_set_dp_phy(unsigned int onoff)
236 set_dp_phy_ctrl(onoff);
239 static int board_dp_set_backlight(int percent)
244 ret = uclass_get_device(UCLASS_VIDEO_BRIDGE, 0, &dev);
246 ret = video_bridge_set_backlight(dev, percent);
251 void exynos_backlight_on(unsigned int on)
256 debug("%s(%u)\n", __func__, on);
260 ret = regulator_get_by_platname("vcd_led", &dev);
262 ret = regulator_set_enable(dev, true);
264 debug("Failed to enable backlight: ret=%d\n", ret);
266 /* T5 in the LCD timing spec (defined as > 10ms) */
269 /* board_dp_backlight_pwm */
270 gpio_direction_output(EXYNOS5_GPIO_B20, 1);
272 /* T6 in the LCD timing spec (defined as > 10ms) */
275 /* try to set the backlight in the bridge registers */
276 ret = board_dp_set_backlight(80);
278 /* if we have no bridge or it does not support backlight, use a GPIO */
279 if (ret == -ENODEV || ret == -ENOSYS) {
280 gpio_request(EXYNOS5_GPIO_X30, "board_dp_backlight_en");
281 gpio_direction_output(EXYNOS5_GPIO_X30, 1);
285 void exynos_lcd_power_on(void)
290 debug("%s\n", __func__);
291 ret = regulator_get_by_platname("lcd_vdd", &dev);
293 ret = regulator_set_enable(dev, true);
295 debug("Failed to enable LCD panel: ret=%d\n", ret);
297 ret = board_dp_bridge_setup(gd->fdt_blob);
298 if (ret && ret != -ENODEV)
299 printf("LCD bridge failed to enable: %d\n", ret);
304 #ifdef CONFIG_USB_DWC3
305 static struct dwc3_device dwc3_device_data = {
306 .maximum_speed = USB_SPEED_SUPER,
308 .dr_mode = USB_DR_MODE_PERIPHERAL,
312 int usb_gadget_handle_interrupts(void)
314 dwc3_uboot_handle_interrupt(0);
318 int board_usb_init(int index, enum usb_init_type init)
320 struct exynos_usb3_phy *phy = (struct exynos_usb3_phy *)
321 samsung_get_base_usb3_phy();
324 error("usb3 phy not supported");
328 set_usbdrd_phy_ctrl(POWER_USB_DRD_PHY_CTRL_EN);
329 exynos5_usb3_phy_init(phy);
331 return dwc3_uboot_init(&dwc3_device_data);
334 #ifdef CONFIG_SET_DFU_ALT_INFO
335 char *get_dfu_alt_system(char *interface, char *devstr)
337 return getenv("dfu_alt_system");
340 char *get_dfu_alt_boot(char *interface, char *devstr)
346 dev_num = simple_strtoul(devstr, NULL, 10);
348 mmc = find_mmc_device(dev_num);
356 alt_boot = CONFIG_DFU_ALT_BOOT_SD;
358 alt_boot = CONFIG_DFU_ALT_BOOT_EMMC;