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