usb_hw.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * usb_hw.h
  3. *
  4. * Copyright (C) 2019 Sylvain Munaut
  5. * All rights reserved.
  6. *
  7. * LGPL v3+, see LICENSE.lgpl3
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 3 of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public License
  20. * along with this program; if not, write to the Free Software Foundation,
  21. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  22. */
  23. #pragma once
  24. #include <stdint.h>
  25. #include "config.h"
  26. struct usb_core {
  27. uint32_t csr;
  28. uint32_t ar;
  29. uint32_t evt;
  30. } __attribute__((packed,aligned(4)));
  31. #define USB_CSR_PU_ENA (1 << 15)
  32. #define USB_CSR_EVT_PENDING (1 << 14)
  33. #define USB_CSR_CEL_ACTIVE (1 << 13)
  34. #define USB_CSR_CEL_ENA (1 << 12)
  35. #define USB_CSR_BUS_SUSPEND (1 << 11)
  36. #define USB_CSR_BUS_RST (1 << 10)
  37. #define USB_CSR_BUS_RST_PENDING (1 << 9)
  38. #define USB_CSR_SOF_PENDING (1 << 8)
  39. #define USB_CSR_ADDR_MATCH (1 << 7)
  40. #define USB_CSR_ADDR(x) ((x) & 0x7f)
  41. #define USB_AR_CEL_RELEASE (1 << 13)
  42. #define USB_AR_BUS_RST_CLEAR (1 << 9)
  43. #define USB_AR_SOF_CLEAR (1 << 8)
  44. struct usb_ep {
  45. uint32_t status;
  46. uint32_t _rsvd[3];
  47. struct {
  48. uint32_t csr;
  49. uint32_t ptr;
  50. } bd[2];
  51. } __attribute__((packed,aligned(4)));
  52. struct usb_ep_pair {
  53. struct usb_ep out;
  54. struct usb_ep in;
  55. } __attribute__((packed,aligned(4)));
  56. #define USB_EP_TYPE_NONE 0x0000
  57. #define USB_EP_TYPE_ISOC 0x0001
  58. #define USB_EP_TYPE_INT 0x0002
  59. #define USB_EP_TYPE_BULK 0x0004
  60. #define USB_EP_TYPE_CTRL 0x0006
  61. #define USB_EP_TYPE_HALTED 0x0001
  62. #define USB_EP_TYPE_IS_BCI(x) (((x) & 6) != 0)
  63. #define USB_EP_TYPE(x) ((x) & 6)
  64. #define USB_EP_DT_BIT 0x0080
  65. #define USB_EP_BD_IDX 0x0040
  66. #define USB_EP_BD_CTRL 0x0020
  67. #define USB_EP_BD_DUAL 0x0010
  68. #define USB_BD_STATE_MSK 0xe000
  69. #define USB_BD_STATE_NONE 0x0000
  70. #define USB_BD_STATE_RDY_DATA 0x4000
  71. #define USB_BD_STATE_RDY_STALL 0x6000
  72. #define USB_BD_STATE_DONE_OK 0x8000
  73. #define USB_BD_STATE_DONE_ERR 0xa000
  74. #define USB_BD_IS_SETUP 0x1000
  75. #define USB_BD_LEN(l) ((l) & 0x3ff)
  76. #define USB_BD_LEN_MSK 0x03ff
  77. static volatile struct usb_core * const usb_regs = (void*) (USB_CORE_BASE);
  78. static volatile struct usb_ep_pair * const usb_ep_regs = (void*)((USB_CORE_BASE) + (1 << 13));