From: luyulin <luyulin@eswincomputing.com>
Created the eswin phy driver directory and added support for
the SATA phy driver on the EIC7700 SoC platform.
Signed-off-by: luyulin <luyulin@eswincomputing.com>
---
drivers/phy/Kconfig | 1 +
drivers/phy/Makefile | 1 +
drivers/phy/eswin/Kconfig | 14 ++
drivers/phy/eswin/Makefile | 2 +
drivers/phy/eswin/phy-eic7700-sata.c | 197 +++++++++++++++++++++++++++
5 files changed, 215 insertions(+)
create mode 100644 drivers/phy/eswin/Kconfig
create mode 100644 drivers/phy/eswin/Makefile
create mode 100644 drivers/phy/eswin/phy-eic7700-sata.c
diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index 58c911e1b2d2..e82ebcfe534a 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -105,6 +105,7 @@ source "drivers/phy/allwinner/Kconfig"
source "drivers/phy/amlogic/Kconfig"
source "drivers/phy/broadcom/Kconfig"
source "drivers/phy/cadence/Kconfig"
+source "drivers/phy/eswin/Kconfig"
source "drivers/phy/freescale/Kconfig"
source "drivers/phy/hisilicon/Kconfig"
source "drivers/phy/ingenic/Kconfig"
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index c670a8dac468..ed7444949259 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -17,6 +17,7 @@ obj-y += allwinner/ \
amlogic/ \
broadcom/ \
cadence/ \
+ eswin/ \
freescale/ \
hisilicon/ \
ingenic/ \
diff --git a/drivers/phy/eswin/Kconfig b/drivers/phy/eswin/Kconfig
new file mode 100644
index 000000000000..3fcd76582c3b
--- /dev/null
+++ b/drivers/phy/eswin/Kconfig
@@ -0,0 +1,14 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# Phy drivers for Eswin platforms
+#
+config PHY_EIC7700_SATA
+ tristate "eic7700 Sata SerDes/PHY driver"
+ depends on ARCH_ESWIN || COMPILE_TEST
+ depends on HAS_IOMEM
+ select GENERIC_PHY
+ help
+ Enable this to support SerDes/Phy found on ESWIN's
+ EIC7700 SoC.This Phy supports SATA 1.5 Gb/s,
+ SATA 3.0 Gb/s, SATA 6.0 Gb/s speeds.
+ It supports one SATA host port to accept one SATA device.
diff --git a/drivers/phy/eswin/Makefile b/drivers/phy/eswin/Makefile
new file mode 100644
index 000000000000..db08c66be812
--- /dev/null
+++ b/drivers/phy/eswin/Makefile
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0
+obj-$(CONFIG_PHY_EIC7700_SATA) += phy-eic7700-sata.o
diff --git a/drivers/phy/eswin/phy-eic7700-sata.c b/drivers/phy/eswin/phy-eic7700-sata.c
new file mode 100644
index 000000000000..8a757839e868
--- /dev/null
+++ b/drivers/phy/eswin/phy-eic7700-sata.c
@@ -0,0 +1,197 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * ESWIN SATA PHY driver
+ *
+ * Copyright 2024, Beijing ESWIN Computing Technology Co., Ltd..
+ * All rights reserved.
+ *
+ * Authors: Yulin Lu <luyulin@eswincomputing.com>
+ */
+
+#include <linux/delay.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/phy/phy.h>
+#include <linux/platform_device.h>
+
+#define SATA_CLK_CTRL 0x0
+#define SATA_AXI_LP_CTRL 0x08
+#define SATA_MPLL_CTRL 0x20
+#define SATA_PHY_CTRL0 0x28
+#define SATA_PHY_CTRL1 0x2c
+#define SATA_REF_CTRL1 0x38
+#define SATA_REG_CTRL 0x34
+#define SATA_LOS_IDEN 0x3c
+#define SATA_RESET_CTRL 0x40
+#define SATA_CLK_RST_SOURCE_PHY BIT(0)
+#define SATA_SYS_CLK_EN BIT(28)
+#define SATA_PHY_RESET BIT(0)
+#define SATA_PORT_RESET BIT(1)
+#define SATA_LOS_LEVEL 0x9
+#define SATA_LOS_BIAS (0x02 << 16)
+#define SATA_REF_REPEATCLK_EN BIT(0)
+#define SATA_REF_USE_PAD BIT(20)
+#define SATA_P0_AMPLITUDE_GEN1 0x42
+#define SATA_P0_AMPLITUDE_GEN2 (0x46 << 8)
+#define SATA_P0_AMPLITUDE_GEN3 (0x73 << 16)
+#define SATA_P0_PHY_TX_PREEMPH_GEN1 0x05
+#define SATA_P0_PHY_TX_PREEMPH_GEN2 (0x05 << 8)
+#define SATA_P0_PHY_TX_PREEMPH_GEN3 (0x08 << 16)
+#define SATA_MPLL_MULTIPLIER (0x3c << 16)
+#define SATA_M_CSYSREQ BIT(0)
+#define SATA_S_CSYSREQ BIT(16)
+#define SATA_P0_PHY_STAT 0x24
+#define SATA_P0_PHY_READY BIT(0)
+
+#define PHY_READY_TIMEOUT (usecs_to_jiffies(4000))
+
+struct eic7700_sata_phy {
+ struct phy *phy;
+ void __iomem *regs;
+};
+
+static int wait_for_phy_ready(void __iomem *base, u32 reg, u32 checkbit,
+ u32 status)
+{
+ unsigned long start = jiffies;
+ unsigned long timeout = start + PHY_READY_TIMEOUT;
+
+ while (time_before(start, timeout)) {
+ if ((readl(base + reg) & checkbit) == status)
+ return 0;
+ usleep_range(50, 70);
+ }
+
+ return -EFAULT;
+}
+
+static int eic7700_sata_phy_init(struct phy *phy)
+{
+ struct eic7700_sata_phy *sata_phy = phy_get_drvdata(phy);
+ u32 val = 0;
+ int ret = 0;
+
+ /*
+ * The SATA_CLK_CTRL register offset controls the pmalive, rxoob,
+ * and rbc clocks gate provided by the PHY through the HSP bus,
+ * and it is not registered in the clock tree.
+ */
+ val = readl(sata_phy->regs + SATA_CLK_CTRL);
+ val |= SATA_SYS_CLK_EN;
+ writel(val, sata_phy->regs + SATA_CLK_CTRL);
+
+ writel(SATA_CLK_RST_SOURCE_PHY, sata_phy->regs + SATA_REF_CTRL1);
+ writel(SATA_P0_AMPLITUDE_GEN1 | SATA_P0_AMPLITUDE_GEN2 |
+ SATA_P0_AMPLITUDE_GEN3, sata_phy->regs + SATA_PHY_CTRL0);
+ writel(SATA_P0_PHY_TX_PREEMPH_GEN1 | SATA_P0_PHY_TX_PREEMPH_GEN2 |
+ SATA_P0_PHY_TX_PREEMPH_GEN3, sata_phy->regs + SATA_PHY_CTRL1);
+ writel(SATA_LOS_LEVEL | SATA_LOS_BIAS,
+ sata_phy->regs + SATA_LOS_IDEN);
+ writel(SATA_M_CSYSREQ | SATA_S_CSYSREQ,
+ sata_phy->regs + SATA_AXI_LP_CTRL);
+ writel(SATA_REF_REPEATCLK_EN | SATA_REF_USE_PAD,
+ sata_phy->regs + SATA_REG_CTRL);
+ writel(SATA_MPLL_MULTIPLIER, sata_phy->regs + SATA_MPLL_CTRL);
+ usleep_range(15, 20);
+
+ /*
+ * The SATA_RESET_CTRL register offset controls reset/deassert
+ * for both the port and the PHY through the HSP bus,
+ * and it is not registered in the reset tree.
+ */
+ val = readl(sata_phy->regs + SATA_RESET_CTRL);
+ val &= ~(SATA_PHY_RESET | SATA_PORT_RESET);
+ writel(val, sata_phy->regs + SATA_RESET_CTRL);
+
+ ret = wait_for_phy_ready(sata_phy->regs, SATA_P0_PHY_STAT,
+ SATA_P0_PHY_READY, 1);
+ if (ret < 0)
+ dev_err(&sata_phy->phy->dev,
+ "PHY READY check failed\n");
+ return ret;
+}
+
+static int eic7700_sata_phy_exit(struct phy *phy)
+{
+ struct eic7700_sata_phy *sata_phy = phy_get_drvdata(phy);
+ u32 val = 0;
+
+ val = readl(sata_phy->regs + SATA_RESET_CTRL);
+ val |= SATA_PHY_RESET | SATA_PORT_RESET;
+ writel(val, sata_phy->regs + SATA_RESET_CTRL);
+
+ val = readl(sata_phy->regs + SATA_CLK_CTRL);
+ val &= ~SATA_SYS_CLK_EN;
+ writel(val, sata_phy->regs + SATA_CLK_CTRL);
+
+ return 0;
+}
+
+static const struct phy_ops eic7700_sata_phy_ops = {
+ .init = eic7700_sata_phy_init,
+ .exit = eic7700_sata_phy_exit,
+ .owner = THIS_MODULE,
+};
+
+static int eic7700_sata_phy_probe(struct platform_device *pdev)
+{
+ struct eic7700_sata_phy *sata_phy;
+ struct device *dev = &pdev->dev;
+ struct phy_provider *phy_provider;
+ u32 val = 0;
+ int ret = 0;
+
+ sata_phy = devm_kzalloc(dev, sizeof(*sata_phy), GFP_KERNEL);
+ if (!sata_phy)
+ return -ENOMEM;
+
+ sata_phy->regs = devm_platform_ioremap_resource(pdev, 0);
+ if (IS_ERR(sata_phy->regs))
+ return PTR_ERR(sata_phy->regs);
+
+ dev_set_drvdata(dev, sata_phy);
+
+ sata_phy->phy = devm_phy_create(dev, NULL, &eic7700_sata_phy_ops);
+ if (IS_ERR(sata_phy->phy)) {
+ dev_err(dev, "failed to create PHY\n");
+ ret = PTR_ERR(sata_phy->phy);
+ goto clk_disable;
+ }
+
+ phy_set_drvdata(sata_phy->phy, sata_phy);
+
+ phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
+ if (IS_ERR(phy_provider)) {
+ ret = PTR_ERR(phy_provider);
+ goto clk_disable;
+ }
+
+ return 0;
+
+clk_disable:
+ val = readl(sata_phy->regs + SATA_CLK_CTRL);
+ val &= ~SATA_SYS_CLK_EN;
+ writel(val, sata_phy->regs + SATA_CLK_CTRL);
+
+ return ret;
+}
+
+static const struct of_device_id eic7700_sata_phy_of_match[] = {
+ { .compatible = "eswin,eic7700-sata-phy" },
+ { },
+};
+MODULE_DEVICE_TABLE(of, eic7700_sata_phy_of_match);
+
+static struct platform_driver eic7700_sata_phy_driver = {
+ .probe = eic7700_sata_phy_probe,
+ .driver = {
+ .of_match_table = eic7700_sata_phy_of_match,
+ .name = "eswin,sata-phy",
+ .suppress_bind_attrs = true,
+ }
+};
+module_platform_driver(eic7700_sata_phy_driver);
+
+MODULE_DESCRIPTION("SATA PHY driver for the ESWIN EIC7700 SoC");
+MODULE_AUTHOR("Yulin Lu <luyulin@eswincomputing.com>");
+MODULE_LICENSE("GPL");
--
2.25.1
Hi Yulin, kernel test robot noticed the following build errors: [auto build test ERROR on robh/for-next] [also build test ERROR on linus/master v6.17-rc2 next-20250820] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Yulin-Lu/dt-bindings-ata-eswin-Document-for-EIC7700-SoC-ahci/20250820-213411 base: https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next patch link: https://lore.kernel.org/r/20250819140043.1862-1-luyulin%40eswincomputing.com patch subject: [PATCH v2 3/3] phy: eswin: Create eswin directory and add EIC7700 SATA PHY driver config: s390-allmodconfig (https://download.01.org/0day-ci/archive/20250821/202508211623.d8Spdqn7-lkp@intel.com/config) compiler: clang version 18.1.8 (https://github.com/llvm/llvm-project 3b5b5c1ec4a3095ab096dd780e84d7ab81f3d7ff) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250821/202508211623.d8Spdqn7-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202508211623.d8Spdqn7-lkp@intel.com/ All errors (new ones prefixed by >>): >> drivers/phy/eswin/phy-eic7700-sata.c:60:8: error: call to undeclared function 'readl'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] 60 | if ((readl(base + reg) & checkbit) == status) | ^ drivers/phy/eswin/phy-eic7700-sata.c:79:8: error: call to undeclared function 'readl'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] 79 | val = readl(sata_phy->regs + SATA_CLK_CTRL); | ^ >> drivers/phy/eswin/phy-eic7700-sata.c:81:2: error: call to undeclared function 'writel'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] 81 | writel(val, sata_phy->regs + SATA_CLK_CTRL); | ^ drivers/phy/eswin/phy-eic7700-sata.c:119:8: error: call to undeclared function 'readl'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] 119 | val = readl(sata_phy->regs + SATA_RESET_CTRL); | ^ drivers/phy/eswin/phy-eic7700-sata.c:121:2: error: call to undeclared function 'writel'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] 121 | writel(val, sata_phy->regs + SATA_RESET_CTRL); | ^ drivers/phy/eswin/phy-eic7700-sata.c:172:8: error: call to undeclared function 'readl'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] 172 | val = readl(sata_phy->regs + SATA_CLK_CTRL); | ^ drivers/phy/eswin/phy-eic7700-sata.c:174:2: error: call to undeclared function 'writel'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] 174 | writel(val, sata_phy->regs + SATA_CLK_CTRL); | ^ 7 errors generated. vim +/readl +60 drivers/phy/eswin/phy-eic7700-sata.c 52 53 static int wait_for_phy_ready(void __iomem *base, u32 reg, u32 checkbit, 54 u32 status) 55 { 56 unsigned long start = jiffies; 57 unsigned long timeout = start + PHY_READY_TIMEOUT; 58 59 while (time_before(start, timeout)) { > 60 if ((readl(base + reg) & checkbit) == status) 61 return 0; 62 usleep_range(50, 70); 63 } 64 65 return -EFAULT; 66 } 67 68 static int eic7700_sata_phy_init(struct phy *phy) 69 { 70 struct eic7700_sata_phy *sata_phy = phy_get_drvdata(phy); 71 u32 val = 0; 72 int ret = 0; 73 74 /* 75 * The SATA_CLK_CTRL register offset controls the pmalive, rxoob, 76 * and rbc clocks gate provided by the PHY through the HSP bus, 77 * and it is not registered in the clock tree. 78 */ 79 val = readl(sata_phy->regs + SATA_CLK_CTRL); 80 val |= SATA_SYS_CLK_EN; > 81 writel(val, sata_phy->regs + SATA_CLK_CTRL); 82 83 writel(SATA_CLK_RST_SOURCE_PHY, sata_phy->regs + SATA_REF_CTRL1); 84 writel(SATA_P0_AMPLITUDE_GEN1 | SATA_P0_AMPLITUDE_GEN2 | 85 SATA_P0_AMPLITUDE_GEN3, sata_phy->regs + SATA_PHY_CTRL0); 86 writel(SATA_P0_PHY_TX_PREEMPH_GEN1 | SATA_P0_PHY_TX_PREEMPH_GEN2 | 87 SATA_P0_PHY_TX_PREEMPH_GEN3, sata_phy->regs + SATA_PHY_CTRL1); 88 writel(SATA_LOS_LEVEL | SATA_LOS_BIAS, 89 sata_phy->regs + SATA_LOS_IDEN); 90 writel(SATA_M_CSYSREQ | SATA_S_CSYSREQ, 91 sata_phy->regs + SATA_AXI_LP_CTRL); 92 writel(SATA_REF_REPEATCLK_EN | SATA_REF_USE_PAD, 93 sata_phy->regs + SATA_REG_CTRL); 94 writel(SATA_MPLL_MULTIPLIER, sata_phy->regs + SATA_MPLL_CTRL); 95 usleep_range(15, 20); 96 97 /* 98 * The SATA_RESET_CTRL register offset controls reset/deassert 99 * for both the port and the PHY through the HSP bus, 100 * and it is not registered in the reset tree. 101 */ 102 val = readl(sata_phy->regs + SATA_RESET_CTRL); 103 val &= ~(SATA_PHY_RESET | SATA_PORT_RESET); 104 writel(val, sata_phy->regs + SATA_RESET_CTRL); 105 106 ret = wait_for_phy_ready(sata_phy->regs, SATA_P0_PHY_STAT, 107 SATA_P0_PHY_READY, 1); 108 if (ret < 0) 109 dev_err(&sata_phy->phy->dev, 110 "PHY READY check failed\n"); 111 return ret; 112 } 113 -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
On 19-08-25, 22:00, Yulin Lu wrote: > From: luyulin <luyulin@eswincomputing.com> > > Created the eswin phy driver directory and added support for > the SATA phy driver on the EIC7700 SoC platform. > > Signed-off-by: luyulin <luyulin@eswincomputing.com> Please use full name as you have used in the copyright notices > +#define SATA_P0_PHY_TX_PREEMPH_GEN2 (0x05 << 8) > +#define SATA_P0_PHY_TX_PREEMPH_GEN3 (0x08 << 16) > +#define SATA_MPLL_MULTIPLIER (0x3c << 16) Use GENMASK for these > +static int eic7700_sata_phy_init(struct phy *phy) > +{ > + struct eic7700_sata_phy *sata_phy = phy_get_drvdata(phy); > + u32 val = 0; > + int ret = 0; both initializations are superfluous > +static int eic7700_sata_phy_exit(struct phy *phy) > +{ > + struct eic7700_sata_phy *sata_phy = phy_get_drvdata(phy); > + u32 val = 0; here and other places > +static struct platform_driver eic7700_sata_phy_driver = { > + .probe = eic7700_sata_phy_probe, > + .driver = { > + .of_match_table = eic7700_sata_phy_of_match, > + .name = "eswin,sata-phy", > + .suppress_bind_attrs = true, why? -- ~Vinod
© 2016 - 2025 Red Hat, Inc.