1 // SPDX-License-Identifier: GPL-2.0-only
3 * Apple Onboard Audio Alsa helpers
5 * Copyright 2006 Johannes Berg <johannes@sipsolutions.net>
7 #include <linux/module.h>
10 static int index
= -1;
11 module_param(index
, int, 0444);
12 MODULE_PARM_DESC(index
, "index for AOA sound card.");
14 static struct aoa_card
*aoa_card
;
16 int aoa_alsa_init(char *name
, struct module
*mod
, struct device
*dev
)
18 struct snd_card
*alsa_card
;
22 /* cannot be EEXIST due to usage in aoa_fabric_register */
25 err
= snd_card_new(dev
, index
, name
, mod
, sizeof(struct aoa_card
),
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
);
37 printk(KERN_ERR
"snd-aoa: couldn't register alsa card\n");
38 snd_card_free(aoa_card
->alsa_card
);
45 struct snd_card
*aoa_get_card(void)
48 return aoa_card
->alsa_card
;
51 EXPORT_SYMBOL_GPL(aoa_get_card
);
53 void aoa_alsa_cleanup(void)
56 snd_card_free(aoa_card
->alsa_card
);
61 int aoa_snd_device_new(enum snd_device_type type
,
62 void *device_data
, const struct snd_device_ops
*ops
)
64 struct snd_card
*card
= aoa_get_card();
67 if (!card
) return -ENOMEM
;
69 err
= snd_device_new(card
, type
, device_data
, ops
);
71 printk(KERN_ERR
"snd-aoa: failed to create snd device (%d)\n", err
);
74 err
= snd_device_register(card
, device_data
);
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
);
84 EXPORT_SYMBOL_GPL(aoa_snd_device_new
);
86 int aoa_snd_ctl_add(struct snd_kcontrol
* control
)
90 if (!aoa_card
) return -ENODEV
;
92 err
= snd_ctl_add(aoa_card
->alsa_card
, control
);
94 printk(KERN_ERR
"snd-aoa: failed to add alsa control (%d)\n",
98 EXPORT_SYMBOL_GPL(aoa_snd_ctl_add
);