]> git.sur5r.net Git - u-boot/blobdiff - drivers/sound/wm8994.c
vexpress: fix syntax error in armv7_boot_nonsec_default()
[u-boot] / drivers / sound / wm8994.c
index 293903ada2e5fb68f3dd6729d0d0978ae535c86b..b8208cdc87495e7c547831f4b6a11c3249f6fc32 100644 (file)
@@ -2,33 +2,19 @@
  * Copyright (C) 2012 Samsung Electronics
  * R. Chandrasekar <rcsekar@samsung.com>
  *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
+ * SPDX-License-Identifier:    GPL-2.0+
  */
+#include <common.h>
 #include <asm/arch/clk.h>
 #include <asm/arch/cpu.h>
 #include <asm/gpio.h>
 #include <asm/io.h>
-#include <common.h>
 #include <div64.h>
+#include <fdtdec.h>
 #include <i2c.h>
 #include <i2s.h>
 #include <sound.h>
+#include <asm/arch/sound.h>
 #include "wm8994.h"
 #include "wm8994_registers.h"
 
@@ -77,6 +63,7 @@ static int bclk_divs[] = {
 
 static struct wm8994_priv g_wm8994_info;
 static unsigned char g_wm8994_i2c_dev_addr;
+static struct sound_codec_info g_codec_info;
 
 /*
  * Initialise I2C for wm 8994
@@ -445,12 +432,12 @@ static int configure_aif_clock(struct wm8994_priv *wm8994, int aif)
        int ret;
 
        /* AIF(1/0) register adress offset calculated */
-       if (aif)
+       if (aif-1)
                offset = 4;
        else
                offset = 0;
 
-       switch (wm8994->sysclk[aif]) {
+       switch (wm8994->sysclk[aif-1]) {
        case WM8994_SYSCLK_MCLK1:
                reg1 |= SEL_MCLK1;
                rate = wm8994->mclk[0];
@@ -473,7 +460,7 @@ static int configure_aif_clock(struct wm8994_priv *wm8994, int aif)
 
        default:
                debug("%s: Invalid input clock selection [%d]\n",
-                     __func__, wm8994->sysclk[aif]);
+                     __func__, wm8994->sysclk[aif-1]);
                return -1;
        }
 
@@ -483,13 +470,18 @@ static int configure_aif_clock(struct wm8994_priv *wm8994, int aif)
                reg1 |= WM8994_AIF1CLK_DIV;
        }
 
-       wm8994->aifclk[aif] = rate;
+       wm8994->aifclk[aif-1] = rate;
 
        ret = wm8994_update_bits(WM8994_AIF1_CLOCKING_1 + offset,
                                WM8994_AIF1CLK_SRC_MASK | WM8994_AIF1CLK_DIV,
                                reg1);
 
