blob: 4a69afb425ad3e2a034849c30902ab8a09ca6a41 [file] [log] [blame]
Sangbeom Kim0f5f7072011-12-23 17:28:08 +09001/*
Sangbeom Kim63063bf2012-07-11 21:06:55 +09002 * sec-core.c
Sangbeom Kim0f5f7072011-12-23 17:28:08 +09003 *
Sangbeom Kim63063bf2012-07-11 21:06:55 +09004 * Copyright (c) 2012 Samsung Electronics Co., Ltd
Sangbeom Kim0f5f7072011-12-23 17:28:08 +09005 * http://www.samsung.com
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 *
12 */
13
14#include <linux/module.h>
15#include <linux/moduleparam.h>
16#include <linux/init.h>
17#include <linux/err.h>
18#include <linux/slab.h>
19#include <linux/i2c.h>
Sachin Kamat1c5a0992013-10-16 14:26:52 +053020#include <linux/of.h>
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -080021#include <linux/of_irq.h>
Sangbeom Kim0f5f7072011-12-23 17:28:08 +090022#include <linux/interrupt.h>
23#include <linux/pm_runtime.h>
24#include <linux/mutex.h>
25#include <linux/mfd/core.h>
Sangbeom Kim54227bc2012-07-11 21:07:16 +090026#include <linux/mfd/samsung/core.h>
27#include <linux/mfd/samsung/irq.h>
Sachin Kamatce249912014-03-14 17:21:57 +053028#include <linux/mfd/samsung/s2mpa01.h>
Mark Brown25f311f2013-07-01 23:02:19 +010029#include <linux/mfd/samsung/s2mps11.h>
Chanwoo Choi76b98402014-11-18 17:59:40 +090030#include <linux/mfd/samsung/s2mps13.h>
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +010031#include <linux/mfd/samsung/s2mps14.h>
Chanwoo Choi00e25732014-06-25 16:14:45 +090032#include <linux/mfd/samsung/s2mpu02.h>
Mark Brown25f311f2013-07-01 23:02:19 +010033#include <linux/mfd/samsung/s5m8763.h>
34#include <linux/mfd/samsung/s5m8767.h>
Sangbeom Kim0f5f7072011-12-23 17:28:08 +090035#include <linux/regmap.h>
36
Geert Uytterhoeven5ac98552013-11-18 14:33:06 +010037static const struct mfd_cell s5m8751_devs[] = {
Sangbeom Kim88a1cfd2012-01-20 16:09:12 +090038 {
39 .name = "s5m8751-pmic",
40 }, {
41 .name = "s5m-charger",
42 }, {
43 .name = "s5m8751-codec",
44 },
45};
46
Geert Uytterhoeven5ac98552013-11-18 14:33:06 +010047static const struct mfd_cell s5m8763_devs[] = {
Sangbeom Kim88a1cfd2012-01-20 16:09:12 +090048 {
49 .name = "s5m8763-pmic",
50 }, {
51 .name = "s5m-rtc",
52 }, {
53 .name = "s5m-charger",
54 },
55};
56
Geert Uytterhoeven5ac98552013-11-18 14:33:06 +010057static const struct mfd_cell s5m8767_devs[] = {
Sangbeom Kim0f5f7072011-12-23 17:28:08 +090058 {
59 .name = "s5m8767-pmic",
60 }, {
61 .name = "s5m-rtc",
Tushar Behera39fed002013-12-26 15:49:00 +053062 }, {
63 .name = "s5m8767-clk",
Krzysztof Kozlowski53c31b32014-03-17 10:19:17 +010064 .of_compatible = "samsung,s5m8767-clk",
Tushar Behera39fed002013-12-26 15:49:00 +053065 }
Sangbeom Kim0f5f7072011-12-23 17:28:08 +090066};
67
Geert Uytterhoeven5ac98552013-11-18 14:33:06 +010068static const struct mfd_cell s2mps11_devs[] = {
Sangbeom Kim9b6d1342012-07-11 21:07:55 +090069 {
70 .name = "s2mps11-pmic",
Yadwinder Singh Brar3134bca2013-07-07 17:14:21 +053071 }, {
Krzysztof Kozlowskieea2e592015-03-17 13:36:17 +010072 .name = "s2mps14-rtc",
73 }, {
Yadwinder Singh Brar3134bca2013-07-07 17:14:21 +053074 .name = "s2mps11-clk",
Krzysztof Kozlowski53c31b32014-03-17 10:19:17 +010075 .of_compatible = "samsung,s2mps11-clk",
Yadwinder Singh Brar3134bca2013-07-07 17:14:21 +053076 }
Sangbeom Kim9b6d1342012-07-11 21:07:55 +090077};
78
Chanwoo Choi3bc2ee92014-11-18 17:59:39 +090079static const struct mfd_cell s2mps13_devs[] = {
80 { .name = "s2mps13-pmic", },
81 { .name = "s2mps13-rtc", },
82 {
83 .name = "s2mps13-clk",
84 .of_compatible = "samsung,s2mps13-clk",
85 },
86};
87
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +010088static const struct mfd_cell s2mps14_devs[] = {
89 {
90 .name = "s2mps14-pmic",
91 }, {
92 .name = "s2mps14-rtc",
93 }, {
94 .name = "s2mps14-clk",
Krzysztof Kozlowski53c31b32014-03-17 10:19:17 +010095 .of_compatible = "samsung,s2mps14-clk",
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +010096 }
97};
98
Sachin Kamatce249912014-03-14 17:21:57 +053099static const struct mfd_cell s2mpa01_devs[] = {
100 {
101 .name = "s2mpa01-pmic",
102 },
103};
104
Chanwoo Choi54e88272014-06-25 16:14:44 +0900105static const struct mfd_cell s2mpu02_devs[] = {
106 { .name = "s2mpu02-pmic", },
107 { .name = "s2mpu02-rtc", },
108 {
109 .name = "s2mpu02-clk",
110 .of_compatible = "samsung,s2mpu02-clk",
111 }
112};
113
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800114#ifdef CONFIG_OF
Krzysztof Kozlowskidf20b7c2014-05-13 12:58:46 +0200115static const struct of_device_id sec_dt_match[] = {
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800116 { .compatible = "samsung,s5m8767-pmic",
117 .data = (void *)S5M8767X,
Sachin Kamatce249912014-03-14 17:21:57 +0530118 }, {
119 .compatible = "samsung,s2mps11-pmic",
Yadwinder Singh Braraa32aca2013-06-29 18:21:20 +0530120 .data = (void *)S2MPS11X,
Sachin Kamatce249912014-03-14 17:21:57 +0530121 }, {
Chanwoo Choi3bc2ee92014-11-18 17:59:39 +0900122 .compatible = "samsung,s2mps13-pmic",
123 .data = (void *)S2MPS13X,
124 }, {
Sachin Kamatce249912014-03-14 17:21:57 +0530125 .compatible = "samsung,s2mps14-pmic",
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +0100126 .data = (void *)S2MPS14X,
Sachin Kamatce249912014-03-14 17:21:57 +0530127 }, {
128 .compatible = "samsung,s2mpa01-pmic",
129 .data = (void *)S2MPA01,
130 }, {
Chanwoo Choi54e88272014-06-25 16:14:44 +0900131 .compatible = "samsung,s2mpu02-pmic",
132 .data = (void *)S2MPU02,
133 }, {
Sachin Kamatce249912014-03-14 17:21:57 +0530134 /* Sentinel */
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +0100135 },
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800136};
137#endif
138
Sachin Kamatce249912014-03-14 17:21:57 +0530139static bool s2mpa01_volatile(struct device *dev, unsigned int reg)
140{
141 switch (reg) {
142 case S2MPA01_REG_INT1M:
143 case S2MPA01_REG_INT2M:
144 case S2MPA01_REG_INT3M:
145 return false;
146 default:
147 return true;
148 }
149}
150
Mark Brown6b845ba2013-07-02 18:51:16 +0100151static bool s2mps11_volatile(struct device *dev, unsigned int reg)
152{
153 switch (reg) {
154 case S2MPS11_REG_INT1M:
155 case S2MPS11_REG_INT2M:
156 case S2MPS11_REG_INT3M:
157 return false;
158 default:
159 return true;
160 }
161}
162
Chanwoo Choi00e25732014-06-25 16:14:45 +0900163static bool s2mpu02_volatile(struct device *dev, unsigned int reg)
164{
165 switch (reg) {
166 case S2MPU02_REG_INT1M:
167 case S2MPU02_REG_INT2M:
168 case S2MPU02_REG_INT3M:
169 return false;
170 default:
171 return true;
172 }
173}
174
Mark Brown6b845ba2013-07-02 18:51:16 +0100175static bool s5m8763_volatile(struct device *dev, unsigned int reg)
176{
177 switch (reg) {
178 case S5M8763_REG_IRQM1:
179 case S5M8763_REG_IRQM2:
180 case S5M8763_REG_IRQM3:
181 case S5M8763_REG_IRQM4:
182 return false;
183 default:
184 return true;
185 }
186}
187
Krzysztof Kozlowskia30fffb2013-11-28 09:09:43 +0100188static const struct regmap_config sec_regmap_config = {
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900189 .reg_bits = 8,
190 .val_bits = 8,
191};
192
Sachin Kamatce249912014-03-14 17:21:57 +0530193static const struct regmap_config s2mpa01_regmap_config = {
194 .reg_bits = 8,
195 .val_bits = 8,
196
197 .max_register = S2MPA01_REG_LDO_OVCB4,
198 .volatile_reg = s2mpa01_volatile,
199 .cache_type = REGCACHE_FLAT,
200};
201
Krzysztof Kozlowskia30fffb2013-11-28 09:09:43 +0100202static const struct regmap_config s2mps11_regmap_config = {
Mark Brown25f311f2013-07-01 23:02:19 +0100203 .reg_bits = 8,
204 .val_bits = 8,
205
206 .max_register = S2MPS11_REG_L38CTRL,
Mark Brown6b845ba2013-07-02 18:51:16 +0100207 .volatile_reg = s2mps11_volatile,
208 .cache_type = REGCACHE_FLAT,
Mark Brown25f311f2013-07-01 23:02:19 +0100209};
210
Chanwoo Choi76b98402014-11-18 17:59:40 +0900211static const struct regmap_config s2mps13_regmap_config = {
212 .reg_bits = 8,
213 .val_bits = 8,
214
215 .max_register = S2MPS13_REG_LDODSCH5,
216 .volatile_reg = s2mps11_volatile,
217 .cache_type = REGCACHE_FLAT,
218};
219
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +0100220static const struct regmap_config s2mps14_regmap_config = {
221 .reg_bits = 8,
222 .val_bits = 8,
223
224 .max_register = S2MPS14_REG_LDODSCH3,
225 .volatile_reg = s2mps11_volatile,
226 .cache_type = REGCACHE_FLAT,
227};
228
Chanwoo Choi00e25732014-06-25 16:14:45 +0900229static const struct regmap_config s2mpu02_regmap_config = {
230 .reg_bits = 8,
231 .val_bits = 8,
232
233 .max_register = S2MPU02_REG_DVSDATA,
234 .volatile_reg = s2mpu02_volatile,
235 .cache_type = REGCACHE_FLAT,
236};
237
Krzysztof Kozlowskia30fffb2013-11-28 09:09:43 +0100238static const struct regmap_config s5m8763_regmap_config = {
Mark Brown25f311f2013-07-01 23:02:19 +0100239 .reg_bits = 8,
240 .val_bits = 8,
241
242 .max_register = S5M8763_REG_LBCNFG2,
Mark Brown6b845ba2013-07-02 18:51:16 +0100243 .volatile_reg = s5m8763_volatile,
244 .cache_type = REGCACHE_FLAT,
Mark Brown25f311f2013-07-01 23:02:19 +0100245};
246
Krzysztof Kozlowskia30fffb2013-11-28 09:09:43 +0100247static const struct regmap_config s5m8767_regmap_config = {
Mark Brown25f311f2013-07-01 23:02:19 +0100248 .reg_bits = 8,
249 .val_bits = 8,
250
251 .max_register = S5M8767_REG_LDO28CTRL,
Mark Brown6b845ba2013-07-02 18:51:16 +0100252 .volatile_reg = s2mps11_volatile,
253 .cache_type = REGCACHE_FLAT,
Mark Brown25f311f2013-07-01 23:02:19 +0100254};
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800255
256#ifdef CONFIG_OF
257/*
258 * Only the common platform data elements for s5m8767 are parsed here from the
259 * device tree. Other sub-modules of s5m8767 such as pmic, rtc , charger and
260 * others have to parse their own platform data elements from device tree.
261 *
262 * The s5m8767 platform data structure is instantiated here and the drivers for
263 * the sub-modules need not instantiate another instance while parsing their
264 * platform data.
265 */
266static struct sec_platform_data *sec_pmic_i2c_parse_dt_pdata(
267 struct device *dev)
268{
269 struct sec_platform_data *pd;
270
271 pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL);
Krzysztof Kozlowski82a00c42015-02-26 10:13:51 +0100272 if (!pd)
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800273 return ERR_PTR(-ENOMEM);
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800274
275 /*
276 * ToDo: the 'wakeup' member in the platform data is more of a linux
277 * specfic information. Hence, there is no binding for that yet and
278 * not parsed here.
279 */
280
281 return pd;
282}
283#else
Mark Brown197bf852013-02-04 18:31:25 +0000284static struct sec_platform_data *sec_pmic_i2c_parse_dt_pdata(
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800285 struct device *dev)
286{
Wei Yongjun005718c2013-12-07 14:02:15 +0800287 return NULL;
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800288}
289#endif
290
Pankaj Dubey8f695de2014-03-13 11:14:07 +0900291static inline unsigned long sec_i2c_get_driver_data(struct i2c_client *i2c,
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800292 const struct i2c_device_id *id)
293{
294#ifdef CONFIG_OF
295 if (i2c->dev.of_node) {
296 const struct of_device_id *match;
Lee Jonesb6c1cb42014-07-21 13:09:25 +0100297
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800298 match = of_match_node(sec_dt_match, i2c->dev.of_node);
Pankaj Dubey8f695de2014-03-13 11:14:07 +0900299 return (unsigned long)match->data;
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800300 }
301#endif
Pankaj Dubey8f695de2014-03-13 11:14:07 +0900302 return id->driver_data;
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800303}
304
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900305static int sec_pmic_probe(struct i2c_client *i2c,
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900306 const struct i2c_device_id *id)
307{
Jingoo Han334a41c2013-07-30 17:10:05 +0900308 struct sec_platform_data *pdata = dev_get_platdata(&i2c->dev);
Krzysztof Kozlowskie349c912014-04-14 09:40:45 +0200309 const struct regmap_config *regmap;
Chanwoo Choi54e88272014-06-25 16:14:44 +0900310 const struct mfd_cell *sec_devs;
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900311 struct sec_pmic_dev *sec_pmic;
Krzysztof Kozlowski9549b5f2014-04-23 16:13:05 +0200312 unsigned long device_type;
Chanwoo Choi54e88272014-06-25 16:14:44 +0900313 int ret, num_sec_devs;
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900314
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900315 sec_pmic = devm_kzalloc(&i2c->dev, sizeof(struct sec_pmic_dev),
Sangbeom Kim621210e2012-01-20 16:09:11 +0900316 GFP_KERNEL);
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900317 if (sec_pmic == NULL)
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900318 return -ENOMEM;
319
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900320 i2c_set_clientdata(i2c, sec_pmic);
321 sec_pmic->dev = &i2c->dev;
322 sec_pmic->i2c = i2c;
323 sec_pmic->irq = i2c->irq;
Krzysztof Kozlowski9549b5f2014-04-23 16:13:05 +0200324 device_type = sec_i2c_get_driver_data(i2c, id);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900325
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800326 if (sec_pmic->dev->of_node) {
327 pdata = sec_pmic_i2c_parse_dt_pdata(sec_pmic->dev);
328 if (IS_ERR(pdata)) {
329 ret = PTR_ERR(pdata);
330 return ret;
331 }
Krzysztof Kozlowski9549b5f2014-04-23 16:13:05 +0200332 pdata->device_type = device_type;
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800333 }
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900334 if (pdata) {
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900335 sec_pmic->device_type = pdata->device_type;
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900336 sec_pmic->irq_base = pdata->irq_base;
337 sec_pmic->wakeup = pdata->wakeup;
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800338 sec_pmic->pdata = pdata;
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900339 }
340
Mark Brown25f311f2013-07-01 23:02:19 +0100341 switch (sec_pmic->device_type) {
Sachin Kamatce249912014-03-14 17:21:57 +0530342 case S2MPA01:
343 regmap = &s2mpa01_regmap_config;
344 break;
Mark Brown25f311f2013-07-01 23:02:19 +0100345 case S2MPS11X:
346 regmap = &s2mps11_regmap_config;
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +0100347 break;
Chanwoo Choi76b98402014-11-18 17:59:40 +0900348 case S2MPS13X:
349 regmap = &s2mps13_regmap_config;
350 break;
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +0100351 case S2MPS14X:
352 regmap = &s2mps14_regmap_config;
Mark Brown25f311f2013-07-01 23:02:19 +0100353 break;
354 case S5M8763X:
355 regmap = &s5m8763_regmap_config;
356 break;
357 case S5M8767X:
358 regmap = &s5m8767_regmap_config;
359 break;
Chanwoo Choi00e25732014-06-25 16:14:45 +0900360 case S2MPU02:
361 regmap = &s2mpu02_regmap_config;
362 break;
Mark Brown25f311f2013-07-01 23:02:19 +0100363 default:
364 regmap = &sec_regmap_config;
365 break;
366 }
367
Krzysztof Kozlowski3e1e4a52013-12-12 17:12:31 -0800368 sec_pmic->regmap_pmic = devm_regmap_init_i2c(i2c, regmap);
369 if (IS_ERR(sec_pmic->regmap_pmic)) {
370 ret = PTR_ERR(sec_pmic->regmap_pmic);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900371 dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
Axel Lin61a2af32012-02-28 14:23:55 +0800372 ret);
Axel Lin1092e1c2012-04-25 10:03:44 +0800373 return ret;
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900374 }
375
Jonghwan Choic3ebb302012-01-16 09:08:42 +0900376 if (pdata && pdata->cfg_pmic_irq)
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900377 pdata->cfg_pmic_irq();
378
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900379 sec_irq_init(sec_pmic);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900380
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900381 pm_runtime_set_active(sec_pmic->dev);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900382
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900383 switch (sec_pmic->device_type) {
Sangbeom Kim88a1cfd2012-01-20 16:09:12 +0900384 case S5M8751X:
Chanwoo Choi54e88272014-06-25 16:14:44 +0900385 sec_devs = s5m8751_devs;
386 num_sec_devs = ARRAY_SIZE(s5m8751_devs);
Sangbeom Kim88a1cfd2012-01-20 16:09:12 +0900387 break;
388 case S5M8763X:
Chanwoo Choi54e88272014-06-25 16:14:44 +0900389 sec_devs = s5m8763_devs;
390 num_sec_devs = ARRAY_SIZE(s5m8763_devs);
Sangbeom Kim88a1cfd2012-01-20 16:09:12 +0900391 break;
392 case S5M8767X:
Chanwoo Choi54e88272014-06-25 16:14:44 +0900393 sec_devs = s5m8767_devs;
394 num_sec_devs = ARRAY_SIZE(s5m8767_devs);
Sangbeom Kim88a1cfd2012-01-20 16:09:12 +0900395 break;
Sachin Kamatce249912014-03-14 17:21:57 +0530396 case S2MPA01:
Chanwoo Choi54e88272014-06-25 16:14:44 +0900397 sec_devs = s2mpa01_devs;
398 num_sec_devs = ARRAY_SIZE(s2mpa01_devs);
Sachin Kamatce249912014-03-14 17:21:57 +0530399 break;
Sangbeom Kim9b6d1342012-07-11 21:07:55 +0900400 case S2MPS11X:
Chanwoo Choi54e88272014-06-25 16:14:44 +0900401 sec_devs = s2mps11_devs;
402 num_sec_devs = ARRAY_SIZE(s2mps11_devs);
Sangbeom Kim9b6d1342012-07-11 21:07:55 +0900403 break;
Chanwoo Choi3bc2ee92014-11-18 17:59:39 +0900404 case S2MPS13X:
405 sec_devs = s2mps13_devs;
406 num_sec_devs = ARRAY_SIZE(s2mps13_devs);
407 break;
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +0100408 case S2MPS14X:
Chanwoo Choi54e88272014-06-25 16:14:44 +0900409 sec_devs = s2mps14_devs;
410 num_sec_devs = ARRAY_SIZE(s2mps14_devs);
411 break;
412 case S2MPU02:
413 sec_devs = s2mpu02_devs;
414 num_sec_devs = ARRAY_SIZE(s2mpu02_devs);
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +0100415 break;
Sangbeom Kim88a1cfd2012-01-20 16:09:12 +0900416 default:
417 /* If this happens the probe function is problem */
418 BUG();
419 }
Chanwoo Choi54e88272014-06-25 16:14:44 +0900420 ret = mfd_add_devices(sec_pmic->dev, -1, sec_devs, num_sec_devs, NULL,
421 0, NULL);
Leon Romanovsky15447a462013-05-15 18:00:48 +0300422 if (ret)
Krzysztof Kozlowski8c66eec2014-03-18 13:57:50 +0100423 goto err_mfd;
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900424
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100425 device_init_wakeup(sec_pmic->dev, sec_pmic->wakeup);
426
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900427 return ret;
428
Krzysztof Kozlowski8c66eec2014-03-18 13:57:50 +0100429err_mfd:
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900430 sec_irq_exit(sec_pmic);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900431 return ret;
432}
433
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900434static int sec_pmic_remove(struct i2c_client *i2c)
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900435{
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900436 struct sec_pmic_dev *sec_pmic = i2c_get_clientdata(i2c);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900437
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900438 mfd_remove_devices(sec_pmic->dev);
439 sec_irq_exit(sec_pmic);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900440 return 0;
441}
442
Geert Uytterhoeven8321bbf2014-01-26 11:38:43 +0100443#ifdef CONFIG_PM_SLEEP
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100444static int sec_pmic_suspend(struct device *dev)
445{
446 struct i2c_client *i2c = container_of(dev, struct i2c_client, dev);
447 struct sec_pmic_dev *sec_pmic = i2c_get_clientdata(i2c);
448
Krzysztof Kozlowski360d15d2014-04-22 16:00:25 +0200449 if (device_may_wakeup(dev))
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100450 enable_irq_wake(sec_pmic->irq);
Krzysztof Kozlowski360d15d2014-04-22 16:00:25 +0200451 /*
452 * PMIC IRQ must be disabled during suspend for RTC alarm
453 * to work properly.
454 * When device is woken up from suspend, an
455 * interrupt occurs before resuming I2C bus controller.
456 * The interrupt is handled by regmap_irq_thread which tries
457 * to read RTC registers. This read fails (I2C is still
458 * suspended) and RTC Alarm interrupt is disabled.
459 */
460 disable_irq(sec_pmic->irq);
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100461
462 return 0;
463}
464
465static int sec_pmic_resume(struct device *dev)
466{
467 struct i2c_client *i2c = container_of(dev, struct i2c_client, dev);
468 struct sec_pmic_dev *sec_pmic = i2c_get_clientdata(i2c);
469
Krzysztof Kozlowski360d15d2014-04-22 16:00:25 +0200470 if (device_may_wakeup(dev))
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100471 disable_irq_wake(sec_pmic->irq);
Krzysztof Kozlowski360d15d2014-04-22 16:00:25 +0200472 enable_irq(sec_pmic->irq);
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100473
474 return 0;
475}
Geert Uytterhoeven8321bbf2014-01-26 11:38:43 +0100476#endif /* CONFIG_PM_SLEEP */
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100477
478static SIMPLE_DEV_PM_OPS(sec_pmic_pm_ops, sec_pmic_suspend, sec_pmic_resume);
479
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900480static const struct i2c_device_id sec_pmic_id[] = {
481 { "sec_pmic", 0 },
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900482 { }
483};
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900484MODULE_DEVICE_TABLE(i2c, sec_pmic_id);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900485
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900486static struct i2c_driver sec_pmic_driver = {
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900487 .driver = {
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900488 .name = "sec_pmic",
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900489 .owner = THIS_MODULE,
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100490 .pm = &sec_pmic_pm_ops,
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800491 .of_match_table = of_match_ptr(sec_dt_match),
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900492 },
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900493 .probe = sec_pmic_probe,
494 .remove = sec_pmic_remove,
495 .id_table = sec_pmic_id,
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900496};
497
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900498static int __init sec_pmic_init(void)
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900499{
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900500 return i2c_add_driver(&sec_pmic_driver);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900501}
502
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900503subsys_initcall(sec_pmic_init);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900504
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900505static void __exit sec_pmic_exit(void)
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900506{
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900507 i2c_del_driver(&sec_pmic_driver);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900508}
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900509module_exit(sec_pmic_exit);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900510
511MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>");
512MODULE_DESCRIPTION("Core support for the S5M MFD");
513MODULE_LICENSE("GPL");