^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 2008, Creative Technology Ltd. All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * @File ctsrc.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * @Brief
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * This file contains the definition of the Sample Rate Convertor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * resource management object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * @Author Liu Chun
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * @Date May 13 2008
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #ifndef CTSRC_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define CTSRC_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include "ctresource.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include "ctimap.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <sound/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define SRC_STATE_OFF 0x0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define SRC_STATE_INIT 0x4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define SRC_STATE_RUN 0x5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define SRC_SF_U8 0x0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define SRC_SF_S16 0x1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define SRC_SF_S24 0x2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define SRC_SF_S32 0x3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define SRC_SF_F32 0x4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) /* Define the descriptor of a src resource */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) enum SRCMODE {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) MEMRD, /* Read data from host memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) MEMWR, /* Write data to host memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) ARCRW, /* Read from and write to audio ring channel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) NUM_SRCMODES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) struct src_rsc_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) struct src {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct rsc rsc; /* Basic resource info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) struct src *intlv; /* Pointer to next interleaved SRC in a series */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) const struct src_rsc_ops *ops; /* SRC specific operations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) /* Number of contiguous srcs for interleaved usage */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) unsigned char multi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) unsigned char mode; /* Working mode of this SRC resource */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) struct src_rsc_ops {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) int (*set_state)(struct src *src, unsigned int state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) int (*set_bm)(struct src *src, unsigned int bm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) int (*set_sf)(struct src *src, unsigned int sf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) int (*set_pm)(struct src *src, unsigned int pm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) int (*set_rom)(struct src *src, unsigned int rom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) int (*set_vo)(struct src *src, unsigned int vo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) int (*set_st)(struct src *src, unsigned int st);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) int (*set_bp)(struct src *src, unsigned int bp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) int (*set_cisz)(struct src *src, unsigned int cisz);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) int (*set_ca)(struct src *src, unsigned int ca);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) int (*set_sa)(struct src *src, unsigned int sa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) int (*set_la)(struct src *src, unsigned int la);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) int (*set_pitch)(struct src *src, unsigned int pitch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) int (*set_clr_zbufs)(struct src *src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) int (*commit_write)(struct src *src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) int (*get_ca)(struct src *src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) int (*init)(struct src *src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) struct src* (*next_interleave)(struct src *src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) /* Define src resource request description info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) struct src_desc {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) /* Number of contiguous master srcs for interleaved usage */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) unsigned char multi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) unsigned char msr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) unsigned char mode; /* Working mode of the requested srcs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) /* Define src manager object */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) struct src_mgr {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) struct rsc_mgr mgr; /* Basic resource manager info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) struct snd_card *card; /* pointer to this card */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) spinlock_t mgr_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) /* request src resource */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) int (*get_src)(struct src_mgr *mgr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) const struct src_desc *desc, struct src **rsrc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) /* return src resource */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) int (*put_src)(struct src_mgr *mgr, struct src *src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) int (*src_enable_s)(struct src_mgr *mgr, struct src *src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) int (*src_enable)(struct src_mgr *mgr, struct src *src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) int (*src_disable)(struct src_mgr *mgr, struct src *src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) int (*commit_write)(struct src_mgr *mgr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) /* Define the descriptor of a SRC Input Mapper resource */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) struct srcimp_mgr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) struct srcimp_rsc_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) struct srcimp {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) struct rsc rsc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) unsigned char idx[8];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) struct imapper *imappers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) unsigned int mapped; /* A bit-map indicating which conj rsc is mapped */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) struct srcimp_mgr *mgr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) const struct srcimp_rsc_ops *ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) struct srcimp_rsc_ops {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) int (*map)(struct srcimp *srcimp, struct src *user, struct rsc *input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) int (*unmap)(struct srcimp *srcimp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) /* Define SRCIMP resource request description info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) struct srcimp_desc {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) unsigned int msr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) struct srcimp_mgr {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) struct rsc_mgr mgr; /* Basic resource manager info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) struct snd_card *card; /* pointer to this card */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) spinlock_t mgr_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) spinlock_t imap_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) struct list_head imappers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) struct imapper *init_imap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) unsigned int init_imap_added;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) /* request srcimp resource */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) int (*get_srcimp)(struct srcimp_mgr *mgr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) const struct srcimp_desc *desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) struct srcimp **rsrcimp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) /* return srcimp resource */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) int (*put_srcimp)(struct srcimp_mgr *mgr, struct srcimp *srcimp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) int (*imap_add)(struct srcimp_mgr *mgr, struct imapper *entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) int (*imap_delete)(struct srcimp_mgr *mgr, struct imapper *entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) /* Constructor and destructor of SRC resource manager */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) int src_mgr_create(struct hw *hw, struct src_mgr **rsrc_mgr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) int src_mgr_destroy(struct src_mgr *src_mgr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) /* Constructor and destructor of SRCIMP resource manager */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) int srcimp_mgr_create(struct hw *hw, struct srcimp_mgr **rsrc_mgr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) int srcimp_mgr_destroy(struct srcimp_mgr *srcimp_mgr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) #endif /* CTSRC_H */