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