Skip to contentSkip to conversation

] mmc:sdhci-pci-o2micro: Change implementation of tuning for SDR104 and HS200 mode

PATCH In review fred 2 participants 4 messages Dec 6, 2021 – Dec 14, 2021

Subsystems (2)
lore
Share & tools
lore

fred

author
#0 lore raw

PATCH v2 1/1 ] mmc:sdhci-pci-o2micro: Change implementation of tuning for SDR104 and HS200 mode

From: "fred.ai" <[email protected]>

Adjust the timing of an interface in SDR104 mode. After sending CMD6 successfully to switch card mode,driver need to select DLL output clock as SD clock.Setting DLL output clock phase value 0x9 when select DLL output clock source.

---
Change in V2:
1.Set register 0x354 bit 16 to select DLL clock
2.Set register 0x354 bit [23:20] to select fixed output tuning phase 0x9 3.Driver need to clear 0x354 bit 16 and bit [23:20] to 0 when setting clock

---
 drivers/mmc/host/sdhci-pci-o2micro.c | 57 ++++++++++++++++++++++------
 1 file changed, 45 insertions(+), 12 deletions(-)
drivers/mmc/host/sdhci-pci-o2micro.c +45 -12
index f045c1ee4667..98c1a17eb619 100644
@@ -43,6 +43,7 @@
 #define O2_SD_CAP_REG0		0x334
 #define O2_SD_UHS1_CAP_SETTING	0x33C
 #define O2_SD_DELAY_CTRL	0x350
+#define O2_SD_OUTPUT_CLK_SOURCE_SWITCH	0x354
 #define O2_SD_UHS2_L1_CTRL	0x35C
 #define O2_SD_FUNC_REG3		0x3E0
 #define O2_SD_FUNC_REG4		0x3E4
