From 6ad6e88a156e131597c8636456d4d84f7987808a Mon Sep 17 00:00:00 2001 From: Mauro Carvalho Chehab Date: Fri, 11 Jan 2008 13:51:45 -0300 Subject: [PATCH] V4L/DVB (12833): tm6000: add a proper init code for -alsa Uses about the same initialization code as defined on usbaudio.c. Signed-off-by: Mauro Carvalho Chehab --- drivers/staging/tm6000/tm6000-alsa.c | 83 +++++++++++++++++++++++----- 1 file changed, 70 insertions(+), 13 deletions(-) diff --git a/drivers/staging/tm6000/tm6000-alsa.c b/drivers/staging/tm6000/tm6000-alsa.c index 0538887542f7..2e48bb27a554 100644 --- a/drivers/staging/tm6000/tm6000-alsa.c +++ b/drivers/staging/tm6000/tm6000-alsa.c @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include @@ -63,6 +63,7 @@ struct snd_tm6000_card { ****************************************************************************/ static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ +static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ static int enable[SNDRV_CARDS] = {1, [1 ... (SNDRV_CARDS - 1)] = 1}; module_param_array(enable, bool, NULL, 0444); @@ -345,21 +346,77 @@ static void snd_tm6000_dev_free(struct snd_card *card) * Alsa Constructor - Component probe */ - -/* FIXME: initialize -alsa driver */ -static int tm6000_audio_init(void) +static int tm6000_audio_init(struct tm6000_core *dev, int idx) { - printk("tm6000-alsa not ready yet\n"); + struct snd_card *card; + struct snd_tm6000_card *chip; + int rc, len; + char component[14]; + + if (idx >= SNDRV_CARDS) + return -ENODEV; + + if (!enable[idx]) + return -ENOENT; + + card = snd_card_new(index[idx], id[idx], THIS_MODULE, 0); + if (card == NULL) { + snd_printk(KERN_ERR "cannot create card instance %d\n", idx); + return -ENOMEM; + } + + chip = kzalloc(sizeof(*chip), GFP_KERNEL); + if (!chip) { + rc = -ENOMEM; + goto error; + } + + chip->core = dev; + chip->card = card; + + strcpy(card->driver, "tm6000-alsa"); + sprintf(component, "USB%04x:%04x", + le16_to_cpu(dev->udev->descriptor.idVendor), + le16_to_cpu(dev->udev->descriptor.idProduct)); + snd_component_add(card, component); + + if (dev->udev->descriptor.iManufacturer) + len = usb_string(dev->udev, + dev->udev->descriptor.iManufacturer, + card->longname, sizeof(card->longname)); + else + len = 0; + + if (len > 0) + strlcat(card->longname, " ", sizeof(card->longname)); + + strlcat(card->longname, card->shortname, sizeof(card->longname)); + + len = strlcat(card->longname, " at ", sizeof(card->longname)); + + if (len < sizeof(card->longname)) + usb_make_path(dev->udev, card->longname + len, + sizeof(card->longname) - len); + + strlcat(card->longname, + dev->udev->speed == USB_SPEED_LOW ? ", low speed" : + dev->udev->speed == USB_SPEED_FULL ? ", full speed" : + ", high speed", + sizeof(card->longname)); + + rc = snd_tm6000_pcm(chip, 0, "tm6000 Digital"); + if (rc < 0) + goto error; + + rc = snd_card_register(card); + if (rc < 0) + goto error; + return 0; -} -/* - * module remove - */ -static void tm6000_audio_fini(void) -{ +error: + snd_card_free(card); + return rc; } -module_init(tm6000_audio_init); -module_exit(tm6000_audio_fini); -- 2.30.2