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.
- 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/mfd/syscon.hlinux/module.hlinux/of_address.hlinux/sched/clock.hsound/soc.h
Detected Declarations
struct mtk_btcvsd_snd_hw_infostruct mtk_btcvsd_snd_streamstruct mtk_btcvsd_sndstruct mtk_btcvsd_snd_time_buffer_infoenum bt_sco_stateenum bt_sco_directenum bt_sco_packet_lenenum BT_SCO_BANDfunction mtk_btcvsd_snd_irq_enablefunction mtk_btcvsd_snd_irq_disablefunction mtk_btcvsd_snd_set_statefunction mtk_btcvsd_snd_tx_initfunction mtk_btcvsd_snd_rx_initfunction get_tx_time_stampfunction get_rx_time_stampfunction btcvsd_bytes_to_framefunction mtk_btcvsd_snd_data_transferfunction btcvsd_tx_clean_bufferfunction mtk_btcvsd_read_from_btfunction mtk_btcvsd_write_to_btfunction scoped_guardfunction scoped_guardfunction mtk_btcvsd_snd_irq_handlerfunction wait_for_bt_irqfunction mtk_btcvsd_snd_readfunction mtk_btcvsd_snd_writefunction mtk_pcm_btcvsd_openfunction mtk_pcm_btcvsd_closefunction mtk_pcm_btcvsd_hw_paramsfunction mtk_pcm_btcvsd_hw_freefunction mtk_pcm_btcvsd_preparefunction mtk_pcm_btcvsd_triggerfunction mtk_pcm_btcvsd_pointerfunction mtk_pcm_btcvsd_copyfunction btcvsd_band_getfunction btcvsd_band_setfunction btcvsd_loopback_getfunction btcvsd_loopback_setfunction btcvsd_tx_mute_getfunction btcvsd_tx_mute_setfunction btcvsd_rx_irq_received_getfunction btcvsd_rx_timeout_getfunction btcvsd_rx_timestamp_getfunction btcvsd_tx_irq_received_getfunction btcvsd_tx_timeout_getfunction btcvsd_tx_timestamp_getfunction mtk_btcvsd_snd_component_probefunction mtk_btcvsd_snd_probe
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
- Immediate include surface: `linux/mfd/syscon.h`, `linux/module.h`, `linux/of_address.h`, `linux/sched/clock.h`, `sound/soc.h`.
- Detected declarations: `struct mtk_btcvsd_snd_hw_info`, `struct mtk_btcvsd_snd_stream`, `struct mtk_btcvsd_snd`, `struct mtk_btcvsd_snd_time_buffer_info`, `enum bt_sco_state`, `enum bt_sco_direct`, `enum bt_sco_packet_len`, `enum BT_SCO_BAND`, `function mtk_btcvsd_snd_irq_enable`, `function mtk_btcvsd_snd_irq_disable`.
- Atlas domain: Driver Families / sound/soc.
- Implementation status: source implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.