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 ctatc.h 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * @Brief 88c2ecf20Sopenharmony_ci * This file contains the definition of the device resource management object. 98c2ecf20Sopenharmony_ci * 108c2ecf20Sopenharmony_ci * @Author Liu Chun 118c2ecf20Sopenharmony_ci * @Date Mar 28 2008 128c2ecf20Sopenharmony_ci */ 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#ifndef CTATC_H 158c2ecf20Sopenharmony_ci#define CTATC_H 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#include <linux/types.h> 188c2ecf20Sopenharmony_ci#include <linux/mutex.h> 198c2ecf20Sopenharmony_ci#include <linux/pci.h> 208c2ecf20Sopenharmony_ci#include <linux/timer.h> 218c2ecf20Sopenharmony_ci#include <sound/core.h> 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci#include "ctvmem.h" 248c2ecf20Sopenharmony_ci#include "cthardware.h" 258c2ecf20Sopenharmony_ci#include "ctresource.h" 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_cienum CTALSADEVS { /* Types of alsa devices */ 288c2ecf20Sopenharmony_ci FRONT, 298c2ecf20Sopenharmony_ci SURROUND, 308c2ecf20Sopenharmony_ci CLFE, 318c2ecf20Sopenharmony_ci SIDE, 328c2ecf20Sopenharmony_ci IEC958, 338c2ecf20Sopenharmony_ci MIXER, 348c2ecf20Sopenharmony_ci NUM_CTALSADEVS /* This should always be the last */ 358c2ecf20Sopenharmony_ci}; 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_cistruct ct_atc_chip_sub_details { 388c2ecf20Sopenharmony_ci u16 subsys; 398c2ecf20Sopenharmony_ci const char *nm_model; 408c2ecf20Sopenharmony_ci}; 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_cistruct ct_atc_chip_details { 438c2ecf20Sopenharmony_ci u16 vendor; 448c2ecf20Sopenharmony_ci u16 device; 458c2ecf20Sopenharmony_ci const struct ct_atc_chip_sub_details *sub_details; 468c2ecf20Sopenharmony_ci const char *nm_card; 478c2ecf20Sopenharmony_ci}; 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_cistruct ct_atc; 508c2ecf20Sopenharmony_cistruct ct_timer; 518c2ecf20Sopenharmony_cistruct ct_timer_instance; 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci/* alsa pcm stream descriptor */ 548c2ecf20Sopenharmony_cistruct ct_atc_pcm { 558c2ecf20Sopenharmony_ci struct snd_pcm_substream *substream; 568c2ecf20Sopenharmony_ci void (*interrupt)(struct ct_atc_pcm *apcm); 578c2ecf20Sopenharmony_ci struct ct_timer_instance *timer; 588c2ecf20Sopenharmony_ci unsigned int started:1; 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci /* Only mono and interleaved modes are supported now. */ 618c2ecf20Sopenharmony_ci struct ct_vm_block *vm_block; 628c2ecf20Sopenharmony_ci void *src; /* SRC for interacting with host memory */ 638c2ecf20Sopenharmony_ci void **srccs; /* SRCs for sample rate conversion */ 648c2ecf20Sopenharmony_ci void **srcimps; /* SRC Input Mappers */ 658c2ecf20Sopenharmony_ci void **amixers; /* AMIXERs for routing converted data */ 668c2ecf20Sopenharmony_ci void *mono; /* A SUM resource for mixing chs to one */ 678c2ecf20Sopenharmony_ci unsigned char n_srcc; /* Number of converting SRCs */ 688c2ecf20Sopenharmony_ci unsigned char n_srcimp; /* Number of SRC Input Mappers */ 698c2ecf20Sopenharmony_ci unsigned char n_amixer; /* Number of AMIXERs */ 708c2ecf20Sopenharmony_ci}; 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci/* Chip resource management object */ 738c2ecf20Sopenharmony_cistruct ct_atc { 748c2ecf20Sopenharmony_ci struct pci_dev *pci; 758c2ecf20Sopenharmony_ci struct snd_card *card; 768c2ecf20Sopenharmony_ci unsigned int rsr; /* reference sample rate in Hz */ 778c2ecf20Sopenharmony_ci unsigned int msr; /* master sample rate in rsr */ 788c2ecf20Sopenharmony_ci unsigned int pll_rate; /* current rate of Phase Lock Loop */ 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci int chip_type; 818c2ecf20Sopenharmony_ci int model; 828c2ecf20Sopenharmony_ci const char *chip_name; 838c2ecf20Sopenharmony_ci const char *model_name; 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci struct ct_vm *vm; /* device virtual memory manager for this card */ 868c2ecf20Sopenharmony_ci int (*map_audio_buffer)(struct ct_atc *atc, struct ct_atc_pcm *apcm); 878c2ecf20Sopenharmony_ci void (*unmap_audio_buffer)(struct ct_atc *atc, struct ct_atc_pcm *apcm); 888c2ecf20Sopenharmony_ci unsigned long (*get_ptp_phys)(struct ct_atc *atc, int index); 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci struct mutex atc_mutex; 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci int (*pcm_playback_prepare)(struct ct_atc *atc, 938c2ecf20Sopenharmony_ci struct ct_atc_pcm *apcm); 948c2ecf20Sopenharmony_ci int (*pcm_playback_start)(struct ct_atc *atc, struct ct_atc_pcm *apcm); 958c2ecf20Sopenharmony_ci int (*pcm_playback_stop)(struct ct_atc *atc, struct ct_atc_pcm *apcm); 968c2ecf20Sopenharmony_ci int (*pcm_playback_position)(struct ct_atc *atc, 978c2ecf20Sopenharmony_ci struct ct_atc_pcm *apcm); 988c2ecf20Sopenharmony_ci int (*spdif_passthru_playback_prepare)(struct ct_atc *atc, 998c2ecf20Sopenharmony_ci struct ct_atc_pcm *apcm); 1008c2ecf20Sopenharmony_ci int (*pcm_capture_prepare)(struct ct_atc *atc, struct ct_atc_pcm *apcm); 1018c2ecf20Sopenharmony_ci int (*pcm_capture_start)(struct ct_atc *atc, struct ct_atc_pcm *apcm); 1028c2ecf20Sopenharmony_ci int (*pcm_capture_stop)(struct ct_atc *atc, struct ct_atc_pcm *apcm); 1038c2ecf20Sopenharmony_ci int (*pcm_capture_position)(struct ct_atc *atc, 1048c2ecf20Sopenharmony_ci struct ct_atc_pcm *apcm); 1058c2ecf20Sopenharmony_ci int (*pcm_release_resources)(struct ct_atc *atc, 1068c2ecf20Sopenharmony_ci struct ct_atc_pcm *apcm); 1078c2ecf20Sopenharmony_ci int (*select_line_in)(struct ct_atc *atc); 1088c2ecf20Sopenharmony_ci int (*select_mic_in)(struct ct_atc *atc); 1098c2ecf20Sopenharmony_ci int (*select_digit_io)(struct ct_atc *atc); 1108c2ecf20Sopenharmony_ci int (*line_front_unmute)(struct ct_atc *atc, unsigned char state); 1118c2ecf20Sopenharmony_ci int (*line_surround_unmute)(struct ct_atc *atc, unsigned char state); 1128c2ecf20Sopenharmony_ci int (*line_clfe_unmute)(struct ct_atc *atc, unsigned char state); 1138c2ecf20Sopenharmony_ci int (*line_rear_unmute)(struct ct_atc *atc, unsigned char state); 1148c2ecf20Sopenharmony_ci int (*line_in_unmute)(struct ct_atc *atc, unsigned char state); 1158c2ecf20Sopenharmony_ci int (*mic_unmute)(struct ct_atc *atc, unsigned char state); 1168c2ecf20Sopenharmony_ci int (*spdif_out_unmute)(struct ct_atc *atc, unsigned char state); 1178c2ecf20Sopenharmony_ci int (*spdif_in_unmute)(struct ct_atc *atc, unsigned char state); 1188c2ecf20Sopenharmony_ci int (*spdif_out_get_status)(struct ct_atc *atc, unsigned int *status); 1198c2ecf20Sopenharmony_ci int (*spdif_out_set_status)(struct ct_atc *atc, unsigned int status); 1208c2ecf20Sopenharmony_ci int (*spdif_out_passthru)(struct ct_atc *atc, unsigned char state); 1218c2ecf20Sopenharmony_ci struct capabilities (*capabilities)(struct ct_atc *atc); 1228c2ecf20Sopenharmony_ci int (*output_switch_get)(struct ct_atc *atc); 1238c2ecf20Sopenharmony_ci int (*output_switch_put)(struct ct_atc *atc, int position); 1248c2ecf20Sopenharmony_ci int (*mic_source_switch_get)(struct ct_atc *atc); 1258c2ecf20Sopenharmony_ci int (*mic_source_switch_put)(struct ct_atc *atc, int position); 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci /* Don't touch! Used for internal object. */ 1288c2ecf20Sopenharmony_ci void *rsc_mgrs[NUM_RSCTYP]; /* chip resource managers */ 1298c2ecf20Sopenharmony_ci void *mixer; /* internal mixer object */ 1308c2ecf20Sopenharmony_ci struct hw *hw; /* chip specific hardware access object */ 1318c2ecf20Sopenharmony_ci void **daios; /* digital audio io resources */ 1328c2ecf20Sopenharmony_ci void **pcm; /* SUMs for collecting all pcm stream */ 1338c2ecf20Sopenharmony_ci void **srcs; /* Sample Rate Converters for input signal */ 1348c2ecf20Sopenharmony_ci void **srcimps; /* input mappers for SRCs */ 1358c2ecf20Sopenharmony_ci unsigned char n_daio; 1368c2ecf20Sopenharmony_ci unsigned char n_src; 1378c2ecf20Sopenharmony_ci unsigned char n_srcimp; 1388c2ecf20Sopenharmony_ci unsigned char n_pcm; 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ci struct ct_timer *timer; 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_ci#ifdef CONFIG_PM_SLEEP 1438c2ecf20Sopenharmony_ci int (*suspend)(struct ct_atc *atc); 1448c2ecf20Sopenharmony_ci int (*resume)(struct ct_atc *atc); 1458c2ecf20Sopenharmony_ci#define NUM_PCMS (NUM_CTALSADEVS - 1) 1468c2ecf20Sopenharmony_ci struct snd_pcm *pcms[NUM_PCMS]; 1478c2ecf20Sopenharmony_ci#endif 1488c2ecf20Sopenharmony_ci}; 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_ciint ct_atc_create(struct snd_card *card, struct pci_dev *pci, 1528c2ecf20Sopenharmony_ci unsigned int rsr, unsigned int msr, int chip_type, 1538c2ecf20Sopenharmony_ci unsigned int subsysid, struct ct_atc **ratc); 1548c2ecf20Sopenharmony_ciint ct_atc_create_alsa_devs(struct ct_atc *atc); 1558c2ecf20Sopenharmony_ci 1568c2ecf20Sopenharmony_ci#endif /* CTATC_H */ 157