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+
4970static struct rn5t618 * rn5t618_pm_power_off ;
5071static 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+
52101static 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
144195static 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+
158229static const struct i2c_device_id rn5t618_i2c_id [] = {
159230 { }
160231};
161232MODULE_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+
163238static 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 ,
0 commit comments