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> |
Sachin Kamat | ce24991 | 2014-03-14 17:21:57 +0530 | [diff] [blame] | 29 | #include <linux/mfd/samsung/s2mpa01.h> |
Mark Brown | 25f311f | 2013-07-01 23:02:19 +0100 | [diff] [blame] | 30 | #include <linux/mfd/samsung/s2mps11.h> |
Krzysztof Kozlowski | dc69196 | 2014-02-28 11:41:44 +0100 | [diff] [blame] | 31 | #include <linux/mfd/samsung/s2mps14.h> |
Mark Brown | 25f311f | 2013-07-01 23:02:19 +0100 | [diff] [blame] | 32 | #include <linux/mfd/samsung/s5m8763.h> |
| 33 | #include <linux/mfd/samsung/s5m8767.h> |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 34 | #include <linux/regmap.h> |
| 35 | |
Geert Uytterhoeven | 5ac9855 | 2013-11-18 14:33:06 +0100 | [diff] [blame] | 36 | static const struct mfd_cell s5m8751_devs[] = { |
Sangbeom Kim | 88a1cfd | 2012-01-20 16:09:12 +0900 | [diff] [blame] | 37 | { |
| 38 | .name = "s5m8751-pmic", |
| 39 | }, { |
| 40 | .name = "s5m-charger", |
| 41 | }, { |
| 42 | .name = "s5m8751-codec", |
| 43 | }, |
| 44 | }; |
| 45 | |
Geert Uytterhoeven | 5ac9855 | 2013-11-18 14:33:06 +0100 | [diff] [blame] | 46 | static const struct mfd_cell s5m8763_devs[] = { |
Sangbeom Kim | 88a1cfd | 2012-01-20 16:09:12 +0900 | [diff] [blame] | 47 | { |
| 48 | .name = "s5m8763-pmic", |
| 49 | }, { |
| 50 | .name = "s5m-rtc", |
| 51 | }, { |
| 52 | .name = "s5m-charger", |
| 53 | }, |
| 54 | }; |
| 55 | |
Geert Uytterhoeven | 5ac9855 | 2013-11-18 14:33:06 +0100 | [diff] [blame] | 56 | static const struct mfd_cell s5m8767_devs[] = { |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 57 | { |
| 58 | .name = "s5m8767-pmic", |
| 59 | }, { |
| 60 | .name = "s5m-rtc", |
Tushar Behera | 39fed00 | 2013-12-26 15:49:00 +0530 | [diff] [blame] | 61 | }, { |
| 62 | .name = "s5m8767-clk", |
Krzysztof Kozlowski | 53c31b3 | 2014-03-17 10:19:17 +0100 | [diff] [blame] | 63 | .of_compatible = "samsung,s5m8767-clk", |
Tushar Behera | 39fed00 | 2013-12-26 15:49:00 +0530 | [diff] [blame] | 64 | } |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 65 | }; |
| 66 | |
Geert Uytterhoeven | 5ac9855 | 2013-11-18 14:33:06 +0100 | [diff] [blame] | 67 | static const struct mfd_cell s2mps11_devs[] = { |
Sangbeom Kim | 9b6d134 | 2012-07-11 21:07:55 +0900 | [diff] [blame] | 68 | { |
| 69 | .name = "s2mps11-pmic", |
Yadwinder Singh Brar | 3134bca | 2013-07-07 17:14:21 +0530 | [diff] [blame] | 70 | }, { |
| 71 | .name = "s2mps11-clk", |
Krzysztof Kozlowski | 53c31b3 | 2014-03-17 10:19:17 +0100 | [diff] [blame] | 72 | .of_compatible = "samsung,s2mps11-clk", |
Yadwinder Singh Brar | 3134bca | 2013-07-07 17:14:21 +0530 | [diff] [blame] | 73 | } |
Sangbeom Kim | 9b6d134 | 2012-07-11 21:07:55 +0900 | [diff] [blame] | 74 | }; |
| 75 | |
Krzysztof Kozlowski | dc69196 | 2014-02-28 11:41:44 +0100 | [diff] [blame] | 76 | static const struct mfd_cell s2mps14_devs[] = { |
| 77 | { |
| 78 | .name = "s2mps14-pmic", |
| 79 | }, { |
| 80 | .name = "s2mps14-rtc", |
| 81 | }, { |
| 82 | .name = "s2mps14-clk", |
Krzysztof Kozlowski | 53c31b3 | 2014-03-17 10:19:17 +0100 | [diff] [blame] | 83 | .of_compatible = "samsung,s2mps14-clk", |
Krzysztof Kozlowski | dc69196 | 2014-02-28 11:41:44 +0100 | [diff] [blame] | 84 | } |
| 85 | }; |
| 86 | |
Sachin Kamat | ce24991 | 2014-03-14 17:21:57 +0530 | [diff] [blame] | 87 | static const struct mfd_cell s2mpa01_devs[] = { |
| 88 | { |
| 89 | .name = "s2mpa01-pmic", |
| 90 | }, |
| 91 | }; |
| 92 | |
Amit Daniel Kachhap | 26aec009 | 2013-02-03 15:49:47 -0800 | [diff] [blame] | 93 | #ifdef CONFIG_OF |
| 94 | static struct of_device_id sec_dt_match[] = { |
| 95 | { .compatible = "samsung,s5m8767-pmic", |
| 96 | .data = (void *)S5M8767X, |
Sachin Kamat | ce24991 | 2014-03-14 17:21:57 +0530 | [diff] [blame] | 97 | }, { |
| 98 | .compatible = "samsung,s2mps11-pmic", |
Yadwinder Singh Brar | aa32aca | 2013-06-29 18:21:20 +0530 | [diff] [blame] | 99 | .data = (void *)S2MPS11X, |
Sachin Kamat | ce24991 | 2014-03-14 17:21:57 +0530 | [diff] [blame] | 100 | }, { |
| 101 | .compatible = "samsung,s2mps14-pmic", |
Krzysztof Kozlowski | dc69196 | 2014-02-28 11:41:44 +0100 | [diff] [blame] | 102 | .data = (void *)S2MPS14X, |
Sachin Kamat | ce24991 | 2014-03-14 17:21:57 +0530 | [diff] [blame] | 103 | }, { |
| 104 | .compatible = "samsung,s2mpa01-pmic", |
| 105 | .data = (void *)S2MPA01, |
| 106 | }, { |
| 107 | /* Sentinel */ |
Krzysztof Kozlowski | dc69196 | 2014-02-28 11:41:44 +0100 | [diff] [blame] | 108 | }, |
Amit Daniel Kachhap | 26aec009 | 2013-02-03 15:49:47 -0800 | [diff] [blame] | 109 | }; |
| 110 | #endif |
| 111 | |
Sachin Kamat | ce24991 | 2014-03-14 17:21:57 +0530 | [diff] [blame] | 112 | static 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 Brown | 6b845ba | 2013-07-02 18:51:16 +0100 | [diff] [blame] | 124 | static 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 | |
| 136 | static 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 Kozlowski | a30fffb | 2013-11-28 09:09:43 +0100 | [diff] [blame] | 149 | static const struct regmap_config sec_regmap_config = { |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 150 | .reg_bits = 8, |
| 151 | .val_bits = 8, |
| 152 | }; |
| 153 | |
Sachin Kamat | ce24991 | 2014-03-14 17:21:57 +0530 | [diff] [blame] | 154 | static 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 Kozlowski | a30fffb | 2013-11-28 09:09:43 +0100 | [diff] [blame] | 163 | static const struct regmap_config s2mps11_regmap_config = { |
Mark Brown | 25f311f | 2013-07-01 23:02:19 +0100 | [diff] [blame] | 164 | .reg_bits = 8, |
| 165 | .val_bits = 8, |
| 166 | |
| 167 | .max_register = S2MPS11_REG_L38CTRL, |
Mark Brown | 6b845ba | 2013-07-02 18:51:16 +0100 | [diff] [blame] | 168 | .volatile_reg = s2mps11_volatile, |
| 169 | .cache_type = REGCACHE_FLAT, |
Mark Brown | 25f311f | 2013-07-01 23:02:19 +0100 | [diff] [blame] | 170 | }; |
| 171 | |
Krzysztof Kozlowski | dc69196 | 2014-02-28 11:41:44 +0100 | [diff] [blame] | 172 | static 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 Kozlowski | a30fffb | 2013-11-28 09:09:43 +0100 | [diff] [blame] | 181 | static const struct regmap_config s5m8763_regmap_config = { |
Mark Brown | 25f311f | 2013-07-01 23:02:19 +0100 | [diff] [blame] | 182 | .reg_bits = 8, |
| 183 | .val_bits = 8, |
| 184 | |
| 185 | .max_register = S5M8763_REG_LBCNFG2, |
Mark Brown | 6b845ba | 2013-07-02 18:51:16 +0100 | [diff] [blame] | 186 | .volatile_reg = s5m8763_volatile, |
| 187 | .cache_type = REGCACHE_FLAT, |
Mark Brown | 25f311f | 2013-07-01 23:02:19 +0100 | [diff] [blame] | 188 | }; |
| 189 | |
Krzysztof Kozlowski | a30fffb | 2013-11-28 09:09:43 +0100 | [diff] [blame] | 190 | static const struct regmap_config s5m8767_regmap_config = { |
Mark Brown | 25f311f | 2013-07-01 23:02:19 +0100 | [diff] [blame] | 191 | .reg_bits = 8, |
| 192 | .val_bits = 8, |
| 193 | |
| 194 | .max_register = S5M8767_REG_LDO28CTRL, |
Mark Brown | 6b845ba | 2013-07-02 18:51:16 +0100 | [diff] [blame] | 195 | .volatile_reg = s2mps11_volatile, |
| 196 | .cache_type = REGCACHE_FLAT, |
Mark Brown | 25f311f | 2013-07-01 23:02:19 +0100 | [diff] [blame] | 197 | }; |
Amit Daniel Kachhap | 26aec009 | 2013-02-03 15:49:47 -0800 | [diff] [blame] | 198 | |
Krzysztof Kozlowski | dc69196 | 2014-02-28 11:41:44 +0100 | [diff] [blame] | 199 | static const struct regmap_config s5m_rtc_regmap_config = { |
Krzysztof Kozlowski | 3e1e4a5 | 2013-12-12 17:12:31 -0800 | [diff] [blame] | 200 | .reg_bits = 8, |
| 201 | .val_bits = 8, |
Krzysztof Kozlowski | b07e2b7 | 2014-02-28 11:41:41 +0100 | [diff] [blame] | 202 | |
| 203 | .max_register = SEC_RTC_REG_MAX, |
Krzysztof Kozlowski | 3e1e4a5 | 2013-12-12 17:12:31 -0800 | [diff] [blame] | 204 | }; |
| 205 | |
Krzysztof Kozlowski | dc69196 | 2014-02-28 11:41:44 +0100 | [diff] [blame] | 206 | static 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 Kachhap | 26aec009 | 2013-02-03 15:49:47 -0800 | [diff] [blame] | 213 | #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 | */ |
| 223 | static 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 Brown | 197bf85 | 2013-02-04 18:31:25 +0000 | [diff] [blame] | 243 | static struct sec_platform_data *sec_pmic_i2c_parse_dt_pdata( |
Amit Daniel Kachhap | 26aec009 | 2013-02-03 15:49:47 -0800 | [diff] [blame] | 244 | struct device *dev) |
| 245 | { |
Wei Yongjun | 005718c | 2013-12-07 14:02:15 +0800 | [diff] [blame] | 246 | return NULL; |
Amit Daniel Kachhap | 26aec009 | 2013-02-03 15:49:47 -0800 | [diff] [blame] | 247 | } |
| 248 | #endif |
| 249 | |
Pankaj Dubey | 8f695de | 2014-03-13 11:14:07 +0900 | [diff] [blame] | 250 | static inline unsigned long sec_i2c_get_driver_data(struct i2c_client *i2c, |
Amit Daniel Kachhap | 26aec009 | 2013-02-03 15:49:47 -0800 | [diff] [blame] | 251 | 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 Dubey | 8f695de | 2014-03-13 11:14:07 +0900 | [diff] [blame] | 257 | return (unsigned long)match->data; |
Amit Daniel Kachhap | 26aec009 | 2013-02-03 15:49:47 -0800 | [diff] [blame] | 258 | } |
| 259 | #endif |
Pankaj Dubey | 8f695de | 2014-03-13 11:14:07 +0900 | [diff] [blame] | 260 | return id->driver_data; |
Amit Daniel Kachhap | 26aec009 | 2013-02-03 15:49:47 -0800 | [diff] [blame] | 261 | } |
| 262 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 263 | static int sec_pmic_probe(struct i2c_client *i2c, |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 264 | const struct i2c_device_id *id) |
| 265 | { |
Jingoo Han | 334a41c | 2013-07-30 17:10:05 +0900 | [diff] [blame] | 266 | struct sec_platform_data *pdata = dev_get_platdata(&i2c->dev); |
Krzysztof Kozlowski | 3e5a45f | 2014-02-28 11:41:42 +0100 | [diff] [blame] | 267 | const struct regmap_config *regmap, *regmap_rtc; |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 268 | struct sec_pmic_dev *sec_pmic; |
Axel Lin | 61a2af3 | 2012-02-28 14:23:55 +0800 | [diff] [blame] | 269 | int ret; |
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 | sec_pmic = devm_kzalloc(&i2c->dev, sizeof(struct sec_pmic_dev), |
Sangbeom Kim | 621210e | 2012-01-20 16:09:11 +0900 | [diff] [blame] | 272 | GFP_KERNEL); |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 273 | if (sec_pmic == NULL) |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 274 | return -ENOMEM; |
| 275 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 276 | 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 Kachhap | 26aec009 | 2013-02-03 15:49:47 -0800 | [diff] [blame] | 280 | sec_pmic->type = sec_i2c_get_driver_data(i2c, id); |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 281 | |
Amit Daniel Kachhap | 26aec009 | 2013-02-03 15:49:47 -0800 | [diff] [blame] | 282 | 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 Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 290 | if (pdata) { |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 291 | 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 Kachhap | 26aec009 | 2013-02-03 15:49:47 -0800 | [diff] [blame] | 295 | sec_pmic->pdata = pdata; |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 296 | } |
| 297 | |
Mark Brown | 25f311f | 2013-07-01 23:02:19 +0100 | [diff] [blame] | 298 | switch (sec_pmic->device_type) { |
Sachin Kamat | ce24991 | 2014-03-14 17:21:57 +0530 | [diff] [blame] | 299 | case S2MPA01: |
| 300 | regmap = &s2mpa01_regmap_config; |
| 301 | break; |
Mark Brown | 25f311f | 2013-07-01 23:02:19 +0100 | [diff] [blame] | 302 | case S2MPS11X: |
| 303 | regmap = &s2mps11_regmap_config; |
Krzysztof Kozlowski | 3e5a45f | 2014-02-28 11:41:42 +0100 | [diff] [blame] | 304 | /* |
| 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 Kozlowski | dc69196 | 2014-02-28 11:41:44 +0100 | [diff] [blame] | 310 | regmap_rtc = &s5m_rtc_regmap_config; |
| 311 | break; |
| 312 | case S2MPS14X: |
| 313 | regmap = &s2mps14_regmap_config; |
| 314 | regmap_rtc = &s2mps14_rtc_regmap_config; |
Mark Brown | 25f311f | 2013-07-01 23:02:19 +0100 | [diff] [blame] | 315 | break; |
| 316 | case S5M8763X: |
| 317 | regmap = &s5m8763_regmap_config; |
Krzysztof Kozlowski | dc69196 | 2014-02-28 11:41:44 +0100 | [diff] [blame] | 318 | regmap_rtc = &s5m_rtc_regmap_config; |
Mark Brown | 25f311f | 2013-07-01 23:02:19 +0100 | [diff] [blame] | 319 | break; |
| 320 | case S5M8767X: |
| 321 | regmap = &s5m8767_regmap_config; |
Krzysztof Kozlowski | dc69196 | 2014-02-28 11:41:44 +0100 | [diff] [blame] | 322 | regmap_rtc = &s5m_rtc_regmap_config; |
Mark Brown | 25f311f | 2013-07-01 23:02:19 +0100 | [diff] [blame] | 323 | break; |
| 324 | default: |
| 325 | regmap = &sec_regmap_config; |
Krzysztof Kozlowski | dc69196 | 2014-02-28 11:41:44 +0100 | [diff] [blame] | 326 | regmap_rtc = &s5m_rtc_regmap_config; |
Mark Brown | 25f311f | 2013-07-01 23:02:19 +0100 | [diff] [blame] | 327 | break; |
| 328 | } |
| 329 | |
Krzysztof Kozlowski | 3e1e4a5 | 2013-12-12 17:12:31 -0800 | [diff] [blame] | 330 | 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 Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 333 | dev_err(&i2c->dev, "Failed to allocate register map: %d\n", |
Axel Lin | 61a2af3 | 2012-02-28 14:23:55 +0800 | [diff] [blame] | 334 | ret); |
Axel Lin | 1092e1c | 2012-04-25 10:03:44 +0800 | [diff] [blame] | 335 | return ret; |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 336 | } |
| 337 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 338 | sec_pmic->rtc = i2c_new_dummy(i2c->adapter, RTC_I2C_ADDR); |
Krzysztof Kozlowski | 65aba1e | 2014-02-11 10:12:25 +0100 | [diff] [blame] | 339 | if (!sec_pmic->rtc) { |
| 340 | dev_err(&i2c->dev, "Failed to allocate I2C for RTC\n"); |
| 341 | return -ENODEV; |
| 342 | } |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 343 | i2c_set_clientdata(sec_pmic->rtc, sec_pmic); |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 344 | |
Krzysztof Kozlowski | 3e5a45f | 2014-02-28 11:41:42 +0100 | [diff] [blame] | 345 | sec_pmic->regmap_rtc = devm_regmap_init_i2c(sec_pmic->rtc, regmap_rtc); |
Krzysztof Kozlowski | 3e1e4a5 | 2013-12-12 17:12:31 -0800 | [diff] [blame] | 346 | 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 Kozlowski | 8c66eec | 2014-03-18 13:57:50 +0100 | [diff] [blame^] | 350 | goto err_regmap_rtc; |
Krzysztof Kozlowski | 3e1e4a5 | 2013-12-12 17:12:31 -0800 | [diff] [blame] | 351 | } |
| 352 | |
Jonghwan Choi | c3ebb30 | 2012-01-16 09:08:42 +0900 | [diff] [blame] | 353 | if (pdata && pdata->cfg_pmic_irq) |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 354 | pdata->cfg_pmic_irq(); |
| 355 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 356 | sec_irq_init(sec_pmic); |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 357 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 358 | pm_runtime_set_active(sec_pmic->dev); |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 359 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 360 | switch (sec_pmic->device_type) { |
Sangbeom Kim | 88a1cfd | 2012-01-20 16:09:12 +0900 | [diff] [blame] | 361 | case S5M8751X: |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 362 | ret = mfd_add_devices(sec_pmic->dev, -1, s5m8751_devs, |
Mark Brown | 0848c94 | 2012-09-11 15:16:36 +0800 | [diff] [blame] | 363 | ARRAY_SIZE(s5m8751_devs), NULL, 0, NULL); |
Sangbeom Kim | 88a1cfd | 2012-01-20 16:09:12 +0900 | [diff] [blame] | 364 | break; |
| 365 | case S5M8763X: |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 366 | ret = mfd_add_devices(sec_pmic->dev, -1, s5m8763_devs, |
Mark Brown | 0848c94 | 2012-09-11 15:16:36 +0800 | [diff] [blame] | 367 | ARRAY_SIZE(s5m8763_devs), NULL, 0, NULL); |
Sangbeom Kim | 88a1cfd | 2012-01-20 16:09:12 +0900 | [diff] [blame] | 368 | break; |
| 369 | case S5M8767X: |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 370 | ret = mfd_add_devices(sec_pmic->dev, -1, s5m8767_devs, |
Mark Brown | 0848c94 | 2012-09-11 15:16:36 +0800 | [diff] [blame] | 371 | ARRAY_SIZE(s5m8767_devs), NULL, 0, NULL); |
Sangbeom Kim | 88a1cfd | 2012-01-20 16:09:12 +0900 | [diff] [blame] | 372 | break; |
Sachin Kamat | ce24991 | 2014-03-14 17:21:57 +0530 | [diff] [blame] | 373 | case S2MPA01: |
| 374 | ret = mfd_add_devices(sec_pmic->dev, -1, s2mpa01_devs, |
| 375 | ARRAY_SIZE(s2mpa01_devs), NULL, 0, NULL); |
| 376 | break; |
Sangbeom Kim | 9b6d134 | 2012-07-11 21:07:55 +0900 | [diff] [blame] | 377 | case S2MPS11X: |
| 378 | ret = mfd_add_devices(sec_pmic->dev, -1, s2mps11_devs, |
Mark Brown | 0848c94 | 2012-09-11 15:16:36 +0800 | [diff] [blame] | 379 | ARRAY_SIZE(s2mps11_devs), NULL, 0, NULL); |
Sangbeom Kim | 9b6d134 | 2012-07-11 21:07:55 +0900 | [diff] [blame] | 380 | break; |
Krzysztof Kozlowski | dc69196 | 2014-02-28 11:41:44 +0100 | [diff] [blame] | 381 | case S2MPS14X: |
| 382 | ret = mfd_add_devices(sec_pmic->dev, -1, s2mps14_devs, |
| 383 | ARRAY_SIZE(s2mps14_devs), NULL, 0, NULL); |
| 384 | break; |
Sangbeom Kim | 88a1cfd | 2012-01-20 16:09:12 +0900 | [diff] [blame] | 385 | default: |
| 386 | /* If this happens the probe function is problem */ |
| 387 | BUG(); |
| 388 | } |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 389 | |
Leon Romanovsky | 15447a46 | 2013-05-15 18:00:48 +0300 | [diff] [blame] | 390 | if (ret) |
Krzysztof Kozlowski | 8c66eec | 2014-03-18 13:57:50 +0100 | [diff] [blame^] | 391 | goto err_mfd; |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 392 | |
Krzysztof Kozlowski | f6d6daa | 2013-11-26 14:50:27 +0100 | [diff] [blame] | 393 | device_init_wakeup(sec_pmic->dev, sec_pmic->wakeup); |
| 394 | |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 395 | return ret; |
| 396 | |
Krzysztof Kozlowski | 8c66eec | 2014-03-18 13:57:50 +0100 | [diff] [blame^] | 397 | err_mfd: |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 398 | sec_irq_exit(sec_pmic); |
Krzysztof Kozlowski | 8c66eec | 2014-03-18 13:57:50 +0100 | [diff] [blame^] | 399 | err_regmap_rtc: |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 400 | i2c_unregister_device(sec_pmic->rtc); |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 401 | return ret; |
| 402 | } |
| 403 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 404 | static int sec_pmic_remove(struct i2c_client *i2c) |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 405 | { |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 406 | struct sec_pmic_dev *sec_pmic = i2c_get_clientdata(i2c); |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 407 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 408 | mfd_remove_devices(sec_pmic->dev); |
| 409 | sec_irq_exit(sec_pmic); |
| 410 | i2c_unregister_device(sec_pmic->rtc); |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 411 | return 0; |
| 412 | } |
| 413 | |
Geert Uytterhoeven | 8321bbf | 2014-01-26 11:38:43 +0100 | [diff] [blame] | 414 | #ifdef CONFIG_PM_SLEEP |
Krzysztof Kozlowski | f6d6daa | 2013-11-26 14:50:27 +0100 | [diff] [blame] | 415 | static 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 | |
| 437 | static 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 Uytterhoeven | 8321bbf | 2014-01-26 11:38:43 +0100 | [diff] [blame] | 449 | #endif /* CONFIG_PM_SLEEP */ |
Krzysztof Kozlowski | f6d6daa | 2013-11-26 14:50:27 +0100 | [diff] [blame] | 450 | |
| 451 | static SIMPLE_DEV_PM_OPS(sec_pmic_pm_ops, sec_pmic_suspend, sec_pmic_resume); |
| 452 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 453 | static const struct i2c_device_id sec_pmic_id[] = { |
| 454 | { "sec_pmic", 0 }, |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 455 | { } |
| 456 | }; |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 457 | MODULE_DEVICE_TABLE(i2c, sec_pmic_id); |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 458 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 459 | static struct i2c_driver sec_pmic_driver = { |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 460 | .driver = { |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 461 | .name = "sec_pmic", |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 462 | .owner = THIS_MODULE, |
Krzysztof Kozlowski | f6d6daa | 2013-11-26 14:50:27 +0100 | [diff] [blame] | 463 | .pm = &sec_pmic_pm_ops, |
Amit Daniel Kachhap | 26aec009 | 2013-02-03 15:49:47 -0800 | [diff] [blame] | 464 | .of_match_table = of_match_ptr(sec_dt_match), |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 465 | }, |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 466 | .probe = sec_pmic_probe, |
| 467 | .remove = sec_pmic_remove, |
| 468 | .id_table = sec_pmic_id, |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 469 | }; |
| 470 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 471 | static int __init sec_pmic_init(void) |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 472 | { |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 473 | return i2c_add_driver(&sec_pmic_driver); |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 474 | } |
| 475 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 476 | subsys_initcall(sec_pmic_init); |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 477 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 478 | static void __exit sec_pmic_exit(void) |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 479 | { |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 480 | i2c_del_driver(&sec_pmic_driver); |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 481 | } |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 482 | module_exit(sec_pmic_exit); |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 483 | |
| 484 | MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>"); |
| 485 | MODULE_DESCRIPTION("Core support for the S5M MFD"); |
| 486 | MODULE_LICENSE("GPL"); |