controller.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright (C) 2016 Robert Jarzmik <robert.jarzmik@free.fr>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. */
  8. #ifndef AC97_CONTROLLER_H
  9. #define AC97_CONTROLLER_H
  10. #include <linux/device.h>
  11. #include <linux/list.h>
  12. #define AC97_BUS_MAX_CODECS 4
  13. #define AC97_SLOTS_AVAILABLE_ALL 0xf
  14. struct ac97_controller_ops;
  15. /**
  16. * struct ac97_controller - The AC97 controller of the AC-Link
  17. * @ops: the AC97 operations.
  18. * @controllers: linked list of all existing controllers.
  19. * @adap: the shell device ac97-%d, ie. ac97 adapter
  20. * @nr: the number of the shell device
  21. * @slots_available: the mask of accessible/scanable codecs.
  22. * @parent: the device providing the AC97 controller.
  23. * @codecs: the 4 possible AC97 codecs (NULL if none found).
  24. * @codecs_pdata: platform_data for each codec (NULL if no pdata).
  25. *
  26. * This structure is internal to AC97 bus, and should not be used by the
  27. * controllers themselves, excepting for using @dev.
  28. */
  29. struct ac97_controller {
  30. const struct ac97_controller_ops *ops;
  31. struct list_head controllers;
  32. struct device adap;
  33. int nr;
  34. unsigned short slots_available;
  35. struct device *parent;
  36. struct ac97_codec_device *codecs[AC97_BUS_MAX_CODECS];
  37. void *codecs_pdata[AC97_BUS_MAX_CODECS];
  38. };
  39. /**
  40. * struct ac97_controller_ops - The AC97 operations
  41. * @reset: Cold reset of the AC97 AC-Link.
  42. * @warm_reset: Warm reset of the AC97 AC-Link.
  43. * @read: Read of a single AC97 register.
  44. * Returns the register value or a negative error code.
  45. * @write: Write of a single AC97 register.
  46. *
  47. * These are the basic operation an AC97 controller must provide for an AC97
  48. * access functions. Amongst these, all but the last 2 are mandatory.
  49. * The slot number is also known as the AC97 codec number, between 0 and 3.
  50. */
  51. struct ac97_controller_ops {
  52. void (*reset)(struct ac97_controller *adrv);
  53. void (*warm_reset)(struct ac97_controller *adrv);
  54. int (*write)(struct ac97_controller *adrv, int slot,
  55. unsigned short reg, unsigned short val);
  56. int (*read)(struct ac97_controller *adrv, int slot, unsigned short reg);
  57. };
  58. #if IS_ENABLED(CONFIG_AC97_BUS_NEW)
  59. struct ac97_controller *snd_ac97_controller_register(
  60. const struct ac97_controller_ops *ops, struct device *dev,
  61. unsigned short slots_available, void **codecs_pdata);
  62. void snd_ac97_controller_unregister(struct ac97_controller *ac97_ctrl);
  63. #else
  64. static inline struct ac97_controller *
  65. snd_ac97_controller_register(const struct ac97_controller_ops *ops,
  66. struct device *dev,
  67. unsigned short slots_available,
  68. void **codecs_pdata)
  69. {
  70. return ERR_PTR(-ENODEV);
  71. }
  72. static inline void
  73. snd_ac97_controller_unregister(struct ac97_controller *ac97_ctrl)
  74. {
  75. }
  76. #endif
  77. #endif