Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ASoC: SDCA: Factor out helper to process Control defaults

The indentation of the loop processing writing out SDCA Control default
values is getting a bit large. Reduce indentation and make adding more
functionality easier by factoring out the Control handling into a helper
function.

Tested-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Reviewed-by: Maciej Strozek <mstrozek@opensource.cirrus.com>
Reviewed-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
Tested-by: Richard Fitzgerald <rf@opensource.cirrus.com>
Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
Link: https://patch.msgid.link/20251120153023.2105663-9-ckeepax@opensource.cirrus.com
Reviewed-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Charles Keepax and committed by
Mark Brown
222cbe17 fb62da31

+39 -22
+39 -22
sound/soc/sdca/sdca_regmap.c
··· 275 275 } 276 276 EXPORT_SYMBOL_NS(sdca_regmap_populate_constants, "SND_SOC_SDCA"); 277 277 278 + static int populate_control_defaults(struct device *dev, struct regmap *regmap, 279 + struct sdca_function_data *function, 280 + struct sdca_entity *entity, 281 + struct sdca_control *control) 282 + { 283 + int i, ret; 284 + int cn; 285 + 286 + if (control->mode == SDCA_ACCESS_MODE_DC) 287 + return 0; 288 + 289 + if (!control->has_default && !control->has_fixed) 290 + return 0; 291 + 292 + i = 0; 293 + for_each_set_bit(cn, (unsigned long *)&control->cn_list, 294 + BITS_PER_TYPE(control->cn_list)) { 295 + unsigned int reg; 296 + 297 + reg = SDW_SDCA_CTL(function->desc->adr, entity->id, control->sel, cn); 298 + 299 + ret = regmap_write(regmap, reg, control->values[i]); 300 + if (ret) { 301 + dev_err(dev, "Failed to write default %#x: %d\n", 302 + reg, ret); 303 + return ret; 304 + } 305 + 306 + i++; 307 + } 308 + 309 + return 0; 310 + } 311 + 278 312 /** 279 313 * sdca_regmap_write_defaults - write out DisCo defaults to device 280 314 * @dev: Pointer to the device. ··· 324 290 int sdca_regmap_write_defaults(struct device *dev, struct regmap *regmap, 325 291 struct sdca_function_data *function) 326 292 { 327 - int i, j, k; 293 + int i, j; 328 294 int ret; 329 295 330 296 for (i = 0; i < function->num_entities; i++) { ··· 332 298 333 299 for (j = 0; j < entity->num_controls; j++) { 334 300 struct sdca_control *control = &entity->controls[j]; 335 - int cn; 336 301 337 - if (control->mode == SDCA_ACCESS_MODE_DC) 338 - continue; 339 - 340 - if (!control->has_default && !control->has_fixed) 341 - continue; 342 - 343 - k = 0; 344 - for_each_set_bit(cn, (unsigned long *)&control->cn_list, 345 - BITS_PER_TYPE(control->cn_list)) { 346 - unsigned int reg; 347 - 348 - reg = SDW_SDCA_CTL(function->desc->adr, entity->id, 349 - control->sel, cn); 350 - 351 - ret = regmap_write(regmap, reg, control->values[k]); 352 - if (ret) 353 - return ret; 354 - 355 - k++; 356 - } 302 + ret = populate_control_defaults(dev, regmap, function, 303 + entity, control); 304 + if (ret) 305 + return ret; 357 306 } 358 307 } 359 308