Skip to contentSkip to conversation

ALSA driver for SGI O2 audio board

PATCH Superseded Thomas Bogendoerfer 2 participants 8 messages Jul 4, 2008 – Jul 10, 2008 Sound

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ALSA driver for SGI O2 audio board

This patch adds a new ALSA driver for the audio device found inside most of the SGI O2 workstation. The hardware uses a SGI custom chip, which feeds a AD codec chip.

---

Please apply for 2.6.27.

 include/sound/ad1843.h  |   46 +++
 sound/mips/Kconfig      |    6 +
 sound/mips/Makefile     |    2 +
 sound/mips/ad1843.c     |  539 +++++++++++++++++++++++++
 sound/mips/sgio2audio.c | 1013 +++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 1606 insertions(+), 0 deletions(-)
include/sound/ad1843.h new file +46 -0
new file mode 100644
index 0000000..b236a9d
@@ -0,0 +1,46 @@
+/*
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright 2003 Vivien Chappelier <[email protected]>
+ * Copyright 2008 Thomas Bogendoerfer <[email protected]>
+ */
+
+#ifndef __SOUND_AD1843_H
+#define __SOUND_AD1843_H
+
+struct snd_ad1843 {
+	void *chip;
+	int (*read)(void *chip, int reg);
+	int (*write)(void *chip, int reg, int val);
+};
+
+#define AD1843_GAIN_RECLEV 0
+#define AD1843_GAIN_LINE   1
+#define AD1843_GAIN_LINE_2 2
+#define AD1843_GAIN_MIC    3
+#define AD1843_GAIN_PCM_0  4
+#define AD1843_GAIN_PCM_1  5
+#define AD1843_GAIN_SIZE   (AD1843_GAIN_PCM_1+1)
+
+int ad1843_get_gain_max(struct snd_ad1843 *ad1843, int id);
+int ad1843_get_gain(struct snd_ad1843 *ad1843, int id);
+int ad1843_set_gain(struct snd_ad1843 *ad1843, int id, int newval);
+int ad1843_get_recsrc(struct snd_ad1843 *ad1843);
+int ad1843_set_recsrc(struct snd_ad1843 *ad1843, int newsrc);
+void ad1843_setup_dac(struct snd_ad1843 *ad1843,
+		      unsigned int id,
+		      unsigned int framerate,
+		      snd_pcm_format_t fmt,
+		      unsigned int channels);
+void ad1843_shutdown_dac(struct snd_ad1843 *ad1843,
+			 unsigned int id);
+void ad1843_setup_adc(struct snd_ad1843 *ad1843,
+		      unsigned int framerate,
+		      snd_pcm_format_t fmt,
+		      unsigned int channels);
+void ad1843_shutdown_adc(struct snd_ad1843 *ad1843);
+int ad1843_init(struct snd_ad1843 *ad1843);
+
+#endif /* __SOUND_AD1843_H */
sound/mips/Kconfig +6 -0
index 531f8ba..a3e202e 100644
@@ -11,5 +11,11 @@ config SND_AU1X00
 	help
 	  ALSA Sound driver for the Au1x00's AC97 port.
 
+config SND_SGI_O2
+	tristate "SGI O2 Audio"
+	depends on  SND && SGI_IP32
+        help
+                Sound support for the SGI O2 Workstation. 
+
 endmenu
 
sound/mips/Makefile +2 -0
index 47afed9..55624d8 100644
@@ -2,7 +2,9 @@
 # Makefile for ALSA
 #
 
+snd-sgi-o2-objs := sgio2audio.o ad1843.o
 snd-au1x00-objs := au1x00.o
 
 # Toplevel Module Dependency
 obj-$(CONFIG_SND_AU1X00) += snd-au1x00.o
+obj-$(CONFIG_SND_SGI_O2) += snd-sgi-o2.o
sound/mips/ad1843.c new file +539 -0

539 lines not on this page · raw message

sound/mips/sgio2audio.c new file +1013 -0

1,013 lines not on this page · raw message

_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#1 lore raw

At Sat, 5 Jul 2008 01:45:59 +0200 (CEST),

Quoted 9 lines · Thomas Bogendoerfer

This patch adds a new ALSA driver for the audio device found inside most of the SGI O2 workstation. The hardware uses a SGI custom chip, which feeds a AD codec chip.

---

Please apply for 2.6.27.

Thanks for the patch.
Below is a quick review.

Quoted 5 lines
sound/mips/Kconfig +0 -0
index 531f8ba..a3e202e 100644

sound/mips/Kconfig config SND_AU1X00 · line 20

Quoted 10 lines
sound/mips/Kconfig +6 -0
@@ -11,5 +11,11 @@ config SND_AU1X00
 	help
 	  ALSA Sound driver for the Au1x00's AC97 port.
 
+config SND_SGI_O2
+	tristate "SGI O2 Audio"
+	depends on  SND && SGI_IP32
+        help
+                Sound support for the SGI O2 Workstation. 
+
 endmenu

The recent version doesn't require "depends on SND" here because of changes to menuconfig. Check the latest ALSA tree or linux-next tree.

Quoted 10 lines
sound/mips/ad1843.c new file +8 -0
+const struct ad1843_gain ad1843_gain_RECLEV = {
+	0, &ad1843_LIG,   &ad1843_RIG
+};
+const struct ad1843_gain ad1843_gain_LINE = {
+	1, &ad1843_LX1M,  &ad1843_RX1M,  &ad1843_LX1MM, &ad1843_RX1MM
+};
+const struct ad1843_gain ad1843_gain_LINE_2 = {
+	1, &ad1843_LDA2G, &ad1843_RDA2G, &ad1843_LDA2GM, &ad1843_RDA2GM

sound/mips/ad1843.c line 150

Quoted 10 lines
sound/mips/ad1843.c new file +10 -0
+};
+const struct ad1843_gain ad1843_gain_MIC = {
+	1, &ad1843_LMCM,  &ad1843_RMCM,  &ad1843_LMCMM,  &ad1843_RMCMM
+};
+const struct ad1843_gain ad1843_gain_PCM_0 = {
+	1, &ad1843_LDA1G, &ad1843_RDA1G, &ad1843_LDA1GM, &ad1843_RDA1GM
+};
+const struct ad1843_gain ad1843_gain_PCM_1 = {
+	1, &ad1843_LD2M,  &ad1843_RD2M,  &ad1843_LD2MM,  &ad1843_RD2MM
+};

Missing static?

sound/mips/ad1843.c line 160

Quoted 10 lines
sound/mips/ad1843.c new file +10 -0
+
+const struct ad1843_gain *ad1843_gain[AD1843_GAIN_SIZE] =
+{
+	&ad1843_gain_RECLEV,
+	&ad1843_gain_LINE,
+	&ad1843_gain_LINE_2,
+	&ad1843_gain_MIC,
+	&ad1843_gain_PCM_0,
+	&ad1843_gain_PCM_1,
+};

Ditto.
Also, better to use C99 style initialization.

