blob: 9b10a1b2ce1a71ae3bed394ff6d9ab8adca3e88c [file] [log] [blame]
Siddartha Mohanadoss41b4cd92017-02-21 14:34:23 -08001/* Copyright (c) 2017, The Linux Foundation. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
Siddartha Mohanadosscd8aa0b2017-04-06 15:17:46 -07004 * it under the terms of the GNU General Public License version 2 and
Siddartha Mohanadoss41b4cd92017-02-21 14:34:23 -08005 * 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 <asm/arch_timer.h>
15#include "tsens.h"
16
17/* debug defines */
18#define TSENS_DBG_BUS_ID_0 0
19#define TSENS_DBG_BUS_ID_1 1
20#define TSENS_DBG_BUS_ID_2 2
21#define TSENS_DBG_BUS_ID_15 15
22#define TSENS_DEBUG_LOOP_COUNT_ID_0 2
23#define TSENS_DEBUG_LOOP_COUNT 5
24#define TSENS_DEBUG_STATUS_REG_START 10
25#define TSENS_DEBUG_OFFSET_RANGE 16
26#define TSENS_DEBUG_OFFSET_WORD1 0x4
27#define TSENS_DEBUG_OFFSET_WORD2 0x8
28#define TSENS_DEBUG_OFFSET_WORD3 0xc
29#define TSENS_DEBUG_OFFSET_ROW 0x10
30#define TSENS_DEBUG_DECIDEGC -950
31#define TSENS_DEBUG_CYCLE_MS 64
32#define TSENS_DEBUG_POLL_MS 200
33#define TSENS_DEBUG_BUS_ID2_MIN_CYCLE 50
34#define TSENS_DEBUG_BUS_ID2_MAX_CYCLE 51
35#define TSENS_DEBUG_ID_MASK_1_4 0xffffffe1
36#define DEBUG_SIZE 10
37
Siddartha Mohanadoss64a5da32017-05-09 11:09:51 -070038#define TSENS_DEBUG_CONTROL(n) ((n) + 0x130)
39#define TSENS_DEBUG_DATA(n) ((n) + 0x134)
Siddartha Mohanadoss41b4cd92017-02-21 14:34:23 -080040
41struct tsens_dbg_func {
42 int (*dbg_func)(struct tsens_device *, u32, u32, int *);
43};
44
45static int tsens_dbg_log_temp_reads(struct tsens_device *data, u32 id,
46 u32 dbg_type, int *temp)
47{
48 struct tsens_sensor *sensor;
49 struct tsens_device *tmdev = NULL;
50 u32 idx = 0;
51
52 if (!data)
53 return -EINVAL;
54
55 pr_debug("%d %d\n", id, dbg_type);
56 tmdev = data;
57 sensor = &tmdev->sensor[id];
58 idx = tmdev->tsens_dbg.sensor_dbg_info[sensor->hw_id].idx;
59 tmdev->tsens_dbg.sensor_dbg_info[sensor->hw_id].temp[idx%10] = *temp;
60 tmdev->tsens_dbg.sensor_dbg_info[sensor->hw_id].time_stmp[idx%10] =
61 sched_clock();
62 idx++;
63 tmdev->tsens_dbg.sensor_dbg_info[sensor->hw_id].idx = idx;
64
65 return 0;
66}
67
68static int tsens_dbg_log_interrupt_timestamp(struct tsens_device *data,
69 u32 id, u32 dbg_type, int *val)
70{
71 struct tsens_device *tmdev = NULL;
72 u32 idx = 0;
73
74 if (!data)
75 return -EINVAL;
76
77 pr_debug("%d %d\n", id, dbg_type);
78 tmdev = data;
79 /* debug */
80 idx = tmdev->tsens_dbg.tsens_thread_iq_dbg.idx;
81 tmdev->tsens_dbg.tsens_thread_iq_dbg.dbg_count[idx%10]++;
82 tmdev->tsens_dbg.tsens_thread_iq_dbg.time_stmp[idx%10] =
83 sched_clock();
84 tmdev->tsens_dbg.tsens_thread_iq_dbg.idx++;
85
86 return 0;
87}
88
Siddartha Mohanadoss64a5da32017-05-09 11:09:51 -070089static int tsens_dbg_log_bus_id_data(struct tsens_device *data,
90 u32 id, u32 dbg_type, int *val)
91{
92 struct tsens_device *tmdev = NULL;
93 u32 loop = 0, i = 0;
94 uint32_t r1, r2, r3, r4, offset = 0;
95 unsigned int debug_dump;
96 unsigned int debug_id = 0, cntrl_id = 0;
97 void __iomem *srot_addr;
98 void __iomem *controller_id_addr;
99 void __iomem *debug_id_addr;
100 void __iomem *debug_data_addr;
101
102 if (!data)
103 return -EINVAL;
104
105 pr_debug("%d %d\n", id, dbg_type);
106 tmdev = data;
107 controller_id_addr = TSENS_CONTROLLER_ID(tmdev->tsens_tm_addr);
108 debug_id_addr = TSENS_DEBUG_CONTROL(tmdev->tsens_tm_addr);
109 debug_data_addr = TSENS_DEBUG_DATA(tmdev->tsens_tm_addr);
110 srot_addr = TSENS_CTRL_ADDR(tmdev->tsens_srot_addr);
111
112 cntrl_id = readl_relaxed(controller_id_addr);
113 pr_err("Controller_id: 0x%x\n", cntrl_id);
114
115 loop = 0;
116 i = 0;
117 debug_id = readl_relaxed(debug_id_addr);
118 writel_relaxed((debug_id | (i << 1) | 1),
119 TSENS_DEBUG_CONTROL(tmdev->tsens_tm_addr));
120 while (loop < TSENS_DEBUG_LOOP_COUNT_ID_0) {
121 debug_dump = readl_relaxed(debug_data_addr);
122 r1 = readl_relaxed(debug_data_addr);
123 r2 = readl_relaxed(debug_data_addr);
124 r3 = readl_relaxed(debug_data_addr);
125 r4 = readl_relaxed(debug_data_addr);
126 pr_err("cntrl:%d, bus-id:%d value:0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n",
127 cntrl_id, i, debug_dump, r1, r2, r3, r4);
128 loop++;
129 }
130
131 for (i = TSENS_DBG_BUS_ID_1; i <= TSENS_DBG_BUS_ID_15; i++) {
132 loop = 0;
133 debug_id = readl_relaxed(debug_id_addr);
134 debug_id = debug_id & TSENS_DEBUG_ID_MASK_1_4;
135 writel_relaxed((debug_id | (i << 1) | 1),
136 TSENS_DEBUG_CONTROL(tmdev->tsens_tm_addr));
137 while (loop < TSENS_DEBUG_LOOP_COUNT) {
138 debug_dump = readl_relaxed(debug_data_addr);
139 pr_err("cntrl:%d, bus-id:%d with value: 0x%x\n",
140 cntrl_id, i, debug_dump);
141 if (i == TSENS_DBG_BUS_ID_2)
142 usleep_range(
143 TSENS_DEBUG_BUS_ID2_MIN_CYCLE,
144 TSENS_DEBUG_BUS_ID2_MAX_CYCLE);
145 loop++;
146 }
147 }
148
149 pr_err("Start of TSENS TM dump\n");
150 for (i = 0; i < TSENS_DEBUG_OFFSET_RANGE; i++) {
151 r1 = readl_relaxed(controller_id_addr + offset);
152 r2 = readl_relaxed(controller_id_addr + (offset +
153 TSENS_DEBUG_OFFSET_WORD1));
154 r3 = readl_relaxed(controller_id_addr + (offset +
155 TSENS_DEBUG_OFFSET_WORD2));
156 r4 = readl_relaxed(controller_id_addr + (offset +
157 TSENS_DEBUG_OFFSET_WORD3));
158
159 pr_err("ctrl:%d:0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
160 cntrl_id, offset, r1, r2, r3, r4);
161 offset += TSENS_DEBUG_OFFSET_ROW;
162 }
163
164 offset = 0;
165 pr_err("Start of TSENS SROT dump\n");
166 for (i = 0; i < TSENS_DEBUG_OFFSET_RANGE; i++) {
167 r1 = readl_relaxed(srot_addr + offset);
168 r2 = readl_relaxed(srot_addr + (offset +
169 TSENS_DEBUG_OFFSET_WORD1));
170 r3 = readl_relaxed(srot_addr + (offset +
171 TSENS_DEBUG_OFFSET_WORD2));
172 r4 = readl_relaxed(srot_addr + (offset +
173 TSENS_DEBUG_OFFSET_WORD3));
174
175 pr_err("ctrl:%d:0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
176 cntrl_id, offset, r1, r2, r3, r4);
177 offset += TSENS_DEBUG_OFFSET_ROW;
178 }
179
180 loop = 0;
181 while (loop < TSENS_DEBUG_LOOP_COUNT) {
182 offset = TSENS_DEBUG_OFFSET_ROW *
183 TSENS_DEBUG_STATUS_REG_START;
184 pr_err("Start of TSENS TM dump %d\n", loop);
185 /* Limited dump of the registers for the temperature */
186 for (i = 0; i < TSENS_DEBUG_LOOP_COUNT; i++) {
187 r1 = readl_relaxed(controller_id_addr + offset);
188 r2 = readl_relaxed(controller_id_addr +
189 (offset + TSENS_DEBUG_OFFSET_WORD1));
190 r3 = readl_relaxed(controller_id_addr +
191 (offset + TSENS_DEBUG_OFFSET_WORD2));
192 r4 = readl_relaxed(controller_id_addr +
193 (offset + TSENS_DEBUG_OFFSET_WORD3));
194
195 pr_err("ctrl:%d:0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
196 cntrl_id, offset, r1, r2, r3, r4);
197 offset += TSENS_DEBUG_OFFSET_ROW;
198 }
199 loop++;
200 }
201
202 return 0;
203}
204
Siddartha Mohanadoss41b4cd92017-02-21 14:34:23 -0800205static struct tsens_dbg_func dbg_arr[] = {
206 [TSENS_DBG_LOG_TEMP_READS] = {tsens_dbg_log_temp_reads},
207 [TSENS_DBG_LOG_INTERRUPT_TIMESTAMP] = {
208 tsens_dbg_log_interrupt_timestamp},
Siddartha Mohanadoss64a5da32017-05-09 11:09:51 -0700209 [TSENS_DBG_LOG_BUS_ID_DATA] = {tsens_dbg_log_bus_id_data},
Siddartha Mohanadoss41b4cd92017-02-21 14:34:23 -0800210};
211
212int tsens2xxx_dbg(struct tsens_device *data, u32 id, u32 dbg_type, int *val)
213{
214 if (dbg_type >= TSENS_DBG_LOG_MAX)
215 return -EINVAL;
216
217 dbg_arr[dbg_type].dbg_func(data, id, dbg_type, val);
218
219 return 0;
220}
221EXPORT_SYMBOL(tsens2xxx_dbg);