linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Gabriel L. Somlo" <gsomlo@gmail.com>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Rob Herring <robh+dt@kernel.org>,
	devicetree <devicetree@vger.kernel.org>,
	Ulf Hansson <ulf.hansson@linaro.org>,
	linux-mmc <linux-mmc@vger.kernel.org>,
	Karol Gugala <kgugala@antmicro.com>,
	Mateusz Holenko <mholenko@antmicro.com>,
	Kamil Rakoczy <krakoczy@antmicro.com>,
	mdudek@internships.antmicro.com,
	Paul Mackerras <paulus@ozlabs.org>, Joel Stanley <joel@jms.id.au>,
	Stafford Horne <shorne@gmail.com>,
	Geert Uytterhoeven <geert@linux-m68k.org>,
	david.abdurachmanov@sifive.com,
	Florent Kermarrec <florent@enjoy-digital.fr>,
	Randy Dunlap <rdunlap@infradead.org>
Subject: Re: [PATCH v9 3/3] mmc: Add driver for LiteX's LiteSDCard interface
Date: Sat, 8 Jan 2022 19:26:03 -0500	[thread overview]
Message-ID: <Ydorm5HirY2i/RCg@errol.ini.cmu.edu> (raw)
In-Reply-To: <CAHp75VeEvT-_47gKFAYdz-BR9y=KLEw2uMbRxYKo1rLQSQEfyg@mail.gmail.com>

On Sat, Jan 08, 2022 at 07:43:19PM +0200, Andy Shevchenko wrote:
> On Sat, Jan 8, 2022 at 6:11 PM Gabriel Somlo <gsomlo@gmail.com> wrote:
> >
> > LiteX (https://github.com/enjoy-digital/litex) is a SoC framework
> > that targets FPGAs. LiteSDCard is a small footprint, configurable
> > SDCard core commonly used in LiteX designs.
> >
> > The driver was first written in May 2020 and has been maintained
> > cooperatively by the LiteX community. Thanks to all contributors!
> 
> Thanks for an update, my comments below.
> 
> ...
> 
> > +#include <linux/bits.h>
> > +#include <linux/clk.h>
> > +#include <linux/delay.h>
> > +#include <linux/dma-mapping.h>
> > +#include <linux/interrupt.h>
> > +#include <linux/iopoll.h>
> > +#include <linux/litex.h>
> > +#include <linux/mod_devicetable.h>
> > +#include <linux/module.h>
> 
> > +#include <linux/mmc/host.h>
> > +#include <linux/mmc/mmc.h>
> > +#include <linux/mmc/sd.h>
> 
> I would move this group of headers...
> 
> > +#include <linux/platform_device.h>
> > +
> 
> ...somewhere here to show that this driver belongs to the MMC subsystem.

OK, lined up for v10
 
> ...
> 
> > +#define LITEX_MMC_OCR (MMC_VDD_27_28 | MMC_VDD_28_29 | MMC_VDD_29_30 | \
> > +                      MMC_VDD_30_31 | MMC_VDD_31_32 | MMC_VDD_32_33 | \
> > +                      MMC_VDD_33_34 | MMC_VDD_34_35 | MMC_VDD_35_36)
> 
> Seems to me this is identical to
> https://elixir.bootlin.com/linux/latest/source/drivers/mmc/host/au1xmmc.c#L72
> 
> And may be reused in
> https://elixir.bootlin.com/linux/latest/source/drivers/mmc/host/vub300.c#L2168.
> 
> Perhaps it makes sense to have
> 
> #define MMC_VDD_27_36 ...
> 
> in mmc.h?
> 
> In any case, it can be postponed, just a side note for the future improvements.

I'm awaiting follow-up advice from Ulf Hansson, who originally suggested
this should be dynamically configured through a dummy voltage regulator
in DTS. Since LiteSDCard doesn't a (current or planned) option to
adaptively configure voltages via software, I think hard-coding the
valid range in the driver (in the exact way as au1xmmc.c) might be
cleaner, and if we end up agreeing on that, there might be opportunity
for factoring it out in the way you describe.

