2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2012-10-25 19:49:23 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 Samsung Electronics
|
|
|
|
* R. Chandrasekar <rcsekar@samsung.com>
|
|
|
|
*/
|
2017-05-31 03:47:09 +00:00
|
|
|
#include <common.h>
|
2018-12-10 17:37:39 +00:00
|
|
|
#include <audio_codec.h>
|
|
|
|
#include <dm.h>
|
2012-10-25 19:49:23 +00:00
|
|
|
#include <div64.h>
|
2012-12-26 20:03:18 +00:00
|
|
|
#include <fdtdec.h>
|
2012-10-25 19:49:23 +00:00
|
|
|
#include <i2c.h>
|
|
|
|
#include <i2s.h>
|
|
|
|
#include <sound.h>
|
2018-12-03 11:37:34 +00:00
|
|
|
#include <asm/gpio.h>
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/arch/clk.h>
|
|
|
|
#include <asm/arch/cpu.h>
|
2012-12-26 20:03:18 +00:00
|
|
|
#include <asm/arch/sound.h>
|
2012-10-25 19:49:23 +00:00
|
|
|
#include "wm8994.h"
|
|
|
|
#include "wm8994_registers.h"
|
|
|
|
|
|
|
|
/* defines for wm8994 system clock selection */
|
|
|
|
#define SEL_MCLK1 0x00
|
|
|
|
#define SEL_MCLK2 0x08
|
|
|
|
#define SEL_FLL1 0x10
|
|
|
|
#define SEL_FLL2 0x18
|
|
|
|
|
|
|
|
/* fll config to configure fll */
|
|
|
|
struct wm8994_fll_config {
|
|
|
|
int src; /* Source */
|
|
|
|
int in; /* Input frequency in Hz */
|
|
|
|
int out; /* output frequency in Hz */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* codec private data */
|
|
|
|
struct wm8994_priv {
|
|
|
|
enum wm8994_type type; /* codec type of wolfson */
|
|
|
|
int revision; /* Revision */
|
|
|
|
int sysclk[WM8994_MAX_AIF]; /* System clock frequency in Hz */
|
|
|
|
int mclk[WM8994_MAX_AIF]; /* master clock frequency in Hz */
|
|
|
|
int aifclk[WM8994_MAX_AIF]; /* audio interface clock in Hz */
|
|
|
|
struct wm8994_fll_config fll[2]; /* fll config to configure fll */
|
2018-12-10 17:37:39 +00:00
|
|
|
struct udevice *dev;
|
2012-10-25 19:49:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* wm 8994 supported sampling rate values */
|
|
|
|
static unsigned int src_rate[] = {
|
|
|
|
8000, 11025, 12000, 16000, 22050, 24000,
|
|
|
|
32000, 44100, 48000, 88200, 96000
|
|
|
|
};
|
|
|
|
|
|
|
|
/* op clock divisions */
|
|
|
|
static int opclk_divs[] = { 10, 20, 30, 40, 55, 60, 80, 120, 160 };
|
|
|
|
|
|
|
|
/* lr clock frame size ratio */
|
|
|
|
static int fs_ratios[] = {
|
|
|
|
64, 128, 192, 256, 348, 512, 768, 1024, 1408, 1536
|
|
|
|
};
|
|
|
|
|
|
|
|
/* bit clock divisors */
|
|
|
|
static int bclk_divs[] = {
|
|
|
|
10, 15, 20, 30, 40, 50, 60, 80, 110, 120, 160, 220, 240, 320, 440, 480,
|
|
|
|
640, 880, 960, 1280, 1760, 1920
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Writes value to a device register through i2c
|
|
|
|
*
|
2018-12-03 11:37:24 +00:00
|
|
|
* @param priv Private data for driver
|
2012-10-25 19:49:23 +00:00
|
|
|
* @param reg reg number to be write
|
|
|
|
* @param data data to be writen to the above registor
|
|
|
|
*
|
|
|
|
* @return int value 1 for change, 0 for no change or negative error code.
|
|
|
|
*/
|
2018-12-03 11:37:24 +00:00
|
|
|
static int wm8994_i2c_write(struct wm8994_priv *priv, unsigned int reg,
|
|
|
|
unsigned short data)
|
2012-10-25 19:49:23 +00:00
|
|
|
{
|
|
|
|
unsigned char val[2];
|
|
|
|
|
|
|
|
val[0] = (unsigned char)((data >> 8) & 0xff);
|
|
|
|
val[1] = (unsigned char)(data & 0xff);
|
|
|
|
debug("Write Addr : 0x%04X, Data : 0x%04X\n", reg, data);
|
|
|
|
|
2018-12-10 17:37:39 +00:00
|
|
|
return dm_i2c_write(priv->dev, reg, val, 2);
|
2012-10-25 19:49:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read a value from a device register through i2c
|
|
|
|
*
|
2018-12-03 11:37:24 +00:00
|
|
|
* @param priv Private data for driver
|
2012-10-25 19:49:23 +00:00
|
|
|
* @param reg reg number to be read
|
|
|
|
* @param data address of read data to be stored
|
|
|
|
*
|
|
|
|
* @return int value 0 for success, -1 in case of error.
|
|
|
|
*/
|
2018-12-03 11:37:24 +00:00
|
|
|
static unsigned int wm8994_i2c_read(struct wm8994_priv *priv, unsigned int reg,
|
|
|
|
unsigned short *data)
|
2012-10-25 19:49:23 +00:00
|
|
|
{
|
|
|
|
unsigned char val[2];
|
|
|
|
int ret;
|
|
|
|
|
2018-12-10 17:37:39 +00:00
|
|
|
ret = dm_i2c_read(priv->dev, reg, val, 1);
|
2012-10-25 19:49:23 +00:00
|
|
|
if (ret != 0) {
|
|
|
|
debug("%s: Error while reading register %#04x\n",
|
|
|
|
__func__, reg);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*data = val[0];
|
|
|
|
*data <<= 8;
|
|
|
|
*data |= val[1];
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* update device register bits through i2c
|
|
|
|
*
|
2018-12-03 11:37:24 +00:00
|
|
|
* @param priv Private data for driver
|
2012-10-25 19:49:23 +00:00
|
|
|
* @param reg codec register
|
|
|
|
* @param mask register mask
|
|
|
|
* @param value new value
|
|
|
|
*
|
|
|
|
* @return int value 1 if change in the register value,
|
|
|
|
* 0 for no change or negative error code.
|
|
|
|
*/
|
2018-12-03 11:37:24 +00:00
|
|
|
static int wm8994_bic_or(struct wm8994_priv *priv, unsigned int reg,
|
|
|
|
unsigned short mask, unsigned short value)
|
2012-10-25 19:49:23 +00:00
|
|
|
{
|
|
|
|
int change , ret = 0;
|
|
|
|
unsigned short old, new;
|
|
|
|
|
2018-12-03 11:37:24 +00:00
|
|
|
if (wm8994_i2c_read(priv, reg, &old) != 0)
|
2012-10-25 19:49:23 +00:00
|
|
|
return -1;
|
|
|
|
new = (old & ~mask) | (value & mask);
|
|
|
|
change = (old != new) ? 1 : 0;
|
|
|
|
if (change)
|
2018-12-03 11:37:24 +00:00
|
|
|
ret = wm8994_i2c_write(priv, reg, new);
|
2012-10-25 19:49:23 +00:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return change;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sets i2s set format
|
|
|
|
*
|
2018-12-03 11:37:24 +00:00
|
|
|
* @param priv wm8994 information
|
2012-10-25 19:49:23 +00:00
|
|
|
* @param aif_id Interface ID
|
|
|
|
* @param fmt i2S format
|
|
|
|
*
|
|
|
|
* @return -1 for error and 0 Success.
|
|
|
|
*/
|
2018-12-03 11:37:24 +00:00
|
|
|
static int wm8994_set_fmt(struct wm8994_priv *priv, int aif_id, uint fmt)
|
2012-10-25 19:49:23 +00:00
|
|
|
{
|
|
|
|
int ms_reg;
|
|
|
|
int aif_reg;
|
|
|
|
int ms = 0;
|
|
|
|
int aif = 0;
|
|
|
|
int aif_clk = 0;
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
switch (aif_id) {
|
|
|
|
case 1:
|
|
|
|
ms_reg = WM8994_AIF1_MASTER_SLAVE;
|
|
|
|
aif_reg = WM8994_AIF1_CONTROL_1;
|
|
|
|
aif_clk = WM8994_AIF1_CLOCKING_1;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
ms_reg = WM8994_AIF2_MASTER_SLAVE;
|
|
|
|
aif_reg = WM8994_AIF2_CONTROL_1;
|
|
|
|
aif_clk = WM8994_AIF2_CLOCKING_1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
debug("%s: Invalid audio interface selection\n", __func__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
|
|
|
|
case SND_SOC_DAIFMT_CBS_CFS:
|
|
|
|
break;
|
|
|
|
case SND_SOC_DAIFMT_CBM_CFM:
|
|
|
|
ms = WM8994_AIF1_MSTR;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
debug("%s: Invalid i2s master selection\n", __func__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
|
|
|
|
case SND_SOC_DAIFMT_DSP_B:
|
|
|
|
aif |= WM8994_AIF1_LRCLK_INV;
|
|
|
|
case SND_SOC_DAIFMT_DSP_A:
|
|
|
|
aif |= 0x18;
|
|
|
|
break;
|
|
|
|
case SND_SOC_DAIFMT_I2S:
|
|
|
|
aif |= 0x10;
|
|
|
|
break;
|
|
|
|
case SND_SOC_DAIFMT_RIGHT_J:
|
|
|
|
break;
|
|
|
|
case SND_SOC_DAIFMT_LEFT_J:
|
|
|
|
aif |= 0x8;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
debug("%s: Invalid i2s format selection\n", __func__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
|
|
|
|
case SND_SOC_DAIFMT_DSP_A:
|
|
|
|
case SND_SOC_DAIFMT_DSP_B:
|
|
|
|
/* frame inversion not valid for DSP modes */
|
|
|
|
switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
|
|
|
|
case SND_SOC_DAIFMT_NB_NF:
|
|
|
|
break;
|
|
|
|
case SND_SOC_DAIFMT_IB_NF:
|
|
|
|
aif |= WM8994_AIF1_BCLK_INV;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
debug("%s: Invalid i2s frame inverse selection\n",
|
|
|
|
__func__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SND_SOC_DAIFMT_I2S:
|
|
|
|
case SND_SOC_DAIFMT_RIGHT_J:
|
|
|
|
case SND_SOC_DAIFMT_LEFT_J:
|
|
|
|
switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
|
|
|
|
case SND_SOC_DAIFMT_NB_NF:
|
|
|
|
break;
|
|
|
|
case SND_SOC_DAIFMT_IB_IF:
|
|
|
|
aif |= WM8994_AIF1_BCLK_INV | WM8994_AIF1_LRCLK_INV;
|
|
|
|
break;
|
|
|
|
case SND_SOC_DAIFMT_IB_NF:
|
|
|
|
aif |= WM8994_AIF1_BCLK_INV;
|
|
|
|
break;
|
|
|
|
case SND_SOC_DAIFMT_NB_IF:
|
|
|
|
aif |= WM8994_AIF1_LRCLK_INV;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
debug("%s: Invalid i2s clock polarity selection\n",
|
|
|
|
__func__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
debug("%s: Invalid i2s format selection\n", __func__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-12-03 11:37:24 +00:00
|
|
|
error = wm8994_bic_or(priv, aif_reg, WM8994_AIF1_BCLK_INV |
|
|
|
|
WM8994_AIF1_LRCLK_INV_MASK |
|
|
|
|
WM8994_AIF1_FMT_MASK, aif);
|
2012-10-25 19:49:23 +00:00
|
|
|
|
2018-12-03 11:37:24 +00:00
|
|
|
error |= wm8994_bic_or(priv, ms_reg, WM8994_AIF1_MSTR_MASK, ms);
|
|
|
|
error |= wm8994_bic_or(priv, aif_clk, WM8994_AIF1CLK_ENA_MASK,
|
|
|
|
WM8994_AIF1CLK_ENA);
|
2012-10-25 19:49:23 +00:00
|
|
|
if (error < 0) {
|
|
|
|
debug("%s: codec register access error\n", __func__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sets hw params FOR WM8994
|
|
|
|
*
|
2018-12-03 11:37:24 +00:00
|
|
|
* @param priv wm8994 information pointer
|
2012-10-25 19:49:23 +00:00
|
|
|
* @param aif_id Audio interface ID
|
|
|
|
* @param sampling_rate Sampling rate
|
|
|
|
* @param bits_per_sample Bits per sample
|
|
|
|
* @param Channels Channels in the given audio input
|
|
|
|
*
|
|
|
|
* @return -1 for error and 0 Success.
|
|
|
|
*/
|
2018-12-03 11:37:24 +00:00
|
|
|
static int wm8994_hw_params(struct wm8994_priv *priv, int aif_id,
|
|
|
|
uint sampling_rate, uint bits_per_sample,
|
|
|
|
uint channels)
|
2012-10-25 19:49:23 +00:00
|
|
|
{
|
|
|
|
int aif1_reg;
|
|
|
|
int aif2_reg;
|
|
|
|
int bclk_reg;
|
|
|
|
int bclk = 0;
|
|
|
|
int rate_reg;
|
|
|
|
int aif1 = 0;
|
|
|
|
int aif2 = 0;
|
|
|
|
int rate_val = 0;
|
|
|
|
int id = aif_id - 1;
|
|
|
|
int i, cur_val, best_val, bclk_rate, best;
|
|
|
|
unsigned short reg_data;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
switch (aif_id) {
|
|
|
|
case 1:
|
|
|
|
aif1_reg = WM8994_AIF1_CONTROL_1;
|
|
|
|
aif2_reg = WM8994_AIF1_CONTROL_2;
|
|
|
|
bclk_reg = WM8994_AIF1_BCLK;
|
|
|
|
rate_reg = WM8994_AIF1_RATE;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
aif1_reg = WM8994_AIF2_CONTROL_1;
|
|
|
|
aif2_reg = WM8994_AIF2_CONTROL_2;
|
|
|
|
bclk_reg = WM8994_AIF2_BCLK;
|
|
|
|
rate_reg = WM8994_AIF2_RATE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bclk_rate = sampling_rate * 32;
|
|
|
|
switch (bits_per_sample) {
|
|
|
|
case 16:
|
|
|
|
bclk_rate *= 16;
|
|
|
|
break;
|
|
|
|
case 20:
|
|
|
|
bclk_rate *= 20;
|
|
|
|
aif1 |= 0x20;
|
|
|
|
break;
|
|
|
|
case 24:
|
|
|
|
bclk_rate *= 24;
|
|
|
|
aif1 |= 0x40;
|
|
|
|
break;
|
|
|
|
case 32:
|
|
|
|
bclk_rate *= 32;
|
|
|
|
aif1 |= 0x60;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Try to find an appropriate sample rate; look for an exact match. */
|
|
|
|
for (i = 0; i < ARRAY_SIZE(src_rate); i++)
|
|
|
|
if (src_rate[i] == sampling_rate)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (i == ARRAY_SIZE(src_rate)) {
|
|
|
|
debug("%s: Could not get the best matching samplingrate\n",
|
|
|
|
__func__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
rate_val |= i << WM8994_AIF1_SR_SHIFT;
|
|
|
|
|
|
|
|
/* AIFCLK/fs ratio; look for a close match in either direction */
|
|
|
|
best = 0;
|
2018-12-03 11:37:24 +00:00
|
|
|
best_val = abs((fs_ratios[0] * sampling_rate) - priv->aifclk[id]);
|
2012-10-25 19:49:23 +00:00
|
|
|
|
|
|
|
for (i = 1; i < ARRAY_SIZE(fs_ratios); i++) {
|
2018-12-03 11:37:24 +00:00
|
|
|
cur_val = abs(fs_ratios[i] * sampling_rate - priv->aifclk[id]);
|
2012-10-25 19:49:23 +00:00
|
|
|
if (cur_val >= best_val)
|
|
|
|
continue;
|
|
|
|
best = i;
|
|
|
|
best_val = cur_val;
|
|
|
|
}
|
|
|
|
|
|
|
|
rate_val |= best;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We may not get quite the right frequency if using
|
|
|
|
* approximate clocks so look for the closest match that is
|
|
|
|
* higher than the target (we need to ensure that there enough
|
|
|
|
* BCLKs to clock out the samples).
|
|
|
|
*/
|
|
|
|
best = 0;
|
|
|
|
for (i = 0; i < ARRAY_SIZE(bclk_divs); i++) {
|
2018-12-03 11:37:24 +00:00
|
|
|
cur_val = (priv->aifclk[id] * 10 / bclk_divs[i]) - bclk_rate;
|
2012-10-25 19:49:23 +00:00
|
|
|
if (cur_val < 0) /* BCLK table is sorted */
|
|
|
|
break;
|
|
|
|
best = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == ARRAY_SIZE(bclk_divs)) {
|
|
|
|
debug("%s: Could not get the best matching bclk division\n",
|
|
|
|
__func__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-12-03 11:37:24 +00:00
|
|
|
bclk_rate = priv->aifclk[id] * 10 / bclk_divs[best];
|
2012-10-25 19:49:23 +00:00
|
|
|
bclk |= best << WM8994_AIF1_BCLK_DIV_SHIFT;
|
|
|
|
|
2018-12-03 11:37:24 +00:00
|
|
|
if (wm8994_i2c_read(priv, aif1_reg, ®_data) != 0) {
|
2012-10-25 19:49:23 +00:00
|
|
|
debug("%s: AIF1 register read Failed\n", __func__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((channels == 1) && ((reg_data & 0x18) == 0x18))
|
|
|
|
aif2 |= WM8994_AIF1_MONO;
|
|
|
|
|
2018-12-03 11:37:24 +00:00
|
|
|
if (priv->aifclk[id] == 0) {
|
2012-10-25 19:49:23 +00:00
|
|
|
debug("%s:Audio interface clock not set\n", __func__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-12-03 11:37:24 +00:00
|
|
|
ret = wm8994_bic_or(priv, aif1_reg, WM8994_AIF1_WL_MASK, aif1);
|
|
|
|
ret |= wm8994_bic_or(priv, aif2_reg, WM8994_AIF1_MONO, aif2);
|
|
|
|
ret |= wm8994_bic_or(priv, bclk_reg, WM8994_AIF1_BCLK_DIV_MASK,
|
|
|
|
bclk);
|
|
|
|
ret |= wm8994_bic_or(priv, rate_reg, WM8994_AIF1_SR_MASK |
|
|
|
|
WM8994_AIF1CLK_RATE_MASK, rate_val);
|
2012-10-25 19:49:23 +00:00
|
|
|
|
|
|
|
debug("rate vale = %x , bclk val= %x\n", rate_val, bclk);
|
|
|
|
|
|
|
|
if (ret < 0) {
|
|
|
|
debug("%s: codec register access error\n", __func__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Configures Audio interface Clock
|
|
|
|
*
|
2018-12-03 11:37:24 +00:00
|
|
|
* @param priv wm8994 information pointer
|
2012-10-25 19:49:23 +00:00
|
|
|
* @param aif Audio Interface ID
|
|
|
|
*
|
|
|
|
* @return -1 for error and 0 Success.
|
|
|
|
*/
|
2018-12-03 11:37:24 +00:00
|
|
|
static int configure_aif_clock(struct wm8994_priv *priv, int aif)
|
2012-10-25 19:49:23 +00:00
|
|
|
{
|
|
|
|
int rate;
|
|
|
|
int reg1 = 0;
|
|
|
|
int offset;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* AIF(1/0) register adress offset calculated */
|
2013-09-11 11:08:46 +00:00
|
|
|
if (aif-1)
|
2012-10-25 19:49:23 +00:00
|
|
|
offset = 4;
|
|
|
|
else
|
|
|
|
offset = 0;
|
|
|
|
|
2018-12-03 11:37:24 +00:00
|
|
|
switch (priv->sysclk[aif - 1]) {
|
2012-10-25 19:49:23 +00:00
|
|
|
case WM8994_SYSCLK_MCLK1:
|
|
|
|
reg1 |= SEL_MCLK1;
|
2018-12-03 11:37:24 +00:00
|
|
|
rate = priv->mclk[0];
|
2012-10-25 19:49:23 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WM8994_SYSCLK_MCLK2:
|
|
|
|
reg1 |= SEL_MCLK2;
|
2018-12-03 11:37:24 +00:00
|
|
|
rate = priv->mclk[1];
|
2012-10-25 19:49:23 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WM8994_SYSCLK_FLL1:
|
|
|
|
reg1 |= SEL_FLL1;
|
2018-12-03 11:37:24 +00:00
|
|
|
rate = priv->fll[0].out;
|
2012-10-25 19:49:23 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WM8994_SYSCLK_FLL2:
|
|
|
|
reg1 |= SEL_FLL2;
|
2018-12-03 11:37:24 +00:00
|
|
|
rate = priv->fll[1].out;
|
2012-10-25 19:49:23 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
debug("%s: Invalid input clock selection [%d]\n",
|
2018-12-03 11:37:24 +00:00
|
|
|
__func__, priv->sysclk[aif - 1]);
|
2012-10-25 19:49:23 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if input clock frequenct is more than 135Mhz then divide */
|
|
|
|
if (rate >= WM8994_MAX_INPUT_CLK_FREQ) {
|
|
|
|
rate /= 2;
|
|
|
|
reg1 |= WM8994_AIF1CLK_DIV;
|
|
|
|
}
|
|
|
|
|
2018-12-03 11:37:24 +00:00
|
|
|
priv->aifclk[aif - 1] = rate;
|
2012-10-25 19:49:23 +00:00
|
|
|
|
2018-12-03 11:37:24 +00:00
|
|
|
ret = wm8994_bic_or(priv, WM8994_AIF1_CLOCKING_1 + offset,
|
|
|
|
WM8994_AIF1CLK_SRC_MASK | WM8994_AIF1CLK_DIV,
|
|
|
|
reg1);
|
2012-10-25 19:49:23 +00:00
|
|
|
|
2013-09-11 11:08:46 +00:00
|
|
|
if (aif == WM8994_AIF1)
|
2018-12-03 11:37:24 +00:00
|
|
|
ret |= wm8994_bic_or(priv, WM8994_CLOCKING_1,
|
2013-09-11 11:08:46 +00:00
|
|
|
WM8994_AIF1DSPCLK_ENA_MASK | WM8994_SYSDSPCLK_ENA_MASK,
|
|
|
|
WM8994_AIF1DSPCLK_ENA | WM8994_SYSDSPCLK_ENA);
|
|
|
|
else if (aif == WM8994_AIF2)
|
2018-12-03 11:37:24 +00:00
|
|
|
ret |= wm8994_bic_or(priv, WM8994_CLOCKING_1,
|
2012-10-25 19:49:23 +00:00
|
|
|
WM8994_SYSCLK_SRC | WM8994_AIF2DSPCLK_ENA_MASK |
|
|
|
|
WM8994_SYSDSPCLK_ENA_MASK, WM8994_SYSCLK_SRC |
|
|
|
|
WM8994_AIF2DSPCLK_ENA | WM8994_SYSDSPCLK_ENA);
|
|
|
|
|
|
|
|
if (ret < 0) {
|
|
|
|
debug("%s: codec register access error\n", __func__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Configures Audio interface for the given frequency
|
|
|
|
*
|
2018-12-03 11:37:24 +00:00
|
|
|
* @param priv wm8994 information
|
2012-10-25 19:49:23 +00:00
|
|
|
* @param aif_id Audio Interface
|
|
|
|
* @param clk_id Input Clock ID
|
|
|
|
* @param freq Sampling frequency in Hz
|
|
|
|
*
|
|
|
|
* @return -1 for error and 0 success.
|
|
|
|
*/
|
2018-12-03 11:37:24 +00:00
|
|
|
static int wm8994_set_sysclk(struct wm8994_priv *priv, int aif_id, int clk_id,
|
|
|
|
unsigned int freq)
|
2012-10-25 19:49:23 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int ret = 0;
|
|
|
|
|
2018-12-03 11:37:24 +00:00
|
|
|
priv->sysclk[aif_id - 1] = clk_id;
|
2012-10-25 19:49:23 +00:00
|
|
|
|
|
|
|
switch (clk_id) {
|
|
|
|
case WM8994_SYSCLK_MCLK1:
|
2018-12-03 11:37:24 +00:00
|
|
|
priv->mclk[0] = freq;
|
2012-10-25 19:49:23 +00:00
|
|
|
if (aif_id == 2) {
|
2018-12-03 11:37:24 +00:00
|
|
|
ret = wm8994_bic_or(priv, WM8994_AIF1_CLOCKING_2,
|
|
|
|
WM8994_AIF2DAC_DIV_MASK, 0);
|
2012-10-25 19:49:23 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM8994_SYSCLK_MCLK2:
|
|
|
|
/* TODO: Set GPIO AF */
|
2018-12-03 11:37:24 +00:00
|
|
|
priv->mclk[1] = freq;
|
2012-10-25 19:49:23 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WM8994_SYSCLK_FLL1:
|
|
|
|
case WM8994_SYSCLK_FLL2:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM8994_SYSCLK_OPCLK:
|
|
|
|
/*
|
|
|
|
* Special case - a division (times 10) is given and
|
|
|
|
* no effect on main clocking.
|
|
|
|
*/
|
|
|
|
if (freq) {
|
|
|
|
for (i = 0; i < ARRAY_SIZE(opclk_divs); i++)
|
|
|
|
if (opclk_divs[i] == freq)
|
|
|
|
break;
|
|
|
|
if (i == ARRAY_SIZE(opclk_divs)) {
|
|
|
|
debug("%s frequency divisor not found\n",
|
2013-09-11 11:08:46 +00:00
|
|
|
__func__);
|
2012-10-25 19:49:23 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2018-12-03 11:37:24 +00:00
|
|
|
ret = wm8994_bic_or(priv, WM8994_CLOCKING_2,
|
2012-10-25 19:49:23 +00:00
|
|
|
WM8994_OPCLK_DIV_MASK, i);
|
2018-12-03 11:37:24 +00:00
|
|
|
ret |= wm8994_bic_or(priv, WM8994_POWER_MANAGEMENT_2,
|
|
|
|
WM8994_OPCLK_ENA,
|
|
|
|
WM8994_OPCLK_ENA);
|
2012-10-25 19:49:23 +00:00
|
|
|
} else {
|
2018-12-03 11:37:24 +00:00
|
|
|
ret |= wm8994_bic_or(priv, WM8994_POWER_MANAGEMENT_2,
|
|
|
|
WM8994_OPCLK_ENA, 0);
|
2012-10-25 19:49:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
debug("%s Invalid input clock selection [%d]\n",
|
|
|
|
__func__, clk_id);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-12-03 11:37:24 +00:00
|
|
|
ret |= configure_aif_clock(priv, aif_id);
|
2012-10-25 19:49:23 +00:00
|
|
|
|
|
|
|
if (ret < 0) {
|
|
|
|
debug("%s: codec register access error\n", __func__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initializes Volume for AIF2 to HP path
|
|
|
|
*
|
2018-12-03 11:37:24 +00:00
|
|
|
* @param priv wm8994 information
|
2012-10-25 19:49:23 +00:00
|
|
|
* @returns -1 for error and 0 Success.
|
|
|
|
*
|
|
|
|
*/
|
2018-12-03 11:37:24 +00:00
|
|
|
static int wm8994_init_volume_aif2_dac1(struct wm8994_priv *priv)
|
2012-10-25 19:49:23 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Unmute AIF2DAC */
|
2018-12-03 11:37:24 +00:00
|
|
|
ret = wm8994_bic_or(priv, WM8994_AIF2_DAC_FILTERS_1,
|
|
|
|
WM8994_AIF2DAC_MUTE_MASK, 0);
|
2012-10-25 19:49:23 +00:00
|
|
|
|
|
|
|
|
2018-12-03 11:37:24 +00:00
|
|
|
ret |= wm8994_bic_or(priv, WM8994_AIF2_DAC_LEFT_VOLUME,
|
|
|
|
WM8994_AIF2DAC_VU_MASK | WM8994_AIF2DACL_VOL_MASK,
|
|
|
|
WM8994_AIF2DAC_VU | 0xff);
|
2012-10-25 19:49:23 +00:00
|
|
|
|
2018-12-03 11:37:24 +00:00
|
|
|
ret |= wm8994_bic_or(priv, WM8994_AIF2_DAC_RIGHT_VOLUME,
|
|
|
|
WM8994_AIF2DAC_VU_MASK | WM8994_AIF2DACR_VOL_MASK,
|
|
|
|
WM8994_AIF2DAC_VU | 0xff);
|
2012-10-25 19:49:23 +00:00
|
|
|
|
|
|
|
|
2018-12-03 11:37:24 +00:00
|
|
|
ret |= wm8994_bic_or(priv, WM8994_DAC1_LEFT_VOLUME,
|
|
|
|
WM8994_DAC1_VU_MASK | WM8994_DAC1L_VOL_MASK |
|
|
|
|
WM8994_DAC1L_MUTE_MASK, WM8994_DAC1_VU | 0xc0);
|
2012-10-25 19:49:23 +00:00
|
|
|
|
2018-12-03 11:37:24 +00:00
|
|
|
ret |= wm8994_bic_or(priv, WM8994_DAC1_RIGHT_VOLUME,
|
|
|
|
WM8994_DAC1_VU_MASK | WM8994_DAC1R_VOL_MASK |
|
|
|
|
WM8994_DAC1R_MUTE_MASK, WM8994_DAC1_VU | 0xc0);
|
2012-10-25 19:49:23 +00:00
|
|
|
/* Head Phone Volume */
|
2018-12-03 11:37:24 +00:00
|
|
|
ret |= wm8994_i2c_write(priv, WM8994_LEFT_OUTPUT_VOLUME, 0x12D);
|
|
|
|
ret |= wm8994_i2c_write(priv, WM8994_RIGHT_OUTPUT_VOLUME, 0x12D);
|
2012-10-25 19:49:23 +00:00
|
|
|
|
|
|
|
if (ret < 0) {
|
|
|
|
debug("%s: codec register access error\n", __func__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-09-11 11:08:46 +00:00
|
|
|
/*
|
|
|
|
* Initializes Volume for AIF1 to HP path
|
|
|
|
*
|
2018-12-03 11:37:24 +00:00
|
|
|
* @param priv wm8994 information
|
2013-09-11 11:08:46 +00:00
|
|
|
* @returns -1 for error and 0 Success.
|
|
|
|
*
|
|
|
|
*/
|
2018-12-03 11:37:24 +00:00
|
|
|
static int wm8994_init_volume_aif1_dac1(struct wm8994_priv *priv)
|
2013-09-11 11:08:46 +00:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
/* Unmute AIF1DAC */
|
2018-12-03 11:37:24 +00:00
|
|
|
ret |= wm8994_i2c_write(priv, WM8994_AIF1_DAC_FILTERS_1, 0x0000);
|
2013-09-11 11:08:46 +00:00
|
|
|
|
2018-12-03 11:37:24 +00:00
|
|
|
ret |= wm8994_bic_or(priv, WM8994_DAC1_LEFT_VOLUME,
|
|
|
|
WM8994_DAC1_VU_MASK | WM8994_DAC1L_VOL_MASK |
|
|
|
|
WM8994_DAC1L_MUTE_MASK, WM8994_DAC1_VU | 0xc0);
|
2013-09-11 11:08:46 +00:00
|
|
|
|
2018-12-03 11:37:24 +00:00
|
|
|
ret |= wm8994_bic_or(priv, WM8994_DAC1_RIGHT_VOLUME,
|
|
|
|
WM8994_DAC1_VU_MASK | WM8994_DAC1R_VOL_MASK |
|
|
|
|
WM8994_DAC1R_MUTE_MASK, WM8994_DAC1_VU | 0xc0);
|
2013-09-11 11:08:46 +00:00
|
|
|
/* Head Phone Volume */
|
2018-12-03 11:37:24 +00:00
|
|
|
ret |= wm8994_i2c_write(priv, WM8994_LEFT_OUTPUT_VOLUME, 0x12D);
|
|
|
|
ret |= wm8994_i2c_write(priv, WM8994_RIGHT_OUTPUT_VOLUME, 0x12D);
|
2013-09-11 11:08:46 +00:00
|
|
|
|
|
|
|
if (ret < 0) {
|
|
|
|
debug("%s: codec register access error\n", __func__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-25 19:49:23 +00:00
|
|
|
/*
|
|
|
|
* Intialise wm8994 codec device
|
|
|
|
*
|
2018-12-03 11:37:24 +00:00
|
|
|
* @param priv wm8994 information
|
2012-10-25 19:49:23 +00:00
|
|
|
*
|
|
|
|
* @returns -1 for error and 0 Success.
|
|
|
|
*/
|
2018-12-03 11:37:27 +00:00
|
|
|
static int wm8994_device_init(struct wm8994_priv *priv)
|
2012-10-25 19:49:23 +00:00
|
|
|
{
|
|
|
|
const char *devname;
|
|
|
|
unsigned short reg_data;
|
|
|
|
int ret;
|
|
|
|
|
2018-12-03 11:37:24 +00:00
|
|
|
wm8994_i2c_write(priv, WM8994_SOFTWARE_RESET, WM8994_SW_RESET);
|
2012-10-25 19:49:23 +00:00
|
|
|
|
2018-12-03 11:37:24 +00:00
|
|
|
ret = wm8994_i2c_read(priv, WM8994_SOFTWARE_RESET, ®_data);
|
2012-10-25 19:49:23 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
debug("Failed to read ID register\n");
|
2018-12-03 11:37:27 +00:00
|
|
|
return ret;
|
2012-10-25 19:49:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (reg_data == WM8994_ID) {
|
|
|
|
devname = "WM8994";
|
2018-12-03 11:37:24 +00:00
|
|
|
debug("Device registered as type %d\n", priv->type);
|
|
|
|
priv->type = WM8994;
|
2012-10-25 19:49:23 +00:00
|
|
|
} else {
|
|
|
|
debug("Device is not a WM8994, ID is %x\n", ret);
|
2018-12-03 11:37:27 +00:00
|
|
|
return -ENXIO;
|
2012-10-25 19:49:23 +00:00
|
|
|
}
|
|
|
|
|
2018-12-03 11:37:24 +00:00
|
|
|
ret = wm8994_i2c_read(priv, WM8994_CHIP_REVISION, ®_data);
|
2012-10-25 19:49:23 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
debug("Failed to read revision register: %d\n", ret);
|
2018-12-03 11:37:27 +00:00
|
|
|
return ret;
|
2012-10-25 19:49:23 +00:00
|
|
|
}
|
2018-12-03 11:37:24 +00:00
|
|
|
priv->revision = reg_data;
|
|
|
|
debug("%s revision %c\n", devname, 'A' + priv->revision);
|
2012-10-25 19:49:23 +00:00
|
|
|
|
2018-12-03 11:37:27 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int wm8994_setup_interface(struct wm8994_priv *priv,
|
|
|
|
enum en_audio_interface aif_id)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2012-10-25 19:49:23 +00:00
|
|
|
/* VMID Selection */
|
2018-12-03 11:37:27 +00:00
|
|
|
ret = wm8994_bic_or(priv, WM8994_POWER_MANAGEMENT_1,
|
|
|
|
WM8994_VMID_SEL_MASK | WM8994_BIAS_ENA_MASK, 0x3);
|
2012-10-25 19:49:23 +00:00
|
|
|
|
|
|
|
/* Charge Pump Enable */
|
2018-12-03 11:37:24 +00:00
|
|
|
ret |= wm8994_bic_or(priv, WM8994_CHARGE_PUMP_1, WM8994_CP_ENA_MASK,
|
|
|
|
WM8994_CP_ENA);
|
2012-10-25 19:49:23 +00:00
|
|
|
|
|
|
|
/* Head Phone Power Enable */
|
2018-12-03 11:37:24 +00:00
|
|
|
ret |= wm8994_bic_or(priv, WM8994_POWER_MANAGEMENT_1,
|
|
|
|
WM8994_HPOUT1L_ENA_MASK, WM8994_HPOUT1L_ENA);
|
2012-10-25 19:49:23 +00:00
|
|
|
|
2018-12-03 11:37:24 +00:00
|
|
|
ret |= wm8994_bic_or(priv, WM8994_POWER_MANAGEMENT_1,
|
|
|
|
WM8994_HPOUT1R_ENA_MASK, WM8994_HPOUT1R_ENA);
|
2012-10-25 19:49:23 +00:00
|
|
|
|
2013-09-11 11:08:46 +00:00
|
|
|
if (aif_id == WM8994_AIF1) {
|
2018-12-03 11:37:24 +00:00
|
|
|
ret |= wm8994_i2c_write(priv, WM8994_POWER_MANAGEMENT_2,
|
2013-09-11 11:08:46 +00:00
|
|
|
WM8994_TSHUT_ENA | WM8994_MIXINL_ENA |
|
|
|
|
WM8994_MIXINR_ENA | WM8994_IN2L_ENA |
|
|
|
|
WM8994_IN2R_ENA);
|
|
|
|
|
2018-12-03 11:37:24 +00:00
|
|
|
ret |= wm8994_i2c_write(priv, WM8994_POWER_MANAGEMENT_4,
|
2013-09-11 11:08:46 +00:00
|
|
|
WM8994_ADCL_ENA | WM8994_ADCR_ENA |
|
|
|
|
WM8994_AIF1ADC1R_ENA |
|
|
|
|
WM8994_AIF1ADC1L_ENA);
|
|
|
|
|
|
|
|
/* Power enable for AIF1 and DAC1 */
|
2018-12-03 11:37:24 +00:00
|
|
|
ret |= wm8994_i2c_write(priv, WM8994_POWER_MANAGEMENT_5,
|
2013-09-11 11:08:46 +00:00
|
|
|
WM8994_AIF1DACL_ENA |
|
|
|
|
WM8994_AIF1DACR_ENA |
|
|
|
|
WM8994_DAC1L_ENA | WM8994_DAC1R_ENA);
|
|
|
|
} else if (aif_id == WM8994_AIF2) {
|
|
|
|
/* Power enable for AIF2 and DAC1 */
|
2018-12-03 11:37:24 +00:00
|
|
|
ret |= wm8994_bic_or(priv, WM8994_POWER_MANAGEMENT_5,
|
2013-09-11 11:08:46 +00:00
|
|
|
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);
|
|
|
|
}
|
2012-10-25 19:49:23 +00:00
|
|
|
/* Head Phone Initialisation */
|
2018-12-03 11:37:24 +00:00
|
|
|
ret |= wm8994_bic_or(priv, WM8994_ANALOGUE_HP_1,
|
2012-10-25 19:49:23 +00:00
|
|
|
WM8994_HPOUT1L_DLY_MASK | WM8994_HPOUT1R_DLY_MASK,
|
|
|
|
WM8994_HPOUT1L_DLY | WM8994_HPOUT1R_DLY);
|
|
|
|
|
2018-12-03 11:37:24 +00:00
|
|
|
ret |= wm8994_bic_or(priv, WM8994_DC_SERVO_1,
|
2012-10-25 19:49:23 +00:00
|
|
|
WM8994_DCS_ENA_CHAN_0_MASK |
|
|
|
|
WM8994_DCS_ENA_CHAN_1_MASK , WM8994_DCS_ENA_CHAN_0 |
|
|
|
|
WM8994_DCS_ENA_CHAN_1);
|
|
|
|
|
2018-12-03 11:37:24 +00:00
|
|
|
ret |= wm8994_bic_or(priv, WM8994_ANALOGUE_HP_1,
|
2012-10-25 19:49:23 +00:00
|
|
|
WM8994_HPOUT1L_DLY_MASK |
|
|
|
|
WM8994_HPOUT1R_DLY_MASK | WM8994_HPOUT1L_OUTP_MASK |
|
|
|
|
WM8994_HPOUT1R_OUTP_MASK |
|
|
|
|
WM8994_HPOUT1L_RMV_SHORT_MASK |
|
|
|
|
WM8994_HPOUT1R_RMV_SHORT_MASK, WM8994_HPOUT1L_DLY |
|
|
|
|
WM8994_HPOUT1R_DLY | WM8994_HPOUT1L_OUTP |
|
|
|
|
WM8994_HPOUT1R_OUTP | WM8994_HPOUT1L_RMV_SHORT |
|
|
|
|
WM8994_HPOUT1R_RMV_SHORT);
|
|
|
|
|
|
|
|
/* MIXER Config DAC1 to HP */
|
2018-12-03 11:37:24 +00:00
|
|
|
ret |= wm8994_bic_or(priv, WM8994_OUTPUT_MIXER_1,
|
|
|
|
WM8994_DAC1L_TO_HPOUT1L_MASK,
|
|
|
|
WM8994_DAC1L_TO_HPOUT1L);
|
2012-10-25 19:49:23 +00:00
|
|
|
|
2018-12-03 11:37:24 +00:00
|
|
|
ret |= wm8994_bic_or(priv, WM8994_OUTPUT_MIXER_2,
|
|
|
|
WM8994_DAC1R_TO_HPOUT1R_MASK,
|
|
|
|
WM8994_DAC1R_TO_HPOUT1R);
|
2012-10-25 19:49:23 +00:00
|
|
|
|
2013-09-11 11:08:46 +00:00
|
|
|
if (aif_id == WM8994_AIF1) {
|
|
|
|
/* Routing AIF1 to DAC1 */
|
2018-12-03 11:37:24 +00:00
|
|
|
ret |= wm8994_i2c_write(priv, WM8994_DAC1_LEFT_MIXER_ROUTING,
|
|
|
|
WM8994_AIF1DAC1L_TO_DAC1L);
|
2013-09-11 11:08:46 +00:00
|
|
|
|
2018-12-03 11:37:24 +00:00
|
|
|
ret |= wm8994_i2c_write(priv, WM8994_DAC1_RIGHT_MIXER_ROUTING,
|
2013-09-11 11:08:46 +00:00
|
|
|
WM8994_AIF1DAC1R_TO_DAC1R);
|
|
|
|
|
|
|
|
/* GPIO Settings for AIF1 */
|
2018-12-03 11:37:24 +00:00
|
|
|
ret |= wm8994_i2c_write(priv, WM8994_GPIO_1,
|
|
|
|
WM8994_GPIO_DIR_OUTPUT |
|
|
|
|
WM8994_GPIO_FUNCTION_I2S_CLK |
|
|
|
|
WM8994_GPIO_INPUT_DEBOUNCE);
|
2013-09-11 11:08:46 +00:00
|
|
|
|
2018-12-03 11:37:24 +00:00
|
|
|
ret |= wm8994_init_volume_aif1_dac1(priv);
|
2013-09-11 11:08:46 +00:00
|
|
|
} else if (aif_id == WM8994_AIF2) {
|
|
|
|
/* Routing AIF2 to DAC1 */
|
2018-12-03 11:37:24 +00:00
|
|
|
ret |= wm8994_bic_or(priv, WM8994_DAC1_LEFT_MIXER_ROUTING,
|
|
|
|
WM8994_AIF2DACL_TO_DAC1L_MASK,
|
|
|
|
WM8994_AIF2DACL_TO_DAC1L);
|
2013-09-11 11:08:46 +00:00
|
|
|
|
2018-12-03 11:37:24 +00:00
|
|
|
ret |= wm8994_bic_or(priv, WM8994_DAC1_RIGHT_MIXER_ROUTING,
|
|
|
|
WM8994_AIF2DACR_TO_DAC1R_MASK,
|
|
|
|
WM8994_AIF2DACR_TO_DAC1R);
|
2013-09-11 11:08:46 +00:00
|
|
|
|
|
|
|
/* GPIO Settings for AIF2 */
|
|
|
|
/* B CLK */
|
2018-12-03 11:37:24 +00:00
|
|
|
ret |= wm8994_bic_or(priv, WM8994_GPIO_3, WM8994_GPIO_DIR_MASK |
|
|
|
|
WM8994_GPIO_FUNCTION_MASK,
|
|
|
|
WM8994_GPIO_DIR_OUTPUT);
|
2013-09-11 11:08:46 +00:00
|
|
|
|
|
|
|
/* LR CLK */
|
2018-12-03 11:37:24 +00:00
|
|
|
ret |= wm8994_bic_or(priv, WM8994_GPIO_4, WM8994_GPIO_DIR_MASK |
|
|
|
|
WM8994_GPIO_FUNCTION_MASK,
|
|
|
|
WM8994_GPIO_DIR_OUTPUT);
|
2013-09-11 11:08:46 +00:00
|
|
|
|
|
|
|
/* DATA */
|
2018-12-03 11:37:24 +00:00
|
|
|
ret |= wm8994_bic_or(priv, WM8994_GPIO_5, WM8994_GPIO_DIR_MASK |
|
|
|
|
WM8994_GPIO_FUNCTION_MASK,
|
|
|
|
WM8994_GPIO_DIR_OUTPUT);
|
2013-09-11 11:08:46 +00:00
|
|
|
|
2018-12-03 11:37:24 +00:00
|
|
|
ret |= wm8994_init_volume_aif2_dac1(priv);
|
2013-09-11 11:08:46 +00:00
|
|
|
}
|
|
|
|
|
2012-10-25 19:49:23 +00:00
|
|
|
if (ret < 0)
|
|
|
|
goto err;
|
|
|
|
|
2018-12-03 11:37:27 +00:00
|
|
|
debug("%s: Codec chip setup ok\n", __func__);
|
2012-10-25 19:49:23 +00:00
|
|
|
return 0;
|
|
|
|
err:
|
2018-12-03 11:37:27 +00:00
|
|
|
debug("%s: Codec chip setup error\n", __func__);
|
2012-10-25 19:49:23 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-12-03 11:37:26 +00:00
|
|
|
static int _wm8994_init(struct wm8994_priv *priv,
|
|
|
|
enum en_audio_interface aif_id, int sampling_rate,
|
|
|
|
int mclk_freq, int bits_per_sample,
|
|
|
|
unsigned int channels)
|
2012-10-25 19:49:23 +00:00
|
|
|
{
|
2018-12-03 11:37:26 +00:00
|
|
|
int ret;
|
2012-10-25 19:49:23 +00:00
|
|
|
|
2018-12-03 11:37:27 +00:00
|
|
|
ret = wm8994_setup_interface(priv, aif_id);
|
2012-10-25 19:49:23 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
debug("%s: wm8994 codec chip init failed\n", __func__);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-12-10 17:37:39 +00:00
|
|
|
ret = wm8994_set_sysclk(priv, aif_id, WM8994_SYSCLK_MCLK1, mclk_freq);
|
2012-10-25 19:49:23 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
debug("%s: wm8994 codec set sys clock failed\n", __func__);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-12-03 11:37:26 +00:00
|
|
|
ret = wm8994_hw_params(priv, aif_id, sampling_rate, bits_per_sample,
|
|
|
|
channels);
|
2012-10-25 19:49:23 +00:00
|
|
|
|
|
|
|
if (ret == 0) {
|
2018-12-03 11:37:26 +00:00
|
|
|
ret = wm8994_set_fmt(priv, aif_id, SND_SOC_DAIFMT_I2S |
|
|
|
|
SND_SOC_DAIFMT_NB_NF |
|
2018-12-03 11:37:24 +00:00
|
|
|
SND_SOC_DAIFMT_CBS_CFS);
|
2012-10-25 19:49:23 +00:00
|
|
|
}
|
2018-12-03 11:37:26 +00:00
|
|
|
|
2012-10-25 19:49:23 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2018-12-03 11:37:26 +00:00
|
|
|
|
2018-12-10 17:37:39 +00:00
|
|
|
static int wm8994_set_params(struct udevice *dev, int interface, int rate,
|
|
|
|
int mclk_freq, int bits_per_sample, uint channels)
|
|
|
|
{
|
|
|
|
struct wm8994_priv *priv = dev_get_priv(dev);
|
|
|
|
|
|
|
|
return _wm8994_init(priv, interface, rate, mclk_freq, bits_per_sample,
|
|
|
|
channels);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int wm8994_probe(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct wm8994_priv *priv = dev_get_priv(dev);
|
|
|
|
|
|
|
|
priv->dev = dev;
|
|
|
|
return wm8994_device_init(priv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct audio_codec_ops wm8994_ops = {
|
|
|
|
.set_params = wm8994_set_params,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct udevice_id wm8994_ids[] = {
|
|
|
|
{ .compatible = "wolfson,wm8994" },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(wm8994) = {
|
|
|
|
.name = "wm8994",
|
|
|
|
.id = UCLASS_AUDIO_CODEC,
|
|
|
|
.of_match = wm8994_ids,
|
|
|
|
.probe = wm8994_probe,
|
|
|
|
.ops = &wm8994_ops,
|
|
|
|
.priv_auto_alloc_size = sizeof(struct wm8994_priv),
|
|
|
|
};
|