mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	extcon: arizona: Simplify HPDET based identification
Rather than measuring both HP channels we can simply directly measure the microphone impedance and then rely on MICDET for final confirmation of the presence of a suitable microphone. This improves the overall performance of the identification process. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
This commit is contained in:
		
							parent
							
								
									db924ff5c7
								
							
						
					
					
						commit
						9c2ba270ea
					
				
					 2 changed files with 28 additions and 21 deletions
				
			
		| 
						 | 
					@ -459,7 +459,8 @@ static int arizona_hpdet_read(struct arizona_extcon_info *info)
 | 
				
			||||||
	return val;
 | 
						return val;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int arizona_hpdet_do_id(struct arizona_extcon_info *info, int *reading)
 | 
					static int arizona_hpdet_do_id(struct arizona_extcon_info *info, int *reading,
 | 
				
			||||||
 | 
								       bool *mic)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct arizona *arizona = info->arizona;
 | 
						struct arizona *arizona = info->arizona;
 | 
				
			||||||
	int id_gpio = arizona->pdata.hpdet_id_gpio;
 | 
						int id_gpio = arizona->pdata.hpdet_id_gpio;
 | 
				
			||||||
| 
						 | 
					@ -470,11 +471,9 @@ static int arizona_hpdet_do_id(struct arizona_extcon_info *info, int *reading)
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	if (arizona->pdata.hpdet_acc_id) {
 | 
						if (arizona->pdata.hpdet_acc_id) {
 | 
				
			||||||
		info->hpdet_res[info->num_hpdet_res++] = *reading;
 | 
							info->hpdet_res[info->num_hpdet_res++] = *reading;
 | 
				
			||||||
		info->hpdet_res[info->num_hpdet_res++] = *reading;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		/* Only check the mic directly if we didn't already ID it */
 | 
							/* Only check the mic directly if we didn't already ID it */
 | 
				
			||||||
		if (id_gpio && info->num_hpdet_res == 2 &&
 | 
							if (id_gpio && info->num_hpdet_res == 1) {
 | 
				
			||||||
		    !((info->hpdet_res[0] > info->hpdet_res[1] * 2))) {
 | 
					 | 
				
			||||||
			dev_dbg(arizona->dev, "Measuring mic\n");
 | 
								dev_dbg(arizona->dev, "Measuring mic\n");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			regmap_update_bits(arizona->regmap,
 | 
								regmap_update_bits(arizona->regmap,
 | 
				
			||||||
| 
						 | 
					@ -493,10 +492,8 @@ static int arizona_hpdet_do_id(struct arizona_extcon_info *info, int *reading)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		/* OK, got both.  Now, compare... */
 | 
							/* OK, got both.  Now, compare... */
 | 
				
			||||||
		dev_dbg(arizona->dev, "HPDET measured %d %d %d\n",
 | 
							dev_dbg(arizona->dev, "HPDET measured %d %d\n",
 | 
				
			||||||
			info->hpdet_res[0], info->hpdet_res[1],
 | 
								info->hpdet_res[0], info->hpdet_res[1]);
 | 
				
			||||||
			info->hpdet_res[2]);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		/* Take the headphone impedance for the main report */
 | 
							/* Take the headphone impedance for the main report */
 | 
				
			||||||
		*reading = info->hpdet_res[0];
 | 
							*reading = info->hpdet_res[0];
 | 
				
			||||||
| 
						 | 
					@ -512,13 +509,11 @@ static int arizona_hpdet_do_id(struct arizona_extcon_info *info, int *reading)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		/*
 | 
							/*
 | 
				
			||||||
		 * Either the two grounds measure differently or we
 | 
							 * If we measure the mic as 
 | 
				
			||||||
		 * measure the mic as high impedance.
 | 
					 | 
				
			||||||
		 */
 | 
							 */
 | 
				
			||||||
		if ((info->hpdet_res[0] > info->hpdet_res[1] * 2) ||
 | 
							if (!id_gpio || info->hpdet_res[1] > 50) {
 | 
				
			||||||
		    (id_gpio && info->hpdet_res[2] > 1257)) {
 | 
					 | 
				
			||||||
			dev_dbg(arizona->dev, "Detected mic\n");
 | 
								dev_dbg(arizona->dev, "Detected mic\n");
 | 
				
			||||||
			info->mic = true;
 | 
								*mic = true;
 | 
				
			||||||
			info->detecting = true;
 | 
								info->detecting = true;
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			dev_dbg(arizona->dev, "Detected headphone\n");
 | 
								dev_dbg(arizona->dev, "Detected headphone\n");
 | 
				
			||||||
| 
						 | 
					@ -541,6 +536,7 @@ static irqreturn_t arizona_hpdet_irq(int irq, void *data)
 | 
				
			||||||
	int id_gpio = arizona->pdata.hpdet_id_gpio;
 | 
						int id_gpio = arizona->pdata.hpdet_id_gpio;
 | 
				
			||||||
	int report = ARIZONA_CABLE_HEADPHONE;
 | 
						int report = ARIZONA_CABLE_HEADPHONE;
 | 
				
			||||||
	int ret, reading;
 | 
						int ret, reading;
 | 
				
			||||||
 | 
						bool mic = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	mutex_lock(&info->lock);
 | 
						mutex_lock(&info->lock);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -576,7 +572,7 @@ static irqreturn_t arizona_hpdet_irq(int irq, void *data)
 | 
				
			||||||
			   ARIZONA_HP_IMPEDANCE_RANGE_MASK | ARIZONA_HP_POLL,
 | 
								   ARIZONA_HP_IMPEDANCE_RANGE_MASK | ARIZONA_HP_POLL,
 | 
				
			||||||
			   0);
 | 
								   0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ret = arizona_hpdet_do_id(info, &reading);
 | 
						ret = arizona_hpdet_do_id(info, &reading, &mic);
 | 
				
			||||||
	if (ret == -EAGAIN) {
 | 
						if (ret == -EAGAIN) {
 | 
				
			||||||
		goto out;
 | 
							goto out;
 | 
				
			||||||
	} else if (ret < 0) {
 | 
						} else if (ret < 0) {
 | 
				
			||||||
| 
						 | 
					@ -606,7 +602,7 @@ static irqreturn_t arizona_hpdet_irq(int irq, void *data)
 | 
				
			||||||
			   ARIZONA_ACCDET_MODE_MASK, ARIZONA_ACCDET_MODE_MIC);
 | 
								   ARIZONA_ACCDET_MODE_MASK, ARIZONA_ACCDET_MODE_MIC);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* If we have a mic then reenable MICDET */
 | 
						/* If we have a mic then reenable MICDET */
 | 
				
			||||||
	if (info->mic)
 | 
						if (mic || info->mic)
 | 
				
			||||||
		arizona_start_mic(info);
 | 
							arizona_start_mic(info);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (info->hpdet_active) {
 | 
						if (info->hpdet_active) {
 | 
				
			||||||
| 
						 | 
					@ -681,6 +677,8 @@ static void arizona_identify_headphone(struct arizona_extcon_info *info)
 | 
				
			||||||
static void arizona_start_hpdet_acc_id(struct arizona_extcon_info *info)
 | 
					static void arizona_start_hpdet_acc_id(struct arizona_extcon_info *info)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct arizona *arizona = info->arizona;
 | 
						struct arizona *arizona = info->arizona;
 | 
				
			||||||
 | 
						int hp_reading = 32;
 | 
				
			||||||
 | 
						bool mic;
 | 
				
			||||||
	int ret;
 | 
						int ret;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	dev_dbg(arizona->dev, "Starting identification via HPDET\n");
 | 
						dev_dbg(arizona->dev, "Starting identification via HPDET\n");
 | 
				
			||||||
| 
						 | 
					@ -702,12 +700,18 @@ static void arizona_start_hpdet_acc_id(struct arizona_extcon_info *info)
 | 
				
			||||||
		goto err;
 | 
							goto err;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ret = regmap_update_bits(arizona->regmap, ARIZONA_HEADPHONE_DETECT_1,
 | 
						if (arizona->pdata.hpdet_acc_id_line) {
 | 
				
			||||||
				 ARIZONA_HP_POLL, ARIZONA_HP_POLL);
 | 
							ret = regmap_update_bits(arizona->regmap,
 | 
				
			||||||
	if (ret != 0) {
 | 
										 ARIZONA_HEADPHONE_DETECT_1,
 | 
				
			||||||
		dev_err(arizona->dev, "Can't start HPDETL measurement: %d\n",
 | 
										 ARIZONA_HP_POLL, ARIZONA_HP_POLL);
 | 
				
			||||||
			ret);
 | 
							if (ret != 0) {
 | 
				
			||||||
		goto err;
 | 
								dev_err(arizona->dev,
 | 
				
			||||||
 | 
									"Can't start HPDETL measurement: %d\n",
 | 
				
			||||||
 | 
									ret);
 | 
				
			||||||
 | 
								goto err;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							arizona_hpdet_do_id(info, &hp_reading, &mic);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return;
 | 
						return;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -128,6 +128,9 @@ struct arizona_pdata {
 | 
				
			||||||
	/** Use the headphone detect circuit to identify the accessory */
 | 
						/** Use the headphone detect circuit to identify the accessory */
 | 
				
			||||||
	bool hpdet_acc_id;
 | 
						bool hpdet_acc_id;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/** Check for line output with HPDET method */
 | 
				
			||||||
 | 
						bool hpdet_acc_id_line;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/** GPIO used for mic isolation with HPDET */
 | 
						/** GPIO used for mic isolation with HPDET */
 | 
				
			||||||
	int hpdet_id_gpio;
 | 
						int hpdet_id_gpio;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue