00001
00045 #ifndef USBB_INTERNAL_H_INCLUDED
00046 #define USBB_INTERNAL_H_INCLUDED
00047
00048 #include <bitops.h>
00049 #include <dmapool.h>
00050 #include <slist.h>
00051 #include <stdint.h>
00052 #include <usb/request.h>
00053 #include <usb/udc.h>
00054
00055 #include "usbb_regs.h"
00056
00061 struct usbb_sw_dma_desc {
00065 struct usbb_dma_desc hw;
00070 phys_addr_t phys;
00071 };
00072
00073 static inline phys_addr_t usbb_dma_desc_phys(struct usbb_sw_dma_desc *desc)
00074 {
00075 return desc->phys;
00076 };
00077
00078 static inline void usbb_dma_desc_set_phys(struct usbb_sw_dma_desc *desc,
00079 phys_addr_t phys)
00080 {
00081 desc->phys = phys;
00082 }
00083
00084
00085
00089 enum ep0_state {
00090 EP0_STATE_SETUP = 0,
00091 EP0_STATE_DATA_IN,
00092 EP0_STATE_DATA_ZLP,
00093 EP0_STATE_DATA_OUT,
00094 EP0_STATE_STATUS_IN,
00095 EP0_STATE_STATUS_OUT,
00096 EP0_STATE_TEST_J,
00097 EP0_STATE_TEST_K,
00098 EP0_STATE_TEST_SE0_NAK,
00099 EP0_STATE_TEST_PACKET,
00100 };
00101
00102 enum usbb_ep_flag {
00103 USBB_EP_ACTIVE_XFER,
00104 USBB_EP_ENABLED,
00105 USBB_EP_WEDGE,
00106 };
00107
00108 struct usbb_udc_ep {
00109 const struct usb_endpoint_descriptor *desc;
00110 unsigned int buf_offset;
00111 uint16_t maxpacket;
00112 uint16_t bytes_written;
00113 unsigned long flags;
00114 struct slist req_queue;
00115 struct slist buf_queue;
00116 };
00117
00118 struct usbb_udc {
00119 struct udc udc;
00120 enum ep0_state ctrl_state;
00121 struct usb_setup_req setup_req;
00122 struct usbb_controller *usbb;
00123 struct usbb_udc_ep ep[CONFIG_USBB_NR_EP];
00124 };
00125
00126 static inline bool usbb_udc_entering_test_mode(struct usbb_udc *udcb)
00127 {
00128 #ifdef CONFIG_UDC_HIGH_SPEED
00129 return udcb->ctrl_state >= EP0_STATE_TEST_J
00130 && udcb->ctrl_state <= EP0_STATE_TEST_PACKET;
00131 #else
00132 return false;
00133 #endif
00134 }
00135
00136 static inline bool usbb_udc_is_enabled(struct usbb_udc *udcb)
00137 {
00138 #if defined(CONFIG_USBB_OTG)
00139 return test_bit(USB_DEV_IS_ENABLED, &udcb->udc.flags);
00140 #elif defined(CONFIG_USBB_UDC)
00141 return true;
00142 #else
00143 return false;
00144 #endif
00145 }
00146
00147 static inline void usbb_udc_enable(struct usbb_udc *udcb)
00148 {
00149
00150
00151
00152
00153
00154
00155 udcb->udc.flags &= (1 << USB_DEV_IS_ENABLED)
00156 | (1 << USB_DEV_AUTOATTACH);
00157 udcb->udc.flags |= 1 << USB_DEV_IS_ENABLED;
00158 }
00159
00160 static inline void usbb_udc_disable(struct usbb_udc *udcb)
00161 {
00162
00163
00164
00165
00166 udcb->udc.flags &= 1 << USB_DEV_AUTOATTACH;
00167 }
00168
00169 extern void usbb_udc_interrupt(struct usbb_udc *udcb);
00170 extern void usbb_udc_vbus_off(struct usbb_udc *udcb);
00171 extern void usbb_udc_vbus_on(struct usbb_udc *udcb);
00172 extern struct usbb_udc *usbb_udc_init(void);
00173 extern void usbb_udc_shutdown(struct usbb_udc *udcb);
00174
00175
00176
00177 struct usbb_host {
00178
00179 };
00180
00181 static inline bool usbb_host_is_enabled(struct usbb_host *hostb)
00182 {
00183 #if defined(CONFIG_USBB_OTG)
00184 return test_bit(USB_HOST_IS_ENABLED, &hostb->hcd.flags);
00185 #elif defined(CONFIG_USBB_HOST)
00186 return true;
00187 #else
00188 return false;
00189 #endif
00190 }
00191
00192 extern void usbb_host_enable(struct usbb_host *hostb);
00193 extern void usbb_host_disable(struct usbb_host *hostb);
00194 extern struct usbb_host *usbb_host_init(void);
00195 extern void usbb_host_shutdown(struct usbb_host *hostb);
00196
00197
00198
00199 struct usbb_controller {
00200 #ifdef CONFIG_USBB_UDC
00201 struct usbb_udc *udc;
00202 #endif
00203 #ifdef CONFIG_USBB_HOST
00204 struct usbb_host *host;
00205 #endif
00206 };
00207
00208 extern struct dma_pool usbb_desc_pool;
00209
00210 static inline struct usbb_sw_dma_desc *usbb_dma_desc_alloc(phys_addr_t *paddr)
00211 {
00212 return dma_pool_alloc(&usbb_desc_pool, paddr);
00213 }
00214
00215 static inline void usbb_dma_desc_free(struct usbb_sw_dma_desc *desc)
00216 {
00217 dma_pool_free(&usbb_desc_pool, desc);
00218 }
00219
00220 #endif