Re: Nokia N900 headset detection & MIC Bias + TVOUT
On Monday 09 January 2017 20:38:28 Mark Brown wrote: > On Mon, Jan 09, 2017 at 08:29:53PM +0100, Pali Rohár wrote: > > On Monday 09 January 2017 20:22:01 Mark Brown wrote: > > > point where you need an actual change. Note that if something > > > holds the microphone bias on (like something using the > > > microphone) separately then that'll take effect so if you really > > > need things to get turned off then that won't work but you > > > probably have trouble anyway in that situation. > > > > This is needed for cable/jack detection at time when jack is > > inserted. So before it there cannot be any user of (disconnected) > > microphone. > > That's not going to stop userspace, consider what happens if the > headset gets removed and userspace is slow to stop a recording for > example. Ok. But in this case changing mic bias does not introduce any problems as userspace already trying to record from disconnected microphone. > > What I need is to enable mic bias, measure ADC of some time period, > > check status of some GPIOs. Then disable mic bias, measure ADC > > again and check GPIOs. I in this detection procedure I need to > > ensure that nobody changes mic bias. So I though that locking the > > whole procedure could ensure that. > > That sounds racy and a bit unusual - what's the actual procedure > here? The whole old code for production Nokia N900 devices is there: https://github.com/pali/linux-n900/blob/v2.6.28-nokia/drivers/misc/nokia-av.c If it is usual/unusual/crazy/wtf/:-) I can just tell: it is working fine with that Maemo 2.6.28 production kernel. And there is no documentation for it, just code. So the best what we can do is reimplement that driver for mainline kernel and check if it is working. (Then we can maybe start changing logic if something make sense...). It is more complicated, but basic idea seems to be: Use interrupt handler when jack_detection_gpio changes. When 1 --> jack unplugged (no detection is needed), otherwise plugged and start detection. Start: set eci_sw_gpio to 1, enable mic bias, wait 20msec Detection point 1: if eci0_gpio is 1 then goto Detection point 3 Detection point 2: measure ECI_ADC (thresholds define type) and goto Stop Detection point 3: set eci_sw_gpio to 0, wait 20msec, if eci1_gpio is 1 then goto Stop (open cable was inserted) Detection point 4: set eci_sw_gpio to 1, disable mic bias, measure ECI_ADC until it stabilize (thresholds define type) Stop: set eci_sw_gpio to 1, revert mic bias Thresholds for Detection point 2 are defined as: #define THRESHOLD_GROUNDED 40 // HEADPHONES or line input cable or external mic #define THRESHOLD_VIDEO_HI 150 // VIDEO_CABLE Thresholds for Detection point 4 are defined as: #define THRESHOLD_HEADSET_HI1000// BASIC_HEADSET (probably threshold for basic headset is not correct) The whole procedure is repeated 5-10 times. If open cable is detected then eci_sw_gpio is set to 0 and procedure is periodically repeated after some interval (looking at the code I think that interrupt for eci1_gpio could be used instead of busy waiting). Optionally if nothing (= unknown) after 5-10 times is detected then another procedure for ECI headsets could be used. As Joerg pointed that nokia-av.c code has incorrect detection for ECI it first needs to be investigated. But it will need to disable TVOUT (OMAP3430 TV_OUT1 and TV_VFB1 pins). -- Pali Rohár pali.ro...@gmail.com signature.asc Description: This is a digitally signed message part.
Re: Nokia N900 headset detection & MIC Bias + TVOUT
On Monday 09 January 2017 20:38:28 Mark Brown wrote: > On Mon, Jan 09, 2017 at 08:29:53PM +0100, Pali Rohár wrote: > > On Monday 09 January 2017 20:22:01 Mark Brown wrote: > > > point where you need an actual change. Note that if something > > > holds the microphone bias on (like something using the > > > microphone) separately then that'll take effect so if you really > > > need things to get turned off then that won't work but you > > > probably have trouble anyway in that situation. > > > > This is needed for cable/jack detection at time when jack is > > inserted. So before it there cannot be any user of (disconnected) > > microphone. > > That's not going to stop userspace, consider what happens if the > headset gets removed and userspace is slow to stop a recording for > example. Ok. But in this case changing mic bias does not introduce any problems as userspace already trying to record from disconnected microphone. > > What I need is to enable mic bias, measure ADC of some time period, > > check status of some GPIOs. Then disable mic bias, measure ADC > > again and check GPIOs. I in this detection procedure I need to > > ensure that nobody changes mic bias. So I though that locking the > > whole procedure could ensure that. > > That sounds racy and a bit unusual - what's the actual procedure > here? The whole old code for production Nokia N900 devices is there: https://github.com/pali/linux-n900/blob/v2.6.28-nokia/drivers/misc/nokia-av.c If it is usual/unusual/crazy/wtf/:-) I can just tell: it is working fine with that Maemo 2.6.28 production kernel. And there is no documentation for it, just code. So the best what we can do is reimplement that driver for mainline kernel and check if it is working. (Then we can maybe start changing logic if something make sense...). It is more complicated, but basic idea seems to be: Use interrupt handler when jack_detection_gpio changes. When 1 --> jack unplugged (no detection is needed), otherwise plugged and start detection. Start: set eci_sw_gpio to 1, enable mic bias, wait 20msec Detection point 1: if eci0_gpio is 1 then goto Detection point 3 Detection point 2: measure ECI_ADC (thresholds define type) and goto Stop Detection point 3: set eci_sw_gpio to 0, wait 20msec, if eci1_gpio is 1 then goto Stop (open cable was inserted) Detection point 4: set eci_sw_gpio to 1, disable mic bias, measure ECI_ADC until it stabilize (thresholds define type) Stop: set eci_sw_gpio to 1, revert mic bias Thresholds for Detection point 2 are defined as: #define THRESHOLD_GROUNDED 40 // HEADPHONES or line input cable or external mic #define THRESHOLD_VIDEO_HI 150 // VIDEO_CABLE Thresholds for Detection point 4 are defined as: #define THRESHOLD_HEADSET_HI1000// BASIC_HEADSET (probably threshold for basic headset is not correct) The whole procedure is repeated 5-10 times. If open cable is detected then eci_sw_gpio is set to 0 and procedure is periodically repeated after some interval (looking at the code I think that interrupt for eci1_gpio could be used instead of busy waiting). Optionally if nothing (= unknown) after 5-10 times is detected then another procedure for ECI headsets could be used. As Joerg pointed that nokia-av.c code has incorrect detection for ECI it first needs to be investigated. But it will need to disable TVOUT (OMAP3430 TV_OUT1 and TV_VFB1 pins). -- Pali Rohár pali.ro...@gmail.com signature.asc Description: This is a digitally signed message part.
Re: Nokia N900 headset detection & MIC Bias + TVOUT
On Mon, Jan 09, 2017 at 08:29:53PM +0100, Pali Rohár wrote: > On Monday 09 January 2017 20:22:01 Mark Brown wrote: > > point where you need an actual change. Note that if something holds > > the microphone bias on (like something using the microphone) > > separately then that'll take effect so if you really need things to > > get turned off then that won't work but you probably have trouble > > anyway in that situation. > This is needed for cable/jack detection at time when jack is inserted. > So before it there cannot be any user of (disconnected) microphone. That's not going to stop userspace, consider what happens if the headset gets removed and userspace is slow to stop a recording for example. > What I need is to enable mic bias, measure ADC of some time period, > check status of some GPIOs. Then disable mic bias, measure ADC again and > check GPIOs. I in this detection procedure I need to ensure that nobody > changes mic bias. So I though that locking the whole procedure could > ensure that. That sounds racy and a bit unusual - what's the actual procedure here? signature.asc Description: PGP signature
Re: Nokia N900 headset detection & MIC Bias + TVOUT
On Mon, Jan 09, 2017 at 08:29:53PM +0100, Pali Rohár wrote: > On Monday 09 January 2017 20:22:01 Mark Brown wrote: > > point where you need an actual change. Note that if something holds > > the microphone bias on (like something using the microphone) > > separately then that'll take effect so if you really need things to > > get turned off then that won't work but you probably have trouble > > anyway in that situation. > This is needed for cable/jack detection at time when jack is inserted. > So before it there cannot be any user of (disconnected) microphone. That's not going to stop userspace, consider what happens if the headset gets removed and userspace is slow to stop a recording for example. > What I need is to enable mic bias, measure ADC of some time period, > check status of some GPIOs. Then disable mic bias, measure ADC again and > check GPIOs. I in this detection procedure I need to ensure that nobody > changes mic bias. So I though that locking the whole procedure could > ensure that. That sounds racy and a bit unusual - what's the actual procedure here? signature.asc Description: PGP signature
Re: Nokia N900 headset detection & MIC Bias + TVOUT
On Monday 09 January 2017 20:22:01 Mark Brown wrote: > On Mon, Jan 09, 2017 at 02:13:17PM +0100, Pali Rohár wrote: > > So... can I call snd_soc_dapm_mutex_lock(dapm) at function startup, > > start doing cable detection and when needed call this? > > > > snd_soc_dapm_enable_pin_unlocked(dapm, "HS Mic"); > > snd_soc_dapm_sync_unlocked(dapm); > > > > And at the end of function revert back "HS Mic" pin status and call > > snd_soc_dapm_mutex_unlock(dapm)? > > You shouldn't need to lock I'd expect, and you'll want to sync at any > point where you need an actual change. Note that if something holds > the microphone bias on (like something using the microphone) > separately then that'll take effect so if you really need things to > get turned off then that won't work but you probably have trouble > anyway in that situation. This is needed for cable/jack detection at time when jack is inserted. So before it there cannot be any user of (disconnected) microphone. What I need is to enable mic bias, measure ADC of some time period, check status of some GPIOs. Then disable mic bias, measure ADC again and check GPIOs. I in this detection procedure I need to ensure that nobody changes mic bias. So I though that locking the whole procedure could ensure that. -- Pali Rohár pali.ro...@gmail.com signature.asc Description: This is a digitally signed message part.
Re: Nokia N900 headset detection & MIC Bias + TVOUT
On Monday 09 January 2017 20:22:01 Mark Brown wrote: > On Mon, Jan 09, 2017 at 02:13:17PM +0100, Pali Rohár wrote: > > So... can I call snd_soc_dapm_mutex_lock(dapm) at function startup, > > start doing cable detection and when needed call this? > > > > snd_soc_dapm_enable_pin_unlocked(dapm, "HS Mic"); > > snd_soc_dapm_sync_unlocked(dapm); > > > > And at the end of function revert back "HS Mic" pin status and call > > snd_soc_dapm_mutex_unlock(dapm)? > > You shouldn't need to lock I'd expect, and you'll want to sync at any > point where you need an actual change. Note that if something holds > the microphone bias on (like something using the microphone) > separately then that'll take effect so if you really need things to > get turned off then that won't work but you probably have trouble > anyway in that situation. This is needed for cable/jack detection at time when jack is inserted. So before it there cannot be any user of (disconnected) microphone. What I need is to enable mic bias, measure ADC of some time period, check status of some GPIOs. Then disable mic bias, measure ADC again and check GPIOs. I in this detection procedure I need to ensure that nobody changes mic bias. So I though that locking the whole procedure could ensure that. -- Pali Rohár pali.ro...@gmail.com signature.asc Description: This is a digitally signed message part.
Re: Nokia N900 headset detection & MIC Bias + TVOUT
On Mon, Jan 09, 2017 at 02:13:17PM +0100, Pali Rohár wrote: > So... can I call snd_soc_dapm_mutex_lock(dapm) at function startup, > start doing cable detection and when needed call this? > snd_soc_dapm_enable_pin_unlocked(dapm, "HS Mic"); > snd_soc_dapm_sync_unlocked(dapm); > And at the end of function revert back "HS Mic" pin status and call > snd_soc_dapm_mutex_unlock(dapm)? You shouldn't need to lock I'd expect, and you'll want to sync at any point where you need an actual change. Note that if something holds the microphone bias on (like something using the microphone) separately then that'll take effect so if you really need things to get turned off then that won't work but you probably have trouble anyway in that situation. signature.asc Description: PGP signature
Re: Nokia N900 headset detection & MIC Bias + TVOUT
On Mon, Jan 09, 2017 at 02:13:17PM +0100, Pali Rohár wrote: > So... can I call snd_soc_dapm_mutex_lock(dapm) at function startup, > start doing cable detection and when needed call this? > snd_soc_dapm_enable_pin_unlocked(dapm, "HS Mic"); > snd_soc_dapm_sync_unlocked(dapm); > And at the end of function revert back "HS Mic" pin status and call > snd_soc_dapm_mutex_unlock(dapm)? You shouldn't need to lock I'd expect, and you'll want to sync at any point where you need an actual change. Note that if something holds the microphone bias on (like something using the microphone) separately then that'll take effect so if you really need things to get turned off then that won't work but you probably have trouble anyway in that situation. signature.asc Description: PGP signature
Re: Nokia N900 headset detection & MIC Bias + TVOUT
On Monday 09 January 2017 11:27:49 Mark Brown wrote: > On Sat, Jan 07, 2017 at 12:07:49AM +0100, Pali Rohár wrote: > > > All that is needed in N900 sound driver, file sound/soc/omap/rx51.c. Can > > you help me which functions should I call to enable/disable it > > correctly? In headset detection code I need to be sure that nobody > > (other kernel drivers or userspace via alsamixer) except current > > function could change Bias settings. > > > MIC Bias is controlled by MICBIAS_CTRL in aic34 'B' part codec, file > > tlv320aic3x.c. > > Microphone biases are normally controlled by supply widgets and managed > via DAPM. You can see quite a few examples of this in existing drivers. So... can I call snd_soc_dapm_mutex_lock(dapm) at function startup, start doing cable detection and when needed call this? snd_soc_dapm_enable_pin_unlocked(dapm, "HS Mic"); snd_soc_dapm_sync_unlocked(dapm); And at the end of function revert back "HS Mic" pin status and call snd_soc_dapm_mutex_unlock(dapm)? -- Pali Rohár pali.ro...@gmail.com
Re: Nokia N900 headset detection & MIC Bias + TVOUT
On Monday 09 January 2017 11:27:49 Mark Brown wrote: > On Sat, Jan 07, 2017 at 12:07:49AM +0100, Pali Rohár wrote: > > > All that is needed in N900 sound driver, file sound/soc/omap/rx51.c. Can > > you help me which functions should I call to enable/disable it > > correctly? In headset detection code I need to be sure that nobody > > (other kernel drivers or userspace via alsamixer) except current > > function could change Bias settings. > > > MIC Bias is controlled by MICBIAS_CTRL in aic34 'B' part codec, file > > tlv320aic3x.c. > > Microphone biases are normally controlled by supply widgets and managed > via DAPM. You can see quite a few examples of this in existing drivers. So... can I call snd_soc_dapm_mutex_lock(dapm) at function startup, start doing cable detection and when needed call this? snd_soc_dapm_enable_pin_unlocked(dapm, "HS Mic"); snd_soc_dapm_sync_unlocked(dapm); And at the end of function revert back "HS Mic" pin status and call snd_soc_dapm_mutex_unlock(dapm)? -- Pali Rohár pali.ro...@gmail.com
Re: Nokia N900 headset detection & MIC Bias + TVOUT
On Sat, Jan 07, 2017 at 12:07:49AM +0100, Pali Rohár wrote: > All that is needed in N900 sound driver, file sound/soc/omap/rx51.c. Can > you help me which functions should I call to enable/disable it > correctly? In headset detection code I need to be sure that nobody > (other kernel drivers or userspace via alsamixer) except current > function could change Bias settings. > MIC Bias is controlled by MICBIAS_CTRL in aic34 'B' part codec, file > tlv320aic3x.c. Microphone biases are normally controlled by supply widgets and managed via DAPM. You can see quite a few examples of this in existing drivers. signature.asc Description: PGP signature
Re: Nokia N900 headset detection & MIC Bias + TVOUT
On Sat, Jan 07, 2017 at 12:07:49AM +0100, Pali Rohár wrote: > All that is needed in N900 sound driver, file sound/soc/omap/rx51.c. Can > you help me which functions should I call to enable/disable it > correctly? In headset detection code I need to be sure that nobody > (other kernel drivers or userspace via alsamixer) except current > function could change Bias settings. > MIC Bias is controlled by MICBIAS_CTRL in aic34 'B' part codec, file > tlv320aic3x.c. Microphone biases are normally controlled by supply widgets and managed via DAPM. You can see quite a few examples of this in existing drivers. signature.asc Description: PGP signature
Nokia N900 headset detection & MIC Bias + TVOUT
Hi! For jack cable and headset detection in Nokia N900 I would need to enable/disable MIC Bias and also enable/disable TVOUT output. All that is needed in N900 sound driver, file sound/soc/omap/rx51.c. Can you help me which functions should I call to enable/disable it correctly? In headset detection code I need to be sure that nobody (other kernel drivers or userspace via alsamixer) except current function could change Bias settings. MIC Bias is controlled by MICBIAS_CTRL in aic34 'B' part codec, file tlv320aic3x.c. And according to RX-51 Schematics TVOUT is controlled by OMAP3430 pins: TV_OUT1 and TV_VFB1. I have not found any references to them in kernel, just in omap trm. How is OMAP3430's TV_OUT1 controlled? (Existing code in Maemo 2.6.28 kernel is doing it by big hack - exports function which directly modify MICBIAS_CTRL) -- Pali Rohár pali.ro...@gmail.com signature.asc Description: This is a digitally signed message part.
Nokia N900 headset detection & MIC Bias + TVOUT
Hi! For jack cable and headset detection in Nokia N900 I would need to enable/disable MIC Bias and also enable/disable TVOUT output. All that is needed in N900 sound driver, file sound/soc/omap/rx51.c. Can you help me which functions should I call to enable/disable it correctly? In headset detection code I need to be sure that nobody (other kernel drivers or userspace via alsamixer) except current function could change Bias settings. MIC Bias is controlled by MICBIAS_CTRL in aic34 'B' part codec, file tlv320aic3x.c. And according to RX-51 Schematics TVOUT is controlled by OMAP3430 pins: TV_OUT1 and TV_VFB1. I have not found any references to them in kernel, just in omap trm. How is OMAP3430's TV_OUT1 controlled? (Existing code in Maemo 2.6.28 kernel is doing it by big hack - exports function which directly modify MICBIAS_CTRL) -- Pali Rohár pali.ro...@gmail.com signature.asc Description: This is a digitally signed message part.