18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (c) 2017, HiSilicon. All rights reserved.
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#ifndef UFS_HISI_H_
78c2ecf20Sopenharmony_ci#define UFS_HISI_H_
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#define HBRN8_POLL_TOUT_MS	1000
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci/*
128c2ecf20Sopenharmony_ci * ufs sysctrl specific define
138c2ecf20Sopenharmony_ci */
148c2ecf20Sopenharmony_ci#define PSW_POWER_CTRL	(0x04)
158c2ecf20Sopenharmony_ci#define PHY_ISO_EN	(0x08)
168c2ecf20Sopenharmony_ci#define HC_LP_CTRL	(0x0C)
178c2ecf20Sopenharmony_ci#define PHY_CLK_CTRL	(0x10)
188c2ecf20Sopenharmony_ci#define PSW_CLK_CTRL	(0x14)
198c2ecf20Sopenharmony_ci#define CLOCK_GATE_BYPASS	(0x18)
208c2ecf20Sopenharmony_ci#define RESET_CTRL_EN	(0x1C)
218c2ecf20Sopenharmony_ci#define UFS_SYSCTRL	(0x5C)
228c2ecf20Sopenharmony_ci#define UFS_DEVICE_RESET_CTRL	(0x60)
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci#define BIT_UFS_PSW_ISO_CTRL		(1 << 16)
258c2ecf20Sopenharmony_ci#define BIT_UFS_PSW_MTCMOS_EN		(1 << 0)
268c2ecf20Sopenharmony_ci#define BIT_UFS_REFCLK_ISO_EN		(1 << 16)
278c2ecf20Sopenharmony_ci#define BIT_UFS_PHY_ISO_CTRL		(1 << 0)
288c2ecf20Sopenharmony_ci#define BIT_SYSCTRL_LP_ISOL_EN		(1 << 16)
298c2ecf20Sopenharmony_ci#define BIT_SYSCTRL_PWR_READY		(1 << 8)
308c2ecf20Sopenharmony_ci#define BIT_SYSCTRL_REF_CLOCK_EN	(1 << 24)
318c2ecf20Sopenharmony_ci#define MASK_SYSCTRL_REF_CLOCK_SEL	(0x3 << 8)
328c2ecf20Sopenharmony_ci#define MASK_SYSCTRL_CFG_CLOCK_FREQ	(0xFF)
338c2ecf20Sopenharmony_ci#define UFS_FREQ_CFG_CLK                (0x39)
348c2ecf20Sopenharmony_ci#define BIT_SYSCTRL_PSW_CLK_EN		(1 << 4)
358c2ecf20Sopenharmony_ci#define MASK_UFS_CLK_GATE_BYPASS	(0x3F)
368c2ecf20Sopenharmony_ci#define BIT_SYSCTRL_LP_RESET_N		(1 << 0)
378c2ecf20Sopenharmony_ci#define BIT_UFS_REFCLK_SRC_SEl		(1 << 0)
388c2ecf20Sopenharmony_ci#define MASK_UFS_SYSCRTL_BYPASS		(0x3F << 16)
398c2ecf20Sopenharmony_ci#define MASK_UFS_DEVICE_RESET		(0x1 << 16)
408c2ecf20Sopenharmony_ci#define BIT_UFS_DEVICE_RESET		(0x1)
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci/*
438c2ecf20Sopenharmony_ci * M-TX Configuration Attributes for Hixxxx
448c2ecf20Sopenharmony_ci */
458c2ecf20Sopenharmony_ci#define MPHY_TX_FSM_STATE	0x41
468c2ecf20Sopenharmony_ci#define TX_FSM_HIBERN8	0x1
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci/*
498c2ecf20Sopenharmony_ci * Hixxxx UFS HC specific Registers
508c2ecf20Sopenharmony_ci */
518c2ecf20Sopenharmony_cienum {
528c2ecf20Sopenharmony_ci	UFS_REG_OCPTHRTL = 0xc0,
538c2ecf20Sopenharmony_ci	UFS_REG_OOCPR    = 0xc4,
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci	UFS_REG_CDACFG   = 0xd0,
568c2ecf20Sopenharmony_ci	UFS_REG_CDATX1   = 0xd4,
578c2ecf20Sopenharmony_ci	UFS_REG_CDATX2   = 0xd8,
588c2ecf20Sopenharmony_ci	UFS_REG_CDARX1   = 0xdc,
598c2ecf20Sopenharmony_ci	UFS_REG_CDARX2   = 0xe0,
608c2ecf20Sopenharmony_ci	UFS_REG_CDASTA   = 0xe4,
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci	UFS_REG_LBMCFG   = 0xf0,
638c2ecf20Sopenharmony_ci	UFS_REG_LBMSTA   = 0xf4,
648c2ecf20Sopenharmony_ci	UFS_REG_UFSMODE  = 0xf8,
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci	UFS_REG_HCLKDIV  = 0xfc,
678c2ecf20Sopenharmony_ci};
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci/* AHIT - Auto-Hibernate Idle Timer */
708c2ecf20Sopenharmony_ci#define UFS_AHIT_AH8ITV_MASK	0x3FF
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci/* REG UFS_REG_OCPTHRTL definition */
738c2ecf20Sopenharmony_ci#define UFS_HCLKDIV_NORMAL_VALUE	0xE4
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci/* vendor specific pre-defined parameters */
768c2ecf20Sopenharmony_ci#define SLOW	1
778c2ecf20Sopenharmony_ci#define FAST	2
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci#define UFS_HISI_LIMIT_NUM_LANES_RX	2
808c2ecf20Sopenharmony_ci#define UFS_HISI_LIMIT_NUM_LANES_TX	2
818c2ecf20Sopenharmony_ci#define UFS_HISI_LIMIT_HSGEAR_RX	UFS_HS_G3
828c2ecf20Sopenharmony_ci#define UFS_HISI_LIMIT_HSGEAR_TX	UFS_HS_G3
838c2ecf20Sopenharmony_ci#define UFS_HISI_LIMIT_PWMGEAR_RX	UFS_PWM_G4
848c2ecf20Sopenharmony_ci#define UFS_HISI_LIMIT_PWMGEAR_TX	UFS_PWM_G4
858c2ecf20Sopenharmony_ci#define UFS_HISI_LIMIT_RX_PWR_PWM	SLOW_MODE
868c2ecf20Sopenharmony_ci#define UFS_HISI_LIMIT_TX_PWR_PWM	SLOW_MODE
878c2ecf20Sopenharmony_ci#define UFS_HISI_LIMIT_RX_PWR_HS	FAST_MODE
888c2ecf20Sopenharmony_ci#define UFS_HISI_LIMIT_TX_PWR_HS	FAST_MODE
898c2ecf20Sopenharmony_ci#define UFS_HISI_LIMIT_HS_RATE	PA_HS_MODE_B
908c2ecf20Sopenharmony_ci#define UFS_HISI_LIMIT_DESIRED_MODE	FAST
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci#define UFS_HISI_CAP_RESERVED		BIT(0)
938c2ecf20Sopenharmony_ci#define UFS_HISI_CAP_PHY10nm		BIT(1)
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_cistruct ufs_hisi_host {
968c2ecf20Sopenharmony_ci	struct ufs_hba *hba;
978c2ecf20Sopenharmony_ci	void __iomem *ufs_sys_ctrl;
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci	struct reset_control	*rst;
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci	uint64_t caps;
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci	bool in_suspend;
1048c2ecf20Sopenharmony_ci};
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci#define ufs_sys_ctrl_writel(host, val, reg)                                    \
1078c2ecf20Sopenharmony_ci	writel((val), (host)->ufs_sys_ctrl + (reg))
1088c2ecf20Sopenharmony_ci#define ufs_sys_ctrl_readl(host, reg) readl((host)->ufs_sys_ctrl + (reg))
1098c2ecf20Sopenharmony_ci#define ufs_sys_ctrl_set_bits(host, mask, reg)                                 \
1108c2ecf20Sopenharmony_ci	ufs_sys_ctrl_writel(                                                   \
1118c2ecf20Sopenharmony_ci		(host), ((mask) | (ufs_sys_ctrl_readl((host), (reg)))), (reg))
1128c2ecf20Sopenharmony_ci#define ufs_sys_ctrl_clr_bits(host, mask, reg)                                 \
1138c2ecf20Sopenharmony_ci	ufs_sys_ctrl_writel((host),                                            \
1148c2ecf20Sopenharmony_ci			    ((~(mask)) & (ufs_sys_ctrl_readl((host), (reg)))), \
1158c2ecf20Sopenharmony_ci			    (reg))
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci#endif /* UFS_HISI_H_ */
118