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/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 */
50 #include "mt6575_sd.h"
51 #include <linux/seq_file.h>
55 unsigned int sd_debug_zone[4] = {
62 #if defined(MT6575_SD_DEBUG)
63 static char cmd_buf[256];
64 /* for driver profile */
65 #define TICKS_ONE_MS (13000)
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};
71 u32 msdc_time_calc(u32 old_L32, u32 old_H32, u32 new_L32, u32 new_H32)
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",
81 ret = (0xffffffff - old_L32);
84 pr_debug("msdc old_H<0x%x> new_H<0x%x>\n", old_H32, new_H32);
90 void msdc_sdio_profile(struct sdio_profile *result)
92 struct cmd_profile *cmd;
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);
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);
110 /* CMD53 Rx bytes + block mode */
111 for (i = 0; i < 512; i++) {
112 cmd = &result->cmd53_rx_byte[i];
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,
118 (cmd->tot_bytes / 10) * 13 / (cmd->tot_tc / 10));
121 for (i = 0; i < 100; i++) {
122 cmd = &result->cmd53_rx_blk[i];
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,
128 (cmd->tot_bytes / 10) * 13 / (cmd->tot_tc / 10));
132 /* CMD53 Tx bytes + block mode */
133 for (i = 0; i < 512; i++) {
134 cmd = &result->cmd53_tx_byte[i];
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,
140 (cmd->tot_bytes / 10) * 13 / (cmd->tot_tc / 10));
143 for (i = 0; i < 100; i++) {
144 cmd = &result->cmd53_tx_blk[i];
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,
150 (cmd->tot_bytes / 10) * 13 / (cmd->tot_tc / 10));
154 pr_debug("sdio === performance dump done ===\n");
157 //========= sdio command table ===========
158 void msdc_performance(u32 opcode, u32 sizes, u32 bRx, u32 ticks)
160 struct sdio_profile *result = &sdio_perfomance;
161 struct cmd_profile *cmd;
164 if (sdio_pro_enable == 0)
168 cmd = bRx ? &result->cmd52_rx : &result->cmd52_tx;
169 } else if (opcode == 53) {
171 cmd = bRx ? &result->cmd53_rx_byte[sizes] : &result->cmd53_tx_byte[sizes];
175 pr_err("cmd53 error blocks\n");
179 cmd = bRx ? &result->cmd53_rx_blk[block] : &result->cmd53_tx_blk[block];
185 /* update the members */
186 if (ticks > cmd->max_tc)
188 if (cmd->min_tc == 0 || ticks < cmd->min_tc)
190 cmd->tot_tc += ticks;
191 cmd->tot_bytes += sizes;
195 result->total_rx_bytes += sizes;
197 result->total_tx_bytes += sizes;
198 result->total_tc += ticks;
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));
207 //========== driver proc interface ===========
208 static int msdc_debug_proc_read(struct seq_file *s, void *p)
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]);
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");
228 static ssize_t msdc_debug_proc_write(struct file *file,
229 const char __user *buf,
230 size_t count, loff_t *data)
243 if (copy_from_user(cmd_buf, buf, count))
246 cmd_buf[count] = '\0';
247 pr_debug("msdc Write %s\n", cmd_buf);
249 ret = sscanf(cmd_buf, "%x %x %x", &cmd, &p1, &p2);
253 if (cmd == SD_TOOL_ZONE) {
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;
264 pr_err("msdc host_id error when set debug zone\n");
266 } else if (cmd == SD_TOOL_SDIO_PROFILE) {
267 if (p1 == 1) { /* enable profile */
276 } else if (p1 == 0) {
285 static int msdc_debug_show(struct inode *inode, struct file *file)
287 return single_open(file, msdc_debug_proc_read, NULL);
290 static const struct file_operations msdc_debug_fops = {
291 .owner = THIS_MODULE,
292 .open = msdc_debug_show,
294 .write = msdc_debug_proc_write,
296 .release = single_release,
299 void msdc_debug_proc_init(void)
301 proc_create("msdc_debug", 0660, NULL, &msdc_debug_fops);
303 EXPORT_SYMBOL_GPL(msdc_debug_proc_init);