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