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> |
Sachin Kamat | ce24991 | 2014-03-14 17:21:57 +0530 | [diff] [blame] | 28 | #include <linux/mfd/samsung/s2mpa01.h> |
Mark Brown | 25f311f | 2013-07-01 23:02:19 +0100 | [diff] [blame] | 29 | #include <linux/mfd/samsung/s2mps11.h> |
Chanwoo Choi | 76b9840 | 2014-11-18 17:59:40 +0900 | [diff] [blame] | 30 | #include <linux/mfd/samsung/s2mps13.h> |
Krzysztof Kozlowski | dc69196 | 2014-02-28 11:41:44 +0100 | [diff] [blame] | 31 | #include <linux/mfd/samsung/s2mps14.h> |
Chanwoo Choi | 00e2573 | 2014-06-25 16:14:45 +0900 | [diff] [blame] | 32 | #include <linux/mfd/samsung/s2mpu02.h> |
Mark Brown | 25f311f | 2013-07-01 23:02:19 +0100 | [diff] [blame] | 33 | #include <linux/mfd/samsung/s5m8763.h> |
| 34 | #include <linux/mfd/samsung/s5m8767.h> |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 35 | #include <linux/regmap.h> |
| 36 | |
Geert Uytterhoeven | 5ac9855 | 2013-11-18 14:33:06 +0100 | [diff] [blame] | 37 | static const struct mfd_cell s5m8751_devs[] = { |
Sangbeom Kim | 88a1cfd | 2012-01-20 16:09:12 +0900 | [diff] [blame] | 38 | { |
| 39 | .name = "s5m8751-pmic", |
| 40 | }, { |
| 41 | .name = "s5m-charger", |
| 42 | }, { |
| 43 | .name = "s5m8751-codec", |
| 44 | }, |
| 45 | }; |
| 46 | |
Geert Uytterhoeven | 5ac9855 | 2013-11-18 14:33:06 +0100 | [diff] [blame] | 47 | static const struct mfd_cell s5m8763_devs[] = { |
Sangbeom Kim | 88a1cfd | 2012-01-20 16:09:12 +0900 | [diff] [blame] | 48 | { |
| 49 | .name = "s5m8763-pmic", |
| 50 | }, { |
| 51 | .name = "s5m-rtc", |
| 52 | }, { |
| 53 | .name = "s5m-charger", |
| 54 | }, |
| 55 | }; |
| 56 | |
Geert Uytterhoeven | 5ac9855 | 2013-11-18 14:33:06 +0100 | [diff] [blame] | 57 | static const struct mfd_cell s5m8767_devs[] = { |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 58 | { |
| 59 | .name = "s5m8767-pmic", |
| 60 | }, { |
| 61 | .name = "s5m-rtc", |
Tushar Behera | 39fed00 | 2013-12-26 15:49:00 +0530 | [diff] [blame] | 62 | }, { |
| 63 | .name = "s5m8767-clk", |
Krzysztof Kozlowski | 53c31b3 | 2014-03-17 10:19:17 +0100 | [diff] [blame] | 64 | .of_compatible = "samsung,s5m8767-clk", |
Tushar Behera | 39fed00 | 2013-12-26 15:49:00 +0530 | [diff] [blame] | 65 | } |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 66 | }; |
| 67 | |
Geert Uytterhoeven | 5ac9855 | 2013-11-18 14:33:06 +0100 | [diff] [blame] | 68 | static const struct mfd_cell s2mps11_devs[] = { |
Sangbeom Kim | 9b6d134 | 2012-07-11 21:07:55 +0900 | [diff] [blame] | 69 | { |
| 70 | .name = "s2mps11-pmic", |
Yadwinder Singh Brar | 3134bca | 2013-07-07 17:14:21 +0530 | [diff] [blame] | 71 | }, { |
Krzysztof Kozlowski | eea2e59 | 2015-03-17 13:36:17 +0100 | [diff] [blame] | 72 | .name = "s2mps14-rtc", |
| 73 | }, { |
Yadwinder Singh Brar | 3134bca | 2013-07-07 17:14:21 +0530 | [diff] [blame] | 74 | .name = "s2mps11-clk", |
Krzysztof Kozlowski | 53c31b3 | 2014-03-17 10:19:17 +0100 | [diff] [blame] | 75 | .of_compatible = "samsung,s2mps11-clk", |
Yadwinder Singh Brar | 3134bca | 2013-07-07 17:14:21 +0530 | [diff] [blame] | 76 | } |
Sangbeom Kim | 9b6d134 | 2012-07-11 21:07:55 +0900 | [diff] [blame] | 77 | }; |
| 78 | |
Chanwoo Choi | 3bc2ee9 | 2014-11-18 17:59:39 +0900 | [diff] [blame] | 79 | static const struct mfd_cell s2mps13_devs[] = { |
| 80 | { .name = "s2mps13-pmic", }, |
| 81 | { .name = "s2mps13-rtc", }, |
| 82 | { |
| 83 | .name = "s2mps13-clk", |
| 84 | .of_compatible = "samsung,s2mps13-clk", |
| 85 | }, |
| 86 | }; |
| 87 | |
Krzysztof Kozlowski | dc69196 | 2014-02-28 11:41:44 +0100 | [diff] [blame] | 88 | static const struct mfd_cell s2mps14_devs[] = { |
| 89 | { |
| 90 | .name = "s2mps14-pmic", |
| 91 | }, { |
| 92 | .name = "s2mps14-rtc", |
| 93 | }, { |
| 94 | .name = "s2mps14-clk", |
Krzysztof Kozlowski | 53c31b3 | 2014-03-17 10:19:17 +0100 | [diff] [blame] | 95 | .of_compatible = "samsung,s2mps14-clk", |
Krzysztof Kozlowski | dc69196 | 2014-02-28 11:41:44 +0100 | [diff] [blame] | 96 | } |
| 97 | }; |
| 98 | |
Sachin Kamat | ce24991 | 2014-03-14 17:21:57 +0530 | [diff] [blame] | 99 | static const struct mfd_cell s2mpa01_devs[] = { |
| 100 | { |
| 101 | .name = "s2mpa01-pmic", |
| 102 | }, |
| 103 | }; |
| 104 | |
Chanwoo Choi | 54e8827 | 2014-06-25 16:14:44 +0900 | [diff] [blame] | 105 | static const struct mfd_cell s2mpu02_devs[] = { |
Chanwoo Choi | 54e8827 | 2014-06-25 16:14:44 +0900 | [diff] [blame] | 106 | { |
Krzysztof Kozlowski | 644a374 | 2015-10-30 16:51:21 +0900 | [diff] [blame] | 107 | .name = "s2mpu02-pmic", |
| 108 | }, |
Chanwoo Choi | 54e8827 | 2014-06-25 16:14:44 +0900 | [diff] [blame] | 109 | }; |
| 110 | |
Amit Daniel Kachhap | 26aec009 | 2013-02-03 15:49:47 -0800 | [diff] [blame] | 111 | #ifdef CONFIG_OF |
Krzysztof Kozlowski | df20b7c | 2014-05-13 12:58:46 +0200 | [diff] [blame] | 112 | static const struct of_device_id sec_dt_match[] = { |
Amit Daniel Kachhap | 26aec009 | 2013-02-03 15:49:47 -0800 | [diff] [blame] | 113 | { .compatible = "samsung,s5m8767-pmic", |
| 114 | .data = (void *)S5M8767X, |
Sachin Kamat | ce24991 | 2014-03-14 17:21:57 +0530 | [diff] [blame] | 115 | }, { |
| 116 | .compatible = "samsung,s2mps11-pmic", |
Yadwinder Singh Brar | aa32aca | 2013-06-29 18:21:20 +0530 | [diff] [blame] | 117 | .data = (void *)S2MPS11X, |
Sachin Kamat | ce24991 | 2014-03-14 17:21:57 +0530 | [diff] [blame] | 118 | }, { |
Chanwoo Choi | 3bc2ee9 | 2014-11-18 17:59:39 +0900 | [diff] [blame] | 119 | .compatible = "samsung,s2mps13-pmic", |
| 120 | .data = (void *)S2MPS13X, |
| 121 | }, { |
Sachin Kamat | ce24991 | 2014-03-14 17:21:57 +0530 | [diff] [blame] | 122 | .compatible = "samsung,s2mps14-pmic", |
Krzysztof Kozlowski | dc69196 | 2014-02-28 11:41:44 +0100 | [diff] [blame] | 123 | .data = (void *)S2MPS14X, |
Sachin Kamat | ce24991 | 2014-03-14 17:21:57 +0530 | [diff] [blame] | 124 | }, { |
| 125 | .compatible = "samsung,s2mpa01-pmic", |
| 126 | .data = (void *)S2MPA01, |
| 127 | }, { |
Chanwoo Choi | 54e8827 | 2014-06-25 16:14:44 +0900 | [diff] [blame] | 128 | .compatible = "samsung,s2mpu02-pmic", |
| 129 | .data = (void *)S2MPU02, |
| 130 | }, { |
Sachin Kamat | ce24991 | 2014-03-14 17:21:57 +0530 | [diff] [blame] | 131 | /* Sentinel */ |
Krzysztof Kozlowski | dc69196 | 2014-02-28 11:41:44 +0100 | [diff] [blame] | 132 | }, |
Amit Daniel Kachhap | 26aec009 | 2013-02-03 15:49:47 -0800 | [diff] [blame] | 133 | }; |
| 134 | #endif |
| 135 | |
Sachin Kamat | ce24991 | 2014-03-14 17:21:57 +0530 | [diff] [blame] | 136 | static bool s2mpa01_volatile(struct device *dev, unsigned int reg) |
| 137 | { |
| 138 | switch (reg) { |
| 139 | case S2MPA01_REG_INT1M: |
| 140 | case S2MPA01_REG_INT2M: |
| 141 | case S2MPA01_REG_INT3M: |
| 142 | return false; |
| 143 | default: |
| 144 | return true; |
| 145 | } |
| 146 | } |
| 147 | |
Mark Brown | 6b845ba | 2013-07-02 18:51:16 +0100 | [diff] [blame] | 148 | static bool s2mps11_volatile(struct device *dev, unsigned int reg) |
| 149 | { |
| 150 | switch (reg) { |
| 151 | case S2MPS11_REG_INT1M: |
| 152 | case S2MPS11_REG_INT2M: |
| 153 | case S2MPS11_REG_INT3M: |
| 154 | return false; |
| 155 | default: |
| 156 | return true; |
| 157 | } |
| 158 | } |
| 159 | |
Chanwoo Choi | 00e2573 | 2014-06-25 16:14:45 +0900 | [diff] [blame] | 160 | static bool s2mpu02_volatile(struct device *dev, unsigned int reg) |
| 161 | { |
| 162 | switch (reg) { |
| 163 | case S2MPU02_REG_INT1M: |
| 164 | case S2MPU02_REG_INT2M: |
| 165 | case S2MPU02_REG_INT3M: |
| 166 | return false; |
| 167 | default: |
| 168 | return true; |
| 169 | } |
| 170 | } |
| 171 | |
Mark Brown | 6b845ba | 2013-07-02 18:51:16 +0100 | [diff] [blame] | 172 | static bool s5m8763_volatile(struct device *dev, unsigned int reg) |
| 173 | { |
| 174 | switch (reg) { |
| 175 | case S5M8763_REG_IRQM1: |
| 176 | case S5M8763_REG_IRQM2: |
| 177 | case S5M8763_REG_IRQM3: |
| 178 | case S5M8763_REG_IRQM4: |
| 179 | return false; |
| 180 | default: |
| 181 | return true; |
| 182 | } |
| 183 | } |
| 184 | |
Krzysztof Kozlowski | a30fffb | 2013-11-28 09:09:43 +0100 | [diff] [blame] | 185 | static const struct regmap_config sec_regmap_config = { |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 186 | .reg_bits = 8, |
| 187 | .val_bits = 8, |
| 188 | }; |
| 189 | |
Sachin Kamat | ce24991 | 2014-03-14 17:21:57 +0530 | [diff] [blame] | 190 | static const struct regmap_config s2mpa01_regmap_config = { |
| 191 | .reg_bits = 8, |
| 192 | .val_bits = 8, |
| 193 | |
| 194 | .max_register = S2MPA01_REG_LDO_OVCB4, |
| 195 | .volatile_reg = s2mpa01_volatile, |
| 196 | .cache_type = REGCACHE_FLAT, |
| 197 | }; |
| 198 | |
Krzysztof Kozlowski | a30fffb | 2013-11-28 09:09:43 +0100 | [diff] [blame] | 199 | static const struct regmap_config s2mps11_regmap_config = { |
Mark Brown | 25f311f | 2013-07-01 23:02:19 +0100 | [diff] [blame] | 200 | .reg_bits = 8, |
| 201 | .val_bits = 8, |
| 202 | |
| 203 | .max_register = S2MPS11_REG_L38CTRL, |
Mark Brown | 6b845ba | 2013-07-02 18:51:16 +0100 | [diff] [blame] | 204 | .volatile_reg = s2mps11_volatile, |
| 205 | .cache_type = REGCACHE_FLAT, |
Mark Brown | 25f311f | 2013-07-01 23:02:19 +0100 | [diff] [blame] | 206 | }; |
| 207 | |
Chanwoo Choi | 76b9840 | 2014-11-18 17:59:40 +0900 | [diff] [blame] | 208 | static const struct regmap_config s2mps13_regmap_config = { |
| 209 | .reg_bits = 8, |
| 210 | .val_bits = 8, |
| 211 | |
| 212 | .max_register = S2MPS13_REG_LDODSCH5, |
| 213 | .volatile_reg = s2mps11_volatile, |
| 214 | .cache_type = REGCACHE_FLAT, |
| 215 | }; |
| 216 | |
Krzysztof Kozlowski | dc69196 | 2014-02-28 11:41:44 +0100 | [diff] [blame] | 217 | static const struct regmap_config s2mps14_regmap_config = { |
| 218 | .reg_bits = 8, |
| 219 | .val_bits = 8, |
| 220 | |
| 221 | .max_register = S2MPS14_REG_LDODSCH3, |
| 222 | .volatile_reg = s2mps11_volatile, |
| 223 | .cache_type = REGCACHE_FLAT, |
| 224 | }; |
| 225 | |
Chanwoo Choi | 00e2573 | 2014-06-25 16:14:45 +0900 | [diff] [blame] | 226 | static const struct regmap_config s2mpu02_regmap_config = { |
| 227 | .reg_bits = 8, |
| 228 | .val_bits = 8, |
| 229 | |
| 230 | .max_register = S2MPU02_REG_DVSDATA, |
| 231 | .volatile_reg = s2mpu02_volatile, |
| 232 | .cache_type = REGCACHE_FLAT, |
| 233 | }; |
| 234 | |
Krzysztof Kozlowski | a30fffb | 2013-11-28 09:09:43 +0100 | [diff] [blame] | 235 | static const struct regmap_config s5m8763_regmap_config = { |
Mark Brown | 25f311f | 2013-07-01 23:02:19 +0100 | [diff] [blame] | 236 | .reg_bits = 8, |
| 237 | .val_bits = 8, |
| 238 | |
| 239 | .max_register = S5M8763_REG_LBCNFG2, |
Mark Brown | 6b845ba | 2013-07-02 18:51:16 +0100 | [diff] [blame] | 240 | .volatile_reg = s5m8763_volatile, |
| 241 | .cache_type = REGCACHE_FLAT, |
Mark Brown | 25f311f | 2013-07-01 23:02:19 +0100 | [diff] [blame] | 242 | }; |
| 243 | |
Krzysztof Kozlowski | a30fffb | 2013-11-28 09:09:43 +0100 | [diff] [blame] | 244 | static const struct regmap_config s5m8767_regmap_config = { |
Mark Brown | 25f311f | 2013-07-01 23:02:19 +0100 | [diff] [blame] | 245 | .reg_bits = 8, |
| 246 | .val_bits = 8, |
| 247 | |
| 248 | .max_register = S5M8767_REG_LDO28CTRL, |
Mark Brown | 6b845ba | 2013-07-02 18:51:16 +0100 | [diff] [blame] | 249 | .volatile_reg = s2mps11_volatile, |
| 250 | .cache_type = REGCACHE_FLAT, |
Mark Brown | 25f311f | 2013-07-01 23:02:19 +0100 | [diff] [blame] | 251 | }; |
Amit Daniel Kachhap | 26aec009 | 2013-02-03 15:49:47 -0800 | [diff] [blame] | 252 | |
Krzysztof Kozlowski | c2c9f1f | 2015-10-07 09:44:39 +0900 | [diff] [blame] | 253 | static void sec_pmic_dump_rev(struct sec_pmic_dev *sec_pmic) |
| 254 | { |
| 255 | unsigned int val; |
| 256 | |
| 257 | /* For each device type, the REG_ID is always the first register */ |
| 258 | if (!regmap_read(sec_pmic->regmap_pmic, S2MPS11_REG_ID, &val)) |
| 259 | dev_dbg(sec_pmic->dev, "Revision: 0x%x\n", val); |
| 260 | } |
| 261 | |
Krzysztof Kozlowski | 8a97d42 | 2015-10-07 09:44:41 +0900 | [diff] [blame] | 262 | static void sec_pmic_configure(struct sec_pmic_dev *sec_pmic) |
| 263 | { |
| 264 | int err; |
| 265 | |
| 266 | if (sec_pmic->device_type != S2MPS13X) |
| 267 | return; |
| 268 | |
| 269 | if (sec_pmic->pdata->disable_wrstbi) { |
| 270 | /* |
| 271 | * If WRSTBI pin is pulled down this feature must be disabled |
| 272 | * because each Suspend to RAM will trigger buck voltage reset |
| 273 | * to default values. |
| 274 | */ |
| 275 | err = regmap_update_bits(sec_pmic->regmap_pmic, |
| 276 | S2MPS13_REG_WRSTBI, |
| 277 | S2MPS13_REG_WRSTBI_MASK, 0x0); |
| 278 | if (err) |
| 279 | dev_warn(sec_pmic->dev, |
| 280 | "Cannot initialize WRSTBI config: %d\n", |
| 281 | err); |
| 282 | } |
| 283 | } |
| 284 | |
Amit Daniel Kachhap | 26aec009 | 2013-02-03 15:49:47 -0800 | [diff] [blame] | 285 | #ifdef CONFIG_OF |
| 286 | /* |
| 287 | * Only the common platform data elements for s5m8767 are parsed here from the |
| 288 | * device tree. Other sub-modules of s5m8767 such as pmic, rtc , charger and |
| 289 | * others have to parse their own platform data elements from device tree. |
| 290 | * |
| 291 | * The s5m8767 platform data structure is instantiated here and the drivers for |
| 292 | * the sub-modules need not instantiate another instance while parsing their |
| 293 | * platform data. |
| 294 | */ |
| 295 | static struct sec_platform_data *sec_pmic_i2c_parse_dt_pdata( |
| 296 | struct device *dev) |
| 297 | { |
| 298 | struct sec_platform_data *pd; |
| 299 | |
| 300 | pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL); |
Krzysztof Kozlowski | 82a00c4 | 2015-02-26 10:13:51 +0100 | [diff] [blame] | 301 | if (!pd) |
Amit Daniel Kachhap | 26aec009 | 2013-02-03 15:49:47 -0800 | [diff] [blame] | 302 | return ERR_PTR(-ENOMEM); |
Amit Daniel Kachhap | 26aec009 | 2013-02-03 15:49:47 -0800 | [diff] [blame] | 303 | |
| 304 | /* |
| 305 | * ToDo: the 'wakeup' member in the platform data is more of a linux |
| 306 | * specfic information. Hence, there is no binding for that yet and |
| 307 | * not parsed here. |
| 308 | */ |
| 309 | |
Krzysztof Kozlowski | d785334 | 2015-09-14 21:12:45 +0900 | [diff] [blame] | 310 | pd->manual_poweroff = of_property_read_bool(dev->of_node, |
| 311 | "samsung,s2mps11-acokb-ground"); |
Krzysztof Kozlowski | 8a97d42 | 2015-10-07 09:44:41 +0900 | [diff] [blame] | 312 | pd->disable_wrstbi = of_property_read_bool(dev->of_node, |
| 313 | "samsung,s2mps11-wrstbi-ground"); |
Amit Daniel Kachhap | 26aec009 | 2013-02-03 15:49:47 -0800 | [diff] [blame] | 314 | return pd; |
| 315 | } |
| 316 | #else |
Mark Brown | 197bf85 | 2013-02-04 18:31:25 +0000 | [diff] [blame] | 317 | static struct sec_platform_data *sec_pmic_i2c_parse_dt_pdata( |
Amit Daniel Kachhap | 26aec009 | 2013-02-03 15:49:47 -0800 | [diff] [blame] | 318 | struct device *dev) |
| 319 | { |
Wei Yongjun | 005718c | 2013-12-07 14:02:15 +0800 | [diff] [blame] | 320 | return NULL; |
Amit Daniel Kachhap | 26aec009 | 2013-02-03 15:49:47 -0800 | [diff] [blame] | 321 | } |
| 322 | #endif |
| 323 | |
Pankaj Dubey | 8f695de | 2014-03-13 11:14:07 +0900 | [diff] [blame] | 324 | 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] | 325 | const struct i2c_device_id *id) |
| 326 | { |
| 327 | #ifdef CONFIG_OF |
| 328 | if (i2c->dev.of_node) { |
| 329 | const struct of_device_id *match; |
Lee Jones | b6c1cb4 | 2014-07-21 13:09:25 +0100 | [diff] [blame] | 330 | |
Amit Daniel Kachhap | 26aec009 | 2013-02-03 15:49:47 -0800 | [diff] [blame] | 331 | match = of_match_node(sec_dt_match, i2c->dev.of_node); |
Pankaj Dubey | 8f695de | 2014-03-13 11:14:07 +0900 | [diff] [blame] | 332 | return (unsigned long)match->data; |
Amit Daniel Kachhap | 26aec009 | 2013-02-03 15:49:47 -0800 | [diff] [blame] | 333 | } |
| 334 | #endif |
Pankaj Dubey | 8f695de | 2014-03-13 11:14:07 +0900 | [diff] [blame] | 335 | return id->driver_data; |
Amit Daniel Kachhap | 26aec009 | 2013-02-03 15:49:47 -0800 | [diff] [blame] | 336 | } |
| 337 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 338 | static int sec_pmic_probe(struct i2c_client *i2c, |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 339 | const struct i2c_device_id *id) |
| 340 | { |
Jingoo Han | 334a41c | 2013-07-30 17:10:05 +0900 | [diff] [blame] | 341 | struct sec_platform_data *pdata = dev_get_platdata(&i2c->dev); |
Krzysztof Kozlowski | e349c91 | 2014-04-14 09:40:45 +0200 | [diff] [blame] | 342 | const struct regmap_config *regmap; |
Chanwoo Choi | 54e8827 | 2014-06-25 16:14:44 +0900 | [diff] [blame] | 343 | const struct mfd_cell *sec_devs; |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 344 | struct sec_pmic_dev *sec_pmic; |
Krzysztof Kozlowski | 9549b5f | 2014-04-23 16:13:05 +0200 | [diff] [blame] | 345 | unsigned long device_type; |
Chanwoo Choi | 54e8827 | 2014-06-25 16:14:44 +0900 | [diff] [blame] | 346 | int ret, num_sec_devs; |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 347 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 348 | sec_pmic = devm_kzalloc(&i2c->dev, sizeof(struct sec_pmic_dev), |
Sangbeom Kim | 621210e | 2012-01-20 16:09:11 +0900 | [diff] [blame] | 349 | GFP_KERNEL); |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 350 | if (sec_pmic == NULL) |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 351 | return -ENOMEM; |
| 352 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 353 | i2c_set_clientdata(i2c, sec_pmic); |
| 354 | sec_pmic->dev = &i2c->dev; |
| 355 | sec_pmic->i2c = i2c; |
| 356 | sec_pmic->irq = i2c->irq; |
Krzysztof Kozlowski | 9549b5f | 2014-04-23 16:13:05 +0200 | [diff] [blame] | 357 | device_type = sec_i2c_get_driver_data(i2c, id); |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 358 | |
Amit Daniel Kachhap | 26aec009 | 2013-02-03 15:49:47 -0800 | [diff] [blame] | 359 | if (sec_pmic->dev->of_node) { |
| 360 | pdata = sec_pmic_i2c_parse_dt_pdata(sec_pmic->dev); |
| 361 | if (IS_ERR(pdata)) { |
| 362 | ret = PTR_ERR(pdata); |
| 363 | return ret; |
| 364 | } |
Krzysztof Kozlowski | 9549b5f | 2014-04-23 16:13:05 +0200 | [diff] [blame] | 365 | pdata->device_type = device_type; |
Amit Daniel Kachhap | 26aec009 | 2013-02-03 15:49:47 -0800 | [diff] [blame] | 366 | } |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 367 | if (pdata) { |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 368 | sec_pmic->device_type = pdata->device_type; |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 369 | sec_pmic->irq_base = pdata->irq_base; |
| 370 | sec_pmic->wakeup = pdata->wakeup; |
Amit Daniel Kachhap | 26aec009 | 2013-02-03 15:49:47 -0800 | [diff] [blame] | 371 | sec_pmic->pdata = pdata; |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 372 | } |
| 373 | |
Mark Brown | 25f311f | 2013-07-01 23:02:19 +0100 | [diff] [blame] | 374 | switch (sec_pmic->device_type) { |
Sachin Kamat | ce24991 | 2014-03-14 17:21:57 +0530 | [diff] [blame] | 375 | case S2MPA01: |
| 376 | regmap = &s2mpa01_regmap_config; |
| 377 | break; |
Mark Brown | 25f311f | 2013-07-01 23:02:19 +0100 | [diff] [blame] | 378 | case S2MPS11X: |
| 379 | regmap = &s2mps11_regmap_config; |
Krzysztof Kozlowski | dc69196 | 2014-02-28 11:41:44 +0100 | [diff] [blame] | 380 | break; |
Chanwoo Choi | 76b9840 | 2014-11-18 17:59:40 +0900 | [diff] [blame] | 381 | case S2MPS13X: |
| 382 | regmap = &s2mps13_regmap_config; |
| 383 | break; |
Krzysztof Kozlowski | dc69196 | 2014-02-28 11:41:44 +0100 | [diff] [blame] | 384 | case S2MPS14X: |
| 385 | regmap = &s2mps14_regmap_config; |
Mark Brown | 25f311f | 2013-07-01 23:02:19 +0100 | [diff] [blame] | 386 | break; |
| 387 | case S5M8763X: |
| 388 | regmap = &s5m8763_regmap_config; |
| 389 | break; |
| 390 | case S5M8767X: |
| 391 | regmap = &s5m8767_regmap_config; |
| 392 | break; |
Chanwoo Choi | 00e2573 | 2014-06-25 16:14:45 +0900 | [diff] [blame] | 393 | case S2MPU02: |
| 394 | regmap = &s2mpu02_regmap_config; |
| 395 | break; |
Mark Brown | 25f311f | 2013-07-01 23:02:19 +0100 | [diff] [blame] | 396 | default: |
| 397 | regmap = &sec_regmap_config; |
| 398 | break; |
| 399 | } |
| 400 | |
Krzysztof Kozlowski | 3e1e4a5 | 2013-12-12 17:12:31 -0800 | [diff] [blame] | 401 | sec_pmic->regmap_pmic = devm_regmap_init_i2c(i2c, regmap); |
| 402 | if (IS_ERR(sec_pmic->regmap_pmic)) { |
| 403 | ret = PTR_ERR(sec_pmic->regmap_pmic); |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 404 | dev_err(&i2c->dev, "Failed to allocate register map: %d\n", |
Axel Lin | 61a2af3 | 2012-02-28 14:23:55 +0800 | [diff] [blame] | 405 | ret); |
Axel Lin | 1092e1c | 2012-04-25 10:03:44 +0800 | [diff] [blame] | 406 | return ret; |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 407 | } |
| 408 | |
Jonghwan Choi | c3ebb30 | 2012-01-16 09:08:42 +0900 | [diff] [blame] | 409 | if (pdata && pdata->cfg_pmic_irq) |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 410 | pdata->cfg_pmic_irq(); |
| 411 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 412 | sec_irq_init(sec_pmic); |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 413 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 414 | pm_runtime_set_active(sec_pmic->dev); |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 415 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 416 | switch (sec_pmic->device_type) { |
Sangbeom Kim | 88a1cfd | 2012-01-20 16:09:12 +0900 | [diff] [blame] | 417 | case S5M8751X: |
Chanwoo Choi | 54e8827 | 2014-06-25 16:14:44 +0900 | [diff] [blame] | 418 | sec_devs = s5m8751_devs; |
| 419 | num_sec_devs = ARRAY_SIZE(s5m8751_devs); |
Sangbeom Kim | 88a1cfd | 2012-01-20 16:09:12 +0900 | [diff] [blame] | 420 | break; |
| 421 | case S5M8763X: |
Chanwoo Choi | 54e8827 | 2014-06-25 16:14:44 +0900 | [diff] [blame] | 422 | sec_devs = s5m8763_devs; |
| 423 | num_sec_devs = ARRAY_SIZE(s5m8763_devs); |
Sangbeom Kim | 88a1cfd | 2012-01-20 16:09:12 +0900 | [diff] [blame] | 424 | break; |
| 425 | case S5M8767X: |
Chanwoo Choi | 54e8827 | 2014-06-25 16:14:44 +0900 | [diff] [blame] | 426 | sec_devs = s5m8767_devs; |
| 427 | num_sec_devs = ARRAY_SIZE(s5m8767_devs); |
Sangbeom Kim | 88a1cfd | 2012-01-20 16:09:12 +0900 | [diff] [blame] | 428 | break; |
Sachin Kamat | ce24991 | 2014-03-14 17:21:57 +0530 | [diff] [blame] | 429 | case S2MPA01: |
Chanwoo Choi | 54e8827 | 2014-06-25 16:14:44 +0900 | [diff] [blame] | 430 | sec_devs = s2mpa01_devs; |
| 431 | num_sec_devs = ARRAY_SIZE(s2mpa01_devs); |
Sachin Kamat | ce24991 | 2014-03-14 17:21:57 +0530 | [diff] [blame] | 432 | break; |
Sangbeom Kim | 9b6d134 | 2012-07-11 21:07:55 +0900 | [diff] [blame] | 433 | case S2MPS11X: |
Chanwoo Choi | 54e8827 | 2014-06-25 16:14:44 +0900 | [diff] [blame] | 434 | sec_devs = s2mps11_devs; |
| 435 | num_sec_devs = ARRAY_SIZE(s2mps11_devs); |
Sangbeom Kim | 9b6d134 | 2012-07-11 21:07:55 +0900 | [diff] [blame] | 436 | break; |
Chanwoo Choi | 3bc2ee9 | 2014-11-18 17:59:39 +0900 | [diff] [blame] | 437 | case S2MPS13X: |
| 438 | sec_devs = s2mps13_devs; |
| 439 | num_sec_devs = ARRAY_SIZE(s2mps13_devs); |
| 440 | break; |
Krzysztof Kozlowski | dc69196 | 2014-02-28 11:41:44 +0100 | [diff] [blame] | 441 | case S2MPS14X: |
Chanwoo Choi | 54e8827 | 2014-06-25 16:14:44 +0900 | [diff] [blame] | 442 | sec_devs = s2mps14_devs; |
| 443 | num_sec_devs = ARRAY_SIZE(s2mps14_devs); |
| 444 | break; |
| 445 | case S2MPU02: |
| 446 | sec_devs = s2mpu02_devs; |
| 447 | num_sec_devs = ARRAY_SIZE(s2mpu02_devs); |
Krzysztof Kozlowski | dc69196 | 2014-02-28 11:41:44 +0100 | [diff] [blame] | 448 | break; |
Sangbeom Kim | 88a1cfd | 2012-01-20 16:09:12 +0900 | [diff] [blame] | 449 | default: |
| 450 | /* If this happens the probe function is problem */ |
| 451 | BUG(); |
| 452 | } |
Chanwoo Choi | 54e8827 | 2014-06-25 16:14:44 +0900 | [diff] [blame] | 453 | ret = mfd_add_devices(sec_pmic->dev, -1, sec_devs, num_sec_devs, NULL, |
| 454 | 0, NULL); |
Leon Romanovsky | 15447a46 | 2013-05-15 18:00:48 +0300 | [diff] [blame] | 455 | if (ret) |
Krzysztof Kozlowski | 8c66eec | 2014-03-18 13:57:50 +0100 | [diff] [blame] | 456 | goto err_mfd; |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 457 | |
Krzysztof Kozlowski | f6d6daa | 2013-11-26 14:50:27 +0100 | [diff] [blame] | 458 | device_init_wakeup(sec_pmic->dev, sec_pmic->wakeup); |
Krzysztof Kozlowski | 8a97d42 | 2015-10-07 09:44:41 +0900 | [diff] [blame] | 459 | sec_pmic_configure(sec_pmic); |
Krzysztof Kozlowski | c2c9f1f | 2015-10-07 09:44:39 +0900 | [diff] [blame] | 460 | sec_pmic_dump_rev(sec_pmic); |
Krzysztof Kozlowski | f6d6daa | 2013-11-26 14:50:27 +0100 | [diff] [blame] | 461 | |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 462 | return ret; |
| 463 | |
Krzysztof Kozlowski | 8c66eec | 2014-03-18 13:57:50 +0100 | [diff] [blame] | 464 | err_mfd: |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 465 | sec_irq_exit(sec_pmic); |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 466 | return ret; |
| 467 | } |
| 468 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 469 | static int sec_pmic_remove(struct i2c_client *i2c) |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 470 | { |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 471 | struct sec_pmic_dev *sec_pmic = i2c_get_clientdata(i2c); |
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 | mfd_remove_devices(sec_pmic->dev); |
| 474 | sec_irq_exit(sec_pmic); |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 475 | return 0; |
| 476 | } |
| 477 | |
Krzysztof Kozlowski | d785334 | 2015-09-14 21:12:45 +0900 | [diff] [blame] | 478 | static void sec_pmic_shutdown(struct i2c_client *i2c) |
| 479 | { |
| 480 | struct sec_pmic_dev *sec_pmic = i2c_get_clientdata(i2c); |
| 481 | unsigned int reg, mask; |
| 482 | |
| 483 | if (!sec_pmic->pdata->manual_poweroff) |
| 484 | return; |
| 485 | |
| 486 | switch (sec_pmic->device_type) { |
| 487 | case S2MPS11X: |
| 488 | reg = S2MPS11_REG_CTRL1; |
| 489 | mask = S2MPS11_CTRL1_PWRHOLD_MASK; |
| 490 | break; |
| 491 | default: |
| 492 | /* |
| 493 | * Currently only one board with S2MPS11 needs this, so just |
| 494 | * ignore the rest. |
| 495 | */ |
| 496 | dev_warn(sec_pmic->dev, |
| 497 | "Unsupported device %lu for manual power off\n", |
| 498 | sec_pmic->device_type); |
| 499 | return; |
| 500 | } |
| 501 | |
| 502 | regmap_update_bits(sec_pmic->regmap_pmic, reg, mask, 0); |
| 503 | } |
| 504 | |
Geert Uytterhoeven | 8321bbf | 2014-01-26 11:38:43 +0100 | [diff] [blame] | 505 | #ifdef CONFIG_PM_SLEEP |
Krzysztof Kozlowski | f6d6daa | 2013-11-26 14:50:27 +0100 | [diff] [blame] | 506 | static int sec_pmic_suspend(struct device *dev) |
| 507 | { |
| 508 | struct i2c_client *i2c = container_of(dev, struct i2c_client, dev); |
| 509 | struct sec_pmic_dev *sec_pmic = i2c_get_clientdata(i2c); |
| 510 | |
Krzysztof Kozlowski | 360d15d | 2014-04-22 16:00:25 +0200 | [diff] [blame] | 511 | if (device_may_wakeup(dev)) |
Krzysztof Kozlowski | f6d6daa | 2013-11-26 14:50:27 +0100 | [diff] [blame] | 512 | enable_irq_wake(sec_pmic->irq); |
Krzysztof Kozlowski | 360d15d | 2014-04-22 16:00:25 +0200 | [diff] [blame] | 513 | /* |
| 514 | * PMIC IRQ must be disabled during suspend for RTC alarm |
| 515 | * to work properly. |
| 516 | * When device is woken up from suspend, an |
| 517 | * interrupt occurs before resuming I2C bus controller. |
| 518 | * The interrupt is handled by regmap_irq_thread which tries |
| 519 | * to read RTC registers. This read fails (I2C is still |
| 520 | * suspended) and RTC Alarm interrupt is disabled. |
| 521 | */ |
| 522 | disable_irq(sec_pmic->irq); |
Krzysztof Kozlowski | f6d6daa | 2013-11-26 14:50:27 +0100 | [diff] [blame] | 523 | |
| 524 | return 0; |
| 525 | } |
| 526 | |
| 527 | static int sec_pmic_resume(struct device *dev) |
| 528 | { |
| 529 | struct i2c_client *i2c = container_of(dev, struct i2c_client, dev); |
| 530 | struct sec_pmic_dev *sec_pmic = i2c_get_clientdata(i2c); |
| 531 | |
Krzysztof Kozlowski | 360d15d | 2014-04-22 16:00:25 +0200 | [diff] [blame] | 532 | if (device_may_wakeup(dev)) |
Krzysztof Kozlowski | f6d6daa | 2013-11-26 14:50:27 +0100 | [diff] [blame] | 533 | disable_irq_wake(sec_pmic->irq); |
Krzysztof Kozlowski | 360d15d | 2014-04-22 16:00:25 +0200 | [diff] [blame] | 534 | enable_irq(sec_pmic->irq); |
Krzysztof Kozlowski | f6d6daa | 2013-11-26 14:50:27 +0100 | [diff] [blame] | 535 | |
| 536 | return 0; |
| 537 | } |
Geert Uytterhoeven | 8321bbf | 2014-01-26 11:38:43 +0100 | [diff] [blame] | 538 | #endif /* CONFIG_PM_SLEEP */ |
Krzysztof Kozlowski | f6d6daa | 2013-11-26 14:50:27 +0100 | [diff] [blame] | 539 | |
| 540 | static SIMPLE_DEV_PM_OPS(sec_pmic_pm_ops, sec_pmic_suspend, sec_pmic_resume); |
| 541 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 542 | static const struct i2c_device_id sec_pmic_id[] = { |
| 543 | { "sec_pmic", 0 }, |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 544 | { } |
| 545 | }; |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 546 | MODULE_DEVICE_TABLE(i2c, sec_pmic_id); |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 547 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 548 | static struct i2c_driver sec_pmic_driver = { |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 549 | .driver = { |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 550 | .name = "sec_pmic", |
Krzysztof Kozlowski | f6d6daa | 2013-11-26 14:50:27 +0100 | [diff] [blame] | 551 | .pm = &sec_pmic_pm_ops, |
Amit Daniel Kachhap | 26aec009 | 2013-02-03 15:49:47 -0800 | [diff] [blame] | 552 | .of_match_table = of_match_ptr(sec_dt_match), |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 553 | }, |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 554 | .probe = sec_pmic_probe, |
| 555 | .remove = sec_pmic_remove, |
Krzysztof Kozlowski | d785334 | 2015-09-14 21:12:45 +0900 | [diff] [blame] | 556 | .shutdown = sec_pmic_shutdown, |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 557 | .id_table = sec_pmic_id, |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 558 | }; |
| 559 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 560 | static int __init sec_pmic_init(void) |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 561 | { |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 562 | return i2c_add_driver(&sec_pmic_driver); |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 563 | } |
| 564 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 565 | subsys_initcall(sec_pmic_init); |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 566 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 567 | static void __exit sec_pmic_exit(void) |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 568 | { |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 569 | i2c_del_driver(&sec_pmic_driver); |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 570 | } |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 571 | module_exit(sec_pmic_exit); |
Sangbeom Kim | 0f5f707 | 2011-12-23 17:28:08 +0900 | [diff] [blame] | 572 | |
| 573 | MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>"); |
| 574 | MODULE_DESCRIPTION("Core support for the S5M MFD"); |
| 575 | MODULE_LICENSE("GPL"); |