Johannes Berg | f3d9478 | 2006-06-21 15:42:43 +0200 | [diff] [blame] | 1 | /* |
| 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> |
| 9 | #include "snd-aoa-alsa.h" |
| 10 | |
| 11 | static int index = -1; |
| 12 | module_param(index, int, 0444); |
| 13 | MODULE_PARM_DESC(index, "index for AOA sound card."); |
| 14 | |
| 15 | static struct aoa_card *aoa_card; |
| 16 | |
| 17 | int aoa_alsa_init(char *name, struct module *mod) |
| 18 | { |
| 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 | |
| 26 | alsa_card = snd_card_new(index, name, mod, sizeof(struct aoa_card)); |
| 27 | if (!alsa_card) |
| 28 | return -ENOMEM; |
| 29 | aoa_card = alsa_card->private_data; |
| 30 | aoa_card->alsa_card = alsa_card; |
| 31 | strlcpy(alsa_card->driver, "AppleOnbdAudio", sizeof(alsa_card->driver)); |
| 32 | strlcpy(alsa_card->shortname, name, sizeof(alsa_card->shortname)); |
| 33 | strlcpy(alsa_card->longname, name, sizeof(alsa_card->longname)); |
| 34 | strlcpy(alsa_card->mixername, name, sizeof(alsa_card->mixername)); |
| 35 | err = snd_card_register(aoa_card->alsa_card); |
| 36 | if (err < 0) { |
| 37 | printk(KERN_ERR "snd-aoa: couldn't register alsa card\n"); |
| 38 | snd_card_free(aoa_card->alsa_card); |
| 39 | aoa_card = NULL; |
| 40 | return err; |
| 41 | } |
| 42 | return 0; |
| 43 | } |
| 44 | |
| 45 | struct snd_card *aoa_get_card(void) |
| 46 | { |
| 47 | if (aoa_card) |
| 48 | return aoa_card->alsa_card; |
| 49 | return NULL; |
| 50 | } |
| 51 | EXPORT_SYMBOL_GPL(aoa_get_card); |
| 52 | |
| 53 | void aoa_alsa_cleanup(void) |
| 54 | { |
| 55 | if (aoa_card) { |
| 56 | snd_card_free(aoa_card->alsa_card); |
| 57 | aoa_card = NULL; |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | int aoa_snd_device_new(snd_device_type_t type, |
| 62 | void * device_data, struct snd_device_ops * ops) |
| 63 | { |
| 64 | struct snd_card *card = aoa_get_card(); |
| 65 | int err; |
| 66 | |
| 67 | if (!card) return -ENOMEM; |
| 68 | |
| 69 | err = snd_device_new(card, type, device_data, ops); |
| 70 | if (err) { |
| 71 | printk(KERN_ERR "snd-aoa: failed to create snd device (%d)\n", err); |
| 72 | return err; |
| 73 | } |
| 74 | err = snd_device_register(card, device_data); |
| 75 | if (err) { |
| 76 | printk(KERN_ERR "snd-aoa: failed to register " |
| 77 | "snd device (%d)\n", err); |
| 78 | printk(KERN_ERR "snd-aoa: have you forgotten the " |
| 79 | "dev_register callback?\n"); |
| 80 | snd_device_free(card, device_data); |
| 81 | } |
| 82 | return err; |
| 83 | } |
| 84 | EXPORT_SYMBOL_GPL(aoa_snd_device_new); |
| 85 | |
| 86 | int aoa_snd_ctl_add(struct snd_kcontrol* control) |
| 87 | { |
| 88 | int err; |
| 89 | |
| 90 | if (!aoa_card) return -ENODEV; |
| 91 | |
| 92 | err = snd_ctl_add(aoa_card->alsa_card, control); |
| 93 | if (err) |
| 94 | printk(KERN_ERR "snd-aoa: failed to add alsa control (%d)\n", |
| 95 | err); |
| 96 | return err; |
| 97 | } |
| 98 | EXPORT_SYMBOL_GPL(aoa_snd_ctl_add); |