|
6 | 6 | #include <linux/bitops.h>
|
7 | 7 | #include <linux/regmap.h>
|
8 | 8 | #include <linux/delay.h>
|
| 9 | +#include <linux/slab.h> |
9 | 10 | #include "tsens.h"
|
10 | 11 |
|
11 | 12 | /* ----- SROT ------ */
|
|
20 | 21 | #define TM_HIGH_LOW_INT_STATUS_OFF 0x0088
|
21 | 22 | #define TM_HIGH_LOW_Sn_INT_THRESHOLD_OFF 0x0090
|
22 | 23 |
|
| 24 | +/* eeprom layout data for msm8956/76 (v1) */ |
| 25 | +#define MSM8976_BASE0_MASK 0xff |
| 26 | +#define MSM8976_BASE1_MASK 0xff |
| 27 | +#define MSM8976_BASE1_SHIFT 8 |
| 28 | + |
| 29 | +#define MSM8976_S0_P1_MASK 0x3f00 |
| 30 | +#define MSM8976_S1_P1_MASK 0x3f00000 |
| 31 | +#define MSM8976_S2_P1_MASK 0x3f |
| 32 | +#define MSM8976_S3_P1_MASK 0x3f000 |
| 33 | +#define MSM8976_S4_P1_MASK 0x3f00 |
| 34 | +#define MSM8976_S5_P1_MASK 0x3f00000 |
| 35 | +#define MSM8976_S6_P1_MASK 0x3f |
| 36 | +#define MSM8976_S7_P1_MASK 0x3f000 |
| 37 | +#define MSM8976_S8_P1_MASK 0x1f8 |
| 38 | +#define MSM8976_S9_P1_MASK 0x1f8000 |
| 39 | +#define MSM8976_S10_P1_MASK 0xf8000000 |
| 40 | +#define MSM8976_S10_P1_MASK_1 0x1 |
| 41 | + |
| 42 | +#define MSM8976_S0_P2_MASK 0xfc000 |
| 43 | +#define MSM8976_S1_P2_MASK 0xfc000000 |
| 44 | +#define MSM8976_S2_P2_MASK 0xfc0 |
| 45 | +#define MSM8976_S3_P2_MASK 0xfc0000 |
| 46 | +#define MSM8976_S4_P2_MASK 0xfc000 |
| 47 | +#define MSM8976_S5_P2_MASK 0xfc000000 |
| 48 | +#define MSM8976_S6_P2_MASK 0xfc0 |
| 49 | +#define MSM8976_S7_P2_MASK 0xfc0000 |
| 50 | +#define MSM8976_S8_P2_MASK 0x7e00 |
| 51 | +#define MSM8976_S9_P2_MASK 0x7e00000 |
| 52 | +#define MSM8976_S10_P2_MASK 0x7e |
| 53 | + |
| 54 | +#define MSM8976_S0_P1_SHIFT 8 |
| 55 | +#define MSM8976_S1_P1_SHIFT 20 |
| 56 | +#define MSM8976_S2_P1_SHIFT 0 |
| 57 | +#define MSM8976_S3_P1_SHIFT 12 |
| 58 | +#define MSM8976_S4_P1_SHIFT 8 |
| 59 | +#define MSM8976_S5_P1_SHIFT 20 |
| 60 | +#define MSM8976_S6_P1_SHIFT 0 |
| 61 | +#define MSM8976_S7_P1_SHIFT 12 |
| 62 | +#define MSM8976_S8_P1_SHIFT 3 |
| 63 | +#define MSM8976_S9_P1_SHIFT 15 |
| 64 | +#define MSM8976_S10_P1_SHIFT 27 |
| 65 | +#define MSM8976_S10_P1_SHIFT_1 0 |
| 66 | + |
| 67 | +#define MSM8976_S0_P2_SHIFT 14 |
| 68 | +#define MSM8976_S1_P2_SHIFT 26 |
| 69 | +#define MSM8976_S2_P2_SHIFT 6 |
| 70 | +#define MSM8976_S3_P2_SHIFT 18 |
| 71 | +#define MSM8976_S4_P2_SHIFT 14 |
| 72 | +#define MSM8976_S5_P2_SHIFT 26 |
| 73 | +#define MSM8976_S6_P2_SHIFT 6 |
| 74 | +#define MSM8976_S7_P2_SHIFT 18 |
| 75 | +#define MSM8976_S8_P2_SHIFT 9 |
| 76 | +#define MSM8976_S9_P2_SHIFT 21 |
| 77 | +#define MSM8976_S10_P2_SHIFT 1 |
| 78 | + |
| 79 | +#define MSM8976_CAL_SEL_MASK 0x3 |
| 80 | + |
| 81 | +#define MSM8976_CAL_DEGC_PT1 30 |
| 82 | +#define MSM8976_CAL_DEGC_PT2 120 |
| 83 | +#define MSM8976_SLOPE_FACTOR 1000 |
| 84 | +#define MSM8976_SLOPE_DEFAULT 3200 |
| 85 | + |
23 | 86 | /* eeprom layout data for qcs404/405 (v1) */
|
24 | 87 | #define BASE0_MASK 0x000007f8
|
25 | 88 | #define BASE1_MASK 0x0007f800
|
|
79 | 142 | #define CAL_SEL_MASK 7
|
80 | 143 | #define CAL_SEL_SHIFT 0
|
81 | 144 |
|
| 145 | +static void compute_intercept_slope_8976(struct tsens_priv *priv, |
| 146 | + u32 *p1, u32 *p2, u32 mode) |
| 147 | +{ |
| 148 | + int i; |
| 149 | + |
| 150 | + priv->sensor[0].slope = 3313; |
| 151 | + priv->sensor[1].slope = 3275; |
| 152 | + priv->sensor[2].slope = 3320; |
| 153 | + priv->sensor[3].slope = 3246; |
| 154 | + priv->sensor[4].slope = 3279; |
| 155 | + priv->sensor[5].slope = 3257; |
| 156 | + priv->sensor[6].slope = 3234; |
| 157 | + priv->sensor[7].slope = 3269; |
| 158 | + priv->sensor[8].slope = 3255; |
| 159 | + priv->sensor[9].slope = 3239; |
| 160 | + priv->sensor[10].slope = 3286; |
| 161 | + |
| 162 | + for (i = 0; i < priv->num_sensors; i++) { |
| 163 | + priv->sensor[i].offset = (p1[i] * MSM8976_SLOPE_FACTOR) - |
| 164 | + (MSM8976_CAL_DEGC_PT1 * |
| 165 | + priv->sensor[i].slope); |
| 166 | + } |
| 167 | +} |
| 168 | + |
82 | 169 | static int calibrate_v1(struct tsens_priv *priv)
|
83 | 170 | {
|
84 | 171 | u32 base0 = 0, base1 = 0;
|
@@ -145,7 +232,74 @@ static int calibrate_v1(struct tsens_priv *priv)
|
145 | 232 | return 0;
|
146 | 233 | }
|
147 | 234 |
|
148 |
| -/* v1.x: qcs404,405 */ |
| 235 | +static int calibrate_8976(struct tsens_priv *priv) |
| 236 | +{ |
| 237 | + int base0 = 0, base1 = 0, i; |
| 238 | + u32 p1[11], p2[11]; |
| 239 | + int mode = 0, tmp = 0; |
| 240 | + u32 *qfprom_cdata; |
| 241 | + |
| 242 | + qfprom_cdata = (u32 *)qfprom_read(priv->dev, "calib"); |
| 243 | + if (IS_ERR(qfprom_cdata)) { |
| 244 | + kfree(qfprom_cdata); |
| 245 | + return PTR_ERR(qfprom_cdata); |
| 246 | + } |
| 247 | + |
| 248 | + mode = (qfprom_cdata[4] & MSM8976_CAL_SEL_MASK); |
| 249 | + dev_dbg(priv->dev, "calibration mode is %d\n", mode); |
| 250 | + |
| 251 | + switch (mode) { |
| 252 | + case TWO_PT_CALIB: |
| 253 | + base1 = (qfprom_cdata[2] & MSM8976_BASE1_MASK) >> MSM8976_BASE1_SHIFT; |
| 254 | + p2[0] = (qfprom_cdata[0] & MSM8976_S0_P2_MASK) >> MSM8976_S0_P2_SHIFT; |
| 255 | + p2[1] = (qfprom_cdata[0] & MSM8976_S1_P2_MASK) >> MSM8976_S1_P2_SHIFT; |
| 256 | + p2[2] = (qfprom_cdata[1] & MSM8976_S2_P2_MASK) >> MSM8976_S2_P2_SHIFT; |
| 257 | + p2[3] = (qfprom_cdata[1] & MSM8976_S3_P2_MASK) >> MSM8976_S3_P2_SHIFT; |
| 258 | + p2[4] = (qfprom_cdata[2] & MSM8976_S4_P2_MASK) >> MSM8976_S4_P2_SHIFT; |
| 259 | + p2[5] = (qfprom_cdata[2] & MSM8976_S5_P2_MASK) >> MSM8976_S5_P2_SHIFT; |
| 260 | + p2[6] = (qfprom_cdata[3] & MSM8976_S6_P2_MASK) >> MSM8976_S6_P2_SHIFT; |
| 261 | + p2[7] = (qfprom_cdata[3] & MSM8976_S7_P2_MASK) >> MSM8976_S7_P2_SHIFT; |
| 262 | + p2[8] = (qfprom_cdata[4] & MSM8976_S8_P2_MASK) >> MSM8976_S8_P2_SHIFT; |
| 263 | + p2[9] = (qfprom_cdata[4] & MSM8976_S9_P2_MASK) >> MSM8976_S9_P2_SHIFT; |
| 264 | + p2[10] = (qfprom_cdata[5] & MSM8976_S10_P2_MASK) >> MSM8976_S10_P2_SHIFT; |
| 265 | + |
| 266 | + for (i = 0; i < priv->num_sensors; i++) |
| 267 | + p2[i] = ((base1 + p2[i]) << 2); |
| 268 | + /* Fall through */ |
| 269 | + case ONE_PT_CALIB2: |
| 270 | + base0 = qfprom_cdata[0] & MSM8976_BASE0_MASK; |
| 271 | + p1[0] = (qfprom_cdata[0] & MSM8976_S0_P1_MASK) >> MSM8976_S0_P1_SHIFT; |
| 272 | + p1[1] = (qfprom_cdata[0] & MSM8976_S1_P1_MASK) >> MSM8976_S1_P1_SHIFT; |
| 273 | + p1[2] = (qfprom_cdata[1] & MSM8976_S2_P1_MASK) >> MSM8976_S2_P1_SHIFT; |
| 274 | + p1[3] = (qfprom_cdata[1] & MSM8976_S3_P1_MASK) >> MSM8976_S3_P1_SHIFT; |
| 275 | + p1[4] = (qfprom_cdata[2] & MSM8976_S4_P1_MASK) >> MSM8976_S4_P1_SHIFT; |
| 276 | + p1[5] = (qfprom_cdata[2] & MSM8976_S5_P1_MASK) >> MSM8976_S5_P1_SHIFT; |
| 277 | + p1[6] = (qfprom_cdata[3] & MSM8976_S6_P1_MASK) >> MSM8976_S6_P1_SHIFT; |
| 278 | + p1[7] = (qfprom_cdata[3] & MSM8976_S7_P1_MASK) >> MSM8976_S7_P1_SHIFT; |
| 279 | + p1[8] = (qfprom_cdata[4] & MSM8976_S8_P1_MASK) >> MSM8976_S8_P1_SHIFT; |
| 280 | + p1[9] = (qfprom_cdata[4] & MSM8976_S9_P1_MASK) >> MSM8976_S9_P1_SHIFT; |
| 281 | + p1[10] = (qfprom_cdata[4] & MSM8976_S10_P1_MASK) >> MSM8976_S10_P1_SHIFT; |
| 282 | + tmp = (qfprom_cdata[5] & MSM8976_S10_P1_MASK_1) << MSM8976_S10_P1_SHIFT_1; |
| 283 | + p1[10] |= tmp; |
| 284 | + |
| 285 | + for (i = 0; i < priv->num_sensors; i++) |
| 286 | + p1[i] = (((base0) + p1[i]) << 2); |
| 287 | + break; |
| 288 | + default: |
| 289 | + for (i = 0; i < priv->num_sensors; i++) { |
| 290 | + p1[i] = 500; |
| 291 | + p2[i] = 780; |
| 292 | + } |
| 293 | + break; |
| 294 | + } |
| 295 | + |
| 296 | + compute_intercept_slope_8976(priv, p1, p2, mode); |
| 297 | + kfree(qfprom_cdata); |
| 298 | + |
| 299 | + return 0; |
| 300 | +} |
| 301 | + |
| 302 | +/* v1.x: msm8956,8976,qcs404,405 */ |
149 | 303 |
|
150 | 304 | static const struct tsens_features tsens_v1_feat = {
|
151 | 305 | .ver_major = VER_1_X,
|
@@ -221,3 +375,18 @@ const struct tsens_plat_data data_tsens_v1 = {
|
221 | 375 | .feat = &tsens_v1_feat,
|
222 | 376 | .fields = tsens_v1_regfields,
|
223 | 377 | };
|
| 378 | + |
| 379 | +static const struct tsens_ops ops_8976 = { |
| 380 | + .init = init_common, |
| 381 | + .calibrate = calibrate_8976, |
| 382 | + .get_temp = get_temp_tsens_valid, |
| 383 | +}; |
| 384 | + |
| 385 | +/* Valid for both MSM8956 and MSM8976. Sensor ID 3 is unused. */ |
| 386 | +const struct tsens_plat_data data_8976 = { |
| 387 | + .num_sensors = 11, |
| 388 | + .ops = &ops_8976, |
| 389 | + .hw_ids = (unsigned int[]){0, 1, 2, 4, 5, 6, 7, 8, 9, 10}, |
| 390 | + .feat = &tsens_v1_feat, |
| 391 | + .fields = tsens_v1_regfields, |
| 392 | +}; |
0 commit comments