Add mmc driver for Sunplus SP7021 SOC
Subsystems (3)
Tony Huang
maintainerv4 cover Add mmc driver for Sunplus SP7021 SOC
This is a patch series for mmc driver for Sunplus SP7021 SOC.
Sunplus SP7021 is an ARM Cortex A7 (4 cores) based SoC. It integrates many peripherals (ex: UART, I2C, SPI, SDIO, eMMC, USB, SD card and etc.) into a single chip. It is designed for industrial control.
Refer to:
https://sunplus-tibbo.atlassian.net/wiki/spaces/doc/overview
https://tibbo.com/store/plus1.html
Tony Huang (2):
dt-binding: mmc: Add mmc yaml file for Sunplus SP7021
mmc: Add mmc driver for Sunplus SP7021
.../devicetree/bindings/mmc/sunplus,mmc.yaml | 79 + MAINTAINERS | 7 + drivers/mmc/host/Kconfig | 9 + drivers/mmc/host/Makefile | 1 + drivers/mmc/host/sunplus_mmc.c | 2195 ++++++++++++++++++++ 5 files changed, 2291 insertions(+) create mode 100644 Documentation/devicetree/bindings/mmc/sunplus,mmc.yaml create mode 100644 drivers/mmc/host/sunplus_mmc.c
Signature · 1 line
2.7.4
Tony Huang
maintainerPATCH v4 1/2 dt-binding: mmc: Add mmc yaml file for Sunplus SP7021
Add mmc yaml file for Sunplus SP7021
---
Changes in v4:
- Addressed comments from Ulf Hansson.
.../devicetree/bindings/mmc/sunplus,mmc.yaml | 79 ++++++++++++++++++++++ MAINTAINERS | 6 ++ 2 files changed, 85 insertions(+) create mode 100644 Documentation/devicetree/bindings/mmc/sunplus,mmc.yaml
Documentation/devicetree/bindings/mmc/sunplus,mmc.yaml new file +79 -0
@@ -0,0 +1,79 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +# Copyright (C) Sunplus Ltd. Co. 2021 +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/mmc/sunplus,mmc.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: sunplus MMC controller + +allOf: + - $ref: "mmc-controller.yaml" + +maintainers: + - Tony Huang <[email protected]> + - Li-hao Kuo <[email protected]> + +properties: + compatible: + enum: + - sunplus,mmc-v1 + - sunplus,mmc-v2 + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + clocks: + minItems: 1 + + resets: + maxItems: 1 + + max-frequency: true + +required: + - compatible + - reg + - interrupts + - clocks + - resets + +unevaluatedProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + #include <dt-bindings/interrupt-controller/arm-gic.h> + mmc0: mmc@9c003b00 { + compatible = "sunplus,mmc-v2"; + reg = <0x9c003b00 0x180>; + interrupts = <20 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&clkc 0x4e>; + resets = <&rstc 0x3e>; + bus-width = <8>; + max-frequency = <52000000>; + non-removable; + disable-wp; + cap-mmc-highspeed; + mmc-ddr-3_3v; + no-sdio; + no-sd; + }; + + mmc1: mmc@9c003e80 { + compatible = "sunplus,mmc-v1"; + reg = <0x9c003e80 0x280>; + interrupts = <21 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&clkc 0x4f>; + resets = <&rstc 0x3f>; + pinctrl-names = "default"; + pinctrl-0 = <&mmc1_mux &mmc1_mux_cd>; + max-frequency = <52000000>; + disable-wp; + cap-sd-highspeed; + no-sdio; + no-mmc; + };
MAINTAINERS +6 -0
@@ -18242,6 +18242,12 @@ L: [email protected] S: Maintained F: drivers/net/ethernet/dlink/sundance.c +SUNPLUS MMC DRIVER +M: Tony Huang <[email protected]> +M: Li-hao Kuo <[email protected]> +S: Maintained +F: Documentation/devicetree/bindings/mmc/sunplu,mmc.yaml + SUPERH M: Yoshinori Sato <[email protected]> M: Rich Felker <[email protected]>
Signature · 1 line
2.7.4
Tony Huang
maintainerPATCH v4 2/2 mmc: Add mmc driver for Sunplus SP7021
In reply to Tony HuangAdd mmc driver for Sunplus SP7021
---
Changes in v4:
- combine sdcard and eMMC into one driver.
MAINTAINERS | 1 + drivers/mmc/host/Kconfig | 9 + drivers/mmc/host/Makefile | 1 + drivers/mmc/host/sunplus_mmc.c | 2195 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 2206 insertions(+) create mode 100644 drivers/mmc/host/sunplus_mmc.c
MAINTAINERS +1 -0
@@ -18247,6 +18247,7 @@ M: Tony Huang <[email protected]> M: Li-hao Kuo <[email protected]> S: Maintained F: Documentation/devicetree/bindings/mmc/sunplu,mmc.yaml +F: drivers/mmc/host/sunplus_mmc.c SUPERH M: Yoshinori Sato <[email protected]>
drivers/mmc/host/Kconfig +9 -0
@@ -14,6 +14,15 @@ config MMC_DEBUG added host drivers please don't invent their private macro for debugging. +config MMC_SUNPLUS + tristate "Sunplus SP7021 MMC Controller" + depends on ARCH_SUNPLUS + help + If you say yes here, you will get support for eMMC host interface + on Sunplus SoCs. + + If unsure, say N + config MMC_ARMMMCI tristate "ARM AMBA Multimedia Card Interface support" depends on ARM_AMBA
drivers/mmc/host/Makefile +1 -0
@@ -97,6 +97,7 @@ obj-$(CONFIG_MMC_SDHCI_MICROCHIP_PIC32) += sdhci-pic32.o obj-$(CONFIG_MMC_SDHCI_BRCMSTB) += sdhci-brcmstb.o obj-$(CONFIG_MMC_SDHCI_OMAP) += sdhci-omap.o obj-$(CONFIG_MMC_SDHCI_SPRD) += sdhci-sprd.o +obj-$(CONFIG_MMC_SUNPLUS) += sunplus_mmc.o obj-$(CONFIG_MMC_CQHCI) += cqhci.o cqhci-y += cqhci-core.o cqhci-$(CONFIG_MMC_CRYPTO) += cqhci-crypto.o
drivers/mmc/host/sunplus_mmc.c new file +2195 -0
2,195 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [PATCH v4 1/2] dt-binding: mmc: Add mmc yaml file for Sunplus SP7021
In reply to Tony HuangQuoted 18 lines · Tony Huang
Add mmc yaml file for Sunplus SP7021
Signed-off-by Tony Huang <[email protected]>---
Changes in v4:
- Addressed comments from Ulf Hansson..../devicetree/bindings/mmc/sunplus,mmc.yaml | 79 ++++++++++++++++++++++ MAINTAINERS | 6 ++ 2 files changed, 85 insertions(+) create mode 100644 Documentation/devicetree/bindings/mmc/sunplus,mmc.yamlDocumentation/devicetree/bindings/mmc/sunplus,mmc.yaml new file +0
-0
Documentation/devicetree/bindings/mmc/sunplus,mmc.yaml line 8
Quoted 8 lines
Documentation/devicetree/bindings/mmc/sunplus,mmc.yaml new file +8
-0@@ -0,0 +1,79 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +# Copyright (C) Sunplus Ltd. Co. 2021 +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/mmc/sunplus,mmc.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: sunplus MMC controller
s/sunplus/Sunplus/
Documentation/devicetree/bindings/mmc/sunplus,mmc.yaml line 11
Quoted 3 lines
Documentation/devicetree/bindings/mmc/sunplus,mmc.yaml new file +3
-0+ +allOf: + - $ref: "mmc-controller.yaml"
allOf below maintainers,
Documentation/devicetree/bindings/mmc/sunplus,mmc.yaml line 21
Quoted 10 lines
Documentation/devicetree/bindings/mmc/sunplus,mmc.yaml new file +10
-0+ +maintainers: + - Tony Huang <[email protected]> + - Li-hao Kuo <[email protected]> + +properties: + compatible: + enum: + - sunplus,mmc-v1 + - sunplus,mmc-v2
How did this happen? Versions of blocks are usually discouraged, unless you have clear specification,. The previous discussion did not end with "add v1 and v2".
Do you have clear documentation/specification of these blocks? If no, please use SoC compatibles.
Documentation/devicetree/bindings/mmc/sunplus,mmc.yaml line 30
Quoted 9 lines
Documentation/devicetree/bindings/mmc/sunplus,mmc.yaml new file +9
-0+ + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + clocks: + minItems: 1
maxItems
Quoted 54 lines
Documentation/devicetree/bindings/mmc/sunplus,mmc.yaml new file +49
-0+ + resets: + maxItems: 1 + + max-frequency: true + +required: + - compatible + - reg + - interrupts + - clocks + - resets + +unevaluatedProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + #include <dt-bindings/interrupt-controller/arm-gic.h> + mmc0: mmc@9c003b00 { + compatible = "sunplus,mmc-v2"; + reg = <0x9c003b00 0x180>; + interrupts = <20 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&clkc 0x4e>; + resets = <&rstc 0x3e>; + bus-width = <8>; + max-frequency = <52000000>; + non-removable; + disable-wp; + cap-mmc-highspeed; + mmc-ddr-3_3v; + no-sdio; + no-sd; + }; + + mmc1: mmc@9c003e80 { + compatible = "sunplus,mmc-v1"; + reg = <0x9c003e80 0x280>; + interrupts = <21 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&clkc 0x4f>; + resets = <&rstc 0x3f>; + pinctrl-names = "default"; + pinctrl-0 = <&mmc1_mux &mmc1_mux_cd>; + max-frequency = <52000000>; + disable-wp; + cap-sd-highspeed; + no-sdio; + no-mmc; + };MAINTAINERS +0
-0
MAINTAINERS L: [email protected] · line 18247
Quoted 6 lines
MAINTAINERS +3
-0@@ -18242,6 +18242,12 @@ L: [email protected] S: Maintained F: drivers/net/ethernet/dlink/sundance.c +SUNPLUS MMC DRIVER +M: Tony Huang <[email protected]> +M: Li-hao Kuo <[email protected]>
Wrong indentation.
MAINTAINERS L: [email protected] · line 18249
Quoted 2 lines
MAINTAINERS +2
-0+S: Maintained +F: Documentation/devicetree/bindings/mmc/sunplu,mmc.yaml
Wrong file name.
MAINTAINERS L: [email protected] · line 18253
Quoted 4 lines
MAINTAINERS +1
-0+ SUPERH M: Yoshinori Sato <[email protected]> M: Rich Felker <[email protected]>
Best regards,
Krzysztof
Re: [PATCH v4 2/2] mmc: Add mmc driver for Sunplus SP7021
In reply to Tony HuangQuoted 31 lines · Tony Huang
Add mmc driver for Sunplus SP7021
Signed-off-by Tony Huang <[email protected]>---
Changes in v4:
- combine sdcard and eMMC into one driver.MAINTAINERS | 1 + drivers/mmc/host/Kconfig | 9 + drivers/mmc/host/Makefile | 1 + drivers/mmc/host/sunplus_mmc.c | 2195 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 2206 insertions(+) create mode 100644 drivers/mmc/host/sunplus_mmc.cMAINTAINERS +1
-0@@ -18247,6 +18247,7 @@ M: Tony Huang <[email protected]> M: Li-hao Kuo <[email protected]> S: Maintained F: Documentation/devicetree/bindings/mmc/sunplu,mmc.yaml +F: drivers/mmc/host/sunplus_mmc.c SUPERH M: Yoshinori Sato <[email protected]>drivers/mmc/host/Kconfig +0
-0
drivers/mmc/host/Kconfig config MMC_DEBUG · line 19
Quoted 6 lines
drivers/mmc/host/Kconfig +3
-0@@ -14,6 +14,15 @@ config MMC_DEBUG added host drivers please don't invent their private macro for debugging. +config MMC_SUNPLUS + tristate "Sunplus SP7021 MMC Controller" + depends on ARCH_SUNPLUS
|| COMPILE_TEST
and please test it
Quoted 14 lines
drivers/mmc/host/Kconfig +6
-0+ help + If you say yes here, you will get support for eMMC host interface + on Sunplus SoCs. + + If unsure, say N + config MMC_ARMMMCI tristate "ARM AMBA Multimedia Card Interface support" depends on ARM_AMBAdrivers/mmc/host/Makefile +0
-0
drivers/mmc/host/Makefile obj-$(CONFIG_MMC_SDHCI_MICROCHIP_PIC32) += sdhci-pic32.o · line 100
Quoted 4 lines
drivers/mmc/host/Makefile +1
-0@@ -97,6 +97,7 @@ obj-$(CONFIG_MMC_SDHCI_MICROCHIP_PIC32) += sdhci-pic32.o obj-$(CONFIG_MMC_SDHCI_BRCMSTB) += sdhci-brcmstb.o obj-$(CONFIG_MMC_SDHCI_OMAP) += sdhci-omap.o obj-$(CONFIG_MMC_SDHCI_SPRD) += sdhci-sprd.o +obj-$(CONFIG_MMC_SUNPLUS) += sunplus_mmc.o
Almost all files use '-', not underscore. Do not bring inconsistencies.
Quoted 188 lines
drivers/mmc/host/Makefile +0
-0obj-$(CONFIG_MMC_CQHCI) += cqhci.o cqhci-y += cqhci-core.o cqhci-$(CONFIG_MMC_CRYPTO) += cqhci-crypto.odrivers/mmc/host/sunplus_mmc.c new file +179
-0@@ -0,0 +1,2195 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (c) Sunplus Inc. +* Author: Tony Huang <[email protected]> +* Author: Li-hao Kuo <[email protected]> +*/ + +#include <linux/bitfield.h> +#include <linux/clk.h> +#include <linux/delay.h> +#include <linux/dma-mapping.h> +#include <linux/interrupt.h> +#include <linux/mmc/core.h> +#include <linux/mmc/host.h> +#include <linux/mmc/mmc.h> +#include <linux/mmc/sdio.h> +#include <linux/mmc/slot-gpio.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/of_device.h> +#include <linux/platform_device.h> +#include <linux/pm_runtime.h> +#include <linux/reset.h> + +#define SPMMC_MIN_CLK 400000 +#define SPMMC_MAX_CLK 52000000 +#define SPMMC_MAX_BLK_COUNT 65536 +#define SPMMC_MAX_TUNABLE_DLY 7 + +#define SPMMC_CARD_MEDIATYPE_SRCDST_REG 0x0000 +#define SPMMC_MEDIA_TYPE GENMASK(2, 0) +#define SPMMC_DMA_SOURCE GENMASK(6, 4) +#define SPMMC_DMA_DESTINATION GENMASK(10, 8) +#define SPMMC_MEDIA_NONE 0 +#define SPMMC_MEDIA_SD 6 +#define SPMMC_MEDIA_MS 7 + +#define SPMMC_SDRAM_SECTOR_0_SIZE_REG 0x0008 +#define SPMMC_DMA_BASE_ADDR_REG 0x000C +#define SPMMC_HW_DMA_CTRL_REG 0x0010 +#define SPMMC_HW_DMA_RST BIT(9) +#define SPMMC_DMAIDLE BIT(10) + +#define SPMMC_MAX_DMA_MEMORY_SECTORS 8 + +#define SPMMC_SDRAM_SECTOR_1_ADDR_REG 0x0018 + +#define SPMMC_SD_INT_REG 0x0088 +#define SPMMC_SDINT_SDCMPEN BIT(0) +#define SPMMC_SDINT_SDCMP BIT(1) +#define SPMMC_SDINT_SDCMPCLR BIT(2) +#define SPMMC_SDINT_SDIOEN BIT(3) +#define SPMMC_SDINT_SDIO BIT(4) +#define SPMMC_SDINT_SDIOCLR BIT(5) + +#define SPMMC_SD_PAGE_NUM_REG 0x008C + +#define SPMMC_SD_CONFIG0_REG 0x0090 +#define SPMMC_SD_PIO_MODE BIT(0) +#define SPMMC_SD_DDR_MODE BIT(1) +#define SPMMC_SD_LEN_MODE BIT(2) +#define SPMMC_SD_TRANS_MODE GENMASK(5, 4) +#define SPMMC_SD_AUTO_RESPONSE BIT(6) +#define SPMMC_SD_CMD_DUMMY BIT(7) +#define SPMMC_SD_RSP_CHK_EN BIT(8) +#define SPMMC_SDIO_MODE BIT(9) +#define SPMMC_SD_MMC_MODE BIT(10) +#define SPMMC_SD_DATA_WD BIT(11) +#define SPMMC_RX4_EN BIT(14) +#define SPMMC_SD_RSP_TYPE BIT(15) +#define SPMMC_MMC8_EN BIT(18) +#define SPMMC_CLOCK_DIVISION GENMASK(31, 20) + +#define SPMMC_MODE_SD 0 +#define SPMMC_MODE_EMMC 1 +#define SPMMC_MODE_SDIO 2 + +#define SPMMC_SDIO_CTRL_REG 0x0094 +#define SPMMC_INT_MULTI_TRIG BIT(6) + +#define SPMMC_SD_RST_REG 0x0098 +#define SPMMC_SD_CTRL_REG 0x009C +#define SPMMC_NEW_COMMAND_TRIGGER BIT(0) +#define SPMMC_DUMMY_CLOCK_TRIGGER BIT(1) + +#define SPMMC_SD_STATUS_REG 0x00A0 +#define SPMMC_SDSTATUS_DUMMY_READY BIT(0) +#define SPMMC_SDSTATUS_RSP_BUF_FULL BIT(1) +#define SPMMC_SDSTATUS_TX_DATA_BUF_EMPTY BIT(2) +#define SPMMC_SDSTATUS_RX_DATA_BUF_FULL BIT(3) +#define SPMMC_SDSTATUS_CMD_PIN_STATUS BIT(4) +#define SPMMC_SDSTATUS_DAT0_PIN_STATUS BIT(5) +#define SPMMC_SDSTATUS_RSP_TIMEOUT BIT(6) +#define SPMMC_SDSTATUS_CARD_CRC_CHECK_TIMEOUT BIT(7) +#define SPMMC_SDSTATUS_STB_TIMEOUT BIT(8) +#define SPMMC_SDSTATUS_RSP_CRC7_ERROR BIT(9) +#define SPMMC_SDSTATUS_CRC_TOKEN_CHECK_ERROR BIT(10) +#define SPMMC_SDSTATUS_RDATA_CRC16_ERROR BIT(11) +#define SPMMC_SDSTATUS_SUSPEND_STATE_READY BIT(12) +#define SPMMC_SDSTATUS_BUSY_CYCLE BIT(13) +#define SPMMC_SDSTATUS_DAT1_PIN_STATUS BIT(14) +#define SPMMC_SDSTATUS_SD_SENSE_STATUS BIT(15) +#define SPMMC_SDSTATUS_BOOT_ACK_TIMEOUT BIT(16) +#define SPMMC_SDSTATUS_BOOT_DATA_TIMEOUT BIT(17) +#define SPMMC_SDSTATUS_BOOT_ACK_ERROR BIT(18) + +#define SPMMC_SD_STATE_REG 0x00A4 +#define SPMMC_CRCTOKEN_CHECK_RESULT GENMASK(6, 4) +#define SPMMC_SDSTATE_ERROR BIT(13) +#define SPMMC_SDSTATE_FINISH BIT(14) + +#define SPMMC_SD_HW_STATE_REG 0x00A8 +#define SPMMC_SD_BLOCKSIZE_REG 0x00AC + +#define SPMMC_SD_CONFIG1_REG 0x00B0 +#define SPMMC_TX_DUMMY_NUM GENMASK(8, 0) +#define SPMMC_SD_HIGH_SPEED_EN BIT(31) + +#define SPMMC_SD_TIMING_CONFIG0_REG 0x00B4 +#define SPMMC_SD_CLOCK_DELAY GENMASK(2, 0) +#define SPMMC_SD_WRITE_DATA_DELAY GENMASK(6, 4) +#define SPMMC_SD_WRITE_COMMAND_DELAY GENMASK(10, 8) +#define SPMMC_SD_READ_RESPONSE_DELAY GENMASK(14, 12) +#define SPMMC_SD_READ_DATA_DELAY GENMASK(18, 16) +#define SPMMC_SD_READ_CRC_DELAY GENMASK(22, 20) + +#define SPMMC_SD_PIODATATX_REG 0x00BC +#define SPMMC_SD_PIODATARX_REG 0x00C0 +#define SPMMC_SD_CMDBUF0_3_REG 0x00C4 +#define SPMMC_SD_CMDBUF4_REG 0x00C8 +#define SPMMC_SD_RSPBUF0_3_REG 0x00CC +#define SPMMC_SD_RSPBUF4_5_REG 0x00D0 + +struct spmmc_tuning_info { +int enable_tuning; +int need_tuning; +#define SPMMC_MAX_RETRIES (8 * 8) +int retried;/* how many times has been retried */ +u32 rd_crc_dly:3 ; +u32 rd_dat_dly:3 ; +u32 rd_rsp_dly:3 ; +u32 wr_cmd_dly:3 ; +u32 wr_dat_dly:3 ; +u32 clk_dly:3 ; +}; + +struct spmmc_compatible { +u8 mode; +u32 min_clk; +u32 max_clk; +u32 max_blk_count; +u32 max_dma_memory_sectors; +u32 blk_size; +}; + +static const u8 tuning_blk_pattern_4bit[] = { +0xff ,0x0f ,0xff ,0x00 ,0xff ,0xcc ,0xc3 ,0xcc , +0xc3 ,0x3c ,0xcc ,0xff ,0xfe ,0xff ,0xfe ,0xef , +0xff ,0xdf ,0xff ,0xdd ,0xff ,0xfb ,0xff ,0xfb , +0xbf ,0xff ,0x7f ,0xff ,0x77 ,0xf7 ,0xbd ,0xef , +0xff ,0xf0 ,0xff ,0xf0 ,0x0f ,0xfc ,0xcc ,0x3c , +0xcc ,0x33 ,0xcc ,0xcf ,0xff ,0xef ,0xff ,0xee , +0xff ,0xfd ,0xff ,0xfd ,0xdf ,0xff ,0xbf ,0xff , +0xbb ,0xff ,0xf7 ,0xff ,0xf7 ,0x7f ,0x7b ,0xde , +}; + +static const u8 tuning_blk_pattern_8bit[] = { +0xff ,0xff ,0x00 ,0xff ,0xff ,0xff ,0x00 ,0x00 , +0xff ,0xff ,0xcc ,0xcc ,0xcc ,0x33 ,0xcc ,0xcc , +0xcc ,0x33 ,0x33 ,0xcc ,0xcc ,0xcc ,0xff ,0xff , +0xff ,0xee ,0xff ,0xff ,0xff ,0xee ,0xee ,0xff , +0xff ,0xff ,0xdd ,0xff ,0xff ,0xff ,0xdd ,0xdd , +0xff ,0xff ,0xff ,0xbb ,0xff ,0xff ,0xff ,0xbb , +0xbb ,0xff ,0xff ,0xff ,0x77 ,0xff ,0xff ,0xff , +0x77 ,0x77 ,0xff ,0x77 ,0xbb ,0xdd ,0xee ,0xff , +0xff ,0xff ,0xff ,0x00 ,0xff ,0xff ,0xff ,0x00 , +0x00 ,0xff ,0xff ,0xcc ,0xcc ,0xcc ,0x33 ,0xcc , +0xcc ,0xcc ,0x33 ,0x33 ,0xcc ,0xcc ,0xcc ,0xff , +0xff ,0xff ,0xee ,0xff ,0xff ,0xff ,0xee ,0xee ,
drivers/mmc/host/sunplus_mmc.c line 189
Quoted 10 lines
drivers/mmc/host/sunplus_mmc.c new file +10
-0+0xff ,0xff ,0xff ,0xdd ,0xff ,0xff ,0xff ,0xdd , +0xdd ,0xff ,0xff ,0xff ,0xbb ,0xff ,0xff ,0xff , +0xbb ,0xbb ,0xff ,0xff ,0xff ,0x77 ,0xff ,0xff , + 0xff, 0x77, 0x77, 0xff, 0x77, 0xbb, 0xdd, 0xee, +}; + +/* Produces a mask of set bits covering a range of a 32-bit value */ +static inline u32 bitfield_mask (u32 shift,u32 width) +{ +return ((1 << width) -1 ) << shift;
Aren't you re-inventing GENMASK?
Quoted 105 lines
drivers/mmc/host/sunplus_mmc.c new file +105
-0+} + +#define SPSDC_MIN_CLK 400000 +#define SPSDC_MAX_CLK 52000000 +#define SPSDC_50M_CLK 50000000 +#define SPSDC_MAX_BLK_COUNT 65536 + +#define SPSD2_MEDIA_TYPE_REG 0x0000 +#define SPSDC_MEDIA_MASK GENMASK(2, 0) +#define SPSDC_MEDIA_NONE 0 +#define SPSDC_MEDIA_SD 6 +#define SPSDC_MEDIA_MS 7 + +#define SPSD2_SDRAM_SECTOR_SIZE_REG 0x0010 +#define SPSDC_MAX_DMA_MEMORY_SECTORS 8 + +#define SPSD2_SDRAM_SECTOR_ADDR_REG 0x001C +#define SPSD2_SD_INT_REG 0x00B0 +#define SPSDC_SDINT_SDCMPEN BIT(0) +#define SPSDC_SDINT_SDCMP BIT(1) +#define SPSDC_SDINT_SDCMP_CLR BIT(2) +#define SPSDC_SDINT_SDIOEN BIT(4) +#define SPSDC_SDINT_SDIO BIT(5) +#define SPSDC_SDINT_SDIO_CLR BIT(6) + +#define SPSD2_SD_PAGE_NUM_REG 0x00B4 +#define SPSD2_SD_CONF0_REG 0x00B8 +#define SPSDC_CONF0_SDPIO_MODE BIT(0) +#define SPSDC_CONF0_SDLEN_MODE BIT(2) +#define SPSDC_CONF0_TRANS_MODE GENMASK(5, 4) +#define SPSDC_TRANS_CMD_MODE 0 +#define SPSDC_TRANS_WR_MODE 1 +#define SPSDC_TRANS_RD_MODE 2 +#define SPSDC_CONF0_AUTORSP BIT(6) +#define SPSDC_CONF0_CMDDUMMY BIT(7) +#define SPSDC_CONF0_RSPCHK BIT(8) + +#define SPSD2_SDIO_CTRL_REG 0x00BC +#define SPSDC_SDIO_CTRL_MULTI_TRIG BIT(6) + +#define SPSD2_SD_RST_REG 0x00C0 +#define SPSDC_RST_ALL 0x07 + +#define SPSD2_SD_CONF_REG 0x00C4 +#define SPSDC_CONF_CLK_DIV GENMASK(11, 0) +#define SPSDC_CONF_4BIT_MODE BIT(12) +#define SPSDC_CONF_SDRSP_TYPE BIT(13) +#define SPSDC_CONF_SD_MODE BIT(16) +#define SPSDC_CONF_MMC8BIT BIT(18) +#define SPSDC_CONF_SDIO_MODE BIT(20) + +#define SPSD2_SD_CTRL_REG 0x00C8 +#define SPSDC_CTRL_CMD_TRIG BIT(0) +#define SPSDC_CTRL_TXDUMMY_TRIG BIT(1) + +#define SPSD2_SD_STATUS_REG 0x00CC +#define SPSDC_STS_DUMMY_RDY BIT(0) +#define SPSDC_STS_RSP_BUF_FULL BIT(1) +#define SPSDC_STS_TX_BUF_EMP BIT(2) +#define SPSDC_STS_RX_BUF_FULL BIT(3) +#define SPSDC_STS_CMD_PIN_STS BIT(4) +#define SPSDC_STS_DAT0_PIN_STS BIT(5) +#define SPSDC_STS_RSP_TIMEOUT BIT(6) +#define SPSDC_STS_CARD_CRC_TIMEOUT BIT(7) +#define SPSDC_STS_STB_TIMEOUT BIT(8) +#define SPSDC_STS_RSP_CRC7_ERR BIT(9) +#define SPSDC_STS_CRC_TOKEN_ERR BIT(10) +#define SPSDC_STS_RDATA_CRC16_ERR BIT(11) +#define SPSDC_STS_SUSPEND_STATE_RDY BIT(12) +#define SPSDC_STS_BUSY_CYCLE BIT(13) + +#define SPSD2_SD_STATE_REG 0x00D0 +#define SPSDC_STATE_IDLE (0x0) +#define SPSDC_STATE_TXDUMMY (0x1) +#define SPSDC_STATE_TXCMD (0x2) +#define SPSDC_STATE_RXRSP (0x3) +#define SPSDC_STATE_TXDATA (0x4) +#define SPSDC_STATE_RXCRC (0x5) +#define SPSDC_STATE_RXDATA (0x6) +#define SPSDC_STATE_MASK (0x7) +#define SPSDC_STATE_ERROR BIT(13) +#define SPSDC_STATE_FINISH BIT(14) + +#define SPSD2_BLOCKSIZE_REG 0x00D4 +#define SPSD2_SD_TIMING_CONF0_REG 0x00DC +#define SPSDC_TIMING_CONF0_HS_EN BIT(11) +#define SPSDC_TIMING_CONF0_WRTD GENMASK(14, 12) + +#define SPSD2_SD_TIMING_CONF1_REG 0x00E0 +#define SPSDC_TIMING_CONF1_RDTD GENMASK(15, 13) + +#define SPSD2_SD_PIO_TX_REG 0x00E4 +#define SPSD2_SD_PIO_RX_REG 0x00E8 +#define SPSD2_SD_CMD_BUF0_REG 0x00EC +#define SPSD2_SD_CMD_BUF1_REG 0x00F0 +#define SPSD2_SD_CMD_BUF2_REG 0x00F4 +#define SPSD2_SD_CMD_BUF3_REG 0x00F8 +#define SPSD2_SD_CMD_BUF4_REG 0x00FC +#define SPSD2_SD_RSP_BUF0_3_REG 0x0100 +#define SPSD2_SD_RSP_BUF4_5_REG 0x0104 +#define SPSD2_DMA_SRCDST_REG 0x0204 +#define SPSD2_DMA_SIZE_REG 0x0208 +#define SPSD2_DMA_STOP_RST_REG 0x020c +#define SPSD2_DMA_CTRL_REG 0x0210 +#define SPSD2_DMA_BASE_ADDR0_REG 0x0214
drivers/mmc/host/sunplus_mmc.c line 304
Quoted 10 lines
drivers/mmc/host/sunplus_mmc.c new file +10
-0+#define SPSD2_DMA_BASE_ADDR16_REG 0x0218 + +struct spsdc_tuning_info { +int need_tuning; +#define SPSDC_MAX_RETRIES (8 * 8) +int retried;/* how many times has been retried */ +u32 wr_dly:3 ; +u32 rd_dly:3 ; +u32 clk_dly:3 ; +};
Please put all type declarations together, after defines. Don't mix defines/declarations/defines/declarations.
Quoted 6 lines
drivers/mmc/host/sunplus_mmc.c new file +6
-0+ +enum { +SPSDC_DMA_MODE =0 , +SPSDC_PIO_MODE =1 , +}; +
drivers/mmc/host/sunplus_mmc.c line 320
Quoted 10 lines
drivers/mmc/host/sunplus_mmc.c new file +10
-0+enum SPSDC_MODE { +SPSDC_MODE_SD =0 , +SPSDC_MODE_SDIO =1 , +}; + +struct spmmc_host { +void __iomem *base; +struct clk *clk; +struct reset_control *rstc; +int mode;/* SD/SDIO/eMMC */
Didn't you define enum for this?
drivers/mmc/host/sunplus_mmc.c line 322
Quoted 2 lines
drivers/mmc/host/sunplus_mmc.c new file +2
-0+spinlock_t lock;/* controller lock */ +struct mutex mrq_lock;
Please describe explicitly what is protected with which lock. "controller lock" seems not specific enough.
drivers/mmc/host/sunplus_mmc.c line 334
Quoted 12 lines
drivers/mmc/host/sunplus_mmc.c new file +12
-0+/* tasklet used to handle error then finish the request */ +struct tasklet_struct tsklet_finish_req; +struct mmc_host *mmc; +struct mmc_request *mrq;/* current mrq */ + +int irq; +int use_int;/* should raise irq when done? */ +int power_state;/* current power state: off/up/on */ +int ddr_enabled; +int signal_voltage; +#define SPMMC_DMA_MODE 0 +#define SPMMC_PIO_MODE 1
You just have enum for it.
drivers/mmc/host/sunplus_mmc.c line 335
Quoted 1 line
drivers/mmc/host/sunplus_mmc.c new file +1
-0+int dmapio_mode;
One more enum...
drivers/mmc/host/sunplus_mmc.c line 337
Quoted 2 lines
drivers/mmc/host/sunplus_mmc.c new file +2
-0+/* for purpose of reducing context switch, only when transfer data that*/ +/* length is greater than `dma_int_threshold' should use interrupt */
Use Linux coding style comments.
drivers/mmc/host/sunplus_mmc.c line 347
Quoted 10 lines
drivers/mmc/host/sunplus_mmc.c new file +10
-0+int dma_int_threshold; +struct sg_mapping_iter sg_miter;/* for pio mode to access sglist */ +int dma_use_int;/* should raise irq when dma done */ +struct spmmc_tuning_info emmc_tuning_info; +struct spsdc_tuning_info sd_tuning_info; +int restore_4bit_sdio_bus; +const struct spmmc_compatible *dev_comp; +}; + +struct spsdc_host {
Where is this used?
drivers/mmc/host/sunplus_mmc.c line 321
Quoted 4 lines
drivers/mmc/host/sunplus_mmc.c new file +4
-0+void __iomem *base; +struct clk *clk; +struct reset_control *rstc; +spinlock_t lock;/* controller lock */
Also a controller lock? Two same locks? No, really.
Sorry, this code is poor quality. Please go through it and clean it up before sending. Duplicated structures should be caught up with some internal review. Do not send code which is not ready.
(...)
drivers/mmc/host/sunplus_mmc.c line 2183
Quoted 9 lines
drivers/mmc/host/sunplus_mmc.c new file +9
-0+ +static struct platform_driver spmmc_driver = { + .probe = spmmc_drv_probe, + .remove = spmmc_drv_remove, + .suspend = spmmc_drv_suspend, + .resume = spmmc_drv_resume, + .driver = { + .name ="spmmc" , + .owner =THIS_MODULE ,
No, no, no. Core sets it. Did you see it in any other driver? Why doing it different than any other driver?
drivers/mmc/host/sunplus_mmc.c line 2195
Quoted 12 lines
drivers/mmc/host/sunplus_mmc.c new file +12
-0+#ifdef CONFIG_PM + .pm = &spmmc_pm_ops, +#endif + .of_match_table = spmmc_of_table, + }, +}; +module_platform_driver (spmmc_driver); + +MODULE_AUTHOR ("Tony Huang <[email protected]>" ); +MODULE_AUTHOR ("Li-hao Kuo <[email protected]>" ); +MODULE_DESCRIPTION ("Sunplus MMC controller driver" ); +MODULE_LICENSE ("GPL" );
Best regards,
Krzysztof
RE: [PATCH v4 1/2] dt-binding: mmc: Add mmc yaml file for Sunplus SP7021
In reply to Krzysztof KozlowskiDear Krzysztof:
Quoted 12 lines
Documentation/devicetree/bindings/mmc/sunplus,mmc.yaml line 7
Quoted 9 lines
+++
b/Documentation/devicetree/bindings/mmc/sunplus,mmc.yamlDocumentation/devicetree/bindings/mmc/sunplus,mmc.yaml new file +7
-0@@ -0,0 +1,79 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) # Copyright +(C) Sunplus Ltd. Co. 2021 %YAML 1.2 +--- +$id: http://devicetree.org/schemas/mmc/sunplus,mmc.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: sunplus MMC controllers/sunplus/Sunplus/
Below is my modification:
title: Sunplus MMC Controller
Quoted 6 lines
Documentation/devicetree/bindings/mmc/sunplus,mmc.yaml line 11
Quoted 3 lines
Documentation/devicetree/bindings/mmc/sunplus,mmc.yaml new file +3
-0+ +allOf: + - $ref: "mmc-controller.yaml"allOf below maintainers,
I will modify it.
Quoted 15 lines
Documentation/devicetree/bindings/mmc/sunplus,mmc.yaml line 21
Quoted 10 lines
Documentation/devicetree/bindings/mmc/sunplus,mmc.yaml new file +10
-0+ +maintainers: + - Tony Huang <[email protected]> + - Li-hao Kuo <[email protected]> + +properties: + compatible: + enum: + - sunplus,mmc-v1 + - sunplus,mmc-v2How did this happen? Versions of blocks are usually discouraged, unless you have clear specification,. The previous discussion did not end with "add v1 and v2".
Quoted 3 lines
Do you have clear documentation/specification of these blocks? If no, please use SoC compatibles.
v1: support SDIO 2.0
v2: support eMMC 4.41
The register base address and offset address of emmc and sd card are different. eMMC and sdcard are individual hardware settings
We need version to distinguish different speeds
Quoted 12 lines
Documentation/devicetree/bindings/mmc/sunplus,mmc.yaml line 30
Quoted 9 lines
Documentation/devicetree/bindings/mmc/sunplus,mmc.yaml new file +9
-0+ + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + clocks: + minItems: 1maxItems
I will modify it.
Quoted 56 lines
Quoted 56 lines
Documentation/devicetree/bindings/mmc/sunplus,mmc.yaml new file +49
-0+ + resets: + maxItems: 1 + + max-frequency: true + +required: + - compatible + - reg + - interrupts + - clocks + - resets + +unevaluatedProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + #include <dt-bindings/interrupt-controller/arm-gic.h> + mmc0: mmc@9c003b00 { + compatible = "sunplus,mmc-v2"; + reg = <0x9c003b00 0x180>; + interrupts = <20 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&clkc 0x4e>; + resets = <&rstc 0x3e>; + bus-width = <8>; + max-frequency = <52000000>; + non-removable; + disable-wp; + cap-mmc-highspeed; + mmc-ddr-3_3v; + no-sdio; + no-sd; + }; + + mmc1: mmc@9c003e80 { + compatible = "sunplus,mmc-v1"; + reg = <0x9c003e80 0x280>; + interrupts = <21 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&clkc 0x4f>; + resets = <&rstc 0x3f>; + pinctrl-names = "default"; + pinctrl-0 = <&mmc1_mux &mmc1_mux_cd>; + max-frequency = <52000000>; + disable-wp; + cap-sd-highspeed; + no-sdio; + no-mmc; + };MAINTAINERS +0
-0@@ -18242,6 +18242,12 @@ L: [email protected] S: Maintained F: drivers/net/ethernet/dlink/sundance.c
Quoted 5 lines
MAINTAINERS L: [email protected] · line 18247
Quoted 3 lines
MAINTAINERS +3
-0+SUNPLUS MMC DRIVER +M: Tony Huang <[email protected]> +M: Li-hao Kuo <[email protected]>Wrong indentation.
I will modify it.
Quoted 6 lines
MAINTAINERS L: [email protected] · line 18249
Quoted 3 lines
MAINTAINERS +2
-0+S: Maintained +F: Documentation/devicetree/bindings/mmc/sunplu,mmc.yamlWrong file name.
I will modify it.
RE: [PATCH v4 2/2] mmc: Add mmc driver for Sunplus SP7021
In reply to Krzysztof KozlowskiDear Krzysztof:
Quoted 13 lines
drivers/mmc/host/sunplus_mmc.c line 347
Quoted 10 lines
drivers/mmc/host/sunplus_mmc.c new file +9
-0+int dma_int_threshold; +struct sg_mapping_iter sg_miter;/* for pio mode to access sglist */ +int dma_use_int;/* should raise irq when dma done */ +struct spmmc_tuning_info emmc_tuning_info; +struct spsdc_tuning_info sd_tuning_info; +int restore_4bit_sdio_bus; +const struct spmmc_compatible *dev_comp; }; + +struct spsdc_host {Where is this used?
struct spmmc_host{} for emmc.
struct spsdc_host{} for SD card.
The register base address and offset address of emmc and sd cards are different. eMMC and sdcard are their respective hardware settings.
RE: [PATCH v4 2/2] mmc: Add mmc driver for Sunplus SP7021
In reply to Krzysztof KozlowskiDear Krzysztof:
Quoted 14 lines
Quoted 13 lines
drivers/mmc/host/sunplus_mmc.c line 347
Quoted 10 lines
drivers/mmc/host/sunplus_mmc.c new file +9
-0+int dma_int_threshold; +struct sg_mapping_iter sg_miter;/* for pio mode to access sglist */ +int dma_use_int;/* should raise irq when dma done */ +struct spmmc_tuning_info emmc_tuning_info; +struct spsdc_tuning_info sd_tuning_info; +int restore_4bit_sdio_bus; +const struct spmmc_compatible *dev_comp; }; + +struct spsdc_host {Where is this used?
Quoted 6 lines
struct spmmc_host{} for emmc.
struct spsdc_host{} for SD card.
The register base address and offset address of emmc and sd cards are different.
eMMC and sdcard are their respective hardware settings.
I will remove struct spsdc_host{}.
Re: [PATCH v4 1/2] dt-binding: mmc: Add mmc yaml file for Sunplus SP7021
In reply to Tony Huang 黃懷厚Quoted 42 lines · Tony Huang 黃懷厚
Dear Krzysztof:
Quoted 12 lines
Documentation/devicetree/bindings/mmc/sunplus,mmc.yaml line 7
Quoted 9 lines
+++
b/Documentation/devicetree/bindings/mmc/sunplus,mmc.yamlDocumentation/devicetree/bindings/mmc/sunplus,mmc.yaml new file +7
-0@@ -0,0 +1,79 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) # Copyright +(C) Sunplus Ltd. Co. 2021 %YAML 1.2 +--- +$id: http://devicetree.org/schemas/mmc/sunplus,mmc.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: sunplus MMC controllers/sunplus/Sunplus/
Below is my modification:
title: Sunplus MMC ControllerQuoted 6 lines
Documentation/devicetree/bindings/mmc/sunplus,mmc.yaml line 11
Quoted 3 lines
Documentation/devicetree/bindings/mmc/sunplus,mmc.yaml new file +3
-0+ +allOf: + - $ref: "mmc-controller.yaml"allOf below maintainers,
I will modify it.
Quoted 15 lines
Documentation/devicetree/bindings/mmc/sunplus,mmc.yaml line 21
Quoted 10 lines
Documentation/devicetree/bindings/mmc/sunplus,mmc.yaml new file +10
-0+ +maintainers: + - Tony Huang <[email protected]> + - Li-hao Kuo <[email protected]> + +properties: + compatible: + enum: + - sunplus,mmc-v1 + - sunplus,mmc-v2How did this happen? Versions of blocks are usually discouraged, unless you have clear specification,. The previous discussion did not end with "add v1 and v2".
Quoted 6 lines
Quoted 3 lines
Do you have clear documentation/specification of these blocks? If no, please use SoC compatibles.
v1: support SDIO 2.0
v2: support eMMC 4.41
That's spec is not enough. You need to provide detailed specification of each of them. See for example versioned blocks of Synopsys DeisgnWare (e.g. eMMC/SDHCI).
Quoted 3 lines
The register base address and offset address of emmc and sd card are different. eMMC and sdcard are individual hardware settings
We need version to distinguish different speeds
That's not the answer. How did it happen that you have now versions and before there were SoC compatibles? No one pointed to this and you did not mention it in description of changes.
Best regards,
Krzysztof
Re: [PATCH v4 2/2] mmc: Add mmc driver for Sunplus SP7021
In reply to Tony Huang 黃懷厚Quoted 15 lines · Tony Huang 黃懷厚
Dear Krzysztof:
Quoted 13 lines
drivers/mmc/host/sunplus_mmc.c line 347
Quoted 10 lines
drivers/mmc/host/sunplus_mmc.c new file +9
-0+int dma_int_threshold; +struct sg_mapping_iter sg_miter;/* for pio mode to access sglist */ +int dma_use_int;/* should raise irq when dma done */ +struct spmmc_tuning_info emmc_tuning_info; +struct spsdc_tuning_info sd_tuning_info; +int restore_4bit_sdio_bus; +const struct spmmc_compatible *dev_comp; }; + +struct spsdc_host {Where is this used?
Quoted 4 lines
struct spmmc_host{} for emmc.
struct spsdc_host{} for SD card.
The register base address and offset address of emmc and sd cards are different. eMMC and sdcard are their respective hardware settings.
This is a weird answer. I asked where is this used (struct spsdc_host). There is no single reference of this type. Your answer does not cover it all. I know that eMMC and SD are different. That was not the question. The question is: point me to the code which uses this type.
Best regards,
Krzysztof
RE: [PATCH v4 2/2] mmc: Add mmc driver for Sunplus SP7021
Dear krzysztof:
Quoted 16 lines
Quoted 13 lines
Quoted 12 lines
drivers/mmc/host/sunplus_mmc.c line 347
Quoted 9 lines
drivers/mmc/host/sunplus_mmc.c new file +9
-0+int dma_int_threshold; +struct sg_mapping_iter sg_miter;/* for pio mode to access sglist */ +int dma_use_int;/* should raise irq when dma done */ +struct spmmc_tuning_info emmc_tuning_info; +struct spsdc_tuning_info sd_tuning_info; +int restore_4bit_sdio_bus; +const struct spmmc_compatible *dev_comp; }; + +struct spsdc_host {Where is this used?
Quoted 3 lines
struct spmmc_host{} for emmc.
struct spsdc_host{} for SD card.
The register base address and offset address of emmc and sd cards are
Quoted 9 lines
different.
Quoted 1 line
eMMC and sdcard are their respective hardware settings.
This is a weird answer. I asked where is this used (struct
spsdc_host). There is no single reference of this type. Your answer does not cover it all. I know that eMMC and SD are different. That was not the question. The question is: point me to the code which uses this type.
Sorry, I will remove struct spsdc_host {}.