auxbus.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * auxbus.h
  3. *
  4. * Copyright (C)2014 : GreenSocs Ltd
  5. * http://www.greensocs.com/ , email: info@greensocs.com
  6. *
  7. * Developed by :
  8. * Frederic Konrad <fred.konrad@greensocs.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation, either version 2 of the License, or
  13. * (at your option)any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License along
  21. * with this program; if not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. #ifndef HW_MISC_AUXBUS_H
  25. #define HW_MISC_AUXBUS_H
  26. #include "hw/qdev.h"
  27. typedef struct AUXBus AUXBus;
  28. typedef struct AUXSlave AUXSlave;
  29. typedef enum AUXCommand AUXCommand;
  30. typedef enum AUXReply AUXReply;
  31. typedef struct AUXTOI2CState AUXTOI2CState;
  32. enum AUXCommand {
  33. WRITE_I2C = 0,
  34. READ_I2C = 1,
  35. WRITE_I2C_STATUS = 2,
  36. WRITE_I2C_MOT = 4,
  37. READ_I2C_MOT = 5,
  38. WRITE_AUX = 8,
  39. READ_AUX = 9
  40. };
  41. enum AUXReply {
  42. AUX_I2C_ACK = 0,
  43. AUX_NACK = 1,
  44. AUX_DEFER = 2,
  45. AUX_I2C_NACK = 4,
  46. AUX_I2C_DEFER = 8
  47. };
  48. #define TYPE_AUX_BUS "aux-bus"
  49. #define AUX_BUS(obj) OBJECT_CHECK(AUXBus, (obj), TYPE_AUX_BUS)
  50. struct AUXBus {
  51. /* < private > */
  52. BusState qbus;
  53. /* < public > */
  54. AUXSlave *current_dev;
  55. AUXSlave *dev;
  56. uint32_t last_i2c_address;
  57. AUXCommand last_transaction;
  58. AUXTOI2CState *bridge;
  59. MemoryRegion *aux_io;
  60. AddressSpace aux_addr_space;
  61. };
  62. #define TYPE_AUX_SLAVE "aux-slave"
  63. #define AUX_SLAVE(obj) \
  64. OBJECT_CHECK(AUXSlave, (obj), TYPE_AUX_SLAVE)
  65. struct AUXSlave {
  66. /* < private > */
  67. DeviceState parent_obj;
  68. /* < public > */
  69. MemoryRegion *mmio;
  70. };
  71. /**
  72. * aux_init_bus: Initialize an AUX bus.
  73. *
  74. * Returns the new AUX bus created.
  75. *
  76. * @parent The device where this bus is located.
  77. * @name The name of the bus.
  78. */
  79. AUXBus *aux_init_bus(DeviceState *parent, const char *name);
  80. /*
  81. * aux_request: Make a request on the bus.
  82. *
  83. * Returns the reply of the request.
  84. *
  85. * @bus Ths bus where the request happen.
  86. * @cmd The command requested.
  87. * @address The 20bits address of the slave.
  88. * @len The length of the read or write.
  89. * @data The data array which will be filled or read during transfer.
  90. */
  91. AUXReply aux_request(AUXBus *bus, AUXCommand cmd, uint32_t address,
  92. uint8_t len, uint8_t *data);
  93. /*
  94. * aux_get_i2c_bus: Get the i2c bus for I2C over AUX command.
  95. *
  96. * Returns the i2c bus associated to this AUX bus.
  97. *
  98. * @bus The AUX bus.
  99. */
  100. I2CBus *aux_get_i2c_bus(AUXBus *bus);
  101. /*
  102. * aux_init_mmio: Init an mmio for an AUX slave.
  103. *
  104. * @aux_slave The AUX slave.
  105. * @mmio The mmio to be registered.
  106. */
  107. void aux_init_mmio(AUXSlave *aux_slave, MemoryRegion *mmio);
  108. DeviceState *aux_create_slave(AUXBus *bus, const char *name, uint32_t addr);
  109. #endif /* HW_MISC_AUXBUS_H */