162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Renesas Solutions Highlander R7785RP Support.
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Copyright (C) 2002  Atom Create Engineering Co., Ltd.
662306a36Sopenharmony_ci * Copyright (C) 2006 - 2008  Paul Mundt
762306a36Sopenharmony_ci * Copyright (C) 2007  Magnus Damm
862306a36Sopenharmony_ci */
962306a36Sopenharmony_ci#include <linux/init.h>
1062306a36Sopenharmony_ci#include <linux/irq.h>
1162306a36Sopenharmony_ci#include <linux/io.h>
1262306a36Sopenharmony_ci#include <mach/highlander.h>
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_cienum {
1562306a36Sopenharmony_ci	UNUSED = 0,
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ci	/* FPGA specific interrupt sources */
1862306a36Sopenharmony_ci	CF,		/* Compact Flash */
1962306a36Sopenharmony_ci	SMBUS,		/* SMBUS */
2062306a36Sopenharmony_ci	TP,		/* Touch panel */
2162306a36Sopenharmony_ci	RTC,		/* RTC Alarm */
2262306a36Sopenharmony_ci	TH_ALERT,	/* Temperature sensor */
2362306a36Sopenharmony_ci	AX88796,	/* Ethernet controller */
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_ci	/* external bus connector */
2662306a36Sopenharmony_ci	EXT0, EXT1, EXT2, EXT3, EXT4, EXT5, EXT6, EXT7,
2762306a36Sopenharmony_ci};
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_cistatic struct intc_vect vectors[] __initdata = {
3062306a36Sopenharmony_ci	INTC_IRQ(CF, IRQ_CF),
3162306a36Sopenharmony_ci	INTC_IRQ(SMBUS, IRQ_SMBUS),
3262306a36Sopenharmony_ci	INTC_IRQ(TP, IRQ_TP),
3362306a36Sopenharmony_ci	INTC_IRQ(RTC, IRQ_RTC),
3462306a36Sopenharmony_ci	INTC_IRQ(TH_ALERT, IRQ_TH_ALERT),
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_ci	INTC_IRQ(EXT0, IRQ_EXT0), INTC_IRQ(EXT1, IRQ_EXT1),
3762306a36Sopenharmony_ci	INTC_IRQ(EXT2, IRQ_EXT2), INTC_IRQ(EXT3, IRQ_EXT3),
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_ci	INTC_IRQ(EXT4, IRQ_EXT4), INTC_IRQ(EXT5, IRQ_EXT5),
4062306a36Sopenharmony_ci	INTC_IRQ(EXT6, IRQ_EXT6), INTC_IRQ(EXT7, IRQ_EXT7),
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci	INTC_IRQ(AX88796, IRQ_AX88796),
4362306a36Sopenharmony_ci};
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_cistatic struct intc_mask_reg mask_registers[] __initdata = {
4662306a36Sopenharmony_ci	{ 0xa4000010, 0, 16, /* IRLMCR1 */
4762306a36Sopenharmony_ci	  { 0, 0, 0, 0, CF, AX88796, SMBUS, TP,
4862306a36Sopenharmony_ci	    RTC, 0, TH_ALERT, 0, 0, 0, 0, 0 } },
4962306a36Sopenharmony_ci	{ 0xa4000012, 0, 16, /* IRLMCR2 */
5062306a36Sopenharmony_ci	  { 0, 0, 0, 0, 0, 0, 0, 0,
5162306a36Sopenharmony_ci	    EXT7, EXT6, EXT5, EXT4, EXT3, EXT2, EXT1, EXT0 } },
5262306a36Sopenharmony_ci};
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_cistatic unsigned char irl2irq[HL_NR_IRL] __initdata = {
5562306a36Sopenharmony_ci	0, IRQ_CF, IRQ_EXT4, IRQ_EXT5,
5662306a36Sopenharmony_ci	IRQ_EXT6, IRQ_EXT7, IRQ_SMBUS, IRQ_TP,
5762306a36Sopenharmony_ci	IRQ_RTC, IRQ_TH_ALERT, IRQ_AX88796, IRQ_EXT0,
5862306a36Sopenharmony_ci	IRQ_EXT1, IRQ_EXT2, IRQ_EXT3,
5962306a36Sopenharmony_ci};
6062306a36Sopenharmony_ci
6162306a36Sopenharmony_cistatic DECLARE_INTC_DESC(intc_desc, "r7785rp", vectors,
6262306a36Sopenharmony_ci			 NULL, mask_registers, NULL, NULL);
6362306a36Sopenharmony_ci
6462306a36Sopenharmony_ciunsigned char * __init highlander_plat_irq_setup(void)
6562306a36Sopenharmony_ci{
6662306a36Sopenharmony_ci	if ((__raw_readw(0xa4000158) & 0xf000) != 0x1000)
6762306a36Sopenharmony_ci		return NULL;
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_ci	printk(KERN_INFO "Using r7785rp interrupt controller.\n");
7062306a36Sopenharmony_ci
7162306a36Sopenharmony_ci	__raw_writew(0x0000, PA_IRLSSR1);	/* FPGA IRLSSR1(CF_CD clear) */
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_ci	/* Setup the FPGA IRL */
7462306a36Sopenharmony_ci	__raw_writew(0x0000, PA_IRLPRA);	/* FPGA IRLA */
7562306a36Sopenharmony_ci	__raw_writew(0xe598, PA_IRLPRB);	/* FPGA IRLB */
7662306a36Sopenharmony_ci	__raw_writew(0x7060, PA_IRLPRC);	/* FPGA IRLC */
7762306a36Sopenharmony_ci	__raw_writew(0x0000, PA_IRLPRD);	/* FPGA IRLD */
7862306a36Sopenharmony_ci	__raw_writew(0x4321, PA_IRLPRE);	/* FPGA IRLE */
7962306a36Sopenharmony_ci	__raw_writew(0xdcba, PA_IRLPRF);	/* FPGA IRLF */
8062306a36Sopenharmony_ci
8162306a36Sopenharmony_ci	register_intc_controller(&intc_desc);
8262306a36Sopenharmony_ci	return irl2irq;
8362306a36Sopenharmony_ci}
84