[go: nahoru, domu]

11b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan/*
21b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan * Interrupt driver for RICOH583 power management chip.
31b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan *
41b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan * Copyright (c) 2011-2012, NVIDIA CORPORATION.  All rights reserved.
51b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan * Author: Laxman dewangan <ldewangan@nvidia.com>
61b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan *
71b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan * based on code
81b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan *      Copyright (C) 2011 RICOH COMPANY,LTD
91b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan *
101b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan * This program is free software; you can redistribute it and/or modify it
111b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan * under the terms and conditions of the GNU General Public License,
121b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan * version 2, as published by the Free Software Foundation.
131b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan *
141b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan * This program is distributed in the hope it will be useful, but WITHOUT
151b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
161b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
171b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan * more details.
181b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan *
191b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan * You should have received a copy of the GNU General Public License
201b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan * along with this program.  If not, see <http://www.gnu.org/licenses/>.
211b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan *
221b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan */
231b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan#include <linux/interrupt.h>
241b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan#include <linux/irq.h>
251b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan#include <linux/i2c.h>
261b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan#include <linux/mfd/rc5t583.h>
271b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
281b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewanganenum int_type {
291b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	SYS_INT  = 0x1,
301b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	DCDC_INT = 0x2,
311b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	RTC_INT  = 0x4,
321b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	ADC_INT  = 0x8,
331b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	GPIO_INT = 0x10,
341b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan};
351b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
361b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewanganstatic int gpedge_add[] = {
371b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	RC5T583_GPIO_GPEDGE2,
381b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	RC5T583_GPIO_GPEDGE2
391b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan};
401b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
411b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewanganstatic int irq_en_add[] = {
421b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	RC5T583_INT_EN_SYS1,
431b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	RC5T583_INT_EN_SYS2,
441b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	RC5T583_INT_EN_DCDC,
451b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	RC5T583_INT_EN_RTC,
461b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	RC5T583_INT_EN_ADC1,
471b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	RC5T583_INT_EN_ADC2,
481b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	RC5T583_INT_EN_ADC3,
491b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	RC5T583_GPIO_EN_INT
501b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan};
511b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
521b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewanganstatic int irq_mon_add[] = {
531b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	RC5T583_INT_MON_SYS1,
541b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	RC5T583_INT_MON_SYS2,
551b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	RC5T583_INT_MON_DCDC,
561b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	RC5T583_INT_MON_RTC,
571b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	RC5T583_INT_IR_ADCL,
581b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	RC5T583_INT_IR_ADCH,
591b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	RC5T583_INT_IR_ADCEND,
601b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	RC5T583_INT_IR_GPIOF,
611b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	RC5T583_INT_IR_GPIOR
621b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan};
631b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
641b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewanganstatic int irq_clr_add[] = {
651b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	RC5T583_INT_IR_SYS1,
661b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	RC5T583_INT_IR_SYS2,
671b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	RC5T583_INT_IR_DCDC,
681b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	RC5T583_INT_IR_RTC,
691b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	RC5T583_INT_IR_ADCL,
701b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	RC5T583_INT_IR_ADCH,
711b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	RC5T583_INT_IR_ADCEND,
721b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	RC5T583_INT_IR_GPIOF,
731b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	RC5T583_INT_IR_GPIOR
741b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan};
751b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
761b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewanganstatic int main_int_type[] = {
771b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	SYS_INT,
781b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	SYS_INT,
791b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	DCDC_INT,
801b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	RTC_INT,
811b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	ADC_INT,
821b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	ADC_INT,
831b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	ADC_INT,
841b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	GPIO_INT,
851b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	GPIO_INT,
861b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan};
871b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
881b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewanganstruct rc5t583_irq_data {
891b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	u8	int_type;
901b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	u8	master_bit;
911b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	u8	int_en_bit;
921b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	u8	mask_reg_index;
931b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	int	grp_index;
941b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan};
951b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
961b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan#define RC5T583_IRQ(_int_type, _master_bit, _grp_index, \
971b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan			_int_bit, _mask_ind)		\
981b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	{						\
991b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan		.int_type	= _int_type,		\
1001b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan		.master_bit	= _master_bit,		\
1011b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan		.grp_index	= _grp_index,		\
1021b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan		.int_en_bit	= _int_bit,		\
1031b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan		.mask_reg_index	= _mask_ind,		\
1041b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	}
1051b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
1061b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewanganstatic const struct rc5t583_irq_data rc5t583_irqs[RC5T583_MAX_IRQS] = {
1071b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	[RC5T583_IRQ_ONKEY]		= RC5T583_IRQ(SYS_INT,  0, 0, 0, 0),
1081b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	[RC5T583_IRQ_ACOK]		= RC5T583_IRQ(SYS_INT,  0, 1, 1, 0),
1091b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	[RC5T583_IRQ_LIDOPEN]		= RC5T583_IRQ(SYS_INT,  0, 2, 2, 0),
1101b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	[RC5T583_IRQ_PREOT]		= RC5T583_IRQ(SYS_INT,  0, 3, 3, 0),
1111b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	[RC5T583_IRQ_CLKSTP]		= RC5T583_IRQ(SYS_INT,  0, 4, 4, 0),
1121b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	[RC5T583_IRQ_ONKEY_OFF]		= RC5T583_IRQ(SYS_INT,  0, 5, 5, 0),
1131b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	[RC5T583_IRQ_WD]		= RC5T583_IRQ(SYS_INT,  0, 7, 7, 0),
1141b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	[RC5T583_IRQ_EN_PWRREQ1]	= RC5T583_IRQ(SYS_INT,  0, 8, 0, 1),
1151b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	[RC5T583_IRQ_EN_PWRREQ2]	= RC5T583_IRQ(SYS_INT,  0, 9, 1, 1),
1161b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	[RC5T583_IRQ_PRE_VINDET]	= RC5T583_IRQ(SYS_INT,  0, 10, 2, 1),
1171b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
1181b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	[RC5T583_IRQ_DC0LIM]		= RC5T583_IRQ(DCDC_INT, 1, 0, 0, 2),
1191b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	[RC5T583_IRQ_DC1LIM]		= RC5T583_IRQ(DCDC_INT, 1, 1, 1, 2),
1201b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	[RC5T583_IRQ_DC2LIM]		= RC5T583_IRQ(DCDC_INT, 1, 2, 2, 2),
1211b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	[RC5T583_IRQ_DC3LIM]		= RC5T583_IRQ(DCDC_INT, 1, 3, 3, 2),
1221b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
1231b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	[RC5T583_IRQ_CTC]		= RC5T583_IRQ(RTC_INT,  2, 0, 0, 3),
1241b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	[RC5T583_IRQ_YALE]		= RC5T583_IRQ(RTC_INT,  2, 5, 5, 3),
1251b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	[RC5T583_IRQ_DALE]		= RC5T583_IRQ(RTC_INT,  2, 6, 6, 3),
1261b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	[RC5T583_IRQ_WALE]		= RC5T583_IRQ(RTC_INT,  2, 7, 7, 3),
1271b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
1281b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	[RC5T583_IRQ_AIN1L]		= RC5T583_IRQ(ADC_INT,  3, 0, 0, 4),
1291b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	[RC5T583_IRQ_AIN2L]		= RC5T583_IRQ(ADC_INT,  3, 1, 1, 4),
1301b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	[RC5T583_IRQ_AIN3L]		= RC5T583_IRQ(ADC_INT,  3, 2, 2, 4),
1311b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	[RC5T583_IRQ_VBATL]		= RC5T583_IRQ(ADC_INT,  3, 3, 3, 4),
1321b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	[RC5T583_IRQ_VIN3L]		= RC5T583_IRQ(ADC_INT,  3, 4, 4, 4),
1331b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	[RC5T583_IRQ_VIN8L]		= RC5T583_IRQ(ADC_INT,  3, 5, 5, 4),
1341b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	[RC5T583_IRQ_AIN1H]		= RC5T583_IRQ(ADC_INT,  3, 6, 0, 5),
1351b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	[RC5T583_IRQ_AIN2H]		= RC5T583_IRQ(ADC_INT,  3, 7, 1, 5),
1361b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	[RC5T583_IRQ_AIN3H]		= RC5T583_IRQ(ADC_INT,  3, 8, 2, 5),
1371b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	[RC5T583_IRQ_VBATH]		= RC5T583_IRQ(ADC_INT,  3, 9, 3, 5),
1381b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	[RC5T583_IRQ_VIN3H]		= RC5T583_IRQ(ADC_INT,  3, 10, 4, 5),
1391b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	[RC5T583_IRQ_VIN8H]		= RC5T583_IRQ(ADC_INT,  3, 11, 5, 5),
1401b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	[RC5T583_IRQ_ADCEND]		= RC5T583_IRQ(ADC_INT,  3, 12, 0, 6),
1411b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
1421b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	[RC5T583_IRQ_GPIO0]		= RC5T583_IRQ(GPIO_INT, 4, 0, 0, 7),
1431b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	[RC5T583_IRQ_GPIO1]		= RC5T583_IRQ(GPIO_INT, 4, 1, 1, 7),
1441b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	[RC5T583_IRQ_GPIO2]		= RC5T583_IRQ(GPIO_INT, 4, 2, 2, 7),
1451b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	[RC5T583_IRQ_GPIO3]		= RC5T583_IRQ(GPIO_INT, 4, 3, 3, 7),
1461b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	[RC5T583_IRQ_GPIO4]		= RC5T583_IRQ(GPIO_INT, 4, 4, 4, 7),
1471b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	[RC5T583_IRQ_GPIO5]		= RC5T583_IRQ(GPIO_INT, 4, 5, 5, 7),
1481b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	[RC5T583_IRQ_GPIO6]		= RC5T583_IRQ(GPIO_INT, 4, 6, 6, 7),
1491b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	[RC5T583_IRQ_GPIO7]		= RC5T583_IRQ(GPIO_INT, 4, 7, 7, 7),
1501b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan};
1511b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
1521b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewanganstatic void rc5t583_irq_lock(struct irq_data *irq_data)
1531b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan{
1541b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	struct rc5t583 *rc5t583 = irq_data_get_irq_chip_data(irq_data);
1551b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	mutex_lock(&rc5t583->irq_lock);
1561b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan}
1571b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
1581b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewanganstatic void rc5t583_irq_unmask(struct irq_data *irq_data)
1591b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan{
1601b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	struct rc5t583 *rc5t583 = irq_data_get_irq_chip_data(irq_data);
1611b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	unsigned int __irq = irq_data->irq - rc5t583->irq_base;
1621b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	const struct rc5t583_irq_data *data = &rc5t583_irqs[__irq];
1631b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
1641b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	rc5t583->group_irq_en[data->grp_index] |= 1 << data->grp_index;
1651b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	rc5t583->intc_inten_reg |= 1 << data->master_bit;
1661b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	rc5t583->irq_en_reg[data->mask_reg_index] |= 1 << data->int_en_bit;
1671b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan}
1681b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
1691b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewanganstatic void rc5t583_irq_mask(struct irq_data *irq_data)
1701b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan{
1711b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	struct rc5t583 *rc5t583 = irq_data_get_irq_chip_data(irq_data);
1721b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	unsigned int __irq = irq_data->irq - rc5t583->irq_base;
1731b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	const struct rc5t583_irq_data *data = &rc5t583_irqs[__irq];
1741b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
1751b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	rc5t583->group_irq_en[data->grp_index] &= ~(1 << data->grp_index);
1761b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	if (!rc5t583->group_irq_en[data->grp_index])
1771b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan		rc5t583->intc_inten_reg &= ~(1 << data->master_bit);
1781b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
1791b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	rc5t583->irq_en_reg[data->mask_reg_index] &= ~(1 << data->int_en_bit);
1801b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan}
1811b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
1821b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewanganstatic int rc5t583_irq_set_type(struct irq_data *irq_data, unsigned int type)
1831b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan{
1841b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	struct rc5t583 *rc5t583 = irq_data_get_irq_chip_data(irq_data);
1851b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	unsigned int __irq = irq_data->irq - rc5t583->irq_base;
1861b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	const struct rc5t583_irq_data *data = &rc5t583_irqs[__irq];
1871b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	int val = 0;
1881b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	int gpedge_index;
1891b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	int gpedge_bit_pos;
1901b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
1911b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	/* Supporting only trigger level inetrrupt */
1921b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	if ((data->int_type & GPIO_INT) && (type & IRQ_TYPE_EDGE_BOTH)) {
1931b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan		gpedge_index = data->int_en_bit / 4;
1941b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan		gpedge_bit_pos = data->int_en_bit % 4;
1951b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
1961b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan		if (type & IRQ_TYPE_EDGE_FALLING)
1971b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan			val |= 0x2;
1981b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
1991b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan		if (type & IRQ_TYPE_EDGE_RISING)
2001b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan			val |= 0x1;
2011b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
2021b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan		rc5t583->gpedge_reg[gpedge_index] &= ~(3 << gpedge_bit_pos);
2031b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan		rc5t583->gpedge_reg[gpedge_index] |= (val << gpedge_bit_pos);
2041b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan		rc5t583_irq_unmask(irq_data);
2051b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan		return 0;
2061b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	}
2071b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	return -EINVAL;
2081b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan}
2091b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
2101b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewanganstatic void rc5t583_irq_sync_unlock(struct irq_data *irq_data)
2111b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan{
2121b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	struct rc5t583 *rc5t583 = irq_data_get_irq_chip_data(irq_data);
2131b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	int i;
2141b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	int ret;
2151b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
2161b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	for (i = 0; i < ARRAY_SIZE(rc5t583->gpedge_reg); i++) {
2171b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan		ret = rc5t583_write(rc5t583->dev, gpedge_add[i],
2181b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan				rc5t583->gpedge_reg[i]);
2191b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan		if (ret < 0)
2201b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan			dev_warn(rc5t583->dev,
2211b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan				"Error in writing reg 0x%02x error: %d\n",
2221b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan				gpedge_add[i], ret);
2231b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	}
2241b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
2251b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	for (i = 0; i < ARRAY_SIZE(rc5t583->irq_en_reg); i++) {
2261b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan		ret = rc5t583_write(rc5t583->dev, irq_en_add[i],
2271b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan					rc5t583->irq_en_reg[i]);
2281b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan		if (ret < 0)
2291b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan			dev_warn(rc5t583->dev,
2301b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan				"Error in writing reg 0x%02x error: %d\n",
2311b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan				irq_en_add[i], ret);
2321b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	}
2331b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
2341b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	ret = rc5t583_write(rc5t583->dev, RC5T583_INTC_INTEN,
2351b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan				rc5t583->intc_inten_reg);
2361b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	if (ret < 0)
2371b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan		dev_warn(rc5t583->dev,
2381b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan			"Error in writing reg 0x%02x error: %d\n",
2391b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan			RC5T583_INTC_INTEN, ret);
2401b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
2411b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	mutex_unlock(&rc5t583->irq_lock);
2421b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan}
2431b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan#ifdef CONFIG_PM_SLEEP
2441b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewanganstatic int rc5t583_irq_set_wake(struct irq_data *irq_data, unsigned int on)
2451b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan{
2461b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	struct rc5t583 *rc5t583 = irq_data_get_irq_chip_data(irq_data);
2471b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	return irq_set_irq_wake(rc5t583->chip_irq, on);
2481b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan}
2491b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan#else
2501b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan#define rc5t583_irq_set_wake NULL
2511b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan#endif
2521b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
2531b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewanganstatic irqreturn_t rc5t583_irq(int irq, void *data)
2541b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan{
2551b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	struct rc5t583 *rc5t583 = data;
2561b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	uint8_t int_sts[RC5T583_MAX_INTERRUPT_MASK_REGS];
2570dd96360e21ec7963aeba253261db87a32e728c6Venu Byravarasu	uint8_t master_int = 0;
2581b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	int i;
2591b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	int ret;
2601b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	unsigned int rtc_int_sts = 0;
2611b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
2621b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	/* Clear the status */
2631b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	for (i = 0; i < RC5T583_MAX_INTERRUPT_MASK_REGS; i++)
2641b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan		int_sts[i] = 0;
2651b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
2661b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	ret  = rc5t583_read(rc5t583->dev, RC5T583_INTC_INTMON, &master_int);
2671b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	if (ret < 0) {
2681b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan		dev_err(rc5t583->dev,
2691b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan			"Error in reading reg 0x%02x error: %d\n",
2701b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan			RC5T583_INTC_INTMON, ret);
2711b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan		return IRQ_HANDLED;
2721b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	}
2731b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
2741b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	for (i = 0; i < RC5T583_MAX_INTERRUPT_MASK_REGS; ++i) {
2751b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan		if (!(master_int & main_int_type[i]))
2761b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan			continue;
2771b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
2781b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan		ret = rc5t583_read(rc5t583->dev, irq_mon_add[i], &int_sts[i]);
2791b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan		if (ret < 0) {
2801b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan			dev_warn(rc5t583->dev,
2811b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan				"Error in reading reg 0x%02x error: %d\n",
2821b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan				irq_mon_add[i], ret);
2831b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan			int_sts[i] = 0;
2841b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan			continue;
2851b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan		}
2861b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
2871b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan		if (main_int_type[i] & RTC_INT) {
2881b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan			rtc_int_sts = 0;
2891b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan			if (int_sts[i] & 0x1)
2901b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan				rtc_int_sts |= BIT(6);
2911b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan			if (int_sts[i] & 0x2)
2921b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan				rtc_int_sts |= BIT(7);
2931b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan			if (int_sts[i] & 0x4)
2941b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan				rtc_int_sts |= BIT(0);
2951b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan			if (int_sts[i] & 0x8)
2961b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan				rtc_int_sts |= BIT(5);
2971b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan		}
2981b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
2991b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan		ret = rc5t583_write(rc5t583->dev, irq_clr_add[i],
3001b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan				~int_sts[i]);
3011b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan		if (ret < 0)
3021b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan			dev_warn(rc5t583->dev,
3031b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan				"Error in reading reg 0x%02x error: %d\n",
3041b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan				irq_clr_add[i], ret);
3051b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
3061b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan		if (main_int_type[i] & RTC_INT)
3071b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan			int_sts[i] = rtc_int_sts;
3081b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	}
3091b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
3101b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	/* Merge gpio interrupts for rising and falling case*/
3111b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	int_sts[7] |= int_sts[8];
3121b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
3131b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	/* Call interrupt handler if enabled */
3141b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	for (i = 0; i < RC5T583_MAX_IRQS; ++i) {
3151b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan		const struct rc5t583_irq_data *data = &rc5t583_irqs[i];
3161b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan		if ((int_sts[data->mask_reg_index] & (1 << data->int_en_bit)) &&
3171b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan			(rc5t583->group_irq_en[data->master_bit] &
3181b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan					(1 << data->grp_index)))
3191b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan			handle_nested_irq(rc5t583->irq_base + i);
3201b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	}
3211b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
3221b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	return IRQ_HANDLED;
3231b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan}
3241b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
3251b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewanganstatic struct irq_chip rc5t583_irq_chip = {
3261b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	.name = "rc5t583-irq",
3271b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	.irq_mask = rc5t583_irq_mask,
3281b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	.irq_unmask = rc5t583_irq_unmask,
3291b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	.irq_bus_lock = rc5t583_irq_lock,
3301b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	.irq_bus_sync_unlock = rc5t583_irq_sync_unlock,
3311b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	.irq_set_type = rc5t583_irq_set_type,
3321b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	.irq_set_wake = rc5t583_irq_set_wake,
3331b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan};
3341b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
3351b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewanganint rc5t583_irq_init(struct rc5t583 *rc5t583, int irq, int irq_base)
3361b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan{
3371b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	int i, ret;
3381b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
3391b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	if (!irq_base) {
3401b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan		dev_warn(rc5t583->dev, "No interrupt support on IRQ base\n");
3411b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan		return -EINVAL;
3421b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	}
3431b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
3441b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	mutex_init(&rc5t583->irq_lock);
3451b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
3461b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	/* Initailize all int register to 0 */
3473f9be35bd9090eaa2f68ed9b24efdbf3abcf4b28Axel Lin	for (i = 0; i < RC5T583_MAX_INTERRUPT_EN_REGS; i++)  {
3481b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan		ret = rc5t583_write(rc5t583->dev, irq_en_add[i],
3491b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan				rc5t583->irq_en_reg[i]);
3501b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan		if (ret < 0)
3511b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan			dev_warn(rc5t583->dev,
3521b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan				"Error in writing reg 0x%02x error: %d\n",
3531b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan				irq_en_add[i], ret);
3541b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	}
3551b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
3561b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	for (i = 0; i < RC5T583_MAX_GPEDGE_REG; i++)  {
3571b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan		ret = rc5t583_write(rc5t583->dev, gpedge_add[i],
3581b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan				rc5t583->gpedge_reg[i]);
3591b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan		if (ret < 0)
3601b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan			dev_warn(rc5t583->dev,
3611b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan				"Error in writing reg 0x%02x error: %d\n",
3621b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan				gpedge_add[i], ret);
3631b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	}
3641b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
3651b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	ret = rc5t583_write(rc5t583->dev, RC5T583_INTC_INTEN, 0x0);
3661b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	if (ret < 0)
3671b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan		dev_warn(rc5t583->dev,
3681b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan			"Error in writing reg 0x%02x error: %d\n",
3691b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan			RC5T583_INTC_INTEN, ret);
3701b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
3711b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	/* Clear all interrupts in case they woke up active. */
3721b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	for (i = 0; i < RC5T583_MAX_INTERRUPT_MASK_REGS; i++)  {
3731b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan		ret = rc5t583_write(rc5t583->dev, irq_clr_add[i], 0);
3741b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan		if (ret < 0)
3751b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan			dev_warn(rc5t583->dev,
3761b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan				"Error in writing reg 0x%02x error: %d\n",
3771b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan				irq_clr_add[i], ret);
3781b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	}
3791b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
3801b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	rc5t583->irq_base = irq_base;
3811b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	rc5t583->chip_irq = irq;
3821b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
3831b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	for (i = 0; i < RC5T583_MAX_IRQS; i++) {
3841b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan		int __irq = i + rc5t583->irq_base;
3851b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan		irq_set_chip_data(__irq, rc5t583);
3861b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan		irq_set_chip_and_handler(__irq, &rc5t583_irq_chip,
3871b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan					 handle_simple_irq);
3881b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan		irq_set_nested_thread(__irq, 1);
3891b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan#ifdef CONFIG_ARM
3901b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan		set_irq_flags(__irq, IRQF_VALID);
3911b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan#endif
3921b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	}
3931b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
3941b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	ret = request_threaded_irq(irq, NULL, rc5t583_irq, IRQF_ONESHOT,
3951b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan				"rc5t583", rc5t583);
3961b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	if (ret < 0)
3971b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan		dev_err(rc5t583->dev,
3981b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan			"Error in registering interrupt error: %d\n", ret);
3991b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	return ret;
4001b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan}
4011b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan
4021b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewanganint rc5t583_irq_exit(struct rc5t583 *rc5t583)
4031b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan{
4041b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	if (rc5t583->chip_irq)
4051b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan		free_irq(rc5t583->chip_irq, rc5t583);
4061b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan	return 0;
4071b1247dd75aa5cf5fae54a3bec7280046e9c7957Laxman Dewangan}
408