[Gta04-owner] Reliable headset detection with raw values

Paul Kocialkowski contact at paulk.fr
Tue May 20 14:49:54 CEST 2014


Le mardi 20 mai 2014 à 07:54 +1000, NeilBrown a écrit :
> On Sun, 18 May 2014 23:04:31 +0200 Paul Kocialkowski <contact at paulk.fr> wrote:
> 
> > In my previous email, commenting on the recent changes I brought to the
> > Replicant 4.2 port, there was a part about headset detection done with
> > better results.
> > 
> > Until this week-end, I was unsure whether this was just an improvement
> > for my own device or was working on any device. I had the occasion to
> > test on another unit, GNUtoo's GTA04A3, both with headphones (no mic)
> > and a headset (mic) and button press. The results are pretty good and
> > detection works flawlessly on both devices.
> > 
> > It's supposed to be reliable because each state has to be detected twice
> > to be reported (headset/headphones detection) as well as button press
> > (for instance, removing headphones seems like a button press, because
> > the pin is shorted to ground for a short time).
> > 
> > The important change to make this work seems to be the use of raw values
> > in the twl4030-madc convert code. I'm guessing that when this isn't
> > used, the twl4030-madc tries to somehow adapt the value to have it
> > matching the actual volts or something like this. I got the idea looking
> > at the Galaxy Nexus's twl6030 madc code, which uses only raw values.
> 
> This doesn't make much sense to me.
> Rather than guessing I looked at the code, and the effect of setting 'raw'
> is to bypass
> 
> 			buf[i] = (buf[i] * 3 * 1000 *
> 				 twl4030_divider_ratios[i].denominator)
> 				/ (2 * 1023 *
> 				twl4030_divider_ratios[i].numerator);
> 
> where 'i' is 7, and twl4030_divider_ratios[7] is
> 
> 	{6, 10},	/* CHANNEL 7 */
> 
> So this becomes
>    buf[i] * 30000 / 12276
> 
> so it rough multiplies the numbers be 2.5.  That shouldn't affect stability
> at all.

Yes, you're perfectly right, I didn't read twl4030_madc_read_channels
completely and just assumed it was changing the range of values in a
dynamic way (for instance, using calibration), but obviously, I was
wrong. It really did seem like it was improving stability (for instance,
I had values that drastically changed from one reboot to the other, like
800 to 400, without raw), but then it was late when I did this and I
jumped to conclusions too fast, without learning about the details.

I'll revert the change in the Replicant 4.2 tree and use thresholds
based on the non-raw values.

> > Using raw values, we get quite similar values on both devices and across
> > reboots and at different points in time. For instance, here are some raw
> > values (ranges)
> > 
> > My GTA04A4:
> > * open: 19-21
> > * headphones (no mic): 338
> > * headset (mic): 177-185
> > * headset button press: 334-335 (very stable)
> > 
> > GNUtoo's GTA04A3:
> > * open: 9-11
> > * headphones (no mic): 344
> > * headset (mic): 170-176
> > * headset button press: 348-353
> > 
> > Hence the values I took for the thresholds:
> > * open/mic (headset): 50
> > * mic (headset)/short (headphones/button): 300
> > 
> > The relevant commits from the Replicant GTA04 kernel[0] tree are the
> > following, perhaps you want to consider adding them to the GNU/Linux
> > kernel tree as well:
> > 
> > commit 6a93c9be394d42c085811b85cefa3284511533a4
> > Author: Paul Kocialkowski <contact at paulk.fr>
> > Date:   Sun May 11 11:51:36 2014 +0200
> > 
> >     gta04-audio: Wait for two consecutive button press values to report
> >     
> >     Signed-off-by: Paul Kocialkowski <contact at paulk.fr>
> > 
> > Mostly, this is because the 50ms polling time is short enough to report
> > a button press when the headset is removed (for a short moment, the
> > detection line is connected to ground before open circuit).
> > 
> > commit bdb7dbfe8039225429584f294233a909daedf69f
> > Author: Paul Kocialkowski <contact at paulk.fr>
> > Date:   Sun May 11 01:33:49 2014 +0200
> > 
> >     gta04-audio: Reliable headphones, headset and button press detection
> >     
> >     Signed-off-by: Paul Kocialkowski <contact at paulk.fr>
> > 
> > This only takes one button, though one can set more precise values for
> > other buttons (volume control on a samsung headset provided reliably
> > stable values, now that the twl4030-madc values are raw, so one could
> > easily report these buttons too).
> > 
> > commit 12f9fdbbccadde55fb6d8441ac2f9744f16f0372
> > Author: Paul Kocialkowski <contact at paulk.fr>
> > Date:   Sun May 11 01:32:53 2014 +0200
> > 
> >     twl4030-madc: Return raw values from twl4030_get_madc_conversion
> >     
> >     Signed-off-by: Paul Kocialkowski <contact at paulk.fr>
> > 
> > [0]:
> > https://gitorious.org/replicant/kernel_goldelico_gta04/source/6a93c9be394d42c085811b85cefa3284511533a4:
> > 
> 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://lists.goldelico.com/pipermail/gta04-owner/attachments/20140520/968e67c3/attachment.asc>


More information about the Gta04-owner mailing list