^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #ifndef __SOUND_CS5535AUDIO_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #define __SOUND_CS5535AUDIO_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #define cs_writel(cs5535au, reg, val) outl(val, (cs5535au)->port + reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #define cs_writeb(cs5535au, reg, val) outb(val, (cs5535au)->port + reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #define cs_readl(cs5535au, reg) inl((cs5535au)->port + reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #define cs_readw(cs5535au, reg) inw((cs5535au)->port + reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #define cs_readb(cs5535au, reg) inb((cs5535au)->port + reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #define CS5535AUDIO_MAX_DESCRIPTORS 128
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) /* acc_codec bar0 reg addrs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #define ACC_GPIO_STATUS 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #define ACC_CODEC_STATUS 0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define ACC_CODEC_CNTL 0x0C
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define ACC_IRQ_STATUS 0x12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define ACC_BM0_CMD 0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define ACC_BM1_CMD 0x28
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define ACC_BM0_PRD 0x24
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define ACC_BM1_PRD 0x2C
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define ACC_BM0_STATUS 0x21
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define ACC_BM1_STATUS 0x29
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define ACC_BM0_PNTR 0x60
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define ACC_BM1_PNTR 0x64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) /* acc_codec bar0 reg bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) /* ACC_IRQ_STATUS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define IRQ_STS 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define WU_IRQ_STS 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define BM0_IRQ_STS 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define BM1_IRQ_STS 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) /* ACC_BMX_STATUS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #define EOP (1<<0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #define BM_EOP_ERR (1<<1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) /* ACC_BMX_CTL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define BM_CTL_EN 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define BM_CTL_PAUSE 0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define BM_CTL_DIS 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #define BM_CTL_BYTE_ORD_LE 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #define BM_CTL_BYTE_ORD_BE 0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) /* cs5535 specific ac97 codec register defines */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #define CMD_MASK 0xFF00FFFF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #define CMD_NEW 0x00010000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #define STS_NEW 0x00020000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #define PRM_RDY_STS 0x00800000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #define ACC_CODEC_CNTL_WR_CMD (~0x80000000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #define ACC_CODEC_CNTL_RD_CMD 0x80000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #define ACC_CODEC_CNTL_LNK_SHUTDOWN 0x00040000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define ACC_CODEC_CNTL_LNK_WRM_RST 0x00020000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #define PRD_JMP 0x2000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #define PRD_EOP 0x4000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #define PRD_EOT 0x8000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) enum { CS5535AUDIO_DMA_PLAYBACK, CS5535AUDIO_DMA_CAPTURE, NUM_CS5535AUDIO_DMAS };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) struct cs5535audio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) struct cs5535audio_dma_ops {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) int type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) void (*enable_dma)(struct cs5535audio *cs5535au);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) void (*disable_dma)(struct cs5535audio *cs5535au);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) void (*pause_dma)(struct cs5535audio *cs5535au);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) void (*setup_prd)(struct cs5535audio *cs5535au, u32 prd_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) u32 (*read_prd)(struct cs5535audio *cs5535au);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) u32 (*read_dma_pntr)(struct cs5535audio *cs5535au);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct cs5535audio_dma_desc {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) __le32 addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) __le16 size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) __le16 ctlreserved;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) struct cs5535audio_dma {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) const struct cs5535audio_dma_ops *ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) struct snd_dma_buffer desc_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) struct snd_pcm_substream *substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) unsigned int buf_addr, buf_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) unsigned int period_bytes, periods;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) u32 saved_prd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) int pcm_open_flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) struct cs5535audio {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) struct snd_card *card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) struct snd_ac97 *ac97;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) struct snd_pcm *pcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) int irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) struct pci_dev *pci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) unsigned long port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) spinlock_t reg_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) struct snd_pcm_substream *playback_substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) struct snd_pcm_substream *capture_substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) struct cs5535audio_dma dmas[NUM_CS5535AUDIO_DMAS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) extern const struct dev_pm_ops snd_cs5535audio_pm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) #ifdef CONFIG_OLPC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) void olpc_prequirks(struct snd_card *card,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) struct snd_ac97_template *ac97);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) int olpc_quirks(struct snd_card *card, struct snd_ac97 *ac97);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) void olpc_quirks_cleanup(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) void olpc_analog_input(struct snd_ac97 *ac97, int on);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) void olpc_mic_bias(struct snd_ac97 *ac97, int on);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) static inline void olpc_capture_open(struct snd_ac97 *ac97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) /* default to Analog Input off */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) olpc_analog_input(ac97, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) /* enable MIC Bias for recording */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) olpc_mic_bias(ac97, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) static inline void olpc_capture_close(struct snd_ac97 *ac97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) /* disable Analog Input */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) olpc_analog_input(ac97, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) /* disable the MIC Bias (so the recording LED turns off) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) olpc_mic_bias(ac97, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) static inline void olpc_prequirks(struct snd_card *card,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) struct snd_ac97_template *ac97) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) static inline int olpc_quirks(struct snd_card *card, struct snd_ac97 *ac97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) static inline void olpc_quirks_cleanup(void) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) static inline void olpc_analog_input(struct snd_ac97 *ac97, int on) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) static inline void olpc_mic_bias(struct snd_ac97 *ac97, int on) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) static inline void olpc_capture_open(struct snd_ac97 *ac97) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) static inline void olpc_capture_close(struct snd_ac97 *ac97) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) int snd_cs5535audio_pcm(struct cs5535audio *cs5535audio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) #endif /* __SOUND_CS5535AUDIO_H */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)