codec.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* SPDX-License-Identifier: GPL-2.0
  2. *
  3. * Copyright (C) 2016 Robert Jarzmik <robert.jarzmik@free.fr>
  4. */
  5. #ifndef __SOUND_AC97_CODEC2_H
  6. #define __SOUND_AC97_CODEC2_H
  7. #include <linux/device.h>
  8. #define AC97_ID(vendor_id1, vendor_id2) \
  9. ((((vendor_id1) & 0xffff) << 16) | ((vendor_id2) & 0xffff))
  10. #define AC97_DRIVER_ID(vendor_id1, vendor_id2, mask_id1, mask_id2, _data) \
  11. { .id = (((vendor_id1) & 0xffff) << 16) | ((vendor_id2) & 0xffff), \
  12. .mask = (((mask_id1) & 0xffff) << 16) | ((mask_id2) & 0xffff), \
  13. .data = (_data) }
  14. struct ac97_controller;
  15. struct clk;
  16. /**
  17. * struct ac97_id - matches a codec device and driver on an ac97 bus
  18. * @id: The significant bits if the codec vendor ID1 and ID2
  19. * @mask: Bitmask specifying which bits of the id field are significant when
  20. * matching. A driver binds to a device when :
  21. * ((vendorID1 << 8 | vendorID2) & (mask_id1 << 8 | mask_id2)) == id.
  22. * @data: Private data used by the driver.
  23. */
  24. struct ac97_id {
  25. unsigned int id;
  26. unsigned int mask;
  27. void *data;
  28. };
  29. /**
  30. * ac97_codec_device - a ac97 codec
  31. * @dev: the core device
  32. * @vendor_id: the vendor_id of the codec, as sensed on the AC-link
  33. * @num: the codec number, 0 is primary, 1 is first slave, etc ...
  34. * @clk: the clock BIT_CLK provided by the codec
  35. * @ac97_ctrl: ac97 digital controller on the same AC-link
  36. *
  37. * This is the device instantiated for each codec living on a AC-link. There are
  38. * normally 0 to 4 codec devices per AC-link, and all of them are controlled by
  39. * an AC97 digital controller.
  40. */
  41. struct ac97_codec_device {
  42. struct device dev;
  43. unsigned int vendor_id;
  44. unsigned int num;
  45. struct clk *clk;
  46. struct ac97_controller *ac97_ctrl;
  47. };
  48. /**
  49. * ac97_codec_driver - a ac97 codec driver
  50. * @driver: the device driver structure
  51. * @probe: the function called when a ac97_codec_device is matched
  52. * @remove: the function called when the device is unbound/removed
  53. * @shutdown: shutdown function (might be NULL)
  54. * @id_table: ac97 vendor_id match table, { } member terminated
  55. */
  56. struct ac97_codec_driver {
  57. struct device_driver driver;
  58. int (*probe)(struct ac97_codec_device *);
  59. int (*remove)(struct ac97_codec_device *);
  60. void (*shutdown)(struct ac97_codec_device *);
  61. const struct ac97_id *id_table;
  62. };
  63. static inline struct ac97_codec_device *to_ac97_device(struct device *d)
  64. {
  65. return container_of(d, struct ac97_codec_device, dev);
  66. }
  67. static inline struct ac97_codec_driver *to_ac97_driver(struct device_driver *d)
  68. {
  69. return container_of(d, struct ac97_codec_driver, driver);
  70. }
  71. #if IS_ENABLED(CONFIG_AC97_BUS_NEW)
  72. int snd_ac97_codec_driver_register(struct ac97_codec_driver *drv);
  73. void snd_ac97_codec_driver_unregister(struct ac97_codec_driver *drv);
  74. #else
  75. static inline int
  76. snd_ac97_codec_driver_register(struct ac97_codec_driver *drv)
  77. {
  78. return 0;
  79. }
  80. static inline void
  81. snd_ac97_codec_driver_unregister(struct ac97_codec_driver *drv)
  82. {
  83. }
  84. #endif
  85. static inline struct device *
  86. ac97_codec_dev2dev(struct ac97_codec_device *adev)
  87. {
  88. return &adev->dev;
  89. }
  90. static inline void *ac97_get_drvdata(struct ac97_codec_device *adev)
  91. {
  92. return dev_get_drvdata(ac97_codec_dev2dev(adev));
  93. }
  94. static inline void ac97_set_drvdata(struct ac97_codec_device *adev,
  95. void *data)
  96. {
  97. dev_set_drvdata(ac97_codec_dev2dev(adev), data);
  98. }
  99. void *snd_ac97_codec_get_platdata(const struct ac97_codec_device *adev);
  100. #endif