blob: 95473ff9bb4b5b4162912662f130e40fc48f0c8e [file] [log] [blame]
Krzysztof Kozlowski39b27ad2018-08-07 18:11:22 +02001// SPDX-License-Identifier: GPL-2.0+
2//
3// Copyright (c) 2012 Samsung Electronics Co., Ltd
4// http://www.samsung.com
Sangbeom Kim0f5f7072011-12-23 17:28:08 +09005
6#include <linux/module.h>
7#include <linux/moduleparam.h>
8#include <linux/init.h>
9#include <linux/err.h>
10#include <linux/slab.h>
11#include <linux/i2c.h>
Sachin Kamat1c5a0992013-10-16 14:26:52 +053012#include <linux/of.h>
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -080013#include <linux/of_irq.h>
Sangbeom Kim0f5f7072011-12-23 17:28:08 +090014#include <linux/interrupt.h>
15#include <linux/pm_runtime.h>
16#include <linux/mutex.h>
17#include <linux/mfd/core.h>
Sangbeom Kim54227bc2012-07-11 21:07:16 +090018#include <linux/mfd/samsung/core.h>
19#include <linux/mfd/samsung/irq.h>
Sachin Kamatce249912014-03-14 17:21:57 +053020#include <linux/mfd/samsung/s2mpa01.h>
Mark Brown25f311f2013-07-01 23:02:19 +010021#include <linux/mfd/samsung/s2mps11.h>
Chanwoo Choi76b98402014-11-18 17:59:40 +090022#include <linux/mfd/samsung/s2mps13.h>
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +010023#include <linux/mfd/samsung/s2mps14.h>
Thomas Abraham9e4808d2015-11-20 16:07:51 +053024#include <linux/mfd/samsung/s2mps15.h>
Chanwoo Choi00e25732014-06-25 16:14:45 +090025#include <linux/mfd/samsung/s2mpu02.h>
Mark Brown25f311f2013-07-01 23:02:19 +010026#include <linux/mfd/samsung/s5m8763.h>
27#include <linux/mfd/samsung/s5m8767.h>
Sangbeom Kim0f5f7072011-12-23 17:28:08 +090028#include <linux/regmap.h>
29
Geert Uytterhoeven5ac98552013-11-18 14:33:06 +010030static const struct mfd_cell s5m8751_devs[] = {
Stuart Menefyf01faec2019-02-13 22:24:01 +000031 { .name = "s5m8751-pmic", },
32 { .name = "s5m-charger", },
33 { .name = "s5m8751-codec", },
Sangbeom Kim88a1cfd2012-01-20 16:09:12 +090034};
35
Geert Uytterhoeven5ac98552013-11-18 14:33:06 +010036static const struct mfd_cell s5m8763_devs[] = {
Stuart Menefyf01faec2019-02-13 22:24:01 +000037 { .name = "s5m8763-pmic", },
38 { .name = "s5m-rtc", },
39 { .name = "s5m-charger", },
Sangbeom Kim88a1cfd2012-01-20 16:09:12 +090040};
41
Geert Uytterhoeven5ac98552013-11-18 14:33:06 +010042static const struct mfd_cell s5m8767_devs[] = {
Stuart Menefyf01faec2019-02-13 22:24:01 +000043 { .name = "s5m8767-pmic", },
44 { .name = "s5m-rtc", },
Sangbeom Kim0f5f7072011-12-23 17:28:08 +090045 {
Tushar Behera39fed002013-12-26 15:49:00 +053046 .name = "s5m8767-clk",
Krzysztof Kozlowski53c31b32014-03-17 10:19:17 +010047 .of_compatible = "samsung,s5m8767-clk",
Stuart Menefyf01faec2019-02-13 22:24:01 +000048 },
Sangbeom Kim0f5f7072011-12-23 17:28:08 +090049};
50
Geert Uytterhoeven5ac98552013-11-18 14:33:06 +010051static const struct mfd_cell s2mps11_devs[] = {
Stuart Menefyf01faec2019-02-13 22:24:01 +000052 { .name = "s2mps11-regulator", },
53 { .name = "s2mps14-rtc", },
Sangbeom Kim9b6d1342012-07-11 21:07:55 +090054 {
Yadwinder Singh Brar3134bca2013-07-07 17:14:21 +053055 .name = "s2mps11-clk",
Krzysztof Kozlowski53c31b32014-03-17 10:19:17 +010056 .of_compatible = "samsung,s2mps11-clk",
Stuart Menefyf01faec2019-02-13 22:24:01 +000057 },
Sangbeom Kim9b6d1342012-07-11 21:07:55 +090058};
59
Chanwoo Choi3bc2ee92014-11-18 17:59:39 +090060static const struct mfd_cell s2mps13_devs[] = {
Alim Akhtar2fadbbf2015-11-20 16:18:26 +053061 { .name = "s2mps13-regulator", },
Chanwoo Choi3bc2ee92014-11-18 17:59:39 +090062 { .name = "s2mps13-rtc", },
63 {
64 .name = "s2mps13-clk",
65 .of_compatible = "samsung,s2mps13-clk",
66 },
67};
68
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +010069static const struct mfd_cell s2mps14_devs[] = {
Stuart Menefyf01faec2019-02-13 22:24:01 +000070 { .name = "s2mps14-regulator", },
71 { .name = "s2mps14-rtc", },
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +010072 {
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +010073 .name = "s2mps14-clk",
Krzysztof Kozlowski53c31b32014-03-17 10:19:17 +010074 .of_compatible = "samsung,s2mps14-clk",
Stuart Menefyf01faec2019-02-13 22:24:01 +000075 },
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +010076};
77
Thomas Abraham9e4808d2015-11-20 16:07:51 +053078static const struct mfd_cell s2mps15_devs[] = {
Stuart Menefyf01faec2019-02-13 22:24:01 +000079 { .name = "s2mps15-regulator", },
80 { .name = "s2mps15-rtc", },
Thomas Abraham9e4808d2015-11-20 16:07:51 +053081 {
Thomas Abraham9e4808d2015-11-20 16:07:51 +053082 .name = "s2mps13-clk",
83 .of_compatible = "samsung,s2mps13-clk",
84 },
85};
86
Sachin Kamatce249912014-03-14 17:21:57 +053087static const struct mfd_cell s2mpa01_devs[] = {
Stuart Menefyf01faec2019-02-13 22:24:01 +000088 { .name = "s2mpa01-pmic", },
Stuart Menefyec85d4a2019-02-13 22:24:02 +000089 { .name = "s2mps14-rtc", },
Sachin Kamatce249912014-03-14 17:21:57 +053090};
91
Chanwoo Choi54e88272014-06-25 16:14:44 +090092static const struct mfd_cell s2mpu02_devs[] = {
Stuart Menefyf01faec2019-02-13 22:24:01 +000093 { .name = "s2mpu02-regulator", },
Chanwoo Choi54e88272014-06-25 16:14:44 +090094};
95
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -080096#ifdef CONFIG_OF
Krzysztof Kozlowskidf20b7c2014-05-13 12:58:46 +020097static const struct of_device_id sec_dt_match[] = {
Krzysztof Kozlowski4720eb42019-02-11 14:20:23 +010098 {
99 .compatible = "samsung,s5m8767-pmic",
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800100 .data = (void *)S5M8767X,
Sachin Kamatce249912014-03-14 17:21:57 +0530101 }, {
102 .compatible = "samsung,s2mps11-pmic",
Yadwinder Singh Braraa32aca2013-06-29 18:21:20 +0530103 .data = (void *)S2MPS11X,
Sachin Kamatce249912014-03-14 17:21:57 +0530104 }, {
Chanwoo Choi3bc2ee92014-11-18 17:59:39 +0900105 .compatible = "samsung,s2mps13-pmic",
106 .data = (void *)S2MPS13X,
107 }, {
Sachin Kamatce249912014-03-14 17:21:57 +0530108 .compatible = "samsung,s2mps14-pmic",
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +0100109 .data = (void *)S2MPS14X,
Sachin Kamatce249912014-03-14 17:21:57 +0530110 }, {
Thomas Abraham9e4808d2015-11-20 16:07:51 +0530111 .compatible = "samsung,s2mps15-pmic",
112 .data = (void *)S2MPS15X,
113 }, {
Sachin Kamatce249912014-03-14 17:21:57 +0530114 .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};
Krzysztof Kozlowskife8166c2018-07-25 17:53:02 +0200123MODULE_DEVICE_TABLE(of, sec_dt_match);
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800124#endif
125
Sachin Kamatce249912014-03-14 17:21:57 +0530126static bool s2mpa01_volatile(struct device *dev, unsigned int reg)
127{
128 switch (reg) {
129 case S2MPA01_REG_INT1M:
130 case S2MPA01_REG_INT2M:
131 case S2MPA01_REG_INT3M:
132 return false;
133 default:
134 return true;
135 }
136}
137
Mark Brown6b845ba2013-07-02 18:51:16 +0100138static bool s2mps11_volatile(struct device *dev, unsigned int reg)
139{
140 switch (reg) {
141 case S2MPS11_REG_INT1M:
142 case S2MPS11_REG_INT2M:
143 case S2MPS11_REG_INT3M:
144 return false;
145 default:
146 return true;
147 }
148}
149
Chanwoo Choi00e25732014-06-25 16:14:45 +0900150static bool s2mpu02_volatile(struct device *dev, unsigned int reg)
151{
152 switch (reg) {
153 case S2MPU02_REG_INT1M:
154 case S2MPU02_REG_INT2M:
155 case S2MPU02_REG_INT3M:
156 return false;
157 default:
158 return true;
159 }
160}
161
Mark Brown6b845ba2013-07-02 18:51:16 +0100162static bool s5m8763_volatile(struct device *dev, unsigned int reg)
163{
164 switch (reg) {
165 case S5M8763_REG_IRQM1:
166 case S5M8763_REG_IRQM2:
167 case S5M8763_REG_IRQM3:
168 case S5M8763_REG_IRQM4:
169 return false;
170 default:
171 return true;
172 }
173}
174
Krzysztof Kozlowskia30fffb2013-11-28 09:09:43 +0100175static const struct regmap_config sec_regmap_config = {
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900176 .reg_bits = 8,
177 .val_bits = 8,
178};
179
Sachin Kamatce249912014-03-14 17:21:57 +0530180static const struct regmap_config s2mpa01_regmap_config = {
181 .reg_bits = 8,
182 .val_bits = 8,
183
184 .max_register = S2MPA01_REG_LDO_OVCB4,
185 .volatile_reg = s2mpa01_volatile,
186 .cache_type = REGCACHE_FLAT,
187};
188
Krzysztof Kozlowskia30fffb2013-11-28 09:09:43 +0100189static const struct regmap_config s2mps11_regmap_config = {
Mark Brown25f311f2013-07-01 23:02:19 +0100190 .reg_bits = 8,
191 .val_bits = 8,
192
193 .max_register = S2MPS11_REG_L38CTRL,
Mark Brown6b845ba2013-07-02 18:51:16 +0100194 .volatile_reg = s2mps11_volatile,
195 .cache_type = REGCACHE_FLAT,
Mark Brown25f311f2013-07-01 23:02:19 +0100196};
197
Chanwoo Choi76b98402014-11-18 17:59:40 +0900198static const struct regmap_config s2mps13_regmap_config = {
199 .reg_bits = 8,
200 .val_bits = 8,
201
202 .max_register = S2MPS13_REG_LDODSCH5,
203 .volatile_reg = s2mps11_volatile,
204 .cache_type = REGCACHE_FLAT,
205};
206
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +0100207static const struct regmap_config s2mps14_regmap_config = {
208 .reg_bits = 8,
209 .val_bits = 8,
210
211 .max_register = S2MPS14_REG_LDODSCH3,
212 .volatile_reg = s2mps11_volatile,
213 .cache_type = REGCACHE_FLAT,
214};
215
Thomas Abraham9e4808d2015-11-20 16:07:51 +0530216static const struct regmap_config s2mps15_regmap_config = {
217 .reg_bits = 8,
218 .val_bits = 8,
219
220 .max_register = S2MPS15_REG_LDODSCH4,
221 .volatile_reg = s2mps11_volatile,
222 .cache_type = REGCACHE_FLAT,
223};
224
Chanwoo Choi00e25732014-06-25 16:14:45 +0900225static const struct regmap_config s2mpu02_regmap_config = {
226 .reg_bits = 8,
227 .val_bits = 8,
228
229 .max_register = S2MPU02_REG_DVSDATA,
230 .volatile_reg = s2mpu02_volatile,
231 .cache_type = REGCACHE_FLAT,
232};
233
Krzysztof Kozlowskia30fffb2013-11-28 09:09:43 +0100234static const struct regmap_config s5m8763_regmap_config = {
Mark Brown25f311f2013-07-01 23:02:19 +0100235 .reg_bits = 8,
236 .val_bits = 8,
237
238 .max_register = S5M8763_REG_LBCNFG2,
Mark Brown6b845ba2013-07-02 18:51:16 +0100239 .volatile_reg = s5m8763_volatile,
240 .cache_type = REGCACHE_FLAT,
Mark Brown25f311f2013-07-01 23:02:19 +0100241};
242
Krzysztof Kozlowskia30fffb2013-11-28 09:09:43 +0100243static const struct regmap_config s5m8767_regmap_config = {
Mark Brown25f311f2013-07-01 23:02:19 +0100244 .reg_bits = 8,
245 .val_bits = 8,
246
247 .max_register = S5M8767_REG_LDO28CTRL,
Mark Brown6b845ba2013-07-02 18:51:16 +0100248 .volatile_reg = s2mps11_volatile,
249 .cache_type = REGCACHE_FLAT,
Mark Brown25f311f2013-07-01 23:02:19 +0100250};
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800251
Krzysztof Kozlowskic2c9f1f2015-10-07 09:44:39 +0900252static void sec_pmic_dump_rev(struct sec_pmic_dev *sec_pmic)
253{
254 unsigned int val;
255
256 /* For each device type, the REG_ID is always the first register */
257 if (!regmap_read(sec_pmic->regmap_pmic, S2MPS11_REG_ID, &val))
258 dev_dbg(sec_pmic->dev, "Revision: 0x%x\n", val);
259}
260
Krzysztof Kozlowski8a97d422015-10-07 09:44:41 +0900261static void sec_pmic_configure(struct sec_pmic_dev *sec_pmic)
262{
263 int err;
264
265 if (sec_pmic->device_type != S2MPS13X)
266 return;
267
268 if (sec_pmic->pdata->disable_wrstbi) {
269 /*
270 * If WRSTBI pin is pulled down this feature must be disabled
271 * because each Suspend to RAM will trigger buck voltage reset
272 * to default values.
273 */
274 err = regmap_update_bits(sec_pmic->regmap_pmic,
275 S2MPS13_REG_WRSTBI,
276 S2MPS13_REG_WRSTBI_MASK, 0x0);
277 if (err)
278 dev_warn(sec_pmic->dev,
279 "Cannot initialize WRSTBI config: %d\n",
280 err);
281 }
282}
283
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800284#ifdef CONFIG_OF
285/*
286 * Only the common platform data elements for s5m8767 are parsed here from the
287 * device tree. Other sub-modules of s5m8767 such as pmic, rtc , charger and
288 * others have to parse their own platform data elements from device tree.
289 *
290 * The s5m8767 platform data structure is instantiated here and the drivers for
291 * the sub-modules need not instantiate another instance while parsing their
292 * platform data.
293 */
Krzysztof Kozlowski4720eb42019-02-11 14:20:23 +0100294static struct sec_platform_data *
295sec_pmic_i2c_parse_dt_pdata(struct device *dev)
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800296{
297 struct sec_platform_data *pd;
298
299 pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL);
Krzysztof Kozlowski82a00c42015-02-26 10:13:51 +0100300 if (!pd)
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800301 return ERR_PTR(-ENOMEM);
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800302
303 /*
304 * ToDo: the 'wakeup' member in the platform data is more of a linux
305 * specfic information. Hence, there is no binding for that yet and
306 * not parsed here.
307 */
308
Krzysztof Kozlowskid7853342015-09-14 21:12:45 +0900309 pd->manual_poweroff = of_property_read_bool(dev->of_node,
310 "samsung,s2mps11-acokb-ground");
Krzysztof Kozlowski8a97d422015-10-07 09:44:41 +0900311 pd->disable_wrstbi = of_property_read_bool(dev->of_node,
312 "samsung,s2mps11-wrstbi-ground");
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800313 return pd;
314}
315#else
Krzysztof Kozlowski4720eb42019-02-11 14:20:23 +0100316static struct sec_platform_data *
317sec_pmic_i2c_parse_dt_pdata(struct device *dev)
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800318{
Wei Yongjun005718c2013-12-07 14:02:15 +0800319 return NULL;
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800320}
321#endif
322
Pankaj Dubey8f695de2014-03-13 11:14:07 +0900323static inline unsigned long sec_i2c_get_driver_data(struct i2c_client *i2c,
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800324 const struct i2c_device_id *id)
325{
326#ifdef CONFIG_OF
327 if (i2c->dev.of_node) {
328 const struct of_device_id *match;
Lee Jonesb6c1cb42014-07-21 13:09:25 +0100329
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800330 match = of_match_node(sec_dt_match, i2c->dev.of_node);
Pankaj Dubey8f695de2014-03-13 11:14:07 +0900331 return (unsigned long)match->data;
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800332 }
333#endif
Pankaj Dubey8f695de2014-03-13 11:14:07 +0900334 return id->driver_data;
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800335}
336
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900337static int sec_pmic_probe(struct i2c_client *i2c,
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900338 const struct i2c_device_id *id)
339{
Jingoo Han334a41ce2013-07-30 17:10:05 +0900340 struct sec_platform_data *pdata = dev_get_platdata(&i2c->dev);
Krzysztof Kozlowskie349c912014-04-14 09:40:45 +0200341 const struct regmap_config *regmap;
Chanwoo Choi54e88272014-06-25 16:14:44 +0900342 const struct mfd_cell *sec_devs;
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900343 struct sec_pmic_dev *sec_pmic;
Krzysztof Kozlowski9549b5f2014-04-23 16:13:05 +0200344 unsigned long device_type;
Chanwoo Choi54e88272014-06-25 16:14:44 +0900345 int ret, num_sec_devs;
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900346
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900347 sec_pmic = devm_kzalloc(&i2c->dev, sizeof(struct sec_pmic_dev),
Sangbeom Kim621210e2012-01-20 16:09:11 +0900348 GFP_KERNEL);
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900349 if (sec_pmic == NULL)
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900350 return -ENOMEM;
351
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900352 i2c_set_clientdata(i2c, sec_pmic);
353 sec_pmic->dev = &i2c->dev;
354 sec_pmic->i2c = i2c;
355 sec_pmic->irq = i2c->irq;
Krzysztof Kozlowski9549b5f2014-04-23 16:13:05 +0200356 device_type = sec_i2c_get_driver_data(i2c, id);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900357
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800358 if (sec_pmic->dev->of_node) {
359 pdata = sec_pmic_i2c_parse_dt_pdata(sec_pmic->dev);
360 if (IS_ERR(pdata)) {
361 ret = PTR_ERR(pdata);
362 return ret;
363 }
Krzysztof Kozlowski9549b5f2014-04-23 16:13:05 +0200364 pdata->device_type = device_type;
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800365 }
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900366 if (pdata) {
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900367 sec_pmic->device_type = pdata->device_type;
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900368 sec_pmic->irq_base = pdata->irq_base;
369 sec_pmic->wakeup = pdata->wakeup;
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800370 sec_pmic->pdata = pdata;
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900371 }
372
Mark Brown25f311f2013-07-01 23:02:19 +0100373 switch (sec_pmic->device_type) {
Sachin Kamatce249912014-03-14 17:21:57 +0530374 case S2MPA01:
375 regmap = &s2mpa01_regmap_config;
376 break;
Mark Brown25f311f2013-07-01 23:02:19 +0100377 case S2MPS11X:
378 regmap = &s2mps11_regmap_config;
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +0100379 break;
Chanwoo Choi76b98402014-11-18 17:59:40 +0900380 case S2MPS13X:
381 regmap = &s2mps13_regmap_config;
382 break;
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +0100383 case S2MPS14X:
384 regmap = &s2mps14_regmap_config;
Mark Brown25f311f2013-07-01 23:02:19 +0100385 break;
Thomas Abraham9e4808d2015-11-20 16:07:51 +0530386 case S2MPS15X:
387 regmap = &s2mps15_regmap_config;
388 break;
Mark Brown25f311f2013-07-01 23:02:19 +0100389 case S5M8763X:
390 regmap = &s5m8763_regmap_config;
391 break;
392 case S5M8767X:
393 regmap = &s5m8767_regmap_config;
394 break;
Chanwoo Choi00e25732014-06-25 16:14:45 +0900395 case S2MPU02:
396 regmap = &s2mpu02_regmap_config;
397 break;
Mark Brown25f311f2013-07-01 23:02:19 +0100398 default:
399 regmap = &sec_regmap_config;
400 break;
401 }
402
Krzysztof Kozlowski3e1e4a52013-12-12 17:12:31 -0800403 sec_pmic->regmap_pmic = devm_regmap_init_i2c(i2c, regmap);
404 if (IS_ERR(sec_pmic->regmap_pmic)) {
405 ret = PTR_ERR(sec_pmic->regmap_pmic);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900406 dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
Axel Lin61a2af32012-02-28 14:23:55 +0800407 ret);
Axel Lin1092e1c2012-04-25 10:03:44 +0800408 return ret;
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900409 }
410
Jonghwan Choic3ebb302012-01-16 09:08:42 +0900411 if (pdata && pdata->cfg_pmic_irq)
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900412 pdata->cfg_pmic_irq();
413
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900414 sec_irq_init(sec_pmic);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900415
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900416 pm_runtime_set_active(sec_pmic->dev);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900417
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900418 switch (sec_pmic->device_type) {
Sangbeom Kim88a1cfd2012-01-20 16:09:12 +0900419 case S5M8751X:
Chanwoo Choi54e88272014-06-25 16:14:44 +0900420 sec_devs = s5m8751_devs;
421 num_sec_devs = ARRAY_SIZE(s5m8751_devs);
Sangbeom Kim88a1cfd2012-01-20 16:09:12 +0900422 break;
423 case S5M8763X:
Chanwoo Choi54e88272014-06-25 16:14:44 +0900424 sec_devs = s5m8763_devs;
425 num_sec_devs = ARRAY_SIZE(s5m8763_devs);
Sangbeom Kim88a1cfd2012-01-20 16:09:12 +0900426 break;
427 case S5M8767X:
Chanwoo Choi54e88272014-06-25 16:14:44 +0900428 sec_devs = s5m8767_devs;
429 num_sec_devs = ARRAY_SIZE(s5m8767_devs);
Sangbeom Kim88a1cfd2012-01-20 16:09:12 +0900430 break;
Sachin Kamatce249912014-03-14 17:21:57 +0530431 case S2MPA01:
Chanwoo Choi54e88272014-06-25 16:14:44 +0900432 sec_devs = s2mpa01_devs;
433 num_sec_devs = ARRAY_SIZE(s2mpa01_devs);
Sachin Kamatce249912014-03-14 17:21:57 +0530434 break;
Sangbeom Kim9b6d1342012-07-11 21:07:55 +0900435 case S2MPS11X:
Chanwoo Choi54e88272014-06-25 16:14:44 +0900436 sec_devs = s2mps11_devs;
437 num_sec_devs = ARRAY_SIZE(s2mps11_devs);
Sangbeom Kim9b6d1342012-07-11 21:07:55 +0900438 break;
Chanwoo Choi3bc2ee92014-11-18 17:59:39 +0900439 case S2MPS13X:
440 sec_devs = s2mps13_devs;
441 num_sec_devs = ARRAY_SIZE(s2mps13_devs);
442 break;
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +0100443 case S2MPS14X:
Chanwoo Choi54e88272014-06-25 16:14:44 +0900444 sec_devs = s2mps14_devs;
445 num_sec_devs = ARRAY_SIZE(s2mps14_devs);
446 break;
Thomas Abraham9e4808d2015-11-20 16:07:51 +0530447 case S2MPS15X:
448 sec_devs = s2mps15_devs;
449 num_sec_devs = ARRAY_SIZE(s2mps15_devs);
450 break;
Chanwoo Choi54e88272014-06-25 16:14:44 +0900451 case S2MPU02:
452 sec_devs = s2mpu02_devs;
453 num_sec_devs = ARRAY_SIZE(s2mpu02_devs);
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +0100454 break;
Sangbeom Kim88a1cfd2012-01-20 16:09:12 +0900455 default:
Krzysztof Kozlowski83761f92019-01-29 12:25:53 +0100456 dev_err(&i2c->dev, "Unsupported device type (%lu)\n",
457 sec_pmic->device_type);
458 return -ENODEV;
Sangbeom Kim88a1cfd2012-01-20 16:09:12 +0900459 }
Laxman Dewangan3dc6f4a2016-04-21 17:55:56 +0530460 ret = devm_mfd_add_devices(sec_pmic->dev, -1, sec_devs, num_sec_devs,
461 NULL, 0, NULL);
Leon Romanovsky15447a462013-05-15 18:00:48 +0300462 if (ret)
Laxman Dewangan3dc6f4a2016-04-21 17:55:56 +0530463 return ret;
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900464
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100465 device_init_wakeup(sec_pmic->dev, sec_pmic->wakeup);
Krzysztof Kozlowski8a97d422015-10-07 09:44:41 +0900466 sec_pmic_configure(sec_pmic);
Krzysztof Kozlowskic2c9f1f2015-10-07 09:44:39 +0900467 sec_pmic_dump_rev(sec_pmic);
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100468
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900469 return ret;
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900470}
471
Krzysztof Kozlowskid7853342015-09-14 21:12:45 +0900472static void sec_pmic_shutdown(struct i2c_client *i2c)
473{
474 struct sec_pmic_dev *sec_pmic = i2c_get_clientdata(i2c);
475 unsigned int reg, mask;
476
477 if (!sec_pmic->pdata->manual_poweroff)
478 return;
479
480 switch (sec_pmic->device_type) {
481 case S2MPS11X:
482 reg = S2MPS11_REG_CTRL1;
483 mask = S2MPS11_CTRL1_PWRHOLD_MASK;
484 break;
485 default:
486 /*
487 * Currently only one board with S2MPS11 needs this, so just
488 * ignore the rest.
489 */
490 dev_warn(sec_pmic->dev,
491 "Unsupported device %lu for manual power off\n",
492 sec_pmic->device_type);
493 return;
494 }
495
496 regmap_update_bits(sec_pmic->regmap_pmic, reg, mask, 0);
497}
498
Geert Uytterhoeven8321bbf2014-01-26 11:38:43 +0100499#ifdef CONFIG_PM_SLEEP
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100500static int sec_pmic_suspend(struct device *dev)
501{
Geliang Tang1b5420e2015-12-28 23:00:14 +0800502 struct i2c_client *i2c = to_i2c_client(dev);
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100503 struct sec_pmic_dev *sec_pmic = i2c_get_clientdata(i2c);
504
Krzysztof Kozlowski360d15d2014-04-22 16:00:25 +0200505 if (device_may_wakeup(dev))
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100506 enable_irq_wake(sec_pmic->irq);
Krzysztof Kozlowski360d15d2014-04-22 16:00:25 +0200507 /*
508 * PMIC IRQ must be disabled during suspend for RTC alarm
509 * to work properly.
510 * When device is woken up from suspend, an
511 * interrupt occurs before resuming I2C bus controller.
512 * The interrupt is handled by regmap_irq_thread which tries
513 * to read RTC registers. This read fails (I2C is still
514 * suspended) and RTC Alarm interrupt is disabled.
515 */
516 disable_irq(sec_pmic->irq);
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100517
518 return 0;
519}
520
521static int sec_pmic_resume(struct device *dev)
522{
Geliang Tang1b5420e2015-12-28 23:00:14 +0800523 struct i2c_client *i2c = to_i2c_client(dev);
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100524 struct sec_pmic_dev *sec_pmic = i2c_get_clientdata(i2c);
525
Krzysztof Kozlowski360d15d2014-04-22 16:00:25 +0200526 if (device_may_wakeup(dev))
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100527 disable_irq_wake(sec_pmic->irq);
Krzysztof Kozlowski360d15d2014-04-22 16:00:25 +0200528 enable_irq(sec_pmic->irq);
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100529
530 return 0;
531}
Geert Uytterhoeven8321bbf2014-01-26 11:38:43 +0100532#endif /* CONFIG_PM_SLEEP */
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100533
534static SIMPLE_DEV_PM_OPS(sec_pmic_pm_ops, sec_pmic_suspend, sec_pmic_resume);
535
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900536static const struct i2c_device_id sec_pmic_id[] = {
537 { "sec_pmic", 0 },
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900538 { }
539};
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900540MODULE_DEVICE_TABLE(i2c, sec_pmic_id);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900541
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900542static struct i2c_driver sec_pmic_driver = {
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900543 .driver = {
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900544 .name = "sec_pmic",
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100545 .pm = &sec_pmic_pm_ops,
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800546 .of_match_table = of_match_ptr(sec_dt_match),
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900547 },
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900548 .probe = sec_pmic_probe,
Krzysztof Kozlowskid7853342015-09-14 21:12:45 +0900549 .shutdown = sec_pmic_shutdown,
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900550 .id_table = sec_pmic_id,
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900551};
552
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900553static int __init sec_pmic_init(void)
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900554{
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900555 return i2c_add_driver(&sec_pmic_driver);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900556}
557
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900558subsys_initcall(sec_pmic_init);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900559
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900560static void __exit sec_pmic_exit(void)
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900561{
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900562 i2c_del_driver(&sec_pmic_driver);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900563}
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900564module_exit(sec_pmic_exit);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900565
566MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>");
567MODULE_DESCRIPTION("Core support for the S5M MFD");
568MODULE_LICENSE("GPL");