1ccb7cc74SKuninori Morimoto /*
2ccb7cc74SKuninori Morimoto  * r8a7778 processor support
3ccb7cc74SKuninori Morimoto  *
4ccb7cc74SKuninori Morimoto  * Copyright (C) 2013  Renesas Solutions Corp.
5ccb7cc74SKuninori Morimoto  * Copyright (C) 2013  Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
652421914SSergei Shtylyov  * Copyright (C) 2013  Cogent Embedded, Inc.
7ccb7cc74SKuninori Morimoto  *
8ccb7cc74SKuninori Morimoto  * This program is free software; you can redistribute it and/or modify
9ccb7cc74SKuninori Morimoto  * it under the terms of the GNU General Public License as published by
10ccb7cc74SKuninori Morimoto  * the Free Software Foundation; version 2 of the License.
11ccb7cc74SKuninori Morimoto  *
12ccb7cc74SKuninori Morimoto  * This program is distributed in the hope that it will be useful,
13ccb7cc74SKuninori Morimoto  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14ccb7cc74SKuninori Morimoto  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15ccb7cc74SKuninori Morimoto  * GNU General Public License for more details.
16ccb7cc74SKuninori Morimoto  *
17ccb7cc74SKuninori Morimoto  * You should have received a copy of the GNU General Public License
18ccb7cc74SKuninori Morimoto  * along with this program; if not, write to the Free Software
19ccb7cc74SKuninori Morimoto  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20ccb7cc74SKuninori Morimoto  */
21ccb7cc74SKuninori Morimoto 
22ccb7cc74SKuninori Morimoto #include <linux/kernel.h>
23ccb7cc74SKuninori Morimoto #include <linux/io.h>
24ccb7cc74SKuninori Morimoto #include <linux/irqchip/arm-gic.h>
25ccb7cc74SKuninori Morimoto #include <linux/of.h>
26ccb7cc74SKuninori Morimoto #include <linux/of_platform.h>
2739ca2283SKuninori Morimoto #include <linux/platform_data/gpio-rcar.h>
283a42fa20SKuninori Morimoto #include <linux/platform_data/irq-renesas-intc-irqpin.h>
29ccb7cc74SKuninori Morimoto #include <linux/platform_device.h>
30ccb7cc74SKuninori Morimoto #include <linux/irqchip.h>
31db331fc8SKuninori Morimoto #include <linux/serial_sci.h>
32ccb7cc74SKuninori Morimoto #include <linux/sh_timer.h>
3302474a41SSergei Shtylyov #include <linux/pm_runtime.h>
3402474a41SSergei Shtylyov #include <linux/usb/phy.h>
3502474a41SSergei Shtylyov #include <linux/usb/hcd.h>
3602474a41SSergei Shtylyov #include <linux/usb/ehci_pdriver.h>
3702474a41SSergei Shtylyov #include <linux/usb/ohci_pdriver.h>
3802474a41SSergei Shtylyov #include <linux/dma-mapping.h>
39ccb7cc74SKuninori Morimoto #include <mach/irqs.h>
40ccb7cc74SKuninori Morimoto #include <mach/r8a7778.h>
41ccb7cc74SKuninori Morimoto #include <mach/common.h>
42ccb7cc74SKuninori Morimoto #include <asm/mach/arch.h>
43ccb7cc74SKuninori Morimoto #include <asm/hardware/cache-l2x0.h>
44ccb7cc74SKuninori Morimoto 
45db331fc8SKuninori Morimoto /* SCIF */
46db331fc8SKuninori Morimoto #define SCIF_INFO(baseaddr, irq)				\
47db331fc8SKuninori Morimoto {								\
48db331fc8SKuninori Morimoto 	.mapbase	= baseaddr,				\
49db331fc8SKuninori Morimoto 	.flags		= UPF_BOOT_AUTOCONF | UPF_IOREMAP,	\
50db331fc8SKuninori Morimoto 	.scscr		= SCSCR_RE | SCSCR_TE | SCSCR_CKE1,	\
51db331fc8SKuninori Morimoto 	.scbrr_algo_id	= SCBRR_ALGO_2,				\
52db331fc8SKuninori Morimoto 	.type		= PORT_SCIF,				\
53db331fc8SKuninori Morimoto 	.irqs		= SCIx_IRQ_MUXED(irq),			\
54db331fc8SKuninori Morimoto }
55db331fc8SKuninori Morimoto 
56c9031fbbSKuninori Morimoto static struct plat_sci_port scif_platform_data[] __initdata = {
57db331fc8SKuninori Morimoto 	SCIF_INFO(0xffe40000, gic_iid(0x66)),
58db331fc8SKuninori Morimoto 	SCIF_INFO(0xffe41000, gic_iid(0x67)),
59db331fc8SKuninori Morimoto 	SCIF_INFO(0xffe42000, gic_iid(0x68)),
60db331fc8SKuninori Morimoto 	SCIF_INFO(0xffe43000, gic_iid(0x69)),
61db331fc8SKuninori Morimoto 	SCIF_INFO(0xffe44000, gic_iid(0x6a)),
62db331fc8SKuninori Morimoto 	SCIF_INFO(0xffe45000, gic_iid(0x6b)),
63db331fc8SKuninori Morimoto };
64db331fc8SKuninori Morimoto 
65ccb7cc74SKuninori Morimoto /* TMU */
66c9031fbbSKuninori Morimoto static struct resource sh_tmu0_resources[] __initdata = {
67ccb7cc74SKuninori Morimoto 	DEFINE_RES_MEM(0xffd80008, 12),
68ccb7cc74SKuninori Morimoto 	DEFINE_RES_IRQ(gic_iid(0x40)),
69ccb7cc74SKuninori Morimoto };
70ccb7cc74SKuninori Morimoto 
71c9031fbbSKuninori Morimoto static struct sh_timer_config sh_tmu0_platform_data __initdata = {
72ccb7cc74SKuninori Morimoto 	.name			= "TMU00",
73ccb7cc74SKuninori Morimoto 	.channel_offset		= 0x4,
74ccb7cc74SKuninori Morimoto 	.timer_bit		= 0,
75ccb7cc74SKuninori Morimoto 	.clockevent_rating	= 200,
76ccb7cc74SKuninori Morimoto };
77ccb7cc74SKuninori Morimoto 
78c9031fbbSKuninori Morimoto static struct resource sh_tmu1_resources[] __initdata = {
79ccb7cc74SKuninori Morimoto 	DEFINE_RES_MEM(0xffd80014, 12),
80ccb7cc74SKuninori Morimoto 	DEFINE_RES_IRQ(gic_iid(0x41)),
81ccb7cc74SKuninori Morimoto };
82ccb7cc74SKuninori Morimoto 
83c9031fbbSKuninori Morimoto static struct sh_timer_config sh_tmu1_platform_data __initdata = {
84ccb7cc74SKuninori Morimoto 	.name			= "TMU01",
85ccb7cc74SKuninori Morimoto 	.channel_offset		= 0x10,
86ccb7cc74SKuninori Morimoto 	.timer_bit		= 1,
87ccb7cc74SKuninori Morimoto 	.clocksource_rating	= 200,
88ccb7cc74SKuninori Morimoto };
89ccb7cc74SKuninori Morimoto 
9081484487SKuninori Morimoto #define r8a7778_register_tmu(idx)			\
9181484487SKuninori Morimoto 	platform_device_register_resndata(		\
9281484487SKuninori Morimoto 		&platform_bus, "sh_tmu", idx,		\
9381484487SKuninori Morimoto 		sh_tmu##idx##_resources,		\
9481484487SKuninori Morimoto 		ARRAY_SIZE(sh_tmu##idx##_resources),	\
9581484487SKuninori Morimoto 		&sh_tmu##idx##_platform_data,		\
9681484487SKuninori Morimoto 		sizeof(sh_tmu##idx##_platform_data))
97ccb7cc74SKuninori Morimoto 
98f39d35fcSKuninori Morimoto int r8a7778_usb_phy_power(bool enable)
99f39d35fcSKuninori Morimoto {
100f39d35fcSKuninori Morimoto 	static struct usb_phy *phy = NULL;
101f39d35fcSKuninori Morimoto 	int ret = 0;
10202474a41SSergei Shtylyov 
103f39d35fcSKuninori Morimoto 	if (!phy)
104f39d35fcSKuninori Morimoto 		phy = usb_get_phy(USB_PHY_TYPE_USB2);
105f39d35fcSKuninori Morimoto 
106f39d35fcSKuninori Morimoto 	if (IS_ERR(phy)) {
107f39d35fcSKuninori Morimoto 		pr_err("kernel doesn't have usb phy driver\n");
108f39d35fcSKuninori Morimoto 		return PTR_ERR(phy);
109f39d35fcSKuninori Morimoto 	}
110f39d35fcSKuninori Morimoto 
111f39d35fcSKuninori Morimoto 	if (enable)
112f39d35fcSKuninori Morimoto 		ret = usb_phy_init(phy);
113f39d35fcSKuninori Morimoto 	else
114f39d35fcSKuninori Morimoto 		usb_phy_shutdown(phy);
115f39d35fcSKuninori Morimoto 
116f39d35fcSKuninori Morimoto 	return ret;
117f39d35fcSKuninori Morimoto }
118f39d35fcSKuninori Morimoto 
119f39d35fcSKuninori Morimoto /* USB */
12002474a41SSergei Shtylyov static int usb_power_on(struct platform_device *pdev)
12102474a41SSergei Shtylyov {
122f39d35fcSKuninori Morimoto 	int ret = r8a7778_usb_phy_power(true);
123f39d35fcSKuninori Morimoto 
124f39d35fcSKuninori Morimoto 	if (ret)
125f39d35fcSKuninori Morimoto 		return ret;
12602474a41SSergei Shtylyov 
12702474a41SSergei Shtylyov 	pm_runtime_enable(&pdev->dev);
12802474a41SSergei Shtylyov 	pm_runtime_get_sync(&pdev->dev);
12902474a41SSergei Shtylyov 
13002474a41SSergei Shtylyov 	return 0;
13102474a41SSergei Shtylyov }
13202474a41SSergei Shtylyov 
13302474a41SSergei Shtylyov static void usb_power_off(struct platform_device *pdev)
13402474a41SSergei Shtylyov {
135f39d35fcSKuninori Morimoto 	if (r8a7778_usb_phy_power(false))
13602474a41SSergei Shtylyov 		return;
13702474a41SSergei Shtylyov 
13802474a41SSergei Shtylyov 	pm_runtime_put_sync(&pdev->dev);
13902474a41SSergei Shtylyov 	pm_runtime_disable(&pdev->dev);
14002474a41SSergei Shtylyov }
14102474a41SSergei Shtylyov 
14202474a41SSergei Shtylyov static int ehci_init_internal_buffer(struct usb_hcd *hcd)
14302474a41SSergei Shtylyov {
14402474a41SSergei Shtylyov 	/*
14502474a41SSergei Shtylyov 	 * Below are recommended values from the datasheet;
14602474a41SSergei Shtylyov 	 * see [USB :: Setting of EHCI Internal Buffer].
14702474a41SSergei Shtylyov 	 */
14802474a41SSergei Shtylyov 	/* EHCI IP internal buffer setting */
14902474a41SSergei Shtylyov 	iowrite32(0x00ff0040, hcd->regs + 0x0094);
15002474a41SSergei Shtylyov 	/* EHCI IP internal buffer enable */
15102474a41SSergei Shtylyov 	iowrite32(0x00000001, hcd->regs + 0x009C);
15202474a41SSergei Shtylyov 
15302474a41SSergei Shtylyov 	return 0;
15402474a41SSergei Shtylyov }
15502474a41SSergei Shtylyov 
15602474a41SSergei Shtylyov static struct usb_ehci_pdata ehci_pdata __initdata = {
15702474a41SSergei Shtylyov 	.power_on	= usb_power_on,
15802474a41SSergei Shtylyov 	.power_off	= usb_power_off,
15902474a41SSergei Shtylyov 	.power_suspend	= usb_power_off,
16002474a41SSergei Shtylyov 	.pre_setup	= ehci_init_internal_buffer,
16102474a41SSergei Shtylyov };
16202474a41SSergei Shtylyov 
16302474a41SSergei Shtylyov static struct resource ehci_resources[] __initdata = {
16402474a41SSergei Shtylyov 	DEFINE_RES_MEM(0xffe70000, 0x400),
16502474a41SSergei Shtylyov 	DEFINE_RES_IRQ(gic_iid(0x4c)),
16602474a41SSergei Shtylyov };
16702474a41SSergei Shtylyov 
16802474a41SSergei Shtylyov static struct usb_ohci_pdata ohci_pdata __initdata = {
16902474a41SSergei Shtylyov 	.power_on	= usb_power_on,
17002474a41SSergei Shtylyov 	.power_off	= usb_power_off,
17102474a41SSergei Shtylyov 	.power_suspend	= usb_power_off,
17202474a41SSergei Shtylyov };
17302474a41SSergei Shtylyov 
17402474a41SSergei Shtylyov static struct resource ohci_resources[] __initdata = {
17502474a41SSergei Shtylyov 	DEFINE_RES_MEM(0xffe70400, 0x400),
17602474a41SSergei Shtylyov 	DEFINE_RES_IRQ(gic_iid(0x4c)),
17702474a41SSergei Shtylyov };
17802474a41SSergei Shtylyov 
17902474a41SSergei Shtylyov #define USB_PLATFORM_INFO(hci)					\
18002474a41SSergei Shtylyov static struct platform_device_info hci##_info __initdata = {	\
18102474a41SSergei Shtylyov 	.parent		= &platform_bus,			\
18202474a41SSergei Shtylyov 	.name		= #hci "-platform",			\
18302474a41SSergei Shtylyov 	.id		= -1,					\
18402474a41SSergei Shtylyov 	.res		= hci##_resources,			\
18502474a41SSergei Shtylyov 	.num_res	= ARRAY_SIZE(hci##_resources),		\
18602474a41SSergei Shtylyov 	.data		= &hci##_pdata,				\
18702474a41SSergei Shtylyov 	.size_data	= sizeof(hci##_pdata),			\
18802474a41SSergei Shtylyov 	.dma_mask	= DMA_BIT_MASK(32),			\
18902474a41SSergei Shtylyov }
19002474a41SSergei Shtylyov 
19102474a41SSergei Shtylyov USB_PLATFORM_INFO(ehci);
19202474a41SSergei Shtylyov USB_PLATFORM_INFO(ohci);
19302474a41SSergei Shtylyov 
194734e02f8SKuninori Morimoto /* Ether */
195c9031fbbSKuninori Morimoto static struct resource ether_resources[] __initdata = {
196734e02f8SKuninori Morimoto 	DEFINE_RES_MEM(0xfde00000, 0x400),
197734e02f8SKuninori Morimoto 	DEFINE_RES_IRQ(gic_iid(0x89)),
198734e02f8SKuninori Morimoto };
199734e02f8SKuninori Morimoto 
200734e02f8SKuninori Morimoto void __init r8a7778_add_ether_device(struct sh_eth_plat_data *pdata)
201734e02f8SKuninori Morimoto {
202c02f8469SSergei Shtylyov 	platform_device_register_resndata(&platform_bus, "r8a777x-ether", -1,
203734e02f8SKuninori Morimoto 					  ether_resources,
204734e02f8SKuninori Morimoto 					  ARRAY_SIZE(ether_resources),
205734e02f8SKuninori Morimoto 					  pdata, sizeof(*pdata));
206734e02f8SKuninori Morimoto }
207734e02f8SKuninori Morimoto 
20839ca2283SKuninori Morimoto /* PFC/GPIO */
209c9031fbbSKuninori Morimoto static struct resource pfc_resources[] __initdata = {
210369b00bbSKuninori Morimoto 	DEFINE_RES_MEM(0xfffc0000, 0x118),
211369b00bbSKuninori Morimoto };
212369b00bbSKuninori Morimoto 
21339ca2283SKuninori Morimoto #define R8A7778_GPIO(idx)						\
214c9031fbbSKuninori Morimoto static struct resource r8a7778_gpio##idx##_resources[] __initdata = {	\
21539ca2283SKuninori Morimoto 	DEFINE_RES_MEM(0xffc40000 + 0x1000 * (idx), 0x30),		\
21639ca2283SKuninori Morimoto 	DEFINE_RES_IRQ(gic_iid(0x87)),					\
21739ca2283SKuninori Morimoto };									\
21839ca2283SKuninori Morimoto 									\
219c9031fbbSKuninori Morimoto static struct gpio_rcar_config r8a7778_gpio##idx##_platform_data __initdata = { \
22039ca2283SKuninori Morimoto 	.gpio_base	= 32 * (idx),					\
22139ca2283SKuninori Morimoto 	.irq_base	= GPIO_IRQ_BASE(idx),				\
22239ca2283SKuninori Morimoto 	.number_of_pins	= 32,						\
22339ca2283SKuninori Morimoto 	.pctl_name	= "pfc-r8a7778",				\
22439ca2283SKuninori Morimoto }
22539ca2283SKuninori Morimoto 
22639ca2283SKuninori Morimoto R8A7778_GPIO(0);
22739ca2283SKuninori Morimoto R8A7778_GPIO(1);
22839ca2283SKuninori Morimoto R8A7778_GPIO(2);
22939ca2283SKuninori Morimoto R8A7778_GPIO(3);
23039ca2283SKuninori Morimoto R8A7778_GPIO(4);
23139ca2283SKuninori Morimoto 
23239ca2283SKuninori Morimoto #define r8a7778_register_gpio(idx)				\
23339ca2283SKuninori Morimoto 	platform_device_register_resndata(			\
23439ca2283SKuninori Morimoto 		&platform_bus, "gpio_rcar", idx,		\
23539ca2283SKuninori Morimoto 		r8a7778_gpio##idx##_resources,			\
23639ca2283SKuninori Morimoto 		ARRAY_SIZE(r8a7778_gpio##idx##_resources),	\
23739ca2283SKuninori Morimoto 		&r8a7778_gpio##idx##_platform_data,		\
23839ca2283SKuninori Morimoto 		sizeof(r8a7778_gpio##idx##_platform_data))
23939ca2283SKuninori Morimoto 
240369b00bbSKuninori Morimoto void __init r8a7778_pinmux_init(void)
241369b00bbSKuninori Morimoto {
242369b00bbSKuninori Morimoto 	platform_device_register_simple(
243369b00bbSKuninori Morimoto 		"pfc-r8a7778", -1,
244369b00bbSKuninori Morimoto 		pfc_resources,
245369b00bbSKuninori Morimoto 		ARRAY_SIZE(pfc_resources));
24639ca2283SKuninori Morimoto 
24739ca2283SKuninori Morimoto 	r8a7778_register_gpio(0);
24839ca2283SKuninori Morimoto 	r8a7778_register_gpio(1);
24939ca2283SKuninori Morimoto 	r8a7778_register_gpio(2);
25039ca2283SKuninori Morimoto 	r8a7778_register_gpio(3);
25139ca2283SKuninori Morimoto 	r8a7778_register_gpio(4);
252ae8b378fSSimon Horman };
253ae8b378fSSimon Horman 
25446b9a092SKuninori Morimoto /* I2C */
25546b9a092SKuninori Morimoto static struct resource i2c_resources[] __initdata = {
25646b9a092SKuninori Morimoto 	/* I2C0 */
25746b9a092SKuninori Morimoto 	DEFINE_RES_MEM(0xffc70000, 0x1000),
25846b9a092SKuninori Morimoto 	DEFINE_RES_IRQ(gic_iid(0x63)),
25946b9a092SKuninori Morimoto 	/* I2C1 */
26046b9a092SKuninori Morimoto 	DEFINE_RES_MEM(0xffc71000, 0x1000),
26146b9a092SKuninori Morimoto 	DEFINE_RES_IRQ(gic_iid(0x6e)),
26246b9a092SKuninori Morimoto 	/* I2C2 */
26346b9a092SKuninori Morimoto 	DEFINE_RES_MEM(0xffc72000, 0x1000),
26446b9a092SKuninori Morimoto 	DEFINE_RES_IRQ(gic_iid(0x6c)),
26546b9a092SKuninori Morimoto 	/* I2C3 */
26646b9a092SKuninori Morimoto 	DEFINE_RES_MEM(0xffc73000, 0x1000),
26746b9a092SKuninori Morimoto 	DEFINE_RES_IRQ(gic_iid(0x6d)),
26846b9a092SKuninori Morimoto };
26946b9a092SKuninori Morimoto 
2701fd4eecdSKuninori Morimoto static void __init r8a7778_register_i2c(int id)
27146b9a092SKuninori Morimoto {
27246b9a092SKuninori Morimoto 	BUG_ON(id < 0 || id > 3);
27346b9a092SKuninori Morimoto 
27446b9a092SKuninori Morimoto 	platform_device_register_simple(
27546b9a092SKuninori Morimoto 		"i2c-rcar", id,
27646b9a092SKuninori Morimoto 		i2c_resources + (2 * id), 2);
27746b9a092SKuninori Morimoto }
27846b9a092SKuninori Morimoto 
2798b89797fSKuninori Morimoto /* HSPI */
2808b89797fSKuninori Morimoto static struct resource hspi_resources[] __initdata = {
2818b89797fSKuninori Morimoto 	/* HSPI0 */
2828b89797fSKuninori Morimoto 	DEFINE_RES_MEM(0xfffc7000, 0x18),
2838b89797fSKuninori Morimoto 	DEFINE_RES_IRQ(gic_iid(0x5f)),
2848b89797fSKuninori Morimoto 	/* HSPI1 */
2858b89797fSKuninori Morimoto 	DEFINE_RES_MEM(0xfffc8000, 0x18),
2868b89797fSKuninori Morimoto 	DEFINE_RES_IRQ(gic_iid(0x74)),
2878b89797fSKuninori Morimoto 	/* HSPI2 */
2888b89797fSKuninori Morimoto 	DEFINE_RES_MEM(0xfffc6000, 0x18),
2898b89797fSKuninori Morimoto 	DEFINE_RES_IRQ(gic_iid(0x75)),
2908b89797fSKuninori Morimoto };
2918b89797fSKuninori Morimoto 
2923c7b5362SKuninori Morimoto void __init r8a7778_register_hspi(int id)
2938b89797fSKuninori Morimoto {
2948b89797fSKuninori Morimoto 	BUG_ON(id < 0 || id > 2);
2958b89797fSKuninori Morimoto 
2968b89797fSKuninori Morimoto 	platform_device_register_simple(
2978b89797fSKuninori Morimoto 		"sh-hspi", id,
2988b89797fSKuninori Morimoto 		hspi_resources + (2 * id), 2);
2998b89797fSKuninori Morimoto }
3008b89797fSKuninori Morimoto 
301803c2df2SVladimir Barinov /* VIN */
302803c2df2SVladimir Barinov #define R8A7778_VIN(idx)						\
303803c2df2SVladimir Barinov static struct resource vin##idx##_resources[] __initdata = {		\
304803c2df2SVladimir Barinov 	DEFINE_RES_MEM(0xffc50000 + 0x1000 * (idx), 0x1000),		\
305803c2df2SVladimir Barinov 	DEFINE_RES_IRQ(gic_iid(0x5a)),					\
306803c2df2SVladimir Barinov };									\
307803c2df2SVladimir Barinov 									\
308803c2df2SVladimir Barinov static struct platform_device_info vin##idx##_info __initdata = {	\
309803c2df2SVladimir Barinov 	.parent		= &platform_bus,				\
310803c2df2SVladimir Barinov 	.name		= "r8a7778-vin",				\
311803c2df2SVladimir Barinov 	.id		= idx,						\
312803c2df2SVladimir Barinov 	.res		= vin##idx##_resources,				\
313803c2df2SVladimir Barinov 	.num_res	= ARRAY_SIZE(vin##idx##_resources),		\
314803c2df2SVladimir Barinov 	.dma_mask	= DMA_BIT_MASK(32),				\
315803c2df2SVladimir Barinov }
316803c2df2SVladimir Barinov 
317803c2df2SVladimir Barinov R8A7778_VIN(0);
318803c2df2SVladimir Barinov R8A7778_VIN(1);
319803c2df2SVladimir Barinov 
320803c2df2SVladimir Barinov static struct platform_device_info *vin_info_table[] __initdata = {
321803c2df2SVladimir Barinov 	&vin0_info,
322803c2df2SVladimir Barinov 	&vin1_info,
323803c2df2SVladimir Barinov };
324803c2df2SVladimir Barinov 
325803c2df2SVladimir Barinov void __init r8a7778_add_vin_device(int id, struct rcar_vin_platform_data *pdata)
326803c2df2SVladimir Barinov {
327803c2df2SVladimir Barinov 	BUG_ON(id < 0 || id > 1);
328803c2df2SVladimir Barinov 
329803c2df2SVladimir Barinov 	vin_info_table[id]->data = pdata;
330803c2df2SVladimir Barinov 	vin_info_table[id]->size_data = sizeof(*pdata);
331803c2df2SVladimir Barinov 
332803c2df2SVladimir Barinov 	platform_device_register_full(vin_info_table[id]);
333803c2df2SVladimir Barinov }
334803c2df2SVladimir Barinov 
335cfa66a81SKuninori Morimoto void __init r8a7778_add_dt_devices(void)
336ccb7cc74SKuninori Morimoto {
337ccb7cc74SKuninori Morimoto 	int i;
338ccb7cc74SKuninori Morimoto 
339ccb7cc74SKuninori Morimoto #ifdef CONFIG_CACHE_L2X0
340ccb7cc74SKuninori Morimoto 	void __iomem *base = ioremap_nocache(0xf0100000, 0x1000);
341ccb7cc74SKuninori Morimoto 	if (base) {
342ccb7cc74SKuninori Morimoto 		/*
343ccb7cc74SKuninori Morimoto 		 * Early BRESP enable, Shared attribute override enable, 64K*16way
344ccb7cc74SKuninori Morimoto 		 * don't call iounmap(base)
345ccb7cc74SKuninori Morimoto 		 */
346ccb7cc74SKuninori Morimoto 		l2x0_init(base, 0x40470000, 0x82000fff);
347ccb7cc74SKuninori Morimoto 	}
348ccb7cc74SKuninori Morimoto #endif
349ccb7cc74SKuninori Morimoto 
350db331fc8SKuninori Morimoto 	for (i = 0; i < ARRAY_SIZE(scif_platform_data); i++)
351db331fc8SKuninori Morimoto 		platform_device_register_data(&platform_bus, "sh-sci", i,
352db331fc8SKuninori Morimoto 					      &scif_platform_data[i],
353db331fc8SKuninori Morimoto 					      sizeof(struct plat_sci_port));
354db331fc8SKuninori Morimoto 
35581484487SKuninori Morimoto 	r8a7778_register_tmu(0);
35681484487SKuninori Morimoto 	r8a7778_register_tmu(1);
357ccb7cc74SKuninori Morimoto }
358ccb7cc74SKuninori Morimoto 
359cfa66a81SKuninori Morimoto void __init r8a7778_add_standard_devices(void)
360cfa66a81SKuninori Morimoto {
361cfa66a81SKuninori Morimoto 	r8a7778_add_dt_devices();
3621fd4eecdSKuninori Morimoto 	r8a7778_register_i2c(0);
3631fd4eecdSKuninori Morimoto 	r8a7778_register_i2c(1);
3641fd4eecdSKuninori Morimoto 	r8a7778_register_i2c(2);
3651fd4eecdSKuninori Morimoto 	r8a7778_register_i2c(3);
3663c7b5362SKuninori Morimoto 	r8a7778_register_hspi(0);
3673c7b5362SKuninori Morimoto 	r8a7778_register_hspi(1);
3683c7b5362SKuninori Morimoto 	r8a7778_register_hspi(2);
369cfa66a81SKuninori Morimoto }
370cfa66a81SKuninori Morimoto 
37102474a41SSergei Shtylyov void __init r8a7778_init_late(void)
37202474a41SSergei Shtylyov {
37302474a41SSergei Shtylyov 	platform_device_register_full(&ehci_info);
37402474a41SSergei Shtylyov 	platform_device_register_full(&ohci_info);
37502474a41SSergei Shtylyov }
37602474a41SSergei Shtylyov 
377c9031fbbSKuninori Morimoto static struct renesas_intc_irqpin_config irqpin_platform_data __initdata = {
3783a42fa20SKuninori Morimoto 	.irq_base = irq_pin(0), /* IRQ0 -> IRQ3 */
3793a42fa20SKuninori Morimoto 	.sense_bitfield_width = 2,
3803a42fa20SKuninori Morimoto };
3813a42fa20SKuninori Morimoto 
382c9031fbbSKuninori Morimoto static struct resource irqpin_resources[] __initdata = {
3833a42fa20SKuninori Morimoto 	DEFINE_RES_MEM(0xfe78001c, 4), /* ICR1 */
3843a42fa20SKuninori Morimoto 	DEFINE_RES_MEM(0xfe780010, 4), /* INTPRI */
3853a42fa20SKuninori Morimoto 	DEFINE_RES_MEM(0xfe780024, 4), /* INTREQ */
3863a42fa20SKuninori Morimoto 	DEFINE_RES_MEM(0xfe780044, 4), /* INTMSK0 */
3873a42fa20SKuninori Morimoto 	DEFINE_RES_MEM(0xfe780064, 4), /* INTMSKCLR0 */
3883a42fa20SKuninori Morimoto 	DEFINE_RES_IRQ(gic_iid(0x3b)), /* IRQ0 */
3893a42fa20SKuninori Morimoto 	DEFINE_RES_IRQ(gic_iid(0x3c)), /* IRQ1 */
3903a42fa20SKuninori Morimoto 	DEFINE_RES_IRQ(gic_iid(0x3d)), /* IRQ2 */
3913a42fa20SKuninori Morimoto 	DEFINE_RES_IRQ(gic_iid(0x3e)), /* IRQ3 */
3923a42fa20SKuninori Morimoto };
3933a42fa20SKuninori Morimoto 
3943a42fa20SKuninori Morimoto void __init r8a7778_init_irq_extpin(int irlm)
3953a42fa20SKuninori Morimoto {
3963a42fa20SKuninori Morimoto 	void __iomem *icr0 = ioremap_nocache(0xfe780000, PAGE_SIZE);
3973a42fa20SKuninori Morimoto 	unsigned long tmp;
3983a42fa20SKuninori Morimoto 
3993a42fa20SKuninori Morimoto 	if (!icr0) {
4003a42fa20SKuninori Morimoto 		pr_warn("r8a7778: unable to setup external irq pin mode\n");
4013a42fa20SKuninori Morimoto 		return;
4023a42fa20SKuninori Morimoto 	}
4033a42fa20SKuninori Morimoto 
4043a42fa20SKuninori Morimoto 	tmp = ioread32(icr0);
4053a42fa20SKuninori Morimoto 	if (irlm)
4063a42fa20SKuninori Morimoto 		tmp |= 1 << 23; /* IRQ0 -> IRQ3 as individual pins */
4073a42fa20SKuninori Morimoto 	else
4083a42fa20SKuninori Morimoto 		tmp &= ~(1 << 23); /* IRL mode - not supported */
4093a42fa20SKuninori Morimoto 	tmp |= (1 << 21); /* LVLMODE = 1 */
4103a42fa20SKuninori Morimoto 	iowrite32(tmp, icr0);
4113a42fa20SKuninori Morimoto 	iounmap(icr0);
4123a42fa20SKuninori Morimoto 
4133a42fa20SKuninori Morimoto 	if (irlm)
4143a42fa20SKuninori Morimoto 		platform_device_register_resndata(
4153a42fa20SKuninori Morimoto 			&platform_bus, "renesas_intc_irqpin", -1,
4163a42fa20SKuninori Morimoto 			irqpin_resources, ARRAY_SIZE(irqpin_resources),
4173a42fa20SKuninori Morimoto 			&irqpin_platform_data, sizeof(irqpin_platform_data));
4183a42fa20SKuninori Morimoto }
4193a42fa20SKuninori Morimoto 
42054aa4c48SKuninori Morimoto void __init r8a7778_init_delay(void)
42154aa4c48SKuninori Morimoto {
42254aa4c48SKuninori Morimoto 	shmobile_setup_delay(800, 1, 3); /* Cortex-A9 @ 800MHz */
42354aa4c48SKuninori Morimoto }
42454aa4c48SKuninori Morimoto 
42554aa4c48SKuninori Morimoto #ifdef CONFIG_USE_OF
426ccb7cc74SKuninori Morimoto #define INT2SMSKCR0	0x82288 /* 0xfe782288 */
427ccb7cc74SKuninori Morimoto #define INT2SMSKCR1	0x8228c /* 0xfe78228c */
428ccb7cc74SKuninori Morimoto 
429ccb7cc74SKuninori Morimoto #define INT2NTSR0	0x00018 /* 0xfe700018 */
430ccb7cc74SKuninori Morimoto #define INT2NTSR1	0x0002c /* 0xfe70002c */
43154aa4c48SKuninori Morimoto void __init r8a7778_init_irq_dt(void)
432ccb7cc74SKuninori Morimoto {
433ccb7cc74SKuninori Morimoto 	void __iomem *base = ioremap_nocache(0xfe700000, 0x00100000);
434ccb7cc74SKuninori Morimoto 
435ccb7cc74SKuninori Morimoto 	BUG_ON(!base);
436ccb7cc74SKuninori Morimoto 
43754aa4c48SKuninori Morimoto 	irqchip_init();
43854aa4c48SKuninori Morimoto 
439ccb7cc74SKuninori Morimoto 	/* route all interrupts to ARM */
440ccb7cc74SKuninori Morimoto 	__raw_writel(0x73ffffff, base + INT2NTSR0);
441ccb7cc74SKuninori Morimoto 	__raw_writel(0xffffffff, base + INT2NTSR1);
442ccb7cc74SKuninori Morimoto 
443ccb7cc74SKuninori Morimoto 	/* unmask all known interrupts in INTCS2 */
444ccb7cc74SKuninori Morimoto 	__raw_writel(0x08330773, base + INT2SMSKCR0);
445ccb7cc74SKuninori Morimoto 	__raw_writel(0x00311110, base + INT2SMSKCR1);
446ccb7cc74SKuninori Morimoto 
447ccb7cc74SKuninori Morimoto 	iounmap(base);
448ccb7cc74SKuninori Morimoto }
449ccb7cc74SKuninori Morimoto 
450ccb7cc74SKuninori Morimoto static const char *r8a7778_compat_dt[] __initdata = {
451ccb7cc74SKuninori Morimoto 	"renesas,r8a7778",
452ccb7cc74SKuninori Morimoto 	NULL,
453ccb7cc74SKuninori Morimoto };
454ccb7cc74SKuninori Morimoto 
455ccb7cc74SKuninori Morimoto DT_MACHINE_START(R8A7778_DT, "Generic R8A7778 (Flattened Device Tree)")
456ccb7cc74SKuninori Morimoto 	.init_early	= r8a7778_init_delay,
457ccb7cc74SKuninori Morimoto 	.init_irq	= r8a7778_init_irq_dt,
458ccb7cc74SKuninori Morimoto 	.dt_compat	= r8a7778_compat_dt,
45902474a41SSergei Shtylyov 	.init_late      = r8a7778_init_late,
460ccb7cc74SKuninori Morimoto MACHINE_END
461ccb7cc74SKuninori Morimoto 
462ccb7cc74SKuninori Morimoto #endif /* CONFIG_USE_OF */
463