exynos5: support tps65090 pmic
[oweals/u-boot.git] / board / samsung / smdk5250 / exynos5-dt.c
1 /*
2  * Copyright (C) 2012 Samsung Electronics
3  *
4  * SPDX-License-Identifier:     GPL-2.0+
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>
14 #include <asm/arch/cpu.h>
15 #include <asm/arch/dwmmc.h>
16 #include <asm/arch/gpio.h>
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>
23 #include <power/tps65090_pmic.h>
24 #include <tmu.h>
25
26 DECLARE_GLOBAL_DATA_PTR;
27
28 #ifdef CONFIG_SOUND_MAX98095
29 static void board_enable_audio_codec(void)
30 {
31         /* Enable MAX98095 Codec */
32         gpio_direction_output(EXYNOS5_GPIO_X17, 1);
33         gpio_set_pull(EXYNOS5_GPIO_X17, S5P_GPIO_PULL_NONE);
34 }
35 #endif
36
37 int exynos_init(void)
38 {
39 #ifdef CONFIG_SOUND_MAX98095
40         board_enable_audio_codec();
41 #endif
42         return 0;
43 }
44
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();
165         if (ret)
166                 return ret;
167 #endif
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
178         return ret;
179 }
180 #endif  /* CONFIG_POWER */
181
182 #ifdef CONFIG_LCD
183 void exynos_cfg_lcd_gpio(void)
184 {
185         /* For Backlight */
186         gpio_cfg_pin(EXYNOS5_GPIO_B20, S5P_GPIO_OUTPUT);
187         gpio_set_value(EXYNOS5_GPIO_B20, 1);
188
189         /* LCD power on */
190         gpio_cfg_pin(EXYNOS5_GPIO_X15, S5P_GPIO_OUTPUT);
191         gpio_set_value(EXYNOS5_GPIO_X15, 1);
192
193         /* Set Hotplug detect for DP */
194         gpio_cfg_pin(EXYNOS5_GPIO_X07, S5P_GPIO_FUNC(0x3));
195 }
196
197 void exynos_set_dp_phy(unsigned int onoff)
198 {
199         set_dp_phy_ctrl(onoff);
200 }
201 #endif