Amar | 752f4c4 | 2013-04-27 11:42:57 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 Samsung Electronics |
| 3 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 4 | * SPDX-License-Identifier: GPL-2.0+ |
Amar | 752f4c4 | 2013-04-27 11:42:57 +0530 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <fdtdec.h> |
| 9 | #include <asm/io.h> |
| 10 | #include <errno.h> |
| 11 | #include <i2c.h> |
| 12 | #include <netdev.h> |
| 13 | #include <spi.h> |
Simon Glass | a9cf6da | 2014-05-20 06:01:42 -0600 | [diff] [blame] | 14 | #include <asm/gpio.h> |
Amar | 752f4c4 | 2013-04-27 11:42:57 +0530 | [diff] [blame] | 15 | #include <asm/arch/cpu.h> |
| 16 | #include <asm/arch/dwmmc.h> |
Amar | 752f4c4 | 2013-04-27 11:42:57 +0530 | [diff] [blame] | 17 | #include <asm/arch/mmc.h> |
| 18 | #include <asm/arch/pinmux.h> |
| 19 | #include <asm/arch/power.h> |
| 20 | #include <asm/arch/sromc.h> |
| 21 | #include <power/pmic.h> |
| 22 | #include <power/max77686_pmic.h> |
Aaron Durbin | 0f2e739 | 2014-05-20 06:01:39 -0600 | [diff] [blame] | 23 | #include <power/tps65090_pmic.h> |
Amar | 752f4c4 | 2013-04-27 11:42:57 +0530 | [diff] [blame] | 24 | #include <tmu.h> |
| 25 | |
| 26 | DECLARE_GLOBAL_DATA_PTR; |
| 27 | |
Amar | 752f4c4 | 2013-04-27 11:42:57 +0530 | [diff] [blame] | 28 | #ifdef CONFIG_SOUND_MAX98095 |
Rajeshwari Birje | 71ebb33 | 2013-12-26 09:44:17 +0530 | [diff] [blame] | 29 | static void board_enable_audio_codec(void) |
Amar | 752f4c4 | 2013-04-27 11:42:57 +0530 | [diff] [blame] | 30 | { |
Amar | 752f4c4 | 2013-04-27 11:42:57 +0530 | [diff] [blame] | 31 | /* Enable MAX98095 Codec */ |
Akshay Saraswat | f6ae1ca | 2014-05-13 10:30:14 +0530 | [diff] [blame] | 32 | gpio_direction_output(EXYNOS5_GPIO_X17, 1); |
| 33 | gpio_set_pull(EXYNOS5_GPIO_X17, S5P_GPIO_PULL_NONE); |
Amar | 752f4c4 | 2013-04-27 11:42:57 +0530 | [diff] [blame] | 34 | } |
| 35 | #endif |
| 36 | |
Rajeshwari Birje | 71ebb33 | 2013-12-26 09:44:17 +0530 | [diff] [blame] | 37 | int exynos_init(void) |
Hung-ying Tyan | eb28fda | 2013-05-15 18:27:34 +0800 | [diff] [blame] | 38 | { |
Amar | 752f4c4 | 2013-04-27 11:42:57 +0530 | [diff] [blame] | 39 | #ifdef CONFIG_SOUND_MAX98095 |
| 40 | board_enable_audio_codec(); |
| 41 | #endif |
| 42 | return 0; |
| 43 | } |
| 44 | |
Simon Glass | 2f7547f | 2014-05-20 06:01:33 -0600 | [diff] [blame] | 45 | #if defined(CONFIG_POWER) |
| 46 | #ifdef CONFIG_POWER_MAX77686 |
| 47 | static int pmic_reg_update(struct pmic *p, int reg, uint regval) |
| 48 | { |
| 49 | u32 val; |
| 50 | int ret = 0; |
| 51 | |
| 52 | ret = pmic_reg_read(p, reg, &val); |
| 53 | if (ret) { |
| 54 | debug("%s: PMIC %d register read failed\n", __func__, reg); |
| 55 | return -1; |
| 56 | } |
| 57 | val |= regval; |
| 58 | ret = pmic_reg_write(p, reg, val); |
| 59 | if (ret) { |
| 60 | debug("%s: PMIC %d register write failed\n", __func__, reg); |
| 61 | return -1; |
| 62 | } |
| 63 | return 0; |
| 64 | } |
| 65 | |
| 66 | static int max77686_init(void) |
| 67 | { |
| 68 | struct pmic *p; |
| 69 | |
| 70 | if (pmic_init(I2C_PMIC)) |
| 71 | return -1; |
| 72 | |
| 73 | p = pmic_get("MAX77686_PMIC"); |
| 74 | if (!p) |
| 75 | return -ENODEV; |
| 76 | |
| 77 | if (pmic_probe(p)) |
| 78 | return -1; |
| 79 | |
| 80 | if (pmic_reg_update(p, MAX77686_REG_PMIC_32KHZ, MAX77686_32KHCP_EN)) |
| 81 | return -1; |
| 82 | |
| 83 | if (pmic_reg_update(p, MAX77686_REG_PMIC_BBAT, |
| 84 | MAX77686_BBCHOSTEN | MAX77686_BBCVS_3_5V)) |
| 85 | return -1; |
| 86 | |
| 87 | /* VDD_MIF */ |
| 88 | if (pmic_reg_write(p, MAX77686_REG_PMIC_BUCK1OUT, |
| 89 | MAX77686_BUCK1OUT_1V)) { |
| 90 | debug("%s: PMIC %d register write failed\n", __func__, |
| 91 | MAX77686_REG_PMIC_BUCK1OUT); |
| 92 | return -1; |
| 93 | } |
| 94 | |
| 95 | if (pmic_reg_update(p, MAX77686_REG_PMIC_BUCK1CRTL, |
| 96 | MAX77686_BUCK1CTRL_EN)) |
| 97 | return -1; |
| 98 | |
| 99 | /* VDD_ARM */ |
| 100 | if (pmic_reg_write(p, MAX77686_REG_PMIC_BUCK2DVS1, |
| 101 | MAX77686_BUCK2DVS1_1_3V)) { |
| 102 | debug("%s: PMIC %d register write failed\n", __func__, |
| 103 | MAX77686_REG_PMIC_BUCK2DVS1); |
| 104 | return -1; |
| 105 | } |
| 106 | |
| 107 | if (pmic_reg_update(p, MAX77686_REG_PMIC_BUCK2CTRL1, |
| 108 | MAX77686_BUCK2CTRL_ON)) |
| 109 | return -1; |
| 110 | |
| 111 | /* VDD_INT */ |
| 112 | if (pmic_reg_write(p, MAX77686_REG_PMIC_BUCK3DVS1, |
| 113 | MAX77686_BUCK3DVS1_1_0125V)) { |
| 114 | debug("%s: PMIC %d register write failed\n", __func__, |
| 115 | MAX77686_REG_PMIC_BUCK3DVS1); |
| 116 | return -1; |
| 117 | } |
| 118 | |
| 119 | if (pmic_reg_update(p, MAX77686_REG_PMIC_BUCK3CTRL, |
| 120 | MAX77686_BUCK3CTRL_ON)) |
| 121 | return -1; |
| 122 | |
| 123 | /* VDD_G3D */ |
| 124 | if (pmic_reg_write(p, MAX77686_REG_PMIC_BUCK4DVS1, |
| 125 | MAX77686_BUCK4DVS1_1_2V)) { |
| 126 | debug("%s: PMIC %d register write failed\n", __func__, |
| 127 | MAX77686_REG_PMIC_BUCK4DVS1); |
| 128 | return -1; |
| 129 | } |
| 130 | |
| 131 | if (pmic_reg_update(p, MAX77686_REG_PMIC_BUCK4CTRL1, |
| 132 | MAX77686_BUCK3CTRL_ON)) |
| 133 | return -1; |
| 134 | |
| 135 | /* VDD_LDO2 */ |
| 136 | if (pmic_reg_update(p, MAX77686_REG_PMIC_LDO2CTRL1, |
| 137 | MAX77686_LD02CTRL1_1_5V | EN_LDO)) |
| 138 | return -1; |
| 139 | |
| 140 | /* VDD_LDO3 */ |
| 141 | if (pmic_reg_update(p, MAX77686_REG_PMIC_LDO3CTRL1, |
| 142 | MAX77686_LD03CTRL1_1_8V | EN_LDO)) |
| 143 | return -1; |
| 144 | |
| 145 | /* VDD_LDO5 */ |
| 146 | if (pmic_reg_update(p, MAX77686_REG_PMIC_LDO5CTRL1, |
| 147 | MAX77686_LD05CTRL1_1_8V | EN_LDO)) |
| 148 | return -1; |
| 149 | |
| 150 | /* VDD_LDO10 */ |
| 151 | if (pmic_reg_update(p, MAX77686_REG_PMIC_LDO10CTRL1, |
| 152 | MAX77686_LD10CTRL1_1_8V | EN_LDO)) |
| 153 | return -1; |
| 154 | |
| 155 | return 0; |
| 156 | } |
| 157 | #endif /* CONFIG_POWER_MAX77686 */ |
| 158 | |
| 159 | int exynos_power_init(void) |
| 160 | { |
| 161 | int ret = 0; |
| 162 | |
| 163 | #ifdef CONFIG_POWER_MAX77686 |
| 164 | ret = max77686_init(); |
Aaron Durbin | 0f2e739 | 2014-05-20 06:01:39 -0600 | [diff] [blame] | 165 | if (ret) |
| 166 | return ret; |
Simon Glass | 2f7547f | 2014-05-20 06:01:33 -0600 | [diff] [blame] | 167 | #endif |
Aaron Durbin | 0f2e739 | 2014-05-20 06:01:39 -0600 | [diff] [blame] | 168 | #ifdef CONFIG_POWER_TPS65090 |
| 169 | /* |
| 170 | * The TPS65090 may not be in the device tree. If so, it is not |
| 171 | * an error. |
| 172 | */ |
| 173 | ret = tps65090_init(); |
| 174 | if (ret == 0 || ret == -ENODEV) |
| 175 | return 0; |
| 176 | #endif |
| 177 | |
Simon Glass | 2f7547f | 2014-05-20 06:01:33 -0600 | [diff] [blame] | 178 | return ret; |
| 179 | } |
| 180 | #endif /* CONFIG_POWER */ |
| 181 | |
Amar | 752f4c4 | 2013-04-27 11:42:57 +0530 | [diff] [blame] | 182 | #ifdef CONFIG_LCD |
Simon Glass | a9cf6da | 2014-05-20 06:01:42 -0600 | [diff] [blame] | 183 | static int board_dp_bridge_setup(void) |
| 184 | { |
| 185 | const int max_tries = 10; |
| 186 | int num_tries, node; |
| 187 | |
| 188 | /* |
| 189 | * TODO(sjg): Use device tree for GPIOs when exynos GPIO |
| 190 | * numbering patch is in mainline. |
| 191 | */ |
| 192 | debug("%s\n", __func__); |
| 193 | node = fdtdec_next_compatible(gd->fdt_blob, 0, COMPAT_NXP_PTN3460); |
| 194 | if (node < 0) { |
| 195 | debug("%s: No node for DP bridge in device tree\n", __func__); |
| 196 | return -ENODEV; |
| 197 | } |
| 198 | |
| 199 | /* Setup the GPIOs */ |
| 200 | |
| 201 | /* PD is ACTIVE_LOW, and initially de-asserted */ |
| 202 | gpio_set_pull(EXYNOS5_GPIO_Y25, S5P_GPIO_PULL_NONE); |
| 203 | gpio_direction_output(EXYNOS5_GPIO_Y25, 1); |
| 204 | |
| 205 | /* Reset is ACTIVE_LOW */ |
| 206 | gpio_set_pull(EXYNOS5_GPIO_X15, S5P_GPIO_PULL_NONE); |
| 207 | gpio_direction_output(EXYNOS5_GPIO_X15, 0); |
| 208 | |
| 209 | udelay(10); |
| 210 | gpio_set_value(EXYNOS5_GPIO_X15, 1); |
| 211 | |
| 212 | gpio_direction_input(EXYNOS5_GPIO_X07); |
| 213 | |
| 214 | /* |
| 215 | * We need to wait for 90ms after bringing up the bridge since there |
| 216 | * is a phantom "high" on the HPD chip during its bootup. The phantom |
| 217 | * high comes within 7ms of de-asserting PD and persists for at least |
| 218 | * 15ms. The real high comes roughly 50ms after PD is de-asserted. The |
| 219 | * phantom high makes it hard for us to know when the NXP chip is up. |
| 220 | */ |
| 221 | mdelay(90); |
| 222 | |
| 223 | for (num_tries = 0; num_tries < max_tries; num_tries++) { |
| 224 | /* Check HPD. If it's high, we're all good. */ |
| 225 | if (gpio_get_value(EXYNOS5_GPIO_X07)) |
| 226 | return 0; |
| 227 | |
| 228 | debug("%s: eDP bridge failed to come up; try %d of %d\n", |
| 229 | __func__, num_tries, max_tries); |
| 230 | } |
| 231 | |
| 232 | /* Immediately go into bridge reset if the hp line is not high */ |
| 233 | return -ENODEV; |
| 234 | } |
| 235 | |
Amar | 752f4c4 | 2013-04-27 11:42:57 +0530 | [diff] [blame] | 236 | void exynos_cfg_lcd_gpio(void) |
| 237 | { |
Amar | 752f4c4 | 2013-04-27 11:42:57 +0530 | [diff] [blame] | 238 | /* For Backlight */ |
Akshay Saraswat | f6ae1ca | 2014-05-13 10:30:14 +0530 | [diff] [blame] | 239 | gpio_cfg_pin(EXYNOS5_GPIO_B20, S5P_GPIO_OUTPUT); |
| 240 | gpio_set_value(EXYNOS5_GPIO_B20, 1); |
Amar | 752f4c4 | 2013-04-27 11:42:57 +0530 | [diff] [blame] | 241 | |
| 242 | /* LCD power on */ |
Akshay Saraswat | f6ae1ca | 2014-05-13 10:30:14 +0530 | [diff] [blame] | 243 | gpio_cfg_pin(EXYNOS5_GPIO_X15, S5P_GPIO_OUTPUT); |
| 244 | gpio_set_value(EXYNOS5_GPIO_X15, 1); |
Amar | 752f4c4 | 2013-04-27 11:42:57 +0530 | [diff] [blame] | 245 | |
| 246 | /* Set Hotplug detect for DP */ |
Akshay Saraswat | f6ae1ca | 2014-05-13 10:30:14 +0530 | [diff] [blame] | 247 | gpio_cfg_pin(EXYNOS5_GPIO_X07, S5P_GPIO_FUNC(0x3)); |
Amar | 752f4c4 | 2013-04-27 11:42:57 +0530 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | void exynos_set_dp_phy(unsigned int onoff) |
| 251 | { |
| 252 | set_dp_phy_ctrl(onoff); |
| 253 | } |
Simon Glass | a9cf6da | 2014-05-20 06:01:42 -0600 | [diff] [blame] | 254 | |
| 255 | void exynos_backlight_on(unsigned int on) |
| 256 | { |
| 257 | debug("%s(%u)\n", __func__, on); |
| 258 | |
| 259 | if (!on) |
| 260 | return; |
| 261 | |
| 262 | #ifdef CONFIG_POWER_TPS65090 |
| 263 | int ret; |
| 264 | |
| 265 | ret = tps65090_fet_enable(1); /* Enable FET1, backlight */ |
| 266 | if (ret) |
| 267 | return; |
| 268 | |
| 269 | /* T5 in the LCD timing spec (defined as > 10ms) */ |
| 270 | mdelay(10); |
| 271 | |
| 272 | /* board_dp_backlight_pwm */ |
| 273 | gpio_direction_output(EXYNOS5_GPIO_B20, 1); |
| 274 | |
| 275 | /* T6 in the LCD timing spec (defined as > 10ms) */ |
| 276 | mdelay(10); |
| 277 | |
| 278 | /* board_dp_backlight_en */ |
| 279 | gpio_direction_output(EXYNOS5_GPIO_X30, 1); |
| 280 | #endif |
| 281 | } |
| 282 | |
| 283 | void exynos_lcd_power_on(void) |
| 284 | { |
| 285 | int ret; |
| 286 | |
| 287 | debug("%s\n", __func__); |
| 288 | |
| 289 | #ifdef CONFIG_POWER_TPS65090 |
| 290 | /* board_dp_lcd_vdd */ |
| 291 | tps65090_fet_enable(6); /* Enable FET6, lcd panel */ |
| 292 | #endif |
| 293 | |
| 294 | ret = board_dp_bridge_setup(); |
| 295 | if (ret && ret != -ENODEV) |
| 296 | printf("LCD bridge failed to enable: %d\n", ret); |
| 297 | } |
| 298 | |
Amar | 752f4c4 | 2013-04-27 11:42:57 +0530 | [diff] [blame] | 299 | #endif |