usbpd.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
  4. */
  5. #ifndef _USBPD_H
  6. #define _USBPD_H
  7. #include <linux/device.h>
  8. struct usbpd;
  9. enum data_role {
  10. DR_NONE = -1,
  11. DR_UFP = 0,
  12. DR_DFP = 1,
  13. };
  14. enum power_role {
  15. PR_NONE = -1,
  16. PR_SINK = 0,
  17. PR_SRC = 1,
  18. };
  19. enum pd_sig_type {
  20. HARD_RESET_SIG = 0,
  21. CABLE_RESET_SIG,
  22. };
  23. enum pd_sop_type {
  24. SOP_MSG = 0,
  25. SOPI_MSG,
  26. SOPII_MSG,
  27. };
  28. enum pd_spec_rev {
  29. USBPD_REV_20 = 1,
  30. USBPD_REV_30 = 2,
  31. };
  32. /* enable msg and signal to be received by phy */
  33. #define FRAME_FILTER_EN_SOP BIT(0)
  34. #define FRAME_FILTER_EN_SOPI BIT(1)
  35. #define FRAME_FILTER_EN_HARD_RESET BIT(5)
  36. struct pd_phy_params {
  37. void (*signal_cb)(struct usbpd *pd, enum pd_sig_type sig);
  38. void (*msg_rx_cb)(struct usbpd *pd, enum pd_sop_type sop,
  39. u8 *buf, size_t len);
  40. void (*shutdown_cb)(struct usbpd *pd);
  41. enum data_role data_role;
  42. enum power_role power_role;
  43. u8 frame_filter_val;
  44. };
  45. struct pd_phy_ops {
  46. int (*open)(struct pd_phy_params *params);
  47. int (*signal)(enum pd_sig_type sig);
  48. int (*write)(u16 hdr, const u8 *data, size_t data_len,
  49. enum pd_sop_type sop);
  50. int (*update_roles)(enum data_role dr, enum power_role pr);
  51. int (*update_frame_filter)(u8 frame_filter_val);
  52. void (*close)(void);
  53. };
  54. #if IS_ENABLED(CONFIG_USB_PD_POLICY)
  55. struct usbpd *usbpd_create(struct device *parent,
  56. struct pd_phy_ops *pdphy_ops);
  57. void usbpd_destroy(struct usbpd *pd);
  58. #else
  59. static inline struct usbpd *usbpd_create(struct device *parent,
  60. struct pd_phy_ops *pdphy_ops)
  61. {
  62. return ERR_PTR(-ENODEV);
  63. }
  64. static inline void usbpd_destroy(struct usbpd *pd) { }
  65. #endif
  66. #endif /* _USBPD_H */