LoongArch: Introduce the Loongson-2K MMC host controller driver
Subsystems (4)
Binbin Zhou
maintainerv4 cover LoongArch: Introduce the Loongson-2K MMC host controller driver
Hi all:
This patchset introduce the MMC host controller on Loongson-2K series CPUs.
They are similar, except for the interface characteristics and the use of DMA engine, specifically, the Loongson-2K0500/Loongson-2K1000 use an externally shared APBDMA engine, while the Loongson-2K2000 uses an internally exclusive DMA.
Based on this, I'm splitting the driver into two patches.
List of the patchset:
Patch1: bindings for Loongson-2K0500/Loongson-2K1000;
Patch2: driver for MMC controller using externally shared APBDMA engine;
Patch3: bindings for Loongson-2K2000;
Patch4: driver for MMC controller using internally exclusive DMA.
Thanks.
-------
V4:
patch(2/4):
- Code formatting;
- Fix lkp error
https://lore.kernel.org/all/[email protected]/ patch(4/4): - Rename function names: ls2k1000_mmc_regmap_config -> ls2k0500_mmc_regmap_config loongson2_mmc_reorder_cmd_data -> ls2k0500_mmc_reorder_cmd_data loongson2_mmc_set_internal_dma -> ls2k2000_mmc_set_internal_dma
- Use macro definitions for magic numbers.
Link to V3:
https://lore.kernel.org/all/[email protected]/
V3:
patch(1/4):
- Rename dt-binding file as loongson,ls2k0500-mmc.yaml.
patch(2/4):
- Fix lkp error;
https://lore.kernel.org/all/[email protected]/ - Add regulators support for ios ops;
- Add ack_sdio_irq() callback;
- Add MMC_CAP2_SDIO_IRQ_NOTHREAD flag;
patch(3/4):
- Add Ack-by tag.
patch(4/4):
- Update commit for fix_data_timeout().
Link to V2:
https://lore.kernel.org/all/[email protected]/
V2:
patch(1/4):
- Add reg define for each reg entry.
patch(2/4):
- Put all code in the c-file;
- Use mmc_from_priv() instead of host->mmc;
- Use sdio_signal_irq() instead of mmc_signal_sdio_irq();
- Use devm_mmc_alloc_host() instead of mmc_alloc_host();
- Use mmc_regulator_get_supply();
patch(4/4):
- Add fix_cmd_interrupt function which is needed by Loongson-2K2000.
Link to V1:
https://lore.kernel.org/linux-mmc/[email protected]/
Binbin Zhou (4):
dt-bindings: mmc: Add Loongson-2K SD/SDIO/eMMC controller binding
mmc: loongson2: Add Loongson-2K SD/SDIO controller driver
dt-bindings: mmc: loongson,ls2k0500-mmc: Add compatible for
Loongson-2K2000
mmc: loongson2: Add Loongson-2K2000 SD/SDIO/eMMC controller driver
.../bindings/mmc/loongson,ls2k0500-mmc.yaml | 112 ++ MAINTAINERS | 7 + drivers/mmc/host/Kconfig | 13 + drivers/mmc/host/Makefile | 1 + drivers/mmc/host/loongson2-mmc.c | 1029 +++++++++++++++++ 5 files changed, 1162 insertions(+) create mode 100644 Documentation/devicetree/bindings/mmc/loongson,ls2k0500-mmc.yaml create mode 100644 drivers/mmc/host/loongson2-mmc.c
base-commit: f5c755ef810009b85350884c483705bd04365370
Signature · 1 line
2.47.1
Binbin Zhou
maintainerPATCH v4 1/4 dt-bindings: mmc: Add Loongson-2K SD/SDIO/eMMC controller binding
Add the Loongson-2K SoC's SD/SDIO/eMMC controller binding with DT schema format using json-schema.
--- .../bindings/mmc/loongson,ls2k0500-mmc.yaml | 69 +++++++++++++++++++ MAINTAINERS | 6 ++ 2 files changed, 75 insertions(+) create mode 100644 Documentation/devicetree/bindings/mmc/loongson,ls2k0500-mmc.yaml
Documentation/devicetree/bindings/mmc/loongson,ls2k0500-mmc.yaml new file +69 -0
@@ -0,0 +1,69 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/mmc/loongson,ls2k0500-mmc.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: The SD/SDIO/eMMC host controller for Loongson-2K family SoCs + +description: + The MMC host controller on the Loongson-2K0500/2K1000 (using an externally + shared apbdma controller) provides the SD and SDIO device interfaces. + +maintainers: + - Binbin Zhou <[email protected]> + +allOf: + - $ref: mmc-controller.yaml# + +properties: + compatible: + enum: + - loongson,ls2k0500-mmc + - loongson,ls2k1000-mmc + + reg: + items: + - description: Loongson-2K MMC controller registers. + - description: APB DMA config register for Loongson-2K MMC controller. + + interrupts: + maxItems: 1 + + clocks: + maxItems: 1 + + dmas: + maxItems: 1 + + dma-names: + const: rx-tx + +required: + - compatible + - reg + - interrupts + - clocks + - dmas + - dma-names + +unevaluatedProperties: false + +examples: + - | + #include <dt-bindings/gpio/gpio.h> + #include <dt-bindings/interrupt-controller/irq.h> + #include <dt-bindings/clock/loongson,ls2k-clk.h> + + mmc@1fe2c000 { + compatible = "loongson,ls2k1000-mmc"; + reg = <0x1fe2c000 0x68>, + <0x1fe00438 0x8>; + interrupt-parent = <&liointc0>; + interrupts = <31 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&clk LOONGSON2_APB_CLK>; + dmas = <&apbdma1 0>; + dma-names = "rx-tx"; + bus-width = <4>; + cd-gpios = <&gpio0 22 GPIO_ACTIVE_LOW>; + };
MAINTAINERS +6 -0
@@ -14175,6 +14175,12 @@ S: Maintained F: Documentation/devicetree/bindings/hwinfo/loongson,ls2k-chipid.yaml F: drivers/soc/loongson/loongson2_guts.c +LOONGSON-2 SOC SERIES MMC/SD/SDIO CONTROLLER DRIVER +M: Binbin Zhou <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/devicetree/bindings/mmc/loongson,ls2k0500-mmc.yaml + LOONGSON-2 SOC SERIES PM DRIVER M: Yinbo Zhu <[email protected]> L: [email protected]
Signature · 1 line
2.47.1
Binbin Zhou
maintainerPATCH v4 2/4 mmc: loongson2: Add Loongson-2K SD/SDIO controller driver
In reply to Binbin ZhouThe MMC controllers on the Loongson-2K series CPUs are similar, except for the interface characteristics and the use of DMA controllers.
This patch describes the MMC controllers on the Loongson-2K0500/2K1000, with the distinguishing feature being the use of an externally shared APBDMA engine.
--- MAINTAINERS | 1 + drivers/mmc/host/Kconfig | 13 + drivers/mmc/host/Makefile | 1 + drivers/mmc/host/loongson2-mmc.c | 798 +++++++++++++++++++++++++++++++ 4 files changed, 813 insertions(+) create mode 100644 drivers/mmc/host/loongson2-mmc.c
MAINTAINERS +1 -0
@@ -14180,6 +14180,7 @@ M: Binbin Zhou <[email protected]> L: [email protected] S: Maintained F: Documentation/devicetree/bindings/mmc/loongson,ls2k0500-mmc.yaml +F: drivers/mmc/host/loongson2-mmc.c LOONGSON-2 SOC SERIES PM DRIVER M: Yinbo Zhu <[email protected]>
drivers/mmc/host/Kconfig +13 -0
@@ -1111,6 +1111,19 @@ config MMC_OWL This selects support for the SD/MMC Host Controller on Actions Semi Owl SoCs. +config MMC_LOONGSON2 + tristate "Loongson-2K SD/SDIO/eMMC Host Interface support" + depends on LOONGARCH || COMPILE_TEST + depends on HAS_DMA + help + This selects support for the SD/SDIO/eMMC Host Controller on + Loongson-2K series CPUs. + + To compile this driver as a module, choose M here: the + module will be called mmc_loongson2. + + If unsure, say N. + config MMC_SDHCI_EXTERNAL_DMA bool
drivers/mmc/host/Makefile +1 -0
@@ -72,6 +72,7 @@ obj-$(CONFIG_MMC_USDHI6ROL0) += usdhi6rol0.o obj-$(CONFIG_MMC_TOSHIBA_PCI) += toshsd.o obj-$(CONFIG_MMC_BCM2835) += bcm2835.o obj-$(CONFIG_MMC_OWL) += owl-mmc.o +obj-$(CONFIG_MMC_LOONGSON2) += loongson2-mmc.o obj-$(CONFIG_MMC_REALTEK_PCI) += rtsx_pci_sdmmc.o obj-$(CONFIG_MMC_REALTEK_USB) += rtsx_usb_sdmmc.o
drivers/mmc/host/loongson2-mmc.c new file +798 -0
798 lines not on this page · raw message
Signature · 1 line
2.47.1
Binbin Zhou
maintainerPATCH v4 3/4 dt-bindings: mmc: loongson,ls2k0500-mmc: Add compatible for Loongson-2K2000
In reply to Binbin ZhouAdd the devicetree compatible for Loongson-2K2000 EMMC/SD/SDIO controller.
--- .../bindings/mmc/loongson,ls2k0500-mmc.yaml | 47 ++++++++++++++++++- 1 file changed, 45 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/mmc/loongson,ls2k0500-mmc.yaml +45 -2
@@ -9,6 +9,9 @@ title: The SD/SDIO/eMMC host controller for Loongson-2K family SoCs description: The MMC host controller on the Loongson-2K0500/2K1000 (using an externally shared apbdma controller) provides the SD and SDIO device interfaces. + The two MMC host controllers on the Loongson-2K2000 are similar, + except that they use internal exclusive DMA. one controller provides + the eMMC interface and the other provides the SD/SDIO interface. maintainers: - Binbin Zhou <[email protected]>
@@ -21,8 +24,10 @@ properties: enum: - loongson,ls2k0500-mmc - loongson,ls2k1000-mmc + - loongson,ls2k2000-mmc reg: + minItems: 1 items: - description: Loongson-2K MMC controller registers. - description: APB DMA config register for Loongson-2K MMC controller.
@@ -44,11 +49,31 @@ required: - reg - interrupts - clocks - - dmas - - dma-names unevaluatedProperties: false +if: + properties: + compatible: + contains: + enum: + - loongson,ls2k0500-mmc + - loongson,ls2k1000-mmc + +then: + properties: + reg: + minItems: 2 + + required: + - dmas + - dma-names + +else: + properties: + reg: + maxItems: 1 + examples: - | #include <dt-bindings/gpio/gpio.h>
@@ -67,3 +92,21 @@ examples: bus-width = <4>; cd-gpios = <&gpio0 22 GPIO_ACTIVE_LOW>; }; + + - | + #include <dt-bindings/interrupt-controller/irq.h> + #include <dt-bindings/clock/loongson,ls2k-clk.h> + + mmc@79990000 { + compatible = "loongson,ls2k2000-mmc"; + reg = <0x79990000 0x1000>; + interrupt-parent = <&pic>; + interrupts = <51 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&clk LOONGSON2_EMMC_CLK>; + bus-width = <8>; + non-removable; + cap-mmc-highspeed; + mmc-hs200-1_8v; + no-sd; + no-sdio; + };
Signature · 1 line
2.47.1
Binbin Zhou
maintainerPATCH v4 4/4 mmc: loongson2: Add Loongson-2K2000 SD/SDIO/eMMC controller driver
In reply to Binbin ZhouThis patch describes the two MMC controllers of the Loongson-2K2000 SoC, one providing an eMMC interface and the other exporting an SD/SDIO interface.
Compared to the Loongson-2K1000's MMC controllers, their internals are similar, except that we use an internally exclusive DMA engine instead of an externally shared APBDMA engine.
--- drivers/mmc/host/loongson2-mmc.c | 231 +++++++++++++++++++++++++++++++ 1 file changed, 231 insertions(+)
drivers/mmc/host/loongson2-mmc.c +231 -0
@@ -44,6 +44,18 @@#define LOONGSON2_MMC_REG_DATA 0x40/* Data Register */ #define LOONGSON2_MMC_REG_IEN 0x64/* Interrupt Enable Register */ +/* EMMC DLL Mode Registers */ +#define LOONGSON2_MMC_REG_DLLVAL 0xf0/* DLL Master Lock-value Register */ +#define LOONGSON2_MMC_REG_DLLCTL 0xf4/* DLL Control Register */ +#define LOONGSON2_MMC_REG_DELAY 0xf8/* DLL Delayed Parameter Register */ +#define LOONGSON2_MMC_REG_SEL 0xfc/* Bus Mode Selection Register */ + +/* Exclusive DMA R/W Registers */ +#define LOONGSON2_MMC_REG_WDMA_LO 0x400 +#define LOONGSON2_MMC_REG_WDMA_HI 0x404 +#define LOONGSON2_MMC_REG_RDMA_LO 0x800 +#define LOONGSON2_MMC_REG_RDMA_HI 0x804 +/* Bitfields of control register */ #define LOONGSON2_MMC_CTL_ENCLK BIT(0)#define LOONGSON2_MMC_CTL_EXTCLK BIT(1)
@@ -109,6 +121,9 @@#define LOONGSON2_MMC_DSTS_RESUME BIT(15)#define LOONGSON2_MMC_DSTS_SUSPEND BIT(16) +/* Bitfields of FIFO Status Register */ +#define LOONGSON2_MMC_FSTS_TXFULL BIT(11) +/* Bitfields of interrupt register */ #define LOONGSON2_MMC_INT_DFIN BIT(0)#define LOONGSON2_MMC_INT_DTIMEOUT BIT(1)
@@ -136,6 +151,44 @@#define LOONGSON2_MMC_IEN_ALL GENMASK(9, 0)#define LOONGSON2_MMC_INT_CLEAR GENMASK(9, 0) +/* Bitfields of DLL master lock-value register */ +#define LOONGSON2_MMC_DLLVAL_DONE BIT(8) + +/* Bitfields of DLL control register */ +#define LOONGSON2_MMC_DLLCTL_TIME GENMASK(7, 0) +#define LOONGSON2_MMC_DLLCTL_INCRE GENMASK(15, 8) +#define LOONGSON2_MMC_DLLCTL_START GENMASK(23, 16) +#define LOONGSON2_MMC_DLLCTL_CLK_MODE BIT(24) +#define LOONGSON2_MMC_DLLCTL_START_BIT BIT(25) +#define LOONGSON2_MMC_DLLCTL_TIME_BPASS GENMASK(29, 26) + +#define LOONGSON2_MMC_DELAY_PAD GENMASK(7, 0) +#define LOONGSON2_MMC_DELAY_RD GENMASK(15, 8) + +#define LOONGSON2_MMC_SEL_DATA BIT(0)/* 0: SDR, 1: DDR */ +#define LOONGSON2_MMC_SEL_BUS BIT(0)/* 0: EMMC, 1: SDIO */ + +/* Internal dma controller registers */ + +/* Bitfields of Global Configuration Register */ +#define LOONGSON2_MMC_DMA_64BIT_EN BIT(0)/* 1: 64 bit support */ +#define LOONGSON2_MMC_DMA_UNCOHERENT_EN BIT(1)/* 0: cache, 1: uncache */ +#define LOONGSON2_MMC_DMA_ASK_VALID BIT(2) +#define LOONGSON2_MMC_DMA_START BIT(3)/* DMA start operation */ +#define LOONGSON2_MMC_DMA_STOP BIT(4)/* DMA stop operation */ +#define LOONGSON2_MMC_DMA_CONFIG_MASK GENMASK_ULL(4, 0)/* DMA controller config bits mask */ + +/* Bitfields of ndesc_addr field of HW descriptor */ +#define LOONGSON2_MMC_DMA_DESC_EN BIT(0)/*1: The next descriptor is valid */ +#define LOONGSON2_MMC_DMA_DESC_ADDR_LOW GENMASK(31, 1) + +/* Bitfields of cmd field of HW descriptor */ +#define LOONGSON2_MMC_DMA_INT BIT(1)/* Enable DMA interrupts */ +#define LOONGSON2_MMC_DMA_DATA_DIR BIT(12)/* 1: write to device, 0: read from device */ + +#define LOONGSON2_MMC_DLLVAL_TIMEOUT_US 4000 +#define LOONGSON2_MMC_TXFULL_TIMEOUT_US 500 +/* Loongson-2K1000 SDIO2 DMA routing register */ #define LS2K1000_SDIO_DMA_MASK GENMASK(17, 15)#define LS2K1000_DMA0_CONF 0x0
@@ -159,6 +212,20 @@ enum loongson2_mmc_state { STATE_XFERFINISH_RSPFIN, }; +struct loongson2_dma_desc { +u32 ndesc_addr; +u32 mem_addr; +u32 apb_addr; +u32 len; +u32 step_len; +u32 step_times; +u32 cmd; +u32 stats; +u32 high_ndesc_addr; +u32 high_mem_addr; +u32 reserved[2 ]; +} __packed; +struct loongson2_mmc_host {struct device *dev;struct mmc_request *mrq;
@@ -166,6 +233,8 @@ struct loongson2_mmc_host {struct resource *res;struct clk *clk;u32 current_clk; +void *sg_cpu; +dma_addr_t sg_dma;int dma_complete;struct dma_chan *chan;int cmd_is_stop;
@@ -178,6 +247,7 @@ struct loongson2_mmc_host {struct loongson2_mmc_pdata {const struct regmap_config *regmap_config;void (*reorder_cmd_data)(struct loongson2_mmc_host *host,struct mmc_command *cmd); +void (*fix_data_timeout)(struct loongson2_mmc_host *host,struct mmc_command *cmd);int (*setting_dma)(struct loongson2_mmc_host *host,struct platform_device *pdev);int (*prepare_dma)(struct loongson2_mmc_host *host,struct mmc_data *data);void (*release_dma)(struct loongson2_mmc_host *host,struct device *dev);
@@ -268,6 +338,9 @@ static void loongson2_mmc_send_request(struct mmc_host *mmc)return ; } +if (host->pdata->fix_data_timeout) + host->pdata->fix_data_timeout (host, cmd); +loongson2_mmc_send_command (host, cmd);/* Fix deselect card */
@@ -410,6 +483,37 @@ static irqreturn_t loongson2_mmc_irq(int irq, void *devid)return IRQ_WAKE_THREAD ; } +static void loongson2_mmc_dll_mode_init (struct loongson2_mmc_host *host) +{ +u32 val, pad_delay, delay, ret; + +regmap_update_bits (host->regmap,LOONGSON2_MMC_REG_SEL , +LOONGSON2_MMC_SEL_DATA ,LOONGSON2_MMC_SEL_DATA ); + + val =FIELD_PREP (LOONGSON2_MMC_DLLCTL_TIME ,0xc8 ) + |FIELD_PREP (LOONGSON2_MMC_DLLCTL_INCRE ,0x1 ) + |FIELD_PREP (LOONGSON2_MMC_DLLCTL_START ,0x1 ) + |FIELD_PREP (LOONGSON2_MMC_DLLCTL_CLK_MODE ,0x1 ) + |FIELD_PREP (LOONGSON2_MMC_DLLCTL_START_BIT ,0x1 ) + |FIELD_PREP (LOONGSON2_MMC_DLLCTL_TIME_BPASS ,0xf ); + +regmap_write (host->regmap,LOONGSON2_MMC_REG_DLLCTL , val); + + ret =regmap_read_poll_timeout (host->regmap,LOONGSON2_MMC_REG_DLLVAL , val, + (val &LOONGSON2_MMC_DLLVAL_DONE ),0 , +LOONGSON2_MMC_DLLVAL_TIMEOUT_US ); +if (ret <0 ) +return ; + +regmap_read (host->regmap,LOONGSON2_MMC_REG_DLLVAL , &val); + pad_delay =FIELD_GET (GENMASK (7 ,1 ), val); + + delay =FIELD_PREP (LOONGSON2_MMC_DELAY_PAD , pad_delay) + |FIELD_PREP (LOONGSON2_MMC_DELAY_RD , pad_delay +1 ); + +regmap_write (host->regmap,LOONGSON2_MMC_REG_DELAY , delay); +} +static void loongson2_mmc_set_clk (struct loongson2_mmc_host *host,struct mmc_ios *ios) {u32 pre;
@@ -422,6 +526,10 @@ static void loongson2_mmc_set_clk(struct loongson2_mmc_host *host, struct mmc_ioregmap_update_bits (host->regmap,LOONGSON2_MMC_REG_CTL ,LOONGSON2_MMC_CTL_ENCLK ,LOONGSON2_MMC_CTL_ENCLK ); + +/* EMMC DLL mode setting */ +if (ios->timing ==MMC_TIMING_UHS_DDR50 || ios->timing ==MMC_TIMING_MMC_DDR52 ) +loongson2_mmc_dll_mode_init (host); }static void loongson2_mmc_set_ios (struct mmc_host *mmc,struct mmc_ios *ios)
@@ -634,6 +742,128 @@ static struct loongson2_mmc_pdata ls2k1000_mmc_pdata = { .release_dma = loongson2_mmc_release_external_dma, }; +static const struct regmap_config ls2k2000_mmc_regmap_config = { + .reg_bits =32 , + .val_bits =32 , + .reg_stride =4 , + .max_register =LOONGSON2_MMC_REG_RDMA_HI , +}; + +static void ls2k2000_mmc_reorder_cmd_data (struct loongson2_mmc_host *host, +struct mmc_command *cmd) +{ +struct scatterlist *sg; +u32 *data; +int i, j; + +if (cmd->opcode !=SD_SWITCH ||mmc_cmd_type (cmd) !=MMC_CMD_ADTC ) +return ; + +for_each_sg (cmd->data->sg, sg, cmd->data->sg_len, i) { + data =sg_virt (&sg[i]); +for (j =0 ; j < (sg_dma_len (&sg[i]) /4 ); j++) + data[j] =bitrev8x4 (data[j]); + } +} + +/* +* This is a controller hardware defect. Single/multiple block write commands +* must be sent after the TX FULL flag is set, otherwise a data timeout interrupt +* will occur. +*/ +static void ls2k2000_mmc_fix_data_timeout (struct loongson2_mmc_host *host, +struct mmc_command *cmd) +{ +int val; + +if (cmd->opcode !=MMC_WRITE_BLOCK && cmd->opcode !=MMC_WRITE_MULTIPLE_BLOCK ) +return ; + +regmap_read_poll_timeout (host->regmap,LOONGSON2_MMC_REG_FSTS , val, + (val &LOONGSON2_MMC_FSTS_TXFULL ),0 , +LOONGSON2_MMC_TXFULL_TIMEOUT_US ); +} + +static int loongson2_mmc_prepare_internal_dma (struct loongson2_mmc_host *host, +struct mmc_data *data) +{ +struct loongson2_dma_desc *pdes = (struct loongson2_dma_desc *)host->sg_cpu; +struct mmc_host *mmc =mmc_from_priv (host); +dma_addr_t next_desc = host->sg_dma; +struct scatterlist *sg; +int reg_lo, reg_hi; +u64 dma_order; +int i, ret; + + ret =dma_map_sg (mmc_dev (mmc), data->sg, data->sg_len, +mmc_get_dma_dir (data)); +if (!ret) +return -ENOMEM ; + +for_each_sg (data->sg, sg, data->sg_len, i) { + pdes[i].len =sg_dma_len (&sg[i]) /4 ; + pdes[i].step_len =0 ; + pdes[i].step_times =1 ; + pdes[i].mem_addr =lower_32_bits (sg_dma_address (&sg[i])); + pdes[i].high_mem_addr =upper_32_bits (sg_dma_address (&sg[i])); + pdes[i].apb_addr = host->res->start +LOONGSON2_MMC_REG_DATA ; + pdes[i].cmd =LOONGSON2_MMC_DMA_INT ; + +if (data->flags &MMC_DATA_READ ) { + reg_lo =LOONGSON2_MMC_REG_RDMA_LO ; + reg_hi =LOONGSON2_MMC_REG_RDMA_HI ; + }else { + pdes[i].cmd |=LOONGSON2_MMC_DMA_DATA_DIR ; + reg_lo =LOONGSON2_MMC_REG_WDMA_LO ; + reg_hi =LOONGSON2_MMC_REG_WDMA_HI ; + } + + next_desc +=sizeof (struct loongson2_dma_desc ); + pdes[i].ndesc_addr =lower_32_bits (next_desc) | +LOONGSON2_MMC_DMA_DESC_EN ; + pdes[i].high_ndesc_addr =upper_32_bits (next_desc); + } + +/* Setting the last descriptor enable bit */ + pdes[i -1 ].ndesc_addr &= ~LOONGSON2_MMC_DMA_DESC_EN ; + + dma_order = (host->sg_dma & ~LOONGSON2_MMC_DMA_CONFIG_MASK ) | +LOONGSON2_MMC_DMA_64BIT_EN | +LOONGSON2_MMC_DMA_START ; + +regmap_write (host->regmap, reg_hi,upper_32_bits (dma_order)); +regmap_write (host->regmap, reg_lo,lower_32_bits (dma_order)); + +return 0 ; +} + +static int loongson2_mmc_set_internal_dma (struct loongson2_mmc_host *host, +struct platform_device *pdev) +{ + host->sg_cpu =dma_alloc_coherent (&pdev->dev,PAGE_SIZE , + &host->sg_dma,GFP_KERNEL ); +if (!host->sg_cpu) +return -ENOMEM ; + +memset (host->sg_cpu,0 ,PAGE_SIZE ); +return 0 ; +} + +static void loongson2_mmc_release_internal_dma (struct loongson2_mmc_host *host, +struct device *dev) +{ +dma_free_coherent (dev,PAGE_SIZE , host->sg_cpu, host->sg_dma); +} + +static struct loongson2_mmc_pdata ls2k2000_mmc_pdata = { + .regmap_config = &ls2k2000_mmc_regmap_config, + .reorder_cmd_data = ls2k2000_mmc_reorder_cmd_data, + .fix_data_timeout = ls2k2000_mmc_fix_data_timeout, + .setting_dma = loongson2_mmc_set_internal_dma, + .prepare_dma = loongson2_mmc_prepare_internal_dma, + .release_dma = loongson2_mmc_release_internal_dma, +}; +static int loongson2_mmc_resource_request (struct platform_device *pdev,struct loongson2_mmc_host *host) {
@@ -756,6 +986,7 @@ static void loongson2_mmc_remove(struct platform_device *pdev)static const struct of_device_id loongson2_mmc_of_ids[] = { { .compatible ="loongson,ls2k0500-mmc" , .data = &ls2k0500_mmc_pdata }, { .compatible ="loongson,ls2k1000-mmc" , .data = &ls2k1000_mmc_pdata }, + { .compatible ="loongson,ls2k2000-mmc" , .data = &ls2k2000_mmc_pdata }, { }, };MODULE_DEVICE_TABLE (of, loongson2_mmc_of_ids);
Signature · 1 line
2.47.1
Hi, Binbin,
Quoted 26 lines · Binbin Zhou
Hi all:
This patchset introduce the MMC host controller on Loongson-2K series CPUs.
They are similar, except for the interface characteristics and the use of DMA engine, specifically, the Loongson-2K0500/Loongson-2K1000 use an externally shared APBDMA engine, while the Loongson-2K2000 uses an internally exclusive DMA.
Based on this, I'm splitting the driver into two patches.
List of the patchset:
Patch1: bindings for Loongson-2K0500/Loongson-2K1000;
Patch2: driver for MMC controller using externally shared APBDMA engine;
Patch3: bindings for Loongson-2K2000;
Patch4: driver for MMC controller using internally exclusive DMA.Thanks.
-------
V4:
patch(2/4):
- Code formatting;
- Fix lkp error
Quoted 4 lines
https://lore.kernel.org/all/[email protected]/ patch(4/4): - Rename function names: ls2k1000_mmc_regmap_config -> ls2k0500_mmc_regmap_config
In Patch-1 there is still ls2k1000_mmc_regmap_config(), others look good to me.
Huacai
Quoted 62 lines
loongson2_mmc_reorder_cmd_data -> ls2k0500_mmc_reorder_cmd_data loongson2_mmc_set_internal_dma -> ls2k2000_mmc_set_internal_dma- Use macro definitions for magic numbers.
Link to V3:
https://lore.kernel.org/all/[email protected]/V3:
patch(1/4):
- Rename dt-binding file as loongson,ls2k0500-mmc.yaml.
patch(2/4):- Fix lkp error; https://lore.kernel.org/all/[email protected]/- Add regulators support for ios ops;
- Addack_sdio_irq()callback;
- AddMMC_CAP2_SDIO_IRQ_NOTHREADflag;
patch(3/4):
- Add Ack-by tag.
patch(4/4):
- Update commit forfix_data_timeout().Link to V2:
https://lore.kernel.org/all/[email protected]/V2:
patch(1/4):
- Add reg define for each reg entry.patch(2/4):
- Put all code in the c-file;
- Usemmc_from_priv()instead ofhost->mmc;
- Usesdio_signal_irq()instead ofmmc_signal_sdio_irq();
- Usedevm_mmc_alloc_host()instead ofmmc_alloc_host();
- Usemmc_regulator_get_supply();patch(4/4):
- Addfix_cmd_interruptfunction which is needed by Loongson-2K2000.Link to V1:
https://lore.kernel.org/linux-mmc/[email protected]/Binbin Zhou (4):
dt-bindings: mmc: Add Loongson-2K SD/SDIO/eMMC controller binding
mmc: loongson2: Add Loongson-2K SD/SDIO controller driver
dt-bindings: mmc: loongson,ls2k0500-mmc: Add compatible forLoongson-2K2000mmc: loongson2: Add Loongson-2K2000 SD/SDIO/eMMC controller driver
.../bindings/mmc/loongson,ls2k0500-mmc.yaml | 112 ++ MAINTAINERS | 7 + drivers/mmc/host/Kconfig | 13 + drivers/mmc/host/Makefile | 1 + drivers/mmc/host/loongson2-mmc.c | 1029 +++++++++++++++++ 5 files changed, 1162 insertions(+) create mode 100644 Documentation/devicetree/bindings/mmc/loongson,ls2k0500-mmc.yaml create mode 100644 drivers/mmc/host/loongson2-mmc.cbase-commit:
f5c755ef810009b85350884c483705bd04365370--
2.47.1
Re: [PATCH v4 1/4] dt-bindings: mmc: Add Loongson-2K SD/SDIO/eMMC controller binding
In reply to Binbin ZhouQuoted 10 lines · Binbin Zhou
Add the Loongson-2K SoC's SD/SDIO/eMMC controller binding with DT schema format using json-schema.
Signed-off-by Binbin Zhou <[email protected]>--- .../bindings/mmc/loongson,ls2k0500-mmc.yaml | 69 +++++++++++++++++++ MAINTAINERS | 6 ++ 2 files changed, 75 insertions(+) create mode 100644 Documentation/devicetree/bindings/mmc/loongson,ls2k0500-mmc.yaml
Quoted 88 lines · Binbin Zhou
Hi all:
This patchset introduce the MMC host controller on Loongson-2K series CPUs.
They are similar, except for the interface characteristics and the use of DMA engine, specifically, the Loongson-2K0500/Loongson-2K1000 use an externally shared APBDMA engine, while the Loongson-2K2000 uses an internally exclusive DMA.
Based on this, I'm splitting the driver into two patches.
List of the patchset:
Patch1: bindings for Loongson-2K0500/Loongson-2K1000;
Patch2: driver for MMC controller using externally shared APBDMA engine;
Patch3: bindings for Loongson-2K2000;
Patch4: driver for MMC controller using internally exclusive DMA.Thanks.
-------
V4:
patch(2/4):
- Code formatting;
- Fix lkp errorhttps://lore.kernel.org/all/[email protected]/ patch(4/4): - Rename function names: ls2k1000_mmc_regmap_config -> ls2k0500_mmc_regmap_config loongson2_mmc_reorder_cmd_data -> ls2k0500_mmc_reorder_cmd_data loongson2_mmc_set_internal_dma -> ls2k2000_mmc_set_internal_dma- Use macro definitions for magic numbers.
Link to V3:
https://lore.kernel.org/all/[email protected]/V3:
patch(1/4):
- Rename dt-binding file as loongson,ls2k0500-mmc.yaml.
patch(2/4):- Fix lkp error; https://lore.kernel.org/all/[email protected]/- Add regulators support for ios ops;
- Addack_sdio_irq()callback;
- AddMMC_CAP2_SDIO_IRQ_NOTHREADflag;
patch(3/4):
- Add Ack-by tag.
patch(4/4):
- Update commit forfix_data_timeout().Link to V2:
https://lore.kernel.org/all/[email protected]/V2:
patch(1/4):
- Add reg define for each reg entry.patch(2/4):
- Put all code in the c-file;
- Usemmc_from_priv()instead ofhost->mmc;
- Usesdio_signal_irq()instead ofmmc_signal_sdio_irq();
- Usedevm_mmc_alloc_host()instead ofmmc_alloc_host();
- Usemmc_regulator_get_supply();patch(4/4):
- Addfix_cmd_interruptfunction which is needed by Loongson-2K2000.Link to V1:
https://lore.kernel.org/linux-mmc/[email protected]/Binbin Zhou (4):
dt-bindings: mmc: Add Loongson-2K SD/SDIO/eMMC controller binding
mmc: loongson2: Add Loongson-2K SD/SDIO controller driver
dt-bindings: mmc: loongson,ls2k0500-mmc: Add compatible forLoongson-2K2000mmc: loongson2: Add Loongson-2K2000 SD/SDIO/eMMC controller driver
.../bindings/mmc/loongson,ls2k0500-mmc.yaml | 112 ++ MAINTAINERS | 7 + drivers/mmc/host/Kconfig | 13 + drivers/mmc/host/Makefile | 1 + drivers/mmc/host/loongson2-mmc.c | 1029 +++++++++++++++++ 5 files changed, 1162 insertions(+) create mode 100644 Documentation/devicetree/bindings/mmc/loongson,ls2k0500-mmc.yaml create mode 100644 drivers/mmc/host/loongson2-mmc.c
Quoted 5 lines
base-commit:
f5c755ef810009b85350884c483705bd04365370--
2.47.1
The series applied for next, thanks!
Note, I am leaving you to address/discuss Huacai's comment on patch1 as a new patch on top.
Kind regards
Uffe
Huacai Chen
maintainerQuoted 96 lines · Ulf Hansson
Quoted 88 lines · Binbin Zhou
Hi all:
This patchset introduce the MMC host controller on Loongson-2K series CPUs.
They are similar, except for the interface characteristics and the use of DMA engine, specifically, the Loongson-2K0500/Loongson-2K1000 use an externally shared APBDMA engine, while the Loongson-2K2000 uses an internally exclusive DMA.
Based on this, I'm splitting the driver into two patches.
List of the patchset:
Patch1: bindings for Loongson-2K0500/Loongson-2K1000;
Patch2: driver for MMC controller using externally shared APBDMA engine;
Patch3: bindings for Loongson-2K2000;
Patch4: driver for MMC controller using internally exclusive DMA.Thanks.
-------
V4:
patch(2/4):
- Code formatting;
- Fix lkp errorhttps://lore.kernel.org/all/[email protected]/ patch(4/4): - Rename function names: ls2k1000_mmc_regmap_config -> ls2k0500_mmc_regmap_config loongson2_mmc_reorder_cmd_data -> ls2k0500_mmc_reorder_cmd_data loongson2_mmc_set_internal_dma -> ls2k2000_mmc_set_internal_dma- Use macro definitions for magic numbers.
Link to V3:
https://lore.kernel.org/all/[email protected]/V3:
patch(1/4):
- Rename dt-binding file as loongson,ls2k0500-mmc.yaml.
patch(2/4):- Fix lkp error; https://lore.kernel.org/all/[email protected]/- Add regulators support for ios ops;
- Addack_sdio_irq()callback;
- AddMMC_CAP2_SDIO_IRQ_NOTHREADflag;
patch(3/4):
- Add Ack-by tag.
patch(4/4):
- Update commit forfix_data_timeout().Link to V2:
https://lore.kernel.org/all/[email protected]/V2:
patch(1/4):
- Add reg define for each reg entry.patch(2/4):
- Put all code in the c-file;
- Usemmc_from_priv()instead ofhost->mmc;
- Usesdio_signal_irq()instead ofmmc_signal_sdio_irq();
- Usedevm_mmc_alloc_host()instead ofmmc_alloc_host();
- Usemmc_regulator_get_supply();patch(4/4):
- Addfix_cmd_interruptfunction which is needed by Loongson-2K2000.Link to V1:
https://lore.kernel.org/linux-mmc/[email protected]/Binbin Zhou (4):
dt-bindings: mmc: Add Loongson-2K SD/SDIO/eMMC controller binding
mmc: loongson2: Add Loongson-2K SD/SDIO controller driver
dt-bindings: mmc: loongson,ls2k0500-mmc: Add compatible forLoongson-2K2000mmc: loongson2: Add Loongson-2K2000 SD/SDIO/eMMC controller driver
.../bindings/mmc/loongson,ls2k0500-mmc.yaml | 112 ++ MAINTAINERS | 7 + drivers/mmc/host/Kconfig | 13 + drivers/mmc/host/Makefile | 1 + drivers/mmc/host/loongson2-mmc.c | 1029 +++++++++++++++++ 5 files changed, 1162 insertions(+) create mode 100644 Documentation/devicetree/bindings/mmc/loongson,ls2k0500-mmc.yaml create mode 100644 drivers/mmc/host/loongson2-mmc.cQuoted 5 lines
base-commit:
f5c755ef810009b85350884c483705bd04365370--
2.47.1
Quoted 4 lines
The series applied for next, thanks!
Note, I am leaving you to address/discuss Huacai's comment on patch1 as a new patch on top.
Hmmm, if possible, I prefer Binbin to send a clean v5 with that modification. Or you modify it by yourself when applying.
Huacai
Quoted 3 lines
Kind regards
Uffe
Quoted 98 lines · Huacai Chen
Quoted 96 lines · Ulf Hansson
Quoted 93 lines · Binbin Zhou
Hi all:
This patchset introduce the MMC host controller on Loongson-2K series CPUs.
They are similar, except for the interface characteristics and the use of DMA engine, specifically, the Loongson-2K0500/Loongson-2K1000 use an externally shared APBDMA engine, while the Loongson-2K2000 uses an internally exclusive DMA.
Based on this, I'm splitting the driver into two patches.
List of the patchset:
Patch1: bindings for Loongson-2K0500/Loongson-2K1000;
Patch2: driver for MMC controller using externally shared APBDMA engine;
Patch3: bindings for Loongson-2K2000;
Patch4: driver for MMC controller using internally exclusive DMA.Thanks.
-------
V4:
patch(2/4):
- Code formatting;
- Fix lkp errorhttps://lore.kernel.org/all/[email protected]/ patch(4/4): - Rename function names: ls2k1000_mmc_regmap_config -> ls2k0500_mmc_regmap_config loongson2_mmc_reorder_cmd_data -> ls2k0500_mmc_reorder_cmd_data loongson2_mmc_set_internal_dma -> ls2k2000_mmc_set_internal_dma- Use macro definitions for magic numbers.
Link to V3:
https://lore.kernel.org/all/[email protected]/V3:
patch(1/4):
- Rename dt-binding file as loongson,ls2k0500-mmc.yaml.
patch(2/4):- Fix lkp error; https://lore.kernel.org/all/[email protected]/- Add regulators support for ios ops;
- Addack_sdio_irq()callback;
- AddMMC_CAP2_SDIO_IRQ_NOTHREADflag;
patch(3/4):
- Add Ack-by tag.
patch(4/4):
- Update commit forfix_data_timeout().Link to V2:
https://lore.kernel.org/all/[email protected]/V2:
patch(1/4):
- Add reg define for each reg entry.patch(2/4):
- Put all code in the c-file;
- Usemmc_from_priv()instead ofhost->mmc;
- Usesdio_signal_irq()instead ofmmc_signal_sdio_irq();
- Usedevm_mmc_alloc_host()instead ofmmc_alloc_host();
- Usemmc_regulator_get_supply();patch(4/4):
- Addfix_cmd_interruptfunction which is needed by Loongson-2K2000.Link to V1:
https://lore.kernel.org/linux-mmc/[email protected]/Binbin Zhou (4):
dt-bindings: mmc: Add Loongson-2K SD/SDIO/eMMC controller binding
mmc: loongson2: Add Loongson-2K SD/SDIO controller driver
dt-bindings: mmc: loongson,ls2k0500-mmc: Add compatible forLoongson-2K2000mmc: loongson2: Add Loongson-2K2000 SD/SDIO/eMMC controller driver
.../bindings/mmc/loongson,ls2k0500-mmc.yaml | 112 ++ MAINTAINERS | 7 + drivers/mmc/host/Kconfig | 13 + drivers/mmc/host/Makefile | 1 + drivers/mmc/host/loongson2-mmc.c | 1029 +++++++++++++++++ 5 files changed, 1162 insertions(+) create mode 100644 Documentation/devicetree/bindings/mmc/loongson,ls2k0500-mmc.yaml create mode 100644 drivers/mmc/host/loongson2-mmc.cbase-commit:
f5c755ef810009b85350884c483705bd04365370--
2.47.1
Quoted 6 lines
Quoted 4 lines
The series applied for next, thanks!
Note, I am leaving you to address/discuss Huacai's comment on patch1 as a new patch on top.
Hmmm, if possible, I prefer Binbin to send a clean v5 with that modification. Or you modify it by yourself when applying.
Sorry, the patch has already been applied and I didn't think a variable rename was that big of a deal.
Please just post a patch on top and I will happily apply it.
Kind regards
Uffe