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	ctsrc.h
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci * @Brief
862306a36Sopenharmony_ci * This file contains the definition of the Sample Rate Convertor
962306a36Sopenharmony_ci * resource management object.
1062306a36Sopenharmony_ci *
1162306a36Sopenharmony_ci * @Author	Liu Chun
1262306a36Sopenharmony_ci * @Date 	May 13 2008
1362306a36Sopenharmony_ci */
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci#ifndef CTSRC_H
1662306a36Sopenharmony_ci#define CTSRC_H
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci#include "ctresource.h"
1962306a36Sopenharmony_ci#include "ctimap.h"
2062306a36Sopenharmony_ci#include <linux/spinlock.h>
2162306a36Sopenharmony_ci#include <linux/list.h>
2262306a36Sopenharmony_ci#include <sound/core.h>
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ci#define SRC_STATE_OFF	0x0
2562306a36Sopenharmony_ci#define SRC_STATE_INIT	0x4
2662306a36Sopenharmony_ci#define SRC_STATE_RUN	0x5
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci#define SRC_SF_U8	0x0
2962306a36Sopenharmony_ci#define SRC_SF_S16	0x1
3062306a36Sopenharmony_ci#define SRC_SF_S24	0x2
3162306a36Sopenharmony_ci#define SRC_SF_S32	0x3
3262306a36Sopenharmony_ci#define SRC_SF_F32	0x4
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ci/* Define the descriptor of a src resource */
3562306a36Sopenharmony_cienum SRCMODE {
3662306a36Sopenharmony_ci	MEMRD,		/* Read data from host memory */
3762306a36Sopenharmony_ci	MEMWR,		/* Write data to host memory */
3862306a36Sopenharmony_ci	ARCRW,		/* Read from and write to audio ring channel */
3962306a36Sopenharmony_ci	NUM_SRCMODES
4062306a36Sopenharmony_ci};
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_cistruct src_rsc_ops;
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_cistruct src {
4562306a36Sopenharmony_ci	struct rsc rsc; /* Basic resource info */
4662306a36Sopenharmony_ci	struct src *intlv; /* Pointer to next interleaved SRC in a series */
4762306a36Sopenharmony_ci	const struct src_rsc_ops *ops; /* SRC specific operations */
4862306a36Sopenharmony_ci	/* Number of contiguous srcs for interleaved usage */
4962306a36Sopenharmony_ci	unsigned char multi;
5062306a36Sopenharmony_ci	unsigned char mode; /* Working mode of this SRC resource */
5162306a36Sopenharmony_ci};
5262306a36Sopenharmony_ci
5362306a36Sopenharmony_cistruct src_rsc_ops {
5462306a36Sopenharmony_ci	int (*set_state)(struct src *src, unsigned int state);
5562306a36Sopenharmony_ci	int (*set_bm)(struct src *src, unsigned int bm);
5662306a36Sopenharmony_ci	int (*set_sf)(struct src *src, unsigned int sf);
5762306a36Sopenharmony_ci	int (*set_pm)(struct src *src, unsigned int pm);
5862306a36Sopenharmony_ci	int (*set_rom)(struct src *src, unsigned int rom);
5962306a36Sopenharmony_ci	int (*set_vo)(struct src *src, unsigned int vo);
6062306a36Sopenharmony_ci	int (*set_st)(struct src *src, unsigned int st);
6162306a36Sopenharmony_ci	int (*set_bp)(struct src *src, unsigned int bp);
6262306a36Sopenharmony_ci	int (*set_cisz)(struct src *src, unsigned int cisz);
6362306a36Sopenharmony_ci	int (*set_ca)(struct src *src, unsigned int ca);
6462306a36Sopenharmony_ci	int (*set_sa)(struct src *src, unsigned int sa);
6562306a36Sopenharmony_ci	int (*set_la)(struct src *src, unsigned int la);
6662306a36Sopenharmony_ci	int (*set_pitch)(struct src *src, unsigned int pitch);
6762306a36Sopenharmony_ci	int (*set_clr_zbufs)(struct src *src);
6862306a36Sopenharmony_ci	int (*commit_write)(struct src *src);
6962306a36Sopenharmony_ci	int (*get_ca)(struct src *src);
7062306a36Sopenharmony_ci	int (*init)(struct src *src);
7162306a36Sopenharmony_ci	struct src* (*next_interleave)(struct src *src);
7262306a36Sopenharmony_ci};
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_ci/* Define src resource request description info */
7562306a36Sopenharmony_cistruct src_desc {
7662306a36Sopenharmony_ci	/* Number of contiguous master srcs for interleaved usage */
7762306a36Sopenharmony_ci	unsigned char multi;
7862306a36Sopenharmony_ci	unsigned char msr;
7962306a36Sopenharmony_ci	unsigned char mode; /* Working mode of the requested srcs */
8062306a36Sopenharmony_ci};
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_ci/* Define src manager object */
8362306a36Sopenharmony_cistruct src_mgr {
8462306a36Sopenharmony_ci	struct rsc_mgr mgr;	/* Basic resource manager info */
8562306a36Sopenharmony_ci	struct snd_card *card;	/* pointer to this card */
8662306a36Sopenharmony_ci	spinlock_t mgr_lock;
8762306a36Sopenharmony_ci
8862306a36Sopenharmony_ci	 /* request src resource */
8962306a36Sopenharmony_ci	int (*get_src)(struct src_mgr *mgr,
9062306a36Sopenharmony_ci		       const struct src_desc *desc, struct src **rsrc);
9162306a36Sopenharmony_ci	/* return src resource */
9262306a36Sopenharmony_ci	int (*put_src)(struct src_mgr *mgr, struct src *src);
9362306a36Sopenharmony_ci	int (*src_enable_s)(struct src_mgr *mgr, struct src *src);
9462306a36Sopenharmony_ci	int (*src_enable)(struct src_mgr *mgr, struct src *src);
9562306a36Sopenharmony_ci	int (*src_disable)(struct src_mgr *mgr, struct src *src);
9662306a36Sopenharmony_ci	int (*commit_write)(struct src_mgr *mgr);
9762306a36Sopenharmony_ci};
9862306a36Sopenharmony_ci
9962306a36Sopenharmony_ci/* Define the descriptor of a SRC Input Mapper resource */
10062306a36Sopenharmony_cistruct srcimp_mgr;
10162306a36Sopenharmony_cistruct srcimp_rsc_ops;
10262306a36Sopenharmony_ci
10362306a36Sopenharmony_cistruct srcimp {
10462306a36Sopenharmony_ci	struct rsc rsc;
10562306a36Sopenharmony_ci	unsigned char idx[8];
10662306a36Sopenharmony_ci	struct imapper *imappers;
10762306a36Sopenharmony_ci	unsigned int mapped; /* A bit-map indicating which conj rsc is mapped */
10862306a36Sopenharmony_ci	struct srcimp_mgr *mgr;
10962306a36Sopenharmony_ci	const struct srcimp_rsc_ops *ops;
11062306a36Sopenharmony_ci};
11162306a36Sopenharmony_ci
11262306a36Sopenharmony_cistruct srcimp_rsc_ops {
11362306a36Sopenharmony_ci	int (*map)(struct srcimp *srcimp, struct src *user, struct rsc *input);
11462306a36Sopenharmony_ci	int (*unmap)(struct srcimp *srcimp);
11562306a36Sopenharmony_ci};
11662306a36Sopenharmony_ci
11762306a36Sopenharmony_ci/* Define SRCIMP resource request description info */
11862306a36Sopenharmony_cistruct srcimp_desc {
11962306a36Sopenharmony_ci	unsigned int msr;
12062306a36Sopenharmony_ci};
12162306a36Sopenharmony_ci
12262306a36Sopenharmony_cistruct srcimp_mgr {
12362306a36Sopenharmony_ci	struct rsc_mgr mgr;	/* Basic resource manager info */
12462306a36Sopenharmony_ci	struct snd_card *card;	/* pointer to this card */
12562306a36Sopenharmony_ci	spinlock_t mgr_lock;
12662306a36Sopenharmony_ci	spinlock_t imap_lock;
12762306a36Sopenharmony_ci	struct list_head imappers;
12862306a36Sopenharmony_ci	struct imapper *init_imap;
12962306a36Sopenharmony_ci	unsigned int init_imap_added;
13062306a36Sopenharmony_ci
13162306a36Sopenharmony_ci	 /* request srcimp resource */
13262306a36Sopenharmony_ci	int (*get_srcimp)(struct srcimp_mgr *mgr,
13362306a36Sopenharmony_ci			  const struct srcimp_desc *desc,
13462306a36Sopenharmony_ci			  struct srcimp **rsrcimp);
13562306a36Sopenharmony_ci	/* return srcimp resource */
13662306a36Sopenharmony_ci	int (*put_srcimp)(struct srcimp_mgr *mgr, struct srcimp *srcimp);
13762306a36Sopenharmony_ci	int (*imap_add)(struct srcimp_mgr *mgr, struct imapper *entry);
13862306a36Sopenharmony_ci	int (*imap_delete)(struct srcimp_mgr *mgr, struct imapper *entry);
13962306a36Sopenharmony_ci};
14062306a36Sopenharmony_ci
14162306a36Sopenharmony_ci/* Constructor and destructor of SRC resource manager */
14262306a36Sopenharmony_ciint src_mgr_create(struct hw *hw, struct src_mgr **rsrc_mgr);
14362306a36Sopenharmony_ciint src_mgr_destroy(struct src_mgr *src_mgr);
14462306a36Sopenharmony_ci/* Constructor and destructor of SRCIMP resource manager */
14562306a36Sopenharmony_ciint srcimp_mgr_create(struct hw *hw, struct srcimp_mgr **rsrc_mgr);
14662306a36Sopenharmony_ciint srcimp_mgr_destroy(struct srcimp_mgr *srcimp_mgr);
14762306a36Sopenharmony_ci
14862306a36Sopenharmony_ci#endif /* CTSRC_H */
149