Some minor SDCA preparation
Subsystems (3)
Charles Keepax
maintainercover Some minor SDCA preparation
Make some small fixups and add some minor missing features that will be needed for the next major part of the SDCA work. This series doesn't do a lot on its own, but as the next series will add all the ALSA control and DAPM graph creation it's probably best to get these minor things out of the way to simplify review on the bigger stuff.
Thanks,
Charles
Charles Keepax (6):
ASoC: SDCA: Tidy up initialization write parsing
ASoC: SDCA: Use __free() to manage local buffers
ASoC: SDCA: Allow naming of imp def controls
ASoC: SDCA: Add type flag for Controls
ASoC: SDCA: Add SDCA Control Range data access helper
ASoC: SDCA: Add support for GE Entity properties
include/sound/sdca_function.h | 90 ++++++++ sound/soc/sdca/sdca_functions.c | 374 ++++++++++++++++++++++++++++---- 2 files changed, 422 insertions(+), 42 deletions(-)
Signature · 1 line
2.39.5
Charles Keepax
maintainerPATCH 1/6 ASoC: SDCA: Tidy up initialization write parsing
Slightly neaten up the initialization write code to overlay a struct rather than shifting the pointer along manually. This also removes the Sparse warning:
sound/soc/sdca/sdca_functions.c:233:36: warning: cast to restricted __le32
--- sound/soc/sdca/sdca_functions.c | 43 ++++++++++++++++----------------- 1 file changed, 21 insertions(+), 22 deletions(-)
sound/soc/sdca/sdca_functions.c +21 -22
@@ -10,6 +10,7 @@#include <linux/acpi.h> #include <linux/byteorder/generic.h> +#include <linux/cleanup.h> #include <linux/device.h> #include <linux/dev_printk.h> #include <linux/module.h>
@@ -186,14 +187,18 @@ void sdca_lookup_functions(struct sdw_slave *slave) }EXPORT_SYMBOL_NS (sdca_lookup_functions,"SND_SOC_SDCA" ); +struct raw_init_write { +__le32 addr; +u8 val; +} __packed; +static int find_sdca_init_table (struct device *dev,struct fwnode_handle *function_node,struct sdca_function_data *function) { + struct raw_init_write *raw __free(kfree) = NULL;struct sdca_init_write *init_write; -int write_size =sizeof (init_write->addr) +sizeof (init_write->val); -u8 *init_list, *init_iter; -int num_init_writes; +int i, num_init_writes; num_init_writes =fwnode_property_count_u8 (function_node,"mipi-sdca-function-initialization-table" );
@@ -203,7 +208,7 @@ static int find_sdca_init_table(struct device *dev,dev_err (dev,"%pfwP: failed to read initialization table: %d\n" , function_node, num_init_writes);return num_init_writes; - }else if (num_init_writes % write_size !=0 ) { + }else if (num_init_writes %sizeof (*raw) !=0 ) {dev_err (dev,"%pfwP: init table size invalid\n" , function_node);return -EINVAL ; }else if (num_init_writes >SDCA_MAX_INIT_COUNT ) {
@@ -211,33 +216,27 @@ static int find_sdca_init_table(struct device *dev,return -EINVAL ; } - init_write =devm_kcalloc (dev, num_init_writes / write_size, -sizeof (*init_write),GFP_KERNEL ); -if (!init_write) -return -ENOMEM ; - - init_list =kcalloc (num_init_writes,sizeof (*init_list),GFP_KERNEL ); -if (!init_list) + raw =kzalloc (num_init_writes,GFP_KERNEL ); +if (!raw)return -ENOMEM ;fwnode_property_read_u8_array (function_node,"mipi-sdca-function-initialization-table" , - init_list, num_init_writes); + (u8 *)raw, num_init_writes); - function->num_init_table = num_init_writes; - function->init_table = init_write; + num_init_writes /=sizeof (*raw); -for (init_iter = init_list; init_iter < init_list + num_init_writes;) { -u32 *addr = (u32 *)init_iter; - - init_write->addr =le32_to_cpu (*addr); - init_iter +=sizeof (init_write->addr); + init_write =devm_kcalloc (dev, num_init_writes,sizeof (*init_write),GFP_KERNEL ); +if (!init_write) +return -ENOMEM ; - init_write->val = *init_iter; - init_iter +=sizeof (init_write->val); +for (i =0 ; i < num_init_writes; i++) { + init_write[i].addr =le32_to_cpu (raw[i].addr); + init_write[i].val = raw[i].val; } -kfree (init_list); + function->num_init_table = num_init_writes; + function->init_table = init_write;return 0 ; }
Signature · 1 line
2.39.5
Charles Keepax
maintainerPATCH 2/6 ASoC: SDCA: Use __free() to manage local buffers
In reply to Charles KeepaxUse the cleanup.h helpers to manage some local buffers, this cleans up the error paths a little.
--- sound/soc/sdca/sdca_functions.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-)
sound/soc/sdca/sdca_functions.c +4 -13
@@ -913,9 +913,9 @@ static int find_sdca_entity_pde(struct device *dev, {static const int mult_delay =3 ;struct sdca_entity_pde *power = &entity->pde; + u32 *delay_list __free(kfree) = NULL;struct sdca_pde_delay *delays;int num_delays; -u32 *delay_list;int i, j; num_delays = fwnode_property_count_u32(entity_node,
@@ -962,8 +962,6 @@ static int find_sdca_entity_pde(struct device *dev, power->num_max_delay = num_delays; power->max_delay = delays; -kfree (delay_list); -return 0 ; }
@@ -1022,8 +1020,8 @@ static int find_sdca_entities(struct device *dev,struct fwnode_handle *function_node, struct sdca_function_data *function) { + u32 *entity_list __free(kfree) = NULL;struct sdca_entity *entities; -u32 *entity_list;int num_entities;int i, ret;
@@ -1054,8 +1052,6 @@ static int find_sdca_entities(struct device *dev,for (i =0 ; i < num_entities; i++) entities[i].id = entity_list[i]; -kfree (entity_list); -/* now read subproperties */ for (i =0 ; i < num_entities; i++) {char entity_property[SDCA_PROPERTY_LENGTH ];
@@ -1170,8 +1166,8 @@ static int find_sdca_entity_connection_pde(struct device *dev, struct sdca_entity *entity) {struct sdca_entity_pde *power = &entity->pde; + u32 *managed_list __free(kfree) = NULL;struct sdca_entity **managed; -u32 *managed_list;int num_managed;int i;
@@ -1205,15 +1201,12 @@ static int find_sdca_entity_connection_pde(struct device *dev,if (!managed[i]) {dev_err (dev,"%s: failed to find entity with id %#x\n" , entity->label, managed_list[i]); -kfree (managed_list);return -EINVAL ; }dev_info (dev,"%s -> %s\n" , managed[i]->label, entity->label); } -kfree (managed_list); - power->num_managed = num_managed; power->managed = managed;
@@ -1453,9 +1446,9 @@ static int find_sdca_clusters(struct device *dev,struct fwnode_handle *function_node, struct sdca_function_data *function) { + u32 *cluster_list __free(kfree) = NULL;struct sdca_cluster *clusters;int num_clusters; -u32 *cluster_list;int i, ret; num_clusters =fwnode_property_count_u32 (function_node,"mipi-sdca-cluster-id-list" );
@@ -1484,8 +1477,6 @@ static int find_sdca_clusters(struct device *dev,for (i =0 ; i < num_clusters; i++) clusters[i].id = cluster_list[i]; -kfree (cluster_list); -/* now read subproperties */ for (i =0 ; i < num_clusters; i++) {char cluster_property[SDCA_PROPERTY_LENGTH ];
Signature · 1 line
2.39.5
Charles Keepax
maintainerPATCH 3/6 ASoC: SDCA: Allow naming of imp def controls
In reply to Charles KeepaxImplementation defined controls will not be present in the large list of known controls for SDCA. The driver should not return an error for these, because it is perfectly legal to have implementation defined controls. Update the handling to instead generate a generic name.
--- sound/soc/sdca/sdca_functions.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
sound/soc/sdca/sdca_functions.c +6 -8
@@ -241,7 +241,8 @@ static int find_sdca_init_table(struct device *dev,return 0 ; } -static const char *find_sdca_control_label (const struct sdca_entity *entity, +static const char *find_sdca_control_label (struct device *dev, +const struct sdca_entity *entity,const struct sdca_control *control) {switch (SDCA_CTL_TYPE (entity->type, control->sel)) {
@@ -530,7 +531,7 @@ static const char *find_sdca_control_label(const struct sdca_entity *entity,case SDCA_CTL_TYPE_S (ENTITY_0 ,DEVICE_SDCA_VERSION ):return SDCA_CTL_DEVICE_SDCA_VERSION_NAME ;default : -return NULL ; +return devm_kasprintf (dev,GFP_KERNEL ,"Imp-Def %#x" , control->sel); } }
@@ -739,12 +740,9 @@ static int find_sdca_entity_control(struct device *dev, struct sdca_entity *entiif (!ret) control->interrupt_position = tmp; - control->label =find_sdca_control_label (entity, control); -if (!control->label) { -dev_err (dev,"%s: control %#x: name not found\n" , - entity->label, control->sel); -return -EINVAL ; - } + control->label =find_sdca_control_label (dev, entity, control); +if (!control->label) +return -ENOMEM ; control->nbits =find_sdca_control_bits (entity, control);
Signature · 1 line
2.39.5
Charles Keepax
maintainerPATCH 4/6 ASoC: SDCA: Add type flag for Controls
In reply to Charles KeepaxSDCA Controls come in a variety of data formats, to simplify later parsing work out this data type as the control is parsed and stash it for later use.
--- include/sound/sdca_function.h | 23 +++++ sound/soc/sdca/sdca_functions.c | 173 ++++++++++++++++++++++++++++++++ 2 files changed, 196 insertions(+)
include/sound/sdca_function.h +23 -0
@@ -600,6 +600,27 @@ enum sdca_entity0_controls {#define SDCA_CTL_DEVICE_VERSION_NAME "Device Version"#define SDCA_CTL_DEVICE_SDCA_VERSION_NAME "Device SDCA Version" +/** +* enum sdca_control_datatype - SDCA Control Data Types +* +* Data Types as described in the SDCA specification v1.0 section +* 7.3. +*/ +enum sdca_control_datatype { +SDCA_CTL_DATATYPE_ONEBIT , +SDCA_CTL_DATATYPE_INTEGER , +SDCA_CTL_DATATYPE_SPEC_ENCODED_VALUE , +SDCA_CTL_DATATYPE_BCD , +SDCA_CTL_DATATYPE_Q7P8DB , +SDCA_CTL_DATATYPE_BYTEINDEX , +SDCA_CTL_DATATYPE_POSTURENUMBER , +SDCA_CTL_DATATYPE_DP_INDEX , +SDCA_CTL_DATATYPE_BITINDEX , +SDCA_CTL_DATATYPE_BITMAP , +SDCA_CTL_DATATYPE_GUID , +SDCA_CTL_DATATYPE_IMPDEF , +}; +/** * enum sdca_access_mode - SDCA Control access mode *
@@ -653,6 +674,7 @@ struct sdca_control_range {* @cn_list: A bitmask showing the valid Control Numbers within this Control, * Control Numbers typically represent channels. * @range: Buffer describing valid range of values for the Control. +* @type: Format of the data in the Control. * @mode: Access mode of the Control. * @layers: Bitmask of access layers of the Control. * @deferrable: Indicates if the access to the Control can be deferred.
@@ -669,6 +691,7 @@ struct sdca_control {u64 cn_list;struct sdca_control_range range; +enum sdca_control_datatype type;enum sdca_access_mode mode;u8 layers;
sound/soc/sdca/sdca_functions.c +173 -0
185 lines not on this page · raw message
Signature · 1 line
2.39.5
Charles Keepax
maintainerPATCH 5/6 ASoC: SDCA: Add SDCA Control Range data access helper
In reply to Charles KeepaxSDCA Ranges are two dimensional arrays of data associated with controls, add a helper to provide an x,y access mechanism to the data and a helper to locate a specific value inside a range.
--- include/sound/sdca_function.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
include/sound/sdca_function.h +19 -0
@@ -1136,6 +1136,25 @@ struct sdca_function_data {unsigned int busy_max_delay; }; +static inline u32 sdca_range (struct sdca_control_range *range, +unsigned int col,unsigned int row) +{ +return range->data[(row * range->cols) + col]; +} + +static inline u32 sdca_range_search (struct sdca_control_range *range, +int search_col,int value,int result_col) +{ +int i; + +for (i =0 ; i < range->rows; i++) { +if (sdca_range (range, search_col, i) == value) +return sdca_range (range, result_col, i); + } + +return 0 ; +} +int sdca_parse_function (struct device *dev,struct sdca_function_desc *desc,struct sdca_function_data *function);
Signature · 1 line
2.39.5
Charles Keepax
maintainerPATCH 6/6 ASoC: SDCA: Add support for GE Entity properties
In reply to Charles KeepaxAdd support for parsing the Group Entity properties from DisCo/ACPI. Group Entities allow control of several other Entities, typically Selector Units, from a single control.
--- include/sound/sdca_function.h | 48 ++++++++++++ sound/soc/sdca/sdca_functions.c | 129 ++++++++++++++++++++++++++++++++ 2 files changed, 177 insertions(+)
include/sound/sdca_function.h +48 -0
@@ -44,6 +44,11 @@ struct sdca_function_desc;*/ #define SDCA_MAX_DELAY_COUNT 256 +/* +* Sanity check on size of affected controls data, can be expanded if needed. +*/ +#define SDCA_MAX_AFFECTED_COUNT 2048 +/** * enum sdca_function_type - SDCA Function Type codes * @SDCA_FUNCTION_TYPE_SMART_AMP: Amplifier with protection features.
@@ -927,11 +932,51 @@ enum sdca_entity_type { SDCA_ENTITY_TYPE_HIDE = 0x31, }; +/** +* struct sdca_ge_control - control entry in the affected controls list +* @id: Entity ID of the Control affected. +* @sel: Control Selector of the Control affected. +* @cn: Control Number of the Control affected. +* @val: Value written to Control for this Mode. +*/ +struct sdca_ge_control { +int id; +int sel; +int cn; +int val; +}; + +/** +* struct sdca_ge_mode - mode entry in the affected controls list +* @controls: Dynamically allocated array of controls written for this Mode. +* @num_controls: Number of controls written in this Mode. +* @val: GE Selector Mode value. +*/ +struct sdca_ge_mode { +struct sdca_ge_control *controls; +int num_controls; +int val; +}; + +/** +* struct sdca_entity_ge - information specific to Group Entities +* @kctl: ALSA control pointer that can be used by linked Entities. +* @modes: Dynamically allocated array of Modes and the Controls written +* in each mode. +* @num_modes: Number of Modes. +*/ +struct sdca_entity_ge { +struct snd_kcontrol_new *kctl; +struct sdca_ge_mode *modes; +int num_modes; +}; +/** * struct sdca_entity - information for one SDCA Entity * @label: String such as "OT 12". * @id: Identifier used for addressing. * @type: Type code for the Entity. +* @group: Pointer to Group Entity controlling this one, NULL if N/A. * @sources: Dynamically allocated array pointing to each input Entity * connected to this Entity. * @controls: Dynamically allocated array of Controls.
@@ -940,12 +985,14 @@ enum sdca_entity_type {* @iot: Input/Output Terminal specific Entity properties. * @cs: Clock Source specific Entity properties. * @pde: Power Domain Entity specific Entity properties. +* @ge: Group Entity specific Entity properties. */ struct sdca_entity {const char *label;int id;enum sdca_entity_type type; +struct sdca_entity *group;struct sdca_entity **sources;struct sdca_control *controls;int num_sources;
@@ -954,6 +1001,7 @@ struct sdca_entity {struct sdca_entity_iot iot;struct sdca_entity_cs cs;struct sdca_entity_pde pde; +struct sdca_entity_ge ge; }; };
sound/soc/sdca/sdca_functions.c +129 -0
153 lines not on this page · raw message
Signature · 1 line
2.39.5
Mark Brown
maintainerQuoted 10 lines · Charles Keepax
Make some small fixups and add some minor missing features that will be needed for the next major part of the SDCA work. This series doesn't do a lot on its own, but as the next series will add all the ALSA control and DAPM graph creation it's probably best to get these minor things out of the way to simplify review on the bigger stuff.
Thanks,
Charles[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
Thanks!
[1/6] ASoC: SDCA: Tidy up initialization write parsing
commit: 988adcb73669a4015974da9057d43226ddc1aa9d
[2/6] ASoC: SDCA: Use __free() to manage local buffers
commit: 0d16daa9405ef7de5c278183d4079013f39a51ac
[3/6] ASoC: SDCA: Allow naming of imp def controls
commit: 49680c9f13b64c13e79e1312c7616d0ab9775e4a
[4/6] ASoC: SDCA: Add type flag for Controls
commit: 2a4667f3d589524bd2fbfe4f7dc0e2f12b832e10
[5/6] ASoC: SDCA: Add SDCA Control Range data access helper
commit: 1bcbb88bedb17804491e692a3f1a38223e09152c
[6/6] ASoC: SDCA: Add support for GE Entity properties
commit: d1cd13f80dc6c8525c539a28d4eb1df913d542deAll being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark