1*77f5075aSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
202bec490STim Blechmann /* -*- linux-c -*- *
302bec490STim Blechmann *
402bec490STim Blechmann * ALSA driver for the digigram lx6464es interface
502bec490STim Blechmann * low-level interface
602bec490STim Blechmann *
702bec490STim Blechmann * Copyright (c) 2009 Tim Blechmann <tim@klingt.org>
802bec490STim Blechmann */
902bec490STim Blechmann
1002bec490STim Blechmann #ifndef LX_CORE_H
1102bec490STim Blechmann #define LX_CORE_H
1202bec490STim Blechmann
1302bec490STim Blechmann #include <linux/interrupt.h>
1402bec490STim Blechmann
1502bec490STim Blechmann #include "lx_defs.h"
1602bec490STim Blechmann
1702bec490STim Blechmann #define REG_CRM_NUMBER 12
1802bec490STim Blechmann
1902bec490STim Blechmann struct lx6464es;
2002bec490STim Blechmann
2102bec490STim Blechmann /* low-level register access */
2202bec490STim Blechmann
2302bec490STim Blechmann /* dsp register access */
2402bec490STim Blechmann enum {
2502bec490STim Blechmann eReg_BASE,
2602bec490STim Blechmann eReg_CSM,
2702bec490STim Blechmann eReg_CRM1,
2802bec490STim Blechmann eReg_CRM2,
2902bec490STim Blechmann eReg_CRM3,
3002bec490STim Blechmann eReg_CRM4,
3102bec490STim Blechmann eReg_CRM5,
3202bec490STim Blechmann eReg_CRM6,
3302bec490STim Blechmann eReg_CRM7,
3402bec490STim Blechmann eReg_CRM8,
3502bec490STim Blechmann eReg_CRM9,
3602bec490STim Blechmann eReg_CRM10,
3702bec490STim Blechmann eReg_CRM11,
3802bec490STim Blechmann eReg_CRM12,
3902bec490STim Blechmann
4002bec490STim Blechmann eReg_ICR,
4102bec490STim Blechmann eReg_CVR,
4202bec490STim Blechmann eReg_ISR,
4302bec490STim Blechmann eReg_RXHTXH,
4402bec490STim Blechmann eReg_RXMTXM,
4502bec490STim Blechmann eReg_RHLTXL,
4602bec490STim Blechmann eReg_RESETDSP,
4702bec490STim Blechmann
4802bec490STim Blechmann eReg_CSUF,
4902bec490STim Blechmann eReg_CSES,
5002bec490STim Blechmann eReg_CRESMSB,
5102bec490STim Blechmann eReg_CRESLSB,
5202bec490STim Blechmann eReg_ADMACESMSB,
5302bec490STim Blechmann eReg_ADMACESLSB,
5402bec490STim Blechmann eReg_CONFES,
5502bec490STim Blechmann
5602bec490STim Blechmann eMaxPortLx
5702bec490STim Blechmann };
5802bec490STim Blechmann
5902bec490STim Blechmann unsigned long lx_dsp_reg_read(struct lx6464es *chip, int port);
6002bec490STim Blechmann void lx_dsp_reg_write(struct lx6464es *chip, int port, unsigned data);
6102bec490STim Blechmann
6202bec490STim Blechmann /* plx register access */
6302bec490STim Blechmann enum {
6402bec490STim Blechmann ePLX_PCICR,
6502bec490STim Blechmann
6602bec490STim Blechmann ePLX_MBOX0,
6702bec490STim Blechmann ePLX_MBOX1,
6802bec490STim Blechmann ePLX_MBOX2,
6902bec490STim Blechmann ePLX_MBOX3,
7002bec490STim Blechmann ePLX_MBOX4,
7102bec490STim Blechmann ePLX_MBOX5,
7202bec490STim Blechmann ePLX_MBOX6,
7302bec490STim Blechmann ePLX_MBOX7,
7402bec490STim Blechmann
7502bec490STim Blechmann ePLX_L2PCIDB,
7602bec490STim Blechmann ePLX_IRQCS,
7702bec490STim Blechmann ePLX_CHIPSC,
7802bec490STim Blechmann
7902bec490STim Blechmann eMaxPort
8002bec490STim Blechmann };
8102bec490STim Blechmann
8202bec490STim Blechmann unsigned long lx_plx_reg_read(struct lx6464es *chip, int port);
8302bec490STim Blechmann void lx_plx_reg_write(struct lx6464es *chip, int port, u32 data);
8402bec490STim Blechmann
8502bec490STim Blechmann /* rhm */
8602bec490STim Blechmann struct lx_rmh {
8702bec490STim Blechmann u16 cmd_len; /* length of the command to send (WORDs) */
8802bec490STim Blechmann u16 stat_len; /* length of the status received (WORDs) */
8902bec490STim Blechmann u16 dsp_stat; /* status type, RMP_SSIZE_XXX */
9002bec490STim Blechmann u16 cmd_idx; /* index of the command */
9102bec490STim Blechmann u32 cmd[REG_CRM_NUMBER];
9202bec490STim Blechmann u32 stat[REG_CRM_NUMBER];
9302bec490STim Blechmann };
9402bec490STim Blechmann
9502bec490STim Blechmann
9602bec490STim Blechmann /* low-level dsp access */
97e23e7a14SBill Pemberton int lx_dsp_get_version(struct lx6464es *chip, u32 *rdsp_version);
9802bec490STim Blechmann int lx_dsp_get_clock_frequency(struct lx6464es *chip, u32 *rfreq);
9902bec490STim Blechmann int lx_dsp_set_granularity(struct lx6464es *chip, u32 gran);
10002bec490STim Blechmann int lx_dsp_read_async_events(struct lx6464es *chip, u32 *data);
10180b52490STim Blechmann int lx_dsp_get_mac(struct lx6464es *chip);
10202bec490STim Blechmann
10302bec490STim Blechmann
10402bec490STim Blechmann /* low-level pipe handling */
10502bec490STim Blechmann int lx_pipe_allocate(struct lx6464es *chip, u32 pipe, int is_capture,
10602bec490STim Blechmann int channels);
10702bec490STim Blechmann int lx_pipe_release(struct lx6464es *chip, u32 pipe, int is_capture);
10802bec490STim Blechmann int lx_pipe_sample_count(struct lx6464es *chip, u32 pipe, int is_capture,
10902bec490STim Blechmann u64 *rsample_count);
11002bec490STim Blechmann int lx_pipe_state(struct lx6464es *chip, u32 pipe, int is_capture, u16 *rstate);
11102bec490STim Blechmann int lx_pipe_stop(struct lx6464es *chip, u32 pipe, int is_capture);
11202bec490STim Blechmann int lx_pipe_start(struct lx6464es *chip, u32 pipe, int is_capture);
11302bec490STim Blechmann int lx_pipe_pause(struct lx6464es *chip, u32 pipe, int is_capture);
11402bec490STim Blechmann
11502bec490STim Blechmann int lx_pipe_wait_for_start(struct lx6464es *chip, u32 pipe, int is_capture);
11602bec490STim Blechmann int lx_pipe_wait_for_idle(struct lx6464es *chip, u32 pipe, int is_capture);
11702bec490STim Blechmann
11802bec490STim Blechmann /* low-level stream handling */
11902bec490STim Blechmann int lx_stream_set_format(struct lx6464es *chip, struct snd_pcm_runtime *runtime,
12002bec490STim Blechmann u32 pipe, int is_capture);
12102bec490STim Blechmann int lx_stream_state(struct lx6464es *chip, u32 pipe, int is_capture,
12202bec490STim Blechmann int *rstate);
12302bec490STim Blechmann int lx_stream_sample_position(struct lx6464es *chip, u32 pipe, int is_capture,
12402bec490STim Blechmann u64 *r_bytepos);
12502bec490STim Blechmann
12602bec490STim Blechmann int lx_stream_set_state(struct lx6464es *chip, u32 pipe,
12702bec490STim Blechmann int is_capture, enum stream_state_t state);
12802bec490STim Blechmann
lx_stream_start(struct lx6464es * chip,u32 pipe,int is_capture)12902bec490STim Blechmann static inline int lx_stream_start(struct lx6464es *chip, u32 pipe,
13002bec490STim Blechmann int is_capture)
13102bec490STim Blechmann {
13202bec490STim Blechmann snd_printdd("->lx_stream_start\n");
13302bec490STim Blechmann return lx_stream_set_state(chip, pipe, is_capture, SSTATE_RUN);
13402bec490STim Blechmann }
13502bec490STim Blechmann
lx_stream_pause(struct lx6464es * chip,u32 pipe,int is_capture)13602bec490STim Blechmann static inline int lx_stream_pause(struct lx6464es *chip, u32 pipe,
13702bec490STim Blechmann int is_capture)
13802bec490STim Blechmann {
13902bec490STim Blechmann snd_printdd("->lx_stream_pause\n");
14002bec490STim Blechmann return lx_stream_set_state(chip, pipe, is_capture, SSTATE_PAUSE);
14102bec490STim Blechmann }
14202bec490STim Blechmann
lx_stream_stop(struct lx6464es * chip,u32 pipe,int is_capture)14302bec490STim Blechmann static inline int lx_stream_stop(struct lx6464es *chip, u32 pipe,
14402bec490STim Blechmann int is_capture)
14502bec490STim Blechmann {
14602bec490STim Blechmann snd_printdd("->lx_stream_stop\n");
14702bec490STim Blechmann return lx_stream_set_state(chip, pipe, is_capture, SSTATE_STOP);
14802bec490STim Blechmann }
14902bec490STim Blechmann
15002bec490STim Blechmann /* low-level buffer handling */
15102bec490STim Blechmann int lx_buffer_ask(struct lx6464es *chip, u32 pipe, int is_capture,
15202bec490STim Blechmann u32 *r_needed, u32 *r_freed, u32 *size_array);
15302bec490STim Blechmann int lx_buffer_give(struct lx6464es *chip, u32 pipe, int is_capture,
15402bec490STim Blechmann u32 buffer_size, u32 buf_address_lo, u32 buf_address_hi,
15502bec490STim Blechmann u32 *r_buffer_index);
15602bec490STim Blechmann int lx_buffer_free(struct lx6464es *chip, u32 pipe, int is_capture,
15702bec490STim Blechmann u32 *r_buffer_size);
15802bec490STim Blechmann int lx_buffer_cancel(struct lx6464es *chip, u32 pipe, int is_capture,
15902bec490STim Blechmann u32 buffer_index);
16002bec490STim Blechmann
16102bec490STim Blechmann /* low-level gain/peak handling */
16202bec490STim Blechmann int lx_level_unmute(struct lx6464es *chip, int is_capture, int unmute);
16302bec490STim Blechmann int lx_level_peaks(struct lx6464es *chip, int is_capture, int channels,
16402bec490STim Blechmann u32 *r_levels);
16502bec490STim Blechmann
16602bec490STim Blechmann
16702bec490STim Blechmann /* interrupt handling */
16802bec490STim Blechmann irqreturn_t lx_interrupt(int irq, void *dev_id);
1696336c20cSTakashi Iwai irqreturn_t lx_threaded_irq(int irq, void *dev_id);
17002bec490STim Blechmann void lx_irq_enable(struct lx6464es *chip);
17102bec490STim Blechmann void lx_irq_disable(struct lx6464es *chip);
17202bec490STim Blechmann
17302bec490STim Blechmann
17402bec490STim Blechmann /* Stream Format Header Defines (for LIN and IEEE754) */
17502bec490STim Blechmann #define HEADER_FMT_BASE HEADER_FMT_BASE_LIN
17602bec490STim Blechmann #define HEADER_FMT_BASE_LIN 0xFED00000
17702bec490STim Blechmann #define HEADER_FMT_BASE_FLOAT 0xFAD00000
17802bec490STim Blechmann #define HEADER_FMT_MONO 0x00000080 /* bit 23 in header_lo. WARNING: old
17902bec490STim Blechmann * bit 22 is ignored in float
18002bec490STim Blechmann * format */
18102bec490STim Blechmann #define HEADER_FMT_INTEL 0x00008000
18202bec490STim Blechmann #define HEADER_FMT_16BITS 0x00002000
18302bec490STim Blechmann #define HEADER_FMT_24BITS 0x00004000
18402bec490STim Blechmann #define HEADER_FMT_UPTO11 0x00000200 /* frequency is less or equ. to 11k.
18502bec490STim Blechmann * */
18602bec490STim Blechmann #define HEADER_FMT_UPTO32 0x00000100 /* frequency is over 11k and less
18702bec490STim Blechmann * then 32k.*/
18802bec490STim Blechmann
18902bec490STim Blechmann
19002bec490STim Blechmann #define BIT_FMP_HEADER 23
19102bec490STim Blechmann #define BIT_FMP_SD 22
19202bec490STim Blechmann #define BIT_FMP_MULTICHANNEL 19
19302bec490STim Blechmann
19402bec490STim Blechmann #define START_STATE 1
19502bec490STim Blechmann #define PAUSE_STATE 0
19602bec490STim Blechmann
19702bec490STim Blechmann
19802bec490STim Blechmann
19902bec490STim Blechmann
20002bec490STim Blechmann
20102bec490STim Blechmann /* from PcxAll_e.h */
20202bec490STim Blechmann /* Start/Pause condition for pipes (PCXStartPipe, PCXPausePipe) */
20302bec490STim Blechmann #define START_PAUSE_IMMEDIATE 0
20402bec490STim Blechmann #define START_PAUSE_ON_SYNCHRO 1
20502bec490STim Blechmann #define START_PAUSE_ON_TIME_CODE 2
20602bec490STim Blechmann
20702bec490STim Blechmann
20802bec490STim Blechmann /* Pipe / Stream state */
20902bec490STim Blechmann #define START_STATE 1
21002bec490STim Blechmann #define PAUSE_STATE 0
21102bec490STim Blechmann
unpack_pointer(dma_addr_t ptr,u32 * r_low,u32 * r_high)21202bec490STim Blechmann static inline void unpack_pointer(dma_addr_t ptr, u32 *r_low, u32 *r_high)
21302bec490STim Blechmann {
21402bec490STim Blechmann *r_low = (u32)(ptr & 0xffffffff);
21502bec490STim Blechmann #if BITS_PER_LONG == 32
21602bec490STim Blechmann *r_high = 0;
21702bec490STim Blechmann #else
21802bec490STim Blechmann *r_high = (u32)((u64)ptr>>32);
21902bec490STim Blechmann #endif
22002bec490STim Blechmann }
22102bec490STim Blechmann
22202bec490STim Blechmann #endif /* LX_CORE_H */
223