18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/**
38c2ecf20Sopenharmony_ci * Copyright (C) 2008, Creative Technology Ltd. All Rights Reserved.
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * @File	cthardware.h
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * @Brief
88c2ecf20Sopenharmony_ci * This file contains the definition of hardware access methord.
98c2ecf20Sopenharmony_ci *
108c2ecf20Sopenharmony_ci * @Author	Liu Chun
118c2ecf20Sopenharmony_ci * @Date 	May 13 2008
128c2ecf20Sopenharmony_ci */
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#ifndef CTHARDWARE_H
158c2ecf20Sopenharmony_ci#define CTHARDWARE_H
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#include <linux/types.h>
188c2ecf20Sopenharmony_ci#include <linux/pci.h>
198c2ecf20Sopenharmony_ci#include <sound/core.h>
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_cienum CHIPTYP {
228c2ecf20Sopenharmony_ci	ATC20K1,
238c2ecf20Sopenharmony_ci	ATC20K2,
248c2ecf20Sopenharmony_ci	ATCNONE
258c2ecf20Sopenharmony_ci};
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_cienum CTCARDS {
288c2ecf20Sopenharmony_ci	/* 20k1 models */
298c2ecf20Sopenharmony_ci	CTSB046X,
308c2ecf20Sopenharmony_ci	CT20K1_MODEL_FIRST = CTSB046X,
318c2ecf20Sopenharmony_ci	CTSB055X,
328c2ecf20Sopenharmony_ci	CTSB073X,
338c2ecf20Sopenharmony_ci	CTUAA,
348c2ecf20Sopenharmony_ci	CT20K1_UNKNOWN,
358c2ecf20Sopenharmony_ci	/* 20k2 models */
368c2ecf20Sopenharmony_ci	CTSB0760,
378c2ecf20Sopenharmony_ci	CT20K2_MODEL_FIRST = CTSB0760,
388c2ecf20Sopenharmony_ci	CTHENDRIX,
398c2ecf20Sopenharmony_ci	CTSB0880,
408c2ecf20Sopenharmony_ci	CTSB1270,
418c2ecf20Sopenharmony_ci	CT20K2_UNKNOWN,
428c2ecf20Sopenharmony_ci	NUM_CTCARDS		/* This should always be the last */
438c2ecf20Sopenharmony_ci};
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci/* Type of input source for ADC */
468c2ecf20Sopenharmony_cienum ADCSRC{
478c2ecf20Sopenharmony_ci	ADC_MICIN,
488c2ecf20Sopenharmony_ci	ADC_LINEIN,
498c2ecf20Sopenharmony_ci	ADC_VIDEO,
508c2ecf20Sopenharmony_ci	ADC_AUX,
518c2ecf20Sopenharmony_ci	ADC_NONE	/* Switch to digital input */
528c2ecf20Sopenharmony_ci};
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_cistruct card_conf {
558c2ecf20Sopenharmony_ci	/* device virtual mem page table page physical addr
568c2ecf20Sopenharmony_ci	 * (supporting one page table page now) */
578c2ecf20Sopenharmony_ci	unsigned long vm_pgt_phys;
588c2ecf20Sopenharmony_ci	unsigned int rsr;	/* reference sample rate in Hzs*/
598c2ecf20Sopenharmony_ci	unsigned int msr;	/* master sample rate in rsrs */
608c2ecf20Sopenharmony_ci};
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_cistruct capabilities {
638c2ecf20Sopenharmony_ci	unsigned int digit_io_switch:1;
648c2ecf20Sopenharmony_ci	unsigned int dedicated_mic:1;
658c2ecf20Sopenharmony_ci	unsigned int output_switch:1;
668c2ecf20Sopenharmony_ci	unsigned int mic_source_switch:1;
678c2ecf20Sopenharmony_ci};
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_cistruct hw {
708c2ecf20Sopenharmony_ci	int (*card_init)(struct hw *hw, struct card_conf *info);
718c2ecf20Sopenharmony_ci	int (*card_stop)(struct hw *hw);
728c2ecf20Sopenharmony_ci	int (*pll_init)(struct hw *hw, unsigned int rsr);
738c2ecf20Sopenharmony_ci#ifdef CONFIG_PM_SLEEP
748c2ecf20Sopenharmony_ci	int (*suspend)(struct hw *hw);
758c2ecf20Sopenharmony_ci	int (*resume)(struct hw *hw, struct card_conf *info);
768c2ecf20Sopenharmony_ci#endif
778c2ecf20Sopenharmony_ci	int (*is_adc_source_selected)(struct hw *hw, enum ADCSRC source);
788c2ecf20Sopenharmony_ci	int (*select_adc_source)(struct hw *hw, enum ADCSRC source);
798c2ecf20Sopenharmony_ci	struct capabilities (*capabilities)(struct hw *hw);
808c2ecf20Sopenharmony_ci	int (*output_switch_get)(struct hw *hw);
818c2ecf20Sopenharmony_ci	int (*output_switch_put)(struct hw *hw, int position);
828c2ecf20Sopenharmony_ci	int (*mic_source_switch_get)(struct hw *hw);
838c2ecf20Sopenharmony_ci	int (*mic_source_switch_put)(struct hw *hw, int position);
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ci	/* SRC operations */
868c2ecf20Sopenharmony_ci	int (*src_rsc_get_ctrl_blk)(void **rblk);
878c2ecf20Sopenharmony_ci	int (*src_rsc_put_ctrl_blk)(void *blk);
888c2ecf20Sopenharmony_ci	int (*src_set_state)(void *blk, unsigned int state);
898c2ecf20Sopenharmony_ci	int (*src_set_bm)(void *blk, unsigned int bm);
908c2ecf20Sopenharmony_ci	int (*src_set_rsr)(void *blk, unsigned int rsr);
918c2ecf20Sopenharmony_ci	int (*src_set_sf)(void *blk, unsigned int sf);
928c2ecf20Sopenharmony_ci	int (*src_set_wr)(void *blk, unsigned int wr);
938c2ecf20Sopenharmony_ci	int (*src_set_pm)(void *blk, unsigned int pm);
948c2ecf20Sopenharmony_ci	int (*src_set_rom)(void *blk, unsigned int rom);
958c2ecf20Sopenharmony_ci	int (*src_set_vo)(void *blk, unsigned int vo);
968c2ecf20Sopenharmony_ci	int (*src_set_st)(void *blk, unsigned int st);
978c2ecf20Sopenharmony_ci	int (*src_set_ie)(void *blk, unsigned int ie);
988c2ecf20Sopenharmony_ci	int (*src_set_ilsz)(void *blk, unsigned int ilsz);
998c2ecf20Sopenharmony_ci	int (*src_set_bp)(void *blk, unsigned int bp);
1008c2ecf20Sopenharmony_ci	int (*src_set_cisz)(void *blk, unsigned int cisz);
1018c2ecf20Sopenharmony_ci	int (*src_set_ca)(void *blk, unsigned int ca);
1028c2ecf20Sopenharmony_ci	int (*src_set_sa)(void *blk, unsigned int sa);
1038c2ecf20Sopenharmony_ci	int (*src_set_la)(void *blk, unsigned int la);
1048c2ecf20Sopenharmony_ci	int (*src_set_pitch)(void *blk, unsigned int pitch);
1058c2ecf20Sopenharmony_ci	int (*src_set_clear_zbufs)(void *blk, unsigned int clear);
1068c2ecf20Sopenharmony_ci	int (*src_set_dirty)(void *blk, unsigned int flags);
1078c2ecf20Sopenharmony_ci	int (*src_set_dirty_all)(void *blk);
1088c2ecf20Sopenharmony_ci	int (*src_commit_write)(struct hw *hw, unsigned int idx, void *blk);
1098c2ecf20Sopenharmony_ci	int (*src_get_ca)(struct hw *hw, unsigned int idx, void *blk);
1108c2ecf20Sopenharmony_ci	unsigned int (*src_get_dirty)(void *blk);
1118c2ecf20Sopenharmony_ci	unsigned int (*src_dirty_conj_mask)(void);
1128c2ecf20Sopenharmony_ci	int (*src_mgr_get_ctrl_blk)(void **rblk);
1138c2ecf20Sopenharmony_ci	int (*src_mgr_put_ctrl_blk)(void *blk);
1148c2ecf20Sopenharmony_ci	/* syncly enable src @idx */
1158c2ecf20Sopenharmony_ci	int (*src_mgr_enbs_src)(void *blk, unsigned int idx);
1168c2ecf20Sopenharmony_ci	/* enable src @idx */
1178c2ecf20Sopenharmony_ci	int (*src_mgr_enb_src)(void *blk, unsigned int idx);
1188c2ecf20Sopenharmony_ci	/* disable src @idx */
1198c2ecf20Sopenharmony_ci	int (*src_mgr_dsb_src)(void *blk, unsigned int idx);
1208c2ecf20Sopenharmony_ci	int (*src_mgr_commit_write)(struct hw *hw, void *blk);
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_ci	/* SRC Input Mapper operations */
1238c2ecf20Sopenharmony_ci	int (*srcimp_mgr_get_ctrl_blk)(void **rblk);
1248c2ecf20Sopenharmony_ci	int (*srcimp_mgr_put_ctrl_blk)(void *blk);
1258c2ecf20Sopenharmony_ci	int (*srcimp_mgr_set_imaparc)(void *blk, unsigned int slot);
1268c2ecf20Sopenharmony_ci	int (*srcimp_mgr_set_imapuser)(void *blk, unsigned int user);
1278c2ecf20Sopenharmony_ci	int (*srcimp_mgr_set_imapnxt)(void *blk, unsigned int next);
1288c2ecf20Sopenharmony_ci	int (*srcimp_mgr_set_imapaddr)(void *blk, unsigned int addr);
1298c2ecf20Sopenharmony_ci	int (*srcimp_mgr_commit_write)(struct hw *hw, void *blk);
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci	/* AMIXER operations */
1328c2ecf20Sopenharmony_ci	int (*amixer_rsc_get_ctrl_blk)(void **rblk);
1338c2ecf20Sopenharmony_ci	int (*amixer_rsc_put_ctrl_blk)(void *blk);
1348c2ecf20Sopenharmony_ci	int (*amixer_mgr_get_ctrl_blk)(void **rblk);
1358c2ecf20Sopenharmony_ci	int (*amixer_mgr_put_ctrl_blk)(void *blk);
1368c2ecf20Sopenharmony_ci	int (*amixer_set_mode)(void *blk, unsigned int mode);
1378c2ecf20Sopenharmony_ci	int (*amixer_set_iv)(void *blk, unsigned int iv);
1388c2ecf20Sopenharmony_ci	int (*amixer_set_x)(void *blk, unsigned int x);
1398c2ecf20Sopenharmony_ci	int (*amixer_set_y)(void *blk, unsigned int y);
1408c2ecf20Sopenharmony_ci	int (*amixer_set_sadr)(void *blk, unsigned int sadr);
1418c2ecf20Sopenharmony_ci	int (*amixer_set_se)(void *blk, unsigned int se);
1428c2ecf20Sopenharmony_ci	int (*amixer_set_dirty)(void *blk, unsigned int flags);
1438c2ecf20Sopenharmony_ci	int (*amixer_set_dirty_all)(void *blk);
1448c2ecf20Sopenharmony_ci	int (*amixer_commit_write)(struct hw *hw, unsigned int idx, void *blk);
1458c2ecf20Sopenharmony_ci	int (*amixer_get_y)(void *blk);
1468c2ecf20Sopenharmony_ci	unsigned int (*amixer_get_dirty)(void *blk);
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_ci	/* DAIO operations */
1498c2ecf20Sopenharmony_ci	int (*dai_get_ctrl_blk)(void **rblk);
1508c2ecf20Sopenharmony_ci	int (*dai_put_ctrl_blk)(void *blk);
1518c2ecf20Sopenharmony_ci	int (*dai_srt_set_srco)(void *blk, unsigned int src);
1528c2ecf20Sopenharmony_ci	int (*dai_srt_set_srcm)(void *blk, unsigned int src);
1538c2ecf20Sopenharmony_ci	int (*dai_srt_set_rsr)(void *blk, unsigned int rsr);
1548c2ecf20Sopenharmony_ci	int (*dai_srt_set_drat)(void *blk, unsigned int drat);
1558c2ecf20Sopenharmony_ci	int (*dai_srt_set_ec)(void *blk, unsigned int ec);
1568c2ecf20Sopenharmony_ci	int (*dai_srt_set_et)(void *blk, unsigned int et);
1578c2ecf20Sopenharmony_ci	int (*dai_commit_write)(struct hw *hw, unsigned int idx, void *blk);
1588c2ecf20Sopenharmony_ci	int (*dao_get_ctrl_blk)(void **rblk);
1598c2ecf20Sopenharmony_ci	int (*dao_put_ctrl_blk)(void *blk);
1608c2ecf20Sopenharmony_ci	int (*dao_set_spos)(void *blk, unsigned int spos);
1618c2ecf20Sopenharmony_ci	int (*dao_commit_write)(struct hw *hw, unsigned int idx, void *blk);
1628c2ecf20Sopenharmony_ci	int (*dao_get_spos)(void *blk, unsigned int *spos);
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ci	int (*daio_mgr_get_ctrl_blk)(struct hw *hw, void **rblk);
1658c2ecf20Sopenharmony_ci	int (*daio_mgr_put_ctrl_blk)(void *blk);
1668c2ecf20Sopenharmony_ci	int (*daio_mgr_enb_dai)(void *blk, unsigned int idx);
1678c2ecf20Sopenharmony_ci	int (*daio_mgr_dsb_dai)(void *blk, unsigned int idx);
1688c2ecf20Sopenharmony_ci	int (*daio_mgr_enb_dao)(void *blk, unsigned int idx);
1698c2ecf20Sopenharmony_ci	int (*daio_mgr_dsb_dao)(void *blk, unsigned int idx);
1708c2ecf20Sopenharmony_ci	int (*daio_mgr_dao_init)(void *blk, unsigned int idx,
1718c2ecf20Sopenharmony_ci						unsigned int conf);
1728c2ecf20Sopenharmony_ci	int (*daio_mgr_set_imaparc)(void *blk, unsigned int slot);
1738c2ecf20Sopenharmony_ci	int (*daio_mgr_set_imapnxt)(void *blk, unsigned int next);
1748c2ecf20Sopenharmony_ci	int (*daio_mgr_set_imapaddr)(void *blk, unsigned int addr);
1758c2ecf20Sopenharmony_ci	int (*daio_mgr_commit_write)(struct hw *hw, void *blk);
1768c2ecf20Sopenharmony_ci
1778c2ecf20Sopenharmony_ci	int (*set_timer_irq)(struct hw *hw, int enable);
1788c2ecf20Sopenharmony_ci	int (*set_timer_tick)(struct hw *hw, unsigned int tick);
1798c2ecf20Sopenharmony_ci	unsigned int (*get_wc)(struct hw *hw);
1808c2ecf20Sopenharmony_ci
1818c2ecf20Sopenharmony_ci	void (*irq_callback)(void *data, unsigned int bit);
1828c2ecf20Sopenharmony_ci	void *irq_callback_data;
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_ci	struct pci_dev *pci;	/* the pci kernel structure of this card */
1858c2ecf20Sopenharmony_ci	struct snd_card *card;	/* pointer to this card */
1868c2ecf20Sopenharmony_ci	int irq;
1878c2ecf20Sopenharmony_ci	unsigned long io_base;
1888c2ecf20Sopenharmony_ci	void __iomem *mem_base;
1898c2ecf20Sopenharmony_ci
1908c2ecf20Sopenharmony_ci	enum CHIPTYP chip_type;
1918c2ecf20Sopenharmony_ci	enum CTCARDS model;
1928c2ecf20Sopenharmony_ci};
1938c2ecf20Sopenharmony_ci
1948c2ecf20Sopenharmony_ciint create_hw_obj(struct pci_dev *pci, enum CHIPTYP chip_type,
1958c2ecf20Sopenharmony_ci		  enum CTCARDS model, struct hw **rhw);
1968c2ecf20Sopenharmony_ciint destroy_hw_obj(struct hw *hw);
1978c2ecf20Sopenharmony_ci
1988c2ecf20Sopenharmony_ciunsigned int get_field(unsigned int data, unsigned int field);
1998c2ecf20Sopenharmony_civoid set_field(unsigned int *data, unsigned int field, unsigned int value);
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_ci/* IRQ bits */
2028c2ecf20Sopenharmony_ci#define	PLL_INT		(1 << 10) /* PLL input-clock out-of-range */
2038c2ecf20Sopenharmony_ci#define FI_INT		(1 << 9)  /* forced interrupt */
2048c2ecf20Sopenharmony_ci#define IT_INT		(1 << 8)  /* timer interrupt */
2058c2ecf20Sopenharmony_ci#define PCI_INT		(1 << 7)  /* PCI bus error pending */
2068c2ecf20Sopenharmony_ci#define URT_INT		(1 << 6)  /* UART Tx/Rx */
2078c2ecf20Sopenharmony_ci#define GPI_INT		(1 << 5)  /* GPI pin */
2088c2ecf20Sopenharmony_ci#define MIX_INT		(1 << 4)  /* mixer parameter segment FIFO channels */
2098c2ecf20Sopenharmony_ci#define DAI_INT		(1 << 3)  /* DAI (SR-tracker or SPDIF-receiver) */
2108c2ecf20Sopenharmony_ci#define TP_INT		(1 << 2)  /* transport priority queue */
2118c2ecf20Sopenharmony_ci#define DSP_INT		(1 << 1)  /* DSP */
2128c2ecf20Sopenharmony_ci#define SRC_INT		(1 << 0)  /* SRC channels */
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_ci#endif /* CTHARDWARE_H */
215