blob: bb3cc641130c68ef6d9ce2c51f070abfc1de9e3f [file] [log] [blame]
Jaya Kumar9b4ffa42005-11-17 10:12:23 +01001#ifndef __SOUND_CS5535AUDIO_H
2#define __SOUND_CS5535AUDIO_H
3
Takashi Iwai3e873172005-11-17 10:15:37 +01004#define cs_writel(cs5535au, reg, val) outl(val, (cs5535au)->port + reg)
5#define cs_writeb(cs5535au, reg, val) outb(val, (cs5535au)->port + reg)
6#define cs_readl(cs5535au, reg) inl((cs5535au)->port + reg)
7#define cs_readw(cs5535au, reg) inw((cs5535au)->port + reg)
8#define cs_readb(cs5535au, reg) inb((cs5535au)->port + reg)
Jaya Kumar9b4ffa42005-11-17 10:12:23 +01009
10#define CS5535AUDIO_MAX_DESCRIPTORS 128
11
12/* acc_codec bar0 reg addrs */
13#define ACC_GPIO_STATUS 0x00
14#define ACC_CODEC_STATUS 0x08
15#define ACC_CODEC_CNTL 0x0C
16#define ACC_IRQ_STATUS 0x12
17#define ACC_BM0_CMD 0x20
18#define ACC_BM1_CMD 0x28
Jaya Kumar9b4ffa42005-11-17 10:12:23 +010019#define ACC_BM0_PRD 0x24
20#define ACC_BM1_PRD 0x2C
Jaya Kumar9b4ffa42005-11-17 10:12:23 +010021#define ACC_BM0_STATUS 0x21
22#define ACC_BM1_STATUS 0x29
Jaya Kumar9b4ffa42005-11-17 10:12:23 +010023#define ACC_BM0_PNTR 0x60
24#define ACC_BM1_PNTR 0x64
Andres Salomon4ea24162007-09-03 15:43:43 +020025
Jaya Kumar9b4ffa42005-11-17 10:12:23 +010026/* acc_codec bar0 reg bits */
27/* ACC_IRQ_STATUS */
28#define IRQ_STS 0
29#define WU_IRQ_STS 1
30#define BM0_IRQ_STS 2
31#define BM1_IRQ_STS 3
Jaya Kumar9b4ffa42005-11-17 10:12:23 +010032/* ACC_BMX_STATUS */
33#define EOP (1<<0)
34#define BM_EOP_ERR (1<<1)
35/* ACC_BMX_CTL */
Andres Salomon506ea682007-09-03 15:43:18 +020036#define BM_CTL_EN 0x01
37#define BM_CTL_PAUSE 0x03
38#define BM_CTL_DIS 0x00
39#define BM_CTL_BYTE_ORD_LE 0x00
40#define BM_CTL_BYTE_ORD_BE 0x04
Jaya Kumar9b4ffa42005-11-17 10:12:23 +010041/* cs5535 specific ac97 codec register defines */
42#define CMD_MASK 0xFF00FFFF
43#define CMD_NEW 0x00010000
44#define STS_NEW 0x00020000
45#define PRM_RDY_STS 0x00800000
46#define ACC_CODEC_CNTL_WR_CMD (~0x80000000)
47#define ACC_CODEC_CNTL_RD_CMD 0x80000000
Jaya Kumar9ac25592006-04-28 14:34:49 +020048#define ACC_CODEC_CNTL_LNK_SHUTDOWN 0x00040000
49#define ACC_CODEC_CNTL_LNK_WRM_RST 0x00020000
Jaya Kumar9b4ffa42005-11-17 10:12:23 +010050#define PRD_JMP 0x2000
51#define PRD_EOP 0x4000
52#define PRD_EOT 0x8000
53
Jaya Kumar9b4ffa42005-11-17 10:12:23 +010054enum { CS5535AUDIO_DMA_PLAYBACK, CS5535AUDIO_DMA_CAPTURE, NUM_CS5535AUDIO_DMAS };
Takashi Iwai66f8df62005-11-17 14:56:21 +010055
56struct cs5535audio;
57
58struct cs5535audio_dma_ops {
Jaya Kumar9b4ffa42005-11-17 10:12:23 +010059 int type;
Takashi Iwai66f8df62005-11-17 14:56:21 +010060 void (*enable_dma)(struct cs5535audio *cs5535au);
61 void (*disable_dma)(struct cs5535audio *cs5535au);
62 void (*pause_dma)(struct cs5535audio *cs5535au);
63 void (*setup_prd)(struct cs5535audio *cs5535au, u32 prd_addr);
Jaya Kumar9ac25592006-04-28 14:34:49 +020064 u32 (*read_prd)(struct cs5535audio *cs5535au);
Takashi Iwai66f8df62005-11-17 14:56:21 +010065 u32 (*read_dma_pntr)(struct cs5535audio *cs5535au);
Jaya Kumar9b4ffa42005-11-17 10:12:23 +010066};
67
Takashi Iwai66f8df62005-11-17 14:56:21 +010068struct cs5535audio_dma_desc {
Jaya Kumar9b4ffa42005-11-17 10:12:23 +010069 u32 addr;
70 u16 size;
71 u16 ctlreserved;
Takashi Iwai66f8df62005-11-17 14:56:21 +010072};
Jaya Kumar9b4ffa42005-11-17 10:12:23 +010073
Takashi Iwai66f8df62005-11-17 14:56:21 +010074struct cs5535audio_dma {
75 const struct cs5535audio_dma_ops *ops;
Jaya Kumar9b4ffa42005-11-17 10:12:23 +010076 struct snd_dma_buffer desc_buf;
Takashi Iwai66f8df62005-11-17 14:56:21 +010077 struct snd_pcm_substream *substream;
Jaya Kumar9b4ffa42005-11-17 10:12:23 +010078 unsigned int buf_addr, buf_bytes;
79 unsigned int period_bytes, periods;
Jaya Kumar9ac25592006-04-28 14:34:49 +020080 u32 saved_prd;
Jaya Kumarb035ce02008-11-05 17:30:08 -050081 int pcm_open_flag;
Jaya Kumar9b4ffa42005-11-17 10:12:23 +010082};
83
Takashi Iwai66f8df62005-11-17 14:56:21 +010084struct cs5535audio {
85 struct snd_card *card;
86 struct snd_ac97 *ac97;
Jaya Kumar9ac25592006-04-28 14:34:49 +020087 struct snd_pcm *pcm;
Jaya Kumar9b4ffa42005-11-17 10:12:23 +010088 int irq;
89 struct pci_dev *pci;
90 unsigned long port;
91 spinlock_t reg_lock;
Takashi Iwai66f8df62005-11-17 14:56:21 +010092 struct snd_pcm_substream *playback_substream;
93 struct snd_pcm_substream *capture_substream;
94 struct cs5535audio_dma dmas[NUM_CS5535AUDIO_DMAS];
Jaya Kumar9b4ffa42005-11-17 10:12:23 +010095};
96
Takashi Iwai68cb2b52012-07-02 15:20:37 +020097extern const struct dev_pm_ops snd_cs5535audio_pm;
Andres Salomonb6c52a2cd2008-11-05 17:30:30 -050098
Andres Salomon3c554942009-12-14 18:00:36 -080099#ifdef CONFIG_OLPC
Andres Salomon3556d182008-11-06 16:44:08 -0500100void __devinit olpc_prequirks(struct snd_card *card,
101 struct snd_ac97_template *ac97);
102int __devinit olpc_quirks(struct snd_card *card, struct snd_ac97 *ac97);
Andres Salomon3c554942009-12-14 18:00:36 -0800103void __devexit olpc_quirks_cleanup(void);
Andres Salomond6276b72008-11-06 16:49:38 -0500104void olpc_analog_input(struct snd_ac97 *ac97, int on);
Andres Salomonbf1e5272008-11-06 16:53:03 -0500105void olpc_mic_bias(struct snd_ac97 *ac97, int on);
106
107static inline void olpc_capture_open(struct snd_ac97 *ac97)
108{
Andres Salomon01da0242008-11-06 16:53:11 -0500109 /* default to Analog Input off */
110 olpc_analog_input(ac97, 0);
Andres Salomonbf1e5272008-11-06 16:53:03 -0500111 /* enable MIC Bias for recording */
112 olpc_mic_bias(ac97, 1);
113}
114
115static inline void olpc_capture_close(struct snd_ac97 *ac97)
116{
Andres Salomon01da0242008-11-06 16:53:11 -0500117 /* disable Analog Input */
118 olpc_analog_input(ac97, 0);
Andres Salomonbf1e5272008-11-06 16:53:03 -0500119 /* disable the MIC Bias (so the recording LED turns off) */
120 olpc_mic_bias(ac97, 0);
121}
Jaya Kumar57d4bf62008-11-06 16:43:34 -0500122#else
Andres Salomon3556d182008-11-06 16:44:08 -0500123static inline void olpc_prequirks(struct snd_card *card,
124 struct snd_ac97_template *ac97) { }
125static inline int olpc_quirks(struct snd_card *card, struct snd_ac97 *ac97)
126{
127 return 0;
128}
Andres Salomon3c554942009-12-14 18:00:36 -0800129static inline void olpc_quirks_cleanup(void) { }
Andres Salomond6276b72008-11-06 16:49:38 -0500130static inline void olpc_analog_input(struct snd_ac97 *ac97, int on) { }
Andres Salomonbf1e5272008-11-06 16:53:03 -0500131static inline void olpc_mic_bias(struct snd_ac97 *ac97, int on) { }
132static inline void olpc_capture_open(struct snd_ac97 *ac97) { }
133static inline void olpc_capture_close(struct snd_ac97 *ac97) { }
Jaya Kumar57d4bf62008-11-06 16:43:34 -0500134#endif
135
Takashi Iwai66f8df62005-11-17 14:56:21 +0100136int __devinit snd_cs5535audio_pcm(struct cs5535audio *cs5535audio);
137
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100138#endif /* __SOUND_CS5535AUDIO_H */
139