1 /*
2 ac97_plugin_ad1980.c Copyright (C) 2003 Red Hat, Inc. All rights reserved.
3
4 The contents of this file are subject to the Open Software License version 1.1
5 that can be found at http://www.opensource.org/licenses/osl-1.1.txt and is
6 included herein by reference.
7
8 Alternatively, the contents of this file may be used under the
9 terms of the GNU General Public License version 2 (the "GPL") as
10 distributed in the kernel source COPYING file, in which
11 case the provisions of the GPL are applicable instead of the
12 above. If you wish to allow the use of your version of this file
13 only under the terms of the GPL and not to allow others to use
14 your version of this file under the OSL, indicate your decision
15 by deleting the provisions above and replace them with the notice
16 and other provisions required by the GPL. If you do not delete
17 the provisions above, a recipient may use your version of this
18 file under either the OSL or the GPL.
19
20 Authors: Alan Cox <alan@redhat.com>
21
22 This is an example codec plugin. This one switches the connections
23 around to match the setups some vendors use with audio switched to
24 non standard front connectors not the normal rear ones
25
26 This code primarily exists to demonstrate how to use the codec
27 interface
28
29 */
30
31 #include <linux/module.h>
32 #include <linux/init.h>
33 #include <linux/kernel.h>
34 #include <linux/ac97_codec.h>
35
36 /**
37 * ad1980_remove - codec remove callback
38 * @codec: The codec that is being removed
39 *
40 * This callback occurs when an AC97 codec is being removed. A
41 * codec remove call will not occur for a codec during that codec
42 * probe callback.
43 *
44 * Most drivers will need to lock their remove versus their
45 * use of the codec after the probe function.
46 */
47
ad1980_remove(struct ac97_codec * codec,struct ac97_driver * driver)48 static void ad1980_remove(struct ac97_codec *codec, struct ac97_driver *driver)
49 {
50 /* Nothing to do in the simple example */
51 }
52
53
54 /**
55 * ad1980_probe - codec found callback
56 * @codec: ac97 codec matching the idents
57 * @driver: ac97_driver it matched
58 *
59 * This entry point is called when a codec is found which matches
60 * the driver. At the point it is called the codec is basically
61 * operational, mixer operations have been initialised and can
62 * be overriden. Called in process context. The field driver_private
63 * is available for the driver to use to store stuff.
64 *
65 * The caller can claim the device by returning zero, or return
66 * a negative error code.
67 */
68
ad1980_probe(struct ac97_codec * codec,struct ac97_driver * driver)69 static int ad1980_probe(struct ac97_codec *codec, struct ac97_driver *driver)
70 {
71 u16 control;
72
73 #define AC97_AD_MISC 0x76
74
75 /* Switch the inputs/outputs over (from Dell code)
76 Set the ADI compatibility mode (AC97NC bit) */
77
78 control = codec->codec_read(codec, AC97_AD_MISC);
79 codec->codec_write(codec, AC97_AD_MISC, control | 0x4420);
80
81 /* We could refuse the device since we dont need to hang around,
82 but we will claim it */
83 return 0;
84 }
85
86
87 static struct ac97_driver ad1980_driver = {
88 codec_id: 0x41445370,
89 codec_mask: 0xFFFFFFFF,
90 name: "AD1980 example",
91 probe: ad1980_probe,
92 remove: __devexit_p(ad1980_remove),
93 };
94
95 /**
96 * ad1980_exit - module exit path
97 *
98 * Our module is being unloaded. At this point unregister_driver
99 * will call back our remove handler for any existing codecs. You
100 * may not unregister_driver from interrupt context or from a
101 * probe/remove callback.
102 */
103
ad1980_exit(void)104 static void ad1980_exit(void)
105 {
106 ac97_unregister_driver(&ad1980_driver);
107 }
108
109 /**
110 * ad1980_init - set up ad1980 handlers
111 *
112 * After we call the register function it will call our probe
113 * function for each existing matching device before returning to us.
114 * Any devices appearing afterwards whose id's match the codec_id
115 * will also cause the probe function to be called.
116 * You may not register_driver from interrupt context or from a
117 * probe/remove callback.
118 */
119
ad1980_init(void)120 static int ad1980_init(void)
121 {
122 return ac97_register_driver(&ad1980_driver);
123 }
124
125 MODULE_LICENSE("GPL");
126 module_init(ad1980_init);
127 module_exit(ad1980_exit);
128