Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Support for audio capture |
| 4 | * PCI function #1 of the cx2388x. |
| 5 | * |
Trent Piepho | 05b2723 | 2007-08-24 01:06:34 -0300 | [diff] [blame] | 6 | * (c) 2007 Trent Piepho <xyzzy@speakeasy.org> |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 7 | * (c) 2005,2006 Ricardo Cerqueira <v4l@cerqueira.org> |
Mauro Carvalho Chehab | 2e7c6dc | 2006-04-03 07:53:40 -0300 | [diff] [blame] | 8 | * (c) 2005 Mauro Carvalho Chehab <mchehab@infradead.org> |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 9 | * Based on a dummy cx88 module by Gerd Knorr <kraxel@bytesex.org> |
Jaroslav Kysela | c1017a4 | 2007-10-15 09:50:19 +0200 | [diff] [blame] | 10 | * Based on dummy.c by Jaroslav Kysela <perex@perex.cz> |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License as published by |
| 14 | * the Free Software Foundation; either version 2 of the License, or |
| 15 | * (at your option) any later version. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with this program; if not, write to the Free Software |
| 24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 25 | */ |
| 26 | |
| 27 | #include <linux/module.h> |
| 28 | #include <linux/init.h> |
| 29 | #include <linux/device.h> |
| 30 | #include <linux/interrupt.h> |
Trent Piepho | f6210c9 | 2007-08-24 01:06:36 -0300 | [diff] [blame] | 31 | #include <linux/vmalloc.h> |
Andrew Morton | c24228d | 2007-05-06 14:51:55 -0700 | [diff] [blame] | 32 | #include <linux/dma-mapping.h> |
Trent Piepho | 19453bc | 2007-08-18 22:54:49 -0300 | [diff] [blame] | 33 | #include <linux/pci.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 34 | #include <linux/slab.h> |
Andrew Morton | c24228d | 2007-05-06 14:51:55 -0700 | [diff] [blame] | 35 | |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 36 | #include <asm/delay.h> |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 37 | #include <sound/core.h> |
| 38 | #include <sound/pcm.h> |
| 39 | #include <sound/pcm_params.h> |
| 40 | #include <sound/control.h> |
| 41 | #include <sound/initval.h> |
Trent Piepho | bbaccc0 | 2007-09-06 23:02:25 -0300 | [diff] [blame] | 42 | #include <sound/tlv.h> |
Lawrence Rust | 6951803 | 2011-02-06 17:46:12 -0300 | [diff] [blame] | 43 | #include <media/wm8775.h> |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 44 | |
| 45 | #include "cx88.h" |
| 46 | #include "cx88-reg.h" |
| 47 | |
Mauro Carvalho Chehab | db61371 | 2012-10-27 15:25:02 -0300 | [diff] [blame] | 48 | #define dprintk(level, fmt, arg...) do { \ |
| 49 | if (debug + 1 > level) \ |
| 50 | printk(KERN_INFO "%s/1: " fmt, chip->core->name , ## arg);\ |
| 51 | } while(0) |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 52 | |
Mauro Carvalho Chehab | db61371 | 2012-10-27 15:25:02 -0300 | [diff] [blame] | 53 | #define dprintk_core(level, fmt, arg...) do { \ |
| 54 | if (debug + 1 > level) \ |
| 55 | printk(KERN_DEBUG "%s/1: " fmt, chip->core->name , ## arg);\ |
| 56 | } while(0) |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 57 | |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 58 | /**************************************************************************** |
| 59 | Data type declarations - Can be moded to a header file later |
| 60 | ****************************************************************************/ |
| 61 | |
Laurent Pinchart | fecfede | 2010-05-11 10:36:31 -0300 | [diff] [blame] | 62 | struct cx88_audio_buffer { |
| 63 | unsigned int bpl; |
Hans Verkuil | 5e7045e | 2014-08-29 04:11:54 -0300 | [diff] [blame] | 64 | struct cx88_riscmem risc; |
Hans Verkuil | b2c75ab | 2014-08-29 05:25:30 -0300 | [diff] [blame] | 65 | void *vaddr; |
| 66 | struct scatterlist *sglist; |
| 67 | int sglen; |
| 68 | int nr_pages; |
Laurent Pinchart | fecfede | 2010-05-11 10:36:31 -0300 | [diff] [blame] | 69 | }; |
| 70 | |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 71 | struct cx88_audio_dev { |
| 72 | struct cx88_core *core; |
| 73 | struct cx88_dmaqueue q; |
| 74 | |
| 75 | /* pci i/o */ |
| 76 | struct pci_dev *pci; |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 77 | |
| 78 | /* audio controls */ |
| 79 | int irq; |
| 80 | |
Takashi Iwai | f7cbb7f | 2006-01-13 18:48:06 +0100 | [diff] [blame] | 81 | struct snd_card *card; |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 82 | |
| 83 | spinlock_t reg_lock; |
Trent Piepho | 05b2723 | 2007-08-24 01:06:34 -0300 | [diff] [blame] | 84 | atomic_t count; |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 85 | |
| 86 | unsigned int dma_size; |
| 87 | unsigned int period_size; |
| 88 | unsigned int num_periods; |
| 89 | |
Laurent Pinchart | fecfede | 2010-05-11 10:36:31 -0300 | [diff] [blame] | 90 | struct cx88_audio_buffer *buf; |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 91 | |
Trent Piepho | 05b2723 | 2007-08-24 01:06:34 -0300 | [diff] [blame] | 92 | struct snd_pcm_substream *substream; |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 93 | }; |
| 94 | typedef struct cx88_audio_dev snd_cx88_card_t; |
| 95 | |
| 96 | |
| 97 | |
| 98 | /**************************************************************************** |
| 99 | Module global static vars |
| 100 | ****************************************************************************/ |
| 101 | |
| 102 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ |
lawrence rust | 2e4e98e | 2010-08-25 09:50:20 -0300 | [diff] [blame] | 103 | static const char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ |
Luis de Bethencourt | d275d93 | 2015-09-21 13:00:41 -0300 | [diff] [blame^] | 104 | static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 105 | |
| 106 | module_param_array(enable, bool, NULL, 0444); |
| 107 | MODULE_PARM_DESC(enable, "Enable cx88x soundcard. default enabled."); |
| 108 | |
| 109 | module_param_array(index, int, NULL, 0444); |
| 110 | MODULE_PARM_DESC(index, "Index value for cx88x capture interface(s)."); |
| 111 | |
| 112 | |
| 113 | /**************************************************************************** |
| 114 | Module macros |
| 115 | ****************************************************************************/ |
| 116 | |
| 117 | MODULE_DESCRIPTION("ALSA driver module for cx2388x based TV cards"); |
| 118 | MODULE_AUTHOR("Ricardo Cerqueira"); |
Mauro Carvalho Chehab | 2e7c6dc | 2006-04-03 07:53:40 -0300 | [diff] [blame] | 119 | MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>"); |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 120 | MODULE_LICENSE("GPL"); |
Mauro Carvalho Chehab | 1990d50 | 2011-06-24 14:45:49 -0300 | [diff] [blame] | 121 | MODULE_VERSION(CX88_VERSION); |
| 122 | |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 123 | MODULE_SUPPORTED_DEVICE("{{Conexant,23881}," |
| 124 | "{{Conexant,23882}," |
| 125 | "{{Conexant,23883}"); |
Mauro Carvalho Chehab | a5ed425 | 2006-01-13 14:10:19 -0200 | [diff] [blame] | 126 | static unsigned int debug; |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 127 | module_param(debug,int,0644); |
| 128 | MODULE_PARM_DESC(debug,"enable debug messages"); |
| 129 | |
| 130 | /**************************************************************************** |
| 131 | Module specific funtions |
| 132 | ****************************************************************************/ |
| 133 | |
| 134 | /* |
| 135 | * BOARD Specific: Sets audio DMA |
| 136 | */ |
| 137 | |
Mauro Carvalho Chehab | be8a82d | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 138 | static int _cx88_start_audio_dma(snd_cx88_card_t *chip) |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 139 | { |
Laurent Pinchart | fecfede | 2010-05-11 10:36:31 -0300 | [diff] [blame] | 140 | struct cx88_audio_buffer *buf = chip->buf; |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 141 | struct cx88_core *core=chip->core; |
lawrence rust | 2e4e98e | 2010-08-25 09:50:20 -0300 | [diff] [blame] | 142 | const struct sram_channel *audio_ch = &cx88_sram_channels[SRAM_CH25]; |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 143 | |
Trent Piepho | 59fd8f8 | 2007-08-18 22:09:42 -0300 | [diff] [blame] | 144 | /* Make sure RISC/FIFO are off before changing FIFO/RISC settings */ |
| 145 | cx_clear(MO_AUD_DMACNTRL, 0x11); |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 146 | |
| 147 | /* setup fifo + format - out channel */ |
Trent Piepho | 59fd8f8 | 2007-08-18 22:09:42 -0300 | [diff] [blame] | 148 | cx88_sram_channel_setup(chip->core, audio_ch, buf->bpl, buf->risc.dma); |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 149 | |
| 150 | /* sets bpl size */ |
| 151 | cx_write(MO_AUDD_LNGTH, buf->bpl); |
| 152 | |
| 153 | /* reset counter */ |
Trent Piepho | 05b2723 | 2007-08-24 01:06:34 -0300 | [diff] [blame] | 154 | cx_write(MO_AUDD_GPCNTRL, GP_COUNT_CONTROL_RESET); |
| 155 | atomic_set(&chip->count, 0); |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 156 | |
Trent Piepho | 05b2723 | 2007-08-24 01:06:34 -0300 | [diff] [blame] | 157 | dprintk(1, "Start audio DMA, %d B/line, %d lines/FIFO, %d periods, %d " |
| 158 | "byte buffer\n", buf->bpl, cx_read(audio_ch->cmds_start + 8)>>1, |
Trent Piepho | 59fd8f8 | 2007-08-18 22:09:42 -0300 | [diff] [blame] | 159 | chip->num_periods, buf->bpl * chip->num_periods); |
| 160 | |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 161 | /* Enables corresponding bits at AUD_INT_STAT */ |
Trent Piepho | 59fd8f8 | 2007-08-18 22:09:42 -0300 | [diff] [blame] | 162 | cx_write(MO_AUD_INTMSK, AUD_INT_OPC_ERR | AUD_INT_DN_SYNC | |
| 163 | AUD_INT_DN_RISCI2 | AUD_INT_DN_RISCI1); |
| 164 | |
| 165 | /* Clean any pending interrupt bits already set */ |
| 166 | cx_write(MO_AUD_INTSTAT, ~0); |
| 167 | |
| 168 | /* enable audio irqs */ |
| 169 | cx_set(MO_PCI_INTMSK, chip->core->pci_irqmask | PCI_INT_AUDINT); |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 170 | |
| 171 | /* start dma */ |
| 172 | cx_set(MO_DEV_CNTRL2, (1<<5)); /* Enables Risc Processor */ |
| 173 | cx_set(MO_AUD_DMACNTRL, 0x11); /* audio downstream FIFO and RISC enable */ |
| 174 | |
| 175 | if (debug) |
Trent Piepho | 59fd8f8 | 2007-08-18 22:09:42 -0300 | [diff] [blame] | 176 | cx88_sram_channel_dump(chip->core, audio_ch); |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 177 | |
| 178 | return 0; |
| 179 | } |
| 180 | |
| 181 | /* |
| 182 | * BOARD Specific: Resets audio DMA |
| 183 | */ |
Mauro Carvalho Chehab | be8a82d | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 184 | static int _cx88_stop_audio_dma(snd_cx88_card_t *chip) |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 185 | { |
| 186 | struct cx88_core *core=chip->core; |
| 187 | dprintk(1, "Stopping audio DMA\n"); |
| 188 | |
| 189 | /* stop dma */ |
| 190 | cx_clear(MO_AUD_DMACNTRL, 0x11); |
| 191 | |
| 192 | /* disable irqs */ |
Trent Piepho | 8ddac9e | 2007-08-18 06:57:55 -0300 | [diff] [blame] | 193 | cx_clear(MO_PCI_INTMSK, PCI_INT_AUDINT); |
Trent Piepho | 59fd8f8 | 2007-08-18 22:09:42 -0300 | [diff] [blame] | 194 | cx_clear(MO_AUD_INTMSK, AUD_INT_OPC_ERR | AUD_INT_DN_SYNC | |
| 195 | AUD_INT_DN_RISCI2 | AUD_INT_DN_RISCI1); |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 196 | |
| 197 | if (debug) |
| 198 | cx88_sram_channel_dump(chip->core, &cx88_sram_channels[SRAM_CH25]); |
| 199 | |
| 200 | return 0; |
| 201 | } |
| 202 | |
Trent Piepho | 05b2723 | 2007-08-24 01:06:34 -0300 | [diff] [blame] | 203 | #define MAX_IRQ_LOOP 50 |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 204 | |
| 205 | /* |
| 206 | * BOARD Specific: IRQ dma bits |
| 207 | */ |
lawrence rust | 2e4e98e | 2010-08-25 09:50:20 -0300 | [diff] [blame] | 208 | static const char *cx88_aud_irqs[32] = { |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 209 | "dn_risci1", "up_risci1", "rds_dn_risc1", /* 0-2 */ |
| 210 | NULL, /* reserved */ |
| 211 | "dn_risci2", "up_risci2", "rds_dn_risc2", /* 4-6 */ |
| 212 | NULL, /* reserved */ |
| 213 | "dnf_of", "upf_uf", "rds_dnf_uf", /* 8-10 */ |
| 214 | NULL, /* reserved */ |
| 215 | "dn_sync", "up_sync", "rds_dn_sync", /* 12-14 */ |
| 216 | NULL, /* reserved */ |
| 217 | "opc_err", "par_err", "rip_err", /* 16-18 */ |
| 218 | "pci_abort", "ber_irq", "mchg_irq" /* 19-21 */ |
| 219 | }; |
| 220 | |
| 221 | /* |
| 222 | * BOARD Specific: Threats IRQ audio specific calls |
| 223 | */ |
| 224 | static void cx8801_aud_irq(snd_cx88_card_t *chip) |
| 225 | { |
| 226 | struct cx88_core *core = chip->core; |
| 227 | u32 status, mask; |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 228 | |
| 229 | status = cx_read(MO_AUD_INTSTAT); |
| 230 | mask = cx_read(MO_AUD_INTMSK); |
Trent Piepho | 05b2723 | 2007-08-24 01:06:34 -0300 | [diff] [blame] | 231 | if (0 == (status & mask)) |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 232 | return; |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 233 | cx_write(MO_AUD_INTSTAT, status); |
| 234 | if (debug > 1 || (status & mask & ~0xff)) |
| 235 | cx88_print_irqbits(core->name, "irq aud", |
Mauro Carvalho Chehab | 66623a0 | 2007-03-29 08:47:04 -0300 | [diff] [blame] | 236 | cx88_aud_irqs, ARRAY_SIZE(cx88_aud_irqs), |
| 237 | status, mask); |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 238 | /* risc op code error */ |
Trent Piepho | 59fd8f8 | 2007-08-18 22:09:42 -0300 | [diff] [blame] | 239 | if (status & AUD_INT_OPC_ERR) { |
Trent Piepho | 05b2723 | 2007-08-24 01:06:34 -0300 | [diff] [blame] | 240 | printk(KERN_WARNING "%s/1: Audio risc op code error\n",core->name); |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 241 | cx_clear(MO_AUD_DMACNTRL, 0x11); |
| 242 | cx88_sram_channel_dump(core, &cx88_sram_channels[SRAM_CH25]); |
| 243 | } |
Trent Piepho | 05b2723 | 2007-08-24 01:06:34 -0300 | [diff] [blame] | 244 | if (status & AUD_INT_DN_SYNC) { |
| 245 | dprintk(1, "Downstream sync error\n"); |
| 246 | cx_write(MO_AUDD_GPCNTRL, GP_COUNT_CONTROL_RESET); |
| 247 | return; |
| 248 | } |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 249 | /* risc1 downstream */ |
Trent Piepho | 59fd8f8 | 2007-08-18 22:09:42 -0300 | [diff] [blame] | 250 | if (status & AUD_INT_DN_RISCI1) { |
Trent Piepho | 05b2723 | 2007-08-24 01:06:34 -0300 | [diff] [blame] | 251 | atomic_set(&chip->count, cx_read(MO_AUDD_GPCNT)); |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 252 | snd_pcm_period_elapsed(chip->substream); |
| 253 | } |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 254 | /* FIXME: Any other status should deserve a special handling? */ |
| 255 | } |
| 256 | |
| 257 | /* |
| 258 | * BOARD Specific: Handles IRQ calls |
| 259 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 260 | static irqreturn_t cx8801_irq(int irq, void *dev_id) |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 261 | { |
| 262 | snd_cx88_card_t *chip = dev_id; |
| 263 | struct cx88_core *core = chip->core; |
| 264 | u32 status; |
| 265 | int loop, handled = 0; |
| 266 | |
| 267 | for (loop = 0; loop < MAX_IRQ_LOOP; loop++) { |
Trent Piepho | 8ddac9e | 2007-08-18 06:57:55 -0300 | [diff] [blame] | 268 | status = cx_read(MO_PCI_INTSTAT) & |
| 269 | (core->pci_irqmask | PCI_INT_AUDINT); |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 270 | if (0 == status) |
| 271 | goto out; |
Trent Piepho | 05b2723 | 2007-08-24 01:06:34 -0300 | [diff] [blame] | 272 | dprintk(3, "cx8801_irq loop %d/%d, status %x\n", |
| 273 | loop, MAX_IRQ_LOOP, status); |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 274 | handled = 1; |
| 275 | cx_write(MO_PCI_INTSTAT, status); |
| 276 | |
Trent Piepho | 5ba862b | 2007-08-18 07:02:26 -0300 | [diff] [blame] | 277 | if (status & core->pci_irqmask) |
| 278 | cx88_core_irq(core, status); |
Trent Piepho | 05b2723 | 2007-08-24 01:06:34 -0300 | [diff] [blame] | 279 | if (status & PCI_INT_AUDINT) |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 280 | cx8801_aud_irq(chip); |
Trent Piepho | 05b2723 | 2007-08-24 01:06:34 -0300 | [diff] [blame] | 281 | } |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 282 | |
| 283 | if (MAX_IRQ_LOOP == loop) { |
Trent Piepho | 05b2723 | 2007-08-24 01:06:34 -0300 | [diff] [blame] | 284 | printk(KERN_ERR |
| 285 | "%s/1: IRQ loop detected, disabling interrupts\n", |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 286 | core->name); |
Trent Piepho | 8ddac9e | 2007-08-18 06:57:55 -0300 | [diff] [blame] | 287 | cx_clear(MO_PCI_INTMSK, PCI_INT_AUDINT); |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | out: |
| 291 | return IRQ_RETVAL(handled); |
| 292 | } |
| 293 | |
Hans Verkuil | b2c75ab | 2014-08-29 05:25:30 -0300 | [diff] [blame] | 294 | static int cx88_alsa_dma_init(struct cx88_audio_dev *chip, int nr_pages) |
| 295 | { |
| 296 | struct cx88_audio_buffer *buf = chip->buf; |
| 297 | struct page *pg; |
| 298 | int i; |
| 299 | |
| 300 | buf->vaddr = vmalloc_32(nr_pages << PAGE_SHIFT); |
| 301 | if (NULL == buf->vaddr) { |
| 302 | dprintk(1, "vmalloc_32(%d pages) failed\n", nr_pages); |
| 303 | return -ENOMEM; |
| 304 | } |
| 305 | |
| 306 | dprintk(1, "vmalloc is at addr 0x%08lx, size=%d\n", |
| 307 | (unsigned long)buf->vaddr, |
| 308 | nr_pages << PAGE_SHIFT); |
| 309 | |
| 310 | memset(buf->vaddr, 0, nr_pages << PAGE_SHIFT); |
| 311 | buf->nr_pages = nr_pages; |
| 312 | |
| 313 | buf->sglist = vzalloc(buf->nr_pages * sizeof(*buf->sglist)); |
| 314 | if (NULL == buf->sglist) |
| 315 | goto vzalloc_err; |
| 316 | |
| 317 | sg_init_table(buf->sglist, buf->nr_pages); |
| 318 | for (i = 0; i < buf->nr_pages; i++) { |
| 319 | pg = vmalloc_to_page(buf->vaddr + i * PAGE_SIZE); |
| 320 | if (NULL == pg) |
| 321 | goto vmalloc_to_page_err; |
| 322 | sg_set_page(&buf->sglist[i], pg, PAGE_SIZE, 0); |
| 323 | } |
| 324 | return 0; |
| 325 | |
| 326 | vmalloc_to_page_err: |
| 327 | vfree(buf->sglist); |
| 328 | buf->sglist = NULL; |
| 329 | vzalloc_err: |
| 330 | vfree(buf->vaddr); |
| 331 | buf->vaddr = NULL; |
| 332 | return -ENOMEM; |
| 333 | } |
| 334 | |
| 335 | static int cx88_alsa_dma_map(struct cx88_audio_dev *dev) |
| 336 | { |
| 337 | struct cx88_audio_buffer *buf = dev->buf; |
| 338 | |
| 339 | buf->sglen = dma_map_sg(&dev->pci->dev, buf->sglist, |
| 340 | buf->nr_pages, PCI_DMA_FROMDEVICE); |
| 341 | |
| 342 | if (0 == buf->sglen) { |
| 343 | pr_warn("%s: cx88_alsa_map_sg failed\n", __func__); |
| 344 | return -ENOMEM; |
| 345 | } |
| 346 | return 0; |
| 347 | } |
| 348 | |
| 349 | static int cx88_alsa_dma_unmap(struct cx88_audio_dev *dev) |
| 350 | { |
| 351 | struct cx88_audio_buffer *buf = dev->buf; |
| 352 | |
| 353 | if (!buf->sglen) |
| 354 | return 0; |
| 355 | |
| 356 | dma_unmap_sg(&dev->pci->dev, buf->sglist, buf->sglen, PCI_DMA_FROMDEVICE); |
| 357 | buf->sglen = 0; |
| 358 | return 0; |
| 359 | } |
| 360 | |
| 361 | static int cx88_alsa_dma_free(struct cx88_audio_buffer *buf) |
| 362 | { |
| 363 | vfree(buf->sglist); |
| 364 | buf->sglist = NULL; |
| 365 | vfree(buf->vaddr); |
| 366 | buf->vaddr = NULL; |
| 367 | return 0; |
| 368 | } |
| 369 | |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 370 | |
| 371 | static int dsp_buffer_free(snd_cx88_card_t *chip) |
| 372 | { |
Hans Verkuil | 5e7045e | 2014-08-29 04:11:54 -0300 | [diff] [blame] | 373 | struct cx88_riscmem *risc = &chip->buf->risc; |
| 374 | |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 375 | BUG_ON(!chip->dma_size); |
| 376 | |
| 377 | dprintk(2,"Freeing buffer\n"); |
Hans Verkuil | b2c75ab | 2014-08-29 05:25:30 -0300 | [diff] [blame] | 378 | cx88_alsa_dma_unmap(chip); |
| 379 | cx88_alsa_dma_free(chip->buf); |
Hans Verkuil | 5e7045e | 2014-08-29 04:11:54 -0300 | [diff] [blame] | 380 | if (risc->cpu) |
| 381 | pci_free_consistent(chip->pci, risc->size, risc->cpu, risc->dma); |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 382 | kfree(chip->buf); |
| 383 | |
Hans Verkuil | b2c75ab | 2014-08-29 05:25:30 -0300 | [diff] [blame] | 384 | chip->buf = NULL; |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 385 | |
Trent Piepho | 05b2723 | 2007-08-24 01:06:34 -0300 | [diff] [blame] | 386 | return 0; |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | /**************************************************************************** |
| 390 | ALSA PCM Interface |
| 391 | ****************************************************************************/ |
| 392 | |
| 393 | /* |
| 394 | * Digital hardware definition |
| 395 | */ |
Trent Piepho | 05b2723 | 2007-08-24 01:06:34 -0300 | [diff] [blame] | 396 | #define DEFAULT_FIFO_SIZE 4096 |
lawrence rust | 2e4e98e | 2010-08-25 09:50:20 -0300 | [diff] [blame] | 397 | static const struct snd_pcm_hardware snd_cx88_digital_hw = { |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 398 | .info = SNDRV_PCM_INFO_MMAP | |
| 399 | SNDRV_PCM_INFO_INTERLEAVED | |
| 400 | SNDRV_PCM_INFO_BLOCK_TRANSFER | |
| 401 | SNDRV_PCM_INFO_MMAP_VALID, |
| 402 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
| 403 | |
| 404 | .rates = SNDRV_PCM_RATE_48000, |
| 405 | .rate_min = 48000, |
| 406 | .rate_max = 48000, |
Trent Piepho | 5a5b3b5 | 2007-08-18 21:01:40 -0300 | [diff] [blame] | 407 | .channels_min = 2, |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 408 | .channels_max = 2, |
Trent Piepho | 05b2723 | 2007-08-24 01:06:34 -0300 | [diff] [blame] | 409 | /* Analog audio output will be full of clicks and pops if there |
| 410 | are not exactly four lines in the SRAM FIFO buffer. */ |
| 411 | .period_bytes_min = DEFAULT_FIFO_SIZE/4, |
| 412 | .period_bytes_max = DEFAULT_FIFO_SIZE/4, |
| 413 | .periods_min = 1, |
| 414 | .periods_max = 1024, |
| 415 | .buffer_bytes_max = (1024*1024), |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 416 | }; |
| 417 | |
| 418 | /* |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 419 | * audio pcm capture open callback |
| 420 | */ |
Takashi Iwai | f7cbb7f | 2006-01-13 18:48:06 +0100 | [diff] [blame] | 421 | static int snd_cx88_pcm_open(struct snd_pcm_substream *substream) |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 422 | { |
| 423 | snd_cx88_card_t *chip = snd_pcm_substream_chip(substream); |
Takashi Iwai | f7cbb7f | 2006-01-13 18:48:06 +0100 | [diff] [blame] | 424 | struct snd_pcm_runtime *runtime = substream->runtime; |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 425 | int err; |
| 426 | |
Mauro Carvalho Chehab | 83ee87a | 2008-06-14 09:41:18 -0300 | [diff] [blame] | 427 | if (!chip) { |
| 428 | printk(KERN_ERR "BUG: cx88 can't find device struct." |
| 429 | " Can't proceed with open\n"); |
| 430 | return -ENODEV; |
| 431 | } |
| 432 | |
Trent Piepho | 05b2723 | 2007-08-24 01:06:34 -0300 | [diff] [blame] | 433 | err = snd_pcm_hw_constraint_pow2(runtime, 0, SNDRV_PCM_HW_PARAM_PERIODS); |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 434 | if (err < 0) |
| 435 | goto _error; |
| 436 | |
| 437 | chip->substream = substream; |
| 438 | |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 439 | runtime->hw = snd_cx88_digital_hw; |
| 440 | |
Trent Piepho | 05b2723 | 2007-08-24 01:06:34 -0300 | [diff] [blame] | 441 | if (cx88_sram_channels[SRAM_CH25].fifo_size != DEFAULT_FIFO_SIZE) { |
| 442 | unsigned int bpl = cx88_sram_channels[SRAM_CH25].fifo_size / 4; |
| 443 | bpl &= ~7; /* must be multiple of 8 */ |
| 444 | runtime->hw.period_bytes_min = bpl; |
| 445 | runtime->hw.period_bytes_max = bpl; |
| 446 | } |
| 447 | |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 448 | return 0; |
| 449 | _error: |
| 450 | dprintk(1,"Error opening PCM!\n"); |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 451 | return err; |
| 452 | } |
| 453 | |
| 454 | /* |
| 455 | * audio close callback |
| 456 | */ |
Takashi Iwai | f7cbb7f | 2006-01-13 18:48:06 +0100 | [diff] [blame] | 457 | static int snd_cx88_close(struct snd_pcm_substream *substream) |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 458 | { |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 459 | return 0; |
| 460 | } |
| 461 | |
| 462 | /* |
| 463 | * hw_params callback |
| 464 | */ |
Takashi Iwai | f7cbb7f | 2006-01-13 18:48:06 +0100 | [diff] [blame] | 465 | static int snd_cx88_hw_params(struct snd_pcm_substream * substream, |
| 466 | struct snd_pcm_hw_params * hw_params) |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 467 | { |
| 468 | snd_cx88_card_t *chip = snd_pcm_substream_chip(substream); |
Mauro Carvalho Chehab | c1accaa | 2007-08-23 16:37:49 -0300 | [diff] [blame] | 469 | |
Laurent Pinchart | fecfede | 2010-05-11 10:36:31 -0300 | [diff] [blame] | 470 | struct cx88_audio_buffer *buf; |
Trent Piepho | 05b2723 | 2007-08-24 01:06:34 -0300 | [diff] [blame] | 471 | int ret; |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 472 | |
| 473 | if (substream->runtime->dma_area) { |
| 474 | dsp_buffer_free(chip); |
| 475 | substream->runtime->dma_area = NULL; |
| 476 | } |
| 477 | |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 478 | chip->period_size = params_period_bytes(hw_params); |
| 479 | chip->num_periods = params_periods(hw_params); |
| 480 | chip->dma_size = chip->period_size * params_periods(hw_params); |
| 481 | |
| 482 | BUG_ON(!chip->dma_size); |
Trent Piepho | 05b2723 | 2007-08-24 01:06:34 -0300 | [diff] [blame] | 483 | BUG_ON(chip->num_periods & (chip->num_periods-1)); |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 484 | |
Laurent Pinchart | fecfede | 2010-05-11 10:36:31 -0300 | [diff] [blame] | 485 | buf = kzalloc(sizeof(*buf), GFP_KERNEL); |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 486 | if (NULL == buf) |
| 487 | return -ENOMEM; |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 488 | |
Hans Verkuil | b2c75ab | 2014-08-29 05:25:30 -0300 | [diff] [blame] | 489 | chip->buf = buf; |
Laurent Pinchart | fecfede | 2010-05-11 10:36:31 -0300 | [diff] [blame] | 490 | buf->bpl = chip->period_size; |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 491 | |
Hans Verkuil | b2c75ab | 2014-08-29 05:25:30 -0300 | [diff] [blame] | 492 | ret = cx88_alsa_dma_init(chip, |
Laurent Pinchart | fecfede | 2010-05-11 10:36:31 -0300 | [diff] [blame] | 493 | (PAGE_ALIGN(chip->dma_size) >> PAGE_SHIFT)); |
Trent Piepho | 05b2723 | 2007-08-24 01:06:34 -0300 | [diff] [blame] | 494 | if (ret < 0) |
| 495 | goto error; |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 496 | |
Hans Verkuil | b2c75ab | 2014-08-29 05:25:30 -0300 | [diff] [blame] | 497 | ret = cx88_alsa_dma_map(chip); |
Trent Piepho | 05b2723 | 2007-08-24 01:06:34 -0300 | [diff] [blame] | 498 | if (ret < 0) |
| 499 | goto error; |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 500 | |
Hans Verkuil | b2c75ab | 2014-08-29 05:25:30 -0300 | [diff] [blame] | 501 | ret = cx88_risc_databuffer(chip->pci, &buf->risc, buf->sglist, |
Laurent Pinchart | fecfede | 2010-05-11 10:36:31 -0300 | [diff] [blame] | 502 | chip->period_size, chip->num_periods, 1); |
Trent Piepho | 05b2723 | 2007-08-24 01:06:34 -0300 | [diff] [blame] | 503 | if (ret < 0) |
| 504 | goto error; |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 505 | |
Trent Piepho | 05b2723 | 2007-08-24 01:06:34 -0300 | [diff] [blame] | 506 | /* Loop back to start of program */ |
| 507 | buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP|RISC_IRQ1|RISC_CNT_INC); |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 508 | buf->risc.jmp[1] = cpu_to_le32(buf->risc.dma); |
| 509 | |
Hans Verkuil | b2c75ab | 2014-08-29 05:25:30 -0300 | [diff] [blame] | 510 | substream->runtime->dma_area = chip->buf->vaddr; |
Trent Piepho | f6210c9 | 2007-08-24 01:06:36 -0300 | [diff] [blame] | 511 | substream->runtime->dma_bytes = chip->dma_size; |
| 512 | substream->runtime->dma_addr = 0; |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 513 | return 0; |
Trent Piepho | 05b2723 | 2007-08-24 01:06:34 -0300 | [diff] [blame] | 514 | |
| 515 | error: |
| 516 | kfree(buf); |
| 517 | return ret; |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | /* |
| 521 | * hw free callback |
| 522 | */ |
Takashi Iwai | f7cbb7f | 2006-01-13 18:48:06 +0100 | [diff] [blame] | 523 | static int snd_cx88_hw_free(struct snd_pcm_substream * substream) |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 524 | { |
| 525 | |
| 526 | snd_cx88_card_t *chip = snd_pcm_substream_chip(substream); |
| 527 | |
| 528 | if (substream->runtime->dma_area) { |
| 529 | dsp_buffer_free(chip); |
| 530 | substream->runtime->dma_area = NULL; |
| 531 | } |
| 532 | |
| 533 | return 0; |
| 534 | } |
| 535 | |
| 536 | /* |
| 537 | * prepare callback |
| 538 | */ |
Takashi Iwai | f7cbb7f | 2006-01-13 18:48:06 +0100 | [diff] [blame] | 539 | static int snd_cx88_prepare(struct snd_pcm_substream *substream) |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 540 | { |
| 541 | return 0; |
| 542 | } |
| 543 | |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 544 | /* |
| 545 | * trigger callback |
| 546 | */ |
Takashi Iwai | f7cbb7f | 2006-01-13 18:48:06 +0100 | [diff] [blame] | 547 | static int snd_cx88_card_trigger(struct snd_pcm_substream *substream, int cmd) |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 548 | { |
| 549 | snd_cx88_card_t *chip = snd_pcm_substream_chip(substream); |
| 550 | int err; |
| 551 | |
Trent Piepho | 05b2723 | 2007-08-24 01:06:34 -0300 | [diff] [blame] | 552 | /* Local interrupts are already disabled by ALSA */ |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 553 | spin_lock(&chip->reg_lock); |
| 554 | |
| 555 | switch (cmd) { |
| 556 | case SNDRV_PCM_TRIGGER_START: |
| 557 | err=_cx88_start_audio_dma(chip); |
| 558 | break; |
| 559 | case SNDRV_PCM_TRIGGER_STOP: |
| 560 | err=_cx88_stop_audio_dma(chip); |
| 561 | break; |
| 562 | default: |
| 563 | err=-EINVAL; |
| 564 | break; |
| 565 | } |
| 566 | |
| 567 | spin_unlock(&chip->reg_lock); |
| 568 | |
| 569 | return err; |
| 570 | } |
| 571 | |
| 572 | /* |
| 573 | * pointer callback |
| 574 | */ |
Takashi Iwai | f7cbb7f | 2006-01-13 18:48:06 +0100 | [diff] [blame] | 575 | static snd_pcm_uframes_t snd_cx88_pointer(struct snd_pcm_substream *substream) |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 576 | { |
| 577 | snd_cx88_card_t *chip = snd_pcm_substream_chip(substream); |
Takashi Iwai | f7cbb7f | 2006-01-13 18:48:06 +0100 | [diff] [blame] | 578 | struct snd_pcm_runtime *runtime = substream->runtime; |
Trent Piepho | 05b2723 | 2007-08-24 01:06:34 -0300 | [diff] [blame] | 579 | u16 count; |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 580 | |
Trent Piepho | 05b2723 | 2007-08-24 01:06:34 -0300 | [diff] [blame] | 581 | count = atomic_read(&chip->count); |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 582 | |
Harvey Harrison | 32d83ef | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 583 | // dprintk(2, "%s - count %d (+%u), period %d, frame %lu\n", __func__, |
Trent Piepho | 05b2723 | 2007-08-24 01:06:34 -0300 | [diff] [blame] | 584 | // count, new, count & (runtime->periods-1), |
| 585 | // runtime->period_size * (count & (runtime->periods-1))); |
| 586 | return runtime->period_size * (count & (runtime->periods-1)); |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | /* |
Trent Piepho | f6210c9 | 2007-08-24 01:06:36 -0300 | [diff] [blame] | 590 | * page callback (needed for mmap) |
| 591 | */ |
| 592 | static struct page *snd_cx88_page(struct snd_pcm_substream *substream, |
| 593 | unsigned long offset) |
| 594 | { |
| 595 | void *pageptr = substream->runtime->dma_area + offset; |
| 596 | return vmalloc_to_page(pageptr); |
| 597 | } |
| 598 | |
| 599 | /* |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 600 | * operators |
| 601 | */ |
Takashi Iwai | f7cbb7f | 2006-01-13 18:48:06 +0100 | [diff] [blame] | 602 | static struct snd_pcm_ops snd_cx88_pcm_ops = { |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 603 | .open = snd_cx88_pcm_open, |
| 604 | .close = snd_cx88_close, |
| 605 | .ioctl = snd_pcm_lib_ioctl, |
| 606 | .hw_params = snd_cx88_hw_params, |
| 607 | .hw_free = snd_cx88_hw_free, |
| 608 | .prepare = snd_cx88_prepare, |
| 609 | .trigger = snd_cx88_card_trigger, |
| 610 | .pointer = snd_cx88_pointer, |
Trent Piepho | f6210c9 | 2007-08-24 01:06:36 -0300 | [diff] [blame] | 611 | .page = snd_cx88_page, |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 612 | }; |
| 613 | |
| 614 | /* |
| 615 | * create a PCM device |
| 616 | */ |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 617 | static int snd_cx88_pcm(snd_cx88_card_t *chip, int device, const char *name) |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 618 | { |
| 619 | int err; |
Takashi Iwai | f7cbb7f | 2006-01-13 18:48:06 +0100 | [diff] [blame] | 620 | struct snd_pcm *pcm; |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 621 | |
| 622 | err = snd_pcm_new(chip->card, name, device, 0, 1, &pcm); |
| 623 | if (err < 0) |
| 624 | return err; |
| 625 | pcm->private_data = chip; |
| 626 | strcpy(pcm->name, name); |
| 627 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_cx88_pcm_ops); |
| 628 | |
| 629 | return 0; |
| 630 | } |
| 631 | |
| 632 | /**************************************************************************** |
| 633 | CONTROL INTERFACE |
| 634 | ****************************************************************************/ |
Trent Piepho | 54ac005 | 2007-09-06 23:02:23 -0300 | [diff] [blame] | 635 | static int snd_cx88_volume_info(struct snd_kcontrol *kcontrol, |
| 636 | struct snd_ctl_elem_info *info) |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 637 | { |
| 638 | info->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
Trent Piepho | 82896f2 | 2007-09-06 23:02:23 -0300 | [diff] [blame] | 639 | info->count = 2; |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 640 | info->value.integer.min = 0; |
| 641 | info->value.integer.max = 0x3f; |
| 642 | |
| 643 | return 0; |
| 644 | } |
| 645 | |
Trent Piepho | 54ac005 | 2007-09-06 23:02:23 -0300 | [diff] [blame] | 646 | static int snd_cx88_volume_get(struct snd_kcontrol *kcontrol, |
| 647 | struct snd_ctl_elem_value *value) |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 648 | { |
| 649 | snd_cx88_card_t *chip = snd_kcontrol_chip(kcontrol); |
| 650 | struct cx88_core *core=chip->core; |
Trent Piepho | 82896f2 | 2007-09-06 23:02:23 -0300 | [diff] [blame] | 651 | int vol = 0x3f - (cx_read(AUD_VOL_CTL) & 0x3f), |
| 652 | bal = cx_read(AUD_BAL_CTL); |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 653 | |
Trent Piepho | 82896f2 | 2007-09-06 23:02:23 -0300 | [diff] [blame] | 654 | value->value.integer.value[(bal & 0x40) ? 0 : 1] = vol; |
| 655 | vol -= (bal & 0x3f); |
| 656 | value->value.integer.value[(bal & 0x40) ? 1 : 0] = vol < 0 ? 0 : vol; |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 657 | |
| 658 | return 0; |
| 659 | } |
| 660 | |
Lawrence Rust | 6951803 | 2011-02-06 17:46:12 -0300 | [diff] [blame] | 661 | static void snd_cx88_wm8775_volume_put(struct snd_kcontrol *kcontrol, |
| 662 | struct snd_ctl_elem_value *value) |
| 663 | { |
| 664 | snd_cx88_card_t *chip = snd_kcontrol_chip(kcontrol); |
| 665 | struct cx88_core *core = chip->core; |
Lawrence Rust | 6951803 | 2011-02-06 17:46:12 -0300 | [diff] [blame] | 666 | int left = value->value.integer.value[0]; |
| 667 | int right = value->value.integer.value[1]; |
| 668 | int v, b; |
| 669 | |
Lawrence Rust | 6951803 | 2011-02-06 17:46:12 -0300 | [diff] [blame] | 670 | /* Pass volume & balance onto any WM8775 */ |
| 671 | if (left >= right) { |
| 672 | v = left << 10; |
| 673 | b = left ? (0x8000 * right) / left : 0x8000; |
| 674 | } else { |
| 675 | v = right << 10; |
| 676 | b = right ? 0xffff - (0x8000 * left) / right : 0x8000; |
| 677 | } |
Hans Verkuil | bac6398 | 2012-06-10 07:39:52 -0300 | [diff] [blame] | 678 | wm8775_s_ctrl(core, V4L2_CID_AUDIO_VOLUME, v); |
| 679 | wm8775_s_ctrl(core, V4L2_CID_AUDIO_BALANCE, b); |
Lawrence Rust | 6951803 | 2011-02-06 17:46:12 -0300 | [diff] [blame] | 680 | } |
| 681 | |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 682 | /* OK - TODO: test it */ |
Trent Piepho | 54ac005 | 2007-09-06 23:02:23 -0300 | [diff] [blame] | 683 | static int snd_cx88_volume_put(struct snd_kcontrol *kcontrol, |
| 684 | struct snd_ctl_elem_value *value) |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 685 | { |
| 686 | snd_cx88_card_t *chip = snd_kcontrol_chip(kcontrol); |
| 687 | struct cx88_core *core=chip->core; |
Clemens Ladisch | cca80b9 | 2010-02-22 06:45:07 -0300 | [diff] [blame] | 688 | int left, right, v, b; |
Trent Piepho | 82896f2 | 2007-09-06 23:02:23 -0300 | [diff] [blame] | 689 | int changed = 0; |
| 690 | u32 old; |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 691 | |
Hans Verkuil | 609c4c1 | 2013-05-29 10:44:22 -0300 | [diff] [blame] | 692 | if (core->sd_wm8775) |
Lawrence Rust | 6951803 | 2011-02-06 17:46:12 -0300 | [diff] [blame] | 693 | snd_cx88_wm8775_volume_put(kcontrol, value); |
| 694 | |
Clemens Ladisch | cca80b9 | 2010-02-22 06:45:07 -0300 | [diff] [blame] | 695 | left = value->value.integer.value[0] & 0x3f; |
| 696 | right = value->value.integer.value[1] & 0x3f; |
| 697 | b = right - left; |
Trent Piepho | 82896f2 | 2007-09-06 23:02:23 -0300 | [diff] [blame] | 698 | if (b < 0) { |
Lawrence Rust | 6951803 | 2011-02-06 17:46:12 -0300 | [diff] [blame] | 699 | v = 0x3f - left; |
| 700 | b = (-b) | 0x40; |
Trent Piepho | 82896f2 | 2007-09-06 23:02:23 -0300 | [diff] [blame] | 701 | } else { |
Lawrence Rust | 6951803 | 2011-02-06 17:46:12 -0300 | [diff] [blame] | 702 | v = 0x3f - right; |
Trent Piepho | 82896f2 | 2007-09-06 23:02:23 -0300 | [diff] [blame] | 703 | } |
Trent Piepho | 05b2723 | 2007-08-24 01:06:34 -0300 | [diff] [blame] | 704 | /* Do we really know this will always be called with IRQs on? */ |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 705 | spin_lock_irq(&chip->reg_lock); |
Trent Piepho | 82896f2 | 2007-09-06 23:02:23 -0300 | [diff] [blame] | 706 | old = cx_read(AUD_VOL_CTL); |
| 707 | if (v != (old & 0x3f)) { |
Lawrence Rust | 6951803 | 2011-02-06 17:46:12 -0300 | [diff] [blame] | 708 | cx_swrite(SHADOW_AUD_VOL_CTL, AUD_VOL_CTL, (old & ~0x3f) | v); |
| 709 | changed = 1; |
Trent Piepho | 82896f2 | 2007-09-06 23:02:23 -0300 | [diff] [blame] | 710 | } |
Lawrence Rust | 6951803 | 2011-02-06 17:46:12 -0300 | [diff] [blame] | 711 | if ((cx_read(AUD_BAL_CTL) & 0x7f) != b) { |
| 712 | cx_write(AUD_BAL_CTL, b); |
| 713 | changed = 1; |
Trent Piepho | 82896f2 | 2007-09-06 23:02:23 -0300 | [diff] [blame] | 714 | } |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 715 | spin_unlock_irq(&chip->reg_lock); |
| 716 | |
Trent Piepho | 82896f2 | 2007-09-06 23:02:23 -0300 | [diff] [blame] | 717 | return changed; |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 718 | } |
| 719 | |
Trent Piepho | bbaccc0 | 2007-09-06 23:02:25 -0300 | [diff] [blame] | 720 | static const DECLARE_TLV_DB_SCALE(snd_cx88_db_scale, -6300, 100, 0); |
| 721 | |
lawrence rust | 2e4e98e | 2010-08-25 09:50:20 -0300 | [diff] [blame] | 722 | static const struct snd_kcontrol_new snd_cx88_volume = { |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 723 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Trent Piepho | bbaccc0 | 2007-09-06 23:02:25 -0300 | [diff] [blame] | 724 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | |
| 725 | SNDRV_CTL_ELEM_ACCESS_TLV_READ, |
Lawrence Rust | 6951803 | 2011-02-06 17:46:12 -0300 | [diff] [blame] | 726 | .name = "Analog-TV Volume", |
Trent Piepho | 54ac005 | 2007-09-06 23:02:23 -0300 | [diff] [blame] | 727 | .info = snd_cx88_volume_info, |
| 728 | .get = snd_cx88_volume_get, |
| 729 | .put = snd_cx88_volume_put, |
Trent Piepho | bbaccc0 | 2007-09-06 23:02:25 -0300 | [diff] [blame] | 730 | .tlv.p = snd_cx88_db_scale, |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 731 | }; |
| 732 | |
Trent Piepho | 54ac005 | 2007-09-06 23:02:23 -0300 | [diff] [blame] | 733 | static int snd_cx88_switch_get(struct snd_kcontrol *kcontrol, |
| 734 | struct snd_ctl_elem_value *value) |
| 735 | { |
| 736 | snd_cx88_card_t *chip = snd_kcontrol_chip(kcontrol); |
| 737 | struct cx88_core *core = chip->core; |
| 738 | u32 bit = kcontrol->private_value; |
| 739 | |
| 740 | value->value.integer.value[0] = !(cx_read(AUD_VOL_CTL) & bit); |
| 741 | return 0; |
| 742 | } |
| 743 | |
| 744 | static int snd_cx88_switch_put(struct snd_kcontrol *kcontrol, |
| 745 | struct snd_ctl_elem_value *value) |
| 746 | { |
| 747 | snd_cx88_card_t *chip = snd_kcontrol_chip(kcontrol); |
| 748 | struct cx88_core *core = chip->core; |
| 749 | u32 bit = kcontrol->private_value; |
| 750 | int ret = 0; |
| 751 | u32 vol; |
| 752 | |
| 753 | spin_lock_irq(&chip->reg_lock); |
| 754 | vol = cx_read(AUD_VOL_CTL); |
| 755 | if (value->value.integer.value[0] != !(vol & bit)) { |
| 756 | vol ^= bit; |
Lawrence Rust | 6951803 | 2011-02-06 17:46:12 -0300 | [diff] [blame] | 757 | cx_swrite(SHADOW_AUD_VOL_CTL, AUD_VOL_CTL, vol); |
| 758 | /* Pass mute onto any WM8775 */ |
Hans Verkuil | 609c4c1 | 2013-05-29 10:44:22 -0300 | [diff] [blame] | 759 | if (core->sd_wm8775 && ((1<<6) == bit)) |
Hans Verkuil | bac6398 | 2012-06-10 07:39:52 -0300 | [diff] [blame] | 760 | wm8775_s_ctrl(core, V4L2_CID_AUDIO_MUTE, 0 != (vol & bit)); |
Trent Piepho | 54ac005 | 2007-09-06 23:02:23 -0300 | [diff] [blame] | 761 | ret = 1; |
| 762 | } |
| 763 | spin_unlock_irq(&chip->reg_lock); |
| 764 | return ret; |
| 765 | } |
| 766 | |
lawrence rust | 2e4e98e | 2010-08-25 09:50:20 -0300 | [diff] [blame] | 767 | static const struct snd_kcontrol_new snd_cx88_dac_switch = { |
Trent Piepho | 54ac005 | 2007-09-06 23:02:23 -0300 | [diff] [blame] | 768 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Lawrence Rust | 6951803 | 2011-02-06 17:46:12 -0300 | [diff] [blame] | 769 | .name = "Audio-Out Switch", |
Trent Piepho | 54ac005 | 2007-09-06 23:02:23 -0300 | [diff] [blame] | 770 | .info = snd_ctl_boolean_mono_info, |
| 771 | .get = snd_cx88_switch_get, |
| 772 | .put = snd_cx88_switch_put, |
| 773 | .private_value = (1<<8), |
| 774 | }; |
| 775 | |
lawrence rust | 2e4e98e | 2010-08-25 09:50:20 -0300 | [diff] [blame] | 776 | static const struct snd_kcontrol_new snd_cx88_source_switch = { |
Trent Piepho | 54ac005 | 2007-09-06 23:02:23 -0300 | [diff] [blame] | 777 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Lawrence Rust | 6951803 | 2011-02-06 17:46:12 -0300 | [diff] [blame] | 778 | .name = "Analog-TV Switch", |
Trent Piepho | 54ac005 | 2007-09-06 23:02:23 -0300 | [diff] [blame] | 779 | .info = snd_ctl_boolean_mono_info, |
| 780 | .get = snd_cx88_switch_get, |
| 781 | .put = snd_cx88_switch_put, |
| 782 | .private_value = (1<<6), |
| 783 | }; |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 784 | |
Lawrence Rust | 6951803 | 2011-02-06 17:46:12 -0300 | [diff] [blame] | 785 | static int snd_cx88_alc_get(struct snd_kcontrol *kcontrol, |
| 786 | struct snd_ctl_elem_value *value) |
| 787 | { |
| 788 | snd_cx88_card_t *chip = snd_kcontrol_chip(kcontrol); |
| 789 | struct cx88_core *core = chip->core; |
Hans Verkuil | bac6398 | 2012-06-10 07:39:52 -0300 | [diff] [blame] | 790 | s32 val; |
Lawrence Rust | 6951803 | 2011-02-06 17:46:12 -0300 | [diff] [blame] | 791 | |
Hans Verkuil | bac6398 | 2012-06-10 07:39:52 -0300 | [diff] [blame] | 792 | val = wm8775_g_ctrl(core, V4L2_CID_AUDIO_LOUDNESS); |
| 793 | value->value.integer.value[0] = val ? 1 : 0; |
Lawrence Rust | 6951803 | 2011-02-06 17:46:12 -0300 | [diff] [blame] | 794 | return 0; |
| 795 | } |
| 796 | |
| 797 | static int snd_cx88_alc_put(struct snd_kcontrol *kcontrol, |
| 798 | struct snd_ctl_elem_value *value) |
| 799 | { |
| 800 | snd_cx88_card_t *chip = snd_kcontrol_chip(kcontrol); |
| 801 | struct cx88_core *core = chip->core; |
| 802 | struct v4l2_control client_ctl; |
| 803 | |
| 804 | memset(&client_ctl, 0, sizeof(client_ctl)); |
| 805 | client_ctl.value = 0 != value->value.integer.value[0]; |
| 806 | client_ctl.id = V4L2_CID_AUDIO_LOUDNESS; |
| 807 | call_hw(core, WM8775_GID, core, s_ctrl, &client_ctl); |
| 808 | |
| 809 | return 0; |
| 810 | } |
| 811 | |
| 812 | static struct snd_kcontrol_new snd_cx88_alc_switch = { |
| 813 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 814 | .name = "Line-In ALC Switch", |
| 815 | .info = snd_ctl_boolean_mono_info, |
| 816 | .get = snd_cx88_alc_get, |
| 817 | .put = snd_cx88_alc_put, |
| 818 | }; |
| 819 | |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 820 | /**************************************************************************** |
| 821 | Basic Flow for Sound Devices |
| 822 | ****************************************************************************/ |
| 823 | |
| 824 | /* |
| 825 | * PCI ID Table - 14f1:8801 and 14f1:8811 means function 1: Audio |
| 826 | * Only boards with eeprom and byte 1 at eeprom=1 have it |
| 827 | */ |
| 828 | |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 829 | static const struct pci_device_id cx88_audio_pci_tbl[] = { |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 830 | {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0}, |
| 831 | {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0}, |
| 832 | {0, } |
| 833 | }; |
| 834 | MODULE_DEVICE_TABLE(pci, cx88_audio_pci_tbl); |
| 835 | |
| 836 | /* |
| 837 | * Chip-specific destructor |
| 838 | */ |
| 839 | |
| 840 | static int snd_cx88_free(snd_cx88_card_t *chip) |
| 841 | { |
| 842 | |
Jeff Garzik | f000fd8 | 2008-04-22 13:50:34 +0200 | [diff] [blame] | 843 | if (chip->irq >= 0) |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 844 | free_irq(chip->irq, chip); |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 845 | |
| 846 | cx88_core_put(chip->core,chip->pci); |
| 847 | |
| 848 | pci_disable_device(chip->pci); |
| 849 | return 0; |
| 850 | } |
| 851 | |
| 852 | /* |
| 853 | * Component Destructor |
| 854 | */ |
Takashi Iwai | f7cbb7f | 2006-01-13 18:48:06 +0100 | [diff] [blame] | 855 | static void snd_cx88_dev_free(struct snd_card * card) |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 856 | { |
| 857 | snd_cx88_card_t *chip = card->private_data; |
| 858 | |
| 859 | snd_cx88_free(chip); |
| 860 | } |
| 861 | |
| 862 | |
| 863 | /* |
| 864 | * Alsa Constructor - Component probe |
| 865 | */ |
| 866 | |
Mauro Carvalho Chehab | a5ed425 | 2006-01-13 14:10:19 -0200 | [diff] [blame] | 867 | static int devno; |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 868 | static int snd_cx88_create(struct snd_card *card, struct pci_dev *pci, |
| 869 | snd_cx88_card_t **rchip, |
| 870 | struct cx88_core **core_ptr) |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 871 | { |
| 872 | snd_cx88_card_t *chip; |
| 873 | struct cx88_core *core; |
| 874 | int err; |
Trent Piepho | 19453bc | 2007-08-18 22:54:49 -0300 | [diff] [blame] | 875 | unsigned char pci_lat; |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 876 | |
| 877 | *rchip = NULL; |
| 878 | |
| 879 | err = pci_enable_device(pci); |
| 880 | if (err < 0) |
| 881 | return err; |
| 882 | |
| 883 | pci_set_master(pci); |
| 884 | |
Joe Perches | abf8438 | 2010-07-12 17:50:03 -0300 | [diff] [blame] | 885 | chip = card->private_data; |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 886 | |
| 887 | core = cx88_core_get(pci); |
Duncan Sands | 31dcbf9 | 2006-03-14 12:12:39 -0300 | [diff] [blame] | 888 | if (NULL == core) { |
| 889 | err = -EINVAL; |
Duncan Sands | 31dcbf9 | 2006-03-14 12:12:39 -0300 | [diff] [blame] | 890 | return err; |
| 891 | } |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 892 | |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 893 | if (!pci_dma_supported(pci,DMA_BIT_MASK(32))) { |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 894 | dprintk(0, "%s/1: Oops: no 32bit PCI DMA ???\n",core->name); |
| 895 | err = -EIO; |
Lawrence Rust | 6951803 | 2011-02-06 17:46:12 -0300 | [diff] [blame] | 896 | cx88_core_put(core, pci); |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 897 | return err; |
| 898 | } |
| 899 | |
| 900 | |
| 901 | /* pci init */ |
| 902 | chip->card = card; |
| 903 | chip->pci = pci; |
| 904 | chip->irq = -1; |
| 905 | spin_lock_init(&chip->reg_lock); |
| 906 | |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 907 | chip->core = core; |
| 908 | |
| 909 | /* get irq */ |
| 910 | err = request_irq(chip->pci->irq, cx8801_irq, |
Michael Opdenacker | 3e018fe | 2013-10-13 02:49:29 -0300 | [diff] [blame] | 911 | IRQF_SHARED, chip->core->name, chip); |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 912 | if (err < 0) { |
| 913 | dprintk(0, "%s: can't get IRQ %d\n", |
| 914 | chip->core->name, chip->pci->irq); |
| 915 | return err; |
| 916 | } |
| 917 | |
| 918 | /* print pci info */ |
Trent Piepho | 19453bc | 2007-08-18 22:54:49 -0300 | [diff] [blame] | 919 | pci_read_config_byte(pci, PCI_LATENCY_TIMER, &pci_lat); |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 920 | |
| 921 | dprintk(1,"ALSA %s/%i: found at %s, rev: %d, irq: %d, " |
Greg Kroah-Hartman | 228aef6 | 2006-06-12 15:16:52 -0700 | [diff] [blame] | 922 | "latency: %d, mmio: 0x%llx\n", core->name, devno, |
Trent Piepho | 19453bc | 2007-08-18 22:54:49 -0300 | [diff] [blame] | 923 | pci_name(pci), pci->revision, pci->irq, |
| 924 | pci_lat, (unsigned long long)pci_resource_start(pci,0)); |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 925 | |
| 926 | chip->irq = pci->irq; |
| 927 | synchronize_irq(chip->irq); |
| 928 | |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 929 | *rchip = chip; |
Lawrence Rust | 6951803 | 2011-02-06 17:46:12 -0300 | [diff] [blame] | 930 | *core_ptr = core; |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 931 | |
| 932 | return 0; |
| 933 | } |
| 934 | |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 935 | static int cx88_audio_initdev(struct pci_dev *pci, |
| 936 | const struct pci_device_id *pci_id) |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 937 | { |
Takashi Iwai | f7cbb7f | 2006-01-13 18:48:06 +0100 | [diff] [blame] | 938 | struct snd_card *card; |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 939 | snd_cx88_card_t *chip; |
Hans Verkuil | d6972cc | 2011-03-06 09:31:00 -0300 | [diff] [blame] | 940 | struct cx88_core *core = NULL; |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 941 | int err; |
| 942 | |
| 943 | if (devno >= SNDRV_CARDS) |
| 944 | return (-ENODEV); |
| 945 | |
| 946 | if (!enable[devno]) { |
| 947 | ++devno; |
| 948 | return (-ENOENT); |
| 949 | } |
| 950 | |
Takashi Iwai | e735688 | 2014-01-29 14:48:43 +0100 | [diff] [blame] | 951 | err = snd_card_new(&pci->dev, index[devno], id[devno], THIS_MODULE, |
| 952 | sizeof(snd_cx88_card_t), &card); |
Takashi Iwai | 758021b | 2009-01-12 15:17:09 +0100 | [diff] [blame] | 953 | if (err < 0) |
| 954 | return err; |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 955 | |
| 956 | card->private_free = snd_cx88_dev_free; |
| 957 | |
Lawrence Rust | 6951803 | 2011-02-06 17:46:12 -0300 | [diff] [blame] | 958 | err = snd_cx88_create(card, pci, &chip, &core); |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 959 | if (err < 0) |
Julia Lawall | a8782f6 | 2008-12-02 19:34:52 -0300 | [diff] [blame] | 960 | goto error; |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 961 | |
| 962 | err = snd_cx88_pcm(chip, 0, "CX88 Digital"); |
Trent Piepho | 82896f2 | 2007-09-06 23:02:23 -0300 | [diff] [blame] | 963 | if (err < 0) |
| 964 | goto error; |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 965 | |
Trent Piepho | 54ac005 | 2007-09-06 23:02:23 -0300 | [diff] [blame] | 966 | err = snd_ctl_add(card, snd_ctl_new1(&snd_cx88_volume, chip)); |
| 967 | if (err < 0) |
| 968 | goto error; |
| 969 | err = snd_ctl_add(card, snd_ctl_new1(&snd_cx88_dac_switch, chip)); |
| 970 | if (err < 0) |
| 971 | goto error; |
| 972 | err = snd_ctl_add(card, snd_ctl_new1(&snd_cx88_source_switch, chip)); |
Trent Piepho | 82896f2 | 2007-09-06 23:02:23 -0300 | [diff] [blame] | 973 | if (err < 0) |
| 974 | goto error; |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 975 | |
Lawrence Rust | 6951803 | 2011-02-06 17:46:12 -0300 | [diff] [blame] | 976 | /* If there's a wm8775 then add a Line-In ALC switch */ |
Hans Verkuil | 609c4c1 | 2013-05-29 10:44:22 -0300 | [diff] [blame] | 977 | if (core->sd_wm8775) |
Lawrence Rust | 6951803 | 2011-02-06 17:46:12 -0300 | [diff] [blame] | 978 | snd_ctl_add(card, snd_ctl_new1(&snd_cx88_alc_switch, chip)); |
| 979 | |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 980 | strcpy (card->driver, "CX88x"); |
| 981 | sprintf(card->shortname, "Conexant CX%x", pci->device); |
Greg Kroah-Hartman | 228aef6 | 2006-06-12 15:16:52 -0700 | [diff] [blame] | 982 | sprintf(card->longname, "%s at %#llx", |
| 983 | card->shortname,(unsigned long long)pci_resource_start(pci, 0)); |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 984 | strcpy (card->mixername, "CX88"); |
| 985 | |
| 986 | dprintk (0, "%s/%i: ALSA support for cx2388x boards\n", |
| 987 | card->driver,devno); |
| 988 | |
| 989 | err = snd_card_register(card); |
Trent Piepho | 82896f2 | 2007-09-06 23:02:23 -0300 | [diff] [blame] | 990 | if (err < 0) |
| 991 | goto error; |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 992 | pci_set_drvdata(pci,card); |
| 993 | |
| 994 | devno++; |
| 995 | return 0; |
Trent Piepho | 82896f2 | 2007-09-06 23:02:23 -0300 | [diff] [blame] | 996 | |
| 997 | error: |
| 998 | snd_card_free(card); |
| 999 | return err; |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 1000 | } |
| 1001 | /* |
| 1002 | * ALSA destructor |
| 1003 | */ |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 1004 | static void cx88_audio_finidev(struct pci_dev *pci) |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 1005 | { |
Wei Yongjun | cd86e3b | 2013-11-21 00:38:44 -0300 | [diff] [blame] | 1006 | struct snd_card *card = pci_get_drvdata(pci); |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 1007 | |
Wei Yongjun | cd86e3b | 2013-11-21 00:38:44 -0300 | [diff] [blame] | 1008 | snd_card_free(card); |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 1009 | |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 1010 | devno--; |
| 1011 | } |
| 1012 | |
| 1013 | /* |
| 1014 | * PCI driver definition |
| 1015 | */ |
| 1016 | |
| 1017 | static struct pci_driver cx88_audio_pci_driver = { |
| 1018 | .name = "cx88_audio", |
| 1019 | .id_table = cx88_audio_pci_tbl, |
| 1020 | .probe = cx88_audio_initdev, |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 1021 | .remove = cx88_audio_finidev, |
Mauro Carvalho Chehab | b7f355d | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 1022 | }; |
| 1023 | |
Sachin Kamat | 59963b9 | 2013-09-20 05:32:05 -0300 | [diff] [blame] | 1024 | module_pci_driver(cx88_audio_pci_driver); |