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