4 * Copyright (C) 2013 Renesas Solutions Corp.
5 * Copyright (C) 2013 Magnus Damm
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.
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.
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
21 #include <linux/gpio.h>
22 #include <linux/gpio_keys.h>
23 #include <linux/input.h>
24 #include <linux/interrupt.h>
25 #include <linux/kernel.h>
26 #include <linux/leds.h>
27 #include <linux/mmc/host.h>
28 #include <linux/mmc/sh_mmcif.h>
29 #include <linux/pinctrl/machine.h>
30 #include <linux/platform_data/camera-rcar.h>
31 #include <linux/platform_data/gpio-rcar.h>
32 #include <linux/platform_data/rcar-du.h>
33 #include <linux/platform_data/usb-rcar-gen2-phy.h>
34 #include <linux/platform_device.h>
35 #include <linux/phy.h>
36 #include <linux/regulator/driver.h>
37 #include <linux/regulator/fixed.h>
38 #include <linux/regulator/gpio-regulator.h>
39 #include <linux/regulator/machine.h>
40 #include <linux/sh_eth.h>
41 #include <linux/usb/phy.h>
42 #include <linux/usb/renesas_usbhs.h>
43 #include <mach/common.h>
44 #include <mach/irqs.h>
45 #include <mach/r8a7790.h>
46 #include <media/soc_camera.h>
47 #include <asm/mach-types.h>
48 #include <asm/mach/arch.h>
49 #include <linux/mtd/partitions.h>
50 #include <linux/mtd/mtd.h>
51 #include <linux/spi/flash.h>
52 #include <linux/spi/rspi.h>
53 #include <linux/spi/spi.h>
56 static struct rcar_du_encoder_data lager_du_encoders[] = {
58 .type = RCAR_DU_ENCODER_VGA,
59 .output = RCAR_DU_OUTPUT_DPAD0,
61 .type = RCAR_DU_ENCODER_NONE,
62 .output = RCAR_DU_OUTPUT_LVDS1,
63 .connector.lvds.panel = {
82 static const struct rcar_du_platform_data lager_du_pdata __initconst = {
83 .encoders = lager_du_encoders,
84 .num_encoders = ARRAY_SIZE(lager_du_encoders),
87 static const struct resource du_resources[] __initconst = {
88 DEFINE_RES_MEM(0xfeb00000, 0x70000),
89 DEFINE_RES_MEM_NAMED(0xfeb90000, 0x1c, "lvds.0"),
90 DEFINE_RES_MEM_NAMED(0xfeb94000, 0x1c, "lvds.1"),
91 DEFINE_RES_IRQ(gic_spi(256)),
92 DEFINE_RES_IRQ(gic_spi(268)),
93 DEFINE_RES_IRQ(gic_spi(269)),
96 static void __init lager_add_du_device(void)
98 struct platform_device_info info = {
99 .name = "rcar-du-r8a7790",
102 .num_res = ARRAY_SIZE(du_resources),
103 .data = &lager_du_pdata,
104 .size_data = sizeof(lager_du_pdata),
105 .dma_mask = DMA_BIT_MASK(32),
108 platform_device_register_full(&info);
112 static struct gpio_led lager_leds[] = {
115 .gpio = RCAR_GP_PIN(5, 17),
116 .default_state = LEDS_GPIO_DEFSTATE_ON,
119 .gpio = RCAR_GP_PIN(4, 23),
120 .default_state = LEDS_GPIO_DEFSTATE_ON,
123 .gpio = RCAR_GP_PIN(4, 22),
124 .default_state = LEDS_GPIO_DEFSTATE_ON,
128 static const struct gpio_led_platform_data lager_leds_pdata __initconst = {
130 .num_leds = ARRAY_SIZE(lager_leds),
134 #define GPIO_KEY(c, g, d, ...) \
135 { .code = c, .gpio = g, .desc = d, .active_low = 1, \
136 .wakeup = 1, .debounce_interval = 20 }
138 static struct gpio_keys_button gpio_buttons[] = {
139 GPIO_KEY(KEY_4, RCAR_GP_PIN(1, 28), "SW2-pin4"),
140 GPIO_KEY(KEY_3, RCAR_GP_PIN(1, 26), "SW2-pin3"),
141 GPIO_KEY(KEY_2, RCAR_GP_PIN(1, 24), "SW2-pin2"),
142 GPIO_KEY(KEY_1, RCAR_GP_PIN(1, 14), "SW2-pin1"),
145 static const struct gpio_keys_platform_data lager_keys_pdata __initconst = {
146 .buttons = gpio_buttons,
147 .nbuttons = ARRAY_SIZE(gpio_buttons),
150 /* Fixed 3.3V regulator to be used by MMCIF */
151 static struct regulator_consumer_supply fixed3v3_power_consumers[] =
153 REGULATOR_SUPPLY("vmmc", "sh_mmcif.1"),
157 * SDHI regulator macro
160 * Lager board vqmmc is provided via DA9063 PMIC chip,
161 * and we should use ${LINK}/drivers/mfd/da9063-* driver for it.
162 * but, it doesn't have regulator support at this point.
163 * It uses gpio-regulator for vqmmc as quick-hack.
165 #define SDHI_REGULATOR(idx, vdd_pin, vccq_pin) \
166 static struct regulator_consumer_supply vcc_sdhi##idx##_consumer = \
167 REGULATOR_SUPPLY("vmmc", "sh_mobile_sdhi." #idx); \
169 static struct regulator_init_data vcc_sdhi##idx##_init_data = { \
171 .valid_ops_mask = REGULATOR_CHANGE_STATUS, \
173 .consumer_supplies = &vcc_sdhi##idx##_consumer, \
174 .num_consumer_supplies = 1, \
177 static const struct fixed_voltage_config vcc_sdhi##idx##_info __initconst = {\
178 .supply_name = "SDHI" #idx "Vcc", \
179 .microvolts = 3300000, \
182 .init_data = &vcc_sdhi##idx##_init_data, \
185 static struct regulator_consumer_supply vccq_sdhi##idx##_consumer = \
186 REGULATOR_SUPPLY("vqmmc", "sh_mobile_sdhi." #idx); \
188 static struct regulator_init_data vccq_sdhi##idx##_init_data = { \
190 .input_uV = 3300000, \
193 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | \
194 REGULATOR_CHANGE_STATUS, \
196 .consumer_supplies = &vccq_sdhi##idx##_consumer, \
197 .num_consumer_supplies = 1, \
200 static struct gpio vccq_sdhi##idx##_gpio = \
201 { vccq_pin, GPIOF_OUT_INIT_HIGH, "vccq-sdhi" #idx }; \
203 static struct gpio_regulator_state vccq_sdhi##idx##_states[] = { \
204 { .value = 1800000, .gpios = 0 }, \
205 { .value = 3300000, .gpios = 1 }, \
208 static const struct gpio_regulator_config vccq_sdhi##idx##_info __initconst = {\
209 .supply_name = "vqmmc", \
210 .gpios = &vccq_sdhi##idx##_gpio, \
212 .states = vccq_sdhi##idx##_states, \
213 .nr_states = ARRAY_SIZE(vccq_sdhi##idx##_states), \
214 .type = REGULATOR_VOLTAGE, \
215 .init_data = &vccq_sdhi##idx##_init_data, \
218 SDHI_REGULATOR(0, RCAR_GP_PIN(5, 24), RCAR_GP_PIN(5, 29));
219 SDHI_REGULATOR(2, RCAR_GP_PIN(5, 25), RCAR_GP_PIN(5, 30));
222 static const struct sh_mmcif_plat_data mmcif1_pdata __initconst = {
223 .caps = MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE,
224 .clk_ctrl2_present = true,
225 .ccs_unsupported = true,
228 static const struct resource mmcif1_resources[] __initconst = {
229 DEFINE_RES_MEM(0xee220000, 0x80),
230 DEFINE_RES_IRQ(gic_spi(170)),
234 static const struct sh_eth_plat_data ether_pdata __initconst = {
236 .edmac_endian = EDMAC_LITTLE_ENDIAN,
237 .phy_interface = PHY_INTERFACE_MODE_RMII,
238 .ether_link_active_low = 1,
241 static const struct resource ether_resources[] __initconst = {
242 DEFINE_RES_MEM(0xee700000, 0x400),
243 DEFINE_RES_IRQ(gic_spi(162)),
246 /* SPI Flash memory (Spansion S25FL512SAGMFIG11 64Mb) */
247 static struct mtd_partition spi_flash_part[] = {
248 /* Reserved for user loader program, read-only */
253 .mask_flags = MTD_WRITEABLE,
255 /* Reserved for user program, read-only */
258 .offset = MTDPART_OFS_APPEND,
260 .mask_flags = MTD_WRITEABLE,
262 /* All else is writable (e.g. JFFS2) */
265 .offset = MTDPART_OFS_APPEND,
266 .size = MTDPART_SIZ_FULL,
271 static const struct flash_platform_data spi_flash_data = {
273 .parts = spi_flash_part,
274 .nr_parts = ARRAY_SIZE(spi_flash_part),
278 static const struct rspi_plat_data qspi_pdata __initconst = {
282 static const struct spi_board_info spi_info[] __initconst = {
284 .modalias = "m25p80",
285 .platform_data = &spi_flash_data,
287 .max_speed_hz = 30000000,
294 static const struct resource qspi_resources[] __initconst = {
295 DEFINE_RES_MEM(0xe6b10000, 0x1000),
296 DEFINE_RES_IRQ(gic_spi(184)),
300 static const struct resource vin_resources[] __initconst = {
302 DEFINE_RES_MEM(0xe6ef0000, 0x1000),
303 DEFINE_RES_IRQ(gic_spi(188)),
305 DEFINE_RES_MEM(0xe6ef1000, 0x1000),
306 DEFINE_RES_IRQ(gic_spi(189)),
309 static void __init lager_add_vin_device(unsigned idx,
310 struct rcar_vin_platform_data *pdata)
312 struct platform_device_info vin_info = {
313 .parent = &platform_bus,
314 .name = "r8a7790-vin",
316 .res = &vin_resources[idx * 2],
318 .dma_mask = DMA_BIT_MASK(32),
320 .size_data = sizeof(*pdata),
325 platform_device_register_full(&vin_info);
328 #define LAGER_CAMERA(idx, name, addr, pdata, flag) \
329 static struct i2c_board_info i2c_cam##idx##_device = { \
330 I2C_BOARD_INFO(name, addr), \
333 static struct rcar_vin_platform_data vin##idx##_pdata = { \
337 static struct soc_camera_link cam##idx##_link = { \
339 .board_info = &i2c_cam##idx##_device, \
340 .i2c_adapter_id = 2, \
341 .module_name = name, \
345 /* Camera 0 is not currently supported due to adv7612 support missing */
346 LAGER_CAMERA(1, "adv7180", 0x20, NULL, RCAR_VIN_BT656);
348 static void __init lager_add_camera1_device(void)
350 platform_device_register_data(&platform_bus, "soc-camera-pdrv", 1,
351 &cam1_link, sizeof(cam1_link));
352 lager_add_vin_device(1, &vin1_pdata);
356 static const struct resource sata1_resources[] __initconst = {
357 DEFINE_RES_MEM(0xee500000, 0x2000),
358 DEFINE_RES_IRQ(gic_spi(106)),
361 static const struct platform_device_info sata1_info __initconst = {
362 .parent = &platform_bus,
363 .name = "sata-r8a7790",
365 .res = sata1_resources,
366 .num_res = ARRAY_SIZE(sata1_resources),
367 .dma_mask = DMA_BIT_MASK(32),
371 #if IS_ENABLED(CONFIG_USB_RENESAS_USBHS_UDC)
372 static const struct resource usbhs_resources[] __initconst = {
373 DEFINE_RES_MEM(0xe6590000, 0x100),
374 DEFINE_RES_IRQ(gic_spi(107)),
377 struct usbhs_private {
378 struct renesas_usbhs_platform_info info;
382 #define usbhs_get_priv(pdev) \
383 container_of(renesas_usbhs_get_info(pdev), struct usbhs_private, info)
385 static int usbhs_power_ctrl(struct platform_device *pdev,
386 void __iomem *base, int enable)
388 struct usbhs_private *priv = usbhs_get_priv(pdev);
394 int retval = usb_phy_init(priv->phy);
397 retval = usb_phy_set_suspend(priv->phy, 0);
401 usb_phy_set_suspend(priv->phy, 1);
402 usb_phy_shutdown(priv->phy);
406 static int usbhs_hardware_init(struct platform_device *pdev)
408 struct usbhs_private *priv = usbhs_get_priv(pdev);
411 phy = usb_get_phy_dev(&pdev->dev, 0);
419 static int usbhs_hardware_exit(struct platform_device *pdev)
421 struct usbhs_private *priv = usbhs_get_priv(pdev);
426 usb_put_phy(priv->phy);
431 static int usbhs_get_id(struct platform_device *pdev)
436 static u32 lager_usbhs_pipe_type[] = {
437 USB_ENDPOINT_XFER_CONTROL,
438 USB_ENDPOINT_XFER_ISOC,
439 USB_ENDPOINT_XFER_ISOC,
440 USB_ENDPOINT_XFER_BULK,
441 USB_ENDPOINT_XFER_BULK,
442 USB_ENDPOINT_XFER_BULK,
443 USB_ENDPOINT_XFER_INT,
444 USB_ENDPOINT_XFER_INT,
445 USB_ENDPOINT_XFER_INT,
446 USB_ENDPOINT_XFER_BULK,
447 USB_ENDPOINT_XFER_BULK,
448 USB_ENDPOINT_XFER_BULK,
449 USB_ENDPOINT_XFER_BULK,
450 USB_ENDPOINT_XFER_BULK,
451 USB_ENDPOINT_XFER_BULK,
452 USB_ENDPOINT_XFER_BULK,
455 static struct usbhs_private usbhs_priv __initdata = {
457 .platform_callback = {
458 .power_ctrl = usbhs_power_ctrl,
459 .hardware_init = usbhs_hardware_init,
460 .hardware_exit = usbhs_hardware_exit,
461 .get_id = usbhs_get_id,
465 .pipe_type = lager_usbhs_pipe_type,
466 .pipe_size = ARRAY_SIZE(lager_usbhs_pipe_type),
471 static void __init lager_register_usbhs(void)
473 usb_bind_phy("renesas_usbhs", 0, "usb_phy_rcar_gen2");
474 platform_device_register_resndata(&platform_bus,
477 ARRAY_SIZE(usbhs_resources),
479 sizeof(usbhs_priv.info));
481 #else /* CONFIG_USB_RENESAS_USBHS_UDC */
482 static inline void lager_register_usbhs(void) { }
483 #endif /* CONFIG_USB_RENESAS_USBHS_UDC */
486 static const struct rcar_gen2_phy_platform_data usbhs_phy_pdata __initconst = {
487 .chan0_pci = 0, /* Channel 0 is USBHS */
488 .chan2_pci = 1, /* Channel 2 is PCI USB */
491 static const struct resource usbhs_phy_resources[] __initconst = {
492 DEFINE_RES_MEM(0xe6590100, 0x100),
495 static const struct pinctrl_map lager_pinctrl_map[] = {
496 /* DU (CN10: ARGB0, CN13: LVDS) */
497 PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7790", "pfc-r8a7790",
499 PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7790", "pfc-r8a7790",
501 PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7790", "pfc-r8a7790",
502 "du_clk_out_0", "du"),
503 /* SCIF0 (CN19: DEBUG SERIAL0) */
504 PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.6", "pfc-r8a7790",
505 "scif0_data", "scif0"),
506 /* SCIF1 (CN20: DEBUG SERIAL1) */
507 PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.7", "pfc-r8a7790",
508 "scif1_data", "scif1"),
510 PIN_MAP_MUX_GROUP_DEFAULT("sh_mmcif.1", "pfc-r8a7790",
511 "mmc1_data8", "mmc1"),
512 PIN_MAP_MUX_GROUP_DEFAULT("sh_mmcif.1", "pfc-r8a7790",
513 "mmc1_ctrl", "mmc1"),
515 PIN_MAP_MUX_GROUP_DEFAULT("r8a7790-ether", "pfc-r8a7790",
517 PIN_MAP_MUX_GROUP_DEFAULT("r8a7790-ether", "pfc-r8a7790",
519 PIN_MAP_MUX_GROUP_DEFAULT("r8a7790-ether", "pfc-r8a7790",
521 PIN_MAP_MUX_GROUP_DEFAULT("r8a7790-ether", "pfc-r8a7790",
522 "intc_irq0", "intc"),
524 PIN_MAP_MUX_GROUP_DEFAULT("r8a7790-vin.0", "pfc-r8a7790",
525 "vin0_data24", "vin0"),
526 PIN_MAP_MUX_GROUP_DEFAULT("r8a7790-vin.0", "pfc-r8a7790",
527 "vin0_sync", "vin0"),
528 PIN_MAP_MUX_GROUP_DEFAULT("r8a7790-vin.0", "pfc-r8a7790",
529 "vin0_field", "vin0"),
530 PIN_MAP_MUX_GROUP_DEFAULT("r8a7790-vin.0", "pfc-r8a7790",
531 "vin0_clkenb", "vin0"),
532 PIN_MAP_MUX_GROUP_DEFAULT("r8a7790-vin.0", "pfc-r8a7790",
535 PIN_MAP_MUX_GROUP_DEFAULT("r8a7790-vin.1", "pfc-r8a7790",
536 "vin1_data8", "vin1"),
537 PIN_MAP_MUX_GROUP_DEFAULT("r8a7790-vin.1", "pfc-r8a7790",
540 PIN_MAP_MUX_GROUP_DEFAULT("renesas_usbhs", "pfc-r8a7790",
544 static void __init lager_add_standard_devices(void)
546 int fixed_regulator_idx = 0;
547 int gpio_regulator_idx = 0;
549 r8a7790_clock_init();
551 pinctrl_register_mappings(lager_pinctrl_map,
552 ARRAY_SIZE(lager_pinctrl_map));
553 r8a7790_pinmux_init();
555 r8a7790_add_standard_devices();
556 platform_device_register_data(&platform_bus, "leds-gpio", -1,
558 sizeof(lager_leds_pdata));
559 platform_device_register_data(&platform_bus, "gpio-keys", -1,
561 sizeof(lager_keys_pdata));
562 regulator_register_always_on(fixed_regulator_idx++,
563 "fixed-3.3V", fixed3v3_power_consumers,
564 ARRAY_SIZE(fixed3v3_power_consumers), 3300000);
565 platform_device_register_resndata(&platform_bus, "sh_mmcif", 1,
566 mmcif1_resources, ARRAY_SIZE(mmcif1_resources),
567 &mmcif1_pdata, sizeof(mmcif1_pdata));
569 platform_device_register_resndata(&platform_bus, "r8a7790-ether", -1,
571 ARRAY_SIZE(ether_resources),
572 ðer_pdata, sizeof(ether_pdata));
574 lager_add_du_device();
576 platform_device_register_resndata(&platform_bus, "qspi", 0,
578 ARRAY_SIZE(qspi_resources),
579 &qspi_pdata, sizeof(qspi_pdata));
580 spi_register_board_info(spi_info, ARRAY_SIZE(spi_info));
582 platform_device_register_data(&platform_bus, "reg-fixed-voltage", fixed_regulator_idx++,
583 &vcc_sdhi0_info, sizeof(struct fixed_voltage_config));
584 platform_device_register_data(&platform_bus, "reg-fixed-voltage", fixed_regulator_idx++,
585 &vcc_sdhi2_info, sizeof(struct fixed_voltage_config));
587 platform_device_register_data(&platform_bus, "gpio-regulator", gpio_regulator_idx++,
588 &vccq_sdhi0_info, sizeof(struct gpio_regulator_config));
589 platform_device_register_data(&platform_bus, "gpio-regulator", gpio_regulator_idx++,
590 &vccq_sdhi2_info, sizeof(struct gpio_regulator_config));
592 lager_add_camera1_device();
594 platform_device_register_full(&sata1_info);
596 platform_device_register_resndata(&platform_bus, "usb_phy_rcar_gen2",
597 -1, usbhs_phy_resources,
598 ARRAY_SIZE(usbhs_phy_resources),
600 sizeof(usbhs_phy_pdata));
601 lager_register_usbhs();
605 * Ether LEDs on the Lager board are named LINK and ACTIVE which corresponds
606 * to non-default 01 setting of the Micrel KSZ8041 PHY control register 1 bits
607 * 14-15. We have to set them back to 01 from the default 00 value each time
608 * the PHY is reset. It's also important because the PHY's LED0 signal is
609 * connected to SoC's ETH_LINK signal and in the PHY's default mode it will
610 * bounce on and off after each packet, which we apparently want to avoid.
612 static int lager_ksz8041_fixup(struct phy_device *phydev)
614 u16 phyctrl1 = phy_read(phydev, 0x1e);
618 return phy_write(phydev, 0x1e, phyctrl1);
621 static void __init lager_init(void)
623 lager_add_standard_devices();
625 if (IS_ENABLED(CONFIG_PHYLIB))
626 phy_register_fixup_for_id("r8a7790-ether-ff:01",
627 lager_ksz8041_fixup);
630 static const char * const lager_boards_compat_dt[] __initconst = {
635 DT_MACHINE_START(LAGER_DT, "lager")
636 .smp = smp_ops(r8a7790_smp_ops),
637 .init_early = r8a7790_init_early,
638 .init_time = rcar_gen2_timer_init,
639 .init_machine = lager_init,
640 .init_late = shmobile_init_late,
641 .dt_compat = lager_boards_compat_dt,