Skip to content

Commit c73cd5e

Browse files
ptr324martinkpetersen
authored andcommitted
scsi: ufs: host: mediatek: Support UFS PHY runtime PM and correct sequence
Add support for UFS PHY runtime power management by probing the PHY device and enabling its runtime PM. Ensure the correct sequence of operations during suspend and resume: PHY suspend -> UFS suspend -> UFS resume -> PHY resume. Improve power management efficiency and system stability with this enhancement. Signed-off-by: Peter Wang <peter.wang@mediatek.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent b2f8aba commit c73cd5e

2 files changed

Lines changed: 48 additions & 6 deletions

File tree

drivers/ufs/host/ufs-mediatek.c

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2243,10 +2243,12 @@ static const struct ufs_hba_variant_ops ufs_hba_mtk_vops = {
22432243
static int ufs_mtk_probe(struct platform_device *pdev)
22442244
{
22452245
int err;
2246-
struct device *dev = &pdev->dev;
2247-
struct device_node *reset_node;
2248-
struct platform_device *reset_pdev;
2246+
struct device *dev = &pdev->dev, *phy_dev = NULL;
2247+
struct device_node *reset_node, *phy_node = NULL;
2248+
struct platform_device *reset_pdev, *phy_pdev = NULL;
22492249
struct device_link *link;
2250+
struct ufs_hba *hba;
2251+
struct ufs_mtk_host *host;
22502252

22512253
reset_node = of_find_compatible_node(NULL, NULL,
22522254
"ti,syscon-reset");
@@ -2273,13 +2275,44 @@ static int ufs_mtk_probe(struct platform_device *pdev)
22732275
}
22742276

22752277
skip_reset:
2278+
/* find phy node */
2279+
phy_node = of_parse_phandle(dev->of_node, "phys", 0);
2280+
2281+
if (phy_node) {
2282+
phy_pdev = of_find_device_by_node(phy_node);
2283+
if (!phy_pdev)
2284+
goto skip_phy;
2285+
phy_dev = &phy_pdev->dev;
2286+
2287+
pm_runtime_set_active(phy_dev);
2288+
pm_runtime_enable(phy_dev);
2289+
pm_runtime_get_sync(phy_dev);
2290+
2291+
put_device(phy_dev);
2292+
dev_info(dev, "phys node found\n");
2293+
} else {
2294+
dev_notice(dev, "phys node not found\n");
2295+
}
2296+
2297+
skip_phy:
22762298
/* perform generic probe */
22772299
err = ufshcd_pltfrm_init(pdev, &ufs_hba_mtk_vops);
2278-
2279-
out:
2280-
if (err)
2300+
if (err) {
22812301
dev_err(dev, "probe failed %d\n", err);
2302+
goto out;
2303+
}
2304+
2305+
hba = platform_get_drvdata(pdev);
2306+
if (!hba)
2307+
goto out;
2308+
2309+
if (phy_node && phy_dev) {
2310+
host = ufshcd_get_variant(hba);
2311+
host->phy_dev = phy_dev;
2312+
}
22822313

2314+
out:
2315+
of_node_put(phy_node);
22832316
of_node_put(reset_node);
22842317
return err;
22852318
}
@@ -2343,6 +2376,7 @@ static int ufs_mtk_system_resume(struct device *dev)
23432376
static int ufs_mtk_runtime_suspend(struct device *dev)
23442377
{
23452378
struct ufs_hba *hba = dev_get_drvdata(dev);
2379+
struct ufs_mtk_host *host = ufshcd_get_variant(hba);
23462380
struct arm_smccc_res res;
23472381
int ret = 0;
23482382

@@ -2355,17 +2389,24 @@ static int ufs_mtk_runtime_suspend(struct device *dev)
23552389
if (ufs_mtk_is_rtff_mtcmos(hba))
23562390
ufs_mtk_mtcmos_ctrl(false, res);
23572391

2392+
if (host->phy_dev)
2393+
pm_runtime_put_sync(host->phy_dev);
2394+
23582395
return 0;
23592396
}
23602397

23612398
static int ufs_mtk_runtime_resume(struct device *dev)
23622399
{
23632400
struct ufs_hba *hba = dev_get_drvdata(dev);
2401+
struct ufs_mtk_host *host = ufshcd_get_variant(hba);
23642402
struct arm_smccc_res res;
23652403

23662404
if (ufs_mtk_is_rtff_mtcmos(hba))
23672405
ufs_mtk_mtcmos_ctrl(true, res);
23682406

2407+
if (host->phy_dev)
2408+
pm_runtime_get_sync(host->phy_dev);
2409+
23692410
ufs_mtk_dev_vreg_set_lpm(hba, false);
23702411

23712412
return ufshcd_runtime_resume(dev);

drivers/ufs/host/ufs-mediatek.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ struct ufs_mtk_host {
193193
bool is_mcq_intr_enabled;
194194
int mcq_nr_intr;
195195
struct ufs_mtk_mcq_intr_info mcq_intr_info[UFSHCD_MAX_Q_NR];
196+
struct device *phy_dev;
196197
};
197198

198199
/* MTK delay of autosuspend: 500 ms */

0 commit comments

Comments
 (0)