Chanwoo Choi | 83871c0 | 2012-05-14 22:50:39 +0200 | [diff] [blame] | 1 | /* |
| 2 | * max77693.c - mfd core driver for the MAX 77693 |
| 3 | * |
| 4 | * Copyright (C) 2012 Samsung Electronics |
Krzysztof Kozlowski | 630fd98 | 2016-04-05 11:04:51 +0900 | [diff] [blame] | 5 | * SangYoung Son <hello.son@samsung.com> |
Chanwoo Choi | 83871c0 | 2012-05-14 22:50:39 +0200 | [diff] [blame] | 6 | * |
| 7 | * This program is not provided / owned by Maxim Integrated Products. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 22 | * |
| 23 | * This driver is based on max8997.c |
| 24 | */ |
| 25 | |
| 26 | #include <linux/module.h> |
| 27 | #include <linux/slab.h> |
| 28 | #include <linux/i2c.h> |
| 29 | #include <linux/err.h> |
| 30 | #include <linux/interrupt.h> |
Sachin Kamat | 71c7f93 | 2013-10-18 16:11:57 +0530 | [diff] [blame] | 31 | #include <linux/of.h> |
Chanwoo Choi | 83871c0 | 2012-05-14 22:50:39 +0200 | [diff] [blame] | 32 | #include <linux/pm_runtime.h> |
| 33 | #include <linux/mutex.h> |
| 34 | #include <linux/mfd/core.h> |
| 35 | #include <linux/mfd/max77693.h> |
Krzysztof Kozlowski | 61b305c | 2015-07-15 21:59:50 +0900 | [diff] [blame] | 36 | #include <linux/mfd/max77693-common.h> |
Chanwoo Choi | 83871c0 | 2012-05-14 22:50:39 +0200 | [diff] [blame] | 37 | #include <linux/mfd/max77693-private.h> |
| 38 | #include <linux/regulator/machine.h> |
| 39 | #include <linux/regmap.h> |
| 40 | |
| 41 | #define I2C_ADDR_PMIC (0xCC >> 1) /* Charger, Flash LED */ |
| 42 | #define I2C_ADDR_MUIC (0x4A >> 1) |
| 43 | #define I2C_ADDR_HAPTIC (0x90 >> 1) |
| 44 | |
Geert Uytterhoeven | 7c0517b | 2013-11-18 14:33:00 +0100 | [diff] [blame] | 45 | static const struct mfd_cell max77693_devs[] = { |
Chanwoo Choi | 83871c0 | 2012-05-14 22:50:39 +0200 | [diff] [blame] | 46 | { .name = "max77693-pmic", }, |
Krzysztof Kozlowski | efa3ca4 | 2014-10-20 14:34:46 +0200 | [diff] [blame] | 47 | { |
| 48 | .name = "max77693-charger", |
| 49 | .of_compatible = "maxim,max77693-charger", |
| 50 | }, |
Maciej Purski | 4589515 | 2017-09-05 15:50:27 +0200 | [diff] [blame] | 51 | { |
| 52 | .name = "max77693-muic", |
| 53 | .of_compatible = "maxim,max77693-muic", |
| 54 | }, |
Jaewon Kim | d1bafd7 | 2014-09-18 01:40:25 +0900 | [diff] [blame] | 55 | { |
| 56 | .name = "max77693-haptic", |
| 57 | .of_compatible = "maxim,max77693-haptic", |
| 58 | }, |
Jacek Anaszewski | a0bc6072 | 2014-08-22 11:06:18 +0200 | [diff] [blame] | 59 | { |
Jacek Anaszewski | 224995d | 2015-03-04 17:14:26 +0100 | [diff] [blame] | 60 | .name = "max77693-led", |
| 61 | .of_compatible = "maxim,max77693-led", |
Jacek Anaszewski | a0bc6072 | 2014-08-22 11:06:18 +0200 | [diff] [blame] | 62 | }, |
Chanwoo Choi | 83871c0 | 2012-05-14 22:50:39 +0200 | [diff] [blame] | 63 | }; |
| 64 | |
Chanwoo Choi | 83871c0 | 2012-05-14 22:50:39 +0200 | [diff] [blame] | 65 | static const struct regmap_config max77693_regmap_config = { |
| 66 | .reg_bits = 8, |
| 67 | .val_bits = 8, |
| 68 | .max_register = MAX77693_PMIC_REG_END, |
| 69 | }; |
| 70 | |
Robert Baldyga | 342d669 | 2014-05-21 08:52:48 +0200 | [diff] [blame] | 71 | static const struct regmap_irq max77693_led_irqs[] = { |
| 72 | { .mask = LED_IRQ_FLED2_OPEN, }, |
| 73 | { .mask = LED_IRQ_FLED2_SHORT, }, |
| 74 | { .mask = LED_IRQ_FLED1_OPEN, }, |
| 75 | { .mask = LED_IRQ_FLED1_SHORT, }, |
| 76 | { .mask = LED_IRQ_MAX_FLASH, }, |
| 77 | }; |
| 78 | |
| 79 | static const struct regmap_irq_chip max77693_led_irq_chip = { |
| 80 | .name = "max77693-led", |
| 81 | .status_base = MAX77693_LED_REG_FLASH_INT, |
| 82 | .mask_base = MAX77693_LED_REG_FLASH_INT_MASK, |
| 83 | .mask_invert = false, |
| 84 | .num_regs = 1, |
| 85 | .irqs = max77693_led_irqs, |
| 86 | .num_irqs = ARRAY_SIZE(max77693_led_irqs), |
| 87 | }; |
| 88 | |
| 89 | static const struct regmap_irq max77693_topsys_irqs[] = { |
| 90 | { .mask = TOPSYS_IRQ_T120C_INT, }, |
| 91 | { .mask = TOPSYS_IRQ_T140C_INT, }, |
| 92 | { .mask = TOPSYS_IRQ_LOWSYS_INT, }, |
| 93 | }; |
| 94 | |
| 95 | static const struct regmap_irq_chip max77693_topsys_irq_chip = { |
| 96 | .name = "max77693-topsys", |
| 97 | .status_base = MAX77693_PMIC_REG_TOPSYS_INT, |
| 98 | .mask_base = MAX77693_PMIC_REG_TOPSYS_INT_MASK, |
| 99 | .mask_invert = false, |
| 100 | .num_regs = 1, |
| 101 | .irqs = max77693_topsys_irqs, |
| 102 | .num_irqs = ARRAY_SIZE(max77693_topsys_irqs), |
| 103 | }; |
| 104 | |
| 105 | static const struct regmap_irq max77693_charger_irqs[] = { |
| 106 | { .mask = CHG_IRQ_BYP_I, }, |
| 107 | { .mask = CHG_IRQ_THM_I, }, |
| 108 | { .mask = CHG_IRQ_BAT_I, }, |
| 109 | { .mask = CHG_IRQ_CHG_I, }, |
| 110 | { .mask = CHG_IRQ_CHGIN_I, }, |
| 111 | }; |
| 112 | |
| 113 | static const struct regmap_irq_chip max77693_charger_irq_chip = { |
| 114 | .name = "max77693-charger", |
| 115 | .status_base = MAX77693_CHG_REG_CHG_INT, |
| 116 | .mask_base = MAX77693_CHG_REG_CHG_INT_MASK, |
| 117 | .mask_invert = false, |
| 118 | .num_regs = 1, |
| 119 | .irqs = max77693_charger_irqs, |
| 120 | .num_irqs = ARRAY_SIZE(max77693_charger_irqs), |
| 121 | }; |
| 122 | |
Krzysztof Kozlowski | 75ad132 | 2013-12-20 10:35:08 +0100 | [diff] [blame] | 123 | static const struct regmap_config max77693_regmap_muic_config = { |
| 124 | .reg_bits = 8, |
| 125 | .val_bits = 8, |
| 126 | .max_register = MAX77693_MUIC_REG_END, |
| 127 | }; |
| 128 | |
Robert Baldyga | 342d669 | 2014-05-21 08:52:48 +0200 | [diff] [blame] | 129 | static const struct regmap_irq max77693_muic_irqs[] = { |
| 130 | { .reg_offset = 0, .mask = MUIC_IRQ_INT1_ADC, }, |
| 131 | { .reg_offset = 0, .mask = MUIC_IRQ_INT1_ADC_LOW, }, |
| 132 | { .reg_offset = 0, .mask = MUIC_IRQ_INT1_ADC_ERR, }, |
| 133 | { .reg_offset = 0, .mask = MUIC_IRQ_INT1_ADC1K, }, |
| 134 | |
| 135 | { .reg_offset = 1, .mask = MUIC_IRQ_INT2_CHGTYP, }, |
| 136 | { .reg_offset = 1, .mask = MUIC_IRQ_INT2_CHGDETREUN, }, |
| 137 | { .reg_offset = 1, .mask = MUIC_IRQ_INT2_DCDTMR, }, |
| 138 | { .reg_offset = 1, .mask = MUIC_IRQ_INT2_DXOVP, }, |
| 139 | { .reg_offset = 1, .mask = MUIC_IRQ_INT2_VBVOLT, }, |
| 140 | { .reg_offset = 1, .mask = MUIC_IRQ_INT2_VIDRM, }, |
| 141 | |
| 142 | { .reg_offset = 2, .mask = MUIC_IRQ_INT3_EOC, }, |
| 143 | { .reg_offset = 2, .mask = MUIC_IRQ_INT3_CGMBC, }, |
| 144 | { .reg_offset = 2, .mask = MUIC_IRQ_INT3_OVP, }, |
| 145 | { .reg_offset = 2, .mask = MUIC_IRQ_INT3_MBCCHG_ERR, }, |
| 146 | { .reg_offset = 2, .mask = MUIC_IRQ_INT3_CHG_ENABLED, }, |
| 147 | { .reg_offset = 2, .mask = MUIC_IRQ_INT3_BAT_DET, }, |
| 148 | }; |
| 149 | |
| 150 | static const struct regmap_irq_chip max77693_muic_irq_chip = { |
| 151 | .name = "max77693-muic", |
| 152 | .status_base = MAX77693_MUIC_REG_INT1, |
| 153 | .mask_base = MAX77693_MUIC_REG_INTMASK1, |
| 154 | .mask_invert = true, |
| 155 | .num_regs = 3, |
| 156 | .irqs = max77693_muic_irqs, |
| 157 | .num_irqs = ARRAY_SIZE(max77693_muic_irqs), |
| 158 | }; |
| 159 | |
Jaewon Kim | efbf492 | 2014-09-18 01:40:24 +0900 | [diff] [blame] | 160 | static const struct regmap_config max77693_regmap_haptic_config = { |
| 161 | .reg_bits = 8, |
| 162 | .val_bits = 8, |
| 163 | .max_register = MAX77693_HAPTIC_REG_END, |
| 164 | }; |
| 165 | |
Chanwoo Choi | 83871c0 | 2012-05-14 22:50:39 +0200 | [diff] [blame] | 166 | static int max77693_i2c_probe(struct i2c_client *i2c, |
| 167 | const struct i2c_device_id *id) |
| 168 | { |
| 169 | struct max77693_dev *max77693; |
Robert Baldyga | d0540f9 | 2014-05-21 08:52:47 +0200 | [diff] [blame] | 170 | unsigned int reg_data; |
Chanwoo Choi | 83871c0 | 2012-05-14 22:50:39 +0200 | [diff] [blame] | 171 | int ret = 0; |
| 172 | |
| 173 | max77693 = devm_kzalloc(&i2c->dev, |
| 174 | sizeof(struct max77693_dev), GFP_KERNEL); |
| 175 | if (max77693 == NULL) |
| 176 | return -ENOMEM; |
| 177 | |
Chanwoo Choi | 83871c0 | 2012-05-14 22:50:39 +0200 | [diff] [blame] | 178 | i2c_set_clientdata(i2c, max77693); |
| 179 | max77693->dev = &i2c->dev; |
| 180 | max77693->i2c = i2c; |
| 181 | max77693->irq = i2c->irq; |
| 182 | max77693->type = id->driver_data; |
| 183 | |
Axel Lin | 2429d86 | 2012-12-25 00:28:36 +0800 | [diff] [blame] | 184 | max77693->regmap = devm_regmap_init_i2c(i2c, &max77693_regmap_config); |
| 185 | if (IS_ERR(max77693->regmap)) { |
| 186 | ret = PTR_ERR(max77693->regmap); |
| 187 | dev_err(max77693->dev, "failed to allocate register map: %d\n", |
| 188 | ret); |
| 189 | return ret; |
| 190 | } |
Chanwoo Choi | 83871c0 | 2012-05-14 22:50:39 +0200 | [diff] [blame] | 191 | |
Robert Baldyga | d0540f9 | 2014-05-21 08:52:47 +0200 | [diff] [blame] | 192 | ret = regmap_read(max77693->regmap, MAX77693_PMIC_REG_PMIC_ID2, |
Axel Lin | 2429d86 | 2012-12-25 00:28:36 +0800 | [diff] [blame] | 193 | ®_data); |
| 194 | if (ret < 0) { |
Chanwoo Choi | 83871c0 | 2012-05-14 22:50:39 +0200 | [diff] [blame] | 195 | dev_err(max77693->dev, "device not found on this channel\n"); |
Axel Lin | 2429d86 | 2012-12-25 00:28:36 +0800 | [diff] [blame] | 196 | return ret; |
Chanwoo Choi | 83871c0 | 2012-05-14 22:50:39 +0200 | [diff] [blame] | 197 | } else |
| 198 | dev_info(max77693->dev, "device ID: 0x%x\n", reg_data); |
| 199 | |
Krzysztof Kozlowski | 61b305c | 2015-07-15 21:59:50 +0900 | [diff] [blame] | 200 | max77693->i2c_muic = i2c_new_dummy(i2c->adapter, I2C_ADDR_MUIC); |
| 201 | if (!max77693->i2c_muic) { |
Krzysztof Kozlowski | ad09dd6 | 2014-02-11 11:03:32 +0100 | [diff] [blame] | 202 | dev_err(max77693->dev, "Failed to allocate I2C device for MUIC\n"); |
| 203 | return -ENODEV; |
| 204 | } |
Krzysztof Kozlowski | 61b305c | 2015-07-15 21:59:50 +0900 | [diff] [blame] | 205 | i2c_set_clientdata(max77693->i2c_muic, max77693); |
Chanwoo Choi | 83871c0 | 2012-05-14 22:50:39 +0200 | [diff] [blame] | 206 | |
Krzysztof Kozlowski | 61b305c | 2015-07-15 21:59:50 +0900 | [diff] [blame] | 207 | max77693->i2c_haptic = i2c_new_dummy(i2c->adapter, I2C_ADDR_HAPTIC); |
| 208 | if (!max77693->i2c_haptic) { |
Krzysztof Kozlowski | ad09dd6 | 2014-02-11 11:03:32 +0100 | [diff] [blame] | 209 | dev_err(max77693->dev, "Failed to allocate I2C device for Haptic\n"); |
| 210 | ret = -ENODEV; |
| 211 | goto err_i2c_haptic; |
| 212 | } |
Krzysztof Kozlowski | 61b305c | 2015-07-15 21:59:50 +0900 | [diff] [blame] | 213 | i2c_set_clientdata(max77693->i2c_haptic, max77693); |
Chanwoo Choi | 83871c0 | 2012-05-14 22:50:39 +0200 | [diff] [blame] | 214 | |
Krzysztof Kozlowski | 61b305c | 2015-07-15 21:59:50 +0900 | [diff] [blame] | 215 | max77693->regmap_haptic = devm_regmap_init_i2c(max77693->i2c_haptic, |
Jaewon Kim | efbf492 | 2014-09-18 01:40:24 +0900 | [diff] [blame] | 216 | &max77693_regmap_haptic_config); |
| 217 | if (IS_ERR(max77693->regmap_haptic)) { |
| 218 | ret = PTR_ERR(max77693->regmap_haptic); |
| 219 | dev_err(max77693->dev, |
| 220 | "failed to initialize haptic register map: %d\n", ret); |
| 221 | goto err_regmap; |
| 222 | } |
| 223 | |
Chanwoo Choi | b186b12 | 2012-08-21 15:16:23 +0900 | [diff] [blame] | 224 | /* |
| 225 | * Initialize register map for MUIC device because use regmap-muic |
| 226 | * instance of MUIC device when irq of max77693 is initialized |
| 227 | * before call max77693-muic probe() function. |
| 228 | */ |
Krzysztof Kozlowski | 61b305c | 2015-07-15 21:59:50 +0900 | [diff] [blame] | 229 | max77693->regmap_muic = devm_regmap_init_i2c(max77693->i2c_muic, |
Krzysztof Kozlowski | 75ad132 | 2013-12-20 10:35:08 +0100 | [diff] [blame] | 230 | &max77693_regmap_muic_config); |
Chanwoo Choi | b186b12 | 2012-08-21 15:16:23 +0900 | [diff] [blame] | 231 | if (IS_ERR(max77693->regmap_muic)) { |
| 232 | ret = PTR_ERR(max77693->regmap_muic); |
| 233 | dev_err(max77693->dev, |
| 234 | "failed to allocate register map: %d\n", ret); |
Jaewon Kim | efbf492 | 2014-09-18 01:40:24 +0900 | [diff] [blame] | 235 | goto err_regmap; |
Chanwoo Choi | b186b12 | 2012-08-21 15:16:23 +0900 | [diff] [blame] | 236 | } |
| 237 | |
Robert Baldyga | 342d669 | 2014-05-21 08:52:48 +0200 | [diff] [blame] | 238 | ret = regmap_add_irq_chip(max77693->regmap, max77693->irq, |
| 239 | IRQF_ONESHOT | IRQF_SHARED | |
| 240 | IRQF_TRIGGER_FALLING, 0, |
| 241 | &max77693_led_irq_chip, |
| 242 | &max77693->irq_data_led); |
| 243 | if (ret) { |
| 244 | dev_err(max77693->dev, "failed to add irq chip: %d\n", ret); |
Jaewon Kim | efbf492 | 2014-09-18 01:40:24 +0900 | [diff] [blame] | 245 | goto err_regmap; |
Robert Baldyga | 342d669 | 2014-05-21 08:52:48 +0200 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | ret = regmap_add_irq_chip(max77693->regmap, max77693->irq, |
| 249 | IRQF_ONESHOT | IRQF_SHARED | |
| 250 | IRQF_TRIGGER_FALLING, 0, |
| 251 | &max77693_topsys_irq_chip, |
| 252 | &max77693->irq_data_topsys); |
| 253 | if (ret) { |
| 254 | dev_err(max77693->dev, "failed to add irq chip: %d\n", ret); |
| 255 | goto err_irq_topsys; |
| 256 | } |
| 257 | |
| 258 | ret = regmap_add_irq_chip(max77693->regmap, max77693->irq, |
| 259 | IRQF_ONESHOT | IRQF_SHARED | |
| 260 | IRQF_TRIGGER_FALLING, 0, |
| 261 | &max77693_charger_irq_chip, |
Krzysztof Kozlowski | 61b305c | 2015-07-15 21:59:50 +0900 | [diff] [blame] | 262 | &max77693->irq_data_chg); |
Robert Baldyga | 342d669 | 2014-05-21 08:52:48 +0200 | [diff] [blame] | 263 | if (ret) { |
| 264 | dev_err(max77693->dev, "failed to add irq chip: %d\n", ret); |
| 265 | goto err_irq_charger; |
| 266 | } |
| 267 | |
Krzysztof Kozlowski | 43fc939 | 2014-10-10 10:22:01 +0200 | [diff] [blame] | 268 | ret = regmap_add_irq_chip(max77693->regmap_muic, max77693->irq, |
Robert Baldyga | 342d669 | 2014-05-21 08:52:48 +0200 | [diff] [blame] | 269 | IRQF_ONESHOT | IRQF_SHARED | |
| 270 | IRQF_TRIGGER_FALLING, 0, |
| 271 | &max77693_muic_irq_chip, |
| 272 | &max77693->irq_data_muic); |
| 273 | if (ret) { |
| 274 | dev_err(max77693->dev, "failed to add irq chip: %d\n", ret); |
| 275 | goto err_irq_muic; |
| 276 | } |
Chanwoo Choi | 6592ebb | 2012-05-14 22:54:20 +0200 | [diff] [blame] | 277 | |
Krzysztof Kozlowski | c0acb81 | 2014-10-10 12:48:35 +0200 | [diff] [blame] | 278 | /* Unmask interrupts from all blocks in interrupt source register */ |
| 279 | ret = regmap_update_bits(max77693->regmap, |
| 280 | MAX77693_PMIC_REG_INTSRC_MASK, |
| 281 | SRC_IRQ_ALL, (unsigned int)~SRC_IRQ_ALL); |
| 282 | if (ret < 0) { |
| 283 | dev_err(max77693->dev, |
| 284 | "Could not unmask interrupts in INTSRC: %d\n", |
| 285 | ret); |
| 286 | goto err_intsrc; |
| 287 | } |
| 288 | |
Chanwoo Choi | 83871c0 | 2012-05-14 22:50:39 +0200 | [diff] [blame] | 289 | pm_runtime_set_active(max77693->dev); |
| 290 | |
| 291 | ret = mfd_add_devices(max77693->dev, -1, max77693_devs, |
Mark Brown | 0848c94 | 2012-09-11 15:16:36 +0800 | [diff] [blame] | 292 | ARRAY_SIZE(max77693_devs), NULL, 0, NULL); |
Chanwoo Choi | 83871c0 | 2012-05-14 22:50:39 +0200 | [diff] [blame] | 293 | if (ret < 0) |
| 294 | goto err_mfd; |
| 295 | |
| 296 | return ret; |
| 297 | |
| 298 | err_mfd: |
Robert Baldyga | 342d669 | 2014-05-21 08:52:48 +0200 | [diff] [blame] | 299 | mfd_remove_devices(max77693->dev); |
Krzysztof Kozlowski | c0acb81 | 2014-10-10 12:48:35 +0200 | [diff] [blame] | 300 | err_intsrc: |
Robert Baldyga | 342d669 | 2014-05-21 08:52:48 +0200 | [diff] [blame] | 301 | regmap_del_irq_chip(max77693->irq, max77693->irq_data_muic); |
| 302 | err_irq_muic: |
Krzysztof Kozlowski | 61b305c | 2015-07-15 21:59:50 +0900 | [diff] [blame] | 303 | regmap_del_irq_chip(max77693->irq, max77693->irq_data_chg); |
Robert Baldyga | 342d669 | 2014-05-21 08:52:48 +0200 | [diff] [blame] | 304 | err_irq_charger: |
| 305 | regmap_del_irq_chip(max77693->irq, max77693->irq_data_topsys); |
| 306 | err_irq_topsys: |
| 307 | regmap_del_irq_chip(max77693->irq, max77693->irq_data_led); |
Jaewon Kim | efbf492 | 2014-09-18 01:40:24 +0900 | [diff] [blame] | 308 | err_regmap: |
Krzysztof Kozlowski | 61b305c | 2015-07-15 21:59:50 +0900 | [diff] [blame] | 309 | i2c_unregister_device(max77693->i2c_haptic); |
Krzysztof Kozlowski | ad09dd6 | 2014-02-11 11:03:32 +0100 | [diff] [blame] | 310 | err_i2c_haptic: |
Krzysztof Kozlowski | 61b305c | 2015-07-15 21:59:50 +0900 | [diff] [blame] | 311 | i2c_unregister_device(max77693->i2c_muic); |
Chanwoo Choi | 83871c0 | 2012-05-14 22:50:39 +0200 | [diff] [blame] | 312 | return ret; |
| 313 | } |
| 314 | |
| 315 | static int max77693_i2c_remove(struct i2c_client *i2c) |
| 316 | { |
| 317 | struct max77693_dev *max77693 = i2c_get_clientdata(i2c); |
| 318 | |
| 319 | mfd_remove_devices(max77693->dev); |
Robert Baldyga | 342d669 | 2014-05-21 08:52:48 +0200 | [diff] [blame] | 320 | |
| 321 | regmap_del_irq_chip(max77693->irq, max77693->irq_data_muic); |
Krzysztof Kozlowski | 61b305c | 2015-07-15 21:59:50 +0900 | [diff] [blame] | 322 | regmap_del_irq_chip(max77693->irq, max77693->irq_data_chg); |
Robert Baldyga | 342d669 | 2014-05-21 08:52:48 +0200 | [diff] [blame] | 323 | regmap_del_irq_chip(max77693->irq, max77693->irq_data_topsys); |
| 324 | regmap_del_irq_chip(max77693->irq, max77693->irq_data_led); |
| 325 | |
Krzysztof Kozlowski | 61b305c | 2015-07-15 21:59:50 +0900 | [diff] [blame] | 326 | i2c_unregister_device(max77693->i2c_muic); |
| 327 | i2c_unregister_device(max77693->i2c_haptic); |
Chanwoo Choi | 83871c0 | 2012-05-14 22:50:39 +0200 | [diff] [blame] | 328 | |
| 329 | return 0; |
| 330 | } |
| 331 | |
| 332 | static const struct i2c_device_id max77693_i2c_id[] = { |
| 333 | { "max77693", TYPE_MAX77693 }, |
| 334 | { } |
| 335 | }; |
| 336 | MODULE_DEVICE_TABLE(i2c, max77693_i2c_id); |
| 337 | |
Chanwoo Choi | 6592ebb | 2012-05-14 22:54:20 +0200 | [diff] [blame] | 338 | static int max77693_suspend(struct device *dev) |
| 339 | { |
Geliang Tang | 1b5420e | 2015-12-28 23:00:14 +0800 | [diff] [blame] | 340 | struct i2c_client *i2c = to_i2c_client(dev); |
Chanwoo Choi | 6592ebb | 2012-05-14 22:54:20 +0200 | [diff] [blame] | 341 | struct max77693_dev *max77693 = i2c_get_clientdata(i2c); |
| 342 | |
Robert Baldyga | 342d669 | 2014-05-21 08:52:48 +0200 | [diff] [blame] | 343 | if (device_may_wakeup(dev)) { |
| 344 | enable_irq_wake(max77693->irq); |
| 345 | disable_irq(max77693->irq); |
| 346 | } |
| 347 | |
Chanwoo Choi | 6592ebb | 2012-05-14 22:54:20 +0200 | [diff] [blame] | 348 | return 0; |
| 349 | } |
| 350 | |
| 351 | static int max77693_resume(struct device *dev) |
| 352 | { |
Geliang Tang | 1b5420e | 2015-12-28 23:00:14 +0800 | [diff] [blame] | 353 | struct i2c_client *i2c = to_i2c_client(dev); |
Chanwoo Choi | 6592ebb | 2012-05-14 22:54:20 +0200 | [diff] [blame] | 354 | struct max77693_dev *max77693 = i2c_get_clientdata(i2c); |
| 355 | |
Robert Baldyga | 342d669 | 2014-05-21 08:52:48 +0200 | [diff] [blame] | 356 | if (device_may_wakeup(dev)) { |
| 357 | disable_irq_wake(max77693->irq); |
| 358 | enable_irq(max77693->irq); |
| 359 | } |
| 360 | |
| 361 | return 0; |
Chanwoo Choi | 6592ebb | 2012-05-14 22:54:20 +0200 | [diff] [blame] | 362 | } |
| 363 | |
Mark Brown | 12477a3 | 2012-06-05 16:15:59 +0100 | [diff] [blame] | 364 | static const struct dev_pm_ops max77693_pm = { |
Chanwoo Choi | 6592ebb | 2012-05-14 22:54:20 +0200 | [diff] [blame] | 365 | .suspend = max77693_suspend, |
| 366 | .resume = max77693_resume, |
| 367 | }; |
| 368 | |
Andrzej Hajda | 4657185 | 2013-09-27 09:27:46 +0200 | [diff] [blame] | 369 | #ifdef CONFIG_OF |
Krzysztof Kozlowski | 5ce9a55 | 2014-05-13 12:58:52 +0200 | [diff] [blame] | 370 | static const struct of_device_id max77693_dt_match[] = { |
Andrzej Hajda | 4657185 | 2013-09-27 09:27:46 +0200 | [diff] [blame] | 371 | { .compatible = "maxim,max77693" }, |
| 372 | {}, |
| 373 | }; |
Krzysztof Kozlowski | 073d4ac | 2016-04-04 16:54:18 +0900 | [diff] [blame] | 374 | MODULE_DEVICE_TABLE(of, max77693_dt_match); |
Andrzej Hajda | 4657185 | 2013-09-27 09:27:46 +0200 | [diff] [blame] | 375 | #endif |
| 376 | |
Chanwoo Choi | 83871c0 | 2012-05-14 22:50:39 +0200 | [diff] [blame] | 377 | static struct i2c_driver max77693_i2c_driver = { |
| 378 | .driver = { |
| 379 | .name = "max77693", |
Chanwoo Choi | 6592ebb | 2012-05-14 22:54:20 +0200 | [diff] [blame] | 380 | .pm = &max77693_pm, |
Andrzej Hajda | 4657185 | 2013-09-27 09:27:46 +0200 | [diff] [blame] | 381 | .of_match_table = of_match_ptr(max77693_dt_match), |
Chanwoo Choi | 83871c0 | 2012-05-14 22:50:39 +0200 | [diff] [blame] | 382 | }, |
| 383 | .probe = max77693_i2c_probe, |
| 384 | .remove = max77693_i2c_remove, |
| 385 | .id_table = max77693_i2c_id, |
| 386 | }; |
| 387 | |
Krzysztof Kozlowski | 073d4ac | 2016-04-04 16:54:18 +0900 | [diff] [blame] | 388 | module_i2c_driver(max77693_i2c_driver); |
Chanwoo Choi | 83871c0 | 2012-05-14 22:50:39 +0200 | [diff] [blame] | 389 | |
| 390 | MODULE_DESCRIPTION("MAXIM 77693 multi-function core driver"); |
| 391 | MODULE_AUTHOR("SangYoung, Son <hello.son@samsung.com>"); |
| 392 | MODULE_LICENSE("GPL"); |