Commit 28f20769 authored by Jeroen Vreeken's avatar Jeroen Vreeken
Browse files

Use averaging if frequency permits.

parent 616aec67
......@@ -113,15 +113,17 @@ int am335x_cm_enable(size_t cm_off)
log_send(LOG_T_DEBUG, "am335x: CM %x: 0x%08x", cm_off, reg);
reg &= AM335X_CM_IDLEST_MASK;
if (reg == AM335X_CM_IDLEST_FUNCTIONAL)
log_send(LOG_T_DEBUG, "am335x: CM %x: functional", cm_off);
log_send(LOG_T_DEBUG, "am335x: CM 0x%x: state: functional", cm_off);
if (reg == AM335X_CM_IDLEST_TRANSITION)
log_send(LOG_T_DEBUG, "am335x: CM %x: transition", cm_off);
log_send(LOG_T_DEBUG, "am335x: CM 0x%x: state: transitining", cm_off);
if (reg == AM335X_CM_IDLEST_IDLE)
log_send(LOG_T_DEBUG, "am335x: CM %x: idle", cm_off);
log_send(LOG_T_DEBUG, "am335x: CM 0x%x: state: idle", cm_off);
if (reg == AM335X_CM_IDLEST_DISABLED)
log_send(LOG_T_DEBUG, "am335x: CM %x: disabled", cm_off);
log_send(LOG_T_DEBUG, "am335x: CM 0x%x: state: disabled", cm_off);
log_send(LOG_T_DEBUG, "am335x: CM %x: enabling", cm_off);
am335x_write32(cm_base, cm_off, AM335X_CM_MODULEMODE_ENABLE);
return 0;
}
......@@ -226,6 +226,11 @@
#define AM335X_ADC_STEPCONFIG_SEL_RFP_SET(x) ((x) << 12)
#define AM335X_ADC_STEPCONFIG_SEL_INP_SET(x) ((x) << 19)
#define AM335X_ADC_STEPCONFIG_SEL_INM_SET(x) ((x) << 15)
#define AM335X_ADC_STEPCONFIG_AVERAGE_1 0x00000000
#define AM335X_ADC_STEPCONFIG_AVERAGE_2 0x00000004
#define AM335X_ADC_STEPCONFIG_AVERAGE_4 0x00000008
#define AM335X_ADC_STEPCONFIG_AVERAGE_8 0x0000000c
#define AM335X_ADC_STEPCONFIG_AVERAGE_16 0x00000010
#define AM335X_ADC_REG_FIFO0COUNT 0x0e4
#define AM335X_ADC_REG_FIFO0THRESHOLD 0x0e8
#define AM335X_ADC_REG_DMA0REQ 0x0ec
......
/*
Copyright Jeroen Vreeken (jeroen@vreeken.net), 2014
Copyright Jeroen Vreeken (jeroen@vreeken.net), 2014, 2015
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -19,6 +19,7 @@
#include "am335x.h"
#include <controller/controller_block.h>
#include <controller/controller_time.h>
#include <log/log.h>
......@@ -112,6 +113,9 @@ static struct controller_block * block_am335x_adc_create(char *name, int argc, v
struct controller_block *adc;
void *base;
uint32_t reg;
double frequency;
int factor;
uint32_t avg;
if (am335x_cm_enable(AM335X_CM_WKUP_ADC_TSC_CLKCTRL)) {
log_send(LOG_T_ERROR, "%s: Enabling module failed", name);
......@@ -136,6 +140,31 @@ static struct controller_block * block_am335x_adc_create(char *name, int argc, v
goto err_rev;
}
if (!(adc = controller_block_alloc("am355x_adc", name, sizeof(struct controller_block_private))))
goto err_alloc;
if (controller_block_outterm_list_init(adc, outterms))
goto err_outterm;
adc->private->base = base;
adc->private->gain[0] = AM335X_ADC_FACTOR;
adc->private->gain[1] = AM335X_ADC_FACTOR;
adc->private->gain[2] = AM335X_ADC_FACTOR;
adc->private->gain[3] = AM335X_ADC_FACTOR;
adc->private->gain[4] = AM335X_ADC_FACTOR;
adc->private->gain[5] = AM335X_ADC_FACTOR;
adc->private->gain[6] = AM335X_ADC_FACTOR;
adc->private->gain[7] = AM335X_ADC_FACTOR;
adc->calculate = adc_calculate;
if (controller_block_param_list_add(adc, params))
goto err_param;
if (controller_block_add(adc))
goto err_add;
am335x_write32(base, AM335X_ADC_REG_CTRL, AM335X_ADC_CTRL_SC_WP_N);
am335x_write32(base, AM335X_ADC_REG_IRQENABLE_CLR,
......@@ -144,6 +173,20 @@ static struct controller_block * block_am335x_adc_create(char *name, int argc, v
am335x_write32(base, AM335X_ADC_REG_DMAENABLE_CLR,
AM335X_ADC_DMAENABLE_CLR_ALL);
frequency = controller_time_frequency_get(adc->time);
factor = 200000 / frequency;
if (factor > 16) {
avg = AM335X_ADC_STEPCONFIG_AVERAGE_16;
} else if (factor > 8) {
avg = AM335X_ADC_STEPCONFIG_AVERAGE_8;
} else if (factor > 4) {
avg = AM335X_ADC_STEPCONFIG_AVERAGE_4;
} else if (factor > 2) {
avg = AM335X_ADC_STEPCONFIG_AVERAGE_2;
} else {
avg = AM335X_ADC_STEPCONFIG_AVERAGE_1;
}
am335x_write32(base, AM335X_ADC_REG_ADC_CLKDIV, 0);
am335x_write32(base, AM335X_ADC_REG_IDLECONFIG, 0);
......@@ -153,56 +196,64 @@ static struct controller_block * block_am335x_adc_create(char *name, int argc, v
AM335X_ADC_STEPCONFIG_SEL_RFP_SET(0) |
AM335X_ADC_STEPCONFIG_SEL_RFM_SET(0) |
AM335X_ADC_STEPCONFIG_SEL_INP_SET(0) |
AM335X_ADC_STEPCONFIG_SEL_INM_SET(8) );
AM335X_ADC_STEPCONFIG_SEL_INM_SET(8) |
avg);
am335x_write32(base, AM335X_ADC_REG_STEPDELAY1, 0);
am335x_write32(base, AM335X_ADC_REG_STEPCONFIG2,
AM335X_ADC_STEPCONFIG_SEL_RFP_SET(0) |
AM335X_ADC_STEPCONFIG_SEL_RFM_SET(0) |
AM335X_ADC_STEPCONFIG_SEL_INP_SET(1) |
AM335X_ADC_STEPCONFIG_SEL_INM_SET(8) );
AM335X_ADC_STEPCONFIG_SEL_INM_SET(8) |
avg);
am335x_write32(base, AM335X_ADC_REG_STEPDELAY2, 0);
am335x_write32(base, AM335X_ADC_REG_STEPCONFIG3,
AM335X_ADC_STEPCONFIG_SEL_RFP_SET(0) |
AM335X_ADC_STEPCONFIG_SEL_RFM_SET(0) |
AM335X_ADC_STEPCONFIG_SEL_INP_SET(2) |
AM335X_ADC_STEPCONFIG_SEL_INM_SET(8) );
AM335X_ADC_STEPCONFIG_SEL_INM_SET(8) |
avg);
am335x_write32(base, AM335X_ADC_REG_STEPDELAY3, 0);
am335x_write32(base, AM335X_ADC_REG_STEPCONFIG4,
AM335X_ADC_STEPCONFIG_SEL_RFP_SET(0) |
AM335X_ADC_STEPCONFIG_SEL_RFM_SET(0) |
AM335X_ADC_STEPCONFIG_SEL_INP_SET(3) |
AM335X_ADC_STEPCONFIG_SEL_INM_SET(8) );
AM335X_ADC_STEPCONFIG_SEL_INM_SET(8) |
avg);
am335x_write32(base, AM335X_ADC_REG_STEPDELAY4, 0);
am335x_write32(base, AM335X_ADC_REG_STEPCONFIG5,
AM335X_ADC_STEPCONFIG_SEL_RFP_SET(0) |
AM335X_ADC_STEPCONFIG_SEL_RFM_SET(0) |
AM335X_ADC_STEPCONFIG_SEL_INP_SET(4) |
AM335X_ADC_STEPCONFIG_SEL_INM_SET(8) );
AM335X_ADC_STEPCONFIG_SEL_INM_SET(8) |
avg);
am335x_write32(base, AM335X_ADC_REG_STEPDELAY5, 0);
am335x_write32(base, AM335X_ADC_REG_STEPCONFIG6,
AM335X_ADC_STEPCONFIG_SEL_RFP_SET(0) |
AM335X_ADC_STEPCONFIG_SEL_RFM_SET(0) |
AM335X_ADC_STEPCONFIG_SEL_INP_SET(5) |
AM335X_ADC_STEPCONFIG_SEL_INM_SET(8) );
AM335X_ADC_STEPCONFIG_SEL_INM_SET(8) |
avg);
am335x_write32(base, AM335X_ADC_REG_STEPDELAY6, 0);
am335x_write32(base, AM335X_ADC_REG_STEPCONFIG7,
AM335X_ADC_STEPCONFIG_SEL_RFP_SET(0) |
AM335X_ADC_STEPCONFIG_SEL_RFM_SET(0) |
AM335X_ADC_STEPCONFIG_SEL_INP_SET(6) |
AM335X_ADC_STEPCONFIG_SEL_INM_SET(8) );
AM335X_ADC_STEPCONFIG_SEL_INM_SET(8) |
avg);
am335x_write32(base, AM335X_ADC_REG_STEPDELAY7, 0);
am335x_write32(base, AM335X_ADC_REG_STEPCONFIG8,
AM335X_ADC_STEPCONFIG_SEL_RFP_SET(0) |
AM335X_ADC_STEPCONFIG_SEL_RFM_SET(0) |
AM335X_ADC_STEPCONFIG_SEL_INP_SET(7) |
AM335X_ADC_STEPCONFIG_SEL_INM_SET(8) );
AM335X_ADC_STEPCONFIG_SEL_INM_SET(8) |
avg);
am335x_write32(base, AM335X_ADC_REG_STEPDELAY8, 0);
am335x_write32(base, AM335X_ADC_REG_CTRL,
......@@ -216,31 +267,6 @@ static struct controller_block * block_am335x_adc_create(char *name, int argc, v
AM335X_ADC_STEPENABLE_STEP5 | AM335X_ADC_STEPENABLE_STEP6 |
AM335X_ADC_STEPENABLE_STEP7 | AM335X_ADC_STEPENABLE_STEP8 );
if (!(adc = controller_block_alloc("am355x_adc", name, sizeof(struct controller_block_private))))
goto err_alloc;
if (controller_block_outterm_list_init(adc, outterms))
goto err_outterm;
adc->private->base = base;
adc->private->gain[0] = AM335X_ADC_FACTOR;
adc->private->gain[1] = AM335X_ADC_FACTOR;
adc->private->gain[2] = AM335X_ADC_FACTOR;
adc->private->gain[3] = AM335X_ADC_FACTOR;
adc->private->gain[4] = AM335X_ADC_FACTOR;
adc->private->gain[5] = AM335X_ADC_FACTOR;
adc->private->gain[6] = AM335X_ADC_FACTOR;
adc->private->gain[7] = AM335X_ADC_FACTOR;
adc->calculate = adc_calculate;
if (controller_block_param_list_add(adc, params))
goto err_param;
if (controller_block_add(adc))
goto err_add;
return adc;
err_add:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment