1 // SPDX-License-Identifier: GPL-2.0
3 * Platform UFS Host driver for Cadence controller
5 * Copyright (C) 2018 Cadence Design Systems, Inc.
8 * Jan Kotas <jank@cadence.com>
12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/platform_device.h>
16 #include <linux/time.h>
18 #include "ufshcd-pltfrm.h"
20 #define CDNS_UFS_REG_HCLKDIV 0xFC
23 * Sets HCLKDIV register value based on the core_clk
24 * @hba: host controller instance
26 * Return zero for success and non-zero for failure
28 static int cdns_ufs_set_hclkdiv(struct ufs_hba
*hba
)
30 struct ufs_clk_info
*clki
;
31 struct list_head
*head
= &hba
->clk_list_head
;
32 unsigned long core_clk_rate
= 0;
38 list_for_each_entry(clki
, head
, list
) {
39 if (IS_ERR_OR_NULL(clki
->clk
))
41 if (!strcmp(clki
->name
, "core_clk"))
42 core_clk_rate
= clk_get_rate(clki
->clk
);
46 dev_err(hba
->dev
, "%s: unable to find core_clk rate\n",
51 core_clk_div
= core_clk_rate
/ USEC_PER_SEC
;
53 ufshcd_writel(hba
, core_clk_div
, CDNS_UFS_REG_HCLKDIV
);
55 * Make sure the register was updated,
56 * UniPro layer will not work with an incorrect value.
64 * Sets clocks used by the controller
65 * @hba: host controller instance
66 * @on: if true, enable clocks, otherwise disable
67 * @status: notify stage (pre, post change)
69 * Return zero for success and non-zero for failure
71 static int cdns_ufs_setup_clocks(struct ufs_hba
*hba
, bool on
,
72 enum ufs_notify_change_status status
)
74 if ((!on
) || (status
== PRE_CHANGE
))
77 return cdns_ufs_set_hclkdiv(hba
);
80 static struct ufs_hba_variant_ops cdns_pltfm_hba_vops
= {
81 .name
= "cdns-ufs-pltfm",
82 .setup_clocks
= cdns_ufs_setup_clocks
,
86 * cdns_ufs_pltfrm_probe - probe routine of the driver
87 * @pdev: pointer to platform device handle
89 * Return zero for success and non-zero for failure
91 static int cdns_ufs_pltfrm_probe(struct platform_device
*pdev
)
94 struct device
*dev
= &pdev
->dev
;
96 /* Perform generic probe */
97 err
= ufshcd_pltfrm_init(pdev
, &cdns_pltfm_hba_vops
);
99 dev_err(dev
, "ufshcd_pltfrm_init() failed %d\n", err
);
105 * cdns_ufs_pltfrm_remove - removes the ufs driver
106 * @pdev: pointer to platform device handle
110 static int cdns_ufs_pltfrm_remove(struct platform_device
*pdev
)
112 struct ufs_hba
*hba
= platform_get_drvdata(pdev
);
118 static const struct of_device_id cdns_ufs_of_match
[] = {
119 { .compatible
= "cdns,ufshc" },
123 MODULE_DEVICE_TABLE(of
, cdns_ufs_of_match
);
125 static const struct dev_pm_ops cdns_ufs_dev_pm_ops
= {
126 .suspend
= ufshcd_pltfrm_suspend
,
127 .resume
= ufshcd_pltfrm_resume
,
128 .runtime_suspend
= ufshcd_pltfrm_runtime_suspend
,
129 .runtime_resume
= ufshcd_pltfrm_runtime_resume
,
130 .runtime_idle
= ufshcd_pltfrm_runtime_idle
,
133 static struct platform_driver cdns_ufs_pltfrm_driver
= {
134 .probe
= cdns_ufs_pltfrm_probe
,
135 .remove
= cdns_ufs_pltfrm_remove
,
137 .name
= "cdns-ufshcd",
138 .pm
= &cdns_ufs_dev_pm_ops
,
139 .of_match_table
= cdns_ufs_of_match
,
143 module_platform_driver(cdns_ufs_pltfrm_driver
);
145 MODULE_AUTHOR("Jan Kotas <jank@cadence.com>");
146 MODULE_DESCRIPTION("Cadence UFS host controller platform driver");
147 MODULE_LICENSE("GPL v2");
148 MODULE_VERSION(UFSHCD_DRIVER_VERSION
);