@@ -301,9 +302,14 @@ static int sdhci_o2_dll_recovery(struct sdhci_host *host)
 static int sdhci_o2_execute_tuning(struct mmc_host *mmc, u32 opcode)
 {
 	struct sdhci_host *host = mmc_priv(mmc);
+	struct sdhci_pci_slot *slot = sdhci_priv(host);
+	struct sdhci_pci_chip *chip = slot->chip;
 	int current_bus_width = 0;
 	u32 scratch32 = 0;
 	u16 scratch = 0;
+	u8  scratch_8 = 0;
+	u32 reg_val;
+	u8  dll_mode;
 
 	/*
 	 * This handler only implements the eMMC tuning that is specific to
@@ -322,6 +328,28 @@ static int sdhci_o2_execute_tuning(struct mmc_host *mmc, u32 opcode)
 	scratch |= O2_SD_PWR_FORCE_L0;
 	sdhci_writew(host, scratch, O2_SD_MISC_CTRL);
 
+	/* stop clk */
+	reg_val = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
+	reg_val &= ~(SDHCI_CLOCK_CARD_EN);
+	sdhci_writew(host, reg_val, SDHCI_CLOCK_CONTROL);
+
+	/* UnLock WP */
+	pci_read_config_byte(chip->pdev, O2_SD_LOCK_WP, &scratch_8);
+	scratch_8 &= 0x7f;
+	pci_write_config_byte(chip->pdev, O2_SD_LOCK_WP, scratch_8);
+
+	/* Set pcr 0x354[16] to choose dll clock, and set the default phase */
+	dll_mode = 0x9;
+	pci_read_config_dword(chip->pdev, O2_SD_OUTPUT_CLK_SOURCE_SWITCH, &reg_val);
+	reg_val &= 0xFF0EFFFF;
+	reg_val |= ((1 << 16) | (dll_mode << 20));
+	pci_write_config_dword(chip->pdev, O2_SD_OUTPUT_CLK_SOURCE_SWITCH, reg_val);
+
+    /* start clk */
+	reg_val = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
+	reg_val |= SDHCI_CLOCK_CARD_EN;
+	sdhci_writew(host, reg_val, SDHCI_CLOCK_CONTROL);
+
 	/* wait DLL lock, timeout value 5ms */
 	if (readx_poll_timeout(sdhci_o2_pll_dll_wdt_control, host,
 		scratch32, (scratch32 & O2_DLL_LOCK_STATUS), 1, 5000))
@@ -520,11 +548,11 @@ static void sdhci_o2_enable_clk(struct sdhci_host *host, u16 clk)
 
 static void sdhci_pci_o2_set_clock(struct sdhci_host *host, unsigned int clock)
 {
-	u16 clk;
-	u8 scratch;
-	u32 scratch_32;
 	struct sdhci_pci_slot *slot = sdhci_priv(host);
 	struct sdhci_pci_chip *chip = slot->chip;
+	u32 scratch_32;
+	u8 scratch;
+	u16 clk;
 
 	host->mmc->actual_clock = 0;
 
@@ -533,22 +561,27 @@ static void sdhci_pci_o2_set_clock(struct sdhci_host *host, unsigned int clock)
 	if (clock == 0)
 		return;
 
-	if ((host->timing == MMC_TIMING_UHS_SDR104) && (clock == 200000000)) {
-		pci_read_config_byte(chip->pdev, O2_SD_LOCK_WP, &scratch);
-
-		scratch &= 0x7f;
-		pci_write_config_byte(chip->pdev, O2_SD_LOCK_WP, scratch);
+	/* UnLock WP */
+	pci_read_config_byte(chip->pdev, O2_SD_LOCK_WP, &scratch);
+	scratch &= 0x7f;
+	pci_write_config_byte(chip->pdev, O2_SD_LOCK_WP, scratch);
 
+	if ((host->timing == MMC_TIMING_UHS_SDR104) && (clock == 200000000)) {
 		pci_read_config_dword(chip->pdev, O2_SD_PLL_SETTING, &scratch_32);
 
 		if ((scratch_32 & 0xFFFF0000) != 0x2c280000)
 			o2_pci_set_baseclk(chip, 0x2c280000);
+	}
 
-		pci_read_config_byte(chip->pdev, O2_SD_LOCK_WP, &scratch);
+	pci_read_config_dword(chip->pdev, O2_SD_OUTPUT_CLK_SOURCE_SWITCH, &scratch_32);
+	scratch_32 &= ~(1 << 16);
+	scratch_32 &= ~(0xf << 20);
+	pci_write_config_dword(chip->pdev, O2_SD_OUTPUT_CLK_SOURCE_SWITCH, scratch_32);
 
-		scratch |= 0x80;
-		pci_write_config_byte(chip->pdev, O2_SD_LOCK_WP, scratch);
-	}
+    /* Lock WP */
+	pci_read_config_byte(chip->pdev, O2_SD_LOCK_WP, &scratch);
+	scratch |= 0x80;
+	pci_write_config_byte(chip->pdev, O2_SD_LOCK_WP, scratch);
 
 	clk = sdhci_calc_clk(host, clock, &host->mmc->actual_clock);
 	sdhci_o2_enable_clk(host, clk);
Signature · 1 line
2.32.0
author
#1 lore raw

PATCH v2 1/1 2/2] mmc:sdhci-pci-o2micro:Change implementation of setting corresponding PLL frequency according to card mode

From: "fred.ai" <[email protected]>

Driver will set PLL frequency by different card mode 1.SD2.0 and SDR50 card mode base clock frequency is 208MHz 2.SDR104 card mode base clock frequency is 200MHz

Change in V2:
---
After SD2.0 or SDR50 card initlization, driver will select base clock frequency 200MHz by setting PLL frequency value 0x2510.

---
 drivers/mmc/host/sdhci-pci-o2micro.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/mmc/host/sdhci-pci-o2micro.c +8 -0
index 98c1a17eb619..4d79fda10dcb 100644
@@ -569,8 +569,16 @@ static void sdhci_pci_o2_set_clock(struct sdhci_host *host, unsigned int clock)
 	if ((host->timing == MMC_TIMING_UHS_SDR104) && (clock == 200000000)) {
 		pci_read_config_dword(chip->pdev, O2_SD_PLL_SETTING, &scratch_32);
 
+		/* SDR104 card mode PLL frequency value is 0x2c28 */
 		if ((scratch_32 & 0xFFFF0000) != 0x2c280000)
 			o2_pci_set_baseclk(chip, 0x2c280000);
+
+	} else {
+		pci_read_config_dword(chip->pdev, O2_SD_PLL_SETTING, &scratch_32);
+
+		/* SD2.0,SDR50 card mode PLL frequency value is 0X2510 */
+		if ((scratch_32 & 0xFFFF0000) != 0x2510000)
+			o2_pci_set_baseclk(chip, 0x25100000);
 	}
 
 	pci_read_config_dword(chip->pdev, O2_SD_OUTPUT_CLK_SOURCE_SWITCH, &scratch_32);
Signature · 1 line
2.32.0
maintainer
#2 lore raw

Re: [[PATCH V2] 2/2] mmc:sdhci-pci-o2micro:Change implementation of setting corresponding PLL frequency according to card mode

Quoted 5 lines · fred

From: "fred.ai" <[email protected]>

Driver will set PLL frequency by different card mode 1.SD2.0 and SDR50 card mode base clock frequency is 208MHz 2.SDR104 card mode base clock frequency is 200MHz

Again the subject needs improvement, should have been like:

[PATCH V2 2/2] mmc: sdhci-pci-o2micro: Change implementation of setting corresponding PLL frequency according to card mode

Quoted 5 lines

Change in V2:
---

This '---' here causes the "Change in V2:" alone to be in the commit message. Better to put it after the signed-off line.

Quoted 28 lines

After SD2.0 or SDR50 card initlization, driver will select base clock frequency 200MHz by setting PLL frequency value 0x2510.

---
 drivers/mmc/host/sdhci-pci-o2micro.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/mmc/host/sdhci-pci-o2micro.c +8 -0
index 98c1a17eb619..4d79fda10dcb 100644
@@ -569,8 +569,16 @@ static void sdhci_pci_o2_set_clock(struct sdhci_host *host, unsigned int clock)
 	if ((host->timing == MMC_TIMING_UHS_SDR104) && (clock == 200000000)) {
 		pci_read_config_dword(chip->pdev, O2_SD_PLL_SETTING, &scratch_32);
 
+		/* SDR104 card mode PLL frequency value is 0x2c28 */
 		if ((scratch_32 & 0xFFFF0000) != 0x2c280000)
 			o2_pci_set_baseclk(chip, 0x2c280000);
+
+	} else {
+		pci_read_config_dword(chip->pdev, O2_SD_PLL_SETTING, &scratch_32);
+
+		/* SD2.0,SDR50 card mode PLL frequency value is 0X2510 */
+		if ((scratch_32 & 0xFFFF0000) != 0x2510000)
+			o2_pci_set_baseclk(chip, 0x25100000);
 	}
 
 	pci_read_config_dword(chip->pdev, O2_SD_OUTPUT_CLK_SOURCE_SWITCH, &scratch_32);
maintainer
#3 lore raw
In reply to fred
Quoted 5 lines · fred

From: "fred.ai" <[email protected]>

Adjust the timing of an interface in SDR104 mode. After sending CMD6 successfully to switch card mode,driver need to select DLL output
clock as SD clock.Setting DLL output clock phase value 0x9 when> select DLL output clock source.

There are some kernel-style issues.

Only single '[' in subject please e.g. should have been [PATCH V2 1/2] not [[PATCH V2]]. Also missing patch number and a space after mmc: i.e. should have been:

[PATCH V2 1/2] mmc: sdhci-pci-o2micro: Change implementation of tuning for SDR104 and HS200 mode

Quoted 2 lines

Normally names are separated with space and capitalized, so perhaps Fred Ai rather than fred.ai ?

Quoted 37 lines

---
Change in V2:
1.Set register 0x354 bit 16 to select DLL clock
2.Set register 0x354 bit [23:20] to select fixed output tuning phase 0x9 3.Driver need to clear 0x354 bit 16 and bit [23:20] to 0 when setting clock

---
 drivers/mmc/host/sdhci-pci-o2micro.c | 57 ++++++++++++++++++++++------
 1 file changed, 45 insertions(+), 12 deletions(-)
drivers/mmc/host/sdhci-pci-o2micro.c +6 -0
index f045c1ee4667..98c1a17eb619 100644
@@ -43,6 +43,7 @@
 #define O2_SD_CAP_REG0		0x334
 #define O2_SD_UHS1_CAP_SETTING	0x33C
 #define O2_SD_DELAY_CTRL	0x350
+#define O2_SD_OUTPUT_CLK_SOURCE_SWITCH	0x354
 #define O2_SD_UHS2_L1_CTRL	0x35C
 #define O2_SD_FUNC_REG3		0x3E0
 #define O2_SD_FUNC_REG4		0x3E4
@@ -301,9 +302,14 @@ static int sdhci_o2_dll_recovery(struct sdhci_host *host)
 static int sdhci_o2_execute_tuning(struct mmc_host *mmc, u32 opcode)
 {
 	struct sdhci_host *host = mmc_priv(mmc);
+	struct sdhci_pci_slot *slot = sdhci_priv(host);
+	struct sdhci_pci_chip *chip = slot->chip;
 	int current_bus_width = 0;
 	u32 scratch32 = 0;
 	u16 scratch = 0;
+	u8  scratch_8 = 0;
+	u32 reg_val;
+	u8  dll_mode;
 
 	/*
 	 * This handler only implements the eMMC tuning that is specific to

drivers/mmc/host/sdhci-pci-o2micro.c static int sdhci_o2_execute_tuning(struct mmc_host *mmc, u32 opcode) · line 333

Quoted 6 lines
drivers/mmc/host/sdhci-pci-o2micro.c +3 -0
@@ -322,6 +328,28 @@ static int sdhci_o2_execute_tuning(struct mmc_host *mmc, u32 opcode)
 	scratch |= O2_SD_PWR_FORCE_L0;
 	sdhci_writew(host, scratch, O2_SD_MISC_CTRL);
 
+	/* stop clk */
+	reg_val = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
+	reg_val &= ~(SDHCI_CLOCK_CARD_EN);

Parenthesis not needed

drivers/mmc/host/sdhci-pci-o2micro.c static int sdhci_o2_execute_tuning(struct mmc_host *mmc, u32 opcode) · line 345

Quoted 12 lines
drivers/mmc/host/sdhci-pci-o2micro.c +12 -0
+	sdhci_writew(host, reg_val, SDHCI_CLOCK_CONTROL);
+
+	/* UnLock WP */
+	pci_read_config_byte(chip->pdev, O2_SD_LOCK_WP, &scratch_8);
+	scratch_8 &= 0x7f;
+	pci_write_config_byte(chip->pdev, O2_SD_LOCK_WP, scratch_8);
+
+	/* Set pcr 0x354[16] to choose dll clock, and set the default phase */
+	dll_mode = 0x9;
+	pci_read_config_dword(chip->pdev, O2_SD_OUTPUT_CLK_SOURCE_SWITCH, &reg_val);
+	reg_val &= 0xFF0EFFFF;
+	reg_val |= ((1 << 16) | (dll_mode << 20));

It would be nicer to define BIT() and GENMASK() and use FIELD_PREP here, refer include/linux/bitfield.h

drivers/mmc/host/sdhci-pci-o2micro.c static int sdhci_o2_execute_tuning(struct mmc_host *mmc, u32 opcode) · line 348

Quoted 3 lines
drivers/mmc/host/sdhci-pci-o2micro.c +3 -0
+	pci_write_config_dword(chip->pdev, O2_SD_OUTPUT_CLK_SOURCE_SWITCH, reg_val);
+
+    /* start clk */

Indent should be a single tab.

drivers/mmc/host/sdhci-pci-o2micro.c static int sdhci_o2_execute_tuning(struct mmc_host *mmc, u32 opcode) · line 351

Quoted 3 lines
drivers/mmc/host/sdhci-pci-o2micro.c +3 -0
+	reg_val = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
+	reg_val |= SDHCI_CLOCK_CARD_EN;
+	sdhci_writew(host, reg_val, SDHCI_CLOCK_CONTROL);

Other places in the code seem to pair "Unlock WP" with "Lock WP" but there is not one here. Is that correct?

Quoted 6 lines
drivers/mmc/host/sdhci-pci-o2micro.c +1 -0
+
 	/* wait DLL lock, timeout value 5ms */
 	if (readx_poll_timeout(sdhci_o2_pll_dll_wdt_control, host,
 		scratch32, (scratch32 & O2_DLL_LOCK_STATUS), 1, 5000))
@@ -520,11 +548,11 @@ static void sdhci_o2_enable_clk(struct sdhci_host *host, u16 clk)
 

drivers/mmc/host/sdhci-pci-o2micro.c static void sdhci_o2_enable_clk(struct sdhci_host *host, u16 clk) · line 555

Quoted 10 lines
drivers/mmc/host/sdhci-pci-o2micro.c +3 -3
 static void sdhci_pci_o2_set_clock(struct sdhci_host *host, unsigned int clock)
 {
-	u16 clk;
-	u8 scratch;
-	u32 scratch_32;
 	struct sdhci_pci_slot *slot = sdhci_priv(host);
 	struct sdhci_pci_chip *chip = slot->chip;
+	u32 scratch_32;
+	u8 scratch;
+	u16 clk;

Please do not make unrelated changes

Quoted 18 lines
drivers/mmc/host/sdhci-pci-o2micro.c +5 -5
 	host->mmc->actual_clock = 0;
 
@@ -533,22 +561,27 @@ static void sdhci_pci_o2_set_clock(struct sdhci_host *host, unsigned int clock)
 	if (clock == 0)
 		return;
 
-	if ((host->timing == MMC_TIMING_UHS_SDR104) && (clock == 200000000)) {
-		pci_read_config_byte(chip->pdev, O2_SD_LOCK_WP, &scratch);
-
-		scratch &= 0x7f;
-		pci_write_config_byte(chip->pdev, O2_SD_LOCK_WP, scratch);
+	/* UnLock WP */
+	pci_read_config_byte(chip->pdev, O2_SD_LOCK_WP, &scratch);
+	scratch &= 0x7f;
+	pci_write_config_byte(chip->pdev, O2_SD_LOCK_WP, scratch);
 
+	if ((host->timing == MMC_TIMING_UHS_SDR104) && (clock == 200000000)) {

drivers/mmc/host/sdhci-pci-o2micro.c static void sdhci_pci_o2_set_clock(struct sdhci_host *host, unsigned int clock) · line 578

Quoted 10 lines
drivers/mmc/host/sdhci-pci-o2micro.c +4 -1
 		pci_read_config_dword(chip->pdev, O2_SD_PLL_SETTING, &scratch_32);
 
 		if ((scratch_32 & 0xFFFF0000) != 0x2c280000)
 			o2_pci_set_baseclk(chip, 0x2c280000);
+	}
 
-		pci_read_config_byte(chip->pdev, O2_SD_LOCK_WP, &scratch);
+	pci_read_config_dword(chip->pdev, O2_SD_OUTPUT_CLK_SOURCE_SWITCH, &scratch_32);
+	scratch_32 &= ~(1 << 16);
+	scratch_32 &= ~(0xf << 20);

It would be nicer to define BIT() and GENMASK() and use them here, refer include/linux/bitfield.h

drivers/mmc/host/sdhci-pci-o2micro.c static void sdhci_pci_o2_set_clock(struct sdhci_host *host, unsigned int clock) · line 581

Quoted 6 lines
drivers/mmc/host/sdhci-pci-o2micro.c +2 -3
+	pci_write_config_dword(chip->pdev, O2_SD_OUTPUT_CLK_SOURCE_SWITCH, scratch_32);
 
-		scratch |= 0x80;
-		pci_write_config_byte(chip->pdev, O2_SD_LOCK_WP, scratch);
-	}
+    /* Lock WP */

Indent a single tab

Quoted 7 lines
drivers/mmc/host/sdhci-pci-o2micro.c +3 -0
+	pci_read_config_byte(chip->pdev, O2_SD_LOCK_WP, &scratch);
+	scratch |= 0x80;
+	pci_write_config_byte(chip->pdev, O2_SD_LOCK_WP, scratch);
 
 	clk = sdhci_calc_clk(host, clock, &host->mmc->actual_clock);
 	sdhci_o2_enable_clk(host, clk);