[ALSA] Fixes to follow the standard coding style

Fixed the tutorial to follow the standard kernel coding style.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Jaroslav Kysela <perex@suse.cz>
This commit is contained in:
Takashi Iwai 2007-07-26 16:50:09 +02:00 коммит произвёл Jaroslav Kysela
Родитель 5b31954e4b
Коммит 95a5b0850a
1 изменённых файлов: 77 добавлений и 48 удалений

Просмотреть файл

@ -18,8 +18,8 @@
</affiliation> </affiliation>
</author> </author>
<date>November 17, 2005</date> <date>July 26, 2007</date>
<edition>0.3.6</edition> <edition>0.3.6.1</edition>
<abstract> <abstract>
<para> <para>
@ -405,8 +405,9 @@
/* definition of the chip-specific record */ /* definition of the chip-specific record */
struct mychip { struct mychip {
struct snd_card *card; struct snd_card *card;
// rest of implementation will be in the section /* rest of implementation will be in the section
// "PCI Resource Managements" * "PCI Resource Managements"
*/
}; };
/* chip-specific destructor /* chip-specific destructor
@ -414,7 +415,7 @@
*/ */
static int snd_mychip_free(struct mychip *chip) static int snd_mychip_free(struct mychip *chip)
{ {
.... // will be implemented later... .... /* will be implemented later... */
} }
/* component-destructor /* component-destructor
@ -440,8 +441,9 @@
*rchip = NULL; *rchip = NULL;
// check PCI availability here /* check PCI availability here
// (see "PCI Resource Managements") * (see "PCI Resource Managements")
*/
.... ....
/* allocate a chip-specific data with zero filled */ /* allocate a chip-specific data with zero filled */
@ -451,12 +453,13 @@
chip->card = card; chip->card = card;
// rest of initialization here; will be implemented /* rest of initialization here; will be implemented
// later, see "PCI Resource Managements" * later, see "PCI Resource Managements"
*/
.... ....
if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
chip, &ops)) < 0) { if (err < 0) {
snd_mychip_free(chip); snd_mychip_free(chip);
return err; return err;
} }
@ -490,7 +493,8 @@
return -ENOMEM; return -ENOMEM;
/* (3) */ /* (3) */
if ((err = snd_mychip_create(card, pci, &chip)) < 0) { err = snd_mychip_create(card, pci, &chip);
if (err < 0) {
snd_card_free(card); snd_card_free(card);
return err; return err;
} }
@ -502,10 +506,11 @@
card->shortname, chip->ioport, chip->irq); card->shortname, chip->ioport, chip->irq);
/* (5) */ /* (5) */
.... // implemented later .... /* implemented later */
/* (6) */ /* (6) */
if ((err = snd_card_register(card)) < 0) { err = snd_card_register(card);
if (err < 0) {
snd_card_free(card); snd_card_free(card);
return err; return err;
} }
@ -605,7 +610,8 @@
<![CDATA[ <![CDATA[
struct mychip *chip; struct mychip *chip;
.... ....
if ((err = snd_mychip_create(card, pci, &chip)) < 0) { err = snd_mychip_create(card, pci, &chip);
if (err < 0) {
snd_card_free(card); snd_card_free(card);
return err; return err;
} }
@ -666,7 +672,8 @@
<informalexample> <informalexample>
<programlisting> <programlisting>
<![CDATA[ <![CDATA[
if ((err = snd_card_register(card)) < 0) { err = snd_card_register(card);
if (err < 0) {
snd_card_free(card); snd_card_free(card);
return err; return err;
} }
@ -1091,7 +1098,7 @@
static int snd_mychip_free(struct mychip *chip) static int snd_mychip_free(struct mychip *chip)
{ {
/* disable hardware here if any */ /* disable hardware here if any */
.... // (not implemented in this document) .... /* (not implemented in this document) */
/* release the irq */ /* release the irq */
if (chip->irq >= 0) if (chip->irq >= 0)
@ -1119,7 +1126,8 @@
*rchip = NULL; *rchip = NULL;
/* initialize the PCI entry */ /* initialize the PCI entry */
if ((err = pci_enable_device(pci)) < 0) err = pci_enable_device(pci);
if (err < 0)
return err; return err;
/* check PCI availability (28bit DMA) */ /* check PCI availability (28bit DMA) */
if (pci_set_dma_mask(pci, DMA_28BIT_MASK) < 0 || if (pci_set_dma_mask(pci, DMA_28BIT_MASK) < 0 ||
@ -1141,7 +1149,8 @@
chip->irq = -1; chip->irq = -1;
/* (1) PCI resource allocation */ /* (1) PCI resource allocation */
if ((err = pci_request_regions(pci, "My Chip")) < 0) { err = pci_request_regions(pci, "My Chip");
if (err < 0) {
kfree(chip); kfree(chip);
pci_disable_device(pci); pci_disable_device(pci);
return err; return err;
@ -1156,10 +1165,10 @@
chip->irq = pci->irq; chip->irq = pci->irq;
/* (2) initialization of the chip hardware */ /* (2) initialization of the chip hardware */
.... // (not implemented in this document) .... /* (not implemented in this document) */
if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
chip, &ops)) < 0) { if (err < 0) {
snd_mychip_free(chip); snd_mychip_free(chip);
return err; return err;
} }
@ -1233,7 +1242,8 @@
<informalexample> <informalexample>
<programlisting> <programlisting>
<![CDATA[ <![CDATA[
if ((err = pci_enable_device(pci)) < 0) err = pci_enable_device(pci);
if (err < 0)
return err; return err;
if (pci_set_dma_mask(pci, DMA_28BIT_MASK) < 0 || if (pci_set_dma_mask(pci, DMA_28BIT_MASK) < 0 ||
pci_set_consistent_dma_mask(pci, DMA_28BIT_MASK) < 0) { pci_set_consistent_dma_mask(pci, DMA_28BIT_MASK) < 0) {
@ -1294,7 +1304,8 @@
<informalexample> <informalexample>
<programlisting> <programlisting>
<![CDATA[ <![CDATA[
if ((err = pci_request_regions(pci, "My Chip")) < 0) { err = pci_request_regions(pci, "My Chip");
if (err < 0) {
kfree(chip); kfree(chip);
pci_disable_device(pci); pci_disable_device(pci);
return err; return err;
@ -1773,7 +1784,8 @@
struct snd_pcm_runtime *runtime = substream->runtime; struct snd_pcm_runtime *runtime = substream->runtime;
runtime->hw = snd_mychip_playback_hw; runtime->hw = snd_mychip_playback_hw;
// more hardware-initialization will be done here /* more hardware-initialization will be done here */
....
return 0; return 0;
} }
@ -1781,7 +1793,8 @@
static int snd_mychip_playback_close(struct snd_pcm_substream *substream) static int snd_mychip_playback_close(struct snd_pcm_substream *substream)
{ {
struct mychip *chip = snd_pcm_substream_chip(substream); struct mychip *chip = snd_pcm_substream_chip(substream);
// the hardware-specific codes will be here /* the hardware-specific codes will be here */
....
return 0; return 0;
} }
@ -1793,7 +1806,8 @@
struct snd_pcm_runtime *runtime = substream->runtime; struct snd_pcm_runtime *runtime = substream->runtime;
runtime->hw = snd_mychip_capture_hw; runtime->hw = snd_mychip_capture_hw;
// more hardware-initialization will be done here /* more hardware-initialization will be done here */
....
return 0; return 0;
} }
@ -1801,7 +1815,8 @@
static int snd_mychip_capture_close(struct snd_pcm_substream *substream) static int snd_mychip_capture_close(struct snd_pcm_substream *substream)
{ {
struct mychip *chip = snd_pcm_substream_chip(substream); struct mychip *chip = snd_pcm_substream_chip(substream);
// the hardware-specific codes will be here /* the hardware-specific codes will be here */
....
return 0; return 0;
} }
@ -1844,10 +1859,12 @@
{ {
switch (cmd) { switch (cmd) {
case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_START:
// do something to start the PCM engine /* do something to start the PCM engine */
....
break; break;
case SNDRV_PCM_TRIGGER_STOP: case SNDRV_PCM_TRIGGER_STOP:
// do something to stop the PCM engine /* do something to stop the PCM engine */
....
break; break;
default: default:
return -EINVAL; return -EINVAL;
@ -1900,8 +1917,8 @@
struct snd_pcm *pcm; struct snd_pcm *pcm;
int err; int err;
if ((err = snd_pcm_new(chip->card, "My Chip", 0, 1, 1, err = snd_pcm_new(chip->card, "My Chip", 0, 1, 1, &pcm);
&pcm)) < 0) if (err < 0)
return err; return err;
pcm->private_data = chip; pcm->private_data = chip;
strcpy(pcm->name, "My Chip"); strcpy(pcm->name, "My Chip");
@ -1939,8 +1956,8 @@
struct snd_pcm *pcm; struct snd_pcm *pcm;
int err; int err;
if ((err = snd_pcm_new(chip->card, "My Chip", 0, 1, 1, err = snd_pcm_new(chip->card, "My Chip", 0, 1, 1, &pcm);
&pcm)) < 0) if (err < 0)
return err; return err;
pcm->private_data = chip; pcm->private_data = chip;
strcpy(pcm->name, "My Chip"); strcpy(pcm->name, "My Chip");
@ -2097,7 +2114,7 @@
struct mychip *chip = snd_pcm_chip(pcm); struct mychip *chip = snd_pcm_chip(pcm);
/* free your own data */ /* free your own data */
kfree(chip->my_private_pcm_data); kfree(chip->my_private_pcm_data);
// do what you like else /* do what you like else */
.... ....
} }
@ -2884,10 +2901,10 @@ struct _snd_pcm_runtime {
<![CDATA[ <![CDATA[
switch (cmd) { switch (cmd) {
case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_START:
// do something to start the PCM engine /* do something to start the PCM engine */
break; break;
case SNDRV_PCM_TRIGGER_STOP: case SNDRV_PCM_TRIGGER_STOP:
// do something to stop the PCM engine /* do something to stop the PCM engine */
break; break;
default: default:
return -EINVAL; return -EINVAL;
@ -3071,7 +3088,7 @@ struct _snd_pcm_runtime {
spin_unlock(&chip->lock); spin_unlock(&chip->lock);
snd_pcm_period_elapsed(chip->substream); snd_pcm_period_elapsed(chip->substream);
spin_lock(&chip->lock); spin_lock(&chip->lock);
// acknowledge the interrupt if necessary /* acknowledge the interrupt if necessary */
} }
.... ....
spin_unlock(&chip->lock); spin_unlock(&chip->lock);
@ -3134,7 +3151,7 @@ struct _snd_pcm_runtime {
snd_pcm_period_elapsed(substream); snd_pcm_period_elapsed(substream);
spin_lock(&chip->lock); spin_lock(&chip->lock);
} }
// acknowledge the interrupt if necessary /* acknowledge the interrupt if necessary */
} }
.... ....
spin_unlock(&chip->lock); spin_unlock(&chip->lock);
@ -3604,7 +3621,7 @@ struct _snd_pcm_runtime {
<title>Example of info callback</title> <title>Example of info callback</title>
<programlisting> <programlisting>
<![CDATA[ <![CDATA[
static int snd_myctl_info(struct snd_kcontrol *kcontrol, static int snd_myctl_mono_info(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_info *uinfo) struct snd_ctl_elem_info *uinfo)
{ {
uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
@ -3639,7 +3656,7 @@ struct _snd_pcm_runtime {
<informalexample> <informalexample>
<programlisting> <programlisting>
<![CDATA[ <![CDATA[
static int snd_myctl_info(struct snd_kcontrol *kcontrol, static int snd_myctl_enum_info(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_info *uinfo) struct snd_ctl_elem_info *uinfo)
{ {
static char *texts[4] = { static char *texts[4] = {
@ -3658,6 +3675,16 @@ struct _snd_pcm_runtime {
</programlisting> </programlisting>
</informalexample> </informalexample>
</para> </para>
<para>
Some common info callbacks are prepared for easy use:
<function>snd_ctl_boolean_mono_info()</function> and
<function>snd_ctl_boolean_stereo_info()</function>.
Obviously, the former is an info callback for a mono channel
boolean item, just like <function>snd_myctl_mono_info</function>
above, and the latter is for a stereo channel boolean item.
</para>
</section> </section>
<section id="control-interface-callbacks-get"> <section id="control-interface-callbacks-get">
@ -3794,7 +3821,8 @@ struct _snd_pcm_runtime {
<informalexample> <informalexample>
<programlisting> <programlisting>
<![CDATA[ <![CDATA[
if ((err = snd_ctl_add(card, snd_ctl_new1(&my_control, chip))) < 0) err = snd_ctl_add(card, snd_ctl_new1(&my_control, chip));
if (err < 0)
return err; return err;
]]> ]]>
</programlisting> </programlisting>
@ -3880,7 +3908,7 @@ struct _snd_pcm_runtime {
{ {
struct mychip *chip = ac97->private_data; struct mychip *chip = ac97->private_data;
.... ....
// read a register value here from the codec /* read a register value here from the codec */
return the_register_value; return the_register_value;
} }
@ -3889,7 +3917,7 @@ struct _snd_pcm_runtime {
{ {
struct mychip *chip = ac97->private_data; struct mychip *chip = ac97->private_data;
.... ....
// write the given register value to the codec /* write the given register value to the codec */
} }
static int snd_mychip_ac97(struct mychip *chip) static int snd_mychip_ac97(struct mychip *chip)
@ -3902,7 +3930,8 @@ struct _snd_pcm_runtime {
.read = snd_mychip_ac97_read, .read = snd_mychip_ac97_read,
}; };
if ((err = snd_ac97_bus(chip->card, 0, &ops, NULL, &bus)) < 0) err = snd_ac97_bus(chip->card, 0, &ops, NULL, &bus);
if (err < 0)
return err; return err;
memset(&ac97, 0, sizeof(ac97)); memset(&ac97, 0, sizeof(ac97));
ac97.private_data = chip; ac97.private_data = chip;
@ -4447,10 +4476,10 @@ struct _snd_pcm_runtime {
<informalexample> <informalexample>
<programlisting> <programlisting>
<![CDATA[ <![CDATA[
struct list_head *list;
struct snd_rawmidi_substream *substream; struct snd_rawmidi_substream *substream;
list_for_each(list, &rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT].substreams) { list_for_each_entry(substream,
substream = list_entry(list, struct snd_rawmidi_substream, list); &rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT].substreams,
list {
sprintf(substream->name, "My MIDI Port %d", substream->number + 1); sprintf(substream->name, "My MIDI Port %d", substream->number + 1);
} }
/* same for SNDRV_RAWMIDI_STREAM_INPUT */ /* same for SNDRV_RAWMIDI_STREAM_INPUT */