| @@ -8,6 +8,8 @@ · 7 unmodified lines |
| 8 | | 8 | |
| 9 | #include <linux/delay.h> | 9 | #include <linux/delay.h> |
| 10 | #include <linux/i2c.h> | 10 | #include <linux/i2c.h> |
| | 11 | #include <linux/interrupt.h> |
| | 12 | #include <linux/irq.h> |
| 11 | #include <linux/mfd/core.h> | 13 | #include <linux/mfd/core.h> |
| 12 | #include <linux/mfd/rn5t618.h> | 14 | #include <linux/mfd/rn5t618.h> |
| 13 | #include <linux/module.h> | 15 | #include <linux/module.h> |
| @@ -46,9 +48,56 @@ static const struct regmap_config rn5t618_regmap_config = { · 32 unmodified lines |
| 46 | .cache_type = REGCACHE_RBTREE, | 48 | .cache_type = REGCACHE_RBTREE, |
| 47 | }; | 49 | }; |
| 48 | | 50 | |
| | 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 | |
| 49 | static struct rn5t618 *rn5t618_pm_power_off; | 70 | static struct rn5t618 *rn5t618_pm_power_off; |
| 50 | static struct notifier_block rn5t618_restart_handler; | 71 | static struct notifier_block rn5t618_restart_handler; |
| 51 | | 72 | |
| | 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 | |
| 52 | static void rn5t618_trigger_poweroff_sequence(bool repower) | 101 | static void rn5t618_trigger_poweroff_sequence(bool repower) |
| 53 | { | 102 | { |
| 54 | /* disable automatic repower-on */ | 103 | /* disable automatic repower-on */ |
| @@ -106,6 +155,8 @@ static int rn5t618_i2c_probe(struct i2c_client *i2c, · 51 unmodified lines |
| 106 | | 155 | |
| 107 | i2c_set_clientdata(i2c, priv); | 156 | i2c_set_clientdata(i2c, priv); |
| 108 | priv->variant = (long)of_id->data; | 157 | priv->variant = (long)of_id->data; |
| | 158 | priv->irq = i2c->irq; |
| | 159 | priv->dev = &i2c->dev; |
| 109 | | 160 | |
| 110 | priv->regmap = devm_regmap_init_i2c(i2c, &rn5t618_regmap_config); | 161 | priv->regmap = devm_regmap_init_i2c(i2c, &rn5t618_regmap_config); |
| 111 | if (IS_ERR(priv->regmap)) { | 162 | if (IS_ERR(priv->regmap)) { |
| @@ -138,7 +189,7 @@ static int rn5t618_i2c_probe(struct i2c_client *i2c, · 26 unmodified lines |
| 138 | return ret; | 189 | return ret; |
| 139 | } | 190 | } |
| 140 | | 191 | |
| 141 | return 0; | 192 | return rn5t618_irq_init(priv); |
| 142 | } | 193 | } |
| 143 | | 194 | |
| 144 | static int rn5t618_i2c_remove(struct i2c_client *i2c) | 195 | static int rn5t618_i2c_remove(struct i2c_client *i2c) |
| @@ -155,15 +206,40 @@ static int rn5t618_i2c_remove(struct i2c_client *i2c) · 10 unmodified lines |
| 155 | return 0; | 206 | return 0; |
| 156 | } | 207 | } |
| 157 | | 208 | |
| | 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 | |
| 158 | static const struct i2c_device_id rn5t618_i2c_id[] = { | 229 | static const struct i2c_device_id rn5t618_i2c_id[] = { |
| 159 | { } | 230 | { } |
| 160 | }; | 231 | }; |
| 161 | MODULE_DEVICE_TABLE(i2c, rn5t618_i2c_id); | 232 | MODULE_DEVICE_TABLE(i2c, rn5t618_i2c_id); |
| 162 | | 233 | |
| | 234 | static SIMPLE_DEV_PM_OPS(rn5t618_i2c_dev_pm_ops, |
| | 235 | rn5t618_i2c_suspend, |
| | 236 | rn5t618_i2c_resume); |
| | 237 | |
| 163 | static struct i2c_driver rn5t618_i2c_driver = { | 238 | static struct i2c_driver rn5t618_i2c_driver = { |
| 164 | .driver = { | 239 | .driver = { |
| 165 | .name = "rn5t618", | 240 | .name = "rn5t618", |
| 166 | .of_match_table = of_match_ptr(rn5t618_of_match), | 241 | .of_match_table = of_match_ptr(rn5t618_of_match), |
| | 242 | .pm = &rn5t618_i2c_dev_pm_ops, |
| 167 | }, | 243 | }, |
| 168 | .probe = rn5t618_i2c_probe, | 244 | .probe = rn5t618_i2c_probe, |
| 169 | .remove = rn5t618_i2c_remove, | 245 | .remove = rn5t618_i2c_remove, |