summaryrefslogtreecommitdiff
path: root/drivers/staging
diff options
context:
space:
mode:
authorPaulo Miguel Almeida <paulo.miguel.almeida.rodenas@gmail.com>2022-01-04 11:23:34 +1300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2022-01-06 15:00:27 +0100
commit70d8e20c24a4ef42ee200cc7b7b93a01f0ebaa0e (patch)
tree3ce4c54949babba74240eb42bfe72e826b1560e2 /drivers/staging
parentb33721baccd5d4e6651cd8f619524a316ff22cd3 (diff)
staging: pi433: fix frequency deviation check
rf69 datasheet states that frequency deviation must exceed 600 Hz but also that frequency deviation + (bitrate / 2) should be less than equal to 500 kHz to ensure proper modulation. This patch validates that both conditions are met so RF intersymbol interference is less likely to happen due to misconfiguration of the uC Signed-off-by: Paulo Miguel Almeida <paulo.miguel.almeida.rodenas@gmail.com> Link: https://lore.kernel.org/r/20220103222334.GA6814@mail.google.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/staging')
-rw-r--r--drivers/staging/pi433/rf69.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/drivers/staging/pi433/rf69.c b/drivers/staging/pi433/rf69.c
index e62e61ef4d27..d64df072d8e8 100644
--- a/drivers/staging/pi433/rf69.c
+++ b/drivers/staging/pi433/rf69.c
@@ -255,13 +255,25 @@ int rf69_set_deviation(struct spi_device *spi, u32 deviation)
int retval;
u64 f_reg;
u64 f_step;
+ u32 bit_rate_reg;
+ u32 bit_rate;
u8 msb;
u8 lsb;
u64 factor = 1000000; // to improve precision of calculation
- // TODO: Dependency to bitrate
- if (deviation < 600 || deviation > 500000) {
- dev_dbg(&spi->dev, "set_deviation: illegal input param");
+ // calculate bit rate
+ bit_rate_reg = rf69_read_reg(spi, REG_BITRATE_MSB) << 8;
+ bit_rate_reg |= rf69_read_reg(spi, REG_BITRATE_LSB);
+ bit_rate = F_OSC / bit_rate_reg;
+
+ /*
+ * frequency deviation must exceed 600 Hz but not exceed
+ * 500kHz when taking bitrate dependency into consideration
+ * to ensure proper modulation
+ */
+ if (deviation < 600 || (deviation + (bit_rate / 2)) > 500000) {
+ dev_dbg(&spi->dev,
+ "set_deviation: illegal input param: %u", deviation);
return -EINVAL;
}