434b213cc738b87cae04406f4307e8d7400d6417
[cascardo/linux.git] / arch / arm / mach-shmobile / board-marzen.c
1 /*
2  * marzen board support
3  *
4  * Copyright (C) 2011, 2013  Renesas Solutions Corp.
5  * Copyright (C) 2011  Magnus Damm
6  * Copyright (C) 2013  Cogent Embedded, Inc.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; version 2 of the License.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20  */
21
22 #include <linux/kernel.h>
23 #include <linux/init.h>
24 #include <linux/interrupt.h>
25 #include <linux/irq.h>
26 #include <linux/platform_device.h>
27 #include <linux/delay.h>
28 #include <linux/io.h>
29 #include <linux/leds.h>
30 #include <linux/dma-mapping.h>
31 #include <linux/pinctrl/machine.h>
32 #include <linux/platform_data/gpio-rcar.h>
33 #include <linux/platform_data/rcar-du.h>
34 #include <linux/platform_data/usb-rcar-phy.h>
35 #include <linux/regulator/fixed.h>
36 #include <linux/regulator/machine.h>
37 #include <linux/smsc911x.h>
38 #include <linux/spi/spi.h>
39 #include <linux/spi/sh_hspi.h>
40 #include <linux/mmc/host.h>
41 #include <linux/mmc/sh_mobile_sdhi.h>
42 #include <linux/mfd/tmio.h>
43 #include <media/soc_camera.h>
44 #include <mach/r8a7779.h>
45 #include <mach/common.h>
46 #include <mach/irqs.h>
47 #include <asm/mach-types.h>
48 #include <asm/mach/arch.h>
49 #include <asm/traps.h>
50
51 /* Fixed 3.3V regulator to be used by SDHI0 */
52 static struct regulator_consumer_supply fixed3v3_power_consumers[] = {
53         REGULATOR_SUPPLY("vmmc", "sh_mobile_sdhi.0"),
54         REGULATOR_SUPPLY("vqmmc", "sh_mobile_sdhi.0"),
55 };
56
57 /* Dummy supplies, where voltage doesn't matter */
58 static struct regulator_consumer_supply dummy_supplies[] = {
59         REGULATOR_SUPPLY("vddvario", "smsc911x"),
60         REGULATOR_SUPPLY("vdd33a", "smsc911x"),
61 };
62
63 /* USB PHY */
64 static struct resource usb_phy_resources[] = {
65         [0] = {
66                 .start          = 0xffe70800,
67                 .end            = 0xffe70900 - 1,
68                 .flags          = IORESOURCE_MEM,
69         },
70 };
71
72 static struct rcar_phy_platform_data usb_phy_platform_data;
73
74 static struct platform_device usb_phy = {
75         .name           = "rcar_usb_phy",
76         .id             = -1,
77         .dev  = {
78                 .platform_data = &usb_phy_platform_data,
79         },
80         .resource       = usb_phy_resources,
81         .num_resources  = ARRAY_SIZE(usb_phy_resources),
82 };
83
84 /* SMSC LAN89218 */
85 static struct resource smsc911x_resources[] = {
86         [0] = {
87                 .start          = 0x18000000, /* ExCS0 */
88                 .end            = 0x180000ff, /* A1->A7 */
89                 .flags          = IORESOURCE_MEM,
90         },
91         [1] = {
92                 .start          = irq_pin(1), /* IRQ 1 */
93                 .flags          = IORESOURCE_IRQ,
94         },
95 };
96
97 static struct smsc911x_platform_config smsc911x_platdata = {
98         .flags          = SMSC911X_USE_32BIT, /* 32-bit SW on 16-bit HW bus */
99         .phy_interface  = PHY_INTERFACE_MODE_MII,
100         .irq_polarity   = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
101         .irq_type       = SMSC911X_IRQ_TYPE_PUSH_PULL,
102 };
103
104 static struct platform_device eth_device = {
105         .name           = "smsc911x",
106         .id             = -1,
107         .dev  = {
108                 .platform_data = &smsc911x_platdata,
109         },
110         .resource       = smsc911x_resources,
111         .num_resources  = ARRAY_SIZE(smsc911x_resources),
112 };
113
114 static struct resource sdhi0_resources[] = {
115         [0] = {
116                 .name   = "sdhi0",
117                 .start  = 0xffe4c000,
118                 .end    = 0xffe4c0ff,
119                 .flags  = IORESOURCE_MEM,
120         },
121         [1] = {
122                 .start  = gic_iid(0x88),
123                 .flags  = IORESOURCE_IRQ,
124         },
125 };
126
127 static struct sh_mobile_sdhi_info sdhi0_platform_data = {
128         .tmio_flags = TMIO_MMC_WRPROTECT_DISABLE | TMIO_MMC_HAS_IDLE_WAIT,
129         .tmio_caps = MMC_CAP_SD_HIGHSPEED,
130 };
131
132 static struct platform_device sdhi0_device = {
133         .name = "sh_mobile_sdhi",
134         .num_resources = ARRAY_SIZE(sdhi0_resources),
135         .resource = sdhi0_resources,
136         .id = 0,
137         .dev = {
138                 .platform_data = &sdhi0_platform_data,
139         }
140 };
141
142 /* Thermal */
143 static struct resource thermal_resources[] = {
144         [0] = {
145                 .start          = 0xFFC48000,
146                 .end            = 0xFFC48038 - 1,
147                 .flags          = IORESOURCE_MEM,
148         },
149 };
150
151 static struct platform_device thermal_device = {
152         .name           = "rcar_thermal",
153         .resource       = thermal_resources,
154         .num_resources  = ARRAY_SIZE(thermal_resources),
155 };
156
157 /* HSPI */
158 static struct resource hspi_resources[] = {
159         [0] = {
160                 .start          = 0xFFFC7000,
161                 .end            = 0xFFFC7018 - 1,
162                 .flags          = IORESOURCE_MEM,
163         },
164 };
165
166 static struct platform_device hspi_device = {
167         .name   = "sh-hspi",
168         .id     = 0,
169         .resource       = hspi_resources,
170         .num_resources  = ARRAY_SIZE(hspi_resources),
171 };
172
173 /*
174  * DU
175  *
176  * The panel only specifies the [hv]display and [hv]total values. The position
177  * and width of the sync pulses don't matter, they're copied from VESA timings.
178  */
179 static struct rcar_du_encoder_data du_encoders[] = {
180         {
181                 .type = RCAR_DU_ENCODER_VGA,
182                 .output = RCAR_DU_OUTPUT_DPAD0,
183         }, {
184                 .type = RCAR_DU_ENCODER_LVDS,
185                 .output = RCAR_DU_OUTPUT_DPAD1,
186                 .connector.lvds.panel = {
187                         .width_mm = 210,
188                         .height_mm = 158,
189                         .mode = {
190                                 .clock = 65000,
191                                 .hdisplay = 1024,
192                                 .hsync_start = 1048,
193                                 .hsync_end = 1184,
194                                 .htotal = 1344,
195                                 .vdisplay = 768,
196                                 .vsync_start = 771,
197                                 .vsync_end = 777,
198                                 .vtotal = 806,
199                                 .flags = 0,
200                         },
201                 },
202         },
203 };
204
205 static const struct rcar_du_platform_data du_pdata __initconst = {
206         .encoders = du_encoders,
207         .num_encoders = ARRAY_SIZE(du_encoders),
208 };
209
210 static const struct resource du_resources[] __initconst = {
211         DEFINE_RES_MEM(0xfff80000, 0x40000),
212         DEFINE_RES_IRQ(gic_iid(0x3f)),
213 };
214
215 static void __init marzen_add_du_device(void)
216 {
217         struct platform_device_info info = {
218                 .name = "rcar-du-r8a7779",
219                 .id = -1,
220                 .res = du_resources,
221                 .num_res = ARRAY_SIZE(du_resources),
222                 .data = &du_pdata,
223                 .size_data = sizeof(du_pdata),
224                 .dma_mask = DMA_BIT_MASK(32),
225         };
226
227         platform_device_register_full(&info);
228 }
229
230 /* LEDS */
231 static struct gpio_led marzen_leds[] = {
232         {
233                 .name           = "led2",
234                 .gpio           = RCAR_GP_PIN(4, 29),
235                 .default_state  = LEDS_GPIO_DEFSTATE_ON,
236         }, {
237                 .name           = "led3",
238                 .gpio           = RCAR_GP_PIN(4, 30),
239                 .default_state  = LEDS_GPIO_DEFSTATE_ON,
240         }, {
241                 .name           = "led4",
242                 .gpio           = RCAR_GP_PIN(4, 31),
243                 .default_state  = LEDS_GPIO_DEFSTATE_ON,
244         },
245 };
246
247 static struct gpio_led_platform_data marzen_leds_pdata = {
248         .leds           = marzen_leds,
249         .num_leds       = ARRAY_SIZE(marzen_leds),
250 };
251
252 static struct platform_device leds_device = {
253         .name   = "leds-gpio",
254         .id     = 0,
255         .dev    = {
256                 .platform_data  = &marzen_leds_pdata,
257         },
258 };
259
260 static struct rcar_vin_platform_data vin_platform_data __initdata = {
261         .flags  = RCAR_VIN_BT656,
262 };
263
264 #define MARZEN_CAMERA(idx)                                      \
265 static struct i2c_board_info camera##idx##_info = {             \
266         I2C_BOARD_INFO("adv7180", 0x20 + (idx)),                \
267 };                                                              \
268                                                                 \
269 static struct soc_camera_link iclink##idx##_adv7180 = {         \
270         .bus_id         = 1 + 2 * (idx),                        \
271         .i2c_adapter_id = 0,                                    \
272         .board_info     = &camera##idx##_info,                  \
273 };                                                              \
274                                                                 \
275 static struct platform_device camera##idx##_device = {          \
276         .name   = "soc-camera-pdrv",                            \
277         .id     = idx,                                          \
278         .dev    = {                                             \
279                 .platform_data  = &iclink##idx##_adv7180,       \
280         },                                                      \
281 };
282
283 MARZEN_CAMERA(0);
284 MARZEN_CAMERA(1);
285
286 static struct platform_device *marzen_devices[] __initdata = {
287         &eth_device,
288         &sdhi0_device,
289         &thermal_device,
290         &hspi_device,
291         &leds_device,
292         &usb_phy,
293         &camera0_device,
294         &camera1_device,
295 };
296
297 static const struct pinctrl_map marzen_pinctrl_map[] = {
298         /* DU (CN10: ARGB0, CN13: LVDS) */
299         PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7779", "pfc-r8a7779",
300                                   "du0_rgb888", "du0"),
301         PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7779", "pfc-r8a7779",
302                                   "du0_sync_1", "du0"),
303         PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7779", "pfc-r8a7779",
304                                   "du0_clk_out_0", "du0"),
305         PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7779", "pfc-r8a7779",
306                                   "du1_rgb666", "du1"),
307         PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7779", "pfc-r8a7779",
308                                   "du1_sync_1", "du1"),
309         PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7779", "pfc-r8a7779",
310                                   "du1_clk_out", "du1"),
311         /* HSPI0 */
312         PIN_MAP_MUX_GROUP_DEFAULT("sh-hspi.0", "pfc-r8a7779",
313                                   "hspi0", "hspi0"),
314         /* SCIF2 (CN18: DEBUG0) */
315         PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.2", "pfc-r8a7779",
316                                   "scif2_data_c", "scif2"),
317         /* SCIF4 (CN19: DEBUG1) */
318         PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.4", "pfc-r8a7779",
319                                   "scif4_data", "scif4"),
320         /* SDHI0 */
321         PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-r8a7779",
322                                   "sdhi0_data4", "sdhi0"),
323         PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-r8a7779",
324                                   "sdhi0_ctrl", "sdhi0"),
325         PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-r8a7779",
326                                   "sdhi0_cd", "sdhi0"),
327         PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-r8a7779",
328                                   "sdhi0_wp", "sdhi0"),
329         /* SMSC */
330         PIN_MAP_MUX_GROUP_DEFAULT("smsc911x", "pfc-r8a7779",
331                                   "intc_irq1_b", "intc"),
332         PIN_MAP_MUX_GROUP_DEFAULT("smsc911x", "pfc-r8a7779",
333                                   "lbsc_ex_cs0", "lbsc"),
334         /* USB0 */
335         PIN_MAP_MUX_GROUP_DEFAULT("ehci-platform.0", "pfc-r8a7779",
336                                   "usb0", "usb0"),
337         /* USB1 */
338         PIN_MAP_MUX_GROUP_DEFAULT("ehci-platform.0", "pfc-r8a7779",
339                                   "usb1", "usb1"),
340         /* USB2 */
341         PIN_MAP_MUX_GROUP_DEFAULT("ehci-platform.1", "pfc-r8a7779",
342                                   "usb2", "usb2"),
343         /* VIN1 */
344         PIN_MAP_MUX_GROUP_DEFAULT("r8a7779-vin.1", "pfc-r8a7779",
345                                   "vin1_clk", "vin1"),
346         PIN_MAP_MUX_GROUP_DEFAULT("r8a7779-vin.1", "pfc-r8a7779",
347                                   "vin1_data8", "vin1"),
348         /* VIN3 */
349         PIN_MAP_MUX_GROUP_DEFAULT("r8a7779-vin.3", "pfc-r8a7779",
350                                   "vin3_clk", "vin3"),
351         PIN_MAP_MUX_GROUP_DEFAULT("r8a7779-vin.3", "pfc-r8a7779",
352                                   "vin3_data8", "vin3"),
353 };
354
355 static void __init marzen_init(void)
356 {
357         regulator_register_always_on(0, "fixed-3.3V", fixed3v3_power_consumers,
358                                 ARRAY_SIZE(fixed3v3_power_consumers), 3300000);
359         regulator_register_fixed(1, dummy_supplies,
360                                 ARRAY_SIZE(dummy_supplies));
361
362         pinctrl_register_mappings(marzen_pinctrl_map,
363                                   ARRAY_SIZE(marzen_pinctrl_map));
364         r8a7779_pinmux_init();
365         r8a7779_init_irq_extpin(1); /* IRQ1 as individual interrupt */
366
367         r8a7779_add_standard_devices();
368         r8a7779_add_vin_device(1, &vin_platform_data);
369         r8a7779_add_vin_device(3, &vin_platform_data);
370         platform_add_devices(marzen_devices, ARRAY_SIZE(marzen_devices));
371         marzen_add_du_device();
372 }
373
374 static const char *marzen_boards_compat_dt[] __initdata = {
375         "renesas,marzen",
376         NULL,
377 };
378
379 DT_MACHINE_START(MARZEN, "marzen")
380         .smp            = smp_ops(r8a7779_smp_ops),
381         .map_io         = r8a7779_map_io,
382         .init_early     = r8a7779_add_early_devices,
383         .init_irq       = r8a7779_init_irq_dt,
384         .init_machine   = marzen_init,
385         .init_late      = r8a7779_init_late,
386         .dt_compat      = marzen_boards_compat_dt,
387         .init_time      = r8a7779_earlytimer_init,
388 MACHINE_END