Add SPI devices to ALSA Kconfig and Makefile
PATCH 1/2 Add SPI devices to ALSA Kconfig and Makefile
This patch adds SPI devices in the ALSA diretory, including the Kconfig and Makefile.
--- sound/Kconfig | 6 +++++- sound/Makefile | 3 ++- sound/spi/Kconfig | 6 ++++++ sound/spi/Makefile | 2 ++ 4 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 sound/spi/Kconfig create mode 100644 sound/spi/Makefile
sound/Kconfig +5 -1
@@ -63,9 +63,13 @@ source "sound/aoa/Kconfig" source "sound/arm/Kconfig" +if SPI +source "sound/spi/Kconfig" +endif + source "sound/mips/Kconfig" -# the following will depend on the order of config. +# tee following will depend on the order of config. # here assuming USB is defined before ALSA source "sound/usb/Kconfig"
sound/Makefile +2 -1
@@ -5,7 +5,8 @@ obj-$(CONFIG_SOUND) += soundcore.o obj-$(CONFIG_SOUND_PRIME) += sound_firmware.o obj-$(CONFIG_SOUND_PRIME) += oss/ obj-$(CONFIG_DMASOUND) += oss/ -obj-$(CONFIG_SND) += core/ i2c/ drivers/ isa/ pci/ ppc/ arm/ synth/ usb/ sparc/ parisc/ pcmcia/ mips/ soc/ +obj-$(CONFIG_SND) += core/ i2c/ drivers/ isa/ pci/ ppc/ arm/ synth/ usb/ \ + sparc/ spi/ parisc/ pcmcia/ mips/ soc/ obj-$(CONFIG_SND_AOA) += aoa/ # This one must be compilable even if sound is configured out
sound/spi/Kconfig new file +6 -0
@@ -0,0 +1,6 @@ +#SPI drivers + +menu "SPI devices" + depends on SND != n + +endmenu
sound/spi/Makefile new file +2 -0
@@ -0,0 +1,2 @@ +# Makefile for SPI drivers +
Signature · 1 line
1.5.2.3
PATCH 2/2 ALSA sound driver for the AT73C213 DAC using Atmel SSC driver
This patch adds support for the AT73C213 DAC using the misc Atmel SSC driver in I2S mode. The driver also requires a SPI to setup the registers and control volume.
It has been tested with an AT32AP7000 on the ATSTK1000 development board. The driver should also work with any Atmel device with an SSC module supported by the Atmel SSC driver (atmel-ssc).
The atmel-ssc driver is just submitted to the Linux kernel. Please see mail thread http://lkml.org/lkml/2007/7/16/32
--- include/linux/spi/at73c213.h | 25 + sound/spi/Kconfig | 25 + sound/spi/Makefile | 3 + sound/spi/at73c213.c | 1128 ++++++++++++++++++++++++++++++++++++++++++ sound/spi/at73c213.h | 119 +++++ 5 files changed, 1300 insertions(+), 0 deletions(-) create mode 100644 include/linux/spi/at73c213.h create mode 100644 sound/spi/at73c213.c create mode 100644 sound/spi/at73c213.h
include/linux/spi/at73c213.h new file +25 -0
@@ -0,0 +1,25 @@ +/* +* Board-specific data used to set up AT73c213 audio DAC driver. +*/ + +#ifndef __LINUX_SPI_AT73C213_H +#define __LINUX_SPI_AT73C213_H + +/** +* at73c213_board_info - how the external DAC is wired to the device. +* +* @ssc_id: SSC platform_driver id the DAC shall use to stream the audio. +* @dac_clk: the external clock used to provide master clock to the DAC. +* @shortname: a short discription for the DAC, seen by userspace tools. +* +* This struct contains the configuration of the hardware connection to the +* external DAC. The DAC needs a master clock and a I2S audio stream. It also +* provides a name which is used to identify it in userspace tools. +*/ +struct at73c213_board_info { +int ssc_id; +struct clk *dac_clk; +char shortname[32 ]; +}; + +#endif /* __LINUX_SPI_AT73C213_H */
sound/spi/Kconfig +25 -0
@@ -3,4 +3,29 @@ menu "SPI devices" depends on SND != n +config SND_AT73C213 + tristate "Atmel AT73C213 DAC driver" + depends on ATMEL_SSC + select SND_PCM + help + Say Y here if you want to use the Atmel AT73C213 external DAC. This + DAC can be found on Atmel development boards. + + This driver requires the Atmel SSC driver for sound sink, a + peripheral found on most AT91 and AVR32 microprocessors. + + To compile this driver as a module, choose M here: the module will be + called snd-at73c213. + +config SND_AT73C213_TARGET_BITRATE + int "Target bitrate for AT73C213" + depends on SND_AT73C213 + default "48000" + range 8000 50000 + help + Sets the target bitrate for the bitrate calculator in the driver. + Limited by hardware to be between 8000 Hz and 50000 Hz. + + Set to 48000 Hz by default. + endmenu
sound/spi/Makefile +3 -0
@@ -1,2 +1,5 @@ # Makefile for SPI drivers +snd-at73c213-objs := at73c213.o + +obj-$(CONFIG_SND_AT73C213) += snd-at73c213.o
sound/spi/at73c213.c new file +1128 -0
1,128 lines not on this page · raw message
sound/spi/at73c213.h new file +119 -0
119 lines not on this page · raw message
Signature · 1 line
1.5.2.3
Re: [PATCH 2/2] ALSA sound driver for the AT73C213 DAC using Atmel SSC driver
At Mon, 16 Jul 2007 16:14:59 +0200,
Quoted 5 lines · Hans-Christian Egtvedt
This patch adds support for the AT73C213 DAC using the misc Atmel SSC driver in I2S mode. The driver also requires a SPI to setup the registers and control volume.
Quoted 8 lines
It has been tested with an AT32AP7000 on the ATSTK1000 development board. The driver should also work with any Atmel device with an SSC module supported by the Atmel SSC driver (atmel-ssc).
The atmel-ssc driver is just submitted to the Linux kernel. Please see mail thread http://lkml.org/lkml/2007/7/16/32
Signed-off-by Hans-Christian Egtvedt <[email protected]>
Are these intended to be merged to 2.6.23 kernel?
Takashi
Re: [PATCH 2/2] ALSA sound driver for the AT73C213 DAC using Atmel SSC driver
Quoted 11 lines · Takashi Iwai
At Mon, 16 Jul 2007 16:14:59 +0200,
Quoted 9 lines · Hans-Christian Egtvedt
This patch adds support for the AT73C213 DAC using the misc Atmel SSC driver in I2S mode. The driver also requires a SPI to setup the registers and control volume.
It has been tested with an AT32AP7000 on the ATSTK1000 development board. The driver should also work with any Atmel device with an SSC module supported by the Atmel SSC driver (atmel-ssc).
Quoted 6 lines
Quoted 4 lines
The atmel-ssc driver is just submitted to the Linux kernel. Please see mail thread http://lkml.org/lkml/2007/7/16/32
Signed-off-by Hans-Christian Egtvedt <[email protected]>Are these intended to be merged to 2.6.23 kernel?
I would prefer that yes. AFAIK alsa-devel@ is the correct list for the sound drivers?
Signature · 4 lines
With kind regards, Hans-Christian Egtvedt, siv.ing. (M.Sc.) Applications Engineer - AVR32 System Solutions - Atmel Norway
Re: [PATCH 2/2] ALSA sound driver for the AT73C213 DAC using Atmel SSC driver
At Mon, 16 Jul 2007 16:25:28 +0200,
Quoted 17 lines · Hans-Christian Egtvedt
Quoted 14 lines · Takashi Iwai
At Mon, 16 Jul 2007 16:14:59 +0200,
Quoted 12 lines · Hans-Christian Egtvedt
This patch adds support for the AT73C213 DAC using the misc Atmel SSC driver in I2S mode. The driver also requires a SPI to setup the registers and control volume.
It has been tested with an AT32AP7000 on the ATSTK1000 development board. The driver should also work with any Atmel device with an SSC module supported by the Atmel SSC driver (atmel-ssc).
The atmel-ssc driver is just submitted to the Linux kernel. Please see mail thread http://lkml.org/lkml/2007/7/16/32
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Hans-Christian Egtvedt <[email protected]>Are these intended to be merged to 2.6.23 kernel?
I would prefer that yes. AFAIK alsa-devel@ is the correct list for the sound drivers?
Yes. Then the questions are:
- the driver is mature enough for the upstream merge,
- whether it's built and tested on the latest 2.6.22 (or more prefarably on the latest git) tree
If they are all OK, I'm willing to merge soon.
thanks,
Takashi
Re: [PATCH 2/2] ALSA sound driver for the AT73C213 DAC using Atmel SSC driver
At Mon, 16 Jul 2007 16:30:56 +0200,
Quoted 24 lines · I wrote:
At Mon, 16 Jul 2007 16:25:28 +0200,
Quoted 21 lines · Hans-Christian Egtvedt
Quoted 17 lines · Takashi Iwai
At Mon, 16 Jul 2007 16:14:59 +0200,
Quoted 5 lines · Hans-Christian Egtvedt
This patch adds support for the AT73C213 DAC using the misc Atmel SSC driver in I2S mode. The driver also requires a SPI to setup the registers and control volume.
Quoted 8 lines
It has been tested with an AT32AP7000 on the ATSTK1000 development board. The driver should also work with any Atmel device with an SSC module supported by the Atmel SSC driver (atmel-ssc).
The atmel-ssc driver is just submitted to the Linux kernel. Please see mail thread http://lkml.org/lkml/2007/7/16/32
Signed-off-by Hans-Christian Egtvedt <[email protected]>Are these intended to be merged to 2.6.23 kernel?
Quoted 7 lines
Quoted 2 lines
I would prefer that yes. AFAIK alsa-devel@ is the correct list for the sound drivers?
Yes. Then the questions are:
- the driver is mature enough for the upstream merge,
- whether it's built and tested on the latest 2.6.22 (or more prefarably on the latest git) tree
Also,
- whether atmel-ssc driver would be merged to 2.6.23, too (otherwise it makes no sense to merge only the corresponding ALSA driver)
Takashi
Re: [PATCH 2/2] ALSA sound driver for the AT73C213 DAC using Atmel SSC driver
Quoted 10 lines · Takashi Iwai
At Mon, 16 Jul 2007 16:30:56 +0200,
Quoted 8 lines · I wrote:
At Mon, 16 Jul 2007 16:25:28 +0200,
Quoted 5 lines · Hans-Christian Egtvedt
Quoted 2 lines · Takashi Iwai
At Mon, 16 Jul 2007 16:14:59 +0200,
Hans-Christian Egtvedt wrote:
<cut driver description>
Quoted 10 lines
Quoted 9 lines
Quoted 4 lines
Quoted 1 line
Are these intended to be merged to 2.6.23 kernel?
I would prefer that yes. AFAIK alsa-devel@ is the correct list for the sound drivers?
Yes. Then the questions are:
- the driver is mature enough for the upstream merge,
- whether it's built and tested on the latest 2.6.22 (or more prefarably on the latest git) tree
Quoted 5 lines
Also,
- whether atmel-ssc driver would be merged to 2.6.23, too (otherwise it makes no sense to merge only the corresponding ALSA driver)
Agree, I have no feedback on the atmel-ssc driver yet. It should be a trivial addition the the kernel.
Signature · 4 lines
With kind regards, Hans-Christian Egtvedt, siv.ing. (M.Sc.) Applications Engineer - AVR32 System Solutions - Atmel Norway
Re: [PATCH 2/2] ALSA sound driver for the AT73C213 DAC using Atmel SSC driver
At Mon, 16 Jul 2007 16:46:58 +0200,
Quoted 26 lines · Hans-Christian Egtvedt
Quoted 10 lines · Takashi Iwai
At Mon, 16 Jul 2007 16:30:56 +0200,
Quoted 8 lines · I wrote:
At Mon, 16 Jul 2007 16:25:28 +0200,
Quoted 5 lines · Hans-Christian Egtvedt
Quoted 2 lines · Takashi Iwai
At Mon, 16 Jul 2007 16:14:59 +0200,
Hans-Christian Egtvedt wrote:<cut driver description>
Quoted 10 lines
Quoted 9 lines
Quoted 4 lines
Quoted 1 line
Are these intended to be merged to 2.6.23 kernel?
I would prefer that yes. AFAIK alsa-devel@ is the correct list for the sound drivers?
Yes. Then the questions are:
- the driver is mature enough for the upstream merge,
- whether it's built and tested on the latest 2.6.22 (or more prefarably on the latest git) tree
Quoted 8 lines
Quoted 5 lines
Also,
- whether atmel-ssc driver would be merged to 2.6.23, too (otherwise it makes no sense to merge only the corresponding ALSA driver)
Agree, I have no feedback on the atmel-ssc driver yet. It should be a trivial addition the the kernel.
OK, that's the dragging point. So far I don't see it on linus git tree yet, too.
Takashi
Re: [PATCH 2/2] ALSA sound driver for the AT73C213 DAC using Atmel SSC driver
In reply to Takashi IwaiQuoted 21 lines · Takashi Iwai
At Mon, 16 Jul 2007 16:25:28 +0200,
Quoted 19 lines · Hans-Christian Egtvedt
Quoted 16 lines · Takashi Iwai
At Mon, 16 Jul 2007 16:14:59 +0200,
Quoted 13 lines · Hans-Christian Egtvedt
This patch adds support for the AT73C213 DAC using the misc Atmel SSC driver in I2S mode. The driver also requires a SPI to setup the registers and control volume.
It has been tested with an AT32AP7000 on the ATSTK1000 development board. The driver should also work with any Atmel device with an SSC module supported by the Atmel SSC driver (atmel-ssc).
The atmel-ssc driver is just submitted to the Linux kernel. Please see mail thread http://lkml.org/lkml/2007/7/16/32
Signed-off-by Hans-Christian Egtvedt <[email protected]>
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Are these intended to be merged to 2.6.23 kernel?
I would prefer that yes. AFAIK alsa-devel@ is the correct list for the sound drivers?
Yes. Then the questions are:
- the driver is mature enough for the upstream merge,
The first driver was made for Linux 2.6.16, and since then I have forward ported it to the never kernels.
We have done some internal code review of this driver as well, so I feel confident that it is mature enough for upstream.
Quoted 2 lines
- whether it's built and tested on the latest 2.6.22 (or more prefarably on the latest git) tree
It is based on Linux 2.6.22 + additional AVR32 patches which does not affect ALSA.
The driver also needs the atmel-ssc driver I submitted to the kernel list earlier today. I hope that also will make it for the 2.6.22 cut.
Quoted 1 line
If they are all OK, I'm willing to merge soon.
Sound nice, let me know if you have any problems merging it into the ALSA tree.
Signature · 4 lines
With kind regards, Hans-Christian Egtvedt, siv.ing. (M.Sc.) Applications Engineer - AVR32 System Solutions - Atmel Norway
Re: [PATCH 2/2] ALSA sound driver for the AT73C213 DAC using Atmel SSC driver
At Mon, 16 Jul 2007 16:43:34 +0200,
Quoted 8 lines · Hans-Christian Egtvedt
Quoted 2 lines
- the driver is mature enough for the upstream merge,
The first driver was made for Linux 2.6.16, and since then I have forward ported it to the never kernels.
We have done some internal code review of this driver as well, so I feel confident that it is mature enough for upstream.
Good.
Quoted 5 lines
Quoted 2 lines
- whether it's built and tested on the latest 2.6.22 (or more prefarably on the latest git) tree
It is based on Linux 2.6.22 + additional AVR32 patches which does not affect ALSA.
Fine, too.
Then I'll give you a quick review back.
thanks,
Takashi
Re: [PATCH 2/2] ALSA sound driver for the AT73C213 DAC using Atmel SSC driver
In reply to Hans-Christian EgtvedtAt Mon, 16 Jul 2007 16:14:59 +0200,
Quoted 19 lines · Hans-Christian Egtvedt
include/linux/spi/at73c213.h new file +15
-0@@ -0,0 +1,25 @@ +/* +* Board-specific data used to set up AT73c213 audio DAC driver. +*/ + +#ifndef __LINUX_SPI_AT73C213_H +#define __LINUX_SPI_AT73C213_H + +/** +* at73c213_board_info - how the external DAC is wired to the device. +* +* @ssc_id: SSC platform_driver id the DAC shall use to stream the audio. +* @dac_clk: the external clock used to provide master clock to the DAC. +* @shortname: a short discription for the DAC, seen by userspace tools. +* +* This struct contains the configuration of the hardware connection to the
include/linux/spi/at73c213.h line 25
Quoted 10 lines
include/linux/spi/at73c213.h new file +10
-0+* external DAC. The DAC needs a master clock and a I2S audio stream. It also +* provides a name which is used to identify it in userspace tools. +*/ +struct at73c213_board_info { +int ssc_id; +struct clk *dac_clk; +char shortname[32 ]; +}; + +#endif /* __LINUX_SPI_AT73C213_H */
Any reason to put this into include/linux? Are (or will be) there users of this except for ALSA driver?
Quoted 5 lines
sound/spi/at73c213.c new file +0
-0
(snip)
Quoted 1 line
+#include <
linux/kmod.h>
Unneeded.
sound/spi/at73c213.c line 26
Quoted 6 lines
sound/spi/at73c213.c new file +6
-0+#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/io.h> + +#include <sound/initval.h> +#include <sound/driver.h>
Please put sound/driver.h at first. This will make it for us much easier to maintain the out-of-kernel tree.
Quoted 23 lines
sound/spi/at73c213.c new file +23
-0+/* +* Calculate and set bitrate and divisions. +*/ +static int snd_at73c213_set_bitrate (struct snd_at73c213 *chip) +{ +unsigned long ssc_rate =clk_get_rate (chip->ssc->clk); +unsigned long dac_rate_new, ssc_div, status; +unsigned long ssc_div_max, ssc_div_min; +int max_tries; + +/* +* We connect two clocks here, picking divisors so the I2S clocks +* out data at the same rate the DAC clocks it in ... and as close +* as practical to the desired target rate. +* +* The DAC master clock (MCLK) is programmable, and is either 256 +* or (not here) 384 times the I2S output clock (BCLK). +*/ + +/* SSC clock / (bitrate * stereo * 16-bit). */ + ssc_div = ssc_rate / (BITRATE_TARGET *2 *16 ); + ssc_div_min = ssc_rate / (BITRATE_MAX *2 *16 ); + ssc_div_max = ssc_rate / (BITRATE_MIN *2 *16 );
sound/spi/at73c213.c line 161
Quoted 10 lines
sound/spi/at73c213.c new file +10
-0+ max_tries = (ssc_div_max - ssc_div_min) /2 ; + +/* ssc_div must be a power of 2. */ + ssc_div = (ssc_div +1 ) & ~1UL ; + +if ((ssc_rate / (ssc_div *2 *16 )) <BITRATE_MIN ) { + ssc_div -=2 ; +if ((ssc_rate / (ssc_div *2 *16 )) >BITRATE_MAX ) { +return -ENXIO ; + }
Remove braces for a single-if block.
Quoted 11 lines
sound/spi/at73c213.c new file +11
-0+ } + +/* Search for a possible bitrate. */ + do { + /* SSC clock / (ssc divider * 16-bit * stereo). */ + if ((ssc_rate / (ssc_div * 2 * 16)) < BITRATE_MIN) + return -ENXIO; + + /* 256 / (2 * 16) = 8 */ + dac_rate_new = 8 * (ssc_rate / ssc_div); +
sound/spi/at73c213.c line 182
Quoted 10 lines
sound/spi/at73c213.c new file +10
-0+ status =clk_round_rate (chip->board->dac_clk, dac_rate_new); +if (status <0 ) +return status; + +/* Ignore difference smaller than 256 Hz. */ +if ((status/256 ) == (dac_rate_new/256 )) + goto set_rate; + + ssc_div +=2 ; + }while (--max_tries);
Can't be max_tries = 0 in theory?
sound/spi/at73c213.c line 264
Quoted 8 lines
sound/spi/at73c213.c new file +8
-0+static int snd_at73c213_pcm_trigger (struct snd_pcm_substream *substream, +int cmd) +{ +struct snd_at73c213 *chip =snd_pcm_substream_chip (substream); +int retval =0 ; +unsigned long flags =0 ; + +spin_lock_irqsave (&chip->lock, flags);
The trigger callback is already spinlock+irqsaved. So, spin_lock() / spin_unlock() should be enough.
sound/spi/at73c213.c line 345
Quoted 6 lines
sound/spi/at73c213.c new file +6
-0+snd_pcm_set_ops (pcm,SNDRV_PCM_STREAM_PLAYBACK , &at73c213_playback_ops); + + retval =snd_pcm_lib_preallocate_pages_for_all (chip->pcm, +SNDRV_DMA_TYPE_DEV , +snd_dma_continuous_data (GFP_KERNEL ), +64 *1024 ,64 *1024 );
For SNDRV_DMA_TYPE_DEV, pass the struct device pointer of the device to the third argument. Then the pre-allocator will allocate the memory via dma_alloc_coherent() with the givn device. If it's not appropriate, SNDRV_DMA_TYPE_CONTINUOUS type. Anyway, snd_dma_continuous_data() is only for SNDRV_DMA_TYPE_CONTINUOUS.
Quoted 4 lines
sound/spi/at73c213.c new file +4
-0+/* +* Mixer functions. +*/ +static int snd_at73c213_mono_get(struct snd_kcontrol *kcontrol,
sound/spi/at73c213.c line 403
Quoted 10 lines
sound/spi/at73c213.c new file +10
-0+ struct snd_ctl_elem_value *ucontrol) +{ +struct snd_at73c213 *chip =snd_kcontrol_chip (kcontrol); +unsigned long flags; +int reg = kcontrol->private_value &0xff ; +int shift = (kcontrol->private_value >>8 ) &0xff ; +int mask = (kcontrol->private_value >>16 ) &0xff ; +int invert = (kcontrol->private_value >>24 ) &0xff ; + +spin_lock_irqsave (&chip->lock, flags);
The mixer (control) callbacks are all schedulable, so you need no irqsave but spin_lock_irq() should be fine.
Quoted 8 lines
sound/spi/at73c213.c new file +8
-0+static int __devinit snd_at73c213_mixer (struct snd_at73c213 *chip) +{ +struct snd_card *card; +int errval, idx; + +if (chip ==NULL || chip->pcm ==NULL ) +return -EINVAL ; +
sound/spi/at73c213.c line 730
Quoted 10 lines
sound/spi/at73c213.c new file +10
-0+ card = chip->card; + +strcpy (card->mixername, chip->pcm->name); + +for (idx =0 ; idx <ARRAY_SIZE (snd_at73c213_controls); idx++) { +if ((errval =snd_ctl_add (card, +snd_ctl_new1 (&snd_at73c213_controls[idx], + chip))) <0 ) { + goto cleanup; + }
Split errval = ; and if (errval < 0) ...
Also drop braces for a single if block.
thanks,
Takashi
Re: [PATCH 2/2] ALSA sound driver for the AT73C213 DAC using Atmel SSC driver
Quoted 10 lines · On Mon, 16 Jul 2007 17:08:02 +0200 Takashi Iwai <[email protected]> wrote:
include/linux/spi/at73c213.h line 25
Quoted 7 lines
include/linux/spi/at73c213.h new file +7
-0+struct at73c213_board_info { +int ssc_id; +struct clk *dac_clk; +char shortname[32 ]; +}; + +#endif /* __LINUX_SPI_AT73C213_H */ Any reason to put this into
include/linux? Are (or will be) there users of this except for ALSA driver?
This struct contains information about how the sound chip is hooked up on the board, so it needs to be defined in a place where the platform code can easily find it. Since it's not arch specific, it doesn't belong under <asm/...> so <linux/spi/...> seems like a logical choice.
This patch shows how it's meant to be used:
http://avr32linux.org/archives/kernel/2007-July/000124.html
Håvard
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Re: [PATCH 2/2] ALSA sound driver for the AT73C213 DAC using Atmel SSC driver
At Mon, 16 Jul 2007 17:27:46 +0200,
Quoted 15 lines · Haavard Skinnemoen
Quoted 10 lines · On Mon, 16 Jul 2007 17:08:02 +0200 Takashi Iwai <[email protected]> wrote:
include/linux/spi/at73c213.h line 25
Quoted 7 lines
include/linux/spi/at73c213.h new file +7
-0+struct at73c213_board_info { +int ssc_id; +struct clk *dac_clk; +char shortname[32 ]; +}; + +#endif /* __LINUX_SPI_AT73C213_H */ Any reason to put this into
include/linux? Are (or will be) there users of this except for ALSA driver?
Quoted 8 lines
This struct contains information about how the sound chip is hooked up on the board, so it needs to be defined in a place where the platform code can easily find it. Since it's not arch specific, it doesn't belong under <asm/...> so <linux/spi/...> seems like a logical choice.
This patch shows how it's meant to be used:
Fair enough, then I have no objection about that.
Takashi
Hans-Christian Egtvedt
AppliedRe: [PATCH 2/2] ALSA sound driver for the AT73C213 DAC using Atmel SSC driver
In reply to Takashi IwaiQuoted 26 lines · Takashi Iwai
At Mon, 16 Jul 2007 16:14:59 +0200,
Quoted 24 lines · Hans-Christian Egtvedt
include/linux/spi/at73c213.h new file +20
-0@@ -0,0 +1,25 @@ +/* +* Board-specific data used to set up AT73c213 audio DAC driver. +*/ + +#ifndef __LINUX_SPI_AT73C213_H +#define __LINUX_SPI_AT73C213_H + +/** + * at73c213_board_info - how the external DAC is wired to the device. + * + * @ssc_id: SSC platform_driver id the DAC shall use to stream the audio. + * @dac_clk: the external clock used to provide master clock to the DAC. + * @shortname: a short discription for the DAC, seen by userspace tools. + * + * This struct contains the configuration of the hardware connection to the + * external DAC. The DAC needs a master clock and a I2S audio stream. It also + * provides a name which is used to identify it in userspace tools. + */ +struct at73c213_board_info { + int ssc_id;
Quoted 8 lines
include/linux/spi/at73c213.h line 25
Quoted 5 lines
include/linux/spi/at73c213.h new file +5
-0+struct clk *dac_clk; + char shortname[32]; +}; + +#endif /* __LINUX_SPI_AT73C213_H */ Any reason to put this into
include/linux? Are (or will be) there users of this except for ALSA driver?
I think Haavards answer describes the usage well.
Quoted 9 lines
Quoted 5 lines
sound/spi/at73c213.c new file +0
-0(snip)
Quoted 1 line
+#include <
linux/kmod.h>Unneeded.
Removed
Quoted 9 lines
sound/spi/at73c213.c
Quoted 6 lines
sound/spi/at73c213.c new file +6
-0+#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/io.h> + +#include <sound/initval.h> +#include <sound/driver.h> Please put
sound/driver.hat first. This will make it for us much easier to maintain the out-of-kernel tree.
Ok, applied.
Quoted 27 lines
Quoted 27 lines
sound/spi/at73c213.c new file +27
-0+/* +* Calculate and set bitrate and divisions. +*/ +static int snd_at73c213_set_bitrate (struct snd_at73c213 *chip) +{ +unsigned long ssc_rate =clk_get_rate (chip->ssc->clk); +unsigned long dac_rate_new, ssc_div, status; +unsigned long ssc_div_max, ssc_div_min; +int max_tries; + +/* +* We connect two clocks here, picking divisors so the I2S clocks +* out data at the same rate the DAC clocks it in ... and as close +* as practical to the desired target rate. +* +* The DAC master clock (MCLK) is programmable, and is either 256 +* or (not here) 384 times the I2S output clock (BCLK). +*/ + +/* SSC clock / (bitrate * stereo * 16-bit). */ + ssc_div = ssc_rate / (BITRATE_TARGET *2 *16 ); + ssc_div_min = ssc_rate / (BITRATE_MAX *2 *16 ); + ssc_div_max = ssc_rate / (BITRATE_MIN *2 *16 ); + max_tries = (ssc_div_max - ssc_div_min) /2 ; + +/* ssc_div must be a power of 2. */ + ssc_div = (ssc_div +1 ) & ~1UL ;
Quoted 8 lines
sound/spi/at73c213.c
Quoted 6 lines
sound/spi/at73c213.c new file +6
-0+ +if ((ssc_rate / (ssc_div *2 *16 )) <BITRATE_MIN ) { + ssc_div -=2 ; +if ((ssc_rate / (ssc_div *2 *16 )) >BITRATE_MAX ) { +return -ENXIO ; + }Remove braces for a single-if block.
Applied.
Quoted 15 lines
Quoted 15 lines
sound/spi/at73c213.c new file +15
-0+ } + +/* Search for a possible bitrate. */ + do { + /* SSC clock / (ssc divider * 16-bit * stereo). */ + if ((ssc_rate / (ssc_div * 2 * 16)) < BITRATE_MIN) + return -ENXIO; + + /* 256 / (2 * 16) = 8 */ + dac_rate_new = 8 * (ssc_rate / ssc_div); + + status = clk_round_rate(chip->board->dac_clk, dac_rate_new); + if (status < 0) + return status; +
Quoted 8 lines
sound/spi/at73c213.c
Quoted 6 lines
sound/spi/at73c213.c new file +6
-0+/* Ignore difference smaller than 256 Hz. */ +if ((status/256 ) == (dac_rate_new/256 )) + goto set_rate; + + ssc_div +=2 ; + }while (--max_tries);Can't be
max_tries= 0 in theory?
Added a check earlier in the code which sets max_tries to 1 if it is smaller than 1. Could have been ugly for really low rates on the module, although it should not happen(tm).
if (max_tries < 1) max_tries = 1;
Quoted 11 lines
sound/spi/at73c213.c
Quoted 8 lines
sound/spi/at73c213.c new file +8
-0+static int snd_at73c213_pcm_trigger (struct snd_pcm_substream *substream, +int cmd) +{ +struct snd_at73c213 *chip =snd_pcm_substream_chip (substream); +int retval =0 ; +unsigned long flags =0 ; + +spin_lock_irqsave (&chip->lock, flags);The trigger callback is already spinlock+irqsaved. So,
spin_lock()/spin_unlock()should be enough.
Ok, applied.
Quoted 4 lines
Quoted 4 lines
sound/spi/at73c213.c new file +4
-0+snd_pcm_set_ops (pcm,SNDRV_PCM_STREAM_PLAYBACK , &at73c213_playback_ops); + + retval = snd_pcm_lib_preallocate_pages_for_all(chip->pcm, + SNDRV_DMA_TYPE_DEV,
Quoted 8 lines
sound/spi/at73c213.c
Quoted 2 lines
sound/spi/at73c213.c new file +2
-0+snd_dma_continuous_data (GFP_KERNEL ), + 64 * 1024, 64 * 1024);For
SNDRV_DMA_TYPE_DEV, pass the struct device pointer of the device to the third argument. Then the pre-allocator will allocate the memory viadma_alloc_coherent()with the givn device. If it's not appropriate,SNDRV_DMA_TYPE_CONTINUOUStype. Anyway,snd_dma_continuous_data()is only forSNDRV_DMA_TYPE_CONTINUOUS.
Ok, applied. Using &chip->spi->dev.
Quoted 9 lines
Quoted 9 lines
sound/spi/at73c213.c new file +9
-0+/* +* Mixer functions. +*/ +static int snd_at73c213_mono_get (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_value *ucontrol) +{ +struct snd_at73c213 *chip =snd_kcontrol_chip (kcontrol); +unsigned long flags; +int reg = kcontrol->private_value &0xff ;
Quoted 8 lines
sound/spi/at73c213.c
Quoted 5 lines
sound/spi/at73c213.c new file +5
-0+int shift = (kcontrol->private_value >>8 ) &0xff ; +int mask = (kcontrol->private_value >>16 ) &0xff ; +int invert = (kcontrol->private_value >>24 ) &0xff ; + +spin_lock_irqsave (&chip->lock, flags);The mixer (control) callbacks are all schedulable, so you need no irqsave but
spin_lock_irq()should be fine.
Ok, applied.
Quoted 13 lines
Quoted 13 lines
sound/spi/at73c213.c new file +13
-0+static int __devinit snd_at73c213_mixer (struct snd_at73c213 *chip) +{ +struct snd_card *card; +int errval, idx; + +if (chip ==NULL || chip->pcm ==NULL ) +return -EINVAL ; + + card = chip->card; + +strcpy (card->mixername, chip->pcm->name); + +for (idx =0 ; idx <ARRAY_SIZE (snd_at73c213_controls); idx++) {
Quoted 8 lines
sound/spi/at73c213.c
Quoted 5 lines
sound/spi/at73c213.c new file +5
-0+if ((errval =snd_ctl_add (card, +snd_ctl_new1 (&snd_at73c213_controls[idx], + chip))) <0 ) { + goto cleanup; + }Split errval = ; and if (errval < 0) ...
Also drop braces for a single if block.
Ok, applied.
I have attached an updated patch with the changes you noted above. Thanks for the review.
Signature · 4 lines
With kind regards, Hans-Christian Egtvedt, siv.ing. (M.Sc.) Applications Engineer - AVR32 System Solutions - Atmel Norway
Quoted 1 line
From
9a5c464308d1f3712ffca1ab3948a49d53da9a6fMon Sep 17 00:00:00 2001
From: Hans-Christian Egtvedt <[email protected]>
Date: Thu, 5 Jul 2007 18:09:33 +0200
Subject: [PATCH 1/1] ALSA sound driver for the AT73C213 DAC using Atmel SSC driver
This patch adds support for the AT73C213 DAC using the misc Atmel SSC driver in I2S mode. The driver also requires a SPI to setup the registers and control volume.
It has been tested with an AT32AP7000 on the ATSTK1000 development board. The driver should also work with any Atmel device with an SSC module supported by the Atmel SSC driver (atmel-ssc).
The atmel-ssc driver is just submitted to the Linux kernel. Please see mail thread http://lkml.org/lkml/2007/7/16/32
--- include/linux/spi/at73c213.h | 25 + sound/spi/Kconfig | 25 + sound/spi/Makefile | 3 + sound/spi/at73c213.c | 1121 ++++++++++++++++++++++++++++++++++++++++++ sound/spi/at73c213.h | 119 +++++ 5 files changed, 1293 insertions(+), 0 deletions(-) create mode 100644 include/linux/spi/at73c213.h create mode 100644 sound/spi/at73c213.c create mode 100644 sound/spi/at73c213.h
include/linux/spi/at73c213.h new file +25 -0
@@ -0,0 +1,25 @@ +/* +* Board-specific data used to set up AT73c213 audio DAC driver. +*/ + +#ifndef __LINUX_SPI_AT73C213_H +#define __LINUX_SPI_AT73C213_H + +/** +* at73c213_board_info - how the external DAC is wired to the device. +* +* @ssc_id: SSC platform_driver id the DAC shall use to stream the audio. +* @dac_clk: the external clock used to provide master clock to the DAC. +* @shortname: a short discription for the DAC, seen by userspace tools. +* +* This struct contains the configuration of the hardware connection to the +* external DAC. The DAC needs a master clock and a I2S audio stream. It also +* provides a name which is used to identify it in userspace tools. +*/ +struct at73c213_board_info { +int ssc_id; +struct clk *dac_clk; +char shortname[32 ]; +}; + +#endif /* __LINUX_SPI_AT73C213_H */
sound/spi/Kconfig +25 -0
@@ -3,4 +3,29 @@ menu "SPI devices" depends on SND != n +config SND_AT73C213 + tristate "Atmel AT73C213 DAC driver" + depends on ATMEL_SSC + select SND_PCM + help + Say Y here if you want to use the Atmel AT73C213 external DAC. This + DAC can be found on Atmel development boards. + + This driver requires the Atmel SSC driver for sound sink, a + peripheral found on most AT91 and AVR32 microprocessors. + + To compile this driver as a module, choose M here: the module will be + called snd-at73c213. + +config SND_AT73C213_TARGET_BITRATE + int "Target bitrate for AT73C213" + depends on SND_AT73C213 + default "48000" + range 8000 50000 + help + Sets the target bitrate for the bitrate calculator in the driver. + Limited by hardware to be between 8000 Hz and 50000 Hz. + + Set to 48000 Hz by default. + endmenu
sound/spi/Makefile +3 -0
@@ -1,2 +1,5 @@ # Makefile for SPI drivers +snd-at73c213-objs := at73c213.o + +obj-$(CONFIG_SND_AT73C213) += snd-at73c213.o
sound/spi/at73c213.c new file +1121 -0
1,121 lines not on this page · raw message
sound/spi/at73c213.h new file +119 -0
119 lines not on this page · raw message
Signature · 1 line
1.5.2.3
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Re: [PATCH 2/2] ALSA sound driver for the AT73C213 DAC using Atmel SSC driver
Quoted 13 lines · On Tue, 17 Jul 2007 10:37:21 +0200 Hans-Christian Egtvedt…
Quoted 4 lines
Quoted 4 lines
sound/spi/at73c213.c new file +4
-0+snd_pcm_set_ops (pcm,SNDRV_PCM_STREAM_PLAYBACK , &at73c213_playback_ops); + + retval = snd_pcm_lib_preallocate_pages_for_all(chip->pcm, + SNDRV_DMA_TYPE_DEV,Quoted 8 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ snd_dma_continuous_data(GFP_KERNEL), + 64 * 1024, 64 * 1024);For
SNDRV_DMA_TYPE_DEV, pass the struct device pointer of the device to the third argument. Then the pre-allocator will allocate the memory viadma_alloc_coherent()with the givn device. If it's not appropriate,SNDRV_DMA_TYPE_CONTINUOUStype. Anyway,snd_dma_continuous_data()is only forSNDRV_DMA_TYPE_CONTINUOUS.
Quoted 1 line
Ok, applied. Using
&chip->spi->dev.
Not that I think it matters at the moment, but that's not entirely correct. The memory is used for DMA transfers to the SSC controller, not the SPI device, so you should pass the SSC's struct device here.
In other words, I think you should use &chip->ssc->pdev->dev.
Håvard
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Re: [PATCH 2/2] ALSA sound driver for the AT73C213 DAC using Atmel SSC driver
Quoted 16 lines · Haavard Skinnemoen
Quoted 13 lines · On Tue, 17 Jul 2007 10:37:21 +0200 Hans-Christian Egtvedt…
Quoted 12 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+ snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &at73c213_playback_ops); + + retval = snd_pcm_lib_preallocate_pages_for_all(chip->pcm, + SNDRV_DMA_TYPE_DEV, + snd_dma_continuous_data(GFP_KERNEL), + 64 * 1024, 64 * 1024);For
SNDRV_DMA_TYPE_DEV, pass the struct device pointer of the device to the third argument. Then the pre-allocator will allocate the memory viadma_alloc_coherent()with the givn device. If it's not appropriate,SNDRV_DMA_TYPE_CONTINUOUStype. Anyway,snd_dma_continuous_data()is only forSNDRV_DMA_TYPE_CONTINUOUS.
Quoted 7 lines
Quoted 1 line
Ok, applied. Using
&chip->spi->dev.Not that I think it matters at the moment, but that's not entirely correct. The memory is used for DMA transfers to the SSC controller, not the SPI device, so you should pass the SSC's struct device here.
In other words, I think you should use
&chip->ssc->pdev->dev.
Hmm, my fault, applied.
New patch attached.
Signature · 4 lines
With kind regards, Hans-Christian Egtvedt, siv.ing. (M.Sc.) Applications Engineer - AVR32 System Solutions - Atmel Norway
Quoted 1 line
From
65eff8723a851c0df1f429112e817e0d5f1ab798Mon Sep 17 00:00:00 2001
From: Hans-Christian Egtvedt <[email protected]>
Date: Thu, 5 Jul 2007 18:09:33 +0200
Subject: [PATCH 1/1] ALSA sound driver for the AT73C213 DAC using Atmel SSC driver
This patch adds support for the AT73C213 DAC using the misc Atmel SSC driver in I2S mode. The driver also requires a SPI to setup the registers and control volume.
It has been tested with an AT32AP7000 on the ATSTK1000 development board. The driver should also work with any Atmel device with an SSC module supported by the Atmel SSC driver (atmel-ssc).
The atmel-ssc driver is just submitted to the Linux kernel. Please see mail thread http://lkml.org/lkml/2007/7/16/32
--- include/linux/spi/at73c213.h | 25 + sound/spi/Kconfig | 25 + sound/spi/Makefile | 3 + sound/spi/at73c213.c | 1121 ++++++++++++++++++++++++++++++++++++++++++ sound/spi/at73c213.h | 119 +++++ 5 files changed, 1293 insertions(+), 0 deletions(-) create mode 100644 include/linux/spi/at73c213.h create mode 100644 sound/spi/at73c213.c create mode 100644 sound/spi/at73c213.h
include/linux/spi/at73c213.h new file +25 -0
@@ -0,0 +1,25 @@ +/* +* Board-specific data used to set up AT73c213 audio DAC driver. +*/ + +#ifndef __LINUX_SPI_AT73C213_H +#define __LINUX_SPI_AT73C213_H + +/** +* at73c213_board_info - how the external DAC is wired to the device. +* +* @ssc_id: SSC platform_driver id the DAC shall use to stream the audio. +* @dac_clk: the external clock used to provide master clock to the DAC. +* @shortname: a short discription for the DAC, seen by userspace tools. +* +* This struct contains the configuration of the hardware connection to the +* external DAC. The DAC needs a master clock and a I2S audio stream. It also +* provides a name which is used to identify it in userspace tools. +*/ +struct at73c213_board_info { +int ssc_id; +struct clk *dac_clk; +char shortname[32 ]; +}; + +#endif /* __LINUX_SPI_AT73C213_H */
sound/spi/Kconfig +25 -0
@@ -3,4 +3,29 @@ menu "SPI devices" depends on SND != n +config SND_AT73C213 + tristate "Atmel AT73C213 DAC driver" + depends on ATMEL_SSC + select SND_PCM + help + Say Y here if you want to use the Atmel AT73C213 external DAC. This + DAC can be found on Atmel development boards. + + This driver requires the Atmel SSC driver for sound sink, a + peripheral found on most AT91 and AVR32 microprocessors. + + To compile this driver as a module, choose M here: the module will be + called snd-at73c213. + +config SND_AT73C213_TARGET_BITRATE + int "Target bitrate for AT73C213" + depends on SND_AT73C213 + default "48000" + range 8000 50000 + help + Sets the target bitrate for the bitrate calculator in the driver. + Limited by hardware to be between 8000 Hz and 50000 Hz. + + Set to 48000 Hz by default. + endmenu
sound/spi/Makefile +3 -0
@@ -1,2 +1,5 @@ # Makefile for SPI drivers +snd-at73c213-objs := at73c213.o + +obj-$(CONFIG_SND_AT73C213) += snd-at73c213.o
sound/spi/at73c213.c new file +1121 -0
1,121 lines not on this page · raw message
sound/spi/at73c213.h new file +119 -0
119 lines not on this page · raw message
Signature · 1 line
1.5.2.3
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Re: [PATCH 2/2] ALSA sound driver for the AT73C213 DAC using Atmel SSC driver
At Tue, 17 Jul 2007 10:54:19 +0200,
Quoted 25 lines · Hans-Christian Egtvedt
Quoted 22 lines · Haavard Skinnemoen
Quoted 13 lines · On Tue, 17 Jul 2007 10:37:21 +0200 Hans-Christian Egtvedt…
Quoted 4 lines
Quoted 4 lines
sound/spi/at73c213.c new file +4
-0+snd_pcm_set_ops (pcm,SNDRV_PCM_STREAM_PLAYBACK , &at73c213_playback_ops); + + retval = snd_pcm_lib_preallocate_pages_for_all(chip->pcm, + SNDRV_DMA_TYPE_DEV,Quoted 8 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ snd_dma_continuous_data(GFP_KERNEL), + 64 * 1024, 64 * 1024);For
SNDRV_DMA_TYPE_DEV, pass the struct device pointer of the device to the third argument. Then the pre-allocator will allocate the memory viadma_alloc_coherent()with the givn device. If it's not appropriate,SNDRV_DMA_TYPE_CONTINUOUStype. Anyway,snd_dma_continuous_data()is only forSNDRV_DMA_TYPE_CONTINUOUS.Quoted 1 line
Ok, applied. Using
&chip->spi->dev.Not that I think it matters at the moment, but that's not entirely correct. The memory is used for DMA transfers to the SSC controller, not the SPI device, so you should pass the SSC's struct device here.
Quoted 5 lines
Quoted 1 line
In other words, I think you should use
&chip->ssc->pdev->dev.Hmm, my fault, applied.
New patch attached.
The patch looks fine, but I suppose it's a post-2.6.23 material, judging from the current situation. Is it OK?
Then I'll queue it soon after the merge window is closed, so that your driver appears in the mm tree.
thanks,
Takashi
Re: [PATCH 2/2] ALSA sound driver for the AT73C213 DAC using Atmel SSC driver
Quoted 5 lines · Takashi Iwai
At Tue, 17 Jul 2007 10:54:19 +0200,
Quoted 3 lines · Hans-Christian Egtvedt
Quoted 2 lines · Haavard Skinnemoen
On Tue, 17 Jul 2007 10:37:21 +0200 Hans-Christian Egtvedt <[email protected]> wrote:
<cut memory preallocation discussion>
Quoted 4 lines
Quoted 1 line
New patch attached.
The patch looks fine, but I suppose it's a post-2.6.23 material, judging from the current situation. Is it OK?
I guess post-2.6.23 is fine since it seems nobody is reacting to the atmel-ssc driver, will bump it later today.
I will notify you if it seems like they will fit it for 2.6.23.
Quoted 2 lines
Then I'll queue it soon after the merge window is closed, so that your driver appears in the mm tree.
Thanks.
Signature · 4 lines
With kind regards, Hans-Christian Egtvedt, siv.ing. (M.Sc.) Applications Engineer - AVR32 System Solutions - Atmel Norway
Re: [PATCH 2/2] ALSA sound driver for the AT73C213 DAC using Atmel SSC driver
Quoted 2 lines · On Tue, 17 Jul 2007 13:23:31 +0200 Hans-Christian Egtvedt…
I guess post-2.6.23 is fine since it seems nobody is reacting to the atmel-ssc driver, will bump it later today.
I wonder if I could actually get away with pushing it through the avr32 tree, as this is one of the two architectures the driver is relevant to (the other one being arm) and there are lots of special-case stuff in misc already.
It would be nice to see some general comments on it though. Cc'ing some AT91 folks might help.
Håvard
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Re: [PATCH 2/2] ALSA sound driver for the AT73C213 DAC using Atmel SSC driver
In reply to Takashi IwaiAt Tue, 17 Jul 2007 12:23:56 +0200,
Quoted 3 lines · I wrote:
Then I'll queue it soon after the merge window is closed, so that your driver appears in the mm tree.
FYI, I applied the patches to ALSA HG tree now (for 2.6.24).
Takashi
Re: [PATCH 2/2] ALSA sound driver for the AT73C213 DAC using Atmel SSC driver
Quoted 7 lines · Takashi Iwai
At Tue, 17 Jul 2007 12:23:56 +0200,
Quoted 3 lines · I wrote:
Then I'll queue it soon after the merge window is closed, so that your driver appears in the mm tree.
FYI, I applied the patches to ALSA HG tree now (for 2.6.24).
Thanks, the SSC driver is also in Andrews -mm tree, so user should be able to test this by fetching both trees.
Signature · 4 lines
With kind regards, Hans-Christian Egtvedt, siv.ing. (M.Sc.) Applications Engineer - AVR32 System Solutions - Atmel Norway