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> |
| 13 | #include <asm/arch/cpu.h> |
| 14 | #include <asm/arch/gpio.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> |
HeungJun, Kim | b4b5468 | 2012-01-16 21:13:05 +0000 | [diff] [blame] | 21 | #include <usb/s3c_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); |
Lukasz Majewski | 51de176 | 2012-08-06 14:41:10 +0200 | [diff] [blame] | 44 | struct s3c_plat_otg_data s5pc210_otg_data; |
| 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 */ |
Akshay Saraswat | 1376cdd | 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 | c877879 | 2012-09-04 23:15:21 +0000 | [diff] [blame] | 68 | } |
| 69 | |
Łukasz Majewski | b6a3dc6 | 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 | d72e0ae | 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 | 4efd33a | 2014-03-07 14:59:48 +0100 | [diff] [blame] | 277 | int exynos_power_init(void) |
Łukasz Majewski | fa62766 | 2012-11-13 03:21:57 +0000 | [diff] [blame] | 278 | { |
Łukasz Majewski | fc2d44a | 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 | fa62766 | 2012-11-13 03:21:57 +0000 | [diff] [blame] | 282 | |
Łukasz Majewski | de55e75 | 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 | 58bbd2b | 2013-11-20 10:43:49 +0100 | [diff] [blame] | 290 | ret = pmic_init(I2C_5); |
Łukasz Majewski | d72e0ae | 2012-11-13 03:22:05 +0000 | [diff] [blame] | 291 | ret |= pmic_init_max8997(); |
Piotr Wilczek | 97ae183 | 2013-12-18 15:43:37 +0100 | [diff] [blame] | 292 | ret |= power_fg_init(I2C_9); |
Piotr Wilczek | 58bbd2b | 2013-11-20 10:43:49 +0100 | [diff] [blame] | 293 | ret |= power_muic_init(I2C_5); |
Łukasz Majewski | e4a182a | 2012-11-13 03:22:08 +0000 | [diff] [blame] | 294 | ret |= power_bat_init(0); |
Łukasz Majewski | fa62766 | 2012-11-13 03:21:57 +0000 | [diff] [blame] | 295 | if (ret) |
| 296 | return ret; |
| 297 | |
Łukasz Majewski | fc2d44a | 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 | fa62766 | 2012-11-13 03:21:57 +0000 | [diff] [blame] | 343 | return 0; |
| 344 | } |
| 345 | |
HeungJun, Kim | b4b5468 | 2012-01-16 21:13:05 +0000 | [diff] [blame] | 346 | static unsigned int get_hw_revision(void) |
| 347 | { |
HeungJun, Kim | b4b5468 | 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 | 1376cdd | 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 | b4b5468 | 2012-01-16 21:13:05 +0000 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | udelay(1); |
| 358 | |
| 359 | for (i = 0; i < 4; i++) |
Akshay Saraswat | 1376cdd | 2014-05-13 10:30:14 +0530 | [diff] [blame] | 360 | hwrev |= (gpio_get_value(EXYNOS4_GPIO_E10 + i) << i); |
HeungJun, Kim | b4b5468 | 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 | b4b5468 | 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 | 6fa846b | 2012-04-25 23:30:18 +0000 | [diff] [blame] | 381 | u32 val = 0; |
Łukasz Majewski | 1c6dba1 | 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 | b4b5468 | 2012-01-16 21:13:05 +0000 | [diff] [blame] | 385 | |
| 386 | if (pmic_probe(p)) |
| 387 | return -1; |
| 388 | |
| 389 | if (on) { |
Łukasz Majewski | 198cd74 | 2012-03-29 01:29:18 +0000 | [diff] [blame] | 390 | ret |= pmic_set_output(p, MAX8997_REG_SAFEOUTCTRL, |
| 391 | ENSAFEOUT1, LDO_ON); |
Łukasz Majewski | 6fa846b | 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 | b4b5468 | 2012-01-16 21:13:05 +0000 | [diff] [blame] | 397 | } else { |
Łukasz Majewski | 6fa846b | 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 | 198cd74 | 2012-03-29 01:29:18 +0000 | [diff] [blame] | 403 | ret |= pmic_set_output(p, MAX8997_REG_SAFEOUTCTRL, |
| 404 | ENSAFEOUT1, LDO_OFF); |
HeungJun, Kim | b4b5468 | 2012-01-16 21:13:05 +0000 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | if (ret) { |
Łukasz Majewski | 198cd74 | 2012-03-29 01:29:18 +0000 | [diff] [blame] | 408 | puts("MAX8997 LDO setting error!\n"); |
HeungJun, Kim | b4b5468 | 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 | 51de176 | 2012-08-06 14:41:10 +0200 | [diff] [blame] | 422 | |
Troy Kisky | de8ae7b | 2013-10-10 15:27:55 -0700 | [diff] [blame] | 423 | int board_usb_init(int index, enum usb_init_type init) |
Lukasz Majewski | 51de176 | 2012-08-06 14:41:10 +0200 | [diff] [blame] | 424 | { |
| 425 | debug("USB_udc_probe\n"); |
Mateusz Zalega | d862f89 | 2013-10-04 19:22:26 +0200 | [diff] [blame] | 426 | return s3c_udc_probe(&s5pc210_otg_data); |
Lukasz Majewski | 51de176 | 2012-08-06 14:41:10 +0200 | [diff] [blame] | 427 | } |
Przemyslaw Marczak | 99b0235 | 2013-12-02 13:54:01 +0100 | [diff] [blame] | 428 | |
Mateusz Zalega | 21fe3f7 | 2014-04-30 13:07:48 +0200 | [diff] [blame] | 429 | int g_dnl_board_usb_cable_connected(void) |
Przemyslaw Marczak | 99b0235 | 2013-12-02 13:54:01 +0100 | [diff] [blame] | 430 | { |
| 431 | struct pmic *muic = pmic_get("MAX8997_MUIC"); |
| 432 | if (!muic) |
| 433 | return 0; |
| 434 | |
| 435 | return !!muic->chrg->chrg_type(muic); |
| 436 | } |
| 437 | #endif |
HeungJun, Kim | b4b5468 | 2012-01-16 21:13:05 +0000 | [diff] [blame] | 438 | |
| 439 | static void pmic_reset(void) |
| 440 | { |
Akshay Saraswat | 1376cdd | 2014-05-13 10:30:14 +0530 | [diff] [blame] | 441 | gpio_direction_output(EXYNOS4_GPIO_X07, 1); |
| 442 | gpio_set_pull(EXYNOS4_GPIO_X27, S5P_GPIO_PULL_NONE); |
HeungJun, Kim | b4b5468 | 2012-01-16 21:13:05 +0000 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | static void board_clock_init(void) |
| 446 | { |
| 447 | struct exynos4_clock *clk = |
| 448 | (struct exynos4_clock *)samsung_get_base_clock(); |
| 449 | |
| 450 | writel(CLK_SRC_CPU_VAL, (unsigned int)&clk->src_cpu); |
| 451 | writel(CLK_SRC_TOP0_VAL, (unsigned int)&clk->src_top0); |
| 452 | writel(CLK_SRC_FSYS_VAL, (unsigned int)&clk->src_fsys); |
| 453 | writel(CLK_SRC_PERIL0_VAL, (unsigned int)&clk->src_peril0); |
| 454 | |
| 455 | writel(CLK_DIV_CPU0_VAL, (unsigned int)&clk->div_cpu0); |
| 456 | writel(CLK_DIV_CPU1_VAL, (unsigned int)&clk->div_cpu1); |
| 457 | writel(CLK_DIV_DMC0_VAL, (unsigned int)&clk->div_dmc0); |
| 458 | writel(CLK_DIV_DMC1_VAL, (unsigned int)&clk->div_dmc1); |
| 459 | writel(CLK_DIV_LEFTBUS_VAL, (unsigned int)&clk->div_leftbus); |
| 460 | writel(CLK_DIV_RIGHTBUS_VAL, (unsigned int)&clk->div_rightbus); |
| 461 | writel(CLK_DIV_TOP_VAL, (unsigned int)&clk->div_top); |
| 462 | writel(CLK_DIV_FSYS1_VAL, (unsigned int)&clk->div_fsys1); |
| 463 | writel(CLK_DIV_FSYS2_VAL, (unsigned int)&clk->div_fsys2); |
| 464 | writel(CLK_DIV_FSYS3_VAL, (unsigned int)&clk->div_fsys3); |
| 465 | writel(CLK_DIV_PERIL0_VAL, (unsigned int)&clk->div_peril0); |
| 466 | writel(CLK_DIV_PERIL3_VAL, (unsigned int)&clk->div_peril3); |
| 467 | |
| 468 | writel(PLL_LOCKTIME, (unsigned int)&clk->apll_lock); |
| 469 | writel(PLL_LOCKTIME, (unsigned int)&clk->mpll_lock); |
| 470 | writel(PLL_LOCKTIME, (unsigned int)&clk->epll_lock); |
| 471 | writel(PLL_LOCKTIME, (unsigned int)&clk->vpll_lock); |
| 472 | writel(APLL_CON1_VAL, (unsigned int)&clk->apll_con1); |
| 473 | writel(APLL_CON0_VAL, (unsigned int)&clk->apll_con0); |
| 474 | writel(MPLL_CON1_VAL, (unsigned int)&clk->mpll_con1); |
| 475 | writel(MPLL_CON0_VAL, (unsigned int)&clk->mpll_con0); |
| 476 | writel(EPLL_CON1_VAL, (unsigned int)&clk->epll_con1); |
| 477 | writel(EPLL_CON0_VAL, (unsigned int)&clk->epll_con0); |
| 478 | writel(VPLL_CON1_VAL, (unsigned int)&clk->vpll_con1); |
| 479 | writel(VPLL_CON0_VAL, (unsigned int)&clk->vpll_con0); |
| 480 | |
| 481 | writel(CLK_GATE_IP_CAM_VAL, (unsigned int)&clk->gate_ip_cam); |
| 482 | writel(CLK_GATE_IP_VP_VAL, (unsigned int)&clk->gate_ip_tv); |
| 483 | writel(CLK_GATE_IP_MFC_VAL, (unsigned int)&clk->gate_ip_mfc); |
| 484 | writel(CLK_GATE_IP_G3D_VAL, (unsigned int)&clk->gate_ip_g3d); |
| 485 | writel(CLK_GATE_IP_IMAGE_VAL, (unsigned int)&clk->gate_ip_image); |
| 486 | writel(CLK_GATE_IP_LCD0_VAL, (unsigned int)&clk->gate_ip_lcd0); |
| 487 | writel(CLK_GATE_IP_LCD1_VAL, (unsigned int)&clk->gate_ip_lcd1); |
| 488 | writel(CLK_GATE_IP_FSYS_VAL, (unsigned int)&clk->gate_ip_fsys); |
| 489 | writel(CLK_GATE_IP_GPS_VAL, (unsigned int)&clk->gate_ip_gps); |
| 490 | writel(CLK_GATE_IP_PERIL_VAL, (unsigned int)&clk->gate_ip_peril); |
| 491 | writel(CLK_GATE_IP_PERIR_VAL, (unsigned int)&clk->gate_ip_perir); |
| 492 | writel(CLK_GATE_BLOCK_VAL, (unsigned int)&clk->gate_block); |
| 493 | } |
| 494 | |
HeungJun, Kim | b4b5468 | 2012-01-16 21:13:05 +0000 | [diff] [blame] | 495 | static void board_power_init(void) |
| 496 | { |
| 497 | struct exynos4_power *pwr = |
| 498 | (struct exynos4_power *)samsung_get_base_power(); |
| 499 | |
| 500 | /* PS HOLD */ |
| 501 | writel(EXYNOS4_PS_HOLD_CON_VAL, (unsigned int)&pwr->ps_hold_control); |
| 502 | |
| 503 | /* Set power down */ |
| 504 | writel(0, (unsigned int)&pwr->cam_configuration); |
| 505 | writel(0, (unsigned int)&pwr->tv_configuration); |
| 506 | writel(0, (unsigned int)&pwr->mfc_configuration); |
| 507 | writel(0, (unsigned int)&pwr->g3d_configuration); |
| 508 | writel(0, (unsigned int)&pwr->lcd1_configuration); |
| 509 | writel(0, (unsigned int)&pwr->gps_configuration); |
| 510 | writel(0, (unsigned int)&pwr->gps_alive_configuration); |
Piotr Wilczek | 9b4faf2 | 2012-10-08 20:45:42 +0000 | [diff] [blame] | 511 | |
| 512 | /* It is necessary to power down core 1 */ |
| 513 | /* to successfully boot CPU1 in kernel */ |
| 514 | writel(0, (unsigned int)&pwr->arm_core1_configuration); |
HeungJun, Kim | b4b5468 | 2012-01-16 21:13:05 +0000 | [diff] [blame] | 515 | } |
| 516 | |
Piotr Wilczek | 4efd33a | 2014-03-07 14:59:48 +0100 | [diff] [blame] | 517 | static void exynos_uart_init(void) |
HeungJun, Kim | b4b5468 | 2012-01-16 21:13:05 +0000 | [diff] [blame] | 518 | { |
HeungJun, Kim | b4b5468 | 2012-01-16 21:13:05 +0000 | [diff] [blame] | 519 | /* UART_SEL GPY4[7] (part2) at EXYNOS4 */ |
Akshay Saraswat | 1376cdd | 2014-05-13 10:30:14 +0530 | [diff] [blame] | 520 | gpio_set_pull(EXYNOS4_GPIO_Y47, S5P_GPIO_PULL_UP); |
| 521 | gpio_direction_output(EXYNOS4_GPIO_Y47, 1); |
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 | int exynos_early_init_f(void) |
HeungJun, Kim | b4b5468 | 2012-01-16 21:13:05 +0000 | [diff] [blame] | 525 | { |
Minkyu Kang | 5826990 | 2012-01-18 15:56:47 +0900 | [diff] [blame] | 526 | wdt_stop(); |
HeungJun, Kim | b4b5468 | 2012-01-16 21:13:05 +0000 | [diff] [blame] | 527 | pmic_reset(); |
| 528 | board_clock_init(); |
Piotr Wilczek | 4efd33a | 2014-03-07 14:59:48 +0100 | [diff] [blame] | 529 | exynos_uart_init(); |
HeungJun, Kim | b4b5468 | 2012-01-16 21:13:05 +0000 | [diff] [blame] | 530 | board_power_init(); |
| 531 | |
| 532 | return 0; |
| 533 | } |
Donghwa Lee | 9ad0ddc | 2012-04-05 19:36:27 +0000 | [diff] [blame] | 534 | |
Ajay Kumar | 41022a1 | 2013-02-21 23:52:57 +0000 | [diff] [blame] | 535 | void exynos_reset_lcd(void) |
Donghwa Lee | 9ad0ddc | 2012-04-05 19:36:27 +0000 | [diff] [blame] | 536 | { |
Akshay Saraswat | 1376cdd | 2014-05-13 10:30:14 +0530 | [diff] [blame] | 537 | gpio_direction_output(EXYNOS4_GPIO_Y45, 1); |
Donghwa Lee | 9ad0ddc | 2012-04-05 19:36:27 +0000 | [diff] [blame] | 538 | udelay(10000); |
Akshay Saraswat | 1376cdd | 2014-05-13 10:30:14 +0530 | [diff] [blame] | 539 | gpio_direction_output(EXYNOS4_GPIO_Y45, 0); |
Donghwa Lee | 9ad0ddc | 2012-04-05 19:36:27 +0000 | [diff] [blame] | 540 | udelay(10000); |
Akshay Saraswat | 1376cdd | 2014-05-13 10:30:14 +0530 | [diff] [blame] | 541 | gpio_direction_output(EXYNOS4_GPIO_Y45, 1); |
Donghwa Lee | 9ad0ddc | 2012-04-05 19:36:27 +0000 | [diff] [blame] | 542 | } |
| 543 | |
Piotr Wilczek | 4efd33a | 2014-03-07 14:59:48 +0100 | [diff] [blame] | 544 | int lcd_power(void) |
Donghwa Lee | 9ad0ddc | 2012-04-05 19:36:27 +0000 | [diff] [blame] | 545 | { |
| 546 | int ret = 0; |
Łukasz Majewski | 1c6dba1 | 2012-11-13 03:21:55 +0000 | [diff] [blame] | 547 | struct pmic *p = pmic_get("MAX8997_PMIC"); |
| 548 | if (!p) |
| 549 | return -ENODEV; |
Donghwa Lee | 9ad0ddc | 2012-04-05 19:36:27 +0000 | [diff] [blame] | 550 | |
| 551 | if (pmic_probe(p)) |
| 552 | return 0; |
| 553 | |
| 554 | /* LDO15 voltage: 2.2v */ |
| 555 | ret |= pmic_reg_write(p, MAX8997_REG_LDO15CTRL, 0x1c | EN_LDO); |
| 556 | /* LDO13 voltage: 3.0v */ |
| 557 | ret |= pmic_reg_write(p, MAX8997_REG_LDO13CTRL, 0x2c | EN_LDO); |
| 558 | |
| 559 | if (ret) { |
| 560 | puts("MAX8997 LDO setting error!\n"); |
| 561 | return -1; |
| 562 | } |
| 563 | |
| 564 | return 0; |
| 565 | } |
| 566 | |
Piotr Wilczek | 4efd33a | 2014-03-07 14:59:48 +0100 | [diff] [blame] | 567 | int mipi_power(void) |
Donghwa Lee | 9ad0ddc | 2012-04-05 19:36:27 +0000 | [diff] [blame] | 568 | { |
| 569 | int ret = 0; |
Łukasz Majewski | 1c6dba1 | 2012-11-13 03:21:55 +0000 | [diff] [blame] | 570 | struct pmic *p = pmic_get("MAX8997_PMIC"); |
| 571 | if (!p) |
| 572 | return -ENODEV; |
Donghwa Lee | 9ad0ddc | 2012-04-05 19:36:27 +0000 | [diff] [blame] | 573 | |
| 574 | if (pmic_probe(p)) |
| 575 | return 0; |
| 576 | |
| 577 | /* LDO3 voltage: 1.1v */ |
| 578 | ret |= pmic_reg_write(p, MAX8997_REG_LDO3CTRL, 0x6 | EN_LDO); |
| 579 | /* LDO4 voltage: 1.8v */ |
| 580 | ret |= pmic_reg_write(p, MAX8997_REG_LDO4CTRL, 0x14 | EN_LDO); |
| 581 | |
| 582 | if (ret) { |
| 583 | puts("MAX8997 LDO setting error!\n"); |
| 584 | return -1; |
| 585 | } |
| 586 | |
| 587 | return 0; |
| 588 | } |
| 589 | |
Piotr Wilczek | 4efd33a | 2014-03-07 14:59:48 +0100 | [diff] [blame] | 590 | void exynos_lcd_misc_init(vidinfo_t *vid) |
Donghwa Lee | 5eec193 | 2012-04-25 13:29:39 +0000 | [diff] [blame] | 591 | { |
Donghwa Lee | 37980dd | 2012-05-09 19:23:46 +0000 | [diff] [blame] | 592 | #ifdef CONFIG_TIZEN |
| 593 | get_tizen_logo_info(vid); |
| 594 | #endif |
Piotr Wilczek | 4efd33a | 2014-03-07 14:59:48 +0100 | [diff] [blame] | 595 | #ifdef CONFIG_S6E8AX0 |
Donghwa Lee | 9ad0ddc | 2012-04-05 19:36:27 +0000 | [diff] [blame] | 596 | s6e8ax0_init(); |
Donghwa Lee | 9ad0ddc | 2012-04-05 19:36:27 +0000 | [diff] [blame] | 597 | setenv("lcdinfo", "lcd=s6e8ax0"); |
Piotr Wilczek | 60d3a30 | 2014-01-22 15:54:35 +0100 | [diff] [blame] | 598 | #endif |
Przemyslaw Marczak | 283a320 | 2014-01-22 11:24:12 +0100 | [diff] [blame] | 599 | } |