Commit 0e7cb145 authored by Mark Brown's avatar Mark Brown

Merge remote-tracking branches 'asoc/topic/ak4671', 'asoc/topic/cs42l51' and...

Merge remote-tracking branches 'asoc/topic/ak4671', 'asoc/topic/cs42l51' and 'asoc/topic/alc5623' into asoc-io
...@@ -18,6 +18,7 @@ atmel,24c02 i2c serial eeprom (24cxx) ...@@ -18,6 +18,7 @@ atmel,24c02 i2c serial eeprom (24cxx)
atmel,at97sc3204t i2c trusted platform module (TPM) atmel,at97sc3204t i2c trusted platform module (TPM)
capella,cm32181 CM32181: Ambient Light Sensor capella,cm32181 CM32181: Ambient Light Sensor
catalyst,24c32 i2c serial eeprom catalyst,24c32 i2c serial eeprom
cirrus,cs42l51 Cirrus Logic CS42L51 audio codec
dallas,ds1307 64 x 8, Serial, I2C Real-Time Clock dallas,ds1307 64 x 8, Serial, I2C Real-Time Clock
dallas,ds1338 I2C RTC with 56-Byte NV RAM dallas,ds1338 I2C RTC with 56-Byte NV RAM
dallas,ds1339 I2C Serial Real-Time Clock dallas,ds1339 I2C Serial Real-Time Clock
......
This diff is collapsed.
...@@ -105,8 +105,6 @@ ...@@ -105,8 +105,6 @@
#define AK4671_DIGITAL_MIXING_CONTROL2 0x59 #define AK4671_DIGITAL_MIXING_CONTROL2 0x59
#define AK4671_SAR_ADC_CONTROL 0x5a #define AK4671_SAR_ADC_CONTROL 0x5a
#define AK4671_CACHEREGNUM (AK4671_SAR_ADC_CONTROL + 1)
/* Bitfield Definitions */ /* Bitfield Definitions */
/* AK4671_AD_DA_POWER_MANAGEMENT (0x00) Fields */ /* AK4671_AD_DA_POWER_MANAGEMENT (0x00) Fields */
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/pm.h> #include <linux/pm.h>
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/regmap.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <sound/core.h> #include <sound/core.h>
#include <sound/pcm.h> #include <sound/pcm.h>
...@@ -38,26 +39,13 @@ MODULE_PARM_DESC(caps_charge, "ALC5623 cap charge time (msecs)"); ...@@ -38,26 +39,13 @@ MODULE_PARM_DESC(caps_charge, "ALC5623 cap charge time (msecs)");
/* codec private data */ /* codec private data */
struct alc5623_priv { struct alc5623_priv {
enum snd_soc_control_type control_type; struct regmap *regmap;
u8 id; u8 id;
unsigned int sysclk; unsigned int sysclk;
u16 reg_cache[ALC5623_VENDOR_ID2+2];
unsigned int add_ctrl; unsigned int add_ctrl;
unsigned int jack_det_ctrl; unsigned int jack_det_ctrl;
}; };
static void alc5623_fill_cache(struct snd_soc_codec *codec)
{
int i, step = codec->driver->reg_cache_step;
u16 *cache = codec->reg_cache;
/* not really efficient ... */
codec->cache_bypass = 1;
for (i = 0 ; i < codec->driver->reg_cache_size ; i += step)
cache[i] = snd_soc_read(codec, i);
codec->cache_bypass = 0;
}
static inline int alc5623_reset(struct snd_soc_codec *codec) static inline int alc5623_reset(struct snd_soc_codec *codec)
{ {
return snd_soc_write(codec, ALC5623_RESET, 0); return snd_soc_write(codec, ALC5623_RESET, 0);
...@@ -228,32 +216,37 @@ static const char *alc5623_aux_out_input_sel[] = { ...@@ -228,32 +216,37 @@ static const char *alc5623_aux_out_input_sel[] = {
"Vmid", "HPOut Mix", "Speaker Mix", "Mono Mix"}; "Vmid", "HPOut Mix", "Speaker Mix", "Mono Mix"};
/* auxout output mux */ /* auxout output mux */
static const struct soc_enum alc5623_aux_out_input_enum = static SOC_ENUM_SINGLE_DECL(alc5623_aux_out_input_enum,
SOC_ENUM_SINGLE(ALC5623_OUTPUT_MIXER_CTRL, 6, 4, alc5623_aux_out_input_sel); ALC5623_OUTPUT_MIXER_CTRL, 6,
alc5623_aux_out_input_sel);
static const struct snd_kcontrol_new alc5623_auxout_mux_controls = static const struct snd_kcontrol_new alc5623_auxout_mux_controls =
SOC_DAPM_ENUM("Route", alc5623_aux_out_input_enum); SOC_DAPM_ENUM("Route", alc5623_aux_out_input_enum);
/* speaker output mux */ /* speaker output mux */
static const struct soc_enum alc5623_spkout_input_enum = static SOC_ENUM_SINGLE_DECL(alc5623_spkout_input_enum,
SOC_ENUM_SINGLE(ALC5623_OUTPUT_MIXER_CTRL, 10, 4, alc5623_spkout_input_sel); ALC5623_OUTPUT_MIXER_CTRL, 10,
alc5623_spkout_input_sel);
static const struct snd_kcontrol_new alc5623_spkout_mux_controls = static const struct snd_kcontrol_new alc5623_spkout_mux_controls =
SOC_DAPM_ENUM("Route", alc5623_spkout_input_enum); SOC_DAPM_ENUM("Route", alc5623_spkout_input_enum);
/* headphone left output mux */ /* headphone left output mux */
static const struct soc_enum alc5623_hpl_out_input_enum = static SOC_ENUM_SINGLE_DECL(alc5623_hpl_out_input_enum,
SOC_ENUM_SINGLE(ALC5623_OUTPUT_MIXER_CTRL, 9, 2, alc5623_hpl_out_input_sel); ALC5623_OUTPUT_MIXER_CTRL, 9,
alc5623_hpl_out_input_sel);
static const struct snd_kcontrol_new alc5623_hpl_out_mux_controls = static const struct snd_kcontrol_new alc5623_hpl_out_mux_controls =
SOC_DAPM_ENUM("Route", alc5623_hpl_out_input_enum); SOC_DAPM_ENUM("Route", alc5623_hpl_out_input_enum);
/* headphone right output mux */ /* headphone right output mux */
static const struct soc_enum alc5623_hpr_out_input_enum = static SOC_ENUM_SINGLE_DECL(alc5623_hpr_out_input_enum,
SOC_ENUM_SINGLE(ALC5623_OUTPUT_MIXER_CTRL, 8, 2, alc5623_hpr_out_input_sel); ALC5623_OUTPUT_MIXER_CTRL, 8,
alc5623_hpr_out_input_sel);
static const struct snd_kcontrol_new alc5623_hpr_out_mux_controls = static const struct snd_kcontrol_new alc5623_hpr_out_mux_controls =
SOC_DAPM_ENUM("Route", alc5623_hpr_out_input_enum); SOC_DAPM_ENUM("Route", alc5623_hpr_out_input_enum);
/* speaker output N select */ /* speaker output N select */
static const struct soc_enum alc5623_spk_n_sour_enum = static SOC_ENUM_SINGLE_DECL(alc5623_spk_n_sour_enum,
SOC_ENUM_SINGLE(ALC5623_OUTPUT_MIXER_CTRL, 14, 4, alc5623_spk_n_sour_sel); ALC5623_OUTPUT_MIXER_CTRL, 14,
alc5623_spk_n_sour_sel);
static const struct snd_kcontrol_new alc5623_spkoutn_mux_controls = static const struct snd_kcontrol_new alc5623_spkoutn_mux_controls =
SOC_DAPM_ENUM("Route", alc5623_spk_n_sour_enum); SOC_DAPM_ENUM("Route", alc5623_spk_n_sour_enum);
...@@ -338,8 +331,9 @@ SND_SOC_DAPM_VMID("Vmid"), ...@@ -338,8 +331,9 @@ SND_SOC_DAPM_VMID("Vmid"),
}; };
static const char *alc5623_amp_names[] = {"AB Amp", "D Amp"}; static const char *alc5623_amp_names[] = {"AB Amp", "D Amp"};
static const struct soc_enum alc5623_amp_enum = static SOC_ENUM_SINGLE_DECL(alc5623_amp_enum,
SOC_ENUM_SINGLE(ALC5623_OUTPUT_MIXER_CTRL, 13, 2, alc5623_amp_names); ALC5623_OUTPUT_MIXER_CTRL, 13,
alc5623_amp_names);
static const struct snd_kcontrol_new alc5623_amp_mux_controls = static const struct snd_kcontrol_new alc5623_amp_mux_controls =
SOC_DAPM_ENUM("Route", alc5623_amp_enum); SOC_DAPM_ENUM("Route", alc5623_amp_enum);
...@@ -869,18 +863,28 @@ static struct snd_soc_dai_driver alc5623_dai = { ...@@ -869,18 +863,28 @@ static struct snd_soc_dai_driver alc5623_dai = {
static int alc5623_suspend(struct snd_soc_codec *codec) static int alc5623_suspend(struct snd_soc_codec *codec)
{ {
struct alc5623_priv *alc5623 = snd_soc_codec_get_drvdata(codec);
alc5623_set_bias_level(codec, SND_SOC_BIAS_OFF); alc5623_set_bias_level(codec, SND_SOC_BIAS_OFF);
regcache_cache_only(alc5623->regmap, true);
return 0; return 0;
} }
static int alc5623_resume(struct snd_soc_codec *codec) static int alc5623_resume(struct snd_soc_codec *codec)
{ {
int i, step = codec->driver->reg_cache_step; struct alc5623_priv *alc5623 = snd_soc_codec_get_drvdata(codec);
u16 *cache = codec->reg_cache; int ret;
/* Sync reg_cache with the hardware */ /* Sync reg_cache with the hardware */
for (i = 2 ; i < codec->driver->reg_cache_size ; i += step) regcache_cache_only(alc5623->regmap, false);
snd_soc_write(codec, i, cache[i]); ret = regcache_sync(alc5623->regmap);
if (ret != 0) {
dev_err(codec->dev, "Failed to sync register cache: %d\n",
ret);
regcache_cache_only(alc5623->regmap, true);
return ret;
}
alc5623_set_bias_level(codec, SND_SOC_BIAS_STANDBY); alc5623_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
...@@ -900,14 +904,14 @@ static int alc5623_probe(struct snd_soc_codec *codec) ...@@ -900,14 +904,14 @@ static int alc5623_probe(struct snd_soc_codec *codec)
struct snd_soc_dapm_context *dapm = &codec->dapm; struct snd_soc_dapm_context *dapm = &codec->dapm;
int ret; int ret;
ret = snd_soc_codec_set_cache_io(codec, 8, 16, alc5623->control_type); codec->control_data = alc5623->regmap;
ret = snd_soc_codec_set_cache_io(codec, 8, 16, SND_SOC_REGMAP);
if (ret < 0) { if (ret < 0) {
dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
return ret; return ret;
} }
alc5623_reset(codec); alc5623_reset(codec);
alc5623_fill_cache(codec);
/* power on device */ /* power on device */
alc5623_set_bias_level(codec, SND_SOC_BIAS_STANDBY); alc5623_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
...@@ -980,9 +984,15 @@ static struct snd_soc_codec_driver soc_codec_device_alc5623 = { ...@@ -980,9 +984,15 @@ static struct snd_soc_codec_driver soc_codec_device_alc5623 = {
.suspend = alc5623_suspend, .suspend = alc5623_suspend,
.resume = alc5623_resume, .resume = alc5623_resume,
.set_bias_level = alc5623_set_bias_level, .set_bias_level = alc5623_set_bias_level,
.reg_cache_size = ALC5623_VENDOR_ID2+2, };
.reg_word_size = sizeof(u16),
.reg_cache_step = 2, static const struct regmap_config alc5623_regmap = {
.reg_bits = 8,
.val_bits = 16,
.reg_stride = 2,
.max_register = ALC5623_VENDOR_ID2,
.cache_type = REGCACHE_RBTREE,
}; };
/* /*
...@@ -996,19 +1006,32 @@ static int alc5623_i2c_probe(struct i2c_client *client, ...@@ -996,19 +1006,32 @@ static int alc5623_i2c_probe(struct i2c_client *client,
{ {
struct alc5623_platform_data *pdata; struct alc5623_platform_data *pdata;
struct alc5623_priv *alc5623; struct alc5623_priv *alc5623;
int ret, vid1, vid2; unsigned int vid1, vid2;
int ret;
vid1 = i2c_smbus_read_word_data(client, ALC5623_VENDOR_ID1); alc5623 = devm_kzalloc(&client->dev, sizeof(struct alc5623_priv),
if (vid1 < 0) { GFP_KERNEL);
dev_err(&client->dev, "failed to read I2C\n"); if (alc5623 == NULL)
return -EIO; return -ENOMEM;
alc5623->regmap = devm_regmap_init_i2c(client, &alc5623_regmap);
if (IS_ERR(alc5623->regmap)) {
ret = PTR_ERR(alc5623->regmap);
dev_err(&client->dev, "Failed to initialise I/O: %d\n", ret);
return ret;
}
ret = regmap_read(alc5623->regmap, ALC5623_VENDOR_ID1, &vid1);
if (ret < 0) {
dev_err(&client->dev, "failed to read vendor ID1: %d\n", ret);
return ret;
} }
vid1 = ((vid1 & 0xff) << 8) | (vid1 >> 8); vid1 = ((vid1 & 0xff) << 8) | (vid1 >> 8);
vid2 = i2c_smbus_read_byte_data(client, ALC5623_VENDOR_ID2); ret = regmap_read(alc5623->regmap, ALC5623_VENDOR_ID2, &vid2);
if (vid2 < 0) { if (ret < 0) {
dev_err(&client->dev, "failed to read I2C\n"); dev_err(&client->dev, "failed to read vendor ID2: %d\n", ret);
return -EIO; return ret;
} }
if ((vid1 != 0x10ec) || (vid2 != id->driver_data)) { if ((vid1 != 0x10ec) || (vid2 != id->driver_data)) {
...@@ -1021,11 +1044,6 @@ static int alc5623_i2c_probe(struct i2c_client *client, ...@@ -1021,11 +1044,6 @@ static int alc5623_i2c_probe(struct i2c_client *client,
dev_dbg(&client->dev, "Found codec id : alc56%02x\n", vid2); dev_dbg(&client->dev, "Found codec id : alc56%02x\n", vid2);
alc5623 = devm_kzalloc(&client->dev, sizeof(struct alc5623_priv),
GFP_KERNEL);
if (alc5623 == NULL)
return -ENOMEM;
pdata = client->dev.platform_data; pdata = client->dev.platform_data;
if (pdata) { if (pdata) {
alc5623->add_ctrl = pdata->add_ctrl; alc5623->add_ctrl = pdata->add_ctrl;
...@@ -1048,7 +1066,6 @@ static int alc5623_i2c_probe(struct i2c_client *client, ...@@ -1048,7 +1066,6 @@ static int alc5623_i2c_probe(struct i2c_client *client,
} }
i2c_set_clientdata(client, alc5623); i2c_set_clientdata(client, alc5623);
alc5623->control_type = SND_SOC_I2C;
ret = snd_soc_register_codec(&client->dev, ret = snd_soc_register_codec(&client->dev,
&soc_codec_device_alc5623, &alc5623_dai, 1); &soc_codec_device_alc5623, &alc5623_dai, 1);
......
...@@ -293,51 +293,59 @@ static const char * const alc5632_i2s_out_sel[] = { ...@@ -293,51 +293,59 @@ static const char * const alc5632_i2s_out_sel[] = {
"ADC LR", "Voice Stereo Digital"}; "ADC LR", "Voice Stereo Digital"};
/* auxout output mux */ /* auxout output mux */
static const struct soc_enum alc5632_aux_out_input_enum = static SOC_ENUM_SINGLE_DECL(alc5632_aux_out_input_enum,
SOC_ENUM_SINGLE(ALC5632_OUTPUT_MIXER_CTRL, 6, 4, alc5632_aux_out_input_sel); ALC5632_OUTPUT_MIXER_CTRL, 6,
alc5632_aux_out_input_sel);
static const struct snd_kcontrol_new alc5632_auxout_mux_controls = static const struct snd_kcontrol_new alc5632_auxout_mux_controls =
SOC_DAPM_ENUM("AuxOut Mux", alc5632_aux_out_input_enum); SOC_DAPM_ENUM("AuxOut Mux", alc5632_aux_out_input_enum);
/* speaker output mux */ /* speaker output mux */
static const struct soc_enum alc5632_spkout_input_enum = static SOC_ENUM_SINGLE_DECL(alc5632_spkout_input_enum,
SOC_ENUM_SINGLE(ALC5632_OUTPUT_MIXER_CTRL, 10, 4, alc5632_spkout_input_sel); ALC5632_OUTPUT_MIXER_CTRL, 10,
alc5632_spkout_input_sel);
static const struct snd_kcontrol_new alc5632_spkout_mux_controls = static const struct snd_kcontrol_new alc5632_spkout_mux_controls =
SOC_DAPM_ENUM("SpeakerOut Mux", alc5632_spkout_input_enum); SOC_DAPM_ENUM("SpeakerOut Mux", alc5632_spkout_input_enum);
/* headphone left output mux */ /* headphone left output mux */
static const struct soc_enum alc5632_hpl_out_input_enum = static SOC_ENUM_SINGLE_DECL(alc5632_hpl_out_input_enum,
SOC_ENUM_SINGLE(ALC5632_OUTPUT_MIXER_CTRL, 9, 2, alc5632_hpl_out_input_sel); ALC5632_OUTPUT_MIXER_CTRL, 9,
alc5632_hpl_out_input_sel);
static const struct snd_kcontrol_new alc5632_hpl_out_mux_controls = static const struct snd_kcontrol_new alc5632_hpl_out_mux_controls =
SOC_DAPM_ENUM("Left Headphone Mux", alc5632_hpl_out_input_enum); SOC_DAPM_ENUM("Left Headphone Mux", alc5632_hpl_out_input_enum);
/* headphone right output mux */ /* headphone right output mux */
static const struct soc_enum alc5632_hpr_out_input_enum = static SOC_ENUM_SINGLE_DECL(alc5632_hpr_out_input_enum,
SOC_ENUM_SINGLE(ALC5632_OUTPUT_MIXER_CTRL, 8, 2, alc5632_hpr_out_input_sel); ALC5632_OUTPUT_MIXER_CTRL, 8,
alc5632_hpr_out_input_sel);
static const struct snd_kcontrol_new alc5632_hpr_out_mux_controls = static const struct snd_kcontrol_new alc5632_hpr_out_mux_controls =
SOC_DAPM_ENUM("Right Headphone Mux", alc5632_hpr_out_input_enum); SOC_DAPM_ENUM("Right Headphone Mux", alc5632_hpr_out_input_enum);
/* speaker output N select */ /* speaker output N select */
static const struct soc_enum alc5632_spk_n_sour_enum = static SOC_ENUM_SINGLE_DECL(alc5632_spk_n_sour_enum,
SOC_ENUM_SINGLE(ALC5632_OUTPUT_MIXER_CTRL, 14, 4, alc5632_spk_n_sour_sel); ALC5632_OUTPUT_MIXER_CTRL, 14,
alc5632_spk_n_sour_sel);
static const struct snd_kcontrol_new alc5632_spkoutn_mux_controls = static const struct snd_kcontrol_new alc5632_spkoutn_mux_controls =
SOC_DAPM_ENUM("SpeakerOut N Mux", alc5632_spk_n_sour_enum); SOC_DAPM_ENUM("SpeakerOut N Mux", alc5632_spk_n_sour_enum);
/* speaker amplifier */ /* speaker amplifier */
static const char *alc5632_amp_names[] = {"AB Amp", "D Amp"}; static const char *alc5632_amp_names[] = {"AB Amp", "D Amp"};
static const struct soc_enum alc5632_amp_enum = static SOC_ENUM_SINGLE_DECL(alc5632_amp_enum,
SOC_ENUM_SINGLE(ALC5632_OUTPUT_MIXER_CTRL, 13, 2, alc5632_amp_names); ALC5632_OUTPUT_MIXER_CTRL, 13,
alc5632_amp_names);
static const struct snd_kcontrol_new alc5632_amp_mux_controls = static const struct snd_kcontrol_new alc5632_amp_mux_controls =
SOC_DAPM_ENUM("AB-D Amp Mux", alc5632_amp_enum); SOC_DAPM_ENUM("AB-D Amp Mux", alc5632_amp_enum);
/* ADC output select */ /* ADC output select */
static const struct soc_enum alc5632_adcr_func_enum = static SOC_ENUM_SINGLE_DECL(alc5632_adcr_func_enum,
SOC_ENUM_SINGLE(ALC5632_DAC_FUNC_SELECT, 5, 2, alc5632_adcr_func_sel); ALC5632_DAC_FUNC_SELECT, 5,
alc5632_adcr_func_sel);
static const struct snd_kcontrol_new alc5632_adcr_func_controls = static const struct snd_kcontrol_new alc5632_adcr_func_controls =
SOC_DAPM_ENUM("ADCR Mux", alc5632_adcr_func_enum); SOC_DAPM_ENUM("ADCR Mux", alc5632_adcr_func_enum);
/* I2S out select */ /* I2S out select */
static const struct soc_enum alc5632_i2s_out_enum = static SOC_ENUM_SINGLE_DECL(alc5632_i2s_out_enum,
SOC_ENUM_SINGLE(ALC5632_I2S_OUT_CTL, 5, 2, alc5632_i2s_out_sel); ALC5632_I2S_OUT_CTL, 5,
alc5632_i2s_out_sel);
static const struct snd_kcontrol_new alc5632_i2s_out_controls = static const struct snd_kcontrol_new alc5632_i2s_out_controls =
SOC_DAPM_ENUM("I2SOut Mux", alc5632_i2s_out_enum); SOC_DAPM_ENUM("I2SOut Mux", alc5632_i2s_out_enum);
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include <sound/pcm_params.h> #include <sound/pcm_params.h>
#include <sound/pcm.h> #include <sound/pcm.h>
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/regmap.h>
#include "cs42l51.h" #include "cs42l51.h"
...@@ -40,7 +41,6 @@ enum master_slave_mode { ...@@ -40,7 +41,6 @@ enum master_slave_mode {
}; };
struct cs42l51_private { struct cs42l51_private {
enum snd_soc_control_type control_type;
unsigned int mclk; unsigned int mclk;
unsigned int audio_mode; /* The mode (I2S or left-justified) */ unsigned int audio_mode; /* The mode (I2S or left-justified) */
enum master_slave_mode func; enum master_slave_mode func;
...@@ -52,24 +52,6 @@ struct cs42l51_private { ...@@ -52,24 +52,6 @@ struct cs42l51_private {
SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE | \ SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE | \
SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE) SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE)
static int cs42l51_fill_cache(struct snd_soc_codec *codec)
{
u8 *cache = codec->reg_cache + 1;
struct i2c_client *i2c_client = to_i2c_client(codec->dev);
s32 length;
length = i2c_smbus_read_i2c_block_data(i2c_client,
CS42L51_FIRSTREG | 0x80, CS42L51_NUMREGS, cache);
if (length != CS42L51_NUMREGS) {
dev_err(&i2c_client->dev,
"I2C read failure, addr=0x%x (ret=%d vs %d)\n",
i2c_client->addr, length, CS42L51_NUMREGS);
return -EIO;
}
return 0;
}
static int cs42l51_get_chan_mix(struct snd_kcontrol *kcontrol, static int cs42l51_get_chan_mix(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol) struct snd_ctl_elem_value *ucontrol)
{ {
...@@ -505,16 +487,9 @@ static struct snd_soc_dai_driver cs42l51_dai = { ...@@ -505,16 +487,9 @@ static struct snd_soc_dai_driver cs42l51_dai = {
static int cs42l51_probe(struct snd_soc_codec *codec) static int cs42l51_probe(struct snd_soc_codec *codec)
{ {
struct cs42l51_private *cs42l51 = snd_soc_codec_get_drvdata(codec);
int ret, reg; int ret, reg;
ret = cs42l51_fill_cache(codec); ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP);
if (ret < 0) {
dev_err(codec->dev, "failed to fill register cache\n");
return ret;
}
ret = snd_soc_codec_set_cache_io(codec, 8, 8, cs42l51->control_type);
if (ret < 0) { if (ret < 0) {
dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
return ret; return ret;
...@@ -538,8 +513,6 @@ static int cs42l51_probe(struct snd_soc_codec *codec) ...@@ -538,8 +513,6 @@ static int cs42l51_probe(struct snd_soc_codec *codec)
static struct snd_soc_codec_driver soc_codec_device_cs42l51 = { static struct snd_soc_codec_driver soc_codec_device_cs42l51 = {
.probe = cs42l51_probe, .probe = cs42l51_probe,
.reg_cache_size = CS42L51_NUMREGS + 1,
.reg_word_size = sizeof(u8),
.controls = cs42l51_snd_controls, .controls = cs42l51_snd_controls,
.num_controls = ARRAY_SIZE(cs42l51_snd_controls), .num_controls = ARRAY_SIZE(cs42l51_snd_controls),
...@@ -549,38 +522,53 @@ static struct snd_soc_codec_driver soc_codec_device_cs42l51 = { ...@@ -549,38 +522,53 @@ static struct snd_soc_codec_driver soc_codec_device_cs42l51 = {
.num_dapm_routes = ARRAY_SIZE(cs42l51_routes), .num_dapm_routes = ARRAY_SIZE(cs42l51_routes),
}; };
static const struct regmap_config cs42l51_regmap = {
.reg_bits = 8,
.val_bits = 8,
.max_register = CS42L51_CHARGE_FREQ,
.cache_type = REGCACHE_RBTREE,
};
static int cs42l51_i2c_probe(struct i2c_client *i2c_client, static int cs42l51_i2c_probe(struct i2c_client *i2c_client,
const struct i2c_device_id *id) const struct i2c_device_id *id)
{ {
struct cs42l51_private *cs42l51; struct cs42l51_private *cs42l51;
struct regmap *regmap;
unsigned int val;
int ret; int ret;
regmap = devm_regmap_init_i2c(i2c_client, &cs42l51_regmap);
if (IS_ERR(regmap)) {
ret = PTR_ERR(regmap);
dev_err(&i2c_client->dev, "Failed to create regmap: %d\n",
ret);
return ret;
}
/* Verify that we have a CS42L51 */ /* Verify that we have a CS42L51 */
ret = i2c_smbus_read_byte_data(i2c_client, CS42L51_CHIP_REV_ID); ret = regmap_read(regmap, CS42L51_CHIP_REV_ID, &val);
if (ret < 0) { if (ret < 0) {
dev_err(&i2c_client->dev, "failed to read I2C\n"); dev_err(&i2c_client->dev, "failed to read I2C\n");
goto error; goto error;
} }
if ((ret != CS42L51_MK_CHIP_REV(CS42L51_CHIP_ID, CS42L51_CHIP_REV_A)) && if ((val != CS42L51_MK_CHIP_REV(CS42L51_CHIP_ID, CS42L51_CHIP_REV_A)) &&
(ret != CS42L51_MK_CHIP_REV(CS42L51_CHIP_ID, CS42L51_CHIP_REV_B))) { (val != CS42L51_MK_CHIP_REV(CS42L51_CHIP_ID, CS42L51_CHIP_REV_B))) {
dev_err(&i2c_client->dev, "Invalid chip id\n"); dev_err(&i2c_client->dev, "Invalid chip id: %x\n", val);
ret = -ENODEV; ret = -ENODEV;
goto error; goto error;
} }
dev_info(&i2c_client->dev, "found device cs42l51 rev %d\n", dev_info(&i2c_client->dev, "found device cs42l51 rev %d\n",
ret & 7); val & 7);
cs42l51 = devm_kzalloc(&i2c_client->dev, sizeof(struct cs42l51_private), cs42l51 = devm_kzalloc(&i2c_client->dev, sizeof(struct cs42l51_private),
GFP_KERNEL); GFP_KERNEL);
if (!cs42l51) { if (!cs42l51)
dev_err(&i2c_client->dev, "could not allocate codec\n");
return -ENOMEM; return -ENOMEM;
}
i2c_set_clientdata(i2c_client, cs42l51); i2c_set_clientdata(i2c_client, cs42l51);
cs42l51->control_type = SND_SOC_I2C;
ret = snd_soc_register_codec(&i2c_client->dev, ret = snd_soc_register_codec(&i2c_client->dev,
&soc_codec_device_cs42l51, &cs42l51_dai, 1); &soc_codec_device_cs42l51, &cs42l51_dai, 1);
...@@ -600,10 +588,17 @@ static const struct i2c_device_id cs42l51_id[] = { ...@@ -600,10 +588,17 @@ static const struct i2c_device_id cs42l51_id[] = {
}; };
MODULE_DEVICE_TABLE(i2c, cs42l51_id); MODULE_DEVICE_TABLE(i2c, cs42l51_id);
static const struct of_device_id cs42l51_of_match[] = {
{ .compatible = "cirrus,cs42l51", },
{ }
};
MODULE_DEVICE_TABLE(of, cs42l51_of_match);
static struct i2c_driver cs42l51_i2c_driver = { static struct i2c_driver cs42l51_i2c_driver = {
.driver = { .driver = {
.name = "cs42l51-codec", .name = "cs42l51-codec",
.owner = THIS_MODULE, .owner = THIS_MODULE,
.of_match_table = cs42l51_of_match,
}, },
.id_table = cs42l51_id, .id_table = cs42l51_id,
.probe = cs42l51_i2c_probe, .probe = cs42l51_i2c_probe,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment