Ashish Garg | 4499247 | 2017-08-07 14:36:59 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2012-2015, 2017, The Linux Foundation. All rights reserved. |
Deepa Dinamani | 2279965 | 2012-07-21 12:26:22 -0700 | [diff] [blame] | 2 | |
| 3 | * Redistribution and use in source and binary forms, with or without |
| 4 | * modification, are permitted provided that the following conditions are |
| 5 | * met: |
| 6 | * * Redistributions of source code must retain the above copyright |
| 7 | * notice, this list of conditions and the following disclaimer. |
| 8 | * * Redistributions in binary form must reproduce the above |
| 9 | * copyright notice, this list of conditions and the following |
| 10 | * disclaimer in the documentation and/or other materials provided |
| 11 | * with the distribution. |
Parth Dixit | c2e6dfe | 2015-06-19 15:57:47 +0530 | [diff] [blame] | 12 | * * Neither the name of The Linux Foundation, nor the names of its |
Deepa Dinamani | 2279965 | 2012-07-21 12:26:22 -0700 | [diff] [blame] | 13 | * contributors may be used to endorse or promote products derived |
| 14 | * from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 23 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 25 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 26 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | */ |
| 28 | |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 29 | #include <bits.h> |
Deepa Dinamani | 2279965 | 2012-07-21 12:26:22 -0700 | [diff] [blame] | 30 | #include <debug.h> |
| 31 | #include <reg.h> |
| 32 | #include <spmi.h> |
Channagoud Kadabi | 0e60b7d | 2012-11-01 22:56:08 +0530 | [diff] [blame] | 33 | #include <string.h> |
Deepa Dinamani | 2279965 | 2012-07-21 12:26:22 -0700 | [diff] [blame] | 34 | #include <pm8x41_hw.h> |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 35 | #include <pm8x41.h> |
Sridhar Parasuram | 92f8728 | 2015-02-05 09:58:18 -0800 | [diff] [blame] | 36 | #include <rpm-ipc.h> |
Channagoud Kadabi | 9089da6 | 2014-11-10 13:19:55 -0800 | [diff] [blame] | 37 | #include <regulator.h> |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 38 | #include <platform/timer.h> |
Deepa Dinamani | 2279965 | 2012-07-21 12:26:22 -0700 | [diff] [blame] | 39 | |
Channagoud Kadabi | 9089da6 | 2014-11-10 13:19:55 -0800 | [diff] [blame] | 40 | /* Enable LN BB CLK */ |
| 41 | static uint32_t ln_bb_clk[][8] = { |
| 42 | { |
| 43 | RPM_CLK_BUFFER_A_REQ, LNBB_CLK_ID, |
| 44 | KEY_SOFTWARE_ENABLE, 4, GENERIC_DISABLE, |
| 45 | RPM_KEY_PIN_CTRL_CLK_BUFFER_ENABLE_KEY, 4, RPM_CLK_BUFFER_PIN_CONTROL_ENABLE_NONE, |
| 46 | }, |
| 47 | { |
| 48 | RPM_CLK_BUFFER_A_REQ, LNBB_CLK_ID, |
| 49 | KEY_SOFTWARE_ENABLE, 4, GENERIC_ENABLE, |
| 50 | RPM_KEY_PIN_CTRL_CLK_BUFFER_ENABLE_KEY, 4, RPM_CLK_BUFFER_PIN_CONTROL_ENABLE_NONE, |
| 51 | }, |
| 52 | }; |
| 53 | |
Aparna Mallavarapu | 083766b | 2014-07-21 21:04:48 +0530 | [diff] [blame] | 54 | static uint8_t mpp_slave_id; |
| 55 | |
vijay kumar | 9ec3394 | 2014-08-08 17:25:46 +0530 | [diff] [blame] | 56 | void pmi8994_config_mpp_slave_id(uint8_t slave_id) |
Aparna Mallavarapu | 083766b | 2014-07-21 21:04:48 +0530 | [diff] [blame] | 57 | { |
| 58 | mpp_slave_id = slave_id; |
| 59 | } |
Channagoud Kadabi | d091f70 | 2013-01-07 16:17:37 -0800 | [diff] [blame] | 60 | /* SPMI helper functions */ |
| 61 | uint8_t pm8x41_reg_read(uint32_t addr) |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 62 | { |
| 63 | uint8_t val = 0; |
| 64 | struct pmic_arb_cmd cmd; |
| 65 | struct pmic_arb_param param; |
| 66 | |
| 67 | cmd.address = PERIPH_ID(addr); |
| 68 | cmd.offset = REG_OFFSET(addr); |
| 69 | cmd.slave_id = SLAVE_ID(addr); |
| 70 | cmd.priority = 0; |
| 71 | |
| 72 | param.buffer = &val; |
| 73 | param.size = 1; |
| 74 | |
| 75 | pmic_arb_read_cmd(&cmd, ¶m); |
| 76 | |
| 77 | return val; |
| 78 | } |
| 79 | |
Channagoud Kadabi | 56a6b52 | 2015-04-24 17:23:27 -0700 | [diff] [blame] | 80 | uint32_t spmi_reg_read(uint32_t slave_id, uint16_t addr, uint8_t *data, uint8_t priority) |
| 81 | { |
| 82 | struct pmic_arb_cmd cmd; |
| 83 | struct pmic_arb_param param; |
| 84 | |
| 85 | cmd.address = PERIPH_ID(addr); |
| 86 | cmd.offset = REG_OFFSET(addr); |
| 87 | cmd.slave_id = slave_id; |
| 88 | |
| 89 | cmd.priority = priority; |
| 90 | |
| 91 | param.buffer = data; |
| 92 | param.size = 1; |
| 93 | |
| 94 | return pmic_arb_read_cmd(&cmd, ¶m); |
| 95 | } |
| 96 | |
| 97 | uint32_t spmi_reg_write(uint32_t slave_id, uint16_t addr, uint8_t *data, uint8_t priority) |
| 98 | { |
| 99 | struct pmic_arb_cmd cmd; |
| 100 | struct pmic_arb_param param; |
| 101 | |
| 102 | cmd.address = PERIPH_ID(addr); |
| 103 | cmd.offset = REG_OFFSET(addr); |
| 104 | cmd.slave_id = slave_id; |
| 105 | |
| 106 | cmd.priority = priority; |
| 107 | |
| 108 | param.buffer = data; |
| 109 | param.size = 1; |
| 110 | |
| 111 | return pmic_arb_write_cmd(&cmd, ¶m); |
| 112 | } |
| 113 | |
Channagoud Kadabi | 1312b5d | 2015-01-28 23:28:47 -0800 | [diff] [blame] | 114 | /* SPMI helper function which takes slave id as the i/p */ |
| 115 | void pm8xxx_reg_write(uint8_t slave_id, uint32_t addr, uint8_t val) |
| 116 | { |
| 117 | struct pmic_arb_cmd cmd; |
| 118 | struct pmic_arb_param param; |
| 119 | |
| 120 | cmd.address = PERIPH_ID(addr); |
| 121 | cmd.offset = REG_OFFSET(addr); |
| 122 | cmd.slave_id = slave_id; |
| 123 | |
| 124 | cmd.priority = 0; |
| 125 | |
| 126 | param.buffer = &val; |
| 127 | param.size = 1; |
| 128 | |
| 129 | pmic_arb_write_cmd(&cmd, ¶m); |
| 130 | } |
| 131 | |
Channagoud Kadabi | d091f70 | 2013-01-07 16:17:37 -0800 | [diff] [blame] | 132 | void pm8x41_reg_write(uint32_t addr, uint8_t val) |
Deepa Dinamani | 2279965 | 2012-07-21 12:26:22 -0700 | [diff] [blame] | 133 | { |
| 134 | struct pmic_arb_cmd cmd; |
| 135 | struct pmic_arb_param param; |
Deepa Dinamani | 2279965 | 2012-07-21 12:26:22 -0700 | [diff] [blame] | 136 | |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 137 | cmd.address = PERIPH_ID(addr); |
| 138 | cmd.offset = REG_OFFSET(addr); |
| 139 | cmd.slave_id = SLAVE_ID(addr); |
Deepa Dinamani | 2279965 | 2012-07-21 12:26:22 -0700 | [diff] [blame] | 140 | cmd.priority = 0; |
Deepa Dinamani | 2279965 | 2012-07-21 12:26:22 -0700 | [diff] [blame] | 141 | |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 142 | param.buffer = &val; |
| 143 | param.size = 1; |
Deepa Dinamani | 2279965 | 2012-07-21 12:26:22 -0700 | [diff] [blame] | 144 | |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 145 | pmic_arb_write_cmd(&cmd, ¶m); |
| 146 | } |
Deepa Dinamani | 2279965 | 2012-07-21 12:26:22 -0700 | [diff] [blame] | 147 | |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 148 | /* Exported functions */ |
| 149 | |
| 150 | /* Set the boot done flag */ |
| 151 | void pm8x41_set_boot_done() |
| 152 | { |
| 153 | uint8_t val; |
| 154 | |
| 155 | val = REG_READ(SMBB_MISC_BOOT_DONE); |
| 156 | val |= BIT(BOOT_DONE_BIT); |
| 157 | REG_WRITE(SMBB_MISC_BOOT_DONE, val); |
| 158 | } |
| 159 | |
| 160 | /* Configure GPIO */ |
| 161 | int pm8x41_gpio_config(uint8_t gpio, struct pm8x41_gpio *config) |
| 162 | { |
| 163 | uint8_t val; |
| 164 | uint32_t gpio_base = GPIO_N_PERIPHERAL_BASE(gpio); |
| 165 | |
| 166 | /* Disable the GPIO */ |
| 167 | val = REG_READ(gpio_base + GPIO_EN_CTL); |
| 168 | val &= ~BIT(PERPH_EN_BIT); |
| 169 | REG_WRITE(gpio_base + GPIO_EN_CTL, val); |
| 170 | |
| 171 | /* Select the mode */ |
| 172 | val = config->function | (config->direction << 4); |
| 173 | REG_WRITE(gpio_base + GPIO_MODE_CTL, val); |
| 174 | |
| 175 | /* Set the right pull */ |
| 176 | val = config->pull; |
| 177 | REG_WRITE(gpio_base + GPIO_DIG_PULL_CTL, val); |
| 178 | |
| 179 | /* Select the VIN */ |
| 180 | val = config->vin_sel; |
| 181 | REG_WRITE(gpio_base + GPIO_DIG_VIN_CTL, val); |
| 182 | |
Siddhartha Agrawal | d61f81e | 2012-12-17 19:20:35 -0800 | [diff] [blame] | 183 | if (config->direction == PM_GPIO_DIR_OUT) { |
| 184 | /* Set the right dig out control */ |
| 185 | val = config->out_strength | (config->output_buffer << 4); |
| 186 | REG_WRITE(gpio_base + GPIO_DIG_OUT_CTL, val); |
| 187 | } |
| 188 | |
Ashish Garg | 4499247 | 2017-08-07 14:36:59 +0530 | [diff] [blame] | 189 | /* Output source sel and output invert */ |
| 190 | val = config->inv_int_pol << 7; |
| 191 | REG_WRITE(gpio_base + GPIO_DIG_OUT_SRC_CTL, val); |
| 192 | |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 193 | /* Enable the GPIO */ |
| 194 | val = REG_READ(gpio_base + GPIO_EN_CTL); |
| 195 | val |= BIT(PERPH_EN_BIT); |
| 196 | REG_WRITE(gpio_base + GPIO_EN_CTL, val); |
| 197 | |
Siddhartha Agrawal | d61f81e | 2012-12-17 19:20:35 -0800 | [diff] [blame] | 198 | return 0; |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | /* Reads the status of requested gpio */ |
| 202 | int pm8x41_gpio_get(uint8_t gpio, uint8_t *status) |
| 203 | { |
| 204 | uint32_t gpio_base = GPIO_N_PERIPHERAL_BASE(gpio); |
| 205 | |
| 206 | *status = REG_READ(gpio_base + GPIO_STATUS); |
| 207 | |
| 208 | /* Return the value of the GPIO pin */ |
| 209 | *status &= BIT(GPIO_STATUS_VAL_BIT); |
| 210 | |
| 211 | dprintf(SPEW, "GPIO %d status is %d\n", gpio, *status); |
| 212 | |
Siddhartha Agrawal | d61f81e | 2012-12-17 19:20:35 -0800 | [diff] [blame] | 213 | return 0; |
| 214 | } |
| 215 | |
| 216 | /* Write the output value of the requested gpio */ |
| 217 | int pm8x41_gpio_set(uint8_t gpio, uint8_t value) |
| 218 | { |
| 219 | uint32_t gpio_base = GPIO_N_PERIPHERAL_BASE(gpio); |
| 220 | uint8_t val; |
| 221 | |
| 222 | /* Set the output value of the gpio */ |
| 223 | val = REG_READ(gpio_base + GPIO_MODE_CTL); |
| 224 | val = (val & ~PM_GPIO_OUTPUT_MASK) | value; |
| 225 | REG_WRITE(gpio_base + GPIO_MODE_CTL, val); |
| 226 | |
| 227 | return 0; |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 228 | } |
| 229 | |
Kuogee Hsieh | 383a5ae | 2014-09-02 16:31:39 -0700 | [diff] [blame] | 230 | /* Configure PM and PMI GPIO with slave id */ |
| 231 | int pm8x41_gpio_config_sid(uint8_t sid, uint8_t gpio, struct pm8x41_gpio *config) |
| 232 | { |
| 233 | uint8_t val; |
| 234 | uint32_t gpio_base = GPIO_N_PERIPHERAL_BASE(gpio); |
| 235 | |
| 236 | gpio_base &= 0x0ffff; /* clear sid */ |
| 237 | gpio_base |= (sid << 16); /* add sid */ |
| 238 | |
| 239 | dprintf(SPEW, "%s: gpio=%d base=%x\n", __func__, gpio, gpio_base); |
| 240 | |
| 241 | /* Disable the GPIO */ |
| 242 | val = REG_READ(gpio_base + GPIO_EN_CTL); |
| 243 | val &= ~BIT(PERPH_EN_BIT); |
| 244 | REG_WRITE(gpio_base + GPIO_EN_CTL, val); |
| 245 | |
| 246 | /* Select the mode */ |
| 247 | val = config->function | (config->direction << 4); |
| 248 | REG_WRITE(gpio_base + GPIO_MODE_CTL, val); |
| 249 | |
| 250 | /* Set the right pull */ |
| 251 | val = config->pull; |
| 252 | REG_WRITE(gpio_base + GPIO_DIG_PULL_CTL, val); |
| 253 | |
| 254 | /* Select the VIN */ |
| 255 | val = config->vin_sel; |
| 256 | REG_WRITE(gpio_base + GPIO_DIG_VIN_CTL, val); |
| 257 | |
| 258 | if (config->direction == PM_GPIO_DIR_OUT) { |
| 259 | /* Set the right dig out control */ |
| 260 | val = config->out_strength | (config->output_buffer << 4); |
| 261 | REG_WRITE(gpio_base + GPIO_DIG_OUT_CTL, val); |
| 262 | } |
| 263 | |
| 264 | /* Enable the GPIO */ |
| 265 | val = REG_READ(gpio_base + GPIO_EN_CTL); |
| 266 | val |= BIT(PERPH_EN_BIT); |
| 267 | REG_WRITE(gpio_base + GPIO_EN_CTL, val); |
| 268 | |
| 269 | return 0; |
| 270 | } |
| 271 | |
| 272 | /* Reads the status of requested gpio */ |
| 273 | int pm8x41_gpio_get_sid(uint8_t sid, uint8_t gpio, uint8_t *status) |
| 274 | { |
| 275 | uint32_t gpio_base = GPIO_N_PERIPHERAL_BASE(gpio); |
| 276 | |
| 277 | gpio_base &= 0x0ffff; /* clear sid */ |
| 278 | gpio_base |= (sid << 16); /* add sid */ |
| 279 | |
| 280 | *status = REG_READ(gpio_base + GPIO_STATUS); |
| 281 | |
| 282 | /* Return the value of the GPIO pin */ |
| 283 | *status &= BIT(GPIO_STATUS_VAL_BIT); |
| 284 | |
| 285 | dprintf(SPEW, "GPIO %d status is %d\n", gpio, *status); |
| 286 | |
| 287 | return 0; |
| 288 | } |
| 289 | |
| 290 | /* Write the output value of the requested gpio */ |
| 291 | int pm8x41_gpio_set_sid(uint8_t sid, uint8_t gpio, uint8_t value) |
| 292 | { |
| 293 | uint32_t gpio_base = GPIO_N_PERIPHERAL_BASE(gpio); |
| 294 | uint8_t val; |
| 295 | |
| 296 | gpio_base &= 0x0ffff; /* clear sid */ |
| 297 | gpio_base |= (sid << 16); /* add sid */ |
| 298 | |
| 299 | dprintf(SPEW, "%s: gpio=%d base=%x\n", __func__, gpio, gpio_base); |
| 300 | |
| 301 | /* Set the output value of the gpio */ |
| 302 | val = REG_READ(gpio_base + GPIO_MODE_CTL); |
| 303 | val = (val & ~PM_GPIO_OUTPUT_MASK) | value; |
| 304 | REG_WRITE(gpio_base + GPIO_MODE_CTL, val); |
| 305 | |
| 306 | return 0; |
| 307 | } |
| 308 | |
Deepa Dinamani | c7f8758 | 2013-02-01 15:24:49 -0800 | [diff] [blame] | 309 | /* Prepare PON RESIN S2 reset (bite) */ |
| 310 | void pm8x41_resin_s2_reset_enable() |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 311 | { |
| 312 | uint8_t val; |
| 313 | |
| 314 | /* disable s2 reset */ |
| 315 | REG_WRITE(PON_RESIN_N_RESET_S2_CTL, 0x0); |
| 316 | |
Amol Jadi | 7ec52b4 | 2012-08-16 14:12:45 -0700 | [diff] [blame] | 317 | /* Delay needed for disable to kick in. */ |
| 318 | udelay(300); |
| 319 | |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 320 | /* configure s1 timer to 0 */ |
| 321 | REG_WRITE(PON_RESIN_N_RESET_S1_TIMER, 0x0); |
| 322 | |
| 323 | /* configure s2 timer to 2s */ |
| 324 | REG_WRITE(PON_RESIN_N_RESET_S2_TIMER, PON_RESIN_N_RESET_S2_TIMER_MAX_VALUE); |
| 325 | |
| 326 | /* configure reset type */ |
| 327 | REG_WRITE(PON_RESIN_N_RESET_S2_CTL, S2_RESET_TYPE_WARM); |
| 328 | |
| 329 | val = REG_READ(PON_RESIN_N_RESET_S2_CTL); |
| 330 | |
| 331 | /* enable s2 reset */ |
| 332 | val |= BIT(S2_RESET_EN_BIT); |
| 333 | REG_WRITE(PON_RESIN_N_RESET_S2_CTL, val); |
| 334 | } |
| 335 | |
Deepa Dinamani | c7f8758 | 2013-02-01 15:24:49 -0800 | [diff] [blame] | 336 | /* Disable PON RESIN S2 reset. (bite)*/ |
| 337 | void pm8x41_resin_s2_reset_disable() |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 338 | { |
| 339 | /* disable s2 reset */ |
| 340 | REG_WRITE(PON_RESIN_N_RESET_S2_CTL, 0x0); |
Amol Jadi | 7ec52b4 | 2012-08-16 14:12:45 -0700 | [diff] [blame] | 341 | |
| 342 | /* Delay needed for disable to kick in. */ |
| 343 | udelay(300); |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 344 | } |
| 345 | |
Deepa Dinamani | c7f8758 | 2013-02-01 15:24:49 -0800 | [diff] [blame] | 346 | /* Resin irq status for faulty pmic*/ |
Channagoud Kadabi | 36c19ea | 2013-07-05 16:28:44 -0700 | [diff] [blame] | 347 | uint32_t pm8x41_v2_resin_status() |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 348 | { |
| 349 | uint8_t rt_sts = 0; |
| 350 | |
| 351 | /* Enable S2 reset so we can detect the volume down key press */ |
Deepa Dinamani | c7f8758 | 2013-02-01 15:24:49 -0800 | [diff] [blame] | 352 | pm8x41_resin_s2_reset_enable(); |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 353 | |
| 354 | /* Delay before interrupt triggering. |
| 355 | * See PON_DEBOUNCE_CTL reg. |
| 356 | */ |
| 357 | mdelay(100); |
| 358 | |
| 359 | rt_sts = REG_READ(PON_INT_RT_STS); |
| 360 | |
| 361 | /* Must disable S2 reset otherwise PMIC will reset if key |
| 362 | * is held longer than S2 timer. |
| 363 | */ |
Deepa Dinamani | c7f8758 | 2013-02-01 15:24:49 -0800 | [diff] [blame] | 364 | pm8x41_resin_s2_reset_disable(); |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 365 | |
| 366 | return (rt_sts & BIT(RESIN_BARK_INT_BIT)); |
Deepa Dinamani | 2279965 | 2012-07-21 12:26:22 -0700 | [diff] [blame] | 367 | } |
Neeti Desai | 120b55d | 2012-08-20 17:15:56 -0700 | [diff] [blame] | 368 | |
Deepa Dinamani | c7f8758 | 2013-02-01 15:24:49 -0800 | [diff] [blame] | 369 | /* Resin pin status */ |
| 370 | uint32_t pm8x41_resin_status() |
| 371 | { |
| 372 | uint8_t rt_sts = 0; |
| 373 | |
| 374 | rt_sts = REG_READ(PON_INT_RT_STS); |
| 375 | |
| 376 | return (rt_sts & BIT(RESIN_ON_INT_BIT)); |
| 377 | } |
| 378 | |
Matthew Qin | 3aa8705 | 2014-02-21 10:32:34 +0800 | [diff] [blame] | 379 | /* Return 1 if power key is pressed */ |
| 380 | uint32_t pm8x41_get_pwrkey_is_pressed() |
| 381 | { |
| 382 | uint8_t pwr_sts = 0; |
| 383 | |
| 384 | pwr_sts = REG_READ(PON_INT_RT_STS); |
| 385 | |
| 386 | if (pwr_sts & BIT(KPDPWR_ON_INT_BIT)) |
| 387 | return 1; |
| 388 | else |
| 389 | return 0; |
| 390 | } |
| 391 | |
Channagoud Kadabi | 1312b5d | 2015-01-28 23:28:47 -0800 | [diff] [blame] | 392 | void pm8994_reset_configure(uint8_t reset_type) |
| 393 | { |
Channagoud Kadabi | 4b07aa7 | 2015-03-23 17:22:36 -0700 | [diff] [blame] | 394 | /* Slave ID of pm8994 and pmi8994 */ |
| 395 | uint8_t slave_id[] = {0, 2}; |
| 396 | uint8_t i; |
Channagoud Kadabi | 1312b5d | 2015-01-28 23:28:47 -0800 | [diff] [blame] | 397 | |
Channagoud Kadabi | 4b07aa7 | 2015-03-23 17:22:36 -0700 | [diff] [blame] | 398 | /* Reset sequence |
| 399 | 1. Disable the ps hold for pm8994 |
| 400 | 2. set reset type for both pm8994 & pmi8994 |
| 401 | 3. Enable ps hold for pm8994 to trigger the reset |
| 402 | */ |
Channagoud Kadabi | 1312b5d | 2015-01-28 23:28:47 -0800 | [diff] [blame] | 403 | /* disable PS_HOLD_RESET */ |
Channagoud Kadabi | 4b07aa7 | 2015-03-23 17:22:36 -0700 | [diff] [blame] | 404 | pm8xxx_reg_write(slave_id[0], PON_PS_HOLD_RESET_CTL2, 0x0); |
Channagoud Kadabi | 085ae31 | 2015-06-25 23:12:47 -0700 | [diff] [blame] | 405 | pm8xxx_reg_write(slave_id[1], PON_PS_HOLD_RESET_CTL2, 0x0); |
Channagoud Kadabi | 1312b5d | 2015-01-28 23:28:47 -0800 | [diff] [blame] | 406 | |
| 407 | /* Delay needed for disable to kick in. */ |
| 408 | udelay(300); |
| 409 | |
| 410 | /* configure reset type */ |
Channagoud Kadabi | 4b07aa7 | 2015-03-23 17:22:36 -0700 | [diff] [blame] | 411 | for (i = 0; i < ARRAY_SIZE(slave_id); i++) |
| 412 | pm8xxx_reg_write(slave_id[i], PON_PS_HOLD_RESET_CTL, reset_type); |
Channagoud Kadabi | 1312b5d | 2015-01-28 23:28:47 -0800 | [diff] [blame] | 413 | |
| 414 | /* enable PS_HOLD_RESET */ |
Channagoud Kadabi | 085ae31 | 2015-06-25 23:12:47 -0700 | [diff] [blame] | 415 | for (i = 0; i < ARRAY_SIZE(slave_id); i++) |
| 416 | pm8xxx_reg_write(slave_id[i], PON_PS_HOLD_RESET_CTL2, BIT(S2_RESET_EN_BIT)); |
Channagoud Kadabi | 1312b5d | 2015-01-28 23:28:47 -0800 | [diff] [blame] | 417 | } |
| 418 | |
Deepa Dinamani | 3c9865d | 2013-03-08 14:03:19 -0800 | [diff] [blame] | 419 | void pm8x41_v2_reset_configure(uint8_t reset_type) |
Neeti Desai | 120b55d | 2012-08-20 17:15:56 -0700 | [diff] [blame] | 420 | { |
| 421 | uint8_t val; |
| 422 | |
| 423 | /* disable PS_HOLD_RESET */ |
| 424 | REG_WRITE(PON_PS_HOLD_RESET_CTL, 0x0); |
| 425 | |
| 426 | /* Delay needed for disable to kick in. */ |
| 427 | udelay(300); |
| 428 | |
| 429 | /* configure reset type */ |
| 430 | REG_WRITE(PON_PS_HOLD_RESET_CTL, reset_type); |
| 431 | |
| 432 | val = REG_READ(PON_PS_HOLD_RESET_CTL); |
| 433 | |
| 434 | /* enable PS_HOLD_RESET */ |
| 435 | val |= BIT(S2_RESET_EN_BIT); |
| 436 | REG_WRITE(PON_PS_HOLD_RESET_CTL, val); |
| 437 | } |
Channagoud Kadabi | 0e60b7d | 2012-11-01 22:56:08 +0530 | [diff] [blame] | 438 | |
Deepa Dinamani | 3c9865d | 2013-03-08 14:03:19 -0800 | [diff] [blame] | 439 | void pm8x41_reset_configure(uint8_t reset_type) |
| 440 | { |
| 441 | /* disable PS_HOLD_RESET */ |
| 442 | REG_WRITE(PON_PS_HOLD_RESET_CTL2, 0x0); |
| 443 | |
| 444 | /* Delay needed for disable to kick in. */ |
| 445 | udelay(300); |
| 446 | |
| 447 | /* configure reset type */ |
| 448 | REG_WRITE(PON_PS_HOLD_RESET_CTL, reset_type); |
| 449 | |
| 450 | /* enable PS_HOLD_RESET */ |
| 451 | REG_WRITE(PON_PS_HOLD_RESET_CTL2, BIT(S2_RESET_EN_BIT)); |
| 452 | } |
| 453 | |
Channagoud Kadabi | 0e60b7d | 2012-11-01 22:56:08 +0530 | [diff] [blame] | 454 | /* |
| 455 | * LDO set voltage, takes ldo name & voltage in UV as input |
| 456 | */ |
Deepa Dinamani | e69ba61 | 2013-06-03 16:10:09 -0700 | [diff] [blame] | 457 | int pm8x41_ldo_set_voltage(struct pm8x41_ldo *ldo, uint32_t voltage) |
Channagoud Kadabi | 0e60b7d | 2012-11-01 22:56:08 +0530 | [diff] [blame] | 458 | { |
| 459 | uint32_t range = 0; |
| 460 | uint32_t step = 0; |
| 461 | uint32_t mult = 0; |
| 462 | uint32_t val = 0; |
| 463 | uint32_t vmin = 0; |
Channagoud Kadabi | 0e60b7d | 2012-11-01 22:56:08 +0530 | [diff] [blame] | 464 | |
Deepa Dinamani | e69ba61 | 2013-06-03 16:10:09 -0700 | [diff] [blame] | 465 | if (!ldo) |
| 466 | { |
| 467 | dprintf(CRITICAL, "LDO pointer is invalid: %p\n", ldo); |
Channagoud Kadabi | 0e60b7d | 2012-11-01 22:56:08 +0530 | [diff] [blame] | 468 | return 1; |
| 469 | } |
| 470 | |
| 471 | /* Program Normal power mode */ |
| 472 | val = 0x0; |
| 473 | val = (1 << LDO_NORMAL_PWR_BIT); |
| 474 | REG_WRITE((ldo->base + LDO_POWER_MODE), val); |
| 475 | |
| 476 | /* |
| 477 | * Select range, step & vmin based on input voltage & type of LDO |
| 478 | * LDO can operate in low, mid, high power mode |
| 479 | */ |
Deepa Dinamani | e69ba61 | 2013-06-03 16:10:09 -0700 | [diff] [blame] | 480 | if (ldo->type == PLDO_TYPE) |
| 481 | { |
| 482 | if (voltage < PLDO_UV_MIN) |
| 483 | { |
Channagoud Kadabi | 0e60b7d | 2012-11-01 22:56:08 +0530 | [diff] [blame] | 484 | range = 2; |
| 485 | step = PLDO_UV_STEP_LOW; |
| 486 | vmin = PLDO_UV_VMIN_LOW; |
Deepa Dinamani | e69ba61 | 2013-06-03 16:10:09 -0700 | [diff] [blame] | 487 | } |
| 488 | else if (voltage < PDLO_UV_MID) |
| 489 | { |
Channagoud Kadabi | 0e60b7d | 2012-11-01 22:56:08 +0530 | [diff] [blame] | 490 | range = 3; |
| 491 | step = PLDO_UV_STEP_MID; |
| 492 | vmin = PLDO_UV_VMIN_MID; |
Deepa Dinamani | e69ba61 | 2013-06-03 16:10:09 -0700 | [diff] [blame] | 493 | } |
| 494 | else |
| 495 | { |
Channagoud Kadabi | 0e60b7d | 2012-11-01 22:56:08 +0530 | [diff] [blame] | 496 | range = 4; |
| 497 | step = PLDO_UV_STEP_HIGH; |
| 498 | vmin = PLDO_UV_VMIN_HIGH; |
| 499 | } |
Deepa Dinamani | e69ba61 | 2013-06-03 16:10:09 -0700 | [diff] [blame] | 500 | } |
| 501 | else |
| 502 | { |
Channagoud Kadabi | 0e60b7d | 2012-11-01 22:56:08 +0530 | [diff] [blame] | 503 | range = 2; |
| 504 | step = NLDO_UV_STEP; |
| 505 | vmin = NLDO_UV_VMIN_LOW; |
| 506 | } |
| 507 | |
| 508 | mult = (voltage - vmin) / step; |
| 509 | |
| 510 | /* Set Range in voltage ctrl register */ |
| 511 | val = 0x0; |
| 512 | val = range << LDO_RANGE_SEL_BIT; |
Deepa Dinamani | e69ba61 | 2013-06-03 16:10:09 -0700 | [diff] [blame] | 513 | REG_WRITE((ldo->base + LDO_RANGE_CTRL), val); |
Channagoud Kadabi | 0e60b7d | 2012-11-01 22:56:08 +0530 | [diff] [blame] | 514 | |
| 515 | /* Set multiplier in voltage ctrl register */ |
| 516 | val = 0x0; |
| 517 | val = mult << LDO_VSET_SEL_BIT; |
Deepa Dinamani | e69ba61 | 2013-06-03 16:10:09 -0700 | [diff] [blame] | 518 | REG_WRITE((ldo->base + LDO_STEP_CTRL), val); |
Channagoud Kadabi | 0e60b7d | 2012-11-01 22:56:08 +0530 | [diff] [blame] | 519 | |
| 520 | return 0; |
| 521 | } |
| 522 | |
| 523 | /* |
| 524 | * Enable or Disable LDO |
| 525 | */ |
Deepa Dinamani | e69ba61 | 2013-06-03 16:10:09 -0700 | [diff] [blame] | 526 | int pm8x41_ldo_control(struct pm8x41_ldo *ldo, uint8_t enable) |
Channagoud Kadabi | 0e60b7d | 2012-11-01 22:56:08 +0530 | [diff] [blame] | 527 | { |
| 528 | uint32_t val = 0; |
Channagoud Kadabi | 0e60b7d | 2012-11-01 22:56:08 +0530 | [diff] [blame] | 529 | |
Deepa Dinamani | e69ba61 | 2013-06-03 16:10:09 -0700 | [diff] [blame] | 530 | if (!ldo) |
| 531 | { |
| 532 | dprintf(CRITICAL, "LDO pointer is invalid: %p\n", ldo); |
Channagoud Kadabi | 0e60b7d | 2012-11-01 22:56:08 +0530 | [diff] [blame] | 533 | return 1; |
| 534 | } |
| 535 | |
| 536 | /* Enable LDO */ |
| 537 | if (enable) |
| 538 | val = (1 << LDO_VREG_ENABLE_BIT); |
| 539 | else |
| 540 | val = (0 << LDO_VREG_ENABLE_BIT); |
| 541 | |
Deepa Dinamani | e69ba61 | 2013-06-03 16:10:09 -0700 | [diff] [blame] | 542 | REG_WRITE((ldo->base + LDO_EN_CTL_REG), val); |
Channagoud Kadabi | 0e60b7d | 2012-11-01 22:56:08 +0530 | [diff] [blame] | 543 | |
| 544 | return 0; |
| 545 | } |
Deepa Dinamani | 7564f2a | 2013-02-05 17:55:51 -0800 | [diff] [blame] | 546 | |
Kuogee Hsieh | 1183511 | 2013-10-04 15:50:36 -0700 | [diff] [blame] | 547 | /* |
| 548 | * lpg channel register write: |
| 549 | */ |
| 550 | void pm8x41_lpg_write(uint8_t chan, uint8_t off, uint8_t val) |
| 551 | { |
| 552 | uint32_t lpg_base = LPG_N_PERIPHERAL_BASE(chan); |
| 553 | |
| 554 | REG_WRITE(lpg_base + off, val); |
| 555 | } |
| 556 | |
Kuogee Hsieh | 383a5ae | 2014-09-02 16:31:39 -0700 | [diff] [blame] | 557 | /* |
| 558 | * pmi lpg channel register write with slave_id: |
| 559 | */ |
| 560 | void pm8x41_lpg_write_sid(uint8_t sid, uint8_t chan, uint8_t off, uint8_t val) |
| 561 | { |
| 562 | uint32_t lpg_base = LPG_N_PERIPHERAL_BASE(chan); |
| 563 | |
| 564 | lpg_base &= 0x0ffff; /* clear sid */ |
| 565 | lpg_base |= (sid << 16); /* add sid */ |
| 566 | |
| 567 | dprintf(SPEW, "%s: lpg=%d base=%x\n", __func__, chan, lpg_base); |
| 568 | |
| 569 | REG_WRITE(lpg_base + off, val); |
| 570 | } |
| 571 | |
Parth Dixit | 1a963d7 | 2015-10-20 01:08:57 +0530 | [diff] [blame] | 572 | uint8_t pmi8950_get_pmi_subtype() |
| 573 | { |
| 574 | uint8_t subtype; |
| 575 | spmi_reg_read((PMI8950_SLAVE_ID >> 16), REVID_REV_ID_SPARE_0, &subtype, 0); |
| 576 | return subtype; |
| 577 | } |
| 578 | |
Deepa Dinamani | 7564f2a | 2013-02-05 17:55:51 -0800 | [diff] [blame] | 579 | uint8_t pm8x41_get_pmic_rev() |
| 580 | { |
| 581 | return REG_READ(REVID_REVISION4); |
| 582 | } |
| 583 | |
sundarajan srinivasan | d0f59e8 | 2013-02-12 19:17:02 -0800 | [diff] [blame] | 584 | uint8_t pm8x41_get_pon_reason() |
| 585 | { |
| 586 | return REG_READ(PON_PON_REASON1); |
| 587 | } |
Deepa Dinamani | c342f12 | 2013-06-12 15:41:31 -0700 | [diff] [blame] | 588 | |
Parth Dixit | c2e6dfe | 2015-06-19 15:57:47 +0530 | [diff] [blame] | 589 | uint8_t pm8950_get_pon_reason() |
| 590 | { |
| 591 | uint8_t pon_reason = 0; |
| 592 | |
Parth Dixit | 746b6bb | 2015-07-09 19:29:44 +0530 | [diff] [blame] | 593 | pon_reason = REG_READ(SMBCHGL_USB_ICL_STS_2|PMI8950_SLAVE_ID); |
Parth Dixit | c2e6dfe | 2015-06-19 15:57:47 +0530 | [diff] [blame] | 594 | /* check usbin/dcin status on pmi and set the corresponding bits for pon */ |
| 595 | pon_reason = (pon_reason & (USBIN_ACTIVE_PWR_SRC|DCIN_ACTIVE_PWR_SRC)) << 3 ; |
| 596 | pon_reason |= REG_READ(PON_PON_REASON1); |
| 597 | |
| 598 | return pon_reason; |
| 599 | } |
| 600 | |
Matthew Qin | 5e90d83 | 2014-07-11 11:15:22 +0800 | [diff] [blame] | 601 | uint8_t pm8x41_get_pon_poff_reason1() |
| 602 | { |
| 603 | return REG_READ(PON_POFF_REASON1); |
| 604 | } |
| 605 | |
| 606 | uint8_t pm8x41_get_pon_poff_reason2() |
| 607 | { |
| 608 | return REG_READ(PON_POFF_REASON2); |
| 609 | } |
| 610 | |
Ajay Singh Parmar | 502ed71 | 2014-07-23 22:58:43 -0700 | [diff] [blame] | 611 | void pm8x41_enable_mvs(struct pm8x41_mvs *mvs, enum mvs_en_ctl enable) |
| 612 | { |
| 613 | ASSERT(mvs); |
| 614 | |
| 615 | REG_WRITE(mvs->base + MVS_EN_CTL, enable << MVS_EN_CTL_ENABLE_SHIFT); |
| 616 | } |
| 617 | |
Deepa Dinamani | c342f12 | 2013-06-12 15:41:31 -0700 | [diff] [blame] | 618 | void pm8x41_enable_mpp(struct pm8x41_mpp *mpp, enum mpp_en_ctl enable) |
| 619 | { |
| 620 | ASSERT(mpp); |
| 621 | |
Aparna Mallavarapu | 083766b | 2014-07-21 21:04:48 +0530 | [diff] [blame] | 622 | REG_WRITE(((mpp->base + MPP_EN_CTL) + (mpp_slave_id << 16)), enable << MPP_EN_CTL_ENABLE_SHIFT); |
Deepa Dinamani | c342f12 | 2013-06-12 15:41:31 -0700 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | void pm8x41_config_output_mpp(struct pm8x41_mpp *mpp) |
| 626 | { |
| 627 | ASSERT(mpp); |
| 628 | |
Aparna Mallavarapu | 083766b | 2014-07-21 21:04:48 +0530 | [diff] [blame] | 629 | REG_WRITE(((mpp->base + MPP_DIG_VIN_CTL) + (mpp_slave_id << 16)), mpp->vin); |
Deepa Dinamani | c342f12 | 2013-06-12 15:41:31 -0700 | [diff] [blame] | 630 | |
Aparna Mallavarapu | 083766b | 2014-07-21 21:04:48 +0530 | [diff] [blame] | 631 | REG_WRITE(((mpp->base + MPP_MODE_CTL) + (mpp_slave_id << 16)), mpp->mode | (MPP_DIGITAL_OUTPUT << MPP_MODE_CTL_MODE_SHIFT)); |
Deepa Dinamani | c342f12 | 2013-06-12 15:41:31 -0700 | [diff] [blame] | 632 | } |
Ameya Thakur | b0a62ab | 2013-06-25 13:43:10 -0700 | [diff] [blame] | 633 | |
| 634 | uint8_t pm8x41_get_is_cold_boot() |
| 635 | { |
| 636 | if (REG_READ(PON_WARMBOOT_STATUS1) || REG_READ(PON_WARMBOOT_STATUS2)) { |
| 637 | dprintf(INFO,"%s: Warm boot\n", __func__); |
| 638 | return 0; |
| 639 | } |
| 640 | dprintf(INFO,"%s: cold boot\n", __func__); |
| 641 | return 1; |
| 642 | } |
Amol Jadi | c3231ff | 2013-07-23 14:35:31 -0700 | [diff] [blame] | 643 | |
Channagoud Kadabi | 7ec7a08 | 2014-02-04 15:47:13 -0800 | [diff] [blame] | 644 | /* api to control lnbb clock */ |
| 645 | void pm8x41_lnbb_clock_ctrl(uint8_t enable) |
| 646 | { |
Channagoud Kadabi | 7ec7a08 | 2014-02-04 15:47:13 -0800 | [diff] [blame] | 647 | if (enable) |
| 648 | { |
Channagoud Kadabi | 9089da6 | 2014-11-10 13:19:55 -0800 | [diff] [blame] | 649 | rpm_clk_enable(&ln_bb_clk[GENERIC_ENABLE][0], 24); |
Channagoud Kadabi | 7ec7a08 | 2014-02-04 15:47:13 -0800 | [diff] [blame] | 650 | } |
| 651 | else |
| 652 | { |
Channagoud Kadabi | 9089da6 | 2014-11-10 13:19:55 -0800 | [diff] [blame] | 653 | rpm_clk_enable(&ln_bb_clk[GENERIC_DISABLE][0], 24); |
Channagoud Kadabi | 7ec7a08 | 2014-02-04 15:47:13 -0800 | [diff] [blame] | 654 | } |
Channagoud Kadabi | 7ec7a08 | 2014-02-04 15:47:13 -0800 | [diff] [blame] | 655 | } |
| 656 | |
Amol Jadi | c3231ff | 2013-07-23 14:35:31 -0700 | [diff] [blame] | 657 | /* api to control diff clock */ |
| 658 | void pm8x41_diff_clock_ctrl(uint8_t enable) |
| 659 | { |
| 660 | uint8_t reg; |
| 661 | |
| 662 | reg = REG_READ(DIFF_CLK1_EN_CTL); |
| 663 | |
| 664 | if (enable) |
| 665 | { |
| 666 | reg |= BIT(DIFF_CLK1_EN_BIT); |
| 667 | } |
| 668 | else |
| 669 | { |
| 670 | reg &= ~BIT(DIFF_CLK1_EN_BIT); |
| 671 | } |
| 672 | |
| 673 | REG_WRITE(DIFF_CLK1_EN_CTL, reg); |
| 674 | } |
Xiaocheng Li | 73c5712 | 2013-09-14 17:32:00 +0800 | [diff] [blame] | 675 | |
| 676 | void pm8x41_clear_pmic_watchdog(void) |
| 677 | { |
| 678 | pm8x41_reg_write(PMIC_WD_RESET_S2_CTL2, 0x0); |
| 679 | } |
Channagoud Kadabi | 1372b90 | 2013-10-28 16:20:51 -0700 | [diff] [blame] | 680 | |
| 681 | /* API to check for borken battery */ |
| 682 | int pm8xxx_is_battery_broken() |
| 683 | { |
| 684 | uint8_t trkl_default = 0; |
| 685 | uint8_t vbat_det_default = 0; |
| 686 | int batt_is_broken = 0; |
| 687 | |
| 688 | /* Store original trickle charging current setting */ |
| 689 | trkl_default = pm8x41_reg_read(PM8XXX_IBAT_ATC_A); |
| 690 | /* Store original VBAT_DET_LO setting */ |
| 691 | vbat_det_default = pm8x41_reg_read(PM8XXX_VBAT_DET); |
| 692 | |
| 693 | /*Set trickle charge current to 50mA (IBAT_ATC_A = 0x00) */ |
| 694 | pm8x41_reg_write(PM8XXX_IBAT_ATC_A, 0x00); |
| 695 | /* Set VBAT_DET_LO to 4.3V so that VBAT_DET_HI = 4.52V (VBAT_DET_LO = 0x35) */ |
| 696 | pm8x41_reg_write(PM8XXX_VBAT_DET, VBAT_DET_LO_4_30V); |
| 697 | /* Unlock SMBBP Secured Register */ |
| 698 | pm8x41_reg_write(PM8XXX_SEC_ACCESS, SEC_ACCESS); |
| 699 | /* Disable VTRKL_FAULT comp (SMBBP_CHGR_COMP_OVR0 = 0x08) */ |
| 700 | pm8x41_reg_write(PM8XXX_COMP_OVR0, OVR0_DIS_VTRKL_FAULT); |
| 701 | /* Disable VCP (SMBB_BAT_IF_VCP = 0x00) */ |
| 702 | pm8x41_reg_write(PM8XXX_VCP, 0x00); |
| 703 | /* Unlock SMBBP Secured Register */ |
| 704 | pm8x41_reg_write(PM8XXX_SEC_ACCESS, SEC_ACCESS); |
| 705 | /* Force trickle charging (SMBB_CHGR_TRKL_CHG_TEST = 0x01) */ |
| 706 | pm8x41_reg_write(PM8XXX_TRKL_CHG_TEST, CHG_TRICKLE_FORCED_ON); |
| 707 | /* Wait for vbat to rise */ |
| 708 | mdelay(12); |
| 709 | |
| 710 | /* Check Above VBAT_DET_HIGH status */ |
| 711 | if (pm8x41_reg_read(PM8XXX_VBAT_IN_TSTS) & VBAT_DET_HI_RT_STS) |
| 712 | batt_is_broken = 1; |
| 713 | else |
| 714 | batt_is_broken = 0; |
| 715 | |
| 716 | /* Unlock SMBBP Secured Register */ |
| 717 | pm8x41_reg_write(PM8XXX_SEC_ACCESS, SEC_ACCESS); |
| 718 | |
| 719 | /* Disable force trickle charging */ |
| 720 | pm8x41_reg_write(PM8XXX_TRKL_CHG_TEST, 0x00); |
| 721 | /* re-enable VCP */ |
| 722 | pm8x41_reg_write(PM8XXX_VCP, VCP_ENABLE); |
| 723 | /* restore trickle charging default current */ |
| 724 | pm8x41_reg_write(PM8XXX_IBAT_ATC_A, trkl_default); |
| 725 | /* restore VBAT_DET_LO setting to original value */ |
| 726 | pm8x41_reg_write(PM8XXX_VBAT_DET, vbat_det_default); |
| 727 | |
| 728 | return batt_is_broken; |
| 729 | } |
Channagoud Kadabi | 8ceb738 | 2014-11-14 11:25:35 -0800 | [diff] [blame] | 730 | |
| 731 | /* Detect broken battery for pmi 8994*/ |
| 732 | bool pmi8994_is_battery_broken() |
| 733 | { |
| 734 | bool batt_is_broken; |
| 735 | uint8_t fast_charge = 0; |
| 736 | |
| 737 | /* Disable the input missing ppoller */ |
| 738 | REG_WRITE(PMI8994_CHGR_TRIM_OPTIONS_7_0, REG_READ(PMI8994_CHGR_TRIM_OPTIONS_7_0) & ~INPUT_MISSING_POLLER_EN); |
| 739 | /* Disable current termination */ |
| 740 | REG_WRITE(PMI8994_CHGR_CFG2, REG_READ(PMI8994_CHGR_CFG2) & ~CURRENT_TERM_EN); |
| 741 | /* Fast-charge current to 300 mA */ |
| 742 | fast_charge = REG_READ(PMI8994_FCC_CFG); |
| 743 | REG_WRITE(PMI8994_FCC_CFG, 0x0); |
| 744 | /* Change the float voltage to 4.50V */ |
| 745 | REG_WRITE(PMI8994_FV_CFG, 0x3F); |
| 746 | |
| 747 | mdelay(5); |
| 748 | |
| 749 | if (REG_READ(PMI8994_INT_RT_STS) & BAT_TAPER_MODE_CHARGING_RT_STS) |
| 750 | batt_is_broken = true; |
| 751 | else |
| 752 | batt_is_broken = false; |
| 753 | |
| 754 | /* Set float voltage back to 4.35V */ |
| 755 | REG_WRITE(PMI8994_FV_CFG, 0x2B); |
| 756 | /* Enable current termination */ |
| 757 | REG_WRITE(PMI8994_CHGR_CFG2, REG_READ(PMI8994_CHGR_CFG2) | CURRENT_TERM_EN); |
| 758 | /* Fast-charge current back to default mA */ |
| 759 | REG_WRITE(PMI8994_FCC_CFG, fast_charge); |
| 760 | /* Re-enable the input missing poller */ |
| 761 | REG_WRITE(PMI8994_CHGR_TRIM_OPTIONS_7_0, REG_READ(PMI8994_CHGR_TRIM_OPTIONS_7_0) | INPUT_MISSING_POLLER_EN); |
| 762 | |
| 763 | return batt_is_broken; |
| 764 | } |