extcon: arizona: Factor out magic application

We have a very similar sequence doing magic writes in several places
(one of which missed an update to interlock with the CODEC driver) so
factor it out into a function.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
This commit is contained in:
Mark Brown 2013-02-12 13:00:31 +00:00
parent 8bb9660418
commit 03409071ce

View File

@ -100,6 +100,39 @@ static const char *arizona_cable[] = {
NULL,
};
static void arizona_extcon_do_magic(struct arizona_extcon_info *info,
unsigned int magic)
{
struct arizona *arizona = info->arizona;
unsigned int val;
int ret;
mutex_lock(&arizona->dapm->card->dapm_mutex);
ret = regmap_read(arizona->regmap, ARIZONA_OUTPUT_ENABLES_1, &val);
if (ret != 0) {
dev_err(arizona->dev, "Failed to read output enables: %d\n",
ret);
val = 0;
}
if (!(val & (ARIZONA_OUT1L_ENA | ARIZONA_OUT1R_ENA))) {
ret = regmap_update_bits(arizona->regmap, 0x225, 0x4000,
magic);
if (ret != 0)
dev_warn(arizona->dev, "Failed to do magic: %d\n",
ret);
ret = regmap_update_bits(arizona->regmap, 0x226, 0x4000,
magic);
if (ret != 0)
dev_warn(arizona->dev, "Failed to do magic: %d\n",
ret);
}
mutex_unlock(&arizona->dapm->card->dapm_mutex);
}
static void arizona_extcon_set_mode(struct arizona_extcon_info *info, int mode)
{
struct arizona *arizona = info->arizona;
@ -484,7 +517,6 @@ static irqreturn_t arizona_hpdet_irq(int irq, void *data)
struct arizona *arizona = info->arizona;
int id_gpio = arizona->pdata.hpdet_id_gpio;
int report = ARIZONA_CABLE_HEADPHONE;
unsigned int val;
int ret, reading;
mutex_lock(&info->lock);
@ -539,28 +571,7 @@ static irqreturn_t arizona_hpdet_irq(int irq, void *data)
dev_err(arizona->dev, "Failed to report HP/line: %d\n",
ret);
mutex_lock(&arizona->dapm->card->dapm_mutex);
ret = regmap_read(arizona->regmap, ARIZONA_OUTPUT_ENABLES_1, &val);
if (ret != 0) {
dev_err(arizona->dev, "Failed to read output enables: %d\n",
ret);
val = 0;
}
if (!(val & (ARIZONA_OUT1L_ENA | ARIZONA_OUT1R_ENA))) {
ret = regmap_update_bits(arizona->regmap, 0x225, 0x4000, 0);
if (ret != 0)
dev_warn(arizona->dev, "Failed to undo magic: %d\n",
ret);
ret = regmap_update_bits(arizona->regmap, 0x226, 0x4000, 0);
if (ret != 0)
dev_warn(arizona->dev, "Failed to undo magic: %d\n",
ret);
}
mutex_unlock(&arizona->dapm->card->dapm_mutex);
arizona_extcon_do_magic(info, 0);
done:
if (id_gpio)
@ -606,13 +617,7 @@ static void arizona_identify_headphone(struct arizona_extcon_info *info)
if (info->mic)
arizona_stop_mic(info);
ret = regmap_update_bits(arizona->regmap, 0x225, 0x4000, 0x4000);
if (ret != 0)
dev_warn(arizona->dev, "Failed to do magic: %d\n", ret);
ret = regmap_update_bits(arizona->regmap, 0x226, 0x4000, 0x4000);
if (ret != 0)
dev_warn(arizona->dev, "Failed to do magic: %d\n", ret);
arizona_extcon_do_magic(info, 0x4000);
ret = regmap_update_bits(arizona->regmap,
ARIZONA_ACCESSORY_DETECT_MODE_1,
@ -653,7 +658,6 @@ err:
static void arizona_start_hpdet_acc_id(struct arizona_extcon_info *info)
{
struct arizona *arizona = info->arizona;
unsigned int val;
int ret;
dev_dbg(arizona->dev, "Starting identification via HPDET\n");
@ -665,30 +669,7 @@ static void arizona_start_hpdet_acc_id(struct arizona_extcon_info *info)
arizona_extcon_pulse_micbias(info);
mutex_lock(&arizona->dapm->card->dapm_mutex);
ret = regmap_read(arizona->regmap, ARIZONA_OUTPUT_ENABLES_1, &val);
if (ret != 0) {
dev_err(arizona->dev, "Failed to read output enables: %d\n",
ret);
val = 0;
}
if (!(val & (ARIZONA_OUT1L_ENA | ARIZONA_OUT1R_ENA))) {
ret = regmap_update_bits(arizona->regmap, 0x225, 0x4000,
0x4000);
if (ret != 0)
dev_warn(arizona->dev, "Failed to do magic: %d\n",
ret);
ret = regmap_update_bits(arizona->regmap, 0x226, 0x4000,
0x4000);
if (ret != 0)
dev_warn(arizona->dev, "Failed to do magic: %d\n",
ret);
}
mutex_unlock(&arizona->dapm->card->dapm_mutex);
arizona_extcon_do_magic(info, 0x4000);
ret = regmap_update_bits(arizona->regmap,
ARIZONA_ACCESSORY_DETECT_MODE_1,