Skip to content

Commit

Permalink
Merge remote-tracking branches 'asoc/topic/txx9', 'asoc/topic/uda134x…
Browse files Browse the repository at this point in the history
…', 'asoc/topic/ux500' and 'asoc/topic/width' into asoc-next
  • Loading branch information
Mark Brown committed Aug 30, 2015
5 parents 428157c + 95e3c23 + ef3355d + 4313489 + 0a3dcb5 commit c009d37
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 141 deletions.
2 changes: 1 addition & 1 deletion sound/soc/codecs/max98925.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ static int max98925_dai_hw_params(struct snd_pcm_substream *substream,
struct snd_soc_codec *codec = dai->codec;
struct max98925_priv *max98925 = snd_soc_codec_get_drvdata(codec);

switch (snd_pcm_format_width(params_format(params))) {
switch (params_width(params)) {
case 16:
regmap_update_bits(max98925->regmap,
MAX98925_FORMAT,
Expand Down
4 changes: 2 additions & 2 deletions sound/soc/codecs/pcm512x.c
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,7 @@ static int pcm512x_hw_params(struct snd_pcm_substream *substream,
params_rate(params),
params_channels(params));

switch (snd_pcm_format_width(params_format(params))) {
switch (params_width(params)) {
case 16:
alen = PCM512x_ALEN_16;
break;
Expand All @@ -1132,7 +1132,7 @@ static int pcm512x_hw_params(struct snd_pcm_substream *substream,
break;
default:
dev_err(codec->dev, "Bad frame size: %d\n",
snd_pcm_format_width(params_format(params)));
params_width(params));
return -EINVAL;
}

Expand Down
180 changes: 76 additions & 104 deletions sound/soc/codecs/uda134x.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,74 +37,53 @@ struct uda134x_priv {

struct snd_pcm_substream *master_substream;
struct snd_pcm_substream *slave_substream;
};

/* In-data addresses are hard-coded into the reg-cache values */
static const char uda134x_reg[UDA134X_REGS_NUM] = {
/* Extended address registers */
0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00,
/* Status, data regs */
0x00, 0x83, 0x00, 0x40, 0x80, 0xC0, 0x00,
struct regmap *regmap;
struct uda134x_platform_data *pd;
};

/*
* The codec has no support for reading its registers except for peak level...
*/
static inline unsigned int uda134x_read_reg_cache(struct snd_soc_codec *codec,
unsigned int reg)
{
u8 *cache = codec->reg_cache;

if (reg >= UDA134X_REGS_NUM)
return -1;
return cache[reg];
}

/*
* Write the register cache
*/
static inline void uda134x_write_reg_cache(struct snd_soc_codec *codec,
u8 reg, unsigned int value)
{
u8 *cache = codec->reg_cache;

if (reg >= UDA134X_REGS_NUM)
return;
cache[reg] = value;
}
static const struct reg_default uda134x_reg_defaults[] = {
{ UDA134X_EA000, 0x04 },
{ UDA134X_EA001, 0x04 },
{ UDA134X_EA010, 0x04 },
{ UDA134X_EA011, 0x00 },
{ UDA134X_EA100, 0x00 },
{ UDA134X_EA101, 0x00 },
{ UDA134X_EA110, 0x00 },
{ UDA134X_EA111, 0x00 },
{ UDA134X_STATUS0, 0x00 },
{ UDA134X_STATUS1, 0x03 },
{ UDA134X_DATA000, 0x00 },
{ UDA134X_DATA001, 0x00 },
{ UDA134X_DATA010, 0x00 },
{ UDA134X_DATA011, 0x00 },
{ UDA134X_DATA1, 0x00 },
};

/*
* Write to the uda134x registers
*
*/
static int uda134x_write(struct snd_soc_codec *codec, unsigned int reg,
static int uda134x_regmap_write(void *context, unsigned int reg,
unsigned int value)
{
struct uda134x_platform_data *pd = context;
int ret;
u8 addr;
u8 data = value;
struct uda134x_platform_data *pd = codec->control_data;

pr_debug("%s reg: %02X, value:%02X\n", __func__, reg, value);

if (reg >= UDA134X_REGS_NUM) {
printk(KERN_ERR "%s unknown register: reg: %u",
__func__, reg);
return -EINVAL;
}

uda134x_write_reg_cache(codec, reg, value);

switch (reg) {
case UDA134X_STATUS0:
case UDA134X_STATUS1:
addr = UDA134X_STATUS_ADDR;
data |= (reg - UDA134X_STATUS0) << 7;
break;
case UDA134X_DATA000:
case UDA134X_DATA001:
case UDA134X_DATA010:
case UDA134X_DATA011:
addr = UDA134X_DATA0_ADDR;
data |= (reg - UDA134X_DATA000) << 6;
break;
case UDA134X_DATA1:
addr = UDA134X_DATA1_ADDR;
Expand Down Expand Up @@ -133,27 +112,28 @@ static int uda134x_write(struct snd_soc_codec *codec, unsigned int reg,

static inline void uda134x_reset(struct snd_soc_codec *codec)
{
u8 reset_reg = uda134x_read_reg_cache(codec, UDA134X_STATUS0);
uda134x_write(codec, UDA134X_STATUS0, reset_reg | (1<<6));
struct uda134x_priv *uda134x = snd_soc_codec_get_drvdata(codec);
unsigned int mask = 1<<6;

regmap_update_bits(uda134x->regmap, UDA134X_STATUS0, mask, mask);
msleep(1);
uda134x_write(codec, UDA134X_STATUS0, reset_reg & ~(1<<6));
regmap_update_bits(uda134x->regmap, UDA134X_STATUS0, mask, 0);
}

static int uda134x_mute(struct snd_soc_dai *dai, int mute)
{
struct snd_soc_codec *codec = dai->codec;
u8 mute_reg = uda134x_read_reg_cache(codec, UDA134X_DATA010);
struct uda134x_priv *uda134x = snd_soc_codec_get_drvdata(dai->codec);
unsigned int mask = 1<<2;
unsigned int val;

pr_debug("%s mute: %d\n", __func__, mute);

if (mute)
mute_reg |= (1<<2);
val = mask;
else
mute_reg &= ~(1<<2);
val = 0;

uda134x_write(codec, UDA134X_DATA010, mute_reg);

return 0;
return regmap_update_bits(uda134x->regmap, UDA134X_DATA010, mask, val);
}

static int uda134x_startup(struct snd_pcm_substream *substream,
Expand Down Expand Up @@ -205,18 +185,14 @@ static int uda134x_hw_params(struct snd_pcm_substream *substream,
{
struct snd_soc_codec *codec = dai->codec;
struct uda134x_priv *uda134x = snd_soc_codec_get_drvdata(codec);
u8 hw_params;
unsigned int hw_params = 0;

if (substream == uda134x->slave_substream) {
pr_debug("%s ignoring hw_params for slave substream\n",
__func__);
return 0;
}

hw_params = uda134x_read_reg_cache(codec, UDA134X_STATUS0);
hw_params &= STATUS0_SYSCLK_MASK;
hw_params &= STATUS0_DAIFMT_MASK;

pr_debug("%s sysclk: %d, rate:%d\n", __func__,
uda134x->sysclk, params_rate(params));

Expand Down Expand Up @@ -267,9 +243,8 @@ static int uda134x_hw_params(struct snd_pcm_substream *substream,
return -EINVAL;
}

uda134x_write(codec, UDA134X_STATUS0, hw_params);

return 0;
return regmap_update_bits(uda134x->regmap, UDA134X_STATUS0,
STATUS0_SYSCLK_MASK | STATUS0_DAIFMT_MASK, hw_params);
}

static int uda134x_set_dai_sysclk(struct snd_soc_dai *codec_dai,
Expand Down Expand Up @@ -324,10 +299,8 @@ static int uda134x_set_dai_fmt(struct snd_soc_dai *codec_dai,
static int uda134x_set_bias_level(struct snd_soc_codec *codec,
enum snd_soc_bias_level level)
{
struct uda134x_platform_data *pd = codec->control_data;
int i;
u8 *cache = codec->reg_cache;

struct uda134x_priv *uda134x = snd_soc_codec_get_drvdata(codec);
struct uda134x_platform_data *pd = uda134x->pd;
pr_debug("%s bias level %d\n", __func__, level);

switch (level) {
Expand All @@ -337,17 +310,17 @@ static int uda134x_set_bias_level(struct snd_soc_codec *codec,
/* power on */
if (pd->power) {
pd->power(1);
/* Sync reg_cache with the hardware */
for (i = 0; i < ARRAY_SIZE(uda134x_reg); i++)
codec->driver->write(codec, i, *cache++);
regcache_sync(uda134x->regmap);
}
break;
case SND_SOC_BIAS_STANDBY:
break;
case SND_SOC_BIAS_OFF:
/* power off */
if (pd->power)
if (pd->power) {
pd->power(0);
regcache_mark_dirty(uda134x->regmap);
}
break;
}
return 0;
Expand Down Expand Up @@ -478,21 +451,14 @@ static struct snd_soc_dai_driver uda134x_dai = {
static int uda134x_soc_probe(struct snd_soc_codec *codec)
{
struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
struct uda134x_priv *uda134x;
struct uda134x_platform_data *pd = codec->component.card->dev->platform_data;
struct uda134x_priv *uda134x = snd_soc_codec_get_drvdata(codec);
struct uda134x_platform_data *pd = uda134x->pd;
const struct snd_soc_dapm_widget *widgets;
unsigned num_widgets;

int ret;

printk(KERN_INFO "UDA134X SoC Audio Codec\n");

if (!pd) {
printk(KERN_ERR "UDA134X SoC codec: "
"missing L3 bitbang function\n");
return -ENODEV;
}

switch (pd->model) {
case UDA134X_UDA1340:
case UDA134X_UDA1341:
Expand All @@ -506,13 +472,6 @@ static int uda134x_soc_probe(struct snd_soc_codec *codec)
return -EINVAL;
}

uda134x = kzalloc(sizeof(struct uda134x_priv), GFP_KERNEL);
if (uda134x == NULL)
return -ENOMEM;
snd_soc_codec_set_drvdata(codec, uda134x);

codec->control_data = pd;

if (pd->power)
pd->power(1);

Expand All @@ -530,7 +489,6 @@ static int uda134x_soc_probe(struct snd_soc_codec *codec)
if (ret) {
printk(KERN_ERR "%s failed to register dapm controls: %d",
__func__, ret);
kfree(uda134x);
return ret;
}

Expand All @@ -551,36 +509,19 @@ static int uda134x_soc_probe(struct snd_soc_codec *codec)
default:
printk(KERN_ERR "%s unknown codec type: %d",
__func__, pd->model);
kfree(uda134x);
return -EINVAL;
}

if (ret < 0) {
printk(KERN_ERR "UDA134X: failed to register controls\n");
kfree(uda134x);
return ret;
}

return 0;
}

/* power down chip */
static int uda134x_soc_remove(struct snd_soc_codec *codec)
{
struct uda134x_priv *uda134x = snd_soc_codec_get_drvdata(codec);

kfree(uda134x);
return 0;
}

static struct snd_soc_codec_driver soc_codec_dev_uda134x = {
.probe = uda134x_soc_probe,
.remove = uda134x_soc_remove,
.reg_cache_size = sizeof(uda134x_reg),
.reg_word_size = sizeof(u8),
.reg_cache_default = uda134x_reg,
.reg_cache_step = 1,
.read = uda134x_read_reg_cache,
.set_bias_level = uda134x_set_bias_level,
.suspend_bias_off = true,

Expand All @@ -590,8 +531,39 @@ static struct snd_soc_codec_driver soc_codec_dev_uda134x = {
.num_dapm_routes = ARRAY_SIZE(uda134x_dapm_routes),
};

static const struct regmap_config uda134x_regmap_config = {
.reg_bits = 8,
.val_bits = 8,
.max_register = UDA134X_DATA1,
.reg_defaults = uda134x_reg_defaults,
.num_reg_defaults = ARRAY_SIZE(uda134x_reg_defaults),
.cache_type = REGCACHE_RBTREE,

.reg_write = uda134x_regmap_write,
};

static int uda134x_codec_probe(struct platform_device *pdev)
{
struct uda134x_platform_data *pd = pdev->dev.platform_data;
struct uda134x_priv *uda134x;

if (!pd) {
dev_err(&pdev->dev, "Missing L3 bitbang function\n");
return -ENODEV;
}

uda134x = devm_kzalloc(&pdev->dev, sizeof(*uda134x), GFP_KERNEL);
if (!uda134x)
return -ENOMEM;

uda134x->pd = pd;
platform_set_drvdata(pdev, uda134x);

uda134x->regmap = devm_regmap_init(&pdev->dev, NULL, pd,
&uda134x_regmap_config);
if (IS_ERR(uda134x->regmap))
return PTR_ERR(uda134x->regmap);

return snd_soc_register_codec(&pdev->dev,
&soc_codec_dev_uda134x, &uda134x_dai, 1);
}
Expand Down
2 changes: 0 additions & 2 deletions sound/soc/codecs/uda134x.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
#define UDA134X_DATA011 13
#define UDA134X_DATA1 14

#define UDA134X_REGS_NUM 15

#define STATUS0_DAIFMT_MASK (~(7<<1))
#define STATUS0_SYSCLK_MASK (~(3<<4))

Expand Down
2 changes: 1 addition & 1 deletion sound/soc/codecs/wm2200.c
Original file line number Diff line number Diff line change
Expand Up @@ -1702,7 +1702,7 @@ static int wm2200_hw_params(struct snd_pcm_substream *substream,
int *bclk_rates;

/* Data sizes if not using TDM */
wl = snd_pcm_format_width(params_format(params));
wl = params_width(params);
if (wl < 0)
return wl;
fl = snd_soc_params_to_frame_size(params);
Expand Down
2 changes: 1 addition & 1 deletion sound/soc/codecs/wm5100.c
Original file line number Diff line number Diff line change
Expand Up @@ -1408,7 +1408,7 @@ static int wm5100_hw_params(struct snd_pcm_substream *substream,
base = dai->driver->base;

/* Data sizes if not using TDM */
wl = snd_pcm_format_width(params_format(params));
wl = params_width(params);
if (wl < 0)
return wl;
fl = snd_soc_params_to_frame_size(params);
Expand Down
4 changes: 2 additions & 2 deletions sound/soc/codecs/wm8776.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ static int wm8776_hw_params(struct snd_pcm_substream *substream,
}

/* Set word length */
switch (snd_pcm_format_width(params_format(params))) {
switch (params_width(params)) {
case 16:
iface = 0;
break;
Expand All @@ -280,7 +280,7 @@ static int wm8776_hw_params(struct snd_pcm_substream *substream,
break;
default:
dev_err(codec->dev, "Unsupported sample size: %i\n",
snd_pcm_format_width(params_format(params)));
params_width(params));
return -EINVAL;
}

Expand Down
Loading

0 comments on commit c009d37

Please sign in to comment.