linux/sound/pci/rme9652/rme9652.c

// SPDX-License-Identifier: GPL-2.0-or-later
/*
 *   ALSA driver for RME Digi9652 audio interfaces 
 *
 *	Copyright (c) 1999 IEM - Winfried Ritsch
 *      Copyright (c) 1999-2001  Paul Davis
 */

#include <linux/delay.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/pci.h>
#include <linux/module.h>
#include <linux/io.h>
#include <linux/nospec.h>

#include <sound/core.h>
#include <sound/control.h>
#include <sound/pcm.h>
#include <sound/info.h>
#include <sound/asoundef.h>
#include <sound/initval.h>

#include <asm/current.h>

static int index[SNDRV_CARDS] =;	/* Index 0-MAX */
static char *id[SNDRV_CARDS] =;	/* ID for this card */
static bool enable[SNDRV_CARDS] =;	/* Enable this card */
static bool precise_ptr[SNDRV_CARDS];			/* Enable precise pointer */

module_param_array();
MODULE_PARM_DESC();
module_param_array();
MODULE_PARM_DESC();
module_param_array();
MODULE_PARM_DESC();
module_param_array();
MODULE_PARM_DESC();
MODULE_AUTHOR();
MODULE_DESCRIPTION();
MODULE_LICENSE();

/* The Hammerfall has two sets of 24 ADAT + 2 S/PDIF channels, one for
   capture, one for playback. Both the ADAT and S/PDIF channels appear
   to the host CPU in the same block of memory. There is no functional
   difference between them in terms of access.
   
   The Hammerfall Light is identical to the Hammerfall, except that it
   has 2 sets 18 channels (16 ADAT + 2 S/PDIF) for capture and playback.
*/

#define RME9652_NCHANNELS
#define RME9636_NCHANNELS

/* Preferred sync source choices - used by "sync_pref" control switch */

#define RME9652_SYNC_FROM_SPDIF
#define RME9652_SYNC_FROM_ADAT1
#define RME9652_SYNC_FROM_ADAT2
#define RME9652_SYNC_FROM_ADAT3

/* Possible sources of S/PDIF input */

#define RME9652_SPDIFIN_OPTICAL
#define RME9652_SPDIFIN_COAXIAL
#define RME9652_SPDIFIN_INTERN

/* ------------- Status-Register bits --------------------- */

#define RME9652_IRQ
#define RME9652_lock_2
#define RME9652_lock_1
#define RME9652_lock_0
#define RME9652_fs48
#define RME9652_wsel_rd
                                        /* bits 6-15 encode h/w buffer pointer position */
#define RME9652_sync_2
#define RME9652_sync_1
#define RME9652_sync_0
#define RME9652_DS_rd
#define RME9652_tc_busy
#define RME9652_tc_out
#define RME9652_F_0
#define RME9652_F_1
#define RME9652_F_2
#define RME9652_ERF
#define RME9652_buffer_id
#define RME9652_tc_valid
#define RME9652_SPDIF_READ

#define RME9652_sync
#define RME9652_lock
#define RME9652_F
#define rme9652_decode_spdif_rate(x)

/* Bit 6..15 : h/w buffer pointer */

#define RME9652_buf_pos

/* Bits 31,30,29 are bits 5,4,3 of h/w pointer position on later
   Rev G EEPROMS and Rev 1.5 cards or later.
*/ 

#define RME9652_REV15_buf_pos(x)

/* amount of io space we remap for register access. i'm not sure we
   even need this much, but 1K is nice round number :)
*/

#define RME9652_IO_EXTENT

#define RME9652_init_buffer
#define RME9652_play_buffer
#define RME9652_rec_buffer
#define RME9652_control_register
#define RME9652_irq_clear
#define RME9652_time_code
#define RME9652_thru_base

/* Read-only registers */

/* Writing to any of the register locations writes to the status
   register. We'll use the first location as our point of access.
*/

#define RME9652_status_register

/* --------- Control-Register Bits ---------------- */


#define RME9652_start_bit
                                                /* bits 1-3 encode buffersize/latency */
#define RME9652_Master
#define RME9652_IE
#define RME9652_freq
#define RME9652_freq1
#define RME9652_DS
#define RME9652_PRO
#define RME9652_EMP
#define RME9652_Dolby
#define RME9652_opt_out
#define RME9652_wsel
#define RME9652_inp_0
#define RME9652_inp_1
#define RME9652_SyncPref_ADAT2
#define RME9652_SyncPref_ADAT3
#define RME9652_SPDIF_RESET
#define RME9652_SPDIF_SELECT
#define RME9652_SPDIF_CLOCK
#define RME9652_SPDIF_WRITE
#define RME9652_ADAT1_INTERNAL

