]> Git Repo - linux.git/blob - drivers/staging/mt7621-mmc/dbg.c
mips: vdso: drop unnecessary cc-ldoption
[linux.git] / drivers / staging / mt7621-mmc / dbg.c
1 /* Copyright Statement:
2  *
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.
10  *
11  * MediaTek Inc. (C) 2010. All rights reserved.
12  *
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.
32  *
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.
37  */
38
39 #include <linux/kernel.h>
40 #include <linux/sched.h>
41 #include <linux/kthread.h>
42 #include <linux/delay.h>
43 #include <linux/module.h>
44 #include <linux/init.h>
45 #include <linux/proc_fs.h>
46 #include <linux/string.h>
47 #include <linux/uaccess.h>
48 // #include <mach/mt6575_gpt.h> /* --- by chhung */
49 #include "dbg.h"
50 #include "mt6575_sd.h"
51 #include <linux/seq_file.h>
52
53
54 /* for debug zone */
55 unsigned int sd_debug_zone[4] = {
56         0,
57         0,
58         0,
59         0
60 };
61
62 #if defined(MT6575_SD_DEBUG)
63 static char cmd_buf[256];
64 /* for driver profile */
65 #define TICKS_ONE_MS  (13000)
66 u32 gpt_enable;
67 u32 sdio_pro_enable;   /* make sure gpt is enabled */
68 u32 sdio_pro_time;     /* no more than 30s */
69 struct sdio_profile sdio_perfomance = {0};
70
71 u32 msdc_time_calc(u32 old_L32, u32 old_H32, u32 new_L32, u32 new_H32)
72 {
73         u32 ret = 0;
74
75         if (new_H32 == old_H32) {
76                 ret = new_L32 - old_L32;
77         } else if (new_H32 == (old_H32 + 1)) {
78                 if (new_L32 > old_L32)
79                         pr_debug("msdc old_L<0x%x> new_L<0x%x>\n",
80                                  old_L32, new_L32);
81                 ret = (0xffffffff - old_L32);
82                 ret += new_L32;
83         } else {
84                 pr_debug("msdc old_H<0x%x> new_H<0x%x>\n", old_H32, new_H32);
85         }
86
87         return ret;
88 }
89
90 void msdc_sdio_profile(struct sdio_profile *result)
91 {
92         struct cmd_profile *cmd;
93         u32 i;
94
95         pr_debug("sdio === performance dump ===\n");
96         pr_debug("sdio === total execute tick<%d> time<%dms> Tx<%dB> Rx<%dB>\n",
97                  result->total_tc, result->total_tc / TICKS_ONE_MS,
98                  result->total_tx_bytes, result->total_rx_bytes);
99
100         /* CMD52 Dump */
101         cmd = &result->cmd52_rx;
102         pr_debug("sdio === CMD52 Rx <%d>times tick<%d> Max<%d> Min<%d> Aver<%d>\n",
103                  cmd->count, cmd->tot_tc, cmd->max_tc, cmd->min_tc,
104                  cmd->tot_tc / cmd->count);
105         cmd = &result->cmd52_tx;
106         pr_debug("sdio === CMD52 Tx <%d>times tick<%d> Max<%d> Min<%d> Aver<%d>\n",
107                  cmd->count, cmd->tot_tc, cmd->max_tc, cmd->min_tc,
108                  cmd->tot_tc / cmd->count);
109
110         /* CMD53 Rx bytes + block mode */
111         for (i = 0; i < 512; i++) {
112                 cmd = &result->cmd53_rx_byte[i];
113                 if (cmd->count) {
114                         pr_debug("sdio<%6d><%3dB>_Rx_<%9d><%9d><%6d><%6d>_<%9dB><%2dM>\n",
115                                  cmd->count, i, cmd->tot_tc, cmd->max_tc,
116                                  cmd->min_tc, cmd->tot_tc / cmd->count,
117                                  cmd->tot_bytes,
118                                  (cmd->tot_bytes / 10) * 13 / (cmd->tot_tc / 10));
119                 }
120         }
121         for (i = 0; i < 100; i++) {
122                 cmd = &result->cmd53_rx_blk[i];
123                 if (cmd->count) {
124                         pr_debug("sdio<%6d><%3d>B_Rx_<%9d><%9d><%6d><%6d>_<%9dB><%2dM>\n",
125                                  cmd->count, i, cmd->tot_tc, cmd->max_tc,
126                                  cmd->min_tc, cmd->tot_tc / cmd->count,
127                                  cmd->tot_bytes,
128                                  (cmd->tot_bytes / 10) * 13 / (cmd->tot_tc / 10));
129                 }
130         }
131
132         /* CMD53 Tx bytes + block mode */
133         for (i = 0; i < 512; i++) {
134                 cmd = &result->cmd53_tx_byte[i];
135                 if (cmd->count) {
136                         pr_debug("sdio<%6d><%3dB>_Tx_<%9d><%9d><%6d><%6d>_<%9dB><%2dM>\n",
137                                  cmd->count, i, cmd->tot_tc, cmd->max_tc,
138                                  cmd->min_tc, cmd->tot_tc / cmd->count,
139                                  cmd->tot_bytes,
140                                  (cmd->tot_bytes / 10) * 13 / (cmd->tot_tc / 10));
141                 }
142         }
143         for (i = 0; i < 100; i++) {
144                 cmd = &result->cmd53_tx_blk[i];
145                 if (cmd->count) {
146                         pr_debug("sdio<%6d><%3d>B_Tx_<%9d><%9d><%6d><%6d>_<%9dB><%2dM>\n",
147                                  cmd->count, i, cmd->tot_tc, cmd->max_tc,
148                                  cmd->min_tc, cmd->tot_tc / cmd->count,
149                                  cmd->tot_bytes,
150                                  (cmd->tot_bytes / 10) * 13 / (cmd->tot_tc / 10));
151                 }
152         }
153
154         pr_debug("sdio === performance dump done ===\n");
155 }
156
157 //========= sdio command table ===========
158 void msdc_performance(u32 opcode, u32 sizes, u32 bRx, u32 ticks)
159 {
160         struct sdio_profile *result = &sdio_perfomance;
161         struct cmd_profile *cmd;
162         u32 block;
163
164         if (sdio_pro_enable == 0)
165                 return;
166
167         if (opcode == 52) {
168                 cmd = bRx ?  &result->cmd52_rx : &result->cmd52_tx;
169         } else if (opcode == 53) {
170                 if (sizes < 512) {
171                         cmd = bRx ?  &result->cmd53_rx_byte[sizes] : &result->cmd53_tx_byte[sizes];
172                 } else {
173                         block = sizes / 512;
174                         if (block >= 99) {
175                                 pr_err("cmd53 error blocks\n");
176                                 while (1)
177                                         ;
178                         }
179                         cmd = bRx ?  &result->cmd53_rx_blk[block] : &result->cmd53_tx_blk[block];
180                 }
181         } else {
182                 return;
183         }
184
185         /* update the members */
186         if (ticks > cmd->max_tc)
187                 cmd->max_tc = ticks;
188         if (cmd->min_tc == 0 || ticks < cmd->min_tc)
189                 cmd->min_tc = ticks;
190         cmd->tot_tc += ticks;
191         cmd->tot_bytes += sizes;
192         cmd->count++;
193
194         if (bRx)
195                 result->total_rx_bytes += sizes;
196         else
197                 result->total_tx_bytes += sizes;
198         result->total_tc += ticks;
199
200         /* dump when total_tc > 30s */
201         if (result->total_tc >= sdio_pro_time * TICKS_ONE_MS * 1000) {
202                 msdc_sdio_profile(result);
203                 memset(result, 0, sizeof(struct sdio_profile));
204         }
205 }
206
207 //========== driver proc interface ===========
208 static int msdc_debug_proc_read(struct seq_file *s, void *p)
209 {
210         seq_puts(s, "\n=========================================\n");
211         seq_puts(s, "Index<0> + Id + Zone\n");
212         seq_puts(s, "-> PWR<9> WRN<8> | FIO<7> OPS<6> FUN<5> CFG<4> | INT<3> RSP<2> CMD<1> DMA<0>\n");
213         seq_puts(s, "-> echo 0 3 0x3ff >msdc_bebug -> host[3] debug zone set to 0x3ff\n");
214         seq_printf(s, "-> MSDC[0] Zone: 0x%.8x\n", sd_debug_zone[0]);
215         seq_printf(s, "-> MSDC[1] Zone: 0x%.8x\n", sd_debug_zone[1]);
216         seq_printf(s, "-> MSDC[2] Zone: 0x%.8x\n", sd_debug_zone[2]);
217         seq_printf(s, "-> MSDC[3] Zone: 0x%.8x\n", sd_debug_zone[3]);
218
219         seq_puts(s, "Index<3> + SDIO_PROFILE + TIME\n");
220         seq_puts(s, "-> echo 3 1 0x1E >msdc_bebug -> enable sdio_profile, 30s\n");
221         seq_printf(s, "-> SDIO_PROFILE<%d> TIME<%ds>\n",
222                    sdio_pro_enable, sdio_pro_time);
223         seq_puts(s, "=========================================\n\n");
224
225         return 0;
226 }
227
228 static ssize_t msdc_debug_proc_write(struct file *file,
229                                      const char __user *buf,
230                                      size_t count, loff_t *data)
231 {
232         int ret;
233
234         int cmd, p1, p2;
235         int id, zone;
236         int mode, size;
237
238         if (count == 0)
239                 return -1;
240         if (count > 255)
241                 count = 255;
242
243         if (copy_from_user(cmd_buf, buf, count))
244                 return -EFAULT;
245
246         cmd_buf[count] = '\0';
247         pr_debug("msdc Write %s\n", cmd_buf);
248
249         ret = sscanf(cmd_buf, "%x %x %x", &cmd, &p1, &p2);
250         if (ret != 3)
251                 return -EINVAL;
252
253         if (cmd == SD_TOOL_ZONE) {
254                 id = p1;
255                 zone = p2;
256                 zone &= 0x3ff;
257                 pr_debug("msdc host_id<%d> zone<0x%.8x>\n", id, zone);
258                 if (id >= 0 && id <= 3) {
259                         sd_debug_zone[id] = zone;
260                 } else if (id == 4) {
261                         sd_debug_zone[0] = sd_debug_zone[1] = zone;
262                         sd_debug_zone[2] = sd_debug_zone[3] = zone;
263                 } else {
264                         pr_err("msdc host_id error when set debug zone\n");
265                 }
266         } else if (cmd == SD_TOOL_SDIO_PROFILE) {
267                 if (p1 == 1) { /* enable profile */
268                         if (gpt_enable == 0)
269                                 gpt_enable = 1;
270                         sdio_pro_enable = 1;
271                         if (p2 == 0)
272                                 p2 = 1;
273                         if (p2 >= 30)
274                                 p2 = 30;
275                         sdio_pro_time = p2;
276                 } else if (p1 == 0) {
277                         /* todo */
278                         sdio_pro_enable = 0;
279                 }
280         }
281
282         return count;
283 }
284
285 static int msdc_debug_show(struct inode *inode, struct file *file)
286 {
287         return single_open(file, msdc_debug_proc_read, NULL);
288 }
289
290 static const struct file_operations msdc_debug_fops = {
291         .owner          = THIS_MODULE,
292         .open           = msdc_debug_show,
293         .read           = seq_read,
294         .write          = msdc_debug_proc_write,
295         .llseek         = seq_lseek,
296         .release        = single_release,
297 };
298
299 void msdc_debug_proc_init(void)
300 {
301         proc_create("msdc_debug", 0660, NULL, &msdc_debug_fops);
302 }
303 EXPORT_SYMBOL_GPL(msdc_debug_proc_init);
304 #endif
This page took 0.051528 seconds and 4 git commands to generate.