Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*****************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (C) 2008 Cedric Bregardis <cedric.bregardis@free.fr> and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Jean-Christian Hassler <jhassler@free.fr>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * This file is part of the Audiowerk2 ALSA driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *****************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/dma-mapping.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/slab.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/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <sound/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <sound/initval.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <sound/pcm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <sound/pcm_params.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <sound/control.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include "saa7146.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include "aw2-saa7146.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) MODULE_AUTHOR("Cedric Bregardis <cedric.bregardis@free.fr>, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	      "Jean-Christian Hassler <jhassler@free.fr>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) MODULE_DESCRIPTION("Emagic Audiowerk 2 sound driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) /*********************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  * DEFINES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  ********************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #define CTL_ROUTE_ANALOG 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #define CTL_ROUTE_DIGITAL 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) /*********************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  * TYPEDEFS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  ********************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)   /* hardware definition */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) static const struct snd_pcm_hardware snd_aw2_playback_hw = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	.info = (SNDRV_PCM_INFO_MMAP |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		 SNDRV_PCM_INFO_INTERLEAVED |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		 SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_MMAP_VALID),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	.formats = SNDRV_PCM_FMTBIT_S16_LE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	.rates = SNDRV_PCM_RATE_44100,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	.rate_min = 44100,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	.rate_max = 44100,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	.channels_min = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	.channels_max = 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	.buffer_bytes_max = 32768,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	.period_bytes_min = 4096,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	.period_bytes_max = 32768,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	.periods_min = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	.periods_max = 1024,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) static const struct snd_pcm_hardware snd_aw2_capture_hw = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	.info = (SNDRV_PCM_INFO_MMAP |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		 SNDRV_PCM_INFO_INTERLEAVED |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		 SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_MMAP_VALID),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	.formats = SNDRV_PCM_FMTBIT_S16_LE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	.rates = SNDRV_PCM_RATE_44100,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	.rate_min = 44100,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	.rate_max = 44100,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	.channels_min = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	.channels_max = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	.buffer_bytes_max = 32768,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	.period_bytes_min = 4096,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	.period_bytes_max = 32768,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	.periods_min = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	.periods_max = 1024,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) struct aw2_pcm_device {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	struct snd_pcm *pcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	unsigned int stream_number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	struct aw2 *chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) struct aw2 {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	struct snd_aw2_saa7146 saa7146;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	struct pci_dev *pci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	int irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	spinlock_t reg_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	struct mutex mtx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	unsigned long iobase_phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	void __iomem *iobase_virt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	struct snd_card *card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	struct aw2_pcm_device device_playback[NB_STREAM_PLAYBACK];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	struct aw2_pcm_device device_capture[NB_STREAM_CAPTURE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) /*********************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)  * FUNCTION DECLARATIONS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)  ********************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) static int snd_aw2_dev_free(struct snd_device *device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) static int snd_aw2_create(struct snd_card *card,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 			  struct pci_dev *pci, struct aw2 **rchip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) static int snd_aw2_probe(struct pci_dev *pci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 			 const struct pci_device_id *pci_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) static void snd_aw2_remove(struct pci_dev *pci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) static int snd_aw2_pcm_playback_open(struct snd_pcm_substream *substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) static int snd_aw2_pcm_playback_close(struct snd_pcm_substream *substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) static int snd_aw2_pcm_capture_open(struct snd_pcm_substream *substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) static int snd_aw2_pcm_capture_close(struct snd_pcm_substream *substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) static int snd_aw2_pcm_prepare_playback(struct snd_pcm_substream *substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static int snd_aw2_pcm_prepare_capture(struct snd_pcm_substream *substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) static int snd_aw2_pcm_trigger_playback(struct snd_pcm_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 					int cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) static int snd_aw2_pcm_trigger_capture(struct snd_pcm_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 				       int cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) static snd_pcm_uframes_t snd_aw2_pcm_pointer_playback(struct snd_pcm_substream
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 						      *substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) static snd_pcm_uframes_t snd_aw2_pcm_pointer_capture(struct snd_pcm_substream
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 						     *substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) static int snd_aw2_new_pcm(struct aw2 *chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) static int snd_aw2_control_switch_capture_info(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 					       struct snd_ctl_elem_info *uinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) static int snd_aw2_control_switch_capture_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 					      struct snd_ctl_elem_value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 					      *ucontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) static int snd_aw2_control_switch_capture_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 					      struct snd_ctl_elem_value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 					      *ucontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) /*********************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)  * VARIABLES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)  ********************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) module_param_array(index, int, NULL, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) MODULE_PARM_DESC(index, "Index value for Audiowerk2 soundcard.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) module_param_array(id, charp, NULL, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) MODULE_PARM_DESC(id, "ID string for the Audiowerk2 soundcard.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) module_param_array(enable, bool, NULL, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) MODULE_PARM_DESC(enable, "Enable Audiowerk2 soundcard.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) static const struct pci_device_id snd_aw2_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	{PCI_VENDOR_ID_PHILIPS, PCI_DEVICE_ID_PHILIPS_SAA7146, 0, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	 0, 0, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	{0}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) MODULE_DEVICE_TABLE(pci, snd_aw2_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) /* pci_driver definition */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) static struct pci_driver aw2_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	.name = KBUILD_MODNAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	.id_table = snd_aw2_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	.probe = snd_aw2_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	.remove = snd_aw2_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) module_pci_driver(aw2_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) /* operators for playback PCM alsa interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) static const struct snd_pcm_ops snd_aw2_playback_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	.open = snd_aw2_pcm_playback_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	.close = snd_aw2_pcm_playback_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	.prepare = snd_aw2_pcm_prepare_playback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	.trigger = snd_aw2_pcm_trigger_playback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	.pointer = snd_aw2_pcm_pointer_playback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) /* operators for capture PCM alsa interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) static const struct snd_pcm_ops snd_aw2_capture_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	.open = snd_aw2_pcm_capture_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	.close = snd_aw2_pcm_capture_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	.prepare = snd_aw2_pcm_prepare_capture,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	.trigger = snd_aw2_pcm_trigger_capture,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	.pointer = snd_aw2_pcm_pointer_capture,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) static const struct snd_kcontrol_new aw2_control = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	.name = "PCM Capture Route",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	.index = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	.private_value = 0xffff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	.info = snd_aw2_control_switch_capture_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	.get = snd_aw2_control_switch_capture_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	.put = snd_aw2_control_switch_capture_put
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) /*********************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)  * FUNCTION IMPLEMENTATIONS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)  ********************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) /* component-destructor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) static int snd_aw2_dev_free(struct snd_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	struct aw2 *chip = device->device_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	/* Free hardware */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	snd_aw2_saa7146_free(&chip->saa7146);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	/* release the irq */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	if (chip->irq >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		free_irq(chip->irq, (void *)chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	/* release the i/o ports & memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	iounmap(chip->iobase_virt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	pci_release_regions(chip->pci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	/* disable the PCI entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	pci_disable_device(chip->pci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	/* release the data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	kfree(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) /* chip-specific constructor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) static int snd_aw2_create(struct snd_card *card,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 			  struct pci_dev *pci, struct aw2 **rchip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	struct aw2 *chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	static const struct snd_device_ops ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		.dev_free = snd_aw2_dev_free,
^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) 	*rchip = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	/* initialize the PCI entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	err = pci_enable_device(pci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	pci_set_master(pci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	/* check PCI availability (32bit DMA) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	if ((dma_set_mask(&pci->dev, DMA_BIT_MASK(32)) < 0) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	    (dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(32)) < 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		dev_err(card->dev, "Impossible to set 32bit mask DMA\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		pci_disable_device(pci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	chip = kzalloc(sizeof(*chip), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	if (chip == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		pci_disable_device(pci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	/* initialize the stuff */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	chip->card = card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	chip->pci = pci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	chip->irq = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	/* (1) PCI resource allocation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	err = pci_request_regions(pci, "Audiowerk2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		pci_disable_device(pci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		kfree(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	chip->iobase_phys = pci_resource_start(pci, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	chip->iobase_virt =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		ioremap(chip->iobase_phys,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 				pci_resource_len(pci, 0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	if (chip->iobase_virt == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		dev_err(card->dev, "unable to remap memory region");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		pci_release_regions(pci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		pci_disable_device(pci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		kfree(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	/* (2) initialization of the chip hardware */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	snd_aw2_saa7146_setup(&chip->saa7146, chip->iobase_virt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	if (request_irq(pci->irq, snd_aw2_saa7146_interrupt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 			IRQF_SHARED, KBUILD_MODNAME, chip)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		dev_err(card->dev, "Cannot grab irq %d\n", pci->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		iounmap(chip->iobase_virt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		pci_release_regions(chip->pci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		pci_disable_device(chip->pci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		kfree(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	chip->irq = pci->irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	card->sync_irq = chip->irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		free_irq(chip->irq, (void *)chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		iounmap(chip->iobase_virt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		pci_release_regions(chip->pci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		pci_disable_device(chip->pci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		kfree(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	*rchip = chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	dev_info(card->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		 "Audiowerk 2 sound card (saa7146 chipset) detected and managed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) /* constructor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) static int snd_aw2_probe(struct pci_dev *pci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 			 const struct pci_device_id *pci_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	static int dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	struct snd_card *card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	struct aw2 *chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	/* (1) Continue if device is not enabled, else inc dev */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	if (dev >= SNDRV_CARDS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	if (!enable[dev]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 		dev++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	/* (2) Create card instance */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 			   0, &card);
^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) 	/* (3) Create main component */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	err = snd_aw2_create(card, pci, &chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 		snd_card_free(card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	/* initialize mutex */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	mutex_init(&chip->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	/* init spinlock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	spin_lock_init(&chip->reg_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	/* (4) Define driver ID and name string */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	strcpy(card->driver, "aw2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	strcpy(card->shortname, "Audiowerk2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	sprintf(card->longname, "%s with SAA7146 irq %i",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 		card->shortname, chip->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	/* (5) Create other components */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	snd_aw2_new_pcm(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	/* (6) Register card instance */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	err = snd_card_register(card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		snd_card_free(card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	/* (7) Set PCI driver data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	pci_set_drvdata(pci, card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	dev++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) /* destructor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) static void snd_aw2_remove(struct pci_dev *pci)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	snd_card_free(pci_get_drvdata(pci));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) /* open callback */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) static int snd_aw2_pcm_playback_open(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	dev_dbg(substream->pcm->card->dev, "Playback_open\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	runtime->hw = snd_aw2_playback_hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	return 0;
^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) /* close callback */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) static int snd_aw2_pcm_playback_close(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 
^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) static int snd_aw2_pcm_capture_open(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	dev_dbg(substream->pcm->card->dev, "Capture_open\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	runtime->hw = snd_aw2_capture_hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) /* close callback */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) static int snd_aw2_pcm_capture_close(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	/* TODO: something to do ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) /* prepare callback for playback */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) static int snd_aw2_pcm_prepare_playback(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	struct aw2_pcm_device *pcm_device = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	struct aw2 *chip = pcm_device->chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	unsigned long period_size, buffer_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	mutex_lock(&chip->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	period_size = snd_pcm_lib_period_bytes(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	buffer_size = snd_pcm_lib_buffer_bytes(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	snd_aw2_saa7146_pcm_init_playback(&chip->saa7146,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 					  pcm_device->stream_number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 					  runtime->dma_addr, period_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 					  buffer_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	/* Define Interrupt callback */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	snd_aw2_saa7146_define_it_playback_callback(pcm_device->stream_number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 						    (snd_aw2_saa7146_it_cb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 						    snd_pcm_period_elapsed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 						    (void *)substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	mutex_unlock(&chip->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) /* prepare callback for capture */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) static int snd_aw2_pcm_prepare_capture(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	struct aw2_pcm_device *pcm_device = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	struct aw2 *chip = pcm_device->chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	unsigned long period_size, buffer_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	mutex_lock(&chip->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	period_size = snd_pcm_lib_period_bytes(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	buffer_size = snd_pcm_lib_buffer_bytes(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	snd_aw2_saa7146_pcm_init_capture(&chip->saa7146,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 					 pcm_device->stream_number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 					 runtime->dma_addr, period_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 					 buffer_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	/* Define Interrupt callback */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	snd_aw2_saa7146_define_it_capture_callback(pcm_device->stream_number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 						   (snd_aw2_saa7146_it_cb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 						   snd_pcm_period_elapsed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 						   (void *)substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	mutex_unlock(&chip->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) /* playback trigger callback */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) static int snd_aw2_pcm_trigger_playback(struct snd_pcm_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 					int cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	int status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	struct aw2_pcm_device *pcm_device = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	struct aw2 *chip = pcm_device->chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	spin_lock(&chip->reg_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	case SNDRV_PCM_TRIGGER_START:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 		snd_aw2_saa7146_pcm_trigger_start_playback(&chip->saa7146,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 							   pcm_device->
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 							   stream_number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	case SNDRV_PCM_TRIGGER_STOP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 		snd_aw2_saa7146_pcm_trigger_stop_playback(&chip->saa7146,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 							  pcm_device->
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 							  stream_number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 		status = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	spin_unlock(&chip->reg_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) /* capture trigger callback */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) static int snd_aw2_pcm_trigger_capture(struct snd_pcm_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 				       int cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	int status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 	struct aw2_pcm_device *pcm_device = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 	struct aw2 *chip = pcm_device->chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 	spin_lock(&chip->reg_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 	case SNDRV_PCM_TRIGGER_START:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 		snd_aw2_saa7146_pcm_trigger_start_capture(&chip->saa7146,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 							  pcm_device->
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 							  stream_number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	case SNDRV_PCM_TRIGGER_STOP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 		snd_aw2_saa7146_pcm_trigger_stop_capture(&chip->saa7146,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 							 pcm_device->
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 							 stream_number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 		status = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 	spin_unlock(&chip->reg_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) /* playback pointer callback */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) static snd_pcm_uframes_t snd_aw2_pcm_pointer_playback(struct snd_pcm_substream
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 						      *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 	struct aw2_pcm_device *pcm_device = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 	struct aw2 *chip = pcm_device->chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 	unsigned int current_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	/* get the current hardware pointer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 	current_ptr =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 		snd_aw2_saa7146_get_hw_ptr_playback(&chip->saa7146,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 						    pcm_device->stream_number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 						    runtime->dma_area,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 						    runtime->buffer_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 	return bytes_to_frames(substream->runtime, current_ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) /* capture pointer callback */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) static snd_pcm_uframes_t snd_aw2_pcm_pointer_capture(struct snd_pcm_substream
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 						     *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 	struct aw2_pcm_device *pcm_device = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 	struct aw2 *chip = pcm_device->chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 	unsigned int current_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 	/* get the current hardware pointer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 	struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 	current_ptr =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 		snd_aw2_saa7146_get_hw_ptr_capture(&chip->saa7146,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 						   pcm_device->stream_number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 						   runtime->dma_area,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 						   runtime->buffer_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 	return bytes_to_frames(substream->runtime, current_ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) /* create a pcm device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) static int snd_aw2_new_pcm(struct aw2 *chip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 	struct snd_pcm *pcm_playback_ana;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 	struct snd_pcm *pcm_playback_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 	struct snd_pcm *pcm_capture;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 	struct aw2_pcm_device *pcm_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 	/* Create new Alsa PCM device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 	err = snd_pcm_new(chip->card, "Audiowerk2 analog playback", 0, 1, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 			  &pcm_playback_ana);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 		dev_err(chip->card->dev, "snd_pcm_new error (0x%X)\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 	/* Creation ok */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 	pcm_device = &chip->device_playback[NUM_STREAM_PLAYBACK_ANA];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 	/* Set PCM device name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 	strcpy(pcm_playback_ana->name, "Analog playback");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 	/* Associate private data to PCM device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 	pcm_playback_ana->private_data = pcm_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 	/* set operators of PCM device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 	snd_pcm_set_ops(pcm_playback_ana, SNDRV_PCM_STREAM_PLAYBACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 			&snd_aw2_playback_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 	/* store PCM device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 	pcm_device->pcm = pcm_playback_ana;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 	/* give base chip pointer to our internal pcm device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 	   structure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 	pcm_device->chip = chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 	/* Give stream number to PCM device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 	pcm_device->stream_number = NUM_STREAM_PLAYBACK_ANA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 	/* pre-allocation of buffers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 	/* Preallocate continuous pages. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 	snd_pcm_set_managed_buffer_all(pcm_playback_ana,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 				       SNDRV_DMA_TYPE_DEV,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 				       &chip->pci->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 				       64 * 1024, 64 * 1024);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 	err = snd_pcm_new(chip->card, "Audiowerk2 digital playback", 1, 1, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 			  &pcm_playback_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 		dev_err(chip->card->dev, "snd_pcm_new error (0x%X)\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 	/* Creation ok */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 	pcm_device = &chip->device_playback[NUM_STREAM_PLAYBACK_DIG];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 	/* Set PCM device name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 	strcpy(pcm_playback_num->name, "Digital playback");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 	/* Associate private data to PCM device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 	pcm_playback_num->private_data = pcm_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 	/* set operators of PCM device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 	snd_pcm_set_ops(pcm_playback_num, SNDRV_PCM_STREAM_PLAYBACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 			&snd_aw2_playback_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 	/* store PCM device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 	pcm_device->pcm = pcm_playback_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 	/* give base chip pointer to our internal pcm device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 	   structure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 	pcm_device->chip = chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 	/* Give stream number to PCM device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 	pcm_device->stream_number = NUM_STREAM_PLAYBACK_DIG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 	/* pre-allocation of buffers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 	/* Preallocate continuous pages. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 	snd_pcm_set_managed_buffer_all(pcm_playback_num,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 				       SNDRV_DMA_TYPE_DEV,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 				       &chip->pci->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 				       64 * 1024, 64 * 1024);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 	err = snd_pcm_new(chip->card, "Audiowerk2 capture", 2, 0, 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 			  &pcm_capture);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 		dev_err(chip->card->dev, "snd_pcm_new error (0x%X)\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 	/* Creation ok */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 	pcm_device = &chip->device_capture[NUM_STREAM_CAPTURE_ANA];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 	/* Set PCM device name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 	strcpy(pcm_capture->name, "Capture");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 	/* Associate private data to PCM device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 	pcm_capture->private_data = pcm_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 	/* set operators of PCM device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 	snd_pcm_set_ops(pcm_capture, SNDRV_PCM_STREAM_CAPTURE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 			&snd_aw2_capture_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 	/* store PCM device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 	pcm_device->pcm = pcm_capture;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 	/* give base chip pointer to our internal pcm device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 	   structure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 	pcm_device->chip = chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 	/* Give stream number to PCM device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 	pcm_device->stream_number = NUM_STREAM_CAPTURE_ANA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 	/* pre-allocation of buffers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 	/* Preallocate continuous pages. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 	snd_pcm_set_managed_buffer_all(pcm_capture,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 				       SNDRV_DMA_TYPE_DEV,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 				       &chip->pci->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 				       64 * 1024, 64 * 1024);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 	/* Create control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 	err = snd_ctl_add(chip->card, snd_ctl_new1(&aw2_control, chip));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 		dev_err(chip->card->dev, "snd_ctl_add error (0x%X)\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) static int snd_aw2_control_switch_capture_info(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 					       struct snd_ctl_elem_info *uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 	static const char * const texts[2] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 		"Analog", "Digital"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 	return snd_ctl_enum_info(uinfo, 1, 2, texts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) static int snd_aw2_control_switch_capture_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 					      struct snd_ctl_elem_value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 					      *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 	struct aw2 *chip = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 	if (snd_aw2_saa7146_is_using_digital_input(&chip->saa7146))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 		ucontrol->value.enumerated.item[0] = CTL_ROUTE_DIGITAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 		ucontrol->value.enumerated.item[0] = CTL_ROUTE_ANALOG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) static int snd_aw2_control_switch_capture_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 					      struct snd_ctl_elem_value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 					      *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) 	struct aw2 *chip = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) 	int changed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 	int is_disgital =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) 	    snd_aw2_saa7146_is_using_digital_input(&chip->saa7146);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) 	if (((ucontrol->value.integer.value[0] == CTL_ROUTE_DIGITAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 	     && !is_disgital)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) 	    || ((ucontrol->value.integer.value[0] == CTL_ROUTE_ANALOG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) 		&& is_disgital)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) 		snd_aw2_saa7146_use_digital_input(&chip->saa7146, !is_disgital);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 		changed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) 	return changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) }