Add StarFive JHB100 soc UFS platform driver
Subsystems (5)
v4 cover Add StarFive JHB100 soc UFS platform driver
JHB100 is a Starfive new RISC-V SoC for datacenter BMC (BaseBoard Managent Controller). Similar with Aspeed 27x0.
JHB100 contain 1 UFS 3.1 interface and using Synopsys designware UFS controller/unipro/M-PHY. The ufs-starfive.c contain JHB100 UFS platform driver, unipro driver and M-PHY driver.
The patch base on kernel v7.4-rc1
previous link:
v1:
https://patchwork.kernel.org/project/linux-scsi/cover/[email protected]/
v2: can't find. (send them 2026.05.09)
v3: https://patchwork.kernel.org/project/linux-scsi/cover/[email protected]/
changes:
v4:
patch1: and operating-table-v2 to required attribue and add it to example dts
Add new patch2 to make PHY register DME attribute tables per-call to fix sashiko ai review bug.
new patch3 change commit message.
new patch4 fix sashiko ai review bug.
1. remove the main clock and make it enable in core clk function.
2. add phy_rst flag and phy reset assert while phy init failed.
v3:
follow sashiko AI review comments to modify the patch
patch1: remove freq hz setting.
syscon change to phandle because this is no argument.
patch3: Call ufshcd_pltfrm_remove(pdev) and add exit function in module remove functions.
v2:
patch1 rename dts binding doc from starfive,ufs to starfive,jhb100-ufs
Minda Chen (4):
scsi: ufs: dt-bindings: starfive: Add UFS Host Controller for JHB100
SoC
scsi: ufs: amd-versal2: Make PHY register DME attribute tables
per-call
scsi: ufs: dwc: Rename amd-versal2 read/write PHY API and move to dwc
common file
scsi: ufs: starfive: Add UFS support for StarFive JHB100 SoC
.../bindings/ufs/starfive,jhb100-ufs.yaml | 81 +++++ MAINTAINERS | 6 + drivers/ufs/host/Kconfig | 13 + drivers/ufs/host/Makefile | 1 + drivers/ufs/host/ufs-amd-versal2.c | 85 ++---- drivers/ufs/host/ufs-starfive.c | 283 ++++++++++++++++++ drivers/ufs/host/ufshcd-dwc.c | 61 ++++ drivers/ufs/host/ufshcd-dwc.h | 20 ++ 8 files changed, 482 insertions(+), 68 deletions(-) create mode 100644 Documentation/devicetree/bindings/ufs/starfive,jhb100-ufs.yaml create mode 100644 drivers/ufs/host/ufs-starfive.c
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
Signature · 1 line
2.17.1
PATCH v4 1/4 scsi: ufs: dt-bindings: starfive: Add UFS Host Controller for JHB100 SoC
Add devicetree document for UFS Host Controller StarFive JHB100 SoC. The UFS controller is based on the Synopsys DesignWare UFS controller.
--- .../bindings/ufs/starfive,jhb100-ufs.yaml | 81 +++++++++++++++++++ MAINTAINERS | 5 ++ 2 files changed, 86 insertions(+) create mode 100644 Documentation/devicetree/bindings/ufs/starfive,jhb100-ufs.yaml
Documentation/devicetree/bindings/ufs/starfive,jhb100-ufs.yaml new file +81 -0
@@ -0,0 +1,81 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/ufs/starfive,jhb100-ufs.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: StarFive Universal Flash Storage (UFS) Controller + +maintainers: + - Minda Chen <[email protected]> + +allOf: + - $ref: ufs-common.yaml + +properties: + compatible: + const: starfive,jhb100-ufs + + reg: + maxItems: 1 + + clocks: + maxItems: 1 + + clock-names: + items: + - const: main + + resets: + items: + - description: UFS main reset + - description: UFS PHY reset + + reset-names: + items: + - const: main + - const: phy + + interrupts: + maxItems: 1 + + starfive,syscon: + $ref: /schemas/types.yaml#/definitions/phandle + description: + The phandle to the StarFive JHB100 SoC Peripheral-1 syscon + register block. + +required: + - compatible + - reg + - clocks + - clock-names + - resets + - reset-names + - interrupts + - starfive,syscon + - operating-points-v2 + +unevaluatedProperties: false + +examples: + - | + ufs@11b10000 { + compatible = "starfive,jhb100-ufs"; + reg = <0x11b10000 0x20000>; + interrupts = <105>; + clocks = <&syscrg 4>; + clock-names = "main"; + resets = <&syscrg 10>, + <&syscrg 7>; + reset-names = "main", "phy"; + starfive,syscon = <&syscon>; + operating-points-v2 = <&ufs_opp_table>; + + ufs_opp_table: opp-table { + compatible = "operating-points-v2"; + opp-100000000 { + opp-hz = /bits/ 64 <100000000>; + }; + }; + };
MAINTAINERS +5 -0
@@ -28801,6 +28801,11 @@ L: [email protected] S: Maintained F: drivers/ufs/host/ufs-renesas.c +UNIVERSAL FLASH STORAGE HOST CONTROLLER DRIVER STARFIVE +M: Minda Chen <[email protected]> +S: Maintained +F: Documentation/devicetree/bindings/ufs/starfive,jhb100-ufs.yaml + UNIWILL LAPTOP DRIVER M: Armin Wolf <[email protected]> L: [email protected]
Signature · 1 line
2.17.1
PATCH v4 2/4 scsi: ufs: amd-versal2: Make PHY register DME attribute tables per-call
In reply to Minda Chenufs_versal2_phy_reg_write() and ufs_versal2_phy_reg_read() keep their DME attribute tables in static, writable arrays and patch the address and value into them on every call. This is not safe once more than one host instance uses the helpers concurrently.
Build the tables on the stack and make them const, in preparation for moving the helpers to the common DWC code.
--- drivers/ufs/host/ufs-amd-versal2.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-)
drivers/ufs/host/ufs-amd-versal2.c +8 -16
@@ -45,20 +45,15 @@ struct ufs_versal2_host {static int ufs_versal2_phy_reg_write (struct ufs_hba *hba,u32 addr,u32 val) { -static struct ufshcd_dme_attr_val phy_write_attrs[] = { - {UIC_ARG_MIB (CBCREGADDRLSB ),0 ,DME_LOCAL }, - {UIC_ARG_MIB (CBCREGADDRMSB ),0 ,DME_LOCAL }, - {UIC_ARG_MIB (CBCREGWRLSB ),0 ,DME_LOCAL }, - {UIC_ARG_MIB (CBCREGWRMSB ),0 ,DME_LOCAL }, +const struct ufshcd_dme_attr_val phy_write_attrs[] = { + {UIC_ARG_MIB (CBCREGADDRLSB ), (u8 )addr,DME_LOCAL }, + {UIC_ARG_MIB (CBCREGADDRMSB ), (u8)(addr >>8 ),DME_LOCAL }, + {UIC_ARG_MIB (CBCREGWRLSB ), (u8 )val,DME_LOCAL }, + {UIC_ARG_MIB (CBCREGWRMSB ), (u8)(val >>8 ),DME_LOCAL }, {UIC_ARG_MIB (CBCREGRDWRSEL ),1 ,DME_LOCAL }, {UIC_ARG_MIB (VS_MPHYCFGUPDT ),1 ,DME_LOCAL } }; - phy_write_attrs[0 ].mib_val = (u8 )addr; - phy_write_attrs[1 ].mib_val = (u8)(addr >>8 ); - phy_write_attrs[2 ].mib_val = (u8 )val; - phy_write_attrs[3 ].mib_val = (u8)(val >>8 ); -return ufshcd_dwc_dme_set_attrs (hba, phy_write_attrs,ARRAY_SIZE (phy_write_attrs)); }
@@ -66,16 +61,13 @@ static int ufs_versal2_phy_reg_read(struct ufs_hba *hba, u32 addr, u32 *val) {u32 mib_val;int ret; -static struct ufshcd_dme_attr_val phy_read_attrs[] = { - {UIC_ARG_MIB (CBCREGADDRLSB ),0 ,DME_LOCAL }, - {UIC_ARG_MIB (CBCREGADDRMSB ),0 ,DME_LOCAL }, +const struct ufshcd_dme_attr_val phy_read_attrs[] = { + {UIC_ARG_MIB (CBCREGADDRLSB ), (u8 )addr,DME_LOCAL }, + {UIC_ARG_MIB (CBCREGADDRMSB ), (u8)(addr >>8 ),DME_LOCAL }, {UIC_ARG_MIB (CBCREGRDWRSEL ),0 ,DME_LOCAL }, {UIC_ARG_MIB (VS_MPHYCFGUPDT ),1 ,DME_LOCAL } }; - phy_read_attrs[0 ].mib_val = (u8 )addr; - phy_read_attrs[1 ].mib_val = (u8)(addr >>8 ); - ret =ufshcd_dwc_dme_set_attrs (hba, phy_read_attrs,ARRAY_SIZE (phy_read_attrs));if (ret)return ret;
Signature · 1 line
2.17.1
PATCH v4 3/4 scsi: ufs: dwc: Rename amd-versal2 read/write PHY API and move to dwc common file
In reply to Minda ChenThe PHY register read/write helpers in the AMD Versal2 driver are generic to the Synopsys DesignWare UFS M-PHY. Move them to ufshcd-dwc.c and rename them so that other DWC based glue drivers can reuse them. Add kernel-doc for the exported helpers. No functional change.
--- drivers/ufs/host/ufs-amd-versal2.c | 77 +++++++----------------------- drivers/ufs/host/ufshcd-dwc.c | 61 +++++++++++++++++++++++ drivers/ufs/host/ufshcd-dwc.h | 2 + 3 files changed, 80 insertions(+), 60 deletions(-)
drivers/ufs/host/ufs-amd-versal2.c +17 -60
@@ -43,49 +43,6 @@ struct ufs_versal2_host {u8 ctlecompval1; }; -static int ufs_versal2_phy_reg_write (struct ufs_hba *hba,u32 addr,u32 val) -{ -const struct ufshcd_dme_attr_val phy_write_attrs[] = { - {UIC_ARG_MIB (CBCREGADDRLSB ), (u8 )addr,DME_LOCAL }, - {UIC_ARG_MIB (CBCREGADDRMSB ), (u8)(addr >>8 ),DME_LOCAL }, - {UIC_ARG_MIB (CBCREGWRLSB ), (u8 )val,DME_LOCAL }, - {UIC_ARG_MIB (CBCREGWRMSB ), (u8)(val >>8 ),DME_LOCAL }, - {UIC_ARG_MIB (CBCREGRDWRSEL ),1 ,DME_LOCAL }, - {UIC_ARG_MIB (VS_MPHYCFGUPDT ),1 ,DME_LOCAL } - }; - -return ufshcd_dwc_dme_set_attrs (hba, phy_write_attrs,ARRAY_SIZE (phy_write_attrs)); -} - -static int ufs_versal2_phy_reg_read (struct ufs_hba *hba,u32 addr,u32 *val) -{ -u32 mib_val; -int ret; -const struct ufshcd_dme_attr_val phy_read_attrs[] = { - {UIC_ARG_MIB (CBCREGADDRLSB ), (u8 )addr,DME_LOCAL }, - {UIC_ARG_MIB (CBCREGADDRMSB ), (u8)(addr >>8 ),DME_LOCAL }, - {UIC_ARG_MIB (CBCREGRDWRSEL ),0 ,DME_LOCAL }, - {UIC_ARG_MIB (VS_MPHYCFGUPDT ),1 ,DME_LOCAL } - }; - - ret =ufshcd_dwc_dme_set_attrs (hba, phy_read_attrs,ARRAY_SIZE (phy_read_attrs)); -if (ret) -return ret; - - ret =ufshcd_dme_get (hba,UIC_ARG_MIB (CBCREGRDLSB ), &mib_val); -if (ret) -return ret; - - *val = mib_val; - ret =ufshcd_dme_get (hba,UIC_ARG_MIB (CBCREGRDMSB ), &mib_val); -if (ret) -return ret; - - *val |= (mib_val <<8 ); - -return 0 ; -} -static int ufs_versal2_enable_phy (struct ufs_hba *hba) {u32 offset, reg;
@@ -154,64 +111,64 @@ static int ufs_versal2_setup_phy(struct ufs_hba *hba)u32 reg;/* Bypass RX-AFE offset calibrations (ATT/CTLE) */ - ret =ufs_versal2_phy_reg_read (hba,FAST_FLAGS (0 ), ®); + ret =ufshcd_dwc_phy_reg_read (hba,FAST_FLAGS (0 ), ®);if (ret)return ret; reg |=MPHY_FAST_RX_AFE_CAL ; - ret =ufs_versal2_phy_reg_write (hba,FAST_FLAGS (0 ), reg); + ret =ufshcd_dwc_phy_reg_write (hba,FAST_FLAGS (0 ), reg);if (ret)return ret; - ret =ufs_versal2_phy_reg_read (hba,FAST_FLAGS (1 ), ®); + ret =ufshcd_dwc_phy_reg_read (hba,FAST_FLAGS (1 ), ®);if (ret)return ret; reg |=MPHY_FAST_RX_AFE_CAL ; - ret =ufs_versal2_phy_reg_write (hba,FAST_FLAGS (1 ), reg); + ret =ufshcd_dwc_phy_reg_write (hba,FAST_FLAGS (1 ), reg);if (ret)return ret;/* Program ATT and CTLE compensation values */ if (host->attcompval0) { - ret =ufs_versal2_phy_reg_write (hba,RX_AFE_ATT_IDAC (0 ), host->attcompval0); + ret =ufshcd_dwc_phy_reg_write (hba,RX_AFE_ATT_IDAC (0 ), host->attcompval0);if (ret)return ret; }if (host->attcompval1) { - ret =ufs_versal2_phy_reg_write (hba,RX_AFE_ATT_IDAC (1 ), host->attcompval1); + ret =ufshcd_dwc_phy_reg_write (hba,RX_AFE_ATT_IDAC (1 ), host->attcompval1);if (ret)return ret; }if (host->ctlecompval0) { - ret =ufs_versal2_phy_reg_write (hba,RX_AFE_CTLE_IDAC (0 ), host->ctlecompval0); + ret =ufshcd_dwc_phy_reg_write (hba,RX_AFE_CTLE_IDAC (0 ), host->ctlecompval0);if (ret)return ret; }if (host->ctlecompval1) { - ret =ufs_versal2_phy_reg_write (hba,RX_AFE_CTLE_IDAC (1 ), host->ctlecompval1); + ret =ufshcd_dwc_phy_reg_write (hba,RX_AFE_CTLE_IDAC (1 ), host->ctlecompval1);if (ret)return ret; } - ret =ufs_versal2_phy_reg_read (hba,FW_CALIB_CCFG (0 ), ®); + ret =ufshcd_dwc_phy_reg_read (hba,FW_CALIB_CCFG (0 ), ®);if (ret)return ret; reg |=MPHY_FW_CALIB_CFG_VAL ; - ret =ufs_versal2_phy_reg_write (hba,FW_CALIB_CCFG (0 ), reg); + ret =ufshcd_dwc_phy_reg_write (hba,FW_CALIB_CCFG (0 ), reg);if (ret)return ret; - ret =ufs_versal2_phy_reg_read (hba,FW_CALIB_CCFG (1 ), ®); + ret =ufshcd_dwc_phy_reg_read (hba,FW_CALIB_CCFG (1 ), ®);if (ret)return ret; reg |=MPHY_FW_CALIB_CFG_VAL ; -return ufs_versal2_phy_reg_write (hba,FW_CALIB_CCFG (1 ), reg); +return ufshcd_dwc_phy_reg_write (hba,FW_CALIB_CCFG (1 ), reg); }static int ufs_versal2_phy_init (struct ufs_hba *hba)
@@ -376,7 +333,7 @@ static int ufs_versal2_phy_ratesel(struct ufs_hba *hba, u32 activelanes, u32 rx_for (lane =0 ; lane < activelanes; lane++) { time_left =TIMEOUT_MICROSEC ; - ret =ufs_versal2_phy_reg_read (hba,RX_OVRD_IN_1 (lane), ®); + ret =ufshcd_dwc_phy_reg_read (hba,RX_OVRD_IN_1 (lane), ®);if (ret)return ret;
@@ -386,12 +343,12 @@ static int ufs_versal2_phy_ratesel(struct ufs_hba *hba, u32 activelanes, u32 rx_else reg &= ~MPHY_RX_OVRD_VAL ; - ret =ufs_versal2_phy_reg_write (hba,RX_OVRD_IN_1 (lane), reg); + ret =ufshcd_dwc_phy_reg_write (hba,RX_OVRD_IN_1 (lane), reg);if (ret)return ret; do { - ret = ufs_versal2_phy_reg_read(hba, RX_PCS_OUT(lane), ®); + ret = ufshcd_dwc_phy_reg_read(hba, RX_PCS_OUT(lane), ®); if (ret) return ret;
@@ -453,12 +410,12 @@ static int ufs_versal2_pwr_change_notify(struct ufs_hba *hba, enum ufs_notify_ch/* Remove rx_req override */ for (lane =0 ; lane < dev_req_params->lane_tx; lane++) { - ret =ufs_versal2_phy_reg_read (hba,RX_OVRD_IN_1 (lane), ®); + ret =ufshcd_dwc_phy_reg_read (hba,RX_OVRD_IN_1 (lane), ®);if (ret)return ret; reg &= ~MPHY_RX_OVRD_EN ; - ret =ufs_versal2_phy_reg_write (hba,RX_OVRD_IN_1 (lane), reg); + ret =ufshcd_dwc_phy_reg_write (hba,RX_OVRD_IN_1 (lane), reg);if (ret)return ret; }
drivers/ufs/host/ufshcd-dwc.c +61 -0
67 lines not on this page · raw message
drivers/ufs/host/ufshcd-dwc.h +2 -0
@@ -68,4 +68,6 @@ int ufshcd_dwc_link_startup_notify(struct ufs_hba *hba, enum ufs_notify_change_status status);int ufshcd_dwc_dme_set_attrs (struct ufs_hba *hba,const struct ufshcd_dme_attr_val *v,int n); +int ufshcd_dwc_phy_reg_write (struct ufs_hba *hba,u32 addr,u32 val); +int ufshcd_dwc_phy_reg_read (struct ufs_hba *hba,u32 addr,u32 *val);#endif /* End of Header */
Signature · 1 line
2.17.1
PATCH v4 4/4 scsi: ufs: starfive: Add UFS support for StarFive JHB100 SoC
In reply to Minda ChenAdd support for the UFS host controller on JHB100 SoC, built on the Synopsys DWC UFS controller and using UFSHCD platform driver.
This controller requires specific configurations like M-PHY/RMMI/UniPro.
--- MAINTAINERS | 1 + drivers/ufs/host/Kconfig | 13 ++ drivers/ufs/host/Makefile | 1 + drivers/ufs/host/ufs-starfive.c | 283 ++++++++++++++++++++++++++++++++ drivers/ufs/host/ufshcd-dwc.h | 18 ++ 5 files changed, 316 insertions(+) create mode 100644 drivers/ufs/host/ufs-starfive.c
MAINTAINERS +1 -0
@@ -28805,6 +28805,7 @@ UNIVERSAL FLASH STORAGE HOST CONTROLLER DRIVER STARFIVE M: Minda Chen <[email protected]> S: Maintained F: Documentation/devicetree/bindings/ufs/starfive,jhb100-ufs.yaml +F: drivers/ufs/host/ufs-starfive.c UNIWILL LAPTOP DRIVER M: Armin Wolf <[email protected]>
drivers/ufs/host/Kconfig +13 -0
@@ -168,3 +168,16 @@ config SCSI_UFS_AMD_VERSAL2 Select this if you have UFS controller on AMD Versal Gen 2 SoC. If unsure, say N. + +config SCSI_UFS_STARFIVE + tristate "Starfive UFS controller platform driver" + depends on OF && SCSI_UFSHCD_PLATFORM + depends on ARCH_STARFIVE || COMPILE_TEST + help + This selects the StarFive specific additions to UFSHCD platform driver. + UFS host on StarFive needs some vendor specific configuration before + accessing the hardware which includes PHY configuration and vendor + specific registers. + + Select this if you have UFS controller on StarFive chipset. + If unsure, say N.
drivers/ufs/host/Makefile +1 -0
@@ -16,3 +16,4 @@ obj-$(CONFIG_SCSI_UFS_ROCKCHIP) += ufs-rockchip.o obj-$(CONFIG_SCSI_UFS_SPRD) += ufs-sprd.o obj-$(CONFIG_SCSI_UFS_TI_J721E) += ti-j721e-ufs.o obj-$(CONFIG_SCSI_UFS_AMD_VERSAL2) += ufs-amd-versal2.o ufshcd-dwc.o +obj-$(CONFIG_SCSI_UFS_STARFIVE) += ufs-starfive.o ufshcd-dwc.o
drivers/ufs/host/ufs-starfive.c new file +283 -0
283 lines not on this page · raw message
drivers/ufs/host/ufshcd-dwc.h +18 -0
@@ -12,7 +12,15 @@#include <ufs/ufshcd.h> +/* ufshcd vendor specific register */ +#define REG_BUSTHRTL 0xc0 +#define LP_AH8_POWER_GATING_EN BIT(17) +#define LP_POWER_GATING_EN BIT(16) +#define CLK_GATING_EN BIT(12) +/* RMMI Attributes */ +#define RXSQCONTROL 0x8009 +#define RXRHOLDCTRLOPT 0x8013#define CBREFCLKCTRL2 0x8132#define CBCRCTRL 0x811F#define CBC10DIRECTCONF2 0x810E
@@ -24,6 +32,8 @@#define CBCREGRDLSB 0x811A#define CBCREGRDMSB 0x811B#define CBCREGRDWRSEL 0x811C +#define EXT_COARSE_TUNE_RATEA 0x814D +#define EXT_COARSE_TUNE_RATEB 0x814E#define CBREFREFCLK_GATE_OVR_EN BIT(7)
@@ -32,12 +42,15 @@#define MRX_FSM_STATE 0xC1/* M-PHY registers */ +#define MPLL_SKIPCAL_COARSE_TUNE 0x28#define RX_OVRD_IN_1 (n) (0x3006 + ((n) * 0x100))#define RX_PCS_OUT (n) (0x300F + ((n) * 0x100))#define FAST_FLAGS (n) (0x401C + ((n) * 0x100)) +#define RX_ADAPT_DFE (n) (0x401E + ((n) * 0x100))#define RX_AFE_ATT_IDAC (n) (0x4000 + ((n) * 0x100))#define RX_AFE_CTLE_IDAC (n) (0x4001 + ((n) * 0x100))#define FW_CALIB_CCFG (n) (0x404D + ((n) * 0x100)) +#define RAWAONLANEN_DIG_MPLLA_COARSE_TUNE 0x7014/* Tx/Rx FSM state */ enum rx_fsm_state {
@@ -64,6 +77,11 @@ struct ufshcd_dme_attr_val {u8 peer; }; +struct ufs_dwc_phy_pair_data { +u32 addr; +u32 value; +}; +int ufshcd_dwc_link_startup_notify (struct ufs_hba *hba,enum ufs_notify_change_status status); int ufshcd_dwc_dme_set_attrs(struct ufs_hba *hba,
Signature · 1 line
2.17.1