aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars-Peter Clausen <lars@metafoo.de>2014-04-22 07:23:14 -0400
committerMark Brown <broonie@linaro.org>2014-04-22 08:38:21 -0400
commit907fe36a2cd572fe58d98be01457b945c47b996e (patch)
tree736044b15f615abaac7201f3ee9fc3e777c80499
parent9f68730dc8be948f0ae0601ef55321765813895c (diff)
ASoC: Move standard kcontrol helpers to the component level
After moving the IO layer inside ASoC to the component level we can now easily move the standard control helpers also to the component level. This allows to reuse the same standard helper control implementations for other components. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Mark Brown <broonie@linaro.org>
-rw-r--r--include/sound/soc.h20
-rw-r--r--sound/soc/soc-core.c221
2 files changed, 156 insertions, 85 deletions
diff --git a/include/sound/soc.h b/include/sound/soc.h
index a4179e73369a..c0b65fc90783 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -1250,6 +1250,22 @@ static inline bool snd_soc_codec_is_active(struct snd_soc_codec *codec)
1250} 1250}
1251 1251
1252/** 1252/**
1253 * snd_soc_kcontrol_component() - Returns the component that registered the
1254 * control
1255 * @kcontrol: The control for which to get the component
1256 *
1257 * Note: This function will work correctly if the control has been registered
1258 * for a component. Either with snd_soc_add_codec_controls() or
1259 * snd_soc_add_platform_controls() or via table based setup for either a
1260 * CODEC, a platform or component driver. Otherwise the behavior is undefined.
1261 */
1262static inline struct snd_soc_component *snd_soc_kcontrol_component(
1263 struct snd_kcontrol *kcontrol)
1264{
1265 return snd_kcontrol_chip(kcontrol);
1266}
1267
1268/**
1253 * snd_soc_kcontrol_codec() - Returns the CODEC that registered the control 1269 * snd_soc_kcontrol_codec() - Returns the CODEC that registered the control
1254 * @kcontrol: The control for which to get the CODEC 1270 * @kcontrol: The control for which to get the CODEC
1255 * 1271 *
@@ -1260,7 +1276,7 @@ static inline bool snd_soc_codec_is_active(struct snd_soc_codec *codec)
1260static inline struct snd_soc_codec *snd_soc_kcontrol_codec( 1276static inline struct snd_soc_codec *snd_soc_kcontrol_codec(
1261 struct snd_kcontrol *kcontrol) 1277 struct snd_kcontrol *kcontrol)
1262{ 1278{
1263 return snd_kcontrol_chip(kcontrol); 1279 return snd_soc_component_to_codec(snd_soc_kcontrol_component(kcontrol));
1264} 1280}
1265 1281
1266/** 1282/**
@@ -1274,7 +1290,7 @@ static inline struct snd_soc_codec *snd_soc_kcontrol_codec(
1274static inline struct snd_soc_platform *snd_soc_kcontrol_platform( 1290static inline struct snd_soc_platform *snd_soc_kcontrol_platform(
1275 struct snd_kcontrol *kcontrol) 1291 struct snd_kcontrol *kcontrol)
1276{ 1292{
1277 return snd_kcontrol_chip(kcontrol); 1293 return snd_soc_component_to_platform(snd_soc_kcontrol_component(kcontrol));
1278} 1294}
1279 1295
1280int snd_soc_util_init(void); 1296int snd_soc_util_init(void);
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index df3e2931cc0d..d5cd80b6d320 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -2353,7 +2353,7 @@ int snd_soc_add_codec_controls(struct snd_soc_codec *codec,
2353 struct snd_card *card = codec->card->snd_card; 2353 struct snd_card *card = codec->card->snd_card;
2354 2354
2355 return snd_soc_add_controls(card, codec->dev, controls, num_controls, 2355 return snd_soc_add_controls(card, codec->dev, controls, num_controls,
2356 codec->name_prefix, codec); 2356 codec->name_prefix, &codec->component);
2357} 2357}
2358EXPORT_SYMBOL_GPL(snd_soc_add_codec_controls); 2358EXPORT_SYMBOL_GPL(snd_soc_add_codec_controls);
2359 2359
@@ -2373,7 +2373,7 @@ int snd_soc_add_platform_controls(struct snd_soc_platform *platform,
2373 struct snd_card *card = platform->card->snd_card; 2373 struct snd_card *card = platform->card->snd_card;
2374 2374
2375 return snd_soc_add_controls(card, platform->dev, controls, num_controls, 2375 return snd_soc_add_controls(card, platform->dev, controls, num_controls,
2376 NULL, platform); 2376 NULL, &platform->component);
2377} 2377}
2378EXPORT_SYMBOL_GPL(snd_soc_add_platform_controls); 2378EXPORT_SYMBOL_GPL(snd_soc_add_platform_controls);
2379 2379
@@ -2457,12 +2457,15 @@ EXPORT_SYMBOL_GPL(snd_soc_info_enum_double);
2457int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol, 2457int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
2458 struct snd_ctl_elem_value *ucontrol) 2458 struct snd_ctl_elem_value *ucontrol)
2459{ 2459{
2460 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 2460 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
2461 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 2461 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2462 unsigned int val, item; 2462 unsigned int val, item;
2463 unsigned int reg_val; 2463 unsigned int reg_val;
2464 int ret;
2464 2465
2465 reg_val = snd_soc_read(codec, e->reg); 2466 ret = snd_soc_component_read(component, e->reg, &reg_val);
2467 if (ret)
2468 return ret;
2466 val = (reg_val >> e->shift_l) & e->mask; 2469 val = (reg_val >> e->shift_l) & e->mask;
2467 item = snd_soc_enum_val_to_item(e, val); 2470 item = snd_soc_enum_val_to_item(e, val);
2468 ucontrol->value.enumerated.item[0] = item; 2471 ucontrol->value.enumerated.item[0] = item;
@@ -2488,7 +2491,7 @@ EXPORT_SYMBOL_GPL(snd_soc_get_enum_double);
2488int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol, 2491int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
2489 struct snd_ctl_elem_value *ucontrol) 2492 struct snd_ctl_elem_value *ucontrol)
2490{ 2493{
2491 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 2494 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
2492 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 2495 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2493 unsigned int *item = ucontrol->value.enumerated.item; 2496 unsigned int *item = ucontrol->value.enumerated.item;
2494 unsigned int val; 2497 unsigned int val;
@@ -2505,38 +2508,48 @@ int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
2505 mask |= e->mask << e->shift_r; 2508 mask |= e->mask << e->shift_r;
2506 } 2509 }
2507 2510
2508 return snd_soc_update_bits_locked(codec, e->reg, mask, val); 2511 return snd_soc_component_update_bits(component, e->reg, mask, val);
2509} 2512}
2510EXPORT_SYMBOL_GPL(snd_soc_put_enum_double); 2513EXPORT_SYMBOL_GPL(snd_soc_put_enum_double);
2511 2514
2512/** 2515/**
2513 * snd_soc_read_signed - Read a codec register and interprete as signed value 2516 * snd_soc_read_signed - Read a codec register and interprete as signed value
2514 * @codec: codec 2517 * @component: component
2515 * @reg: Register to read 2518 * @reg: Register to read
2516 * @mask: Mask to use after shifting the register value 2519 * @mask: Mask to use after shifting the register value
2517 * @shift: Right shift of register value 2520 * @shift: Right shift of register value
2518 * @sign_bit: Bit that describes if a number is negative or not. 2521 * @sign_bit: Bit that describes if a number is negative or not.
2522 * @signed_val: Pointer to where the read value should be stored
2519 * 2523 *
2520 * This functions reads a codec register. The register value is shifted right 2524 * This functions reads a codec register. The register value is shifted right
2521 * by 'shift' bits and masked with the given 'mask'. Afterwards it translates 2525 * by 'shift' bits and masked with the given 'mask'. Afterwards it translates
2522 * the given registervalue into a signed integer if sign_bit is non-zero. 2526 * the given registervalue into a signed integer if sign_bit is non-zero.
2523 * 2527 *
2524 * Returns the register value as signed int. 2528 * Returns 0 on sucess, otherwise an error value
2525 */ 2529 */
2526static int snd_soc_read_signed(struct snd_soc_codec *codec, unsigned int reg, 2530static int snd_soc_read_signed(struct snd_soc_component *component,
2527 unsigned int mask, unsigned int shift, unsigned int sign_bit) 2531 unsigned int reg, unsigned int mask, unsigned int shift,
2532 unsigned int sign_bit, int *signed_val)
2528{ 2533{
2529 int ret; 2534 int ret;
2530 unsigned int val; 2535 unsigned int val;
2531 2536
2532 val = (snd_soc_read(codec, reg) >> shift) & mask; 2537 ret = snd_soc_component_read(component, reg, &val);
2538 if (ret < 0)
2539 return ret;
2540
2541 val = (val >> shift) & mask;
2533 2542
2534 if (!sign_bit) 2543 if (!sign_bit) {
2535 return val; 2544 *signed_val = val;
2545 return 0;
2546 }
2536 2547
2537 /* non-negative number */ 2548 /* non-negative number */
2538 if (!(val & BIT(sign_bit))) 2549 if (!(val & BIT(sign_bit))) {
2539 return val; 2550 *signed_val = val;
2551 return 0;
2552 }
2540 2553
2541 ret = val; 2554 ret = val;
2542 2555
@@ -2548,7 +2561,9 @@ static int snd_soc_read_signed(struct snd_soc_codec *codec, unsigned int reg,
2548 */ 2561 */
2549 ret |= ~((int)(BIT(sign_bit) - 1)); 2562 ret |= ~((int)(BIT(sign_bit) - 1));
2550 2563
2551 return ret; 2564 *signed_val = ret;
2565
2566 return 0;
2552} 2567}
2553 2568
2554/** 2569/**
@@ -2597,9 +2612,9 @@ EXPORT_SYMBOL_GPL(snd_soc_info_volsw);
2597int snd_soc_get_volsw(struct snd_kcontrol *kcontrol, 2612int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
2598 struct snd_ctl_elem_value *ucontrol) 2613 struct snd_ctl_elem_value *ucontrol)
2599{ 2614{
2615 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
2600 struct soc_mixer_control *mc = 2616 struct soc_mixer_control *mc =
2601 (struct soc_mixer_control *)kcontrol->private_value; 2617 (struct soc_mixer_control *)kcontrol->private_value;
2602 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2603 unsigned int reg = mc->reg; 2618 unsigned int reg = mc->reg;
2604 unsigned int reg2 = mc->rreg; 2619 unsigned int reg2 = mc->rreg;
2605 unsigned int shift = mc->shift; 2620 unsigned int shift = mc->shift;
@@ -2609,25 +2624,32 @@ int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
2609 int sign_bit = mc->sign_bit; 2624 int sign_bit = mc->sign_bit;
2610 unsigned int mask = (1 << fls(max)) - 1; 2625 unsigned int mask = (1 << fls(max)) - 1;
2611 unsigned int invert = mc->invert; 2626 unsigned int invert = mc->invert;
2627 int val;
2628 int ret;
2612 2629
2613 if (sign_bit) 2630 if (sign_bit)
2614 mask = BIT(sign_bit + 1) - 1; 2631 mask = BIT(sign_bit + 1) - 1;
2615 2632
2616 ucontrol->value.integer.value[0] = snd_soc_read_signed(codec, reg, mask, 2633 ret = snd_soc_read_signed(component, reg, mask, shift, sign_bit, &val);
2617 shift, sign_bit) - min; 2634 if (ret)
2635 return ret;
2636
2637 ucontrol->value.integer.value[0] = val - min;
2618 if (invert) 2638 if (invert)
2619 ucontrol->value.integer.value[0] = 2639 ucontrol->value.integer.value[0] =
2620 max - ucontrol->value.integer.value[0]; 2640 max - ucontrol->value.integer.value[0];
2621 2641
2622 if (snd_soc_volsw_is_stereo(mc)) { 2642 if (snd_soc_volsw_is_stereo(mc)) {
2623 if (reg == reg2) 2643 if (reg == reg2)
2624 ucontrol->value.integer.value[1] = 2644 ret = snd_soc_read_signed(component, reg, mask, rshift,
2625 snd_soc_read_signed(codec, reg, mask, rshift, 2645 sign_bit, &val);
2626 sign_bit) - min;
2627 else 2646 else
2628 ucontrol->value.integer.value[1] = 2647 ret = snd_soc_read_signed(component, reg2, mask, shift,
2629 snd_soc_read_signed(codec, reg2, mask, shift, 2648 sign_bit, &val);
2630 sign_bit) - min; 2649 if (ret)
2650 return ret;
2651
2652 ucontrol->value.integer.value[1] = val - min;
2631 if (invert) 2653 if (invert)
2632 ucontrol->value.integer.value[1] = 2654 ucontrol->value.integer.value[1] =
2633 max - ucontrol->value.integer.value[1]; 2655 max - ucontrol->value.integer.value[1];
@@ -2650,9 +2672,9 @@ EXPORT_SYMBOL_GPL(snd_soc_get_volsw);
2650int snd_soc_put_volsw(struct snd_kcontrol *kcontrol, 2672int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
2651 struct snd_ctl_elem_value *ucontrol) 2673 struct snd_ctl_elem_value *ucontrol)
2652{ 2674{
2675 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
2653 struct soc_mixer_control *mc = 2676 struct soc_mixer_control *mc =
2654 (struct soc_mixer_control *)kcontrol->private_value; 2677 (struct soc_mixer_control *)kcontrol->private_value;
2655 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2656 unsigned int reg = mc->reg; 2678 unsigned int reg = mc->reg;
2657 unsigned int reg2 = mc->rreg; 2679 unsigned int reg2 = mc->rreg;
2658 unsigned int shift = mc->shift; 2680 unsigned int shift = mc->shift;
@@ -2687,12 +2709,13 @@ int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
2687 type_2r = true; 2709 type_2r = true;
2688 } 2710 }
2689 } 2711 }
2690 err = snd_soc_update_bits_locked(codec, reg, val_mask, val); 2712 err = snd_soc_component_update_bits(component, reg, val_mask, val);
2691 if (err < 0) 2713 if (err < 0)
2692 return err; 2714 return err;
2693 2715
2694 if (type_2r) 2716 if (type_2r)
2695 err = snd_soc_update_bits_locked(codec, reg2, val_mask, val2); 2717 err = snd_soc_component_update_bits(component, reg2, val_mask,
2718 val2);
2696 2719
2697 return err; 2720 return err;
2698} 2721}
@@ -2711,10 +2734,9 @@ EXPORT_SYMBOL_GPL(snd_soc_put_volsw);
2711int snd_soc_get_volsw_sx(struct snd_kcontrol *kcontrol, 2734int snd_soc_get_volsw_sx(struct snd_kcontrol *kcontrol,
2712 struct snd_ctl_elem_value *ucontrol) 2735 struct snd_ctl_elem_value *ucontrol)
2713{ 2736{
2714 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 2737 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
2715 struct soc_mixer_control *mc = 2738 struct soc_mixer_control *mc =
2716 (struct soc_mixer_control *)kcontrol->private_value; 2739 (struct soc_mixer_control *)kcontrol->private_value;
2717
2718 unsigned int reg = mc->reg; 2740 unsigned int reg = mc->reg;
2719 unsigned int reg2 = mc->rreg; 2741 unsigned int reg2 = mc->rreg;
2720 unsigned int shift = mc->shift; 2742 unsigned int shift = mc->shift;
@@ -2722,13 +2744,23 @@ int snd_soc_get_volsw_sx(struct snd_kcontrol *kcontrol,
2722 int max = mc->max; 2744 int max = mc->max;
2723 int min = mc->min; 2745 int min = mc->min;
2724 int mask = (1 << (fls(min + max) - 1)) - 1; 2746 int mask = (1 << (fls(min + max) - 1)) - 1;
2747 unsigned int val;
2748 int ret;
2725 2749
2726 ucontrol->value.integer.value[0] = 2750 ret = snd_soc_component_read(component, reg, &val);
2727 ((snd_soc_read(codec, reg) >> shift) - min) & mask; 2751 if (ret < 0)
2752 return ret;
2728 2753
2729 if (snd_soc_volsw_is_stereo(mc)) 2754 ucontrol->value.integer.value[0] = ((val >> shift) - min) & mask;
2730 ucontrol->value.integer.value[1] = 2755
2731 ((snd_soc_read(codec, reg2) >> rshift) - min) & mask; 2756 if (snd_soc_volsw_is_stereo(mc)) {
2757 ret = snd_soc_component_read(component, reg2, &val);
2758 if (ret < 0)
2759 return ret;
2760
2761 val = ((val >> rshift) - min) & mask;
2762 ucontrol->value.integer.value[1] = val;
2763 }
2732 2764
2733 return 0; 2765 return 0;
2734} 2766}
@@ -2746,7 +2778,7 @@ EXPORT_SYMBOL_GPL(snd_soc_get_volsw_sx);
2746int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol, 2778int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol,
2747 struct snd_ctl_elem_value *ucontrol) 2779 struct snd_ctl_elem_value *ucontrol)
2748{ 2780{
2749 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 2781 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
2750 struct soc_mixer_control *mc = 2782 struct soc_mixer_control *mc =
2751 (struct soc_mixer_control *)kcontrol->private_value; 2783 (struct soc_mixer_control *)kcontrol->private_value;
2752 2784
@@ -2764,7 +2796,7 @@ int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol,
2764 val = (ucontrol->value.integer.value[0] + min) & mask; 2796 val = (ucontrol->value.integer.value[0] + min) & mask;
2765 val = val << shift; 2797 val = val << shift;
2766 2798
2767 err = snd_soc_update_bits_locked(codec, reg, val_mask, val); 2799 err = snd_soc_component_update_bits(component, reg, val_mask, val);
2768 if (err < 0) 2800 if (err < 0)
2769 return err; 2801 return err;
2770 2802
@@ -2773,10 +2805,10 @@ int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol,
2773 val2 = (ucontrol->value.integer.value[1] + min) & mask; 2805 val2 = (ucontrol->value.integer.value[1] + min) & mask;
2774 val2 = val2 << rshift; 2806 val2 = val2 << rshift;
2775 2807
2776 if (snd_soc_update_bits_locked(codec, reg2, val_mask, val2)) 2808 err = snd_soc_component_update_bits(component, reg2, val_mask,
2777 return err; 2809 val2);
2778 } 2810 }
2779 return 0; 2811 return err;
2780} 2812}
2781EXPORT_SYMBOL_GPL(snd_soc_put_volsw_sx); 2813EXPORT_SYMBOL_GPL(snd_soc_put_volsw_sx);
2782 2814
@@ -2823,10 +2855,15 @@ int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol,
2823{ 2855{
2824 struct soc_mixer_control *mc = 2856 struct soc_mixer_control *mc =
2825 (struct soc_mixer_control *)kcontrol->private_value; 2857 (struct soc_mixer_control *)kcontrol->private_value;
2826 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 2858 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
2827 unsigned int reg = mc->reg; 2859 unsigned int reg = mc->reg;
2860 unsigned int val;
2828 int min = mc->min; 2861 int min = mc->min;
2829 int val = snd_soc_read(codec, reg); 2862 int ret;
2863
2864 ret = snd_soc_component_read(component, reg, &val);
2865 if (ret)
2866 return ret;
2830 2867
2831 ucontrol->value.integer.value[0] = 2868 ucontrol->value.integer.value[0] =
2832 ((signed char)(val & 0xff))-min; 2869 ((signed char)(val & 0xff))-min;
@@ -2850,7 +2887,7 @@ int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,
2850{ 2887{
2851 struct soc_mixer_control *mc = 2888 struct soc_mixer_control *mc =
2852 (struct soc_mixer_control *)kcontrol->private_value; 2889 (struct soc_mixer_control *)kcontrol->private_value;
2853 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 2890 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
2854 unsigned int reg = mc->reg; 2891 unsigned int reg = mc->reg;
2855 int min = mc->min; 2892 int min = mc->min;
2856 unsigned int val; 2893 unsigned int val;
@@ -2858,7 +2895,7 @@ int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,
2858 val = (ucontrol->value.integer.value[0]+min) & 0xff; 2895 val = (ucontrol->value.integer.value[0]+min) & 0xff;
2859 val |= ((ucontrol->value.integer.value[1]+min) & 0xff) << 8; 2896 val |= ((ucontrol->value.integer.value[1]+min) & 0xff) << 8;
2860 2897
2861 return snd_soc_update_bits_locked(codec, reg, 0xffff, val); 2898 return snd_soc_component_update_bits(component, reg, 0xffff, val);
2862} 2899}
2863EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8); 2900EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8);
2864 2901
@@ -2907,7 +2944,7 @@ int snd_soc_put_volsw_range(struct snd_kcontrol *kcontrol,
2907{ 2944{
2908 struct soc_mixer_control *mc = 2945 struct soc_mixer_control *mc =
2909 (struct soc_mixer_control *)kcontrol->private_value; 2946 (struct soc_mixer_control *)kcontrol->private_value;
2910 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 2947 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
2911 unsigned int reg = mc->reg; 2948 unsigned int reg = mc->reg;
2912 unsigned int rreg = mc->rreg; 2949 unsigned int rreg = mc->rreg;
2913 unsigned int shift = mc->shift; 2950 unsigned int shift = mc->shift;
@@ -2924,7 +2961,7 @@ int snd_soc_put_volsw_range(struct snd_kcontrol *kcontrol,
2924 val_mask = mask << shift; 2961 val_mask = mask << shift;
2925 val = val << shift; 2962 val = val << shift;
2926 2963
2927 ret = snd_soc_update_bits_locked(codec, reg, val_mask, val); 2964 ret = snd_soc_component_update_bits(component, reg, val_mask, val);
2928 if (ret < 0) 2965 if (ret < 0)
2929 return ret; 2966 return ret;
2930 2967
@@ -2935,7 +2972,8 @@ int snd_soc_put_volsw_range(struct snd_kcontrol *kcontrol,
2935 val_mask = mask << shift; 2972 val_mask = mask << shift;
2936 val = val << shift; 2973 val = val << shift;
2937 2974
2938 ret = snd_soc_update_bits_locked(codec, rreg, val_mask, val); 2975 ret = snd_soc_component_update_bits(component, rreg, val_mask,
2976 val);
2939 } 2977 }
2940 2978
2941 return ret; 2979 return ret;
@@ -2954,9 +2992,9 @@ EXPORT_SYMBOL_GPL(snd_soc_put_volsw_range);
2954int snd_soc_get_volsw_range(struct snd_kcontrol *kcontrol, 2992int snd_soc_get_volsw_range(struct snd_kcontrol *kcontrol,
2955 struct snd_ctl_elem_value *ucontrol) 2993 struct snd_ctl_elem_value *ucontrol)
2956{ 2994{
2995 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
2957 struct soc_mixer_control *mc = 2996 struct soc_mixer_control *mc =
2958 (struct soc_mixer_control *)kcontrol->private_value; 2997 (struct soc_mixer_control *)kcontrol->private_value;
2959 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2960 unsigned int reg = mc->reg; 2998 unsigned int reg = mc->reg;
2961 unsigned int rreg = mc->rreg; 2999 unsigned int rreg = mc->rreg;
2962 unsigned int shift = mc->shift; 3000 unsigned int shift = mc->shift;
@@ -2964,9 +3002,14 @@ int snd_soc_get_volsw_range(struct snd_kcontrol *kcontrol,
2964 int max = mc->max; 3002 int max = mc->max;
2965 unsigned int mask = (1 << fls(max)) - 1; 3003 unsigned int mask = (1 << fls(max)) - 1;
2966 unsigned int invert = mc->invert; 3004 unsigned int invert = mc->invert;
3005 unsigned int val;
3006 int ret;
2967 3007
2968 ucontrol->value.integer.value[0] = 3008 ret = snd_soc_component_read(component, reg, &val);
2969 (snd_soc_read(codec, reg) >> shift) & mask; 3009 if (ret)
3010 return ret;
3011
3012 ucontrol->value.integer.value[0] = (val >> shift) & mask;
2970 if (invert) 3013 if (invert)
2971 ucontrol->value.integer.value[0] = 3014 ucontrol->value.integer.value[0] =
2972 max - ucontrol->value.integer.value[0]; 3015 max - ucontrol->value.integer.value[0];
@@ -2974,8 +3017,11 @@ int snd_soc_get_volsw_range(struct snd_kcontrol *kcontrol,
2974 ucontrol->value.integer.value[0] - min; 3017 ucontrol->value.integer.value[0] - min;
2975 3018
2976 if (snd_soc_volsw_is_stereo(mc)) { 3019 if (snd_soc_volsw_is_stereo(mc)) {
2977 ucontrol->value.integer.value[1] = 3020 ret = snd_soc_component_read(component, rreg, &val);
2978 (snd_soc_read(codec, rreg) >> shift) & mask; 3021 if (ret)
3022 return ret;
3023
3024 ucontrol->value.integer.value[1] = (val >> shift) & mask;
2979 if (invert) 3025 if (invert)
2980 ucontrol->value.integer.value[1] = 3026 ucontrol->value.integer.value[1] =
2981 max - ucontrol->value.integer.value[1]; 3027 max - ucontrol->value.integer.value[1];
@@ -3029,11 +3075,11 @@ EXPORT_SYMBOL_GPL(snd_soc_limit_volume);
3029int snd_soc_bytes_info(struct snd_kcontrol *kcontrol, 3075int snd_soc_bytes_info(struct snd_kcontrol *kcontrol,
3030 struct snd_ctl_elem_info *uinfo) 3076 struct snd_ctl_elem_info *uinfo)
3031{ 3077{
3032 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 3078 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
3033 struct soc_bytes *params = (void *)kcontrol->private_value; 3079 struct soc_bytes *params = (void *)kcontrol->private_value;
3034 3080
3035 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES; 3081 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
3036 uinfo->count = params->num_regs * codec->component.val_bytes; 3082 uinfo->count = params->num_regs * component->val_bytes;
3037 3083
3038 return 0; 3084 return 0;
3039} 3085}
@@ -3042,20 +3088,20 @@ EXPORT_SYMBOL_GPL(snd_soc_bytes_info);
3042int snd_soc_bytes_get(struct snd_kcontrol *kcontrol, 3088int snd_soc_bytes_get(struct snd_kcontrol *kcontrol,
3043 struct snd_ctl_elem_value *ucontrol) 3089 struct snd_ctl_elem_value *ucontrol)
3044{ 3090{
3091 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
3045 struct soc_bytes *params = (void *)kcontrol->private_value; 3092 struct soc_bytes *params = (void *)kcontrol->private_value;
3046 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
3047 int ret; 3093 int ret;
3048 3094
3049 if (codec->component.regmap) 3095 if (component->regmap)
3050 ret = regmap_raw_read(codec->component.regmap, params->base, 3096 ret = regmap_raw_read(component->regmap, params->base,
3051 ucontrol->value.bytes.data, 3097 ucontrol->value.bytes.data,
3052 params->num_regs * codec->component.val_bytes); 3098 params->num_regs * component->val_bytes);
3053 else 3099 else
3054 ret = -EINVAL; 3100 ret = -EINVAL;
3055 3101
3056 /* Hide any masked bytes to ensure consistent data reporting */ 3102 /* Hide any masked bytes to ensure consistent data reporting */
3057 if (ret == 0 && params->mask) { 3103 if (ret == 0 && params->mask) {
3058 switch (codec->component.val_bytes) { 3104 switch (component->val_bytes) {
3059 case 1: 3105 case 1:
3060 ucontrol->value.bytes.data[0] &= ~params->mask; 3106 ucontrol->value.bytes.data[0] &= ~params->mask;
3061 break; 3107 break;
@@ -3079,16 +3125,16 @@ EXPORT_SYMBOL_GPL(snd_soc_bytes_get);
3079int snd_soc_bytes_put(struct snd_kcontrol *kcontrol, 3125int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
3080 struct snd_ctl_elem_value *ucontrol) 3126 struct snd_ctl_elem_value *ucontrol)
3081{ 3127{
3128 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
3082 struct soc_bytes *params = (void *)kcontrol->private_value; 3129 struct soc_bytes *params = (void *)kcontrol->private_value;
3083 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
3084 int ret, len; 3130 int ret, len;
3085 unsigned int val, mask; 3131 unsigned int val, mask;
3086 void *data; 3132 void *data;
3087 3133
3088 if (!codec->component.regmap) 3134 if (!component->regmap)
3089 return -EINVAL; 3135 return -EINVAL;
3090 3136
3091 len = params->num_regs * codec->component.val_bytes; 3137 len = params->num_regs * component->val_bytes;
3092 3138
3093 data = kmemdup(ucontrol->value.bytes.data, len, GFP_KERNEL | GFP_DMA); 3139 data = kmemdup(ucontrol->value.bytes.data, len, GFP_KERNEL | GFP_DMA);
3094 if (!data) 3140 if (!data)
@@ -3100,27 +3146,27 @@ int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
3100 * copy. 3146 * copy.
3101 */ 3147 */
3102 if (params->mask) { 3148 if (params->mask) {
3103 ret = regmap_read(codec->component.regmap, params->base, &val); 3149 ret = regmap_read(component->regmap, params->base, &val);
3104 if (ret != 0) 3150 if (ret != 0)
3105 goto out; 3151 goto out;
3106 3152
3107 val &= params->mask; 3153 val &= params->mask;
3108 3154
3109 switch (codec->component.val_bytes) { 3155 switch (component->val_bytes) {
3110 case 1: 3156 case 1:
3111 ((u8 *)data)[0] &= ~params->mask; 3157 ((u8 *)data)[0] &= ~params->mask;
3112 ((u8 *)data)[0] |= val; 3158 ((u8 *)data)[0] |= val;
3113 break; 3159 break;
3114 case 2: 3160 case 2:
3115 mask = ~params->mask; 3161 mask = ~params->mask;
3116 ret = regmap_parse_val(codec->component.regmap, 3162 ret = regmap_parse_val(component->regmap,
3117 &mask, &mask); 3163 &mask, &mask);
3118 if (ret != 0) 3164 if (ret != 0)
3119 goto out; 3165 goto out;
3120 3166
3121 ((u16 *)data)[0] &= mask; 3167 ((u16 *)data)[0] &= mask;
3122 3168
3123 ret = regmap_parse_val(codec->component.regmap, 3169 ret = regmap_parse_val(component->regmap,
3124 &val, &val); 3170 &val, &val);
3125 if (ret != 0) 3171 if (ret != 0)
3126 goto out; 3172 goto out;
@@ -3129,14 +3175,14 @@ int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
3129 break; 3175 break;
3130 case 4: 3176 case 4:
3131 mask = ~params->mask; 3177 mask = ~params->mask;
3132 ret = regmap_parse_val(codec->component.regmap, 3178 ret = regmap_parse_val(component->regmap,
3133 &mask, &mask); 3179 &mask, &mask);
3134 if (ret != 0) 3180 if (ret != 0)
3135 goto out; 3181 goto out;
3136 3182
3137 ((u32 *)data)[0] &= mask; 3183 ((u32 *)data)[0] &= mask;
3138 3184
3139 ret = regmap_parse_val(codec->component.regmap, 3185 ret = regmap_parse_val(component->regmap,
3140 &val, &val); 3186 &val, &val);
3141 if (ret != 0) 3187 if (ret != 0)
3142 goto out; 3188 goto out;
@@ -3149,7 +3195,7 @@ int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
3149 } 3195 }
3150 } 3196 }
3151 3197
3152 ret = regmap_raw_write(codec->component.regmap, params->base, 3198 ret = regmap_raw_write(component->regmap, params->base,
3153 data, len); 3199 data, len);
3154 3200
3155out: 3201out:
@@ -3200,24 +3246,27 @@ EXPORT_SYMBOL_GPL(snd_soc_info_xr_sx);
3200int snd_soc_get_xr_sx(struct snd_kcontrol *kcontrol, 3246int snd_soc_get_xr_sx(struct snd_kcontrol *kcontrol,
3201 struct snd_ctl_elem_value *ucontrol) 3247 struct snd_ctl_elem_value *ucontrol)
3202{ 3248{
3249 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
3203 struct soc_mreg_control *mc = 3250 struct soc_mreg_control *mc =
3204 (struct soc_mreg_control *)kcontrol->private_value; 3251 (struct soc_mreg_control *)kcontrol->private_value;
3205 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
3206 unsigned int regbase = mc->regbase; 3252 unsigned int regbase = mc->regbase;
3207 unsigned int regcount = mc->regcount; 3253 unsigned int regcount = mc->regcount;
3208 unsigned int regwshift = codec->component.val_bytes * BITS_PER_BYTE; 3254 unsigned int regwshift = component->val_bytes * BITS_PER_BYTE;
3209 unsigned int regwmask = (1<<regwshift)-1; 3255 unsigned int regwmask = (1<<regwshift)-1;
3210 unsigned int invert = mc->invert; 3256 unsigned int invert = mc->invert;
3211 unsigned long mask = (1UL<<mc->nbits)-1; 3257 unsigned long mask = (1UL<<mc->nbits)-1;
3212 long min = mc->min; 3258 long min = mc->min;
3213 long max = mc->max; 3259 long max = mc->max;
3214 long val = 0; 3260 long val = 0;
3215 unsigned long regval; 3261 unsigned int regval;
3216 unsigned int i; 3262 unsigned int i;
3263 int ret;
3217 3264
3218 for (i = 0; i < regcount; i++) { 3265 for (i = 0; i < regcount; i++) {
3219 regval = snd_soc_read(codec, regbase+i) & regwmask; 3266 ret = snd_soc_component_read(component, regbase+i, &regval);
3220 val |= regval << (regwshift*(regcount-i-1)); 3267 if (ret)
3268 return ret;
3269 val |= (regval & regwmask) << (regwshift*(regcount-i-1));
3221 } 3270 }
3222 val &= mask; 3271 val &= mask;
3223 if (min < 0 && val > max) 3272 if (min < 0 && val > max)
@@ -3246,12 +3295,12 @@ EXPORT_SYMBOL_GPL(snd_soc_get_xr_sx);
3246int snd_soc_put_xr_sx(struct snd_kcontrol *kcontrol, 3295int snd_soc_put_xr_sx(struct snd_kcontrol *kcontrol,
3247 struct snd_ctl_elem_value *ucontrol) 3296 struct snd_ctl_elem_value *ucontrol)
3248{ 3297{
3298 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
3249 struct soc_mreg_control *mc = 3299 struct soc_mreg_control *mc =
3250 (struct soc_mreg_control *)kcontrol->private_value; 3300 (struct soc_mreg_control *)kcontrol->private_value;
3251 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
3252 unsigned int regbase = mc->regbase; 3301 unsigned int regbase = mc->regbase;
3253 unsigned int regcount = mc->regcount; 3302 unsigned int regcount = mc->regcount;
3254 unsigned int regwshift = codec->component.val_bytes * BITS_PER_BYTE; 3303 unsigned int regwshift = component->val_bytes * BITS_PER_BYTE;
3255 unsigned int regwmask = (1<<regwshift)-1; 3304 unsigned int regwmask = (1<<regwshift)-1;
3256 unsigned int invert = mc->invert; 3305 unsigned int invert = mc->invert;
3257 unsigned long mask = (1UL<<mc->nbits)-1; 3306 unsigned long mask = (1UL<<mc->nbits)-1;
@@ -3266,7 +3315,7 @@ int snd_soc_put_xr_sx(struct snd_kcontrol *kcontrol,
3266 for (i = 0; i < regcount; i++) { 3315 for (i = 0; i < regcount; i++) {
3267 regval = (val >> (regwshift*(regcount-i-1))) & regwmask; 3316 regval = (val >> (regwshift*(regcount-i-1))) & regwmask;
3268 regmask = (mask >> (regwshift*(regcount-i-1))) & regwmask; 3317 regmask = (mask >> (regwshift*(regcount-i-1))) & regwmask;
3269 err = snd_soc_update_bits_locked(codec, regbase+i, 3318 err = snd_soc_component_update_bits(component, regbase+i,
3270 regmask, regval); 3319 regmask, regval);
3271 if (err < 0) 3320 if (err < 0)
3272 return err; 3321 return err;
@@ -3288,14 +3337,21 @@ EXPORT_SYMBOL_GPL(snd_soc_put_xr_sx);
3288int snd_soc_get_strobe(struct snd_kcontrol *kcontrol, 3337int snd_soc_get_strobe(struct snd_kcontrol *kcontrol,
3289 struct snd_ctl_elem_value *ucontrol) 3338 struct snd_ctl_elem_value *ucontrol)
3290{ 3339{
3340 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
3291 struct soc_mixer_control *mc = 3341 struct soc_mixer_control *mc =
3292 (struct soc_mixer_control *)kcontrol->private_value; 3342 (struct soc_mixer_control *)kcontrol->private_value;
3293 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
3294 unsigned int reg = mc->reg; 3343 unsigned int reg = mc->reg;
3295 unsigned int shift = mc->shift; 3344 unsigned int shift = mc->shift;
3296 unsigned int mask = 1 << shift; 3345 unsigned int mask = 1 << shift;
3297 unsigned int invert = mc->invert != 0; 3346 unsigned int invert = mc->invert != 0;
3298 unsigned int val = snd_soc_read(codec, reg) & mask; 3347 unsigned int val;
3348 int ret;
3349
3350 ret = snd_soc_component_read(component, reg, &val);
3351 if (ret)
3352 return ret;
3353
3354 val &= mask;
3299 3355
3300 if (shift != 0 && val != 0) 3356 if (shift != 0 && val != 0)
3301 val = val >> shift; 3357 val = val >> shift;
@@ -3318,9 +3374,9 @@ EXPORT_SYMBOL_GPL(snd_soc_get_strobe);
3318int snd_soc_put_strobe(struct snd_kcontrol *kcontrol, 3374int snd_soc_put_strobe(struct snd_kcontrol *kcontrol,
3319 struct snd_ctl_elem_value *ucontrol) 3375 struct snd_ctl_elem_value *ucontrol)
3320{ 3376{
3377 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
3321 struct soc_mixer_control *mc = 3378 struct soc_mixer_control *mc =
3322 (struct soc_mixer_control *)kcontrol->private_value; 3379 (struct soc_mixer_control *)kcontrol->private_value;
3323 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
3324 unsigned int reg = mc->reg; 3380 unsigned int reg = mc->reg;
3325 unsigned int shift = mc->shift; 3381 unsigned int shift = mc->shift;
3326 unsigned int mask = 1 << shift; 3382 unsigned int mask = 1 << shift;
@@ -3330,12 +3386,11 @@ int snd_soc_put_strobe(struct snd_kcontrol *kcontrol,
3330 unsigned int val2 = (strobe ^ invert) ? 0 : mask; 3386 unsigned int val2 = (strobe ^ invert) ? 0 : mask;
3331 int err; 3387 int err;
3332 3388
3333 err = snd_soc_update_bits_locked(codec, reg, mask, val1); 3389 err = snd_soc_component_update_bits(component, reg, mask, val1);
3334 if (err < 0) 3390 if (err < 0)
3335 return err; 3391 return err;
3336 3392
3337 err = snd_soc_update_bits_locked(codec, reg, mask, val2); 3393 return snd_soc_component_update_bits(component, reg, mask, val2);
3338 return err;
3339} 3394}
3340EXPORT_SYMBOL_GPL(snd_soc_put_strobe); 3395EXPORT_SYMBOL_GPL(snd_soc_put_strobe);
3341 3396