blob: 0fa3855b4790e30753b7b8ea4fb29644a6e8cd1f [file] [log] [blame]
Johannes Bergf3d94782006-06-21 15:42:43 +02001/*
2 * Apple Onboard Audio Alsa helpers
3 *
4 * Copyright 2006 Johannes Berg <johannes@sipsolutions.net>
5 *
6 * GPL v2, can be found in COPYING.
7 */
8#include <linux/module.h>
Johannes Berg888dcb72008-10-23 15:47:56 +02009#include "alsa.h"
Johannes Bergf3d94782006-06-21 15:42:43 +020010
11static int index = -1;
12module_param(index, int, 0444);
13MODULE_PARM_DESC(index, "index for AOA sound card.");
14
15static struct aoa_card *aoa_card;
16
Olaf Hering61e77102006-12-07 08:24:12 +010017int aoa_alsa_init(char *name, struct module *mod, struct device *dev)
Johannes Bergf3d94782006-06-21 15:42:43 +020018{
19 struct snd_card *alsa_card;
20 int err;
21
22 if (aoa_card)
23 /* cannot be EEXIST due to usage in aoa_fabric_register */
24 return -EBUSY;
25
Takashi Iwaibd7dd772008-12-28 16:45:02 +010026 err = snd_card_create(index, name, mod, sizeof(struct aoa_card),
27 &alsa_card);
28 if (err < 0)
29 return err;
Johannes Bergf3d94782006-06-21 15:42:43 +020030 aoa_card = alsa_card->private_data;
31 aoa_card->alsa_card = alsa_card;
Olaf Hering61e77102006-12-07 08:24:12 +010032 alsa_card->dev = dev;
Johannes Bergf3d94782006-06-21 15:42:43 +020033 strlcpy(alsa_card->driver, "AppleOnbdAudio", sizeof(alsa_card->driver));
34 strlcpy(alsa_card->shortname, name, sizeof(alsa_card->shortname));
35 strlcpy(alsa_card->longname, name, sizeof(alsa_card->longname));
36 strlcpy(alsa_card->mixername, name, sizeof(alsa_card->mixername));
37 err = snd_card_register(aoa_card->alsa_card);
38 if (err < 0) {
39 printk(KERN_ERR "snd-aoa: couldn't register alsa card\n");
40 snd_card_free(aoa_card->alsa_card);
41 aoa_card = NULL;
42 return err;
43 }
44 return 0;
45}
46
47struct snd_card *aoa_get_card(void)
48{
49 if (aoa_card)
50 return aoa_card->alsa_card;
51 return NULL;
52}
53EXPORT_SYMBOL_GPL(aoa_get_card);
54
55void aoa_alsa_cleanup(void)
56{
57 if (aoa_card) {
58 snd_card_free(aoa_card->alsa_card);
59 aoa_card = NULL;
60 }
61}
62
63int aoa_snd_device_new(snd_device_type_t type,
Johannes Berg73e85fe2006-10-05 15:07:23 +020064 void * device_data, struct snd_device_ops * ops)
Johannes Bergf3d94782006-06-21 15:42:43 +020065{
66 struct snd_card *card = aoa_get_card();
67 int err;
Johannes Berg888dcb72008-10-23 15:47:56 +020068
Johannes Bergf3d94782006-06-21 15:42:43 +020069 if (!card) return -ENOMEM;
70
71 err = snd_device_new(card, type, device_data, ops);
72 if (err) {
73 printk(KERN_ERR "snd-aoa: failed to create snd device (%d)\n", err);
74 return err;
75 }
76 err = snd_device_register(card, device_data);
77 if (err) {
78 printk(KERN_ERR "snd-aoa: failed to register "
79 "snd device (%d)\n", err);
80 printk(KERN_ERR "snd-aoa: have you forgotten the "
81 "dev_register callback?\n");
82 snd_device_free(card, device_data);
83 }
84 return err;
85}
86EXPORT_SYMBOL_GPL(aoa_snd_device_new);
87
88int aoa_snd_ctl_add(struct snd_kcontrol* control)
89{
90 int err;
91
92 if (!aoa_card) return -ENODEV;
93
94 err = snd_ctl_add(aoa_card->alsa_card, control);
95 if (err)
96 printk(KERN_ERR "snd-aoa: failed to add alsa control (%d)\n",
97 err);
98 return err;
99}
100EXPORT_SYMBOL_GPL(aoa_snd_ctl_add);