intel-hda.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #ifndef HW_INTEL_HDA_H
  2. #define HW_INTEL_HDA_H
  3. #include "qdev.h"
  4. /* --------------------------------------------------------------------- */
  5. /* hda bus */
  6. #define TYPE_HDA_CODEC_DEVICE "hda-codec"
  7. #define HDA_CODEC_DEVICE(obj) \
  8. OBJECT_CHECK(HDACodecDevice, (obj), TYPE_HDA_CODEC_DEVICE)
  9. #define HDA_CODEC_DEVICE_CLASS(klass) \
  10. OBJECT_CLASS_CHECK(HDACodecDeviceClass, (klass), TYPE_HDA_CODEC_DEVICE)
  11. #define HDA_CODEC_DEVICE_GET_CLASS(obj) \
  12. OBJECT_GET_CLASS(HDACodecDeviceClass, (obj), TYPE_HDA_CODEC_DEVICE)
  13. #define TYPE_HDA_BUS "HDA"
  14. #define HDA_BUS(obj) OBJECT_CHECK(HDACodecBus, (obj), TYPE_HDA_BUS)
  15. typedef struct HDACodecBus HDACodecBus;
  16. typedef struct HDACodecDevice HDACodecDevice;
  17. typedef void (*hda_codec_response_func)(HDACodecDevice *dev,
  18. bool solicited, uint32_t response);
  19. typedef bool (*hda_codec_xfer_func)(HDACodecDevice *dev,
  20. uint32_t stnr, bool output,
  21. uint8_t *buf, uint32_t len);
  22. struct HDACodecBus {
  23. BusState qbus;
  24. uint32_t next_cad;
  25. hda_codec_response_func response;
  26. hda_codec_xfer_func xfer;
  27. };
  28. typedef struct HDACodecDeviceClass
  29. {
  30. DeviceClass parent_class;
  31. int (*init)(HDACodecDevice *dev);
  32. int (*exit)(HDACodecDevice *dev);
  33. void (*command)(HDACodecDevice *dev, uint32_t nid, uint32_t data);
  34. void (*stream)(HDACodecDevice *dev, uint32_t stnr, bool running, bool output);
  35. } HDACodecDeviceClass;
  36. struct HDACodecDevice {
  37. DeviceState qdev;
  38. uint32_t cad; /* codec address */
  39. };
  40. void hda_codec_bus_init(DeviceState *dev, HDACodecBus *bus,
  41. hda_codec_response_func response,
  42. hda_codec_xfer_func xfer);
  43. HDACodecDevice *hda_codec_find(HDACodecBus *bus, uint32_t cad);
  44. void hda_codec_response(HDACodecDevice *dev, bool solicited, uint32_t response);
  45. bool hda_codec_xfer(HDACodecDevice *dev, uint32_t stnr, bool output,
  46. uint8_t *buf, uint32_t len);
  47. /* --------------------------------------------------------------------- */
  48. #define dprint(_dev, _level, _fmt, ...) \
  49. do { \
  50. if (_dev->debug >= _level) { \
  51. fprintf(stderr, "%s: ", _dev->name); \
  52. fprintf(stderr, _fmt, ## __VA_ARGS__); \
  53. } \
  54. } while (0)
  55. /* --------------------------------------------------------------------- */
  56. #endif