linux/drivers/thermal/qcom/tsens-8974.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0
   2/*
   3 * Copyright (c) 2015, The Linux Foundation. All rights reserved.
   4 */
   5
   6#include <linux/platform_device.h>
   7#include "tsens.h"
   8
   9/* eeprom layout data for 8974 */
  10#define BASE1_MASK              0xff
  11#define S0_P1_MASK              0x3f00
  12#define S1_P1_MASK              0xfc000
  13#define S2_P1_MASK              0x3f00000
  14#define S3_P1_MASK              0xfc000000
  15#define S4_P1_MASK              0x3f
  16#define S5_P1_MASK              0xfc0
  17#define S6_P1_MASK              0x3f000
  18#define S7_P1_MASK              0xfc0000
  19#define S8_P1_MASK              0x3f000000
  20#define S8_P1_MASK_BKP          0x3f
  21#define S9_P1_MASK              0x3f
  22#define S9_P1_MASK_BKP          0xfc0
  23#define S10_P1_MASK             0xfc0
  24#define S10_P1_MASK_BKP         0x3f000
  25#define CAL_SEL_0_1             0xc0000000
  26#define CAL_SEL_2               0x40000000
  27#define CAL_SEL_SHIFT           30
  28#define CAL_SEL_SHIFT_2         28
  29
  30#define S0_P1_SHIFT             8
  31#define S1_P1_SHIFT             14
  32#define S2_P1_SHIFT             20
  33#define S3_P1_SHIFT             26
  34#define S5_P1_SHIFT             6
  35#define S6_P1_SHIFT             12
  36#define S7_P1_SHIFT             18
  37#define S8_P1_SHIFT             24
  38#define S9_P1_BKP_SHIFT         6
  39#define S10_P1_SHIFT            6
  40#define S10_P1_BKP_SHIFT        12
  41
  42#define BASE2_SHIFT             12
  43#define BASE2_BKP_SHIFT         18
  44#define S0_P2_SHIFT             20
  45#define S0_P2_BKP_SHIFT         26
  46#define S1_P2_SHIFT             26
  47#define S2_P2_BKP_SHIFT         6
  48#define S3_P2_SHIFT             6
  49#define S3_P2_BKP_SHIFT         12
  50#define S4_P2_SHIFT             12
  51#define S4_P2_BKP_SHIFT         18
  52#define S5_P2_SHIFT             18
  53#define S5_P2_BKP_SHIFT         24
  54#define S6_P2_SHIFT             24
  55#define S7_P2_BKP_SHIFT         6
  56#define S8_P2_SHIFT             6
  57#define S8_P2_BKP_SHIFT         12
  58#define S9_P2_SHIFT             12
  59#define S9_P2_BKP_SHIFT         18
  60#define S10_P2_SHIFT            18
  61#define S10_P2_BKP_SHIFT        24
  62
  63#define BASE2_MASK              0xff000
  64#define BASE2_BKP_MASK          0xfc0000
  65#define S0_P2_MASK              0x3f00000
  66#define S0_P2_BKP_MASK          0xfc000000
  67#define S1_P2_MASK              0xfc000000
  68#define S1_P2_BKP_MASK          0x3f
  69#define S2_P2_MASK              0x3f
  70#define S2_P2_BKP_MASK          0xfc0
  71#define S3_P2_MASK              0xfc0
  72#define S3_P2_BKP_MASK          0x3f000
  73#define S4_P2_MASK              0x3f000
  74#define S4_P2_BKP_MASK          0xfc0000
  75#define S5_P2_MASK              0xfc0000
  76#define S5_P2_BKP_MASK          0x3f000000
  77#define S6_P2_MASK              0x3f000000
  78#define S6_P2_BKP_MASK          0x3f
  79#define S7_P2_MASK              0x3f
  80#define S7_P2_BKP_MASK          0xfc0
  81#define S8_P2_MASK              0xfc0
  82#define S8_P2_BKP_MASK          0x3f000
  83#define S9_P2_MASK              0x3f000
  84#define S9_P2_BKP_MASK          0xfc0000
  85#define S10_P2_MASK             0xfc0000
  86#define S10_P2_BKP_MASK         0x3f000000
  87
  88#define BKP_SEL                 0x3
  89#define BKP_REDUN_SEL           0xe0000000
  90#define BKP_REDUN_SHIFT         29
  91
  92#define BIT_APPEND              0x3
  93
  94static int calibrate_8974(struct tsens_device *tmdev)
  95{
  96        int base1 = 0, base2 = 0, i;
  97        u32 p1[11], p2[11];
  98        int mode = 0;
  99        u32 *calib, *bkp;
 100        u32 calib_redun_sel;
 101
 102        calib = (u32 *)qfprom_read(tmdev->dev, "calib");
 103        if (IS_ERR(calib))
 104                return PTR_ERR(calib);
 105
 106        bkp = (u32 *)qfprom_read(tmdev->dev, "calib_backup");
 107        if (IS_ERR(bkp))
 108                return PTR_ERR(bkp);
 109
 110        calib_redun_sel =  bkp[1] & BKP_REDUN_SEL;
 111        calib_redun_sel >>= BKP_REDUN_SHIFT;
 112
 113        if (calib_redun_sel == BKP_SEL) {
 114                mode = (calib[4] & CAL_SEL_0_1) >> CAL_SEL_SHIFT;
 115                mode |= (calib[5] & CAL_SEL_2) >> CAL_SEL_SHIFT_2;
 116
 117                switch (mode) {
 118                case TWO_PT_CALIB:
 119                        base2 = (bkp[2] & BASE2_BKP_MASK) >> BASE2_BKP_SHIFT;
 120                        p2[0] = (bkp[2] & S0_P2_BKP_MASK) >> S0_P2_BKP_SHIFT;
 121                        p2[1] = (bkp[3] & S1_P2_BKP_MASK);
 122                        p2[2] = (bkp[3] & S2_P2_BKP_MASK) >> S2_P2_BKP_SHIFT;
 123                        p2[3] = (bkp[3] & S3_P2_BKP_MASK) >> S3_P2_BKP_SHIFT;
 124                        p2[4] = (bkp[3] & S4_P2_BKP_MASK) >> S4_P2_BKP_SHIFT;
 125                        p2[5] = (calib[4] & S5_P2_BKP_MASK) >> S5_P2_BKP_SHIFT;
 126                        p2[6] = (calib[5] & S6_P2_BKP_MASK);
 127                        p2[7] = (calib[5] & S7_P2_BKP_MASK) >> S7_P2_BKP_SHIFT;
 128                        p2[8] = (calib[5] & S8_P2_BKP_MASK) >> S8_P2_BKP_SHIFT;
 129                        p2[9] = (calib[5] & S9_P2_BKP_MASK) >> S9_P2_BKP_SHIFT;
 130                        p2[10] = (calib[5] & S10_P2_BKP_MASK) >> S10_P2_BKP_SHIFT;
 131                        /* Fall through */
 132                case ONE_PT_CALIB:
 133                case ONE_PT_CALIB2:
 134                        base1 = bkp[0] & BASE1_MASK;
 135                        p1[0] = (bkp[0] & S0_P1_MASK) >> S0_P1_SHIFT;
 136                        p1[1] = (bkp[0] & S1_P1_MASK) >> S1_P1_SHIFT;
 137                        p1[2] = (bkp[0] & S2_P1_MASK) >> S2_P1_SHIFT;
 138                        p1[3] = (bkp[0] & S3_P1_MASK) >> S3_P1_SHIFT;
 139                        p1[4] = (bkp[1] & S4_P1_MASK);
 140                        p1[5] = (bkp[1] & S5_P1_MASK) >> S5_P1_SHIFT;
 141                        p1[6] = (bkp[1] & S6_P1_MASK) >> S6_P1_SHIFT;
 142                        p1[7] = (bkp[1] & S7_P1_MASK) >> S7_P1_SHIFT;
 143                        p1[8] = (bkp[2] & S8_P1_MASK_BKP) >> S8_P1_SHIFT;
 144                        p1[9] = (bkp[2] & S9_P1_MASK_BKP) >> S9_P1_BKP_SHIFT;
 145                        p1[10] = (bkp[2] & S10_P1_MASK_BKP) >> S10_P1_BKP_SHIFT;
 146                        break;
 147                }
 148        } else {
 149                mode = (calib[1] & CAL_SEL_0_1) >> CAL_SEL_SHIFT;
 150                mode |= (calib[3] & CAL_SEL_2) >> CAL_SEL_SHIFT_2;
 151
 152                switch (mode) {
 153                case TWO_PT_CALIB:
 154                        base2 = (calib[2] & BASE2_MASK) >> BASE2_SHIFT;
 155                        p2[0] = (calib[2] & S0_P2_MASK) >> S0_P2_SHIFT;
 156                        p2[1] = (calib[2] & S1_P2_MASK) >> S1_P2_SHIFT;
 157                        p2[2] = (calib[3] & S2_P2_MASK);
 158                        p2[3] = (calib[3] & S3_P2_MASK) >> S3_P2_SHIFT;
 159                        p2[4] = (calib[3] & S4_P2_MASK) >> S4_P2_SHIFT;
 160                        p2[5] = (calib[3] & S5_P2_MASK) >> S5_P2_SHIFT;
 161                        p2[6] = (calib[3] & S6_P2_MASK) >> S6_P2_SHIFT;
 162                        p2[7] = (calib[4] & S7_P2_MASK);
 163                        p2[8] = (calib[4] & S8_P2_MASK) >> S8_P2_SHIFT;
 164                        p2[9] = (calib[4] & S9_P2_MASK) >> S9_P2_SHIFT;
 165                        p2[10] = (calib[4] & S10_P2_MASK) >> S10_P2_SHIFT;
 166                        /* Fall through */
 167                case ONE_PT_CALIB:
 168                case ONE_PT_CALIB2:
 169                        base1 = calib[0] & BASE1_MASK;
 170                        p1[0] = (calib[0] & S0_P1_MASK) >> S0_P1_SHIFT;
 171                        p1[1] = (calib[0] & S1_P1_MASK) >> S1_P1_SHIFT;
 172                        p1[2] = (calib[0] & S2_P1_MASK) >> S2_P1_SHIFT;
 173                        p1[3] = (calib[0] & S3_P1_MASK) >> S3_P1_SHIFT;
 174                        p1[4] = (calib[1] & S4_P1_MASK);
 175                        p1[5] = (calib[1] & S5_P1_MASK) >> S5_P1_SHIFT;
 176                        p1[6] = (calib[1] & S6_P1_MASK) >> S6_P1_SHIFT;
 177                        p1[7] = (calib[1] & S7_P1_MASK) >> S7_P1_SHIFT;
 178                        p1[8] = (calib[1] & S8_P1_MASK) >> S8_P1_SHIFT;
 179                        p1[9] = (calib[2] & S9_P1_MASK);
 180                        p1[10] = (calib[2] & S10_P1_MASK) >> S10_P1_SHIFT;
 181                        break;
 182                }
 183        }
 184
 185        switch (mode) {
 186        case ONE_PT_CALIB:
 187                for (i = 0; i < tmdev->num_sensors; i++)
 188                        p1[i] += (base1 << 2) | BIT_APPEND;
 189                break;
 190        case TWO_PT_CALIB:
 191                for (i = 0; i < tmdev->num_sensors; i++) {
 192                        p2[i] += base2;
 193                        p2[i] <<= 2;
 194                        p2[i] |= BIT_APPEND;
 195                }
 196                /* Fall through */
 197        case ONE_PT_CALIB2:
 198                for (i = 0; i < tmdev->num_sensors; i++) {
 199                        p1[i] += base1;
 200                        p1[i] <<= 2;
 201                        p1[i] |= BIT_APPEND;
 202                }
 203                break;
 204        default:
 205                for (i = 0; i < tmdev->num_sensors; i++)
 206                        p2[i] = 780;
 207                p1[0] = 502;
 208                p1[1] = 509;
 209                p1[2] = 503;
 210                p1[3] = 509;
 211                p1[4] = 505;
 212                p1[5] = 509;
 213                p1[6] = 507;
 214                p1[7] = 510;
 215                p1[8] = 508;
 216                p1[9] = 509;
 217                p1[10] = 508;
 218                break;
 219        }
 220
 221        compute_intercept_slope(tmdev, p1, p2, mode);
 222
 223        return 0;
 224}
 225
 226static const struct tsens_ops ops_8974 = {
 227        .init           = init_common,
 228        .calibrate      = calibrate_8974,
 229        .get_temp       = get_temp_common,
 230};
 231
 232const struct tsens_data data_8974 = {
 233        .num_sensors    = 11,
 234        .ops            = &ops_8974,
 235        .reg_offsets    = { [SROT_CTRL_OFFSET] = 0x0 },
 236};
 237