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