Jonghwa Lee | dae8a96 | 2012-06-25 10:34:36 +0200 | [diff] [blame] | 1 | /* |
Javier Martinez Canillas | a259f38 | 2014-07-24 14:39:24 +0200 | [diff] [blame] | 2 | * max77686.c - mfd core driver for the Maxim 77686/802 |
Jonghwa Lee | dae8a96 | 2012-06-25 10:34:36 +0200 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2012 Samsung Electronics |
| 5 | * Chiwoong Byun <woong.byun@smasung.com> |
| 6 | * Jonghwa Lee <jonghwa3.lee@samsung.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 21 | * |
| 22 | * This driver is based on max8997.c |
| 23 | */ |
| 24 | |
| 25 | #include <linux/export.h> |
| 26 | #include <linux/slab.h> |
| 27 | #include <linux/i2c.h> |
Javier Martinez Canillas | 6f1c1e7 | 2014-07-04 22:24:04 +0200 | [diff] [blame] | 28 | #include <linux/irq.h> |
| 29 | #include <linux/interrupt.h> |
Jonghwa Lee | dae8a96 | 2012-06-25 10:34:36 +0200 | [diff] [blame] | 30 | #include <linux/pm_runtime.h> |
| 31 | #include <linux/module.h> |
Jonghwa Lee | dae8a96 | 2012-06-25 10:34:36 +0200 | [diff] [blame] | 32 | #include <linux/mfd/core.h> |
| 33 | #include <linux/mfd/max77686.h> |
| 34 | #include <linux/mfd/max77686-private.h> |
| 35 | #include <linux/err.h> |
Sachin Kamat | 2a048d3 | 2013-10-16 14:26:49 +0530 | [diff] [blame] | 36 | #include <linux/of.h> |
Jonghwa Lee | dae8a96 | 2012-06-25 10:34:36 +0200 | [diff] [blame] | 37 | |
| 38 | #define I2C_ADDR_RTC (0x0C >> 1) |
| 39 | |
Geert Uytterhoeven | 7c0517b | 2013-11-18 14:33:00 +0100 | [diff] [blame] | 40 | static const struct mfd_cell max77686_devs[] = { |
Jonghwa Lee | dae8a96 | 2012-06-25 10:34:36 +0200 | [diff] [blame] | 41 | { .name = "max77686-pmic", }, |
| 42 | { .name = "max77686-rtc", }, |
Olof Johansson | c0fa7e1 | 2013-05-10 10:11:59 -0700 | [diff] [blame] | 43 | { .name = "max77686-clk", }, |
Jonghwa Lee | dae8a96 | 2012-06-25 10:34:36 +0200 | [diff] [blame] | 44 | }; |
| 45 | |
Javier Martinez Canillas | a259f38 | 2014-07-24 14:39:24 +0200 | [diff] [blame] | 46 | static const struct mfd_cell max77802_devs[] = { |
| 47 | { .name = "max77802-pmic", }, |
| 48 | { .name = "max77802-clk", }, |
| 49 | { .name = "max77802-rtc", }, |
| 50 | }; |
| 51 | |
| 52 | static bool max77802_pmic_is_accessible_reg(struct device *dev, |
| 53 | unsigned int reg) |
| 54 | { |
Lee Jones | b87d9a0 | 2014-08-18 15:41:59 +0100 | [diff] [blame] | 55 | return reg < MAX77802_REG_PMIC_END; |
Javier Martinez Canillas | a259f38 | 2014-07-24 14:39:24 +0200 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | static bool max77802_rtc_is_accessible_reg(struct device *dev, |
| 59 | unsigned int reg) |
| 60 | { |
| 61 | return (reg >= MAX77802_RTC_INT && reg < MAX77802_RTC_END); |
| 62 | } |
| 63 | |
| 64 | static bool max77802_is_accessible_reg(struct device *dev, unsigned int reg) |
| 65 | { |
| 66 | return (max77802_pmic_is_accessible_reg(dev, reg) || |
| 67 | max77802_rtc_is_accessible_reg(dev, reg)); |
| 68 | } |
| 69 | |
| 70 | static bool max77802_pmic_is_precious_reg(struct device *dev, unsigned int reg) |
| 71 | { |
| 72 | return (reg == MAX77802_REG_INTSRC || reg == MAX77802_REG_INT1 || |
| 73 | reg == MAX77802_REG_INT2); |
| 74 | } |
| 75 | |
| 76 | static bool max77802_rtc_is_precious_reg(struct device *dev, unsigned int reg) |
| 77 | { |
| 78 | return (reg == MAX77802_RTC_INT || |
| 79 | reg == MAX77802_RTC_UPDATE0 || |
| 80 | reg == MAX77802_RTC_UPDATE1); |
| 81 | } |
| 82 | |
| 83 | static bool max77802_is_precious_reg(struct device *dev, unsigned int reg) |
| 84 | { |
| 85 | return (max77802_pmic_is_precious_reg(dev, reg) || |
| 86 | max77802_rtc_is_precious_reg(dev, reg)); |
| 87 | } |
| 88 | |
| 89 | static bool max77802_pmic_is_volatile_reg(struct device *dev, unsigned int reg) |
| 90 | { |
| 91 | return (max77802_is_precious_reg(dev, reg) || |
| 92 | reg == MAX77802_REG_STATUS1 || reg == MAX77802_REG_STATUS2 || |
| 93 | reg == MAX77802_REG_PWRON); |
| 94 | } |
| 95 | |
| 96 | static bool max77802_rtc_is_volatile_reg(struct device *dev, unsigned int reg) |
| 97 | { |
| 98 | return (max77802_rtc_is_precious_reg(dev, reg) || |
| 99 | reg == MAX77802_RTC_SEC || |
| 100 | reg == MAX77802_RTC_MIN || |
| 101 | reg == MAX77802_RTC_HOUR || |
| 102 | reg == MAX77802_RTC_WEEKDAY || |
| 103 | reg == MAX77802_RTC_MONTH || |
| 104 | reg == MAX77802_RTC_YEAR || |
| 105 | reg == MAX77802_RTC_DATE); |
| 106 | } |
| 107 | |
| 108 | static bool max77802_is_volatile_reg(struct device *dev, unsigned int reg) |
| 109 | { |
| 110 | return (max77802_pmic_is_volatile_reg(dev, reg) || |
| 111 | max77802_rtc_is_volatile_reg(dev, reg)); |
| 112 | } |
| 113 | |
Krzysztof Kozlowski | 68be231 | 2015-01-05 10:01:25 +0100 | [diff] [blame] | 114 | static const struct regmap_config max77686_regmap_config = { |
Jonghwa Lee | dae8a96 | 2012-06-25 10:34:36 +0200 | [diff] [blame] | 115 | .reg_bits = 8, |
| 116 | .val_bits = 8, |
| 117 | }; |
| 118 | |
Krzysztof Kozlowski | 68be231 | 2015-01-05 10:01:25 +0100 | [diff] [blame] | 119 | static const struct regmap_config max77686_rtc_regmap_config = { |
Javier Martinez Canillas | 6f1c1e7 | 2014-07-04 22:24:04 +0200 | [diff] [blame] | 120 | .reg_bits = 8, |
| 121 | .val_bits = 8, |
| 122 | }; |
| 123 | |
Krzysztof Kozlowski | 68be231 | 2015-01-05 10:01:25 +0100 | [diff] [blame] | 124 | static const struct regmap_config max77802_regmap_config = { |
Javier Martinez Canillas | a259f38 | 2014-07-24 14:39:24 +0200 | [diff] [blame] | 125 | .reg_bits = 8, |
| 126 | .val_bits = 8, |
| 127 | .writeable_reg = max77802_is_accessible_reg, |
| 128 | .readable_reg = max77802_is_accessible_reg, |
| 129 | .precious_reg = max77802_is_precious_reg, |
| 130 | .volatile_reg = max77802_is_volatile_reg, |
| 131 | .name = "max77802-pmic", |
| 132 | .cache_type = REGCACHE_RBTREE, |
| 133 | }; |
| 134 | |
Javier Martinez Canillas | 6f1c1e7 | 2014-07-04 22:24:04 +0200 | [diff] [blame] | 135 | static const struct regmap_irq max77686_irqs[] = { |
| 136 | /* INT1 interrupts */ |
| 137 | { .reg_offset = 0, .mask = MAX77686_INT1_PWRONF_MSK, }, |
| 138 | { .reg_offset = 0, .mask = MAX77686_INT1_PWRONR_MSK, }, |
| 139 | { .reg_offset = 0, .mask = MAX77686_INT1_JIGONBF_MSK, }, |
| 140 | { .reg_offset = 0, .mask = MAX77686_INT1_JIGONBR_MSK, }, |
| 141 | { .reg_offset = 0, .mask = MAX77686_INT1_ACOKBF_MSK, }, |
| 142 | { .reg_offset = 0, .mask = MAX77686_INT1_ACOKBR_MSK, }, |
| 143 | { .reg_offset = 0, .mask = MAX77686_INT1_ONKEY1S_MSK, }, |
| 144 | { .reg_offset = 0, .mask = MAX77686_INT1_MRSTB_MSK, }, |
| 145 | /* INT2 interrupts */ |
| 146 | { .reg_offset = 1, .mask = MAX77686_INT2_140C_MSK, }, |
| 147 | { .reg_offset = 1, .mask = MAX77686_INT2_120C_MSK, }, |
| 148 | }; |
| 149 | |
| 150 | static const struct regmap_irq_chip max77686_irq_chip = { |
| 151 | .name = "max77686-pmic", |
| 152 | .status_base = MAX77686_REG_INT1, |
| 153 | .mask_base = MAX77686_REG_INT1MSK, |
| 154 | .num_regs = 2, |
| 155 | .irqs = max77686_irqs, |
| 156 | .num_irqs = ARRAY_SIZE(max77686_irqs), |
| 157 | }; |
| 158 | |
| 159 | static const struct regmap_irq max77686_rtc_irqs[] = { |
| 160 | /* RTC interrupts */ |
| 161 | { .reg_offset = 0, .mask = MAX77686_RTCINT_RTC60S_MSK, }, |
| 162 | { .reg_offset = 0, .mask = MAX77686_RTCINT_RTCA1_MSK, }, |
| 163 | { .reg_offset = 0, .mask = MAX77686_RTCINT_RTCA2_MSK, }, |
| 164 | { .reg_offset = 0, .mask = MAX77686_RTCINT_SMPL_MSK, }, |
| 165 | { .reg_offset = 0, .mask = MAX77686_RTCINT_RTC1S_MSK, }, |
| 166 | { .reg_offset = 0, .mask = MAX77686_RTCINT_WTSR_MSK, }, |
| 167 | }; |
| 168 | |
| 169 | static const struct regmap_irq_chip max77686_rtc_irq_chip = { |
| 170 | .name = "max77686-rtc", |
| 171 | .status_base = MAX77686_RTC_INT, |
| 172 | .mask_base = MAX77686_RTC_INTM, |
| 173 | .num_regs = 1, |
| 174 | .irqs = max77686_rtc_irqs, |
| 175 | .num_irqs = ARRAY_SIZE(max77686_rtc_irqs), |
| 176 | }; |
| 177 | |
Javier Martinez Canillas | a259f38 | 2014-07-24 14:39:24 +0200 | [diff] [blame] | 178 | static const struct regmap_irq_chip max77802_irq_chip = { |
| 179 | .name = "max77802-pmic", |
| 180 | .status_base = MAX77802_REG_INT1, |
| 181 | .mask_base = MAX77802_REG_INT1MSK, |
| 182 | .num_regs = 2, |
| 183 | .irqs = max77686_irqs, /* same masks as 77686 */ |
| 184 | .num_irqs = ARRAY_SIZE(max77686_irqs), |
| 185 | }; |
| 186 | |
| 187 | static const struct regmap_irq_chip max77802_rtc_irq_chip = { |
| 188 | .name = "max77802-rtc", |
| 189 | .status_base = MAX77802_RTC_INT, |
| 190 | .mask_base = MAX77802_RTC_INTM, |
| 191 | .num_regs = 1, |
| 192 | .irqs = max77686_rtc_irqs, /* same masks as 77686 */ |
| 193 | .num_irqs = ARRAY_SIZE(max77686_rtc_irqs), |
| 194 | }; |
| 195 | |
Krzysztof Kozlowski | b68ece3 | 2014-05-13 12:58:51 +0200 | [diff] [blame] | 196 | static const struct of_device_id max77686_pmic_dt_match[] = { |
Javier Martinez Canillas | a259f38 | 2014-07-24 14:39:24 +0200 | [diff] [blame] | 197 | { |
| 198 | .compatible = "maxim,max77686", |
| 199 | .data = (void *)TYPE_MAX77686, |
| 200 | }, |
| 201 | { |
| 202 | .compatible = "maxim,max77802", |
| 203 | .data = (void *)TYPE_MAX77802, |
| 204 | }, |
| 205 | { }, |
Axel Lin | 2984fc0 | 2012-07-09 22:29:00 +0800 | [diff] [blame] | 206 | }; |
| 207 | |
Jonghwa Lee | dae8a96 | 2012-06-25 10:34:36 +0200 | [diff] [blame] | 208 | static int max77686_i2c_probe(struct i2c_client *i2c, |
| 209 | const struct i2c_device_id *id) |
| 210 | { |
Yadwinder Singh Brar | c1516f8 | 2012-07-06 17:02:55 +0530 | [diff] [blame] | 211 | struct max77686_dev *max77686 = NULL; |
Javier Martinez Canillas | a259f38 | 2014-07-24 14:39:24 +0200 | [diff] [blame] | 212 | const struct of_device_id *match; |
Jonghwa Lee | dae8a96 | 2012-06-25 10:34:36 +0200 | [diff] [blame] | 213 | unsigned int data; |
| 214 | int ret = 0; |
Javier Martinez Canillas | a259f38 | 2014-07-24 14:39:24 +0200 | [diff] [blame] | 215 | const struct regmap_config *config; |
| 216 | const struct regmap_irq_chip *irq_chip; |
| 217 | const struct regmap_irq_chip *rtc_irq_chip; |
| 218 | struct regmap **rtc_regmap; |
| 219 | const struct mfd_cell *cells; |
| 220 | int n_devs; |
Jonghwa Lee | dae8a96 | 2012-06-25 10:34:36 +0200 | [diff] [blame] | 221 | |
Lee Jones | 742413a | 2013-05-23 16:25:16 +0100 | [diff] [blame] | 222 | max77686 = devm_kzalloc(&i2c->dev, |
| 223 | sizeof(struct max77686_dev), GFP_KERNEL); |
Javier Martinez Canillas | c0e0fcd | 2014-07-04 22:24:09 +0200 | [diff] [blame] | 224 | if (!max77686) |
Jonghwa Lee | dae8a96 | 2012-06-25 10:34:36 +0200 | [diff] [blame] | 225 | return -ENOMEM; |
| 226 | |
Javier Martinez Canillas | a259f38 | 2014-07-24 14:39:24 +0200 | [diff] [blame] | 227 | if (i2c->dev.of_node) { |
| 228 | match = of_match_node(max77686_pmic_dt_match, i2c->dev.of_node); |
| 229 | if (!match) |
| 230 | return -EINVAL; |
| 231 | |
Lee Jones | ec8bd56 | 2014-07-24 17:07:16 +0100 | [diff] [blame] | 232 | max77686->type = (unsigned long)match->data; |
| 233 | } else |
Javier Martinez Canillas | a259f38 | 2014-07-24 14:39:24 +0200 | [diff] [blame] | 234 | max77686->type = id->driver_data; |
Javier Martinez Canillas | a259f38 | 2014-07-24 14:39:24 +0200 | [diff] [blame] | 235 | |
Jonghwa Lee | dae8a96 | 2012-06-25 10:34:36 +0200 | [diff] [blame] | 236 | i2c_set_clientdata(i2c, max77686); |
| 237 | max77686->dev = &i2c->dev; |
| 238 | max77686->i2c = i2c; |
Jonghwa Lee | dae8a96 | 2012-06-25 10:34:36 +0200 | [diff] [blame] | 239 | |
Yadwinder Singh Brar | 2b40459 | 2012-07-09 13:21:45 +0200 | [diff] [blame] | 240 | max77686->irq = i2c->irq; |
Jonghwa Lee | dae8a96 | 2012-06-25 10:34:36 +0200 | [diff] [blame] | 241 | |
Javier Martinez Canillas | a259f38 | 2014-07-24 14:39:24 +0200 | [diff] [blame] | 242 | if (max77686->type == TYPE_MAX77686) { |
| 243 | config = &max77686_regmap_config; |
| 244 | irq_chip = &max77686_irq_chip; |
| 245 | rtc_irq_chip = &max77686_rtc_irq_chip; |
| 246 | rtc_regmap = &max77686->rtc_regmap; |
| 247 | cells = max77686_devs; |
| 248 | n_devs = ARRAY_SIZE(max77686_devs); |
| 249 | } else { |
| 250 | config = &max77802_regmap_config; |
| 251 | irq_chip = &max77802_irq_chip; |
| 252 | rtc_irq_chip = &max77802_rtc_irq_chip; |
| 253 | rtc_regmap = &max77686->regmap; |
| 254 | cells = max77802_devs; |
| 255 | n_devs = ARRAY_SIZE(max77802_devs); |
| 256 | } |
| 257 | |
| 258 | max77686->regmap = devm_regmap_init_i2c(i2c, config); |
Axel Lin | 136d982 | 2012-12-25 00:16:43 +0800 | [diff] [blame] | 259 | if (IS_ERR(max77686->regmap)) { |
| 260 | ret = PTR_ERR(max77686->regmap); |
| 261 | dev_err(max77686->dev, "Failed to allocate register map: %d\n", |
| 262 | ret); |
Axel Lin | 136d982 | 2012-12-25 00:16:43 +0800 | [diff] [blame] | 263 | return ret; |
| 264 | } |
| 265 | |
Javier Martinez Canillas | c0e0fcd | 2014-07-04 22:24:09 +0200 | [diff] [blame] | 266 | ret = regmap_read(max77686->regmap, MAX77686_REG_DEVICE_ID, &data); |
| 267 | if (ret < 0) { |
Jonghwa Lee | dae8a96 | 2012-06-25 10:34:36 +0200 | [diff] [blame] | 268 | dev_err(max77686->dev, |
| 269 | "device not found on this channel (this is not an error)\n"); |
Lee Jones | 742413a | 2013-05-23 16:25:16 +0100 | [diff] [blame] | 270 | return -ENODEV; |
Javier Martinez Canillas | 6f1c1e7 | 2014-07-04 22:24:04 +0200 | [diff] [blame] | 271 | } |
Jonghwa Lee | dae8a96 | 2012-06-25 10:34:36 +0200 | [diff] [blame] | 272 | |
Javier Martinez Canillas | a259f38 | 2014-07-24 14:39:24 +0200 | [diff] [blame] | 273 | if (max77686->type == TYPE_MAX77686) { |
| 274 | max77686->rtc = i2c_new_dummy(i2c->adapter, I2C_ADDR_RTC); |
| 275 | if (!max77686->rtc) { |
| 276 | dev_err(max77686->dev, |
| 277 | "Failed to allocate I2C device for RTC\n"); |
| 278 | return -ENODEV; |
| 279 | } |
| 280 | i2c_set_clientdata(max77686->rtc, max77686); |
Jonghwa Lee | dae8a96 | 2012-06-25 10:34:36 +0200 | [diff] [blame] | 281 | |
Javier Martinez Canillas | a259f38 | 2014-07-24 14:39:24 +0200 | [diff] [blame] | 282 | max77686->rtc_regmap = |
| 283 | devm_regmap_init_i2c(max77686->rtc, |
| 284 | &max77686_rtc_regmap_config); |
| 285 | if (IS_ERR(max77686->rtc_regmap)) { |
| 286 | ret = PTR_ERR(max77686->rtc_regmap); |
| 287 | dev_err(max77686->dev, |
| 288 | "failed to allocate RTC regmap: %d\n", |
| 289 | ret); |
| 290 | goto err_unregister_i2c; |
| 291 | } |
Javier Martinez Canillas | 6f1c1e7 | 2014-07-04 22:24:04 +0200 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | ret = regmap_add_irq_chip(max77686->regmap, max77686->irq, |
| 295 | IRQF_TRIGGER_FALLING | IRQF_ONESHOT | |
Javier Martinez Canillas | a259f38 | 2014-07-24 14:39:24 +0200 | [diff] [blame] | 296 | IRQF_SHARED, 0, irq_chip, |
Javier Martinez Canillas | 6f1c1e7 | 2014-07-04 22:24:04 +0200 | [diff] [blame] | 297 | &max77686->irq_data); |
Javier Martinez Canillas | c0e0fcd | 2014-07-04 22:24:09 +0200 | [diff] [blame] | 298 | if (ret) { |
Javier Martinez Canillas | 6f1c1e7 | 2014-07-04 22:24:04 +0200 | [diff] [blame] | 299 | dev_err(&i2c->dev, "failed to add PMIC irq chip: %d\n", ret); |
| 300 | goto err_unregister_i2c; |
| 301 | } |
Javier Martinez Canillas | a259f38 | 2014-07-24 14:39:24 +0200 | [diff] [blame] | 302 | |
| 303 | ret = regmap_add_irq_chip(*rtc_regmap, max77686->irq, |
Javier Martinez Canillas | 6f1c1e7 | 2014-07-04 22:24:04 +0200 | [diff] [blame] | 304 | IRQF_TRIGGER_FALLING | IRQF_ONESHOT | |
Javier Martinez Canillas | a259f38 | 2014-07-24 14:39:24 +0200 | [diff] [blame] | 305 | IRQF_SHARED, 0, rtc_irq_chip, |
Javier Martinez Canillas | 6f1c1e7 | 2014-07-04 22:24:04 +0200 | [diff] [blame] | 306 | &max77686->rtc_irq_data); |
Javier Martinez Canillas | c0e0fcd | 2014-07-04 22:24:09 +0200 | [diff] [blame] | 307 | if (ret) { |
Javier Martinez Canillas | 6f1c1e7 | 2014-07-04 22:24:04 +0200 | [diff] [blame] | 308 | dev_err(&i2c->dev, "failed to add RTC irq chip: %d\n", ret); |
| 309 | goto err_del_irqc; |
| 310 | } |
Jonghwa Lee | dae8a96 | 2012-06-25 10:34:36 +0200 | [diff] [blame] | 311 | |
Javier Martinez Canillas | a259f38 | 2014-07-24 14:39:24 +0200 | [diff] [blame] | 312 | ret = mfd_add_devices(max77686->dev, -1, cells, n_devs, NULL, 0, NULL); |
Lee Jones | 742413a | 2013-05-23 16:25:16 +0100 | [diff] [blame] | 313 | if (ret < 0) { |
Javier Martinez Canillas | 6f1c1e7 | 2014-07-04 22:24:04 +0200 | [diff] [blame] | 314 | dev_err(&i2c->dev, "failed to add MFD devices: %d\n", ret); |
| 315 | goto err_del_rtc_irqc; |
Lee Jones | 742413a | 2013-05-23 16:25:16 +0100 | [diff] [blame] | 316 | } |
Jonghwa Lee | dae8a96 | 2012-06-25 10:34:36 +0200 | [diff] [blame] | 317 | |
Javier Martinez Canillas | 6f1c1e7 | 2014-07-04 22:24:04 +0200 | [diff] [blame] | 318 | return 0; |
| 319 | |
| 320 | err_del_rtc_irqc: |
| 321 | regmap_del_irq_chip(max77686->irq, max77686->rtc_irq_data); |
| 322 | err_del_irqc: |
| 323 | regmap_del_irq_chip(max77686->irq, max77686->irq_data); |
| 324 | err_unregister_i2c: |
Javier Martinez Canillas | a259f38 | 2014-07-24 14:39:24 +0200 | [diff] [blame] | 325 | if (max77686->type == TYPE_MAX77686) |
| 326 | i2c_unregister_device(max77686->rtc); |
Javier Martinez Canillas | 6f1c1e7 | 2014-07-04 22:24:04 +0200 | [diff] [blame] | 327 | |
Jonghwa Lee | dae8a96 | 2012-06-25 10:34:36 +0200 | [diff] [blame] | 328 | return ret; |
| 329 | } |
| 330 | |
| 331 | static int max77686_i2c_remove(struct i2c_client *i2c) |
| 332 | { |
| 333 | struct max77686_dev *max77686 = i2c_get_clientdata(i2c); |
| 334 | |
| 335 | mfd_remove_devices(max77686->dev); |
Javier Martinez Canillas | 6f1c1e7 | 2014-07-04 22:24:04 +0200 | [diff] [blame] | 336 | |
| 337 | regmap_del_irq_chip(max77686->irq, max77686->rtc_irq_data); |
| 338 | regmap_del_irq_chip(max77686->irq, max77686->irq_data); |
| 339 | |
Javier Martinez Canillas | a259f38 | 2014-07-24 14:39:24 +0200 | [diff] [blame] | 340 | if (max77686->type == TYPE_MAX77686) |
| 341 | i2c_unregister_device(max77686->rtc); |
Jonghwa Lee | dae8a96 | 2012-06-25 10:34:36 +0200 | [diff] [blame] | 342 | |
| 343 | return 0; |
| 344 | } |
| 345 | |
| 346 | static const struct i2c_device_id max77686_i2c_id[] = { |
| 347 | { "max77686", TYPE_MAX77686 }, |
| 348 | { } |
| 349 | }; |
| 350 | MODULE_DEVICE_TABLE(i2c, max77686_i2c_id); |
| 351 | |
Javier Martinez Canillas | 2b52b5d | 2014-07-04 22:24:05 +0200 | [diff] [blame] | 352 | #ifdef CONFIG_PM_SLEEP |
| 353 | static int max77686_suspend(struct device *dev) |
| 354 | { |
| 355 | struct i2c_client *i2c = container_of(dev, struct i2c_client, dev); |
| 356 | struct max77686_dev *max77686 = i2c_get_clientdata(i2c); |
| 357 | |
| 358 | if (device_may_wakeup(dev)) |
| 359 | enable_irq_wake(max77686->irq); |
| 360 | |
| 361 | /* |
| 362 | * IRQ must be disabled during suspend because if it happens |
| 363 | * while suspended it will be handled before resuming I2C. |
| 364 | * |
| 365 | * When device is woken up from suspend (e.g. by RTC wake alarm), |
| 366 | * an interrupt occurs before resuming I2C bus controller. |
| 367 | * Interrupt handler tries to read registers but this read |
| 368 | * will fail because I2C is still suspended. |
| 369 | */ |
| 370 | disable_irq(max77686->irq); |
| 371 | |
| 372 | return 0; |
| 373 | } |
| 374 | |
| 375 | static int max77686_resume(struct device *dev) |
| 376 | { |
| 377 | struct i2c_client *i2c = container_of(dev, struct i2c_client, dev); |
| 378 | struct max77686_dev *max77686 = i2c_get_clientdata(i2c); |
| 379 | |
| 380 | if (device_may_wakeup(dev)) |
| 381 | disable_irq_wake(max77686->irq); |
| 382 | |
| 383 | enable_irq(max77686->irq); |
| 384 | |
| 385 | return 0; |
| 386 | } |
| 387 | #endif /* CONFIG_PM_SLEEP */ |
| 388 | |
| 389 | static SIMPLE_DEV_PM_OPS(max77686_pm, max77686_suspend, max77686_resume); |
| 390 | |
Jonghwa Lee | dae8a96 | 2012-06-25 10:34:36 +0200 | [diff] [blame] | 391 | static struct i2c_driver max77686_i2c_driver = { |
| 392 | .driver = { |
| 393 | .name = "max77686", |
Javier Martinez Canillas | 2b52b5d | 2014-07-04 22:24:05 +0200 | [diff] [blame] | 394 | .pm = &max77686_pm, |
Yadwinder Singh Brar | c1516f8 | 2012-07-06 17:02:55 +0530 | [diff] [blame] | 395 | .of_match_table = of_match_ptr(max77686_pmic_dt_match), |
Jonghwa Lee | dae8a96 | 2012-06-25 10:34:36 +0200 | [diff] [blame] | 396 | }, |
| 397 | .probe = max77686_i2c_probe, |
| 398 | .remove = max77686_i2c_remove, |
| 399 | .id_table = max77686_i2c_id, |
| 400 | }; |
| 401 | |
| 402 | static int __init max77686_i2c_init(void) |
| 403 | { |
| 404 | return i2c_add_driver(&max77686_i2c_driver); |
| 405 | } |
| 406 | /* init early so consumer devices can complete system boot */ |
| 407 | subsys_initcall(max77686_i2c_init); |
| 408 | |
| 409 | static void __exit max77686_i2c_exit(void) |
| 410 | { |
| 411 | i2c_del_driver(&max77686_i2c_driver); |
| 412 | } |
| 413 | module_exit(max77686_i2c_exit); |
| 414 | |
Javier Martinez Canillas | a259f38 | 2014-07-24 14:39:24 +0200 | [diff] [blame] | 415 | MODULE_DESCRIPTION("MAXIM 77686/802 multi-function core driver"); |
Jonghwa Lee | dae8a96 | 2012-06-25 10:34:36 +0200 | [diff] [blame] | 416 | MODULE_AUTHOR("Chiwoong Byun <woong.byun@samsung.com>"); |
| 417 | MODULE_LICENSE("GPL"); |