Quantcast

twl4030_madc low read value

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

twl4030_madc low read value

Michael Lindemuth
This post was updated on .
Have an Overo Fire FE running the following kernel built with Yocto:
Linux <hostname> 3.5.0 #1 PREEMPT Tue Dec 18 02:25:50 EST 2012 armv7l GNU/Linux

For some reason the ADC channel 3 is returning a strange value:
# cat /sys/class/hwmon/hwmon0/device/in3_input
26

This is supposed to be the mV value read on pin 3 of ADC.  We have checked the value of the Tobi headers for this channel and it is around 2000 mV.  Any ideas on why we are reading such a low value?  

Let me know if you need any more information to help diagnose this issue.

Thank You!
Michael
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: twl4030_madc read errors

Frank Agius
On 4/11/2013 3:15 PM, Michael Lindemuth wrote:

> Have an Overo Fire FE running the following kernel built with Yocto:
> Linux <hostname> 3.5.0 #1 PREEMPT Tue Dec 18 02:25:50 EST 2012 armv7l
> GNU/Linux
>
> For some reason the ADC channel 3 is returning a strange value:
> # cat /sys/class/hwmon/hwmon0/device/in3_input
> 26
>
> This is supposed to be the mV value read on pin 3 of ADC.  We have checked
> the value of the Tobi headers for this channel and it is around 2000 mV.
> Any ideas on why we are reading such a low value?
>
> Let me know if you need any more information to help diagnose this issue.

Do you have anything connected to the USB otg port when you read the
ADC?  If no, then plug something into that port and then re-read your
ADC.  If you now get the expected value, then your problem is as follows:

If nothing is connected to the USB OTG port, the phy suspension code is
called.  In the chain of calls that follows, the vusb3v1 regulator is
disabled. However, according to the OMAP power management manual,
vusb3v1 is used "to bias the analog multiplexers on the four MCPC pins
between the carkit and the MADC". I've seen if there is no bias on this
mux, the MADC driver returns incorrect counts on these 4 pins that
should be in A/D mode.  If I plug something into the USB OTG port, the
MADC driver returns the expected counts.  I also created a debug version
of the twl4030-usb driver, with the disabling of the vusb3v1 commented
out and  the MADC returns the correct counts regardless of the state of
the USB OTG port. Since the vusb3v1 regulator is required for the proper
operation of the mux and by extension the MADC and carkit mode, I
believe that the vusb3v1 regulator should never be disabled.

frank agius


>
> Thank You!
> Michael
>
>
>
> --
> View this message in context: http://gumstix.8.x6.nabble.com/twl4030-madc-read-errors-tp4967139.html
> Sent from the Gumstix mailing list archive at Nabble.com.
>
> ------------------------------------------------------------------------------
> Precog is a next-generation analytics platform capable of advanced
> analytics on semi-structured data. The platform includes APIs for building
> apps and a phenomenal toolset for data science. Developers can use
> our toolset for easy data analysis & visualization. Get a free account!
> http://www2.precog.com/precogplatform/slashdotnewsletter
>



------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
gumstix-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gumstix-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: twl4030_madc low read value

pg0h
In reply to this post by Michael Lindemuth
I was having this problem for ADCIN3-6 a couple of weeks ago and this is what I found to sort out the issue:

http://gumstix.8.x6.nabble.com/using-ADCIN-on-3-0-kernel-no-readings-for-ADC3-6-td640585.html

Since the post, I've had to change the code in static void twl4030_phy_power(struct twl4030_usb *twl, int on)

to set the TWL4030_USB_CARKIT_ANA_CTRL register, everytime (whether on-or off). I have yet to find a better fix for this problem.

However, what this does is I can get proper readings on ADCIN3-6 with USB OTG working properly, where previously I was not able to use ADCIN3-6 while a OTG cable was plugged in, or in my case if g_ether was being used.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: twl4030_madc low read value

the suicidal eggroll
In reply to this post by Michael Lindemuth
Or perhaps your system is like mine, and ADC 3-6 don't work whether or not anything is plugged into the USB OTG port, and none of the posted patches have fixed it.

I'm still looking into the cause on my system.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: twl4030_madc low read value

Michael Lindemuth
Frank and pg0h are correct.  For anyone using the release version of Yocto builds here is the output of a patch between the older and new version of twl4030-usb.c that works:

<pre>
--- /home/developer/yocto/build/tmp/work/overo-poky-linux-gnueabi/linux-sakoman-3.5-r0/git/drivers/usb/otg/twl4030-usb.c.old 2013-04-16 11:33:03.567297626 -0400
+++ /home/developer/yocto/build/tmp/work/overo-poky-linux-gnueabi/linux-sakoman-3.5-r0/git/drivers/usb/otg/twl4030-usb.c 2013-04-15 10:12:05.810409845 -0400
@@ -143,6 +143,10 @@
 #define PMBR1 0x0D
 #define GPIO_USB_4PIN_ULPI_2430C (3 << 0)
 
+/*Added to try and deal with ADCIN3-6 read problem*/
+#define TWL4030_USB_SEL_MADC_MCPC     (1<<3)
+#define TWL4030_USB_CARKIT_ANA_CTRL   0xBB
+
 struct twl4030_usb {
  struct usb_phy phy;
  struct device *dev;
@@ -393,6 +397,11 @@
  regulator_disable(twl->usb1v8);
  regulator_disable(twl->usb3v1);
  }
+
+    /* Ensure that ADCIN3-6 are enabled as per TPS65950 manual */
+    twl4030_usb_write(twl, TWL4030_USB_CARKIT_ANA_CTRL,
+                twl4030_usb_read(twl, TWL4030_USB_CARKIT_ANA_CTRL) |
+                    TWL4030_USB_SEL_MADC_MCPC);
 }
 
 static void twl4030_phy_suspend(struct twl4030_usb *twl, int controller_off)
</pre>

Download the patch here:
twl4030-usb.c-ADC3-6Fix.patch

Hope this Helps!
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: twl4030_madc low read value

the suicidal eggroll
Michael Lindemuth and Frank Agius's suggestions fixed my system as well.

With no mods to the OpenEmbedded omap3-console-image 3.2 kernel, ADC 3-6 would read noise if the USB OTG port was disconnected, and they would all read around 12mV regardless of what was being fed to them if the USB OTG port was connected.

After applying Michael Lindemuth's patch, ADC 3-6 would track the input voltage, but always read about 10% low if the USB OTG port was disconnected, and they would all read perfectly if the USB OTG port was connected.

Adding in Frank Agius's suggestion, ADC 3-6 now read perfectly all the time.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: twl4030_madc low read value

Michael Lindemuth
Thanks for the feedback eggroll.  I forgot to uncomment the regulator_disable line.  Incorporating Frank's suggestion here's the new patch:

<pre>
--- /home/developer/yocto/build/tmp/work/overo-poky-linux-gnueabi/linux-sakoman-3.5-r0/git/drivers/usb/otg/twl4030-usb.c.old 2013-04-16 11:33:03.567297626 -0400
+++ /home/developer/yocto/build/tmp/work/overo-poky-linux-gnueabi/linux-sakoman-3.5-r0/git/drivers/usb/otg/twl4030-usb.c 2013-04-16 15:32:27.366927254 -0400
@@ -143,6 +143,10 @@
 #define PMBR1 0x0D
 #define GPIO_USB_4PIN_ULPI_2430C (3 << 0)
 
+/*Added to try and deal with ADCIN3-6 read problem*/
+#define TWL4030_USB_SEL_MADC_MCPC     (1<<3)
+#define TWL4030_USB_CARKIT_ANA_CTRL   0xBB
+
 struct twl4030_usb {
  struct usb_phy phy;
  struct device *dev;
@@ -391,8 +395,13 @@
  __twl4030_phy_power(twl, 0);
  regulator_disable(twl->usb1v5);
  regulator_disable(twl->usb1v8);
- regulator_disable(twl->usb3v1);
+ // regulator_disable(twl->usb3v1);
  }
+
+    /* Ensure that ADCIN3-6 are enabled as per TPS65950 manual */
+    twl4030_usb_write(twl, TWL4030_USB_CARKIT_ANA_CTRL,
+                twl4030_usb_read(twl, TWL4030_USB_CARKIT_ANA_CTRL) |
+                    TWL4030_USB_SEL_MADC_MCPC);
 }
 
 static void twl4030_phy_suspend(struct twl4030_usb *twl, int controller_off)
</pre>

twl4030-usb.c-ADC3-6Fix.patch
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: twl4030_madc low read value

Michael Lindemuth
In case anyone needs a refresher on how to recompile the kernel and modules after making these changes, here you go:

cd ~/yocto
TEMPLATECONF=meta-gumstix/conf source ./poky/oe-init-build-env
bitbake -c compile -f virtual/kernel
bitbake -c build -f virtual/kernel

Your new image will be in:
~/yocto/build/tmp/deploy/images
Loading...