mmc: dw_mmc: add dw_mmc-k3
v2 cover mmc: dw_mmc: add dw_mmc-k3
v2:
Follow Jaehoon's suggestion
Use slot-gpio.c handle cd pin
Move table out to dts
other suggestion
Zhangfei Gao (2):
mmc: dw_mmc: add dw_mci_of_get_cd_gpio to handle cd pin
mmc: dw_mmc: add dw_mmc-k3 for k3 platform
.../devicetree/bindings/mmc/k3-dw-mshc.txt | 77 +++++ drivers/mmc/host/Kconfig | 10 + drivers/mmc/host/Makefile | 1 + drivers/mmc/host/dw_mmc-k3.c | 298 ++++++++++++++++++++ drivers/mmc/host/dw_mmc.c | 34 +++ 5 files changed, 420 insertions(+) create mode 100644 Documentation/devicetree/bindings/mmc/k3-dw-mshc.txt create mode 100644 drivers/mmc/host/dw_mmc-k3.c
Signature · 1 line
1.7.9.5
PATCH v2 1/2 mmc: dw_mmc: add dw_mci_of_get_cd_gpio to handle cd pin
Add function dw_mci_of_get_cd_gpio to check "cd-gpios" from dts. mmc_gpio_request_cd and mmc_gpio_get_cd are used to handle cd pin
--- drivers/mmc/host/dw_mmc.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)
drivers/mmc/host/dw_mmc.c +34 -0
@@ -35,6 +35,7 @@#include <linux/workqueue.h> #include <linux/of.h> #include <linux/of_gpio.h> +#include <linux/mmc/slot-gpio.h> #include "dw_mmc.h"
@@ -872,12 +873,15 @@ static int dw_mci_get_cd(struct mmc_host *mmc)int present;struct dw_mci_slot *slot =mmc_priv (mmc);struct dw_mci_board *brd = slot->host->pdata; +int gpio_cd = !mmc_gpio_get_cd (mmc);/* Use platform get_cd function, else try onboard card detect */ if (brd->quirks &DW_MCI_QUIRK_BROKEN_CARD_DETECTION ) present =1 ;else if (brd->get_cd) present = !brd->get_cd (slot->id); +else if (!IS_ERR_VALUE (gpio_cd)) + present = !!gpio_cd;else present = (mci_readl (slot->host,CDETECT ) & (1 << slot->id)) ==0 ?1 :0 ;
@@ -1876,6 +1880,30 @@ static int dw_mci_of_get_wp_gpio(struct device *dev, u8 slot) return gpio; } + +/* find the cd gpio for a given slot; or -1 if none specified */ +static int dw_mci_of_get_cd_gpio (struct device *dev,u8 slot, +struct mmc_host *mmc) +{ +struct device_node *np =dw_mci_of_find_slot_node (dev, slot); +int gpio; + +if (!np) +return -EINVAL ; + + gpio =of_get_named_gpio (np,"cd-gpios" ,0 ); + +/* Having a missing entry is valid; return silently */ +if (!gpio_is_valid (gpio)) +return -EINVAL ; + +if (mmc_gpio_request_cd (mmc, gpio,0 )) { +dev_warn (dev,"gpio [%d] request failed\n" , gpio); +return -EINVAL ; + } + +return gpio; +}#else /* CONFIG_OF */ static int dw_mci_of_get_slot_quirks (struct device *dev,u8 slot) {
@@ -1893,6 +1921,11 @@ static int dw_mci_of_get_wp_gpio(struct device *dev, u8 slot) {return -EINVAL ; } +static int dw_mci_of_get_cd_gpio (struct device *dev,u8 slot, +struct mmc_host *mmc) +{ +return -EINVAL ; +}#endif /* CONFIG_OF */ static int dw_mci_init_slot (struct dw_mci *host,unsigned int id)
@@ -1996,6 +2029,7 @@ static int dw_mci_init_slot(struct dw_mci *host, unsigned int id)clear_bit (DW_MMC_CARD_PRESENT , &slot->flags); slot->wp_gpio =dw_mci_of_get_wp_gpio (host->dev, slot->id); +dw_mci_of_get_cd_gpio (host->dev, slot->id, mmc); ret =mmc_add_host (mmc);if (ret)
Signature · 1 line
1.7.9.5
PATCH v2 2/2 mmc: dw_mmc: add dw_mmc-k3 for k3 platform
In reply to Zhangfei GaoAdd dw_mmc-k3.c for k3v2, support sd/emmc
--- .../devicetree/bindings/mmc/k3-dw-mshc.txt | 77 +++++ drivers/mmc/host/Kconfig | 10 + drivers/mmc/host/Makefile | 1 + drivers/mmc/host/dw_mmc-k3.c | 298 ++++++++++++++++++++ 4 files changed, 386 insertions(+) create mode 100644 Documentation/devicetree/bindings/mmc/k3-dw-mshc.txt create mode 100644 drivers/mmc/host/dw_mmc-k3.c
Documentation/devicetree/bindings/mmc/k3-dw-mshc.txt new file +77 -0
@@ -0,0 +1,77 @@ +* Hisilicon specific extensions to the Synopsys Designware Mobile + Storage Host Controller + +Read synopsis-dw-mshc.txt for more details +The Synopsys designware mobile storage host controller is used to interface +a SoC with storage medium such as eMMC or SD/MMC cards. This file documents +differences between the core Synopsys dw mshc controller properties described +by synopsis-dw-mshc.txt and the properties used by the Hisilicon specific +extensions to the Synopsys Designware Mobile Storage Host Controller. + +Required Properties: + +* compatible: should be + - "hisilicon,hi4511-dw-mshc": for controllers with hi4511 + specific extentions. +* vmmc-supply: should be vmmc used in dwmmc +* fifo-depth: should be provided if register can not provide correct value +* clken-reg: should be clock enable register and offset +* drv-sel-reg: should be driver delay select register, offset and bits +* sam-sel-reg: should be sample delay select register, offset and bits +* div-reg: should be divider register, offset and bits +* tune-table: should be array of clock tune mmc controller + +Example: + + The MSHC controller node can be split into two portions, SoC specific and + board specific portions as listed below. + + dwmmc_0: dwmmc0 at fcd03000 { + compatible = "hisilicon,hi4511-dw-mshc"; + reg = <0xfcd03000 0x1000>; + interrupts = <0 16 4>; + #address-cells = <1>; + #size-cells = <0>; + clocks = <&clk_sd>, <&clk_ddrc_per>; + clock-names = "ciu", "biu"; + clken-reg = <0x1f8 0>; + drv-sel-reg = <0x1f8 4 4>; + sam-sel-reg = <0x1f8 8 4>; + div-reg = <0x1f8 1 3>; + tune-table = + <180000000 6 6 13 13 25000000>, + <0 0 0 0 0 0>, + <360000000 6 4 2 0 50000000>, + <180000000 6 4 13 13 25000000>, + <360000000 6 4 2 0 50000000>, + <720000000 6 1 9 4 100000000>, + <0 0 0 0 0 0>, + <360000000 7 1 3 0 50000000>; + }; + dwmmc0 at fcd03000 { + num-slots = <1>; + vmmc-supply = <&ldo12>; + fifo-depth = <0x100>; + supports-highspeed; + pinctrl-names = "default"; + pinctrl-0 = <&sd_pmx_pins &sd_cfg_func1 &sd_cfg_func2>; + slot at 0 { + reg = <0>; + bus-width = <4>; + disable-wp; + cd-gpios = <&gpio10 3 0>; + }; + }; + +PCTRL: + +Required Properties: +* compatible: should be + - "hisilicon,pctrl": Peripheral control + +Example: + + pctrl: pctrl at fca09000 { + compatible = "hisilicon,pctrl"; + reg = <0xfca09000 0x1000>; + };
drivers/mmc/host/Kconfig +10 -0
@@ -575,6 +575,16 @@ config MMC_DW_SOCFPGA This selects support for Altera SoCFPGA specific extensions to the Synopsys DesignWare Memory Card Interface driver. +config MMC_DW_K3 + tristate "K3 specific extensions for Synopsys DW Memory Card Interface" + depends on MMC_DW + select MMC_DW_PLTFM + select MMC_DW_IDMAC + help + This selects support for Hisilicon K3 SoC specific extensions to the + Synopsys DesignWare Memory Card Interface driver. Select this option + for platforms based on Hisilicon K3 SoC's. + config MMC_DW_PCI tristate "Synopsys Designware MCI support on PCI bus" depends on MMC_DW && PCI
drivers/mmc/host/Makefile +1 -0
@@ -43,6 +43,7 @@ obj-$(CONFIG_MMC_DW) += dw_mmc.o obj-$(CONFIG_MMC_DW_PLTFM) += dw_mmc-pltfm.o obj-$(CONFIG_MMC_DW_EXYNOS) += dw_mmc-exynos.o obj-$(CONFIG_MMC_DW_SOCFPGA) += dw_mmc-socfpga.o +obj-$(CONFIG_MMC_DW_K3) += dw_mmc-k3.o obj-$(CONFIG_MMC_DW_PCI) += dw_mmc-pci.o obj-$(CONFIG_MMC_SH_MMCIF) += sh_mmcif.o obj-$(CONFIG_MMC_JZ4740) += jz4740_mmc.o
drivers/mmc/host/dw_mmc-k3.c new file +298 -0
298 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH v2 2/2 mmc: dw_mmc: add dw_mmc-k3 for k3 platform
update: fix typo
Add dw_mmc-k3.c for k3v2, support sd/emmc
--- .../devicetree/bindings/mmc/k3-dw-mshc.txt | 77 +++++ drivers/mmc/host/Kconfig | 10 + drivers/mmc/host/Makefile | 1 + drivers/mmc/host/dw_mmc-k3.c | 297 ++++++++++++++++++++ 4 files changed, 385 insertions(+) create mode 100644 Documentation/devicetree/bindings/mmc/k3-dw-mshc.txt create mode 100644 drivers/mmc/host/dw_mmc-k3.c
Documentation/devicetree/bindings/mmc/k3-dw-mshc.txt new file +77 -0
@@ -0,0 +1,77 @@ +* Hisilicon specific extensions to the Synopsys Designware Mobile + Storage Host Controller + +Read synopsis-dw-mshc.txt for more details +The Synopsys designware mobile storage host controller is used to interface +a SoC with storage medium such as eMMC or SD/MMC cards. This file documents +differences between the core Synopsys dw mshc controller properties described +by synopsis-dw-mshc.txt and the properties used by the Hisilicon specific +extensions to the Synopsys Designware Mobile Storage Host Controller. + +Required Properties: + +* compatible: should be + - "hisilicon,hi4511-dw-mshc": for controllers with hi4511 + specific extentions. +* vmmc-supply: should be vmmc used in dwmmc +* fifo-depth: should be provided if register can not provide correct value +* clken-reg: should be clock enable register and offset +* drv-sel-reg: should be driver delay select register, offset and bits +* sam-sel-reg: should be sample delay select register, offset and bits +* div-reg: should be divider register, offset and bits +* tune-table: should be array of clock tune mmc controller + +Example: + + The MSHC controller node can be split into two portions, SoC specific and + board specific portions as listed below. + + dwmmc_0: dwmmc0 at fcd03000 { + compatible = "hisilicon,hi4511-dw-mshc"; + reg = <0xfcd03000 0x1000>; + interrupts = <0 16 4>; + #address-cells = <1>; + #size-cells = <0>; + clocks = <&clk_sd>, <&clk_ddrc_per>; + clock-names = "ciu", "biu"; + clken-reg = <0x1f8 0>; + drv-sel-reg = <0x1f8 4 4>; + sam-sel-reg = <0x1f8 8 4>; + div-reg = <0x1f8 1 3>; + tune-table = + <180000000 6 6 13 13 25000000>, + <0 0 0 0 0 0>, + <360000000 6 4 2 0 50000000>, + <180000000 6 4 13 13 25000000>, + <360000000 6 4 2 0 50000000>, + <720000000 6 1 9 4 100000000>, + <0 0 0 0 0 0>, + <360000000 7 1 3 0 50000000>; + }; + dwmmc0 at fcd03000 { + num-slots = <1>; + vmmc-supply = <&ldo12>; + fifo-depth = <0x100>; + supports-highspeed; + pinctrl-names = "default"; + pinctrl-0 = <&sd_pmx_pins &sd_cfg_func1 &sd_cfg_func2>; + slot at 0 { + reg = <0>; + bus-width = <4>; + disable-wp; + cd-gpios = <&gpio10 3 0>; + }; + }; + +PCTRL: + +Required Properties: +* compatible: should be + - "hisilicon,pctrl": Peripheral control + +Example: + + pctrl: pctrl at fca09000 { + compatible = "hisilicon,pctrl"; + reg = <0xfca09000 0x1000>; + };
drivers/mmc/host/Kconfig +10 -0
@@ -575,6 +575,16 @@ config MMC_DW_SOCFPGA This selects support for Altera SoCFPGA specific extensions to the Synopsys DesignWare Memory Card Interface driver. +config MMC_DW_K3 + tristate "K3 specific extensions for Synopsys DW Memory Card Interface" + depends on MMC_DW + select MMC_DW_PLTFM + select MMC_DW_IDMAC + help + This selects support for Hisilicon K3 SoC specific extensions to the + Synopsys DesignWare Memory Card Interface driver. Select this option + for platforms based on Hisilicon K3 SoC's. + config MMC_DW_PCI tristate "Synopsys Designware MCI support on PCI bus" depends on MMC_DW && PCI
drivers/mmc/host/Makefile +1 -0
@@ -43,6 +43,7 @@ obj-$(CONFIG_MMC_DW) += dw_mmc.o obj-$(CONFIG_MMC_DW_PLTFM) += dw_mmc-pltfm.o obj-$(CONFIG_MMC_DW_EXYNOS) += dw_mmc-exynos.o obj-$(CONFIG_MMC_DW_SOCFPGA) += dw_mmc-socfpga.o +obj-$(CONFIG_MMC_DW_K3) += dw_mmc-k3.o obj-$(CONFIG_MMC_DW_PCI) += dw_mmc-pci.o obj-$(CONFIG_MMC_SH_MMCIF) += sh_mmcif.o obj-$(CONFIG_MMC_JZ4740) += jz4740_mmc.o
drivers/mmc/host/dw_mmc-k3.c new file +297 -0
297 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH 2/2 mmc: dw_mmc: add dw_mmc-k3 for k3 platform
Hi Zhangfei, just small changes,
Quoted 1 line · Zhangfei Gao
+* tune-table: should be array of clock tune mmc controller
This sounds like it should be "tuning-table", and shouldn't it also have a prefix?
drivers/mmc/host/dw_mmc-k3.c line 167
Quoted 2 lines
drivers/mmc/host/dw_mmc-k3.c new file +2
-0+ node =of_find_compatible_node (NULL ,NULL , +"hisilicon,pctrl" );
No need to use two lines here.
drivers/mmc/host/dw_mmc-k3.c line 194
Quoted 2 lines
drivers/mmc/host/dw_mmc-k3.c new file +2
-0+ ret =of_property_read_u32_array (np, +"clken-reg" , data,2 );
Or here, same with the other of_property_read_u32_array() calls.
drivers/mmc/host/dw_mmc-k3.c line 297
Quoted 3 lines
drivers/mmc/host/dw_mmc-k3.c new file +3
-0+MODULE_DESCRIPTION ("K3 Specific DW-MSHC Driver Extension" ); +MODULE_LICENSE ("GPL v2" ); +MODULE_ALIAS ("platform:dwmmc-k3" );
Can you add a MODULE_AUTHOR too?
Thanks,
- Chris.
Signature · 1 line
Chris Ball <[email protected]> <http://printf.net/>
PATCH 2/2 mmc: dw_mmc: add dw_mmc-k3 for k3 platform
In reply to Zhangfei GaoQuoted 34 lines · Zhangfei Gao
update: fix typo
Add
dw_mmc-k3.cfor k3v2, support sd/emmcSigned-off-by Zhangfei Gao <[email protected]>Tested-by Zhigang Wang <[email protected]>---
.../devicetree/bindings/mmc/k3-dw-mshc.txt | 77 +++++ drivers/mmc/host/Kconfig | 10 + drivers/mmc/host/Makefile | 1 + drivers/mmc/host/dw_mmc-k3.c | 297 ++++++++++++++++++++ 4 files changed, 385 insertions(+)create mode 100644
Documentation/devicetree/bindings/mmc/k3-dw-mshc.txtcreate mode 100644drivers/mmc/host/dw_mmc-k3.cDocumentation/devicetree/bindings/mmc/k3-dw-mshc.txt new file +13
-0@@ -0,0 +1,77 @@ +* Hisilicon specific extensions to the Synopsys Designware Mobile + Storage Host Controller + +Read synopsis-dw-mshc.txt for more details +The Synopsys designware mobile storage host controller is used to interface +a SoC with storage medium such as eMMC or SD/MMC cards. This file documents +differences between the core Synopsys dw mshc controller properties described +by synopsis-dw-mshc.txt and the properties used by the Hisilicon specific +extensions to the Synopsys Designware Mobile Storage Host Controller. + +Required Properties: + +* compatible: should be
Documentation/devicetree/bindings/mmc/k3-dw-mshc.txt line 23
Quoted 10 lines
Documentation/devicetree/bindings/mmc/k3-dw-mshc.txt new file +10
-0+ - "hisilicon,hi4511-dw-mshc": for controllers with hi4511 + specific extentions. +* vmmc-supply: should be vmmc used in dwmmc +* fifo-depth: should be provided if register can not provide correct value +* clken-reg: should be clock enable register and offset +* drv-sel-reg: should be driver delay select register, offset and bits +* sam-sel-reg: should be sample delay select register, offset and bits +* div-reg: should be divider register, offset and bits +* tune-table: should be array of clock tune mmc controller +
1. These should have vendor prefixes
2. why do we need the *-reg properties
3. for the *-reg properties its not clear what bits means?
4. tune-table is not well described, what does 'clock tune' mean, why an array?
Documentation/devicetree/bindings/mmc/k3-dw-mshc.txt line 28
Quoted 5 lines
Documentation/devicetree/bindings/mmc/k3-dw-mshc.txt new file +5
-0+Example: + + The MSHC controller node can be split into two portions, SoC specific and + board specific portions as listed below. +
Does dtc merge this all into a single node? Would probably be good to have comments in the example stating both that the merge into one node, and which is board and which is soc.
Quoted 29 lines
Documentation/devicetree/bindings/mmc/k3-dw-mshc.txt new file +29
-0+ dwmmc_0: dwmmc0 at fcd03000 { + compatible = "hisilicon,hi4511-dw-mshc"; + reg = <0xfcd03000 0x1000>; + interrupts = <0 16 4>; + #address-cells = <1>; + #size-cells = <0>; + clocks = <&clk_sd>, <&clk_ddrc_per>; + clock-names = "ciu", "biu"; + clken-reg = <0x1f8 0>; + drv-sel-reg = <0x1f8 4 4>; + sam-sel-reg = <0x1f8 8 4>; + div-reg = <0x1f8 1 3>; + tune-table = + <180000000 6 6 13 13 25000000>, + <0 0 0 0 0 0>, + <360000000 6 4 2 0 50000000>, + <180000000 6 4 13 13 25000000>, + <360000000 6 4 2 0 50000000>, + <720000000 6 1 9 4 100000000>, + <0 0 0 0 0 0>, + <360000000 7 1 3 0 50000000>; + }; + dwmmc0 at fcd03000 { + num-slots = <1>; + vmmc-supply = <&ldo12>; + fifo-depth = <0x100>; + supports-highspeed; + pinctrl-names = "default"; + pinctrl-0 = <&sd_pmx_pins &sd_cfg_func1 &sd_cfg_func2>;
Documentation/devicetree/bindings/mmc/k3-dw-mshc.txt line 67
Quoted 10 lines
Documentation/devicetree/bindings/mmc/k3-dw-mshc.txt new file +10
-0+ slot at 0 { + reg = <0>; + bus-width = <4>; + disable-wp; + cd-gpios = <&gpio10 3 0>; + }; + }; + +PCTRL: +
should have a description
Documentation/devicetree/bindings/mmc/k3-dw-mshc.txt line 71
Quoted 4 lines
Documentation/devicetree/bindings/mmc/k3-dw-mshc.txt new file +4
-0+Required Properties: +* compatible: should be + - "hisilicon,pctrl": Peripheral control +
Reg is not described as a required property.
Documentation/devicetree/bindings/mmc/k3-dw-mshc.txt line 77
Quoted 6 lines
Documentation/devicetree/bindings/mmc/k3-dw-mshc.txt new file +6
-0+Example: + + pctrl: pctrl at fca09000 { + compatible = "hisilicon,pctrl"; + reg = <0xfca09000 0x1000>; + };
This should be in its own binding document, and not part of the mmc binding
- k
Quoted 1 line
Signature · 2 lines
Employee of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
PATCH 2/2 mmc: dw_mmc: add dw_mmc-k3 for k3 platform
Dear Kumar
Thanks for the careful review.
Quoted 4 lines · Kumar Gala
On Oct 23, 2013, at 8:03 AM, Zhangfei Gao wrote:
Quoted 15 lines
Documentation/devicetree/bindings/mmc/k3-dw-mshc.txt line 23
Quoted 13 lines
Documentation/devicetree/bindings/mmc/k3-dw-mshc.txt new file +13
-0+Required Properties: + +* compatible: should be + - "hisilicon,hi4511-dw-mshc": for controllers with hi4511 + specific extentions. +* vmmc-supply: should be vmmc used in dwmmc +* fifo-depth: should be provided if register can not provide correct value +* clken-reg: should be clock enable register and offset +* drv-sel-reg: should be driver delay select register, offset and bits +* sam-sel-reg: should be sample delay select register, offset and bits +* div-reg: should be divider register, offset and bits +* tune-table: should be array of clock tune mmc controller +1. These should have vendor prefixes
However Olof and Mark once suggested not using prefix if vector is internally used.
Example before:
Quoted 3 lines
+ - #hisilicon,clkdiv-table-cells : the number of parameters after phandle in
+ hisilicon,clkdiv-table property.
+ - hisilicon,clkdiv-table : list of value that are used to configure clock
Olof:
For a binding that is your own, you don't need to prefix the properties. Prefixes are mostly used when adding new vendor-specific attributes to a common binding.
Mark:
People seem to be *very* keen on adding them for all bindings for some reason.
Quoted 2 lines
2. why do we need the *-reg properties
3. for the *-reg properties its not clear what bits means?
The silicon has some limitaiton to tune the clock timing according to working mode,
including driver delay, sample delay, and divider.
If not set even the host register may not read out.
The register in PCTRL described below,
And one register may contains sereral usage,
for example
mmc0: 0x1f8: bit 0 is clock en/dis, bit 1 ~ bit 3 controls div, bit 4~7 controls drv-sel, bit 8 ~11 controls sam-sel
mmc1: 0x1f8: bit 12 ~~
register, offset and bits stands for 0x1f8, start bit and how many bits. Is this fine?
Quoted 1 line
4. tune-table is not well described, what does 'clock tune' mean, why an array?
Will change to "tuning-table"
It is values used for computing these div, drv, sample register, Also contains system clock need to be set, and output clock output after PCTRL control.
Quoted 11 lines
Documentation/devicetree/bindings/mmc/k3-dw-mshc.txt line 28
Quoted 7 lines
Documentation/devicetree/bindings/mmc/k3-dw-mshc.txt new file +5
-0+Example: + + The MSHC controller node can be split into two portions, SoC specific and + board specific portions as listed below. +Does dtc merge this all into a single node? Would probably be good to have comments in the example stating both that the merge into one node, and which is board and which is soc.
OK, will add comments to distinguish dtsi for soc and dts for board.
Quoted 34 lines
Quoted 34 lines
Documentation/devicetree/bindings/mmc/k3-dw-mshc.txt new file +33
-0+ dwmmc_0: dwmmc0 at fcd03000 { + compatible = "hisilicon,hi4511-dw-mshc"; + reg = <0xfcd03000 0x1000>; + interrupts = <0 16 4>; + #address-cells = <1>; + #size-cells = <0>; + clocks = <&clk_sd>, <&clk_ddrc_per>; + clock-names = "ciu", "biu"; + clken-reg = <0x1f8 0>; + drv-sel-reg = <0x1f8 4 4>; + sam-sel-reg = <0x1f8 8 4>; + div-reg = <0x1f8 1 3>; + tune-table = + <180000000 6 6 13 13 25000000>, + <0 0 0 0 0 0>, + <360000000 6 4 2 0 50000000>, + <180000000 6 4 13 13 25000000>, + <360000000 6 4 2 0 50000000>, + <720000000 6 1 9 4 100000000>, + <0 0 0 0 0 0>, + <360000000 7 1 3 0 50000000>; + }; + dwmmc0 at fcd03000 { + num-slots = <1>; + vmmc-supply = <&ldo12>; + fifo-depth = <0x100>; + supports-highspeed; + pinctrl-names = "default"; + pinctrl-0 = <&sd_pmx_pins &sd_cfg_func1 &sd_cfg_func2>; + slot at 0 { + reg = <0>; + bus-width = <4>; + disable-wp;
Quoted 8 lines
Documentation/devicetree/bindings/mmc/k3-dw-mshc.txt line 67
Quoted 6 lines
Documentation/devicetree/bindings/mmc/k3-dw-mshc.txt new file +6
-0+ cd-gpios = <&gpio10 3 0>; + }; + }; + +PCTRL: +should have a description
OK.
Quoted 7 lines
Documentation/devicetree/bindings/mmc/k3-dw-mshc.txt line 71
Quoted 5 lines
Documentation/devicetree/bindings/mmc/k3-dw-mshc.txt new file +4
-0+Required Properties: +* compatible: should be + - "hisilicon,pctrl": Peripheral control +Reg is not described as a required property.
OK.
Quoted 9 lines
Documentation/devicetree/bindings/mmc/k3-dw-mshc.txt line 77
Quoted 7 lines
Documentation/devicetree/bindings/mmc/k3-dw-mshc.txt new file +6
-0+Example: + + pctrl: pctrl at fca09000 { + compatible = "hisilicon,pctrl"; + reg = <0xfca09000 0x1000>; + };This should be in its own binding document, and not part of the mmc binding
bindings/arm/hisilicon/hisilicon.txt still not been merged in another patch, where
we want to push such desc as well as other system binding.
Is it OK adding this node desc twice in two files, since mmc need such node. or move this desc after hisilicon.txt get merged for saving conflict?
Thanks
PATCH 2/2 mmc: dw_mmc: add dw_mmc-k3 for k3 platform
In reply to Zhangfei GaoHi Zhangfei,
Quoted 260 lines · Zhangfei Gao
update: fix typo
Add
dw_mmc-k3.cfor k3v2, support sd/emmcSigned-off-by Zhangfei Gao <[email protected]>Tested-by Zhigang Wang <[email protected]>--- .../devicetree/bindings/mmc/k3-dw-mshc.txt | 77 +++++ drivers/mmc/host/Kconfig | 10 + drivers/mmc/host/Makefile | 1 + drivers/mmc/host/dw_mmc-k3.c | 297 ++++++++++++++++++++ 4 files changed, 385 insertions(+) create mode 100644 Documentation/devicetree/bindings/mmc/k3-dw-mshc.txt create mode 100644 drivers/mmc/host/dw_mmc-k3.cDocumentation/devicetree/bindings/mmc/k3-dw-mshc.txt new file +77
-0@@ -0,0 +1,77 @@ +* Hisilicon specific extensions to the Synopsys Designware Mobile + Storage Host Controller + +Read synopsis-dw-mshc.txt for more details +The Synopsys designware mobile storage host controller is used to interface +a SoC with storage medium such as eMMC or SD/MMC cards. This file documents +differences between the core Synopsys dw mshc controller properties described +by synopsis-dw-mshc.txt and the properties used by the Hisilicon specific +extensions to the Synopsys Designware Mobile Storage Host Controller. + +Required Properties: + +* compatible: should be + - "hisilicon,hi4511-dw-mshc": for controllers with hi4511 + specific extentions. +* vmmc-supply: should be vmmc used in dwmmc +* fifo-depth: should be provided if register can not provide correct value +* clken-reg: should be clock enable register and offset +* drv-sel-reg: should be driver delay select register, offset and bits +* sam-sel-reg: should be sample delay select register, offset and bits +* div-reg: should be divider register, offset and bits +* tune-table: should be array of clock tune mmc controller + +Example: + + The MSHC controller node can be split into two portions, SoC specific and + board specific portions as listed below. + + dwmmc_0: dwmmc0 at fcd03000 { + compatible = "hisilicon,hi4511-dw-mshc"; + reg = <0xfcd03000 0x1000>; + interrupts = <0 16 4>; + #address-cells = <1>; + #size-cells = <0>; + clocks = <&clk_sd>, <&clk_ddrc_per>; + clock-names = "ciu", "biu"; + clken-reg = <0x1f8 0>; + drv-sel-reg = <0x1f8 4 4>; + sam-sel-reg = <0x1f8 8 4>; + div-reg = <0x1f8 1 3>; + tune-table = + <180000000 6 6 13 13 25000000>, + <0 0 0 0 0 0>, + <360000000 6 4 2 0 50000000>, + <180000000 6 4 13 13 25000000>, + <360000000 6 4 2 0 50000000>, + <720000000 6 1 9 4 100000000>, + <0 0 0 0 0 0>, + <360000000 7 1 3 0 50000000>; + }; + dwmmc0 at fcd03000 { + num-slots = <1>; + vmmc-supply = <&ldo12>; + fifo-depth = <0x100>; + supports-highspeed; + pinctrl-names = "default"; + pinctrl-0 = <&sd_pmx_pins &sd_cfg_func1 &sd_cfg_func2>; + slot at 0 { + reg = <0>; + bus-width = <4>; + disable-wp; + cd-gpios = <&gpio10 3 0>; + }; + }; + +PCTRL: + +Required Properties: +* compatible: should be + - "hisilicon,pctrl": Peripheral control + +Example: + + pctrl: pctrl at fca09000 { + compatible = "hisilicon,pctrl"; + reg = <0xfca09000 0x1000>; + };drivers/mmc/host/Kconfig +10
-0@@ -575,6 +575,16 @@ config MMC_DW_SOCFPGA This selects support for Altera SoCFPGA specific extensions to the Synopsys DesignWare Memory Card Interface driver. +config MMC_DW_K3 + tristate "K3 specific extensions for Synopsys DW Memory Card Interface" + depends on MMC_DW + select MMC_DW_PLTFM + select MMC_DW_IDMAC + help + This selects support for Hisilicon K3 SoC specific extensions to the + Synopsys DesignWare Memory Card Interface driver. Select this option + for platforms based on Hisilicon K3 SoC's. + config MMC_DW_PCI tristate "Synopsys Designware MCI support on PCI bus" depends on MMC_DW && PCIdrivers/mmc/host/Makefile +1
-0@@ -43,6 +43,7 @@ obj-$(CONFIG_MMC_DW) += dw_mmc.o obj-$(CONFIG_MMC_DW_PLTFM) += dw_mmc-pltfm.o obj-$(CONFIG_MMC_DW_EXYNOS) += dw_mmc-exynos.o obj-$(CONFIG_MMC_DW_SOCFPGA) += dw_mmc-socfpga.o +obj-$(CONFIG_MMC_DW_K3) += dw_mmc-k3.o obj-$(CONFIG_MMC_DW_PCI) += dw_mmc-pci.o obj-$(CONFIG_MMC_SH_MMCIF) += sh_mmcif.o obj-$(CONFIG_MMC_JZ4740) += jz4740_mmc.odrivers/mmc/host/dw_mmc-k3.c new file +122
-0@@ -0,0 +1,297 @@ +/* +* Copyright (c) 2013 Linaro Ltd. +* Copyright (c) 2013 Hisilicon Limited. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +*/ + +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/clk.h> +#include <linux/mmc/host.h> +#include <linux/mmc/dw_mmc.h> +#include <linux/of_address.h> + +#include "dw_mmc.h" +#include "dw_mmc-pltfm.h" + +enum dw_mci_k3_type { +DW_MCI_TYPE_HI4511 , +}; + +static struct dw_mci_k3_compatible { +char *compatible; +enum dw_mci_k3_type type; +} k3_compat[] = { + { + .compatible ="hisilicon,hi4511-dw-mshc" , + .type =DW_MCI_TYPE_HI4511 , + }, +}; + +#define TABLE_WIDTH 6 +#define TABLE_HEIGHT 8 +struct dw_mci_k3_priv_data { +enum dw_mci_k3_type type; +int old_timing; +u32 table[TABLE_WIDTH *TABLE_HEIGHT ]; +u32 clken_reg; +u32 clken_bit; +u32 sam_reg; +u32 sam_off; +u32 sam_bits; +u32 drv_reg; +u32 drv_off; +u32 drv_bits; +u32 div_reg; +u32 div_off; +u32 div_bits; +}; + +static void __iomem *pctrl; +static DEFINE_SPINLOCK (mmc_tuning_lock); + +static u32 dw_mci_k3_delay (u32 val,u32 para,u32 off,u32 len) +{ +u32 i; + +if (para >=0 ) { +for (i =0 ; i < len; i++) { +if (para %2 ) + val |=1 <<(off + i); +else + val &= ~(1 <<(off + i)); + para = para >>1 ; + } + } +return val; +} + +static void dw_mci_k3_set_timing (struct dw_mci_k3_priv_data *priv, +u32 sam,u32 drv,u32 div) +{ +u32 val; +unsigned long flags; + +if (!pctrl || !priv->clken_reg || !priv->sam_reg + || !priv->drv_reg || !priv->div_reg) +return ; + +spin_lock_irqsave (&mmc_tuning_lock, flags); + + val =readl (pctrl + priv->clken_reg); + val &= ~(1 << priv->clken_bit); +writel (val, pctrl + priv->clken_reg); + + val =readl (pctrl + priv->sam_reg); + val =dw_mci_k3_delay (val, sam, priv->sam_off, priv->sam_bits); +writel (val, pctrl + priv->sam_reg); + + val =readl (pctrl + priv->drv_reg); + val =dw_mci_k3_delay (val, drv, priv->drv_off, priv->drv_bits); +writel (val, pctrl + priv->drv_reg); + + val =readl (pctrl + priv->div_reg); + val =dw_mci_k3_delay (val, div, priv->div_off, priv->div_bits); +writel (val, pctrl + priv->div_reg); + + val =readl (pctrl + priv->clken_reg); + val |=1 << priv->clken_bit; +writel (val, pctrl + priv->clken_reg); + +spin_unlock_irqrestore (&mmc_tuning_lock, flags); +} + +static void dw_mci_k3_tun (struct dw_mci *host,int timing) +{ +struct dw_mci_k3_priv_data *priv = host->priv; +int ret; +u32 *table = &priv->table[TABLE_WIDTH * timing]; + +if (priv->old_timing == timing) +return ; + + ret =clk_set_rate (host->ciu_clk, table[0 ]); +if (ret) { +dev_err (host->dev,"clk_set_rate failed\n" ); +return ; + } + dw_mci_k3_set_timing(priv, (table[3] + table[4]) / 2,
drivers/mmc/host/dw_mmc-k3.c line 132
Quoted 10 lines
drivers/mmc/host/dw_mmc-k3.c new file +10
-0+ table[2], table[1]); + host->bus_hz = table[5 ]; + priv->old_timing = timing; +} + +static void dw_mci_k3_set_ios (struct dw_mci *host,struct mmc_ios *ios) +{ +struct dw_mci_k3_priv_data *priv = host->priv; + +if (priv->type ==DW_MCI_TYPE_HI4511 )
There are several checking controller type. But now DW_MCI_TYPE_HI4511 is just introduced alone. It seems like unnecessary.
Quoted 50 lines
drivers/mmc/host/dw_mmc-k3.c new file +50
-0+dw_mci_k3_tun (host, ios->timing); +} + +static int dw_mci_k3_priv_init (struct dw_mci *host) +{ +struct dw_mci_k3_priv_data *priv; +int i, ret; + + priv =devm_kzalloc (host->dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) { +dev_err (host->dev,"mem alloc failed for private data\n" ); +return -ENOMEM ; + } + priv->old_timing =-1 ; + host->priv = priv; + +for (i =0 ; i <ARRAY_SIZE (k3_compat); i++) { +if (of_device_is_compatible (host->dev->of_node, + k3_compat[i].compatible)) + priv->type = k3_compat[i].type; + } + +if (priv->type ==DW_MCI_TYPE_HI4511 ) { + ret =of_property_read_u32_array (host->dev->of_node, +"tune-table" , priv->table,TABLE_WIDTH *TABLE_HEIGHT ); +if (ret) { +dev_err (host->dev,"not found tune-table\n" ); +return -EINVAL ; + } + +if (!pctrl) { +struct device_node *node; + + node =of_find_compatible_node (NULL ,NULL , +"hisilicon,pctrl" ); + pctrl =of_iomap (node,0 ); + } + } + +return 0 ; +} + +static int dw_mci_k3_setup_clock (struct dw_mci *host) +{ +struct dw_mci_k3_priv_data *priv = host->priv; + +if (priv->type ==DW_MCI_TYPE_HI4511 ) +dw_mci_k3_tun (host,MMC_TIMING_LEGACY ); + +return 0 ;
drivers/mmc/host/dw_mmc-k3.c line 192
Quoted 10 lines
drivers/mmc/host/dw_mmc-k3.c new file +10
-0+} + +static int dw_mci_k3_parse_dt (struct dw_mci *host) +{ +struct dw_mci_k3_priv_data *priv = host->priv; +struct device_node *np = host->dev->of_node; +u32 data[3 ]; +int ret; + +if (priv->type ==DW_MCI_TYPE_HI4511 ) {
Didn't you see Kernel panic here?host->priv is not allocated yet, it's a invalid pointer dereference. dw_mci_k3_parse_dt() is called prior to dw_mci_k3_priv_init(). You can check dw_mci_probe() sequence.
Quoted 20 lines
drivers/mmc/host/dw_mmc-k3.c new file +20
-0+ ret =of_property_read_u32_array (np, +"clken-reg" , data,2 ); +if (!ret) { + priv->clken_reg = data[0 ]; + priv->clken_bit = data[1 ]; + } + + ret =of_property_read_u32_array (np, +"drv-sel-reg" , data,3 ); +if (!ret) { + priv->drv_reg = data[0 ]; + priv->drv_off = data[1 ]; + priv->drv_bits = data[2 ]; + } + + ret =of_property_read_u32_array (np, +"sam-sel-reg" , data,3 ); +if (!ret) { + priv->sam_reg = data[0 ]; + priv->sam_off = data[1 ];
drivers/mmc/host/dw_mmc-k3.c line 222
Quoted 10 lines
drivers/mmc/host/dw_mmc-k3.c new file +10
-0+ priv->sam_bits = data[2 ]; + } + + ret =of_property_read_u32_array (np, +"div-reg" , data,3 ); +if (!ret) { + priv->div_reg = data[0 ]; + priv->div_off = data[1 ]; + priv->div_bits = data[2 ]; + }
Should these register information be got from dt?
It could be define in source code instead.
Thanks,
Seungwon Jeon
Quoted 82 lines
drivers/mmc/host/dw_mmc-k3.c new file +75
-1+ } + +return 0 ; +} + +static unsigned long k3_dwmmc_caps[4 ] = { +MMC_CAP_4_BIT_DATA |MMC_CAP_SD_HIGHSPEED , +MMC_CAP_8_BIT_DATA |MMC_CAP_MMC_HIGHSPEED , +0 , +0 , +}; + +static const struct dw_mci_drv_data k3_drv_data = { + .caps = k3_dwmmc_caps, + .init = dw_mci_k3_priv_init, + .set_ios = dw_mci_k3_set_ios, + .setup_clock = dw_mci_k3_setup_clock, + .parse_dt = dw_mci_k3_parse_dt, +}; + +static const struct of_device_id dw_mci_k3_match[] = { + { .compatible ="hisilicon,hi4511-dw-mshc" , + .data = &k3_drv_data, }, + {}, +}; +MODULE_DEVICE_TABLE (of, dw_mci_k3_match); + +static int dw_mci_k3_probe (struct platform_device *pdev) +{ +const struct dw_mci_drv_data *drv_data; +const struct of_device_id *match; + + match =of_match_node (dw_mci_k3_match, pdev->dev.of_node); + drv_data = match->data; + +return dw_mci_pltfm_register (pdev, drv_data); +} + +static int dw_mci_k3_suspend (struct device *dev) +{ +struct dw_mci *host =dev_get_drvdata (dev); + +return dw_mci_suspend (host); +} + +static int dw_mci_k3_resume (struct device *dev) +{ +struct dw_mci *host =dev_get_drvdata (dev); +struct dw_mci_k3_priv_data *priv = host->priv; + +if (priv->type ==DW_MCI_TYPE_HI4511 ) { + priv->old_timing =-1 ; +dw_mci_k3_tun (host,MMC_TIMING_LEGACY ); + } + +return dw_mci_resume (host); +} + +SIMPLE_DEV_PM_OPS (dw_mci_k3_pmops, dw_mci_k3_suspend, dw_mci_k3_resume); + +static struct platform_driver dw_mci_k3_pltfm_driver = { + .probe = dw_mci_k3_probe, + .remove = dw_mci_pltfm_remove, + .driver = { + .name ="dwmmc_k3" , + .of_match_table = dw_mci_k3_match, + .pm = &dw_mci_k3_pmops, + }, +}; + +module_platform_driver (dw_mci_k3_pltfm_driver); + +MODULE_DESCRIPTION ("K3 Specific DW-MSHC Driver Extension" ); +MODULE_LICENSE ("GPL v2" ); +MODULE_ALIAS ("platform:dwmmc-k3" ); --1.7.9.5
--
To unsubscribe from this list: send the line "unsubscribe linux-mmc" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 2/2 mmc: dw_mmc: add dw_mmc-k3 for k3 platform
Dear Seungwon
Thanks for giving suggestion.
Quoted 10 lines · Seungwon Jeon
Hi Zhangfei,
drivers/mmc/host/dw_mmc-k3.c line 132
Quoted 5 lines
drivers/mmc/host/dw_mmc-k3.c new file +5
-0+static void dw_mci_k3_set_ios (struct dw_mci *host,struct mmc_ios *ios) +{ +struct dw_mci_k3_priv_data *priv = host->priv; + +if (priv->type ==DW_MCI_TYPE_HI4511 )There are several checking controller type. But now
DW_MCI_TYPE_HI4511is just introduced alone. It seems like unnecessary.
Yes, currently only K3V2 is added, and k3v3 code will be added soon. Do you think type is more suitable to add later?
Quoted 4 lines
Quoted 4 lines
drivers/mmc/host/dw_mmc-k3.c new file +4
-0+static int dw_mci_k3_parse_dt (struct dw_mci *host) +{ +struct dw_mci_k3_priv_data *priv = host->priv; +struct device_node *np = host->dev->of_node;
Quoted 8 lines
drivers/mmc/host/dw_mmc-k3.c line 192
Quoted 4 lines
drivers/mmc/host/dw_mmc-k3.c new file +4
-0+u32 data[3 ]; +int ret; + +if (priv->type ==DW_MCI_TYPE_HI4511 ) {Didn't you see Kernel panic here?
host->privis not allocated yet, it's a invalid pointer dereference.dw_mci_k3_parse_dt()is called prior todw_mci_k3_priv_init(). You can checkdw_mci_probe()sequence.
It is no problem heredw_mci_pltfm_register -> drv_data->init(host) -> dw_mci_probe -> dw_mci_parse_dt
Quoted 25 lines
Quoted 25 lines
drivers/mmc/host/dw_mmc-k3.c new file +24
-0+ ret =of_property_read_u32_array (np, +"clken-reg" , data,2 ); +if (!ret) { + priv->clken_reg = data[0 ]; + priv->clken_bit = data[1 ]; + } + + ret =of_property_read_u32_array (np, +"drv-sel-reg" , data,3 ); +if (!ret) { + priv->drv_reg = data[0 ]; + priv->drv_off = data[1 ]; + priv->drv_bits = data[2 ]; + } + + ret =of_property_read_u32_array (np, +"sam-sel-reg" , data,3 ); +if (!ret) { + priv->sam_reg = data[0 ]; + priv->sam_off = data[1 ]; + priv->sam_bits = data[2 ]; + } + + ret = of_property_read_u32_array(np,
Quoted 8 lines
drivers/mmc/host/dw_mmc-k3.c line 222
Quoted 6 lines
drivers/mmc/host/dw_mmc-k3.c new file +6
-0+ "div-reg", data, 3); +if (!ret) { + priv->div_reg = data[0 ]; + priv->div_off = data[1 ]; + priv->div_bits = data[2 ]; + }Should these register information be got from dt?
It could be define in source code instead.
There are many register from pctrl node instead of mmc controller. If set in code, we may read id and then switch id, set register, start bit, bits number,
which is no rules for different controller, using defiine is not helpful. for example:
switch (idx) {
case 0:
clken_reg = 0x1F8;
clken_bit = 0;
drv_sel_reg = 0x1F8;
drv_sel_bit = 4;
sam_sel_reg = 0x1F8;
sam_sel_bit = 8;
div_reg = 0x1F8;
div_bit = 1;
break;
case 1:
clken_reg = 0x1F8;
clken_bit = 12;
drv_sel_reg = 0x1F8;
drv_sel_bit = 16;
sam_sel_reg = 0x1F8;
sam_sel_bit = 20;
div_reg = 0x1F8;
div_bit = 13;
break;
case 2:
clken_reg = 0x1F8;
clken_bit = 24;
drv_sel_reg = 0x1F8;
drv_sel_bit = 28;
sam_sel_reg = 0x1FC;
sam_sel_bit = 0;
div_reg = 0x1F8;
div_bit = 25;
break;So define register offset, start bit and bits number in dts make it simplier. Is this acceptable?
Thanks.
PATCH 2/2 mmc: dw_mmc: add dw_mmc-k3 for k3 platform
Quoted 16 lines · zhangfei gao
Dear Seungwon
Thanks for giving suggestion.
Quoted 10 lines · Seungwon Jeon
Hi Zhangfei,
drivers/mmc/host/dw_mmc-k3.c line 132
Quoted 5 lines
drivers/mmc/host/dw_mmc-k3.c new file +5
-0+static void dw_mci_k3_set_ios (struct dw_mci *host,struct mmc_ios *ios) +{ +struct dw_mci_k3_priv_data *priv = host->priv; + +if (priv->type ==DW_MCI_TYPE_HI4511 )There are several checking controller type. But now
DW_MCI_TYPE_HI4511is just introduced alone. It seems like unnecessary.
Quoted 2 lines
Yes, currently only K3V2 is added, and k3v3 code will be added soon. Do you think type is more suitable to add later?
Yes, it would be better.
Quoted 14 lines
Quoted 13 lines
drivers/mmc/host/dw_mmc-k3.c line 192
Quoted 9 lines
drivers/mmc/host/dw_mmc-k3.c new file +8
-0+static int dw_mci_k3_parse_dt (struct dw_mci *host) +{ +struct dw_mci_k3_priv_data *priv = host->priv; +struct device_node *np = host->dev->of_node; +u32 data[3 ]; +int ret; + +if (priv->type ==DW_MCI_TYPE_HI4511 ) {Didn't you see Kernel panic here?
host->privis not allocated yet, it's a invalid pointer dereference.dw_mci_k3_parse_dt()is called prior todw_mci_k3_priv_init(). You can checkdw_mci_probe()sequence.
Quoted 2 lines
It is no problem here
dw_mci_pltfm_register->drv_data->init(host)->dw_mci_probe->dw_mci_parse_dt
I guess your base is not latest.
Can you check cjb's tree?
Quoted 72 lines
Quoted 26 lines
Quoted 26 lines
drivers/mmc/host/dw_mmc-k3.c new file +24
-0+ ret =of_property_read_u32_array (np, +"clken-reg" , data,2 ); +if (!ret) { + priv->clken_reg = data[0 ]; + priv->clken_bit = data[1 ]; + } + + ret =of_property_read_u32_array (np, +"drv-sel-reg" , data,3 ); +if (!ret) { + priv->drv_reg = data[0 ]; + priv->drv_off = data[1 ]; + priv->drv_bits = data[2 ]; + } + + ret =of_property_read_u32_array (np, +"sam-sel-reg" , data,3 ); +if (!ret) { + priv->sam_reg = data[0 ]; + priv->sam_off = data[1 ]; + priv->sam_bits = data[2 ]; + } + + ret = of_property_read_u32_array(np,Quoted 8 lines
drivers/mmc/host/dw_mmc-k3.c line 222
Quoted 6 lines
drivers/mmc/host/dw_mmc-k3.c new file +6
-0+ "div-reg", data, 3); +if (!ret) { + priv->div_reg = data[0 ]; + priv->div_off = data[1 ]; + priv->div_bits = data[2 ]; + }Should these register information be got from dt?
It could be define in source code instead.There are many register from pctrl node instead of mmc controller. If set in code, we may read id and then switch id, set register, start bit, bits number,
which is no rules for different controller, using defiine is not helpful. for example:switch (idx) { case 0: clken_reg = 0x1F8; clken_bit = 0; drv_sel_reg = 0x1F8; drv_sel_bit = 4; sam_sel_reg = 0x1F8; sam_sel_bit = 8; div_reg = 0x1F8; div_bit = 1; break; case 1: clken_reg = 0x1F8; clken_bit = 12; drv_sel_reg = 0x1F8; drv_sel_bit = 16; sam_sel_reg = 0x1F8; sam_sel_bit = 20; div_reg = 0x1F8; div_bit = 13; break; case 2: clken_reg = 0x1F8; clken_bit = 24; drv_sel_reg = 0x1F8; drv_sel_bit = 28; sam_sel_reg = 0x1FC; sam_sel_bit = 0; div_reg = 0x1F8; div_bit = 25; break;
Quoted 2 lines
So define register offset, start bit and bits number in dts make it simplier. Is this acceptable?
It's up to you. I think there will be better ways.
For example, some table for variable register can be used for each controller type. Additionally, if you intend to use dt, error handling is needed. dw_mci_k3_parse_dt always returns success although of_property_read_u32_array is failed.
Thanks,
Seungwon Jeon
PATCH 2/2 mmc: dw_mmc: add dw_mmc-k3 for k3 platform
Quoted 17 lines · Seungwon Jeon
Quoted 16 lines · zhangfei gao
Dear Seungwon
Thanks for giving suggestion.
Quoted 10 lines · Seungwon Jeon
Hi Zhangfei,
drivers/mmc/host/dw_mmc-k3.c line 132
Quoted 5 lines
drivers/mmc/host/dw_mmc-k3.c new file +5
-0+static void dw_mci_k3_set_ios (struct dw_mci *host,struct mmc_ios *ios) +{ +struct dw_mci_k3_priv_data *priv = host->priv; + +if (priv->type ==DW_MCI_TYPE_HI4511 )There are several checking controller type. But now
DW_MCI_TYPE_HI4511is just introduced alone. It seems like unnecessary.
Quoted 3 lines
Quoted 2 lines
Yes, currently only K3V2 is added, and k3v3 code will be added soon. Do you think type is more suitable to add later?
Yes, it would be better.
OK, got it.
Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
drivers/mmc/host/dw_mmc-k3.c line 192
Quoted 10 lines
drivers/mmc/host/dw_mmc-k3.c new file +8
-0+static int dw_mci_k3_parse_dt (struct dw_mci *host) +{ +struct dw_mci_k3_priv_data *priv = host->priv; +struct device_node *np = host->dev->of_node; +u32 data[3 ]; +int ret; + +if (priv->type ==DW_MCI_TYPE_HI4511 ) {Didn't you see Kernel panic here?
host->privis not allocated yet, it's a invalid pointer dereference.dw_mci_k3_parse_dt()is called prior todw_mci_k3_priv_init(). You can checkdw_mci_probe()sequence.
Quoted 4 lines
Quoted 2 lines
It is no problem here
dw_mci_pltfm_register->drv_data->init(host)->dw_mci_probe->dw_mci_parse_dtI guess your base is not latest.
Can you check cjb's tree?
Yes, thanks for the info.
It is changed in 3.12-rc2
While what we use is 3.12-rc1, will rebase.
Quoted 73 lines
Quoted 73 lines
Quoted 27 lines
Quoted 27 lines
drivers/mmc/host/dw_mmc-k3.c new file +24
-0+ ret =of_property_read_u32_array (np, +"clken-reg" , data,2 ); +if (!ret) { + priv->clken_reg = data[0 ]; + priv->clken_bit = data[1 ]; + } + + ret =of_property_read_u32_array (np, +"drv-sel-reg" , data,3 ); +if (!ret) { + priv->drv_reg = data[0 ]; + priv->drv_off = data[1 ]; + priv->drv_bits = data[2 ]; + } + + ret =of_property_read_u32_array (np, +"sam-sel-reg" , data,3 ); +if (!ret) { + priv->sam_reg = data[0 ]; + priv->sam_off = data[1 ]; + priv->sam_bits = data[2 ]; + } + + ret = of_property_read_u32_array(np,Quoted 8 lines
drivers/mmc/host/dw_mmc-k3.c line 222
Quoted 6 lines
drivers/mmc/host/dw_mmc-k3.c new file +6
-0+ "div-reg", data, 3); +if (!ret) { + priv->div_reg = data[0 ]; + priv->div_off = data[1 ]; + priv->div_bits = data[2 ]; + }Should these register information be got from dt?
It could be define in source code instead.There are many register from pctrl node instead of mmc controller. If set in code, we may read id and then switch id, set register, start bit, bits number,
which is no rules for different controller, using defiine is not helpful. for example:switch (idx) { case 0: clken_reg = 0x1F8; clken_bit = 0; drv_sel_reg = 0x1F8; drv_sel_bit = 4; sam_sel_reg = 0x1F8; sam_sel_bit = 8; div_reg = 0x1F8; div_bit = 1; break; case 1: clken_reg = 0x1F8; clken_bit = 12; drv_sel_reg = 0x1F8; drv_sel_bit = 16; sam_sel_reg = 0x1F8; sam_sel_bit = 20; div_reg = 0x1F8; div_bit = 13; break; case 2: clken_reg = 0x1F8; clken_bit = 24; drv_sel_reg = 0x1F8; drv_sel_bit = 28; sam_sel_reg = 0x1FC; sam_sel_bit = 0; div_reg = 0x1F8; div_bit = 25; break;
Quoted 6 lines
Quoted 2 lines
So define register offset, start bit and bits number in dts make it simplier. Is this acceptable?
It's up to you. I think there will be better ways.
For example, some table for variable register can be used for each controller type. Additionally, if you intend to use dt, error handling is needed.dw_mci_k3_parse_dtalways returns success althoughof_property_read_u32_arrayis failed.
The reason is they are optional property.
SD would fail if not setting the property, while emmc does not matter. So set for optional, dw_mci_k3_set_timing will check whether they exists.
Thanks