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