usb_hc_ehci.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 10
  19. #endif
  20. #ifndef CONFIG_USB_EHCI_QTD_NUM
  21. #define CONFIG_USB_EHCI_QTD_NUM (CONFIG_USB_EHCI_QH_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. #if CONFIG_USB_ALIGN_SIZE <= 32
  30. #define CONFIG_USB_EHCI_ALIGN_SIZE 32
  31. #elif CONFIG_USB_ALIGN_SIZE <= 64
  32. #define CONFIG_USB_EHCI_ALIGN_SIZE 64
  33. #else
  34. #error "CONFIG_USB_ALIGN_SIZE must be 32 or 64"
  35. #endif
  36. #if CONFIG_USB_EHCI_QTD_NUM < 9
  37. #error CONFIG_USB_EHCI_QTD_NUM is too small, recommand CONFIG_USB_EHCI_QH_NUM * 3
  38. #endif
  39. struct ehci_qtd_hw {
  40. struct ehci_qtd hw;
  41. #if defined(CONFIG_USB_EHCI_DESC_DCACHE_ENABLE) && (CONFIG_USB_ALIGN_SIZE == 64)
  42. uint8_t pad[32];
  43. #endif
  44. bool inuse;
  45. struct usbh_urb *urb;
  46. uintptr_t bufaddr;
  47. uint32_t length;
  48. } __attribute__((aligned(CONFIG_USB_EHCI_ALIGN_SIZE)));
  49. struct ehci_qh_hw {
  50. struct ehci_qh hw;
  51. #if defined(CONFIG_USB_EHCI_DESC_DCACHE_ENABLE)
  52. uint16_t pad[16];
  53. #endif
  54. bool inuse;
  55. uint32_t first_qtd;
  56. struct usbh_urb *urb;
  57. usb_osal_sem_t waitsem;
  58. uint8_t remove_in_iaad;
  59. } __attribute__((aligned(CONFIG_USB_EHCI_ALIGN_SIZE)));
  60. struct ehci_itd_hw {
  61. struct ehci_itd hw;
  62. struct usbh_urb *urb;
  63. uint16_t start_frame;
  64. uint8_t mf_unmask;
  65. uint8_t mf_valid;
  66. uint32_t pkt_idx[8];
  67. bool dir_in;
  68. } __attribute__((aligned(CONFIG_USB_EHCI_ALIGN_SIZE)));
  69. struct ehci_iso_hw {
  70. struct ehci_itd_hw itd_pool[CONFIG_USB_EHCI_ITD_NUM];
  71. uint32_t itd_num;
  72. };
  73. struct ehci_hcd {
  74. bool ehci_iso_used[CONFIG_USB_EHCI_ISO_NUM];
  75. bool ppc; /* Port Power Control */
  76. bool has_tt; /* if use tt instead of Companion Controller */
  77. uint8_t n_cc; /* Number of Companion Controller */
  78. uint8_t n_pcc; /* Number of ports supported per companion host controller */
  79. uint8_t n_ports;
  80. uint8_t hcor_offset;
  81. };
  82. extern struct ehci_hcd g_ehci_hcd[CONFIG_USBHOST_MAX_BUS];
  83. extern uint32_t g_framelist[CONFIG_USBHOST_MAX_BUS][USB_ALIGN_UP(CONFIG_USB_EHCI_FRAME_LIST_SIZE, 1024)];
  84. extern uint8_t usbh_get_port_speed(struct usbh_bus *bus, const uint8_t port);
  85. int ehci_iso_urb_init(struct usbh_bus *bus, struct usbh_urb *urb);
  86. void ehci_kill_iso_urb(struct usbh_bus *bus, struct usbh_urb *urb);
  87. void ehci_scan_isochronous_list(struct usbh_bus *bus);
  88. #endif