Lines Matching refs:mxs_phy
22 #define DRIVER_NAME "mxs_phy"
120 #define to_mxs_phy(p) container_of((p), struct mxs_phy, phy)
199 struct mxs_phy {
209 static inline bool is_imx6q_phy(struct mxs_phy *mxs_phy)
211 return mxs_phy->data == &imx6q_phy_data;
214 static inline bool is_imx6sl_phy(struct mxs_phy *mxs_phy)
216 return mxs_phy->data == &imx6sl_phy_data;
219 static inline bool is_imx7ulp_phy(struct mxs_phy *mxs_phy)
221 return mxs_phy->data == &imx7ulp_phy_data;
233 static void mxs_phy_tx_init(struct mxs_phy *mxs_phy)
235 void __iomem *base = mxs_phy->phy.io_priv;
239 if (mxs_phy->tx_reg_mask) {
241 phytx &= ~mxs_phy->tx_reg_mask;
242 phytx |= mxs_phy->tx_reg_set;
276 static int mxs_phy_hw_init(struct mxs_phy *mxs_phy)
279 void __iomem *base = mxs_phy->phy.io_priv;
281 if (is_imx7ulp_phy(mxs_phy)) {
308 if (mxs_phy->data->flags & MXS_PHY_NEED_IP_FIX)
311 if (mxs_phy->regmap_anatop) {
312 unsigned int reg = mxs_phy->port_id ?
319 regmap_write(mxs_phy->regmap_anatop, reg,
324 mxs_phy_tx_init(mxs_phy);
329 if (is_imx7ulp_phy(mxs_phy))
335 static bool mxs_phy_get_vbus_status(struct mxs_phy *mxs_phy)
339 if (!mxs_phy->regmap_anatop)
342 if (mxs_phy->port_id == 0)
343 regmap_read(mxs_phy->regmap_anatop,
346 else if (mxs_phy->port_id == 1)
347 regmap_read(mxs_phy->regmap_anatop,
357 static void __mxs_phy_disconnect_line(struct mxs_phy *mxs_phy, bool disconnect)
359 void __iomem *base = mxs_phy->phy.io_priv;
366 if (mxs_phy->port_id == 0) {
369 regmap_write(mxs_phy->regmap_anatop, reg,
372 } else if (mxs_phy->port_id == 1) {
375 regmap_write(mxs_phy->regmap_anatop, reg,
389 static bool mxs_phy_is_otg_host(struct mxs_phy *mxs_phy)
391 return mxs_phy->phy.last_event == USB_EVENT_ID;
394 static void mxs_phy_disconnect_line(struct mxs_phy *mxs_phy, bool on)
399 if (!(mxs_phy->data->flags & MXS_PHY_DISCONNECT_LINE_WITHOUT_VBUS))
403 if (!mxs_phy->regmap_anatop)
406 vbus_is_on = mxs_phy_get_vbus_status(mxs_phy);
408 if (on && !vbus_is_on && !mxs_phy_is_otg_host(mxs_phy))
409 __mxs_phy_disconnect_line(mxs_phy, true);
411 __mxs_phy_disconnect_line(mxs_phy, false);
418 struct mxs_phy *mxs_phy = to_mxs_phy(phy);
421 ret = clk_prepare_enable(mxs_phy->clk);
425 return mxs_phy_hw_init(mxs_phy);
430 struct mxs_phy *mxs_phy = to_mxs_phy(phy);
446 if (is_imx7ulp_phy(mxs_phy))
449 clk_disable_unprepare(mxs_phy->clk);
452 static bool mxs_phy_is_low_speed_connection(struct mxs_phy *mxs_phy)
461 if (!mxs_phy->regmap_anatop)
464 if (mxs_phy->port_id == 0)
466 else if (mxs_phy->port_id == 1)
469 regmap_read(mxs_phy->regmap_anatop, reg, &line_state);
480 struct mxs_phy *mxs_phy = to_mxs_phy(x);
483 low_speed_connection = mxs_phy_is_low_speed_connection(mxs_phy);
484 vbus_is_on = mxs_phy_get_vbus_status(mxs_phy);
504 clk_disable_unprepare(mxs_phy->clk);
507 ret = clk_prepare_enable(mxs_phy->clk);
520 struct mxs_phy *mxs_phy = to_mxs_phy(x);
525 mxs_phy_disconnect_line(mxs_phy, true);
529 mxs_phy_disconnect_line(mxs_phy, false);
564 static int mxs_charger_data_contact_detect(struct mxs_phy *x)
617 static enum usb_charger_type mxs_charger_primary_detection(struct mxs_phy *x)
653 static enum usb_charger_type mxs_charger_secondary_detection(struct mxs_phy *x)
672 struct mxs_phy *mxs_phy = to_mxs_phy(phy);
673 struct regmap *regmap = mxs_phy->regmap_anatop;
680 if (mxs_charger_data_contact_detect(mxs_phy))
683 chgr_type = mxs_charger_primary_detection(mxs_phy);
692 chgr_type = mxs_charger_secondary_detection(mxs_phy);
708 struct mxs_phy *mxs_phy;
729 mxs_phy = devm_kzalloc(&pdev->dev, sizeof(*mxs_phy), GFP_KERNEL);
730 if (!mxs_phy)
735 mxs_phy->regmap_anatop = syscon_regmap_lookup_by_phandle
737 if (IS_ERR(mxs_phy->regmap_anatop)) {
740 return PTR_ERR(mxs_phy->regmap_anatop);
750 mxs_phy->tx_reg_mask |= GM_USBPHY_TX_TXCAL45DN(~0);
751 mxs_phy->tx_reg_set |= GM_USBPHY_TX_TXCAL45DN(val);
759 mxs_phy->tx_reg_mask |= GM_USBPHY_TX_TXCAL45DP(~0);
760 mxs_phy->tx_reg_set |= GM_USBPHY_TX_TXCAL45DP(val);
771 mxs_phy->tx_reg_mask |= GM_USBPHY_TX_D_CAL(~0);
772 mxs_phy->tx_reg_set |= GM_USBPHY_TX_D_CAL(val);
778 mxs_phy->port_id = ret;
780 mxs_phy->phy.io_priv = base;
781 mxs_phy->phy.dev = &pdev->dev;
782 mxs_phy->phy.label = DRIVER_NAME;
783 mxs_phy->phy.init = mxs_phy_init;
784 mxs_phy->phy.shutdown = mxs_phy_shutdown;
785 mxs_phy->phy.set_suspend = mxs_phy_suspend;
786 mxs_phy->phy.notify_connect = mxs_phy_on_connect;
787 mxs_phy->phy.notify_disconnect = mxs_phy_on_disconnect;
788 mxs_phy->phy.type = USB_PHY_TYPE_USB2;
789 mxs_phy->phy.set_wakeup = mxs_phy_set_wakeup;
790 mxs_phy->phy.charger_detect = mxs_phy_charger_detect;
792 mxs_phy->clk = clk;
793 mxs_phy->data = of_id->data;
795 platform_set_drvdata(pdev, mxs_phy);
799 return usb_add_phy_dev(&mxs_phy->phy);
804 struct mxs_phy *mxs_phy = platform_get_drvdata(pdev);
806 usb_remove_phy(&mxs_phy->phy);
812 static void mxs_phy_enable_ldo_in_suspend(struct mxs_phy *mxs_phy, bool on)
817 if (!mxs_phy->regmap_anatop)
820 if (is_imx6q_phy(mxs_phy))
821 regmap_write(mxs_phy->regmap_anatop, reg,
823 else if (is_imx6sl_phy(mxs_phy))
824 regmap_write(mxs_phy->regmap_anatop,
830 struct mxs_phy *mxs_phy = dev_get_drvdata(dev);
833 mxs_phy_enable_ldo_in_suspend(mxs_phy, true);
840 struct mxs_phy *mxs_phy = dev_get_drvdata(dev);
843 mxs_phy_enable_ldo_in_suspend(mxs_phy, false);