18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Driver for Digigram pcxhr compatible soundcards 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * mixer interface for stereo cards 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Copyright (c) 2004 by Digigram <alsa@digigram.com> 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#include <linux/delay.h> 118c2ecf20Sopenharmony_ci#include <linux/io.h> 128c2ecf20Sopenharmony_ci#include <linux/pci.h> 138c2ecf20Sopenharmony_ci#include <sound/core.h> 148c2ecf20Sopenharmony_ci#include <sound/control.h> 158c2ecf20Sopenharmony_ci#include <sound/tlv.h> 168c2ecf20Sopenharmony_ci#include <sound/asoundef.h> 178c2ecf20Sopenharmony_ci#include "pcxhr.h" 188c2ecf20Sopenharmony_ci#include "pcxhr_core.h" 198c2ecf20Sopenharmony_ci#include "pcxhr_mix22.h" 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci/* registers used on the DSP and Xilinx (port 2) : HR stereo cards only */ 238c2ecf20Sopenharmony_ci#define PCXHR_DSP_RESET 0x20 248c2ecf20Sopenharmony_ci#define PCXHR_XLX_CFG 0x24 258c2ecf20Sopenharmony_ci#define PCXHR_XLX_RUER 0x28 268c2ecf20Sopenharmony_ci#define PCXHR_XLX_DATA 0x2C 278c2ecf20Sopenharmony_ci#define PCXHR_XLX_STATUS 0x30 288c2ecf20Sopenharmony_ci#define PCXHR_XLX_LOFREQ 0x34 298c2ecf20Sopenharmony_ci#define PCXHR_XLX_HIFREQ 0x38 308c2ecf20Sopenharmony_ci#define PCXHR_XLX_CSUER 0x3C 318c2ecf20Sopenharmony_ci#define PCXHR_XLX_SELMIC 0x40 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci#define PCXHR_DSP 2 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci/* byte access only ! */ 368c2ecf20Sopenharmony_ci#define PCXHR_INPB(mgr, x) inb((mgr)->port[PCXHR_DSP] + (x)) 378c2ecf20Sopenharmony_ci#define PCXHR_OUTPB(mgr, x, data) outb((data), (mgr)->port[PCXHR_DSP] + (x)) 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci/* values for PCHR_DSP_RESET register */ 418c2ecf20Sopenharmony_ci#define PCXHR_DSP_RESET_DSP 0x01 428c2ecf20Sopenharmony_ci#define PCXHR_DSP_RESET_MUTE 0x02 438c2ecf20Sopenharmony_ci#define PCXHR_DSP_RESET_CODEC 0x08 448c2ecf20Sopenharmony_ci#define PCXHR_DSP_RESET_SMPTE 0x10 458c2ecf20Sopenharmony_ci#define PCXHR_DSP_RESET_GPO_OFFSET 5 468c2ecf20Sopenharmony_ci#define PCXHR_DSP_RESET_GPO_MASK 0x60 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci/* values for PCHR_XLX_CFG register */ 498c2ecf20Sopenharmony_ci#define PCXHR_CFG_SYNCDSP_MASK 0x80 508c2ecf20Sopenharmony_ci#define PCXHR_CFG_DEPENDENCY_MASK 0x60 518c2ecf20Sopenharmony_ci#define PCXHR_CFG_INDEPENDANT_SEL 0x00 528c2ecf20Sopenharmony_ci#define PCXHR_CFG_MASTER_SEL 0x40 538c2ecf20Sopenharmony_ci#define PCXHR_CFG_SLAVE_SEL 0x20 548c2ecf20Sopenharmony_ci#define PCXHR_CFG_DATA_UER1_SEL_MASK 0x10 /* 0 (UER0), 1(UER1) */ 558c2ecf20Sopenharmony_ci#define PCXHR_CFG_DATAIN_SEL_MASK 0x08 /* 0 (ana), 1 (UER) */ 568c2ecf20Sopenharmony_ci#define PCXHR_CFG_SRC_MASK 0x04 /* 0 (Bypass), 1 (SRC Actif) */ 578c2ecf20Sopenharmony_ci#define PCXHR_CFG_CLOCK_UER1_SEL_MASK 0x02 /* 0 (UER0), 1(UER1) */ 588c2ecf20Sopenharmony_ci#define PCXHR_CFG_CLOCKIN_SEL_MASK 0x01 /* 0 (internal), 1 (AES/EBU) */ 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci/* values for PCHR_XLX_DATA register */ 618c2ecf20Sopenharmony_ci#define PCXHR_DATA_CODEC 0x80 628c2ecf20Sopenharmony_ci#define AKM_POWER_CONTROL_CMD 0xA007 638c2ecf20Sopenharmony_ci#define AKM_RESET_ON_CMD 0xA100 648c2ecf20Sopenharmony_ci#define AKM_RESET_OFF_CMD 0xA103 658c2ecf20Sopenharmony_ci#define AKM_CLOCK_INF_55K_CMD 0xA240 668c2ecf20Sopenharmony_ci#define AKM_CLOCK_SUP_55K_CMD 0xA24D 678c2ecf20Sopenharmony_ci#define AKM_MUTE_CMD 0xA38D 688c2ecf20Sopenharmony_ci#define AKM_UNMUTE_CMD 0xA30D 698c2ecf20Sopenharmony_ci#define AKM_LEFT_LEVEL_CMD 0xA600 708c2ecf20Sopenharmony_ci#define AKM_RIGHT_LEVEL_CMD 0xA700 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci/* values for PCHR_XLX_STATUS register - READ */ 738c2ecf20Sopenharmony_ci#define PCXHR_STAT_SRC_LOCK 0x01 748c2ecf20Sopenharmony_ci#define PCXHR_STAT_LEVEL_IN 0x02 758c2ecf20Sopenharmony_ci#define PCXHR_STAT_GPI_OFFSET 2 768c2ecf20Sopenharmony_ci#define PCXHR_STAT_GPI_MASK 0x0C 778c2ecf20Sopenharmony_ci#define PCXHR_STAT_MIC_CAPS 0x10 788c2ecf20Sopenharmony_ci/* values for PCHR_XLX_STATUS register - WRITE */ 798c2ecf20Sopenharmony_ci#define PCXHR_STAT_FREQ_SYNC_MASK 0x01 808c2ecf20Sopenharmony_ci#define PCXHR_STAT_FREQ_UER1_MASK 0x02 818c2ecf20Sopenharmony_ci#define PCXHR_STAT_FREQ_SAVE_MASK 0x80 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci/* values for PCHR_XLX_CSUER register */ 848c2ecf20Sopenharmony_ci#define PCXHR_SUER1_BIT_U_READ_MASK 0x80 858c2ecf20Sopenharmony_ci#define PCXHR_SUER1_BIT_C_READ_MASK 0x40 868c2ecf20Sopenharmony_ci#define PCXHR_SUER1_DATA_PRESENT_MASK 0x20 878c2ecf20Sopenharmony_ci#define PCXHR_SUER1_CLOCK_PRESENT_MASK 0x10 888c2ecf20Sopenharmony_ci#define PCXHR_SUER_BIT_U_READ_MASK 0x08 898c2ecf20Sopenharmony_ci#define PCXHR_SUER_BIT_C_READ_MASK 0x04 908c2ecf20Sopenharmony_ci#define PCXHR_SUER_DATA_PRESENT_MASK 0x02 918c2ecf20Sopenharmony_ci#define PCXHR_SUER_CLOCK_PRESENT_MASK 0x01 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_ci#define PCXHR_SUER_BIT_U_WRITE_MASK 0x02 948c2ecf20Sopenharmony_ci#define PCXHR_SUER_BIT_C_WRITE_MASK 0x01 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ci/* values for PCXHR_XLX_SELMIC register - WRITE */ 978c2ecf20Sopenharmony_ci#define PCXHR_SELMIC_PREAMPLI_OFFSET 2 988c2ecf20Sopenharmony_ci#define PCXHR_SELMIC_PREAMPLI_MASK 0x0C 998c2ecf20Sopenharmony_ci#define PCXHR_SELMIC_PHANTOM_ALIM 0x80 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_cistatic const unsigned char g_hr222_p_level[] = { 1038c2ecf20Sopenharmony_ci 0x00, /* [000] -49.5 dB: AKM[000] = -1.#INF dB (mute) */ 1048c2ecf20Sopenharmony_ci 0x01, /* [001] -49.0 dB: AKM[001] = -48.131 dB (diff=0.86920 dB) */ 1058c2ecf20Sopenharmony_ci 0x01, /* [002] -48.5 dB: AKM[001] = -48.131 dB (diff=0.36920 dB) */ 1068c2ecf20Sopenharmony_ci 0x01, /* [003] -48.0 dB: AKM[001] = -48.131 dB (diff=0.13080 dB) */ 1078c2ecf20Sopenharmony_ci 0x01, /* [004] -47.5 dB: AKM[001] = -48.131 dB (diff=0.63080 dB) */ 1088c2ecf20Sopenharmony_ci 0x01, /* [005] -46.5 dB: AKM[001] = -48.131 dB (diff=1.63080 dB) */ 1098c2ecf20Sopenharmony_ci 0x01, /* [006] -47.0 dB: AKM[001] = -48.131 dB (diff=1.13080 dB) */ 1108c2ecf20Sopenharmony_ci 0x01, /* [007] -46.0 dB: AKM[001] = -48.131 dB (diff=2.13080 dB) */ 1118c2ecf20Sopenharmony_ci 0x01, /* [008] -45.5 dB: AKM[001] = -48.131 dB (diff=2.63080 dB) */ 1128c2ecf20Sopenharmony_ci 0x02, /* [009] -45.0 dB: AKM[002] = -42.110 dB (diff=2.88980 dB) */ 1138c2ecf20Sopenharmony_ci 0x02, /* [010] -44.5 dB: AKM[002] = -42.110 dB (diff=2.38980 dB) */ 1148c2ecf20Sopenharmony_ci 0x02, /* [011] -44.0 dB: AKM[002] = -42.110 dB (diff=1.88980 dB) */ 1158c2ecf20Sopenharmony_ci 0x02, /* [012] -43.5 dB: AKM[002] = -42.110 dB (diff=1.38980 dB) */ 1168c2ecf20Sopenharmony_ci 0x02, /* [013] -43.0 dB: AKM[002] = -42.110 dB (diff=0.88980 dB) */ 1178c2ecf20Sopenharmony_ci 0x02, /* [014] -42.5 dB: AKM[002] = -42.110 dB (diff=0.38980 dB) */ 1188c2ecf20Sopenharmony_ci 0x02, /* [015] -42.0 dB: AKM[002] = -42.110 dB (diff=0.11020 dB) */ 1198c2ecf20Sopenharmony_ci 0x02, /* [016] -41.5 dB: AKM[002] = -42.110 dB (diff=0.61020 dB) */ 1208c2ecf20Sopenharmony_ci 0x02, /* [017] -41.0 dB: AKM[002] = -42.110 dB (diff=1.11020 dB) */ 1218c2ecf20Sopenharmony_ci 0x02, /* [018] -40.5 dB: AKM[002] = -42.110 dB (diff=1.61020 dB) */ 1228c2ecf20Sopenharmony_ci 0x03, /* [019] -40.0 dB: AKM[003] = -38.588 dB (diff=1.41162 dB) */ 1238c2ecf20Sopenharmony_ci 0x03, /* [020] -39.5 dB: AKM[003] = -38.588 dB (diff=0.91162 dB) */ 1248c2ecf20Sopenharmony_ci 0x03, /* [021] -39.0 dB: AKM[003] = -38.588 dB (diff=0.41162 dB) */ 1258c2ecf20Sopenharmony_ci 0x03, /* [022] -38.5 dB: AKM[003] = -38.588 dB (diff=0.08838 dB) */ 1268c2ecf20Sopenharmony_ci 0x03, /* [023] -38.0 dB: AKM[003] = -38.588 dB (diff=0.58838 dB) */ 1278c2ecf20Sopenharmony_ci 0x03, /* [024] -37.5 dB: AKM[003] = -38.588 dB (diff=1.08838 dB) */ 1288c2ecf20Sopenharmony_ci 0x04, /* [025] -37.0 dB: AKM[004] = -36.090 dB (diff=0.91040 dB) */ 1298c2ecf20Sopenharmony_ci 0x04, /* [026] -36.5 dB: AKM[004] = -36.090 dB (diff=0.41040 dB) */ 1308c2ecf20Sopenharmony_ci 0x04, /* [027] -36.0 dB: AKM[004] = -36.090 dB (diff=0.08960 dB) */ 1318c2ecf20Sopenharmony_ci 0x04, /* [028] -35.5 dB: AKM[004] = -36.090 dB (diff=0.58960 dB) */ 1328c2ecf20Sopenharmony_ci 0x05, /* [029] -35.0 dB: AKM[005] = -34.151 dB (diff=0.84860 dB) */ 1338c2ecf20Sopenharmony_ci 0x05, /* [030] -34.5 dB: AKM[005] = -34.151 dB (diff=0.34860 dB) */ 1348c2ecf20Sopenharmony_ci 0x05, /* [031] -34.0 dB: AKM[005] = -34.151 dB (diff=0.15140 dB) */ 1358c2ecf20Sopenharmony_ci 0x05, /* [032] -33.5 dB: AKM[005] = -34.151 dB (diff=0.65140 dB) */ 1368c2ecf20Sopenharmony_ci 0x06, /* [033] -33.0 dB: AKM[006] = -32.568 dB (diff=0.43222 dB) */ 1378c2ecf20Sopenharmony_ci 0x06, /* [034] -32.5 dB: AKM[006] = -32.568 dB (diff=0.06778 dB) */ 1388c2ecf20Sopenharmony_ci 0x06, /* [035] -32.0 dB: AKM[006] = -32.568 dB (diff=0.56778 dB) */ 1398c2ecf20Sopenharmony_ci 0x07, /* [036] -31.5 dB: AKM[007] = -31.229 dB (diff=0.27116 dB) */ 1408c2ecf20Sopenharmony_ci 0x07, /* [037] -31.0 dB: AKM[007] = -31.229 dB (diff=0.22884 dB) */ 1418c2ecf20Sopenharmony_ci 0x08, /* [038] -30.5 dB: AKM[008] = -30.069 dB (diff=0.43100 dB) */ 1428c2ecf20Sopenharmony_ci 0x08, /* [039] -30.0 dB: AKM[008] = -30.069 dB (diff=0.06900 dB) */ 1438c2ecf20Sopenharmony_ci 0x09, /* [040] -29.5 dB: AKM[009] = -29.046 dB (diff=0.45405 dB) */ 1448c2ecf20Sopenharmony_ci 0x09, /* [041] -29.0 dB: AKM[009] = -29.046 dB (diff=0.04595 dB) */ 1458c2ecf20Sopenharmony_ci 0x0a, /* [042] -28.5 dB: AKM[010] = -28.131 dB (diff=0.36920 dB) */ 1468c2ecf20Sopenharmony_ci 0x0a, /* [043] -28.0 dB: AKM[010] = -28.131 dB (diff=0.13080 dB) */ 1478c2ecf20Sopenharmony_ci 0x0b, /* [044] -27.5 dB: AKM[011] = -27.303 dB (diff=0.19705 dB) */ 1488c2ecf20Sopenharmony_ci 0x0b, /* [045] -27.0 dB: AKM[011] = -27.303 dB (diff=0.30295 dB) */ 1498c2ecf20Sopenharmony_ci 0x0c, /* [046] -26.5 dB: AKM[012] = -26.547 dB (diff=0.04718 dB) */ 1508c2ecf20Sopenharmony_ci 0x0d, /* [047] -26.0 dB: AKM[013] = -25.852 dB (diff=0.14806 dB) */ 1518c2ecf20Sopenharmony_ci 0x0e, /* [048] -25.5 dB: AKM[014] = -25.208 dB (diff=0.29176 dB) */ 1528c2ecf20Sopenharmony_ci 0x0e, /* [049] -25.0 dB: AKM[014] = -25.208 dB (diff=0.20824 dB) */ 1538c2ecf20Sopenharmony_ci 0x0f, /* [050] -24.5 dB: AKM[015] = -24.609 dB (diff=0.10898 dB) */ 1548c2ecf20Sopenharmony_ci 0x10, /* [051] -24.0 dB: AKM[016] = -24.048 dB (diff=0.04840 dB) */ 1558c2ecf20Sopenharmony_ci 0x11, /* [052] -23.5 dB: AKM[017] = -23.522 dB (diff=0.02183 dB) */ 1568c2ecf20Sopenharmony_ci 0x12, /* [053] -23.0 dB: AKM[018] = -23.025 dB (diff=0.02535 dB) */ 1578c2ecf20Sopenharmony_ci 0x13, /* [054] -22.5 dB: AKM[019] = -22.556 dB (diff=0.05573 dB) */ 1588c2ecf20Sopenharmony_ci 0x14, /* [055] -22.0 dB: AKM[020] = -22.110 dB (diff=0.11020 dB) */ 1598c2ecf20Sopenharmony_ci 0x15, /* [056] -21.5 dB: AKM[021] = -21.686 dB (diff=0.18642 dB) */ 1608c2ecf20Sopenharmony_ci 0x17, /* [057] -21.0 dB: AKM[023] = -20.896 dB (diff=0.10375 dB) */ 1618c2ecf20Sopenharmony_ci 0x18, /* [058] -20.5 dB: AKM[024] = -20.527 dB (diff=0.02658 dB) */ 1628c2ecf20Sopenharmony_ci 0x1a, /* [059] -20.0 dB: AKM[026] = -19.831 dB (diff=0.16866 dB) */ 1638c2ecf20Sopenharmony_ci 0x1b, /* [060] -19.5 dB: AKM[027] = -19.504 dB (diff=0.00353 dB) */ 1648c2ecf20Sopenharmony_ci 0x1d, /* [061] -19.0 dB: AKM[029] = -18.883 dB (diff=0.11716 dB) */ 1658c2ecf20Sopenharmony_ci 0x1e, /* [062] -18.5 dB: AKM[030] = -18.588 dB (diff=0.08838 dB) */ 1668c2ecf20Sopenharmony_ci 0x20, /* [063] -18.0 dB: AKM[032] = -18.028 dB (diff=0.02780 dB) */ 1678c2ecf20Sopenharmony_ci 0x22, /* [064] -17.5 dB: AKM[034] = -17.501 dB (diff=0.00123 dB) */ 1688c2ecf20Sopenharmony_ci 0x24, /* [065] -17.0 dB: AKM[036] = -17.005 dB (diff=0.00475 dB) */ 1698c2ecf20Sopenharmony_ci 0x26, /* [066] -16.5 dB: AKM[038] = -16.535 dB (diff=0.03513 dB) */ 1708c2ecf20Sopenharmony_ci 0x28, /* [067] -16.0 dB: AKM[040] = -16.090 dB (diff=0.08960 dB) */ 1718c2ecf20Sopenharmony_ci 0x2b, /* [068] -15.5 dB: AKM[043] = -15.461 dB (diff=0.03857 dB) */ 1728c2ecf20Sopenharmony_ci 0x2d, /* [069] -15.0 dB: AKM[045] = -15.067 dB (diff=0.06655 dB) */ 1738c2ecf20Sopenharmony_ci 0x30, /* [070] -14.5 dB: AKM[048] = -14.506 dB (diff=0.00598 dB) */ 1748c2ecf20Sopenharmony_ci 0x33, /* [071] -14.0 dB: AKM[051] = -13.979 dB (diff=0.02060 dB) */ 1758c2ecf20Sopenharmony_ci 0x36, /* [072] -13.5 dB: AKM[054] = -13.483 dB (diff=0.01707 dB) */ 1768c2ecf20Sopenharmony_ci 0x39, /* [073] -13.0 dB: AKM[057] = -13.013 dB (diff=0.01331 dB) */ 1778c2ecf20Sopenharmony_ci 0x3c, /* [074] -12.5 dB: AKM[060] = -12.568 dB (diff=0.06778 dB) */ 1788c2ecf20Sopenharmony_ci 0x40, /* [075] -12.0 dB: AKM[064] = -12.007 dB (diff=0.00720 dB) */ 1798c2ecf20Sopenharmony_ci 0x44, /* [076] -11.5 dB: AKM[068] = -11.481 dB (diff=0.01937 dB) */ 1808c2ecf20Sopenharmony_ci 0x48, /* [077] -11.0 dB: AKM[072] = -10.984 dB (diff=0.01585 dB) */ 1818c2ecf20Sopenharmony_ci 0x4c, /* [078] -10.5 dB: AKM[076] = -10.515 dB (diff=0.01453 dB) */ 1828c2ecf20Sopenharmony_ci 0x51, /* [079] -10.0 dB: AKM[081] = -9.961 dB (diff=0.03890 dB) */ 1838c2ecf20Sopenharmony_ci 0x55, /* [080] -9.5 dB: AKM[085] = -9.542 dB (diff=0.04243 dB) */ 1848c2ecf20Sopenharmony_ci 0x5a, /* [081] -9.0 dB: AKM[090] = -9.046 dB (diff=0.04595 dB) */ 1858c2ecf20Sopenharmony_ci 0x60, /* [082] -8.5 dB: AKM[096] = -8.485 dB (diff=0.01462 dB) */ 1868c2ecf20Sopenharmony_ci 0x66, /* [083] -8.0 dB: AKM[102] = -7.959 dB (diff=0.04120 dB) */ 1878c2ecf20Sopenharmony_ci 0x6c, /* [084] -7.5 dB: AKM[108] = -7.462 dB (diff=0.03767 dB) */ 1888c2ecf20Sopenharmony_ci 0x72, /* [085] -7.0 dB: AKM[114] = -6.993 dB (diff=0.00729 dB) */ 1898c2ecf20Sopenharmony_ci 0x79, /* [086] -6.5 dB: AKM[121] = -6.475 dB (diff=0.02490 dB) */ 1908c2ecf20Sopenharmony_ci 0x80, /* [087] -6.0 dB: AKM[128] = -5.987 dB (diff=0.01340 dB) */ 1918c2ecf20Sopenharmony_ci 0x87, /* [088] -5.5 dB: AKM[135] = -5.524 dB (diff=0.02413 dB) */ 1928c2ecf20Sopenharmony_ci 0x8f, /* [089] -5.0 dB: AKM[143] = -5.024 dB (diff=0.02408 dB) */ 1938c2ecf20Sopenharmony_ci 0x98, /* [090] -4.5 dB: AKM[152] = -4.494 dB (diff=0.00607 dB) */ 1948c2ecf20Sopenharmony_ci 0xa1, /* [091] -4.0 dB: AKM[161] = -3.994 dB (diff=0.00571 dB) */ 1958c2ecf20Sopenharmony_ci 0xaa, /* [092] -3.5 dB: AKM[170] = -3.522 dB (diff=0.02183 dB) */ 1968c2ecf20Sopenharmony_ci 0xb5, /* [093] -3.0 dB: AKM[181] = -2.977 dB (diff=0.02277 dB) */ 1978c2ecf20Sopenharmony_ci 0xbf, /* [094] -2.5 dB: AKM[191] = -2.510 dB (diff=0.01014 dB) */ 1988c2ecf20Sopenharmony_ci 0xcb, /* [095] -2.0 dB: AKM[203] = -1.981 dB (diff=0.01912 dB) */ 1998c2ecf20Sopenharmony_ci 0xd7, /* [096] -1.5 dB: AKM[215] = -1.482 dB (diff=0.01797 dB) */ 2008c2ecf20Sopenharmony_ci 0xe3, /* [097] -1.0 dB: AKM[227] = -1.010 dB (diff=0.01029 dB) */ 2018c2ecf20Sopenharmony_ci 0xf1, /* [098] -0.5 dB: AKM[241] = -0.490 dB (diff=0.00954 dB) */ 2028c2ecf20Sopenharmony_ci 0xff, /* [099] +0.0 dB: AKM[255] = +0.000 dB (diff=0.00000 dB) */ 2038c2ecf20Sopenharmony_ci}; 2048c2ecf20Sopenharmony_ci 2058c2ecf20Sopenharmony_ci 2068c2ecf20Sopenharmony_cistatic void hr222_config_akm(struct pcxhr_mgr *mgr, unsigned short data) 2078c2ecf20Sopenharmony_ci{ 2088c2ecf20Sopenharmony_ci unsigned short mask = 0x8000; 2098c2ecf20Sopenharmony_ci /* activate access to codec registers */ 2108c2ecf20Sopenharmony_ci PCXHR_INPB(mgr, PCXHR_XLX_HIFREQ); 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_ci while (mask) { 2138c2ecf20Sopenharmony_ci PCXHR_OUTPB(mgr, PCXHR_XLX_DATA, 2148c2ecf20Sopenharmony_ci data & mask ? PCXHR_DATA_CODEC : 0); 2158c2ecf20Sopenharmony_ci mask >>= 1; 2168c2ecf20Sopenharmony_ci } 2178c2ecf20Sopenharmony_ci /* termiate access to codec registers */ 2188c2ecf20Sopenharmony_ci PCXHR_INPB(mgr, PCXHR_XLX_RUER); 2198c2ecf20Sopenharmony_ci} 2208c2ecf20Sopenharmony_ci 2218c2ecf20Sopenharmony_ci 2228c2ecf20Sopenharmony_cistatic int hr222_set_hw_playback_level(struct pcxhr_mgr *mgr, 2238c2ecf20Sopenharmony_ci int idx, int level) 2248c2ecf20Sopenharmony_ci{ 2258c2ecf20Sopenharmony_ci unsigned short cmd; 2268c2ecf20Sopenharmony_ci if (idx > 1 || 2278c2ecf20Sopenharmony_ci level < 0 || 2288c2ecf20Sopenharmony_ci level >= ARRAY_SIZE(g_hr222_p_level)) 2298c2ecf20Sopenharmony_ci return -EINVAL; 2308c2ecf20Sopenharmony_ci 2318c2ecf20Sopenharmony_ci if (idx == 0) 2328c2ecf20Sopenharmony_ci cmd = AKM_LEFT_LEVEL_CMD; 2338c2ecf20Sopenharmony_ci else 2348c2ecf20Sopenharmony_ci cmd = AKM_RIGHT_LEVEL_CMD; 2358c2ecf20Sopenharmony_ci 2368c2ecf20Sopenharmony_ci /* conversion from PmBoardCodedLevel to AKM nonlinear programming */ 2378c2ecf20Sopenharmony_ci cmd += g_hr222_p_level[level]; 2388c2ecf20Sopenharmony_ci 2398c2ecf20Sopenharmony_ci hr222_config_akm(mgr, cmd); 2408c2ecf20Sopenharmony_ci return 0; 2418c2ecf20Sopenharmony_ci} 2428c2ecf20Sopenharmony_ci 2438c2ecf20Sopenharmony_ci 2448c2ecf20Sopenharmony_cistatic int hr222_set_hw_capture_level(struct pcxhr_mgr *mgr, 2458c2ecf20Sopenharmony_ci int level_l, int level_r, int level_mic) 2468c2ecf20Sopenharmony_ci{ 2478c2ecf20Sopenharmony_ci /* program all input levels at the same time */ 2488c2ecf20Sopenharmony_ci unsigned int data; 2498c2ecf20Sopenharmony_ci int i; 2508c2ecf20Sopenharmony_ci 2518c2ecf20Sopenharmony_ci if (!mgr->capture_chips) 2528c2ecf20Sopenharmony_ci return -EINVAL; /* no PCX22 */ 2538c2ecf20Sopenharmony_ci 2548c2ecf20Sopenharmony_ci data = ((level_mic & 0xff) << 24); /* micro is mono, but apply */ 2558c2ecf20Sopenharmony_ci data |= ((level_mic & 0xff) << 16); /* level on both channels */ 2568c2ecf20Sopenharmony_ci data |= ((level_r & 0xff) << 8); /* line input right channel */ 2578c2ecf20Sopenharmony_ci data |= (level_l & 0xff); /* line input left channel */ 2588c2ecf20Sopenharmony_ci 2598c2ecf20Sopenharmony_ci PCXHR_INPB(mgr, PCXHR_XLX_DATA); /* activate input codec */ 2608c2ecf20Sopenharmony_ci /* send 32 bits (4 x 8 bits) */ 2618c2ecf20Sopenharmony_ci for (i = 0; i < 32; i++, data <<= 1) { 2628c2ecf20Sopenharmony_ci PCXHR_OUTPB(mgr, PCXHR_XLX_DATA, 2638c2ecf20Sopenharmony_ci (data & 0x80000000) ? PCXHR_DATA_CODEC : 0); 2648c2ecf20Sopenharmony_ci } 2658c2ecf20Sopenharmony_ci PCXHR_INPB(mgr, PCXHR_XLX_RUER); /* close input level codec */ 2668c2ecf20Sopenharmony_ci return 0; 2678c2ecf20Sopenharmony_ci} 2688c2ecf20Sopenharmony_ci 2698c2ecf20Sopenharmony_cistatic void hr222_micro_boost(struct pcxhr_mgr *mgr, int level); 2708c2ecf20Sopenharmony_ci 2718c2ecf20Sopenharmony_ciint hr222_sub_init(struct pcxhr_mgr *mgr) 2728c2ecf20Sopenharmony_ci{ 2738c2ecf20Sopenharmony_ci unsigned char reg; 2748c2ecf20Sopenharmony_ci 2758c2ecf20Sopenharmony_ci mgr->board_has_analog = 1; /* analog always available */ 2768c2ecf20Sopenharmony_ci mgr->xlx_cfg = PCXHR_CFG_SYNCDSP_MASK; 2778c2ecf20Sopenharmony_ci 2788c2ecf20Sopenharmony_ci reg = PCXHR_INPB(mgr, PCXHR_XLX_STATUS); 2798c2ecf20Sopenharmony_ci if (reg & PCXHR_STAT_MIC_CAPS) 2808c2ecf20Sopenharmony_ci mgr->board_has_mic = 1; /* microphone available */ 2818c2ecf20Sopenharmony_ci dev_dbg(&mgr->pci->dev, 2828c2ecf20Sopenharmony_ci "MIC input available = %d\n", mgr->board_has_mic); 2838c2ecf20Sopenharmony_ci 2848c2ecf20Sopenharmony_ci /* reset codec */ 2858c2ecf20Sopenharmony_ci PCXHR_OUTPB(mgr, PCXHR_DSP_RESET, 2868c2ecf20Sopenharmony_ci PCXHR_DSP_RESET_DSP); 2878c2ecf20Sopenharmony_ci msleep(5); 2888c2ecf20Sopenharmony_ci mgr->dsp_reset = PCXHR_DSP_RESET_DSP | 2898c2ecf20Sopenharmony_ci PCXHR_DSP_RESET_MUTE | 2908c2ecf20Sopenharmony_ci PCXHR_DSP_RESET_CODEC; 2918c2ecf20Sopenharmony_ci PCXHR_OUTPB(mgr, PCXHR_DSP_RESET, mgr->dsp_reset); 2928c2ecf20Sopenharmony_ci /* hr222_write_gpo(mgr, 0); does the same */ 2938c2ecf20Sopenharmony_ci msleep(5); 2948c2ecf20Sopenharmony_ci 2958c2ecf20Sopenharmony_ci /* config AKM */ 2968c2ecf20Sopenharmony_ci hr222_config_akm(mgr, AKM_POWER_CONTROL_CMD); 2978c2ecf20Sopenharmony_ci hr222_config_akm(mgr, AKM_CLOCK_INF_55K_CMD); 2988c2ecf20Sopenharmony_ci hr222_config_akm(mgr, AKM_UNMUTE_CMD); 2998c2ecf20Sopenharmony_ci hr222_config_akm(mgr, AKM_RESET_OFF_CMD); 3008c2ecf20Sopenharmony_ci 3018c2ecf20Sopenharmony_ci /* init micro boost */ 3028c2ecf20Sopenharmony_ci hr222_micro_boost(mgr, 0); 3038c2ecf20Sopenharmony_ci 3048c2ecf20Sopenharmony_ci return 0; 3058c2ecf20Sopenharmony_ci} 3068c2ecf20Sopenharmony_ci 3078c2ecf20Sopenharmony_ci 3088c2ecf20Sopenharmony_ci/* calc PLL register */ 3098c2ecf20Sopenharmony_ci/* TODO : there is a very similar fct in pcxhr.c */ 3108c2ecf20Sopenharmony_cistatic int hr222_pll_freq_register(unsigned int freq, 3118c2ecf20Sopenharmony_ci unsigned int *pllreg, 3128c2ecf20Sopenharmony_ci unsigned int *realfreq) 3138c2ecf20Sopenharmony_ci{ 3148c2ecf20Sopenharmony_ci unsigned int reg; 3158c2ecf20Sopenharmony_ci 3168c2ecf20Sopenharmony_ci if (freq < 6900 || freq > 219000) 3178c2ecf20Sopenharmony_ci return -EINVAL; 3188c2ecf20Sopenharmony_ci reg = (28224000 * 2) / freq; 3198c2ecf20Sopenharmony_ci reg = (reg - 1) / 2; 3208c2ecf20Sopenharmony_ci if (reg < 0x100) 3218c2ecf20Sopenharmony_ci *pllreg = reg + 0xC00; 3228c2ecf20Sopenharmony_ci else if (reg < 0x200) 3238c2ecf20Sopenharmony_ci *pllreg = reg + 0x800; 3248c2ecf20Sopenharmony_ci else if (reg < 0x400) 3258c2ecf20Sopenharmony_ci *pllreg = reg & 0x1ff; 3268c2ecf20Sopenharmony_ci else if (reg < 0x800) { 3278c2ecf20Sopenharmony_ci *pllreg = ((reg >> 1) & 0x1ff) + 0x200; 3288c2ecf20Sopenharmony_ci reg &= ~1; 3298c2ecf20Sopenharmony_ci } else { 3308c2ecf20Sopenharmony_ci *pllreg = ((reg >> 2) & 0x1ff) + 0x400; 3318c2ecf20Sopenharmony_ci reg &= ~3; 3328c2ecf20Sopenharmony_ci } 3338c2ecf20Sopenharmony_ci if (realfreq) 3348c2ecf20Sopenharmony_ci *realfreq = (28224000 / (reg + 1)); 3358c2ecf20Sopenharmony_ci return 0; 3368c2ecf20Sopenharmony_ci} 3378c2ecf20Sopenharmony_ci 3388c2ecf20Sopenharmony_ciint hr222_sub_set_clock(struct pcxhr_mgr *mgr, 3398c2ecf20Sopenharmony_ci unsigned int rate, 3408c2ecf20Sopenharmony_ci int *changed) 3418c2ecf20Sopenharmony_ci{ 3428c2ecf20Sopenharmony_ci unsigned int speed, pllreg = 0; 3438c2ecf20Sopenharmony_ci int err; 3448c2ecf20Sopenharmony_ci unsigned realfreq = rate; 3458c2ecf20Sopenharmony_ci 3468c2ecf20Sopenharmony_ci switch (mgr->use_clock_type) { 3478c2ecf20Sopenharmony_ci case HR22_CLOCK_TYPE_INTERNAL: 3488c2ecf20Sopenharmony_ci err = hr222_pll_freq_register(rate, &pllreg, &realfreq); 3498c2ecf20Sopenharmony_ci if (err) 3508c2ecf20Sopenharmony_ci return err; 3518c2ecf20Sopenharmony_ci 3528c2ecf20Sopenharmony_ci mgr->xlx_cfg &= ~(PCXHR_CFG_CLOCKIN_SEL_MASK | 3538c2ecf20Sopenharmony_ci PCXHR_CFG_CLOCK_UER1_SEL_MASK); 3548c2ecf20Sopenharmony_ci break; 3558c2ecf20Sopenharmony_ci case HR22_CLOCK_TYPE_AES_SYNC: 3568c2ecf20Sopenharmony_ci mgr->xlx_cfg |= PCXHR_CFG_CLOCKIN_SEL_MASK; 3578c2ecf20Sopenharmony_ci mgr->xlx_cfg &= ~PCXHR_CFG_CLOCK_UER1_SEL_MASK; 3588c2ecf20Sopenharmony_ci break; 3598c2ecf20Sopenharmony_ci case HR22_CLOCK_TYPE_AES_1: 3608c2ecf20Sopenharmony_ci if (!mgr->board_has_aes1) 3618c2ecf20Sopenharmony_ci return -EINVAL; 3628c2ecf20Sopenharmony_ci 3638c2ecf20Sopenharmony_ci mgr->xlx_cfg |= (PCXHR_CFG_CLOCKIN_SEL_MASK | 3648c2ecf20Sopenharmony_ci PCXHR_CFG_CLOCK_UER1_SEL_MASK); 3658c2ecf20Sopenharmony_ci break; 3668c2ecf20Sopenharmony_ci default: 3678c2ecf20Sopenharmony_ci return -EINVAL; 3688c2ecf20Sopenharmony_ci } 3698c2ecf20Sopenharmony_ci hr222_config_akm(mgr, AKM_MUTE_CMD); 3708c2ecf20Sopenharmony_ci 3718c2ecf20Sopenharmony_ci if (mgr->use_clock_type == HR22_CLOCK_TYPE_INTERNAL) { 3728c2ecf20Sopenharmony_ci PCXHR_OUTPB(mgr, PCXHR_XLX_HIFREQ, pllreg >> 8); 3738c2ecf20Sopenharmony_ci PCXHR_OUTPB(mgr, PCXHR_XLX_LOFREQ, pllreg & 0xff); 3748c2ecf20Sopenharmony_ci } 3758c2ecf20Sopenharmony_ci 3768c2ecf20Sopenharmony_ci /* set clock source */ 3778c2ecf20Sopenharmony_ci PCXHR_OUTPB(mgr, PCXHR_XLX_CFG, mgr->xlx_cfg); 3788c2ecf20Sopenharmony_ci 3798c2ecf20Sopenharmony_ci /* codec speed modes */ 3808c2ecf20Sopenharmony_ci speed = rate < 55000 ? 0 : 1; 3818c2ecf20Sopenharmony_ci if (mgr->codec_speed != speed) { 3828c2ecf20Sopenharmony_ci mgr->codec_speed = speed; 3838c2ecf20Sopenharmony_ci if (speed == 0) 3848c2ecf20Sopenharmony_ci hr222_config_akm(mgr, AKM_CLOCK_INF_55K_CMD); 3858c2ecf20Sopenharmony_ci else 3868c2ecf20Sopenharmony_ci hr222_config_akm(mgr, AKM_CLOCK_SUP_55K_CMD); 3878c2ecf20Sopenharmony_ci } 3888c2ecf20Sopenharmony_ci 3898c2ecf20Sopenharmony_ci mgr->sample_rate_real = realfreq; 3908c2ecf20Sopenharmony_ci mgr->cur_clock_type = mgr->use_clock_type; 3918c2ecf20Sopenharmony_ci 3928c2ecf20Sopenharmony_ci if (changed) 3938c2ecf20Sopenharmony_ci *changed = 1; 3948c2ecf20Sopenharmony_ci 3958c2ecf20Sopenharmony_ci hr222_config_akm(mgr, AKM_UNMUTE_CMD); 3968c2ecf20Sopenharmony_ci 3978c2ecf20Sopenharmony_ci dev_dbg(&mgr->pci->dev, "set_clock to %dHz (realfreq=%d pllreg=%x)\n", 3988c2ecf20Sopenharmony_ci rate, realfreq, pllreg); 3998c2ecf20Sopenharmony_ci return 0; 4008c2ecf20Sopenharmony_ci} 4018c2ecf20Sopenharmony_ci 4028c2ecf20Sopenharmony_ciint hr222_get_external_clock(struct pcxhr_mgr *mgr, 4038c2ecf20Sopenharmony_ci enum pcxhr_clock_type clock_type, 4048c2ecf20Sopenharmony_ci int *sample_rate) 4058c2ecf20Sopenharmony_ci{ 4068c2ecf20Sopenharmony_ci int rate, calc_rate = 0; 4078c2ecf20Sopenharmony_ci unsigned int ticks; 4088c2ecf20Sopenharmony_ci unsigned char mask, reg; 4098c2ecf20Sopenharmony_ci 4108c2ecf20Sopenharmony_ci if (clock_type == HR22_CLOCK_TYPE_AES_SYNC) { 4118c2ecf20Sopenharmony_ci 4128c2ecf20Sopenharmony_ci mask = (PCXHR_SUER_CLOCK_PRESENT_MASK | 4138c2ecf20Sopenharmony_ci PCXHR_SUER_DATA_PRESENT_MASK); 4148c2ecf20Sopenharmony_ci reg = PCXHR_STAT_FREQ_SYNC_MASK; 4158c2ecf20Sopenharmony_ci 4168c2ecf20Sopenharmony_ci } else if (clock_type == HR22_CLOCK_TYPE_AES_1 && mgr->board_has_aes1) { 4178c2ecf20Sopenharmony_ci 4188c2ecf20Sopenharmony_ci mask = (PCXHR_SUER1_CLOCK_PRESENT_MASK | 4198c2ecf20Sopenharmony_ci PCXHR_SUER1_DATA_PRESENT_MASK); 4208c2ecf20Sopenharmony_ci reg = PCXHR_STAT_FREQ_UER1_MASK; 4218c2ecf20Sopenharmony_ci 4228c2ecf20Sopenharmony_ci } else { 4238c2ecf20Sopenharmony_ci dev_dbg(&mgr->pci->dev, 4248c2ecf20Sopenharmony_ci "get_external_clock : type %d not supported\n", 4258c2ecf20Sopenharmony_ci clock_type); 4268c2ecf20Sopenharmony_ci return -EINVAL; /* other clocks not supported */ 4278c2ecf20Sopenharmony_ci } 4288c2ecf20Sopenharmony_ci 4298c2ecf20Sopenharmony_ci if ((PCXHR_INPB(mgr, PCXHR_XLX_CSUER) & mask) != mask) { 4308c2ecf20Sopenharmony_ci dev_dbg(&mgr->pci->dev, 4318c2ecf20Sopenharmony_ci "get_external_clock(%d) = 0 Hz\n", clock_type); 4328c2ecf20Sopenharmony_ci *sample_rate = 0; 4338c2ecf20Sopenharmony_ci return 0; /* no external clock locked */ 4348c2ecf20Sopenharmony_ci } 4358c2ecf20Sopenharmony_ci 4368c2ecf20Sopenharmony_ci PCXHR_OUTPB(mgr, PCXHR_XLX_STATUS, reg); /* calculate freq */ 4378c2ecf20Sopenharmony_ci 4388c2ecf20Sopenharmony_ci /* save the measured clock frequency */ 4398c2ecf20Sopenharmony_ci reg |= PCXHR_STAT_FREQ_SAVE_MASK; 4408c2ecf20Sopenharmony_ci 4418c2ecf20Sopenharmony_ci if (mgr->last_reg_stat != reg) { 4428c2ecf20Sopenharmony_ci udelay(500); /* wait min 2 cycles of lowest freq (8000) */ 4438c2ecf20Sopenharmony_ci mgr->last_reg_stat = reg; 4448c2ecf20Sopenharmony_ci } 4458c2ecf20Sopenharmony_ci 4468c2ecf20Sopenharmony_ci PCXHR_OUTPB(mgr, PCXHR_XLX_STATUS, reg); /* save */ 4478c2ecf20Sopenharmony_ci 4488c2ecf20Sopenharmony_ci /* get the frequency */ 4498c2ecf20Sopenharmony_ci ticks = (unsigned int)PCXHR_INPB(mgr, PCXHR_XLX_CFG); 4508c2ecf20Sopenharmony_ci ticks = (ticks & 0x03) << 8; 4518c2ecf20Sopenharmony_ci ticks |= (unsigned int)PCXHR_INPB(mgr, PCXHR_DSP_RESET); 4528c2ecf20Sopenharmony_ci 4538c2ecf20Sopenharmony_ci if (ticks != 0) 4548c2ecf20Sopenharmony_ci calc_rate = 28224000 / ticks; 4558c2ecf20Sopenharmony_ci /* rounding */ 4568c2ecf20Sopenharmony_ci if (calc_rate > 184200) 4578c2ecf20Sopenharmony_ci rate = 192000; 4588c2ecf20Sopenharmony_ci else if (calc_rate > 152200) 4598c2ecf20Sopenharmony_ci rate = 176400; 4608c2ecf20Sopenharmony_ci else if (calc_rate > 112000) 4618c2ecf20Sopenharmony_ci rate = 128000; 4628c2ecf20Sopenharmony_ci else if (calc_rate > 92100) 4638c2ecf20Sopenharmony_ci rate = 96000; 4648c2ecf20Sopenharmony_ci else if (calc_rate > 76100) 4658c2ecf20Sopenharmony_ci rate = 88200; 4668c2ecf20Sopenharmony_ci else if (calc_rate > 56000) 4678c2ecf20Sopenharmony_ci rate = 64000; 4688c2ecf20Sopenharmony_ci else if (calc_rate > 46050) 4698c2ecf20Sopenharmony_ci rate = 48000; 4708c2ecf20Sopenharmony_ci else if (calc_rate > 38050) 4718c2ecf20Sopenharmony_ci rate = 44100; 4728c2ecf20Sopenharmony_ci else if (calc_rate > 28000) 4738c2ecf20Sopenharmony_ci rate = 32000; 4748c2ecf20Sopenharmony_ci else if (calc_rate > 23025) 4758c2ecf20Sopenharmony_ci rate = 24000; 4768c2ecf20Sopenharmony_ci else if (calc_rate > 19025) 4778c2ecf20Sopenharmony_ci rate = 22050; 4788c2ecf20Sopenharmony_ci else if (calc_rate > 14000) 4798c2ecf20Sopenharmony_ci rate = 16000; 4808c2ecf20Sopenharmony_ci else if (calc_rate > 11512) 4818c2ecf20Sopenharmony_ci rate = 12000; 4828c2ecf20Sopenharmony_ci else if (calc_rate > 9512) 4838c2ecf20Sopenharmony_ci rate = 11025; 4848c2ecf20Sopenharmony_ci else if (calc_rate > 7000) 4858c2ecf20Sopenharmony_ci rate = 8000; 4868c2ecf20Sopenharmony_ci else 4878c2ecf20Sopenharmony_ci rate = 0; 4888c2ecf20Sopenharmony_ci 4898c2ecf20Sopenharmony_ci dev_dbg(&mgr->pci->dev, "External clock is at %d Hz (measured %d Hz)\n", 4908c2ecf20Sopenharmony_ci rate, calc_rate); 4918c2ecf20Sopenharmony_ci *sample_rate = rate; 4928c2ecf20Sopenharmony_ci return 0; 4938c2ecf20Sopenharmony_ci} 4948c2ecf20Sopenharmony_ci 4958c2ecf20Sopenharmony_ci 4968c2ecf20Sopenharmony_ciint hr222_read_gpio(struct pcxhr_mgr *mgr, int is_gpi, int *value) 4978c2ecf20Sopenharmony_ci{ 4988c2ecf20Sopenharmony_ci if (is_gpi) { 4998c2ecf20Sopenharmony_ci unsigned char reg = PCXHR_INPB(mgr, PCXHR_XLX_STATUS); 5008c2ecf20Sopenharmony_ci *value = (int)(reg & PCXHR_STAT_GPI_MASK) >> 5018c2ecf20Sopenharmony_ci PCXHR_STAT_GPI_OFFSET; 5028c2ecf20Sopenharmony_ci } else { 5038c2ecf20Sopenharmony_ci *value = (int)(mgr->dsp_reset & PCXHR_DSP_RESET_GPO_MASK) >> 5048c2ecf20Sopenharmony_ci PCXHR_DSP_RESET_GPO_OFFSET; 5058c2ecf20Sopenharmony_ci } 5068c2ecf20Sopenharmony_ci return 0; 5078c2ecf20Sopenharmony_ci} 5088c2ecf20Sopenharmony_ci 5098c2ecf20Sopenharmony_ci 5108c2ecf20Sopenharmony_ciint hr222_write_gpo(struct pcxhr_mgr *mgr, int value) 5118c2ecf20Sopenharmony_ci{ 5128c2ecf20Sopenharmony_ci unsigned char reg = mgr->dsp_reset & ~PCXHR_DSP_RESET_GPO_MASK; 5138c2ecf20Sopenharmony_ci 5148c2ecf20Sopenharmony_ci reg |= (unsigned char)(value << PCXHR_DSP_RESET_GPO_OFFSET) & 5158c2ecf20Sopenharmony_ci PCXHR_DSP_RESET_GPO_MASK; 5168c2ecf20Sopenharmony_ci 5178c2ecf20Sopenharmony_ci PCXHR_OUTPB(mgr, PCXHR_DSP_RESET, reg); 5188c2ecf20Sopenharmony_ci mgr->dsp_reset = reg; 5198c2ecf20Sopenharmony_ci return 0; 5208c2ecf20Sopenharmony_ci} 5218c2ecf20Sopenharmony_ci 5228c2ecf20Sopenharmony_ciint hr222_manage_timecode(struct pcxhr_mgr *mgr, int enable) 5238c2ecf20Sopenharmony_ci{ 5248c2ecf20Sopenharmony_ci if (enable) 5258c2ecf20Sopenharmony_ci mgr->dsp_reset |= PCXHR_DSP_RESET_SMPTE; 5268c2ecf20Sopenharmony_ci else 5278c2ecf20Sopenharmony_ci mgr->dsp_reset &= ~PCXHR_DSP_RESET_SMPTE; 5288c2ecf20Sopenharmony_ci 5298c2ecf20Sopenharmony_ci PCXHR_OUTPB(mgr, PCXHR_DSP_RESET, mgr->dsp_reset); 5308c2ecf20Sopenharmony_ci return 0; 5318c2ecf20Sopenharmony_ci} 5328c2ecf20Sopenharmony_ci 5338c2ecf20Sopenharmony_ciint hr222_update_analog_audio_level(struct snd_pcxhr *chip, 5348c2ecf20Sopenharmony_ci int is_capture, int channel) 5358c2ecf20Sopenharmony_ci{ 5368c2ecf20Sopenharmony_ci dev_dbg(chip->card->dev, 5378c2ecf20Sopenharmony_ci "hr222_update_analog_audio_level(%s chan=%d)\n", 5388c2ecf20Sopenharmony_ci is_capture ? "capture" : "playback", channel); 5398c2ecf20Sopenharmony_ci if (is_capture) { 5408c2ecf20Sopenharmony_ci int level_l, level_r, level_mic; 5418c2ecf20Sopenharmony_ci /* we have to update all levels */ 5428c2ecf20Sopenharmony_ci if (chip->analog_capture_active) { 5438c2ecf20Sopenharmony_ci level_l = chip->analog_capture_volume[0]; 5448c2ecf20Sopenharmony_ci level_r = chip->analog_capture_volume[1]; 5458c2ecf20Sopenharmony_ci } else { 5468c2ecf20Sopenharmony_ci level_l = HR222_LINE_CAPTURE_LEVEL_MIN; 5478c2ecf20Sopenharmony_ci level_r = HR222_LINE_CAPTURE_LEVEL_MIN; 5488c2ecf20Sopenharmony_ci } 5498c2ecf20Sopenharmony_ci if (chip->mic_active) 5508c2ecf20Sopenharmony_ci level_mic = chip->mic_volume; 5518c2ecf20Sopenharmony_ci else 5528c2ecf20Sopenharmony_ci level_mic = HR222_MICRO_CAPTURE_LEVEL_MIN; 5538c2ecf20Sopenharmony_ci return hr222_set_hw_capture_level(chip->mgr, 5548c2ecf20Sopenharmony_ci level_l, level_r, level_mic); 5558c2ecf20Sopenharmony_ci } else { 5568c2ecf20Sopenharmony_ci int vol; 5578c2ecf20Sopenharmony_ci if (chip->analog_playback_active[channel]) 5588c2ecf20Sopenharmony_ci vol = chip->analog_playback_volume[channel]; 5598c2ecf20Sopenharmony_ci else 5608c2ecf20Sopenharmony_ci vol = HR222_LINE_PLAYBACK_LEVEL_MIN; 5618c2ecf20Sopenharmony_ci return hr222_set_hw_playback_level(chip->mgr, channel, vol); 5628c2ecf20Sopenharmony_ci } 5638c2ecf20Sopenharmony_ci} 5648c2ecf20Sopenharmony_ci 5658c2ecf20Sopenharmony_ci 5668c2ecf20Sopenharmony_ci/*texts[5] = {"Line", "Digital", "Digi+SRC", "Mic", "Line+Mic"}*/ 5678c2ecf20Sopenharmony_ci#define SOURCE_LINE 0 5688c2ecf20Sopenharmony_ci#define SOURCE_DIGITAL 1 5698c2ecf20Sopenharmony_ci#define SOURCE_DIGISRC 2 5708c2ecf20Sopenharmony_ci#define SOURCE_MIC 3 5718c2ecf20Sopenharmony_ci#define SOURCE_LINEMIC 4 5728c2ecf20Sopenharmony_ci 5738c2ecf20Sopenharmony_ciint hr222_set_audio_source(struct snd_pcxhr *chip) 5748c2ecf20Sopenharmony_ci{ 5758c2ecf20Sopenharmony_ci int digital = 0; 5768c2ecf20Sopenharmony_ci /* default analog source */ 5778c2ecf20Sopenharmony_ci chip->mgr->xlx_cfg &= ~(PCXHR_CFG_SRC_MASK | 5788c2ecf20Sopenharmony_ci PCXHR_CFG_DATAIN_SEL_MASK | 5798c2ecf20Sopenharmony_ci PCXHR_CFG_DATA_UER1_SEL_MASK); 5808c2ecf20Sopenharmony_ci 5818c2ecf20Sopenharmony_ci if (chip->audio_capture_source == SOURCE_DIGISRC) { 5828c2ecf20Sopenharmony_ci chip->mgr->xlx_cfg |= PCXHR_CFG_SRC_MASK; 5838c2ecf20Sopenharmony_ci digital = 1; 5848c2ecf20Sopenharmony_ci } else { 5858c2ecf20Sopenharmony_ci if (chip->audio_capture_source == SOURCE_DIGITAL) 5868c2ecf20Sopenharmony_ci digital = 1; 5878c2ecf20Sopenharmony_ci } 5888c2ecf20Sopenharmony_ci if (digital) { 5898c2ecf20Sopenharmony_ci chip->mgr->xlx_cfg |= PCXHR_CFG_DATAIN_SEL_MASK; 5908c2ecf20Sopenharmony_ci if (chip->mgr->board_has_aes1) { 5918c2ecf20Sopenharmony_ci /* get data from the AES1 plug */ 5928c2ecf20Sopenharmony_ci chip->mgr->xlx_cfg |= PCXHR_CFG_DATA_UER1_SEL_MASK; 5938c2ecf20Sopenharmony_ci } 5948c2ecf20Sopenharmony_ci /* chip->mic_active = 0; */ 5958c2ecf20Sopenharmony_ci /* chip->analog_capture_active = 0; */ 5968c2ecf20Sopenharmony_ci } else { 5978c2ecf20Sopenharmony_ci int update_lvl = 0; 5988c2ecf20Sopenharmony_ci chip->analog_capture_active = 0; 5998c2ecf20Sopenharmony_ci chip->mic_active = 0; 6008c2ecf20Sopenharmony_ci if (chip->audio_capture_source == SOURCE_LINE || 6018c2ecf20Sopenharmony_ci chip->audio_capture_source == SOURCE_LINEMIC) { 6028c2ecf20Sopenharmony_ci if (chip->analog_capture_active == 0) 6038c2ecf20Sopenharmony_ci update_lvl = 1; 6048c2ecf20Sopenharmony_ci chip->analog_capture_active = 1; 6058c2ecf20Sopenharmony_ci } 6068c2ecf20Sopenharmony_ci if (chip->audio_capture_source == SOURCE_MIC || 6078c2ecf20Sopenharmony_ci chip->audio_capture_source == SOURCE_LINEMIC) { 6088c2ecf20Sopenharmony_ci if (chip->mic_active == 0) 6098c2ecf20Sopenharmony_ci update_lvl = 1; 6108c2ecf20Sopenharmony_ci chip->mic_active = 1; 6118c2ecf20Sopenharmony_ci } 6128c2ecf20Sopenharmony_ci if (update_lvl) { 6138c2ecf20Sopenharmony_ci /* capture: update all 3 mutes/unmutes with one call */ 6148c2ecf20Sopenharmony_ci hr222_update_analog_audio_level(chip, 1, 0); 6158c2ecf20Sopenharmony_ci } 6168c2ecf20Sopenharmony_ci } 6178c2ecf20Sopenharmony_ci /* set the source infos (max 3 bits modified) */ 6188c2ecf20Sopenharmony_ci PCXHR_OUTPB(chip->mgr, PCXHR_XLX_CFG, chip->mgr->xlx_cfg); 6198c2ecf20Sopenharmony_ci return 0; 6208c2ecf20Sopenharmony_ci} 6218c2ecf20Sopenharmony_ci 6228c2ecf20Sopenharmony_ci 6238c2ecf20Sopenharmony_ciint hr222_iec958_capture_byte(struct snd_pcxhr *chip, 6248c2ecf20Sopenharmony_ci int aes_idx, unsigned char *aes_bits) 6258c2ecf20Sopenharmony_ci{ 6268c2ecf20Sopenharmony_ci unsigned char idx = (unsigned char)(aes_idx * 8); 6278c2ecf20Sopenharmony_ci unsigned char temp = 0; 6288c2ecf20Sopenharmony_ci unsigned char mask = chip->mgr->board_has_aes1 ? 6298c2ecf20Sopenharmony_ci PCXHR_SUER1_BIT_C_READ_MASK : PCXHR_SUER_BIT_C_READ_MASK; 6308c2ecf20Sopenharmony_ci int i; 6318c2ecf20Sopenharmony_ci for (i = 0; i < 8; i++) { 6328c2ecf20Sopenharmony_ci PCXHR_OUTPB(chip->mgr, PCXHR_XLX_RUER, idx++); /* idx < 192 */ 6338c2ecf20Sopenharmony_ci temp <<= 1; 6348c2ecf20Sopenharmony_ci if (PCXHR_INPB(chip->mgr, PCXHR_XLX_CSUER) & mask) 6358c2ecf20Sopenharmony_ci temp |= 1; 6368c2ecf20Sopenharmony_ci } 6378c2ecf20Sopenharmony_ci dev_dbg(chip->card->dev, "read iec958 AES %d byte %d = 0x%x\n", 6388c2ecf20Sopenharmony_ci chip->chip_idx, aes_idx, temp); 6398c2ecf20Sopenharmony_ci *aes_bits = temp; 6408c2ecf20Sopenharmony_ci return 0; 6418c2ecf20Sopenharmony_ci} 6428c2ecf20Sopenharmony_ci 6438c2ecf20Sopenharmony_ci 6448c2ecf20Sopenharmony_ciint hr222_iec958_update_byte(struct snd_pcxhr *chip, 6458c2ecf20Sopenharmony_ci int aes_idx, unsigned char aes_bits) 6468c2ecf20Sopenharmony_ci{ 6478c2ecf20Sopenharmony_ci int i; 6488c2ecf20Sopenharmony_ci unsigned char new_bits = aes_bits; 6498c2ecf20Sopenharmony_ci unsigned char old_bits = chip->aes_bits[aes_idx]; 6508c2ecf20Sopenharmony_ci unsigned char idx = (unsigned char)(aes_idx * 8); 6518c2ecf20Sopenharmony_ci for (i = 0; i < 8; i++) { 6528c2ecf20Sopenharmony_ci if ((old_bits & 0x01) != (new_bits & 0x01)) { 6538c2ecf20Sopenharmony_ci /* idx < 192 */ 6548c2ecf20Sopenharmony_ci PCXHR_OUTPB(chip->mgr, PCXHR_XLX_RUER, idx); 6558c2ecf20Sopenharmony_ci /* write C and U bit */ 6568c2ecf20Sopenharmony_ci PCXHR_OUTPB(chip->mgr, PCXHR_XLX_CSUER, new_bits&0x01 ? 6578c2ecf20Sopenharmony_ci PCXHR_SUER_BIT_C_WRITE_MASK : 0); 6588c2ecf20Sopenharmony_ci } 6598c2ecf20Sopenharmony_ci idx++; 6608c2ecf20Sopenharmony_ci old_bits >>= 1; 6618c2ecf20Sopenharmony_ci new_bits >>= 1; 6628c2ecf20Sopenharmony_ci } 6638c2ecf20Sopenharmony_ci chip->aes_bits[aes_idx] = aes_bits; 6648c2ecf20Sopenharmony_ci return 0; 6658c2ecf20Sopenharmony_ci} 6668c2ecf20Sopenharmony_ci 6678c2ecf20Sopenharmony_cistatic void hr222_micro_boost(struct pcxhr_mgr *mgr, int level) 6688c2ecf20Sopenharmony_ci{ 6698c2ecf20Sopenharmony_ci unsigned char boost_mask; 6708c2ecf20Sopenharmony_ci boost_mask = (unsigned char) (level << PCXHR_SELMIC_PREAMPLI_OFFSET); 6718c2ecf20Sopenharmony_ci if (boost_mask & (~PCXHR_SELMIC_PREAMPLI_MASK)) 6728c2ecf20Sopenharmony_ci return; /* only values form 0 to 3 accepted */ 6738c2ecf20Sopenharmony_ci 6748c2ecf20Sopenharmony_ci mgr->xlx_selmic &= ~PCXHR_SELMIC_PREAMPLI_MASK; 6758c2ecf20Sopenharmony_ci mgr->xlx_selmic |= boost_mask; 6768c2ecf20Sopenharmony_ci 6778c2ecf20Sopenharmony_ci PCXHR_OUTPB(mgr, PCXHR_XLX_SELMIC, mgr->xlx_selmic); 6788c2ecf20Sopenharmony_ci 6798c2ecf20Sopenharmony_ci dev_dbg(&mgr->pci->dev, "hr222_micro_boost : set %x\n", boost_mask); 6808c2ecf20Sopenharmony_ci} 6818c2ecf20Sopenharmony_ci 6828c2ecf20Sopenharmony_cistatic void hr222_phantom_power(struct pcxhr_mgr *mgr, int power) 6838c2ecf20Sopenharmony_ci{ 6848c2ecf20Sopenharmony_ci if (power) 6858c2ecf20Sopenharmony_ci mgr->xlx_selmic |= PCXHR_SELMIC_PHANTOM_ALIM; 6868c2ecf20Sopenharmony_ci else 6878c2ecf20Sopenharmony_ci mgr->xlx_selmic &= ~PCXHR_SELMIC_PHANTOM_ALIM; 6888c2ecf20Sopenharmony_ci 6898c2ecf20Sopenharmony_ci PCXHR_OUTPB(mgr, PCXHR_XLX_SELMIC, mgr->xlx_selmic); 6908c2ecf20Sopenharmony_ci 6918c2ecf20Sopenharmony_ci dev_dbg(&mgr->pci->dev, "hr222_phantom_power : set %d\n", power); 6928c2ecf20Sopenharmony_ci} 6938c2ecf20Sopenharmony_ci 6948c2ecf20Sopenharmony_ci 6958c2ecf20Sopenharmony_ci/* mic level */ 6968c2ecf20Sopenharmony_cistatic const DECLARE_TLV_DB_SCALE(db_scale_mic_hr222, -9850, 50, 650); 6978c2ecf20Sopenharmony_ci 6988c2ecf20Sopenharmony_cistatic int hr222_mic_vol_info(struct snd_kcontrol *kcontrol, 6998c2ecf20Sopenharmony_ci struct snd_ctl_elem_info *uinfo) 7008c2ecf20Sopenharmony_ci{ 7018c2ecf20Sopenharmony_ci uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 7028c2ecf20Sopenharmony_ci uinfo->count = 1; 7038c2ecf20Sopenharmony_ci uinfo->value.integer.min = HR222_MICRO_CAPTURE_LEVEL_MIN; /* -98 dB */ 7048c2ecf20Sopenharmony_ci /* gains from 9 dB to 31.5 dB not recommended; use micboost instead */ 7058c2ecf20Sopenharmony_ci uinfo->value.integer.max = HR222_MICRO_CAPTURE_LEVEL_MAX; /* +7 dB */ 7068c2ecf20Sopenharmony_ci return 0; 7078c2ecf20Sopenharmony_ci} 7088c2ecf20Sopenharmony_ci 7098c2ecf20Sopenharmony_cistatic int hr222_mic_vol_get(struct snd_kcontrol *kcontrol, 7108c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 7118c2ecf20Sopenharmony_ci{ 7128c2ecf20Sopenharmony_ci struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol); 7138c2ecf20Sopenharmony_ci mutex_lock(&chip->mgr->mixer_mutex); 7148c2ecf20Sopenharmony_ci ucontrol->value.integer.value[0] = chip->mic_volume; 7158c2ecf20Sopenharmony_ci mutex_unlock(&chip->mgr->mixer_mutex); 7168c2ecf20Sopenharmony_ci return 0; 7178c2ecf20Sopenharmony_ci} 7188c2ecf20Sopenharmony_ci 7198c2ecf20Sopenharmony_cistatic int hr222_mic_vol_put(struct snd_kcontrol *kcontrol, 7208c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 7218c2ecf20Sopenharmony_ci{ 7228c2ecf20Sopenharmony_ci struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol); 7238c2ecf20Sopenharmony_ci int changed = 0; 7248c2ecf20Sopenharmony_ci mutex_lock(&chip->mgr->mixer_mutex); 7258c2ecf20Sopenharmony_ci if (chip->mic_volume != ucontrol->value.integer.value[0]) { 7268c2ecf20Sopenharmony_ci changed = 1; 7278c2ecf20Sopenharmony_ci chip->mic_volume = ucontrol->value.integer.value[0]; 7288c2ecf20Sopenharmony_ci hr222_update_analog_audio_level(chip, 1, 0); 7298c2ecf20Sopenharmony_ci } 7308c2ecf20Sopenharmony_ci mutex_unlock(&chip->mgr->mixer_mutex); 7318c2ecf20Sopenharmony_ci return changed; 7328c2ecf20Sopenharmony_ci} 7338c2ecf20Sopenharmony_ci 7348c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new hr222_control_mic_level = { 7358c2ecf20Sopenharmony_ci .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 7368c2ecf20Sopenharmony_ci .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | 7378c2ecf20Sopenharmony_ci SNDRV_CTL_ELEM_ACCESS_TLV_READ), 7388c2ecf20Sopenharmony_ci .name = "Mic Capture Volume", 7398c2ecf20Sopenharmony_ci .info = hr222_mic_vol_info, 7408c2ecf20Sopenharmony_ci .get = hr222_mic_vol_get, 7418c2ecf20Sopenharmony_ci .put = hr222_mic_vol_put, 7428c2ecf20Sopenharmony_ci .tlv = { .p = db_scale_mic_hr222 }, 7438c2ecf20Sopenharmony_ci}; 7448c2ecf20Sopenharmony_ci 7458c2ecf20Sopenharmony_ci 7468c2ecf20Sopenharmony_ci/* mic boost level */ 7478c2ecf20Sopenharmony_cistatic const DECLARE_TLV_DB_SCALE(db_scale_micboost_hr222, 0, 1800, 5400); 7488c2ecf20Sopenharmony_ci 7498c2ecf20Sopenharmony_cistatic int hr222_mic_boost_info(struct snd_kcontrol *kcontrol, 7508c2ecf20Sopenharmony_ci struct snd_ctl_elem_info *uinfo) 7518c2ecf20Sopenharmony_ci{ 7528c2ecf20Sopenharmony_ci uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 7538c2ecf20Sopenharmony_ci uinfo->count = 1; 7548c2ecf20Sopenharmony_ci uinfo->value.integer.min = 0; /* 0 dB */ 7558c2ecf20Sopenharmony_ci uinfo->value.integer.max = 3; /* 54 dB */ 7568c2ecf20Sopenharmony_ci return 0; 7578c2ecf20Sopenharmony_ci} 7588c2ecf20Sopenharmony_ci 7598c2ecf20Sopenharmony_cistatic int hr222_mic_boost_get(struct snd_kcontrol *kcontrol, 7608c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 7618c2ecf20Sopenharmony_ci{ 7628c2ecf20Sopenharmony_ci struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol); 7638c2ecf20Sopenharmony_ci mutex_lock(&chip->mgr->mixer_mutex); 7648c2ecf20Sopenharmony_ci ucontrol->value.integer.value[0] = chip->mic_boost; 7658c2ecf20Sopenharmony_ci mutex_unlock(&chip->mgr->mixer_mutex); 7668c2ecf20Sopenharmony_ci return 0; 7678c2ecf20Sopenharmony_ci} 7688c2ecf20Sopenharmony_ci 7698c2ecf20Sopenharmony_cistatic int hr222_mic_boost_put(struct snd_kcontrol *kcontrol, 7708c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 7718c2ecf20Sopenharmony_ci{ 7728c2ecf20Sopenharmony_ci struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol); 7738c2ecf20Sopenharmony_ci int changed = 0; 7748c2ecf20Sopenharmony_ci mutex_lock(&chip->mgr->mixer_mutex); 7758c2ecf20Sopenharmony_ci if (chip->mic_boost != ucontrol->value.integer.value[0]) { 7768c2ecf20Sopenharmony_ci changed = 1; 7778c2ecf20Sopenharmony_ci chip->mic_boost = ucontrol->value.integer.value[0]; 7788c2ecf20Sopenharmony_ci hr222_micro_boost(chip->mgr, chip->mic_boost); 7798c2ecf20Sopenharmony_ci } 7808c2ecf20Sopenharmony_ci mutex_unlock(&chip->mgr->mixer_mutex); 7818c2ecf20Sopenharmony_ci return changed; 7828c2ecf20Sopenharmony_ci} 7838c2ecf20Sopenharmony_ci 7848c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new hr222_control_mic_boost = { 7858c2ecf20Sopenharmony_ci .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 7868c2ecf20Sopenharmony_ci .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | 7878c2ecf20Sopenharmony_ci SNDRV_CTL_ELEM_ACCESS_TLV_READ), 7888c2ecf20Sopenharmony_ci .name = "MicBoost Capture Volume", 7898c2ecf20Sopenharmony_ci .info = hr222_mic_boost_info, 7908c2ecf20Sopenharmony_ci .get = hr222_mic_boost_get, 7918c2ecf20Sopenharmony_ci .put = hr222_mic_boost_put, 7928c2ecf20Sopenharmony_ci .tlv = { .p = db_scale_micboost_hr222 }, 7938c2ecf20Sopenharmony_ci}; 7948c2ecf20Sopenharmony_ci 7958c2ecf20Sopenharmony_ci 7968c2ecf20Sopenharmony_ci/******************* Phantom power switch *******************/ 7978c2ecf20Sopenharmony_ci#define hr222_phantom_power_info snd_ctl_boolean_mono_info 7988c2ecf20Sopenharmony_ci 7998c2ecf20Sopenharmony_cistatic int hr222_phantom_power_get(struct snd_kcontrol *kcontrol, 8008c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 8018c2ecf20Sopenharmony_ci{ 8028c2ecf20Sopenharmony_ci struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol); 8038c2ecf20Sopenharmony_ci mutex_lock(&chip->mgr->mixer_mutex); 8048c2ecf20Sopenharmony_ci ucontrol->value.integer.value[0] = chip->phantom_power; 8058c2ecf20Sopenharmony_ci mutex_unlock(&chip->mgr->mixer_mutex); 8068c2ecf20Sopenharmony_ci return 0; 8078c2ecf20Sopenharmony_ci} 8088c2ecf20Sopenharmony_ci 8098c2ecf20Sopenharmony_cistatic int hr222_phantom_power_put(struct snd_kcontrol *kcontrol, 8108c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 8118c2ecf20Sopenharmony_ci{ 8128c2ecf20Sopenharmony_ci struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol); 8138c2ecf20Sopenharmony_ci int power, changed = 0; 8148c2ecf20Sopenharmony_ci 8158c2ecf20Sopenharmony_ci mutex_lock(&chip->mgr->mixer_mutex); 8168c2ecf20Sopenharmony_ci power = !!ucontrol->value.integer.value[0]; 8178c2ecf20Sopenharmony_ci if (chip->phantom_power != power) { 8188c2ecf20Sopenharmony_ci hr222_phantom_power(chip->mgr, power); 8198c2ecf20Sopenharmony_ci chip->phantom_power = power; 8208c2ecf20Sopenharmony_ci changed = 1; 8218c2ecf20Sopenharmony_ci } 8228c2ecf20Sopenharmony_ci mutex_unlock(&chip->mgr->mixer_mutex); 8238c2ecf20Sopenharmony_ci return changed; 8248c2ecf20Sopenharmony_ci} 8258c2ecf20Sopenharmony_ci 8268c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new hr222_phantom_power_switch = { 8278c2ecf20Sopenharmony_ci .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 8288c2ecf20Sopenharmony_ci .name = "Phantom Power Switch", 8298c2ecf20Sopenharmony_ci .info = hr222_phantom_power_info, 8308c2ecf20Sopenharmony_ci .get = hr222_phantom_power_get, 8318c2ecf20Sopenharmony_ci .put = hr222_phantom_power_put, 8328c2ecf20Sopenharmony_ci}; 8338c2ecf20Sopenharmony_ci 8348c2ecf20Sopenharmony_ci 8358c2ecf20Sopenharmony_ciint hr222_add_mic_controls(struct snd_pcxhr *chip) 8368c2ecf20Sopenharmony_ci{ 8378c2ecf20Sopenharmony_ci int err; 8388c2ecf20Sopenharmony_ci if (!chip->mgr->board_has_mic) 8398c2ecf20Sopenharmony_ci return 0; 8408c2ecf20Sopenharmony_ci 8418c2ecf20Sopenharmony_ci /* controls */ 8428c2ecf20Sopenharmony_ci err = snd_ctl_add(chip->card, snd_ctl_new1(&hr222_control_mic_level, 8438c2ecf20Sopenharmony_ci chip)); 8448c2ecf20Sopenharmony_ci if (err < 0) 8458c2ecf20Sopenharmony_ci return err; 8468c2ecf20Sopenharmony_ci 8478c2ecf20Sopenharmony_ci err = snd_ctl_add(chip->card, snd_ctl_new1(&hr222_control_mic_boost, 8488c2ecf20Sopenharmony_ci chip)); 8498c2ecf20Sopenharmony_ci if (err < 0) 8508c2ecf20Sopenharmony_ci return err; 8518c2ecf20Sopenharmony_ci 8528c2ecf20Sopenharmony_ci err = snd_ctl_add(chip->card, snd_ctl_new1(&hr222_phantom_power_switch, 8538c2ecf20Sopenharmony_ci chip)); 8548c2ecf20Sopenharmony_ci return err; 8558c2ecf20Sopenharmony_ci} 856