2 * Apple Onboard Audio driver core
4 * Copyright 2006 Johannes Berg <johannes@sipsolutions.net>
6 * GPL v2, can be found in COPYING.
9 #include <linux/init.h>
10 #include <linux/module.h>
11 #include <linux/list.h>
13 #include "snd-aoa-alsa.h"
15 MODULE_DESCRIPTION("Apple Onboard Audio Sound Driver");
16 MODULE_AUTHOR("Johannes Berg <johannes@sipsolutions.net>");
17 MODULE_LICENSE("GPL");
19 /* We allow only one fabric. This simplifies things,
20 * and more don't really make that much sense */
21 static struct aoa_fabric
*fabric
;
22 static LIST_HEAD(codec_list
);
24 static int attach_codec_to_fabric(struct aoa_codec
*c
)
28 if (!try_module_get(c
->owner
))
30 /* found_codec has to be assigned */
32 if (fabric
->found_codec
)
33 err
= fabric
->found_codec(c
);
36 printk(KERN_ERR
"snd-aoa: fabric didn't like codec %s\n",
46 printk(KERN_ERR
"snd-aoa: codec %s didn't init\n", c
->name
);
48 if (fabric
->remove_codec
)
49 fabric
->remove_codec(c
);
53 if (fabric
->attached_codec
)
54 fabric
->attached_codec(c
);
58 int aoa_codec_register(struct aoa_codec
*codec
)
62 /* if there's a fabric already, we can tell if we
63 * will want to have this codec, so propagate error
64 * through. Otherwise, this will happen later... */
66 err
= attach_codec_to_fabric(codec
);
68 list_add(&codec
->list
, &codec_list
);
71 EXPORT_SYMBOL_GPL(aoa_codec_register
);
73 void aoa_codec_unregister(struct aoa_codec
*codec
)
75 list_del(&codec
->list
);
76 if (codec
->fabric
&& codec
->exit
)
78 if (fabric
&& fabric
->remove_codec
)
79 fabric
->remove_codec(codec
);
81 module_put(codec
->owner
);
83 EXPORT_SYMBOL_GPL(aoa_codec_unregister
);
85 int aoa_fabric_register(struct aoa_fabric
*new_fabric
)
90 /* allow querying for presence of fabric
91 * (i.e. do this test first!) */
92 if (new_fabric
== fabric
) {
101 err
= aoa_alsa_init(new_fabric
->name
, new_fabric
->owner
);
108 list_for_each_entry(c
, &codec_list
, list
) {
109 if (c
->fabric
!= fabric
)
110 attach_codec_to_fabric(c
);
114 EXPORT_SYMBOL_GPL(aoa_fabric_register
);
116 void aoa_fabric_unregister(struct aoa_fabric
*old_fabric
)
120 if (fabric
!= old_fabric
)
123 list_for_each_entry(c
, &codec_list
, list
) {
125 aoa_fabric_unlink_codec(c
);
132 EXPORT_SYMBOL_GPL(aoa_fabric_unregister
);
134 void aoa_fabric_unlink_codec(struct aoa_codec
*codec
)
136 if (!codec
->fabric
) {
137 printk(KERN_ERR
"snd-aoa: fabric unassigned "
138 "in aoa_fabric_unlink_codec\n");
144 if (codec
->fabric
->remove_codec
)
145 codec
->fabric
->remove_codec(codec
);
146 codec
->fabric
= NULL
;
147 module_put(codec
->owner
);
149 EXPORT_SYMBOL_GPL(aoa_fabric_unlink_codec
);
151 static int __init
aoa_init(void)
156 static void __exit
aoa_exit(void)
161 module_init(aoa_init
);
162 module_exit(aoa_exit
);