Linux 4.19.133
[linux/fpc-iii.git] / drivers / staging / mt7621-mmc / dbg.c
blob6e518dce9029afde7b682e5ddb536942b774ef4b
1 /* Copyright Statement:
3 * This software/firmware and related documentation ("MediaTek Software") are
4 * protected under relevant copyright laws. The information contained herein
5 * is confidential and proprietary to MediaTek Inc. and/or its licensors.
6 * Without the prior written permission of MediaTek inc. and/or its licensors,
7 * any reproduction, modification, use or disclosure of MediaTek Software,
8 * and information contained herein, in whole or in part, shall be strictly prohibited.
10 * MediaTek Inc. (C) 2010. All rights reserved.
12 * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
13 * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
14 * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
15 * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
18 * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
19 * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
20 * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
21 * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
22 * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
23 * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
24 * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
25 * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
26 * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
27 * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
28 * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
29 * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
31 * The following software/firmware and/or related documentation ("MediaTek Software")
32 * have been modified by MediaTek Inc. All revisions are subject to any receiver's
33 * applicable license agreements with MediaTek Inc.
36 #include <linux/version.h>
37 #include <linux/kernel.h>
38 #include <linux/sched.h>
39 #include <linux/kthread.h>
40 #include <linux/delay.h>
41 #include <linux/module.h>
42 #include <linux/init.h>
43 #include <linux/proc_fs.h>
44 #include <linux/string.h>
45 #include <linux/uaccess.h>
46 // #include <mach/mt6575_gpt.h> /* --- by chhung */
47 #include "dbg.h"
48 #include "mt6575_sd.h"
49 #include <linux/seq_file.h>
51 static char cmd_buf[256];
53 /* for debug zone */
54 unsigned int sd_debug_zone[4] = {
61 #if defined(MT6575_SD_DEBUG)
62 /* for driver profile */
63 #define TICKS_ONE_MS (13000)
64 u32 gpt_enable;
65 u32 sdio_pro_enable; /* make sure gpt is enabled */
66 u32 sdio_pro_time; /* no more than 30s */
67 struct sdio_profile sdio_perfomance = {0};
69 #if 0 /* --- chhung */
70 void msdc_init_gpt(void)
72 GPT_CONFIG config;
74 config.num = GPT6;
75 config.mode = GPT_FREE_RUN;
76 config.clkSrc = GPT_CLK_SRC_SYS;
77 config.clkDiv = GPT_CLK_DIV_1; /* 13MHz GPT6 */
79 if (GPT_Config(config) == FALSE)
80 return;
82 GPT_Start(GPT6);
84 #endif /* end of --- */
86 u32 msdc_time_calc(u32 old_L32, u32 old_H32, u32 new_L32, u32 new_H32)
88 u32 ret = 0;
90 if (new_H32 == old_H32) {
91 ret = new_L32 - old_L32;
92 } else if (new_H32 == (old_H32 + 1)) {
93 if (new_L32 > old_L32)
94 pr_debug("msdc old_L<0x%x> new_L<0x%x>\n", old_L32, new_L32);
95 ret = (0xffffffff - old_L32);
96 ret += new_L32;
97 } else {
98 pr_debug("msdc old_H<0x%x> new_H<0x%x>\n", old_H32, new_H32);
101 return ret;
104 void msdc_sdio_profile(struct sdio_profile *result)
106 struct cmd_profile *cmd;
107 u32 i;
109 pr_debug("sdio === performance dump ===\n");
110 pr_debug("sdio === total execute tick<%d> time<%dms> Tx<%dB> Rx<%dB>\n",
111 result->total_tc, result->total_tc / TICKS_ONE_MS,
112 result->total_tx_bytes, result->total_rx_bytes);
114 /* CMD52 Dump */
115 cmd = &result->cmd52_rx;
116 pr_debug("sdio === CMD52 Rx <%d>times tick<%d> Max<%d> Min<%d> Aver<%d>\n", cmd->count, cmd->tot_tc,
117 cmd->max_tc, cmd->min_tc, cmd->tot_tc / cmd->count);
118 cmd = &result->cmd52_tx;
119 pr_debug("sdio === CMD52 Tx <%d>times tick<%d> Max<%d> Min<%d> Aver<%d>\n", cmd->count, cmd->tot_tc,
120 cmd->max_tc, cmd->min_tc, cmd->tot_tc / cmd->count);
122 /* CMD53 Rx bytes + block mode */
123 for (i = 0; i < 512; i++) {
124 cmd = &result->cmd53_rx_byte[i];
125 if (cmd->count) {
126 pr_debug("sdio<%6d><%3dB>_Rx_<%9d><%9d><%6d><%6d>_<%9dB><%2dM>\n", cmd->count, i, cmd->tot_tc,
127 cmd->max_tc, cmd->min_tc, cmd->tot_tc / cmd->count,
128 cmd->tot_bytes, (cmd->tot_bytes / 10) * 13 / (cmd->tot_tc / 10));
131 for (i = 0; i < 100; i++) {
132 cmd = &result->cmd53_rx_blk[i];
133 if (cmd->count) {
134 pr_debug("sdio<%6d><%3d>B_Rx_<%9d><%9d><%6d><%6d>_<%9dB><%2dM>\n", cmd->count, i, cmd->tot_tc,
135 cmd->max_tc, cmd->min_tc, cmd->tot_tc / cmd->count,
136 cmd->tot_bytes, (cmd->tot_bytes / 10) * 13 / (cmd->tot_tc / 10));
140 /* CMD53 Tx bytes + block mode */
141 for (i = 0; i < 512; i++) {
142 cmd = &result->cmd53_tx_byte[i];
143 if (cmd->count) {
144 pr_debug("sdio<%6d><%3dB>_Tx_<%9d><%9d><%6d><%6d>_<%9dB><%2dM>\n", cmd->count, i, cmd->tot_tc,
145 cmd->max_tc, cmd->min_tc, cmd->tot_tc / cmd->count,
146 cmd->tot_bytes, (cmd->tot_bytes / 10) * 13 / (cmd->tot_tc / 10));
149 for (i = 0; i < 100; i++) {
150 cmd = &result->cmd53_tx_blk[i];
151 if (cmd->count) {
152 pr_debug("sdio<%6d><%3d>B_Tx_<%9d><%9d><%6d><%6d>_<%9dB><%2dM>\n", cmd->count, i, cmd->tot_tc,
153 cmd->max_tc, cmd->min_tc, cmd->tot_tc / cmd->count,
154 cmd->tot_bytes, (cmd->tot_bytes / 10) * 13 / (cmd->tot_tc / 10));
158 pr_debug("sdio === performance dump done ===\n");
161 //========= sdio command table ===========
162 void msdc_performance(u32 opcode, u32 sizes, u32 bRx, u32 ticks)
164 struct sdio_profile *result = &sdio_perfomance;
165 struct cmd_profile *cmd;
166 u32 block;
168 if (sdio_pro_enable == 0)
169 return;
171 if (opcode == 52) {
172 cmd = bRx ? &result->cmd52_rx : &result->cmd52_tx;
173 } else if (opcode == 53) {
174 if (sizes < 512) {
175 cmd = bRx ? &result->cmd53_rx_byte[sizes] : &result->cmd53_tx_byte[sizes];
176 } else {
177 block = sizes / 512;
178 if (block >= 99) {
179 pr_err("cmd53 error blocks\n");
180 while (1)
183 cmd = bRx ? &result->cmd53_rx_blk[block] : &result->cmd53_tx_blk[block];
185 } else {
186 return;
189 /* update the members */
190 if (ticks > cmd->max_tc)
191 cmd->max_tc = ticks;
192 if (cmd->min_tc == 0 || ticks < cmd->min_tc)
193 cmd->min_tc = ticks;
194 cmd->tot_tc += ticks;
195 cmd->tot_bytes += sizes;
196 cmd->count++;
198 if (bRx)
199 result->total_rx_bytes += sizes;
200 else
201 result->total_tx_bytes += sizes;
202 result->total_tc += ticks;
204 /* dump when total_tc > 30s */
205 if (result->total_tc >= sdio_pro_time * TICKS_ONE_MS * 1000) {
206 msdc_sdio_profile(result);
207 memset(result, 0, sizeof(struct sdio_profile));
211 //========== driver proc interface ===========
212 static int msdc_debug_proc_read(struct seq_file *s, void *p)
214 seq_puts(s, "\n=========================================\n");
215 seq_puts(s, "Index<0> + Id + Zone\n");
216 seq_puts(s, "-> PWR<9> WRN<8> | FIO<7> OPS<6> FUN<5> CFG<4> | INT<3> RSP<2> CMD<1> DMA<0>\n");
217 seq_puts(s, "-> echo 0 3 0x3ff >msdc_bebug -> host[3] debug zone set to 0x3ff\n");
218 seq_printf(s, "-> MSDC[0] Zone: 0x%.8x\n", sd_debug_zone[0]);
219 seq_printf(s, "-> MSDC[1] Zone: 0x%.8x\n", sd_debug_zone[1]);
220 seq_printf(s, "-> MSDC[2] Zone: 0x%.8x\n", sd_debug_zone[2]);
221 seq_printf(s, "-> MSDC[3] Zone: 0x%.8x\n", sd_debug_zone[3]);
223 seq_puts(s, "Index<3> + SDIO_PROFILE + TIME\n");
224 seq_puts(s, "-> echo 3 1 0x1E >msdc_bebug -> enable sdio_profile, 30s\n");
225 seq_printf(s, "-> SDIO_PROFILE<%d> TIME<%ds>\n", sdio_pro_enable, sdio_pro_time);
226 seq_puts(s, "=========================================\n\n");
228 return 0;
231 static ssize_t msdc_debug_proc_write(struct file *file,
232 const char __user *buf,
233 size_t count, loff_t *data)
235 int ret;
237 int cmd, p1, p2;
238 int id, zone;
239 int mode, size;
241 if (count == 0)
242 return -1;
243 if (count > 255)
244 count = 255;
246 if (copy_from_user(cmd_buf, buf, count))
247 return -EFAULT;
249 cmd_buf[count] = '\0';
250 pr_debug("msdc Write %s\n", cmd_buf);
252 sscanf(cmd_buf, "%x %x %x", &cmd, &p1, &p2);
254 if (cmd == SD_TOOL_ZONE) {
255 id = p1;
256 zone = p2;
257 zone &= 0x3ff;
258 pr_debug("msdc host_id<%d> zone<0x%.8x>\n", id, zone);
259 if (id >= 0 && id <= 3) {
260 sd_debug_zone[id] = zone;
261 } else if (id == 4) {
262 sd_debug_zone[0] = sd_debug_zone[1] = zone;
263 sd_debug_zone[2] = sd_debug_zone[3] = zone;
264 } else {
265 pr_err("msdc host_id error when set debug zone\n");
267 } else if (cmd == SD_TOOL_SDIO_PROFILE) {
268 if (p1 == 1) { /* enable profile */
269 if (gpt_enable == 0) {
270 // msdc_init_gpt(); /* --- by chhung */
271 gpt_enable = 1;
273 sdio_pro_enable = 1;
274 if (p2 == 0)
275 p2 = 1;
276 if (p2 >= 30)
277 p2 = 30;
278 sdio_pro_time = p2;
279 } else if (p1 == 0) {
280 /* todo */
281 sdio_pro_enable = 0;
285 return count;
288 static int msdc_debug_show(struct inode *inode, struct file *file)
290 return single_open(file, msdc_debug_proc_read, NULL);
293 static const struct file_operations msdc_debug_fops = {
294 .owner = THIS_MODULE,
295 .open = msdc_debug_show,
296 .read = seq_read,
297 .write = msdc_debug_proc_write,
298 .llseek = seq_lseek,
299 .release = single_release,
302 void msdc_debug_proc_init(void)
304 proc_create("msdc_debug", 0660, NULL, &msdc_debug_fops);
306 EXPORT_SYMBOL_GPL(msdc_debug_proc_init);
307 #endif