Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions drivers/soundwire/cadence_master.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <linux/pm_runtime.h>
#include <linux/soundwire/sdw_registers.h>
#include <linux/soundwire/sdw.h>
#include <linux/soundwire/sdw_cadence.h>
#include <sound/pcm_params.h>
#include <sound/soc.h>
#include <linux/workqueue.h>
Expand Down Expand Up @@ -1839,6 +1840,7 @@ int sdw_cdns_probe(struct sdw_cdns *cdns)

mutex_init(&cdns->status_update_lock);

spin_lock_init(&cdns->pdi_lock);
INIT_WORK(&cdns->work, cdns_update_slave_status_work);
INIT_DELAYED_WORK(&cdns->attach_dwork, cdns_check_attached_status_dwork);

Expand Down Expand Up @@ -1995,6 +1997,69 @@ struct sdw_cdns_pdi *sdw_cdns_alloc_pdi(struct sdw_cdns *cdns,
}
EXPORT_SYMBOL(sdw_cdns_alloc_pdi);

/**
* sdw_cdns_assign_pdi - Assign a PDI
* @bus: SoundWire bus instance
* @dir: Data direction
*
* Return: A valid PDI instance or %NULL if none available.
*/
struct sdw_cdns_pdi *sdw_cdns_assign_pdi(struct sdw_bus *bus, u32 dir)
{
struct sdw_cdns *cdns = bus_to_cdns(bus);
struct sdw_cdns_streams *stream = &cdns->pcm;
struct sdw_cdns_pdi *pdis, *pdi;
size_t num_pdis;
int i;

if (dir == SDW_DATA_DIR_RX) {
num_pdis = stream->num_in;
pdis = stream->in;
} else {
num_pdis = stream->num_out;
pdis = stream->out;
}

spin_lock(&cdns->pdi_lock);
for (i = 0; i < num_pdis; i++) {
if (!pdis[i].assigned) {
pdi = &pdis[i];
goto found;
}
}

/* Indexes 0/1 are reserved for the Bulk transfer. */
for (i = 2; i < stream->num_bd; i++) {
if (!stream->bd[i].assigned) {
pdi = &stream->bd[i];
goto found;
}
}

spin_unlock(&cdns->pdi_lock);
return NULL;
found:
pdi->dir = dir;
pdi->assigned = true;
spin_unlock(&cdns->pdi_lock);
return pdi;
}
EXPORT_SYMBOL(sdw_cdns_assign_pdi);

/**
* sdw_cdns_release_pdi() - Release a PDI
* @bus: SoundWire bus instance
* @pdi: PDI instance
*/
void sdw_cdns_release_pdi(struct sdw_bus *bus, struct sdw_cdns_pdi *pdi)
{
struct sdw_cdns *cdns = bus_to_cdns(bus);

guard(spinlock)(&cdns->pdi_lock);
pdi->assigned = false;
}
EXPORT_SYMBOL(sdw_cdns_release_pdi);

/*
* the MIPI SoundWire CRC8 polynomial is X^8 + X^6 + X^3 + X^2 + 1, MSB first
* The value is (1)01001101 = 0x4D
Expand Down
25 changes: 4 additions & 21 deletions drivers/soundwire/cadence_master.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#ifndef __SDW_CADENCE_H
#define __SDW_CADENCE_H

#include <linux/soundwire/sdw_cadence.h>

#define SDW_CADENCE_GSYNC_KHZ 4 /* 4 kHz */
#define SDW_CADENCE_GSYNC_HZ (SDW_CADENCE_GSYNC_KHZ * 1000)

Expand All @@ -17,27 +19,6 @@

#define SDW_CADENCE_MCP_IP_OFFSET 0x4000

/**
* struct sdw_cdns_pdi: PDI (Physical Data Interface) instance
*
* @num: pdi number
* @intel_alh_id: link identifier
* @l_ch_num: low channel for PDI
* @h_ch_num: high channel for PDI
* @ch_count: total channel count for PDI
* @dir: data direction
* @type: stream type, (only PCM supported)
*/
struct sdw_cdns_pdi {
int num;
int intel_alh_id;
int l_ch_num;
int h_ch_num;
int ch_count;
enum sdw_data_direction dir;
enum sdw_stream_type type;
};

/**
* struct sdw_cdns_streams: Cadence stream data structure
*
Expand Down Expand Up @@ -114,6 +95,7 @@ struct sdw_cdns_dai_runtime {
* @ports: Data ports
* @num_ports: Total number of data ports
* @pcm: PCM streams
* @pdi_lock: synchronizes assignment of PDIs found in PCM streams
* @registers: Cadence registers
* @link_up: Link status
* @msg_count: Messages sent on bus
Expand All @@ -140,6 +122,7 @@ struct sdw_cdns {
int num_ports;

struct sdw_cdns_streams pcm;
spinlock_t pdi_lock;

int pdi_loopback_source;
int pdi_loopback_target;
Expand Down
37 changes: 30 additions & 7 deletions drivers/soundwire/intel.c
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,22 @@ intel_pdi_alh_configure(struct sdw_intel *sdw, struct sdw_cdns_pdi *pdi)
intel_writel(alh, SDW_ALH_STRMZCFG(pdi->intel_alh_id), conf);
}

/**
* sdw_intel_pdi_config - Configure specified PDI
* @bus: SoundWire bus instance
* @pdi: PDI instance to configure
*/
void sdw_intel_pdi_config(struct sdw_bus *bus, struct sdw_cdns_pdi *pdi)
{
struct sdw_cdns *cdns = bus_to_cdns(bus);
struct sdw_intel *sdw = cdns_to_intel(cdns);

intel_pdi_shim_configure(sdw, pdi);
intel_pdi_alh_configure(sdw, pdi);
sdw_cdns_config_stream(cdns, pdi->ch_count, pdi->dir, pdi);
}
EXPORT_SYMBOL(sdw_intel_pdi_config);

