Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | dc4d5e5 | 2015-08-03 08:19:27 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2012 Samsung Electronics |
Simon Glass | dc4d5e5 | 2015-08-03 08:19:27 -0600 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <dm.h> |
| 8 | #include <dwc3-uboot.h> |
Simon Glass | 0af6e2d | 2019-08-01 09:46:52 -0600 | [diff] [blame] | 9 | #include <env.h> |
Simon Glass | dc4d5e5 | 2015-08-03 08:19:27 -0600 | [diff] [blame] | 10 | #include <fdtdec.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 11 | #include <log.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 12 | #include <asm/global_data.h> |
Simon Glass | dc4d5e5 | 2015-08-03 08:19:27 -0600 | [diff] [blame] | 13 | #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> |
| 29 | #include <power/pmic.h> |
| 30 | #include <power/max77686_pmic.h> |
| 31 | #include <power/regulator.h> |
Przemyslaw Marczak | a6e12d3 | 2015-10-27 13:08:05 +0100 | [diff] [blame] | 32 | #include <power/s2mps11.h> |
Simon Glass | dc4d5e5 | 2015-08-03 08:19:27 -0600 | [diff] [blame] | 33 | #include <power/s5m8767.h> |
Przemyslaw Marczak | a6e12d3 | 2015-10-27 13:08:05 +0100 | [diff] [blame] | 34 | #include <samsung/exynos5-dt-types.h> |
| 35 | #include <samsung/misc.h> |
Simon Glass | dc4d5e5 | 2015-08-03 08:19:27 -0600 | [diff] [blame] | 36 | #include <tmu.h> |
| 37 | |
| 38 | DECLARE_GLOBAL_DATA_PTR; |
| 39 | |
Simon Glass | dc4d5e5 | 2015-08-03 08:19:27 -0600 | [diff] [blame] | 40 | int exynos_init(void) |
| 41 | { |
Simon Glass | dc4d5e5 | 2015-08-03 08:19:27 -0600 | [diff] [blame] | 42 | return 0; |
| 43 | } |
| 44 | |
| 45 | static int exynos_set_regulator(const char *name, uint uv) |
| 46 | { |
| 47 | struct udevice *dev; |
| 48 | int ret; |
| 49 | |
| 50 | ret = regulator_get_by_platname(name, &dev); |
| 51 | if (ret) { |
| 52 | debug("%s: Cannot find regulator %s\n", __func__, name); |
| 53 | return ret; |
| 54 | } |
| 55 | ret = regulator_set_value(dev, uv); |
| 56 | if (ret) { |
| 57 | debug("%s: Cannot set regulator %s\n", __func__, name); |
| 58 | return ret; |
| 59 | } |
| 60 | |
| 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | int exynos_power_init(void) |
| 65 | { |
| 66 | struct udevice *dev; |
| 67 | int ret; |
| 68 | |
Jaehoon Chung | a47a6bb | 2018-01-29 13:53:19 +0900 | [diff] [blame] | 69 | #ifdef CONFIG_PMIC_S2MPS11 |
Marek Szyprowski | a436d70 | 2020-01-16 14:46:04 +0100 | [diff] [blame] | 70 | ret = pmic_get("s2mps11_pmic@66", &dev); |
Jaehoon Chung | a47a6bb | 2018-01-29 13:53:19 +0900 | [diff] [blame] | 71 | #else |
Marek Szyprowski | a436d70 | 2020-01-16 14:46:04 +0100 | [diff] [blame] | 72 | ret = pmic_get("max77686_pmic@09", &dev); |
Simon Glass | dc4d5e5 | 2015-08-03 08:19:27 -0600 | [diff] [blame] | 73 | if (!ret) { |
| 74 | /* TODO(sjg@chromium.org): Move into the clock/pmic API */ |
| 75 | ret = pmic_clrsetbits(dev, MAX77686_REG_PMIC_32KHZ, 0, |
| 76 | MAX77686_32KHCP_EN); |
| 77 | if (ret) |
| 78 | return ret; |
| 79 | ret = pmic_clrsetbits(dev, MAX77686_REG_PMIC_BBAT, 0, |
| 80 | MAX77686_BBCHOSTEN | MAX77686_BBCVS_3_5V); |
| 81 | if (ret) |
| 82 | return ret; |
| 83 | } else { |
Marek Szyprowski | a436d70 | 2020-01-16 14:46:04 +0100 | [diff] [blame] | 84 | ret = pmic_get("s5m8767_pmic@66", &dev); |
Simon Glass | dc4d5e5 | 2015-08-03 08:19:27 -0600 | [diff] [blame] | 85 | /* TODO(sjg@chromium.org): Use driver model to access clock */ |
| 86 | #ifdef CONFIG_PMIC_S5M8767 |
| 87 | if (!ret) |
| 88 | s5m8767_enable_32khz_cp(dev); |
| 89 | #endif |
| 90 | } |
Jaehoon Chung | a47a6bb | 2018-01-29 13:53:19 +0900 | [diff] [blame] | 91 | #endif /* CONFIG_PMIC_S2MPS11 */ |
Simon Glass | dc4d5e5 | 2015-08-03 08:19:27 -0600 | [diff] [blame] | 92 | if (ret == -ENODEV) |
| 93 | return 0; |
| 94 | |
| 95 | ret = regulators_enable_boot_on(false); |
| 96 | if (ret) |
| 97 | return ret; |
| 98 | |
| 99 | ret = exynos_set_regulator("vdd_mif", 1100000); |
| 100 | if (ret) |
| 101 | return ret; |
| 102 | |
Sjoerd Simons | 9526fc4 | 2017-01-10 12:28:57 +0100 | [diff] [blame] | 103 | ret = exynos_set_regulator("vdd_arm", 1300000); |
Simon Glass | dc4d5e5 | 2015-08-03 08:19:27 -0600 | [diff] [blame] | 104 | if (ret) |
| 105 | return ret; |
| 106 | ret = exynos_set_regulator("vdd_int", 1012500); |
| 107 | if (ret) |
| 108 | return ret; |
| 109 | ret = exynos_set_regulator("vdd_g3d", 1200000); |
| 110 | if (ret) |
| 111 | return ret; |
| 112 | |
| 113 | return 0; |
| 114 | } |
| 115 | |
| 116 | int board_get_revision(void) |
| 117 | { |
| 118 | return 0; |
| 119 | } |
| 120 | |
Simon Glass | dc4d5e5 | 2015-08-03 08:19:27 -0600 | [diff] [blame] | 121 | #ifdef CONFIG_USB_DWC3 |
| 122 | static struct dwc3_device dwc3_device_data = { |
| 123 | .maximum_speed = USB_SPEED_SUPER, |
| 124 | .base = 0x12400000, |
| 125 | .dr_mode = USB_DR_MODE_PERIPHERAL, |
| 126 | .index = 0, |
| 127 | }; |
| 128 | |
| 129 | int usb_gadget_handle_interrupts(void) |
| 130 | { |
| 131 | dwc3_uboot_handle_interrupt(0); |
| 132 | return 0; |
| 133 | } |
| 134 | |
| 135 | int board_usb_init(int index, enum usb_init_type init) |
| 136 | { |
| 137 | struct exynos_usb3_phy *phy = (struct exynos_usb3_phy *) |
| 138 | samsung_get_base_usb3_phy(); |
| 139 | |
| 140 | if (!phy) { |
Seung-Woo Kim | ca21166 | 2018-06-04 16:03:05 +0900 | [diff] [blame] | 141 | pr_err("usb3 phy not supported\n"); |
Simon Glass | dc4d5e5 | 2015-08-03 08:19:27 -0600 | [diff] [blame] | 142 | return -ENODEV; |
| 143 | } |
| 144 | |
| 145 | set_usbdrd_phy_ctrl(POWER_USB_DRD_PHY_CTRL_EN); |
| 146 | exynos5_usb3_phy_init(phy); |
| 147 | |
| 148 | return dwc3_uboot_init(&dwc3_device_data); |
| 149 | } |
| 150 | #endif |
| 151 | #ifdef CONFIG_SET_DFU_ALT_INFO |
| 152 | char *get_dfu_alt_system(char *interface, char *devstr) |
| 153 | { |
Przemyslaw Marczak | a6e12d3 | 2015-10-27 13:08:05 +0100 | [diff] [blame] | 154 | char *info = "Not supported!"; |
| 155 | |
Dirk Meul | 738805d | 2018-10-14 17:14:17 +0200 | [diff] [blame] | 156 | if (board_is_odroidxu4() || board_is_odroidhc1() || board_is_odroidhc2()) |
Przemyslaw Marczak | a6e12d3 | 2015-10-27 13:08:05 +0100 | [diff] [blame] | 157 | return info; |
| 158 | |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 159 | return env_get("dfu_alt_system"); |
Simon Glass | dc4d5e5 | 2015-08-03 08:19:27 -0600 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | char *get_dfu_alt_boot(char *interface, char *devstr) |
| 163 | { |
Przemyslaw Marczak | a6e12d3 | 2015-10-27 13:08:05 +0100 | [diff] [blame] | 164 | char *info = "Not supported!"; |
Simon Glass | dc4d5e5 | 2015-08-03 08:19:27 -0600 | [diff] [blame] | 165 | struct mmc *mmc; |
| 166 | char *alt_boot; |
| 167 | int dev_num; |
| 168 | |
Dirk Meul | 738805d | 2018-10-14 17:14:17 +0200 | [diff] [blame] | 169 | if (board_is_odroidxu4() || board_is_odroidhc1() || board_is_odroidhc2()) |
Przemyslaw Marczak | a6e12d3 | 2015-10-27 13:08:05 +0100 | [diff] [blame] | 170 | return info; |
| 171 | |
Simon Glass | dc4d5e5 | 2015-08-03 08:19:27 -0600 | [diff] [blame] | 172 | dev_num = simple_strtoul(devstr, NULL, 10); |
| 173 | |
| 174 | mmc = find_mmc_device(dev_num); |
| 175 | if (!mmc) |
| 176 | return NULL; |
| 177 | |
| 178 | if (mmc_init(mmc)) |
| 179 | return NULL; |
| 180 | |
| 181 | if (IS_SD(mmc)) |
| 182 | alt_boot = CONFIG_DFU_ALT_BOOT_SD; |
| 183 | else |
| 184 | alt_boot = CONFIG_DFU_ALT_BOOT_EMMC; |
| 185 | |
| 186 | return alt_boot; |
| 187 | } |
| 188 | #endif |