summaryrefslogtreecommitdiffstats
path: root/firmware/target/arm/imx233
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2014-02-04 00:23:35 +0100
committerAmaury Pouly <amaury.pouly@gmail.com>2014-02-10 23:14:25 +0100
commit0324bf59a8810cadf35d67f71f5ee409834ec4ee (patch)
treea636cb9b3ab6cfd6c0d3c54eb5659294799291a2 /firmware/target/arm/imx233
parent0e0c610df0d3d4044d0b21ddc1752a5dacd7f86e (diff)
downloadrockbox-0324bf59a8810cadf35d67f71f5ee409834ec4ee.tar.gz
rockbox-0324bf59a8810cadf35d67f71f5ee409834ec4ee.tar.bz2
rockbox-0324bf59a8810cadf35d67f71f5ee409834ec4ee.zip
imx233: make button-lradc drive able to handle VDDIO derived values
In most devices, the button ladder is not actually derived from VDDIO but from a constant voltage source, making it very easy to read it. However on some devices like ther ZEN X-Fi Style, the ladder is wired to VDDIO we can be changed so it's crucial that the button driver correctly scales the values wrt VDDIO. Change-Id: Ifc11abe2838fa7d16d0d60ecd96964a8dc5ea6d7
Diffstat (limited to 'firmware/target/arm/imx233')
-rw-r--r--firmware/target/arm/imx233/button-lradc-imx233.c73
-rw-r--r--firmware/target/arm/imx233/button-lradc-imx233.h19
-rw-r--r--firmware/target/arm/imx233/creative-zen/button-target.h11
-rw-r--r--firmware/target/arm/imx233/lradc-imx233.h3
4 files changed, 93 insertions, 13 deletions
diff --git a/firmware/target/arm/imx233/button-lradc-imx233.c b/firmware/target/arm/imx233/button-lradc-imx233.c
index 6bb7f9babe..141281041b 100644
--- a/firmware/target/arm/imx233/button-lradc-imx233.c
+++ b/firmware/target/arm/imx233/button-lradc-imx233.c
@@ -58,6 +58,10 @@
/* delay's delay */
#define DELAY (LRADC_DELAY_FREQ / RATE / SAMPLES)
+#ifdef IMX233_BUTTON_LRADC_VDDIO
+#define HAS_VDDIO
+#endif
+
static int button_delay;
static int button_chan;
static int button_val[2];
@@ -65,9 +69,18 @@ static int button_idx;
static int button_mask;
static int table_size;
static int raw_val;
+#ifdef HAS_VDDIO
+static int vddio_chan;
+static int vddio_val;
+#endif
+static int delay_chan_mask; // trigger channel mask
+static int irq_chan_mask; // triggered channel mask
static int button_find(int val)
{
+#ifdef IMX233_BUTTON_LRADC_VDDIO
+ val = (val * IMX233_BUTTON_LRADC_VDDIO) / vddio_val;
+#endif
// shortcuts
struct imx233_button_lradc_mapping_t *table = imx233_button_lradc_mapping;
/* FIXME use a dichotomy */
@@ -91,18 +104,35 @@ static int button_find(int val)
static void button_lradc_irq(int chan)
{
- (void) chan;
- /* read value, kick channel */
- raw_val = imx233_lradc_read_channel(button_chan) / SAMPLES;
- imx233_lradc_clear_channel(button_chan);
- imx233_lradc_setup_channel(button_chan, true, true, SAMPLES - 1, LRADC_SRC(CHAN));
- imx233_lradc_setup_delay(button_delay, 1 << button_chan, 0, SAMPLES - 1, DELAY);
- imx233_lradc_kick_delay(button_delay);
- /* compute mask, compare to previous one */
- button_val[button_idx] = button_find(raw_val);
- button_idx = 1 - button_idx;
- if(button_val[0] == button_val[1])
- button_mask = button_val[0];
+ /* read value, clear channel */
+#ifdef HAS_VDDIO
+ if(chan == vddio_chan)
+ {
+ vddio_val = imx233_lradc_read_channel(vddio_chan) / SAMPLES;
+ vddio_val *= 2; /* VDDIO channel has internal divider */
+ imx233_lradc_clear_channel(vddio_chan);
+ imx233_lradc_setup_channel(vddio_chan, true, true, SAMPLES - 1, LRADC_SRC_VDDIO);
+ }
+#endif
+ if(chan == button_chan)
+ {
+ raw_val = imx233_lradc_read_channel(button_chan) / SAMPLES;
+ imx233_lradc_clear_channel(button_chan);
+ imx233_lradc_setup_channel(button_chan, true, true, SAMPLES - 1, LRADC_SRC(CHAN));
+ }
+ /* record irq, trigger delay if all IRQs have been fired */
+ irq_chan_mask |= 1 << chan;
+ if(irq_chan_mask == delay_chan_mask)
+ {
+ irq_chan_mask = 0;
+ imx233_lradc_setup_delay(button_delay, delay_chan_mask, 0, SAMPLES - 1, DELAY);
+ imx233_lradc_kick_delay(button_delay);
+ /* compute mask, compare to previous one */
+ button_val[button_idx] = button_find(raw_val);
+ button_idx = 1 - button_idx;
+ if(button_val[0] == button_val[1])
+ button_mask = button_val[0];
+ }
}
void imx233_button_lradc_init(void)
@@ -118,9 +148,19 @@ void imx233_button_lradc_init(void)
if(button_delay < 0)
panicf("Cannot get delay for button-lradc");
imx233_lradc_setup_channel(button_chan, true, true, SAMPLES - 1, LRADC_SRC(CHAN));
- imx233_lradc_setup_delay(button_delay, 1 << button_chan, 0, SAMPLES - 1, DELAY);
imx233_lradc_enable_channel_irq(button_chan, true);
imx233_lradc_set_channel_irq_callback(button_chan, button_lradc_irq);
+ delay_chan_mask = 1 << button_chan;
+#ifdef HAS_VDDIO
+ vddio_chan = imx233_lradc_acquire_channel(LRADC_SRC_VDDIO, TIMEOUT_NOBLOCK);
+ if(vddio_chan < 0)
+ panicf("Cannot get vddio channel for button-lradc");
+ imx233_lradc_setup_channel(vddio_chan, true, true, SAMPLES - 1, LRADC_SRC_VDDIO);
+ imx233_lradc_enable_channel_irq(vddio_chan, true);
+ imx233_lradc_set_channel_irq_callback(vddio_chan, button_lradc_irq);
+ delay_chan_mask |= 1 << vddio_chan;
+#endif
+ imx233_lradc_setup_delay(button_delay, delay_chan_mask, 0, SAMPLES - 1, DELAY);
imx233_lradc_kick_delay(button_delay);
#if defined(HAS_BUTTON_HOLD) && IMX233_BUTTON_LRADC_HOLD_DET == BLH_GPIO
imx233_pinctrl_acquire(BLH_GPIO_BANK, BLH_GPIO_PIN, "button_lradc_hold");
@@ -164,3 +204,10 @@ int imx233_button_lradc_read_raw(void)
{
return raw_val;
}
+
+#ifdef HAS_VDDIO
+int imx233_button_lradc_read_vddio(void)
+{
+ return vddio_val; // the VDDIO channel has an internal divider
+}
+#endif
diff --git a/firmware/target/arm/imx233/button-lradc-imx233.h b/firmware/target/arm/imx233/button-lradc-imx233.h
index eac5517adf..d96823fcdc 100644
--- a/firmware/target/arm/imx233/button-lradc-imx233.h
+++ b/firmware/target/arm/imx233/button-lradc-imx233.h
@@ -30,7 +30,19 @@
* - imx233_button_lradc_mapping: target-defined table of adc values and mapping
* - IMX233_BUTTON_LRADC_CHANNEL: lradc channel to use
* - IMX233_BUTTON_LRADC_HOLD_DET: define hold detection method (ignored if !HAS_BUTTON_HOLD)
+ * - IMX233_BUTTON_LRADC_MODE: define the button lradc mode
*
+ * The LRADC code supports two modes of operations: VDDIO relative or absolute.
+ * In the (default) absolute value mode, the LRADC channel is sampled and its value
+ * is compared to the one in the imx233_button_lradc_mapping table. This is
+ * appropriate when the resistor ladder is derived from a fixed voltage.
+ * In the VDDIO relative mode, the values in imx233_button_lradc_mapping are
+ * the values for a specific value of VDDIO which is given by
+ * IMX233_BUTTON_LRADC_VDDIO. In this mode, the code will also sample VDDIO
+ * and do the following comparison:
+ * lradc_value <=? imx233_button_lradc_mapping[i] * vddio_ref / vddio_value
+ * where vddio_ref is IMX233_BUTTON_LRADC_VDDIO.
+ *
* The available values of IMX233_BUTTON_LRADC_HOLD are:
* - BLH_ADC: detect hold using adc
* - BLH_EXT: target button driver implements imx233_button_lradc_hold() using
@@ -40,6 +52,10 @@
* + BLH_GPIO_PIN: pin in bank
* + BLH_GPIO_INVERTED: define if inverted, default is active high
* + BLH_GPIO_PULLUP: define if pins needs pullup
+ *
+ * WARNING
+ * There must always be entry in imx233_button_lradc_mapping whose value is the steady
+ * value of the channel when no button is pressed, and which maps to no button (.btn = 0)
*/
/* hold detect method */
@@ -74,5 +90,8 @@ int imx233_button_lradc_read(int others);
bool imx233_button_lradc_hold(void);
#endif
int imx233_button_lradc_read_raw(void); // return raw adc value
+#ifdef IMX233_BUTTON_LRADC_VDDIO
+int imx233_button_lradc_read_vddio(void);
+#endif
#endif /* __button_lradc_imx233__ */
diff --git a/firmware/target/arm/imx233/creative-zen/button-target.h b/firmware/target/arm/imx233/creative-zen/button-target.h
index 65521d66e4..e9a3ac5ab7 100644
--- a/firmware/target/arm/imx233/creative-zen/button-target.h
+++ b/firmware/target/arm/imx233/creative-zen/button-target.h
@@ -25,11 +25,22 @@
bool button_debug_screen(void);
+/* HOLD button */
#if !defined(CREATIVE_ZENXFISTYLE)
#define HAS_BUTTON_HOLD
#define IMX233_BUTTON_LRADC_HOLD_DET BLH_ADC
#endif
+/* VDDIO value */
+#if defined(CREATIVE_ZENXFISTYLE)
+#define IMX233_BUTTON_LRADC_VDDIO 3660
+#elif defined(CREATIVE_ZEN)
+#define IMX233_BUTTON_LRADC_VDDIO 3480
+#elif defined(CREATIVE_ZENXFI)
+#define IMX233_BUTTON_LRADC_VDDIO 3500
+#endif
+
+/* LRADC channel */
#if defined(CREATIVE_ZENXFISTYLE)
#define IMX233_BUTTON_LRADC_CHANNEL 2
#else
diff --git a/firmware/target/arm/imx233/lradc-imx233.h b/firmware/target/arm/imx233/lradc-imx233.h
index f274db3520..e7853b97a5 100644
--- a/firmware/target/arm/imx233/lradc-imx233.h
+++ b/firmware/target/arm/imx233/lradc-imx233.h
@@ -65,6 +65,9 @@
/* frequency of the delay counter */
#define LRADC_DELAY_FREQ 2000
+/* maximum value of a sample (without accumulation), defines the precision */
+#define LRADC_MAX_VALUE 4096
+
typedef void (*lradc_irq_fn_t)(int chan);
void imx233_lradc_init(void);