123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462 |
- #define AW2_SAA7146_M
- #include <linux/init.h>
- #include <linux/pci.h>
- #include <linux/interrupt.h>
- #include <linux/delay.h>
- #include <linux/io.h>
- #include <sound/core.h>
- #include <sound/initval.h>
- #include <sound/pcm.h>
- #include <sound/pcm_params.h>
- #include "saa7146.h"
- #include "aw2-saa7146.h"
- #include "aw2-tsl.c"
- #define WRITEREG(value, addr) writel((value), chip->base_addr + (addr))
- #define READREG(addr) readl(chip->base_addr + (addr))
- static struct snd_aw2_saa7146_cb_param
- arr_substream_it_playback_cb[NB_STREAM_PLAYBACK];
- static struct snd_aw2_saa7146_cb_param
- arr_substream_it_capture_cb[NB_STREAM_CAPTURE];
- static int snd_aw2_saa7146_get_limit(int size);
- int snd_aw2_saa7146_free(struct snd_aw2_saa7146 *chip)
- {
-
- WRITEREG(0, IER);
-
- WRITEREG((MRST_N << 16), MC1);
-
- chip->base_addr = NULL;
- return 0;
- }
- void snd_aw2_saa7146_setup(struct snd_aw2_saa7146 *chip,
- void __iomem *pci_base_addr)
- {
-
- unsigned int acon2;
- unsigned int acon1 = 0;
- int i;
-
- chip->base_addr = pci_base_addr;
-
- WRITEREG(0, IER);
-
- WRITEREG((MRST_N << 16), MC1);
-
- #ifdef __BIG_ENDIAN
- acon1 |= A1_SWAP;
- acon1 |= A2_SWAP;
- #endif
-
-
- acon1 |= 0 * WS1_CTRL;
- acon1 |= 0 * WS2_CTRL;
-
- acon1 |= 3 * WS4_CTRL;
-
- acon1 |= 2 * WS3_CTRL;
-
- acon1 |= 3 * AUDIO_MODE;
- WRITEREG(acon1, ACON1);
-
- WRITEREG(3 * (BurstA1_in) + 3 * (ThreshA1_in) +
- 3 * (BurstA1_out) + 3 * (ThreshA1_out) +
- 3 * (BurstA2_out) + 3 * (ThreshA2_out), PCI_BT_A);
-
- WRITEREG((EAP << 16) | EAP, MC1);
-
- WRITEREG((EI2C << 16) | EI2C, MC1);
-
- WRITEREG(A1_out | A2_out | A1_in | IIC_S | IIC_E, IER);
-
- acon2 = A2_CLKSRC | BCLK1_OEN;
- WRITEREG(acon2, ACON2);
-
- snd_aw2_saa7146_use_digital_input(chip, 0);
-
- for (i = 0; i < 8; ++i) {
- WRITEREG(tsl1[i], TSL1 + (i * 4));
- WRITEREG(tsl2[i], TSL2 + (i * 4));
- }
- }
- void snd_aw2_saa7146_pcm_init_playback(struct snd_aw2_saa7146 *chip,
- int stream_number,
- unsigned long dma_addr,
- unsigned long period_size,
- unsigned long buffer_size)
- {
- unsigned long dw_page, dw_limit;
-
-
-
- dw_page = (0L << 11);
-
- dw_limit = snd_aw2_saa7146_get_limit(period_size);
- dw_page |= (dw_limit << 4);
- if (stream_number == 0) {
- WRITEREG(dw_page, PageA2_out);
-
-
-
- WRITEREG(dma_addr, BaseA2_out);
-
- WRITEREG(dma_addr + buffer_size, ProtA2_out);
- } else if (stream_number == 1) {
- WRITEREG(dw_page, PageA1_out);
-
-
-
- WRITEREG(dma_addr, BaseA1_out);
-
- WRITEREG(dma_addr + buffer_size, ProtA1_out);
- } else {
- pr_err("aw2: snd_aw2_saa7146_pcm_init_playback: "
- "Substream number is not 0 or 1 -> not managed\n");
- }
- }
- void snd_aw2_saa7146_pcm_init_capture(struct snd_aw2_saa7146 *chip,
- int stream_number, unsigned long dma_addr,
- unsigned long period_size,
- unsigned long buffer_size)
- {
- unsigned long dw_page, dw_limit;
-
-
-
- dw_page = (0L << 11);
-
- dw_limit = snd_aw2_saa7146_get_limit(period_size);
- dw_page |= (dw_limit << 4);
- if (stream_number == 0) {
- WRITEREG(dw_page, PageA1_in);
-
-
-
- WRITEREG(dma_addr, BaseA1_in);
-
- WRITEREG(dma_addr + buffer_size, ProtA1_in);
- } else {
- pr_err("aw2: snd_aw2_saa7146_pcm_init_capture: "
- "Substream number is not 0 -> not managed\n");
- }
- }
- void snd_aw2_saa7146_define_it_playback_callback(unsigned int stream_number,
- snd_aw2_saa7146_it_cb
- p_it_callback,
- void *p_callback_param)
- {
- if (stream_number < NB_STREAM_PLAYBACK) {
- arr_substream_it_playback_cb[stream_number].p_it_callback =
- (snd_aw2_saa7146_it_cb) p_it_callback;
- arr_substream_it_playback_cb[stream_number].p_callback_param =
- (void *)p_callback_param;
- }
- }
- void snd_aw2_saa7146_define_it_capture_callback(unsigned int stream_number,
- snd_aw2_saa7146_it_cb
- p_it_callback,
- void *p_callback_param)
- {
- if (stream_number < NB_STREAM_CAPTURE) {
- arr_substream_it_capture_cb[stream_number].p_it_callback =
- (snd_aw2_saa7146_it_cb) p_it_callback;
- arr_substream_it_capture_cb[stream_number].p_callback_param =
- (void *)p_callback_param;
- }
- }
- void snd_aw2_saa7146_pcm_trigger_start_playback(struct snd_aw2_saa7146 *chip,
- int stream_number)
- {
- unsigned int acon1 = 0;
-
- acon1 = READREG(ACON1);
- if (stream_number == 0) {
- WRITEREG((TR_E_A2_OUT << 16) | TR_E_A2_OUT, MC1);
-
- acon1 |= 2 * WS2_CTRL;
- WRITEREG(acon1, ACON1);
- } else if (stream_number == 1) {
- WRITEREG((TR_E_A1_OUT << 16) | TR_E_A1_OUT, MC1);
-
- acon1 |= 1 * WS1_CTRL;
- WRITEREG(acon1, ACON1);
- }
- }
- void snd_aw2_saa7146_pcm_trigger_stop_playback(struct snd_aw2_saa7146 *chip,
- int stream_number)
- {
- unsigned int acon1 = 0;
- acon1 = READREG(ACON1);
- if (stream_number == 0) {
-
- acon1 &= ~(3 * WS2_CTRL);
- WRITEREG(acon1, ACON1);
- WRITEREG((TR_E_A2_OUT << 16), MC1);
- } else if (stream_number == 1) {
-
- acon1 &= ~(3 * WS1_CTRL);
- WRITEREG(acon1, ACON1);
- WRITEREG((TR_E_A1_OUT << 16), MC1);
- }
- }
- void snd_aw2_saa7146_pcm_trigger_start_capture(struct snd_aw2_saa7146 *chip,
- int stream_number)
- {
-
- if (stream_number == 0)
- WRITEREG((TR_E_A1_IN << 16) | TR_E_A1_IN, MC1);
- }
- void snd_aw2_saa7146_pcm_trigger_stop_capture(struct snd_aw2_saa7146 *chip,
- int stream_number)
- {
- if (stream_number == 0)
- WRITEREG((TR_E_A1_IN << 16), MC1);
- }
- irqreturn_t snd_aw2_saa7146_interrupt(int irq, void *dev_id)
- {
- unsigned int isr;
- unsigned int iicsta;
- struct snd_aw2_saa7146 *chip = dev_id;
- isr = READREG(ISR);
- if (!isr)
- return IRQ_NONE;
- WRITEREG(isr, ISR);
- if (isr & (IIC_S | IIC_E)) {
- iicsta = READREG(IICSTA);
- WRITEREG(0x100, IICSTA);
- }
- if (isr & A1_out) {
- if (arr_substream_it_playback_cb[1].p_it_callback != NULL) {
- arr_substream_it_playback_cb[1].
- p_it_callback(arr_substream_it_playback_cb[1].
- p_callback_param);
- }
- }
- if (isr & A2_out) {
- if (arr_substream_it_playback_cb[0].p_it_callback != NULL) {
- arr_substream_it_playback_cb[0].
- p_it_callback(arr_substream_it_playback_cb[0].
- p_callback_param);
- }
- }
- if (isr & A1_in) {
- if (arr_substream_it_capture_cb[0].p_it_callback != NULL) {
- arr_substream_it_capture_cb[0].
- p_it_callback(arr_substream_it_capture_cb[0].
- p_callback_param);
- }
- }
- return IRQ_HANDLED;
- }
- unsigned int snd_aw2_saa7146_get_hw_ptr_playback(struct snd_aw2_saa7146 *chip,
- int stream_number,
- unsigned char *start_addr,
- unsigned int buffer_size)
- {
- long pci_adp = 0;
- size_t ptr = 0;
- if (stream_number == 0) {
- pci_adp = READREG(PCI_ADP3);
- ptr = pci_adp - (long)start_addr;
- if (ptr == buffer_size)
- ptr = 0;
- }
- if (stream_number == 1) {
- pci_adp = READREG(PCI_ADP1);
- ptr = pci_adp - (size_t) start_addr;
- if (ptr == buffer_size)
- ptr = 0;
- }
- return ptr;
- }
- unsigned int snd_aw2_saa7146_get_hw_ptr_capture(struct snd_aw2_saa7146 *chip,
- int stream_number,
- unsigned char *start_addr,
- unsigned int buffer_size)
- {
- size_t pci_adp = 0;
- size_t ptr = 0;
- if (stream_number == 0) {
- pci_adp = READREG(PCI_ADP2);
- ptr = pci_adp - (size_t) start_addr;
- if (ptr == buffer_size)
- ptr = 0;
- }
- return ptr;
- }
- void snd_aw2_saa7146_use_digital_input(struct snd_aw2_saa7146 *chip,
- int use_digital)
- {
-
- if (use_digital)
- WRITEREG(0x40, GPIO_CTRL);
- else
- WRITEREG(0x50, GPIO_CTRL);
- }
- int snd_aw2_saa7146_is_using_digital_input(struct snd_aw2_saa7146 *chip)
- {
- unsigned int reg_val = READREG(GPIO_CTRL);
- if ((reg_val & 0xFF) == 0x40)
- return 1;
- else
- return 0;
- }
- static int snd_aw2_saa7146_get_limit(int size)
- {
- int limitsize = 32;
- int limit = 0;
- while (limitsize < size) {
- limitsize *= 2;
- limit++;
- }
- return limit;
- }
|