static int intel_params_stream(struct sdw_intel *sdw,
struct snd_pcm_substream *substream,
struct snd_soc_dai *dai,
Expand Down Expand Up @@ -1011,22 +1027,28 @@ static int intel_create_dai(struct sdw_cdns *cdns,
return 0;
}

static int intel_register_dai(struct sdw_intel *sdw)
static int intel_init_pdis(struct sdw_intel *sdw)
{
struct sdw_cdns_dai_runtime **dai_runtime_array;
struct sdw_cdns_stream_config config;
struct sdw_cdns *cdns = &sdw->cdns;
struct sdw_cdns_streams *stream;
struct snd_soc_dai_driver *dais;
int num_dai, ret, off = 0;
int ret;

/* Read the PDI config and initialize cadence PDI */
intel_pdi_init(sdw, &config);
ret = sdw_cdns_pdi_init(cdns, config);
ret = sdw_cdns_pdi_init(&sdw->cdns, config);
if (ret)
return ret;

intel_pdi_stream_ch_update(sdw, &sdw->cdns.pcm);
return 0;
}

static int intel_register_dai(struct sdw_intel *sdw)
{
struct sdw_cdns_dai_runtime **dai_runtime_array;
struct sdw_cdns *cdns = &sdw->cdns;
struct sdw_cdns_streams *stream;
struct snd_soc_dai_driver *dais;
int num_dai, ret, off = 0;

/* DAIs are created based on total number of PDIs supported */
num_dai = cdns->pcm.num_pdi;
Expand Down Expand Up @@ -1071,6 +1093,7 @@ const struct sdw_intel_hw_ops sdw_intel_cnl_hw_ops = {
.debugfs_init = intel_debugfs_init,
.debugfs_exit = intel_debugfs_exit,

.init_pdis = intel_init_pdis,
.register_dai = intel_register_dai,

.check_clock_stop = intel_check_clock_stop,
Expand Down
10 changes: 9 additions & 1 deletion drivers/soundwire/intel.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,18 @@ static inline void sdw_intel_debugfs_exit(struct sdw_intel *sdw)
SDW_INTEL_OPS(sdw, debugfs_exit)(sdw);
}

static inline int sdw_intel_init_pdis(struct sdw_intel *sdw)
{
if (SDW_INTEL_CHECK_OPS(sdw, init_pdis))
return SDW_INTEL_OPS(sdw, init_pdis)(sdw);
return -ENOTSUPP;
}

static inline int sdw_intel_register_dai(struct sdw_intel *sdw)
{
if (SDW_INTEL_CHECK_OPS(sdw, register_dai))
return SDW_INTEL_OPS(sdw, register_dai)(sdw);
return -ENOTSUPP;
return 0;
}

static inline void sdw_intel_check_clock_stop(struct sdw_intel *sdw)
Expand Down Expand Up @@ -262,6 +269,7 @@ int intel_start_bus_after_reset(struct sdw_intel *sdw);
void intel_check_clock_stop(struct sdw_intel *sdw);
int intel_start_bus_after_clock_stop(struct sdw_intel *sdw);
int intel_stop_bus(struct sdw_intel *sdw, bool clock_stop, bool wake_enable);
int sdw_intel_init_pdis(struct sdw_intel *sdw);

/* common bank switch routines */
int intel_pre_bank_switch(struct sdw_intel *sdw);
Expand Down
23 changes: 15 additions & 8 deletions drivers/soundwire/intel_ace2x.c
Original file line number Diff line number Diff line change
Expand Up @@ -1058,24 +1058,30 @@ static int intel_create_dai(struct sdw_cdns *cdns,
return 0;
}

static int intel_register_dai(struct sdw_intel *sdw)
static int intel_init_pdis(struct sdw_intel *sdw)
{
struct sdw_cdns_dai_runtime **dai_runtime_array;
struct sdw_cdns_stream_config config;
struct sdw_cdns *cdns = &sdw->cdns;
struct sdw_cdns_streams *stream;
struct snd_soc_dai_driver *dais;
int num_dai;
int ret;
int off = 0;

/* Read the PDI config and initialize cadence PDI */
intel_pdi_init(sdw, &config);
ret = sdw_cdns_pdi_init(cdns, config);
ret = sdw_cdns_pdi_init(&sdw->cdns, config);
if (ret)
return ret;

intel_pdi_stream_ch_update(sdw, &sdw->cdns.pcm);
return 0;
}

static int intel_register_dai(struct sdw_intel *sdw)
{
struct sdw_cdns_dai_runtime **dai_runtime_array;
struct sdw_cdns *cdns = &sdw->cdns;
struct sdw_cdns_streams *stream;
struct snd_soc_dai_driver *dais;
int num_dai;
int ret;
int off = 0;

/* DAIs are created based on total number of PDIs supported */
num_dai = cdns->pcm.num_pdi;
Expand Down Expand Up @@ -1149,6 +1155,7 @@ const struct sdw_intel_hw_ops sdw_intel_lnl_hw_ops = {

.get_link_count = intel_get_link_count,

.init_pdis = intel_init_pdis,
.register_dai = intel_register_dai,

.check_clock_stop = intel_check_clock_stop,
Expand Down
4 changes: 4 additions & 0 deletions drivers/soundwire/intel_auxdevice.c
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,10 @@ int intel_link_startup(struct auxiliary_device *auxdev)
if (ret)
goto err_init;

ret = sdw_intel_init_pdis(sdw);
if (ret)
goto err_power_up;

/* Register DAIs */
ret = sdw_intel_register_dai(sdw);
if (ret) {
Expand Down
35 changes: 35 additions & 0 deletions include/linux/soundwire/sdw_cadence.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
/* Copyright(c) 2024-2026 Intel Corporation */

#ifndef ___SDW_CADENCE_H
#define ___SDW_CADENCE_H

#include <linux/soundwire/sdw.h>

/**
* struct sdw_cdns_pdi: PDI (Physical Data Interface) instance
*
* @num: pdi number
* @intel_alh_id: link identifier
* @l_ch_num: low channel for PDI
* @h_ch_num: high channel for PDI
* @ch_count: total channel count for PDI
* @dir: data direction
* @type: stream type, (only PCM supported)
* @assigned: whether PDI is in use
*/
struct sdw_cdns_pdi {
int num;
int intel_alh_id;
int l_ch_num;
int h_ch_num;
int ch_count;
enum sdw_data_direction dir;
enum sdw_stream_type type;
bool assigned;
};

struct sdw_cdns_pdi *sdw_cdns_assign_pdi(struct sdw_bus *bus, u32 dir);
void sdw_cdns_release_pdi(struct sdw_bus *bus, struct sdw_cdns_pdi *pdi);

#endif
Loading
Loading