Skip to contentSkip to conversation

mmc: Add LiteSDCard mmc driver

PATCH Superseded Gabriel Somlo 2 participants 9 messages Jan 9, 2022 – Jan 10, 2022

Subsystems (3)

v11 of 14 Superseded Latest is v14 →

lore
Share & tools
lore
#0 lore raw

v11 cover mmc: Add LiteSDCard mmc driver

Add support for the LiteX SD-Card device, LiteSDCard.

LiteSDCard is a simple SD-Card interface available as part of the LiteX environment, used with various RISC-V and other FPGA based SoCs.

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

Quoted 150 lines

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()

Quoted 142 lines

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()

Quoted 131 lines

New in v8:
commit blurbs:
- cosmetic editing of descriptions
- removed Cc: lines
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()

Quoted 120 lines

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()

Quoted 98 lines

New in v6:

drivers/mmc/host/litex_mmc.c:
- 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)

Quoted 86 lines

New in v5:

MAINTAINERS:

- picked up a/b Mateusz

Doc/dt/bindings/mmc/litex,mmc.yaml:

- picked up r/b Rob, Joel

drivers/mmc/host/litex_mmc.c:

- shorten #define constant names (cosmetic, make them less unwieldy)
- picked up r/b Joel

Quoted 71 lines

New in v4:

Doc/dt/bindings/mmc/litex,mmc.yaml:

- fixed dt_binding_check errors uncovered by Rob's script

drivers/mmc/host/litex_mmc.c:

- struct litex_mmc_host fields re-ordered so that pahole reports no holes in 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()

Quoted 56 lines

New in v3:

MAINTAINERS:

- picked up acked-by Joel
- added listing for liteeth driver
- added Joel as additional co-maintainer (thanks!)

Doc/dt/bindings/mmc/litex,mmc.yaml:

- picked up r/b Geert Uytterhoeven <[email protected]> in DT bindings document (please let me know if that was premature, and happy to take further review if needed :)
- add dedicated DT property for source clock frequency

drivers/mmc/host/litex_mmc.c:

- 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 in Kconfig
- fixed DT documentation
- 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
- 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!
- 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)

Quoted 9 lines

New in v2:
- reword info message in litex_set_clk()
- streamline code in litex_map_status()
- fix typos in Kconfig (thanks Randy Dunlap <[email protected]>)
- improvements suggested by Stafford Horne <[email protected]>
- allow COMPILE_TEST in Kconfig
- use read_poll_timeout() when waiting for cmd/data/DMA xfer completion
- include interrupt.h (thanks kernel test robot <[email protected]>)

Gabriel Somlo (3):
MAINTAINERS: co-maintain LiteX platform
dt-bindings: mmc: Add bindings for LiteSDCard
mmc: Add driver for LiteX's LiteSDCard interface

 .../devicetree/bindings/mmc/litex,mmc.yaml    |  72 ++
 MAINTAINERS                                   |   9 +-
 drivers/mmc/host/Kconfig                      |   9 +
 drivers/mmc/host/Makefile                     |   1 +
 drivers/mmc/host/litex_mmc.c                  | 657 ++++++++++++++++++
 5 files changed, 746 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mmc/litex,mmc.yaml
 create mode 100644 drivers/mmc/host/litex_mmc.c
Signature · 1 line
2.31.1
#1 lore raw

PATCH v11 1/3 MAINTAINERS: co-maintain LiteX platform

Add the litex_mmc (LiteSDCard) and LiteETH drivers to the list of files maintained under LiteX.

Add Gabriel Somlo and Joel Stanley as maintainers; Joel authored the LiteETH driver, and Gabriel is currently curating the LiteX out-of-tree device drivers as they are tested and prepared for upstream submission, having also co-authored a number of them.

---
 MAINTAINERS | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
MAINTAINERS +7 -2
index dd36acc87ce6..88f105711b85 100644
@@ -11012,12 +11012,17 @@ F:	lib/list-test.c
 LITEX PLATFORM
 M:	Karol Gugala <[email protected]>
 M:	Mateusz Holenko <[email protected]>
