Re: [patch 1/1]sdhci: sdhc spec 3.0 add some modification

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Aug 9, 2010 at 6:10 PM, Matt Fleming <matt@xxxxxxxxxxxxxxxxx> wrote:
> On Thu, Aug 05, 2010 at 03:09:14PM +0800, zhangfei gao wrote:
>> >>
>> >>        1. support 8 bit data transfer width
>> > 8 bit buswidth patch is already merged to mm tree.
>> >
>> > http://marc.info/?l=linux-mmc&m=127783663526810&w=3
>> >
>> > Thank you,
>> > Kyungmin Park
>> >
>>
>> Thanks Kyungmin, updated without 8 bit support.
>>
>> From 2b717444443acdac90c5f31522a1515a2000749a Mon Sep 17 00:00:00 2001
>> From: Zhangfei Gao <zgao6@xxxxxxxxxxx>
>> Date: Fri, 6 Aug 2010 07:10:01 +0800
>> Subject: [PATCH] sdhc: support 10-bit divided clock Mode
>>
>>
>> Signed-off-by: Zhangfei Gao <zgao6@xxxxxxxxxxx>
>> ---
>>  drivers/mmc/host/sdhci.c |    5 +++--
>>  drivers/mmc/host/sdhci.h |    4 ++++
>>  2 files changed, 7 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
>> index c6d1bd8..212dc9e 100644
>> --- a/drivers/mmc/host/sdhci.c
>> +++ b/drivers/mmc/host/sdhci.c
>> @@ -1002,7 +1002,8 @@ static void sdhci_set_clock(struct sdhci_host
>> *host, unsigned int clock)
>>       }
>>       div >>= 1;
>>
>> -     clk = div << SDHCI_DIVIDER_SHIFT;
>> +     clk = (div & SDHCI_DIV_MASK) << SDHCI_DIVIDER_SHIFT;
>> +     clk |= ((div & SDHCI_DIV_HI_MASK) >> SDHCI_DIVIDER_SHIFT) <<
>> SDHCI_DIVIDER_SHIFT_HI;
>>       clk |= SDHCI_CLOCK_INT_EN;
>>       sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
>>
>
> This patch is missing a change to the way we calculate 'div'. While your
> patch is correct, I think it would be better to fit some more things
> into it.
>
> This is the current code for calculating the clock divider,
>
>
>        for (div = 1;div < 256;div *= 2) {
>                if ((host->max_clk / div) <= clock)
>                        break;
>        }
>        div >>= 1;
>
>        clk = div << SDHCI_DIVIDER_SHIFT;
>
>
> even with your patch applied 'div' will never be greater 256 and we
> won't be executing your changes. So I think this patch also needs to
> bump the upper limit of 'div' to 2046.
>
> We should probably introduce some safety at this point and check that
> the divider value is legal for the version of the host controller, to
> stop people shooting themselves in the foot if they mess up their clock
> settings. I was thinking of something like,
>
>        if (host->version >= SDHCI_SPEC_300)
>                max_div = 2046;
>        else
>                max_div = 256;
>
>        for (div = 1;div < max_div;div *= 2) {
>                if ((host->max_clk / div) <= clock)
>                        break;
>        }
>
> What do you think?
>

Thanks for your careful review, in our platform, we use max/min for
the max_div, so miss this modification :(
Update the patch, help review again.

>From 4b0a4d60fb39437a7fde7e52fb769fa0110c052f Mon Sep 17 00:00:00 2001
From: Zhangfei Gao <zgao6@xxxxxxxxxxx>
Date: Fri, 6 Aug 2010 07:10:01 +0800
Subject: [PATCH] sdhc: support 10-bit divided clock Mode

Signed-off-by: Zhangfei Gao <zgao6@xxxxxxxxxxx>
Reviewed-by: Matt Fleming <matt@xxxxxxxxxxxxxxxxx>
---
 drivers/mmc/host/sdhci.c |   14 ++++++++++----
 drivers/mmc/host/sdhci.h |    4 ++++
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index c6d1bd8..c4b3d6f 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -978,7 +978,7 @@ static void sdhci_finish_command(struct sdhci_host *host)

 static void sdhci_set_clock(struct sdhci_host *host, unsigned int clock)
 {
-	int div;
+	int div, max_div;
 	u16 clk;
 	unsigned long timeout;

@@ -996,13 +996,19 @@ static void sdhci_set_clock(struct sdhci_host
*host, unsigned int clock)
 	if (clock == 0)
 		goto out;

-	for (div = 1;div < 256;div *= 2) {
+	if (host->version >= SDHCI_SPEC_300)
+		max_div = 2046;
+	else
+		max_div = 256;
+
+	for (div = 1;div < max_div;div *= 2) {
 		if ((host->max_clk / div) <= clock)
 			break;
 	}
 	div >>= 1;

-	clk = div << SDHCI_DIVIDER_SHIFT;
+	clk = (div & SDHCI_DIV_MASK) << SDHCI_DIVIDER_SHIFT;
+	clk |= ((div & SDHCI_DIV_HI_MASK) >> SDHCI_DIVIDER_SHIFT) <<
SDHCI_DIVIDER_SHIFT_HI;
 	clk |= SDHCI_CLOCK_INT_EN;
 	sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);

@@ -1681,7 +1687,7 @@ int sdhci_add_host(struct sdhci_host *host)
 	host->version = sdhci_readw(host, SDHCI_HOST_VERSION);
 	host->version = (host->version & SDHCI_SPEC_VER_MASK)
 				>> SDHCI_SPEC_VER_SHIFT;
-	if (host->version > SDHCI_SPEC_200) {
+	if (host->version > SDHCI_SPEC_300) {
 		printk(KERN_ERR "%s: Unknown controller version (%d). "
 			"You may experience problems.\n", mmc_hostname(mmc),
 			host->version);
diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h
index c846813..7c09b4f 100644
--- a/drivers/mmc/host/sdhci.h
+++ b/drivers/mmc/host/sdhci.h
@@ -85,6 +85,9 @@

 #define SDHCI_CLOCK_CONTROL	0x2C
 #define  SDHCI_DIVIDER_SHIFT	8
+#define  SDHCI_DIVIDER_SHIFT_HI	6
+#define  SDHCI_DIV_MASK	0xFF
+#define  SDHCI_DIV_HI_MASK	0x300
 #define  SDHCI_CLOCK_CARD_EN	0x0004
 #define  SDHCI_CLOCK_INT_STABLE	0x0002
 #define  SDHCI_CLOCK_INT_EN	0x0001
@@ -177,6 +180,7 @@
 #define  SDHCI_SPEC_VER_SHIFT	0
 #define   SDHCI_SPEC_100	0
 #define   SDHCI_SPEC_200	1
+#define   SDHCI_SPEC_300	2

 struct sdhci_ops;

-- 
1.6.0.4

Attachment: 0001-sdhc-support-10-bit-divided-clock-Mode.patch
Description: Binary data


[Index of Archives]     [Linux USB Devel]     [Linux Media]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux