Linux Audio

Check our new training course

Loading...
v5.9
  1// SPDX-License-Identifier: GPL-2.0+
  2//
  3// max8998.c - mfd core driver for the Maxim 8998
  4//
  5//  Copyright (C) 2009-2010 Samsung Electronics
  6//  Kyungmin Park <kyungmin.park@samsung.com>
  7//  Marek Szyprowski <m.szyprowski@samsung.com>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  8
  9#include <linux/err.h>
 10#include <linux/init.h>
 11#include <linux/slab.h>
 12#include <linux/i2c.h>
 13#include <linux/interrupt.h>
 14#include <linux/of.h>
 15#include <linux/of_irq.h>
 16#include <linux/pm_runtime.h>
 17#include <linux/mutex.h>
 18#include <linux/mfd/core.h>
 19#include <linux/mfd/max8998.h>
 20#include <linux/mfd/max8998-private.h>
 21
 22#define RTC_I2C_ADDR		(0x0c >> 1)
 23
 24static const struct mfd_cell max8998_devs[] = {
 25	{
 26		.name = "max8998-pmic",
 27	}, {
 28		.name = "max8998-rtc",
 29	}, {
 30		.name = "max8998-battery",
 31	},
 32};
 33
 34static const struct mfd_cell lp3974_devs[] = {
 35	{
 36		.name = "lp3974-pmic",
 37	}, {
 38		.name = "lp3974-rtc",
 39	},
 40};
 41
 42int max8998_read_reg(struct i2c_client *i2c, u8 reg, u8 *dest)
 43{
 44	struct max8998_dev *max8998 = i2c_get_clientdata(i2c);
 45	int ret;
 46
 47	mutex_lock(&max8998->iolock);
 48	ret = i2c_smbus_read_byte_data(i2c, reg);
 49	mutex_unlock(&max8998->iolock);
 50	if (ret < 0)
 51		return ret;
 52
 53	ret &= 0xff;
 54	*dest = ret;
 55	return 0;
 56}
 57EXPORT_SYMBOL(max8998_read_reg);
 58
 59int max8998_bulk_read(struct i2c_client *i2c, u8 reg, int count, u8 *buf)
 60{
 61	struct max8998_dev *max8998 = i2c_get_clientdata(i2c);
 62	int ret;
 63
 64	mutex_lock(&max8998->iolock);
 65	ret = i2c_smbus_read_i2c_block_data(i2c, reg, count, buf);
 66	mutex_unlock(&max8998->iolock);
 67	if (ret < 0)
 68		return ret;
 69
 70	return 0;
 71}
 72EXPORT_SYMBOL(max8998_bulk_read);
 73
 74int max8998_write_reg(struct i2c_client *i2c, u8 reg, u8 value)
 75{
 76	struct max8998_dev *max8998 = i2c_get_clientdata(i2c);
 77	int ret;
 78
 79	mutex_lock(&max8998->iolock);
 80	ret = i2c_smbus_write_byte_data(i2c, reg, value);
 81	mutex_unlock(&max8998->iolock);
 82	return ret;
 83}
 84EXPORT_SYMBOL(max8998_write_reg);
 85
 86int max8998_bulk_write(struct i2c_client *i2c, u8 reg, int count, u8 *buf)
 87{
 88	struct max8998_dev *max8998 = i2c_get_clientdata(i2c);
 89	int ret;
 90
 91	mutex_lock(&max8998->iolock);
 92	ret = i2c_smbus_write_i2c_block_data(i2c, reg, count, buf);
 93	mutex_unlock(&max8998->iolock);
 94	if (ret < 0)
 95		return ret;
 96
 97	return 0;
 98}
 99EXPORT_SYMBOL(max8998_bulk_write);
100
101int max8998_update_reg(struct i2c_client *i2c, u8 reg, u8 val, u8 mask)
102{
103	struct max8998_dev *max8998 = i2c_get_clientdata(i2c);
104	int ret;
105
106	mutex_lock(&max8998->iolock);
107	ret = i2c_smbus_read_byte_data(i2c, reg);
108	if (ret >= 0) {
109		u8 old_val = ret & 0xff;
110		u8 new_val = (val & mask) | (old_val & (~mask));
111		ret = i2c_smbus_write_byte_data(i2c, reg, new_val);
112	}
113	mutex_unlock(&max8998->iolock);
114	return ret;
115}
116EXPORT_SYMBOL(max8998_update_reg);
117
118#ifdef CONFIG_OF
119static const struct of_device_id max8998_dt_match[] = {
120	{ .compatible = "maxim,max8998", .data = (void *)TYPE_MAX8998 },
121	{ .compatible = "national,lp3974", .data = (void *)TYPE_LP3974 },
122	{ .compatible = "ti,lp3974", .data = (void *)TYPE_LP3974 },
123	{},
124};
125#endif
126
127/*
128 * Only the common platform data elements for max8998 are parsed here from the
129 * device tree. Other sub-modules of max8998 such as pmic, rtc and others have
130 * to parse their own platform data elements from device tree.
131 *
132 * The max8998 platform data structure is instantiated here and the drivers for
133 * the sub-modules need not instantiate another instance while parsing their
134 * platform data.
135 */
136static struct max8998_platform_data *max8998_i2c_parse_dt_pdata(
137							struct device *dev)
138{
139	struct max8998_platform_data *pd;
140
141	pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL);
142	if (!pd)
143		return ERR_PTR(-ENOMEM);
144
145	pd->ono = irq_of_parse_and_map(dev->of_node, 1);
146
147	/*
148	 * ToDo: the 'wakeup' member in the platform data is more of a linux
149	 * specfic information. Hence, there is no binding for that yet and
150	 * not parsed here.
151	 */
152	return pd;
153}
154
155static inline unsigned long max8998_i2c_get_driver_data(struct i2c_client *i2c,
156						const struct i2c_device_id *id)
157{
158	if (IS_ENABLED(CONFIG_OF) && i2c->dev.of_node) {
159		const struct of_device_id *match;
160		match = of_match_node(max8998_dt_match, i2c->dev.of_node);
161		return (unsigned long)match->data;
162	}
163
164	return id->driver_data;
165}
166
167static int max8998_i2c_probe(struct i2c_client *i2c,
168			    const struct i2c_device_id *id)
169{
170	struct max8998_platform_data *pdata = dev_get_platdata(&i2c->dev);
171	struct max8998_dev *max8998;
172	int ret = 0;
173
174	max8998 = devm_kzalloc(&i2c->dev, sizeof(struct max8998_dev),
175				GFP_KERNEL);
176	if (max8998 == NULL)
177		return -ENOMEM;
178
179	if (IS_ENABLED(CONFIG_OF) && i2c->dev.of_node) {
180		pdata = max8998_i2c_parse_dt_pdata(&i2c->dev);
181		if (IS_ERR(pdata))
182			return PTR_ERR(pdata);
 
 
183	}
184
185	i2c_set_clientdata(i2c, max8998);
186	max8998->dev = &i2c->dev;
187	max8998->i2c = i2c;
188	max8998->irq = i2c->irq;
189	max8998->type = max8998_i2c_get_driver_data(i2c, id);
190	max8998->pdata = pdata;
191	if (pdata) {
192		max8998->ono = pdata->ono;
193		max8998->irq_base = pdata->irq_base;
194		max8998->wakeup = pdata->wakeup;
195	}
196	mutex_init(&max8998->iolock);
197
198	max8998->rtc = i2c_new_dummy_device(i2c->adapter, RTC_I2C_ADDR);
199	if (IS_ERR(max8998->rtc)) {
200		dev_err(&i2c->dev, "Failed to allocate I2C device for RTC\n");
201		return PTR_ERR(max8998->rtc);
202	}
203	i2c_set_clientdata(max8998->rtc, max8998);
204
205	max8998_irq_init(max8998);
206
207	pm_runtime_set_active(max8998->dev);
208
209	switch (max8998->type) {
210	case TYPE_LP3974:
211		ret = mfd_add_devices(max8998->dev, -1,
212				      lp3974_devs, ARRAY_SIZE(lp3974_devs),
213				      NULL, 0, NULL);
214		break;
215	case TYPE_MAX8998:
216		ret = mfd_add_devices(max8998->dev, -1,
217				      max8998_devs, ARRAY_SIZE(max8998_devs),
218				      NULL, 0, NULL);
219		break;
220	default:
221		ret = -EINVAL;
222	}
223
224	if (ret < 0)
225		goto err;
226
227	device_init_wakeup(max8998->dev, max8998->wakeup);
228
229	return ret;
230
231err:
232	mfd_remove_devices(max8998->dev);
233	max8998_irq_exit(max8998);
234	i2c_unregister_device(max8998->rtc);
235	return ret;
236}
237
238static const struct i2c_device_id max8998_i2c_id[] = {
239	{ "max8998", TYPE_MAX8998 },
240	{ "lp3974", TYPE_LP3974},
241	{ }
242};
243
244static int max8998_suspend(struct device *dev)
245{
246	struct i2c_client *i2c = to_i2c_client(dev);
247	struct max8998_dev *max8998 = i2c_get_clientdata(i2c);
248
249	if (device_may_wakeup(dev))
250		irq_set_irq_wake(max8998->irq, 1);
251	return 0;
252}
253
254static int max8998_resume(struct device *dev)
255{
256	struct i2c_client *i2c = to_i2c_client(dev);
257	struct max8998_dev *max8998 = i2c_get_clientdata(i2c);
258
259	if (device_may_wakeup(dev))
260		irq_set_irq_wake(max8998->irq, 0);
261	/*
262	 * In LP3974, if IRQ registers are not "read & clear"
263	 * when it's set during sleep, the interrupt becomes
264	 * disabled.
265	 */
266	return max8998_irq_resume(i2c_get_clientdata(i2c));
267}
268
269struct max8998_reg_dump {
270	u8	addr;
271	u8	val;
272};
273#define SAVE_ITEM(x)	{ .addr = (x), .val = 0x0, }
274static struct max8998_reg_dump max8998_dump[] = {
275	SAVE_ITEM(MAX8998_REG_IRQM1),
276	SAVE_ITEM(MAX8998_REG_IRQM2),
277	SAVE_ITEM(MAX8998_REG_IRQM3),
278	SAVE_ITEM(MAX8998_REG_IRQM4),
279	SAVE_ITEM(MAX8998_REG_STATUSM1),
280	SAVE_ITEM(MAX8998_REG_STATUSM2),
281	SAVE_ITEM(MAX8998_REG_CHGR1),
282	SAVE_ITEM(MAX8998_REG_CHGR2),
283	SAVE_ITEM(MAX8998_REG_LDO_ACTIVE_DISCHARGE1),
284	SAVE_ITEM(MAX8998_REG_LDO_ACTIVE_DISCHARGE1),
285	SAVE_ITEM(MAX8998_REG_BUCK_ACTIVE_DISCHARGE3),
286	SAVE_ITEM(MAX8998_REG_ONOFF1),
287	SAVE_ITEM(MAX8998_REG_ONOFF2),
288	SAVE_ITEM(MAX8998_REG_ONOFF3),
289	SAVE_ITEM(MAX8998_REG_ONOFF4),
290	SAVE_ITEM(MAX8998_REG_BUCK1_VOLTAGE1),
291	SAVE_ITEM(MAX8998_REG_BUCK1_VOLTAGE2),
292	SAVE_ITEM(MAX8998_REG_BUCK1_VOLTAGE3),
293	SAVE_ITEM(MAX8998_REG_BUCK1_VOLTAGE4),
294	SAVE_ITEM(MAX8998_REG_BUCK2_VOLTAGE1),
295	SAVE_ITEM(MAX8998_REG_BUCK2_VOLTAGE2),
296	SAVE_ITEM(MAX8998_REG_LDO2_LDO3),
297	SAVE_ITEM(MAX8998_REG_LDO4),
298	SAVE_ITEM(MAX8998_REG_LDO5),
299	SAVE_ITEM(MAX8998_REG_LDO6),
300	SAVE_ITEM(MAX8998_REG_LDO7),
301	SAVE_ITEM(MAX8998_REG_LDO8_LDO9),
302	SAVE_ITEM(MAX8998_REG_LDO10_LDO11),
303	SAVE_ITEM(MAX8998_REG_LDO12),
304	SAVE_ITEM(MAX8998_REG_LDO13),
305	SAVE_ITEM(MAX8998_REG_LDO14),
306	SAVE_ITEM(MAX8998_REG_LDO15),
307	SAVE_ITEM(MAX8998_REG_LDO16),
308	SAVE_ITEM(MAX8998_REG_LDO17),
309	SAVE_ITEM(MAX8998_REG_BKCHR),
310	SAVE_ITEM(MAX8998_REG_LBCNFG1),
311	SAVE_ITEM(MAX8998_REG_LBCNFG2),
312};
313/* Save registers before hibernation */
314static int max8998_freeze(struct device *dev)
315{
316	struct i2c_client *i2c = to_i2c_client(dev);
317	int i;
318
319	for (i = 0; i < ARRAY_SIZE(max8998_dump); i++)
320		max8998_read_reg(i2c, max8998_dump[i].addr,
321				&max8998_dump[i].val);
322
323	return 0;
324}
325
326/* Restore registers after hibernation */
327static int max8998_restore(struct device *dev)
328{
329	struct i2c_client *i2c = to_i2c_client(dev);
330	int i;
331
332	for (i = 0; i < ARRAY_SIZE(max8998_dump); i++)
333		max8998_write_reg(i2c, max8998_dump[i].addr,
334				max8998_dump[i].val);
335
336	return 0;
337}
338
339static const struct dev_pm_ops max8998_pm = {
340	.suspend = max8998_suspend,
341	.resume = max8998_resume,
342	.freeze = max8998_freeze,
343	.restore = max8998_restore,
344};
345
346static struct i2c_driver max8998_i2c_driver = {
347	.driver = {
348		   .name = "max8998",
349		   .pm = &max8998_pm,
350		   .suppress_bind_attrs = true,
351		   .of_match_table = of_match_ptr(max8998_dt_match),
352	},
353	.probe = max8998_i2c_probe,
354	.id_table = max8998_i2c_id,
355};
356
357static int __init max8998_i2c_init(void)
358{
359	return i2c_add_driver(&max8998_i2c_driver);
360}
361/* init early so consumer devices can complete system boot */
362subsys_initcall(max8998_i2c_init);
v4.10.11
  1/*
  2 * max8998.c - mfd core driver for the Maxim 8998
  3 *
  4 *  Copyright (C) 2009-2010 Samsung Electronics
  5 *  Kyungmin Park <kyungmin.park@samsung.com>
  6 *  Marek Szyprowski <m.szyprowski@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
 23#include <linux/err.h>
 24#include <linux/init.h>
 25#include <linux/slab.h>
 26#include <linux/i2c.h>
 27#include <linux/interrupt.h>
 28#include <linux/of.h>
 29#include <linux/of_irq.h>
 30#include <linux/pm_runtime.h>
 31#include <linux/mutex.h>
 32#include <linux/mfd/core.h>
 33#include <linux/mfd/max8998.h>
 34#include <linux/mfd/max8998-private.h>
 35
 36#define RTC_I2C_ADDR		(0x0c >> 1)
 37
 38static const struct mfd_cell max8998_devs[] = {
 39	{
 40		.name = "max8998-pmic",
 41	}, {
 42		.name = "max8998-rtc",
 43	}, {
 44		.name = "max8998-battery",
 45	},
 46};
 47
 48static const struct mfd_cell lp3974_devs[] = {
 49	{
 50		.name = "lp3974-pmic",
 51	}, {
 52		.name = "lp3974-rtc",
 53	},
 54};
 55
 56int max8998_read_reg(struct i2c_client *i2c, u8 reg, u8 *dest)
 57{
 58	struct max8998_dev *max8998 = i2c_get_clientdata(i2c);
 59	int ret;
 60
 61	mutex_lock(&max8998->iolock);
 62	ret = i2c_smbus_read_byte_data(i2c, reg);
 63	mutex_unlock(&max8998->iolock);
 64	if (ret < 0)
 65		return ret;
 66
 67	ret &= 0xff;
 68	*dest = ret;
 69	return 0;
 70}
 71EXPORT_SYMBOL(max8998_read_reg);
 72
 73int max8998_bulk_read(struct i2c_client *i2c, u8 reg, int count, u8 *buf)
 74{
 75	struct max8998_dev *max8998 = i2c_get_clientdata(i2c);
 76	int ret;
 77
 78	mutex_lock(&max8998->iolock);
 79	ret = i2c_smbus_read_i2c_block_data(i2c, reg, count, buf);
 80	mutex_unlock(&max8998->iolock);
 81	if (ret < 0)
 82		return ret;
 83
 84	return 0;
 85}
 86EXPORT_SYMBOL(max8998_bulk_read);
 87
 88int max8998_write_reg(struct i2c_client *i2c, u8 reg, u8 value)
 89{
 90	struct max8998_dev *max8998 = i2c_get_clientdata(i2c);
 91	int ret;
 92
 93	mutex_lock(&max8998->iolock);
 94	ret = i2c_smbus_write_byte_data(i2c, reg, value);
 95	mutex_unlock(&max8998->iolock);
 96	return ret;
 97}
 98EXPORT_SYMBOL(max8998_write_reg);
 99
100int max8998_bulk_write(struct i2c_client *i2c, u8 reg, int count, u8 *buf)
101{
102	struct max8998_dev *max8998 = i2c_get_clientdata(i2c);
103	int ret;
104
105	mutex_lock(&max8998->iolock);
106	ret = i2c_smbus_write_i2c_block_data(i2c, reg, count, buf);
107	mutex_unlock(&max8998->iolock);
108	if (ret < 0)
109		return ret;
110
111	return 0;
112}
113EXPORT_SYMBOL(max8998_bulk_write);
114
115int max8998_update_reg(struct i2c_client *i2c, u8 reg, u8 val, u8 mask)
116{
117	struct max8998_dev *max8998 = i2c_get_clientdata(i2c);
118	int ret;
119
120	mutex_lock(&max8998->iolock);
121	ret = i2c_smbus_read_byte_data(i2c, reg);
122	if (ret >= 0) {
123		u8 old_val = ret & 0xff;
124		u8 new_val = (val & mask) | (old_val & (~mask));
125		ret = i2c_smbus_write_byte_data(i2c, reg, new_val);
126	}
127	mutex_unlock(&max8998->iolock);
128	return ret;
129}
130EXPORT_SYMBOL(max8998_update_reg);
131
132#ifdef CONFIG_OF
133static const struct of_device_id max8998_dt_match[] = {
134	{ .compatible = "maxim,max8998", .data = (void *)TYPE_MAX8998 },
135	{ .compatible = "national,lp3974", .data = (void *)TYPE_LP3974 },
136	{ .compatible = "ti,lp3974", .data = (void *)TYPE_LP3974 },
137	{},
138};
139#endif
140
141/*
142 * Only the common platform data elements for max8998 are parsed here from the
143 * device tree. Other sub-modules of max8998 such as pmic, rtc and others have
144 * to parse their own platform data elements from device tree.
145 *
146 * The max8998 platform data structure is instantiated here and the drivers for
147 * the sub-modules need not instantiate another instance while parsing their
148 * platform data.
149 */
150static struct max8998_platform_data *max8998_i2c_parse_dt_pdata(
151							struct device *dev)
152{
153	struct max8998_platform_data *pd;
154
155	pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL);
156	if (!pd)
157		return ERR_PTR(-ENOMEM);
158
159	pd->ono = irq_of_parse_and_map(dev->of_node, 1);
160
161	/*
162	 * ToDo: the 'wakeup' member in the platform data is more of a linux
163	 * specfic information. Hence, there is no binding for that yet and
164	 * not parsed here.
165	 */
166	return pd;
167}
168
169static inline unsigned long max8998_i2c_get_driver_data(struct i2c_client *i2c,
170						const struct i2c_device_id *id)
171{
172	if (IS_ENABLED(CONFIG_OF) && i2c->dev.of_node) {
173		const struct of_device_id *match;
174		match = of_match_node(max8998_dt_match, i2c->dev.of_node);
175		return (unsigned long)match->data;
176	}
177
178	return id->driver_data;
179}
180
181static int max8998_i2c_probe(struct i2c_client *i2c,
182			    const struct i2c_device_id *id)
183{
184	struct max8998_platform_data *pdata = dev_get_platdata(&i2c->dev);
185	struct max8998_dev *max8998;
186	int ret = 0;
187
188	max8998 = devm_kzalloc(&i2c->dev, sizeof(struct max8998_dev),
189				GFP_KERNEL);
190	if (max8998 == NULL)
191		return -ENOMEM;
192
193	if (IS_ENABLED(CONFIG_OF) && i2c->dev.of_node) {
194		pdata = max8998_i2c_parse_dt_pdata(&i2c->dev);
195		if (IS_ERR(pdata)) {
196			ret = PTR_ERR(pdata);
197			goto err;
198		}
199	}
200
201	i2c_set_clientdata(i2c, max8998);
202	max8998->dev = &i2c->dev;
203	max8998->i2c = i2c;
204	max8998->irq = i2c->irq;
205	max8998->type = max8998_i2c_get_driver_data(i2c, id);
206	max8998->pdata = pdata;
207	if (pdata) {
208		max8998->ono = pdata->ono;
209		max8998->irq_base = pdata->irq_base;
210		max8998->wakeup = pdata->wakeup;
211	}
212	mutex_init(&max8998->iolock);
213
214	max8998->rtc = i2c_new_dummy(i2c->adapter, RTC_I2C_ADDR);
215	if (!max8998->rtc) {
216		dev_err(&i2c->dev, "Failed to allocate I2C device for RTC\n");
217		return -ENODEV;
218	}
219	i2c_set_clientdata(max8998->rtc, max8998);
220
221	max8998_irq_init(max8998);
222
223	pm_runtime_set_active(max8998->dev);
224
225	switch (max8998->type) {
226	case TYPE_LP3974:
227		ret = mfd_add_devices(max8998->dev, -1,
228				      lp3974_devs, ARRAY_SIZE(lp3974_devs),
229				      NULL, 0, NULL);
230		break;
231	case TYPE_MAX8998:
232		ret = mfd_add_devices(max8998->dev, -1,
233				      max8998_devs, ARRAY_SIZE(max8998_devs),
234				      NULL, 0, NULL);
235		break;
236	default:
237		ret = -EINVAL;
238	}
239
240	if (ret < 0)
241		goto err;
242
243	device_init_wakeup(max8998->dev, max8998->wakeup);
244
245	return ret;
246
247err:
248	mfd_remove_devices(max8998->dev);
249	max8998_irq_exit(max8998);
250	i2c_unregister_device(max8998->rtc);
251	return ret;
252}
253
254static const struct i2c_device_id max8998_i2c_id[] = {
255	{ "max8998", TYPE_MAX8998 },
256	{ "lp3974", TYPE_LP3974},
257	{ }
258};
259
260static int max8998_suspend(struct device *dev)
261{
262	struct i2c_client *i2c = to_i2c_client(dev);
263	struct max8998_dev *max8998 = i2c_get_clientdata(i2c);
264
265	if (device_may_wakeup(dev))
266		irq_set_irq_wake(max8998->irq, 1);
267	return 0;
268}
269
270static int max8998_resume(struct device *dev)
271{
272	struct i2c_client *i2c = to_i2c_client(dev);
273	struct max8998_dev *max8998 = i2c_get_clientdata(i2c);
274
275	if (device_may_wakeup(dev))
276		irq_set_irq_wake(max8998->irq, 0);
277	/*
278	 * In LP3974, if IRQ registers are not "read & clear"
279	 * when it's set during sleep, the interrupt becomes
280	 * disabled.
281	 */
282	return max8998_irq_resume(i2c_get_clientdata(i2c));
283}
284
285struct max8998_reg_dump {
286	u8	addr;
287	u8	val;
288};
289#define SAVE_ITEM(x)	{ .addr = (x), .val = 0x0, }
290static struct max8998_reg_dump max8998_dump[] = {
291	SAVE_ITEM(MAX8998_REG_IRQM1),
292	SAVE_ITEM(MAX8998_REG_IRQM2),
293	SAVE_ITEM(MAX8998_REG_IRQM3),
294	SAVE_ITEM(MAX8998_REG_IRQM4),
295	SAVE_ITEM(MAX8998_REG_STATUSM1),
296	SAVE_ITEM(MAX8998_REG_STATUSM2),
297	SAVE_ITEM(MAX8998_REG_CHGR1),
298	SAVE_ITEM(MAX8998_REG_CHGR2),
299	SAVE_ITEM(MAX8998_REG_LDO_ACTIVE_DISCHARGE1),
300	SAVE_ITEM(MAX8998_REG_LDO_ACTIVE_DISCHARGE1),
301	SAVE_ITEM(MAX8998_REG_BUCK_ACTIVE_DISCHARGE3),
302	SAVE_ITEM(MAX8998_REG_ONOFF1),
303	SAVE_ITEM(MAX8998_REG_ONOFF2),
304	SAVE_ITEM(MAX8998_REG_ONOFF3),
305	SAVE_ITEM(MAX8998_REG_ONOFF4),
306	SAVE_ITEM(MAX8998_REG_BUCK1_VOLTAGE1),
307	SAVE_ITEM(MAX8998_REG_BUCK1_VOLTAGE2),
308	SAVE_ITEM(MAX8998_REG_BUCK1_VOLTAGE3),
309	SAVE_ITEM(MAX8998_REG_BUCK1_VOLTAGE4),
310	SAVE_ITEM(MAX8998_REG_BUCK2_VOLTAGE1),
311	SAVE_ITEM(MAX8998_REG_BUCK2_VOLTAGE2),
312	SAVE_ITEM(MAX8998_REG_LDO2_LDO3),
313	SAVE_ITEM(MAX8998_REG_LDO4),
314	SAVE_ITEM(MAX8998_REG_LDO5),
315	SAVE_ITEM(MAX8998_REG_LDO6),
316	SAVE_ITEM(MAX8998_REG_LDO7),
317	SAVE_ITEM(MAX8998_REG_LDO8_LDO9),
318	SAVE_ITEM(MAX8998_REG_LDO10_LDO11),
319	SAVE_ITEM(MAX8998_REG_LDO12),
320	SAVE_ITEM(MAX8998_REG_LDO13),
321	SAVE_ITEM(MAX8998_REG_LDO14),
322	SAVE_ITEM(MAX8998_REG_LDO15),
323	SAVE_ITEM(MAX8998_REG_LDO16),
324	SAVE_ITEM(MAX8998_REG_LDO17),
325	SAVE_ITEM(MAX8998_REG_BKCHR),
326	SAVE_ITEM(MAX8998_REG_LBCNFG1),
327	SAVE_ITEM(MAX8998_REG_LBCNFG2),
328};
329/* Save registers before hibernation */
330static int max8998_freeze(struct device *dev)
331{
332	struct i2c_client *i2c = to_i2c_client(dev);
333	int i;
334
335	for (i = 0; i < ARRAY_SIZE(max8998_dump); i++)
336		max8998_read_reg(i2c, max8998_dump[i].addr,
337				&max8998_dump[i].val);
338
339	return 0;
340}
341
342/* Restore registers after hibernation */
343static int max8998_restore(struct device *dev)
344{
345	struct i2c_client *i2c = to_i2c_client(dev);
346	int i;
347
348	for (i = 0; i < ARRAY_SIZE(max8998_dump); i++)
349		max8998_write_reg(i2c, max8998_dump[i].addr,
350				max8998_dump[i].val);
351
352	return 0;
353}
354
355static const struct dev_pm_ops max8998_pm = {
356	.suspend = max8998_suspend,
357	.resume = max8998_resume,
358	.freeze = max8998_freeze,
359	.restore = max8998_restore,
360};
361
362static struct i2c_driver max8998_i2c_driver = {
363	.driver = {
364		   .name = "max8998",
365		   .pm = &max8998_pm,
366		   .suppress_bind_attrs = true,
367		   .of_match_table = of_match_ptr(max8998_dt_match),
368	},
369	.probe = max8998_i2c_probe,
370	.id_table = max8998_i2c_id,
371};
372
373static int __init max8998_i2c_init(void)
374{
375	return i2c_add_driver(&max8998_i2c_driver);
376}
377/* init early so consumer devices can complete system boot */
378subsys_initcall(max8998_i2c_init);