[Armadeus-commitlog] armadeus branch, master, updated. latestrelease-160-gb6f655f
Brought to you by:
sszy
|
From: Julien B a. A. <ar...@us...> - 2009-11-23 14:25:10
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "armadeus".
The branch, master has been updated
via b6f655f9991fe3b1582d4b7dd04dafcf4e74ec62 (commit)
via 59b7fceef1b34132bf42b09af9fede390e686514 (commit)
via 27c375d59173ecc067332159cab4e4172b079efe (commit)
from ea401419e5cff42bf2ee9243e4a63e2c8ce3aa9c (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit b6f655f9991fe3b1582d4b7dd04dafcf4e74ec62
Merge: 59b7fceef1b34132bf42b09af9fede390e686514 ea401419e5cff42bf2ee9243e4a63e2c8ce3aa9c
Author: Julien Boibessot <jul...@ar...>
Date: Mon Nov 23 15:24:07 2009 +0100
Merge branch 'master' of ssh://artemys@armadeus.git.sourceforge.net/gitroot/armadeus/armadeus
commit 59b7fceef1b34132bf42b09af9fede390e686514
Author: Julien Boibessot <jul...@ar...>
Date: Mon Nov 23 15:23:36 2009 +0100
[LINUX] Makes /sys/ (slow) mode of the max1027 more reliable + addstatistics entry
commit 27c375d59173ecc067332159cab4e4172b079efe
Author: Julien Boibessot <jul...@ar...>
Date: Fri Nov 20 11:31:22 2009 +0100
Indentation + ^M at the end of lines: please don't use wordpad as text editor ! ;-) (only vim users can understand my pain)
-----------------------------------------------------------------------
Summary of changes:
target/linux/modules/max1027/max1027.c | 277 +++++++++++++++++++++-----------
target/packages/ch7024ctrl/ch7024.c | 236 ++++++++++++++--------------
2 files changed, 299 insertions(+), 214 deletions(-)
diff --git a/target/linux/modules/max1027/max1027.c b/target/linux/modules/max1027/max1027.c
index bfdc9fb..28d2290 100644
--- a/target/linux/modules/max1027/max1027.c
+++ b/target/linux/modules/max1027/max1027.c
@@ -1,5 +1,5 @@
/*
- * Max1027 driver for kernel >= 2.6.23
+ * MAX1027 (ADC) driver for kernel >= 2.6.23
*
* Copyright (C) 2006-2008 Armadeus Project / Armadeus Systems
* Authors: Nicolas Colombain / Julien Boibessot
@@ -20,7 +20,7 @@
*
*/
-// #define DEBUG 1
+/*#define DEBUG 1*/
#include <linux/module.h>
#include <linux/moduleparam.h>
@@ -49,7 +49,7 @@
#define DRIVER_NAME "max1027"
-#define DRIVER_VERSION "0.5"
+#define DRIVER_VERSION "0.6"
/* Internal registers prefixes */
@@ -61,24 +61,22 @@
#define MAX1027_REG_BIPO 0x00
/* register specifics */
-
+#define MAX1027_REG_CONV_SCAN1 (1 << 2)
+#define MAX1027_REG_SETUP_CKSEL1 (1 << 5)
#define GET_SELECTED_CHANNEL(conv) ( (conv & 0x78) >> 3 )
-#define MAX1027_SETUP_DIFFSEL_MASK 0x03
-#define GET_NB_SCAN(avg) ( 4 * ((avg & 0x03)+1) )
-#define MAX1027_RESET_ALL (0x0|MAX1027_REG_RESET)
-#define MAX1027_RESET_FIFO (0x8|MAX1027_REG_RESET)
-#define MAX1027_UNI_UCH(x) ((x&0x0f)<<4)
-#define MAX1027_BIPO_BCH(x) ((x&0x0f)<<4)
-
-#define NB_CHANNELS 8
+#define MAX1027_SETUP_DIFFSEL_MASK 0x03
+#define GET_NB_SCAN(avg) ( 4 * ((avg & 0x03)+1) )
+#define MAX1027_RESET_ALL (0x0|MAX1027_REG_RESET)
+#define MAX1027_RESET_FIFO (0x8|MAX1027_REG_RESET)
+#define MAX1027_UNI_UCH(x) ((x&0x0f)<<4)
+#define MAX1027_BIPO_BCH(x) ((x&0x0f)<<4)
+
+#define NB_CHANNELS 8
#define MAX_RESULTS_PER_CHANNEL 16 /* NSCAN = 11 */
-#define MAX_NB_RESULTS (MAX_RESULTS_PER_CHANNEL+1) /* + temp */
+#define MAX_NB_RESULTS (MAX_RESULTS_PER_CHANNEL+1) /* + temp */
#define FIFO_SIZE 128
-//#undef pr_debug
-//#define pr_debug(fmt, ...) \
-// (printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__))
/* Global variables */
struct max1027_operations *driver_ops;
@@ -120,6 +118,9 @@ struct max1027 {
int cnvst; /* conversion start pin */
struct tasklet_struct tasklet;
+
+ wait_queue_head_t conv_wq; /* stores waiters of end of conv */
+ int missed_eoc; /* stores all missed EOC interrupts */
};
#define CS_CHANGE(val) 0 /* <-- what is it for ??? */
@@ -128,7 +129,9 @@ static struct spi_device *current_spi;
struct spi_transfer transfer[MAX_NB_RESULTS];
struct spi_message message;
-u8 buffer[MAX_NB_RESULTS*2]; // each result is sent with 16 bits
+u8 buffer[MAX_NB_RESULTS*2]; /* each result is sent with 16 bits */
+
+static void max1027_start_conv(struct max1027*, struct adc_channel*);
static void fifo_flush(struct adc_channel* channel)
{
@@ -142,20 +145,20 @@ static u16 fifo_inuse(struct adc_channel* channel)
return channel->head - channel->tail;
}
-static void fifo_put(u16 c, struct adc_channel* channel)
+static void fifo_put(u16 c, struct adc_channel* channel)
{
if (fifo_inuse(channel) != FIFO_SIZE) {
channel->buffer[channel->head++%FIFO_SIZE] = c;
- if(channel->nb_data_required)
+ if (channel->nb_data_required)
channel->nb_data_required--;
- }
- else {
+ } else {
pr_debug("put fifo full %d\n", channel->id);
+ printk("put fifo full %d\n", channel->id);
}
if (channel->nb_data_required <= 0) {
- set_bit( DATA_AVAILABLE, &channel->status );
- wake_up_interruptible( &(channel->change_wq) );
+ set_bit(DATA_AVAILABLE, &channel->status);
+ wake_up_interruptible(&(channel->change_wq));
}
}
@@ -165,22 +168,36 @@ static u16 fifo_get(u16 * c, u16 count, struct adc_channel* channel)
channel->nb_data_required = 0;
j = fifo_inuse(channel);
- for (i = 0; i < min( j, (int)count); i++) {
+ for (i = 0; i < min(j, (int)count); i++) {
c[i] = channel->buffer[channel->tail++%FIFO_SIZE];
}
- channel->nb_data_required = min( count-i, FIFO_SIZE);
+ channel->nb_data_required = min(count-i, FIFO_SIZE);
return i;
}
+static void inline max1027_wait_end_of_conv(struct max1027 *max1027)
+{
+ int delay;
+
+ delay = wait_event_timeout(max1027->conv_wq, max1027->status==0, msecs_to_jiffies(20));
+ if (delay == 0) {
+ printk("T%lu ", max1027->status);
+ if (test_bit(CONVERSION_RUNNING, &max1027->status)) {
+ max1027->missed_eoc++;
+ clear_bit(CONVERSION_RUNNING, &max1027->status);
+ }
+ }
+
+ /*printk("delay %lu\n", delay);*/
+}
+
/* Must be used within mutex and outside of IRQ context !!! */
-static void max1027_send_cmd( struct spi_device *spi, u8 cmd )
+static void max1027_send_cmd(struct spi_device *spi, u8 cmd)
{
u8 buf = cmd;
struct max1027 *p_max1027 = dev_get_drvdata(&spi->dev);
- spi_write_then_read(spi, &buf, 1, NULL, 0);
-
/* !! order is important here !! ;-) */
if (cmd & MAX1027_REG_CONV) {
p_max1027->conv_reg = cmd;
@@ -191,20 +208,34 @@ static void max1027_send_cmd( struct spi_device *spi, u8 cmd )
else if (cmd & MAX1027_REG_AVG) {
p_max1027->avg_reg = cmd;
}
+
+ spi_write_then_read(spi, &buf, 1, NULL, 0);
}
-static void max1027_start_conv(struct max1027 *max1027)
-{
- /* if no convst pin */
- if (max1027->cnvst < 0) {
+static void max1027_start_conv(struct max1027 *max1027, struct adc_channel *channel)
+{
+ if (test_and_set_bit(CONVERSION_RUNNING, &max1027->status)) {
+ printk("conv already running\n");
+ return;
+ }
+
+ /* No conversion running: launch one */
+
+ if (channel)
+ clear_bit(DATA_AVAILABLE, &channel->status);
+ /* Conversion start depends on CNVST pin presence and clock mode */
+ if ((max1027->cnvst < 0) || (max1027->setup_reg & MAX1027_REG_SETUP_CKSEL1)) {
+ /* Use SPI triggered conv. */
max1027_send_cmd(current_spi, max1027->conv_reg);
} else {
- gpio_set_value(max1027->cnvst, 0);
+ /* Use CNVST triggered conv. */
+ gpio_set_value(max1027->cnvst, 0); /* Platform specific no ? */
udelay(1);
gpio_set_value(max1027->cnvst, 1);
}
}
+/* Called when SPI got results from MAX1027 */
static void max1027_process_results(struct max1027 *max1027)
{
u8 msb, lsb;
@@ -212,9 +243,7 @@ static void max1027_process_results(struct max1027 *max1027)
int i=0, values_to_read=0, start=0, nb_data_required=0;
unsigned int scan_mode, selected_channel;
- pr_debug("%s", __FUNCTION__);
-
-// mutex_lock(&max1027->update_lock); // XXX
+ pr_debug("%s: ", __FUNCTION__);
selected_channel = GET_SELECTED_CHANNEL(max1027->conv_reg);
if (selected_channel >= NB_CHANNELS)
@@ -240,12 +269,12 @@ static void max1027_process_results(struct max1027 *max1027)
start = 0;
/* temp */
if (max1027->conv_reg & MAX1027_CONV_TEMP) {
- start = 1;
msb = buffer[0] & 0x0f;
lsb = buffer[1];
value = ((msb << 8) | lsb);
max1027->temperature = (value * 1000) >> 3; /* 1 unit = 1/8 °C + save it in millidegree */
pr_debug("%d m°C ", max1027->temperature);
+ start = 1;
}
nb_data_required = 0;
for (i=start; i<values_to_read; i++) {
@@ -271,14 +300,16 @@ static void max1027_process_results(struct max1027 *max1027)
pr_debug("\n");
if (nb_data_required) {
- max1027_start_conv(max1027);
+ max1027_start_conv(max1027, max1027->channels[selected_channel]);
} else {
- max1027->status = 0;
+ clear_bit(CONVERSION_RUNNING, &max1027->status);
}
-// mutex_unlock(&max1027->update_lock); // XXX
+
+ /* Somebody's waiting for the "global" End Of Conversion ? */
+ wake_up(&(max1027->conv_wq));
}
-static void max1027_reads_async( struct spi_device *spi, int num_values )
+static void max1027_reads_async(struct spi_device *spi, int num_values)
{
int ret, i;
@@ -302,7 +333,7 @@ static void max1027_reads_async( struct spi_device *spi, int num_values )
}
/*
- * Handles read() done on /dev/gpioxx
+ * Handles read() done on /dev/...
*/
static ssize_t max1027_dev_read(struct file *file, char *buf, size_t count, loff_t *ppos)
{
@@ -317,10 +348,8 @@ static ssize_t max1027_dev_read(struct file *file, char *buf, size_t count, loff
pr_debug("- %s %d byte(s) on minor %d -> channel %d\n", __FUNCTION__, count, minor, channel->id);
if (fifo_inuse(channel) == 0) {
- if (! test_and_set_bit( CONVERSION_RUNNING,&max1027->status)) {
- clear_bit( DATA_AVAILABLE, &channel->status );
- max1027_start_conv(max1027);
- }
+ max1027_start_conv(max1027, channel);
+
if (file->f_flags & O_NONBLOCK)
return -EAGAIN;
@@ -343,15 +372,16 @@ out:
return ret;
}
-/* Tasklet to get results after EOC IRQ */
-static void read_conversion_results( unsigned long data )
+/* Tasklet to get results after EOC interrupt */
+static void read_conversion_results(unsigned long data)
{
struct spi_device *spi = (struct spi_device *)data;
struct max1027 *max1027 = dev_get_drvdata(&spi->dev);
int size = 0;
- /* Get conversion results from chip (depends on conversion mode) */
- switch( GET_SCAN_MODE(max1027->conv_reg) )
+ /* Calculate parameters to get conversion results from chip
+ (depends on conversion mode) */
+ switch (GET_SCAN_MODE(max1027->conv_reg))
{
case SCAN_MODE_00:
size = GET_SELECTED_CHANNEL(max1027->conv_reg) + 1;
@@ -375,6 +405,7 @@ static void read_conversion_results( unsigned long data )
break;
}
+ /* Get the results */
if (max1027->conv_reg & MAX1027_CONV_TEMP) {
max1027_reads_async(spi, size+1);
} else {
@@ -386,8 +417,9 @@ static void read_conversion_results( unsigned long data )
static irqreturn_t max1027_interrupt(int irq, void *dev_id)
{
struct max1027 *max1027 = dev_id;
- /* schedule task for reading results from chip outside of IRQ */
- tasklet_hi_schedule( &max1027->tasklet );
+
+ /* schedules task for reading conversion results outside of IRQ */
+ tasklet_hi_schedule(&max1027->tasklet);
return IRQ_HANDLED;
}
@@ -398,7 +430,7 @@ static void max1027_flush_all_channels(struct max1027 *p_max1027)
int i;
for (i=0; i < NB_CHANNELS; i++) {
- if( p_max1027->channels[i] != NULL )
+ if (p_max1027->channels[i] != NULL)
fifo_flush(p_max1027->channels[i]);
}
}
@@ -468,20 +500,42 @@ static struct file_operations max1027_fops = {
/* sysfs hook functions */
+/* Given value will be put in MAX1027 conversion register.
+ Writing to this register will start an acquisition/conversion if
+ clock mode 1x is configured in setup register.
+*/
static ssize_t max1027_set_conversion(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
{
struct spi_device *spi = to_spi_device(dev);
+ struct max1027 *max1027 = dev_get_drvdata(&spi->dev);
int val;
- struct max1027 *p_max1027 = dev_get_drvdata(&spi->dev);
-
- val = (simple_strtol(buf, NULL, 10)) & 0xff;
- pr_debug("%s: 0x%02x\n", __FUNCTION__, val);
- mutex_lock(&p_max1027->update_lock);
+ /* Only 1 conversion can be launched that way at a given time */
+ mutex_lock(&max1027->update_lock);
+
+ val = (simple_strtol(buf, NULL, 10)) & 0xff;
+ pr_debug("\n%s: 0x%02x\n", __FUNCTION__, val);
+ max1027_flush_all_channels(max1027);
+ /* Warn if a conversion is already launched and selected mode will
+ trigger a new one */
+ if ((max1027->setup_reg & MAX1027_REG_SETUP_CKSEL1)) {
+ if (test_and_set_bit(CONVERSION_RUNNING, &max1027->status)) {
+ /* Should not occur !! */
+ printk("%s: conv already running!\n", __func__);
+ }
+ }
+ /* Send value to chip */
max1027_send_cmd(spi, MAX1027_REG_CONV | val);
- max1027_flush_all_channels(p_max1027);
- mutex_unlock(&p_max1027->update_lock);
+
+ /* Wait until current convertion is finished if corresponding clock
+ mode is selected */
+ if ((max1027->setup_reg & MAX1027_REG_SETUP_CKSEL1)) {
+ max1027_wait_end_of_conv(max1027);
+ }
+ pr_debug("%s end\n", __FUNCTION__);
+
+ mutex_unlock(&max1027->update_lock);
return count;
}
@@ -490,36 +544,37 @@ static ssize_t max1027_get_conversion(struct device *dev, struct device_attribut
{
ssize_t ret_size = 0;
struct spi_device *spi = to_spi_device(dev);
- struct max1027 *p_max1027 = dev_get_drvdata(&spi->dev);
+ struct max1027 *max1027 = dev_get_drvdata(&spi->dev);
- ret_size = sprintf(buf,"0x%02x", p_max1027->conv_reg);
+ ret_size = sprintf(buf,"0x%02x", max1027->conv_reg);
return ret_size;
}
-// buf value <256 -> max1027 config register
-// buf value >=256 -> max1027 Unipolar or Bipolar mode registers
+/* buf value <256 -> accesss to "config" register
+ buf value >=256 -> "Unipolar" or "Bipolar" mode registers */
static ssize_t max1027_set_setup(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
{
struct spi_device *spi = to_spi_device(dev);
+ struct max1027 *max1027 = dev_get_drvdata(&spi->dev);
int val;
- struct max1027 *p_max1027 = dev_get_drvdata(&spi->dev);
val = simple_strtol(buf, NULL, 10);
pr_debug("%s: 0x%02x", __FUNCTION__, val);
- mutex_lock(&p_max1027->update_lock);
- max1027_send_cmd( spi, MAX1027_REG_SETUP | (val&0xff) );
+ mutex_lock(&max1027->update_lock);
+ max1027_send_cmd(spi, MAX1027_REG_SETUP | (val&0xff));
/* check whether we need to configure the uni or bipolar mode IOs or not */
- if( ((val&0xff) & MAX1027_SETUP_DIFFSEL_MASK) > MAX1027_SETUP_DIFFSEL(1) ) {
- max1027_send_cmd( spi, val>>8 );
+ if (((val&0xff) & MAX1027_SETUP_DIFFSEL_MASK) > MAX1027_SETUP_DIFFSEL(1)) {
+ max1027_send_cmd(spi, val>>8);
pr_debug("+ 0x%02x", val);
}
- max1027_flush_all_channels(p_max1027);
- mutex_unlock(&p_max1027->update_lock);
+ max1027_flush_all_channels(max1027);
+ mutex_unlock(&max1027->update_lock);
pr_debug("\n");
+
return count;
}
@@ -558,7 +613,7 @@ static ssize_t max1027_get_averaging(struct device *dev, struct device_attribute
struct spi_device *spi = to_spi_device(dev);
struct max1027 *p_max1027 = dev_get_drvdata(&spi->dev);
- ret_size = sprintf(buf,"0x%02x", p_max1027->avg_reg);
+ ret_size = sprintf(buf, "0x%02x", p_max1027->avg_reg);
return ret_size;
}
@@ -570,6 +625,33 @@ static DEVICE_ATTR(averaging, S_IWUSR | S_IRUGO, max1027_get_averaging, max1027
static DEVICE_ATTR(unipolar, S_IWUSR, NULL, max1027_unipolar);
static DEVICE_ATTR(bipolar, S_IWUSR, NULL, max1027_bipolar);*/
+/* For debug: */
+static ssize_t max1027_get_statistics(struct device *dev, struct device_attribute *attr, char *buf)
+{
+ ssize_t ret_size = 0;
+ struct spi_device *spi = to_spi_device(dev);
+ struct max1027 *max1027 = dev_get_drvdata(&spi->dev);
+
+ ret_size = sprintf(buf, "%d", max1027->missed_eoc);
+
+ return ret_size;
+}
+
+static ssize_t max1027_set_statistics(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t count)
+{
+ struct spi_device *spi = to_spi_device(dev);
+ struct max1027 *max1027 = dev_get_drvdata(&spi->dev);
+
+ /* Whatever was given, clear statistics */
+ max1027->missed_eoc = 0;
+
+ return count;
+}
+
+static DEVICE_ATTR(statistics, S_IWUSR | S_IRUGO, max1027_get_statistics, max1027_set_statistics);
+
+/* For channel values: */
#define show_in(offset) \
static ssize_t show_in##offset##_input(struct device *dev, \
struct device_attribute *attr, char *buf) \
@@ -577,9 +659,9 @@ static ssize_t show_in##offset##_input(struct device *dev, \
int result; \
ssize_t size; \
struct spi_device *spi = to_spi_device(dev); \
- struct max1027 *p_max1027 = dev_get_drvdata(&spi->dev); \
- \
- result = p_max1027->ain[offset]; \
+ struct max1027 *max1027 = dev_get_drvdata(&spi->dev); \
+\
+ result = max1027->ain[offset]; \
size = sprintf(buf, "%d\n", (result*2500)>>10); /* millivolt with 2.5V ref */ \
\
return size; \
@@ -603,17 +685,17 @@ static DEVICE_ATTR(in5_input, S_IRUGO, show_in5_input, NULL);
static DEVICE_ATTR(in6_input, S_IRUGO, show_in6_input, NULL);
static DEVICE_ATTR(in7_input, S_IRUGO, show_in7_input, NULL);
-
+/* On chip temperature: */
static ssize_t max1027_get_temperature(struct device *dev,
struct device_attribute *attr, char *buf)
{
int result;
ssize_t size;
struct spi_device *spi = to_spi_device(dev);
- struct max1027 *p_max1027 = dev_get_drvdata(&spi->dev);
+ struct max1027 *max1027 = dev_get_drvdata(&spi->dev);
- result = p_max1027->temperature;
- size = sprintf(buf, "%d\n", result );
+ result = max1027->temperature;
+ size = sprintf(buf, "%d\n", result);
return size;
}
@@ -648,6 +730,11 @@ static int max1027_create_sys_entries(struct spi_device *spi)
goto end;
}
+ if ((status = device_create_file(&spi->dev, &dev_attr_statistics))) {
+ printk(KERN_WARNING SYSFS_ERROR_STRING " missed EOC accessor\n");
+ goto end;
+ }
+
if ((status = device_create_file(&spi->dev, &dev_attr_temp1_input))){
printk(KERN_WARNING SYSFS_ERROR_STRING " temp1\n");
goto end;
@@ -671,6 +758,7 @@ static void max1027_remove_sys_entries(struct spi_device *spi)
device_remove_file(&spi->dev, &dev_attr_conversion);
device_remove_file(&spi->dev, &dev_attr_setup);
device_remove_file(&spi->dev, &dev_attr_averaging);
+ device_remove_file(&spi->dev, &dev_attr_statistics);
device_remove_file(&spi->dev, &dev_attr_temp1_input);
device_remove_file(&spi->dev, &dev_attr_in0_input);
device_remove_file(&spi->dev, &dev_attr_in1_input);
@@ -713,8 +801,6 @@ static int __devinit max1027_probe(struct spi_device *spi)
if (max1027_major == 0)
max1027_major = result; /* dynamic Major allocation */
- //init_waitqueue_head(&max1027->conversion_wq);
-
/* Setup any GPIO active */
result = platform_info->init(spi);
if (result) {
@@ -743,26 +829,28 @@ static int __devinit max1027_probe(struct spi_device *spi)
if (result)
goto err_sys;
- tasklet_init( &max1027->tasklet, read_conversion_results, (unsigned long)spi);
+ tasklet_init(&max1027->tasklet, read_conversion_results, (unsigned long)spi);
max1027->status = 0;
+ init_waitqueue_head(&max1027->conv_wq);
/* setup spi_device */
spi->bits_per_word = 8;
spi_setup(spi);
/* configure the MAX */
- max1027_send_cmd( spi, MAX1027_RESET_ALL );
- max1027_send_cmd( spi, platform_info->setup | MAX1027_REG_SETUP );
- max1027_send_cmd( spi, platform_info->avg | MAX1027_REG_AVG );
- max1027->conv_reg = (u8)(platform_info->conv|MAX1027_REG_CONV);
-
- set_irq_type( spi->irq, IRQF_TRIGGER_FALLING );
- /* Request interrupt for EOC */
- result = request_irq( spi->irq, max1027_interrupt, 0, DRIVER_NAME, max1027 );
+ max1027_send_cmd(spi, MAX1027_RESET_ALL);
+ max1027_send_cmd(spi, platform_info->setup | MAX1027_REG_SETUP);
+ max1027_send_cmd(spi, platform_info->avg | MAX1027_REG_AVG);
+ max1027->conv_reg = (u8)(platform_info->conv | MAX1027_REG_CONV);
+
+ set_irq_type(spi->irq, IRQF_TRIGGER_FALLING); /* machine specific... */
+ /* Request interrupt for EOC */ /* Should be put before GPIO init no ? */
+ result = request_irq(spi->irq, max1027_interrupt, 0, DRIVER_NAME, max1027);
if (result)
goto err_irq;
- printk( DRIVER_NAME " v" DRIVER_VERSION " successfully probed !\n");
+ printk(DRIVER_NAME " v" DRIVER_VERSION " successfully probed !\n");
+
return 0;
err_sys:
@@ -791,26 +879,25 @@ static int __devexit max1027_remove(struct spi_device *spi)
hwmon_device_unregister(max1027->cdev);
#endif
- tasklet_kill( &max1027->tasklet );
+ tasklet_kill(&max1027->tasklet);
/* De-register from /dev interface */
unregister_chrdev(max1027_major, DRIVER_NAME);
free_irq(spi->irq, max1027);
- /* free IOs*/
+ /* Free GPIOs*/
platform_info->exit(spi);
dev_set_drvdata(&spi->dev, NULL);
for (i=0; i < NB_CHANNELS; i++) {
- kfree( max1027->channels[i] );
+ kfree(max1027->channels[i]);
}
kfree(max1027);
return 0;
}
-
static struct spi_driver max1027_driver = {
.driver = {
.name = DRIVER_NAME,
diff --git a/target/packages/ch7024ctrl/ch7024.c b/target/packages/ch7024ctrl/ch7024.c
index 0d7706c..e8ce201 100644
--- a/target/packages/ch7024ctrl/ch7024.c
+++ b/target/packages/ch7024ctrl/ch7024.c
@@ -1,7 +1,7 @@
/*
** THE ARMADEUS PROJECT
**
-** Copyright (C) year The source forge armadeus project team
+** Copyright (C) 2007 The source forge armadeus project team
**
** 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
@@ -21,7 +21,6 @@
**
** author: th...@us...
*/
-
#include <stdio.h>
#include <fcntl.h>
@@ -37,53 +36,54 @@
#include "ch7024.h"
//#define DEBUG_CH7024 1
-#define VERSION 0.1f
+#define VERSION "0.2"
#define CONF_FILE "ch7024.conf"
#define MAX_DUMP_LINE 100
-/****************************************************************************************************************************/
+
/* MENU */
void usage()
{
- printf ("\nCH7024 utility ver %0.1f. Armadeus\n", VERSION);
- printf ("q: quit\n");
- printf ("m: modify\n");
- printf ("d: dump all\n");
- printf ("s: save\n");
- printf ("l: load\n");
- printf ("other: menu\n");
+ printf("\nCH7024 utility ver %s. Armadeus\n", VERSION);
+ printf("q: quit\n");
+ printf("m: modify\n");
+ printf("d: dump all\n");
+ printf("s: save\n");
+ printf("l: load\n");
+ printf("other: menu\n");
}
-/* Read a byte on the I2C bus
- This is done by writing the register address
+/* Read a byte on the I2C bus
+ This is done by writing the register address
we want to access and then by reading this register
@param fd: file descriptor of the device
@param reg: register to access
@param buf: buffer used to store the result
@return : -1 in case of error otherwise 0
*/
-int read_byte( int fd, unsigned char reg, unsigned char *buf )
-{
- // create an I2C write message (only one byte: the address)
- struct i2c_msg msg = { CH7024_I2C_SLAVE_ADDR, 0, 1, buf };
- // create a I2C IOCTL request
- struct i2c_rdwr_ioctl_data rdwr = { &msg, 1 };
+int read_byte(int fd, unsigned char reg, unsigned char *buf)
+{
+ /* create an I2C write message (only one byte: the address) */
+ struct i2c_msg msg = { CH7024_I2C_SLAVE_ADDR, 0, 1, buf };
+ /* create a I2C IOCTL request */
+ struct i2c_rdwr_ioctl_data rdwr = { &msg, 1 };
+
+ buf[0] = reg; /* select reg to read */
- buf[0] = reg; // select reg to read
-
- // write the desired register address
- if ( ioctl( fd, I2C_RDWR, &rdwr ) < 0 ){
+ /* write the desired register address */
+ if (ioctl(fd, I2C_RDWR, &rdwr) < 0) {
printf("Write error\n");
return -1;
}
- msg.flags = I2C_M_RD; // read
-
- // read the result and write it in buf[0]
- if ( ioctl( fd, I2C_RDWR, &rdwr ) < 0 ){
+ msg.flags = I2C_M_RD; /* read */
+
+ /* read the result and write it in buf[0] */
+ if (ioctl(fd, I2C_RDWR, &rdwr) < 0) {
printf("Read error\n");
return -1;
}
- return 0;
+
+ return 0;
}
/* Write a byte on the I2C bus
@@ -94,21 +94,22 @@ int read_byte( int fd, unsigned char reg, unsigned char *buf )
*/
int write_byte(int fd, unsigned char reg, unsigned char value)
{
- unsigned char buf[2] = {reg,value}; // initialise a data buffer with
- // address and data
+ unsigned char buf[2] = {reg, value}; /* initialise a data buffer with
+ address and data */
- // create an I2C write message
- struct i2c_msg msg = { CH7024_I2C_SLAVE_ADDR, 0, sizeof(buf), buf };
- // create a I2C IOCTL request
+ /* create an I2C write message */
+ struct i2c_msg msg = { CH7024_I2C_SLAVE_ADDR, 0, sizeof(buf), buf };
+ /* create a I2C IOCTL request */
struct i2c_rdwr_ioctl_data rdwr = { &msg, 1 };
#ifdef DEBUG_CH7024
printf("write ref %02X value %02X\n",reg, value);
#endif
- if ( ioctl( fd, I2C_RDWR, &rdwr ) < 0 ){
- printf("Write error\n");
- return -1;
- }
+ if (ioctl(fd, I2C_RDWR, &rdwr) < 0) {
+ printf("Write error\n");
+ return -1;
+ }
+
return 0;
}
@@ -116,12 +117,12 @@ int write_byte(int fd, unsigned char reg, unsigned char value)
@param string: string to dump
@param destFile: file in which to write
*/
- void dump2Output(char* string, FILE* destFile)
+void dump2Output(char* string, FILE* destFile)
{
- if( destFile == NULL )
+ if (destFile == NULL)
printf("%s", string);
else
- fprintf(destFile,"%s", string);
+ fprintf(destFile, "%s", string);
}
/* dump the register values on the screen if destFile is NULL or in a file
@@ -134,29 +135,29 @@ void dump(int fd, FILE* destFile)
unsigned char buf[2];
char dumpString[MAX_DUMP_LINE];
- if( destFile == NULL )
+ if (destFile == NULL)
printf("Ad:Va\tRe:Va\tRe:Va\tRe:Va\n");
- for( i = 0; i<14; i++ ){
- for( j = 0; j<4; j++ ){
+ for (i=0; i<14; i++) {
+ for (j=0; j<4; j++) {
address = i*4+j;
- if( !read_byte( fd, address, buf ) ){
- sprintf( dumpString, "%02X:%02X\t", address, buf[0] );
- dump2Output( dumpString, destFile );
+ if (!read_byte(fd, address, buf)) {
+ sprintf(dumpString, "%02X:%02X\t", address, buf[0]);
+ dump2Output(dumpString, destFile);
}
}
- dump2Output( "\n", destFile );
+ dump2Output("\n", destFile);
}
- if( !read_byte( fd, DAC_TRIMMING_CMD, buf ) ){
- sprintf( dumpString, "%02X:%02X\t", DAC_TRIMMING_CMD, buf[0] );
- dump2Output( dumpString, destFile );
+ if (!read_byte(fd, DAC_TRIMMING_CMD, buf)) {
+ sprintf(dumpString, "%02X:%02X\t", DAC_TRIMMING_CMD, buf[0]);
+ dump2Output(dumpString, destFile);
}
- if( !read_byte( fd, DATA_IO_CMD, buf ) ){
- sprintf( dumpString, "%02X:%02X\t", DATA_IO_CMD, buf[0] );
- dump2Output( dumpString, destFile );
+ if (!read_byte(fd, DATA_IO_CMD, buf)) {
+ sprintf(dumpString, "%02X:%02X\t", DATA_IO_CMD, buf[0]);
+ dump2Output(dumpString, destFile);
}
- if( !read_byte( fd, ATTACHED_DISPLAY, buf ) ){
- sprintf( dumpString, "%02X:%02X\n", ATTACHED_DISPLAY, buf[0] );
- dump2Output( dumpString, destFile );
+ if (!read_byte(fd, ATTACHED_DISPLAY, buf)) {
+ sprintf(dumpString, "%02X:%02X\n", ATTACHED_DISPLAY, buf[0]);
+ dump2Output(dumpString, destFile);
}
}
@@ -164,7 +165,7 @@ void dump(int fd, FILE* destFile)
@param fd: file descriptor of the CH7024
@param fileName: file containing the values. If "" then the name has to be entered
*/
-void load( int fd, char* fileName )
+void load(int fd, char* fileName)
{
char line[MAX_DUMP_LINE];
char tempFileName[MAX_DUMP_LINE];
@@ -173,118 +174,115 @@ void load( int fd, char* fileName )
int val1, val2, val3, val4;
int nb;
- if( strlen(fileName) == 0 ){
+ if (strlen(fileName) == 0) {
printf("Enter file name: ");
- fgets (tempFileName, sizeof(tempFileName), stdin);
- tempFileName[strlen(tempFileName)-1] = '\0'; //suppress \n
- }
- else{
- strcpy(tempFileName,fileName);
+ fgets(tempFileName, sizeof(tempFileName), stdin);
+ tempFileName[strlen(tempFileName)-1] = '\0'; /* suppress \n */
+ } else {
+ strcpy(tempFileName, fileName);
}
- if ((fd_conf = fopen(tempFileName,"r")) == NULL){
+ if ((fd_conf = fopen(tempFileName, "r")) == NULL) {
perror("Open error: ");
exit (1);
}
- while(fgets(line, MAX_DUMP_LINE, fd_conf) != NULL){
- nb = sscanf(line,"%2X%*c%2X%2X%*c%2X%2X%*c%2X%2X%*c%2X",
- &addr1,&val1,&addr2,&val2,&addr3,&val3,&addr4,&val4 );
- if(nb>=2)
- write_byte (fd, addr1, val1);
- if(nb>=4)
- write_byte (fd, addr2, val2);
- if(nb>=6)
- write_byte (fd, addr3, val3);
- if(nb>=8)
- write_byte (fd, addr4, val4);
+ while(fgets(line, MAX_DUMP_LINE, fd_conf) != NULL) {
+ nb = sscanf(line, "%2X%*c%2X%2X%*c%2X%2X%*c%2X%2X%*c%2X",
+ &addr1, &val1, &addr2, &val2, &addr3, &val3, &addr4, &val4);
+ if (nb >= 2)
+ write_byte(fd, addr1, val1);
+ if (nb >= 4)
+ write_byte(fd, addr2, val2);
+ if (nb >= 6)
+ write_byte(fd, addr3, val3);
+ if (nb >= 8)
+ write_byte(fd, addr4, val4);
}
- /* power down to reset the dac after parameter changing*/
- write_byte (fd, POWER_STATE_CMD, 0xFF);
- /* power on the dac after parameter changing*/
- write_byte (fd, POWER_STATE_CMD, 0x00);
- if(fd_conf != NULL)
+ /* power down to reset the DAC after parameter changing */
+ write_byte(fd, POWER_STATE_CMD, 0xFF);
+ /* power on the DAC after parameter changing */
+ write_byte(fd, POWER_STATE_CMD, 0x00);
+ if (fd_conf != NULL)
fclose(fd_conf);
}
int main(int argc, char *argv[])
{
- int fd; // CH7024 file descriptor
- FILE *fd_conf = NULL; // config file
- char string[10]; // user input string
- unsigned char buf[2]; // buf to store I2C command/data
+ int fd; /* CH7024 file descriptor */
+ FILE *fd_conf = NULL; /* config file */
+ char string[10]; /* user input string */
+ unsigned char buf[2]; /* buf to store I2C command/data */
int regAddr;
int regValue;
- if ( argc >2 ){ // too many args
- usage();
+ if (argc > 2) { /* too many args */
+ usage();
exit(1);
}
- // open I2C /dev
- if ((fd = open("/dev/i2c-0",O_RDWR)) < 0){
- perror("Open error: ");
- exit (1);
- }
+ /* open I2C /dev */
+ if ((fd = open("/dev/i2c-0", O_RDWR)) < 0) {
+ perror("Open error: ");
+ exit (1);
+ }
- // configure I2C_SLAVE
- if ( ioctl(fd ,/*I2C_SLAVE*/ 0x703, CH7024_I2C_SLAVE_ADDR) < 0){
- perror("Ioctl error: ");
- exit (1);
- }
+ /* configure I2C_SLAVE */
+ if (ioctl(fd ,/*I2C_SLAVE*/ 0x703, CH7024_I2C_SLAVE_ADDR) < 0) {
+ perror("Ioctl error: ");
+ exit (1);
+ }
- // check CH7024 presence
- if( !read_byte( fd, DEVICE_ID_CMD, buf ) ){
- if( buf[0] != CH7024_ID ){
+ /* check CH7024 presence */
+ if (!read_byte( fd, DEVICE_ID_CMD, buf)) {
+ if (buf[0] != CH7024_ID) {
printf("CH7024 not recognized. Exit\n");
exit(1);
}
- }
- else{
+ } else {
printf("CH7024 not found. Exit\n");
exit(1);
}
-
- if ( argc == 2 ){ // read data from file
+ if (argc == 2) { /* read data from file */
load(fd,argv[1]);
exit(0);
}
usage();
- while(1){
- fgets(string,sizeof(string),stdin);
- if(string[0] == 'q') // Exit
+ while(1) {
+ fgets(string, sizeof(string), stdin);
+ if (string[0] == 'q') /* Exit */
exit(0);
- else if (string[0] == 'm'){ // Modify registers
+ else if (string[0] == 'm') { /* Modify registers */
printf("reg addr (hex without 0x): ");
- fgets(string,sizeof(string),stdin);
- sscanf(string,"%2x", ®Addr);
+ fgets(string, sizeof(string), stdin);
+ sscanf(string, "%2x", ®Addr);
printf("reg value (hex without 0x): ");
- fgets(string,sizeof(string),stdin);
+ fgets(string, sizeof(string), stdin);
sscanf(string,"%2x", ®Value);
- write_byte (fd, regAddr, regValue);
+ write_byte(fd, regAddr, regValue);
}
- else if (string[0] == 'd') // Dump to screen
+ else if (string[0] == 'd') /* Dump to screen */
dump(fd,fd_conf);
- else if (string[0] == 's'){ // Save to file
- if ((fd_conf = fopen(CONF_FILE,"w")) < 0){
+ else if (string[0] == 's') { /* Save to file */
+ if ((fd_conf = fopen(CONF_FILE, "w")) < 0) {
perror("Open error: ");
exit (1);
}
- dump(fd,fd_conf);
- if(fd_conf != NULL)
+ dump(fd, fd_conf);
+ if (fd_conf != NULL)
fclose(fd_conf);
}
- else if (string[0] == 'l'){ // load from file
+ else if (string[0] == 'l') { /* load from file */
load(fd,"");
}
else
usage();
};
- if(fd >= 0)
+ if (fd >= 0)
close(fd);
- exit (0);
+ exit (0);
}
hooks/post-receive
--
armadeus
|