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> |
Simon Glass | bdd5f81 | 2023-09-14 18:21:46 -0600 | [diff] [blame] | 29 | #include <linux/printk.h> |
Simon Glass | dc4d5e5 | 2015-08-03 08:19:27 -0600 | [diff] [blame] | 30 | #include <power/pmic.h> |
| 31 | #include <power/max77686_pmic.h> |
| 32 | #include <power/regulator.h> |
Przemyslaw Marczak | a6e12d3 | 2015-10-27 13:08:05 +0100 | [diff] [blame] | 33 | #include <power/s2mps11.h> |
Simon Glass | dc4d5e5 | 2015-08-03 08:19:27 -0600 | [diff] [blame] | 34 | #include <power/s5m8767.h> |
Przemyslaw Marczak | a6e12d3 | 2015-10-27 13:08:05 +0100 | [diff] [blame] | 35 | #include <samsung/exynos5-dt-types.h> |
| 36 | #include <samsung/misc.h> |
Simon Glass | dc4d5e5 | 2015-08-03 08:19:27 -0600 | [diff] [blame] | 37 | #include <tmu.h> |
| 38 | |
| 39 | DECLARE_GLOBAL_DATA_PTR; |
| 40 | |
Simon Glass | dc4d5e5 | 2015-08-03 08:19:27 -0600 | [diff] [blame] | 41 | static 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 | |
| 60 | int exynos_power_init(void) |
| 61 | { |
| 62 | struct udevice *dev; |
| 63 | int ret; |
| 64 | |
Jaehoon Chung | a47a6bb | 2018-01-29 13:53:19 +0900 | [diff] [blame] | 65 | #ifdef CONFIG_PMIC_S2MPS11 |
Marek Szyprowski | a436d70 | 2020-01-16 14:46:04 +0100 | [diff] [blame] | 66 | ret = pmic_get("s2mps11_pmic@66", &dev); |
Jaehoon Chung | a47a6bb | 2018-01-29 13:53:19 +0900 | [diff] [blame] | 67 | #else |
Marek Szyprowski | a436d70 | 2020-01-16 14:46:04 +0100 | [diff] [blame] | 68 | ret = pmic_get("max77686_pmic@09", &dev); |
Simon Glass | dc4d5e5 | 2015-08-03 08:19:27 -0600 | [diff] [blame] | 69 | 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 Szyprowski | a436d70 | 2020-01-16 14:46:04 +0100 | [diff] [blame] | 80 | ret = pmic_get("s5m8767_pmic@66", &dev); |
Simon Glass | dc4d5e5 | 2015-08-03 08:19:27 -0600 | [diff] [blame] | 81 | /* 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 Chung | a47a6bb | 2018-01-29 13:53:19 +0900 | [diff] [blame] | 87 | #endif /* CONFIG_PMIC_S2MPS11 */ |
Simon Glass | dc4d5e5 | 2015-08-03 08:19:27 -0600 | [diff] [blame] | 88 | if (ret == -ENODEV) |
| 89 | return 0; |
| 90 | |
| 91 | ret = regulators_enable_boot_on(false); |
| 92 | if (ret) |
| 93 | return ret; |
| 94 | |
| 95 | ret = exynos_set_regulator("vdd_mif", 1100000); |
| 96 | if (ret) |
| 97 | return ret; |
| 98 | |
Sjoerd Simons | 9526fc4 | 2017-01-10 12:28:57 +0100 | [diff] [blame] | 99 | ret = exynos_set_regulator("vdd_arm", 1300000); |
Simon Glass | dc4d5e5 | 2015-08-03 08:19:27 -0600 | [diff] [blame] | 100 | if (ret) |
| 101 | return ret; |
| 102 | ret = exynos_set_regulator("vdd_int", 1012500); |
| 103 | if (ret) |
| 104 | return ret; |
| 105 | ret = exynos_set_regulator("vdd_g3d", 1200000); |
| 106 | if (ret) |
| 107 | return ret; |
| 108 | |
| 109 | return 0; |
| 110 | } |
| 111 | |
| 112 | int board_get_revision(void) |
| 113 | { |
| 114 | return 0; |
| 115 | } |
| 116 | |
Simon Glass | dc4d5e5 | 2015-08-03 08:19:27 -0600 | [diff] [blame] | 117 | #ifdef CONFIG_USB_DWC3 |
| 118 | static struct dwc3_device dwc3_device_data = { |
| 119 | .maximum_speed = USB_SPEED_SUPER, |
| 120 | .base = 0x12400000, |
| 121 | .dr_mode = USB_DR_MODE_PERIPHERAL, |
| 122 | .index = 0, |
| 123 | }; |
| 124 | |
Marek Vasut | 283bbec | 2023-09-01 11:50:03 +0200 | [diff] [blame] | 125 | int dm_usb_gadget_handle_interrupts(struct udevice *dev) |
Simon Glass | dc4d5e5 | 2015-08-03 08:19:27 -0600 | [diff] [blame] | 126 | { |
Marek Vasut | 283bbec | 2023-09-01 11:50:03 +0200 | [diff] [blame] | 127 | dwc3_uboot_handle_interrupt(dev); |
Simon Glass | dc4d5e5 | 2015-08-03 08:19:27 -0600 | [diff] [blame] | 128 | return 0; |
| 129 | } |
| 130 | |
| 131 | int board_usb_init(int index, enum usb_init_type init) |
| 132 | { |
| 133 | struct exynos_usb3_phy *phy = (struct exynos_usb3_phy *) |
| 134 | samsung_get_base_usb3_phy(); |
| 135 | |
| 136 | if (!phy) { |
Seung-Woo Kim | ca21166 | 2018-06-04 16:03:05 +0900 | [diff] [blame] | 137 | pr_err("usb3 phy not supported\n"); |
Simon Glass | dc4d5e5 | 2015-08-03 08:19:27 -0600 | [diff] [blame] | 138 | return -ENODEV; |
| 139 | } |
| 140 | |
| 141 | set_usbdrd_phy_ctrl(POWER_USB_DRD_PHY_CTRL_EN); |
| 142 | exynos5_usb3_phy_init(phy); |
| 143 | |
| 144 | return dwc3_uboot_init(&dwc3_device_data); |
| 145 | } |
| 146 | #endif |
| 147 | #ifdef CONFIG_SET_DFU_ALT_INFO |
| 148 | char *get_dfu_alt_system(char *interface, char *devstr) |
| 149 | { |
Przemyslaw Marczak | a6e12d3 | 2015-10-27 13:08:05 +0100 | [diff] [blame] | 150 | char *info = "Not supported!"; |
| 151 | |
Dirk Meul | 738805d | 2018-10-14 17:14:17 +0200 | [diff] [blame] | 152 | if (board_is_odroidxu4() || board_is_odroidhc1() || board_is_odroidhc2()) |
Przemyslaw Marczak | a6e12d3 | 2015-10-27 13:08:05 +0100 | [diff] [blame] | 153 | return info; |
| 154 | |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 155 | return env_get("dfu_alt_system"); |
Simon Glass | dc4d5e5 | 2015-08-03 08:19:27 -0600 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | char *get_dfu_alt_boot(char *interface, char *devstr) |
| 159 | { |
Przemyslaw Marczak | a6e12d3 | 2015-10-27 13:08:05 +0100 | [diff] [blame] | 160 | char *info = "Not supported!"; |
Simon Glass | dc4d5e5 | 2015-08-03 08:19:27 -0600 | [diff] [blame] | 161 | struct mmc *mmc; |
| 162 | char *alt_boot; |
| 163 | int dev_num; |
| 164 | |
Dirk Meul | 738805d | 2018-10-14 17:14:17 +0200 | [diff] [blame] | 165 | if (board_is_odroidxu4() || board_is_odroidhc1() || board_is_odroidhc2()) |
Przemyslaw Marczak | a6e12d3 | 2015-10-27 13:08:05 +0100 | [diff] [blame] | 166 | return info; |
| 167 | |
Simon Glass | ff9b903 | 2021-07-24 09:03:30 -0600 | [diff] [blame] | 168 | dev_num = dectoul(devstr, NULL); |
Simon Glass | dc4d5e5 | 2015-08-03 08:19:27 -0600 | [diff] [blame] | 169 | |
| 170 | mmc = find_mmc_device(dev_num); |
| 171 | if (!mmc) |
| 172 | return NULL; |
| 173 | |
| 174 | if (mmc_init(mmc)) |
| 175 | return NULL; |
| 176 | |
| 177 | if (IS_SD(mmc)) |
Tom Rini | 3aef00d | 2022-12-04 10:03:38 -0500 | [diff] [blame] | 178 | alt_boot = CFG_DFU_ALT_BOOT_SD; |
Simon Glass | dc4d5e5 | 2015-08-03 08:19:27 -0600 | [diff] [blame] | 179 | else |
Tom Rini | 3aef00d | 2022-12-04 10:03:38 -0500 | [diff] [blame] | 180 | alt_boot = CFG_DFU_ALT_BOOT_EMMC; |
Simon Glass | dc4d5e5 | 2015-08-03 08:19:27 -0600 | [diff] [blame] | 181 | |
| 182 | return alt_boot; |
| 183 | } |
| 184 | #endif |