HeungJun, Kim | b4b5468 | 2012-01-16 21:13:05 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 Samsung Electronics |
| 3 | * Heungjun Kim <riverful.kim@samsung.com> |
| 4 | * Kyungmin Park <kyungmin.park@samsung.com> |
Donghwa Lee | 9ad0ddc | 2012-04-05 19:36:27 +0000 | [diff] [blame] | 5 | * Donghwa Lee <dh09.lee@samsung.com> |
HeungJun, Kim | b4b5468 | 2012-01-16 21:13:05 +0000 | [diff] [blame] | 6 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 7 | * SPDX-License-Identifier: GPL-2.0+ |
HeungJun, Kim | b4b5468 | 2012-01-16 21:13:05 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <common.h> |
Donghwa Lee | 9ad0ddc | 2012-04-05 19:36:27 +0000 | [diff] [blame] | 11 | #include <lcd.h> |
HeungJun, Kim | b4b5468 | 2012-01-16 21:13:05 +0000 | [diff] [blame] | 12 | #include <asm/io.h> |
Simon Glass | 37f1162 | 2014-10-20 19:48:37 -0600 | [diff] [blame] | 13 | #include <asm/gpio.h> |
HeungJun, Kim | b4b5468 | 2012-01-16 21:13:05 +0000 | [diff] [blame] | 14 | #include <asm/arch/cpu.h> |
Piotr Wilczek | 3c8b71d | 2012-09-20 00:19:58 +0000 | [diff] [blame] | 15 | #include <asm/arch/pinmux.h> |
HeungJun, Kim | b4b5468 | 2012-01-16 21:13:05 +0000 | [diff] [blame] | 16 | #include <asm/arch/clock.h> |
Donghwa Lee | 9ad0ddc | 2012-04-05 19:36:27 +0000 | [diff] [blame] | 17 | #include <asm/arch/mipi_dsim.h> |
HeungJun, Kim | b4b5468 | 2012-01-16 21:13:05 +0000 | [diff] [blame] | 18 | #include <asm/arch/watchdog.h> |
| 19 | #include <asm/arch/power.h> |
Łukasz Majewski | 1c6dba1 | 2012-11-13 03:21:55 +0000 | [diff] [blame] | 20 | #include <power/pmic.h> |
Marek Vasut | f1be9cb | 2015-12-04 02:51:20 +0100 | [diff] [blame] | 21 | #include <usb/dwc2_udc.h> |
Łukasz Majewski | 1c6dba1 | 2012-11-13 03:21:55 +0000 | [diff] [blame] | 22 | #include <power/max8997_pmic.h> |
Łukasz Majewski | 40e330a | 2012-11-13 03:22:06 +0000 | [diff] [blame] | 23 | #include <power/max8997_muic.h> |
Łukasz Majewski | e4a182a | 2012-11-13 03:22:08 +0000 | [diff] [blame] | 24 | #include <power/battery.h> |
Łukasz Majewski | 7aba6a1 | 2012-11-13 03:22:07 +0000 | [diff] [blame] | 25 | #include <power/max17042_fg.h> |
Piotr Wilczek | 4efd33a | 2014-03-07 14:59:48 +0100 | [diff] [blame] | 26 | #include <libtizen.h> |
Mateusz Zalega | d862f89 | 2013-10-04 19:22:26 +0200 | [diff] [blame] | 27 | #include <usb.h> |
Lukasz Majewski | 0a4d8a9 | 2013-03-05 12:10:18 +0100 | [diff] [blame] | 28 | #include <usb_mass_storage.h> |
HeungJun, Kim | b4b5468 | 2012-01-16 21:13:05 +0000 | [diff] [blame] | 29 | |
| 30 | #include "setup.h" |
| 31 | |
| 32 | DECLARE_GLOBAL_DATA_PTR; |
| 33 | |
| 34 | unsigned int board_rev; |
| 35 | |
| 36 | #ifdef CONFIG_REVISION_TAG |
| 37 | u32 get_board_rev(void) |
| 38 | { |
| 39 | return board_rev; |
| 40 | } |
| 41 | #endif |
| 42 | |
| 43 | static void check_hw_revision(void); |
Marek Vasut | 6939aca | 2015-12-04 02:23:29 +0100 | [diff] [blame] | 44 | struct dwc2_plat_otg_data s5pc210_otg_data; |
Lukasz Majewski | 51de176 | 2012-08-06 14:41:10 +0200 | [diff] [blame] | 45 | |
Piotr Wilczek | 4efd33a | 2014-03-07 14:59:48 +0100 | [diff] [blame] | 46 | int exynos_init(void) |
HeungJun, Kim | b4b5468 | 2012-01-16 21:13:05 +0000 | [diff] [blame] | 47 | { |
HeungJun, Kim | b4b5468 | 2012-01-16 21:13:05 +0000 | [diff] [blame] | 48 | check_hw_revision(); |
| 49 | printf("HW Revision:\t0x%x\n", board_rev); |
| 50 | |
HeungJun, Kim | b4b5468 | 2012-01-16 21:13:05 +0000 | [diff] [blame] | 51 | return 0; |
| 52 | } |
| 53 | |
Łukasz Majewski | c877879 | 2012-09-04 23:15:21 +0000 | [diff] [blame] | 54 | void i2c_init_board(void) |
| 55 | { |
Piotr Wilczek | 58bbd2b | 2013-11-20 10:43:49 +0100 | [diff] [blame] | 56 | int err; |
Łukasz Majewski | c877879 | 2012-09-04 23:15:21 +0000 | [diff] [blame] | 57 | |
Piotr Wilczek | 58bbd2b | 2013-11-20 10:43:49 +0100 | [diff] [blame] | 58 | /* I2C_5 -> PMIC */ |
| 59 | err = exynos_pinmux_config(PERIPH_ID_I2C5, PINMUX_FLAG_NONE); |
| 60 | if (err) { |
| 61 | debug("I2C%d not configured\n", (I2C_5)); |
| 62 | return; |
| 63 | } |
| 64 | |
| 65 | /* I2C_8 -> FG */ |
Simon Glass | 4f83d3d | 2014-10-20 19:48:39 -0600 | [diff] [blame] | 66 | gpio_request(EXYNOS4_GPIO_Y40, "i2c_clk"); |
| 67 | gpio_request(EXYNOS4_GPIO_Y41, "i2c_data"); |
Akshay Saraswat | 1376cdd | 2014-05-13 10:30:14 +0530 | [diff] [blame] | 68 | gpio_direction_output(EXYNOS4_GPIO_Y40, 1); |
| 69 | gpio_direction_output(EXYNOS4_GPIO_Y41, 1); |
Łukasz Majewski | c877879 | 2012-09-04 23:15:21 +0000 | [diff] [blame] | 70 | } |
| 71 | |
Łukasz Majewski | b6a3dc6 | 2012-11-13 03:22:10 +0000 | [diff] [blame] | 72 | static void trats_low_power_mode(void) |
| 73 | { |
| 74 | struct exynos4_clock *clk = |
| 75 | (struct exynos4_clock *)samsung_get_base_clock(); |
| 76 | struct exynos4_power *pwr = |
| 77 | (struct exynos4_power *)samsung_get_base_power(); |
| 78 | |
| 79 | /* Power down CORE1 */ |
| 80 | /* LOCAL_PWR_CFG [1:0] 0x3 EN, 0x0 DIS */ |
| 81 | writel(0x0, &pwr->arm_core1_configuration); |
| 82 | |
| 83 | /* Change the APLL frequency */ |
| 84 | /* ENABLE (1 enable) | LOCKED (1 locked) */ |
| 85 | /* [31] | [29] */ |
| 86 | /* FSEL | MDIV | PDIV | SDIV */ |
| 87 | /* [27] | [25:16] | [13:8] | [2:0] */ |
| 88 | writel(0xa0c80604, &clk->apll_con0); |
| 89 | |
| 90 | /* Change CPU0 clock divider */ |
| 91 | /* CORE2_RATIO | APLL_RATIO | PCLK_DBG_RATIO | ATB_RATIO */ |
| 92 | /* [30:28] | [26:24] | [22:20] | [18:16] */ |
| 93 | /* PERIPH_RATIO | COREM1_RATIO | COREM0_RATIO | CORE_RATIO */ |
| 94 | /* [14:12] | [10:8] | [6:4] | [2:0] */ |
| 95 | writel(0x00000100, &clk->div_cpu0); |
| 96 | |
| 97 | /* CLK_DIV_STAT_CPU0 - wait until clock gets stable (0 = stable) */ |
| 98 | while (readl(&clk->div_stat_cpu0) & 0x1111111) |
| 99 | continue; |
| 100 | |
| 101 | /* Change clock divider ratio for DMC */ |
| 102 | /* DMCP_RATIO | DMCD_RATIO */ |
| 103 | /* [22:20] | [18:16] */ |
| 104 | /* DMC_RATIO | DPHY_RATIO | ACP_PCLK_RATIO | ACP_RATIO */ |
| 105 | /* [14:12] | [10:8] | [6:4] | [2:0] */ |
| 106 | writel(0x13113117, &clk->div_dmc0); |
| 107 | |
| 108 | /* CLK_DIV_STAT_DMC0 - wait until clock gets stable (0 = stable) */ |
| 109 | while (readl(&clk->div_stat_dmc0) & 0x11111111) |
| 110 | continue; |
| 111 | |
| 112 | /* Turn off unnecessary power domains */ |
| 113 | writel(0x0, &pwr->xxti_configuration); /* XXTI */ |
| 114 | writel(0x0, &pwr->cam_configuration); /* CAM */ |
| 115 | writel(0x0, &pwr->tv_configuration); /* TV */ |
| 116 | writel(0x0, &pwr->mfc_configuration); /* MFC */ |
| 117 | writel(0x0, &pwr->g3d_configuration); /* G3D */ |
| 118 | writel(0x0, &pwr->gps_configuration); /* GPS */ |
| 119 | writel(0x0, &pwr->gps_alive_configuration); /* GPS_ALIVE */ |
| 120 | |
| 121 | /* Turn off unnecessary clocks */ |
| 122 | writel(0x0, &clk->gate_ip_cam); /* CAM */ |
| 123 | writel(0x0, &clk->gate_ip_tv); /* TV */ |
| 124 | writel(0x0, &clk->gate_ip_mfc); /* MFC */ |
| 125 | writel(0x0, &clk->gate_ip_g3d); /* G3D */ |
| 126 | writel(0x0, &clk->gate_ip_image); /* IMAGE */ |
| 127 | writel(0x0, &clk->gate_ip_gps); /* GPS */ |
| 128 | } |
| 129 | |
Łukasz Majewski | d72e0ae | 2012-11-13 03:22:05 +0000 | [diff] [blame] | 130 | static int pmic_init_max8997(void) |
| 131 | { |
| 132 | struct pmic *p = pmic_get("MAX8997_PMIC"); |
| 133 | int i = 0, ret = 0; |
| 134 | u32 val; |
| 135 | |
| 136 | if (pmic_probe(p)) |
| 137 | return -1; |
| 138 | |
| 139 | /* BUCK1 VARM: 1.2V */ |
| 140 | val = (1200000 - 650000) / 25000; |
| 141 | ret |= pmic_reg_write(p, MAX8997_REG_BUCK1DVS1, val); |
| 142 | val = ENBUCK | ACTIVE_DISCHARGE; /* DVS OFF */ |
| 143 | ret |= pmic_reg_write(p, MAX8997_REG_BUCK1CTRL, val); |
| 144 | |
| 145 | /* BUCK2 VINT: 1.1V */ |
| 146 | val = (1100000 - 650000) / 25000; |
| 147 | ret |= pmic_reg_write(p, MAX8997_REG_BUCK2DVS1, val); |
| 148 | val = ENBUCK | ACTIVE_DISCHARGE; /* DVS OFF */ |
| 149 | ret |= pmic_reg_write(p, MAX8997_REG_BUCK2CTRL, val); |
| 150 | |
| 151 | |
| 152 | /* BUCK3 G3D: 1.1V - OFF */ |
| 153 | ret |= pmic_reg_read(p, MAX8997_REG_BUCK3CTRL, &val); |
| 154 | val &= ~ENBUCK; |
| 155 | ret |= pmic_reg_write(p, MAX8997_REG_BUCK3CTRL, val); |
| 156 | |
| 157 | val = (1100000 - 750000) / 50000; |
| 158 | ret |= pmic_reg_write(p, MAX8997_REG_BUCK3DVS, val); |
| 159 | |
| 160 | /* BUCK4 CAMISP: 1.2V - OFF */ |
| 161 | ret |= pmic_reg_read(p, MAX8997_REG_BUCK4CTRL, &val); |
| 162 | val &= ~ENBUCK; |
| 163 | ret |= pmic_reg_write(p, MAX8997_REG_BUCK4CTRL, val); |
| 164 | |
| 165 | val = (1200000 - 650000) / 25000; |
| 166 | ret |= pmic_reg_write(p, MAX8997_REG_BUCK4DVS, val); |
| 167 | |
| 168 | /* BUCK5 VMEM: 1.2V */ |
| 169 | val = (1200000 - 650000) / 25000; |
| 170 | for (i = 0; i < 8; i++) |
| 171 | ret |= pmic_reg_write(p, MAX8997_REG_BUCK5DVS1 + i, val); |
| 172 | |
| 173 | val = ENBUCK | ACTIVE_DISCHARGE; /* DVS OFF */ |
| 174 | ret |= pmic_reg_write(p, MAX8997_REG_BUCK5CTRL, val); |
| 175 | |
| 176 | /* BUCK6 CAM AF: 2.8V */ |
| 177 | /* No Voltage Setting Register */ |
| 178 | /* GNSLCT 3.0X */ |
| 179 | val = GNSLCT; |
| 180 | ret |= pmic_reg_write(p, MAX8997_REG_BUCK6CTRL, val); |
| 181 | |
| 182 | /* BUCK7 VCC_SUB: 2.0V */ |
| 183 | val = (2000000 - 750000) / 50000; |
| 184 | ret |= pmic_reg_write(p, MAX8997_REG_BUCK7DVS, val); |
| 185 | |
| 186 | /* LDO1 VADC: 3.3V */ |
| 187 | val = max8997_reg_ldo(3300000) | DIS_LDO; /* OFF */ |
| 188 | ret |= pmic_reg_write(p, MAX8997_REG_LDO1CTRL, val); |
| 189 | |
| 190 | /* LDO1 Disable active discharging */ |
| 191 | ret |= pmic_reg_read(p, MAX8997_REG_LDO1CONFIG, &val); |
| 192 | val &= ~LDO_ADE; |
| 193 | ret |= pmic_reg_write(p, MAX8997_REG_LDO1CONFIG, val); |
| 194 | |
| 195 | /* LDO2 VALIVE: 1.1V */ |
| 196 | val = max8997_reg_ldo(1100000) | EN_LDO; |
| 197 | ret |= pmic_reg_write(p, MAX8997_REG_LDO2CTRL, val); |
| 198 | |
| 199 | /* LDO3 VUSB/MIPI: 1.1V */ |
| 200 | val = max8997_reg_ldo(1100000) | DIS_LDO; /* OFF */ |
| 201 | ret |= pmic_reg_write(p, MAX8997_REG_LDO3CTRL, val); |
| 202 | |
| 203 | /* LDO4 VMIPI: 1.8V */ |
| 204 | val = max8997_reg_ldo(1800000) | DIS_LDO; /* OFF */ |
| 205 | ret |= pmic_reg_write(p, MAX8997_REG_LDO4CTRL, val); |
| 206 | |
| 207 | /* LDO5 VHSIC: 1.2V */ |
| 208 | val = max8997_reg_ldo(1200000) | DIS_LDO; /* OFF */ |
| 209 | ret |= pmic_reg_write(p, MAX8997_REG_LDO5CTRL, val); |
| 210 | |
| 211 | /* LDO6 VCC_1.8V_PDA: 1.8V */ |
| 212 | val = max8997_reg_ldo(1800000) | EN_LDO; |
| 213 | ret |= pmic_reg_write(p, MAX8997_REG_LDO6CTRL, val); |
| 214 | |
| 215 | /* LDO7 CAM_ISP: 1.8V */ |
| 216 | val = max8997_reg_ldo(1800000) | DIS_LDO; /* OFF */ |
| 217 | ret |= pmic_reg_write(p, MAX8997_REG_LDO7CTRL, val); |
| 218 | |
| 219 | /* LDO8 VDAC/VUSB: 3.3V */ |
| 220 | val = max8997_reg_ldo(3300000) | DIS_LDO; /* OFF */ |
| 221 | ret |= pmic_reg_write(p, MAX8997_REG_LDO8CTRL, val); |
| 222 | |
| 223 | /* LDO9 VCC_2.8V_PDA: 2.8V */ |
| 224 | val = max8997_reg_ldo(2800000) | EN_LDO; |
| 225 | ret |= pmic_reg_write(p, MAX8997_REG_LDO9CTRL, val); |
| 226 | |
| 227 | /* LDO10 VPLL: 1.1V */ |
| 228 | val = max8997_reg_ldo(1100000) | EN_LDO; |
| 229 | ret |= pmic_reg_write(p, MAX8997_REG_LDO10CTRL, val); |
| 230 | |
| 231 | /* LDO11 TOUCH: 2.8V */ |
| 232 | val = max8997_reg_ldo(2800000) | DIS_LDO; /* OFF */ |
| 233 | ret |= pmic_reg_write(p, MAX8997_REG_LDO11CTRL, val); |
| 234 | |
| 235 | /* LDO12 VTCAM: 1.8V */ |
| 236 | val = max8997_reg_ldo(1800000) | DIS_LDO; /* OFF */ |
| 237 | ret |= pmic_reg_write(p, MAX8997_REG_LDO12CTRL, val); |
| 238 | |
| 239 | /* LDO13 VCC_3.0_LCD: 3.0V */ |
| 240 | val = max8997_reg_ldo(3000000) | DIS_LDO; /* OFF */ |
| 241 | ret |= pmic_reg_write(p, MAX8997_REG_LDO13CTRL, val); |
| 242 | |
| 243 | /* LDO14 MOTOR: 3.0V */ |
| 244 | val = max8997_reg_ldo(3000000) | DIS_LDO; /* OFF */ |
| 245 | ret |= pmic_reg_write(p, MAX8997_REG_LDO14CTRL, val); |
| 246 | |
| 247 | /* LDO15 LED_A: 2.8V */ |
| 248 | val = max8997_reg_ldo(2800000) | DIS_LDO; /* OFF */ |
| 249 | ret |= pmic_reg_write(p, MAX8997_REG_LDO15CTRL, val); |
| 250 | |
| 251 | /* LDO16 CAM_SENSOR: 1.8V */ |
| 252 | val = max8997_reg_ldo(1800000) | DIS_LDO; /* OFF */ |
| 253 | ret |= pmic_reg_write(p, MAX8997_REG_LDO16CTRL, val); |
| 254 | |
| 255 | /* LDO17 VTF: 2.8V */ |
| 256 | val = max8997_reg_ldo(2800000) | DIS_LDO; /* OFF */ |
| 257 | ret |= pmic_reg_write(p, MAX8997_REG_LDO17CTRL, val); |
| 258 | |
| 259 | /* LDO18 TOUCH_LED 3.3V */ |
| 260 | val = max8997_reg_ldo(3300000) | DIS_LDO; /* OFF */ |
| 261 | ret |= pmic_reg_write(p, MAX8997_REG_LDO18CTRL, val); |
| 262 | |
| 263 | /* LDO21 VDDQ: 1.2V */ |
| 264 | val = max8997_reg_ldo(1200000) | EN_LDO; |
| 265 | ret |= pmic_reg_write(p, MAX8997_REG_LDO21CTRL, val); |
| 266 | |
| 267 | /* SAFEOUT for both 1 and 2: 4.9V, Active discharge, Enable */ |
| 268 | val = (SAFEOUT_4_90V << 0) | (SAFEOUT_4_90V << 2) | |
| 269 | ACTDISSAFEO1 | ACTDISSAFEO2 | ENSAFEOUT1 | ENSAFEOUT2; |
| 270 | ret |= pmic_reg_write(p, MAX8997_REG_SAFEOUTCTRL, val); |
| 271 | |
| 272 | if (ret) { |
| 273 | puts("MAX8997 PMIC setting error!\n"); |
| 274 | return -1; |
| 275 | } |
| 276 | return 0; |
| 277 | } |
| 278 | |
Piotr Wilczek | 4efd33a | 2014-03-07 14:59:48 +0100 | [diff] [blame] | 279 | int exynos_power_init(void) |
Łukasz Majewski | fa62766 | 2012-11-13 03:21:57 +0000 | [diff] [blame] | 280 | { |
Łukasz Majewski | fc2d44a | 2012-11-13 03:22:11 +0000 | [diff] [blame] | 281 | int chrg, ret; |
| 282 | struct power_battery *pb; |
| 283 | struct pmic *p_fg, *p_chrg, *p_muic, *p_bat; |
Łukasz Majewski | fa62766 | 2012-11-13 03:21:57 +0000 | [diff] [blame] | 284 | |
Łukasz Majewski | de55e75 | 2013-08-16 15:33:33 +0200 | [diff] [blame] | 285 | /* |
| 286 | * For PMIC/MUIC the I2C bus is named as I2C5, but it is connected |
| 287 | * to logical I2C adapter 0 |
| 288 | * |
| 289 | * The FUEL_GAUGE is marked as I2C9 on the schematic, but connected |
| 290 | * to logical I2C adapter 1 |
| 291 | */ |
Piotr Wilczek | 58bbd2b | 2013-11-20 10:43:49 +0100 | [diff] [blame] | 292 | ret = pmic_init(I2C_5); |
Łukasz Majewski | d72e0ae | 2012-11-13 03:22:05 +0000 | [diff] [blame] | 293 | ret |= pmic_init_max8997(); |
Piotr Wilczek | 97ae183 | 2013-12-18 15:43:37 +0100 | [diff] [blame] | 294 | ret |= power_fg_init(I2C_9); |
Piotr Wilczek | 58bbd2b | 2013-11-20 10:43:49 +0100 | [diff] [blame] | 295 | ret |= power_muic_init(I2C_5); |
Łukasz Majewski | e4a182a | 2012-11-13 03:22:08 +0000 | [diff] [blame] | 296 | ret |= power_bat_init(0); |
Łukasz Majewski | fa62766 | 2012-11-13 03:21:57 +0000 | [diff] [blame] | 297 | if (ret) |
| 298 | return ret; |
| 299 | |
Łukasz Majewski | fc2d44a | 2012-11-13 03:22:11 +0000 | [diff] [blame] | 300 | p_fg = pmic_get("MAX17042_FG"); |
| 301 | if (!p_fg) { |
| 302 | puts("MAX17042_FG: Not found\n"); |
| 303 | return -ENODEV; |
| 304 | } |
| 305 | |
| 306 | p_chrg = pmic_get("MAX8997_PMIC"); |
| 307 | if (!p_chrg) { |
| 308 | puts("MAX8997_PMIC: Not found\n"); |
| 309 | return -ENODEV; |
| 310 | } |
| 311 | |
| 312 | p_muic = pmic_get("MAX8997_MUIC"); |
| 313 | if (!p_muic) { |
| 314 | puts("MAX8997_MUIC: Not found\n"); |
| 315 | return -ENODEV; |
| 316 | } |
| 317 | |
| 318 | p_bat = pmic_get("BAT_TRATS"); |
| 319 | if (!p_bat) { |
| 320 | puts("BAT_TRATS: Not found\n"); |
| 321 | return -ENODEV; |
| 322 | } |
| 323 | |
| 324 | p_fg->parent = p_bat; |
| 325 | p_chrg->parent = p_bat; |
| 326 | p_muic->parent = p_bat; |
| 327 | |
| 328 | p_bat->low_power_mode = trats_low_power_mode; |
| 329 | p_bat->pbat->battery_init(p_bat, p_fg, p_chrg, p_muic); |
| 330 | |
| 331 | pb = p_bat->pbat; |
| 332 | chrg = p_muic->chrg->chrg_type(p_muic); |
| 333 | debug("CHARGER TYPE: %d\n", chrg); |
| 334 | |
| 335 | if (!p_chrg->chrg->chrg_bat_present(p_chrg)) { |
| 336 | puts("No battery detected\n"); |
Przemyslaw Marczak | dd0c48e | 2014-06-10 16:55:08 +0200 | [diff] [blame] | 337 | return 0; |
Łukasz Majewski | fc2d44a | 2012-11-13 03:22:11 +0000 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | p_fg->fg->fg_battery_check(p_fg, p_bat); |
| 341 | |
| 342 | if (pb->bat->state == CHARGE && chrg == CHARGER_USB) |
| 343 | puts("CHARGE Battery !\n"); |
| 344 | |
Łukasz Majewski | fa62766 | 2012-11-13 03:21:57 +0000 | [diff] [blame] | 345 | return 0; |
| 346 | } |
| 347 | |
HeungJun, Kim | b4b5468 | 2012-01-16 21:13:05 +0000 | [diff] [blame] | 348 | static unsigned int get_hw_revision(void) |
| 349 | { |
HeungJun, Kim | b4b5468 | 2012-01-16 21:13:05 +0000 | [diff] [blame] | 350 | int hwrev = 0; |
Simon Glass | 4f83d3d | 2014-10-20 19:48:39 -0600 | [diff] [blame] | 351 | char str[10]; |
HeungJun, Kim | b4b5468 | 2012-01-16 21:13:05 +0000 | [diff] [blame] | 352 | int i; |
| 353 | |
| 354 | /* hw_rev[3:0] == GPE1[3:0] */ |
Simon Glass | 4f83d3d | 2014-10-20 19:48:39 -0600 | [diff] [blame] | 355 | for (i = 0; i < 4; i++) { |
| 356 | int pin = i + EXYNOS4_GPIO_E10; |
| 357 | |
| 358 | sprintf(str, "hw_rev%d", i); |
| 359 | gpio_request(pin, str); |
| 360 | gpio_cfg_pin(pin, S5P_GPIO_INPUT); |
| 361 | gpio_set_pull(pin, S5P_GPIO_PULL_NONE); |
HeungJun, Kim | b4b5468 | 2012-01-16 21:13:05 +0000 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | udelay(1); |
| 365 | |
| 366 | for (i = 0; i < 4; i++) |
Akshay Saraswat | 1376cdd | 2014-05-13 10:30:14 +0530 | [diff] [blame] | 367 | hwrev |= (gpio_get_value(EXYNOS4_GPIO_E10 + i) << i); |
HeungJun, Kim | b4b5468 | 2012-01-16 21:13:05 +0000 | [diff] [blame] | 368 | |
| 369 | debug("hwrev 0x%x\n", hwrev); |
| 370 | |
| 371 | return hwrev; |
| 372 | } |
| 373 | |
| 374 | static void check_hw_revision(void) |
| 375 | { |
| 376 | int hwrev; |
| 377 | |
| 378 | hwrev = get_hw_revision(); |
| 379 | |
| 380 | board_rev |= hwrev; |
| 381 | } |
| 382 | |
HeungJun, Kim | b4b5468 | 2012-01-16 21:13:05 +0000 | [diff] [blame] | 383 | |
| 384 | #ifdef CONFIG_USB_GADGET |
| 385 | static int s5pc210_phy_control(int on) |
| 386 | { |
| 387 | int ret = 0; |
Łukasz Majewski | 6fa846b | 2012-04-25 23:30:18 +0000 | [diff] [blame] | 388 | u32 val = 0; |
Łukasz Majewski | 1c6dba1 | 2012-11-13 03:21:55 +0000 | [diff] [blame] | 389 | struct pmic *p = pmic_get("MAX8997_PMIC"); |
| 390 | if (!p) |
| 391 | return -ENODEV; |
HeungJun, Kim | b4b5468 | 2012-01-16 21:13:05 +0000 | [diff] [blame] | 392 | |
| 393 | if (pmic_probe(p)) |
| 394 | return -1; |
| 395 | |
| 396 | if (on) { |
Łukasz Majewski | 198cd74 | 2012-03-29 01:29:18 +0000 | [diff] [blame] | 397 | ret |= pmic_set_output(p, MAX8997_REG_SAFEOUTCTRL, |
| 398 | ENSAFEOUT1, LDO_ON); |
Łukasz Majewski | 6fa846b | 2012-04-25 23:30:18 +0000 | [diff] [blame] | 399 | ret |= pmic_reg_read(p, MAX8997_REG_LDO3CTRL, &val); |
| 400 | ret |= pmic_reg_write(p, MAX8997_REG_LDO3CTRL, EN_LDO | val); |
| 401 | |
| 402 | ret |= pmic_reg_read(p, MAX8997_REG_LDO8CTRL, &val); |
| 403 | ret |= pmic_reg_write(p, MAX8997_REG_LDO8CTRL, EN_LDO | val); |
HeungJun, Kim | b4b5468 | 2012-01-16 21:13:05 +0000 | [diff] [blame] | 404 | } else { |
Łukasz Majewski | 6fa846b | 2012-04-25 23:30:18 +0000 | [diff] [blame] | 405 | ret |= pmic_reg_read(p, MAX8997_REG_LDO8CTRL, &val); |
| 406 | ret |= pmic_reg_write(p, MAX8997_REG_LDO8CTRL, DIS_LDO | val); |
| 407 | |
| 408 | ret |= pmic_reg_read(p, MAX8997_REG_LDO3CTRL, &val); |
| 409 | ret |= pmic_reg_write(p, MAX8997_REG_LDO3CTRL, DIS_LDO | val); |
Łukasz Majewski | 198cd74 | 2012-03-29 01:29:18 +0000 | [diff] [blame] | 410 | ret |= pmic_set_output(p, MAX8997_REG_SAFEOUTCTRL, |
| 411 | ENSAFEOUT1, LDO_OFF); |
HeungJun, Kim | b4b5468 | 2012-01-16 21:13:05 +0000 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | if (ret) { |
Łukasz Majewski | 198cd74 | 2012-03-29 01:29:18 +0000 | [diff] [blame] | 415 | puts("MAX8997 LDO setting error!\n"); |
HeungJun, Kim | b4b5468 | 2012-01-16 21:13:05 +0000 | [diff] [blame] | 416 | return -1; |
| 417 | } |
| 418 | |
| 419 | return 0; |
| 420 | } |
| 421 | |
Marek Vasut | 6939aca | 2015-12-04 02:23:29 +0100 | [diff] [blame] | 422 | struct dwc2_plat_otg_data s5pc210_otg_data = { |
HeungJun, Kim | b4b5468 | 2012-01-16 21:13:05 +0000 | [diff] [blame] | 423 | .phy_control = s5pc210_phy_control, |
| 424 | .regs_phy = EXYNOS4_USBPHY_BASE, |
| 425 | .regs_otg = EXYNOS4_USBOTG_BASE, |
| 426 | .usb_phy_ctrl = EXYNOS4_USBPHY_CONTROL, |
| 427 | .usb_flags = PHY0_SLEEP, |
| 428 | }; |
Lukasz Majewski | 51de176 | 2012-08-06 14:41:10 +0200 | [diff] [blame] | 429 | |
Troy Kisky | de8ae7b | 2013-10-10 15:27:55 -0700 | [diff] [blame] | 430 | int board_usb_init(int index, enum usb_init_type init) |
Lukasz Majewski | 51de176 | 2012-08-06 14:41:10 +0200 | [diff] [blame] | 431 | { |
| 432 | debug("USB_udc_probe\n"); |
Marek Vasut | 01b61fa | 2015-12-04 02:26:33 +0100 | [diff] [blame] | 433 | return dwc2_udc_probe(&s5pc210_otg_data); |
Lukasz Majewski | 51de176 | 2012-08-06 14:41:10 +0200 | [diff] [blame] | 434 | } |
Przemyslaw Marczak | 99b0235 | 2013-12-02 13:54:01 +0100 | [diff] [blame] | 435 | |
Mateusz Zalega | 21fe3f7 | 2014-04-30 13:07:48 +0200 | [diff] [blame] | 436 | int g_dnl_board_usb_cable_connected(void) |
Przemyslaw Marczak | 99b0235 | 2013-12-02 13:54:01 +0100 | [diff] [blame] | 437 | { |
| 438 | struct pmic *muic = pmic_get("MAX8997_MUIC"); |
| 439 | if (!muic) |
| 440 | return 0; |
| 441 | |
| 442 | return !!muic->chrg->chrg_type(muic); |
| 443 | } |
| 444 | #endif |
HeungJun, Kim | b4b5468 | 2012-01-16 21:13:05 +0000 | [diff] [blame] | 445 | |
| 446 | static void pmic_reset(void) |
| 447 | { |
Akshay Saraswat | 1376cdd | 2014-05-13 10:30:14 +0530 | [diff] [blame] | 448 | gpio_direction_output(EXYNOS4_GPIO_X07, 1); |
| 449 | gpio_set_pull(EXYNOS4_GPIO_X27, S5P_GPIO_PULL_NONE); |
HeungJun, Kim | b4b5468 | 2012-01-16 21:13:05 +0000 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | static void board_clock_init(void) |
| 453 | { |
| 454 | struct exynos4_clock *clk = |
| 455 | (struct exynos4_clock *)samsung_get_base_clock(); |
| 456 | |
| 457 | writel(CLK_SRC_CPU_VAL, (unsigned int)&clk->src_cpu); |
| 458 | writel(CLK_SRC_TOP0_VAL, (unsigned int)&clk->src_top0); |
| 459 | writel(CLK_SRC_FSYS_VAL, (unsigned int)&clk->src_fsys); |
| 460 | writel(CLK_SRC_PERIL0_VAL, (unsigned int)&clk->src_peril0); |
| 461 | |
| 462 | writel(CLK_DIV_CPU0_VAL, (unsigned int)&clk->div_cpu0); |
| 463 | writel(CLK_DIV_CPU1_VAL, (unsigned int)&clk->div_cpu1); |
| 464 | writel(CLK_DIV_DMC0_VAL, (unsigned int)&clk->div_dmc0); |
| 465 | writel(CLK_DIV_DMC1_VAL, (unsigned int)&clk->div_dmc1); |
| 466 | writel(CLK_DIV_LEFTBUS_VAL, (unsigned int)&clk->div_leftbus); |
| 467 | writel(CLK_DIV_RIGHTBUS_VAL, (unsigned int)&clk->div_rightbus); |
| 468 | writel(CLK_DIV_TOP_VAL, (unsigned int)&clk->div_top); |
| 469 | writel(CLK_DIV_FSYS1_VAL, (unsigned int)&clk->div_fsys1); |
| 470 | writel(CLK_DIV_FSYS2_VAL, (unsigned int)&clk->div_fsys2); |
| 471 | writel(CLK_DIV_FSYS3_VAL, (unsigned int)&clk->div_fsys3); |
| 472 | writel(CLK_DIV_PERIL0_VAL, (unsigned int)&clk->div_peril0); |
| 473 | writel(CLK_DIV_PERIL3_VAL, (unsigned int)&clk->div_peril3); |
| 474 | |
| 475 | writel(PLL_LOCKTIME, (unsigned int)&clk->apll_lock); |
| 476 | writel(PLL_LOCKTIME, (unsigned int)&clk->mpll_lock); |
| 477 | writel(PLL_LOCKTIME, (unsigned int)&clk->epll_lock); |
| 478 | writel(PLL_LOCKTIME, (unsigned int)&clk->vpll_lock); |
| 479 | writel(APLL_CON1_VAL, (unsigned int)&clk->apll_con1); |
| 480 | writel(APLL_CON0_VAL, (unsigned int)&clk->apll_con0); |
| 481 | writel(MPLL_CON1_VAL, (unsigned int)&clk->mpll_con1); |
| 482 | writel(MPLL_CON0_VAL, (unsigned int)&clk->mpll_con0); |
| 483 | writel(EPLL_CON1_VAL, (unsigned int)&clk->epll_con1); |
| 484 | writel(EPLL_CON0_VAL, (unsigned int)&clk->epll_con0); |
| 485 | writel(VPLL_CON1_VAL, (unsigned int)&clk->vpll_con1); |
| 486 | writel(VPLL_CON0_VAL, (unsigned int)&clk->vpll_con0); |
| 487 | |
| 488 | writel(CLK_GATE_IP_CAM_VAL, (unsigned int)&clk->gate_ip_cam); |
| 489 | writel(CLK_GATE_IP_VP_VAL, (unsigned int)&clk->gate_ip_tv); |
| 490 | writel(CLK_GATE_IP_MFC_VAL, (unsigned int)&clk->gate_ip_mfc); |
| 491 | writel(CLK_GATE_IP_G3D_VAL, (unsigned int)&clk->gate_ip_g3d); |
| 492 | writel(CLK_GATE_IP_IMAGE_VAL, (unsigned int)&clk->gate_ip_image); |
| 493 | writel(CLK_GATE_IP_LCD0_VAL, (unsigned int)&clk->gate_ip_lcd0); |
| 494 | writel(CLK_GATE_IP_LCD1_VAL, (unsigned int)&clk->gate_ip_lcd1); |
| 495 | writel(CLK_GATE_IP_FSYS_VAL, (unsigned int)&clk->gate_ip_fsys); |
| 496 | writel(CLK_GATE_IP_GPS_VAL, (unsigned int)&clk->gate_ip_gps); |
| 497 | writel(CLK_GATE_IP_PERIL_VAL, (unsigned int)&clk->gate_ip_peril); |
| 498 | writel(CLK_GATE_IP_PERIR_VAL, (unsigned int)&clk->gate_ip_perir); |
| 499 | writel(CLK_GATE_BLOCK_VAL, (unsigned int)&clk->gate_block); |
| 500 | } |
| 501 | |
HeungJun, Kim | b4b5468 | 2012-01-16 21:13:05 +0000 | [diff] [blame] | 502 | static void board_power_init(void) |
| 503 | { |
| 504 | struct exynos4_power *pwr = |
| 505 | (struct exynos4_power *)samsung_get_base_power(); |
| 506 | |
| 507 | /* PS HOLD */ |
| 508 | writel(EXYNOS4_PS_HOLD_CON_VAL, (unsigned int)&pwr->ps_hold_control); |
| 509 | |
| 510 | /* Set power down */ |
| 511 | writel(0, (unsigned int)&pwr->cam_configuration); |
| 512 | writel(0, (unsigned int)&pwr->tv_configuration); |
| 513 | writel(0, (unsigned int)&pwr->mfc_configuration); |
| 514 | writel(0, (unsigned int)&pwr->g3d_configuration); |
| 515 | writel(0, (unsigned int)&pwr->lcd1_configuration); |
| 516 | writel(0, (unsigned int)&pwr->gps_configuration); |
| 517 | writel(0, (unsigned int)&pwr->gps_alive_configuration); |
Piotr Wilczek | 9b4faf2 | 2012-10-08 20:45:42 +0000 | [diff] [blame] | 518 | |
| 519 | /* It is necessary to power down core 1 */ |
| 520 | /* to successfully boot CPU1 in kernel */ |
| 521 | writel(0, (unsigned int)&pwr->arm_core1_configuration); |
HeungJun, Kim | b4b5468 | 2012-01-16 21:13:05 +0000 | [diff] [blame] | 522 | } |
| 523 | |
Piotr Wilczek | 4efd33a | 2014-03-07 14:59:48 +0100 | [diff] [blame] | 524 | static void exynos_uart_init(void) |
HeungJun, Kim | b4b5468 | 2012-01-16 21:13:05 +0000 | [diff] [blame] | 525 | { |
HeungJun, Kim | b4b5468 | 2012-01-16 21:13:05 +0000 | [diff] [blame] | 526 | /* UART_SEL GPY4[7] (part2) at EXYNOS4 */ |
Simon Glass | 4f83d3d | 2014-10-20 19:48:39 -0600 | [diff] [blame] | 527 | gpio_request(EXYNOS4_GPIO_Y47, "uart_sel"); |
Akshay Saraswat | 1376cdd | 2014-05-13 10:30:14 +0530 | [diff] [blame] | 528 | gpio_set_pull(EXYNOS4_GPIO_Y47, S5P_GPIO_PULL_UP); |
| 529 | gpio_direction_output(EXYNOS4_GPIO_Y47, 1); |
HeungJun, Kim | b4b5468 | 2012-01-16 21:13:05 +0000 | [diff] [blame] | 530 | } |
| 531 | |
Piotr Wilczek | 4efd33a | 2014-03-07 14:59:48 +0100 | [diff] [blame] | 532 | int exynos_early_init_f(void) |
HeungJun, Kim | b4b5468 | 2012-01-16 21:13:05 +0000 | [diff] [blame] | 533 | { |
Minkyu Kang | 5826990 | 2012-01-18 15:56:47 +0900 | [diff] [blame] | 534 | wdt_stop(); |
HeungJun, Kim | b4b5468 | 2012-01-16 21:13:05 +0000 | [diff] [blame] | 535 | pmic_reset(); |
| 536 | board_clock_init(); |
Piotr Wilczek | 4efd33a | 2014-03-07 14:59:48 +0100 | [diff] [blame] | 537 | exynos_uart_init(); |
HeungJun, Kim | b4b5468 | 2012-01-16 21:13:05 +0000 | [diff] [blame] | 538 | board_power_init(); |
| 539 | |
| 540 | return 0; |
| 541 | } |
Donghwa Lee | 9ad0ddc | 2012-04-05 19:36:27 +0000 | [diff] [blame] | 542 | |
Ajay Kumar | 41022a1 | 2013-02-21 23:52:57 +0000 | [diff] [blame] | 543 | void exynos_reset_lcd(void) |
Donghwa Lee | 9ad0ddc | 2012-04-05 19:36:27 +0000 | [diff] [blame] | 544 | { |
Simon Glass | 4f83d3d | 2014-10-20 19:48:39 -0600 | [diff] [blame] | 545 | gpio_request(EXYNOS4_GPIO_Y45, "lcd_reset"); |
Akshay Saraswat | 1376cdd | 2014-05-13 10:30:14 +0530 | [diff] [blame] | 546 | gpio_direction_output(EXYNOS4_GPIO_Y45, 1); |
Donghwa Lee | 9ad0ddc | 2012-04-05 19:36:27 +0000 | [diff] [blame] | 547 | udelay(10000); |
Akshay Saraswat | 1376cdd | 2014-05-13 10:30:14 +0530 | [diff] [blame] | 548 | gpio_direction_output(EXYNOS4_GPIO_Y45, 0); |
Donghwa Lee | 9ad0ddc | 2012-04-05 19:36:27 +0000 | [diff] [blame] | 549 | udelay(10000); |
Akshay Saraswat | 1376cdd | 2014-05-13 10:30:14 +0530 | [diff] [blame] | 550 | gpio_direction_output(EXYNOS4_GPIO_Y45, 1); |
Donghwa Lee | 9ad0ddc | 2012-04-05 19:36:27 +0000 | [diff] [blame] | 551 | } |
| 552 | |
Piotr Wilczek | 4efd33a | 2014-03-07 14:59:48 +0100 | [diff] [blame] | 553 | int lcd_power(void) |
Donghwa Lee | 9ad0ddc | 2012-04-05 19:36:27 +0000 | [diff] [blame] | 554 | { |
| 555 | int ret = 0; |
Łukasz Majewski | 1c6dba1 | 2012-11-13 03:21:55 +0000 | [diff] [blame] | 556 | struct pmic *p = pmic_get("MAX8997_PMIC"); |
| 557 | if (!p) |
| 558 | return -ENODEV; |
Donghwa Lee | 9ad0ddc | 2012-04-05 19:36:27 +0000 | [diff] [blame] | 559 | |
| 560 | if (pmic_probe(p)) |
| 561 | return 0; |
| 562 | |
| 563 | /* LDO15 voltage: 2.2v */ |
| 564 | ret |= pmic_reg_write(p, MAX8997_REG_LDO15CTRL, 0x1c | EN_LDO); |
| 565 | /* LDO13 voltage: 3.0v */ |
| 566 | ret |= pmic_reg_write(p, MAX8997_REG_LDO13CTRL, 0x2c | EN_LDO); |
| 567 | |
| 568 | if (ret) { |
| 569 | puts("MAX8997 LDO setting error!\n"); |
| 570 | return -1; |
| 571 | } |
| 572 | |
| 573 | return 0; |
| 574 | } |
| 575 | |
Piotr Wilczek | 4efd33a | 2014-03-07 14:59:48 +0100 | [diff] [blame] | 576 | int mipi_power(void) |
Donghwa Lee | 9ad0ddc | 2012-04-05 19:36:27 +0000 | [diff] [blame] | 577 | { |
| 578 | int ret = 0; |
Łukasz Majewski | 1c6dba1 | 2012-11-13 03:21:55 +0000 | [diff] [blame] | 579 | struct pmic *p = pmic_get("MAX8997_PMIC"); |
| 580 | if (!p) |
| 581 | return -ENODEV; |
Donghwa Lee | 9ad0ddc | 2012-04-05 19:36:27 +0000 | [diff] [blame] | 582 | |
| 583 | if (pmic_probe(p)) |
| 584 | return 0; |
| 585 | |
| 586 | /* LDO3 voltage: 1.1v */ |
| 587 | ret |= pmic_reg_write(p, MAX8997_REG_LDO3CTRL, 0x6 | EN_LDO); |
| 588 | /* LDO4 voltage: 1.8v */ |
| 589 | ret |= pmic_reg_write(p, MAX8997_REG_LDO4CTRL, 0x14 | EN_LDO); |
| 590 | |
| 591 | if (ret) { |
| 592 | puts("MAX8997 LDO setting error!\n"); |
| 593 | return -1; |
| 594 | } |
| 595 | |
| 596 | return 0; |
| 597 | } |
| 598 | |
Simon Glass | b4a967e | 2016-02-21 21:08:54 -0700 | [diff] [blame] | 599 | #ifdef CONFIG_LCD |
Piotr Wilczek | 4efd33a | 2014-03-07 14:59:48 +0100 | [diff] [blame] | 600 | void exynos_lcd_misc_init(vidinfo_t *vid) |
Donghwa Lee | 5eec193 | 2012-04-25 13:29:39 +0000 | [diff] [blame] | 601 | { |
Donghwa Lee | 37980dd | 2012-05-09 19:23:46 +0000 | [diff] [blame] | 602 | #ifdef CONFIG_TIZEN |
| 603 | get_tizen_logo_info(vid); |
| 604 | #endif |
Piotr Wilczek | 4efd33a | 2014-03-07 14:59:48 +0100 | [diff] [blame] | 605 | #ifdef CONFIG_S6E8AX0 |
Donghwa Lee | 9ad0ddc | 2012-04-05 19:36:27 +0000 | [diff] [blame] | 606 | s6e8ax0_init(); |
Donghwa Lee | 9ad0ddc | 2012-04-05 19:36:27 +0000 | [diff] [blame] | 607 | setenv("lcdinfo", "lcd=s6e8ax0"); |
Piotr Wilczek | 60d3a30 | 2014-01-22 15:54:35 +0100 | [diff] [blame] | 608 | #endif |
Przemyslaw Marczak | 283a320 | 2014-01-22 11:24:12 +0100 | [diff] [blame] | 609 | } |
Simon Glass | b4a967e | 2016-02-21 21:08:54 -0700 | [diff] [blame] | 610 | #endif |