/* buffersize = 512Bytes * 2^n, where n is made from Bit2 ... Bit0 */

#define RME9652_latency
#define rme9652_encode_latency(x)
#define rme9652_decode_latency(x)
#define rme9652_running_double_speed(s)
#define RME9652_inp
#define rme9652_encode_spdif_in(x)
#define rme9652_decode_spdif_in(x)

#define RME9652_SyncPref_Mask
#define RME9652_SyncPref_ADAT1
#define RME9652_SyncPref_SPDIF

/* the size of a substream (1 mono data stream) */

#define RME9652_CHANNEL_BUFFER_SAMPLES
#define RME9652_CHANNEL_BUFFER_BYTES

/* the size of the area we need to allocate for DMA transfers. the
   size is the same regardless of the number of channels - the 
   9636 still uses the same memory area.

   Note that we allocate 1 more channel than is apparently needed
   because the h/w seems to write 1 byte beyond the end of the last
   page. Sigh.
*/

#define RME9652_DMA_AREA_BYTES
#define RME9652_DMA_AREA_KILOBYTES

struct snd_rme9652 {};

/* These tables map the ALSA channels 1..N to the channels that we
   need to use in order to find the relevant channel buffer. RME
   refer to this kind of mapping as between "the ADAT channel and
   the DMA channel." We index it using the logical audio channel,
   and the value is the DMA channel (i.e. channel buffer number)
   where the data for that channel can be read/written from/to.
*/

static const signed char channel_map_9652_ss[26] =;

static const signed char channel_map_9636_ss[26] =;

static const signed char channel_map_9652_ds[26] =;

static const signed char channel_map_9636_ds[26] =;

static struct snd_dma_buffer *
snd_hammerfall_get_buffer(struct pci_dev *pci, size_t size)
{}

static const struct pci_device_id snd_rme9652_ids[] =;

MODULE_DEVICE_TABLE(pci, snd_rme9652_ids);

static inline void rme9652_write(struct snd_rme9652 *rme9652, int reg, int val)
{}

static inline unsigned int rme9652_read(struct snd_rme9652 *rme9652, int reg)
{}

static inline int snd_rme9652_use_is_exclusive(struct snd_rme9652 *rme9652)
{}

static inline int rme9652_adat_sample_rate(struct snd_rme9652 *rme9652)
{}

static inline void rme9652_compute_period_size(struct snd_rme9652 *rme9652)
{}

static snd_pcm_uframes_t rme9652_hw_pointer(struct snd_rme9652 *rme9652)
{}

static inline void rme9652_reset_hw_pointer(struct snd_rme9652 *rme9652)
{}

static inline void rme9652_start(struct snd_rme9652 *s)
{}

static inline void rme9652_stop(struct snd_rme9652 *s)
{}

static int rme9652_set_interrupt_interval(struct snd_rme9652 *s,
					  unsigned int frames)
{}

static int rme9652_set_rate(struct snd_rme9652 *rme9652, int rate)
{}

static void rme9652_set_thru(struct snd_rme9652 *rme9652, int channel, int enable)
{}

static int rme9652_set_passthru(struct snd_rme9652 *rme9652, int onoff)
{}

static void rme9652_spdif_set_bit (struct snd_rme9652 *rme9652, int mask, int onoff)
{}

static void rme9652_spdif_write_byte (struct snd_rme9652 *rme9652, const int val)
{}

static int rme9652_spdif_read_byte (struct snd_rme9652 *rme9652)
{}

static void rme9652_write_spdif_codec (struct snd_rme9652 *rme9652, const int address, const int data)
{}


static int rme9652_spdif_read_codec (struct snd_rme9652 *rme9652, const int address)
{}

static void rme9652_initialize_spdif_receiver (struct snd_rme9652 *rme9652)
{}

static inline int rme9652_spdif_sample_rate(struct snd_rme9652 *s)
{}

/*-----------------------------------------------------------------------------
  Control Interface
  ----------------------------------------------------------------------------*/

static u32 snd_rme9652_convert_from_aes(struct snd_aes_iec958 *aes)
{}

static void snd_rme9652_convert_to_aes(struct snd_aes_iec958 *aes, u32 val)
{}

static int snd_rme9652_control_spdif_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
{}

static int snd_rme9652_control_spdif_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
{}

