sound/soc/mediatek/common/mtk-btcvsd.c

Source file repositories/reference/linux-study-clean/sound/soc/mediatek/common/mtk-btcvsd.c

File Facts

System
Linux kernel
Corpus path
sound/soc/mediatek/common/mtk-btcvsd.c
Extension
.c
Size
38803 bytes
Lines
1400
Domain
Driver Families
Bucket
sound/soc
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

struct mtk_btcvsd_snd_hw_info {
	unsigned int num_valid_addr;
	unsigned long bt_sram_addr[20];
	unsigned int packet_length;
	unsigned int packet_num;
};

struct mtk_btcvsd_snd_stream {
	struct snd_pcm_substream *substream;
	int stream;

	enum bt_sco_state state;

	unsigned int packet_size;
	unsigned int buf_size;
	u8 temp_packet_buf[SCO_PACKET_180];

	int packet_w;
	int packet_r;
	snd_pcm_uframes_t prev_frame;
	int prev_packet_idx;

	unsigned int xrun:1;
	unsigned int timeout:1;
	unsigned int mute:1;
	unsigned int trigger_start:1;
	unsigned int wait_flag:1;
	unsigned int rw_cnt;

	unsigned long long time_stamp;
	unsigned long long buf_data_equivalent_time;

	struct mtk_btcvsd_snd_hw_info buffer_info;
};

struct mtk_btcvsd_snd {
	struct device *dev;
	int irq_id;

	struct regmap *infra;
	void __iomem *bt_pkv_base;
	void __iomem *bt_sram_bank2_base;

	unsigned int infra_misc_offset;
	unsigned int conn_bt_cvsd_mask;
	unsigned int cvsd_mcu_read_offset;
	unsigned int cvsd_mcu_write_offset;
	unsigned int cvsd_packet_indicator;

	u32 *bt_reg_pkt_r;
	u32 *bt_reg_pkt_w;
	u32 *bt_reg_ctl;

	unsigned int irq_disabled:1;

	spinlock_t tx_lock;	/* spinlock for bt tx stream control */
	spinlock_t rx_lock;	/* spinlock for bt rx stream control */
	wait_queue_head_t tx_wait;
	wait_queue_head_t rx_wait;

	struct mtk_btcvsd_snd_stream *tx;
	struct mtk_btcvsd_snd_stream *rx;
	u8 tx_packet_buf[BTCVSD_TX_BUF_SIZE];
	u8 rx_packet_buf[BTCVSD_RX_BUF_SIZE];

	enum BT_SCO_BAND band;
};

struct mtk_btcvsd_snd_time_buffer_info {
	unsigned long long data_count_equi_time;
	unsigned long long time_stamp_us;
};

static const unsigned int btsco_packet_valid_mask[BT_SCO_CVSD_MAX][6] = {
	{0x1, 0x1 << 1, 0x1 << 2, 0x1 << 3, 0x1 << 4, 0x1 << 5},
	{0x1, 0x1, 0x2, 0x2, 0x4, 0x4},
	{0x1, 0x1, 0x1, 0x2, 0x2, 0x2},
	{0x1, 0x1, 0x1, 0x1, 0x0, 0x0},
	{0x7, 0x7 << 3, 0x7 << 6, 0x7 << 9, 0x7 << 12, 0x7 << 15},
	{0x3, 0x3 << 1, 0x3 << 3, 0x3 << 4, 0x3 << 6, 0x3 << 7},
};

static const unsigned int btsco_packet_info[BT_SCO_CVSD_MAX][4] = {
	{30, 6, SCO_PACKET_180 / SCO_TX_ENCODE_SIZE,
	 SCO_PACKET_180 / SCO_RX_PLC_SIZE},
	{60, 3, SCO_PACKET_180 / SCO_TX_ENCODE_SIZE,
	 SCO_PACKET_180 / SCO_RX_PLC_SIZE},
	{90, 2, SCO_PACKET_180 / SCO_TX_ENCODE_SIZE,
	 SCO_PACKET_180 / SCO_RX_PLC_SIZE},
	{120, 1, SCO_PACKET_120 / SCO_TX_ENCODE_SIZE,

Annotation

Implementation Notes