blob: 0a4f2b8fcab6cf840804cfa804b73d24e66a3458 [file] [log] [blame]
Amit Kucheria770324a2018-07-18 12:13:11 +05301// SPDX-License-Identifier: GPL-2.0
Rajendra Nayakd059c732016-05-05 14:21:44 +05302/*
3 * Copyright (c) 2015, The Linux Foundation. All rights reserved.
Amit Kucheria770324a2018-07-18 12:13:11 +05304 * Copyright (c) 2018, Linaro Limited
Rajendra Nayakd059c732016-05-05 14:21:44 +05305 */
6
Amit Kucheria432121a2018-07-26 16:03:10 +05307#include <linux/bitops.h>
Amit Kucheriac1997052019-03-20 18:47:50 +05308#include <linux/regmap.h>
Rajendra Nayakd059c732016-05-05 14:21:44 +05309#include "tsens.h"
10
Amit Kucheriac1997052019-03-20 18:47:50 +053011/* ----- SROT ------ */
12#define SROT_HW_VER_OFF 0x0000
13#define SROT_CTRL_OFF 0x0004
14
15/* ----- TM ------ */
16#define TM_INT_EN_OFF 0x0004
17#define TM_UPPER_LOWER_INT_STATUS_OFF 0x0008
18#define TM_UPPER_LOWER_INT_CLEAR_OFF 0x000c
19#define TM_UPPER_LOWER_INT_MASK_OFF 0x0010
20#define TM_CRITICAL_INT_STATUS_OFF 0x0014
21#define TM_CRITICAL_INT_CLEAR_OFF 0x0018
22#define TM_CRITICAL_INT_MASK_OFF 0x001c
23#define TM_Sn_UPPER_LOWER_THRESHOLD_OFF 0x0020
24#define TM_Sn_CRITICAL_THRESHOLD_OFF 0x0060
25#define TM_Sn_STATUS_OFF 0x00a0
26#define TM_TRDY_OFF 0x00e4
27
Amit Kucheriac1997052019-03-20 18:47:50 +053028/* v2.x: 8996, 8998, sdm845 */
29
30static const struct tsens_features tsens_v2_feat = {
31 .ver_major = VER_2_X,
32 .crit_int = 1,
33 .adc = 0,
34 .srot_split = 1,
Amit Kucheria1b6e3e52019-03-20 18:47:55 +053035 .max_sensors = 16,
Amit Kucheriac1997052019-03-20 18:47:50 +053036};
37
38static const struct reg_field tsens_v2_regfields[MAX_REGFIELDS] = {
39 /* ----- SROT ------ */
40 /* VERSION */
41 [VER_MAJOR] = REG_FIELD(SROT_HW_VER_OFF, 28, 31),
42 [VER_MINOR] = REG_FIELD(SROT_HW_VER_OFF, 16, 27),
43 [VER_STEP] = REG_FIELD(SROT_HW_VER_OFF, 0, 15),
44 /* CTRL_OFF */
45 [TSENS_EN] = REG_FIELD(SROT_CTRL_OFF, 0, 0),
46 [TSENS_SW_RST] = REG_FIELD(SROT_CTRL_OFF, 1, 1),
47
48 /* ----- TM ------ */
49 /* INTERRUPT ENABLE */
50 /* v2 has separate enables for UPPER/LOWER/CRITICAL interrupts */
51 [INT_EN] = REG_FIELD(TM_INT_EN_OFF, 0, 2),
52
53 /* Sn_STATUS */
54 REG_FIELD_FOR_EACH_SENSOR16(LAST_TEMP, TM_Sn_STATUS_OFF, 0, 11),
55 REG_FIELD_FOR_EACH_SENSOR16(VALID, TM_Sn_STATUS_OFF, 21, 21),
56 REG_FIELD_FOR_EACH_SENSOR16(MIN_STATUS, TM_Sn_STATUS_OFF, 16, 16),
57 REG_FIELD_FOR_EACH_SENSOR16(LOWER_STATUS, TM_Sn_STATUS_OFF, 17, 17),
58 REG_FIELD_FOR_EACH_SENSOR16(UPPER_STATUS, TM_Sn_STATUS_OFF, 18, 18),
59 REG_FIELD_FOR_EACH_SENSOR16(CRITICAL_STATUS, TM_Sn_STATUS_OFF, 19, 19),
60 REG_FIELD_FOR_EACH_SENSOR16(MAX_STATUS, TM_Sn_STATUS_OFF, 20, 20),
61
62 /* TRDY: 1=ready, 0=in progress */
63 [TRDY] = REG_FIELD(TM_TRDY_OFF, 0, 0),
64};
65
Amit Kucheria770324a2018-07-18 12:13:11 +053066static const struct tsens_ops ops_generic_v2 = {
Rajendra Nayakd059c732016-05-05 14:21:44 +053067 .init = init_common,
Amit Kucheriac8b61692019-03-20 18:47:57 +053068 .get_temp = get_temp_tsens_valid,
Rajendra Nayakd059c732016-05-05 14:21:44 +053069};
70
Amit Kucheria3c040ce2019-03-20 18:47:42 +053071const struct tsens_plat_data data_tsens_v2 = {
Amit Kucheriac1997052019-03-20 18:47:50 +053072 .ops = &ops_generic_v2,
73 .feat = &tsens_v2_feat,
74 .fields = tsens_v2_regfields,
Amit Kucheria191dc742018-07-18 12:13:12 +053075};
76
77/* Kept around for backward compatibility with old msm8996.dtsi */
Amit Kucheria3c040ce2019-03-20 18:47:42 +053078const struct tsens_plat_data data_8996 = {
Rajendra Nayakd059c732016-05-05 14:21:44 +053079 .num_sensors = 13,
Amit Kucheria770324a2018-07-18 12:13:11 +053080 .ops = &ops_generic_v2,
Amit Kucheriac1997052019-03-20 18:47:50 +053081 .feat = &tsens_v2_feat,
82 .fields = tsens_v2_regfields,
Rajendra Nayakd059c732016-05-05 14:21:44 +053083};