Skip to content

Commit c57ad86

Browse files
charleskeepaxbroonie
authored andcommitted
ASoC: SDCA: Move SDCA search functions and export
The ASoC code for SDCA contains several helper functions that search for controls/ranges/etc. As the code evolves these helpers are likely to be useful to anything interacting with the stored DisCo data. Move the helpers into sdca_function.c and export them so other modules can also use them. Signed-off-by: Charles Keepax <[email protected]> Reviewed-by: Pierre-Louis Bossart <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent cbcb5f5 commit c57ad86

File tree

3 files changed

+74
-60
lines changed

3 files changed

+74
-60
lines changed

include/sound/sdca_function.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,4 +1316,15 @@ int sdca_parse_function(struct device *dev,
13161316
struct sdca_function_desc *desc,
13171317
struct sdca_function_data *function);
13181318

1319+
struct sdca_control *sdca_selector_find_control(struct device *dev,
1320+
struct sdca_entity *entity,
1321+
const int sel);
1322+
struct sdca_control_range *sdca_control_find_range(struct device *dev,
1323+
struct sdca_entity *entity,
1324+
struct sdca_control *control,
1325+
int cols, int rows);
1326+
struct sdca_control_range *sdca_selector_find_range(struct device *dev,
1327+
struct sdca_entity *entity,
1328+
int sel, int cols, int rows);
1329+
13191330
#endif

sound/soc/sdca/sdca_asoc.c

Lines changed: 13 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -26,53 +26,6 @@
2626
#include <sound/soc-dapm.h>
2727
#include <sound/tlv.h>
2828

29-
static struct sdca_control *selector_find_control(struct device *dev,
30-
struct sdca_entity *entity,
31-
const int sel)
32-
{
33-
int i;
34-
35-
for (i = 0; i < entity->num_controls; i++) {
36-
struct sdca_control *control = &entity->controls[i];
37-
38-
if (control->sel == sel)
39-
return control;
40-
}
41-
42-
dev_err(dev, "%s: control %#x: missing\n", entity->label, sel);
43-
return NULL;
44-
}
45-
46-
static struct sdca_control_range *control_find_range(struct device *dev,
47-
struct sdca_entity *entity,
48-
struct sdca_control *control,
49-
int cols, int rows)
50-
{
51-
struct sdca_control_range *range = &control->range;
52-
53-
if ((cols && range->cols != cols) || (rows && range->rows != rows) ||
54-
!range->data) {
55-
dev_err(dev, "%s: control %#x: ranges invalid (%d,%d)\n",
56-
entity->label, control->sel, range->cols, range->rows);
57-
return NULL;
58-
}
59-
60-
return range;
61-
}
62-
63-
static struct sdca_control_range *selector_find_range(struct device *dev,
64-
struct sdca_entity *entity,
65-
int sel, int cols, int rows)
66-
{
67-
struct sdca_control *control;
68-
69-
control = selector_find_control(dev, entity, sel);
70-
if (!control)
71-
return NULL;
72-
73-
return control_find_range(dev, entity, control, cols, rows);
74-
}
75-
7629
static bool exported_control(struct sdca_entity *entity, struct sdca_control *control)
7730
{
7831
switch (SDCA_CTL_TYPE(entity->type, control->sel)) {
@@ -213,15 +166,15 @@ static int entity_early_parse_ge(struct device *dev,
213166
const char **texts;
214167
int i;
215168

216-
control = selector_find_control(dev, entity, SDCA_CTL_GE_SELECTED_MODE);
169+
control = sdca_selector_find_control(dev, entity, SDCA_CTL_GE_SELECTED_MODE);
217170
if (!control)
218171
return -EINVAL;
219172

220173
if (control->layers != SDCA_ACCESS_LAYER_CLASS)
221174
dev_warn(dev, "%s: unexpected access layer: %x\n",
222175
entity->label, control->layers);
223176

224-
range = control_find_range(dev, entity, control, SDCA_SELECTED_MODE_NCOLS, 0);
177+
range = sdca_control_find_range(dev, entity, control, SDCA_SELECTED_MODE_NCOLS, 0);
225178
if (!range)
226179
return -EINVAL;
227180

@@ -443,7 +396,7 @@ static int entity_parse_pde(struct device *dev,
443396
unsigned int mask = 0;
444397
int i;
445398

446-
control = selector_find_control(dev, entity, SDCA_CTL_PDE_REQUESTED_PS);
399+
control = sdca_selector_find_control(dev, entity, SDCA_CTL_PDE_REQUESTED_PS);
447400
if (!control)
448401
return -EINVAL;
449402

@@ -452,7 +405,7 @@ static int entity_parse_pde(struct device *dev,
452405
dev_warn(dev, "%s: unexpected access layer: %x\n",
453406
entity->label, control->layers);
454407

455-
range = control_find_range(dev, entity, control, SDCA_REQUESTED_PS_NCOLS, 0);
408+
range = sdca_control_find_range(dev, entity, control, SDCA_REQUESTED_PS_NCOLS, 0);
456409
if (!range)
457410
return -EINVAL;
458411

@@ -499,8 +452,8 @@ static int entity_parse_su_device(struct device *dev,
499452
return -EINVAL;
500453
}
501454

502-
range = selector_find_range(dev, entity->group, SDCA_CTL_GE_SELECTED_MODE,
503-
SDCA_SELECTED_MODE_NCOLS, 0);
455+
range = sdca_selector_find_range(dev, entity->group, SDCA_CTL_GE_SELECTED_MODE,
456+
SDCA_SELECTED_MODE_NCOLS, 0);
504457
if (!range)
505458
return -EINVAL;
506459

@@ -613,7 +566,7 @@ static int entity_parse_su(struct device *dev,
613566
return -EINVAL;
614567
}
615568

616-
control = selector_find_control(dev, entity, SDCA_CTL_SU_SELECTOR);
569+
control = sdca_selector_find_control(dev, entity, SDCA_CTL_SU_SELECTOR);
617570
if (!control)
618571
return -EINVAL;
619572

@@ -643,7 +596,7 @@ static int entity_parse_mu(struct device *dev,
643596
return -EINVAL;
644597
}
645598

646-
control = selector_find_control(dev, entity, SDCA_CTL_MU_MIXER);
599+
control = sdca_selector_find_control(dev, entity, SDCA_CTL_MU_MIXER);
647600
if (!control)
648601
return -EINVAL;
649602

@@ -853,7 +806,7 @@ static int control_limit_kctl(struct device *dev,
853806
/*
854807
* FIXME: For now only handle the simple case of a single linear range
855808
*/
856-
range = control_find_range(dev, entity, control, SDCA_VOLUME_LINEAR_NCOLS, 1);
809+
range = sdca_control_find_range(dev, entity, control, SDCA_VOLUME_LINEAR_NCOLS, 1);
857810
if (!range)
858811
return -EINVAL;
859812

@@ -1140,9 +1093,9 @@ static int populate_rate_format(struct device *dev,
11401093
}
11411094

11421095
if (entity->iot.clock) {
1143-
range = selector_find_range(dev, entity->iot.clock,
1144-
SDCA_CTL_CS_SAMPLERATEINDEX,
1145-
SDCA_SAMPLERATEINDEX_NCOLS, 0);
1096+
range = sdca_selector_find_range(dev, entity->iot.clock,
1097+
SDCA_CTL_CS_SAMPLERATEINDEX,
1098+
SDCA_SAMPLERATEINDEX_NCOLS, 0);
11461099
if (!range)
11471100
return -EINVAL;
11481101

@@ -1154,7 +1107,7 @@ static int populate_rate_format(struct device *dev,
11541107
clock_rates = UINT_MAX;
11551108
}
11561109

1157-
range = selector_find_range(dev, entity, sel, SDCA_USAGE_NCOLS, 0);
1110+
range = sdca_selector_find_range(dev, entity, sel, SDCA_USAGE_NCOLS, 0);
11581111
if (!range)
11591112
return -EINVAL;
11601113

sound/soc/sdca/sdca_functions.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,5 +1941,55 @@ int sdca_parse_function(struct device *dev,
19411941
}
19421942
EXPORT_SYMBOL_NS(sdca_parse_function, "SND_SOC_SDCA");
19431943

1944+
struct sdca_control *sdca_selector_find_control(struct device *dev,
1945+
struct sdca_entity *entity,
1946+
const int sel)
1947+
{
1948+
int i;
1949+
1950+
for (i = 0; i < entity->num_controls; i++) {
1951+
struct sdca_control *control = &entity->controls[i];
1952+
1953+
if (control->sel == sel)
1954+
return control;
1955+
}
1956+
1957+
dev_err(dev, "%s: control %#x: missing\n", entity->label, sel);
1958+
return NULL;
1959+
}
1960+
EXPORT_SYMBOL_NS(sdca_selector_find_control, "SND_SOC_SDCA");
1961+
1962+
struct sdca_control_range *sdca_control_find_range(struct device *dev,
1963+
struct sdca_entity *entity,
1964+
struct sdca_control *control,
1965+
int cols, int rows)
1966+
{
1967+
struct sdca_control_range *range = &control->range;
1968+
1969+
if ((cols && range->cols != cols) || (rows && range->rows != rows) ||
1970+
!range->data) {
1971+
dev_err(dev, "%s: control %#x: ranges invalid (%d,%d)\n",
1972+
entity->label, control->sel, range->cols, range->rows);
1973+
return NULL;
1974+
}
1975+
1976+
return range;
1977+
}
1978+
EXPORT_SYMBOL_NS(sdca_control_find_range, "SND_SOC_SDCA");
1979+
1980+
struct sdca_control_range *sdca_selector_find_range(struct device *dev,
1981+
struct sdca_entity *entity,
1982+
int sel, int cols, int rows)
1983+
{
1984+
struct sdca_control *control;
1985+
1986+
control = sdca_selector_find_control(dev, entity, sel);
1987+
if (!control)
1988+
return NULL;
1989+
1990+
return sdca_control_find_range(dev, entity, control, cols, rows);
1991+
}
1992+
EXPORT_SYMBOL_NS(sdca_selector_find_range, "SND_SOC_SDCA");
1993+
19441994
MODULE_LICENSE("Dual BSD/GPL");
19451995
MODULE_DESCRIPTION("SDCA library");

0 commit comments

Comments
 (0)