Quoted 4 lines
sound/mips/ad1843.c new file +4 -0
+int ad1843_init(struct snd_ad1843 *ad1843)
+{
+	unsigned long later;
+

sound/mips/ad1843.c line 473

Quoted 10 lines
sound/mips/ad1843.c new file +10 -0
+	if (ad1843_read_bits(ad1843, &ad1843_INIT) != 0) {
+		printk(KERN_ERR "ad1843: AD1843 won't initialize\n");
+		return -EIO;
+	}
+
+	ad1843_write_bits(ad1843, &ad1843_SCF, 1);
+
+	/* 4. Put the conversion resources into standby. */
+	ad1843_write_bits(ad1843, &ad1843_PDNI, 0);
+	later = jiffies + HZ / 2;	/* roughly half a second */

Use msecs_to_jiffies().

sound/mips/ad1843.c line 481

Quoted 8 lines
sound/mips/ad1843.c new file +8 -0
+
+	while (ad1843_read_bits(ad1843, &ad1843_PDNO)) {
+		if (time_after(jiffies, later)) {
+			printk(KERN_ERR
+			       "ad1843: AD1843 won't power up\n");
+			return -EIO;
+		}
+		schedule();

No set_current_state() ?

Quoted 5 lines
sound/mips/sgio2audio.c new file +3 -0
+static int read_ad1843_reg(void *priv, int reg)
+{
+	struct snd_sgio2audio *chip = priv;

sound/mips/sgio2audio.c line 133

Quoted 10 lines
sound/mips/sgio2audio.c new file +10 -0
+	int val;
+	unsigned long flags;
+
+	spin_lock_irqsave(&chip->ad1843_lock, flags);
+
+	writeq((reg << CODEC_CONTROL_ADDRESS_SHIFT) |
+	       CODEC_CONTROL_READ, &mace->perif.audio.codec_control);
+	wmb();
+	val = readq(&mace->perif.audio.codec_control); /* flush bus */
+	udelay(200);

It'd be nicer if this long delay can be avoided. Or, could it be mutex?

This isn't a fatal problem, so it's OK as is, though.

Quoted 41 lines
sound/mips/sgio2audio.c new file +41 -0
+static int __devinit snd_sgio2audio_create(struct snd_card *card,
+					   struct snd_sgio2audio **rchip)
+{
+	struct snd_sgio2audio *chip;
+	int i, err;
+
+	*rchip = NULL;
+
+	/* check if a codec is attached to the interface */
+	/* (Audio or Audio/Video board present) */
+	if (!(readq(&mace->perif.audio.control) & AUDIO_CONTROL_CODEC_PRESENT))
+		return -ENOENT;
+
+	chip = kzalloc(sizeof(struct snd_sgio2audio), GFP_KERNEL);
+	if (chip == NULL)
+		return -ENOMEM;
+
+	chip->card = card;
+
+	chip->ring_base = dma_alloc_coherent(NULL, MACEISA_RINGBUFFERS_SIZE,
+					     &chip->ring_base_dma, GFP_USER);
+	if (chip->ring_base == NULL) {
+		printk(KERN_ERR
+		       "sgio2audio: could not allocate ring buffers\n");
+		kfree(chip);
+		return -ENOMEM;
+	}
+
+	spin_lock_init(&chip->ad1843_lock);
+
+	chip->volume = SGIO2AUDIO_MAX_VOLUME;
+
+	/* initialize channels */
+	for (i = 0; i < 3; i++) {
+		spin_lock_init(&chip->channel[i].lock);
+		chip->channel[i].idx = i;
+	}
+
+	/* allocate IRQs */
+	for (i = 0; i < ARRAY_SIZE(snd_sgio2_isr_table); i++) {
+		if (request_irq(snd_sgio2_isr_table[i].irq,

sound/mips/sgio2audio.c line 908

Quoted 10 lines
sound/mips/sgio2audio.c new file +10 -0
+				snd_sgio2_isr_table[i].isr,
+				IRQF_SHARED,
+				snd_sgio2_isr_table[i].desc,
+				&chip->channel[snd_sgio2_isr_table[i].idx])) {
+			snd_sgio2audio_free(chip);
+			printk(KERN_ERR "sgio2audio: cannot allocate irq %d\n",
+			       snd_sgio2_isr_table[i].irq);
+			return -EBUSY;
+		}
+	}

If there are shared interrupts, they could be called before the initialization below. So, safer to move after the init.

thanks,

Takashi

#2 lore raw
Quoted 2 lines · Takashi Iwai

Thanks for the patch.
Below is a quick review.

thank you.

Quoted 8 lines

sound/mips/sgio2audio.c line 133

Quoted 3 lines
sound/mips/sgio2audio.c new file +3 -0
+	wmb();
+	val = readq(&mace->perif.audio.codec_control); /* flush bus */
+	udelay(200);

It'd be nicer if this long delay can be avoided. Or, could it be mutex?

This isn't a fatal problem, so it's OK as is, though.

I'm not quite sure, what delay really is sufficient at the moment. It worked without delay on my slow O2, but caused problems on faster maschines. I want to figure out a good value and if it's just a few microsecons simply use an udelay(). If a longer delay is needed I'll switch over to something more kernel friendly.

Quoted 8 lines
Quoted 8 lines
sound/mips/sgio2audio.c new file +8 -0
+	/* allocate IRQs */
+	for (i = 0; i < ARRAY_SIZE(snd_sgio2_isr_table); i++) {
+		if (request_irq(snd_sgio2_isr_table[i].irq,
+				snd_sgio2_isr_table[i].isr,
+				IRQF_SHARED,
+				snd_sgio2_isr_table[i].desc,
+				&chip->channel[snd_sgio2_isr_table[i].idx])) {
+			snd_sgio2audio_free(chip);
Quoted 8 lines

sound/mips/sgio2audio.c line 908

Quoted 5 lines
sound/mips/sgio2audio.c new file +5 -0
+			printk(KERN_ERR "sgio2audio: cannot allocate irq %d\n",
+			       snd_sgio2_isr_table[i].irq);
+			return -EBUSY;
+		}
+	}

If there are shared interrupts, they could be called before the initialization below. So, safer to move after the init.

they can't be shared and it's already done before any hardware init. We only check, whether there is a sound module installed before that.

I'll post an updated patch in a couple of minutes.

Thomas,

Signature · 2 lines
Crap can work. Given enough thrust pigs will fly, but it's not necessary a
good idea.                                                [ RFC1925, 2.3 ]
#3 lore raw

At Wed, 9 Jul 2008 19:50:59 +0200,

Quoted 19 lines · Thomas Bogendoerfer
Quoted 8 lines · Takashi Iwai
Quoted 8 lines
sound/mips/sgio2audio.c new file +8 -0
+	/* allocate IRQs */
+	for (i = 0; i < ARRAY_SIZE(snd_sgio2_isr_table); i++) {
+		if (request_irq(snd_sgio2_isr_table[i].irq,
+				snd_sgio2_isr_table[i].isr,
+				IRQF_SHARED,
+				snd_sgio2_isr_table[i].desc,
+				&chip->channel[snd_sgio2_isr_table[i].idx])) {
+			snd_sgio2audio_free(chip);
Quoted 8 lines

sound/mips/sgio2audio.c line 908

Quoted 5 lines
sound/mips/sgio2audio.c new file +5 -0
+			printk(KERN_ERR "sgio2audio: cannot allocate irq %d\n",
+			       snd_sgio2_isr_table[i].irq);
+			return -EBUSY;
+		}
+	}

If there are shared interrupts, they could be called before the initialization below. So, safer to move after the init.

Quoted 1 line

they can't be shared and it's already done before any hardware init.

Then any reason to pass IRQF_SHARED?

Takashi

#4 lore raw
Quoted 7 lines · Takashi Iwai

At Wed, 9 Jul 2008 19:50:59 +0200,

Quoted 4 lines
Quoted 2 lines

If there are shared interrupts, they could be called before the initialization below. So, safer to move after the init.

they can't be shared and it's already done before any hardware init.

Then any reason to pass IRQF_SHARED?

of course not. I'll remove it.

Thomas.

Signature · 2 lines
Crap can work. Given enough thrust pigs will fly, but it's not necessary a
good idea.                                                [ RFC1925, 2.3 ]
#5 lore raw

At Wed, 9 Jul 2008 20:31:38 +0200,

Quoted 11 lines · Thomas Bogendoerfer
Quoted 7 lines · Takashi Iwai

At Wed, 9 Jul 2008 19:50:59 +0200,

Quoted 4 lines
Quoted 2 lines

If there are shared interrupts, they could be called before the initialization below. So, safer to move after the init.

they can't be shared and it's already done before any hardware init.

Then any reason to pass IRQF_SHARED?

of course not. I'll remove it.

v2 still has it...

Takashi

#6 lore raw
Quoted 8 lines · Takashi Iwai

At Wed, 9 Jul 2008 20:31:38 +0200,

Quoted 6 lines · Thomas Bogendoerfer
Quoted 4 lines · Takashi Iwai

At Wed, 9 Jul 2008 19:50:59 +0200,

Quoted 3 lines
Quoted 2 lines

If there are shared interrupts, they could be called before the initialization below. So, safer to move after the init.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

they can't be shared and it's already done before any hardware init.

Then any reason to pass IRQF_SHARED?

of course not. I'll remove it.

v2 still has it...

I know, I've sent it earlier. Just wanted to give v2 a little time, if something else pops up. If everything else is ok, I'll respin a v3 with just the IRQF_SHARED removed.

Thomas.

Signature · 2 lines
Crap can work. Given enough thrust pigs will fly, but it's not necessary a
good idea.                                                [ RFC1925, 2.3 ]
#7 lore raw

At Thu, 10 Jul 2008 19:00:11 +0200,

Quoted 14 lines · Thomas Bogendoerfer
Quoted 12 lines · Takashi Iwai

At Wed, 9 Jul 2008 20:31:38 +0200,

Quoted 10 lines · Thomas Bogendoerfer
Quoted 7 lines · Takashi Iwai

At Wed, 9 Jul 2008 19:50:59 +0200,

Quoted 4 lines
Quoted 2 lines

If there are shared interrupts, they could be called before the initialization below. So, safer to move after the init.

they can't be shared and it's already done before any hardware init.

Then any reason to pass IRQF_SHARED?

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

of course not. I'll remove it.

v2 still has it...

I know, I've sent it earlier. Just wanted to give v2 a little time, if something else pops up. If everything else is ok, I'll respin a v3 with just the IRQF_SHARED removed.

Ah, OK.

thanks,

Takashi