mmc: dw_mmc: Allow lower TMOUT value than maximum
Subsystems (2)
PATCH v6 1/1 mmc: dw_mmc: Allow lower TMOUT value than maximum
The TMOUT register is always set with a full value for every transfer, which (with a 200MHz clock) will give a full DRTO of ~84 milliseconds. This is normally good enough to complete the request, but setting a full value makes it impossible to test shorter timeouts, when for example testing data read times on different SD cards.
Add a function to set any value smaller than the maximum of 0xFFFFFF.
---
v2:
- Calculate new value before checking boundaries
- Include CLKDIV register to get proper value
v3:
- Use 'if-else' instead of 'goto'
- Don't touch response field when maximize data field
v4:
- Prevent 32bit divider overflow by splitting the operation
- Changed %06x to %#08x as suggested by Doug
- Rephrased commit msg as suggested by Doug
v5:
- Use u32 type for CPU reg access
- Make tmp 64bit to handle INT_MAX parameters
v6:
- Use u64 type for tmp
drivers/mmc/host/dw_mmc.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-)
drivers/mmc/host/dw_mmc.c +28 -1
@@ -1283,6 +1283,33 @@ static void dw_mci_setup_bus(struct dw_mci_slot *slot, bool force_clkinit)mci_writel (host,CTYPE , (slot->ctype << slot->id)); } +static void dw_mci_set_data_timeout (struct dw_mci *host, +unsigned int timeout_ns) +{ +u32 clk_div, tmout; +u64 tmp; + + clk_div = (mci_readl (host,CLKDIV ) &0xFF ) *2 ; +if (clk_div ==0 ) + clk_div =1 ; + + tmp =DIV_ROUND_UP_ULL ((u64 )timeout_ns * host->bus_hz,NSEC_PER_SEC ); + tmp =DIV_ROUND_UP_ULL (tmp, clk_div); + +/* TMOUT[7:0] (RESPONSE_TIMEOUT) */ + tmout =0xFF ;/* Set maximum */ + +/* TMOUT[31:8] (DATA_TIMEOUT) */ +if (!tmp || tmp >0xFFFFFF ) + tmout |= (0xFFFFFF <<8 ); +else + tmout |= (tmp &0xFFFFFF ) <<8 ; + +mci_writel (host,TMOUT , tmout); +dev_dbg (host->dev,"timeout_ns: %u => TMOUT[31:8]: 0x%#08x" , + timeout_ns, tmout >>8 ); +} +static void __dw_mci_start_request (struct dw_mci *host,struct dw_mci_slot *slot,struct mmc_command *cmd)
@@ -1303,7 +1330,7 @@ static void __dw_mci_start_request(struct dw_mci *host, data = cmd->data;if (data) { -mci_writel (host,TMOUT ,0xFFFFFFFF ); +dw_mci_set_data_timeout (host, data->timeout_ns);mci_writel (host,BYTCNT , data->blksz*data->blocks);mci_writel (host,BLKSIZ , data->blksz); }
Signature · 1 line
2.20.1
Hi,
Quoted 29 lines · Mårten Lindahl
The TMOUT register is always set with a full value for every transfer, which (with a 200MHz clock) will give a full DRTO of ~84 milliseconds. This is normally good enough to complete the request, but setting a full value makes it impossible to test shorter timeouts, when for example testing data read times on different SD cards.
Add a function to set any value smaller than the maximum of
0xFFFFFF.Signed-off-by Mårten Lindahl <[email protected]>---
v2:
- Calculate new value before checking boundaries
- Include CLKDIV register to get proper valuev3:
- Use 'if-else' instead of 'goto'
- Don't touch response field when maximize data fieldv4:
- Prevent 32bit divider overflow by splitting the operation
- Changed %06x to %#08x as suggested by Doug
- Rephrased commit msg as suggested by Dougv5:
- Use u32 type for CPU reg access
- Make tmp 64bit to handleINT_MAXparameters
Quoted 5 lines
v6:
- Use u64 type for tmpdrivers/mmc/host/dw_mmc.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-)
Quoted 9 lines · Mårten Lindahl
The TMOUT register is always set with a full value for every transfer, which (with a 200MHz clock) will give a full DRTO of ~84 milliseconds. This is normally good enough to complete the request, but setting a full value makes it impossible to test shorter timeouts, when for example testing data read times on different SD cards.
Add a function to set any value smaller than the maximum of
0xFFFFFF.Signed-off-by Mårten Lindahl <[email protected]>
Best Regards,
Jaehoon Chung
Quoted 73 lines
---
v2:
- Calculate new value before checking boundaries
- Include CLKDIV register to get proper valuev3:
- Use 'if-else' instead of 'goto'
- Don't touch response field when maximize data fieldv4:
- Prevent 32bit divider overflow by splitting the operation
- Changed %06x to %#08x as suggested by Doug
- Rephrased commit msg as suggested by Dougv5:
- Use u32 type for CPU reg access
- Make tmp 64bit to handleINT_MAXparametersv6:
- Use u64 type for tmpdrivers/mmc/host/dw_mmc.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-)drivers/mmc/host/dw_mmc.c +28
-1@@ -1283,6 +1283,33 @@ static void dw_mci_setup_bus(struct dw_mci_slot *slot, bool force_clkinit)mci_writel (host,CTYPE , (slot->ctype << slot->id)); } +static void dw_mci_set_data_timeout (struct dw_mci *host, +unsigned int timeout_ns) +{ +u32 clk_div, tmout; +u64 tmp; + + clk_div = (mci_readl (host,CLKDIV ) &0xFF ) *2 ; +if (clk_div ==0 ) + clk_div =1 ; + + tmp =DIV_ROUND_UP_ULL ((u64 )timeout_ns * host->bus_hz,NSEC_PER_SEC ); + tmp =DIV_ROUND_UP_ULL (tmp, clk_div); + +/* TMOUT[7:0] (RESPONSE_TIMEOUT) */ + tmout =0xFF ;/* Set maximum */ + +/* TMOUT[31:8] (DATA_TIMEOUT) */ +if (!tmp || tmp >0xFFFFFF ) + tmout |= (0xFFFFFF <<8 ); +else + tmout |= (tmp &0xFFFFFF ) <<8 ; + +mci_writel (host,TMOUT , tmout); +dev_dbg (host->dev,"timeout_ns: %u => TMOUT[31:8]: 0x%#08x" , + timeout_ns, tmout >>8 ); +} +static void __dw_mci_start_request (struct dw_mci *host,struct dw_mci_slot *slot,struct mmc_command *cmd)@@ -1303,7 +1330,7 @@ static void __dw_mci_start_request(struct dw_mci *host, data = cmd->data;if (data) { -mci_writel (host,TMOUT ,0xFFFFFFFF ); +dw_mci_set_data_timeout (host, data->timeout_ns);mci_writel (host,BYTCNT , data->blksz*data->blocks);mci_writel (host,BLKSIZ , data->blksz); }
Quoted 10 lines · Mårten Lindahl
The TMOUT register is always set with a full value for every transfer, which (with a 200MHz clock) will give a full DRTO of ~84 milliseconds. This is normally good enough to complete the request, but setting a full value makes it impossible to test shorter timeouts, when for example testing data read times on different SD cards.
Add a function to set any value smaller than the maximum of
0xFFFFFF.Signed-off-by Mårten Lindahl <[email protected]>
Applied for next, thanks!
Kind regards
Uffe
Quoted 75 lines
---
v2:
- Calculate new value before checking boundaries
- Include CLKDIV register to get proper valuev3:
- Use 'if-else' instead of 'goto'
- Don't touch response field when maximize data fieldv4:
- Prevent 32bit divider overflow by splitting the operation
- Changed %06x to %#08x as suggested by Doug
- Rephrased commit msg as suggested by Dougv5:
- Use u32 type for CPU reg access
- Make tmp 64bit to handleINT_MAXparametersv6:
- Use u64 type for tmpdrivers/mmc/host/dw_mmc.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-)drivers/mmc/host/dw_mmc.c +28
-2@@ -1283,6 +1283,33 @@ static void dw_mci_setup_bus(struct dw_mci_slot *slot, bool force_clkinit)mci_writel (host,CTYPE , (slot->ctype << slot->id)); } +static void dw_mci_set_data_timeout (struct dw_mci *host, +unsigned int timeout_ns) +{ +u32 clk_div, tmout; +u64 tmp; + + clk_div = (mci_readl (host,CLKDIV ) &0xFF ) *2 ; +if (clk_div ==0 ) + clk_div =1 ; + + tmp =DIV_ROUND_UP_ULL ((u64 )timeout_ns * host->bus_hz,NSEC_PER_SEC ); + tmp =DIV_ROUND_UP_ULL (tmp, clk_div); + +/* TMOUT[7:0] (RESPONSE_TIMEOUT) */ + tmout =0xFF ;/* Set maximum */ + +/* TMOUT[31:8] (DATA_TIMEOUT) */ +if (!tmp || tmp >0xFFFFFF ) + tmout |= (0xFFFFFF <<8 ); +else + tmout |= (tmp &0xFFFFFF ) <<8 ; + +mci_writel (host,TMOUT , tmout); +dev_dbg (host->dev,"timeout_ns: %u => TMOUT[31:8]: 0x%#08x" , + timeout_ns, tmout >>8 ); +} +static void __dw_mci_start_request (struct dw_mci *host,struct dw_mci_slot *slot,struct mmc_command *cmd)@@ -1303,7 +1330,7 @@ static void __dw_mci_start_request(struct dw_mci *host, data = cmd->data;if (data) { -mci_writel (host,TMOUT ,0xFFFFFFFF ); +dw_mci_set_data_timeout (host, data->timeout_ns);mci_writel (host,BYTCNT , data->blksz*data->blocks);mci_writel (host,BLKSIZ , data->blksz); } --2.20.1