blob: 9613b425730218887807d82b01885586208bc81f [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};
Krzysztof Kozlowskife8166c2018-07-25 17:53:02 +0200149MODULE_DEVICE_TABLE(of, sec_dt_match);
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800150#endif
151
Sachin Kamatce249912014-03-14 17:21:57 +0530152static bool s2mpa01_volatile(struct device *dev, unsigned int reg)
153{
154 switch (reg) {
155 case S2MPA01_REG_INT1M:
156 case S2MPA01_REG_INT2M:
157 case S2MPA01_REG_INT3M:
158 return false;
159 default:
160 return true;
161 }
162}
163
Mark Brown6b845ba2013-07-02 18:51:16 +0100164static bool s2mps11_volatile(struct device *dev, unsigned int reg)
165{
166 switch (reg) {
167 case S2MPS11_REG_INT1M:
168 case S2MPS11_REG_INT2M:
169 case S2MPS11_REG_INT3M:
170 return false;
171 default:
172 return true;
173 }
174}
175
Chanwoo Choi00e25732014-06-25 16:14:45 +0900176static bool s2mpu02_volatile(struct device *dev, unsigned int reg)
177{
178 switch (reg) {
179 case S2MPU02_REG_INT1M:
180 case S2MPU02_REG_INT2M:
181 case S2MPU02_REG_INT3M:
182 return false;
183 default:
184 return true;
185 }
186}
187
Mark Brown6b845ba2013-07-02 18:51:16 +0100188static bool s5m8763_volatile(struct device *dev, unsigned int reg)
189{
190 switch (reg) {
191 case S5M8763_REG_IRQM1:
192 case S5M8763_REG_IRQM2:
193 case S5M8763_REG_IRQM3:
194 case S5M8763_REG_IRQM4:
195 return false;
196 default:
197 return true;
198 }
199}
200
Krzysztof Kozlowskia30fffb2013-11-28 09:09:43 +0100201static const struct regmap_config sec_regmap_config = {
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900202 .reg_bits = 8,
203 .val_bits = 8,
204};
205
Sachin Kamatce249912014-03-14 17:21:57 +0530206static const struct regmap_config s2mpa01_regmap_config = {
207 .reg_bits = 8,
208 .val_bits = 8,
209
210 .max_register = S2MPA01_REG_LDO_OVCB4,
211 .volatile_reg = s2mpa01_volatile,
212 .cache_type = REGCACHE_FLAT,
213};
214
Krzysztof Kozlowskia30fffb2013-11-28 09:09:43 +0100215static const struct regmap_config s2mps11_regmap_config = {
Mark Brown25f311f2013-07-01 23:02:19 +0100216 .reg_bits = 8,
217 .val_bits = 8,
218
219 .max_register = S2MPS11_REG_L38CTRL,
Mark Brown6b845ba2013-07-02 18:51:16 +0100220 .volatile_reg = s2mps11_volatile,
221 .cache_type = REGCACHE_FLAT,
Mark Brown25f311f2013-07-01 23:02:19 +0100222};
223
Chanwoo Choi76b98402014-11-18 17:59:40 +0900224static const struct regmap_config s2mps13_regmap_config = {
225 .reg_bits = 8,
226 .val_bits = 8,
227
228 .max_register = S2MPS13_REG_LDODSCH5,
229 .volatile_reg = s2mps11_volatile,
230 .cache_type = REGCACHE_FLAT,
231};
232
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +0100233static const struct regmap_config s2mps14_regmap_config = {
234 .reg_bits = 8,
235 .val_bits = 8,
236
237 .max_register = S2MPS14_REG_LDODSCH3,
238 .volatile_reg = s2mps11_volatile,
239 .cache_type = REGCACHE_FLAT,
240};
241
Thomas Abraham9e4808d2015-11-20 16:07:51 +0530242static const struct regmap_config s2mps15_regmap_config = {
243 .reg_bits = 8,
244 .val_bits = 8,
245
246 .max_register = S2MPS15_REG_LDODSCH4,
247 .volatile_reg = s2mps11_volatile,
248 .cache_type = REGCACHE_FLAT,
249};
250
Chanwoo Choi00e25732014-06-25 16:14:45 +0900251static const struct regmap_config s2mpu02_regmap_config = {
252 .reg_bits = 8,
253 .val_bits = 8,
254
255 .max_register = S2MPU02_REG_DVSDATA,
256 .volatile_reg = s2mpu02_volatile,
257 .cache_type = REGCACHE_FLAT,
258};
259
Krzysztof Kozlowskia30fffb2013-11-28 09:09:43 +0100260static const struct regmap_config s5m8763_regmap_config = {
Mark Brown25f311f2013-07-01 23:02:19 +0100261 .reg_bits = 8,
262 .val_bits = 8,
263
264 .max_register = S5M8763_REG_LBCNFG2,
Mark Brown6b845ba2013-07-02 18:51:16 +0100265 .volatile_reg = s5m8763_volatile,
266 .cache_type = REGCACHE_FLAT,
Mark Brown25f311f2013-07-01 23:02:19 +0100267};
268
Krzysztof Kozlowskia30fffb2013-11-28 09:09:43 +0100269static const struct regmap_config s5m8767_regmap_config = {
Mark Brown25f311f2013-07-01 23:02:19 +0100270 .reg_bits = 8,
271 .val_bits = 8,
272
273 .max_register = S5M8767_REG_LDO28CTRL,
Mark Brown6b845ba2013-07-02 18:51:16 +0100274 .volatile_reg = s2mps11_volatile,
275 .cache_type = REGCACHE_FLAT,
Mark Brown25f311f2013-07-01 23:02:19 +0100276};
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800277
Krzysztof Kozlowskic2c9f1f2015-10-07 09:44:39 +0900278static void sec_pmic_dump_rev(struct sec_pmic_dev *sec_pmic)
279{
280 unsigned int val;
281
282 /* For each device type, the REG_ID is always the first register */
283 if (!regmap_read(sec_pmic->regmap_pmic, S2MPS11_REG_ID, &val))
284 dev_dbg(sec_pmic->dev, "Revision: 0x%x\n", val);
285}
286
Krzysztof Kozlowski8a97d422015-10-07 09:44:41 +0900287static void sec_pmic_configure(struct sec_pmic_dev *sec_pmic)
288{
289 int err;
290
291 if (sec_pmic->device_type != S2MPS13X)
292 return;
293
294 if (sec_pmic->pdata->disable_wrstbi) {
295 /*
296 * If WRSTBI pin is pulled down this feature must be disabled
297 * because each Suspend to RAM will trigger buck voltage reset
298 * to default values.
299 */
300 err = regmap_update_bits(sec_pmic->regmap_pmic,
301 S2MPS13_REG_WRSTBI,
302 S2MPS13_REG_WRSTBI_MASK, 0x0);
303 if (err)
304 dev_warn(sec_pmic->dev,
305 "Cannot initialize WRSTBI config: %d\n",
306 err);
307 }
308}
309
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800310#ifdef CONFIG_OF
311/*
312 * Only the common platform data elements for s5m8767 are parsed here from the
313 * device tree. Other sub-modules of s5m8767 such as pmic, rtc , charger and
314 * others have to parse their own platform data elements from device tree.
315 *
316 * The s5m8767 platform data structure is instantiated here and the drivers for
317 * the sub-modules need not instantiate another instance while parsing their
318 * platform data.
319 */
320static struct sec_platform_data *sec_pmic_i2c_parse_dt_pdata(
321 struct device *dev)
322{
323 struct sec_platform_data *pd;
324
325 pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL);
Krzysztof Kozlowski82a00c42015-02-26 10:13:51 +0100326 if (!pd)
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800327 return ERR_PTR(-ENOMEM);
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800328
329 /*
330 * ToDo: the 'wakeup' member in the platform data is more of a linux
331 * specfic information. Hence, there is no binding for that yet and
332 * not parsed here.
333 */
334
Krzysztof Kozlowskid7853342015-09-14 21:12:45 +0900335 pd->manual_poweroff = of_property_read_bool(dev->of_node,
336 "samsung,s2mps11-acokb-ground");
Krzysztof Kozlowski8a97d422015-10-07 09:44:41 +0900337 pd->disable_wrstbi = of_property_read_bool(dev->of_node,
338 "samsung,s2mps11-wrstbi-ground");
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800339 return pd;
340}
341#else
Mark Brown197bf852013-02-04 18:31:25 +0000342static struct sec_platform_data *sec_pmic_i2c_parse_dt_pdata(
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800343 struct device *dev)
344{
Wei Yongjun005718c2013-12-07 14:02:15 +0800345 return NULL;
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800346}
347#endif
348
Pankaj Dubey8f695de2014-03-13 11:14:07 +0900349static inline unsigned long sec_i2c_get_driver_data(struct i2c_client *i2c,
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800350 const struct i2c_device_id *id)
351{
352#ifdef CONFIG_OF
353 if (i2c->dev.of_node) {
354 const struct of_device_id *match;
Lee Jonesb6c1cb42014-07-21 13:09:25 +0100355
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800356 match = of_match_node(sec_dt_match, i2c->dev.of_node);
Pankaj Dubey8f695de2014-03-13 11:14:07 +0900357 return (unsigned long)match->data;
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800358 }
359#endif
Pankaj Dubey8f695de2014-03-13 11:14:07 +0900360 return id->driver_data;
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800361}
362
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900363static int sec_pmic_probe(struct i2c_client *i2c,
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900364 const struct i2c_device_id *id)
365{
Jingoo Han334a41c2013-07-30 17:10:05 +0900366 struct sec_platform_data *pdata = dev_get_platdata(&i2c->dev);
Krzysztof Kozlowskie349c912014-04-14 09:40:45 +0200367 const struct regmap_config *regmap;
Chanwoo Choi54e88272014-06-25 16:14:44 +0900368 const struct mfd_cell *sec_devs;
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900369 struct sec_pmic_dev *sec_pmic;
Krzysztof Kozlowski9549b5f2014-04-23 16:13:05 +0200370 unsigned long device_type;
Chanwoo Choi54e88272014-06-25 16:14:44 +0900371 int ret, num_sec_devs;
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900372
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900373 sec_pmic = devm_kzalloc(&i2c->dev, sizeof(struct sec_pmic_dev),
Sangbeom Kim621210e2012-01-20 16:09:11 +0900374 GFP_KERNEL);
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900375 if (sec_pmic == NULL)
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900376 return -ENOMEM;
377
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900378 i2c_set_clientdata(i2c, sec_pmic);
379 sec_pmic->dev = &i2c->dev;
380 sec_pmic->i2c = i2c;
381 sec_pmic->irq = i2c->irq;
Krzysztof Kozlowski9549b5f2014-04-23 16:13:05 +0200382 device_type = sec_i2c_get_driver_data(i2c, id);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900383
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800384 if (sec_pmic->dev->of_node) {
385 pdata = sec_pmic_i2c_parse_dt_pdata(sec_pmic->dev);
386 if (IS_ERR(pdata)) {
387 ret = PTR_ERR(pdata);
388 return ret;
389 }
Krzysztof Kozlowski9549b5f2014-04-23 16:13:05 +0200390 pdata->device_type = device_type;
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800391 }
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900392 if (pdata) {
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900393 sec_pmic->device_type = pdata->device_type;
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900394 sec_pmic->irq_base = pdata->irq_base;
395 sec_pmic->wakeup = pdata->wakeup;
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800396 sec_pmic->pdata = pdata;
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900397 }
398
Mark Brown25f311f2013-07-01 23:02:19 +0100399 switch (sec_pmic->device_type) {
Sachin Kamatce249912014-03-14 17:21:57 +0530400 case S2MPA01:
401 regmap = &s2mpa01_regmap_config;
402 break;
Mark Brown25f311f2013-07-01 23:02:19 +0100403 case S2MPS11X:
404 regmap = &s2mps11_regmap_config;
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +0100405 break;
Chanwoo Choi76b98402014-11-18 17:59:40 +0900406 case S2MPS13X:
407 regmap = &s2mps13_regmap_config;
408 break;
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +0100409 case S2MPS14X:
410 regmap = &s2mps14_regmap_config;
Mark Brown25f311f2013-07-01 23:02:19 +0100411 break;
Thomas Abraham9e4808d2015-11-20 16:07:51 +0530412 case S2MPS15X:
413 regmap = &s2mps15_regmap_config;
414 break;
Mark Brown25f311f2013-07-01 23:02:19 +0100415 case S5M8763X:
416 regmap = &s5m8763_regmap_config;
417 break;
418 case S5M8767X:
419 regmap = &s5m8767_regmap_config;
420 break;
Chanwoo Choi00e25732014-06-25 16:14:45 +0900421 case S2MPU02:
422 regmap = &s2mpu02_regmap_config;
423 break;
Mark Brown25f311f2013-07-01 23:02:19 +0100424 default:
425 regmap = &sec_regmap_config;
426 break;
427 }
428
Krzysztof Kozlowski3e1e4a52013-12-12 17:12:31 -0800429 sec_pmic->regmap_pmic = devm_regmap_init_i2c(i2c, regmap);
430 if (IS_ERR(sec_pmic->regmap_pmic)) {
431 ret = PTR_ERR(sec_pmic->regmap_pmic);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900432 dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
Axel Lin61a2af32012-02-28 14:23:55 +0800433 ret);
Axel Lin1092e1c2012-04-25 10:03:44 +0800434 return ret;
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900435 }
436
Jonghwan Choic3ebb302012-01-16 09:08:42 +0900437 if (pdata && pdata->cfg_pmic_irq)
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900438 pdata->cfg_pmic_irq();
439
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900440 sec_irq_init(sec_pmic);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900441
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900442 pm_runtime_set_active(sec_pmic->dev);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900443
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900444 switch (sec_pmic->device_type) {
Sangbeom Kim88a1cfd2012-01-20 16:09:12 +0900445 case S5M8751X:
Chanwoo Choi54e88272014-06-25 16:14:44 +0900446 sec_devs = s5m8751_devs;
447 num_sec_devs = ARRAY_SIZE(s5m8751_devs);
Sangbeom Kim88a1cfd2012-01-20 16:09:12 +0900448 break;
449 case S5M8763X:
Chanwoo Choi54e88272014-06-25 16:14:44 +0900450 sec_devs = s5m8763_devs;
451 num_sec_devs = ARRAY_SIZE(s5m8763_devs);
Sangbeom Kim88a1cfd2012-01-20 16:09:12 +0900452 break;
453 case S5M8767X:
Chanwoo Choi54e88272014-06-25 16:14:44 +0900454 sec_devs = s5m8767_devs;
455 num_sec_devs = ARRAY_SIZE(s5m8767_devs);
Sangbeom Kim88a1cfd2012-01-20 16:09:12 +0900456 break;
Sachin Kamatce249912014-03-14 17:21:57 +0530457 case S2MPA01:
Chanwoo Choi54e88272014-06-25 16:14:44 +0900458 sec_devs = s2mpa01_devs;
459 num_sec_devs = ARRAY_SIZE(s2mpa01_devs);
Sachin Kamatce249912014-03-14 17:21:57 +0530460 break;
Sangbeom Kim9b6d1342012-07-11 21:07:55 +0900461 case S2MPS11X:
Chanwoo Choi54e88272014-06-25 16:14:44 +0900462 sec_devs = s2mps11_devs;
463 num_sec_devs = ARRAY_SIZE(s2mps11_devs);
Sangbeom Kim9b6d1342012-07-11 21:07:55 +0900464 break;
Chanwoo Choi3bc2ee92014-11-18 17:59:39 +0900465 case S2MPS13X:
466 sec_devs = s2mps13_devs;
467 num_sec_devs = ARRAY_SIZE(s2mps13_devs);
468 break;
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +0100469 case S2MPS14X:
Chanwoo Choi54e88272014-06-25 16:14:44 +0900470 sec_devs = s2mps14_devs;
471 num_sec_devs = ARRAY_SIZE(s2mps14_devs);
472 break;
Thomas Abraham9e4808d2015-11-20 16:07:51 +0530473 case S2MPS15X:
474 sec_devs = s2mps15_devs;
475 num_sec_devs = ARRAY_SIZE(s2mps15_devs);
476 break;
Chanwoo Choi54e88272014-06-25 16:14:44 +0900477 case S2MPU02:
478 sec_devs = s2mpu02_devs;
479 num_sec_devs = ARRAY_SIZE(s2mpu02_devs);
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +0100480 break;
Sangbeom Kim88a1cfd2012-01-20 16:09:12 +0900481 default:
482 /* If this happens the probe function is problem */
483 BUG();
484 }
Laxman Dewangan3dc6f4a2016-04-21 17:55:56 +0530485 ret = devm_mfd_add_devices(sec_pmic->dev, -1, sec_devs, num_sec_devs,
486 NULL, 0, NULL);
Leon Romanovsky15447a462013-05-15 18:00:48 +0300487 if (ret)
Laxman Dewangan3dc6f4a2016-04-21 17:55:56 +0530488 return ret;
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900489
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100490 device_init_wakeup(sec_pmic->dev, sec_pmic->wakeup);
Krzysztof Kozlowski8a97d422015-10-07 09:44:41 +0900491 sec_pmic_configure(sec_pmic);
Krzysztof Kozlowskic2c9f1f2015-10-07 09:44:39 +0900492 sec_pmic_dump_rev(sec_pmic);
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100493
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900494 return ret;
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900495}
496
Krzysztof Kozlowskid7853342015-09-14 21:12:45 +0900497static void sec_pmic_shutdown(struct i2c_client *i2c)
498{
499 struct sec_pmic_dev *sec_pmic = i2c_get_clientdata(i2c);
500 unsigned int reg, mask;
501
502 if (!sec_pmic->pdata->manual_poweroff)
503 return;
504
505 switch (sec_pmic->device_type) {
506 case S2MPS11X:
507 reg = S2MPS11_REG_CTRL1;
508 mask = S2MPS11_CTRL1_PWRHOLD_MASK;
509 break;
510 default:
511 /*
512 * Currently only one board with S2MPS11 needs this, so just
513 * ignore the rest.
514 */
515 dev_warn(sec_pmic->dev,
516 "Unsupported device %lu for manual power off\n",
517 sec_pmic->device_type);
518 return;
519 }
520
521 regmap_update_bits(sec_pmic->regmap_pmic, reg, mask, 0);
522}
523
Geert Uytterhoeven8321bbf2014-01-26 11:38:43 +0100524#ifdef CONFIG_PM_SLEEP
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100525static int sec_pmic_suspend(struct device *dev)
526{
Geliang Tang1b5420e2015-12-28 23:00:14 +0800527 struct i2c_client *i2c = to_i2c_client(dev);
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100528 struct sec_pmic_dev *sec_pmic = i2c_get_clientdata(i2c);
529
Krzysztof Kozlowski360d15d2014-04-22 16:00:25 +0200530 if (device_may_wakeup(dev))
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100531 enable_irq_wake(sec_pmic->irq);
Krzysztof Kozlowski360d15d2014-04-22 16:00:25 +0200532 /*
533 * PMIC IRQ must be disabled during suspend for RTC alarm
534 * to work properly.
535 * When device is woken up from suspend, an
536 * interrupt occurs before resuming I2C bus controller.
537 * The interrupt is handled by regmap_irq_thread which tries
538 * to read RTC registers. This read fails (I2C is still
539 * suspended) and RTC Alarm interrupt is disabled.
540 */
541 disable_irq(sec_pmic->irq);
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100542
543 return 0;
544}
545
546static int sec_pmic_resume(struct device *dev)
547{
Geliang Tang1b5420e2015-12-28 23:00:14 +0800548 struct i2c_client *i2c = to_i2c_client(dev);
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100549 struct sec_pmic_dev *sec_pmic = i2c_get_clientdata(i2c);
550
Krzysztof Kozlowski360d15d2014-04-22 16:00:25 +0200551 if (device_may_wakeup(dev))
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100552 disable_irq_wake(sec_pmic->irq);
Krzysztof Kozlowski360d15d2014-04-22 16:00:25 +0200553 enable_irq(sec_pmic->irq);
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100554
555 return 0;
556}
Geert Uytterhoeven8321bbf2014-01-26 11:38:43 +0100557#endif /* CONFIG_PM_SLEEP */
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100558
559static SIMPLE_DEV_PM_OPS(sec_pmic_pm_ops, sec_pmic_suspend, sec_pmic_resume);
560
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900561static const struct i2c_device_id sec_pmic_id[] = {
562 { "sec_pmic", 0 },
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900563 { }
564};
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900565MODULE_DEVICE_TABLE(i2c, sec_pmic_id);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900566
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900567static struct i2c_driver sec_pmic_driver = {
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900568 .driver = {
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900569 .name = "sec_pmic",
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100570 .pm = &sec_pmic_pm_ops,
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800571 .of_match_table = of_match_ptr(sec_dt_match),
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900572 },
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900573 .probe = sec_pmic_probe,
Krzysztof Kozlowskid7853342015-09-14 21:12:45 +0900574 .shutdown = sec_pmic_shutdown,
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900575 .id_table = sec_pmic_id,
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900576};
577
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900578static int __init sec_pmic_init(void)
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900579{
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900580 return i2c_add_driver(&sec_pmic_driver);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900581}
582
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900583subsys_initcall(sec_pmic_init);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900584
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900585static void __exit sec_pmic_exit(void)
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900586{
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900587 i2c_del_driver(&sec_pmic_driver);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900588}
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900589module_exit(sec_pmic_exit);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900590
591MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>");
592MODULE_DESCRIPTION("Core support for the S5M MFD");
593MODULE_LICENSE("GPL");