blob: 451c6c72aed4265285a595a99caab430df4cf486 [file] [log] [blame]
Rama Krishna Phani A82403082018-03-12 17:09:36 +05301/* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved.
Ashok Jammigumpulaa1b7ec12017-11-23 15:37:44 +05302 *
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
14#include "tsens.h"
15#include "tsens-mtc.h"
16
17struct tsens_device *tsens_controller_is_present(void)
18{
19 struct tsens_device *tmdev_chip = NULL;
20
21 if (list_empty(&tsens_device_list)) {
22 pr_err("%s: TSENS controller not available\n", __func__);
23 return tmdev_chip;
24 }
25
26 list_for_each_entry(tmdev_chip, &tsens_device_list, list)
27 return tmdev_chip;
28
29 return tmdev_chip;
30}
31EXPORT_SYMBOL(tsens_controller_is_present);
32
Rama Krishna Phani A82403082018-03-12 17:09:36 +053033int tsens_mtc_reset_history_counter(unsigned int zone)
Ashok Jammigumpulaa1b7ec12017-11-23 15:37:44 +053034{
35 unsigned int reg_cntl, is_valid;
36 void __iomem *sensor_addr;
37 struct tsens_device *tmdev = NULL;
38
39 if (zone > TSENS_NUM_MTC_ZONES_SUPPORT)
40 return -EINVAL;
41
42 tmdev = tsens_controller_is_present();
43 if (!tmdev) {
44 pr_err("No TSENS controller present\n");
45 return -EPROBE_DEFER;
46 }
47
48 sensor_addr = TSENS_TM_MTC_ZONE0_SW_MASK_ADDR(tmdev->tsens_tm_addr);
49 reg_cntl = readl_relaxed((sensor_addr +
50 (zone * TSENS_SN_ADDR_OFFSET)));
51 is_valid = (reg_cntl & TSENS_RESET_HISTORY_MASK)
52 >> TSENS_RESET_HISTORY_SHIFT;
53 if (!is_valid) {
54 /*Enable the bit to reset counter*/
55 writel_relaxed(reg_cntl | (1 << TSENS_RESET_HISTORY_SHIFT),
56 (sensor_addr + (zone * TSENS_SN_ADDR_OFFSET)));
57 reg_cntl = readl_relaxed((sensor_addr +
58 (zone * TSENS_SN_ADDR_OFFSET)));
59 pr_debug("tsens : zone =%d reg=%x\n", zone, reg_cntl);
60 }
61
62 /*Disble the bit to start counter*/
63 writel_relaxed(reg_cntl & ~(1 << TSENS_RESET_HISTORY_SHIFT),
64 (sensor_addr + (zone * TSENS_SN_ADDR_OFFSET)));
65 reg_cntl = readl_relaxed((sensor_addr +
66 (zone * TSENS_SN_ADDR_OFFSET)));
67 pr_debug("tsens : zone =%d reg=%x\n", zone, reg_cntl);
68
69 return 0;
70}
71EXPORT_SYMBOL(tsens_mtc_reset_history_counter);
72
73int tsens_set_mtc_zone_sw_mask(unsigned int zone, unsigned int th1_enable,
74 unsigned int th2_enable)
75{
76 unsigned int reg_cntl;
77 void __iomem *sensor_addr;
78 struct tsens_device *tmdev = NULL;
79
80 if (zone > TSENS_NUM_MTC_ZONES_SUPPORT)
81 return -EINVAL;
82
83 tmdev = tsens_controller_is_present();
84 if (!tmdev) {
85 pr_err("No TSENS controller present\n");
86 return -EPROBE_DEFER;
87 }
88
89 sensor_addr = TSENS_TM_MTC_ZONE0_SW_MASK_ADDR
90 (tmdev->tsens_tm_addr);
91
92 if (th1_enable && th2_enable)
93 writel_relaxed(TSENS_MTC_IN_EFFECT,
94 (sensor_addr +
95 (zone * TSENS_SN_ADDR_OFFSET)));
96 if (!th1_enable && !th2_enable)
97 writel_relaxed(TSENS_MTC_DISABLE,
98 (sensor_addr +
99 (zone * TSENS_SN_ADDR_OFFSET)));
100 if (th1_enable && !th2_enable)
101 writel_relaxed(TSENS_TH1_MTC_IN_EFFECT,
102 (sensor_addr +
103 (zone * TSENS_SN_ADDR_OFFSET)));
104 if (!th1_enable && th2_enable)
105 writel_relaxed(TSENS_TH2_MTC_IN_EFFECT,
106 (sensor_addr +
107 (zone * TSENS_SN_ADDR_OFFSET)));
108 reg_cntl = readl_relaxed((sensor_addr +
109 (zone * TSENS_SN_ADDR_OFFSET)));
110 pr_debug("tsens : zone =%d th1=%d th2=%d reg=%x\n",
111 zone, th1_enable, th2_enable, reg_cntl);
112
113 return 0;
114}
115EXPORT_SYMBOL(tsens_set_mtc_zone_sw_mask);
116
117int tsens_get_mtc_zone_log(unsigned int zone, void *zone_log)
118{
119 unsigned int i, reg_cntl, is_valid, log[TSENS_MTC_ZONE_LOG_SIZE];
120 int *zlog = (int *)zone_log;
121 void __iomem *sensor_addr;
122 struct tsens_device *tmdev = NULL;
123
124 if (zone > TSENS_NUM_MTC_ZONES_SUPPORT)
125 return -EINVAL;
126
127 tmdev = tsens_controller_is_present();
128 if (!tmdev) {
129 pr_err("No TSENS controller present\n");
130 return -EPROBE_DEFER;
131 }
132
133 sensor_addr = TSENS_TM_MTC_ZONE0_LOG(tmdev->tsens_tm_addr);
134
135 reg_cntl = readl_relaxed((sensor_addr +
136 (zone * TSENS_SN_ADDR_OFFSET)));
137 is_valid = (reg_cntl & TSENS_LOGS_VALID_MASK)
138 >> TSENS_LOGS_VALID_SHIFT;
139 if (is_valid) {
140 log[0] = (reg_cntl & TSENS_LOGS_LATEST_MASK);
141 log[1] = (reg_cntl & TSENS_LOGS_LOG1_MASK)
142 >> TSENS_LOGS_LOG1_SHIFT;
143 log[2] = (reg_cntl & TSENS_LOGS_LOG2_MASK)
144 >> TSENS_LOGS_LOG2_SHIFT;
145 log[3] = (reg_cntl & TSENS_LOGS_LOG3_MASK)
146 >> TSENS_LOGS_LOG3_SHIFT;
147 log[4] = (reg_cntl & TSENS_LOGS_LOG4_MASK)
148 >> TSENS_LOGS_LOG4_SHIFT;
149 log[5] = (reg_cntl & TSENS_LOGS_LOG5_MASK)
150 >> TSENS_LOGS_LOG5_SHIFT;
151 for (i = 0; i < (TSENS_MTC_ZONE_LOG_SIZE); i++) {
152 *(zlog+i) = log[i];
153 pr_debug("Log[%d]=%d\n", i, log[i]);
154 }
155 } else {
156 pr_debug("tsens: Valid bit disabled\n");
157 return -EINVAL;
158 }
159 return 0;
160}
161EXPORT_SYMBOL(tsens_get_mtc_zone_log);
162
163int tsens_get_mtc_zone_history(unsigned int zone, void *zone_hist)
164{
165 unsigned int i, reg_cntl, hist[TSENS_MTC_ZONE_HISTORY_SIZE];
166 int *zhist = (int *)zone_hist;
167 void __iomem *sensor_addr;
168 struct tsens_device *tmdev = NULL;
169
170 if (zone > TSENS_NUM_MTC_ZONES_SUPPORT)
171 return -EINVAL;
172
173 tmdev = tsens_controller_is_present();
174 if (!tmdev) {
175 pr_err("No TSENS controller present\n");
176 return -EPROBE_DEFER;
177 }
178
179 sensor_addr = TSENS_TM_MTC_ZONE0_HISTORY(tmdev->tsens_tm_addr);
180 reg_cntl = readl_relaxed((sensor_addr +
181 (zone * TSENS_SN_ADDR_OFFSET)));
182
183 hist[0] = (reg_cntl & TSENS_PS_COOL_CMD_MASK);
184 hist[1] = (reg_cntl & TSENS_PS_YELLOW_CMD_MASK)
185 >> TSENS_PS_YELLOW_CMD_SHIFT;
186 hist[2] = (reg_cntl & TSENS_PS_RED_CMD_MASK)
187 >> TSENS_PS_RED_CMD_SHIFT;
188 for (i = 0; i < (TSENS_MTC_ZONE_HISTORY_SIZE); i++) {
189 *(zhist+i) = hist[i];
190 pr_debug("tsens : %d\n", hist[i]);
191 }
192
193 return 0;
194}
195EXPORT_SYMBOL(tsens_get_mtc_zone_history);