usb_hc_ohci.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 CONFIG_USBHOST_PIPE_NUM
  17. #endif
  18. #ifndef CONFIG_USB_OHCI_TD_NUM
  19. #define CONFIG_USB_OHCI_TD_NUM 3
  20. #endif
  21. #ifndef CONFIG_USB_OHCI_ALIGN_SIZE
  22. #define CONFIG_USB_OHCI_ALIGN_SIZE 64
  23. #endif
  24. struct ohci_ed_hw;
  25. struct ohci_td_hw {
  26. struct ohci_gtd hw;
  27. struct usbh_urb *urb;
  28. bool dir_in;
  29. uint32_t buf_start;
  30. uint32_t length;
  31. } __attribute__((aligned(CONFIG_USB_OHCI_ALIGN_SIZE))); /* min is 16bytes, we use CONFIG_USB_OHCI_ALIGN_SIZE for cacheline */
  32. struct ohci_ed_hw {
  33. struct ohci_ed hw;
  34. struct ohci_td_hw td_pool[CONFIG_USB_OHCI_TD_NUM];
  35. uint32_t td_count;
  36. uint8_t ed_type;
  37. usb_osal_sem_t waitsem;
  38. } __attribute__((aligned(CONFIG_USB_OHCI_ALIGN_SIZE))); /* min is 16bytes, we use CONFIG_USB_OHCI_ALIGN_SIZE for cacheline */
  39. struct ohci_hcd {
  40. bool ohci_ed_used[CONFIG_USB_OHCI_ED_NUM];
  41. uint8_t n_ports;
  42. };
  43. int ohci_init(struct usbh_bus *bus);
  44. int ohci_deinit(struct usbh_bus *bus);
  45. uint16_t ohci_get_frame_number(struct usbh_bus *bus);
  46. int ohci_roothub_control(struct usbh_bus *bus, struct usb_setup_packet *setup, uint8_t *buf);
  47. int ohci_submit_urb(struct usbh_urb *urb);
  48. int ohci_kill_urb(struct usbh_urb *urb);
  49. void OHCI_IRQHandler(uint8_t busid);
  50. #endif