All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] fix sd power bug and modify phase-searching method
@ 2013-11-19 11:10 ` micky_ching
  0 siblings, 0 replies; 10+ messages in thread
From: micky_ching @ 2013-11-19 11:10 UTC (permalink / raw)
  To: cjb, sameo; +Cc: devel, linux-kernel, linux-mmc, gregkh, wei_wang, Micky Ching

From: Micky Ching <micky_ching@realsil.com.cn>

If the driver removed while sd card still in the slot, the card power
will not power down correctly, if we insert the driver module again,
UHS card will not switch to UHS mode. This bug is fix in this patch.

We use another phase search method for tuning, which looks more
simple, and reduce some source code.

Micky Ching (2):
  mmc: rtsx: fix card poweroff bug
  mmc: rtsx: modify phase searching method for tunning

 drivers/mmc/host/rtsx_pci_sdmmc.c |  111 +++++++++++--------------------------
 1 file changed, 32 insertions(+), 79 deletions(-)

--
1.7.9.5

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 0/2] fix sd power bug and modify phase-searching method
@ 2013-11-19 11:10 ` micky_ching
  0 siblings, 0 replies; 10+ messages in thread
From: micky_ching @ 2013-11-19 11:10 UTC (permalink / raw)
  To: cjb, sameo; +Cc: gregkh, linux-mmc, linux-kernel, wei_wang, devel

From: Micky Ching <micky_ching@realsil.com.cn>

If the driver removed while sd card still in the slot, the card power
will not power down correctly, if we insert the driver module again,
UHS card will not switch to UHS mode. This bug is fix in this patch.

We use another phase search method for tuning, which looks more
simple, and reduce some source code.

Micky Ching (2):
  mmc: rtsx: fix card poweroff bug
  mmc: rtsx: modify phase searching method for tunning

 drivers/mmc/host/rtsx_pci_sdmmc.c |  111 +++++++++++--------------------------
 1 file changed, 32 insertions(+), 79 deletions(-)

--
1.7.9.5

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/2] mmc: rtsx: fix card poweroff bug
  2013-11-19 11:10 ` micky_ching
@ 2013-11-19 11:10   ` micky_ching
  -1 siblings, 0 replies; 10+ messages in thread
From: micky_ching @ 2013-11-19 11:10 UTC (permalink / raw)
  To: cjb, sameo; +Cc: devel, linux-kernel, linux-mmc, gregkh, wei_wang, Micky Ching

From: Micky Ching <micky_ching@realsil.com.cn>

If the host driver removed while card in the slot, the host will not
power off card power correctly. This bug is produced because host
eject flag set before the last mmc_set_ios callback, we should set the
eject flag after power off.

Signed-off-by: Micky Ching <micky_ching@realsil.com.cn>
---
 drivers/mmc/host/rtsx_pci_sdmmc.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/mmc/host/rtsx_pci_sdmmc.c b/drivers/mmc/host/rtsx_pci_sdmmc.c
index 375a880e..c9a7328 100644
--- a/drivers/mmc/host/rtsx_pci_sdmmc.c
+++ b/drivers/mmc/host/rtsx_pci_sdmmc.c
@@ -1328,7 +1328,6 @@ static int rtsx_pci_sdmmc_drv_remove(struct platform_device *pdev)
 	pcr->slots[RTSX_SD_CARD].p_dev = NULL;
 	pcr->slots[RTSX_SD_CARD].card_event = NULL;
 	mmc = host->mmc;
-	host->eject = true;
 
 	mutex_lock(&host->host_mutex);
 	if (host->mrq) {
@@ -1346,6 +1345,8 @@ static int rtsx_pci_sdmmc_drv_remove(struct platform_device *pdev)
 	mutex_unlock(&host->host_mutex);
 
 	mmc_remove_host(mmc);
+	host->eject = true;
+
 	mmc_free_host(mmc);
 
 	dev_dbg(&(pdev->dev),
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 1/2] mmc: rtsx: fix card poweroff bug
@ 2013-11-19 11:10   ` micky_ching
  0 siblings, 0 replies; 10+ messages in thread
From: micky_ching @ 2013-11-19 11:10 UTC (permalink / raw)
  To: cjb, sameo; +Cc: gregkh, linux-mmc, linux-kernel, wei_wang, devel

From: Micky Ching <micky_ching@realsil.com.cn>

If the host driver removed while card in the slot, the host will not
power off card power correctly. This bug is produced because host
eject flag set before the last mmc_set_ios callback, we should set the
eject flag after power off.

Signed-off-by: Micky Ching <micky_ching@realsil.com.cn>
---
 drivers/mmc/host/rtsx_pci_sdmmc.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/mmc/host/rtsx_pci_sdmmc.c b/drivers/mmc/host/rtsx_pci_sdmmc.c
index 375a880e..c9a7328 100644
--- a/drivers/mmc/host/rtsx_pci_sdmmc.c
+++ b/drivers/mmc/host/rtsx_pci_sdmmc.c
@@ -1328,7 +1328,6 @@ static int rtsx_pci_sdmmc_drv_remove(struct platform_device *pdev)
 	pcr->slots[RTSX_SD_CARD].p_dev = NULL;
 	pcr->slots[RTSX_SD_CARD].card_event = NULL;
 	mmc = host->mmc;
-	host->eject = true;
 
 	mutex_lock(&host->host_mutex);
 	if (host->mrq) {
@@ -1346,6 +1345,8 @@ static int rtsx_pci_sdmmc_drv_remove(struct platform_device *pdev)
 	mutex_unlock(&host->host_mutex);
 
 	mmc_remove_host(mmc);
+	host->eject = true;
+
 	mmc_free_host(mmc);
 
 	dev_dbg(&(pdev->dev),
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/2] mmc: rtsx: modify phase searching method for tunning
  2013-11-19 11:10 ` micky_ching
@ 2013-11-19 11:10   ` micky_ching
  -1 siblings, 0 replies; 10+ messages in thread
From: micky_ching @ 2013-11-19 11:10 UTC (permalink / raw)
  To: cjb, sameo; +Cc: devel, linux-kernel, linux-mmc, gregkh, wei_wang, Micky Ching

From: Micky Ching <micky_ching@realsil.com.cn>

The new phase searching method is more concise and easier to
understand.

Signed-off-by: Micky Ching <micky_ching@realsil.com.cn>
---
 drivers/mmc/host/rtsx_pci_sdmmc.c |  108 +++++++++++--------------------------
 1 file changed, 30 insertions(+), 78 deletions(-)

diff --git a/drivers/mmc/host/rtsx_pci_sdmmc.c b/drivers/mmc/host/rtsx_pci_sdmmc.c
index c9a7328..fb2f159 100644
--- a/drivers/mmc/host/rtsx_pci_sdmmc.c
+++ b/drivers/mmc/host/rtsx_pci_sdmmc.c
@@ -31,16 +31,6 @@
 #include <linux/mfd/rtsx_pci.h>
 #include <asm/unaligned.h>
 
-/* SD Tuning Data Structure
- * Record continuous timing phase path
- */
-struct timing_phase_path {
-	int start;
-	int end;
-	int mid;
-	int len;
-};
-
 struct realtek_pci_sdmmc {
 	struct platform_device	*pdev;
 	struct rtsx_pcr		*pcr;
@@ -511,85 +501,47 @@ static int sd_change_phase(struct realtek_pci_sdmmc *host,
 	return 0;
 }
 
-static u8 sd_search_final_phase(struct realtek_pci_sdmmc *host, u32 phase_map)
+static inline u32 sd_get_phase_point(u32 phase_map, unsigned int idx)
 {
-	struct timing_phase_path path[MAX_PHASE + 1];
-	int i, j, cont_path_cnt;
-	int new_block, max_len, final_path_idx;
-	u8 final_phase = 0xFF;
+	idx &= MAX_PHASE;
+	return phase_map & (1 << idx);
+}
+
+static int sd_get_phase_len(u32 phase_map, unsigned int idx)
+{
+	int i;
 
-	/* Parse phase_map, take it as a bit-ring */
-	cont_path_cnt = 0;
-	new_block = 1;
-	j = 0;
 	for (i = 0; i < MAX_PHASE + 1; i++) {
-		if (phase_map & (1 << i)) {
-			if (new_block) {
-				new_block = 0;
-				j = cont_path_cnt++;
-				path[j].start = i;
-				path[j].end = i;
-			} else {
-				path[j].end = i;
-			}
-		} else {
-			new_block = 1;
-			if (cont_path_cnt) {
-				/* Calculate path length and middle point */
-				int idx = cont_path_cnt - 1;
-				path[idx].len =
-					path[idx].end - path[idx].start + 1;
-				path[idx].mid =
-					path[idx].start + path[idx].len / 2;
-			}
-		}
+		if (sd_get_phase_point(phase_map, idx + i) == 0)
+			return i;
 	}
+	return MAX_PHASE + 1;
+}
 
-	if (cont_path_cnt == 0) {
-		dev_dbg(sdmmc_dev(host), "No continuous phase path\n");
-		goto finish;
-	} else {
-		/* Calculate last continuous path length and middle point */
-		int idx = cont_path_cnt - 1;
-		path[idx].len = path[idx].end - path[idx].start + 1;
-		path[idx].mid = path[idx].start + path[idx].len / 2;
-	}
+static u8 sd_search_final_phase(struct realtek_pci_sdmmc *host, u32 phase_map)
+{
+	int start = 0, len = 0;
+	int start_final = 0, len_final = 0;
+	u8 final_phase = 0xFF;
 
-	/* Connect the first and last continuous paths if they are adjacent */
-	if (!path[0].start && (path[cont_path_cnt - 1].end == MAX_PHASE)) {
-		/* Using negative index */
-		path[0].start = path[cont_path_cnt - 1].start - MAX_PHASE - 1;
-		path[0].len += path[cont_path_cnt - 1].len;
-		path[0].mid = path[0].start + path[0].len / 2;
-		/* Convert negative middle point index to positive one */
-		if (path[0].mid < 0)
-			path[0].mid += MAX_PHASE + 1;
-		cont_path_cnt--;
+	if (phase_map == 0) {
+		dev_dbg(sdmmc_dev(host), "Phase: [map:%x]\n", phase_map);
+		return final_phase;
 	}
 
-	/* Choose the longest continuous phase path */
-	max_len = 0;
-	final_phase = 0;
-	final_path_idx = 0;
-	for (i = 0; i < cont_path_cnt; i++) {
-		if (path[i].len > max_len) {
-			max_len = path[i].len;
-			final_phase = (u8)path[i].mid;
-			final_path_idx = i;
+	while (start < MAX_PHASE + 1) {
+		len = sd_get_phase_len(phase_map, start);
+		if (len_final < len) {
+			start_final = start;
+			len_final = len;
 		}
-
-		dev_dbg(sdmmc_dev(host), "path[%d].start = %d\n",
-				i, path[i].start);
-		dev_dbg(sdmmc_dev(host), "path[%d].end = %d\n",
-				i, path[i].end);
-		dev_dbg(sdmmc_dev(host), "path[%d].len = %d\n",
-				i, path[i].len);
-		dev_dbg(sdmmc_dev(host), "path[%d].mid = %d\n",
-				i, path[i].mid);
+		start += len ? len : 1;
 	}
 
-finish:
-	dev_dbg(sdmmc_dev(host), "Final chosen phase: %d\n", final_phase);
+	final_phase = (start_final + len_final / 2) & MAX_PHASE;
+	dev_dbg(sdmmc_dev(host), "Phase: [map:%x] [maxlen:%d] [final:%d]\n",
+		phase_map, len_final, final_phase);
+
 	return final_phase;
 }
 
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/2] mmc: rtsx: modify phase searching method for tunning
@ 2013-11-19 11:10   ` micky_ching
  0 siblings, 0 replies; 10+ messages in thread
From: micky_ching @ 2013-11-19 11:10 UTC (permalink / raw)
  To: cjb, sameo; +Cc: gregkh, linux-mmc, linux-kernel, wei_wang, devel

From: Micky Ching <micky_ching@realsil.com.cn>

The new phase searching method is more concise and easier to
understand.

Signed-off-by: Micky Ching <micky_ching@realsil.com.cn>
---
 drivers/mmc/host/rtsx_pci_sdmmc.c |  108 +++++++++++--------------------------
 1 file changed, 30 insertions(+), 78 deletions(-)

diff --git a/drivers/mmc/host/rtsx_pci_sdmmc.c b/drivers/mmc/host/rtsx_pci_sdmmc.c
index c9a7328..fb2f159 100644
--- a/drivers/mmc/host/rtsx_pci_sdmmc.c
+++ b/drivers/mmc/host/rtsx_pci_sdmmc.c
@@ -31,16 +31,6 @@
 #include <linux/mfd/rtsx_pci.h>
 #include <asm/unaligned.h>
 
-/* SD Tuning Data Structure
- * Record continuous timing phase path
- */
-struct timing_phase_path {
-	int start;
-	int end;
-	int mid;
-	int len;
-};
-
 struct realtek_pci_sdmmc {
 	struct platform_device	*pdev;
 	struct rtsx_pcr		*pcr;
@@ -511,85 +501,47 @@ static int sd_change_phase(struct realtek_pci_sdmmc *host,
 	return 0;
 }
 
-static u8 sd_search_final_phase(struct realtek_pci_sdmmc *host, u32 phase_map)
+static inline u32 sd_get_phase_point(u32 phase_map, unsigned int idx)
 {
-	struct timing_phase_path path[MAX_PHASE + 1];
-	int i, j, cont_path_cnt;
-	int new_block, max_len, final_path_idx;
-	u8 final_phase = 0xFF;
+	idx &= MAX_PHASE;
+	return phase_map & (1 << idx);
+}
+
+static int sd_get_phase_len(u32 phase_map, unsigned int idx)
+{
+	int i;
 
-	/* Parse phase_map, take it as a bit-ring */
-	cont_path_cnt = 0;
-	new_block = 1;
-	j = 0;
 	for (i = 0; i < MAX_PHASE + 1; i++) {
-		if (phase_map & (1 << i)) {
-			if (new_block) {
-				new_block = 0;
-				j = cont_path_cnt++;
-				path[j].start = i;
-				path[j].end = i;
-			} else {
-				path[j].end = i;
-			}
-		} else {
-			new_block = 1;
-			if (cont_path_cnt) {
-				/* Calculate path length and middle point */
-				int idx = cont_path_cnt - 1;
-				path[idx].len =
-					path[idx].end - path[idx].start + 1;
-				path[idx].mid =
-					path[idx].start + path[idx].len / 2;
-			}
-		}
+		if (sd_get_phase_point(phase_map, idx + i) == 0)
+			return i;
 	}
+	return MAX_PHASE + 1;
+}
 
-	if (cont_path_cnt == 0) {
-		dev_dbg(sdmmc_dev(host), "No continuous phase path\n");
-		goto finish;
-	} else {
-		/* Calculate last continuous path length and middle point */
-		int idx = cont_path_cnt - 1;
-		path[idx].len = path[idx].end - path[idx].start + 1;
-		path[idx].mid = path[idx].start + path[idx].len / 2;
-	}
+static u8 sd_search_final_phase(struct realtek_pci_sdmmc *host, u32 phase_map)
+{
+	int start = 0, len = 0;
+	int start_final = 0, len_final = 0;
+	u8 final_phase = 0xFF;
 
-	/* Connect the first and last continuous paths if they are adjacent */
-	if (!path[0].start && (path[cont_path_cnt - 1].end == MAX_PHASE)) {
-		/* Using negative index */
-		path[0].start = path[cont_path_cnt - 1].start - MAX_PHASE - 1;
-		path[0].len += path[cont_path_cnt - 1].len;
-		path[0].mid = path[0].start + path[0].len / 2;
-		/* Convert negative middle point index to positive one */
-		if (path[0].mid < 0)
-			path[0].mid += MAX_PHASE + 1;
-		cont_path_cnt--;
+	if (phase_map == 0) {
+		dev_dbg(sdmmc_dev(host), "Phase: [map:%x]\n", phase_map);
+		return final_phase;
 	}
 
-	/* Choose the longest continuous phase path */
-	max_len = 0;
-	final_phase = 0;
-	final_path_idx = 0;
-	for (i = 0; i < cont_path_cnt; i++) {
-		if (path[i].len > max_len) {
-			max_len = path[i].len;
-			final_phase = (u8)path[i].mid;
-			final_path_idx = i;
+	while (start < MAX_PHASE + 1) {
+		len = sd_get_phase_len(phase_map, start);
+		if (len_final < len) {
+			start_final = start;
+			len_final = len;
 		}
-
-		dev_dbg(sdmmc_dev(host), "path[%d].start = %d\n",
-				i, path[i].start);
-		dev_dbg(sdmmc_dev(host), "path[%d].end = %d\n",
-				i, path[i].end);
-		dev_dbg(sdmmc_dev(host), "path[%d].len = %d\n",
-				i, path[i].len);
-		dev_dbg(sdmmc_dev(host), "path[%d].mid = %d\n",
-				i, path[i].mid);
+		start += len ? len : 1;
 	}
 
-finish:
-	dev_dbg(sdmmc_dev(host), "Final chosen phase: %d\n", final_phase);
+	final_phase = (start_final + len_final / 2) & MAX_PHASE;
+	dev_dbg(sdmmc_dev(host), "Phase: [map:%x] [maxlen:%d] [final:%d]\n",
+		phase_map, len_final, final_phase);
+
 	return final_phase;
 }
 
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/2] mmc: rtsx: modify phase searching method for tunning
  2013-11-19 11:10   ` micky_ching
@ 2013-11-20  8:17     ` Dan Carpenter
  -1 siblings, 0 replies; 10+ messages in thread
From: Dan Carpenter @ 2013-11-20  8:17 UTC (permalink / raw)
  To: micky_ching; +Cc: cjb, sameo, gregkh, linux-mmc, linux-kernel, wei_wang, devel

On Tue, Nov 19, 2013 at 07:10:35PM +0800, micky_ching@realsil.com.cn wrote:
> -static u8 sd_search_final_phase(struct realtek_pci_sdmmc *host, u32 phase_map)
> +static inline u32 sd_get_phase_point(u32 phase_map, unsigned int idx)
>  {
> -	struct timing_phase_path path[MAX_PHASE + 1];
> -	int i, j, cont_path_cnt;
> -	int new_block, max_len, final_path_idx;
> -	u8 final_phase = 0xFF;
> +	idx &= MAX_PHASE;
> +	return phase_map & (1 << idx);
> +}
> +

This function is confusing....

MAX_PHASE is a terrible name.  It's in a global header but it doesn't
have a prefix.  It should be #define RTS_MAX_PHASE.  It's weird that we
are using it both as a number and as bit mask.  It's weird that we
always add a "+ 1" to MAX_PHASE.  It means the name is chosen poorly.
Maybe it should be:

#define RTS_MAX_PHASE  32
#define RTS_PHASE_MASK 0x1f

So this function takes a phase_map and an index and it wraps the index
by masking away the top bits then it tests to see if the wrapped index
bit is set?  The wrapping is very strange.

The name of the function is sd_get_phase_point() but we only test to
see if it returns zero.  The name of the function is not helpful.
"sd" is a generic prefix.
"get" is misleading because we don't "get" anything it only returns zero
on success?
"phase_point" might be helpful but I don't know what a phase_point is.
Add a comment about that maybe.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/2] mmc: rtsx: modify phase searching method for tunning
@ 2013-11-20  8:17     ` Dan Carpenter
  0 siblings, 0 replies; 10+ messages in thread
From: Dan Carpenter @ 2013-11-20  8:17 UTC (permalink / raw)
  To: micky_ching; +Cc: sameo, gregkh, linux-mmc, linux-kernel, wei_wang, devel, cjb

On Tue, Nov 19, 2013 at 07:10:35PM +0800, micky_ching@realsil.com.cn wrote:
> -static u8 sd_search_final_phase(struct realtek_pci_sdmmc *host, u32 phase_map)
> +static inline u32 sd_get_phase_point(u32 phase_map, unsigned int idx)
>  {
> -	struct timing_phase_path path[MAX_PHASE + 1];
> -	int i, j, cont_path_cnt;
> -	int new_block, max_len, final_path_idx;
> -	u8 final_phase = 0xFF;
> +	idx &= MAX_PHASE;
> +	return phase_map & (1 << idx);
> +}
> +

This function is confusing....

MAX_PHASE is a terrible name.  It's in a global header but it doesn't
have a prefix.  It should be #define RTS_MAX_PHASE.  It's weird that we
are using it both as a number and as bit mask.  It's weird that we
always add a "+ 1" to MAX_PHASE.  It means the name is chosen poorly.
Maybe it should be:

#define RTS_MAX_PHASE  32
#define RTS_PHASE_MASK 0x1f

So this function takes a phase_map and an index and it wraps the index
by masking away the top bits then it tests to see if the wrapped index
bit is set?  The wrapping is very strange.

The name of the function is sd_get_phase_point() but we only test to
see if it returns zero.  The name of the function is not helpful.
"sd" is a generic prefix.
"get" is misleading because we don't "get" anything it only returns zero
on success?
"phase_point" might be helpful but I don't know what a phase_point is.
Add a comment about that maybe.

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/2] mmc: rtsx: modify phase searching method for tunning
  2013-11-20  8:17     ` Dan Carpenter
@ 2013-11-20  9:13       ` micky
  -1 siblings, 0 replies; 10+ messages in thread
From: micky @ 2013-11-20  9:13 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: cjb, sameo, gregkh, linux-mmc, linux-kernel, wei_wang, devel

Hi Dan:
On 11/20/2013 04:17 PM, Dan Carpenter wrote:
> On Tue, Nov 19, 2013 at 07:10:35PM +0800, micky_ching@realsil.com.cn wrote:
>> -static u8 sd_search_final_phase(struct realtek_pci_sdmmc *host, u32 phase_map)
>> +static inline u32 sd_get_phase_point(u32 phase_map, unsigned int idx)
>>   {
>> -	struct timing_phase_path path[MAX_PHASE + 1];
>> -	int i, j, cont_path_cnt;
>> -	int new_block, max_len, final_path_idx;
>> -	u8 final_phase = 0xFF;
>> +	idx &= MAX_PHASE;
>> +	return phase_map & (1 << idx);
>> +}
>> +
> This function is confusing....
>
> MAX_PHASE is a terrible name.  It's in a global header but it doesn't
> have a prefix.  It should be #define RTS_MAX_PHASE.  It's weird that we
> are using it both as a number and as bit mask.  It's weird that we
> always add a "+ 1" to MAX_PHASE.  It means the name is chosen poorly.
> Maybe it should be:
>
> #define RTS_MAX_PHASE  32
> #define RTS_PHASE_MASK 0x1f
That's good, I will modify and resend.
> So this function takes a phase_map and an index and it wraps the index
> by masking away the top bits then it tests to see if the wrapped index
> bit is set?  The wrapping is very strange.
We use this function to find whether the bit of index in the phase_map
is 1. The index can be twice as MAX_PHASE(reach to 63), because we use
a unidirectional search, start search continuous phase to found the
max continuous length from 0, 1, ..., to 31. When we start from
bit31, index 32 should wrap as 0. This function can be replaced by mod
function(idx %= MAX_PHASE + 1).
> The name of the function is sd_get_phase_point() but we only test to
> see if it returns zero.  The name of the function is not helpful.
> "sd" is a generic prefix.
> "get" is misleading because we don't "get" anything it only returns zero
> on success?
> "phase_point" might be helpful but I don't know what a phase_point is.
> Add a comment about that maybe.
Yes, thank you for your suggestion, the function name is really not good.
I want use test_phase_bit(u32 phase_map, unsigned int bit), is that ok?
> regards,
> dan carpenter
>
> .
>


-- 
Best Regards
Micky.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/2] mmc: rtsx: modify phase searching method for tunning
@ 2013-11-20  9:13       ` micky
  0 siblings, 0 replies; 10+ messages in thread
From: micky @ 2013-11-20  9:13 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: sameo, gregkh, linux-mmc, linux-kernel, wei_wang, devel, cjb

Hi Dan:
On 11/20/2013 04:17 PM, Dan Carpenter wrote:
> On Tue, Nov 19, 2013 at 07:10:35PM +0800, micky_ching@realsil.com.cn wrote:
>> -static u8 sd_search_final_phase(struct realtek_pci_sdmmc *host, u32 phase_map)
>> +static inline u32 sd_get_phase_point(u32 phase_map, unsigned int idx)
>>   {
>> -	struct timing_phase_path path[MAX_PHASE + 1];
>> -	int i, j, cont_path_cnt;
>> -	int new_block, max_len, final_path_idx;
>> -	u8 final_phase = 0xFF;
>> +	idx &= MAX_PHASE;
>> +	return phase_map & (1 << idx);
>> +}
>> +
> This function is confusing....
>
> MAX_PHASE is a terrible name.  It's in a global header but it doesn't
> have a prefix.  It should be #define RTS_MAX_PHASE.  It's weird that we
> are using it both as a number and as bit mask.  It's weird that we
> always add a "+ 1" to MAX_PHASE.  It means the name is chosen poorly.
> Maybe it should be:
>
> #define RTS_MAX_PHASE  32
> #define RTS_PHASE_MASK 0x1f
That's good, I will modify and resend.
> So this function takes a phase_map and an index and it wraps the index
> by masking away the top bits then it tests to see if the wrapped index
> bit is set?  The wrapping is very strange.
We use this function to find whether the bit of index in the phase_map
is 1. The index can be twice as MAX_PHASE(reach to 63), because we use
a unidirectional search, start search continuous phase to found the
max continuous length from 0, 1, ..., to 31. When we start from
bit31, index 32 should wrap as 0. This function can be replaced by mod
function(idx %= MAX_PHASE + 1).
> The name of the function is sd_get_phase_point() but we only test to
> see if it returns zero.  The name of the function is not helpful.
> "sd" is a generic prefix.
> "get" is misleading because we don't "get" anything it only returns zero
> on success?
> "phase_point" might be helpful but I don't know what a phase_point is.
> Add a comment about that maybe.
Yes, thank you for your suggestion, the function name is really not good.
I want use test_phase_bit(u32 phase_map, unsigned int bit), is that ok?
> regards,
> dan carpenter
>
> .
>


-- 
Best Regards
Micky.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2013-11-20  9:13 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-19 11:10 [PATCH 0/2] fix sd power bug and modify phase-searching method micky_ching
2013-11-19 11:10 ` micky_ching
2013-11-19 11:10 ` [PATCH 1/2] mmc: rtsx: fix card poweroff bug micky_ching
2013-11-19 11:10   ` micky_ching
2013-11-19 11:10 ` [PATCH 2/2] mmc: rtsx: modify phase searching method for tunning micky_ching
2013-11-19 11:10   ` micky_ching
2013-11-20  8:17   ` Dan Carpenter
2013-11-20  8:17     ` Dan Carpenter
2013-11-20  9:13     ` micky
2013-11-20  9:13       ` micky

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.