Hi, On Fri, Nov 19, 2021 at 3:12 AM Mårten Lindahl <marten.lindahl@xxxxxxxx> wrote: > > 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 <marten.lindahl@xxxxxxxx> > --- > > 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 > > drivers/mmc/host/dw_mmc.c | 29 ++++++++++++++++++++++++++++- > 1 file changed, 28 insertions(+), 1 deletion(-) > > diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c > index d977f34f6b55..210252d33b95 100644 > --- a/drivers/mmc/host/dw_mmc.c > +++ b/drivers/mmc/host/dw_mmc.c > @@ -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; > + unsigned long 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); Unfortunately I don't think "tmp" is always a 64-bit type (unsigned long is only 32-bit on many devices). As per my response just now to your v4, I'd be happy with going back to a normal DIV_ROUND_UP. However, if you want to keep it extra safe and keep the _ULL version then you should change tmp to "u64". In any case: Reviewed-by: Douglas Anderson <dianders@xxxxxxxxxxxx>