// SPDX-License-Identifier: GPL-2.0-only
/*
* UFS PHY driver data for Google Tensor gs101 SoC
*
* Copyright (C) 2024 Linaro Ltd
* Author: Peter Griffin <peter.griffin@linaro.org>
*/
#include "phy-samsung-ufs.h"
#define TENSOR_GS101_PHY_CTRL 0 x3ec8
#define TENSOR_GS101_PHY_CTRL_MASK 0 x1
#define TENSOR_GS101_PHY_CTRL_EN BIT(0 )
#define PHY_GS101_LANE_OFFSET 0 x200
#define TRSV_REG338 0 x338
#define LN0_MON_RX_CAL_DONE BIT(3 )
#define TRSV_REG339 0 x339
#define LN0_MON_RX_CDR_FLD_CK_MODE_DONE BIT(3 )
#define TRSV_REG222 0 x222
#define LN0_OVRD_RX_CDR_EN BIT(4 )
#define LN0_RX_CDR_EN BIT(3 )
#define PHY_PMA_TRSV_ADDR(reg, lane) (PHY_APB_ADDR((reg) + \
((lane) * PHY_GS101_LANE_OFFSET)))
#define PHY_TRSV_REG_CFG_GS101(o, v, d) \
PHY_TRSV_REG_CFG_OFFSET(o, v, d, PHY_GS101_LANE_OFFSET)
/* Calibration for phy initialization */
static const struct samsung_ufs_phy_cfg tensor_gs101_pre_init_cfg[] = {
PHY_COMN_REG_CFG(0 x43, 0 x10, PWR_MODE_ANY),
PHY_COMN_REG_CFG(0 x3C, 0 x14, PWR_MODE_ANY),
PHY_COMN_REG_CFG(0 x46, 0 x48, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x200, 0 x00, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x201, 0 x06, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x202, 0 x06, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x203, 0 x0a, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x204, 0 x00, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x205, 0 x11, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x207, 0 x0c, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x2E1, 0 xc0, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x22D, 0 xb8, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x234, 0 x60, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x238, 0 x13, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x239, 0 x48, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x23A, 0 x01, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x23B, 0 x25, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x23C, 0 x2a, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x23D, 0 x01, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x23E, 0 x13, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x23F, 0 x13, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x240, 0 x4a, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x243, 0 x40, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x244, 0 x02, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x25D, 0 x00, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x25E, 0 x3f, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x25F, 0 xff, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x273, 0 x33, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x274, 0 x50, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x284, 0 x02, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x285, 0 x02, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x2A2, 0 x04, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x25D, 0 x01, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x2FA, 0 x01, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x286, 0 x03, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x287, 0 x03, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x288, 0 x03, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x289, 0 x03, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x2B3, 0 x04, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x2B6, 0 x0b, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x2B7, 0 x0b, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x2B8, 0 x0b, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x2B9, 0 x0b, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x2BA, 0 x0b, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x2BB, 0 x06, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x2BC, 0 x06, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x2BD, 0 x06, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x29E, 0 x06, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x2E4, 0 x1a, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x2ED, 0 x25, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x269, 0 x1a, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x2F4, 0 x2f, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x34B, 0 x01, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x34C, 0 x23, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x34D, 0 x23, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x34E, 0 x45, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x34F, 0 x00, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x350, 0 x31, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x351, 0 x00, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x352, 0 x02, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x353, 0 x00, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x354, 0 x01, PWR_MODE_ANY),
PHY_COMN_REG_CFG(0 x43, 0 x18, PWR_MODE_ANY),
PHY_COMN_REG_CFG(0 x43, 0 x00, PWR_MODE_ANY),
END_UFS_PHY_CFG,
};
static const struct samsung_ufs_phy_cfg tensor_gs101_pre_pwr_hs_config[] = {
PHY_TRSV_REG_CFG_GS101(0 x369, 0 x11, PWR_MODE_ANY),
PHY_TRSV_REG_CFG_GS101(0 x246, 0 x03, PWR_MODE_ANY),
};
/* Calibration for HS mode series A/B */
static const struct samsung_ufs_phy_cfg tensor_gs101_post_pwr_hs_config[] = {
PHY_COMN_REG_CFG(0 x8, 0 x60, PWR_MODE_PWM_ANY),
PHY_TRSV_REG_CFG_GS101(0 x222, 0 x08, PWR_MODE_PWM_ANY),
PHY_TRSV_REG_CFG_GS101(0 x246, 0 x01, PWR_MODE_ANY),
END_UFS_PHY_CFG,
};
static const struct samsung_ufs_phy_cfg *tensor_gs101_ufs_phy_cfgs[CFG_TAG_MAX] = {
[CFG_PRE_INIT] = tensor_gs101_pre_init_cfg,
[CFG_PRE_PWR_HS] = tensor_gs101_pre_pwr_hs_config,
[CFG_POST_PWR_HS] = tensor_gs101_post_pwr_hs_config,
};
static const char * const tensor_gs101_ufs_phy_clks[] = {
"ref_clk" ,
};
static int gs101_phy_wait_for_calibration(struct phy *phy, u8 lane)
{
struct samsung_ufs_phy *ufs_phy = get_samsung_ufs_phy(phy);
const unsigned int timeout_us = 40000 ;
const unsigned int sleep_us = 40 ;
u32 val;
u32 off;
int err;
off = PHY_PMA_TRSV_ADDR(TRSV_REG338, lane);
err = readl_poll_timeout(ufs_phy->reg_pma + off,
val, (val & LN0_MON_RX_CAL_DONE),
sleep_us, timeout_us);
if (err) {
dev_err(ufs_phy->dev,
"failed to get phy cal done %d\n" , err);
}
return err;
}
#define DELAY_IN_US 40
#define RETRY_CNT 100
static int gs101_phy_wait_for_cdr_lock(struct phy *phy, u8 lane)
{
struct samsung_ufs_phy *ufs_phy = get_samsung_ufs_phy(phy);
u32 val;
int i;
for (i = 0 ; i < RETRY_CNT; i++) {
udelay(DELAY_IN_US);
val = readl(ufs_phy->reg_pma +
PHY_PMA_TRSV_ADDR(TRSV_REG339, lane));
if (val & LN0_MON_RX_CDR_FLD_CK_MODE_DONE)
return 0 ;
udelay(DELAY_IN_US);
/* Override and enable clock data recovery */
writel(LN0_OVRD_RX_CDR_EN, ufs_phy->reg_pma +
PHY_PMA_TRSV_ADDR(TRSV_REG222, lane));
writel(LN0_OVRD_RX_CDR_EN | LN0_RX_CDR_EN,
ufs_phy->reg_pma + PHY_PMA_TRSV_ADDR(TRSV_REG222, lane));
}
dev_err(ufs_phy->dev, "failed to get cdr lock\n" );
return -ETIMEDOUT;
}
const struct samsung_ufs_phy_drvdata tensor_gs101_ufs_phy = {
.cfgs = tensor_gs101_ufs_phy_cfgs,
.isol = {
.offset = TENSOR_GS101_PHY_CTRL,
.mask = TENSOR_GS101_PHY_CTRL_MASK,
.en = TENSOR_GS101_PHY_CTRL_EN,
},
.clk_list = tensor_gs101_ufs_phy_clks,
.num_clks = ARRAY_SIZE(tensor_gs101_ufs_phy_clks),
.wait_for_cal = gs101_phy_wait_for_calibration,
.wait_for_cdr = gs101_phy_wait_for_cdr_lock,
};
Messung V0.5 in Prozent C=97 H=96 G=96
¤ Dauer der Verarbeitung: 0.9 Sekunden
(vorverarbeitet am 2026-06-08)
¤
*© Formatika GbR, Deutschland