static int snd_rme9652_control_spdif_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
{}

static int snd_rme9652_control_spdif_stream_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
{}

static int snd_rme9652_control_spdif_stream_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
{}

static int snd_rme9652_control_spdif_stream_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
{}

static int snd_rme9652_control_spdif_mask_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
{}

static int snd_rme9652_control_spdif_mask_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
{}

#define RME9652_ADAT1_IN(xname, xindex)

static unsigned int rme9652_adat1_in(struct snd_rme9652 *rme9652)
{}

static int rme9652_set_adat1_input(struct snd_rme9652 *rme9652, int internal)
{}

static int snd_rme9652_info_adat1_in(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
{}

static int snd_rme9652_get_adat1_in(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
{}

static int snd_rme9652_put_adat1_in(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
{}

#define RME9652_SPDIF_IN(xname, xindex)

static unsigned int rme9652_spdif_in(struct snd_rme9652 *rme9652)
{}

static int rme9652_set_spdif_input(struct snd_rme9652 *rme9652, int in)
{}

static int snd_rme9652_info_spdif_in(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
{}

static int snd_rme9652_get_spdif_in(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
{}

static int snd_rme9652_put_spdif_in(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
{}

#define RME9652_SPDIF_OUT(xname, xindex)

static int rme9652_spdif_out(struct snd_rme9652 *rme9652)
{}

static int rme9652_set_spdif_output(struct snd_rme9652 *rme9652, int out)
{}

#define snd_rme9652_info_spdif_out

static int snd_rme9652_get_spdif_out(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
{}

static int snd_rme9652_put_spdif_out(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
{}

#define RME9652_SYNC_MODE(xname, xindex)

static int rme9652_sync_mode(struct snd_rme9652 *rme9652)
{}

static int rme9652_set_sync_mode(struct snd_rme9652 *rme9652, int mode)
{}

static int snd_rme9652_info_sync_mode(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
{}

static int snd_rme9652_get_sync_mode(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
{}

static int snd_rme9652_put_sync_mode(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
{}

#define RME9652_SYNC_PREF(xname, xindex)

static int rme9652_sync_pref(struct snd_rme9652 *rme9652)
{}

static int rme9652_set_sync_pref(struct snd_rme9652 *rme9652, int pref)
{}

static int snd_rme9652_info_sync_pref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
{}

static int snd_rme9652_get_sync_pref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
{}

static int snd_rme9652_put_sync_pref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
{}

static int snd_rme9652_info_thru(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
{}

static int snd_rme9652_get_thru(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
{}

static int snd_rme9652_put_thru(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
{}

#define RME9652_PASSTHRU(xname, xindex)

#define snd_rme9652_info_passthru

static int snd_rme9652_get_passthru(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
{}

static int snd_rme9652_put_passthru(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
{}

/* Read-only switches */

#define RME9652_SPDIF_RATE(xname, xindex)

static int snd_rme9652_info_spdif_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
{}

static int snd_rme9652_get_spdif_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
{}

#define RME9652_ADAT_SYNC(xname, xindex, xidx)

static int snd_rme9652_info_adat_sync(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
{}

static int snd_rme9652_get_adat_sync(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
{}

#define RME9652_TC_VALID(xname, xindex)

#define snd_rme9652_info_tc_valid

static int snd_rme9652_get_tc_valid(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
{}

#ifdef ALSA_HAS_STANDARD_WAY_OF_RETURNING_TIMECODE

/* FIXME: this routine needs a port to the new control API --jk */

static int snd_rme9652_get_tc_value(void *private_data,
				    snd_kswitch_t *kswitch,
				    snd_switch_t *uswitch)
{
	struct snd_rme9652 *s = (struct snd_rme9652 *) private_data;
	u32 value;
	int i;

	uswitch->type = SNDRV_SW_TYPE_DWORD;

	if ((rme9652_read(s, RME9652_status_register) &
	     RME9652_tc_valid) == 0) {
		uswitch->value.data32[0] = 0;
		return 0;
	}

	/* timecode request */

	rme9652_write(s, RME9652_time_code, 0);

	/* XXX bug alert: loop-based timing !!!! */

	for (i = 0; i < 50; i++) {
		if (!(rme9652_read(s, i * 4) & RME9652_tc_busy))
			break;
	}

	if (!(rme9652_read(s, i * 4) & RME9652_tc_busy)) {
		return -EIO;
	}

	value = 0;

	for (i = 0; i < 32; i++) {
		value >>= 1;

		if (rme9652_read(s, i * 4) & RME9652_tc_out)
			value |= 0x80000000;
	}

	if (value > 2 * 60 * 48000) {
		value -= 2 * 60 * 48000;
	} else {
		value = 0;
	}

	uswitch->value.data32[0] = value;

	return 0;
}

#endif				/* ALSA_HAS_STANDARD_WAY_OF_RETURNING_TIMECODE */

static const struct snd_kcontrol_new snd_rme9652_controls[] =;

static const struct snd_kcontrol_new snd_rme9652_adat3_check =;

static const struct snd_kcontrol_new snd_rme9652_adat1_input =;

static int snd_rme9652_create_controls(struct snd_card *card, struct snd_rme9652 *rme9652)
{}

/*------------------------------------------------------------
   /proc interface 
 ------------------------------------------------------------*/

static void
snd_rme9652_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
{}

static void snd_rme9652_proc_init(struct snd_rme9652 *rme9652)
{}

static void snd_rme9652_card_free(struct snd_card *card)
{}

static int snd_rme9652_initialize_memory(struct snd_rme9652 *rme9652)
{}

static void snd_rme9652_set_defaults(struct snd_rme9652 *rme9652)
{}

static irqreturn_t snd_rme9652_interrupt(int irq, void *dev_id)
{}

static snd_pcm_uframes_t snd_rme9652_hw_pointer(struct snd_pcm_substream *substream)
{}

static signed char *rme9652_channel_buffer_location(struct snd_rme9652 *rme9652,
					     int stream,
					     int channel)

{}

static int snd_rme9652_playback_copy(struct snd_pcm_substream *substream,
				     int channel, unsigned long pos,
				     struct iov_iter *src, unsigned long count)
{}

static int snd_rme9652_capture_copy(struct snd_pcm_substream *substream,
				    int channel, unsigned long pos,
				    struct iov_iter *dst, unsigned long count)
{}

static int snd_rme9652_hw_silence(struct snd_pcm_substream *substream,
				  int channel, unsigned long pos,
				  unsigned long count)
{}

static int snd_rme9652_reset(struct snd_pcm_substream *substream)
{}

static int snd_rme9652_hw_params(struct snd_pcm_substream *substream,
				 struct snd_pcm_hw_params *params)
{}

static int snd_rme9652_channel_info(struct snd_pcm_substream *substream,
				    struct snd_pcm_channel_info *info)
{}

static int snd_rme9652_ioctl(struct snd_pcm_substream *substream,
			     unsigned int cmd, void *arg)
{}

static void rme9652_silence_playback(struct snd_rme9652 *rme9652)
{}

static int snd_rme9652_trigger(struct snd_pcm_substream *substream,
			       int cmd)
{}

static int snd_rme9652_prepare(struct snd_pcm_substream *substream)
{}

static const struct snd_pcm_hardware snd_rme9652_playback_subinfo =;

static const struct snd_pcm_hardware snd_rme9652_capture_subinfo =;

static const unsigned int period_sizes[] =;

static const struct snd_pcm_hw_constraint_list hw_constraints_period_sizes =;

static int snd_rme9652_hw_rule_channels(struct snd_pcm_hw_params *params,
					struct snd_pcm_hw_rule *rule)
{}

static int snd_rme9652_hw_rule_channels_rate(struct snd_pcm_hw_params *params,
					     struct snd_pcm_hw_rule *rule)
{}

static int snd_rme9652_hw_rule_rate_channels(struct snd_pcm_hw_params *params,
					     struct snd_pcm_hw_rule *rule)
{}

static int snd_rme9652_playback_open(struct snd_pcm_substream *substream)
{}

static int snd_rme9652_playback_release(struct snd_pcm_substream *substream)
{}


static int snd_rme9652_capture_open(struct snd_pcm_substream *substream)
{}

static int snd_rme9652_capture_release(struct snd_pcm_substream *substream)
{}

static const struct snd_pcm_ops snd_rme9652_playback_ops =;

static const struct snd_pcm_ops snd_rme9652_capture_ops =;

static int snd_rme9652_create_pcm(struct snd_card *card,
				  struct snd_rme9652 *rme9652)
{}

static int snd_rme9652_create(struct snd_card *card,
			      struct snd_rme9652 *rme9652,
			      int precise_ptr)
{}

static int snd_rme9652_probe(struct pci_dev *pci,
			     const struct pci_device_id *pci_id)
{}

static struct pci_driver rme9652_driver =;

module_pci_driver();