blob: 91405e94cfee2f8badf44a792a0c80293547426d [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>
28#include <linux/mfd/samsung/rtc.h>
Sachin Kamatce249912014-03-14 17:21:57 +053029#include <linux/mfd/samsung/s2mpa01.h>
Mark Brown25f311f2013-07-01 23:02:19 +010030#include <linux/mfd/samsung/s2mps11.h>
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +010031#include <linux/mfd/samsung/s2mps14.h>
Mark Brown25f311f2013-07-01 23:02:19 +010032#include <linux/mfd/samsung/s5m8763.h>
33#include <linux/mfd/samsung/s5m8767.h>
Sangbeom Kim0f5f7072011-12-23 17:28:08 +090034#include <linux/regmap.h>
35
Geert Uytterhoeven5ac98552013-11-18 14:33:06 +010036static const struct mfd_cell s5m8751_devs[] = {
Sangbeom Kim88a1cfd2012-01-20 16:09:12 +090037 {
38 .name = "s5m8751-pmic",
39 }, {
40 .name = "s5m-charger",
41 }, {
42 .name = "s5m8751-codec",
43 },
44};
45
Geert Uytterhoeven5ac98552013-11-18 14:33:06 +010046static const struct mfd_cell s5m8763_devs[] = {
Sangbeom Kim88a1cfd2012-01-20 16:09:12 +090047 {
48 .name = "s5m8763-pmic",
49 }, {
50 .name = "s5m-rtc",
51 }, {
52 .name = "s5m-charger",
53 },
54};
55
Geert Uytterhoeven5ac98552013-11-18 14:33:06 +010056static const struct mfd_cell s5m8767_devs[] = {
Sangbeom Kim0f5f7072011-12-23 17:28:08 +090057 {
58 .name = "s5m8767-pmic",
59 }, {
60 .name = "s5m-rtc",
Tushar Behera39fed002013-12-26 15:49:00 +053061 }, {
62 .name = "s5m8767-clk",
Krzysztof Kozlowski53c31b32014-03-17 10:19:17 +010063 .of_compatible = "samsung,s5m8767-clk",
Tushar Behera39fed002013-12-26 15:49:00 +053064 }
Sangbeom Kim0f5f7072011-12-23 17:28:08 +090065};
66
Geert Uytterhoeven5ac98552013-11-18 14:33:06 +010067static const struct mfd_cell s2mps11_devs[] = {
Sangbeom Kim9b6d1342012-07-11 21:07:55 +090068 {
69 .name = "s2mps11-pmic",
Yadwinder Singh Brar3134bca2013-07-07 17:14:21 +053070 }, {
71 .name = "s2mps11-clk",
Krzysztof Kozlowski53c31b32014-03-17 10:19:17 +010072 .of_compatible = "samsung,s2mps11-clk",
Yadwinder Singh Brar3134bca2013-07-07 17:14:21 +053073 }
Sangbeom Kim9b6d1342012-07-11 21:07:55 +090074};
75
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +010076static const struct mfd_cell s2mps14_devs[] = {
77 {
78 .name = "s2mps14-pmic",
79 }, {
80 .name = "s2mps14-rtc",
81 }, {
82 .name = "s2mps14-clk",
Krzysztof Kozlowski53c31b32014-03-17 10:19:17 +010083 .of_compatible = "samsung,s2mps14-clk",
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +010084 }
85};
86
Sachin Kamatce249912014-03-14 17:21:57 +053087static const struct mfd_cell s2mpa01_devs[] = {
88 {
89 .name = "s2mpa01-pmic",
90 },
91};
92
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -080093#ifdef CONFIG_OF
94static struct of_device_id sec_dt_match[] = {
95 { .compatible = "samsung,s5m8767-pmic",
96 .data = (void *)S5M8767X,
Sachin Kamatce249912014-03-14 17:21:57 +053097 }, {
98 .compatible = "samsung,s2mps11-pmic",
Yadwinder Singh Braraa32aca2013-06-29 18:21:20 +053099 .data = (void *)S2MPS11X,
Sachin Kamatce249912014-03-14 17:21:57 +0530100 }, {
101 .compatible = "samsung,s2mps14-pmic",
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +0100102 .data = (void *)S2MPS14X,
Sachin Kamatce249912014-03-14 17:21:57 +0530103 }, {
104 .compatible = "samsung,s2mpa01-pmic",
105 .data = (void *)S2MPA01,
106 }, {
107 /* Sentinel */
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +0100108 },
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800109};
110#endif
111
Sachin Kamatce249912014-03-14 17:21:57 +0530112static bool s2mpa01_volatile(struct device *dev, unsigned int reg)
113{
114 switch (reg) {
115 case S2MPA01_REG_INT1M:
116 case S2MPA01_REG_INT2M:
117 case S2MPA01_REG_INT3M:
118 return false;
119 default:
120 return true;
121 }
122}
123
Mark Brown6b845ba2013-07-02 18:51:16 +0100124static bool s2mps11_volatile(struct device *dev, unsigned int reg)
125{
126 switch (reg) {
127 case S2MPS11_REG_INT1M:
128 case S2MPS11_REG_INT2M:
129 case S2MPS11_REG_INT3M:
130 return false;
131 default:
132 return true;
133 }
134}
135
136static bool s5m8763_volatile(struct device *dev, unsigned int reg)
137{
138 switch (reg) {
139 case S5M8763_REG_IRQM1:
140 case S5M8763_REG_IRQM2:
141 case S5M8763_REG_IRQM3:
142 case S5M8763_REG_IRQM4:
143 return false;
144 default:
145 return true;
146 }
147}
148
Krzysztof Kozlowskia30fffb2013-11-28 09:09:43 +0100149static const struct regmap_config sec_regmap_config = {
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900150 .reg_bits = 8,
151 .val_bits = 8,
152};
153
Sachin Kamatce249912014-03-14 17:21:57 +0530154static const struct regmap_config s2mpa01_regmap_config = {
155 .reg_bits = 8,
156 .val_bits = 8,
157
158 .max_register = S2MPA01_REG_LDO_OVCB4,
159 .volatile_reg = s2mpa01_volatile,
160 .cache_type = REGCACHE_FLAT,
161};
162
Krzysztof Kozlowskia30fffb2013-11-28 09:09:43 +0100163static const struct regmap_config s2mps11_regmap_config = {
Mark Brown25f311f2013-07-01 23:02:19 +0100164 .reg_bits = 8,
165 .val_bits = 8,
166
167 .max_register = S2MPS11_REG_L38CTRL,
Mark Brown6b845ba2013-07-02 18:51:16 +0100168 .volatile_reg = s2mps11_volatile,
169 .cache_type = REGCACHE_FLAT,
Mark Brown25f311f2013-07-01 23:02:19 +0100170};
171
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +0100172static const struct regmap_config s2mps14_regmap_config = {
173 .reg_bits = 8,
174 .val_bits = 8,
175
176 .max_register = S2MPS14_REG_LDODSCH3,
177 .volatile_reg = s2mps11_volatile,
178 .cache_type = REGCACHE_FLAT,
179};
180
Krzysztof Kozlowskia30fffb2013-11-28 09:09:43 +0100181static const struct regmap_config s5m8763_regmap_config = {
Mark Brown25f311f2013-07-01 23:02:19 +0100182 .reg_bits = 8,
183 .val_bits = 8,
184
185 .max_register = S5M8763_REG_LBCNFG2,
Mark Brown6b845ba2013-07-02 18:51:16 +0100186 .volatile_reg = s5m8763_volatile,
187 .cache_type = REGCACHE_FLAT,
Mark Brown25f311f2013-07-01 23:02:19 +0100188};
189
Krzysztof Kozlowskia30fffb2013-11-28 09:09:43 +0100190static const struct regmap_config s5m8767_regmap_config = {
Mark Brown25f311f2013-07-01 23:02:19 +0100191 .reg_bits = 8,
192 .val_bits = 8,
193
194 .max_register = S5M8767_REG_LDO28CTRL,
Mark Brown6b845ba2013-07-02 18:51:16 +0100195 .volatile_reg = s2mps11_volatile,
196 .cache_type = REGCACHE_FLAT,
Mark Brown25f311f2013-07-01 23:02:19 +0100197};
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800198
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +0100199static const struct regmap_config s5m_rtc_regmap_config = {
Krzysztof Kozlowski3e1e4a52013-12-12 17:12:31 -0800200 .reg_bits = 8,
201 .val_bits = 8,
Krzysztof Kozlowskib07e2b72014-02-28 11:41:41 +0100202
203 .max_register = SEC_RTC_REG_MAX,
Krzysztof Kozlowski3e1e4a52013-12-12 17:12:31 -0800204};
205
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +0100206static const struct regmap_config s2mps14_rtc_regmap_config = {
207 .reg_bits = 8,
208 .val_bits = 8,
209
210 .max_register = S2MPS_RTC_REG_MAX,
211};
212
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800213#ifdef CONFIG_OF
214/*
215 * Only the common platform data elements for s5m8767 are parsed here from the
216 * device tree. Other sub-modules of s5m8767 such as pmic, rtc , charger and
217 * others have to parse their own platform data elements from device tree.
218 *
219 * The s5m8767 platform data structure is instantiated here and the drivers for
220 * the sub-modules need not instantiate another instance while parsing their
221 * platform data.
222 */
223static struct sec_platform_data *sec_pmic_i2c_parse_dt_pdata(
224 struct device *dev)
225{
226 struct sec_platform_data *pd;
227
228 pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL);
229 if (!pd) {
230 dev_err(dev, "could not allocate memory for pdata\n");
231 return ERR_PTR(-ENOMEM);
232 }
233
234 /*
235 * ToDo: the 'wakeup' member in the platform data is more of a linux
236 * specfic information. Hence, there is no binding for that yet and
237 * not parsed here.
238 */
239
240 return pd;
241}
242#else
Mark Brown197bf852013-02-04 18:31:25 +0000243static struct sec_platform_data *sec_pmic_i2c_parse_dt_pdata(
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800244 struct device *dev)
245{
Wei Yongjun005718c2013-12-07 14:02:15 +0800246 return NULL;
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800247}
248#endif
249
Pankaj Dubey8f695de2014-03-13 11:14:07 +0900250static inline unsigned long sec_i2c_get_driver_data(struct i2c_client *i2c,
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800251 const struct i2c_device_id *id)
252{
253#ifdef CONFIG_OF
254 if (i2c->dev.of_node) {
255 const struct of_device_id *match;
256 match = of_match_node(sec_dt_match, i2c->dev.of_node);
Pankaj Dubey8f695de2014-03-13 11:14:07 +0900257 return (unsigned long)match->data;
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800258 }
259#endif
Pankaj Dubey8f695de2014-03-13 11:14:07 +0900260 return id->driver_data;
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800261}
262
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900263static int sec_pmic_probe(struct i2c_client *i2c,
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900264 const struct i2c_device_id *id)
265{
Jingoo Han334a41c2013-07-30 17:10:05 +0900266 struct sec_platform_data *pdata = dev_get_platdata(&i2c->dev);
Krzysztof Kozlowski3e5a45f2014-02-28 11:41:42 +0100267 const struct regmap_config *regmap, *regmap_rtc;
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900268 struct sec_pmic_dev *sec_pmic;
Axel Lin61a2af32012-02-28 14:23:55 +0800269 int ret;
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900270
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900271 sec_pmic = devm_kzalloc(&i2c->dev, sizeof(struct sec_pmic_dev),
Sangbeom Kim621210e2012-01-20 16:09:11 +0900272 GFP_KERNEL);
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900273 if (sec_pmic == NULL)
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900274 return -ENOMEM;
275
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900276 i2c_set_clientdata(i2c, sec_pmic);
277 sec_pmic->dev = &i2c->dev;
278 sec_pmic->i2c = i2c;
279 sec_pmic->irq = i2c->irq;
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800280 sec_pmic->type = sec_i2c_get_driver_data(i2c, id);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900281
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800282 if (sec_pmic->dev->of_node) {
283 pdata = sec_pmic_i2c_parse_dt_pdata(sec_pmic->dev);
284 if (IS_ERR(pdata)) {
285 ret = PTR_ERR(pdata);
286 return ret;
287 }
288 pdata->device_type = sec_pmic->type;
289 }
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900290 if (pdata) {
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900291 sec_pmic->device_type = pdata->device_type;
292 sec_pmic->ono = pdata->ono;
293 sec_pmic->irq_base = pdata->irq_base;
294 sec_pmic->wakeup = pdata->wakeup;
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800295 sec_pmic->pdata = pdata;
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900296 }
297
Mark Brown25f311f2013-07-01 23:02:19 +0100298 switch (sec_pmic->device_type) {
Sachin Kamatce249912014-03-14 17:21:57 +0530299 case S2MPA01:
300 regmap = &s2mpa01_regmap_config;
301 break;
Mark Brown25f311f2013-07-01 23:02:19 +0100302 case S2MPS11X:
303 regmap = &s2mps11_regmap_config;
Krzysztof Kozlowski3e5a45f2014-02-28 11:41:42 +0100304 /*
305 * The rtc-s5m driver does not support S2MPS11 and there
306 * is no mfd_cell for S2MPS11 RTC device.
307 * However we must pass something to devm_regmap_init_i2c()
308 * so use S5M-like regmap config even though it wouldn't work.
309 */
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +0100310 regmap_rtc = &s5m_rtc_regmap_config;
311 break;
312 case S2MPS14X:
313 regmap = &s2mps14_regmap_config;
314 regmap_rtc = &s2mps14_rtc_regmap_config;
Mark Brown25f311f2013-07-01 23:02:19 +0100315 break;
316 case S5M8763X:
317 regmap = &s5m8763_regmap_config;
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +0100318 regmap_rtc = &s5m_rtc_regmap_config;
Mark Brown25f311f2013-07-01 23:02:19 +0100319 break;
320 case S5M8767X:
321 regmap = &s5m8767_regmap_config;
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +0100322 regmap_rtc = &s5m_rtc_regmap_config;
Mark Brown25f311f2013-07-01 23:02:19 +0100323 break;
324 default:
325 regmap = &sec_regmap_config;
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +0100326 regmap_rtc = &s5m_rtc_regmap_config;
Mark Brown25f311f2013-07-01 23:02:19 +0100327 break;
328 }
329
Krzysztof Kozlowski3e1e4a52013-12-12 17:12:31 -0800330 sec_pmic->regmap_pmic = devm_regmap_init_i2c(i2c, regmap);
331 if (IS_ERR(sec_pmic->regmap_pmic)) {
332 ret = PTR_ERR(sec_pmic->regmap_pmic);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900333 dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
Axel Lin61a2af32012-02-28 14:23:55 +0800334 ret);
Axel Lin1092e1c2012-04-25 10:03:44 +0800335 return ret;
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900336 }
337
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900338 sec_pmic->rtc = i2c_new_dummy(i2c->adapter, RTC_I2C_ADDR);
Krzysztof Kozlowski65aba1e2014-02-11 10:12:25 +0100339 if (!sec_pmic->rtc) {
340 dev_err(&i2c->dev, "Failed to allocate I2C for RTC\n");
341 return -ENODEV;
342 }
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900343 i2c_set_clientdata(sec_pmic->rtc, sec_pmic);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900344
Krzysztof Kozlowski3e5a45f2014-02-28 11:41:42 +0100345 sec_pmic->regmap_rtc = devm_regmap_init_i2c(sec_pmic->rtc, regmap_rtc);
Krzysztof Kozlowski3e1e4a52013-12-12 17:12:31 -0800346 if (IS_ERR(sec_pmic->regmap_rtc)) {
347 ret = PTR_ERR(sec_pmic->regmap_rtc);
348 dev_err(&i2c->dev, "Failed to allocate RTC register map: %d\n",
349 ret);
Krzysztof Kozlowski8c66eec2014-03-18 13:57:50 +0100350 goto err_regmap_rtc;
Krzysztof Kozlowski3e1e4a52013-12-12 17:12:31 -0800351 }
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:
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900362 ret = mfd_add_devices(sec_pmic->dev, -1, s5m8751_devs,
Mark Brown0848c942012-09-11 15:16:36 +0800363 ARRAY_SIZE(s5m8751_devs), NULL, 0, NULL);
Sangbeom Kim88a1cfd2012-01-20 16:09:12 +0900364 break;
365 case S5M8763X:
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900366 ret = mfd_add_devices(sec_pmic->dev, -1, s5m8763_devs,
Mark Brown0848c942012-09-11 15:16:36 +0800367 ARRAY_SIZE(s5m8763_devs), NULL, 0, NULL);
Sangbeom Kim88a1cfd2012-01-20 16:09:12 +0900368 break;
369 case S5M8767X:
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900370 ret = mfd_add_devices(sec_pmic->dev, -1, s5m8767_devs,
Mark Brown0848c942012-09-11 15:16:36 +0800371 ARRAY_SIZE(s5m8767_devs), NULL, 0, NULL);
Sangbeom Kim88a1cfd2012-01-20 16:09:12 +0900372 break;
Sachin Kamatce249912014-03-14 17:21:57 +0530373 case S2MPA01:
374 ret = mfd_add_devices(sec_pmic->dev, -1, s2mpa01_devs,
375 ARRAY_SIZE(s2mpa01_devs), NULL, 0, NULL);
376 break;
Sangbeom Kim9b6d1342012-07-11 21:07:55 +0900377 case S2MPS11X:
378 ret = mfd_add_devices(sec_pmic->dev, -1, s2mps11_devs,
Mark Brown0848c942012-09-11 15:16:36 +0800379 ARRAY_SIZE(s2mps11_devs), NULL, 0, NULL);
Sangbeom Kim9b6d1342012-07-11 21:07:55 +0900380 break;
Krzysztof Kozlowskidc691962014-02-28 11:41:44 +0100381 case S2MPS14X:
382 ret = mfd_add_devices(sec_pmic->dev, -1, s2mps14_devs,
383 ARRAY_SIZE(s2mps14_devs), NULL, 0, NULL);
384 break;
Sangbeom Kim88a1cfd2012-01-20 16:09:12 +0900385 default:
386 /* If this happens the probe function is problem */
387 BUG();
388 }
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900389
Leon Romanovsky15447a462013-05-15 18:00:48 +0300390 if (ret)
Krzysztof Kozlowski8c66eec2014-03-18 13:57:50 +0100391 goto err_mfd;
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900392
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100393 device_init_wakeup(sec_pmic->dev, sec_pmic->wakeup);
394
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900395 return ret;
396
Krzysztof Kozlowski8c66eec2014-03-18 13:57:50 +0100397err_mfd:
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900398 sec_irq_exit(sec_pmic);
Krzysztof Kozlowski8c66eec2014-03-18 13:57:50 +0100399err_regmap_rtc:
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900400 i2c_unregister_device(sec_pmic->rtc);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900401 return ret;
402}
403
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900404static int sec_pmic_remove(struct i2c_client *i2c)
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900405{
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900406 struct sec_pmic_dev *sec_pmic = i2c_get_clientdata(i2c);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900407
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900408 mfd_remove_devices(sec_pmic->dev);
409 sec_irq_exit(sec_pmic);
410 i2c_unregister_device(sec_pmic->rtc);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900411 return 0;
412}
413
Geert Uytterhoeven8321bbf2014-01-26 11:38:43 +0100414#ifdef CONFIG_PM_SLEEP
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100415static int sec_pmic_suspend(struct device *dev)
416{
417 struct i2c_client *i2c = container_of(dev, struct i2c_client, dev);
418 struct sec_pmic_dev *sec_pmic = i2c_get_clientdata(i2c);
419
420 if (device_may_wakeup(dev)) {
421 enable_irq_wake(sec_pmic->irq);
422 /*
423 * PMIC IRQ must be disabled during suspend for RTC alarm
424 * to work properly.
425 * When device is woken up from suspend by RTC Alarm, an
426 * interrupt occurs before resuming I2C bus controller.
427 * The interrupt is handled by regmap_irq_thread which tries
428 * to read RTC registers. This read fails (I2C is still
429 * suspended) and RTC Alarm interrupt is disabled.
430 */
431 disable_irq(sec_pmic->irq);
432 }
433
434 return 0;
435}
436
437static int sec_pmic_resume(struct device *dev)
438{
439 struct i2c_client *i2c = container_of(dev, struct i2c_client, dev);
440 struct sec_pmic_dev *sec_pmic = i2c_get_clientdata(i2c);
441
442 if (device_may_wakeup(dev)) {
443 disable_irq_wake(sec_pmic->irq);
444 enable_irq(sec_pmic->irq);
445 }
446
447 return 0;
448}
Geert Uytterhoeven8321bbf2014-01-26 11:38:43 +0100449#endif /* CONFIG_PM_SLEEP */
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100450
451static SIMPLE_DEV_PM_OPS(sec_pmic_pm_ops, sec_pmic_suspend, sec_pmic_resume);
452
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900453static const struct i2c_device_id sec_pmic_id[] = {
454 { "sec_pmic", 0 },
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900455 { }
456};
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900457MODULE_DEVICE_TABLE(i2c, sec_pmic_id);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900458
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900459static struct i2c_driver sec_pmic_driver = {
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900460 .driver = {
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900461 .name = "sec_pmic",
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900462 .owner = THIS_MODULE,
Krzysztof Kozlowskif6d6daa2013-11-26 14:50:27 +0100463 .pm = &sec_pmic_pm_ops,
Amit Daniel Kachhap26aec0092013-02-03 15:49:47 -0800464 .of_match_table = of_match_ptr(sec_dt_match),
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900465 },
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900466 .probe = sec_pmic_probe,
467 .remove = sec_pmic_remove,
468 .id_table = sec_pmic_id,
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900469};
470
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900471static int __init sec_pmic_init(void)
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900472{
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900473 return i2c_add_driver(&sec_pmic_driver);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900474}
475
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900476subsys_initcall(sec_pmic_init);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900477
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900478static void __exit sec_pmic_exit(void)
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900479{
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900480 i2c_del_driver(&sec_pmic_driver);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900481}
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900482module_exit(sec_pmic_exit);
Sangbeom Kim0f5f7072011-12-23 17:28:08 +0900483
484MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>");
485MODULE_DESCRIPTION("Core support for the S5M MFD");
486MODULE_LICENSE("GPL");