mfd: max8998: Add irq domain support
This patch adds irq domain support for max8998 interrupts. To keep both non-DT and DT worlds happy, simple domain is used, which is linear when no explicit IRQ base is specified and legacy, with static mapping, otherwise. Signed-off-by: Tomasz Figa <t.figa@samsung.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
Родитель
b5c46787df
Коммит
443c6ae253
|
@ -363,6 +363,7 @@ config MFD_MAX8998
|
||||||
bool "Maxim Semiconductor MAX8998/National LP3974 PMIC Support"
|
bool "Maxim Semiconductor MAX8998/National LP3974 PMIC Support"
|
||||||
depends on I2C=y && GENERIC_HARDIRQS
|
depends on I2C=y && GENERIC_HARDIRQS
|
||||||
select MFD_CORE
|
select MFD_CORE
|
||||||
|
select IRQ_DOMAIN
|
||||||
help
|
help
|
||||||
Say yes here to support for Maxim Semiconductor MAX8998 and
|
Say yes here to support for Maxim Semiconductor MAX8998 and
|
||||||
National Semiconductor LP3974. This is a Power Management IC.
|
National Semiconductor LP3974. This is a Power Management IC.
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include <linux/device.h>
|
#include <linux/device.h>
|
||||||
#include <linux/interrupt.h>
|
#include <linux/interrupt.h>
|
||||||
#include <linux/irq.h>
|
#include <linux/irq.h>
|
||||||
|
#include <linux/irqdomain.h>
|
||||||
#include <linux/mfd/max8998-private.h>
|
#include <linux/mfd/max8998-private.h>
|
||||||
|
|
||||||
struct max8998_irq_data {
|
struct max8998_irq_data {
|
||||||
|
@ -99,7 +100,8 @@ static struct max8998_irq_data max8998_irqs[] = {
|
||||||
static inline struct max8998_irq_data *
|
static inline struct max8998_irq_data *
|
||||||
irq_to_max8998_irq(struct max8998_dev *max8998, int irq)
|
irq_to_max8998_irq(struct max8998_dev *max8998, int irq)
|
||||||
{
|
{
|
||||||
return &max8998_irqs[irq - max8998->irq_base];
|
struct irq_data *data = irq_get_irq_data(irq);
|
||||||
|
return &max8998_irqs[data->hwirq];
|
||||||
}
|
}
|
||||||
|
|
||||||
static void max8998_irq_lock(struct irq_data *data)
|
static void max8998_irq_lock(struct irq_data *data)
|
||||||
|
@ -176,8 +178,14 @@ static irqreturn_t max8998_irq_thread(int irq, void *data)
|
||||||
|
|
||||||
/* Report */
|
/* Report */
|
||||||
for (i = 0; i < MAX8998_IRQ_NR; i++) {
|
for (i = 0; i < MAX8998_IRQ_NR; i++) {
|
||||||
if (irq_reg[max8998_irqs[i].reg - 1] & max8998_irqs[i].mask)
|
if (irq_reg[max8998_irqs[i].reg - 1] & max8998_irqs[i].mask) {
|
||||||
handle_nested_irq(max8998->irq_base + i);
|
irq = irq_find_mapping(max8998->irq_domain, i);
|
||||||
|
if (WARN_ON(!irq)) {
|
||||||
|
disable_irq_nosync(max8998->irq);
|
||||||
|
return IRQ_NONE;
|
||||||
|
}
|
||||||
|
handle_nested_irq(irq);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return IRQ_HANDLED;
|
return IRQ_HANDLED;
|
||||||
|
@ -185,27 +193,40 @@ static irqreturn_t max8998_irq_thread(int irq, void *data)
|
||||||
|
|
||||||
int max8998_irq_resume(struct max8998_dev *max8998)
|
int max8998_irq_resume(struct max8998_dev *max8998)
|
||||||
{
|
{
|
||||||
if (max8998->irq && max8998->irq_base)
|
if (max8998->irq && max8998->irq_domain)
|
||||||
max8998_irq_thread(max8998->irq_base, max8998);
|
max8998_irq_thread(max8998->irq, max8998);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int max8998_irq_domain_map(struct irq_domain *d, unsigned int irq,
|
||||||
|
irq_hw_number_t hw)
|
||||||
|
{
|
||||||
|
struct max8997_dev *max8998 = d->host_data;
|
||||||
|
|
||||||
|
irq_set_chip_data(irq, max8998);
|
||||||
|
irq_set_chip_and_handler(irq, &max8998_irq_chip, handle_edge_irq);
|
||||||
|
irq_set_nested_thread(irq, 1);
|
||||||
|
#ifdef CONFIG_ARM
|
||||||
|
set_irq_flags(irq, IRQF_VALID);
|
||||||
|
#else
|
||||||
|
irq_set_noprobe(irq);
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct irq_domain_ops max8998_irq_domain_ops = {
|
||||||
|
.map = max8998_irq_domain_map,
|
||||||
|
};
|
||||||
|
|
||||||
int max8998_irq_init(struct max8998_dev *max8998)
|
int max8998_irq_init(struct max8998_dev *max8998)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int cur_irq;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
struct irq_domain *domain;
|
||||||
|
|
||||||
if (!max8998->irq) {
|
if (!max8998->irq) {
|
||||||
dev_warn(max8998->dev,
|
dev_warn(max8998->dev,
|
||||||
"No interrupt specified, no interrupts\n");
|
"No interrupt specified, no interrupts\n");
|
||||||
max8998->irq_base = 0;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!max8998->irq_base) {
|
|
||||||
dev_err(max8998->dev,
|
|
||||||
"No interrupt base specified, no interrupts\n");
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,19 +242,13 @@ int max8998_irq_init(struct max8998_dev *max8998)
|
||||||
max8998_write_reg(max8998->i2c, MAX8998_REG_STATUSM1, 0xff);
|
max8998_write_reg(max8998->i2c, MAX8998_REG_STATUSM1, 0xff);
|
||||||
max8998_write_reg(max8998->i2c, MAX8998_REG_STATUSM2, 0xff);
|
max8998_write_reg(max8998->i2c, MAX8998_REG_STATUSM2, 0xff);
|
||||||
|
|
||||||
/* register with genirq */
|
domain = irq_domain_add_simple(NULL, MAX8998_IRQ_NR,
|
||||||
for (i = 0; i < MAX8998_IRQ_NR; i++) {
|
max8998->irq_base, &max8998_irq_domain_ops, max8998);
|
||||||
cur_irq = i + max8998->irq_base;
|
if (!domain) {
|
||||||
irq_set_chip_data(cur_irq, max8998);
|
dev_err(max8998->dev, "could not create irq domain\n");
|
||||||
irq_set_chip_and_handler(cur_irq, &max8998_irq_chip,
|
return -ENODEV;
|
||||||
handle_edge_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
|
|
||||||
}
|
}
|
||||||
|
max8998->irq_domain = domain;
|
||||||
|
|
||||||
ret = request_threaded_irq(max8998->irq, NULL, max8998_irq_thread,
|
ret = request_threaded_irq(max8998->irq, NULL, max8998_irq_thread,
|
||||||
IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
|
IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include <linux/i2c.h>
|
#include <linux/i2c.h>
|
||||||
#include <linux/slab.h>
|
#include <linux/slab.h>
|
||||||
#include <linux/bcd.h>
|
#include <linux/bcd.h>
|
||||||
|
#include <linux/irqdomain.h>
|
||||||
#include <linux/rtc.h>
|
#include <linux/rtc.h>
|
||||||
#include <linux/platform_device.h>
|
#include <linux/platform_device.h>
|
||||||
#include <linux/mfd/max8998.h>
|
#include <linux/mfd/max8998.h>
|
||||||
|
@ -264,7 +265,6 @@ static int max8998_rtc_probe(struct platform_device *pdev)
|
||||||
info->dev = &pdev->dev;
|
info->dev = &pdev->dev;
|
||||||
info->max8998 = max8998;
|
info->max8998 = max8998;
|
||||||
info->rtc = max8998->rtc;
|
info->rtc = max8998->rtc;
|
||||||
info->irq = max8998->irq_base + MAX8998_IRQ_ALARM0;
|
|
||||||
|
|
||||||
platform_set_drvdata(pdev, info);
|
platform_set_drvdata(pdev, info);
|
||||||
|
|
||||||
|
@ -277,6 +277,15 @@ static int max8998_rtc_probe(struct platform_device *pdev)
|
||||||
goto out_rtc;
|
goto out_rtc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!max8998->irq_domain)
|
||||||
|
goto no_irq;
|
||||||
|
|
||||||
|
info->irq = irq_create_mapping(max8998->irq_domain, MAX8998_IRQ_ALARM0);
|
||||||
|
if (!info->irq) {
|
||||||
|
dev_warn(&pdev->dev, "Failed to map alarm IRQ\n");
|
||||||
|
goto no_irq;
|
||||||
|
}
|
||||||
|
|
||||||
ret = devm_request_threaded_irq(&pdev->dev, info->irq, NULL,
|
ret = devm_request_threaded_irq(&pdev->dev, info->irq, NULL,
|
||||||
max8998_rtc_alarm_irq, 0, "rtc-alarm0", info);
|
max8998_rtc_alarm_irq, 0, "rtc-alarm0", info);
|
||||||
|
|
||||||
|
@ -284,6 +293,7 @@ static int max8998_rtc_probe(struct platform_device *pdev)
|
||||||
dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n",
|
dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n",
|
||||||
info->irq, ret);
|
info->irq, ret);
|
||||||
|
|
||||||
|
no_irq:
|
||||||
dev_info(&pdev->dev, "RTC CHIP NAME: %s\n", pdev->id_entry->name);
|
dev_info(&pdev->dev, "RTC CHIP NAME: %s\n", pdev->id_entry->name);
|
||||||
if (pdata && pdata->rtc_delay) {
|
if (pdata && pdata->rtc_delay) {
|
||||||
info->lp3974_bug_workaround = true;
|
info->lp3974_bug_workaround = true;
|
||||||
|
|
|
@ -132,6 +132,8 @@ enum {
|
||||||
|
|
||||||
#define MAX8998_ENRAMP (1 << 4)
|
#define MAX8998_ENRAMP (1 << 4)
|
||||||
|
|
||||||
|
struct irq_domain;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* struct max8998_dev - max8998 master device for sub-drivers
|
* struct max8998_dev - max8998 master device for sub-drivers
|
||||||
* @dev: master device of the chip (can be used to access platform data)
|
* @dev: master device of the chip (can be used to access platform data)
|
||||||
|
@ -153,7 +155,8 @@ struct max8998_dev {
|
||||||
struct mutex iolock;
|
struct mutex iolock;
|
||||||
struct mutex irqlock;
|
struct mutex irqlock;
|
||||||
|
|
||||||
int irq_base;
|
unsigned int irq_base;
|
||||||
|
struct irq_domain *irq_domain;
|
||||||
int irq;
|
int irq;
|
||||||
int ono;
|
int ono;
|
||||||
u8 irq_masks_cur[MAX8998_NUM_IRQ_REGS];
|
u8 irq_masks_cur[MAX8998_NUM_IRQ_REGS];
|
||||||
|
|
|
@ -100,7 +100,7 @@ struct max8998_regulator_data {
|
||||||
struct max8998_platform_data {
|
struct max8998_platform_data {
|
||||||
struct max8998_regulator_data *regulators;
|
struct max8998_regulator_data *regulators;
|
||||||
int num_regulators;
|
int num_regulators;
|
||||||
int irq_base;
|
unsigned int irq_base;
|
||||||
int ono;
|
int ono;
|
||||||
bool buck_voltage_lock;
|
bool buck_voltage_lock;
|
||||||
int buck1_voltage1;
|
int buck1_voltage1;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче