qcom: smb-lib: make smb_irq_info common for smb2 and smb138x chargers

Since the interrupt information for both smb2 and smb138x charger
devices are almost common, abstract it to a single smb_irq_info
struct. Also, keep an interrupt index for every interrupt which
can be used when necessary.

Change-Id: I4e42dd15a46b59c1a9c27412ca6fdff281fa71ec
Signed-off-by: Subbaraman Narayanamurthy <subbaram@codeaurora.org>
This commit is contained in:
Subbaraman Narayanamurthy 2017-02-06 16:22:48 -08:00
parent 1f0f1184a0
commit 2b9d6a362f
3 changed files with 134 additions and 95 deletions

View file

@ -16,7 +16,6 @@
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/regmap.h> #include <linux/regmap.h>
#include <linux/power_supply.h> #include <linux/power_supply.h>
#include <linux/interrupt.h>
#include <linux/of.h> #include <linux/of.h>
#include <linux/of_irq.h> #include <linux/of_irq.h>
#include <linux/qpnp/qpnp-revid.h> #include <linux/qpnp/qpnp-revid.h>
@ -1660,180 +1659,172 @@ static int smb2_determine_initial_status(struct smb2 *chip)
* INTERRUPT REGISTRATION * * INTERRUPT REGISTRATION *
**************************/ **************************/
struct smb2_irq_info { static struct smb_irq_info smb2_irqs[] = {
const char *name;
const irq_handler_t handler;
const bool wake;
const struct storm_watch storm_data;
int irq;
};
static struct smb2_irq_info smb2_irqs[] = {
/* CHARGER IRQs */ /* CHARGER IRQs */
{ [CHG_ERROR_IRQ] = {
.name = "chg-error", .name = "chg-error",
.handler = smblib_handle_debug, .handler = smblib_handle_debug,
}, },
{ [CHG_STATE_CHANGE_IRQ] = {
.name = "chg-state-change", .name = "chg-state-change",
.handler = smblib_handle_chg_state_change, .handler = smblib_handle_chg_state_change,
.wake = true, .wake = true,
}, },
{ [STEP_CHG_STATE_CHANGE_IRQ] = {
.name = "step-chg-state-change", .name = "step-chg-state-change",
.handler = smblib_handle_step_chg_state_change, .handler = smblib_handle_step_chg_state_change,
.wake = true, .wake = true,
}, },
{ [STEP_CHG_SOC_UPDATE_FAIL_IRQ] = {
.name = "step-chg-soc-update-fail", .name = "step-chg-soc-update-fail",
.handler = smblib_handle_step_chg_soc_update_fail, .handler = smblib_handle_step_chg_soc_update_fail,
.wake = true, .wake = true,
}, },
{ [STEP_CHG_SOC_UPDATE_REQ_IRQ] = {
.name = "step-chg-soc-update-request", .name = "step-chg-soc-update-request",
.handler = smblib_handle_step_chg_soc_update_request, .handler = smblib_handle_step_chg_soc_update_request,
.wake = true, .wake = true,
}, },
/* OTG IRQs */ /* OTG IRQs */
{ [OTG_FAIL_IRQ] = {
.name = "otg-fail", .name = "otg-fail",
.handler = smblib_handle_debug, .handler = smblib_handle_debug,
}, },
{ [OTG_OVERCURRENT_IRQ] = {
.name = "otg-overcurrent", .name = "otg-overcurrent",
.handler = smblib_handle_otg_overcurrent, .handler = smblib_handle_otg_overcurrent,
}, },
{ [OTG_OC_DIS_SW_STS_IRQ] = {
.name = "otg-oc-dis-sw-sts", .name = "otg-oc-dis-sw-sts",
.handler = smblib_handle_debug, .handler = smblib_handle_debug,
}, },
{ [TESTMODE_CHANGE_DET_IRQ] = {
.name = "testmode-change-detect", .name = "testmode-change-detect",
.handler = smblib_handle_debug, .handler = smblib_handle_debug,
}, },
/* BATTERY IRQs */ /* BATTERY IRQs */
{ [BATT_TEMP_IRQ] = {
.name = "bat-temp", .name = "bat-temp",
.handler = smblib_handle_batt_temp_changed, .handler = smblib_handle_batt_temp_changed,
}, },
{ [BATT_OCP_IRQ] = {
.name = "bat-ocp", .name = "bat-ocp",
.handler = smblib_handle_batt_psy_changed, .handler = smblib_handle_batt_psy_changed,
}, },
{ [BATT_OV_IRQ] = {
.name = "bat-ov", .name = "bat-ov",
.handler = smblib_handle_batt_psy_changed, .handler = smblib_handle_batt_psy_changed,
}, },
{ [BATT_LOW_IRQ] = {
.name = "bat-low", .name = "bat-low",
.handler = smblib_handle_batt_psy_changed, .handler = smblib_handle_batt_psy_changed,
}, },
{ [BATT_THERM_ID_MISS_IRQ] = {
.name = "bat-therm-or-id-missing", .name = "bat-therm-or-id-missing",
.handler = smblib_handle_batt_psy_changed, .handler = smblib_handle_batt_psy_changed,
}, },
{ [BATT_TERM_MISS_IRQ] = {
.name = "bat-terminal-missing", .name = "bat-terminal-missing",
.handler = smblib_handle_batt_psy_changed, .handler = smblib_handle_batt_psy_changed,
}, },
/* USB INPUT IRQs */ /* USB INPUT IRQs */
{ [USBIN_COLLAPSE_IRQ] = {
.name = "usbin-collapse", .name = "usbin-collapse",
.handler = smblib_handle_debug, .handler = smblib_handle_debug,
}, },
{ [USBIN_LT_3P6V_IRQ] = {
.name = "usbin-lt-3p6v", .name = "usbin-lt-3p6v",
.handler = smblib_handle_debug, .handler = smblib_handle_debug,
}, },
{ [USBIN_UV_IRQ] = {
.name = "usbin-uv", .name = "usbin-uv",
.handler = smblib_handle_debug, .handler = smblib_handle_debug,
}, },
{ [USBIN_OV_IRQ] = {
.name = "usbin-ov", .name = "usbin-ov",
.handler = smblib_handle_debug, .handler = smblib_handle_debug,
}, },
{ [USBIN_PLUGIN_IRQ] = {
.name = "usbin-plugin", .name = "usbin-plugin",
.handler = smblib_handle_usb_plugin, .handler = smblib_handle_usb_plugin,
.wake = true, .wake = true,
}, },
{ [USBIN_SRC_CHANGE_IRQ] = {
.name = "usbin-src-change", .name = "usbin-src-change",
.handler = smblib_handle_usb_source_change, .handler = smblib_handle_usb_source_change,
.wake = true, .wake = true,
}, },
{ [USBIN_ICL_CHANGE_IRQ] = {
.name = "usbin-icl-change", .name = "usbin-icl-change",
.handler = smblib_handle_icl_change, .handler = smblib_handle_icl_change,
.wake = true, .wake = true,
}, },
{ [TYPE_C_CHANGE_IRQ] = {
.name = "type-c-change", .name = "type-c-change",
.handler = smblib_handle_usb_typec_change, .handler = smblib_handle_usb_typec_change,
.wake = true, .wake = true,
}, },
/* DC INPUT IRQs */ /* DC INPUT IRQs */
{ [DCIN_COLLAPSE_IRQ] = {
.name = "dcin-collapse", .name = "dcin-collapse",
.handler = smblib_handle_debug, .handler = smblib_handle_debug,
}, },
{ [DCIN_LT_3P6V_IRQ] = {
.name = "dcin-lt-3p6v", .name = "dcin-lt-3p6v",
.handler = smblib_handle_debug, .handler = smblib_handle_debug,
}, },
{ [DCIN_UV_IRQ] = {
.name = "dcin-uv", .name = "dcin-uv",
.handler = smblib_handle_debug, .handler = smblib_handle_debug,
}, },
{ [DCIN_OV_IRQ] = {
.name = "dcin-ov", .name = "dcin-ov",
.handler = smblib_handle_debug, .handler = smblib_handle_debug,
}, },
{ [DCIN_PLUGIN_IRQ] = {
.name = "dcin-plugin", .name = "dcin-plugin",
.handler = smblib_handle_dc_plugin, .handler = smblib_handle_dc_plugin,
.wake = true, .wake = true,
}, },
{ [DIV2_EN_DG_IRQ] = {
.name = "div2-en-dg", .name = "div2-en-dg",
.handler = smblib_handle_debug, .handler = smblib_handle_debug,
}, },
{ [DCIN_ICL_CHANGE_IRQ] = {
.name = "dcin-icl-change", .name = "dcin-icl-change",
.handler = smblib_handle_debug, .handler = smblib_handle_debug,
}, },
/* MISCELLANEOUS IRQs */ /* MISCELLANEOUS IRQs */
{ [WDOG_SNARL_IRQ] = {
.name = "wdog-snarl", .name = "wdog-snarl",
.handler = NULL, .handler = NULL,
}, },
{ [WDOG_BARK_IRQ] = {
.name = "wdog-bark", .name = "wdog-bark",
.handler = NULL, .handler = NULL,
}, },
{ [AICL_FAIL_IRQ] = {
.name = "aicl-fail", .name = "aicl-fail",
.handler = smblib_handle_debug, .handler = smblib_handle_debug,
}, },
{ [AICL_DONE_IRQ] = {
.name = "aicl-done", .name = "aicl-done",
.handler = smblib_handle_debug, .handler = smblib_handle_debug,
}, },
{ [HIGH_DUTY_CYCLE_IRQ] = {
.name = "high-duty-cycle", .name = "high-duty-cycle",
.handler = smblib_handle_high_duty_cycle, .handler = smblib_handle_high_duty_cycle,
.wake = true, .wake = true,
}, },
{ [INPUT_CURRENT_LIMIT_IRQ] = {
.name = "input-current-limiting", .name = "input-current-limiting",
.handler = smblib_handle_debug, .handler = smblib_handle_debug,
}, },
{ [TEMPERATURE_CHANGE_IRQ] = {
.name = "temperature-change", .name = "temperature-change",
.handler = smblib_handle_debug, .handler = smblib_handle_debug,
}, },
{ [SWITCH_POWER_OK_IRQ] = {
.name = "switcher-power-ok", .name = "switcher-power-ok",
.handler = smblib_handle_switcher_power_ok, .handler = smblib_handle_switcher_power_ok,
.storm_data = {true, 1000, 3}, .storm_data = {true, 1000, 3},
@ -1892,6 +1883,7 @@ static int smb2_request_interrupt(struct smb2 *chip,
} }
smb2_irqs[irq_index].irq = irq; smb2_irqs[irq_index].irq = irq;
smb2_irqs[irq_index].irq_data = irq_data;
if (smb2_irqs[irq_index].wake) if (smb2_irqs[irq_index].wake)
enable_irq_wake(irq); enable_irq_wake(irq);
@ -2005,6 +1997,7 @@ static int smb2_probe(struct platform_device *pdev)
chg->param = v1_params; chg->param = v1_params;
chg->debug_mask = &__debug_mask; chg->debug_mask = &__debug_mask;
chg->mode = PARALLEL_MASTER; chg->mode = PARALLEL_MASTER;
chg->irq_info = smb2_irqs;
chg->name = "PMI"; chg->name = "PMI";
chg->regmap = dev_get_regmap(chg->dev->parent, NULL); chg->regmap = dev_get_regmap(chg->dev->parent, NULL);

View file

@ -13,6 +13,7 @@
#ifndef __SMB2_CHARGER_H #ifndef __SMB2_CHARGER_H
#define __SMB2_CHARGER_H #define __SMB2_CHARGER_H
#include <linux/types.h> #include <linux/types.h>
#include <linux/interrupt.h>
#include <linux/irqreturn.h> #include <linux/irqreturn.h>
#include <linux/regulator/driver.h> #include <linux/regulator/driver.h>
#include <linux/regulator/consumer.h> #include <linux/regulator/consumer.h>
@ -79,6 +80,57 @@ enum {
TYPEC_CC2_REMOVAL_WA_BIT = BIT(2), TYPEC_CC2_REMOVAL_WA_BIT = BIT(2),
}; };
enum smb_irq_index {
CHG_ERROR_IRQ = 0,
CHG_STATE_CHANGE_IRQ,
STEP_CHG_STATE_CHANGE_IRQ,
STEP_CHG_SOC_UPDATE_FAIL_IRQ,
STEP_CHG_SOC_UPDATE_REQ_IRQ,
OTG_FAIL_IRQ,
OTG_OVERCURRENT_IRQ,
OTG_OC_DIS_SW_STS_IRQ,
TESTMODE_CHANGE_DET_IRQ,
BATT_TEMP_IRQ,
BATT_OCP_IRQ,
BATT_OV_IRQ,
BATT_LOW_IRQ,
BATT_THERM_ID_MISS_IRQ,
BATT_TERM_MISS_IRQ,
USBIN_COLLAPSE_IRQ,
USBIN_LT_3P6V_IRQ,
USBIN_UV_IRQ,
USBIN_OV_IRQ,
USBIN_PLUGIN_IRQ,
USBIN_SRC_CHANGE_IRQ,
USBIN_ICL_CHANGE_IRQ,
TYPE_C_CHANGE_IRQ,
DCIN_COLLAPSE_IRQ,
DCIN_LT_3P6V_IRQ,
DCIN_UV_IRQ,
DCIN_OV_IRQ,
DCIN_PLUGIN_IRQ,
DIV2_EN_DG_IRQ,
DCIN_ICL_CHANGE_IRQ,
WDOG_SNARL_IRQ,
WDOG_BARK_IRQ,
AICL_FAIL_IRQ,
AICL_DONE_IRQ,
HIGH_DUTY_CYCLE_IRQ,
INPUT_CURRENT_LIMIT_IRQ,
TEMPERATURE_CHANGE_IRQ,
SWITCH_POWER_OK_IRQ,
SMB_IRQ_MAX,
};
struct smb_irq_info {
const char *name;
const irq_handler_t handler;
const bool wake;
const struct storm_watch storm_data;
struct smb_irq_data *irq_data;
int irq;
};
static const unsigned int smblib_extcon_cable[] = { static const unsigned int smblib_extcon_cable[] = {
EXTCON_USB, EXTCON_USB,
EXTCON_USB_HOST, EXTCON_USB_HOST,
@ -167,6 +219,7 @@ struct smb_charger {
struct device *dev; struct device *dev;
char *name; char *name;
struct regmap *regmap; struct regmap *regmap;
struct smb_irq_info *irq_info;
struct smb_params param; struct smb_params param;
struct smb_iio iio; struct smb_iio iio;
int *debug_mask; int *debug_mask;

View file

@ -14,7 +14,6 @@
#include <linux/device.h> #include <linux/device.h>
#include <linux/iio/consumer.h> #include <linux/iio/consumer.h>
#include <linux/interrupt.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/of.h> #include <linux/of.h>
#include <linux/of_device.h> #include <linux/of_device.h>
@ -985,171 +984,164 @@ static int smb138x_determine_initial_status(struct smb138x *chip)
* INTERRUPT REGISTRATION * * INTERRUPT REGISTRATION *
**************************/ **************************/
struct smb138x_irq_info { static struct smb_irq_info smb138x_irqs[] = {
const char *name;
const irq_handler_t handler;
const bool wake;
const struct storm_watch storm_data;
};
static const struct smb138x_irq_info smb138x_irqs[] = {
/* CHARGER IRQs */ /* CHARGER IRQs */
{ [CHG_ERROR_IRQ] = {
.name = "chg-error", .name = "chg-error",
.handler = smblib_handle_debug, .handler = smblib_handle_debug,
}, },
{ [CHG_STATE_CHANGE_IRQ] = {
.name = "chg-state-change", .name = "chg-state-change",
.handler = smb138x_handle_slave_chg_state_change, .handler = smb138x_handle_slave_chg_state_change,
.wake = true, .wake = true,
}, },
{ [STEP_CHG_STATE_CHANGE_IRQ] = {
.name = "step-chg-state-change", .name = "step-chg-state-change",
.handler = smblib_handle_debug, .handler = smblib_handle_debug,
}, },
{ [STEP_CHG_SOC_UPDATE_FAIL_IRQ] = {
.name = "step-chg-soc-update-fail", .name = "step-chg-soc-update-fail",
.handler = smblib_handle_debug, .handler = smblib_handle_debug,
}, },
{ [STEP_CHG_SOC_UPDATE_REQ_IRQ] = {
.name = "step-chg-soc-update-request", .name = "step-chg-soc-update-request",
.handler = smblib_handle_debug, .handler = smblib_handle_debug,
}, },
/* OTG IRQs */ /* OTG IRQs */
{ [OTG_FAIL_IRQ] = {
.name = "otg-fail", .name = "otg-fail",
.handler = smblib_handle_debug, .handler = smblib_handle_debug,
}, },
{ [OTG_OVERCURRENT_IRQ] = {
.name = "otg-overcurrent", .name = "otg-overcurrent",
.handler = smblib_handle_debug, .handler = smblib_handle_debug,
}, },
{ [OTG_OC_DIS_SW_STS_IRQ] = {
.name = "otg-oc-dis-sw-sts", .name = "otg-oc-dis-sw-sts",
.handler = smblib_handle_debug, .handler = smblib_handle_debug,
}, },
{ [TESTMODE_CHANGE_DET_IRQ] = {
.name = "testmode-change-detect", .name = "testmode-change-detect",
.handler = smblib_handle_debug, .handler = smblib_handle_debug,
}, },
/* BATTERY IRQs */ /* BATTERY IRQs */
{ [BATT_TEMP_IRQ] = {
.name = "bat-temp", .name = "bat-temp",
.handler = smblib_handle_batt_psy_changed, .handler = smblib_handle_batt_psy_changed,
}, },
{ [BATT_OCP_IRQ] = {
.name = "bat-ocp", .name = "bat-ocp",
.handler = smblib_handle_batt_psy_changed, .handler = smblib_handle_batt_psy_changed,
}, },
{ [BATT_OV_IRQ] = {
.name = "bat-ov", .name = "bat-ov",
.handler = smblib_handle_batt_psy_changed, .handler = smblib_handle_batt_psy_changed,
}, },
{ [BATT_LOW_IRQ] = {
.name = "bat-low", .name = "bat-low",
.handler = smblib_handle_batt_psy_changed, .handler = smblib_handle_batt_psy_changed,
}, },
{ [BATT_THERM_ID_MISS_IRQ] = {
.name = "bat-therm-or-id-missing", .name = "bat-therm-or-id-missing",
.handler = smblib_handle_batt_psy_changed, .handler = smblib_handle_batt_psy_changed,
}, },
{ [BATT_TERM_MISS_IRQ] = {
.name = "bat-terminal-missing", .name = "bat-terminal-missing",
.handler = smblib_handle_batt_psy_changed, .handler = smblib_handle_batt_psy_changed,
}, },
/* USB INPUT IRQs */ /* USB INPUT IRQs */
{ [USBIN_COLLAPSE_IRQ] = {
.name = "usbin-collapse", .name = "usbin-collapse",
.handler = smblib_handle_debug, .handler = smblib_handle_debug,
}, },
{ [USBIN_LT_3P6V_IRQ] = {
.name = "usbin-lt-3p6v", .name = "usbin-lt-3p6v",
.handler = smblib_handle_debug, .handler = smblib_handle_debug,
}, },
{ [USBIN_UV_IRQ] = {
.name = "usbin-uv", .name = "usbin-uv",
.handler = smblib_handle_debug, .handler = smblib_handle_debug,
}, },
{ [USBIN_OV_IRQ] = {
.name = "usbin-ov", .name = "usbin-ov",
.handler = smblib_handle_debug, .handler = smblib_handle_debug,
}, },
{ [USBIN_PLUGIN_IRQ] = {
.name = "usbin-plugin", .name = "usbin-plugin",
.handler = smblib_handle_usb_plugin, .handler = smblib_handle_usb_plugin,
}, },
{ [USBIN_SRC_CHANGE_IRQ] = {
.name = "usbin-src-change", .name = "usbin-src-change",
.handler = smblib_handle_usb_source_change, .handler = smblib_handle_usb_source_change,
}, },
{ [USBIN_ICL_CHANGE_IRQ] = {
.name = "usbin-icl-change", .name = "usbin-icl-change",
.handler = smblib_handle_debug, .handler = smblib_handle_debug,
}, },
{ [TYPE_C_CHANGE_IRQ] = {
.name = "type-c-change", .name = "type-c-change",
.handler = smblib_handle_usb_typec_change, .handler = smblib_handle_usb_typec_change,
}, },
/* DC INPUT IRQs */ /* DC INPUT IRQs */
{ [DCIN_COLLAPSE_IRQ] = {
.name = "dcin-collapse", .name = "dcin-collapse",
.handler = smblib_handle_debug, .handler = smblib_handle_debug,
}, },
{ [DCIN_LT_3P6V_IRQ] = {
.name = "dcin-lt-3p6v", .name = "dcin-lt-3p6v",
.handler = smblib_handle_debug, .handler = smblib_handle_debug,
}, },
{ [DCIN_UV_IRQ] = {
.name = "dcin-uv", .name = "dcin-uv",
.handler = smblib_handle_debug, .handler = smblib_handle_debug,
}, },
{ [DCIN_OV_IRQ] = {
.name = "dcin-ov", .name = "dcin-ov",
.handler = smblib_handle_debug, .handler = smblib_handle_debug,
}, },
{ [DCIN_PLUGIN_IRQ] = {
.name = "dcin-plugin", .name = "dcin-plugin",
.handler = smblib_handle_debug, .handler = smblib_handle_debug,
}, },
{ [DIV2_EN_DG_IRQ] = {
.name = "div2-en-dg", .name = "div2-en-dg",
.handler = smblib_handle_debug, .handler = smblib_handle_debug,
}, },
{ [DCIN_ICL_CHANGE_IRQ] = {
.name = "dcin-icl-change", .name = "dcin-icl-change",
.handler = smblib_handle_debug, .handler = smblib_handle_debug,
}, },
/* MISCELLANEOUS IRQs */ /* MISCELLANEOUS IRQs */
{ [WDOG_SNARL_IRQ] = {
.name = "wdog-snarl", .name = "wdog-snarl",
.handler = smblib_handle_debug, .handler = smblib_handle_debug,
}, },
{ [WDOG_BARK_IRQ] = {
.name = "wdog-bark", .name = "wdog-bark",
.handler = smblib_handle_wdog_bark, .handler = smblib_handle_wdog_bark,
.wake = true, .wake = true,
}, },
{ [AICL_FAIL_IRQ] = {
.name = "aicl-fail", .name = "aicl-fail",
.handler = smblib_handle_debug, .handler = smblib_handle_debug,
}, },
{ [AICL_DONE_IRQ] = {
.name = "aicl-done", .name = "aicl-done",
.handler = smblib_handle_debug, .handler = smblib_handle_debug,
}, },
{ [HIGH_DUTY_CYCLE_IRQ] = {
.name = "high-duty-cycle", .name = "high-duty-cycle",
.handler = smblib_handle_debug, .handler = smblib_handle_debug,
}, },
{ [INPUT_CURRENT_LIMIT_IRQ] = {
.name = "input-current-limiting", .name = "input-current-limiting",
.handler = smblib_handle_debug, .handler = smblib_handle_debug,
}, },
{ [TEMPERATURE_CHANGE_IRQ] = {
.name = "temperature-change", .name = "temperature-change",
.handler = smb138x_handle_temperature_change, .handler = smb138x_handle_temperature_change,
}, },
{ [SWITCH_POWER_OK_IRQ] = {
.name = "switcher-power-ok", .name = "switcher-power-ok",
.handler = smblib_handle_debug, .handler = smblib_handle_debug,
}, },
@ -1411,6 +1403,7 @@ static int smb138x_probe(struct platform_device *pdev)
chip->chg.dev = &pdev->dev; chip->chg.dev = &pdev->dev;
chip->chg.debug_mask = &__debug_mask; chip->chg.debug_mask = &__debug_mask;
chip->chg.irq_info = smb138x_irqs;
chip->chg.name = "SMB"; chip->chg.name = "SMB";
chip->chg.regmap = dev_get_regmap(chip->chg.dev->parent, NULL); chip->chg.regmap = dev_get_regmap(chip->chg.dev->parent, NULL);