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