2 * max77693.c - mfd core driver for the MAX 77693
4 * Copyright (C) 2012 Samsung Electronics
5 * SangYoung Son <hello.son@smasung.com>
7 * This program is not provided / owned by Maxim Integrated Products.
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.
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.
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
23 * This driver is based on max8997.c
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>
32 #include <linux/pm_runtime.h>
33 #include <linux/mutex.h>
34 #include <linux/mfd/core.h>
35 #include <linux/mfd/max77693.h>
36 #include <linux/mfd/max77693-private.h>
37 #include <linux/regulator/machine.h>
38 #include <linux/regmap.h>
40 #define I2C_ADDR_PMIC (0xCC >> 1) /* Charger, Flash LED */
41 #define I2C_ADDR_MUIC (0x4A >> 1)
42 #define I2C_ADDR_HAPTIC (0x90 >> 1)
44 static struct mfd_cell max77693_devs
[] = {
45 { .name
= "max77693-pmic", },
46 { .name
= "max77693-charger", },
47 { .name
= "max77693-flash", },
48 { .name
= "max77693-muic", },
49 { .name
= "max77693-haptic", },
52 int max77693_read_reg(struct regmap
*map
, u8 reg
, u8
*dest
)
57 ret
= regmap_read(map
, reg
, &val
);
62 EXPORT_SYMBOL_GPL(max77693_read_reg
);
64 int max77693_bulk_read(struct regmap
*map
, u8 reg
, int count
, u8
*buf
)
68 ret
= regmap_bulk_read(map
, reg
, buf
, count
);
72 EXPORT_SYMBOL_GPL(max77693_bulk_read
);
74 int max77693_write_reg(struct regmap
*map
, u8 reg
, u8 value
)
78 ret
= regmap_write(map
, reg
, value
);
82 EXPORT_SYMBOL_GPL(max77693_write_reg
);
84 int max77693_bulk_write(struct regmap
*map
, u8 reg
, int count
, u8
*buf
)
88 ret
= regmap_bulk_write(map
, reg
, buf
, count
);
92 EXPORT_SYMBOL_GPL(max77693_bulk_write
);
94 int max77693_update_reg(struct regmap
*map
, u8 reg
, u8 val
, u8 mask
)
98 ret
= regmap_update_bits(map
, reg
, mask
, val
);
102 EXPORT_SYMBOL_GPL(max77693_update_reg
);
104 static const struct regmap_config max77693_regmap_config
= {
107 .max_register
= MAX77693_PMIC_REG_END
,
110 static int max77693_i2c_probe(struct i2c_client
*i2c
,
111 const struct i2c_device_id
*id
)
113 struct max77693_dev
*max77693
;
117 max77693
= devm_kzalloc(&i2c
->dev
,
118 sizeof(struct max77693_dev
), GFP_KERNEL
);
119 if (max77693
== NULL
)
122 i2c_set_clientdata(i2c
, max77693
);
123 max77693
->dev
= &i2c
->dev
;
125 max77693
->irq
= i2c
->irq
;
126 max77693
->type
= id
->driver_data
;
128 max77693
->regmap
= devm_regmap_init_i2c(i2c
, &max77693_regmap_config
);
129 if (IS_ERR(max77693
->regmap
)) {
130 ret
= PTR_ERR(max77693
->regmap
);
131 dev_err(max77693
->dev
, "failed to allocate register map: %d\n",
136 ret
= max77693_read_reg(max77693
->regmap
, MAX77693_PMIC_REG_PMIC_ID2
,
139 dev_err(max77693
->dev
, "device not found on this channel\n");
142 dev_info(max77693
->dev
, "device ID: 0x%x\n", reg_data
);
144 max77693
->muic
= i2c_new_dummy(i2c
->adapter
, I2C_ADDR_MUIC
);
145 i2c_set_clientdata(max77693
->muic
, max77693
);
147 max77693
->haptic
= i2c_new_dummy(i2c
->adapter
, I2C_ADDR_HAPTIC
);
148 i2c_set_clientdata(max77693
->haptic
, max77693
);
151 * Initialize register map for MUIC device because use regmap-muic
152 * instance of MUIC device when irq of max77693 is initialized
153 * before call max77693-muic probe() function.
155 max77693
->regmap_muic
= devm_regmap_init_i2c(max77693
->muic
,
156 &max77693_regmap_config
);
157 if (IS_ERR(max77693
->regmap_muic
)) {
158 ret
= PTR_ERR(max77693
->regmap_muic
);
159 dev_err(max77693
->dev
,
160 "failed to allocate register map: %d\n", ret
);
161 goto err_regmap_muic
;
164 ret
= max77693_irq_init(max77693
);
168 pm_runtime_set_active(max77693
->dev
);
170 ret
= mfd_add_devices(max77693
->dev
, -1, max77693_devs
,
171 ARRAY_SIZE(max77693_devs
), NULL
, 0, NULL
);
178 max77693_irq_exit(max77693
);
181 i2c_unregister_device(max77693
->muic
);
182 i2c_unregister_device(max77693
->haptic
);
186 static int max77693_i2c_remove(struct i2c_client
*i2c
)
188 struct max77693_dev
*max77693
= i2c_get_clientdata(i2c
);
190 mfd_remove_devices(max77693
->dev
);
191 max77693_irq_exit(max77693
);
192 i2c_unregister_device(max77693
->muic
);
193 i2c_unregister_device(max77693
->haptic
);
198 static const struct i2c_device_id max77693_i2c_id
[] = {
199 { "max77693", TYPE_MAX77693
},
202 MODULE_DEVICE_TABLE(i2c
, max77693_i2c_id
);
204 static int max77693_suspend(struct device
*dev
)
206 struct i2c_client
*i2c
= container_of(dev
, struct i2c_client
, dev
);
207 struct max77693_dev
*max77693
= i2c_get_clientdata(i2c
);
209 if (device_may_wakeup(dev
))
210 irq_set_irq_wake(max77693
->irq
, 1);
214 static int max77693_resume(struct device
*dev
)
216 struct i2c_client
*i2c
= container_of(dev
, struct i2c_client
, dev
);
217 struct max77693_dev
*max77693
= i2c_get_clientdata(i2c
);
219 if (device_may_wakeup(dev
))
220 irq_set_irq_wake(max77693
->irq
, 0);
221 return max77693_irq_resume(max77693
);
224 static const struct dev_pm_ops max77693_pm
= {
225 .suspend
= max77693_suspend
,
226 .resume
= max77693_resume
,
230 static struct of_device_id max77693_dt_match
[] = {
231 { .compatible
= "maxim,max77693" },
236 static struct i2c_driver max77693_i2c_driver
= {
239 .owner
= THIS_MODULE
,
241 .of_match_table
= of_match_ptr(max77693_dt_match
),
243 .probe
= max77693_i2c_probe
,
244 .remove
= max77693_i2c_remove
,
245 .id_table
= max77693_i2c_id
,
248 static int __init
max77693_i2c_init(void)
250 return i2c_add_driver(&max77693_i2c_driver
);
252 /* init early so consumer devices can complete system boot */
253 subsys_initcall(max77693_i2c_init
);
255 static void __exit
max77693_i2c_exit(void)
257 i2c_del_driver(&max77693_i2c_driver
);
259 module_exit(max77693_i2c_exit
);
261 MODULE_DESCRIPTION("MAXIM 77693 multi-function core driver");
262 MODULE_AUTHOR("SangYoung, Son <hello.son@samsung.com>");
263 MODULE_LICENSE("GPL");