From: Michael Opdenacker Date: Wed, 24 Oct 2007 08:59:44 +0000 (+0200) Subject: [ALSA] writing-an-alsa-driver.tmpl: English style improvements X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=3f03f7c586471f376eab497ab33394ab086f5301;p=GitHub%2FLineageOS%2Fandroid_kernel_samsung_universal7580.git [ALSA] writing-an-alsa-driver.tmpl: English style improvements This patch brings some English style improvements throughout the document, as well as 1 or 2 extra technical details. Signed-off-by: Michael Opdenacker Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela --- diff --git a/Documentation/sound/alsa/DocBook/writing-an-alsa-driver.tmpl b/Documentation/sound/alsa/DocBook/writing-an-alsa-driver.tmpl index 2c3fc3cb3b6..48e4053eda1 100644 --- a/Documentation/sound/alsa/DocBook/writing-an-alsa-driver.tmpl +++ b/Documentation/sound/alsa/DocBook/writing-an-alsa-driver.tmpl @@ -18,7 +18,7 @@ - September 10, 2007 + Oct 15, 2007 0.3.7 @@ -67,7 +67,7 @@ This document describes how to write an ALSA (Advanced Linux Sound Architecture) - driver. The document focuses mainly on the PCI soundcard. + driver. The document focuses mainly on PCI soundcards. In the case of other device types, the API might be different, too. However, at least the ALSA kernel API is consistent, and therefore it would be still a bit help for @@ -75,23 +75,23 @@ - The target of this document is ones who already have enough - skill of C language and have the basic knowledge of linux - kernel programming. This document doesn't explain the general - topics of linux kernel codes and doesn't cover the detail of - implementation of each low-level driver. It describes only how is + This document targets people who already have enough + C language skills and have basic linux kernel programming + knowledge. This document doesn't explain the general + topic of linux kernel coding and doesn't cover low-level + driver implementation details. It only describes the standard way to write a PCI sound driver on ALSA. - If you are already familiar with the older ALSA ver.0.5.x, you - can check the drivers such as es1938.c or - maestro3.c which have also almost the same + If you are already familiar with the older ALSA ver.0.5.x API, you + can check the drivers such as sound/pci/es1938.c or + sound/pci/maestro3.c which have also almost the same code-base in the ALSA 0.5.x tree, so you can compare the differences. - This document is still a draft version. Any feedbacks and + This document is still a draft version. Any feedback and corrections, please!! @@ -106,7 +106,7 @@
General - The ALSA drivers are provided in the two ways. + The ALSA drivers are provided in two ways. @@ -114,15 +114,14 @@ ALSA's ftp site, and another is the 2.6 (or later) Linux kernel tree. To synchronize both, the ALSA driver tree is split into two different trees: alsa-kernel and alsa-driver. The former - contains purely the source codes for the Linux 2.6 (or later) + contains purely the source code for the Linux 2.6 (or later) tree. This tree is designed only for compilation on 2.6 or later environment. The latter, alsa-driver, contains many subtle - files for compiling the ALSA driver on the outside of Linux - kernel like configure script, the wrapper functions for older, - 2.2 and 2.4 kernels, to adapt the latest kernel API, + files for compiling ALSA drivers outside of the Linux kernel tree, + wrapper functions for older 2.2 and 2.4 kernels, to adapt the latest kernel API, and additional drivers which are still in development or in tests. The drivers in alsa-driver tree will be moved to - alsa-kernel (eventually 2.6 kernel tree) once when they are + alsa-kernel (and eventually to the 2.6 kernel tree) when they are finished and confirmed to work fine. @@ -168,7 +167,7 @@
core directory - This directory contains the middle layer, that is, the heart + This directory contains the middle layer which is the heart of ALSA drivers. In this directory, the native ALSA modules are stored. The sub-directories contain different modules and are dependent upon the kernel config. @@ -181,7 +180,7 @@ The codes for PCM and mixer OSS emulation modules are stored in this directory. The rawmidi OSS emulation is included in the ALSA rawmidi code since it's quite small. The sequencer - code is stored in core/seq/oss directory (see + code is stored in core/seq/oss directory (see below). @@ -200,7 +199,7 @@
core/seq - This and its sub-directories are for the ALSA + This directory and its sub-directories are for the ALSA sequencer. This directory contains the sequencer core and primary sequencer modules such like snd-seq-midi, snd-seq-virmidi, etc. They are compiled only when @@ -229,22 +228,22 @@ include directory This is the place for the public header files of ALSA drivers, - which are to be exported to the user-space, or included by + which are to be exported to user-space, or included by several files at different directories. Basically, the private header files should not be placed in this directory, but you may - still find files there, due to historical reason :) + still find files there, due to historical reasons :)
drivers directory - This directory contains the codes shared among different drivers - on the different architectures. They are hence supposed not to be + This directory contains code shared among different drivers + on different architectures. They are hence supposed not to be architecture-specific. For example, the dummy pcm driver and the serial MIDI driver are found in this directory. In the sub-directories, - there are the codes for components which are independent from + there is code for components which are independent from bus and cpu architectures. @@ -271,7 +270,7 @@ Although there is a standard i2c layer on Linux, ALSA has its - own i2c codes for some cards, because the soundcard needs only a + own i2c code for some cards, because the soundcard needs only a simple operation and the standard i2c API is too complicated for such a purpose. @@ -292,28 +291,28 @@ So far, there is only Emu8000/Emu10k1 synth driver under - synth/emux sub-directory. + the synth/emux sub-directory.
pci directory - This and its sub-directories hold the top-level card modules - for PCI soundcards and the codes specific to the PCI BUS. + This directory and its sub-directories hold the top-level card modules + for PCI soundcards and the code specific to the PCI BUS. - The drivers compiled from a single file is stored directly on - pci directory, while the drivers with several source files are - stored on its own sub-directory (e.g. emu10k1, ice1712). + The drivers compiled from a single file are stored directly + in the pci directory, while the drivers with several source files are + stored on their own sub-directory (e.g. emu10k1, ice1712).
isa directory - This and its sub-directories hold the top-level card modules + This directory and its sub-directories hold the top-level card modules for ISA soundcards.
@@ -321,16 +320,16 @@
arm, ppc, and sparc directories - These are for the top-level card modules which are - specific to each given architecture. + They are used for top-level card modules which are + specific to one of these architectures.
usb directory - This contains the USB-audio driver. On the latest version, the - USB MIDI driver is integrated together with usb-audio driver. + This directory contains the USB-audio driver. In the latest version, the + USB MIDI driver is integrated in the usb-audio driver.
@@ -338,16 +337,17 @@ pcmcia directory The PCMCIA, especially PCCard drivers will go here. CardBus - drivers will be on pci directory, because its API is identical - with the standard PCI cards. + drivers will be in the pci directory, because their API is identical + to that of standard PCI cards.
oss directory - The OSS/Lite source files are stored here on Linux 2.6 (or - later) tree. (In the ALSA driver tarball, it's empty, of course :) + The OSS/Lite source files are stored here in Linux 2.6 (or + later) tree. In the ALSA driver tarball, this directory is empty, + of course :)
@@ -362,7 +362,7 @@
Outline - The minimum flow of PCI soundcard is like the following: + The minimum flow for PCI soundcards is as follows: define the PCI ID table (see the section @@ -370,9 +370,13 @@ ). create probe() callback. create remove() callback. - create pci_driver table which contains the three pointers above. - create init() function just calling pci_register_driver() to register the pci_driver table defined above. - create exit() function to call pci_unregister_driver() function. + create a pci_driver structure + containing the three pointers above. + create an init() function just calling + the pci_register_driver() to register the pci_driver table + defined above. + create an exit() function to call + the pci_unregister_driver() function.
@@ -382,12 +386,12 @@ The code example is shown below. Some parts are kept unimplemented at this moment but will be filled in the - succeeding sections. The numbers in comment lines of - snd_mychip_probe() function are the - markers. + next sections. The numbers in the comment lines of the + snd_mychip_probe() function + refer to details explained in the following section. - Basic Flow for PCI Drivers Example + Basic Flow for PCI Drivers - Example @@ -398,6 +402,7 @@ #include /* module parameters (see "Module Parameters") */ + /* SNDRV_CARDS: maximum number of cards supported by this module */ static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; @@ -405,13 +410,13 @@ /* definition of the chip-specific record */ struct mychip { struct snd_card *card; - /* rest of implementation will be in the section - * "PCI Resource Managements" + /* the rest of the implementation will be in section + * "PCI Resource Management" */ }; /* chip-specific destructor - * (see "PCI Resource Managements") + * (see "PCI Resource Management") */ static int snd_mychip_free(struct mychip *chip) { @@ -442,7 +447,7 @@ *rchip = NULL; /* check PCI availability here - * (see "PCI Resource Managements") + * (see "PCI Resource Management") */ .... @@ -454,7 +459,7 @@ chip->card = card; /* rest of initialization here; will be implemented - * later, see "PCI Resource Managements" + * later, see "PCI Resource Management" */ .... @@ -521,7 +526,7 @@ return 0; } - /* destructor -- see "Destructor" sub-section */ + /* destructor -- see the "Destructor" sub-section */ static void __devexit snd_mychip_remove(struct pci_dev *pci) { snd_card_free(pci_get_drvdata(pci)); @@ -536,16 +541,16 @@
Constructor - The real constructor of PCI drivers is probe callback. The - probe callback and other component-constructors which are called - from probe callback should be defined with - __devinit prefix. You - cannot use __init prefix for them, + The real constructor of PCI drivers is the probe callback. + The probe callback and other component-constructors which are called + from the probe callback should be defined with + the __devinit prefix. You + cannot use the __init prefix for them, because any PCI device could be a hotplug device. - In the probe callback, the following scheme is often used. + In the probe callback, the following scheme is often used.
@@ -570,7 +575,7 @@ - At each time probe callback is called, check the + Each time the probe callback is called, check the availability of the device. If not available, simply increment the device index and returns. dev will be incremented also later ( - The detail will be explained in the section + The details will be explained in the section Management of Cards and Components. @@ -619,9 +624,9 @@ - The detail will be explained in the section PCI Resource - Managements. + Management.
@@ -640,7 +645,7 @@ The driver field holds the minimal ID string of the - chip. This is referred by alsa-lib's configurator, so keep it + chip. This is used by alsa-lib's configurator, so keep it simple but unique. Even the same driver can have different driver IDs to distinguish the functionality of each chip type. @@ -648,7 +653,7 @@ The shortname field is a string shown as more verbose - name. The longname field contains the information which is + name. The longname field contains the information shown in /proc/asound/cards.
@@ -703,7 +708,7 @@ In the above, the card record is stored. This pointer is - referred in the remove callback and power-management + used in the remove callback and power-management callbacks, too.
@@ -757,22 +762,22 @@ where the last one is necessary only when module options are - defined in the source file. If the codes are split to several - files, the file without module options don't need them. + defined in the source file. If the code is split into several + files, the files without module options don't need them. - In addition to them, you'll need - <linux/interrupt.h> for the interrupt - handling, and <asm/io.h> for the i/o - access. If you use mdelay() or + In addition to these headers, you'll need + <linux/interrupt.h> for interrupt + handling, and <asm/io.h> for I/O + access. If you use the mdelay() or udelay() functions, you'll need to include - <linux/delay.h>, too. + <linux/delay.h> too. - The ALSA interfaces like PCM or control API are defined in other - header files as <sound/xxx.h>. + The ALSA interfaces like the PCM and control APIs are defined in other + <sound/xxx.h> header files. They have to be included after <sound/core.h>. @@ -795,12 +800,12 @@ A card record is the headquarters of the soundcard. It manages - the list of whole devices (components) on the soundcard, such as + the whole list of devices (components) on the soundcard, such as PCM, mixers, MIDI, synthesizer, and so on. Also, the card record holds the ID and the name strings of the card, manages the root of proc files, and controls the power-management states and hotplug disconnections. The component list on the card - record is used to manage the proper releases of resources at + record is used to manage the correct release of resources at destruction. @@ -824,9 +829,8 @@ THIS_MODULE), and the size of extra-data space. The last argument is used to allocate card->private_data for the - chip-specific data. Note that this data - is allocated by - snd_card_new(). + chip-specific data. Note that these data + are allocated by snd_card_new(). @@ -834,10 +838,10 @@ Components After the card is created, you can attach the components - (devices) to the card instance. On ALSA driver, a component is + (devices) to the card instance. In an ALSA driver, a component is represented as a struct snd_device object. A component can be a PCM instance, a control interface, a raw - MIDI interface, etc. Each of such instances has one component + MIDI interface, etc. Each such instance has one component entry. @@ -859,7 +863,7 @@ (SNDRV_DEV_XXX), the data pointer, and the callback pointers (&ops). The device-level defines the type of components and the order of - registration and de-registration. For most of components, the + registration and de-registration. For most components, the device-level is already defined. For a user-defined component, you can use SNDRV_DEV_LOWLEVEL. @@ -867,13 +871,13 @@ This function itself doesn't allocate the data space. The data must be allocated manually beforehand, and its pointer is passed - as the argument. This pointer is used as the identifier - (chip in the above example) for the - instance. + as the argument. This pointer is used as the + (chip identifier in the above example) + for the instance. - Each ALSA pre-defined component such as ac97 or pcm calls + Each pre-defined ALSA component such as ac97 and pcm calls snd_device_new() inside its constructor. The destructor for each component is defined in the callback pointers. Hence, you don't need to take care of @@ -881,19 +885,19 @@ - If you would like to create your own component, you need to - set the destructor function to dev_free callback in - ops, so that it can be released - automatically via snd_card_free(). The - example will be shown later as an implementation of a - chip-specific data. + If you wish to create your own component, you need to + set the destructor function to the dev_free callback in + the ops, so that it can be released + automatically via snd_card_free(). + The next example will show an implementation of chip-specific + data.
Chip-Specific Data - The chip-specific information, e.g. the i/o port address, its + Chip-specific information, e.g. the I/O port address, its resource pointer, or the irq number, is stored in the chip-specific record. @@ -909,13 +913,14 @@ - In general, there are two ways to allocate the chip record. + In general, there are two ways of allocating the chip record.
1. Allocating via <function>snd_card_new()</function>. - As mentioned above, you can pass the extra-data-length to the 4th argument of snd_card_new(), i.e. + As mentioned above, you can pass the extra-data-length + to the 4th argument of snd_card_new(), i.e. @@ -925,7 +930,7 @@ - whether struct mychip is the type of the chip record. + struct mychip is the type of the chip record. @@ -1037,8 +1042,8 @@ Registration and Release After all components are assigned, register the card instance - by calling snd_card_register(). The access - to the device files are enabled at this point. That is, before + by calling snd_card_register(). Access + to the device files is enabled at this point. That is, before snd_card_register() is called, the components are safely inaccessible from external side. If this call fails, exit the probe function after releasing the card via @@ -1047,7 +1052,7 @@ For releasing the card instance, you can call simply - snd_card_free(). As already mentioned, all + snd_card_free(). As mentioned earlier, all components are released automatically by this call. @@ -1055,7 +1060,7 @@ As further notes, the destructors (both snd_mychip_dev_free and snd_mychip_free) cannot be defined with - __devexit prefix, because they may be + the __devexit prefix, because they may be called from the constructor, too, at the false path. @@ -1071,20 +1076,20 @@ - + - PCI Resource Managements + PCI Resource Management
Full Code Example - In this section, we'll finish the chip-specific constructor, - destructor and PCI entries. The example code is shown first, + In this section, we'll complete the chip-specific constructor, + destructor and PCI entries. Example code is shown first, below. - PCI Resource Managements Example + PCI Resource Management Example irq >= 0) free_irq(chip->irq, chip); - /* release the i/o ports & memory */ + /* release the I/O ports & memory */ pci_release_regions(chip->pci); /* disable the PCI entry */ pci_disable_device(chip->pci); @@ -1196,13 +1201,13 @@ .remove = __devexit_p(snd_mychip_remove), }; - /* initialization of the module */ + /* module initialization */ static int __init alsa_card_mychip_init(void) { return pci_register_driver(&driver); } - /* clean up the module */ + /* module clean up */ static void __exit alsa_card_mychip_exit(void) { pci_unregister_driver(&driver); @@ -1228,10 +1233,10 @@ - In the case of PCI devices, you have to call at first - pci_enable_device() function before + In the case of PCI devices, you first have to call + the pci_enable_device() function before allocating resources. Also, you need to set the proper PCI DMA - mask to limit the accessed i/o range. In some cases, you might + mask to limit the accessed I/O range. In some cases, you might need to call pci_set_master() function, too. @@ -1261,15 +1266,15 @@
Resource Allocation - The allocation of I/O ports and irqs are done via standard kernel + The allocation of I/O ports and irqs is done via standard kernel functions. Unlike ALSA ver.0.5.x., there are no helpers for that. And these resources must be released in the destructor function (see below). Also, on ALSA 0.9.x, you don't need to - allocate (pseudo-)DMA for PCI like ALSA 0.5.x. + allocate (pseudo-)DMA for PCI like in ALSA 0.5.x. - Now assume that this PCI device has an I/O port with 8 bytes + Now assume that the PCI device has an I/O port with 8 bytes and an interrupt. Then struct mychip will have the following fields: @@ -1288,7 +1293,7 @@ - For an i/o port (and also a memory region), you need to have + For an I/O port (and also a memory region), you need to have the resource pointer for the standard resource management. For an irq, you have to keep only the irq number (integer). But you need to initialize this number as -1 before actual allocation, @@ -1299,7 +1304,7 @@ - The allocation of an i/o port is done like this: + The allocation of an I/O port is done like this: @@ -1318,12 +1323,12 @@ - It will reserve the i/o port region of 8 bytes of the given + It will reserve the I/O port region of 8 bytes of the given PCI device. The returned value, chip->res_port, is allocated via kmalloc() by request_region(). The pointer must be - released via kfree(), but there is some - problem regarding this. This issue will be explained more below. + released via kfree(), but there is a + problem with this. This issue will be explained later. @@ -1351,8 +1356,8 @@ - On the PCI bus, the interrupts can be shared. Thus, - IRQF_SHARED is given as the interrupt flag of + On the PCI bus, interrupts can be shared. Thus, + IRQF_SHARED is used as the interrupt flag of request_irq(). @@ -1364,7 +1369,7 @@ - I won't define the detail of the interrupt handler at this + I won't give details about the interrupt handler at this point, but at least its appearance can be explained now. The interrupt handler looks usually like the following: @@ -1386,11 +1391,11 @@ Now let's write the corresponding destructor for the resources above. The role of destructor is simple: disable the hardware (if already activated) and release the resources. So far, we - have no hardware part, so the disabling is not written here. + have no hardware part, so the disabling code is not written here. - For releasing the resources, check-and-release + To release the resources, the check-and-release method is a safer way. For the interrupt, do like this: @@ -1410,7 +1415,7 @@ When you requested I/O ports or memory regions via pci_request_region() or - pci_request_regions() like this example, + pci_request_regions() like in this example, release the resource(s) using the corresponding function, pci_release_region() or pci_release_regions(). @@ -1429,7 +1434,7 @@ or request_mem_region, you can release it via release_resource(). Suppose that you keep the resource pointer returned from request_region() - in chip->res_port, the release procedure looks like below: + in chip->res_port, the release procedure looks like: @@ -1442,7 +1447,7 @@ Don't forget to call pci_disable_device() - before all finished. + before the end. @@ -1459,14 +1464,14 @@ Again, remember that you cannot - set __devexit prefix for this destructor. + use the __devexit prefix for this destructor. - We didn't implement the hardware-disabling part in the above. + We didn't implement the hardware disabling part in the above. If you need to do this, please note that the destructor may be called even before the initialization of the chip is completed. - It would be better to have a flag to skip the hardware-disabling + It would be better to have a flag to skip hardware disabling if the hardware was not initialized yet. @@ -1475,14 +1480,14 @@ snd_device_new() with SNDRV_DEV_LOWLELVEL , its destructor is called at the last. That is, it is assured that all other - components like PCMs and controls have been already released. - You don't have to call stopping PCMs, etc. explicitly, but just - stop the hardware in the low-level. + components like PCMs and controls have already been released. + You don't have to stop PCMs, etc. explicitly, but just + call low-level hardware stopping. The management of a memory-mapped region is almost as same as - the management of an i/o port. You'll need three fields like + the management of an I/O port. You'll need three fields like the following: @@ -1561,8 +1566,8 @@
PCI Entries - So far, so good. Let's finish the rest of missing PCI - stuffs. At first, we need a + So far, so good. Let's finish the missing PCI + stuff. At first, we need a pci_device_id table for this chipset. It's a table of PCI vendor/device ID number, and some masks. @@ -1588,13 +1593,13 @@ The first and second fields of - pci_device_id struct are the vendor and - device IDs. If you have nothing special to filter the matching - devices, you can use the rest of fields like above. The last - field of pci_device_id struct is a + the pci_device_id structure are the vendor and + device IDs. If you have no reason to filter the matching + devices, you can leave the remaining fields as above. The last + field of the pci_device_id struct contains private data for this entry. You can specify any value here, for - example, to tell the type of different operations per each - device IDs. Such an example is found in intel8x0 driver. + example, to define specific operations for supported device IDs. + Such an example is found in the intel8x0 driver. @@ -1621,10 +1626,10 @@ The probe and - remove functions are what we already - defined in - the previous sections. The remove should - be defined with + remove functions have already + been defined in the previous sections. + The remove function should + be defined with the __devexit_p() macro, so that it's not defined for built-in (and non-hot-pluggable) case. The name @@ -1665,8 +1670,7 @@ Oh, one thing was forgotten. If you have no exported symbols, - you need to declare it on 2.2 or 2.4 kernels (on 2.6 kernels - it's not necessary, though). + you need to declare it in 2.2 or 2.4 kernels (it's not necessary in 2.6 kernels). @@ -1698,7 +1702,7 @@ For accessing to the PCM layer, you need to include - <sound/pcm.h> above all. In addition, + <sound/pcm.h> first. In addition, <sound/pcm_params.h> might be needed if you access to some functions related with hw_param. @@ -1707,21 +1711,21 @@ Each card device can have up to four pcm instances. A pcm instance corresponds to a pcm device file. The limitation of number of instances comes only from the available bit size of - the linux's device number. Once when 64bit device number is - used, we'll have more available pcm instances. + the Linux's device numbers. Once when 64bit device number is + used, we'll have more pcm instances available. A pcm instance consists of pcm playback and capture streams, and each pcm stream consists of one or more pcm substreams. Some - soundcard supports the multiple-playback function. For example, + soundcards support multiple playback functions. For example, emu10k1 has a PCM playback of 32 stereo substreams. In this case, at each open, a free substream is (usually) automatically chosen and opened. Meanwhile, when only one substream exists and it was - already opened, the succeeding open will result in the blocking - or the error with EAGAIN according to the - file open mode. But you don't have to know the detail in your - driver. The PCM middle layer will take all such jobs. + already opened, the successful open will either block + or error with EAGAIN according to the + file open mode. But you don't have to care about such details in your + driver. The PCM middle layer will take care of such work.
@@ -1944,7 +1948,7 @@
Constructor - A pcm instance is allocated by snd_pcm_new() + A pcm instance is allocated by the snd_pcm_new() function. It would be better to create a constructor for pcm, namely, @@ -1971,23 +1975,23 @@ - The snd_pcm_new() function takes the four + The snd_pcm_new() function takes four arguments. The first argument is the card pointer to which this pcm is assigned, and the second is the ID string. The third argument (index, 0 in the - above) is the index of this new pcm. It begins from zero. When - you will create more than one pcm instances, specify the + above) is the index of this new pcm. It begins from zero. If + you create more than one pcm instances, specify the different numbers in this argument. For example, index = 1 for the second PCM device. The fourth and fifth arguments are the number of substreams - for playback and capture, respectively. Here both 1 are given in - the above example. When no playback or no capture is available, + for playback and capture, respectively. Here 1 is used for + both arguments. When no playback or capture substreams are available, pass 0 to the corresponding argument. @@ -2045,13 +2049,13 @@ - Each of callbacks is explained in the subsection + All the callbacks are described in the - Operators. + Operators subsection. - After setting the operators, most likely you'd like to + After setting the operators, you probably will want to pre-allocate the buffer. For the pre-allocation, simply call the following: @@ -2065,8 +2069,8 @@ - It will allocate up to 64kB buffer as default. The details of - buffer management will be described in the later section Buffer and Memory Management. @@ -2095,13 +2099,13 @@ The destructor for a pcm instance is not always necessary. Since the pcm device will be released by the middle - layer code automatically, you don't have to call destructor + layer code automatically, you don't have to call the destructor explicitly. - The destructor would be necessary when you created some - special records internally and need to release them. In such a + The destructor would be necessary if you created + special records internally and needed to release them. In such a case, set the destructor function to pcm->private_free: @@ -2141,16 +2145,15 @@ When the PCM substream is opened, a PCM runtime instance is allocated and assigned to the substream. This pointer is accessible via substream->runtime. - This runtime pointer holds the various information; it holds - the copy of hw_params and sw_params configurations, the buffer - pointers, mmap records, spinlocks, etc. Almost everything you - need for controlling the PCM can be found there. + This runtime pointer holds most information you need + to control the PCM: the copy of hw_params and sw_params configurations, the buffer + pointers, mmap records, spinlocks, etc. The definition of runtime instance is found in - <sound/pcm.h>. Here is the - copy from the file. + <sound/pcm.h>. Here are + the contents of this file: For the operators (callbacks) of each sound driver, most of these records are supposed to be read-only. Only the PCM - middle-layer changes / updates these info. The exceptions are + middle-layer changes / updates them. The exceptions are the hardware description (hw), interrupt callbacks (transfer_ack_xxx), DMA buffer information, and the private data. Besides, if you use the standard buffer allocation @@ -2285,7 +2288,7 @@ struct _snd_pcm_runtime { - Typically, you'll have a hardware descriptor like below: + Typically, you'll have a hardware descriptor as below: SNDRV_PCM_INFO_XXX. Here, at least, you have to specify whether the mmap is supported and which interleaved format is supported. - When the mmap is supported, add + When the is supported, add the SNDRV_PCM_INFO_MMAP flag here. When the hardware supports the interleaved or the non-interleaved - format, SNDRV_PCM_INFO_INTERLEAVED or + formats, SNDRV_PCM_INFO_INTERLEAVED or SNDRV_PCM_INFO_NONINTERLEAVED flag must be set, respectively. If both are supported, you can set both, too. @@ -2331,7 +2334,7 @@ struct _snd_pcm_runtime { In the above example, MMAP_VALID and - BLOCK_TRANSFER are specified for OSS mmap + BLOCK_TRANSFER are specified for the OSS mmap mode. Usually both are set. Of course, MMAP_VALID is set only if the mmap is really supported. @@ -2345,11 +2348,11 @@ struct _snd_pcm_runtime { pause operation, while the RESUME bit means that the pcm supports the full suspend/resume operation. - If PAUSE flag is set, + If the PAUSE flag is set, the trigger callback below must handle the corresponding (pause push/release) commands. The suspend/resume trigger commands can be defined even without - RESUME flag. See RESUME flag. See Power Management section for details. @@ -2382,7 +2385,7 @@ struct _snd_pcm_runtime { CONTINUOUS bit additionally. The pre-defined rate bits are provided only for typical rates. If your chip supports unconventional rates, you need to add - KNOT bit and set up the hardware + the KNOT bit and set up the hardware constraint manually (explained later). @@ -2390,8 +2393,8 @@ struct _snd_pcm_runtime { rate_min and - rate_max define the minimal and - maximal sample rate. This should correspond somehow to + rate_max define the minimum and + maximum sample rate. This should correspond somehow to rates bits. @@ -2400,7 +2403,7 @@ struct _snd_pcm_runtime { channel_min and channel_max - define, as you might already expected, the minimal and maximal + define, as you might already expected, the minimum and maximum number of channels. @@ -2408,21 +2411,21 @@ struct _snd_pcm_runtime { buffer_bytes_max defines the - maximal buffer size in bytes. There is no + maximum buffer size in bytes. There is no buffer_bytes_min field, since - it can be calculated from the minimal period size and the - minimal number of periods. + it can be calculated from the minimum period size and the + minimum number of periods. Meanwhile, period_bytes_min and - define the minimal and maximal size of the period in bytes. + define the minimum and maximum size of the period in bytes. periods_max and - periods_min define the maximal and - minimal number of periods in the buffer. + periods_min define the maximum and + minimum number of periods in the buffer. - The period is a term, that corresponds to - fragment in the OSS world. The period defines the size at - which the PCM interrupt is generated. This size strongly + The period is a term that corresponds to + a fragment in the OSS world. The period defines the size at + which a PCM interrupt is generated. This size strongly depends on the hardware. Generally, the smaller period size will give you more interrupts, that is, more controls. @@ -2435,8 +2438,8 @@ struct _snd_pcm_runtime { There is also a field fifo_size. - This specifies the size of the hardware FIFO, but it's not - used currently in the driver nor in the alsa-lib. So, you + This specifies the size of the hardware FIFO, but currently it + is neither used in the driver nor in the alsa-lib. So, you can ignore this field. @@ -2450,7 +2453,7 @@ struct _snd_pcm_runtime { Ok, let's go back again to the PCM runtime records. The most frequently referred records in the runtime instance are the PCM configurations. - The PCM configurations are stored on runtime instance + The PCM configurations are stored in the runtime instance after the application sends hw_params data via alsa-lib. There are many fields copied from hw_params and sw_params structs. For example, @@ -2461,11 +2464,11 @@ struct _snd_pcm_runtime { One thing to be noted is that the configured buffer and period - sizes are stored in frames in the runtime + sizes are stored in frames in the runtime. In the ALSA world, 1 frame = channels * samples-size. For conversion between frames and bytes, you can use the - helper functions, frames_to_bytes() and - bytes_to_frames(). + frames_to_bytes() and + bytes_to_frames() helper functions. dma_area is necessary when the buffer is mmapped. If your driver doesn't support mmap, this field is not necessary. dma_addr - is also not mandatory. You can use + is also optional. You can use dma_private as you like, too.
@@ -2524,14 +2527,14 @@ struct _snd_pcm_runtime { Running Status The running status can be referred via runtime->status. - This is the pointer to struct snd_pcm_mmap_status + This is the pointer to the struct snd_pcm_mmap_status record. For example, you can get the current DMA hardware pointer via runtime->status->hw_ptr. The DMA application pointer can be referred via - runtime->control, which points + runtime->control, which points to the struct snd_pcm_mmap_control record. However, accessing directly to this value is not recommended. @@ -2542,14 +2545,14 @@ struct _snd_pcm_runtime { You can allocate a record for the substream and store it in runtime->private_data. Usually, this - done in + is done in the open callback. Don't mix this with pcm->private_data. - The pcm->private_data usually points the + The pcm->private_data usually points to the chip instance assigned statically at the creation of PCM, while the - runtime->private_data points a dynamic - data created at the PCM open callback. + runtime->private_data points to a dynamic + data structure created at the PCM open callback. @@ -2579,7 +2582,7 @@ struct _snd_pcm_runtime { The field transfer_ack_begin and transfer_ack_end are called at - the beginning and the end of + the beginning and at the end of snd_pcm_period_elapsed(), respectively.
@@ -2589,17 +2592,18 @@ struct _snd_pcm_runtime {
Operators - OK, now let me explain the detail of each pcm callback + OK, now let me give details about each pcm callback (ops). In general, every callback must - return 0 if successful, or a negative number with the error - number such as -EINVAL at any - error. + return 0 if successful, or a negative error number + such as -EINVAL. To choose an appropriate + error number, it is advised to check what value other parts of + the kernel return when the same kind of request fails. The callback function takes at least the argument with - snd_pcm_substream pointer. For retrieving the - chip record from the given substream instance, you can use the + snd_pcm_substream pointer. To retrieve + the chip record from the given substream instance, you can use the following macro. @@ -2616,7 +2620,7 @@ struct _snd_pcm_runtime { The macro reads substream->private_data, which is a copy of pcm->private_data. You can override the former if you need to assign different data - records per PCM substream. For example, cmi8330 driver assigns + records per PCM substream. For example, the cmi8330 driver assigns different private_data for playback and capture directions, because it uses two different codecs (SB- and AD-compatible) for different directions. @@ -2709,7 +2713,7 @@ struct _snd_pcm_runtime {
ioctl callback - This is used for any special action to pcm ioctls. But + This is used for any special call to pcm ioctls. But usually you can pass a generic ioctl callback, snd_pcm_lib_ioctl. @@ -2726,9 +2730,6 @@ struct _snd_pcm_runtime { ]]> - - This and hw_free callbacks exist - only on ALSA 0.9.x. @@ -2740,13 +2741,13 @@ struct _snd_pcm_runtime { - Many hardware set-up should be done in this callback, + Many hardware setups should be done in this callback, including the allocation of buffers. Parameters to be initialized are retrieved by - params_xxx() macros. For allocating a + params_xxx() macros. To allocate buffer, you can call a helper function, @@ -2772,8 +2773,8 @@ struct _snd_pcm_runtime { - Thus, you need to take care not to allocate the same buffers - many times, which will lead to memory leak! Calling the + Thus, you need to be careful not to allocate the same buffers + many times, which will lead to memory leaks! Calling the helper function above many times is OK. It will release the previous buffer automatically when it was already allocated. @@ -2782,7 +2783,7 @@ struct _snd_pcm_runtime { Another note is that this callback is non-atomic (schedulable). This is important, because the trigger callback - is atomic (non-schedulable). That is, mutex or any + is atomic (non-schedulable). That is, mutexes or any schedule-related functions are not available in trigger callback. Please see the subsection @@ -2843,15 +2844,15 @@ struct _snd_pcm_runtime { prepared. You can set the format type, sample rate, etc. here. The difference from hw_params is that the - prepare callback will be called at each + prepare callback will be called each time snd_pcm_prepare() is called, i.e. when - recovered after underruns, etc. + recovering after underruns, etc. - Note that this callback became non-atomic since the recent version. - You can use schedule-related functions safely in this callback now. + Note that this callback is now non-atomic. + You can use schedule-related functions safely in this callback. @@ -2871,7 +2872,7 @@ struct _snd_pcm_runtime { Be careful that this callback will be called many times at - each set up, too. + each setup, too.
@@ -2893,7 +2894,7 @@ struct _snd_pcm_runtime { Which action is specified in the second argument, SNDRV_PCM_TRIGGER_XXX in <sound/pcm.h>. At least, - START and STOP + the START and STOP commands must be defined in this callback. @@ -2915,8 +2916,8 @@ struct _snd_pcm_runtime {
- When the pcm supports the pause operation (given in info - field of the hardware table), PAUSE_PUSE + When the pcm supports the pause operation (given in the info + field of the hardware table), the PAUSE_PUSE and PAUSE_RELEASE commands must be handled here, too. The former is the command to pause the pcm, and the latter to restart the pcm again. @@ -2925,21 +2926,21 @@ struct _snd_pcm_runtime { When the pcm supports the suspend/resume operation, regardless of full or partial suspend/resume support, - SUSPEND and RESUME + the SUSPEND and RESUME commands must be handled, too. These commands are issued when the power-management status is changed. Obviously, the SUSPEND and - RESUME - do suspend and resume of the pcm substream, and usually, they - are identical with STOP and + RESUME commands + suspend and resume the pcm substream, and usually, they + are identical to the STOP and START commands, respectively. - See + See the Power Management section for details. As mentioned, this callback is atomic. You cannot call - the function going to sleep. + functions which may sleep. The trigger callback should be as minimal as possible, just really triggering the DMA. The other stuff should be initialized hw_params and prepare callbacks properly @@ -2960,8 +2961,8 @@ struct _snd_pcm_runtime { This callback is called when the PCM middle layer inquires the current hardware position on the buffer. The position must - be returned in frames (which was in bytes on ALSA 0.5.x), - ranged from 0 to buffer_size - 1. + be returned in frames, + ranging from 0 to buffer_size - 1. @@ -2983,7 +2984,7 @@ struct _snd_pcm_runtime { These callbacks are not mandatory, and can be omitted in most cases. These callbacks are used when the hardware buffer - cannot be on the normal memory space. Some chips have their + cannot be in the normal memory space. Some chips have their own buffer on the hardware which is not mappable. In such a case, you have to transfer the data manually from the memory buffer to the hardware buffer. Or, if the buffer is @@ -3018,8 +3019,8 @@ struct _snd_pcm_runtime { page callback - This callback is also not mandatory. This callback is used - mainly for the non-contiguous buffer. The mmap calls this + This callback is optional too. This callback is used + mainly for non-contiguous buffers. The mmap calls this callback to get the page address. Some examples will be explained in the later section Buffer and Memory @@ -3035,7 +3036,7 @@ struct _snd_pcm_runtime { role of PCM interrupt handler in the sound driver is to update the buffer position and to tell the PCM middle layer when the buffer position goes across the prescribed period size. To - inform this, call snd_pcm_period_elapsed() + inform this, call the snd_pcm_period_elapsed() function. @@ -3072,7 +3073,7 @@ struct _snd_pcm_runtime { - A typical coding would be like: + Typical code would be like: Interrupt Handler Case #1 @@ -3101,21 +3102,21 @@ struct _snd_pcm_runtime {
- High-frequent timer interrupts + High frequency timer interrupts - This is the case when the hardware doesn't generate interrupts - at the period boundary but do timer-interrupts at the fixed + This happense when the hardware doesn't generate interrupts + at the period boundary but issues timer interrupts at a fixed timer rate (e.g. es1968 or ymfpci drivers). In this case, you need to check the current hardware - position and accumulates the processed sample length at each - interrupt. When the accumulated size overcomes the period + position and accumulate the processed sample length at each + interrupt. When the accumulated size exceeds the period size, call snd_pcm_period_elapsed() and reset the accumulator. - A typical coding would be like the following. + Typical code would be like the following. Interrupt Handler Case #2 @@ -3178,32 +3179,33 @@ struct _snd_pcm_runtime {
Atomicity - One of the most important (and thus difficult to debug) problem - on the kernel programming is the race condition. - On linux kernel, usually it's solved via spin-locks or - semaphores. In general, if the race condition may - happen in the interrupt handler, it's handled as atomic, and you - have to use spinlock for protecting the critical session. If it - never happens in the interrupt and it may take relatively long - time, you should use semaphore. + One of the most important (and thus difficult to debug) problems + in kernel programming are race conditions. + In the Linux kernel, they are usually avoided via spin-locks, mutexes + or semaphores. In general, if a race condition can happen + in an interrupt handler, it has to be managed atomically, and you + have to use a spinlock to protect the critical session. If the + critical section is not in interrupt handler code and + if taking a relatively long time to execute is acceptable, you + should use mutexes or semaphores instead. As already seen, some pcm callbacks are atomic and some are - not. For example, hw_params callback is + not. For example, the hw_params callback is non-atomic, while trigger callback is atomic. This means, the latter is called already in a spinlock held by the PCM middle layer. Please take this atomicity into - account when you use a spinlock or a semaphore in the callbacks. + account when you choose a locking scheme in the callbacks. In the atomic callbacks, you cannot use functions which may call schedule or go to - sleep. The semaphore and mutex do sleep, + sleep. Semaphores and mutexes can sleep, and hence they cannot be used inside the atomic callbacks (e.g. trigger callback). - For taking a certain delay in such a callback, please use + To implement some delay in such a callback, please use udelay() or mdelay(). @@ -3257,7 +3259,7 @@ struct _snd_pcm_runtime { There are many different constraints. - Look in sound/pcm.h for a complete list. + Look at sound/pcm.h for a complete list. You can even define your own constraint rules. For example, let's suppose my_chip can manage a substream of 1 channel if and only if the format is S16_LE, otherwise it supports any format @@ -3346,7 +3348,7 @@ struct _snd_pcm_runtime { - I won't explain more details here, rather I + I won't give more details here, rather I would like to say, Luke, use the source.
@@ -3364,10 +3366,9 @@ struct _snd_pcm_runtime { General The control interface is used widely for many switches, - sliders, etc. which are accessed from the user-space. Its most - important use is the mixer interface. In other words, on ALSA - 0.9.x, all the mixer stuff is implemented on the control kernel - API (while there was an independent mixer kernel API on 0.5.x). + sliders, etc. which are accessed from user-space. Its most + important use is the mixer interface. In other words, since ALSA + 0.9.x, all the mixer stuff is implemented on the control kernel API. @@ -3379,14 +3380,15 @@ struct _snd_pcm_runtime { The control API is defined in <sound/control.h>. - Include this file if you add your own controls. + Include this file if you want to add your own controls.
Definition of Controls - For creating a new control, you need to define the three + To create a new control, you need to define the + following three callbacks: info, get and put. Then, define a @@ -3414,13 +3416,13 @@ struct _snd_pcm_runtime { Most likely the control is created via snd_ctl_new1(), and in such a case, you can - add __devinitdata prefix to the - definition like above. + add the __devinitdata prefix to the + definition as above. - The iface field specifies the type of - the control, SNDRV_CTL_ELEM_IFACE_XXX, which + The iface field specifies the control + type, SNDRV_CTL_ELEM_IFACE_XXX, which is usually MIXER. Use CARD for global controls that are not logically part of the mixer. @@ -3435,12 +3437,11 @@ struct _snd_pcm_runtime { The name is the name identifier - string. On ALSA 0.9.x, the control name is very important, + string. Since ALSA 0.9.x, the control name is very important, because its role is classified from its name. There are pre-defined standard control names. The details are described in - the subsection - - Control Names. + the + Control Names subsection. @@ -3456,15 +3457,15 @@ struct _snd_pcm_runtime { The access field contains the access type of this control. Give the combination of bit masks, SNDRV_CTL_ELEM_ACCESS_XXX, there. - The detailed will be explained in the subsection - - Access Flags. + The details will be explained in + the + Access Flags subsection. The private_value field contains an arbitrary long integer value for this record. When using - generic info, + the generic info, get and put callbacks, you can pass a value through this field. If several small numbers are necessary, you can @@ -3489,7 +3490,7 @@ struct _snd_pcm_runtime {
Control Names - There are some standards for defining the control names. A + There are some standards to define the control names. A control is usually defined from the three parts as SOURCE DIRECTION FUNCTION. @@ -3497,7 +3498,7 @@ struct _snd_pcm_runtime { The first, SOURCE, specifies the source of the control, and is a string such as Master, - PCM, CD or + PCM, CD and Line. There are many pre-defined sources. @@ -3575,22 +3576,22 @@ struct _snd_pcm_runtime { Access Flags - The access flag is the bit-flags which specifies the access type + The access flag is the bitmask which specifies the access type of the given control. The default access type is SNDRV_CTL_ELEM_ACCESS_READWRITE, which means both read and write are allowed to this control. When the access flag is omitted (i.e. = 0), it is - regarded as READWRITE access as default. + considered as READWRITE access as default. When the control is read-only, pass SNDRV_CTL_ELEM_ACCESS_READ instead. In this case, you don't have to define - put callback. + the put callback. Similarly, when the control is write-only (although it's a rare - case), you can use WRITE flag instead, and - you don't need get callback. + case), you can use the WRITE flag instead, and + you don't need the get callback. @@ -3598,15 +3599,15 @@ struct _snd_pcm_runtime { VOLATILE flag should be given. This means that the control may be changed without - notification. Applications should poll such + notification. Applications should poll such a control constantly. When the control is inactive, set - INACTIVE flag, too. + the INACTIVE flag, too. There are LOCK and - OWNER flags for changing the write + OWNER flags to change the write permissions. @@ -3619,10 +3620,10 @@ struct _snd_pcm_runtime { info callback The info callback is used to get - the detailed information of this control. This must store the + detailed information on this control. This must store the values of the given struct snd_ctl_elem_info object. For example, for a boolean control with a single - element will be: + element: Example of info callback @@ -3653,7 +3654,7 @@ struct _snd_pcm_runtime { volume would have count = 2. The value field is a union, and the values stored are depending on the type. The boolean and - integer are identical. + integer types are identical. @@ -3684,7 +3685,7 @@ struct _snd_pcm_runtime { - Some common info callbacks are prepared for easy use: + Some common info callbacks are available for your convenience: snd_ctl_boolean_mono_info() and snd_ctl_boolean_stereo_info(). Obviously, the former is an info callback for a mono channel @@ -3699,7 +3700,7 @@ struct _snd_pcm_runtime { This callback is used to read the current value of the - control and to return to the user-space. + control and to return to user-space. @@ -3722,11 +3723,11 @@ struct _snd_pcm_runtime { - The value field is depending on - the type of control as well as on info callback. For example, + The value field depends on + the type of control as well as on the info callback. For example, the sb driver uses this field to store the register offset, the bit-shift and the bit-mask. The - private_value is set like + private_value field is set as follows: - In get callback, you have to fill all the elements if the + In the get callback, + you have to fill all the elements if the control has more than one elements, i.e. count > 1. In the example above, we filled only one element @@ -3765,7 +3767,7 @@ struct _snd_pcm_runtime { put callback - This callback is used to write a value from the user-space. + This callback is used to write a value from user-space. @@ -3799,7 +3801,7 @@ struct _snd_pcm_runtime { - Like get callback, + As in the get callback, when the control has more than one elements, all elements must be evaluated in this callback, too. @@ -3817,7 +3819,7 @@ struct _snd_pcm_runtime { Constructor When everything is ready, finally we can create a new - control. For creating a control, there are two functions to be + control. To create a control, there are two functions to be called, snd_ctl_new1() and snd_ctl_add(). @@ -3839,14 +3841,14 @@ struct _snd_pcm_runtime { struct snd_kcontrol_new object defined above, and chip is the object pointer to be passed to kcontrol->private_data - which can be referred in callbacks. + which can be referred to in callbacks. snd_ctl_new1() allocates a new snd_kcontrol instance (that's why the definition of my_control can be with - __devinitdata + the __devinitdata prefix), and snd_ctl_add assigns the given control component to the card. @@ -3941,7 +3943,7 @@ struct _snd_pcm_runtime { General The ALSA AC97 codec layer is a well-defined one, and you don't - have to write many codes to control it. Only low-level control + have to write much code to control it. Only low-level control routines are necessary. The AC97 codec API is defined in <sound/ac97_codec.h>. @@ -4004,7 +4006,7 @@ struct _snd_pcm_runtime {
Constructor - For creating an ac97 instance, first call snd_ac97_bus + To create an ac97 instance, first call snd_ac97_bus with an ac97_bus_ops_t record with callback functions. @@ -4042,12 +4044,12 @@ struct _snd_pcm_runtime { - where chip->ac97 is the pointer of a newly created + where chip->ac97 is a pointer to a newly created ac97_t instance. In this case, the chip pointer is set as the private data, so that the read/write callback functions can refer to this chip instance. This instance is not necessarily stored in the chip - record. When you need to change the register values from the + record. If you need to change the register values from the driver, or need the suspend/resume of ac97 codecs, keep this pointer to pass to the corresponding functions. @@ -4098,7 +4100,7 @@ struct _snd_pcm_runtime { - These callbacks are non-atomic like the callbacks of control API. + These callbacks are non-atomic like the control API callbacks. @@ -4110,14 +4112,14 @@ struct _snd_pcm_runtime { The reset callback is used to reset - the codec. If the chip requires a special way of reset, you can + the codec. If the chip requires a special kind of reset, you can define this callback. - The wait callback is used for a - certain wait at the standard initialization of the codec. If the - chip requires the extra wait-time, define this callback. + The wait callback is used to + add some waiting time in the standard initialization of the codec. If the + chip requires the extra waiting time, define this callback. @@ -4172,7 +4174,7 @@ struct _snd_pcm_runtime { snd_ac97_update_bits() is used to update - some bits of the given register. + some bits in the given register. @@ -4185,7 +4187,7 @@ struct _snd_pcm_runtime { Also, there is a function to change the sample rate (of a - certain register such as + given register such as AC97_PCM_FRONT_DAC_RATE) when VRA or DRA is supported by the codec: snd_ac97_set_rate(). @@ -4200,11 +4202,11 @@ struct _snd_pcm_runtime { - The following registers are available for setting the rate: + The following registers are available to set the rate: AC97_PCM_MIC_ADC_RATE, AC97_PCM_FRONT_DAC_RATE, AC97_PCM_LR_ADC_RATE, - AC97_SPDIF. When the + AC97_SPDIF. When AC97_SPDIF is specified, the register is not really changed but the corresponding IEC958 status bits will be updated. @@ -4214,12 +4216,11 @@ struct _snd_pcm_runtime {
Clock Adjustment - On some chip, the clock of the codec isn't 48000 but using a + In some chips, the clock of the codec isn't 48000 but using a PCI clock (to save a quartz!). In this case, change the field bus->clock to the corresponding value. For example, intel8x0 - and es1968 drivers have the auto-measurement function of the - clock. + and es1968 drivers have their own function to read from the clock.
@@ -4239,15 +4240,13 @@ struct _snd_pcm_runtime { When there are several codecs on the same card, you need to call snd_ac97_mixer() multiple times with ac97.num=1 or greater. The num field - specifies the codec - number. + specifies the codec number.
- If you have set up multiple codecs, you need to either write + If you set up multiple codecs, you either need to write different callbacks for each codec or check - ac97->num in the - callback routines. + ac97->num in the callback routines.
@@ -4271,7 +4270,7 @@ struct _snd_pcm_runtime {
- Some soundchips have similar but a little bit different + Some soundchips have a similar but slightly different implementation of mpu401 stuff. For example, emu10k1 has its own mpu401 routines. @@ -4280,7 +4279,7 @@ struct _snd_pcm_runtime {
Constructor - For creating a rawmidi object, call + To create a rawmidi object, call snd_mpu401_uart_new(). @@ -4307,25 +4306,24 @@ struct _snd_pcm_runtime { - The 4th argument is the i/o port address. Many - backward-compatible MPU401 has an i/o port such as 0x330. Or, it - might be a part of its own PCI i/o region. It depends on the + The 4th argument is the I/O port address. Many + backward-compatible MPU401 have an I/O port such as 0x330. Or, it + might be a part of its own PCI I/O region. It depends on the chip design. - The 5th argument is bitflags for additional information. - When the i/o port address above is a part of the PCI i/o - region, the MPU401 i/o port might have been already allocated + The 5th argument is a bitflag for additional information. + When the I/O port address above is part of the PCI I/O + region, the MPU401 I/O port might have been already allocated (reserved) by the driver itself. In such a case, pass a bit flag MPU401_INFO_INTEGRATED, - and - the mpu401-uart layer will allocate the i/o ports by itself. + and the mpu401-uart layer will allocate the I/O ports by itself. When the controller supports only the input or output MIDI stream, - pass MPU401_INFO_INPUT or + pass the MPU401_INFO_INPUT or MPU401_INFO_OUTPUT bitflag, respectively. Then the rawmidi instance is created as a single stream. @@ -4333,7 +4331,7 @@ struct _snd_pcm_runtime { MPU401_INFO_MMIO bitflag is used to change the access method to MMIO (via readb and writeb) instead of - iob and outb. In this case, you have to pass the iomapped address + iob and outb. In this case, you have to pass the iomapped address to snd_mpu401_uart_new(). @@ -4341,7 +4339,7 @@ struct _snd_pcm_runtime { When MPU401_INFO_TX_IRQ is set, the output stream isn't checked in the default interrupt handler. The driver needs to call snd_mpu401_uart_interrupt_tx() - by itself to start processing the output stream in irq handler. + by itself to start processing the output stream in the irq handler. @@ -4381,7 +4379,7 @@ struct _snd_pcm_runtime { (irq_flags). Otherwise, pass the flags for irq allocation (SA_XXX bits) to it, and the irq will be - reserved by the mpu401-uart layer. If the card doesn't generates + reserved by the mpu401-uart layer. If the card doesn't generate UART interrupts, pass -1 as the irq number. Then a timer interrupt will be invoked for polling. @@ -4392,8 +4390,8 @@ struct _snd_pcm_runtime { When the interrupt is allocated in snd_mpu401_uart_new(), the private - interrupt handler is used, hence you don't have to do nothing - else than creating the mpu401 stuff. Otherwise, you have to call + interrupt handler is used, hence you don't have anything else to do + than creating the mpu401 stuff. Otherwise, you have to call snd_mpu401_uart_interrupt() explicitly when a UART interrupt is invoked and checked in your own interrupt handler. @@ -4480,8 +4478,8 @@ struct _snd_pcm_runtime { The fourth and fifth arguments are the number of output and - input substreams, respectively, of this device. (A substream is - the equivalent of a MIDI port.) + input substreams, respectively, of this device (a substream is + the equivalent of a MIDI port). @@ -4498,7 +4496,7 @@ struct _snd_pcm_runtime { After the rawmidi device is created, you need to set the operators (callbacks) for each substream. There are helper - functions to set the operators for all substream of a device: + functions to set the operators for all the substreams of a device: - If there is more than one substream, you should give each one a - unique name: + If there are more than one substream, you should give a + unique name to each of them: Callbacks - In all callbacks, the private data that you've set for the + In all the callbacks, the private data that you've set for the rawmidi device can be accessed as substream->rmidi->private_data. @@ -4583,8 +4581,8 @@ struct _snd_pcm_runtime { This is called when a substream is opened. - You can initialize the hardware here, but you should not yet - start transmitting/receiving data. + You can initialize the hardware here, but you shouldn't + start transmitting/receiving data yet.
@@ -4632,9 +4630,9 @@ struct _snd_pcm_runtime { To read data from the buffer, call snd_rawmidi_transmit_peek. It will return the number of bytes that have been read; this will be - less than the number of bytes requested when there is no more + less than the number of bytes requested when there are no more data in the buffer. - After the data has been transmitted successfully, call + After the data have been transmitted successfully, call snd_rawmidi_transmit_ack to remove the data from the substream buffer: @@ -4655,7 +4653,7 @@ struct _snd_pcm_runtime { If you know beforehand that the hardware will accept data, you can use the snd_rawmidi_transmit function - which reads some data and removes it from the buffer at once: + which reads some data and removes them from the buffer at once: This is only used with output substreams. This function should wait - until all data read from the substream buffer has been transmitted. + until all data read from the substream buffer have been transmitted. This ensures that the device can be closed and the driver unloaded without losing data. - This callback is optional. If you do not set + This callback is optional. If you do not set drain in the struct snd_rawmidi_ops structure, ALSA will simply wait for 50 milliseconds instead. @@ -4775,24 +4773,24 @@ struct _snd_pcm_runtime {
FM OPL3 - The FM OPL3 is still used on many chips (mainly for backward + The FM OPL3 is still used in many chips (mainly for backward compatibility). ALSA has a nice OPL3 FM control layer, too. The OPL3 API is defined in <sound/opl3.h>. - FM registers can be directly accessed through direct-FM API, + FM registers can be directly accessed through the direct-FM API, defined in <sound/asound_fm.h>. In ALSA native mode, FM registers are accessed through - Hardware-Dependant Device direct-FM extension API, whereas in - OSS compatible mode, FM registers can be accessed with OSS - direct-FM compatible API on /dev/dmfmX device. + the Hardware-Dependant Device direct-FM extension API, whereas in + OSS compatible mode, FM registers can be accessed with the OSS + direct-FM compatible API in /dev/dmfmX device. - For creating the OPL3 component, you have two functions to - call. The first one is a constructor for opl3_t + To create the OPL3 component, you have two functions to + call. The first one is a constructor for the opl3_t instance. @@ -4819,12 +4817,12 @@ struct _snd_pcm_runtime { When the left and right ports have been already allocated by the card driver, pass non-zero to the fifth argument - (integrated). Otherwise, opl3 module will + (integrated). Otherwise, the opl3 module will allocate the specified ports by itself. - When the accessing to the hardware requires special method + When the accessing the hardware requires special method instead of the standard I/O access, you can create opl3 instance separately with snd_opl3_new(). @@ -4845,13 +4843,13 @@ struct _snd_pcm_runtime { access function, the private data and the destructor. The l_port and r_port are not necessarily set. Only the command must be set properly. You can retrieve the data - from opl3->private_data field. + from the opl3->private_data field. After creating the opl3 instance via snd_opl3_new(), call snd_opl3_init() to initialize the chip to the - proper state. Note that snd_opl3_create() always + proper state. Note that snd_opl3_create() always calls it internally. @@ -4884,7 +4882,7 @@ struct _snd_pcm_runtime {
Hardware-Dependent Devices - Some chips need the access from the user-space for special + Some chips need user-space access for special controls or for loading the micro code. In such a case, you can create a hwdep (hardware-dependent) device. The hwdep API is defined in <sound/hwdep.h>. You can @@ -4893,7 +4891,7 @@ struct _snd_pcm_runtime { - Creation of the hwdep instance is done via + The creation of the hwdep instance is done via snd_hwdep_new(). @@ -4912,8 +4910,8 @@ struct _snd_pcm_runtime { You can then pass any pointer value to the private_data. If you assign a private data, you should define the - destructor, too. The destructor function is set to - private_free field. + destructor, too. The destructor function is set in + the private_free field. @@ -4925,7 +4923,7 @@ struct _snd_pcm_runtime { - and the implementation of destructor would be: + and the implementation of the destructor would be: @@ -4943,7 +4941,7 @@ struct _snd_pcm_runtime { The arbitrary file operations can be defined for this instance. The file operators are defined in - ops table. For example, assume that + the ops table. For example, assume that this chip needs an ioctl. @@ -4964,7 +4962,7 @@ struct _snd_pcm_runtime { IEC958 (S/PDIF) Usually the controls for IEC958 devices are implemented via - control interface. There is a macro to compose a name string for + the control interface. There is a macro to compose a name string for IEC958 controls, SNDRV_CTL_NAME_IEC958() defined in <include/asound.h>. @@ -4973,7 +4971,7 @@ struct _snd_pcm_runtime { There are some standard controls for IEC958 status bits. These controls use the type SNDRV_CTL_ELEM_TYPE_IEC958, and the size of element is fixed as 4 bytes array - (value.iec958.status[x]). For info + (value.iec958.status[x]). For the info callback, you don't specify the value field for this type (the count field must be set, though). @@ -5001,7 +4999,7 @@ struct _snd_pcm_runtime { enable/disable or to set the raw bit mode. The implementation will depend on the chip, but the control should be named as IEC958 xxx, preferably using - SNDRV_CTL_NAME_IEC958() macro. + the SNDRV_CTL_NAME_IEC958() macro. @@ -5036,12 +5034,12 @@ struct _snd_pcm_runtime { The allocation of pages with fallback is snd_malloc_xxx_pages_fallback(). This function tries to allocate the specified pages but if the pages - are not available, it tries to reduce the page sizes until the + are not available, it tries to reduce the page sizes until enough space is found. - For releasing the space, call + The release the pages, call snd_free_xxx_pages() function. @@ -5050,8 +5048,8 @@ struct _snd_pcm_runtime { a large contiguous physical space at the time the module is loaded for the later use. This is called pre-allocation. - As already written, you can call the following function at the - construction of pcm instance (in the case of PCI bus). + As already written, you can call the following function at + pcm instance construction time (in the case of PCI bus). @@ -5063,34 +5061,34 @@ struct _snd_pcm_runtime { where size is the byte size to be - pre-allocated and the max is the maximal - size to be changed via prealloc proc file. - The allocator will try to get as large area as possible + pre-allocated and the max is the maximum + size to be changed via the prealloc proc file. + The allocator will try to get an area as large as possible within the given size. The second argument (type) and the third argument (device pointer) are dependent on the bus. - In the case of ISA bus, pass snd_dma_isa_data() + In the case of the ISA bus, pass snd_dma_isa_data() as the third argument with SNDRV_DMA_TYPE_DEV type. For the continuous buffer unrelated to the bus can be pre-allocated with SNDRV_DMA_TYPE_CONTINUOUS type and the snd_dma_continuous_data(GFP_KERNEL) device pointer, - whereh GFP_KERNEL is the kernel allocation flag to + where GFP_KERNEL is the kernel allocation flag to use. For the SBUS, SNDRV_DMA_TYPE_SBUS and snd_dma_sbus_data(sbus_dev) are used instead. For the PCI scatter-gather buffers, use SNDRV_DMA_TYPE_DEV_SG with snd_dma_pci_data(pci) - (see the section + (see the Non-Contiguous Buffers - ). + section). - Once when the buffer is pre-allocated, you can use the - allocator in the hw_params callback + Once the buffer is pre-allocated, you can use the + allocator in the hw_params callback: @@ -5116,8 +5114,8 @@ struct _snd_pcm_runtime { - The first case works fine if the external hardware buffer is enough - large. This method doesn't need any extra buffers and thus is + The first case works fine if the external hardware buffer is large + enough. This method doesn't need any extra buffers and thus is more effective. You need to define the copy and silence callbacks for @@ -5127,25 +5125,25 @@ struct _snd_pcm_runtime { - The second case allows the mmap of the buffer, although you have - to handle an interrupt or a tasklet for transferring the data + The second case allows for mmap on the buffer, although you have + to handle an interrupt or a tasklet to transfer the data from the intermediate buffer to the hardware buffer. You can find an - example in vxpocket driver. + example in the vxpocket driver. - Another case is that the chip uses a PCI memory-map + Another case is when the chip uses a PCI memory-map region for the buffer instead of the host memory. In this case, - mmap is available only on certain architectures like intel. In - non-mmap mode, the data cannot be transferred as the normal - way. Thus you need to define copy and - silence callbacks as well + mmap is available only on certain architectures like the Intel one. + In non-mmap mode, the data cannot be transferred as in the normal + way. Thus you need to define the copy and + silence callbacks as well, as in the cases above. The examples are found in rme32.c and rme96.c. - The implementation of copy and + The implementation of the copy and silence callbacks depends upon whether the hardware supports interleaved or non-interleaved samples. The copy callback is @@ -5184,8 +5182,8 @@ struct _snd_pcm_runtime { What you have to do in this callback is again different - between playback and capture directions. In the case of - playback, you do: copy the given amount of data + between playback and capture directions. In the + playback case, you copy the given amount of data (count) at the specified pointer (src) to the specified offset (pos) on the hardware buffer. When @@ -5202,7 +5200,7 @@ struct _snd_pcm_runtime { - For the capture direction, you do: copy the given amount of + For the capture direction, you copy the given amount of data (count) at the specified offset (pos) on the hardware buffer to the specified pointer (dst). @@ -5216,7 +5214,7 @@ struct _snd_pcm_runtime { - Note that both of the position and the data amount are given + Note that both the position and the amount of data are given in frames. @@ -5247,7 +5245,7 @@ struct _snd_pcm_runtime { - The meanings of arguments are identical with the + The meanings of arguments are the same as in the copy callback, although there is no src/dst argument. In the case of interleaved samples, the channel @@ -5284,8 +5282,8 @@ struct _snd_pcm_runtime {
Non-Contiguous Buffers - If your hardware supports the page table like emu10k1 or the - buffer descriptors like via82xx, you can use the scatter-gather + If your hardware supports the page table as in emu10k1 or the + buffer descriptors as in via82xx, you can use the scatter-gather (SG) DMA. ALSA provides an interface for handling SG-buffers. The API is provided in <sound/pcm.h>. @@ -5296,7 +5294,7 @@ struct _snd_pcm_runtime { snd_pcm_lib_preallocate_pages_for_all() with SNDRV_DMA_TYPE_DEV_SG in the PCM constructor like other PCI pre-allocator. - You need to pass the snd_dma_pci_data(pci), + You need to pass snd_dma_pci_data(pci), where pci is the struct pci_dev pointer of the chip as well. The struct snd_sg_buf instance is created as @@ -5314,7 +5312,7 @@ struct _snd_pcm_runtime { Then call snd_pcm_lib_malloc_pages() - in hw_params callback + in the hw_params callback as well as in the case of normal PCI buffer. The SG-buffer handler will allocate the non-contiguous kernel pages of the given size and map them onto the virtually contiguous @@ -5335,7 +5333,7 @@ struct _snd_pcm_runtime { - For releasing the data, call + To release the data, call snd_pcm_lib_free_pages() in the hw_free callback as usual. @@ -5390,7 +5388,7 @@ struct _snd_pcm_runtime { - For creating a proc file, call + To create a proc file, call snd_card_proc_new(). @@ -5402,7 +5400,7 @@ struct _snd_pcm_runtime { - where the second argument specifies the proc-file name to be + where the second argument specifies the name of the proc file to be created. The above example will create a file my-file under the card directory, e.g. /proc/asound/card0/my-file. @@ -5417,8 +5415,8 @@ struct _snd_pcm_runtime { When the creation is successful, the function stores a new - instance at the pointer given in the third argument. - It is initialized as a text proc file for read only. For using + instance in the pointer given in the third argument. + It is initialized as a text proc file for read only. To use this proc file as a read-only text file as it is, set the read callback with a private data via snd_info_set_text_ops(). @@ -5470,9 +5468,9 @@ struct _snd_pcm_runtime { - The file permission can be changed afterwards. As default, it's - set as read only for all users. If you want to add the write - permission to the user (root as default), set like below: + The file permissions can be changed afterwards. As default, it's + set as read only for all users. If you want to add write + permission for the user (root as default), do as follows: @@ -5503,7 +5501,7 @@ struct _snd_pcm_runtime { - For a raw-data proc-file, set the attributes like the following: + For a raw-data proc-file, set the attributes as follows: @@ -5524,7 +5522,7 @@ struct _snd_pcm_runtime { The callback is much more complicated than the text-file - version. You need to use a low-level i/o functions such as + version. You need to use a low-level I/O functions such as copy_from/to_user() to transfer the data. @@ -5560,28 +5558,28 @@ struct _snd_pcm_runtime { Power Management If the chip is supposed to work with suspend/resume - functions, you need to add the power-management codes to the - driver. The additional codes for the power-management should be + functions, you need to add power-management code to the + driver. The additional code for power-management should be ifdef'ed with CONFIG_PM. - If the driver supports the suspend/resume - fully, that is, the device can be - properly resumed to the status at the suspend is called, - you can set SNDRV_PCM_INFO_RESUME flag - to pcm info field. Usually, this is possible when the - registers of ths chip can be safely saved and restored to the - RAM. If this is set, the trigger callback is called with - SNDRV_PCM_TRIGGER_RESUME after resume - callback is finished. + If the driver fully supports suspend/resume + that is, the device can be + properly resumed to its state when suspend was called, + you can set the SNDRV_PCM_INFO_RESUME flag + in the pcm info field. Usually, this is possible when the + registers of the chip can be safely saved and restored to + RAM. If this is set, the trigger callback is called with + SNDRV_PCM_TRIGGER_RESUME after the resume + callback completes. - Even if the driver doesn't support PM fully but only the - partial suspend/resume is possible, it's still worthy to - implement suspend/resume callbacks. In such a case, applications + Even if the driver doesn't support PM fully but + partial suspend/resume is still possible, it's still worthy to + implement suspend/resume callbacks. In such a case, applications would reset the status by calling snd_pcm_prepare() and restart the stream appropriately. Hence, you can define suspend/resume callbacks @@ -5590,22 +5588,22 @@ struct _snd_pcm_runtime { - Note that the trigger with SUSPEND can be always called when + Note that the trigger with SUSPEND can always be called when snd_pcm_suspend_all is called, - regardless of SNDRV_PCM_INFO_RESUME flag. + regardless of the SNDRV_PCM_INFO_RESUME flag. The RESUME flag affects only the behavior of snd_pcm_resume(). (Thus, in theory, SNDRV_PCM_TRIGGER_RESUME isn't needed to be handled in the trigger callback when no SNDRV_PCM_INFO_RESUME flag is set. But, - it's better to keep it for compatibility reason.) + it's better to keep it for compatibility reasons.) In the earlier version of ALSA drivers, a common power-management layer was provided, but it has been removed. The driver needs to define the suspend/resume hooks according to - the bus the device is assigned. In the case of PCI driver, the + the bus the device is connected to. In the case of PCI drivers, the callbacks look like below: @@ -5629,7 +5627,7 @@ struct _snd_pcm_runtime { - The scheme of the real suspend job is as following. + The scheme of the real suspend job is as follows. Retrieve the card and the chip data. @@ -5679,11 +5677,11 @@ struct _snd_pcm_runtime { - The scheme of the real resume job is as following. + The scheme of the real resume job is as follows. Retrieve the card and the chip data. - Set up PCI. First, call pci_restore_state(). + Set up PCI. First, call pci_restore_state(). Then enable the pci device again by calling pci_enable_device(). Call pci_set_master() if necessary, too. Re-initialize the chip. @@ -5734,7 +5732,7 @@ struct _snd_pcm_runtime { snd_pcm_suspend_all() or snd_pcm_suspend(). It means that the PCM streams are already stoppped when the register snapshot is - taken. But, remind that you don't have to restart the PCM + taken. But, remember that you don't have to restart the PCM stream in the resume callback. It'll be restarted via trigger call with SNDRV_PCM_TRIGGER_RESUME when necessary. @@ -5795,7 +5793,7 @@ struct _snd_pcm_runtime { - If you need a space for saving the registers, allocate the + If you need a space to save the registers, allocate the buffer for it here, too, since it would be fatal if you cannot allocate a memory in the suspend phase. The allocated buffer should be released in the corresponding @@ -5833,7 +5831,7 @@ struct _snd_pcm_runtime { Module Parameters There are standard module options for ALSA. At least, each - module should have index, + module should have the index, id and enable options. @@ -5841,8 +5839,8 @@ struct _snd_pcm_runtime { If the module supports multiple cards (usually up to 8 = SNDRV_CARDS cards), they should be - arrays. The default initial values are defined already as - constants for ease of programming: + arrays. The default initial values are defined already as + constants for easier programming: @@ -5858,7 +5856,7 @@ struct _snd_pcm_runtime { If the module supports only a single card, they could be single variables, instead. enable option is not - always necessary in this case, but it wouldn't be so bad to have a + always necessary in this case, but it would be better to have a dummy option for compatibility. @@ -5923,22 +5921,22 @@ struct _snd_pcm_runtime { - Suppose that you'll create a new PCI driver for the card + Suppose that you create a new PCI driver for the card xyz. The card module name would be - snd-xyz. The new driver is usually put into alsa-driver + snd-xyz. The new driver is usually put into the alsa-driver tree, alsa-driver/pci directory in the case of PCI cards. Then the driver is evaluated, audited and tested by developers and users. After a certain time, the driver - will go to alsa-kernel tree (to the corresponding directory, + will go to the alsa-kernel tree (to the corresponding directory, such as alsa-kernel/pci) and eventually - integrated into Linux 2.6 tree (the directory would be + will be integrated into the Linux 2.6 tree (the directory would be linux/sound/pci). In the following sections, the driver code is supposed - to be put into alsa-driver tree. The two cases are assumed: + to be put into alsa-driver tree. The two cases are covered: a driver consisting of a single source file and one consisting of several source files. @@ -6033,7 +6031,7 @@ struct _snd_pcm_runtime { Add a new directory (xyz) in - alsa-driver/pci/Makefile like below + alsa-driver/pci/Makefile as below @@ -6102,7 +6100,7 @@ struct _snd_pcm_runtime {
<function>snd_printk()</function> and friends - ALSA provides a verbose version of + ALSA provides a verbose version of the printk() function. If a kernel config CONFIG_SND_VERBOSE_PRINTK is set, this function prints the given message together with the file name @@ -6170,7 +6168,7 @@ struct _snd_pcm_runtime {
<function>snd_BUG()</function> - It shows BUG? message and + It shows the BUG? message and stack trace as well as snd_assert at the point. It's useful to show that a fatal error happens there. @@ -6199,6 +6197,4 @@ struct _snd_pcm_runtime { in the hardware constraints section. - -