^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Sound driver for Silicon Graphics O2 Workstations A/V board audio.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright 2003 Vivien Chappelier <vivien.chappelier@linux-mips.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright 2008 Thomas Bogendoerfer <tsbogend@alpha.franken.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Mxier part taken from mace_audio.c:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Copyright 2007 Thorben Jändling <tj.trevelyan@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/dma-mapping.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <asm/ip32/ip32_ints.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <asm/ip32/mace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <sound/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <sound/control.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <sound/pcm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define SNDRV_GET_ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <sound/initval.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <sound/ad1843.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) MODULE_AUTHOR("Vivien Chappelier <vivien.chappelier@linux-mips.org>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) MODULE_DESCRIPTION("SGI O2 Audio");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) MODULE_SUPPORTED_DEVICE("{{Silicon Graphics, O2 Audio}}");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) module_param(index, int, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) MODULE_PARM_DESC(index, "Index value for SGI O2 soundcard.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) module_param(id, charp, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) MODULE_PARM_DESC(id, "ID string for SGI O2 soundcard.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #define AUDIO_CONTROL_RESET BIT(0) /* 1: reset audio interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #define AUDIO_CONTROL_CODEC_PRESENT BIT(1) /* 1: codec detected */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #define CODEC_CONTROL_WORD_SHIFT 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define CODEC_CONTROL_READ BIT(16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #define CODEC_CONTROL_ADDRESS_SHIFT 17
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #define CHANNEL_CONTROL_RESET BIT(10) /* 1: reset channel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #define CHANNEL_DMA_ENABLE BIT(9) /* 1: enable DMA transfer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #define CHANNEL_INT_THRESHOLD_DISABLED (0 << 5) /* interrupt disabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #define CHANNEL_INT_THRESHOLD_25 (1 << 5) /* int on buffer >25% full */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #define CHANNEL_INT_THRESHOLD_50 (2 << 5) /* int on buffer >50% full */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #define CHANNEL_INT_THRESHOLD_75 (3 << 5) /* int on buffer >75% full */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #define CHANNEL_INT_THRESHOLD_EMPTY (4 << 5) /* int on buffer empty */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #define CHANNEL_INT_THRESHOLD_NOT_EMPTY (5 << 5) /* int on buffer !empty */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) #define CHANNEL_INT_THRESHOLD_FULL (6 << 5) /* int on buffer empty */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) #define CHANNEL_INT_THRESHOLD_NOT_FULL (7 << 5) /* int on buffer !empty */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) #define CHANNEL_RING_SHIFT 12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) #define CHANNEL_RING_SIZE (1 << CHANNEL_RING_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) #define CHANNEL_RING_MASK (CHANNEL_RING_SIZE - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #define CHANNEL_LEFT_SHIFT 40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) #define CHANNEL_RIGHT_SHIFT 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) struct snd_sgio2audio_chan {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) int idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) struct snd_pcm_substream *substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) int pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) snd_pcm_uframes_t size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) spinlock_t lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) /* definition of the chip-specific record */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) struct snd_sgio2audio {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) struct snd_card *card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) /* codec */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) struct snd_ad1843 ad1843;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) spinlock_t ad1843_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) /* channels */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) struct snd_sgio2audio_chan channel[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) /* resources */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) void *ring_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) dma_addr_t ring_base_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) /* AD1843 access */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * read_ad1843_reg returns the current contents of a 16 bit AD1843 register.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) * Returns unsigned register value on success, -errno on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) static int read_ad1843_reg(void *priv, int reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) struct snd_sgio2audio *chip = priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) spin_lock_irqsave(&chip->ad1843_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) writeq((reg << CODEC_CONTROL_ADDRESS_SHIFT) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) CODEC_CONTROL_READ, &mace->perif.audio.codec_control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) val = readq(&mace->perif.audio.codec_control); /* flush bus */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) udelay(200);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) val = readq(&mace->perif.audio.codec_read);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) spin_unlock_irqrestore(&chip->ad1843_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) return val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) * write_ad1843_reg writes the specified value to a 16 bit AD1843 register.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) static int write_ad1843_reg(void *priv, int reg, int word)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) struct snd_sgio2audio *chip = priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) spin_lock_irqsave(&chip->ad1843_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) writeq((reg << CODEC_CONTROL_ADDRESS_SHIFT) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) (word << CODEC_CONTROL_WORD_SHIFT),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) &mace->perif.audio.codec_control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) val = readq(&mace->perif.audio.codec_control); /* flush bus */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) udelay(200);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) spin_unlock_irqrestore(&chip->ad1843_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) static int sgio2audio_gain_info(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) struct snd_ctl_elem_info *uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) struct snd_sgio2audio *chip = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) uinfo->count = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) uinfo->value.integer.min = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) uinfo->value.integer.max = ad1843_get_gain_max(&chip->ad1843,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) (int)kcontrol->private_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) static int sgio2audio_gain_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) struct snd_sgio2audio *chip = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) int vol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) vol = ad1843_get_gain(&chip->ad1843, (int)kcontrol->private_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) ucontrol->value.integer.value[0] = (vol >> 8) & 0xFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) ucontrol->value.integer.value[1] = vol & 0xFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) static int sgio2audio_gain_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) struct snd_sgio2audio *chip = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) int newvol, oldvol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) oldvol = ad1843_get_gain(&chip->ad1843, kcontrol->private_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) newvol = (ucontrol->value.integer.value[0] << 8) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) ucontrol->value.integer.value[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) newvol = ad1843_set_gain(&chip->ad1843, kcontrol->private_value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) newvol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) return newvol != oldvol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) static int sgio2audio_source_info(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) struct snd_ctl_elem_info *uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) static const char * const texts[3] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) "Cam Mic", "Mic", "Line"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) return snd_ctl_enum_info(uinfo, 1, 3, texts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) static int sgio2audio_source_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) struct snd_sgio2audio *chip = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) ucontrol->value.enumerated.item[0] = ad1843_get_recsrc(&chip->ad1843);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) static int sgio2audio_source_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) struct snd_sgio2audio *chip = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) int newsrc, oldsrc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) oldsrc = ad1843_get_recsrc(&chip->ad1843);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) newsrc = ad1843_set_recsrc(&chip->ad1843,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) ucontrol->value.enumerated.item[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) return newsrc != oldsrc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) /* dac1/pcm0 mixer control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) static const struct snd_kcontrol_new sgio2audio_ctrl_pcm0 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) .name = "PCM Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) .index = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) .private_value = AD1843_GAIN_PCM_0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) .info = sgio2audio_gain_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) .get = sgio2audio_gain_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) .put = sgio2audio_gain_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) /* dac2/pcm1 mixer control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) static const struct snd_kcontrol_new sgio2audio_ctrl_pcm1 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) .name = "PCM Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) .index = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) .private_value = AD1843_GAIN_PCM_1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) .info = sgio2audio_gain_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) .get = sgio2audio_gain_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) .put = sgio2audio_gain_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) /* record level mixer control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) static const struct snd_kcontrol_new sgio2audio_ctrl_reclevel = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) .name = "Capture Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) .private_value = AD1843_GAIN_RECLEV,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) .info = sgio2audio_gain_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) .get = sgio2audio_gain_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) .put = sgio2audio_gain_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) /* record level source control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) static const struct snd_kcontrol_new sgio2audio_ctrl_recsource = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) .name = "Capture Source",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) .info = sgio2audio_source_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) .get = sgio2audio_source_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) .put = sgio2audio_source_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) /* line mixer control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) static const struct snd_kcontrol_new sgio2audio_ctrl_line = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) .name = "Line Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) .index = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) .private_value = AD1843_GAIN_LINE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) .info = sgio2audio_gain_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) .get = sgio2audio_gain_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) .put = sgio2audio_gain_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) /* cd mixer control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) static const struct snd_kcontrol_new sgio2audio_ctrl_cd = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) .name = "Line Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) .index = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) .private_value = AD1843_GAIN_LINE_2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) .info = sgio2audio_gain_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) .get = sgio2audio_gain_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) .put = sgio2audio_gain_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) /* mic mixer control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) static const struct snd_kcontrol_new sgio2audio_ctrl_mic = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) .name = "Mic Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) .private_value = AD1843_GAIN_MIC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) .info = sgio2audio_gain_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) .get = sgio2audio_gain_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) .put = sgio2audio_gain_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) static int snd_sgio2audio_new_mixer(struct snd_sgio2audio *chip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) err = snd_ctl_add(chip->card,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) snd_ctl_new1(&sgio2audio_ctrl_pcm0, chip));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) err = snd_ctl_add(chip->card,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) snd_ctl_new1(&sgio2audio_ctrl_pcm1, chip));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) err = snd_ctl_add(chip->card,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) snd_ctl_new1(&sgio2audio_ctrl_reclevel, chip));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) err = snd_ctl_add(chip->card,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) snd_ctl_new1(&sgio2audio_ctrl_recsource, chip));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) err = snd_ctl_add(chip->card,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) snd_ctl_new1(&sgio2audio_ctrl_line, chip));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) err = snd_ctl_add(chip->card,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) snd_ctl_new1(&sgio2audio_ctrl_cd, chip));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) err = snd_ctl_add(chip->card,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) snd_ctl_new1(&sgio2audio_ctrl_mic, chip));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) /* low-level audio interface DMA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) /* get data out of bounce buffer, count must be a multiple of 32 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) /* returns 1 if a period has elapsed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) static int snd_sgio2audio_dma_pull_frag(struct snd_sgio2audio *chip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) unsigned int ch, unsigned int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) unsigned long src_base, src_pos, dst_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) unsigned char *dst_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) int dst_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) u64 *src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) s16 *dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) u64 x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) struct snd_pcm_runtime *runtime = chip->channel[ch].substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) spin_lock_irqsave(&chip->channel[ch].lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) src_base = (unsigned long) chip->ring_base | (ch << CHANNEL_RING_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) src_pos = readq(&mace->perif.audio.chan[ch].read_ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) dst_base = runtime->dma_area;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) dst_pos = chip->channel[ch].pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) dst_mask = frames_to_bytes(runtime, runtime->buffer_size) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) /* check if a period has elapsed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) chip->channel[ch].size += (count >> 3); /* in frames */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) ret = chip->channel[ch].size >= runtime->period_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) chip->channel[ch].size %= runtime->period_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) while (count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) src = (u64 *)(src_base + src_pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) dst = (s16 *)(dst_base + dst_pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) x = *src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) dst[0] = (x >> CHANNEL_LEFT_SHIFT) & 0xffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) dst[1] = (x >> CHANNEL_RIGHT_SHIFT) & 0xffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) src_pos = (src_pos + sizeof(u64)) & CHANNEL_RING_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) dst_pos = (dst_pos + 2 * sizeof(s16)) & dst_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) count -= sizeof(u64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) writeq(src_pos, &mace->perif.audio.chan[ch].read_ptr); /* in bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) chip->channel[ch].pos = dst_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) spin_unlock_irqrestore(&chip->channel[ch].lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) /* put some DMA data in bounce buffer, count must be a multiple of 32 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) /* returns 1 if a period has elapsed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) static int snd_sgio2audio_dma_push_frag(struct snd_sgio2audio *chip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) unsigned int ch, unsigned int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) s64 l, r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) unsigned long dst_base, dst_pos, src_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) unsigned char *src_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) int src_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) u64 *dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) s16 *src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) struct snd_pcm_runtime *runtime = chip->channel[ch].substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) spin_lock_irqsave(&chip->channel[ch].lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) dst_base = (unsigned long)chip->ring_base | (ch << CHANNEL_RING_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) dst_pos = readq(&mace->perif.audio.chan[ch].write_ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) src_base = runtime->dma_area;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) src_pos = chip->channel[ch].pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) src_mask = frames_to_bytes(runtime, runtime->buffer_size) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) /* check if a period has elapsed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) chip->channel[ch].size += (count >> 3); /* in frames */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) ret = chip->channel[ch].size >= runtime->period_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) chip->channel[ch].size %= runtime->period_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) while (count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) src = (s16 *)(src_base + src_pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) dst = (u64 *)(dst_base + dst_pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) l = src[0]; /* sign extend */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) r = src[1]; /* sign extend */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) *dst = ((l & 0x00ffffff) << CHANNEL_LEFT_SHIFT) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) ((r & 0x00ffffff) << CHANNEL_RIGHT_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) dst_pos = (dst_pos + sizeof(u64)) & CHANNEL_RING_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) src_pos = (src_pos + 2 * sizeof(s16)) & src_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) count -= sizeof(u64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) writeq(dst_pos, &mace->perif.audio.chan[ch].write_ptr); /* in bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) chip->channel[ch].pos = src_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) spin_unlock_irqrestore(&chip->channel[ch].lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) static int snd_sgio2audio_dma_start(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) struct snd_sgio2audio *chip = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) struct snd_sgio2audio_chan *chan = substream->runtime->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) int ch = chan->idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) /* reset DMA channel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) writeq(CHANNEL_CONTROL_RESET, &mace->perif.audio.chan[ch].control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) udelay(10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) writeq(0, &mace->perif.audio.chan[ch].control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) /* push a full buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) snd_sgio2audio_dma_push_frag(chip, ch, CHANNEL_RING_SIZE - 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) /* set DMA to wake on 50% empty and enable interrupt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) writeq(CHANNEL_DMA_ENABLE | CHANNEL_INT_THRESHOLD_50,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) &mace->perif.audio.chan[ch].control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) static int snd_sgio2audio_dma_stop(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) struct snd_sgio2audio_chan *chan = substream->runtime->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) writeq(0, &mace->perif.audio.chan[chan->idx].control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) static irqreturn_t snd_sgio2audio_dma_in_isr(int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) struct snd_sgio2audio_chan *chan = dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) struct snd_pcm_substream *substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) struct snd_sgio2audio *chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) int count, ch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) substream = chan->substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) chip = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) ch = chan->idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) /* empty the ring */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) count = CHANNEL_RING_SIZE -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) readq(&mace->perif.audio.chan[ch].depth) - 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) if (snd_sgio2audio_dma_pull_frag(chip, ch, count))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) snd_pcm_period_elapsed(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) static irqreturn_t snd_sgio2audio_dma_out_isr(int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) struct snd_sgio2audio_chan *chan = dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) struct snd_pcm_substream *substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) struct snd_sgio2audio *chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) int count, ch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) substream = chan->substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) chip = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) ch = chan->idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) /* fill the ring */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) count = CHANNEL_RING_SIZE -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) readq(&mace->perif.audio.chan[ch].depth) - 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) if (snd_sgio2audio_dma_push_frag(chip, ch, count))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) snd_pcm_period_elapsed(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) static irqreturn_t snd_sgio2audio_error_isr(int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) struct snd_sgio2audio_chan *chan = dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) struct snd_pcm_substream *substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) substream = chan->substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) snd_sgio2audio_dma_stop(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) snd_sgio2audio_dma_start(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) /* PCM part */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) /* PCM hardware definition */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) static const struct snd_pcm_hardware snd_sgio2audio_pcm_hw = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) .info = (SNDRV_PCM_INFO_MMAP |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) SNDRV_PCM_INFO_MMAP_VALID |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) SNDRV_PCM_INFO_INTERLEAVED |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) SNDRV_PCM_INFO_BLOCK_TRANSFER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) .formats = SNDRV_PCM_FMTBIT_S16_BE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) .rates = SNDRV_PCM_RATE_8000_48000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) .rate_min = 8000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) .rate_max = 48000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) .channels_min = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) .channels_max = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) .buffer_bytes_max = 65536,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) .period_bytes_min = 32768,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) .period_bytes_max = 65536,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) .periods_min = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) .periods_max = 1024,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) /* PCM playback open callback */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) static int snd_sgio2audio_playback1_open(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) struct snd_sgio2audio *chip = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) runtime->hw = snd_sgio2audio_pcm_hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) runtime->private_data = &chip->channel[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) static int snd_sgio2audio_playback2_open(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) struct snd_sgio2audio *chip = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) runtime->hw = snd_sgio2audio_pcm_hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) runtime->private_data = &chip->channel[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) /* PCM capture open callback */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) static int snd_sgio2audio_capture_open(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) struct snd_sgio2audio *chip = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) runtime->hw = snd_sgio2audio_pcm_hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) runtime->private_data = &chip->channel[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) /* PCM close callback */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) static int snd_sgio2audio_pcm_close(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) runtime->private_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) /* prepare callback */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) static int snd_sgio2audio_pcm_prepare(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) struct snd_sgio2audio *chip = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) struct snd_sgio2audio_chan *chan = substream->runtime->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) int ch = chan->idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) spin_lock_irqsave(&chip->channel[ch].lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) /* Setup the pseudo-dma transfer pointers. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) chip->channel[ch].pos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) chip->channel[ch].size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) chip->channel[ch].substream = substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) /* set AD1843 format */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) /* hardware format is always S16_LE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) switch (substream->stream) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) case SNDRV_PCM_STREAM_PLAYBACK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) ad1843_setup_dac(&chip->ad1843,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) ch - 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) runtime->rate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) SNDRV_PCM_FORMAT_S16_LE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) runtime->channels);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) case SNDRV_PCM_STREAM_CAPTURE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) ad1843_setup_adc(&chip->ad1843,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) runtime->rate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) SNDRV_PCM_FORMAT_S16_LE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) runtime->channels);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) spin_unlock_irqrestore(&chip->channel[ch].lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) /* trigger callback */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) static int snd_sgio2audio_pcm_trigger(struct snd_pcm_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) int cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) case SNDRV_PCM_TRIGGER_START:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) /* start the PCM engine */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) snd_sgio2audio_dma_start(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) case SNDRV_PCM_TRIGGER_STOP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) /* stop the PCM engine */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) snd_sgio2audio_dma_stop(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) /* pointer callback */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) static snd_pcm_uframes_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) snd_sgio2audio_pcm_pointer(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) struct snd_sgio2audio *chip = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) struct snd_sgio2audio_chan *chan = substream->runtime->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) /* get the current hardware pointer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) return bytes_to_frames(substream->runtime,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) chip->channel[chan->idx].pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) /* operators */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) static const struct snd_pcm_ops snd_sgio2audio_playback1_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) .open = snd_sgio2audio_playback1_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) .close = snd_sgio2audio_pcm_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) .prepare = snd_sgio2audio_pcm_prepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) .trigger = snd_sgio2audio_pcm_trigger,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) .pointer = snd_sgio2audio_pcm_pointer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) static const struct snd_pcm_ops snd_sgio2audio_playback2_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) .open = snd_sgio2audio_playback2_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) .close = snd_sgio2audio_pcm_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) .prepare = snd_sgio2audio_pcm_prepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) .trigger = snd_sgio2audio_pcm_trigger,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) .pointer = snd_sgio2audio_pcm_pointer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) static const struct snd_pcm_ops snd_sgio2audio_capture_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) .open = snd_sgio2audio_capture_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) .close = snd_sgio2audio_pcm_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) .prepare = snd_sgio2audio_pcm_prepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) .trigger = snd_sgio2audio_pcm_trigger,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) .pointer = snd_sgio2audio_pcm_pointer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) * definitions of capture are omitted here...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) /* create a pcm device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) static int snd_sgio2audio_new_pcm(struct snd_sgio2audio *chip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) struct snd_pcm *pcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) /* create first pcm device with one outputs and one input */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) err = snd_pcm_new(chip->card, "SGI O2 Audio", 0, 1, 1, &pcm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) pcm->private_data = chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) strcpy(pcm->name, "SGI O2 DAC1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) /* set operators */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) &snd_sgio2audio_playback1_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) &snd_sgio2audio_capture_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_VMALLOC, NULL, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) /* create second pcm device with one outputs and no input */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) err = snd_pcm_new(chip->card, "SGI O2 Audio", 1, 1, 0, &pcm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) pcm->private_data = chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) strcpy(pcm->name, "SGI O2 DAC2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) /* set operators */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) &snd_sgio2audio_playback2_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_VMALLOC, NULL, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) static struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) int idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) int irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) irqreturn_t (*isr)(int, void *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) const char *desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) } snd_sgio2_isr_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) .idx = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) .irq = MACEISA_AUDIO1_DMAT_IRQ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) .isr = snd_sgio2audio_dma_in_isr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) .desc = "Capture DMA Channel 0"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) .idx = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) .irq = MACEISA_AUDIO1_OF_IRQ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) .isr = snd_sgio2audio_error_isr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) .desc = "Capture Overflow"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) .idx = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) .irq = MACEISA_AUDIO2_DMAT_IRQ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) .isr = snd_sgio2audio_dma_out_isr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) .desc = "Playback DMA Channel 1"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) .idx = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) .irq = MACEISA_AUDIO2_MERR_IRQ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) .isr = snd_sgio2audio_error_isr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) .desc = "Memory Error Channel 1"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) .idx = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) .irq = MACEISA_AUDIO3_DMAT_IRQ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) .isr = snd_sgio2audio_dma_out_isr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) .desc = "Playback DMA Channel 2"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) .idx = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) .irq = MACEISA_AUDIO3_MERR_IRQ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) .isr = snd_sgio2audio_error_isr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) .desc = "Memory Error Channel 2"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) /* ALSA driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) static int snd_sgio2audio_free(struct snd_sgio2audio *chip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) /* reset interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) writeq(AUDIO_CONTROL_RESET, &mace->perif.audio.control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) udelay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) writeq(0, &mace->perif.audio.control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) /* release IRQ's */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) for (i = 0; i < ARRAY_SIZE(snd_sgio2_isr_table); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) free_irq(snd_sgio2_isr_table[i].irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) &chip->channel[snd_sgio2_isr_table[i].idx]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) dma_free_coherent(chip->card->dev, MACEISA_RINGBUFFERS_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) chip->ring_base, chip->ring_base_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) /* release card data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) kfree(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) static int snd_sgio2audio_dev_free(struct snd_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) struct snd_sgio2audio *chip = device->device_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) return snd_sgio2audio_free(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) static const struct snd_device_ops ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) .dev_free = snd_sgio2audio_dev_free,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) static int snd_sgio2audio_create(struct snd_card *card,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) struct snd_sgio2audio **rchip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) struct snd_sgio2audio *chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) int i, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) *rchip = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) /* check if a codec is attached to the interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) /* (Audio or Audio/Video board present) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) if (!(readq(&mace->perif.audio.control) & AUDIO_CONTROL_CODEC_PRESENT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) chip = kzalloc(sizeof(*chip), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) if (chip == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) chip->card = card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) chip->ring_base = dma_alloc_coherent(card->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) MACEISA_RINGBUFFERS_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) &chip->ring_base_dma, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) if (chip->ring_base == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) printk(KERN_ERR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) "sgio2audio: could not allocate ring buffers\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) kfree(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) spin_lock_init(&chip->ad1843_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) /* initialize channels */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) for (i = 0; i < 3; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) spin_lock_init(&chip->channel[i].lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) chip->channel[i].idx = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) /* allocate IRQs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) for (i = 0; i < ARRAY_SIZE(snd_sgio2_isr_table); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) if (request_irq(snd_sgio2_isr_table[i].irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) snd_sgio2_isr_table[i].isr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) snd_sgio2_isr_table[i].desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) &chip->channel[snd_sgio2_isr_table[i].idx])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) snd_sgio2audio_free(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) printk(KERN_ERR "sgio2audio: cannot allocate irq %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) snd_sgio2_isr_table[i].irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) /* reset the interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) writeq(AUDIO_CONTROL_RESET, &mace->perif.audio.control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) udelay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) writeq(0, &mace->perif.audio.control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) msleep_interruptible(1); /* give time to recover */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) /* set ring base */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) writeq(chip->ring_base_dma, &mace->perif.ctrl.ringbase);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) /* attach the AD1843 codec */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) chip->ad1843.read = read_ad1843_reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) chip->ad1843.write = write_ad1843_reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) chip->ad1843.chip = chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) /* initialize the AD1843 codec */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) err = ad1843_init(&chip->ad1843);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) snd_sgio2audio_free(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) snd_sgio2audio_free(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) *rchip = chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) static int snd_sgio2audio_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) struct snd_card *card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) struct snd_sgio2audio *chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) err = snd_card_new(&pdev->dev, index, id, THIS_MODULE, 0, &card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) err = snd_sgio2audio_create(card, &chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) snd_card_free(card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) err = snd_sgio2audio_new_pcm(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) snd_card_free(card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) err = snd_sgio2audio_new_mixer(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) snd_card_free(card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) strcpy(card->driver, "SGI O2 Audio");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) strcpy(card->shortname, "SGI O2 Audio");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) sprintf(card->longname, "%s irq %i-%i",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) card->shortname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) MACEISA_AUDIO1_DMAT_IRQ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) MACEISA_AUDIO3_MERR_IRQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) err = snd_card_register(card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) snd_card_free(card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) platform_set_drvdata(pdev, card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) static int snd_sgio2audio_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) struct snd_card *card = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) snd_card_free(card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) static struct platform_driver sgio2audio_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) .probe = snd_sgio2audio_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) .remove = snd_sgio2audio_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) .name = "sgio2audio",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) module_platform_driver(sgio2audio_driver);