blob: d84620a0c26c4b95017e186930804f145656d981 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Jaya Kumar9b4ffa42005-11-17 10:12:23 +01002#ifndef __SOUND_CS5535AUDIO_H
3#define __SOUND_CS5535AUDIO_H
4
Takashi Iwai3e873172005-11-17 10:15:37 +01005#define cs_writel(cs5535au, reg, val) outl(val, (cs5535au)->port + reg)
6#define cs_writeb(cs5535au, reg, val) outb(val, (cs5535au)->port + reg)
7#define cs_readl(cs5535au, reg) inl((cs5535au)->port + reg)
8#define cs_readw(cs5535au, reg) inw((cs5535au)->port + reg)
9#define cs_readb(cs5535au, reg) inb((cs5535au)->port + reg)
Jaya Kumar9b4ffa42005-11-17 10:12:23 +010010
11#define CS5535AUDIO_MAX_DESCRIPTORS 128
12
13/* acc_codec bar0 reg addrs */
14#define ACC_GPIO_STATUS 0x00
15#define ACC_CODEC_STATUS 0x08
16#define ACC_CODEC_CNTL 0x0C
17#define ACC_IRQ_STATUS 0x12
18#define ACC_BM0_CMD 0x20
19#define ACC_BM1_CMD 0x28
Jaya Kumar9b4ffa42005-11-17 10:12:23 +010020#define ACC_BM0_PRD 0x24
21#define ACC_BM1_PRD 0x2C
Jaya Kumar9b4ffa42005-11-17 10:12:23 +010022#define ACC_BM0_STATUS 0x21
23#define ACC_BM1_STATUS 0x29
Jaya Kumar9b4ffa42005-11-17 10:12:23 +010024#define ACC_BM0_PNTR 0x60
25#define ACC_BM1_PNTR 0x64
Andres Salomon4ea24162007-09-03 15:43:43 +020026
Jaya Kumar9b4ffa42005-11-17 10:12:23 +010027/* acc_codec bar0 reg bits */
28/* ACC_IRQ_STATUS */
29#define IRQ_STS 0
30#define WU_IRQ_STS 1
31#define BM0_IRQ_STS 2
32#define BM1_IRQ_STS 3
Jaya Kumar9b4ffa42005-11-17 10:12:23 +010033/* ACC_BMX_STATUS */
34#define EOP (1<<0)
35#define BM_EOP_ERR (1<<1)
36/* ACC_BMX_CTL */
Andres Salomon506ea682007-09-03 15:43:18 +020037#define BM_CTL_EN 0x01
38#define BM_CTL_PAUSE 0x03
39#define BM_CTL_DIS 0x00
40#define BM_CTL_BYTE_ORD_LE 0x00
41#define BM_CTL_BYTE_ORD_BE 0x04
Jaya Kumar9b4ffa42005-11-17 10:12:23 +010042/* cs5535 specific ac97 codec register defines */
43#define CMD_MASK 0xFF00FFFF
44#define CMD_NEW 0x00010000
45#define STS_NEW 0x00020000
46#define PRM_RDY_STS 0x00800000
47#define ACC_CODEC_CNTL_WR_CMD (~0x80000000)
48#define ACC_CODEC_CNTL_RD_CMD 0x80000000
Jaya Kumar9ac25592006-04-28 14:34:49 +020049#define ACC_CODEC_CNTL_LNK_SHUTDOWN 0x00040000
50#define ACC_CODEC_CNTL_LNK_WRM_RST 0x00020000
Jaya Kumar9b4ffa42005-11-17 10:12:23 +010051#define PRD_JMP 0x2000
52#define PRD_EOP 0x4000
53#define PRD_EOT 0x8000
54
Jaya Kumar9b4ffa42005-11-17 10:12:23 +010055enum { CS5535AUDIO_DMA_PLAYBACK, CS5535AUDIO_DMA_CAPTURE, NUM_CS5535AUDIO_DMAS };
Takashi Iwai66f8df62005-11-17 14:56:21 +010056
57struct cs5535audio;
58
59struct cs5535audio_dma_ops {
Jaya Kumar9b4ffa42005-11-17 10:12:23 +010060 int type;
Takashi Iwai66f8df62005-11-17 14:56:21 +010061 void (*enable_dma)(struct cs5535audio *cs5535au);
62 void (*disable_dma)(struct cs5535audio *cs5535au);
63 void (*pause_dma)(struct cs5535audio *cs5535au);
64 void (*setup_prd)(struct cs5535audio *cs5535au, u32 prd_addr);
Jaya Kumar9ac25592006-04-28 14:34:49 +020065 u32 (*read_prd)(struct cs5535audio *cs5535au);
Takashi Iwai66f8df62005-11-17 14:56:21 +010066 u32 (*read_dma_pntr)(struct cs5535audio *cs5535au);
Jaya Kumar9b4ffa42005-11-17 10:12:23 +010067};
68
Takashi Iwai66f8df62005-11-17 14:56:21 +010069struct cs5535audio_dma_desc {
Takashi Iwai69756932018-07-25 17:59:26 +020070 __le32 addr;
71 __le16 size;
72 __le16 ctlreserved;
Takashi Iwai66f8df62005-11-17 14:56:21 +010073};
Jaya Kumar9b4ffa42005-11-17 10:12:23 +010074
Takashi Iwai66f8df62005-11-17 14:56:21 +010075struct cs5535audio_dma {
76 const struct cs5535audio_dma_ops *ops;
Jaya Kumar9b4ffa42005-11-17 10:12:23 +010077 struct snd_dma_buffer desc_buf;
Takashi Iwai66f8df62005-11-17 14:56:21 +010078 struct snd_pcm_substream *substream;
Jaya Kumar9b4ffa42005-11-17 10:12:23 +010079 unsigned int buf_addr, buf_bytes;
80 unsigned int period_bytes, periods;
Jaya Kumar9ac25592006-04-28 14:34:49 +020081 u32 saved_prd;
Jaya Kumarb035ce02008-11-05 17:30:08 -050082 int pcm_open_flag;
Jaya Kumar9b4ffa42005-11-17 10:12:23 +010083};
84
Takashi Iwai66f8df62005-11-17 14:56:21 +010085struct cs5535audio {
86 struct snd_card *card;
87 struct snd_ac97 *ac97;
Jaya Kumar9ac25592006-04-28 14:34:49 +020088 struct snd_pcm *pcm;
Jaya Kumar9b4ffa42005-11-17 10:12:23 +010089 int irq;
90 struct pci_dev *pci;
91 unsigned long port;
92 spinlock_t reg_lock;
Takashi Iwai66f8df62005-11-17 14:56:21 +010093 struct snd_pcm_substream *playback_substream;
94 struct snd_pcm_substream *capture_substream;
95 struct cs5535audio_dma dmas[NUM_CS5535AUDIO_DMAS];
Jaya Kumar9b4ffa42005-11-17 10:12:23 +010096};
97
Takashi Iwai68cb2b52012-07-02 15:20:37 +020098extern const struct dev_pm_ops snd_cs5535audio_pm;
Andres Salomonb6c52a2cd2008-11-05 17:30:30 -050099
Andres Salomon3c554942009-12-14 18:00:36 -0800100#ifdef CONFIG_OLPC
Bill Pembertone23e7a12012-12-06 12:35:10 -0500101void olpc_prequirks(struct snd_card *card,
102 struct snd_ac97_template *ac97);
103int olpc_quirks(struct snd_card *card, struct snd_ac97 *ac97);
104void olpc_quirks_cleanup(void);
Andres Salomond6276b72008-11-06 16:49:38 -0500105void olpc_analog_input(struct snd_ac97 *ac97, int on);
Andres Salomonbf1e5272008-11-06 16:53:03 -0500106void olpc_mic_bias(struct snd_ac97 *ac97, int on);
107
108static inline void olpc_capture_open(struct snd_ac97 *ac97)
109{
Andres Salomon01da0242008-11-06 16:53:11 -0500110 /* default to Analog Input off */
111 olpc_analog_input(ac97, 0);
Andres Salomonbf1e5272008-11-06 16:53:03 -0500112 /* enable MIC Bias for recording */
113 olpc_mic_bias(ac97, 1);
114}
115
116static inline void olpc_capture_close(struct snd_ac97 *ac97)
117{
Andres Salomon01da0242008-11-06 16:53:11 -0500118 /* disable Analog Input */
119 olpc_analog_input(ac97, 0);
Andres Salomonbf1e5272008-11-06 16:53:03 -0500120 /* disable the MIC Bias (so the recording LED turns off) */
121 olpc_mic_bias(ac97, 0);
122}
Jaya Kumar57d4bf62008-11-06 16:43:34 -0500123#else
Andres Salomon3556d182008-11-06 16:44:08 -0500124static inline void olpc_prequirks(struct snd_card *card,
125 struct snd_ac97_template *ac97) { }
126static inline int olpc_quirks(struct snd_card *card, struct snd_ac97 *ac97)
127{
128 return 0;
129}
Andres Salomon3c554942009-12-14 18:00:36 -0800130static inline void olpc_quirks_cleanup(void) { }
Andres Salomond6276b72008-11-06 16:49:38 -0500131static inline void olpc_analog_input(struct snd_ac97 *ac97, int on) { }
Andres Salomonbf1e5272008-11-06 16:53:03 -0500132static inline void olpc_mic_bias(struct snd_ac97 *ac97, int on) { }
133static inline void olpc_capture_open(struct snd_ac97 *ac97) { }
134static inline void olpc_capture_close(struct snd_ac97 *ac97) { }
Jaya Kumar57d4bf62008-11-06 16:43:34 -0500135#endif
136
Bill Pembertone23e7a12012-12-06 12:35:10 -0500137int snd_cs5535audio_pcm(struct cs5535audio *cs5535audio);
Takashi Iwai66f8df62005-11-17 14:56:21 +0100138
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100139#endif /* __SOUND_CS5535AUDIO_H */
140