+M:	Gabriel Somlo <[email protected]>
+M:	Joel Stanley <[email protected]>
 S:	Maintained
 F:	Documentation/devicetree/bindings/*/litex,*.yaml
 F:	arch/openrisc/boot/dts/or1klitex.dts
-F:	drivers/soc/litex/litex_soc_ctrl.c
-F:	drivers/tty/serial/liteuart.c
 F:	include/linux/litex.h
+F:	drivers/tty/serial/liteuart.c
+F:	drivers/soc/litex/*
+F:	drivers/net/ethernet/litex/*
+F:	drivers/mmc/host/litex_mmc.c
+N:	litex
 
 LIVE PATCHING
 M:	Josh Poimboeuf <[email protected]>
Signature · 1 line
2.31.1
#2 lore raw

PATCH v11 2/3 dt-bindings: mmc: Add bindings for LiteSDCard

In reply to Gabriel Somlo

LiteSDCard is a small footprint, configurable SDCard core for FPGA based SoCs.

---
 .../devicetree/bindings/mmc/litex,mmc.yaml    | 72 +++++++++++++++++++
 1 file changed, 72 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mmc/litex,mmc.yaml
Documentation/devicetree/bindings/mmc/litex,mmc.yaml new file +72 -0
new file mode 100644
index 000000000000..f57cf42b8db7
@@ -0,0 +1,72 @@
+# SPDX-License-Identifier: GPL-2.0-or-later OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mmc/litex,mmc.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: LiteX LiteSDCard device
+
+maintainers:
+  - Gabriel Somlo <[email protected]>
+
+description: |
+  LiteSDCard is a small footprint, configurable SDCard core for FPGA based
+  system on chips.
+
+  The hardware source is Open Source and can be found on at
+  https://github.com/enjoy-digital/litesdcard/.
+
+allOf:
+  - $ref: mmc-controller.yaml#
+
+properties:
+  compatible:
+    const: litex,mmc
+
+  reg:
+    items:
+      - description: PHY registers
+      - description: CORE registers
+      - description: DMA Reader buffer
+      - description: DMA Writer buffer
+      - description: IRQ registers
+    minItems: 4
+
+  reg-names:
+    items:
+      - const: phy
+      - const: core
+      - const: reader
+      - const: writer
+      - const: irq
+    minItems: 4
+
+  clocks:
+    maxItems: 1
+    description:
+      Handle to reference clock.
+
+  interrupts:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - reg-names
+  - clocks
+
+additionalProperties: false
+
+examples:
+  - |
+    mmc: mmc@12005000 {
+        compatible = "litex,mmc";
+        reg = <0x12005000 0x100>,
+              <0x12003800 0x100>,
+              <0x12003000 0x100>,
+              <0x12004800 0x100>,
+              <0x12004000 0x100>;
+        reg-names = "phy", "core", "reader", "writer", "irq";
+        clocks = <&reference_clk>;
+        interrupts = <4>;
+    };
Signature · 1 line
2.31.1
#3 lore raw

PATCH v11 3/3 mmc: Add driver for LiteX's LiteSDCard interface

In reply to Gabriel Somlo

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!

---

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

Quoted 99 lines

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()

Quoted 91 lines

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()

Quoted 80 lines

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()

Quoted 71 lines

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()

Quoted 51 lines

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)

Quoted 41 lines

New in v5:
- shorter #define constant names (cosmetic, make them less unwieldy)
- picked up reviewed-by Joel

Quoted 37 lines

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()

Quoted 29 lines

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
drivers/mmc/host/Kconfig +9 -0
index 5af8494c31b5..8f661f52b502 100644
@@ -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.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called litex_mmc.
drivers/mmc/host/Makefile +1 -0
index ea36d379bd3c..4e4ceb32c4b4 100644
@@ -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
drivers/mmc/host/litex_mmc.c new file +657 -0

657 lines not on this page · raw message

Signature · 1 line
2.31.1
#4 lore raw

Re: [PATCH v11 3/3] mmc: Add driver for LiteX's LiteSDCard interface

Quoted 135 lines · Gabriel Somlo

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!

---

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

Quoted 99 lines

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()

Quoted 91 lines

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()

Quoted 80 lines

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()

Quoted 71 lines

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()

Quoted 51 lines

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)

Quoted 41 lines

New in v5:
- shorter #define constant names (cosmetic, make them less unwieldy)
- picked up reviewed-by Joel

Quoted 37 lines

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()

Quoted 29 lines

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
drivers/mmc/host/Kconfig +0 -0
index 5af8494c31b5..8f661f52b502 100644

drivers/mmc/host/Kconfig config MMC_OWL · line 1101

Quoted 9 lines
drivers/mmc/host/Kconfig +6 -0
@@ -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.

drivers/mmc/host/Kconfig config MMC_OWL · line 1104

Quoted 2 lines
drivers/mmc/host/Kconfig +2 -0
+	  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.

Quoted 18 lines
drivers/mmc/host/Makefile +1 -0
index ea36d379bd3c..4e4ceb32c4b4 100644
@@ -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
drivers/mmc/host/litex_mmc.c new file +0 -0
new file mode 100644
index 000000000000..cc2848030e6b
@@ -0,0 +1,657 @@

...

drivers/mmc/host/litex_mmc.c line 547

Quoted 6 lines
drivers/mmc/host/litex_mmc.c new file +6 -0
+
+	/* 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

#5 lore raw

Re: [PATCH v11 3/3] mmc: Add driver for LiteX's LiteSDCard interface

Quoted 148 lines · Stafford Horne
Quoted 135 lines · Gabriel Somlo

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!

---

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

Quoted 99 lines

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()

Quoted 91 lines

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()

Quoted 80 lines

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()

Quoted 71 lines

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()

Quoted 51 lines

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)

Quoted 41 lines

New in v5:
- shorter #define constant names (cosmetic, make them less unwieldy)
- picked up reviewed-by Joel

Quoted 37 lines

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()

Quoted 29 lines

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
drivers/mmc/host/Kconfig +0 -0
index 5af8494c31b5..8f661f52b502 100644

drivers/mmc/host/Kconfig config MMC_OWL · line 1101

Quoted 9 lines
drivers/mmc/host/Kconfig +6 -0
@@ -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.

Quoted 6 lines

drivers/mmc/host/Kconfig config MMC_OWL · line 1104

Quoted 2 lines
drivers/mmc/host/Kconfig +2 -0
+	  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.

OK, lined up for v12.

Quoted 40 lines
Quoted 18 lines
drivers/mmc/host/Makefile +1 -0
index ea36d379bd3c..4e4ceb32c4b4 100644
@@ -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
drivers/mmc/host/litex_mmc.c new file +0 -0
new file mode 100644
index 000000000000..cc2848030e6b
@@ -0,0 +1,657 @@

...

drivers/mmc/host/litex_mmc.c line 547

Quoted 6 lines
drivers/mmc/host/litex_mmc.c new file +6 -0
+
+	/* 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.

Quoted 5 lines

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

OK, also lined up for v12.

I'll probably send out v12 in a few hours -- thanks for the suggestions and testing!

Best,
--Gabriel

#6 lore raw

Re: [PATCH v11 3/3] mmc: Add driver for LiteX's LiteSDCard interface

In reply to Gabriel Somlo
Quoted 18 lines · Gabriel Somlo

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!

---

...

Quoted 96 lines
drivers/mmc/host/litex_mmc.c new file +96 -0
+static int litex_mmc_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct litex_mmc_host *host;
+	struct mmc_host *mmc;
+	struct clk *clk;
+	int ret;
+
+	/*
+	 * NOTE: defaults to max_[req,seg]_size=PAGE_SIZE, max_blk_size=512,
+	 * and max_blk_count accordingly set to 8;
+	 * If for some reason we need to modify max_blk_count, we must also
+	 * re-calculate `max_[req,seg]_size = max_blk_size * max_blk_count;`
+	 */
+	mmc = mmc_alloc_host(sizeof(struct litex_mmc_host), dev);
+	if (!mmc)
+		return -ENOMEM;
+
+	ret = devm_add_action_or_reset(dev, litex_mmc_free_host_wrapper, mmc);
+	if (ret)
+		return dev_err_probe(dev, ret,
+				     "Can't register mmc_free_host action\n");
+
+	host = mmc_priv(mmc);
+	host->mmc = mmc;
+
+	/* 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);
+	host->sd_clk = 0;
+
+	/*
+	 * LiteSDCard only supports 4-bit bus width; therefore, we MUST inject
+	 * a SET_BUS_WIDTH (acmd6) before the very first data transfer, earlier
+	 * than when the mmc subsystem would normally get around to it!
+	 */
+	host->is_bus_width_set = false;
+	host->app_cmd = false;
+
+	/* LiteSDCard can support 64-bit DMA addressing */
+	ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64));
+	if (ret)
+		return ret;
+
+	host->buf_size = mmc->max_req_size * 2;
+	host->buffer = dmam_alloc_coherent(dev, host->buf_size,
+					   &host->dma, GFP_KERNEL);
+	if (host->buffer == NULL)
+		return -ENOMEM;
+
+	host->sdphy = devm_platform_ioremap_resource_byname(pdev, "phy");
+	if (IS_ERR(host->sdphy))
+		return PTR_ERR(host->sdphy);
+
+	host->sdcore = devm_platform_ioremap_resource_byname(pdev, "core");
+	if (IS_ERR(host->sdcore))
+		return PTR_ERR(host->sdcore);
+
+	host->sdreader = devm_platform_ioremap_resource_byname(pdev, "reader");
+	if (IS_ERR(host->sdreader))
+		return PTR_ERR(host->sdreader);
+
+	host->sdwriter = devm_platform_ioremap_resource_byname(pdev, "writer");
+	if (IS_ERR(host->sdwriter))
+		return PTR_ERR(host->sdwriter);
+
+	/* Ensure DMA bus masters are disabled */
+	litex_write8(host->sdreader + LITEX_BLK2MEM_ENA, 0);
+	litex_write8(host->sdwriter + LITEX_MEM2BLK_ENA, 0);
+
+	init_completion(&host->cmd_done);
+	ret = litex_mmc_irq_init(pdev, host);
+	if (ret)
+		return ret;
+
+	/* Allow full generic 2.7-3.6V range; no software tuning available */
+	mmc->ocr_avail = LITEX_MMC_OCR;
+
+	mmc->ops = &litex_mmc_ops;
+
+	/*
+	 * Set default sd_clk frequency range based on empirical observations
+	 * of LiteSDCard gateware behavior on typical SDCard media
+	 */
+	mmc->f_min = 12.5e6;
+	mmc->f_max = 50e6;
+
+	ret = mmc_of_parse(mmc);
+	if (ret)
+		return ret;
+
+	/* Force 4-bit bus_width (only width supported by hardware) */
+	mmc->caps &= ~MMC_CAP_8_BIT_DATA;
+	mmc->caps |= MMC_CAP_4_BIT_DATA;

drivers/mmc/host/litex_mmc.c line 622

Quoted 10 lines
drivers/mmc/host/litex_mmc.c new file +10 -0
+
+	/* Set default capabilities */
+	mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY |
+		     MMC_CAP_DRIVER_TYPE_D |
+		     MMC_CAP_CMD23;
+	mmc->caps2 |= MMC_CAP2_NO_WRITE_PROTECT |
+		      MMC_CAP2_NO_SDIO |
+		      MMC_CAP2_NO_MMC;
+
+	platform_set_drvdata(pdev, host);

One more thing here. Or somewhere, should we add:

	dev_info(dev, "Litex MMC controller initialized");

I was having a hard time debugging probing of this and having no printk's made it a bit difficult.

Though I was able to get most of the debug statements I needed using:

"debug initcall_debug dyndbg=\"file drivers/* +p\" loglevel=8"

-Stafford

Quoted 3 lines
drivers/mmc/host/litex_mmc.c new file +3 -0
+	return mmc_add_host(mmc);
+}
+
#7 lore raw

Re: [PATCH v11 3/3] mmc: Add driver for LiteX's LiteSDCard interface

Quoted 134 lines · Stafford Horne
Quoted 18 lines · Gabriel Somlo

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!

---

...

Quoted 96 lines
drivers/mmc/host/litex_mmc.c new file +96 -0
+static int litex_mmc_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct litex_mmc_host *host;
+	struct mmc_host *mmc;
+	struct clk *clk;
+	int ret;
+
+	/*
+	 * NOTE: defaults to max_[req,seg]_size=PAGE_SIZE, max_blk_size=512,
+	 * and max_blk_count accordingly set to 8;
+	 * If for some reason we need to modify max_blk_count, we must also
+	 * re-calculate `max_[req,seg]_size = max_blk_size * max_blk_count;`
+	 */
+	mmc = mmc_alloc_host(sizeof(struct litex_mmc_host), dev);
+	if (!mmc)
+		return -ENOMEM;
+
+	ret = devm_add_action_or_reset(dev, litex_mmc_free_host_wrapper, mmc);
+	if (ret)
+		return dev_err_probe(dev, ret,
+				     "Can't register mmc_free_host action\n");
+
+	host = mmc_priv(mmc);
+	host->mmc = mmc;
+
+	/* 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);
+	host->sd_clk = 0;
+
+	/*
+	 * LiteSDCard only supports 4-bit bus width; therefore, we MUST inject
+	 * a SET_BUS_WIDTH (acmd6) before the very first data transfer, earlier
+	 * than when the mmc subsystem would normally get around to it!
+	 */
+	host->is_bus_width_set = false;
+	host->app_cmd = false;
+
+	/* LiteSDCard can support 64-bit DMA addressing */
+	ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64));
+	if (ret)
+		return ret;
+
+	host->buf_size = mmc->max_req_size * 2;
+	host->buffer = dmam_alloc_coherent(dev, host->buf_size,
+					   &host->dma, GFP_KERNEL);
+	if (host->buffer == NULL)
+		return -ENOMEM;
+
+	host->sdphy = devm_platform_ioremap_resource_byname(pdev, "phy");
+	if (IS_ERR(host->sdphy))
+		return PTR_ERR(host->sdphy);
+
+	host->sdcore = devm_platform_ioremap_resource_byname(pdev, "core");
+	if (IS_ERR(host->sdcore))
+		return PTR_ERR(host->sdcore);
+
+	host->sdreader = devm_platform_ioremap_resource_byname(pdev, "reader");
+	if (IS_ERR(host->sdreader))
+		return PTR_ERR(host->sdreader);
+
+	host->sdwriter = devm_platform_ioremap_resource_byname(pdev, "writer");
+	if (IS_ERR(host->sdwriter))
+		return PTR_ERR(host->sdwriter);
+
+	/* Ensure DMA bus masters are disabled */
+	litex_write8(host->sdreader + LITEX_BLK2MEM_ENA, 0);
+	litex_write8(host->sdwriter + LITEX_MEM2BLK_ENA, 0);
+
+	init_completion(&host->cmd_done);
+	ret = litex_mmc_irq_init(pdev, host);
+	if (ret)
+		return ret;
+
+	/* Allow full generic 2.7-3.6V range; no software tuning available */
+	mmc->ocr_avail = LITEX_MMC_OCR;
+
+	mmc->ops = &litex_mmc_ops;
+
+	/*
+	 * Set default sd_clk frequency range based on empirical observations
+	 * of LiteSDCard gateware behavior on typical SDCard media
+	 */
+	mmc->f_min = 12.5e6;
+	mmc->f_max = 50e6;
+
+	ret = mmc_of_parse(mmc);
+	if (ret)
+		return ret;
+
+	/* Force 4-bit bus_width (only width supported by hardware) */
+	mmc->caps &= ~MMC_CAP_8_BIT_DATA;
+	mmc->caps |= MMC_CAP_4_BIT_DATA;

