#ifndef __SOUND_AK4113_H1#define __SOUND_AK4113_H23/*4* Routines for Asahi Kasei AK41135* Copyright (c) by Jaroslav Kysela <[email protected]>,6* Copyright (c) by Pavel Hofman <[email protected]>,7*8*9* This program is free software; you can redistribute it and/or modify10* it under the terms of the GNU General Public License as published by11* the Free Software Foundation; either version 2 of the License, or12* (at your option) any later version.13*14* This program is distributed in the hope that it will be useful,15* but WITHOUT ANY WARRANTY; without even the implied warranty of16* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the17* GNU General Public License for more details.18*19* You should have received a copy of the GNU General Public License20* along with this program; if not, write to the Free Software21* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA22*23*/2425/* AK4113 registers */26/* power down */27#define AK4113_REG_PWRDN 0x0028/* format control */29#define AK4113_REG_FORMAT 0x0130/* input/output control */31#define AK4113_REG_IO0 0x0232/* input/output control */33#define AK4113_REG_IO1 0x0334/* interrupt0 mask */35#define AK4113_REG_INT0_MASK 0x0436/* interrupt1 mask */37#define AK4113_REG_INT1_MASK 0x0538/* DAT mask & DTS select */39#define AK4113_REG_DATDTS 0x0640/* receiver status 0 */41#define AK4113_REG_RCS0 0x0742/* receiver status 1 */43#define AK4113_REG_RCS1 0x0844/* receiver status 2 */45#define AK4113_REG_RCS2 0x0946/* RX channel status byte 0 */47#define AK4113_REG_RXCSB0 0x0a48/* RX channel status byte 1 */49#define AK4113_REG_RXCSB1 0x0b50/* RX channel status byte 2 */51#define AK4113_REG_RXCSB2 0x0c52/* RX channel status byte 3 */53#define AK4113_REG_RXCSB3 0x0d54/* RX channel status byte 4 */55#define AK4113_REG_RXCSB4 0x0e56/* burst preamble Pc byte 0 */57#define AK4113_REG_Pc0 0x0f58/* burst preamble Pc byte 1 */59#define AK4113_REG_Pc1 0x1060/* burst preamble Pd byte 0 */61#define AK4113_REG_Pd0 0x1162/* burst preamble Pd byte 1 */63#define AK4113_REG_Pd1 0x1264/* Q-subcode address + control */65#define AK4113_REG_QSUB_ADDR 0x1366/* Q-subcode track */67#define AK4113_REG_QSUB_TRACK 0x1468/* Q-subcode index */69#define AK4113_REG_QSUB_INDEX 0x1570/* Q-subcode minute */71#define AK4113_REG_QSUB_MINUTE 0x1672/* Q-subcode second */73#define AK4113_REG_QSUB_SECOND 0x1774/* Q-subcode frame */75#define AK4113_REG_QSUB_FRAME 0x1876/* Q-subcode zero */77#define AK4113_REG_QSUB_ZERO 0x1978/* Q-subcode absolute minute */79#define AK4113_REG_QSUB_ABSMIN 0x1a80/* Q-subcode absolute second */81#define AK4113_REG_QSUB_ABSSEC 0x1b82/* Q-subcode absolute frame */83#define AK4113_REG_QSUB_ABSFRM 0x1c8485/* sizes */86#define AK4113_REG_RXCSB_SIZE ((AK4113_REG_RXCSB4-AK4113_REG_RXCSB0)+1)87#define AK4113_REG_QSUB_SIZE ((AK4113_REG_QSUB_ABSFRM-AK4113_REG_QSUB_ADDR)\88+1)8990#define AK4113_WRITABLE_REGS (AK4113_REG_DATDTS + 1)9192/* AK4113_REG_PWRDN bits */93/* Channel Status Select */94#define AK4113_CS12 (1<<7)95/* Block Start & C/U Output Mode */96#define AK4113_BCU (1<<6)97/* Master Clock Operation Select */98#define AK4113_CM1 (1<<5)99/* Master Clock Operation Select */100#define AK4113_CM0 (1<<4)101/* Master Clock Frequency Select */102#define AK4113_OCKS1 (1<<3)103/* Master Clock Frequency Select */104#define AK4113_OCKS0 (1<<2)105/* 0 = power down, 1 = normal operation */106#define AK4113_PWN (1<<1)107/* 0 = reset & initialize (except thisregister), 1 = normal operation */108#define AK4113_RST (1<<0)109110/* AK4113_REQ_FORMAT bits */111/* V/TX Output select: 0 = Validity Flag Output, 1 = TX */112#define AK4113_VTX (1<<7)113/* Audio Data Control */114#define AK4113_DIF2 (1<<6)115/* Audio Data Control */116#define AK4113_DIF1 (1<<5)117/* Audio Data Control */118#define AK4113_DIF0 (1<<4)119/* Deemphasis Autodetect Enable (1 = enable) */120#define AK4113_DEAU (1<<3)121/* 32kHz-48kHz Deemphasis Control */122#define AK4113_DEM1 (1<<2)123/* 32kHz-48kHz Deemphasis Control */124#define AK4113_DEM0 (1<<1)125#define AK4113_DEM_OFF (AK4113_DEM0)126#define AK4113_DEM_44KHZ (0)127#define AK4113_DEM_48KHZ (AK4113_DEM1)128#define AK4113_DEM_32KHZ (AK4113_DEM0|AK4113_DEM1)129/* STDO: 16-bit, right justified */130#define AK4113_DIF_16R (0)131/* STDO: 18-bit, right justified */132#define AK4113_DIF_18R (AK4113_DIF0)133/* STDO: 20-bit, right justified */134#define AK4113_DIF_20R (AK4113_DIF1)135/* STDO: 24-bit, right justified */136#define AK4113_DIF_24R (AK4113_DIF1|AK4113_DIF0)137/* STDO: 24-bit, left justified */138#define AK4113_DIF_24L (AK4113_DIF2)139/* STDO: I2S */140#define AK4113_DIF_24I2S (AK4113_DIF2|AK4113_DIF0)141/* STDO: 24-bit, left justified; LRCLK, BICK = Input */142#define AK4113_DIF_I24L (AK4113_DIF2|AK4113_DIF1)143/* STDO: I2S; LRCLK, BICK = Input */144#define AK4113_DIF_I24I2S (AK4113_DIF2|AK4113_DIF1|AK4113_DIF0)145146/* AK4113_REG_IO0 */147/* XTL1=0,XTL0=0 -> 11.2896Mhz; XTL1=0,XTL0=1 -> 12.288Mhz */148#define AK4113_XTL1 (1<<6)149/* XTL1=1,XTL0=0 -> 24.576Mhz; XTL1=1,XTL0=1 -> use channel status */150#define AK4113_XTL0 (1<<5)151/* Block Start Signal Output: 0 = U-bit, 1 = C-bit (req. BCU = 1) */152#define AK4113_UCE (1<<4)153/* TX Output Enable (1 = enable) */154#define AK4113_TXE (1<<3)155/* Output Through Data Selector for TX pin */156#define AK4113_OPS2 (1<<2)157/* Output Through Data Selector for TX pin */158#define AK4113_OPS1 (1<<1)159/* Output Through Data Selector for TX pin */160#define AK4113_OPS0 (1<<0)161/* 11.2896 MHz ref. Xtal freq. */162#define AK4113_XTL_11_2896M (0)163/* 12.288 MHz ref. Xtal freq. */164#define AK4113_XTL_12_288M (AK4113_XTL0)165/* 24.576 MHz ref. Xtal freq. */166#define AK4113_XTL_24_576M (AK4113_XTL1)167168/* AK4113_REG_IO1 */169/* Interrupt 0 pin Hold */170#define AK4113_EFH1 (1<<7)171/* Interrupt 0 pin Hold */172#define AK4113_EFH0 (1<<6)173#define AK4113_EFH_512LRCLK (0)174#define AK4113_EFH_1024LRCLK (AK4113_EFH0)175#define AK4113_EFH_2048LRCLK (AK4113_EFH1)176#define AK4113_EFH_4096LRCLK (AK4113_EFH1|AK4113_EFH0)177/* PLL Lock Time: 0 = 384/fs, 1 = 1/fs */178#define AK4113_FAST (1<<5)179/* MCKO2 Output Select: 0 = CMx/OCKSx, 1 = Xtal */180#define AK4113_XMCK (1<<4)181/* MCKO2 Output Freq. Select: 0 = x1, 1 = x0.5 (req. XMCK = 1) */182#define AK4113_DIV (1<<3)183/* Input Recovery Data Select */184#define AK4113_IPS2 (1<<2)185/* Input Recovery Data Select */186#define AK4113_IPS1 (1<<1)187/* Input Recovery Data Select */188#define AK4113_IPS0 (1<<0)189#define AK4113_IPS(x) ((x)&7)190191/* AK4113_REG_INT0_MASK && AK4113_REG_INT1_MASK*/192/* mask enable for QINT bit */193#define AK4113_MQI (1<<7)194/* mask enable for AUTO bit */195#define AK4113_MAUT (1<<6)196/* mask enable for CINT bit */197#define AK4113_MCIT (1<<5)198/* mask enable for UNLOCK bit */199#define AK4113_MULK (1<<4)200/* mask enable for V bit */201#define AK4113_V (1<<3)202/* mask enable for STC bit */203#define AK4113_STC (1<<2)204/* mask enable for AUDN bit */205#define AK4113_MAN (1<<1)206/* mask enable for PAR bit */207#define AK4113_MPR (1<<0)208209/* AK4113_REG_DATDTS */210/* DAT Start ID Counter */211#define AK4113_DCNT (1<<4)212/* DTS-CD 16-bit Sync Word Detect */213#define AK4113_DTS16 (1<<3)214/* DTS-CD 14-bit Sync Word Detect */215#define AK4113_DTS14 (1<<2)216/* mask enable for DAT bit (if 1, no INT1 effect */217#define AK4113_MDAT1 (1<<1)218/* mask enable for DAT bit (if 1, no INT0 effect */219#define AK4113_MDAT0 (1<<0)220221/* AK4113_REG_RCS0 */222/* Q-subcode buffer interrupt, 0 = no change, 1 = changed */223#define AK4113_QINT (1<<7)224/* Non-PCM or DTS stream auto detection, 0 = no detect, 1 = detect */225#define AK4113_AUTO (1<<6)226/* channel status buffer interrupt, 0 = no change, 1 = change */227#define AK4113_CINT (1<<5)228/* PLL lock status, 0 = lock, 1 = unlock */229#define AK4113_UNLCK (1<<4)230/* Validity bit, 0 = valid, 1 = invalid */231#define AK4113_V (1<<3)232/* sampling frequency or Pre-emphasis change, 0 = no detect, 1 = detect */233#define AK4113_STC (1<<2)234/* audio bit output, 0 = audio, 1 = non-audio */235#define AK4113_AUDION (1<<1)236/* parity error or biphase error status, 0 = no error, 1 = error */237#define AK4113_PAR (1<<0)238239/* AK4113_REG_RCS1 */240/* sampling frequency detection */241#define AK4113_FS3 (1<<7)242#define AK4113_FS2 (1<<6)243#define AK4113_FS1 (1<<5)244#define AK4113_FS0 (1<<4)245/* Pre-emphasis detect, 0 = OFF, 1 = ON */246#define AK4113_PEM (1<<3)247/* DAT Start ID Detect, 0 = no detect, 1 = detect */248#define AK4113_DAT (1<<2)249/* DTS-CD bit audio stream detect, 0 = no detect, 1 = detect */250#define AK4113_DTSCD (1<<1)251/* Non-PCM bit stream detection, 0 = no detect, 1 = detect */252#define AK4113_NPCM (1<<0)253#define AK4113_FS_8000HZ (AK4113_FS3|AK4113_FS0)254#define AK4113_FS_11025HZ (AK4113_FS2|AK4113_FS0)255#define AK4113_FS_16000HZ (AK4113_FS2|AK4113_FS1|AK4113_FS0)256#define AK4113_FS_22050HZ (AK4113_FS2)257#define AK4113_FS_24000HZ (AK4113_FS2|AK4113_FS1)258#define AK4113_FS_32000HZ (AK4113_FS1|AK4113_FS0)259#define AK4113_FS_44100HZ (0)260#define AK4113_FS_48000HZ (AK4113_FS1)261#define AK4113_FS_64000HZ (AK4113_FS3|AK4113_FS1|AK4113_FS0)262#define AK4113_FS_88200HZ (AK4113_FS3)263#define AK4113_FS_96000HZ (AK4113_FS3|AK4113_FS1)264#define AK4113_FS_176400HZ (AK4113_FS3|AK4113_FS2)265#define AK4113_FS_192000HZ (AK4113_FS3|AK4113_FS2|AK4113_FS1)266267/* AK4113_REG_RCS2 */268/* CRC for Q-subcode, 0 = no error, 1 = error */269#define AK4113_QCRC (1<<1)270/* CRC for channel status, 0 = no error, 1 = error */271#define AK4113_CCRC (1<<0)272273/* flags for snd_ak4113_check_rate_and_errors() */274#define AK4113_CHECK_NO_STAT (1<<0) /* no statistics */275#define AK4113_CHECK_NO_RATE (1<<1) /* no rate check */276277#define AK4113_CONTROLS 13278279typedef void (ak4113_write_t)(void *private_data, unsigned char addr,280unsigned char data);281typedef unsigned char (ak4113_read_t)(void *private_data, unsigned char addr);282283struct ak4113 {284struct snd_card *card;285ak4113_write_t *write;286ak4113_read_t *read;287void *private_data;288unsigned int init:1;289spinlock_t lock;290unsigned char regmap[AK4113_WRITABLE_REGS];291struct snd_kcontrol *kctls[AK4113_CONTROLS];292struct snd_pcm_substream *substream;293unsigned long parity_errors;294unsigned long v_bit_errors;295unsigned long qcrc_errors;296unsigned long ccrc_errors;297unsigned char rcs0;298unsigned char rcs1;299unsigned char rcs2;300struct delayed_work work;301unsigned int check_flags;302void *change_callback_private;303void (*change_callback)(struct ak4113 *ak4113, unsigned char c0,304unsigned char c1);305};306307int snd_ak4113_create(struct snd_card *card, ak4113_read_t *read,308ak4113_write_t *write,309const unsigned char *pgm,310void *private_data, struct ak4113 **r_ak4113);311void snd_ak4113_reg_write(struct ak4113 *ak4113, unsigned char reg,312unsigned char mask, unsigned char val);313void snd_ak4113_reinit(struct ak4113 *ak4113);314int snd_ak4113_build(struct ak4113 *ak4113,315struct snd_pcm_substream *capture_substream);316int snd_ak4113_external_rate(struct ak4113 *ak4113);317int snd_ak4113_check_rate_and_errors(struct ak4113 *ak4113, unsigned int flags);318319#endif /* __SOUND_AK4113_H */320321322323