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

Configure Feed

Select the types of activity you want to include in your feed.

ASoC: soc-component: add snd_soc_component_regmap_val_bytes()

Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> says:

component has component->val_bytes which is set via
snd_soc_component_setup_regmap(). But it can be calculated via
component->regmap. No need to keep it as component->val_bytes.

This patchset adds new snd_soc_component_regmap_val_bytes(),
and remove component->val_bytes / snd_soc_component_setup_regmap().

Link: https://patch.msgid.link/87a4wdzyxf.wl-kuninori.morimoto.gx@renesas.com

+46 -27
+1 -2
include/sound/soc-component.h
··· 224 224 int num_dai; 225 225 226 226 struct regmap *regmap; 227 - int val_bytes; 228 227 229 228 struct mutex io_mutex; 230 229 ··· 326 327 int snd_soc_component_set_bias_level(struct snd_soc_component *component, 327 328 enum snd_soc_bias_level level); 328 329 329 - void snd_soc_component_setup_regmap(struct snd_soc_component *component); 330 + int snd_soc_component_regmap_val_bytes(struct snd_soc_component *component); 330 331 #ifdef CONFIG_REGMAP 331 332 void snd_soc_component_init_regmap(struct snd_soc_component *component, 332 333 struct regmap *regmap);
+12 -5
sound/soc/soc-component.c
··· 342 342 return -ENOTSUPP; 343 343 } 344 344 345 - void snd_soc_component_setup_regmap(struct snd_soc_component *component) 345 + int snd_soc_component_regmap_val_bytes(struct snd_soc_component *component) 346 346 { 347 - int val_bytes = regmap_get_val_bytes(component->regmap); 347 + int val_bytes; 348 348 349 349 /* Errors are legitimate for non-integer byte multiples */ 350 - if (val_bytes > 0) 351 - component->val_bytes = val_bytes; 350 + 351 + if (!component->regmap) 352 + return 0; 353 + 354 + val_bytes = regmap_get_val_bytes(component->regmap); 355 + if (val_bytes < 0) 356 + return 0; 357 + 358 + return val_bytes; 352 359 } 360 + EXPORT_SYMBOL_GPL(snd_soc_component_regmap_val_bytes); 353 361 354 362 #ifdef CONFIG_REGMAP 355 363 ··· 376 368 struct regmap *regmap) 377 369 { 378 370 component->regmap = regmap; 379 - snd_soc_component_setup_regmap(component); 380 371 } 381 372 EXPORT_SYMBOL_GPL(snd_soc_component_init_regmap); 382 373
-2
sound/soc/soc-core.c
··· 2906 2906 if (!component->regmap) 2907 2907 component->regmap = dev_get_regmap(component->dev, 2908 2908 NULL); 2909 - if (component->regmap) 2910 - snd_soc_component_setup_regmap(component); 2911 2909 } 2912 2910 2913 2911 /* see for_each_component */
+12 -7
sound/soc/soc-ops.c
··· 472 472 { 473 473 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); 474 474 struct soc_bytes *params = (void *)kcontrol->private_value; 475 + int val_bytes = snd_soc_component_regmap_val_bytes(component); 475 476 476 477 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES; 477 - uinfo->count = params->num_regs * component->val_bytes; 478 + uinfo->count = params->num_regs * val_bytes; 478 479 479 480 return 0; 480 481 } ··· 486 485 { 487 486 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); 488 487 struct soc_bytes *params = (void *)kcontrol->private_value; 488 + int val_bytes = snd_soc_component_regmap_val_bytes(component); 489 489 int ret; 490 490 491 491 if (component->regmap) 492 492 ret = regmap_raw_read(component->regmap, params->base, 493 493 ucontrol->value.bytes.data, 494 - params->num_regs * component->val_bytes); 494 + params->num_regs * val_bytes); 495 495 else 496 496 ret = -EINVAL; 497 497 498 498 /* Hide any masked bytes to ensure consistent data reporting */ 499 499 if (ret == 0 && params->mask) { 500 - switch (component->val_bytes) { 500 + switch (val_bytes) { 501 501 case 1: 502 502 ucontrol->value.bytes.data[0] &= ~params->mask; 503 503 break; ··· 524 522 { 525 523 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); 526 524 struct soc_bytes *params = (void *)kcontrol->private_value; 525 + int val_bytes = snd_soc_component_regmap_val_bytes(component); 527 526 unsigned int val, mask; 528 527 int ret, len; 529 528 530 529 if (!component->regmap || !params->num_regs) 531 530 return -EINVAL; 532 531 533 - len = params->num_regs * component->val_bytes; 532 + len = params->num_regs * val_bytes; 534 533 535 534 void *data __free(kfree) = kmemdup(ucontrol->value.bytes.data, len, 536 535 GFP_KERNEL | GFP_DMA); ··· 550 547 551 548 val &= params->mask; 552 549 553 - switch (component->val_bytes) { 550 + switch (val_bytes) { 554 551 case 1: 555 552 ((u8 *)data)[0] &= ~params->mask; 556 553 ((u8 *)data)[0] |= val; ··· 673 670 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); 674 671 struct soc_mreg_control *mc = 675 672 (struct soc_mreg_control *)kcontrol->private_value; 673 + int val_bytes = snd_soc_component_regmap_val_bytes(component); 676 674 unsigned int regbase = mc->regbase; 677 675 unsigned int regcount = mc->regcount; 678 - unsigned int regwshift = component->val_bytes * BITS_PER_BYTE; 676 + unsigned int regwshift = val_bytes * BITS_PER_BYTE; 679 677 unsigned int regwmask = GENMASK(regwshift - 1, 0); 680 678 unsigned long mask = GENMASK(mc->nbits - 1, 0); 681 679 long val = 0; ··· 718 714 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); 719 715 struct soc_mreg_control *mc = 720 716 (struct soc_mreg_control *)kcontrol->private_value; 717 + int val_bytes = snd_soc_component_regmap_val_bytes(component); 721 718 unsigned int regbase = mc->regbase; 722 719 unsigned int regcount = mc->regcount; 723 - unsigned int regwshift = component->val_bytes * BITS_PER_BYTE; 720 + unsigned int regwshift = val_bytes * BITS_PER_BYTE; 724 721 unsigned int regwmask = GENMASK(regwshift - 1, 0); 725 722 unsigned long mask = GENMASK(mc->nbits - 1, 0); 726 723 long val = ucontrol->value.integer.value[0];
+5 -3
sound/soc/tegra/tegra210_ahub.c
··· 20 20 struct snd_soc_component *cmpnt = snd_soc_dapm_kcontrol_to_component(kctl); 21 21 struct tegra_ahub *ahub = snd_soc_component_get_drvdata(cmpnt); 22 22 struct soc_enum *e = (struct soc_enum *)kctl->private_value; 23 + int val_bytes = snd_soc_component_regmap_val_bytes(cmpnt); 23 24 unsigned int reg, i, bit_pos = 0; 24 25 25 26 /* ··· 36 35 37 36 if (reg_val) { 38 37 bit_pos = ffs(reg_val) + 39 - (8 * cmpnt->val_bytes * i); 38 + (8 * val_bytes * i); 40 39 break; 41 40 } 42 41 } ··· 60 59 struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_to_dapm(kctl); 61 60 struct soc_enum *e = (struct soc_enum *)kctl->private_value; 62 61 struct snd_soc_dapm_update update[TEGRA_XBAR_UPDATE_MAX_REG] = { }; 62 + int val_bytes = snd_soc_component_regmap_val_bytes(cmpnt); 63 63 unsigned int *item = uctl->value.enumerated.item; 64 64 unsigned int value = e->values[item[0]]; 65 65 unsigned int i, bit_pos, reg_idx = 0, reg_val = 0; ··· 71 69 72 70 if (value) { 73 71 /* Get the register index and value to set */ 74 - reg_idx = (value - 1) / (8 * cmpnt->val_bytes); 75 - bit_pos = (value - 1) % (8 * cmpnt->val_bytes); 72 + reg_idx = (value - 1) / (8 * val_bytes); 73 + bit_pos = (value - 1) % (8 * val_bytes); 76 74 reg_val = BIT(bit_pos); 77 75 } 78 76
+12 -6
sound/soc/tegra/tegra210_mbdrc.c
··· 307 307 struct tegra_soc_bytes *params = (void *)kcontrol->private_value; 308 308 struct snd_soc_component *cmpnt = snd_kcontrol_chip(kcontrol); 309 309 struct tegra210_ope *ope = snd_soc_component_get_drvdata(cmpnt); 310 + int val_bytes = snd_soc_component_regmap_val_bytes(cmpnt); 310 311 u32 *data = (u32 *)ucontrol->value.bytes.data; 311 312 u32 regs = params->soc.base; 312 313 u32 mask = params->soc.mask; 313 314 u32 shift = params->shift; 314 315 unsigned int i; 315 316 316 - for (i = 0; i < params->soc.num_regs; i++, regs += cmpnt->val_bytes) { 317 + for (i = 0; i < params->soc.num_regs; i++, regs += val_bytes) { 317 318 regmap_read(ope->mbdrc_regmap, regs, &data[i]); 318 319 319 320 data[i] = ((data[i] & mask) >> shift); ··· 329 328 struct tegra_soc_bytes *params = (void *)kcontrol->private_value; 330 329 struct snd_soc_component *cmpnt = snd_kcontrol_chip(kcontrol); 331 330 struct tegra210_ope *ope = snd_soc_component_get_drvdata(cmpnt); 331 + int val_bytes = snd_soc_component_regmap_val_bytes(cmpnt); 332 332 u32 *data = (u32 *)ucontrol->value.bytes.data; 333 333 u32 regs = params->soc.base; 334 334 u32 mask = params->soc.mask; ··· 337 335 bool change = false; 338 336 unsigned int i; 339 337 340 - for (i = 0; i < params->soc.num_regs; i++, regs += cmpnt->val_bytes) { 338 + for (i = 0; i < params->soc.num_regs; i++, regs += val_bytes) { 341 339 bool update = false; 342 340 343 341 regmap_update_bits_check(ope->mbdrc_regmap, regs, mask, ··· 355 353 struct tegra_soc_bytes *params = (void *)kcontrol->private_value; 356 354 struct snd_soc_component *cmpnt = snd_kcontrol_chip(kcontrol); 357 355 struct tegra210_ope *ope = snd_soc_component_get_drvdata(cmpnt); 356 + int val_bytes = snd_soc_component_regmap_val_bytes(cmpnt); 358 357 u32 *data = (u32 *)ucontrol->value.bytes.data; 359 358 u32 regs = params->soc.base; 360 359 u32 num_regs = params->soc.num_regs; 361 360 u32 val; 362 361 unsigned int i; 363 362 364 - for (i = 0; i < num_regs; i += 4, regs += cmpnt->val_bytes) { 363 + for (i = 0; i < num_regs; i += 4, regs += val_bytes) { 365 364 regmap_read(ope->mbdrc_regmap, regs, &val); 366 365 367 366 data[i] = (val & TEGRA210_MBDRC_THRESH_1ST_MASK) >> ··· 384 381 struct tegra_soc_bytes *params = (void *)kcontrol->private_value; 385 382 struct snd_soc_component *cmpnt = snd_kcontrol_chip(kcontrol); 386 383 struct tegra210_ope *ope = snd_soc_component_get_drvdata(cmpnt); 384 + int val_bytes = snd_soc_component_regmap_val_bytes(cmpnt); 387 385 u32 *data = (u32 *)ucontrol->value.bytes.data; 388 386 u32 regs = params->soc.base; 389 387 u32 num_regs = params->soc.num_regs; 390 388 bool change = false; 391 389 unsigned int i; 392 390 393 - for (i = 0; i < num_regs; i += 4, regs += cmpnt->val_bytes) { 391 + for (i = 0; i < num_regs; i += 4, regs += val_bytes) { 394 392 bool update = false; 395 393 396 394 data[i] = (((data[i] >> TEGRA210_MBDRC_THRESH_1ST_SHIFT) & ··· 417 413 { 418 414 struct tegra_soc_bytes *params = (void *)kcontrol->private_value; 419 415 struct snd_soc_component *cmpnt = snd_kcontrol_chip(kcontrol); 416 + int val_bytes = snd_soc_component_regmap_val_bytes(cmpnt); 420 417 u32 *data = (u32 *)ucontrol->value.bytes.data; 421 418 422 - memset(data, 0, params->soc.num_regs * cmpnt->val_bytes); 419 + memset(data, 0, params->soc.num_regs * val_bytes); 423 420 424 421 return 0; 425 422 } ··· 431 426 struct tegra_soc_bytes *params = (void *)kcontrol->private_value; 432 427 struct snd_soc_component *cmpnt = snd_kcontrol_chip(kcontrol); 433 428 struct tegra210_ope *ope = snd_soc_component_get_drvdata(cmpnt); 429 + int val_bytes = snd_soc_component_regmap_val_bytes(cmpnt); 434 430 u32 reg_ctrl = params->soc.base; 435 - u32 reg_data = reg_ctrl + cmpnt->val_bytes; 431 + u32 reg_data = reg_ctrl + val_bytes; 436 432 u32 *data = (u32 *)ucontrol->value.bytes.data; 437 433 438 434 tegra210_mbdrc_write_ram(ope->mbdrc_regmap, reg_ctrl, reg_data,
+4 -2
sound/soc/tegra/tegra210_peq.c
··· 148 148 struct tegra_soc_bytes *params = (void *)kcontrol->private_value; 149 149 struct snd_soc_component *cmpnt = snd_kcontrol_chip(kcontrol); 150 150 struct tegra210_ope *ope = snd_soc_component_get_drvdata(cmpnt); 151 + int val_bytes = snd_soc_component_regmap_val_bytes(cmpnt); 151 152 u32 i, reg_ctrl = params->soc.base; 152 - u32 reg_data = reg_ctrl + cmpnt->val_bytes; 153 + u32 reg_data = reg_ctrl + val_bytes; 153 154 s32 *data = (s32 *)biquad_coeff_buffer; 154 155 155 156 pm_runtime_get_sync(cmpnt->dev); ··· 172 171 struct tegra_soc_bytes *params = (void *)kcontrol->private_value; 173 172 struct snd_soc_component *cmpnt = snd_kcontrol_chip(kcontrol); 174 173 struct tegra210_ope *ope = snd_soc_component_get_drvdata(cmpnt); 174 + int val_bytes = snd_soc_component_regmap_val_bytes(cmpnt); 175 175 u32 i, reg_ctrl = params->soc.base; 176 - u32 reg_data = reg_ctrl + cmpnt->val_bytes; 176 + u32 reg_data = reg_ctrl + val_bytes; 177 177 s32 *data = (s32 *)biquad_coeff_buffer; 178 178 179 179 for (i = 0; i < params->soc.num_regs; i++)