aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mmc/host/rtsx_pci_sdmmc.c
diff options
context:
space:
mode:
authorMicky Ching <micky_ching@realsil.com.cn>2014-02-17 03:45:47 -0500
committerChris Ball <chris@printf.net>2014-02-22 13:34:18 -0500
commitabcc6b2943145ae2e17a52632ccab50cd612914c (patch)
tree4b3a81be7f62c09845e69721f56cd1c7c8911eb6 /drivers/mmc/host/rtsx_pci_sdmmc.c
parent640e09bc45f5d03622da5230d131c0bfd0d2da3f (diff)
mmc: rtsx: modify phase searching method for tuning
The new phase searching method is more concise and easier to understand. Signed-off-by: Micky Ching <micky_ching@realsil.com.cn> Signed-off-by: Chris Ball <chris@printf.net>
Diffstat (limited to 'drivers/mmc/host/rtsx_pci_sdmmc.c')
-rw-r--r--drivers/mmc/host/rtsx_pci_sdmmc.c112
1 files changed, 32 insertions, 80 deletions
diff --git a/drivers/mmc/host/rtsx_pci_sdmmc.c b/drivers/mmc/host/rtsx_pci_sdmmc.c
index cc80e3119d1d..0b9ded13a3ae 100644
--- a/drivers/mmc/host/rtsx_pci_sdmmc.c
+++ b/drivers/mmc/host/rtsx_pci_sdmmc.c
@@ -31,16 +31,6 @@
31#include <linux/mfd/rtsx_pci.h> 31#include <linux/mfd/rtsx_pci.h>
32#include <asm/unaligned.h> 32#include <asm/unaligned.h>
33 33
34/* SD Tuning Data Structure
35 * Record continuous timing phase path
36 */
37struct timing_phase_path {
38 int start;
39 int end;
40 int mid;
41 int len;
42};
43
44struct realtek_pci_sdmmc { 34struct realtek_pci_sdmmc {
45 struct platform_device *pdev; 35 struct platform_device *pdev;
46 struct rtsx_pcr *pcr; 36 struct rtsx_pcr *pcr;
@@ -511,85 +501,47 @@ static int sd_change_phase(struct realtek_pci_sdmmc *host,
511 return 0; 501 return 0;
512} 502}
513 503
514static u8 sd_search_final_phase(struct realtek_pci_sdmmc *host, u32 phase_map) 504static inline u32 test_phase_bit(u32 phase_map, unsigned int bit)
515{ 505{
516 struct timing_phase_path path[MAX_PHASE + 1]; 506 bit %= RTSX_PHASE_MAX;
517 int i, j, cont_path_cnt; 507 return phase_map & (1 << bit);
518 int new_block, max_len, final_path_idx; 508}
519 u8 final_phase = 0xFF;
520 509
521 /* Parse phase_map, take it as a bit-ring */ 510static int sd_get_phase_len(u32 phase_map, unsigned int start_bit)
522 cont_path_cnt = 0; 511{
523 new_block = 1; 512 int i;
524 j = 0;
525 for (i = 0; i < MAX_PHASE + 1; i++) {
526 if (phase_map & (1 << i)) {
527 if (new_block) {
528 new_block = 0;
529 j = cont_path_cnt++;
530 path[j].start = i;
531 path[j].end = i;
532 } else {
533 path[j].end = i;
534 }
535 } else {
536 new_block = 1;
537 if (cont_path_cnt) {
538 /* Calculate path length and middle point */
539 int idx = cont_path_cnt - 1;
540 path[idx].len =
541 path[idx].end - path[idx].start + 1;
542 path[idx].mid =
543 path[idx].start + path[idx].len / 2;
544 }
545 }
546 }
547 513
548 if (cont_path_cnt == 0) { 514 for (i = 0; i < RTSX_PHASE_MAX; i++) {
549 dev_dbg(sdmmc_dev(host), "No continuous phase path\n"); 515 if (test_phase_bit(phase_map, start_bit + i) == 0)
550 goto finish; 516 return i;
551 } else {
552 /* Calculate last continuous path length and middle point */
553 int idx = cont_path_cnt - 1;
554 path[idx].len = path[idx].end - path[idx].start + 1;
555 path[idx].mid = path[idx].start + path[idx].len / 2;
556 } 517 }
518 return RTSX_PHASE_MAX;
519}
520
521static u8 sd_search_final_phase(struct realtek_pci_sdmmc *host, u32 phase_map)
522{
523 int start = 0, len = 0;
524 int start_final = 0, len_final = 0;
525 u8 final_phase = 0xFF;
557 526
558 /* Connect the first and last continuous paths if they are adjacent */ 527 if (phase_map == 0) {
559 if (!path[0].start && (path[cont_path_cnt - 1].end == MAX_PHASE)) { 528 dev_err(sdmmc_dev(host), "phase error: [map:%x]\n", phase_map);
560 /* Using negative index */ 529 return final_phase;
561 path[0].start = path[cont_path_cnt - 1].start - MAX_PHASE - 1;
562 path[0].len += path[cont_path_cnt - 1].len;
563 path[0].mid = path[0].start + path[0].len / 2;
564 /* Convert negative middle point index to positive one */
565 if (path[0].mid < 0)
566 path[0].mid += MAX_PHASE + 1;
567 cont_path_cnt--;
568 } 530 }
569 531
570 /* Choose the longest continuous phase path */ 532 while (start < RTSX_PHASE_MAX) {
571 max_len = 0; 533 len = sd_get_phase_len(phase_map, start);
572 final_phase = 0; 534 if (len_final < len) {
573 final_path_idx = 0; 535 start_final = start;
574 for (i = 0; i < cont_path_cnt; i++) { 536 len_final = len;
575 if (path[i].len > max_len) {
576 max_len = path[i].len;
577 final_phase = (u8)path[i].mid;
578 final_path_idx = i;
579 } 537 }
580 538 start += len ? len : 1;
581 dev_dbg(sdmmc_dev(host), "path[%d].start = %d\n",
582 i, path[i].start);
583 dev_dbg(sdmmc_dev(host), "path[%d].end = %d\n",
584 i, path[i].end);
585 dev_dbg(sdmmc_dev(host), "path[%d].len = %d\n",
586 i, path[i].len);
587 dev_dbg(sdmmc_dev(host), "path[%d].mid = %d\n",
588 i, path[i].mid);
589 } 539 }
590 540
591finish: 541 final_phase = (start_final + len_final / 2) % RTSX_PHASE_MAX;
592 dev_dbg(sdmmc_dev(host), "Final chosen phase: %d\n", final_phase); 542 dev_dbg(sdmmc_dev(host), "phase: [map:%x] [maxlen:%d] [final:%d]\n",
543 phase_map, len_final, final_phase);
544
593 return final_phase; 545 return final_phase;
594} 546}
595 547
@@ -635,7 +587,7 @@ static int sd_tuning_phase(struct realtek_pci_sdmmc *host,
635 int err, i; 587 int err, i;
636 u32 raw_phase_map = 0; 588 u32 raw_phase_map = 0;
637 589
638 for (i = MAX_PHASE; i >= 0; i--) { 590 for (i = 0; i < RTSX_PHASE_MAX; i++) {
639 err = sd_tuning_rx_cmd(host, opcode, (u8)i); 591 err = sd_tuning_rx_cmd(host, opcode, (u8)i);
640 if (err == 0) 592 if (err == 0)
641 raw_phase_map |= 1 << i; 593 raw_phase_map |= 1 << i;