2019-06-03 13:45:06 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2006-06-21 21:42:43 +08:00
|
|
|
/*
|
|
|
|
* Apple Onboard Audio Alsa helpers
|
|
|
|
*
|
|
|
|
* Copyright 2006 Johannes Berg <johannes@sipsolutions.net>
|
|
|
|
*/
|
|
|
|
#include <linux/module.h>
|
2008-10-23 21:47:56 +08:00
|
|
|
#include "alsa.h"
|
2006-06-21 21:42:43 +08:00
|
|
|
|
|
|
|
static int index = -1;
|
|
|
|
module_param(index, int, 0444);
|
|
|
|
MODULE_PARM_DESC(index, "index for AOA sound card.");
|
|
|
|
|
|
|
|
static struct aoa_card *aoa_card;
|
|
|
|
|
2006-12-07 15:24:12 +08:00
|
|
|
int aoa_alsa_init(char *name, struct module *mod, struct device *dev)
|
2006-06-21 21:42:43 +08:00
|
|
|
{
|
|
|
|
struct snd_card *alsa_card;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
if (aoa_card)
|
|
|
|
/* cannot be EEXIST due to usage in aoa_fabric_register */
|
|
|
|
return -EBUSY;
|
|
|
|
|
2014-01-29 21:38:59 +08:00
|
|
|
err = snd_card_new(dev, index, name, mod, sizeof(struct aoa_card),
|
|
|
|
&alsa_card);
|
2008-12-28 23:45:02 +08:00
|
|
|
if (err < 0)
|
|
|
|
return err;
|
2006-06-21 21:42:43 +08:00
|
|
|
aoa_card = alsa_card->private_data;
|
|
|
|
aoa_card->alsa_card = alsa_card;
|
ALSA: Convert strlcpy to strscpy when return value is unused
strlcpy is deprecated. see: Documentation/process/deprecated.rst
Change the calls that do not use the strlcpy return value to the
preferred strscpy.
Done with cocci script:
@@
expression e1, e2, e3;
@@
- strlcpy(
+ strscpy(
e1, e2, e3);
This cocci script leaves the instances where the return value is
used unchanged.
After this patch, sound/ has 3 uses of strlcpy() that need to be
manually inspected for conversion and changed one day.
$ git grep -w strlcpy sound/
sound/usb/card.c: len = strlcpy(card->longname, s, sizeof(card->longname));
sound/usb/mixer.c: return strlcpy(buf, p->name, buflen);
sound/usb/mixer.c: return strlcpy(buf, p->names[index], buflen);
Miscellenea:
o Remove trailing whitespace in conversion of sound/core/hwdep.c
Link: https://lore.kernel.org/lkml/CAHk-=wgfRnXz0W3D37d01q3JFkr_i_uTL=V6A6G1oUZcprmknw@mail.gmail.com/
Signed-off-by: Joe Perches <joe@perches.com>
Acked-by: Mark Brown <broonie@kernel.org>
Link: https://lore.kernel.org/r/22b393d1790bb268769d0bab7bacf0866dcb0c14.camel@perches.com
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2021-01-05 01:17:34 +08:00
|
|
|
strscpy(alsa_card->driver, "AppleOnbdAudio", sizeof(alsa_card->driver));
|
|
|
|
strscpy(alsa_card->shortname, name, sizeof(alsa_card->shortname));
|
|
|
|
strscpy(alsa_card->longname, name, sizeof(alsa_card->longname));
|
|
|
|
strscpy(alsa_card->mixername, name, sizeof(alsa_card->mixername));
|
2006-06-21 21:42:43 +08:00
|
|
|
err = snd_card_register(aoa_card->alsa_card);
|
|
|
|
if (err < 0) {
|
|
|
|
printk(KERN_ERR "snd-aoa: couldn't register alsa card\n");
|
|
|
|
snd_card_free(aoa_card->alsa_card);
|
|
|
|
aoa_card = NULL;
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct snd_card *aoa_get_card(void)
|
|
|
|
{
|
|
|
|
if (aoa_card)
|
|
|
|
return aoa_card->alsa_card;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(aoa_get_card);
|
|
|
|
|
|
|
|
void aoa_alsa_cleanup(void)
|
|
|
|
{
|
|
|
|
if (aoa_card) {
|
|
|
|
snd_card_free(aoa_card->alsa_card);
|
|
|
|
aoa_card = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-29 22:13:33 +08:00
|
|
|
int aoa_snd_device_new(enum snd_device_type type,
|
2020-01-03 16:16:27 +08:00
|
|
|
void *device_data, const struct snd_device_ops *ops)
|
2006-06-21 21:42:43 +08:00
|
|
|
{
|
|
|
|
struct snd_card *card = aoa_get_card();
|
|
|
|
int err;
|
2008-10-23 21:47:56 +08:00
|
|
|
|
2006-06-21 21:42:43 +08:00
|
|
|
if (!card) return -ENOMEM;
|
|
|
|
|
|
|
|
err = snd_device_new(card, type, device_data, ops);
|
|
|
|
if (err) {
|
|
|
|
printk(KERN_ERR "snd-aoa: failed to create snd device (%d)\n", err);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
err = snd_device_register(card, device_data);
|
|
|
|
if (err) {
|
|
|
|
printk(KERN_ERR "snd-aoa: failed to register "
|
|
|
|
"snd device (%d)\n", err);
|
|
|
|
printk(KERN_ERR "snd-aoa: have you forgotten the "
|
|
|
|
"dev_register callback?\n");
|
|
|
|
snd_device_free(card, device_data);
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(aoa_snd_device_new);
|
|
|
|
|
|
|
|
int aoa_snd_ctl_add(struct snd_kcontrol* control)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
if (!aoa_card) return -ENODEV;
|
|
|
|
|
|
|
|
err = snd_ctl_add(aoa_card->alsa_card, control);
|
|
|
|
if (err)
|
|
|
|
printk(KERN_ERR "snd-aoa: failed to add alsa control (%d)\n",
|
|
|
|
err);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(aoa_snd_ctl_add);
|