[PATCH v2 2/2] phy: cix: add Sky1 USB/DP combo PHY driver

Gary Yang gary.yang at cixtech.com
Sun Nov 29 19:18:11 PST 2026


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 at cixtech.com>
> > Signed-off-by: Gary Yang <gary.yang at 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
> 
> 
> 



More information about the linux-arm-kernel mailing list