// SPDX-License-Identifier: GPL-2.0+
/*
* DPHY TX driver for the StarFive JH7110 SoC
*
* Copyright (C) 2023 StarFive Technology Co., Ltd.
* Author: Keith Zhao <keith.zhao@starfivetech.com>
* Author: Shengyang Chen <shengyang.chen@starfivetech.com>
*/
#include <linux/bitfield.h>
#include <linux/clk.h>
#include <linux/io.h>
#include <linux/iopoll.h>
#include <linux/mfd/syscon.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_device.h>
#include <linux/phy/phy.h>
#include <linux/phy/phy-mipi-dphy.h>
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>
#include <linux/reset.h>
#define STF_DPHY_APBIFSAIF_SYSCFG(x) (x)
#define STF_DPHY_AON_POWER_READY_N_ACTIVE 0
#define STF_DPHY_AON_POWER_READY_N BIT(0 )
#define STF_DPHY_CFG_L0_SWAP_SEL GENMASK(14 , 12 )
#define STF_DPHY_CFG_L1_SWAP_SEL GENMASK(17 , 15 )
#define STF_DPHY_CFG_L2_SWAP_SEL GENMASK(20 , 18 )
#define STF_DPHY_CFG_L3_SWAP_SEL GENMASK(23 , 21 )
#define STF_DPHY_CFG_L4_SWAP_SEL GENMASK(26 , 24 )
#define STF_DPHY_RGS_CDTX_PLL_UNLOCK BIT(18 )
#define STF_DPHY_RG_CDTX_L0N_HSTX_RES GENMASK(23 , 19 )
#define STF_DPHY_RG_CDTX_L0P_HSTX_RES GENMASK(28 , 24 )
#define STF_DPHY_RG_CDTX_L1P_HSTX_RES GENMASK(9 , 5 )
#define STF_DPHY_RG_CDTX_L2N_HSTX_RES GENMASK(14 , 10 )
#define STF_DPHY_RG_CDTX_L2P_HSTX_RES GENMASK(19 , 15 )
#define STF_DPHY_RG_CDTX_L3N_HSTX_RES GENMASK(24 , 20 )
#define STF_DPHY_RG_CDTX_L3P_HSTX_RES GENMASK(29 , 25 )
#define STF_DPHY_RG_CDTX_L4N_HSTX_RES GENMASK(4 , 0 )
#define STF_DPHY_RG_CDTX_L4P_HSTX_RES GENMASK(9 , 5 )
#define STF_DPHY_RG_CDTX_PLL_FBK_FRA GENMASK(23 , 0 )
#define STF_DPHY_RG_CDTX_PLL_FBK_INT GENMASK(8 , 0 )
#define STF_DPHY_RG_CDTX_PLL_FM_EN BIT(9 )
#define STF_DPHY_RG_CDTX_PLL_LDO_STB_X2_EN BIT(10 )
#define STF_DPHY_RG_CDTX_PLL_PRE_DIV GENMASK(12 , 11 )
#define STF_DPHY_RG_CDTX_PLL_SSC_EN BIT(18 )
#define STF_DPHY_RG_CLANE_HS_CLK_POST_TIME GENMASK(7 , 0 )
#define STF_DPHY_RG_CLANE_HS_CLK_PRE_TIME GENMASK(15 , 8 )
#define STF_DPHY_RG_CLANE_HS_PRE_TIME GENMASK(23 , 16 )
#define STF_DPHY_RG_CLANE_HS_TRAIL_TIME GENMASK(31 , 24 )
#define STF_DPHY_RG_CLANE_HS_ZERO_TIME GENMASK(7 , 0 )
#define STF_DPHY_RG_DLANE_HS_PRE_TIME GENMASK(15 , 8 )
#define STF_DPHY_RG_DLANE_HS_TRAIL_TIME GENMASK(23 , 16 )
#define STF_DPHY_RG_DLANE_HS_ZERO_TIME GENMASK(31 , 24 )
#define STF_DPHY_RG_EXTD_CYCLE_SEL GENMASK(2 , 0 )
#define STF_DPHY_SCFG_C_HS_PRE_ZERO_TIME GENMASK(31 , 0 )
#define STF_DPHY_SCFG_DSI_TXREADY_ESC_SEL GENMASK(2 , 1 )
#define STF_DPHY_SCFG_PPI_C_READY_SEL GENMASK(4 , 3 )
#define STF_DPHY_REFCLK_IN_SEL GENMASK(28 , 26 )
#define STF_DPHY_RESETB BIT(29 )
#define STF_DPHY_REFCLK_12M 1
#define STF_DPHY_BITRATE_ALIGN 10000000
#define STF_MAP_LANES_NUM 5
#define STF_DPHY_LSHIFT_16(x) (FIELD_PREP(GENMASK(23 , 16 ), (x)))
#define STF_DPHY_LSHIFT_8(x) (FIELD_PREP(GENMASK(15 , 8 ), (x)))
#define STF_DPHY_HW_DELAY_US 200
#define STF_DPHY_HW_TIMEOUT_US 5000
struct stf_dphy_config {
unsigned long bitrate;
u32 pll_fbk_int;
u32 pll_fbk_fra_val;
u32 extd_cycle_sel;
u32 dlane_hs_pre_time;
u32 dlane_hs_zero_time;
u32 dlane_hs_trail_time;
u32 clane_hs_pre_time;
u32 clane_hs_zero_time;
u32 clane_hs_trail_time;
u32 clane_hs_clk_pre_time;
u32 clane_hs_clk_post_time;
};
static const struct stf_dphy_config reg_configs[] = {
{160000000 , 0 x6a, 0 xaa, 0 x3, 0 xa, 0 x17, 0 x11, 0 x5, 0 x2b, 0 xd, 0 x7, 0 x3d},
{170000000 , 0 x71, 0 x55, 0 x3, 0 xb, 0 x18, 0 x11, 0 x5, 0 x2e, 0 xd, 0 x7, 0 x3d},
{180000000 , 0 x78, 0 x0, 0 x3, 0 xb, 0 x19, 0 x12, 0 x6, 0 x30, 0 xe, 0 x7, 0 x3e},
{190000000 , 0 x7e, 0 xaa, 0 x3, 0 xc, 0 x1a, 0 x12, 0 x6, 0 x33, 0 xe, 0 x7, 0 x3e},
{200000000 , 0 x85, 0 x55, 0 x3, 0 xc, 0 x1b, 0 x13, 0 x7, 0 x35, 0 xf, 0 x7, 0 x3f},
{320000000 , 0 x6a, 0 xaa, 0 x2, 0 x8, 0 x14, 0 xf, 0 x5, 0 x2b, 0 xd, 0 x3, 0 x23},
{330000000 , 0 x6e, 0 x0, 0 x2, 0 x8, 0 x15, 0 xf, 0 x5, 0 x2d, 0 xd, 0 x3, 0 x23},
{340000000 , 0 x71, 0 x55, 0 x2, 0 x9, 0 x15, 0 xf, 0 x5, 0 x2e, 0 xd, 0 x3, 0 x23},
{350000000 , 0 x74, 0 xaa, 0 x2, 0 x9, 0 x15, 0 x10, 0 x6, 0 x2f, 0 xe, 0 x3, 0 x24},
{360000000 , 0 x78, 0 x0, 0 x2, 0 x9, 0 x16, 0 x10, 0 x6, 0 x30, 0 xe, 0 x3, 0 x24},
{370000000 , 0 x7b, 0 x55, 0 x2, 0 x9, 0 x17, 0 x10, 0 x6, 0 x32, 0 xe, 0 x3, 0 x24},
{380000000 , 0 x7e, 0 xaa, 0 x2, 0 xa, 0 x17, 0 x10, 0 x6, 0 x33, 0 xe, 0 x3, 0 x24},
{390000000 , 0 x82, 0 x0, 0 x2, 0 xa, 0 x17, 0 x11, 0 x6, 0 x35, 0 xf, 0 x3, 0 x25},
{400000000 , 0 x85, 0 x55, 0 x2, 0 xa, 0 x18, 0 x11, 0 x7, 0 x35, 0 xf, 0 x3, 0 x25},
{410000000 , 0 x88, 0 xaa, 0 x2, 0 xa, 0 x19, 0 x11, 0 x7, 0 x37, 0 xf, 0 x3, 0 x25},
{420000000 , 0 x8c, 0 x0, 0 x2, 0 xa, 0 x19, 0 x12, 0 x7, 0 x38, 0 x10, 0 x3, 0 x26},
{430000000 , 0 x8f, 0 x55, 0 x2, 0 xb, 0 x19, 0 x12, 0 x7, 0 x39, 0 x10, 0 x3, 0 x26},
{440000000 , 0 x92, 0 xaa, 0 x2, 0 xb, 0 x1a, 0 x12, 0 x7, 0 x3b, 0 x10, 0 x3, 0 x26},
{450000000 , 0 x96, 0 x0, 0 x2, 0 xb, 0 x1b, 0 x12, 0 x8, 0 x3c, 0 x10, 0 x3, 0 x26},
{460000000 , 0 x99, 0 x55, 0 x2, 0 xb, 0 x1b, 0 x13, 0 x8, 0 x3d, 0 x11, 0 x3, 0 x27},
{470000000 , 0 x9c, 0 xaa, 0 x2, 0 xc, 0 x1b, 0 x13, 0 x8, 0 x3e, 0 x11, 0 x3, 0 x27},
{480000000 , 0 xa0, 0 x27, 0 x2, 0 xc, 0 x1c, 0 x13, 0 x8, 0 x40, 0 x11, 0 x3, 0 x27},
{490000000 , 0 xa3, 0 x55, 0 x2, 0 xc, 0 x1d, 0 x14, 0 x8, 0 x42, 0 x12, 0 x3, 0 x28},
{500000000 , 0 xa6, 0 xaa, 0 x2, 0 xc, 0 x1d, 0 x14, 0 x9, 0 x42, 0 x12, 0 x3, 0 x28},
{510000000 , 0 xaa, 0 x0, 0 x2, 0 xc, 0 x1e, 0 x14, 0 x9, 0 x44, 0 x12, 0 x3, 0 x28},
{520000000 , 0 xad, 0 x55, 0 x2, 0 xd, 0 x1e, 0 x15, 0 x9, 0 x45, 0 x13, 0 x3, 0 x29},
{530000000 , 0 xb0, 0 xaa, 0 x2, 0 xd, 0 x1e, 0 x15, 0 x9, 0 x47, 0 x13, 0 x3, 0 x29},
{540000000 , 0 xb4, 0 x0, 0 x2, 0 xd, 0 x1f, 0 x15, 0 x9, 0 x48, 0 x13, 0 x3, 0 x29},
{550000000 , 0 xb7, 0 x55, 0 x2, 0 xd, 0 x20, 0 x16, 0 x9, 0 x4a, 0 x14, 0 x3, 0 x2a},
{560000000 , 0 xba, 0 xaa, 0 x2, 0 xe, 0 x20, 0 x16, 0 xa, 0 x4a, 0 x14, 0 x3, 0 x2a},
{570000000 , 0 xbe, 0 x0, 0 x2, 0 xe, 0 x20, 0 x16, 0 xa, 0 x4c, 0 x14, 0 x3, 0 x2a},
{580000000 , 0 xc1, 0 x55, 0 x2, 0 xe, 0 x21, 0 x16, 0 xa, 0 x4d, 0 x14, 0 x3, 0 x2a},
{590000000 , 0 xc4, 0 xaa, 0 x2, 0 xe, 0 x22, 0 x17, 0 xa, 0 x4f, 0 x15, 0 x3, 0 x2b},
{600000000 , 0 xc8, 0 x0, 0 x2, 0 xe, 0 x23, 0 x17, 0 xa, 0 x50, 0 x15, 0 x3, 0 x2b},
{610000000 , 0 xcb, 0 x55, 0 x2, 0 xf, 0 x22, 0 x17, 0 xb, 0 x50, 0 x15, 0 x3, 0 x2b},
{620000000 , 0 xce, 0 xaa, 0 x2, 0 xf, 0 x23, 0 x18, 0 xb, 0 x52, 0 x16, 0 x3, 0 x2c},
{630000000 , 0 x69, 0 x0, 0 x1, 0 x7, 0 x12, 0 xd, 0 x5, 0 x2a, 0 xc, 0 x1, 0 x15},
{640000000 , 0 x6a, 0 xaa, 0 x1, 0 x7, 0 x13, 0 xe, 0 x5, 0 x2b, 0 xd, 0 x1, 0 x16},
{650000000 , 0 x6c, 0 x55, 0 x1, 0 x7, 0 x13, 0 xe, 0 x5, 0 x2c, 0 xd, 0 x1, 0 x16},
{660000000 , 0 x6e, 0 x0, 0 x1, 0 x7, 0 x13, 0 xe, 0 x5, 0 x2d, 0 xd, 0 x1, 0 x16},
{670000000 , 0 x6f, 0 xaa, 0 x1, 0 x8, 0 x13, 0 xe, 0 x5, 0 x2d, 0 xd, 0 x1, 0 x16},
{680000000 , 0 x71, 0 x55, 0 x1, 0 x8, 0 x13, 0 xe, 0 x5, 0 x2e, 0 xd, 0 x1, 0 x16},
{690000000 , 0 x73, 0 x0, 0 x1, 0 x8, 0 x14, 0 xe, 0 x6, 0 x2e, 0 xd, 0 x1, 0 x16},
{700000000 , 0 x74, 0 xaa, 0 x1, 0 x8, 0 x14, 0 xf, 0 x6, 0 x2f, 0 xe, 0 x1, 0 x16},
{710000000 , 0 x76, 0 x55, 0 x1, 0 x8, 0 x14, 0 xf, 0 x6, 0 x2f, 0 xe, 0 x1, 0 x17},
{720000000 , 0 x78, 0 x0, 0 x1, 0 x8, 0 x15, 0 xf, 0 x6, 0 x30, 0 xe, 0 x1, 0 x17},
{730000000 , 0 x79, 0 xaa, 0 x1, 0 x8, 0 x15, 0 xf, 0 x6, 0 x31, 0 xe, 0 x1, 0 x17},
{740000000 , 0 x7b, 0 x55, 0 x1, 0 x8, 0 x15, 0 xf, 0 x6, 0 x32, 0 xe, 0 x1, 0 x17},
{750000000 , 0 x7d, 0 x0, 0 x1, 0 x8, 0 x16, 0 xf, 0 x6, 0 x32, 0 xe, 0 x1, 0 x17},
{760000000 , 0 x7e, 0 xaa, 0 x1, 0 x9, 0 x15, 0 xf, 0 x6, 0 x33, 0 xe, 0 x1, 0 x17},
{770000000 , 0 x80, 0 x55, 0 x1, 0 x9, 0 x15, 0 x10, 0 x6, 0 x34, 0 xf, 0 x1, 0 x18},
{780000000 , 0 x82, 0 x0, 0 x1, 0 x9, 0 x16, 0 x10, 0 x6, 0 x35, 0 xf, 0 x1, 0 x18,},
{790000000 , 0 x83, 0 xaa, 0 x1, 0 x9, 0 x16, 0 x10, 0 x7, 0 x34, 0 xf, 0 x1, 0 x18},
{800000000 , 0 x85, 0 x55, 0 x1, 0 x9, 0 x17, 0 x10, 0 x7, 0 x35, 0 xf, 0 x1, 0 x18},
{810000000 , 0 x87, 0 x0, 0 x1, 0 x9, 0 x17, 0 x10, 0 x7, 0 x36, 0 xf, 0 x1, 0 x18},
{820000000 , 0 x88, 0 xaa, 0 x1, 0 x9, 0 x17, 0 x10, 0 x7, 0 x37, 0 xf, 0 x1, 0 x18},
{830000000 , 0 x8a, 0 x55, 0 x1, 0 x9, 0 x18, 0 x10, 0 x7, 0 x37, 0 xf, 0 x1, 0 x18},
{840000000 , 0 x8c, 0 x0, 0 x1, 0 x9, 0 x18, 0 x11, 0 x7, 0 x38, 0 x10, 0 x1, 0 x19},
{850000000 , 0 x8d, 0 xaa, 0 x1, 0 xa, 0 x17, 0 x11, 0 x7, 0 x39, 0 x10, 0 x1, 0 x19},
{860000000 , 0 x8f, 0 x55, 0 x1, 0 xa, 0 x18, 0 x11, 0 x7, 0 x39, 0 x10, 0 x1, 0 x19},
{870000000 , 0 x91, 0 x0, 0 x1, 0 xa, 0 x18, 0 x11, 0 x7, 0 x3a, 0 x10, 0 x1, 0 x19},
{880000000 , 0 x92, 0 xaa, 0 x1, 0 xa, 0 x18, 0 x11, 0 x7, 0 x3b, 0 x10, 0 x1, 0 x19},
{890000000 , 0 x94, 0 x55, 0 x1, 0 xa, 0 x19, 0 x11, 0 x7, 0 x3c, 0 x10, 0 x1, 0 x19},
{900000000 , 0 x96, 0 x0, 0 x1, 0 xa, 0 x19, 0 x12, 0 x8, 0 x3c, 0 x10, 0 x1, 0 x19},
{910000000 , 0 x97, 0 xaa, 0 x1, 0 xa, 0 x19, 0 x12, 0 x8, 0 x3c, 0 x11, 0 x1, 0 x1a},
{920000000 , 0 x99, 0 x55, 0 x1, 0 xa, 0 x1a, 0 x12, 0 x8, 0 x3d, 0 x11, 0 x1, 0 x1a},
{930000000 , 0 x9b, 0 x0, 0 x1, 0 xa, 0 x1a, 0 x12, 0 x8, 0 x3e, 0 x11, 0 x1, 0 x1a},
{940000000 , 0 x9c, 0 xaa, 0 x1, 0 xb, 0 x1a, 0 x12, 0 x8, 0 x3e, 0 x11, 0 x1, 0 x1a},
{950000000 , 0 x9e, 0 x55, 0 x1, 0 xb, 0 x1a, 0 x12, 0 x8, 0 x3f, 0 x11, 0 x1, 0 x1a},
{960000000 , 0 xa0, 0 x0, 0 x1, 0 xb, 0 x1a, 0 x12, 0 x8, 0 x40, 0 x11, 0 x1, 0 x1a},
{970000000 , 0 xa1, 0 xaa, 0 x1, 0 xb, 0 x1b, 0 x13, 0 x8, 0 x41, 0 x12, 0 x1, 0 x1b},
{980000000 , 0 xa3, 0 x55, 0 x1, 0 xb, 0 x1b, 0 x13, 0 x8, 0 x42, 0 x12, 0 x1, 0 x1b},
{990000000 , 0 xa5, 0 x0, 0 x1, 0 xb, 0 x1b, 0 x13, 0 x8, 0 x42, 0 x12, 0 x1, 0 x1b},
{1000000000 , 0 xa6, 0 xaa, 0 x1, 0 xb, 0 x1c, 0 x13, 0 x9, 0 x42, 0 x12, 0 x1, 0 x1b},
};
struct stf_dphy_info {
/**
* @maps:
*
* Physical lanes and logic lanes mapping table.
*
* The default order is:
* [data lane 0, data lane 1, data lane 2, date lane 3, clk lane]
*/
u8 maps[STF_MAP_LANES_NUM];
};
struct stf_dphy {
struct device *dev;
void __iomem *topsys;
struct clk *txesc_clk;
struct reset_control *sys_rst;
struct phy_configure_opts_mipi_dphy config;
struct phy *phy;
const struct stf_dphy_info *info;
};
static u32 stf_dphy_get_config_index(u32 bitrate)
{
u32 i;
for (i = 0 ; i < ARRAY_SIZE(reg_configs); i++) {
if (reg_configs[i].bitrate == bitrate)
return i;
}
return 0 ;
}
static void stf_dphy_hw_reset(struct stf_dphy *dphy, int assert)
{
int rc;
u32 status = 0 ;
writel(FIELD_PREP(STF_DPHY_RESETB, assert),
dphy->topsys + STF_DPHY_APBIFSAIF_SYSCFG(100 ));
if (assert) {
rc = readl_poll_timeout_atomic(dphy->topsys +
STF_DPHY_APBIFSAIF_SYSCFG(8 ),
status,
!(FIELD_GET(STF_DPHY_RGS_CDTX_PLL_UNLOCK, status)),
STF_DPHY_HW_DELAY_US, STF_DPHY_HW_TIMEOUT_US);
if (rc)
dev_err(dphy->dev, "MIPI dphy-tx # PLL Locked\n" );
}
}
static int stf_dphy_configure(struct phy *phy, union phy_configure_opts *opts)
{
struct stf_dphy *dphy = phy_get_drvdata(phy);
const struct stf_dphy_info *info = dphy->info;
const struct stf_dphy_config *p = reg_configs;
unsigned long alignment = STF_DPHY_BITRATE_ALIGN;
u32 bitrate = opts->mipi_dphy.hs_clk_rate;
u32 tmp;
u32 i;
if (bitrate % alignment)
bitrate += alignment - (bitrate % alignment);
i = stf_dphy_get_config_index(bitrate);
tmp = readl(dphy->topsys + STF_DPHY_APBIFSAIF_SYSCFG(100 ));
tmp &= ~STF_DPHY_REFCLK_IN_SEL;
tmp |= FIELD_PREP(STF_DPHY_REFCLK_IN_SEL, STF_DPHY_REFCLK_12M);
writel(tmp, dphy->topsys + STF_DPHY_APBIFSAIF_SYSCFG(100 ));
writel(FIELD_PREP(STF_DPHY_RG_CDTX_L0N_HSTX_RES, 0 x10) |
FIELD_PREP(STF_DPHY_RG_CDTX_L0P_HSTX_RES, 0 x10),
dphy->topsys + STF_DPHY_APBIFSAIF_SYSCFG(8 ));
writel(FIELD_PREP(STF_DPHY_RG_CDTX_L0N_HSTX_RES, 0 x10) |
FIELD_PREP(STF_DPHY_RG_CDTX_L2N_HSTX_RES, 0 x10) |
FIELD_PREP(STF_DPHY_RG_CDTX_L3N_HSTX_RES, 0 x10) |
FIELD_PREP(STF_DPHY_RG_CDTX_L1P_HSTX_RES, 0 x10) |
FIELD_PREP(STF_DPHY_RG_CDTX_L2P_HSTX_RES, 0 x10) |
FIELD_PREP(STF_DPHY_RG_CDTX_L3P_HSTX_RES, 0 x10),
dphy->topsys + STF_DPHY_APBIFSAIF_SYSCFG(12 ));
writel(FIELD_PREP(STF_DPHY_RG_CDTX_L4N_HSTX_RES, 0 x10) |
FIELD_PREP(STF_DPHY_RG_CDTX_L4P_HSTX_RES, 0 x10),
dphy->topsys + STF_DPHY_APBIFSAIF_SYSCFG(16 ));
/* Lane setting */
writel(FIELD_PREP(STF_DPHY_AON_POWER_READY_N,
STF_DPHY_AON_POWER_READY_N_ACTIVE) |
FIELD_PREP(STF_DPHY_CFG_L0_SWAP_SEL, info->maps[0 ]) |
FIELD_PREP(STF_DPHY_CFG_L1_SWAP_SEL, info->maps[1 ]) |
FIELD_PREP(STF_DPHY_CFG_L2_SWAP_SEL, info->maps[2 ]) |
FIELD_PREP(STF_DPHY_CFG_L3_SWAP_SEL, info->maps[3 ]) |
FIELD_PREP(STF_DPHY_CFG_L4_SWAP_SEL, info->maps[4 ]),
dphy->topsys + STF_DPHY_APBIFSAIF_SYSCFG(0 ));
/* PLL setting */
writel(FIELD_PREP(STF_DPHY_RG_CDTX_PLL_SSC_EN, 0 x0),
dphy->topsys + STF_DPHY_APBIFSAIF_SYSCFG(28 ));
writel(FIELD_PREP(STF_DPHY_RG_CDTX_PLL_LDO_STB_X2_EN, 0 x1) |
FIELD_PREP(STF_DPHY_RG_CDTX_PLL_FM_EN, 0 x1) |
FIELD_PREP(STF_DPHY_RG_CDTX_PLL_PRE_DIV, 0 x0) |
FIELD_PREP(STF_DPHY_RG_CDTX_PLL_FBK_INT, p[i].pll_fbk_int),
dphy->topsys + STF_DPHY_APBIFSAIF_SYSCFG(24 ));
writel(FIELD_PREP(STF_DPHY_RG_CDTX_PLL_FBK_FRA,
STF_DPHY_LSHIFT_16(p[i].pll_fbk_fra_val) |
STF_DPHY_LSHIFT_8(p[i].pll_fbk_fra_val) |
p[i].pll_fbk_fra_val),
dphy->topsys + STF_DPHY_APBIFSAIF_SYSCFG(20 ));
writel(FIELD_PREP(STF_DPHY_RG_EXTD_CYCLE_SEL, p[i].extd_cycle_sel),
dphy->topsys + STF_DPHY_APBIFSAIF_SYSCFG(40 ));
writel(FIELD_PREP(STF_DPHY_RG_DLANE_HS_PRE_TIME, p[i].dlane_hs_pre_time) |
FIELD_PREP(STF_DPHY_RG_DLANE_HS_ZERO_TIME, p[i].dlane_hs_zero_time) |
FIELD_PREP(STF_DPHY_RG_DLANE_HS_TRAIL_TIME, p[i].dlane_hs_trail_time) |
FIELD_PREP(STF_DPHY_RG_CLANE_HS_ZERO_TIME, p[i].clane_hs_zero_time),
dphy->topsys + STF_DPHY_APBIFSAIF_SYSCFG(36 ));
writel(FIELD_PREP(STF_DPHY_RG_CLANE_HS_PRE_TIME, p[i].clane_hs_pre_time) |
FIELD_PREP(STF_DPHY_RG_CLANE_HS_TRAIL_TIME, p[i].clane_hs_trail_time) |
FIELD_PREP(STF_DPHY_RG_CLANE_HS_CLK_PRE_TIME, p[i].clane_hs_clk_pre_time) |
FIELD_PREP(STF_DPHY_RG_CLANE_HS_CLK_POST_TIME, p[i].clane_hs_clk_post_time),
dphy->topsys + STF_DPHY_APBIFSAIF_SYSCFG(32 ));
return 0 ;
}
static int stf_dphy_init(struct phy *phy)
{
struct stf_dphy *dphy = phy_get_drvdata(phy);
int ret;
stf_dphy_hw_reset(dphy, 1 );
writel(FIELD_PREP(STF_DPHY_SCFG_PPI_C_READY_SEL, 0 ) |
FIELD_PREP(STF_DPHY_SCFG_DSI_TXREADY_ESC_SEL, 0 ),
dphy->topsys + STF_DPHY_APBIFSAIF_SYSCFG(48 ));
writel(FIELD_PREP(STF_DPHY_SCFG_C_HS_PRE_ZERO_TIME, 0 x30),
dphy->topsys + STF_DPHY_APBIFSAIF_SYSCFG(44 ));
ret = clk_prepare_enable(dphy->txesc_clk);
if (ret) {
dev_err(dphy->dev, "Failed to prepare/enable txesc_clk\n" );
return ret;
}
ret = reset_control_deassert(dphy->sys_rst);
if (ret) {
dev_err(dphy->dev, "Failed to deassert sys_rst\n" );
return ret;
}
return 0 ;
}
static int stf_dphy_exit(struct phy *phy)
{
struct stf_dphy *dphy = phy_get_drvdata(phy);
int ret;
ret = reset_control_assert(dphy->sys_rst);
if (ret) {
dev_err(dphy->dev, "Failed to assert sys_rst\n" );
return ret;
}
clk_disable_unprepare(dphy->txesc_clk);
stf_dphy_hw_reset(dphy, 0 );
return 0 ;
}
static int stf_dphy_power_on(struct phy *phy)
{
struct stf_dphy *dphy = phy_get_drvdata(phy);
return pm_runtime_resume_and_get(dphy->dev);
}
static int stf_dphy_validate(struct phy *phy, enum phy_mode mode, int submode,
union phy_configure_opts *opts)
{
if (mode != PHY_MODE_MIPI_DPHY)
return -EINVAL;
return 0 ;
}
static int stf_dphy_power_off(struct phy *phy)
{
struct stf_dphy *dphy = phy_get_drvdata(phy);
return pm_runtime_put_sync(dphy->dev);
}
static const struct phy_ops stf_dphy_ops = {
.power_on = stf_dphy_power_on,
.power_off = stf_dphy_power_off,
.init = stf_dphy_init,
.exit = stf_dphy_exit,
.configure = stf_dphy_configure,
.validate = stf_dphy_validate,
.owner = THIS_MODULE,
};
static int stf_dphy_probe(struct platform_device *pdev)
{
struct phy_provider *phy_provider;
struct stf_dphy *dphy;
dphy = devm_kzalloc(&pdev->dev, sizeof (*dphy), GFP_KERNEL);
if (!dphy)
return -ENOMEM;
dphy->info = of_device_get_match_data(&pdev->dev);
dphy->dev = &pdev->dev;
dev_set_drvdata(&pdev->dev, dphy);
dphy->topsys = devm_platform_ioremap_resource(pdev, 0 );
if (IS_ERR(dphy->topsys))
return PTR_ERR(dphy->topsys);
pm_runtime_enable(&pdev->dev);
dphy->txesc_clk = devm_clk_get(&pdev->dev, "txesc" );
if (IS_ERR(dphy->txesc_clk))
return dev_err_probe(&pdev->dev, PTR_ERR(dphy->txesc_clk),
"Failed to get txesc clock\n" );
dphy->sys_rst = devm_reset_control_get_exclusive(&pdev->dev, "sys" );
if (IS_ERR(dphy->sys_rst))
return dev_err_probe(&pdev->dev, PTR_ERR(dphy->sys_rst),
"Failed to get sys reset\n" );
dphy->phy = devm_phy_create(&pdev->dev, NULL, &stf_dphy_ops);
if (IS_ERR(dphy->phy))
return dev_err_probe(&pdev->dev, PTR_ERR(dphy->phy),
"Failed to create phy\n" );
phy_set_drvdata(dphy->phy, dphy);
phy_provider = devm_of_phy_provider_register(&pdev->dev, of_phy_simple_xlate);
if (IS_ERR(phy_provider))
return dev_err_probe(&pdev->dev, PTR_ERR(phy_provider),
"Failed to register phy\n" );
return 0 ;
}
static const struct stf_dphy_info starfive_dphy_info = {
.maps = {0 , 1 , 2 , 3 , 4 },
};
static const struct of_device_id stf_dphy_dt_ids[] = {
{
.compatible = "starfive,jh7110-dphy-tx" ,
.data = &starfive_dphy_info,
},
{ /* sentinel */ },
};
MODULE_DEVICE_TABLE(of, stf_dphy_dt_ids);
static struct platform_driver stf_dphy_driver = {
.driver = {
.name = "starfive-dphy-tx" ,
.of_match_table = stf_dphy_dt_ids,
},
.probe = stf_dphy_probe,
};
module_platform_driver(stf_dphy_driver);
MODULE_AUTHOR("Keith Zhao <keith.zhao@starfivetech.com>" );
MODULE_AUTHOR("Shengyang Chen <shengyang.chen@starfivetech.com>" );
MODULE_DESCRIPTION("StarFive JH7110 DPHY TX driver" );
MODULE_LICENSE("GPL" );
Messung V0.5 in Prozent C=96 H=96 G=95
¤ Dauer der Verarbeitung: 0.11 Sekunden
(vorverarbeitet am 2026-06-08)
¤
*© Formatika GbR, Deutschland