blob: dcb17e5480fcb6b5e1f11d2b2649e9ce4b7166a7 [file] [log] [blame]
/*
* s2mu106-irq.c - Interrupt controller support for s2mu106
*
* Copyright (C) 2018 Samsung Electronics Co.Ltd
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <linux/irq.h>
#include <linux/interrupt.h>
#include <linux/gpio.h>
#include <linux/mfd/samsung/s2mu106.h>
#include <linux/err.h>
/* TODO : add IP Header file include*/
#if defined(CONFIG_CHARGER_S2MU106)
#include "../battery_v2/include/charger/s2mu106_charger.h"
#endif
#if defined(CONFIG_MUIC_S2MU106)
#include <linux/muic/s2mu106-muic.h>
#endif
#if defined(CONFIG_PM_S2MU106)
#include "../battery_v2/include/s2mu106_pmeter.h"
#endif
#if defined(CONFIG_LEDS_S2MU106_FLASH)
#include <linux/leds-s2mu106.h>
#endif
#if defined(CONFIG_MOTOR_S2MU106)
#include <linux/s2mu106_haptic.h>
#endif
static const u8 s2mu106_mask_reg[] = {
#if defined(CONFIG_CHARGER_S2MU106)
[CHG_INT1] = S2MU106_CHG_INT1M,
[CHG_INT2] = S2MU106_CHG_INT2M,
[CHG_INT3] = S2MU106_CHG_INT3M,
#endif
#if defined(CONFIG_LEDS_S2MU106_FLASH)
[FLED_INT1] = S2MU106_FLED_INT1_MASK,
[FLED_INT2] = S2MU106_FLED_INT2_MASK,
#endif
#if defined(CONFIG_HV_MUIC_S2MU106_AFC)
[AFC_INT] = S2MU106_REG_AFC_INT,
#endif
#if defined(CONFIG_MUIC_S2MU106)
[MUIC_INT1] = S2MU106_REG_MUIC_INT1,
[MUIC_INT2] = S2MU106_REG_MUIC_INT2,
#endif
#if defined(CONFIG_PM_S2MU106)
[PM_VALUP1] = S2MU106_PM_VALUP1_MASK,
[PM_VALUP2] = S2MU106_PM_VALUP2_MASK,
[PM_INT1] = S2MU106_PM_INT1_MASK,
[PM_INT2] = S2MU106_PM_INT2_MASK,
#endif
#if defined(CONFIG_MOTOR_S2MU106)
[HAPTIC_INT] = S2MU106_REG_HAPTIC_INT_MASK,
#endif
};
struct s2mu106_irq_data {
int mask;
enum s2mu106_irq_source group;
};
static struct i2c_client *get_i2c(struct s2mu106_dev *s2mu106,
enum s2mu106_irq_source src)
{
switch (src) {
#if defined(CONFIG_CHARGER_S2MU106)
case CHG_INT1 ... CHG_INT3:
return s2mu106->i2c;
#endif
#if defined(CONFIG_LEDS_S2MU106_FLASH)
case FLED_INT1 ... FLED_INT2:
return s2mu106->i2c;
#endif
#if defined(CONFIG_HV_MUIC_S2MU106_AFC)
case AFC_INT:
return s2mu106->muic;
#endif
#if defined(CONFIG_MUIC_S2MU106)
case MUIC_INT1 ... MUIC_INT2:
return s2mu106->muic;
#endif
#if defined(CONFIG_PM_S2MU106)
case PM_VALUP1 ... PM_INT2:
return s2mu106->muic;
#endif
#if defined(CONFIG_MST_S2MU106)
case MST_INT:
return s2mu106->muic;
#endif
#if defined(CONFIG_MOTOR_S2MU106)
case HAPTIC_INT:
return s2mu106->haptic;
#endif
#if defined(CONFIG_REGULATOR_S2MU106)
case HBST_INT:
return s2mu106->haptic;
#endif
default:
return ERR_PTR(-EINVAL);
}
}
#define DECLARE_IRQ(idx, _group, _mask) \
[(idx)] = { .group = (_group), .mask = (_mask) }
static const struct s2mu106_irq_data s2mu106_irqs[] = {
#if defined(CONFIG_CHARGER_S2MU106)
DECLARE_IRQ(S2MU106_CHG1_IRQ_SYS, CHG_INT1, 1 << 0),
DECLARE_IRQ(S2MU106_CHG1_IRQ_CV, CHG_INT1, 1 << 1),
DECLARE_IRQ(S2MU106_CHG1_IRQ_CHG_Fault, CHG_INT1, 1 << 2),
DECLARE_IRQ(S2MU106_CHG1_IRQ_CHG_RSTART, CHG_INT1, 1 << 3),
DECLARE_IRQ(S2MU106_CHG1_IRQ_DONE, CHG_INT1, 1 << 4),
DECLARE_IRQ(S2MU106_CHG1_IRQ_TOP_OFF, CHG_INT1, 1 << 5),
DECLARE_IRQ(S2MU106_CHG1_IRQ_WCIN, CHG_INT1, 1 << 6),
DECLARE_IRQ(S2MU106_CHG1_IRQ_CHGIN, CHG_INT1, 1 << 7),
DECLARE_IRQ(S2MU106_CHG2_IRQ_ICR, CHG_INT2, 1 << 0),
DECLARE_IRQ(S2MU106_CHG2_IRQ_IVR, CHG_INT2, 1 << 1),
DECLARE_IRQ(S2MU106_CHG2_IRQ_AICL, CHG_INT2, 1 << 2),
DECLARE_IRQ(S2MU106_CHG2_IRQ_DET_BAT, CHG_INT2, 1 << 3),
DECLARE_IRQ(S2MU106_CHG2_IRQ_BAT, CHG_INT2, 1 << 4),
DECLARE_IRQ(S2MU106_CHG2_IRQ_BATN_OPEN, CHG_INT2, 1 << 5),
DECLARE_IRQ(S2MU106_CHG2_IRQ_BATP_OPEN, CHG_INT2, 1 << 6),
DECLARE_IRQ(S2MU106_CHG2_IRQ_QBAT_OFF, CHG_INT2, 1 << 7),
DECLARE_IRQ(S2MU106_CHG3_IRQ_BST, CHG_INT3, 1 << 0),
DECLARE_IRQ(S2MU106_CHG3_IRQ_TX, CHG_INT3, 1 << 1),
DECLARE_IRQ(S2MU106_CHG3_IRQ_OTG, CHG_INT3, 1 << 2),
DECLARE_IRQ(S2MU106_CHG3_IRQ_VBUS_Short, CHG_INT3, 1 << 3),
DECLARE_IRQ(S2MU106_CHG3_IRQ_MaxDuty, CHG_INT3, 1 << 4),
DECLARE_IRQ(S2MU106_CHG3_IRQ_PEdone, CHG_INT3, 1 << 5),
DECLARE_IRQ(S2MU106_CHG3_IRQ_BAT_Contact_CK_Done, CHG_INT3, 1 << 6),
#endif
#if defined(CONFIG_LEDS_S2MU106_FLASH)
DECLARE_IRQ(S2MU106_FLED1_IRQ_C2F_Vbyp_ovp_prot, FLED_INT1, 1 << 0),
DECLARE_IRQ(S2MU106_FLED1_IRQ_C2F_Vbyp_OK_Warning, FLED_INT1, 1 << 1),
DECLARE_IRQ(S2MU106_FLED1_IRQ_OPEN_CH3, FLED_INT1, 1 << 2),
DECLARE_IRQ(S2MU106_FLED1_IRQ_OPEN_CH2, FLED_INT1, 1 << 3),
DECLARE_IRQ(S2MU106_FLED1_IRQ_OPEN_CH1, FLED_INT1, 1 << 4),
DECLARE_IRQ(S2MU106_FLED1_IRQ_SHORT_CH3, FLED_INT1, 1 << 5),
DECLARE_IRQ(S2MU106_FLED1_IRQ_SHORT_CH2, FLED_INT1, 1 << 6),
DECLARE_IRQ(S2MU106_FLED1_IRQ_SHORT_CH1, FLED_INT1, 1 << 7),
DECLARE_IRQ(S2MU106_FLED2_IRQ_CH3_ON, FLED_INT2, 1 << 2),
DECLARE_IRQ(S2MU106_FLED2_IRQ_CH2_ON, FLED_INT2, 1 << 3),
DECLARE_IRQ(S2MU106_FLED2_IRQ_CH1_ON, FLED_INT2, 1 << 4),
DECLARE_IRQ(S2MU106_FLED2_IRQ_TORCH_ON, FLED_INT2, 1 << 6),
DECLARE_IRQ(S2MU106_FLED2_IRQ_LED_ON_TA_Detach, FLED_INT2, 1 << 7),
#endif
#if defined(CONFIG_HV_MUIC_S2MU106_AFC)
DECLARE_IRQ(S2MU106_AFC_IRQ_VbADC, AFC_INT, 1 << 0),
DECLARE_IRQ(S2MU106_AFC_IRQ_VDNMon, AFC_INT, 1 << 1),
DECLARE_IRQ(S2MU106_AFC_IRQ_DNRes, AFC_INT, 1 << 2),
DECLARE_IRQ(S2MU106_AFC_IRQ_MPNack, AFC_INT, 1 << 3),
DECLARE_IRQ(S2MU106_AFC_IRQ_MRxTrf, AFC_INT, 1 << 5),
DECLARE_IRQ(S2MU106_AFC_IRQ_MRxPerr, AFC_INT, 1 << 6),
DECLARE_IRQ(S2MU106_AFC_IRQ_MRxRdy, AFC_INT, 1 << 7),
#endif
#if defined(CONFIG_MUIC_S2MU106)
DECLARE_IRQ(S2MU106_MUIC_IRQ1_DETACH, MUIC_INT1, 1 << 1),
DECLARE_IRQ(S2MU106_MUIC_IRQ1_ATTATCH, MUIC_INT1, 1 << 0),
DECLARE_IRQ(S2MU106_MUIC_IRQ1_KP, MUIC_INT1, 1 << 2),
DECLARE_IRQ(S2MU106_MUIC_IRQ1_LKP, MUIC_INT1, 1 << 3),
DECLARE_IRQ(S2MU106_MUIC_IRQ1_LKR, MUIC_INT1, 1 << 4),
DECLARE_IRQ(S2MU106_MUIC_IRQ1_RID_CHG, MUIC_INT1, 1 << 5),
DECLARE_IRQ(S2MU106_MUIC_IRQ1_USB_Killer, MUIC_INT1, 1 << 6),
DECLARE_IRQ(S2MU106_MUIC_IRQ2_VBUS_ON, MUIC_INT2, 1 << 0),
DECLARE_IRQ(S2MU106_MUIC_IRQ2_RSVD_ATTACH, MUIC_INT2, 1 << 1),
DECLARE_IRQ(S2MU106_MUIC_IRQ2_ADC_CHANGE, MUIC_INT2, 1 << 2),
DECLARE_IRQ(S2MU106_MUIC_IRQ2_STUCK, MUIC_INT2, 1 << 3),
DECLARE_IRQ(S2MU106_MUIC_IRQ2_STUCKRCV, MUIC_INT2, 1 << 4),
DECLARE_IRQ(S2MU106_MUIC_IRQ2_MHDL, MUIC_INT2, 1 << 5),
DECLARE_IRQ(S2MU106_MUIC_IRQ2_AV_CHARGE, MUIC_INT2, 1 << 6),
DECLARE_IRQ(S2MU106_MUIC_IRQ2_VBUS_OFF, MUIC_INT2, 1 << 7),
#endif
#if defined(CONFIG_PM_S2MU106)
DECLARE_IRQ(S2MU106_PM_VALUP1_VCC2UP, PM_VALUP1, 1 << 0),
DECLARE_IRQ(S2MU106_PM_VALUP1_VGPADCUP, PM_VALUP1, 1 << 1),
DECLARE_IRQ(S2MU106_PM_VALUP1_VCC1UP, PM_VALUP1, 1 << 2),
DECLARE_IRQ(S2MU106_PM_VALUP1_VBATAUP, PM_VALUP1, 1 << 3),
DECLARE_IRQ(S2MU106_PM_VALUP1_VSYSAUP, PM_VALUP1, 1 << 4),
DECLARE_IRQ(S2MU106_PM_VALUP1_VBYPUP, PM_VALUP1, 1 << 5),
DECLARE_IRQ(S2MU106_PM_VALUP1_VWCINUP, PM_VALUP1, 1 << 6),
DECLARE_IRQ(S2MU106_PM_VALUP1_VCHGINUP, PM_VALUP1, 1 << 7),
DECLARE_IRQ(S2MU106_PM_VALUP2_ITXUP, PM_VALUP2, 1 << 3),
DECLARE_IRQ(S2MU106_PM_VALUP2_IOTGUP, PM_VALUP2, 1 << 4),
DECLARE_IRQ(S2MU106_PM_VALUP2_IWCINUP, PM_VALUP2, 1 << 6),
DECLARE_IRQ(S2MU106_PM_VALUP2_ICHGINUP, PM_VALUP2, 1 << 7),
DECLARE_IRQ(S2MU106_PM_IRQ1_VCC2UP, PM_INT1, 1 << 0),
DECLARE_IRQ(S2MU106_PM_IRQ1_VGPADCUP, PM_INT1, 1 << 1),
DECLARE_IRQ(S2MU106_PM_IRQ1_VCC1UP, PM_INT1, 1 << 2),
DECLARE_IRQ(S2MU106_PM_IRQ1_VBATAUP, PM_INT1, 1 << 3),
DECLARE_IRQ(S2MU106_PM_IRQ1_VSYSAUP, PM_INT1, 1 << 4),
DECLARE_IRQ(S2MU106_PM_IRQ1_VBYPUP, PM_INT1, 1 << 5),
DECLARE_IRQ(S2MU106_PM_IRQ1_VWCINUP, PM_INT1, 1 << 6),
DECLARE_IRQ(S2MU106_PM_IRQ1_VCHGINUP, PM_INT1, 1 << 7),
DECLARE_IRQ(S2MU106_PM_IRQ2_ITXUP, PM_INT2, 1 << 3),
DECLARE_IRQ(S2MU106_PM_IRQ2_IOTGUP, PM_INT2, 1 << 4),
DECLARE_IRQ(S2MU106_PM_IRQ2_IWCINUP, PM_INT2, 1 << 6),
DECLARE_IRQ(S2MU106_PM_IRQ2_ICHGINUP, PM_INT2, 1 << 7),
#endif
#if defined(CONFIG_MST_S2MU106)
DECLARE_IRQ(S2MU106_MST_IRQ_SHORT, MST_INT, 1 << 3),
DECLARE_IRQ(S2MU106_MST_IRQ_OCP, MST_INT, 1 << 4),
DECLARE_IRQ(S2MU106_MST_IRQ_EN_OVL, MST_INT, 1 << 5),
DECLARE_IRQ(S2MU106_MST_IRQ_DONE, MST_INT, 1 << 6),
DECLARE_IRQ(S2MU106_MST_IRQ_EN, MST_INT, 1 << 7),
#endif
#if defined(CONFIG_MOTOR_S2MU106)
DECLARE_IRQ(S2MU106_HAPTIC_IRQ_OCP, HAPTIC_INT, 1 << 0),
#endif
#if defined(CONFIG_REGULATOR_S2MU106)
DECLARE_IRQ(S2MU106_HBST_IRQ_OFF, HBST_INT 1 << 0),
DECLARE_IRQ(S2MU106_HBST_IRQ_ON, HBST_INT 1 << 1),
DECLARE_IRQ(S2MU106_HBST_IRQ_SCP, HBST_INT 1 << 2),
#endif
};
static void s2mu106_irq_lock(struct irq_data *data)
{
struct s2mu106_dev *s2mu106 = irq_get_chip_data(data->irq);
mutex_lock(&s2mu106->irqlock);
}
static void s2mu106_irq_sync_unlock(struct irq_data *data)
{
struct s2mu106_dev *s2mu106 = irq_get_chip_data(data->irq);
int i;
u8 mask_reg;
struct i2c_client *i2c;
for (i = 0; i < S2MU106_IRQ_GROUP_NR; i++) {
mask_reg = s2mu106_mask_reg[i];
i2c = get_i2c(s2mu106, i);
if (mask_reg == S2MU106_REG_INVALID ||
IS_ERR_OR_NULL(i2c))
continue;
s2mu106->irq_masks_cache[i] = s2mu106->irq_masks_cur[i];
s2mu106_write_reg(i2c, s2mu106_mask_reg[i],
s2mu106->irq_masks_cur[i]);
}
mutex_unlock(&s2mu106->irqlock);
}
static const inline struct s2mu106_irq_data *
irq_to_s2mu106_irq(struct s2mu106_dev *s2mu106, int irq)
{
return &s2mu106_irqs[irq - s2mu106->irq_base];
}
static void s2mu106_irq_mask(struct irq_data *data)
{
struct s2mu106_dev *s2mu106 = irq_get_chip_data(data->irq);
const struct s2mu106_irq_data *irq_data =
irq_to_s2mu106_irq(s2mu106, data->irq);
if (irq_data->group >= S2MU106_IRQ_GROUP_NR)
return;
s2mu106->irq_masks_cur[irq_data->group] |= irq_data->mask;
}
static void s2mu106_irq_unmask(struct irq_data *data)
{
struct s2mu106_dev *s2mu106 = irq_get_chip_data(data->irq);
const struct s2mu106_irq_data *irq_data =
irq_to_s2mu106_irq(s2mu106, data->irq);
if (irq_data->group >= S2MU106_IRQ_GROUP_NR)
return;
s2mu106->irq_masks_cur[irq_data->group] &= ~irq_data->mask;
}
static struct irq_chip s2mu106_irq_chip = {
.name = MFD_DEV_NAME,
.irq_bus_lock = s2mu106_irq_lock,
.irq_bus_sync_unlock = s2mu106_irq_sync_unlock,
.irq_mask = s2mu106_irq_mask,
.irq_unmask = s2mu106_irq_unmask,
};
static irqreturn_t s2mu106_irq_thread(int irq, void *data)
{
struct s2mu106_dev *s2mu106 = data;
u8 irq_reg[S2MU106_IRQ_GROUP_NR] = {0, };
int i, ret;
u8 irq_src;
ret = s2mu106_read_reg(s2mu106->i2c, S2MU106_REG_IPINT, &irq_src);
if (ret) {
pr_err("%s:%s Failed to read interrupt source: %d\n",
MFD_DEV_NAME, __func__, ret);
return IRQ_NONE;
}
pr_info("%s: Top interrupt(0x%02x)\n", __func__, irq_src);
#if defined(CONFIG_CHARGER_S2MU106)
if (irq_src & S2MU106_IRQSRC_CHG) {
ret = s2mu106_bulk_read(s2mu106->i2c, S2MU106_CHG_INT1,
S2MU106_NUM_IRQ_CHG_REGS, &irq_reg[CHG_INT1]);
if (ret) {
pr_err("%s:%s Failed to read charger interrupt: %d\n",
MFD_DEV_NAME, __func__, ret);
return IRQ_NONE;
}
pr_info("%s() CHARGER intrrupt(0x%02x, 0x%02x, 0x%02x)\n",
__func__, irq_reg[CHG_INT1], irq_reg[CHG_INT2],
irq_reg[CHG_INT3]);
}
#endif
#if defined(CONFIG_LEDS_S2MU106_FLASH)
if (irq_src & S2MU106_IRQSRC_FLED) {
ret = s2mu106_bulk_read(s2mu106->i2c, S2MU106_FLED_INT1,
S2MU106_NUM_IRQ_LED_REGS, &irq_reg[FLED_INT1]);
if (ret) {
pr_err("%s:%s Failed to read charger interrupt: %d\n",
MFD_DEV_NAME, __func__, ret);
return IRQ_NONE;
}
pr_info("%s() FLED intrrupt(0x%02x, 0x%02x)\n",
__func__, irq_reg[FLED_INT1], irq_reg[FLED_INT2]);
}
#endif
#if defined(CONFIG_HV_MUIC_S2MU106_AFC)
if (irq_src & S2MU106_IRQSRC_AFC) {
s2mu106_read_reg(s2mu106->muic, S2MU106_REG_AFC_INT, &irq_reg[AFC_INT]);
pr_info("%s: AFC interrupt(0x%02x)\n", __func__, irq_reg[AFC_INT]);
}
#endif
#if defined(CONFIG_MUIC_S2MU106)
if (irq_src & S2MU106_IRQSRC_MUIC) {
s2mu106_read_reg(s2mu106->muic, S2MU106_REG_MUIC_INT1, &irq_reg[MUIC_INT1]);
s2mu106_read_reg(s2mu106->muic, S2MU106_REG_MUIC_INT2, &irq_reg[MUIC_INT2]);
pr_info("%s: muic interrupt(0x%02x, 0x%02x)\n", __func__, irq_reg[MUIC_INT1],
irq_reg[MUIC_INT2]);
}
#endif
#if defined(CONFIG_PM_S2MU106)
if (irq_src & S2MU106_IRQSRC_PM) {
s2mu106_read_reg(s2mu106->muic, S2MU106_PM_VALUP1, &irq_reg[PM_VALUP1]);
s2mu106_read_reg(s2mu106->muic, S2MU106_PM_VALUP2, &irq_reg[PM_VALUP2]);
s2mu106_read_reg(s2mu106->muic, S2MU106_PM_INT1, &irq_reg[PM_INT1]);
s2mu106_read_reg(s2mu106->muic, S2MU106_PM_INT2, &irq_reg[PM_INT2]);
pr_info("%s: powermeter interrupt(0x%02x, 0x%02x, 0x%02x, 0x%02x)\n",__func__,
irq_reg[PM_VALUP1], irq_reg[PM_VALUP2], irq_reg[PM_INT1], irq_reg[PM_INT2]);
}
#endif
#if defined(CONFIG_MST_S2MU106)
if (irq_src & S2MU106_IRQSRC_MST) {
}
#endif
#if defined(CONFIG_MOTOR_S2MU106)
if (irq_src & S2MU106_IRQSRC_HAPTIC) {
s2mu106_read_reg(s2mu106->haptic, S2MU106_REG_HAPTIC_INT, &irq_reg[HAPTIC_INT]);
pr_info("%s: haptic interrupt(0x%02x)\n", __func__, irq_reg[HAPTIC_INT]);
}
#endif
#if defined(CONFIG_REGULATOR_S2MU106)
if (irq_src & S2MU106_IRQSRC_HBST) {
}
#endif
/* Apply masking */
for (i = 0; i < S2MU106_IRQ_GROUP_NR; i++)
irq_reg[i] &= ~s2mu106->irq_masks_cur[i];
/* Report */
for (i = 0; i < S2MU106_IRQ_NR; i++) {
if (irq_reg[s2mu106_irqs[i].group] & s2mu106_irqs[i].mask)
handle_nested_irq(s2mu106->irq_base + i);
}
return IRQ_HANDLED;
}
static int irq_is_enable = true;
int s2mu106_irq_init(struct s2mu106_dev *s2mu106)
{
int i;
int ret;
struct i2c_client *i2c = s2mu106->i2c;
int cur_irq;
u8 i2c_data;
if (!s2mu106->irq_gpio) {
dev_warn(s2mu106->dev, "No interrupt specified.\n");
s2mu106->irq_base = 0;
return 0;
}
if (!s2mu106->irq_base) {
dev_err(s2mu106->dev, "No interrupt base specified.\n");
return 0;
}
mutex_init(&s2mu106->irqlock);
s2mu106->irq = gpio_to_irq(s2mu106->irq_gpio);
pr_err("%s:%s irq=%d, irq->gpio=%d\n", MFD_DEV_NAME, __func__,
s2mu106->irq, s2mu106->irq_gpio);
ret = gpio_request(s2mu106->irq_gpio, "if_pmic_irq");
if (ret) {
dev_err(s2mu106->dev, "%s: failed requesting gpio %d\n",
__func__, s2mu106->irq_gpio);
return ret;
}
gpio_direction_input(s2mu106->irq_gpio);
gpio_free(s2mu106->irq_gpio);
/* Mask individual interrupt sources */
for (i = 0; i < S2MU106_IRQ_GROUP_NR; i++) {
s2mu106->irq_masks_cur[i] = 0xff;
s2mu106->irq_masks_cache[i] = 0xff;
i2c = get_i2c(s2mu106, i);
if (IS_ERR_OR_NULL(i2c))
continue;
if (s2mu106_mask_reg[i] == S2MU106_REG_INVALID)
continue;
s2mu106_write_reg(i2c, s2mu106_mask_reg[i], 0xff);
}
/* Register with genirq */
for (i = 0; i < S2MU106_IRQ_NR; i++) {
cur_irq = 0;
cur_irq = i + s2mu106->irq_base;
irq_set_chip_data(cur_irq, s2mu106);
irq_set_chip_and_handler(cur_irq, &s2mu106_irq_chip,
handle_level_irq);
irq_set_nested_thread(cur_irq, 1);
#ifdef CONFIG_ARM
set_irq_flags(cur_irq, IRQF_VALID);
#else
irq_set_noprobe(cur_irq);
#endif
}
/* Unmask S2MU106 interrupt */
i2c_data = 0xff;
#if defined(CONFIG_CHARGER_S2MU106)
i2c_data &= ~(S2MU106_IRQSRC_CHG);
#endif
#if defined(CONFIG_LEDS_S2MU106_FLASH)
i2c_data &= ~(S2MU106_IRQSRC_FLED);
#endif
#if defined(CONFIG_HV_MUIC_S2MU106_AFC)
i2c_data &= ~(S2MU106_IRQSRC_AFC);
#endif
#if defined(CONFIG_MUIC_S2MU106)
i2c_data &= ~(S2MU106_IRQSRC_MUIC);
#endif
#if defined(CONFIG_PM_S2MU106)
i2c_data &= ~(S2MU106_IRQSRC_PM);
#endif
#if defined(CONFIG_MST_S2MU106)
i2c_data &= ~(S2MU106_IRQSRC_MST);
#endif
#if defined(CONFIG_MOTOR_S2MU106)
i2c_data &= ~(S2MU106_IRQSRC_HAPTIC);
#endif
#if defined(CONFIG_REGULATOR_S2MU106)
i2c_data &= ~(S2MU106_IRQSRC_HBST);
#endif
s2mu106_write_reg(s2mu106->i2c, S2MU106_REG_IPINT_MASK, i2c_data);
pr_info("%s: %s init top-irq mask(0x%02x)\n", MFD_DEV_NAME, __func__, i2c_data);
pr_info("%s: irq gpio pre-state(0x%02x)\n", __func__,
gpio_get_value(s2mu106->irq_gpio));
if (irq_is_enable) {
ret = request_threaded_irq(s2mu106->irq, NULL,
s2mu106_irq_thread,
IRQF_TRIGGER_LOW | IRQF_ONESHOT,
"s2mu106-irq", s2mu106);
}
if (ret) {
dev_err(s2mu106->dev, "Failed to request IRQ %d: %d\n",
s2mu106->irq, ret);
return ret;
}
return 0;
}
void s2mu106_irq_exit(struct s2mu106_dev *s2mu106)
{
if (s2mu106->irq)
free_irq(s2mu106->irq, s2mu106);
}