1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2012 Samsung Electronics
4 * R. Chandrasekar <rcsekar@samsung.com>
7 #include <audio_codec.h>
17 #include <asm/arch/clk.h>
18 #include <asm/arch/cpu.h>
19 #include <asm/arch/sound.h>
21 #include "wm8994_registers.h"
23 /* defines for wm8994 system clock selection */
24 #define SEL_MCLK1 0x00
25 #define SEL_MCLK2 0x08
29 /* fll config to configure fll */
30 struct wm8994_fll_config {
32 int in; /* Input frequency in Hz */
33 int out; /* output frequency in Hz */
36 /* codec private data */
38 enum wm8994_type type; /* codec type of wolfson */
39 int revision; /* Revision */
40 int sysclk[WM8994_MAX_AIF]; /* System clock frequency in Hz */
41 int mclk[WM8994_MAX_AIF]; /* master clock frequency in Hz */
42 int aifclk[WM8994_MAX_AIF]; /* audio interface clock in Hz */
43 struct wm8994_fll_config fll[2]; /* fll config to configure fll */
47 /* wm 8994 supported sampling rate values */
48 static unsigned int src_rate[] = {
49 8000, 11025, 12000, 16000, 22050, 24000,
50 32000, 44100, 48000, 88200, 96000
53 /* op clock divisions */
54 static int opclk_divs[] = { 10, 20, 30, 40, 55, 60, 80, 120, 160 };
56 /* lr clock frame size ratio */
57 static int fs_ratios[] = {
58 64, 128, 192, 256, 348, 512, 768, 1024, 1408, 1536
61 /* bit clock divisors */
62 static int bclk_divs[] = {
63 10, 15, 20, 30, 40, 50, 60, 80, 110, 120, 160, 220, 240, 320, 440, 480,
64 640, 880, 960, 1280, 1760, 1920
68 * Writes value to a device register through i2c
70 * @param priv Private data for driver
71 * @param reg reg number to be write
72 * @param data data to be writen to the above registor
74 * @return int value 1 for change, 0 for no change or negative error code.
76 static int wm8994_i2c_write(struct wm8994_priv *priv, unsigned int reg,
81 val[0] = (unsigned char)((data >> 8) & 0xff);
82 val[1] = (unsigned char)(data & 0xff);
83 debug("Write Addr : 0x%04X, Data : 0x%04X\n", reg, data);
85 return dm_i2c_write(priv->dev, reg, val, 2);
89 * Read a value from a device register through i2c
91 * @param priv Private data for driver
92 * @param reg reg number to be read
93 * @param data address of read data to be stored
95 * @return int value 0 for success, -1 in case of error.
97 static unsigned int wm8994_i2c_read(struct wm8994_priv *priv, unsigned int reg,
100 unsigned char val[2];
103 ret = dm_i2c_read(priv->dev, reg, val, 1);
105 debug("%s: Error while reading register %#04x\n",
118 * update device register bits through i2c
120 * @param priv Private data for driver
121 * @param reg codec register
122 * @param mask register mask
123 * @param value new value
125 * @return int value 1 if change in the register value,
126 * 0 for no change or negative error code.
128 static int wm8994_bic_or(struct wm8994_priv *priv, unsigned int reg,
129 unsigned short mask, unsigned short value)
131 int change , ret = 0;
132 unsigned short old, new;
134 if (wm8994_i2c_read(priv, reg, &old) != 0)
136 new = (old & ~mask) | (value & mask);
137 change = (old != new) ? 1 : 0;
139 ret = wm8994_i2c_write(priv, reg, new);
147 * Sets i2s set format
149 * @param priv wm8994 information
150 * @param aif_id Interface ID
151 * @param fmt i2S format
153 * @return -1 for error and 0 Success.
155 static int wm8994_set_fmt(struct wm8994_priv *priv, int aif_id, uint fmt)
166 ms_reg = WM8994_AIF1_MASTER_SLAVE;
167 aif_reg = WM8994_AIF1_CONTROL_1;
168 aif_clk = WM8994_AIF1_CLOCKING_1;
171 ms_reg = WM8994_AIF2_MASTER_SLAVE;
172 aif_reg = WM8994_AIF2_CONTROL_1;
173 aif_clk = WM8994_AIF2_CLOCKING_1;
176 debug("%s: Invalid audio interface selection\n", __func__);
180 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
181 case SND_SOC_DAIFMT_CBS_CFS:
183 case SND_SOC_DAIFMT_CBM_CFM:
184 ms = WM8994_AIF1_MSTR;
187 debug("%s: Invalid i2s master selection\n", __func__);
191 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
192 case SND_SOC_DAIFMT_DSP_B:
193 aif |= WM8994_AIF1_LRCLK_INV;
194 case SND_SOC_DAIFMT_DSP_A:
197 case SND_SOC_DAIFMT_I2S:
200 case SND_SOC_DAIFMT_RIGHT_J:
202 case SND_SOC_DAIFMT_LEFT_J:
206 debug("%s: Invalid i2s format selection\n", __func__);
210 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
211 case SND_SOC_DAIFMT_DSP_A:
212 case SND_SOC_DAIFMT_DSP_B:
213 /* frame inversion not valid for DSP modes */
214 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
215 case SND_SOC_DAIFMT_NB_NF:
217 case SND_SOC_DAIFMT_IB_NF:
218 aif |= WM8994_AIF1_BCLK_INV;
221 debug("%s: Invalid i2s frame inverse selection\n",
227 case SND_SOC_DAIFMT_I2S:
228 case SND_SOC_DAIFMT_RIGHT_J:
229 case SND_SOC_DAIFMT_LEFT_J:
230 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
231 case SND_SOC_DAIFMT_NB_NF:
233 case SND_SOC_DAIFMT_IB_IF:
234 aif |= WM8994_AIF1_BCLK_INV | WM8994_AIF1_LRCLK_INV;
236 case SND_SOC_DAIFMT_IB_NF:
237 aif |= WM8994_AIF1_BCLK_INV;
239 case SND_SOC_DAIFMT_NB_IF:
240 aif |= WM8994_AIF1_LRCLK_INV;
243 debug("%s: Invalid i2s clock polarity selection\n",
249 debug("%s: Invalid i2s format selection\n", __func__);
253 error = wm8994_bic_or(priv, aif_reg, WM8994_AIF1_BCLK_INV |
254 WM8994_AIF1_LRCLK_INV_MASK |
255 WM8994_AIF1_FMT_MASK, aif);
257 error |= wm8994_bic_or(priv, ms_reg, WM8994_AIF1_MSTR_MASK, ms);
258 error |= wm8994_bic_or(priv, aif_clk, WM8994_AIF1CLK_ENA_MASK,
261 debug("%s: codec register access error\n", __func__);
269 * Sets hw params FOR WM8994
271 * @param priv wm8994 information pointer
272 * @param aif_id Audio interface ID
273 * @param sampling_rate Sampling rate
274 * @param bits_per_sample Bits per sample
275 * @param Channels Channels in the given audio input
277 * @return -1 for error and 0 Success.
279 static int wm8994_hw_params(struct wm8994_priv *priv, int aif_id,
280 uint sampling_rate, uint bits_per_sample,
292 int i, cur_val, best_val, bclk_rate, best;
293 unsigned short reg_data;
298 aif1_reg = WM8994_AIF1_CONTROL_1;
299 aif2_reg = WM8994_AIF1_CONTROL_2;
300 bclk_reg = WM8994_AIF1_BCLK;
301 rate_reg = WM8994_AIF1_RATE;
304 aif1_reg = WM8994_AIF2_CONTROL_1;
305 aif2_reg = WM8994_AIF2_CONTROL_2;
306 bclk_reg = WM8994_AIF2_BCLK;
307 rate_reg = WM8994_AIF2_RATE;
313 bclk_rate = sampling_rate * 32;
314 switch (bits_per_sample) {
334 /* Try to find an appropriate sample rate; look for an exact match. */
335 for (i = 0; i < ARRAY_SIZE(src_rate); i++)
336 if (src_rate[i] == sampling_rate)
339 if (i == ARRAY_SIZE(src_rate)) {
340 debug("%s: Could not get the best matching samplingrate\n",
345 rate_val |= i << WM8994_AIF1_SR_SHIFT;
347 /* AIFCLK/fs ratio; look for a close match in either direction */
349 best_val = abs((fs_ratios[0] * sampling_rate) - priv->aifclk[id]);
351 for (i = 1; i < ARRAY_SIZE(fs_ratios); i++) {
352 cur_val = abs(fs_ratios[i] * sampling_rate - priv->aifclk[id]);
353 if (cur_val >= best_val)
362 * We may not get quite the right frequency if using
363 * approximate clocks so look for the closest match that is
364 * higher than the target (we need to ensure that there enough
365 * BCLKs to clock out the samples).
368 for (i = 0; i < ARRAY_SIZE(bclk_divs); i++) {
369 cur_val = (priv->aifclk[id] * 10 / bclk_divs[i]) - bclk_rate;
370 if (cur_val < 0) /* BCLK table is sorted */
375 if (i == ARRAY_SIZE(bclk_divs)) {
376 debug("%s: Could not get the best matching bclk division\n",
381 bclk_rate = priv->aifclk[id] * 10 / bclk_divs[best];
382 bclk |= best << WM8994_AIF1_BCLK_DIV_SHIFT;
384 if (wm8994_i2c_read(priv, aif1_reg, ®_data) != 0) {
385 debug("%s: AIF1 register read Failed\n", __func__);
389 if ((channels == 1) && ((reg_data & 0x18) == 0x18))
390 aif2 |= WM8994_AIF1_MONO;
392 if (priv->aifclk[id] == 0) {
393 debug("%s:Audio interface clock not set\n", __func__);
397 ret = wm8994_bic_or(priv, aif1_reg, WM8994_AIF1_WL_MASK, aif1);
398 ret |= wm8994_bic_or(priv, aif2_reg, WM8994_AIF1_MONO, aif2);
399 ret |= wm8994_bic_or(priv, bclk_reg, WM8994_AIF1_BCLK_DIV_MASK,
401 ret |= wm8994_bic_or(priv, rate_reg, WM8994_AIF1_SR_MASK |
402 WM8994_AIF1CLK_RATE_MASK, rate_val);
404 debug("rate vale = %x , bclk val= %x\n", rate_val, bclk);
407 debug("%s: codec register access error\n", __func__);
415 * Configures Audio interface Clock
417 * @param priv wm8994 information pointer
418 * @param aif Audio Interface ID
420 * @return -1 for error and 0 Success.
422 static int configure_aif_clock(struct wm8994_priv *priv, int aif)
429 /* AIF(1/0) register adress offset calculated */
435 switch (priv->sysclk[aif - 1]) {
436 case WM8994_SYSCLK_MCLK1:
438 rate = priv->mclk[0];
441 case WM8994_SYSCLK_MCLK2:
443 rate = priv->mclk[1];
446 case WM8994_SYSCLK_FLL1:
448 rate = priv->fll[0].out;
451 case WM8994_SYSCLK_FLL2:
453 rate = priv->fll[1].out;
457 debug("%s: Invalid input clock selection [%d]\n",
458 __func__, priv->sysclk[aif - 1]);
462 /* if input clock frequenct is more than 135Mhz then divide */
463 if (rate >= WM8994_MAX_INPUT_CLK_FREQ) {
465 reg1 |= WM8994_AIF1CLK_DIV;
468 priv->aifclk[aif - 1] = rate;
470 ret = wm8994_bic_or(priv, WM8994_AIF1_CLOCKING_1 + offset,
471 WM8994_AIF1CLK_SRC_MASK | WM8994_AIF1CLK_DIV,
474 if (aif == WM8994_AIF1)
475 ret |= wm8994_bic_or(priv, WM8994_CLOCKING_1,
476 WM8994_AIF1DSPCLK_ENA_MASK | WM8994_SYSDSPCLK_ENA_MASK,
477 WM8994_AIF1DSPCLK_ENA | WM8994_SYSDSPCLK_ENA);
478 else if (aif == WM8994_AIF2)
479 ret |= wm8994_bic_or(priv, WM8994_CLOCKING_1,
480 WM8994_SYSCLK_SRC | WM8994_AIF2DSPCLK_ENA_MASK |
481 WM8994_SYSDSPCLK_ENA_MASK, WM8994_SYSCLK_SRC |
482 WM8994_AIF2DSPCLK_ENA | WM8994_SYSDSPCLK_ENA);
485 debug("%s: codec register access error\n", __func__);
493 * Configures Audio interface for the given frequency
495 * @param priv wm8994 information
496 * @param aif_id Audio Interface
497 * @param clk_id Input Clock ID
498 * @param freq Sampling frequency in Hz
500 * @return -1 for error and 0 success.
502 static int wm8994_set_sysclk(struct wm8994_priv *priv, int aif_id, int clk_id,
508 priv->sysclk[aif_id - 1] = clk_id;
511 case WM8994_SYSCLK_MCLK1:
512 priv->mclk[0] = freq;
514 ret = wm8994_bic_or(priv, WM8994_AIF1_CLOCKING_2,
515 WM8994_AIF2DAC_DIV_MASK, 0);
519 case WM8994_SYSCLK_MCLK2:
520 /* TODO: Set GPIO AF */
521 priv->mclk[1] = freq;
524 case WM8994_SYSCLK_FLL1:
525 case WM8994_SYSCLK_FLL2:
528 case WM8994_SYSCLK_OPCLK:
530 * Special case - a division (times 10) is given and
531 * no effect on main clocking.
534 for (i = 0; i < ARRAY_SIZE(opclk_divs); i++)
535 if (opclk_divs[i] == freq)
537 if (i == ARRAY_SIZE(opclk_divs)) {
538 debug("%s frequency divisor not found\n",
542 ret = wm8994_bic_or(priv, WM8994_CLOCKING_2,
543 WM8994_OPCLK_DIV_MASK, i);
544 ret |= wm8994_bic_or(priv, WM8994_POWER_MANAGEMENT_2,
548 ret |= wm8994_bic_or(priv, WM8994_POWER_MANAGEMENT_2,
549 WM8994_OPCLK_ENA, 0);
553 debug("%s Invalid input clock selection [%d]\n",
558 ret |= configure_aif_clock(priv, aif_id);
561 debug("%s: codec register access error\n", __func__);
569 * Initializes Volume for AIF2 to HP path
571 * @param priv wm8994 information
572 * @returns -1 for error and 0 Success.
575 static int wm8994_init_volume_aif2_dac1(struct wm8994_priv *priv)
580 ret = wm8994_bic_or(priv, WM8994_AIF2_DAC_FILTERS_1,
581 WM8994_AIF2DAC_MUTE_MASK, 0);
584 ret |= wm8994_bic_or(priv, WM8994_AIF2_DAC_LEFT_VOLUME,
585 WM8994_AIF2DAC_VU_MASK | WM8994_AIF2DACL_VOL_MASK,
586 WM8994_AIF2DAC_VU | 0xff);
588 ret |= wm8994_bic_or(priv, WM8994_AIF2_DAC_RIGHT_VOLUME,
589 WM8994_AIF2DAC_VU_MASK | WM8994_AIF2DACR_VOL_MASK,
590 WM8994_AIF2DAC_VU | 0xff);
593 ret |= wm8994_bic_or(priv, WM8994_DAC1_LEFT_VOLUME,
594 WM8994_DAC1_VU_MASK | WM8994_DAC1L_VOL_MASK |
595 WM8994_DAC1L_MUTE_MASK, WM8994_DAC1_VU | 0xc0);
597 ret |= wm8994_bic_or(priv, WM8994_DAC1_RIGHT_VOLUME,
598 WM8994_DAC1_VU_MASK | WM8994_DAC1R_VOL_MASK |
599 WM8994_DAC1R_MUTE_MASK, WM8994_DAC1_VU | 0xc0);
600 /* Head Phone Volume */
601 ret |= wm8994_i2c_write(priv, WM8994_LEFT_OUTPUT_VOLUME, 0x12D);
602 ret |= wm8994_i2c_write(priv, WM8994_RIGHT_OUTPUT_VOLUME, 0x12D);
605 debug("%s: codec register access error\n", __func__);
613 * Initializes Volume for AIF1 to HP path
615 * @param priv wm8994 information
616 * @returns -1 for error and 0 Success.
619 static int wm8994_init_volume_aif1_dac1(struct wm8994_priv *priv)
624 ret |= wm8994_i2c_write(priv, WM8994_AIF1_DAC_FILTERS_1, 0x0000);
626 ret |= wm8994_bic_or(priv, WM8994_DAC1_LEFT_VOLUME,
627 WM8994_DAC1_VU_MASK | WM8994_DAC1L_VOL_MASK |
628 WM8994_DAC1L_MUTE_MASK, WM8994_DAC1_VU | 0xc0);
630 ret |= wm8994_bic_or(priv, WM8994_DAC1_RIGHT_VOLUME,
631 WM8994_DAC1_VU_MASK | WM8994_DAC1R_VOL_MASK |
632 WM8994_DAC1R_MUTE_MASK, WM8994_DAC1_VU | 0xc0);
633 /* Head Phone Volume */
634 ret |= wm8994_i2c_write(priv, WM8994_LEFT_OUTPUT_VOLUME, 0x12D);
635 ret |= wm8994_i2c_write(priv, WM8994_RIGHT_OUTPUT_VOLUME, 0x12D);
638 debug("%s: codec register access error\n", __func__);
646 * Intialise wm8994 codec device
648 * @param priv wm8994 information
650 * @returns -1 for error and 0 Success.
652 static int wm8994_device_init(struct wm8994_priv *priv)
655 unsigned short reg_data;
658 wm8994_i2c_write(priv, WM8994_SOFTWARE_RESET, WM8994_SW_RESET);
660 ret = wm8994_i2c_read(priv, WM8994_SOFTWARE_RESET, ®_data);
662 debug("Failed to read ID register\n");
666 if (reg_data == WM8994_ID) {
668 debug("Device registered as type %d\n", priv->type);
671 debug("Device is not a WM8994, ID is %x\n", ret);
675 ret = wm8994_i2c_read(priv, WM8994_CHIP_REVISION, ®_data);
677 debug("Failed to read revision register: %d\n", ret);
680 priv->revision = reg_data;
681 debug("%s revision %c\n", devname, 'A' + priv->revision);
686 static int wm8994_setup_interface(struct wm8994_priv *priv,
687 enum en_audio_interface aif_id)
692 ret = wm8994_bic_or(priv, WM8994_POWER_MANAGEMENT_1,
693 WM8994_VMID_SEL_MASK | WM8994_BIAS_ENA_MASK, 0x3);
695 /* Charge Pump Enable */
696 ret |= wm8994_bic_or(priv, WM8994_CHARGE_PUMP_1, WM8994_CP_ENA_MASK,
699 /* Head Phone Power Enable */
700 ret |= wm8994_bic_or(priv, WM8994_POWER_MANAGEMENT_1,
701 WM8994_HPOUT1L_ENA_MASK, WM8994_HPOUT1L_ENA);
703 ret |= wm8994_bic_or(priv, WM8994_POWER_MANAGEMENT_1,
704 WM8994_HPOUT1R_ENA_MASK, WM8994_HPOUT1R_ENA);
706 if (aif_id == WM8994_AIF1) {
707 ret |= wm8994_i2c_write(priv, WM8994_POWER_MANAGEMENT_2,
708 WM8994_TSHUT_ENA | WM8994_MIXINL_ENA |
709 WM8994_MIXINR_ENA | WM8994_IN2L_ENA |
712 ret |= wm8994_i2c_write(priv, WM8994_POWER_MANAGEMENT_4,
713 WM8994_ADCL_ENA | WM8994_ADCR_ENA |
714 WM8994_AIF1ADC1R_ENA |
715 WM8994_AIF1ADC1L_ENA);
717 /* Power enable for AIF1 and DAC1 */
718 ret |= wm8994_i2c_write(priv, WM8994_POWER_MANAGEMENT_5,
719 WM8994_AIF1DACL_ENA |
720 WM8994_AIF1DACR_ENA |
721 WM8994_DAC1L_ENA | WM8994_DAC1R_ENA);
722 } else if (aif_id == WM8994_AIF2) {
723 /* Power enable for AIF2 and DAC1 */
724 ret |= wm8994_bic_or(priv, WM8994_POWER_MANAGEMENT_5,
725 WM8994_AIF2DACL_ENA_MASK | WM8994_AIF2DACR_ENA_MASK |
726 WM8994_DAC1L_ENA_MASK | WM8994_DAC1R_ENA_MASK,
727 WM8994_AIF2DACL_ENA | WM8994_AIF2DACR_ENA |
728 WM8994_DAC1L_ENA | WM8994_DAC1R_ENA);
730 /* Head Phone Initialisation */
731 ret |= wm8994_bic_or(priv, WM8994_ANALOGUE_HP_1,
732 WM8994_HPOUT1L_DLY_MASK | WM8994_HPOUT1R_DLY_MASK,
733 WM8994_HPOUT1L_DLY | WM8994_HPOUT1R_DLY);
735 ret |= wm8994_bic_or(priv, WM8994_DC_SERVO_1,
736 WM8994_DCS_ENA_CHAN_0_MASK |
737 WM8994_DCS_ENA_CHAN_1_MASK , WM8994_DCS_ENA_CHAN_0 |
738 WM8994_DCS_ENA_CHAN_1);
740 ret |= wm8994_bic_or(priv, WM8994_ANALOGUE_HP_1,
741 WM8994_HPOUT1L_DLY_MASK |
742 WM8994_HPOUT1R_DLY_MASK | WM8994_HPOUT1L_OUTP_MASK |
743 WM8994_HPOUT1R_OUTP_MASK |
744 WM8994_HPOUT1L_RMV_SHORT_MASK |
745 WM8994_HPOUT1R_RMV_SHORT_MASK, WM8994_HPOUT1L_DLY |
746 WM8994_HPOUT1R_DLY | WM8994_HPOUT1L_OUTP |
747 WM8994_HPOUT1R_OUTP | WM8994_HPOUT1L_RMV_SHORT |
748 WM8994_HPOUT1R_RMV_SHORT);
750 /* MIXER Config DAC1 to HP */
751 ret |= wm8994_bic_or(priv, WM8994_OUTPUT_MIXER_1,
752 WM8994_DAC1L_TO_HPOUT1L_MASK,
753 WM8994_DAC1L_TO_HPOUT1L);
755 ret |= wm8994_bic_or(priv, WM8994_OUTPUT_MIXER_2,
756 WM8994_DAC1R_TO_HPOUT1R_MASK,
757 WM8994_DAC1R_TO_HPOUT1R);
759 if (aif_id == WM8994_AIF1) {
760 /* Routing AIF1 to DAC1 */
761 ret |= wm8994_i2c_write(priv, WM8994_DAC1_LEFT_MIXER_ROUTING,
762 WM8994_AIF1DAC1L_TO_DAC1L);
764 ret |= wm8994_i2c_write(priv, WM8994_DAC1_RIGHT_MIXER_ROUTING,
765 WM8994_AIF1DAC1R_TO_DAC1R);
767 /* GPIO Settings for AIF1 */
768 ret |= wm8994_i2c_write(priv, WM8994_GPIO_1,
769 WM8994_GPIO_DIR_OUTPUT |
770 WM8994_GPIO_FUNCTION_I2S_CLK |
771 WM8994_GPIO_INPUT_DEBOUNCE);
773 ret |= wm8994_init_volume_aif1_dac1(priv);
774 } else if (aif_id == WM8994_AIF2) {
775 /* Routing AIF2 to DAC1 */
776 ret |= wm8994_bic_or(priv, WM8994_DAC1_LEFT_MIXER_ROUTING,
777 WM8994_AIF2DACL_TO_DAC1L_MASK,
778 WM8994_AIF2DACL_TO_DAC1L);
780 ret |= wm8994_bic_or(priv, WM8994_DAC1_RIGHT_MIXER_ROUTING,
781 WM8994_AIF2DACR_TO_DAC1R_MASK,
782 WM8994_AIF2DACR_TO_DAC1R);
784 /* GPIO Settings for AIF2 */
786 ret |= wm8994_bic_or(priv, WM8994_GPIO_3, WM8994_GPIO_DIR_MASK |
787 WM8994_GPIO_FUNCTION_MASK,
788 WM8994_GPIO_DIR_OUTPUT);
791 ret |= wm8994_bic_or(priv, WM8994_GPIO_4, WM8994_GPIO_DIR_MASK |
792 WM8994_GPIO_FUNCTION_MASK,
793 WM8994_GPIO_DIR_OUTPUT);
796 ret |= wm8994_bic_or(priv, WM8994_GPIO_5, WM8994_GPIO_DIR_MASK |
797 WM8994_GPIO_FUNCTION_MASK,
798 WM8994_GPIO_DIR_OUTPUT);
800 ret |= wm8994_init_volume_aif2_dac1(priv);
806 debug("%s: Codec chip setup ok\n", __func__);
809 debug("%s: Codec chip setup error\n", __func__);
813 static int _wm8994_init(struct wm8994_priv *priv,
814 enum en_audio_interface aif_id, int sampling_rate,
815 int mclk_freq, int bits_per_sample,
816 unsigned int channels)
820 ret = wm8994_setup_interface(priv, aif_id);
822 debug("%s: wm8994 codec chip init failed\n", __func__);
826 ret = wm8994_set_sysclk(priv, aif_id, WM8994_SYSCLK_MCLK1, mclk_freq);
828 debug("%s: wm8994 codec set sys clock failed\n", __func__);
832 ret = wm8994_hw_params(priv, aif_id, sampling_rate, bits_per_sample,
836 ret = wm8994_set_fmt(priv, aif_id, SND_SOC_DAIFMT_I2S |
837 SND_SOC_DAIFMT_NB_NF |
838 SND_SOC_DAIFMT_CBS_CFS);
844 static int wm8994_set_params(struct udevice *dev, int interface, int rate,
845 int mclk_freq, int bits_per_sample, uint channels)
847 struct wm8994_priv *priv = dev_get_priv(dev);
849 return _wm8994_init(priv, interface, rate, mclk_freq, bits_per_sample,
853 static int wm8994_probe(struct udevice *dev)
855 struct wm8994_priv *priv = dev_get_priv(dev);
858 return wm8994_device_init(priv);
861 static const struct audio_codec_ops wm8994_ops = {
862 .set_params = wm8994_set_params,
865 static const struct udevice_id wm8994_ids[] = {
866 { .compatible = "wolfson,wm8994" },
870 U_BOOT_DRIVER(wm8994) = {
872 .id = UCLASS_AUDIO_CODEC,
873 .of_match = wm8994_ids,
874 .probe = wm8994_probe,
876 .priv_auto_alloc_size = sizeof(struct wm8994_priv),