blob: ca6b80d08ffccbdc0736f4901ef09bc833939f19 [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>
Thomas Abraham9e4808d2015-11-20 16:07:51 +053032#include <linux/mfd/samsung/s2mps15.h>
Chanwoo Choi00e25732014-06-25 16:14:45 +090033#include <linux/mfd/samsung/s2mpu02.h>
Mark Brown25f311f2013-07-01 23:02:19 +010034#include <linux/mfd/samsung/s5m8763.h>
35#include <linux/mfd/samsung/s5m8767.h>
Sangbeom Kim0f5f7072011-12-23 17:28:08 +090036#include <linux/regmap.h>
37
Geert Uytterhoeven5ac98552013-11-18 14:33:06 +010038static const struct mfd_cell s5m8751_devs[] = {
Sangbeom Kim88a1cfd2012-01-20 16:09:12 +090039 {
40 .name = "s5m8751-pmic",
41 }, {
42 .name = "s5m-charger",
43 }, {
44 .name = "s5m8751-codec",
45 },
46};
47
Geert Uytterhoeven5ac98552013-11-18 14:33:06 +010048static const struct mfd_cell s5m8763_devs[] = {
Sangbeom Kim88a1cfd2012-01-20 16:09:12 +090049 {
50 .name = "s5m8763-pmic",
51 }, {
52 .name = "s5m-rtc",
53 }, {
54 .name = "s5m-charger",
55 },
56};
57
Geert Uytterhoeven5ac98552013-11-18 14:33:06 +010058static const struct mfd_cell s5m8767_devs[] = {
Sangbeom Kim0f5f7072011-12-23 17:28:08 +090059 {
60 .name = "s5m8767-pmic",
61 }, {
62 .name = "s5m-rtc",
Tushar Behera39fed002013-12-26 15:49:00 +053063 }, {
64 .name = "s5m8767-clk",
Krzysztof Kozlowski53c31b32014-03-17 10:19:17 +010065 .of_compatible = "samsung,s5m8767-clk",
Tushar Behera39fed002013-12-26 15:49:00 +053066 }
Sangbeom Kim0f5f7072011-12-23 17:28:08 +090067};
68
Geert Uytterhoeven5ac98552013-11-18 14:33:06 +010069static const struct mfd_cell s2mps11_devs[] = {
Sangbeom Kim9b6d1342012-07-11 21:07:55 +090070 {
Alim Akhtar2fadbbf2015-11-20 16:18:26 +053071 .name = "s2mps11-regulator",
Yadwinder Singh Brar3134bca2013-07-07 17:14:21 +053072 }, {
Krzysztof Kozlowskieea2e592015-03-17 13:36:17 +010073 .name = "s2mps14-rtc",
74 }, {
Yadwinder Singh Brar3134bca2013-07-07 17:14:21 +053075 .name = "s2mps11-clk",
Krzysztof Kozlowski53c31b32014-03-17 10:19:17 +010076 .of_compatible = "samsung,s2mps11-clk",
Yadwinder Singh Brar3134bca2013-07-07 17:14:21 +053077 }
Sangbeom Kim9b6d1342012-07-11 21:07:55 +090078};
79
Chanwoo Choi3bc2ee92014-11-18 17:59:39 +090080static const struct mfd_cell s2mps13_devs[] = {
Alim Akhtar2fadbbf2015-11-20 16:18:26 +053081 { .name = "s2mps13-regulator", },
Chanwoo Choi3bc2ee92014-11-18 17:59:39 +090082 { .name = "s2mps13-rtc", },
83 {
84 .name = "s2mps13-clk",
85 .of_compatible = "samsung,s2mps13-clk",
86 },
87};
88
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +010089static const struct mfd_cell s2mps14_devs[] = {
90 {
Alim Akhtar2fadbbf2015-11-20 16:18:26 +053091 .name = "s2mps14-regulator",
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +010092 }, {
93 .name = "s2mps14-rtc",
94 }, {
95 .name = "s2mps14-clk",
Krzysztof Kozlowski53c31b32014-03-17 10:19:17 +010096 .of_compatible = "samsung,s2mps14-clk",
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +010097 }
98};
99
Thomas Abraham9e4808d2015-11-20 16:07:51 +0530100static const struct mfd_cell s2mps15_devs[] = {
101 {
102 .name = "s2mps15-regulator",
103 }, {
104 .name = "s2mps15-rtc",
105 }, {
106 .name = "s2mps13-clk",
107 .of_compatible = "samsung,s2mps13-clk",
108 },
109};
110
Sachin Kamatce249912014-03-14 17:21:57 +0530111static const struct mfd_cell s2mpa01_devs[] = {
112 {
113 .name = "s2mpa01-pmic",
114 },
115};
116
Chanwoo Choi54e88272014-06-25 16:14:44 +0900117static const struct mfd_cell s2mpu02_devs[] = {
Chanwoo Choi54e88272014-06-25 16:14:44 +0900118 {
Alim Akhtar2fadbbf2015-11-20 16:18:26 +0530119 .name = "s2mpu02-regulator",
Krzysztof Kozlowski644a3742015-10-30 16:51:21 +0900120 },
Chanwoo Choi54e88272014-06-25 16:14:44 +0900121};
122
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800123#ifdef CONFIG_OF
Krzysztof Kozlowskidf20b7c2014-05-13 12:58:46 +0200124static const struct of_device_id sec_dt_match[] = {
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800125 { .compatible = "samsung,s5m8767-pmic",
126 .data = (void *)S5M8767X,
Sachin Kamatce249912014-03-14 17:21:57 +0530127 }, {
128 .compatible = "samsung,s2mps11-pmic",
Yadwinder Singh Braraa32aca2013-06-29 18:21:20 +0530129 .data = (void *)S2MPS11X,
Sachin Kamatce249912014-03-14 17:21:57 +0530130 }, {
Chanwoo Choi3bc2ee92014-11-18 17:59:39 +0900131 .compatible = "samsung,s2mps13-pmic",
132 .data = (void *)S2MPS13X,
133 }, {
Sachin Kamatce249912014-03-14 17:21:57 +0530134 .compatible = "samsung,s2mps14-pmic",
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +0100135 .data = (void *)S2MPS14X,
Sachin Kamatce249912014-03-14 17:21:57 +0530136 }, {
Thomas Abraham9e4808d2015-11-20 16:07:51 +0530137 .compatible = "samsung,s2mps15-pmic",
138 .data = (void *)S2MPS15X,
139 }, {
Sachin Kamatce249912014-03-14 17:21:57 +0530140 .compatible = "samsung,s2mpa01-pmic",
141 .data = (void *)S2MPA01,
142 }, {
Chanwoo Choi54e88272014-06-25 16:14:44 +0900143 .compatible = "samsung,s2mpu02-pmic",
144 .data = (void *)S2MPU02,
145 }, {
Sachin Kamatce249912014-03-14 17:21:57 +0530146 /* Sentinel */
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +0100147 },
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800148};
149#endif
150
Sachin Kamatce249912014-03-14 17:21:57 +0530151static bool s2mpa01_volatile(struct device *dev, unsigned int reg)
152{
153 switch (reg) {
154 case S2MPA01_REG_INT1M:
155 case S2MPA01_REG_INT2M:
156 case S2MPA01_REG_INT3M:
157 return false;
158 default:
159 return true;
160 }
161}
162
Mark Brown6b845ba2013-07-02 18:51:16 +0100163static bool s2mps11_volatile(struct device *dev, unsigned int reg)
164{
165 switch (reg) {
166 case S2MPS11_REG_INT1M:
167 case S2MPS11_REG_INT2M:
168 case S2MPS11_REG_INT3M:
169 return false;
170 default:
171 return true;
172 }
173}
174
Chanwoo Choi00e25732014-06-25 16:14:45 +0900175static bool s2mpu02_volatile(struct device *dev, unsigned int reg)
176{
177 switch (reg) {
178 case S2MPU02_REG_INT1M:
179 case S2MPU02_REG_INT2M:
180 case S2MPU02_REG_INT3M:
181 return false;
182 default:
183 return true;
184 }
185}
186
Mark Brown6b845ba2013-07-02 18:51:16 +0100187static bool s5m8763_volatile(struct device *dev, unsigned int reg)
188{
189 switch (reg) {
190 case S5M8763_REG_IRQM1:
191 case S5M8763_REG_IRQM2:
192 case S5M8763_REG_IRQM3:
193 case S5M8763_REG_IRQM4:
194 return false;
195 default:
196 return true;
197 }
198}
199
Krzysztof Kozlowskia30fffb2013-11-28 09:09:43 +0100200static const struct regmap_config sec_regmap_config = {
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900201 .reg_bits = 8,
202 .val_bits = 8,
203};
204
Sachin Kamatce249912014-03-14 17:21:57 +0530205static const struct regmap_config s2mpa01_regmap_config = {
206 .reg_bits = 8,
207 .val_bits = 8,
208
209 .max_register = S2MPA01_REG_LDO_OVCB4,
210 .volatile_reg = s2mpa01_volatile,
211 .cache_type = REGCACHE_FLAT,
212};
213
Krzysztof Kozlowskia30fffb2013-11-28 09:09:43 +0100214static const struct regmap_config s2mps11_regmap_config = {
Mark Brown25f311f2013-07-01 23:02:19 +0100215 .reg_bits = 8,
216 .val_bits = 8,
217
218 .max_register = S2MPS11_REG_L38CTRL,
Mark Brown6b845ba2013-07-02 18:51:16 +0100219 .volatile_reg = s2mps11_volatile,
220 .cache_type = REGCACHE_FLAT,
Mark Brown25f311f2013-07-01 23:02:19 +0100221};
222
Chanwoo Choi76b98402014-11-18 17:59:40 +0900223static const struct regmap_config s2mps13_regmap_config = {
224 .reg_bits = 8,
225 .val_bits = 8,
226
227 .max_register = S2MPS13_REG_LDODSCH5,
228 .volatile_reg = s2mps11_volatile,
229 .cache_type = REGCACHE_FLAT,
230};
231
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +0100232static const struct regmap_config s2mps14_regmap_config = {
233 .reg_bits = 8,
234 .val_bits = 8,
235
236 .max_register = S2MPS14_REG_LDODSCH3,
237 .volatile_reg = s2mps11_volatile,
238 .cache_type = REGCACHE_FLAT,
239};
240
Thomas Abraham9e4808d2015-11-20 16:07:51 +0530241static const struct regmap_config s2mps15_regmap_config = {
242 .reg_bits = 8,
243 .val_bits = 8,
244
245 .max_register = S2MPS15_REG_LDODSCH4,
246 .volatile_reg = s2mps11_volatile,
247 .cache_type = REGCACHE_FLAT,
248};
249
Chanwoo Choi00e25732014-06-25 16:14:45 +0900250static const struct regmap_config s2mpu02_regmap_config = {
251 .reg_bits = 8,
252 .val_bits = 8,
253
254 .max_register = S2MPU02_REG_DVSDATA,
255 .volatile_reg = s2mpu02_volatile,
256 .cache_type = REGCACHE_FLAT,
257};
258
Krzysztof Kozlowskia30fffb2013-11-28 09:09:43 +0100259static const struct regmap_config s5m8763_regmap_config = {
Mark Brown25f311f2013-07-01 23:02:19 +0100260 .reg_bits = 8,
261 .val_bits = 8,
262
263 .max_register = S5M8763_REG_LBCNFG2,
Mark Brown6b845ba2013-07-02 18:51:16 +0100264 .volatile_reg = s5m8763_volatile,
265 .cache_type = REGCACHE_FLAT,
Mark Brown25f311f2013-07-01 23:02:19 +0100266};
267
Krzysztof Kozlowskia30fffb2013-11-28 09:09:43 +0100268static const struct regmap_config s5m8767_regmap_config = {
Mark Brown25f311f2013-07-01 23:02:19 +0100269 .reg_bits = 8,
270 .val_bits = 8,
271
272 .max_register = S5M8767_REG_LDO28CTRL,
Mark Brown6b845ba2013-07-02 18:51:16 +0100273 .volatile_reg = s2mps11_volatile,
274 .cache_type = REGCACHE_FLAT,
Mark Brown25f311f2013-07-01 23:02:19 +0100275};
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800276
Krzysztof Kozlowskic2c9f1f2015-10-07 09:44:39 +0900277static void sec_pmic_dump_rev(struct sec_pmic_dev *sec_pmic)
278{
279 unsigned int val;
280
281 /* For each device type, the REG_ID is always the first register */
282 if (!regmap_read(sec_pmic->regmap_pmic, S2MPS11_REG_ID, &val))
283 dev_dbg(sec_pmic->dev, "Revision: 0x%x\n", val);
284}
285
Krzysztof Kozlowski8a97d422015-10-07 09:44:41 +0900286static void sec_pmic_configure(struct sec_pmic_dev *sec_pmic)
287{
288 int err;
289
290 if (sec_pmic->device_type != S2MPS13X)
291 return;
292
293 if (sec_pmic->pdata->disable_wrstbi) {
294 /*
295 * If WRSTBI pin is pulled down this feature must be disabled
296 * because each Suspend to RAM will trigger buck voltage reset
297 * to default values.
298 */
299 err = regmap_update_bits(sec_pmic->regmap_pmic,
300 S2MPS13_REG_WRSTBI,
301 S2MPS13_REG_WRSTBI_MASK, 0x0);
302 if (err)
303 dev_warn(sec_pmic->dev,
304 "Cannot initialize WRSTBI config: %d\n",
305 err);
306 }
307}
308
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800309#ifdef CONFIG_OF
310/*
311 * Only the common platform data elements for s5m8767 are parsed here from the
312 * device tree. Other sub-modules of s5m8767 such as pmic, rtc , charger and
313 * others have to parse their own platform data elements from device tree.
314 *
315 * The s5m8767 platform data structure is instantiated here and the drivers for
316 * the sub-modules need not instantiate another instance while parsing their
317 * platform data.
318 */
319static struct sec_platform_data *sec_pmic_i2c_parse_dt_pdata(
320 struct device *dev)
321{
322 struct sec_platform_data *pd;
323
324 pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL);
Krzysztof Kozlowski82a00c42015-02-26 10:13:51 +0100325 if (!pd)
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800326 return ERR_PTR(-ENOMEM);
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800327
328 /*
329 * ToDo: the 'wakeup' member in the platform data is more of a linux
330 * specfic information. Hence, there is no binding for that yet and
331 * not parsed here.
332 */
333
Krzysztof Kozlowskid7853342015-09-14 21:12:45 +0900334 pd->manual_poweroff = of_property_read_bool(dev->of_node,
335 "samsung,s2mps11-acokb-ground");
Krzysztof Kozlowski8a97d422015-10-07 09:44:41 +0900336 pd->disable_wrstbi = of_property_read_bool(dev->of_node,
337 "samsung,s2mps11-wrstbi-ground");
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800338 return pd;
339}
340#else
Mark Brown197bf852013-02-04 18:31:25 +0000341static struct sec_platform_data *sec_pmic_i2c_parse_dt_pdata(
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800342 struct device *dev)
343{
Wei Yongjun005718c2013-12-07 14:02:15 +0800344 return NULL;
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800345}
346#endif
347
Pankaj Dubey8f695de2014-03-13 11:14:07 +0900348static inline unsigned long sec_i2c_get_driver_data(struct i2c_client *i2c,
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800349 const struct i2c_device_id *id)
350{
351#ifdef CONFIG_OF
352 if (i2c->dev.of_node) {
353 const struct of_device_id *match;
Lee Jonesb6c1cb42014-07-21 13:09:25 +0100354
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800355 match = of_match_node(sec_dt_match, i2c->dev.of_node);
Pankaj Dubey8f695de2014-03-13 11:14:07 +0900356 return (unsigned long)match->data;
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800357 }
358#endif
Pankaj Dubey8f695de2014-03-13 11:14:07 +0900359 return id->driver_data;
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800360}
361
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900362static int sec_pmic_probe(struct i2c_client *i2c,
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900363 const struct i2c_device_id *id)
364{
Jingoo Han334a41c2013-07-30 17:10:05 +0900365 struct sec_platform_data *pdata = dev_get_platdata(&i2c->dev);
Krzysztof Kozlowskie349c912014-04-14 09:40:45 +0200366 const struct regmap_config *regmap;
Chanwoo Choi54e88272014-06-25 16:14:44 +0900367 const struct mfd_cell *sec_devs;
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900368 struct sec_pmic_dev *sec_pmic;
Krzysztof Kozlowski9549b5f2014-04-23 16:13:05 +0200369 unsigned long device_type;
Chanwoo Choi54e88272014-06-25 16:14:44 +0900370 int ret, num_sec_devs;
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900371
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900372 sec_pmic = devm_kzalloc(&i2c->dev, sizeof(struct sec_pmic_dev),
Sangbeom Kim621210e2012-01-20 16:09:11 +0900373 GFP_KERNEL);
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900374 if (sec_pmic == NULL)
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900375 return -ENOMEM;
376
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900377 i2c_set_clientdata(i2c, sec_pmic);
378 sec_pmic->dev = &i2c->dev;
379 sec_pmic->i2c = i2c;
380 sec_pmic->irq = i2c->irq;
Krzysztof Kozlowski9549b5f2014-04-23 16:13:05 +0200381 device_type = sec_i2c_get_driver_data(i2c, id);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900382
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800383 if (sec_pmic->dev->of_node) {
384 pdata = sec_pmic_i2c_parse_dt_pdata(sec_pmic->dev);
385 if (IS_ERR(pdata)) {
386 ret = PTR_ERR(pdata);
387 return ret;
388 }
Krzysztof Kozlowski9549b5f2014-04-23 16:13:05 +0200389 pdata->device_type = device_type;
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800390 }
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900391 if (pdata) {
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900392 sec_pmic->device_type = pdata->device_type;
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900393 sec_pmic->irq_base = pdata->irq_base;
394 sec_pmic->wakeup = pdata->wakeup;
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800395 sec_pmic->pdata = pdata;
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900396 }
397
Mark Brown25f311f2013-07-01 23:02:19 +0100398 switch (sec_pmic->device_type) {
Sachin Kamatce249912014-03-14 17:21:57 +0530399 case S2MPA01:
400 regmap = &s2mpa01_regmap_config;
401 break;
Mark Brown25f311f2013-07-01 23:02:19 +0100402 case S2MPS11X:
403 regmap = &s2mps11_regmap_config;
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +0100404 break;
Chanwoo Choi76b98402014-11-18 17:59:40 +0900405 case S2MPS13X:
406 regmap = &s2mps13_regmap_config;
407 break;
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +0100408 case S2MPS14X:
409 regmap = &s2mps14_regmap_config;
Mark Brown25f311f2013-07-01 23:02:19 +0100410 break;
Thomas Abraham9e4808d2015-11-20 16:07:51 +0530411 case S2MPS15X:
412 regmap = &s2mps15_regmap_config;
413 break;
Mark Brown25f311f2013-07-01 23:02:19 +0100414 case S5M8763X:
415 regmap = &s5m8763_regmap_config;
416 break;
417 case S5M8767X:
418 regmap = &s5m8767_regmap_config;
419 break;
Chanwoo Choi00e25732014-06-25 16:14:45 +0900420 case S2MPU02:
421 regmap = &s2mpu02_regmap_config;
422 break;
Mark Brown25f311f2013-07-01 23:02:19 +0100423 default:
424 regmap = &sec_regmap_config;
425 break;
426 }
427
Krzysztof Kozlowski3e1e4a52013-12-12 17:12:31 -0800428 sec_pmic->regmap_pmic = devm_regmap_init_i2c(i2c, regmap);
429 if (IS_ERR(sec_pmic->regmap_pmic)) {
430 ret = PTR_ERR(sec_pmic->regmap_pmic);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900431 dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
Axel Lin61a2af32012-02-28 14:23:55 +0800432 ret);
Axel Lin1092e1c2012-04-25 10:03:44 +0800433 return ret;
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900434 }
435
Jonghwan Choic3ebb302012-01-16 09:08:42 +0900436 if (pdata && pdata->cfg_pmic_irq)
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900437 pdata->cfg_pmic_irq();
438
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900439 sec_irq_init(sec_pmic);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900440
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900441 pm_runtime_set_active(sec_pmic->dev);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900442
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900443 switch (sec_pmic->device_type) {
Sangbeom Kim88a1cfd2012-01-20 16:09:12 +0900444 case S5M8751X:
Chanwoo Choi54e88272014-06-25 16:14:44 +0900445 sec_devs = s5m8751_devs;
446 num_sec_devs = ARRAY_SIZE(s5m8751_devs);
Sangbeom Kim88a1cfd2012-01-20 16:09:12 +0900447 break;
448 case S5M8763X:
Chanwoo Choi54e88272014-06-25 16:14:44 +0900449 sec_devs = s5m8763_devs;
450 num_sec_devs = ARRAY_SIZE(s5m8763_devs);
Sangbeom Kim88a1cfd2012-01-20 16:09:12 +0900451 break;
452 case S5M8767X:
Chanwoo Choi54e88272014-06-25 16:14:44 +0900453 sec_devs = s5m8767_devs;
454 num_sec_devs = ARRAY_SIZE(s5m8767_devs);
Sangbeom Kim88a1cfd2012-01-20 16:09:12 +0900455 break;
Sachin Kamatce249912014-03-14 17:21:57 +0530456 case S2MPA01:
Chanwoo Choi54e88272014-06-25 16:14:44 +0900457 sec_devs = s2mpa01_devs;
458 num_sec_devs = ARRAY_SIZE(s2mpa01_devs);
Sachin Kamatce249912014-03-14 17:21:57 +0530459 break;
Sangbeom Kim9b6d1342012-07-11 21:07:55 +0900460 case S2MPS11X:
Chanwoo Choi54e88272014-06-25 16:14:44 +0900461 sec_devs = s2mps11_devs;
462 num_sec_devs = ARRAY_SIZE(s2mps11_devs);
Sangbeom Kim9b6d1342012-07-11 21:07:55 +0900463 break;
Chanwoo Choi3bc2ee92014-11-18 17:59:39 +0900464 case S2MPS13X:
465 sec_devs = s2mps13_devs;
466 num_sec_devs = ARRAY_SIZE(s2mps13_devs);
467 break;
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +0100468 case S2MPS14X:
Chanwoo Choi54e88272014-06-25 16:14:44 +0900469 sec_devs = s2mps14_devs;
470 num_sec_devs = ARRAY_SIZE(s2mps14_devs);
471 break;
Thomas Abraham9e4808d2015-11-20 16:07:51 +0530472 case S2MPS15X:
473 sec_devs = s2mps15_devs;
474 num_sec_devs = ARRAY_SIZE(s2mps15_devs);
475 break;
Chanwoo Choi54e88272014-06-25 16:14:44 +0900476 case S2MPU02:
477 sec_devs = s2mpu02_devs;
478 num_sec_devs = ARRAY_SIZE(s2mpu02_devs);
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +0100479 break;
Sangbeom Kim88a1cfd2012-01-20 16:09:12 +0900480 default:
481 /* If this happens the probe function is problem */
482 BUG();
483 }
Laxman Dewangan3dc6f4a2016-04-21 17:55:56 +0530484 ret = devm_mfd_add_devices(sec_pmic->dev, -1, sec_devs, num_sec_devs,
485 NULL, 0, NULL);
Leon Romanovsky15447a462013-05-15 18:00:48 +0300486 if (ret)
Laxman Dewangan3dc6f4a2016-04-21 17:55:56 +0530487 return ret;
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900488
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100489 device_init_wakeup(sec_pmic->dev, sec_pmic->wakeup);
Krzysztof Kozlowski8a97d422015-10-07 09:44:41 +0900490 sec_pmic_configure(sec_pmic);
Krzysztof Kozlowskic2c9f1f2015-10-07 09:44:39 +0900491 sec_pmic_dump_rev(sec_pmic);
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100492
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900493 return ret;
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900494}
495
Krzysztof Kozlowskid7853342015-09-14 21:12:45 +0900496static void sec_pmic_shutdown(struct i2c_client *i2c)
497{
498 struct sec_pmic_dev *sec_pmic = i2c_get_clientdata(i2c);
499 unsigned int reg, mask;
500
501 if (!sec_pmic->pdata->manual_poweroff)
502 return;
503
504 switch (sec_pmic->device_type) {
505 case S2MPS11X:
506 reg = S2MPS11_REG_CTRL1;
507 mask = S2MPS11_CTRL1_PWRHOLD_MASK;
508 break;
509 default:
510 /*
511 * Currently only one board with S2MPS11 needs this, so just
512 * ignore the rest.
513 */
514 dev_warn(sec_pmic->dev,
515 "Unsupported device %lu for manual power off\n",
516 sec_pmic->device_type);
517 return;
518 }
519
520 regmap_update_bits(sec_pmic->regmap_pmic, reg, mask, 0);
521}
522
Geert Uytterhoeven8321bbf2014-01-26 11:38:43 +0100523#ifdef CONFIG_PM_SLEEP
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100524static int sec_pmic_suspend(struct device *dev)
525{
Geliang Tang1b5420e2015-12-28 23:00:14 +0800526 struct i2c_client *i2c = to_i2c_client(dev);
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100527 struct sec_pmic_dev *sec_pmic = i2c_get_clientdata(i2c);
528
Krzysztof Kozlowski360d15d2014-04-22 16:00:25 +0200529 if (device_may_wakeup(dev))
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100530 enable_irq_wake(sec_pmic->irq);
Krzysztof Kozlowski360d15d2014-04-22 16:00:25 +0200531 /*
532 * PMIC IRQ must be disabled during suspend for RTC alarm
533 * to work properly.
534 * When device is woken up from suspend, an
535 * interrupt occurs before resuming I2C bus controller.
536 * The interrupt is handled by regmap_irq_thread which tries
537 * to read RTC registers. This read fails (I2C is still
538 * suspended) and RTC Alarm interrupt is disabled.
539 */
540 disable_irq(sec_pmic->irq);
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100541
542 return 0;
543}
544
545static int sec_pmic_resume(struct device *dev)
546{
Geliang Tang1b5420e2015-12-28 23:00:14 +0800547 struct i2c_client *i2c = to_i2c_client(dev);
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100548 struct sec_pmic_dev *sec_pmic = i2c_get_clientdata(i2c);
549
Krzysztof Kozlowski360d15d2014-04-22 16:00:25 +0200550 if (device_may_wakeup(dev))
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100551 disable_irq_wake(sec_pmic->irq);
Krzysztof Kozlowski360d15d2014-04-22 16:00:25 +0200552 enable_irq(sec_pmic->irq);
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100553
554 return 0;
555}
Geert Uytterhoeven8321bbf2014-01-26 11:38:43 +0100556#endif /* CONFIG_PM_SLEEP */
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100557
558static SIMPLE_DEV_PM_OPS(sec_pmic_pm_ops, sec_pmic_suspend, sec_pmic_resume);
559
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900560static const struct i2c_device_id sec_pmic_id[] = {
561 { "sec_pmic", 0 },
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900562 { }
563};
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900564MODULE_DEVICE_TABLE(i2c, sec_pmic_id);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900565
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900566static struct i2c_driver sec_pmic_driver = {
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900567 .driver = {
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900568 .name = "sec_pmic",
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100569 .pm = &sec_pmic_pm_ops,
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800570 .of_match_table = of_match_ptr(sec_dt_match),
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900571 },
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900572 .probe = sec_pmic_probe,
Krzysztof Kozlowskid7853342015-09-14 21:12:45 +0900573 .shutdown = sec_pmic_shutdown,
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900574 .id_table = sec_pmic_id,
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900575};
576
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900577static int __init sec_pmic_init(void)
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900578{
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900579 return i2c_add_driver(&sec_pmic_driver);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900580}
581
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900582subsys_initcall(sec_pmic_init);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900583
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900584static void __exit sec_pmic_exit(void)
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900585{
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900586 i2c_del_driver(&sec_pmic_driver);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900587}
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900588module_exit(sec_pmic_exit);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900589
590MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>");
591MODULE_DESCRIPTION("Core support for the S5M MFD");
592MODULE_LICENSE("GPL");