-       ret |= wm8994_update_bits(WM8994_CLOCKING_1,
+       if (aif == WM8994_AIF1)
+               ret |= wm8994_update_bits(WM8994_CLOCKING_1,
+                       WM8994_AIF1DSPCLK_ENA_MASK | WM8994_SYSDSPCLK_ENA_MASK,
+                       WM8994_AIF1DSPCLK_ENA | WM8994_SYSDSPCLK_ENA);
+       else if (aif == WM8994_AIF2)
+               ret |= wm8994_update_bits(WM8994_CLOCKING_1,
                        WM8994_SYSCLK_SRC | WM8994_AIF2DSPCLK_ENA_MASK |
                        WM8994_SYSDSPCLK_ENA_MASK, WM8994_SYSCLK_SRC |
                        WM8994_AIF2DSPCLK_ENA | WM8994_SYSDSPCLK_ENA);
@@ -549,7 +541,7 @@ static int wm8994_set_sysclk(struct wm8994_priv *wm8994, int aif_id,
                                        break;
                        if (i == ARRAY_SIZE(opclk_divs)) {
                                debug("%s frequency divisor not found\n",
-                                       __func__);
+                                     __func__);
                                return -1;
                        }
                        ret = wm8994_update_bits(WM8994_CLOCKING_2,
@@ -567,7 +559,7 @@ static int wm8994_set_sysclk(struct wm8994_priv *wm8994, int aif_id,
                return -1;
        }
 
-       ret |= configure_aif_clock(wm8994, aif_id - 1);
+       ret |= configure_aif_clock(wm8994, aif_id);
 
        if (ret < 0) {
                debug("%s: codec register access error\n", __func__);
@@ -620,6 +612,38 @@ static int wm8994_init_volume_aif2_dac1(void)
        return 0;
 }
 
+/*
+ * Initializes Volume for AIF1 to HP path
+ *
+ * @returns -1 for error  and 0 Success.
+ *
+ */
+static int wm8994_init_volume_aif1_dac1(void)
+{
+       int ret = 0;
+
+       /* Unmute AIF1DAC */
+       ret |= wm8994_i2c_write(WM8994_AIF1_DAC_FILTERS_1, 0x0000);
+
+       ret |= wm8994_update_bits(WM8994_DAC1_LEFT_VOLUME,
+                       WM8994_DAC1_VU_MASK | WM8994_DAC1L_VOL_MASK |
+                       WM8994_DAC1L_MUTE_MASK, WM8994_DAC1_VU | 0xc0);
+
+       ret |= wm8994_update_bits(WM8994_DAC1_RIGHT_VOLUME,
+                       WM8994_DAC1_VU_MASK | WM8994_DAC1R_VOL_MASK |
+                       WM8994_DAC1R_MUTE_MASK, WM8994_DAC1_VU | 0xc0);
+       /* Head Phone Volume */
+       ret |= wm8994_i2c_write(WM8994_LEFT_OUTPUT_VOLUME, 0x12D);
+       ret |= wm8994_i2c_write(WM8994_RIGHT_OUTPUT_VOLUME, 0x12D);
+
+       if (ret < 0) {
+               debug("%s: codec register access error\n", __func__);
+               return -1;
+       }
+
+       return 0;
+}
+
 /*
  * Intialise wm8994 codec device
  *
@@ -627,7 +651,8 @@ static int wm8994_init_volume_aif2_dac1(void)
  *
  * @returns -1 for error  and 0 Success.
  */
-static int wm8994_device_init(struct wm8994_priv *wm8994)
+static int wm8994_device_init(struct wm8994_priv *wm8994,
+                             enum en_audio_interface aif_id)
 {
        const char *devname;
        unsigned short reg_data;
@@ -674,13 +699,30 @@ static int wm8994_device_init(struct wm8994_priv *wm8994)
        ret |= wm8994_update_bits(WM8994_POWER_MANAGEMENT_1,
                                WM8994_HPOUT1R_ENA_MASK, WM8994_HPOUT1R_ENA);
 
-       /* Power enable for AIF2 and DAC1 */
-       ret |= wm8994_update_bits(WM8994_POWER_MANAGEMENT_5,
-               WM8994_AIF2DACL_ENA_MASK | WM8994_AIF2DACR_ENA_MASK |
-               WM8994_DAC1L_ENA_MASK | WM8994_DAC1R_ENA_MASK,
-               WM8994_AIF2DACL_ENA | WM8994_AIF2DACR_ENA | WM8994_DAC1L_ENA |
-               WM8994_DAC1R_ENA);
-
+       if (aif_id == WM8994_AIF1) {
+               ret |= wm8994_i2c_write(WM8994_POWER_MANAGEMENT_2,
+                                       WM8994_TSHUT_ENA | WM8994_MIXINL_ENA |
+                                       WM8994_MIXINR_ENA | WM8994_IN2L_ENA |
+                                       WM8994_IN2R_ENA);
+
+               ret |= wm8994_i2c_write(WM8994_POWER_MANAGEMENT_4,
+                                       WM8994_ADCL_ENA | WM8994_ADCR_ENA |
+                                       WM8994_AIF1ADC1R_ENA |
+                                       WM8994_AIF1ADC1L_ENA);
+
+               /* Power enable for AIF1 and DAC1 */
+               ret |= wm8994_i2c_write(WM8994_POWER_MANAGEMENT_5,
+                                       WM8994_AIF1DACL_ENA |
+                                       WM8994_AIF1DACR_ENA |
+                                       WM8994_DAC1L_ENA | WM8994_DAC1R_ENA);
+       } else if (aif_id == WM8994_AIF2) {
+               /* Power enable for AIF2 and DAC1 */
+               ret |= wm8994_update_bits(WM8994_POWER_MANAGEMENT_5,
+                       WM8994_AIF2DACL_ENA_MASK | WM8994_AIF2DACR_ENA_MASK |
+                       WM8994_DAC1L_ENA_MASK | WM8994_DAC1R_ENA_MASK,
+                       WM8994_AIF2DACL_ENA | WM8994_AIF2DACR_ENA |
+                       WM8994_DAC1L_ENA | WM8994_DAC1R_ENA);
+       }
        /* Head Phone Initialisation */
        ret |= wm8994_update_bits(WM8994_ANALOGUE_HP_1,
                WM8994_HPOUT1L_DLY_MASK | WM8994_HPOUT1R_DLY_MASK,
@@ -708,35 +750,49 @@ static int wm8994_device_init(struct wm8994_priv *wm8994)
        ret |= wm8994_update_bits(WM8994_OUTPUT_MIXER_2,
                        WM8994_DAC1R_TO_HPOUT1R_MASK, WM8994_DAC1R_TO_HPOUT1R);
 
-       /* Routing AIF2 to DAC1 */
-       ret |= wm8994_update_bits(WM8994_DAC1_LEFT_MIXER_ROUTING,
-                       WM8994_AIF2DACL_TO_DAC1L_MASK,
-                       WM8994_AIF2DACL_TO_DAC1L);
-
-       ret |= wm8994_update_bits(WM8994_DAC1_RIGHT_MIXER_ROUTING,
-                       WM8994_AIF2DACR_TO_DAC1R_MASK,
-                       WM8994_AIF2DACR_TO_DAC1R);
-
-        /* GPIO Settings for AIF2 */
-        /* B CLK */
-       ret |= wm8994_update_bits(WM8994_GPIO_3, WM8994_GPIO_DIR_MASK |
-                               WM8994_GPIO_FUNCTION_MASK ,
-                               WM8994_GPIO_DIR_OUTPUT |
-                               WM8994_GPIO_FUNCTION_I2S_CLK);
-
-       /* LR CLK */
-       ret |= wm8994_update_bits(WM8994_GPIO_4, WM8994_GPIO_DIR_MASK |
-                               WM8994_GPIO_FUNCTION_MASK,
-                               WM8994_GPIO_DIR_OUTPUT |
-                               WM8994_GPIO_FUNCTION_I2S_CLK);
-
-       /* DATA */
-       ret |= wm8994_update_bits(WM8994_GPIO_5, WM8994_GPIO_DIR_MASK |
-                               WM8994_GPIO_FUNCTION_MASK,
-                               WM8994_GPIO_DIR_OUTPUT |
-                               WM8994_GPIO_FUNCTION_I2S_CLK);
-
-       ret |= wm8994_init_volume_aif2_dac1();
+       if (aif_id == WM8994_AIF1) {
+               /* Routing AIF1 to DAC1 */
+               ret |= wm8994_i2c_write(WM8994_DAC1_LEFT_MIXER_ROUTING,
+                               WM8994_AIF1DAC1L_TO_DAC1L);
+
+               ret |= wm8994_i2c_write(WM8994_DAC1_RIGHT_MIXER_ROUTING,
+                                       WM8994_AIF1DAC1R_TO_DAC1R);
+
+               /* GPIO Settings for AIF1 */
+               ret |=  wm8994_i2c_write(WM8994_GPIO_1, WM8994_GPIO_DIR_OUTPUT
+                                        | WM8994_GPIO_FUNCTION_I2S_CLK
+                                        | WM8994_GPIO_INPUT_DEBOUNCE);
+
+               ret |= wm8994_init_volume_aif1_dac1();
+       } else if (aif_id == WM8994_AIF2) {
+               /* Routing AIF2 to DAC1 */
+               ret |= wm8994_update_bits(WM8994_DAC1_LEFT_MIXER_ROUTING,
+                               WM8994_AIF2DACL_TO_DAC1L_MASK,
+                               WM8994_AIF2DACL_TO_DAC1L);
+
+               ret |= wm8994_update_bits(WM8994_DAC1_RIGHT_MIXER_ROUTING,
+                               WM8994_AIF2DACR_TO_DAC1R_MASK,
+                               WM8994_AIF2DACR_TO_DAC1R);
+
+               /* GPIO Settings for AIF2 */
+               /* B CLK */
+               ret |= wm8994_update_bits(WM8994_GPIO_3, WM8994_GPIO_DIR_MASK |
+                                       WM8994_GPIO_FUNCTION_MASK ,
+                                       WM8994_GPIO_DIR_OUTPUT);
+
+               /* LR CLK */
+               ret |= wm8994_update_bits(WM8994_GPIO_4, WM8994_GPIO_DIR_MASK |
+                                       WM8994_GPIO_FUNCTION_MASK,
+                                       WM8994_GPIO_DIR_OUTPUT);
+
+               /* DATA */
+               ret |= wm8994_update_bits(WM8994_GPIO_5, WM8994_GPIO_DIR_MASK |
+                                       WM8994_GPIO_FUNCTION_MASK,
+                                       WM8994_GPIO_DIR_OUTPUT);
+
+               ret |= wm8994_init_volume_aif2_dac1();
+       }
+
        if (ret < 0)
                goto err;
 
@@ -747,27 +803,94 @@ err:
        return -1;
 }
 
-/*wm8994 Device Initialisation */
-int wm8994_init(struct sound_codec_info *pcodec_info,
-                       enum en_audio_interface aif_id,
+/*
+ * Gets fdt values for wm8994 config parameters
+ *
+ * @param pcodec_info  codec information structure
+ * @param blob         FDT blob
+ * @return             int value, 0 for success
+ */
+static int get_codec_values(struct sound_codec_info *pcodec_info,
+                       const void *blob)
+{
+       int error = 0;
+#if CONFIG_IS_ENABLED(OF_CONTROL)
+       enum fdt_compat_id compat;
+       int node;
+       int parent;
+
+       /* Get the node from FDT for codec */
+       node = fdtdec_next_compatible(blob, 0, COMPAT_WOLFSON_WM8994_CODEC);
+       if (node <= 0) {
+               debug("EXYNOS_SOUND: No node for codec in device tree\n");
+               debug("node = %d\n", node);
+               return -1;
+       }
+
+       parent = fdt_parent_offset(blob, node);
+       if (parent < 0) {
+               debug("%s: Cannot find node parent\n", __func__);
+               return -1;
+       }
+
+       compat = fdtdec_lookup(blob, parent);
+       switch (compat) {
+       case COMPAT_SAMSUNG_S3C2440_I2C:
+               pcodec_info->i2c_bus = i2c_get_bus_num_fdt(parent);
+               error |= pcodec_info->i2c_bus;
+               debug("i2c bus = %d\n", pcodec_info->i2c_bus);
+               pcodec_info->i2c_dev_addr = fdtdec_get_int(blob, node,
+                                                       "reg", 0);
+               error |= pcodec_info->i2c_dev_addr;
+               debug("i2c dev addr = %d\n", pcodec_info->i2c_dev_addr);
+               break;
+       default:
+               debug("%s: Unknown compat id %d\n", __func__, compat);
+               return -1;
+       }
+#else
+       pcodec_info->i2c_bus = AUDIO_I2C_BUS;
+       pcodec_info->i2c_dev_addr = AUDIO_I2C_REG;
+       debug("i2c dev addr = %d\n", pcodec_info->i2c_dev_addr);
+#endif
+
+       pcodec_info->codec_type = CODEC_WM_8994;
+
+       if (error == -1) {
+               debug("fail to get wm8994 codec node properties\n");
+               return -1;
+       }
+
+       return 0;
+}
+
+/* WM8994 Device Initialisation */
+int wm8994_init(const void *blob, enum en_audio_interface aif_id,
                        int sampling_rate, int mclk_freq,
                        int bits_per_sample, unsigned int channels)
 {
        int ret = 0;
+       struct sound_codec_info *pcodec_info = &g_codec_info;
+
+       /* Get the codec Values */
+       if (get_codec_values(pcodec_info, blob) < 0) {
+               debug("FDT Codec values failed\n");
+               return -1;
+       }
 
        /* shift the device address by 1 for 7 bit addressing */
        g_wm8994_i2c_dev_addr = pcodec_info->i2c_dev_addr;
        wm8994_i2c_init(pcodec_info->i2c_bus);
 
-       if (pcodec_info->codec_type == CODEC_WM_8994)
+       if (pcodec_info->codec_type == CODEC_WM_8994) {
                g_wm8994_info.type = WM8994;
-       else {
+       else {
                debug("%s: Codec id [%d] not defined\n", __func__,
-                               pcodec_info->codec_type);
+                     pcodec_info->codec_type);
                return -1;
        }
 
-       ret = wm8994_device_init(&g_wm8994_info);
+       ret = wm8994_device_init(&g_wm8994_info, aif_id);
        if (ret < 0) {
                debug("%s: wm8994 codec chip init failed\n", __func__);
                return ret;