sound/soc/codecs/wcd-mbhc-v2.c
Source file repositories/reference/linux-study-clean/sound/soc/codecs/wcd-mbhc-v2.c
File Facts
- System
- Linux kernel
- Corpus path
sound/soc/codecs/wcd-mbhc-v2.c- Extension
.c- Size
- 46183 bytes
- Lines
- 1636
- Domain
- Driver Families
- Bucket
- sound/soc
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/module.hlinux/init.hlinux/slab.hlinux/device.hlinux/pm_runtime.hlinux/printk.hlinux/delay.hlinux/kernel.hsound/soc.hsound/jack.hwcd-mbhc-v2.h
Detected Declarations
struct wcd_mbhcenum wcd_mbhc_adc_mux_ctlfunction wcd_mbhc_write_fieldfunction wcd_mbhc_read_fieldfunction wcd_program_hs_vreffunction wcd_program_btn_thresholdfunction wcd_mbhc_curr_micbias_controlfunction wcd_mbhc_event_notifyfunction wcd_cancel_btn_workfunction wcd_micbias_disablefunction wcd_mbhc_report_plug_removalfunction wcd_mbhc_compute_impedancefunction wcd_mbhc_report_plug_insertionfunction wcd_mbhc_report_plugfunction wcd_cancel_hs_detect_plugfunction wcd_mbhc_cancel_pending_workfunction wcd_mbhc_elec_hs_report_unplugfunction wcd_mbhc_find_plug_and_reportfunction wcd_schedule_hs_detect_plugfunction wcd_mbhc_adc_detect_plug_typefunction mbhc_plug_detect_fnfunction wcd_mbhc_mech_plug_detect_irqfunction wcd_mbhc_typec_report_unplugfunction wcd_mbhc_typec_report_plugfunction wcd_mbhc_get_button_maskfunction wcd_btn_long_press_fnfunction wcd_mbhc_btn_press_handlerfunction wcd_mbhc_btn_release_handlerfunction wcd_mbhc_hph_ocp_irqfunction wcd_mbhc_hphl_ocp_irqfunction wcd_mbhc_hphr_ocp_irqfunction wcd_mbhc_initialisefunction wcd_mbhc_get_micbiasfunction wcd_get_voltage_from_adcfunction wcd_measure_adc_continuousfunction wcd_measure_adc_oncefunction wcd_check_cross_connfunction wcd_mbhc_adc_get_hs_thresfunction wcd_mbhc_adc_get_hph_thresfunction wcd_mbhc_adc_update_fsm_sourcefunction wcd_mbhc_bcs_enablefunction wcd_mbhc_get_plug_from_adcfunction wcd_mbhc_get_spl_hs_thresfunction wcd_mbhc_check_for_spl_headsetfunction wcd_correct_swch_plugfunction wcd_mbhc_adc_hs_rem_irqfunction wcd_mbhc_adc_hs_ins_irqfunction wcd_mbhc_get_impedance
Annotated Snippet
struct wcd_mbhc {
struct device *dev;
struct snd_soc_component *component;
struct snd_soc_jack *jack;
struct wcd_mbhc_config *cfg;
const struct wcd_mbhc_cb *mbhc_cb;
const struct wcd_mbhc_intr *intr_ids;
const struct wcd_mbhc_field *fields;
/* Delayed work to report long button press */
struct delayed_work mbhc_btn_dwork;
/* Work to handle plug report */
struct work_struct mbhc_plug_detect_work;
/* Work to correct accessory type */
struct work_struct correct_plug_swch;
struct mutex lock;
int buttons_pressed;
u32 hph_status; /* track headhpone status */
u8 current_plug;
unsigned int swap_thr;
bool is_btn_press;
bool in_swch_irq_handler;
bool hs_detect_work_stop;
bool is_hs_recording;
bool extn_cable_hph_rem;
bool force_linein;
bool impedance_detect;
unsigned long event_state;
unsigned long jiffies_atreport;
/* impedance of hphl and hphr */
uint32_t zl, zr;
/* Holds type of Headset - Mono/Stereo */
enum wcd_mbhc_hph_type hph_type;
/* Holds mbhc detection method - ADC/Legacy */
int mbhc_detection_logic;
};
static inline int wcd_mbhc_write_field(const struct wcd_mbhc *mbhc,
int field, int val)
{
if (!mbhc->fields[field].reg)
return 0;
return snd_soc_component_write_field(mbhc->component,
mbhc->fields[field].reg,
mbhc->fields[field].mask, val);
}
static inline int wcd_mbhc_read_field(const struct wcd_mbhc *mbhc, int field)
{
if (!mbhc->fields[field].reg)
return 0;
return snd_soc_component_read_field(mbhc->component,
mbhc->fields[field].reg,
mbhc->fields[field].mask);
}
static void wcd_program_hs_vref(struct wcd_mbhc *mbhc)
{
u32 reg_val = ((mbhc->cfg->v_hs_max - HS_VREF_MIN_VAL) / 100);
wcd_mbhc_write_field(mbhc, WCD_MBHC_HS_VREF, reg_val);
}
static void wcd_program_btn_threshold(const struct wcd_mbhc *mbhc, bool micbias)
{
struct snd_soc_component *component = mbhc->component;
mbhc->mbhc_cb->set_btn_thr(component, mbhc->cfg->btn_low,
mbhc->cfg->btn_high,
mbhc->cfg->num_btn, micbias);
}
static void wcd_mbhc_curr_micbias_control(const struct wcd_mbhc *mbhc,
const enum wcd_mbhc_cs_mb_en_flag cs_mb_en)
{
/*
* Some codecs handle micbias/pullup enablement in codec
* drivers itself and micbias is not needed for regular
* plug type detection. So if micbias_control callback function
* is defined, just return.
*/
if (mbhc->mbhc_cb->mbhc_micbias_control)
return;
switch (cs_mb_en) {
case WCD_MBHC_EN_CS:
wcd_mbhc_write_field(mbhc, WCD_MBHC_MICB_CTRL, 0);
wcd_mbhc_write_field(mbhc, WCD_MBHC_BTN_ISRC_CTL, 3);
Annotation
- Immediate include surface: `linux/module.h`, `linux/init.h`, `linux/slab.h`, `linux/device.h`, `linux/pm_runtime.h`, `linux/printk.h`, `linux/delay.h`, `linux/kernel.h`.
- Detected declarations: `struct wcd_mbhc`, `enum wcd_mbhc_adc_mux_ctl`, `function wcd_mbhc_write_field`, `function wcd_mbhc_read_field`, `function wcd_program_hs_vref`, `function wcd_program_btn_threshold`, `function wcd_mbhc_curr_micbias_control`, `function wcd_mbhc_event_notify`, `function wcd_cancel_btn_work`, `function wcd_micbias_disable`.
- Atlas domain: Driver Families / sound/soc.
- Implementation status: integration implementation candidate.
- 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.