usb_hc_ehci.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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_ehci_reg.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. #ifndef CONFIG_USB_EHCI_ALIGN_SIZE
  30. #define CONFIG_USB_EHCI_ALIGN_SIZE 64
  31. #endif
  32. extern uint8_t usbh_get_port_speed(struct usbh_bus *bus, const uint8_t port);
  33. struct ehci_qtd_hw {
  34. struct ehci_qtd hw;
  35. struct usbh_urb *urb;
  36. bool dir_in;
  37. uintptr_t bufaddr;
  38. uint32_t length;
  39. } __attribute__((aligned(CONFIG_USB_EHCI_ALIGN_SIZE)));
  40. struct ehci_qh_hw {
  41. struct ehci_qh hw;
  42. struct ehci_qtd_hw qtd_pool[CONFIG_USB_EHCI_QTD_NUM];
  43. uint32_t first_qtd;
  44. struct usbh_urb *urb;
  45. usb_osal_sem_t waitsem;
  46. uint8_t remove_in_iaad;
  47. } __attribute__((aligned(CONFIG_USB_EHCI_ALIGN_SIZE)));
  48. struct ehci_itd_hw {
  49. struct ehci_itd hw;
  50. struct usbh_urb *urb;
  51. uint16_t start_frame;
  52. uint8_t mf_unmask;
  53. uint8_t mf_valid;
  54. uint32_t pkt_idx[8];
  55. bool dir_in;
  56. } __attribute__((aligned(CONFIG_USB_EHCI_ALIGN_SIZE)));
  57. struct ehci_iso_hw
  58. {
  59. struct ehci_itd_hw itd_pool[CONFIG_USB_EHCI_ITD_NUM];
  60. uint32_t itd_num;
  61. };
  62. struct ehci_hcd {
  63. bool ehci_qh_used[CONFIG_USB_EHCI_QH_NUM];
  64. bool ehci_iso_used[CONFIG_USB_EHCI_ISO_NUM];
  65. bool ppc; /* Port Power Control */
  66. bool has_tt; /* if use tt instead of Companion Controller */
  67. uint8_t n_cc; /* Number of Companion Controller */
  68. uint8_t n_pcc; /* Number of ports supported per companion host controller */
  69. uint8_t n_ports;
  70. uint8_t hcor_offset;
  71. };
  72. extern struct ehci_hcd g_ehci_hcd[CONFIG_USBHOST_MAX_BUS];
  73. extern uint32_t g_framelist[CONFIG_USBHOST_MAX_BUS][USB_ALIGN_UP(CONFIG_USB_EHCI_FRAME_LIST_SIZE, 1024)];
  74. int ehci_iso_urb_init(struct usbh_bus *bus, struct usbh_urb *urb);
  75. void ehci_kill_iso_urb(struct usbh_bus *bus, struct usbh_urb *urb);
  76. void ehci_scan_isochronous_list(struct usbh_bus *bus);
  77. #endif