18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (C) 2019 MediaTek Inc. 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci#ifndef _UFS_MEDIATEK_H 78c2ecf20Sopenharmony_ci#define _UFS_MEDIATEK_H 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#include <linux/bitops.h> 108c2ecf20Sopenharmony_ci#include <linux/soc/mediatek/mtk_sip_svc.h> 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci/* 138c2ecf20Sopenharmony_ci * Vendor specific UFSHCI Registers 148c2ecf20Sopenharmony_ci */ 158c2ecf20Sopenharmony_ci#define REG_UFS_REFCLK_CTRL 0x144 168c2ecf20Sopenharmony_ci#define REG_UFS_EXTREG 0x2100 178c2ecf20Sopenharmony_ci#define REG_UFS_MPHYCTRL 0x2200 188c2ecf20Sopenharmony_ci#define REG_UFS_REJECT_MON 0x22AC 198c2ecf20Sopenharmony_ci#define REG_UFS_DEBUG_SEL 0x22C0 208c2ecf20Sopenharmony_ci#define REG_UFS_PROBE 0x22C8 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci/* 238c2ecf20Sopenharmony_ci * Ref-clk control 248c2ecf20Sopenharmony_ci * 258c2ecf20Sopenharmony_ci * Values for register REG_UFS_REFCLK_CTRL 268c2ecf20Sopenharmony_ci */ 278c2ecf20Sopenharmony_ci#define REFCLK_RELEASE 0x0 288c2ecf20Sopenharmony_ci#define REFCLK_REQUEST BIT(0) 298c2ecf20Sopenharmony_ci#define REFCLK_ACK BIT(1) 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci#define REFCLK_REQ_TIMEOUT_US 3000 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci/* 348c2ecf20Sopenharmony_ci * Vendor specific pre-defined parameters 358c2ecf20Sopenharmony_ci */ 368c2ecf20Sopenharmony_ci#define UFS_MTK_LIMIT_NUM_LANES_RX 2 378c2ecf20Sopenharmony_ci#define UFS_MTK_LIMIT_NUM_LANES_TX 2 388c2ecf20Sopenharmony_ci#define UFS_MTK_LIMIT_HSGEAR_RX UFS_HS_G3 398c2ecf20Sopenharmony_ci#define UFS_MTK_LIMIT_HSGEAR_TX UFS_HS_G3 408c2ecf20Sopenharmony_ci#define UFS_MTK_LIMIT_PWMGEAR_RX UFS_PWM_G4 418c2ecf20Sopenharmony_ci#define UFS_MTK_LIMIT_PWMGEAR_TX UFS_PWM_G4 428c2ecf20Sopenharmony_ci#define UFS_MTK_LIMIT_RX_PWR_PWM SLOW_MODE 438c2ecf20Sopenharmony_ci#define UFS_MTK_LIMIT_TX_PWR_PWM SLOW_MODE 448c2ecf20Sopenharmony_ci#define UFS_MTK_LIMIT_RX_PWR_HS FAST_MODE 458c2ecf20Sopenharmony_ci#define UFS_MTK_LIMIT_TX_PWR_HS FAST_MODE 468c2ecf20Sopenharmony_ci#define UFS_MTK_LIMIT_HS_RATE PA_HS_MODE_B 478c2ecf20Sopenharmony_ci#define UFS_MTK_LIMIT_DESIRED_MODE UFS_HS_MODE 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci/* 508c2ecf20Sopenharmony_ci * Other attributes 518c2ecf20Sopenharmony_ci */ 528c2ecf20Sopenharmony_ci#define VS_DEBUGCLOCKENABLE 0xD0A1 538c2ecf20Sopenharmony_ci#define VS_SAVEPOWERCONTROL 0xD0A6 548c2ecf20Sopenharmony_ci#define VS_UNIPROPOWERDOWNCONTROL 0xD0A8 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci/* 578c2ecf20Sopenharmony_ci * Vendor specific link state 588c2ecf20Sopenharmony_ci */ 598c2ecf20Sopenharmony_cienum { 608c2ecf20Sopenharmony_ci VS_LINK_DISABLED = 0, 618c2ecf20Sopenharmony_ci VS_LINK_DOWN = 1, 628c2ecf20Sopenharmony_ci VS_LINK_UP = 2, 638c2ecf20Sopenharmony_ci VS_LINK_HIBERN8 = 3, 648c2ecf20Sopenharmony_ci VS_LINK_LOST = 4, 658c2ecf20Sopenharmony_ci VS_LINK_CFG = 5, 668c2ecf20Sopenharmony_ci}; 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci/* 698c2ecf20Sopenharmony_ci * SiP commands 708c2ecf20Sopenharmony_ci */ 718c2ecf20Sopenharmony_ci#define MTK_SIP_UFS_CONTROL MTK_SIP_SMC_CMD(0x276) 728c2ecf20Sopenharmony_ci#define UFS_MTK_SIP_DEVICE_RESET BIT(1) 738c2ecf20Sopenharmony_ci#define UFS_MTK_SIP_CRYPTO_CTRL BIT(2) 748c2ecf20Sopenharmony_ci#define UFS_MTK_SIP_REF_CLK_NOTIFICATION BIT(3) 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci/* 778c2ecf20Sopenharmony_ci * VS_DEBUGCLOCKENABLE 788c2ecf20Sopenharmony_ci */ 798c2ecf20Sopenharmony_cienum { 808c2ecf20Sopenharmony_ci TX_SYMBOL_CLK_REQ_FORCE = 5, 818c2ecf20Sopenharmony_ci}; 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci/* 848c2ecf20Sopenharmony_ci * VS_SAVEPOWERCONTROL 858c2ecf20Sopenharmony_ci */ 868c2ecf20Sopenharmony_cienum { 878c2ecf20Sopenharmony_ci RX_SYMBOL_CLK_GATE_EN = 0, 888c2ecf20Sopenharmony_ci SYS_CLK_GATE_EN = 2, 898c2ecf20Sopenharmony_ci TX_CLK_GATE_EN = 3, 908c2ecf20Sopenharmony_ci}; 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci/* 938c2ecf20Sopenharmony_ci * Host capability 948c2ecf20Sopenharmony_ci */ 958c2ecf20Sopenharmony_cienum ufs_mtk_host_caps { 968c2ecf20Sopenharmony_ci UFS_MTK_CAP_BOOST_CRYPT_ENGINE = 1 << 0, 978c2ecf20Sopenharmony_ci}; 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_cistruct ufs_mtk_crypt_cfg { 1008c2ecf20Sopenharmony_ci struct regulator *reg_vcore; 1018c2ecf20Sopenharmony_ci struct clk *clk_crypt_perf; 1028c2ecf20Sopenharmony_ci struct clk *clk_crypt_mux; 1038c2ecf20Sopenharmony_ci struct clk *clk_crypt_lp; 1048c2ecf20Sopenharmony_ci int vcore_volt; 1058c2ecf20Sopenharmony_ci}; 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_cistruct ufs_mtk_host_cfg { 1088c2ecf20Sopenharmony_ci enum ufs_mtk_host_caps caps; 1098c2ecf20Sopenharmony_ci}; 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_cistruct ufs_mtk_host { 1128c2ecf20Sopenharmony_ci struct ufs_hba *hba; 1138c2ecf20Sopenharmony_ci struct phy *mphy; 1148c2ecf20Sopenharmony_ci struct ufs_mtk_host_cfg *cfg; 1158c2ecf20Sopenharmony_ci struct ufs_mtk_crypt_cfg *crypt; 1168c2ecf20Sopenharmony_ci enum ufs_mtk_host_caps caps; 1178c2ecf20Sopenharmony_ci struct reset_control *hci_reset; 1188c2ecf20Sopenharmony_ci struct reset_control *unipro_reset; 1198c2ecf20Sopenharmony_ci struct reset_control *crypto_reset; 1208c2ecf20Sopenharmony_ci bool mphy_powered_on; 1218c2ecf20Sopenharmony_ci bool unipro_lpm; 1228c2ecf20Sopenharmony_ci bool ref_clk_enabled; 1238c2ecf20Sopenharmony_ci u16 ref_clk_ungating_wait_us; 1248c2ecf20Sopenharmony_ci u16 ref_clk_gating_wait_us; 1258c2ecf20Sopenharmony_ci}; 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci#endif /* !_UFS_MEDIATEK_H */ 128