[PATCH] staging: pi433: fixed coding style issues

From: Peter Johennecken
Date: Fri Dec 08 2017 - 18:28:17 EST


Fixed braces, double empty lines, tabs and spaces
and a macro with checkpatch.

Signed-off-by: Peter Johennecken <peter.johennecken@xxxxxxxxx>
---
drivers/staging/pi433/pi433_if.c | 242 +++++++++++--------------
drivers/staging/pi433/pi433_if.h | 13 +-
drivers/staging/pi433/rf69.c | 66 ++++---
drivers/staging/pi433/rf69.h | 5 +-
drivers/staging/pi433/rf69_enum.h | 314 +++++++++++++++------------------
drivers/staging/pi433/rf69_registers.h | 4 -
6 files changed, 286 insertions(+), 358 deletions(-)

diff --git a/drivers/staging/pi433/pi433_if.c b/drivers/staging/pi433/pi433_if.c
index 2a205c6173dc..6cca18cd0991 100644
--- a/drivers/staging/pi433/pi433_if.c
+++ b/drivers/staging/pi433/pi433_if.c
@@ -48,13 +48,12 @@
#include <linux/wait.h>
#include <linux/spi/spi.h>
#ifdef CONFIG_COMPAT
-#include <asm/compat.h>
+#include <linux/compat.h>
#endif

#include "pi433_if.h"
#include "rf69.h"

-
#define N_PI433_MINORS (1U << MINORBITS) /*32*/ /* ... up to 256 */
#define MAX_MSG_SIZE 900 /* min: FIFO_SIZE! */
#define MSG_FIFO_SIZE 65536 /* 65536 = 2^16 */
@@ -79,7 +78,7 @@ struct pi433_device {
struct device *dev;
struct cdev *cdev;
struct spi_device *spi;
- unsigned users;
+ unsigned int users;

/* irq related values */
struct gpio_desc *gpiod[NUM_DIO];
@@ -122,9 +121,9 @@ struct pi433_instance {
/*-------------------------------------------------------------------------*/

/* macro for checked access of registers of radio module */
-#define SET_CHECKED(retval) \
+#define (do { SET_CHECKED(retval) \
if (retval < 0) \
- return retval;
+ return retval; } while (0))

/*-------------------------------------------------------------------------*/

