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