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)
397 enum usb_phy_events last_event = mxs_phy->phy.last_event;
400 if (!(mxs_phy->data->flags & MXS_PHY_DISCONNECT_LINE_WITHOUT_VBUS))
404 if (!mxs_phy->regmap_anatop)
407 vbus_is_on = mxs_phy_get_vbus_status(mxs_phy);
409 if (on && ((!vbus_is_on && !mxs_phy_is_otg_host(mxs_phy))
411 __mxs_phy_disconnect_line(mxs_phy, true);
413 __mxs_phy_disconnect_line(mxs_phy, false);
420 struct mxs_phy *mxs_phy = to_mxs_phy(phy);
423 ret = clk_prepare_enable(mxs_phy->clk);
427 return mxs_phy_hw_init(mxs_phy);
432 struct mxs_phy *mxs_phy = to_mxs_phy(phy);
448 if (is_imx7ulp_phy(mxs_phy))
451 clk_disable_unprepare(mxs_phy->clk);
454 static bool mxs_phy_is_low_speed_connection(struct mxs_phy *mxs_phy)
463 if (!mxs_phy->regmap_anatop)
466 if (mxs_phy->port_id == 0)
468 else if (mxs_phy->port_id == 1)
471 regmap_read(mxs_phy->regmap_anatop, reg, &line_state);
482 struct mxs_phy *mxs_phy = to_mxs_phy(x);
485 low_speed_connection = mxs_phy_is_low_speed_connection(mxs_phy);
486 vbus_is_on = mxs_phy_get_vbus_status(mxs_phy);
506 clk_disable_unprepare(mxs_phy->clk);
509 ret = clk_prepare_enable(mxs_phy->clk);
522 struct mxs_phy *mxs_phy = to_mxs_phy(x);
527 mxs_phy_disconnect_line(mxs_phy, true);
531 mxs_phy_disconnect_line(mxs_phy, false);
566 static int mxs_charger_data_contact_detect(struct mxs_phy *x)
619 static enum usb_charger_type mxs_charger_primary_detection(struct mxs_phy *x)
655 static enum usb_charger_type mxs_charger_secondary_detection(struct mxs_phy *x)
674 struct mxs_phy *mxs_phy = to_mxs_phy(phy);
675 struct regmap *regmap = mxs_phy->regmap_anatop;
682 if (mxs_charger_data_contact_detect(mxs_phy))
685 chgr_type = mxs_charger_primary_detection(mxs_phy);
694 chgr_type = mxs_charger_secondary_detection(mxs_phy);
710 struct mxs_phy *mxs_phy;
726 mxs_phy = devm_kzalloc(&pdev->dev, sizeof(*mxs_phy), GFP_KERNEL);
727 if (!mxs_phy)
732 mxs_phy->regmap_anatop = syscon_regmap_lookup_by_phandle
734 if (IS_ERR(mxs_phy->regmap_anatop)) {
737 return PTR_ERR(mxs_phy->regmap_anatop);
747 mxs_phy->tx_reg_mask |= GM_USBPHY_TX_TXCAL45DN(~0);
748 mxs_phy->tx_reg_set |= GM_USBPHY_TX_TXCAL45DN(val);
756 mxs_phy->tx_reg_mask |= GM_USBPHY_TX_TXCAL45DP(~0);
757 mxs_phy->tx_reg_set |= GM_USBPHY_TX_TXCAL45DP(val);
768 mxs_phy->tx_reg_mask |= GM_USBPHY_TX_D_CAL(~0);
769 mxs_phy->tx_reg_set |= GM_USBPHY_TX_D_CAL(val);
775 mxs_phy->port_id = ret;
777 mxs_phy->phy.io_priv = base;
778 mxs_phy->phy.dev = &pdev->dev;
779 mxs_phy->phy.label = DRIVER_NAME;
780 mxs_phy->phy.init = mxs_phy_init;
781 mxs_phy->phy.shutdown = mxs_phy_shutdown;
782 mxs_phy->phy.set_suspend = mxs_phy_suspend;
783 mxs_phy->phy.notify_connect = mxs_phy_on_connect;
784 mxs_phy->phy.notify_disconnect = mxs_phy_on_disconnect;
785 mxs_phy->phy.type = USB_PHY_TYPE_USB2;
786 mxs_phy->phy.set_wakeup = mxs_phy_set_wakeup;
787 mxs_phy->phy.charger_detect = mxs_phy_charger_detect;
789 mxs_phy->clk = clk;
790 mxs_phy->data = of_device_get_match_data(&pdev->dev);
792 platform_set_drvdata(pdev, mxs_phy);
796 return usb_add_phy_dev(&mxs_phy->phy);
801 struct mxs_phy *mxs_phy = platform_get_drvdata(pdev);
803 usb_remove_phy(&mxs_phy->phy);
807 static void mxs_phy_enable_ldo_in_suspend(struct mxs_phy *mxs_phy, bool on)
812 if (!mxs_phy->regmap_anatop)
815 if (is_imx6q_phy(mxs_phy))
816 regmap_write(mxs_phy->regmap_anatop, reg,
818 else if (is_imx6sl_phy(mxs_phy))
819 regmap_write(mxs_phy->regmap_anatop,
825 struct mxs_phy *mxs_phy = dev_get_drvdata(dev);
828 mxs_phy_enable_ldo_in_suspend(mxs_phy, true);
835 struct mxs_phy *mxs_phy = dev_get_drvdata(dev);
838 mxs_phy_enable_ldo_in_suspend(mxs_phy, false);