> 
> ...
> 
> > +       /* Ensure bus width will be set (again) upon card (re)insertion */
> > +       if (ret == 0)
> > +               host->is_bus_width_set = false;
> > +
> > +       return ret;
> 
> Please, switch to standard pattern, i.e.
> 
>   if (ret)
>     return ret;
>   ...
>   return 0;

OK, lined up for v10

> ...
> 
> > +       u32 div;
> > +
> > +       div = freq ? host->ref_clk / freq : 256U;
> 
> > +       div = roundup_pow_of_two(div);
> > +       div = clamp(div, 2U, 256U);
> 
> Not sure why it becomes two lines again.

Per my previous email, I have:

        div = clamp((u32)roundup_pow_of_two(div), 2U, 256U);

... lined up for v10 (pending also Geert's OK on the (u32) cast
to shut up compiler warnings) :)

> ...
> 
> > +       ret = devm_add_action_or_reset(dev,
> > +                                      (void(*)(void *))mmc_free_host, mmc);
> 
> One line?
> An actually preferable way is to define a separate wrapper function
> and use it here without any casting.

Done and lined up for v10:

    /* wrapper for use with devm_add_action_or_reset(), below */
    static void litex_mmc_free_host_wrapper(void *ptr)
    {
        mmc_free_host((struct mmc_host *)ptr);
    }

    static int litex_mmc_probe(struct platform_device *pdev)
    {
        ...
        ret = devm_add_action_or_reset(dev, litex_mmc_free_host_wrapper, mmc);
        ...
    }

> > +       if (ret) {
> 
> > +               dev_err(dev, "Failed to register mmc_free_host action\n");
> > +               return ret;
> 
> return dev_err_probe(...);

OK.
 
> > +       }
> 
> ...
> 
> > +       clk = devm_clk_get(dev, NULL);
> > +       if (IS_ERR(clk)) {
> 
> > +               ret = dev_err_probe(dev, PTR_ERR(clk), "can't get clock\n");
> > +               return ret;
> 
>     return dev_err_probe(...);

OK.

> > +       }
> 
> ...
> 
> > +       ret = mmc_add_host(mmc);
> > +
> > +       return ret;
> 
> It's now
> 
>     return mmc_add_host(...);

OK.

I'll wait till sometime tomorrow for additional feedback on clamp()
casting and voltage range hard-coding vs. regulators, before I send
out v10 so we can continue from there.

Thanks, as always,
--Gabriel

  reply	other threads:[~2022-01-09  0:26 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-08 16:11 [PATCH v9 0/3] mmc: Add LiteSDCard mmc driver Gabriel Somlo
2022-01-08 16:11 ` [PATCH v9 1/3] MAINTAINERS: co-maintain LiteX platform Gabriel Somlo
2022-01-08 16:11 ` [PATCH v9 2/3] dt-bindings: mmc: Add bindings for LiteSDCard Gabriel Somlo
2022-01-08 16:11 ` [PATCH v9 3/3] mmc: Add driver for LiteX's LiteSDCard interface Gabriel Somlo
2022-01-08 17:43   ` Andy Shevchenko
2022-01-09  0:26     ` Gabriel L. Somlo [this message]
2022-01-09 11:43       ` Andy Shevchenko
2022-01-10  8:25       ` Geert Uytterhoeven
     [not found] ` <20220109025042.1537-1-hdanton@sina.com>
2022-01-09  4:19   ` Gabriel L. Somlo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Ydorm5HirY2i/RCg@errol.ini.cmu.edu \
    --to=gsomlo@gmail.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=david.abdurachmanov@sifive.com \
    --cc=devicetree@vger.kernel.org \
    --cc=florent@enjoy-digital.fr \
    --cc=geert@linux-m68k.org \
    --cc=joel@jms.id.au \
    --cc=kgugala@antmicro.com \
    --cc=krakoczy@antmicro.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=mdudek@internships.antmicro.com \
    --cc=mholenko@antmicro.com \
    --cc=paulus@ozlabs.org \
    --cc=rdunlap@infradead.org \
    --cc=robh+dt@kernel.org \
    --cc=shorne@gmail.com \
    --cc=ulf.hansson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).