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
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
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 */
51 #include "mt6575_sd.h"
52 #include <linux/seq_file.h>
54 static char cmd_buf
[256];
57 unsigned int sd_debug_zone
[4] = {
64 #if defined(MT6575_SD_DEBUG)
65 /* for driver profile */
66 #define TICKS_ONE_MS (13000)
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
)
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",
82 ret
= (0xffffffff - old_L32
);
85 pr_debug("msdc old_H<0x%x> new_H<0x%x>\n", old_H32
, new_H32
);
91 void msdc_sdio_profile(struct sdio_profile
*result
)
93 struct cmd_profile
*cmd
;
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
);
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
];
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
,
119 (cmd
->tot_bytes
/ 10) * 13 / (cmd
->tot_tc
/ 10));
122 for (i
= 0; i
< 100; i
++) {
123 cmd
= &result
->cmd53_rx_blk
[i
];
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
,
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
];
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
,
141 (cmd
->tot_bytes
/ 10) * 13 / (cmd
->tot_tc
/ 10));
144 for (i
= 0; i
< 100; i
++) {
145 cmd
= &result
->cmd53_tx_blk
[i
];
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
,
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
;
165 if (sdio_pro_enable
== 0)
169 cmd
= bRx
? &result
->cmd52_rx
: &result
->cmd52_tx
;
170 } else if (opcode
== 53) {
172 cmd
= bRx
? &result
->cmd53_rx_byte
[sizes
] : &result
->cmd53_tx_byte
[sizes
];
176 pr_err("cmd53 error blocks\n");
180 cmd
= bRx
? &result
->cmd53_rx_blk
[block
] : &result
->cmd53_tx_blk
[block
];
186 /* update the members */
187 if (ticks
> cmd
->max_tc
)
189 if (cmd
->min_tc
== 0 || ticks
< cmd
->min_tc
)
191 cmd
->tot_tc
+= ticks
;
192 cmd
->tot_bytes
+= sizes
;
196 result
->total_rx_bytes
+= sizes
;
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");
229 static ssize_t
msdc_debug_proc_write(struct file
*file
,
230 const char __user
*buf
,
231 size_t count
, loff_t
*data
)
244 if (copy_from_user(cmd_buf
, buf
, count
))
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
);
254 if (cmd
== SD_TOOL_ZONE
) {
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
;
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 */
277 } else if (p1
== 0) {
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
,
295 .write
= msdc_debug_proc_write
,
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
);