ASoC: da7219: Move required devm_* allocations to device level code

In preparation for cleanup of device level and codec level probe
funcitonality, all necessary devm_* allocations and fw retrieval
functions are moved to the I2C probe level code.

Signed-off-by: Adam Thomson <Adam.Thomson.Opensource@diasemi.com>
Link: https://lore.kernel.org/r/7a9a2ead6e37820a6025c0a62dc45952d5032ab7.1597164865.git.Adam.Thomson.Opensource@diasemi.com
Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
Adam Thomson 2020-08-11 17:57:23 +01:00 committed by Mark Brown
parent 549ade5721
commit 21f279f34c
No known key found for this signature in database
GPG Key ID: 24D68B725D5487D0
3 changed files with 70 additions and 48 deletions

View File

@ -460,7 +460,7 @@ static irqreturn_t da7219_aad_irq_thread(int irq, void *data)
*/ */
static enum da7219_aad_micbias_pulse_lvl static enum da7219_aad_micbias_pulse_lvl
da7219_aad_fw_micbias_pulse_lvl(struct snd_soc_component *component, u32 val) da7219_aad_fw_micbias_pulse_lvl(struct device *dev, u32 val)
{ {
switch (val) { switch (val) {
case 2800: case 2800:
@ -468,13 +468,13 @@ static enum da7219_aad_micbias_pulse_lvl
case 2900: case 2900:
return DA7219_AAD_MICBIAS_PULSE_LVL_2_9V; return DA7219_AAD_MICBIAS_PULSE_LVL_2_9V;
default: default:
dev_warn(component->dev, "Invalid micbias pulse level"); dev_warn(dev, "Invalid micbias pulse level");
return DA7219_AAD_MICBIAS_PULSE_LVL_OFF; return DA7219_AAD_MICBIAS_PULSE_LVL_OFF;
} }
} }
static enum da7219_aad_btn_cfg static enum da7219_aad_btn_cfg
da7219_aad_fw_btn_cfg(struct snd_soc_component *component, u32 val) da7219_aad_fw_btn_cfg(struct device *dev, u32 val)
{ {
switch (val) { switch (val) {
case 2: case 2:
@ -492,13 +492,13 @@ static enum da7219_aad_btn_cfg
case 500: case 500:
return DA7219_AAD_BTN_CFG_500MS; return DA7219_AAD_BTN_CFG_500MS;
default: default:
dev_warn(component->dev, "Invalid button config"); dev_warn(dev, "Invalid button config");
return DA7219_AAD_BTN_CFG_10MS; return DA7219_AAD_BTN_CFG_10MS;
} }
} }
static enum da7219_aad_mic_det_thr static enum da7219_aad_mic_det_thr
da7219_aad_fw_mic_det_thr(struct snd_soc_component *component, u32 val) da7219_aad_fw_mic_det_thr(struct device *dev, u32 val)
{ {
switch (val) { switch (val) {
case 200: case 200:
@ -510,13 +510,13 @@ static enum da7219_aad_mic_det_thr
case 1000: case 1000:
return DA7219_AAD_MIC_DET_THR_1000_OHMS; return DA7219_AAD_MIC_DET_THR_1000_OHMS;
default: default:
dev_warn(component->dev, "Invalid mic detect threshold"); dev_warn(dev, "Invalid mic detect threshold");
return DA7219_AAD_MIC_DET_THR_500_OHMS; return DA7219_AAD_MIC_DET_THR_500_OHMS;
} }
} }
static enum da7219_aad_jack_ins_deb static enum da7219_aad_jack_ins_deb
da7219_aad_fw_jack_ins_deb(struct snd_soc_component *component, u32 val) da7219_aad_fw_jack_ins_deb(struct device *dev, u32 val)
{ {
switch (val) { switch (val) {
case 5: case 5:
@ -536,13 +536,13 @@ static enum da7219_aad_jack_ins_deb
case 1000: case 1000:
return DA7219_AAD_JACK_INS_DEB_1S; return DA7219_AAD_JACK_INS_DEB_1S;
default: default:
dev_warn(component->dev, "Invalid jack insert debounce"); dev_warn(dev, "Invalid jack insert debounce");
return DA7219_AAD_JACK_INS_DEB_20MS; return DA7219_AAD_JACK_INS_DEB_20MS;
} }
} }
static enum da7219_aad_jack_det_rate static enum da7219_aad_jack_det_rate
da7219_aad_fw_jack_det_rate(struct snd_soc_component *component, const char *str) da7219_aad_fw_jack_det_rate(struct device *dev, const char *str)
{ {
if (!strcmp(str, "32ms_64ms")) { if (!strcmp(str, "32ms_64ms")) {
return DA7219_AAD_JACK_DET_RATE_32_64MS; return DA7219_AAD_JACK_DET_RATE_32_64MS;
@ -553,13 +553,13 @@ static enum da7219_aad_jack_det_rate
} else if (!strcmp(str, "256ms_512ms")) { } else if (!strcmp(str, "256ms_512ms")) {
return DA7219_AAD_JACK_DET_RATE_256_512MS; return DA7219_AAD_JACK_DET_RATE_256_512MS;
} else { } else {
dev_warn(component->dev, "Invalid jack detect rate"); dev_warn(dev, "Invalid jack detect rate");
return DA7219_AAD_JACK_DET_RATE_256_512MS; return DA7219_AAD_JACK_DET_RATE_256_512MS;
} }
} }
static enum da7219_aad_jack_rem_deb static enum da7219_aad_jack_rem_deb
da7219_aad_fw_jack_rem_deb(struct snd_soc_component *component, u32 val) da7219_aad_fw_jack_rem_deb(struct device *dev, u32 val)
{ {
switch (val) { switch (val) {
case 1: case 1:
@ -571,13 +571,13 @@ static enum da7219_aad_jack_rem_deb
case 20: case 20:
return DA7219_AAD_JACK_REM_DEB_20MS; return DA7219_AAD_JACK_REM_DEB_20MS;
default: default:
dev_warn(component->dev, "Invalid jack removal debounce"); dev_warn(dev, "Invalid jack removal debounce");
return DA7219_AAD_JACK_REM_DEB_1MS; return DA7219_AAD_JACK_REM_DEB_1MS;
} }
} }
static enum da7219_aad_btn_avg static enum da7219_aad_btn_avg
da7219_aad_fw_btn_avg(struct snd_soc_component *component, u32 val) da7219_aad_fw_btn_avg(struct device *dev, u32 val)
{ {
switch (val) { switch (val) {
case 1: case 1:
@ -589,13 +589,13 @@ static enum da7219_aad_btn_avg
case 8: case 8:
return DA7219_AAD_BTN_AVG_8; return DA7219_AAD_BTN_AVG_8;
default: default:
dev_warn(component->dev, "Invalid button average value"); dev_warn(dev, "Invalid button average value");
return DA7219_AAD_BTN_AVG_2; return DA7219_AAD_BTN_AVG_2;
} }
} }
static enum da7219_aad_adc_1bit_rpt static enum da7219_aad_adc_1bit_rpt
da7219_aad_fw_adc_1bit_rpt(struct snd_soc_component *component, u32 val) da7219_aad_fw_adc_1bit_rpt(struct device *dev, u32 val)
{ {
switch (val) { switch (val) {
case 1: case 1:
@ -607,14 +607,13 @@ static enum da7219_aad_adc_1bit_rpt
case 8: case 8:
return DA7219_AAD_ADC_1BIT_RPT_8; return DA7219_AAD_ADC_1BIT_RPT_8;
default: default:
dev_warn(component->dev, "Invalid ADC 1-bit repeat value"); dev_warn(dev, "Invalid ADC 1-bit repeat value");
return DA7219_AAD_ADC_1BIT_RPT_1; return DA7219_AAD_ADC_1BIT_RPT_1;
} }
} }
static struct da7219_aad_pdata *da7219_aad_fw_to_pdata(struct snd_soc_component *component) static struct da7219_aad_pdata *da7219_aad_fw_to_pdata(struct device *dev)
{ {
struct device *dev = component->dev;
struct i2c_client *i2c = to_i2c_client(dev); struct i2c_client *i2c = to_i2c_client(dev);
struct fwnode_handle *aad_np; struct fwnode_handle *aad_np;
struct da7219_aad_pdata *aad_pdata; struct da7219_aad_pdata *aad_pdata;
@ -634,7 +633,7 @@ static struct da7219_aad_pdata *da7219_aad_fw_to_pdata(struct snd_soc_component
if (fwnode_property_read_u32(aad_np, "dlg,micbias-pulse-lvl", if (fwnode_property_read_u32(aad_np, "dlg,micbias-pulse-lvl",
&fw_val32) >= 0) &fw_val32) >= 0)
aad_pdata->micbias_pulse_lvl = aad_pdata->micbias_pulse_lvl =
da7219_aad_fw_micbias_pulse_lvl(component, fw_val32); da7219_aad_fw_micbias_pulse_lvl(dev, fw_val32);
else else
aad_pdata->micbias_pulse_lvl = DA7219_AAD_MICBIAS_PULSE_LVL_OFF; aad_pdata->micbias_pulse_lvl = DA7219_AAD_MICBIAS_PULSE_LVL_OFF;
@ -643,31 +642,31 @@ static struct da7219_aad_pdata *da7219_aad_fw_to_pdata(struct snd_soc_component
aad_pdata->micbias_pulse_time = fw_val32; aad_pdata->micbias_pulse_time = fw_val32;
if (fwnode_property_read_u32(aad_np, "dlg,btn-cfg", &fw_val32) >= 0) if (fwnode_property_read_u32(aad_np, "dlg,btn-cfg", &fw_val32) >= 0)
aad_pdata->btn_cfg = da7219_aad_fw_btn_cfg(component, fw_val32); aad_pdata->btn_cfg = da7219_aad_fw_btn_cfg(dev, fw_val32);
else else
aad_pdata->btn_cfg = DA7219_AAD_BTN_CFG_10MS; aad_pdata->btn_cfg = DA7219_AAD_BTN_CFG_10MS;
if (fwnode_property_read_u32(aad_np, "dlg,mic-det-thr", &fw_val32) >= 0) if (fwnode_property_read_u32(aad_np, "dlg,mic-det-thr", &fw_val32) >= 0)
aad_pdata->mic_det_thr = aad_pdata->mic_det_thr =
da7219_aad_fw_mic_det_thr(component, fw_val32); da7219_aad_fw_mic_det_thr(dev, fw_val32);
else else
aad_pdata->mic_det_thr = DA7219_AAD_MIC_DET_THR_500_OHMS; aad_pdata->mic_det_thr = DA7219_AAD_MIC_DET_THR_500_OHMS;
if (fwnode_property_read_u32(aad_np, "dlg,jack-ins-deb", &fw_val32) >= 0) if (fwnode_property_read_u32(aad_np, "dlg,jack-ins-deb", &fw_val32) >= 0)
aad_pdata->jack_ins_deb = aad_pdata->jack_ins_deb =
da7219_aad_fw_jack_ins_deb(component, fw_val32); da7219_aad_fw_jack_ins_deb(dev, fw_val32);
else else
aad_pdata->jack_ins_deb = DA7219_AAD_JACK_INS_DEB_20MS; aad_pdata->jack_ins_deb = DA7219_AAD_JACK_INS_DEB_20MS;
if (!fwnode_property_read_string(aad_np, "dlg,jack-det-rate", &fw_str)) if (!fwnode_property_read_string(aad_np, "dlg,jack-det-rate", &fw_str))
aad_pdata->jack_det_rate = aad_pdata->jack_det_rate =
da7219_aad_fw_jack_det_rate(component, fw_str); da7219_aad_fw_jack_det_rate(dev, fw_str);
else else
aad_pdata->jack_det_rate = DA7219_AAD_JACK_DET_RATE_256_512MS; aad_pdata->jack_det_rate = DA7219_AAD_JACK_DET_RATE_256_512MS;
if (fwnode_property_read_u32(aad_np, "dlg,jack-rem-deb", &fw_val32) >= 0) if (fwnode_property_read_u32(aad_np, "dlg,jack-rem-deb", &fw_val32) >= 0)
aad_pdata->jack_rem_deb = aad_pdata->jack_rem_deb =
da7219_aad_fw_jack_rem_deb(component, fw_val32); da7219_aad_fw_jack_rem_deb(dev, fw_val32);
else else
aad_pdata->jack_rem_deb = DA7219_AAD_JACK_REM_DEB_1MS; aad_pdata->jack_rem_deb = DA7219_AAD_JACK_REM_DEB_1MS;
@ -692,13 +691,13 @@ static struct da7219_aad_pdata *da7219_aad_fw_to_pdata(struct snd_soc_component
aad_pdata->c_mic_btn_thr = 0x3E; aad_pdata->c_mic_btn_thr = 0x3E;
if (fwnode_property_read_u32(aad_np, "dlg,btn-avg", &fw_val32) >= 0) if (fwnode_property_read_u32(aad_np, "dlg,btn-avg", &fw_val32) >= 0)
aad_pdata->btn_avg = da7219_aad_fw_btn_avg(component, fw_val32); aad_pdata->btn_avg = da7219_aad_fw_btn_avg(dev, fw_val32);
else else
aad_pdata->btn_avg = DA7219_AAD_BTN_AVG_2; aad_pdata->btn_avg = DA7219_AAD_BTN_AVG_2;
if (fwnode_property_read_u32(aad_np, "dlg,adc-1bit-rpt", &fw_val32) >= 0) if (fwnode_property_read_u32(aad_np, "dlg,adc-1bit-rpt", &fw_val32) >= 0)
aad_pdata->adc_1bit_rpt = aad_pdata->adc_1bit_rpt =
da7219_aad_fw_adc_1bit_rpt(component, fw_val32); da7219_aad_fw_adc_1bit_rpt(dev, fw_val32);
else else
aad_pdata->adc_1bit_rpt = DA7219_AAD_ADC_1BIT_RPT_1; aad_pdata->adc_1bit_rpt = DA7219_AAD_ADC_1BIT_RPT_1;
@ -887,21 +886,13 @@ void da7219_aad_resume(struct snd_soc_component *component)
int da7219_aad_init(struct snd_soc_component *component) int da7219_aad_init(struct snd_soc_component *component)
{ {
struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component); struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component);
struct da7219_aad_priv *da7219_aad; struct da7219_aad_priv *da7219_aad = da7219->aad;
u8 mask[DA7219_AAD_IRQ_REG_MAX]; u8 mask[DA7219_AAD_IRQ_REG_MAX];
int ret; int ret;
da7219_aad = devm_kzalloc(component->dev, sizeof(*da7219_aad), GFP_KERNEL);
if (!da7219_aad)
return -ENOMEM;
da7219->aad = da7219_aad;
da7219_aad->component = component; da7219_aad->component = component;
/* Handle any DT/ACPI/platform data */ /* Handle any DT/ACPI/platform data */
if (da7219->pdata && !da7219->pdata->aad_pdata)
da7219->pdata->aad_pdata = da7219_aad_fw_to_pdata(component);
da7219_aad_handle_pdata(component); da7219_aad_handle_pdata(component);
/* Disable button detection */ /* Disable button detection */
@ -947,6 +938,30 @@ void da7219_aad_exit(struct snd_soc_component *component)
} }
EXPORT_SYMBOL_GPL(da7219_aad_exit); EXPORT_SYMBOL_GPL(da7219_aad_exit);
/*
* AAD related I2C probe handling
*/
int da7219_aad_probe(struct i2c_client *i2c)
{
struct da7219_priv *da7219 = i2c_get_clientdata(i2c);
struct device *dev = &i2c->dev;
struct da7219_aad_priv *da7219_aad;
da7219_aad = devm_kzalloc(dev, sizeof(*da7219_aad), GFP_KERNEL);
if (!da7219_aad)
return -ENOMEM;
da7219->aad = da7219_aad;
/* Retrieve any DT/ACPI/platform data */
if (da7219->pdata && !da7219->pdata->aad_pdata)
da7219->pdata->aad_pdata = da7219_aad_fw_to_pdata(dev);
return 0;
}
EXPORT_SYMBOL_GPL(da7219_aad_probe);
MODULE_DESCRIPTION("ASoC DA7219 AAD Driver"); MODULE_DESCRIPTION("ASoC DA7219 AAD Driver");
MODULE_AUTHOR("Adam Thomson <Adam.Thomson.Opensource@diasemi.com>"); MODULE_AUTHOR("Adam Thomson <Adam.Thomson.Opensource@diasemi.com>");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");

View File

@ -212,4 +212,7 @@ void da7219_aad_resume(struct snd_soc_component *component);
int da7219_aad_init(struct snd_soc_component *component); int da7219_aad_init(struct snd_soc_component *component);
void da7219_aad_exit(struct snd_soc_component *component); void da7219_aad_exit(struct snd_soc_component *component);
/* I2C Probe */
int da7219_aad_probe(struct i2c_client *i2c);
#endif /* __DA7219_AAD_H */ #endif /* __DA7219_AAD_H */

View File

@ -1753,9 +1753,8 @@ static enum da7219_mic_amp_in_sel
} }
} }
static struct da7219_pdata *da7219_fw_to_pdata(struct snd_soc_component *component) static struct da7219_pdata *da7219_fw_to_pdata(struct device *dev)
{ {
struct device *dev = component->dev;
struct da7219_pdata *pdata; struct da7219_pdata *pdata;
const char *of_str; const char *of_str;
u32 of_val32; u32 of_val32;
@ -2291,10 +2290,6 @@ static int da7219_probe(struct snd_soc_component *component)
} }
/* Handle DT/ACPI/Platform data */ /* Handle DT/ACPI/Platform data */
da7219->pdata = dev_get_platdata(component->dev);
if (!da7219->pdata)
da7219->pdata = da7219_fw_to_pdata(component);
da7219_handle_pdata(component); da7219_handle_pdata(component);
/* Check if MCLK provided */ /* Check if MCLK provided */
@ -2571,11 +2566,12 @@ static const struct regmap_config da7219_regmap_config = {
static int da7219_i2c_probe(struct i2c_client *i2c, static int da7219_i2c_probe(struct i2c_client *i2c,
const struct i2c_device_id *id) const struct i2c_device_id *id)
{ {
struct device *dev = &i2c->dev;
struct da7219_priv *da7219; struct da7219_priv *da7219;
unsigned int system_active, system_status; unsigned int system_active, system_status;
int i, ret; int i, ret;
da7219 = devm_kzalloc(&i2c->dev, sizeof(struct da7219_priv), da7219 = devm_kzalloc(dev, sizeof(struct da7219_priv),
GFP_KERNEL); GFP_KERNEL);
if (!da7219) if (!da7219)
return -ENOMEM; return -ENOMEM;
@ -2585,7 +2581,7 @@ static int da7219_i2c_probe(struct i2c_client *i2c,
da7219->regmap = devm_regmap_init_i2c(i2c, &da7219_regmap_config); da7219->regmap = devm_regmap_init_i2c(i2c, &da7219_regmap_config);
if (IS_ERR(da7219->regmap)) { if (IS_ERR(da7219->regmap)) {
ret = PTR_ERR(da7219->regmap); ret = PTR_ERR(da7219->regmap);
dev_err(&i2c->dev, "regmap_init() failed: %d\n", ret); dev_err(dev, "regmap_init() failed: %d\n", ret);
return ret; return ret;
} }
@ -2620,12 +2616,20 @@ static int da7219_i2c_probe(struct i2c_client *i2c,
regcache_cache_bypass(da7219->regmap, false); regcache_cache_bypass(da7219->regmap, false);
ret = devm_snd_soc_register_component(&i2c->dev, /* Retrieve DT/ACPI/Platform data */
&soc_component_dev_da7219, da7219->pdata = dev_get_platdata(dev);
&da7219_dai, 1); if (!da7219->pdata)
da7219->pdata = da7219_fw_to_pdata(dev);
/* AAD */
ret = da7219_aad_probe(i2c);
if (ret)
return ret;
ret = devm_snd_soc_register_component(dev, &soc_component_dev_da7219,
&da7219_dai, 1);
if (ret < 0) { if (ret < 0) {
dev_err(&i2c->dev, "Failed to register da7219 component: %d\n", dev_err(dev, "Failed to register da7219 component: %d\n", ret);
ret);
} }
return ret; return ret;
} }