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 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #include <linux/delay.h>
25 #include <linux/kernel.h>
26 #include <linux/init.h>
27 #include <linux/interrupt.h>
28 #include <linux/irq.h>
29 #include <linux/platform_device.h>
30 #include <linux/gpio.h>
31 #include <linux/input.h>
33 #include <linux/i2c.h>
34 #include <linux/leds.h>
35 #include <linux/mfd/tmio.h>
36 #include <linux/mmc/host.h>
37 #include <linux/mmc/sh_mmcif.h>
38 #include <linux/mmc/sh_mobile_sdhi.h>
39 #include <linux/mtd/mtd.h>
40 #include <linux/mtd/partitions.h>
41 #include <linux/mtd/physmap.h>
42 #include <linux/mtd/sh_flctl.h>
43 #include <linux/pinctrl/machine.h>
44 #include <linux/pinctrl/pinconf-generic.h>
45 #include <linux/platform_data/gpio_backlight.h>
46 #include <linux/pm_clock.h>
47 #include <linux/regulator/fixed.h>
48 #include <linux/regulator/machine.h>
49 #include <linux/smsc911x.h>
50 #include <linux/sh_clk.h>
51 #include <linux/tca6416_keypad.h>
52 #include <linux/usb/renesas_usbhs.h>
53 #include <linux/dma-mapping.h>
54 #include <video/sh_mobile_hdmi.h>
55 #include <video/sh_mobile_lcdc.h>
56 #include <media/sh_mobile_ceu.h>
57 #include <media/soc_camera.h>
58 #include <media/soc_camera_platform.h>
59 #include <sound/sh_fsi.h>
60 #include <sound/simple_card.h>
61 #include <mach/sh7372.h>
62 #include <asm/mach/arch.h>
63 #include <asm/mach-types.h>
66 #include "pm-rmobile.h"
70 * Address Interface BusWidth note
71 * ------------------------------------------------------------------
72 * 0x0000_0000 NOR Flash ROM (MCP) 16bit SW7 : bit1 = ON
73 * 0x0800_0000 user area -
74 * 0x1000_0000 NOR Flash ROM (MCP) 16bit SW7 : bit1 = OFF
75 * 0x1400_0000 Ether (LAN9220) 16bit
76 * 0x1600_0000 user area - cannot use with NAND
77 * 0x1800_0000 user area -
79 * 0x4000_0000 LPDDR2-SDRAM (POP) 32bit
85 * SW4 | Boot Area| Master | Remarks
86 * 1 | 2 | 3 | 4 | 5 | 6 | 8 | | Processor|
87 * ----+-----+-----+-----+-----+-----+-----+----------+----------+--------------
88 * ON | ON | OFF | ON | ON | OFF | OFF | External | System | External ROM
89 * ON | ON | ON | ON | ON | OFF | OFF | External | System | ROM Debug
90 * ON | ON | X | ON | OFF | OFF | OFF | Built-in | System | ROM Debug
91 * X | OFF | X | X | X | X | OFF | Built-in | System | MaskROM
92 * OFF | X | X | X | X | X | OFF | Built-in | System | MaskROM
93 * X | X | X | OFF | X | X | OFF | Built-in | System | MaskROM
94 * OFF | ON | OFF | X | X | OFF | ON | External | System | Standalone
95 * ON | OFF | OFF | X | X | OFF | ON | External | Realtime | Standalone
101 * SW1 | SW2 | SW7 | NOR Flash ROM
102 * bit1 | bit1 bit2 | bit1 | Memory allocation
103 * ------+------------+------+------------------
104 * OFF | ON OFF | ON | Area 0
105 * OFF | ON OFF | OFF | Area 4
112 * -----------------------
120 * SW1 | SW2 | SW7 | NAND Flash ROM
121 * bit1 | bit1 bit2 | bit2 | Memory allocation
122 * ------+------------+------+------------------
123 * OFF | ON OFF | ON | FCE 0
124 * OFF | ON OFF | OFF | FCE 1
128 * External interrupt pin settings
130 * IRQX | pin setting | device | level
131 * ------+--------------------+--------------------+-------
132 * IRQ0 | ICR1A.IRQ0SA=0010 | SDHI2 card detect | Low
133 * IRQ6 | ICR1A.IRQ6SA=0011 | Ether(LAN9220) | High
134 * IRQ7 | ICR1A.IRQ7SA=0010 | LCD Touch Panel | Low
135 * IRQ8 | ICR2A.IRQ8SA=0010 | MMC/SD card detect | Low
136 * IRQ9 | ICR2A.IRQ9SA=0010 | KEY(TCA6408) | Low
137 * IRQ21 | ICR4A.IRQ21SA=0011 | Sensor(ADXL345) | High
138 * IRQ22 | ICR4A.IRQ22SA=0011 | Sensor(AK8975) | High
144 * USB0 : CN22 : Function
145 * USB1 : CN31 : Function/Host *1
148 * ----------+---------------+-------------
149 * 1-2 short | VBUS 5V | Host
150 * open | external VBUS | Function
154 * renesas_usbhs driver can use external interrupt mode
155 * (which come from USB-PHY) or autonomy mode (it use own interrupt)
156 * for detecting connection/disconnection when Function.
157 * USB will be power OFF while it has been disconnecting
158 * if external interrupt mode, and it is always power ON if autonomy mode,
160 * mackerel can not use external interrupt (IRQ7-PORT167) mode on "USB0",
161 * because Touchscreen is using IRQ7-PORT40.
162 * It is impossible to use IRQ7 demux on this board.
176 * Power voltage : 1.8v or 3.3v
177 * J22 : select power voltage *1
182 * Please change J22 depends the card to be used.
183 * MMC's OCR field set to support either voltage for the card inserted.
186 * | bit1 | bit2 | bit3 | bit4
187 * -------------+------+------+------+-------
188 * MMC0 OFF | OFF | X | ON | X (Use MMCIF)
189 * SDHI1 OFF | ON | X | OFF | X (Use MFD_SH_MOBILE_SDHI)
203 * it needs amixer settings for playing
205 * amixer set "Headphone Enable" on
208 /* Fixed 3.3V and 1.8V regulators to be used by multiple devices */
209 static struct regulator_consumer_supply fixed1v8_power_consumers[] =
212 * J22 on mackerel switches mmcif.0 and sdhi.1 between 1.8V and 3.3V
213 * Since we cannot support both voltages, we support the default 1.8V
215 REGULATOR_SUPPLY("vmmc", "sh_mobile_sdhi.1"),
216 REGULATOR_SUPPLY("vqmmc", "sh_mobile_sdhi.1"),
217 REGULATOR_SUPPLY("vmmc", "sh_mmcif.0"),
218 REGULATOR_SUPPLY("vqmmc", "sh_mmcif.0"),
221 static struct regulator_consumer_supply fixed3v3_power_consumers[] =
223 REGULATOR_SUPPLY("vmmc", "sh_mobile_sdhi.0"),
224 REGULATOR_SUPPLY("vqmmc", "sh_mobile_sdhi.0"),
225 REGULATOR_SUPPLY("vmmc", "sh_mobile_sdhi.2"),
226 REGULATOR_SUPPLY("vqmmc", "sh_mobile_sdhi.2"),
229 /* Dummy supplies, where voltage doesn't matter */
230 static struct regulator_consumer_supply dummy_supplies[] = {
231 REGULATOR_SUPPLY("vddvario", "smsc911x"),
232 REGULATOR_SUPPLY("vdd33a", "smsc911x"),
236 static struct mtd_partition nor_flash_partitions[] = {
239 .offset = 0x00000000,
241 .mask_flags = MTD_WRITEABLE,
245 .offset = MTDPART_OFS_APPEND,
247 .mask_flags = MTD_WRITEABLE,
251 .offset = MTDPART_OFS_APPEND,
252 .size = 8 * 1024 * 1024,
253 .mask_flags = MTD_WRITEABLE,
257 .offset = MTDPART_OFS_APPEND,
258 .size = 8 * 1024 * 1024,
262 .offset = MTDPART_OFS_APPEND,
263 .size = MTDPART_SIZ_FULL,
267 static struct physmap_flash_data nor_flash_data = {
269 .parts = nor_flash_partitions,
270 .nr_parts = ARRAY_SIZE(nor_flash_partitions),
273 static struct resource nor_flash_resources[] = {
275 .start = 0x20000000, /* CS0 shadow instead of regular CS0 */
276 .end = 0x28000000 - 1, /* needed by USB MASK ROM boot */
277 .flags = IORESOURCE_MEM,
281 static struct platform_device nor_flash_device = {
282 .name = "physmap-flash",
284 .platform_data = &nor_flash_data,
286 .num_resources = ARRAY_SIZE(nor_flash_resources),
287 .resource = nor_flash_resources,
291 static struct resource smc911x_resources[] = {
294 .end = 0x16000000 - 1,
295 .flags = IORESOURCE_MEM,
297 .start = evt2irq(0x02c0) /* IRQ6A */,
298 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
302 static struct smsc911x_platform_config smsc911x_info = {
303 .flags = SMSC911X_USE_16BIT | SMSC911X_SAVE_MAC_ADDRESS,
304 .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
305 .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
308 static struct platform_device smc911x_device = {
311 .num_resources = ARRAY_SIZE(smc911x_resources),
312 .resource = smc911x_resources,
314 .platform_data = &smsc911x_info,
319 static struct sh_mobile_meram_info mackerel_meram_info = {
320 .addr_mode = SH_MOBILE_MERAM_MODE1,
323 static struct resource meram_resources[] = {
328 .flags = IORESOURCE_MEM,
334 .flags = IORESOURCE_MEM,
338 static struct platform_device meram_device = {
339 .name = "sh_mobile_meram",
341 .num_resources = ARRAY_SIZE(meram_resources),
342 .resource = meram_resources,
344 .platform_data = &mackerel_meram_info,
348 /* LCDC and backlight */
349 static struct fb_videomode mackerel_lcdc_modes[] = {
351 .name = "WVGA Panel",
364 static const struct sh_mobile_meram_cfg lcd_meram_cfg = {
373 static struct sh_mobile_lcdc_info lcdc_info = {
374 .meram_dev = &mackerel_meram_info,
375 .clock_source = LCDC_CLK_BUS,
377 .chan = LCDC_CHAN_MAINLCD,
378 .fourcc = V4L2_PIX_FMT_RGB565,
379 .lcd_modes = mackerel_lcdc_modes,
380 .num_modes = ARRAY_SIZE(mackerel_lcdc_modes),
381 .interface_type = RGB24,
388 .meram_cfg = &lcd_meram_cfg,
392 static struct resource lcdc_resources[] = {
397 .flags = IORESOURCE_MEM,
400 .start = intcs_evt2irq(0x580),
401 .flags = IORESOURCE_IRQ,
405 static struct platform_device lcdc_device = {
406 .name = "sh_mobile_lcdc_fb",
407 .num_resources = ARRAY_SIZE(lcdc_resources),
408 .resource = lcdc_resources,
410 .platform_data = &lcdc_info,
411 .coherent_dma_mask = DMA_BIT_MASK(32),
415 static struct gpio_backlight_platform_data gpio_backlight_data = {
416 .fbdev = &lcdc_device.dev,
422 static struct platform_device gpio_backlight_device = {
423 .name = "gpio-backlight",
425 .platform_data = &gpio_backlight_data,
430 static struct sh_mobile_hdmi_info hdmi_info = {
431 .flags = HDMI_SND_SRC_SPDIF,
434 static struct resource hdmi_resources[] = {
439 .flags = IORESOURCE_MEM,
442 /* There's also an HDMI interrupt on INTCS @ 0x18e0 */
443 .start = evt2irq(0x17e0),
444 .flags = IORESOURCE_IRQ,
448 static struct platform_device hdmi_device = {
449 .name = "sh-mobile-hdmi",
450 .num_resources = ARRAY_SIZE(hdmi_resources),
451 .resource = hdmi_resources,
454 .platform_data = &hdmi_info,
458 static const struct sh_mobile_meram_cfg hdmi_meram_cfg = {
467 static struct sh_mobile_lcdc_info hdmi_lcdc_info = {
468 .meram_dev = &mackerel_meram_info,
469 .clock_source = LCDC_CLK_EXTERNAL,
471 .chan = LCDC_CHAN_MAINLCD,
472 .fourcc = V4L2_PIX_FMT_RGB565,
473 .interface_type = RGB24,
475 .flags = LCDC_FLAGS_DWPOL,
476 .meram_cfg = &hdmi_meram_cfg,
477 .tx_dev = &hdmi_device,
481 static struct resource hdmi_lcdc_resources[] = {
486 .flags = IORESOURCE_MEM,
489 .start = intcs_evt2irq(0x1780),
490 .flags = IORESOURCE_IRQ,
494 static struct platform_device hdmi_lcdc_device = {
495 .name = "sh_mobile_lcdc_fb",
496 .num_resources = ARRAY_SIZE(hdmi_lcdc_resources),
497 .resource = hdmi_lcdc_resources,
500 .platform_data = &hdmi_lcdc_info,
501 .coherent_dma_mask = DMA_BIT_MASK(32),
505 static struct asoc_simple_card_info fsi2_hdmi_info = {
507 .card = "FSI2B-HDMI",
508 .codec = "sh-mobile-hdmi",
509 .platform = "sh_fsi2",
510 .daifmt = SND_SOC_DAIFMT_CBS_CFS,
515 .name = "sh_mobile_hdmi-hifi",
519 static struct platform_device fsi_hdmi_device = {
520 .name = "asoc-simple-card",
523 .platform_data = &fsi2_hdmi_info,
527 static void __init hdmi_init_pm_clock(void)
529 struct clk *hdmi_ick = clk_get(&hdmi_device.dev, "ick");
533 if (IS_ERR(hdmi_ick)) {
534 ret = PTR_ERR(hdmi_ick);
535 pr_err("Cannot get HDMI ICK: %d\n", ret);
539 ret = clk_set_parent(&sh7372_pllc2_clk, &sh7372_dv_clki_div2_clk);
541 pr_err("Cannot set PLLC2 parent: %d, %d users\n",
542 ret, sh7372_pllc2_clk.usecount);
546 pr_debug("PLLC2 initial frequency %lu\n",
547 clk_get_rate(&sh7372_pllc2_clk));
549 rate = clk_round_rate(&sh7372_pllc2_clk, 594000000);
551 pr_err("Cannot get suitable rate: %ld\n", rate);
556 ret = clk_set_rate(&sh7372_pllc2_clk, rate);
558 pr_err("Cannot set rate %ld: %d\n", rate, ret);
562 pr_debug("PLLC2 set frequency %lu\n", rate);
564 ret = clk_set_parent(hdmi_ick, &sh7372_pllc2_clk);
566 pr_err("Cannot set HDMI parent: %d\n", ret);
569 if (!IS_ERR(hdmi_ick))
573 /* USBHS0 is connected to CN22 which takes a USB Mini-B plug
575 * The sh7372 SoC has IRQ7 set aside for USBHS0 hotplug,
576 * but on this particular board IRQ7 is already used by
577 * the touch screen. This leaves us with software polling.
579 #define USBHS0_POLL_INTERVAL (HZ * 5)
581 struct usbhs_private {
582 void __iomem *usbphyaddr;
583 void __iomem *usbcrcaddr;
584 struct renesas_usbhs_platform_info info;
585 struct delayed_work work;
586 struct platform_device *pdev;
589 #define usbhs_get_priv(pdev) \
590 container_of(renesas_usbhs_get_info(pdev), \
591 struct usbhs_private, info)
593 #define usbhs_is_connected(priv) \
594 (!((1 << 7) & __raw_readw(priv->usbcrcaddr)))
596 static int usbhs_get_vbus(struct platform_device *pdev)
598 return usbhs_is_connected(usbhs_get_priv(pdev));
601 static int usbhs_phy_reset(struct platform_device *pdev)
603 struct usbhs_private *priv = usbhs_get_priv(pdev);
606 __raw_writew(0x8a0a, priv->usbcrcaddr);
611 static int usbhs0_get_id(struct platform_device *pdev)
616 static void usbhs0_work_function(struct work_struct *work)
618 struct usbhs_private *priv = container_of(work, struct usbhs_private,
621 renesas_usbhs_call_notify_hotplug(priv->pdev);
622 schedule_delayed_work(&priv->work, USBHS0_POLL_INTERVAL);
625 static int usbhs0_hardware_init(struct platform_device *pdev)
627 struct usbhs_private *priv = usbhs_get_priv(pdev);
630 INIT_DELAYED_WORK(&priv->work, usbhs0_work_function);
631 schedule_delayed_work(&priv->work, USBHS0_POLL_INTERVAL);
635 static int usbhs0_hardware_exit(struct platform_device *pdev)
637 struct usbhs_private *priv = usbhs_get_priv(pdev);
639 cancel_delayed_work_sync(&priv->work);
644 static struct usbhs_private usbhs0_private = {
645 .usbcrcaddr = IOMEM(0xe605810c), /* USBCR2 */
647 .platform_callback = {
648 .hardware_init = usbhs0_hardware_init,
649 .hardware_exit = usbhs0_hardware_exit,
650 .phy_reset = usbhs_phy_reset,
651 .get_id = usbhs0_get_id,
652 .get_vbus = usbhs_get_vbus,
656 .d0_tx_id = SHDMA_SLAVE_USB0_TX,
657 .d1_rx_id = SHDMA_SLAVE_USB0_RX,
662 static struct resource usbhs0_resources[] = {
666 .end = 0xe68900e6 - 1,
667 .flags = IORESOURCE_MEM,
670 .start = evt2irq(0x1ca0) /* USB0_USB0I0 */,
671 .flags = IORESOURCE_IRQ,
675 static struct platform_device usbhs0_device = {
676 .name = "renesas_usbhs",
679 .platform_data = &usbhs0_private.info,
681 .num_resources = ARRAY_SIZE(usbhs0_resources),
682 .resource = usbhs0_resources,
685 /* USBHS1 is connected to CN31 which takes a USB Mini-AB plug
687 * Use J30 to select between Host and Function. This setting
688 * can however not be detected by software. Hotplug of USBHS1
689 * is provided via IRQ8.
691 * Current USB1 works as "USB Host".
694 * If you want to use it as "USB gadget",
696 * - modify usbhs1_get_id() USBHS_HOST -> USBHS_GADGET
697 * - add .get_vbus = usbhs_get_vbus in usbhs1_private
698 * - check usbhs0_device(pio)/usbhs1_device(irq) order in mackerel_devices.
700 #define IRQ8 evt2irq(0x0300)
701 #define USB_PHY_MODE (1 << 4)
702 #define USB_PHY_INT_EN ((1 << 3) | (1 << 2))
703 #define USB_PHY_ON (1 << 1)
704 #define USB_PHY_OFF (1 << 0)
705 #define USB_PHY_INT_CLR (USB_PHY_ON | USB_PHY_OFF)
707 static irqreturn_t usbhs1_interrupt(int irq, void *data)
709 struct platform_device *pdev = data;
710 struct usbhs_private *priv = usbhs_get_priv(pdev);
712 dev_dbg(&pdev->dev, "%s\n", __func__);
714 renesas_usbhs_call_notify_hotplug(pdev);
717 __raw_writew(__raw_readw(priv->usbphyaddr) | USB_PHY_INT_CLR,
723 static int usbhs1_hardware_init(struct platform_device *pdev)
725 struct usbhs_private *priv = usbhs_get_priv(pdev);
728 /* clear interrupt status */
729 __raw_writew(USB_PHY_MODE | USB_PHY_INT_CLR, priv->usbphyaddr);
731 ret = request_irq(IRQ8, usbhs1_interrupt, IRQF_TRIGGER_HIGH,
732 dev_name(&pdev->dev), pdev);
734 dev_err(&pdev->dev, "request_irq err\n");
738 /* enable USB phy interrupt */
739 __raw_writew(USB_PHY_MODE | USB_PHY_INT_EN, priv->usbphyaddr);
744 static int usbhs1_hardware_exit(struct platform_device *pdev)
746 struct usbhs_private *priv = usbhs_get_priv(pdev);
748 /* clear interrupt status */
749 __raw_writew(USB_PHY_MODE | USB_PHY_INT_CLR, priv->usbphyaddr);
751 free_irq(IRQ8, pdev);
756 static int usbhs1_get_id(struct platform_device *pdev)
761 static u32 usbhs1_pipe_cfg[] = {
762 USB_ENDPOINT_XFER_CONTROL,
763 USB_ENDPOINT_XFER_ISOC,
764 USB_ENDPOINT_XFER_ISOC,
765 USB_ENDPOINT_XFER_BULK,
766 USB_ENDPOINT_XFER_BULK,
767 USB_ENDPOINT_XFER_BULK,
768 USB_ENDPOINT_XFER_INT,
769 USB_ENDPOINT_XFER_INT,
770 USB_ENDPOINT_XFER_INT,
771 USB_ENDPOINT_XFER_BULK,
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,
780 static struct usbhs_private usbhs1_private = {
781 .usbphyaddr = IOMEM(0xe60581e2), /* USBPHY1INTAP */
782 .usbcrcaddr = IOMEM(0xe6058130), /* USBCR4 */
784 .platform_callback = {
785 .hardware_init = usbhs1_hardware_init,
786 .hardware_exit = usbhs1_hardware_exit,
787 .get_id = usbhs1_get_id,
788 .phy_reset = usbhs_phy_reset,
793 .pipe_type = usbhs1_pipe_cfg,
794 .pipe_size = ARRAY_SIZE(usbhs1_pipe_cfg),
795 .d0_tx_id = SHDMA_SLAVE_USB1_TX,
796 .d1_rx_id = SHDMA_SLAVE_USB1_RX,
801 static struct resource usbhs1_resources[] = {
805 .end = 0xe68b00e6 - 1,
806 .flags = IORESOURCE_MEM,
809 .start = evt2irq(0x1ce0) /* USB1_USB1I0 */,
810 .flags = IORESOURCE_IRQ,
814 static struct platform_device usbhs1_device = {
815 .name = "renesas_usbhs",
818 .platform_data = &usbhs1_private.info,
819 .dma_mask = &usbhs1_device.dev.coherent_dma_mask,
820 .coherent_dma_mask = DMA_BIT_MASK(32),
822 .num_resources = ARRAY_SIZE(usbhs1_resources),
823 .resource = usbhs1_resources,
827 static struct gpio_led mackerel_leds[] = {
831 .default_state = LEDS_GPIO_DEFSTATE_ON,
836 .default_state = LEDS_GPIO_DEFSTATE_ON,
841 .default_state = LEDS_GPIO_DEFSTATE_ON,
846 .default_state = LEDS_GPIO_DEFSTATE_ON,
850 static struct gpio_led_platform_data mackerel_leds_pdata = {
851 .leds = mackerel_leds,
852 .num_leds = ARRAY_SIZE(mackerel_leds),
855 static struct platform_device leds_device = {
859 .platform_data = &mackerel_leds_pdata,
864 #define IRQ_FSI evt2irq(0x1840)
865 static struct sh_fsi_platform_info fsi_info = {
867 .tx_id = SHDMA_SLAVE_FSIA_TX,
868 .rx_id = SHDMA_SLAVE_FSIA_RX,
871 .flags = SH_FSI_CLK_CPG |
876 static struct resource fsi_resources[] = {
878 /* we need 0xFE1F0000 to access DMA
879 * instead of 0xFE3C0000 */
882 .end = 0xFE1F0400 - 1,
883 .flags = IORESOURCE_MEM,
887 .flags = IORESOURCE_IRQ,
891 static struct platform_device fsi_device = {
894 .num_resources = ARRAY_SIZE(fsi_resources),
895 .resource = fsi_resources,
897 .platform_data = &fsi_info,
901 static struct asoc_simple_card_info fsi2_ak4643_info = {
903 .card = "FSI2A-AK4643",
904 .codec = "ak4642-codec.0-0013",
905 .platform = "sh_fsi2",
906 .daifmt = SND_SOC_DAIFMT_LEFT_J | SND_SOC_DAIFMT_CBM_CFM,
911 .name = "ak4642-hifi",
916 static struct platform_device fsi_ak4643_device = {
917 .name = "asoc-simple-card",
919 .platform_data = &fsi2_ak4643_info,
924 static struct mtd_partition nand_partition_info[] = {
928 .size = 128 * 1024 * 1024,
932 .offset = MTDPART_OFS_APPEND,
933 .size = 256 * 1024 * 1024,
937 .offset = MTDPART_OFS_APPEND,
938 .size = 128 * 1024 * 1024,
942 static struct resource nand_flash_resources[] = {
946 .flags = IORESOURCE_MEM,
949 .start = evt2irq(0x0d80), /* flstei: status error irq */
950 .flags = IORESOURCE_IRQ,
954 static struct sh_flctl_platform_data nand_flash_data = {
955 .parts = nand_partition_info,
956 .nr_parts = ARRAY_SIZE(nand_partition_info),
957 .flcmncr_val = CLK_16B_12L_4H | TYPESEL_SET
958 | SHBUSSEL | SEL_16BIT | SNAND_E,
962 static struct platform_device nand_flash_device = {
964 .resource = nand_flash_resources,
965 .num_resources = ARRAY_SIZE(nand_flash_resources),
967 .platform_data = &nand_flash_data,
972 static struct sh_mobile_sdhi_info sdhi0_info = {
973 .dma_slave_tx = SHDMA_SLAVE_SDHI0_TX,
974 .dma_slave_rx = SHDMA_SLAVE_SDHI0_RX,
975 .tmio_flags = TMIO_MMC_USE_GPIO_CD,
976 .tmio_caps = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ,
980 static struct resource sdhi0_resources[] = {
985 .flags = IORESOURCE_MEM,
987 .name = SH_MOBILE_SDHI_IRQ_SDCARD,
988 .start = evt2irq(0x0e20) /* SDHI0_SDHI0I1 */,
989 .flags = IORESOURCE_IRQ,
991 .name = SH_MOBILE_SDHI_IRQ_SDIO,
992 .start = evt2irq(0x0e40) /* SDHI0_SDHI0I2 */,
993 .flags = IORESOURCE_IRQ,
997 static struct platform_device sdhi0_device = {
998 .name = "sh_mobile_sdhi",
999 .num_resources = ARRAY_SIZE(sdhi0_resources),
1000 .resource = sdhi0_resources,
1003 .platform_data = &sdhi0_info,
1007 #if !IS_ENABLED(CONFIG_MMC_SH_MMCIF)
1010 /* GPIO 41 can trigger IRQ8, but it is used by USBHS1, we have to poll */
1011 static struct sh_mobile_sdhi_info sdhi1_info = {
1012 .dma_slave_tx = SHDMA_SLAVE_SDHI1_TX,
1013 .dma_slave_rx = SHDMA_SLAVE_SDHI1_RX,
1014 .tmio_flags = TMIO_MMC_WRPROTECT_DISABLE | TMIO_MMC_USE_GPIO_CD,
1015 .tmio_caps = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ |
1020 static struct resource sdhi1_resources[] = {
1023 .start = 0xe6860000,
1025 .flags = IORESOURCE_MEM,
1027 .name = SH_MOBILE_SDHI_IRQ_SDCARD,
1028 .start = evt2irq(0x0ea0), /* SDHI1_SDHI1I1 */
1029 .flags = IORESOURCE_IRQ,
1031 .name = SH_MOBILE_SDHI_IRQ_SDIO,
1032 .start = evt2irq(0x0ec0), /* SDHI1_SDHI1I2 */
1033 .flags = IORESOURCE_IRQ,
1037 static struct platform_device sdhi1_device = {
1038 .name = "sh_mobile_sdhi",
1039 .num_resources = ARRAY_SIZE(sdhi1_resources),
1040 .resource = sdhi1_resources,
1043 .platform_data = &sdhi1_info,
1051 * The card detect pin of the top SD/MMC slot (CN23) is active low and is
1052 * connected to GPIO SCIFB_SCK of SH7372 (GPIO 162).
1054 static struct sh_mobile_sdhi_info sdhi2_info = {
1055 .dma_slave_tx = SHDMA_SLAVE_SDHI2_TX,
1056 .dma_slave_rx = SHDMA_SLAVE_SDHI2_RX,
1057 .tmio_flags = TMIO_MMC_WRPROTECT_DISABLE | TMIO_MMC_USE_GPIO_CD,
1058 .tmio_caps = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ |
1063 static struct resource sdhi2_resources[] = {
1066 .start = 0xe6870000,
1068 .flags = IORESOURCE_MEM,
1070 .name = SH_MOBILE_SDHI_IRQ_SDCARD,
1071 .start = evt2irq(0x1220), /* SDHI2_SDHI2I1 */
1072 .flags = IORESOURCE_IRQ,
1074 .name = SH_MOBILE_SDHI_IRQ_SDIO,
1075 .start = evt2irq(0x1240), /* SDHI2_SDHI2I2 */
1076 .flags = IORESOURCE_IRQ,
1080 static struct platform_device sdhi2_device = {
1081 .name = "sh_mobile_sdhi",
1082 .num_resources = ARRAY_SIZE(sdhi2_resources),
1083 .resource = sdhi2_resources,
1086 .platform_data = &sdhi2_info,
1091 #if IS_ENABLED(CONFIG_MMC_SH_MMCIF)
1092 static struct resource sh_mmcif_resources[] = {
1095 .start = 0xE6BD0000,
1097 .flags = IORESOURCE_MEM,
1101 .start = evt2irq(0x1ac0),
1102 .flags = IORESOURCE_IRQ,
1106 .start = evt2irq(0x1ae0),
1107 .flags = IORESOURCE_IRQ,
1111 static struct sh_mmcif_plat_data sh_mmcif_plat = {
1113 .caps = MMC_CAP_4_BIT_DATA |
1114 MMC_CAP_8_BIT_DATA |
1116 .use_cd_gpio = true,
1117 /* card detect pin for SD/MMC slot (CN7) */
1119 .slave_id_tx = SHDMA_SLAVE_MMCIF_TX,
1120 .slave_id_rx = SHDMA_SLAVE_MMCIF_RX,
1123 static struct platform_device sh_mmcif_device = {
1128 .coherent_dma_mask = 0xffffffff,
1129 .platform_data = &sh_mmcif_plat,
1131 .num_resources = ARRAY_SIZE(sh_mmcif_resources),
1132 .resource = sh_mmcif_resources,
1136 static int mackerel_camera_add(struct soc_camera_device *icd);
1137 static void mackerel_camera_del(struct soc_camera_device *icd);
1139 static int camera_set_capture(struct soc_camera_platform_info *info,
1142 return 0; /* camera sensor always enabled */
1145 static struct soc_camera_platform_info camera_info = {
1146 .format_name = "UYVY",
1149 .code = V4L2_MBUS_FMT_UYVY8_2X8,
1150 .colorspace = V4L2_COLORSPACE_SMPTE170M,
1151 .field = V4L2_FIELD_NONE,
1155 .mbus_param = V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_MASTER |
1156 V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_HIGH |
1157 V4L2_MBUS_DATA_ACTIVE_HIGH,
1158 .mbus_type = V4L2_MBUS_PARALLEL,
1159 .set_capture = camera_set_capture,
1162 static struct soc_camera_link camera_link = {
1164 .add_device = mackerel_camera_add,
1165 .del_device = mackerel_camera_del,
1166 .module_name = "soc_camera_platform",
1167 .priv = &camera_info,
1170 static struct platform_device *camera_device;
1172 static void mackerel_camera_release(struct device *dev)
1174 soc_camera_platform_release(&camera_device);
1177 static int mackerel_camera_add(struct soc_camera_device *icd)
1179 return soc_camera_platform_add(icd, &camera_device, &camera_link,
1180 mackerel_camera_release, 0);
1183 static void mackerel_camera_del(struct soc_camera_device *icd)
1185 soc_camera_platform_del(icd, camera_device, &camera_link);
1188 static struct sh_mobile_ceu_info sh_mobile_ceu_info = {
1189 .flags = SH_CEU_FLAG_USE_8BIT_BUS,
1194 static struct resource ceu_resources[] = {
1197 .start = 0xfe910000,
1199 .flags = IORESOURCE_MEM,
1202 .start = intcs_evt2irq(0x880),
1203 .flags = IORESOURCE_IRQ,
1206 /* place holder for contiguous memory */
1210 static struct platform_device ceu_device = {
1211 .name = "sh_mobile_ceu",
1212 .id = 0, /* "ceu0" clock */
1213 .num_resources = ARRAY_SIZE(ceu_resources),
1214 .resource = ceu_resources,
1216 .platform_data = &sh_mobile_ceu_info,
1217 .coherent_dma_mask = 0xffffffff,
1221 static struct platform_device mackerel_camera = {
1222 .name = "soc-camera-pdrv",
1225 .platform_data = &camera_link,
1229 static struct platform_device *mackerel_devices[] __initdata = {
1233 &gpio_backlight_device,
1242 #if !IS_ENABLED(CONFIG_MMC_SH_MMCIF)
1255 /* Keypad Initialization */
1256 #define KEYPAD_BUTTON(ev_type, ev_code, act_low) \
1260 .active_low = act_low, \
1263 #define KEYPAD_BUTTON_LOW(event_code) KEYPAD_BUTTON(EV_KEY, event_code, 1)
1265 static struct tca6416_button mackerel_gpio_keys[] = {
1266 KEYPAD_BUTTON_LOW(KEY_HOME),
1267 KEYPAD_BUTTON_LOW(KEY_MENU),
1268 KEYPAD_BUTTON_LOW(KEY_BACK),
1269 KEYPAD_BUTTON_LOW(KEY_POWER),
1272 static struct tca6416_keys_platform_data mackerel_tca6416_keys_info = {
1273 .buttons = mackerel_gpio_keys,
1274 .nbuttons = ARRAY_SIZE(mackerel_gpio_keys),
1281 #define IRQ7 evt2irq(0x02e0)
1282 #define IRQ9 evt2irq(0x0320)
1284 static struct i2c_board_info i2c0_devices[] = {
1286 I2C_BOARD_INFO("ak4643", 0x13),
1290 I2C_BOARD_INFO("tca6408-keys", 0x20),
1291 .platform_data = &mackerel_tca6416_keys_info,
1296 I2C_BOARD_INFO("st1232-ts", 0x55),
1301 #define IRQ21 evt2irq(0x32a0)
1303 static struct i2c_board_info i2c1_devices[] = {
1306 I2C_BOARD_INFO("adxl34x", 0x53),
1311 static unsigned long pin_pulldown_conf[] = {
1312 PIN_CONF_PACKED(PIN_CONFIG_BIAS_PULL_DOWN, 0),
1315 static const struct pinctrl_map mackerel_pinctrl_map[] = {
1317 PIN_MAP_MUX_GROUP_DEFAULT("1-0053", "pfc-sh7372",
1318 "intc_irq21", "intc"),
1320 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_ceu.0", "pfc-sh7372",
1321 "ceu_data_0_7", "ceu"),
1322 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_ceu.0", "pfc-sh7372",
1323 "ceu_clk_0", "ceu"),
1324 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_ceu.0", "pfc-sh7372",
1326 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_ceu.0", "pfc-sh7372",
1327 "ceu_field", "ceu"),
1329 PIN_MAP_MUX_GROUP_DEFAULT("sh_flctl.0", "pfc-sh7372",
1330 "flctl_data", "flctl"),
1331 PIN_MAP_MUX_GROUP_DEFAULT("sh_flctl.0", "pfc-sh7372",
1332 "flctl_ce0", "flctl"),
1333 PIN_MAP_MUX_GROUP_DEFAULT("sh_flctl.0", "pfc-sh7372",
1334 "flctl_ctrl", "flctl"),
1336 PIN_MAP_MUX_GROUP_DEFAULT("asoc-simple-card.0", "pfc-sh7372",
1337 "fsia_sclk_in", "fsia"),
1338 PIN_MAP_MUX_GROUP_DEFAULT("asoc-simple-card.0", "pfc-sh7372",
1339 "fsia_data_in", "fsia"),
1340 PIN_MAP_MUX_GROUP_DEFAULT("asoc-simple-card.0", "pfc-sh7372",
1341 "fsia_data_out", "fsia"),
1343 PIN_MAP_MUX_GROUP_DEFAULT("asoc-simple-card.1", "pfc-sh7372",
1344 "fsib_mclk_in", "fsib"),
1346 PIN_MAP_MUX_GROUP_DEFAULT("sh-mobile-hdmi", "pfc-sh7372",
1349 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_lcdc_fb.0", "pfc-sh7372",
1350 "lcd_data24", "lcd"),
1351 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_lcdc_fb.0", "pfc-sh7372",
1354 PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.0", "pfc-sh7372",
1355 "scifa0_data", "scifa0"),
1356 /* SCIFA2 (GT-720F GPS module) */
1357 PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.2", "pfc-sh7372",
1358 "scifa2_data", "scifa2"),
1360 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-sh7372",
1361 "sdhi0_data4", "sdhi0"),
1362 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-sh7372",
1363 "sdhi0_ctrl", "sdhi0"),
1364 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-sh7372",
1365 "sdhi0_wp", "sdhi0"),
1366 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-sh7372",
1367 "intc_irq26_1", "intc"),
1369 #if !IS_ENABLED(CONFIG_MMC_SH_MMCIF)
1370 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.1", "pfc-sh7372",
1371 "sdhi1_data4", "sdhi1"),
1372 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.1", "pfc-sh7372",
1373 "sdhi1_ctrl", "sdhi1"),
1376 PIN_MAP_MUX_GROUP_DEFAULT("sh_mmcif.0", "pfc-sh7372",
1377 "mmc0_data8_0", "mmc0"),
1378 PIN_MAP_MUX_GROUP_DEFAULT("sh_mmcif.0", "pfc-sh7372",
1379 "mmc0_ctrl_0", "mmc0"),
1382 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.2", "pfc-sh7372",
1383 "sdhi2_data4", "sdhi2"),
1384 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.2", "pfc-sh7372",
1385 "sdhi2_ctrl", "sdhi2"),
1387 PIN_MAP_MUX_GROUP_DEFAULT("smsc911x", "pfc-sh7372",
1389 PIN_MAP_MUX_GROUP_DEFAULT("smsc911x", "pfc-sh7372",
1390 "intc_irq6_0", "intc"),
1392 PIN_MAP_MUX_GROUP_DEFAULT("0-0055", "pfc-sh7372",
1393 "intc_irq7_0", "intc"),
1395 PIN_MAP_MUX_GROUP_DEFAULT("0-0020", "pfc-sh7372",
1396 "intc_irq9_0", "intc"),
1398 PIN_MAP_MUX_GROUP_DEFAULT("renesas_usbhs.0", "pfc-sh7372",
1399 "usb0_vbus", "usb0"),
1400 PIN_MAP_CONFIGS_GROUP_DEFAULT("renesas_usbhs.0", "pfc-sh7372",
1401 "usb0_vbus", pin_pulldown_conf),
1403 PIN_MAP_MUX_GROUP_DEFAULT("renesas_usbhs.1", "pfc-sh7372",
1404 "usb1_vbus", "usb1"),
1405 PIN_MAP_CONFIGS_GROUP_DEFAULT("renesas_usbhs.1", "pfc-sh7372",
1406 "usb1_vbus", pin_pulldown_conf),
1407 PIN_MAP_MUX_GROUP_DEFAULT("renesas_usbhs.1", "pfc-sh7372",
1408 "usb1_otg_id_0", "usb1"),
1411 #define GPIO_PORT9CR IOMEM(0xE6051009)
1412 #define GPIO_PORT10CR IOMEM(0xE605100A)
1413 #define SRCR4 IOMEM(0xe61580bc)
1414 #define USCCR1 IOMEM(0xE6058144)
1415 static void __init mackerel_init(void)
1417 struct pm_domain_device domain_devices[] = {
1418 { "A4LC", &lcdc_device, },
1419 { "A4LC", &hdmi_lcdc_device, },
1420 { "A4LC", &meram_device, },
1421 { "A4MP", &fsi_device, },
1422 { "A3SP", &usbhs0_device, },
1423 { "A3SP", &usbhs1_device, },
1424 { "A3SP", &nand_flash_device, },
1425 { "A3SP", &sdhi0_device, },
1426 #if !IS_ENABLED(CONFIG_MMC_SH_MMCIF)
1427 { "A3SP", &sdhi1_device, },
1429 { "A3SP", &sh_mmcif_device, },
1431 { "A3SP", &sdhi2_device, },
1432 { "A4R", &ceu_device, },
1437 regulator_register_always_on(0, "fixed-1.8V", fixed1v8_power_consumers,
1438 ARRAY_SIZE(fixed1v8_power_consumers), 1800000);
1439 regulator_register_always_on(1, "fixed-3.3V", fixed3v3_power_consumers,
1440 ARRAY_SIZE(fixed3v3_power_consumers), 3300000);
1441 regulator_register_fixed(2, dummy_supplies, ARRAY_SIZE(dummy_supplies));
1443 /* External clock source */
1444 clk_set_rate(&sh7372_dv_clki_clk, 27000000);
1446 pinctrl_register_mappings(mackerel_pinctrl_map,
1447 ARRAY_SIZE(mackerel_pinctrl_map));
1448 sh7372_pinmux_init();
1450 gpio_request_one(151, GPIOF_OUT_INIT_HIGH, NULL); /* LCDDON */
1452 /* FSI2 port A (ak4643) */
1453 gpio_request_one(161, GPIOF_OUT_INIT_LOW, NULL); /* slave */
1455 gpio_request(9, NULL);
1456 gpio_request(10, NULL);
1457 gpio_direction_none(GPIO_PORT9CR); /* FSIAOBT needs no direction */
1458 gpio_direction_none(GPIO_PORT10CR); /* FSIAOLR needs no direction */
1460 intc_set_priority(IRQ_FSI, 3); /* irq priority FSI(3) > SMSC911X(2) */
1462 /* FSI2 port B (HDMI) */
1463 __raw_writew(__raw_readw(USCCR1) & ~(1 << 6), USCCR1); /* use SPDIF */
1465 /* set SPU2 clock to 119.6 MHz */
1466 clk = clk_get(NULL, "spu_clk");
1468 clk_set_rate(clk, clk_round_rate(clk, 119600000));
1473 irq_set_irq_type(IRQ9, IRQ_TYPE_LEVEL_HIGH);
1476 irq_set_irq_type(IRQ7, IRQ_TYPE_LEVEL_LOW);
1479 irq_set_irq_type(IRQ21, IRQ_TYPE_LEVEL_HIGH);
1481 /* Reset HDMI, must be held at least one EXTALR (32768Hz) period */
1482 srcr4 = __raw_readl(SRCR4);
1483 __raw_writel(srcr4 | (1 << 13), SRCR4);
1485 __raw_writel(srcr4 & ~(1 << 13), SRCR4);
1487 i2c_register_board_info(0, i2c0_devices,
1488 ARRAY_SIZE(i2c0_devices));
1489 i2c_register_board_info(1, i2c1_devices,
1490 ARRAY_SIZE(i2c1_devices));
1492 sh7372_add_standard_devices();
1494 platform_add_devices(mackerel_devices, ARRAY_SIZE(mackerel_devices));
1496 rmobile_add_devices_to_domains(domain_devices,
1497 ARRAY_SIZE(domain_devices));
1499 hdmi_init_pm_clock();
1501 pm_clk_add(&fsi_device.dev, "spu2");
1502 pm_clk_add(&hdmi_lcdc_device.dev, "hdmi");
1505 static const char *mackerel_boards_compat_dt[] __initdata = {
1510 DT_MACHINE_START(MACKEREL_DT, "mackerel")
1511 .map_io = sh7372_map_io,
1512 .init_early = sh7372_add_early_devices,
1513 .init_irq = sh7372_init_irq,
1514 .handle_irq = shmobile_handle_irq_intc,
1515 .init_machine = mackerel_init,
1516 .init_late = sh7372_pm_init_late,
1517 .init_time = sh7372_earlytimer_init,
1518 .dt_compat = mackerel_boards_compat_dt,