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	ctsrc.h
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * @Brief
88c2ecf20Sopenharmony_ci * This file contains the definition of the Sample Rate Convertor
98c2ecf20Sopenharmony_ci * resource management object.
108c2ecf20Sopenharmony_ci *
118c2ecf20Sopenharmony_ci * @Author	Liu Chun
128c2ecf20Sopenharmony_ci * @Date 	May 13 2008
138c2ecf20Sopenharmony_ci */
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#ifndef CTSRC_H
168c2ecf20Sopenharmony_ci#define CTSRC_H
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci#include "ctresource.h"
198c2ecf20Sopenharmony_ci#include "ctimap.h"
208c2ecf20Sopenharmony_ci#include <linux/spinlock.h>
218c2ecf20Sopenharmony_ci#include <linux/list.h>
228c2ecf20Sopenharmony_ci#include <sound/core.h>
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci#define SRC_STATE_OFF	0x0
258c2ecf20Sopenharmony_ci#define SRC_STATE_INIT	0x4
268c2ecf20Sopenharmony_ci#define SRC_STATE_RUN	0x5
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci#define SRC_SF_U8	0x0
298c2ecf20Sopenharmony_ci#define SRC_SF_S16	0x1
308c2ecf20Sopenharmony_ci#define SRC_SF_S24	0x2
318c2ecf20Sopenharmony_ci#define SRC_SF_S32	0x3
328c2ecf20Sopenharmony_ci#define SRC_SF_F32	0x4
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci/* Define the descriptor of a src resource */
358c2ecf20Sopenharmony_cienum SRCMODE {
368c2ecf20Sopenharmony_ci	MEMRD,		/* Read data from host memory */
378c2ecf20Sopenharmony_ci	MEMWR,		/* Write data to host memory */
388c2ecf20Sopenharmony_ci	ARCRW,		/* Read from and write to audio ring channel */
398c2ecf20Sopenharmony_ci	NUM_SRCMODES
408c2ecf20Sopenharmony_ci};
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_cistruct src_rsc_ops;
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_cistruct src {
458c2ecf20Sopenharmony_ci	struct rsc rsc; /* Basic resource info */
468c2ecf20Sopenharmony_ci	struct src *intlv; /* Pointer to next interleaved SRC in a series */
478c2ecf20Sopenharmony_ci	const struct src_rsc_ops *ops; /* SRC specific operations */
488c2ecf20Sopenharmony_ci	/* Number of contiguous srcs for interleaved usage */
498c2ecf20Sopenharmony_ci	unsigned char multi;
508c2ecf20Sopenharmony_ci	unsigned char mode; /* Working mode of this SRC resource */
518c2ecf20Sopenharmony_ci};
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_cistruct src_rsc_ops {
548c2ecf20Sopenharmony_ci	int (*set_state)(struct src *src, unsigned int state);
558c2ecf20Sopenharmony_ci	int (*set_bm)(struct src *src, unsigned int bm);
568c2ecf20Sopenharmony_ci	int (*set_sf)(struct src *src, unsigned int sf);
578c2ecf20Sopenharmony_ci	int (*set_pm)(struct src *src, unsigned int pm);
588c2ecf20Sopenharmony_ci	int (*set_rom)(struct src *src, unsigned int rom);
598c2ecf20Sopenharmony_ci	int (*set_vo)(struct src *src, unsigned int vo);
608c2ecf20Sopenharmony_ci	int (*set_st)(struct src *src, unsigned int st);
618c2ecf20Sopenharmony_ci	int (*set_bp)(struct src *src, unsigned int bp);
628c2ecf20Sopenharmony_ci	int (*set_cisz)(struct src *src, unsigned int cisz);
638c2ecf20Sopenharmony_ci	int (*set_ca)(struct src *src, unsigned int ca);
648c2ecf20Sopenharmony_ci	int (*set_sa)(struct src *src, unsigned int sa);
658c2ecf20Sopenharmony_ci	int (*set_la)(struct src *src, unsigned int la);
668c2ecf20Sopenharmony_ci	int (*set_pitch)(struct src *src, unsigned int pitch);
678c2ecf20Sopenharmony_ci	int (*set_clr_zbufs)(struct src *src);
688c2ecf20Sopenharmony_ci	int (*commit_write)(struct src *src);
698c2ecf20Sopenharmony_ci	int (*get_ca)(struct src *src);
708c2ecf20Sopenharmony_ci	int (*init)(struct src *src);
718c2ecf20Sopenharmony_ci	struct src* (*next_interleave)(struct src *src);
728c2ecf20Sopenharmony_ci};
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci/* Define src resource request description info */
758c2ecf20Sopenharmony_cistruct src_desc {
768c2ecf20Sopenharmony_ci	/* Number of contiguous master srcs for interleaved usage */
778c2ecf20Sopenharmony_ci	unsigned char multi;
788c2ecf20Sopenharmony_ci	unsigned char msr;
798c2ecf20Sopenharmony_ci	unsigned char mode; /* Working mode of the requested srcs */
808c2ecf20Sopenharmony_ci};
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci/* Define src manager object */
838c2ecf20Sopenharmony_cistruct src_mgr {
848c2ecf20Sopenharmony_ci	struct rsc_mgr mgr;	/* Basic resource manager info */
858c2ecf20Sopenharmony_ci	struct snd_card *card;	/* pointer to this card */
868c2ecf20Sopenharmony_ci	spinlock_t mgr_lock;
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci	 /* request src resource */
898c2ecf20Sopenharmony_ci	int (*get_src)(struct src_mgr *mgr,
908c2ecf20Sopenharmony_ci		       const struct src_desc *desc, struct src **rsrc);
918c2ecf20Sopenharmony_ci	/* return src resource */
928c2ecf20Sopenharmony_ci	int (*put_src)(struct src_mgr *mgr, struct src *src);
938c2ecf20Sopenharmony_ci	int (*src_enable_s)(struct src_mgr *mgr, struct src *src);
948c2ecf20Sopenharmony_ci	int (*src_enable)(struct src_mgr *mgr, struct src *src);
958c2ecf20Sopenharmony_ci	int (*src_disable)(struct src_mgr *mgr, struct src *src);
968c2ecf20Sopenharmony_ci	int (*commit_write)(struct src_mgr *mgr);
978c2ecf20Sopenharmony_ci};
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci/* Define the descriptor of a SRC Input Mapper resource */
1008c2ecf20Sopenharmony_cistruct srcimp_mgr;
1018c2ecf20Sopenharmony_cistruct srcimp_rsc_ops;
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_cistruct srcimp {
1048c2ecf20Sopenharmony_ci	struct rsc rsc;
1058c2ecf20Sopenharmony_ci	unsigned char idx[8];
1068c2ecf20Sopenharmony_ci	struct imapper *imappers;
1078c2ecf20Sopenharmony_ci	unsigned int mapped; /* A bit-map indicating which conj rsc is mapped */
1088c2ecf20Sopenharmony_ci	struct srcimp_mgr *mgr;
1098c2ecf20Sopenharmony_ci	const struct srcimp_rsc_ops *ops;
1108c2ecf20Sopenharmony_ci};
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_cistruct srcimp_rsc_ops {
1138c2ecf20Sopenharmony_ci	int (*map)(struct srcimp *srcimp, struct src *user, struct rsc *input);
1148c2ecf20Sopenharmony_ci	int (*unmap)(struct srcimp *srcimp);
1158c2ecf20Sopenharmony_ci};
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci/* Define SRCIMP resource request description info */
1188c2ecf20Sopenharmony_cistruct srcimp_desc {
1198c2ecf20Sopenharmony_ci	unsigned int msr;
1208c2ecf20Sopenharmony_ci};
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_cistruct srcimp_mgr {
1238c2ecf20Sopenharmony_ci	struct rsc_mgr mgr;	/* Basic resource manager info */
1248c2ecf20Sopenharmony_ci	struct snd_card *card;	/* pointer to this card */
1258c2ecf20Sopenharmony_ci	spinlock_t mgr_lock;
1268c2ecf20Sopenharmony_ci	spinlock_t imap_lock;
1278c2ecf20Sopenharmony_ci	struct list_head imappers;
1288c2ecf20Sopenharmony_ci	struct imapper *init_imap;
1298c2ecf20Sopenharmony_ci	unsigned int init_imap_added;
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci	 /* request srcimp resource */
1328c2ecf20Sopenharmony_ci	int (*get_srcimp)(struct srcimp_mgr *mgr,
1338c2ecf20Sopenharmony_ci			  const struct srcimp_desc *desc,
1348c2ecf20Sopenharmony_ci			  struct srcimp **rsrcimp);
1358c2ecf20Sopenharmony_ci	/* return srcimp resource */
1368c2ecf20Sopenharmony_ci	int (*put_srcimp)(struct srcimp_mgr *mgr, struct srcimp *srcimp);
1378c2ecf20Sopenharmony_ci	int (*imap_add)(struct srcimp_mgr *mgr, struct imapper *entry);
1388c2ecf20Sopenharmony_ci	int (*imap_delete)(struct srcimp_mgr *mgr, struct imapper *entry);
1398c2ecf20Sopenharmony_ci};
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci/* Constructor and destructor of SRC resource manager */
1428c2ecf20Sopenharmony_ciint src_mgr_create(struct hw *hw, struct src_mgr **rsrc_mgr);
1438c2ecf20Sopenharmony_ciint src_mgr_destroy(struct src_mgr *src_mgr);
1448c2ecf20Sopenharmony_ci/* Constructor and destructor of SRCIMP resource manager */
1458c2ecf20Sopenharmony_ciint srcimp_mgr_create(struct hw *hw, struct srcimp_mgr **rsrc_mgr);
1468c2ecf20Sopenharmony_ciint srcimp_mgr_destroy(struct srcimp_mgr *srcimp_mgr);
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_ci#endif /* CTSRC_H */
149