bcm2835_i2c.h 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Broadcom Serial Controller (BSC)
  3. *
  4. * Copyright (c) 2024 Rayhan Faizel <rayhan.faizel@gmail.com>
  5. *
  6. * SPDX-License-Identifier: MIT
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  21. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. */
  26. #include "hw/sysbus.h"
  27. #include "hw/i2c/i2c.h"
  28. #include "qom/object.h"
  29. #define TYPE_BCM2835_I2C "bcm2835-i2c"
  30. OBJECT_DECLARE_SIMPLE_TYPE(BCM2835I2CState, BCM2835_I2C)
  31. #define BCM2835_I2C_C 0x0 /* Control */
  32. #define BCM2835_I2C_S 0x4 /* Status */
  33. #define BCM2835_I2C_DLEN 0x8 /* Data Length */
  34. #define BCM2835_I2C_A 0xc /* Slave Address */
  35. #define BCM2835_I2C_FIFO 0x10 /* FIFO */
  36. #define BCM2835_I2C_DIV 0x14 /* Clock Divider */
  37. #define BCM2835_I2C_DEL 0x18 /* Data Delay */
  38. #define BCM2835_I2C_CLKT 0x20 /* Clock Stretch Timeout */
  39. #define BCM2835_I2C_C_I2CEN BIT(15) /* I2C enable */
  40. #define BCM2835_I2C_C_INTR BIT(10) /* Interrupt on RXR */
  41. #define BCM2835_I2C_C_INTT BIT(9) /* Interrupt on TXW */
  42. #define BCM2835_I2C_C_INTD BIT(8) /* Interrupt on DONE */
  43. #define BCM2835_I2C_C_ST BIT(7) /* Start transfer */
  44. #define BCM2835_I2C_C_CLEAR (BIT(5) | BIT(4)) /* Clear FIFO */
  45. #define BCM2835_I2C_C_READ BIT(0) /* I2C read mode */
  46. #define BCM2835_I2C_S_CLKT BIT(9) /* Clock stretch timeout */
  47. #define BCM2835_I2C_S_ERR BIT(8) /* Slave error */
  48. #define BCM2835_I2C_S_RXF BIT(7) /* RX FIFO full */
  49. #define BCM2835_I2C_S_TXE BIT(6) /* TX FIFO empty */
  50. #define BCM2835_I2C_S_RXD BIT(5) /* RX bytes available */
  51. #define BCM2835_I2C_S_TXD BIT(4) /* TX space available */
  52. #define BCM2835_I2C_S_RXR BIT(3) /* RX FIFO needs reading */
  53. #define BCM2835_I2C_S_TXW BIT(2) /* TX FIFO needs writing */
  54. #define BCM2835_I2C_S_DONE BIT(1) /* I2C Transfer complete */
  55. #define BCM2835_I2C_S_TA BIT(0) /* I2C Transfer active */
  56. struct BCM2835I2CState {
  57. /* <private> */
  58. SysBusDevice parent_obj;
  59. /* <public> */
  60. MemoryRegion iomem;
  61. I2CBus *bus;
  62. qemu_irq irq;
  63. uint32_t c;
  64. uint32_t s;
  65. uint32_t dlen;
  66. uint32_t a;
  67. uint32_t div;
  68. uint32_t del;
  69. uint32_t clkt;
  70. uint32_t last_dlen;
  71. };