Commit ac8c2459 authored by Stanley Chu's avatar Stanley Chu Committed by Martin K. Petersen

scsi: ufs-mediatek: Decouple features from platform bindings

UFS proprietary features (including features introduced later) in MediaTek
UFS platforms have complicated combinations among different platforms.

To ease code readability and maintenance, decouple all proprietary features
from platform bindings. Each feature would be enabled only if specific
property string is defined in device tree node.

Link: https://lore.kernel.org/r/20201029115750.24391-4-stanley.chu@mediatek.comSigned-off-by: default avatarStanley Chu <stanley.chu@mediatek.com>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent cf137b3e
...@@ -48,23 +48,8 @@ static struct ufs_dev_fix ufs_mtk_dev_fixups[] = { ...@@ -48,23 +48,8 @@ static struct ufs_dev_fix ufs_mtk_dev_fixups[] = {
END_FIX END_FIX
}; };
static const struct ufs_mtk_host_cfg ufs_mtk_mt8183_cfg = {
.caps = UFS_MTK_CAP_VA09_PWR_CTRL,
};
static const struct ufs_mtk_host_cfg ufs_mtk_mt8192_cfg = {
.caps = UFS_MTK_CAP_BOOST_CRYPT_ENGINE,
};
static const struct of_device_id ufs_mtk_of_match[] = { static const struct of_device_id ufs_mtk_of_match[] = {
{ { .compatible = "mediatek,mt8183-ufshci" },
.compatible = "mediatek,mt8183-ufshci",
.data = &ufs_mtk_mt8183_cfg
},
{
.compatible = "mediatek,mt8192-ufshci",
.data = &ufs_mtk_mt8192_cfg
},
{}, {},
}; };
...@@ -72,14 +57,14 @@ static bool ufs_mtk_is_boost_crypt_enabled(struct ufs_hba *hba) ...@@ -72,14 +57,14 @@ static bool ufs_mtk_is_boost_crypt_enabled(struct ufs_hba *hba)
{ {
struct ufs_mtk_host *host = ufshcd_get_variant(hba); struct ufs_mtk_host *host = ufshcd_get_variant(hba);
return (host->caps & UFS_MTK_CAP_BOOST_CRYPT_ENGINE); return !!(host->caps & UFS_MTK_CAP_BOOST_CRYPT_ENGINE);
} }
static bool ufs_mtk_is_va09_supported(struct ufs_hba *hba) static bool ufs_mtk_is_va09_supported(struct ufs_hba *hba)
{ {
struct ufs_mtk_host *host = ufshcd_get_variant(hba); struct ufs_mtk_host *host = ufshcd_get_variant(hba);
return (host->caps & UFS_MTK_CAP_VA09_PWR_CTRL); return !!(host->caps & UFS_MTK_CAP_VA09_PWR_CTRL);
} }
static void ufs_mtk_cfg_unipro_cg(struct ufs_hba *hba, bool enable) static void ufs_mtk_cfg_unipro_cg(struct ufs_hba *hba, bool enable)
...@@ -326,7 +311,7 @@ static int ufs_mtk_mphy_power_on(struct ufs_hba *hba, bool on) ...@@ -326,7 +311,7 @@ static int ufs_mtk_mphy_power_on(struct ufs_hba *hba, bool on)
return 0; return 0;
if (on) { if (on) {
if (host->reg_va09) { if (ufs_mtk_is_va09_supported(hba)) {
ret = regulator_enable(host->reg_va09); ret = regulator_enable(host->reg_va09);
if (ret < 0) if (ret < 0)
goto out; goto out;
...@@ -337,7 +322,7 @@ static int ufs_mtk_mphy_power_on(struct ufs_hba *hba, bool on) ...@@ -337,7 +322,7 @@ static int ufs_mtk_mphy_power_on(struct ufs_hba *hba, bool on)
phy_power_on(mphy); phy_power_on(mphy);
} else { } else {
phy_power_off(mphy); phy_power_off(mphy);
if (host->reg_va09) { if (ufs_mtk_is_va09_supported(hba)) {
ufs_mtk_va09_pwr_ctrl(res, 0); ufs_mtk_va09_pwr_ctrl(res, 0);
ret = regulator_disable(host->reg_va09); ret = regulator_disable(host->reg_va09);
if (ret < 0) if (ret < 0)
...@@ -483,10 +468,10 @@ static void ufs_mtk_init_boost_crypt(struct ufs_hba *hba) ...@@ -483,10 +468,10 @@ static void ufs_mtk_init_boost_crypt(struct ufs_hba *hba)
cfg->reg_vcore = reg; cfg->reg_vcore = reg;
cfg->vcore_volt = volt; cfg->vcore_volt = volt;
return; host->caps |= UFS_MTK_CAP_BOOST_CRYPT_ENGINE;
disable_caps: disable_caps:
host->caps &= ~UFS_MTK_CAP_BOOST_CRYPT_ENGINE; return;
} }
static void ufs_mtk_init_va09_pwr_ctrl(struct ufs_hba *hba) static void ufs_mtk_init_va09_pwr_ctrl(struct ufs_hba *hba)
...@@ -494,22 +479,21 @@ static void ufs_mtk_init_va09_pwr_ctrl(struct ufs_hba *hba) ...@@ -494,22 +479,21 @@ static void ufs_mtk_init_va09_pwr_ctrl(struct ufs_hba *hba)
struct ufs_mtk_host *host = ufshcd_get_variant(hba); struct ufs_mtk_host *host = ufshcd_get_variant(hba);
host->reg_va09 = regulator_get(hba->dev, "va09"); host->reg_va09 = regulator_get(hba->dev, "va09");
if (!host->reg_va09) { if (!host->reg_va09)
dev_info(hba->dev, "failed to get va09"); dev_info(hba->dev, "failed to get va09");
host->caps &= ~UFS_MTK_CAP_VA09_PWR_CTRL; else
} host->caps |= UFS_MTK_CAP_VA09_PWR_CTRL;
} }
static void ufs_mtk_init_host_caps(struct ufs_hba *hba) static void ufs_mtk_init_host_caps(struct ufs_hba *hba)
{ {
struct ufs_mtk_host *host = ufshcd_get_variant(hba); struct ufs_mtk_host *host = ufshcd_get_variant(hba);
struct device_node *np = hba->dev->of_node;
host->caps = host->cfg->caps; if (of_property_read_bool(np, "mediatek,ufs-boost-crypt"))
if (ufs_mtk_is_boost_crypt_enabled(hba))
ufs_mtk_init_boost_crypt(hba); ufs_mtk_init_boost_crypt(hba);
if (ufs_mtk_is_va09_supported(hba)) if (of_property_read_bool(np, "mediatek,ufs-support-va09"))
ufs_mtk_init_va09_pwr_ctrl(hba); ufs_mtk_init_va09_pwr_ctrl(hba);
dev_info(hba->dev, "caps: 0x%x", host->caps); dev_info(hba->dev, "caps: 0x%x", host->caps);
...@@ -597,17 +581,14 @@ static int ufs_mtk_init(struct ufs_hba *hba) ...@@ -597,17 +581,14 @@ static int ufs_mtk_init(struct ufs_hba *hba)
host->hba = hba; host->hba = hba;
ufshcd_set_variant(hba, host); ufshcd_set_variant(hba, host);
/* Get host capability and platform data */
id = of_match_device(ufs_mtk_of_match, dev); id = of_match_device(ufs_mtk_of_match, dev);
if (!id) { if (!id) {
err = -EINVAL; err = -EINVAL;
goto out; goto out;
} }
if (id->data) { /* Initialize host capability */
host->cfg = (struct ufs_mtk_host_cfg *)id->data; ufs_mtk_init_host_caps(hba);
ufs_mtk_init_host_caps(hba);
}
err = ufs_mtk_bind_mphy(hba); err = ufs_mtk_bind_mphy(hba);
if (err) if (err)
......
...@@ -106,20 +106,15 @@ struct ufs_mtk_crypt_cfg { ...@@ -106,20 +106,15 @@ struct ufs_mtk_crypt_cfg {
int vcore_volt; int vcore_volt;
}; };
struct ufs_mtk_host_cfg {
enum ufs_mtk_host_caps caps;
};
struct ufs_mtk_host { struct ufs_mtk_host {
struct ufs_hba *hba;
struct phy *mphy; struct phy *mphy;
struct ufs_mtk_host_cfg *cfg;
struct ufs_mtk_crypt_cfg *crypt;
struct regulator *reg_va09; struct regulator *reg_va09;
enum ufs_mtk_host_caps caps;
struct reset_control *hci_reset; struct reset_control *hci_reset;
struct reset_control *unipro_reset; struct reset_control *unipro_reset;
struct reset_control *crypto_reset; struct reset_control *crypto_reset;
struct ufs_hba *hba;
struct ufs_mtk_crypt_cfg *crypt;
enum ufs_mtk_host_caps caps;
bool mphy_powered_on; bool mphy_powered_on;
bool unipro_lpm; bool unipro_lpm;
bool ref_clk_enabled; bool ref_clk_enabled;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment