Xiaozhe Shi | 767fdb6 | 2013-01-10 15:09:08 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #define pr_fmt(fmt) "%s: " fmt, __func__ |
| 14 | |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/of.h> |
| 17 | #include <linux/err.h> |
| 18 | #include <linux/init.h> |
| 19 | #include <linux/slab.h> |
| 20 | #include <linux/delay.h> |
| 21 | #include <linux/mutex.h> |
| 22 | #include <linux/types.h> |
| 23 | #include <linux/hwmon.h> |
| 24 | #include <linux/module.h> |
| 25 | #include <linux/debugfs.h> |
| 26 | #include <linux/spmi.h> |
| 27 | #include <linux/of_irq.h> |
| 28 | #include <linux/wakelock.h> |
| 29 | #include <linux/interrupt.h> |
| 30 | #include <linux/completion.h> |
| 31 | #include <linux/hwmon-sysfs.h> |
| 32 | #include <linux/qpnp/qpnp-adc.h> |
| 33 | #include <linux/platform_device.h> |
| 34 | |
| 35 | /* QPNP IADC register definition */ |
Siddartha Mohanadoss | 5ace110 | 2012-08-20 23:18:10 -0700 | [diff] [blame] | 36 | #define QPNP_IADC_REVISION1 0x0 |
| 37 | #define QPNP_IADC_REVISION2 0x1 |
| 38 | #define QPNP_IADC_REVISION3 0x2 |
| 39 | #define QPNP_IADC_REVISION4 0x3 |
| 40 | #define QPNP_IADC_PERPH_TYPE 0x4 |
| 41 | #define QPNP_IADC_PERH_SUBTYPE 0x5 |
| 42 | |
| 43 | #define QPNP_IADC_SUPPORTED_REVISION2 1 |
| 44 | |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 45 | #define QPNP_STATUS1 0x8 |
| 46 | #define QPNP_STATUS1_OP_MODE 4 |
| 47 | #define QPNP_STATUS1_MULTI_MEAS_EN BIT(3) |
| 48 | #define QPNP_STATUS1_MEAS_INTERVAL_EN_STS BIT(2) |
| 49 | #define QPNP_STATUS1_REQ_STS BIT(1) |
| 50 | #define QPNP_STATUS1_EOC BIT(0) |
| 51 | #define QPNP_STATUS2 0x9 |
| 52 | #define QPNP_STATUS2_CONV_SEQ_STATE_SHIFT 4 |
| 53 | #define QPNP_STATUS2_FIFO_NOT_EMPTY_FLAG BIT(1) |
| 54 | #define QPNP_STATUS2_CONV_SEQ_TIMEOUT_STS BIT(0) |
| 55 | #define QPNP_CONV_TIMEOUT_ERR 2 |
| 56 | |
Siddartha Mohanadoss | 5ace110 | 2012-08-20 23:18:10 -0700 | [diff] [blame] | 57 | #define QPNP_IADC_MODE_CTL 0x40 |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 58 | #define QPNP_OP_MODE_SHIFT 4 |
| 59 | #define QPNP_USE_BMS_DATA BIT(4) |
| 60 | #define QPNP_VADC_SYNCH_EN BIT(2) |
| 61 | #define QPNP_OFFSET_RMV_EN BIT(1) |
| 62 | #define QPNP_ADC_TRIM_EN BIT(0) |
Siddartha Mohanadoss | 5ace110 | 2012-08-20 23:18:10 -0700 | [diff] [blame] | 63 | #define QPNP_IADC_EN_CTL1 0x46 |
| 64 | #define QPNP_IADC_ADC_EN BIT(7) |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 65 | #define QPNP_ADC_CH_SEL_CTL 0x48 |
| 66 | #define QPNP_ADC_DIG_PARAM 0x50 |
| 67 | #define QPNP_ADC_CLK_SEL_MASK 0x3 |
| 68 | #define QPNP_ADC_DEC_RATIO_SEL_MASK 0xc |
| 69 | #define QPNP_ADC_DIG_DEC_RATIO_SEL_SHIFT 2 |
| 70 | |
| 71 | #define QPNP_HW_SETTLE_DELAY 0x51 |
| 72 | #define QPNP_CONV_REQ 0x52 |
| 73 | #define QPNP_CONV_REQ_SET BIT(7) |
| 74 | #define QPNP_CONV_SEQ_CTL 0x54 |
| 75 | #define QPNP_CONV_SEQ_HOLDOFF_SHIFT 4 |
| 76 | #define QPNP_CONV_SEQ_TRIG_CTL 0x55 |
| 77 | #define QPNP_FAST_AVG_CTL 0x5a |
| 78 | |
| 79 | #define QPNP_M0_LOW_THR_LSB 0x5c |
| 80 | #define QPNP_M0_LOW_THR_MSB 0x5d |
| 81 | #define QPNP_M0_HIGH_THR_LSB 0x5e |
| 82 | #define QPNP_M0_HIGH_THR_MSB 0x5f |
| 83 | #define QPNP_M1_LOW_THR_LSB 0x69 |
| 84 | #define QPNP_M1_LOW_THR_MSB 0x6a |
| 85 | #define QPNP_M1_HIGH_THR_LSB 0x6b |
| 86 | #define QPNP_M1_HIGH_THR_MSB 0x6c |
| 87 | |
| 88 | #define QPNP_DATA0 0x60 |
| 89 | #define QPNP_DATA1 0x61 |
| 90 | #define QPNP_CONV_TIMEOUT_ERR 2 |
| 91 | |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 92 | #define QPNP_IADC_SEC_ACCESS 0xD0 |
| 93 | #define QPNP_IADC_SEC_ACCESS_DATA 0xA5 |
| 94 | #define QPNP_IADC_MSB_OFFSET 0xF2 |
| 95 | #define QPNP_IADC_LSB_OFFSET 0xF3 |
| 96 | #define QPNP_IADC_NOMINAL_RSENSE 0xF4 |
| 97 | #define QPNP_IADC_ATE_GAIN_CALIB_OFFSET 0xF5 |
Siddartha Mohanadoss | 4e64f8c | 2013-04-08 15:57:32 -0700 | [diff] [blame^] | 98 | #define QPNP_INT_TEST_VAL 0xE1 |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 99 | |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 100 | #define QPNP_IADC_ADC_CH_SEL_CTL 0x48 |
| 101 | #define QPNP_IADC_ADC_CHX_SEL_SHIFT 3 |
| 102 | |
| 103 | #define QPNP_IADC_ADC_DIG_PARAM 0x50 |
| 104 | #define QPNP_IADC_CLK_SEL_SHIFT 1 |
| 105 | #define QPNP_IADC_DEC_RATIO_SEL 3 |
| 106 | |
| 107 | #define QPNP_IADC_CONV_REQUEST 0x52 |
| 108 | #define QPNP_IADC_CONV_REQ BIT(7) |
| 109 | |
| 110 | #define QPNP_IADC_DATA0 0x60 |
| 111 | #define QPNP_IADC_DATA1 0x61 |
| 112 | |
Siddartha Mohanadoss | 5ace110 | 2012-08-20 23:18:10 -0700 | [diff] [blame] | 113 | #define QPNP_ADC_CONV_TIME_MIN 8000 |
| 114 | #define QPNP_ADC_CONV_TIME_MAX 8200 |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 115 | |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 116 | #define QPNP_ADC_GAIN_NV 17857 |
| 117 | #define QPNP_OFFSET_CALIBRATION_SHORT_CADC_LEADS_IDEAL 0 |
| 118 | #define QPNP_IADC_INTERNAL_RSENSE_N_OHMS_FACTOR 10000000 |
Siddartha Mohanadoss | 22618be | 2013-04-02 15:02:19 -0700 | [diff] [blame] | 119 | #define QPNP_IADC_NANO_VOLTS_FACTOR 1000000 |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 120 | #define QPNP_IADC_CALIB_SECONDS 300000 |
| 121 | #define QPNP_IADC_RSENSE_LSB_N_OHMS_PER_BIT 15625 |
| 122 | #define QPNP_IADC_DIE_TEMP_CALIB_OFFSET 5000 |
| 123 | |
| 124 | #define QPNP_RAW_CODE_16_BIT_MSB_MASK 0xff00 |
| 125 | #define QPNP_RAW_CODE_16_BIT_LSB_MASK 0xff |
| 126 | #define QPNP_BIT_SHIFT_8 8 |
| 127 | #define QPNP_RSENSE_MSB_SIGN_CHECK 0x80 |
Siddartha Mohanadoss | 1a0d203 | 2012-11-01 11:22:29 -0700 | [diff] [blame] | 128 | #define QPNP_ADC_COMPLETION_TIMEOUT HZ |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 129 | |
Siddartha Mohanadoss | 4e64f8c | 2013-04-08 15:57:32 -0700 | [diff] [blame^] | 130 | struct qpnp_iadc_comp { |
| 131 | bool ext_rsense; |
| 132 | u8 id; |
| 133 | u8 sys_gain; |
| 134 | u8 revision; |
| 135 | }; |
| 136 | |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 137 | struct qpnp_iadc_drv { |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 138 | struct qpnp_adc_drv *adc; |
| 139 | int32_t rsense; |
Siddartha Mohanadoss | e70010b | 2013-04-04 14:51:41 -0700 | [diff] [blame] | 140 | bool external_rsense; |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 141 | struct device *iadc_hwmon; |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 142 | bool iadc_initialized; |
Siddartha Mohanadoss | 4e64f8c | 2013-04-08 15:57:32 -0700 | [diff] [blame^] | 143 | int64_t die_temp; |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 144 | struct delayed_work iadc_work; |
Siddartha Mohanadoss | a32ea2a | 2013-02-12 09:58:31 -0800 | [diff] [blame] | 145 | struct mutex iadc_vadc_lock; |
| 146 | bool iadc_mode_sel; |
Siddartha Mohanadoss | 4e64f8c | 2013-04-08 15:57:32 -0700 | [diff] [blame^] | 147 | struct qpnp_iadc_comp iadc_comp; |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 148 | struct sensor_device_attribute sens_attr[0]; |
| 149 | }; |
| 150 | |
| 151 | struct qpnp_iadc_drv *qpnp_iadc; |
| 152 | |
| 153 | static int32_t qpnp_iadc_read_reg(uint32_t reg, u8 *data) |
| 154 | { |
| 155 | struct qpnp_iadc_drv *iadc = qpnp_iadc; |
| 156 | int rc; |
| 157 | |
| 158 | rc = spmi_ext_register_readl(iadc->adc->spmi->ctrl, iadc->adc->slave, |
Siddartha Mohanadoss | ae1da73 | 2012-08-08 16:39:02 -0700 | [diff] [blame] | 159 | (iadc->adc->offset + reg), data, 1); |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 160 | if (rc < 0) { |
| 161 | pr_err("qpnp iadc read reg %d failed with %d\n", reg, rc); |
| 162 | return rc; |
| 163 | } |
| 164 | |
| 165 | return 0; |
| 166 | } |
| 167 | |
| 168 | static int32_t qpnp_iadc_write_reg(uint32_t reg, u8 data) |
| 169 | { |
| 170 | struct qpnp_iadc_drv *iadc = qpnp_iadc; |
| 171 | int rc; |
| 172 | u8 *buf; |
| 173 | |
| 174 | buf = &data; |
| 175 | rc = spmi_ext_register_writel(iadc->adc->spmi->ctrl, iadc->adc->slave, |
Siddartha Mohanadoss | ae1da73 | 2012-08-08 16:39:02 -0700 | [diff] [blame] | 176 | (iadc->adc->offset + reg), buf, 1); |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 177 | if (rc < 0) { |
| 178 | pr_err("qpnp iadc write reg %d failed with %d\n", reg, rc); |
| 179 | return rc; |
| 180 | } |
| 181 | |
| 182 | return 0; |
| 183 | } |
| 184 | |
Siddartha Mohanadoss | e236359 | 2012-12-14 18:59:01 -0800 | [diff] [blame] | 185 | static void trigger_iadc_completion(struct work_struct *work) |
| 186 | { |
| 187 | struct qpnp_iadc_drv *iadc = qpnp_iadc; |
| 188 | |
Siddartha Mohanadoss | b60f646 | 2012-11-20 18:06:51 -0800 | [diff] [blame] | 189 | if (!iadc || !iadc->iadc_initialized) |
| 190 | return; |
| 191 | |
Siddartha Mohanadoss | e236359 | 2012-12-14 18:59:01 -0800 | [diff] [blame] | 192 | complete(&iadc->adc->adc_rslt_completion); |
| 193 | |
| 194 | return; |
| 195 | } |
| 196 | DECLARE_WORK(trigger_iadc_completion_work, trigger_iadc_completion); |
| 197 | |
| 198 | static irqreturn_t qpnp_iadc_isr(int irq, void *dev_id) |
| 199 | { |
| 200 | schedule_work(&trigger_iadc_completion_work); |
| 201 | |
| 202 | return IRQ_HANDLED; |
| 203 | } |
| 204 | |
| 205 | static int32_t qpnp_iadc_enable(bool state) |
| 206 | { |
| 207 | int rc = 0; |
| 208 | u8 data = 0; |
| 209 | |
| 210 | data = QPNP_IADC_ADC_EN; |
| 211 | if (state) { |
| 212 | rc = qpnp_iadc_write_reg(QPNP_IADC_EN_CTL1, |
| 213 | data); |
| 214 | if (rc < 0) { |
| 215 | pr_err("IADC enable failed\n"); |
| 216 | return rc; |
| 217 | } |
| 218 | } else { |
| 219 | rc = qpnp_iadc_write_reg(QPNP_IADC_EN_CTL1, |
| 220 | (~data & QPNP_IADC_ADC_EN)); |
| 221 | if (rc < 0) { |
| 222 | pr_err("IADC disable failed\n"); |
| 223 | return rc; |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | return 0; |
| 228 | } |
| 229 | |
Siddartha Mohanadoss | d3a3c95 | 2012-12-10 16:55:19 -0800 | [diff] [blame] | 230 | static int32_t qpnp_iadc_status_debug(void) |
| 231 | { |
| 232 | int rc = 0; |
| 233 | u8 mode = 0, status1 = 0, chan = 0, dig = 0, en = 0; |
| 234 | |
| 235 | rc = qpnp_iadc_read_reg(QPNP_IADC_MODE_CTL, &mode); |
| 236 | if (rc < 0) { |
| 237 | pr_err("mode ctl register read failed with %d\n", rc); |
| 238 | return rc; |
| 239 | } |
| 240 | |
| 241 | rc = qpnp_iadc_read_reg(QPNP_ADC_DIG_PARAM, &dig); |
| 242 | if (rc < 0) { |
| 243 | pr_err("digital param read failed with %d\n", rc); |
| 244 | return rc; |
| 245 | } |
| 246 | |
| 247 | rc = qpnp_iadc_read_reg(QPNP_IADC_ADC_CH_SEL_CTL, &chan); |
| 248 | if (rc < 0) { |
| 249 | pr_err("channel read failed with %d\n", rc); |
| 250 | return rc; |
| 251 | } |
| 252 | |
| 253 | rc = qpnp_iadc_read_reg(QPNP_STATUS1, &status1); |
| 254 | if (rc < 0) { |
| 255 | pr_err("status1 read failed with %d\n", rc); |
| 256 | return rc; |
| 257 | } |
| 258 | |
| 259 | rc = qpnp_iadc_read_reg(QPNP_IADC_EN_CTL1, &en); |
| 260 | if (rc < 0) { |
| 261 | pr_err("en read failed with %d\n", rc); |
| 262 | return rc; |
| 263 | } |
| 264 | |
Siddartha Mohanadoss | 73ae69b | 2013-04-03 17:34:03 -0700 | [diff] [blame] | 265 | pr_debug("EOC not set with status:%x, dig:%x, ch:%x, mode:%x, en:%x\n", |
Siddartha Mohanadoss | d3a3c95 | 2012-12-10 16:55:19 -0800 | [diff] [blame] | 266 | status1, dig, chan, mode, en); |
| 267 | |
Siddartha Mohanadoss | e236359 | 2012-12-14 18:59:01 -0800 | [diff] [blame] | 268 | rc = qpnp_iadc_enable(false); |
| 269 | if (rc < 0) { |
| 270 | pr_err("IADC disable failed with %d\n", rc); |
| 271 | return rc; |
Siddartha Mohanadoss | 5ace110 | 2012-08-20 23:18:10 -0700 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | return 0; |
| 275 | } |
| 276 | |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 277 | static int32_t qpnp_iadc_read_conversion_result(uint16_t *data) |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 278 | { |
| 279 | uint8_t rslt_lsb, rslt_msb; |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 280 | uint16_t rslt; |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 281 | int32_t rc; |
| 282 | |
| 283 | rc = qpnp_iadc_read_reg(QPNP_IADC_DATA0, &rslt_lsb); |
| 284 | if (rc < 0) { |
| 285 | pr_err("qpnp adc result read failed with %d\n", rc); |
| 286 | return rc; |
| 287 | } |
| 288 | |
| 289 | rc = qpnp_iadc_read_reg(QPNP_IADC_DATA1, &rslt_msb); |
| 290 | if (rc < 0) { |
| 291 | pr_err("qpnp adc result read failed with %d\n", rc); |
| 292 | return rc; |
| 293 | } |
| 294 | |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 295 | rslt = (rslt_msb << 8) | rslt_lsb; |
| 296 | *data = rslt; |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 297 | |
Siddartha Mohanadoss | 5ace110 | 2012-08-20 23:18:10 -0700 | [diff] [blame] | 298 | rc = qpnp_iadc_enable(false); |
| 299 | if (rc) |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 300 | return rc; |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 301 | |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 302 | return 0; |
| 303 | } |
| 304 | |
Siddartha Mohanadoss | 4e64f8c | 2013-04-08 15:57:32 -0700 | [diff] [blame^] | 305 | static int32_t qpnp_iadc_comp(int64_t *result, struct qpnp_iadc_comp comp, |
| 306 | int64_t die_temp) |
| 307 | { |
| 308 | int64_t temp_var = 0, sign_coeff = 0, sys_gain_coeff = 0; |
| 309 | |
| 310 | *result = *result * 1000000; |
| 311 | |
| 312 | if (comp.revision == QPNP_IADC_VER_3_1) { |
| 313 | /* revision 3.1 */ |
| 314 | if (comp.sys_gain > 127) |
| 315 | sys_gain_coeff = -QPNP_COEFF_6 * (comp.sys_gain - 128); |
| 316 | else |
| 317 | sys_gain_coeff = QPNP_COEFF_6 * comp.sys_gain; |
| 318 | } |
| 319 | |
| 320 | comp.id = 0; |
| 321 | if (!comp.ext_rsense) { |
| 322 | /* internal rsense */ |
| 323 | switch (comp.id) { |
| 324 | case COMP_ID_TSMC: |
| 325 | temp_var = ((QPNP_COEFF_2 * die_temp) - |
| 326 | QPNP_COEFF_3_TYPEB); |
| 327 | break; |
| 328 | case COMP_ID_GF: |
| 329 | default: |
| 330 | temp_var = ((QPNP_COEFF_2 * die_temp) - |
| 331 | QPNP_COEFF_3_TYPEA); |
| 332 | break; |
| 333 | } |
| 334 | temp_var = div64_s64(temp_var, QPNP_COEFF_4); |
| 335 | if (comp.revision == QPNP_IADC_VER_3_0) |
| 336 | temp_var = QPNP_COEFF_1 * (1000000 - temp_var); |
| 337 | else if (comp.revision == QPNP_IADC_VER_3_1) |
| 338 | temp_var = (1000000 - temp_var); |
| 339 | *result = div64_s64(*result, temp_var); |
| 340 | } |
| 341 | |
| 342 | sign_coeff = *result < 0 ? QPNP_COEFF_7 : QPNP_COEFF_5; |
| 343 | if (comp.ext_rsense) { |
| 344 | /* external rsense and current charging */ |
| 345 | temp_var = div64_s64((-sign_coeff * die_temp) + QPNP_COEFF_8, |
| 346 | QPNP_COEFF_4); |
| 347 | temp_var = 1000000000 - temp_var; |
| 348 | if (comp.revision == QPNP_IADC_VER_3_1) { |
| 349 | sys_gain_coeff = (1000000 + |
| 350 | div64_s64(sys_gain_coeff, QPNP_COEFF_4)); |
| 351 | temp_var = div64_s64(temp_var * sys_gain_coeff, |
| 352 | 1000000000); |
| 353 | } |
| 354 | *result = div64_s64(*result, temp_var); |
| 355 | } |
| 356 | |
| 357 | return 0; |
| 358 | } |
| 359 | |
| 360 | int32_t qpnp_iadc_comp_result(int64_t *result) |
| 361 | { |
| 362 | struct qpnp_iadc_drv *iadc = qpnp_iadc; |
| 363 | |
| 364 | return qpnp_iadc_comp(result, iadc->iadc_comp, iadc->die_temp); |
| 365 | } |
| 366 | EXPORT_SYMBOL(qpnp_iadc_comp_result); |
| 367 | |
| 368 | static int32_t qpnp_iadc_comp_info(void) |
| 369 | { |
| 370 | struct qpnp_iadc_drv *iadc = qpnp_iadc; |
| 371 | int rc = 0; |
| 372 | |
| 373 | rc = qpnp_iadc_read_reg(QPNP_INT_TEST_VAL, &iadc->iadc_comp.id); |
| 374 | if (rc < 0) { |
| 375 | pr_err("qpnp adc comp id failed with %d\n", rc); |
| 376 | return rc; |
| 377 | } |
| 378 | |
| 379 | rc = qpnp_iadc_read_reg(QPNP_IADC_REVISION2, &iadc->iadc_comp.revision); |
| 380 | if (rc < 0) { |
| 381 | pr_err("qpnp adc revision read failed with %d\n", rc); |
| 382 | return rc; |
| 383 | } |
| 384 | |
| 385 | rc = qpnp_iadc_read_reg(QPNP_IADC_ATE_GAIN_CALIB_OFFSET, |
| 386 | &iadc->iadc_comp.sys_gain); |
| 387 | if (rc < 0) |
| 388 | pr_err("full scale read failed with %d\n", rc); |
| 389 | |
| 390 | pr_debug("fab id = %u, revision = %u, sys gain = %u, external_rsense = %d\n", |
| 391 | iadc->iadc_comp.id, |
| 392 | iadc->iadc_comp.revision, |
| 393 | iadc->iadc_comp.sys_gain, |
| 394 | iadc->iadc_comp.ext_rsense); |
| 395 | return rc; |
| 396 | } |
| 397 | |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 398 | static int32_t qpnp_iadc_configure(enum qpnp_iadc_channels channel, |
Siddartha Mohanadoss | a32ea2a | 2013-02-12 09:58:31 -0800 | [diff] [blame] | 399 | uint16_t *raw_code, uint32_t mode_sel) |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 400 | { |
| 401 | struct qpnp_iadc_drv *iadc = qpnp_iadc; |
| 402 | u8 qpnp_iadc_mode_reg = 0, qpnp_iadc_ch_sel_reg = 0; |
| 403 | u8 qpnp_iadc_conv_req = 0, qpnp_iadc_dig_param_reg = 0; |
| 404 | int32_t rc = 0; |
| 405 | |
Siddartha Mohanadoss | 5ace110 | 2012-08-20 23:18:10 -0700 | [diff] [blame] | 406 | qpnp_iadc_ch_sel_reg = channel; |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 407 | |
| 408 | qpnp_iadc_dig_param_reg |= iadc->adc->amux_prop->decimation << |
| 409 | QPNP_IADC_DEC_RATIO_SEL; |
Siddartha Mohanadoss | a32ea2a | 2013-02-12 09:58:31 -0800 | [diff] [blame] | 410 | if (iadc->iadc_mode_sel) |
| 411 | qpnp_iadc_mode_reg |= (QPNP_ADC_TRIM_EN | QPNP_VADC_SYNCH_EN); |
| 412 | else |
| 413 | qpnp_iadc_mode_reg |= QPNP_ADC_TRIM_EN; |
| 414 | |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 415 | qpnp_iadc_conv_req = QPNP_IADC_CONV_REQ; |
| 416 | |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 417 | rc = qpnp_iadc_write_reg(QPNP_IADC_MODE_CTL, qpnp_iadc_mode_reg); |
| 418 | if (rc) { |
| 419 | pr_err("qpnp adc read adc failed with %d\n", rc); |
| 420 | return rc; |
| 421 | } |
| 422 | |
| 423 | rc = qpnp_iadc_write_reg(QPNP_IADC_ADC_CH_SEL_CTL, |
| 424 | qpnp_iadc_ch_sel_reg); |
| 425 | if (rc) { |
| 426 | pr_err("qpnp adc read adc failed with %d\n", rc); |
| 427 | return rc; |
| 428 | } |
| 429 | |
| 430 | rc = qpnp_iadc_write_reg(QPNP_ADC_DIG_PARAM, |
| 431 | qpnp_iadc_dig_param_reg); |
| 432 | if (rc) { |
| 433 | pr_err("qpnp adc read adc failed with %d\n", rc); |
| 434 | return rc; |
| 435 | } |
| 436 | |
| 437 | rc = qpnp_iadc_write_reg(QPNP_HW_SETTLE_DELAY, |
| 438 | iadc->adc->amux_prop->hw_settle_time); |
| 439 | if (rc < 0) { |
| 440 | pr_err("qpnp adc configure error for hw settling time setup\n"); |
| 441 | return rc; |
| 442 | } |
| 443 | |
| 444 | rc = qpnp_iadc_write_reg(QPNP_FAST_AVG_CTL, |
| 445 | iadc->adc->amux_prop->fast_avg_setup); |
| 446 | if (rc < 0) { |
| 447 | pr_err("qpnp adc fast averaging configure error\n"); |
| 448 | return rc; |
| 449 | } |
| 450 | |
Siddartha Mohanadoss | 3f219c4 | 2013-04-02 11:01:28 -0700 | [diff] [blame] | 451 | INIT_COMPLETION(iadc->adc->adc_rslt_completion); |
| 452 | |
Siddartha Mohanadoss | 5ace110 | 2012-08-20 23:18:10 -0700 | [diff] [blame] | 453 | rc = qpnp_iadc_enable(true); |
| 454 | if (rc) |
| 455 | return rc; |
| 456 | |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 457 | rc = qpnp_iadc_write_reg(QPNP_CONV_REQ, qpnp_iadc_conv_req); |
| 458 | if (rc) { |
| 459 | pr_err("qpnp adc read adc failed with %d\n", rc); |
| 460 | return rc; |
| 461 | } |
| 462 | |
Siddartha Mohanadoss | 1a0d203 | 2012-11-01 11:22:29 -0700 | [diff] [blame] | 463 | rc = wait_for_completion_timeout(&iadc->adc->adc_rslt_completion, |
| 464 | QPNP_ADC_COMPLETION_TIMEOUT); |
| 465 | if (!rc) { |
| 466 | u8 status1 = 0; |
| 467 | rc = qpnp_iadc_read_reg(QPNP_STATUS1, &status1); |
| 468 | if (rc < 0) |
| 469 | return rc; |
| 470 | status1 &= (QPNP_STATUS1_REQ_STS | QPNP_STATUS1_EOC); |
| 471 | if (status1 == QPNP_STATUS1_EOC) |
| 472 | pr_debug("End of conversion status set\n"); |
| 473 | else { |
Siddartha Mohanadoss | d3a3c95 | 2012-12-10 16:55:19 -0800 | [diff] [blame] | 474 | rc = qpnp_iadc_status_debug(); |
| 475 | if (rc < 0) { |
| 476 | pr_err("status1 read failed with %d\n", rc); |
| 477 | return rc; |
| 478 | } |
Siddartha Mohanadoss | 1a0d203 | 2012-11-01 11:22:29 -0700 | [diff] [blame] | 479 | return -EINVAL; |
| 480 | } |
| 481 | } |
| 482 | |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 483 | rc = qpnp_iadc_read_conversion_result(raw_code); |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 484 | if (rc) { |
| 485 | pr_err("qpnp adc read adc failed with %d\n", rc); |
| 486 | return rc; |
| 487 | } |
| 488 | |
| 489 | return 0; |
| 490 | } |
| 491 | |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 492 | static int32_t qpnp_convert_raw_offset_voltage(void) |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 493 | { |
| 494 | struct qpnp_iadc_drv *iadc = qpnp_iadc; |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 495 | uint32_t num = 0; |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 496 | |
Siddartha Mohanadoss | d752e47 | 2013-02-26 18:30:14 -0800 | [diff] [blame] | 497 | if ((iadc->adc->calib.gain_raw - iadc->adc->calib.offset_raw) == 0) { |
| 498 | pr_err("raw offset errors! raw_gain:0x%x and raw_offset:0x%x\n", |
| 499 | iadc->adc->calib.gain_raw, iadc->adc->calib.offset_raw); |
| 500 | return -EINVAL; |
| 501 | } |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 502 | |
Siddartha Mohanadoss | d752e47 | 2013-02-26 18:30:14 -0800 | [diff] [blame] | 503 | iadc->adc->calib.offset_uv = 0; |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 504 | |
| 505 | num = iadc->adc->calib.gain_raw - iadc->adc->calib.offset_raw; |
| 506 | |
| 507 | iadc->adc->calib.gain_uv = (num * QPNP_ADC_GAIN_NV)/ |
| 508 | (iadc->adc->calib.gain_raw - iadc->adc->calib.offset_raw); |
| 509 | |
Siddartha Mohanadoss | b2a4237 | 2013-03-26 15:53:41 -0700 | [diff] [blame] | 510 | pr_debug("gain_uv:%d offset_uv:%d\n", |
| 511 | iadc->adc->calib.gain_uv, iadc->adc->calib.offset_uv); |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 512 | return 0; |
| 513 | } |
| 514 | |
Siddartha Mohanadoss | 0667392 | 2013-03-27 11:14:19 -0700 | [diff] [blame] | 515 | int32_t qpnp_iadc_calibrate_for_trim(void) |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 516 | { |
| 517 | struct qpnp_iadc_drv *iadc = qpnp_iadc; |
| 518 | uint8_t rslt_lsb, rslt_msb; |
| 519 | int32_t rc = 0; |
| 520 | uint16_t raw_data; |
Siddartha Mohanadoss | a32ea2a | 2013-02-12 09:58:31 -0800 | [diff] [blame] | 521 | uint32_t mode_sel = 0; |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 522 | |
Siddartha Mohanadoss | a9b9167 | 2013-02-22 18:32:27 -0800 | [diff] [blame] | 523 | mutex_lock(&iadc->adc->adc_lock); |
| 524 | |
Siddartha Mohanadoss | a32ea2a | 2013-02-12 09:58:31 -0800 | [diff] [blame] | 525 | rc = qpnp_iadc_configure(GAIN_CALIBRATION_17P857MV, |
| 526 | &raw_data, mode_sel); |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 527 | if (rc < 0) { |
| 528 | pr_err("qpnp adc result read failed with %d\n", rc); |
| 529 | goto fail; |
| 530 | } |
| 531 | |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 532 | iadc->adc->calib.gain_raw = raw_data; |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 533 | |
Siddartha Mohanadoss | a32ea2a | 2013-02-12 09:58:31 -0800 | [diff] [blame] | 534 | rc = qpnp_iadc_configure(OFFSET_CALIBRATION_CSP2_CSN2, |
| 535 | &raw_data, mode_sel); |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 536 | if (rc < 0) { |
| 537 | pr_err("qpnp adc result read failed with %d\n", rc); |
| 538 | goto fail; |
| 539 | } |
| 540 | |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 541 | iadc->adc->calib.offset_raw = raw_data; |
| 542 | if (rc < 0) { |
| 543 | pr_err("qpnp adc offset/gain calculation failed\n"); |
| 544 | goto fail; |
| 545 | } |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 546 | |
Siddartha Mohanadoss | b2a4237 | 2013-03-26 15:53:41 -0700 | [diff] [blame] | 547 | pr_debug("raw gain:0x%x, raw offset:0x%x\n", |
| 548 | iadc->adc->calib.gain_raw, iadc->adc->calib.offset_raw); |
| 549 | |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 550 | rc = qpnp_convert_raw_offset_voltage(); |
Siddartha Mohanadoss | d752e47 | 2013-02-26 18:30:14 -0800 | [diff] [blame] | 551 | if (rc < 0) { |
| 552 | pr_err("qpnp raw_voltage conversion failed\n"); |
| 553 | goto fail; |
| 554 | } |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 555 | |
| 556 | rslt_msb = (raw_data & QPNP_RAW_CODE_16_BIT_MSB_MASK) >> |
| 557 | QPNP_BIT_SHIFT_8; |
| 558 | rslt_lsb = raw_data & QPNP_RAW_CODE_16_BIT_LSB_MASK; |
| 559 | |
Siddartha Mohanadoss | b2a4237 | 2013-03-26 15:53:41 -0700 | [diff] [blame] | 560 | pr_debug("trim values:lsb:0x%x and msb:0x%x\n", rslt_lsb, rslt_msb); |
| 561 | |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 562 | rc = qpnp_iadc_write_reg(QPNP_IADC_SEC_ACCESS, |
| 563 | QPNP_IADC_SEC_ACCESS_DATA); |
| 564 | if (rc < 0) { |
| 565 | pr_err("qpnp iadc configure error for sec access\n"); |
| 566 | goto fail; |
| 567 | } |
| 568 | |
| 569 | rc = qpnp_iadc_write_reg(QPNP_IADC_MSB_OFFSET, |
| 570 | rslt_msb); |
| 571 | if (rc < 0) { |
| 572 | pr_err("qpnp iadc configure error for MSB write\n"); |
| 573 | goto fail; |
| 574 | } |
| 575 | |
| 576 | rc = qpnp_iadc_write_reg(QPNP_IADC_SEC_ACCESS, |
| 577 | QPNP_IADC_SEC_ACCESS_DATA); |
| 578 | if (rc < 0) { |
| 579 | pr_err("qpnp iadc configure error for sec access\n"); |
| 580 | goto fail; |
| 581 | } |
| 582 | |
| 583 | rc = qpnp_iadc_write_reg(QPNP_IADC_LSB_OFFSET, |
| 584 | rslt_lsb); |
| 585 | if (rc < 0) { |
| 586 | pr_err("qpnp iadc configure error for LSB write\n"); |
| 587 | goto fail; |
| 588 | } |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 589 | fail: |
Siddartha Mohanadoss | a9b9167 | 2013-02-22 18:32:27 -0800 | [diff] [blame] | 590 | mutex_unlock(&iadc->adc->adc_lock); |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 591 | return rc; |
| 592 | } |
Siddartha Mohanadoss | 0667392 | 2013-03-27 11:14:19 -0700 | [diff] [blame] | 593 | EXPORT_SYMBOL(qpnp_iadc_calibrate_for_trim); |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 594 | |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 595 | static void qpnp_iadc_work(struct work_struct *work) |
| 596 | { |
| 597 | struct qpnp_iadc_drv *iadc = qpnp_iadc; |
| 598 | int rc = 0; |
| 599 | |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 600 | rc = qpnp_iadc_calibrate_for_trim(); |
Siddartha Mohanadoss | 73ae69b | 2013-04-03 17:34:03 -0700 | [diff] [blame] | 601 | if (rc) |
| 602 | pr_debug("periodic IADC calibration failed\n"); |
| 603 | else |
Siddartha Mohanadoss | 12a15ea | 2013-02-05 19:13:41 -0800 | [diff] [blame] | 604 | schedule_delayed_work(&iadc->iadc_work, |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 605 | round_jiffies_relative(msecs_to_jiffies |
| 606 | (QPNP_IADC_CALIB_SECONDS))); |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 607 | return; |
| 608 | } |
| 609 | |
Siddartha Mohanadoss | 5ace110 | 2012-08-20 23:18:10 -0700 | [diff] [blame] | 610 | static int32_t qpnp_iadc_version_check(void) |
| 611 | { |
| 612 | uint8_t revision; |
| 613 | int rc; |
| 614 | |
| 615 | rc = qpnp_iadc_read_reg(QPNP_IADC_REVISION2, &revision); |
| 616 | if (rc < 0) { |
| 617 | pr_err("qpnp adc result read failed with %d\n", rc); |
| 618 | return rc; |
| 619 | } |
| 620 | |
| 621 | if (revision < QPNP_IADC_SUPPORTED_REVISION2) { |
| 622 | pr_err("IADC Version not supported\n"); |
| 623 | return -EINVAL; |
| 624 | } |
| 625 | |
| 626 | return 0; |
| 627 | } |
| 628 | |
| 629 | int32_t qpnp_iadc_is_ready(void) |
| 630 | { |
| 631 | struct qpnp_iadc_drv *iadc = qpnp_iadc; |
| 632 | |
| 633 | if (!iadc || !iadc->iadc_initialized) |
| 634 | return -EPROBE_DEFER; |
| 635 | else |
| 636 | return 0; |
| 637 | } |
| 638 | EXPORT_SYMBOL(qpnp_iadc_is_ready); |
| 639 | |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 640 | int32_t qpnp_iadc_get_rsense(int32_t *rsense) |
| 641 | { |
Siddartha Mohanadoss | a9b9167 | 2013-02-22 18:32:27 -0800 | [diff] [blame] | 642 | struct qpnp_iadc_drv *iadc = qpnp_iadc; |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 643 | uint8_t rslt_rsense; |
| 644 | int32_t rc, sign_bit = 0; |
| 645 | |
Siddartha Mohanadoss | a9b9167 | 2013-02-22 18:32:27 -0800 | [diff] [blame] | 646 | if (!iadc || !iadc->iadc_initialized) |
| 647 | return -EPROBE_DEFER; |
| 648 | |
Siddartha Mohanadoss | e70010b | 2013-04-04 14:51:41 -0700 | [diff] [blame] | 649 | if (iadc->external_rsense) |
| 650 | *rsense = iadc->rsense; |
| 651 | |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 652 | rc = qpnp_iadc_read_reg(QPNP_IADC_NOMINAL_RSENSE, &rslt_rsense); |
| 653 | if (rc < 0) { |
| 654 | pr_err("qpnp adc rsense read failed with %d\n", rc); |
| 655 | return rc; |
| 656 | } |
| 657 | |
Siddartha Mohanadoss | b2a4237 | 2013-03-26 15:53:41 -0700 | [diff] [blame] | 658 | pr_debug("rsense:0%x\n", rslt_rsense); |
| 659 | |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 660 | if (rslt_rsense & QPNP_RSENSE_MSB_SIGN_CHECK) |
| 661 | sign_bit = 1; |
| 662 | |
| 663 | rslt_rsense &= ~QPNP_RSENSE_MSB_SIGN_CHECK; |
| 664 | |
| 665 | if (sign_bit) |
| 666 | *rsense = QPNP_IADC_INTERNAL_RSENSE_N_OHMS_FACTOR - |
| 667 | (rslt_rsense * QPNP_IADC_RSENSE_LSB_N_OHMS_PER_BIT); |
| 668 | else |
| 669 | *rsense = QPNP_IADC_INTERNAL_RSENSE_N_OHMS_FACTOR + |
| 670 | (rslt_rsense * QPNP_IADC_RSENSE_LSB_N_OHMS_PER_BIT); |
| 671 | |
| 672 | return rc; |
| 673 | } |
Xiaozhe Shi | 767fdb6 | 2013-01-10 15:09:08 -0800 | [diff] [blame] | 674 | EXPORT_SYMBOL(qpnp_iadc_get_rsense); |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 675 | |
Siddartha Mohanadoss | a9b9167 | 2013-02-22 18:32:27 -0800 | [diff] [blame] | 676 | static int32_t qpnp_check_pmic_temp(void) |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 677 | { |
| 678 | struct qpnp_iadc_drv *iadc = qpnp_iadc; |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 679 | struct qpnp_vadc_result result_pmic_therm; |
Siddartha Mohanadoss | d4e9edc | 2013-04-17 14:42:16 -0700 | [diff] [blame] | 680 | int64_t die_temp_offset; |
Siddartha Mohanadoss | d752e47 | 2013-02-26 18:30:14 -0800 | [diff] [blame] | 681 | int rc = 0; |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 682 | |
| 683 | rc = qpnp_vadc_read(DIE_TEMP, &result_pmic_therm); |
| 684 | if (rc < 0) |
| 685 | return rc; |
| 686 | |
Siddartha Mohanadoss | d4e9edc | 2013-04-17 14:42:16 -0700 | [diff] [blame] | 687 | die_temp_offset = result_pmic_therm.physical - |
Siddartha Mohanadoss | 4e64f8c | 2013-04-08 15:57:32 -0700 | [diff] [blame^] | 688 | iadc->die_temp; |
Siddartha Mohanadoss | d4e9edc | 2013-04-17 14:42:16 -0700 | [diff] [blame] | 689 | if (die_temp_offset < 0) |
| 690 | die_temp_offset = -die_temp_offset; |
| 691 | |
| 692 | if (die_temp_offset > QPNP_IADC_DIE_TEMP_CALIB_OFFSET) { |
Siddartha Mohanadoss | 4e64f8c | 2013-04-08 15:57:32 -0700 | [diff] [blame^] | 693 | iadc->die_temp = |
Siddartha Mohanadoss | d4e9edc | 2013-04-17 14:42:16 -0700 | [diff] [blame] | 694 | result_pmic_therm.physical; |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 695 | rc = qpnp_iadc_calibrate_for_trim(); |
| 696 | if (rc) |
| 697 | pr_err("periodic IADC calibration failed\n"); |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 698 | } |
| 699 | |
Siddartha Mohanadoss | d752e47 | 2013-02-26 18:30:14 -0800 | [diff] [blame] | 700 | return rc; |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | int32_t qpnp_iadc_read(enum qpnp_iadc_channels channel, |
| 704 | struct qpnp_iadc_result *result) |
| 705 | { |
| 706 | struct qpnp_iadc_drv *iadc = qpnp_iadc; |
Siddartha Mohanadoss | a32ea2a | 2013-02-12 09:58:31 -0800 | [diff] [blame] | 707 | int32_t rc, rsense_n_ohms, sign = 0, num, mode_sel = 0; |
Siddartha Mohanadoss | 22618be | 2013-04-02 15:02:19 -0700 | [diff] [blame] | 708 | int32_t rsense_u_ohms = 0; |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 709 | int64_t result_current; |
| 710 | uint16_t raw_data; |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 711 | |
Siddartha Mohanadoss | 5ace110 | 2012-08-20 23:18:10 -0700 | [diff] [blame] | 712 | if (!iadc || !iadc->iadc_initialized) |
| 713 | return -EPROBE_DEFER; |
| 714 | |
Siddartha Mohanadoss | a32ea2a | 2013-02-12 09:58:31 -0800 | [diff] [blame] | 715 | if (!iadc->iadc_mode_sel) { |
| 716 | rc = qpnp_check_pmic_temp(); |
| 717 | if (rc) { |
| 718 | pr_err("Error checking pmic therm temp\n"); |
| 719 | return rc; |
| 720 | } |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 721 | } |
| 722 | |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 723 | mutex_lock(&iadc->adc->adc_lock); |
| 724 | |
Siddartha Mohanadoss | a32ea2a | 2013-02-12 09:58:31 -0800 | [diff] [blame] | 725 | rc = qpnp_iadc_configure(channel, &raw_data, mode_sel); |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 726 | if (rc < 0) { |
| 727 | pr_err("qpnp adc result read failed with %d\n", rc); |
| 728 | goto fail; |
| 729 | } |
| 730 | |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 731 | rc = qpnp_iadc_get_rsense(&rsense_n_ohms); |
Siddartha Mohanadoss | b2a4237 | 2013-03-26 15:53:41 -0700 | [diff] [blame] | 732 | pr_debug("current raw:0%x and rsense:%d\n", |
| 733 | raw_data, rsense_n_ohms); |
Siddartha Mohanadoss | 22618be | 2013-04-02 15:02:19 -0700 | [diff] [blame] | 734 | rsense_u_ohms = rsense_n_ohms/1000; |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 735 | num = raw_data - iadc->adc->calib.offset_raw; |
| 736 | if (num < 0) { |
| 737 | sign = 1; |
| 738 | num = -num; |
| 739 | } |
| 740 | |
| 741 | result->result_uv = (num * QPNP_ADC_GAIN_NV)/ |
| 742 | (iadc->adc->calib.gain_raw - iadc->adc->calib.offset_raw); |
| 743 | result_current = result->result_uv; |
| 744 | result_current *= QPNP_IADC_NANO_VOLTS_FACTOR; |
Siddartha Mohanadoss | 4e64f8c | 2013-04-08 15:57:32 -0700 | [diff] [blame^] | 745 | /* Intentional fall through. Process the result w/o comp */ |
Siddartha Mohanadoss | 22618be | 2013-04-02 15:02:19 -0700 | [diff] [blame] | 746 | do_div(result_current, rsense_u_ohms); |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 747 | |
| 748 | if (sign) { |
| 749 | result->result_uv = -result->result_uv; |
| 750 | result_current = -result_current; |
| 751 | } |
Siddartha Mohanadoss | 4e64f8c | 2013-04-08 15:57:32 -0700 | [diff] [blame^] | 752 | rc = qpnp_iadc_comp_result(&result_current); |
| 753 | if (rc < 0) |
| 754 | pr_err("Error during compensating the IADC\n"); |
| 755 | rc = 0; |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 756 | |
| 757 | result->result_ua = (int32_t) result_current; |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 758 | fail: |
| 759 | mutex_unlock(&iadc->adc->adc_lock); |
| 760 | |
| 761 | return rc; |
| 762 | } |
| 763 | EXPORT_SYMBOL(qpnp_iadc_read); |
| 764 | |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 765 | int32_t qpnp_iadc_get_gain_and_offset(struct qpnp_iadc_calib *result) |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 766 | { |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 767 | struct qpnp_iadc_drv *iadc = qpnp_iadc; |
| 768 | int rc; |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 769 | |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 770 | if (!iadc || !iadc->iadc_initialized) |
| 771 | return -EPROBE_DEFER; |
| 772 | |
| 773 | rc = qpnp_check_pmic_temp(); |
| 774 | if (rc) { |
| 775 | pr_err("Error checking pmic therm temp\n"); |
| 776 | return rc; |
| 777 | } |
| 778 | |
| 779 | mutex_lock(&iadc->adc->adc_lock); |
| 780 | result->gain_raw = iadc->adc->calib.gain_raw; |
| 781 | result->ideal_gain_nv = QPNP_ADC_GAIN_NV; |
| 782 | result->gain_uv = iadc->adc->calib.gain_uv; |
| 783 | result->offset_raw = iadc->adc->calib.offset_raw; |
| 784 | result->ideal_offset_uv = |
| 785 | QPNP_OFFSET_CALIBRATION_SHORT_CADC_LEADS_IDEAL; |
| 786 | result->offset_uv = iadc->adc->calib.offset_uv; |
Siddartha Mohanadoss | b2a4237 | 2013-03-26 15:53:41 -0700 | [diff] [blame] | 787 | pr_debug("raw gain:0%x, raw offset:0%x\n", |
| 788 | result->gain_raw, result->offset_raw); |
| 789 | pr_debug("gain_uv:%d offset_uv:%d\n", |
| 790 | result->gain_uv, result->offset_uv); |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 791 | mutex_unlock(&iadc->adc->adc_lock); |
| 792 | |
| 793 | return 0; |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 794 | } |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 795 | EXPORT_SYMBOL(qpnp_iadc_get_gain_and_offset); |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 796 | |
Siddartha Mohanadoss | a32ea2a | 2013-02-12 09:58:31 -0800 | [diff] [blame] | 797 | int32_t qpnp_iadc_vadc_sync_read( |
| 798 | enum qpnp_iadc_channels i_channel, struct qpnp_iadc_result *i_result, |
| 799 | enum qpnp_vadc_channels v_channel, struct qpnp_vadc_result *v_result) |
| 800 | { |
| 801 | struct qpnp_iadc_drv *iadc = qpnp_iadc; |
| 802 | int rc = 0; |
| 803 | |
| 804 | if (!iadc || !iadc->iadc_initialized) |
| 805 | return -EPROBE_DEFER; |
| 806 | |
| 807 | mutex_lock(&iadc->iadc_vadc_lock); |
| 808 | |
| 809 | rc = qpnp_check_pmic_temp(); |
| 810 | if (rc) { |
| 811 | pr_err("PMIC die temp check failed\n"); |
| 812 | goto fail; |
| 813 | } |
| 814 | |
| 815 | iadc->iadc_mode_sel = true; |
| 816 | |
| 817 | rc = qpnp_vadc_iadc_sync_request(v_channel); |
| 818 | if (rc) { |
| 819 | pr_err("Configuring VADC failed\n"); |
| 820 | goto fail; |
| 821 | } |
| 822 | |
| 823 | rc = qpnp_iadc_read(i_channel, i_result); |
| 824 | if (rc) |
| 825 | pr_err("Configuring IADC failed\n"); |
| 826 | /* Intentional fall through to release VADC */ |
| 827 | |
| 828 | rc = qpnp_vadc_iadc_sync_complete_request(v_channel, |
| 829 | v_result); |
| 830 | if (rc) |
| 831 | pr_err("Releasing VADC failed\n"); |
| 832 | fail: |
| 833 | iadc->iadc_mode_sel = false; |
| 834 | |
| 835 | mutex_unlock(&iadc->iadc_vadc_lock); |
| 836 | |
| 837 | return rc; |
| 838 | } |
| 839 | EXPORT_SYMBOL(qpnp_iadc_vadc_sync_read); |
| 840 | |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 841 | static ssize_t qpnp_iadc_show(struct device *dev, |
| 842 | struct device_attribute *devattr, char *buf) |
| 843 | { |
| 844 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 845 | struct qpnp_iadc_result result; |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 846 | int rc = -1; |
| 847 | |
| 848 | rc = qpnp_iadc_read(attr->index, &result); |
| 849 | |
| 850 | if (rc) |
| 851 | return 0; |
| 852 | |
| 853 | return snprintf(buf, QPNP_ADC_HWMON_NAME_LENGTH, |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 854 | "Result:%d\n", result.result_ua); |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | static struct sensor_device_attribute qpnp_adc_attr = |
| 858 | SENSOR_ATTR(NULL, S_IRUGO, qpnp_iadc_show, NULL, 0); |
| 859 | |
| 860 | static int32_t qpnp_iadc_init_hwmon(struct spmi_device *spmi) |
| 861 | { |
| 862 | struct qpnp_iadc_drv *iadc = qpnp_iadc; |
| 863 | struct device_node *child; |
| 864 | struct device_node *node = spmi->dev.of_node; |
| 865 | int rc = 0, i = 0, channel; |
| 866 | |
| 867 | for_each_child_of_node(node, child) { |
| 868 | channel = iadc->adc->adc_channels[i].channel_num; |
| 869 | qpnp_adc_attr.index = iadc->adc->adc_channels[i].channel_num; |
| 870 | qpnp_adc_attr.dev_attr.attr.name = |
| 871 | iadc->adc->adc_channels[i].name; |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 872 | memcpy(&iadc->sens_attr[i], &qpnp_adc_attr, |
| 873 | sizeof(qpnp_adc_attr)); |
Stephen Boyd | 8a5c4e4 | 2012-10-30 11:07:22 -0700 | [diff] [blame] | 874 | sysfs_attr_init(&iadc->sens_attr[i].dev_attr.attr); |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 875 | rc = device_create_file(&spmi->dev, |
| 876 | &iadc->sens_attr[i].dev_attr); |
| 877 | if (rc) { |
| 878 | dev_err(&spmi->dev, |
| 879 | "device_create_file failed for dev %s\n", |
| 880 | iadc->adc->adc_channels[i].name); |
| 881 | goto hwmon_err_sens; |
| 882 | } |
| 883 | i++; |
| 884 | } |
| 885 | |
| 886 | return 0; |
| 887 | hwmon_err_sens: |
| 888 | pr_err("Init HWMON failed for qpnp_iadc with %d\n", rc); |
| 889 | return rc; |
| 890 | } |
| 891 | |
| 892 | static int __devinit qpnp_iadc_probe(struct spmi_device *spmi) |
| 893 | { |
| 894 | struct qpnp_iadc_drv *iadc; |
| 895 | struct qpnp_adc_drv *adc_qpnp; |
| 896 | struct device_node *node = spmi->dev.of_node; |
| 897 | struct device_node *child; |
| 898 | int rc, count_adc_channel_list = 0; |
| 899 | |
| 900 | if (!node) |
| 901 | return -EINVAL; |
| 902 | |
| 903 | if (qpnp_iadc) { |
| 904 | pr_err("IADC already in use\n"); |
| 905 | return -EBUSY; |
| 906 | } |
| 907 | |
| 908 | for_each_child_of_node(node, child) |
| 909 | count_adc_channel_list++; |
| 910 | |
| 911 | if (!count_adc_channel_list) { |
| 912 | pr_err("No channel listing\n"); |
| 913 | return -EINVAL; |
| 914 | } |
| 915 | |
| 916 | iadc = devm_kzalloc(&spmi->dev, sizeof(struct qpnp_iadc_drv) + |
| 917 | (sizeof(struct sensor_device_attribute) * |
| 918 | count_adc_channel_list), GFP_KERNEL); |
| 919 | if (!iadc) { |
| 920 | dev_err(&spmi->dev, "Unable to allocate memory\n"); |
| 921 | return -ENOMEM; |
| 922 | } |
| 923 | |
| 924 | adc_qpnp = devm_kzalloc(&spmi->dev, sizeof(struct qpnp_adc_drv), |
| 925 | GFP_KERNEL); |
| 926 | if (!adc_qpnp) { |
| 927 | dev_err(&spmi->dev, "Unable to allocate memory\n"); |
Siddartha Mohanadoss | b60f646 | 2012-11-20 18:06:51 -0800 | [diff] [blame] | 928 | rc = -ENOMEM; |
| 929 | goto fail; |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 930 | } |
| 931 | |
| 932 | iadc->adc = adc_qpnp; |
| 933 | |
| 934 | rc = qpnp_adc_get_devicetree_data(spmi, iadc->adc); |
| 935 | if (rc) { |
| 936 | dev_err(&spmi->dev, "failed to read device tree\n"); |
Siddartha Mohanadoss | b60f646 | 2012-11-20 18:06:51 -0800 | [diff] [blame] | 937 | goto fail; |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 938 | } |
| 939 | |
Stephen Boyd | beab450 | 2013-04-25 10:18:17 -0700 | [diff] [blame] | 940 | mutex_init(&iadc->adc->adc_lock); |
| 941 | |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 942 | rc = of_property_read_u32(node, "qcom,rsense", |
| 943 | &iadc->rsense); |
Siddartha Mohanadoss | e70010b | 2013-04-04 14:51:41 -0700 | [diff] [blame] | 944 | if (rc) |
| 945 | pr_debug("Defaulting to internal rsense\n"); |
| 946 | else { |
| 947 | pr_debug("Use external rsense\n"); |
| 948 | iadc->external_rsense = true; |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 949 | } |
| 950 | |
Siddartha Mohanadoss | 1210995 | 2012-11-20 14:57:51 -0800 | [diff] [blame] | 951 | rc = devm_request_irq(&spmi->dev, iadc->adc->adc_irq_eoc, |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 952 | qpnp_iadc_isr, |
| 953 | IRQF_TRIGGER_RISING, "qpnp_iadc_interrupt", iadc); |
| 954 | if (rc) { |
| 955 | dev_err(&spmi->dev, "failed to request adc irq\n"); |
Siddartha Mohanadoss | b60f646 | 2012-11-20 18:06:51 -0800 | [diff] [blame] | 956 | goto fail; |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 957 | } else |
Siddartha Mohanadoss | 1210995 | 2012-11-20 14:57:51 -0800 | [diff] [blame] | 958 | enable_irq_wake(iadc->adc->adc_irq_eoc); |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 959 | |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 960 | dev_set_drvdata(&spmi->dev, iadc); |
| 961 | qpnp_iadc = iadc; |
| 962 | |
| 963 | rc = qpnp_iadc_init_hwmon(spmi); |
| 964 | if (rc) { |
| 965 | dev_err(&spmi->dev, "failed to initialize qpnp hwmon adc\n"); |
Siddartha Mohanadoss | b60f646 | 2012-11-20 18:06:51 -0800 | [diff] [blame] | 966 | goto fail; |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 967 | } |
| 968 | iadc->iadc_hwmon = hwmon_device_register(&iadc->adc->spmi->dev); |
| 969 | |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 970 | rc = qpnp_iadc_version_check(); |
| 971 | if (rc) { |
| 972 | dev_err(&spmi->dev, "IADC version not supported\n"); |
Siddartha Mohanadoss | b60f646 | 2012-11-20 18:06:51 -0800 | [diff] [blame] | 973 | goto fail; |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 974 | } |
| 975 | |
Siddartha Mohanadoss | a32ea2a | 2013-02-12 09:58:31 -0800 | [diff] [blame] | 976 | mutex_init(&iadc->iadc_vadc_lock); |
Siddartha Mohanadoss | a9b9167 | 2013-02-22 18:32:27 -0800 | [diff] [blame] | 977 | INIT_DELAYED_WORK(&iadc->iadc_work, qpnp_iadc_work); |
Siddartha Mohanadoss | 4e64f8c | 2013-04-08 15:57:32 -0700 | [diff] [blame^] | 978 | rc = qpnp_iadc_comp_info(); |
| 979 | if (rc) { |
| 980 | dev_err(&spmi->dev, "abstracting IADC comp info failed!\n"); |
| 981 | goto fail; |
| 982 | } |
Siddartha Mohanadoss | 12a15ea | 2013-02-05 19:13:41 -0800 | [diff] [blame] | 983 | iadc->iadc_initialized = true; |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 984 | |
Siddartha Mohanadoss | a9b9167 | 2013-02-22 18:32:27 -0800 | [diff] [blame] | 985 | rc = qpnp_iadc_calibrate_for_trim(); |
| 986 | if (rc) |
| 987 | dev_err(&spmi->dev, "failed to calibrate for USR trim\n"); |
| 988 | schedule_delayed_work(&iadc->iadc_work, |
| 989 | round_jiffies_relative(msecs_to_jiffies |
| 990 | (QPNP_IADC_CALIB_SECONDS))); |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 991 | return 0; |
Siddartha Mohanadoss | b60f646 | 2012-11-20 18:06:51 -0800 | [diff] [blame] | 992 | fail: |
Siddartha Mohanadoss | 32019b5 | 2012-12-23 17:05:45 -0800 | [diff] [blame] | 993 | qpnp_iadc = NULL; |
Siddartha Mohanadoss | b60f646 | 2012-11-20 18:06:51 -0800 | [diff] [blame] | 994 | return rc; |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 995 | } |
| 996 | |
| 997 | static int __devexit qpnp_iadc_remove(struct spmi_device *spmi) |
| 998 | { |
| 999 | struct qpnp_iadc_drv *iadc = dev_get_drvdata(&spmi->dev); |
| 1000 | struct device_node *node = spmi->dev.of_node; |
| 1001 | struct device_node *child; |
| 1002 | int i = 0; |
| 1003 | |
Siddartha Mohanadoss | a9b9167 | 2013-02-22 18:32:27 -0800 | [diff] [blame] | 1004 | cancel_delayed_work(&iadc->iadc_work); |
Siddartha Mohanadoss | a32ea2a | 2013-02-12 09:58:31 -0800 | [diff] [blame] | 1005 | mutex_destroy(&iadc->iadc_vadc_lock); |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 1006 | for_each_child_of_node(node, child) { |
| 1007 | device_remove_file(&spmi->dev, |
| 1008 | &iadc->sens_attr[i].dev_attr); |
| 1009 | i++; |
| 1010 | } |
| 1011 | dev_set_drvdata(&spmi->dev, NULL); |
| 1012 | |
| 1013 | return 0; |
| 1014 | } |
| 1015 | |
| 1016 | static const struct of_device_id qpnp_iadc_match_table[] = { |
| 1017 | { .compatible = "qcom,qpnp-iadc", |
| 1018 | }, |
| 1019 | {} |
| 1020 | }; |
| 1021 | |
| 1022 | static struct spmi_driver qpnp_iadc_driver = { |
| 1023 | .driver = { |
| 1024 | .name = "qcom,qpnp-iadc", |
| 1025 | .of_match_table = qpnp_iadc_match_table, |
| 1026 | }, |
| 1027 | .probe = qpnp_iadc_probe, |
| 1028 | .remove = qpnp_iadc_remove, |
| 1029 | }; |
| 1030 | |
| 1031 | static int __init qpnp_iadc_init(void) |
| 1032 | { |
| 1033 | return spmi_driver_register(&qpnp_iadc_driver); |
| 1034 | } |
| 1035 | module_init(qpnp_iadc_init); |
| 1036 | |
| 1037 | static void __exit qpnp_iadc_exit(void) |
| 1038 | { |
| 1039 | spmi_driver_unregister(&qpnp_iadc_driver); |
| 1040 | } |
| 1041 | module_exit(qpnp_iadc_exit); |
| 1042 | |
| 1043 | MODULE_DESCRIPTION("QPNP PMIC current ADC driver"); |
| 1044 | MODULE_LICENSE("GPL v2"); |