Changes for SDCC5 version
Subsystems (4)
cover Changes for SDCC5 version
With SDCC5, the MCI register space got removed and the offset/order of several registers have changed. Based on SDCC version used and the register, we need to pick the base address and offset.
Also power irq is a signal from controller to SW that it is ready for voltage switch. So added support to register voltage regulators in the msm driver and use them. With this core layer will not have to take care of voltage regulators. Chips which are currently using core layer regulator APIs can continue to do so, while newer chips can utilize power irq for voltage switch.
Depends on patch series:
[PATCH V5 0/2] mmc: sdhci-msm: Configuring IO_PAD support for sdhci-msm https://lkml.org/lkml/2018/4/20/370
Asutosh Das (1):
mmc: sdhci-msm: Add and use voltage regulator related APIs
Sahitya Tummala (2):
host: sdhci: fix current caps when there is no host->vmmc
host: sdhci-msm: implement get_current_limit() host op
Sayali Lokhande (1):
mmc: host: Register changes for sdcc V5
.../devicetree/bindings/mmc/sdhci-msm.txt | 32 +- drivers/mmc/host/sdhci-msm.c | 1027 +++++++++++++++++--- drivers/mmc/host/sdhci.c | 11 +- drivers/mmc/host/sdhci.h | 1 + 4 files changed, 912 insertions(+), 159 deletions(-)
Signature · 2 lines
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.
RFC PATCH 1/4 mmc: host: Register changes for sdcc V5
From: Sayali Lokhande <[email protected]>
For SDCC version 5.0.0, MCI registers are removed from SDCC interface and some registers are moved to HC. This change is to support MCI register removal for msmfalcon. New compatible string "qcom,sdhci-msm-v5" is added for msmfalcon to support this change.
--- .../devicetree/bindings/mmc/sdhci-msm.txt | 5 +- drivers/mmc/host/sdhci-msm.c | 485 +++++++++++++++------ 2 files changed, 365 insertions(+), 125 deletions(-)
Documentation/devicetree/bindings/mmc/sdhci-msm.txt +4 -1
@@ -4,7 +4,10 @@ This file documents differences between the core properties in mmc.txt and the properties used by the sdhci-msm driver. Required properties: -- compatible: Should contain "qcom,sdhci-msm-v4". +- compatible: Should contain "qcom,sdhci-msm-v4" or "qcom,sdhci-msm-v5". + For SDCC version 5.0.0, MCI registers are removed from SDCC + interface and some registers are moved to HC. New compatible + string is added to support this change - "qcom,sdhci-msm-v5". - reg: Base address and length of the register in the following order: - Host controller register map (required) - SD Core register map (required)
drivers/mmc/host/sdhci-msm.c +361 -124
906 lines not on this page · raw message
Signature · 2 lines
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.
RFC PATCH 2/4 mmc: sdhci-msm: Add and use voltage regulator related APIs
In reply to Vijay ViswanathFrom: Asutosh Das <[email protected]>
Some platforms require that the voltage switching happen only after the register write occurs and controller is ready for the switch. When the controller is ready, it will inform through power irq.
Add voltage regulator APIs and use them during power irq to switch voltage instead of relying on core layer voltage switching.
--- .../devicetree/bindings/mmc/sdhci-msm.txt | 27 +- drivers/mmc/host/sdhci-msm.c | 537 +++++++++++++++++++-- 2 files changed, 529 insertions(+), 35 deletions(-)
Documentation/devicetree/bindings/mmc/sdhci-msm.txt +25 -2
@@ -23,6 +23,22 @@ Required properties: "xo" - TCXO clock (optional) "cal" - reference clock for RCLK delay calibration (optional) "sleep" - sleep clock for RCLK delay calibration (optional) +- <supply-name>-supply: phandle to the regulator device tree node if voltage + regulators needs to be handled from within sdhci-msm layer. + Supported "supply-name" are "vdd" and "vdd-io". + +Optional Properties: + - qcom,<supply>-always-on - specifies whether supply should be kept + "on" always. + - qcom,<supply>-lpm_sup - specifies whether supply can be kept in low + power mode (lpm). + - qcom,<supply>-voltage_level - specifies voltage levels for supply. + Should be specified in pairs (min, max), units uV. + - qcom,<supply>-current_level - specifies load levels for supply in lpm + or high power mode (hpm). Should be specified in + pairs (lpm, hpm), units uA. + + Example:
@@ -33,8 +49,15 @@ Example: bus-width = <8>; non-removable; - vmmc-supply = <&pm8941_l20>; - vqmmc-supply = <&pm8941_s3>; + vdd-supply = <&pm8941_l20>; + qcom,vdd-voltage-level = <2950000 2950000>; + qcom,vdd-current-level = <9000 800000>; + + vdd-io-supply = <&pm8941_s3>; + qcom,vdd-io-always-on; + qcom,vdd-io-lpm-sup; + qcom,vdd-io-voltage-level = <1800000 2950000>; + qcom,vdd-io-current-level = <6 22000>; pinctrl-names = "default"; pinctrl-0 = <&sdc1_clk &sdc1_cmd &sdc1_data>;
drivers/mmc/host/sdhci-msm.c +504 -33
650 lines not on this page · raw message
Signature · 2 lines
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.
RFC PATCH 3/4 host: sdhci: fix current caps when there is no host->vmmc
In reply to Vijay ViswanathFrom: Sahitya Tummala <[email protected]>
When the regulators are not managed by SDHCI host driver (i.e., when host->vmmc and host->vmmcq are absent), get the regulator current capabilities through a new host op get_current_limit().
Change-Id: I3370a2411beec1f03cc5f102bf95cd816c60351e
--- drivers/mmc/host/sdhci.c | 11 ++++++++--- drivers/mmc/host/sdhci.h | 1 + 2 files changed, 9 insertions(+), 3 deletions(-)
drivers/mmc/host/sdhci.c +8 -3
@@ -3570,10 +3570,15 @@ int sdhci_setup_host(struct sdhci_host *host)* value. */ max_current_caps =sdhci_readl (host,SDHCI_MAX_CURRENT ); -if (!max_current_caps && !IS_ERR (mmc->supply.vmmc)) { -int curr =regulator_get_current_limit (mmc->supply.vmmc); -if (curr >0 ) { +if (!max_current_caps) { +u32 curr =0 ; + +if (!IS_ERR (mmc->supply.vmmc)) + curr =regulator_get_current_limit (mmc->supply.vmmc); +else if (host->ops->get_current_limit) + curr = host->ops->get_current_limit (host); +if (curr >0 ) {/* convert to SDHCI_MAX_CURRENT format */ curr = curr/1000 ;/* convert to mA */ curr = curr/SDHCI_MAX_CURRENT_MULTIPLIER ;
drivers/mmc/host/sdhci.h +1 -0
@@ -584,6 +584,7 @@ struct sdhci_ops {void (*adma_workaround)(struct sdhci_host *host,u32 intmask);void (*card_event)(struct sdhci_host *host);void (*voltage_switch)(struct sdhci_host *host); +unsigned int (*get_current_limit)(struct sdhci_host *host); };#ifdef CONFIG_MMC_SDHCI_IO_ACCESSORS
Signature · 2 lines
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.
RFC PATCH 4/4 host: sdhci-msm: implement get_current_limit() host op
In reply to Vijay ViswanathFrom: Sahitya Tummala <[email protected]>
This is needed to get the current capabilities of vdd regulator that is not managed by SDHCI driver.
--- drivers/mmc/host/sdhci-msm.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
drivers/mmc/host/sdhci-msm.c +13 -0
@@ -2079,6 +2079,18 @@ static void sdhci_msm_set_default_hw_caps(struct device *dev, {}, }; +static unsigned int sdhci_msm_get_current_limit (struct sdhci_host *host) +{ +struct sdhci_pltfm_host *pltfm_host =sdhci_priv (host); +struct sdhci_msm_host *msm_host =sdhci_pltfm_priv (pltfm_host); +struct sdhci_msm_reg_data *vdd_data = msm_host->pdata.vdd_data; +u32 max_curr =0 ; + +if (vdd_data) + max_curr = vdd_data->hpm_uA; +return max_curr; +} +MODULE_DEVICE_TABLE (of, sdhci_msm_dt_match);static const struct sdhci_ops sdhci_msm_ops = {
@@ -2090,6 +2102,7 @@ static void sdhci_msm_set_default_hw_caps(struct device *dev, .set_uhs_signaling = sdhci_msm_set_uhs_signaling, .write_w = sdhci_msm_writew, .write_b = sdhci_msm_writeb, + .get_current_limit = sdhci_msm_get_current_limit, };static const struct sdhci_pltfm_data sdhci_msm_pdata = {
Signature · 2 lines
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.
Re: [PATCH RFC 1/4] mmc: host: Register changes for sdcc V5
In reply to Vijay ViswanathQuoted 7 lines · Vijay Viswanath
From: Sayali Lokhande <[email protected]>
For SDCC version 5.0.0, MCI registers are removed from SDCC interface and some registers are moved to HC. This change is to support MCI register removal for msmfalcon. New compatible string "qcom,sdhci-msm-v5" is added for msmfalcon to support this change.
To simplify review, I would recommend to split this up in a few more pieces, a few re-factoring while the final change adds the qcom,sdhci-msm-v5 support.
Quoted 6 lines
Change-Id I0febfd9bb2222436a8eff20c20107dd4180c9781Signed-off-by Sayali Lokhande <[email protected]>Signed-off-by Vijay Viswanath <[email protected]>--- .../devicetree/bindings/mmc/sdhci-msm.txt | 5 +-
Please move DT changes into separate patches and make sure to sent it to DT maintainers as well.
Quoted 23 lines
drivers/mmc/host/sdhci-msm.c | 485 +++++++++++++++------ 2 files changed, 365 insertions(+), 125 deletions(-)Documentation/devicetree/bindings/mmc/sdhci-msm.txt +4
-1@@ -4,7 +4,10 @@ This file documents differences between the core properties in mmc.txt and the properties used by the sdhci-msm driver. Required properties: -- compatible: Should contain "qcom,sdhci-msm-v4". +- compatible: Should contain "qcom,sdhci-msm-v4" or "qcom,sdhci-msm-v5". + For SDCC version 5.0.0, MCI registers are removed from SDCC + interface and some registers are moved to HC. New compatible + string is added to support this change - "qcom,sdhci-msm-v5". - reg: Base address and length of the register in the following order: - Host controller register map (required) - SD Core register map (required)drivers/mmc/host/sdhci-msm.c +0
-0
[...]
Quoted 2 lines
+struct
sdhci_msm_offset{
I think a better idea is to create a struct sdhci_msm_variant and make it contain all the variant specific data. So, not only the offsets, but other variant data as well.
More comments below.
Quoted 99 lines
drivers/mmc/host/sdhci-msm.c +90
-0+u32 core_mci_data_cnt; +u32 core_mci_status; +u32 core_mci_fifo_cnt; +u32 core_mci_version; +u32 core_generics; +u32 core_testbus_config; +u32 core_testbus_sel2_bit; +u32 core_testbus_ena; +u32 core_testbus_sel2; +u32 core_pwrctl_status; +u32 core_pwrctl_mask; +u32 core_pwrctl_clear; +u32 core_pwrctl_ctl; +u32 core_sdcc_debug_reg; +u32 core_dll_config; +u32 core_dll_status; +u32 core_vendor_spec; +u32 core_vendor_spec_adma_err_addr0; +u32 core_vendor_spec_adma_err_addr1; +u32 core_vendor_spec_func2; +u32 core_vendor_spec_capabilities0; +u32 core_ddr_200_cfg; +u32 core_vendor_spec3; +u32 core_dll_config_2; +u32 core_ddr_config; +u32 core_ddr_config_2; +}; + +struct sdhci_msm_offset sdhci_msm_offset_mci_removed = { + .core_mci_data_cnt =0x35c , + .core_mci_status =0x324 , + .core_mci_fifo_cnt =0x308 , + .core_mci_version =0x318 , + .core_generics =0x320 , + .core_testbus_config =0x32c , + .core_testbus_sel2_bit =3 , + .core_testbus_ena = (1 <<31 ), + .core_testbus_sel2 = (1 <<3 ), + .core_pwrctl_status =0x240 , + .core_pwrctl_mask =0x244 , + .core_pwrctl_clear =0x248 , + .core_pwrctl_ctl =0x24c , + .core_sdcc_debug_reg =0x358 , + .core_dll_config =0x200 , + .core_dll_status =0x208 , + .core_vendor_spec =0x20c , + .core_vendor_spec_adma_err_addr0 =0x214 , + .core_vendor_spec_adma_err_addr1 =0x218 , + .core_vendor_spec_func2 =0x210 , + .core_vendor_spec_capabilities0 =0x21c , + .core_ddr_200_cfg =0x224 , + .core_vendor_spec3 =0x250 , + .core_dll_config_2 =0x254 , + .core_ddr_config =0x258 , + .core_ddr_config_2 =0x25c , +}; + +struct sdhci_msm_offset sdhci_msm_offset_mci_present = { + .core_mci_data_cnt =0x30 , + .core_mci_status =0x34 , + .core_mci_fifo_cnt =0x44 , + .core_mci_version =0x050 , + .core_generics =0x70 , + .core_testbus_config =0x0CC , + .core_testbus_sel2_bit =4 , + .core_testbus_ena = (1 <<3 ), + .core_testbus_sel2 = (1 <<4 ), + .core_pwrctl_status =0xDC , + .core_pwrctl_mask =0xE0 , + .core_pwrctl_clear =0xE4 , + .core_pwrctl_ctl =0xE8 , + .core_sdcc_debug_reg =0x124 , + .core_dll_config =0x100 , + .core_dll_status =0x108 , + .core_vendor_spec =0x10C , + .core_vendor_spec_adma_err_addr0 =0x114 , + .core_vendor_spec_adma_err_addr1 =0x118 , + .core_vendor_spec_func2 =0x110 , + .core_vendor_spec_capabilities0 =0x11C , + .core_ddr_200_cfg =0x184 , + .core_vendor_spec3 =0x1B0 , + .core_dll_config_2 =0x1B4 , + .core_ddr_config =0x1B8 , + .core_ddr_config_2 =0x1BC , +}; +struct sdhci_msm_host {struct platform_device *pdev;void __iomem *core_mem;/* MSM SDCC mapped address */ @@ -156,8 +232,72 @@ struct sdhci_msm_host {wait_queue_head_t pwr_irq_wait;bool pwr_irq_flag;u32 caps_0; +bool mci_removed; +const struct sdhci_msm_offset *offset; }; +/* +* APIs to write to vendor specific registers which were there in the core_mem
drivers/mmc/host/sdhci-msm.c struct sdhci_msm_host { · line 250
Quoted 10 lines
drivers/mmc/host/sdhci-msm.c +10
-0+* region before MCI was removed. +*/ +u8 sdhci_msm_vendor_readb_relaxed (struct sdhci_host *host,u32 offset) +{ +struct sdhci_pltfm_host *pltfm_host =sdhci_priv (host); +struct sdhci_msm_host *msm_host =sdhci_pltfm_priv (pltfm_host); +void __iomem *base_addr; + +if (msm_host->mci_removed) + base_addr = host->ioaddr;
I would rather use a separate set of functions, which you assign at ->probe().
That may speed things up a little bit, as you don't need to check for "mci_removed", each time in these read/write functions.
Quoted 5 lines
drivers/mmc/host/sdhci-msm.c +5
-0+else + base_addr = msm_host->core_mem; + +return readb_relaxed (base_addr + offset); +}
[...]
Quoted 15 lines
static const struct of_device_id sdhci_msm_dt_match[] = { { .compatible = "qcom,sdhci-msm-v4" },drivers/mmc/host/sdhci-msm.c +2
-0+ {.compatible = "qcom,sdhci-msm-v5"}, {}, };@@ -1430,6 +1651,7 @@ static int sdhci_msm_probe(struct platform_device *pdev)u16 host_version, core_minor;u32 core_version, config;u8 core_major; +const struct sdhci_msm_offset *msm_offset; host =sdhci_pltfm_init (pdev, &sdhci_msm_pdata,sizeof (*msm_host));if (IS_ERR (host))
drivers/mmc/host/sdhci-msm.c static int sdhci_msm_probe(struct platform_device *pdev) · line 1672
Quoted 6 lines
drivers/mmc/host/sdhci-msm.c +3
-0@@ -1445,6 +1667,15 @@ static int sdhci_msm_probe(struct platform_device *pdev)if (ret) goto pltfm_free; +if (of_find_compatible_node (NULL ,NULL ,"qcom,sdhci-msm-v5" )) { + msm_host->mci_removed = true; + msm_host->offset = &sdhci_msm_offset_mci_removed;
I would suggest to extend your array of "struct of_device_id" to use the .data member to store all the variant specific data (such as the offsets for example).
Then you can use of_device_get_match_data(), to get the variant data.
drivers/mmc/host/sdhci-msm.c static int sdhci_msm_probe(struct platform_device *pdev) · line 1678
Quoted 6 lines
drivers/mmc/host/sdhci-msm.c +6
-0+ }else { + msm_host->mci_removed = false; + msm_host->offset = &sdhci_msm_offset_mci_present; + } + msm_offset = msm_host->offset; +
[...]
Kind regards
Uffe
Re: [PATCH RFC 2/4] mmc: sdhci-msm: Add and use voltage regulator related APIs
In reply to Vijay ViswanathQuoted 8 lines · Vijay Viswanath
From: Asutosh Das <[email protected]>
Some platforms require that the voltage switching happen only after the register write occurs and controller is ready for the switch. When the controller is ready, it will inform through power irq.
Add voltage regulator APIs and use them during power irq to switch voltage instead of relying on core layer voltage switching.
This is way to simplified. 529 lines of new code deserves some more explanations.
Quoted 2 lines
Change-Id: Iaa98686e71a5bfe0092c68e9ffa563b060c5ac60
Remove this.
Quoted 6 lines
Signed-off-by Asutosh Das <[email protected]>Signed-off-by Venkat Gopalakrishnan <[email protected]>Signed-off-by Subhash Jadavani <[email protected]>Signed-off-by Vijay Viswanath <[email protected]>--- .../devicetree/bindings/mmc/sdhci-msm.txt | 27 +-
Split DT changes and add DT maintainers.
Quoted 17 lines
drivers/mmc/host/sdhci-msm.c | 537 +++++++++++++++++++-- 2 files changed, 529 insertions(+), 35 deletions(-)Documentation/devicetree/bindings/mmc/sdhci-msm.txt +6
-0@@ -23,6 +23,22 @@ Required properties: "xo" - TCXO clock (optional) "cal" - reference clock for RCLK delay calibration (optional) "sleep" - sleep clock for RCLK delay calibration (optional) +- <supply-name>-supply: phandle to the regulator device tree node if voltage + regulators needs to be handled from within sdhci-msm layer. + Supported "supply-name" are "vdd" and "vdd-io". + +Optional Properties: + - qcom,<supply>-always-on - specifies whether supply should be kept
Documentation/devicetree/bindings/mmc/sdhci-msm.txt Required properties: · line 41
Quoted 10 lines
Documentation/devicetree/bindings/mmc/sdhci-msm.txt +10
-0+ "on" always. + - qcom,<supply>-lpm_sup - specifies whether supply can be kept in low + power mode (lpm). + - qcom,<supply>-voltage_level - specifies voltage levels for supply. + Should be specified in pairs (min, max), units uV. + - qcom,<supply>-current_level - specifies load levels for supply in lpm + or high power mode (hpm). Should be specified in + pairs (lpm, hpm), units uA. + +
This looks really weird.
What's so special here that requires you to have your own specific regulator bindings?
Quoted 131 lines
Documentation/devicetree/bindings/mmc/sdhci-msm.txt +9
-2Example:@@ -33,8 +49,15 @@ Example: bus-width = <8>; non-removable; - vmmc-supply = <&pm8941_l20>; - vqmmc-supply = <&pm8941_s3>; + vdd-supply = <&pm8941_l20>; + qcom,vdd-voltage-level = <2950000 2950000>; + qcom,vdd-current-level = <9000 800000>; + + vdd-io-supply = <&pm8941_s3>; + qcom,vdd-io-always-on; + qcom,vdd-io-lpm-sup; + qcom,vdd-io-voltage-level = <1800000 2950000>; + qcom,vdd-io-current-level = <6 22000>; pinctrl-names = "default"; pinctrl-0 = <&sdc1_clk &sdc1_cmd &sdc1_data>;drivers/mmc/host/sdhci-msm.c +88
-0@@ -213,6 +213,33 @@ struct sdhci_msm_offset sdhci_msm_offset_mci_present = { .core_ddr_config_2 = 0x1BC, }; +/* This structure keeps information per regulator */ +struct sdhci_msm_reg_data { +/* voltage regulator handle */ +struct regulator *reg; +/* regulator name */ +const char *name; +/* voltage level to be set */ +u32 low_vol_level; +u32 high_vol_level; +/* Load values for low power and high power mode */ +u32 lpm_uA; +u32 hpm_uA; +/* is this regulator enabled? */ +bool is_enabled; +/* is this regulator needs to be always on? */ +bool is_always_on; +/* is low power mode setting required for this regulator? */ +bool lpm_sup; +bool set_voltage_sup; +}; + +struct sdhci_msm_pltfm_data { +/* Change-Id: Ide3a658ad51a3c3d4a05c47c0e8f013f647c9516 */ +struct sdhci_msm_reg_data *vdd_data; +struct sdhci_msm_reg_data *vdd_io_data; +}; +struct sdhci_msm_host {struct platform_device *pdev;void __iomem *core_mem;/* MSM SDCC mapped address */ @@ -234,6 +261,8 @@ struct sdhci_msm_host {u32 caps_0;bool mci_removed;const struct sdhci_msm_offset *offset; +bool pltfm_init_done; +struct sdhci_msm_pltfm_data pdata; };/* @@ -298,6 +327,336 @@ void sdhci_msm_vendor_writel_relaxed(u32 val, struct sdhci_host *host,writel_relaxed (val, base_addr + offset); } +enum vdd_io_level { +/* set vdd_io_data->low_vol_level */ +VDD_IO_LOW , +/* set vdd_io_data->high_vol_level */ +VDD_IO_HIGH , +/* +* set whatever there in voltage_level (third argument) of +* sdhci_msm_set_vdd_io_vol() function. +*/ +VDD_IO_SET_LEVEL , +}; + +#define MAX_PROP_SIZE 32 +static int sdhci_msm_dt_parse_vreg_info (struct device *dev, +struct sdhci_msm_reg_data **vreg_data,const char *vreg_name) +{ +int len, ret =0 ; +const __be32 *prop; +char prop_name[MAX_PROP_SIZE ]; +struct sdhci_msm_reg_data *vreg; +struct device_node *np = dev->of_node; + +snprintf (prop_name,MAX_PROP_SIZE ,"%s-supply" , vreg_name); +if (!of_parse_phandle (np, prop_name,0 )) { +dev_warn (dev,"No internal vreg data found for %s\n" , + vreg_name); + ret = -EINVAL ; +return ret; + } + vreg =devm_kzalloc (dev,sizeof (*vreg),GFP_KERNEL ); +if (!vreg) { + ret = -ENOMEM ; +return ret; + } + vreg->name = vreg_name; +snprintf (prop_name,MAX_PROP_SIZE , +"qcom,%s-always-on" , vreg_name); +if (of_get_property (np, prop_name,NULL )) + vreg->is_always_on = true; + +snprintf (prop_name,MAX_PROP_SIZE , +"qcom,%s-lpm-sup" , vreg_name); +if (of_get_property (np, prop_name,NULL )) + vreg->lpm_sup = true; +snprintf (prop_name,MAX_PROP_SIZE , +"qcom,%s-voltage-level" , vreg_name); + prop =of_get_property (np, prop_name, &len); +if (!prop || (len != (2 *sizeof (__be32)))) { +dev_warn (dev,"%s %s property\n" , + prop ?"invalid format" :"no" , prop_name); + }else { + vreg->low_vol_level =be32_to_cpup (&prop[0 ]); + vreg->high_vol_level =be32_to_cpup (&prop[1 ]); + } +snprintf (prop_name,MAX_PROP_SIZE , +"qcom,%s-current-level" , vreg_name); + prop =of_get_property (np, prop_name, &len); +if (!prop || (len != (2 *sizeof (__be32)))) { + dev_warn(dev, "%s %s property\n",
drivers/mmc/host/sdhci-msm.c void sdhci_msm_vendor_writel_relaxed(u32 val, struct sdhci_host *host, · line 398
Quoted 10 lines
drivers/mmc/host/sdhci-msm.c +10
-0+ prop ? "invalid format" : "no", prop_name); + }else { + vreg->lpm_uA =be32_to_cpup (&prop[0 ]); + vreg->hpm_uA =be32_to_cpup (&prop[1 ]); + } + *vreg_data = vreg; +dev_dbg (dev,"%s: %s %s vol=[%d %d]uV, curr=[%d %d]uA\n" , + vreg->name, vreg->is_always_on ?"always_on," :"" , + vreg->lpm_sup ?"lpm_sup," :"" , vreg->low_vol_level, + vreg->high_vol_level, vreg->lpm_uA, vreg->hpm_uA);
So again, I don't get why this isn't being implemented as a regular regulator and why is this code in the mmc driver?
Quoted 43 lines
drivers/mmc/host/sdhci-msm.c +43
-0+ +return ret; +} + +/* Regulator utility functions */ +static int sdhci_msm_vreg_init_reg (struct device *dev, +struct sdhci_msm_reg_data *vreg) +{ +int ret =0 ; + +/* check if regulator is already initialized? */ +if (vreg->reg) + goto out; + +/* Get the regulator handle */ + vreg->reg =devm_regulator_get (dev, vreg->name); +if (IS_ERR (vreg->reg)) { + ret =PTR_ERR (vreg->reg); +pr_err ("%s: devm_regulator_get(%s) failed. ret=%d\n" , + __func__, vreg->name, ret); + goto out; + } + +if (regulator_count_voltages (vreg->reg) >0 ) { + vreg->set_voltage_sup = true; +/* sanity check */ +if (!vreg->high_vol_level || !vreg->hpm_uA) { +pr_err ("%s: %s invalid constraints specified high_vol_level: %d hpm_uA: %d\n" , + __func__, vreg->name, vreg->high_vol_level, + vreg->hpm_uA); + ret = -EINVAL ; + } + } + +out: +return ret; +} + +static void sdhci_msm_vreg_deinit_reg (struct sdhci_msm_reg_data *vreg) +{ +if (vreg->reg) +devm_regulator_put (vreg->reg); +}
drivers/mmc/host/sdhci-msm.c void sdhci_msm_vendor_writel_relaxed(u32 val, struct sdhci_host *host, · line 451
Quoted 10 lines
drivers/mmc/host/sdhci-msm.c +10
-0+ +static int sdhci_msm_vreg_set_optimum_mode (struct sdhci_msm_reg_data + *vreg,int uA_load) +{ +int ret =0 ; + +/* +* regulators that do not support regulator_set_voltage also +* do not support regulator_set_optimum_mode +*/
If that's the case, the regulator core should return proper error codes and you should need to have these kind of checks here. Right?
Or at least there should be a helper function telling what you can do with your regulator, instead of encoding it at in the mmc driver.
Quoted 11 lines
drivers/mmc/host/sdhci-msm.c +11
-0+if (vreg->set_voltage_sup) { + ret =regulator_set_load (vreg->reg, uA_load); +if (ret <0 ) +pr_err ("%s: regulator_set_load(reg=%s,uA_load=%d) failed. ret=%d\n" , + __func__, vreg->name, uA_load, ret); +else +/* +* regulator_set_load() can return non zero +* value even for success case. +*/ + ret =0 ;
drivers/mmc/host/sdhci-msm.c void sdhci_msm_vendor_writel_relaxed(u32 val, struct sdhci_host *host, · line 472
Quoted 10 lines
drivers/mmc/host/sdhci-msm.c +10
-0+ } +return ret; +} + +static int sdhci_msm_vreg_set_voltage (struct sdhci_msm_reg_data *vreg, +int min_uV,int max_uV) +{ +int ret =0 ; + +if (vreg && vreg->set_voltage_sup) {
Ditto.
Quoted 24 lines
drivers/mmc/host/sdhci-msm.c +24
-0+ ret =regulator_set_voltage (vreg->reg, min_uV, max_uV); +if (ret) { +pr_err ("%s: regulator_set_voltage(%s)failed. min_uV=%d,max_uV=%d,ret=%d\n" , + __func__, vreg->name, min_uV, max_uV, ret); + } + } + +return ret; +} + +static int sdhci_msm_vreg_enable (struct sdhci_msm_reg_data *vreg) +{ +int ret =0 ; + +/* Put regulator in HPM (high power mode) */ + ret =sdhci_msm_vreg_set_optimum_mode (vreg, vreg->hpm_uA); +if (ret <0 ) +return ret; + +if (!vreg->is_enabled) { +/* Set voltage level */ + ret =sdhci_msm_vreg_set_voltage (vreg, vreg->high_vol_level, + vreg->high_vol_level); +if (ret)
drivers/mmc/host/sdhci-msm.c void sdhci_msm_vendor_writel_relaxed(u32 val, struct sdhci_host *host, · line 506
Quoted 10 lines
drivers/mmc/host/sdhci-msm.c +10
-0+return ret; + } + ret =regulator_enable (vreg->reg); +if (ret) { +pr_err ("%s: regulator_enable(%s) failed. ret=%d\n" , + __func__, vreg->name, ret); +return ret; + } + vreg->is_enabled = true; +return ret;
Why don't you use the mmc_regulator_*() APIs? It seems like lots of open coding here.
Quoted 26 lines
drivers/mmc/host/sdhci-msm.c +26
-0+} + +static int sdhci_msm_vreg_disable (struct sdhci_msm_reg_data *vreg) +{ +int ret =0 ; + +/* Never disable regulator marked as always_on */ +if (vreg->is_enabled && !vreg->is_always_on) { + ret =regulator_disable (vreg->reg); +if (ret) { +pr_err ("%s: regulator_disable(%s) failed. ret=%d\n" , + __func__, vreg->name, ret); + goto out; + } + vreg->is_enabled = false; + + ret =sdhci_msm_vreg_set_optimum_mode (vreg,0 ); +if (ret <0 ) + goto out; + +/* Set min. voltage level to 0 */ + ret =sdhci_msm_vreg_set_voltage (vreg,0 , vreg->high_vol_level); +if (ret) + goto out; + }else if (vreg->is_enabled && vreg->is_always_on) { +if (vreg->lpm_sup) {
drivers/mmc/host/sdhci-msm.c void sdhci_msm_vendor_writel_relaxed(u32 val, struct sdhci_host *host, · line 542
Quoted 10 lines
drivers/mmc/host/sdhci-msm.c +10
-0+/* Put always_on regulator in LPM (low power mode) */ + ret =sdhci_msm_vreg_set_optimum_mode (vreg, + vreg->lpm_uA); +if (ret <0 ) + goto out; + } + } +out: +return ret; +}
Ditto.
[...]
Quoted 152 lines
drivers/mmc/host/sdhci-msm.c +108
-1+ +/* Parse platform data */ +static void sdhci_msm_populate_pdata (struct device *dev, +struct sdhci_msm_pltfm_data *pdata) +{ +int ret =0 ; + + ret =sdhci_msm_dt_parse_vreg_info (dev, &pdata->vdd_data,"vdd" ); +if (ret) +dev_warn (dev,"failed parsing vdd data (%d)\n" , ret); + + ret =sdhci_msm_dt_parse_vreg_info (dev, &pdata->vdd_io_data,"vdd-io" ); +if (ret) +dev_warn (dev,"failed parsing vdd-io data (%d)\n" , ret); + +} +static unsigned int msm_get_clock_rate_for_bus_mode (struct sdhci_host *host,unsigned int clock) {@@ -1326,6 +1685,7 @@ static void sdhci_msm_handle_pwr_irq(struct sdhci_host *host, int irq)u32 pwr_state =0 , io_level =0 ;u32 config;const struct sdhci_msm_offset *msm_offset = msm_host->offset; +int ret =0 ; irq_status =sdhci_msm_vendor_readl_relaxed (host, msm_offset->core_pwrctl_status);@@ -1358,21 +1718,54 @@ static void sdhci_msm_handle_pwr_irq(struct sdhci_host *host, int irq)/* Handle BUS ON/OFF*/ if (irq_status &CORE_PWRCTL_BUS_ON ) { + ret =sdhci_msm_setup_vreg (&msm_host->pdata, true, false); +if (!ret) { + ret =sdhci_msm_set_vdd_io_vol (&msm_host->pdata, +VDD_IO_HIGH ,0 ); +if (ret) +pr_err ("%s: error setting vdd io in BUS_ON: %d\n" , +mmc_hostname (host->mmc), ret); + }else { +pr_err ("%s: error setting up vreg ON : %d\n" , +mmc_hostname (host->mmc), ret); + } pwr_state =REQ_BUS_ON ; io_level =REQ_IO_HIGH ; irq_ack |=CORE_PWRCTL_BUS_SUCCESS ; }if (irq_status &CORE_PWRCTL_BUS_OFF ) { +if (msm_host->pltfm_init_done) + ret =sdhci_msm_setup_vreg (&msm_host->pdata, + false, false); +if (!ret) { + ret =sdhci_msm_set_vdd_io_vol (&msm_host->pdata, +VDD_IO_LOW ,0 ); +if (ret) +pr_err ("%s: error setting vdd io in BUS_OFF: %d\n" , +mmc_hostname (host->mmc), ret); + }else { +pr_err ("%s: error setting up vreg OFF: %d\n" , +mmc_hostname (host->mmc), ret); + } pwr_state =REQ_BUS_OFF ; io_level =REQ_IO_LOW ; irq_ack |=CORE_PWRCTL_BUS_SUCCESS ; }/* Handle IO LOW/HIGH */ if (irq_status &CORE_PWRCTL_IO_LOW ) { + ret =sdhci_msm_set_vdd_io_vol (&msm_host->pdata,VDD_IO_LOW ,0 ); +if (ret) +pr_err ("%s: error setting up vdd io low: %d\n" , +mmc_hostname (host->mmc), ret); io_level =REQ_IO_LOW ; irq_ack |=CORE_PWRCTL_IO_SUCCESS ; }if (irq_status &CORE_PWRCTL_IO_HIGH ) { + ret =sdhci_msm_set_vdd_io_vol (&msm_host->pdata, +VDD_IO_HIGH ,0 ); +if (ret) +pr_err ("%s: error setting up vdd io high: %d\n" , +mmc_hostname (host->mmc), ret); io_level =REQ_IO_HIGH ; irq_ack |=CORE_PWRCTL_IO_SUCCESS ; }@@ -1380,7 +1773,7 @@ static void sdhci_msm_handle_pwr_irq(struct sdhci_host *host, int irq)/* * The driver has to acknowledge the interrupt, switch voltages and * report back if it succeded or not to this register. The voltage -* switches are handled by the sdhci core, so just report success. +* switches may be handled by the sdhci core, so just report success. */ sdhci_msm_vendor_writel_relaxed (irq_ack, host, msm_offset->core_pwrctl_ctl);@@ -1612,6 +2005,74 @@ static void sdhci_msm_set_regulator_caps(struct sdhci_msm_host *msm_host)pr_debug ("%s: supported caps: 0x%08x\n" ,mmc_hostname (mmc), caps); } +static void sdhci_msm_set_default_hw_caps (struct device *dev, +struct sdhci_msm_host *msm_host, +struct sdhci_host *host) +{ +u32 version, config; +u16 minor; +u8 major; +const struct sdhci_msm_offset *msm_offset = msm_host->offset; +struct sdhci_msm_reg_data *vdd_io_reg = msm_host->pdata.vdd_io_data; +u32 caps =0 ; + + version =sdhci_msm_vendor_readl_relaxed (host, + msm_offset->core_mci_version); + major = (version &CORE_VERSION_MAJOR_MASK ) >> +CORE_VERSION_MAJOR_SHIFT ; + minor = version &CORE_VERSION_MINOR_MASK ; +dev_dbg (dev,"MCI Version: 0x%08x, major: 0x%04x, minor: 0x%02x\n" , + version, major, minor); + +/* +* If voltage regulators are controlled by msm host layer and +* IO voltage regulator can support 1.8V, we need to +* update the capabilities here before sdhci host is added. +*/ +if (vdd_io_reg && (vdd_io_reg->low_vol_level <1950000 )) + caps |=CORE_1_8V_SUPPORT ; +if (vdd_io_reg && (vdd_io_reg->low_vol_level >2700000 )) + caps |=CORE_3_0V_SUPPORT ; +if (caps) { + msm_host->caps_0 |= caps; + config =readl_relaxed (host->ioaddr + + msm_offset->core_vendor_spec); + config |=CORE_IO_PAD_PWR_SWITCH_EN ; +writel_relaxed (config, + host->ioaddr + msm_offset->core_vendor_spec); + } + + caps =readl_relaxed (host->ioaddr +SDHCI_CAPABILITIES ); + +if (major ==1 && minor >=0x42 ) + msm_host->use_14lpp_dll_reset = true; +/* +* SDCC 5 controller with major version 1, minor version 0x34 and later +* with HS 400 mode support will use CM DLL instead of CDC LP 533 DLL. +*/ +if (major ==1 && minor <0x34 ) + msm_host->use_cdclp533 = true; + +/* +* Support for some capabilities is not advertised by newer +* controller versions and must be explicitly enabled. +*/ +if (major >=1 && minor !=0x11 && minor !=0x12 ) { + + vdd_io_reg = msm_host->pdata.vdd_io_data; + caps |=SDHCI_CAN_VDD_300 |SDHCI_CAN_DO_8BIT ;
drivers/mmc/host/sdhci-msm.c static void sdhci_msm_set_regulator_caps(struct sdhci_msm_host *msm_host) · line 2073
Quoted 10 lines
drivers/mmc/host/sdhci-msm.c +10
-0+if (msm_host->caps_0 &CORE_1_8V_SUPPORT ) + caps |=CORE_1_8V_SUPPORT ; + } + msm_host->caps_0 |= caps; +writel_relaxed (msm_host->caps_0, host->ioaddr + + msm_offset->core_vendor_spec_capabilities0); + +/* Set more host capabilities */ + msm_host->mmc->caps |=MMC_CAP_WAIT_WHILE_BUSY ; + msm_host->mmc->caps2 |=MMC_CAP2_BOOTPART_NOACC ;
Is really all above only related to regulators, as according to the change log? Probably not.
Reaching this point in the review, it certainly seems like the change needs to be split up in quite a few smaller pieces. Can you please do that!?
[...]
Kind regards
Uffe
Re: [PATCH RFC 1/4] mmc: host: Register changes for sdcc V5
In reply to Ulf HanssonQuoted 9 lines · Ulf Hansson
Quoted 7 lines · Vijay Viswanath
From: Sayali Lokhande <[email protected]>
For SDCC version 5.0.0, MCI registers are removed from SDCC interface and some registers are moved to HC. This change is to support MCI register removal for msmfalcon. New compatible string "qcom,sdhci-msm-v5" is added for msmfalcon to support this change.
Quoted 4 lines
To simplify review, I would recommend to split this up in a few more pieces, a few re-factoring while the final change adds the qcom,sdhci-msm-v5 support.
Will do
Quoted 203 lines
Quoted 6 lines
Change-Id I0febfd9bb2222436a8eff20c20107dd4180c9781Signed-off-by Sayali Lokhande <[email protected]>Signed-off-by Vijay Viswanath <[email protected]>--- .../devicetree/bindings/mmc/sdhci-msm.txt | 5 +-Please move DT changes into separate patches and make sure to sent it to DT maintainers as well.
Quoted 23 lines
drivers/mmc/host/sdhci-msm.c | 485 +++++++++++++++------ 2 files changed, 365 insertions(+), 125 deletions(-)Documentation/devicetree/bindings/mmc/sdhci-msm.txt +4
-1@@ -4,7 +4,10 @@ This file documents differences between the core properties in mmc.txt and the properties used by the sdhci-msm driver. Required properties: -- compatible: Should contain "qcom,sdhci-msm-v4". +- compatible: Should contain "qcom,sdhci-msm-v4" or "qcom,sdhci-msm-v5". + For SDCC version 5.0.0, MCI registers are removed from SDCC + interface and some registers are moved to HC. New compatible + string is added to support this change - "qcom,sdhci-msm-v5". - reg: Base address and length of the register in the following order: - Host controller register map (required) - SD Core register map (required)drivers/mmc/host/sdhci-msm.c +0
-0[...]
Quoted 2 lines
+struct
sdhci_msm_offset{I think a better idea is to create a struct
sdhci_msm_variantand make it contain all the variant specific data. So, not only the offsets, but other variant data as well.More comments below.
Quoted 99 lines
drivers/mmc/host/sdhci-msm.c +90
-0+u32 core_mci_data_cnt; +u32 core_mci_status; +u32 core_mci_fifo_cnt; +u32 core_mci_version; +u32 core_generics; +u32 core_testbus_config; +u32 core_testbus_sel2_bit; +u32 core_testbus_ena; +u32 core_testbus_sel2; +u32 core_pwrctl_status; +u32 core_pwrctl_mask; +u32 core_pwrctl_clear; +u32 core_pwrctl_ctl; +u32 core_sdcc_debug_reg; +u32 core_dll_config; +u32 core_dll_status; +u32 core_vendor_spec; +u32 core_vendor_spec_adma_err_addr0; +u32 core_vendor_spec_adma_err_addr1; +u32 core_vendor_spec_func2; +u32 core_vendor_spec_capabilities0; +u32 core_ddr_200_cfg; +u32 core_vendor_spec3; +u32 core_dll_config_2; +u32 core_ddr_config; +u32 core_ddr_config_2; +}; + +struct sdhci_msm_offset sdhci_msm_offset_mci_removed = { + .core_mci_data_cnt =0x35c , + .core_mci_status =0x324 , + .core_mci_fifo_cnt =0x308 , + .core_mci_version =0x318 , + .core_generics =0x320 , + .core_testbus_config =0x32c , + .core_testbus_sel2_bit =3 , + .core_testbus_ena = (1 <<31 ), + .core_testbus_sel2 = (1 <<3 ), + .core_pwrctl_status =0x240 , + .core_pwrctl_mask =0x244 , + .core_pwrctl_clear =0x248 , + .core_pwrctl_ctl =0x24c , + .core_sdcc_debug_reg =0x358 , + .core_dll_config =0x200 , + .core_dll_status =0x208 , + .core_vendor_spec =0x20c , + .core_vendor_spec_adma_err_addr0 =0x214 , + .core_vendor_spec_adma_err_addr1 =0x218 , + .core_vendor_spec_func2 =0x210 , + .core_vendor_spec_capabilities0 =0x21c , + .core_ddr_200_cfg =0x224 , + .core_vendor_spec3 =0x250 , + .core_dll_config_2 =0x254 , + .core_ddr_config =0x258 , + .core_ddr_config_2 =0x25c , +}; + +struct sdhci_msm_offset sdhci_msm_offset_mci_present = { + .core_mci_data_cnt =0x30 , + .core_mci_status =0x34 , + .core_mci_fifo_cnt =0x44 , + .core_mci_version =0x050 , + .core_generics =0x70 , + .core_testbus_config =0x0CC , + .core_testbus_sel2_bit =4 , + .core_testbus_ena = (1 <<3 ), + .core_testbus_sel2 = (1 <<4 ), + .core_pwrctl_status =0xDC , + .core_pwrctl_mask =0xE0 , + .core_pwrctl_clear =0xE4 , + .core_pwrctl_ctl =0xE8 , + .core_sdcc_debug_reg =0x124 , + .core_dll_config =0x100 , + .core_dll_status =0x108 , + .core_vendor_spec =0x10C , + .core_vendor_spec_adma_err_addr0 =0x114 , + .core_vendor_spec_adma_err_addr1 =0x118 , + .core_vendor_spec_func2 =0x110 , + .core_vendor_spec_capabilities0 =0x11C , + .core_ddr_200_cfg =0x184 , + .core_vendor_spec3 =0x1B0 , + .core_dll_config_2 =0x1B4 , + .core_ddr_config =0x1B8 , + .core_ddr_config_2 =0x1BC , +}; +struct sdhci_msm_host {struct platform_device *pdev;void __iomem *core_mem;/* MSM SDCC mapped address */ @@ -156,8 +232,72 @@ struct sdhci_msm_host {wait_queue_head_t pwr_irq_wait;bool pwr_irq_flag;u32 caps_0; +bool mci_removed; +const struct sdhci_msm_offset *offset; }; +/* +* APIs to write to vendor specific registers which were there in the core_mem drivers/mmc/host/sdhci-msm.c struct sdhci_msm_host { · line 250
Quoted 10 lines
drivers/mmc/host/sdhci-msm.c +10
-0+* region before MCI was removed. +*/ +u8 sdhci_msm_vendor_readb_relaxed (struct sdhci_host *host,u32 offset) +{ +struct sdhci_pltfm_host *pltfm_host =sdhci_priv (host); +struct sdhci_msm_host *msm_host =sdhci_pltfm_priv (pltfm_host); +void __iomem *base_addr; + +if (msm_host->mci_removed) + base_addr = host->ioaddr;I would rather use a separate set of functions, which you assign at ->probe().
That may speed things up a little bit, as you don't need to check for "
mci_removed", each time in these read/write functions.Quoted 5 lines
drivers/mmc/host/sdhci-msm.c +5
-0+else + base_addr = msm_host->core_mem; + +return readb_relaxed (base_addr + offset); +}[...]
Quoted 15 lines
static const struct of_device_id sdhci_msm_dt_match[] = { { .compatible = "qcom,sdhci-msm-v4" },drivers/mmc/host/sdhci-msm.c +2
-0+ {.compatible = "qcom,sdhci-msm-v5"}, {}, };@@ -1430,6 +1651,7 @@ static int sdhci_msm_probe(struct platform_device *pdev)u16 host_version, core_minor;u32 core_version, config;u8 core_major; +const struct sdhci_msm_offset *msm_offset; host =sdhci_pltfm_init (pdev, &sdhci_msm_pdata,sizeof (*msm_host));if (IS_ERR (host))drivers/mmc/host/sdhci-msm.c static int sdhci_msm_probe(struct platform_device *pdev) · line 1672
Quoted 6 lines
drivers/mmc/host/sdhci-msm.c +3
-0@@ -1445,6 +1667,15 @@ static int sdhci_msm_probe(struct platform_device *pdev)if (ret) goto pltfm_free; +if (of_find_compatible_node (NULL ,NULL ,"qcom,sdhci-msm-v5" )) { + msm_host->mci_removed = true; + msm_host->offset = &sdhci_msm_offset_mci_removed;I would suggest to extend your array of "struct
of_device_id" to use the .data member to store all the variant specific data (such as the offsets for example).Then you can use
of_device_get_match_data(), to get the variant data.drivers/mmc/host/sdhci-msm.c static int sdhci_msm_probe(struct platform_device *pdev) · line 1678
Quoted 6 lines
drivers/mmc/host/sdhci-msm.c +6
-0+ }else { + msm_host->mci_removed = false; + msm_host->offset = &sdhci_msm_offset_mci_present; + } + msm_offset = msm_host->offset; +
Quoted 9 lines
[...]
Kind regards
Uffe
--
To unsubscribe from this list: send the line "unsubscribe linux-mmc" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
I will explore the approach you suggested and will get back to you.
Thanks,
Vijay
Re: [PATCH RFC 2/4] mmc: sdhci-msm: Add and use voltage regulator related APIs
In reply to Ulf HanssonQuoted 18 lines · Ulf Hansson
Quoted 8 lines · Vijay Viswanath
From: Asutosh Das <[email protected]>
Some platforms require that the voltage switching happen only after the register write occurs and controller is ready for the switch. When the controller is ready, it will inform through power irq.
Add voltage regulator APIs and use them during power irq to switch voltage instead of relying on core layer voltage switching.
This is way to simplified. 529 lines of new code deserves some more explanations.
Quoted 2 lines
Change-Id: Iaa98686e71a5bfe0092c68e9ffa563b060c5ac60
Remove this.
Quoted 9 lines
Quoted 6 lines
Signed-off-by Asutosh Das <[email protected]>Signed-off-by Venkat Gopalakrishnan <[email protected]>Signed-off-by Subhash Jadavani <[email protected]>Signed-off-by Vijay Viswanath <[email protected]>--- .../devicetree/bindings/mmc/sdhci-msm.txt | 27 +-Split DT changes and add DT maintainers.
Will do
Quoted 507 lines
Quoted 17 lines
drivers/mmc/host/sdhci-msm.c | 537 +++++++++++++++++++-- 2 files changed, 529 insertions(+), 35 deletions(-)Documentation/devicetree/bindings/mmc/sdhci-msm.txt +6
-0@@ -23,6 +23,22 @@ Required properties: "xo" - TCXO clock (optional) "cal" - reference clock for RCLK delay calibration (optional) "sleep" - sleep clock for RCLK delay calibration (optional) +- <supply-name>-supply: phandle to the regulator device tree node if voltage + regulators needs to be handled from within sdhci-msm layer. + Supported "supply-name" are "vdd" and "vdd-io". + +Optional Properties: + - qcom,<supply>-always-on - specifies whether supply should be keptDocumentation/devicetree/bindings/mmc/sdhci-msm.txt Required properties: · line 41
Quoted 10 lines
Documentation/devicetree/bindings/mmc/sdhci-msm.txt +10
-0+ "on" always. + - qcom,<supply>-lpm_sup - specifies whether supply can be kept in low + power mode (lpm). + - qcom,<supply>-voltage_level - specifies voltage levels for supply. + Should be specified in pairs (min, max), units uV. + - qcom,<supply>-current_level - specifies load levels for supply in lpm + or high power mode (hpm). Should be specified in + pairs (lpm, hpm), units uA. + +This looks really weird.
What's so special here that requires you to have your own specific regulator bindings?
Quoted 131 lines
Documentation/devicetree/bindings/mmc/sdhci-msm.txt +9
-2Example:@@ -33,8 +49,15 @@ Example: bus-width = <8>; non-removable; - vmmc-supply = <&pm8941_l20>; - vqmmc-supply = <&pm8941_s3>; + vdd-supply = <&pm8941_l20>; + qcom,vdd-voltage-level = <2950000 2950000>; + qcom,vdd-current-level = <9000 800000>; + + vdd-io-supply = <&pm8941_s3>; + qcom,vdd-io-always-on; + qcom,vdd-io-lpm-sup; + qcom,vdd-io-voltage-level = <1800000 2950000>; + qcom,vdd-io-current-level = <6 22000>; pinctrl-names = "default"; pinctrl-0 = <&sdc1_clk &sdc1_cmd &sdc1_data>;drivers/mmc/host/sdhci-msm.c +88
-0@@ -213,6 +213,33 @@ struct sdhci_msm_offset sdhci_msm_offset_mci_present = { .core_ddr_config_2 = 0x1BC, }; +/* This structure keeps information per regulator */ +struct sdhci_msm_reg_data { +/* voltage regulator handle */ +struct regulator *reg; +/* regulator name */ +const char *name; +/* voltage level to be set */ +u32 low_vol_level; +u32 high_vol_level; +/* Load values for low power and high power mode */ +u32 lpm_uA; +u32 hpm_uA; +/* is this regulator enabled? */ +bool is_enabled; +/* is this regulator needs to be always on? */ +bool is_always_on; +/* is low power mode setting required for this regulator? */ +bool lpm_sup; +bool set_voltage_sup; +}; + +struct sdhci_msm_pltfm_data { +/* Change-Id: Ide3a658ad51a3c3d4a05c47c0e8f013f647c9516 */ +struct sdhci_msm_reg_data *vdd_data; +struct sdhci_msm_reg_data *vdd_io_data; +}; +struct sdhci_msm_host {struct platform_device *pdev;void __iomem *core_mem;/* MSM SDCC mapped address */ @@ -234,6 +261,8 @@ struct sdhci_msm_host {u32 caps_0;bool mci_removed;const struct sdhci_msm_offset *offset; +bool pltfm_init_done; +struct sdhci_msm_pltfm_data pdata; };/* @@ -298,6 +327,336 @@ void sdhci_msm_vendor_writel_relaxed(u32 val, struct sdhci_host *host,writel_relaxed (val, base_addr + offset); } +enum vdd_io_level { +/* set vdd_io_data->low_vol_level */ +VDD_IO_LOW , +/* set vdd_io_data->high_vol_level */ +VDD_IO_HIGH , +/* +* set whatever there in voltage_level (third argument) of +* sdhci_msm_set_vdd_io_vol() function. +*/ +VDD_IO_SET_LEVEL , +}; + +#define MAX_PROP_SIZE 32 +static int sdhci_msm_dt_parse_vreg_info (struct device *dev, +struct sdhci_msm_reg_data **vreg_data,const char *vreg_name) +{ +int len, ret =0 ; +const __be32 *prop; +char prop_name[MAX_PROP_SIZE ]; +struct sdhci_msm_reg_data *vreg; +struct device_node *np = dev->of_node; + +snprintf (prop_name,MAX_PROP_SIZE ,"%s-supply" , vreg_name); +if (!of_parse_phandle (np, prop_name,0 )) { +dev_warn (dev,"No internal vreg data found for %s\n" , + vreg_name); + ret = -EINVAL ; +return ret; + } + vreg =devm_kzalloc (dev,sizeof (*vreg),GFP_KERNEL ); +if (!vreg) { + ret = -ENOMEM ; +return ret; + } + vreg->name = vreg_name; +snprintf (prop_name,MAX_PROP_SIZE , +"qcom,%s-always-on" , vreg_name); +if (of_get_property (np, prop_name,NULL )) + vreg->is_always_on = true; + +snprintf (prop_name,MAX_PROP_SIZE , +"qcom,%s-lpm-sup" , vreg_name); +if (of_get_property (np, prop_name,NULL )) + vreg->lpm_sup = true; +snprintf (prop_name,MAX_PROP_SIZE , +"qcom,%s-voltage-level" , vreg_name); + prop =of_get_property (np, prop_name, &len); +if (!prop || (len != (2 *sizeof (__be32)))) { +dev_warn (dev,"%s %s property\n" , + prop ?"invalid format" :"no" , prop_name); + }else { + vreg->low_vol_level =be32_to_cpup (&prop[0 ]); + vreg->high_vol_level =be32_to_cpup (&prop[1 ]); + } +snprintf (prop_name,MAX_PROP_SIZE , +"qcom,%s-current-level" , vreg_name); + prop =of_get_property (np, prop_name, &len); +if (!prop || (len != (2 *sizeof (__be32)))) { + dev_warn(dev, "%s %s property\n",drivers/mmc/host/sdhci-msm.c void sdhci_msm_vendor_writel_relaxed(u32 val, struct sdhci_host *host, · line 398
Quoted 10 lines
drivers/mmc/host/sdhci-msm.c +10
-0+ prop ? "invalid format" : "no", prop_name); + }else { + vreg->lpm_uA =be32_to_cpup (&prop[0 ]); + vreg->hpm_uA =be32_to_cpup (&prop[1 ]); + } + *vreg_data = vreg; +dev_dbg (dev,"%s: %s %s vol=[%d %d]uV, curr=[%d %d]uA\n" , + vreg->name, vreg->is_always_on ?"always_on," :"" , + vreg->lpm_sup ?"lpm_sup," :"" , vreg->low_vol_level, + vreg->high_vol_level, vreg->lpm_uA, vreg->hpm_uA);So again, I don't get why this isn't being implemented as a regular regulator and why is this code in the mmc driver?
Quoted 43 lines
drivers/mmc/host/sdhci-msm.c +43
-0+ +return ret; +} + +/* Regulator utility functions */ +static int sdhci_msm_vreg_init_reg (struct device *dev, +struct sdhci_msm_reg_data *vreg) +{ +int ret =0 ; + +/* check if regulator is already initialized? */ +if (vreg->reg) + goto out; + +/* Get the regulator handle */ + vreg->reg =devm_regulator_get (dev, vreg->name); +if (IS_ERR (vreg->reg)) { + ret =PTR_ERR (vreg->reg); +pr_err ("%s: devm_regulator_get(%s) failed. ret=%d\n" , + __func__, vreg->name, ret); + goto out; + } + +if (regulator_count_voltages (vreg->reg) >0 ) { + vreg->set_voltage_sup = true; +/* sanity check */ +if (!vreg->high_vol_level || !vreg->hpm_uA) { +pr_err ("%s: %s invalid constraints specified high_vol_level: %d hpm_uA: %d\n" , + __func__, vreg->name, vreg->high_vol_level, + vreg->hpm_uA); + ret = -EINVAL ; + } + } + +out: +return ret; +} + +static void sdhci_msm_vreg_deinit_reg (struct sdhci_msm_reg_data *vreg) +{ +if (vreg->reg) +devm_regulator_put (vreg->reg); +}drivers/mmc/host/sdhci-msm.c void sdhci_msm_vendor_writel_relaxed(u32 val, struct sdhci_host *host, · line 451
Quoted 10 lines
drivers/mmc/host/sdhci-msm.c +10
-0+ +static int sdhci_msm_vreg_set_optimum_mode (struct sdhci_msm_reg_data + *vreg,int uA_load) +{ +int ret =0 ; + +/* +* regulators that do not support regulator_set_voltage also +* do not support regulator_set_optimum_mode +*/ If that's the case, the regulator core should return proper error codes and you should need to have these kind of checks here. Right?
Or at least there should be a helper function telling what you can do with your regulator, instead of encoding it at in the mmc driver.
Quoted 11 lines
drivers/mmc/host/sdhci-msm.c +11
-0+if (vreg->set_voltage_sup) { + ret =regulator_set_load (vreg->reg, uA_load); +if (ret <0 ) +pr_err ("%s: regulator_set_load(reg=%s,uA_load=%d) failed. ret=%d\n" , + __func__, vreg->name, uA_load, ret); +else +/* +* regulator_set_load() can return non zero +* value even for success case. +*/ + ret =0 ;drivers/mmc/host/sdhci-msm.c void sdhci_msm_vendor_writel_relaxed(u32 val, struct sdhci_host *host, · line 472
Quoted 10 lines
drivers/mmc/host/sdhci-msm.c +10
-0+ } +return ret; +} + +static int sdhci_msm_vreg_set_voltage (struct sdhci_msm_reg_data *vreg, +int min_uV,int max_uV) +{ +int ret =0 ; + +if (vreg && vreg->set_voltage_sup) {Ditto.
Quoted 24 lines
drivers/mmc/host/sdhci-msm.c +24
-0+ ret =regulator_set_voltage (vreg->reg, min_uV, max_uV); +if (ret) { +pr_err ("%s: regulator_set_voltage(%s)failed. min_uV=%d,max_uV=%d,ret=%d\n" , + __func__, vreg->name, min_uV, max_uV, ret); + } + } + +return ret; +} + +static int sdhci_msm_vreg_enable (struct sdhci_msm_reg_data *vreg) +{ +int ret =0 ; + +/* Put regulator in HPM (high power mode) */ + ret =sdhci_msm_vreg_set_optimum_mode (vreg, vreg->hpm_uA); +if (ret <0 ) +return ret; + +if (!vreg->is_enabled) { +/* Set voltage level */ + ret =sdhci_msm_vreg_set_voltage (vreg, vreg->high_vol_level, + vreg->high_vol_level); +if (ret)drivers/mmc/host/sdhci-msm.c void sdhci_msm_vendor_writel_relaxed(u32 val, struct sdhci_host *host, · line 506
Quoted 10 lines
drivers/mmc/host/sdhci-msm.c +10
-0+return ret; + } + ret =regulator_enable (vreg->reg); +if (ret) { +pr_err ("%s: regulator_enable(%s) failed. ret=%d\n" , + __func__, vreg->name, ret); +return ret; + } + vreg->is_enabled = true; +return ret;Why don't you use the mmc_regulator_*() APIs? It seems like lots of open coding here.
Quoted 26 lines
drivers/mmc/host/sdhci-msm.c +26
-0+} + +static int sdhci_msm_vreg_disable (struct sdhci_msm_reg_data *vreg) +{ +int ret =0 ; + +/* Never disable regulator marked as always_on */ +if (vreg->is_enabled && !vreg->is_always_on) { + ret =regulator_disable (vreg->reg); +if (ret) { +pr_err ("%s: regulator_disable(%s) failed. ret=%d\n" , + __func__, vreg->name, ret); + goto out; + } + vreg->is_enabled = false; + + ret =sdhci_msm_vreg_set_optimum_mode (vreg,0 ); +if (ret <0 ) + goto out; + +/* Set min. voltage level to 0 */ + ret =sdhci_msm_vreg_set_voltage (vreg,0 , vreg->high_vol_level); +if (ret) + goto out; + }else if (vreg->is_enabled && vreg->is_always_on) { +if (vreg->lpm_sup) {drivers/mmc/host/sdhci-msm.c void sdhci_msm_vendor_writel_relaxed(u32 val, struct sdhci_host *host, · line 542
Quoted 10 lines
drivers/mmc/host/sdhci-msm.c +10
-0+/* Put always_on regulator in LPM (low power mode) */ + ret =sdhci_msm_vreg_set_optimum_mode (vreg, + vreg->lpm_uA); +if (ret <0 ) + goto out; + } + } +out: +return ret; +}Ditto.
[...]
Quoted 152 lines
drivers/mmc/host/sdhci-msm.c +108
-1+ +/* Parse platform data */ +static void sdhci_msm_populate_pdata (struct device *dev, +struct sdhci_msm_pltfm_data *pdata) +{ +int ret =0 ; + + ret =sdhci_msm_dt_parse_vreg_info (dev, &pdata->vdd_data,"vdd" ); +if (ret) +dev_warn (dev,"failed parsing vdd data (%d)\n" , ret); + + ret =sdhci_msm_dt_parse_vreg_info (dev, &pdata->vdd_io_data,"vdd-io" ); +if (ret) +dev_warn (dev,"failed parsing vdd-io data (%d)\n" , ret); + +} +static unsigned int msm_get_clock_rate_for_bus_mode (struct sdhci_host *host,unsigned int clock) {@@ -1326,6 +1685,7 @@ static void sdhci_msm_handle_pwr_irq(struct sdhci_host *host, int irq)u32 pwr_state =0 , io_level =0 ;u32 config;const struct sdhci_msm_offset *msm_offset = msm_host->offset; +int ret =0 ; irq_status =sdhci_msm_vendor_readl_relaxed (host, msm_offset->core_pwrctl_status);@@ -1358,21 +1718,54 @@ static void sdhci_msm_handle_pwr_irq(struct sdhci_host *host, int irq)/* Handle BUS ON/OFF*/ if (irq_status &CORE_PWRCTL_BUS_ON ) { + ret =sdhci_msm_setup_vreg (&msm_host->pdata, true, false); +if (!ret) { + ret =sdhci_msm_set_vdd_io_vol (&msm_host->pdata, +VDD_IO_HIGH ,0 ); +if (ret) +pr_err ("%s: error setting vdd io in BUS_ON: %d\n" , +mmc_hostname (host->mmc), ret); + }else { +pr_err ("%s: error setting up vreg ON : %d\n" , +mmc_hostname (host->mmc), ret); + } pwr_state =REQ_BUS_ON ; io_level =REQ_IO_HIGH ; irq_ack |=CORE_PWRCTL_BUS_SUCCESS ; }if (irq_status &CORE_PWRCTL_BUS_OFF ) { +if (msm_host->pltfm_init_done) + ret =sdhci_msm_setup_vreg (&msm_host->pdata, + false, false); +if (!ret) { + ret =sdhci_msm_set_vdd_io_vol (&msm_host->pdata, +VDD_IO_LOW ,0 ); +if (ret) +pr_err ("%s: error setting vdd io in BUS_OFF: %d\n" , +mmc_hostname (host->mmc), ret); + }else { +pr_err ("%s: error setting up vreg OFF: %d\n" , +mmc_hostname (host->mmc), ret); + } pwr_state =REQ_BUS_OFF ; io_level =REQ_IO_LOW ; irq_ack |=CORE_PWRCTL_BUS_SUCCESS ; }/* Handle IO LOW/HIGH */ if (irq_status &CORE_PWRCTL_IO_LOW ) { + ret =sdhci_msm_set_vdd_io_vol (&msm_host->pdata,VDD_IO_LOW ,0 ); +if (ret) +pr_err ("%s: error setting up vdd io low: %d\n" , +mmc_hostname (host->mmc), ret); io_level =REQ_IO_LOW ; irq_ack |=CORE_PWRCTL_IO_SUCCESS ; }if (irq_status &CORE_PWRCTL_IO_HIGH ) { + ret =sdhci_msm_set_vdd_io_vol (&msm_host->pdata, +VDD_IO_HIGH ,0 ); +if (ret) +pr_err ("%s: error setting up vdd io high: %d\n" , +mmc_hostname (host->mmc), ret); io_level =REQ_IO_HIGH ; irq_ack |=CORE_PWRCTL_IO_SUCCESS ; }@@ -1380,7 +1773,7 @@ static void sdhci_msm_handle_pwr_irq(struct sdhci_host *host, int irq)/* * The driver has to acknowledge the interrupt, switch voltages and * report back if it succeded or not to this register. The voltage -* switches are handled by the sdhci core, so just report success. +* switches may be handled by the sdhci core, so just report success. */ sdhci_msm_vendor_writel_relaxed (irq_ack, host, msm_offset->core_pwrctl_ctl);@@ -1612,6 +2005,74 @@ static void sdhci_msm_set_regulator_caps(struct sdhci_msm_host *msm_host)pr_debug ("%s: supported caps: 0x%08x\n" ,mmc_hostname (mmc), caps); } +static void sdhci_msm_set_default_hw_caps (struct device *dev, +struct sdhci_msm_host *msm_host, +struct sdhci_host *host) +{ +u32 version, config; +u16 minor; +u8 major; +const struct sdhci_msm_offset *msm_offset = msm_host->offset; +struct sdhci_msm_reg_data *vdd_io_reg = msm_host->pdata.vdd_io_data; +u32 caps =0 ; + + version =sdhci_msm_vendor_readl_relaxed (host, + msm_offset->core_mci_version); + major = (version &CORE_VERSION_MAJOR_MASK ) >> +CORE_VERSION_MAJOR_SHIFT ; + minor = version &CORE_VERSION_MINOR_MASK ; +dev_dbg (dev,"MCI Version: 0x%08x, major: 0x%04x, minor: 0x%02x\n" , + version, major, minor); + +/* +* If voltage regulators are controlled by msm host layer and +* IO voltage regulator can support 1.8V, we need to +* update the capabilities here before sdhci host is added. +*/ +if (vdd_io_reg && (vdd_io_reg->low_vol_level <1950000 )) + caps |=CORE_1_8V_SUPPORT ; +if (vdd_io_reg && (vdd_io_reg->low_vol_level >2700000 )) + caps |=CORE_3_0V_SUPPORT ; +if (caps) { + msm_host->caps_0 |= caps; + config =readl_relaxed (host->ioaddr + + msm_offset->core_vendor_spec); + config |=CORE_IO_PAD_PWR_SWITCH_EN ; +writel_relaxed (config, + host->ioaddr + msm_offset->core_vendor_spec); + } + + caps =readl_relaxed (host->ioaddr +SDHCI_CAPABILITIES ); + +if (major ==1 && minor >=0x42 ) + msm_host->use_14lpp_dll_reset = true; +/* +* SDCC 5 controller with major version 1, minor version 0x34 and later +* with HS 400 mode support will use CM DLL instead of CDC LP 533 DLL. +*/ +if (major ==1 && minor <0x34 ) + msm_host->use_cdclp533 = true; + +/* +* Support for some capabilities is not advertised by newer +* controller versions and must be explicitly enabled. +*/ +if (major >=1 && minor !=0x11 && minor !=0x12 ) { + + vdd_io_reg = msm_host->pdata.vdd_io_data; + caps |=SDHCI_CAN_VDD_300 |SDHCI_CAN_DO_8BIT ;drivers/mmc/host/sdhci-msm.c static void sdhci_msm_set_regulator_caps(struct sdhci_msm_host *msm_host) · line 2073
Quoted 10 lines
drivers/mmc/host/sdhci-msm.c +10
-0+if (msm_host->caps_0 &CORE_1_8V_SUPPORT ) + caps |=CORE_1_8V_SUPPORT ; + } + msm_host->caps_0 |= caps; +writel_relaxed (msm_host->caps_0, host->ioaddr + + msm_offset->core_vendor_spec_capabilities0); + +/* Set more host capabilities */ + msm_host->mmc->caps |=MMC_CAP_WAIT_WHILE_BUSY ; + msm_host->mmc->caps2 |=MMC_CAP2_BOOTPART_NOACC ;Is really all above only related to regulators, as according to the change log? Probably not.
Quoted 9 lines
Reaching this point in the review, it certainly seems like the change needs to be split up in quite a few smaller pieces. Can you please do that!?
[...]
Kind regards
Uffe
I am checking this. Will get back to you.
Thanks,
Vijay