blob: 3f554c44752183a917f6229a4bc26ec81a042e00 [file] [log] [blame]
MyungJoo Ham527e7e92011-03-04 15:50:26 +09001/*
2 * max8997.c - mfd core driver for the Maxim 8966 and 8997
3 *
4 * Copyright (C) 2011 Samsung Electronics
Paul Gortmaker9cf0c212016-06-02 20:39:47 -04005 * MyungJoo Ham <myungjoo.ham@samsung.com>
MyungJoo Ham527e7e92011-03-04 15:50:26 +09006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 * This driver is based on max8998.c
22 */
23
Thomas Abraham77b71b32012-11-27 14:04:32 +053024#include <linux/err.h>
MyungJoo Ham527e7e92011-03-04 15:50:26 +090025#include <linux/slab.h>
26#include <linux/i2c.h>
Sachin Kamatfb7d4a52013-10-16 14:26:51 +053027#include <linux/of.h>
Thomas Abraham77b71b32012-11-27 14:04:32 +053028#include <linux/of_irq.h>
MyungJoo Ham01fdaab2011-08-19 14:39:40 +090029#include <linux/interrupt.h>
MyungJoo Ham527e7e92011-03-04 15:50:26 +090030#include <linux/pm_runtime.h>
Paul Gortmaker9cf0c212016-06-02 20:39:47 -040031#include <linux/init.h>
MyungJoo Ham527e7e92011-03-04 15:50:26 +090032#include <linux/mutex.h>
33#include <linux/mfd/core.h>
34#include <linux/mfd/max8997.h>
35#include <linux/mfd/max8997-private.h>
36
37#define I2C_ADDR_PMIC (0xCC >> 1)
38#define I2C_ADDR_MUIC (0x4A >> 1)
39#define I2C_ADDR_BATTERY (0x6C >> 1)
40#define I2C_ADDR_RTC (0x0C >> 1)
41#define I2C_ADDR_HAPTIC (0x90 >> 1)
42
Geert Uytterhoeven7c0517b2013-11-18 14:33:00 +010043static const struct mfd_cell max8997_devs[] = {
MyungJoo Ham527e7e92011-03-04 15:50:26 +090044 { .name = "max8997-pmic", },
45 { .name = "max8997-rtc", },
46 { .name = "max8997-battery", },
47 { .name = "max8997-haptic", },
48 { .name = "max8997-muic", },
Donggeun Kimf6dd2db2011-12-14 18:23:55 +090049 { .name = "max8997-led", .id = 1 },
50 { .name = "max8997-led", .id = 2 },
MyungJoo Ham527e7e92011-03-04 15:50:26 +090051};
52
Thomas Abraham77b71b32012-11-27 14:04:32 +053053#ifdef CONFIG_OF
Krzysztof Kozlowskif1eb2cb2014-05-13 12:58:49 +020054static const struct of_device_id max8997_pmic_dt_match[] = {
Jingoo Haned6ccdc2013-08-01 11:01:27 +090055 { .compatible = "maxim,max8997-pmic", .data = (void *)TYPE_MAX8997 },
Thomas Abraham77b71b32012-11-27 14:04:32 +053056 {},
57};
58#endif
59
MyungJoo Ham527e7e92011-03-04 15:50:26 +090060int max8997_read_reg(struct i2c_client *i2c, u8 reg, u8 *dest)
61{
62 struct max8997_dev *max8997 = i2c_get_clientdata(i2c);
63 int ret;
64
65 mutex_lock(&max8997->iolock);
66 ret = i2c_smbus_read_byte_data(i2c, reg);
67 mutex_unlock(&max8997->iolock);
68 if (ret < 0)
69 return ret;
70
71 ret &= 0xff;
72 *dest = ret;
73 return 0;
74}
75EXPORT_SYMBOL_GPL(max8997_read_reg);
76
77int max8997_bulk_read(struct i2c_client *i2c, u8 reg, int count, u8 *buf)
78{
79 struct max8997_dev *max8997 = i2c_get_clientdata(i2c);
80 int ret;
81
82 mutex_lock(&max8997->iolock);
83 ret = i2c_smbus_read_i2c_block_data(i2c, reg, count, buf);
84 mutex_unlock(&max8997->iolock);
85 if (ret < 0)
86 return ret;
87
88 return 0;
89}
90EXPORT_SYMBOL_GPL(max8997_bulk_read);
91
92int max8997_write_reg(struct i2c_client *i2c, u8 reg, u8 value)
93{
94 struct max8997_dev *max8997 = i2c_get_clientdata(i2c);
95 int ret;
96
97 mutex_lock(&max8997->iolock);
98 ret = i2c_smbus_write_byte_data(i2c, reg, value);
99 mutex_unlock(&max8997->iolock);
100 return ret;
101}
102EXPORT_SYMBOL_GPL(max8997_write_reg);
103
104int max8997_bulk_write(struct i2c_client *i2c, u8 reg, int count, u8 *buf)
105{
106 struct max8997_dev *max8997 = i2c_get_clientdata(i2c);
107 int ret;
108
109 mutex_lock(&max8997->iolock);
110 ret = i2c_smbus_write_i2c_block_data(i2c, reg, count, buf);
111 mutex_unlock(&max8997->iolock);
112 if (ret < 0)
113 return ret;
114
115 return 0;
116}
117EXPORT_SYMBOL_GPL(max8997_bulk_write);
118
119int max8997_update_reg(struct i2c_client *i2c, u8 reg, u8 val, u8 mask)
120{
121 struct max8997_dev *max8997 = i2c_get_clientdata(i2c);
122 int ret;
123
124 mutex_lock(&max8997->iolock);
125 ret = i2c_smbus_read_byte_data(i2c, reg);
126 if (ret >= 0) {
127 u8 old_val = ret & 0xff;
128 u8 new_val = (val & mask) | (old_val & (~mask));
129 ret = i2c_smbus_write_byte_data(i2c, reg, new_val);
130 }
131 mutex_unlock(&max8997->iolock);
132 return ret;
133}
134EXPORT_SYMBOL_GPL(max8997_update_reg);
135
Thomas Abraham77b71b32012-11-27 14:04:32 +0530136/*
137 * Only the common platform data elements for max8997 are parsed here from the
138 * device tree. Other sub-modules of max8997 such as pmic, rtc and others have
139 * to parse their own platform data elements from device tree.
140 *
141 * The max8997 platform data structure is instantiated here and the drivers for
142 * the sub-modules need not instantiate another instance while parsing their
143 * platform data.
144 */
145static struct max8997_platform_data *max8997_i2c_parse_dt_pdata(
146 struct device *dev)
147{
148 struct max8997_platform_data *pd;
149
150 pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL);
Markus Elfringf01b90b2018-01-15 09:35:17 +0100151 if (!pd)
Thomas Abraham77b71b32012-11-27 14:04:32 +0530152 return ERR_PTR(-ENOMEM);
Thomas Abraham77b71b32012-11-27 14:04:32 +0530153
154 pd->ono = irq_of_parse_and_map(dev->of_node, 1);
155
156 /*
157 * ToDo: the 'wakeup' member in the platform data is more of a linux
158 * specfic information. Hence, there is no binding for that yet and
159 * not parsed here.
160 */
161
162 return pd;
163}
Thomas Abraham77b71b32012-11-27 14:04:32 +0530164
Lee Jones05fb7a52014-01-23 14:35:28 +0000165static inline unsigned long max8997_i2c_get_driver_data(struct i2c_client *i2c,
Thomas Abraham77b71b32012-11-27 14:04:32 +0530166 const struct i2c_device_id *id)
167{
Manish Badarkhe01c3f112013-12-22 23:18:49 +0530168 if (IS_ENABLED(CONFIG_OF) && i2c->dev.of_node) {
Thomas Abraham77b71b32012-11-27 14:04:32 +0530169 const struct of_device_id *match;
170 match = of_match_node(max8997_pmic_dt_match, i2c->dev.of_node);
Lee Jones05fb7a52014-01-23 14:35:28 +0000171 return (unsigned long)match->data;
Thomas Abraham77b71b32012-11-27 14:04:32 +0530172 }
Lee Jones05fb7a52014-01-23 14:35:28 +0000173 return id->driver_data;
Thomas Abraham77b71b32012-11-27 14:04:32 +0530174}
175
MyungJoo Ham527e7e92011-03-04 15:50:26 +0900176static int max8997_i2c_probe(struct i2c_client *i2c,
177 const struct i2c_device_id *id)
178{
179 struct max8997_dev *max8997;
Jingoo Han334a41c2013-07-30 17:10:05 +0900180 struct max8997_platform_data *pdata = dev_get_platdata(&i2c->dev);
MyungJoo Ham527e7e92011-03-04 15:50:26 +0900181 int ret = 0;
182
Jingoo Han6922ffc2013-08-20 16:03:20 +0900183 max8997 = devm_kzalloc(&i2c->dev, sizeof(struct max8997_dev),
184 GFP_KERNEL);
MyungJoo Ham527e7e92011-03-04 15:50:26 +0900185 if (max8997 == NULL)
186 return -ENOMEM;
187
188 i2c_set_clientdata(i2c, max8997);
189 max8997->dev = &i2c->dev;
190 max8997->i2c = i2c;
Thomas Abraham77b71b32012-11-27 14:04:32 +0530191 max8997->type = max8997_i2c_get_driver_data(i2c, id);
MyungJoo Ham7eb31542011-08-18 16:37:35 +0900192 max8997->irq = i2c->irq;
MyungJoo Ham527e7e92011-03-04 15:50:26 +0900193
Manish Badarkhe01c3f112013-12-22 23:18:49 +0530194 if (IS_ENABLED(CONFIG_OF) && max8997->dev->of_node) {
Thomas Abraham77b71b32012-11-27 14:04:32 +0530195 pdata = max8997_i2c_parse_dt_pdata(max8997->dev);
Jingoo Han6922ffc2013-08-20 16:03:20 +0900196 if (IS_ERR(pdata))
197 return PTR_ERR(pdata);
Thomas Abraham77b71b32012-11-27 14:04:32 +0530198 }
199
MyungJoo Ham527e7e92011-03-04 15:50:26 +0900200 if (!pdata)
Jingoo Han6922ffc2013-08-20 16:03:20 +0900201 return ret;
MyungJoo Ham527e7e92011-03-04 15:50:26 +0900202
Thomas Abraham77b71b32012-11-27 14:04:32 +0530203 max8997->pdata = pdata;
MyungJoo Ham7eb31542011-08-18 16:37:35 +0900204 max8997->ono = pdata->ono;
MyungJoo Ham527e7e92011-03-04 15:50:26 +0900205
206 mutex_init(&max8997->iolock);
207
208 max8997->rtc = i2c_new_dummy(i2c->adapter, I2C_ADDR_RTC);
Krzysztof Kozlowski97dc4ed2014-02-11 11:03:34 +0100209 if (!max8997->rtc) {
210 dev_err(max8997->dev, "Failed to allocate I2C device for RTC\n");
211 return -ENODEV;
212 }
MyungJoo Ham527e7e92011-03-04 15:50:26 +0900213 i2c_set_clientdata(max8997->rtc, max8997);
Krzysztof Kozlowski97dc4ed2014-02-11 11:03:34 +0100214
MyungJoo Ham527e7e92011-03-04 15:50:26 +0900215 max8997->haptic = i2c_new_dummy(i2c->adapter, I2C_ADDR_HAPTIC);
Krzysztof Kozlowski97dc4ed2014-02-11 11:03:34 +0100216 if (!max8997->haptic) {
217 dev_err(max8997->dev, "Failed to allocate I2C device for Haptic\n");
218 ret = -ENODEV;
219 goto err_i2c_haptic;
220 }
MyungJoo Ham527e7e92011-03-04 15:50:26 +0900221 i2c_set_clientdata(max8997->haptic, max8997);
Krzysztof Kozlowski97dc4ed2014-02-11 11:03:34 +0100222
MyungJoo Ham527e7e92011-03-04 15:50:26 +0900223 max8997->muic = i2c_new_dummy(i2c->adapter, I2C_ADDR_MUIC);
Krzysztof Kozlowski97dc4ed2014-02-11 11:03:34 +0100224 if (!max8997->muic) {
225 dev_err(max8997->dev, "Failed to allocate I2C device for MUIC\n");
226 ret = -ENODEV;
227 goto err_i2c_muic;
228 }
MyungJoo Ham527e7e92011-03-04 15:50:26 +0900229 i2c_set_clientdata(max8997->muic, max8997);
230
231 pm_runtime_set_active(max8997->dev);
232
MyungJoo Ham7eb31542011-08-18 16:37:35 +0900233 max8997_irq_init(max8997);
234
Laszlo Pappc1ec8fc2013-12-17 12:49:51 +0000235 ret = mfd_add_devices(max8997->dev, -1, max8997_devs,
MyungJoo Ham527e7e92011-03-04 15:50:26 +0900236 ARRAY_SIZE(max8997_devs),
Mark Brown0848c942012-09-11 15:16:36 +0800237 NULL, 0, NULL);
Laszlo Pappc1ec8fc2013-12-17 12:49:51 +0000238 if (ret < 0) {
239 dev_err(max8997->dev, "failed to add MFD devices %d\n", ret);
240 goto err_mfd;
241 }
MyungJoo Ham527e7e92011-03-04 15:50:26 +0900242
243 /*
244 * TODO: enable others (flash, muic, rtc, battery, ...) and
245 * check the return value
246 */
247
MyungJoo Ham01fdaab2011-08-19 14:39:40 +0900248 /* MAX8997 has a power button input. */
249 device_init_wakeup(max8997->dev, pdata->wakeup);
250
MyungJoo Ham527e7e92011-03-04 15:50:26 +0900251 return ret;
252
253err_mfd:
254 mfd_remove_devices(max8997->dev);
255 i2c_unregister_device(max8997->muic);
Krzysztof Kozlowski97dc4ed2014-02-11 11:03:34 +0100256err_i2c_muic:
MyungJoo Ham527e7e92011-03-04 15:50:26 +0900257 i2c_unregister_device(max8997->haptic);
Krzysztof Kozlowski97dc4ed2014-02-11 11:03:34 +0100258err_i2c_haptic:
MyungJoo Ham527e7e92011-03-04 15:50:26 +0900259 i2c_unregister_device(max8997->rtc);
MyungJoo Ham527e7e92011-03-04 15:50:26 +0900260 return ret;
261}
262
MyungJoo Ham527e7e92011-03-04 15:50:26 +0900263static const struct i2c_device_id max8997_i2c_id[] = {
264 { "max8997", TYPE_MAX8997 },
265 { "max8966", TYPE_MAX8966 },
266 { }
267};
MyungJoo Ham527e7e92011-03-04 15:50:26 +0900268
Sachin Kamatb673e242012-06-04 16:39:07 +0530269static u8 max8997_dumpaddr_pmic[] = {
MyungJoo Ham527e7e92011-03-04 15:50:26 +0900270 MAX8997_REG_INT1MSK,
271 MAX8997_REG_INT2MSK,
272 MAX8997_REG_INT3MSK,
273 MAX8997_REG_INT4MSK,
274 MAX8997_REG_MAINCON1,
275 MAX8997_REG_MAINCON2,
276 MAX8997_REG_BUCKRAMP,
277 MAX8997_REG_BUCK1CTRL,
278 MAX8997_REG_BUCK1DVS1,
279 MAX8997_REG_BUCK1DVS2,
280 MAX8997_REG_BUCK1DVS3,
281 MAX8997_REG_BUCK1DVS4,
282 MAX8997_REG_BUCK1DVS5,
283 MAX8997_REG_BUCK1DVS6,
284 MAX8997_REG_BUCK1DVS7,
285 MAX8997_REG_BUCK1DVS8,
286 MAX8997_REG_BUCK2CTRL,
287 MAX8997_REG_BUCK2DVS1,
288 MAX8997_REG_BUCK2DVS2,
289 MAX8997_REG_BUCK2DVS3,
290 MAX8997_REG_BUCK2DVS4,
291 MAX8997_REG_BUCK2DVS5,
292 MAX8997_REG_BUCK2DVS6,
293 MAX8997_REG_BUCK2DVS7,
294 MAX8997_REG_BUCK2DVS8,
295 MAX8997_REG_BUCK3CTRL,
296 MAX8997_REG_BUCK3DVS,
297 MAX8997_REG_BUCK4CTRL,
298 MAX8997_REG_BUCK4DVS,
299 MAX8997_REG_BUCK5CTRL,
300 MAX8997_REG_BUCK5DVS1,
301 MAX8997_REG_BUCK5DVS2,
302 MAX8997_REG_BUCK5DVS3,
303 MAX8997_REG_BUCK5DVS4,
304 MAX8997_REG_BUCK5DVS5,
305 MAX8997_REG_BUCK5DVS6,
306 MAX8997_REG_BUCK5DVS7,
307 MAX8997_REG_BUCK5DVS8,
308 MAX8997_REG_BUCK6CTRL,
309 MAX8997_REG_BUCK6BPSKIPCTRL,
310 MAX8997_REG_BUCK7CTRL,
311 MAX8997_REG_BUCK7DVS,
312 MAX8997_REG_LDO1CTRL,
313 MAX8997_REG_LDO2CTRL,
314 MAX8997_REG_LDO3CTRL,
315 MAX8997_REG_LDO4CTRL,
316 MAX8997_REG_LDO5CTRL,
317 MAX8997_REG_LDO6CTRL,
318 MAX8997_REG_LDO7CTRL,
319 MAX8997_REG_LDO8CTRL,
320 MAX8997_REG_LDO9CTRL,
321 MAX8997_REG_LDO10CTRL,
322 MAX8997_REG_LDO11CTRL,
323 MAX8997_REG_LDO12CTRL,
324 MAX8997_REG_LDO13CTRL,
325 MAX8997_REG_LDO14CTRL,
326 MAX8997_REG_LDO15CTRL,
327 MAX8997_REG_LDO16CTRL,
328 MAX8997_REG_LDO17CTRL,
329 MAX8997_REG_LDO18CTRL,
330 MAX8997_REG_LDO21CTRL,
331 MAX8997_REG_MBCCTRL1,
332 MAX8997_REG_MBCCTRL2,
333 MAX8997_REG_MBCCTRL3,
334 MAX8997_REG_MBCCTRL4,
335 MAX8997_REG_MBCCTRL5,
336 MAX8997_REG_MBCCTRL6,
337 MAX8997_REG_OTPCGHCVS,
338 MAX8997_REG_SAFEOUTCTRL,
339 MAX8997_REG_LBCNFG1,
340 MAX8997_REG_LBCNFG2,
341 MAX8997_REG_BBCCTRL,
342
343 MAX8997_REG_FLASH1_CUR,
344 MAX8997_REG_FLASH2_CUR,
345 MAX8997_REG_MOVIE_CUR,
346 MAX8997_REG_GSMB_CUR,
347 MAX8997_REG_BOOST_CNTL,
348 MAX8997_REG_LEN_CNTL,
349 MAX8997_REG_FLASH_CNTL,
350 MAX8997_REG_WDT_CNTL,
351 MAX8997_REG_MAXFLASH1,
352 MAX8997_REG_MAXFLASH2,
353 MAX8997_REG_FLASHSTATUSMASK,
354
355 MAX8997_REG_GPIOCNTL1,
356 MAX8997_REG_GPIOCNTL2,
357 MAX8997_REG_GPIOCNTL3,
358 MAX8997_REG_GPIOCNTL4,
359 MAX8997_REG_GPIOCNTL5,
360 MAX8997_REG_GPIOCNTL6,
361 MAX8997_REG_GPIOCNTL7,
362 MAX8997_REG_GPIOCNTL8,
363 MAX8997_REG_GPIOCNTL9,
364 MAX8997_REG_GPIOCNTL10,
365 MAX8997_REG_GPIOCNTL11,
366 MAX8997_REG_GPIOCNTL12,
367
368 MAX8997_REG_LDO1CONFIG,
369 MAX8997_REG_LDO2CONFIG,
370 MAX8997_REG_LDO3CONFIG,
371 MAX8997_REG_LDO4CONFIG,
372 MAX8997_REG_LDO5CONFIG,
373 MAX8997_REG_LDO6CONFIG,
374 MAX8997_REG_LDO7CONFIG,
375 MAX8997_REG_LDO8CONFIG,
376 MAX8997_REG_LDO9CONFIG,
377 MAX8997_REG_LDO10CONFIG,
378 MAX8997_REG_LDO11CONFIG,
379 MAX8997_REG_LDO12CONFIG,
380 MAX8997_REG_LDO13CONFIG,
381 MAX8997_REG_LDO14CONFIG,
382 MAX8997_REG_LDO15CONFIG,
383 MAX8997_REG_LDO16CONFIG,
384 MAX8997_REG_LDO17CONFIG,
385 MAX8997_REG_LDO18CONFIG,
386 MAX8997_REG_LDO21CONFIG,
387
388 MAX8997_REG_DVSOKTIMER1,
389 MAX8997_REG_DVSOKTIMER2,
390 MAX8997_REG_DVSOKTIMER4,
391 MAX8997_REG_DVSOKTIMER5,
392};
393
Sachin Kamatb673e242012-06-04 16:39:07 +0530394static u8 max8997_dumpaddr_muic[] = {
MyungJoo Ham527e7e92011-03-04 15:50:26 +0900395 MAX8997_MUIC_REG_INTMASK1,
396 MAX8997_MUIC_REG_INTMASK2,
397 MAX8997_MUIC_REG_INTMASK3,
398 MAX8997_MUIC_REG_CDETCTRL,
399 MAX8997_MUIC_REG_CONTROL1,
400 MAX8997_MUIC_REG_CONTROL2,
401 MAX8997_MUIC_REG_CONTROL3,
402};
403
Sachin Kamatb673e242012-06-04 16:39:07 +0530404static u8 max8997_dumpaddr_haptic[] = {
MyungJoo Ham527e7e92011-03-04 15:50:26 +0900405 MAX8997_HAPTIC_REG_CONF1,
406 MAX8997_HAPTIC_REG_CONF2,
407 MAX8997_HAPTIC_REG_DRVCONF,
408 MAX8997_HAPTIC_REG_CYCLECONF1,
409 MAX8997_HAPTIC_REG_CYCLECONF2,
410 MAX8997_HAPTIC_REG_SIGCONF1,
411 MAX8997_HAPTIC_REG_SIGCONF2,
412 MAX8997_HAPTIC_REG_SIGCONF3,
413 MAX8997_HAPTIC_REG_SIGCONF4,
414 MAX8997_HAPTIC_REG_SIGDC1,
415 MAX8997_HAPTIC_REG_SIGDC2,
416 MAX8997_HAPTIC_REG_SIGPWMDC1,
417 MAX8997_HAPTIC_REG_SIGPWMDC2,
418 MAX8997_HAPTIC_REG_SIGPWMDC3,
419 MAX8997_HAPTIC_REG_SIGPWMDC4,
420};
421
422static int max8997_freeze(struct device *dev)
423{
Geliang Tang1b5420e2015-12-28 23:00:14 +0800424 struct i2c_client *i2c = to_i2c_client(dev);
MyungJoo Ham527e7e92011-03-04 15:50:26 +0900425 struct max8997_dev *max8997 = i2c_get_clientdata(i2c);
426 int i;
427
428 for (i = 0; i < ARRAY_SIZE(max8997_dumpaddr_pmic); i++)
429 max8997_read_reg(i2c, max8997_dumpaddr_pmic[i],
430 &max8997->reg_dump[i]);
431
432 for (i = 0; i < ARRAY_SIZE(max8997_dumpaddr_muic); i++)
433 max8997_read_reg(i2c, max8997_dumpaddr_muic[i],
434 &max8997->reg_dump[i + MAX8997_REG_PMIC_END]);
435
436 for (i = 0; i < ARRAY_SIZE(max8997_dumpaddr_haptic); i++)
437 max8997_read_reg(i2c, max8997_dumpaddr_haptic[i],
438 &max8997->reg_dump[i + MAX8997_REG_PMIC_END +
439 MAX8997_MUIC_REG_END]);
440
441 return 0;
442}
443
444static int max8997_restore(struct device *dev)
445{
Geliang Tang1b5420e2015-12-28 23:00:14 +0800446 struct i2c_client *i2c = to_i2c_client(dev);
MyungJoo Ham527e7e92011-03-04 15:50:26 +0900447 struct max8997_dev *max8997 = i2c_get_clientdata(i2c);
448 int i;
449
450 for (i = 0; i < ARRAY_SIZE(max8997_dumpaddr_pmic); i++)
451 max8997_write_reg(i2c, max8997_dumpaddr_pmic[i],
452 max8997->reg_dump[i]);
453
454 for (i = 0; i < ARRAY_SIZE(max8997_dumpaddr_muic); i++)
455 max8997_write_reg(i2c, max8997_dumpaddr_muic[i],
456 max8997->reg_dump[i + MAX8997_REG_PMIC_END]);
457
458 for (i = 0; i < ARRAY_SIZE(max8997_dumpaddr_haptic); i++)
459 max8997_write_reg(i2c, max8997_dumpaddr_haptic[i],
460 max8997->reg_dump[i + MAX8997_REG_PMIC_END +
461 MAX8997_MUIC_REG_END]);
462
463 return 0;
464}
465
MyungJoo Ham01fdaab2011-08-19 14:39:40 +0900466static int max8997_suspend(struct device *dev)
467{
Geliang Tang1b5420e2015-12-28 23:00:14 +0800468 struct i2c_client *i2c = to_i2c_client(dev);
MyungJoo Ham01fdaab2011-08-19 14:39:40 +0900469 struct max8997_dev *max8997 = i2c_get_clientdata(i2c);
470
471 if (device_may_wakeup(dev))
472 irq_set_irq_wake(max8997->irq, 1);
473 return 0;
474}
475
476static int max8997_resume(struct device *dev)
477{
Geliang Tang1b5420e2015-12-28 23:00:14 +0800478 struct i2c_client *i2c = to_i2c_client(dev);
MyungJoo Ham01fdaab2011-08-19 14:39:40 +0900479 struct max8997_dev *max8997 = i2c_get_clientdata(i2c);
480
481 if (device_may_wakeup(dev))
482 irq_set_irq_wake(max8997->irq, 0);
483 return max8997_irq_resume(max8997);
484}
485
Sachin Kamatb673e242012-06-04 16:39:07 +0530486static const struct dev_pm_ops max8997_pm = {
MyungJoo Ham01fdaab2011-08-19 14:39:40 +0900487 .suspend = max8997_suspend,
488 .resume = max8997_resume,
MyungJoo Ham527e7e92011-03-04 15:50:26 +0900489 .freeze = max8997_freeze,
490 .restore = max8997_restore,
491};
492
493static struct i2c_driver max8997_i2c_driver = {
494 .driver = {
495 .name = "max8997",
MyungJoo Ham527e7e92011-03-04 15:50:26 +0900496 .pm = &max8997_pm,
Paul Gortmaker9cf0c212016-06-02 20:39:47 -0400497 .suppress_bind_attrs = true,
Thomas Abraham77b71b32012-11-27 14:04:32 +0530498 .of_match_table = of_match_ptr(max8997_pmic_dt_match),
MyungJoo Ham527e7e92011-03-04 15:50:26 +0900499 },
500 .probe = max8997_i2c_probe,
MyungJoo Ham527e7e92011-03-04 15:50:26 +0900501 .id_table = max8997_i2c_id,
502};
503
504static int __init max8997_i2c_init(void)
505{
506 return i2c_add_driver(&max8997_i2c_driver);
507}
508/* init early so consumer devices can complete system boot */
509subsys_initcall(max8997_i2c_init);