Merge tag 'renesas-soc-fixes3-for-v3.19' of git://git.kernel.org/pub/scm/linux/kernel...
[sfrench/cifs-2.6.git] / arch / arm / mach-shmobile / board-lager.c
1 /*
2  * Lager board support
3  *
4  * Copyright (C) 2013-2014  Renesas Solutions Corp.
5  * Copyright (C) 2013  Magnus Damm
6  * Copyright (C) 2014  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/gpio.h>
19 #include <linux/gpio_keys.h>
20 #include <linux/i2c.h>
21 #include <linux/input.h>
22 #include <linux/interrupt.h>
23 #include <linux/irq.h>
24 #include <linux/irqchip.h>
25 #include <linux/irqchip/arm-gic.h>
26 #include <linux/kernel.h>
27 #include <linux/leds.h>
28 #include <linux/mfd/tmio.h>
29 #include <linux/mmc/host.h>
30 #include <linux/mmc/sh_mmcif.h>
31 #include <linux/mmc/sh_mobile_sdhi.h>
32 #include <linux/mtd/partitions.h>
33 #include <linux/mtd/mtd.h>
34 #include <linux/pinctrl/machine.h>
35 #include <linux/platform_data/camera-rcar.h>
36 #include <linux/platform_data/gpio-rcar.h>
37 #include <linux/platform_data/usb-rcar-gen2-phy.h>
38 #include <linux/platform_device.h>
39 #include <linux/phy.h>
40 #include <linux/regulator/driver.h>
41 #include <linux/regulator/fixed.h>
42 #include <linux/regulator/gpio-regulator.h>
43 #include <linux/regulator/machine.h>
44 #include <linux/sh_eth.h>
45 #include <linux/spi/flash.h>
46 #include <linux/spi/rspi.h>
47 #include <linux/spi/spi.h>
48 #include <linux/usb/phy.h>
49 #include <linux/usb/renesas_usbhs.h>
50
51 #include <media/soc_camera.h>
52 #include <asm/mach-types.h>
53 #include <asm/mach/arch.h>
54 #include <sound/rcar_snd.h>
55 #include <sound/simple_card.h>
56
57 #include "common.h"
58 #include "irqs.h"
59 #include "r8a7790.h"
60 #include "rcar-gen2.h"
61
62 /*
63  * SSI-AK4643
64  *
65  * SW1: 1: AK4643
66  *      2: CN22
67  *      3: ADV7511
68  *
69  * this command is required when playback.
70  *
71  * # amixer set "LINEOUT Mixer DACL" on
72  */
73
74 /*
75  * SDHI0 (CN8)
76  *
77  * JP3:  pin1
78  * SW20: pin1
79
80  * GP5_24:      1:  VDD  3.3V (defult)
81  *              0:  VDD  0.0V
82  * GP5_29:      1:  VccQ 3.3V (defult)
83  *              0:  VccQ 1.8V
84  *
85  */
86
87 /* LEDS */
88 static struct gpio_led lager_leds[] = {
89         {
90                 .name           = "led8",
91                 .gpio           = RCAR_GP_PIN(5, 17),
92                 .default_state  = LEDS_GPIO_DEFSTATE_ON,
93         }, {
94                 .name           = "led7",
95                 .gpio           = RCAR_GP_PIN(4, 23),
96                 .default_state  = LEDS_GPIO_DEFSTATE_ON,
97         }, {
98                 .name           = "led6",
99                 .gpio           = RCAR_GP_PIN(4, 22),
100                 .default_state  = LEDS_GPIO_DEFSTATE_ON,
101         },
102 };
103
104 static const struct gpio_led_platform_data lager_leds_pdata __initconst = {
105         .leds           = lager_leds,
106         .num_leds       = ARRAY_SIZE(lager_leds),
107 };
108
109 /* GPIO KEY */
110 #define GPIO_KEY(c, g, d, ...) \
111         { .code = c, .gpio = g, .desc = d, .active_low = 1, \
112           .wakeup = 1, .debounce_interval = 20 }
113
114 static struct gpio_keys_button gpio_buttons[] = {
115         GPIO_KEY(KEY_4,         RCAR_GP_PIN(1, 28),     "SW2-pin4"),
116         GPIO_KEY(KEY_3,         RCAR_GP_PIN(1, 26),     "SW2-pin3"),
117         GPIO_KEY(KEY_2,         RCAR_GP_PIN(1, 24),     "SW2-pin2"),
118         GPIO_KEY(KEY_1,         RCAR_GP_PIN(1, 14),     "SW2-pin1"),
119 };
120
121 static const struct gpio_keys_platform_data lager_keys_pdata __initconst = {
122         .buttons        = gpio_buttons,
123         .nbuttons       = ARRAY_SIZE(gpio_buttons),
124 };
125
126 /* Fixed 3.3V regulator to be used by MMCIF */
127 static struct regulator_consumer_supply fixed3v3_power_consumers[] =
128 {
129         REGULATOR_SUPPLY("vmmc", "sh_mmcif.1"),
130 };
131
132 /*
133  * SDHI regulator macro
134  *
135  ** FIXME**
136  * Lager board vqmmc is provided via DA9063 PMIC chip,
137  * and we should use ${LINK}/drivers/mfd/da9063-* driver for it.
138  * but, it doesn't have regulator support at this point.
139  * It uses gpio-regulator for vqmmc as quick-hack.
140  */
141 #define SDHI_REGULATOR(idx, vdd_pin, vccq_pin)                          \
142 static struct regulator_consumer_supply vcc_sdhi##idx##_consumer =      \
143         REGULATOR_SUPPLY("vmmc", "sh_mobile_sdhi." #idx);               \
144                                                                         \
145 static struct regulator_init_data vcc_sdhi##idx##_init_data = {         \
146         .constraints = {                                                \
147                 .valid_ops_mask = REGULATOR_CHANGE_STATUS,              \
148         },                                                              \
149         .consumer_supplies      = &vcc_sdhi##idx##_consumer,            \
150         .num_consumer_supplies  = 1,                                    \
151 };                                                                      \
152                                                                         \
153 static const struct fixed_voltage_config vcc_sdhi##idx##_info __initconst = {\
154         .supply_name    = "SDHI" #idx "Vcc",                            \
155         .microvolts     = 3300000,                                      \
156         .gpio           = vdd_pin,                                      \
157         .enable_high    = 1,                                            \
158         .init_data      = &vcc_sdhi##idx##_init_data,                   \
159 };                                                                      \
160                                                                         \
161 static struct regulator_consumer_supply vccq_sdhi##idx##_consumer =     \
162         REGULATOR_SUPPLY("vqmmc", "sh_mobile_sdhi." #idx);              \
163                                                                         \
164 static struct regulator_init_data vccq_sdhi##idx##_init_data = {        \
165         .constraints = {                                                \
166                 .input_uV       = 3300000,                              \
167                 .min_uV         = 1800000,                              \
168                 .max_uV         = 3300000,                              \
169                 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE |            \
170                                   REGULATOR_CHANGE_STATUS,              \
171         },                                                              \
172         .consumer_supplies      = &vccq_sdhi##idx##_consumer,           \
173         .num_consumer_supplies  = 1,                                    \
174 };                                                                      \
175                                                                         \
176 static struct gpio vccq_sdhi##idx##_gpio =                              \
177         { vccq_pin, GPIOF_OUT_INIT_HIGH, "vccq-sdhi" #idx };            \
178                                                                         \
179 static struct gpio_regulator_state vccq_sdhi##idx##_states[] = {        \
180         { .value = 1800000, .gpios = 0 },                               \
181         { .value = 3300000, .gpios = 1 },                               \
182 };                                                                      \
183                                                                         \
184 static const struct gpio_regulator_config vccq_sdhi##idx##_info __initconst = {\
185         .supply_name    = "vqmmc",                                      \
186         .gpios          = &vccq_sdhi##idx##_gpio,                       \
187         .nr_gpios       = 1,                                            \
188         .states         = vccq_sdhi##idx##_states,                      \
189         .nr_states      = ARRAY_SIZE(vccq_sdhi##idx##_states),          \
190         .type           = REGULATOR_VOLTAGE,                            \
191         .init_data      = &vccq_sdhi##idx##_init_data,                  \
192 };
193
194 SDHI_REGULATOR(0, RCAR_GP_PIN(5, 24), RCAR_GP_PIN(5, 29));
195 SDHI_REGULATOR(2, RCAR_GP_PIN(5, 25), RCAR_GP_PIN(5, 30));
196
197 /* MMCIF */
198 static const struct sh_mmcif_plat_data mmcif1_pdata __initconst = {
199         .caps           = MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE,
200         .clk_ctrl2_present = true,
201         .ccs_unsupported = true,
202 };
203
204 static const struct resource mmcif1_resources[] __initconst = {
205         DEFINE_RES_MEM(0xee220000, 0x80),
206         DEFINE_RES_IRQ(gic_spi(170)),
207 };
208
209 /* Ether */
210 static const struct sh_eth_plat_data ether_pdata __initconst = {
211         .phy                    = 0x1,
212         .phy_irq                = irq_pin(0),
213         .edmac_endian           = EDMAC_LITTLE_ENDIAN,
214         .phy_interface          = PHY_INTERFACE_MODE_RMII,
215         .ether_link_active_low  = 1,
216 };
217
218 static const struct resource ether_resources[] __initconst = {
219         DEFINE_RES_MEM(0xee700000, 0x400),
220         DEFINE_RES_IRQ(gic_spi(162)),
221 };
222
223 static const struct platform_device_info ether_info __initconst = {
224         .name           = "r8a7790-ether",
225         .id             = -1,
226         .res            = ether_resources,
227         .num_res        = ARRAY_SIZE(ether_resources),
228         .data           = &ether_pdata,
229         .size_data      = sizeof(ether_pdata),
230         .dma_mask       = DMA_BIT_MASK(32),
231 };
232
233 /* SPI Flash memory (Spansion S25FL512SAGMFIG11 64Mb) */
234 static struct mtd_partition spi_flash_part[] = {
235         /* Reserved for user loader program, read-only */
236         {
237                 .name = "loader",
238                 .offset = 0,
239                 .size = SZ_256K,
240                 .mask_flags = MTD_WRITEABLE,
241         },
242         /* Reserved for user program, read-only */
243         {
244                 .name = "user",
245                 .offset = MTDPART_OFS_APPEND,
246                 .size = SZ_4M,
247                 .mask_flags = MTD_WRITEABLE,
248         },
249         /* All else is writable (e.g. JFFS2) */
250         {
251                 .name = "flash",
252                 .offset = MTDPART_OFS_APPEND,
253                 .size = MTDPART_SIZ_FULL,
254                 .mask_flags = 0,
255         },
256 };
257
258 static const struct flash_platform_data spi_flash_data = {
259         .name           = "m25p80",
260         .parts          = spi_flash_part,
261         .nr_parts       = ARRAY_SIZE(spi_flash_part),
262         .type           = "s25fl512s",
263 };
264
265 static const struct rspi_plat_data qspi_pdata __initconst = {
266         .num_chipselect = 1,
267 };
268
269 static const struct spi_board_info spi_info[] __initconst = {
270         {
271                 .modalias       = "m25p80",
272                 .platform_data  = &spi_flash_data,
273                 .mode           = SPI_MODE_0 | SPI_TX_QUAD | SPI_RX_QUAD,
274                 .max_speed_hz   = 30000000,
275                 .bus_num        = 0,
276                 .chip_select    = 0,
277         },
278 };
279
280 /* QSPI resource */
281 static const struct resource qspi_resources[] __initconst = {
282         DEFINE_RES_MEM(0xe6b10000, 0x1000),
283         DEFINE_RES_IRQ_NAMED(gic_spi(184), "mux"),
284 };
285
286 /* VIN */
287 static const struct resource vin_resources[] __initconst = {
288         /* VIN0 */
289         DEFINE_RES_MEM(0xe6ef0000, 0x1000),
290         DEFINE_RES_IRQ(gic_spi(188)),
291         /* VIN1 */
292         DEFINE_RES_MEM(0xe6ef1000, 0x1000),
293         DEFINE_RES_IRQ(gic_spi(189)),
294 };
295
296 static void __init lager_add_vin_device(unsigned idx,
297                                         struct rcar_vin_platform_data *pdata)
298 {
299         struct platform_device_info vin_info = {
300                 .name           = "r8a7790-vin",
301                 .id             = idx,
302                 .res            = &vin_resources[idx * 2],
303                 .num_res        = 2,
304                 .dma_mask       = DMA_BIT_MASK(32),
305                 .data           = pdata,
306                 .size_data      = sizeof(*pdata),
307         };
308
309         BUG_ON(idx > 1);
310
311         platform_device_register_full(&vin_info);
312 }
313
314 #define LAGER_CAMERA(idx, name, addr, pdata, flag)                      \
315 static struct i2c_board_info i2c_cam##idx##_device = {                  \
316         I2C_BOARD_INFO(name, addr),                                     \
317 };                                                                      \
318                                                                         \
319 static struct rcar_vin_platform_data vin##idx##_pdata = {               \
320         .flags = flag,                                                  \
321 };                                                                      \
322                                                                         \
323 static struct soc_camera_link cam##idx##_link = {                       \
324         .bus_id = idx,                                                  \
325         .board_info = &i2c_cam##idx##_device,                           \
326         .i2c_adapter_id = 2,                                            \
327         .module_name = name,                                            \
328         .priv = pdata,                                                  \
329 }
330
331 /* Camera 0 is not currently supported due to adv7612 support missing */
332 LAGER_CAMERA(1, "adv7180", 0x20, NULL, RCAR_VIN_BT656);
333
334 static void __init lager_add_camera1_device(void)
335 {
336         platform_device_register_data(NULL, "soc-camera-pdrv", 1,
337                                       &cam1_link, sizeof(cam1_link));
338         lager_add_vin_device(1, &vin1_pdata);
339 }
340
341 /* SATA1 */
342 static const struct resource sata1_resources[] __initconst = {
343         DEFINE_RES_MEM(0xee500000, 0x2000),
344         DEFINE_RES_IRQ(gic_spi(106)),
345 };
346
347 static const struct platform_device_info sata1_info __initconst = {
348         .name           = "sata-r8a7790",
349         .id             = 1,
350         .res            = sata1_resources,
351         .num_res        = ARRAY_SIZE(sata1_resources),
352         .dma_mask       = DMA_BIT_MASK(32),
353 };
354
355 /* USBHS */
356 static const struct resource usbhs_resources[] __initconst = {
357         DEFINE_RES_MEM(0xe6590000, 0x100),
358         DEFINE_RES_IRQ(gic_spi(107)),
359 };
360
361 struct usbhs_private {
362         struct renesas_usbhs_platform_info info;
363         struct usb_phy *phy;
364 };
365
366 #define usbhs_get_priv(pdev) \
367         container_of(renesas_usbhs_get_info(pdev), struct usbhs_private, info)
368
369 static int usbhs_power_ctrl(struct platform_device *pdev,
370                                 void __iomem *base, int enable)
371 {
372         struct usbhs_private *priv = usbhs_get_priv(pdev);
373
374         if (!priv->phy)
375                 return -ENODEV;
376
377         if (enable) {
378                 int retval = usb_phy_init(priv->phy);
379
380                 if (!retval)
381                         retval = usb_phy_set_suspend(priv->phy, 0);
382                 return retval;
383         }
384
385         usb_phy_set_suspend(priv->phy, 1);
386         usb_phy_shutdown(priv->phy);
387         return 0;
388 }
389
390 static int usbhs_hardware_init(struct platform_device *pdev)
391 {
392         struct usbhs_private *priv = usbhs_get_priv(pdev);
393         struct usb_phy *phy;
394         int ret;
395
396         /* USB0 Function - use PWEN as GPIO input to detect DIP Switch SW5
397          * setting to avoid VBUS short circuit due to wrong cable.
398          * PWEN should be pulled up high if USB Function is selected by SW5
399          */
400         gpio_request_one(RCAR_GP_PIN(5, 18), GPIOF_IN, NULL); /* USB0_PWEN */
401         if (!gpio_get_value(RCAR_GP_PIN(5, 18))) {
402                 pr_warn("Error: USB Function not selected - check SW5 + SW6\n");
403                 ret = -ENOTSUPP;
404                 goto error;
405         }
406
407         phy = usb_get_phy_dev(&pdev->dev, 0);
408         if (IS_ERR(phy)) {
409                 ret = PTR_ERR(phy);
410                 goto error;
411         }
412
413         priv->phy = phy;
414         return 0;
415  error:
416         gpio_free(RCAR_GP_PIN(5, 18));
417         return ret;
418 }
419
420 static int usbhs_hardware_exit(struct platform_device *pdev)
421 {
422         struct usbhs_private *priv = usbhs_get_priv(pdev);
423
424         if (!priv->phy)
425                 return 0;
426
427         usb_put_phy(priv->phy);
428         priv->phy = NULL;
429
430         gpio_free(RCAR_GP_PIN(5, 18));
431         return 0;
432 }
433
434 static int usbhs_get_id(struct platform_device *pdev)
435 {
436         return USBHS_GADGET;
437 }
438
439 static u32 lager_usbhs_pipe_type[] = {
440         USB_ENDPOINT_XFER_CONTROL,
441         USB_ENDPOINT_XFER_ISOC,
442         USB_ENDPOINT_XFER_ISOC,
443         USB_ENDPOINT_XFER_BULK,
444         USB_ENDPOINT_XFER_BULK,
445         USB_ENDPOINT_XFER_BULK,
446         USB_ENDPOINT_XFER_INT,
447         USB_ENDPOINT_XFER_INT,
448         USB_ENDPOINT_XFER_INT,
449         USB_ENDPOINT_XFER_BULK,
450         USB_ENDPOINT_XFER_BULK,
451         USB_ENDPOINT_XFER_BULK,
452         USB_ENDPOINT_XFER_BULK,
453         USB_ENDPOINT_XFER_BULK,
454         USB_ENDPOINT_XFER_BULK,
455         USB_ENDPOINT_XFER_BULK,
456 };
457
458 static struct usbhs_private usbhs_priv __initdata = {
459         .info = {
460                 .platform_callback = {
461                         .power_ctrl     = usbhs_power_ctrl,
462                         .hardware_init  = usbhs_hardware_init,
463                         .hardware_exit  = usbhs_hardware_exit,
464                         .get_id         = usbhs_get_id,
465                 },
466                 .driver_param = {
467                         .buswait_bwait  = 4,
468                         .pipe_type = lager_usbhs_pipe_type,
469                         .pipe_size = ARRAY_SIZE(lager_usbhs_pipe_type),
470                 },
471         }
472 };
473
474 static void __init lager_register_usbhs(void)
475 {
476         usb_bind_phy("renesas_usbhs", 0, "usb_phy_rcar_gen2");
477         platform_device_register_resndata(NULL,
478                                           "renesas_usbhs", -1,
479                                           usbhs_resources,
480                                           ARRAY_SIZE(usbhs_resources),
481                                           &usbhs_priv.info,
482                                           sizeof(usbhs_priv.info));
483 }
484
485 /* USBHS PHY */
486 static const struct rcar_gen2_phy_platform_data usbhs_phy_pdata __initconst = {
487         .chan0_pci = 0, /* Channel 0 is USBHS */
488         .chan2_pci = 1, /* Channel 2 is PCI USB */
489 };
490
491 static const struct resource usbhs_phy_resources[] __initconst = {
492         DEFINE_RES_MEM(0xe6590100, 0x100),
493 };
494
495 /* I2C */
496 static struct i2c_board_info i2c2_devices[] = {
497         {
498                 I2C_BOARD_INFO("ak4643", 0x12),
499         }
500 };
501
502 /* Sound */
503 static struct resource rsnd_resources[] __initdata = {
504         [RSND_GEN2_SCU]  = DEFINE_RES_MEM(0xec500000, 0x1000),
505         [RSND_GEN2_ADG]  = DEFINE_RES_MEM(0xec5a0000, 0x100),
506         [RSND_GEN2_SSIU] = DEFINE_RES_MEM(0xec540000, 0x1000),
507         [RSND_GEN2_SSI]  = DEFINE_RES_MEM(0xec541000, 0x1280),
508 };
509
510 static struct rsnd_ssi_platform_info rsnd_ssi[] = {
511         RSND_SSI(0, gic_spi(370), 0),
512         RSND_SSI(0, gic_spi(371), RSND_SSI_CLK_PIN_SHARE),
513 };
514
515 static struct rsnd_src_platform_info rsnd_src[2] = {
516         /* no member at this point */
517 };
518
519 static struct rsnd_dai_platform_info rsnd_dai = {
520         .playback = { .ssi = &rsnd_ssi[0], },
521         .capture  = { .ssi = &rsnd_ssi[1], },
522 };
523
524 static struct rcar_snd_info rsnd_info = {
525         .flags          = RSND_GEN2,
526         .ssi_info       = rsnd_ssi,
527         .ssi_info_nr    = ARRAY_SIZE(rsnd_ssi),
528         .src_info       = rsnd_src,
529         .src_info_nr    = ARRAY_SIZE(rsnd_src),
530         .dai_info       = &rsnd_dai,
531         .dai_info_nr    = 1,
532 };
533
534 static struct asoc_simple_card_info rsnd_card_info = {
535         .name           = "AK4643",
536         .card           = "SSI01-AK4643",
537         .codec          = "ak4642-codec.2-0012",
538         .platform       = "rcar_sound",
539         .daifmt         = SND_SOC_DAIFMT_LEFT_J | SND_SOC_DAIFMT_CBM_CFM,
540         .cpu_dai = {
541                 .name   = "rcar_sound",
542         },
543         .codec_dai = {
544                 .name   = "ak4642-hifi",
545                 .sysclk = 11289600,
546         },
547 };
548
549 static void __init lager_add_rsnd_device(void)
550 {
551         struct platform_device_info cardinfo = {
552                 .name           = "asoc-simple-card",
553                 .id             = -1,
554                 .data           = &rsnd_card_info,
555                 .size_data      = sizeof(struct asoc_simple_card_info),
556                 .dma_mask       = DMA_BIT_MASK(32),
557         };
558
559         i2c_register_board_info(2, i2c2_devices,
560                                 ARRAY_SIZE(i2c2_devices));
561
562         platform_device_register_resndata(
563                 NULL, "rcar_sound", -1,
564                 rsnd_resources, ARRAY_SIZE(rsnd_resources),
565                 &rsnd_info, sizeof(rsnd_info));
566
567         platform_device_register_full(&cardinfo);
568 }
569
570 /* SDHI0 */
571 static struct sh_mobile_sdhi_info sdhi0_info __initdata = {
572         .tmio_caps      = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ |
573                           MMC_CAP_POWER_OFF_CARD,
574         .tmio_flags     = TMIO_MMC_HAS_IDLE_WAIT |
575                           TMIO_MMC_WRPROTECT_DISABLE,
576 };
577
578 static struct resource sdhi0_resources[] __initdata = {
579         DEFINE_RES_MEM(0xee100000, 0x200),
580         DEFINE_RES_IRQ(gic_spi(165)),
581 };
582
583 /* SDHI2 */
584 static struct sh_mobile_sdhi_info sdhi2_info __initdata = {
585         .tmio_caps      = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ |
586                           MMC_CAP_POWER_OFF_CARD,
587         .tmio_flags     = TMIO_MMC_HAS_IDLE_WAIT |
588                           TMIO_MMC_WRPROTECT_DISABLE,
589 };
590
591 static struct resource sdhi2_resources[] __initdata = {
592         DEFINE_RES_MEM(0xee140000, 0x100),
593         DEFINE_RES_IRQ(gic_spi(167)),
594 };
595
596 /* Internal PCI1 */
597 static const struct resource pci1_resources[] __initconst = {
598         DEFINE_RES_MEM(0xee0b0000, 0x10000),    /* CFG */
599         DEFINE_RES_MEM(0xee0a0000, 0x10000),    /* MEM */
600         DEFINE_RES_IRQ(gic_spi(112)),
601 };
602
603 static const struct platform_device_info pci1_info __initconst = {
604         .name           = "pci-rcar-gen2",
605         .id             = 1,
606         .res            = pci1_resources,
607         .num_res        = ARRAY_SIZE(pci1_resources),
608         .dma_mask       = DMA_BIT_MASK(32),
609 };
610
611 static void __init lager_add_usb1_device(void)
612 {
613         platform_device_register_full(&pci1_info);
614 }
615
616 /* Internal PCI2 */
617 static const struct resource pci2_resources[] __initconst = {
618         DEFINE_RES_MEM(0xee0d0000, 0x10000),    /* CFG */
619         DEFINE_RES_MEM(0xee0c0000, 0x10000),    /* MEM */
620         DEFINE_RES_IRQ(gic_spi(113)),
621 };
622
623 static const struct platform_device_info pci2_info __initconst = {
624         .name           = "pci-rcar-gen2",
625         .id             = 2,
626         .res            = pci2_resources,
627         .num_res        = ARRAY_SIZE(pci2_resources),
628         .dma_mask       = DMA_BIT_MASK(32),
629 };
630
631 static void __init lager_add_usb2_device(void)
632 {
633         platform_device_register_full(&pci2_info);
634 }
635
636 static const struct pinctrl_map lager_pinctrl_map[] = {
637         /* DU (CN10: ARGB0, CN13: LVDS) */
638         PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7790", "pfc-r8a7790",
639                                   "du_rgb666", "du"),
640         PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7790", "pfc-r8a7790",
641                                   "du_sync_1", "du"),
642         PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7790", "pfc-r8a7790",
643                                   "du_clk_out_0", "du"),
644         /* I2C2 */
645         PIN_MAP_MUX_GROUP_DEFAULT("i2c-rcar.2", "pfc-r8a7790",
646                                   "i2c2", "i2c2"),
647         /* QSPI */
648         PIN_MAP_MUX_GROUP_DEFAULT("qspi.0", "pfc-r8a7790",
649                                   "qspi_ctrl", "qspi"),
650         PIN_MAP_MUX_GROUP_DEFAULT("qspi.0", "pfc-r8a7790",
651                                   "qspi_data4", "qspi"),
652         /* SCIF0 (CN19: DEBUG SERIAL0) */
653         PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.6", "pfc-r8a7790",
654                                   "scif0_data", "scif0"),
655         /* SCIF1 (CN20: DEBUG SERIAL1) */
656         PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.7", "pfc-r8a7790",
657                                   "scif1_data", "scif1"),
658         /* SDHI0 */
659         PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-r8a7790",
660                                   "sdhi0_data4", "sdhi0"),
661         PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-r8a7790",
662                                   "sdhi0_ctrl", "sdhi0"),
663         PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-r8a7790",
664                                   "sdhi0_cd", "sdhi0"),
665         /* SDHI2 */
666         PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.2", "pfc-r8a7790",
667                                   "sdhi2_data4", "sdhi2"),
668         PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.2", "pfc-r8a7790",
669                                   "sdhi2_ctrl", "sdhi2"),
670         PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.2", "pfc-r8a7790",
671                                   "sdhi2_cd", "sdhi2"),
672         /* SSI (CN17: sound) */
673         PIN_MAP_MUX_GROUP_DEFAULT("rcar_sound", "pfc-r8a7790",
674                                   "ssi0129_ctrl", "ssi"),
675         PIN_MAP_MUX_GROUP_DEFAULT("rcar_sound", "pfc-r8a7790",
676                                   "ssi0_data", "ssi"),
677         PIN_MAP_MUX_GROUP_DEFAULT("rcar_sound", "pfc-r8a7790",
678                                   "ssi1_data", "ssi"),
679         PIN_MAP_MUX_GROUP_DEFAULT("rcar_sound", "pfc-r8a7790",
680                                   "audio_clk_a", "audio_clk"),
681         /* MMCIF1 */
682         PIN_MAP_MUX_GROUP_DEFAULT("sh_mmcif.1", "pfc-r8a7790",
683                                   "mmc1_data8", "mmc1"),
684         PIN_MAP_MUX_GROUP_DEFAULT("sh_mmcif.1", "pfc-r8a7790",
685                                   "mmc1_ctrl", "mmc1"),
686         /* Ether */
687         PIN_MAP_MUX_GROUP_DEFAULT("r8a7790-ether", "pfc-r8a7790",
688                                   "eth_link", "eth"),
689         PIN_MAP_MUX_GROUP_DEFAULT("r8a7790-ether", "pfc-r8a7790",
690                                   "eth_mdio", "eth"),
691         PIN_MAP_MUX_GROUP_DEFAULT("r8a7790-ether", "pfc-r8a7790",
692                                   "eth_rmii", "eth"),
693         PIN_MAP_MUX_GROUP_DEFAULT("r8a7790-ether", "pfc-r8a7790",
694                                   "intc_irq0", "intc"),
695         /* VIN0 */
696         PIN_MAP_MUX_GROUP_DEFAULT("r8a7790-vin.0", "pfc-r8a7790",
697                                   "vin0_data24", "vin0"),
698         PIN_MAP_MUX_GROUP_DEFAULT("r8a7790-vin.0", "pfc-r8a7790",
699                                   "vin0_sync", "vin0"),
700         PIN_MAP_MUX_GROUP_DEFAULT("r8a7790-vin.0", "pfc-r8a7790",
701                                   "vin0_field", "vin0"),
702         PIN_MAP_MUX_GROUP_DEFAULT("r8a7790-vin.0", "pfc-r8a7790",
703                                   "vin0_clkenb", "vin0"),
704         PIN_MAP_MUX_GROUP_DEFAULT("r8a7790-vin.0", "pfc-r8a7790",
705                                   "vin0_clk", "vin0"),
706         /* VIN1 */
707         PIN_MAP_MUX_GROUP_DEFAULT("r8a7790-vin.1", "pfc-r8a7790",
708                                   "vin1_data8", "vin1"),
709         PIN_MAP_MUX_GROUP_DEFAULT("r8a7790-vin.1", "pfc-r8a7790",
710                                   "vin1_clk", "vin1"),
711         /* USB0 */
712         PIN_MAP_MUX_GROUP_DEFAULT("renesas_usbhs", "pfc-r8a7790",
713                                   "usb0_ovc_vbus", "usb0"),
714         /* USB1 */
715         PIN_MAP_MUX_GROUP_DEFAULT("pci-rcar-gen2.1", "pfc-r8a7790",
716                                   "usb1", "usb1"),
717         /* USB2 */
718         PIN_MAP_MUX_GROUP_DEFAULT("pci-rcar-gen2.2", "pfc-r8a7790",
719                                   "usb2", "usb2"),
720 };
721
722 static void __init lager_add_standard_devices(void)
723 {
724         int fixed_regulator_idx = 0;
725         int gpio_regulator_idx = 0;
726
727         r8a7790_clock_init();
728
729         pinctrl_register_mappings(lager_pinctrl_map,
730                                   ARRAY_SIZE(lager_pinctrl_map));
731         r8a7790_pinmux_init();
732
733         r8a7790_add_standard_devices();
734         platform_device_register_data(NULL, "leds-gpio", -1,
735                                       &lager_leds_pdata,
736                                       sizeof(lager_leds_pdata));
737         platform_device_register_data(NULL, "gpio-keys", -1,
738                                       &lager_keys_pdata,
739                                       sizeof(lager_keys_pdata));
740         regulator_register_always_on(fixed_regulator_idx++,
741                                      "fixed-3.3V", fixed3v3_power_consumers,
742                                      ARRAY_SIZE(fixed3v3_power_consumers), 3300000);
743         platform_device_register_resndata(NULL, "sh_mmcif", 1,
744                                           mmcif1_resources, ARRAY_SIZE(mmcif1_resources),
745                                           &mmcif1_pdata, sizeof(mmcif1_pdata));
746
747         platform_device_register_full(&ether_info);
748
749         platform_device_register_resndata(NULL, "qspi", 0,
750                                           qspi_resources,
751                                           ARRAY_SIZE(qspi_resources),
752                                           &qspi_pdata, sizeof(qspi_pdata));
753         spi_register_board_info(spi_info, ARRAY_SIZE(spi_info));
754
755         platform_device_register_data(NULL, "reg-fixed-voltage", fixed_regulator_idx++,
756                                       &vcc_sdhi0_info, sizeof(struct fixed_voltage_config));
757         platform_device_register_data(NULL, "reg-fixed-voltage", fixed_regulator_idx++,
758                                       &vcc_sdhi2_info, sizeof(struct fixed_voltage_config));
759
760         platform_device_register_data(NULL, "gpio-regulator", gpio_regulator_idx++,
761                                       &vccq_sdhi0_info, sizeof(struct gpio_regulator_config));
762         platform_device_register_data(NULL, "gpio-regulator", gpio_regulator_idx++,
763                                       &vccq_sdhi2_info, sizeof(struct gpio_regulator_config));
764
765         lager_add_camera1_device();
766
767         platform_device_register_full(&sata1_info);
768
769         platform_device_register_resndata(NULL, "usb_phy_rcar_gen2",
770                                           -1, usbhs_phy_resources,
771                                           ARRAY_SIZE(usbhs_phy_resources),
772                                           &usbhs_phy_pdata,
773                                           sizeof(usbhs_phy_pdata));
774         lager_register_usbhs();
775         lager_add_usb1_device();
776         lager_add_usb2_device();
777
778         lager_add_rsnd_device();
779
780         platform_device_register_resndata(NULL, "sh_mobile_sdhi", 0,
781                                           sdhi0_resources, ARRAY_SIZE(sdhi0_resources),
782                                           &sdhi0_info, sizeof(struct sh_mobile_sdhi_info));
783         platform_device_register_resndata(NULL, "sh_mobile_sdhi", 2,
784                                           sdhi2_resources, ARRAY_SIZE(sdhi2_resources),
785                                           &sdhi2_info, sizeof(struct sh_mobile_sdhi_info));
786 }
787
788 /*
789  * Ether LEDs on the Lager board are named LINK and ACTIVE which corresponds
790  * to non-default 01 setting of the Micrel KSZ8041 PHY control register 1 bits
791  * 14-15. We have to set them back to 01 from the default 00 value each time
792  * the PHY is reset. It's also important because the PHY's LED0 signal is
793  * connected to SoC's ETH_LINK signal and in the PHY's default mode it will
794  * bounce on and off after each packet, which we apparently want to avoid.
795  */
796 static int lager_ksz8041_fixup(struct phy_device *phydev)
797 {
798         u16 phyctrl1 = phy_read(phydev, 0x1e);
799
800         phyctrl1 &= ~0xc000;
801         phyctrl1 |= 0x4000;
802         return phy_write(phydev, 0x1e, phyctrl1);
803 }
804
805 static void __init lager_init(void)
806 {
807         lager_add_standard_devices();
808
809         irq_set_irq_type(irq_pin(0), IRQ_TYPE_LEVEL_LOW);
810
811         if (IS_ENABLED(CONFIG_PHYLIB))
812                 phy_register_fixup_for_id("r8a7790-ether-ff:01",
813                                           lager_ksz8041_fixup);
814 }
815
816 static void __init lager_legacy_init_irq(void)
817 {
818         void __iomem *gic_dist_base = ioremap_nocache(0xf1001000, 0x1000);
819         void __iomem *gic_cpu_base = ioremap_nocache(0xf1002000, 0x1000);
820
821         gic_init(0, 29, gic_dist_base, gic_cpu_base);
822
823         /* Do not invoke DT-based interrupt code via irqchip_init() */
824 }
825
826 static const char * const lager_boards_compat_dt[] __initconst = {
827         "renesas,lager",
828         NULL,
829 };
830
831 DT_MACHINE_START(LAGER_DT, "lager")
832         .smp            = smp_ops(r8a7790_smp_ops),
833         .init_early     = shmobile_init_delay,
834         .init_irq       = lager_legacy_init_irq,
835         .init_time      = rcar_gen2_timer_init,
836         .init_machine   = lager_init,
837         .init_late      = shmobile_init_late,
838         .reserve        = rcar_gen2_reserve,
839         .dt_compat      = lager_boards_compat_dt,
840 MACHINE_END