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