sound/soc/codecs/rt5677.c
Source file repositories/reference/linux-study-clean/sound/soc/codecs/rt5677.c
File Facts
- System
- Linux kernel
- Corpus path
sound/soc/codecs/rt5677.c- Extension
.c- Size
- 187661 bytes
- Lines
- 5710
- 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/delay.hlinux/firmware.hlinux/fs.hlinux/i2c.hlinux/init.hlinux/interrupt.hlinux/irqdomain.hlinux/irq.hlinux/module.hlinux/moduleparam.hlinux/platform_device.hlinux/pm.hlinux/property.hlinux/regmap.hlinux/spi/spi.hlinux/workqueue.hsound/core.hsound/pcm.hsound/pcm_params.hsound/soc.hsound/soc-dapm.hsound/initval.hsound/tlv.hrl6231.hrt5677.hrt5677-spi.h
Detected Declarations
struct rt5677_irq_descfunction rt5677_volatile_registerfunction rt5677_readable_registerfunction rt5677_dsp_mode_i2c_write_addrfunction rt5677_dsp_mode_i2c_read_addrfunction rt5677_dsp_mode_i2c_writefunction rt5677_dsp_mode_i2c_readfunction rt5677_set_dsp_modefunction rt5677_set_vad_sourcefunction rt5677_parse_and_load_dspfunction rt5677_load_dsp_from_filefunction rt5677_set_dsp_vadfunction rt5677_dsp_workfunction rt5677_dsp_vad_getfunction rt5677_dsp_vad_putfunction set_dmic_clkfunction is_sys_clk_from_pllfunction is_using_asrcfunction can_use_asrcfunction rt5677_sel_asrc_clk_srcfunction rt5677_dmic_use_asrcfunction rt5677_bst1_eventfunction rt5677_bst2_eventfunction rt5677_set_pll1_eventfunction rt5677_set_pll2_eventfunction rt5677_set_micbias1_eventfunction rt5677_if1_adc_tdm_eventfunction rt5677_if2_adc_tdm_eventfunction rt5677_vref_eventfunction rt5677_filter_power_eventfunction rt5677_hw_paramsfunction rt5677_set_dai_fmtfunction rt5677_set_dai_sysclkfunction rt5677_pll_calcfunction rt5677_set_dai_pllfunction rt5677_set_tdm_slotfunction rt5677_set_bias_levelfunction rt5677_update_gpio_bitsfunction rt5677_gpio_setfunction rt5677_gpio_direction_outfunction rt5677_gpio_getfunction rt5677_gpio_direction_infunction rt5677_gpio_configfunction rt5677_to_irqfunction rt5677_init_gpiofunction rt5677_free_gpiofunction rt5677_gpio_configfunction rt5677_remove
Annotated Snippet
struct rt5677_irq_desc {
unsigned int enable_mask;
unsigned int status_mask;
unsigned int polarity_mask;
};
static const struct rt5677_irq_desc rt5677_irq_descs[] = {
[RT5677_IRQ_JD1] = {
.enable_mask = RT5677_EN_IRQ_GPIO_JD1,
.status_mask = RT5677_STA_GPIO_JD1,
.polarity_mask = RT5677_INV_GPIO_JD1,
},
[RT5677_IRQ_JD2] = {
.enable_mask = RT5677_EN_IRQ_GPIO_JD2,
.status_mask = RT5677_STA_GPIO_JD2,
.polarity_mask = RT5677_INV_GPIO_JD2,
},
[RT5677_IRQ_JD3] = {
.enable_mask = RT5677_EN_IRQ_GPIO_JD3,
.status_mask = RT5677_STA_GPIO_JD3,
.polarity_mask = RT5677_INV_GPIO_JD3,
},
};
static bool rt5677_check_hotword(struct rt5677_priv *rt5677)
{
int reg_gpio;
if (!rt5677->is_dsp_mode)
return false;
if (regmap_read(rt5677->regmap, RT5677_GPIO_CTRL1, ®_gpio))
return false;
/* Firmware sets GPIO1 pin to be GPIO1 after hotword is detected */
if ((reg_gpio & RT5677_GPIO1_PIN_MASK) == RT5677_GPIO1_PIN_IRQ)
return false;
/* Set GPIO1 pin back to be IRQ output for jack detect */
regmap_update_bits(rt5677->regmap, RT5677_GPIO_CTRL1,
RT5677_GPIO1_PIN_MASK, RT5677_GPIO1_PIN_IRQ);
rt5677_spi_hotword_detected();
return true;
}
static irqreturn_t rt5677_irq(int unused, void *data)
{
struct rt5677_priv *rt5677 = data;
int ret, loop, i, reg_irq, virq;
bool irq_fired = false;
mutex_lock(&rt5677->irq_lock);
/*
* Loop to handle interrupts until the last i2c read shows no pending
* irqs. The interrupt line is shared by multiple interrupt sources.
* After the regmap_read() below, a new interrupt source line may
* become high before the regmap_write() finishes, so there isn't a
* rising edge on the shared interrupt line for the new interrupt. Thus,
* the loop is needed to avoid missing irqs.
*
* A safeguard of 20 loops is used to avoid hanging in the irq handler
* if there is something wrong with the interrupt status update. The
* interrupt sources here are audio jack plug/unplug events which
* shouldn't happen at a high frequency for a long period of time.
* Empirically, more than 3 loops have never been seen.
*/
for (loop = 0; loop < 20; loop++) {
/* Read interrupt status */
ret = regmap_read(rt5677->regmap, RT5677_IRQ_CTRL1, ®_irq);
if (ret) {
dev_err(rt5677->dev, "failed reading IRQ status: %d\n",
ret);
goto exit;
}
irq_fired = false;
for (i = 0; i < RT5677_IRQ_NUM; i++) {
if (reg_irq & rt5677_irq_descs[i].status_mask) {
irq_fired = true;
virq = irq_find_mapping(rt5677->domain, i);
if (virq)
handle_nested_irq(virq);
/* Clear the interrupt by flipping the polarity
* of the interrupt source line that fired
*/
reg_irq ^= rt5677_irq_descs[i].polarity_mask;
}
Annotation
- Immediate include surface: `linux/delay.h`, `linux/firmware.h`, `linux/fs.h`, `linux/i2c.h`, `linux/init.h`, `linux/interrupt.h`, `linux/irqdomain.h`, `linux/irq.h`.
- Detected declarations: `struct rt5677_irq_desc`, `function rt5677_volatile_register`, `function rt5677_readable_register`, `function rt5677_dsp_mode_i2c_write_addr`, `function rt5677_dsp_mode_i2c_read_addr`, `function rt5677_dsp_mode_i2c_write`, `function rt5677_dsp_mode_i2c_read`, `function rt5677_set_dsp_mode`, `function rt5677_set_vad_source`, `function rt5677_parse_and_load_dsp`.
- 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.