2 * max8997.c - mfd core driver for the Maxim 8966 and 8997
4 * Copyright (C) 2011 Samsung Electronics
5 * MyungJoo Ham <myungjoo.ham@smasung.com>
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.
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.
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
21 * This driver is based on max8998.c
24 #include <linux/slab.h>
25 #include <linux/i2c.h>
26 #include <linux/pm_runtime.h>
27 #include <linux/module.h>
28 #include <linux/mutex.h>
29 #include <linux/mfd/core.h>
30 #include <linux/mfd/max8997.h>
31 #include <linux/mfd/max8997-private.h>
33 #define I2C_ADDR_PMIC (0xCC >> 1)
34 #define I2C_ADDR_MUIC (0x4A >> 1)
35 #define I2C_ADDR_BATTERY (0x6C >> 1)
36 #define I2C_ADDR_RTC (0x0C >> 1)
37 #define I2C_ADDR_HAPTIC (0x90 >> 1)
39 static struct mfd_cell max8997_devs
[] = {
40 { .name
= "max8997-pmic", },
41 { .name
= "max8997-rtc", },
42 { .name
= "max8997-battery", },
43 { .name
= "max8997-haptic", },
44 { .name
= "max8997-muic", },
45 { .name
= "max8997-flash", },
48 int max8997_read_reg(struct i2c_client
*i2c
, u8 reg
, u8
*dest
)
50 struct max8997_dev
*max8997
= i2c_get_clientdata(i2c
);
53 mutex_lock(&max8997
->iolock
);
54 ret
= i2c_smbus_read_byte_data(i2c
, reg
);
55 mutex_unlock(&max8997
->iolock
);
63 EXPORT_SYMBOL_GPL(max8997_read_reg
);
65 int max8997_bulk_read(struct i2c_client
*i2c
, u8 reg
, int count
, u8
*buf
)
67 struct max8997_dev
*max8997
= i2c_get_clientdata(i2c
);
70 mutex_lock(&max8997
->iolock
);
71 ret
= i2c_smbus_read_i2c_block_data(i2c
, reg
, count
, buf
);
72 mutex_unlock(&max8997
->iolock
);
78 EXPORT_SYMBOL_GPL(max8997_bulk_read
);
80 int max8997_write_reg(struct i2c_client
*i2c
, u8 reg
, u8 value
)
82 struct max8997_dev
*max8997
= i2c_get_clientdata(i2c
);
85 mutex_lock(&max8997
->iolock
);
86 ret
= i2c_smbus_write_byte_data(i2c
, reg
, value
);
87 mutex_unlock(&max8997
->iolock
);
90 EXPORT_SYMBOL_GPL(max8997_write_reg
);
92 int max8997_bulk_write(struct i2c_client
*i2c
, u8 reg
, int count
, u8
*buf
)
94 struct max8997_dev
*max8997
= i2c_get_clientdata(i2c
);
97 mutex_lock(&max8997
->iolock
);
98 ret
= i2c_smbus_write_i2c_block_data(i2c
, reg
, count
, buf
);
99 mutex_unlock(&max8997
->iolock
);
105 EXPORT_SYMBOL_GPL(max8997_bulk_write
);
107 int max8997_update_reg(struct i2c_client
*i2c
, u8 reg
, u8 val
, u8 mask
)
109 struct max8997_dev
*max8997
= i2c_get_clientdata(i2c
);
112 mutex_lock(&max8997
->iolock
);
113 ret
= i2c_smbus_read_byte_data(i2c
, reg
);
115 u8 old_val
= ret
& 0xff;
116 u8 new_val
= (val
& mask
) | (old_val
& (~mask
));
117 ret
= i2c_smbus_write_byte_data(i2c
, reg
, new_val
);
119 mutex_unlock(&max8997
->iolock
);
122 EXPORT_SYMBOL_GPL(max8997_update_reg
);
124 static int max8997_i2c_probe(struct i2c_client
*i2c
,
125 const struct i2c_device_id
*id
)
127 struct max8997_dev
*max8997
;
128 struct max8997_platform_data
*pdata
= i2c
->dev
.platform_data
;
131 max8997
= kzalloc(sizeof(struct max8997_dev
), GFP_KERNEL
);
135 i2c_set_clientdata(i2c
, max8997
);
136 max8997
->dev
= &i2c
->dev
;
138 max8997
->type
= id
->driver_data
;
143 max8997
->wakeup
= pdata
->wakeup
;
145 mutex_init(&max8997
->iolock
);
147 max8997
->rtc
= i2c_new_dummy(i2c
->adapter
, I2C_ADDR_RTC
);
148 i2c_set_clientdata(max8997
->rtc
, max8997
);
149 max8997
->haptic
= i2c_new_dummy(i2c
->adapter
, I2C_ADDR_HAPTIC
);
150 i2c_set_clientdata(max8997
->haptic
, max8997
);
151 max8997
->muic
= i2c_new_dummy(i2c
->adapter
, I2C_ADDR_MUIC
);
152 i2c_set_clientdata(max8997
->muic
, max8997
);
154 pm_runtime_set_active(max8997
->dev
);
156 mfd_add_devices(max8997
->dev
, -1, max8997_devs
,
157 ARRAY_SIZE(max8997_devs
),
161 * TODO: enable others (flash, muic, rtc, battery, ...) and
162 * check the return value
171 mfd_remove_devices(max8997
->dev
);
172 i2c_unregister_device(max8997
->muic
);
173 i2c_unregister_device(max8997
->haptic
);
174 i2c_unregister_device(max8997
->rtc
);
180 static int max8997_i2c_remove(struct i2c_client
*i2c
)
182 struct max8997_dev
*max8997
= i2c_get_clientdata(i2c
);
184 mfd_remove_devices(max8997
->dev
);
185 i2c_unregister_device(max8997
->muic
);
186 i2c_unregister_device(max8997
->haptic
);
187 i2c_unregister_device(max8997
->rtc
);
193 static const struct i2c_device_id max8997_i2c_id
[] = {
194 { "max8997", TYPE_MAX8997
},
195 { "max8966", TYPE_MAX8966
},
198 MODULE_DEVICE_TABLE(i2c
, max8998_i2c_id
);
200 u8 max8997_dumpaddr_pmic
[] = {
205 MAX8997_REG_MAINCON1
,
206 MAX8997_REG_MAINCON2
,
207 MAX8997_REG_BUCKRAMP
,
208 MAX8997_REG_BUCK1CTRL
,
209 MAX8997_REG_BUCK1DVS1
,
210 MAX8997_REG_BUCK1DVS2
,
211 MAX8997_REG_BUCK1DVS3
,
212 MAX8997_REG_BUCK1DVS4
,
213 MAX8997_REG_BUCK1DVS5
,
214 MAX8997_REG_BUCK1DVS6
,
215 MAX8997_REG_BUCK1DVS7
,
216 MAX8997_REG_BUCK1DVS8
,
217 MAX8997_REG_BUCK2CTRL
,
218 MAX8997_REG_BUCK2DVS1
,
219 MAX8997_REG_BUCK2DVS2
,
220 MAX8997_REG_BUCK2DVS3
,
221 MAX8997_REG_BUCK2DVS4
,
222 MAX8997_REG_BUCK2DVS5
,
223 MAX8997_REG_BUCK2DVS6
,
224 MAX8997_REG_BUCK2DVS7
,
225 MAX8997_REG_BUCK2DVS8
,
226 MAX8997_REG_BUCK3CTRL
,
227 MAX8997_REG_BUCK3DVS
,
228 MAX8997_REG_BUCK4CTRL
,
229 MAX8997_REG_BUCK4DVS
,
230 MAX8997_REG_BUCK5CTRL
,
231 MAX8997_REG_BUCK5DVS1
,
232 MAX8997_REG_BUCK5DVS2
,
233 MAX8997_REG_BUCK5DVS3
,
234 MAX8997_REG_BUCK5DVS4
,
235 MAX8997_REG_BUCK5DVS5
,
236 MAX8997_REG_BUCK5DVS6
,
237 MAX8997_REG_BUCK5DVS7
,
238 MAX8997_REG_BUCK5DVS8
,
239 MAX8997_REG_BUCK6CTRL
,
240 MAX8997_REG_BUCK6BPSKIPCTRL
,
241 MAX8997_REG_BUCK7CTRL
,
242 MAX8997_REG_BUCK7DVS
,
243 MAX8997_REG_LDO1CTRL
,
244 MAX8997_REG_LDO2CTRL
,
245 MAX8997_REG_LDO3CTRL
,
246 MAX8997_REG_LDO4CTRL
,
247 MAX8997_REG_LDO5CTRL
,
248 MAX8997_REG_LDO6CTRL
,
249 MAX8997_REG_LDO7CTRL
,
250 MAX8997_REG_LDO8CTRL
,
251 MAX8997_REG_LDO9CTRL
,
252 MAX8997_REG_LDO10CTRL
,
253 MAX8997_REG_LDO11CTRL
,
254 MAX8997_REG_LDO12CTRL
,
255 MAX8997_REG_LDO13CTRL
,
256 MAX8997_REG_LDO14CTRL
,
257 MAX8997_REG_LDO15CTRL
,
258 MAX8997_REG_LDO16CTRL
,
259 MAX8997_REG_LDO17CTRL
,
260 MAX8997_REG_LDO18CTRL
,
261 MAX8997_REG_LDO21CTRL
,
262 MAX8997_REG_MBCCTRL1
,
263 MAX8997_REG_MBCCTRL2
,
264 MAX8997_REG_MBCCTRL3
,
265 MAX8997_REG_MBCCTRL4
,
266 MAX8997_REG_MBCCTRL5
,
267 MAX8997_REG_MBCCTRL6
,
268 MAX8997_REG_OTPCGHCVS
,
269 MAX8997_REG_SAFEOUTCTRL
,
274 MAX8997_REG_FLASH1_CUR
,
275 MAX8997_REG_FLASH2_CUR
,
276 MAX8997_REG_MOVIE_CUR
,
277 MAX8997_REG_GSMB_CUR
,
278 MAX8997_REG_BOOST_CNTL
,
279 MAX8997_REG_LEN_CNTL
,
280 MAX8997_REG_FLASH_CNTL
,
281 MAX8997_REG_WDT_CNTL
,
282 MAX8997_REG_MAXFLASH1
,
283 MAX8997_REG_MAXFLASH2
,
284 MAX8997_REG_FLASHSTATUSMASK
,
286 MAX8997_REG_GPIOCNTL1
,
287 MAX8997_REG_GPIOCNTL2
,
288 MAX8997_REG_GPIOCNTL3
,
289 MAX8997_REG_GPIOCNTL4
,
290 MAX8997_REG_GPIOCNTL5
,
291 MAX8997_REG_GPIOCNTL6
,
292 MAX8997_REG_GPIOCNTL7
,
293 MAX8997_REG_GPIOCNTL8
,
294 MAX8997_REG_GPIOCNTL9
,
295 MAX8997_REG_GPIOCNTL10
,
296 MAX8997_REG_GPIOCNTL11
,
297 MAX8997_REG_GPIOCNTL12
,
299 MAX8997_REG_LDO1CONFIG
,
300 MAX8997_REG_LDO2CONFIG
,
301 MAX8997_REG_LDO3CONFIG
,
302 MAX8997_REG_LDO4CONFIG
,
303 MAX8997_REG_LDO5CONFIG
,
304 MAX8997_REG_LDO6CONFIG
,
305 MAX8997_REG_LDO7CONFIG
,
306 MAX8997_REG_LDO8CONFIG
,
307 MAX8997_REG_LDO9CONFIG
,
308 MAX8997_REG_LDO10CONFIG
,
309 MAX8997_REG_LDO11CONFIG
,
310 MAX8997_REG_LDO12CONFIG
,
311 MAX8997_REG_LDO13CONFIG
,
312 MAX8997_REG_LDO14CONFIG
,
313 MAX8997_REG_LDO15CONFIG
,
314 MAX8997_REG_LDO16CONFIG
,
315 MAX8997_REG_LDO17CONFIG
,
316 MAX8997_REG_LDO18CONFIG
,
317 MAX8997_REG_LDO21CONFIG
,
319 MAX8997_REG_DVSOKTIMER1
,
320 MAX8997_REG_DVSOKTIMER2
,
321 MAX8997_REG_DVSOKTIMER4
,
322 MAX8997_REG_DVSOKTIMER5
,
325 u8 max8997_dumpaddr_muic
[] = {
326 MAX8997_MUIC_REG_INTMASK1
,
327 MAX8997_MUIC_REG_INTMASK2
,
328 MAX8997_MUIC_REG_INTMASK3
,
329 MAX8997_MUIC_REG_CDETCTRL
,
330 MAX8997_MUIC_REG_CONTROL1
,
331 MAX8997_MUIC_REG_CONTROL2
,
332 MAX8997_MUIC_REG_CONTROL3
,
335 u8 max8997_dumpaddr_haptic
[] = {
336 MAX8997_HAPTIC_REG_CONF1
,
337 MAX8997_HAPTIC_REG_CONF2
,
338 MAX8997_HAPTIC_REG_DRVCONF
,
339 MAX8997_HAPTIC_REG_CYCLECONF1
,
340 MAX8997_HAPTIC_REG_CYCLECONF2
,
341 MAX8997_HAPTIC_REG_SIGCONF1
,
342 MAX8997_HAPTIC_REG_SIGCONF2
,
343 MAX8997_HAPTIC_REG_SIGCONF3
,
344 MAX8997_HAPTIC_REG_SIGCONF4
,
345 MAX8997_HAPTIC_REG_SIGDC1
,
346 MAX8997_HAPTIC_REG_SIGDC2
,
347 MAX8997_HAPTIC_REG_SIGPWMDC1
,
348 MAX8997_HAPTIC_REG_SIGPWMDC2
,
349 MAX8997_HAPTIC_REG_SIGPWMDC3
,
350 MAX8997_HAPTIC_REG_SIGPWMDC4
,
353 static int max8997_freeze(struct device
*dev
)
355 struct i2c_client
*i2c
= container_of(dev
, struct i2c_client
, dev
);
356 struct max8997_dev
*max8997
= i2c_get_clientdata(i2c
);
359 for (i
= 0; i
< ARRAY_SIZE(max8997_dumpaddr_pmic
); i
++)
360 max8997_read_reg(i2c
, max8997_dumpaddr_pmic
[i
],
361 &max8997
->reg_dump
[i
]);
363 for (i
= 0; i
< ARRAY_SIZE(max8997_dumpaddr_muic
); i
++)
364 max8997_read_reg(i2c
, max8997_dumpaddr_muic
[i
],
365 &max8997
->reg_dump
[i
+ MAX8997_REG_PMIC_END
]);
367 for (i
= 0; i
< ARRAY_SIZE(max8997_dumpaddr_haptic
); i
++)
368 max8997_read_reg(i2c
, max8997_dumpaddr_haptic
[i
],
369 &max8997
->reg_dump
[i
+ MAX8997_REG_PMIC_END
+
370 MAX8997_MUIC_REG_END
]);
375 static int max8997_restore(struct device
*dev
)
377 struct i2c_client
*i2c
= container_of(dev
, struct i2c_client
, dev
);
378 struct max8997_dev
*max8997
= i2c_get_clientdata(i2c
);
381 for (i
= 0; i
< ARRAY_SIZE(max8997_dumpaddr_pmic
); i
++)
382 max8997_write_reg(i2c
, max8997_dumpaddr_pmic
[i
],
383 max8997
->reg_dump
[i
]);
385 for (i
= 0; i
< ARRAY_SIZE(max8997_dumpaddr_muic
); i
++)
386 max8997_write_reg(i2c
, max8997_dumpaddr_muic
[i
],
387 max8997
->reg_dump
[i
+ MAX8997_REG_PMIC_END
]);
389 for (i
= 0; i
< ARRAY_SIZE(max8997_dumpaddr_haptic
); i
++)
390 max8997_write_reg(i2c
, max8997_dumpaddr_haptic
[i
],
391 max8997
->reg_dump
[i
+ MAX8997_REG_PMIC_END
+
392 MAX8997_MUIC_REG_END
]);
397 const struct dev_pm_ops max8997_pm
= {
398 .freeze
= max8997_freeze
,
399 .restore
= max8997_restore
,
402 static struct i2c_driver max8997_i2c_driver
= {
405 .owner
= THIS_MODULE
,
408 .probe
= max8997_i2c_probe
,
409 .remove
= max8997_i2c_remove
,
410 .id_table
= max8997_i2c_id
,
413 static int __init
max8997_i2c_init(void)
415 return i2c_add_driver(&max8997_i2c_driver
);
417 /* init early so consumer devices can complete system boot */
418 subsys_initcall(max8997_i2c_init
);
420 static void __exit
max8997_i2c_exit(void)
422 i2c_del_driver(&max8997_i2c_driver
);
424 module_exit(max8997_i2c_exit
);
426 MODULE_DESCRIPTION("MAXIM 8997 multi-function core driver");
427 MODULE_AUTHOR("MyungJoo Ham <myungjoo.ham@samsung.com>");
428 MODULE_LICENSE("GPL");