[Armadeus-commitlog] SF.net SVN: armadeus:[1262] trunk/target/linux/modules/max1027/max1027.c
Brought to you by:
sszy
|
From: <ar...@us...> - 2009-05-07 15:04:38
|
Revision: 1262
http://armadeus.svn.sourceforge.net/armadeus/?rev=1262&view=rev
Author: artemys
Date: 2009-05-07 15:04:20 +0000 (Thu, 07 May 2009)
Log Message:
-----------
[LINUX] Corrects indentation in max1027 driver
Modified Paths:
--------------
trunk/target/linux/modules/max1027/max1027.c
Modified: trunk/target/linux/modules/max1027/max1027.c
===================================================================
--- trunk/target/linux/modules/max1027/max1027.c 2009-05-06 17:36:33 UTC (rev 1261)
+++ trunk/target/linux/modules/max1027/max1027.c 2009-05-07 15:04:20 UTC (rev 1262)
@@ -81,17 +81,16 @@
static int max1027_major = 0; /* Dynamic major allocation */
struct adc_channel {
-
int id; /* channel ID */
#define DATA_AVAILABLE 0
- unsigned long status;
+ unsigned long status;
- /* channel FIFO */
+ /* channel FIFO */
volatile unsigned int head, tail;
- int nb_data_required;
+ int nb_data_required;
volatile u16 buffer[FIFO_SIZE];
- /* channel wait queue */
+ /* channel wait queue */
wait_queue_head_t change_wq;
struct spi_dev *spi; /* clean ?? */
};
@@ -105,9 +104,9 @@
struct mutex update_lock;
#define CONVERSION_RUNNING 0
- unsigned long status;
+ unsigned long status;
- u16 ain[NB_CHANNELS]; /* latest channels value */
+ u16 ain[NB_CHANNELS]; /* latest channels value */
struct adc_channel* channels[NB_CHANNELS];
int temperature; /* current one in millidegree Celcius */
/* Shadow registers to hold current configuration */
@@ -128,45 +127,46 @@
u8 buffer[MAX_NB_RESULTS*2]; // each result is sent with 16 bits
static void fifo_flush(struct adc_channel* channel)
-{
+{
channel->head = 0;
- channel->tail = 0;
- channel->nb_data_required = 0;
+ channel->tail = 0;
+ channel->nb_data_required = 0;
}
static u16 fifo_inuse(struct adc_channel* channel)
-{
+{
return channel->head - channel->tail;
}
-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)
- channel->nb_data_required--;
- }
- else{
- pr_debug("put fifo full %d\n", channel->id);
- }
+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)
+ channel->nb_data_required--;
+ }
+ else {
+ pr_debug("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) );
- }
+ if (channel->nb_data_required <= 0) {
+ set_bit( DATA_AVAILABLE, &channel->status );
+ wake_up_interruptible( &(channel->change_wq) );
+ }
}
-static u16 fifo_get(u16 * c, u16 count, struct adc_channel* channel)
+static u16 fifo_get(u16 * c, u16 count, struct adc_channel* channel)
{
- int j, i=0;
+ int j, i=0;
- channel->nb_data_required = 0;
- j = fifo_inuse(channel);
- 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 = 0;
+ j = fifo_inuse(channel);
+ 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);
- return i;
+ return i;
}
/* Must be used within mutex and outside of IRQ context !!! */
@@ -178,22 +178,22 @@
spi_write_then_read(spi, &buf, 1, NULL, 0);
/* !! order is important here !! ;-) */
- if( cmd & MAX1027_REG_CONV ) {
+ if (cmd & MAX1027_REG_CONV) {
p_max1027->conv_reg = cmd;
}
- else if( cmd & MAX1027_REG_SETUP ) {
+ else if (cmd & MAX1027_REG_SETUP) {
p_max1027->setup_reg = cmd;
}
- else if( cmd & MAX1027_REG_AVG ) {
+ else if (cmd & MAX1027_REG_AVG) {
p_max1027->avg_reg = cmd;
}
}
static void max1027_start_conv(struct max1027 *max1027)
{
- /* if no convst pin */
- if( max1027->cnvst < 0 ) {
- max1027_send_cmd( current_spi, max1027->conv_reg );
+ /* if no convst pin */
+ if (max1027->cnvst < 0) {
+ max1027_send_cmd(current_spi, max1027->conv_reg);
}
else {
gpio_set_value(max1027->cnvst, 0);
@@ -211,7 +211,7 @@
pr_debug("%s", __FUNCTION__);
- mutex_lock(&max1027->update_lock);
+ mutex_lock(&max1027->update_lock);
selected_channel = GET_SELECTED_CHANNEL(max1027->conv_reg);
if (selected_channel >= NB_CHANNELS)
selected_channel = NB_CHANNELS - 1;
@@ -224,11 +224,11 @@
values_to_read = 1;
}
- if( max1027->conv_reg & MAX1027_CONV_TEMP )
+ if (max1027->conv_reg & MAX1027_CONV_TEMP)
values_to_read += 1;
#ifdef DEBUG
- for( i=0; i<values_to_read*2; i++ ) {
+ for (i=0; i<values_to_read*2; i++) {
printk("%02x ", buffer[i]);
}
printk("\n");
@@ -236,7 +236,7 @@
start = 0;
/* temp */
- if( max1027->conv_reg & MAX1027_CONV_TEMP ) {
+ if (max1027->conv_reg & MAX1027_CONV_TEMP) {
start = 1;
msb = buffer[0] & 0x0f;
lsb = buffer[1];
@@ -244,34 +244,35 @@
max1027->temperature = (value * 1000) >> 3; /* 1 unit = 1/8 °C + save it in millidegree */
pr_debug("%d m°C ", max1027->temperature);
}
- nb_data_required = 0;
- for( i=start; i<values_to_read; i++ ) {
+ nb_data_required = 0;
+ for (i=start; i<values_to_read; i++) {
msb = buffer[i*2] & 0x0f;
lsb = buffer[(i*2)+1];
value = ((msb << 8) | lsb) >> 2;
- if( scan_mode == SCAN_MODE_00 ) {
- int id = i-start;
- if( max1027->channels[id] != NULL ){
- fifo_put( value ,max1027->channels[id]);
- nb_data_required = max(nb_data_required, max1027->channels[id]->nb_data_required);
- }
+ if (scan_mode == SCAN_MODE_00) {
+ int id = i-start;
+ if (max1027->channels[id] != NULL) {
+ fifo_put(value, max1027->channels[id]);
+ nb_data_required = max(nb_data_required, max1027->channels[id]->nb_data_required);
+ }
max1027->ain[i-start] = value;
} else {
- if( max1027->channels[selected_channel] != NULL ){
- fifo_put( value ,max1027->channels[selected_channel]);
- nb_data_required = max(nb_data_required, max1027->channels[selected_channel]->nb_data_required);
- }
+ if (max1027->channels[selected_channel] != NULL) {
+ fifo_put(value, max1027->channels[selected_channel]);
+ nb_data_required = max(nb_data_required, max1027->channels[selected_channel]->nb_data_required);
+ }
max1027->ain[selected_channel++] = value;
}
pr_debug("0x%04x ", value);
}
pr_debug("\n");
- if( nb_data_required )
- max1027_start_conv(max1027);
- else
- max1027->status = 0;
- mutex_unlock(&max1027->update_lock);
+ if (nb_data_required) {
+ max1027_start_conv(max1027);
+ } else {
+ max1027->status = 0;
+ }
+ mutex_unlock(&max1027->update_lock);
}
static void max1027_reads_async( struct spi_device *spi, int num_values )
@@ -312,25 +313,24 @@
return count;
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);
+ if (fifo_inuse(channel) == 0) {
+ if (! test_and_set_bit( CONVERSION_RUNNING,&max1027->status)) {
+ clear_bit( DATA_AVAILABLE, &channel->status );
+ max1027_start_conv(max1027);
}
if (file->f_flags & O_NONBLOCK)
return -EAGAIN;
if (wait_event_interruptible(channel->change_wq, channel->status))
return -ERESTARTSYS;
-
}
- //printk("count dev %d\n", count);
+ //printk("count dev %d\n", count);
count = fifo_get(value, count>>1, channel)<<1;
- //printk("count %d\n", count);
+ //printk("count %d\n", count);
/* Copy result to given userspace buffer */
//count = min( count, (size_t)sizeof(u16) );
- if ( copy_to_user(buf, value, count) ) {
+ if (copy_to_user(buf, value, count)) {
ret = -EFAULT;
goto out;
}
@@ -349,22 +349,35 @@
int size = 0;
/* 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;
- break;
- case SCAN_MODE_01: size = NB_CHANNELS -
- GET_SELECTED_CHANNEL(max1027->conv_reg); break;
- case SCAN_MODE_10: size = GET_NB_SCAN(max1027->avg_reg); break;
- case SCAN_MODE_11: size = 1; break;
- default: printk(KERN_ERR "%s: max1027 scan mode not supported\n",
- __FUNCTION__); break;
- }
+ switch( GET_SCAN_MODE(max1027->conv_reg) )
+ {
+ case SCAN_MODE_00:
+ size = GET_SELECTED_CHANNEL(max1027->conv_reg) + 1;
+ break;
- if( max1027->conv_reg & MAX1027_CONV_TEMP )
+ case SCAN_MODE_01:
+ size = NB_CHANNELS - GET_SELECTED_CHANNEL(max1027->conv_reg);
+ break;
+
+ case SCAN_MODE_10:
+ size = GET_NB_SCAN(max1027->avg_reg);
+ break;
+
+ case SCAN_MODE_11:
+ size = 1;
+ break;
+
+ default:
+ printk(KERN_ERR "%s: max1027 scan mode not supported\n",
+ __FUNCTION__);
+ break;
+ }
+
+ if (max1027->conv_reg & MAX1027_CONV_TEMP) {
max1027_reads_async(spi, size+1);
- else
+ } else {
max1027_reads_async(spi, size);
+ }
}
/* EOC (End Of Conversion) IRQ handler */
@@ -381,11 +394,11 @@
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 )
- fifo_flush(p_max1027->channels[i]);
- }
+ int i;
+ for (i=0; i < NB_CHANNELS; i++) {
+ if( p_max1027->channels[i] != NULL )
+ fifo_flush(p_max1027->channels[i]);
+ }
}
static int max1027_dev_open(struct inode *inode, struct file *file)
@@ -407,7 +420,7 @@
channel->status = 0;
pr_debug("Opening /dev/max1027/AN%d\n", minor);
- fifo_flush(channel);
+ fifo_flush(channel);
max1027->channels[minor & 0x07] = channel;
return 0;
@@ -423,12 +436,12 @@
struct adc_channel *channel = file->private_data;
struct max1027 *max1027 = dev_get_drvdata(¤t_spi->dev); /* suite du cradingue */
- mutex_lock(&max1027->update_lock);
- max1027->channels[channel->id] = NULL;
+ mutex_lock(&max1027->update_lock);
+ max1027->channels[channel->id] = NULL;
kfree(channel);
- mutex_unlock(&max1027->update_lock);
+ mutex_unlock(&max1027->update_lock);
+
pr_debug("Closing access to /dev/max1027/AN%d\n", minor);
-
return 0;
}
@@ -464,8 +477,8 @@
pr_debug("%s: 0x%02x\n", __FUNCTION__, val);
mutex_lock(&p_max1027->update_lock);
- max1027_send_cmd( spi, MAX1027_REG_CONV | val );
- max1027_flush_all_channels(p_max1027);
+ max1027_send_cmd(spi, MAX1027_REG_CONV | val);
+ max1027_flush_all_channels(p_max1027);
mutex_unlock(&p_max1027->update_lock);
return count;
@@ -476,7 +489,7 @@
ssize_t ret_size = 0;
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->conv_reg);
return ret_size;
@@ -490,7 +503,7 @@
struct spi_device *spi = to_spi_device(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);
@@ -501,7 +514,7 @@
max1027_send_cmd( spi, val>>8 );
pr_debug("+ 0x%02x", val);
}
- max1027_flush_all_channels(p_max1027);
+ max1027_flush_all_channels(p_max1027);
mutex_unlock(&p_max1027->update_lock);
pr_debug("\n");
@@ -513,7 +526,7 @@
ssize_t ret_size = 0;
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->setup_reg);
return ret_size;
@@ -525,13 +538,13 @@
struct spi_device *spi = to_spi_device(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);
- max1027_send_cmd( spi, MAX1027_REG_AVG | val );
- max1027_flush_all_channels(p_max1027);
+ max1027_send_cmd(spi, MAX1027_REG_AVG | val);
+ max1027_flush_all_channels(p_max1027);
mutex_unlock(&p_max1027->update_lock);
return count;
@@ -542,7 +555,7 @@
ssize_t ret_size = 0;
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);
return ret_size;
@@ -685,30 +698,29 @@
if (!max1027)
return -ENOMEM;
mutex_init(&max1027->update_lock);
- for (i=0; i < NB_CHANNELS; i++ ) {
+ for (i=0; i < NB_CHANNELS; i++) {
max1027->channels[i] = NULL;
}
/* Register the driver as character device by getting a major number */
result = register_chrdev(max1027_major, DRIVER_NAME, &max1027_fops);
- if (result < 0)
- {
+ if (result < 0) {
printk(KERN_WARNING DRIVER_NAME ": can't get major %d\n", max1027_major);
return result;
}
- if( max1027_major == 0 ) max1027_major = result; /* dynamic Major allocation */
+ 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 )
- {
+ if (result) {
printk(KERN_WARNING DRIVER_NAME ": can't reserve gpios\n");
goto err_irq;
}
max1027->cnvst = platform_info->cnvst_pin;
- if( max1027->cnvst >= 0 )
+ if (max1027->cnvst >= 0)
gpio_set_value(max1027->cnvst, 1);
/* Create /sys entries */
@@ -739,17 +751,17 @@
/* 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_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 );
- if( result )
+ if (result)
goto err_irq;
printk( DRIVER_NAME " v" DRIVER_VERSION " successfully probed !\n");
- return(0);
+ return 0;
err_sys:
free_irq(spi->irq, max1027);
@@ -819,7 +831,6 @@
module_init(max1027_init);
module_exit(max1027_exit);
-
MODULE_AUTHOR("Julien Boibessot / Nicolas Colombain - Armadeus Systems");
MODULE_DESCRIPTION("Max1027 driver");
MODULE_LICENSE("GPL");
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|