xref: /OK3568_Linux_fs/kernel/include/sound/info.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-or-later */
2*4882a593Smuzhiyun #ifndef __SOUND_INFO_H
3*4882a593Smuzhiyun #define __SOUND_INFO_H
4*4882a593Smuzhiyun 
5*4882a593Smuzhiyun /*
6*4882a593Smuzhiyun  *  Header file for info interface
7*4882a593Smuzhiyun  *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
8*4882a593Smuzhiyun  */
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun #include <linux/poll.h>
11*4882a593Smuzhiyun #include <linux/seq_file.h>
12*4882a593Smuzhiyun #include <linux/android_kabi.h>
13*4882a593Smuzhiyun #include <sound/core.h>
14*4882a593Smuzhiyun 
15*4882a593Smuzhiyun /* buffer for information */
16*4882a593Smuzhiyun struct snd_info_buffer {
17*4882a593Smuzhiyun 	char *buffer;		/* pointer to begin of buffer */
18*4882a593Smuzhiyun 	unsigned int curr;	/* current position in buffer */
19*4882a593Smuzhiyun 	unsigned int size;	/* current size */
20*4882a593Smuzhiyun 	unsigned int len;	/* total length of buffer */
21*4882a593Smuzhiyun 	int stop;		/* stop flag */
22*4882a593Smuzhiyun 	int error;		/* error code */
23*4882a593Smuzhiyun };
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun #define SNDRV_INFO_CONTENT_TEXT		0
26*4882a593Smuzhiyun #define SNDRV_INFO_CONTENT_DATA		1
27*4882a593Smuzhiyun 
28*4882a593Smuzhiyun struct snd_info_entry;
29*4882a593Smuzhiyun 
30*4882a593Smuzhiyun struct snd_info_entry_text {
31*4882a593Smuzhiyun 	void (*read)(struct snd_info_entry *entry,
32*4882a593Smuzhiyun 		     struct snd_info_buffer *buffer);
33*4882a593Smuzhiyun 	void (*write)(struct snd_info_entry *entry,
34*4882a593Smuzhiyun 		      struct snd_info_buffer *buffer);
35*4882a593Smuzhiyun };
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun struct snd_info_entry_ops {
38*4882a593Smuzhiyun 	int (*open)(struct snd_info_entry *entry,
39*4882a593Smuzhiyun 		    unsigned short mode, void **file_private_data);
40*4882a593Smuzhiyun 	int (*release)(struct snd_info_entry *entry,
41*4882a593Smuzhiyun 		       unsigned short mode, void *file_private_data);
42*4882a593Smuzhiyun 	ssize_t (*read)(struct snd_info_entry *entry, void *file_private_data,
43*4882a593Smuzhiyun 			struct file *file, char __user *buf,
44*4882a593Smuzhiyun 			size_t count, loff_t pos);
45*4882a593Smuzhiyun 	ssize_t (*write)(struct snd_info_entry *entry, void *file_private_data,
46*4882a593Smuzhiyun 			 struct file *file, const char __user *buf,
47*4882a593Smuzhiyun 			 size_t count, loff_t pos);
48*4882a593Smuzhiyun 	loff_t (*llseek)(struct snd_info_entry *entry,
49*4882a593Smuzhiyun 			 void *file_private_data, struct file *file,
50*4882a593Smuzhiyun 			 loff_t offset, int orig);
51*4882a593Smuzhiyun 	__poll_t (*poll)(struct snd_info_entry *entry,
52*4882a593Smuzhiyun 			     void *file_private_data, struct file *file,
53*4882a593Smuzhiyun 			     poll_table *wait);
54*4882a593Smuzhiyun 	int (*ioctl)(struct snd_info_entry *entry, void *file_private_data,
55*4882a593Smuzhiyun 		     struct file *file, unsigned int cmd, unsigned long arg);
56*4882a593Smuzhiyun 	int (*mmap)(struct snd_info_entry *entry, void *file_private_data,
57*4882a593Smuzhiyun 		    struct inode *inode, struct file *file,
58*4882a593Smuzhiyun 		    struct vm_area_struct *vma);
59*4882a593Smuzhiyun 
60*4882a593Smuzhiyun 	ANDROID_KABI_RESERVE(1);
61*4882a593Smuzhiyun };
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun struct snd_info_entry {
64*4882a593Smuzhiyun 	const char *name;
65*4882a593Smuzhiyun 	umode_t mode;
66*4882a593Smuzhiyun 	long size;
67*4882a593Smuzhiyun 	unsigned short content;
68*4882a593Smuzhiyun 	union {
69*4882a593Smuzhiyun 		struct snd_info_entry_text text;
70*4882a593Smuzhiyun 		const struct snd_info_entry_ops *ops;
71*4882a593Smuzhiyun 	} c;
72*4882a593Smuzhiyun 	struct snd_info_entry *parent;
73*4882a593Smuzhiyun 	struct module *module;
74*4882a593Smuzhiyun 	void *private_data;
75*4882a593Smuzhiyun 	void (*private_free)(struct snd_info_entry *entry);
76*4882a593Smuzhiyun 	struct proc_dir_entry *p;
77*4882a593Smuzhiyun 	struct mutex access;
78*4882a593Smuzhiyun 	struct list_head children;
79*4882a593Smuzhiyun 	struct list_head list;
80*4882a593Smuzhiyun 
81*4882a593Smuzhiyun 	ANDROID_KABI_RESERVE(1);
82*4882a593Smuzhiyun };
83*4882a593Smuzhiyun 
84*4882a593Smuzhiyun #if defined(CONFIG_SND_OSSEMUL) && defined(CONFIG_SND_PROC_FS)
85*4882a593Smuzhiyun int snd_info_minor_register(void);
86*4882a593Smuzhiyun #else
87*4882a593Smuzhiyun #define snd_info_minor_register()	0
88*4882a593Smuzhiyun #endif
89*4882a593Smuzhiyun 
90*4882a593Smuzhiyun 
91*4882a593Smuzhiyun #ifdef CONFIG_SND_PROC_FS
92*4882a593Smuzhiyun 
93*4882a593Smuzhiyun extern struct snd_info_entry *snd_seq_root;
94*4882a593Smuzhiyun #ifdef CONFIG_SND_OSSEMUL
95*4882a593Smuzhiyun extern struct snd_info_entry *snd_oss_root;
96*4882a593Smuzhiyun void snd_card_info_read_oss(struct snd_info_buffer *buffer);
97*4882a593Smuzhiyun #else
98*4882a593Smuzhiyun #define snd_oss_root NULL
snd_card_info_read_oss(struct snd_info_buffer * buffer)99*4882a593Smuzhiyun static inline void snd_card_info_read_oss(struct snd_info_buffer *buffer) {}
100*4882a593Smuzhiyun #endif
101*4882a593Smuzhiyun 
102*4882a593Smuzhiyun /**
103*4882a593Smuzhiyun  * snd_iprintf - printf on the procfs buffer
104*4882a593Smuzhiyun  * @buf: the procfs buffer
105*4882a593Smuzhiyun  * @fmt: the printf format
106*4882a593Smuzhiyun  *
107*4882a593Smuzhiyun  * Outputs the string on the procfs buffer just like printf().
108*4882a593Smuzhiyun  *
109*4882a593Smuzhiyun  * Return: zero for success, or a negative error code.
110*4882a593Smuzhiyun  */
111*4882a593Smuzhiyun #define snd_iprintf(buf, fmt, args...) \
112*4882a593Smuzhiyun 	seq_printf((struct seq_file *)(buf)->buffer, fmt, ##args)
113*4882a593Smuzhiyun 
114*4882a593Smuzhiyun int snd_info_init(void);
115*4882a593Smuzhiyun int snd_info_done(void);
116*4882a593Smuzhiyun 
117*4882a593Smuzhiyun int snd_info_get_line(struct snd_info_buffer *buffer, char *line, int len);
118*4882a593Smuzhiyun const char *snd_info_get_str(char *dest, const char *src, int len);
119*4882a593Smuzhiyun struct snd_info_entry *snd_info_create_module_entry(struct module *module,
120*4882a593Smuzhiyun 					       const char *name,
121*4882a593Smuzhiyun 					       struct snd_info_entry *parent);
122*4882a593Smuzhiyun struct snd_info_entry *snd_info_create_card_entry(struct snd_card *card,
123*4882a593Smuzhiyun 					     const char *name,
124*4882a593Smuzhiyun 					     struct snd_info_entry *parent);
125*4882a593Smuzhiyun void snd_info_free_entry(struct snd_info_entry *entry);
126*4882a593Smuzhiyun int snd_info_store_text(struct snd_info_entry *entry);
127*4882a593Smuzhiyun int snd_info_restore_text(struct snd_info_entry *entry);
128*4882a593Smuzhiyun 
129*4882a593Smuzhiyun int snd_info_card_create(struct snd_card *card);
130*4882a593Smuzhiyun int snd_info_card_register(struct snd_card *card);
131*4882a593Smuzhiyun int snd_info_card_free(struct snd_card *card);
132*4882a593Smuzhiyun void snd_info_card_disconnect(struct snd_card *card);
133*4882a593Smuzhiyun void snd_info_card_id_change(struct snd_card *card);
134*4882a593Smuzhiyun int snd_info_register(struct snd_info_entry *entry);
135*4882a593Smuzhiyun 
136*4882a593Smuzhiyun /* for card drivers */
snd_card_proc_new(struct snd_card * card,const char * name,struct snd_info_entry ** entryp)137*4882a593Smuzhiyun static inline int snd_card_proc_new(struct snd_card *card, const char *name,
138*4882a593Smuzhiyun 				    struct snd_info_entry **entryp)
139*4882a593Smuzhiyun {
140*4882a593Smuzhiyun 	*entryp = snd_info_create_card_entry(card, name, card->proc_root);
141*4882a593Smuzhiyun 	return *entryp ? 0 : -ENOMEM;
142*4882a593Smuzhiyun }
143*4882a593Smuzhiyun 
snd_info_set_text_ops(struct snd_info_entry * entry,void * private_data,void (* read)(struct snd_info_entry *,struct snd_info_buffer *))144*4882a593Smuzhiyun static inline void snd_info_set_text_ops(struct snd_info_entry *entry,
145*4882a593Smuzhiyun 	void *private_data,
146*4882a593Smuzhiyun 	void (*read)(struct snd_info_entry *, struct snd_info_buffer *))
147*4882a593Smuzhiyun {
148*4882a593Smuzhiyun 	entry->private_data = private_data;
149*4882a593Smuzhiyun 	entry->c.text.read = read;
150*4882a593Smuzhiyun }
151*4882a593Smuzhiyun 
152*4882a593Smuzhiyun int snd_card_rw_proc_new(struct snd_card *card, const char *name,
153*4882a593Smuzhiyun 			 void *private_data,
154*4882a593Smuzhiyun 			 void (*read)(struct snd_info_entry *,
155*4882a593Smuzhiyun 				      struct snd_info_buffer *),
156*4882a593Smuzhiyun 			 void (*write)(struct snd_info_entry *entry,
157*4882a593Smuzhiyun 				       struct snd_info_buffer *buffer));
158*4882a593Smuzhiyun 
159*4882a593Smuzhiyun int snd_info_check_reserved_words(const char *str);
160*4882a593Smuzhiyun 
161*4882a593Smuzhiyun #else
162*4882a593Smuzhiyun 
163*4882a593Smuzhiyun #define snd_seq_root NULL
164*4882a593Smuzhiyun #define snd_oss_root NULL
165*4882a593Smuzhiyun 
snd_iprintf(struct snd_info_buffer * buffer,char * fmt,...)166*4882a593Smuzhiyun static inline int snd_iprintf(struct snd_info_buffer *buffer, char *fmt, ...) { return 0; }
snd_info_init(void)167*4882a593Smuzhiyun static inline int snd_info_init(void) { return 0; }
snd_info_done(void)168*4882a593Smuzhiyun static inline int snd_info_done(void) { return 0; }
169*4882a593Smuzhiyun 
snd_info_get_line(struct snd_info_buffer * buffer,char * line,int len)170*4882a593Smuzhiyun static inline int snd_info_get_line(struct snd_info_buffer *buffer, char *line, int len) { return 0; }
snd_info_get_str(char * dest,char * src,int len)171*4882a593Smuzhiyun static inline char *snd_info_get_str(char *dest, char *src, int len) { return NULL; }
snd_info_create_module_entry(struct module * module,const char * name,struct snd_info_entry * parent)172*4882a593Smuzhiyun static inline struct snd_info_entry *snd_info_create_module_entry(struct module *module, const char *name, struct snd_info_entry *parent) { return NULL; }
snd_info_create_card_entry(struct snd_card * card,const char * name,struct snd_info_entry * parent)173*4882a593Smuzhiyun static inline struct snd_info_entry *snd_info_create_card_entry(struct snd_card *card, const char *name, struct snd_info_entry *parent) { return NULL; }
snd_info_free_entry(struct snd_info_entry * entry)174*4882a593Smuzhiyun static inline void snd_info_free_entry(struct snd_info_entry *entry) { ; }
175*4882a593Smuzhiyun 
snd_info_card_create(struct snd_card * card)176*4882a593Smuzhiyun static inline int snd_info_card_create(struct snd_card *card) { return 0; }
snd_info_card_register(struct snd_card * card)177*4882a593Smuzhiyun static inline int snd_info_card_register(struct snd_card *card) { return 0; }
snd_info_card_free(struct snd_card * card)178*4882a593Smuzhiyun static inline int snd_info_card_free(struct snd_card *card) { return 0; }
snd_info_card_disconnect(struct snd_card * card)179*4882a593Smuzhiyun static inline void snd_info_card_disconnect(struct snd_card *card) { }
snd_info_card_id_change(struct snd_card * card)180*4882a593Smuzhiyun static inline void snd_info_card_id_change(struct snd_card *card) { }
snd_info_register(struct snd_info_entry * entry)181*4882a593Smuzhiyun static inline int snd_info_register(struct snd_info_entry *entry) { return 0; }
182*4882a593Smuzhiyun 
snd_card_proc_new(struct snd_card * card,const char * name,struct snd_info_entry ** entryp)183*4882a593Smuzhiyun static inline int snd_card_proc_new(struct snd_card *card, const char *name,
184*4882a593Smuzhiyun 				    struct snd_info_entry **entryp) { return -EINVAL; }
snd_info_set_text_ops(struct snd_info_entry * entry,void * private_data,void (* read)(struct snd_info_entry *,struct snd_info_buffer *))185*4882a593Smuzhiyun static inline void snd_info_set_text_ops(struct snd_info_entry *entry __attribute__((unused)),
186*4882a593Smuzhiyun 					 void *private_data,
187*4882a593Smuzhiyun 					 void (*read)(struct snd_info_entry *, struct snd_info_buffer *)) {}
snd_card_rw_proc_new(struct snd_card * card,const char * name,void * private_data,void (* read)(struct snd_info_entry *,struct snd_info_buffer *),void (* write)(struct snd_info_entry * entry,struct snd_info_buffer * buffer))188*4882a593Smuzhiyun static inline int snd_card_rw_proc_new(struct snd_card *card, const char *name,
189*4882a593Smuzhiyun 				       void *private_data,
190*4882a593Smuzhiyun 				       void (*read)(struct snd_info_entry *,
191*4882a593Smuzhiyun 						    struct snd_info_buffer *),
192*4882a593Smuzhiyun 				       void (*write)(struct snd_info_entry *entry,
193*4882a593Smuzhiyun 						     struct snd_info_buffer *buffer))
194*4882a593Smuzhiyun {
195*4882a593Smuzhiyun 	return 0;
196*4882a593Smuzhiyun }
snd_info_check_reserved_words(const char * str)197*4882a593Smuzhiyun static inline int snd_info_check_reserved_words(const char *str) { return 1; }
198*4882a593Smuzhiyun 
199*4882a593Smuzhiyun #endif
200*4882a593Smuzhiyun 
201*4882a593Smuzhiyun /**
202*4882a593Smuzhiyun  * snd_card_ro_proc_new - Create a read-only text proc file entry for the card
203*4882a593Smuzhiyun  * @card: the card instance
204*4882a593Smuzhiyun  * @name: the file name
205*4882a593Smuzhiyun  * @private_data: the arbitrary private data
206*4882a593Smuzhiyun  * @read: the read callback
207*4882a593Smuzhiyun  *
208*4882a593Smuzhiyun  * This proc file entry will be registered via snd_card_register() call, and
209*4882a593Smuzhiyun  * it will be removed automatically at the card removal, too.
210*4882a593Smuzhiyun  */
211*4882a593Smuzhiyun static inline int
snd_card_ro_proc_new(struct snd_card * card,const char * name,void * private_data,void (* read)(struct snd_info_entry *,struct snd_info_buffer *))212*4882a593Smuzhiyun snd_card_ro_proc_new(struct snd_card *card, const char *name,
213*4882a593Smuzhiyun 		     void *private_data,
214*4882a593Smuzhiyun 		     void (*read)(struct snd_info_entry *,
215*4882a593Smuzhiyun 				  struct snd_info_buffer *))
216*4882a593Smuzhiyun {
217*4882a593Smuzhiyun 	return snd_card_rw_proc_new(card, name, private_data, read, NULL);
218*4882a593Smuzhiyun }
219*4882a593Smuzhiyun 
220*4882a593Smuzhiyun /*
221*4882a593Smuzhiyun  * OSS info part
222*4882a593Smuzhiyun  */
223*4882a593Smuzhiyun 
224*4882a593Smuzhiyun #if defined(CONFIG_SND_OSSEMUL) && defined(CONFIG_SND_PROC_FS)
225*4882a593Smuzhiyun 
226*4882a593Smuzhiyun #define SNDRV_OSS_INFO_DEV_AUDIO	0
227*4882a593Smuzhiyun #define SNDRV_OSS_INFO_DEV_SYNTH	1
228*4882a593Smuzhiyun #define SNDRV_OSS_INFO_DEV_MIDI		2
229*4882a593Smuzhiyun #define SNDRV_OSS_INFO_DEV_TIMERS	4
230*4882a593Smuzhiyun #define SNDRV_OSS_INFO_DEV_MIXERS	5
231*4882a593Smuzhiyun 
232*4882a593Smuzhiyun #define SNDRV_OSS_INFO_DEV_COUNT	6
233*4882a593Smuzhiyun 
234*4882a593Smuzhiyun int snd_oss_info_register(int dev, int num, char *string);
235*4882a593Smuzhiyun #define snd_oss_info_unregister(dev, num) snd_oss_info_register(dev, num, NULL)
236*4882a593Smuzhiyun 
237*4882a593Smuzhiyun #endif /* CONFIG_SND_OSSEMUL && CONFIG_SND_PROC_FS */
238*4882a593Smuzhiyun 
239*4882a593Smuzhiyun #endif /* __SOUND_INFO_H */
240