[Gta04-owner] Reliable headset detection with raw values

Paul Kocialkowski contact at paulk.fr
Sun May 18 23:04:31 CEST 2014

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.

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>


Paul Kocialkowski, Replicant developer

Replicant is a fully free Android distribution

Website: http://www.replicant.us/
Redmine: http://redmine.replicant.us/
-------------- 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/20140518/6ce1d297/attachment.asc>

More information about the Gta04-owner mailing list