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 | dc4d5e5 | 2015-08-03 08:19:27 -0600 | [diff] [blame] | 12 | #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 Marczak | a6e12d3 | 2015-10-27 13:08:05 +0100 | [diff] [blame] | 31 | #include <power/s2mps11.h> |
Simon Glass | dc4d5e5 | 2015-08-03 08:19:27 -0600 | [diff] [blame] | 32 | #include <power/s5m8767.h> |
Przemyslaw Marczak | a6e12d3 | 2015-10-27 13:08:05 +0100 | [diff] [blame] | 33 | #include <samsung/exynos5-dt-types.h> |
| 34 | #include <samsung/misc.h> |
Simon Glass | dc4d5e5 | 2015-08-03 08:19:27 -0600 | [diff] [blame] | 35 | #include <tmu.h> |
| 36 | |
| 37 | DECLARE_GLOBAL_DATA_PTR; |
| 38 | |
Simon Glass | dc4d5e5 | 2015-08-03 08:19:27 -0600 | [diff] [blame] | 39 | int exynos_init(void) |
| 40 | { |
Simon Glass | dc4d5e5 | 2015-08-03 08:19:27 -0600 | [diff] [blame] | 41 | return 0; |
| 42 | } |
| 43 | |
| 44 | static 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 | |
| 63 | int exynos_power_init(void) |
| 64 | { |
| 65 | struct udevice *dev; |
| 66 | int ret; |
| 67 | |
Jaehoon Chung | a47a6bb | 2018-01-29 13:53:19 +0900 | [diff] [blame] | 68 | #ifdef CONFIG_PMIC_S2MPS11 |
Marek Szyprowski | a436d70 | 2020-01-16 14:46:04 +0100 | [diff] [blame] | 69 | ret = pmic_get("s2mps11_pmic@66", &dev); |
Jaehoon Chung | a47a6bb | 2018-01-29 13:53:19 +0900 | [diff] [blame] | 70 | #else |
Marek Szyprowski | a436d70 | 2020-01-16 14:46:04 +0100 | [diff] [blame] | 71 | ret = pmic_get("max77686_pmic@09", &dev); |
Simon Glass | dc4d5e5 | 2015-08-03 08:19:27 -0600 | [diff] [blame] | 72 | 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 Szyprowski | a436d70 | 2020-01-16 14:46:04 +0100 | [diff] [blame] | 83 | ret = pmic_get("s5m8767_pmic@66", &dev); |
Simon Glass | dc4d5e5 | 2015-08-03 08:19:27 -0600 | [diff] [blame] | 84 | /* 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 Chung | a47a6bb | 2018-01-29 13:53:19 +0900 | [diff] [blame] | 90 | #endif /* CONFIG_PMIC_S2MPS11 */ |
Simon Glass | dc4d5e5 | 2015-08-03 08:19:27 -0600 | [diff] [blame] | 91 | 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 Simons | 9526fc4 | 2017-01-10 12:28:57 +0100 | [diff] [blame] | 102 | ret = exynos_set_regulator("vdd_arm", 1300000); |
Simon Glass | dc4d5e5 | 2015-08-03 08:19:27 -0600 | [diff] [blame] | 103 | 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 | |
| 115 | int board_get_revision(void) |
| 116 | { |
| 117 | return 0; |
| 118 | } |
| 119 | |
Simon Glass | dc4d5e5 | 2015-08-03 08:19:27 -0600 | [diff] [blame] | 120 | #ifdef CONFIG_USB_DWC3 |
| 121 | static 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 | |
| 128 | int usb_gadget_handle_interrupts(void) |
| 129 | { |
| 130 | dwc3_uboot_handle_interrupt(0); |
| 131 | return 0; |
| 132 | } |
| 133 | |
| 134 | int 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 Kim | ca21166 | 2018-06-04 16:03:05 +0900 | [diff] [blame] | 140 | pr_err("usb3 phy not supported\n"); |
Simon Glass | dc4d5e5 | 2015-08-03 08:19:27 -0600 | [diff] [blame] | 141 | 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 |
| 151 | char *get_dfu_alt_system(char *interface, char *devstr) |
| 152 | { |
Przemyslaw Marczak | a6e12d3 | 2015-10-27 13:08:05 +0100 | [diff] [blame] | 153 | char *info = "Not supported!"; |
| 154 | |
Dirk Meul | 738805d | 2018-10-14 17:14:17 +0200 | [diff] [blame] | 155 | if (board_is_odroidxu4() || board_is_odroidhc1() || board_is_odroidhc2()) |
Przemyslaw Marczak | a6e12d3 | 2015-10-27 13:08:05 +0100 | [diff] [blame] | 156 | return info; |
| 157 | |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 158 | return env_get("dfu_alt_system"); |
Simon Glass | dc4d5e5 | 2015-08-03 08:19:27 -0600 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | char *get_dfu_alt_boot(char *interface, char *devstr) |
| 162 | { |
Przemyslaw Marczak | a6e12d3 | 2015-10-27 13:08:05 +0100 | [diff] [blame] | 163 | char *info = "Not supported!"; |
Simon Glass | dc4d5e5 | 2015-08-03 08:19:27 -0600 | [diff] [blame] | 164 | struct mmc *mmc; |
| 165 | char *alt_boot; |
| 166 | int dev_num; |
| 167 | |
Dirk Meul | 738805d | 2018-10-14 17:14:17 +0200 | [diff] [blame] | 168 | if (board_is_odroidxu4() || board_is_odroidhc1() || board_is_odroidhc2()) |
Przemyslaw Marczak | a6e12d3 | 2015-10-27 13:08:05 +0100 | [diff] [blame] | 169 | return info; |
| 170 | |
Simon Glass | dc4d5e5 | 2015-08-03 08:19:27 -0600 | [diff] [blame] | 171 | 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 |