diff options
author | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2009-07-10 18:12:01 -0400 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2009-08-03 11:59:16 -0400 |
commit | 8d50e447d19fec64adebeef55f2b60d695435412 (patch) | |
tree | aac4234db113cf40abc4c7779ddecb76d7e0946b /sound/soc/codecs/wm9081.c | |
parent | afa2f1066e7288a9e4f8e3fda277da245219dffc (diff) |
ASoC: Factor out I/O for Wolfson 8 bit data 16 bit register CODECs
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound/soc/codecs/wm9081.c')
-rw-r--r-- | sound/soc/codecs/wm9081.c | 229 |
1 files changed, 85 insertions, 144 deletions
diff --git a/sound/soc/codecs/wm9081.c b/sound/soc/codecs/wm9081.c index dbe20597d872..dc383c29cce5 100644 --- a/sound/soc/codecs/wm9081.c +++ b/sound/soc/codecs/wm9081.c | |||
@@ -168,84 +168,19 @@ struct wm9081_priv { | |||
168 | struct wm9081_retune_mobile_config *retune; | 168 | struct wm9081_retune_mobile_config *retune; |
169 | }; | 169 | }; |
170 | 170 | ||
171 | static int wm9081_reg_is_volatile(int reg) | 171 | static int wm9081_volatile_register(unsigned int reg) |
172 | { | 172 | { |
173 | switch (reg) { | 173 | switch (reg) { |
174 | case WM9081_SOFTWARE_RESET: | ||
175 | return 1; | ||
174 | default: | 176 | default: |
175 | return 0; | 177 | return 0; |
176 | } | 178 | } |
177 | } | 179 | } |
178 | 180 | ||
179 | static unsigned int wm9081_read_reg_cache(struct snd_soc_codec *codec, | ||
180 | unsigned int reg) | ||
181 | { | ||
182 | u16 *cache = codec->reg_cache; | ||
183 | BUG_ON(reg > WM9081_MAX_REGISTER); | ||
184 | return cache[reg]; | ||
185 | } | ||
186 | |||
187 | static unsigned int wm9081_read_hw(struct snd_soc_codec *codec, u8 reg) | ||
188 | { | ||
189 | struct i2c_msg xfer[2]; | ||
190 | u16 data; | ||
191 | int ret; | ||
192 | struct i2c_client *client = codec->control_data; | ||
193 | |||
194 | BUG_ON(reg > WM9081_MAX_REGISTER); | ||
195 | |||
196 | /* Write register */ | ||
197 | xfer[0].addr = client->addr; | ||
198 | xfer[0].flags = 0; | ||
199 | xfer[0].len = 1; | ||
200 | xfer[0].buf = ® | ||
201 | |||
202 | /* Read data */ | ||
203 | xfer[1].addr = client->addr; | ||
204 | xfer[1].flags = I2C_M_RD; | ||
205 | xfer[1].len = 2; | ||
206 | xfer[1].buf = (u8 *)&data; | ||
207 | |||
208 | ret = i2c_transfer(client->adapter, xfer, 2); | ||
209 | if (ret != 2) { | ||
210 | dev_err(&client->dev, "i2c_transfer() returned %d\n", ret); | ||
211 | return 0; | ||
212 | } | ||
213 | |||
214 | return (data >> 8) | ((data & 0xff) << 8); | ||
215 | } | ||
216 | |||
217 | static unsigned int wm9081_read(struct snd_soc_codec *codec, unsigned int reg) | ||
218 | { | ||
219 | if (wm9081_reg_is_volatile(reg)) | ||
220 | return wm9081_read_hw(codec, reg); | ||
221 | else | ||
222 | return wm9081_read_reg_cache(codec, reg); | ||
223 | } | ||
224 | |||
225 | static int wm9081_write(struct snd_soc_codec *codec, unsigned int reg, | ||
226 | unsigned int value) | ||
227 | { | ||
228 | u16 *cache = codec->reg_cache; | ||
229 | u8 data[3]; | ||
230 | |||
231 | BUG_ON(reg > WM9081_MAX_REGISTER); | ||
232 | |||
233 | if (!wm9081_reg_is_volatile(reg)) | ||
234 | cache[reg] = value; | ||
235 | |||
236 | data[0] = reg; | ||
237 | data[1] = value >> 8; | ||
238 | data[2] = value & 0x00ff; | ||
239 | |||
240 | if (codec->hw_write(codec->control_data, data, 3) == 3) | ||
241 | return 0; | ||
242 | else | ||
243 | return -EIO; | ||
244 | } | ||
245 | |||
246 | static int wm9081_reset(struct snd_soc_codec *codec) | 181 | static int wm9081_reset(struct snd_soc_codec *codec) |
247 | { | 182 | { |
248 | return wm9081_write(codec, WM9081_SOFTWARE_RESET, 0); | 183 | return snd_soc_write(codec, WM9081_SOFTWARE_RESET, 0); |
249 | } | 184 | } |
250 | 185 | ||
251 | static const DECLARE_TLV_DB_SCALE(drc_in_tlv, -4500, 75, 0); | 186 | static const DECLARE_TLV_DB_SCALE(drc_in_tlv, -4500, 75, 0); |
@@ -356,7 +291,7 @@ static int speaker_mode_get(struct snd_kcontrol *kcontrol, | |||
356 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); | 291 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
357 | unsigned int reg; | 292 | unsigned int reg; |
358 | 293 | ||
359 | reg = wm9081_read(codec, WM9081_ANALOGUE_SPEAKER_2); | 294 | reg = snd_soc_read(codec, WM9081_ANALOGUE_SPEAKER_2); |
360 | if (reg & WM9081_SPK_MODE) | 295 | if (reg & WM9081_SPK_MODE) |
361 | ucontrol->value.integer.value[0] = 1; | 296 | ucontrol->value.integer.value[0] = 1; |
362 | else | 297 | else |
@@ -375,8 +310,8 @@ static int speaker_mode_put(struct snd_kcontrol *kcontrol, | |||
375 | struct snd_ctl_elem_value *ucontrol) | 310 | struct snd_ctl_elem_value *ucontrol) |
376 | { | 311 | { |
377 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); | 312 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
378 | unsigned int reg_pwr = wm9081_read(codec, WM9081_POWER_MANAGEMENT); | 313 | unsigned int reg_pwr = snd_soc_read(codec, WM9081_POWER_MANAGEMENT); |
379 | unsigned int reg2 = wm9081_read(codec, WM9081_ANALOGUE_SPEAKER_2); | 314 | unsigned int reg2 = snd_soc_read(codec, WM9081_ANALOGUE_SPEAKER_2); |
380 | 315 | ||
381 | /* Are we changing anything? */ | 316 | /* Are we changing anything? */ |
382 | if (ucontrol->value.integer.value[0] == | 317 | if (ucontrol->value.integer.value[0] == |
@@ -397,7 +332,7 @@ static int speaker_mode_put(struct snd_kcontrol *kcontrol, | |||
397 | reg2 &= ~WM9081_SPK_MODE; | 332 | reg2 &= ~WM9081_SPK_MODE; |
398 | } | 333 | } |
399 | 334 | ||
400 | wm9081_write(codec, WM9081_ANALOGUE_SPEAKER_2, reg2); | 335 | snd_soc_write(codec, WM9081_ANALOGUE_SPEAKER_2, reg2); |
401 | 336 | ||
402 | return 0; | 337 | return 0; |
403 | } | 338 | } |
@@ -456,7 +391,7 @@ static int speaker_event(struct snd_soc_dapm_widget *w, | |||
456 | struct snd_kcontrol *kcontrol, int event) | 391 | struct snd_kcontrol *kcontrol, int event) |
457 | { | 392 | { |
458 | struct snd_soc_codec *codec = w->codec; | 393 | struct snd_soc_codec *codec = w->codec; |
459 | unsigned int reg = wm9081_read(codec, WM9081_POWER_MANAGEMENT); | 394 | unsigned int reg = snd_soc_read(codec, WM9081_POWER_MANAGEMENT); |
460 | 395 | ||
461 | switch (event) { | 396 | switch (event) { |
462 | case SND_SOC_DAPM_POST_PMU: | 397 | case SND_SOC_DAPM_POST_PMU: |
@@ -468,7 +403,7 @@ static int speaker_event(struct snd_soc_dapm_widget *w, | |||
468 | break; | 403 | break; |
469 | } | 404 | } |
470 | 405 | ||
471 | wm9081_write(codec, WM9081_POWER_MANAGEMENT, reg); | 406 | snd_soc_write(codec, WM9081_POWER_MANAGEMENT, reg); |
472 | 407 | ||
473 | return 0; | 408 | return 0; |
474 | } | 409 | } |
@@ -607,7 +542,7 @@ static int wm9081_set_fll(struct snd_soc_codec *codec, int fll_id, | |||
607 | if (ret != 0) | 542 | if (ret != 0) |
608 | return ret; | 543 | return ret; |
609 | 544 | ||
610 | reg5 = wm9081_read(codec, WM9081_FLL_CONTROL_5); | 545 | reg5 = snd_soc_read(codec, WM9081_FLL_CONTROL_5); |
611 | reg5 &= ~WM9081_FLL_CLK_SRC_MASK; | 546 | reg5 &= ~WM9081_FLL_CLK_SRC_MASK; |
612 | 547 | ||
613 | switch (fll_id) { | 548 | switch (fll_id) { |
@@ -621,44 +556,44 @@ static int wm9081_set_fll(struct snd_soc_codec *codec, int fll_id, | |||
621 | } | 556 | } |
622 | 557 | ||
623 | /* Disable CLK_SYS while we reconfigure */ | 558 | /* Disable CLK_SYS while we reconfigure */ |
624 | clk_sys_reg = wm9081_read(codec, WM9081_CLOCK_CONTROL_3); | 559 | clk_sys_reg = snd_soc_read(codec, WM9081_CLOCK_CONTROL_3); |
625 | if (clk_sys_reg & WM9081_CLK_SYS_ENA) | 560 | if (clk_sys_reg & WM9081_CLK_SYS_ENA) |
626 | wm9081_write(codec, WM9081_CLOCK_CONTROL_3, | 561 | snd_soc_write(codec, WM9081_CLOCK_CONTROL_3, |
627 | clk_sys_reg & ~WM9081_CLK_SYS_ENA); | 562 | clk_sys_reg & ~WM9081_CLK_SYS_ENA); |
628 | 563 | ||
629 | /* Any FLL configuration change requires that the FLL be | 564 | /* Any FLL configuration change requires that the FLL be |
630 | * disabled first. */ | 565 | * disabled first. */ |
631 | reg1 = wm9081_read(codec, WM9081_FLL_CONTROL_1); | 566 | reg1 = snd_soc_read(codec, WM9081_FLL_CONTROL_1); |
632 | reg1 &= ~WM9081_FLL_ENA; | 567 | reg1 &= ~WM9081_FLL_ENA; |
633 | wm9081_write(codec, WM9081_FLL_CONTROL_1, reg1); | 568 | snd_soc_write(codec, WM9081_FLL_CONTROL_1, reg1); |
634 | 569 | ||
635 | /* Apply the configuration */ | 570 | /* Apply the configuration */ |
636 | if (fll_div.k) | 571 | if (fll_div.k) |
637 | reg1 |= WM9081_FLL_FRAC_MASK; | 572 | reg1 |= WM9081_FLL_FRAC_MASK; |
638 | else | 573 | else |
639 | reg1 &= ~WM9081_FLL_FRAC_MASK; | 574 | reg1 &= ~WM9081_FLL_FRAC_MASK; |
640 | wm9081_write(codec, WM9081_FLL_CONTROL_1, reg1); | 575 | snd_soc_write(codec, WM9081_FLL_CONTROL_1, reg1); |
641 | 576 | ||
642 | wm9081_write(codec, WM9081_FLL_CONTROL_2, | 577 | snd_soc_write(codec, WM9081_FLL_CONTROL_2, |
643 | (fll_div.fll_outdiv << WM9081_FLL_OUTDIV_SHIFT) | | 578 | (fll_div.fll_outdiv << WM9081_FLL_OUTDIV_SHIFT) | |
644 | (fll_div.fll_fratio << WM9081_FLL_FRATIO_SHIFT)); | 579 | (fll_div.fll_fratio << WM9081_FLL_FRATIO_SHIFT)); |
645 | wm9081_write(codec, WM9081_FLL_CONTROL_3, fll_div.k); | 580 | snd_soc_write(codec, WM9081_FLL_CONTROL_3, fll_div.k); |
646 | 581 | ||
647 | reg4 = wm9081_read(codec, WM9081_FLL_CONTROL_4); | 582 | reg4 = snd_soc_read(codec, WM9081_FLL_CONTROL_4); |
648 | reg4 &= ~WM9081_FLL_N_MASK; | 583 | reg4 &= ~WM9081_FLL_N_MASK; |
649 | reg4 |= fll_div.n << WM9081_FLL_N_SHIFT; | 584 | reg4 |= fll_div.n << WM9081_FLL_N_SHIFT; |
650 | wm9081_write(codec, WM9081_FLL_CONTROL_4, reg4); | 585 | snd_soc_write(codec, WM9081_FLL_CONTROL_4, reg4); |
651 | 586 | ||
652 | reg5 &= ~WM9081_FLL_CLK_REF_DIV_MASK; | 587 | reg5 &= ~WM9081_FLL_CLK_REF_DIV_MASK; |
653 | reg5 |= fll_div.fll_clk_ref_div << WM9081_FLL_CLK_REF_DIV_SHIFT; | 588 | reg5 |= fll_div.fll_clk_ref_div << WM9081_FLL_CLK_REF_DIV_SHIFT; |
654 | wm9081_write(codec, WM9081_FLL_CONTROL_5, reg5); | 589 | snd_soc_write(codec, WM9081_FLL_CONTROL_5, reg5); |
655 | 590 | ||
656 | /* Enable the FLL */ | 591 | /* Enable the FLL */ |
657 | wm9081_write(codec, WM9081_FLL_CONTROL_1, reg1 | WM9081_FLL_ENA); | 592 | snd_soc_write(codec, WM9081_FLL_CONTROL_1, reg1 | WM9081_FLL_ENA); |
658 | 593 | ||
659 | /* Then bring CLK_SYS up again if it was disabled */ | 594 | /* Then bring CLK_SYS up again if it was disabled */ |
660 | if (clk_sys_reg & WM9081_CLK_SYS_ENA) | 595 | if (clk_sys_reg & WM9081_CLK_SYS_ENA) |
661 | wm9081_write(codec, WM9081_CLOCK_CONTROL_3, clk_sys_reg); | 596 | snd_soc_write(codec, WM9081_CLOCK_CONTROL_3, clk_sys_reg); |
662 | 597 | ||
663 | dev_dbg(codec->dev, "FLL enabled at %dHz->%dHz\n", Fref, Fout); | 598 | dev_dbg(codec->dev, "FLL enabled at %dHz->%dHz\n", Fref, Fout); |
664 | 599 | ||
@@ -734,19 +669,19 @@ static int configure_clock(struct snd_soc_codec *codec) | |||
734 | return -EINVAL; | 669 | return -EINVAL; |
735 | } | 670 | } |
736 | 671 | ||
737 | reg = wm9081_read(codec, WM9081_CLOCK_CONTROL_1); | 672 | reg = snd_soc_read(codec, WM9081_CLOCK_CONTROL_1); |
738 | if (mclkdiv) | 673 | if (mclkdiv) |
739 | reg |= WM9081_MCLKDIV2; | 674 | reg |= WM9081_MCLKDIV2; |
740 | else | 675 | else |
741 | reg &= ~WM9081_MCLKDIV2; | 676 | reg &= ~WM9081_MCLKDIV2; |
742 | wm9081_write(codec, WM9081_CLOCK_CONTROL_1, reg); | 677 | snd_soc_write(codec, WM9081_CLOCK_CONTROL_1, reg); |
743 | 678 | ||
744 | reg = wm9081_read(codec, WM9081_CLOCK_CONTROL_3); | 679 | reg = snd_soc_read(codec, WM9081_CLOCK_CONTROL_3); |
745 | if (fll) | 680 | if (fll) |
746 | reg |= WM9081_CLK_SRC_SEL; | 681 | reg |= WM9081_CLK_SRC_SEL; |
747 | else | 682 | else |
748 | reg &= ~WM9081_CLK_SRC_SEL; | 683 | reg &= ~WM9081_CLK_SRC_SEL; |
749 | wm9081_write(codec, WM9081_CLOCK_CONTROL_3, reg); | 684 | snd_soc_write(codec, WM9081_CLOCK_CONTROL_3, reg); |
750 | 685 | ||
751 | dev_dbg(codec->dev, "CLK_SYS is %dHz\n", wm9081->sysclk_rate); | 686 | dev_dbg(codec->dev, "CLK_SYS is %dHz\n", wm9081->sysclk_rate); |
752 | 687 | ||
@@ -846,76 +781,76 @@ static int wm9081_set_bias_level(struct snd_soc_codec *codec, | |||
846 | 781 | ||
847 | case SND_SOC_BIAS_PREPARE: | 782 | case SND_SOC_BIAS_PREPARE: |
848 | /* VMID=2*40k */ | 783 | /* VMID=2*40k */ |
849 | reg = wm9081_read(codec, WM9081_VMID_CONTROL); | 784 | reg = snd_soc_read(codec, WM9081_VMID_CONTROL); |
850 | reg &= ~WM9081_VMID_SEL_MASK; | 785 | reg &= ~WM9081_VMID_SEL_MASK; |
851 | reg |= 0x2; | 786 | reg |= 0x2; |
852 | wm9081_write(codec, WM9081_VMID_CONTROL, reg); | 787 | snd_soc_write(codec, WM9081_VMID_CONTROL, reg); |
853 | 788 | ||
854 | /* Normal bias current */ | 789 | /* Normal bias current */ |
855 | reg = wm9081_read(codec, WM9081_BIAS_CONTROL_1); | 790 | reg = snd_soc_read(codec, WM9081_BIAS_CONTROL_1); |
856 | reg &= ~WM9081_STBY_BIAS_ENA; | 791 | reg &= ~WM9081_STBY_BIAS_ENA; |
857 | wm9081_write(codec, WM9081_BIAS_CONTROL_1, reg); | 792 | snd_soc_write(codec, WM9081_BIAS_CONTROL_1, reg); |
858 | break; | 793 | break; |
859 | 794 | ||
860 | case SND_SOC_BIAS_STANDBY: | 795 | case SND_SOC_BIAS_STANDBY: |
861 | /* Initial cold start */ | 796 | /* Initial cold start */ |
862 | if (codec->bias_level == SND_SOC_BIAS_OFF) { | 797 | if (codec->bias_level == SND_SOC_BIAS_OFF) { |
863 | /* Disable LINEOUT discharge */ | 798 | /* Disable LINEOUT discharge */ |
864 | reg = wm9081_read(codec, WM9081_ANTI_POP_CONTROL); | 799 | reg = snd_soc_read(codec, WM9081_ANTI_POP_CONTROL); |
865 | reg &= ~WM9081_LINEOUT_DISCH; | 800 | reg &= ~WM9081_LINEOUT_DISCH; |
866 | wm9081_write(codec, WM9081_ANTI_POP_CONTROL, reg); | 801 | snd_soc_write(codec, WM9081_ANTI_POP_CONTROL, reg); |
867 | 802 | ||
868 | /* Select startup bias source */ | 803 | /* Select startup bias source */ |
869 | reg = wm9081_read(codec, WM9081_BIAS_CONTROL_1); | 804 | reg = snd_soc_read(codec, WM9081_BIAS_CONTROL_1); |
870 | reg |= WM9081_BIAS_SRC | WM9081_BIAS_ENA; | 805 | reg |= WM9081_BIAS_SRC | WM9081_BIAS_ENA; |
871 | wm9081_write(codec, WM9081_BIAS_CONTROL_1, reg); | 806 | snd_soc_write(codec, WM9081_BIAS_CONTROL_1, reg); |
872 | 807 | ||
873 | /* VMID 2*4k; Soft VMID ramp enable */ | 808 | /* VMID 2*4k; Soft VMID ramp enable */ |
874 | reg = wm9081_read(codec, WM9081_VMID_CONTROL); | 809 | reg = snd_soc_read(codec, WM9081_VMID_CONTROL); |
875 | reg |= WM9081_VMID_RAMP | 0x6; | 810 | reg |= WM9081_VMID_RAMP | 0x6; |
876 | wm9081_write(codec, WM9081_VMID_CONTROL, reg); | 811 | snd_soc_write(codec, WM9081_VMID_CONTROL, reg); |
877 | 812 | ||
878 | mdelay(100); | 813 | mdelay(100); |
879 | 814 | ||
880 | /* Normal bias enable & soft start off */ | 815 | /* Normal bias enable & soft start off */ |
881 | reg |= WM9081_BIAS_ENA; | 816 | reg |= WM9081_BIAS_ENA; |
882 | reg &= ~WM9081_VMID_RAMP; | 817 | reg &= ~WM9081_VMID_RAMP; |
883 | wm9081_write(codec, WM9081_VMID_CONTROL, reg); | 818 | snd_soc_write(codec, WM9081_VMID_CONTROL, reg); |
884 | 819 | ||
885 | /* Standard bias source */ | 820 | /* Standard bias source */ |
886 | reg = wm9081_read(codec, WM9081_BIAS_CONTROL_1); | 821 | reg = snd_soc_read(codec, WM9081_BIAS_CONTROL_1); |
887 | reg &= ~WM9081_BIAS_SRC; | 822 | reg &= ~WM9081_BIAS_SRC; |
888 | wm9081_write(codec, WM9081_BIAS_CONTROL_1, reg); | 823 | snd_soc_write(codec, WM9081_BIAS_CONTROL_1, reg); |
889 | } | 824 | } |
890 | 825 | ||
891 | /* VMID 2*240k */ | 826 | /* VMID 2*240k */ |
892 | reg = wm9081_read(codec, WM9081_BIAS_CONTROL_1); | 827 | reg = snd_soc_read(codec, WM9081_BIAS_CONTROL_1); |
893 | reg &= ~WM9081_VMID_SEL_MASK; | 828 | reg &= ~WM9081_VMID_SEL_MASK; |
894 | reg |= 0x40; | 829 | reg |= 0x40; |
895 | wm9081_write(codec, WM9081_VMID_CONTROL, reg); | 830 | snd_soc_write(codec, WM9081_VMID_CONTROL, reg); |
896 | 831 | ||
897 | /* Standby bias current on */ | 832 | /* Standby bias current on */ |
898 | reg = wm9081_read(codec, WM9081_BIAS_CONTROL_1); | 833 | reg = snd_soc_read(codec, WM9081_BIAS_CONTROL_1); |
899 | reg |= WM9081_STBY_BIAS_ENA; | 834 | reg |= WM9081_STBY_BIAS_ENA; |
900 | wm9081_write(codec, WM9081_BIAS_CONTROL_1, reg); | 835 | snd_soc_write(codec, WM9081_BIAS_CONTROL_1, reg); |
901 | break; | 836 | break; |
902 | 837 | ||
903 | case SND_SOC_BIAS_OFF: | 838 | case SND_SOC_BIAS_OFF: |
904 | /* Startup bias source */ | 839 | /* Startup bias source */ |
905 | reg = wm9081_read(codec, WM9081_BIAS_CONTROL_1); | 840 | reg = snd_soc_read(codec, WM9081_BIAS_CONTROL_1); |
906 | reg |= WM9081_BIAS_SRC; | 841 | reg |= WM9081_BIAS_SRC; |
907 | wm9081_write(codec, WM9081_BIAS_CONTROL_1, reg); | 842 | snd_soc_write(codec, WM9081_BIAS_CONTROL_1, reg); |
908 | 843 | ||
909 | /* Disable VMID and biases with soft ramping */ | 844 | /* Disable VMID and biases with soft ramping */ |
910 | reg = wm9081_read(codec, WM9081_VMID_CONTROL); | 845 | reg = snd_soc_read(codec, WM9081_VMID_CONTROL); |
911 | reg &= ~(WM9081_VMID_SEL_MASK | WM9081_BIAS_ENA); | 846 | reg &= ~(WM9081_VMID_SEL_MASK | WM9081_BIAS_ENA); |
912 | reg |= WM9081_VMID_RAMP; | 847 | reg |= WM9081_VMID_RAMP; |
913 | wm9081_write(codec, WM9081_VMID_CONTROL, reg); | 848 | snd_soc_write(codec, WM9081_VMID_CONTROL, reg); |
914 | 849 | ||
915 | /* Actively discharge LINEOUT */ | 850 | /* Actively discharge LINEOUT */ |
916 | reg = wm9081_read(codec, WM9081_ANTI_POP_CONTROL); | 851 | reg = snd_soc_read(codec, WM9081_ANTI_POP_CONTROL); |
917 | reg |= WM9081_LINEOUT_DISCH; | 852 | reg |= WM9081_LINEOUT_DISCH; |
918 | wm9081_write(codec, WM9081_ANTI_POP_CONTROL, reg); | 853 | snd_soc_write(codec, WM9081_ANTI_POP_CONTROL, reg); |
919 | break; | 854 | break; |
920 | } | 855 | } |
921 | 856 | ||
@@ -929,7 +864,7 @@ static int wm9081_set_dai_fmt(struct snd_soc_dai *dai, | |||
929 | { | 864 | { |
930 | struct snd_soc_codec *codec = dai->codec; | 865 | struct snd_soc_codec *codec = dai->codec; |
931 | struct wm9081_priv *wm9081 = codec->private_data; | 866 | struct wm9081_priv *wm9081 = codec->private_data; |
932 | unsigned int aif2 = wm9081_read(codec, WM9081_AUDIO_INTERFACE_2); | 867 | unsigned int aif2 = snd_soc_read(codec, WM9081_AUDIO_INTERFACE_2); |
933 | 868 | ||
934 | aif2 &= ~(WM9081_AIF_BCLK_INV | WM9081_AIF_LRCLK_INV | | 869 | aif2 &= ~(WM9081_AIF_BCLK_INV | WM9081_AIF_LRCLK_INV | |
935 | WM9081_BCLK_DIR | WM9081_LRCLK_DIR | WM9081_AIF_FMT_MASK); | 870 | WM9081_BCLK_DIR | WM9081_LRCLK_DIR | WM9081_AIF_FMT_MASK); |
@@ -1010,7 +945,7 @@ static int wm9081_set_dai_fmt(struct snd_soc_dai *dai, | |||
1010 | return -EINVAL; | 945 | return -EINVAL; |
1011 | } | 946 | } |
1012 | 947 | ||
1013 | wm9081_write(codec, WM9081_AUDIO_INTERFACE_2, aif2); | 948 | snd_soc_write(codec, WM9081_AUDIO_INTERFACE_2, aif2); |
1014 | 949 | ||
1015 | return 0; | 950 | return 0; |
1016 | } | 951 | } |
@@ -1024,18 +959,18 @@ static int wm9081_hw_params(struct snd_pcm_substream *substream, | |||
1024 | int ret, i, best, best_val, cur_val; | 959 | int ret, i, best, best_val, cur_val; |
1025 | unsigned int clk_ctrl2, aif1, aif2, aif3, aif4; | 960 | unsigned int clk_ctrl2, aif1, aif2, aif3, aif4; |
1026 | 961 | ||
1027 | clk_ctrl2 = wm9081_read(codec, WM9081_CLOCK_CONTROL_2); | 962 | clk_ctrl2 = snd_soc_read(codec, WM9081_CLOCK_CONTROL_2); |
1028 | clk_ctrl2 &= ~(WM9081_CLK_SYS_RATE_MASK | WM9081_SAMPLE_RATE_MASK); | 963 | clk_ctrl2 &= ~(WM9081_CLK_SYS_RATE_MASK | WM9081_SAMPLE_RATE_MASK); |
1029 | 964 | ||
1030 | aif1 = wm9081_read(codec, WM9081_AUDIO_INTERFACE_1); | 965 | aif1 = snd_soc_read(codec, WM9081_AUDIO_INTERFACE_1); |
1031 | 966 | ||
1032 | aif2 = wm9081_read(codec, WM9081_AUDIO_INTERFACE_2); | 967 | aif2 = snd_soc_read(codec, WM9081_AUDIO_INTERFACE_2); |
1033 | aif2 &= ~WM9081_AIF_WL_MASK; | 968 | aif2 &= ~WM9081_AIF_WL_MASK; |
1034 | 969 | ||
1035 | aif3 = wm9081_read(codec, WM9081_AUDIO_INTERFACE_3); | 970 | aif3 = snd_soc_read(codec, WM9081_AUDIO_INTERFACE_3); |
1036 | aif3 &= ~WM9081_BCLK_DIV_MASK; | 971 | aif3 &= ~WM9081_BCLK_DIV_MASK; |
1037 | 972 | ||
1038 | aif4 = wm9081_read(codec, WM9081_AUDIO_INTERFACE_4); | 973 | aif4 = snd_soc_read(codec, WM9081_AUDIO_INTERFACE_4); |
1039 | aif4 &= ~WM9081_LRCLK_RATE_MASK; | 974 | aif4 &= ~WM9081_LRCLK_RATE_MASK; |
1040 | 975 | ||
1041 | /* What BCLK do we need? */ | 976 | /* What BCLK do we need? */ |
@@ -1149,22 +1084,22 @@ static int wm9081_hw_params(struct snd_pcm_substream *substream, | |||
1149 | s->name, s->rate); | 1084 | s->name, s->rate); |
1150 | 1085 | ||
1151 | /* If the EQ is enabled then disable it while we write out */ | 1086 | /* If the EQ is enabled then disable it while we write out */ |
1152 | eq1 = wm9081_read(codec, WM9081_EQ_1) & WM9081_EQ_ENA; | 1087 | eq1 = snd_soc_read(codec, WM9081_EQ_1) & WM9081_EQ_ENA; |
1153 | if (eq1 & WM9081_EQ_ENA) | 1088 | if (eq1 & WM9081_EQ_ENA) |
1154 | wm9081_write(codec, WM9081_EQ_1, 0); | 1089 | snd_soc_write(codec, WM9081_EQ_1, 0); |
1155 | 1090 | ||
1156 | /* Write out the other values */ | 1091 | /* Write out the other values */ |
1157 | for (i = 1; i < ARRAY_SIZE(s->config); i++) | 1092 | for (i = 1; i < ARRAY_SIZE(s->config); i++) |
1158 | wm9081_write(codec, WM9081_EQ_1 + i, s->config[i]); | 1093 | snd_soc_write(codec, WM9081_EQ_1 + i, s->config[i]); |
1159 | 1094 | ||
1160 | eq1 |= (s->config[0] & ~WM9081_EQ_ENA); | 1095 | eq1 |= (s->config[0] & ~WM9081_EQ_ENA); |
1161 | wm9081_write(codec, WM9081_EQ_1, eq1); | 1096 | snd_soc_write(codec, WM9081_EQ_1, eq1); |
1162 | } | 1097 | } |
1163 | 1098 | ||
1164 | wm9081_write(codec, WM9081_CLOCK_CONTROL_2, clk_ctrl2); | 1099 | snd_soc_write(codec, WM9081_CLOCK_CONTROL_2, clk_ctrl2); |
1165 | wm9081_write(codec, WM9081_AUDIO_INTERFACE_2, aif2); | 1100 | snd_soc_write(codec, WM9081_AUDIO_INTERFACE_2, aif2); |
1166 | wm9081_write(codec, WM9081_AUDIO_INTERFACE_3, aif3); | 1101 | snd_soc_write(codec, WM9081_AUDIO_INTERFACE_3, aif3); |
1167 | wm9081_write(codec, WM9081_AUDIO_INTERFACE_4, aif4); | 1102 | snd_soc_write(codec, WM9081_AUDIO_INTERFACE_4, aif4); |
1168 | 1103 | ||
1169 | return 0; | 1104 | return 0; |
1170 | } | 1105 | } |
@@ -1174,14 +1109,14 @@ static int wm9081_digital_mute(struct snd_soc_dai *codec_dai, int mute) | |||
1174 | struct snd_soc_codec *codec = codec_dai->codec; | 1109 | struct snd_soc_codec *codec = codec_dai->codec; |
1175 | unsigned int reg; | 1110 | unsigned int reg; |
1176 | 1111 | ||
1177 | reg = wm9081_read(codec, WM9081_DAC_DIGITAL_2); | 1112 | reg = snd_soc_read(codec, WM9081_DAC_DIGITAL_2); |
1178 | 1113 | ||
1179 | if (mute) | 1114 | if (mute) |
1180 | reg |= WM9081_DAC_MUTE; | 1115 | reg |= WM9081_DAC_MUTE; |
1181 | else | 1116 | else |
1182 | reg &= ~WM9081_DAC_MUTE; | 1117 | reg &= ~WM9081_DAC_MUTE; |
1183 | 1118 | ||
1184 | wm9081_write(codec, WM9081_DAC_DIGITAL_2, reg); | 1119 | snd_soc_write(codec, WM9081_DAC_DIGITAL_2, reg); |
1185 | 1120 | ||
1186 | return 0; | 1121 | return 0; |
1187 | } | 1122 | } |
@@ -1210,7 +1145,7 @@ static int wm9081_set_tdm_slot(struct snd_soc_dai *dai, | |||
1210 | unsigned int mask, int slots) | 1145 | unsigned int mask, int slots) |
1211 | { | 1146 | { |
1212 | struct snd_soc_codec *codec = dai->codec; | 1147 | struct snd_soc_codec *codec = dai->codec; |
1213 | unsigned int aif1 = wm9081_read(codec, WM9081_AUDIO_INTERFACE_1); | 1148 | unsigned int aif1 = snd_soc_read(codec, WM9081_AUDIO_INTERFACE_1); |
1214 | 1149 | ||
1215 | aif1 &= ~(WM9081_AIFDAC_TDM_SLOT_MASK | WM9081_AIFDAC_TDM_MODE_MASK); | 1150 | aif1 &= ~(WM9081_AIFDAC_TDM_SLOT_MASK | WM9081_AIFDAC_TDM_MODE_MASK); |
1216 | 1151 | ||
@@ -1235,7 +1170,7 @@ static int wm9081_set_tdm_slot(struct snd_soc_dai *dai, | |||
1235 | return -EINVAL; | 1170 | return -EINVAL; |
1236 | } | 1171 | } |
1237 | 1172 | ||
1238 | wm9081_write(codec, WM9081_AUDIO_INTERFACE_1, aif1); | 1173 | snd_soc_write(codec, WM9081_AUDIO_INTERFACE_1, aif1); |
1239 | 1174 | ||
1240 | return 0; | 1175 | return 0; |
1241 | } | 1176 | } |
@@ -1357,7 +1292,7 @@ static int wm9081_resume(struct platform_device *pdev) | |||
1357 | if (i == WM9081_SOFTWARE_RESET) | 1292 | if (i == WM9081_SOFTWARE_RESET) |
1358 | continue; | 1293 | continue; |
1359 | 1294 | ||
1360 | wm9081_write(codec, i, reg_cache[i]); | 1295 | snd_soc_write(codec, i, reg_cache[i]); |
1361 | } | 1296 | } |
1362 | 1297 | ||
1363 | wm9081_set_bias_level(codec, SND_SOC_BIAS_STANDBY); | 1298 | wm9081_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
@@ -1377,7 +1312,8 @@ struct snd_soc_codec_device soc_codec_dev_wm9081 = { | |||
1377 | }; | 1312 | }; |
1378 | EXPORT_SYMBOL_GPL(soc_codec_dev_wm9081); | 1313 | EXPORT_SYMBOL_GPL(soc_codec_dev_wm9081); |
1379 | 1314 | ||
1380 | static int wm9081_register(struct wm9081_priv *wm9081) | 1315 | static int wm9081_register(struct wm9081_priv *wm9081, |
1316 | enum snd_soc_control_type control) | ||
1381 | { | 1317 | { |
1382 | struct snd_soc_codec *codec = &wm9081->codec; | 1318 | struct snd_soc_codec *codec = &wm9081->codec; |
1383 | int ret; | 1319 | int ret; |
@@ -1396,19 +1332,24 @@ static int wm9081_register(struct wm9081_priv *wm9081) | |||
1396 | codec->private_data = wm9081; | 1332 | codec->private_data = wm9081; |
1397 | codec->name = "WM9081"; | 1333 | codec->name = "WM9081"; |
1398 | codec->owner = THIS_MODULE; | 1334 | codec->owner = THIS_MODULE; |
1399 | codec->read = wm9081_read; | ||
1400 | codec->write = wm9081_write; | ||
1401 | codec->dai = &wm9081_dai; | 1335 | codec->dai = &wm9081_dai; |
1402 | codec->num_dai = 1; | 1336 | codec->num_dai = 1; |
1403 | codec->reg_cache_size = ARRAY_SIZE(wm9081->reg_cache); | 1337 | codec->reg_cache_size = ARRAY_SIZE(wm9081->reg_cache); |
1404 | codec->reg_cache = &wm9081->reg_cache; | 1338 | codec->reg_cache = &wm9081->reg_cache; |
1405 | codec->bias_level = SND_SOC_BIAS_OFF; | 1339 | codec->bias_level = SND_SOC_BIAS_OFF; |
1406 | codec->set_bias_level = wm9081_set_bias_level; | 1340 | codec->set_bias_level = wm9081_set_bias_level; |
1341 | codec->volatile_register = wm9081_volatile_register; | ||
1407 | 1342 | ||
1408 | memcpy(codec->reg_cache, wm9081_reg_defaults, | 1343 | memcpy(codec->reg_cache, wm9081_reg_defaults, |
1409 | sizeof(wm9081_reg_defaults)); | 1344 | sizeof(wm9081_reg_defaults)); |
1410 | 1345 | ||
1411 | reg = wm9081_read_hw(codec, WM9081_SOFTWARE_RESET); | 1346 | ret = snd_soc_codec_set_cache_io(codec, 8, 16, control); |
1347 | if (ret != 0) { | ||
1348 | dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); | ||
1349 | return ret; | ||
1350 | } | ||
1351 | |||
1352 | reg = snd_soc_read(codec, WM9081_SOFTWARE_RESET); | ||
1412 | if (reg != 0x9081) { | 1353 | if (reg != 0x9081) { |
1413 | dev_err(codec->dev, "Device is not a WM9081: ID=0x%x\n", reg); | 1354 | dev_err(codec->dev, "Device is not a WM9081: ID=0x%x\n", reg); |
1414 | ret = -EINVAL; | 1355 | ret = -EINVAL; |
@@ -1424,10 +1365,10 @@ static int wm9081_register(struct wm9081_priv *wm9081) | |||
1424 | wm9081_set_bias_level(codec, SND_SOC_BIAS_STANDBY); | 1365 | wm9081_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
1425 | 1366 | ||
1426 | /* Enable zero cross by default */ | 1367 | /* Enable zero cross by default */ |
1427 | reg = wm9081_read(codec, WM9081_ANALOGUE_LINEOUT); | 1368 | reg = snd_soc_read(codec, WM9081_ANALOGUE_LINEOUT); |
1428 | wm9081_write(codec, WM9081_ANALOGUE_LINEOUT, reg | WM9081_LINEOUTZC); | 1369 | snd_soc_write(codec, WM9081_ANALOGUE_LINEOUT, reg | WM9081_LINEOUTZC); |
1429 | reg = wm9081_read(codec, WM9081_ANALOGUE_SPEAKER_PGA); | 1370 | reg = snd_soc_read(codec, WM9081_ANALOGUE_SPEAKER_PGA); |
1430 | wm9081_write(codec, WM9081_ANALOGUE_SPEAKER_PGA, | 1371 | snd_soc_write(codec, WM9081_ANALOGUE_SPEAKER_PGA, |
1431 | reg | WM9081_SPKPGAZC); | 1372 | reg | WM9081_SPKPGAZC); |
1432 | 1373 | ||
1433 | wm9081_dai.dev = codec->dev; | 1374 | wm9081_dai.dev = codec->dev; |
@@ -1482,7 +1423,7 @@ static __devinit int wm9081_i2c_probe(struct i2c_client *i2c, | |||
1482 | 1423 | ||
1483 | codec->dev = &i2c->dev; | 1424 | codec->dev = &i2c->dev; |
1484 | 1425 | ||
1485 | return wm9081_register(wm9081); | 1426 | return wm9081_register(wm9081, SND_SOC_I2C); |
1486 | } | 1427 | } |
1487 | 1428 | ||
1488 | static __devexit int wm9081_i2c_remove(struct i2c_client *client) | 1429 | static __devexit int wm9081_i2c_remove(struct i2c_client *client) |