aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/pi433
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/staging/pi433')
-rw-r--r--drivers/staging/pi433/Kconfig1
-rw-r--r--drivers/staging/pi433/Makefile1
-rw-r--r--drivers/staging/pi433/pi433_if.c40
-rw-r--r--drivers/staging/pi433/rf69.c49
4 files changed, 59 insertions, 32 deletions
diff --git a/drivers/staging/pi433/Kconfig b/drivers/staging/pi433/Kconfig
index c7340129dd4c..8acde0814206 100644
--- a/drivers/staging/pi433/Kconfig
+++ b/drivers/staging/pi433/Kconfig
@@ -1,3 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0
config PI433
tristate "Pi433 - a 433MHz radio module for Raspberry Pi"
depends on SPI
diff --git a/drivers/staging/pi433/Makefile b/drivers/staging/pi433/Makefile
index 417f3e4d12b1..051132fe4dae 100644
--- a/drivers/staging/pi433/Makefile
+++ b/drivers/staging/pi433/Makefile
@@ -1,3 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0
obj-$(CONFIG_PI433) += pi433.o
pi433-objs := pi433_if.o rf69.o
diff --git a/drivers/staging/pi433/pi433_if.c b/drivers/staging/pi433/pi433_if.c
index b2314636dc89..c889f0bdf424 100644
--- a/drivers/staging/pi433/pi433_if.c
+++ b/drivers/staging/pi433/pi433_if.c
@@ -45,10 +45,10 @@
#include "pi433_if.h"
#include "rf69.h"
-#define N_PI433_MINORS BIT(MINORBITS) /*32*/ /* ... up to 256 */
-#define MAX_MSG_SIZE 900 /* min: FIFO_SIZE! */
-#define MSG_FIFO_SIZE 65536 /* 65536 = 2^16 */
-#define NUM_DIO 2
+#define N_PI433_MINORS BIT(MINORBITS) /*32*/ /* ... up to 256 */
+#define MAX_MSG_SIZE 900 /* min: FIFO_SIZE! */
+#define MSG_FIFO_SIZE 65536 /* 65536 = 2^16 */
+#define NUM_DIO 2
static dev_t pi433_dev;
static DEFINE_IDR(pi433_idr);
@@ -319,6 +319,12 @@ rf69_set_tx_cfg(struct pi433_device *dev, struct pi433_tx_cfg *tx_cfg)
}
if (tx_cfg->enable_sync == OPTION_ON) {
+ ret = rf69_set_sync_size(dev->spi, tx_cfg->sync_length);
+ if (ret < 0)
+ return ret;
+ ret = rf69_set_sync_values(dev->spi, tx_cfg->sync_pattern);
+ if (ret < 0)
+ return ret;
ret = rf69_enable_sync(dev->spi);
if (ret < 0)
return ret;
@@ -348,16 +354,6 @@ rf69_set_tx_cfg(struct pi433_device *dev, struct pi433_tx_cfg *tx_cfg)
return ret;
}
- /* configure sync, if enabled */
- if (tx_cfg->enable_sync == OPTION_ON) {
- ret = rf69_set_sync_size(dev->spi, tx_cfg->sync_length);
- if (ret < 0)
- return ret;
- ret = rf69_set_sync_values(dev->spi, tx_cfg->sync_pattern);
- if (ret < 0)
- return ret;
- }
-
return 0;
}
@@ -650,21 +646,19 @@ pi433_tx_thread(void *data)
disable_irq(device->irq_num[DIO0]);
device->tx_active = true;
+ /* clear fifo, set fifo threshold, set payload length */
+ retval = rf69_set_mode(spi, standby); /* this clears the fifo */
+ if (retval < 0)
+ return retval;
+
if (device->rx_active && !rx_interrupted) {
/*
* rx is currently waiting for a telegram;
* we need to set the radio module to standby
*/
- retval = rf69_set_mode(device->spi, standby);
- if (retval < 0)
- return retval;
rx_interrupted = true;
}
- /* clear fifo, set fifo threshold, set payload length */
- retval = rf69_set_mode(spi, standby); /* this clears the fifo */
- if (retval < 0)
- return retval;
retval = rf69_set_fifo_threshold(spi, FIFO_THRESHOLD);
if (retval < 0)
return retval;
@@ -742,7 +736,7 @@ pi433_tx_thread(void *data)
device->free_in_fifo == FIFO_SIZE ||
kthread_should_stop());
if (kthread_should_stop())
- dev_dbg(device->dev, "ABORT\n");
+ return 0;
/* STOP_TRANSMISSION */
dev_dbg(device->dev, "thread: Packet sent. Set mode to stby.");
@@ -971,7 +965,7 @@ static int pi433_open(struct inode *inode, struct file *filp)
/* instance data as context */
filp->private_data = instance;
- nonseekable_open(inode, filp);
+ stream_open(inode, filp);
return 0;
}
diff --git a/drivers/staging/pi433/rf69.c b/drivers/staging/pi433/rf69.c
index e19b9ce794a8..4cd16257f0aa 100644
--- a/drivers/staging/pi433/rf69.c
+++ b/drivers/staging/pi433/rf69.c
@@ -349,18 +349,51 @@ int rf69_disable_amplifier(struct spi_device *spi, u8 amplifier_mask)
int rf69_set_output_power_level(struct spi_device *spi, u8 power_level)
{
- // TODO: Dependency to PA0,1,2 setting
- power_level += 18;
+ u8 pa_level, ocp, test_pa1, test_pa2;
+ bool pa0, pa1, pa2, high_power;
+ u8 min_power_level;
+
+ // check register pa_level
+ pa_level = rf69_read_reg(spi, REG_PALEVEL);
+ pa0 = pa_level & MASK_PALEVEL_PA0;
+ pa1 = pa_level & MASK_PALEVEL_PA1;
+ pa2 = pa_level & MASK_PALEVEL_PA2;
+
+ // check high power mode
+ ocp = rf69_read_reg(spi, REG_OCP);
+ test_pa1 = rf69_read_reg(spi, REG_TESTPA1);
+ test_pa2 = rf69_read_reg(spi, REG_TESTPA2);
+ high_power = (ocp == 0x0f) && (test_pa1 == 0x5d) && (test_pa2 == 0x7c);
+
+ if (pa0 && !pa1 && !pa2) {
+ power_level += 18;
+ min_power_level = 0;
+ } else if (!pa0 && pa1 && !pa2) {
+ power_level += 18;
+ min_power_level = 16;
+ } else if (!pa0 && pa1 && pa2) {
+ if (high_power)
+ power_level += 11;
+ else
+ power_level += 14;
+ min_power_level = 16;
+ } else {
+ goto failed;
+ }
// check input value
- if (power_level > 0x1f) {
- dev_dbg(&spi->dev, "set: illegal input param");
- return -EINVAL;
- }
+ if (power_level > 0x1f)
+ goto failed;
+
+ if (power_level < min_power_level)
+ goto failed;
// write value
return rf69_read_mod_write(spi, REG_PALEVEL, MASK_PALEVEL_OUTPUT_POWER,
power_level);
+failed:
+ dev_dbg(&spi->dev, "set: illegal input param");
+ return -EINVAL;
}
int rf69_set_pa_ramp(struct spi_device *spi, enum pa_ramp pa_ramp)
@@ -624,9 +657,7 @@ int rf69_set_preamble_length(struct spi_device *spi, u16 preamble_length)
retval = rf69_write_reg(spi, REG_PREAMBLE_MSB, msb);
if (retval)
return retval;
- retval = rf69_write_reg(spi, REG_PREAMBLE_LSB, lsb);
-
- return retval;
+ return rf69_write_reg(spi, REG_PREAMBLE_LSB, lsb);
}
int rf69_enable_sync(struct spi_device *spi)