From: Stafford Horne <shorne@gmail.com>
To: Gabriel Somlo <gsomlo@gmail.com>
Cc: linux-kernel@vger.kernel.org, robh+dt@kernel.org,
devicetree@vger.kernel.org, ulf.hansson@linaro.org,
linux-mmc@vger.kernel.org, kgugala@antmicro.com,
mholenko@antmicro.com, krakoczy@antmicro.com,
mdudek@internships.antmicro.com, paulus@ozlabs.org,
joel@jms.id.au, geert@linux-m68k.org,
david.abdurachmanov@sifive.com, florent@enjoy-digital.fr,
rdunlap@infradead.org, andy.shevchenko@gmail.com,
hdanton@sina.com
Subject: Re: [PATCH v11 3/3] mmc: Add driver for LiteX's LiteSDCard interface
Date: Tue, 11 Jan 2022 07:07:47 +0900 [thread overview]
Message-ID: <YdyuMw8GHfXgKrvn@antec> (raw)
In-Reply-To: <20220109232003.2573924-4-gsomlo@gmail.com>
On Sun, Jan 09, 2022 at 06:20:03PM -0500, Gabriel Somlo 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!
>
> Co-developed-by: Kamil Rakoczy <krakoczy@antmicro.com>
> Signed-off-by: Kamil Rakoczy <krakoczy@antmicro.com>
> Co-developed-by: Maciej Dudek <mdudek@internships.antmicro.com>
> Signed-off-by: Maciej Dudek <mdudek@internships.antmicro.com>
> Co-developed-by: Paul Mackerras <paulus@ozlabs.org>
> Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
> Signed-off-by: Gabriel Somlo <gsomlo@gmail.com>
> Reviewed-by: Joel Stanley <joel@jms.id.au>
> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
> ---
>
> New in v11:
> - picked up r/b from Andy
> drivers/mmc/host/litex_mmc.c:
> - defensive coding of litex_mmc_interrupt() return logic
> - remove `dev` member of `struct litex_mmc_host`, only used during probe
>
> >New in v10:
> >drivers/mmc/host/litex_mmc.c:
> > - group `linux/mmc/*` includes by themselves
> > - clean-up of `return` style (multiple locations throughout source)
> > - create `mmc_free_host()` wrapper for use with
> > `devm_add_action_or_reset()`
> > - use GFP_KERNEL with `dmam_alloc_coherent()`
> >
> >>New in v9:
> >>drivers/mmc/host/Kconfig:
> >> - fix OF dependency
> >>drivers/mmc/host/litex_mmc.c:
> >> - remove `linux/of.h` include, no longer needed since dropping
> >> `of_match_ptr()`
> >> - add `linux/mod_devicetable.h` include
> >> - use devm_action_or_reset() to devm-ify mmc_alloc_host(), and obviate
> >> the need to call mmc_free_host() explicitly during either probe()
> >> error path or during remove()
> >>
> >>>New in v8:
> >>> - remove `Cc:` lines from commit blurb
> >>>drivers/mmc/host/litex_mmc.c:
> >>> - fix file header comment (for real, this time)
> >>> - add explicit `bits.h` include
> >>> - remove `of_match_ptr()` wrapper from around .of_match_table argument
> >>> - fix devm ordering issues: use `devm_request_irq()`, which precludes
> >>> the need to call `free_irq()` on `probe()` error path or from `remove()`
> >>>
> >>>>New in v7:
> >>>>drivers/mmc/host/Kconfig:
> >>>> - added module name in LiteSDCard Kconfig entry
> >>>>drivers/mmc/host/litex_mmc.c:
> >>>> - fixed comment formatting, ordering, and capitalization throughout
> >>>> the entire file
> >>>> - sorted header #include statements
> >>>> - removed redundant parantheses in readx_poll_timeout() condition
> >>>> - explicit handling of readx_poll_timeout() timeout scenarios
> >>>> - dev_err() used in litex_mmc_sdcard_wait_done()
> >>>> - use memcpy_fromio() to grab command response
> >>>> - no need to apply 0xffff mask to a 32-bit value right-shifted by 16
> >>>> (host->resp[3])
> >>>> - use clamp() instead of min(max(...)...)
> >>>> - reworked platform_get_irq_optional() error handling logic
> >>>> - no need to explicitly zero host->irq, kzalloc() does that already
> >>>> - added missing free_irq() in litex_mmc_probe() error path
> >>>> - reordered calls inside litex_mmc_remove() (calling mmc_free_host()
> >>>> before free_irq()
> >>>>
> >>>>>New in v6:
> >>>>> - fix handling of deferred probe vs. platform_get_irq_optional()
> >>>>> - don't #ifdef dma_set_mask_and_coherent(), since it automatically
> >>>>> does the right thing on both 32- and 64-bit DMA capable arches
> >>>>> - remove MMC_CAP2_FULL_PWR_CYCLE, add MMC_CAP2_NO_MMC to list of
> >>>>> hardcoded capabilities during litex_mmc_probe()
> >>>>> - hardcode mmc->ocr_avail to the full 2.7-3.6V range allowed by the
> >>>>> SDCard spec (the LiteSDCard device doesn't accept software
> >>>>> configuration)
> >>>>>
> >>>>>>New in v5:
> >>>>>> - shorter #define constant names (cosmetic, make them less unwieldy)
> >>>>>> - picked up reviewed-by Joel
> >>>>>>
> >>>>>>>New in v4:
> >>>>>>> - struct litex_mmc_host fields re-ordered so that `pahole` reports
> >>>>>>> no holes on either 32- or 64-bit builds
> >>>>>>> - litex_mmc_set_bus_width() now encapsulates check for
> >>>>>>> host->is_bus_width_set
> >>>>>>> - litex_mmc_request() - factor out dma data setup into separate
> >>>>>>> helper function: litex_mmc_do_dma()
> >>>>>>>
> >>>>>>>> New in v3:
> >>>>>>>> - fixed function signature (no line split), and naming (litex_mmc_*)
> >>>>>>>> - more informative MODULE_AUTHOR() entries
> >>>>>>>> - also added matching "Copyright" entries in file header
> >>>>>>>> - fixed description and dependencies in Kconfig
> >>>>>>>> - removed magic constants
> >>>>>>>> - removed litex_map_status(), have sdcard_wait_done() return *real*
> >>>>>>>> error codes directly instead.
> >>>>>>>> - streamlined litex_mmc_reponse_len()
> >>>>>>>> - call litex_mmc_set_bus_width() only once, and ensure it returns
> >>>>>>>> correct error code(s)
> >>>>>>>> - use readx_poll_timeout() -- more concise -- instead of
> >>>>>>>> read_poll_timeout()
> >>>>>>>> - use dev_err() in litex_mmc_send_cmd() (instead of pr_err())
> >>>>>>>> - litex_mmc_setclk() will update host->clock before returning
> >>>>>>>> - separate irq initialization into its own function,
> >>>>>>>> litex_mmc_irq_init()
> >>>>>>>> - document rationale for f_min, f_max
> >>>>>>>> - use dmam_alloc_coherent(), which simplifies cleanup significantly
> >>>>>>>> - bump dma_set_mask_and_coherent() to 64-bits on suitable
> >>>>>>>> architectures
> >>>>>>>> - clock source picked up from dedicated DT clock reference property
> >>>>>>>> - remove gpio card-detect logic (needs testing and a dt binding
> >>>>>>>> example before being eligible for upstream inclusion)
> >>>>>>>> - large `if (data) { ... }` block in litex_mmc_request() left as-is,
> >>>>>>>> there are too many variables shared with the rest of the parent
> >>>>>>>> function body to easily separate (e.g., `len`, `transfer`, `direct`).
> >>>>>>>> If this is indeed a blocker, I can take another shot at refactoring
> >>>>>>>> it in a future revision!
>
> drivers/mmc/host/Kconfig | 9 +
> drivers/mmc/host/Makefile | 1 +
> drivers/mmc/host/litex_mmc.c | 657 +++++++++++++++++++++++++++++++++++
> 3 files changed, 667 insertions(+)
> create mode 100644 drivers/mmc/host/litex_mmc.c
>
> diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig
> index 5af8494c31b5..8f661f52b502 100644
> --- a/drivers/mmc/host/Kconfig
> +++ b/drivers/mmc/host/Kconfig
> @@ -1093,3 +1093,12 @@ config MMC_OWL
>
> config MMC_SDHCI_EXTERNAL_DMA
> bool
> +
> +config MMC_LITEX
> + tristate "LiteX MMC Host Controller support"
> + depends on ((PPC_MICROWATT || LITEX) && OF) || COMPILE_TEST
> + help
> + This selects support for the MMC Host Controller found in LiteX SoCs.
See comment below.
> + To compile this driver as a module, choose M here: the
> + module will be called litex_mmc.
Can we add this here too?
If unsure, say N.
> diff --git a/drivers/mmc/host/Makefile b/drivers/mmc/host/Makefile
> index ea36d379bd3c..4e4ceb32c4b4 100644
> --- a/drivers/mmc/host/Makefile
> +++ b/drivers/mmc/host/Makefile
> @@ -101,6 +101,7 @@ obj-$(CONFIG_MMC_CQHCI) += cqhci.o
> cqhci-y += cqhci-core.o
> cqhci-$(CONFIG_MMC_CRYPTO) += cqhci-crypto.o
> obj-$(CONFIG_MMC_HSQ) += mmc_hsq.o
> +obj-$(CONFIG_MMC_LITEX) += litex_mmc.o
>
> ifeq ($(CONFIG_CB710_DEBUG),y)
> CFLAGS-cb710-mmc += -DDEBUG
> diff --git a/drivers/mmc/host/litex_mmc.c b/drivers/mmc/host/litex_mmc.c
> new file mode 100644
> index 000000000000..cc2848030e6b
> --- /dev/null
> +++ b/drivers/mmc/host/litex_mmc.c
> @@ -0,0 +1,657 @@
...
> +
> + /* Initialize clock source */
> + clk = devm_clk_get(dev, NULL);
> + if (IS_ERR(clk))
> + return dev_err_probe(dev, PTR_ERR(clk), "can't get clock\n");
> + host->ref_clk = clk_get_rate(clk);
Note, we used to have:
cpu = of_get_next_cpu_node(NULL);
ret = of_property_read_u32(cpu, "clock-frequency", &host->freq);
of_node_put(cpu);
if (ret) {
dev_err(&pdev->dev, "No \"clock-frequency\" property in DT\n");
goto err_free_host;
}
As we agree, this worked but was hacky. The new use of devm_clk_get above uses
the COMMON_CLK framework. Which is great but OpenRISC doesn't yet support
COMMON_CLK, so this driver no longer works on OpenRISC.
I think the ideal thing is to not change the driver code and I will just add
support for COMMON_CLK on openrisc (already done and tested). But as we
discussed off e-mail I think we should change the config constraints to.
depends on ((PPC_MICROWATT || LITEX) && OF && HAVE_CLK) || COMPILE_TEST
-Stafford
next prev parent reply other threads:[~2022-01-10 22:07 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-09 23:20 [PATCH v11 0/3] mmc: Add LiteSDCard mmc driver Gabriel Somlo
2022-01-09 23:20 ` [PATCH v11 1/3] MAINTAINERS: co-maintain LiteX platform Gabriel Somlo
2022-01-09 23:20 ` [PATCH v11 2/3] dt-bindings: mmc: Add bindings for LiteSDCard Gabriel Somlo
2022-01-09 23:20 ` [PATCH v11 3/3] mmc: Add driver for LiteX's LiteSDCard interface Gabriel Somlo
2022-01-10 22:07 ` Stafford Horne [this message]
2022-01-10 22:15 ` Gabriel L. Somlo
2022-01-10 22:15 ` Stafford Horne
2022-01-10 22:39 ` Gabriel L. Somlo
2022-01-10 23:41 ` Stafford Horne
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=YdyuMw8GHfXgKrvn@antec \
--to=shorne@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=gsomlo@gmail.com \
--cc=hdanton@sina.com \
--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=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