Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 1 | /* |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 2 | * sec-core.c |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 3 | * |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 4 | * Copyright (c) 2012 Samsung Electronics Co., Ltd |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 5 | * 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 Kamat | 1c5a099 | 2013-10-16 14:26:52 +0530 | [diff] [blame] | 20 | #include <linux/of.h> |
Amit Daniel Kachhap | 26aec009 | 2013-02-03 15:49:47 -0800 | [diff] [blame] | 21 | #include <linux/of_irq.h> |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 22 | #include <linux/interrupt.h> |
| 23 | #include <linux/pm_runtime.h> |
| 24 | #include <linux/mutex.h> |
| 25 | #include <linux/mfd/core.h> |
Sangbeom Kim | 54227bc | 2012-07-11 21:07:16 +0900 | [diff] [blame] | 26 | #include <linux/mfd/samsung/core.h> |
| 27 | #include <linux/mfd/samsung/irq.h> |
| 28 | #include <linux/mfd/samsung/rtc.h> |
Mark Brown | 25f311f | 2013-07-01 23:02:19 +0100 | [diff] [blame] | 29 | #include <linux/mfd/samsung/s2mps11.h> |
| 30 | #include <linux/mfd/samsung/s5m8763.h> |
| 31 | #include <linux/mfd/samsung/s5m8767.h> |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 32 | #include <linux/regmap.h> |
| 33 | |
Geert Uytterhoeven | 5ac9855 | 2013-11-18 14:33:06 +0100 | [diff] [blame] | 34 | static const struct mfd_cell s5m8751_devs[] = { |
Sangbeom Kim | 88a1cfd | 2012-01-20 16:09:12 +0900 | [diff] [blame] | 35 | { |
| 36 | .name = "s5m8751-pmic", |
| 37 | }, { |
| 38 | .name = "s5m-charger", |
| 39 | }, { |
| 40 | .name = "s5m8751-codec", |
| 41 | }, |
| 42 | }; |
| 43 | |
Geert Uytterhoeven | 5ac9855 | 2013-11-18 14:33:06 +0100 | [diff] [blame] | 44 | static const struct mfd_cell s5m8763_devs[] = { |
Sangbeom Kim | 88a1cfd | 2012-01-20 16:09:12 +0900 | [diff] [blame] | 45 | { |
| 46 | .name = "s5m8763-pmic", |
| 47 | }, { |
| 48 | .name = "s5m-rtc", |
| 49 | }, { |
| 50 | .name = "s5m-charger", |
| 51 | }, |
| 52 | }; |
| 53 | |
Geert Uytterhoeven | 5ac9855 | 2013-11-18 14:33:06 +0100 | [diff] [blame] | 54 | static const struct mfd_cell s5m8767_devs[] = { |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 55 | { |
| 56 | .name = "s5m8767-pmic", |
| 57 | }, { |
| 58 | .name = "s5m-rtc", |
Tushar Behera | 39fed00 | 2013-12-26 15:49:00 +0530 | [diff] [blame] | 59 | }, { |
| 60 | .name = "s5m8767-clk", |
| 61 | } |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 62 | }; |
| 63 | |
Geert Uytterhoeven | 5ac9855 | 2013-11-18 14:33:06 +0100 | [diff] [blame] | 64 | static const struct mfd_cell s2mps11_devs[] = { |
Sangbeom Kim | 9b6d134 | 2012-07-11 21:07:55 +0900 | [diff] [blame] | 65 | { |
| 66 | .name = "s2mps11-pmic", |
Yadwinder Singh Brar | 3134bca | 2013-07-07 17:14:21 +0530 | [diff] [blame] | 67 | }, { |
| 68 | .name = "s2mps11-clk", |
| 69 | } |
Sangbeom Kim | 9b6d134 | 2012-07-11 21:07:55 +0900 | [diff] [blame] | 70 | }; |
| 71 | |
Amit Daniel Kachhap | 26aec009 | 2013-02-03 15:49:47 -0800 | [diff] [blame] | 72 | #ifdef CONFIG_OF |
| 73 | static struct of_device_id sec_dt_match[] = { |
| 74 | { .compatible = "samsung,s5m8767-pmic", |
| 75 | .data = (void *)S5M8767X, |
| 76 | }, |
Yadwinder Singh Brar | aa32aca | 2013-06-29 18:21:20 +0530 | [diff] [blame] | 77 | { .compatible = "samsung,s2mps11-pmic", |
| 78 | .data = (void *)S2MPS11X, |
| 79 | }, |
Amit Daniel Kachhap | 26aec009 | 2013-02-03 15:49:47 -0800 | [diff] [blame] | 80 | {}, |
| 81 | }; |
| 82 | #endif |
| 83 | |
Mark Brown | 6b845ba | 2013-07-02 18:51:16 +0100 | [diff] [blame] | 84 | static bool s2mps11_volatile(struct device *dev, unsigned int reg) |
| 85 | { |
| 86 | switch (reg) { |
| 87 | case S2MPS11_REG_INT1M: |
| 88 | case S2MPS11_REG_INT2M: |
| 89 | case S2MPS11_REG_INT3M: |
| 90 | return false; |
| 91 | default: |
| 92 | return true; |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | static bool s5m8763_volatile(struct device *dev, unsigned int reg) |
| 97 | { |
| 98 | switch (reg) { |
| 99 | case S5M8763_REG_IRQM1: |
| 100 | case S5M8763_REG_IRQM2: |
| 101 | case S5M8763_REG_IRQM3: |
| 102 | case S5M8763_REG_IRQM4: |
| 103 | return false; |
| 104 | default: |
| 105 | return true; |
| 106 | } |
| 107 | } |
| 108 | |
Krzysztof Kozlowski | a30fffb | 2013-11-28 09:09:43 +0100 | [diff] [blame] | 109 | static const struct regmap_config sec_regmap_config = { |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 110 | .reg_bits = 8, |
| 111 | .val_bits = 8, |
| 112 | }; |
| 113 | |
Krzysztof Kozlowski | a30fffb | 2013-11-28 09:09:43 +0100 | [diff] [blame] | 114 | static const struct regmap_config s2mps11_regmap_config = { |
Mark Brown | 25f311f | 2013-07-01 23:02:19 +0100 | [diff] [blame] | 115 | .reg_bits = 8, |
| 116 | .val_bits = 8, |
| 117 | |
| 118 | .max_register = S2MPS11_REG_L38CTRL, |
Mark Brown | 6b845ba | 2013-07-02 18:51:16 +0100 | [diff] [blame] | 119 | .volatile_reg = s2mps11_volatile, |
| 120 | .cache_type = REGCACHE_FLAT, |
Mark Brown | 25f311f | 2013-07-01 23:02:19 +0100 | [diff] [blame] | 121 | }; |
| 122 | |
Krzysztof Kozlowski | a30fffb | 2013-11-28 09:09:43 +0100 | [diff] [blame] | 123 | static const struct regmap_config s5m8763_regmap_config = { |
Mark Brown | 25f311f | 2013-07-01 23:02:19 +0100 | [diff] [blame] | 124 | .reg_bits = 8, |
| 125 | .val_bits = 8, |
| 126 | |
| 127 | .max_register = S5M8763_REG_LBCNFG2, |
Mark Brown | 6b845ba | 2013-07-02 18:51:16 +0100 | [diff] [blame] | 128 | .volatile_reg = s5m8763_volatile, |
| 129 | .cache_type = REGCACHE_FLAT, |
Mark Brown | 25f311f | 2013-07-01 23:02:19 +0100 | [diff] [blame] | 130 | }; |
| 131 | |
Krzysztof Kozlowski | a30fffb | 2013-11-28 09:09:43 +0100 | [diff] [blame] | 132 | static const struct regmap_config s5m8767_regmap_config = { |
Mark Brown | 25f311f | 2013-07-01 23:02:19 +0100 | [diff] [blame] | 133 | .reg_bits = 8, |
| 134 | .val_bits = 8, |
| 135 | |
| 136 | .max_register = S5M8767_REG_LDO28CTRL, |
Mark Brown | 6b845ba | 2013-07-02 18:51:16 +0100 | [diff] [blame] | 137 | .volatile_reg = s2mps11_volatile, |
| 138 | .cache_type = REGCACHE_FLAT, |
Mark Brown | 25f311f | 2013-07-01 23:02:19 +0100 | [diff] [blame] | 139 | }; |
Amit Daniel Kachhap | 26aec009 | 2013-02-03 15:49:47 -0800 | [diff] [blame] | 140 | |
Krzysztof Kozlowski | 3e1e4a5 | 2013-12-12 17:12:31 -0800 | [diff] [blame] | 141 | static const struct regmap_config sec_rtc_regmap_config = { |
| 142 | .reg_bits = 8, |
| 143 | .val_bits = 8, |
| 144 | }; |
| 145 | |
Amit Daniel Kachhap | 26aec009 | 2013-02-03 15:49:47 -0800 | [diff] [blame] | 146 | #ifdef CONFIG_OF |
| 147 | /* |
| 148 | * Only the common platform data elements for s5m8767 are parsed here from the |
| 149 | * device tree. Other sub-modules of s5m8767 such as pmic, rtc , charger and |
| 150 | * others have to parse their own platform data elements from device tree. |
| 151 | * |
| 152 | * The s5m8767 platform data structure is instantiated here and the drivers for |
| 153 | * the sub-modules need not instantiate another instance while parsing their |
| 154 | * platform data. |
| 155 | */ |
| 156 | static struct sec_platform_data *sec_pmic_i2c_parse_dt_pdata( |
| 157 | struct device *dev) |
| 158 | { |
| 159 | struct sec_platform_data *pd; |
| 160 | |
| 161 | pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL); |
| 162 | if (!pd) { |
| 163 | dev_err(dev, "could not allocate memory for pdata\n"); |
| 164 | return ERR_PTR(-ENOMEM); |
| 165 | } |
| 166 | |
| 167 | /* |
| 168 | * ToDo: the 'wakeup' member in the platform data is more of a linux |
| 169 | * specfic information. Hence, there is no binding for that yet and |
| 170 | * not parsed here. |
| 171 | */ |
| 172 | |
| 173 | return pd; |
| 174 | } |
| 175 | #else |
Mark Brown | 197bf85 | 2013-02-04 18:31:25 +0000 | [diff] [blame] | 176 | static struct sec_platform_data *sec_pmic_i2c_parse_dt_pdata( |
Amit Daniel Kachhap | 26aec009 | 2013-02-03 15:49:47 -0800 | [diff] [blame] | 177 | struct device *dev) |
| 178 | { |
Wei Yongjun | 005718c | 2013-12-07 14:02:15 +0800 | [diff] [blame] | 179 | return NULL; |
Amit Daniel Kachhap | 26aec009 | 2013-02-03 15:49:47 -0800 | [diff] [blame] | 180 | } |
| 181 | #endif |
| 182 | |
| 183 | static inline int sec_i2c_get_driver_data(struct i2c_client *i2c, |
| 184 | const struct i2c_device_id *id) |
| 185 | { |
| 186 | #ifdef CONFIG_OF |
| 187 | if (i2c->dev.of_node) { |
| 188 | const struct of_device_id *match; |
| 189 | match = of_match_node(sec_dt_match, i2c->dev.of_node); |
| 190 | return (int)match->data; |
| 191 | } |
| 192 | #endif |
| 193 | return (int)id->driver_data; |
| 194 | } |
| 195 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 196 | static int sec_pmic_probe(struct i2c_client *i2c, |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 197 | const struct i2c_device_id *id) |
| 198 | { |
Jingoo Han | 334a41c | 2013-07-30 17:10:05 +0900 | [diff] [blame] | 199 | struct sec_platform_data *pdata = dev_get_platdata(&i2c->dev); |
Mark Brown | 25f311f | 2013-07-01 23:02:19 +0100 | [diff] [blame] | 200 | const struct regmap_config *regmap; |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 201 | struct sec_pmic_dev *sec_pmic; |
Axel Lin | 61a2af3 | 2012-02-28 14:23:55 +0800 | [diff] [blame] | 202 | int ret; |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 203 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 204 | sec_pmic = devm_kzalloc(&i2c->dev, sizeof(struct sec_pmic_dev), |
Sangbeom Kim | 621210e | 2012-01-20 16:09:11 +0900 | [diff] [blame] | 205 | GFP_KERNEL); |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 206 | if (sec_pmic == NULL) |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 207 | return -ENOMEM; |
| 208 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 209 | i2c_set_clientdata(i2c, sec_pmic); |
| 210 | sec_pmic->dev = &i2c->dev; |
| 211 | sec_pmic->i2c = i2c; |
| 212 | sec_pmic->irq = i2c->irq; |
Amit Daniel Kachhap | 26aec009 | 2013-02-03 15:49:47 -0800 | [diff] [blame] | 213 | sec_pmic->type = sec_i2c_get_driver_data(i2c, id); |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 214 | |
Amit Daniel Kachhap | 26aec009 | 2013-02-03 15:49:47 -0800 | [diff] [blame] | 215 | if (sec_pmic->dev->of_node) { |
| 216 | pdata = sec_pmic_i2c_parse_dt_pdata(sec_pmic->dev); |
| 217 | if (IS_ERR(pdata)) { |
| 218 | ret = PTR_ERR(pdata); |
| 219 | return ret; |
| 220 | } |
| 221 | pdata->device_type = sec_pmic->type; |
| 222 | } |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 223 | if (pdata) { |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 224 | sec_pmic->device_type = pdata->device_type; |
| 225 | sec_pmic->ono = pdata->ono; |
| 226 | sec_pmic->irq_base = pdata->irq_base; |
| 227 | sec_pmic->wakeup = pdata->wakeup; |
Amit Daniel Kachhap | 26aec009 | 2013-02-03 15:49:47 -0800 | [diff] [blame] | 228 | sec_pmic->pdata = pdata; |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 229 | } |
| 230 | |
Mark Brown | 25f311f | 2013-07-01 23:02:19 +0100 | [diff] [blame] | 231 | switch (sec_pmic->device_type) { |
| 232 | case S2MPS11X: |
| 233 | regmap = &s2mps11_regmap_config; |
| 234 | break; |
| 235 | case S5M8763X: |
| 236 | regmap = &s5m8763_regmap_config; |
| 237 | break; |
| 238 | case S5M8767X: |
| 239 | regmap = &s5m8767_regmap_config; |
| 240 | break; |
| 241 | default: |
| 242 | regmap = &sec_regmap_config; |
| 243 | break; |
| 244 | } |
| 245 | |
Krzysztof Kozlowski | 3e1e4a5 | 2013-12-12 17:12:31 -0800 | [diff] [blame] | 246 | sec_pmic->regmap_pmic = devm_regmap_init_i2c(i2c, regmap); |
| 247 | if (IS_ERR(sec_pmic->regmap_pmic)) { |
| 248 | ret = PTR_ERR(sec_pmic->regmap_pmic); |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 249 | dev_err(&i2c->dev, "Failed to allocate register map: %d\n", |
Axel Lin | 61a2af3 | 2012-02-28 14:23:55 +0800 | [diff] [blame] | 250 | ret); |
Axel Lin | 1092e1c | 2012-04-25 10:03:44 +0800 | [diff] [blame] | 251 | return ret; |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 252 | } |
| 253 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 254 | sec_pmic->rtc = i2c_new_dummy(i2c->adapter, RTC_I2C_ADDR); |
| 255 | i2c_set_clientdata(sec_pmic->rtc, sec_pmic); |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 256 | |
Krzysztof Kozlowski | 3e1e4a5 | 2013-12-12 17:12:31 -0800 | [diff] [blame] | 257 | sec_pmic->regmap_rtc = devm_regmap_init_i2c(sec_pmic->rtc, |
| 258 | &sec_rtc_regmap_config); |
| 259 | if (IS_ERR(sec_pmic->regmap_rtc)) { |
| 260 | ret = PTR_ERR(sec_pmic->regmap_rtc); |
| 261 | dev_err(&i2c->dev, "Failed to allocate RTC register map: %d\n", |
| 262 | ret); |
| 263 | return ret; |
| 264 | } |
| 265 | |
Jonghwan Choi | c3ebb30 | 2012-01-16 09:08:42 +0900 | [diff] [blame] | 266 | if (pdata && pdata->cfg_pmic_irq) |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 267 | pdata->cfg_pmic_irq(); |
| 268 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 269 | sec_irq_init(sec_pmic); |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 270 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 271 | pm_runtime_set_active(sec_pmic->dev); |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 272 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 273 | switch (sec_pmic->device_type) { |
Sangbeom Kim | 88a1cfd | 2012-01-20 16:09:12 +0900 | [diff] [blame] | 274 | case S5M8751X: |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 275 | ret = mfd_add_devices(sec_pmic->dev, -1, s5m8751_devs, |
Mark Brown | 0848c94 | 2012-09-11 15:16:36 +0800 | [diff] [blame] | 276 | ARRAY_SIZE(s5m8751_devs), NULL, 0, NULL); |
Sangbeom Kim | 88a1cfd | 2012-01-20 16:09:12 +0900 | [diff] [blame] | 277 | break; |
| 278 | case S5M8763X: |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 279 | ret = mfd_add_devices(sec_pmic->dev, -1, s5m8763_devs, |
Mark Brown | 0848c94 | 2012-09-11 15:16:36 +0800 | [diff] [blame] | 280 | ARRAY_SIZE(s5m8763_devs), NULL, 0, NULL); |
Sangbeom Kim | 88a1cfd | 2012-01-20 16:09:12 +0900 | [diff] [blame] | 281 | break; |
| 282 | case S5M8767X: |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 283 | ret = mfd_add_devices(sec_pmic->dev, -1, s5m8767_devs, |
Mark Brown | 0848c94 | 2012-09-11 15:16:36 +0800 | [diff] [blame] | 284 | ARRAY_SIZE(s5m8767_devs), NULL, 0, NULL); |
Sangbeom Kim | 88a1cfd | 2012-01-20 16:09:12 +0900 | [diff] [blame] | 285 | break; |
Sangbeom Kim | 9b6d134 | 2012-07-11 21:07:55 +0900 | [diff] [blame] | 286 | case S2MPS11X: |
| 287 | ret = mfd_add_devices(sec_pmic->dev, -1, s2mps11_devs, |
Mark Brown | 0848c94 | 2012-09-11 15:16:36 +0800 | [diff] [blame] | 288 | ARRAY_SIZE(s2mps11_devs), NULL, 0, NULL); |
Sangbeom Kim | 9b6d134 | 2012-07-11 21:07:55 +0900 | [diff] [blame] | 289 | break; |
Sangbeom Kim | 88a1cfd | 2012-01-20 16:09:12 +0900 | [diff] [blame] | 290 | default: |
| 291 | /* If this happens the probe function is problem */ |
| 292 | BUG(); |
| 293 | } |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 294 | |
Leon Romanovsky | 15447a46 | 2013-05-15 18:00:48 +0300 | [diff] [blame] | 295 | if (ret) |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 296 | goto err; |
| 297 | |
Krzysztof Kozlowski | f6d6daa | 2013-11-26 14:50:27 +0100 | [diff] [blame] | 298 | device_init_wakeup(sec_pmic->dev, sec_pmic->wakeup); |
| 299 | |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 300 | return ret; |
| 301 | |
| 302 | err: |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 303 | sec_irq_exit(sec_pmic); |
| 304 | i2c_unregister_device(sec_pmic->rtc); |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 305 | return ret; |
| 306 | } |
| 307 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 308 | static int sec_pmic_remove(struct i2c_client *i2c) |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 309 | { |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 310 | struct sec_pmic_dev *sec_pmic = i2c_get_clientdata(i2c); |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 311 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 312 | mfd_remove_devices(sec_pmic->dev); |
| 313 | sec_irq_exit(sec_pmic); |
| 314 | i2c_unregister_device(sec_pmic->rtc); |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 315 | return 0; |
| 316 | } |
| 317 | |
Geert Uytterhoeven | 8321bbf | 2014-01-26 11:38:43 +0100 | [diff] [blame] | 318 | #ifdef CONFIG_PM_SLEEP |
Krzysztof Kozlowski | f6d6daa | 2013-11-26 14:50:27 +0100 | [diff] [blame] | 319 | static int sec_pmic_suspend(struct device *dev) |
| 320 | { |
| 321 | struct i2c_client *i2c = container_of(dev, struct i2c_client, dev); |
| 322 | struct sec_pmic_dev *sec_pmic = i2c_get_clientdata(i2c); |
| 323 | |
| 324 | if (device_may_wakeup(dev)) { |
| 325 | enable_irq_wake(sec_pmic->irq); |
| 326 | /* |
| 327 | * PMIC IRQ must be disabled during suspend for RTC alarm |
| 328 | * to work properly. |
| 329 | * When device is woken up from suspend by RTC Alarm, an |
| 330 | * interrupt occurs before resuming I2C bus controller. |
| 331 | * The interrupt is handled by regmap_irq_thread which tries |
| 332 | * to read RTC registers. This read fails (I2C is still |
| 333 | * suspended) and RTC Alarm interrupt is disabled. |
| 334 | */ |
| 335 | disable_irq(sec_pmic->irq); |
| 336 | } |
| 337 | |
| 338 | return 0; |
| 339 | } |
| 340 | |
| 341 | static int sec_pmic_resume(struct device *dev) |
| 342 | { |
| 343 | struct i2c_client *i2c = container_of(dev, struct i2c_client, dev); |
| 344 | struct sec_pmic_dev *sec_pmic = i2c_get_clientdata(i2c); |
| 345 | |
| 346 | if (device_may_wakeup(dev)) { |
| 347 | disable_irq_wake(sec_pmic->irq); |
| 348 | enable_irq(sec_pmic->irq); |
| 349 | } |
| 350 | |
| 351 | return 0; |
| 352 | } |
Geert Uytterhoeven | 8321bbf | 2014-01-26 11:38:43 +0100 | [diff] [blame] | 353 | #endif /* CONFIG_PM_SLEEP */ |
Krzysztof Kozlowski | f6d6daa | 2013-11-26 14:50:27 +0100 | [diff] [blame] | 354 | |
| 355 | static SIMPLE_DEV_PM_OPS(sec_pmic_pm_ops, sec_pmic_suspend, sec_pmic_resume); |
| 356 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 357 | static const struct i2c_device_id sec_pmic_id[] = { |
| 358 | { "sec_pmic", 0 }, |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 359 | { } |
| 360 | }; |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 361 | MODULE_DEVICE_TABLE(i2c, sec_pmic_id); |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 362 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 363 | static struct i2c_driver sec_pmic_driver = { |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 364 | .driver = { |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 365 | .name = "sec_pmic", |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 366 | .owner = THIS_MODULE, |
Krzysztof Kozlowski | f6d6daa | 2013-11-26 14:50:27 +0100 | [diff] [blame] | 367 | .pm = &sec_pmic_pm_ops, |
Amit Daniel Kachhap | 26aec009 | 2013-02-03 15:49:47 -0800 | [diff] [blame] | 368 | .of_match_table = of_match_ptr(sec_dt_match), |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 369 | }, |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 370 | .probe = sec_pmic_probe, |
| 371 | .remove = sec_pmic_remove, |
| 372 | .id_table = sec_pmic_id, |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 373 | }; |
| 374 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 375 | static int __init sec_pmic_init(void) |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 376 | { |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 377 | return i2c_add_driver(&sec_pmic_driver); |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 378 | } |
| 379 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 380 | subsys_initcall(sec_pmic_init); |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 381 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 382 | static void __exit sec_pmic_exit(void) |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 383 | { |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 384 | i2c_del_driver(&sec_pmic_driver); |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 385 | } |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 386 | module_exit(sec_pmic_exit); |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 387 | |
| 388 | MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>"); |
| 389 | MODULE_DESCRIPTION("Core support for the S5M MFD"); |
| 390 | MODULE_LICENSE("GPL"); |