controller.h 2.6 KB

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