drivers/mmc/host/litex_mmc.c line 622

Quoted 10 lines
drivers/mmc/host/litex_mmc.c new file +10 -0
+
+	/* Set default capabilities */
+	mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY |
+		     MMC_CAP_DRIVER_TYPE_D |
+		     MMC_CAP_CMD23;
+	mmc->caps2 |= MMC_CAP2_NO_WRITE_PROTECT |
+		      MMC_CAP2_NO_SDIO |
+		      MMC_CAP2_NO_MMC;
+
+	platform_set_drvdata(pdev, host);

One more thing here. Or somewhere, should we add:

	dev_info(dev, "Litex MMC controller initialized");

I was having a hard time debugging probing of this and having no printk's made it a bit difficult.

Quoted 7 lines

Though I was able to get most of the debug statements I needed using:

"debug initcall_debug dyndbg=\"file drivers/* +p\" loglevel=8"

-Stafford

drivers/mmc/host/litex_mmc.c line 624

Quoted 1 line
drivers/mmc/host/litex_mmc.c new file +1 -0
+	return mmc_add_host(mmc);

I'd prefer to declare victory *after* calling mmc_add_host(), so if there are no objections I'd prefer to do the following in v12:

        ... 
        platform_set_drvdata(pdev, host);
-       return mmc_add_host(mmc);
+       ret = mmc_add_host(mmc);
+       if (ret)

