blob: dba7e2b6f8e9d949c7c3de18299625448ecd86d8 [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>
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +010030#include <linux/mfd/samsung/s2mps14.h>
Chanwoo Choi00e25732014-06-25 16:14:45 +090031#include <linux/mfd/samsung/s2mpu02.h>
Mark Brown25f311f2013-07-01 23:02:19 +010032#include <linux/mfd/samsung/s5m8763.h>
33#include <linux/mfd/samsung/s5m8767.h>
Chanwoo Choib7cde702014-06-25 16:14:47 +090034#include <linux/regulator/machine.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 }, {
72 .name = "s2mps11-clk",
Krzysztof Kozlowski53c31b32014-03-17 10:19:17 +010073 .of_compatible = "samsung,s2mps11-clk",
Yadwinder Singh Brar3134bca2013-07-07 17:14:21 +053074 }
Sangbeom Kim9b6d1342012-07-11 21:07:55 +090075};
76
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +010077static const struct mfd_cell s2mps14_devs[] = {
78 {
79 .name = "s2mps14-pmic",
80 }, {
81 .name = "s2mps14-rtc",
82 }, {
83 .name = "s2mps14-clk",
Krzysztof Kozlowski53c31b32014-03-17 10:19:17 +010084 .of_compatible = "samsung,s2mps14-clk",
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +010085 }
86};
87
Sachin Kamatce249912014-03-14 17:21:57 +053088static const struct mfd_cell s2mpa01_devs[] = {
89 {
90 .name = "s2mpa01-pmic",
91 },
92};
93
Chanwoo Choi54e88272014-06-25 16:14:44 +090094static const struct mfd_cell s2mpu02_devs[] = {
95 { .name = "s2mpu02-pmic", },
96 { .name = "s2mpu02-rtc", },
97 {
98 .name = "s2mpu02-clk",
99 .of_compatible = "samsung,s2mpu02-clk",
100 }
101};
102
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800103#ifdef CONFIG_OF
Krzysztof Kozlowskidf20b7c2014-05-13 12:58:46 +0200104static const struct of_device_id sec_dt_match[] = {
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800105 { .compatible = "samsung,s5m8767-pmic",
106 .data = (void *)S5M8767X,
Sachin Kamatce249912014-03-14 17:21:57 +0530107 }, {
108 .compatible = "samsung,s2mps11-pmic",
Yadwinder Singh Braraa32aca2013-06-29 18:21:20 +0530109 .data = (void *)S2MPS11X,
Sachin Kamatce249912014-03-14 17:21:57 +0530110 }, {
111 .compatible = "samsung,s2mps14-pmic",
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +0100112 .data = (void *)S2MPS14X,
Sachin Kamatce249912014-03-14 17:21:57 +0530113 }, {
114 .compatible = "samsung,s2mpa01-pmic",
115 .data = (void *)S2MPA01,
116 }, {
Chanwoo Choi54e88272014-06-25 16:14:44 +0900117 .compatible = "samsung,s2mpu02-pmic",
118 .data = (void *)S2MPU02,
119 }, {
Sachin Kamatce249912014-03-14 17:21:57 +0530120 /* Sentinel */
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +0100121 },
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800122};
123#endif
124
Sachin Kamatce249912014-03-14 17:21:57 +0530125static bool s2mpa01_volatile(struct device *dev, unsigned int reg)
126{
127 switch (reg) {
128 case S2MPA01_REG_INT1M:
129 case S2MPA01_REG_INT2M:
130 case S2MPA01_REG_INT3M:
131 return false;
132 default:
133 return true;
134 }
135}
136
Mark Brown6b845ba2013-07-02 18:51:16 +0100137static bool s2mps11_volatile(struct device *dev, unsigned int reg)
138{
139 switch (reg) {
140 case S2MPS11_REG_INT1M:
141 case S2MPS11_REG_INT2M:
142 case S2MPS11_REG_INT3M:
143 return false;
144 default:
145 return true;
146 }
147}
148
Chanwoo Choi00e25732014-06-25 16:14:45 +0900149static bool s2mpu02_volatile(struct device *dev, unsigned int reg)
150{
151 switch (reg) {
152 case S2MPU02_REG_INT1M:
153 case S2MPU02_REG_INT2M:
154 case S2MPU02_REG_INT3M:
155 return false;
156 default:
157 return true;
158 }
159}
160
Mark Brown6b845ba2013-07-02 18:51:16 +0100161static bool s5m8763_volatile(struct device *dev, unsigned int reg)
162{
163 switch (reg) {
164 case S5M8763_REG_IRQM1:
165 case S5M8763_REG_IRQM2:
166 case S5M8763_REG_IRQM3:
167 case S5M8763_REG_IRQM4:
168 return false;
169 default:
170 return true;
171 }
172}
173
Krzysztof Kozlowskia30fffb2013-11-28 09:09:43 +0100174static const struct regmap_config sec_regmap_config = {
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900175 .reg_bits = 8,
176 .val_bits = 8,
177};
178
Sachin Kamatce249912014-03-14 17:21:57 +0530179static const struct regmap_config s2mpa01_regmap_config = {
180 .reg_bits = 8,
181 .val_bits = 8,
182
183 .max_register = S2MPA01_REG_LDO_OVCB4,
184 .volatile_reg = s2mpa01_volatile,
185 .cache_type = REGCACHE_FLAT,
186};
187
Krzysztof Kozlowskia30fffb2013-11-28 09:09:43 +0100188static const struct regmap_config s2mps11_regmap_config = {
Mark Brown25f311f2013-07-01 23:02:19 +0100189 .reg_bits = 8,
190 .val_bits = 8,
191
192 .max_register = S2MPS11_REG_L38CTRL,
Mark Brown6b845ba2013-07-02 18:51:16 +0100193 .volatile_reg = s2mps11_volatile,
194 .cache_type = REGCACHE_FLAT,
Mark Brown25f311f2013-07-01 23:02:19 +0100195};
196
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +0100197static const struct regmap_config s2mps14_regmap_config = {
198 .reg_bits = 8,
199 .val_bits = 8,
200
201 .max_register = S2MPS14_REG_LDODSCH3,
202 .volatile_reg = s2mps11_volatile,
203 .cache_type = REGCACHE_FLAT,
204};
205
Chanwoo Choi00e25732014-06-25 16:14:45 +0900206static const struct regmap_config s2mpu02_regmap_config = {
207 .reg_bits = 8,
208 .val_bits = 8,
209
210 .max_register = S2MPU02_REG_DVSDATA,
211 .volatile_reg = s2mpu02_volatile,
212 .cache_type = REGCACHE_FLAT,
213};
214
Krzysztof Kozlowskia30fffb2013-11-28 09:09:43 +0100215static const struct regmap_config s5m8763_regmap_config = {
Mark Brown25f311f2013-07-01 23:02:19 +0100216 .reg_bits = 8,
217 .val_bits = 8,
218
219 .max_register = S5M8763_REG_LBCNFG2,
Mark Brown6b845ba2013-07-02 18:51:16 +0100220 .volatile_reg = s5m8763_volatile,
221 .cache_type = REGCACHE_FLAT,
Mark Brown25f311f2013-07-01 23:02:19 +0100222};
223
Krzysztof Kozlowskia30fffb2013-11-28 09:09:43 +0100224static const struct regmap_config s5m8767_regmap_config = {
Mark Brown25f311f2013-07-01 23:02:19 +0100225 .reg_bits = 8,
226 .val_bits = 8,
227
228 .max_register = S5M8767_REG_LDO28CTRL,
Mark Brown6b845ba2013-07-02 18:51:16 +0100229 .volatile_reg = s2mps11_volatile,
230 .cache_type = REGCACHE_FLAT,
Mark Brown25f311f2013-07-01 23:02:19 +0100231};
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800232
233#ifdef CONFIG_OF
234/*
235 * Only the common platform data elements for s5m8767 are parsed here from the
236 * device tree. Other sub-modules of s5m8767 such as pmic, rtc , charger and
237 * others have to parse their own platform data elements from device tree.
238 *
239 * The s5m8767 platform data structure is instantiated here and the drivers for
240 * the sub-modules need not instantiate another instance while parsing their
241 * platform data.
242 */
243static struct sec_platform_data *sec_pmic_i2c_parse_dt_pdata(
244 struct device *dev)
245{
246 struct sec_platform_data *pd;
247
248 pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL);
249 if (!pd) {
250 dev_err(dev, "could not allocate memory for pdata\n");
251 return ERR_PTR(-ENOMEM);
252 }
253
254 /*
255 * ToDo: the 'wakeup' member in the platform data is more of a linux
256 * specfic information. Hence, there is no binding for that yet and
257 * not parsed here.
258 */
259
260 return pd;
261}
262#else
Mark Brown197bf852013-02-04 18:31:25 +0000263static struct sec_platform_data *sec_pmic_i2c_parse_dt_pdata(
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800264 struct device *dev)
265{
Wei Yongjun005718c2013-12-07 14:02:15 +0800266 return NULL;
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800267}
268#endif
269
Pankaj Dubey8f695de2014-03-13 11:14:07 +0900270static inline unsigned long sec_i2c_get_driver_data(struct i2c_client *i2c,
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800271 const struct i2c_device_id *id)
272{
273#ifdef CONFIG_OF
274 if (i2c->dev.of_node) {
275 const struct of_device_id *match;
Lee Jonesb6c1cb42014-07-21 13:09:25 +0100276
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800277 match = of_match_node(sec_dt_match, i2c->dev.of_node);
Pankaj Dubey8f695de2014-03-13 11:14:07 +0900278 return (unsigned long)match->data;
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800279 }
280#endif
Pankaj Dubey8f695de2014-03-13 11:14:07 +0900281 return id->driver_data;
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800282}
283
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900284static int sec_pmic_probe(struct i2c_client *i2c,
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900285 const struct i2c_device_id *id)
286{
Jingoo Han334a41c2013-07-30 17:10:05 +0900287 struct sec_platform_data *pdata = dev_get_platdata(&i2c->dev);
Krzysztof Kozlowskie349c912014-04-14 09:40:45 +0200288 const struct regmap_config *regmap;
Chanwoo Choi54e88272014-06-25 16:14:44 +0900289 const struct mfd_cell *sec_devs;
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900290 struct sec_pmic_dev *sec_pmic;
Krzysztof Kozlowski9549b5f2014-04-23 16:13:05 +0200291 unsigned long device_type;
Chanwoo Choi54e88272014-06-25 16:14:44 +0900292 int ret, num_sec_devs;
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900293
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900294 sec_pmic = devm_kzalloc(&i2c->dev, sizeof(struct sec_pmic_dev),
Sangbeom Kim621210e2012-01-20 16:09:11 +0900295 GFP_KERNEL);
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900296 if (sec_pmic == NULL)
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900297 return -ENOMEM;
298
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900299 i2c_set_clientdata(i2c, sec_pmic);
300 sec_pmic->dev = &i2c->dev;
301 sec_pmic->i2c = i2c;
302 sec_pmic->irq = i2c->irq;
Krzysztof Kozlowski9549b5f2014-04-23 16:13:05 +0200303 device_type = sec_i2c_get_driver_data(i2c, id);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900304
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800305 if (sec_pmic->dev->of_node) {
306 pdata = sec_pmic_i2c_parse_dt_pdata(sec_pmic->dev);
307 if (IS_ERR(pdata)) {
308 ret = PTR_ERR(pdata);
309 return ret;
310 }
Krzysztof Kozlowski9549b5f2014-04-23 16:13:05 +0200311 pdata->device_type = device_type;
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800312 }
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900313 if (pdata) {
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900314 sec_pmic->device_type = pdata->device_type;
315 sec_pmic->ono = pdata->ono;
316 sec_pmic->irq_base = pdata->irq_base;
317 sec_pmic->wakeup = pdata->wakeup;
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800318 sec_pmic->pdata = pdata;
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900319 }
320
Mark Brown25f311f2013-07-01 23:02:19 +0100321 switch (sec_pmic->device_type) {
Sachin Kamatce249912014-03-14 17:21:57 +0530322 case S2MPA01:
323 regmap = &s2mpa01_regmap_config;
324 break;
Mark Brown25f311f2013-07-01 23:02:19 +0100325 case S2MPS11X:
326 regmap = &s2mps11_regmap_config;
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +0100327 break;
328 case S2MPS14X:
329 regmap = &s2mps14_regmap_config;
Mark Brown25f311f2013-07-01 23:02:19 +0100330 break;
331 case S5M8763X:
332 regmap = &s5m8763_regmap_config;
333 break;
334 case S5M8767X:
335 regmap = &s5m8767_regmap_config;
336 break;
Chanwoo Choi00e25732014-06-25 16:14:45 +0900337 case S2MPU02:
338 regmap = &s2mpu02_regmap_config;
339 break;
Mark Brown25f311f2013-07-01 23:02:19 +0100340 default:
341 regmap = &sec_regmap_config;
342 break;
343 }
344
Krzysztof Kozlowski3e1e4a52013-12-12 17:12:31 -0800345 sec_pmic->regmap_pmic = devm_regmap_init_i2c(i2c, regmap);
346 if (IS_ERR(sec_pmic->regmap_pmic)) {
347 ret = PTR_ERR(sec_pmic->regmap_pmic);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900348 dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
Axel Lin61a2af32012-02-28 14:23:55 +0800349 ret);
Axel Lin1092e1c2012-04-25 10:03:44 +0800350 return ret;
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900351 }
352
Jonghwan Choic3ebb302012-01-16 09:08:42 +0900353 if (pdata && pdata->cfg_pmic_irq)
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900354 pdata->cfg_pmic_irq();
355
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900356 sec_irq_init(sec_pmic);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900357
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900358 pm_runtime_set_active(sec_pmic->dev);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900359
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900360 switch (sec_pmic->device_type) {
Sangbeom Kim88a1cfd2012-01-20 16:09:12 +0900361 case S5M8751X:
Chanwoo Choi54e88272014-06-25 16:14:44 +0900362 sec_devs = s5m8751_devs;
363 num_sec_devs = ARRAY_SIZE(s5m8751_devs);
Sangbeom Kim88a1cfd2012-01-20 16:09:12 +0900364 break;
365 case S5M8763X:
Chanwoo Choi54e88272014-06-25 16:14:44 +0900366 sec_devs = s5m8763_devs;
367 num_sec_devs = ARRAY_SIZE(s5m8763_devs);
Sangbeom Kim88a1cfd2012-01-20 16:09:12 +0900368 break;
369 case S5M8767X:
Chanwoo Choi54e88272014-06-25 16:14:44 +0900370 sec_devs = s5m8767_devs;
371 num_sec_devs = ARRAY_SIZE(s5m8767_devs);
Sangbeom Kim88a1cfd2012-01-20 16:09:12 +0900372 break;
Sachin Kamatce249912014-03-14 17:21:57 +0530373 case S2MPA01:
Chanwoo Choi54e88272014-06-25 16:14:44 +0900374 sec_devs = s2mpa01_devs;
375 num_sec_devs = ARRAY_SIZE(s2mpa01_devs);
Sachin Kamatce249912014-03-14 17:21:57 +0530376 break;
Sangbeom Kim9b6d1342012-07-11 21:07:55 +0900377 case S2MPS11X:
Chanwoo Choi54e88272014-06-25 16:14:44 +0900378 sec_devs = s2mps11_devs;
379 num_sec_devs = ARRAY_SIZE(s2mps11_devs);
Sangbeom Kim9b6d1342012-07-11 21:07:55 +0900380 break;
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +0100381 case S2MPS14X:
Chanwoo Choi54e88272014-06-25 16:14:44 +0900382 sec_devs = s2mps14_devs;
383 num_sec_devs = ARRAY_SIZE(s2mps14_devs);
384 break;
385 case S2MPU02:
386 sec_devs = s2mpu02_devs;
387 num_sec_devs = ARRAY_SIZE(s2mpu02_devs);
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +0100388 break;
Sangbeom Kim88a1cfd2012-01-20 16:09:12 +0900389 default:
390 /* If this happens the probe function is problem */
391 BUG();
392 }
Chanwoo Choi54e88272014-06-25 16:14:44 +0900393 ret = mfd_add_devices(sec_pmic->dev, -1, sec_devs, num_sec_devs, NULL,
394 0, NULL);
Leon Romanovsky15447a462013-05-15 18:00:48 +0300395 if (ret)
Krzysztof Kozlowski8c66eec2014-03-18 13:57:50 +0100396 goto err_mfd;
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900397
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100398 device_init_wakeup(sec_pmic->dev, sec_pmic->wakeup);
399
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900400 return ret;
401
Krzysztof Kozlowski8c66eec2014-03-18 13:57:50 +0100402err_mfd:
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900403 sec_irq_exit(sec_pmic);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900404 return ret;
405}
406
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900407static int sec_pmic_remove(struct i2c_client *i2c)
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900408{
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900409 struct sec_pmic_dev *sec_pmic = i2c_get_clientdata(i2c);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900410
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900411 mfd_remove_devices(sec_pmic->dev);
412 sec_irq_exit(sec_pmic);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900413 return 0;
414}
415
Geert Uytterhoeven8321bbf2014-01-26 11:38:43 +0100416#ifdef CONFIG_PM_SLEEP
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100417static int sec_pmic_suspend(struct device *dev)
418{
419 struct i2c_client *i2c = container_of(dev, struct i2c_client, dev);
420 struct sec_pmic_dev *sec_pmic = i2c_get_clientdata(i2c);
421
Krzysztof Kozlowski360d15d2014-04-22 16:00:25 +0200422 if (device_may_wakeup(dev))
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100423 enable_irq_wake(sec_pmic->irq);
Krzysztof Kozlowski360d15d2014-04-22 16:00:25 +0200424 /*
425 * PMIC IRQ must be disabled during suspend for RTC alarm
426 * to work properly.
427 * When device is woken up from suspend, an
428 * interrupt occurs before resuming I2C bus controller.
429 * The interrupt is handled by regmap_irq_thread which tries
430 * to read RTC registers. This read fails (I2C is still
431 * suspended) and RTC Alarm interrupt is disabled.
432 */
433 disable_irq(sec_pmic->irq);
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100434
Chanwoo Choib7cde702014-06-25 16:14:47 +0900435 switch (sec_pmic->device_type) {
436 case S2MPS14X:
437 case S2MPU02:
438 regulator_suspend_prepare(PM_SUSPEND_MEM);
439 break;
440 default:
441 break;
442 }
443
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100444 return 0;
445}
446
447static int sec_pmic_resume(struct device *dev)
448{
449 struct i2c_client *i2c = container_of(dev, struct i2c_client, dev);
450 struct sec_pmic_dev *sec_pmic = i2c_get_clientdata(i2c);
451
Krzysztof Kozlowski360d15d2014-04-22 16:00:25 +0200452 if (device_may_wakeup(dev))
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100453 disable_irq_wake(sec_pmic->irq);
Krzysztof Kozlowski360d15d2014-04-22 16:00:25 +0200454 enable_irq(sec_pmic->irq);
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100455
456 return 0;
457}
Geert Uytterhoeven8321bbf2014-01-26 11:38:43 +0100458#endif /* CONFIG_PM_SLEEP */
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100459
460static SIMPLE_DEV_PM_OPS(sec_pmic_pm_ops, sec_pmic_suspend, sec_pmic_resume);
461
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900462static const struct i2c_device_id sec_pmic_id[] = {
463 { "sec_pmic", 0 },
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900464 { }
465};
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900466MODULE_DEVICE_TABLE(i2c, sec_pmic_id);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900467
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900468static struct i2c_driver sec_pmic_driver = {
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900469 .driver = {
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900470 .name = "sec_pmic",
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900471 .owner = THIS_MODULE,
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100472 .pm = &sec_pmic_pm_ops,
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800473 .of_match_table = of_match_ptr(sec_dt_match),
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900474 },
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900475 .probe = sec_pmic_probe,
476 .remove = sec_pmic_remove,
477 .id_table = sec_pmic_id,
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900478};
479
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900480static int __init sec_pmic_init(void)
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900481{
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900482 return i2c_add_driver(&sec_pmic_driver);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900483}
484
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900485subsys_initcall(sec_pmic_init);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900486
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900487static void __exit sec_pmic_exit(void)
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900488{
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900489 i2c_del_driver(&sec_pmic_driver);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900490}
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900491module_exit(sec_pmic_exit);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900492
493MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>");
494MODULE_DESCRIPTION("Core support for the S5M MFD");
495MODULE_LICENSE("GPL");