staging: mt7621-mmc: Fix lines over 80 characters in dbg.c
[linux/fpc-iii.git] / drivers / staging / mt7621-mmc / dbg.c
blob829d3d0e895ee3306c1080ecbfe1a32a0b903aa1
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
9 * prohibited.
11 * MediaTek Inc. (C) 2010. All rights reserved.
13 * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
14 * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
15 * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
16 * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
19 * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
20 * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
21 * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO
22 * SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY
23 * ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY
24 * THIRD PARTY ALL PROPER LICENSES CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK
25 * SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO
26 * RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN
27 * FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
28 * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED
29 * HEREUNDER WILL BE, AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK
30 * SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE
31 * PAID BY RECEIVER TO MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
33 * The following software/firmware and/or related documentation
34 * ("MediaTek Software") have been modified by MediaTek Inc. All revisions
35 * are subject to any receiver's applicable license agreements with MediaTek
36 * Inc.
39 #include <linux/version.h>
40 #include <linux/kernel.h>
41 #include <linux/sched.h>
42 #include <linux/kthread.h>
43 #include <linux/delay.h>
44 #include <linux/module.h>
45 #include <linux/init.h>
46 #include <linux/proc_fs.h>
47 #include <linux/string.h>
48 #include <linux/uaccess.h>
49 // #include <mach/mt6575_gpt.h> /* --- by chhung */
50 #include "dbg.h"
51 #include "mt6575_sd.h"
52 #include <linux/seq_file.h>
54 static char cmd_buf[256];
56 /* for debug zone */
57 unsigned int sd_debug_zone[4] = {
64 #if defined(MT6575_SD_DEBUG)
65 /* for driver profile */
66 #define TICKS_ONE_MS (13000)
67 u32 gpt_enable;
68 u32 sdio_pro_enable; /* make sure gpt is enabled */
69 u32 sdio_pro_time; /* no more than 30s */
70 struct sdio_profile sdio_perfomance = {0};
72 u32 msdc_time_calc(u32 old_L32, u32 old_H32, u32 new_L32, u32 new_H32)
74 u32 ret = 0;
76 if (new_H32 == old_H32) {
77 ret = new_L32 - old_L32;
78 } else if (new_H32 == (old_H32 + 1)) {
79 if (new_L32 > old_L32)
80 pr_debug("msdc old_L<0x%x> new_L<0x%x>\n",
81 old_L32, new_L32);
82 ret = (0xffffffff - old_L32);
83 ret += new_L32;
84 } else {
85 pr_debug("msdc old_H<0x%x> new_H<0x%x>\n", old_H32, new_H32);
88 return ret;
91 void msdc_sdio_profile(struct sdio_profile *result)
93 struct cmd_profile *cmd;
94 u32 i;
96 pr_debug("sdio === performance dump ===\n");
97 pr_debug("sdio === total execute tick<%d> time<%dms> Tx<%dB> Rx<%dB>\n",
98 result->total_tc, result->total_tc / TICKS_ONE_MS,
99 result->total_tx_bytes, result->total_rx_bytes);
101 /* CMD52 Dump */
102 cmd = &result->cmd52_rx;
103 pr_debug("sdio === CMD52 Rx <%d>times tick<%d> Max<%d> Min<%d> Aver<%d>\n",
104 cmd->count, cmd->tot_tc, cmd->max_tc, cmd->min_tc,
105 cmd->tot_tc / cmd->count);
106 cmd = &result->cmd52_tx;
107 pr_debug("sdio === CMD52 Tx <%d>times tick<%d> Max<%d> Min<%d> Aver<%d>\n",
108 cmd->count, cmd->tot_tc, cmd->max_tc, cmd->min_tc,
109 cmd->tot_tc / cmd->count);
111 /* CMD53 Rx bytes + block mode */
112 for (i = 0; i < 512; i++) {
113 cmd = &result->cmd53_rx_byte[i];
114 if (cmd->count) {
115 pr_debug("sdio<%6d><%3dB>_Rx_<%9d><%9d><%6d><%6d>_<%9dB><%2dM>\n",
116 cmd->count, i, cmd->tot_tc, cmd->max_tc,
117 cmd->min_tc, cmd->tot_tc / cmd->count,
118 cmd->tot_bytes,
119 (cmd->tot_bytes / 10) * 13 / (cmd->tot_tc / 10));
122 for (i = 0; i < 100; i++) {
123 cmd = &result->cmd53_rx_blk[i];
124 if (cmd->count) {
125 pr_debug("sdio<%6d><%3d>B_Rx_<%9d><%9d><%6d><%6d>_<%9dB><%2dM>\n",
126 cmd->count, i, cmd->tot_tc, cmd->max_tc,
127 cmd->min_tc, cmd->tot_tc / cmd->count,
128 cmd->tot_bytes,
129 (cmd->tot_bytes / 10) * 13 / (cmd->tot_tc / 10));
133 /* CMD53 Tx bytes + block mode */
134 for (i = 0; i < 512; i++) {
135 cmd = &result->cmd53_tx_byte[i];
136 if (cmd->count) {
137 pr_debug("sdio<%6d><%3dB>_Tx_<%9d><%9d><%6d><%6d>_<%9dB><%2dM>\n",
138 cmd->count, i, cmd->tot_tc, cmd->max_tc,
139 cmd->min_tc, cmd->tot_tc / cmd->count,
140 cmd->tot_bytes,
141 (cmd->tot_bytes / 10) * 13 / (cmd->tot_tc / 10));
144 for (i = 0; i < 100; i++) {
145 cmd = &result->cmd53_tx_blk[i];
146 if (cmd->count) {
147 pr_debug("sdio<%6d><%3d>B_Tx_<%9d><%9d><%6d><%6d>_<%9dB><%2dM>\n",
148 cmd->count, i, cmd->tot_tc, cmd->max_tc,
149 cmd->min_tc, cmd->tot_tc / cmd->count,
150 cmd->tot_bytes,
151 (cmd->tot_bytes / 10) * 13 / (cmd->tot_tc / 10));
155 pr_debug("sdio === performance dump done ===\n");
158 //========= sdio command table ===========
159 void msdc_performance(u32 opcode, u32 sizes, u32 bRx, u32 ticks)
161 struct sdio_profile *result = &sdio_perfomance;
162 struct cmd_profile *cmd;
163 u32 block;
165 if (sdio_pro_enable == 0)
166 return;
168 if (opcode == 52) {
169 cmd = bRx ? &result->cmd52_rx : &result->cmd52_tx;
170 } else if (opcode == 53) {
171 if (sizes < 512) {
172 cmd = bRx ? &result->cmd53_rx_byte[sizes] : &result->cmd53_tx_byte[sizes];
173 } else {
174 block = sizes / 512;
175 if (block >= 99) {
176 pr_err("cmd53 error blocks\n");
177 while (1)
180 cmd = bRx ? &result->cmd53_rx_blk[block] : &result->cmd53_tx_blk[block];
182 } else {
183 return;
186 /* update the members */
187 if (ticks > cmd->max_tc)
188 cmd->max_tc = ticks;
189 if (cmd->min_tc == 0 || ticks < cmd->min_tc)
190 cmd->min_tc = ticks;
191 cmd->tot_tc += ticks;
192 cmd->tot_bytes += sizes;
193 cmd->count++;
195 if (bRx)
196 result->total_rx_bytes += sizes;
197 else
198 result->total_tx_bytes += sizes;
199 result->total_tc += ticks;
201 /* dump when total_tc > 30s */
202 if (result->total_tc >= sdio_pro_time * TICKS_ONE_MS * 1000) {
203 msdc_sdio_profile(result);
204 memset(result, 0, sizeof(struct sdio_profile));
208 //========== driver proc interface ===========
209 static int msdc_debug_proc_read(struct seq_file *s, void *p)
211 seq_puts(s, "\n=========================================\n");
212 seq_puts(s, "Index<0> + Id + Zone\n");
213 seq_puts(s, "-> PWR<9> WRN<8> | FIO<7> OPS<6> FUN<5> CFG<4> | INT<3> RSP<2> CMD<1> DMA<0>\n");
214 seq_puts(s, "-> echo 0 3 0x3ff >msdc_bebug -> host[3] debug zone set to 0x3ff\n");
215 seq_printf(s, "-> MSDC[0] Zone: 0x%.8x\n", sd_debug_zone[0]);
216 seq_printf(s, "-> MSDC[1] Zone: 0x%.8x\n", sd_debug_zone[1]);
217 seq_printf(s, "-> MSDC[2] Zone: 0x%.8x\n", sd_debug_zone[2]);
218 seq_printf(s, "-> MSDC[3] Zone: 0x%.8x\n", sd_debug_zone[3]);
220 seq_puts(s, "Index<3> + SDIO_PROFILE + TIME\n");
221 seq_puts(s, "-> echo 3 1 0x1E >msdc_bebug -> enable sdio_profile, 30s\n");
222 seq_printf(s, "-> SDIO_PROFILE<%d> TIME<%ds>\n",
223 sdio_pro_enable, sdio_pro_time);
224 seq_puts(s, "=========================================\n\n");
226 return 0;
229 static ssize_t msdc_debug_proc_write(struct file *file,
230 const char __user *buf,
231 size_t count, loff_t *data)
233 int ret;
235 int cmd, p1, p2;
236 int id, zone;
237 int mode, size;
239 if (count == 0)
240 return -1;
241 if (count > 255)
242 count = 255;
244 if (copy_from_user(cmd_buf, buf, count))
245 return -EFAULT;
247 cmd_buf[count] = '\0';
248 pr_debug("msdc Write %s\n", cmd_buf);
250 ret = sscanf(cmd_buf, "%x %x %x", &cmd, &p1, &p2);
251 if (ret != 3)
252 return -EINVAL;
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 gpt_enable = 1;
271 sdio_pro_enable = 1;
272 if (p2 == 0)
273 p2 = 1;
274 if (p2 >= 30)
275 p2 = 30;
276 sdio_pro_time = p2;
277 } else if (p1 == 0) {
278 /* todo */
279 sdio_pro_enable = 0;
283 return count;
286 static int msdc_debug_show(struct inode *inode, struct file *file)
288 return single_open(file, msdc_debug_proc_read, NULL);
291 static const struct file_operations msdc_debug_fops = {
292 .owner = THIS_MODULE,
293 .open = msdc_debug_show,
294 .read = seq_read,
295 .write = msdc_debug_proc_write,
296 .llseek = seq_lseek,
297 .release = single_release,
300 void msdc_debug_proc_init(void)
302 proc_create("msdc_debug", 0660, NULL, &msdc_debug_fops);
304 EXPORT_SYMBOL_GPL(msdc_debug_proc_init);
305 #endif