mt7620-usb-phy.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2020 MediaTek Inc. All Rights Reserved.
  4. *
  5. * Author: Weijie Gao <weijie.gao@mediatek.com>
  6. */
  7. #include <clk.h>
  8. #include <dm.h>
  9. #include <generic-phy.h>
  10. #include <misc.h>
  11. #include <reset.h>
  12. #include <dm/device_compat.h>
  13. #include <linux/delay.h>
  14. #include <mach/mt7620-sysc.h>
  15. struct mt7620_usb_phy {
  16. struct udevice *sysc;
  17. struct clk_bulk clocks;
  18. struct reset_ctl_bulk resets;
  19. };
  20. static int mt7620_usb_phy_power_on(struct phy *_phy)
  21. {
  22. struct mt7620_usb_phy *phy = dev_get_priv(_phy->dev);
  23. u32 mode = MT7620_SYSC_USB_HOST_MODE;
  24. int ret;
  25. reset_deassert_bulk(&phy->resets);
  26. clk_enable_bulk(&phy->clocks);
  27. mdelay(10);
  28. ret = misc_ioctl(phy->sysc, MT7620_SYSC_IOCTL_SET_USB_MODE, &mode);
  29. if (ret) {
  30. dev_err(_phy->dev,
  31. "mt7620_usbphy: failed to set USB host mode\n");
  32. return ret;
  33. }
  34. mdelay(10);
  35. return 0;
  36. }
  37. static int mt7620_usb_phy_power_off(struct phy *_phy)
  38. {
  39. struct mt7620_usb_phy *phy = dev_get_priv(_phy->dev);
  40. clk_disable_bulk(&phy->clocks);
  41. reset_assert_bulk(&phy->resets);
  42. return 0;
  43. }
  44. static int mt7620_usb_phy_probe(struct udevice *dev)
  45. {
  46. struct mt7620_usb_phy *phy = dev_get_priv(dev);
  47. struct ofnode_phandle_args sysc_args;
  48. int ret;
  49. ret = ofnode_parse_phandle_with_args(dev_ofnode(dev), "mediatek,sysc", NULL,
  50. 0, 0, &sysc_args);
  51. if (ret) {
  52. dev_err(dev, "mt7620_usbphy: sysc property not found\n");
  53. return ret;
  54. }
  55. ret = uclass_get_device_by_ofnode(UCLASS_MISC, sysc_args.node,
  56. &phy->sysc);
  57. if (ret) {
  58. dev_err(dev, "mt7620_usbphy: failed to sysc device\n");
  59. return ret;
  60. }
  61. ret = clk_get_bulk(dev, &phy->clocks);
  62. if (ret) {
  63. dev_err(dev, "mt7620_usbphy: failed to get clocks\n");
  64. return ret;
  65. }
  66. ret = reset_get_bulk(dev, &phy->resets);
  67. if (ret) {
  68. dev_err(dev, "mt7620_usbphy: failed to get reset control\n");
  69. return ret;
  70. }
  71. return 0;
  72. }
  73. static struct phy_ops mt7620_usb_phy_ops = {
  74. .power_on = mt7620_usb_phy_power_on,
  75. .power_off = mt7620_usb_phy_power_off,
  76. };
  77. static const struct udevice_id mt7620_usb_phy_ids[] = {
  78. { .compatible = "mediatek,mt7620-usbphy" },
  79. { }
  80. };
  81. U_BOOT_DRIVER(mt7620_usb_phy) = {
  82. .name = "mt7620_usb_phy",
  83. .id = UCLASS_PHY,
  84. .of_match = mt7620_usb_phy_ids,
  85. .ops = &mt7620_usb_phy_ops,
  86. .probe = mt7620_usb_phy_probe,
  87. .priv_auto = sizeof(struct mt7620_usb_phy),
  88. };