ufs: ufs-qcom: Add support firmware managed platforms
Subsystems (5)
v4 cover ufs: ufs-qcom: Add support firmware managed platforms
On Qualcomm automotive SoC SA8255P, platform resource like clocks, interconnect, resets, regulators and PHY are configured remotely by firmware.
Logical power domain is used to abstract these resources in firmware and SCMI power protocol is used to request resource operations by using runtime PM framework APIs such as pm_runtime_get/put_sync to invoke power_on/_off calls from kernel respectively.
Changes from V1
1. Updated "dma-coherent" property type from boolean to just true.
2. Switched from QUIC mail ID to OSS mail ID.
3. Added Acknowledged by tag from Dmitry for patch 1/3
4. Added Reviewed-by tag from Manivannan for patch 1/3
Changes from V2
1. Added new patch "scsi: ufs: core Enforce minimum pm level for sysfs configuration" to prevent users from selecting unsupported power levels via sysfs.
2. Set minimum power level (UFS_PM_LVL_5) for SA8255P platforms.
3. Changed DT example in qcom,sa8255p-ufshc.yaml to use single-cell addressing instead of dual-cell addressing.
Changes from V3
1. Removed address-cells and size-cells from example DT in qcom,sa8255p-ufshc.yaml.
Ram Kumar Dwivedi (4):
MAINTAINERS: broaden UFS Qualcomm binding file pattern
dt-bindings: ufs: Document bindings for SA8255P UFS Host Controller
scsi: ufs: core Enforce minimum pm level for sysfs configuration
ufs: ufs-qcom: Add support for firmware-managed resource abstraction
.../bindings/ufs/qcom,sa8255p-ufshc.yaml | 56 ++++++ MAINTAINERS | 2 +- drivers/ufs/core/ufs-sysfs.c | 2 +- drivers/ufs/host/ufs-qcom.c | 164 +++++++++++++++++- drivers/ufs/host/ufs-qcom.h | 1 + include/ufs/ufshcd.h | 1 + 6 files changed, 223 insertions(+), 3 deletions(-) create mode 100644 Documentation/devicetree/bindings/ufs/qcom,sa8255p-ufshc.yaml
Signature · 1 line
2.34.1
PATCH v4 1/4 MAINTAINERS: broaden UFS Qualcomm binding file pattern
Update the file pattern for UFS Qualcomm devicetree bindings to match all files under Documentation/devicetree/bindings/ufs/qcom* instead of only qcom,ufs.yaml. This ensures maintainers are correctly notified for any related binding changes.
--- MAINTAINERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
MAINTAINERS +1 -1
@@ -26842,7 +26842,7 @@ M: Manivannan Sadhasivam <[email protected]> L: [email protected] L: [email protected] S: Maintained -F: Documentation/devicetree/bindings/ufs/qcom,ufs.yaml +F: Documentation/devicetree/bindings/ufs/qcom* F: drivers/ufs/host/ufs-qcom* UNIVERSAL FLASH STORAGE HOST CONTROLLER DRIVER RENESAS HOOKS
Signature · 1 line
2.34.1
PATCH v4 2/4 dt-bindings: ufs: Document bindings for SA8255P UFS Host Controller
In reply to Ram Kumar DwivediDocument the device tree bindings for UFS host controller on Qualcomm SA8255P platform which integrates firmware-managed resources.
The platform firmware implements the SCMI server and manages resources such as the PHY, clocks, regulators and resets via the SCMI power protocol. As a result, the OS-visible DT only describes the controller’s MMIO, interrupt, IOMMU and power-domain interfaces.
The generic "qcom,ufshc" and "jedec,ufs-2.0" compatible strings are removed from the binding, since this firmware managed design won't be compatible with the drivers doing full resource management.
--- .../bindings/ufs/qcom,sa8255p-ufshc.yaml | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 Documentation/devicetree/bindings/ufs/qcom,sa8255p-ufshc.yaml
Documentation/devicetree/bindings/ufs/qcom,sa8255p-ufshc.yaml new file +56 -0
@@ -0,0 +1,56 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/ufs/qcom,sa8255p-ufshc.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Qualcomm SA8255P UFS Host Controller + +maintainers: + - Ram Kumar Dwivedi <[email protected]> + +properties: + compatible: + const: qcom,sa8255p-ufshc + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + iommus: + maxItems: 1 + + dma-coherent: true + + power-domains: + maxItems: 1 + +required: + - compatible + - reg + - interrupts + - power-domains + - iommus + - dma-coherent + +allOf: + - $ref: ufs-common.yaml + +unevaluatedProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/arm-gic.h> + + ufshc@1d84000 { + compatible = "qcom,sa8255p-ufshc"; + reg = <0x01d84000 0x3000>; + interrupts = <GIC_SPI 265 IRQ_TYPE_LEVEL_HIGH>; + lanes-per-direction = <2>; + + iommus = <&apps_smmu 0x100 0x0>; + power-domains = <&scmi3_pd 0>; + dma-coherent; + };
Signature · 1 line
2.34.1
Re: [PATCH V4 2/4] dt-bindings: ufs: Document bindings for SA8255P UFS Host Controller
Documentation/devicetree/bindings/ufs/qcom,sa8255p-ufshc.yaml line 47
Quoted 7 lines · Ram Kumar Dwivedi
Documentation/devicetree/bindings/ufs/qcom,sa8255p-ufshc.yaml new file +7
-0+unevaluatedProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/arm-gic.h> + + ufshc@1d84000 {
Completely messed indentation.
Why did we ask to drop the unnecessary soc node? To make it simpler.
Even if you do not believe that code should be simpler, you should immediately spot the odd indentation.
For such trivialities you cannot get this patch merged. It's third revision which you send carelessly.
Best regards,
Krzysztof
Re: [PATCH V4 2/4] dt-bindings: ufs: Document bindings for SA8255P UFS Host Controller
Quoted 11 lines · Krzysztof Kozlowski
Documentation/devicetree/bindings/ufs/qcom,sa8255p-ufshc.yaml line 47
Quoted 7 lines · Ram Kumar Dwivedi
Documentation/devicetree/bindings/ufs/qcom,sa8255p-ufshc.yaml new file +7
-0+unevaluatedProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/arm-gic.h> + + ufshc@1d84000 {Completely messed indentation.
Quoted 7 lines
Why did we ask to drop the unnecessary soc node? To make it simpler.
Even if you do not believe that code should be simpler, you should immediately spot the odd indentation.
For such trivialities you cannot get this patch merged. It's third revision which you send carelessly.
Hi Krzysztof,
Apologies for the oversight. I missed correcting the indentation after removing the 'soc' node wrapper. I will ensure the example is correctly indented in the next version.
Thanks,
Ram
Quoted 4 lines
Best regards,
Krzysztof
PATCH v4 3/4 scsi: ufs: core Enforce minimum pm level for sysfs configuration
In reply to Ram Kumar DwivediSome UFS platforms only support a limited subset of power levels. Currently, the sysfs interface allows users to set any pm level without validating the minimum supported value. If an unsupported level is selected, suspend may fail.
Introduce an pm_lvl_min field in the ufs_hba structure and use it to clamp the pm level requested via sysfs so that only supported levels are accepted. Platforms that require a minimum pm level can set this field during probe.
--- drivers/ufs/core/ufs-sysfs.c | 2 +- include/ufs/ufshcd.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
drivers/ufs/core/ufs-sysfs.c +1 -1
@@ -141,7 +141,7 @@ static inline ssize_t ufs_sysfs_pm_lvl_store(struct device *dev,if (kstrtoul (buf,0 , &value))return -EINVAL ; -if (value >=UFS_PM_LVL_MAX ) +if (value >=UFS_PM_LVL_MAX || value < hba->pm_lvl_min)return -EINVAL ; if (ufs_pm_lvl_states[value].dev_state == UFS_DEEPSLEEP_PWR_MODE &&
include/ufs/ufshcd.h +1 -0
@@ -972,6 +972,7 @@ struct ufs_hba {enum ufs_pm_level rpm_lvl;/* Desired UFS power management level during system PM */ enum ufs_pm_level spm_lvl; +enum ufs_pm_level pm_lvl_min;int pm_op_in_progress;/* Auto-Hibernate Idle Timer register value */
Signature · 1 line
2.34.1
Bart Van Assche
reviewerRe: [PATCH V4 3/4] scsi: ufs: core Enforce minimum pm level for sysfs configuration
include/ufs/ufshcd.h struct ufs_hba { · line 978
Quoted 12 lines · Ram Kumar Dwivedi
include/ufs/ufshcd.h +1
-0@@ -972,6 +972,7 @@ struct ufs_hba {enum ufs_pm_level rpm_lvl;/* Desired UFS power management level during system PM */ enum ufs_pm_level spm_lvl; +enum ufs_pm_level pm_lvl_min;int pm_op_in_progress;/* Auto-Hibernate Idle Timer register value */
Please do not introduce new kernel-doc warnings and update the documentation block above this data structure when adding new members.
Thanks,
Bart.
Re: [PATCH V4 3/4] scsi: ufs: core Enforce minimum pm level for sysfs configuration
Quoted 14 lines · Bart Van Assche
include/ufs/ufshcd.h struct ufs_hba { · line 977
Quoted 11 lines · Ram Kumar Dwivedi
include/ufs/ufshcd.h +1
-0@@ -972,6 +972,7 @@ struct ufs_hba { enum ufs_pm_level rpm_lvl; /* Desired UFS power management level during system PM */ enum ufs_pm_level spm_lvl; + enum ufs_pm_level pm_lvl_min; int pm_op_in_progress; /* Auto-Hibernate Idle Timer register value */Please do not introduce new kernel-doc warnings and update the documentation block above this data structure when adding new members.
Hi Bart,
I will add the kernel-doc description for pm_lvl_min in the next version.
Thanks,
Ram
Quoted 4 lines
Thanks,
Bart.
Re: [PATCH V4 3/4] scsi: ufs: core Enforce minimum pm level for sysfs configuration
In reply to Ram Kumar DwivediQuoted 21 lines · Ram Kumar Dwivedi
Some UFS platforms only support a limited subset of power levels. Currently, the sysfs interface allows users to set any pm level without validating the minimum supported value. If an unsupported level is selected, suspend may fail.
Introduce an
pm_lvl_minfield in theufs_hbastructure and use it to clamp the pm level requested via sysfs so that only supported levels are accepted. Platforms that require a minimum pm level can set this field during probe.Signed-off-by Ram Kumar Dwivedi <[email protected]>--- drivers/ufs/core/ufs-sysfs.c | 2 +- include/ufs/ufshcd.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)drivers/ufs/core/ufs-sysfs.c +0
-0
drivers/ufs/core/ufs-sysfs.c static inline ssize_t ufs_sysfs_pm_lvl_store(struct device *dev, · line 144
Quoted 5 lines
drivers/ufs/core/ufs-sysfs.c +1
-1@@ -141,7 +141,7 @@ static inline ssize_t ufs_sysfs_pm_lvl_store(struct device *dev,if (kstrtoul (buf,0 , &value))return -EINVAL ; -if (value >=UFS_PM_LVL_MAX ) +if (value >=UFS_PM_LVL_MAX || value < hba->pm_lvl_min)
It makes sense that some platform support a limited subset of power levels. But each level is in increasing order of power savings, and you set it to UFS_PM_LVL_5. Don't you support UFS_PM_LVL_0 the full active mode?
Quoted 15 lines
drivers/ufs/core/ufs-sysfs.c +0
-0return -EINVAL ; if (ufs_pm_lvl_states[value].dev_state == UFS_DEEPSLEEP_PWR_MODE &&include/ufs/ufshcd.h +1
-0@@ -972,6 +972,7 @@ struct ufs_hba {enum ufs_pm_level rpm_lvl;/* Desired UFS power management level during system PM */ enum ufs_pm_level spm_lvl; +enum ufs_pm_level pm_lvl_min;int pm_op_in_progress;/* Auto-Hibernate Idle Timer register value */
Manivannan Sadhasivam
maintainerRe: [PATCH V4 3/4] scsi: ufs: core Enforce minimum pm level for sysfs configuration
Quoted 17 lines · Shawn Lin
Quoted 16 lines · Ram Kumar Dwivedi
Some UFS platforms only support a limited subset of power levels. Currently, the sysfs interface allows users to set any pm level without validating the minimum supported value. If an unsupported level is selected, suspend may fail.
Introduce an
pm_lvl_minfield in theufs_hbastructure and use it to clamp the pm level requested via sysfs so that only supported levels are accepted. Platforms that require a minimum pm level can set this field during probe.Signed-off-by Ram Kumar Dwivedi <[email protected]>--- drivers/ufs/core/ufs-sysfs.c | 2 +- include/ufs/ufshcd.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
Quoted 15 lines
drivers/ufs/core/ufs-sysfs.c static inline ssize_t ufs_sysfs_pm_lvl_store(struct device *dev, · line 143
Quoted 9 lines
drivers/ufs/core/ufs-sysfs.c +1
-1@@ -141,7 +141,7 @@ static inline ssize_t ufs_sysfs_pm_lvl_store(struct device *dev,if (kstrtoul (buf,0 , &value))return -EINVAL ; -if (value >=UFS_PM_LVL_MAX ) +if (value >=UFS_PM_LVL_MAX || value < hba->pm_lvl_min)It makes sense that some platform support a limited subset of power levels. But each level is in increasing order of power savings, and you set it to
UFS_PM_LVL_5. Don't you supportUFS_PM_LVL_0the full active mode?
These are the suspend levels, not runtime levels. So yes, our platform doesn't support full power mode when it is in suspend state.
- Mani
Quoted 14 lines
Quoted 13 lines
drivers/ufs/core/ufs-sysfs.c +0
-0return -EINVAL ; if (ufs_pm_lvl_states[value].dev_state == UFS_DEEPSLEEP_PWR_MODE &&include/ufs/ufshcd.h +1
-0@@ -972,6 +972,7 @@ struct ufs_hba {enum ufs_pm_level rpm_lvl;/* Desired UFS power management level during system PM */ enum ufs_pm_level spm_lvl; +enum ufs_pm_level pm_lvl_min;int pm_op_in_progress;/* Auto-Hibernate Idle Timer register value */
Signature · 1 line
மணிவண்ணன் சதாசிவம்
PATCH v4 4/4 ufs: ufs-qcom: Add support for firmware-managed resource abstraction
In reply to Ram Kumar DwivediAdd a compatible string for SA8255p platforms where resources such as PHY, clocks, regulators, and resets are managed by firmware through an SCMI server. Use the SCMI power protocol to abstract these resources and invoke power operations via runtime PM APIs (pm_runtime_get/put_sync).
Introduce vendor operations (vops) for SA8255p targets to enable SCMI- based resource control. In this model, capabilities like clock scaling and gating are not yet supported; these will be added incrementally.
--- drivers/ufs/host/ufs-qcom.c | 164 +++++++++++++++++++++++++++++++++++- drivers/ufs/host/ufs-qcom.h | 1 + 2 files changed, 164 insertions(+), 1 deletion(-)
drivers/ufs/host/ufs-qcom.c +163 -1
@@ -14,6 +14,7 @@#include <linux/of.h> #include <linux/phy/phy.h> #include <linux/platform_device.h> +#include <linux/pm_domain.h> #include <linux/reset-controller.h> #include <linux/time.h> #include <linux/unaligned.h>
@@ -619,6 +620,27 @@ static int ufs_qcom_hce_enable_notify(struct ufs_hba *hba,return err; } +static int ufs_qcom_fw_managed_hce_enable_notify (struct ufs_hba *hba, +enum ufs_notify_change_status status) +{ +struct ufs_qcom_host *host =ufshcd_get_variant (hba); + +switch (status) { +case PRE_CHANGE : +ufs_qcom_select_unipro_mode (host); +break ; +case POST_CHANGE : +ufs_qcom_enable_hw_clk_gating (hba); +ufs_qcom_ice_enable (host); +break ; +default : +dev_err (hba->dev,"Invalid status %d\n" , status); +return -EINVAL ; + } + +return 0 ; +} +/** * ufs_qcom_cfg_timers - Configure ufs qcom cfg timers *
@@ -789,6 +811,38 @@ static int ufs_qcom_resume(struct ufs_hba *hba, enum ufs_pm_op pm_op)return ufs_qcom_ice_resume (host); } +static int ufs_qcom_fw_managed_suspend (struct ufs_hba *hba,enum ufs_pm_op pm_op, +enum ufs_notify_change_status status) +{ +struct ufs_qcom_host *host =ufshcd_get_variant (hba); + +if (status ==PRE_CHANGE ) +return 0 ; + +if (hba->spm_lvl !=UFS_PM_LVL_5 ) { +dev_err (hba->dev,"Unsupported spm level %d\n" , hba->spm_lvl); +return -EINVAL ; + } + +pm_runtime_put_sync (hba->dev); + +return ufs_qcom_ice_suspend (host); +} + +static int ufs_qcom_fw_managed_resume (struct ufs_hba *hba,enum ufs_pm_op pm_op) +{ +struct ufs_qcom_host *host =ufshcd_get_variant (hba); +int err; + + err =pm_runtime_resume_and_get (hba->dev); +if (err) { +dev_err (hba->dev,"PM runtime resume failed: %d\n" , err); +return err; + } + +return ufs_qcom_ice_resume (host); +} +static void ufs_qcom_dev_ref_clk_ctrl (struct ufs_qcom_host *host,bool enable) { if (host->dev_ref_clk_ctrl_mmio &&
@@ -1421,6 +1475,55 @@ static void ufs_qcom_exit(struct ufs_hba *hba)phy_exit (host->generic_phy); } +static int ufs_qcom_fw_managed_init (struct ufs_hba *hba) +{ +struct device *dev = hba->dev; +struct ufs_qcom_host *host; +int err; + + host =devm_kzalloc (dev,sizeof (*host),GFP_KERNEL ); +if (!host) +return -ENOMEM ; + + host->hba = hba; +ufshcd_set_variant (hba, host); + +ufs_qcom_get_controller_revision (hba, &host->hw_ver.major, + &host->hw_ver.minor, &host->hw_ver.step); + + err =ufs_qcom_ice_init (host); +if (err) + goto out_variant_clear; + +ufs_qcom_get_default_testbus_cfg (host); + err =ufs_qcom_testbus_config (host); +if (err) +/* Failure is non-fatal */ +dev_warn (dev,"Failed to configure the testbus %d\n" , err); + + hba->caps |=UFSHCD_CAP_WB_EN ; + +ufs_qcom_advertise_quirks (hba); + host->hba->quirks &= ~UFSHCD_QUIRK_REINIT_AFTER_MAX_GEAR_SWITCH ; + + hba->pm_lvl_min =UFS_PM_LVL_5 ; + hba->spm_lvl = hba->rpm_lvl = hba->pm_lvl_min; + +ufs_qcom_set_host_params (hba); +ufs_qcom_parse_gear_limits (hba); + +return 0 ; + +out_variant_clear: +ufshcd_set_variant (hba,NULL ); +return err; +} + +static void ufs_qcom_fw_managed_exit (struct ufs_hba *hba) +{ +pm_runtime_put_sync (hba->dev); +} +/** * ufs_qcom_set_clk_40ns_cycles - Configure 40ns clk cycles *
@@ -1950,6 +2053,39 @@ static int ufs_qcom_device_reset(struct ufs_hba *hba)return 0 ; } +/** +* ufs_qcom_fw_managed_device_reset - Reset UFS device under FW-managed design +* @hba: pointer to UFS host bus adapter +* +* In the firmware-managed reset model, cold boot power-on is handled +* automatically by the PM domain framework during SCMI protocol init, +* before ufshcd_device_reset() is reached. For subsequent resets +* (such as suspend/resume or recovery), the UFS driver must explicitly +* invoke PM runtime operations to reset the subsystem. +* +* Return: 0 on success or a negative error code on failure. +*/ +static int ufs_qcom_fw_managed_device_reset (struct ufs_hba *hba) +{ +static bool is_boot = true; +int err; + +/* Skip reset on cold boot; perform it on subsequent calls */ +if (is_boot) { + is_boot = false; +return 0 ; + } + +pm_runtime_put_sync (hba->dev); + err =pm_runtime_resume_and_get (hba->dev); +if (err <0 ) { +dev_err (hba->dev,"PM runtime resume failed: %d\n" , err); +return err; + } + +return 0 ; +} +static void ufs_qcom_config_scaling_param (struct ufs_hba *hba,struct devfreq_dev_profile *p,struct devfreq_simple_ondemand_data *d)
@@ -2229,6 +2365,20 @@ static const struct ufs_hba_variant_ops ufs_hba_qcom_vops = { .freq_to_gear_speed = ufs_qcom_freq_to_gear_speed, }; +static const struct ufs_hba_variant_ops ufs_hba_qcom_sa8255p_vops = { + .name ="qcom-sa8255p" , + .init = ufs_qcom_fw_managed_init, + .exit = ufs_qcom_fw_managed_exit, + .hce_enable_notify = ufs_qcom_fw_managed_hce_enable_notify, + .pwr_change_notify = ufs_qcom_pwr_change_notify, + .apply_dev_quirks = ufs_qcom_apply_dev_quirks, + .fixup_dev_quirks = ufs_qcom_fixup_dev_quirks, + .suspend = ufs_qcom_fw_managed_suspend, + .resume = ufs_qcom_fw_managed_resume, + .dbg_register_dump = ufs_qcom_dump_dbg_regs, + .device_reset = ufs_qcom_fw_managed_device_reset, +}; +/** * ufs_qcom_probe - probe routine of the driver * @pdev: pointer to Platform device handle
@@ -2239,9 +2389,16 @@ static int ufs_qcom_probe(struct platform_device *pdev) {int err;struct device *dev = &pdev->dev; +const struct ufs_hba_variant_ops *vops; +const struct ufs_qcom_drvdata *drvdata =device_get_match_data (dev); + +if (drvdata && drvdata->vops) + vops = drvdata->vops; +else + vops = &ufs_hba_qcom_vops;/* Perform generic probe */ - err =ufshcd_pltfrm_init (pdev, &ufs_hba_qcom_vops); + err =ufshcd_pltfrm_init (pdev, vops);if (err)return dev_err_probe (dev, err,"ufshcd_pltfrm_init() failed\n" );
@@ -2269,10 +2426,15 @@ static const struct ufs_qcom_drvdata ufs_qcom_sm8550_drvdata = { .no_phy_retention = true, }; +static const struct ufs_qcom_drvdata ufs_qcom_sa8255p_drvdata = { + .vops = &ufs_hba_qcom_sa8255p_vops +}; +static const struct of_device_id ufs_qcom_of_match[]__maybe_unused = { { .compatible ="qcom,ufshc" }, { .compatible ="qcom,sm8550-ufshc" , .data = &ufs_qcom_sm8550_drvdata }, { .compatible ="qcom,sm8650-ufshc" , .data = &ufs_qcom_sm8550_drvdata }, + { .compatible ="qcom,sa8255p-ufshc" , .data = &ufs_qcom_sa8255p_drvdata }, {}, };MODULE_DEVICE_TABLE (of, ufs_qcom_of_match);
drivers/ufs/host/ufs-qcom.h +1 -0
@@ -313,6 +313,7 @@ struct ufs_qcom_host {struct ufs_qcom_drvdata {enum ufshcd_quirks quirks;bool no_phy_retention; +const struct ufs_hba_variant_ops *vops; }; static inline u32
Signature · 1 line
2.34.1
Manivannan Sadhasivam
maintainerRe: [PATCH V4 4/4] ufs: ufs-qcom: Add support for firmware-managed resource abstraction
Quoted 64 lines · Ram Kumar Dwivedi
Add a compatible string for SA8255p platforms where resources such as PHY, clocks, regulators, and resets are managed by firmware through an SCMI server. Use the SCMI power protocol to abstract these resources and invoke power operations via runtime PM APIs (pm_runtime_get/put_sync).
Introduce vendor operations (vops) for SA8255p targets to enable SCMI- based resource control. In this model, capabilities like clock scaling and gating are not yet supported; these will be added incrementally.
Co-developed-by Anjana Hari <[email protected]>Signed-off-by Anjana Hari <[email protected]>Co-developed-by Shazad Hussain <[email protected]>Signed-off-by Shazad Hussain <[email protected]>Signed-off-by Ram Kumar Dwivedi <[email protected]>--- drivers/ufs/host/ufs-qcom.c | 164 +++++++++++++++++++++++++++++++++++- drivers/ufs/host/ufs-qcom.h | 1 + 2 files changed, 164 insertions(+), 1 deletion(-)drivers/ufs/host/ufs-qcom.c +23
-0@@ -14,6 +14,7 @@#include <linux/of.h> #include <linux/phy/phy.h> #include <linux/platform_device.h> +#include <linux/pm_domain.h> #include <linux/reset-controller.h> #include <linux/time.h> #include <linux/unaligned.h> @@ -619,6 +620,27 @@ static int ufs_qcom_hce_enable_notify(struct ufs_hba *hba,return err; } +static int ufs_qcom_fw_managed_hce_enable_notify (struct ufs_hba *hba, +enum ufs_notify_change_status status) +{ +struct ufs_qcom_host *host =ufshcd_get_variant (hba); + +switch (status) { +case PRE_CHANGE : +ufs_qcom_select_unipro_mode (host); +break ; +case POST_CHANGE : +ufs_qcom_enable_hw_clk_gating (hba); +ufs_qcom_ice_enable (host); +break ; +default : +dev_err (hba->dev,"Invalid status %d\n" , status); +return -EINVAL ; + } + +return 0 ; +} +/** * ufs_qcom_cfg_timers - Configure ufs qcom cfg timers * @@ -789,6 +811,38 @@ static int ufs_qcom_resume(struct ufs_hba *hba, enum ufs_pm_op pm_op)return ufs_qcom_ice_resume (host); } +static int ufs_qcom_fw_managed_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op,
drivers/ufs/host/ufs-qcom.c static int ufs_qcom_resume(struct ufs_hba *hba, enum ufs_pm_op pm_op) · line 824
Quoted 10 lines
drivers/ufs/host/ufs-qcom.c +10
-0+ enum ufs_notify_change_status status) +{ +struct ufs_qcom_host *host =ufshcd_get_variant (hba); + +if (status ==PRE_CHANGE ) +return 0 ; + +if (hba->spm_lvl !=UFS_PM_LVL_5 ) { +dev_err (hba->dev,"Unsupported spm level %d\n" , hba->spm_lvl); +return -EINVAL ;
After the sysfs change, do you still need this check?
Quoted 51 lines
drivers/ufs/host/ufs-qcom.c +44
-0+ } + +pm_runtime_put_sync (hba->dev); + +return ufs_qcom_ice_suspend (host); +} + +static int ufs_qcom_fw_managed_resume (struct ufs_hba *hba,enum ufs_pm_op pm_op) +{ +struct ufs_qcom_host *host =ufshcd_get_variant (hba); +int err; + + err =pm_runtime_resume_and_get (hba->dev); +if (err) { +dev_err (hba->dev,"PM runtime resume failed: %d\n" , err); +return err; + } + +return ufs_qcom_ice_resume (host); +} +static void ufs_qcom_dev_ref_clk_ctrl (struct ufs_qcom_host *host,bool enable) { if (host->dev_ref_clk_ctrl_mmio &&@@ -1421,6 +1475,55 @@ static void ufs_qcom_exit(struct ufs_hba *hba)phy_exit (host->generic_phy); } +static int ufs_qcom_fw_managed_init (struct ufs_hba *hba) +{ +struct device *dev = hba->dev; +struct ufs_qcom_host *host; +int err; + + host =devm_kzalloc (dev,sizeof (*host),GFP_KERNEL ); +if (!host) +return -ENOMEM ; + + host->hba = hba; +ufshcd_set_variant (hba, host); + +ufs_qcom_get_controller_revision (hba, &host->hw_ver.major, + &host->hw_ver.minor, &host->hw_ver.step); + + err =ufs_qcom_ice_init (host); +if (err) + goto out_variant_clear; + +ufs_qcom_get_default_testbus_cfg (host); + err =ufs_qcom_testbus_config (host); +if (err)
drivers/ufs/host/ufs-qcom.c static void ufs_qcom_exit(struct ufs_hba *hba) · line 1510
Quoted 10 lines
drivers/ufs/host/ufs-qcom.c +10
-0+/* Failure is non-fatal */ +dev_warn (dev,"Failed to configure the testbus %d\n" , err); + + hba->caps |=UFSHCD_CAP_WB_EN ; + +ufs_qcom_advertise_quirks (hba); + host->hba->quirks &= ~UFSHCD_QUIRK_REINIT_AFTER_MAX_GEAR_SWITCH ; + + hba->pm_lvl_min =UFS_PM_LVL_5 ; + hba->spm_lvl = hba->rpm_lvl = hba->pm_lvl_min;
hba->spm_lvl = hba->rpm_lvl = hba->pm_lvl_min = UFS_PM_LVL_5; ?
Quoted 20 lines
drivers/ufs/host/ufs-qcom.c +16
-0+ +ufs_qcom_set_host_params (hba); +ufs_qcom_parse_gear_limits (hba); + +return 0 ; + +out_variant_clear: +ufshcd_set_variant (hba,NULL ); +return err; +} + +static void ufs_qcom_fw_managed_exit (struct ufs_hba *hba) +{ +pm_runtime_put_sync (hba->dev); +} +/** * ufs_qcom_set_clk_40ns_cycles - Configure 40ns clk cycles *
drivers/ufs/host/ufs-qcom.c static int ufs_qcom_device_reset(struct ufs_hba *hba) · line 2061
Quoted 9 lines
drivers/ufs/host/ufs-qcom.c +6
-0@@ -1950,6 +2053,39 @@ static int ufs_qcom_device_reset(struct ufs_hba *hba)return 0 ; } +/** +* ufs_qcom_fw_managed_device_reset - Reset UFS device under FW-managed design +* @hba: pointer to UFS host bus adapter +* +* In the firmware-managed reset model, cold boot power-on is handled +* automatically by the PM domain framework during SCMI protocol init,
No. genpd handles the power on for the power domain before UFS controller driver probes. SCMI protocol init has nothing to do with it.
- Mani
Signature · 1 line
மணிவண்ணன் சதாசிவம்
Re: [PATCH V4 4/4] ufs: ufs-qcom: Add support for firmware-managed resource abstraction
Quoted 64 lines · Manivannan Sadhasivam
Quoted 63 lines · Ram Kumar Dwivedi
Add a compatible string for SA8255p platforms where resources such as PHY, clocks, regulators, and resets are managed by firmware through an SCMI server. Use the SCMI power protocol to abstract these resources and invoke power operations via runtime PM APIs (pm_runtime_get/put_sync).
Introduce vendor operations (vops) for SA8255p targets to enable SCMI- based resource control. In this model, capabilities like clock scaling and gating are not yet supported; these will be added incrementally.
Co-developed-by Anjana Hari <[email protected]>Signed-off-by Anjana Hari <[email protected]>Co-developed-by Shazad Hussain <[email protected]>Signed-off-by Shazad Hussain <[email protected]>Signed-off-by Ram Kumar Dwivedi <[email protected]>--- drivers/ufs/host/ufs-qcom.c | 164 +++++++++++++++++++++++++++++++++++- drivers/ufs/host/ufs-qcom.h | 1 + 2 files changed, 164 insertions(+), 1 deletion(-)drivers/ufs/host/ufs-qcom.c +22
-0@@ -14,6 +14,7 @@#include <linux/of.h> #include <linux/phy/phy.h> #include <linux/platform_device.h> +#include <linux/pm_domain.h> #include <linux/reset-controller.h> #include <linux/time.h> #include <linux/unaligned.h> @@ -619,6 +620,27 @@ static int ufs_qcom_hce_enable_notify(struct ufs_hba *hba,return err; } +static int ufs_qcom_fw_managed_hce_enable_notify (struct ufs_hba *hba, +enum ufs_notify_change_status status) +{ +struct ufs_qcom_host *host =ufshcd_get_variant (hba); + +switch (status) { +case PRE_CHANGE : +ufs_qcom_select_unipro_mode (host); +break ; +case POST_CHANGE : +ufs_qcom_enable_hw_clk_gating (hba); +ufs_qcom_ice_enable (host); +break ; +default : +dev_err (hba->dev,"Invalid status %d\n" , status); +return -EINVAL ; + } + +return 0 ; +} +/** * ufs_qcom_cfg_timers - Configure ufs qcom cfg timers * @@ -789,6 +811,38 @@ static int ufs_qcom_resume(struct ufs_hba *hba, enum ufs_pm_op pm_op)return ufs_qcom_ice_resume (host); }
Quoted 13 lines
drivers/ufs/host/ufs-qcom.c static int ufs_qcom_resume(struct ufs_hba *hba, enum ufs_pm_op pm_op) · line 824
Quoted 11 lines
drivers/ufs/host/ufs-qcom.c +11
-0+static int ufs_qcom_fw_managed_suspend (struct ufs_hba *hba,enum ufs_pm_op pm_op, +enum ufs_notify_change_status status) +{ +struct ufs_qcom_host *host =ufshcd_get_variant (hba); + +if (status ==PRE_CHANGE ) +return 0 ; + +if (hba->spm_lvl !=UFS_PM_LVL_5 ) { +dev_err (hba->dev,"Unsupported spm level %d\n" , hba->spm_lvl); +return -EINVAL ;After the sysfs change, do you still need this check?
Hi Mani,
I will remove this check in the next version.
Thanks,
Ram.
Quoted 56 lines
Quoted 56 lines
drivers/ufs/host/ufs-qcom.c +48
-0+ } + +pm_runtime_put_sync (hba->dev); + +return ufs_qcom_ice_suspend (host); +} + +static int ufs_qcom_fw_managed_resume (struct ufs_hba *hba,enum ufs_pm_op pm_op) +{ +struct ufs_qcom_host *host =ufshcd_get_variant (hba); +int err; + + err =pm_runtime_resume_and_get (hba->dev); +if (err) { +dev_err (hba->dev,"PM runtime resume failed: %d\n" , err); +return err; + } + +return ufs_qcom_ice_resume (host); +} +static void ufs_qcom_dev_ref_clk_ctrl (struct ufs_qcom_host *host,bool enable) { if (host->dev_ref_clk_ctrl_mmio &&@@ -1421,6 +1475,55 @@ static void ufs_qcom_exit(struct ufs_hba *hba)phy_exit (host->generic_phy); } +static int ufs_qcom_fw_managed_init (struct ufs_hba *hba) +{ +struct device *dev = hba->dev; +struct ufs_qcom_host *host; +int err; + + host =devm_kzalloc (dev,sizeof (*host),GFP_KERNEL ); +if (!host) +return -ENOMEM ; + + host->hba = hba; +ufshcd_set_variant (hba, host); + +ufs_qcom_get_controller_revision (hba, &host->hw_ver.major, + &host->hw_ver.minor, &host->hw_ver.step); + + err =ufs_qcom_ice_init (host); +if (err) + goto out_variant_clear; + +ufs_qcom_get_default_testbus_cfg (host); + err =ufs_qcom_testbus_config (host); +if (err) +/* Failure is non-fatal */ +dev_warn (dev,"Failed to configure the testbus %d\n" , err); + + hba->caps |=UFSHCD_CAP_WB_EN ;
Quoted 8 lines
drivers/ufs/host/ufs-qcom.c static void ufs_qcom_exit(struct ufs_hba *hba) · line 1510
Quoted 6 lines
drivers/ufs/host/ufs-qcom.c +6
-0+ +ufs_qcom_advertise_quirks (hba); + host->hba->quirks &= ~UFSHCD_QUIRK_REINIT_AFTER_MAX_GEAR_SWITCH ; + + hba->pm_lvl_min =UFS_PM_LVL_5 ; + hba->spm_lvl = hba->rpm_lvl = hba->pm_lvl_min;
hba->spm_lvl=hba->rpm_lvl=hba->pm_lvl_min=UFS_PM_LVL_5; ?
Hi Mani,
I will update this to a single-line assignment as suggested in the next version.
Thanks,
Ram
Quoted 24 lines
Quoted 24 lines
drivers/ufs/host/ufs-qcom.c +16
-0+ +ufs_qcom_set_host_params (hba); +ufs_qcom_parse_gear_limits (hba); + +return 0 ; + +out_variant_clear: +ufshcd_set_variant (hba,NULL ); +return err; +} + +static void ufs_qcom_fw_managed_exit (struct ufs_hba *hba) +{ +pm_runtime_put_sync (hba->dev); +} +/** * ufs_qcom_set_clk_40ns_cycles - Configure 40ns clk cycles * @@ -1950,6 +2053,39 @@ static int ufs_qcom_device_reset(struct ufs_hba *hba)return 0 ; }
Quoted 9 lines
drivers/ufs/host/ufs-qcom.c static int ufs_qcom_device_reset(struct ufs_hba *hba) · line 2061
Quoted 6 lines
drivers/ufs/host/ufs-qcom.c +6
-0+/** +* ufs_qcom_fw_managed_device_reset - Reset UFS device under FW-managed design +* @hba: pointer to UFS host bus adapter +* +* In the firmware-managed reset model, cold boot power-on is handled +* automatically by the PM domain framework during SCMI protocol init, No. genpd handles the power on for the power domain before UFS controller driver probes. SCMI protocol init has nothing to do with it.
Hi Mani,
I have updated the comment in the next version to clarify that genpd handles the power-on.
Thanks,
Ram.
Quoted 3 lines
- Mani