summaryrefslogtreecommitdiffstats
path: root/firmware/target/arm
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm')
-rw-r--r--firmware/target/arm/imx31/debug-imx31.c26
-rw-r--r--firmware/target/arm/imx31/gigabeat-s/adc-imx31.c103
-rw-r--r--firmware/target/arm/imx31/gigabeat-s/adc-target.h29
-rw-r--r--firmware/target/arm/imx31/gigabeat-s/mc13783-imx31.c40
4 files changed, 145 insertions, 53 deletions
diff --git a/firmware/target/arm/imx31/debug-imx31.c b/firmware/target/arm/imx31/debug-imx31.c
index 7f1c9166d6..94df64b6d7 100644
--- a/firmware/target/arm/imx31/debug-imx31.c
+++ b/firmware/target/arm/imx31/debug-imx31.c
@@ -25,6 +25,7 @@
#include "font.h"
#include "debug-target.h"
#include "mc13783.h"
+#include "adc.h"
bool __dbg_hw_info(void)
{
@@ -47,11 +48,6 @@ bool __dbg_ports(void)
MC13783_RTC_ALARM,
MC13783_RTC_DAY,
MC13783_RTC_DAY_ALARM,
- MC13783_ADC0,
- MC13783_ADC1,
- MC13783_ADC2,
- MC13783_ADC3,
- MC13783_ADC4,
};
static const char *pmic_regnames[ARRAYLEN(pmic_regset)] =
@@ -64,11 +60,6 @@ bool __dbg_ports(void)
"RTC Alarm ",
"RTC Day ",
"RTC Day Al",
- "ADC0 ",
- "ADC1 ",
- "ADC2 ",
- "ADC3 ",
- "ADC4 ",
};
uint32_t pmic_regs[ARRAYLEN(pmic_regset)];
@@ -132,6 +123,21 @@ bool __dbg_ports(void)
lcd_puts(0, line++, buf);
}
+ line++;
+
+ lcd_puts(0, line++, "ADC"); line++;
+
+ for (i = 0; i < NUM_ADC_CHANNELS; i += 4)
+ {
+ snprintf(buf, sizeof(buf),
+ "CH%02d:%04u CH%02d:%04u CH%02d:%04u CH%02d:%04u",
+ i+0, adc_read(i+0),
+ i+1, adc_read(i+1),
+ i+2, adc_read(i+2),
+ i+3, adc_read(i+3));
+ lcd_puts(0, line++, buf);
+ }
+
lcd_update();
if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
return false;
diff --git a/firmware/target/arm/imx31/gigabeat-s/adc-imx31.c b/firmware/target/arm/imx31/gigabeat-s/adc-imx31.c
index 1fd2247ef1..b1b79a7989 100644
--- a/firmware/target/arm/imx31/gigabeat-s/adc-imx31.c
+++ b/firmware/target/arm/imx31/gigabeat-s/adc-imx31.c
@@ -7,7 +7,7 @@
* \/ \/ \/ \/ \/
* $Id$
*
- * Copyright (C) 2006 by Wade Brown
+ * Copyright (C) 2008 by Michael Sevakis
*
* All files in this archive are subject to the GNU General Public License.
* See the file COPYING in the source tree root for full license agreement.
@@ -16,37 +16,96 @@
* KIND, either express or implied.
*
****************************************************************************/
-#include "cpu.h"
+#include "config.h"
+#include "system.h"
+#include "mc13783.h"
#include "adc-target.h"
#include "kernel.h"
-/* prototypes */
-static unsigned short __adc_read(int channel);
-static void adc_tick(void);
-
-void adc_init(void)
+/* Do this so we may read all channels in a single SPI message */
+static const unsigned char reg_array[NUM_ADC_CHANNELS/2] =
{
-}
+ MC13783_ADC2,
+ MC13783_ADC2,
+ MC13783_ADC2,
+ MC13783_ADC2,
+ MC13783_ADC2,
+ MC13783_ADC2,
+ MC13783_ADC2,
+ MC13783_ADC2,
+};
-/* Called to get the recent ADC reading */
-inline unsigned short adc_read(int channel)
+static uint32_t channels[2][NUM_ADC_CHANNELS/2];
+static struct wakeup adc_wake;
+static struct mutex adc_mtx;
+static long last_adc_read[2]; /* One for each input group */
+
+/* Read 10-bit ADC channel */
+unsigned short adc_read(int channel)
{
- (void)channel;
- return 0;
+ uint32_t data;
+ int input_select;
+
+ if ((unsigned)channel >= NUM_ADC_CHANNELS)
+ return ADC_READ_ERROR;
+
+ mutex_lock(&adc_mtx);
+
+ input_select = channel >> 3;
+
+ /* Limit the traffic through here */
+ if (TIME_AFTER(current_tick, last_adc_read[input_select]))
+ {
+ /* Keep enable, start conversion, increment from channel 0,
+ * increment from channel 4 */
+ uint32_t adc1 = MC13783_ADEN | MC13783_ASC | MC13783_ADA1w(0) |
+ MC13783_ADA2w(4);
+
+ if (input_select == 1)
+ adc1 |= MC13783_ADSEL; /* 2nd set of inputs */
+
+ /* Start conversion */
+ mc13783_write(MC13783_ADC1, adc1);
+
+ /* Wait for done signal */
+ wakeup_wait(&adc_wake, TIMEOUT_BLOCK);
+
+ /* Read all 8 channels that are converted - two channels in each
+ * word. */
+ mc13783_read_regset(reg_array, channels[input_select],
+ NUM_ADC_CHANNELS/2);
+
+ last_adc_read[input_select] = current_tick;
+ }
+
+ data = channels[input_select][channel & 7];
+
+ mutex_unlock(&adc_mtx);
+
+ /* Extract the bitfield depending on even or odd channel number */
+ return (channel & 1) ? MC13783_ADD2r(data) : MC13783_ADD1r(data);
}
-/**
- * Read the ADC by polling
- * @param channel The ADC channel to read
- * @return 10bit reading from ADC channel or ADC_READ_ERROR if timeout
- */
-static unsigned short __adc_read(int channel)
+/* Called when conversion is complete */
+void adc_done(void)
{
- (void)channel;
- return 0;
+ wakeup_signal(&adc_wake);
}
-/* add this to the tick so that the ADC converts are done in the background */
-static void adc_tick(void)
+void adc_init(void)
{
+ wakeup_init(&adc_wake);
+ mutex_init(&adc_mtx);
+
+ /* Init so first reads get data */
+ last_adc_read[0] = last_adc_read[1] = current_tick-1;
+
+ /* Enable increment-by-read, thermistor */
+ mc13783_write(MC13783_ADC0, MC13783_ADINC2 | MC13783_ADINC1 |
+ MC13783_RTHEN);
+ /* Enable ADC, set multi-channel mode */
+ mc13783_write(MC13783_ADC1, MC13783_ADEN);
+ /* Enable the ADCDONE interrupt - notifications are dispatched by
+ * event handler. */
+ mc13783_clear(MC13783_INTERRUPT_MASK0, MC13783_ADCDONE);
}
diff --git a/firmware/target/arm/imx31/gigabeat-s/adc-target.h b/firmware/target/arm/imx31/gigabeat-s/adc-target.h
index 8d2beaf320..6b066b0b59 100644
--- a/firmware/target/arm/imx31/gigabeat-s/adc-target.h
+++ b/firmware/target/arm/imx31/gigabeat-s/adc-target.h
@@ -20,18 +20,29 @@
#define _ADC_TARGET_H_
/* only two channels used by the Gigabeat */
-#define NUM_ADC_CHANNELS 2
+#define NUM_ADC_CHANNELS 16
+
+#define ADC_BATTERY 0
+#define ADC_UNKNOWN_1 1
+#define ADC_UNKNOWN_2 2
+#define ADC_UNKNOWN_3 3
+#define ADC_UNKNOWN_4 4
+#define ADC_UNKNOWN_5 5
+#define ADC_UNKNOWN_6 6
+#define ADC_UNKNOWN_7 7
+#define ADC_HPREMOTE 8
+#define ADC_UNKNOWN_9 9
+#define ADC_UNKNOWN_10 10
+#define ADC_UNKNOWN_11 11
+#define ADC_UNKNOWN_12 12
+#define ADC_UNKNOWN_13 13
+#define ADC_UNKNOWN_14 14
+#define ADC_UNKNOWN_15 15
-#define ADC_BATTERY 0
-#define ADC_HPREMOTE 1
-#define ADC_UNKNOWN_3 2
-#define ADC_UNKNOWN_4 3
-#define ADC_UNKNOWN_5 4
-#define ADC_UNKNOWN_6 5
-#define ADC_UNKNOWN_7 6
-#define ADC_UNKNOWN_8 7
#define ADC_UNREG_POWER ADC_BATTERY /* For compatibility */
#define ADC_READ_ERROR 0xFFFF
+void adc_done(void);
+
#endif
diff --git a/firmware/target/arm/imx31/gigabeat-s/mc13783-imx31.c b/firmware/target/arm/imx31/gigabeat-s/mc13783-imx31.c
index fdb214a33d..d62df92ac5 100644
--- a/firmware/target/arm/imx31/gigabeat-s/mc13783-imx31.c
+++ b/firmware/target/arm/imx31/gigabeat-s/mc13783-imx31.c
@@ -26,6 +26,7 @@
#include "power-imx31.h"
#include "button-target.h"
+#include "adc-target.h"
/* This is all based on communicating with the MC13783 PMU which is on
* CSPI2 with the chip select at 0. The LCD controller resides on
@@ -64,17 +65,21 @@ static __attribute__((noreturn)) void mc13783_interrupt_thread(void)
gpio_enable_event(MC13783_GPIO_NUM, MC13783_EVENT_ID);
- /* Check initial states */
+ /* Check initial states for events with a sense bit */
value = mc13783_read(MC13783_INTERRUPT_SENSE0);
set_charger_inserted(value & MC13783_CHGDET);
value = mc13783_read(MC13783_INTERRUPT_SENSE1);
- button_power_set_state((value & MC13783_ON1B) == 0);
- set_headphones_inserted((value & MC13783_ON2B) == 0);
+ button_power_set_state((value & MC13783_ONOFD1) == 0);
+ set_headphones_inserted((value & MC13783_ONOFD2) == 0);
- /* Enable desired PMIC interrupts */
+ pending[0] = pending[1] = 0xffffff;
+ mc13783_write_regset(status_regs, pending, 2);
+
+ /* Enable desired PMIC interrupts - some are unmasked in the drivers that
+ * handle a specific task */
mc13783_clear(MC13783_INTERRUPT_MASK0, MC13783_CHGDET);
- mc13783_clear(MC13783_INTERRUPT_MASK1, MC13783_ON1B | MC13783_ON2B);
+ mc13783_clear(MC13783_INTERRUPT_MASK1, MC13783_ONOFD1 | MC13783_ONOFD2);
while (1)
{
@@ -83,10 +88,16 @@ static __attribute__((noreturn)) void mc13783_interrupt_thread(void)
mc13783_read_regset(status_regs, pending, 2);
mc13783_write_regset(status_regs, pending, 2);
-
if (pending[0])
{
/* Handle ...PENDING0 */
+
+ /* Handle interrupts without a sense bit */
+ if (pending[0] & MC13783_ADCDONE)
+ adc_done();
+
+ /* Handle interrupts that have a sense bit that needs to
+ * be checked */
if (pending[0] & MC13783_CHGDET)
{
value = mc13783_read(MC13783_INTERRUPT_SENSE0);
@@ -96,19 +107,24 @@ static __attribute__((noreturn)) void mc13783_interrupt_thread(void)
}
}
-
if (pending[1])
{
/* Handle ...PENDING1 */
- if (pending[1] & (MC13783_ON1B | MC13783_ON2B))
+
+ /* Handle interrupts without a sense bit */
+ /* ... */
+
+ /* Handle interrupts that have a sense bit that needs to
+ * be checked */
+ if (pending[1] & (MC13783_ONOFD1 | MC13783_ONOFD2))
{
value = mc13783_read(MC13783_INTERRUPT_SENSE1);
- if (pending[1] & MC13783_ON1B)
- button_power_set_state((value & MC13783_ON1B) == 0);
+ if (pending[1] & MC13783_ONOFD1)
+ button_power_set_state((value & MC13783_ONOFD1) == 0);
- if (pending[1] & MC13783_ON2B)
- set_headphones_inserted((value & MC13783_ON2B) == 0);
+ if (pending[1] & MC13783_ONOFD2)
+ set_headphones_inserted((value & MC13783_ONOFD2) == 0);
}
}
}