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>
55 #include <video/sh_mobile_hdmi.h>
56 #include <video/sh_mobile_lcdc.h>
57 #include <media/sh_mobile_ceu.h>
58 #include <media/soc_camera.h>
59 #include <media/soc_camera_platform.h>
60 #include <sound/sh_fsi.h>
61 #include <sound/simple_card.h>
62 #include <asm/mach/arch.h>
63 #include <asm/mach-types.h>
67 #include "pm-rmobile.h"
72 * Address Interface BusWidth note
73 * ------------------------------------------------------------------
74 * 0x0000_0000 NOR Flash ROM (MCP) 16bit SW7 : bit1 = ON
75 * 0x0800_0000 user area -
76 * 0x1000_0000 NOR Flash ROM (MCP) 16bit SW7 : bit1 = OFF
77 * 0x1400_0000 Ether (LAN9220) 16bit
78 * 0x1600_0000 user area - cannot use with NAND
79 * 0x1800_0000 user area -
81 * 0x4000_0000 LPDDR2-SDRAM (POP) 32bit
87 * SW4 | Boot Area| Master | Remarks
88 * 1 | 2 | 3 | 4 | 5 | 6 | 8 | | Processor|
89 * ----+-----+-----+-----+-----+-----+-----+----------+----------+--------------
90 * ON | ON | OFF | ON | ON | OFF | OFF | External | System | External ROM
91 * ON | ON | ON | ON | ON | OFF | OFF | External | System | ROM Debug
92 * ON | ON | X | ON | OFF | OFF | OFF | Built-in | System | ROM Debug
93 * X | OFF | X | X | X | X | OFF | Built-in | System | MaskROM
94 * OFF | X | X | X | X | X | OFF | Built-in | System | MaskROM
95 * X | X | X | OFF | X | X | OFF | Built-in | System | MaskROM
96 * OFF | ON | OFF | X | X | OFF | ON | External | System | Standalone
97 * ON | OFF | OFF | X | X | OFF | ON | External | Realtime | Standalone
103 * SW1 | SW2 | SW7 | NOR Flash ROM
104 * bit1 | bit1 bit2 | bit1 | Memory allocation
105 * ------+------------+------+------------------
106 * OFF | ON OFF | ON | Area 0
107 * OFF | ON OFF | OFF | Area 4
114 * -----------------------
122 * SW1 | SW2 | SW7 | NAND Flash ROM
123 * bit1 | bit1 bit2 | bit2 | Memory allocation
124 * ------+------------+------+------------------
125 * OFF | ON OFF | ON | FCE 0
126 * OFF | ON OFF | OFF | FCE 1
130 * External interrupt pin settings
132 * IRQX | pin setting | device | level
133 * ------+--------------------+--------------------+-------
134 * IRQ0 | ICR1A.IRQ0SA=0010 | SDHI2 card detect | Low
135 * IRQ6 | ICR1A.IRQ6SA=0011 | Ether(LAN9220) | High
136 * IRQ7 | ICR1A.IRQ7SA=0010 | LCD Touch Panel | Low
137 * IRQ8 | ICR2A.IRQ8SA=0010 | MMC/SD card detect | Low
138 * IRQ9 | ICR2A.IRQ9SA=0010 | KEY(TCA6408) | Low
139 * IRQ21 | ICR4A.IRQ21SA=0011 | Sensor(ADXL345) | High
140 * IRQ22 | ICR4A.IRQ22SA=0011 | Sensor(AK8975) | High
146 * USB0 : CN22 : Function
147 * USB1 : CN31 : Function/Host *1
150 * ----------+---------------+-------------
151 * 1-2 short | VBUS 5V | Host
152 * open | external VBUS | Function
156 * renesas_usbhs driver can use external interrupt mode
157 * (which come from USB-PHY) or autonomy mode (it use own interrupt)
158 * for detecting connection/disconnection when Function.
159 * USB will be power OFF while it has been disconnecting
160 * if external interrupt mode, and it is always power ON if autonomy mode,
162 * mackerel can not use external interrupt (IRQ7-PORT167) mode on "USB0",
163 * because Touchscreen is using IRQ7-PORT40.
164 * It is impossible to use IRQ7 demux on this board.
178 * Power voltage : 1.8v or 3.3v
179 * J22 : select power voltage *1
184 * Please change J22 depends the card to be used.
185 * MMC's OCR field set to support either voltage for the card inserted.
188 * | bit1 | bit2 | bit3 | bit4
189 * -------------+------+------+------+-------
190 * MMC0 OFF | OFF | X | ON | X (Use MMCIF)
191 * SDHI1 OFF | ON | X | OFF | X (Use MFD_SH_MOBILE_SDHI)
205 * it needs amixer settings for playing
207 * amixer set "Headphone Enable" on
210 /* Fixed 3.3V and 1.8V regulators to be used by multiple devices */
211 static struct regulator_consumer_supply fixed1v8_power_consumers[] =
214 * J22 on mackerel switches mmcif.0 and sdhi.1 between 1.8V and 3.3V
215 * Since we cannot support both voltages, we support the default 1.8V
217 REGULATOR_SUPPLY("vmmc", "sh_mobile_sdhi.1"),
218 REGULATOR_SUPPLY("vqmmc", "sh_mobile_sdhi.1"),
219 REGULATOR_SUPPLY("vmmc", "sh_mmcif.0"),
220 REGULATOR_SUPPLY("vqmmc", "sh_mmcif.0"),
223 static struct regulator_consumer_supply fixed3v3_power_consumers[] =
225 REGULATOR_SUPPLY("vmmc", "sh_mobile_sdhi.0"),
226 REGULATOR_SUPPLY("vqmmc", "sh_mobile_sdhi.0"),
227 REGULATOR_SUPPLY("vmmc", "sh_mobile_sdhi.2"),
228 REGULATOR_SUPPLY("vqmmc", "sh_mobile_sdhi.2"),
231 /* Dummy supplies, where voltage doesn't matter */
232 static struct regulator_consumer_supply dummy_supplies[] = {
233 REGULATOR_SUPPLY("vddvario", "smsc911x"),
234 REGULATOR_SUPPLY("vdd33a", "smsc911x"),
238 static struct mtd_partition nor_flash_partitions[] = {
241 .offset = 0x00000000,
243 .mask_flags = MTD_WRITEABLE,
247 .offset = MTDPART_OFS_APPEND,
249 .mask_flags = MTD_WRITEABLE,
253 .offset = MTDPART_OFS_APPEND,
254 .size = 8 * 1024 * 1024,
255 .mask_flags = MTD_WRITEABLE,
259 .offset = MTDPART_OFS_APPEND,
260 .size = 8 * 1024 * 1024,
264 .offset = MTDPART_OFS_APPEND,
265 .size = MTDPART_SIZ_FULL,
269 static struct physmap_flash_data nor_flash_data = {
271 .parts = nor_flash_partitions,
272 .nr_parts = ARRAY_SIZE(nor_flash_partitions),
275 static struct resource nor_flash_resources[] = {
277 .start = 0x20000000, /* CS0 shadow instead of regular CS0 */
278 .end = 0x28000000 - 1, /* needed by USB MASK ROM boot */
279 .flags = IORESOURCE_MEM,
283 static struct platform_device nor_flash_device = {
284 .name = "physmap-flash",
286 .platform_data = &nor_flash_data,
288 .num_resources = ARRAY_SIZE(nor_flash_resources),
289 .resource = nor_flash_resources,
293 static struct resource smc911x_resources[] = {
296 .end = 0x16000000 - 1,
297 .flags = IORESOURCE_MEM,
299 .start = evt2irq(0x02c0) /* IRQ6A */,
300 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
304 static struct smsc911x_platform_config smsc911x_info = {
305 .flags = SMSC911X_USE_16BIT | SMSC911X_SAVE_MAC_ADDRESS,
306 .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
307 .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
310 static struct platform_device smc911x_device = {
313 .num_resources = ARRAY_SIZE(smc911x_resources),
314 .resource = smc911x_resources,
316 .platform_data = &smsc911x_info,
321 static struct sh_mobile_meram_info mackerel_meram_info = {
322 .addr_mode = SH_MOBILE_MERAM_MODE1,
325 static struct resource meram_resources[] = {
330 .flags = IORESOURCE_MEM,
336 .flags = IORESOURCE_MEM,
340 static struct platform_device meram_device = {
341 .name = "sh_mobile_meram",
343 .num_resources = ARRAY_SIZE(meram_resources),
344 .resource = meram_resources,
346 .platform_data = &mackerel_meram_info,
350 /* LCDC and backlight */
351 static struct fb_videomode mackerel_lcdc_modes[] = {
353 .name = "WVGA Panel",
366 static const struct sh_mobile_meram_cfg lcd_meram_cfg = {
375 static struct sh_mobile_lcdc_info lcdc_info = {
376 .meram_dev = &mackerel_meram_info,
377 .clock_source = LCDC_CLK_BUS,
379 .chan = LCDC_CHAN_MAINLCD,
380 .fourcc = V4L2_PIX_FMT_RGB565,
381 .lcd_modes = mackerel_lcdc_modes,
382 .num_modes = ARRAY_SIZE(mackerel_lcdc_modes),
383 .interface_type = RGB24,
390 .meram_cfg = &lcd_meram_cfg,
394 static struct resource lcdc_resources[] = {
399 .flags = IORESOURCE_MEM,
402 .start = intcs_evt2irq(0x580),
403 .flags = IORESOURCE_IRQ,
407 static struct platform_device lcdc_device = {
408 .name = "sh_mobile_lcdc_fb",
409 .num_resources = ARRAY_SIZE(lcdc_resources),
410 .resource = lcdc_resources,
412 .platform_data = &lcdc_info,
413 .coherent_dma_mask = DMA_BIT_MASK(32),
417 static struct gpio_backlight_platform_data gpio_backlight_data = {
418 .fbdev = &lcdc_device.dev,
424 static struct platform_device gpio_backlight_device = {
425 .name = "gpio-backlight",
427 .platform_data = &gpio_backlight_data,
432 static struct sh_mobile_hdmi_info hdmi_info = {
433 .flags = HDMI_SND_SRC_SPDIF,
436 static struct resource hdmi_resources[] = {
441 .flags = IORESOURCE_MEM,
444 /* There's also an HDMI interrupt on INTCS @ 0x18e0 */
445 .start = evt2irq(0x17e0),
446 .flags = IORESOURCE_IRQ,
450 static struct platform_device hdmi_device = {
451 .name = "sh-mobile-hdmi",
452 .num_resources = ARRAY_SIZE(hdmi_resources),
453 .resource = hdmi_resources,
456 .platform_data = &hdmi_info,
460 static const struct sh_mobile_meram_cfg hdmi_meram_cfg = {
469 static struct sh_mobile_lcdc_info hdmi_lcdc_info = {
470 .meram_dev = &mackerel_meram_info,
471 .clock_source = LCDC_CLK_EXTERNAL,
473 .chan = LCDC_CHAN_MAINLCD,
474 .fourcc = V4L2_PIX_FMT_RGB565,
475 .interface_type = RGB24,
477 .flags = LCDC_FLAGS_DWPOL,
478 .meram_cfg = &hdmi_meram_cfg,
479 .tx_dev = &hdmi_device,
483 static struct resource hdmi_lcdc_resources[] = {
488 .flags = IORESOURCE_MEM,
491 .start = intcs_evt2irq(0x1780),
492 .flags = IORESOURCE_IRQ,
496 static struct platform_device hdmi_lcdc_device = {
497 .name = "sh_mobile_lcdc_fb",
498 .num_resources = ARRAY_SIZE(hdmi_lcdc_resources),
499 .resource = hdmi_lcdc_resources,
502 .platform_data = &hdmi_lcdc_info,
503 .coherent_dma_mask = DMA_BIT_MASK(32),
507 static struct asoc_simple_card_info fsi2_hdmi_info = {
509 .card = "FSI2B-HDMI",
510 .codec = "sh-mobile-hdmi",
511 .platform = "sh_fsi2",
512 .daifmt = SND_SOC_DAIFMT_CBS_CFS,
517 .name = "sh_mobile_hdmi-hifi",
521 static struct platform_device fsi_hdmi_device = {
522 .name = "asoc-simple-card",
525 .platform_data = &fsi2_hdmi_info,
526 .coherent_dma_mask = DMA_BIT_MASK(32),
527 .dma_mask = &fsi_hdmi_device.dev.coherent_dma_mask,
531 static void __init hdmi_init_pm_clock(void)
533 struct clk *hdmi_ick = clk_get(&hdmi_device.dev, "ick");
537 if (IS_ERR(hdmi_ick)) {
538 ret = PTR_ERR(hdmi_ick);
539 pr_err("Cannot get HDMI ICK: %d\n", ret);
543 ret = clk_set_parent(&sh7372_pllc2_clk, &sh7372_dv_clki_div2_clk);
545 pr_err("Cannot set PLLC2 parent: %d, %d users\n",
546 ret, sh7372_pllc2_clk.usecount);
550 pr_debug("PLLC2 initial frequency %lu\n",
551 clk_get_rate(&sh7372_pllc2_clk));
553 rate = clk_round_rate(&sh7372_pllc2_clk, 594000000);
555 pr_err("Cannot get suitable rate: %ld\n", rate);
560 ret = clk_set_rate(&sh7372_pllc2_clk, rate);
562 pr_err("Cannot set rate %ld: %d\n", rate, ret);
566 pr_debug("PLLC2 set frequency %lu\n", rate);
568 ret = clk_set_parent(hdmi_ick, &sh7372_pllc2_clk);
570 pr_err("Cannot set HDMI parent: %d\n", ret);
573 if (!IS_ERR(hdmi_ick))
577 /* USBHS0 is connected to CN22 which takes a USB Mini-B plug
579 * The sh7372 SoC has IRQ7 set aside for USBHS0 hotplug,
580 * but on this particular board IRQ7 is already used by
581 * the touch screen. This leaves us with software polling.
583 #define USBHS0_POLL_INTERVAL (HZ * 5)
585 struct usbhs_private {
586 void __iomem *usbphyaddr;
587 void __iomem *usbcrcaddr;
588 struct renesas_usbhs_platform_info info;
589 struct delayed_work work;
590 struct platform_device *pdev;
593 #define usbhs_get_priv(pdev) \
594 container_of(renesas_usbhs_get_info(pdev), \
595 struct usbhs_private, info)
597 #define usbhs_is_connected(priv) \
598 (!((1 << 7) & __raw_readw(priv->usbcrcaddr)))
600 static int usbhs_get_vbus(struct platform_device *pdev)
602 return usbhs_is_connected(usbhs_get_priv(pdev));
605 static int usbhs_phy_reset(struct platform_device *pdev)
607 struct usbhs_private *priv = usbhs_get_priv(pdev);
610 __raw_writew(0x8a0a, priv->usbcrcaddr);
615 static int usbhs0_get_id(struct platform_device *pdev)
620 static void usbhs0_work_function(struct work_struct *work)
622 struct usbhs_private *priv = container_of(work, struct usbhs_private,
625 renesas_usbhs_call_notify_hotplug(priv->pdev);
626 schedule_delayed_work(&priv->work, USBHS0_POLL_INTERVAL);
629 static int usbhs0_hardware_init(struct platform_device *pdev)
631 struct usbhs_private *priv = usbhs_get_priv(pdev);
634 INIT_DELAYED_WORK(&priv->work, usbhs0_work_function);
635 schedule_delayed_work(&priv->work, USBHS0_POLL_INTERVAL);
639 static int usbhs0_hardware_exit(struct platform_device *pdev)
641 struct usbhs_private *priv = usbhs_get_priv(pdev);
643 cancel_delayed_work_sync(&priv->work);
648 static struct usbhs_private usbhs0_private = {
649 .usbcrcaddr = IOMEM(0xe605810c), /* USBCR2 */
651 .platform_callback = {
652 .hardware_init = usbhs0_hardware_init,
653 .hardware_exit = usbhs0_hardware_exit,
654 .phy_reset = usbhs_phy_reset,
655 .get_id = usbhs0_get_id,
656 .get_vbus = usbhs_get_vbus,
660 .d0_tx_id = SHDMA_SLAVE_USB0_TX,
661 .d1_rx_id = SHDMA_SLAVE_USB0_RX,
666 static struct resource usbhs0_resources[] = {
670 .end = 0xe68900e6 - 1,
671 .flags = IORESOURCE_MEM,
674 .start = evt2irq(0x1ca0) /* USB0_USB0I0 */,
675 .flags = IORESOURCE_IRQ,
679 static struct platform_device usbhs0_device = {
680 .name = "renesas_usbhs",
683 .platform_data = &usbhs0_private.info,
685 .num_resources = ARRAY_SIZE(usbhs0_resources),
686 .resource = usbhs0_resources,
689 /* USBHS1 is connected to CN31 which takes a USB Mini-AB plug
691 * Use J30 to select between Host and Function. This setting
692 * can however not be detected by software. Hotplug of USBHS1
693 * is provided via IRQ8.
695 * Current USB1 works as "USB Host".
698 * If you want to use it as "USB gadget",
700 * - modify usbhs1_get_id() USBHS_HOST -> USBHS_GADGET
701 * - add .get_vbus = usbhs_get_vbus in usbhs1_private
702 * - check usbhs0_device(pio)/usbhs1_device(irq) order in mackerel_devices.
704 #define IRQ8 evt2irq(0x0300)
705 #define USB_PHY_MODE (1 << 4)
706 #define USB_PHY_INT_EN ((1 << 3) | (1 << 2))
707 #define USB_PHY_ON (1 << 1)
708 #define USB_PHY_OFF (1 << 0)
709 #define USB_PHY_INT_CLR (USB_PHY_ON | USB_PHY_OFF)
711 static irqreturn_t usbhs1_interrupt(int irq, void *data)
713 struct platform_device *pdev = data;
714 struct usbhs_private *priv = usbhs_get_priv(pdev);
716 dev_dbg(&pdev->dev, "%s\n", __func__);
718 renesas_usbhs_call_notify_hotplug(pdev);
721 __raw_writew(__raw_readw(priv->usbphyaddr) | USB_PHY_INT_CLR,
727 static int usbhs1_hardware_init(struct platform_device *pdev)
729 struct usbhs_private *priv = usbhs_get_priv(pdev);
732 /* clear interrupt status */
733 __raw_writew(USB_PHY_MODE | USB_PHY_INT_CLR, priv->usbphyaddr);
735 ret = request_irq(IRQ8, usbhs1_interrupt, IRQF_TRIGGER_HIGH,
736 dev_name(&pdev->dev), pdev);
738 dev_err(&pdev->dev, "request_irq err\n");
742 /* enable USB phy interrupt */
743 __raw_writew(USB_PHY_MODE | USB_PHY_INT_EN, priv->usbphyaddr);
748 static int usbhs1_hardware_exit(struct platform_device *pdev)
750 struct usbhs_private *priv = usbhs_get_priv(pdev);
752 /* clear interrupt status */
753 __raw_writew(USB_PHY_MODE | USB_PHY_INT_CLR, priv->usbphyaddr);
755 free_irq(IRQ8, pdev);
760 static int usbhs1_get_id(struct platform_device *pdev)
765 static u32 usbhs1_pipe_cfg[] = {
766 USB_ENDPOINT_XFER_CONTROL,
767 USB_ENDPOINT_XFER_ISOC,
768 USB_ENDPOINT_XFER_ISOC,
769 USB_ENDPOINT_XFER_BULK,
770 USB_ENDPOINT_XFER_BULK,
771 USB_ENDPOINT_XFER_BULK,
772 USB_ENDPOINT_XFER_INT,
773 USB_ENDPOINT_XFER_INT,
774 USB_ENDPOINT_XFER_INT,
775 USB_ENDPOINT_XFER_BULK,
776 USB_ENDPOINT_XFER_BULK,
777 USB_ENDPOINT_XFER_BULK,
778 USB_ENDPOINT_XFER_BULK,
779 USB_ENDPOINT_XFER_BULK,
780 USB_ENDPOINT_XFER_BULK,
781 USB_ENDPOINT_XFER_BULK,
784 static struct usbhs_private usbhs1_private = {
785 .usbphyaddr = IOMEM(0xe60581e2), /* USBPHY1INTAP */
786 .usbcrcaddr = IOMEM(0xe6058130), /* USBCR4 */
788 .platform_callback = {
789 .hardware_init = usbhs1_hardware_init,
790 .hardware_exit = usbhs1_hardware_exit,
791 .get_id = usbhs1_get_id,
792 .phy_reset = usbhs_phy_reset,
797 .pipe_type = usbhs1_pipe_cfg,
798 .pipe_size = ARRAY_SIZE(usbhs1_pipe_cfg),
799 .d0_tx_id = SHDMA_SLAVE_USB1_TX,
800 .d1_rx_id = SHDMA_SLAVE_USB1_RX,
805 static struct resource usbhs1_resources[] = {
809 .end = 0xe68b00e6 - 1,
810 .flags = IORESOURCE_MEM,
813 .start = evt2irq(0x1ce0) /* USB1_USB1I0 */,
814 .flags = IORESOURCE_IRQ,
818 static struct platform_device usbhs1_device = {
819 .name = "renesas_usbhs",
822 .platform_data = &usbhs1_private.info,
823 .dma_mask = &usbhs1_device.dev.coherent_dma_mask,
824 .coherent_dma_mask = DMA_BIT_MASK(32),
826 .num_resources = ARRAY_SIZE(usbhs1_resources),
827 .resource = usbhs1_resources,
831 static struct gpio_led mackerel_leds[] = {
835 .default_state = LEDS_GPIO_DEFSTATE_ON,
840 .default_state = LEDS_GPIO_DEFSTATE_ON,
845 .default_state = LEDS_GPIO_DEFSTATE_ON,
850 .default_state = LEDS_GPIO_DEFSTATE_ON,
854 static struct gpio_led_platform_data mackerel_leds_pdata = {
855 .leds = mackerel_leds,
856 .num_leds = ARRAY_SIZE(mackerel_leds),
859 static struct platform_device leds_device = {
863 .platform_data = &mackerel_leds_pdata,
868 #define IRQ_FSI evt2irq(0x1840)
869 static struct sh_fsi_platform_info fsi_info = {
871 .tx_id = SHDMA_SLAVE_FSIA_TX,
872 .rx_id = SHDMA_SLAVE_FSIA_RX,
875 .flags = SH_FSI_CLK_CPG |
880 static struct resource fsi_resources[] = {
882 /* we need 0xFE1F0000 to access DMA
883 * instead of 0xFE3C0000 */
886 .end = 0xFE1F0400 - 1,
887 .flags = IORESOURCE_MEM,
891 .flags = IORESOURCE_IRQ,
895 static struct platform_device fsi_device = {
898 .num_resources = ARRAY_SIZE(fsi_resources),
899 .resource = fsi_resources,
901 .platform_data = &fsi_info,
905 static struct asoc_simple_card_info fsi2_ak4643_info = {
907 .card = "FSI2A-AK4643",
908 .codec = "ak4642-codec.0-0013",
909 .platform = "sh_fsi2",
910 .daifmt = SND_SOC_DAIFMT_LEFT_J | SND_SOC_DAIFMT_CBM_CFM,
915 .name = "ak4642-hifi",
920 static struct platform_device fsi_ak4643_device = {
921 .name = "asoc-simple-card",
923 .platform_data = &fsi2_ak4643_info,
924 .coherent_dma_mask = DMA_BIT_MASK(32),
925 .dma_mask = &fsi_ak4643_device.dev.coherent_dma_mask,
930 static struct mtd_partition nand_partition_info[] = {
934 .size = 128 * 1024 * 1024,
938 .offset = MTDPART_OFS_APPEND,
939 .size = 256 * 1024 * 1024,
943 .offset = MTDPART_OFS_APPEND,
944 .size = 128 * 1024 * 1024,
948 static struct resource nand_flash_resources[] = {
952 .flags = IORESOURCE_MEM,
955 .start = evt2irq(0x0d80), /* flstei: status error irq */
956 .flags = IORESOURCE_IRQ,
960 static struct sh_flctl_platform_data nand_flash_data = {
961 .parts = nand_partition_info,
962 .nr_parts = ARRAY_SIZE(nand_partition_info),
963 .flcmncr_val = CLK_16B_12L_4H | TYPESEL_SET
964 | SHBUSSEL | SEL_16BIT | SNAND_E,
968 static struct platform_device nand_flash_device = {
970 .resource = nand_flash_resources,
971 .num_resources = ARRAY_SIZE(nand_flash_resources),
973 .platform_data = &nand_flash_data,
978 static struct sh_mobile_sdhi_info sdhi0_info = {
979 .dma_slave_tx = SHDMA_SLAVE_SDHI0_TX,
980 .dma_slave_rx = SHDMA_SLAVE_SDHI0_RX,
981 .tmio_flags = TMIO_MMC_USE_GPIO_CD,
982 .tmio_caps = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ,
986 static struct resource sdhi0_resources[] = {
991 .flags = IORESOURCE_MEM,
993 .name = SH_MOBILE_SDHI_IRQ_SDCARD,
994 .start = evt2irq(0x0e20) /* SDHI0_SDHI0I1 */,
995 .flags = IORESOURCE_IRQ,
997 .name = SH_MOBILE_SDHI_IRQ_SDIO,
998 .start = evt2irq(0x0e40) /* SDHI0_SDHI0I2 */,
999 .flags = IORESOURCE_IRQ,
1003 static struct platform_device sdhi0_device = {
1004 .name = "sh_mobile_sdhi",
1005 .num_resources = ARRAY_SIZE(sdhi0_resources),
1006 .resource = sdhi0_resources,
1009 .platform_data = &sdhi0_info,
1013 #if !IS_ENABLED(CONFIG_MMC_SH_MMCIF)
1016 /* GPIO 41 can trigger IRQ8, but it is used by USBHS1, we have to poll */
1017 static struct sh_mobile_sdhi_info sdhi1_info = {
1018 .dma_slave_tx = SHDMA_SLAVE_SDHI1_TX,
1019 .dma_slave_rx = SHDMA_SLAVE_SDHI1_RX,
1020 .tmio_flags = TMIO_MMC_WRPROTECT_DISABLE | TMIO_MMC_USE_GPIO_CD,
1021 .tmio_caps = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ |
1026 static struct resource sdhi1_resources[] = {
1029 .start = 0xe6860000,
1031 .flags = IORESOURCE_MEM,
1033 .name = SH_MOBILE_SDHI_IRQ_SDCARD,
1034 .start = evt2irq(0x0ea0), /* SDHI1_SDHI1I1 */
1035 .flags = IORESOURCE_IRQ,
1037 .name = SH_MOBILE_SDHI_IRQ_SDIO,
1038 .start = evt2irq(0x0ec0), /* SDHI1_SDHI1I2 */
1039 .flags = IORESOURCE_IRQ,
1043 static struct platform_device sdhi1_device = {
1044 .name = "sh_mobile_sdhi",
1045 .num_resources = ARRAY_SIZE(sdhi1_resources),
1046 .resource = sdhi1_resources,
1049 .platform_data = &sdhi1_info,
1057 * The card detect pin of the top SD/MMC slot (CN23) is active low and is
1058 * connected to GPIO SCIFB_SCK of SH7372 (GPIO 162).
1060 static struct sh_mobile_sdhi_info sdhi2_info = {
1061 .dma_slave_tx = SHDMA_SLAVE_SDHI2_TX,
1062 .dma_slave_rx = SHDMA_SLAVE_SDHI2_RX,
1063 .tmio_flags = TMIO_MMC_WRPROTECT_DISABLE | TMIO_MMC_USE_GPIO_CD,
1064 .tmio_caps = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ |
1069 static struct resource sdhi2_resources[] = {
1072 .start = 0xe6870000,
1074 .flags = IORESOURCE_MEM,
1076 .name = SH_MOBILE_SDHI_IRQ_SDCARD,
1077 .start = evt2irq(0x1220), /* SDHI2_SDHI2I1 */
1078 .flags = IORESOURCE_IRQ,
1080 .name = SH_MOBILE_SDHI_IRQ_SDIO,
1081 .start = evt2irq(0x1240), /* SDHI2_SDHI2I2 */
1082 .flags = IORESOURCE_IRQ,
1086 static struct platform_device sdhi2_device = {
1087 .name = "sh_mobile_sdhi",
1088 .num_resources = ARRAY_SIZE(sdhi2_resources),
1089 .resource = sdhi2_resources,
1092 .platform_data = &sdhi2_info,
1097 #if IS_ENABLED(CONFIG_MMC_SH_MMCIF)
1098 static struct resource sh_mmcif_resources[] = {
1101 .start = 0xE6BD0000,
1103 .flags = IORESOURCE_MEM,
1107 .start = evt2irq(0x1ac0),
1108 .flags = IORESOURCE_IRQ,
1112 .start = evt2irq(0x1ae0),
1113 .flags = IORESOURCE_IRQ,
1117 static struct sh_mmcif_plat_data sh_mmcif_plat = {
1119 .caps = MMC_CAP_4_BIT_DATA |
1120 MMC_CAP_8_BIT_DATA |
1122 .use_cd_gpio = true,
1123 /* card detect pin for SD/MMC slot (CN7) */
1125 .slave_id_tx = SHDMA_SLAVE_MMCIF_TX,
1126 .slave_id_rx = SHDMA_SLAVE_MMCIF_RX,
1129 static struct platform_device sh_mmcif_device = {
1134 .coherent_dma_mask = 0xffffffff,
1135 .platform_data = &sh_mmcif_plat,
1137 .num_resources = ARRAY_SIZE(sh_mmcif_resources),
1138 .resource = sh_mmcif_resources,
1142 static int mackerel_camera_add(struct soc_camera_device *icd);
1143 static void mackerel_camera_del(struct soc_camera_device *icd);
1145 static int camera_set_capture(struct soc_camera_platform_info *info,
1148 return 0; /* camera sensor always enabled */
1151 static struct soc_camera_platform_info camera_info = {
1152 .format_name = "UYVY",
1155 .code = V4L2_MBUS_FMT_UYVY8_2X8,
1156 .colorspace = V4L2_COLORSPACE_SMPTE170M,
1157 .field = V4L2_FIELD_NONE,
1161 .mbus_param = V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_MASTER |
1162 V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_HIGH |
1163 V4L2_MBUS_DATA_ACTIVE_HIGH,
1164 .mbus_type = V4L2_MBUS_PARALLEL,
1165 .set_capture = camera_set_capture,
1168 static struct soc_camera_link camera_link = {
1170 .add_device = mackerel_camera_add,
1171 .del_device = mackerel_camera_del,
1172 .module_name = "soc_camera_platform",
1173 .priv = &camera_info,
1176 static struct platform_device *camera_device;
1178 static void mackerel_camera_release(struct device *dev)
1180 soc_camera_platform_release(&camera_device);
1183 static int mackerel_camera_add(struct soc_camera_device *icd)
1185 return soc_camera_platform_add(icd, &camera_device, &camera_link,
1186 mackerel_camera_release, 0);
1189 static void mackerel_camera_del(struct soc_camera_device *icd)
1191 soc_camera_platform_del(icd, camera_device, &camera_link);
1194 static struct sh_mobile_ceu_info sh_mobile_ceu_info = {
1195 .flags = SH_CEU_FLAG_USE_8BIT_BUS,
1200 static struct resource ceu_resources[] = {
1203 .start = 0xfe910000,
1205 .flags = IORESOURCE_MEM,
1208 .start = intcs_evt2irq(0x880),
1209 .flags = IORESOURCE_IRQ,
1212 /* place holder for contiguous memory */
1216 static struct platform_device ceu_device = {
1217 .name = "sh_mobile_ceu",
1218 .id = 0, /* "ceu0" clock */
1219 .num_resources = ARRAY_SIZE(ceu_resources),
1220 .resource = ceu_resources,
1222 .platform_data = &sh_mobile_ceu_info,
1223 .coherent_dma_mask = 0xffffffff,
1227 static struct platform_device mackerel_camera = {
1228 .name = "soc-camera-pdrv",
1231 .platform_data = &camera_link,
1235 static struct platform_device *mackerel_devices[] __initdata = {
1239 &gpio_backlight_device,
1248 #if !IS_ENABLED(CONFIG_MMC_SH_MMCIF)
1261 /* Keypad Initialization */
1262 #define KEYPAD_BUTTON(ev_type, ev_code, act_low) \
1266 .active_low = act_low, \
1269 #define KEYPAD_BUTTON_LOW(event_code) KEYPAD_BUTTON(EV_KEY, event_code, 1)
1271 static struct tca6416_button mackerel_gpio_keys[] = {
1272 KEYPAD_BUTTON_LOW(KEY_HOME),
1273 KEYPAD_BUTTON_LOW(KEY_MENU),
1274 KEYPAD_BUTTON_LOW(KEY_BACK),
1275 KEYPAD_BUTTON_LOW(KEY_POWER),
1278 static struct tca6416_keys_platform_data mackerel_tca6416_keys_info = {
1279 .buttons = mackerel_gpio_keys,
1280 .nbuttons = ARRAY_SIZE(mackerel_gpio_keys),
1287 #define IRQ7 evt2irq(0x02e0)
1288 #define IRQ9 evt2irq(0x0320)
1290 static struct i2c_board_info i2c0_devices[] = {
1292 I2C_BOARD_INFO("ak4643", 0x13),
1296 I2C_BOARD_INFO("tca6408-keys", 0x20),
1297 .platform_data = &mackerel_tca6416_keys_info,
1302 I2C_BOARD_INFO("st1232-ts", 0x55),
1307 #define IRQ21 evt2irq(0x32a0)
1309 static struct i2c_board_info i2c1_devices[] = {
1312 I2C_BOARD_INFO("adxl34x", 0x53),
1317 static unsigned long pin_pulldown_conf[] = {
1318 PIN_CONF_PACKED(PIN_CONFIG_BIAS_PULL_DOWN, 0),
1321 static const struct pinctrl_map mackerel_pinctrl_map[] = {
1323 PIN_MAP_MUX_GROUP_DEFAULT("1-0053", "pfc-sh7372",
1324 "intc_irq21", "intc"),
1326 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_ceu.0", "pfc-sh7372",
1327 "ceu_data_0_7", "ceu"),
1328 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_ceu.0", "pfc-sh7372",
1329 "ceu_clk_0", "ceu"),
1330 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_ceu.0", "pfc-sh7372",
1332 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_ceu.0", "pfc-sh7372",
1333 "ceu_field", "ceu"),
1335 PIN_MAP_MUX_GROUP_DEFAULT("sh_flctl.0", "pfc-sh7372",
1336 "flctl_data", "flctl"),
1337 PIN_MAP_MUX_GROUP_DEFAULT("sh_flctl.0", "pfc-sh7372",
1338 "flctl_ce0", "flctl"),
1339 PIN_MAP_MUX_GROUP_DEFAULT("sh_flctl.0", "pfc-sh7372",
1340 "flctl_ctrl", "flctl"),
1342 PIN_MAP_MUX_GROUP_DEFAULT("asoc-simple-card.0", "pfc-sh7372",
1343 "fsia_sclk_in", "fsia"),
1344 PIN_MAP_MUX_GROUP_DEFAULT("asoc-simple-card.0", "pfc-sh7372",
1345 "fsia_data_in", "fsia"),
1346 PIN_MAP_MUX_GROUP_DEFAULT("asoc-simple-card.0", "pfc-sh7372",
1347 "fsia_data_out", "fsia"),
1349 PIN_MAP_MUX_GROUP_DEFAULT("asoc-simple-card.1", "pfc-sh7372",
1350 "fsib_mclk_in", "fsib"),
1352 PIN_MAP_MUX_GROUP_DEFAULT("sh-mobile-hdmi", "pfc-sh7372",
1355 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_lcdc_fb.0", "pfc-sh7372",
1356 "lcd_data24", "lcd"),
1357 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_lcdc_fb.0", "pfc-sh7372",
1360 PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.0", "pfc-sh7372",
1361 "scifa0_data", "scifa0"),
1362 /* SCIFA2 (GT-720F GPS module) */
1363 PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.2", "pfc-sh7372",
1364 "scifa2_data", "scifa2"),
1366 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-sh7372",
1367 "sdhi0_data4", "sdhi0"),
1368 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-sh7372",
1369 "sdhi0_ctrl", "sdhi0"),
1370 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-sh7372",
1371 "sdhi0_wp", "sdhi0"),
1372 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-sh7372",
1373 "intc_irq26_1", "intc"),
1375 #if !IS_ENABLED(CONFIG_MMC_SH_MMCIF)
1376 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.1", "pfc-sh7372",
1377 "sdhi1_data4", "sdhi1"),
1378 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.1", "pfc-sh7372",
1379 "sdhi1_ctrl", "sdhi1"),
1382 PIN_MAP_MUX_GROUP_DEFAULT("sh_mmcif.0", "pfc-sh7372",
1383 "mmc0_data8_0", "mmc0"),
1384 PIN_MAP_MUX_GROUP_DEFAULT("sh_mmcif.0", "pfc-sh7372",
1385 "mmc0_ctrl_0", "mmc0"),
1388 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.2", "pfc-sh7372",
1389 "sdhi2_data4", "sdhi2"),
1390 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.2", "pfc-sh7372",
1391 "sdhi2_ctrl", "sdhi2"),
1393 PIN_MAP_MUX_GROUP_DEFAULT("smsc911x", "pfc-sh7372",
1395 PIN_MAP_MUX_GROUP_DEFAULT("smsc911x", "pfc-sh7372",
1396 "intc_irq6_0", "intc"),
1398 PIN_MAP_MUX_GROUP_DEFAULT("0-0055", "pfc-sh7372",
1399 "intc_irq7_0", "intc"),
1401 PIN_MAP_MUX_GROUP_DEFAULT("0-0020", "pfc-sh7372",
1402 "intc_irq9_0", "intc"),
1404 PIN_MAP_MUX_GROUP_DEFAULT("renesas_usbhs.0", "pfc-sh7372",
1405 "usb0_vbus", "usb0"),
1406 PIN_MAP_CONFIGS_GROUP_DEFAULT("renesas_usbhs.0", "pfc-sh7372",
1407 "usb0_vbus", pin_pulldown_conf),
1409 PIN_MAP_MUX_GROUP_DEFAULT("renesas_usbhs.1", "pfc-sh7372",
1410 "usb1_vbus", "usb1"),
1411 PIN_MAP_CONFIGS_GROUP_DEFAULT("renesas_usbhs.1", "pfc-sh7372",
1412 "usb1_vbus", pin_pulldown_conf),
1413 PIN_MAP_MUX_GROUP_DEFAULT("renesas_usbhs.1", "pfc-sh7372",
1414 "usb1_otg_id_0", "usb1"),
1417 #define GPIO_PORT9CR IOMEM(0xE6051009)
1418 #define GPIO_PORT10CR IOMEM(0xE605100A)
1419 #define SRCR4 IOMEM(0xe61580bc)
1420 #define USCCR1 IOMEM(0xE6058144)
1421 static void __init mackerel_init(void)
1423 struct pm_domain_device domain_devices[] = {
1424 { "A4LC", &lcdc_device, },
1425 { "A4LC", &hdmi_lcdc_device, },
1426 { "A4LC", &meram_device, },
1427 { "A4MP", &fsi_device, },
1428 { "A3SP", &usbhs0_device, },
1429 { "A3SP", &usbhs1_device, },
1430 { "A3SP", &nand_flash_device, },
1431 { "A3SP", &sdhi0_device, },
1432 #if !IS_ENABLED(CONFIG_MMC_SH_MMCIF)
1433 { "A3SP", &sdhi1_device, },
1435 { "A3SP", &sh_mmcif_device, },
1437 { "A3SP", &sdhi2_device, },
1438 { "A4R", &ceu_device, },
1443 regulator_register_always_on(0, "fixed-1.8V", fixed1v8_power_consumers,
1444 ARRAY_SIZE(fixed1v8_power_consumers), 1800000);
1445 regulator_register_always_on(1, "fixed-3.3V", fixed3v3_power_consumers,
1446 ARRAY_SIZE(fixed3v3_power_consumers), 3300000);
1447 regulator_register_fixed(2, dummy_supplies, ARRAY_SIZE(dummy_supplies));
1449 /* External clock source */
1450 clk_set_rate(&sh7372_dv_clki_clk, 27000000);
1452 pinctrl_register_mappings(mackerel_pinctrl_map,
1453 ARRAY_SIZE(mackerel_pinctrl_map));
1454 sh7372_pinmux_init();
1456 gpio_request_one(151, GPIOF_OUT_INIT_HIGH, NULL); /* LCDDON */
1458 /* FSI2 port A (ak4643) */
1459 gpio_request_one(161, GPIOF_OUT_INIT_LOW, NULL); /* slave */
1461 gpio_request(9, NULL);
1462 gpio_request(10, NULL);
1463 gpio_direction_none(GPIO_PORT9CR); /* FSIAOBT needs no direction */
1464 gpio_direction_none(GPIO_PORT10CR); /* FSIAOLR needs no direction */
1466 intc_set_priority(IRQ_FSI, 3); /* irq priority FSI(3) > SMSC911X(2) */
1468 /* FSI2 port B (HDMI) */
1469 __raw_writew(__raw_readw(USCCR1) & ~(1 << 6), USCCR1); /* use SPDIF */
1471 /* set SPU2 clock to 119.6 MHz */
1472 clk = clk_get(NULL, "spu_clk");
1474 clk_set_rate(clk, clk_round_rate(clk, 119600000));
1479 irq_set_irq_type(IRQ9, IRQ_TYPE_LEVEL_HIGH);
1482 irq_set_irq_type(IRQ7, IRQ_TYPE_LEVEL_LOW);
1485 irq_set_irq_type(IRQ21, IRQ_TYPE_LEVEL_HIGH);
1487 /* Reset HDMI, must be held at least one EXTALR (32768Hz) period */
1488 srcr4 = __raw_readl(SRCR4);
1489 __raw_writel(srcr4 | (1 << 13), SRCR4);
1491 __raw_writel(srcr4 & ~(1 << 13), SRCR4);
1493 i2c_register_board_info(0, i2c0_devices,
1494 ARRAY_SIZE(i2c0_devices));
1495 i2c_register_board_info(1, i2c1_devices,
1496 ARRAY_SIZE(i2c1_devices));
1498 sh7372_add_standard_devices();
1500 platform_add_devices(mackerel_devices, ARRAY_SIZE(mackerel_devices));
1502 rmobile_add_devices_to_domains(domain_devices,
1503 ARRAY_SIZE(domain_devices));
1505 hdmi_init_pm_clock();
1507 pm_clk_add(&fsi_device.dev, "spu2");
1508 pm_clk_add(&hdmi_lcdc_device.dev, "hdmi");
1511 static const char *mackerel_boards_compat_dt[] __initdata = {
1516 DT_MACHINE_START(MACKEREL_DT, "mackerel")
1517 .map_io = sh7372_map_io,
1518 .init_early = sh7372_add_early_devices,
1519 .init_irq = sh7372_init_irq,
1520 .handle_irq = shmobile_handle_irq_intc,
1521 .init_machine = mackerel_init,
1522 .init_late = sh7372_pm_init_late,
1523 .init_time = sh7372_earlytimer_init,
1524 .dt_compat = mackerel_boards_compat_dt,