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