sound/soc/codecs/pm4125-sdw.c

Source file repositories/reference/linux-study-clean/sound/soc/codecs/pm4125-sdw.c

File Facts

System
Linux kernel
Corpus path
sound/soc/codecs/pm4125-sdw.c
Extension
.c
Size
16597 bytes
Lines
494
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.

Dependency Surface

Detected Declarations

Annotated Snippet

// SPDX-License-Identifier: GPL-2.0-only
// Copyright (c) 2023-2024 Qualcomm Innovation Center, Inc. All rights reserved.
// Copyright, 2025 Linaro Ltd

#include <linux/component.h>
#include <linux/device.h>
#include <linux/irq.h>
#include <linux/irqdomain.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>
#include <linux/regmap.h>
#include <linux/slab.h>
#include <linux/soundwire/sdw.h>
#include <linux/soundwire/sdw_registers.h>
#include <linux/soundwire/sdw_type.h>
#include <sound/soc-dapm.h>
#include <sound/soc.h>
#include "pm4125.h"

static struct wcd_sdw_ch_info pm4125_sdw_rx_ch_info[] = {
	WCD_SDW_CH(PM4125_HPH_L, PM4125_HPH_PORT, BIT(0)),
	WCD_SDW_CH(PM4125_HPH_R, PM4125_HPH_PORT, BIT(1)),
};

static struct wcd_sdw_ch_info pm4125_sdw_tx_ch_info[] = {
	WCD_SDW_CH(PM4125_ADC1, PM4125_ADC_1_2_DMIC1L_BCS_PORT, BIT(0)),
	WCD_SDW_CH(PM4125_ADC2, PM4125_ADC_1_2_DMIC1L_BCS_PORT, BIT(1)),
};

static struct sdw_dpn_prop pm4125_dpn_prop[PM4125_MAX_SWR_PORTS] = {
	{
		.num = 1,
		.type = SDW_DPN_SIMPLE,
		.min_ch = 1,
		.max_ch = 8,
		.simple_ch_prep_sm = true,
	}, {
		.num = 2,
		.type = SDW_DPN_SIMPLE,
		.min_ch = 1,
		.max_ch = 4,
		.simple_ch_prep_sm = true,
	}
};

int pm4125_sdw_hw_params(struct pm4125_sdw_priv *priv, struct snd_pcm_substream *substream,
			 struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
{
	struct sdw_port_config port_config[PM4125_MAX_SWR_PORTS];
	unsigned long ch_mask;
	int i, j;

	priv->sconfig.ch_count = 1;
	priv->active_ports = 0;
	for (i = 0; i < PM4125_MAX_SWR_PORTS; i++) {
		ch_mask = priv->port_config[i].ch_mask;
		if (!ch_mask)
			continue;

		for_each_set_bit(j, &ch_mask, 4)
			priv->sconfig.ch_count++;

		port_config[priv->active_ports] = priv->port_config[i];
		priv->active_ports++;
	}

	priv->sconfig.bps = 1;
	priv->sconfig.frame_rate = params_rate(params);
	priv->sconfig.direction = priv->is_tx ? SDW_DATA_DIR_TX : SDW_DATA_DIR_RX;
	priv->sconfig.type = SDW_STREAM_PCM;

	return sdw_stream_add_slave(priv->sdev, &priv->sconfig, &port_config[0], priv->active_ports,
				    priv->sruntime);
}
EXPORT_SYMBOL_GPL(pm4125_sdw_hw_params);

/*
 * Handle Soundwire out-of-band interrupt event by triggering the first irq of the slave_irq
 * irq domain, which then will be handled by the regmap_irq threaded irq.
 * Looping is to ensure no interrupts were missed in the process.
 */
static int pm4125_interrupt_callback(struct sdw_slave *slave, struct sdw_slave_intr_status *status)
{
	struct pm4125_sdw_priv *priv = dev_get_drvdata(&slave->dev);

	return wcd_interrupt_callback(slave, priv->slave_irq, PM4125_DIG_SWR_INTR_STATUS_0,
				PM4125_DIG_SWR_INTR_STATUS_1, PM4125_DIG_SWR_INTR_STATUS_2);

Annotation

Implementation Notes