bcm2835_spi.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * BCM2835 SPI Master Controller
  3. *
  4. * Copyright (c) 2024 Rayhan Faizel <rayhan.faizel@gmail.com>
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. * THE SOFTWARE.
  23. */
  24. #include "hw/sysbus.h"
  25. #include "hw/ssi/ssi.h"
  26. #include "qom/object.h"
  27. #include "qemu/fifo8.h"
  28. #define TYPE_BCM2835_SPI "bcm2835-spi"
  29. OBJECT_DECLARE_SIMPLE_TYPE(BCM2835SPIState, BCM2835_SPI)
  30. /*
  31. * Though BCM2835 documentation says FIFOs have a capacity of 16,
  32. * FIFOs are actually 16 words in size or effectively 64 bytes when operating
  33. * in non DMA mode.
  34. */
  35. #define FIFO_SIZE 64
  36. #define FIFO_SIZE_3_4 48
  37. #define RO_MASK 0x1f0000
  38. #define BCM2835_SPI_CS 0x00
  39. #define BCM2835_SPI_FIFO 0x04
  40. #define BCM2835_SPI_CLK 0x08
  41. #define BCM2835_SPI_DLEN 0x0c
  42. #define BCM2835_SPI_LTOH 0x10
  43. #define BCM2835_SPI_DC 0x14
  44. #define BCM2835_SPI_CS_RXF BIT(20)
  45. #define BCM2835_SPI_CS_RXR BIT(19)
  46. #define BCM2835_SPI_CS_TXD BIT(18)
  47. #define BCM2835_SPI_CS_RXD BIT(17)
  48. #define BCM2835_SPI_CS_DONE BIT(16)
  49. #define BCM2835_SPI_CS_LEN BIT(13)
  50. #define BCM2835_SPI_CS_REN BIT(12)
  51. #define BCM2835_SPI_CS_INTR BIT(10)
  52. #define BCM2835_SPI_CS_INTD BIT(9)
  53. #define BCM2835_SPI_CS_DMAEN BIT(8)
  54. #define BCM2835_SPI_CS_TA BIT(7)
  55. #define BCM2835_SPI_CLEAR_RX BIT(5)
  56. #define BCM2835_SPI_CLEAR_TX BIT(4)
  57. struct BCM2835SPIState {
  58. /* <private> */
  59. SysBusDevice parent_obj;
  60. /* <public> */
  61. SSIBus *bus;
  62. MemoryRegion iomem;
  63. qemu_irq irq;
  64. uint32_t cs;
  65. uint32_t clk;
  66. uint32_t dlen;
  67. uint32_t ltoh;
  68. uint32_t dc;
  69. Fifo8 tx_fifo;
  70. Fifo8 rx_fifo;
  71. };