xref: /illumos-gate/usr/src/uts/common/io/audio/ac97/ac97_impl.h (revision c7402f0767d7a0360fabd0bd449c6baf9b282074)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_AC97_IMPL_H
28 #define	_SYS_AC97_IMPL_H
29 
30 typedef struct ac97_ctrl ac97_ctrl_t;
31 typedef void (*ac97_set_t)(ac97_ctrl_t *, uint64_t);
32 
33 /*
34  * Per control state
35  */
36 struct ac97_ctrl {
37 	list_node_t	actrl_linkage;  /* For private cntrls list */
38 	struct ac97	*actrl_ac97;
39 	int		actrl_bits;	/* Port width */
40 	uint32_t	actrl_type;	/* control type */
41 	const char	*actrl_name;	/* control's name */
42 	audio_ctrl_t	*actrl_ctrl;    /* control framework handle */
43 	ac97_set_t	actrl_write_fn; /* control write function */
44 	uint64_t	actrl_minval;   /* MIN value for control */
45 	uint64_t	actrl_maxval;   /* MAX value for control */
46 	uint64_t	actrl_value;    /* current value in port */
47 	uint64_t	actrl_initval;  /* initial value in port */
48 	uint16_t	actrl_muteable; /* if muteable, bits to do it */
49 };
50 
51 /*
52  * Function Type used on controls that are optional
53  * This will return non-zero if the control should be
54  * installed and configured.
55  */
56 typedef int (*cp_probe_t)(ac97_t *ac);
57 
58 
59 /*
60  * This is used to enumerate and probe all controls that are
61  * supported and configurable on AC97 hardware
62  */
63 typedef struct ac97_ctrl_probe {
64 	const char	*cp_name;	/* name of control */
65 	uint64_t	cp_initval;	/* Initial value for control */
66 	uint64_t	cp_minval;	/* MIN value for control */
67 	uint64_t	cp_maxval;	/* MAX value for control */
68 	uint32_t	cp_type;	/* Type of control */
69 	uint32_t	cp_flags;	/* control type flags */
70 	uint16_t	cp_muteable;	/* Mute bit mask */
71 	ac97_set_t	cp_write_fn;	/* control write function */
72 	cp_probe_t	cp_probe;	/* Probe if control exists */
73 	int		cp_bits;	/* Bits for volume controls */
74 	const char	**cp_enum;	/* Enumeration value */
75 } ac97_ctrl_probe_t;
76 
77 typedef struct ac97_hooks {
78 	void		(*h_detach)(ac97_t *);
79 	void		(*h_reset)(ac97_t *);
80 	void		(*h_restore)(ac97_t *);
81 } ac97_hooks_t;
82 
83 /*
84  * These are the flags for most of our controls
85  */
86 #define	AC97_RW		(AUDIO_CTRL_FLAG_READABLE | AUDIO_CTRL_FLAG_WRITEABLE)
87 #define	AC97_FLAGS	(AC97_RW | AUDIO_CTRL_FLAG_POLL)
88 
89 void ac97_wr(ac97_t *, uint8_t, uint16_t);
90 uint16_t ac97_rd(ac97_t *, uint8_t);
91 void ac97_clr(ac97_t *, uint8_t, uint16_t);
92 void ac97_set(ac97_t *, uint8_t, uint16_t);
93 void ac97_alloc_control(ac97_t *, ac97_ctrl_probe_t *);
94 void ac97_free_control(ac97_ctrl_t *);
95 ac97_ctrl_t *ac97_control_find(ac97_t *, const char *);
96 uint16_t ac97_val_scale(int left, int right, int bits);
97 uint16_t ac97_mono_scale(int val, int bits);
98 audio_dev_t *ac97_get_dev(ac97_t *);
99 int ac97_get_prop(ac97_t *, char *, int);
100 
101 /* Codec specific initializations */
102 
103 void ad1981a_init(ac97_t *);
104 void ad1981b_init(ac97_t *);
105 
106 void alc650_init(ac97_t *);
107 void alc850_init(ac97_t *);
108 
109 void cmi9738_init(ac97_t *);
110 void cmi9739_init(ac97_t *);
111 void cmi9761_init(ac97_t *);
112 
113 #endif	/* _SYS_AC97_IMPL_H */
114