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