@@ -133,19 +132,14 @@ static irqreturn_t DIO0_irq_handler(int irq, void *dev_id)
{
struct pi433_device *device = dev_id;

- if (device->irq_state[DIO0] == DIO_PacketSent)
- {
+ if (device->irq_state[DIO0] == DIO_PacketSent) {
device->free_in_fifo = FIFO_SIZE;
dev_dbg(device->dev, "DIO0 irq: Packet sent\n");
wake_up_interruptible(&device->fifo_wait_queue);
- }
- else if (device->irq_state[DIO0] == DIO_Rssi_DIO0)
- {
+ } else if (device->irq_state[DIO0] == DIO_Rssi_DIO0) {
dev_dbg(device->dev, "DIO0 irq: RSSI level over threshold\n");
wake_up_interruptible(&device->rx_wait_queue);
- }
- else if (device->irq_state[DIO0] == DIO_PayloadReady)
- {
+ } else if (device->irq_state[DIO0] == DIO_PayloadReady) {
dev_dbg(device->dev, "DIO0 irq: PayloadReady\n");
device->free_in_fifo = 0;
wake_up_interruptible(&device->fifo_wait_queue);
@@ -158,14 +152,13 @@ static irqreturn_t DIO1_irq_handler(int irq, void *dev_id)
{
struct pi433_device *device = dev_id;

- if (device->irq_state[DIO1] == DIO_FifoNotEmpty_DIO1)
- {
+ if (device->irq_state[DIO1] == DIO_FifoNotEmpty_DIO1) {
device->free_in_fifo = FIFO_SIZE;
- }
- else if (device->irq_state[DIO1] == DIO_FifoLevel)
- {
- if (device->rx_active) device->free_in_fifo = FIFO_THRESHOLD - 1;
- else device->free_in_fifo = FIFO_SIZE - FIFO_THRESHOLD - 1;
+ } else if (device->irq_state[DIO1] == DIO_FifoLevel) {
+ if (device->rx_active)
+ device->free_in_fifo = FIFO_THRESHOLD - 1;
+ else
+ device->free_in_fifo = FIFO_SIZE - FIFO_THRESHOLD - 1;
}
dev_dbg(device->dev,
"DIO1 irq: %d bytes free in fifo\n", device->free_in_fifo);
@@ -189,9 +182,9 @@ rf69_set_rx_cfg(struct pi433_device *dev, struct pi433_rx_cfg *rx_cfg)
SET_CHECKED(rf69_set_antenna_impedance (dev->spi, rx_cfg->antenna_impedance));
SET_CHECKED(rf69_set_rssi_threshold (dev->spi, rx_cfg->rssi_threshold));
SET_CHECKED(rf69_set_ook_threshold_dec (dev->spi, rx_cfg->thresholdDecrement));
- SET_CHECKED(rf69_set_bandwidth (dev->spi, rx_cfg->bw_mantisse, rx_cfg->bw_exponent));
+ SET_CHECKED(rf69_set_bandwidth (dev->spi, rx_cfg->bw_mantisse, rx_cfg->bw_exponent));
SET_CHECKED(rf69_set_bandwidth_during_afc(dev->spi, rx_cfg->bw_mantisse, rx_cfg->bw_exponent));
- SET_CHECKED(rf69_set_dagc (dev->spi, rx_cfg->dagc));
+ SET_CHECKED(rf69_set_dagc (dev->spi, rx_cfg->dagc));

dev->rx_bytes_to_drop = rx_cfg->bytes_to_drop;

@@ -199,13 +192,10 @@ rf69_set_rx_cfg(struct pi433_device *dev, struct pi433_rx_cfg *rx_cfg)
/* enable */
SET_CHECKED(rf69_set_sync_enable(dev->spi, rx_cfg->enable_sync));
if (rx_cfg->enable_sync == optionOn)
- {
SET_CHECKED(rf69_set_fifo_fill_condition(dev->spi, afterSyncInterrupt));
- }
else
- {
SET_CHECKED(rf69_set_fifo_fill_condition(dev->spi, always));
- }
+
if (rx_cfg->enable_length_byte == optionOn) {
ret = rf69_set_packet_format(dev->spi, packetLengthVar);
if (ret < 0)
@@ -220,29 +210,24 @@ rf69_set_rx_cfg(struct pi433_device *dev, struct pi433_rx_cfg *rx_cfg)

/* lengths */
SET_CHECKED(rf69_set_sync_size(dev->spi, rx_cfg->sync_length));
- if (rx_cfg->enable_length_byte == optionOn)
- {
+ if (rx_cfg->enable_length_byte == optionOn) {
SET_CHECKED(rf69_set_payload_length(dev->spi, 0xff));
- }
- else if (rx_cfg->fixed_message_length != 0)
- {
+ } else if (rx_cfg->fixed_message_length != 0) {
payload_length = rx_cfg->fixed_message_length;
- if (rx_cfg->enable_length_byte == optionOn) payload_length++;
- if (rx_cfg->enable_address_filtering != filteringOff) payload_length++;
+ if (rx_cfg->enable_length_byte == optionOn)
+ payload_length++;
+ if (rx_cfg->enable_address_filtering != filteringOff)
+ payload_length++;
SET_CHECKED(rf69_set_payload_length(dev->spi, payload_length));
- }
- else
- {
+ } else {
SET_CHECKED(rf69_set_payload_length(dev->spi, 0));
}

/* values */
if (rx_cfg->enable_sync == optionOn)
- {
SET_CHECKED(rf69_set_sync_values(dev->spi, rx_cfg->sync_pattern));
- }
- if (rx_cfg->enable_address_filtering != filteringOff)
- {
+
+ if (rx_cfg->enable_address_filtering != filteringOff) {
SET_CHECKED(rf69_set_node_address (dev->spi, rx_cfg->node_address));
SET_CHECKED(rf69_set_broadcast_address(dev->spi, rx_cfg->broadcast_address));
}
@@ -265,13 +250,10 @@ rf69_set_tx_cfg(struct pi433_device *dev, struct pi433_tx_cfg *tx_cfg)

/* packet format enable */
if (tx_cfg->enable_preamble == optionOn)
- {
SET_CHECKED(rf69_set_preamble_length(dev->spi, tx_cfg->preamble_length));
- }
else
- {
SET_CHECKED(rf69_set_preamble_length(dev->spi, 0));
- }
+
SET_CHECKED(rf69_set_sync_enable (dev->spi, tx_cfg->enable_sync));
if (tx_cfg->enable_length_byte == optionOn) {
ret = rf69_set_packet_format(dev->spi, packetLengthVar);
@@ -306,7 +288,8 @@ pi433_start_rx(struct pi433_device *dev)

/* setup for receiving */
retval = rf69_set_rx_cfg(dev, &dev->rx_cfg);
- if (retval) return retval;
+ if (retval)
+ return retval;

/* setup rssi irq */
SET_CHECKED(rf69_set_dio_mapping(dev->spi, DIO0, DIO_Rssi_DIO0));
@@ -325,7 +308,6 @@ pi433_start_rx(struct pi433_device *dev)
return 0;
}

-
/*-------------------------------------------------------------------------*/

static int
@@ -339,10 +321,10 @@ pi433_receive(void *data)
dev->interrupt_rx_allowed = false;

/* wait for any tx to finish */
- dev_dbg(dev->dev,"rx: going to wait for any tx to finish");
+ dev_dbg(dev->dev, "rx: going to wait for any tx to finish");
retval = wait_event_interruptible(dev->rx_wait_queue, !dev->tx_active);
- if(retval) /* wait was interrupted */
- {
+ /* wait was interrupted */
+ if (retval) {
dev->interrupt_rx_allowed = true;
wake_up_interruptible(&dev->tx_wait_queue);
return retval;
@@ -359,8 +341,7 @@ pi433_receive(void *data)
return retval;

/* now check RSSI, if low wait for getting high (RSSI interrupt) */
- while ( !rf69_get_flag(dev->spi, rssiExceededThreshold) )
- {
+ while (!rf69_get_flag(dev->spi, rssiExceededThreshold)) {
/* allow tx to interrupt us while waiting for high RSSI */
dev->interrupt_rx_allowed = true;
wake_up_interruptible(&dev->tx_wait_queue);
@@ -368,13 +349,16 @@ pi433_receive(void *data)
/* wait for RSSI level to become high */
dev_dbg(dev->dev, "rx: going to wait for high RSSI level");
retval = wait_event_interruptible(dev->rx_wait_queue,
- rf69_get_flag(dev->spi,
- rssiExceededThreshold));
- if (retval) goto abort; /* wait was interrupted */
+ rf69_get_flag(dev->spi,
+ rssiExceededThreshold));
+ /* wait was interrupted */
+ if (retval)
+ goto abort;
dev->interrupt_rx_allowed = false;

/* cross check for ongoing tx */
- if (!dev->tx_active) break;
+ if (!dev->tx_active)
+ break;
}

/* configure payload ready irq */
@@ -383,28 +367,25 @@ pi433_receive(void *data)
irq_set_irq_type(dev->irq_num[DIO0], IRQ_TYPE_EDGE_RISING);

/* fixed or unlimited length? */
- if (dev->rx_cfg.fixed_message_length != 0)
- {
- if (dev->rx_cfg.fixed_message_length > dev->rx_buffer_size)
- {
+ if (dev->rx_cfg.fixed_message_length != 0) {
+ if (dev->rx_cfg.fixed_message_length > dev->rx_buffer_size) {
retval = -1;
goto abort;
}
bytes_total = dev->rx_cfg.fixed_message_length;
- dev_dbg(dev->dev,"rx: msg len set to %d by fixed length", bytes_total);
- }
- else
- {
+ dev_dbg(dev->dev, "rx: msg len set to %d by fixed length", bytes_total);
+ } else {
bytes_total = dev->rx_buffer_size;
dev_dbg(dev->dev, "rx: msg len set to %d as requested by read", bytes_total);
}

/* length byte enabled? */
- if (dev->rx_cfg.enable_length_byte == optionOn)
- {
+ if (dev->rx_cfg.enable_length_byte == optionOn) {
retval = wait_event_interruptible(dev->fifo_wait_queue,
dev->free_in_fifo < FIFO_SIZE);
- if (retval) goto abort; /* wait was interrupted */
+ /* wait was interrupted */
+ if (retval)
+ goto abort;

rf69_read_fifo(spi, (u8 *)&bytes_total, 1);
if (bytes_total > dev->rx_buffer_size) {
@@ -416,15 +397,16 @@ pi433_receive(void *data)
}

/* address byte enabled? */
- if (dev->rx_cfg.enable_address_filtering != filteringOff)
- {
+ if (dev->rx_cfg.enable_address_filtering != filteringOff) {
u8 dummy;

bytes_total--;

retval = wait_event_interruptible(dev->fifo_wait_queue,
dev->free_in_fifo < FIFO_SIZE);
- if (retval) goto abort; /* wait was interrupted */
+ /* wait was interrupted */
+ if (retval)
+ goto abort;

rf69_read_fifo(spi, &dummy, 1);
dev->free_in_fifo++;
@@ -432,13 +414,13 @@ pi433_receive(void *data)
}

/* get payload */
- while (dev->rx_position < bytes_total)
- {
- if ( !rf69_get_flag(dev->spi, payloadReady) )
- {
+ while (dev->rx_position < bytes_total) {
+ if (!rf69_get_flag(dev->spi, payloadReady)) {
retval = wait_event_interruptible(dev->fifo_wait_queue,
dev->free_in_fifo < FIFO_SIZE);
- if (retval) goto abort; /* wait was interrupted */
+ /* wait was interrupted */
+ if (retval)
+ goto abort;
}

/* need to drop bytes or acquire? */
@@ -447,14 +429,15 @@ pi433_receive(void *data)
else
bytes_to_read = bytes_total - dev->rx_position;

-
/* access the fifo */
if (bytes_to_read > FIFO_SIZE - dev->free_in_fifo)
bytes_to_read = FIFO_SIZE - dev->free_in_fifo;
retval = rf69_read_fifo(spi,
&dev->rx_buffer[dev->rx_position],
bytes_to_read);
- if (retval) goto abort; /* read failed */
+ /* read failed */
+ if (retval)
+ goto abort;
dev->free_in_fifo += bytes_to_read;

/* adjust status vars */
@@ -464,7 +447,6 @@ pi433_receive(void *data)
dev->rx_position += bytes_to_read;
}

-
/* rx done, wait was interrupted or error occurred */
abort:
dev->interrupt_rx_allowed = true;
@@ -489,14 +471,13 @@ pi433_tx_thread(void *data)
int position, repetitions;
int retval;

- while (1)
- {
+ while (1) {
/* wait for fifo to be populated or for request to terminate*/
dev_dbg(device->dev, "thread: going to wait for new messages");
wait_event_interruptible(device->tx_wait_queue,
- ( !kfifo_is_empty(&device->tx_fifo) ||
- kthread_should_stop() ));
- if ( kthread_should_stop() )
+ (!kfifo_is_empty(&device->tx_fifo) ||
+ kthread_should_stop()));
+ if (kthread_should_stop())
return 0;

/* get data from fifo in the following order:
@@ -508,14 +489,14 @@ pi433_tx_thread(void *data)

retval = kfifo_out(&device->tx_fifo, &tx_cfg, sizeof(tx_cfg));
if (retval != sizeof(tx_cfg)) {
- dev_dbg(device->dev, "reading tx_cfg from fifo failed: got %d byte(s), expected %d", retval, (unsigned int)sizeof(tx_cfg) );
+ dev_dbg(device->dev, "reading tx_cfg from fifo failed: got %d byte(s), expected %d", retval, (unsigned int)sizeof(tx_cfg));
mutex_unlock(&device->tx_fifo_lock);
continue;
}

retval = kfifo_out(&device->tx_fifo, &size, sizeof(size_t));
if (retval != sizeof(size_t)) {
- dev_dbg(device->dev, "reading msg size from fifo failed: got %d, expected %d", retval, (unsigned int)sizeof(size_t) );
+ dev_dbg(device->dev, "reading msg size from fifo failed: got %d, expected %d", retval, (unsigned int)sizeof(size_t));
mutex_unlock(&device->tx_fifo_lock);
continue;
}
@@ -538,14 +519,14 @@ pi433_tx_thread(void *data)

/* add length byte, if requested */
if (tx_cfg.enable_length_byte == optionOn)
- buffer[position++] = size-1; /* according to spec length byte itself must be excluded from the length calculation */
+ buffer[position++] = size - 1; /* according to spec length byte itself must be excluded from the length calculation */

/* add adr byte, if requested */
if (tx_cfg.enable_address_byte == optionOn)
buffer[position++] = tx_cfg.address_byte;

/* finally get message data from fifo */
- retval = kfifo_out(&device->tx_fifo, &buffer[position], sizeof(buffer)-position );
+ retval = kfifo_out(&device->tx_fifo, &buffer[position], sizeof(buffer) - position);
dev_dbg(device->dev, "read %d message byte(s) from fifo queue.", retval);
mutex_unlock(&device->tx_fifo_lock);

@@ -565,8 +546,7 @@ pi433_tx_thread(void *data)
disable_irq(device->irq_num[DIO0]);
device->tx_active = true;

- if (device->rx_active && rx_interrupted == false)
- {
+ if (device->rx_active && rx_interrupted == false) {
/* rx is currently waiting for a telegram;
* we need to set the radio module to standby
*/
@@ -578,13 +558,9 @@ pi433_tx_thread(void *data)
SET_CHECKED(rf69_set_mode(spi, standby)); /* this clears the fifo */
SET_CHECKED(rf69_set_fifo_threshold(spi, FIFO_THRESHOLD));
if (tx_cfg.enable_length_byte == optionOn)
- {
SET_CHECKED(rf69_set_payload_length(spi, size * tx_cfg.repetitions));
- }
else
- {
SET_CHECKED(rf69_set_payload_length(spi, 0));
- }

/* configure the rf chip */
rf69_set_tx_cfg(device, &tx_cfg);
@@ -607,39 +583,40 @@ pi433_tx_thread(void *data)
device->free_in_fifo = FIFO_SIZE;
position = 0;
repetitions = tx_cfg.repetitions;
- while( (repetitions > 0) && (size > position) )
- {
- if ( (size - position) > device->free_in_fifo)
- { /* msg to big for fifo - take a part */
+ while ((repetitions > 0) && (size > position)) {
+ if ((size - position) > device->free_in_fifo) {
+ /* msg to big for fifo - take a part */
int temp = device->free_in_fifo;
+
device->free_in_fifo = 0;
rf69_write_fifo(spi,
- &buffer[position],
- temp);
- position +=temp;
- }
- else
- { /* msg fits into fifo - take all */
+ &buffer[position],
+ temp);
+ position += temp;
+ } else { /* msg fits into fifo - take all */
device->free_in_fifo -= size;
repetitions--;
rf69_write_fifo(spi,
&buffer[position],
- (size - position) );
+ (size - position));
position = 0; /* reset for next repetition */
}

retval = wait_event_interruptible(device->fifo_wait_queue,
device->free_in_fifo > 0);
- if (retval) { printk("ABORT\n"); goto abort; }
+ if (retval) {
+ dev_info(device, "ABORT\n");
+ goto abort;
+ }
}

/* we are done. Wait for packet to get sent */
dev_dbg(device->dev, "thread: wait for packet to get sent/fifo to be empty");
wait_event_interruptible(device->fifo_wait_queue,
device->free_in_fifo == FIFO_SIZE ||
- kthread_should_stop() );
- if ( kthread_should_stop() ) printk("ABORT\n");
-
+ kthread_should_stop());
+ if (kthread_should_stop())
+ dev_info(device, "ABORT\n");

/* STOP_TRANSMISSION */
dev_dbg(device->dev, "thread: Packet sent. Set mode to stby.");
@@ -648,8 +625,7 @@ pi433_tx_thread(void *data)
/* everything sent? */
if (kfifo_is_empty(&device->tx_fifo)) {
abort:
- if (rx_interrupted)
- {
+ if (rx_interrupted) {
rx_interrupted = false;
pi433_start_rx(device);
}
@@ -678,13 +654,10 @@ pi433_read(struct file *filp, char __user *buf, size_t size, loff_t *f_pos)

/* just one read request at a time */
mutex_lock(&device->rx_lock);
- if (device->rx_active)
- {
+ if (device->rx_active) {
mutex_unlock(&device->rx_lock);
return -EAGAIN;
- }
- else
- {
+ } else {
device->rx_active = true;
mutex_unlock(&device->rx_lock);
}
@@ -709,7 +682,6 @@ pi433_read(struct file *filp, char __user *buf, size_t size, loff_t *f_pos)
return bytes_received;
}

-
static ssize_t
pi433_write(struct file *filp, const char __user *buf,
size_t count, loff_t *f_pos)
@@ -732,11 +704,11 @@ pi433_write(struct file *filp, const char __user *buf,
*/
mutex_lock(&device->tx_fifo_lock);
retval = kfifo_in(&device->tx_fifo, &instance->tx_cfg, sizeof(instance->tx_cfg));
- if ( retval != sizeof(instance->tx_cfg) )
+ if (retval != sizeof(instance->tx_cfg))
goto abort;

- retval = kfifo_in (&device->tx_fifo, &count, sizeof(size_t));
- if ( retval != sizeof(size_t) )
+ retval = kfifo_in(&device->tx_fifo, &count, sizeof(size_t));
+ if (retval != sizeof(size_t))
goto abort;

retval = kfifo_from_user(&device->tx_fifo, buf, count, &copied);
@@ -758,7 +730,6 @@ pi433_write(struct file *filp, const char __user *buf,
return -EAGAIN;
}

-
static long
pi433_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
{
@@ -896,12 +867,11 @@ static int pi433_release(struct inode *inode, struct file *filp)
return 0;
}

-
/*-------------------------------------------------------------------------*/

static int setup_GPIOs(struct pi433_device *device)
{
- char name[5];
+ char name[5];
int retval;
int i;
const irq_handler_t DIO_irq_handler[NUM_DIO] = {
@@ -909,8 +879,7 @@ static int setup_GPIOs(struct pi433_device *device)
DIO1_irq_handler
};

- for (i=0; i<NUM_DIO; i++)
- {
+ for (i = 0; i < NUM_DIO; i++) {
/* "construct" name and get the gpio descriptor */
snprintf(name, sizeof(name), "DIO%d", i);
device->gpiod[i] = gpiod_get(&device->spi->dev, name, 0 /*GPIOD_IN*/);
@@ -923,24 +892,21 @@ static int setup_GPIOs(struct pi433_device *device)
if (device->gpiod[i] == ERR_PTR(-EBUSY))
dev_dbg(&device->spi->dev, "%s is busy.", name);

- if ( IS_ERR(device->gpiod[i]) )
- {
+ if (IS_ERR(device->gpiod[i])) {
retval = PTR_ERR(device->gpiod[i]);
/* release already allocated gpios */
- for (i--; i>=0; i--)
- {
+ for (i--; i >= 0; i--) {
free_irq(device->irq_num[i], device);
gpiod_put(device->gpiod[i]);
}
return retval;
}

-
/* configure the pin */
gpiod_unexport(device->gpiod[i]);
retval = gpiod_direction_input(device->gpiod[i]);
- if (retval) return retval;
-
+ if (retval)
+ return retval;

/* configure irq */
device->irq_num[i] = gpiod_to_irq(device->gpiod[i]);
@@ -967,10 +933,9 @@ static void free_GPIOs(struct pi433_device *device)
{
int i;

- for (i=0; i<NUM_DIO; i++)
- {
+ for (i = 0; i < NUM_DIO; i++) {
/* check if gpiod is valid */
- if ( IS_ERR(device->gpiod[i]) )
+ if (IS_ERR(device->gpiod[i]))
continue;

free_irq(device->irq_num[i], device);
@@ -1002,6 +967,7 @@ static void pi433_free_minor(struct pi433_device *dev)
idr_remove(&pi433_idr, dev->minor);
mutex_unlock(&minor_lock);
}
+
/*-------------------------------------------------------------------------*/

static const struct file_operations pi433_fops = {
@@ -1032,13 +998,10 @@ static int pi433_probe(struct spi_device *spi)
/* spi->max_speed_hz = 10000000; 1MHz already set by device tree overlay */

retval = spi_setup(spi);
- if (retval)
- {
+ if (retval) {
dev_dbg(&spi->dev, "configuration of SPI interface failed!\n");
return retval;
- }
- else
- {
+ } else {
dev_dbg(&spi->dev,
"spi interface setup: mode 0x%2x, %d bits per word, %dhz max speed",
spi->mode, spi->bits_per_word, spi->max_speed_hz);
@@ -1124,8 +1087,7 @@ static int pi433_probe(struct spi_device *spi)
pr_err("pi433: device register failed\n");
retval = PTR_ERR(device->dev);
goto device_create_failed;
- }
- else {
+ } else {
dev_dbg(device->dev,
"created device for major %d, minor %d\n",
MAJOR(pi433_dev),
diff --git a/drivers/staging/pi433/pi433_if.h b/drivers/staging/pi433/pi433_if.h
index e6ed3cd9b2e2..bae6478516e5 100644
--- a/drivers/staging/pi433/pi433_if.h
+++ b/drivers/staging/pi433/pi433_if.h
@@ -34,7 +34,6 @@

/*---------------------------------------------------------------------------*/

-
/*---------------------------------------------------------------------------*/

/* IOCTL structs and commands */
@@ -57,9 +56,8 @@
*
* NOTE: struct layout is the same in 64bit and 32bit userspace.
*/
-#define PI433_TX_CFG_IOCTL_NR 0
-struct pi433_tx_cfg
-{
+#define PI433_TX_CFG_IOCTL_NR 0
+struct pi433_tx_cfg {
__u32 frequency;
__u16 bit_rate;
__u32 dev_frequency;
@@ -72,7 +70,6 @@ struct pi433_tx_cfg

__u16 repetitions;

-
/* packet format */
enum optionOnOff enable_preamble;
enum optionOnOff enable_sync;
@@ -88,7 +85,6 @@ struct pi433_tx_cfg
__u8 address_byte;
};

-
/**
* struct pi433_rx_config - describes the configuration of the radio module for sending
* @frequency:
@@ -107,7 +103,7 @@ struct pi433_tx_cfg
*
* NOTE: struct layout is the same in 64bit and 32bit userspace.
*/
-#define PI433_RX_CFG_IOCTL_NR 1
+#define PI433_RX_CFG_IOCTL_NR 1
struct pi433_rx_cfg {
__u32 frequency;
__u16 bit_rate;
@@ -123,8 +119,6 @@ struct pi433_rx_cfg {
__u8 bw_exponent; /* during AFC: 0x8b */
enum dagc dagc;

-
-
/* packet format */
enum optionOnOff enable_sync;
enum optionOnOff enable_length_byte; /* should be used in combination with sync, only */
@@ -140,7 +134,6 @@ struct pi433_rx_cfg {
__u8 broadcast_address;
};

-
#define PI433_IOC_MAGIC 'r'

#define PI433_IOC_RD_TX_CFG _IOR(PI433_IOC_MAGIC, PI433_TX_CFG_IOCTL_NR, char[sizeof(struct pi433_tx_cfg)])
diff --git a/drivers/staging/pi433/rf69.c b/drivers/staging/pi433/rf69.c
index e69a2153c999..db7c319711ab 100644
--- a/drivers/staging/pi433/rf69.c
+++ b/drivers/staging/pi433/rf69.c
@@ -29,11 +29,11 @@
#include "rf69_registers.h"

#define F_OSC 32000000 /* in Hz */
-#define FIFO_SIZE 66 /* in byte */
+#define FIFO_SIZE 66 /* in byte */

/*-------------------------------------------------------------------------*/

-#define READ_REG(x) rf69_read_reg (spi, x)
+#define READ_REG(x) rf69_read_reg(spi, x)
#define WRITE_REG(x, y) rf69_write_reg(spi, x, y)

/*-------------------------------------------------------------------------*/
@@ -58,7 +58,6 @@ int rf69_set_mode(struct spi_device *spi, enum mode mode)
// we are using packet mode, so this check is not really needed
// but waiting for mode ready is necessary when going from sleep because the FIFO may not be immediately available from previous mode
//while (_mode == RF69_MODE_SLEEP && (READ_REG(REG_IRQFLAGS1) & RF_IRQFLAGS1_MODEREADY) == 0x00); // Wait for ModeReady
-
}

int rf69_set_data_mode(struct spi_device *spi, enum dataMode dataMode)
@@ -102,7 +101,7 @@ enum modulation rf69_get_modulation(struct spi_device *spi)

currentValue = READ_REG(REG_DATAMODUL);

- switch (currentValue & MASK_DATAMODUL_MODULATION_TYPE >> 3) { // TODO improvement: change 3 to define
+ switch (currentValue & (MASK_DATAMODUL_MODULATION_TYPE >> 3)) { // TODO improvement: change 3 to define
case DATAMODUL_MODULATION_TYPE_OOK: return OOK;
case DATAMODUL_MODULATION_TYPE_FSK: return FSK;
default: return undefined;
@@ -159,8 +158,8 @@ int rf69_set_bit_rate(struct spi_device *spi, u16 bitRate)
// calculate reg settings
bitRate_reg = (F_OSC / bitRate);

- msb = (bitRate_reg&0xff00) >> 8;
- lsb = (bitRate_reg&0xff);
+ msb = (bitRate_reg & 0xff00) >> 8;
+ lsb = (bitRate_reg & 0xff);

// transmit to RF 69
retval = WRITE_REG(REG_BITRATE_MSB, msb);
@@ -177,7 +176,7 @@ int rf69_set_bit_rate(struct spi_device *spi, u16 bitRate)
int rf69_set_deviation(struct spi_device *spi, u32 deviation)
{
int retval;
-// u32 f_max; TODO: Abhäigkeit von Bitrate beachten!!
+// u32 f_max; TODO: depends on bitrate
u64 f_reg;
u64 f_step;
u8 msb;
@@ -188,7 +187,7 @@ int rf69_set_deviation(struct spi_device *spi, u32 deviation)
dev_dbg(&spi->dev, "set: deviation");
#endif

- if (deviation < 600 || deviation > 500000) { //TODO: Abhäigkeit von Bitrate beachten!!
+ if (deviation < 600 || deviation > 500000) { //TODO: depends on bitrate
dev_dbg(&spi->dev, "set_deviation: illegal input param");
return -EINVAL;
}
@@ -201,8 +200,8 @@ int rf69_set_deviation(struct spi_device *spi, u32 deviation)
f_reg = deviation * factor;
do_div(f_reg, f_step);

- msb = (f_reg&0xff00) >> 8;
- lsb = (f_reg&0xff);
+ msb = (f_reg & 0xff00) >> 8;
+ lsb = (f_reg & 0xff);

// check msb
if (msb & ~FDEVMASB_MASK) {
@@ -252,9 +251,9 @@ int rf69_set_frequency(struct spi_device *spi, u32 frequency)
f_reg = frequency * factor;
do_div(f_reg, f_step);

- msb = (f_reg&0xff0000) >> 16;
- mid = (f_reg&0xff00) >> 8;
- lsb = (f_reg&0xff);
+ msb = (f_reg & 0xff0000) >> 16;
+ mid = (f_reg & 0xff00) >> 8;
+ lsb = (f_reg & 0xff);

// write to chip
retval = WRITE_REG(REG_FRF_MSB, msb);
@@ -323,7 +322,7 @@ int rf69_set_output_power_level(struct spi_device *spi, u8 powerLevel)
dev_dbg(&spi->dev, "set: power level");
#endif

- powerLevel += 18; // TODO Abhäigkeit von PA0,1,2 setting
+ powerLevel += 18; // TODO depends on PA0,1,2 setting

// check input value
if (powerLevel > 0x1f) {
@@ -409,7 +408,7 @@ enum lnaGain rf69_get_lna_gain(struct spi_device *spi)

currentValue = READ_REG(REG_LNA);

- switch (currentValue & MASK_LNA_CURRENT_GAIN >> 3) { // improvement: change 3 to define
+ switch (currentValue & (MASK_LNA_CURRENT_GAIN >> 3)) { // improvement: change 3 to define
case LNA_GAIN_AUTO: return automatic;
case LNA_GAIN_MAX: return max;
case LNA_GAIN_MAX_MINUS_6: return maxMinus6;
@@ -467,9 +466,9 @@ static int rf69_set_bandwidth_intern(struct spi_device *spi, u8 reg,
return -EINVAL;
}

- if ((mantisse != mantisse16) &&
- (mantisse != mantisse20) &&
- (mantisse != mantisse24)) {
+ if (mantisse != mantisse16 &&
+ mantisse != mantisse20 &&
+ mantisse != mantisse24) {
dev_dbg(&spi->dev, "set: illegal input param");
return -EINVAL;
}
@@ -710,8 +709,8 @@ int rf69_set_preamble_length(struct spi_device *spi, u16 preambleLength)
/* no value check needed - u16 exactly matches register size */

/* calculate reg settings */
- msb = (preambleLength&0xff00) >> 8;
- lsb = (preambleLength&0xff);
+ msb = (preambleLength & 0xff00) >> 8;
+ lsb = (preambleLength & 0xff);

/* transmit to chip */
retval = WRITE_REG(REG_PREAMBLE_MSB, msb);
@@ -863,7 +862,7 @@ u8 rf69_get_payload_length(struct spi_device *spi)
dev_dbg(&spi->dev, "get: payload length");
#endif

- return (u8) READ_REG(REG_PAYLOAD_LENGTH);
+ return (u8)READ_REG(REG_PAYLOAD_LENGTH);
}

int rf69_set_node_address(struct spi_device *spi, u8 nodeAddress)
@@ -940,7 +939,7 @@ int rf69_set_dagc(struct spi_device *spi, enum dagc dagc)

/*-------------------------------------------------------------------------*/

-int rf69_read_fifo (struct spi_device *spi, u8 *buffer, unsigned int size)
+int rf69_read_fifo(struct spi_device *spi, u8 *buffer, unsigned int size)
{
#ifdef DEBUG_FIFO_ACCESS
int i;
@@ -950,9 +949,9 @@ int rf69_read_fifo (struct spi_device *spi, u8 *buffer, unsigned int size)
int retval;

if (size > FIFO_SIZE) {
- #ifdef DEBUG
- dev_dbg(&spi->dev, "read fifo: passed in buffer bigger then internal buffer \n");
- #endif
+#ifdef DEBUG
+ dev_dbg(&spi->dev, "read fifo: passed in buffer bigger then internal buffer\n");
+#endif
return -EMSGSIZE;
}

@@ -961,16 +960,16 @@ int rf69_read_fifo (struct spi_device *spi, u8 *buffer, unsigned int size)
memset(&transfer, 0, sizeof(transfer));
transfer.tx_buf = local_buffer;
transfer.rx_buf = local_buffer;
- transfer.len = size+1;
+ transfer.len = size + 1;

retval = spi_sync_transfer(spi, &transfer, 1);

#ifdef DEBUG_FIFO_ACCESS
for (i = 0; i < size; i++)
- dev_dbg(&spi->dev, "%d - 0x%x\n", i, local_buffer[i+1]);
+ dev_dbg(&spi->dev, "%d - 0x%x\n", i, local_buffer[i + 1]);
#endif

- memcpy(buffer, &local_buffer[1], size); // TODO: ohne memcopy wä schö
+ memcpy(buffer, &local_buffer[1], size); // TODO: try to avoid memcopy

return retval;
}
@@ -984,21 +983,21 @@ int rf69_write_fifo(struct spi_device *spi, u8 *buffer, unsigned int size)
u8 local_buffer[FIFO_SIZE + 1];

if (size > FIFO_SIZE) {
- #ifdef DEBUG
- dev_dbg(&spi->dev, "read fifo: passed in buffer bigger then internal buffer \n");
- #endif
+#ifdef DEBUG
+ dev_dbg(&spi->dev, "read fifo: passed in buffer bigger then internal buffer\n");
+#endif
return -EMSGSIZE;
}

local_buffer[0] = spi_address;
- memcpy(&local_buffer[1], buffer, size); // TODO: ohne memcopy wä schö
+ memcpy(&local_buffer[1], buffer, size); // TODO: try to avoid memcopy

#ifdef DEBUG_FIFO_ACCESS
for (i = 0; i < size; i++)
dev_dbg(&spi->dev, "0x%x\n", buffer[i]);
#endif

- return spi_write (spi, local_buffer, size + 1);
+ return spi_write(spi, local_buffer, size + 1);
}

/*-------------------------------------------------------------------------*/
@@ -1054,4 +1053,3 @@ int rf69_write_reg(struct spi_device *spi, u8 addr, u8 value)
return retval;
}

-
diff --git a/drivers/staging/pi433/rf69.h b/drivers/staging/pi433/rf69.h
index 5c0c95628f2f..e3d881f2c3ac 100644
--- a/drivers/staging/pi433/rf69.h
+++ b/drivers/staging/pi433/rf69.h
@@ -72,11 +72,10 @@ int rf69_set_tx_start_condition(struct spi_device *spi, enum txStartCondition tx
int rf69_set_fifo_threshold(struct spi_device *spi, u8 threshold);
int rf69_set_dagc(struct spi_device *spi, enum dagc dagc);

-int rf69_read_fifo (struct spi_device *spi, u8 *buffer, unsigned int size);
+int rf69_read_fifo(struct spi_device *spi, u8 *buffer, unsigned int size);
int rf69_write_fifo(struct spi_device *spi, u8 *buffer, unsigned int size);

-u8 rf69_read_reg (struct spi_device *spi, u8 addr);
+u8 rf69_read_reg(struct spi_device *spi, u8 addr);
int rf69_write_reg(struct spi_device *spi, u8 addr, u8 value);

-
#endif
diff --git a/drivers/staging/pi433/rf69_enum.h b/drivers/staging/pi433/rf69_enum.h
index fbfb59bd3f3d..943bb31e7f79 100644
--- a/drivers/staging/pi433/rf69_enum.h
+++ b/drivers/staging/pi433/rf69_enum.h
@@ -18,184 +18,164 @@
#ifndef RF69_ENUM_H
#define RF69_ENUM_H

-enum optionOnOff
-{
- optionOff,
- optionOn
-};
-
-enum mode
-{
- mode_sleep,
- standby,
- synthesizer,
- transmit,
- receive
-};
-
-enum dataMode
-{
- packet,
- continuous,
- continuousNoSync
-};
-
-enum modulation
-{
- OOK,
- FSK
-};
-
-enum modShaping
-{
- shapingOff,
- shaping1_0,
- shaping0_5,
- shaping0_3,
- shapingBR,
- shaping2BR
-};
-
-enum paRamp
-{
- ramp3400,
- ramp2000,
- ramp1000,
- ramp500,
- ramp250,
- ramp125,
- ramp100,
- ramp62,
- ramp50,
- ramp40,
- ramp31,
- ramp25,
- ramp20,
- ramp15,
- ramp12,
- ramp10
-};
-
-enum antennaImpedance
-{
- fiftyOhm,
- twohundretOhm
-};
-
-enum lnaGain
-{
- automatic,
- max,
- maxMinus6,
- maxMinus12,
- maxMinus24,
- maxMinus36,
- maxMinus48,
- undefined
-};
-
-enum dccPercent
-{
- dcc16Percent,
- dcc8Percent,
- dcc4Percent,
- dcc2Percent,
- dcc1Percent,
- dcc0_5Percent,
- dcc0_25Percent,
- dcc0_125Percent
-};
-
-enum mantisse
-{
- mantisse16,
- mantisse20,
- mantisse24
-};
-
-enum thresholdType
-{
- fixed,
- peak,
- average
-};
-
-enum thresholdStep
-{
- step_0_5db,
- step_1_0db,
- step_1_5db,
- step_2_0db,
- step_3_0db,
- step_4_0db,
- step_5_0db,
- step_6_0db
-};
-
-enum thresholdDecrement
-{
- dec_every8th,
- dec_every4th,
- dec_every2nd,
- dec_once,
- dec_twice,
- dec_4times,
- dec_8times,
- dec_16times
-};
-
-enum flag
-{
- modeSwitchCompleted,
- readyToReceive,
- readyToSend,
- pllLocked,
- rssiExceededThreshold,
- timeout,
- automode,
- syncAddressMatch,
- fifoFull,
+enum optionOnOff {
+ optionOff,
+ optionOn
+};
+
+enum mode {
+ mode_sleep,
+ standby,
+ synthesizer,
+ transmit,
+ receive
+};
+
+enum dataMode {
+ packet,
+ continuous,
+ continuousNoSync
+};
+
+enum modulation {
+ OOK,
+ FSK
+};
+
+enum modShaping {
+ shapingOff,
+ shaping1_0,
+ shaping0_5,
+ shaping0_3,
+ shapingBR,
+ shaping2BR
+};
+
+enum paRamp {
+ ramp3400,
+ ramp2000,
+ ramp1000,
+ ramp500,
+ ramp250,
+ ramp125,
+ ramp100,
+ ramp62,
+ ramp50,
+ ramp40,
+ ramp31,
+ ramp25,
+ ramp20,
+ ramp15,
+ ramp12,
+ ramp10
+};
+
+enum antennaImpedance {
+ fiftyOhm,
+ twohundretOhm
+};
+
+enum lnaGain {
+ automatic,
+ max,
+ maxMinus6,
+ maxMinus12,
+ maxMinus24,
+ maxMinus36,
+ maxMinus48,
+ undefined
+};
+
+enum dccPercent {
+ dcc16Percent,
+ dcc8Percent,
+ dcc4Percent,
+ dcc2Percent,
+ dcc1Percent,
+ dcc0_5Percent,
+ dcc0_25Percent,
+ dcc0_125Percent
+};
+
+enum mantisse {
+ mantisse16,
+ mantisse20,
+ mantisse24
+};
+
+enum thresholdType {
+ fixed,
+ peak,
+ average
+};
+
+enum thresholdStep {
+ step_0_5db,
+ step_1_0db,
+ step_1_5db,
+ step_2_0db,
+ step_3_0db,
+ step_4_0db,
+ step_5_0db,
+ step_6_0db
+};
+
+enum thresholdDecrement {
+ dec_every8th,
+ dec_every4th,
+ dec_every2nd,
+ dec_once,
+ dec_twice,
+ dec_4times,
+ dec_8times,
+ dec_16times
+};
+
+enum flag {
+ modeSwitchCompleted,
+ readyToReceive,
+ readyToSend,
+ pllLocked,
+ rssiExceededThreshold,
+ timeout,
+ automode,
+ syncAddressMatch,
+ fifoFull,
// fifoNotEmpty, collision with next enum; replaced by following enum...
- fifoEmpty,
- fifoLevelBelowThreshold,
- fifoOverrun,
- packetSent,
- payloadReady,
- crcOk,
- batteryLow
+ fifoEmpty,
+ fifoLevelBelowThreshold,
+ fifoOverrun,
+ packetSent,
+ payloadReady,
+ crcOk,
+ batteryLow
};

-enum fifoFillCondition
-{
- afterSyncInterrupt,
- always
+enum fifoFillCondition {
+ afterSyncInterrupt,
+ always
};

-enum packetFormat
-{
- packetLengthFix,
- packetLengthVar
+enum packetFormat {
+ packetLengthFix,
+ packetLengthVar
};

-enum txStartCondition
-{
- fifoLevel,
- fifoNotEmpty
+enum txStartCondition {
+ fifoLevel,
+ fifoNotEmpty
};

-enum addressFiltering
-{
- filteringOff,
- nodeAddress,
- nodeOrBroadcastAddress
+enum addressFiltering {
+ filteringOff,
+ nodeAddress,
+ nodeOrBroadcastAddress
};

-enum dagc
-{
- normalMode,
- improve,
- improve4LowModulationIndex
+enum dagc {
+ normalMode,
+ improve,
+ improve4LowModulationIndex
};

-
#endif
diff --git a/drivers/staging/pi433/rf69_registers.h b/drivers/staging/pi433/rf69_registers.h
index 6335d42142fe..4f1e81530831 100644
--- a/drivers/staging/pi433/rf69_registers.h
+++ b/drivers/staging/pi433/rf69_registers.h
@@ -188,8 +188,6 @@
#define MASK_PALEVEL_PA2 0x20
#define MASK_PALEVEL_OUTPUT_POWER 0x1F

-
-
// RegPaRamp
#define PARAMP_3400 0x00
#define PARAMP_2000 0x01
@@ -246,7 +244,6 @@
#define LNA_GAIN_MAX_MINUS_36 0x05
#define LNA_GAIN_MAX_MINUS_48 0x06

-
/* RegRxBw (0x19) and RegAfcBw (0x1A) */
#define MASK_BW_DCC_FREQ 0xE0
#define MASK_BW_MANTISSE 0x18
@@ -265,7 +262,6 @@
#define BW_MANT_20 0x08
#define BW_MANT_24 0x10 /* default */

-
/* RegOokPeak (0x1B) */
#define MASK_OOKPEAK_THRESTYPE 0xc0
#define MASK_OOKPEAK_THRESSTEP 0x38
--
2.15.1