diff options
Diffstat (limited to 'sound/pci/rme9652/hdspm.c')
| -rw-r--r-- | sound/pci/rme9652/hdspm.c | 700 |
1 files changed, 282 insertions, 418 deletions
diff --git a/sound/pci/rme9652/hdspm.c b/sound/pci/rme9652/hdspm.c index 679ad0415e3b..3ba5bdc96d9d 100644 --- a/sound/pci/rme9652/hdspm.c +++ b/sound/pci/rme9652/hdspm.c @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * ALSA driver for RME Hammerfall DSP MADI audio interface(s) * @@ -23,20 +24,8 @@ * * Modified 2011-01-25 variable period sizes on RayDAT/AIO by Adrian Knoth * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * + * Modified 2019-05-23 fix AIO single speed ADAT capture and playback + * by Philippe.Bekaert@uhasselt.be */ /* ************* Register Documentation ******************************************************* @@ -176,7 +165,6 @@ MODULE_AUTHOR ); MODULE_DESCRIPTION("RME HDSPM"); MODULE_LICENSE("GPL"); -MODULE_SUPPORTED_DEVICE("{{RME HDSPM-MADI}}"); /* --- Write registers. --- These are defined as byte-offsets from the iobase value. */ @@ -648,7 +636,7 @@ MODULE_SUPPORTED_DEVICE("{{RME HDSPM-MADI}}"); #define HDSPM_SPEED_QUAD 2 /* names for speed modes */ -static char *hdspm_speed_names[] = { "single", "double", "quad" }; +static const char * const hdspm_speed_names[] = { "single", "double", "quad" }; static const char *const texts_autosync_aes_tco[] = { "Word Clock", "AES1", "AES2", "AES3", "AES4", @@ -695,7 +683,7 @@ static const char *const texts_freq[] = { "192 kHz" }; -static char *texts_ports_madi[] = { +static const char * const texts_ports_madi[] = { "MADI.1", "MADI.2", "MADI.3", "MADI.4", "MADI.5", "MADI.6", "MADI.7", "MADI.8", "MADI.9", "MADI.10", "MADI.11", "MADI.12", "MADI.13", "MADI.14", "MADI.15", "MADI.16", "MADI.17", "MADI.18", @@ -710,7 +698,7 @@ static char *texts_ports_madi[] = { }; -static char *texts_ports_raydat_ss[] = { +static const char * const texts_ports_raydat_ss[] = { "ADAT1.1", "ADAT1.2", "ADAT1.3", "ADAT1.4", "ADAT1.5", "ADAT1.6", "ADAT1.7", "ADAT1.8", "ADAT2.1", "ADAT2.2", "ADAT2.3", "ADAT2.4", "ADAT2.5", "ADAT2.6", "ADAT2.7", "ADAT2.8", "ADAT3.1", "ADAT3.2", @@ -721,7 +709,7 @@ static char *texts_ports_raydat_ss[] = { "SPDIF.L", "SPDIF.R" }; -static char *texts_ports_raydat_ds[] = { +static const char * const texts_ports_raydat_ds[] = { "ADAT1.1", "ADAT1.2", "ADAT1.3", "ADAT1.4", "ADAT2.1", "ADAT2.2", "ADAT2.3", "ADAT2.4", "ADAT3.1", "ADAT3.2", "ADAT3.3", "ADAT3.4", @@ -730,7 +718,7 @@ static char *texts_ports_raydat_ds[] = { "SPDIF.L", "SPDIF.R" }; -static char *texts_ports_raydat_qs[] = { +static const char * const texts_ports_raydat_qs[] = { "ADAT1.1", "ADAT1.2", "ADAT2.1", "ADAT2.2", "ADAT3.1", "ADAT3.2", @@ -740,7 +728,7 @@ static char *texts_ports_raydat_qs[] = { }; -static char *texts_ports_aio_in_ss[] = { +static const char * const texts_ports_aio_in_ss[] = { "Analogue.L", "Analogue.R", "AES.L", "AES.R", "SPDIF.L", "SPDIF.R", @@ -749,7 +737,7 @@ static char *texts_ports_aio_in_ss[] = { "AEB.1", "AEB.2", "AEB.3", "AEB.4" }; -static char *texts_ports_aio_out_ss[] = { +static const char * const texts_ports_aio_out_ss[] = { "Analogue.L", "Analogue.R", "AES.L", "AES.R", "SPDIF.L", "SPDIF.R", @@ -759,7 +747,7 @@ static char *texts_ports_aio_out_ss[] = { "AEB.1", "AEB.2", "AEB.3", "AEB.4" }; -static char *texts_ports_aio_in_ds[] = { +static const char * const texts_ports_aio_in_ds[] = { "Analogue.L", "Analogue.R", "AES.L", "AES.R", "SPDIF.L", "SPDIF.R", @@ -767,7 +755,7 @@ static char *texts_ports_aio_in_ds[] = { "AEB.1", "AEB.2", "AEB.3", "AEB.4" }; -static char *texts_ports_aio_out_ds[] = { +static const char * const texts_ports_aio_out_ds[] = { "Analogue.L", "Analogue.R", "AES.L", "AES.R", "SPDIF.L", "SPDIF.R", @@ -776,7 +764,7 @@ static char *texts_ports_aio_out_ds[] = { "AEB.1", "AEB.2", "AEB.3", "AEB.4" }; -static char *texts_ports_aio_in_qs[] = { +static const char * const texts_ports_aio_in_qs[] = { "Analogue.L", "Analogue.R", "AES.L", "AES.R", "SPDIF.L", "SPDIF.R", @@ -784,7 +772,7 @@ static char *texts_ports_aio_in_qs[] = { "AEB.1", "AEB.2", "AEB.3", "AEB.4" }; -static char *texts_ports_aio_out_qs[] = { +static const char * const texts_ports_aio_out_qs[] = { "Analogue.L", "Analogue.R", "AES.L", "AES.R", "SPDIF.L", "SPDIF.R", @@ -793,7 +781,7 @@ static char *texts_ports_aio_out_qs[] = { "AEB.1", "AEB.2", "AEB.3", "AEB.4" }; -static char *texts_ports_aes32[] = { +static const char * const texts_ports_aes32[] = { "AES.1", "AES.2", "AES.3", "AES.4", "AES.5", "AES.6", "AES.7", "AES.8", "AES.9.", "AES.10", "AES.11", "AES.12", "AES.13", "AES.14", "AES.15", "AES.16" @@ -807,7 +795,7 @@ static char *texts_ports_aes32[] = { where the data for that channel can be read/written from/to. */ -static char channel_map_unity_ss[HDSPM_MAX_CHANNELS] = { +static const char channel_map_unity_ss[HDSPM_MAX_CHANNELS] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, @@ -818,7 +806,7 @@ static char channel_map_unity_ss[HDSPM_MAX_CHANNELS] = { 56, 57, 58, 59, 60, 61, 62, 63 }; -static char channel_map_raydat_ss[HDSPM_MAX_CHANNELS] = { +static const char channel_map_raydat_ss[HDSPM_MAX_CHANNELS] = { 4, 5, 6, 7, 8, 9, 10, 11, /* ADAT 1 */ 12, 13, 14, 15, 16, 17, 18, 19, /* ADAT 2 */ 20, 21, 22, 23, 24, 25, 26, 27, /* ADAT 3 */ @@ -831,7 +819,7 @@ static char channel_map_raydat_ss[HDSPM_MAX_CHANNELS] = { -1, -1, -1, -1, -1, -1, -1, -1, }; -static char channel_map_raydat_ds[HDSPM_MAX_CHANNELS] = { +static const char channel_map_raydat_ds[HDSPM_MAX_CHANNELS] = { 4, 5, 6, 7, /* ADAT 1 */ 8, 9, 10, 11, /* ADAT 2 */ 12, 13, 14, 15, /* ADAT 3 */ @@ -846,7 +834,7 @@ static char channel_map_raydat_ds[HDSPM_MAX_CHANNELS] = { -1, -1, -1, -1, -1, -1, -1, -1, }; -static char channel_map_raydat_qs[HDSPM_MAX_CHANNELS] = { +static const char channel_map_raydat_qs[HDSPM_MAX_CHANNELS] = { 4, 5, /* ADAT 1 */ 6, 7, /* ADAT 2 */ 8, 9, /* ADAT 3 */ @@ -862,7 +850,7 @@ static char channel_map_raydat_qs[HDSPM_MAX_CHANNELS] = { -1, -1, -1, -1, -1, -1, -1, -1, }; -static char channel_map_aio_in_ss[HDSPM_MAX_CHANNELS] = { +static const char channel_map_aio_in_ss[HDSPM_MAX_CHANNELS] = { 0, 1, /* line in */ 8, 9, /* aes in, */ 10, 11, /* spdif in */ @@ -876,7 +864,7 @@ static char channel_map_aio_in_ss[HDSPM_MAX_CHANNELS] = { -1, -1, -1, -1, -1, -1, -1, -1, }; -static char channel_map_aio_out_ss[HDSPM_MAX_CHANNELS] = { +static const char channel_map_aio_out_ss[HDSPM_MAX_CHANNELS] = { 0, 1, /* line out */ 8, 9, /* aes out */ 10, 11, /* spdif out */ @@ -891,7 +879,7 @@ static char channel_map_aio_out_ss[HDSPM_MAX_CHANNELS] = { -1, -1, -1, -1, -1, -1, -1, -1, }; -static char channel_map_aio_in_ds[HDSPM_MAX_CHANNELS] = { +static const char channel_map_aio_in_ds[HDSPM_MAX_CHANNELS] = { 0, 1, /* line in */ 8, 9, /* aes in */ 10, 11, /* spdif in */ @@ -906,7 +894,7 @@ static char channel_map_aio_in_ds[HDSPM_MAX_CHANNELS] = { -1, -1, -1, -1, -1, -1, -1, -1 }; -static char channel_map_aio_out_ds[HDSPM_MAX_CHANNELS] = { +static const char channel_map_aio_out_ds[HDSPM_MAX_CHANNELS] = { 0, 1, /* line out */ 8, 9, /* aes out */ 10, 11, /* spdif out */ @@ -921,7 +909,7 @@ static char channel_map_aio_out_ds[HDSPM_MAX_CHANNELS] = { -1, -1, -1, -1, -1, -1, -1, -1 }; -static char channel_map_aio_in_qs[HDSPM_MAX_CHANNELS] = { +static const char channel_map_aio_in_qs[HDSPM_MAX_CHANNELS] = { 0, 1, /* line in */ 8, 9, /* aes in */ 10, 11, /* spdif in */ @@ -936,7 +924,7 @@ static char channel_map_aio_in_qs[HDSPM_MAX_CHANNELS] = { -1, -1, -1, -1, -1, -1, -1, -1 }; -static char channel_map_aio_out_qs[HDSPM_MAX_CHANNELS] = { +static const char channel_map_aio_out_qs[HDSPM_MAX_CHANNELS] = { 0, 1, /* line out */ 8, 9, /* aes out */ 10, 11, /* spdif out */ @@ -952,7 +940,7 @@ static char channel_map_aio_out_qs[HDSPM_MAX_CHANNELS] = { -1, -1, -1, -1, -1, -1, -1, -1 }; -static char channel_map_aes32[HDSPM_MAX_CHANNELS] = { +static const char channel_map_aes32[HDSPM_MAX_CHANNELS] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, @@ -1008,7 +996,7 @@ struct hdspm { u32 settings_register; /* cached value for AIO / RayDat (sync reference, master/slave) */ struct hdspm_midi midi[4]; - struct tasklet_struct midi_tasklet; + struct work_struct midi_work; size_t period_bytes; unsigned char ss_in_channels; @@ -1021,17 +1009,21 @@ struct hdspm { unsigned char max_channels_in; unsigned char max_channels_out; - signed char *channel_map_in; - signed char *channel_map_out; + const signed char *channel_map_in; + const signed char *channel_map_out; - signed char *channel_map_in_ss, *channel_map_in_ds, *channel_map_in_qs; - signed char *channel_map_out_ss, *channel_map_out_ds, *channel_map_out_qs; + const signed char *channel_map_in_ss, *channel_map_in_ds, *channel_map_in_qs; + const signed char *channel_map_out_ss, *channel_map_out_ds, *channel_map_out_qs; - char **port_names_in; - char **port_names_out; + const char * const *port_names_in; + const char * const *port_names_out; - char **port_names_in_ss, **port_names_in_ds, **port_names_in_qs; - char **port_names_out_ss, **port_names_out_ds, **port_names_out_qs; + const char * const *port_names_in_ss; + const char * const *port_names_in_ds; + const char * const *port_names_in_qs; + const char * const *port_names_out_ss; + const char * const *port_names_out_ds; + const char * const *port_names_out_qs; unsigned char *playback_buffer; /* suitably aligned address */ unsigned char *capture_buffer; /* suitably aligned address */ @@ -1105,9 +1097,9 @@ static int hdspm_autosync_ref(struct hdspm *hdspm); static int hdspm_set_toggle_setting(struct hdspm *hdspm, u32 regmask, int out); static int snd_hdspm_set_defaults(struct hdspm *hdspm); static int hdspm_system_clock_mode(struct hdspm *hdspm); -static void hdspm_set_sgbuf(struct hdspm *hdspm, - struct snd_pcm_substream *substream, - unsigned int reg, int channels); +static void hdspm_set_channel_dma_addr(struct hdspm *hdspm, + struct snd_pcm_substream *substream, + unsigned int reg, int channels); static int hdspm_aes_sync_check(struct hdspm *hdspm, int idx); static int hdspm_wc_sync_check(struct hdspm *hdspm); @@ -1212,19 +1204,14 @@ static inline void snd_hdspm_enable_out(struct hdspm * hdspm, int i, int v) /* check if same process is writing and reading */ static int snd_hdspm_use_is_exclusive(struct hdspm *hdspm) { - unsigned long flags; - int ret = 1; - - spin_lock_irqsave(&hdspm->lock, flags); + guard(spinlock_irqsave)(&hdspm->lock); if ((hdspm->playback_pid != hdspm->capture_pid) && - (hdspm->playback_pid >= 0) && (hdspm->capture_pid >= 0)) { - ret = 0; - } - spin_unlock_irqrestore(&hdspm->lock, flags); - return ret; + (hdspm->playback_pid >= 0) && (hdspm->capture_pid >= 0)) + return 0; + return 1; } -/* round arbitary sample rates to commonly known rates */ +/* round arbitrary sample rates to commonly known rates */ static int hdspm_round_frequency(int rate) { if (rate < 38050) @@ -1535,7 +1522,7 @@ static int hdspm_set_interrupt_interval(struct hdspm *s, unsigned int frames) { int n; - spin_lock_irq(&s->lock); + guard(spinlock_irq)(&s->lock); if (32 == frames) { /* Special case for new RME cards like RayDAT/AIO which @@ -1565,8 +1552,6 @@ static int hdspm_set_interrupt_interval(struct hdspm *s, unsigned int frames) hdspm_compute_period_size(s); - spin_unlock_irq(&s->lock); - return 0; } @@ -1846,13 +1831,14 @@ static inline int snd_hdspm_midi_output_possible (struct hdspm *hdspm, int id) static void snd_hdspm_flush_midi_input(struct hdspm *hdspm, int id) { - while (snd_hdspm_midi_input_available (hdspm, id)) - snd_hdspm_midi_read_byte (hdspm, id); + int count = 256; + + while (snd_hdspm_midi_input_available(hdspm, id) && --count) + snd_hdspm_midi_read_byte(hdspm, id); } static int snd_hdspm_midi_output_write (struct hdspm_midi *hmidi) { - unsigned long flags; int n_pending; int to_write; int i; @@ -1860,7 +1846,7 @@ static int snd_hdspm_midi_output_write (struct hdspm_midi *hmidi) /* Output is not interrupt driven */ - spin_lock_irqsave (&hmidi->lock, flags); + guard(spinlock_irqsave)(&hmidi->lock); if (hmidi->output && !snd_rawmidi_transmit_empty (hmidi->output)) { n_pending = snd_hdspm_midi_output_possible (hmidi->hdspm, @@ -1879,7 +1865,6 @@ static int snd_hdspm_midi_output_write (struct hdspm_midi *hmidi) } } } - spin_unlock_irqrestore (&hmidi->lock, flags); return 0; } @@ -1888,37 +1873,36 @@ static int snd_hdspm_midi_input_read (struct hdspm_midi *hmidi) unsigned char buf[128]; /* this buffer is designed to match the MIDI * input FIFO size */ - unsigned long flags; int n_pending; int i; - spin_lock_irqsave (&hmidi->lock, flags); - n_pending = snd_hdspm_midi_input_available (hmidi->hdspm, hmidi->id); - if (n_pending > 0) { - if (hmidi->input) { - if (n_pending > (int)sizeof (buf)) - n_pending = sizeof (buf); - for (i = 0; i < n_pending; ++i) - buf[i] = snd_hdspm_midi_read_byte (hmidi->hdspm, - hmidi->id); - if (n_pending) - snd_rawmidi_receive (hmidi->input, buf, - n_pending); - } else { - /* flush the MIDI input FIFO */ - while (n_pending--) - snd_hdspm_midi_read_byte (hmidi->hdspm, - hmidi->id); + scoped_guard(spinlock_irqsave, &hmidi->lock) { + n_pending = snd_hdspm_midi_input_available(hmidi->hdspm, hmidi->id); + if (n_pending > 0) { + if (hmidi->input) { + if (n_pending > (int)sizeof(buf)) + n_pending = sizeof(buf); + for (i = 0; i < n_pending; ++i) + buf[i] = snd_hdspm_midi_read_byte(hmidi->hdspm, + hmidi->id); + if (n_pending) + snd_rawmidi_receive(hmidi->input, buf, + n_pending); + } else { + /* flush the MIDI input FIFO */ + while (n_pending--) + snd_hdspm_midi_read_byte(hmidi->hdspm, + hmidi->id); + } } + hmidi->pending = 0; } - hmidi->pending = 0; - spin_unlock_irqrestore(&hmidi->lock, flags); - spin_lock_irqsave(&hmidi->hdspm->lock, flags); - hmidi->hdspm->control_register |= hmidi->ie; - hdspm_write(hmidi->hdspm, HDSPM_controlRegister, - hmidi->hdspm->control_register); - spin_unlock_irqrestore(&hmidi->hdspm->lock, flags); + scoped_guard(spinlock_irqsave, &hmidi->hdspm->lock) { + hmidi->hdspm->control_register |= hmidi->ie; + hdspm_write(hmidi->hdspm, HDSPM_controlRegister, + hmidi->hdspm->control_register); + } return snd_hdspm_midi_output_write (hmidi); } @@ -1928,12 +1912,11 @@ snd_hdspm_midi_input_trigger(struct snd_rawmidi_substream *substream, int up) { struct hdspm *hdspm; struct hdspm_midi *hmidi; - unsigned long flags; hmidi = substream->rmidi->private_data; hdspm = hmidi->hdspm; - spin_lock_irqsave (&hdspm->lock, flags); + guard(spinlock_irqsave)(&hdspm->lock); if (up) { if (!(hdspm->control_register & hmidi->ie)) { snd_hdspm_flush_midi_input (hdspm, hmidi->id); @@ -1944,16 +1927,14 @@ snd_hdspm_midi_input_trigger(struct snd_rawmidi_substream *substream, int up) } hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); - spin_unlock_irqrestore (&hdspm->lock, flags); } static void snd_hdspm_midi_output_timer(struct timer_list *t) { - struct hdspm_midi *hmidi = from_timer(hmidi, t, timer); - unsigned long flags; + struct hdspm_midi *hmidi = timer_container_of(hmidi, t, timer); snd_hdspm_midi_output_write(hmidi); - spin_lock_irqsave (&hmidi->lock, flags); + guard(spinlock_irqsave)(&hmidi->lock); /* this does not bump hmidi->istimer, because the kernel automatically removed the timer when it @@ -1963,30 +1944,27 @@ static void snd_hdspm_midi_output_timer(struct timer_list *t) if (hmidi->istimer) mod_timer(&hmidi->timer, 1 + jiffies); - - spin_unlock_irqrestore (&hmidi->lock, flags); } static void snd_hdspm_midi_output_trigger(struct snd_rawmidi_substream *substream, int up) { struct hdspm_midi *hmidi; - unsigned long flags; hmidi = substream->rmidi->private_data; - spin_lock_irqsave (&hmidi->lock, flags); - if (up) { - if (!hmidi->istimer) { - timer_setup(&hmidi->timer, - snd_hdspm_midi_output_timer, 0); - mod_timer(&hmidi->timer, 1 + jiffies); - hmidi->istimer++; + scoped_guard(spinlock_irqsave, &hmidi->lock) { + if (up) { + if (!hmidi->istimer) { + timer_setup(&hmidi->timer, + snd_hdspm_midi_output_timer, 0); + mod_timer(&hmidi->timer, 1 + jiffies); + hmidi->istimer++; + } + } else { + if (hmidi->istimer && --hmidi->istimer <= 0) + timer_delete(&hmidi->timer); } - } else { - if (hmidi->istimer && --hmidi->istimer <= 0) - del_timer (&hmidi->timer); } - spin_unlock_irqrestore (&hmidi->lock, flags); if (up) snd_hdspm_midi_output_write(hmidi); } @@ -1996,10 +1974,9 @@ static int snd_hdspm_midi_input_open(struct snd_rawmidi_substream *substream) struct hdspm_midi *hmidi; hmidi = substream->rmidi->private_data; - spin_lock_irq (&hmidi->lock); + guard(spinlock_irq)(&hmidi->lock); snd_hdspm_flush_midi_input (hmidi->hdspm, hmidi->id); hmidi->input = substream; - spin_unlock_irq (&hmidi->lock); return 0; } @@ -2009,9 +1986,8 @@ static int snd_hdspm_midi_output_open(struct snd_rawmidi_substream *substream) struct hdspm_midi *hmidi; hmidi = substream->rmidi->private_data; - spin_lock_irq (&hmidi->lock); + guard(spinlock_irq)(&hmidi->lock); hmidi->output = substream; - spin_unlock_irq (&hmidi->lock); return 0; } @@ -2023,9 +1999,8 @@ static int snd_hdspm_midi_input_close(struct snd_rawmidi_substream *substream) snd_hdspm_midi_input_trigger (substream, 0); hmidi = substream->rmidi->private_data; - spin_lock_irq (&hmidi->lock); + guard(spinlock_irq)(&hmidi->lock); hmidi->input = NULL; - spin_unlock_irq (&hmidi->lock); return 0; } @@ -2037,9 +2012,8 @@ static int snd_hdspm_midi_output_close(struct snd_rawmidi_substream *substream) snd_hdspm_midi_output_trigger (substream, 0); hmidi = substream->rmidi->private_data; - spin_lock_irq (&hmidi->lock); + guard(spinlock_irq)(&hmidi->lock); hmidi->output = NULL; - spin_unlock_irq (&hmidi->lock); return 0; } @@ -2176,9 +2150,9 @@ static int snd_hdspm_create_midi(struct snd_card *card, } -static void hdspm_midi_tasklet(unsigned long arg) +static void hdspm_midi_work(struct work_struct *work) { - struct hdspm *hdspm = (struct hdspm *)arg; + struct hdspm *hdspm = container_of(work, struct hdspm, midi_work); int i = 0; while (i < hdspm->midiPorts) { @@ -2293,7 +2267,6 @@ static int hdspm_get_wc_sample_rate(struct hdspm *hdspm) case AIO: status = hdspm_read(hdspm, HDSPM_RD_STATUS_1); return (status >> 16) & 0xF; - break; case AES32: status = hdspm_read(hdspm, HDSPM_statusRegister); return (status >> HDSPM_AES32_wcFreq_bit) & 0xF; @@ -2319,7 +2292,6 @@ static int hdspm_get_tco_sample_rate(struct hdspm *hdspm) case AIO: status = hdspm_read(hdspm, HDSPM_RD_STATUS_1); return (status >> 20) & 0xF; - break; case AES32: status = hdspm_read(hdspm, HDSPM_statusRegister); return (status >> 1) & 0xF; @@ -2345,7 +2317,6 @@ static int hdspm_get_sync_in_sample_rate(struct hdspm *hdspm) case AIO: status = hdspm_read(hdspm, HDSPM_RD_STATUS_2); return (status >> 12) & 0xF; - break; default: break; } @@ -2365,7 +2336,6 @@ static int hdspm_get_aes_sample_rate(struct hdspm *hdspm, int index) case AES32: timecode = hdspm_read(hdspm, HDSPM_timecodeRegister); return (timecode >> (4*index)) & 0xF; - break; default: break; } @@ -2681,12 +2651,11 @@ static int snd_hdspm_put_clock_source(struct snd_kcontrol *kcontrol, val = 0; if (val > 9) val = 9; - spin_lock_irq(&hdspm->lock); + guard(spinlock_irq)(&hdspm->lock); if (val != hdspm_clock_source(hdspm)) change = (hdspm_set_clock_source(hdspm, val) == 0) ? 1 : 0; else change = 0; - spin_unlock_irq(&hdspm->lock); return change; } @@ -3009,11 +2978,10 @@ static int snd_hdspm_put_pref_sync_ref(struct snd_kcontrol *kcontrol, else if (val >= hdspm->texts_autosync_items) val = hdspm->texts_autosync_items-1; - spin_lock_irq(&hdspm->lock); + guard(spinlock_irq)(&hdspm->lock); if (val != hdspm_pref_sync_ref(hdspm)) change = (0 == hdspm_set_pref_sync_ref(hdspm, val)) ? 1 : 0; - spin_unlock_irq(&hdspm->lock); return change; } @@ -3034,8 +3002,8 @@ static int hdspm_autosync_ref(struct hdspm *hdspm) unsigned int status = hdspm_read(hdspm, HDSPM_statusRegister); unsigned int syncref = (status >> HDSPM_AES32_syncref_bit) & 0xF; - if ((syncref >= HDSPM_AES32_AUTOSYNC_FROM_WORD) && - (syncref <= HDSPM_AES32_AUTOSYNC_FROM_SYNC_IN)) { + /* syncref >= HDSPM_AES32_AUTOSYNC_FROM_WORD is always true */ + if (syncref <= HDSPM_AES32_AUTOSYNC_FROM_SYNC_IN) { return syncref; } return HDSPM_AES32_AUTOSYNC_FROM_NONE; @@ -3093,7 +3061,7 @@ static int snd_hdspm_get_autosync_ref(struct snd_kcontrol *kcontrol, -#define HDSPM_TCO_VIDEO_INPUT_FORMAT(xname, xindex) \ +#define HDSPM_TCO_VIDEO_INPUT_FORMAT(xname) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = xname, \ .access = SNDRV_CTL_ELEM_ACCESS_READ |\ @@ -3139,7 +3107,7 @@ static int snd_hdspm_get_tco_video_input_format(struct snd_kcontrol *kcontrol, -#define HDSPM_TCO_LTC_FRAMES(xname, xindex) \ +#define HDSPM_TCO_LTC_FRAMES(xname) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = xname, \ .access = SNDRV_CTL_ELEM_ACCESS_READ |\ @@ -3249,9 +3217,8 @@ static int snd_hdspm_get_toggle_setting(struct snd_kcontrol *kcontrol, struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); u32 regmask = kcontrol->private_value; - spin_lock_irq(&hdspm->lock); + guard(spinlock_irq)(&hdspm->lock); ucontrol->value.integer.value[0] = hdspm_toggle_setting(hdspm, regmask); - spin_unlock_irq(&hdspm->lock); return 0; } @@ -3266,10 +3233,9 @@ static int snd_hdspm_put_toggle_setting(struct snd_kcontrol *kcontrol, if (!snd_hdspm_use_is_exclusive(hdspm)) return -EBUSY; val = ucontrol->value.integer.value[0] & 1; - spin_lock_irq(&hdspm->lock); + guard(spinlock_irq)(&hdspm->lock); change = (int) val != hdspm_toggle_setting(hdspm, regmask); hdspm_set_toggle_setting(hdspm, regmask, val); - spin_unlock_irq(&hdspm->lock); return change; } @@ -3311,9 +3277,8 @@ static int snd_hdspm_get_input_select(struct snd_kcontrol *kcontrol, { struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); - spin_lock_irq(&hdspm->lock); + guard(spinlock_irq)(&hdspm->lock); ucontrol->value.enumerated.item[0] = hdspm_input_select(hdspm); - spin_unlock_irq(&hdspm->lock); return 0; } @@ -3327,10 +3292,9 @@ static int snd_hdspm_put_input_select(struct snd_kcontrol *kcontrol, if (!snd_hdspm_use_is_exclusive(hdspm)) return -EBUSY; val = ucontrol->value.integer.value[0] & 1; - spin_lock_irq(&hdspm->lock); + guard(spinlock_irq)(&hdspm->lock); change = (int) val != hdspm_input_select(hdspm); hdspm_set_input_select(hdspm, val); - spin_unlock_irq(&hdspm->lock); return change; } @@ -3373,9 +3337,8 @@ static int snd_hdspm_get_ds_wire(struct snd_kcontrol *kcontrol, { struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); - spin_lock_irq(&hdspm->lock); + guard(spinlock_irq)(&hdspm->lock); ucontrol->value.enumerated.item[0] = hdspm_ds_wire(hdspm); - spin_unlock_irq(&hdspm->lock); return 0; } @@ -3389,10 +3352,9 @@ static int snd_hdspm_put_ds_wire(struct snd_kcontrol *kcontrol, if (!snd_hdspm_use_is_exclusive(hdspm)) return -EBUSY; val = ucontrol->value.integer.value[0] & 1; - spin_lock_irq(&hdspm->lock); + guard(spinlock_irq)(&hdspm->lock); change = (int) val != hdspm_ds_wire(hdspm); hdspm_set_ds_wire(hdspm, val); - spin_unlock_irq(&hdspm->lock); return change; } @@ -3446,9 +3408,8 @@ static int snd_hdspm_get_qs_wire(struct snd_kcontrol *kcontrol, { struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); - spin_lock_irq(&hdspm->lock); + guard(spinlock_irq)(&hdspm->lock); ucontrol->value.enumerated.item[0] = hdspm_qs_wire(hdspm); - spin_unlock_irq(&hdspm->lock); return 0; } @@ -3466,10 +3427,9 @@ static int snd_hdspm_put_qs_wire(struct snd_kcontrol *kcontrol, val = 0; if (val > 2) val = 2; - spin_lock_irq(&hdspm->lock); + guard(spinlock_irq)(&hdspm->lock); change = val != hdspm_qs_wire(hdspm); hdspm_set_qs_wire(hdspm, val); - spin_unlock_irq(&hdspm->lock); return change; } @@ -3522,9 +3482,8 @@ static int snd_hdspm_get_tristate(struct snd_kcontrol *kcontrol, struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); u32 regmask = kcontrol->private_value; - spin_lock_irq(&hdspm->lock); + guard(spinlock_irq)(&hdspm->lock); ucontrol->value.enumerated.item[0] = hdspm_tristate(hdspm, regmask); - spin_unlock_irq(&hdspm->lock); return 0; } @@ -3544,10 +3503,9 @@ static int snd_hdspm_put_tristate(struct snd_kcontrol *kcontrol, if (val > 2) val = 2; - spin_lock_irq(&hdspm->lock); + guard(spinlock_irq)(&hdspm->lock); change = val != hdspm_tristate(hdspm, regmask); hdspm_set_tristate(hdspm, val, regmask); - spin_unlock_irq(&hdspm->lock); return change; } @@ -3600,9 +3558,8 @@ static int snd_hdspm_get_madi_speedmode(struct snd_kcontrol *kcontrol, { struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); - spin_lock_irq(&hdspm->lock); + guard(spinlock_irq)(&hdspm->lock); ucontrol->value.enumerated.item[0] = hdspm_madi_speedmode(hdspm); - spin_unlock_irq(&hdspm->lock); return 0; } @@ -3620,10 +3577,9 @@ static int snd_hdspm_put_madi_speedmode(struct snd_kcontrol *kcontrol, val = 0; if (val > 2) val = 2; - spin_lock_irq(&hdspm->lock); + guard(spinlock_irq)(&hdspm->lock); change = val != hdspm_madi_speedmode(hdspm); hdspm_set_madi_speedmode(hdspm, val); - spin_unlock_irq(&hdspm->lock); return change; } @@ -3669,7 +3625,7 @@ static int snd_hdspm_get_mixer(struct snd_kcontrol *kcontrol, else if (destination >= HDSPM_MAX_CHANNELS) destination = HDSPM_MAX_CHANNELS - 1; - spin_lock_irq(&hdspm->lock); + guard(spinlock_irq)(&hdspm->lock); if (source >= HDSPM_MAX_CHANNELS) ucontrol->value.integer.value[2] = hdspm_read_pb_gain(hdspm, destination, @@ -3678,8 +3634,6 @@ static int snd_hdspm_get_mixer(struct snd_kcontrol *kcontrol, ucontrol->value.integer.value[2] = hdspm_read_in_gain(hdspm, destination, source); - spin_unlock_irq(&hdspm->lock); - return 0; } @@ -3705,7 +3659,7 @@ static int snd_hdspm_put_mixer(struct snd_kcontrol *kcontrol, gain = ucontrol->value.integer.value[2]; - spin_lock_irq(&hdspm->lock); + guard(spinlock_irq)(&hdspm->lock); if (source >= HDSPM_MAX_CHANNELS) change = gain != hdspm_read_pb_gain(hdspm, destination, @@ -3724,7 +3678,6 @@ static int snd_hdspm_put_mixer(struct snd_kcontrol *kcontrol, hdspm_write_in_gain(hdspm, destination, source, gain); } - spin_unlock_irq(&hdspm->lock); return change; } @@ -3765,10 +3718,9 @@ static int snd_hdspm_get_playback_mixer(struct snd_kcontrol *kcontrol, if (snd_BUG_ON(channel < 0 || channel >= HDSPM_MAX_CHANNELS)) return -EINVAL; - spin_lock_irq(&hdspm->lock); + guard(spinlock_irq)(&hdspm->lock); ucontrol->value.integer.value[0] = (hdspm_read_pb_gain(hdspm, channel, channel)*64)/UNITY_GAIN; - spin_unlock_irq(&hdspm->lock); return 0; } @@ -3791,14 +3743,13 @@ static int snd_hdspm_put_playback_mixer(struct snd_kcontrol *kcontrol, gain = ucontrol->value.integer.value[0]*UNITY_GAIN/64; - spin_lock_irq(&hdspm->lock); + guard(spinlock_irq)(&hdspm->lock); change = gain != hdspm_read_pb_gain(hdspm, channel, channel); if (change) hdspm_write_pb_gain(hdspm, channel, channel, gain); - spin_unlock_irq(&hdspm->lock); return change; } @@ -3852,7 +3803,6 @@ static int hdspm_wc_sync_check(struct hdspm *hdspm) return 1; } return 0; - break; case MADI: status2 = hdspm_read(hdspm, HDSPM_statusRegister2); @@ -3863,7 +3813,6 @@ static int hdspm_wc_sync_check(struct hdspm *hdspm) return 1; } return 0; - break; case RayDAT: case AIO: @@ -3875,8 +3824,6 @@ static int hdspm_wc_sync_check(struct hdspm *hdspm) return 1; return 0; - break; - case MADIface: break; } @@ -4489,7 +4436,7 @@ static int snd_hdspm_put_tco_word_term(struct snd_kcontrol *kcontrol, -static struct snd_kcontrol_new snd_hdspm_controls_madi[] = { +static const struct snd_kcontrol_new snd_hdspm_controls_madi[] = { HDSPM_MIXER("Mixer", 0), HDSPM_INTERNAL_CLOCK("Internal Clock", 0), HDSPM_SYSTEM_CLOCK_MODE("System Clock Mode", 0), @@ -4511,7 +4458,7 @@ static struct snd_kcontrol_new snd_hdspm_controls_madi[] = { }; -static struct snd_kcontrol_new snd_hdspm_controls_madiface[] = { +static const struct snd_kcontrol_new snd_hdspm_controls_madiface[] = { HDSPM_MIXER("Mixer", 0), HDSPM_INTERNAL_CLOCK("Internal Clock", 0), HDSPM_SYSTEM_CLOCK_MODE("System Clock Mode", 0), @@ -4524,7 +4471,7 @@ static struct snd_kcontrol_new snd_hdspm_controls_madiface[] = { HDSPM_MADI_SPEEDMODE("MADI Speed Mode", 0) }; -static struct snd_kcontrol_new snd_hdspm_controls_aio[] = { +static const struct snd_kcontrol_new snd_hdspm_controls_aio[] = { HDSPM_MIXER("Mixer", 0), HDSPM_INTERNAL_CLOCK("Internal Clock", 0), HDSPM_SYSTEM_CLOCK_MODE("System Clock Mode", 0), @@ -4565,7 +4512,7 @@ static struct snd_kcontrol_new snd_hdspm_controls_aio[] = { */ }; -static struct snd_kcontrol_new snd_hdspm_controls_raydat[] = { +static const struct snd_kcontrol_new snd_hdspm_controls_raydat[] = { HDSPM_MIXER("Mixer", 0), HDSPM_INTERNAL_CLOCK("Internal Clock", 0), HDSPM_SYSTEM_CLOCK_MODE("Clock Mode", 0), @@ -4593,7 +4540,7 @@ static struct snd_kcontrol_new snd_hdspm_controls_raydat[] = { HDSPM_TOGGLE_SETTING("Single Speed WordClock Out", HDSPM_c0_Wck48) }; -static struct snd_kcontrol_new snd_hdspm_controls_aes32[] = { +static const struct snd_kcontrol_new snd_hdspm_controls_aes32[] = { HDSPM_MIXER("Mixer", 0), HDSPM_INTERNAL_CLOCK("Internal Clock", 0), HDSPM_SYSTEM_CLOCK_MODE("System Clock Mode", 0), @@ -4635,7 +4582,7 @@ static struct snd_kcontrol_new snd_hdspm_controls_aes32[] = { /* Control elements for the optional TCO module */ -static struct snd_kcontrol_new snd_hdspm_controls_tco[] = { +static const struct snd_kcontrol_new snd_hdspm_controls_tco[] = { HDSPM_TCO_SAMPLE_RATE("TCO Sample Rate", 0), HDSPM_TCO_PULL("TCO Pull", 0), HDSPM_TCO_WCK_CONVERSION("TCO WCK Conversion", 0), @@ -4644,8 +4591,8 @@ static struct snd_kcontrol_new snd_hdspm_controls_tco[] = { HDSPM_TCO_WORD_TERM("TCO Word Term", 0), HDSPM_TCO_LOCK_CHECK("TCO Input Check", 11), HDSPM_TCO_LOCK_CHECK("TCO LTC Valid", 12), - HDSPM_TCO_LTC_FRAMES("TCO Detected Frame Rate", 0), - HDSPM_TCO_VIDEO_INPUT_FORMAT("Video Input Format", 0) + HDSPM_TCO_LTC_FRAMES("TCO Detected Frame Rate"), + HDSPM_TCO_VIDEO_INPUT_FORMAT("Video Input Format") }; @@ -4682,7 +4629,7 @@ static int snd_hdspm_create_controls(struct snd_card *card, unsigned int idx, limit; int err; struct snd_kcontrol *kctl; - struct snd_kcontrol_new *list = NULL; + const struct snd_kcontrol_new *list = NULL; switch (hdspm->io_type) { case MADI: @@ -4941,14 +4888,14 @@ snd_hdspm_proc_read_madi(struct snd_info_entry *entry, x, (unsigned long) hdspm->period_bytes); snd_iprintf(buffer, "Line out: %s\n", - (hdspm->control_register & HDSPM_LineOut) ? "on " : "off"); + str_on_off(hdspm->control_register & HDSPM_LineOut)); snd_iprintf(buffer, "ClearTrackMarker = %s, Transmit in %s Channel Mode, " "Auto Input %s\n", - (hdspm->control_register & HDSPM_clr_tms) ? "on" : "off", + str_on_off(hdspm->control_register & HDSPM_clr_tms), (hdspm->control_register & HDSPM_TX_64ch) ? "64" : "56", - (hdspm->control_register & HDSPM_AutoInp) ? "on" : "off"); + str_on_off(hdspm->control_register & HDSPM_AutoInp)); if (!(hdspm->control_register & HDSPM_ClockModeMaster)) @@ -5102,12 +5049,9 @@ snd_hdspm_proc_read_aes32(struct snd_info_entry * entry, snd_iprintf(buffer, "ClearTrackMarker %s, Emphasis %s, Dolby %s\n", - (hdspm-> - control_register & HDSPM_clr_tms) ? "on" : "off", - (hdspm-> - control_register & HDSPM_Emphasis) ? "on" : "off", - (hdspm-> - control_register & HDSPM_Dolby) ? "on" : "off"); + str_on_off(hdspm->control_register & HDSPM_clr_tms), + str_on_off(hdspm->control_register & HDSPM_Emphasis), + str_on_off(hdspm->control_register & HDSPM_Dolby)); pref_syncref = hdspm_pref_sync_ref(hdspm); @@ -5287,44 +5231,35 @@ static void snd_hdspm_proc_ports_out(struct snd_info_entry *entry, static void snd_hdspm_proc_init(struct hdspm *hdspm) { - struct snd_info_entry *entry; + void (*read)(struct snd_info_entry *, struct snd_info_buffer *) = NULL; - if (!snd_card_proc_new(hdspm->card, "hdspm", &entry)) { - switch (hdspm->io_type) { - case AES32: - snd_info_set_text_ops(entry, hdspm, - snd_hdspm_proc_read_aes32); - break; - case MADI: - snd_info_set_text_ops(entry, hdspm, - snd_hdspm_proc_read_madi); - break; - case MADIface: - /* snd_info_set_text_ops(entry, hdspm, - snd_hdspm_proc_read_madiface); */ - break; - case RayDAT: - snd_info_set_text_ops(entry, hdspm, - snd_hdspm_proc_read_raydat); - break; - case AIO: - break; - } - } - - if (!snd_card_proc_new(hdspm->card, "ports.in", &entry)) { - snd_info_set_text_ops(entry, hdspm, snd_hdspm_proc_ports_in); + switch (hdspm->io_type) { + case AES32: + read = snd_hdspm_proc_read_aes32; + break; + case MADI: + read = snd_hdspm_proc_read_madi; + break; + case MADIface: + /* read = snd_hdspm_proc_read_madiface; */ + break; + case RayDAT: + read = snd_hdspm_proc_read_raydat; + break; + case AIO: + break; } - if (!snd_card_proc_new(hdspm->card, "ports.out", &entry)) { - snd_info_set_text_ops(entry, hdspm, snd_hdspm_proc_ports_out); - } + snd_card_ro_proc_new(hdspm->card, "hdspm", hdspm, read); + snd_card_ro_proc_new(hdspm->card, "ports.in", hdspm, + snd_hdspm_proc_ports_in); + snd_card_ro_proc_new(hdspm->card, "ports.out", hdspm, + snd_hdspm_proc_ports_out); #ifdef CONFIG_SND_DEBUG /* debug file to read all hdspm registers */ - if (!snd_card_proc_new(hdspm->card, "debug", &entry)) - snd_info_set_text_ops(entry, hdspm, - snd_hdspm_proc_read_debug); + snd_card_ro_proc_new(hdspm->card, "debug", hdspm, + snd_hdspm_proc_read_debug); #endif } @@ -5465,7 +5400,7 @@ static irqreturn_t snd_hdspm_interrupt(int irq, void *dev_id) } if (schedule) - tasklet_hi_schedule(&hdspm->midi_tasklet); + queue_work(system_highpri_wq, &hdspm->midi_work); } return IRQ_HANDLED; @@ -5522,53 +5457,50 @@ static int snd_hdspm_hw_params(struct snd_pcm_substream *substream, pid_t this_pid; pid_t other_pid; - spin_lock_irq(&hdspm->lock); + scoped_guard(spinlock_irq, &hdspm->lock) { - if (substream->pstr->stream == SNDRV_PCM_STREAM_PLAYBACK) { - this_pid = hdspm->playback_pid; - other_pid = hdspm->capture_pid; - } else { - this_pid = hdspm->capture_pid; - other_pid = hdspm->playback_pid; - } + if (substream->pstr->stream == SNDRV_PCM_STREAM_PLAYBACK) { + this_pid = hdspm->playback_pid; + other_pid = hdspm->capture_pid; + } else { + this_pid = hdspm->capture_pid; + other_pid = hdspm->playback_pid; + } - if (other_pid > 0 && this_pid != other_pid) { + if (other_pid > 0 && this_pid != other_pid) { - /* The other stream is open, and not by the same - task as this one. Make sure that the parameters - that matter are the same. - */ + /* The other stream is open, and not by the same + task as this one. Make sure that the parameters + that matter are the same. + */ - if (params_rate(params) != hdspm->system_sample_rate) { - spin_unlock_irq(&hdspm->lock); - _snd_pcm_hw_param_setempty(params, - SNDRV_PCM_HW_PARAM_RATE); - return -EBUSY; - } + if (params_rate(params) != hdspm->system_sample_rate) { + _snd_pcm_hw_param_setempty(params, + SNDRV_PCM_HW_PARAM_RATE); + return -EBUSY; + } - if (params_period_size(params) != hdspm->period_bytes / 4) { - spin_unlock_irq(&hdspm->lock); - _snd_pcm_hw_param_setempty(params, - SNDRV_PCM_HW_PARAM_PERIOD_SIZE); - return -EBUSY; - } + if (params_period_size(params) != hdspm->period_bytes / 4) { + _snd_pcm_hw_param_setempty(params, + SNDRV_PCM_HW_PARAM_PERIOD_SIZE); + return -EBUSY; + } + } } /* We're fine. */ - spin_unlock_irq(&hdspm->lock); /* how to make sure that the rate matches an externally-set one ? */ - spin_lock_irq(&hdspm->lock); - err = hdspm_set_rate(hdspm, params_rate(params), 0); - if (err < 0) { - dev_info(hdspm->card->dev, "err on hdspm_set_rate: %d\n", err); - spin_unlock_irq(&hdspm->lock); - _snd_pcm_hw_param_setempty(params, - SNDRV_PCM_HW_PARAM_RATE); - return err; + scoped_guard(spinlock_irq, &hdspm->lock) { + err = hdspm_set_rate(hdspm, params_rate(params), 0); + if (err < 0) { + dev_info(hdspm->card->dev, "err on hdspm_set_rate: %d\n", err); + _snd_pcm_hw_param_setempty(params, + SNDRV_PCM_HW_PARAM_RATE); + return err; + } } - spin_unlock_irq(&hdspm->lock); err = hdspm_set_interrupt_interval(hdspm, params_period_size(params)); @@ -5597,11 +5529,16 @@ static int snd_hdspm_hw_params(struct snd_pcm_substream *substream, if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { - hdspm_set_sgbuf(hdspm, substream, HDSPM_pageAddressBufferOut, - params_channels(params)); + for (i = 0; i < params_channels(params); ++i) { + int c = hdspm->channel_map_out[i]; - for (i = 0; i < params_channels(params); ++i) - snd_hdspm_enable_out(hdspm, i, 1); + if (c < 0) + continue; /* just make sure */ + hdspm_set_channel_dma_addr(hdspm, substream, + HDSPM_pageAddressBufferOut, + c); + snd_hdspm_enable_out(hdspm, c, 1); + } hdspm->playback_buffer = (unsigned char *) substream->runtime->dma_area; @@ -5609,11 +5546,16 @@ static int snd_hdspm_hw_params(struct snd_pcm_substream *substream, "Allocated sample buffer for playback at %p\n", hdspm->playback_buffer); } else { - hdspm_set_sgbuf(hdspm, substream, HDSPM_pageAddressBufferIn, - params_channels(params)); - - for (i = 0; i < params_channels(params); ++i) - snd_hdspm_enable_in(hdspm, i, 1); + for (i = 0; i < params_channels(params); ++i) { + int c = hdspm->channel_map_in[i]; + + if (c < 0) + continue; + hdspm_set_channel_dma_addr(hdspm, substream, + HDSPM_pageAddressBufferIn, + c); + snd_hdspm_enable_in(hdspm, c, 1); + } hdspm->capture_buffer = (unsigned char *) substream->runtime->dma_area; @@ -5625,15 +5567,13 @@ static int snd_hdspm_hw_params(struct snd_pcm_substream *substream, /* dev_dbg(hdspm->card->dev, "Allocated sample buffer for %s at 0x%08X\n", - substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? - "playback" : "capture", + snd_pcm_direction_name(substream->stream), snd_pcm_sgbuf_get_addr(substream, 0)); */ /* dev_dbg(hdspm->card->dev, "set_hwparams: %s %d Hz, %d channels, bs = %d\n", - substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? - "playback" : "capture", + snd_pcm_direction_name(substream->stream), params_rate(params), params_channels(params), params_buffer_size(params)); */ @@ -5674,19 +5614,17 @@ static int snd_hdspm_hw_free(struct snd_pcm_substream *substream) struct hdspm *hdspm = snd_pcm_substream_chip(substream); if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { - - /* params_channels(params) should be enough, - but to get sure in case of error */ - for (i = 0; i < hdspm->max_channels_out; ++i) + /* Just disable all channels. The saving when disabling a */ + /* smaller set is not worth the trouble. */ + for (i = 0; i < HDSPM_MAX_CHANNELS; ++i) snd_hdspm_enable_out(hdspm, i, 0); hdspm->playback_buffer = NULL; } else { - for (i = 0; i < hdspm->max_channels_in; ++i) + for (i = 0; i < HDSPM_MAX_CHANNELS; ++i) snd_hdspm_enable_in(hdspm, i, 0); hdspm->capture_buffer = NULL; - } snd_pcm_lib_free_pages(substream); @@ -5770,7 +5708,7 @@ static int snd_hdspm_trigger(struct snd_pcm_substream *substream, int cmd) struct snd_pcm_substream *other; int running; - spin_lock(&hdspm->lock); + guard(spinlock)(&hdspm->lock); running = hdspm->running; switch (cmd) { case SNDRV_PCM_TRIGGER_START: @@ -5781,7 +5719,6 @@ static int snd_hdspm_trigger(struct snd_pcm_substream *substream, int cmd) break; default: snd_BUG(); - spin_unlock(&hdspm->lock); return -EINVAL; } if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) @@ -5822,7 +5759,6 @@ _ok: else if (hdspm->running && !running) hdspm_stop_audio(hdspm); hdspm->running = running; - spin_unlock(&hdspm->lock); return 0; } @@ -5832,7 +5768,7 @@ static int snd_hdspm_prepare(struct snd_pcm_substream *substream) return 0; } -static struct snd_pcm_hardware snd_hdspm_playback_subinfo = { +static const struct snd_pcm_hardware snd_hdspm_playback_subinfo = { .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_NONINTERLEAVED | @@ -5857,7 +5793,7 @@ static struct snd_pcm_hardware snd_hdspm_playback_subinfo = { .fifo_size = 0 }; -static struct snd_pcm_hardware snd_hdspm_capture_subinfo = { +static const struct snd_pcm_hardware snd_hdspm_capture_subinfo = { .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_NONINTERLEAVED | @@ -6049,45 +5985,32 @@ static int snd_hdspm_hw_rule_out_channels(struct snd_pcm_hw_params *params, return snd_interval_list(c, 3, list, 0); } - -static const unsigned int hdspm_aes32_sample_rates[] = { - 32000, 44100, 48000, 64000, 88200, 96000, 128000, 176400, 192000 -}; - -static const struct snd_pcm_hw_constraint_list -hdspm_hw_constraints_aes32_sample_rates = { - .count = ARRAY_SIZE(hdspm_aes32_sample_rates), - .list = hdspm_aes32_sample_rates, - .mask = 0 -}; - static int snd_hdspm_open(struct snd_pcm_substream *substream) { struct hdspm *hdspm = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; bool playback = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK); - spin_lock_irq(&hdspm->lock); - snd_pcm_set_sync(substream); - runtime->hw = (playback) ? snd_hdspm_playback_subinfo : - snd_hdspm_capture_subinfo; + scoped_guard(spinlock_irq, &hdspm->lock) { + snd_pcm_set_sync(substream); + runtime->hw = (playback) ? snd_hdspm_playback_subinfo : + snd_hdspm_capture_subinfo; - if (playback) { - if (!hdspm->capture_substream) - hdspm_stop_audio(hdspm); + if (playback) { + if (!hdspm->capture_substream) + hdspm_stop_audio(hdspm); - hdspm->playback_pid = current->pid; - hdspm->playback_substream = substream; - } else { - if (!hdspm->playback_substream) - hdspm_stop_audio(hdspm); + hdspm->playback_pid = current->pid; + hdspm->playback_substream = substream; + } else { + if (!hdspm->playback_substream) + hdspm_stop_audio(hdspm); - hdspm->capture_pid = current->pid; - hdspm->capture_substream = substream; + hdspm->capture_pid = current->pid; + hdspm->capture_substream = substream; + } } - spin_unlock_irq(&hdspm->lock); - snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24); snd_pcm_hw_constraint_pow2(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE); @@ -6113,9 +6036,7 @@ static int snd_hdspm_open(struct snd_pcm_substream *substream) } if (AES32 == hdspm->io_type) { - runtime->hw.rates |= SNDRV_PCM_RATE_KNOT; - snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, - &hdspm_hw_constraints_aes32_sample_rates); + runtime->hw.rates |= SNDRV_PCM_RATE_128000; } else { snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, (playback ? @@ -6142,7 +6063,7 @@ static int snd_hdspm_release(struct snd_pcm_substream *substream) struct hdspm *hdspm = snd_pcm_substream_chip(substream); bool playback = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK); - spin_lock_irq(&hdspm->lock); + guard(spinlock_irq)(&hdspm->lock); if (playback) { hdspm->playback_pid = -1; @@ -6152,8 +6073,6 @@ static int snd_hdspm_release(struct snd_pcm_substream *substream) hdspm->capture_substream = NULL; } - spin_unlock_irq(&hdspm->lock); - return 0; } @@ -6163,12 +6082,6 @@ static int snd_hdspm_hwdep_dummy_op(struct snd_hwdep *hw, struct file *file) return 0; } -static inline int copy_u32_le(void __user *dest, void __iomem *src) -{ - u32 val = readl(src); - return copy_to_user(dest, &val, 4); -} - static int snd_hdspm_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, unsigned int cmd, unsigned long arg) { @@ -6282,19 +6195,19 @@ static int snd_hdspm_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, case SNDRV_HDSPM_IOCTL_GET_CONFIG: memset(&info, 0, sizeof(info)); - spin_lock_irq(&hdspm->lock); - info.pref_sync_ref = hdspm_pref_sync_ref(hdspm); - info.wordclock_sync_check = hdspm_wc_sync_check(hdspm); - - info.system_sample_rate = hdspm->system_sample_rate; - info.autosync_sample_rate = - hdspm_external_sample_rate(hdspm); - info.system_clock_mode = hdspm_system_clock_mode(hdspm); - info.clock_source = hdspm_clock_source(hdspm); - info.autosync_ref = hdspm_autosync_ref(hdspm); - info.line_out = hdspm_toggle_setting(hdspm, HDSPM_LineOut); - info.passthru = 0; - spin_unlock_irq(&hdspm->lock); + scoped_guard(spinlock_irq, &hdspm->lock) { + info.pref_sync_ref = hdspm_pref_sync_ref(hdspm); + info.wordclock_sync_check = hdspm_wc_sync_check(hdspm); + + info.system_sample_rate = hdspm->system_sample_rate; + info.autosync_sample_rate = + hdspm_external_sample_rate(hdspm); + info.system_clock_mode = hdspm_system_clock_mode(hdspm); + info.clock_source = hdspm_clock_source(hdspm); + info.autosync_ref = hdspm_autosync_ref(hdspm); + info.line_out = hdspm_toggle_setting(hdspm, HDSPM_LineOut); + info.passthru = 0; + } if (copy_to_user(argp, &info, sizeof(info))) return -EFAULT; break; @@ -6329,6 +6242,7 @@ static int snd_hdspm_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, (statusregister & HDSPM_RX_64ch) ? 1 : 0; /* TODO: Mac driver sets it when f_s>48kHz */ status.card_specific.madi.frame_format = 0; + break; default: break; @@ -6344,7 +6258,7 @@ static int snd_hdspm_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, memset(&hdspm_version, 0, sizeof(hdspm_version)); hdspm_version.card_type = hdspm->io_type; - strlcpy(hdspm_version.cardname, hdspm->card_name, + strscpy(hdspm_version.cardname, hdspm->card_name, sizeof(hdspm_version.cardname)); hdspm_version.serial = hdspm->serial; hdspm_version.firmware_rev = hdspm->firmware_rev; @@ -6380,7 +6294,6 @@ static const struct snd_pcm_ops snd_hdspm_ops = { .prepare = snd_hdspm_prepare, .trigger = snd_hdspm_trigger, .pointer = snd_hdspm_hw_pointer, - .page = snd_pcm_sgbuf_ops_page, }; static int snd_hdspm_create_hwdep(struct snd_card *card, @@ -6395,7 +6308,7 @@ static int snd_hdspm_create_hwdep(struct snd_card *card, hdspm->hwdep = hw; hw->private_data = hdspm; - strcpy(hw->name, "HDSPM hwdep interface"); + strscpy(hw->name, "HDSPM hwdep interface"); hw->ops.open = snd_hdspm_hwdep_dummy_op; hw->ops.ioctl = snd_hdspm_hwdep_ioctl; @@ -6411,7 +6324,6 @@ static int snd_hdspm_create_hwdep(struct snd_card *card, ------------------------------------------------------------*/ static int snd_hdspm_preallocate_memory(struct hdspm *hdspm) { - int err; struct snd_pcm *pcm; size_t wanted; @@ -6419,35 +6331,24 @@ static int snd_hdspm_preallocate_memory(struct hdspm *hdspm) wanted = HDSPM_DMA_AREA_BYTES; - err = - snd_pcm_lib_preallocate_pages_for_all(pcm, - SNDRV_DMA_TYPE_DEV_SG, - snd_dma_pci_data(hdspm->pci), - wanted, - wanted); - if (err < 0) { - dev_dbg(hdspm->card->dev, - "Could not preallocate %zd Bytes\n", wanted); - - return err; - } else - dev_dbg(hdspm->card->dev, - " Preallocated %zd Bytes\n", wanted); - + snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG, + &hdspm->pci->dev, + wanted, wanted); + dev_dbg(hdspm->card->dev, " Preallocated %zd Bytes\n", wanted); return 0; } - -static void hdspm_set_sgbuf(struct hdspm *hdspm, - struct snd_pcm_substream *substream, - unsigned int reg, int channels) +/* Inform the card what DMA addresses to use for the indicated channel. */ +/* Each channel got 16 4K pages allocated for DMA transfers. */ +static void hdspm_set_channel_dma_addr(struct hdspm *hdspm, + struct snd_pcm_substream *substream, + unsigned int reg, int channel) { int i; - /* continuous memory segment */ - for (i = 0; i < (channels * 16); i++) + for (i = channel * 16; i < channel * 16 + 16; i++) hdspm_write(hdspm, reg + 4 * i, - snd_pcm_sgbuf_get_addr(substream, 4096 * i)); + snd_pcm_sgbuf_get_addr(substream, 4096 * i)); } @@ -6464,7 +6365,7 @@ static int snd_hdspm_create_pcm(struct snd_card *card, hdspm->pcm = pcm; pcm->private_data = hdspm; - strcpy(pcm->name, hdspm->card_name); + strscpy(pcm->name, hdspm->card_name); snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_hdspm_ops); @@ -6559,12 +6460,13 @@ static int snd_hdspm_create(struct snd_card *card, hdspm->card = card; spin_lock_init(&hdspm->lock); + INIT_WORK(&hdspm->midi_work, hdspm_midi_work); pci_read_config_word(hdspm->pci, PCI_CLASS_REVISION, &hdspm->firmware_rev); - strcpy(card->mixername, "Xilinx FPGA"); - strcpy(card->driver, "HDSPM"); + strscpy(card->mixername, "Xilinx FPGA"); + strscpy(card->driver, "HDSPM"); switch (hdspm->firmware_rev) { case HDSPM_RAYDAT_REV: @@ -6603,34 +6505,24 @@ static int snd_hdspm_create(struct snd_card *card, } } - err = pci_enable_device(pci); + err = pcim_enable_device(pci); if (err < 0) return err; pci_set_master(hdspm->pci); - err = pci_request_regions(pci, "hdspm"); - if (err < 0) - return err; + hdspm->iobase = pcim_iomap_region(pci, 0, "hdspm"); + if (IS_ERR(hdspm->iobase)) + return PTR_ERR(hdspm->iobase); hdspm->port = pci_resource_start(pci, 0); io_extent = pci_resource_len(pci, 0); - - dev_dbg(card->dev, "grabbed memory region 0x%lx-0x%lx\n", - hdspm->port, hdspm->port + io_extent - 1); - - hdspm->iobase = ioremap_nocache(hdspm->port, io_extent); - if (!hdspm->iobase) { - dev_err(card->dev, "unable to remap region 0x%lx-0x%lx\n", - hdspm->port, hdspm->port + io_extent - 1); - return -EBUSY; - } dev_dbg(card->dev, "remapped region (0x%lx) 0x%lx-0x%lx\n", (unsigned long)hdspm->iobase, hdspm->port, hdspm->port + io_extent - 1); - if (request_irq(pci->irq, snd_hdspm_interrupt, - IRQF_SHARED, KBUILD_MODNAME, hdspm)) { + if (devm_request_irq(&pci->dev, pci->irq, snd_hdspm_interrupt, + IRQF_SHARED, KBUILD_MODNAME, hdspm)) { dev_err(card->dev, "unable to use IRQ %d\n", pci->irq); return -EBUSY; } @@ -6638,10 +6530,11 @@ static int snd_hdspm_create(struct snd_card *card, dev_dbg(card->dev, "use IRQ %d\n", pci->irq); hdspm->irq = pci->irq; + card->sync_irq = hdspm->irq; dev_dbg(card->dev, "kmalloc Mixer memory of %zd Bytes\n", sizeof(*hdspm->mixer)); - hdspm->mixer = kzalloc(sizeof(*hdspm->mixer), GFP_KERNEL); + hdspm->mixer = devm_kzalloc(&pci->dev, sizeof(*hdspm->mixer), GFP_KERNEL); if (!hdspm->mixer) return -ENOMEM; @@ -6856,10 +6749,6 @@ static int snd_hdspm_create(struct snd_card *card, } - tasklet_init(&hdspm->midi_tasklet, - hdspm_midi_tasklet, (unsigned long) hdspm); - - if (hdspm->io_type != MADIface) { hdspm->serial = (hdspm_read(hdspm, HDSPM_midiStatusIn0)>>8) & 0xFFFFFF; @@ -6890,10 +6779,12 @@ static int snd_hdspm_create(struct snd_card *card, } -static int snd_hdspm_free(struct hdspm * hdspm) +static void snd_hdspm_card_free(struct snd_card *card) { + struct hdspm *hdspm = card->private_data; if (hdspm->port) { + cancel_work_sync(&hdspm->midi_work); /* stop th audio, and cancel all interrupts */ hdspm->control_register &= @@ -6903,27 +6794,6 @@ static int snd_hdspm_free(struct hdspm * hdspm) hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); } - - if (hdspm->irq >= 0) - free_irq(hdspm->irq, (void *) hdspm); - - kfree(hdspm->mixer); - iounmap(hdspm->iobase); - - if (hdspm->port) - pci_release_regions(hdspm->pci); - - pci_disable_device(hdspm->pci); - return 0; -} - - -static void snd_hdspm_card_free(struct snd_card *card) -{ - struct hdspm *hdspm = card->private_data; - - if (hdspm) - snd_hdspm_free(hdspm); } @@ -6942,8 +6812,8 @@ static int snd_hdspm_probe(struct pci_dev *pci, return -ENOENT; } - err = snd_card_new(&pci->dev, index[dev], id[dev], - THIS_MODULE, sizeof(*hdspm), &card); + err = snd_devm_card_new(&pci->dev, index[dev], id[dev], + THIS_MODULE, sizeof(*hdspm), &card); if (err < 0) return err; @@ -6954,7 +6824,7 @@ static int snd_hdspm_probe(struct pci_dev *pci, err = snd_hdspm_create(card, hdspm); if (err < 0) - goto free_card; + goto error; if (hdspm->io_type != MADIface) { snprintf(card->shortname, sizeof(card->shortname), "%s_%x", @@ -6973,28 +6843,22 @@ static int snd_hdspm_probe(struct pci_dev *pci, err = snd_card_register(card); if (err < 0) - goto free_card; + goto error; pci_set_drvdata(pci, card); dev++; return 0; -free_card: + error: snd_card_free(card); return err; } -static void snd_hdspm_remove(struct pci_dev *pci) -{ - snd_card_free(pci_get_drvdata(pci)); -} - static struct pci_driver hdspm_driver = { .name = KBUILD_MODNAME, .id_table = snd_hdspm_ids, .probe = snd_hdspm_probe, - .remove = snd_hdspm_remove, }; module_pci_driver(hdspm_driver); |