+ return dev_err_probe(dev, ret, "LiteX MMC probe failed!\n");
+
+ dev_info(dev, "LiteX MMC controller initialized.\n");
+
+ return 0;
}

Thanks,
--Gabriel

#8 lore raw

Re: [PATCH v11 3/3] mmc: Add driver for LiteX's LiteSDCard interface

Quoted 149 lines · Gabriel L. Somlo
Quoted 134 lines · Stafford Horne
Quoted 18 lines · Gabriel Somlo

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!

---

...

Quoted 96 lines
drivers/mmc/host/litex_mmc.c new file +96 -0
+static int litex_mmc_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct litex_mmc_host *host;
+	struct mmc_host *mmc;
+	struct clk *clk;
+	int ret;
+
+	/*
+	 * NOTE: defaults to max_[req,seg]_size=PAGE_SIZE, max_blk_size=512,
+	 * and max_blk_count accordingly set to 8;
+	 * If for some reason we need to modify max_blk_count, we must also
+	 * re-calculate `max_[req,seg]_size = max_blk_size * max_blk_count;`
+	 */
+	mmc = mmc_alloc_host(sizeof(struct litex_mmc_host), dev);
+	if (!mmc)
+		return -ENOMEM;
+
+	ret = devm_add_action_or_reset(dev, litex_mmc_free_host_wrapper, mmc);
+	if (ret)
+		return dev_err_probe(dev, ret,
+				     "Can't register mmc_free_host action\n");
+
+	host = mmc_priv(mmc);
+	host->mmc = mmc;
+
+	/* 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);
+	host->sd_clk = 0;
+
+	/*
+	 * LiteSDCard only supports 4-bit bus width; therefore, we MUST inject
+	 * a SET_BUS_WIDTH (acmd6) before the very first data transfer, earlier
+	 * than when the mmc subsystem would normally get around to it!
+	 */
+	host->is_bus_width_set = false;
+	host->app_cmd = false;
+
+	/* LiteSDCard can support 64-bit DMA addressing */
+	ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64));
+	if (ret)
+		return ret;
+
+	host->buf_size = mmc->max_req_size * 2;
+	host->buffer = dmam_alloc_coherent(dev, host->buf_size,
+					   &host->dma, GFP_KERNEL);
+	if (host->buffer == NULL)
+		return -ENOMEM;
+
+	host->sdphy = devm_platform_ioremap_resource_byname(pdev, "phy");
+	if (IS_ERR(host->sdphy))
+		return PTR_ERR(host->sdphy);
+
+	host->sdcore = devm_platform_ioremap_resource_byname(pdev, "core");
+	if (IS_ERR(host->sdcore))
+		return PTR_ERR(host->sdcore);
+
+	host->sdreader = devm_platform_ioremap_resource_byname(pdev, "reader");
+	if (IS_ERR(host->sdreader))
+		return PTR_ERR(host->sdreader);
+
+	host->sdwriter = devm_platform_ioremap_resource_byname(pdev, "writer");
+	if (IS_ERR(host->sdwriter))
+		return PTR_ERR(host->sdwriter);
+
+	/* Ensure DMA bus masters are disabled */
+	litex_write8(host->sdreader + LITEX_BLK2MEM_ENA, 0);
+	litex_write8(host->sdwriter + LITEX_MEM2BLK_ENA, 0);
+
+	init_completion(&host->cmd_done);
+	ret = litex_mmc_irq_init(pdev, host);
+	if (ret)
+		return ret;
+
+	/* Allow full generic 2.7-3.6V range; no software tuning available */
+	mmc->ocr_avail = LITEX_MMC_OCR;
+
+	mmc->ops = &litex_mmc_ops;
+
+	/*
+	 * Set default sd_clk frequency range based on empirical observations
+	 * of LiteSDCard gateware behavior on typical SDCard media
+	 */
+	mmc->f_min = 12.5e6;
+	mmc->f_max = 50e6;
+
+	ret = mmc_of_parse(mmc);
+	if (ret)
+		return ret;
+
+	/* Force 4-bit bus_width (only width supported by hardware) */
+	mmc->caps &= ~MMC_CAP_8_BIT_DATA;
+	mmc->caps |= MMC_CAP_4_BIT_DATA;

