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