ARM: EXYNOS: Add reserve function to increase consistent memory
[cascardo/linux.git] / arch / arm / mach-exynos / mach-exynos5-dt.c
1 /*
2  * SAMSUNG EXYNOS5250 Flattened Device Tree enabled machine
3  *
4  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5  *              http://www.samsung.com
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10 */
11
12 #include <linux/gpio.h>
13 #include <linux/of_platform.h>
14 #include <linux/serial_core.h>
15 #include <linux/smsc911x.h>
16 #include <linux/delay.h>
17 #include <linux/i2c.h>
18 #include <linux/pwm_backlight.h>
19 #include <linux/mfd/wm8994/pdata.h>
20 #include <linux/regulator/machine.h>
21
22 #include <asm/mach/arch.h>
23 #include <asm/hardware/gic.h>
24 #include <mach/map.h>
25 #include <mach/ohci.h>
26 #include <mach/regs-pmu.h>
27
28 #include <plat/cpu.h>
29 #include <plat/regs-serial.h>
30 #include <plat/regs-srom.h>
31 #include <plat/backlight.h>
32 #include <plat/devs.h>
33 #include <plat/usb-phy.h>
34
35 #include <video/platform_lcd.h>
36
37 #include "common.h"
38
39 static void __init smsc911x_init(int ncs)
40 {
41         u32 data;
42
43         /* configure nCS1 width to 16 bits */
44         data = __raw_readl(S5P_SROM_BW) &
45                 ~(S5P_SROM_BW__CS_MASK << (ncs * 4));
46         data |= ((1 << S5P_SROM_BW__DATAWIDTH__SHIFT) |
47                 (1 << S5P_SROM_BW__WAITENABLE__SHIFT) |
48                 (1 << S5P_SROM_BW__BYTEENABLE__SHIFT)) << (ncs * 4);
49         __raw_writel(data, S5P_SROM_BW);
50
51         /* set timing for nCS1 suitable for ethernet chip */
52         __raw_writel((0x1 << S5P_SROM_BCX__PMC__SHIFT) |
53                 (0x9 << S5P_SROM_BCX__TACP__SHIFT) |
54                 (0xc << S5P_SROM_BCX__TCAH__SHIFT) |
55                 (0x1 << S5P_SROM_BCX__TCOH__SHIFT) |
56                 (0x6 << S5P_SROM_BCX__TACC__SHIFT) |
57                 (0x1 << S5P_SROM_BCX__TCOS__SHIFT) |
58                 (0x1 << S5P_SROM_BCX__TACS__SHIFT),
59                 S5P_SROM_BC0 + (ncs * 4));
60 }
61
62 static void mipi_lcd_set_power(struct plat_lcd_data *pd,
63                         unsigned int power)
64 {
65         /* reset */
66         gpio_request_one(EXYNOS5_GPX1(5), GPIOF_OUT_INIT_HIGH, "GPX1");
67
68         mdelay(20);
69         if (power) {
70                 /* fire nRESET on power up */
71                 gpio_set_value(EXYNOS5_GPX1(5), 0);
72                 mdelay(20);
73                 gpio_set_value(EXYNOS5_GPX1(5), 1);
74                 mdelay(20);
75                 gpio_free(EXYNOS5_GPX1(5));
76         } else {
77                 /* fire nRESET on power off */
78                 gpio_set_value(EXYNOS5_GPX1(5), 0);
79                 mdelay(20);
80                 gpio_set_value(EXYNOS5_GPX1(5), 1);
81                 mdelay(20);
82                 gpio_free(EXYNOS5_GPX1(5));
83         }
84         mdelay(20);
85         /*
86          * Request lcd_bl_en GPIO for smdk5250_bl_notify().
87          * TODO: Fix this so we are not at risk of requesting the GPIO
88          * multiple times, this should be done with device tree, and
89          * likely integrated into the plat-samsung/dev-backlight.c init.
90          */
91         gpio_request_one(EXYNOS5_GPX3(0), GPIOF_OUT_INIT_LOW, "GPX3");
92 }
93
94 static int smdk5250_match_fb(struct plat_lcd_data *pd, struct fb_info *info)
95 {
96         /* Don't call .set_power callback while unblanking */
97         return 0;
98 }
99
100 static struct plat_lcd_data smdk5250_mipi_lcd_data = {
101         .set_power      = mipi_lcd_set_power,
102         .match_fb       = smdk5250_match_fb,
103 };
104
105 static struct platform_device smdk5250_mipi_lcd = {
106         .name                   = "platform-lcd",
107         .dev.platform_data      = &smdk5250_mipi_lcd_data,
108 };
109
110 static int smdk5250_bl_notify(struct device *unused, int brightness)
111 {
112         /* manage lcd_bl_en signal */
113         if (brightness)
114                 gpio_set_value(EXYNOS5_GPX3(0), 1);
115         else
116                 gpio_set_value(EXYNOS5_GPX3(0), 0);
117
118         return brightness;
119 }
120
121 /* LCD Backlight data */
122 static struct samsung_bl_gpio_info smdk5250_bl_gpio_info = {
123         .no     = EXYNOS5_GPB2(0),
124         .func   = S3C_GPIO_SFN(2),
125 };
126
127 static struct platform_pwm_backlight_data smdk5250_bl_data = {
128         .pwm_period_ns  = 1000,
129         .notify         = smdk5250_bl_notify,
130 };
131
132 struct platform_device exynos_device_md0 = {
133         .name = "exynos-mdev",
134         .id = 0,
135 };
136
137 struct platform_device exynos_device_md1 = {
138         .name = "exynos-mdev",
139         .id = 1,
140 };
141
142 struct platform_device exynos_device_md2 = {
143         .name = "exynos-mdev",
144         .id = 2,
145 };
146
147 static struct regulator_consumer_supply wm8994_avdd1_supply =
148         REGULATOR_SUPPLY("AVDD1", "1-001a");
149
150 static struct regulator_consumer_supply wm8994_dcvdd_supply =
151         REGULATOR_SUPPLY("DCVDD", "1-001a");
152
153 static struct regulator_init_data wm8994_ldo1_data = {
154         .constraints    = {
155                 .name           = "AVDD1",
156         },
157         .num_consumer_supplies  = 1,
158         .consumer_supplies      = &wm8994_avdd1_supply,
159 };
160
161 static struct regulator_init_data wm8994_ldo2_data = {
162         .constraints    = {
163         .name                   = "DCVDD",
164                 },
165         .num_consumer_supplies  = 1,
166         .consumer_supplies      = &wm8994_dcvdd_supply,
167 };
168
169 static struct wm8994_pdata wm8994_platform_data = {
170         /* configure gpio1 function: 0x0001(Logic level input/output) */
171         .gpio_defaults[0] = 0x0001,
172         /* If the i2s0 and i2s2 is enabled simultaneously */
173         .gpio_defaults[7] = 0x8100, /* GPIO8  DACDAT3 in */
174         .gpio_defaults[8] = 0x0100, /* GPIO9  ADCDAT3 out */
175         .gpio_defaults[9] = 0x0100, /* GPIO10 LRCLK3  out */
176         .gpio_defaults[10] = 0x0100,/* GPIO11 BCLK3   out */
177         .ldo[0] = { 0, &wm8994_ldo1_data },
178         .ldo[1] = { 0, &wm8994_ldo2_data },
179 };
180
181 static struct i2c_board_info i2c_devs1[] __initdata = {
182         {
183                 I2C_BOARD_INFO("wm8994", 0x1a),
184                 .platform_data  = &wm8994_platform_data,
185         },
186 };
187
188 /*
189  * The following lookup table is used to override device names when devices
190  * are registered from device tree. This is temporarily added to enable
191  * device tree support addition for the EXYNOS5 architecture.
192  *
193  * For drivers that require platform data to be provided from the machine
194  * file, a platform data pointer can also be supplied along with the
195  * devices names. Usually, the platform data elements that cannot be parsed
196  * from the device tree by the drivers (example: function pointers) are
197  * supplied. But it should be noted that this is a temporary mechanism and
198  * at some point, the drivers should be capable of parsing all the platform
199  * data from the device tree.
200  */
201 static const struct of_dev_auxdata exynos5250_auxdata_lookup[] __initconst = {
202         OF_DEV_AUXDATA("samsung,exynos4210-uart", EXYNOS5_PA_UART0,
203                                 "exynos4210-uart.0", NULL),
204         OF_DEV_AUXDATA("samsung,exynos4210-uart", EXYNOS5_PA_UART1,
205                                 "exynos4210-uart.1", NULL),
206         OF_DEV_AUXDATA("samsung,exynos4210-uart", EXYNOS5_PA_UART2,
207                                 "exynos4210-uart.2", NULL),
208         OF_DEV_AUXDATA("samsung,exynos4210-uart", EXYNOS5_PA_UART3,
209                                 "exynos4210-uart.3", NULL),
210         OF_DEV_AUXDATA("samsung,s3c2440-i2c", EXYNOS5_PA_IIC(0),
211                                 "s3c2440-i2c.0", NULL),
212         OF_DEV_AUXDATA("samsung,s3c2440-i2c", EXYNOS5_PA_IIC(1),
213                                 "s3c2440-i2c.1", NULL),
214         OF_DEV_AUXDATA("synopsis,dw-mshc-exynos5250", 0x12200000,
215                                 "dw_mmc.0", NULL),
216         OF_DEV_AUXDATA("synopsis,dw-mshc-exynos5250", 0x12210000,
217                                 "dw_mmc.1", NULL),
218         OF_DEV_AUXDATA("synopsis,dw-mshc-exynos5250", 0x12220000,
219                                 "dw_mmc.2", NULL),
220         OF_DEV_AUXDATA("synopsis,dw-mshc-exynos5250", 0x12230000,
221                                 "dw_mmc.3", NULL),
222         OF_DEV_AUXDATA("arm,pl330", EXYNOS5_PA_PDMA0, "dma-pl330.0", NULL),
223         OF_DEV_AUXDATA("arm,pl330", EXYNOS5_PA_PDMA1, "dma-pl330.1", NULL),
224         OF_DEV_AUXDATA("arm,pl330", EXYNOS5_PA_MDMA1, "dma-pl330.2", NULL),
225         {},
226 };
227
228 static struct platform_device *smdk5250_devices[] __initdata = {
229         &smdk5250_mipi_lcd, /* for platform_lcd device */
230         &exynos_device_md0, /* for media device framework */
231         &exynos_device_md1, /* for media device framework */
232         &exynos_device_md2, /* for media device framework */
233         &samsung_asoc_dma,  /* for audio dma interface device */
234 };
235
236 static void __init exynos5250_dt_map_io(void)
237 {
238         exynos_init_io(NULL, 0);
239         s3c24xx_init_clocks(24000000);
240 }
241
242 static void __init exynos5_reserve(void)
243 {
244         /* required to have enough address range to remap the IOMMU
245          * allocated buffers */
246         init_consistent_dma_size(SZ_64M);
247 }
248
249 static void s5p_tv_setup(void)
250 {
251         /* direct HPD to HDMI chip */
252         gpio_request(EXYNOS5_GPX3(7), "hpd-plug");
253
254         gpio_direction_input(EXYNOS5_GPX3(7));
255         s3c_gpio_cfgpin(EXYNOS5_GPX3(7), S3C_GPIO_SFN(0x3));
256         s3c_gpio_setpull(EXYNOS5_GPX3(7), S3C_GPIO_PULL_NONE);
257 }
258
259 static void exynos5_i2c_setup(void)
260 {
261         /* Setup the low-speed i2c controller interrupts */
262         writel(0x0, EXYNOS5_SYS_I2C_CFG);
263 }
264
265 static void __init exynos5250_dt_machine_init(void)
266 {
267         if (of_machine_is_compatible("samsung,smdk5250"))
268                 smsc911x_init(1);
269         samsung_bl_set(&smdk5250_bl_gpio_info, &smdk5250_bl_data);
270
271         if (gpio_request_one(EXYNOS5_GPX2(6), GPIOF_OUT_INIT_HIGH,
272                 "HOST_VBUS_CONTROL")) {
273                 printk(KERN_ERR "failed to request gpio_host_vbus\n");
274         } else {
275                 s3c_gpio_setpull(EXYNOS5_GPX2(6), S3C_GPIO_PULL_NONE);
276                 gpio_free(EXYNOS5_GPX2(6));
277         }
278
279         exynos5_i2c_setup();
280
281         i2c_register_board_info(1, i2c_devs1, ARRAY_SIZE(i2c_devs1));
282
283         of_platform_populate(NULL, of_default_bus_match_table,
284                                 exynos5250_auxdata_lookup, NULL);
285
286         s5p_tv_setup();
287
288         platform_add_devices(smdk5250_devices, ARRAY_SIZE(smdk5250_devices));
289 }
290
291 static char const *exynos5250_dt_compat[] __initdata = {
292         "samsung,exynos5250",
293         NULL
294 };
295
296 DT_MACHINE_START(EXYNOS5_DT, "SAMSUNG EXYNOS5 (Flattened Device Tree)")
297         /* Maintainer: Kukjin Kim <kgene.kim@samsung.com> */
298         .init_irq       = exynos5_init_irq,
299         .reserve        = exynos5_reserve,
300         .map_io         = exynos5250_dt_map_io,
301         .handle_irq     = gic_handle_irq,
302         .init_machine   = exynos5250_dt_machine_init,
303         .timer          = &exynos4_timer,
304         .dt_compat      = exynos5250_dt_compat,
305         .restart        = exynos5_restart,
306 MACHINE_END