2 * mackerel board support
4 * Copyright (C) 2010 Renesas Solutions Corp.
5 * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
8 * Copyright (C) 2010 Magnus Damm
9 * Copyright (C) 2008 Yoshihiro Shimoda
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; version 2 of the License.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 #include <linux/delay.h>
21 #include <linux/kernel.h>
22 #include <linux/init.h>
23 #include <linux/interrupt.h>
24 #include <linux/irq.h>
25 #include <linux/platform_device.h>
26 #include <linux/gpio.h>
27 #include <linux/input.h>
29 #include <linux/i2c.h>
30 #include <linux/leds.h>
31 #include <linux/mfd/tmio.h>
32 #include <linux/mmc/host.h>
33 #include <linux/mmc/sh_mmcif.h>
34 #include <linux/mmc/sh_mobile_sdhi.h>
35 #include <linux/mtd/mtd.h>
36 #include <linux/mtd/partitions.h>
37 #include <linux/mtd/physmap.h>
38 #include <linux/mtd/sh_flctl.h>
39 #include <linux/pinctrl/machine.h>
40 #include <linux/pinctrl/pinconf-generic.h>
41 #include <linux/platform_data/gpio_backlight.h>
42 #include <linux/pm_clock.h>
43 #include <linux/regulator/fixed.h>
44 #include <linux/regulator/machine.h>
45 #include <linux/smsc911x.h>
46 #include <linux/sh_clk.h>
47 #include <linux/tca6416_keypad.h>
48 #include <linux/usb/renesas_usbhs.h>
49 #include <linux/dma-mapping.h>
51 #include <video/sh_mobile_hdmi.h>
52 #include <video/sh_mobile_lcdc.h>
53 #include <media/sh_mobile_ceu.h>
54 #include <media/soc_camera.h>
55 #include <media/soc_camera_platform.h>
56 #include <sound/sh_fsi.h>
57 #include <sound/simple_card.h>
58 #include <asm/mach/arch.h>
59 #include <asm/mach-types.h>
64 #include "pm-rmobile.h"
69 * Address Interface BusWidth note
70 * ------------------------------------------------------------------
71 * 0x0000_0000 NOR Flash ROM (MCP) 16bit SW7 : bit1 = ON
72 * 0x0800_0000 user area -
73 * 0x1000_0000 NOR Flash ROM (MCP) 16bit SW7 : bit1 = OFF
74 * 0x1400_0000 Ether (LAN9220) 16bit
75 * 0x1600_0000 user area - cannot use with NAND
76 * 0x1800_0000 user area -
78 * 0x4000_0000 LPDDR2-SDRAM (POP) 32bit
84 * SW4 | Boot Area| Master | Remarks
85 * 1 | 2 | 3 | 4 | 5 | 6 | 8 | | Processor|
86 * ----+-----+-----+-----+-----+-----+-----+----------+----------+--------------
87 * ON | ON | OFF | ON | ON | OFF | OFF | External | System | External ROM
88 * ON | ON | ON | ON | ON | OFF | OFF | External | System | ROM Debug
89 * ON | ON | X | ON | OFF | OFF | OFF | Built-in | System | ROM Debug
90 * X | OFF | X | X | X | X | OFF | Built-in | System | MaskROM
91 * OFF | X | X | X | X | X | OFF | Built-in | System | MaskROM
92 * X | X | X | OFF | X | X | OFF | Built-in | System | MaskROM
93 * OFF | ON | OFF | X | X | OFF | ON | External | System | Standalone
94 * ON | OFF | OFF | X | X | OFF | ON | External | Realtime | Standalone
100 * SW1 | SW2 | SW7 | NOR Flash ROM
101 * bit1 | bit1 bit2 | bit1 | Memory allocation
102 * ------+------------+------+------------------
103 * OFF | ON OFF | ON | Area 0
104 * OFF | ON OFF | OFF | Area 4
111 * -----------------------
119 * SW1 | SW2 | SW7 | NAND Flash ROM
120 * bit1 | bit1 bit2 | bit2 | Memory allocation
121 * ------+------------+------+------------------
122 * OFF | ON OFF | ON | FCE 0
123 * OFF | ON OFF | OFF | FCE 1
127 * External interrupt pin settings
129 * IRQX | pin setting | device | level
130 * ------+--------------------+--------------------+-------
131 * IRQ0 | ICR1A.IRQ0SA=0010 | SDHI2 card detect | Low
132 * IRQ6 | ICR1A.IRQ6SA=0011 | Ether(LAN9220) | High
133 * IRQ7 | ICR1A.IRQ7SA=0010 | LCD Touch Panel | Low
134 * IRQ8 | ICR2A.IRQ8SA=0010 | MMC/SD card detect | Low
135 * IRQ9 | ICR2A.IRQ9SA=0010 | KEY(TCA6408) | Low
136 * IRQ21 | ICR4A.IRQ21SA=0011 | Sensor(ADXL345) | High
137 * IRQ22 | ICR4A.IRQ22SA=0011 | Sensor(AK8975) | High
143 * USB0 : CN22 : Function
144 * USB1 : CN31 : Function/Host *1
147 * ----------+---------------+-------------
148 * 1-2 short | VBUS 5V | Host
149 * open | external VBUS | Function
153 * renesas_usbhs driver can use external interrupt mode
154 * (which come from USB-PHY) or autonomy mode (it use own interrupt)
155 * for detecting connection/disconnection when Function.
156 * USB will be power OFF while it has been disconnecting
157 * if external interrupt mode, and it is always power ON if autonomy mode,
159 * mackerel can not use external interrupt (IRQ7-PORT167) mode on "USB0",
160 * because Touchscreen is using IRQ7-PORT40.
161 * It is impossible to use IRQ7 demux on this board.
175 * Power voltage : 1.8v or 3.3v
176 * J22 : select power voltage *1
181 * Please change J22 depends the card to be used.
182 * MMC's OCR field set to support either voltage for the card inserted.
185 * | bit1 | bit2 | bit3 | bit4
186 * -------------+------+------+------+-------
187 * MMC0 OFF | OFF | X | ON | X (Use MMCIF)
188 * SDHI1 OFF | ON | X | OFF | X (Use MFD_SH_MOBILE_SDHI)
202 * it needs amixer settings for playing
204 * amixer set "Headphone Enable" on
207 /* Fixed 3.3V and 1.8V regulators to be used by multiple devices */
208 static struct regulator_consumer_supply fixed1v8_power_consumers[] =
211 * J22 on mackerel switches mmcif.0 and sdhi.1 between 1.8V and 3.3V
212 * Since we cannot support both voltages, we support the default 1.8V
214 REGULATOR_SUPPLY("vmmc", "sh_mobile_sdhi.1"),
215 REGULATOR_SUPPLY("vqmmc", "sh_mobile_sdhi.1"),
216 REGULATOR_SUPPLY("vmmc", "sh_mmcif.0"),
217 REGULATOR_SUPPLY("vqmmc", "sh_mmcif.0"),
220 static struct regulator_consumer_supply fixed3v3_power_consumers[] =
222 REGULATOR_SUPPLY("vmmc", "sh_mobile_sdhi.0"),
223 REGULATOR_SUPPLY("vqmmc", "sh_mobile_sdhi.0"),
224 REGULATOR_SUPPLY("vmmc", "sh_mobile_sdhi.2"),
225 REGULATOR_SUPPLY("vqmmc", "sh_mobile_sdhi.2"),
228 /* Dummy supplies, where voltage doesn't matter */
229 static struct regulator_consumer_supply dummy_supplies[] = {
230 REGULATOR_SUPPLY("vddvario", "smsc911x"),
231 REGULATOR_SUPPLY("vdd33a", "smsc911x"),
235 static struct mtd_partition nor_flash_partitions[] = {
238 .offset = 0x00000000,
240 .mask_flags = MTD_WRITEABLE,
244 .offset = MTDPART_OFS_APPEND,
246 .mask_flags = MTD_WRITEABLE,
250 .offset = MTDPART_OFS_APPEND,
251 .size = 8 * 1024 * 1024,
252 .mask_flags = MTD_WRITEABLE,
256 .offset = MTDPART_OFS_APPEND,
257 .size = 8 * 1024 * 1024,
261 .offset = MTDPART_OFS_APPEND,
262 .size = MTDPART_SIZ_FULL,
266 static struct physmap_flash_data nor_flash_data = {
268 .parts = nor_flash_partitions,
269 .nr_parts = ARRAY_SIZE(nor_flash_partitions),
272 static struct resource nor_flash_resources[] = {
274 .start = 0x20000000, /* CS0 shadow instead of regular CS0 */
275 .end = 0x28000000 - 1, /* needed by USB MASK ROM boot */
276 .flags = IORESOURCE_MEM,
280 static struct platform_device nor_flash_device = {
281 .name = "physmap-flash",
283 .platform_data = &nor_flash_data,
285 .num_resources = ARRAY_SIZE(nor_flash_resources),
286 .resource = nor_flash_resources,
290 static struct resource smc911x_resources[] = {
293 .end = 0x16000000 - 1,
294 .flags = IORESOURCE_MEM,
296 .start = evt2irq(0x02c0) /* IRQ6A */,
297 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
301 static struct smsc911x_platform_config smsc911x_info = {
302 .flags = SMSC911X_USE_16BIT | SMSC911X_SAVE_MAC_ADDRESS,
303 .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
304 .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
307 static struct platform_device smc911x_device = {
310 .num_resources = ARRAY_SIZE(smc911x_resources),
311 .resource = smc911x_resources,
313 .platform_data = &smsc911x_info,
318 static struct sh_mobile_meram_info mackerel_meram_info = {
319 .addr_mode = SH_MOBILE_MERAM_MODE1,
322 static struct resource meram_resources[] = {
327 .flags = IORESOURCE_MEM,
333 .flags = IORESOURCE_MEM,
337 static struct platform_device meram_device = {
338 .name = "sh_mobile_meram",
340 .num_resources = ARRAY_SIZE(meram_resources),
341 .resource = meram_resources,
343 .platform_data = &mackerel_meram_info,
347 /* LCDC and backlight */
348 static struct fb_videomode mackerel_lcdc_modes[] = {
350 .name = "WVGA Panel",
363 static const struct sh_mobile_meram_cfg lcd_meram_cfg = {
372 static struct sh_mobile_lcdc_info lcdc_info = {
373 .meram_dev = &mackerel_meram_info,
374 .clock_source = LCDC_CLK_BUS,
376 .chan = LCDC_CHAN_MAINLCD,
377 .fourcc = V4L2_PIX_FMT_RGB565,
378 .lcd_modes = mackerel_lcdc_modes,
379 .num_modes = ARRAY_SIZE(mackerel_lcdc_modes),
380 .interface_type = RGB24,
387 .meram_cfg = &lcd_meram_cfg,
391 static struct resource lcdc_resources[] = {
396 .flags = IORESOURCE_MEM,
399 .start = intcs_evt2irq(0x580),
400 .flags = IORESOURCE_IRQ,
404 static struct platform_device lcdc_device = {
405 .name = "sh_mobile_lcdc_fb",
406 .num_resources = ARRAY_SIZE(lcdc_resources),
407 .resource = lcdc_resources,
409 .platform_data = &lcdc_info,
410 .coherent_dma_mask = DMA_BIT_MASK(32),
414 static struct gpio_backlight_platform_data gpio_backlight_data = {
415 .fbdev = &lcdc_device.dev,
421 static struct platform_device gpio_backlight_device = {
422 .name = "gpio-backlight",
424 .platform_data = &gpio_backlight_data,
429 static struct sh_mobile_hdmi_info hdmi_info = {
430 .flags = HDMI_SND_SRC_SPDIF,
433 static struct resource hdmi_resources[] = {
438 .flags = IORESOURCE_MEM,
441 /* There's also an HDMI interrupt on INTCS @ 0x18e0 */
442 .start = evt2irq(0x17e0),
443 .flags = IORESOURCE_IRQ,
447 static struct platform_device hdmi_device = {
448 .name = "sh-mobile-hdmi",
449 .num_resources = ARRAY_SIZE(hdmi_resources),
450 .resource = hdmi_resources,
453 .platform_data = &hdmi_info,
457 static const struct sh_mobile_meram_cfg hdmi_meram_cfg = {
466 static struct sh_mobile_lcdc_info hdmi_lcdc_info = {
467 .meram_dev = &mackerel_meram_info,
468 .clock_source = LCDC_CLK_EXTERNAL,
470 .chan = LCDC_CHAN_MAINLCD,
471 .fourcc = V4L2_PIX_FMT_RGB565,
472 .interface_type = RGB24,
474 .flags = LCDC_FLAGS_DWPOL,
475 .meram_cfg = &hdmi_meram_cfg,
476 .tx_dev = &hdmi_device,
480 static struct resource hdmi_lcdc_resources[] = {
485 .flags = IORESOURCE_MEM,
488 .start = intcs_evt2irq(0x1780),
489 .flags = IORESOURCE_IRQ,
493 static struct platform_device hdmi_lcdc_device = {
494 .name = "sh_mobile_lcdc_fb",
495 .num_resources = ARRAY_SIZE(hdmi_lcdc_resources),
496 .resource = hdmi_lcdc_resources,
499 .platform_data = &hdmi_lcdc_info,
500 .coherent_dma_mask = DMA_BIT_MASK(32),
504 static struct asoc_simple_card_info fsi2_hdmi_info = {
506 .card = "FSI2B-HDMI",
507 .codec = "sh-mobile-hdmi",
508 .platform = "sh_fsi2",
509 .daifmt = SND_SOC_DAIFMT_CBS_CFS,
514 .name = "sh_mobile_hdmi-hifi",
518 static struct platform_device fsi_hdmi_device = {
519 .name = "asoc-simple-card",
522 .platform_data = &fsi2_hdmi_info,
523 .coherent_dma_mask = DMA_BIT_MASK(32),
524 .dma_mask = &fsi_hdmi_device.dev.coherent_dma_mask,
528 static void __init hdmi_init_pm_clock(void)
530 struct clk *hdmi_ick = clk_get(&hdmi_device.dev, "ick");
534 if (IS_ERR(hdmi_ick)) {
535 ret = PTR_ERR(hdmi_ick);
536 pr_err("Cannot get HDMI ICK: %d\n", ret);
540 ret = clk_set_parent(&sh7372_pllc2_clk, &sh7372_dv_clki_div2_clk);
542 pr_err("Cannot set PLLC2 parent: %d, %d users\n",
543 ret, sh7372_pllc2_clk.usecount);
547 pr_debug("PLLC2 initial frequency %lu\n",
548 clk_get_rate(&sh7372_pllc2_clk));
550 rate = clk_round_rate(&sh7372_pllc2_clk, 594000000);
552 pr_err("Cannot get suitable rate: %ld\n", rate);
557 ret = clk_set_rate(&sh7372_pllc2_clk, rate);
559 pr_err("Cannot set rate %ld: %d\n", rate, ret);
563 pr_debug("PLLC2 set frequency %lu\n", rate);
565 ret = clk_set_parent(hdmi_ick, &sh7372_pllc2_clk);
567 pr_err("Cannot set HDMI parent: %d\n", ret);
570 if (!IS_ERR(hdmi_ick))
574 /* USBHS0 is connected to CN22 which takes a USB Mini-B plug
576 * The sh7372 SoC has IRQ7 set aside for USBHS0 hotplug,
577 * but on this particular board IRQ7 is already used by
578 * the touch screen. This leaves us with software polling.
580 #define USBHS0_POLL_INTERVAL (HZ * 5)
582 struct usbhs_private {
583 void __iomem *usbphyaddr;
584 void __iomem *usbcrcaddr;
585 struct renesas_usbhs_platform_info info;
586 struct delayed_work work;
587 struct platform_device *pdev;
590 #define usbhs_get_priv(pdev) \
591 container_of(renesas_usbhs_get_info(pdev), \
592 struct usbhs_private, info)
594 #define usbhs_is_connected(priv) \
595 (!((1 << 7) & __raw_readw(priv->usbcrcaddr)))
597 static int usbhs_get_vbus(struct platform_device *pdev)
599 return usbhs_is_connected(usbhs_get_priv(pdev));
602 static int usbhs_phy_reset(struct platform_device *pdev)
604 struct usbhs_private *priv = usbhs_get_priv(pdev);
607 __raw_writew(0x8a0a, priv->usbcrcaddr);
612 static int usbhs0_get_id(struct platform_device *pdev)
617 static void usbhs0_work_function(struct work_struct *work)
619 struct usbhs_private *priv = container_of(work, struct usbhs_private,
622 renesas_usbhs_call_notify_hotplug(priv->pdev);
623 schedule_delayed_work(&priv->work, USBHS0_POLL_INTERVAL);
626 static int usbhs0_hardware_init(struct platform_device *pdev)
628 struct usbhs_private *priv = usbhs_get_priv(pdev);
631 INIT_DELAYED_WORK(&priv->work, usbhs0_work_function);
632 schedule_delayed_work(&priv->work, USBHS0_POLL_INTERVAL);
636 static int usbhs0_hardware_exit(struct platform_device *pdev)
638 struct usbhs_private *priv = usbhs_get_priv(pdev);
640 cancel_delayed_work_sync(&priv->work);
645 static struct usbhs_private usbhs0_private = {
646 .usbcrcaddr = IOMEM(0xe605810c), /* USBCR2 */
648 .platform_callback = {
649 .hardware_init = usbhs0_hardware_init,
650 .hardware_exit = usbhs0_hardware_exit,
651 .phy_reset = usbhs_phy_reset,
652 .get_id = usbhs0_get_id,
653 .get_vbus = usbhs_get_vbus,
657 .d0_tx_id = SHDMA_SLAVE_USB0_TX,
658 .d1_rx_id = SHDMA_SLAVE_USB0_RX,
663 static struct resource usbhs0_resources[] = {
667 .end = 0xe68900e6 - 1,
668 .flags = IORESOURCE_MEM,
671 .start = evt2irq(0x1ca0) /* USB0_USB0I0 */,
672 .flags = IORESOURCE_IRQ,
676 static struct platform_device usbhs0_device = {
677 .name = "renesas_usbhs",
680 .platform_data = &usbhs0_private.info,
682 .num_resources = ARRAY_SIZE(usbhs0_resources),
683 .resource = usbhs0_resources,
686 /* USBHS1 is connected to CN31 which takes a USB Mini-AB plug
688 * Use J30 to select between Host and Function. This setting
689 * can however not be detected by software. Hotplug of USBHS1
690 * is provided via IRQ8.
692 * Current USB1 works as "USB Host".
695 * If you want to use it as "USB gadget",
697 * - modify usbhs1_get_id() USBHS_HOST -> USBHS_GADGET
698 * - add .get_vbus = usbhs_get_vbus in usbhs1_private
699 * - check usbhs0_device(pio)/usbhs1_device(irq) order in mackerel_devices.
701 #define IRQ8 evt2irq(0x0300)
702 #define USB_PHY_MODE (1 << 4)
703 #define USB_PHY_INT_EN ((1 << 3) | (1 << 2))
704 #define USB_PHY_ON (1 << 1)
705 #define USB_PHY_OFF (1 << 0)
706 #define USB_PHY_INT_CLR (USB_PHY_ON | USB_PHY_OFF)
708 static irqreturn_t usbhs1_interrupt(int irq, void *data)
710 struct platform_device *pdev = data;
711 struct usbhs_private *priv = usbhs_get_priv(pdev);
713 dev_dbg(&pdev->dev, "%s\n", __func__);
715 renesas_usbhs_call_notify_hotplug(pdev);
718 __raw_writew(__raw_readw(priv->usbphyaddr) | USB_PHY_INT_CLR,
724 static int usbhs1_hardware_init(struct platform_device *pdev)
726 struct usbhs_private *priv = usbhs_get_priv(pdev);
729 /* clear interrupt status */
730 __raw_writew(USB_PHY_MODE | USB_PHY_INT_CLR, priv->usbphyaddr);
732 ret = request_irq(IRQ8, usbhs1_interrupt, IRQF_TRIGGER_HIGH,
733 dev_name(&pdev->dev), pdev);
735 dev_err(&pdev->dev, "request_irq err\n");
739 /* enable USB phy interrupt */
740 __raw_writew(USB_PHY_MODE | USB_PHY_INT_EN, priv->usbphyaddr);
745 static int usbhs1_hardware_exit(struct platform_device *pdev)
747 struct usbhs_private *priv = usbhs_get_priv(pdev);
749 /* clear interrupt status */
750 __raw_writew(USB_PHY_MODE | USB_PHY_INT_CLR, priv->usbphyaddr);
752 free_irq(IRQ8, pdev);
757 static int usbhs1_get_id(struct platform_device *pdev)
762 static u32 usbhs1_pipe_cfg[] = {
763 USB_ENDPOINT_XFER_CONTROL,
764 USB_ENDPOINT_XFER_ISOC,
765 USB_ENDPOINT_XFER_ISOC,
766 USB_ENDPOINT_XFER_BULK,
767 USB_ENDPOINT_XFER_BULK,
768 USB_ENDPOINT_XFER_BULK,
769 USB_ENDPOINT_XFER_INT,
770 USB_ENDPOINT_XFER_INT,
771 USB_ENDPOINT_XFER_INT,
772 USB_ENDPOINT_XFER_BULK,
773 USB_ENDPOINT_XFER_BULK,
774 USB_ENDPOINT_XFER_BULK,
775 USB_ENDPOINT_XFER_BULK,
776 USB_ENDPOINT_XFER_BULK,
777 USB_ENDPOINT_XFER_BULK,
778 USB_ENDPOINT_XFER_BULK,
781 static struct usbhs_private usbhs1_private = {
782 .usbphyaddr = IOMEM(0xe60581e2), /* USBPHY1INTAP */
783 .usbcrcaddr = IOMEM(0xe6058130), /* USBCR4 */
785 .platform_callback = {
786 .hardware_init = usbhs1_hardware_init,
787 .hardware_exit = usbhs1_hardware_exit,
788 .get_id = usbhs1_get_id,
789 .phy_reset = usbhs_phy_reset,
794 .pipe_type = usbhs1_pipe_cfg,
795 .pipe_size = ARRAY_SIZE(usbhs1_pipe_cfg),
796 .d0_tx_id = SHDMA_SLAVE_USB1_TX,
797 .d1_rx_id = SHDMA_SLAVE_USB1_RX,
802 static struct resource usbhs1_resources[] = {
806 .end = 0xe68b00e6 - 1,
807 .flags = IORESOURCE_MEM,
810 .start = evt2irq(0x1ce0) /* USB1_USB1I0 */,
811 .flags = IORESOURCE_IRQ,
815 static struct platform_device usbhs1_device = {
816 .name = "renesas_usbhs",
819 .platform_data = &usbhs1_private.info,
820 .dma_mask = &usbhs1_device.dev.coherent_dma_mask,
821 .coherent_dma_mask = DMA_BIT_MASK(32),
823 .num_resources = ARRAY_SIZE(usbhs1_resources),
824 .resource = usbhs1_resources,
828 static struct gpio_led mackerel_leds[] = {
832 .default_state = LEDS_GPIO_DEFSTATE_ON,
837 .default_state = LEDS_GPIO_DEFSTATE_ON,
842 .default_state = LEDS_GPIO_DEFSTATE_ON,
847 .default_state = LEDS_GPIO_DEFSTATE_ON,
851 static struct gpio_led_platform_data mackerel_leds_pdata = {
852 .leds = mackerel_leds,
853 .num_leds = ARRAY_SIZE(mackerel_leds),
856 static struct platform_device leds_device = {
860 .platform_data = &mackerel_leds_pdata,
865 #define IRQ_FSI evt2irq(0x1840)
866 static struct sh_fsi_platform_info fsi_info = {
868 .tx_id = SHDMA_SLAVE_FSIA_TX,
869 .rx_id = SHDMA_SLAVE_FSIA_RX,
872 .flags = SH_FSI_CLK_CPG |
877 static struct resource fsi_resources[] = {
879 /* we need 0xFE1F0000 to access DMA
880 * instead of 0xFE3C0000 */
883 .end = 0xFE1F0400 - 1,
884 .flags = IORESOURCE_MEM,
888 .flags = IORESOURCE_IRQ,
892 static struct platform_device fsi_device = {
895 .num_resources = ARRAY_SIZE(fsi_resources),
896 .resource = fsi_resources,
898 .platform_data = &fsi_info,
902 static struct asoc_simple_card_info fsi2_ak4643_info = {
904 .card = "FSI2A-AK4643",
905 .codec = "ak4642-codec.0-0013",
906 .platform = "sh_fsi2",
907 .daifmt = SND_SOC_DAIFMT_LEFT_J | SND_SOC_DAIFMT_CBM_CFM,
912 .name = "ak4642-hifi",
917 static struct platform_device fsi_ak4643_device = {
918 .name = "asoc-simple-card",
920 .platform_data = &fsi2_ak4643_info,
921 .coherent_dma_mask = DMA_BIT_MASK(32),
922 .dma_mask = &fsi_ak4643_device.dev.coherent_dma_mask,
927 static struct mtd_partition nand_partition_info[] = {
931 .size = 128 * 1024 * 1024,
935 .offset = MTDPART_OFS_APPEND,
936 .size = 256 * 1024 * 1024,
940 .offset = MTDPART_OFS_APPEND,
941 .size = 128 * 1024 * 1024,
945 static struct resource nand_flash_resources[] = {
949 .flags = IORESOURCE_MEM,
952 .start = evt2irq(0x0d80), /* flstei: status error irq */
953 .flags = IORESOURCE_IRQ,
957 static struct sh_flctl_platform_data nand_flash_data = {
958 .parts = nand_partition_info,
959 .nr_parts = ARRAY_SIZE(nand_partition_info),
960 .flcmncr_val = CLK_16B_12L_4H | TYPESEL_SET
961 | SHBUSSEL | SEL_16BIT | SNAND_E,
965 static struct platform_device nand_flash_device = {
967 .resource = nand_flash_resources,
968 .num_resources = ARRAY_SIZE(nand_flash_resources),
970 .platform_data = &nand_flash_data,
975 static struct sh_mobile_sdhi_info sdhi0_info = {
976 .dma_slave_tx = SHDMA_SLAVE_SDHI0_TX,
977 .dma_slave_rx = SHDMA_SLAVE_SDHI0_RX,
978 .tmio_flags = TMIO_MMC_USE_GPIO_CD,
979 .tmio_caps = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ,
983 static struct resource sdhi0_resources[] = {
988 .flags = IORESOURCE_MEM,
990 .name = SH_MOBILE_SDHI_IRQ_SDCARD,
991 .start = evt2irq(0x0e20) /* SDHI0_SDHI0I1 */,
992 .flags = IORESOURCE_IRQ,
994 .name = SH_MOBILE_SDHI_IRQ_SDIO,
995 .start = evt2irq(0x0e40) /* SDHI0_SDHI0I2 */,
996 .flags = IORESOURCE_IRQ,
1000 static struct platform_device sdhi0_device = {
1001 .name = "sh_mobile_sdhi",
1002 .num_resources = ARRAY_SIZE(sdhi0_resources),
1003 .resource = sdhi0_resources,
1006 .platform_data = &sdhi0_info,
1010 #if !IS_ENABLED(CONFIG_MMC_SH_MMCIF)
1013 /* GPIO 41 can trigger IRQ8, but it is used by USBHS1, we have to poll */
1014 static struct sh_mobile_sdhi_info sdhi1_info = {
1015 .dma_slave_tx = SHDMA_SLAVE_SDHI1_TX,
1016 .dma_slave_rx = SHDMA_SLAVE_SDHI1_RX,
1017 .tmio_flags = TMIO_MMC_WRPROTECT_DISABLE | TMIO_MMC_USE_GPIO_CD,
1018 .tmio_caps = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ |
1023 static struct resource sdhi1_resources[] = {
1026 .start = 0xe6860000,
1028 .flags = IORESOURCE_MEM,
1030 .name = SH_MOBILE_SDHI_IRQ_SDCARD,
1031 .start = evt2irq(0x0ea0), /* SDHI1_SDHI1I1 */
1032 .flags = IORESOURCE_IRQ,
1034 .name = SH_MOBILE_SDHI_IRQ_SDIO,
1035 .start = evt2irq(0x0ec0), /* SDHI1_SDHI1I2 */
1036 .flags = IORESOURCE_IRQ,
1040 static struct platform_device sdhi1_device = {
1041 .name = "sh_mobile_sdhi",
1042 .num_resources = ARRAY_SIZE(sdhi1_resources),
1043 .resource = sdhi1_resources,
1046 .platform_data = &sdhi1_info,
1054 * The card detect pin of the top SD/MMC slot (CN23) is active low and is
1055 * connected to GPIO SCIFB_SCK of SH7372 (GPIO 162).
1057 static struct sh_mobile_sdhi_info sdhi2_info = {
1058 .dma_slave_tx = SHDMA_SLAVE_SDHI2_TX,
1059 .dma_slave_rx = SHDMA_SLAVE_SDHI2_RX,
1060 .tmio_flags = TMIO_MMC_WRPROTECT_DISABLE | TMIO_MMC_USE_GPIO_CD,
1061 .tmio_caps = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ |
1066 static struct resource sdhi2_resources[] = {
1069 .start = 0xe6870000,
1071 .flags = IORESOURCE_MEM,
1073 .name = SH_MOBILE_SDHI_IRQ_SDCARD,
1074 .start = evt2irq(0x1220), /* SDHI2_SDHI2I1 */
1075 .flags = IORESOURCE_IRQ,
1077 .name = SH_MOBILE_SDHI_IRQ_SDIO,
1078 .start = evt2irq(0x1240), /* SDHI2_SDHI2I2 */
1079 .flags = IORESOURCE_IRQ,
1083 static struct platform_device sdhi2_device = {
1084 .name = "sh_mobile_sdhi",
1085 .num_resources = ARRAY_SIZE(sdhi2_resources),
1086 .resource = sdhi2_resources,
1089 .platform_data = &sdhi2_info,
1094 #if IS_ENABLED(CONFIG_MMC_SH_MMCIF)
1095 static struct resource sh_mmcif_resources[] = {
1098 .start = 0xE6BD0000,
1100 .flags = IORESOURCE_MEM,
1104 .start = evt2irq(0x1ac0),
1105 .flags = IORESOURCE_IRQ,
1109 .start = evt2irq(0x1ae0),
1110 .flags = IORESOURCE_IRQ,
1114 static struct sh_mmcif_plat_data sh_mmcif_plat = {
1116 .caps = MMC_CAP_4_BIT_DATA |
1117 MMC_CAP_8_BIT_DATA |
1119 .use_cd_gpio = true,
1120 /* card detect pin for SD/MMC slot (CN7) */
1122 .slave_id_tx = SHDMA_SLAVE_MMCIF_TX,
1123 .slave_id_rx = SHDMA_SLAVE_MMCIF_RX,
1126 static struct platform_device sh_mmcif_device = {
1131 .coherent_dma_mask = 0xffffffff,
1132 .platform_data = &sh_mmcif_plat,
1134 .num_resources = ARRAY_SIZE(sh_mmcif_resources),
1135 .resource = sh_mmcif_resources,
1139 static int mackerel_camera_add(struct soc_camera_device *icd);
1140 static void mackerel_camera_del(struct soc_camera_device *icd);
1142 static int camera_set_capture(struct soc_camera_platform_info *info,
1145 return 0; /* camera sensor always enabled */
1148 static struct soc_camera_platform_info camera_info = {
1149 .format_name = "UYVY",
1152 .code = MEDIA_BUS_FMT_UYVY8_2X8,
1153 .colorspace = V4L2_COLORSPACE_SMPTE170M,
1154 .field = V4L2_FIELD_NONE,
1158 .mbus_param = V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_MASTER |
1159 V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_HIGH |
1160 V4L2_MBUS_DATA_ACTIVE_HIGH,
1161 .mbus_type = V4L2_MBUS_PARALLEL,
1162 .set_capture = camera_set_capture,
1165 static struct soc_camera_link camera_link = {
1167 .add_device = mackerel_camera_add,
1168 .del_device = mackerel_camera_del,
1169 .module_name = "soc_camera_platform",
1170 .priv = &camera_info,
1173 static struct platform_device *camera_device;
1175 static void mackerel_camera_release(struct device *dev)
1177 soc_camera_platform_release(&camera_device);
1180 static int mackerel_camera_add(struct soc_camera_device *icd)
1182 return soc_camera_platform_add(icd, &camera_device, &camera_link,
1183 mackerel_camera_release, 0);
1186 static void mackerel_camera_del(struct soc_camera_device *icd)
1188 soc_camera_platform_del(icd, camera_device, &camera_link);
1191 static struct sh_mobile_ceu_info sh_mobile_ceu_info = {
1192 .flags = SH_CEU_FLAG_USE_8BIT_BUS,
1197 static struct resource ceu_resources[] = {
1200 .start = 0xfe910000,
1202 .flags = IORESOURCE_MEM,
1205 .start = intcs_evt2irq(0x880),
1206 .flags = IORESOURCE_IRQ,
1209 /* place holder for contiguous memory */
1213 static struct platform_device ceu_device = {
1214 .name = "sh_mobile_ceu",
1215 .id = 0, /* "ceu0" clock */
1216 .num_resources = ARRAY_SIZE(ceu_resources),
1217 .resource = ceu_resources,
1219 .platform_data = &sh_mobile_ceu_info,
1220 .coherent_dma_mask = 0xffffffff,
1224 static struct platform_device mackerel_camera = {
1225 .name = "soc-camera-pdrv",
1228 .platform_data = &camera_link,
1232 static struct platform_device *mackerel_devices[] __initdata = {
1236 &gpio_backlight_device,
1245 #if !IS_ENABLED(CONFIG_MMC_SH_MMCIF)
1258 /* Keypad Initialization */
1259 #define KEYPAD_BUTTON(ev_type, ev_code, act_low) \
1263 .active_low = act_low, \
1266 #define KEYPAD_BUTTON_LOW(event_code) KEYPAD_BUTTON(EV_KEY, event_code, 1)
1268 static struct tca6416_button mackerel_gpio_keys[] = {
1269 KEYPAD_BUTTON_LOW(KEY_HOME),
1270 KEYPAD_BUTTON_LOW(KEY_MENU),
1271 KEYPAD_BUTTON_LOW(KEY_BACK),
1272 KEYPAD_BUTTON_LOW(KEY_POWER),
1275 static struct tca6416_keys_platform_data mackerel_tca6416_keys_info = {
1276 .buttons = mackerel_gpio_keys,
1277 .nbuttons = ARRAY_SIZE(mackerel_gpio_keys),
1284 #define IRQ7 evt2irq(0x02e0)
1285 #define IRQ9 evt2irq(0x0320)
1287 static struct i2c_board_info i2c0_devices[] = {
1289 I2C_BOARD_INFO("ak4643", 0x13),
1293 I2C_BOARD_INFO("tca6408-keys", 0x20),
1294 .platform_data = &mackerel_tca6416_keys_info,
1299 I2C_BOARD_INFO("st1232-ts", 0x55),
1304 #define IRQ21 evt2irq(0x32a0)
1306 static struct i2c_board_info i2c1_devices[] = {
1309 I2C_BOARD_INFO("adxl34x", 0x53),
1314 static unsigned long pin_pulldown_conf[] = {
1315 PIN_CONF_PACKED(PIN_CONFIG_BIAS_PULL_DOWN, 0),
1318 static const struct pinctrl_map mackerel_pinctrl_map[] = {
1320 PIN_MAP_MUX_GROUP_DEFAULT("1-0053", "pfc-sh7372",
1321 "intc_irq21", "intc"),
1323 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_ceu.0", "pfc-sh7372",
1324 "ceu_data_0_7", "ceu"),
1325 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_ceu.0", "pfc-sh7372",
1326 "ceu_clk_0", "ceu"),
1327 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_ceu.0", "pfc-sh7372",
1329 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_ceu.0", "pfc-sh7372",
1330 "ceu_field", "ceu"),
1332 PIN_MAP_MUX_GROUP_DEFAULT("sh_flctl.0", "pfc-sh7372",
1333 "flctl_data", "flctl"),
1334 PIN_MAP_MUX_GROUP_DEFAULT("sh_flctl.0", "pfc-sh7372",
1335 "flctl_ce0", "flctl"),
1336 PIN_MAP_MUX_GROUP_DEFAULT("sh_flctl.0", "pfc-sh7372",
1337 "flctl_ctrl", "flctl"),
1339 PIN_MAP_MUX_GROUP_DEFAULT("asoc-simple-card.0", "pfc-sh7372",
1340 "fsia_sclk_in", "fsia"),
1341 PIN_MAP_MUX_GROUP_DEFAULT("asoc-simple-card.0", "pfc-sh7372",
1342 "fsia_data_in", "fsia"),
1343 PIN_MAP_MUX_GROUP_DEFAULT("asoc-simple-card.0", "pfc-sh7372",
1344 "fsia_data_out", "fsia"),
1346 PIN_MAP_MUX_GROUP_DEFAULT("asoc-simple-card.1", "pfc-sh7372",
1347 "fsib_mclk_in", "fsib"),
1349 PIN_MAP_MUX_GROUP_DEFAULT("sh-mobile-hdmi", "pfc-sh7372",
1352 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_lcdc_fb.0", "pfc-sh7372",
1353 "lcd_data24", "lcd"),
1354 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_lcdc_fb.0", "pfc-sh7372",
1357 PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.0", "pfc-sh7372",
1358 "scifa0_data", "scifa0"),
1359 /* SCIFA2 (GT-720F GPS module) */
1360 PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.2", "pfc-sh7372",
1361 "scifa2_data", "scifa2"),
1363 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-sh7372",
1364 "sdhi0_data4", "sdhi0"),
1365 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-sh7372",
1366 "sdhi0_ctrl", "sdhi0"),
1367 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-sh7372",
1368 "sdhi0_wp", "sdhi0"),
1369 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-sh7372",
1370 "intc_irq26_1", "intc"),
1372 #if !IS_ENABLED(CONFIG_MMC_SH_MMCIF)
1373 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.1", "pfc-sh7372",
1374 "sdhi1_data4", "sdhi1"),
1375 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.1", "pfc-sh7372",
1376 "sdhi1_ctrl", "sdhi1"),
1379 PIN_MAP_MUX_GROUP_DEFAULT("sh_mmcif.0", "pfc-sh7372",
1380 "mmc0_data8_0", "mmc0"),
1381 PIN_MAP_MUX_GROUP_DEFAULT("sh_mmcif.0", "pfc-sh7372",
1382 "mmc0_ctrl_0", "mmc0"),
1385 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.2", "pfc-sh7372",
1386 "sdhi2_data4", "sdhi2"),
1387 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.2", "pfc-sh7372",
1388 "sdhi2_ctrl", "sdhi2"),
1390 PIN_MAP_MUX_GROUP_DEFAULT("smsc911x", "pfc-sh7372",
1392 PIN_MAP_MUX_GROUP_DEFAULT("smsc911x", "pfc-sh7372",
1393 "intc_irq6_0", "intc"),
1395 PIN_MAP_MUX_GROUP_DEFAULT("0-0055", "pfc-sh7372",
1396 "intc_irq7_0", "intc"),
1398 PIN_MAP_MUX_GROUP_DEFAULT("0-0020", "pfc-sh7372",
1399 "intc_irq9_0", "intc"),
1401 PIN_MAP_MUX_GROUP_DEFAULT("renesas_usbhs.0", "pfc-sh7372",
1402 "usb0_vbus", "usb0"),
1403 PIN_MAP_CONFIGS_GROUP_DEFAULT("renesas_usbhs.0", "pfc-sh7372",
1404 "usb0_vbus", pin_pulldown_conf),
1406 PIN_MAP_MUX_GROUP_DEFAULT("renesas_usbhs.1", "pfc-sh7372",
1407 "usb1_vbus", "usb1"),
1408 PIN_MAP_CONFIGS_GROUP_DEFAULT("renesas_usbhs.1", "pfc-sh7372",
1409 "usb1_vbus", pin_pulldown_conf),
1410 PIN_MAP_MUX_GROUP_DEFAULT("renesas_usbhs.1", "pfc-sh7372",
1411 "usb1_otg_id_0", "usb1"),
1414 #define GPIO_PORT9CR IOMEM(0xE6051009)
1415 #define GPIO_PORT10CR IOMEM(0xE605100A)
1416 #define SRCR4 IOMEM(0xe61580bc)
1417 #define USCCR1 IOMEM(0xE6058144)
1418 static void __init mackerel_init(void)
1420 static struct pm_domain_device domain_devices[] __initdata = {
1421 { "A4LC", &lcdc_device, },
1422 { "A4LC", &hdmi_lcdc_device, },
1423 { "A4LC", &meram_device, },
1424 { "A4MP", &fsi_device, },
1425 { "A3SP", &usbhs0_device, },
1426 { "A3SP", &usbhs1_device, },
1427 { "A3SP", &nand_flash_device, },
1428 { "A3SP", &sdhi0_device, },
1429 #if !IS_ENABLED(CONFIG_MMC_SH_MMCIF)
1430 { "A3SP", &sdhi1_device, },
1432 { "A3SP", &sh_mmcif_device, },
1434 { "A3SP", &sdhi2_device, },
1435 { "A4R", &ceu_device, },
1440 regulator_register_always_on(0, "fixed-1.8V", fixed1v8_power_consumers,
1441 ARRAY_SIZE(fixed1v8_power_consumers), 1800000);
1442 regulator_register_always_on(1, "fixed-3.3V", fixed3v3_power_consumers,
1443 ARRAY_SIZE(fixed3v3_power_consumers), 3300000);
1444 regulator_register_fixed(2, dummy_supplies, ARRAY_SIZE(dummy_supplies));
1446 /* External clock source */
1447 clk_set_rate(&sh7372_dv_clki_clk, 27000000);
1449 pinctrl_register_mappings(mackerel_pinctrl_map,
1450 ARRAY_SIZE(mackerel_pinctrl_map));
1451 sh7372_pinmux_init();
1453 gpio_request_one(151, GPIOF_OUT_INIT_HIGH, NULL); /* LCDDON */
1455 /* FSI2 port A (ak4643) */
1456 gpio_request_one(161, GPIOF_OUT_INIT_LOW, NULL); /* slave */
1458 gpio_request(9, NULL);
1459 gpio_request(10, NULL);
1460 gpio_direction_none(GPIO_PORT9CR); /* FSIAOBT needs no direction */
1461 gpio_direction_none(GPIO_PORT10CR); /* FSIAOLR needs no direction */
1463 intc_set_priority(IRQ_FSI, 3); /* irq priority FSI(3) > SMSC911X(2) */
1465 /* FSI2 port B (HDMI) */
1466 __raw_writew(__raw_readw(USCCR1) & ~(1 << 6), USCCR1); /* use SPDIF */
1468 /* set SPU2 clock to 119.6 MHz */
1469 clk = clk_get(NULL, "spu_clk");
1471 clk_set_rate(clk, clk_round_rate(clk, 119600000));
1476 irq_set_irq_type(IRQ9, IRQ_TYPE_LEVEL_HIGH);
1479 irq_set_irq_type(IRQ7, IRQ_TYPE_LEVEL_LOW);
1482 irq_set_irq_type(IRQ21, IRQ_TYPE_LEVEL_HIGH);
1484 /* Reset HDMI, must be held at least one EXTALR (32768Hz) period */
1485 srcr4 = __raw_readl(SRCR4);
1486 __raw_writel(srcr4 | (1 << 13), SRCR4);
1488 __raw_writel(srcr4 & ~(1 << 13), SRCR4);
1490 i2c_register_board_info(0, i2c0_devices,
1491 ARRAY_SIZE(i2c0_devices));
1492 i2c_register_board_info(1, i2c1_devices,
1493 ARRAY_SIZE(i2c1_devices));
1495 sh7372_add_standard_devices();
1497 platform_add_devices(mackerel_devices, ARRAY_SIZE(mackerel_devices));
1499 rmobile_add_devices_to_domains(domain_devices,
1500 ARRAY_SIZE(domain_devices));
1502 hdmi_init_pm_clock();
1504 pm_clk_add(&fsi_device.dev, "spu2");
1505 pm_clk_add(&hdmi_lcdc_device.dev, "hdmi");
1508 static const char *mackerel_boards_compat_dt[] __initdata = {
1513 DT_MACHINE_START(MACKEREL_DT, "mackerel")
1514 .map_io = sh7372_map_io,
1515 .init_early = sh7372_add_early_devices,
1516 .init_irq = sh7372_init_irq,
1517 .handle_irq = shmobile_handle_irq_intc,
1518 .init_machine = mackerel_init,
1519 .init_late = sh7372_pm_init_late,
1520 .init_time = sh7372_earlytimer_init,
1521 .dt_compat = mackerel_boards_compat_dt,