Skip to content

Commit 0c81604

Browse files
akemnadeLee Jones
authored andcommitted
mfd: rn5t618: Add IRQ support
This adds support for IRQ handling in the RC5T619 which is required for properly implementing subdevices like RTC. For now only definitions for the variant RC5T619 are included. Signed-off-by: Andreas Kemnade <andreas@kemnade.info> Signed-off-by: Lee Jones <lee.jones@linaro.org>
1 parent 361dca7 commit 0c81604

3 files changed

Lines changed: 93 additions & 1 deletion

File tree

‎drivers/mfd/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,7 @@ config MFD_RN5T618
10581058
depends on OF
10591059
select MFD_CORE
10601060
select REGMAP_I2C
1061+
select REGMAP_IRQ
10611062
help
10621063
Say yes here to add support for the Ricoh RN5T567,
10631064
RN5T618, RC5T619 PMIC.

‎drivers/mfd/rn5t618.c‎

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#include <linux/delay.h>
1010
#include <linux/i2c.h>
11+
#include <linux/interrupt.h>
12+
#include <linux/irq.h>
1113
#include <linux/mfd/core.h>
1214
#include <linux/mfd/rn5t618.h>
1315
#include <linux/module.h>
@@ -46,9 +48,56 @@ static const struct regmap_config rn5t618_regmap_config = {
4648
.cache_type = REGCACHE_RBTREE,
4749
};
4850

51+
static const struct regmap_irq rc5t619_irqs[] = {
52+
REGMAP_IRQ_REG(RN5T618_IRQ_SYS, 0, BIT(0)),
53+
REGMAP_IRQ_REG(RN5T618_IRQ_DCDC, 0, BIT(1)),
54+
REGMAP_IRQ_REG(RN5T618_IRQ_RTC, 0, BIT(2)),
55+
REGMAP_IRQ_REG(RN5T618_IRQ_ADC, 0, BIT(3)),
56+
REGMAP_IRQ_REG(RN5T618_IRQ_GPIO, 0, BIT(4)),
57+
REGMAP_IRQ_REG(RN5T618_IRQ_CHG, 0, BIT(6)),
58+
};
59+
60+
static const struct regmap_irq_chip rc5t619_irq_chip = {
61+
.name = "rc5t619",
62+
.irqs = rc5t619_irqs,
63+
.num_irqs = ARRAY_SIZE(rc5t619_irqs),
64+
.num_regs = 1,
65+
.status_base = RN5T618_INTMON,
66+
.mask_base = RN5T618_INTEN,
67+
.mask_invert = true,
68+
};
69+
4970
static struct rn5t618 *rn5t618_pm_power_off;
5071
static struct notifier_block rn5t618_restart_handler;
5172

73+
static int rn5t618_irq_init(struct rn5t618 *rn5t618)
74+
{
75+
const struct regmap_irq_chip *irq_chip = NULL;
76+
int ret;
77+
78+
if (!rn5t618->irq)
79+
return 0;
80+
81+
switch (rn5t618->variant) {
82+
case RC5T619:
83+
irq_chip = &rc5t619_irq_chip;
84+
break;
85+
default:
86+
dev_err(rn5t618->dev, "Currently no IRQ support for variant %d\n",
87+
(int)rn5t618->variant);
88+
return -ENOENT;
89+
}
90+
91+
ret = devm_regmap_add_irq_chip(rn5t618->dev, rn5t618->regmap,
92+
rn5t618->irq,
93+
IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
94+
0, irq_chip, &rn5t618->irq_data);
95+
if (ret)
96+
dev_err(rn5t618->dev, "Failed to register IRQ chip\n");
97+
98+
return ret;
99+
}
100+
52101
static void rn5t618_trigger_poweroff_sequence(bool repower)
53102
{
54103
/* disable automatic repower-on */
@@ -106,6 +155,8 @@ static int rn5t618_i2c_probe(struct i2c_client *i2c,
106155

107156
i2c_set_clientdata(i2c, priv);
108157
priv->variant = (long)of_id->data;
158+
priv->irq = i2c->irq;
159+
priv->dev = &i2c->dev;
109160

110161
priv->regmap = devm_regmap_init_i2c(i2c, &rn5t618_regmap_config);
111162
if (IS_ERR(priv->regmap)) {
@@ -138,7 +189,7 @@ static int rn5t618_i2c_probe(struct i2c_client *i2c,
138189
return ret;
139190
}
140191

141-
return 0;
192+
return rn5t618_irq_init(priv);
142193
}
143194

144195
static int rn5t618_i2c_remove(struct i2c_client *i2c)
@@ -155,15 +206,40 @@ static int rn5t618_i2c_remove(struct i2c_client *i2c)
155206
return 0;
156207
}
157208

209+
static int __maybe_unused rn5t618_i2c_suspend(struct device *dev)
210+
{
211+
struct rn5t618 *priv = dev_get_drvdata(dev);
212+
213+
if (priv->irq)
214+
disable_irq(priv->irq);
215+
216+
return 0;
217+
}
218+
219+
static int __maybe_unused rn5t618_i2c_resume(struct device *dev)
220+
{
221+
struct rn5t618 *priv = dev_get_drvdata(dev);
222+
223+
if (priv->irq)
224+
enable_irq(priv->irq);
225+
226+
return 0;
227+
}
228+
158229
static const struct i2c_device_id rn5t618_i2c_id[] = {
159230
{ }
160231
};
161232
MODULE_DEVICE_TABLE(i2c, rn5t618_i2c_id);
162233

234+
static SIMPLE_DEV_PM_OPS(rn5t618_i2c_dev_pm_ops,
235+
rn5t618_i2c_suspend,
236+
rn5t618_i2c_resume);
237+
163238
static struct i2c_driver rn5t618_i2c_driver = {
164239
.driver = {
165240
.name = "rn5t618",
166241
.of_match_table = of_match_ptr(rn5t618_of_match),
242+
.pm = &rn5t618_i2c_dev_pm_ops,
167243
},
168244
.probe = rn5t618_i2c_probe,
169245
.remove = rn5t618_i2c_remove,

‎include/linux/mfd/rn5t618.h‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,24 @@ enum {
242242
RC5T619,
243243
};
244244

245+
/* RN5T618 IRQ definitions */
246+
enum {
247+
RN5T618_IRQ_SYS = 0,
248+
RN5T618_IRQ_DCDC,
249+
RN5T618_IRQ_RTC,
250+
RN5T618_IRQ_ADC,
251+
RN5T618_IRQ_GPIO,
252+
RN5T618_IRQ_CHG,
253+
RN5T618_NR_IRQS,
254+
};
255+
245256
struct rn5t618 {
246257
struct regmap *regmap;
258+
struct device *dev;
247259
long variant;
260+
261+
int irq;
262+
struct regmap_irq_chip_data *irq_data;
248263
};
249264

250265
#endif /* __LINUX_MFD_RN5T618_H */

0 commit comments

Comments
 (0)