Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Piotr Wilczek | 2b3c92a | 2013-09-20 15:01:27 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved. |
| 4 | * Sanghee Kim <sh0130.kim@samsung.com> |
| 5 | * Piotr Wilczek <p.wilczek@samsung.com> |
Piotr Wilczek | 2b3c92a | 2013-09-20 15:01:27 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 8 | #include <log.h> |
Simon Glass | 37f1162 | 2014-10-20 19:48:37 -0600 | [diff] [blame] | 9 | #include <asm/gpio.h> |
Piotr Wilczek | 2b3c92a | 2013-09-20 15:01:27 +0200 | [diff] [blame] | 10 | #include <asm/arch/pinmux.h> |
| 11 | #include <asm/arch/power.h> |
Piotr Wilczek | 87d2e78 | 2014-03-07 14:59:49 +0100 | [diff] [blame] | 12 | #include <asm/arch/mipi_dsim.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 13 | #include <linux/delay.h> |
Piotr Wilczek | 2b3c92a | 2013-09-20 15:01:27 +0200 | [diff] [blame] | 14 | #include <power/pmic.h> |
| 15 | #include <power/max77686_pmic.h> |
| 16 | #include <power/battery.h> |
| 17 | #include <power/max77693_pmic.h> |
| 18 | #include <power/max77693_muic.h> |
| 19 | #include <power/max77693_fg.h> |
| 20 | #include <libtizen.h> |
| 21 | #include <errno.h> |
Piotr Wilczek | 0c2ba4c | 2013-11-21 15:46:45 +0100 | [diff] [blame] | 22 | #include <usb.h> |
Marek Vasut | f1be9cb | 2015-12-04 02:51:20 +0100 | [diff] [blame] | 23 | #include <usb/dwc2_udc.h> |
Piotr Wilczek | 0c2ba4c | 2013-11-21 15:46:45 +0100 | [diff] [blame] | 24 | #include <usb_mass_storage.h> |
Piotr Wilczek | 2b3c92a | 2013-09-20 15:01:27 +0200 | [diff] [blame] | 25 | |
Piotr Wilczek | 2b3c92a | 2013-09-20 15:01:27 +0200 | [diff] [blame] | 26 | static unsigned int board_rev = -1; |
| 27 | |
| 28 | static inline u32 get_model_rev(void); |
| 29 | |
| 30 | static void check_hw_revision(void) |
| 31 | { |
| 32 | int modelrev = 0; |
Simon Glass | 4f83d3d | 2014-10-20 19:48:39 -0600 | [diff] [blame] | 33 | char str[12]; |
Piotr Wilczek | 2b3c92a | 2013-09-20 15:01:27 +0200 | [diff] [blame] | 34 | int i; |
| 35 | |
Piotr Wilczek | 2b3c92a | 2013-09-20 15:01:27 +0200 | [diff] [blame] | 36 | /* |
| 37 | * GPM1[1:0]: MODEL_REV[1:0] |
| 38 | * Don't set as pull-none for these N/C pin. |
| 39 | * TRM say that it may cause unexcepted state and leakage current. |
| 40 | * and pull-none is only for output function. |
| 41 | */ |
Simon Glass | 4f83d3d | 2014-10-20 19:48:39 -0600 | [diff] [blame] | 42 | for (i = 0; i < 2; i++) { |
| 43 | int pin = i + EXYNOS4X12_GPIO_M10; |
| 44 | |
| 45 | sprintf(str, "model_rev%d", i); |
| 46 | gpio_request(pin, str); |
| 47 | gpio_cfg_pin(pin, S5P_GPIO_INPUT); |
| 48 | } |
Piotr Wilczek | 2b3c92a | 2013-09-20 15:01:27 +0200 | [diff] [blame] | 49 | |
| 50 | /* GPM1[5:2]: HW_REV[3:0] */ |
Simon Glass | 4f83d3d | 2014-10-20 19:48:39 -0600 | [diff] [blame] | 51 | for (i = 0; i < 4; i++) { |
| 52 | int pin = i + EXYNOS4X12_GPIO_M12; |
| 53 | |
| 54 | sprintf(str, "hw_rev%d", i); |
| 55 | gpio_request(pin, str); |
| 56 | gpio_cfg_pin(pin, S5P_GPIO_INPUT); |
| 57 | gpio_set_pull(pin, S5P_GPIO_PULL_NONE); |
Piotr Wilczek | 2b3c92a | 2013-09-20 15:01:27 +0200 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | /* GPM1[1:0]: MODEL_REV[1:0] */ |
| 61 | for (i = 0; i < 2; i++) |
Akshay Saraswat | 1376cdd | 2014-05-13 10:30:14 +0530 | [diff] [blame] | 62 | modelrev |= (gpio_get_value(EXYNOS4X12_GPIO_M10 + i) << i); |
Piotr Wilczek | 2b3c92a | 2013-09-20 15:01:27 +0200 | [diff] [blame] | 63 | |
| 64 | /* board_rev[15:8] = model */ |
| 65 | board_rev = modelrev << 8; |
| 66 | } |
Piotr Wilczek | 2b3c92a | 2013-09-20 15:01:27 +0200 | [diff] [blame] | 67 | |
Tom Rini | 4cc3885 | 2021-08-30 09:16:30 -0400 | [diff] [blame] | 68 | #ifdef CONFIG_REVISION_TAG |
Piotr Wilczek | 2b3c92a | 2013-09-20 15:01:27 +0200 | [diff] [blame] | 69 | u32 get_board_rev(void) |
| 70 | { |
| 71 | return board_rev; |
| 72 | } |
Tom Rini | 4cc3885 | 2021-08-30 09:16:30 -0400 | [diff] [blame] | 73 | #endif |
Piotr Wilczek | 2b3c92a | 2013-09-20 15:01:27 +0200 | [diff] [blame] | 74 | |
| 75 | static inline u32 get_model_rev(void) |
| 76 | { |
| 77 | return (board_rev >> 8) & 0xff; |
| 78 | } |
| 79 | |
| 80 | static void board_external_gpio_init(void) |
| 81 | { |
Piotr Wilczek | 2b3c92a | 2013-09-20 15:01:27 +0200 | [diff] [blame] | 82 | /* |
| 83 | * some pins which in alive block are connected with external pull-up |
| 84 | * but it's default setting is pull-down. |
| 85 | * if that pin set as input then that floated |
| 86 | */ |
| 87 | |
Akshay Saraswat | 1376cdd | 2014-05-13 10:30:14 +0530 | [diff] [blame] | 88 | gpio_set_pull(EXYNOS4X12_GPIO_X02, S5P_GPIO_PULL_NONE); /* PS_ALS_INT */ |
| 89 | gpio_set_pull(EXYNOS4X12_GPIO_X04, S5P_GPIO_PULL_NONE); /* TSP_nINT */ |
| 90 | gpio_set_pull(EXYNOS4X12_GPIO_X07, S5P_GPIO_PULL_NONE); /* AP_PMIC_IRQ*/ |
| 91 | gpio_set_pull(EXYNOS4X12_GPIO_X15, S5P_GPIO_PULL_NONE); /* IF_PMIC_IRQ*/ |
| 92 | gpio_set_pull(EXYNOS4X12_GPIO_X20, S5P_GPIO_PULL_NONE); /* VOL_UP */ |
| 93 | gpio_set_pull(EXYNOS4X12_GPIO_X21, S5P_GPIO_PULL_NONE); /* VOL_DOWN */ |
| 94 | gpio_set_pull(EXYNOS4X12_GPIO_X23, S5P_GPIO_PULL_NONE); /* FUEL_ALERT */ |
| 95 | gpio_set_pull(EXYNOS4X12_GPIO_X24, S5P_GPIO_PULL_NONE); /* ADC_INT */ |
| 96 | gpio_set_pull(EXYNOS4X12_GPIO_X27, S5P_GPIO_PULL_NONE); /* nPOWER */ |
| 97 | gpio_set_pull(EXYNOS4X12_GPIO_X30, S5P_GPIO_PULL_NONE); /* WPC_INT */ |
| 98 | gpio_set_pull(EXYNOS4X12_GPIO_X35, S5P_GPIO_PULL_NONE); /* OK_KEY */ |
| 99 | gpio_set_pull(EXYNOS4X12_GPIO_X37, S5P_GPIO_PULL_NONE); /* HDMI_HPD */ |
Piotr Wilczek | 2b3c92a | 2013-09-20 15:01:27 +0200 | [diff] [blame] | 100 | } |
| 101 | |
Piotr Wilczek | 87d2e78 | 2014-03-07 14:59:49 +0100 | [diff] [blame] | 102 | int exynos_early_init_f(void) |
Piotr Wilczek | 2b3c92a | 2013-09-20 15:01:27 +0200 | [diff] [blame] | 103 | { |
Piotr Wilczek | 2b3c92a | 2013-09-20 15:01:27 +0200 | [diff] [blame] | 104 | board_external_gpio_init(); |
| 105 | |
Piotr Wilczek | 2b3c92a | 2013-09-20 15:01:27 +0200 | [diff] [blame] | 106 | return 0; |
| 107 | } |
| 108 | |
Tom Rini | 757dc98 | 2023-09-21 19:32:48 -0400 | [diff] [blame] | 109 | void exynos_init(void) |
Piotr Wilczek | 2b3c92a | 2013-09-20 15:01:27 +0200 | [diff] [blame] | 110 | { |
Łukasz Majewski | 27937c0 | 2014-04-09 15:09:44 +0200 | [diff] [blame] | 111 | struct exynos4_power *pwr = |
| 112 | (struct exynos4_power *)samsung_get_base_power(); |
| 113 | |
Piotr Wilczek | 87d2e78 | 2014-03-07 14:59:49 +0100 | [diff] [blame] | 114 | check_hw_revision(); |
| 115 | printf("HW Revision:\t0x%04x\n", board_rev); |
Piotr Wilczek | 2b3c92a | 2013-09-20 15:01:27 +0200 | [diff] [blame] | 116 | |
Łukasz Majewski | 27937c0 | 2014-04-09 15:09:44 +0200 | [diff] [blame] | 117 | /* |
| 118 | * First bootloader on the TRATS2 platform uses |
| 119 | * INFORM4 and INFORM5 registers for recovery |
| 120 | * |
| 121 | * To indicate correct boot chain - those two |
| 122 | * registers must be cleared out |
| 123 | */ |
| 124 | writel(0, &pwr->inform4); |
| 125 | writel(0, &pwr->inform5); |
Piotr Wilczek | 2b3c92a | 2013-09-20 15:01:27 +0200 | [diff] [blame] | 126 | } |
| 127 | |
Piotr Wilczek | 87d2e78 | 2014-03-07 14:59:49 +0100 | [diff] [blame] | 128 | int exynos_power_init(void) |
Piotr Wilczek | 2b3c92a | 2013-09-20 15:01:27 +0200 | [diff] [blame] | 129 | { |
Igor Opaniuk | f7c9176 | 2021-02-09 13:52:45 +0200 | [diff] [blame] | 130 | #if !CONFIG_IS_ENABLED(DM_I2C) /* TODO(maintainer): Convert to driver model */ |
Piotr Wilczek | 2b3c92a | 2013-09-20 15:01:27 +0200 | [diff] [blame] | 131 | int chrg; |
| 132 | struct power_battery *pb; |
| 133 | struct pmic *p_chrg, *p_muic, *p_fg, *p_bat; |
| 134 | |
Piotr Wilczek | 97ae183 | 2013-12-18 15:43:37 +0100 | [diff] [blame] | 135 | pmic_init_max77693(I2C_10); /* I2C adapter 10 - bus name soft1 */ |
| 136 | power_muic_init(I2C_10); /* I2C adapter 10 - bus name soft1 */ |
| 137 | power_fg_init(I2C_9); /* I2C adapter 9 - bus name soft0 */ |
Piotr Wilczek | 2b3c92a | 2013-09-20 15:01:27 +0200 | [diff] [blame] | 138 | power_bat_init(0); |
| 139 | |
| 140 | p_chrg = pmic_get("MAX77693_PMIC"); |
| 141 | if (!p_chrg) { |
| 142 | puts("MAX77693_PMIC: Not found\n"); |
| 143 | return -ENODEV; |
| 144 | } |
| 145 | |
| 146 | p_muic = pmic_get("MAX77693_MUIC"); |
| 147 | if (!p_muic) { |
| 148 | puts("MAX77693_MUIC: Not found\n"); |
| 149 | return -ENODEV; |
| 150 | } |
| 151 | |
| 152 | p_fg = pmic_get("MAX77693_FG"); |
| 153 | if (!p_fg) { |
| 154 | puts("MAX17042_FG: Not found\n"); |
| 155 | return -ENODEV; |
| 156 | } |
| 157 | |
| 158 | if (p_chrg->chrg->chrg_bat_present(p_chrg) == 0) |
| 159 | puts("No battery detected\n"); |
| 160 | |
| 161 | p_bat = pmic_get("BAT_TRATS2"); |
| 162 | if (!p_bat) { |
| 163 | puts("BAT_TRATS2: Not found\n"); |
| 164 | return -ENODEV; |
| 165 | } |
| 166 | |
| 167 | p_fg->parent = p_bat; |
| 168 | p_chrg->parent = p_bat; |
| 169 | p_muic->parent = p_bat; |
| 170 | |
| 171 | p_bat->pbat->battery_init(p_bat, p_fg, p_chrg, p_muic); |
| 172 | |
| 173 | pb = p_bat->pbat; |
| 174 | chrg = p_muic->chrg->chrg_type(p_muic); |
| 175 | debug("CHARGER TYPE: %d\n", chrg); |
| 176 | |
| 177 | if (!p_chrg->chrg->chrg_bat_present(p_chrg)) { |
| 178 | puts("No battery detected\n"); |
Przemyslaw Marczak | dd0c48e | 2014-06-10 16:55:08 +0200 | [diff] [blame] | 179 | return 0; |
Piotr Wilczek | 2b3c92a | 2013-09-20 15:01:27 +0200 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | p_fg->fg->fg_battery_check(p_fg, p_bat); |
| 183 | |
| 184 | if (pb->bat->state == CHARGE && chrg == CHARGER_USB) |
| 185 | puts("CHARGE Battery !\n"); |
Simon Glass | 7bbb7d9 | 2016-11-23 06:34:40 -0700 | [diff] [blame] | 186 | #endif |
Piotr Wilczek | 2b3c92a | 2013-09-20 15:01:27 +0200 | [diff] [blame] | 187 | return 0; |
| 188 | } |
| 189 | |
Piotr Wilczek | 0c2ba4c | 2013-11-21 15:46:45 +0100 | [diff] [blame] | 190 | #ifdef CONFIG_USB_GADGET |
| 191 | static int s5pc210_phy_control(int on) |
| 192 | { |
Igor Opaniuk | f7c9176 | 2021-02-09 13:52:45 +0200 | [diff] [blame] | 193 | #if !CONFIG_IS_ENABLED(DM_I2C) /* TODO(maintainer): Convert to driver model */ |
Piotr Wilczek | 0c2ba4c | 2013-11-21 15:46:45 +0100 | [diff] [blame] | 194 | int ret = 0; |
| 195 | unsigned int val; |
| 196 | struct pmic *p, *p_pmic, *p_muic; |
| 197 | |
| 198 | p_pmic = pmic_get("MAX77686_PMIC"); |
| 199 | if (!p_pmic) |
| 200 | return -ENODEV; |
| 201 | |
| 202 | if (pmic_probe(p_pmic)) |
| 203 | return -1; |
| 204 | |
| 205 | p_muic = pmic_get("MAX77693_MUIC"); |
| 206 | if (!p_muic) |
| 207 | return -ENODEV; |
| 208 | |
| 209 | if (pmic_probe(p_muic)) |
| 210 | return -1; |
| 211 | |
| 212 | if (on) { |
| 213 | ret = max77686_set_ldo_mode(p_pmic, 12, OPMODE_ON); |
| 214 | if (ret) |
| 215 | return -1; |
| 216 | |
| 217 | p = pmic_get("MAX77693_PMIC"); |
| 218 | if (!p) |
| 219 | return -ENODEV; |
| 220 | |
| 221 | if (pmic_probe(p)) |
| 222 | return -1; |
| 223 | |
| 224 | /* SAFEOUT */ |
| 225 | ret = pmic_reg_read(p, MAX77693_SAFEOUT, &val); |
| 226 | if (ret) |
| 227 | return -1; |
| 228 | |
| 229 | val |= MAX77693_ENSAFEOUT1; |
| 230 | ret = pmic_reg_write(p, MAX77693_SAFEOUT, val); |
| 231 | if (ret) |
| 232 | return -1; |
| 233 | |
| 234 | /* PATH: USB */ |
| 235 | ret = pmic_reg_write(p_muic, MAX77693_MUIC_CONTROL1, |
| 236 | MAX77693_MUIC_CTRL1_DN1DP2); |
| 237 | |
| 238 | } else { |
| 239 | ret = max77686_set_ldo_mode(p_pmic, 12, OPMODE_LPM); |
| 240 | if (ret) |
| 241 | return -1; |
| 242 | |
| 243 | /* PATH: UART */ |
| 244 | ret = pmic_reg_write(p_muic, MAX77693_MUIC_CONTROL1, |
| 245 | MAX77693_MUIC_CTRL1_UT1UR2); |
| 246 | } |
| 247 | |
| 248 | if (ret) |
| 249 | return -1; |
Simon Glass | 7bbb7d9 | 2016-11-23 06:34:40 -0700 | [diff] [blame] | 250 | #endif |
Piotr Wilczek | 0c2ba4c | 2013-11-21 15:46:45 +0100 | [diff] [blame] | 251 | return 0; |
| 252 | } |
| 253 | |
Marek Vasut | 6939aca | 2015-12-04 02:23:29 +0100 | [diff] [blame] | 254 | struct dwc2_plat_otg_data s5pc210_otg_data = { |
Piotr Wilczek | 0c2ba4c | 2013-11-21 15:46:45 +0100 | [diff] [blame] | 255 | .phy_control = s5pc210_phy_control, |
| 256 | .regs_phy = EXYNOS4X12_USBPHY_BASE, |
| 257 | .regs_otg = EXYNOS4X12_USBOTG_BASE, |
| 258 | .usb_phy_ctrl = EXYNOS4X12_USBPHY_CONTROL, |
| 259 | .usb_flags = PHY0_SLEEP, |
| 260 | }; |
| 261 | |
| 262 | int board_usb_init(int index, enum usb_init_type init) |
| 263 | { |
| 264 | debug("USB_udc_probe\n"); |
Marek Vasut | 01b61fa | 2015-12-04 02:26:33 +0100 | [diff] [blame] | 265 | return dwc2_udc_probe(&s5pc210_otg_data); |
Piotr Wilczek | 0c2ba4c | 2013-11-21 15:46:45 +0100 | [diff] [blame] | 266 | } |
| 267 | |
Mateusz Zalega | 21fe3f7 | 2014-04-30 13:07:48 +0200 | [diff] [blame] | 268 | int g_dnl_board_usb_cable_connected(void) |
Piotr Wilczek | 0c2ba4c | 2013-11-21 15:46:45 +0100 | [diff] [blame] | 269 | { |
Igor Opaniuk | f7c9176 | 2021-02-09 13:52:45 +0200 | [diff] [blame] | 270 | #if !CONFIG_IS_ENABLED(DM_I2C) /* TODO(maintainer): Convert to driver model */ |
Piotr Wilczek | 0c2ba4c | 2013-11-21 15:46:45 +0100 | [diff] [blame] | 271 | struct pmic *muic = pmic_get("MAX77693_MUIC"); |
| 272 | if (!muic) |
| 273 | return 0; |
| 274 | |
| 275 | return !!muic->chrg->chrg_type(muic); |
Simon Glass | 7bbb7d9 | 2016-11-23 06:34:40 -0700 | [diff] [blame] | 276 | #else |
| 277 | return false; |
| 278 | #endif |
Piotr Wilczek | 0c2ba4c | 2013-11-21 15:46:45 +0100 | [diff] [blame] | 279 | } |
| 280 | #endif |