18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (c) by Jaroslav Kysela <perex@perex.cz> 48c2ecf20Sopenharmony_ci * Abramo Bagnara <abramo@alsa-project.org> 58c2ecf20Sopenharmony_ci * Cirrus Logic, Inc. 68c2ecf20Sopenharmony_ci * Routines for control of Cirrus Logic CS461x chips 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * KNOWN BUGS: 98c2ecf20Sopenharmony_ci * - Sometimes the SPDIF input DSP tasks get's unsynchronized 108c2ecf20Sopenharmony_ci * and the SPDIF get somewhat "distorcionated", or/and left right channel 118c2ecf20Sopenharmony_ci * are swapped. To get around this problem when it happens, mute and unmute 128c2ecf20Sopenharmony_ci * the SPDIF input mixer control. 138c2ecf20Sopenharmony_ci * - On the Hercules Game Theater XP the amplifier are sometimes turned 148c2ecf20Sopenharmony_ci * off on inadecuate moments which causes distorcions on sound. 158c2ecf20Sopenharmony_ci * 168c2ecf20Sopenharmony_ci * TODO: 178c2ecf20Sopenharmony_ci * - Secondary CODEC on some soundcards 188c2ecf20Sopenharmony_ci * - SPDIF input support for other sample rates then 48khz 198c2ecf20Sopenharmony_ci * - Posibility to mix the SPDIF output with analog sources. 208c2ecf20Sopenharmony_ci * - PCM channels for Center and LFE on secondary codec 218c2ecf20Sopenharmony_ci * 228c2ecf20Sopenharmony_ci * NOTE: with CONFIG_SND_CS46XX_NEW_DSP unset uses old DSP image (which 238c2ecf20Sopenharmony_ci * is default configuration), no SPDIF, no secondary codec, no 248c2ecf20Sopenharmony_ci * multi channel PCM. But known to work. 258c2ecf20Sopenharmony_ci * 268c2ecf20Sopenharmony_ci * FINALLY: A credit to the developers Tom and Jordan 278c2ecf20Sopenharmony_ci * at Cirrus for have helping me out with the DSP, however we 288c2ecf20Sopenharmony_ci * still don't have sufficient documentation and technical 298c2ecf20Sopenharmony_ci * references to be able to implement all fancy feutures 308c2ecf20Sopenharmony_ci * supported by the cs46xx DSP's. 318c2ecf20Sopenharmony_ci * Benny <benny@hostmobility.com> 328c2ecf20Sopenharmony_ci */ 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci#include <linux/delay.h> 358c2ecf20Sopenharmony_ci#include <linux/pci.h> 368c2ecf20Sopenharmony_ci#include <linux/pm.h> 378c2ecf20Sopenharmony_ci#include <linux/init.h> 388c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 398c2ecf20Sopenharmony_ci#include <linux/slab.h> 408c2ecf20Sopenharmony_ci#include <linux/gameport.h> 418c2ecf20Sopenharmony_ci#include <linux/mutex.h> 428c2ecf20Sopenharmony_ci#include <linux/export.h> 438c2ecf20Sopenharmony_ci#include <linux/module.h> 448c2ecf20Sopenharmony_ci#include <linux/firmware.h> 458c2ecf20Sopenharmony_ci#include <linux/vmalloc.h> 468c2ecf20Sopenharmony_ci#include <linux/io.h> 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci#include <sound/core.h> 498c2ecf20Sopenharmony_ci#include <sound/control.h> 508c2ecf20Sopenharmony_ci#include <sound/info.h> 518c2ecf20Sopenharmony_ci#include <sound/pcm.h> 528c2ecf20Sopenharmony_ci#include <sound/pcm_params.h> 538c2ecf20Sopenharmony_ci#include "cs46xx.h" 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci#include "cs46xx_lib.h" 568c2ecf20Sopenharmony_ci#include "dsp_spos.h" 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_cistatic void amp_voyetra(struct snd_cs46xx *chip, int change); 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 618c2ecf20Sopenharmony_cistatic const struct snd_pcm_ops snd_cs46xx_playback_rear_ops; 628c2ecf20Sopenharmony_cistatic const struct snd_pcm_ops snd_cs46xx_playback_indirect_rear_ops; 638c2ecf20Sopenharmony_cistatic const struct snd_pcm_ops snd_cs46xx_playback_clfe_ops; 648c2ecf20Sopenharmony_cistatic const struct snd_pcm_ops snd_cs46xx_playback_indirect_clfe_ops; 658c2ecf20Sopenharmony_cistatic const struct snd_pcm_ops snd_cs46xx_playback_iec958_ops; 668c2ecf20Sopenharmony_cistatic const struct snd_pcm_ops snd_cs46xx_playback_indirect_iec958_ops; 678c2ecf20Sopenharmony_ci#endif 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_cistatic const struct snd_pcm_ops snd_cs46xx_playback_ops; 708c2ecf20Sopenharmony_cistatic const struct snd_pcm_ops snd_cs46xx_playback_indirect_ops; 718c2ecf20Sopenharmony_cistatic const struct snd_pcm_ops snd_cs46xx_capture_ops; 728c2ecf20Sopenharmony_cistatic const struct snd_pcm_ops snd_cs46xx_capture_indirect_ops; 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_cistatic unsigned short snd_cs46xx_codec_read(struct snd_cs46xx *chip, 758c2ecf20Sopenharmony_ci unsigned short reg, 768c2ecf20Sopenharmony_ci int codec_index) 778c2ecf20Sopenharmony_ci{ 788c2ecf20Sopenharmony_ci int count; 798c2ecf20Sopenharmony_ci unsigned short result,tmp; 808c2ecf20Sopenharmony_ci u32 offset = 0; 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci if (snd_BUG_ON(codec_index != CS46XX_PRIMARY_CODEC_INDEX && 838c2ecf20Sopenharmony_ci codec_index != CS46XX_SECONDARY_CODEC_INDEX)) 848c2ecf20Sopenharmony_ci return 0xffff; 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci chip->active_ctrl(chip, 1); 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci if (codec_index == CS46XX_SECONDARY_CODEC_INDEX) 898c2ecf20Sopenharmony_ci offset = CS46XX_SECONDARY_CODEC_OFFSET; 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_ci /* 928c2ecf20Sopenharmony_ci * 1. Write ACCAD = Command Address Register = 46Ch for AC97 register address 938c2ecf20Sopenharmony_ci * 2. Write ACCDA = Command Data Register = 470h for data to write to AC97 948c2ecf20Sopenharmony_ci * 3. Write ACCTL = Control Register = 460h for initiating the write7---55 958c2ecf20Sopenharmony_ci * 4. Read ACCTL = 460h, DCV should be reset by now and 460h = 17h 968c2ecf20Sopenharmony_ci * 5. if DCV not cleared, break and return error 978c2ecf20Sopenharmony_ci * 6. Read ACSTS = Status Register = 464h, check VSTS bit 988c2ecf20Sopenharmony_ci */ 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ci snd_cs46xx_peekBA0(chip, BA0_ACSDA + offset); 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_ci tmp = snd_cs46xx_peekBA0(chip, BA0_ACCTL); 1038c2ecf20Sopenharmony_ci if ((tmp & ACCTL_VFRM) == 0) { 1048c2ecf20Sopenharmony_ci dev_warn(chip->card->dev, "ACCTL_VFRM not set 0x%x\n", tmp); 1058c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_ACCTL, (tmp & (~ACCTL_ESYN)) | ACCTL_VFRM ); 1068c2ecf20Sopenharmony_ci msleep(50); 1078c2ecf20Sopenharmony_ci tmp = snd_cs46xx_peekBA0(chip, BA0_ACCTL + offset); 1088c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_ACCTL, tmp | ACCTL_ESYN | ACCTL_VFRM ); 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_ci } 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ci /* 1138c2ecf20Sopenharmony_ci * Setup the AC97 control registers on the CS461x to send the 1148c2ecf20Sopenharmony_ci * appropriate command to the AC97 to perform the read. 1158c2ecf20Sopenharmony_ci * ACCAD = Command Address Register = 46Ch 1168c2ecf20Sopenharmony_ci * ACCDA = Command Data Register = 470h 1178c2ecf20Sopenharmony_ci * ACCTL = Control Register = 460h 1188c2ecf20Sopenharmony_ci * set DCV - will clear when process completed 1198c2ecf20Sopenharmony_ci * set CRW - Read command 1208c2ecf20Sopenharmony_ci * set VFRM - valid frame enabled 1218c2ecf20Sopenharmony_ci * set ESYN - ASYNC generation enabled 1228c2ecf20Sopenharmony_ci * set RSTN - ARST# inactive, AC97 codec not reset 1238c2ecf20Sopenharmony_ci */ 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_ACCAD, reg); 1268c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_ACCDA, 0); 1278c2ecf20Sopenharmony_ci if (codec_index == CS46XX_PRIMARY_CODEC_INDEX) { 1288c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_ACCTL,/* clear ACCTL_DCV */ ACCTL_CRW | 1298c2ecf20Sopenharmony_ci ACCTL_VFRM | ACCTL_ESYN | 1308c2ecf20Sopenharmony_ci ACCTL_RSTN); 1318c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_ACCTL, ACCTL_DCV | ACCTL_CRW | 1328c2ecf20Sopenharmony_ci ACCTL_VFRM | ACCTL_ESYN | 1338c2ecf20Sopenharmony_ci ACCTL_RSTN); 1348c2ecf20Sopenharmony_ci } else { 1358c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_ACCTL, ACCTL_DCV | ACCTL_TC | 1368c2ecf20Sopenharmony_ci ACCTL_CRW | ACCTL_VFRM | ACCTL_ESYN | 1378c2ecf20Sopenharmony_ci ACCTL_RSTN); 1388c2ecf20Sopenharmony_ci } 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ci /* 1418c2ecf20Sopenharmony_ci * Wait for the read to occur. 1428c2ecf20Sopenharmony_ci */ 1438c2ecf20Sopenharmony_ci for (count = 0; count < 1000; count++) { 1448c2ecf20Sopenharmony_ci /* 1458c2ecf20Sopenharmony_ci * First, we want to wait for a short time. 1468c2ecf20Sopenharmony_ci */ 1478c2ecf20Sopenharmony_ci udelay(10); 1488c2ecf20Sopenharmony_ci /* 1498c2ecf20Sopenharmony_ci * Now, check to see if the read has completed. 1508c2ecf20Sopenharmony_ci * ACCTL = 460h, DCV should be reset by now and 460h = 17h 1518c2ecf20Sopenharmony_ci */ 1528c2ecf20Sopenharmony_ci if (!(snd_cs46xx_peekBA0(chip, BA0_ACCTL) & ACCTL_DCV)) 1538c2ecf20Sopenharmony_ci goto ok1; 1548c2ecf20Sopenharmony_ci } 1558c2ecf20Sopenharmony_ci 1568c2ecf20Sopenharmony_ci dev_err(chip->card->dev, 1578c2ecf20Sopenharmony_ci "AC'97 read problem (ACCTL_DCV), reg = 0x%x\n", reg); 1588c2ecf20Sopenharmony_ci result = 0xffff; 1598c2ecf20Sopenharmony_ci goto end; 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_ci ok1: 1628c2ecf20Sopenharmony_ci /* 1638c2ecf20Sopenharmony_ci * Wait for the valid status bit to go active. 1648c2ecf20Sopenharmony_ci */ 1658c2ecf20Sopenharmony_ci for (count = 0; count < 100; count++) { 1668c2ecf20Sopenharmony_ci /* 1678c2ecf20Sopenharmony_ci * Read the AC97 status register. 1688c2ecf20Sopenharmony_ci * ACSTS = Status Register = 464h 1698c2ecf20Sopenharmony_ci * VSTS - Valid Status 1708c2ecf20Sopenharmony_ci */ 1718c2ecf20Sopenharmony_ci if (snd_cs46xx_peekBA0(chip, BA0_ACSTS + offset) & ACSTS_VSTS) 1728c2ecf20Sopenharmony_ci goto ok2; 1738c2ecf20Sopenharmony_ci udelay(10); 1748c2ecf20Sopenharmony_ci } 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_ci dev_err(chip->card->dev, 1778c2ecf20Sopenharmony_ci "AC'97 read problem (ACSTS_VSTS), codec_index %d, reg = 0x%x\n", 1788c2ecf20Sopenharmony_ci codec_index, reg); 1798c2ecf20Sopenharmony_ci result = 0xffff; 1808c2ecf20Sopenharmony_ci goto end; 1818c2ecf20Sopenharmony_ci 1828c2ecf20Sopenharmony_ci ok2: 1838c2ecf20Sopenharmony_ci /* 1848c2ecf20Sopenharmony_ci * Read the data returned from the AC97 register. 1858c2ecf20Sopenharmony_ci * ACSDA = Status Data Register = 474h 1868c2ecf20Sopenharmony_ci */ 1878c2ecf20Sopenharmony_ci#if 0 1888c2ecf20Sopenharmony_ci dev_dbg(chip->card->dev, 1898c2ecf20Sopenharmony_ci "e) reg = 0x%x, val = 0x%x, BA0_ACCAD = 0x%x\n", reg, 1908c2ecf20Sopenharmony_ci snd_cs46xx_peekBA0(chip, BA0_ACSDA), 1918c2ecf20Sopenharmony_ci snd_cs46xx_peekBA0(chip, BA0_ACCAD)); 1928c2ecf20Sopenharmony_ci#endif 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_ci //snd_cs46xx_peekBA0(chip, BA0_ACCAD); 1958c2ecf20Sopenharmony_ci result = snd_cs46xx_peekBA0(chip, BA0_ACSDA + offset); 1968c2ecf20Sopenharmony_ci end: 1978c2ecf20Sopenharmony_ci chip->active_ctrl(chip, -1); 1988c2ecf20Sopenharmony_ci return result; 1998c2ecf20Sopenharmony_ci} 2008c2ecf20Sopenharmony_ci 2018c2ecf20Sopenharmony_cistatic unsigned short snd_cs46xx_ac97_read(struct snd_ac97 * ac97, 2028c2ecf20Sopenharmony_ci unsigned short reg) 2038c2ecf20Sopenharmony_ci{ 2048c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = ac97->private_data; 2058c2ecf20Sopenharmony_ci unsigned short val; 2068c2ecf20Sopenharmony_ci int codec_index = ac97->num; 2078c2ecf20Sopenharmony_ci 2088c2ecf20Sopenharmony_ci if (snd_BUG_ON(codec_index != CS46XX_PRIMARY_CODEC_INDEX && 2098c2ecf20Sopenharmony_ci codec_index != CS46XX_SECONDARY_CODEC_INDEX)) 2108c2ecf20Sopenharmony_ci return 0xffff; 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_ci val = snd_cs46xx_codec_read(chip, reg, codec_index); 2138c2ecf20Sopenharmony_ci 2148c2ecf20Sopenharmony_ci return val; 2158c2ecf20Sopenharmony_ci} 2168c2ecf20Sopenharmony_ci 2178c2ecf20Sopenharmony_ci 2188c2ecf20Sopenharmony_cistatic void snd_cs46xx_codec_write(struct snd_cs46xx *chip, 2198c2ecf20Sopenharmony_ci unsigned short reg, 2208c2ecf20Sopenharmony_ci unsigned short val, 2218c2ecf20Sopenharmony_ci int codec_index) 2228c2ecf20Sopenharmony_ci{ 2238c2ecf20Sopenharmony_ci int count; 2248c2ecf20Sopenharmony_ci 2258c2ecf20Sopenharmony_ci if (snd_BUG_ON(codec_index != CS46XX_PRIMARY_CODEC_INDEX && 2268c2ecf20Sopenharmony_ci codec_index != CS46XX_SECONDARY_CODEC_INDEX)) 2278c2ecf20Sopenharmony_ci return; 2288c2ecf20Sopenharmony_ci 2298c2ecf20Sopenharmony_ci chip->active_ctrl(chip, 1); 2308c2ecf20Sopenharmony_ci 2318c2ecf20Sopenharmony_ci /* 2328c2ecf20Sopenharmony_ci * 1. Write ACCAD = Command Address Register = 46Ch for AC97 register address 2338c2ecf20Sopenharmony_ci * 2. Write ACCDA = Command Data Register = 470h for data to write to AC97 2348c2ecf20Sopenharmony_ci * 3. Write ACCTL = Control Register = 460h for initiating the write 2358c2ecf20Sopenharmony_ci * 4. Read ACCTL = 460h, DCV should be reset by now and 460h = 07h 2368c2ecf20Sopenharmony_ci * 5. if DCV not cleared, break and return error 2378c2ecf20Sopenharmony_ci */ 2388c2ecf20Sopenharmony_ci 2398c2ecf20Sopenharmony_ci /* 2408c2ecf20Sopenharmony_ci * Setup the AC97 control registers on the CS461x to send the 2418c2ecf20Sopenharmony_ci * appropriate command to the AC97 to perform the read. 2428c2ecf20Sopenharmony_ci * ACCAD = Command Address Register = 46Ch 2438c2ecf20Sopenharmony_ci * ACCDA = Command Data Register = 470h 2448c2ecf20Sopenharmony_ci * ACCTL = Control Register = 460h 2458c2ecf20Sopenharmony_ci * set DCV - will clear when process completed 2468c2ecf20Sopenharmony_ci * reset CRW - Write command 2478c2ecf20Sopenharmony_ci * set VFRM - valid frame enabled 2488c2ecf20Sopenharmony_ci * set ESYN - ASYNC generation enabled 2498c2ecf20Sopenharmony_ci * set RSTN - ARST# inactive, AC97 codec not reset 2508c2ecf20Sopenharmony_ci */ 2518c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_ACCAD , reg); 2528c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_ACCDA , val); 2538c2ecf20Sopenharmony_ci snd_cs46xx_peekBA0(chip, BA0_ACCTL); 2548c2ecf20Sopenharmony_ci 2558c2ecf20Sopenharmony_ci if (codec_index == CS46XX_PRIMARY_CODEC_INDEX) { 2568c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_ACCTL, /* clear ACCTL_DCV */ ACCTL_VFRM | 2578c2ecf20Sopenharmony_ci ACCTL_ESYN | ACCTL_RSTN); 2588c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_ACCTL, ACCTL_DCV | ACCTL_VFRM | 2598c2ecf20Sopenharmony_ci ACCTL_ESYN | ACCTL_RSTN); 2608c2ecf20Sopenharmony_ci } else { 2618c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_ACCTL, ACCTL_DCV | ACCTL_TC | 2628c2ecf20Sopenharmony_ci ACCTL_VFRM | ACCTL_ESYN | ACCTL_RSTN); 2638c2ecf20Sopenharmony_ci } 2648c2ecf20Sopenharmony_ci 2658c2ecf20Sopenharmony_ci for (count = 0; count < 4000; count++) { 2668c2ecf20Sopenharmony_ci /* 2678c2ecf20Sopenharmony_ci * First, we want to wait for a short time. 2688c2ecf20Sopenharmony_ci */ 2698c2ecf20Sopenharmony_ci udelay(10); 2708c2ecf20Sopenharmony_ci /* 2718c2ecf20Sopenharmony_ci * Now, check to see if the write has completed. 2728c2ecf20Sopenharmony_ci * ACCTL = 460h, DCV should be reset by now and 460h = 07h 2738c2ecf20Sopenharmony_ci */ 2748c2ecf20Sopenharmony_ci if (!(snd_cs46xx_peekBA0(chip, BA0_ACCTL) & ACCTL_DCV)) { 2758c2ecf20Sopenharmony_ci goto end; 2768c2ecf20Sopenharmony_ci } 2778c2ecf20Sopenharmony_ci } 2788c2ecf20Sopenharmony_ci dev_err(chip->card->dev, 2798c2ecf20Sopenharmony_ci "AC'97 write problem, codec_index = %d, reg = 0x%x, val = 0x%x\n", 2808c2ecf20Sopenharmony_ci codec_index, reg, val); 2818c2ecf20Sopenharmony_ci end: 2828c2ecf20Sopenharmony_ci chip->active_ctrl(chip, -1); 2838c2ecf20Sopenharmony_ci} 2848c2ecf20Sopenharmony_ci 2858c2ecf20Sopenharmony_cistatic void snd_cs46xx_ac97_write(struct snd_ac97 *ac97, 2868c2ecf20Sopenharmony_ci unsigned short reg, 2878c2ecf20Sopenharmony_ci unsigned short val) 2888c2ecf20Sopenharmony_ci{ 2898c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = ac97->private_data; 2908c2ecf20Sopenharmony_ci int codec_index = ac97->num; 2918c2ecf20Sopenharmony_ci 2928c2ecf20Sopenharmony_ci if (snd_BUG_ON(codec_index != CS46XX_PRIMARY_CODEC_INDEX && 2938c2ecf20Sopenharmony_ci codec_index != CS46XX_SECONDARY_CODEC_INDEX)) 2948c2ecf20Sopenharmony_ci return; 2958c2ecf20Sopenharmony_ci 2968c2ecf20Sopenharmony_ci snd_cs46xx_codec_write(chip, reg, val, codec_index); 2978c2ecf20Sopenharmony_ci} 2988c2ecf20Sopenharmony_ci 2998c2ecf20Sopenharmony_ci 3008c2ecf20Sopenharmony_ci/* 3018c2ecf20Sopenharmony_ci * Chip initialization 3028c2ecf20Sopenharmony_ci */ 3038c2ecf20Sopenharmony_ci 3048c2ecf20Sopenharmony_ciint snd_cs46xx_download(struct snd_cs46xx *chip, 3058c2ecf20Sopenharmony_ci u32 *src, 3068c2ecf20Sopenharmony_ci unsigned long offset, 3078c2ecf20Sopenharmony_ci unsigned long len) 3088c2ecf20Sopenharmony_ci{ 3098c2ecf20Sopenharmony_ci void __iomem *dst; 3108c2ecf20Sopenharmony_ci unsigned int bank = offset >> 16; 3118c2ecf20Sopenharmony_ci offset = offset & 0xffff; 3128c2ecf20Sopenharmony_ci 3138c2ecf20Sopenharmony_ci if (snd_BUG_ON((offset & 3) || (len & 3))) 3148c2ecf20Sopenharmony_ci return -EINVAL; 3158c2ecf20Sopenharmony_ci dst = chip->region.idx[bank+1].remap_addr + offset; 3168c2ecf20Sopenharmony_ci len /= sizeof(u32); 3178c2ecf20Sopenharmony_ci 3188c2ecf20Sopenharmony_ci /* writel already converts 32-bit value to right endianess */ 3198c2ecf20Sopenharmony_ci while (len-- > 0) { 3208c2ecf20Sopenharmony_ci writel(*src++, dst); 3218c2ecf20Sopenharmony_ci dst += sizeof(u32); 3228c2ecf20Sopenharmony_ci } 3238c2ecf20Sopenharmony_ci return 0; 3248c2ecf20Sopenharmony_ci} 3258c2ecf20Sopenharmony_ci 3268c2ecf20Sopenharmony_cistatic inline void memcpy_le32(void *dst, const void *src, unsigned int len) 3278c2ecf20Sopenharmony_ci{ 3288c2ecf20Sopenharmony_ci#ifdef __LITTLE_ENDIAN 3298c2ecf20Sopenharmony_ci memcpy(dst, src, len); 3308c2ecf20Sopenharmony_ci#else 3318c2ecf20Sopenharmony_ci u32 *_dst = dst; 3328c2ecf20Sopenharmony_ci const __le32 *_src = src; 3338c2ecf20Sopenharmony_ci len /= 4; 3348c2ecf20Sopenharmony_ci while (len-- > 0) 3358c2ecf20Sopenharmony_ci *_dst++ = le32_to_cpu(*_src++); 3368c2ecf20Sopenharmony_ci#endif 3378c2ecf20Sopenharmony_ci} 3388c2ecf20Sopenharmony_ci 3398c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 3408c2ecf20Sopenharmony_ci 3418c2ecf20Sopenharmony_cistatic const char *module_names[CS46XX_DSP_MODULES] = { 3428c2ecf20Sopenharmony_ci "cwc4630", "cwcasync", "cwcsnoop", "cwcbinhack", "cwcdma" 3438c2ecf20Sopenharmony_ci}; 3448c2ecf20Sopenharmony_ci 3458c2ecf20Sopenharmony_ciMODULE_FIRMWARE("cs46xx/cwc4630"); 3468c2ecf20Sopenharmony_ciMODULE_FIRMWARE("cs46xx/cwcasync"); 3478c2ecf20Sopenharmony_ciMODULE_FIRMWARE("cs46xx/cwcsnoop"); 3488c2ecf20Sopenharmony_ciMODULE_FIRMWARE("cs46xx/cwcbinhack"); 3498c2ecf20Sopenharmony_ciMODULE_FIRMWARE("cs46xx/cwcdma"); 3508c2ecf20Sopenharmony_ci 3518c2ecf20Sopenharmony_cistatic void free_module_desc(struct dsp_module_desc *module) 3528c2ecf20Sopenharmony_ci{ 3538c2ecf20Sopenharmony_ci if (!module) 3548c2ecf20Sopenharmony_ci return; 3558c2ecf20Sopenharmony_ci kfree(module->module_name); 3568c2ecf20Sopenharmony_ci kfree(module->symbol_table.symbols); 3578c2ecf20Sopenharmony_ci if (module->segments) { 3588c2ecf20Sopenharmony_ci int i; 3598c2ecf20Sopenharmony_ci for (i = 0; i < module->nsegments; i++) 3608c2ecf20Sopenharmony_ci kfree(module->segments[i].data); 3618c2ecf20Sopenharmony_ci kfree(module->segments); 3628c2ecf20Sopenharmony_ci } 3638c2ecf20Sopenharmony_ci kfree(module); 3648c2ecf20Sopenharmony_ci} 3658c2ecf20Sopenharmony_ci 3668c2ecf20Sopenharmony_ci/* firmware binary format: 3678c2ecf20Sopenharmony_ci * le32 nsymbols; 3688c2ecf20Sopenharmony_ci * struct { 3698c2ecf20Sopenharmony_ci * le32 address; 3708c2ecf20Sopenharmony_ci * char symbol_name[DSP_MAX_SYMBOL_NAME]; 3718c2ecf20Sopenharmony_ci * le32 symbol_type; 3728c2ecf20Sopenharmony_ci * } symbols[nsymbols]; 3738c2ecf20Sopenharmony_ci * le32 nsegments; 3748c2ecf20Sopenharmony_ci * struct { 3758c2ecf20Sopenharmony_ci * le32 segment_type; 3768c2ecf20Sopenharmony_ci * le32 offset; 3778c2ecf20Sopenharmony_ci * le32 size; 3788c2ecf20Sopenharmony_ci * le32 data[size]; 3798c2ecf20Sopenharmony_ci * } segments[nsegments]; 3808c2ecf20Sopenharmony_ci */ 3818c2ecf20Sopenharmony_ci 3828c2ecf20Sopenharmony_cistatic int load_firmware(struct snd_cs46xx *chip, 3838c2ecf20Sopenharmony_ci struct dsp_module_desc **module_ret, 3848c2ecf20Sopenharmony_ci const char *fw_name) 3858c2ecf20Sopenharmony_ci{ 3868c2ecf20Sopenharmony_ci int i, err; 3878c2ecf20Sopenharmony_ci unsigned int nums, fwlen, fwsize; 3888c2ecf20Sopenharmony_ci const __le32 *fwdat; 3898c2ecf20Sopenharmony_ci struct dsp_module_desc *module = NULL; 3908c2ecf20Sopenharmony_ci const struct firmware *fw; 3918c2ecf20Sopenharmony_ci char fw_path[32]; 3928c2ecf20Sopenharmony_ci 3938c2ecf20Sopenharmony_ci sprintf(fw_path, "cs46xx/%s", fw_name); 3948c2ecf20Sopenharmony_ci err = request_firmware(&fw, fw_path, &chip->pci->dev); 3958c2ecf20Sopenharmony_ci if (err < 0) 3968c2ecf20Sopenharmony_ci return err; 3978c2ecf20Sopenharmony_ci fwsize = fw->size / 4; 3988c2ecf20Sopenharmony_ci if (fwsize < 2) { 3998c2ecf20Sopenharmony_ci err = -EINVAL; 4008c2ecf20Sopenharmony_ci goto error; 4018c2ecf20Sopenharmony_ci } 4028c2ecf20Sopenharmony_ci 4038c2ecf20Sopenharmony_ci err = -ENOMEM; 4048c2ecf20Sopenharmony_ci module = kzalloc(sizeof(*module), GFP_KERNEL); 4058c2ecf20Sopenharmony_ci if (!module) 4068c2ecf20Sopenharmony_ci goto error; 4078c2ecf20Sopenharmony_ci module->module_name = kstrdup(fw_name, GFP_KERNEL); 4088c2ecf20Sopenharmony_ci if (!module->module_name) 4098c2ecf20Sopenharmony_ci goto error; 4108c2ecf20Sopenharmony_ci 4118c2ecf20Sopenharmony_ci fwlen = 0; 4128c2ecf20Sopenharmony_ci fwdat = (const __le32 *)fw->data; 4138c2ecf20Sopenharmony_ci nums = module->symbol_table.nsymbols = le32_to_cpu(fwdat[fwlen++]); 4148c2ecf20Sopenharmony_ci if (nums >= 40) 4158c2ecf20Sopenharmony_ci goto error_inval; 4168c2ecf20Sopenharmony_ci module->symbol_table.symbols = 4178c2ecf20Sopenharmony_ci kcalloc(nums, sizeof(struct dsp_symbol_entry), GFP_KERNEL); 4188c2ecf20Sopenharmony_ci if (!module->symbol_table.symbols) 4198c2ecf20Sopenharmony_ci goto error; 4208c2ecf20Sopenharmony_ci for (i = 0; i < nums; i++) { 4218c2ecf20Sopenharmony_ci struct dsp_symbol_entry *entry = 4228c2ecf20Sopenharmony_ci &module->symbol_table.symbols[i]; 4238c2ecf20Sopenharmony_ci if (fwlen + 2 + DSP_MAX_SYMBOL_NAME / 4 > fwsize) 4248c2ecf20Sopenharmony_ci goto error_inval; 4258c2ecf20Sopenharmony_ci entry->address = le32_to_cpu(fwdat[fwlen++]); 4268c2ecf20Sopenharmony_ci memcpy(entry->symbol_name, &fwdat[fwlen], DSP_MAX_SYMBOL_NAME - 1); 4278c2ecf20Sopenharmony_ci fwlen += DSP_MAX_SYMBOL_NAME / 4; 4288c2ecf20Sopenharmony_ci entry->symbol_type = le32_to_cpu(fwdat[fwlen++]); 4298c2ecf20Sopenharmony_ci } 4308c2ecf20Sopenharmony_ci 4318c2ecf20Sopenharmony_ci if (fwlen >= fwsize) 4328c2ecf20Sopenharmony_ci goto error_inval; 4338c2ecf20Sopenharmony_ci nums = module->nsegments = le32_to_cpu(fwdat[fwlen++]); 4348c2ecf20Sopenharmony_ci if (nums > 10) 4358c2ecf20Sopenharmony_ci goto error_inval; 4368c2ecf20Sopenharmony_ci module->segments = 4378c2ecf20Sopenharmony_ci kcalloc(nums, sizeof(struct dsp_segment_desc), GFP_KERNEL); 4388c2ecf20Sopenharmony_ci if (!module->segments) 4398c2ecf20Sopenharmony_ci goto error; 4408c2ecf20Sopenharmony_ci for (i = 0; i < nums; i++) { 4418c2ecf20Sopenharmony_ci struct dsp_segment_desc *entry = &module->segments[i]; 4428c2ecf20Sopenharmony_ci if (fwlen + 3 > fwsize) 4438c2ecf20Sopenharmony_ci goto error_inval; 4448c2ecf20Sopenharmony_ci entry->segment_type = le32_to_cpu(fwdat[fwlen++]); 4458c2ecf20Sopenharmony_ci entry->offset = le32_to_cpu(fwdat[fwlen++]); 4468c2ecf20Sopenharmony_ci entry->size = le32_to_cpu(fwdat[fwlen++]); 4478c2ecf20Sopenharmony_ci if (fwlen + entry->size > fwsize) 4488c2ecf20Sopenharmony_ci goto error_inval; 4498c2ecf20Sopenharmony_ci entry->data = kmalloc_array(entry->size, 4, GFP_KERNEL); 4508c2ecf20Sopenharmony_ci if (!entry->data) 4518c2ecf20Sopenharmony_ci goto error; 4528c2ecf20Sopenharmony_ci memcpy_le32(entry->data, &fwdat[fwlen], entry->size * 4); 4538c2ecf20Sopenharmony_ci fwlen += entry->size; 4548c2ecf20Sopenharmony_ci } 4558c2ecf20Sopenharmony_ci 4568c2ecf20Sopenharmony_ci *module_ret = module; 4578c2ecf20Sopenharmony_ci release_firmware(fw); 4588c2ecf20Sopenharmony_ci return 0; 4598c2ecf20Sopenharmony_ci 4608c2ecf20Sopenharmony_ci error_inval: 4618c2ecf20Sopenharmony_ci err = -EINVAL; 4628c2ecf20Sopenharmony_ci error: 4638c2ecf20Sopenharmony_ci free_module_desc(module); 4648c2ecf20Sopenharmony_ci release_firmware(fw); 4658c2ecf20Sopenharmony_ci return err; 4668c2ecf20Sopenharmony_ci} 4678c2ecf20Sopenharmony_ci 4688c2ecf20Sopenharmony_ciint snd_cs46xx_clear_BA1(struct snd_cs46xx *chip, 4698c2ecf20Sopenharmony_ci unsigned long offset, 4708c2ecf20Sopenharmony_ci unsigned long len) 4718c2ecf20Sopenharmony_ci{ 4728c2ecf20Sopenharmony_ci void __iomem *dst; 4738c2ecf20Sopenharmony_ci unsigned int bank = offset >> 16; 4748c2ecf20Sopenharmony_ci offset = offset & 0xffff; 4758c2ecf20Sopenharmony_ci 4768c2ecf20Sopenharmony_ci if (snd_BUG_ON((offset & 3) || (len & 3))) 4778c2ecf20Sopenharmony_ci return -EINVAL; 4788c2ecf20Sopenharmony_ci dst = chip->region.idx[bank+1].remap_addr + offset; 4798c2ecf20Sopenharmony_ci len /= sizeof(u32); 4808c2ecf20Sopenharmony_ci 4818c2ecf20Sopenharmony_ci /* writel already converts 32-bit value to right endianess */ 4828c2ecf20Sopenharmony_ci while (len-- > 0) { 4838c2ecf20Sopenharmony_ci writel(0, dst); 4848c2ecf20Sopenharmony_ci dst += sizeof(u32); 4858c2ecf20Sopenharmony_ci } 4868c2ecf20Sopenharmony_ci return 0; 4878c2ecf20Sopenharmony_ci} 4888c2ecf20Sopenharmony_ci 4898c2ecf20Sopenharmony_ci#else /* old DSP image */ 4908c2ecf20Sopenharmony_ci 4918c2ecf20Sopenharmony_cistruct ba1_struct { 4928c2ecf20Sopenharmony_ci struct { 4938c2ecf20Sopenharmony_ci u32 offset; 4948c2ecf20Sopenharmony_ci u32 size; 4958c2ecf20Sopenharmony_ci } memory[BA1_MEMORY_COUNT]; 4968c2ecf20Sopenharmony_ci u32 map[BA1_DWORD_SIZE]; 4978c2ecf20Sopenharmony_ci}; 4988c2ecf20Sopenharmony_ci 4998c2ecf20Sopenharmony_ciMODULE_FIRMWARE("cs46xx/ba1"); 5008c2ecf20Sopenharmony_ci 5018c2ecf20Sopenharmony_cistatic int load_firmware(struct snd_cs46xx *chip) 5028c2ecf20Sopenharmony_ci{ 5038c2ecf20Sopenharmony_ci const struct firmware *fw; 5048c2ecf20Sopenharmony_ci int i, size, err; 5058c2ecf20Sopenharmony_ci 5068c2ecf20Sopenharmony_ci err = request_firmware(&fw, "cs46xx/ba1", &chip->pci->dev); 5078c2ecf20Sopenharmony_ci if (err < 0) 5088c2ecf20Sopenharmony_ci return err; 5098c2ecf20Sopenharmony_ci if (fw->size != sizeof(*chip->ba1)) { 5108c2ecf20Sopenharmony_ci err = -EINVAL; 5118c2ecf20Sopenharmony_ci goto error; 5128c2ecf20Sopenharmony_ci } 5138c2ecf20Sopenharmony_ci 5148c2ecf20Sopenharmony_ci chip->ba1 = vmalloc(sizeof(*chip->ba1)); 5158c2ecf20Sopenharmony_ci if (!chip->ba1) { 5168c2ecf20Sopenharmony_ci err = -ENOMEM; 5178c2ecf20Sopenharmony_ci goto error; 5188c2ecf20Sopenharmony_ci } 5198c2ecf20Sopenharmony_ci 5208c2ecf20Sopenharmony_ci memcpy_le32(chip->ba1, fw->data, sizeof(*chip->ba1)); 5218c2ecf20Sopenharmony_ci 5228c2ecf20Sopenharmony_ci /* sanity check */ 5238c2ecf20Sopenharmony_ci size = 0; 5248c2ecf20Sopenharmony_ci for (i = 0; i < BA1_MEMORY_COUNT; i++) 5258c2ecf20Sopenharmony_ci size += chip->ba1->memory[i].size; 5268c2ecf20Sopenharmony_ci if (size > BA1_DWORD_SIZE * 4) 5278c2ecf20Sopenharmony_ci err = -EINVAL; 5288c2ecf20Sopenharmony_ci 5298c2ecf20Sopenharmony_ci error: 5308c2ecf20Sopenharmony_ci release_firmware(fw); 5318c2ecf20Sopenharmony_ci return err; 5328c2ecf20Sopenharmony_ci} 5338c2ecf20Sopenharmony_ci 5348c2ecf20Sopenharmony_ciint snd_cs46xx_download_image(struct snd_cs46xx *chip) 5358c2ecf20Sopenharmony_ci{ 5368c2ecf20Sopenharmony_ci int idx, err; 5378c2ecf20Sopenharmony_ci unsigned int offset = 0; 5388c2ecf20Sopenharmony_ci struct ba1_struct *ba1 = chip->ba1; 5398c2ecf20Sopenharmony_ci 5408c2ecf20Sopenharmony_ci for (idx = 0; idx < BA1_MEMORY_COUNT; idx++) { 5418c2ecf20Sopenharmony_ci err = snd_cs46xx_download(chip, 5428c2ecf20Sopenharmony_ci &ba1->map[offset], 5438c2ecf20Sopenharmony_ci ba1->memory[idx].offset, 5448c2ecf20Sopenharmony_ci ba1->memory[idx].size); 5458c2ecf20Sopenharmony_ci if (err < 0) 5468c2ecf20Sopenharmony_ci return err; 5478c2ecf20Sopenharmony_ci offset += ba1->memory[idx].size >> 2; 5488c2ecf20Sopenharmony_ci } 5498c2ecf20Sopenharmony_ci return 0; 5508c2ecf20Sopenharmony_ci} 5518c2ecf20Sopenharmony_ci#endif /* CONFIG_SND_CS46XX_NEW_DSP */ 5528c2ecf20Sopenharmony_ci 5538c2ecf20Sopenharmony_ci/* 5548c2ecf20Sopenharmony_ci * Chip reset 5558c2ecf20Sopenharmony_ci */ 5568c2ecf20Sopenharmony_ci 5578c2ecf20Sopenharmony_cistatic void snd_cs46xx_reset(struct snd_cs46xx *chip) 5588c2ecf20Sopenharmony_ci{ 5598c2ecf20Sopenharmony_ci int idx; 5608c2ecf20Sopenharmony_ci 5618c2ecf20Sopenharmony_ci /* 5628c2ecf20Sopenharmony_ci * Write the reset bit of the SP control register. 5638c2ecf20Sopenharmony_ci */ 5648c2ecf20Sopenharmony_ci snd_cs46xx_poke(chip, BA1_SPCR, SPCR_RSTSP); 5658c2ecf20Sopenharmony_ci 5668c2ecf20Sopenharmony_ci /* 5678c2ecf20Sopenharmony_ci * Write the control register. 5688c2ecf20Sopenharmony_ci */ 5698c2ecf20Sopenharmony_ci snd_cs46xx_poke(chip, BA1_SPCR, SPCR_DRQEN); 5708c2ecf20Sopenharmony_ci 5718c2ecf20Sopenharmony_ci /* 5728c2ecf20Sopenharmony_ci * Clear the trap registers. 5738c2ecf20Sopenharmony_ci */ 5748c2ecf20Sopenharmony_ci for (idx = 0; idx < 8; idx++) { 5758c2ecf20Sopenharmony_ci snd_cs46xx_poke(chip, BA1_DREG, DREG_REGID_TRAP_SELECT + idx); 5768c2ecf20Sopenharmony_ci snd_cs46xx_poke(chip, BA1_TWPR, 0xFFFF); 5778c2ecf20Sopenharmony_ci } 5788c2ecf20Sopenharmony_ci snd_cs46xx_poke(chip, BA1_DREG, 0); 5798c2ecf20Sopenharmony_ci 5808c2ecf20Sopenharmony_ci /* 5818c2ecf20Sopenharmony_ci * Set the frame timer to reflect the number of cycles per frame. 5828c2ecf20Sopenharmony_ci */ 5838c2ecf20Sopenharmony_ci snd_cs46xx_poke(chip, BA1_FRMT, 0xadf); 5848c2ecf20Sopenharmony_ci} 5858c2ecf20Sopenharmony_ci 5868c2ecf20Sopenharmony_cistatic int cs46xx_wait_for_fifo(struct snd_cs46xx * chip,int retry_timeout) 5878c2ecf20Sopenharmony_ci{ 5888c2ecf20Sopenharmony_ci u32 i, status = 0; 5898c2ecf20Sopenharmony_ci /* 5908c2ecf20Sopenharmony_ci * Make sure the previous FIFO write operation has completed. 5918c2ecf20Sopenharmony_ci */ 5928c2ecf20Sopenharmony_ci for(i = 0; i < 50; i++){ 5938c2ecf20Sopenharmony_ci status = snd_cs46xx_peekBA0(chip, BA0_SERBST); 5948c2ecf20Sopenharmony_ci 5958c2ecf20Sopenharmony_ci if( !(status & SERBST_WBSY) ) 5968c2ecf20Sopenharmony_ci break; 5978c2ecf20Sopenharmony_ci 5988c2ecf20Sopenharmony_ci mdelay(retry_timeout); 5998c2ecf20Sopenharmony_ci } 6008c2ecf20Sopenharmony_ci 6018c2ecf20Sopenharmony_ci if(status & SERBST_WBSY) { 6028c2ecf20Sopenharmony_ci dev_err(chip->card->dev, 6038c2ecf20Sopenharmony_ci "failure waiting for FIFO command to complete\n"); 6048c2ecf20Sopenharmony_ci return -EINVAL; 6058c2ecf20Sopenharmony_ci } 6068c2ecf20Sopenharmony_ci 6078c2ecf20Sopenharmony_ci return 0; 6088c2ecf20Sopenharmony_ci} 6098c2ecf20Sopenharmony_ci 6108c2ecf20Sopenharmony_cistatic void snd_cs46xx_clear_serial_FIFOs(struct snd_cs46xx *chip) 6118c2ecf20Sopenharmony_ci{ 6128c2ecf20Sopenharmony_ci int idx, powerdown = 0; 6138c2ecf20Sopenharmony_ci unsigned int tmp; 6148c2ecf20Sopenharmony_ci 6158c2ecf20Sopenharmony_ci /* 6168c2ecf20Sopenharmony_ci * See if the devices are powered down. If so, we must power them up first 6178c2ecf20Sopenharmony_ci * or they will not respond. 6188c2ecf20Sopenharmony_ci */ 6198c2ecf20Sopenharmony_ci tmp = snd_cs46xx_peekBA0(chip, BA0_CLKCR1); 6208c2ecf20Sopenharmony_ci if (!(tmp & CLKCR1_SWCE)) { 6218c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_CLKCR1, tmp | CLKCR1_SWCE); 6228c2ecf20Sopenharmony_ci powerdown = 1; 6238c2ecf20Sopenharmony_ci } 6248c2ecf20Sopenharmony_ci 6258c2ecf20Sopenharmony_ci /* 6268c2ecf20Sopenharmony_ci * We want to clear out the serial port FIFOs so we don't end up playing 6278c2ecf20Sopenharmony_ci * whatever random garbage happens to be in them. We fill the sample FIFOS 6288c2ecf20Sopenharmony_ci * with zero (silence). 6298c2ecf20Sopenharmony_ci */ 6308c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_SERBWP, 0); 6318c2ecf20Sopenharmony_ci 6328c2ecf20Sopenharmony_ci /* 6338c2ecf20Sopenharmony_ci * Fill all 256 sample FIFO locations. 6348c2ecf20Sopenharmony_ci */ 6358c2ecf20Sopenharmony_ci for (idx = 0; idx < 0xFF; idx++) { 6368c2ecf20Sopenharmony_ci /* 6378c2ecf20Sopenharmony_ci * Make sure the previous FIFO write operation has completed. 6388c2ecf20Sopenharmony_ci */ 6398c2ecf20Sopenharmony_ci if (cs46xx_wait_for_fifo(chip,1)) { 6408c2ecf20Sopenharmony_ci dev_dbg(chip->card->dev, 6418c2ecf20Sopenharmony_ci "failed waiting for FIFO at addr (%02X)\n", 6428c2ecf20Sopenharmony_ci idx); 6438c2ecf20Sopenharmony_ci 6448c2ecf20Sopenharmony_ci if (powerdown) 6458c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_CLKCR1, tmp); 6468c2ecf20Sopenharmony_ci 6478c2ecf20Sopenharmony_ci break; 6488c2ecf20Sopenharmony_ci } 6498c2ecf20Sopenharmony_ci /* 6508c2ecf20Sopenharmony_ci * Write the serial port FIFO index. 6518c2ecf20Sopenharmony_ci */ 6528c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_SERBAD, idx); 6538c2ecf20Sopenharmony_ci /* 6548c2ecf20Sopenharmony_ci * Tell the serial port to load the new value into the FIFO location. 6558c2ecf20Sopenharmony_ci */ 6568c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_SERBCM, SERBCM_WRC); 6578c2ecf20Sopenharmony_ci } 6588c2ecf20Sopenharmony_ci /* 6598c2ecf20Sopenharmony_ci * Now, if we powered up the devices, then power them back down again. 6608c2ecf20Sopenharmony_ci * This is kinda ugly, but should never happen. 6618c2ecf20Sopenharmony_ci */ 6628c2ecf20Sopenharmony_ci if (powerdown) 6638c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_CLKCR1, tmp); 6648c2ecf20Sopenharmony_ci} 6658c2ecf20Sopenharmony_ci 6668c2ecf20Sopenharmony_cistatic void snd_cs46xx_proc_start(struct snd_cs46xx *chip) 6678c2ecf20Sopenharmony_ci{ 6688c2ecf20Sopenharmony_ci int cnt; 6698c2ecf20Sopenharmony_ci 6708c2ecf20Sopenharmony_ci /* 6718c2ecf20Sopenharmony_ci * Set the frame timer to reflect the number of cycles per frame. 6728c2ecf20Sopenharmony_ci */ 6738c2ecf20Sopenharmony_ci snd_cs46xx_poke(chip, BA1_FRMT, 0xadf); 6748c2ecf20Sopenharmony_ci /* 6758c2ecf20Sopenharmony_ci * Turn on the run, run at frame, and DMA enable bits in the local copy of 6768c2ecf20Sopenharmony_ci * the SP control register. 6778c2ecf20Sopenharmony_ci */ 6788c2ecf20Sopenharmony_ci snd_cs46xx_poke(chip, BA1_SPCR, SPCR_RUN | SPCR_RUNFR | SPCR_DRQEN); 6798c2ecf20Sopenharmony_ci /* 6808c2ecf20Sopenharmony_ci * Wait until the run at frame bit resets itself in the SP control 6818c2ecf20Sopenharmony_ci * register. 6828c2ecf20Sopenharmony_ci */ 6838c2ecf20Sopenharmony_ci for (cnt = 0; cnt < 25; cnt++) { 6848c2ecf20Sopenharmony_ci udelay(50); 6858c2ecf20Sopenharmony_ci if (!(snd_cs46xx_peek(chip, BA1_SPCR) & SPCR_RUNFR)) 6868c2ecf20Sopenharmony_ci break; 6878c2ecf20Sopenharmony_ci } 6888c2ecf20Sopenharmony_ci 6898c2ecf20Sopenharmony_ci if (snd_cs46xx_peek(chip, BA1_SPCR) & SPCR_RUNFR) 6908c2ecf20Sopenharmony_ci dev_err(chip->card->dev, "SPCR_RUNFR never reset\n"); 6918c2ecf20Sopenharmony_ci} 6928c2ecf20Sopenharmony_ci 6938c2ecf20Sopenharmony_cistatic void snd_cs46xx_proc_stop(struct snd_cs46xx *chip) 6948c2ecf20Sopenharmony_ci{ 6958c2ecf20Sopenharmony_ci /* 6968c2ecf20Sopenharmony_ci * Turn off the run, run at frame, and DMA enable bits in the local copy of 6978c2ecf20Sopenharmony_ci * the SP control register. 6988c2ecf20Sopenharmony_ci */ 6998c2ecf20Sopenharmony_ci snd_cs46xx_poke(chip, BA1_SPCR, 0); 7008c2ecf20Sopenharmony_ci} 7018c2ecf20Sopenharmony_ci 7028c2ecf20Sopenharmony_ci/* 7038c2ecf20Sopenharmony_ci * Sample rate routines 7048c2ecf20Sopenharmony_ci */ 7058c2ecf20Sopenharmony_ci 7068c2ecf20Sopenharmony_ci#define GOF_PER_SEC 200 7078c2ecf20Sopenharmony_ci 7088c2ecf20Sopenharmony_cistatic void snd_cs46xx_set_play_sample_rate(struct snd_cs46xx *chip, unsigned int rate) 7098c2ecf20Sopenharmony_ci{ 7108c2ecf20Sopenharmony_ci unsigned long flags; 7118c2ecf20Sopenharmony_ci unsigned int tmp1, tmp2; 7128c2ecf20Sopenharmony_ci unsigned int phiIncr; 7138c2ecf20Sopenharmony_ci unsigned int correctionPerGOF, correctionPerSec; 7148c2ecf20Sopenharmony_ci 7158c2ecf20Sopenharmony_ci /* 7168c2ecf20Sopenharmony_ci * Compute the values used to drive the actual sample rate conversion. 7178c2ecf20Sopenharmony_ci * The following formulas are being computed, using inline assembly 7188c2ecf20Sopenharmony_ci * since we need to use 64 bit arithmetic to compute the values: 7198c2ecf20Sopenharmony_ci * 7208c2ecf20Sopenharmony_ci * phiIncr = floor((Fs,in * 2^26) / Fs,out) 7218c2ecf20Sopenharmony_ci * correctionPerGOF = floor((Fs,in * 2^26 - Fs,out * phiIncr) / 7228c2ecf20Sopenharmony_ci * GOF_PER_SEC) 7238c2ecf20Sopenharmony_ci * ulCorrectionPerSec = Fs,in * 2^26 - Fs,out * phiIncr -M 7248c2ecf20Sopenharmony_ci * GOF_PER_SEC * correctionPerGOF 7258c2ecf20Sopenharmony_ci * 7268c2ecf20Sopenharmony_ci * i.e. 7278c2ecf20Sopenharmony_ci * 7288c2ecf20Sopenharmony_ci * phiIncr:other = dividend:remainder((Fs,in * 2^26) / Fs,out) 7298c2ecf20Sopenharmony_ci * correctionPerGOF:correctionPerSec = 7308c2ecf20Sopenharmony_ci * dividend:remainder(ulOther / GOF_PER_SEC) 7318c2ecf20Sopenharmony_ci */ 7328c2ecf20Sopenharmony_ci tmp1 = rate << 16; 7338c2ecf20Sopenharmony_ci phiIncr = tmp1 / 48000; 7348c2ecf20Sopenharmony_ci tmp1 -= phiIncr * 48000; 7358c2ecf20Sopenharmony_ci tmp1 <<= 10; 7368c2ecf20Sopenharmony_ci phiIncr <<= 10; 7378c2ecf20Sopenharmony_ci tmp2 = tmp1 / 48000; 7388c2ecf20Sopenharmony_ci phiIncr += tmp2; 7398c2ecf20Sopenharmony_ci tmp1 -= tmp2 * 48000; 7408c2ecf20Sopenharmony_ci correctionPerGOF = tmp1 / GOF_PER_SEC; 7418c2ecf20Sopenharmony_ci tmp1 -= correctionPerGOF * GOF_PER_SEC; 7428c2ecf20Sopenharmony_ci correctionPerSec = tmp1; 7438c2ecf20Sopenharmony_ci 7448c2ecf20Sopenharmony_ci /* 7458c2ecf20Sopenharmony_ci * Fill in the SampleRateConverter control block. 7468c2ecf20Sopenharmony_ci */ 7478c2ecf20Sopenharmony_ci spin_lock_irqsave(&chip->reg_lock, flags); 7488c2ecf20Sopenharmony_ci snd_cs46xx_poke(chip, BA1_PSRC, 7498c2ecf20Sopenharmony_ci ((correctionPerSec << 16) & 0xFFFF0000) | (correctionPerGOF & 0xFFFF)); 7508c2ecf20Sopenharmony_ci snd_cs46xx_poke(chip, BA1_PPI, phiIncr); 7518c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&chip->reg_lock, flags); 7528c2ecf20Sopenharmony_ci} 7538c2ecf20Sopenharmony_ci 7548c2ecf20Sopenharmony_cistatic void snd_cs46xx_set_capture_sample_rate(struct snd_cs46xx *chip, unsigned int rate) 7558c2ecf20Sopenharmony_ci{ 7568c2ecf20Sopenharmony_ci unsigned long flags; 7578c2ecf20Sopenharmony_ci unsigned int phiIncr, coeffIncr, tmp1, tmp2; 7588c2ecf20Sopenharmony_ci unsigned int correctionPerGOF, correctionPerSec, initialDelay; 7598c2ecf20Sopenharmony_ci unsigned int frameGroupLength, cnt; 7608c2ecf20Sopenharmony_ci 7618c2ecf20Sopenharmony_ci /* 7628c2ecf20Sopenharmony_ci * We can only decimate by up to a factor of 1/9th the hardware rate. 7638c2ecf20Sopenharmony_ci * Correct the value if an attempt is made to stray outside that limit. 7648c2ecf20Sopenharmony_ci */ 7658c2ecf20Sopenharmony_ci if ((rate * 9) < 48000) 7668c2ecf20Sopenharmony_ci rate = 48000 / 9; 7678c2ecf20Sopenharmony_ci 7688c2ecf20Sopenharmony_ci /* 7698c2ecf20Sopenharmony_ci * We can not capture at a rate greater than the Input Rate (48000). 7708c2ecf20Sopenharmony_ci * Return an error if an attempt is made to stray outside that limit. 7718c2ecf20Sopenharmony_ci */ 7728c2ecf20Sopenharmony_ci if (rate > 48000) 7738c2ecf20Sopenharmony_ci rate = 48000; 7748c2ecf20Sopenharmony_ci 7758c2ecf20Sopenharmony_ci /* 7768c2ecf20Sopenharmony_ci * Compute the values used to drive the actual sample rate conversion. 7778c2ecf20Sopenharmony_ci * The following formulas are being computed, using inline assembly 7788c2ecf20Sopenharmony_ci * since we need to use 64 bit arithmetic to compute the values: 7798c2ecf20Sopenharmony_ci * 7808c2ecf20Sopenharmony_ci * coeffIncr = -floor((Fs,out * 2^23) / Fs,in) 7818c2ecf20Sopenharmony_ci * phiIncr = floor((Fs,in * 2^26) / Fs,out) 7828c2ecf20Sopenharmony_ci * correctionPerGOF = floor((Fs,in * 2^26 - Fs,out * phiIncr) / 7838c2ecf20Sopenharmony_ci * GOF_PER_SEC) 7848c2ecf20Sopenharmony_ci * correctionPerSec = Fs,in * 2^26 - Fs,out * phiIncr - 7858c2ecf20Sopenharmony_ci * GOF_PER_SEC * correctionPerGOF 7868c2ecf20Sopenharmony_ci * initialDelay = ceil((24 * Fs,in) / Fs,out) 7878c2ecf20Sopenharmony_ci * 7888c2ecf20Sopenharmony_ci * i.e. 7898c2ecf20Sopenharmony_ci * 7908c2ecf20Sopenharmony_ci * coeffIncr = neg(dividend((Fs,out * 2^23) / Fs,in)) 7918c2ecf20Sopenharmony_ci * phiIncr:ulOther = dividend:remainder((Fs,in * 2^26) / Fs,out) 7928c2ecf20Sopenharmony_ci * correctionPerGOF:correctionPerSec = 7938c2ecf20Sopenharmony_ci * dividend:remainder(ulOther / GOF_PER_SEC) 7948c2ecf20Sopenharmony_ci * initialDelay = dividend(((24 * Fs,in) + Fs,out - 1) / Fs,out) 7958c2ecf20Sopenharmony_ci */ 7968c2ecf20Sopenharmony_ci 7978c2ecf20Sopenharmony_ci tmp1 = rate << 16; 7988c2ecf20Sopenharmony_ci coeffIncr = tmp1 / 48000; 7998c2ecf20Sopenharmony_ci tmp1 -= coeffIncr * 48000; 8008c2ecf20Sopenharmony_ci tmp1 <<= 7; 8018c2ecf20Sopenharmony_ci coeffIncr <<= 7; 8028c2ecf20Sopenharmony_ci coeffIncr += tmp1 / 48000; 8038c2ecf20Sopenharmony_ci coeffIncr ^= 0xFFFFFFFF; 8048c2ecf20Sopenharmony_ci coeffIncr++; 8058c2ecf20Sopenharmony_ci tmp1 = 48000 << 16; 8068c2ecf20Sopenharmony_ci phiIncr = tmp1 / rate; 8078c2ecf20Sopenharmony_ci tmp1 -= phiIncr * rate; 8088c2ecf20Sopenharmony_ci tmp1 <<= 10; 8098c2ecf20Sopenharmony_ci phiIncr <<= 10; 8108c2ecf20Sopenharmony_ci tmp2 = tmp1 / rate; 8118c2ecf20Sopenharmony_ci phiIncr += tmp2; 8128c2ecf20Sopenharmony_ci tmp1 -= tmp2 * rate; 8138c2ecf20Sopenharmony_ci correctionPerGOF = tmp1 / GOF_PER_SEC; 8148c2ecf20Sopenharmony_ci tmp1 -= correctionPerGOF * GOF_PER_SEC; 8158c2ecf20Sopenharmony_ci correctionPerSec = tmp1; 8168c2ecf20Sopenharmony_ci initialDelay = ((48000 * 24) + rate - 1) / rate; 8178c2ecf20Sopenharmony_ci 8188c2ecf20Sopenharmony_ci /* 8198c2ecf20Sopenharmony_ci * Fill in the VariDecimate control block. 8208c2ecf20Sopenharmony_ci */ 8218c2ecf20Sopenharmony_ci spin_lock_irqsave(&chip->reg_lock, flags); 8228c2ecf20Sopenharmony_ci snd_cs46xx_poke(chip, BA1_CSRC, 8238c2ecf20Sopenharmony_ci ((correctionPerSec << 16) & 0xFFFF0000) | (correctionPerGOF & 0xFFFF)); 8248c2ecf20Sopenharmony_ci snd_cs46xx_poke(chip, BA1_CCI, coeffIncr); 8258c2ecf20Sopenharmony_ci snd_cs46xx_poke(chip, BA1_CD, 8268c2ecf20Sopenharmony_ci (((BA1_VARIDEC_BUF_1 + (initialDelay << 2)) << 16) & 0xFFFF0000) | 0x80); 8278c2ecf20Sopenharmony_ci snd_cs46xx_poke(chip, BA1_CPI, phiIncr); 8288c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&chip->reg_lock, flags); 8298c2ecf20Sopenharmony_ci 8308c2ecf20Sopenharmony_ci /* 8318c2ecf20Sopenharmony_ci * Figure out the frame group length for the write back task. Basically, 8328c2ecf20Sopenharmony_ci * this is just the factors of 24000 (2^6*3*5^3) that are not present in 8338c2ecf20Sopenharmony_ci * the output sample rate. 8348c2ecf20Sopenharmony_ci */ 8358c2ecf20Sopenharmony_ci frameGroupLength = 1; 8368c2ecf20Sopenharmony_ci for (cnt = 2; cnt <= 64; cnt *= 2) { 8378c2ecf20Sopenharmony_ci if (((rate / cnt) * cnt) != rate) 8388c2ecf20Sopenharmony_ci frameGroupLength *= 2; 8398c2ecf20Sopenharmony_ci } 8408c2ecf20Sopenharmony_ci if (((rate / 3) * 3) != rate) { 8418c2ecf20Sopenharmony_ci frameGroupLength *= 3; 8428c2ecf20Sopenharmony_ci } 8438c2ecf20Sopenharmony_ci for (cnt = 5; cnt <= 125; cnt *= 5) { 8448c2ecf20Sopenharmony_ci if (((rate / cnt) * cnt) != rate) 8458c2ecf20Sopenharmony_ci frameGroupLength *= 5; 8468c2ecf20Sopenharmony_ci } 8478c2ecf20Sopenharmony_ci 8488c2ecf20Sopenharmony_ci /* 8498c2ecf20Sopenharmony_ci * Fill in the WriteBack control block. 8508c2ecf20Sopenharmony_ci */ 8518c2ecf20Sopenharmony_ci spin_lock_irqsave(&chip->reg_lock, flags); 8528c2ecf20Sopenharmony_ci snd_cs46xx_poke(chip, BA1_CFG1, frameGroupLength); 8538c2ecf20Sopenharmony_ci snd_cs46xx_poke(chip, BA1_CFG2, (0x00800000 | frameGroupLength)); 8548c2ecf20Sopenharmony_ci snd_cs46xx_poke(chip, BA1_CCST, 0x0000FFFF); 8558c2ecf20Sopenharmony_ci snd_cs46xx_poke(chip, BA1_CSPB, ((65536 * rate) / 24000)); 8568c2ecf20Sopenharmony_ci snd_cs46xx_poke(chip, (BA1_CSPB + 4), 0x0000FFFF); 8578c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&chip->reg_lock, flags); 8588c2ecf20Sopenharmony_ci} 8598c2ecf20Sopenharmony_ci 8608c2ecf20Sopenharmony_ci/* 8618c2ecf20Sopenharmony_ci * PCM part 8628c2ecf20Sopenharmony_ci */ 8638c2ecf20Sopenharmony_ci 8648c2ecf20Sopenharmony_cistatic void snd_cs46xx_pb_trans_copy(struct snd_pcm_substream *substream, 8658c2ecf20Sopenharmony_ci struct snd_pcm_indirect *rec, size_t bytes) 8668c2ecf20Sopenharmony_ci{ 8678c2ecf20Sopenharmony_ci struct snd_pcm_runtime *runtime = substream->runtime; 8688c2ecf20Sopenharmony_ci struct snd_cs46xx_pcm * cpcm = runtime->private_data; 8698c2ecf20Sopenharmony_ci memcpy(cpcm->hw_buf.area + rec->hw_data, runtime->dma_area + rec->sw_data, bytes); 8708c2ecf20Sopenharmony_ci} 8718c2ecf20Sopenharmony_ci 8728c2ecf20Sopenharmony_cistatic int snd_cs46xx_playback_transfer(struct snd_pcm_substream *substream) 8738c2ecf20Sopenharmony_ci{ 8748c2ecf20Sopenharmony_ci struct snd_pcm_runtime *runtime = substream->runtime; 8758c2ecf20Sopenharmony_ci struct snd_cs46xx_pcm * cpcm = runtime->private_data; 8768c2ecf20Sopenharmony_ci return snd_pcm_indirect_playback_transfer(substream, &cpcm->pcm_rec, 8778c2ecf20Sopenharmony_ci snd_cs46xx_pb_trans_copy); 8788c2ecf20Sopenharmony_ci} 8798c2ecf20Sopenharmony_ci 8808c2ecf20Sopenharmony_cistatic void snd_cs46xx_cp_trans_copy(struct snd_pcm_substream *substream, 8818c2ecf20Sopenharmony_ci struct snd_pcm_indirect *rec, size_t bytes) 8828c2ecf20Sopenharmony_ci{ 8838c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = snd_pcm_substream_chip(substream); 8848c2ecf20Sopenharmony_ci struct snd_pcm_runtime *runtime = substream->runtime; 8858c2ecf20Sopenharmony_ci memcpy(runtime->dma_area + rec->sw_data, 8868c2ecf20Sopenharmony_ci chip->capt.hw_buf.area + rec->hw_data, bytes); 8878c2ecf20Sopenharmony_ci} 8888c2ecf20Sopenharmony_ci 8898c2ecf20Sopenharmony_cistatic int snd_cs46xx_capture_transfer(struct snd_pcm_substream *substream) 8908c2ecf20Sopenharmony_ci{ 8918c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = snd_pcm_substream_chip(substream); 8928c2ecf20Sopenharmony_ci return snd_pcm_indirect_capture_transfer(substream, &chip->capt.pcm_rec, 8938c2ecf20Sopenharmony_ci snd_cs46xx_cp_trans_copy); 8948c2ecf20Sopenharmony_ci} 8958c2ecf20Sopenharmony_ci 8968c2ecf20Sopenharmony_cistatic snd_pcm_uframes_t snd_cs46xx_playback_direct_pointer(struct snd_pcm_substream *substream) 8978c2ecf20Sopenharmony_ci{ 8988c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = snd_pcm_substream_chip(substream); 8998c2ecf20Sopenharmony_ci size_t ptr; 9008c2ecf20Sopenharmony_ci struct snd_cs46xx_pcm *cpcm = substream->runtime->private_data; 9018c2ecf20Sopenharmony_ci 9028c2ecf20Sopenharmony_ci if (snd_BUG_ON(!cpcm->pcm_channel)) 9038c2ecf20Sopenharmony_ci return -ENXIO; 9048c2ecf20Sopenharmony_ci 9058c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 9068c2ecf20Sopenharmony_ci ptr = snd_cs46xx_peek(chip, (cpcm->pcm_channel->pcm_reader_scb->address + 2) << 2); 9078c2ecf20Sopenharmony_ci#else 9088c2ecf20Sopenharmony_ci ptr = snd_cs46xx_peek(chip, BA1_PBA); 9098c2ecf20Sopenharmony_ci#endif 9108c2ecf20Sopenharmony_ci ptr -= cpcm->hw_buf.addr; 9118c2ecf20Sopenharmony_ci return ptr >> cpcm->shift; 9128c2ecf20Sopenharmony_ci} 9138c2ecf20Sopenharmony_ci 9148c2ecf20Sopenharmony_cistatic snd_pcm_uframes_t snd_cs46xx_playback_indirect_pointer(struct snd_pcm_substream *substream) 9158c2ecf20Sopenharmony_ci{ 9168c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = snd_pcm_substream_chip(substream); 9178c2ecf20Sopenharmony_ci size_t ptr; 9188c2ecf20Sopenharmony_ci struct snd_cs46xx_pcm *cpcm = substream->runtime->private_data; 9198c2ecf20Sopenharmony_ci 9208c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 9218c2ecf20Sopenharmony_ci if (snd_BUG_ON(!cpcm->pcm_channel)) 9228c2ecf20Sopenharmony_ci return -ENXIO; 9238c2ecf20Sopenharmony_ci ptr = snd_cs46xx_peek(chip, (cpcm->pcm_channel->pcm_reader_scb->address + 2) << 2); 9248c2ecf20Sopenharmony_ci#else 9258c2ecf20Sopenharmony_ci ptr = snd_cs46xx_peek(chip, BA1_PBA); 9268c2ecf20Sopenharmony_ci#endif 9278c2ecf20Sopenharmony_ci ptr -= cpcm->hw_buf.addr; 9288c2ecf20Sopenharmony_ci return snd_pcm_indirect_playback_pointer(substream, &cpcm->pcm_rec, ptr); 9298c2ecf20Sopenharmony_ci} 9308c2ecf20Sopenharmony_ci 9318c2ecf20Sopenharmony_cistatic snd_pcm_uframes_t snd_cs46xx_capture_direct_pointer(struct snd_pcm_substream *substream) 9328c2ecf20Sopenharmony_ci{ 9338c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = snd_pcm_substream_chip(substream); 9348c2ecf20Sopenharmony_ci size_t ptr = snd_cs46xx_peek(chip, BA1_CBA) - chip->capt.hw_buf.addr; 9358c2ecf20Sopenharmony_ci return ptr >> chip->capt.shift; 9368c2ecf20Sopenharmony_ci} 9378c2ecf20Sopenharmony_ci 9388c2ecf20Sopenharmony_cistatic snd_pcm_uframes_t snd_cs46xx_capture_indirect_pointer(struct snd_pcm_substream *substream) 9398c2ecf20Sopenharmony_ci{ 9408c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = snd_pcm_substream_chip(substream); 9418c2ecf20Sopenharmony_ci size_t ptr = snd_cs46xx_peek(chip, BA1_CBA) - chip->capt.hw_buf.addr; 9428c2ecf20Sopenharmony_ci return snd_pcm_indirect_capture_pointer(substream, &chip->capt.pcm_rec, ptr); 9438c2ecf20Sopenharmony_ci} 9448c2ecf20Sopenharmony_ci 9458c2ecf20Sopenharmony_cistatic int snd_cs46xx_playback_trigger(struct snd_pcm_substream *substream, 9468c2ecf20Sopenharmony_ci int cmd) 9478c2ecf20Sopenharmony_ci{ 9488c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = snd_pcm_substream_chip(substream); 9498c2ecf20Sopenharmony_ci /*struct snd_pcm_runtime *runtime = substream->runtime;*/ 9508c2ecf20Sopenharmony_ci int result = 0; 9518c2ecf20Sopenharmony_ci 9528c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 9538c2ecf20Sopenharmony_ci struct snd_cs46xx_pcm *cpcm = substream->runtime->private_data; 9548c2ecf20Sopenharmony_ci if (! cpcm->pcm_channel) { 9558c2ecf20Sopenharmony_ci return -ENXIO; 9568c2ecf20Sopenharmony_ci } 9578c2ecf20Sopenharmony_ci#endif 9588c2ecf20Sopenharmony_ci switch (cmd) { 9598c2ecf20Sopenharmony_ci case SNDRV_PCM_TRIGGER_START: 9608c2ecf20Sopenharmony_ci case SNDRV_PCM_TRIGGER_RESUME: 9618c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 9628c2ecf20Sopenharmony_ci /* magic value to unmute PCM stream playback volume */ 9638c2ecf20Sopenharmony_ci snd_cs46xx_poke(chip, (cpcm->pcm_channel->pcm_reader_scb->address + 9648c2ecf20Sopenharmony_ci SCBVolumeCtrl) << 2, 0x80008000); 9658c2ecf20Sopenharmony_ci 9668c2ecf20Sopenharmony_ci if (cpcm->pcm_channel->unlinked) 9678c2ecf20Sopenharmony_ci cs46xx_dsp_pcm_link(chip,cpcm->pcm_channel); 9688c2ecf20Sopenharmony_ci 9698c2ecf20Sopenharmony_ci if (substream->runtime->periods != CS46XX_FRAGS) 9708c2ecf20Sopenharmony_ci snd_cs46xx_playback_transfer(substream); 9718c2ecf20Sopenharmony_ci#else 9728c2ecf20Sopenharmony_ci spin_lock(&chip->reg_lock); 9738c2ecf20Sopenharmony_ci if (substream->runtime->periods != CS46XX_FRAGS) 9748c2ecf20Sopenharmony_ci snd_cs46xx_playback_transfer(substream); 9758c2ecf20Sopenharmony_ci { unsigned int tmp; 9768c2ecf20Sopenharmony_ci tmp = snd_cs46xx_peek(chip, BA1_PCTL); 9778c2ecf20Sopenharmony_ci tmp &= 0x0000ffff; 9788c2ecf20Sopenharmony_ci snd_cs46xx_poke(chip, BA1_PCTL, chip->play_ctl | tmp); 9798c2ecf20Sopenharmony_ci } 9808c2ecf20Sopenharmony_ci spin_unlock(&chip->reg_lock); 9818c2ecf20Sopenharmony_ci#endif 9828c2ecf20Sopenharmony_ci break; 9838c2ecf20Sopenharmony_ci case SNDRV_PCM_TRIGGER_STOP: 9848c2ecf20Sopenharmony_ci case SNDRV_PCM_TRIGGER_SUSPEND: 9858c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 9868c2ecf20Sopenharmony_ci /* magic mute channel */ 9878c2ecf20Sopenharmony_ci snd_cs46xx_poke(chip, (cpcm->pcm_channel->pcm_reader_scb->address + 9888c2ecf20Sopenharmony_ci SCBVolumeCtrl) << 2, 0xffffffff); 9898c2ecf20Sopenharmony_ci 9908c2ecf20Sopenharmony_ci if (!cpcm->pcm_channel->unlinked) 9918c2ecf20Sopenharmony_ci cs46xx_dsp_pcm_unlink(chip,cpcm->pcm_channel); 9928c2ecf20Sopenharmony_ci#else 9938c2ecf20Sopenharmony_ci spin_lock(&chip->reg_lock); 9948c2ecf20Sopenharmony_ci { unsigned int tmp; 9958c2ecf20Sopenharmony_ci tmp = snd_cs46xx_peek(chip, BA1_PCTL); 9968c2ecf20Sopenharmony_ci tmp &= 0x0000ffff; 9978c2ecf20Sopenharmony_ci snd_cs46xx_poke(chip, BA1_PCTL, tmp); 9988c2ecf20Sopenharmony_ci } 9998c2ecf20Sopenharmony_ci spin_unlock(&chip->reg_lock); 10008c2ecf20Sopenharmony_ci#endif 10018c2ecf20Sopenharmony_ci break; 10028c2ecf20Sopenharmony_ci default: 10038c2ecf20Sopenharmony_ci result = -EINVAL; 10048c2ecf20Sopenharmony_ci break; 10058c2ecf20Sopenharmony_ci } 10068c2ecf20Sopenharmony_ci 10078c2ecf20Sopenharmony_ci return result; 10088c2ecf20Sopenharmony_ci} 10098c2ecf20Sopenharmony_ci 10108c2ecf20Sopenharmony_cistatic int snd_cs46xx_capture_trigger(struct snd_pcm_substream *substream, 10118c2ecf20Sopenharmony_ci int cmd) 10128c2ecf20Sopenharmony_ci{ 10138c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = snd_pcm_substream_chip(substream); 10148c2ecf20Sopenharmony_ci unsigned int tmp; 10158c2ecf20Sopenharmony_ci int result = 0; 10168c2ecf20Sopenharmony_ci 10178c2ecf20Sopenharmony_ci spin_lock(&chip->reg_lock); 10188c2ecf20Sopenharmony_ci switch (cmd) { 10198c2ecf20Sopenharmony_ci case SNDRV_PCM_TRIGGER_START: 10208c2ecf20Sopenharmony_ci case SNDRV_PCM_TRIGGER_RESUME: 10218c2ecf20Sopenharmony_ci tmp = snd_cs46xx_peek(chip, BA1_CCTL); 10228c2ecf20Sopenharmony_ci tmp &= 0xffff0000; 10238c2ecf20Sopenharmony_ci snd_cs46xx_poke(chip, BA1_CCTL, chip->capt.ctl | tmp); 10248c2ecf20Sopenharmony_ci break; 10258c2ecf20Sopenharmony_ci case SNDRV_PCM_TRIGGER_STOP: 10268c2ecf20Sopenharmony_ci case SNDRV_PCM_TRIGGER_SUSPEND: 10278c2ecf20Sopenharmony_ci tmp = snd_cs46xx_peek(chip, BA1_CCTL); 10288c2ecf20Sopenharmony_ci tmp &= 0xffff0000; 10298c2ecf20Sopenharmony_ci snd_cs46xx_poke(chip, BA1_CCTL, tmp); 10308c2ecf20Sopenharmony_ci break; 10318c2ecf20Sopenharmony_ci default: 10328c2ecf20Sopenharmony_ci result = -EINVAL; 10338c2ecf20Sopenharmony_ci break; 10348c2ecf20Sopenharmony_ci } 10358c2ecf20Sopenharmony_ci spin_unlock(&chip->reg_lock); 10368c2ecf20Sopenharmony_ci 10378c2ecf20Sopenharmony_ci return result; 10388c2ecf20Sopenharmony_ci} 10398c2ecf20Sopenharmony_ci 10408c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 10418c2ecf20Sopenharmony_cistatic int _cs46xx_adjust_sample_rate (struct snd_cs46xx *chip, struct snd_cs46xx_pcm *cpcm, 10428c2ecf20Sopenharmony_ci int sample_rate) 10438c2ecf20Sopenharmony_ci{ 10448c2ecf20Sopenharmony_ci 10458c2ecf20Sopenharmony_ci /* If PCMReaderSCB and SrcTaskSCB not created yet ... */ 10468c2ecf20Sopenharmony_ci if ( cpcm->pcm_channel == NULL) { 10478c2ecf20Sopenharmony_ci cpcm->pcm_channel = cs46xx_dsp_create_pcm_channel (chip, sample_rate, 10488c2ecf20Sopenharmony_ci cpcm, cpcm->hw_buf.addr,cpcm->pcm_channel_id); 10498c2ecf20Sopenharmony_ci if (cpcm->pcm_channel == NULL) { 10508c2ecf20Sopenharmony_ci dev_err(chip->card->dev, 10518c2ecf20Sopenharmony_ci "failed to create virtual PCM channel\n"); 10528c2ecf20Sopenharmony_ci return -ENOMEM; 10538c2ecf20Sopenharmony_ci } 10548c2ecf20Sopenharmony_ci cpcm->pcm_channel->sample_rate = sample_rate; 10558c2ecf20Sopenharmony_ci } else 10568c2ecf20Sopenharmony_ci /* if sample rate is changed */ 10578c2ecf20Sopenharmony_ci if ((int)cpcm->pcm_channel->sample_rate != sample_rate) { 10588c2ecf20Sopenharmony_ci int unlinked = cpcm->pcm_channel->unlinked; 10598c2ecf20Sopenharmony_ci cs46xx_dsp_destroy_pcm_channel (chip,cpcm->pcm_channel); 10608c2ecf20Sopenharmony_ci 10618c2ecf20Sopenharmony_ci if ( (cpcm->pcm_channel = cs46xx_dsp_create_pcm_channel (chip, sample_rate, cpcm, 10628c2ecf20Sopenharmony_ci cpcm->hw_buf.addr, 10638c2ecf20Sopenharmony_ci cpcm->pcm_channel_id)) == NULL) { 10648c2ecf20Sopenharmony_ci dev_err(chip->card->dev, 10658c2ecf20Sopenharmony_ci "failed to re-create virtual PCM channel\n"); 10668c2ecf20Sopenharmony_ci return -ENOMEM; 10678c2ecf20Sopenharmony_ci } 10688c2ecf20Sopenharmony_ci 10698c2ecf20Sopenharmony_ci if (!unlinked) cs46xx_dsp_pcm_link (chip,cpcm->pcm_channel); 10708c2ecf20Sopenharmony_ci cpcm->pcm_channel->sample_rate = sample_rate; 10718c2ecf20Sopenharmony_ci } 10728c2ecf20Sopenharmony_ci 10738c2ecf20Sopenharmony_ci return 0; 10748c2ecf20Sopenharmony_ci} 10758c2ecf20Sopenharmony_ci#endif 10768c2ecf20Sopenharmony_ci 10778c2ecf20Sopenharmony_ci 10788c2ecf20Sopenharmony_cistatic int snd_cs46xx_playback_hw_params(struct snd_pcm_substream *substream, 10798c2ecf20Sopenharmony_ci struct snd_pcm_hw_params *hw_params) 10808c2ecf20Sopenharmony_ci{ 10818c2ecf20Sopenharmony_ci struct snd_pcm_runtime *runtime = substream->runtime; 10828c2ecf20Sopenharmony_ci struct snd_cs46xx_pcm *cpcm; 10838c2ecf20Sopenharmony_ci int err; 10848c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 10858c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = snd_pcm_substream_chip(substream); 10868c2ecf20Sopenharmony_ci int sample_rate = params_rate(hw_params); 10878c2ecf20Sopenharmony_ci int period_size = params_period_bytes(hw_params); 10888c2ecf20Sopenharmony_ci#endif 10898c2ecf20Sopenharmony_ci cpcm = runtime->private_data; 10908c2ecf20Sopenharmony_ci 10918c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 10928c2ecf20Sopenharmony_ci if (snd_BUG_ON(!sample_rate)) 10938c2ecf20Sopenharmony_ci return -ENXIO; 10948c2ecf20Sopenharmony_ci 10958c2ecf20Sopenharmony_ci mutex_lock(&chip->spos_mutex); 10968c2ecf20Sopenharmony_ci 10978c2ecf20Sopenharmony_ci if (_cs46xx_adjust_sample_rate (chip,cpcm,sample_rate)) { 10988c2ecf20Sopenharmony_ci mutex_unlock(&chip->spos_mutex); 10998c2ecf20Sopenharmony_ci return -ENXIO; 11008c2ecf20Sopenharmony_ci } 11018c2ecf20Sopenharmony_ci 11028c2ecf20Sopenharmony_ci snd_BUG_ON(!cpcm->pcm_channel); 11038c2ecf20Sopenharmony_ci if (!cpcm->pcm_channel) { 11048c2ecf20Sopenharmony_ci mutex_unlock(&chip->spos_mutex); 11058c2ecf20Sopenharmony_ci return -ENXIO; 11068c2ecf20Sopenharmony_ci } 11078c2ecf20Sopenharmony_ci 11088c2ecf20Sopenharmony_ci 11098c2ecf20Sopenharmony_ci if (cs46xx_dsp_pcm_channel_set_period (chip,cpcm->pcm_channel,period_size)) { 11108c2ecf20Sopenharmony_ci mutex_unlock(&chip->spos_mutex); 11118c2ecf20Sopenharmony_ci return -EINVAL; 11128c2ecf20Sopenharmony_ci } 11138c2ecf20Sopenharmony_ci 11148c2ecf20Sopenharmony_ci dev_dbg(chip->card->dev, 11158c2ecf20Sopenharmony_ci "period_size (%d), periods (%d) buffer_size(%d)\n", 11168c2ecf20Sopenharmony_ci period_size, params_periods(hw_params), 11178c2ecf20Sopenharmony_ci params_buffer_bytes(hw_params)); 11188c2ecf20Sopenharmony_ci#endif 11198c2ecf20Sopenharmony_ci 11208c2ecf20Sopenharmony_ci if (params_periods(hw_params) == CS46XX_FRAGS) { 11218c2ecf20Sopenharmony_ci if (runtime->dma_area != cpcm->hw_buf.area) 11228c2ecf20Sopenharmony_ci snd_pcm_lib_free_pages(substream); 11238c2ecf20Sopenharmony_ci runtime->dma_area = cpcm->hw_buf.area; 11248c2ecf20Sopenharmony_ci runtime->dma_addr = cpcm->hw_buf.addr; 11258c2ecf20Sopenharmony_ci runtime->dma_bytes = cpcm->hw_buf.bytes; 11268c2ecf20Sopenharmony_ci 11278c2ecf20Sopenharmony_ci 11288c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 11298c2ecf20Sopenharmony_ci if (cpcm->pcm_channel_id == DSP_PCM_MAIN_CHANNEL) { 11308c2ecf20Sopenharmony_ci substream->ops = &snd_cs46xx_playback_ops; 11318c2ecf20Sopenharmony_ci } else if (cpcm->pcm_channel_id == DSP_PCM_REAR_CHANNEL) { 11328c2ecf20Sopenharmony_ci substream->ops = &snd_cs46xx_playback_rear_ops; 11338c2ecf20Sopenharmony_ci } else if (cpcm->pcm_channel_id == DSP_PCM_CENTER_LFE_CHANNEL) { 11348c2ecf20Sopenharmony_ci substream->ops = &snd_cs46xx_playback_clfe_ops; 11358c2ecf20Sopenharmony_ci } else if (cpcm->pcm_channel_id == DSP_IEC958_CHANNEL) { 11368c2ecf20Sopenharmony_ci substream->ops = &snd_cs46xx_playback_iec958_ops; 11378c2ecf20Sopenharmony_ci } else { 11388c2ecf20Sopenharmony_ci snd_BUG(); 11398c2ecf20Sopenharmony_ci } 11408c2ecf20Sopenharmony_ci#else 11418c2ecf20Sopenharmony_ci substream->ops = &snd_cs46xx_playback_ops; 11428c2ecf20Sopenharmony_ci#endif 11438c2ecf20Sopenharmony_ci 11448c2ecf20Sopenharmony_ci } else { 11458c2ecf20Sopenharmony_ci if (runtime->dma_area == cpcm->hw_buf.area) { 11468c2ecf20Sopenharmony_ci runtime->dma_area = NULL; 11478c2ecf20Sopenharmony_ci runtime->dma_addr = 0; 11488c2ecf20Sopenharmony_ci runtime->dma_bytes = 0; 11498c2ecf20Sopenharmony_ci } 11508c2ecf20Sopenharmony_ci if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0) { 11518c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 11528c2ecf20Sopenharmony_ci mutex_unlock(&chip->spos_mutex); 11538c2ecf20Sopenharmony_ci#endif 11548c2ecf20Sopenharmony_ci return err; 11558c2ecf20Sopenharmony_ci } 11568c2ecf20Sopenharmony_ci 11578c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 11588c2ecf20Sopenharmony_ci if (cpcm->pcm_channel_id == DSP_PCM_MAIN_CHANNEL) { 11598c2ecf20Sopenharmony_ci substream->ops = &snd_cs46xx_playback_indirect_ops; 11608c2ecf20Sopenharmony_ci } else if (cpcm->pcm_channel_id == DSP_PCM_REAR_CHANNEL) { 11618c2ecf20Sopenharmony_ci substream->ops = &snd_cs46xx_playback_indirect_rear_ops; 11628c2ecf20Sopenharmony_ci } else if (cpcm->pcm_channel_id == DSP_PCM_CENTER_LFE_CHANNEL) { 11638c2ecf20Sopenharmony_ci substream->ops = &snd_cs46xx_playback_indirect_clfe_ops; 11648c2ecf20Sopenharmony_ci } else if (cpcm->pcm_channel_id == DSP_IEC958_CHANNEL) { 11658c2ecf20Sopenharmony_ci substream->ops = &snd_cs46xx_playback_indirect_iec958_ops; 11668c2ecf20Sopenharmony_ci } else { 11678c2ecf20Sopenharmony_ci snd_BUG(); 11688c2ecf20Sopenharmony_ci } 11698c2ecf20Sopenharmony_ci#else 11708c2ecf20Sopenharmony_ci substream->ops = &snd_cs46xx_playback_indirect_ops; 11718c2ecf20Sopenharmony_ci#endif 11728c2ecf20Sopenharmony_ci 11738c2ecf20Sopenharmony_ci } 11748c2ecf20Sopenharmony_ci 11758c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 11768c2ecf20Sopenharmony_ci mutex_unlock(&chip->spos_mutex); 11778c2ecf20Sopenharmony_ci#endif 11788c2ecf20Sopenharmony_ci 11798c2ecf20Sopenharmony_ci return 0; 11808c2ecf20Sopenharmony_ci} 11818c2ecf20Sopenharmony_ci 11828c2ecf20Sopenharmony_cistatic int snd_cs46xx_playback_hw_free(struct snd_pcm_substream *substream) 11838c2ecf20Sopenharmony_ci{ 11848c2ecf20Sopenharmony_ci /*struct snd_cs46xx *chip = snd_pcm_substream_chip(substream);*/ 11858c2ecf20Sopenharmony_ci struct snd_pcm_runtime *runtime = substream->runtime; 11868c2ecf20Sopenharmony_ci struct snd_cs46xx_pcm *cpcm; 11878c2ecf20Sopenharmony_ci 11888c2ecf20Sopenharmony_ci cpcm = runtime->private_data; 11898c2ecf20Sopenharmony_ci 11908c2ecf20Sopenharmony_ci /* if play_back open fails, then this function 11918c2ecf20Sopenharmony_ci is called and cpcm can actually be NULL here */ 11928c2ecf20Sopenharmony_ci if (!cpcm) return -ENXIO; 11938c2ecf20Sopenharmony_ci 11948c2ecf20Sopenharmony_ci if (runtime->dma_area != cpcm->hw_buf.area) 11958c2ecf20Sopenharmony_ci snd_pcm_lib_free_pages(substream); 11968c2ecf20Sopenharmony_ci 11978c2ecf20Sopenharmony_ci runtime->dma_area = NULL; 11988c2ecf20Sopenharmony_ci runtime->dma_addr = 0; 11998c2ecf20Sopenharmony_ci runtime->dma_bytes = 0; 12008c2ecf20Sopenharmony_ci 12018c2ecf20Sopenharmony_ci return 0; 12028c2ecf20Sopenharmony_ci} 12038c2ecf20Sopenharmony_ci 12048c2ecf20Sopenharmony_cistatic int snd_cs46xx_playback_prepare(struct snd_pcm_substream *substream) 12058c2ecf20Sopenharmony_ci{ 12068c2ecf20Sopenharmony_ci unsigned int tmp; 12078c2ecf20Sopenharmony_ci unsigned int pfie; 12088c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = snd_pcm_substream_chip(substream); 12098c2ecf20Sopenharmony_ci struct snd_pcm_runtime *runtime = substream->runtime; 12108c2ecf20Sopenharmony_ci struct snd_cs46xx_pcm *cpcm; 12118c2ecf20Sopenharmony_ci 12128c2ecf20Sopenharmony_ci cpcm = runtime->private_data; 12138c2ecf20Sopenharmony_ci 12148c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 12158c2ecf20Sopenharmony_ci if (snd_BUG_ON(!cpcm->pcm_channel)) 12168c2ecf20Sopenharmony_ci return -ENXIO; 12178c2ecf20Sopenharmony_ci 12188c2ecf20Sopenharmony_ci pfie = snd_cs46xx_peek(chip, (cpcm->pcm_channel->pcm_reader_scb->address + 1) << 2 ); 12198c2ecf20Sopenharmony_ci pfie &= ~0x0000f03f; 12208c2ecf20Sopenharmony_ci#else 12218c2ecf20Sopenharmony_ci /* old dsp */ 12228c2ecf20Sopenharmony_ci pfie = snd_cs46xx_peek(chip, BA1_PFIE); 12238c2ecf20Sopenharmony_ci pfie &= ~0x0000f03f; 12248c2ecf20Sopenharmony_ci#endif 12258c2ecf20Sopenharmony_ci 12268c2ecf20Sopenharmony_ci cpcm->shift = 2; 12278c2ecf20Sopenharmony_ci /* if to convert from stereo to mono */ 12288c2ecf20Sopenharmony_ci if (runtime->channels == 1) { 12298c2ecf20Sopenharmony_ci cpcm->shift--; 12308c2ecf20Sopenharmony_ci pfie |= 0x00002000; 12318c2ecf20Sopenharmony_ci } 12328c2ecf20Sopenharmony_ci /* if to convert from 8 bit to 16 bit */ 12338c2ecf20Sopenharmony_ci if (snd_pcm_format_width(runtime->format) == 8) { 12348c2ecf20Sopenharmony_ci cpcm->shift--; 12358c2ecf20Sopenharmony_ci pfie |= 0x00001000; 12368c2ecf20Sopenharmony_ci } 12378c2ecf20Sopenharmony_ci /* if to convert to unsigned */ 12388c2ecf20Sopenharmony_ci if (snd_pcm_format_unsigned(runtime->format)) 12398c2ecf20Sopenharmony_ci pfie |= 0x00008000; 12408c2ecf20Sopenharmony_ci 12418c2ecf20Sopenharmony_ci /* Never convert byte order when sample stream is 8 bit */ 12428c2ecf20Sopenharmony_ci if (snd_pcm_format_width(runtime->format) != 8) { 12438c2ecf20Sopenharmony_ci /* convert from big endian to little endian */ 12448c2ecf20Sopenharmony_ci if (snd_pcm_format_big_endian(runtime->format)) 12458c2ecf20Sopenharmony_ci pfie |= 0x00004000; 12468c2ecf20Sopenharmony_ci } 12478c2ecf20Sopenharmony_ci 12488c2ecf20Sopenharmony_ci memset(&cpcm->pcm_rec, 0, sizeof(cpcm->pcm_rec)); 12498c2ecf20Sopenharmony_ci cpcm->pcm_rec.sw_buffer_size = snd_pcm_lib_buffer_bytes(substream); 12508c2ecf20Sopenharmony_ci cpcm->pcm_rec.hw_buffer_size = runtime->period_size * CS46XX_FRAGS << cpcm->shift; 12518c2ecf20Sopenharmony_ci 12528c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 12538c2ecf20Sopenharmony_ci 12548c2ecf20Sopenharmony_ci tmp = snd_cs46xx_peek(chip, (cpcm->pcm_channel->pcm_reader_scb->address) << 2); 12558c2ecf20Sopenharmony_ci tmp &= ~0x000003ff; 12568c2ecf20Sopenharmony_ci tmp |= (4 << cpcm->shift) - 1; 12578c2ecf20Sopenharmony_ci /* playback transaction count register */ 12588c2ecf20Sopenharmony_ci snd_cs46xx_poke(chip, (cpcm->pcm_channel->pcm_reader_scb->address) << 2, tmp); 12598c2ecf20Sopenharmony_ci 12608c2ecf20Sopenharmony_ci /* playback format && interrupt enable */ 12618c2ecf20Sopenharmony_ci snd_cs46xx_poke(chip, (cpcm->pcm_channel->pcm_reader_scb->address + 1) << 2, pfie | cpcm->pcm_channel->pcm_slot); 12628c2ecf20Sopenharmony_ci#else 12638c2ecf20Sopenharmony_ci snd_cs46xx_poke(chip, BA1_PBA, cpcm->hw_buf.addr); 12648c2ecf20Sopenharmony_ci tmp = snd_cs46xx_peek(chip, BA1_PDTC); 12658c2ecf20Sopenharmony_ci tmp &= ~0x000003ff; 12668c2ecf20Sopenharmony_ci tmp |= (4 << cpcm->shift) - 1; 12678c2ecf20Sopenharmony_ci snd_cs46xx_poke(chip, BA1_PDTC, tmp); 12688c2ecf20Sopenharmony_ci snd_cs46xx_poke(chip, BA1_PFIE, pfie); 12698c2ecf20Sopenharmony_ci snd_cs46xx_set_play_sample_rate(chip, runtime->rate); 12708c2ecf20Sopenharmony_ci#endif 12718c2ecf20Sopenharmony_ci 12728c2ecf20Sopenharmony_ci return 0; 12738c2ecf20Sopenharmony_ci} 12748c2ecf20Sopenharmony_ci 12758c2ecf20Sopenharmony_cistatic int snd_cs46xx_capture_hw_params(struct snd_pcm_substream *substream, 12768c2ecf20Sopenharmony_ci struct snd_pcm_hw_params *hw_params) 12778c2ecf20Sopenharmony_ci{ 12788c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = snd_pcm_substream_chip(substream); 12798c2ecf20Sopenharmony_ci struct snd_pcm_runtime *runtime = substream->runtime; 12808c2ecf20Sopenharmony_ci int err; 12818c2ecf20Sopenharmony_ci 12828c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 12838c2ecf20Sopenharmony_ci cs46xx_dsp_pcm_ostream_set_period (chip, params_period_bytes(hw_params)); 12848c2ecf20Sopenharmony_ci#endif 12858c2ecf20Sopenharmony_ci if (runtime->periods == CS46XX_FRAGS) { 12868c2ecf20Sopenharmony_ci if (runtime->dma_area != chip->capt.hw_buf.area) 12878c2ecf20Sopenharmony_ci snd_pcm_lib_free_pages(substream); 12888c2ecf20Sopenharmony_ci runtime->dma_area = chip->capt.hw_buf.area; 12898c2ecf20Sopenharmony_ci runtime->dma_addr = chip->capt.hw_buf.addr; 12908c2ecf20Sopenharmony_ci runtime->dma_bytes = chip->capt.hw_buf.bytes; 12918c2ecf20Sopenharmony_ci substream->ops = &snd_cs46xx_capture_ops; 12928c2ecf20Sopenharmony_ci } else { 12938c2ecf20Sopenharmony_ci if (runtime->dma_area == chip->capt.hw_buf.area) { 12948c2ecf20Sopenharmony_ci runtime->dma_area = NULL; 12958c2ecf20Sopenharmony_ci runtime->dma_addr = 0; 12968c2ecf20Sopenharmony_ci runtime->dma_bytes = 0; 12978c2ecf20Sopenharmony_ci } 12988c2ecf20Sopenharmony_ci if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0) 12998c2ecf20Sopenharmony_ci return err; 13008c2ecf20Sopenharmony_ci substream->ops = &snd_cs46xx_capture_indirect_ops; 13018c2ecf20Sopenharmony_ci } 13028c2ecf20Sopenharmony_ci 13038c2ecf20Sopenharmony_ci return 0; 13048c2ecf20Sopenharmony_ci} 13058c2ecf20Sopenharmony_ci 13068c2ecf20Sopenharmony_cistatic int snd_cs46xx_capture_hw_free(struct snd_pcm_substream *substream) 13078c2ecf20Sopenharmony_ci{ 13088c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = snd_pcm_substream_chip(substream); 13098c2ecf20Sopenharmony_ci struct snd_pcm_runtime *runtime = substream->runtime; 13108c2ecf20Sopenharmony_ci 13118c2ecf20Sopenharmony_ci if (runtime->dma_area != chip->capt.hw_buf.area) 13128c2ecf20Sopenharmony_ci snd_pcm_lib_free_pages(substream); 13138c2ecf20Sopenharmony_ci runtime->dma_area = NULL; 13148c2ecf20Sopenharmony_ci runtime->dma_addr = 0; 13158c2ecf20Sopenharmony_ci runtime->dma_bytes = 0; 13168c2ecf20Sopenharmony_ci 13178c2ecf20Sopenharmony_ci return 0; 13188c2ecf20Sopenharmony_ci} 13198c2ecf20Sopenharmony_ci 13208c2ecf20Sopenharmony_cistatic int snd_cs46xx_capture_prepare(struct snd_pcm_substream *substream) 13218c2ecf20Sopenharmony_ci{ 13228c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = snd_pcm_substream_chip(substream); 13238c2ecf20Sopenharmony_ci struct snd_pcm_runtime *runtime = substream->runtime; 13248c2ecf20Sopenharmony_ci 13258c2ecf20Sopenharmony_ci snd_cs46xx_poke(chip, BA1_CBA, chip->capt.hw_buf.addr); 13268c2ecf20Sopenharmony_ci chip->capt.shift = 2; 13278c2ecf20Sopenharmony_ci memset(&chip->capt.pcm_rec, 0, sizeof(chip->capt.pcm_rec)); 13288c2ecf20Sopenharmony_ci chip->capt.pcm_rec.sw_buffer_size = snd_pcm_lib_buffer_bytes(substream); 13298c2ecf20Sopenharmony_ci chip->capt.pcm_rec.hw_buffer_size = runtime->period_size * CS46XX_FRAGS << 2; 13308c2ecf20Sopenharmony_ci snd_cs46xx_set_capture_sample_rate(chip, runtime->rate); 13318c2ecf20Sopenharmony_ci 13328c2ecf20Sopenharmony_ci return 0; 13338c2ecf20Sopenharmony_ci} 13348c2ecf20Sopenharmony_ci 13358c2ecf20Sopenharmony_cistatic irqreturn_t snd_cs46xx_interrupt(int irq, void *dev_id) 13368c2ecf20Sopenharmony_ci{ 13378c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = dev_id; 13388c2ecf20Sopenharmony_ci u32 status1; 13398c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 13408c2ecf20Sopenharmony_ci struct dsp_spos_instance * ins = chip->dsp_spos_instance; 13418c2ecf20Sopenharmony_ci u32 status2; 13428c2ecf20Sopenharmony_ci int i; 13438c2ecf20Sopenharmony_ci struct snd_cs46xx_pcm *cpcm = NULL; 13448c2ecf20Sopenharmony_ci#endif 13458c2ecf20Sopenharmony_ci 13468c2ecf20Sopenharmony_ci /* 13478c2ecf20Sopenharmony_ci * Read the Interrupt Status Register to clear the interrupt 13488c2ecf20Sopenharmony_ci */ 13498c2ecf20Sopenharmony_ci status1 = snd_cs46xx_peekBA0(chip, BA0_HISR); 13508c2ecf20Sopenharmony_ci if ((status1 & 0x7fffffff) == 0) { 13518c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_HICR, HICR_CHGM | HICR_IEV); 13528c2ecf20Sopenharmony_ci return IRQ_NONE; 13538c2ecf20Sopenharmony_ci } 13548c2ecf20Sopenharmony_ci 13558c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 13568c2ecf20Sopenharmony_ci status2 = snd_cs46xx_peekBA0(chip, BA0_HSR0); 13578c2ecf20Sopenharmony_ci 13588c2ecf20Sopenharmony_ci for (i = 0; i < DSP_MAX_PCM_CHANNELS; ++i) { 13598c2ecf20Sopenharmony_ci if (i <= 15) { 13608c2ecf20Sopenharmony_ci if ( status1 & (1 << i) ) { 13618c2ecf20Sopenharmony_ci if (i == CS46XX_DSP_CAPTURE_CHANNEL) { 13628c2ecf20Sopenharmony_ci if (chip->capt.substream) 13638c2ecf20Sopenharmony_ci snd_pcm_period_elapsed(chip->capt.substream); 13648c2ecf20Sopenharmony_ci } else { 13658c2ecf20Sopenharmony_ci if (ins->pcm_channels[i].active && 13668c2ecf20Sopenharmony_ci ins->pcm_channels[i].private_data && 13678c2ecf20Sopenharmony_ci !ins->pcm_channels[i].unlinked) { 13688c2ecf20Sopenharmony_ci cpcm = ins->pcm_channels[i].private_data; 13698c2ecf20Sopenharmony_ci snd_pcm_period_elapsed(cpcm->substream); 13708c2ecf20Sopenharmony_ci } 13718c2ecf20Sopenharmony_ci } 13728c2ecf20Sopenharmony_ci } 13738c2ecf20Sopenharmony_ci } else { 13748c2ecf20Sopenharmony_ci if ( status2 & (1 << (i - 16))) { 13758c2ecf20Sopenharmony_ci if (ins->pcm_channels[i].active && 13768c2ecf20Sopenharmony_ci ins->pcm_channels[i].private_data && 13778c2ecf20Sopenharmony_ci !ins->pcm_channels[i].unlinked) { 13788c2ecf20Sopenharmony_ci cpcm = ins->pcm_channels[i].private_data; 13798c2ecf20Sopenharmony_ci snd_pcm_period_elapsed(cpcm->substream); 13808c2ecf20Sopenharmony_ci } 13818c2ecf20Sopenharmony_ci } 13828c2ecf20Sopenharmony_ci } 13838c2ecf20Sopenharmony_ci } 13848c2ecf20Sopenharmony_ci 13858c2ecf20Sopenharmony_ci#else 13868c2ecf20Sopenharmony_ci /* old dsp */ 13878c2ecf20Sopenharmony_ci if ((status1 & HISR_VC0) && chip->playback_pcm) { 13888c2ecf20Sopenharmony_ci if (chip->playback_pcm->substream) 13898c2ecf20Sopenharmony_ci snd_pcm_period_elapsed(chip->playback_pcm->substream); 13908c2ecf20Sopenharmony_ci } 13918c2ecf20Sopenharmony_ci if ((status1 & HISR_VC1) && chip->pcm) { 13928c2ecf20Sopenharmony_ci if (chip->capt.substream) 13938c2ecf20Sopenharmony_ci snd_pcm_period_elapsed(chip->capt.substream); 13948c2ecf20Sopenharmony_ci } 13958c2ecf20Sopenharmony_ci#endif 13968c2ecf20Sopenharmony_ci 13978c2ecf20Sopenharmony_ci if ((status1 & HISR_MIDI) && chip->rmidi) { 13988c2ecf20Sopenharmony_ci unsigned char c; 13998c2ecf20Sopenharmony_ci 14008c2ecf20Sopenharmony_ci spin_lock(&chip->reg_lock); 14018c2ecf20Sopenharmony_ci while ((snd_cs46xx_peekBA0(chip, BA0_MIDSR) & MIDSR_RBE) == 0) { 14028c2ecf20Sopenharmony_ci c = snd_cs46xx_peekBA0(chip, BA0_MIDRP); 14038c2ecf20Sopenharmony_ci if ((chip->midcr & MIDCR_RIE) == 0) 14048c2ecf20Sopenharmony_ci continue; 14058c2ecf20Sopenharmony_ci snd_rawmidi_receive(chip->midi_input, &c, 1); 14068c2ecf20Sopenharmony_ci } 14078c2ecf20Sopenharmony_ci while ((snd_cs46xx_peekBA0(chip, BA0_MIDSR) & MIDSR_TBF) == 0) { 14088c2ecf20Sopenharmony_ci if ((chip->midcr & MIDCR_TIE) == 0) 14098c2ecf20Sopenharmony_ci break; 14108c2ecf20Sopenharmony_ci if (snd_rawmidi_transmit(chip->midi_output, &c, 1) != 1) { 14118c2ecf20Sopenharmony_ci chip->midcr &= ~MIDCR_TIE; 14128c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_MIDCR, chip->midcr); 14138c2ecf20Sopenharmony_ci break; 14148c2ecf20Sopenharmony_ci } 14158c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_MIDWP, c); 14168c2ecf20Sopenharmony_ci } 14178c2ecf20Sopenharmony_ci spin_unlock(&chip->reg_lock); 14188c2ecf20Sopenharmony_ci } 14198c2ecf20Sopenharmony_ci /* 14208c2ecf20Sopenharmony_ci * EOI to the PCI part....reenables interrupts 14218c2ecf20Sopenharmony_ci */ 14228c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_HICR, HICR_CHGM | HICR_IEV); 14238c2ecf20Sopenharmony_ci 14248c2ecf20Sopenharmony_ci return IRQ_HANDLED; 14258c2ecf20Sopenharmony_ci} 14268c2ecf20Sopenharmony_ci 14278c2ecf20Sopenharmony_cistatic const struct snd_pcm_hardware snd_cs46xx_playback = 14288c2ecf20Sopenharmony_ci{ 14298c2ecf20Sopenharmony_ci .info = (SNDRV_PCM_INFO_MMAP | 14308c2ecf20Sopenharmony_ci SNDRV_PCM_INFO_INTERLEAVED | 14318c2ecf20Sopenharmony_ci SNDRV_PCM_INFO_BLOCK_TRANSFER /*|*/ 14328c2ecf20Sopenharmony_ci /*SNDRV_PCM_INFO_RESUME*/ | 14338c2ecf20Sopenharmony_ci SNDRV_PCM_INFO_SYNC_APPLPTR), 14348c2ecf20Sopenharmony_ci .formats = (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U8 | 14358c2ecf20Sopenharmony_ci SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE | 14368c2ecf20Sopenharmony_ci SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE), 14378c2ecf20Sopenharmony_ci .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000, 14388c2ecf20Sopenharmony_ci .rate_min = 5500, 14398c2ecf20Sopenharmony_ci .rate_max = 48000, 14408c2ecf20Sopenharmony_ci .channels_min = 1, 14418c2ecf20Sopenharmony_ci .channels_max = 2, 14428c2ecf20Sopenharmony_ci .buffer_bytes_max = (256 * 1024), 14438c2ecf20Sopenharmony_ci .period_bytes_min = CS46XX_MIN_PERIOD_SIZE, 14448c2ecf20Sopenharmony_ci .period_bytes_max = CS46XX_MAX_PERIOD_SIZE, 14458c2ecf20Sopenharmony_ci .periods_min = CS46XX_FRAGS, 14468c2ecf20Sopenharmony_ci .periods_max = 1024, 14478c2ecf20Sopenharmony_ci .fifo_size = 0, 14488c2ecf20Sopenharmony_ci}; 14498c2ecf20Sopenharmony_ci 14508c2ecf20Sopenharmony_cistatic const struct snd_pcm_hardware snd_cs46xx_capture = 14518c2ecf20Sopenharmony_ci{ 14528c2ecf20Sopenharmony_ci .info = (SNDRV_PCM_INFO_MMAP | 14538c2ecf20Sopenharmony_ci SNDRV_PCM_INFO_INTERLEAVED | 14548c2ecf20Sopenharmony_ci SNDRV_PCM_INFO_BLOCK_TRANSFER /*|*/ 14558c2ecf20Sopenharmony_ci /*SNDRV_PCM_INFO_RESUME*/ | 14568c2ecf20Sopenharmony_ci SNDRV_PCM_INFO_SYNC_APPLPTR), 14578c2ecf20Sopenharmony_ci .formats = SNDRV_PCM_FMTBIT_S16_LE, 14588c2ecf20Sopenharmony_ci .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000, 14598c2ecf20Sopenharmony_ci .rate_min = 5500, 14608c2ecf20Sopenharmony_ci .rate_max = 48000, 14618c2ecf20Sopenharmony_ci .channels_min = 2, 14628c2ecf20Sopenharmony_ci .channels_max = 2, 14638c2ecf20Sopenharmony_ci .buffer_bytes_max = (256 * 1024), 14648c2ecf20Sopenharmony_ci .period_bytes_min = CS46XX_MIN_PERIOD_SIZE, 14658c2ecf20Sopenharmony_ci .period_bytes_max = CS46XX_MAX_PERIOD_SIZE, 14668c2ecf20Sopenharmony_ci .periods_min = CS46XX_FRAGS, 14678c2ecf20Sopenharmony_ci .periods_max = 1024, 14688c2ecf20Sopenharmony_ci .fifo_size = 0, 14698c2ecf20Sopenharmony_ci}; 14708c2ecf20Sopenharmony_ci 14718c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 14728c2ecf20Sopenharmony_ci 14738c2ecf20Sopenharmony_cistatic const unsigned int period_sizes[] = { 32, 64, 128, 256, 512, 1024, 2048 }; 14748c2ecf20Sopenharmony_ci 14758c2ecf20Sopenharmony_cistatic const struct snd_pcm_hw_constraint_list hw_constraints_period_sizes = { 14768c2ecf20Sopenharmony_ci .count = ARRAY_SIZE(period_sizes), 14778c2ecf20Sopenharmony_ci .list = period_sizes, 14788c2ecf20Sopenharmony_ci .mask = 0 14798c2ecf20Sopenharmony_ci}; 14808c2ecf20Sopenharmony_ci 14818c2ecf20Sopenharmony_ci#endif 14828c2ecf20Sopenharmony_ci 14838c2ecf20Sopenharmony_cistatic void snd_cs46xx_pcm_free_substream(struct snd_pcm_runtime *runtime) 14848c2ecf20Sopenharmony_ci{ 14858c2ecf20Sopenharmony_ci kfree(runtime->private_data); 14868c2ecf20Sopenharmony_ci} 14878c2ecf20Sopenharmony_ci 14888c2ecf20Sopenharmony_cistatic int _cs46xx_playback_open_channel (struct snd_pcm_substream *substream,int pcm_channel_id) 14898c2ecf20Sopenharmony_ci{ 14908c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = snd_pcm_substream_chip(substream); 14918c2ecf20Sopenharmony_ci struct snd_cs46xx_pcm * cpcm; 14928c2ecf20Sopenharmony_ci struct snd_pcm_runtime *runtime = substream->runtime; 14938c2ecf20Sopenharmony_ci 14948c2ecf20Sopenharmony_ci cpcm = kzalloc(sizeof(*cpcm), GFP_KERNEL); 14958c2ecf20Sopenharmony_ci if (cpcm == NULL) 14968c2ecf20Sopenharmony_ci return -ENOMEM; 14978c2ecf20Sopenharmony_ci if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, &chip->pci->dev, 14988c2ecf20Sopenharmony_ci PAGE_SIZE, &cpcm->hw_buf) < 0) { 14998c2ecf20Sopenharmony_ci kfree(cpcm); 15008c2ecf20Sopenharmony_ci return -ENOMEM; 15018c2ecf20Sopenharmony_ci } 15028c2ecf20Sopenharmony_ci 15038c2ecf20Sopenharmony_ci runtime->hw = snd_cs46xx_playback; 15048c2ecf20Sopenharmony_ci runtime->private_data = cpcm; 15058c2ecf20Sopenharmony_ci runtime->private_free = snd_cs46xx_pcm_free_substream; 15068c2ecf20Sopenharmony_ci 15078c2ecf20Sopenharmony_ci cpcm->substream = substream; 15088c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 15098c2ecf20Sopenharmony_ci mutex_lock(&chip->spos_mutex); 15108c2ecf20Sopenharmony_ci cpcm->pcm_channel = NULL; 15118c2ecf20Sopenharmony_ci cpcm->pcm_channel_id = pcm_channel_id; 15128c2ecf20Sopenharmony_ci 15138c2ecf20Sopenharmony_ci 15148c2ecf20Sopenharmony_ci snd_pcm_hw_constraint_list(runtime, 0, 15158c2ecf20Sopenharmony_ci SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 15168c2ecf20Sopenharmony_ci &hw_constraints_period_sizes); 15178c2ecf20Sopenharmony_ci 15188c2ecf20Sopenharmony_ci mutex_unlock(&chip->spos_mutex); 15198c2ecf20Sopenharmony_ci#else 15208c2ecf20Sopenharmony_ci chip->playback_pcm = cpcm; /* HACK */ 15218c2ecf20Sopenharmony_ci#endif 15228c2ecf20Sopenharmony_ci 15238c2ecf20Sopenharmony_ci if (chip->accept_valid) 15248c2ecf20Sopenharmony_ci substream->runtime->hw.info |= SNDRV_PCM_INFO_MMAP_VALID; 15258c2ecf20Sopenharmony_ci chip->active_ctrl(chip, 1); 15268c2ecf20Sopenharmony_ci 15278c2ecf20Sopenharmony_ci return 0; 15288c2ecf20Sopenharmony_ci} 15298c2ecf20Sopenharmony_ci 15308c2ecf20Sopenharmony_cistatic int snd_cs46xx_playback_open(struct snd_pcm_substream *substream) 15318c2ecf20Sopenharmony_ci{ 15328c2ecf20Sopenharmony_ci dev_dbg(substream->pcm->card->dev, "open front channel\n"); 15338c2ecf20Sopenharmony_ci return _cs46xx_playback_open_channel(substream,DSP_PCM_MAIN_CHANNEL); 15348c2ecf20Sopenharmony_ci} 15358c2ecf20Sopenharmony_ci 15368c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 15378c2ecf20Sopenharmony_cistatic int snd_cs46xx_playback_open_rear(struct snd_pcm_substream *substream) 15388c2ecf20Sopenharmony_ci{ 15398c2ecf20Sopenharmony_ci dev_dbg(substream->pcm->card->dev, "open rear channel\n"); 15408c2ecf20Sopenharmony_ci return _cs46xx_playback_open_channel(substream,DSP_PCM_REAR_CHANNEL); 15418c2ecf20Sopenharmony_ci} 15428c2ecf20Sopenharmony_ci 15438c2ecf20Sopenharmony_cistatic int snd_cs46xx_playback_open_clfe(struct snd_pcm_substream *substream) 15448c2ecf20Sopenharmony_ci{ 15458c2ecf20Sopenharmony_ci dev_dbg(substream->pcm->card->dev, "open center - LFE channel\n"); 15468c2ecf20Sopenharmony_ci return _cs46xx_playback_open_channel(substream,DSP_PCM_CENTER_LFE_CHANNEL); 15478c2ecf20Sopenharmony_ci} 15488c2ecf20Sopenharmony_ci 15498c2ecf20Sopenharmony_cistatic int snd_cs46xx_playback_open_iec958(struct snd_pcm_substream *substream) 15508c2ecf20Sopenharmony_ci{ 15518c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = snd_pcm_substream_chip(substream); 15528c2ecf20Sopenharmony_ci 15538c2ecf20Sopenharmony_ci dev_dbg(chip->card->dev, "open raw iec958 channel\n"); 15548c2ecf20Sopenharmony_ci 15558c2ecf20Sopenharmony_ci mutex_lock(&chip->spos_mutex); 15568c2ecf20Sopenharmony_ci cs46xx_iec958_pre_open (chip); 15578c2ecf20Sopenharmony_ci mutex_unlock(&chip->spos_mutex); 15588c2ecf20Sopenharmony_ci 15598c2ecf20Sopenharmony_ci return _cs46xx_playback_open_channel(substream,DSP_IEC958_CHANNEL); 15608c2ecf20Sopenharmony_ci} 15618c2ecf20Sopenharmony_ci 15628c2ecf20Sopenharmony_cistatic int snd_cs46xx_playback_close(struct snd_pcm_substream *substream); 15638c2ecf20Sopenharmony_ci 15648c2ecf20Sopenharmony_cistatic int snd_cs46xx_playback_close_iec958(struct snd_pcm_substream *substream) 15658c2ecf20Sopenharmony_ci{ 15668c2ecf20Sopenharmony_ci int err; 15678c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = snd_pcm_substream_chip(substream); 15688c2ecf20Sopenharmony_ci 15698c2ecf20Sopenharmony_ci dev_dbg(chip->card->dev, "close raw iec958 channel\n"); 15708c2ecf20Sopenharmony_ci 15718c2ecf20Sopenharmony_ci err = snd_cs46xx_playback_close(substream); 15728c2ecf20Sopenharmony_ci 15738c2ecf20Sopenharmony_ci mutex_lock(&chip->spos_mutex); 15748c2ecf20Sopenharmony_ci cs46xx_iec958_post_close (chip); 15758c2ecf20Sopenharmony_ci mutex_unlock(&chip->spos_mutex); 15768c2ecf20Sopenharmony_ci 15778c2ecf20Sopenharmony_ci return err; 15788c2ecf20Sopenharmony_ci} 15798c2ecf20Sopenharmony_ci#endif 15808c2ecf20Sopenharmony_ci 15818c2ecf20Sopenharmony_cistatic int snd_cs46xx_capture_open(struct snd_pcm_substream *substream) 15828c2ecf20Sopenharmony_ci{ 15838c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = snd_pcm_substream_chip(substream); 15848c2ecf20Sopenharmony_ci 15858c2ecf20Sopenharmony_ci if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, &chip->pci->dev, 15868c2ecf20Sopenharmony_ci PAGE_SIZE, &chip->capt.hw_buf) < 0) 15878c2ecf20Sopenharmony_ci return -ENOMEM; 15888c2ecf20Sopenharmony_ci chip->capt.substream = substream; 15898c2ecf20Sopenharmony_ci substream->runtime->hw = snd_cs46xx_capture; 15908c2ecf20Sopenharmony_ci 15918c2ecf20Sopenharmony_ci if (chip->accept_valid) 15928c2ecf20Sopenharmony_ci substream->runtime->hw.info |= SNDRV_PCM_INFO_MMAP_VALID; 15938c2ecf20Sopenharmony_ci 15948c2ecf20Sopenharmony_ci chip->active_ctrl(chip, 1); 15958c2ecf20Sopenharmony_ci 15968c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 15978c2ecf20Sopenharmony_ci snd_pcm_hw_constraint_list(substream->runtime, 0, 15988c2ecf20Sopenharmony_ci SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 15998c2ecf20Sopenharmony_ci &hw_constraints_period_sizes); 16008c2ecf20Sopenharmony_ci#endif 16018c2ecf20Sopenharmony_ci return 0; 16028c2ecf20Sopenharmony_ci} 16038c2ecf20Sopenharmony_ci 16048c2ecf20Sopenharmony_cistatic int snd_cs46xx_playback_close(struct snd_pcm_substream *substream) 16058c2ecf20Sopenharmony_ci{ 16068c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = snd_pcm_substream_chip(substream); 16078c2ecf20Sopenharmony_ci struct snd_pcm_runtime *runtime = substream->runtime; 16088c2ecf20Sopenharmony_ci struct snd_cs46xx_pcm * cpcm; 16098c2ecf20Sopenharmony_ci 16108c2ecf20Sopenharmony_ci cpcm = runtime->private_data; 16118c2ecf20Sopenharmony_ci 16128c2ecf20Sopenharmony_ci /* when playback_open fails, then cpcm can be NULL */ 16138c2ecf20Sopenharmony_ci if (!cpcm) return -ENXIO; 16148c2ecf20Sopenharmony_ci 16158c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 16168c2ecf20Sopenharmony_ci mutex_lock(&chip->spos_mutex); 16178c2ecf20Sopenharmony_ci if (cpcm->pcm_channel) { 16188c2ecf20Sopenharmony_ci cs46xx_dsp_destroy_pcm_channel(chip,cpcm->pcm_channel); 16198c2ecf20Sopenharmony_ci cpcm->pcm_channel = NULL; 16208c2ecf20Sopenharmony_ci } 16218c2ecf20Sopenharmony_ci mutex_unlock(&chip->spos_mutex); 16228c2ecf20Sopenharmony_ci#else 16238c2ecf20Sopenharmony_ci chip->playback_pcm = NULL; 16248c2ecf20Sopenharmony_ci#endif 16258c2ecf20Sopenharmony_ci 16268c2ecf20Sopenharmony_ci cpcm->substream = NULL; 16278c2ecf20Sopenharmony_ci snd_dma_free_pages(&cpcm->hw_buf); 16288c2ecf20Sopenharmony_ci chip->active_ctrl(chip, -1); 16298c2ecf20Sopenharmony_ci 16308c2ecf20Sopenharmony_ci return 0; 16318c2ecf20Sopenharmony_ci} 16328c2ecf20Sopenharmony_ci 16338c2ecf20Sopenharmony_cistatic int snd_cs46xx_capture_close(struct snd_pcm_substream *substream) 16348c2ecf20Sopenharmony_ci{ 16358c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = snd_pcm_substream_chip(substream); 16368c2ecf20Sopenharmony_ci 16378c2ecf20Sopenharmony_ci chip->capt.substream = NULL; 16388c2ecf20Sopenharmony_ci snd_dma_free_pages(&chip->capt.hw_buf); 16398c2ecf20Sopenharmony_ci chip->active_ctrl(chip, -1); 16408c2ecf20Sopenharmony_ci 16418c2ecf20Sopenharmony_ci return 0; 16428c2ecf20Sopenharmony_ci} 16438c2ecf20Sopenharmony_ci 16448c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 16458c2ecf20Sopenharmony_cistatic const struct snd_pcm_ops snd_cs46xx_playback_rear_ops = { 16468c2ecf20Sopenharmony_ci .open = snd_cs46xx_playback_open_rear, 16478c2ecf20Sopenharmony_ci .close = snd_cs46xx_playback_close, 16488c2ecf20Sopenharmony_ci .hw_params = snd_cs46xx_playback_hw_params, 16498c2ecf20Sopenharmony_ci .hw_free = snd_cs46xx_playback_hw_free, 16508c2ecf20Sopenharmony_ci .prepare = snd_cs46xx_playback_prepare, 16518c2ecf20Sopenharmony_ci .trigger = snd_cs46xx_playback_trigger, 16528c2ecf20Sopenharmony_ci .pointer = snd_cs46xx_playback_direct_pointer, 16538c2ecf20Sopenharmony_ci}; 16548c2ecf20Sopenharmony_ci 16558c2ecf20Sopenharmony_cistatic const struct snd_pcm_ops snd_cs46xx_playback_indirect_rear_ops = { 16568c2ecf20Sopenharmony_ci .open = snd_cs46xx_playback_open_rear, 16578c2ecf20Sopenharmony_ci .close = snd_cs46xx_playback_close, 16588c2ecf20Sopenharmony_ci .hw_params = snd_cs46xx_playback_hw_params, 16598c2ecf20Sopenharmony_ci .hw_free = snd_cs46xx_playback_hw_free, 16608c2ecf20Sopenharmony_ci .prepare = snd_cs46xx_playback_prepare, 16618c2ecf20Sopenharmony_ci .trigger = snd_cs46xx_playback_trigger, 16628c2ecf20Sopenharmony_ci .pointer = snd_cs46xx_playback_indirect_pointer, 16638c2ecf20Sopenharmony_ci .ack = snd_cs46xx_playback_transfer, 16648c2ecf20Sopenharmony_ci}; 16658c2ecf20Sopenharmony_ci 16668c2ecf20Sopenharmony_cistatic const struct snd_pcm_ops snd_cs46xx_playback_clfe_ops = { 16678c2ecf20Sopenharmony_ci .open = snd_cs46xx_playback_open_clfe, 16688c2ecf20Sopenharmony_ci .close = snd_cs46xx_playback_close, 16698c2ecf20Sopenharmony_ci .hw_params = snd_cs46xx_playback_hw_params, 16708c2ecf20Sopenharmony_ci .hw_free = snd_cs46xx_playback_hw_free, 16718c2ecf20Sopenharmony_ci .prepare = snd_cs46xx_playback_prepare, 16728c2ecf20Sopenharmony_ci .trigger = snd_cs46xx_playback_trigger, 16738c2ecf20Sopenharmony_ci .pointer = snd_cs46xx_playback_direct_pointer, 16748c2ecf20Sopenharmony_ci}; 16758c2ecf20Sopenharmony_ci 16768c2ecf20Sopenharmony_cistatic const struct snd_pcm_ops snd_cs46xx_playback_indirect_clfe_ops = { 16778c2ecf20Sopenharmony_ci .open = snd_cs46xx_playback_open_clfe, 16788c2ecf20Sopenharmony_ci .close = snd_cs46xx_playback_close, 16798c2ecf20Sopenharmony_ci .hw_params = snd_cs46xx_playback_hw_params, 16808c2ecf20Sopenharmony_ci .hw_free = snd_cs46xx_playback_hw_free, 16818c2ecf20Sopenharmony_ci .prepare = snd_cs46xx_playback_prepare, 16828c2ecf20Sopenharmony_ci .trigger = snd_cs46xx_playback_trigger, 16838c2ecf20Sopenharmony_ci .pointer = snd_cs46xx_playback_indirect_pointer, 16848c2ecf20Sopenharmony_ci .ack = snd_cs46xx_playback_transfer, 16858c2ecf20Sopenharmony_ci}; 16868c2ecf20Sopenharmony_ci 16878c2ecf20Sopenharmony_cistatic const struct snd_pcm_ops snd_cs46xx_playback_iec958_ops = { 16888c2ecf20Sopenharmony_ci .open = snd_cs46xx_playback_open_iec958, 16898c2ecf20Sopenharmony_ci .close = snd_cs46xx_playback_close_iec958, 16908c2ecf20Sopenharmony_ci .hw_params = snd_cs46xx_playback_hw_params, 16918c2ecf20Sopenharmony_ci .hw_free = snd_cs46xx_playback_hw_free, 16928c2ecf20Sopenharmony_ci .prepare = snd_cs46xx_playback_prepare, 16938c2ecf20Sopenharmony_ci .trigger = snd_cs46xx_playback_trigger, 16948c2ecf20Sopenharmony_ci .pointer = snd_cs46xx_playback_direct_pointer, 16958c2ecf20Sopenharmony_ci}; 16968c2ecf20Sopenharmony_ci 16978c2ecf20Sopenharmony_cistatic const struct snd_pcm_ops snd_cs46xx_playback_indirect_iec958_ops = { 16988c2ecf20Sopenharmony_ci .open = snd_cs46xx_playback_open_iec958, 16998c2ecf20Sopenharmony_ci .close = snd_cs46xx_playback_close_iec958, 17008c2ecf20Sopenharmony_ci .hw_params = snd_cs46xx_playback_hw_params, 17018c2ecf20Sopenharmony_ci .hw_free = snd_cs46xx_playback_hw_free, 17028c2ecf20Sopenharmony_ci .prepare = snd_cs46xx_playback_prepare, 17038c2ecf20Sopenharmony_ci .trigger = snd_cs46xx_playback_trigger, 17048c2ecf20Sopenharmony_ci .pointer = snd_cs46xx_playback_indirect_pointer, 17058c2ecf20Sopenharmony_ci .ack = snd_cs46xx_playback_transfer, 17068c2ecf20Sopenharmony_ci}; 17078c2ecf20Sopenharmony_ci 17088c2ecf20Sopenharmony_ci#endif 17098c2ecf20Sopenharmony_ci 17108c2ecf20Sopenharmony_cistatic const struct snd_pcm_ops snd_cs46xx_playback_ops = { 17118c2ecf20Sopenharmony_ci .open = snd_cs46xx_playback_open, 17128c2ecf20Sopenharmony_ci .close = snd_cs46xx_playback_close, 17138c2ecf20Sopenharmony_ci .hw_params = snd_cs46xx_playback_hw_params, 17148c2ecf20Sopenharmony_ci .hw_free = snd_cs46xx_playback_hw_free, 17158c2ecf20Sopenharmony_ci .prepare = snd_cs46xx_playback_prepare, 17168c2ecf20Sopenharmony_ci .trigger = snd_cs46xx_playback_trigger, 17178c2ecf20Sopenharmony_ci .pointer = snd_cs46xx_playback_direct_pointer, 17188c2ecf20Sopenharmony_ci}; 17198c2ecf20Sopenharmony_ci 17208c2ecf20Sopenharmony_cistatic const struct snd_pcm_ops snd_cs46xx_playback_indirect_ops = { 17218c2ecf20Sopenharmony_ci .open = snd_cs46xx_playback_open, 17228c2ecf20Sopenharmony_ci .close = snd_cs46xx_playback_close, 17238c2ecf20Sopenharmony_ci .hw_params = snd_cs46xx_playback_hw_params, 17248c2ecf20Sopenharmony_ci .hw_free = snd_cs46xx_playback_hw_free, 17258c2ecf20Sopenharmony_ci .prepare = snd_cs46xx_playback_prepare, 17268c2ecf20Sopenharmony_ci .trigger = snd_cs46xx_playback_trigger, 17278c2ecf20Sopenharmony_ci .pointer = snd_cs46xx_playback_indirect_pointer, 17288c2ecf20Sopenharmony_ci .ack = snd_cs46xx_playback_transfer, 17298c2ecf20Sopenharmony_ci}; 17308c2ecf20Sopenharmony_ci 17318c2ecf20Sopenharmony_cistatic const struct snd_pcm_ops snd_cs46xx_capture_ops = { 17328c2ecf20Sopenharmony_ci .open = snd_cs46xx_capture_open, 17338c2ecf20Sopenharmony_ci .close = snd_cs46xx_capture_close, 17348c2ecf20Sopenharmony_ci .hw_params = snd_cs46xx_capture_hw_params, 17358c2ecf20Sopenharmony_ci .hw_free = snd_cs46xx_capture_hw_free, 17368c2ecf20Sopenharmony_ci .prepare = snd_cs46xx_capture_prepare, 17378c2ecf20Sopenharmony_ci .trigger = snd_cs46xx_capture_trigger, 17388c2ecf20Sopenharmony_ci .pointer = snd_cs46xx_capture_direct_pointer, 17398c2ecf20Sopenharmony_ci}; 17408c2ecf20Sopenharmony_ci 17418c2ecf20Sopenharmony_cistatic const struct snd_pcm_ops snd_cs46xx_capture_indirect_ops = { 17428c2ecf20Sopenharmony_ci .open = snd_cs46xx_capture_open, 17438c2ecf20Sopenharmony_ci .close = snd_cs46xx_capture_close, 17448c2ecf20Sopenharmony_ci .hw_params = snd_cs46xx_capture_hw_params, 17458c2ecf20Sopenharmony_ci .hw_free = snd_cs46xx_capture_hw_free, 17468c2ecf20Sopenharmony_ci .prepare = snd_cs46xx_capture_prepare, 17478c2ecf20Sopenharmony_ci .trigger = snd_cs46xx_capture_trigger, 17488c2ecf20Sopenharmony_ci .pointer = snd_cs46xx_capture_indirect_pointer, 17498c2ecf20Sopenharmony_ci .ack = snd_cs46xx_capture_transfer, 17508c2ecf20Sopenharmony_ci}; 17518c2ecf20Sopenharmony_ci 17528c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 17538c2ecf20Sopenharmony_ci#define MAX_PLAYBACK_CHANNELS (DSP_MAX_PCM_CHANNELS - 1) 17548c2ecf20Sopenharmony_ci#else 17558c2ecf20Sopenharmony_ci#define MAX_PLAYBACK_CHANNELS 1 17568c2ecf20Sopenharmony_ci#endif 17578c2ecf20Sopenharmony_ci 17588c2ecf20Sopenharmony_ciint snd_cs46xx_pcm(struct snd_cs46xx *chip, int device) 17598c2ecf20Sopenharmony_ci{ 17608c2ecf20Sopenharmony_ci struct snd_pcm *pcm; 17618c2ecf20Sopenharmony_ci int err; 17628c2ecf20Sopenharmony_ci 17638c2ecf20Sopenharmony_ci if ((err = snd_pcm_new(chip->card, "CS46xx", device, MAX_PLAYBACK_CHANNELS, 1, &pcm)) < 0) 17648c2ecf20Sopenharmony_ci return err; 17658c2ecf20Sopenharmony_ci 17668c2ecf20Sopenharmony_ci pcm->private_data = chip; 17678c2ecf20Sopenharmony_ci 17688c2ecf20Sopenharmony_ci snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_cs46xx_playback_ops); 17698c2ecf20Sopenharmony_ci snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_cs46xx_capture_ops); 17708c2ecf20Sopenharmony_ci 17718c2ecf20Sopenharmony_ci /* global setup */ 17728c2ecf20Sopenharmony_ci pcm->info_flags = 0; 17738c2ecf20Sopenharmony_ci strcpy(pcm->name, "CS46xx"); 17748c2ecf20Sopenharmony_ci chip->pcm = pcm; 17758c2ecf20Sopenharmony_ci 17768c2ecf20Sopenharmony_ci snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, 17778c2ecf20Sopenharmony_ci &chip->pci->dev, 17788c2ecf20Sopenharmony_ci 64*1024, 256*1024); 17798c2ecf20Sopenharmony_ci 17808c2ecf20Sopenharmony_ci return 0; 17818c2ecf20Sopenharmony_ci} 17828c2ecf20Sopenharmony_ci 17838c2ecf20Sopenharmony_ci 17848c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 17858c2ecf20Sopenharmony_ciint snd_cs46xx_pcm_rear(struct snd_cs46xx *chip, int device) 17868c2ecf20Sopenharmony_ci{ 17878c2ecf20Sopenharmony_ci struct snd_pcm *pcm; 17888c2ecf20Sopenharmony_ci int err; 17898c2ecf20Sopenharmony_ci 17908c2ecf20Sopenharmony_ci if ((err = snd_pcm_new(chip->card, "CS46xx - Rear", device, MAX_PLAYBACK_CHANNELS, 0, &pcm)) < 0) 17918c2ecf20Sopenharmony_ci return err; 17928c2ecf20Sopenharmony_ci 17938c2ecf20Sopenharmony_ci pcm->private_data = chip; 17948c2ecf20Sopenharmony_ci 17958c2ecf20Sopenharmony_ci snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_cs46xx_playback_rear_ops); 17968c2ecf20Sopenharmony_ci 17978c2ecf20Sopenharmony_ci /* global setup */ 17988c2ecf20Sopenharmony_ci pcm->info_flags = 0; 17998c2ecf20Sopenharmony_ci strcpy(pcm->name, "CS46xx - Rear"); 18008c2ecf20Sopenharmony_ci chip->pcm_rear = pcm; 18018c2ecf20Sopenharmony_ci 18028c2ecf20Sopenharmony_ci snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, 18038c2ecf20Sopenharmony_ci &chip->pci->dev, 18048c2ecf20Sopenharmony_ci 64*1024, 256*1024); 18058c2ecf20Sopenharmony_ci 18068c2ecf20Sopenharmony_ci return 0; 18078c2ecf20Sopenharmony_ci} 18088c2ecf20Sopenharmony_ci 18098c2ecf20Sopenharmony_ciint snd_cs46xx_pcm_center_lfe(struct snd_cs46xx *chip, int device) 18108c2ecf20Sopenharmony_ci{ 18118c2ecf20Sopenharmony_ci struct snd_pcm *pcm; 18128c2ecf20Sopenharmony_ci int err; 18138c2ecf20Sopenharmony_ci 18148c2ecf20Sopenharmony_ci if ((err = snd_pcm_new(chip->card, "CS46xx - Center LFE", device, MAX_PLAYBACK_CHANNELS, 0, &pcm)) < 0) 18158c2ecf20Sopenharmony_ci return err; 18168c2ecf20Sopenharmony_ci 18178c2ecf20Sopenharmony_ci pcm->private_data = chip; 18188c2ecf20Sopenharmony_ci 18198c2ecf20Sopenharmony_ci snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_cs46xx_playback_clfe_ops); 18208c2ecf20Sopenharmony_ci 18218c2ecf20Sopenharmony_ci /* global setup */ 18228c2ecf20Sopenharmony_ci pcm->info_flags = 0; 18238c2ecf20Sopenharmony_ci strcpy(pcm->name, "CS46xx - Center LFE"); 18248c2ecf20Sopenharmony_ci chip->pcm_center_lfe = pcm; 18258c2ecf20Sopenharmony_ci 18268c2ecf20Sopenharmony_ci snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, 18278c2ecf20Sopenharmony_ci &chip->pci->dev, 18288c2ecf20Sopenharmony_ci 64*1024, 256*1024); 18298c2ecf20Sopenharmony_ci 18308c2ecf20Sopenharmony_ci return 0; 18318c2ecf20Sopenharmony_ci} 18328c2ecf20Sopenharmony_ci 18338c2ecf20Sopenharmony_ciint snd_cs46xx_pcm_iec958(struct snd_cs46xx *chip, int device) 18348c2ecf20Sopenharmony_ci{ 18358c2ecf20Sopenharmony_ci struct snd_pcm *pcm; 18368c2ecf20Sopenharmony_ci int err; 18378c2ecf20Sopenharmony_ci 18388c2ecf20Sopenharmony_ci if ((err = snd_pcm_new(chip->card, "CS46xx - IEC958", device, 1, 0, &pcm)) < 0) 18398c2ecf20Sopenharmony_ci return err; 18408c2ecf20Sopenharmony_ci 18418c2ecf20Sopenharmony_ci pcm->private_data = chip; 18428c2ecf20Sopenharmony_ci 18438c2ecf20Sopenharmony_ci snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_cs46xx_playback_iec958_ops); 18448c2ecf20Sopenharmony_ci 18458c2ecf20Sopenharmony_ci /* global setup */ 18468c2ecf20Sopenharmony_ci pcm->info_flags = 0; 18478c2ecf20Sopenharmony_ci strcpy(pcm->name, "CS46xx - IEC958"); 18488c2ecf20Sopenharmony_ci chip->pcm_iec958 = pcm; 18498c2ecf20Sopenharmony_ci 18508c2ecf20Sopenharmony_ci snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, 18518c2ecf20Sopenharmony_ci &chip->pci->dev, 18528c2ecf20Sopenharmony_ci 64*1024, 256*1024); 18538c2ecf20Sopenharmony_ci 18548c2ecf20Sopenharmony_ci return 0; 18558c2ecf20Sopenharmony_ci} 18568c2ecf20Sopenharmony_ci#endif 18578c2ecf20Sopenharmony_ci 18588c2ecf20Sopenharmony_ci/* 18598c2ecf20Sopenharmony_ci * Mixer routines 18608c2ecf20Sopenharmony_ci */ 18618c2ecf20Sopenharmony_cistatic void snd_cs46xx_mixer_free_ac97_bus(struct snd_ac97_bus *bus) 18628c2ecf20Sopenharmony_ci{ 18638c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = bus->private_data; 18648c2ecf20Sopenharmony_ci 18658c2ecf20Sopenharmony_ci chip->ac97_bus = NULL; 18668c2ecf20Sopenharmony_ci} 18678c2ecf20Sopenharmony_ci 18688c2ecf20Sopenharmony_cistatic void snd_cs46xx_mixer_free_ac97(struct snd_ac97 *ac97) 18698c2ecf20Sopenharmony_ci{ 18708c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = ac97->private_data; 18718c2ecf20Sopenharmony_ci 18728c2ecf20Sopenharmony_ci if (snd_BUG_ON(ac97 != chip->ac97[CS46XX_PRIMARY_CODEC_INDEX] && 18738c2ecf20Sopenharmony_ci ac97 != chip->ac97[CS46XX_SECONDARY_CODEC_INDEX])) 18748c2ecf20Sopenharmony_ci return; 18758c2ecf20Sopenharmony_ci 18768c2ecf20Sopenharmony_ci if (ac97 == chip->ac97[CS46XX_PRIMARY_CODEC_INDEX]) { 18778c2ecf20Sopenharmony_ci chip->ac97[CS46XX_PRIMARY_CODEC_INDEX] = NULL; 18788c2ecf20Sopenharmony_ci chip->eapd_switch = NULL; 18798c2ecf20Sopenharmony_ci } 18808c2ecf20Sopenharmony_ci else 18818c2ecf20Sopenharmony_ci chip->ac97[CS46XX_SECONDARY_CODEC_INDEX] = NULL; 18828c2ecf20Sopenharmony_ci} 18838c2ecf20Sopenharmony_ci 18848c2ecf20Sopenharmony_cistatic int snd_cs46xx_vol_info(struct snd_kcontrol *kcontrol, 18858c2ecf20Sopenharmony_ci struct snd_ctl_elem_info *uinfo) 18868c2ecf20Sopenharmony_ci{ 18878c2ecf20Sopenharmony_ci uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 18888c2ecf20Sopenharmony_ci uinfo->count = 2; 18898c2ecf20Sopenharmony_ci uinfo->value.integer.min = 0; 18908c2ecf20Sopenharmony_ci uinfo->value.integer.max = 0x7fff; 18918c2ecf20Sopenharmony_ci return 0; 18928c2ecf20Sopenharmony_ci} 18938c2ecf20Sopenharmony_ci 18948c2ecf20Sopenharmony_cistatic int snd_cs46xx_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 18958c2ecf20Sopenharmony_ci{ 18968c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = snd_kcontrol_chip(kcontrol); 18978c2ecf20Sopenharmony_ci int reg = kcontrol->private_value; 18988c2ecf20Sopenharmony_ci unsigned int val = snd_cs46xx_peek(chip, reg); 18998c2ecf20Sopenharmony_ci ucontrol->value.integer.value[0] = 0xffff - (val >> 16); 19008c2ecf20Sopenharmony_ci ucontrol->value.integer.value[1] = 0xffff - (val & 0xffff); 19018c2ecf20Sopenharmony_ci return 0; 19028c2ecf20Sopenharmony_ci} 19038c2ecf20Sopenharmony_ci 19048c2ecf20Sopenharmony_cistatic int snd_cs46xx_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 19058c2ecf20Sopenharmony_ci{ 19068c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = snd_kcontrol_chip(kcontrol); 19078c2ecf20Sopenharmony_ci int reg = kcontrol->private_value; 19088c2ecf20Sopenharmony_ci unsigned int val = ((0xffff - ucontrol->value.integer.value[0]) << 16 | 19098c2ecf20Sopenharmony_ci (0xffff - ucontrol->value.integer.value[1])); 19108c2ecf20Sopenharmony_ci unsigned int old = snd_cs46xx_peek(chip, reg); 19118c2ecf20Sopenharmony_ci int change = (old != val); 19128c2ecf20Sopenharmony_ci 19138c2ecf20Sopenharmony_ci if (change) { 19148c2ecf20Sopenharmony_ci snd_cs46xx_poke(chip, reg, val); 19158c2ecf20Sopenharmony_ci } 19168c2ecf20Sopenharmony_ci 19178c2ecf20Sopenharmony_ci return change; 19188c2ecf20Sopenharmony_ci} 19198c2ecf20Sopenharmony_ci 19208c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 19218c2ecf20Sopenharmony_ci 19228c2ecf20Sopenharmony_cistatic int snd_cs46xx_vol_dac_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 19238c2ecf20Sopenharmony_ci{ 19248c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = snd_kcontrol_chip(kcontrol); 19258c2ecf20Sopenharmony_ci 19268c2ecf20Sopenharmony_ci ucontrol->value.integer.value[0] = chip->dsp_spos_instance->dac_volume_left; 19278c2ecf20Sopenharmony_ci ucontrol->value.integer.value[1] = chip->dsp_spos_instance->dac_volume_right; 19288c2ecf20Sopenharmony_ci 19298c2ecf20Sopenharmony_ci return 0; 19308c2ecf20Sopenharmony_ci} 19318c2ecf20Sopenharmony_ci 19328c2ecf20Sopenharmony_cistatic int snd_cs46xx_vol_dac_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 19338c2ecf20Sopenharmony_ci{ 19348c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = snd_kcontrol_chip(kcontrol); 19358c2ecf20Sopenharmony_ci int change = 0; 19368c2ecf20Sopenharmony_ci 19378c2ecf20Sopenharmony_ci if (chip->dsp_spos_instance->dac_volume_right != ucontrol->value.integer.value[0] || 19388c2ecf20Sopenharmony_ci chip->dsp_spos_instance->dac_volume_left != ucontrol->value.integer.value[1]) { 19398c2ecf20Sopenharmony_ci cs46xx_dsp_set_dac_volume(chip, 19408c2ecf20Sopenharmony_ci ucontrol->value.integer.value[0], 19418c2ecf20Sopenharmony_ci ucontrol->value.integer.value[1]); 19428c2ecf20Sopenharmony_ci change = 1; 19438c2ecf20Sopenharmony_ci } 19448c2ecf20Sopenharmony_ci 19458c2ecf20Sopenharmony_ci return change; 19468c2ecf20Sopenharmony_ci} 19478c2ecf20Sopenharmony_ci 19488c2ecf20Sopenharmony_ci#if 0 19498c2ecf20Sopenharmony_cistatic int snd_cs46xx_vol_iec958_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 19508c2ecf20Sopenharmony_ci{ 19518c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = snd_kcontrol_chip(kcontrol); 19528c2ecf20Sopenharmony_ci 19538c2ecf20Sopenharmony_ci ucontrol->value.integer.value[0] = chip->dsp_spos_instance->spdif_input_volume_left; 19548c2ecf20Sopenharmony_ci ucontrol->value.integer.value[1] = chip->dsp_spos_instance->spdif_input_volume_right; 19558c2ecf20Sopenharmony_ci return 0; 19568c2ecf20Sopenharmony_ci} 19578c2ecf20Sopenharmony_ci 19588c2ecf20Sopenharmony_cistatic int snd_cs46xx_vol_iec958_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 19598c2ecf20Sopenharmony_ci{ 19608c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = snd_kcontrol_chip(kcontrol); 19618c2ecf20Sopenharmony_ci int change = 0; 19628c2ecf20Sopenharmony_ci 19638c2ecf20Sopenharmony_ci if (chip->dsp_spos_instance->spdif_input_volume_left != ucontrol->value.integer.value[0] || 19648c2ecf20Sopenharmony_ci chip->dsp_spos_instance->spdif_input_volume_right!= ucontrol->value.integer.value[1]) { 19658c2ecf20Sopenharmony_ci cs46xx_dsp_set_iec958_volume (chip, 19668c2ecf20Sopenharmony_ci ucontrol->value.integer.value[0], 19678c2ecf20Sopenharmony_ci ucontrol->value.integer.value[1]); 19688c2ecf20Sopenharmony_ci change = 1; 19698c2ecf20Sopenharmony_ci } 19708c2ecf20Sopenharmony_ci 19718c2ecf20Sopenharmony_ci return change; 19728c2ecf20Sopenharmony_ci} 19738c2ecf20Sopenharmony_ci#endif 19748c2ecf20Sopenharmony_ci 19758c2ecf20Sopenharmony_ci#define snd_mixer_boolean_info snd_ctl_boolean_mono_info 19768c2ecf20Sopenharmony_ci 19778c2ecf20Sopenharmony_cistatic int snd_cs46xx_iec958_get(struct snd_kcontrol *kcontrol, 19788c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 19798c2ecf20Sopenharmony_ci{ 19808c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = snd_kcontrol_chip(kcontrol); 19818c2ecf20Sopenharmony_ci int reg = kcontrol->private_value; 19828c2ecf20Sopenharmony_ci 19838c2ecf20Sopenharmony_ci if (reg == CS46XX_MIXER_SPDIF_OUTPUT_ELEMENT) 19848c2ecf20Sopenharmony_ci ucontrol->value.integer.value[0] = (chip->dsp_spos_instance->spdif_status_out & DSP_SPDIF_STATUS_OUTPUT_ENABLED); 19858c2ecf20Sopenharmony_ci else 19868c2ecf20Sopenharmony_ci ucontrol->value.integer.value[0] = chip->dsp_spos_instance->spdif_status_in; 19878c2ecf20Sopenharmony_ci 19888c2ecf20Sopenharmony_ci return 0; 19898c2ecf20Sopenharmony_ci} 19908c2ecf20Sopenharmony_ci 19918c2ecf20Sopenharmony_cistatic int snd_cs46xx_iec958_put(struct snd_kcontrol *kcontrol, 19928c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 19938c2ecf20Sopenharmony_ci{ 19948c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = snd_kcontrol_chip(kcontrol); 19958c2ecf20Sopenharmony_ci int change, res; 19968c2ecf20Sopenharmony_ci 19978c2ecf20Sopenharmony_ci switch (kcontrol->private_value) { 19988c2ecf20Sopenharmony_ci case CS46XX_MIXER_SPDIF_OUTPUT_ELEMENT: 19998c2ecf20Sopenharmony_ci mutex_lock(&chip->spos_mutex); 20008c2ecf20Sopenharmony_ci change = (chip->dsp_spos_instance->spdif_status_out & DSP_SPDIF_STATUS_OUTPUT_ENABLED); 20018c2ecf20Sopenharmony_ci if (ucontrol->value.integer.value[0] && !change) 20028c2ecf20Sopenharmony_ci cs46xx_dsp_enable_spdif_out(chip); 20038c2ecf20Sopenharmony_ci else if (change && !ucontrol->value.integer.value[0]) 20048c2ecf20Sopenharmony_ci cs46xx_dsp_disable_spdif_out(chip); 20058c2ecf20Sopenharmony_ci 20068c2ecf20Sopenharmony_ci res = (change != (chip->dsp_spos_instance->spdif_status_out & DSP_SPDIF_STATUS_OUTPUT_ENABLED)); 20078c2ecf20Sopenharmony_ci mutex_unlock(&chip->spos_mutex); 20088c2ecf20Sopenharmony_ci break; 20098c2ecf20Sopenharmony_ci case CS46XX_MIXER_SPDIF_INPUT_ELEMENT: 20108c2ecf20Sopenharmony_ci change = chip->dsp_spos_instance->spdif_status_in; 20118c2ecf20Sopenharmony_ci if (ucontrol->value.integer.value[0] && !change) { 20128c2ecf20Sopenharmony_ci cs46xx_dsp_enable_spdif_in(chip); 20138c2ecf20Sopenharmony_ci /* restore volume */ 20148c2ecf20Sopenharmony_ci } 20158c2ecf20Sopenharmony_ci else if (change && !ucontrol->value.integer.value[0]) 20168c2ecf20Sopenharmony_ci cs46xx_dsp_disable_spdif_in(chip); 20178c2ecf20Sopenharmony_ci 20188c2ecf20Sopenharmony_ci res = (change != chip->dsp_spos_instance->spdif_status_in); 20198c2ecf20Sopenharmony_ci break; 20208c2ecf20Sopenharmony_ci default: 20218c2ecf20Sopenharmony_ci res = -EINVAL; 20228c2ecf20Sopenharmony_ci snd_BUG(); /* should never happen ... */ 20238c2ecf20Sopenharmony_ci } 20248c2ecf20Sopenharmony_ci 20258c2ecf20Sopenharmony_ci return res; 20268c2ecf20Sopenharmony_ci} 20278c2ecf20Sopenharmony_ci 20288c2ecf20Sopenharmony_cistatic int snd_cs46xx_adc_capture_get(struct snd_kcontrol *kcontrol, 20298c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 20308c2ecf20Sopenharmony_ci{ 20318c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = snd_kcontrol_chip(kcontrol); 20328c2ecf20Sopenharmony_ci struct dsp_spos_instance * ins = chip->dsp_spos_instance; 20338c2ecf20Sopenharmony_ci 20348c2ecf20Sopenharmony_ci if (ins->adc_input != NULL) 20358c2ecf20Sopenharmony_ci ucontrol->value.integer.value[0] = 1; 20368c2ecf20Sopenharmony_ci else 20378c2ecf20Sopenharmony_ci ucontrol->value.integer.value[0] = 0; 20388c2ecf20Sopenharmony_ci 20398c2ecf20Sopenharmony_ci return 0; 20408c2ecf20Sopenharmony_ci} 20418c2ecf20Sopenharmony_ci 20428c2ecf20Sopenharmony_cistatic int snd_cs46xx_adc_capture_put(struct snd_kcontrol *kcontrol, 20438c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 20448c2ecf20Sopenharmony_ci{ 20458c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = snd_kcontrol_chip(kcontrol); 20468c2ecf20Sopenharmony_ci struct dsp_spos_instance * ins = chip->dsp_spos_instance; 20478c2ecf20Sopenharmony_ci int change = 0; 20488c2ecf20Sopenharmony_ci 20498c2ecf20Sopenharmony_ci if (ucontrol->value.integer.value[0] && !ins->adc_input) { 20508c2ecf20Sopenharmony_ci cs46xx_dsp_enable_adc_capture(chip); 20518c2ecf20Sopenharmony_ci change = 1; 20528c2ecf20Sopenharmony_ci } else if (!ucontrol->value.integer.value[0] && ins->adc_input) { 20538c2ecf20Sopenharmony_ci cs46xx_dsp_disable_adc_capture(chip); 20548c2ecf20Sopenharmony_ci change = 1; 20558c2ecf20Sopenharmony_ci } 20568c2ecf20Sopenharmony_ci return change; 20578c2ecf20Sopenharmony_ci} 20588c2ecf20Sopenharmony_ci 20598c2ecf20Sopenharmony_cistatic int snd_cs46xx_pcm_capture_get(struct snd_kcontrol *kcontrol, 20608c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 20618c2ecf20Sopenharmony_ci{ 20628c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = snd_kcontrol_chip(kcontrol); 20638c2ecf20Sopenharmony_ci struct dsp_spos_instance * ins = chip->dsp_spos_instance; 20648c2ecf20Sopenharmony_ci 20658c2ecf20Sopenharmony_ci if (ins->pcm_input != NULL) 20668c2ecf20Sopenharmony_ci ucontrol->value.integer.value[0] = 1; 20678c2ecf20Sopenharmony_ci else 20688c2ecf20Sopenharmony_ci ucontrol->value.integer.value[0] = 0; 20698c2ecf20Sopenharmony_ci 20708c2ecf20Sopenharmony_ci return 0; 20718c2ecf20Sopenharmony_ci} 20728c2ecf20Sopenharmony_ci 20738c2ecf20Sopenharmony_ci 20748c2ecf20Sopenharmony_cistatic int snd_cs46xx_pcm_capture_put(struct snd_kcontrol *kcontrol, 20758c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 20768c2ecf20Sopenharmony_ci{ 20778c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = snd_kcontrol_chip(kcontrol); 20788c2ecf20Sopenharmony_ci struct dsp_spos_instance * ins = chip->dsp_spos_instance; 20798c2ecf20Sopenharmony_ci int change = 0; 20808c2ecf20Sopenharmony_ci 20818c2ecf20Sopenharmony_ci if (ucontrol->value.integer.value[0] && !ins->pcm_input) { 20828c2ecf20Sopenharmony_ci cs46xx_dsp_enable_pcm_capture(chip); 20838c2ecf20Sopenharmony_ci change = 1; 20848c2ecf20Sopenharmony_ci } else if (!ucontrol->value.integer.value[0] && ins->pcm_input) { 20858c2ecf20Sopenharmony_ci cs46xx_dsp_disable_pcm_capture(chip); 20868c2ecf20Sopenharmony_ci change = 1; 20878c2ecf20Sopenharmony_ci } 20888c2ecf20Sopenharmony_ci 20898c2ecf20Sopenharmony_ci return change; 20908c2ecf20Sopenharmony_ci} 20918c2ecf20Sopenharmony_ci 20928c2ecf20Sopenharmony_cistatic int snd_herc_spdif_select_get(struct snd_kcontrol *kcontrol, 20938c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 20948c2ecf20Sopenharmony_ci{ 20958c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = snd_kcontrol_chip(kcontrol); 20968c2ecf20Sopenharmony_ci 20978c2ecf20Sopenharmony_ci int val1 = snd_cs46xx_peekBA0(chip, BA0_EGPIODR); 20988c2ecf20Sopenharmony_ci 20998c2ecf20Sopenharmony_ci if (val1 & EGPIODR_GPOE0) 21008c2ecf20Sopenharmony_ci ucontrol->value.integer.value[0] = 1; 21018c2ecf20Sopenharmony_ci else 21028c2ecf20Sopenharmony_ci ucontrol->value.integer.value[0] = 0; 21038c2ecf20Sopenharmony_ci 21048c2ecf20Sopenharmony_ci return 0; 21058c2ecf20Sopenharmony_ci} 21068c2ecf20Sopenharmony_ci 21078c2ecf20Sopenharmony_ci/* 21088c2ecf20Sopenharmony_ci * Game Theatre XP card - EGPIO[0] is used to select SPDIF input optical or coaxial. 21098c2ecf20Sopenharmony_ci */ 21108c2ecf20Sopenharmony_cistatic int snd_herc_spdif_select_put(struct snd_kcontrol *kcontrol, 21118c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 21128c2ecf20Sopenharmony_ci{ 21138c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = snd_kcontrol_chip(kcontrol); 21148c2ecf20Sopenharmony_ci int val1 = snd_cs46xx_peekBA0(chip, BA0_EGPIODR); 21158c2ecf20Sopenharmony_ci int val2 = snd_cs46xx_peekBA0(chip, BA0_EGPIOPTR); 21168c2ecf20Sopenharmony_ci 21178c2ecf20Sopenharmony_ci if (ucontrol->value.integer.value[0]) { 21188c2ecf20Sopenharmony_ci /* optical is default */ 21198c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_EGPIODR, 21208c2ecf20Sopenharmony_ci EGPIODR_GPOE0 | val1); /* enable EGPIO0 output */ 21218c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_EGPIOPTR, 21228c2ecf20Sopenharmony_ci EGPIOPTR_GPPT0 | val2); /* open-drain on output */ 21238c2ecf20Sopenharmony_ci } else { 21248c2ecf20Sopenharmony_ci /* coaxial */ 21258c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_EGPIODR, val1 & ~EGPIODR_GPOE0); /* disable */ 21268c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_EGPIOPTR, val2 & ~EGPIOPTR_GPPT0); /* disable */ 21278c2ecf20Sopenharmony_ci } 21288c2ecf20Sopenharmony_ci 21298c2ecf20Sopenharmony_ci /* checking diff from the EGPIO direction register 21308c2ecf20Sopenharmony_ci should be enough */ 21318c2ecf20Sopenharmony_ci return (val1 != (int)snd_cs46xx_peekBA0(chip, BA0_EGPIODR)); 21328c2ecf20Sopenharmony_ci} 21338c2ecf20Sopenharmony_ci 21348c2ecf20Sopenharmony_ci 21358c2ecf20Sopenharmony_cistatic int snd_cs46xx_spdif_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 21368c2ecf20Sopenharmony_ci{ 21378c2ecf20Sopenharmony_ci uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; 21388c2ecf20Sopenharmony_ci uinfo->count = 1; 21398c2ecf20Sopenharmony_ci return 0; 21408c2ecf20Sopenharmony_ci} 21418c2ecf20Sopenharmony_ci 21428c2ecf20Sopenharmony_cistatic int snd_cs46xx_spdif_default_get(struct snd_kcontrol *kcontrol, 21438c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 21448c2ecf20Sopenharmony_ci{ 21458c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = snd_kcontrol_chip(kcontrol); 21468c2ecf20Sopenharmony_ci struct dsp_spos_instance * ins = chip->dsp_spos_instance; 21478c2ecf20Sopenharmony_ci 21488c2ecf20Sopenharmony_ci mutex_lock(&chip->spos_mutex); 21498c2ecf20Sopenharmony_ci ucontrol->value.iec958.status[0] = _wrap_all_bits((ins->spdif_csuv_default >> 24) & 0xff); 21508c2ecf20Sopenharmony_ci ucontrol->value.iec958.status[1] = _wrap_all_bits((ins->spdif_csuv_default >> 16) & 0xff); 21518c2ecf20Sopenharmony_ci ucontrol->value.iec958.status[2] = 0; 21528c2ecf20Sopenharmony_ci ucontrol->value.iec958.status[3] = _wrap_all_bits((ins->spdif_csuv_default) & 0xff); 21538c2ecf20Sopenharmony_ci mutex_unlock(&chip->spos_mutex); 21548c2ecf20Sopenharmony_ci 21558c2ecf20Sopenharmony_ci return 0; 21568c2ecf20Sopenharmony_ci} 21578c2ecf20Sopenharmony_ci 21588c2ecf20Sopenharmony_cistatic int snd_cs46xx_spdif_default_put(struct snd_kcontrol *kcontrol, 21598c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 21608c2ecf20Sopenharmony_ci{ 21618c2ecf20Sopenharmony_ci struct snd_cs46xx * chip = snd_kcontrol_chip(kcontrol); 21628c2ecf20Sopenharmony_ci struct dsp_spos_instance * ins = chip->dsp_spos_instance; 21638c2ecf20Sopenharmony_ci unsigned int val; 21648c2ecf20Sopenharmony_ci int change; 21658c2ecf20Sopenharmony_ci 21668c2ecf20Sopenharmony_ci mutex_lock(&chip->spos_mutex); 21678c2ecf20Sopenharmony_ci val = ((unsigned int)_wrap_all_bits(ucontrol->value.iec958.status[0]) << 24) | 21688c2ecf20Sopenharmony_ci ((unsigned int)_wrap_all_bits(ucontrol->value.iec958.status[2]) << 16) | 21698c2ecf20Sopenharmony_ci ((unsigned int)_wrap_all_bits(ucontrol->value.iec958.status[3])) | 21708c2ecf20Sopenharmony_ci /* left and right validity bit */ 21718c2ecf20Sopenharmony_ci (1 << 13) | (1 << 12); 21728c2ecf20Sopenharmony_ci 21738c2ecf20Sopenharmony_ci 21748c2ecf20Sopenharmony_ci change = (unsigned int)ins->spdif_csuv_default != val; 21758c2ecf20Sopenharmony_ci ins->spdif_csuv_default = val; 21768c2ecf20Sopenharmony_ci 21778c2ecf20Sopenharmony_ci if ( !(ins->spdif_status_out & DSP_SPDIF_STATUS_PLAYBACK_OPEN) ) 21788c2ecf20Sopenharmony_ci cs46xx_poke_via_dsp (chip,SP_SPDOUT_CSUV,val); 21798c2ecf20Sopenharmony_ci 21808c2ecf20Sopenharmony_ci mutex_unlock(&chip->spos_mutex); 21818c2ecf20Sopenharmony_ci 21828c2ecf20Sopenharmony_ci return change; 21838c2ecf20Sopenharmony_ci} 21848c2ecf20Sopenharmony_ci 21858c2ecf20Sopenharmony_cistatic int snd_cs46xx_spdif_mask_get(struct snd_kcontrol *kcontrol, 21868c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 21878c2ecf20Sopenharmony_ci{ 21888c2ecf20Sopenharmony_ci ucontrol->value.iec958.status[0] = 0xff; 21898c2ecf20Sopenharmony_ci ucontrol->value.iec958.status[1] = 0xff; 21908c2ecf20Sopenharmony_ci ucontrol->value.iec958.status[2] = 0x00; 21918c2ecf20Sopenharmony_ci ucontrol->value.iec958.status[3] = 0xff; 21928c2ecf20Sopenharmony_ci return 0; 21938c2ecf20Sopenharmony_ci} 21948c2ecf20Sopenharmony_ci 21958c2ecf20Sopenharmony_cistatic int snd_cs46xx_spdif_stream_get(struct snd_kcontrol *kcontrol, 21968c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 21978c2ecf20Sopenharmony_ci{ 21988c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = snd_kcontrol_chip(kcontrol); 21998c2ecf20Sopenharmony_ci struct dsp_spos_instance * ins = chip->dsp_spos_instance; 22008c2ecf20Sopenharmony_ci 22018c2ecf20Sopenharmony_ci mutex_lock(&chip->spos_mutex); 22028c2ecf20Sopenharmony_ci ucontrol->value.iec958.status[0] = _wrap_all_bits((ins->spdif_csuv_stream >> 24) & 0xff); 22038c2ecf20Sopenharmony_ci ucontrol->value.iec958.status[1] = _wrap_all_bits((ins->spdif_csuv_stream >> 16) & 0xff); 22048c2ecf20Sopenharmony_ci ucontrol->value.iec958.status[2] = 0; 22058c2ecf20Sopenharmony_ci ucontrol->value.iec958.status[3] = _wrap_all_bits((ins->spdif_csuv_stream) & 0xff); 22068c2ecf20Sopenharmony_ci mutex_unlock(&chip->spos_mutex); 22078c2ecf20Sopenharmony_ci 22088c2ecf20Sopenharmony_ci return 0; 22098c2ecf20Sopenharmony_ci} 22108c2ecf20Sopenharmony_ci 22118c2ecf20Sopenharmony_cistatic int snd_cs46xx_spdif_stream_put(struct snd_kcontrol *kcontrol, 22128c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 22138c2ecf20Sopenharmony_ci{ 22148c2ecf20Sopenharmony_ci struct snd_cs46xx * chip = snd_kcontrol_chip(kcontrol); 22158c2ecf20Sopenharmony_ci struct dsp_spos_instance * ins = chip->dsp_spos_instance; 22168c2ecf20Sopenharmony_ci unsigned int val; 22178c2ecf20Sopenharmony_ci int change; 22188c2ecf20Sopenharmony_ci 22198c2ecf20Sopenharmony_ci mutex_lock(&chip->spos_mutex); 22208c2ecf20Sopenharmony_ci val = ((unsigned int)_wrap_all_bits(ucontrol->value.iec958.status[0]) << 24) | 22218c2ecf20Sopenharmony_ci ((unsigned int)_wrap_all_bits(ucontrol->value.iec958.status[1]) << 16) | 22228c2ecf20Sopenharmony_ci ((unsigned int)_wrap_all_bits(ucontrol->value.iec958.status[3])) | 22238c2ecf20Sopenharmony_ci /* left and right validity bit */ 22248c2ecf20Sopenharmony_ci (1 << 13) | (1 << 12); 22258c2ecf20Sopenharmony_ci 22268c2ecf20Sopenharmony_ci 22278c2ecf20Sopenharmony_ci change = ins->spdif_csuv_stream != val; 22288c2ecf20Sopenharmony_ci ins->spdif_csuv_stream = val; 22298c2ecf20Sopenharmony_ci 22308c2ecf20Sopenharmony_ci if ( ins->spdif_status_out & DSP_SPDIF_STATUS_PLAYBACK_OPEN ) 22318c2ecf20Sopenharmony_ci cs46xx_poke_via_dsp (chip,SP_SPDOUT_CSUV,val); 22328c2ecf20Sopenharmony_ci 22338c2ecf20Sopenharmony_ci mutex_unlock(&chip->spos_mutex); 22348c2ecf20Sopenharmony_ci 22358c2ecf20Sopenharmony_ci return change; 22368c2ecf20Sopenharmony_ci} 22378c2ecf20Sopenharmony_ci 22388c2ecf20Sopenharmony_ci#endif /* CONFIG_SND_CS46XX_NEW_DSP */ 22398c2ecf20Sopenharmony_ci 22408c2ecf20Sopenharmony_ci 22418c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new snd_cs46xx_controls[] = { 22428c2ecf20Sopenharmony_ci{ 22438c2ecf20Sopenharmony_ci .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 22448c2ecf20Sopenharmony_ci .name = "DAC Volume", 22458c2ecf20Sopenharmony_ci .info = snd_cs46xx_vol_info, 22468c2ecf20Sopenharmony_ci#ifndef CONFIG_SND_CS46XX_NEW_DSP 22478c2ecf20Sopenharmony_ci .get = snd_cs46xx_vol_get, 22488c2ecf20Sopenharmony_ci .put = snd_cs46xx_vol_put, 22498c2ecf20Sopenharmony_ci .private_value = BA1_PVOL, 22508c2ecf20Sopenharmony_ci#else 22518c2ecf20Sopenharmony_ci .get = snd_cs46xx_vol_dac_get, 22528c2ecf20Sopenharmony_ci .put = snd_cs46xx_vol_dac_put, 22538c2ecf20Sopenharmony_ci#endif 22548c2ecf20Sopenharmony_ci}, 22558c2ecf20Sopenharmony_ci 22568c2ecf20Sopenharmony_ci{ 22578c2ecf20Sopenharmony_ci .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 22588c2ecf20Sopenharmony_ci .name = "ADC Volume", 22598c2ecf20Sopenharmony_ci .info = snd_cs46xx_vol_info, 22608c2ecf20Sopenharmony_ci .get = snd_cs46xx_vol_get, 22618c2ecf20Sopenharmony_ci .put = snd_cs46xx_vol_put, 22628c2ecf20Sopenharmony_ci#ifndef CONFIG_SND_CS46XX_NEW_DSP 22638c2ecf20Sopenharmony_ci .private_value = BA1_CVOL, 22648c2ecf20Sopenharmony_ci#else 22658c2ecf20Sopenharmony_ci .private_value = (VARIDECIMATE_SCB_ADDR + 0xE) << 2, 22668c2ecf20Sopenharmony_ci#endif 22678c2ecf20Sopenharmony_ci}, 22688c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 22698c2ecf20Sopenharmony_ci{ 22708c2ecf20Sopenharmony_ci .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 22718c2ecf20Sopenharmony_ci .name = "ADC Capture Switch", 22728c2ecf20Sopenharmony_ci .info = snd_mixer_boolean_info, 22738c2ecf20Sopenharmony_ci .get = snd_cs46xx_adc_capture_get, 22748c2ecf20Sopenharmony_ci .put = snd_cs46xx_adc_capture_put 22758c2ecf20Sopenharmony_ci}, 22768c2ecf20Sopenharmony_ci{ 22778c2ecf20Sopenharmony_ci .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 22788c2ecf20Sopenharmony_ci .name = "DAC Capture Switch", 22798c2ecf20Sopenharmony_ci .info = snd_mixer_boolean_info, 22808c2ecf20Sopenharmony_ci .get = snd_cs46xx_pcm_capture_get, 22818c2ecf20Sopenharmony_ci .put = snd_cs46xx_pcm_capture_put 22828c2ecf20Sopenharmony_ci}, 22838c2ecf20Sopenharmony_ci{ 22848c2ecf20Sopenharmony_ci .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 22858c2ecf20Sopenharmony_ci .name = SNDRV_CTL_NAME_IEC958("Output ",NONE,SWITCH), 22868c2ecf20Sopenharmony_ci .info = snd_mixer_boolean_info, 22878c2ecf20Sopenharmony_ci .get = snd_cs46xx_iec958_get, 22888c2ecf20Sopenharmony_ci .put = snd_cs46xx_iec958_put, 22898c2ecf20Sopenharmony_ci .private_value = CS46XX_MIXER_SPDIF_OUTPUT_ELEMENT, 22908c2ecf20Sopenharmony_ci}, 22918c2ecf20Sopenharmony_ci{ 22928c2ecf20Sopenharmony_ci .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 22938c2ecf20Sopenharmony_ci .name = SNDRV_CTL_NAME_IEC958("Input ",NONE,SWITCH), 22948c2ecf20Sopenharmony_ci .info = snd_mixer_boolean_info, 22958c2ecf20Sopenharmony_ci .get = snd_cs46xx_iec958_get, 22968c2ecf20Sopenharmony_ci .put = snd_cs46xx_iec958_put, 22978c2ecf20Sopenharmony_ci .private_value = CS46XX_MIXER_SPDIF_INPUT_ELEMENT, 22988c2ecf20Sopenharmony_ci}, 22998c2ecf20Sopenharmony_ci#if 0 23008c2ecf20Sopenharmony_ci/* Input IEC958 volume does not work for the moment. (Benny) */ 23018c2ecf20Sopenharmony_ci{ 23028c2ecf20Sopenharmony_ci .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 23038c2ecf20Sopenharmony_ci .name = SNDRV_CTL_NAME_IEC958("Input ",NONE,VOLUME), 23048c2ecf20Sopenharmony_ci .info = snd_cs46xx_vol_info, 23058c2ecf20Sopenharmony_ci .get = snd_cs46xx_vol_iec958_get, 23068c2ecf20Sopenharmony_ci .put = snd_cs46xx_vol_iec958_put, 23078c2ecf20Sopenharmony_ci .private_value = (ASYNCRX_SCB_ADDR + 0xE) << 2, 23088c2ecf20Sopenharmony_ci}, 23098c2ecf20Sopenharmony_ci#endif 23108c2ecf20Sopenharmony_ci{ 23118c2ecf20Sopenharmony_ci .iface = SNDRV_CTL_ELEM_IFACE_PCM, 23128c2ecf20Sopenharmony_ci .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT), 23138c2ecf20Sopenharmony_ci .info = snd_cs46xx_spdif_info, 23148c2ecf20Sopenharmony_ci .get = snd_cs46xx_spdif_default_get, 23158c2ecf20Sopenharmony_ci .put = snd_cs46xx_spdif_default_put, 23168c2ecf20Sopenharmony_ci}, 23178c2ecf20Sopenharmony_ci{ 23188c2ecf20Sopenharmony_ci .iface = SNDRV_CTL_ELEM_IFACE_PCM, 23198c2ecf20Sopenharmony_ci .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK), 23208c2ecf20Sopenharmony_ci .info = snd_cs46xx_spdif_info, 23218c2ecf20Sopenharmony_ci .get = snd_cs46xx_spdif_mask_get, 23228c2ecf20Sopenharmony_ci .access = SNDRV_CTL_ELEM_ACCESS_READ 23238c2ecf20Sopenharmony_ci}, 23248c2ecf20Sopenharmony_ci{ 23258c2ecf20Sopenharmony_ci .iface = SNDRV_CTL_ELEM_IFACE_PCM, 23268c2ecf20Sopenharmony_ci .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM), 23278c2ecf20Sopenharmony_ci .info = snd_cs46xx_spdif_info, 23288c2ecf20Sopenharmony_ci .get = snd_cs46xx_spdif_stream_get, 23298c2ecf20Sopenharmony_ci .put = snd_cs46xx_spdif_stream_put 23308c2ecf20Sopenharmony_ci}, 23318c2ecf20Sopenharmony_ci 23328c2ecf20Sopenharmony_ci#endif 23338c2ecf20Sopenharmony_ci}; 23348c2ecf20Sopenharmony_ci 23358c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 23368c2ecf20Sopenharmony_ci/* set primary cs4294 codec into Extended Audio Mode */ 23378c2ecf20Sopenharmony_cistatic int snd_cs46xx_front_dup_get(struct snd_kcontrol *kcontrol, 23388c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 23398c2ecf20Sopenharmony_ci{ 23408c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = snd_kcontrol_chip(kcontrol); 23418c2ecf20Sopenharmony_ci unsigned short val; 23428c2ecf20Sopenharmony_ci val = snd_ac97_read(chip->ac97[CS46XX_PRIMARY_CODEC_INDEX], AC97_CSR_ACMODE); 23438c2ecf20Sopenharmony_ci ucontrol->value.integer.value[0] = (val & 0x200) ? 0 : 1; 23448c2ecf20Sopenharmony_ci return 0; 23458c2ecf20Sopenharmony_ci} 23468c2ecf20Sopenharmony_ci 23478c2ecf20Sopenharmony_cistatic int snd_cs46xx_front_dup_put(struct snd_kcontrol *kcontrol, 23488c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 23498c2ecf20Sopenharmony_ci{ 23508c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = snd_kcontrol_chip(kcontrol); 23518c2ecf20Sopenharmony_ci return snd_ac97_update_bits(chip->ac97[CS46XX_PRIMARY_CODEC_INDEX], 23528c2ecf20Sopenharmony_ci AC97_CSR_ACMODE, 0x200, 23538c2ecf20Sopenharmony_ci ucontrol->value.integer.value[0] ? 0 : 0x200); 23548c2ecf20Sopenharmony_ci} 23558c2ecf20Sopenharmony_ci 23568c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new snd_cs46xx_front_dup_ctl = { 23578c2ecf20Sopenharmony_ci .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 23588c2ecf20Sopenharmony_ci .name = "Duplicate Front", 23598c2ecf20Sopenharmony_ci .info = snd_mixer_boolean_info, 23608c2ecf20Sopenharmony_ci .get = snd_cs46xx_front_dup_get, 23618c2ecf20Sopenharmony_ci .put = snd_cs46xx_front_dup_put, 23628c2ecf20Sopenharmony_ci}; 23638c2ecf20Sopenharmony_ci#endif 23648c2ecf20Sopenharmony_ci 23658c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 23668c2ecf20Sopenharmony_ci/* Only available on the Hercules Game Theater XP soundcard */ 23678c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new snd_hercules_controls[] = { 23688c2ecf20Sopenharmony_ci{ 23698c2ecf20Sopenharmony_ci .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 23708c2ecf20Sopenharmony_ci .name = "Optical/Coaxial SPDIF Input Switch", 23718c2ecf20Sopenharmony_ci .info = snd_mixer_boolean_info, 23728c2ecf20Sopenharmony_ci .get = snd_herc_spdif_select_get, 23738c2ecf20Sopenharmony_ci .put = snd_herc_spdif_select_put, 23748c2ecf20Sopenharmony_ci}, 23758c2ecf20Sopenharmony_ci}; 23768c2ecf20Sopenharmony_ci 23778c2ecf20Sopenharmony_ci 23788c2ecf20Sopenharmony_cistatic void snd_cs46xx_codec_reset (struct snd_ac97 * ac97) 23798c2ecf20Sopenharmony_ci{ 23808c2ecf20Sopenharmony_ci unsigned long end_time; 23818c2ecf20Sopenharmony_ci int err; 23828c2ecf20Sopenharmony_ci 23838c2ecf20Sopenharmony_ci /* reset to defaults */ 23848c2ecf20Sopenharmony_ci snd_ac97_write(ac97, AC97_RESET, 0); 23858c2ecf20Sopenharmony_ci 23868c2ecf20Sopenharmony_ci /* set the desired CODEC mode */ 23878c2ecf20Sopenharmony_ci if (ac97->num == CS46XX_PRIMARY_CODEC_INDEX) { 23888c2ecf20Sopenharmony_ci dev_dbg(ac97->bus->card->dev, "CODEC1 mode %04x\n", 0x0); 23898c2ecf20Sopenharmony_ci snd_cs46xx_ac97_write(ac97, AC97_CSR_ACMODE, 0x0); 23908c2ecf20Sopenharmony_ci } else if (ac97->num == CS46XX_SECONDARY_CODEC_INDEX) { 23918c2ecf20Sopenharmony_ci dev_dbg(ac97->bus->card->dev, "CODEC2 mode %04x\n", 0x3); 23928c2ecf20Sopenharmony_ci snd_cs46xx_ac97_write(ac97, AC97_CSR_ACMODE, 0x3); 23938c2ecf20Sopenharmony_ci } else { 23948c2ecf20Sopenharmony_ci snd_BUG(); /* should never happen ... */ 23958c2ecf20Sopenharmony_ci } 23968c2ecf20Sopenharmony_ci 23978c2ecf20Sopenharmony_ci udelay(50); 23988c2ecf20Sopenharmony_ci 23998c2ecf20Sopenharmony_ci /* it's necessary to wait awhile until registers are accessible after RESET */ 24008c2ecf20Sopenharmony_ci /* because the PCM or MASTER volume registers can be modified, */ 24018c2ecf20Sopenharmony_ci /* the REC_GAIN register is used for tests */ 24028c2ecf20Sopenharmony_ci end_time = jiffies + HZ; 24038c2ecf20Sopenharmony_ci do { 24048c2ecf20Sopenharmony_ci unsigned short ext_mid; 24058c2ecf20Sopenharmony_ci 24068c2ecf20Sopenharmony_ci /* use preliminary reads to settle the communication */ 24078c2ecf20Sopenharmony_ci snd_ac97_read(ac97, AC97_RESET); 24088c2ecf20Sopenharmony_ci snd_ac97_read(ac97, AC97_VENDOR_ID1); 24098c2ecf20Sopenharmony_ci snd_ac97_read(ac97, AC97_VENDOR_ID2); 24108c2ecf20Sopenharmony_ci /* modem? */ 24118c2ecf20Sopenharmony_ci ext_mid = snd_ac97_read(ac97, AC97_EXTENDED_MID); 24128c2ecf20Sopenharmony_ci if (ext_mid != 0xffff && (ext_mid & 1) != 0) 24138c2ecf20Sopenharmony_ci return; 24148c2ecf20Sopenharmony_ci 24158c2ecf20Sopenharmony_ci /* test if we can write to the record gain volume register */ 24168c2ecf20Sopenharmony_ci snd_ac97_write(ac97, AC97_REC_GAIN, 0x8a05); 24178c2ecf20Sopenharmony_ci if ((err = snd_ac97_read(ac97, AC97_REC_GAIN)) == 0x8a05) 24188c2ecf20Sopenharmony_ci return; 24198c2ecf20Sopenharmony_ci 24208c2ecf20Sopenharmony_ci msleep(10); 24218c2ecf20Sopenharmony_ci } while (time_after_eq(end_time, jiffies)); 24228c2ecf20Sopenharmony_ci 24238c2ecf20Sopenharmony_ci dev_err(ac97->bus->card->dev, 24248c2ecf20Sopenharmony_ci "CS46xx secondary codec doesn't respond!\n"); 24258c2ecf20Sopenharmony_ci} 24268c2ecf20Sopenharmony_ci#endif 24278c2ecf20Sopenharmony_ci 24288c2ecf20Sopenharmony_cistatic int cs46xx_detect_codec(struct snd_cs46xx *chip, int codec) 24298c2ecf20Sopenharmony_ci{ 24308c2ecf20Sopenharmony_ci int idx, err; 24318c2ecf20Sopenharmony_ci struct snd_ac97_template ac97; 24328c2ecf20Sopenharmony_ci 24338c2ecf20Sopenharmony_ci memset(&ac97, 0, sizeof(ac97)); 24348c2ecf20Sopenharmony_ci ac97.private_data = chip; 24358c2ecf20Sopenharmony_ci ac97.private_free = snd_cs46xx_mixer_free_ac97; 24368c2ecf20Sopenharmony_ci ac97.num = codec; 24378c2ecf20Sopenharmony_ci if (chip->amplifier_ctrl == amp_voyetra) 24388c2ecf20Sopenharmony_ci ac97.scaps = AC97_SCAP_INV_EAPD; 24398c2ecf20Sopenharmony_ci 24408c2ecf20Sopenharmony_ci if (codec == CS46XX_SECONDARY_CODEC_INDEX) { 24418c2ecf20Sopenharmony_ci snd_cs46xx_codec_write(chip, AC97_RESET, 0, codec); 24428c2ecf20Sopenharmony_ci udelay(10); 24438c2ecf20Sopenharmony_ci if (snd_cs46xx_codec_read(chip, AC97_RESET, codec) & 0x8000) { 24448c2ecf20Sopenharmony_ci dev_dbg(chip->card->dev, 24458c2ecf20Sopenharmony_ci "secondary codec not present\n"); 24468c2ecf20Sopenharmony_ci return -ENXIO; 24478c2ecf20Sopenharmony_ci } 24488c2ecf20Sopenharmony_ci } 24498c2ecf20Sopenharmony_ci 24508c2ecf20Sopenharmony_ci snd_cs46xx_codec_write(chip, AC97_MASTER, 0x8000, codec); 24518c2ecf20Sopenharmony_ci for (idx = 0; idx < 100; ++idx) { 24528c2ecf20Sopenharmony_ci if (snd_cs46xx_codec_read(chip, AC97_MASTER, codec) == 0x8000) { 24538c2ecf20Sopenharmony_ci err = snd_ac97_mixer(chip->ac97_bus, &ac97, &chip->ac97[codec]); 24548c2ecf20Sopenharmony_ci return err; 24558c2ecf20Sopenharmony_ci } 24568c2ecf20Sopenharmony_ci msleep(10); 24578c2ecf20Sopenharmony_ci } 24588c2ecf20Sopenharmony_ci dev_dbg(chip->card->dev, "codec %d detection timeout\n", codec); 24598c2ecf20Sopenharmony_ci return -ENXIO; 24608c2ecf20Sopenharmony_ci} 24618c2ecf20Sopenharmony_ci 24628c2ecf20Sopenharmony_ciint snd_cs46xx_mixer(struct snd_cs46xx *chip, int spdif_device) 24638c2ecf20Sopenharmony_ci{ 24648c2ecf20Sopenharmony_ci struct snd_card *card = chip->card; 24658c2ecf20Sopenharmony_ci struct snd_ctl_elem_id id; 24668c2ecf20Sopenharmony_ci int err; 24678c2ecf20Sopenharmony_ci unsigned int idx; 24688c2ecf20Sopenharmony_ci static const struct snd_ac97_bus_ops ops = { 24698c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 24708c2ecf20Sopenharmony_ci .reset = snd_cs46xx_codec_reset, 24718c2ecf20Sopenharmony_ci#endif 24728c2ecf20Sopenharmony_ci .write = snd_cs46xx_ac97_write, 24738c2ecf20Sopenharmony_ci .read = snd_cs46xx_ac97_read, 24748c2ecf20Sopenharmony_ci }; 24758c2ecf20Sopenharmony_ci 24768c2ecf20Sopenharmony_ci /* detect primary codec */ 24778c2ecf20Sopenharmony_ci chip->nr_ac97_codecs = 0; 24788c2ecf20Sopenharmony_ci dev_dbg(chip->card->dev, "detecting primary codec\n"); 24798c2ecf20Sopenharmony_ci if ((err = snd_ac97_bus(card, 0, &ops, chip, &chip->ac97_bus)) < 0) 24808c2ecf20Sopenharmony_ci return err; 24818c2ecf20Sopenharmony_ci chip->ac97_bus->private_free = snd_cs46xx_mixer_free_ac97_bus; 24828c2ecf20Sopenharmony_ci 24838c2ecf20Sopenharmony_ci if (cs46xx_detect_codec(chip, CS46XX_PRIMARY_CODEC_INDEX) < 0) 24848c2ecf20Sopenharmony_ci return -ENXIO; 24858c2ecf20Sopenharmony_ci chip->nr_ac97_codecs = 1; 24868c2ecf20Sopenharmony_ci 24878c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 24888c2ecf20Sopenharmony_ci dev_dbg(chip->card->dev, "detecting secondary codec\n"); 24898c2ecf20Sopenharmony_ci /* try detect a secondary codec */ 24908c2ecf20Sopenharmony_ci if (! cs46xx_detect_codec(chip, CS46XX_SECONDARY_CODEC_INDEX)) 24918c2ecf20Sopenharmony_ci chip->nr_ac97_codecs = 2; 24928c2ecf20Sopenharmony_ci#endif /* CONFIG_SND_CS46XX_NEW_DSP */ 24938c2ecf20Sopenharmony_ci 24948c2ecf20Sopenharmony_ci /* add cs4630 mixer controls */ 24958c2ecf20Sopenharmony_ci for (idx = 0; idx < ARRAY_SIZE(snd_cs46xx_controls); idx++) { 24968c2ecf20Sopenharmony_ci struct snd_kcontrol *kctl; 24978c2ecf20Sopenharmony_ci kctl = snd_ctl_new1(&snd_cs46xx_controls[idx], chip); 24988c2ecf20Sopenharmony_ci if (kctl && kctl->id.iface == SNDRV_CTL_ELEM_IFACE_PCM) 24998c2ecf20Sopenharmony_ci kctl->id.device = spdif_device; 25008c2ecf20Sopenharmony_ci if ((err = snd_ctl_add(card, kctl)) < 0) 25018c2ecf20Sopenharmony_ci return err; 25028c2ecf20Sopenharmony_ci } 25038c2ecf20Sopenharmony_ci 25048c2ecf20Sopenharmony_ci /* get EAPD mixer switch (for voyetra hack) */ 25058c2ecf20Sopenharmony_ci memset(&id, 0, sizeof(id)); 25068c2ecf20Sopenharmony_ci id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; 25078c2ecf20Sopenharmony_ci strcpy(id.name, "External Amplifier"); 25088c2ecf20Sopenharmony_ci chip->eapd_switch = snd_ctl_find_id(chip->card, &id); 25098c2ecf20Sopenharmony_ci 25108c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 25118c2ecf20Sopenharmony_ci if (chip->nr_ac97_codecs == 1) { 25128c2ecf20Sopenharmony_ci unsigned int id2 = chip->ac97[CS46XX_PRIMARY_CODEC_INDEX]->id & 0xffff; 25138c2ecf20Sopenharmony_ci if ((id2 & 0xfff0) == 0x5920) { /* CS4294 and CS4298 */ 25148c2ecf20Sopenharmony_ci err = snd_ctl_add(card, snd_ctl_new1(&snd_cs46xx_front_dup_ctl, chip)); 25158c2ecf20Sopenharmony_ci if (err < 0) 25168c2ecf20Sopenharmony_ci return err; 25178c2ecf20Sopenharmony_ci snd_ac97_write_cache(chip->ac97[CS46XX_PRIMARY_CODEC_INDEX], 25188c2ecf20Sopenharmony_ci AC97_CSR_ACMODE, 0x200); 25198c2ecf20Sopenharmony_ci } 25208c2ecf20Sopenharmony_ci } 25218c2ecf20Sopenharmony_ci /* do soundcard specific mixer setup */ 25228c2ecf20Sopenharmony_ci if (chip->mixer_init) { 25238c2ecf20Sopenharmony_ci dev_dbg(chip->card->dev, "calling chip->mixer_init(chip);\n"); 25248c2ecf20Sopenharmony_ci chip->mixer_init(chip); 25258c2ecf20Sopenharmony_ci } 25268c2ecf20Sopenharmony_ci#endif 25278c2ecf20Sopenharmony_ci 25288c2ecf20Sopenharmony_ci /* turn on amplifier */ 25298c2ecf20Sopenharmony_ci chip->amplifier_ctrl(chip, 1); 25308c2ecf20Sopenharmony_ci 25318c2ecf20Sopenharmony_ci return 0; 25328c2ecf20Sopenharmony_ci} 25338c2ecf20Sopenharmony_ci 25348c2ecf20Sopenharmony_ci/* 25358c2ecf20Sopenharmony_ci * RawMIDI interface 25368c2ecf20Sopenharmony_ci */ 25378c2ecf20Sopenharmony_ci 25388c2ecf20Sopenharmony_cistatic void snd_cs46xx_midi_reset(struct snd_cs46xx *chip) 25398c2ecf20Sopenharmony_ci{ 25408c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_MIDCR, MIDCR_MRST); 25418c2ecf20Sopenharmony_ci udelay(100); 25428c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_MIDCR, chip->midcr); 25438c2ecf20Sopenharmony_ci} 25448c2ecf20Sopenharmony_ci 25458c2ecf20Sopenharmony_cistatic int snd_cs46xx_midi_input_open(struct snd_rawmidi_substream *substream) 25468c2ecf20Sopenharmony_ci{ 25478c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = substream->rmidi->private_data; 25488c2ecf20Sopenharmony_ci 25498c2ecf20Sopenharmony_ci chip->active_ctrl(chip, 1); 25508c2ecf20Sopenharmony_ci spin_lock_irq(&chip->reg_lock); 25518c2ecf20Sopenharmony_ci chip->uartm |= CS46XX_MODE_INPUT; 25528c2ecf20Sopenharmony_ci chip->midcr |= MIDCR_RXE; 25538c2ecf20Sopenharmony_ci chip->midi_input = substream; 25548c2ecf20Sopenharmony_ci if (!(chip->uartm & CS46XX_MODE_OUTPUT)) { 25558c2ecf20Sopenharmony_ci snd_cs46xx_midi_reset(chip); 25568c2ecf20Sopenharmony_ci } else { 25578c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_MIDCR, chip->midcr); 25588c2ecf20Sopenharmony_ci } 25598c2ecf20Sopenharmony_ci spin_unlock_irq(&chip->reg_lock); 25608c2ecf20Sopenharmony_ci return 0; 25618c2ecf20Sopenharmony_ci} 25628c2ecf20Sopenharmony_ci 25638c2ecf20Sopenharmony_cistatic int snd_cs46xx_midi_input_close(struct snd_rawmidi_substream *substream) 25648c2ecf20Sopenharmony_ci{ 25658c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = substream->rmidi->private_data; 25668c2ecf20Sopenharmony_ci 25678c2ecf20Sopenharmony_ci spin_lock_irq(&chip->reg_lock); 25688c2ecf20Sopenharmony_ci chip->midcr &= ~(MIDCR_RXE | MIDCR_RIE); 25698c2ecf20Sopenharmony_ci chip->midi_input = NULL; 25708c2ecf20Sopenharmony_ci if (!(chip->uartm & CS46XX_MODE_OUTPUT)) { 25718c2ecf20Sopenharmony_ci snd_cs46xx_midi_reset(chip); 25728c2ecf20Sopenharmony_ci } else { 25738c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_MIDCR, chip->midcr); 25748c2ecf20Sopenharmony_ci } 25758c2ecf20Sopenharmony_ci chip->uartm &= ~CS46XX_MODE_INPUT; 25768c2ecf20Sopenharmony_ci spin_unlock_irq(&chip->reg_lock); 25778c2ecf20Sopenharmony_ci chip->active_ctrl(chip, -1); 25788c2ecf20Sopenharmony_ci return 0; 25798c2ecf20Sopenharmony_ci} 25808c2ecf20Sopenharmony_ci 25818c2ecf20Sopenharmony_cistatic int snd_cs46xx_midi_output_open(struct snd_rawmidi_substream *substream) 25828c2ecf20Sopenharmony_ci{ 25838c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = substream->rmidi->private_data; 25848c2ecf20Sopenharmony_ci 25858c2ecf20Sopenharmony_ci chip->active_ctrl(chip, 1); 25868c2ecf20Sopenharmony_ci 25878c2ecf20Sopenharmony_ci spin_lock_irq(&chip->reg_lock); 25888c2ecf20Sopenharmony_ci chip->uartm |= CS46XX_MODE_OUTPUT; 25898c2ecf20Sopenharmony_ci chip->midcr |= MIDCR_TXE; 25908c2ecf20Sopenharmony_ci chip->midi_output = substream; 25918c2ecf20Sopenharmony_ci if (!(chip->uartm & CS46XX_MODE_INPUT)) { 25928c2ecf20Sopenharmony_ci snd_cs46xx_midi_reset(chip); 25938c2ecf20Sopenharmony_ci } else { 25948c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_MIDCR, chip->midcr); 25958c2ecf20Sopenharmony_ci } 25968c2ecf20Sopenharmony_ci spin_unlock_irq(&chip->reg_lock); 25978c2ecf20Sopenharmony_ci return 0; 25988c2ecf20Sopenharmony_ci} 25998c2ecf20Sopenharmony_ci 26008c2ecf20Sopenharmony_cistatic int snd_cs46xx_midi_output_close(struct snd_rawmidi_substream *substream) 26018c2ecf20Sopenharmony_ci{ 26028c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = substream->rmidi->private_data; 26038c2ecf20Sopenharmony_ci 26048c2ecf20Sopenharmony_ci spin_lock_irq(&chip->reg_lock); 26058c2ecf20Sopenharmony_ci chip->midcr &= ~(MIDCR_TXE | MIDCR_TIE); 26068c2ecf20Sopenharmony_ci chip->midi_output = NULL; 26078c2ecf20Sopenharmony_ci if (!(chip->uartm & CS46XX_MODE_INPUT)) { 26088c2ecf20Sopenharmony_ci snd_cs46xx_midi_reset(chip); 26098c2ecf20Sopenharmony_ci } else { 26108c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_MIDCR, chip->midcr); 26118c2ecf20Sopenharmony_ci } 26128c2ecf20Sopenharmony_ci chip->uartm &= ~CS46XX_MODE_OUTPUT; 26138c2ecf20Sopenharmony_ci spin_unlock_irq(&chip->reg_lock); 26148c2ecf20Sopenharmony_ci chip->active_ctrl(chip, -1); 26158c2ecf20Sopenharmony_ci return 0; 26168c2ecf20Sopenharmony_ci} 26178c2ecf20Sopenharmony_ci 26188c2ecf20Sopenharmony_cistatic void snd_cs46xx_midi_input_trigger(struct snd_rawmidi_substream *substream, int up) 26198c2ecf20Sopenharmony_ci{ 26208c2ecf20Sopenharmony_ci unsigned long flags; 26218c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = substream->rmidi->private_data; 26228c2ecf20Sopenharmony_ci 26238c2ecf20Sopenharmony_ci spin_lock_irqsave(&chip->reg_lock, flags); 26248c2ecf20Sopenharmony_ci if (up) { 26258c2ecf20Sopenharmony_ci if ((chip->midcr & MIDCR_RIE) == 0) { 26268c2ecf20Sopenharmony_ci chip->midcr |= MIDCR_RIE; 26278c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_MIDCR, chip->midcr); 26288c2ecf20Sopenharmony_ci } 26298c2ecf20Sopenharmony_ci } else { 26308c2ecf20Sopenharmony_ci if (chip->midcr & MIDCR_RIE) { 26318c2ecf20Sopenharmony_ci chip->midcr &= ~MIDCR_RIE; 26328c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_MIDCR, chip->midcr); 26338c2ecf20Sopenharmony_ci } 26348c2ecf20Sopenharmony_ci } 26358c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&chip->reg_lock, flags); 26368c2ecf20Sopenharmony_ci} 26378c2ecf20Sopenharmony_ci 26388c2ecf20Sopenharmony_cistatic void snd_cs46xx_midi_output_trigger(struct snd_rawmidi_substream *substream, int up) 26398c2ecf20Sopenharmony_ci{ 26408c2ecf20Sopenharmony_ci unsigned long flags; 26418c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = substream->rmidi->private_data; 26428c2ecf20Sopenharmony_ci unsigned char byte; 26438c2ecf20Sopenharmony_ci 26448c2ecf20Sopenharmony_ci spin_lock_irqsave(&chip->reg_lock, flags); 26458c2ecf20Sopenharmony_ci if (up) { 26468c2ecf20Sopenharmony_ci if ((chip->midcr & MIDCR_TIE) == 0) { 26478c2ecf20Sopenharmony_ci chip->midcr |= MIDCR_TIE; 26488c2ecf20Sopenharmony_ci /* fill UART FIFO buffer at first, and turn Tx interrupts only if necessary */ 26498c2ecf20Sopenharmony_ci while ((chip->midcr & MIDCR_TIE) && 26508c2ecf20Sopenharmony_ci (snd_cs46xx_peekBA0(chip, BA0_MIDSR) & MIDSR_TBF) == 0) { 26518c2ecf20Sopenharmony_ci if (snd_rawmidi_transmit(substream, &byte, 1) != 1) { 26528c2ecf20Sopenharmony_ci chip->midcr &= ~MIDCR_TIE; 26538c2ecf20Sopenharmony_ci } else { 26548c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_MIDWP, byte); 26558c2ecf20Sopenharmony_ci } 26568c2ecf20Sopenharmony_ci } 26578c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_MIDCR, chip->midcr); 26588c2ecf20Sopenharmony_ci } 26598c2ecf20Sopenharmony_ci } else { 26608c2ecf20Sopenharmony_ci if (chip->midcr & MIDCR_TIE) { 26618c2ecf20Sopenharmony_ci chip->midcr &= ~MIDCR_TIE; 26628c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_MIDCR, chip->midcr); 26638c2ecf20Sopenharmony_ci } 26648c2ecf20Sopenharmony_ci } 26658c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&chip->reg_lock, flags); 26668c2ecf20Sopenharmony_ci} 26678c2ecf20Sopenharmony_ci 26688c2ecf20Sopenharmony_cistatic const struct snd_rawmidi_ops snd_cs46xx_midi_output = 26698c2ecf20Sopenharmony_ci{ 26708c2ecf20Sopenharmony_ci .open = snd_cs46xx_midi_output_open, 26718c2ecf20Sopenharmony_ci .close = snd_cs46xx_midi_output_close, 26728c2ecf20Sopenharmony_ci .trigger = snd_cs46xx_midi_output_trigger, 26738c2ecf20Sopenharmony_ci}; 26748c2ecf20Sopenharmony_ci 26758c2ecf20Sopenharmony_cistatic const struct snd_rawmidi_ops snd_cs46xx_midi_input = 26768c2ecf20Sopenharmony_ci{ 26778c2ecf20Sopenharmony_ci .open = snd_cs46xx_midi_input_open, 26788c2ecf20Sopenharmony_ci .close = snd_cs46xx_midi_input_close, 26798c2ecf20Sopenharmony_ci .trigger = snd_cs46xx_midi_input_trigger, 26808c2ecf20Sopenharmony_ci}; 26818c2ecf20Sopenharmony_ci 26828c2ecf20Sopenharmony_ciint snd_cs46xx_midi(struct snd_cs46xx *chip, int device) 26838c2ecf20Sopenharmony_ci{ 26848c2ecf20Sopenharmony_ci struct snd_rawmidi *rmidi; 26858c2ecf20Sopenharmony_ci int err; 26868c2ecf20Sopenharmony_ci 26878c2ecf20Sopenharmony_ci if ((err = snd_rawmidi_new(chip->card, "CS46XX", device, 1, 1, &rmidi)) < 0) 26888c2ecf20Sopenharmony_ci return err; 26898c2ecf20Sopenharmony_ci strcpy(rmidi->name, "CS46XX"); 26908c2ecf20Sopenharmony_ci snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_cs46xx_midi_output); 26918c2ecf20Sopenharmony_ci snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &snd_cs46xx_midi_input); 26928c2ecf20Sopenharmony_ci rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT | SNDRV_RAWMIDI_INFO_INPUT | SNDRV_RAWMIDI_INFO_DUPLEX; 26938c2ecf20Sopenharmony_ci rmidi->private_data = chip; 26948c2ecf20Sopenharmony_ci chip->rmidi = rmidi; 26958c2ecf20Sopenharmony_ci return 0; 26968c2ecf20Sopenharmony_ci} 26978c2ecf20Sopenharmony_ci 26988c2ecf20Sopenharmony_ci 26998c2ecf20Sopenharmony_ci/* 27008c2ecf20Sopenharmony_ci * gameport interface 27018c2ecf20Sopenharmony_ci */ 27028c2ecf20Sopenharmony_ci 27038c2ecf20Sopenharmony_ci#if IS_REACHABLE(CONFIG_GAMEPORT) 27048c2ecf20Sopenharmony_ci 27058c2ecf20Sopenharmony_cistatic void snd_cs46xx_gameport_trigger(struct gameport *gameport) 27068c2ecf20Sopenharmony_ci{ 27078c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = gameport_get_port_data(gameport); 27088c2ecf20Sopenharmony_ci 27098c2ecf20Sopenharmony_ci if (snd_BUG_ON(!chip)) 27108c2ecf20Sopenharmony_ci return; 27118c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_JSPT, 0xFF); //outb(gameport->io, 0xFF); 27128c2ecf20Sopenharmony_ci} 27138c2ecf20Sopenharmony_ci 27148c2ecf20Sopenharmony_cistatic unsigned char snd_cs46xx_gameport_read(struct gameport *gameport) 27158c2ecf20Sopenharmony_ci{ 27168c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = gameport_get_port_data(gameport); 27178c2ecf20Sopenharmony_ci 27188c2ecf20Sopenharmony_ci if (snd_BUG_ON(!chip)) 27198c2ecf20Sopenharmony_ci return 0; 27208c2ecf20Sopenharmony_ci return snd_cs46xx_peekBA0(chip, BA0_JSPT); //inb(gameport->io); 27218c2ecf20Sopenharmony_ci} 27228c2ecf20Sopenharmony_ci 27238c2ecf20Sopenharmony_cistatic int snd_cs46xx_gameport_cooked_read(struct gameport *gameport, int *axes, int *buttons) 27248c2ecf20Sopenharmony_ci{ 27258c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = gameport_get_port_data(gameport); 27268c2ecf20Sopenharmony_ci unsigned js1, js2, jst; 27278c2ecf20Sopenharmony_ci 27288c2ecf20Sopenharmony_ci if (snd_BUG_ON(!chip)) 27298c2ecf20Sopenharmony_ci return 0; 27308c2ecf20Sopenharmony_ci 27318c2ecf20Sopenharmony_ci js1 = snd_cs46xx_peekBA0(chip, BA0_JSC1); 27328c2ecf20Sopenharmony_ci js2 = snd_cs46xx_peekBA0(chip, BA0_JSC2); 27338c2ecf20Sopenharmony_ci jst = snd_cs46xx_peekBA0(chip, BA0_JSPT); 27348c2ecf20Sopenharmony_ci 27358c2ecf20Sopenharmony_ci *buttons = (~jst >> 4) & 0x0F; 27368c2ecf20Sopenharmony_ci 27378c2ecf20Sopenharmony_ci axes[0] = ((js1 & JSC1_Y1V_MASK) >> JSC1_Y1V_SHIFT) & 0xFFFF; 27388c2ecf20Sopenharmony_ci axes[1] = ((js1 & JSC1_X1V_MASK) >> JSC1_X1V_SHIFT) & 0xFFFF; 27398c2ecf20Sopenharmony_ci axes[2] = ((js2 & JSC2_Y2V_MASK) >> JSC2_Y2V_SHIFT) & 0xFFFF; 27408c2ecf20Sopenharmony_ci axes[3] = ((js2 & JSC2_X2V_MASK) >> JSC2_X2V_SHIFT) & 0xFFFF; 27418c2ecf20Sopenharmony_ci 27428c2ecf20Sopenharmony_ci for(jst=0;jst<4;++jst) 27438c2ecf20Sopenharmony_ci if(axes[jst]==0xFFFF) axes[jst] = -1; 27448c2ecf20Sopenharmony_ci return 0; 27458c2ecf20Sopenharmony_ci} 27468c2ecf20Sopenharmony_ci 27478c2ecf20Sopenharmony_cistatic int snd_cs46xx_gameport_open(struct gameport *gameport, int mode) 27488c2ecf20Sopenharmony_ci{ 27498c2ecf20Sopenharmony_ci switch (mode) { 27508c2ecf20Sopenharmony_ci case GAMEPORT_MODE_COOKED: 27518c2ecf20Sopenharmony_ci return 0; 27528c2ecf20Sopenharmony_ci case GAMEPORT_MODE_RAW: 27538c2ecf20Sopenharmony_ci return 0; 27548c2ecf20Sopenharmony_ci default: 27558c2ecf20Sopenharmony_ci return -1; 27568c2ecf20Sopenharmony_ci } 27578c2ecf20Sopenharmony_ci return 0; 27588c2ecf20Sopenharmony_ci} 27598c2ecf20Sopenharmony_ci 27608c2ecf20Sopenharmony_ciint snd_cs46xx_gameport(struct snd_cs46xx *chip) 27618c2ecf20Sopenharmony_ci{ 27628c2ecf20Sopenharmony_ci struct gameport *gp; 27638c2ecf20Sopenharmony_ci 27648c2ecf20Sopenharmony_ci chip->gameport = gp = gameport_allocate_port(); 27658c2ecf20Sopenharmony_ci if (!gp) { 27668c2ecf20Sopenharmony_ci dev_err(chip->card->dev, 27678c2ecf20Sopenharmony_ci "cannot allocate memory for gameport\n"); 27688c2ecf20Sopenharmony_ci return -ENOMEM; 27698c2ecf20Sopenharmony_ci } 27708c2ecf20Sopenharmony_ci 27718c2ecf20Sopenharmony_ci gameport_set_name(gp, "CS46xx Gameport"); 27728c2ecf20Sopenharmony_ci gameport_set_phys(gp, "pci%s/gameport0", pci_name(chip->pci)); 27738c2ecf20Sopenharmony_ci gameport_set_dev_parent(gp, &chip->pci->dev); 27748c2ecf20Sopenharmony_ci gameport_set_port_data(gp, chip); 27758c2ecf20Sopenharmony_ci 27768c2ecf20Sopenharmony_ci gp->open = snd_cs46xx_gameport_open; 27778c2ecf20Sopenharmony_ci gp->read = snd_cs46xx_gameport_read; 27788c2ecf20Sopenharmony_ci gp->trigger = snd_cs46xx_gameport_trigger; 27798c2ecf20Sopenharmony_ci gp->cooked_read = snd_cs46xx_gameport_cooked_read; 27808c2ecf20Sopenharmony_ci 27818c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_JSIO, 0xFF); // ? 27828c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_JSCTL, JSCTL_SP_MEDIUM_SLOW); 27838c2ecf20Sopenharmony_ci 27848c2ecf20Sopenharmony_ci gameport_register_port(gp); 27858c2ecf20Sopenharmony_ci 27868c2ecf20Sopenharmony_ci return 0; 27878c2ecf20Sopenharmony_ci} 27888c2ecf20Sopenharmony_ci 27898c2ecf20Sopenharmony_cistatic inline void snd_cs46xx_remove_gameport(struct snd_cs46xx *chip) 27908c2ecf20Sopenharmony_ci{ 27918c2ecf20Sopenharmony_ci if (chip->gameport) { 27928c2ecf20Sopenharmony_ci gameport_unregister_port(chip->gameport); 27938c2ecf20Sopenharmony_ci chip->gameport = NULL; 27948c2ecf20Sopenharmony_ci } 27958c2ecf20Sopenharmony_ci} 27968c2ecf20Sopenharmony_ci#else 27978c2ecf20Sopenharmony_ciint snd_cs46xx_gameport(struct snd_cs46xx *chip) { return -ENOSYS; } 27988c2ecf20Sopenharmony_cistatic inline void snd_cs46xx_remove_gameport(struct snd_cs46xx *chip) { } 27998c2ecf20Sopenharmony_ci#endif /* CONFIG_GAMEPORT */ 28008c2ecf20Sopenharmony_ci 28018c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_PROC_FS 28028c2ecf20Sopenharmony_ci/* 28038c2ecf20Sopenharmony_ci * proc interface 28048c2ecf20Sopenharmony_ci */ 28058c2ecf20Sopenharmony_ci 28068c2ecf20Sopenharmony_cistatic ssize_t snd_cs46xx_io_read(struct snd_info_entry *entry, 28078c2ecf20Sopenharmony_ci void *file_private_data, 28088c2ecf20Sopenharmony_ci struct file *file, char __user *buf, 28098c2ecf20Sopenharmony_ci size_t count, loff_t pos) 28108c2ecf20Sopenharmony_ci{ 28118c2ecf20Sopenharmony_ci struct snd_cs46xx_region *region = entry->private_data; 28128c2ecf20Sopenharmony_ci 28138c2ecf20Sopenharmony_ci if (copy_to_user_fromio(buf, region->remap_addr + pos, count)) 28148c2ecf20Sopenharmony_ci return -EFAULT; 28158c2ecf20Sopenharmony_ci return count; 28168c2ecf20Sopenharmony_ci} 28178c2ecf20Sopenharmony_ci 28188c2ecf20Sopenharmony_cistatic const struct snd_info_entry_ops snd_cs46xx_proc_io_ops = { 28198c2ecf20Sopenharmony_ci .read = snd_cs46xx_io_read, 28208c2ecf20Sopenharmony_ci}; 28218c2ecf20Sopenharmony_ci 28228c2ecf20Sopenharmony_cistatic int snd_cs46xx_proc_init(struct snd_card *card, struct snd_cs46xx *chip) 28238c2ecf20Sopenharmony_ci{ 28248c2ecf20Sopenharmony_ci struct snd_info_entry *entry; 28258c2ecf20Sopenharmony_ci int idx; 28268c2ecf20Sopenharmony_ci 28278c2ecf20Sopenharmony_ci for (idx = 0; idx < 5; idx++) { 28288c2ecf20Sopenharmony_ci struct snd_cs46xx_region *region = &chip->region.idx[idx]; 28298c2ecf20Sopenharmony_ci if (! snd_card_proc_new(card, region->name, &entry)) { 28308c2ecf20Sopenharmony_ci entry->content = SNDRV_INFO_CONTENT_DATA; 28318c2ecf20Sopenharmony_ci entry->private_data = chip; 28328c2ecf20Sopenharmony_ci entry->c.ops = &snd_cs46xx_proc_io_ops; 28338c2ecf20Sopenharmony_ci entry->size = region->size; 28348c2ecf20Sopenharmony_ci entry->mode = S_IFREG | 0400; 28358c2ecf20Sopenharmony_ci } 28368c2ecf20Sopenharmony_ci } 28378c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 28388c2ecf20Sopenharmony_ci cs46xx_dsp_proc_init(card, chip); 28398c2ecf20Sopenharmony_ci#endif 28408c2ecf20Sopenharmony_ci return 0; 28418c2ecf20Sopenharmony_ci} 28428c2ecf20Sopenharmony_ci 28438c2ecf20Sopenharmony_cistatic int snd_cs46xx_proc_done(struct snd_cs46xx *chip) 28448c2ecf20Sopenharmony_ci{ 28458c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 28468c2ecf20Sopenharmony_ci cs46xx_dsp_proc_done(chip); 28478c2ecf20Sopenharmony_ci#endif 28488c2ecf20Sopenharmony_ci return 0; 28498c2ecf20Sopenharmony_ci} 28508c2ecf20Sopenharmony_ci#else /* !CONFIG_SND_PROC_FS */ 28518c2ecf20Sopenharmony_ci#define snd_cs46xx_proc_init(card, chip) 28528c2ecf20Sopenharmony_ci#define snd_cs46xx_proc_done(chip) 28538c2ecf20Sopenharmony_ci#endif 28548c2ecf20Sopenharmony_ci 28558c2ecf20Sopenharmony_ci/* 28568c2ecf20Sopenharmony_ci * stop the h/w 28578c2ecf20Sopenharmony_ci */ 28588c2ecf20Sopenharmony_cistatic void snd_cs46xx_hw_stop(struct snd_cs46xx *chip) 28598c2ecf20Sopenharmony_ci{ 28608c2ecf20Sopenharmony_ci unsigned int tmp; 28618c2ecf20Sopenharmony_ci 28628c2ecf20Sopenharmony_ci tmp = snd_cs46xx_peek(chip, BA1_PFIE); 28638c2ecf20Sopenharmony_ci tmp &= ~0x0000f03f; 28648c2ecf20Sopenharmony_ci tmp |= 0x00000010; 28658c2ecf20Sopenharmony_ci snd_cs46xx_poke(chip, BA1_PFIE, tmp); /* playback interrupt disable */ 28668c2ecf20Sopenharmony_ci 28678c2ecf20Sopenharmony_ci tmp = snd_cs46xx_peek(chip, BA1_CIE); 28688c2ecf20Sopenharmony_ci tmp &= ~0x0000003f; 28698c2ecf20Sopenharmony_ci tmp |= 0x00000011; 28708c2ecf20Sopenharmony_ci snd_cs46xx_poke(chip, BA1_CIE, tmp); /* capture interrupt disable */ 28718c2ecf20Sopenharmony_ci 28728c2ecf20Sopenharmony_ci /* 28738c2ecf20Sopenharmony_ci * Stop playback DMA. 28748c2ecf20Sopenharmony_ci */ 28758c2ecf20Sopenharmony_ci tmp = snd_cs46xx_peek(chip, BA1_PCTL); 28768c2ecf20Sopenharmony_ci snd_cs46xx_poke(chip, BA1_PCTL, tmp & 0x0000ffff); 28778c2ecf20Sopenharmony_ci 28788c2ecf20Sopenharmony_ci /* 28798c2ecf20Sopenharmony_ci * Stop capture DMA. 28808c2ecf20Sopenharmony_ci */ 28818c2ecf20Sopenharmony_ci tmp = snd_cs46xx_peek(chip, BA1_CCTL); 28828c2ecf20Sopenharmony_ci snd_cs46xx_poke(chip, BA1_CCTL, tmp & 0xffff0000); 28838c2ecf20Sopenharmony_ci 28848c2ecf20Sopenharmony_ci /* 28858c2ecf20Sopenharmony_ci * Reset the processor. 28868c2ecf20Sopenharmony_ci */ 28878c2ecf20Sopenharmony_ci snd_cs46xx_reset(chip); 28888c2ecf20Sopenharmony_ci 28898c2ecf20Sopenharmony_ci snd_cs46xx_proc_stop(chip); 28908c2ecf20Sopenharmony_ci 28918c2ecf20Sopenharmony_ci /* 28928c2ecf20Sopenharmony_ci * Power down the PLL. 28938c2ecf20Sopenharmony_ci */ 28948c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_CLKCR1, 0); 28958c2ecf20Sopenharmony_ci 28968c2ecf20Sopenharmony_ci /* 28978c2ecf20Sopenharmony_ci * Turn off the Processor by turning off the software clock enable flag in 28988c2ecf20Sopenharmony_ci * the clock control register. 28998c2ecf20Sopenharmony_ci */ 29008c2ecf20Sopenharmony_ci tmp = snd_cs46xx_peekBA0(chip, BA0_CLKCR1) & ~CLKCR1_SWCE; 29018c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_CLKCR1, tmp); 29028c2ecf20Sopenharmony_ci} 29038c2ecf20Sopenharmony_ci 29048c2ecf20Sopenharmony_ci 29058c2ecf20Sopenharmony_cistatic int snd_cs46xx_free(struct snd_cs46xx *chip) 29068c2ecf20Sopenharmony_ci{ 29078c2ecf20Sopenharmony_ci int idx; 29088c2ecf20Sopenharmony_ci 29098c2ecf20Sopenharmony_ci if (snd_BUG_ON(!chip)) 29108c2ecf20Sopenharmony_ci return -EINVAL; 29118c2ecf20Sopenharmony_ci 29128c2ecf20Sopenharmony_ci if (chip->active_ctrl) 29138c2ecf20Sopenharmony_ci chip->active_ctrl(chip, 1); 29148c2ecf20Sopenharmony_ci 29158c2ecf20Sopenharmony_ci snd_cs46xx_remove_gameport(chip); 29168c2ecf20Sopenharmony_ci 29178c2ecf20Sopenharmony_ci if (chip->amplifier_ctrl) 29188c2ecf20Sopenharmony_ci chip->amplifier_ctrl(chip, -chip->amplifier); /* force to off */ 29198c2ecf20Sopenharmony_ci 29208c2ecf20Sopenharmony_ci snd_cs46xx_proc_done(chip); 29218c2ecf20Sopenharmony_ci 29228c2ecf20Sopenharmony_ci if (chip->region.idx[0].resource) 29238c2ecf20Sopenharmony_ci snd_cs46xx_hw_stop(chip); 29248c2ecf20Sopenharmony_ci 29258c2ecf20Sopenharmony_ci if (chip->irq >= 0) 29268c2ecf20Sopenharmony_ci free_irq(chip->irq, chip); 29278c2ecf20Sopenharmony_ci 29288c2ecf20Sopenharmony_ci if (chip->active_ctrl) 29298c2ecf20Sopenharmony_ci chip->active_ctrl(chip, -chip->amplifier); 29308c2ecf20Sopenharmony_ci 29318c2ecf20Sopenharmony_ci for (idx = 0; idx < 5; idx++) { 29328c2ecf20Sopenharmony_ci struct snd_cs46xx_region *region = &chip->region.idx[idx]; 29338c2ecf20Sopenharmony_ci 29348c2ecf20Sopenharmony_ci iounmap(region->remap_addr); 29358c2ecf20Sopenharmony_ci release_and_free_resource(region->resource); 29368c2ecf20Sopenharmony_ci } 29378c2ecf20Sopenharmony_ci 29388c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 29398c2ecf20Sopenharmony_ci if (chip->dsp_spos_instance) { 29408c2ecf20Sopenharmony_ci cs46xx_dsp_spos_destroy(chip); 29418c2ecf20Sopenharmony_ci chip->dsp_spos_instance = NULL; 29428c2ecf20Sopenharmony_ci } 29438c2ecf20Sopenharmony_ci for (idx = 0; idx < CS46XX_DSP_MODULES; idx++) 29448c2ecf20Sopenharmony_ci free_module_desc(chip->modules[idx]); 29458c2ecf20Sopenharmony_ci#else 29468c2ecf20Sopenharmony_ci vfree(chip->ba1); 29478c2ecf20Sopenharmony_ci#endif 29488c2ecf20Sopenharmony_ci 29498c2ecf20Sopenharmony_ci#ifdef CONFIG_PM_SLEEP 29508c2ecf20Sopenharmony_ci kfree(chip->saved_regs); 29518c2ecf20Sopenharmony_ci#endif 29528c2ecf20Sopenharmony_ci 29538c2ecf20Sopenharmony_ci pci_disable_device(chip->pci); 29548c2ecf20Sopenharmony_ci kfree(chip); 29558c2ecf20Sopenharmony_ci return 0; 29568c2ecf20Sopenharmony_ci} 29578c2ecf20Sopenharmony_ci 29588c2ecf20Sopenharmony_cistatic int snd_cs46xx_dev_free(struct snd_device *device) 29598c2ecf20Sopenharmony_ci{ 29608c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = device->device_data; 29618c2ecf20Sopenharmony_ci return snd_cs46xx_free(chip); 29628c2ecf20Sopenharmony_ci} 29638c2ecf20Sopenharmony_ci 29648c2ecf20Sopenharmony_ci/* 29658c2ecf20Sopenharmony_ci * initialize chip 29668c2ecf20Sopenharmony_ci */ 29678c2ecf20Sopenharmony_cistatic int snd_cs46xx_chip_init(struct snd_cs46xx *chip) 29688c2ecf20Sopenharmony_ci{ 29698c2ecf20Sopenharmony_ci int timeout; 29708c2ecf20Sopenharmony_ci 29718c2ecf20Sopenharmony_ci /* 29728c2ecf20Sopenharmony_ci * First, blast the clock control register to zero so that the PLL starts 29738c2ecf20Sopenharmony_ci * out in a known state, and blast the master serial port control register 29748c2ecf20Sopenharmony_ci * to zero so that the serial ports also start out in a known state. 29758c2ecf20Sopenharmony_ci */ 29768c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_CLKCR1, 0); 29778c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_SERMC1, 0); 29788c2ecf20Sopenharmony_ci 29798c2ecf20Sopenharmony_ci /* 29808c2ecf20Sopenharmony_ci * If we are in AC97 mode, then we must set the part to a host controlled 29818c2ecf20Sopenharmony_ci * AC-link. Otherwise, we won't be able to bring up the link. 29828c2ecf20Sopenharmony_ci */ 29838c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 29848c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_SERACC, SERACC_HSP | SERACC_CHIP_TYPE_2_0 | 29858c2ecf20Sopenharmony_ci SERACC_TWO_CODECS); /* 2.00 dual codecs */ 29868c2ecf20Sopenharmony_ci /* snd_cs46xx_pokeBA0(chip, BA0_SERACC, SERACC_HSP | SERACC_CHIP_TYPE_2_0); */ /* 2.00 codec */ 29878c2ecf20Sopenharmony_ci#else 29888c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_SERACC, SERACC_HSP | SERACC_CHIP_TYPE_1_03); /* 1.03 codec */ 29898c2ecf20Sopenharmony_ci#endif 29908c2ecf20Sopenharmony_ci 29918c2ecf20Sopenharmony_ci /* 29928c2ecf20Sopenharmony_ci * Drive the ARST# pin low for a minimum of 1uS (as defined in the AC97 29938c2ecf20Sopenharmony_ci * spec) and then drive it high. This is done for non AC97 modes since 29948c2ecf20Sopenharmony_ci * there might be logic external to the CS461x that uses the ARST# line 29958c2ecf20Sopenharmony_ci * for a reset. 29968c2ecf20Sopenharmony_ci */ 29978c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_ACCTL, 0); 29988c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 29998c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_ACCTL2, 0); 30008c2ecf20Sopenharmony_ci#endif 30018c2ecf20Sopenharmony_ci udelay(50); 30028c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_ACCTL, ACCTL_RSTN); 30038c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 30048c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_ACCTL2, ACCTL_RSTN); 30058c2ecf20Sopenharmony_ci#endif 30068c2ecf20Sopenharmony_ci 30078c2ecf20Sopenharmony_ci /* 30088c2ecf20Sopenharmony_ci * The first thing we do here is to enable sync generation. As soon 30098c2ecf20Sopenharmony_ci * as we start receiving bit clock, we'll start producing the SYNC 30108c2ecf20Sopenharmony_ci * signal. 30118c2ecf20Sopenharmony_ci */ 30128c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_ACCTL, ACCTL_ESYN | ACCTL_RSTN); 30138c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 30148c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_ACCTL2, ACCTL_ESYN | ACCTL_RSTN); 30158c2ecf20Sopenharmony_ci#endif 30168c2ecf20Sopenharmony_ci 30178c2ecf20Sopenharmony_ci /* 30188c2ecf20Sopenharmony_ci * Now wait for a short while to allow the AC97 part to start 30198c2ecf20Sopenharmony_ci * generating bit clock (so we don't try to start the PLL without an 30208c2ecf20Sopenharmony_ci * input clock). 30218c2ecf20Sopenharmony_ci */ 30228c2ecf20Sopenharmony_ci mdelay(10); 30238c2ecf20Sopenharmony_ci 30248c2ecf20Sopenharmony_ci /* 30258c2ecf20Sopenharmony_ci * Set the serial port timing configuration, so that 30268c2ecf20Sopenharmony_ci * the clock control circuit gets its clock from the correct place. 30278c2ecf20Sopenharmony_ci */ 30288c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_SERMC1, SERMC1_PTC_AC97); 30298c2ecf20Sopenharmony_ci 30308c2ecf20Sopenharmony_ci /* 30318c2ecf20Sopenharmony_ci * Write the selected clock control setup to the hardware. Do not turn on 30328c2ecf20Sopenharmony_ci * SWCE yet (if requested), so that the devices clocked by the output of 30338c2ecf20Sopenharmony_ci * PLL are not clocked until the PLL is stable. 30348c2ecf20Sopenharmony_ci */ 30358c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_PLLCC, PLLCC_LPF_1050_2780_KHZ | PLLCC_CDR_73_104_MHZ); 30368c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_PLLM, 0x3a); 30378c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_CLKCR2, CLKCR2_PDIVS_8); 30388c2ecf20Sopenharmony_ci 30398c2ecf20Sopenharmony_ci /* 30408c2ecf20Sopenharmony_ci * Power up the PLL. 30418c2ecf20Sopenharmony_ci */ 30428c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_CLKCR1, CLKCR1_PLLP); 30438c2ecf20Sopenharmony_ci 30448c2ecf20Sopenharmony_ci /* 30458c2ecf20Sopenharmony_ci * Wait until the PLL has stabilized. 30468c2ecf20Sopenharmony_ci */ 30478c2ecf20Sopenharmony_ci msleep(100); 30488c2ecf20Sopenharmony_ci 30498c2ecf20Sopenharmony_ci /* 30508c2ecf20Sopenharmony_ci * Turn on clocking of the core so that we can setup the serial ports. 30518c2ecf20Sopenharmony_ci */ 30528c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_CLKCR1, CLKCR1_PLLP | CLKCR1_SWCE); 30538c2ecf20Sopenharmony_ci 30548c2ecf20Sopenharmony_ci /* 30558c2ecf20Sopenharmony_ci * Enable FIFO Host Bypass 30568c2ecf20Sopenharmony_ci */ 30578c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_SERBCF, SERBCF_HBP); 30588c2ecf20Sopenharmony_ci 30598c2ecf20Sopenharmony_ci /* 30608c2ecf20Sopenharmony_ci * Fill the serial port FIFOs with silence. 30618c2ecf20Sopenharmony_ci */ 30628c2ecf20Sopenharmony_ci snd_cs46xx_clear_serial_FIFOs(chip); 30638c2ecf20Sopenharmony_ci 30648c2ecf20Sopenharmony_ci /* 30658c2ecf20Sopenharmony_ci * Set the serial port FIFO pointer to the first sample in the FIFO. 30668c2ecf20Sopenharmony_ci */ 30678c2ecf20Sopenharmony_ci /* snd_cs46xx_pokeBA0(chip, BA0_SERBSP, 0); */ 30688c2ecf20Sopenharmony_ci 30698c2ecf20Sopenharmony_ci /* 30708c2ecf20Sopenharmony_ci * Write the serial port configuration to the part. The master 30718c2ecf20Sopenharmony_ci * enable bit is not set until all other values have been written. 30728c2ecf20Sopenharmony_ci */ 30738c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_SERC1, SERC1_SO1F_AC97 | SERC1_SO1EN); 30748c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_SERC2, SERC2_SI1F_AC97 | SERC1_SO1EN); 30758c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_SERMC1, SERMC1_PTC_AC97 | SERMC1_MSPE); 30768c2ecf20Sopenharmony_ci 30778c2ecf20Sopenharmony_ci 30788c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 30798c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_SERC7, SERC7_ASDI2EN); 30808c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_SERC3, 0); 30818c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_SERC4, 0); 30828c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_SERC5, 0); 30838c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_SERC6, 1); 30848c2ecf20Sopenharmony_ci#endif 30858c2ecf20Sopenharmony_ci 30868c2ecf20Sopenharmony_ci mdelay(5); 30878c2ecf20Sopenharmony_ci 30888c2ecf20Sopenharmony_ci 30898c2ecf20Sopenharmony_ci /* 30908c2ecf20Sopenharmony_ci * Wait for the codec ready signal from the AC97 codec. 30918c2ecf20Sopenharmony_ci */ 30928c2ecf20Sopenharmony_ci timeout = 150; 30938c2ecf20Sopenharmony_ci while (timeout-- > 0) { 30948c2ecf20Sopenharmony_ci /* 30958c2ecf20Sopenharmony_ci * Read the AC97 status register to see if we've seen a CODEC READY 30968c2ecf20Sopenharmony_ci * signal from the AC97 codec. 30978c2ecf20Sopenharmony_ci */ 30988c2ecf20Sopenharmony_ci if (snd_cs46xx_peekBA0(chip, BA0_ACSTS) & ACSTS_CRDY) 30998c2ecf20Sopenharmony_ci goto ok1; 31008c2ecf20Sopenharmony_ci msleep(10); 31018c2ecf20Sopenharmony_ci } 31028c2ecf20Sopenharmony_ci 31038c2ecf20Sopenharmony_ci 31048c2ecf20Sopenharmony_ci dev_err(chip->card->dev, 31058c2ecf20Sopenharmony_ci "create - never read codec ready from AC'97\n"); 31068c2ecf20Sopenharmony_ci dev_err(chip->card->dev, 31078c2ecf20Sopenharmony_ci "it is not probably bug, try to use CS4236 driver\n"); 31088c2ecf20Sopenharmony_ci return -EIO; 31098c2ecf20Sopenharmony_ci ok1: 31108c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 31118c2ecf20Sopenharmony_ci { 31128c2ecf20Sopenharmony_ci int count; 31138c2ecf20Sopenharmony_ci for (count = 0; count < 150; count++) { 31148c2ecf20Sopenharmony_ci /* First, we want to wait for a short time. */ 31158c2ecf20Sopenharmony_ci udelay(25); 31168c2ecf20Sopenharmony_ci 31178c2ecf20Sopenharmony_ci if (snd_cs46xx_peekBA0(chip, BA0_ACSTS2) & ACSTS_CRDY) 31188c2ecf20Sopenharmony_ci break; 31198c2ecf20Sopenharmony_ci } 31208c2ecf20Sopenharmony_ci 31218c2ecf20Sopenharmony_ci /* 31228c2ecf20Sopenharmony_ci * Make sure CODEC is READY. 31238c2ecf20Sopenharmony_ci */ 31248c2ecf20Sopenharmony_ci if (!(snd_cs46xx_peekBA0(chip, BA0_ACSTS2) & ACSTS_CRDY)) 31258c2ecf20Sopenharmony_ci dev_dbg(chip->card->dev, 31268c2ecf20Sopenharmony_ci "never read card ready from secondary AC'97\n"); 31278c2ecf20Sopenharmony_ci } 31288c2ecf20Sopenharmony_ci#endif 31298c2ecf20Sopenharmony_ci 31308c2ecf20Sopenharmony_ci /* 31318c2ecf20Sopenharmony_ci * Assert the vaid frame signal so that we can start sending commands 31328c2ecf20Sopenharmony_ci * to the AC97 codec. 31338c2ecf20Sopenharmony_ci */ 31348c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_ACCTL, ACCTL_VFRM | ACCTL_ESYN | ACCTL_RSTN); 31358c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 31368c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_ACCTL2, ACCTL_VFRM | ACCTL_ESYN | ACCTL_RSTN); 31378c2ecf20Sopenharmony_ci#endif 31388c2ecf20Sopenharmony_ci 31398c2ecf20Sopenharmony_ci 31408c2ecf20Sopenharmony_ci /* 31418c2ecf20Sopenharmony_ci * Wait until we've sampled input slots 3 and 4 as valid, meaning that 31428c2ecf20Sopenharmony_ci * the codec is pumping ADC data across the AC-link. 31438c2ecf20Sopenharmony_ci */ 31448c2ecf20Sopenharmony_ci timeout = 150; 31458c2ecf20Sopenharmony_ci while (timeout-- > 0) { 31468c2ecf20Sopenharmony_ci /* 31478c2ecf20Sopenharmony_ci * Read the input slot valid register and see if input slots 3 and 31488c2ecf20Sopenharmony_ci * 4 are valid yet. 31498c2ecf20Sopenharmony_ci */ 31508c2ecf20Sopenharmony_ci if ((snd_cs46xx_peekBA0(chip, BA0_ACISV) & (ACISV_ISV3 | ACISV_ISV4)) == (ACISV_ISV3 | ACISV_ISV4)) 31518c2ecf20Sopenharmony_ci goto ok2; 31528c2ecf20Sopenharmony_ci msleep(10); 31538c2ecf20Sopenharmony_ci } 31548c2ecf20Sopenharmony_ci 31558c2ecf20Sopenharmony_ci#ifndef CONFIG_SND_CS46XX_NEW_DSP 31568c2ecf20Sopenharmony_ci dev_err(chip->card->dev, 31578c2ecf20Sopenharmony_ci "create - never read ISV3 & ISV4 from AC'97\n"); 31588c2ecf20Sopenharmony_ci return -EIO; 31598c2ecf20Sopenharmony_ci#else 31608c2ecf20Sopenharmony_ci /* This may happen on a cold boot with a Terratec SiXPack 5.1. 31618c2ecf20Sopenharmony_ci Reloading the driver may help, if there's other soundcards 31628c2ecf20Sopenharmony_ci with the same problem I would like to know. (Benny) */ 31638c2ecf20Sopenharmony_ci 31648c2ecf20Sopenharmony_ci dev_err(chip->card->dev, "never read ISV3 & ISV4 from AC'97\n"); 31658c2ecf20Sopenharmony_ci dev_err(chip->card->dev, 31668c2ecf20Sopenharmony_ci "Try reloading the ALSA driver, if you find something\n"); 31678c2ecf20Sopenharmony_ci dev_err(chip->card->dev, 31688c2ecf20Sopenharmony_ci "broken or not working on your soundcard upon\n"); 31698c2ecf20Sopenharmony_ci dev_err(chip->card->dev, 31708c2ecf20Sopenharmony_ci "this message please report to alsa-devel@alsa-project.org\n"); 31718c2ecf20Sopenharmony_ci 31728c2ecf20Sopenharmony_ci return -EIO; 31738c2ecf20Sopenharmony_ci#endif 31748c2ecf20Sopenharmony_ci ok2: 31758c2ecf20Sopenharmony_ci 31768c2ecf20Sopenharmony_ci /* 31778c2ecf20Sopenharmony_ci * Now, assert valid frame and the slot 3 and 4 valid bits. This will 31788c2ecf20Sopenharmony_ci * commense the transfer of digital audio data to the AC97 codec. 31798c2ecf20Sopenharmony_ci */ 31808c2ecf20Sopenharmony_ci 31818c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_ACOSV, ACOSV_SLV3 | ACOSV_SLV4); 31828c2ecf20Sopenharmony_ci 31838c2ecf20Sopenharmony_ci 31848c2ecf20Sopenharmony_ci /* 31858c2ecf20Sopenharmony_ci * Power down the DAC and ADC. We will power them up (if) when we need 31868c2ecf20Sopenharmony_ci * them. 31878c2ecf20Sopenharmony_ci */ 31888c2ecf20Sopenharmony_ci /* snd_cs46xx_pokeBA0(chip, BA0_AC97_POWERDOWN, 0x300); */ 31898c2ecf20Sopenharmony_ci 31908c2ecf20Sopenharmony_ci /* 31918c2ecf20Sopenharmony_ci * Turn off the Processor by turning off the software clock enable flag in 31928c2ecf20Sopenharmony_ci * the clock control register. 31938c2ecf20Sopenharmony_ci */ 31948c2ecf20Sopenharmony_ci /* tmp = snd_cs46xx_peekBA0(chip, BA0_CLKCR1) & ~CLKCR1_SWCE; */ 31958c2ecf20Sopenharmony_ci /* snd_cs46xx_pokeBA0(chip, BA0_CLKCR1, tmp); */ 31968c2ecf20Sopenharmony_ci 31978c2ecf20Sopenharmony_ci return 0; 31988c2ecf20Sopenharmony_ci} 31998c2ecf20Sopenharmony_ci 32008c2ecf20Sopenharmony_ci/* 32018c2ecf20Sopenharmony_ci * start and load DSP 32028c2ecf20Sopenharmony_ci */ 32038c2ecf20Sopenharmony_ci 32048c2ecf20Sopenharmony_cistatic void cs46xx_enable_stream_irqs(struct snd_cs46xx *chip) 32058c2ecf20Sopenharmony_ci{ 32068c2ecf20Sopenharmony_ci unsigned int tmp; 32078c2ecf20Sopenharmony_ci 32088c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_HICR, HICR_IEV | HICR_CHGM); 32098c2ecf20Sopenharmony_ci 32108c2ecf20Sopenharmony_ci tmp = snd_cs46xx_peek(chip, BA1_PFIE); 32118c2ecf20Sopenharmony_ci tmp &= ~0x0000f03f; 32128c2ecf20Sopenharmony_ci snd_cs46xx_poke(chip, BA1_PFIE, tmp); /* playback interrupt enable */ 32138c2ecf20Sopenharmony_ci 32148c2ecf20Sopenharmony_ci tmp = snd_cs46xx_peek(chip, BA1_CIE); 32158c2ecf20Sopenharmony_ci tmp &= ~0x0000003f; 32168c2ecf20Sopenharmony_ci tmp |= 0x00000001; 32178c2ecf20Sopenharmony_ci snd_cs46xx_poke(chip, BA1_CIE, tmp); /* capture interrupt enable */ 32188c2ecf20Sopenharmony_ci} 32198c2ecf20Sopenharmony_ci 32208c2ecf20Sopenharmony_ciint snd_cs46xx_start_dsp(struct snd_cs46xx *chip) 32218c2ecf20Sopenharmony_ci{ 32228c2ecf20Sopenharmony_ci unsigned int tmp; 32238c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 32248c2ecf20Sopenharmony_ci int i; 32258c2ecf20Sopenharmony_ci#endif 32268c2ecf20Sopenharmony_ci int err; 32278c2ecf20Sopenharmony_ci 32288c2ecf20Sopenharmony_ci /* 32298c2ecf20Sopenharmony_ci * Reset the processor. 32308c2ecf20Sopenharmony_ci */ 32318c2ecf20Sopenharmony_ci snd_cs46xx_reset(chip); 32328c2ecf20Sopenharmony_ci /* 32338c2ecf20Sopenharmony_ci * Download the image to the processor. 32348c2ecf20Sopenharmony_ci */ 32358c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 32368c2ecf20Sopenharmony_ci for (i = 0; i < CS46XX_DSP_MODULES; i++) { 32378c2ecf20Sopenharmony_ci err = load_firmware(chip, &chip->modules[i], module_names[i]); 32388c2ecf20Sopenharmony_ci if (err < 0) { 32398c2ecf20Sopenharmony_ci dev_err(chip->card->dev, "firmware load error [%s]\n", 32408c2ecf20Sopenharmony_ci module_names[i]); 32418c2ecf20Sopenharmony_ci return err; 32428c2ecf20Sopenharmony_ci } 32438c2ecf20Sopenharmony_ci err = cs46xx_dsp_load_module(chip, chip->modules[i]); 32448c2ecf20Sopenharmony_ci if (err < 0) { 32458c2ecf20Sopenharmony_ci dev_err(chip->card->dev, "image download error [%s]\n", 32468c2ecf20Sopenharmony_ci module_names[i]); 32478c2ecf20Sopenharmony_ci return err; 32488c2ecf20Sopenharmony_ci } 32498c2ecf20Sopenharmony_ci } 32508c2ecf20Sopenharmony_ci 32518c2ecf20Sopenharmony_ci if (cs46xx_dsp_scb_and_task_init(chip) < 0) 32528c2ecf20Sopenharmony_ci return -EIO; 32538c2ecf20Sopenharmony_ci#else 32548c2ecf20Sopenharmony_ci err = load_firmware(chip); 32558c2ecf20Sopenharmony_ci if (err < 0) 32568c2ecf20Sopenharmony_ci return err; 32578c2ecf20Sopenharmony_ci 32588c2ecf20Sopenharmony_ci /* old image */ 32598c2ecf20Sopenharmony_ci err = snd_cs46xx_download_image(chip); 32608c2ecf20Sopenharmony_ci if (err < 0) { 32618c2ecf20Sopenharmony_ci dev_err(chip->card->dev, "image download error\n"); 32628c2ecf20Sopenharmony_ci return err; 32638c2ecf20Sopenharmony_ci } 32648c2ecf20Sopenharmony_ci 32658c2ecf20Sopenharmony_ci /* 32668c2ecf20Sopenharmony_ci * Stop playback DMA. 32678c2ecf20Sopenharmony_ci */ 32688c2ecf20Sopenharmony_ci tmp = snd_cs46xx_peek(chip, BA1_PCTL); 32698c2ecf20Sopenharmony_ci chip->play_ctl = tmp & 0xffff0000; 32708c2ecf20Sopenharmony_ci snd_cs46xx_poke(chip, BA1_PCTL, tmp & 0x0000ffff); 32718c2ecf20Sopenharmony_ci#endif 32728c2ecf20Sopenharmony_ci 32738c2ecf20Sopenharmony_ci /* 32748c2ecf20Sopenharmony_ci * Stop capture DMA. 32758c2ecf20Sopenharmony_ci */ 32768c2ecf20Sopenharmony_ci tmp = snd_cs46xx_peek(chip, BA1_CCTL); 32778c2ecf20Sopenharmony_ci chip->capt.ctl = tmp & 0x0000ffff; 32788c2ecf20Sopenharmony_ci snd_cs46xx_poke(chip, BA1_CCTL, tmp & 0xffff0000); 32798c2ecf20Sopenharmony_ci 32808c2ecf20Sopenharmony_ci mdelay(5); 32818c2ecf20Sopenharmony_ci 32828c2ecf20Sopenharmony_ci snd_cs46xx_set_play_sample_rate(chip, 8000); 32838c2ecf20Sopenharmony_ci snd_cs46xx_set_capture_sample_rate(chip, 8000); 32848c2ecf20Sopenharmony_ci 32858c2ecf20Sopenharmony_ci snd_cs46xx_proc_start(chip); 32868c2ecf20Sopenharmony_ci 32878c2ecf20Sopenharmony_ci cs46xx_enable_stream_irqs(chip); 32888c2ecf20Sopenharmony_ci 32898c2ecf20Sopenharmony_ci#ifndef CONFIG_SND_CS46XX_NEW_DSP 32908c2ecf20Sopenharmony_ci /* set the attenuation to 0dB */ 32918c2ecf20Sopenharmony_ci snd_cs46xx_poke(chip, BA1_PVOL, 0x80008000); 32928c2ecf20Sopenharmony_ci snd_cs46xx_poke(chip, BA1_CVOL, 0x80008000); 32938c2ecf20Sopenharmony_ci#endif 32948c2ecf20Sopenharmony_ci 32958c2ecf20Sopenharmony_ci return 0; 32968c2ecf20Sopenharmony_ci} 32978c2ecf20Sopenharmony_ci 32988c2ecf20Sopenharmony_ci 32998c2ecf20Sopenharmony_ci/* 33008c2ecf20Sopenharmony_ci * AMP control - null AMP 33018c2ecf20Sopenharmony_ci */ 33028c2ecf20Sopenharmony_ci 33038c2ecf20Sopenharmony_cistatic void amp_none(struct snd_cs46xx *chip, int change) 33048c2ecf20Sopenharmony_ci{ 33058c2ecf20Sopenharmony_ci} 33068c2ecf20Sopenharmony_ci 33078c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 33088c2ecf20Sopenharmony_cistatic int voyetra_setup_eapd_slot(struct snd_cs46xx *chip) 33098c2ecf20Sopenharmony_ci{ 33108c2ecf20Sopenharmony_ci 33118c2ecf20Sopenharmony_ci u32 idx, valid_slots,tmp,powerdown = 0; 33128c2ecf20Sopenharmony_ci u16 modem_power,pin_config,logic_type; 33138c2ecf20Sopenharmony_ci 33148c2ecf20Sopenharmony_ci dev_dbg(chip->card->dev, "cs46xx_setup_eapd_slot()+\n"); 33158c2ecf20Sopenharmony_ci 33168c2ecf20Sopenharmony_ci /* 33178c2ecf20Sopenharmony_ci * See if the devices are powered down. If so, we must power them up first 33188c2ecf20Sopenharmony_ci * or they will not respond. 33198c2ecf20Sopenharmony_ci */ 33208c2ecf20Sopenharmony_ci tmp = snd_cs46xx_peekBA0(chip, BA0_CLKCR1); 33218c2ecf20Sopenharmony_ci 33228c2ecf20Sopenharmony_ci if (!(tmp & CLKCR1_SWCE)) { 33238c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_CLKCR1, tmp | CLKCR1_SWCE); 33248c2ecf20Sopenharmony_ci powerdown = 1; 33258c2ecf20Sopenharmony_ci } 33268c2ecf20Sopenharmony_ci 33278c2ecf20Sopenharmony_ci /* 33288c2ecf20Sopenharmony_ci * Clear PRA. The Bonzo chip will be used for GPIO not for modem 33298c2ecf20Sopenharmony_ci * stuff. 33308c2ecf20Sopenharmony_ci */ 33318c2ecf20Sopenharmony_ci if(chip->nr_ac97_codecs != 2) { 33328c2ecf20Sopenharmony_ci dev_err(chip->card->dev, 33338c2ecf20Sopenharmony_ci "cs46xx_setup_eapd_slot() - no secondary codec configured\n"); 33348c2ecf20Sopenharmony_ci return -EINVAL; 33358c2ecf20Sopenharmony_ci } 33368c2ecf20Sopenharmony_ci 33378c2ecf20Sopenharmony_ci modem_power = snd_cs46xx_codec_read (chip, 33388c2ecf20Sopenharmony_ci AC97_EXTENDED_MSTATUS, 33398c2ecf20Sopenharmony_ci CS46XX_SECONDARY_CODEC_INDEX); 33408c2ecf20Sopenharmony_ci modem_power &=0xFEFF; 33418c2ecf20Sopenharmony_ci 33428c2ecf20Sopenharmony_ci snd_cs46xx_codec_write(chip, 33438c2ecf20Sopenharmony_ci AC97_EXTENDED_MSTATUS, modem_power, 33448c2ecf20Sopenharmony_ci CS46XX_SECONDARY_CODEC_INDEX); 33458c2ecf20Sopenharmony_ci 33468c2ecf20Sopenharmony_ci /* 33478c2ecf20Sopenharmony_ci * Set GPIO pin's 7 and 8 so that they are configured for output. 33488c2ecf20Sopenharmony_ci */ 33498c2ecf20Sopenharmony_ci pin_config = snd_cs46xx_codec_read (chip, 33508c2ecf20Sopenharmony_ci AC97_GPIO_CFG, 33518c2ecf20Sopenharmony_ci CS46XX_SECONDARY_CODEC_INDEX); 33528c2ecf20Sopenharmony_ci pin_config &=0x27F; 33538c2ecf20Sopenharmony_ci 33548c2ecf20Sopenharmony_ci snd_cs46xx_codec_write(chip, 33558c2ecf20Sopenharmony_ci AC97_GPIO_CFG, pin_config, 33568c2ecf20Sopenharmony_ci CS46XX_SECONDARY_CODEC_INDEX); 33578c2ecf20Sopenharmony_ci 33588c2ecf20Sopenharmony_ci /* 33598c2ecf20Sopenharmony_ci * Set GPIO pin's 7 and 8 so that they are compatible with CMOS logic. 33608c2ecf20Sopenharmony_ci */ 33618c2ecf20Sopenharmony_ci 33628c2ecf20Sopenharmony_ci logic_type = snd_cs46xx_codec_read(chip, AC97_GPIO_POLARITY, 33638c2ecf20Sopenharmony_ci CS46XX_SECONDARY_CODEC_INDEX); 33648c2ecf20Sopenharmony_ci logic_type &=0x27F; 33658c2ecf20Sopenharmony_ci 33668c2ecf20Sopenharmony_ci snd_cs46xx_codec_write (chip, AC97_GPIO_POLARITY, logic_type, 33678c2ecf20Sopenharmony_ci CS46XX_SECONDARY_CODEC_INDEX); 33688c2ecf20Sopenharmony_ci 33698c2ecf20Sopenharmony_ci valid_slots = snd_cs46xx_peekBA0(chip, BA0_ACOSV); 33708c2ecf20Sopenharmony_ci valid_slots |= 0x200; 33718c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_ACOSV, valid_slots); 33728c2ecf20Sopenharmony_ci 33738c2ecf20Sopenharmony_ci if ( cs46xx_wait_for_fifo(chip,1) ) { 33748c2ecf20Sopenharmony_ci dev_dbg(chip->card->dev, "FIFO is busy\n"); 33758c2ecf20Sopenharmony_ci 33768c2ecf20Sopenharmony_ci return -EINVAL; 33778c2ecf20Sopenharmony_ci } 33788c2ecf20Sopenharmony_ci 33798c2ecf20Sopenharmony_ci /* 33808c2ecf20Sopenharmony_ci * Fill slots 12 with the correct value for the GPIO pins. 33818c2ecf20Sopenharmony_ci */ 33828c2ecf20Sopenharmony_ci for(idx = 0x90; idx <= 0x9F; idx++) { 33838c2ecf20Sopenharmony_ci /* 33848c2ecf20Sopenharmony_ci * Initialize the fifo so that bits 7 and 8 are on. 33858c2ecf20Sopenharmony_ci * 33868c2ecf20Sopenharmony_ci * Remember that the GPIO pins in bonzo are shifted by 4 bits to 33878c2ecf20Sopenharmony_ci * the left. 0x1800 corresponds to bits 7 and 8. 33888c2ecf20Sopenharmony_ci */ 33898c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_SERBWP, 0x1800); 33908c2ecf20Sopenharmony_ci 33918c2ecf20Sopenharmony_ci /* 33928c2ecf20Sopenharmony_ci * Wait for command to complete 33938c2ecf20Sopenharmony_ci */ 33948c2ecf20Sopenharmony_ci if ( cs46xx_wait_for_fifo(chip,200) ) { 33958c2ecf20Sopenharmony_ci dev_dbg(chip->card->dev, 33968c2ecf20Sopenharmony_ci "failed waiting for FIFO at addr (%02X)\n", 33978c2ecf20Sopenharmony_ci idx); 33988c2ecf20Sopenharmony_ci 33998c2ecf20Sopenharmony_ci return -EINVAL; 34008c2ecf20Sopenharmony_ci } 34018c2ecf20Sopenharmony_ci 34028c2ecf20Sopenharmony_ci /* 34038c2ecf20Sopenharmony_ci * Write the serial port FIFO index. 34048c2ecf20Sopenharmony_ci */ 34058c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_SERBAD, idx); 34068c2ecf20Sopenharmony_ci 34078c2ecf20Sopenharmony_ci /* 34088c2ecf20Sopenharmony_ci * Tell the serial port to load the new value into the FIFO location. 34098c2ecf20Sopenharmony_ci */ 34108c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_SERBCM, SERBCM_WRC); 34118c2ecf20Sopenharmony_ci } 34128c2ecf20Sopenharmony_ci 34138c2ecf20Sopenharmony_ci /* wait for last command to complete */ 34148c2ecf20Sopenharmony_ci cs46xx_wait_for_fifo(chip,200); 34158c2ecf20Sopenharmony_ci 34168c2ecf20Sopenharmony_ci /* 34178c2ecf20Sopenharmony_ci * Now, if we powered up the devices, then power them back down again. 34188c2ecf20Sopenharmony_ci * This is kinda ugly, but should never happen. 34198c2ecf20Sopenharmony_ci */ 34208c2ecf20Sopenharmony_ci if (powerdown) 34218c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_CLKCR1, tmp); 34228c2ecf20Sopenharmony_ci 34238c2ecf20Sopenharmony_ci return 0; 34248c2ecf20Sopenharmony_ci} 34258c2ecf20Sopenharmony_ci#endif 34268c2ecf20Sopenharmony_ci 34278c2ecf20Sopenharmony_ci/* 34288c2ecf20Sopenharmony_ci * Crystal EAPD mode 34298c2ecf20Sopenharmony_ci */ 34308c2ecf20Sopenharmony_ci 34318c2ecf20Sopenharmony_cistatic void amp_voyetra(struct snd_cs46xx *chip, int change) 34328c2ecf20Sopenharmony_ci{ 34338c2ecf20Sopenharmony_ci /* Manage the EAPD bit on the Crystal 4297 34348c2ecf20Sopenharmony_ci and the Analog AD1885 */ 34358c2ecf20Sopenharmony_ci 34368c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 34378c2ecf20Sopenharmony_ci int old = chip->amplifier; 34388c2ecf20Sopenharmony_ci#endif 34398c2ecf20Sopenharmony_ci int oval, val; 34408c2ecf20Sopenharmony_ci 34418c2ecf20Sopenharmony_ci chip->amplifier += change; 34428c2ecf20Sopenharmony_ci oval = snd_cs46xx_codec_read(chip, AC97_POWERDOWN, 34438c2ecf20Sopenharmony_ci CS46XX_PRIMARY_CODEC_INDEX); 34448c2ecf20Sopenharmony_ci val = oval; 34458c2ecf20Sopenharmony_ci if (chip->amplifier) { 34468c2ecf20Sopenharmony_ci /* Turn the EAPD amp on */ 34478c2ecf20Sopenharmony_ci val |= 0x8000; 34488c2ecf20Sopenharmony_ci } else { 34498c2ecf20Sopenharmony_ci /* Turn the EAPD amp off */ 34508c2ecf20Sopenharmony_ci val &= ~0x8000; 34518c2ecf20Sopenharmony_ci } 34528c2ecf20Sopenharmony_ci if (val != oval) { 34538c2ecf20Sopenharmony_ci snd_cs46xx_codec_write(chip, AC97_POWERDOWN, val, 34548c2ecf20Sopenharmony_ci CS46XX_PRIMARY_CODEC_INDEX); 34558c2ecf20Sopenharmony_ci if (chip->eapd_switch) 34568c2ecf20Sopenharmony_ci snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, 34578c2ecf20Sopenharmony_ci &chip->eapd_switch->id); 34588c2ecf20Sopenharmony_ci } 34598c2ecf20Sopenharmony_ci 34608c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 34618c2ecf20Sopenharmony_ci if (chip->amplifier && !old) { 34628c2ecf20Sopenharmony_ci voyetra_setup_eapd_slot(chip); 34638c2ecf20Sopenharmony_ci } 34648c2ecf20Sopenharmony_ci#endif 34658c2ecf20Sopenharmony_ci} 34668c2ecf20Sopenharmony_ci 34678c2ecf20Sopenharmony_cistatic void hercules_init(struct snd_cs46xx *chip) 34688c2ecf20Sopenharmony_ci{ 34698c2ecf20Sopenharmony_ci /* default: AMP off, and SPDIF input optical */ 34708c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_EGPIODR, EGPIODR_GPOE0); 34718c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_EGPIOPTR, EGPIODR_GPOE0); 34728c2ecf20Sopenharmony_ci} 34738c2ecf20Sopenharmony_ci 34748c2ecf20Sopenharmony_ci 34758c2ecf20Sopenharmony_ci/* 34768c2ecf20Sopenharmony_ci * Game Theatre XP card - EGPIO[2] is used to enable the external amp. 34778c2ecf20Sopenharmony_ci */ 34788c2ecf20Sopenharmony_cistatic void amp_hercules(struct snd_cs46xx *chip, int change) 34798c2ecf20Sopenharmony_ci{ 34808c2ecf20Sopenharmony_ci int old = chip->amplifier; 34818c2ecf20Sopenharmony_ci int val1 = snd_cs46xx_peekBA0(chip, BA0_EGPIODR); 34828c2ecf20Sopenharmony_ci int val2 = snd_cs46xx_peekBA0(chip, BA0_EGPIOPTR); 34838c2ecf20Sopenharmony_ci 34848c2ecf20Sopenharmony_ci chip->amplifier += change; 34858c2ecf20Sopenharmony_ci if (chip->amplifier && !old) { 34868c2ecf20Sopenharmony_ci dev_dbg(chip->card->dev, "Hercules amplifier ON\n"); 34878c2ecf20Sopenharmony_ci 34888c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_EGPIODR, 34898c2ecf20Sopenharmony_ci EGPIODR_GPOE2 | val1); /* enable EGPIO2 output */ 34908c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_EGPIOPTR, 34918c2ecf20Sopenharmony_ci EGPIOPTR_GPPT2 | val2); /* open-drain on output */ 34928c2ecf20Sopenharmony_ci } else if (old && !chip->amplifier) { 34938c2ecf20Sopenharmony_ci dev_dbg(chip->card->dev, "Hercules amplifier OFF\n"); 34948c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_EGPIODR, val1 & ~EGPIODR_GPOE2); /* disable */ 34958c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_EGPIOPTR, val2 & ~EGPIOPTR_GPPT2); /* disable */ 34968c2ecf20Sopenharmony_ci } 34978c2ecf20Sopenharmony_ci} 34988c2ecf20Sopenharmony_ci 34998c2ecf20Sopenharmony_cistatic void voyetra_mixer_init (struct snd_cs46xx *chip) 35008c2ecf20Sopenharmony_ci{ 35018c2ecf20Sopenharmony_ci dev_dbg(chip->card->dev, "initializing Voyetra mixer\n"); 35028c2ecf20Sopenharmony_ci 35038c2ecf20Sopenharmony_ci /* Enable SPDIF out */ 35048c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_EGPIODR, EGPIODR_GPOE0); 35058c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, BA0_EGPIOPTR, EGPIODR_GPOE0); 35068c2ecf20Sopenharmony_ci} 35078c2ecf20Sopenharmony_ci 35088c2ecf20Sopenharmony_cistatic void hercules_mixer_init (struct snd_cs46xx *chip) 35098c2ecf20Sopenharmony_ci{ 35108c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 35118c2ecf20Sopenharmony_ci unsigned int idx; 35128c2ecf20Sopenharmony_ci int err; 35138c2ecf20Sopenharmony_ci struct snd_card *card = chip->card; 35148c2ecf20Sopenharmony_ci#endif 35158c2ecf20Sopenharmony_ci 35168c2ecf20Sopenharmony_ci /* set EGPIO to default */ 35178c2ecf20Sopenharmony_ci hercules_init(chip); 35188c2ecf20Sopenharmony_ci 35198c2ecf20Sopenharmony_ci dev_dbg(chip->card->dev, "initializing Hercules mixer\n"); 35208c2ecf20Sopenharmony_ci 35218c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 35228c2ecf20Sopenharmony_ci if (chip->in_suspend) 35238c2ecf20Sopenharmony_ci return; 35248c2ecf20Sopenharmony_ci 35258c2ecf20Sopenharmony_ci for (idx = 0 ; idx < ARRAY_SIZE(snd_hercules_controls); idx++) { 35268c2ecf20Sopenharmony_ci struct snd_kcontrol *kctl; 35278c2ecf20Sopenharmony_ci 35288c2ecf20Sopenharmony_ci kctl = snd_ctl_new1(&snd_hercules_controls[idx], chip); 35298c2ecf20Sopenharmony_ci if ((err = snd_ctl_add(card, kctl)) < 0) { 35308c2ecf20Sopenharmony_ci dev_err(card->dev, 35318c2ecf20Sopenharmony_ci "failed to initialize Hercules mixer (%d)\n", 35328c2ecf20Sopenharmony_ci err); 35338c2ecf20Sopenharmony_ci break; 35348c2ecf20Sopenharmony_ci } 35358c2ecf20Sopenharmony_ci } 35368c2ecf20Sopenharmony_ci#endif 35378c2ecf20Sopenharmony_ci} 35388c2ecf20Sopenharmony_ci 35398c2ecf20Sopenharmony_ci 35408c2ecf20Sopenharmony_ci#if 0 35418c2ecf20Sopenharmony_ci/* 35428c2ecf20Sopenharmony_ci * Untested 35438c2ecf20Sopenharmony_ci */ 35448c2ecf20Sopenharmony_ci 35458c2ecf20Sopenharmony_cistatic void amp_voyetra_4294(struct snd_cs46xx *chip, int change) 35468c2ecf20Sopenharmony_ci{ 35478c2ecf20Sopenharmony_ci chip->amplifier += change; 35488c2ecf20Sopenharmony_ci 35498c2ecf20Sopenharmony_ci if (chip->amplifier) { 35508c2ecf20Sopenharmony_ci /* Switch the GPIO pins 7 and 8 to open drain */ 35518c2ecf20Sopenharmony_ci snd_cs46xx_codec_write(chip, 0x4C, 35528c2ecf20Sopenharmony_ci snd_cs46xx_codec_read(chip, 0x4C) & 0xFE7F); 35538c2ecf20Sopenharmony_ci snd_cs46xx_codec_write(chip, 0x4E, 35548c2ecf20Sopenharmony_ci snd_cs46xx_codec_read(chip, 0x4E) | 0x0180); 35558c2ecf20Sopenharmony_ci /* Now wake the AMP (this might be backwards) */ 35568c2ecf20Sopenharmony_ci snd_cs46xx_codec_write(chip, 0x54, 35578c2ecf20Sopenharmony_ci snd_cs46xx_codec_read(chip, 0x54) & ~0x0180); 35588c2ecf20Sopenharmony_ci } else { 35598c2ecf20Sopenharmony_ci snd_cs46xx_codec_write(chip, 0x54, 35608c2ecf20Sopenharmony_ci snd_cs46xx_codec_read(chip, 0x54) | 0x0180); 35618c2ecf20Sopenharmony_ci } 35628c2ecf20Sopenharmony_ci} 35638c2ecf20Sopenharmony_ci#endif 35648c2ecf20Sopenharmony_ci 35658c2ecf20Sopenharmony_ci 35668c2ecf20Sopenharmony_ci/* 35678c2ecf20Sopenharmony_ci * Handle the CLKRUN on a thinkpad. We must disable CLKRUN support 35688c2ecf20Sopenharmony_ci * whenever we need to beat on the chip. 35698c2ecf20Sopenharmony_ci * 35708c2ecf20Sopenharmony_ci * The original idea and code for this hack comes from David Kaiser at 35718c2ecf20Sopenharmony_ci * Linuxcare. Perhaps one day Crystal will document their chips well 35728c2ecf20Sopenharmony_ci * enough to make them useful. 35738c2ecf20Sopenharmony_ci */ 35748c2ecf20Sopenharmony_ci 35758c2ecf20Sopenharmony_cistatic void clkrun_hack(struct snd_cs46xx *chip, int change) 35768c2ecf20Sopenharmony_ci{ 35778c2ecf20Sopenharmony_ci u16 control, nval; 35788c2ecf20Sopenharmony_ci 35798c2ecf20Sopenharmony_ci if (!chip->acpi_port) 35808c2ecf20Sopenharmony_ci return; 35818c2ecf20Sopenharmony_ci 35828c2ecf20Sopenharmony_ci chip->amplifier += change; 35838c2ecf20Sopenharmony_ci 35848c2ecf20Sopenharmony_ci /* Read ACPI port */ 35858c2ecf20Sopenharmony_ci nval = control = inw(chip->acpi_port + 0x10); 35868c2ecf20Sopenharmony_ci 35878c2ecf20Sopenharmony_ci /* Flip CLKRUN off while running */ 35888c2ecf20Sopenharmony_ci if (! chip->amplifier) 35898c2ecf20Sopenharmony_ci nval |= 0x2000; 35908c2ecf20Sopenharmony_ci else 35918c2ecf20Sopenharmony_ci nval &= ~0x2000; 35928c2ecf20Sopenharmony_ci if (nval != control) 35938c2ecf20Sopenharmony_ci outw(nval, chip->acpi_port + 0x10); 35948c2ecf20Sopenharmony_ci} 35958c2ecf20Sopenharmony_ci 35968c2ecf20Sopenharmony_ci 35978c2ecf20Sopenharmony_ci/* 35988c2ecf20Sopenharmony_ci * detect intel piix4 35998c2ecf20Sopenharmony_ci */ 36008c2ecf20Sopenharmony_cistatic void clkrun_init(struct snd_cs46xx *chip) 36018c2ecf20Sopenharmony_ci{ 36028c2ecf20Sopenharmony_ci struct pci_dev *pdev; 36038c2ecf20Sopenharmony_ci u8 pp; 36048c2ecf20Sopenharmony_ci 36058c2ecf20Sopenharmony_ci chip->acpi_port = 0; 36068c2ecf20Sopenharmony_ci 36078c2ecf20Sopenharmony_ci pdev = pci_get_device(PCI_VENDOR_ID_INTEL, 36088c2ecf20Sopenharmony_ci PCI_DEVICE_ID_INTEL_82371AB_3, NULL); 36098c2ecf20Sopenharmony_ci if (pdev == NULL) 36108c2ecf20Sopenharmony_ci return; /* Not a thinkpad thats for sure */ 36118c2ecf20Sopenharmony_ci 36128c2ecf20Sopenharmony_ci /* Find the control port */ 36138c2ecf20Sopenharmony_ci pci_read_config_byte(pdev, 0x41, &pp); 36148c2ecf20Sopenharmony_ci chip->acpi_port = pp << 8; 36158c2ecf20Sopenharmony_ci pci_dev_put(pdev); 36168c2ecf20Sopenharmony_ci} 36178c2ecf20Sopenharmony_ci 36188c2ecf20Sopenharmony_ci 36198c2ecf20Sopenharmony_ci/* 36208c2ecf20Sopenharmony_ci * Card subid table 36218c2ecf20Sopenharmony_ci */ 36228c2ecf20Sopenharmony_ci 36238c2ecf20Sopenharmony_cistruct cs_card_type 36248c2ecf20Sopenharmony_ci{ 36258c2ecf20Sopenharmony_ci u16 vendor; 36268c2ecf20Sopenharmony_ci u16 id; 36278c2ecf20Sopenharmony_ci char *name; 36288c2ecf20Sopenharmony_ci void (*init)(struct snd_cs46xx *); 36298c2ecf20Sopenharmony_ci void (*amp)(struct snd_cs46xx *, int); 36308c2ecf20Sopenharmony_ci void (*active)(struct snd_cs46xx *, int); 36318c2ecf20Sopenharmony_ci void (*mixer_init)(struct snd_cs46xx *); 36328c2ecf20Sopenharmony_ci}; 36338c2ecf20Sopenharmony_ci 36348c2ecf20Sopenharmony_cistatic struct cs_card_type cards[] = { 36358c2ecf20Sopenharmony_ci { 36368c2ecf20Sopenharmony_ci .vendor = 0x1489, 36378c2ecf20Sopenharmony_ci .id = 0x7001, 36388c2ecf20Sopenharmony_ci .name = "Genius Soundmaker 128 value", 36398c2ecf20Sopenharmony_ci /* nothing special */ 36408c2ecf20Sopenharmony_ci }, 36418c2ecf20Sopenharmony_ci { 36428c2ecf20Sopenharmony_ci .vendor = 0x5053, 36438c2ecf20Sopenharmony_ci .id = 0x3357, 36448c2ecf20Sopenharmony_ci .name = "Voyetra", 36458c2ecf20Sopenharmony_ci .amp = amp_voyetra, 36468c2ecf20Sopenharmony_ci .mixer_init = voyetra_mixer_init, 36478c2ecf20Sopenharmony_ci }, 36488c2ecf20Sopenharmony_ci { 36498c2ecf20Sopenharmony_ci .vendor = 0x1071, 36508c2ecf20Sopenharmony_ci .id = 0x6003, 36518c2ecf20Sopenharmony_ci .name = "Mitac MI6020/21", 36528c2ecf20Sopenharmony_ci .amp = amp_voyetra, 36538c2ecf20Sopenharmony_ci }, 36548c2ecf20Sopenharmony_ci /* Hercules Game Theatre XP */ 36558c2ecf20Sopenharmony_ci { 36568c2ecf20Sopenharmony_ci .vendor = 0x14af, /* Guillemot Corporation */ 36578c2ecf20Sopenharmony_ci .id = 0x0050, 36588c2ecf20Sopenharmony_ci .name = "Hercules Game Theatre XP", 36598c2ecf20Sopenharmony_ci .amp = amp_hercules, 36608c2ecf20Sopenharmony_ci .mixer_init = hercules_mixer_init, 36618c2ecf20Sopenharmony_ci }, 36628c2ecf20Sopenharmony_ci { 36638c2ecf20Sopenharmony_ci .vendor = 0x1681, 36648c2ecf20Sopenharmony_ci .id = 0x0050, 36658c2ecf20Sopenharmony_ci .name = "Hercules Game Theatre XP", 36668c2ecf20Sopenharmony_ci .amp = amp_hercules, 36678c2ecf20Sopenharmony_ci .mixer_init = hercules_mixer_init, 36688c2ecf20Sopenharmony_ci }, 36698c2ecf20Sopenharmony_ci { 36708c2ecf20Sopenharmony_ci .vendor = 0x1681, 36718c2ecf20Sopenharmony_ci .id = 0x0051, 36728c2ecf20Sopenharmony_ci .name = "Hercules Game Theatre XP", 36738c2ecf20Sopenharmony_ci .amp = amp_hercules, 36748c2ecf20Sopenharmony_ci .mixer_init = hercules_mixer_init, 36758c2ecf20Sopenharmony_ci 36768c2ecf20Sopenharmony_ci }, 36778c2ecf20Sopenharmony_ci { 36788c2ecf20Sopenharmony_ci .vendor = 0x1681, 36798c2ecf20Sopenharmony_ci .id = 0x0052, 36808c2ecf20Sopenharmony_ci .name = "Hercules Game Theatre XP", 36818c2ecf20Sopenharmony_ci .amp = amp_hercules, 36828c2ecf20Sopenharmony_ci .mixer_init = hercules_mixer_init, 36838c2ecf20Sopenharmony_ci }, 36848c2ecf20Sopenharmony_ci { 36858c2ecf20Sopenharmony_ci .vendor = 0x1681, 36868c2ecf20Sopenharmony_ci .id = 0x0053, 36878c2ecf20Sopenharmony_ci .name = "Hercules Game Theatre XP", 36888c2ecf20Sopenharmony_ci .amp = amp_hercules, 36898c2ecf20Sopenharmony_ci .mixer_init = hercules_mixer_init, 36908c2ecf20Sopenharmony_ci }, 36918c2ecf20Sopenharmony_ci { 36928c2ecf20Sopenharmony_ci .vendor = 0x1681, 36938c2ecf20Sopenharmony_ci .id = 0x0054, 36948c2ecf20Sopenharmony_ci .name = "Hercules Game Theatre XP", 36958c2ecf20Sopenharmony_ci .amp = amp_hercules, 36968c2ecf20Sopenharmony_ci .mixer_init = hercules_mixer_init, 36978c2ecf20Sopenharmony_ci }, 36988c2ecf20Sopenharmony_ci /* Herculess Fortissimo */ 36998c2ecf20Sopenharmony_ci { 37008c2ecf20Sopenharmony_ci .vendor = 0x1681, 37018c2ecf20Sopenharmony_ci .id = 0xa010, 37028c2ecf20Sopenharmony_ci .name = "Hercules Gamesurround Fortissimo II", 37038c2ecf20Sopenharmony_ci }, 37048c2ecf20Sopenharmony_ci { 37058c2ecf20Sopenharmony_ci .vendor = 0x1681, 37068c2ecf20Sopenharmony_ci .id = 0xa011, 37078c2ecf20Sopenharmony_ci .name = "Hercules Gamesurround Fortissimo III 7.1", 37088c2ecf20Sopenharmony_ci }, 37098c2ecf20Sopenharmony_ci /* Teratec */ 37108c2ecf20Sopenharmony_ci { 37118c2ecf20Sopenharmony_ci .vendor = 0x153b, 37128c2ecf20Sopenharmony_ci .id = 0x112e, 37138c2ecf20Sopenharmony_ci .name = "Terratec DMX XFire 1024", 37148c2ecf20Sopenharmony_ci }, 37158c2ecf20Sopenharmony_ci { 37168c2ecf20Sopenharmony_ci .vendor = 0x153b, 37178c2ecf20Sopenharmony_ci .id = 0x1136, 37188c2ecf20Sopenharmony_ci .name = "Terratec SiXPack 5.1", 37198c2ecf20Sopenharmony_ci }, 37208c2ecf20Sopenharmony_ci /* Not sure if the 570 needs the clkrun hack */ 37218c2ecf20Sopenharmony_ci { 37228c2ecf20Sopenharmony_ci .vendor = PCI_VENDOR_ID_IBM, 37238c2ecf20Sopenharmony_ci .id = 0x0132, 37248c2ecf20Sopenharmony_ci .name = "Thinkpad 570", 37258c2ecf20Sopenharmony_ci .init = clkrun_init, 37268c2ecf20Sopenharmony_ci .active = clkrun_hack, 37278c2ecf20Sopenharmony_ci }, 37288c2ecf20Sopenharmony_ci { 37298c2ecf20Sopenharmony_ci .vendor = PCI_VENDOR_ID_IBM, 37308c2ecf20Sopenharmony_ci .id = 0x0153, 37318c2ecf20Sopenharmony_ci .name = "Thinkpad 600X/A20/T20", 37328c2ecf20Sopenharmony_ci .init = clkrun_init, 37338c2ecf20Sopenharmony_ci .active = clkrun_hack, 37348c2ecf20Sopenharmony_ci }, 37358c2ecf20Sopenharmony_ci { 37368c2ecf20Sopenharmony_ci .vendor = PCI_VENDOR_ID_IBM, 37378c2ecf20Sopenharmony_ci .id = 0x1010, 37388c2ecf20Sopenharmony_ci .name = "Thinkpad 600E (unsupported)", 37398c2ecf20Sopenharmony_ci }, 37408c2ecf20Sopenharmony_ci {} /* terminator */ 37418c2ecf20Sopenharmony_ci}; 37428c2ecf20Sopenharmony_ci 37438c2ecf20Sopenharmony_ci 37448c2ecf20Sopenharmony_ci/* 37458c2ecf20Sopenharmony_ci * APM support 37468c2ecf20Sopenharmony_ci */ 37478c2ecf20Sopenharmony_ci#ifdef CONFIG_PM_SLEEP 37488c2ecf20Sopenharmony_cistatic const unsigned int saved_regs[] = { 37498c2ecf20Sopenharmony_ci BA0_ACOSV, 37508c2ecf20Sopenharmony_ci /*BA0_ASER_FADDR,*/ 37518c2ecf20Sopenharmony_ci BA0_ASER_MASTER, 37528c2ecf20Sopenharmony_ci BA1_PVOL, 37538c2ecf20Sopenharmony_ci BA1_CVOL, 37548c2ecf20Sopenharmony_ci}; 37558c2ecf20Sopenharmony_ci 37568c2ecf20Sopenharmony_cistatic int snd_cs46xx_suspend(struct device *dev) 37578c2ecf20Sopenharmony_ci{ 37588c2ecf20Sopenharmony_ci struct snd_card *card = dev_get_drvdata(dev); 37598c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = card->private_data; 37608c2ecf20Sopenharmony_ci int i, amp_saved; 37618c2ecf20Sopenharmony_ci 37628c2ecf20Sopenharmony_ci snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); 37638c2ecf20Sopenharmony_ci chip->in_suspend = 1; 37648c2ecf20Sopenharmony_ci // chip->ac97_powerdown = snd_cs46xx_codec_read(chip, AC97_POWER_CONTROL); 37658c2ecf20Sopenharmony_ci // chip->ac97_general_purpose = snd_cs46xx_codec_read(chip, BA0_AC97_GENERAL_PURPOSE); 37668c2ecf20Sopenharmony_ci 37678c2ecf20Sopenharmony_ci snd_ac97_suspend(chip->ac97[CS46XX_PRIMARY_CODEC_INDEX]); 37688c2ecf20Sopenharmony_ci snd_ac97_suspend(chip->ac97[CS46XX_SECONDARY_CODEC_INDEX]); 37698c2ecf20Sopenharmony_ci 37708c2ecf20Sopenharmony_ci /* save some registers */ 37718c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(saved_regs); i++) 37728c2ecf20Sopenharmony_ci chip->saved_regs[i] = snd_cs46xx_peekBA0(chip, saved_regs[i]); 37738c2ecf20Sopenharmony_ci 37748c2ecf20Sopenharmony_ci amp_saved = chip->amplifier; 37758c2ecf20Sopenharmony_ci /* turn off amp */ 37768c2ecf20Sopenharmony_ci chip->amplifier_ctrl(chip, -chip->amplifier); 37778c2ecf20Sopenharmony_ci snd_cs46xx_hw_stop(chip); 37788c2ecf20Sopenharmony_ci /* disable CLKRUN */ 37798c2ecf20Sopenharmony_ci chip->active_ctrl(chip, -chip->amplifier); 37808c2ecf20Sopenharmony_ci chip->amplifier = amp_saved; /* restore the status */ 37818c2ecf20Sopenharmony_ci return 0; 37828c2ecf20Sopenharmony_ci} 37838c2ecf20Sopenharmony_ci 37848c2ecf20Sopenharmony_cistatic int snd_cs46xx_resume(struct device *dev) 37858c2ecf20Sopenharmony_ci{ 37868c2ecf20Sopenharmony_ci struct snd_card *card = dev_get_drvdata(dev); 37878c2ecf20Sopenharmony_ci struct snd_cs46xx *chip = card->private_data; 37888c2ecf20Sopenharmony_ci int amp_saved; 37898c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 37908c2ecf20Sopenharmony_ci int i; 37918c2ecf20Sopenharmony_ci#endif 37928c2ecf20Sopenharmony_ci unsigned int tmp; 37938c2ecf20Sopenharmony_ci 37948c2ecf20Sopenharmony_ci amp_saved = chip->amplifier; 37958c2ecf20Sopenharmony_ci chip->amplifier = 0; 37968c2ecf20Sopenharmony_ci chip->active_ctrl(chip, 1); /* force to on */ 37978c2ecf20Sopenharmony_ci 37988c2ecf20Sopenharmony_ci snd_cs46xx_chip_init(chip); 37998c2ecf20Sopenharmony_ci 38008c2ecf20Sopenharmony_ci snd_cs46xx_reset(chip); 38018c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 38028c2ecf20Sopenharmony_ci cs46xx_dsp_resume(chip); 38038c2ecf20Sopenharmony_ci /* restore some registers */ 38048c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(saved_regs); i++) 38058c2ecf20Sopenharmony_ci snd_cs46xx_pokeBA0(chip, saved_regs[i], chip->saved_regs[i]); 38068c2ecf20Sopenharmony_ci#else 38078c2ecf20Sopenharmony_ci snd_cs46xx_download_image(chip); 38088c2ecf20Sopenharmony_ci#endif 38098c2ecf20Sopenharmony_ci 38108c2ecf20Sopenharmony_ci#if 0 38118c2ecf20Sopenharmony_ci snd_cs46xx_codec_write(chip, BA0_AC97_GENERAL_PURPOSE, 38128c2ecf20Sopenharmony_ci chip->ac97_general_purpose); 38138c2ecf20Sopenharmony_ci snd_cs46xx_codec_write(chip, AC97_POWER_CONTROL, 38148c2ecf20Sopenharmony_ci chip->ac97_powerdown); 38158c2ecf20Sopenharmony_ci mdelay(10); 38168c2ecf20Sopenharmony_ci snd_cs46xx_codec_write(chip, BA0_AC97_POWERDOWN, 38178c2ecf20Sopenharmony_ci chip->ac97_powerdown); 38188c2ecf20Sopenharmony_ci mdelay(5); 38198c2ecf20Sopenharmony_ci#endif 38208c2ecf20Sopenharmony_ci 38218c2ecf20Sopenharmony_ci snd_ac97_resume(chip->ac97[CS46XX_PRIMARY_CODEC_INDEX]); 38228c2ecf20Sopenharmony_ci snd_ac97_resume(chip->ac97[CS46XX_SECONDARY_CODEC_INDEX]); 38238c2ecf20Sopenharmony_ci 38248c2ecf20Sopenharmony_ci /* 38258c2ecf20Sopenharmony_ci * Stop capture DMA. 38268c2ecf20Sopenharmony_ci */ 38278c2ecf20Sopenharmony_ci tmp = snd_cs46xx_peek(chip, BA1_CCTL); 38288c2ecf20Sopenharmony_ci chip->capt.ctl = tmp & 0x0000ffff; 38298c2ecf20Sopenharmony_ci snd_cs46xx_poke(chip, BA1_CCTL, tmp & 0xffff0000); 38308c2ecf20Sopenharmony_ci 38318c2ecf20Sopenharmony_ci mdelay(5); 38328c2ecf20Sopenharmony_ci 38338c2ecf20Sopenharmony_ci /* reset playback/capture */ 38348c2ecf20Sopenharmony_ci snd_cs46xx_set_play_sample_rate(chip, 8000); 38358c2ecf20Sopenharmony_ci snd_cs46xx_set_capture_sample_rate(chip, 8000); 38368c2ecf20Sopenharmony_ci snd_cs46xx_proc_start(chip); 38378c2ecf20Sopenharmony_ci 38388c2ecf20Sopenharmony_ci cs46xx_enable_stream_irqs(chip); 38398c2ecf20Sopenharmony_ci 38408c2ecf20Sopenharmony_ci if (amp_saved) 38418c2ecf20Sopenharmony_ci chip->amplifier_ctrl(chip, 1); /* turn amp on */ 38428c2ecf20Sopenharmony_ci else 38438c2ecf20Sopenharmony_ci chip->active_ctrl(chip, -1); /* disable CLKRUN */ 38448c2ecf20Sopenharmony_ci chip->amplifier = amp_saved; 38458c2ecf20Sopenharmony_ci chip->in_suspend = 0; 38468c2ecf20Sopenharmony_ci snd_power_change_state(card, SNDRV_CTL_POWER_D0); 38478c2ecf20Sopenharmony_ci return 0; 38488c2ecf20Sopenharmony_ci} 38498c2ecf20Sopenharmony_ci 38508c2ecf20Sopenharmony_ciSIMPLE_DEV_PM_OPS(snd_cs46xx_pm, snd_cs46xx_suspend, snd_cs46xx_resume); 38518c2ecf20Sopenharmony_ci#endif /* CONFIG_PM_SLEEP */ 38528c2ecf20Sopenharmony_ci 38538c2ecf20Sopenharmony_ci 38548c2ecf20Sopenharmony_ci/* 38558c2ecf20Sopenharmony_ci */ 38568c2ecf20Sopenharmony_ci 38578c2ecf20Sopenharmony_ciint snd_cs46xx_create(struct snd_card *card, 38588c2ecf20Sopenharmony_ci struct pci_dev *pci, 38598c2ecf20Sopenharmony_ci int external_amp, int thinkpad, 38608c2ecf20Sopenharmony_ci struct snd_cs46xx **rchip) 38618c2ecf20Sopenharmony_ci{ 38628c2ecf20Sopenharmony_ci struct snd_cs46xx *chip; 38638c2ecf20Sopenharmony_ci int err, idx; 38648c2ecf20Sopenharmony_ci struct snd_cs46xx_region *region; 38658c2ecf20Sopenharmony_ci struct cs_card_type *cp; 38668c2ecf20Sopenharmony_ci u16 ss_card, ss_vendor; 38678c2ecf20Sopenharmony_ci static const struct snd_device_ops ops = { 38688c2ecf20Sopenharmony_ci .dev_free = snd_cs46xx_dev_free, 38698c2ecf20Sopenharmony_ci }; 38708c2ecf20Sopenharmony_ci 38718c2ecf20Sopenharmony_ci *rchip = NULL; 38728c2ecf20Sopenharmony_ci 38738c2ecf20Sopenharmony_ci /* enable PCI device */ 38748c2ecf20Sopenharmony_ci if ((err = pci_enable_device(pci)) < 0) 38758c2ecf20Sopenharmony_ci return err; 38768c2ecf20Sopenharmony_ci 38778c2ecf20Sopenharmony_ci chip = kzalloc(sizeof(*chip), GFP_KERNEL); 38788c2ecf20Sopenharmony_ci if (chip == NULL) { 38798c2ecf20Sopenharmony_ci pci_disable_device(pci); 38808c2ecf20Sopenharmony_ci return -ENOMEM; 38818c2ecf20Sopenharmony_ci } 38828c2ecf20Sopenharmony_ci spin_lock_init(&chip->reg_lock); 38838c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 38848c2ecf20Sopenharmony_ci mutex_init(&chip->spos_mutex); 38858c2ecf20Sopenharmony_ci#endif 38868c2ecf20Sopenharmony_ci chip->card = card; 38878c2ecf20Sopenharmony_ci chip->pci = pci; 38888c2ecf20Sopenharmony_ci chip->irq = -1; 38898c2ecf20Sopenharmony_ci chip->ba0_addr = pci_resource_start(pci, 0); 38908c2ecf20Sopenharmony_ci chip->ba1_addr = pci_resource_start(pci, 1); 38918c2ecf20Sopenharmony_ci if (chip->ba0_addr == 0 || chip->ba0_addr == (unsigned long)~0 || 38928c2ecf20Sopenharmony_ci chip->ba1_addr == 0 || chip->ba1_addr == (unsigned long)~0) { 38938c2ecf20Sopenharmony_ci dev_err(chip->card->dev, 38948c2ecf20Sopenharmony_ci "wrong address(es) - ba0 = 0x%lx, ba1 = 0x%lx\n", 38958c2ecf20Sopenharmony_ci chip->ba0_addr, chip->ba1_addr); 38968c2ecf20Sopenharmony_ci snd_cs46xx_free(chip); 38978c2ecf20Sopenharmony_ci return -ENOMEM; 38988c2ecf20Sopenharmony_ci } 38998c2ecf20Sopenharmony_ci 39008c2ecf20Sopenharmony_ci region = &chip->region.name.ba0; 39018c2ecf20Sopenharmony_ci strcpy(region->name, "CS46xx_BA0"); 39028c2ecf20Sopenharmony_ci region->base = chip->ba0_addr; 39038c2ecf20Sopenharmony_ci region->size = CS46XX_BA0_SIZE; 39048c2ecf20Sopenharmony_ci 39058c2ecf20Sopenharmony_ci region = &chip->region.name.data0; 39068c2ecf20Sopenharmony_ci strcpy(region->name, "CS46xx_BA1_data0"); 39078c2ecf20Sopenharmony_ci region->base = chip->ba1_addr + BA1_SP_DMEM0; 39088c2ecf20Sopenharmony_ci region->size = CS46XX_BA1_DATA0_SIZE; 39098c2ecf20Sopenharmony_ci 39108c2ecf20Sopenharmony_ci region = &chip->region.name.data1; 39118c2ecf20Sopenharmony_ci strcpy(region->name, "CS46xx_BA1_data1"); 39128c2ecf20Sopenharmony_ci region->base = chip->ba1_addr + BA1_SP_DMEM1; 39138c2ecf20Sopenharmony_ci region->size = CS46XX_BA1_DATA1_SIZE; 39148c2ecf20Sopenharmony_ci 39158c2ecf20Sopenharmony_ci region = &chip->region.name.pmem; 39168c2ecf20Sopenharmony_ci strcpy(region->name, "CS46xx_BA1_pmem"); 39178c2ecf20Sopenharmony_ci region->base = chip->ba1_addr + BA1_SP_PMEM; 39188c2ecf20Sopenharmony_ci region->size = CS46XX_BA1_PRG_SIZE; 39198c2ecf20Sopenharmony_ci 39208c2ecf20Sopenharmony_ci region = &chip->region.name.reg; 39218c2ecf20Sopenharmony_ci strcpy(region->name, "CS46xx_BA1_reg"); 39228c2ecf20Sopenharmony_ci region->base = chip->ba1_addr + BA1_SP_REG; 39238c2ecf20Sopenharmony_ci region->size = CS46XX_BA1_REG_SIZE; 39248c2ecf20Sopenharmony_ci 39258c2ecf20Sopenharmony_ci /* set up amp and clkrun hack */ 39268c2ecf20Sopenharmony_ci pci_read_config_word(pci, PCI_SUBSYSTEM_VENDOR_ID, &ss_vendor); 39278c2ecf20Sopenharmony_ci pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &ss_card); 39288c2ecf20Sopenharmony_ci 39298c2ecf20Sopenharmony_ci for (cp = &cards[0]; cp->name; cp++) { 39308c2ecf20Sopenharmony_ci if (cp->vendor == ss_vendor && cp->id == ss_card) { 39318c2ecf20Sopenharmony_ci dev_dbg(chip->card->dev, "hack for %s enabled\n", 39328c2ecf20Sopenharmony_ci cp->name); 39338c2ecf20Sopenharmony_ci 39348c2ecf20Sopenharmony_ci chip->amplifier_ctrl = cp->amp; 39358c2ecf20Sopenharmony_ci chip->active_ctrl = cp->active; 39368c2ecf20Sopenharmony_ci chip->mixer_init = cp->mixer_init; 39378c2ecf20Sopenharmony_ci 39388c2ecf20Sopenharmony_ci if (cp->init) 39398c2ecf20Sopenharmony_ci cp->init(chip); 39408c2ecf20Sopenharmony_ci break; 39418c2ecf20Sopenharmony_ci } 39428c2ecf20Sopenharmony_ci } 39438c2ecf20Sopenharmony_ci 39448c2ecf20Sopenharmony_ci if (external_amp) { 39458c2ecf20Sopenharmony_ci dev_info(chip->card->dev, 39468c2ecf20Sopenharmony_ci "Crystal EAPD support forced on.\n"); 39478c2ecf20Sopenharmony_ci chip->amplifier_ctrl = amp_voyetra; 39488c2ecf20Sopenharmony_ci } 39498c2ecf20Sopenharmony_ci 39508c2ecf20Sopenharmony_ci if (thinkpad) { 39518c2ecf20Sopenharmony_ci dev_info(chip->card->dev, 39528c2ecf20Sopenharmony_ci "Activating CLKRUN hack for Thinkpad.\n"); 39538c2ecf20Sopenharmony_ci chip->active_ctrl = clkrun_hack; 39548c2ecf20Sopenharmony_ci clkrun_init(chip); 39558c2ecf20Sopenharmony_ci } 39568c2ecf20Sopenharmony_ci 39578c2ecf20Sopenharmony_ci if (chip->amplifier_ctrl == NULL) 39588c2ecf20Sopenharmony_ci chip->amplifier_ctrl = amp_none; 39598c2ecf20Sopenharmony_ci if (chip->active_ctrl == NULL) 39608c2ecf20Sopenharmony_ci chip->active_ctrl = amp_none; 39618c2ecf20Sopenharmony_ci 39628c2ecf20Sopenharmony_ci chip->active_ctrl(chip, 1); /* enable CLKRUN */ 39638c2ecf20Sopenharmony_ci 39648c2ecf20Sopenharmony_ci pci_set_master(pci); 39658c2ecf20Sopenharmony_ci 39668c2ecf20Sopenharmony_ci for (idx = 0; idx < 5; idx++) { 39678c2ecf20Sopenharmony_ci region = &chip->region.idx[idx]; 39688c2ecf20Sopenharmony_ci if ((region->resource = request_mem_region(region->base, region->size, 39698c2ecf20Sopenharmony_ci region->name)) == NULL) { 39708c2ecf20Sopenharmony_ci dev_err(chip->card->dev, 39718c2ecf20Sopenharmony_ci "unable to request memory region 0x%lx-0x%lx\n", 39728c2ecf20Sopenharmony_ci region->base, region->base + region->size - 1); 39738c2ecf20Sopenharmony_ci snd_cs46xx_free(chip); 39748c2ecf20Sopenharmony_ci return -EBUSY; 39758c2ecf20Sopenharmony_ci } 39768c2ecf20Sopenharmony_ci region->remap_addr = ioremap(region->base, region->size); 39778c2ecf20Sopenharmony_ci if (region->remap_addr == NULL) { 39788c2ecf20Sopenharmony_ci dev_err(chip->card->dev, 39798c2ecf20Sopenharmony_ci "%s ioremap problem\n", region->name); 39808c2ecf20Sopenharmony_ci snd_cs46xx_free(chip); 39818c2ecf20Sopenharmony_ci return -ENOMEM; 39828c2ecf20Sopenharmony_ci } 39838c2ecf20Sopenharmony_ci } 39848c2ecf20Sopenharmony_ci 39858c2ecf20Sopenharmony_ci if (request_irq(pci->irq, snd_cs46xx_interrupt, IRQF_SHARED, 39868c2ecf20Sopenharmony_ci KBUILD_MODNAME, chip)) { 39878c2ecf20Sopenharmony_ci dev_err(chip->card->dev, "unable to grab IRQ %d\n", pci->irq); 39888c2ecf20Sopenharmony_ci snd_cs46xx_free(chip); 39898c2ecf20Sopenharmony_ci return -EBUSY; 39908c2ecf20Sopenharmony_ci } 39918c2ecf20Sopenharmony_ci chip->irq = pci->irq; 39928c2ecf20Sopenharmony_ci card->sync_irq = chip->irq; 39938c2ecf20Sopenharmony_ci 39948c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 39958c2ecf20Sopenharmony_ci chip->dsp_spos_instance = cs46xx_dsp_spos_create(chip); 39968c2ecf20Sopenharmony_ci if (chip->dsp_spos_instance == NULL) { 39978c2ecf20Sopenharmony_ci snd_cs46xx_free(chip); 39988c2ecf20Sopenharmony_ci return -ENOMEM; 39998c2ecf20Sopenharmony_ci } 40008c2ecf20Sopenharmony_ci#endif 40018c2ecf20Sopenharmony_ci 40028c2ecf20Sopenharmony_ci err = snd_cs46xx_chip_init(chip); 40038c2ecf20Sopenharmony_ci if (err < 0) { 40048c2ecf20Sopenharmony_ci snd_cs46xx_free(chip); 40058c2ecf20Sopenharmony_ci return err; 40068c2ecf20Sopenharmony_ci } 40078c2ecf20Sopenharmony_ci 40088c2ecf20Sopenharmony_ci if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) { 40098c2ecf20Sopenharmony_ci snd_cs46xx_free(chip); 40108c2ecf20Sopenharmony_ci return err; 40118c2ecf20Sopenharmony_ci } 40128c2ecf20Sopenharmony_ci 40138c2ecf20Sopenharmony_ci snd_cs46xx_proc_init(card, chip); 40148c2ecf20Sopenharmony_ci 40158c2ecf20Sopenharmony_ci#ifdef CONFIG_PM_SLEEP 40168c2ecf20Sopenharmony_ci chip->saved_regs = kmalloc_array(ARRAY_SIZE(saved_regs), 40178c2ecf20Sopenharmony_ci sizeof(*chip->saved_regs), 40188c2ecf20Sopenharmony_ci GFP_KERNEL); 40198c2ecf20Sopenharmony_ci if (!chip->saved_regs) { 40208c2ecf20Sopenharmony_ci snd_cs46xx_free(chip); 40218c2ecf20Sopenharmony_ci return -ENOMEM; 40228c2ecf20Sopenharmony_ci } 40238c2ecf20Sopenharmony_ci#endif 40248c2ecf20Sopenharmony_ci 40258c2ecf20Sopenharmony_ci chip->active_ctrl(chip, -1); /* disable CLKRUN */ 40268c2ecf20Sopenharmony_ci 40278c2ecf20Sopenharmony_ci *rchip = chip; 40288c2ecf20Sopenharmony_ci return 0; 40298c2ecf20Sopenharmony_ci} 4030