Skip to content

Commit 5728fd5

Browse files
committed
WIP: ASoC: SDCA: Initial SmartMic wake-on-voice support
Add state machine control for SmartMic voice trigger and an ALSA compressed stream to report the trigger event. This is initial support with the following limitations: - The compressed stream is currently a dummy implementation. It will report data available when there is a trigger event but the returned data is only a buffer of '.' characters. The plumbing into a SoundWire data stream is still to-do. - The voice trigger functionality is expected to be provided by the "SMPU 16" and "MFPU 16" entities, and a streaming output terminal connected directly to SMPU 16. - Detection is one-shot; stop and restart the stream to arm it again. Continuous triggers and concurrect triggers are not supported. - Only required MFPU algorithms are managed, and they must already be prepared and ready before arming. Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
1 parent 12c4f99 commit 5728fd5

10 files changed

Lines changed: 1528 additions & 21 deletions

File tree

‎include/sound/sdca_asoc.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
struct device;
1414
struct regmap;
1515
struct sdca_function_data;
16+
struct sdca_interrupt_info;
1617
struct sdca_pde_delay;
1718
struct snd_ctl_elem_value;
1819
struct snd_kcontrol;
@@ -80,6 +81,7 @@ int sdca_asoc_populate_dais(struct device *dev, struct sdca_function_data *funct
8081

8182
int sdca_asoc_populate_component(struct device *dev,
8283
struct sdca_function_data *function,
84+
struct sdca_interrupt_info *irq_info,
8385
struct snd_soc_component_driver *component_drv,
8486
struct snd_soc_dai_driver **dai_drv, int *num_dai_drv,
8587
const struct snd_soc_dai_ops *ops);

‎include/sound/sdca_function.h‎

Lines changed: 106 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef __SDCA_FUNCTION_H__
1010
#define __SDCA_FUNCTION_H__
1111

12+
#include <linux/bitmap.h>
1213
#include <linux/bits.h>
1314
#include <linux/types.h>
1415
#include <linux/hid.h>
@@ -48,6 +49,22 @@ struct sdca_function_desc;
4849
*/
4950
#define SDCA_MAX_AFFECTED_COUNT 2048
5051

52+
/*
53+
* Sanity limits for the DisCo Behavior Set library, can be expanded if
54+
* needed.
55+
*/
56+
#define SDCA_MAX_BEHAVIOR_SET_COUNT 256
57+
#define SDCA_MAX_BEHAVIOR_COUNT 256
58+
59+
/* BitIndex controls use up to 64 Control Number bytes (SDCA 1.0 sec. 7.3.9). */
60+
#define SDCA_MAX_CONTROL_NUMBERS 64
61+
#define SDCA_MAX_BMT_BITS (SDCA_MAX_CONTROL_NUMBERS * BITS_PER_BYTE)
62+
63+
/* Generic BitIndex Mapping Table layout (SDCA 1.0 sec. 7.3.9.2, Fig. 114). */
64+
#define SDCA_BMT_COLS 3
65+
#define SDCA_BMT_BIT 0
66+
#define SDCA_BMT_BEHAVIOR_SET 1
67+
5168
/**
5269
* enum sdca_function_type - SDCA Function Type codes
5370
* @SDCA_FUNCTION_TYPE_SMART_AMP: Amplifier with protection features.
@@ -787,6 +804,68 @@ struct sdca_control_range {
787804
u32 *data;
788805
};
789806

807+
/**
808+
* struct sdca_bmt_bits - selected BitIndex bits and their Control Numbers
809+
* @bits: Bitmap of selected bit positions in a BitIndex Mapping Table.
810+
* @control_numbers: Bitmap of Control Numbers containing selected bits.
811+
*
812+
* A BitIndex control is a set of byte controls, with one or more used bits
813+
* in each control. Each group of 8 bits in @bits corresponds to one byte
814+
* control. A bit is set in @bits if that control register bit is part of
815+
* the BMT.
816+
* (SDCA 1.0 Table 178, note 6: each Control Number holds eight BitIndex bits.)
817+
*
818+
* There is one bit in @control_numbers for each control. A bit is set in
819+
* @control_numbers if any of its bits is selected in @bits. This allows
820+
* quick iteration over only the Control Numbers.
821+
*/
822+
struct sdca_bmt_bits {
823+
DECLARE_BITMAP(bits, SDCA_MAX_BMT_BITS);
824+
DECLARE_BITMAP(control_numbers, SDCA_MAX_CONTROL_NUMBERS);
825+
};
826+
827+
/**
828+
* sdca_for_each_bmt_control - iterate over Control Numbers selected in a BMT
829+
* @number: Loop variable containing the Control Number.
830+
* @bmt: Pointer to the BMT bitmaps.
831+
*/
832+
#define sdca_for_each_bmt_control(number, bmt) \
833+
for_each_set_bit(number, (bmt)->control_numbers, SDCA_MAX_CONTROL_NUMBERS)
834+
835+
/**
836+
* sdca_bmt_control_mask - get the selected bits for one Control Number
837+
* @bmt: BMT bitmaps containing the selected bits.
838+
* @number: Control Number.
839+
*
840+
* Return: An eight-bit mask of the selected bits in the control byte.
841+
*/
842+
static inline u8 sdca_bmt_control_mask(const struct sdca_bmt_bits *bmt, unsigned int number)
843+
{
844+
return bitmap_get_value8(bmt->bits, number * BITS_PER_BYTE);
845+
}
846+
847+
/**
848+
* struct sdca_cbns - a list of Class Behavior Numbers
849+
* @cbns: Array of Class Behavior Numbers.
850+
* @num_cbns: Number of entries in @cbns.
851+
*/
852+
struct sdca_cbns {
853+
const u32 *cbns;
854+
int num_cbns;
855+
};
856+
857+
/**
858+
* struct sdca_behavior_set - one entry in the DisCo Behavior Set library
859+
* @id: Behavior Set identifier.
860+
* @cbns: Class Behavior Numbers in this set.
861+
* @num_cbns: Number of entries in @cbns.
862+
*/
863+
struct sdca_behavior_set {
864+
u32 id;
865+
u32 *cbns;
866+
int num_cbns;
867+
};
868+
790869
/**
791870
* struct sdca_control - information for one SDCA Control
792871
* @label: Name for the Control, from SDCA Specification v1.0, section 7.1.7.
@@ -1160,6 +1239,15 @@ struct sdca_entity_xu {
11601239
enum sdca_xu_reset_mechanism reset_mechanism;
11611240
};
11621241

1242+
/**
1243+
* struct sdca_entity_smpu - information specific to SMPU Entities
1244+
* @trigger_ready_max_delay: Host Trigger_Ready polling timeout in microseconds,
1245+
* clamped to at least 10 if described, or 0 if not described.
1246+
*/
1247+
struct sdca_entity_smpu {
1248+
unsigned int trigger_ready_max_delay;
1249+
};
1250+
11631251
/**
11641252
* struct sdca_entity - information for one SDCA Entity
11651253
* @label: String such as "OT 12".
@@ -1177,6 +1265,7 @@ struct sdca_entity_xu {
11771265
* @ge: Group Entity specific Entity properties.
11781266
* @hide: HIDE Entity specific Entity properties.
11791267
* @xu: XU Entity specific Entity properties.
1268+
* @smpu: SMPU Entity specific Entity properties.
11801269
*/
11811270
struct sdca_entity {
11821271
const char *label;
@@ -1195,6 +1284,7 @@ struct sdca_entity {
11951284
struct sdca_entity_ge ge;
11961285
struct sdca_entity_hide hide;
11971286
struct sdca_entity_xu xu;
1287+
struct sdca_entity_smpu smpu;
11981288
};
11991289
};
12001290

@@ -1413,9 +1503,11 @@ struct sdca_function_hid {
14131503
* @init_table: Pointer to a table of initialization writes.
14141504
* @entities: Dynamically allocated array of Entities.
14151505
* @clusters: Dynamically allocated array of Channel Clusters.
1506+
* @behavior_sets: Dynamically allocated array of Behavior Sets.
14161507
* @num_init_table: Number of initialization writes.
14171508
* @num_entities: Number of Entities reported in this Function.
14181509
* @num_clusters: Number of Channel Clusters reported in this Function.
1510+
* @num_behavior_sets: Number of Behavior Sets reported in this Function.
14191511
* @busy_max_delay: Maximum Function busy delay in microseconds, before an
14201512
* error should be reported.
14211513
* @reset_max_delay: Maximum Function reset delay in microseconds, before an
@@ -1429,9 +1521,11 @@ struct sdca_function_data {
14291521
struct sdca_init_write *init_table;
14301522
struct sdca_entity *entities;
14311523
struct sdca_cluster *clusters;
1524+
struct sdca_behavior_set *behavior_sets;
14321525
int num_init_table;
14331526
int num_entities;
14341527
int num_clusters;
1528+
int num_behavior_sets;
14351529

14361530
unsigned int busy_max_delay;
14371531
unsigned int reset_max_delay;
@@ -1443,7 +1537,7 @@ struct sdca_function_data {
14431537
};
14441538
};
14451539

1446-
static inline u32 sdca_range(struct sdca_control_range *range,
1540+
static inline u32 sdca_range(const struct sdca_control_range *range,
14471541
unsigned int col, unsigned int row)
14481542
{
14491543
return range->data[(row * range->cols) + col];
@@ -1467,10 +1561,10 @@ int sdca_parse_function(struct device *dev, struct sdca_function_data *function)
14671561
const char *sdca_find_terminal_name(enum sdca_terminal_type type);
14681562

14691563
struct sdca_control *sdca_selector_find_control(struct device *dev,
1470-
struct sdca_entity *entity,
1564+
const struct sdca_entity *entity,
14711565
const int sel);
14721566
struct sdca_control_range *sdca_control_find_range(struct device *dev,
1473-
struct sdca_entity *entity,
1567+
const struct sdca_entity *entity,
14741568
struct sdca_control *control,
14751569
int cols, int rows);
14761570
struct sdca_control_range *sdca_selector_find_range(struct device *dev,
@@ -1479,7 +1573,14 @@ struct sdca_control_range *sdca_selector_find_range(struct device *dev,
14791573
struct sdca_cluster *sdca_id_find_cluster(struct device *dev,
14801574
struct sdca_function_data *function,
14811575
const int id);
1482-
struct sdca_entity *sdca_find_entity_by_label(struct sdca_function_data *function,
1483-
const char *entity_label);
1576+
struct sdca_entity *sdca_find_entity_by_label(const struct sdca_function_data *function,
1577+
const char *entity_label);
1578+
struct sdca_behavior_set *sdca_find_behavior_set(const struct sdca_function_data *function,
1579+
unsigned int id);
1580+
bool sdca_behavior_set_contains_cbn(const struct sdca_behavior_set *set,
1581+
const struct sdca_cbns *cbns);
1582+
int sdca_lookup_bmt_bits(struct device *dev, const struct sdca_function_data *function,
1583+
const struct sdca_entity *entity, struct sdca_control *control,
1584+
const struct sdca_cbns *cbns, struct sdca_bmt_bits *bmt);
14841585

14851586
#endif

‎include/sound/sdca_wov.h‎

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/*
3+
* The MIPI SDCA specification is available for public downloads at
4+
* https://www.mipi.org/mipi-sdca-v1-0-download
5+
*
6+
* Copyright (C) 2026 Cirrus Logic, Inc. and
7+
* Cirrus Logic International Semiconductor Ltd.
8+
*/
9+
10+
#ifndef __SDCA_WOV_H__
11+
#define __SDCA_WOV_H__
12+
13+
#include <linux/kconfig.h>
14+
#include <linux/types.h>
15+
16+
#define SDCA_WOV_SMPU_LABEL "SMPU 16"
17+
#define SDCA_WOV_MAX_DRAIN_PASSES 32
18+
#define SDCA_WOV_READY_POLL_US 100
19+
20+
/* SDCA v1.0 Table 103 and v1.1 Table 144: algorithm usage tags. */
21+
#define SDCA_ALGORITHM_CBN_REQUIRED 300
22+
#define SDCA_ALGORITHM_CBN_CONDITIONAL_ON_TRIGGER 350
23+
#define SDCA_ALGORITHM_CBN_OPTIONAL_CLASS 400
24+
25+
/* SDCA v1.0 Table 124: Voice and Speech trigger behaviors. */
26+
#define SDCA_TRIGGER_CBN_VOICE 2000
27+
#define SDCA_TRIGGER_CBN_SPEECH 3000
28+
29+
struct device;
30+
struct sdca_entity;
31+
struct sdca_function_data;
32+
struct sdca_interrupt;
33+
struct sdca_interrupt_info;
34+
struct snd_soc_component_driver;
35+
struct snd_soc_dai_driver;
36+
struct snd_soc_dapm_route;
37+
struct snd_soc_pcm_stream;
38+
39+
int sdca_wov_alloc_state(struct sdca_interrupt *interrupt);
40+
void sdca_wov_free_state(struct sdca_interrupt *interrupt);
41+
42+
int sdca_wov_process_voice_trigger(struct sdca_interrupt *interrupt);
43+
44+
#if IS_ENABLED(CONFIG_SND_SOC_SDCA_IRQ)
45+
bool sdca_wov_is_terminal(struct device *dev, struct sdca_function_data *function,
46+
struct sdca_entity *entity);
47+
48+
int sdca_wov_populate_dapm(struct device *dev, struct sdca_entity *entity,
49+
struct snd_soc_dapm_route **route);
50+
51+
int sdca_wov_populate_dai(struct device *dev,
52+
struct sdca_function_data *function,
53+
struct snd_soc_dai_driver *dai,
54+
const struct snd_soc_pcm_stream *stream,
55+
int entity_index);
56+
57+
int sdca_wov_init_component(struct device *dev,
58+
struct sdca_function_data *function,
59+
struct sdca_interrupt_info *info,
60+
struct snd_soc_component_driver *component_drv);
61+
#else
62+
static inline bool sdca_wov_is_terminal(struct device *dev,
63+
struct sdca_function_data *function,
64+
struct sdca_entity *entity)
65+
{
66+
return false;
67+
}
68+
69+
static inline int sdca_wov_populate_dapm(struct device *dev, struct sdca_entity *entity,
70+
struct snd_soc_dapm_route **route)
71+
{
72+
return 0;
73+
}
74+
75+
static inline int sdca_wov_populate_dai(struct device *dev,
76+
struct sdca_function_data *function,
77+
struct snd_soc_dai_driver *dai,
78+
const struct snd_soc_pcm_stream *stream,
79+
int entity_index)
80+
{
81+
return 0;
82+
}
83+
84+
static inline int sdca_wov_init_component(struct device *dev,
85+
struct sdca_function_data *function,
86+
struct sdca_interrupt_info *info,
87+
struct snd_soc_component_driver *component_drv)
88+
{
89+
return 0;
90+
}
91+
#endif
92+
93+
#endif /* __SDCA_WOV_H__ */

‎sound/soc/sdca/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ config SND_SOC_SDCA_IRQ
2323
bool "SDCA IRQ support"
2424
select REGMAP
2525
select REGMAP_IRQ
26+
select SND_SOC_COMPRESS
2627
depends on SND_SOC_SDCA
2728
default y
2829
help

‎sound/soc/sdca/Makefile‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
snd-soc-sdca-y := sdca_functions.o sdca_device.o sdca_function_device.o \
44
sdca_regmap.o sdca_asoc.o sdca_ump.o
55
snd-soc-sdca-$(CONFIG_SND_SOC_SDCA_HID) += sdca_hid.o
6-
snd-soc-sdca-$(CONFIG_SND_SOC_SDCA_IRQ) += sdca_interrupts.o sdca_jack.o
6+
snd-soc-sdca-$(CONFIG_SND_SOC_SDCA_IRQ) += sdca_interrupts.o sdca_jack.o \
7+
sdca_wov.o
78
snd-soc-sdca-$(CONFIG_SND_SOC_SDCA_FDL) += sdca_fdl.o
89

910
snd-soc-sdca-class-y := sdca_class.o

0 commit comments

Comments
 (0)