162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (C) 2008, Creative Technology Ltd. All Rights Reserved.
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * @File	cthardware.h
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci * @Brief
862306a36Sopenharmony_ci * This file contains the definition of hardware access methord.
962306a36Sopenharmony_ci *
1062306a36Sopenharmony_ci * @Author	Liu Chun
1162306a36Sopenharmony_ci * @Date 	May 13 2008
1262306a36Sopenharmony_ci */
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci#ifndef CTHARDWARE_H
1562306a36Sopenharmony_ci#define CTHARDWARE_H
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ci#include <linux/types.h>
1862306a36Sopenharmony_ci#include <linux/pci.h>
1962306a36Sopenharmony_ci#include <sound/core.h>
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_cienum CHIPTYP {
2262306a36Sopenharmony_ci	ATC20K1,
2362306a36Sopenharmony_ci	ATC20K2,
2462306a36Sopenharmony_ci	ATCNONE
2562306a36Sopenharmony_ci};
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_cienum CTCARDS {
2862306a36Sopenharmony_ci	/* 20k1 models */
2962306a36Sopenharmony_ci	CTSB046X,
3062306a36Sopenharmony_ci	CT20K1_MODEL_FIRST = CTSB046X,
3162306a36Sopenharmony_ci	CTSB055X,
3262306a36Sopenharmony_ci	CTSB073X,
3362306a36Sopenharmony_ci	CTUAA,
3462306a36Sopenharmony_ci	CT20K1_UNKNOWN,
3562306a36Sopenharmony_ci	/* 20k2 models */
3662306a36Sopenharmony_ci	CTSB0760,
3762306a36Sopenharmony_ci	CT20K2_MODEL_FIRST = CTSB0760,
3862306a36Sopenharmony_ci	CTHENDRIX,
3962306a36Sopenharmony_ci	CTSB0880,
4062306a36Sopenharmony_ci	CTSB1270,
4162306a36Sopenharmony_ci	CT20K2_UNKNOWN,
4262306a36Sopenharmony_ci	NUM_CTCARDS		/* This should always be the last */
4362306a36Sopenharmony_ci};
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_ci/* Type of input source for ADC */
4662306a36Sopenharmony_cienum ADCSRC{
4762306a36Sopenharmony_ci	ADC_MICIN,
4862306a36Sopenharmony_ci	ADC_LINEIN,
4962306a36Sopenharmony_ci	ADC_VIDEO,
5062306a36Sopenharmony_ci	ADC_AUX,
5162306a36Sopenharmony_ci	ADC_NONE	/* Switch to digital input */
5262306a36Sopenharmony_ci};
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_cistruct card_conf {
5562306a36Sopenharmony_ci	/* device virtual mem page table page physical addr
5662306a36Sopenharmony_ci	 * (supporting one page table page now) */
5762306a36Sopenharmony_ci	unsigned long vm_pgt_phys;
5862306a36Sopenharmony_ci	unsigned int rsr;	/* reference sample rate in Hzs*/
5962306a36Sopenharmony_ci	unsigned int msr;	/* master sample rate in rsrs */
6062306a36Sopenharmony_ci};
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_cistruct capabilities {
6362306a36Sopenharmony_ci	unsigned int digit_io_switch:1;
6462306a36Sopenharmony_ci	unsigned int dedicated_mic:1;
6562306a36Sopenharmony_ci	unsigned int output_switch:1;
6662306a36Sopenharmony_ci	unsigned int mic_source_switch:1;
6762306a36Sopenharmony_ci};
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_cistruct hw {
7062306a36Sopenharmony_ci	int (*card_init)(struct hw *hw, struct card_conf *info);
7162306a36Sopenharmony_ci	int (*card_stop)(struct hw *hw);
7262306a36Sopenharmony_ci	int (*pll_init)(struct hw *hw, unsigned int rsr);
7362306a36Sopenharmony_ci#ifdef CONFIG_PM_SLEEP
7462306a36Sopenharmony_ci	int (*suspend)(struct hw *hw);
7562306a36Sopenharmony_ci	int (*resume)(struct hw *hw, struct card_conf *info);
7662306a36Sopenharmony_ci#endif
7762306a36Sopenharmony_ci	int (*is_adc_source_selected)(struct hw *hw, enum ADCSRC source);
7862306a36Sopenharmony_ci	int (*select_adc_source)(struct hw *hw, enum ADCSRC source);
7962306a36Sopenharmony_ci	struct capabilities (*capabilities)(struct hw *hw);
8062306a36Sopenharmony_ci	int (*output_switch_get)(struct hw *hw);
8162306a36Sopenharmony_ci	int (*output_switch_put)(struct hw *hw, int position);
8262306a36Sopenharmony_ci	int (*mic_source_switch_get)(struct hw *hw);
8362306a36Sopenharmony_ci	int (*mic_source_switch_put)(struct hw *hw, int position);
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_ci	/* SRC operations */
8662306a36Sopenharmony_ci	int (*src_rsc_get_ctrl_blk)(void **rblk);
8762306a36Sopenharmony_ci	int (*src_rsc_put_ctrl_blk)(void *blk);
8862306a36Sopenharmony_ci	int (*src_set_state)(void *blk, unsigned int state);
8962306a36Sopenharmony_ci	int (*src_set_bm)(void *blk, unsigned int bm);
9062306a36Sopenharmony_ci	int (*src_set_rsr)(void *blk, unsigned int rsr);
9162306a36Sopenharmony_ci	int (*src_set_sf)(void *blk, unsigned int sf);
9262306a36Sopenharmony_ci	int (*src_set_wr)(void *blk, unsigned int wr);
9362306a36Sopenharmony_ci	int (*src_set_pm)(void *blk, unsigned int pm);
9462306a36Sopenharmony_ci	int (*src_set_rom)(void *blk, unsigned int rom);
9562306a36Sopenharmony_ci	int (*src_set_vo)(void *blk, unsigned int vo);
9662306a36Sopenharmony_ci	int (*src_set_st)(void *blk, unsigned int st);
9762306a36Sopenharmony_ci	int (*src_set_ie)(void *blk, unsigned int ie);
9862306a36Sopenharmony_ci	int (*src_set_ilsz)(void *blk, unsigned int ilsz);
9962306a36Sopenharmony_ci	int (*src_set_bp)(void *blk, unsigned int bp);
10062306a36Sopenharmony_ci	int (*src_set_cisz)(void *blk, unsigned int cisz);
10162306a36Sopenharmony_ci	int (*src_set_ca)(void *blk, unsigned int ca);
10262306a36Sopenharmony_ci	int (*src_set_sa)(void *blk, unsigned int sa);
10362306a36Sopenharmony_ci	int (*src_set_la)(void *blk, unsigned int la);
10462306a36Sopenharmony_ci	int (*src_set_pitch)(void *blk, unsigned int pitch);
10562306a36Sopenharmony_ci	int (*src_set_clear_zbufs)(void *blk, unsigned int clear);
10662306a36Sopenharmony_ci	int (*src_set_dirty)(void *blk, unsigned int flags);
10762306a36Sopenharmony_ci	int (*src_set_dirty_all)(void *blk);
10862306a36Sopenharmony_ci	int (*src_commit_write)(struct hw *hw, unsigned int idx, void *blk);
10962306a36Sopenharmony_ci	int (*src_get_ca)(struct hw *hw, unsigned int idx, void *blk);
11062306a36Sopenharmony_ci	unsigned int (*src_get_dirty)(void *blk);
11162306a36Sopenharmony_ci	unsigned int (*src_dirty_conj_mask)(void);
11262306a36Sopenharmony_ci	int (*src_mgr_get_ctrl_blk)(void **rblk);
11362306a36Sopenharmony_ci	int (*src_mgr_put_ctrl_blk)(void *blk);
11462306a36Sopenharmony_ci	/* syncly enable src @idx */
11562306a36Sopenharmony_ci	int (*src_mgr_enbs_src)(void *blk, unsigned int idx);
11662306a36Sopenharmony_ci	/* enable src @idx */
11762306a36Sopenharmony_ci	int (*src_mgr_enb_src)(void *blk, unsigned int idx);
11862306a36Sopenharmony_ci	/* disable src @idx */
11962306a36Sopenharmony_ci	int (*src_mgr_dsb_src)(void *blk, unsigned int idx);
12062306a36Sopenharmony_ci	int (*src_mgr_commit_write)(struct hw *hw, void *blk);
12162306a36Sopenharmony_ci
12262306a36Sopenharmony_ci	/* SRC Input Mapper operations */
12362306a36Sopenharmony_ci	int (*srcimp_mgr_get_ctrl_blk)(void **rblk);
12462306a36Sopenharmony_ci	int (*srcimp_mgr_put_ctrl_blk)(void *blk);
12562306a36Sopenharmony_ci	int (*srcimp_mgr_set_imaparc)(void *blk, unsigned int slot);
12662306a36Sopenharmony_ci	int (*srcimp_mgr_set_imapuser)(void *blk, unsigned int user);
12762306a36Sopenharmony_ci	int (*srcimp_mgr_set_imapnxt)(void *blk, unsigned int next);
12862306a36Sopenharmony_ci	int (*srcimp_mgr_set_imapaddr)(void *blk, unsigned int addr);
12962306a36Sopenharmony_ci	int (*srcimp_mgr_commit_write)(struct hw *hw, void *blk);
13062306a36Sopenharmony_ci
13162306a36Sopenharmony_ci	/* AMIXER operations */
13262306a36Sopenharmony_ci	int (*amixer_rsc_get_ctrl_blk)(void **rblk);
13362306a36Sopenharmony_ci	int (*amixer_rsc_put_ctrl_blk)(void *blk);
13462306a36Sopenharmony_ci	int (*amixer_mgr_get_ctrl_blk)(void **rblk);
13562306a36Sopenharmony_ci	int (*amixer_mgr_put_ctrl_blk)(void *blk);
13662306a36Sopenharmony_ci	int (*amixer_set_mode)(void *blk, unsigned int mode);
13762306a36Sopenharmony_ci	int (*amixer_set_iv)(void *blk, unsigned int iv);
13862306a36Sopenharmony_ci	int (*amixer_set_x)(void *blk, unsigned int x);
13962306a36Sopenharmony_ci	int (*amixer_set_y)(void *blk, unsigned int y);
14062306a36Sopenharmony_ci	int (*amixer_set_sadr)(void *blk, unsigned int sadr);
14162306a36Sopenharmony_ci	int (*amixer_set_se)(void *blk, unsigned int se);
14262306a36Sopenharmony_ci	int (*amixer_set_dirty)(void *blk, unsigned int flags);
14362306a36Sopenharmony_ci	int (*amixer_set_dirty_all)(void *blk);
14462306a36Sopenharmony_ci	int (*amixer_commit_write)(struct hw *hw, unsigned int idx, void *blk);
14562306a36Sopenharmony_ci	int (*amixer_get_y)(void *blk);
14662306a36Sopenharmony_ci	unsigned int (*amixer_get_dirty)(void *blk);
14762306a36Sopenharmony_ci
14862306a36Sopenharmony_ci	/* DAIO operations */
14962306a36Sopenharmony_ci	int (*dai_get_ctrl_blk)(void **rblk);
15062306a36Sopenharmony_ci	int (*dai_put_ctrl_blk)(void *blk);
15162306a36Sopenharmony_ci	int (*dai_srt_set_srco)(void *blk, unsigned int src);
15262306a36Sopenharmony_ci	int (*dai_srt_set_srcm)(void *blk, unsigned int src);
15362306a36Sopenharmony_ci	int (*dai_srt_set_rsr)(void *blk, unsigned int rsr);
15462306a36Sopenharmony_ci	int (*dai_srt_set_drat)(void *blk, unsigned int drat);
15562306a36Sopenharmony_ci	int (*dai_srt_set_ec)(void *blk, unsigned int ec);
15662306a36Sopenharmony_ci	int (*dai_srt_set_et)(void *blk, unsigned int et);
15762306a36Sopenharmony_ci	int (*dai_commit_write)(struct hw *hw, unsigned int idx, void *blk);
15862306a36Sopenharmony_ci	int (*dao_get_ctrl_blk)(void **rblk);
15962306a36Sopenharmony_ci	int (*dao_put_ctrl_blk)(void *blk);
16062306a36Sopenharmony_ci	int (*dao_set_spos)(void *blk, unsigned int spos);
16162306a36Sopenharmony_ci	int (*dao_commit_write)(struct hw *hw, unsigned int idx, void *blk);
16262306a36Sopenharmony_ci	int (*dao_get_spos)(void *blk, unsigned int *spos);
16362306a36Sopenharmony_ci
16462306a36Sopenharmony_ci	int (*daio_mgr_get_ctrl_blk)(struct hw *hw, void **rblk);
16562306a36Sopenharmony_ci	int (*daio_mgr_put_ctrl_blk)(void *blk);
16662306a36Sopenharmony_ci	int (*daio_mgr_enb_dai)(void *blk, unsigned int idx);
16762306a36Sopenharmony_ci	int (*daio_mgr_dsb_dai)(void *blk, unsigned int idx);
16862306a36Sopenharmony_ci	int (*daio_mgr_enb_dao)(void *blk, unsigned int idx);
16962306a36Sopenharmony_ci	int (*daio_mgr_dsb_dao)(void *blk, unsigned int idx);
17062306a36Sopenharmony_ci	int (*daio_mgr_dao_init)(void *blk, unsigned int idx,
17162306a36Sopenharmony_ci						unsigned int conf);
17262306a36Sopenharmony_ci	int (*daio_mgr_set_imaparc)(void *blk, unsigned int slot);
17362306a36Sopenharmony_ci	int (*daio_mgr_set_imapnxt)(void *blk, unsigned int next);
17462306a36Sopenharmony_ci	int (*daio_mgr_set_imapaddr)(void *blk, unsigned int addr);
17562306a36Sopenharmony_ci	int (*daio_mgr_commit_write)(struct hw *hw, void *blk);
17662306a36Sopenharmony_ci
17762306a36Sopenharmony_ci	int (*set_timer_irq)(struct hw *hw, int enable);
17862306a36Sopenharmony_ci	int (*set_timer_tick)(struct hw *hw, unsigned int tick);
17962306a36Sopenharmony_ci	unsigned int (*get_wc)(struct hw *hw);
18062306a36Sopenharmony_ci
18162306a36Sopenharmony_ci	void (*irq_callback)(void *data, unsigned int bit);
18262306a36Sopenharmony_ci	void *irq_callback_data;
18362306a36Sopenharmony_ci
18462306a36Sopenharmony_ci	struct pci_dev *pci;	/* the pci kernel structure of this card */
18562306a36Sopenharmony_ci	struct snd_card *card;	/* pointer to this card */
18662306a36Sopenharmony_ci	int irq;
18762306a36Sopenharmony_ci	unsigned long io_base;
18862306a36Sopenharmony_ci	void __iomem *mem_base;
18962306a36Sopenharmony_ci
19062306a36Sopenharmony_ci	enum CHIPTYP chip_type;
19162306a36Sopenharmony_ci	enum CTCARDS model;
19262306a36Sopenharmony_ci};
19362306a36Sopenharmony_ci
19462306a36Sopenharmony_ciint create_hw_obj(struct pci_dev *pci, enum CHIPTYP chip_type,
19562306a36Sopenharmony_ci		  enum CTCARDS model, struct hw **rhw);
19662306a36Sopenharmony_ciint destroy_hw_obj(struct hw *hw);
19762306a36Sopenharmony_ci
19862306a36Sopenharmony_ciunsigned int get_field(unsigned int data, unsigned int field);
19962306a36Sopenharmony_civoid set_field(unsigned int *data, unsigned int field, unsigned int value);
20062306a36Sopenharmony_ci
20162306a36Sopenharmony_ci/* IRQ bits */
20262306a36Sopenharmony_ci#define	PLL_INT		(1 << 10) /* PLL input-clock out-of-range */
20362306a36Sopenharmony_ci#define FI_INT		(1 << 9)  /* forced interrupt */
20462306a36Sopenharmony_ci#define IT_INT		(1 << 8)  /* timer interrupt */
20562306a36Sopenharmony_ci#define PCI_INT		(1 << 7)  /* PCI bus error pending */
20662306a36Sopenharmony_ci#define URT_INT		(1 << 6)  /* UART Tx/Rx */
20762306a36Sopenharmony_ci#define GPI_INT		(1 << 5)  /* GPI pin */
20862306a36Sopenharmony_ci#define MIX_INT		(1 << 4)  /* mixer parameter segment FIFO channels */
20962306a36Sopenharmony_ci#define DAI_INT		(1 << 3)  /* DAI (SR-tracker or SPDIF-receiver) */
21062306a36Sopenharmony_ci#define TP_INT		(1 << 2)  /* transport priority queue */
21162306a36Sopenharmony_ci#define DSP_INT		(1 << 1)  /* DSP */
21262306a36Sopenharmony_ci#define SRC_INT		(1 << 0)  /* SRC channels */
21362306a36Sopenharmony_ci
21462306a36Sopenharmony_ci#endif /* CTHARDWARE_H */
215