Thomas Gleixner | 1a59d1b8 | 2019-05-27 08:55:05 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Driver for Sound Cors PDAudioCF soundcard |
| 4 | * |
Jaroslav Kysela | c1017a4 | 2007-10-15 09:50:19 +0200 | [diff] [blame] | 5 | * Copyright (c) 2003 by Jaroslav Kysela <perex@perex.cz> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #ifndef __PDAUDIOCF_H |
| 9 | #define __PDAUDIOCF_H |
| 10 | |
| 11 | #include <sound/pcm.h> |
Takashi Iwai | ddfb319 | 2011-02-02 17:49:53 +0100 | [diff] [blame] | 12 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/interrupt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <pcmcia/cistpl.h> |
| 15 | #include <pcmcia/ds.h> |
| 16 | |
| 17 | #include <sound/ak4117.h> |
| 18 | |
| 19 | /* PDAUDIOCF registers */ |
| 20 | #define PDAUDIOCF_REG_MD 0x00 /* music data, R/O */ |
| 21 | #define PDAUDIOCF_REG_WDP 0x02 /* write data pointer / 2, R/O */ |
| 22 | #define PDAUDIOCF_REG_RDP 0x04 /* read data pointer / 2, R/O */ |
| 23 | #define PDAUDIOCF_REG_TCR 0x06 /* test control register W/O */ |
| 24 | #define PDAUDIOCF_REG_SCR 0x08 /* status and control, R/W (see bit description) */ |
| 25 | #define PDAUDIOCF_REG_ISR 0x0a /* interrupt status, R/O */ |
| 26 | #define PDAUDIOCF_REG_IER 0x0c /* interrupt enable, R/W */ |
| 27 | #define PDAUDIOCF_REG_AK_IFR 0x0e /* AK interface register, R/W */ |
| 28 | |
| 29 | /* PDAUDIOCF_REG_TCR */ |
| 30 | #define PDAUDIOCF_ELIMAKMBIT (1<<0) /* simulate AKM music data */ |
| 31 | #define PDAUDIOCF_TESTDATASEL (1<<1) /* test data selection, 0 = 0x55, 1 = pseudo-random */ |
| 32 | |
| 33 | /* PDAUDIOCF_REG_SCR */ |
| 34 | #define PDAUDIOCF_AK_SBP (1<<0) /* serial port busy flag */ |
| 35 | #define PDAUDIOCF_RST (1<<2) /* FPGA, AKM + SRAM buffer reset */ |
| 36 | #define PDAUDIOCF_PDN (1<<3) /* power down bit */ |
| 37 | #define PDAUDIOCF_CLKDIV0 (1<<4) /* choose 24.576Mhz clock divided by 1,2,3 or 4 */ |
| 38 | #define PDAUDIOCF_CLKDIV1 (1<<5) |
| 39 | #define PDAUDIOCF_RECORD (1<<6) /* start capturing to SRAM */ |
| 40 | #define PDAUDIOCF_AK_SDD (1<<7) /* music data detected */ |
| 41 | #define PDAUDIOCF_RED_LED_OFF (1<<8) /* red LED off override */ |
| 42 | #define PDAUDIOCF_BLUE_LED_OFF (1<<9) /* blue LED off override */ |
| 43 | #define PDAUDIOCF_DATAFMT0 (1<<10) /* data format bits: 00 = 16-bit, 01 = 18-bit */ |
| 44 | #define PDAUDIOCF_DATAFMT1 (1<<11) /* 10 = 20-bit, 11 = 24-bit, all right justified */ |
| 45 | #define PDAUDIOCF_FPGAREV(x) ((x>>12)&0x0f) /* FPGA revision */ |
| 46 | |
| 47 | /* PDAUDIOCF_REG_ISR */ |
| 48 | #define PDAUDIOCF_IRQLVL (1<<0) /* Buffer level IRQ */ |
| 49 | #define PDAUDIOCF_IRQOVR (1<<1) /* Overrun IRQ */ |
| 50 | #define PDAUDIOCF_IRQAKM (1<<2) /* AKM IRQ */ |
| 51 | |
| 52 | /* PDAUDIOCF_REG_IER */ |
| 53 | #define PDAUDIOCF_IRQLVLEN0 (1<<0) /* fill threshold levels; 00 = none, 01 = 1/8th of buffer */ |
| 54 | #define PDAUDIOCF_IRQLVLEN1 (1<<1) /* 10 = 1/4th of buffer, 11 = 1/2th of buffer */ |
| 55 | #define PDAUDIOCF_IRQOVREN (1<<2) /* enable overrun IRQ */ |
| 56 | #define PDAUDIOCF_IRQAKMEN (1<<3) /* enable AKM IRQ */ |
| 57 | #define PDAUDIOCF_BLUEDUTY0 (1<<8) /* blue LED duty cycle; 00 = 100%, 01 = 50% */ |
| 58 | #define PDAUDIOCF_BLUEDUTY1 (1<<9) /* 02 = 25%, 11 = 12% */ |
| 59 | #define PDAUDIOCF_REDDUTY0 (1<<10) /* red LED duty cycle; 00 = 100%, 01 = 50% */ |
| 60 | #define PDAUDIOCF_REDDUTY1 (1<<11) /* 02 = 25%, 11 = 12% */ |
| 61 | #define PDAUDIOCF_BLUESDD (1<<12) /* blue LED against SDD bit */ |
| 62 | #define PDAUDIOCF_BLUEMODULATE (1<<13) /* save power when 100% duty cycle selected */ |
| 63 | #define PDAUDIOCF_REDMODULATE (1<<14) /* save power when 100% duty cycle selected */ |
| 64 | #define PDAUDIOCF_HALFRATE (1<<15) /* slow both LED blinks by half (also spdif detect rate) */ |
| 65 | |
| 66 | /* chip status */ |
| 67 | #define PDAUDIOCF_STAT_IS_STALE (1<<0) |
| 68 | #define PDAUDIOCF_STAT_IS_CONFIGURED (1<<1) |
| 69 | #define PDAUDIOCF_STAT_IS_SUSPENDED (1<<2) |
| 70 | |
Takashi Iwai | db13154 | 2005-11-17 15:07:38 +0100 | [diff] [blame] | 71 | struct snd_pdacf { |
| 72 | struct snd_card *card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | int index; |
| 74 | |
| 75 | unsigned long port; |
| 76 | int irq; |
| 77 | |
Takashi Iwai | 3b73cfe5 | 2014-09-10 14:58:59 +0200 | [diff] [blame] | 78 | struct mutex reg_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | unsigned short regmap[8]; |
| 80 | unsigned short suspend_reg_scr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | |
| 82 | spinlock_t ak4117_lock; |
Takashi Iwai | db13154 | 2005-11-17 15:07:38 +0100 | [diff] [blame] | 83 | struct ak4117 *ak4117; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | |
| 85 | unsigned int chip_status; |
| 86 | |
Takashi Iwai | db13154 | 2005-11-17 15:07:38 +0100 | [diff] [blame] | 87 | struct snd_pcm *pcm; |
| 88 | struct snd_pcm_substream *pcm_substream; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | unsigned int pcm_running: 1; |
| 90 | unsigned int pcm_channels; |
| 91 | unsigned int pcm_swab; |
| 92 | unsigned int pcm_little; |
| 93 | unsigned int pcm_frame; |
| 94 | unsigned int pcm_sample; |
| 95 | unsigned int pcm_xor; |
| 96 | unsigned int pcm_size; |
| 97 | unsigned int pcm_period; |
| 98 | unsigned int pcm_tdone; |
| 99 | unsigned int pcm_hwptr; |
| 100 | void *pcm_area; |
| 101 | |
| 102 | /* pcmcia stuff */ |
Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 103 | struct pcmcia_device *p_dev; |
Takashi Iwai | db13154 | 2005-11-17 15:07:38 +0100 | [diff] [blame] | 104 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
Takashi Iwai | db13154 | 2005-11-17 15:07:38 +0100 | [diff] [blame] | 106 | static inline void pdacf_reg_write(struct snd_pdacf *chip, unsigned char reg, unsigned short val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | { |
| 108 | outw(chip->regmap[reg>>1] = val, chip->port + reg); |
| 109 | } |
| 110 | |
Takashi Iwai | db13154 | 2005-11-17 15:07:38 +0100 | [diff] [blame] | 111 | static inline unsigned short pdacf_reg_read(struct snd_pdacf *chip, unsigned char reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | { |
| 113 | return inw(chip->port + reg); |
| 114 | } |
| 115 | |
Takashi Iwai | db13154 | 2005-11-17 15:07:38 +0100 | [diff] [blame] | 116 | struct snd_pdacf *snd_pdacf_create(struct snd_card *card); |
| 117 | int snd_pdacf_ak4117_create(struct snd_pdacf *pdacf); |
| 118 | void snd_pdacf_powerdown(struct snd_pdacf *chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | #ifdef CONFIG_PM |
Takashi Iwai | 2cb1331 | 2012-07-02 15:42:33 +0200 | [diff] [blame] | 120 | int snd_pdacf_suspend(struct snd_pdacf *chip); |
Takashi Iwai | e4f163d | 2005-11-17 17:15:58 +0100 | [diff] [blame] | 121 | int snd_pdacf_resume(struct snd_pdacf *chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | #endif |
Takashi Iwai | db13154 | 2005-11-17 15:07:38 +0100 | [diff] [blame] | 123 | int snd_pdacf_pcm_new(struct snd_pdacf *chip); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 124 | irqreturn_t pdacf_interrupt(int irq, void *dev); |
Takashi Iwai | 3b73cfe5 | 2014-09-10 14:58:59 +0200 | [diff] [blame] | 125 | irqreturn_t pdacf_threaded_irq(int irq, void *dev); |
Takashi Iwai | db13154 | 2005-11-17 15:07:38 +0100 | [diff] [blame] | 126 | void pdacf_reinit(struct snd_pdacf *chip, int resume); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | |
| 128 | #endif /* __PDAUDIOCF_H */ |