ARM: shmobile: Remove FSF address from copyright headers
[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
18 #include <linux/kernel.h>
19 #include <linux/init.h>
20 #include <linux/interrupt.h>
21 #include <linux/irq.h>
22 #include <linux/platform_device.h>
23 #include <linux/delay.h>
24 #include <linux/io.h>
25 #include <linux/leds.h>
26 #include <linux/dma-mapping.h>
27 #include <linux/pinctrl/machine.h>
28 #include <linux/platform_data/camera-rcar.h>
29 #include <linux/platform_data/gpio-rcar.h>
30 #include <linux/platform_data/rcar-du.h>
31 #include <linux/platform_data/usb-rcar-phy.h>
32 #include <linux/regulator/fixed.h>
33 #include <linux/regulator/machine.h>
34 #include <linux/smsc911x.h>
35 #include <linux/spi/spi.h>
36 #include <linux/spi/sh_hspi.h>
37 #include <linux/mmc/host.h>
38 #include <linux/mmc/sh_mobile_sdhi.h>
39 #include <linux/mfd/tmio.h>
40
41 #include <media/soc_camera.h>
42 #include <asm/mach-types.h>
43 #include <asm/mach/arch.h>
44 #include <asm/traps.h>
45
46 #include "common.h"
47 #include "irqs.h"
48 #include "r8a7779.h"
49
50 /* Fixed 3.3V regulator to be used by SDHI0 */
51 static struct regulator_consumer_supply fixed3v3_power_consumers[] = {
52         REGULATOR_SUPPLY("vmmc", "sh_mobile_sdhi.0"),
53         REGULATOR_SUPPLY("vqmmc", "sh_mobile_sdhi.0"),
54 };
55
56 /* Dummy supplies, where voltage doesn't matter */
57 static struct regulator_consumer_supply dummy_supplies[] = {
58         REGULATOR_SUPPLY("vddvario", "smsc911x"),
59         REGULATOR_SUPPLY("vdd33a", "smsc911x"),
60 };
61
62 /* USB PHY */
63 static struct resource usb_phy_resources[] = {
64         [0] = {
65                 .start          = 0xffe70800,
66                 .end            = 0xffe70900 - 1,
67                 .flags          = IORESOURCE_MEM,
68         },
69 };
70
71 static struct rcar_phy_platform_data usb_phy_platform_data;
72
73 static struct platform_device usb_phy = {
74         .name           = "rcar_usb_phy",
75         .id             = -1,
76         .dev  = {
77                 .platform_data = &usb_phy_platform_data,
78         },
79         .resource       = usb_phy_resources,
80         .num_resources  = ARRAY_SIZE(usb_phy_resources),
81 };
82
83 /* SMSC LAN89218 */
84 static struct resource smsc911x_resources[] = {
85         [0] = {
86                 .start          = 0x18000000, /* ExCS0 */
87                 .end            = 0x180000ff, /* A1->A7 */
88                 .flags          = IORESOURCE_MEM,
89         },
90         [1] = {
91                 .start          = irq_pin(1), /* IRQ 1 */
92                 .flags          = IORESOURCE_IRQ,
93         },
94 };
95
96 static struct smsc911x_platform_config smsc911x_platdata = {
97         .flags          = SMSC911X_USE_32BIT, /* 32-bit SW on 16-bit HW bus */
98         .phy_interface  = PHY_INTERFACE_MODE_MII,
99         .irq_polarity   = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
100         .irq_type       = SMSC911X_IRQ_TYPE_PUSH_PULL,
101 };
102
103 static struct platform_device eth_device = {
104         .name           = "smsc911x",
105         .id             = -1,
106         .dev  = {
107                 .platform_data = &smsc911x_platdata,
108         },
109         .resource       = smsc911x_resources,
110         .num_resources  = ARRAY_SIZE(smsc911x_resources),
111 };
112
113 static struct resource sdhi0_resources[] = {
114         [0] = {
115                 .name   = "sdhi0",
116                 .start  = 0xffe4c000,
117                 .end    = 0xffe4c0ff,
118                 .flags  = IORESOURCE_MEM,
119         },
120         [1] = {
121                 .start  = gic_iid(0x88),
122                 .flags  = IORESOURCE_IRQ,
123         },
124 };
125
126 static struct sh_mobile_sdhi_info sdhi0_platform_data = {
127         .dma_slave_tx = HPBDMA_SLAVE_SDHI0_TX,
128         .dma_slave_rx = HPBDMA_SLAVE_SDHI0_RX,
129         .tmio_flags = TMIO_MMC_WRPROTECT_DISABLE | TMIO_MMC_HAS_IDLE_WAIT,
130         .tmio_caps = MMC_CAP_SD_HIGHSPEED,
131 };
132
133 static struct platform_device sdhi0_device = {
134         .name = "sh_mobile_sdhi",
135         .num_resources = ARRAY_SIZE(sdhi0_resources),
136         .resource = sdhi0_resources,
137         .id = 0,
138         .dev = {
139                 .platform_data = &sdhi0_platform_data,
140         }
141 };
142
143 /* Thermal */
144 static struct resource thermal_resources[] = {
145         [0] = {
146                 .start          = 0xFFC48000,
147                 .end            = 0xFFC48038 - 1,
148                 .flags          = IORESOURCE_MEM,
149         },
150 };
151
152 static struct platform_device thermal_device = {
153         .name           = "rcar_thermal",
154         .resource       = thermal_resources,
155         .num_resources  = ARRAY_SIZE(thermal_resources),
156 };
157
158 /* HSPI */
159 static struct resource hspi_resources[] = {
160         [0] = {
161                 .start          = 0xFFFC7000,
162                 .end            = 0xFFFC7018 - 1,
163                 .flags          = IORESOURCE_MEM,
164         },
165 };
166
167 static struct platform_device hspi_device = {
168         .name   = "sh-hspi",
169         .id     = 0,
170         .resource       = hspi_resources,
171         .num_resources  = ARRAY_SIZE(hspi_resources),
172 };
173
174 /*
175  * DU
176  *
177  * The panel only specifies the [hv]display and [hv]total values. The position
178  * and width of the sync pulses don't matter, they're copied from VESA timings.
179  */
180 static struct rcar_du_encoder_data du_encoders[] = {
181         {
182                 .type = RCAR_DU_ENCODER_VGA,
183                 .output = RCAR_DU_OUTPUT_DPAD0,
184         }, {
185                 .type = RCAR_DU_ENCODER_LVDS,
186                 .output = RCAR_DU_OUTPUT_DPAD1,
187                 .connector.lvds.panel = {
188                         .width_mm = 210,
189                         .height_mm = 158,
190                         .mode = {
191                                 .pixelclock = 65000000,
192                                 .hactive = 1024,
193                                 .hfront_porch = 20,
194                                 .hback_porch = 160,
195                                 .hsync_len = 136,
196                                 .vactive = 768,
197                                 .vfront_porch = 3,
198                                 .vback_porch = 29,
199                                 .vsync_len = 6,
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 /* VIN */
261 static struct rcar_vin_platform_data vin_platform_data __initdata = {
262         .flags  = RCAR_VIN_BT656,
263 };
264
265 #define MARZEN_VIN(idx)                                         \
266 static struct resource vin##idx##_resources[] __initdata = {    \
267         DEFINE_RES_MEM(0xffc50000 + 0x1000 * (idx), 0x1000),    \
268         DEFINE_RES_IRQ(gic_iid(0x5f + (idx))),                  \
269 };                                                              \
270                                                                 \
271 static struct platform_device_info vin##idx##_info __initdata = { \
272         .name           = "r8a7779-vin",                        \
273         .id             = idx,                                  \
274         .res            = vin##idx##_resources,                 \
275         .num_res        = ARRAY_SIZE(vin##idx##_resources),     \
276         .dma_mask       = DMA_BIT_MASK(32),                     \
277         .data           = &vin_platform_data,                   \
278         .size_data      = sizeof(vin_platform_data),            \
279 }
280 MARZEN_VIN(1);
281 MARZEN_VIN(3);
282
283 #define MARZEN_CAMERA(idx)                                      \
284 static struct i2c_board_info camera##idx##_info = {             \
285         I2C_BOARD_INFO("adv7180", 0x20 + (idx)),                \
286 };                                                              \
287                                                                 \
288 static struct soc_camera_link iclink##idx##_adv7180 = {         \
289         .bus_id         = 1 + 2 * (idx),                        \
290         .i2c_adapter_id = 0,                                    \
291         .board_info     = &camera##idx##_info,                  \
292 };                                                              \
293                                                                 \
294 static struct platform_device camera##idx##_device = {          \
295         .name   = "soc-camera-pdrv",                            \
296         .id     = idx,                                          \
297         .dev    = {                                             \
298                 .platform_data  = &iclink##idx##_adv7180,       \
299         },                                                      \
300 };
301
302 MARZEN_CAMERA(0);
303 MARZEN_CAMERA(1);
304
305 static struct platform_device *marzen_devices[] __initdata = {
306         &eth_device,
307         &sdhi0_device,
308         &thermal_device,
309         &hspi_device,
310         &leds_device,
311         &usb_phy,
312         &camera0_device,
313         &camera1_device,
314 };
315
316 static const struct pinctrl_map marzen_pinctrl_map[] = {
317         /* DU (CN10: ARGB0, CN13: LVDS) */
318         PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7779", "pfc-r8a7779",
319                                   "du0_rgb888", "du0"),
320         PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7779", "pfc-r8a7779",
321                                   "du0_sync_1", "du0"),
322         PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7779", "pfc-r8a7779",
323                                   "du0_clk_out_0", "du0"),
324         PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7779", "pfc-r8a7779",
325                                   "du1_rgb666", "du1"),
326         PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7779", "pfc-r8a7779",
327                                   "du1_sync_1", "du1"),
328         PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7779", "pfc-r8a7779",
329                                   "du1_clk_out", "du1"),
330         /* HSPI0 */
331         PIN_MAP_MUX_GROUP_DEFAULT("sh-hspi.0", "pfc-r8a7779",
332                                   "hspi0", "hspi0"),
333         /* SCIF2 (CN18: DEBUG0) */
334         PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.2", "pfc-r8a7779",
335                                   "scif2_data_c", "scif2"),
336         /* SCIF4 (CN19: DEBUG1) */
337         PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.4", "pfc-r8a7779",
338                                   "scif4_data", "scif4"),
339         /* SDHI0 */
340         PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-r8a7779",
341                                   "sdhi0_data4", "sdhi0"),
342         PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-r8a7779",
343                                   "sdhi0_ctrl", "sdhi0"),
344         PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-r8a7779",
345                                   "sdhi0_cd", "sdhi0"),
346         /* SMSC */
347         PIN_MAP_MUX_GROUP_DEFAULT("smsc911x", "pfc-r8a7779",
348                                   "intc_irq1_b", "intc"),
349         PIN_MAP_MUX_GROUP_DEFAULT("smsc911x", "pfc-r8a7779",
350                                   "lbsc_ex_cs0", "lbsc"),
351         /* USB0 */
352         PIN_MAP_MUX_GROUP_DEFAULT("ehci-platform.0", "pfc-r8a7779",
353                                   "usb0", "usb0"),
354         /* USB1 */
355         PIN_MAP_MUX_GROUP_DEFAULT("ehci-platform.0", "pfc-r8a7779",
356                                   "usb1", "usb1"),
357         /* USB2 */
358         PIN_MAP_MUX_GROUP_DEFAULT("ehci-platform.1", "pfc-r8a7779",
359                                   "usb2", "usb2"),
360         /* VIN1 */
361         PIN_MAP_MUX_GROUP_DEFAULT("r8a7779-vin.1", "pfc-r8a7779",
362                                   "vin1_clk", "vin1"),
363         PIN_MAP_MUX_GROUP_DEFAULT("r8a7779-vin.1", "pfc-r8a7779",
364                                   "vin1_data8", "vin1"),
365         /* VIN3 */
366         PIN_MAP_MUX_GROUP_DEFAULT("r8a7779-vin.3", "pfc-r8a7779",
367                                   "vin3_clk", "vin3"),
368         PIN_MAP_MUX_GROUP_DEFAULT("r8a7779-vin.3", "pfc-r8a7779",
369                                   "vin3_data8", "vin3"),
370 };
371
372 static void __init marzen_init(void)
373 {
374         regulator_register_always_on(0, "fixed-3.3V", fixed3v3_power_consumers,
375                                 ARRAY_SIZE(fixed3v3_power_consumers), 3300000);
376         regulator_register_fixed(1, dummy_supplies,
377                                 ARRAY_SIZE(dummy_supplies));
378
379         pinctrl_register_mappings(marzen_pinctrl_map,
380                                   ARRAY_SIZE(marzen_pinctrl_map));
381         r8a7779_pinmux_init();
382         r8a7779_init_irq_extpin(1); /* IRQ1 as individual interrupt */
383
384         r8a7779_add_standard_devices();
385         platform_device_register_full(&vin1_info);
386         platform_device_register_full(&vin3_info);
387         platform_add_devices(marzen_devices, ARRAY_SIZE(marzen_devices));
388         marzen_add_du_device();
389 }
390
391 static const char *marzen_boards_compat_dt[] __initdata = {
392         "renesas,marzen",
393         NULL,
394 };
395
396 DT_MACHINE_START(MARZEN, "marzen")
397         .smp            = smp_ops(r8a7779_smp_ops),
398         .map_io         = r8a7779_map_io,
399         .init_early     = r8a7779_add_early_devices,
400         .init_irq       = r8a7779_init_irq_dt,
401         .init_machine   = marzen_init,
402         .init_late      = r8a7779_init_late,
403         .dt_compat      = marzen_boards_compat_dt,
404         .init_time      = r8a7779_earlytimer_init,
405 MACHINE_END