usb_hc_ohci.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright (c) 2024, sakumisu
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #ifndef _USB_OHCI_PRIV_H
  7. #define _USB_OHCI_PRIV_H
  8. #include "usbh_core.h"
  9. #include "usbh_hub.h"
  10. #include "usb_ohci_reg.h"
  11. #define OHCI_HCOR ((struct ohci_hcor *)(uintptr_t)(bus->hcd.reg_base + CONFIG_USB_OHCI_HCOR_OFFSET))
  12. #define OHCI_PTR2ADDR(x) ((uint32_t)(uintptr_t)(x) & ~0x0F)
  13. #define OHCI_ADDR2ED(x) ((struct ohci_ed_hw *)(uintptr_t)((uint32_t)(x) & ~0x0F))
  14. #define OHCI_ADDR2TD(x) ((struct ohci_td_hw *)(uintptr_t)((uint32_t)(x) & ~0x0F))
  15. #ifndef CONFIG_USB_OHCI_ED_NUM
  16. #define CONFIG_USB_OHCI_ED_NUM 10
  17. #endif
  18. #ifndef CONFIG_USB_OHCI_TD_NUM
  19. #define CONFIG_USB_OHCI_TD_NUM 3
  20. #endif
  21. #if CONFIG_USB_ALIGN_SIZE <= 32
  22. #define CONFIG_USB_OHCI_ALIGN_SIZE 32
  23. #elif CONFIG_USB_ALIGN_SIZE <= 64
  24. #define CONFIG_USB_OHCI_ALIGN_SIZE 64
  25. #else
  26. #error "CONFIG_USB_ALIGN_SIZE must be 32 or 64"
  27. #endif
  28. struct ohci_ed_hw;
  29. struct ohci_td_hw {
  30. struct ohci_gtd hw;
  31. #if defined(CONFIG_USB_OHCI_DESC_DCACHE_ENABLE) && (CONFIG_USB_ALIGN_SIZE == 32)
  32. uint8_t pad[16];
  33. #elif defined(CONFIG_USB_OHCI_DESC_DCACHE_ENABLE) && (CONFIG_USB_ALIGN_SIZE == 64)
  34. uint8_t pad[48];
  35. #endif
  36. struct usbh_urb *urb;
  37. bool dir_in;
  38. uint32_t buf_start;
  39. uint32_t length;
  40. } __attribute__((aligned(CONFIG_USB_OHCI_ALIGN_SIZE))); /* min is 16bytes, we use CONFIG_USB_OHCI_ALIGN_SIZE for cacheline */
  41. struct ohci_ed_hw {
  42. struct ohci_ed hw;
  43. #if defined(CONFIG_USB_OHCI_DESC_DCACHE_ENABLE) && (CONFIG_USB_ALIGN_SIZE == 32)
  44. uint8_t pad[16];
  45. #elif defined(CONFIG_USB_OHCI_DESC_DCACHE_ENABLE) && (CONFIG_USB_ALIGN_SIZE == 64)
  46. uint8_t pad[48];
  47. #endif
  48. struct ohci_td_hw td_pool[CONFIG_USB_OHCI_TD_NUM];
  49. uint32_t td_count;
  50. uint8_t ed_type;
  51. usb_osal_sem_t waitsem;
  52. } __attribute__((aligned(CONFIG_USB_OHCI_ALIGN_SIZE))); /* min is 16bytes, we use CONFIG_USB_OHCI_ALIGN_SIZE for cacheline */
  53. struct ohci_hcd {
  54. bool ohci_ed_used[CONFIG_USB_OHCI_ED_NUM];
  55. uint8_t n_ports;
  56. };
  57. int ohci_init(struct usbh_bus *bus);
  58. int ohci_deinit(struct usbh_bus *bus);
  59. uint16_t ohci_get_frame_number(struct usbh_bus *bus);
  60. int ohci_roothub_control(struct usbh_bus *bus, struct usb_setup_packet *setup, uint8_t *buf);
  61. int ohci_submit_urb(struct usbh_urb *urb);
  62. int ohci_kill_urb(struct usbh_urb *urb);
  63. void OHCI_IRQHandler(uint8_t busid);
  64. #endif