usb_ehci_priv.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright (c) 2022, sakumisu
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #ifndef _USB_EHCI_PRIV_H
  7. #define _USB_EHCI_PRIV_H
  8. #include "usbh_core.h"
  9. #include "usbh_hub.h"
  10. #include "usb_hc_ehci.h"
  11. #define EHCI_HCCR ((struct ehci_hccr *)(uintptr_t)(bus->hcd.reg_base + CONFIG_USB_EHCI_HCCR_OFFSET))
  12. #define EHCI_HCOR ((struct ehci_hcor *)(uintptr_t)(bus->hcd.reg_base + CONFIG_USB_EHCI_HCCR_OFFSET + g_ehci_hcd[bus->hcd.hcd_id].hcor_offset))
  13. #define EHCI_PTR2ADDR(x) ((uint32_t)(uintptr_t)(x) & ~0x1F)
  14. #define EHCI_ADDR2QH(x) ((struct ehci_qh_hw *)(uintptr_t)((uint32_t)(x) & ~0x1F))
  15. #define EHCI_ADDR2QTD(x) ((struct ehci_qtd_hw *)(uintptr_t)((uint32_t)(x) & ~0x1F))
  16. #define EHCI_ADDR2ITD(x) ((struct ehci_itd_hw *)(uintptr_t)((uint32_t)(x) & ~0x1F))
  17. #ifndef CONFIG_USB_EHCI_QH_NUM
  18. #define CONFIG_USB_EHCI_QH_NUM CONFIG_USBHOST_PIPE_NUM
  19. #endif
  20. #ifndef CONFIG_USB_EHCI_QTD_NUM
  21. #define CONFIG_USB_EHCI_QTD_NUM 3
  22. #endif
  23. #ifndef CONFIG_USB_EHCI_ITD_NUM
  24. #define CONFIG_USB_EHCI_ITD_NUM 5
  25. #endif
  26. #ifndef CONFIG_USB_EHCI_ISO_NUM
  27. #define CONFIG_USB_EHCI_ISO_NUM 4
  28. #endif
  29. extern uint8_t usbh_get_port_speed(struct usbh_bus *bus, const uint8_t port);
  30. struct ehci_qtd_hw {
  31. struct ehci_qtd hw;
  32. struct usbh_urb *urb;
  33. uint32_t length;
  34. } __attribute__((aligned(32)));
  35. struct ehci_qh_hw {
  36. struct ehci_qh hw;
  37. struct ehci_qtd_hw qtd_pool[CONFIG_USB_EHCI_QTD_NUM];
  38. uint32_t first_qtd;
  39. struct usbh_urb *urb;
  40. usb_osal_sem_t waitsem;
  41. uint8_t remove_in_iaad;
  42. } __attribute__((aligned(32)));
  43. struct ehci_itd_hw {
  44. struct ehci_itd hw;
  45. struct usbh_urb *urb;
  46. uint16_t start_frame;
  47. uint8_t mf_unmask;
  48. uint8_t mf_valid;
  49. uint32_t pkt_idx[8];
  50. } __attribute__((aligned(32)));
  51. struct ehci_iso_hw
  52. {
  53. struct ehci_itd_hw itd_pool[CONFIG_USB_EHCI_ITD_NUM];
  54. uint32_t itd_num;
  55. };
  56. struct ehci_hcd {
  57. bool ehci_qh_used[CONFIG_USB_EHCI_QH_NUM];
  58. bool ehci_iso_used[CONFIG_USB_EHCI_ISO_NUM];
  59. bool ppc; /* Port Power Control */
  60. bool has_tt; /* if use tt instead of Companion Controller */
  61. uint8_t n_cc; /* Number of Companion Controller */
  62. uint8_t n_pcc; /* Number of ports supported per companion host controller */
  63. uint8_t n_ports;
  64. uint8_t hcor_offset;
  65. };
  66. extern struct ehci_hcd g_ehci_hcd[CONFIG_USBHOST_MAX_BUS];
  67. extern uint32_t g_framelist[CONFIG_USBHOST_MAX_BUS][USB_ALIGN_UP(CONFIG_USB_EHCI_FRAME_LIST_SIZE, 1024)];
  68. int ehci_iso_urb_init(struct usbh_bus *bus, struct usbh_urb *urb);
  69. void ehci_kill_iso_urb(struct usbh_bus *bus, struct usbh_urb *urb);
  70. void ehci_scan_isochronous_list(struct usbh_bus *bus);
  71. #endif