From 3df3162f1d52c143f48fb213d8d2c7fcce5b41d5 Mon Sep 17 00:00:00 2001 From: Bhagyashri Dighole Date: Thu, 14 Mar 2019 00:37:17 +0530 Subject: staging: pi433: Remove unused variable. Remove unused variable which is used to store return value, Detected by Coccinelle semantic patch returnvar.cocci Signed-off-by: Bhagyashri Dighole Signed-off-by: Greg Kroah-Hartman --- drivers/staging/pi433/rf69.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'drivers/staging/pi433') diff --git a/drivers/staging/pi433/rf69.c b/drivers/staging/pi433/rf69.c index e19b9ce794a8..340ffa7ccf18 100644 --- a/drivers/staging/pi433/rf69.c +++ b/drivers/staging/pi433/rf69.c @@ -624,9 +624,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) -- cgit v1.2.3 From 8f51bd83e4438fed92a9b4bb062eae7cd5a6c074 Mon Sep 17 00:00:00 2001 From: Jules Irenge Date: Thu, 21 Mar 2019 19:54:08 +0000 Subject: staging: pi433: remove empty space to fix line over 80 characters warning Remove empty space to solve checkpatch.pl warning: "WARNING: line over 80 characters". Signed-off-by: Jules Irenge Signed-off-by: Greg Kroah-Hartman --- drivers/staging/pi433/pi433_if.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'drivers/staging/pi433') diff --git a/drivers/staging/pi433/pi433_if.c b/drivers/staging/pi433/pi433_if.c index b2314636dc89..53928af696a6 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); -- cgit v1.2.3 From e5adddf5ae97811abe917b267a0d11daec5ccc16 Mon Sep 17 00:00:00 2001 From: Sidong Yang Date: Sun, 24 Mar 2019 14:54:41 +0000 Subject: staging: pi433: remove unnecessary calling rf69_set_mode() Remove unnecessary rf69_set_mode() function call when rx is waiting for a telegram. There is waste to call rf69_set_mode() twice for becoming standby mode. Signed-off-by: Sidong Yang Signed-off-by: Greg Kroah-Hartman --- drivers/staging/pi433/pi433_if.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'drivers/staging/pi433') diff --git a/drivers/staging/pi433/pi433_if.c b/drivers/staging/pi433/pi433_if.c index 53928af696a6..e822f87fc533 100644 --- a/drivers/staging/pi433/pi433_if.c +++ b/drivers/staging/pi433/pi433_if.c @@ -650,21 +650,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; -- cgit v1.2.3 From 81a6e1cc312ea43b4a23e6f371dda1bd233ea750 Mon Sep 17 00:00:00 2001 From: Sidong Yang Date: Thu, 28 Mar 2019 09:49:14 +0000 Subject: staging: pi433: Fix rf69_set_tx_cfg() logic Moved code to configure sync to where check enable_sync option before. There is no need to check enable_sync twice. Configuring sync should be executed immediately after enabling sync. Signed-off-by: Sidong Yang Signed-off-by: Greg Kroah-Hartman --- drivers/staging/pi433/pi433_if.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'drivers/staging/pi433') diff --git a/drivers/staging/pi433/pi433_if.c b/drivers/staging/pi433/pi433_if.c index e822f87fc533..ab90d6f80931 100644 --- a/drivers/staging/pi433/pi433_if.c +++ b/drivers/staging/pi433/pi433_if.c @@ -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; } -- cgit v1.2.3 From a35342d0f8b348fad38e6250f9b646b99aa210c7 Mon Sep 17 00:00:00 2001 From: Sidong Yang Date: Tue, 2 Apr 2019 12:14:31 +0000 Subject: staging: pi433: Return thread immediately when kthread_should_stop() call. When kthread_stop() called by removing module, running thread should return immediately. Otherwise, It is very dangerous that thread may access any released data like struct pi433_device. Signed-off-by: Sidong Yang Signed-off-by: Greg Kroah-Hartman --- drivers/staging/pi433/pi433_if.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/staging/pi433') diff --git a/drivers/staging/pi433/pi433_if.c b/drivers/staging/pi433/pi433_if.c index ab90d6f80931..16dc380eb176 100644 --- a/drivers/staging/pi433/pi433_if.c +++ b/drivers/staging/pi433/pi433_if.c @@ -736,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."); -- cgit v1.2.3 From 99b75a4e3275e85814db0fa2f49274bd3d5359d3 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Tue, 2 Apr 2019 12:31:48 +0200 Subject: staging: add missing SPDX lines to Kconfig files There are a few remaining drivers/staging/*/Kconfig files that do not have SPDX identifiers in them. Add the correct GPL-2.0 identifier to them to make scanning tools happy. Signed-off-by: Greg Kroah-Hartman --- drivers/staging/pi433/Kconfig | 1 + 1 file changed, 1 insertion(+) (limited to 'drivers/staging/pi433') 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 -- cgit v1.2.3 From 97ed8eab2a0067bee21aa634c938454660e76a38 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Tue, 2 Apr 2019 12:31:49 +0200 Subject: staging: add missing SPDX lines to Makefile files There are a few remaining drivers/staging/*/Makefile files that do not have SPDX identifiers in them. Add the correct GPL-2.0 identifier to them to make scanning tools happy. Reviewed-by: Mukesh Ojha Signed-off-by: Greg Kroah-Hartman --- drivers/staging/pi433/Makefile | 1 + 1 file changed, 1 insertion(+) (limited to 'drivers/staging/pi433') 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 -- cgit v1.2.3 From 7be2b288be66e08d78ede27d8ab0adb61b30d4db Mon Sep 17 00:00:00 2001 From: Sidong Yang Date: Wed, 10 Apr 2019 05:09:06 +0000 Subject: staging: pi433: add dependency to PA0, 1, 2 setting for output power level When setting output power level called, the power level should be checked by power amplifier level register and high power option. There was todo about it. Add some variables for checking power level range. The values that used for checking high power or minimum power are from rf69 datasheets. The maximum power level is always same regardless of mode. Signed-off-by: Sidong Yang Signed-off-by: Greg Kroah-Hartman --- drivers/staging/pi433/rf69.c | 45 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) (limited to 'drivers/staging/pi433') diff --git a/drivers/staging/pi433/rf69.c b/drivers/staging/pi433/rf69.c index 340ffa7ccf18..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) -- cgit v1.2.3