Graeme Gregory | 27c6750 | 2011-05-02 16:19:46 -0500 | [diff] [blame] | 1 | /* |
| 2 | * tps65910.c -- TI TPS6591x |
| 3 | * |
| 4 | * Copyright 2010 Texas Instruments Inc. |
| 5 | * |
| 6 | * Author: Graeme Gregory <gg@slimlogic.co.uk> |
| 7 | * Author: Jorge Eduardo Candelaria <jedu@slimlogic.co.uk> |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify it |
| 10 | * under the terms of the GNU General Public License as published by the |
| 11 | * Free Software Foundation; either version 2 of the License, or (at your |
| 12 | * option) any later version. |
| 13 | * |
| 14 | */ |
| 15 | |
| 16 | #include <linux/module.h> |
| 17 | #include <linux/moduleparam.h> |
| 18 | #include <linux/init.h> |
Laxman Dewangan | dc9913a | 2012-02-21 18:21:34 +0530 | [diff] [blame] | 19 | #include <linux/err.h> |
Graeme Gregory | 27c6750 | 2011-05-02 16:19:46 -0500 | [diff] [blame] | 20 | #include <linux/slab.h> |
| 21 | #include <linux/i2c.h> |
Laxman Dewangan | 4aab3fa | 2012-11-13 19:33:58 +0530 | [diff] [blame] | 22 | #include <linux/interrupt.h> |
| 23 | #include <linux/irq.h> |
| 24 | #include <linux/irqdomain.h> |
Graeme Gregory | 27c6750 | 2011-05-02 16:19:46 -0500 | [diff] [blame] | 25 | #include <linux/mfd/core.h> |
Laxman Dewangan | dc9913a | 2012-02-21 18:21:34 +0530 | [diff] [blame] | 26 | #include <linux/regmap.h> |
Graeme Gregory | 27c6750 | 2011-05-02 16:19:46 -0500 | [diff] [blame] | 27 | #include <linux/mfd/tps65910.h> |
Sachin Kamat | 1fead3f | 2013-10-16 14:26:55 +0530 | [diff] [blame] | 28 | #include <linux/of.h> |
Rhyland Klein | cd4209c | 2012-05-11 11:36:26 +0200 | [diff] [blame] | 29 | #include <linux/of_device.h> |
Graeme Gregory | 27c6750 | 2011-05-02 16:19:46 -0500 | [diff] [blame] | 30 | |
Venu Byravarasu | 5863eab | 2012-09-21 16:25:36 +0530 | [diff] [blame] | 31 | static struct resource rtc_resources[] = { |
| 32 | { |
| 33 | .start = TPS65910_IRQ_RTC_ALARM, |
| 34 | .end = TPS65910_IRQ_RTC_ALARM, |
| 35 | .flags = IORESOURCE_IRQ, |
| 36 | } |
| 37 | }; |
| 38 | |
Geert Uytterhoeven | 30fe2b5 | 2013-11-18 14:33:02 +0100 | [diff] [blame] | 39 | static const struct mfd_cell tps65910s[] = { |
Graeme Gregory | 27c6750 | 2011-05-02 16:19:46 -0500 | [diff] [blame] | 40 | { |
Laxman Dewangan | 32df986 | 2012-05-11 15:07:44 +0200 | [diff] [blame] | 41 | .name = "tps65910-gpio", |
| 42 | }, |
| 43 | { |
Graeme Gregory | 27c6750 | 2011-05-02 16:19:46 -0500 | [diff] [blame] | 44 | .name = "tps65910-pmic", |
| 45 | }, |
| 46 | { |
| 47 | .name = "tps65910-rtc", |
Venu Byravarasu | 5863eab | 2012-09-21 16:25:36 +0530 | [diff] [blame] | 48 | .num_resources = ARRAY_SIZE(rtc_resources), |
| 49 | .resources = &rtc_resources[0], |
Graeme Gregory | 27c6750 | 2011-05-02 16:19:46 -0500 | [diff] [blame] | 50 | }, |
| 51 | { |
| 52 | .name = "tps65910-power", |
| 53 | }, |
| 54 | }; |
| 55 | |
| 56 | |
Laxman Dewangan | 4aab3fa | 2012-11-13 19:33:58 +0530 | [diff] [blame] | 57 | static const struct regmap_irq tps65911_irqs[] = { |
| 58 | /* INT_STS */ |
| 59 | [TPS65911_IRQ_PWRHOLD_F] = { |
| 60 | .mask = INT_MSK_PWRHOLD_F_IT_MSK_MASK, |
| 61 | .reg_offset = 0, |
| 62 | }, |
| 63 | [TPS65911_IRQ_VBAT_VMHI] = { |
| 64 | .mask = INT_MSK_VMBHI_IT_MSK_MASK, |
| 65 | .reg_offset = 0, |
| 66 | }, |
| 67 | [TPS65911_IRQ_PWRON] = { |
| 68 | .mask = INT_MSK_PWRON_IT_MSK_MASK, |
| 69 | .reg_offset = 0, |
| 70 | }, |
| 71 | [TPS65911_IRQ_PWRON_LP] = { |
| 72 | .mask = INT_MSK_PWRON_LP_IT_MSK_MASK, |
| 73 | .reg_offset = 0, |
| 74 | }, |
| 75 | [TPS65911_IRQ_PWRHOLD_R] = { |
| 76 | .mask = INT_MSK_PWRHOLD_R_IT_MSK_MASK, |
| 77 | .reg_offset = 0, |
| 78 | }, |
| 79 | [TPS65911_IRQ_HOTDIE] = { |
| 80 | .mask = INT_MSK_HOTDIE_IT_MSK_MASK, |
| 81 | .reg_offset = 0, |
| 82 | }, |
| 83 | [TPS65911_IRQ_RTC_ALARM] = { |
| 84 | .mask = INT_MSK_RTC_ALARM_IT_MSK_MASK, |
| 85 | .reg_offset = 0, |
| 86 | }, |
| 87 | [TPS65911_IRQ_RTC_PERIOD] = { |
| 88 | .mask = INT_MSK_RTC_PERIOD_IT_MSK_MASK, |
| 89 | .reg_offset = 0, |
| 90 | }, |
| 91 | |
| 92 | /* INT_STS2 */ |
| 93 | [TPS65911_IRQ_GPIO0_R] = { |
| 94 | .mask = INT_MSK2_GPIO0_R_IT_MSK_MASK, |
| 95 | .reg_offset = 1, |
| 96 | }, |
| 97 | [TPS65911_IRQ_GPIO0_F] = { |
| 98 | .mask = INT_MSK2_GPIO0_F_IT_MSK_MASK, |
| 99 | .reg_offset = 1, |
| 100 | }, |
| 101 | [TPS65911_IRQ_GPIO1_R] = { |
| 102 | .mask = INT_MSK2_GPIO1_R_IT_MSK_MASK, |
| 103 | .reg_offset = 1, |
| 104 | }, |
| 105 | [TPS65911_IRQ_GPIO1_F] = { |
| 106 | .mask = INT_MSK2_GPIO1_F_IT_MSK_MASK, |
| 107 | .reg_offset = 1, |
| 108 | }, |
| 109 | [TPS65911_IRQ_GPIO2_R] = { |
| 110 | .mask = INT_MSK2_GPIO2_R_IT_MSK_MASK, |
| 111 | .reg_offset = 1, |
| 112 | }, |
| 113 | [TPS65911_IRQ_GPIO2_F] = { |
| 114 | .mask = INT_MSK2_GPIO2_F_IT_MSK_MASK, |
| 115 | .reg_offset = 1, |
| 116 | }, |
| 117 | [TPS65911_IRQ_GPIO3_R] = { |
| 118 | .mask = INT_MSK2_GPIO3_R_IT_MSK_MASK, |
| 119 | .reg_offset = 1, |
| 120 | }, |
| 121 | [TPS65911_IRQ_GPIO3_F] = { |
| 122 | .mask = INT_MSK2_GPIO3_F_IT_MSK_MASK, |
| 123 | .reg_offset = 1, |
| 124 | }, |
| 125 | |
| 126 | /* INT_STS2 */ |
| 127 | [TPS65911_IRQ_GPIO4_R] = { |
| 128 | .mask = INT_MSK3_GPIO4_R_IT_MSK_MASK, |
| 129 | .reg_offset = 2, |
| 130 | }, |
| 131 | [TPS65911_IRQ_GPIO4_F] = { |
| 132 | .mask = INT_MSK3_GPIO4_F_IT_MSK_MASK, |
| 133 | .reg_offset = 2, |
| 134 | }, |
| 135 | [TPS65911_IRQ_GPIO5_R] = { |
| 136 | .mask = INT_MSK3_GPIO5_R_IT_MSK_MASK, |
| 137 | .reg_offset = 2, |
| 138 | }, |
| 139 | [TPS65911_IRQ_GPIO5_F] = { |
| 140 | .mask = INT_MSK3_GPIO5_F_IT_MSK_MASK, |
| 141 | .reg_offset = 2, |
| 142 | }, |
| 143 | [TPS65911_IRQ_WTCHDG] = { |
| 144 | .mask = INT_MSK3_WTCHDG_IT_MSK_MASK, |
| 145 | .reg_offset = 2, |
| 146 | }, |
| 147 | [TPS65911_IRQ_VMBCH2_H] = { |
| 148 | .mask = INT_MSK3_VMBCH2_H_IT_MSK_MASK, |
| 149 | .reg_offset = 2, |
| 150 | }, |
| 151 | [TPS65911_IRQ_VMBCH2_L] = { |
| 152 | .mask = INT_MSK3_VMBCH2_L_IT_MSK_MASK, |
| 153 | .reg_offset = 2, |
| 154 | }, |
| 155 | [TPS65911_IRQ_PWRDN] = { |
| 156 | .mask = INT_MSK3_PWRDN_IT_MSK_MASK, |
| 157 | .reg_offset = 2, |
| 158 | }, |
| 159 | }; |
| 160 | |
| 161 | static const struct regmap_irq tps65910_irqs[] = { |
| 162 | /* INT_STS */ |
| 163 | [TPS65910_IRQ_VBAT_VMBDCH] = { |
| 164 | .mask = TPS65910_INT_MSK_VMBDCH_IT_MSK_MASK, |
| 165 | .reg_offset = 0, |
| 166 | }, |
| 167 | [TPS65910_IRQ_VBAT_VMHI] = { |
| 168 | .mask = TPS65910_INT_MSK_VMBHI_IT_MSK_MASK, |
| 169 | .reg_offset = 0, |
| 170 | }, |
| 171 | [TPS65910_IRQ_PWRON] = { |
| 172 | .mask = TPS65910_INT_MSK_PWRON_IT_MSK_MASK, |
| 173 | .reg_offset = 0, |
| 174 | }, |
| 175 | [TPS65910_IRQ_PWRON_LP] = { |
| 176 | .mask = TPS65910_INT_MSK_PWRON_LP_IT_MSK_MASK, |
| 177 | .reg_offset = 0, |
| 178 | }, |
| 179 | [TPS65910_IRQ_PWRHOLD] = { |
| 180 | .mask = TPS65910_INT_MSK_PWRHOLD_IT_MSK_MASK, |
| 181 | .reg_offset = 0, |
| 182 | }, |
| 183 | [TPS65910_IRQ_HOTDIE] = { |
| 184 | .mask = TPS65910_INT_MSK_HOTDIE_IT_MSK_MASK, |
| 185 | .reg_offset = 0, |
| 186 | }, |
| 187 | [TPS65910_IRQ_RTC_ALARM] = { |
| 188 | .mask = TPS65910_INT_MSK_RTC_ALARM_IT_MSK_MASK, |
| 189 | .reg_offset = 0, |
| 190 | }, |
| 191 | [TPS65910_IRQ_RTC_PERIOD] = { |
| 192 | .mask = TPS65910_INT_MSK_RTC_PERIOD_IT_MSK_MASK, |
| 193 | .reg_offset = 0, |
| 194 | }, |
| 195 | |
| 196 | /* INT_STS2 */ |
| 197 | [TPS65910_IRQ_GPIO_R] = { |
| 198 | .mask = TPS65910_INT_MSK2_GPIO0_F_IT_MSK_MASK, |
| 199 | .reg_offset = 1, |
| 200 | }, |
| 201 | [TPS65910_IRQ_GPIO_F] = { |
| 202 | .mask = TPS65910_INT_MSK2_GPIO0_R_IT_MSK_MASK, |
| 203 | .reg_offset = 1, |
| 204 | }, |
| 205 | }; |
| 206 | |
| 207 | static struct regmap_irq_chip tps65911_irq_chip = { |
| 208 | .name = "tps65910", |
| 209 | .irqs = tps65911_irqs, |
| 210 | .num_irqs = ARRAY_SIZE(tps65911_irqs), |
| 211 | .num_regs = 3, |
| 212 | .irq_reg_stride = 2, |
| 213 | .status_base = TPS65910_INT_STS, |
| 214 | .mask_base = TPS65910_INT_MSK, |
Kim, Milo | 0582c0f | 2012-11-29 06:42:12 +0000 | [diff] [blame] | 215 | .ack_base = TPS65910_INT_STS, |
Laxman Dewangan | 4aab3fa | 2012-11-13 19:33:58 +0530 | [diff] [blame] | 216 | }; |
| 217 | |
| 218 | static struct regmap_irq_chip tps65910_irq_chip = { |
| 219 | .name = "tps65910", |
| 220 | .irqs = tps65910_irqs, |
| 221 | .num_irqs = ARRAY_SIZE(tps65910_irqs), |
| 222 | .num_regs = 2, |
| 223 | .irq_reg_stride = 2, |
| 224 | .status_base = TPS65910_INT_STS, |
| 225 | .mask_base = TPS65910_INT_MSK, |
Kim, Milo | 0582c0f | 2012-11-29 06:42:12 +0000 | [diff] [blame] | 226 | .ack_base = TPS65910_INT_STS, |
Laxman Dewangan | 4aab3fa | 2012-11-13 19:33:58 +0530 | [diff] [blame] | 227 | }; |
| 228 | |
| 229 | static int tps65910_irq_init(struct tps65910 *tps65910, int irq, |
| 230 | struct tps65910_platform_data *pdata) |
| 231 | { |
| 232 | int ret = 0; |
| 233 | static struct regmap_irq_chip *tps6591x_irqs_chip; |
| 234 | |
| 235 | if (!irq) { |
| 236 | dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n"); |
| 237 | return -EINVAL; |
| 238 | } |
| 239 | |
| 240 | if (!pdata) { |
| 241 | dev_warn(tps65910->dev, "No interrupt support, no pdata\n"); |
| 242 | return -EINVAL; |
| 243 | } |
| 244 | |
| 245 | switch (tps65910_chip_id(tps65910)) { |
| 246 | case TPS65910: |
| 247 | tps6591x_irqs_chip = &tps65910_irq_chip; |
| 248 | break; |
| 249 | case TPS65911: |
| 250 | tps6591x_irqs_chip = &tps65911_irq_chip; |
| 251 | break; |
| 252 | } |
| 253 | |
| 254 | tps65910->chip_irq = irq; |
Laxman Dewangan | 6167c5b | 2016-04-21 17:55:57 +0530 | [diff] [blame] | 255 | ret = devm_regmap_add_irq_chip(tps65910->dev, tps65910->regmap, |
| 256 | tps65910->chip_irq, |
| 257 | IRQF_ONESHOT, pdata->irq_base, |
| 258 | tps6591x_irqs_chip, &tps65910->irq_data); |
Krzysztof Kozlowski | 483e2df | 2014-03-12 16:50:44 +0100 | [diff] [blame] | 259 | if (ret < 0) { |
Laxman Dewangan | 4aab3fa | 2012-11-13 19:33:58 +0530 | [diff] [blame] | 260 | dev_warn(tps65910->dev, "Failed to add irq_chip %d\n", ret); |
Krzysztof Kozlowski | 483e2df | 2014-03-12 16:50:44 +0100 | [diff] [blame] | 261 | tps65910->chip_irq = 0; |
| 262 | } |
Laxman Dewangan | 4aab3fa | 2012-11-13 19:33:58 +0530 | [diff] [blame] | 263 | return ret; |
| 264 | } |
| 265 | |
Laxman Dewangan | dc9913a | 2012-02-21 18:21:34 +0530 | [diff] [blame] | 266 | static bool is_volatile_reg(struct device *dev, unsigned int reg) |
| 267 | { |
| 268 | struct tps65910 *tps65910 = dev_get_drvdata(dev); |
| 269 | |
| 270 | /* |
| 271 | * Caching all regulator registers. |
| 272 | * All regualator register address range is same for |
| 273 | * TPS65910 and TPS65911 |
| 274 | */ |
| 275 | if ((reg >= TPS65910_VIO) && (reg <= TPS65910_VDAC)) { |
| 276 | /* Check for non-existing register */ |
| 277 | if (tps65910_chip_id(tps65910) == TPS65910) |
| 278 | if ((reg == TPS65911_VDDCTRL_OP) || |
| 279 | (reg == TPS65911_VDDCTRL_SR)) |
| 280 | return true; |
| 281 | return false; |
| 282 | } |
| 283 | return true; |
| 284 | } |
| 285 | |
Laxman Dewangan | 39ecb03 | 2012-03-07 18:46:05 +0530 | [diff] [blame] | 286 | static const struct regmap_config tps65910_regmap_config = { |
Laxman Dewangan | dc9913a | 2012-02-21 18:21:34 +0530 | [diff] [blame] | 287 | .reg_bits = 8, |
| 288 | .val_bits = 8, |
| 289 | .volatile_reg = is_volatile_reg, |
Laxman Dewangan | 3bf6bf9 | 2012-05-09 18:40:54 +0530 | [diff] [blame] | 290 | .max_register = TPS65910_MAX_REGISTER - 1, |
Laxman Dewangan | dc9913a | 2012-02-21 18:21:34 +0530 | [diff] [blame] | 291 | .cache_type = REGCACHE_RBTREE, |
| 292 | }; |
| 293 | |
Bill Pemberton | f791be4 | 2012-11-19 13:23:04 -0500 | [diff] [blame] | 294 | static int tps65910_ck32k_init(struct tps65910 *tps65910, |
Johan Hovold | 712db99 | 2012-06-28 12:20:21 +0200 | [diff] [blame] | 295 | struct tps65910_board *pmic_pdata) |
| 296 | { |
Johan Hovold | 712db99 | 2012-06-28 12:20:21 +0200 | [diff] [blame] | 297 | int ret; |
| 298 | |
Johan Hovold | d02e83c | 2012-07-11 15:44:33 +0200 | [diff] [blame] | 299 | if (!pmic_pdata->en_ck32k_xtal) |
| 300 | return 0; |
| 301 | |
| 302 | ret = tps65910_reg_clear_bits(tps65910, TPS65910_DEVCTRL, |
Johan Hovold | 712db99 | 2012-06-28 12:20:21 +0200 | [diff] [blame] | 303 | DEVCTRL_CK32K_CTRL_MASK); |
Johan Hovold | d02e83c | 2012-07-11 15:44:33 +0200 | [diff] [blame] | 304 | if (ret < 0) { |
| 305 | dev_err(tps65910->dev, "clear ck32k_ctrl failed: %d\n", ret); |
| 306 | return ret; |
Johan Hovold | 712db99 | 2012-06-28 12:20:21 +0200 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | return 0; |
| 310 | } |
| 311 | |
Bill Pemberton | f791be4 | 2012-11-19 13:23:04 -0500 | [diff] [blame] | 312 | static int tps65910_sleepinit(struct tps65910 *tps65910, |
Laxman Dewangan | 201cf05 | 2012-04-18 12:13:51 +0200 | [diff] [blame] | 313 | struct tps65910_board *pmic_pdata) |
| 314 | { |
| 315 | struct device *dev = NULL; |
| 316 | int ret = 0; |
| 317 | |
| 318 | dev = tps65910->dev; |
| 319 | |
| 320 | if (!pmic_pdata->en_dev_slp) |
| 321 | return 0; |
| 322 | |
| 323 | /* enabling SLEEP device state */ |
Rhyland Klein | 3f7e827 | 2012-05-08 11:42:38 -0700 | [diff] [blame] | 324 | ret = tps65910_reg_set_bits(tps65910, TPS65910_DEVCTRL, |
Laxman Dewangan | 201cf05 | 2012-04-18 12:13:51 +0200 | [diff] [blame] | 325 | DEVCTRL_DEV_SLP_MASK); |
| 326 | if (ret < 0) { |
| 327 | dev_err(dev, "set dev_slp failed: %d\n", ret); |
| 328 | goto err_sleep_init; |
| 329 | } |
| 330 | |
Michał Mirosław | a9bc67d | 2017-06-14 21:04:14 +0200 | [diff] [blame^] | 331 | if (pmic_pdata->slp_keepon.therm_keepon) { |
Rhyland Klein | 3f7e827 | 2012-05-08 11:42:38 -0700 | [diff] [blame] | 332 | ret = tps65910_reg_set_bits(tps65910, |
| 333 | TPS65910_SLEEP_KEEP_RES_ON, |
Laxman Dewangan | 201cf05 | 2012-04-18 12:13:51 +0200 | [diff] [blame] | 334 | SLEEP_KEEP_RES_ON_THERM_KEEPON_MASK); |
| 335 | if (ret < 0) { |
| 336 | dev_err(dev, "set therm_keepon failed: %d\n", ret); |
| 337 | goto disable_dev_slp; |
| 338 | } |
| 339 | } |
| 340 | |
Michał Mirosław | a9bc67d | 2017-06-14 21:04:14 +0200 | [diff] [blame^] | 341 | if (pmic_pdata->slp_keepon.clkout32k_keepon) { |
Rhyland Klein | 3f7e827 | 2012-05-08 11:42:38 -0700 | [diff] [blame] | 342 | ret = tps65910_reg_set_bits(tps65910, |
| 343 | TPS65910_SLEEP_KEEP_RES_ON, |
Laxman Dewangan | 201cf05 | 2012-04-18 12:13:51 +0200 | [diff] [blame] | 344 | SLEEP_KEEP_RES_ON_CLKOUT32K_KEEPON_MASK); |
| 345 | if (ret < 0) { |
| 346 | dev_err(dev, "set clkout32k_keepon failed: %d\n", ret); |
| 347 | goto disable_dev_slp; |
| 348 | } |
| 349 | } |
| 350 | |
Michał Mirosław | a9bc67d | 2017-06-14 21:04:14 +0200 | [diff] [blame^] | 351 | if (pmic_pdata->slp_keepon.i2chs_keepon) { |
Rhyland Klein | 3f7e827 | 2012-05-08 11:42:38 -0700 | [diff] [blame] | 352 | ret = tps65910_reg_set_bits(tps65910, |
| 353 | TPS65910_SLEEP_KEEP_RES_ON, |
Laxman Dewangan | 201cf05 | 2012-04-18 12:13:51 +0200 | [diff] [blame] | 354 | SLEEP_KEEP_RES_ON_I2CHS_KEEPON_MASK); |
| 355 | if (ret < 0) { |
| 356 | dev_err(dev, "set i2chs_keepon failed: %d\n", ret); |
| 357 | goto disable_dev_slp; |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | return 0; |
| 362 | |
| 363 | disable_dev_slp: |
Rhyland Klein | 3f7e827 | 2012-05-08 11:42:38 -0700 | [diff] [blame] | 364 | tps65910_reg_clear_bits(tps65910, TPS65910_DEVCTRL, |
| 365 | DEVCTRL_DEV_SLP_MASK); |
Laxman Dewangan | 201cf05 | 2012-04-18 12:13:51 +0200 | [diff] [blame] | 366 | |
| 367 | err_sleep_init: |
| 368 | return ret; |
| 369 | } |
| 370 | |
Rhyland Klein | cd4209c | 2012-05-11 11:36:26 +0200 | [diff] [blame] | 371 | #ifdef CONFIG_OF |
Jingoo Han | c0dfbfe | 2014-05-07 17:15:48 +0900 | [diff] [blame] | 372 | static const struct of_device_id tps65910_of_match[] = { |
Rhyland Klein | cd4209c | 2012-05-11 11:36:26 +0200 | [diff] [blame] | 373 | { .compatible = "ti,tps65910", .data = (void *)TPS65910}, |
| 374 | { .compatible = "ti,tps65911", .data = (void *)TPS65911}, |
| 375 | { }, |
| 376 | }; |
| 377 | MODULE_DEVICE_TABLE(of, tps65910_of_match); |
| 378 | |
| 379 | static struct tps65910_board *tps65910_parse_dt(struct i2c_client *client, |
Lee Jones | 01a0f4a | 2014-07-02 14:34:13 +0100 | [diff] [blame] | 380 | unsigned long *chip_id) |
Rhyland Klein | cd4209c | 2012-05-11 11:36:26 +0200 | [diff] [blame] | 381 | { |
| 382 | struct device_node *np = client->dev.of_node; |
| 383 | struct tps65910_board *board_info; |
| 384 | unsigned int prop; |
| 385 | const struct of_device_id *match; |
Rhyland Klein | cd4209c | 2012-05-11 11:36:26 +0200 | [diff] [blame] | 386 | int ret = 0; |
Rhyland Klein | cd4209c | 2012-05-11 11:36:26 +0200 | [diff] [blame] | 387 | |
| 388 | match = of_match_device(tps65910_of_match, &client->dev); |
| 389 | if (!match) { |
| 390 | dev_err(&client->dev, "Failed to find matching dt id\n"); |
| 391 | return NULL; |
| 392 | } |
| 393 | |
Lee Jones | 01a0f4a | 2014-07-02 14:34:13 +0100 | [diff] [blame] | 394 | *chip_id = (unsigned long)match->data; |
Rhyland Klein | cd4209c | 2012-05-11 11:36:26 +0200 | [diff] [blame] | 395 | |
| 396 | board_info = devm_kzalloc(&client->dev, sizeof(*board_info), |
| 397 | GFP_KERNEL); |
| 398 | if (!board_info) { |
| 399 | dev_err(&client->dev, "Failed to allocate pdata\n"); |
| 400 | return NULL; |
| 401 | } |
| 402 | |
| 403 | ret = of_property_read_u32(np, "ti,vmbch-threshold", &prop); |
| 404 | if (!ret) |
| 405 | board_info->vmbch_threshold = prop; |
Rhyland Klein | cd4209c | 2012-05-11 11:36:26 +0200 | [diff] [blame] | 406 | |
| 407 | ret = of_property_read_u32(np, "ti,vmbch2-threshold", &prop); |
| 408 | if (!ret) |
| 409 | board_info->vmbch2_threshold = prop; |
Rhyland Klein | cd4209c | 2012-05-11 11:36:26 +0200 | [diff] [blame] | 410 | |
Johan Hovold | bcc1dd4 | 2012-06-28 12:20:22 +0200 | [diff] [blame] | 411 | prop = of_property_read_bool(np, "ti,en-ck32k-xtal"); |
| 412 | board_info->en_ck32k_xtal = prop; |
| 413 | |
Michał Mirosław | a9bc67d | 2017-06-14 21:04:14 +0200 | [diff] [blame^] | 414 | prop = of_property_read_bool(np, "ti,sleep-enable"); |
| 415 | board_info->en_dev_slp = prop; |
| 416 | |
| 417 | prop = of_property_read_bool(np, "ti,sleep-keep-therm"); |
| 418 | board_info->slp_keepon.therm_keepon = prop; |
| 419 | |
| 420 | prop = of_property_read_bool(np, "ti,sleep-keep-ck32k"); |
| 421 | board_info->slp_keepon.clkout32k_keepon = prop; |
| 422 | |
| 423 | prop = of_property_read_bool(np, "ti,sleep-keep-hsclk"); |
| 424 | board_info->slp_keepon.i2chs_keepon = prop; |
| 425 | |
Rhyland Klein | cd4209c | 2012-05-11 11:36:26 +0200 | [diff] [blame] | 426 | board_info->irq = client->irq; |
| 427 | board_info->irq_base = -1; |
Bill Huang | b079fa72 | 2012-08-19 18:07:56 -0700 | [diff] [blame] | 428 | board_info->pm_off = of_property_read_bool(np, |
| 429 | "ti,system-power-controller"); |
Rhyland Klein | cd4209c | 2012-05-11 11:36:26 +0200 | [diff] [blame] | 430 | |
| 431 | return board_info; |
| 432 | } |
| 433 | #else |
Samuel Ortiz | 7f65f74 | 2012-05-11 15:10:28 +0200 | [diff] [blame] | 434 | static inline |
| 435 | struct tps65910_board *tps65910_parse_dt(struct i2c_client *client, |
Lee Jones | 01a0f4a | 2014-07-02 14:34:13 +0100 | [diff] [blame] | 436 | unsigned long *chip_id) |
Rhyland Klein | cd4209c | 2012-05-11 11:36:26 +0200 | [diff] [blame] | 437 | { |
| 438 | return NULL; |
| 439 | } |
| 440 | #endif |
Laxman Dewangan | 201cf05 | 2012-04-18 12:13:51 +0200 | [diff] [blame] | 441 | |
Bill Huang | b079fa72 | 2012-08-19 18:07:56 -0700 | [diff] [blame] | 442 | static struct i2c_client *tps65910_i2c_client; |
| 443 | static void tps65910_power_off(void) |
| 444 | { |
| 445 | struct tps65910 *tps65910; |
| 446 | |
| 447 | tps65910 = dev_get_drvdata(&tps65910_i2c_client->dev); |
| 448 | |
| 449 | if (tps65910_reg_set_bits(tps65910, TPS65910_DEVCTRL, |
| 450 | DEVCTRL_PWR_OFF_MASK) < 0) |
| 451 | return; |
| 452 | |
| 453 | tps65910_reg_clear_bits(tps65910, TPS65910_DEVCTRL, |
| 454 | DEVCTRL_DEV_ON_MASK); |
| 455 | } |
| 456 | |
Bill Pemberton | f791be4 | 2012-11-19 13:23:04 -0500 | [diff] [blame] | 457 | static int tps65910_i2c_probe(struct i2c_client *i2c, |
Lee Jones | 01a0f4a | 2014-07-02 14:34:13 +0100 | [diff] [blame] | 458 | const struct i2c_device_id *id) |
Graeme Gregory | 27c6750 | 2011-05-02 16:19:46 -0500 | [diff] [blame] | 459 | { |
| 460 | struct tps65910 *tps65910; |
Graeme Gregory | 2537df7 | 2011-05-02 16:19:52 -0500 | [diff] [blame] | 461 | struct tps65910_board *pmic_plat_data; |
Laxman Dewangan | cb8d865 | 2012-05-19 02:01:41 +0530 | [diff] [blame] | 462 | struct tps65910_board *of_pmic_plat_data = NULL; |
Graeme Gregory | e3471bd | 2011-05-02 16:20:04 -0500 | [diff] [blame] | 463 | struct tps65910_platform_data *init_data; |
Lee Jones | 01a0f4a | 2014-07-02 14:34:13 +0100 | [diff] [blame] | 464 | unsigned long chip_id = id->driver_data; |
Graeme Gregory | 27c6750 | 2011-05-02 16:19:46 -0500 | [diff] [blame] | 465 | int ret = 0; |
| 466 | |
Graeme Gregory | 2537df7 | 2011-05-02 16:19:52 -0500 | [diff] [blame] | 467 | pmic_plat_data = dev_get_platdata(&i2c->dev); |
Rhyland Klein | cd4209c | 2012-05-11 11:36:26 +0200 | [diff] [blame] | 468 | |
Laxman Dewangan | cb8d865 | 2012-05-19 02:01:41 +0530 | [diff] [blame] | 469 | if (!pmic_plat_data && i2c->dev.of_node) { |
Rhyland Klein | cd4209c | 2012-05-11 11:36:26 +0200 | [diff] [blame] | 470 | pmic_plat_data = tps65910_parse_dt(i2c, &chip_id); |
Laxman Dewangan | cb8d865 | 2012-05-19 02:01:41 +0530 | [diff] [blame] | 471 | of_pmic_plat_data = pmic_plat_data; |
| 472 | } |
Rhyland Klein | cd4209c | 2012-05-11 11:36:26 +0200 | [diff] [blame] | 473 | |
Graeme Gregory | 2537df7 | 2011-05-02 16:19:52 -0500 | [diff] [blame] | 474 | if (!pmic_plat_data) |
| 475 | return -EINVAL; |
| 476 | |
Laxman Dewangan | 63fe7de | 2012-05-11 12:36:57 +0200 | [diff] [blame] | 477 | init_data = devm_kzalloc(&i2c->dev, sizeof(*init_data), GFP_KERNEL); |
Graeme Gregory | e3471bd | 2011-05-02 16:20:04 -0500 | [diff] [blame] | 478 | if (init_data == NULL) |
| 479 | return -ENOMEM; |
| 480 | |
Laxman Dewangan | 63fe7de | 2012-05-11 12:36:57 +0200 | [diff] [blame] | 481 | tps65910 = devm_kzalloc(&i2c->dev, sizeof(*tps65910), GFP_KERNEL); |
| 482 | if (tps65910 == NULL) |
Graeme Gregory | 27c6750 | 2011-05-02 16:19:46 -0500 | [diff] [blame] | 483 | return -ENOMEM; |
| 484 | |
Laxman Dewangan | cb8d865 | 2012-05-19 02:01:41 +0530 | [diff] [blame] | 485 | tps65910->of_plat_data = of_pmic_plat_data; |
Graeme Gregory | 27c6750 | 2011-05-02 16:19:46 -0500 | [diff] [blame] | 486 | i2c_set_clientdata(i2c, tps65910); |
| 487 | tps65910->dev = &i2c->dev; |
| 488 | tps65910->i2c_client = i2c; |
Rhyland Klein | cd4209c | 2012-05-11 11:36:26 +0200 | [diff] [blame] | 489 | tps65910->id = chip_id; |
Graeme Gregory | 27c6750 | 2011-05-02 16:19:46 -0500 | [diff] [blame] | 490 | |
Arnout Vandecappelle (Essensium/Mind) | be1c770 | 2014-08-22 17:30:56 +0200 | [diff] [blame] | 491 | /* Work around silicon erratum SWCZ010: the tps65910 may miss the |
| 492 | * first I2C transfer. So issue a dummy transfer before the first |
| 493 | * real transfer. |
| 494 | */ |
| 495 | i2c_master_send(i2c, "", 1); |
Laxman Dewangan | 63fe7de | 2012-05-11 12:36:57 +0200 | [diff] [blame] | 496 | tps65910->regmap = devm_regmap_init_i2c(i2c, &tps65910_regmap_config); |
Laxman Dewangan | dc9913a | 2012-02-21 18:21:34 +0530 | [diff] [blame] | 497 | if (IS_ERR(tps65910->regmap)) { |
| 498 | ret = PTR_ERR(tps65910->regmap); |
| 499 | dev_err(&i2c->dev, "regmap initialization failed: %d\n", ret); |
Laxman Dewangan | 63fe7de | 2012-05-11 12:36:57 +0200 | [diff] [blame] | 500 | return ret; |
Laxman Dewangan | dc9913a | 2012-02-21 18:21:34 +0530 | [diff] [blame] | 501 | } |
| 502 | |
Jesper Juhl | b1224cd | 2011-07-13 23:22:26 +0200 | [diff] [blame] | 503 | init_data->irq = pmic_plat_data->irq; |
Laxman Dewangan | 1773140 | 2012-01-18 20:19:16 +0530 | [diff] [blame] | 504 | init_data->irq_base = pmic_plat_data->irq_base; |
Jesper Juhl | b1224cd | 2011-07-13 23:22:26 +0200 | [diff] [blame] | 505 | |
Afzal Mohammed | 1e351a9 | 2011-12-14 16:05:35 +0530 | [diff] [blame] | 506 | tps65910_irq_init(tps65910, init_data->irq, init_data); |
Johan Hovold | d02e83c | 2012-07-11 15:44:33 +0200 | [diff] [blame] | 507 | tps65910_ck32k_init(tps65910, pmic_plat_data); |
Laxman Dewangan | 201cf05 | 2012-04-18 12:13:51 +0200 | [diff] [blame] | 508 | tps65910_sleepinit(tps65910, pmic_plat_data); |
| 509 | |
Bill Huang | b079fa72 | 2012-08-19 18:07:56 -0700 | [diff] [blame] | 510 | if (pmic_plat_data->pm_off && !pm_power_off) { |
| 511 | tps65910_i2c_client = i2c; |
| 512 | pm_power_off = tps65910_power_off; |
| 513 | } |
| 514 | |
Laxman Dewangan | f3466e7 | 2016-04-08 00:13:13 +0530 | [diff] [blame] | 515 | ret = devm_mfd_add_devices(tps65910->dev, -1, |
| 516 | tps65910s, ARRAY_SIZE(tps65910s), |
| 517 | NULL, 0, |
| 518 | regmap_irq_get_domain(tps65910->irq_data)); |
Laxman Dewangan | 10ecb80 | 2012-11-13 19:33:56 +0530 | [diff] [blame] | 519 | if (ret < 0) { |
| 520 | dev_err(&i2c->dev, "mfd_add_devices failed: %d\n", ret); |
| 521 | return ret; |
| 522 | } |
| 523 | |
Graeme Gregory | 27c6750 | 2011-05-02 16:19:46 -0500 | [diff] [blame] | 524 | return ret; |
| 525 | } |
| 526 | |
Graeme Gregory | 27c6750 | 2011-05-02 16:19:46 -0500 | [diff] [blame] | 527 | static const struct i2c_device_id tps65910_i2c_id[] = { |
Jorge Eduardo Candelaria | 7955705 | 2011-05-16 18:34:59 -0500 | [diff] [blame] | 528 | { "tps65910", TPS65910 }, |
| 529 | { "tps65911", TPS65911 }, |
Graeme Gregory | 27c6750 | 2011-05-02 16:19:46 -0500 | [diff] [blame] | 530 | { } |
| 531 | }; |
| 532 | MODULE_DEVICE_TABLE(i2c, tps65910_i2c_id); |
| 533 | |
| 534 | |
| 535 | static struct i2c_driver tps65910_i2c_driver = { |
| 536 | .driver = { |
| 537 | .name = "tps65910", |
Rhyland Klein | cd4209c | 2012-05-11 11:36:26 +0200 | [diff] [blame] | 538 | .of_match_table = of_match_ptr(tps65910_of_match), |
Graeme Gregory | 27c6750 | 2011-05-02 16:19:46 -0500 | [diff] [blame] | 539 | }, |
| 540 | .probe = tps65910_i2c_probe, |
Graeme Gregory | 27c6750 | 2011-05-02 16:19:46 -0500 | [diff] [blame] | 541 | .id_table = tps65910_i2c_id, |
| 542 | }; |
| 543 | |
| 544 | static int __init tps65910_i2c_init(void) |
| 545 | { |
| 546 | return i2c_add_driver(&tps65910_i2c_driver); |
| 547 | } |
| 548 | /* init early so consumer devices can complete system boot */ |
| 549 | subsys_initcall(tps65910_i2c_init); |
| 550 | |
| 551 | static void __exit tps65910_i2c_exit(void) |
| 552 | { |
| 553 | i2c_del_driver(&tps65910_i2c_driver); |
| 554 | } |
| 555 | module_exit(tps65910_i2c_exit); |
| 556 | |
| 557 | MODULE_AUTHOR("Graeme Gregory <gg@slimlogic.co.uk>"); |
| 558 | MODULE_AUTHOR("Jorge Eduardo Candelaria <jedu@slimlogic.co.uk>"); |
| 559 | MODULE_DESCRIPTION("TPS6591x chip family multi-function driver"); |
| 560 | MODULE_LICENSE("GPL"); |