scsi: ufs: add MediaTek vendor implementations
Subsystems (2)
v2 cover scsi: ufs: add MediaTek vendor implementations
Hi,
This series provides MediaTek vendor implementations as below,
- Device reset
- Reference clock control
- Auto-hibernate enabling with customized timer value
- Clk-gating enabling with customized delayed timer value
v1 -> v2:
- Move MTK_SIP_UFS_CONTROL to ufs-mediatek.h and make include/linux/soc/mediatek/mtk_sip_svc.h has common definitions only (Alim)
- Remove dummy "line change" for MTK_SIP_UFS_CONTROL definition
- Refactor UFS SMC calls in ufs-mediatek.c
Stanley Chu (6):
soc: mediatek: add header for SiP service interface
scsi: ufs-mediatek: add device reset implementation
scsi: ufs-mediatek: introduce reference clock control
scsi: ufs: export ufshcd_auto_hibern8_update for vendor usage
scsi: ufs-mediatek: configure customized auto-hibern8 timer
scsi: ufs-mediatek: configure and enable clk-gating
drivers/scsi/ufs/ufs-mediatek.c | 125 ++++++++++++++++++++++- drivers/scsi/ufs/ufs-mediatek.h | 27 +++++ drivers/scsi/ufs/ufs-sysfs.c | 20 ---- drivers/scsi/ufs/ufshcd.c | 18 ++++ drivers/scsi/ufs/ufshcd.h | 1 + include/linux/soc/mediatek/mtk_sip_svc.h | 25 +++++ 6 files changed, 192 insertions(+), 24 deletions(-) create mode 100644 include/linux/soc/mediatek/mtk_sip_svc.h
Signature · 1 line
2.18.0
PATCH v2 1/6 soc: mediatek: add header for SiP service interface
Add a common header for the SiP service interface in MediaTek Chipsets.
--- include/linux/soc/mediatek/mtk_sip_svc.h | 25 ++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 include/linux/soc/mediatek/mtk_sip_svc.h
include/linux/soc/mediatek/mtk_sip_svc.h new file +25 -0
@@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2019 MediaTek Inc. +*/ +#ifndef __MTK_SIP_SVC_H +#define __MTK_SIP_SVC_H + +/* Error Code */ +#define SIP_SVC_E_SUCCESS 0 +#define SIP_SVC_E_NOT_SUPPORTED -1 +#define SIP_SVC_E_INVALID_PARAMS -2 +#define SIP_SVC_E_INVALID_RANGE -3 +#define SIP_SVC_E_PERMISSION_DENIED -4 + +#ifdef CONFIG_ARM64 +#define MTK_SIP_SMC_CONVENTION ARM_SMCCC_SMC_64 +#else +#define MTK_SIP_SMC_CONVENTION ARM_SMCCC_SMC_32 +#endif + +#define MTK_SIP_SMC_CMD (fn_id) \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, MTK_SIP_SMC_CONVENTION, \ + ARM_SMCCC_OWNER_SIP, fn_id) + +#endif
Signature · 1 line
2.18.0
PATCH v2 2/6 scsi: ufs-mediatek: add device reset implementation
In reply to Stanley ChuAdd device reset vops implementation in MediaTek UFS driver.
--- drivers/scsi/ufs/ufs-mediatek.c | 33 +++++++++++++++++++++++++++++++++ drivers/scsi/ufs/ufs-mediatek.h | 9 +++++++++ 2 files changed, 42 insertions(+)
drivers/scsi/ufs/ufs-mediatek.c +33 -0
@@ -6,16 +6,25 @@* Peter Wang <[email protected]> */ +#include <linux/arm-smccc.h> #include <linux/of.h> #include <linux/of_address.h> #include <linux/phy/phy.h> #include <linux/platform_device.h> +#include <linux/soc/mediatek/mtk_sip_svc.h> #include "ufshcd.h" #include "ufshcd-pltfrm.h" #include "unipro.h" #include "ufs-mediatek.h" +#define ufs_mtk_smc (cmd, val, res) \ + arm_smccc_smc(MTK_SIP_UFS_CONTROL, \ + cmd, val, 0, 0, 0, 0, 0, &(res)) + +#define ufs_mtk_device_reset_ctrl (high, res) \ + ufs_mtk_smc(UFS_MTK_SIP_DEVICE_RESET, high, res) +static void ufs_mtk_cfg_unipro_cg (struct ufs_hba *hba,bool enable) {u32 tmp;
@@ -269,6 +278,29 @@ static int ufs_mtk_link_startup_notify(struct ufs_hba *hba,return ret; } +static void ufs_mtk_device_reset (struct ufs_hba *hba) +{ +struct arm_smccc_res res; + +ufs_mtk_device_reset_ctrl (0 , res); + +/* +* The reset signal is active low. UFS devices shall detect +* more than or equal to 1us of positive or negative RST_n +* pulse width. +* +* To be on safe side, keep the reset low for at least 10us. +*/ +usleep_range (10 ,15 ); + +ufs_mtk_device_reset_ctrl (1 , res); + +/* Some devices may need time to respond to rst_n */ +usleep_range (10000 ,15000 ); + +dev_info (hba->dev,"device reset done\n" ); +} +static int ufs_mtk_suspend (struct ufs_hba *hba,enum ufs_pm_op pm_op) {struct ufs_mtk_host *host =ufshcd_get_variant (hba);
@@ -303,6 +335,7 @@ static struct ufs_hba_variant_ops ufs_hba_mtk_vops = { .pwr_change_notify = ufs_mtk_pwr_change_notify, .suspend = ufs_mtk_suspend, .resume = ufs_mtk_resume, + .device_reset = ufs_mtk_device_reset, };/**
drivers/scsi/ufs/ufs-mediatek.h +9 -0
@@ -6,6 +6,9 @@#ifndef _UFS_MEDIATEK_H#define _UFS_MEDIATEK_H +#include <linux/bitops.h> +#include <linux/soc/mediatek/mtk_sip_svc.h> +/* * Vendor specific pre-defined parameters */
@@ -29,6 +32,12 @@#define VS_SAVEPOWERCONTROL 0xD0A6#define VS_UNIPROPOWERDOWNCONTROL 0xD0A8 +/* +* SiP commands +*/ +#define MTK_SIP_UFS_CONTROL MTK_SIP_SMC_CMD(0x276) +#define UFS_MTK_SIP_DEVICE_RESET BIT(1) +/* * VS_DEBUGCLOCKENABLE */
Signature · 1 line
2.18.0
PATCH v2 3/6 scsi: ufs-mediatek: introduce reference clock control
In reply to Stanley ChuIntroduce reference clock control in MediaTek Chipset in order to disable it if it is not necessary by UFS device to save system power.
Currently reference clock can be disabled during system suspend, runtime suspend and clock-gating after link enters hibernate state.
--- drivers/scsi/ufs/ufs-mediatek.c | 62 ++++++++++++++++++++++++++++++--- drivers/scsi/ufs/ufs-mediatek.h | 22 ++++++++++-- 2 files changed, 78 insertions(+), 6 deletions(-)
drivers/scsi/ufs/ufs-mediatek.c +58 -4
@@ -22,6 +22,9 @@arm_smccc_smc (MTK_SIP_UFS_CONTROL , \ cmd, val, 0, 0, 0, 0, 0, &(res)) +#define ufs_mtk_ref_clk_notify (on, res) \ + ufs_mtk_smc(UFS_MTK_SIP_REF_CLK_NOTIFICATION, on, res) +#define ufs_mtk_device_reset_ctrl (high, res) \ ufs_mtk_smc(UFS_MTK_SIP_DEVICE_RESET, high, res)
@@ -90,6 +93,49 @@ static int ufs_mtk_bind_mphy(struct ufs_hba *hba)return err; } +static int ufs_mtk_setup_ref_clk (struct ufs_hba *hba,bool on) +{ +struct ufs_mtk_host *host =ufshcd_get_variant (hba); +struct arm_smccc_res res; +unsigned long timeout; +u32 value; + +if (host->ref_clk_enabled == on) +return 0 ; + +if (on) { +ufs_mtk_ref_clk_notify (on, res); +ufshcd_writel (hba,REFCLK_REQUEST ,REG_UFS_REFCLK_CTRL ); + }else { +ufshcd_writel (hba,REFCLK_RELEASE ,REG_UFS_REFCLK_CTRL ); + } + +/* Wait for ack */ + timeout = jiffies +msecs_to_jiffies (REFCLK_REQ_TIMEOUT_MS ); +do { + value =ufshcd_readl (hba,REG_UFS_REFCLK_CTRL ); + +/* Wait until ack bit equals to req bit */ +if (((value &REFCLK_ACK ) >>1 ) == (value &REFCLK_REQUEST )) + goto out; + +usleep_range (100 ,200 ); + }while (time_before (jiffies, timeout)); + +dev_err (hba->dev,"missing ack of refclk req, reg: 0x%x\n" , value); + +ufs_mtk_ref_clk_notify (host->ref_clk_enabled, res); + +return -ETIMEDOUT ; + +out: + host->ref_clk_enabled = on; +if (!on) +ufs_mtk_ref_clk_notify (on, res); + +return 0 ; +} +/** * ufs_mtk_setup_clocks - enables/disable clocks * @hba: host controller instance
@@ -114,12 +160,16 @@ static int ufs_mtk_setup_clocks(struct ufs_hba *hba, bool on,switch (status) {case PRE_CHANGE : -if (!on) +if (!on) { +ufs_mtk_setup_ref_clk (hba, on); ret =phy_power_off (host->mphy); + }break ;case POST_CHANGE : -if (on) +if (on) { ret =phy_power_on (host->mphy); +ufs_mtk_setup_ref_clk (hba, on); + }break ; }
@@ -305,8 +355,10 @@ static int ufs_mtk_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op) {struct ufs_mtk_host *host =ufshcd_get_variant (hba); -if (ufshcd_is_link_hibern8 (hba)) +if (ufshcd_is_link_hibern8 (hba)) {phy_power_off (host->mphy); +ufs_mtk_setup_ref_clk (hba, false); + }return 0 ; }
@@ -315,8 +367,10 @@ static int ufs_mtk_resume(struct ufs_hba *hba, enum ufs_pm_op pm_op) {struct ufs_mtk_host *host =ufshcd_get_variant (hba); -if (ufshcd_is_link_hibern8 (hba)) +if (ufshcd_is_link_hibern8 (hba)) { +ufs_mtk_setup_ref_clk (hba, true);phy_power_on (host->mphy); + }return 0 ; }
drivers/scsi/ufs/ufs-mediatek.h +20 -2
@@ -9,6 +9,22 @@#include <linux/bitops.h> #include <linux/soc/mediatek/mtk_sip_svc.h> +/* +* Vendor specific UFSHCI Registers +*/ +#define REG_UFS_REFCLK_CTRL 0x144 + +/* +* Ref-clk control +* +* Values for register REG_UFS_REFCLK_CTRL +*/ +#define REFCLK_RELEASE 0x0 +#define REFCLK_REQUEST BIT(0) +#define REFCLK_ACK BIT(1) + +#define REFCLK_REQ_TIMEOUT_MS 3 +/* * Vendor specific pre-defined parameters */
@@ -35,8 +51,9 @@/* * SiP commands */ -#define MTK_SIP_UFS_CONTROL MTK_SIP_SMC_CMD(0x276) -#define UFS_MTK_SIP_DEVICE_RESET BIT(1) +#define MTK_SIP_UFS_CONTROL MTK_SIP_SMC_CMD(0x276) +#define UFS_MTK_SIP_DEVICE_RESET BIT(1) +#define UFS_MTK_SIP_REF_CLK_NOTIFICATION BIT(3)/* * VS_DEBUGCLOCKENABLE
@@ -57,6 +74,7 @@ enum {struct ufs_mtk_host {struct ufs_hba *hba;struct phy *mphy; +bool ref_clk_enabled; };#endif /* !_UFS_MEDIATEK_H */
Signature · 1 line
2.18.0
PATCH v2 4/6 scsi: ufs: export ufshcd_auto_hibern8_update for vendor usage
In reply to Stanley ChuExport ufshcd_auto_hibern8_update to allow vendors to use common interface to customize auto-hibernate timer.
--- drivers/scsi/ufs/ufs-sysfs.c | 20 -------------------- drivers/scsi/ufs/ufshcd.c | 18 ++++++++++++++++++ drivers/scsi/ufs/ufshcd.h | 1 + 3 files changed, 19 insertions(+), 20 deletions(-)
drivers/scsi/ufs/ufs-sysfs.c +0 -20
@@ -118,26 +118,6 @@ static ssize_t spm_target_link_state_show(struct device *dev, ufs_pm_lvl_states[hba->spm_lvl].link_state)); } -static void ufshcd_auto_hibern8_update (struct ufs_hba *hba,u32 ahit) -{ -unsigned long flags; - -if (!ufshcd_is_auto_hibern8_supported (hba)) -return ; - -spin_lock_irqsave (hba->host->host_lock, flags); -if (hba->ahit != ahit) - hba->ahit = ahit; -spin_unlock_irqrestore (hba->host->host_lock, flags); -if (!pm_runtime_suspended (hba->dev)) { -pm_runtime_get_sync (hba->dev); -ufshcd_hold (hba, false); -ufshcd_auto_hibern8_enable (hba); -ufshcd_release (hba); -pm_runtime_put (hba->dev); - } -} -/* Convert Auto-Hibernate Idle Timer register value to microseconds */ static int ufshcd_ahit_to_us (u32 ahit) {
drivers/scsi/ufs/ufshcd.c +18 -0
@@ -3893,6 +3893,24 @@ static int ufshcd_uic_hibern8_exit(struct ufs_hba *hba)return ret; } +void ufshcd_auto_hibern8_update (struct ufs_hba *hba,u32 ahit) +{ +unsigned long flags; + +if (!(hba->capabilities &MASK_AUTO_HIBERN8_SUPPORT )) +return ; + +spin_lock_irqsave (hba->host->host_lock, flags); +if (hba->ahit == ahit) + goto out_unlock; + hba->ahit = ahit; +if (!pm_runtime_suspended (hba->dev)) +ufshcd_writel (hba, hba->ahit,REG_AUTO_HIBERNATE_IDLE_TIMER ); +out_unlock: +spin_unlock_irqrestore (hba->host->host_lock, flags); +} +EXPORT_SYMBOL_GPL (ufshcd_auto_hibern8_update); +void ufshcd_auto_hibern8_enable (struct ufs_hba *hba) {unsigned long flags;
drivers/scsi/ufs/ufshcd.h +1 -0
@@ -923,6 +923,7 @@ int ufshcd_query_flag(struct ufs_hba *hba, enum query_opcode opcode, enum flag_idn idn, bool *flag_res);void ufshcd_auto_hibern8_enable (struct ufs_hba *hba); +void ufshcd_auto_hibern8_update (struct ufs_hba *hba,u32 ahit);#define SD_ASCII_STD true#define SD_RAW false
Signature · 1 line
2.18.0
PATCH v2 5/6 scsi: ufs-mediatek: configure customized auto-hibern8 timer
In reply to Stanley ChuConfigure customized auto-hibern8 timer in MediaTek Chipsets.
--- drivers/scsi/ufs/ufs-mediatek.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/scsi/ufs/ufs-mediatek.c +8 -0
@@ -7,6 +7,7 @@*/ #include <linux/arm-smccc.h> +#include <linux/bitfield.h> #include <linux/of.h> #include <linux/of_address.h> #include <linux/phy/phy.h>
@@ -305,6 +306,13 @@ static int ufs_mtk_post_link(struct ufs_hba *hba)/* enable unipro clock gating feature */ ufs_mtk_cfg_unipro_cg (hba, true); +/* configure auto-hibern8 timer to 10ms */ +if (ufshcd_is_auto_hibern8_supported (hba)) { +ufshcd_auto_hibern8_update (hba, +FIELD_PREP (UFSHCI_AHIBERN8_TIMER_MASK ,10 ) | +FIELD_PREP (UFSHCI_AHIBERN8_SCALE_MASK ,3 )); + } +return 0 ; }
Signature · 1 line
2.18.0
PATCH v2 6/6 scsi: ufs-mediatek: configure and enable clk-gating
In reply to Stanley ChuEnable clk-gating with customized delayed timer value in MediaTek Chipsets.
--- drivers/scsi/ufs/ufs-mediatek.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
drivers/scsi/ufs/ufs-mediatek.c +22 -0
@@ -210,6 +210,9 @@ static int ufs_mtk_init(struct ufs_hba *hba)/* Enable runtime autosuspend */ hba->caps |=UFSHCD_CAP_RPM_AUTOSUSPEND ; +/* Enable clock-gating */ + hba->caps |=UFSHCD_CAP_CLK_GATING ; +/* * ufshcd_vops_init() is invoked after * ufshcd_setup_clock(true) in ufshcd_hba_init() thus
@@ -298,6 +301,23 @@ static int ufs_mtk_pre_link(struct ufs_hba *hba)return ret; } +static void ufs_mtk_setup_clk_gating (struct ufs_hba *hba) +{ +unsigned long flags; +u32 ah_ms; + +if (ufshcd_is_clkgating_allowed (hba)) { +if (ufshcd_is_auto_hibern8_supported (hba) && hba->ahit) + ah_ms =FIELD_GET (UFSHCI_AHIBERN8_TIMER_MASK , + hba->ahit); +else + ah_ms =10 ; +spin_lock_irqsave (hba->host->host_lock, flags); + hba->clk_gating.delay_ms = ah_ms +5 ; +spin_unlock_irqrestore (hba->host->host_lock, flags); + } +} +static int ufs_mtk_post_link (struct ufs_hba *hba) {/* disable device LCC */
@@ -313,6 +333,8 @@ static int ufs_mtk_post_link(struct ufs_hba *hba) FIELD_PREP(UFSHCI_AHIBERN8_SCALE_MASK, 3)); } +ufs_mtk_setup_clk_gating (hba); +return 0 ; }
Signature · 1 line
2.18.0
Martin K. Petersen
AppliedStanley,
Quoted 6 lines
This series provides MediaTek vendor implementations as below,
- Device reset
- Reference clock control
- Auto-hibernate enabling with customized timer value
- Clk-gating enabling with customized delayed timer value
Applied to 5.6/scsi-queue, thanks!
Signature · 6 lines
Martin K. Petersen Oracle Linux Engineering _______________________________________________ Linux-mediatek mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-mediatek