Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 354962
b: refs/heads/master
c: 1eda6aa
h: refs/heads/master
v: v3
  • Loading branch information
Mark Brown authored and Chanwoo Choi committed Jan 15, 2013
1 parent f78746b commit 954c861
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 6 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: dd235eea4ed75b1599dd9a53bb618fe5befeb731
refs/heads/master: 1eda6aa7ce101b59dfd91abef2c8b0e51e96e199
50 changes: 45 additions & 5 deletions trunk/drivers/extcon/extcon-arizona.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct arizona_extcon_info {
bool hpdet_active;

int num_hpdet_res;
unsigned int hpdet_res[2];
unsigned int hpdet_res[3];

bool mic;
bool detecting;
Expand Down Expand Up @@ -313,6 +313,7 @@ static int arizona_hpdet_read(struct arizona_extcon_info *info)
static int arizona_hpdet_do_id(struct arizona_extcon_info *info, int *reading)
{
struct arizona *arizona = info->arizona;
int id_gpio = arizona->pdata.hpdet_id_gpio;
int ret;

/*
Expand All @@ -338,20 +339,44 @@ static int arizona_hpdet_do_id(struct arizona_extcon_info *info, int *reading)
ARIZONA_ACCESSORY_DETECT_MODE_1,
ARIZONA_ACCDET_SRC,
~info->micd_modes[0].src);

regmap_update_bits(arizona->regmap,
ARIZONA_HEADPHONE_DETECT_1,
ARIZONA_HP_POLL, 0);
ARIZONA_HP_POLL, ARIZONA_HP_POLL);
return -EAGAIN;
}

/* Only check the mic directly if we didn't already ID it */
if (id_gpio && info->num_hpdet_res == 2 &&
!((info->hpdet_res[0] > info->hpdet_res[1] * 2))) {
dev_dbg(arizona->dev, "Measuring mic\n");

regmap_update_bits(arizona->regmap,
ARIZONA_ACCESSORY_DETECT_MODE_1,
ARIZONA_ACCDET_MODE_MASK |
ARIZONA_ACCDET_SRC,
ARIZONA_ACCDET_MODE_HPR |
info->micd_modes[0].src);

gpio_set_value_cansleep(id_gpio, 1);

regmap_update_bits(arizona->regmap,
ARIZONA_HEADPHONE_DETECT_1,
ARIZONA_HP_POLL, ARIZONA_HP_POLL);
return -EAGAIN;
}

/* OK, got both. Now, compare... */
dev_dbg(arizona->dev, "HPDET measured %d %d\n",
info->hpdet_res[0], info->hpdet_res[1]);
dev_dbg(arizona->dev, "HPDET measured %d %d %d\n",
info->hpdet_res[0], info->hpdet_res[1],
info->hpdet_res[2]);

if (info->hpdet_res[0] > info->hpdet_res[1] * 2) {
/*
* Either the two grounds measure differently or we
* measure the mic as high impedance.
*/
if ((info->hpdet_res[0] > info->hpdet_res[1] * 2) ||
(id_gpio && info->hpdet_res[2] > 10)) {
dev_dbg(arizona->dev, "Detected mic\n");
info->mic = true;
ret = extcon_set_cable_state_(&info->edev,
Expand Down Expand Up @@ -382,6 +407,7 @@ static irqreturn_t arizona_hpdet_irq(int irq, void *data)
{
struct arizona_extcon_info *info = data;
struct arizona *arizona = info->arizona;
int id_gpio = arizona->pdata.hpdet_id_gpio;
int report = ARIZONA_CABLE_HEADPHONE;
int ret, reading;

Expand Down Expand Up @@ -446,6 +472,8 @@ static irqreturn_t arizona_hpdet_irq(int irq, void *data)
dev_warn(arizona->dev, "Failed to undo magic: %d\n", ret);

done:
if (id_gpio)
gpio_set_value_cansleep(id_gpio, 0);

/* Revert back to MICDET mode */
regmap_update_bits(arizona->regmap,
Expand Down Expand Up @@ -854,6 +882,18 @@ static int arizona_extcon_probe(struct platform_device *pdev)
}
}

if (arizona->pdata.hpdet_id_gpio > 0) {
ret = devm_gpio_request_one(&pdev->dev,
arizona->pdata.hpdet_id_gpio,
GPIOF_OUT_INIT_LOW,
"HPDET");
if (ret != 0) {
dev_err(arizona->dev, "Failed to request GPIO%d: %d\n",
arizona->pdata.hpdet_id_gpio, ret);
goto err_register;
}
}

if (arizona->pdata.micd_bias_start_time)
regmap_update_bits(arizona->regmap, ARIZONA_MIC_DETECT_1,
ARIZONA_MICD_BIAS_STARTTIME_MASK,
Expand Down
3 changes: 3 additions & 0 deletions trunk/include/linux/mfd/arizona/pdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ struct arizona_pdata {
/** Use the headphone detect circuit to identify the accessory */
bool hpdet_acc_id;

/** GPIO used for mic isolation with HPDET */
int hpdet_id_gpio;

/** GPIO for mic detection polarity */
int micd_pol_gpio;

Expand Down

0 comments on commit 954c861

Please sign in to comment.