Skip to content

Commit 4e405ae

Browse files
Qing XuSamuel Ortiz
authored andcommitted
mfd: max8925: Add irqdomain for dt
Add irqdomains for max8925's main irq, wrap irq register operations into irqdomain's map func. it is necessary for dt support. Also, add dt support for max8925 driver. Signed-off-by: Qing Xu <qingx@marvell.com> Signed-off-by: Haojian Zhuang <haojian.zhuang@gmail.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
1 parent dcd560c commit 4e405ae

3 files changed

Lines changed: 78 additions & 34 deletions

File tree

‎drivers/mfd/max8925-core.c‎

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@
1414
#include <linux/i2c.h>
1515
#include <linux/irq.h>
1616
#include <linux/interrupt.h>
17+
#include <linux/irqdomain.h>
1718
#include <linux/platform_device.h>
1819
#include <linux/regulator/machine.h>
1920
#include <linux/mfd/core.h>
2021
#include <linux/mfd/max8925.h>
22+
#include <linux/of.h>
23+
#include <linux/of_platform.h>
2124

2225
static struct resource bk_resources[] = {
2326
{ 0x84, 0x84, "mode control", IORESOURCE_REG, },
@@ -639,17 +642,33 @@ static struct irq_chip max8925_irq_chip = {
639642
.irq_disable = max8925_irq_disable,
640643
};
641644

645+
static int max8925_irq_domain_map(struct irq_domain *d, unsigned int virq,
646+
irq_hw_number_t hw)
647+
{
648+
irq_set_chip_data(virq, d->host_data);
649+
irq_set_chip_and_handler(virq, &max8925_irq_chip, handle_edge_irq);
650+
irq_set_nested_thread(virq, 1);
651+
#ifdef CONFIG_ARM
652+
set_irq_flags(virq, IRQF_VALID);
653+
#else
654+
irq_set_noprobe(virq);
655+
#endif
656+
return 0;
657+
}
658+
659+
static struct irq_domain_ops max8925_irq_domain_ops = {
660+
.map = max8925_irq_domain_map,
661+
.xlate = irq_domain_xlate_onetwocell,
662+
};
663+
664+
642665
static int max8925_irq_init(struct max8925_chip *chip, int irq,
643666
struct max8925_platform_data *pdata)
644667
{
645668
unsigned long flags = IRQF_TRIGGER_FALLING | IRQF_ONESHOT;
646-
int i, ret;
647-
int __irq;
669+
int ret;
670+
struct device_node *node = chip->dev->of_node;
648671

649-
if (!pdata || !pdata->irq_base) {
650-
dev_warn(chip->dev, "No interrupt support on IRQ base\n");
651-
return -EINVAL;
652-
}
653672
/* clear all interrupts */
654673
max8925_reg_read(chip->i2c, MAX8925_CHG_IRQ1);
655674
max8925_reg_read(chip->i2c, MAX8925_CHG_IRQ2);
@@ -667,35 +686,30 @@ static int max8925_irq_init(struct max8925_chip *chip, int irq,
667686
max8925_reg_write(chip->rtc, MAX8925_RTC_IRQ_MASK, 0xff);
668687

669688
mutex_init(&chip->irq_lock);
670-
chip->core_irq = irq;
671-
chip->irq_base = pdata->irq_base;
672-
673-
/* register with genirq */
674-
for (i = 0; i < ARRAY_SIZE(max8925_irqs); i++) {
675-
__irq = i + chip->irq_base;
676-
irq_set_chip_data(__irq, chip);
677-
irq_set_chip_and_handler(__irq, &max8925_irq_chip,
678-
handle_edge_irq);
679-
irq_set_nested_thread(__irq, 1);
680-
#ifdef CONFIG_ARM
681-
set_irq_flags(__irq, IRQF_VALID);
682-
#else
683-
irq_set_noprobe(__irq);
684-
#endif
685-
}
686-
if (!irq) {
687-
dev_warn(chip->dev, "No interrupt support on core IRQ\n");
688-
goto tsc_irq;
689+
chip->irq_base = irq_alloc_descs(-1, 0, MAX8925_NR_IRQS, 0);
690+
if (chip->irq_base < 0) {
691+
dev_err(chip->dev, "Failed to allocate interrupts, ret:%d\n",
692+
chip->irq_base);
693+
return -EBUSY;
689694
}
690695

696+
irq_domain_add_legacy(node, MAX8925_NR_IRQS, chip->irq_base, 0,
697+
&max8925_irq_domain_ops, chip);
698+
699+
/* request irq handler for pmic main irq*/
700+
chip->core_irq = irq;
701+
if (!chip->core_irq)
702+
return -EBUSY;
691703
ret = request_threaded_irq(irq, NULL, max8925_irq, flags | IRQF_ONESHOT,
692704
"max8925", chip);
693705
if (ret) {
694706
dev_err(chip->dev, "Failed to request core IRQ: %d\n", ret);
695707
chip->core_irq = 0;
708+
return -EBUSY;
696709
}
697710

698-
tsc_irq:
711+
/* request irq handler for pmic tsc irq*/
712+
699713
/* mask TSC interrupt */
700714
max8925_reg_write(chip->adc, MAX8925_TSC_IRQ_MASK, 0x0f);
701715

@@ -704,7 +718,6 @@ static int max8925_irq_init(struct max8925_chip *chip, int irq,
704718
return 0;
705719
}
706720
chip->tsc_irq = pdata->tsc_irq;
707-
708721
ret = request_threaded_irq(chip->tsc_irq, NULL, max8925_tsc_irq,
709722
flags | IRQF_ONESHOT, "max8925-tsc", chip);
710723
if (ret) {
@@ -875,11 +888,11 @@ int max8925_device_init(struct max8925_chip *chip,
875888

876889
if (pdata && pdata->power) {
877890
ret = mfd_add_devices(chip->dev, 0, &power_devs[0],
878-
ARRAY_SIZE(power_devs),
891+
ARRAY_SIZE(power_devs),
879892
&power_supply_resources[0], 0, NULL);
880893
if (ret < 0) {
881-
dev_err(chip->dev, "Failed to add power supply "
882-
"subdev\n");
894+
dev_err(chip->dev,
895+
"Failed to add power supply subdev\n");
883896
goto out_dev;
884897
}
885898
}

‎drivers/mfd/max8925-i2c.c‎

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,37 @@ static const struct i2c_device_id max8925_id_table[] = {
135135
};
136136
MODULE_DEVICE_TABLE(i2c, max8925_id_table);
137137

138+
static int max8925_dt_init(struct device_node *np, struct device *dev,
139+
struct max8925_platform_data *pdata)
140+
{
141+
int ret;
142+
143+
ret = of_property_read_u32(np, "maxim,tsc-irq", &pdata->tsc_irq);
144+
if (ret) {
145+
dev_err(dev, "Not found maxim,tsc-irq property\n");
146+
return -EINVAL;
147+
}
148+
return 0;
149+
}
150+
138151
static int max8925_probe(struct i2c_client *client,
139152
const struct i2c_device_id *id)
140153
{
141154
struct max8925_platform_data *pdata = client->dev.platform_data;
142155
static struct max8925_chip *chip;
143-
144-
if (!pdata) {
156+
struct device_node *node = client->dev.of_node;
157+
158+
if (node && !pdata) {
159+
/* parse DT to get platform data */
160+
pdata = devm_kzalloc(&client->dev,
161+
sizeof(struct max8925_platform_data),
162+
GFP_KERNEL);
163+
if (!pdata)
164+
return -ENOMEM;
165+
166+
if (max8925_dt_init(node, &client->dev, pdata))
167+
return -EINVAL;
168+
} else if (!pdata) {
145169
pr_info("%s: platform data is missing\n", __func__);
146170
return -EINVAL;
147171
}
@@ -203,11 +227,18 @@ static int max8925_resume(struct device *dev)
203227

204228
static SIMPLE_DEV_PM_OPS(max8925_pm_ops, max8925_suspend, max8925_resume);
205229

230+
static const struct of_device_id max8925_dt_ids[] = {
231+
{ .compatible = "maxim,max8925", },
232+
{},
233+
};
234+
MODULE_DEVICE_TABLE(of, max8925_dt_ids);
235+
206236
static struct i2c_driver max8925_driver = {
207237
.driver = {
208238
.name = "max8925",
209239
.owner = THIS_MODULE,
210240
.pm = &max8925_pm_ops,
241+
.of_match_table = of_match_ptr(max8925_dt_ids),
211242
},
212243
.probe = max8925_probe,
213244
.remove = max8925_remove,
@@ -217,7 +248,6 @@ static struct i2c_driver max8925_driver = {
217248
static int __init max8925_i2c_init(void)
218249
{
219250
int ret;
220-
221251
ret = i2c_add_driver(&max8925_driver);
222252
if (ret != 0)
223253
pr_err("Failed to register MAX8925 I2C driver: %d\n", ret);

‎include/linux/mfd/max8925.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ enum {
190190
MAX8925_NR_IRQS,
191191
};
192192

193+
194+
193195
struct max8925_chip {
194196
struct device *dev;
195197
struct i2c_client *i2c;
@@ -201,7 +203,6 @@ struct max8925_chip {
201203
int irq_base;
202204
int core_irq;
203205
int tsc_irq;
204-
205206
unsigned int wakeup_flag;
206207
};
207208

0 commit comments

Comments
 (0)