From: Gary Yang <gary.yang@cixtech.com>
To: Manivannan Sadhasivam <mani@kernel.org>
Cc: Vinod Koul <vkoul@kernel.org>,
Neil Armstrong <neil.armstrong@linaro.org>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Fugang Duan <fugang.duan@cixtech.com>,
Luo Liu <Luo.Liu@cixtech.com>,
CIX Linux Kernel Upstream Group <cix-kernel-upstream@cixtech.com>,
linux-phy@lists.infradead.org, devicetree@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/2] phy: cix: add Sky1 USB/DP combo PHY driver
Date: Mon, 30 Nov 2026 11:18:11 +0800 [thread overview]
Message-ID: <awzq82-68VUooiRu@gary-System-Product-Name> (raw)
In-Reply-To: <179577770311.3421.6446368011498200273.b4-reply@b4>
hi Manivannan:
Thanks for your review. I'm glad to see your comments!
On 2026-11-27 16:38, Manivannan Sadhasivam wrote:
> EXTERNAL EMAIL
>
> On 2026-11-17 16:34 +0800, Gary Yang wrote:
> > Add a driver for the USB/DP combo PHY found on the CIX Sky1 SoC. A
> > single PHY instance drives one SuperSpeedPlus USB lane and up to four
> > DisplayPort lanes of a USB Type-C port, and exposes them as two PHYs
> > selected by PHY_TYPE_USB3 and PHY_TYPE_DP, so that the USB and DP
> > controllers can bind to them independently.
> >
> > The PHY supports Type-C plug orientation switching, which is driven
> > through the S5 system controller, and muxing of the PHY lanes between
> > USB and DP, which is programmed in the PHY registers. It registers a
> > Type-C switch and mux with the Type-C class, so the orientation and
> > mode decisions are taken by the connector driver instead of the PHY.
> >
> > The shared PHY is programmed once per mode combination: the driver
> > tracks the current and requested USB/DP mode as well as the plug
> > orientation, and reprograms the PHY on the next power-on only when the
> > mode combination or the orientation has changed.
> >
> > Reviewed-by: Fugang Duan <fugang.duan@cixtech.com>
> > Signed-off-by: Gary Yang <gary.yang@cixtech.com>
> > ---
> > MAINTAINERS | 4 +-
> > drivers/phy/cix/Kconfig | 16 +
> > drivers/phy/cix/Makefile | 1 +
> > drivers/phy/cix/phy-cix-usbdp.c | 1422 +++++++++++++++++++++++++++++++
> > drivers/phy/cix/phy-cix-usbdp.h | 257 ++++++
> > 5 files changed, 1699 insertions(+), 1 deletion(-)
> > create mode 100644 drivers/phy/cix/phy-cix-usbdp.c
> > create mode 100644 drivers/phy/cix/phy-cix-usbdp.h
>
> [...]
>
> > +static inline void udphy_write(struct cix_udphy *udphy, u32 reg, u32 val)
>
> No 'inline' keyword in .c files please. Compilers will decide when to inline a
> function. Same comment applies to other helpers.
>
> Besides, this function doesn't add any value. So drop it please.
>
Agree, we will drop it in next version
> > +{
> > + writel(val, udphy->base + reg * 4);
> > +}
> > +
> > +static inline void udphy_update_bits(struct cix_udphy *udphy, u32 reg,
> > + u32 mask, u32 val)
> > +{
> > + void __iomem *addr = udphy->base + reg * 4;
> > + u32 tmp;
> > +
> > + tmp = readl(addr);
> > + writel((tmp & ~mask) | (val & mask), addr);
> > +}
> > +
> > +static inline void udphy_write_table(struct cix_udphy *udphy,
> > + const struct reg_sequence *seq,
> > + unsigned int num)
> > +{
> > + unsigned int i;
> > +
> > + for (i = 0; i < num; i++)
> > + udphy_write(udphy, seq[i].reg, seq[i].def);
> > +}
> > +
> > +/* Link rate change */
> > +struct phy_link_cfg {
> > + const struct reg_sequence *seq;
> > + unsigned int num_seq;
> > + u32 hsclk_div;
> > + u32 clk_sel;
> > + u32 pll_intdiv;
> > + u32 pll_fracdivl;
> > + u32 pll_high_thr;
> > +};
> > +
> > +static const struct phy_link_cfg link_cfg[] = {
> > + { sky1_udphy_dp_partial_conf, ARRAY_SIZE(sky1_udphy_dp_partial_conf),
> > + 0x0002, 0x0f01, 0x0195, 0x0000, 0x010e }, /* 1.62 Gbps */
> > + { sky1_udphy_dp_partial_conf, ARRAY_SIZE(sky1_udphy_dp_partial_conf),
> > + 0x0001, 0x0701, 0x01c2, 0x0000, 0x012c }, /* 2.70 Gbps */
> > + { sky1_udphy_dp_partial_conf, ARRAY_SIZE(sky1_udphy_dp_partial_conf),
> > + 0x0000, 0x0301, 0x01c2, 0x0000, 0x012c }, /* 5.40 Gbps */
> > + { sky1_udphy_dp_8p1_conf, ARRAY_SIZE(sky1_udphy_dp_8p1_conf),
> > + 0x0000, 0x0200, 0x0151, 0x8000, 0x00e2 }, /* 8.10 Gbps */
> > +};
> > +
> > +struct phy_voltage_conf {
> > + u32 tx_txcc_ctrl;
> > + u32 drv_diag_tx_drv;
> > + u32 tx_txcc_mgnfc_mult_000;
> > + u32 tx_txcc_cpost_mult_00;
> > +};
> > +
> > +static const struct phy_voltage_conf volt_cfg[] = {
> > + { 0x08a4, 0x0003, 0x0028, 0x0000 }, /* swing level == 0 */
> > + { 0x08a4, 0x0003, 0x001f, 0x0014 },
> > + { 0x08a4, 0x0003, 0x0012, 0x0020 },
> > + { 0x08a4, 0x0003, 0x0000, 0x0027 },
> > + { 0x08a4, 0x0003, 0x001f, 0x0000 }, /* swing level == 1 */
> > + { 0x08a4, 0x0003, 0x0013, 0x0012 },
> > + { 0x08a4, 0x0003, 0x0000, 0x001f },
> > + { 0x08a4, 0x0003, 0x0000, 0x001f },
> > + { 0x08a4, 0x0003, 0x0013, 0x0000 }, /* swing level == 2 */
> > + { 0x08a4, 0x0003, 0x0000, 0x0013 },
> > + { 0x08a4, 0x0003, 0x0000, 0x0013 },
> > + { 0x08a4, 0x0003, 0x0000, 0x0013 },
> > + { 0x08a4, 0x0003, 0x0000, 0x0000 }, /* swing level == 3 */
> > + { 0x08a4, 0x0003, 0x0000, 0x0000 },
> > + { 0x08a4, 0x0003, 0x0000, 0x0000 },
> > + { 0x08a4, 0x0003, 0x0000, 0x0000 },
> > +};
> > +
> > +static int udphy_dplane_get(struct cix_udphy *udphy)
> > +{
> > + int dp_lanes;
> > +
> > + switch (udphy->next_mode) {
> > + case UDPHY_MODE_DP:
> > + dp_lanes = 4;
> > + break;
> > + case UDPHY_MODE_DP_USB:
> > + dp_lanes = 2;
> > + break;
> > + case UDPHY_MODE_USB:
> > + fallthrough;
> > + default:
> > + dp_lanes = 0;
> > + break;
> > + }
> > +
> > + return dp_lanes;
> > +}
> > +
> > +static int sky1_udphy_clk_enable(struct clk *clk)
> > +{
> > + int i, ret = -EBUSY;
>
> Why can't you return the actual error from clk_prepare_enable()?
>
Sorry for the confusion. That is just a default; it is later overwritten
by the return value of clk_prepare_enable(), so the value actually returned
is clk_prepare_enable()'s. I will drop the default in the next version to
make this clearer.
> > +
> > + /*
> > + * If the clock could not enable 10 iterations,
> > + * it considers this clock is broken.
>
> Make use of full 80 columns for comments.
>
OK, we will fix it in next version
> > + */
> > + for (i = 0; i < 10; i++) {
> > + ret = clk_prepare_enable(clk);
> > + if (!ret)
> > + return 0;
> > +
> > + usleep_range(5000, 6000);
> > + }
> > +
> > + return ret;
> > +}
> > +
> > +static int sky1_udphy_exit(struct cix_udphy *udphy)
> > +{
> > + reset_control_assert(udphy->reset);
> > + reset_control_assert(udphy->preset);
> > + clk_disable_unprepare(udphy->apb_clk);
> > + return 0;
> > +}
> > +
> > +static void sky1_udphy_set_orientation(struct cix_udphy *udphy)
> > +{
> > + const struct cix_udphy_con_dir *con_dir =
> > + &udphy->cfg->con_dir[udphy->id];
> > +
> > + regmap_update_bits(udphy->usbphy_syscon, con_dir->offset,
> > + GENMASK(con_dir->bit, con_dir->bit),
> > + (u32)udphy->flip << con_dir->bit);
> > +
> > + usleep_range(10, 20);
> > +}
> > +
> > +static void sky1_udphy_write_mode_table(struct cix_udphy *udphy)
> > +{
> > + if (udphy->next_mode == UDPHY_MODE_DP) {
> > + udphy_write_table(udphy, sky1_udphy_dp_conf,
> > + ARRAY_SIZE(sky1_udphy_dp_conf));
> > + } else if (!udphy->flip) {
> > + udphy_write_table(udphy, sky1_udphy_usbdp_conf_normal,
> > + ARRAY_SIZE(sky1_udphy_usbdp_conf_normal));
> > + } else {
> > + udphy_write_table(udphy, sky1_udphy_usbdp_conf_flip,
> > + ARRAY_SIZE(sky1_udphy_usbdp_conf_flip));
> > + }
> > +}
> > +
> > +/* Reprogram the PHY after the mode or the plug orientation has changed. */
> > +static int sky1_udphy_reinit(struct cix_udphy *udphy)
> > +{
> > + sky1_udphy_set_orientation(udphy);
> > +
> > + /*
> > + * The APB clock is still enabled, so the block can be reset without
> > + * running the full power-on sequence again.
> > + */
> > + reset_control_assert(udphy->reset);
> > + reset_control_assert(udphy->preset);
> > + reset_control_deassert(udphy->preset);
> > +
> > + sky1_udphy_write_mode_table(udphy);
> > +
> > + reset_control_deassert(udphy->reset);
> > +
> > + return 0;
> > +}
> > +
> > +static int sky1_udphy_init(struct cix_udphy *udphy)
> > +{
> > + int ret;
> > +
> > + sky1_udphy_set_orientation(udphy);
> > +
> > + /* usb rcsu reset is default deassert */
> > + reset_control_assert(udphy->reset);
> > + reset_control_assert(udphy->preset);
> > +
> > + ret = sky1_udphy_clk_enable(udphy->apb_clk);
> > + if (ret) {
> > + dev_err(udphy->dev, "failed to enable APB clock\n");
> > + return ret;
> > + }
> > +
> > + reset_control_deassert(udphy->preset);
> > +
> > + sky1_udphy_write_mode_table(udphy);
> > +
> > + reset_control_deassert(udphy->reset);
> > +
> > + return 0;
> > +}
> > +
> > +static const struct cix_udphy_cfg sky1_udphy_cfg = {
> > + .con_dir = sky1_udphy_con_dir,
> > + .udphy_init = sky1_udphy_init,
> > + .udphy_reinit = sky1_udphy_reinit,
> > + .udphy_exit = sky1_udphy_exit
> > +};
>
> Do you really need per-device callbacks? Do you really forsee different devices
> using different callbacks in the future? If not, I'd suggest to drop it.
>
Yes, this is an interface reserved for future combo PHYs, since different
PHYs have different implementations of the PHY init() and exit() callbacks.
I hope that makes sense. Thanks.
> > +
> > +static int udphy_orien_sw_set(struct typec_switch_dev *sw,
> > + enum typec_orientation orien)
> > +{
> > + struct cix_udphy *udphy = typec_switch_get_drvdata(sw);
> > + bool flip;
> > +
> > + guard(mutex)(&udphy->mutex);
> > +
> > + if (orien == TYPEC_ORIENTATION_NONE)
> > + return 0;
> > +
> > + flip = (orien == TYPEC_ORIENTATION_REVERSE);
> > + if (udphy->flip != flip) {
> > + dev_dbg(udphy->dev, "plug orientation changed, re-init required\n");
> > + udphy->needs_reinit = true;
> > + }
> > +
> > + udphy->flip = flip;
> > +
> > + return 0;
> > +}
>
> [...]
>
> > +static int cix_udphy_probe(struct platform_device *pdev)
> > +{
> > + struct device *dev = &pdev->dev;
> > + struct device_node *np = dev->of_node;
> > + struct phy_provider *phy_provider;
> > + struct cix_udphy *udphy;
> > + u32 id;
> > + int ret;
> > +
> > + udphy = devm_kzalloc(dev, sizeof(*udphy), GFP_KERNEL);
> > + if (!udphy)
> > + return -ENOMEM;
> > +
> > + dev_set_drvdata(dev, udphy);
> > + udphy->dev = dev;
> > + udphy_set_default_mode(udphy);
> > +
> > + udphy->usbphy_syscon =
> > + syscon_regmap_lookup_by_phandle_args(np, "cix,usbphy-syscon", 1,
> > + &id);
> > + if (IS_ERR(udphy->usbphy_syscon))
> > + return dev_err_probe(dev, PTR_ERR(udphy->usbphy_syscon),
> > + "failed to get usbphy syscon\n");
> > +
> > + if (id >= ARRAY_SIZE(sky1_udphy_con_dir))
> > + return dev_err_probe(dev, -EINVAL,
> > + "invalid usbphy syscon id\n");
> > +
> > + udphy->id = id;
> > +
> > + udphy->cfg = device_get_match_data(dev);
> > + if (!udphy->cfg)
> > + return dev_err_probe(dev, -EINVAL,
> > + "failed to get match data\n");
> > +
> > + udphy->reset = devm_reset_control_get_exclusive(dev, "core");
> > + if (IS_ERR(udphy->reset))
> > + return dev_err_probe(dev, PTR_ERR(udphy->reset),
> > + "failed to get reset\n");
> > +
> > + udphy->preset = devm_reset_control_get_exclusive(dev, "apb");
> > + if (IS_ERR(udphy->preset))
> > + return dev_err_probe(dev, PTR_ERR(udphy->preset),
> > + "failed to get preset\n");
> > +
> > + reset_control_assert(udphy->reset);
> > + reset_control_assert(udphy->preset);
> > +
> > + udphy->apb_clk = devm_clk_get(dev, NULL);
> > + if (IS_ERR(udphy->apb_clk))
> > + return dev_err_probe(dev, PTR_ERR(udphy->apb_clk),
> > + "failed to get APB clock\n");
> > +
> > + udphy->base = devm_platform_ioremap_resource(pdev, 0);
> > + if (IS_ERR(udphy->base))
> > + return dev_err_probe(dev, PTR_ERR(udphy->base),
> > + "failed to remap registers\n");
> > +
> > + mutex_init(&udphy->mutex);
>
> devm_mutex_init()?
>
Good idea. we will fix it as your suggestions.
If I miss any your comments, please kindly remind me. Thanks
Best Regards
Gary
> - Mani
>
>
>
next prev parent reply other threads:[~2026-11-30 3:18 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-02 8:21 [PATCH 0/3] phy: cix: add Sky1 USB/DP combo PHY Gary Yang
2026-11-02 8:21 ` [PATCH 1/3] dt-bindings: phy: add CIX " Gary Yang
2026-11-02 8:21 ` [PATCH 2/3] phy: cix: add Sky1 USB/DP combo PHY driver Gary Yang
2026-11-15 20:35 ` Manivannan Sadhasivam
2026-11-02 8:21 ` [PATCH 3/3] arm64: dts: cix: add Sky1 USB/DP combo PHY Gary Yang
2026-11-17 8:34 ` [PATCH v2 0/2] phy: cix: add Sky1 USB/DP combo PHY support Gary Yang
2026-11-17 8:34 ` [PATCH v2 1/2] dt-bindings: phy: add CIX Sky1 USB/DP combo PHY Gary Yang
2026-11-17 8:34 ` [PATCH v2 2/2] phy: cix: add Sky1 USB/DP combo PHY driver Gary Yang
2026-11-27 11:08 ` Manivannan Sadhasivam
2026-11-30 3:18 ` Gary Yang [this message]
2026-11-27 10:55 ` [PATCH v2 0/2] phy: cix: add Sky1 USB/DP combo PHY support Manivannan Sadhasivam
2026-11-27 11:06 ` Gary Yang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=awzq82-68VUooiRu@gary-System-Product-Name \
--to=gary.yang@cixtech.com \
--cc=Luo.Liu@cixtech.com \
--cc=cix-kernel-upstream@cixtech.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=fugang.duan@cixtech.com \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-phy@lists.infradead.org \
--cc=mani@kernel.org \
--cc=neil.armstrong@linaro.org \
--cc=robh@kernel.org \
--cc=vkoul@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®