4 * Copyright (C) 2013-2014 Renesas Solutions Corp.
5 * Copyright (C) 2013 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
6 * Copyright (C) 2013-2014 Cogent Embedded, Inc.
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.
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.
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
22 #include <linux/mfd/tmio.h>
23 #include <linux/mmc/host.h>
24 #include <linux/mmc/sh_mobile_sdhi.h>
25 #include <linux/mmc/sh_mmcif.h>
26 #include <linux/mtd/partitions.h>
27 #include <linux/pinctrl/machine.h>
28 #include <linux/platform_data/camera-rcar.h>
29 #include <linux/platform_data/usb-rcar-phy.h>
30 #include <linux/platform_device.h>
31 #include <linux/regulator/fixed.h>
32 #include <linux/regulator/machine.h>
33 #include <linux/smsc911x.h>
34 #include <linux/spi/spi.h>
35 #include <linux/spi/flash.h>
36 #include <linux/usb/renesas_usbhs.h>
37 #include <media/soc_camera.h>
38 #include <mach/common.h>
39 #include <mach/irqs.h>
40 #include <mach/r8a7778.h>
41 #include <asm/mach/arch.h>
42 #include <sound/rcar_snd.h>
43 #include <sound/simple_card.h>
45 #define FPGA 0x18200000
47 #define COMCTLR 0x101c
48 static void __iomem *fpga;
51 * CN9(Upper side) SCIF/RCAN selection
78 * SW45: 1-4 side (SSI5 out, ROUT/LOUT CN19 Mid)
79 * SW46: 1101 (SSI6 Recorde)
80 * SW47: 1110 (SSI5 Playback)
81 * SW48: 11 (Recorde power)
82 * SW49: 1 (SSI slave mode)
83 * SW50: 1111 (SSI7, SSI8)
84 * SW51: 1111 (SSI3, SSI4)
85 * SW54: 1pin (ak4554 FPGA control)
86 * SW55: 1 (CLKB is 24.5760MHz)
87 * SW60: 1pin (ak4554 FPGA control)
88 * SW61: 3pin (use X11 clock)
89 * SW78: 3-6 (ak4642 connects I2C0)
91 * You can use sound as
93 * hw0: CN19: SSI56-AK4643
94 * hw1: CN21: SSI3-AK4554(playback)
95 * hw2: CN21: SSI4-AK4554(capture)
96 * hw3: CN20: SSI7-AK4554(playback)
97 * hw4: CN20: SSI8-AK4554(capture)
99 * this command is required when playback on hw0.
101 * # amixer set "LINEOUT Mixer DACL" on
107 * USB1 (CN29) can be Host/Function
114 /* Dummy supplies, where voltage doesn't matter */
115 static struct regulator_consumer_supply dummy_supplies[] = {
116 REGULATOR_SUPPLY("vddvario", "smsc911x"),
117 REGULATOR_SUPPLY("vdd33a", "smsc911x"),
120 static struct regulator_consumer_supply fixed3v3_power_consumers[] = {
121 REGULATOR_SUPPLY("vmmc", "sh_mmcif"),
122 REGULATOR_SUPPLY("vqmmc", "sh_mmcif"),
125 static struct smsc911x_platform_config smsc911x_data __initdata = {
126 .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
127 .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
128 .flags = SMSC911X_USE_32BIT,
129 .phy_interface = PHY_INTERFACE_MODE_MII,
132 static struct resource smsc911x_resources[] __initdata = {
133 DEFINE_RES_MEM(0x18300000, 0x1000),
134 DEFINE_RES_IRQ(irq_pin(0)), /* IRQ 0 */
137 #if IS_ENABLED(CONFIG_USB_RENESAS_USBHS_UDC)
141 static int usbhsf_get_id(struct platform_device *pdev)
146 #define SUSPMODE 0x102
147 static int usbhsf_power_ctrl(struct platform_device *pdev,
148 void __iomem *base, int enable)
152 r8a7778_usb_phy_power(enable);
154 iowrite16(enable << 14, base + SUSPMODE);
159 static struct resource usbhsf_resources[] __initdata = {
160 DEFINE_RES_MEM(0xffe60000, 0x110),
161 DEFINE_RES_IRQ(gic_iid(0x4f)),
164 static struct renesas_usbhs_platform_info usbhs_info __initdata = {
165 .platform_callback = {
166 .get_id = usbhsf_get_id,
167 .power_ctrl = usbhsf_power_ctrl,
171 .d0_tx_id = HPBDMA_SLAVE_USBFUNC_TX,
172 .d1_rx_id = HPBDMA_SLAVE_USBFUNC_RX,
176 #define USB_PHY_SETTING {.port1_func = 1, .ovc_pin[1].active_high = 1,}
177 #define USB1_DEVICE "renesas_usbhs"
178 #define ADD_USB_FUNC_DEVICE_IF_POSSIBLE() \
179 platform_device_register_resndata( \
180 &platform_bus, "renesas_usbhs", -1, \
182 ARRAY_SIZE(usbhsf_resources), \
183 &usbhs_info, sizeof(struct renesas_usbhs_platform_info))
189 #define USB_PHY_SETTING { }
190 #define USB1_DEVICE "ehci-platform"
191 #define ADD_USB_FUNC_DEVICE_IF_POSSIBLE()
196 static struct resource usb_phy_resources[] __initdata = {
197 DEFINE_RES_MEM(0xffe70800, 0x100),
198 DEFINE_RES_MEM(0xffe76000, 0x100),
201 static struct rcar_phy_platform_data usb_phy_platform_data __initdata =
206 static struct sh_mobile_sdhi_info sdhi0_info __initdata = {
207 .dma_slave_tx = HPBDMA_SLAVE_SDHI0_TX,
208 .dma_slave_rx = HPBDMA_SLAVE_SDHI0_RX,
209 .tmio_caps = MMC_CAP_SD_HIGHSPEED,
210 .tmio_ocr_mask = MMC_VDD_165_195 | MMC_VDD_32_33 | MMC_VDD_33_34,
211 .tmio_flags = TMIO_MMC_HAS_IDLE_WAIT,
214 static struct resource sdhi0_resources[] __initdata = {
215 DEFINE_RES_MEM(0xFFE4C000, 0x100),
216 DEFINE_RES_IRQ(gic_iid(0x77)),
220 static struct resource ether_resources[] __initdata = {
221 DEFINE_RES_MEM(0xfde00000, 0x400),
222 DEFINE_RES_IRQ(gic_iid(0x89)),
225 static struct sh_eth_plat_data ether_platform_data __initdata = {
227 .edmac_endian = EDMAC_LITTLE_ENDIAN,
228 .phy_interface = PHY_INTERFACE_MODE_RMII,
230 * Although the LINK signal is available on the board, it's connected to
231 * the link/activity LED output of the PHY, thus the link disappears and
232 * reappears after each packet. We'd be better off ignoring such signal
233 * and getting the link state from the PHY indirectly.
238 static struct platform_device_info ether_info __initdata = {
239 .parent = &platform_bus,
240 .name = "r8a777x-ether",
242 .res = ether_resources,
243 .num_res = ARRAY_SIZE(ether_resources),
244 .data = ðer_platform_data,
245 .size_data = sizeof(ether_platform_data),
246 .dma_mask = DMA_BIT_MASK(32),
250 static struct i2c_board_info i2c0_devices[] = {
252 I2C_BOARD_INFO("rx8581", 0x51),
254 I2C_BOARD_INFO("ak4643", 0x12),
259 static struct mtd_partition m25p80_spi_flash_partitions[] = {
267 static struct flash_platform_data spi_flash_data = {
270 .parts = m25p80_spi_flash_partitions,
271 .nr_parts = ARRAY_SIZE(m25p80_spi_flash_partitions),
274 static struct spi_board_info spi_board_info[] __initdata = {
276 .modalias = "m25p80",
277 .max_speed_hz = 104000000,
281 .platform_data = &spi_flash_data,
286 static struct resource mmc_resources[] __initdata = {
287 DEFINE_RES_MEM(0xffe4e000, 0x100),
288 DEFINE_RES_IRQ(gic_iid(0x5d)),
291 static struct sh_mmcif_plat_data sh_mmcif_plat __initdata = {
293 .caps = MMC_CAP_4_BIT_DATA |
298 /* In the default configuration both decoders reside on I2C bus 0 */
299 #define BOCKW_CAMERA(idx) \
300 static struct i2c_board_info camera##idx##_info = { \
301 I2C_BOARD_INFO("ml86v7667", 0x41 + 2 * (idx)), \
304 static struct soc_camera_link iclink##idx##_ml86v7667 __initdata = { \
306 .i2c_adapter_id = 0, \
307 .board_info = &camera##idx##_info, \
314 static struct rcar_vin_platform_data vin_platform_data __initdata = {
315 .flags = RCAR_VIN_BT656,
318 #define R8A7778_VIN(idx) \
319 static struct resource vin##idx##_resources[] __initdata = { \
320 DEFINE_RES_MEM(0xffc50000 + 0x1000 * (idx), 0x1000), \
321 DEFINE_RES_IRQ(gic_iid(0x5a)), \
324 static struct platform_device_info vin##idx##_info __initdata = { \
325 .parent = &platform_bus, \
326 .name = "r8a7778-vin", \
328 .res = vin##idx##_resources, \
329 .num_res = ARRAY_SIZE(vin##idx##_resources), \
330 .dma_mask = DMA_BIT_MASK(32), \
331 .data = &vin_platform_data, \
332 .size_data = sizeof(vin_platform_data), \
338 static struct resource rsnd_resources[] __initdata = {
339 [RSND_GEN1_SRU] = DEFINE_RES_MEM(0xffd90000, 0x1000),
340 [RSND_GEN1_SSI] = DEFINE_RES_MEM(0xffd91000, 0x1240),
341 [RSND_GEN1_ADG] = DEFINE_RES_MEM(0xfffe0000, 0x24),
344 static struct rsnd_ssi_platform_info rsnd_ssi[] = {
345 RSND_SSI_UNUSED, /* SSI 0 */
346 RSND_SSI_UNUSED, /* SSI 1 */
347 RSND_SSI_UNUSED, /* SSI 2 */
348 RSND_SSI_SET(1, HPBDMA_SLAVE_HPBIF3_TX, gic_iid(0x85), RSND_SSI_PLAY),
349 RSND_SSI_SET(2, HPBDMA_SLAVE_HPBIF4_RX, gic_iid(0x85), RSND_SSI_CLK_PIN_SHARE),
350 RSND_SSI_SET(0, HPBDMA_SLAVE_HPBIF5_TX, gic_iid(0x86), RSND_SSI_PLAY),
351 RSND_SSI_SET(0, HPBDMA_SLAVE_HPBIF6_RX, gic_iid(0x86), 0),
352 RSND_SSI_SET(3, HPBDMA_SLAVE_HPBIF7_TX, gic_iid(0x86), RSND_SSI_PLAY),
353 RSND_SSI_SET(4, HPBDMA_SLAVE_HPBIF8_RX, gic_iid(0x86), RSND_SSI_CLK_PIN_SHARE),
356 static struct rsnd_scu_platform_info rsnd_scu[9] = {
357 { .flags = 0, }, /* SRU 0 */
358 { .flags = 0, }, /* SRU 1 */
359 { .flags = 0, }, /* SRU 2 */
360 { .flags = RSND_SCU_USE_HPBIF, },
361 { .flags = RSND_SCU_USE_HPBIF, },
362 { .flags = RSND_SCU_USE_HPBIF, },
363 { .flags = RSND_SCU_USE_HPBIF, },
364 { .flags = RSND_SCU_USE_HPBIF, },
365 { .flags = RSND_SCU_USE_HPBIF, },
375 static int rsnd_codec_power(int id, int enable)
377 static int sound_user[SOUND_MAX] = {0, 0, 0};
384 usr = sound_user + AK4554_34;
389 usr = sound_user + AK4643_56;
394 usr = sound_user + AK4554_78;
404 u32 val = ioread16(fpga + COMCTLR);
406 iowrite16(val, fpga + COMCTLR);
417 u32 val = ioread16(fpga + COMCTLR);
419 iowrite16(val, fpga + COMCTLR);
426 static int rsnd_start(int id)
428 return rsnd_codec_power(id, 1);
431 static int rsnd_stop(int id)
433 return rsnd_codec_power(id, 0);
436 static struct rcar_snd_info rsnd_info = {
438 .ssi_info = rsnd_ssi,
439 .ssi_info_nr = ARRAY_SIZE(rsnd_ssi),
440 .scu_info = rsnd_scu,
441 .scu_info_nr = ARRAY_SIZE(rsnd_scu),
446 static struct asoc_simple_card_info rsnd_card_info[] = {
450 .card = "SSI56-AK4643",
451 .codec = "ak4642-codec.0-0012",
452 .platform = "rcar_sound",
453 .daifmt = SND_SOC_DAIFMT_LEFT_J | SND_SOC_DAIFMT_CBM_CFM,
455 .name = "rsnd-dai.0",
458 .name = "ak4642-hifi",
465 .card = "SSI3-AK4554(playback)",
466 .codec = "ak4554-adc-dac.0",
467 .platform = "rcar_sound",
468 .daifmt = SND_SOC_DAIFMT_CBS_CFS | SND_SOC_DAIFMT_RIGHT_J,
470 .name = "rsnd-dai.1",
473 .name = "ak4554-hifi",
479 .card = "SSI4-AK4554(capture)",
480 .codec = "ak4554-adc-dac.0",
481 .platform = "rcar_sound",
482 .daifmt = SND_SOC_DAIFMT_CBS_CFS | SND_SOC_DAIFMT_LEFT_J,
484 .name = "rsnd-dai.2",
487 .name = "ak4554-hifi",
493 .card = "SSI7-AK4554(playback)",
494 .codec = "ak4554-adc-dac.1",
495 .platform = "rcar_sound",
496 .daifmt = SND_SOC_DAIFMT_CBS_CFS | SND_SOC_DAIFMT_RIGHT_J,
498 .name = "rsnd-dai.3",
501 .name = "ak4554-hifi",
507 .card = "SSI8-AK4554(capture)",
508 .codec = "ak4554-adc-dac.1",
509 .platform = "rcar_sound",
510 .daifmt = SND_SOC_DAIFMT_CBS_CFS | SND_SOC_DAIFMT_LEFT_J,
512 .name = "rsnd-dai.4",
515 .name = "ak4554-hifi",
520 static const struct pinctrl_map bockw_pinctrl_map[] = {
522 PIN_MAP_MUX_GROUP_DEFAULT("rcar_sound", "pfc-r8a7778",
523 "audio_clk_a", "audio_clk"),
524 PIN_MAP_MUX_GROUP_DEFAULT("rcar_sound", "pfc-r8a7778",
525 "audio_clk_b", "audio_clk"),
526 PIN_MAP_MUX_GROUP_DEFAULT("rcar_sound", "pfc-r8a7778",
527 "ssi34_ctrl", "ssi"),
528 PIN_MAP_MUX_GROUP_DEFAULT("rcar_sound", "pfc-r8a7778",
530 PIN_MAP_MUX_GROUP_DEFAULT("rcar_sound", "pfc-r8a7778",
532 PIN_MAP_MUX_GROUP_DEFAULT("rcar_sound", "pfc-r8a7778",
534 PIN_MAP_MUX_GROUP_DEFAULT("rcar_sound", "pfc-r8a7778",
536 PIN_MAP_MUX_GROUP_DEFAULT("rcar_sound", "pfc-r8a7778",
538 PIN_MAP_MUX_GROUP_DEFAULT("rcar_sound", "pfc-r8a7778",
540 PIN_MAP_MUX_GROUP_DEFAULT("rcar_sound", "pfc-r8a7778",
541 "ssi78_ctrl", "ssi"),
542 PIN_MAP_MUX_GROUP_DEFAULT("rcar_sound", "pfc-r8a7778",
544 PIN_MAP_MUX_GROUP_DEFAULT("rcar_sound", "pfc-r8a7778",
547 PIN_MAP_MUX_GROUP_DEFAULT("r8a777x-ether", "pfc-r8a7778",
548 "ether_rmii", "ether"),
550 PIN_MAP_MUX_GROUP_DEFAULT("sh-hspi.0", "pfc-r8a7778",
553 PIN_MAP_MUX_GROUP_DEFAULT("sh_mmcif", "pfc-r8a7778",
555 PIN_MAP_MUX_GROUP_DEFAULT("sh_mmcif", "pfc-r8a7778",
558 PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.0", "pfc-r8a7778",
559 "scif0_data_a", "scif0"),
560 PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.0", "pfc-r8a7778",
561 "scif0_ctrl", "scif0"),
563 PIN_MAP_MUX_GROUP_DEFAULT("ehci-platform", "pfc-r8a7778",
565 PIN_MAP_MUX_GROUP_DEFAULT(USB1_DEVICE, "pfc-r8a7778",
568 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-r8a7778",
569 "sdhi0_data4", "sdhi0"),
570 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-r8a7778",
571 "sdhi0_ctrl", "sdhi0"),
572 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-r8a7778",
573 "sdhi0_cd", "sdhi0"),
574 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-r8a7778",
575 "sdhi0_wp", "sdhi0"),
577 PIN_MAP_MUX_GROUP_DEFAULT("r8a7778-vin.0", "pfc-r8a7778",
579 PIN_MAP_MUX_GROUP_DEFAULT("r8a7778-vin.0", "pfc-r8a7778",
580 "vin0_data8", "vin0"),
582 PIN_MAP_MUX_GROUP_DEFAULT("r8a7778-vin.1", "pfc-r8a7778",
584 PIN_MAP_MUX_GROUP_DEFAULT("r8a7778-vin.1", "pfc-r8a7778",
585 "vin1_data8", "vin1"),
588 #define PFC 0xfffc0000
590 static void __init bockw_init(void)
596 r8a7778_clock_init();
597 r8a7778_init_irq_extpin(1);
598 r8a7778_add_standard_devices();
600 platform_device_register_full(ðer_info);
602 platform_device_register_full(&vin0_info);
603 /* VIN1 has a pin conflict with Ether */
604 if (!IS_ENABLED(CONFIG_SH_ETH))
605 platform_device_register_full(&vin1_info);
606 platform_device_register_data(&platform_bus, "soc-camera-pdrv", 0,
608 sizeof(iclink0_ml86v7667));
609 platform_device_register_data(&platform_bus, "soc-camera-pdrv", 1,
611 sizeof(iclink1_ml86v7667));
613 i2c_register_board_info(0, i2c0_devices,
614 ARRAY_SIZE(i2c0_devices));
615 spi_register_board_info(spi_board_info,
616 ARRAY_SIZE(spi_board_info));
617 pinctrl_register_mappings(bockw_pinctrl_map,
618 ARRAY_SIZE(bockw_pinctrl_map));
619 r8a7778_pinmux_init();
621 platform_device_register_resndata(
622 &platform_bus, "sh_mmcif", -1,
623 mmc_resources, ARRAY_SIZE(mmc_resources),
624 &sh_mmcif_plat, sizeof(struct sh_mmcif_plat_data));
626 platform_device_register_resndata(
627 &platform_bus, "rcar_usb_phy", -1,
629 ARRAY_SIZE(usb_phy_resources),
630 &usb_phy_platform_data,
631 sizeof(struct rcar_phy_platform_data));
633 regulator_register_fixed(0, dummy_supplies,
634 ARRAY_SIZE(dummy_supplies));
635 regulator_register_always_on(1, "fixed-3.3V", fixed3v3_power_consumers,
636 ARRAY_SIZE(fixed3v3_power_consumers), 3300000);
639 fpga = ioremap_nocache(FPGA, SZ_1M);
644 * IRQ0/1 is cascaded interrupt from FPGA.
645 * it should be cared in the future
646 * Now, it is assuming IRQ0 was used only from SMSC.
648 u16 val = ioread16(fpga + IRQ0MR);
649 val &= ~(1 << 4); /* enable SMSC911x */
650 iowrite16(val, fpga + IRQ0MR);
652 platform_device_register_resndata(
653 &platform_bus, "smsc911x", -1,
654 smsc911x_resources, ARRAY_SIZE(smsc911x_resources),
655 &smsc911x_data, sizeof(smsc911x_data));
659 base = ioremap_nocache(PFC, 0x200);
664 * SDHI CD/WP pin needs pull-up
666 iowrite32(ioread32(base + PUPR4) | (3 << 26), base + PUPR4);
669 platform_device_register_resndata(
670 &platform_bus, "sh_mobile_sdhi", 0,
671 sdhi0_resources, ARRAY_SIZE(sdhi0_resources),
672 &sdhi0_info, sizeof(struct sh_mobile_sdhi_info));
676 clk = clk_get(NULL, "audio_clk_b");
677 clk_set_rate(clk, 24576000);
679 rsnd_codec_power(5, 1); /* enable ak4642 */
681 platform_device_register_simple(
682 "ak4554-adc-dac", 0, NULL, 0);
684 platform_device_register_simple(
685 "ak4554-adc-dac", 1, NULL, 0);
687 platform_device_register_resndata(
688 &platform_bus, "rcar_sound", -1,
689 rsnd_resources, ARRAY_SIZE(rsnd_resources),
690 &rsnd_info, sizeof(rsnd_info));
692 for (i = 0; i < ARRAY_SIZE(rsnd_card_info); i++) {
693 struct platform_device_info cardinfo = {
694 .parent = &platform_bus,
695 .name = "asoc-simple-card",
697 .data = &rsnd_card_info[i],
698 .size_data = sizeof(struct asoc_simple_card_info),
699 .dma_mask = DMA_BIT_MASK(32),
702 platform_device_register_full(&cardinfo);
706 static void __init bockw_init_late(void)
709 ADD_USB_FUNC_DEVICE_IF_POSSIBLE();
712 static const char *bockw_boards_compat_dt[] __initdata = {
717 DT_MACHINE_START(BOCKW_DT, "bockw")
718 .init_early = r8a7778_init_delay,
719 .init_irq = r8a7778_init_irq_dt,
720 .init_machine = bockw_init,
721 .dt_compat = bockw_boards_compat_dt,
722 .init_late = bockw_init_late,