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