Commit e8e7ef43 authored by Mark Brown's avatar Mark Brown

Merge series "ASoC: rt5682: apply some refactors" from Tzung-Bi Shih <tzungbi@google.com>:

The series tries to refactor the coding style to follow most conventions.

The 4th patch converts pr_() to dev_().
(https://mailman.alsa-project.org/pipermail/alsa-devel/2020-March/164849.html)

The 6th patch changes the behavior a bit to restore its original intent.

Tzung-Bi Shih (6):
  ASoC: rt5682: simplify assertions
  ASoC: rt5682: fix space issues
  ASoC: rt5682: remove empty default case
  ASoC: rt5682: replace message printing from pr_() to dev_()
  ASoC: rt5682: remove duplicate rt5682_reset() calls
  ASoC: rt5682: remove unwanted btn_type assignment

 sound/soc/codecs/rt5682.c | 198 ++++++++++++++++----------------------
 1 file changed, 84 insertions(+), 114 deletions(-)

--
2.26.2.303.gf8c07b1a785-goog
parents c03d5821 4642126b
...@@ -806,6 +806,7 @@ static void rt5682_reset(struct rt5682_priv *rt5682) ...@@ -806,6 +806,7 @@ static void rt5682_reset(struct rt5682_priv *rt5682)
if (!rt5682->is_sdw) if (!rt5682->is_sdw)
regmap_write(rt5682->regmap, RT5682_I2C_MODE, 1); regmap_write(rt5682->regmap, RT5682_I2C_MODE, 1);
} }
/** /**
* rt5682_sel_asrc_clk_src - select ASRC clock source for a set of filters * rt5682_sel_asrc_clk_src - select ASRC clock source for a set of filters
* @component: SoC audio component device. * @component: SoC audio component device.
...@@ -823,7 +824,6 @@ static void rt5682_reset(struct rt5682_priv *rt5682) ...@@ -823,7 +824,6 @@ static void rt5682_reset(struct rt5682_priv *rt5682)
int rt5682_sel_asrc_clk_src(struct snd_soc_component *component, int rt5682_sel_asrc_clk_src(struct snd_soc_component *component,
unsigned int filter_mask, unsigned int clk_src) unsigned int filter_mask, unsigned int clk_src)
{ {
switch (clk_src) { switch (clk_src) {
case RT5682_CLK_SEL_SYS: case RT5682_CLK_SEL_SYS:
case RT5682_CLK_SEL_I2S1_ASRC: case RT5682_CLK_SEL_I2S1_ASRC:
...@@ -857,7 +857,7 @@ static int rt5682_button_detect(struct snd_soc_component *component) ...@@ -857,7 +857,7 @@ static int rt5682_button_detect(struct snd_soc_component *component)
val = snd_soc_component_read32(component, RT5682_4BTN_IL_CMD_1); val = snd_soc_component_read32(component, RT5682_4BTN_IL_CMD_1);
btn_type = val & 0xfff0; btn_type = val & 0xfff0;
snd_soc_component_write(component, RT5682_4BTN_IL_CMD_1, val); snd_soc_component_write(component, RT5682_4BTN_IL_CMD_1, val);
pr_debug("%s btn_type=%x\n", __func__, btn_type); dev_dbg(component->dev, "%s btn_type=%x\n", __func__, btn_type);
snd_soc_component_update_bits(component, snd_soc_component_update_bits(component,
RT5682_SAR_IL_CMD_2, 0x10, 0x10); RT5682_SAR_IL_CMD_2, 0x10, 0x10);
...@@ -918,7 +918,6 @@ static int rt5682_headset_detect(struct snd_soc_component *component, ...@@ -918,7 +918,6 @@ static int rt5682_headset_detect(struct snd_soc_component *component,
unsigned int val, count; unsigned int val, count;
if (jack_insert) { if (jack_insert) {
snd_soc_component_update_bits(component, RT5682_PWR_ANLG_1, snd_soc_component_update_bits(component, RT5682_PWR_ANLG_1,
RT5682_PWR_VREF2 | RT5682_PWR_MB, RT5682_PWR_VREF2 | RT5682_PWR_MB,
RT5682_PWR_VREF2 | RT5682_PWR_MB); RT5682_PWR_VREF2 | RT5682_PWR_MB);
...@@ -951,8 +950,8 @@ static int rt5682_headset_detect(struct snd_soc_component *component, ...@@ -951,8 +950,8 @@ static int rt5682_headset_detect(struct snd_soc_component *component,
break; break;
default: default:
rt5682->jack_type = SND_JACK_HEADPHONE; rt5682->jack_type = SND_JACK_HEADPHONE;
break;
} }
} else { } else {
rt5682_enable_push_button_irq(component, false); rt5682_enable_push_button_irq(component, false);
snd_soc_component_update_bits(component, RT5682_CBJ_CTRL_1, snd_soc_component_update_bits(component, RT5682_CBJ_CTRL_1,
...@@ -1135,7 +1134,6 @@ static void rt5682_jack_detect_handler(struct work_struct *work) ...@@ -1135,7 +1134,6 @@ static void rt5682_jack_detect_handler(struct work_struct *work)
case 0x0000: /* unpressed */ case 0x0000: /* unpressed */
break; break;
default: default:
btn_type = 0;
dev_err(rt5682->component->dev, dev_err(rt5682->component->dev,
"Unexpected button code 0x%04x\n", "Unexpected button code 0x%04x\n",
btn_type); btn_type);
...@@ -1184,15 +1182,14 @@ static const struct snd_kcontrol_new rt5682_snd_controls[] = { ...@@ -1184,15 +1182,14 @@ static const struct snd_kcontrol_new rt5682_snd_controls[] = {
3, 0, adc_bst_tlv), 3, 0, adc_bst_tlv),
}; };
static int rt5682_div_sel(struct rt5682_priv *rt5682, static int rt5682_div_sel(struct rt5682_priv *rt5682,
int target, const int div[], int size) int target, const int div[], int size)
{ {
int i; int i;
if (rt5682->sysclk < target) { if (rt5682->sysclk < target) {
pr_err("sysclk rate %d is too low\n", dev_err(rt5682->component->dev,
rt5682->sysclk); "sysclk rate %d is too low\n", rt5682->sysclk);
return 0; return 0;
} }
...@@ -1201,18 +1198,18 @@ static int rt5682_div_sel(struct rt5682_priv *rt5682, ...@@ -1201,18 +1198,18 @@ static int rt5682_div_sel(struct rt5682_priv *rt5682,
if (target * div[i] == rt5682->sysclk) if (target * div[i] == rt5682->sysclk)
return i; return i;
if (target * div[i + 1] > rt5682->sysclk) { if (target * div[i + 1] > rt5682->sysclk) {
dev_dbg(rt5682->component->dev, "can't find div for sysclk %d\n", dev_dbg(rt5682->component->dev,
"can't find div for sysclk %d\n",
rt5682->sysclk); rt5682->sysclk);
return i; return i;
} }
} }
if (target * div[i] < rt5682->sysclk) if (target * div[i] < rt5682->sysclk)
pr_err("sysclk rate %d is too high\n", dev_err(rt5682->component->dev,
rt5682->sysclk); "sysclk rate %d is too high\n", rt5682->sysclk);
return size - 1; return size - 1;
} }
/** /**
...@@ -1347,7 +1344,6 @@ static int is_using_asrc(struct snd_soc_dapm_widget *w, ...@@ -1347,7 +1344,6 @@ static int is_using_asrc(struct snd_soc_dapm_widget *w,
default: default:
return 0; return 0;
} }
} }
/* Digital Mixer */ /* Digital Mixer */
...@@ -1532,13 +1528,9 @@ static int rt5682_hp_event(struct snd_soc_dapm_widget *w, ...@@ -1532,13 +1528,9 @@ static int rt5682_hp_event(struct snd_soc_dapm_widget *w,
snd_soc_component_update_bits(component, snd_soc_component_update_bits(component,
RT5682_DAC_ADC_DIG_VOL1, 0x00c0, 0x0000); RT5682_DAC_ADC_DIG_VOL1, 0x00c0, 0x0000);
break; break;
default:
return 0;
} }
return 0; return 0;
} }
static int set_dmic_power(struct snd_soc_dapm_widget *w, static int set_dmic_power(struct snd_soc_dapm_widget *w,
...@@ -1557,9 +1549,6 @@ static int set_dmic_power(struct snd_soc_dapm_widget *w, ...@@ -1557,9 +1549,6 @@ static int set_dmic_power(struct snd_soc_dapm_widget *w,
/*Add delay to avoid pop noise*/ /*Add delay to avoid pop noise*/
msleep(delay); msleep(delay);
break; break;
default:
return 0;
} }
return 0; return 0;
...@@ -1583,9 +1572,6 @@ static int rt5682_set_verf(struct snd_soc_dapm_widget *w, ...@@ -1583,9 +1572,6 @@ static int rt5682_set_verf(struct snd_soc_dapm_widget *w,
snd_soc_component_update_bits(component, snd_soc_component_update_bits(component,
RT5682_PWR_ANLG_1, RT5682_PWR_FV2, 0); RT5682_PWR_ANLG_1, RT5682_PWR_FV2, 0);
break; break;
default:
break;
} }
break; break;
...@@ -1603,14 +1589,8 @@ static int rt5682_set_verf(struct snd_soc_dapm_widget *w, ...@@ -1603,14 +1589,8 @@ static int rt5682_set_verf(struct snd_soc_dapm_widget *w,
RT5682_PWR_ANLG_1, RT5682_PWR_FV2, RT5682_PWR_ANLG_1, RT5682_PWR_FV2,
RT5682_PWR_FV2); RT5682_PWR_FV2);
break; break;
default:
break;
} }
break; break;
default:
return 0;
} }
return 0; return 0;
...@@ -1831,7 +1811,6 @@ static const struct snd_soc_dapm_widget rt5682_dapm_widgets[] = { ...@@ -1831,7 +1811,6 @@ static const struct snd_soc_dapm_widget rt5682_dapm_widgets[] = {
/* Output Lines */ /* Output Lines */
SND_SOC_DAPM_OUTPUT("HPOL"), SND_SOC_DAPM_OUTPUT("HPOL"),
SND_SOC_DAPM_OUTPUT("HPOR"), SND_SOC_DAPM_OUTPUT("HPOR"),
}; };
static const struct snd_soc_dapm_route rt5682_dapm_routes[] = { static const struct snd_soc_dapm_route rt5682_dapm_routes[] = {
...@@ -2065,7 +2044,6 @@ static int rt5682_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask, ...@@ -2065,7 +2044,6 @@ static int rt5682_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask,
return 0; return 0;
} }
static int rt5682_hw_params(struct snd_pcm_substream *substream, static int rt5682_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
{ {
...@@ -2492,8 +2470,7 @@ static int rt5682_set_bias_level(struct snd_soc_component *component, ...@@ -2492,8 +2470,7 @@ static int rt5682_set_bias_level(struct snd_soc_component *component,
regmap_update_bits(rt5682->regmap, RT5682_PWR_ANLG_1, regmap_update_bits(rt5682->regmap, RT5682_PWR_ANLG_1,
RT5682_PWR_BG, 0); RT5682_PWR_BG, 0);
break; break;
case SND_SOC_BIAS_ON:
default:
break; break;
} }
...@@ -2997,8 +2974,8 @@ static int rt5682_sdw_hw_params(struct snd_pcm_substream *substream, ...@@ -2997,8 +2974,8 @@ static int rt5682_sdw_hw_params(struct snd_pcm_substream *substream,
unsigned int val_p = 0, val_c = 0, osr_p = 0, osr_c = 0; unsigned int val_p = 0, val_c = 0, osr_p = 0, osr_c = 0;
dev_dbg(dai->dev, "%s %s", __func__, dai->name); dev_dbg(dai->dev, "%s %s", __func__, dai->name);
stream = snd_soc_dai_get_dma_data(dai, substream);
stream = snd_soc_dai_get_dma_data(dai, substream);
if (!stream) if (!stream)
return -ENOMEM; return -ENOMEM;
...@@ -3296,7 +3273,7 @@ static void rt5682_calibrate(struct rt5682_priv *rt5682) ...@@ -3296,7 +3273,7 @@ static void rt5682_calibrate(struct rt5682_priv *rt5682)
} }
if (count >= 60) if (count >= 60)
pr_err("HP Calibration Failure\n"); dev_err(rt5682->component->dev, "HP Calibration Failure\n");
/* restore settings */ /* restore settings */
regmap_write(rt5682->regmap, RT5682_PWR_ANLG_1, 0x02af); regmap_write(rt5682->regmap, RT5682_PWR_ANLG_1, 0x02af);
...@@ -3308,7 +3285,6 @@ static void rt5682_calibrate(struct rt5682_priv *rt5682) ...@@ -3308,7 +3285,6 @@ static void rt5682_calibrate(struct rt5682_priv *rt5682)
regmap_write(rt5682->regmap, RT5682_STO1_ADC_MIXER, 0xc0c4); regmap_write(rt5682->regmap, RT5682_STO1_ADC_MIXER, 0xc0c4);
mutex_unlock(&rt5682->calibrate_mutex); mutex_unlock(&rt5682->calibrate_mutex);
} }
#if IS_ENABLED(CONFIG_SND_SOC_RT5682_SDW) #if IS_ENABLED(CONFIG_SND_SOC_RT5682_SDW)
...@@ -3416,7 +3392,7 @@ int rt5682_io_init(struct device *dev, struct sdw_slave *slave) ...@@ -3416,7 +3392,7 @@ int rt5682_io_init(struct device *dev, struct sdw_slave *slave)
regmap_read(rt5682->regmap, RT5682_DEVICE_ID, &val); regmap_read(rt5682->regmap, RT5682_DEVICE_ID, &val);
if (val != DEVICE_ID) { if (val != DEVICE_ID) {
pr_err("Device with ID register %x is not rt5682\n", val); dev_err(dev, "Device with ID register %x is not rt5682\n", val);
return -ENODEV; return -ENODEV;
} }
...@@ -3439,8 +3415,6 @@ int rt5682_io_init(struct device *dev, struct sdw_slave *slave) ...@@ -3439,8 +3415,6 @@ int rt5682_io_init(struct device *dev, struct sdw_slave *slave)
pm_runtime_get_noresume(&slave->dev); pm_runtime_get_noresume(&slave->dev);
rt5682_reset(rt5682);
if (rt5682->first_hw_init) { if (rt5682->first_hw_init) {
regcache_cache_only(rt5682->regmap, false); regcache_cache_only(rt5682->regmap, false);
regcache_cache_bypass(rt5682->regmap, true); regcache_cache_bypass(rt5682->regmap, true);
...@@ -3462,7 +3436,7 @@ int rt5682_io_init(struct device *dev, struct sdw_slave *slave) ...@@ -3462,7 +3436,7 @@ int rt5682_io_init(struct device *dev, struct sdw_slave *slave)
ret = regmap_multi_reg_write(rt5682->regmap, patch_list, ret = regmap_multi_reg_write(rt5682->regmap, patch_list,
ARRAY_SIZE(patch_list)); ARRAY_SIZE(patch_list));
if (ret != 0) if (ret)
dev_warn(dev, "Failed to apply regmap patch: %d\n", ret); dev_warn(dev, "Failed to apply regmap patch: %d\n", ret);
regmap_write(rt5682->regmap, RT5682_DEPOP_1, 0x0000); regmap_write(rt5682->regmap, RT5682_DEPOP_1, 0x0000);
...@@ -3536,8 +3510,7 @@ static int rt5682_i2c_probe(struct i2c_client *i2c, ...@@ -3536,8 +3510,7 @@ static int rt5682_i2c_probe(struct i2c_client *i2c,
rt5682 = devm_kzalloc(&i2c->dev, sizeof(struct rt5682_priv), rt5682 = devm_kzalloc(&i2c->dev, sizeof(struct rt5682_priv),
GFP_KERNEL); GFP_KERNEL);
if (!rt5682)
if (rt5682 == NULL)
return -ENOMEM; return -ENOMEM;
i2c_set_clientdata(i2c, rt5682); i2c_set_clientdata(i2c, rt5682);
...@@ -3562,14 +3535,14 @@ static int rt5682_i2c_probe(struct i2c_client *i2c, ...@@ -3562,14 +3535,14 @@ static int rt5682_i2c_probe(struct i2c_client *i2c,
ret = devm_regulator_bulk_get(&i2c->dev, ARRAY_SIZE(rt5682->supplies), ret = devm_regulator_bulk_get(&i2c->dev, ARRAY_SIZE(rt5682->supplies),
rt5682->supplies); rt5682->supplies);
if (ret != 0) { if (ret) {
dev_err(&i2c->dev, "Failed to request supplies: %d\n", ret); dev_err(&i2c->dev, "Failed to request supplies: %d\n", ret);
return ret; return ret;
} }
ret = regulator_bulk_enable(ARRAY_SIZE(rt5682->supplies), ret = regulator_bulk_enable(ARRAY_SIZE(rt5682->supplies),
rt5682->supplies); rt5682->supplies);
if (ret != 0) { if (ret) {
dev_err(&i2c->dev, "Failed to enable supplies: %d\n", ret); dev_err(&i2c->dev, "Failed to enable supplies: %d\n", ret);
return ret; return ret;
} }
...@@ -3588,18 +3561,17 @@ static int rt5682_i2c_probe(struct i2c_client *i2c, ...@@ -3588,18 +3561,17 @@ static int rt5682_i2c_probe(struct i2c_client *i2c,
regmap_read(rt5682->regmap, RT5682_DEVICE_ID, &val); regmap_read(rt5682->regmap, RT5682_DEVICE_ID, &val);
if (val != DEVICE_ID) { if (val != DEVICE_ID) {
pr_err("Device with ID register %x is not rt5682\n", val); dev_err(&i2c->dev,
"Device with ID register %x is not rt5682\n", val);
return -ENODEV; return -ENODEV;
} }
rt5682_reset(rt5682);
mutex_init(&rt5682->calibrate_mutex); mutex_init(&rt5682->calibrate_mutex);
rt5682_calibrate(rt5682); rt5682_calibrate(rt5682);
ret = regmap_multi_reg_write(rt5682->regmap, patch_list, ret = regmap_multi_reg_write(rt5682->regmap, patch_list,
ARRAY_SIZE(patch_list)); ARRAY_SIZE(patch_list));
if (ret != 0) if (ret)
dev_warn(&i2c->dev, "Failed to apply regmap patch: %d\n", ret); dev_warn(&i2c->dev, "Failed to apply regmap patch: %d\n", ret);
regmap_write(rt5682->regmap, RT5682_DEPOP_1, 0x0000); regmap_write(rt5682->regmap, RT5682_DEPOP_1, 0x0000);
...@@ -3665,14 +3637,12 @@ static int rt5682_i2c_probe(struct i2c_client *i2c, ...@@ -3665,14 +3637,12 @@ static int rt5682_i2c_probe(struct i2c_client *i2c,
INIT_DELAYED_WORK(&rt5682->jd_check_work, INIT_DELAYED_WORK(&rt5682->jd_check_work,
rt5682_jd_check_handler); rt5682_jd_check_handler);
if (i2c->irq) { if (i2c->irq) {
ret = devm_request_threaded_irq(&i2c->dev, i2c->irq, NULL, ret = devm_request_threaded_irq(&i2c->dev, i2c->irq, NULL,
rt5682_irq, IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING rt5682_irq, IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING
| IRQF_ONESHOT, "rt5682", rt5682); | IRQF_ONESHOT, "rt5682", rt5682);
if (ret) if (ret)
dev_err(&i2c->dev, "Failed to reguest IRQ: %d\n", ret); dev_err(&i2c->dev, "Failed to reguest IRQ: %d\n", ret);
} }
return devm_snd_soc_register_component(&i2c->dev, return devm_snd_soc_register_component(&i2c->dev,
......
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