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