drivers/mmc/host/litex_mmc.c line 622

Quoted 10 lines
drivers/mmc/host/litex_mmc.c new file +10 -0
+
+	/* Set default capabilities */
+	mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY |
+		     MMC_CAP_DRIVER_TYPE_D |
+		     MMC_CAP_CMD23;
+	mmc->caps2 |= MMC_CAP2_NO_WRITE_PROTECT |
+		      MMC_CAP2_NO_SDIO |
+		      MMC_CAP2_NO_MMC;
+
+	platform_set_drvdata(pdev, host);

One more thing here. Or somewhere, should we add:

	dev_info(dev, "Litex MMC controller initialized");

I was having a hard time debugging probing of this and having no printk's made it a bit difficult.

Quoted 7 lines

Though I was able to get most of the debug statements I needed using:

"debug initcall_debug dyndbg=\"file drivers/* +p\" loglevel=8"

-Stafford

drivers/mmc/host/litex_mmc.c line 624

Quoted 1 line
drivers/mmc/host/litex_mmc.c new file +1 -0
+	return mmc_add_host(mmc);

I'd prefer to declare victory *after* calling mmc_add_host(), so if there are no objections I'd prefer to do the following in v12:

        ... 
        platform_set_drvdata(pdev, host);

Review

Quoted 9 lines
(quoted diff) +7 -1
-       return mmc_add_host(mmc);
+       ret = mmc_add_host(mmc);
+       if (ret)
+               return dev_err_probe(dev, ret, "LiteX MMC probe failed!\n");
+
+       dev_info(dev, "LiteX MMC controller initialized.\n");
+
+       return 0;
 }

Yes, that is what I was thinking too.

-Stafford