phy-ab8500-usb.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /* Copyright (C) 2019 Stephan Gerhold */
  3. #include <common.h>
  4. #include <dm.h>
  5. #include <generic-phy.h>
  6. #include <linux/bitops.h>
  7. #include <power/pmic.h>
  8. #include <power/ab8500.h>
  9. #define AB8500_USB_PHY_CTRL_REG AB8500_USB(0x8A)
  10. #define AB8500_BIT_PHY_CTRL_HOST_EN BIT(0)
  11. #define AB8500_BIT_PHY_CTRL_DEVICE_EN BIT(1)
  12. #define AB8500_USB_PHY_CTRL_MASK (AB8500_BIT_PHY_CTRL_HOST_EN |\
  13. AB8500_BIT_PHY_CTRL_DEVICE_EN)
  14. static int ab8500_usb_phy_power_on(struct phy *phy)
  15. {
  16. struct udevice *dev = phy->dev;
  17. uint set = AB8500_BIT_PHY_CTRL_DEVICE_EN;
  18. if (CONFIG_IS_ENABLED(USB_MUSB_HOST))
  19. set = AB8500_BIT_PHY_CTRL_HOST_EN;
  20. return pmic_clrsetbits(dev->parent, AB8500_USB_PHY_CTRL_REG,
  21. AB8500_USB_PHY_CTRL_MASK, set);
  22. }
  23. static int ab8500_usb_phy_power_off(struct phy *phy)
  24. {
  25. struct udevice *dev = phy->dev;
  26. return pmic_clrsetbits(dev->parent, AB8500_USB_PHY_CTRL_REG,
  27. AB8500_USB_PHY_CTRL_MASK, 0);
  28. }
  29. struct phy_ops ab8500_usb_phy_ops = {
  30. .power_on = ab8500_usb_phy_power_on,
  31. .power_off = ab8500_usb_phy_power_off,
  32. };
  33. static const struct udevice_id ab8500_usb_phy_ids[] = {
  34. { .compatible = "stericsson,ab8500-usb" },
  35. { }
  36. };
  37. U_BOOT_DRIVER(ab8500_usb_phy) = {
  38. .name = "ab8500_usb_phy",
  39. .id = UCLASS_PHY,
  40. .of_match = ab8500_usb_phy_ids,
  41. .ops = &ab8500_usb_phy_ops,
  42. };