usb_otg_aotg.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * Copyright (c) 2020 Actions Corporation.
  3. * Author: Jinang Lv <lvjinang@actions-semi.com>
  4. *
  5. * SPDX-License-Identifier: Apache-2.0
  6. */
  7. /**
  8. * @file
  9. * @brief USB Actions OTG controller driver private definitions
  10. *
  11. * This file contains the Actions OTG USB controller driver private
  12. * definitions.
  13. */
  14. #ifndef __USB_OTG_AOTG_H__
  15. #define __USB_OTG_AOTG_H__
  16. #include <sys/sys_io.h>
  17. #include <board.h>
  18. #ifndef DIV_ROUND_UP
  19. #define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
  20. #endif
  21. static inline uint8_t usb_read8(uint32_t addr)
  22. {
  23. return *(volatile uint8_t *)addr;
  24. }
  25. static inline void usb_write8(uint32_t addr, uint8_t val)
  26. {
  27. *(volatile uint8_t *)addr = val;
  28. }
  29. static inline uint16_t usb_read16(uint32_t addr)
  30. {
  31. return *(volatile uint16_t *)addr;
  32. }
  33. static inline void usb_write16(uint32_t addr, uint16_t val)
  34. {
  35. *(volatile uint16_t *)addr = val;
  36. }
  37. static inline uint32_t usb_read32(uint32_t addr)
  38. {
  39. return sys_read32(addr);
  40. }
  41. static inline void usb_write32(uint32_t addr, uint32_t val)
  42. {
  43. sys_write32(val, addr);
  44. }
  45. static inline void usb_set_bit8(uint32_t addr, uint8_t val)
  46. {
  47. uint8_t tmp = *(volatile uint8_t *)addr;
  48. *(volatile uint8_t *)addr = tmp | (1 << val);
  49. }
  50. static inline void usb_clear_bit8(uint32_t addr, uint8_t val)
  51. {
  52. uint8_t tmp = *(volatile uint8_t *)addr;
  53. *(volatile uint8_t *)addr = tmp & ~(1 << val);
  54. }
  55. static inline void usb_set_bit32(uint32_t addr, uint32_t val)
  56. {
  57. sys_set_bit(addr, val);
  58. }
  59. static inline void usb_clear_bit32(uint32_t addr, uint32_t val)
  60. {
  61. sys_clear_bit(addr, val);
  62. }
  63. /* Max device address */
  64. #define USB_AOTG_MAX_ADDR 0x7F
  65. #define USB_AOTG_EP0_IDX 0
  66. /* AOTG EP reset type */
  67. enum usb_aotg_ep_reset_type {
  68. USB_AOTG_EP_FIFO_RESET = 0,
  69. USB_AOTG_EP_TOGGLE_RESET,
  70. /* Toggle & FIFO reset */
  71. USB_AOTG_EP_RESET
  72. };
  73. /* AOTG FIFO type */
  74. enum usb_aotg_fifo_type {
  75. USB_AOTG_FIFO_SINGLE = 0, /* default */
  76. USB_AOTG_FIFO_DOUBLE,
  77. USB_AOTG_FIFO_TRIPLE,
  78. USB_AOTG_FIFO_QUAD
  79. };
  80. /**
  81. * There are 2 or 3 stages: Setup, Data (optional), Status
  82. * for control transfer.
  83. * There are 3 cases that may exist during control transfer
  84. * which we have to take care to make AOTG work fine.
  85. * Case 1: Setup, In Data, Out Status;
  86. * Case 2: Setup, In Status;
  87. * Case 3: Setup, Out Data, In Status;
  88. */
  89. enum usb_aotg_ep0_phase {
  90. USB_AOTG_SETUP = 1,
  91. USB_AOTG_IN_DATA,
  92. USB_AOTG_OUT_DATA,
  93. USB_AOTG_IN_STATUS,
  94. USB_AOTG_OUT_STATUS,
  95. /* Special phase which is necessary */
  96. USB_AOTG_SET_ADDRESS
  97. };
  98. /*
  99. * version list: Append if need
  100. */
  101. #define USB_AOTG_VERSION_ANDESM 0x551A20FF
  102. #define USB_AOTG_VERSION_WOODPECKER 0x551A18CF
  103. #define USB_AOTG_VERSION_LARK 0x551A22CF
  104. #define USB_AOTG_VERSION_LEOPARD 0x551A24CF
  105. /*
  106. * specific header file
  107. */
  108. #if (CONFIG_USB_AOTG_OTG_VERSION == USB_AOTG_VERSION_ANDESM)
  109. #include "usb_aotg_andesm.h"
  110. #elif (CONFIG_USB_AOTG_OTG_VERSION == USB_AOTG_VERSION_WOODPECKER)
  111. #include "usb_aotg_woodpecker.h"
  112. #elif (CONFIG_USB_AOTG_OTG_VERSION == USB_AOTG_VERSION_LARK)
  113. #include "usb_aotg_lark.h"
  114. #elif (CONFIG_USB_AOTG_OTG_VERSION == USB_AOTG_VERSION_LEOPARD)
  115. #include "usb_aotg_leopard.h"
  116. #else
  117. #error Wrong CONFIG_USB_AOTG_OTG_VERSION
  118. #endif
  119. #endif /* __USB_OTG_AOTG_H__ */