diff mbox series

[lora-next,v2,6/8] net: lora: sx1301: replace version and size magic numbers with defines

Message ID 1533818018-29005-6-git-send-email-ben.whitten@lairdtech.com
State Not Applicable, archived
Delegated to: David Miller
Headers show
Series [lora-next,v2,1/8] net: lora: add methods for devm registration | expand

Commit Message

Ben Whitten Aug. 9, 2018, 12:33 p.m. UTC
We replace the hard coded numbers for size and version with meaningful
names.

Signed-off-by: Ben Whitten <ben.whitten@lairdtech.com>
---
 drivers/net/lora/sx1301.c | 21 +++++++++++++--------
 drivers/net/lora/sx1301.h | 18 ++++++++++++++++++
 2 files changed, 31 insertions(+), 8 deletions(-)
 create mode 100644 drivers/net/lora/sx1301.h

Comments

Andreas Färber Aug. 9, 2018, 9:11 p.m. UTC | #1
Am 09.08.2018 um 14:33 schrieb Ben Whitten:
> We replace the hard coded numbers for size and version with meaningful
> names.
> 
> Signed-off-by: Ben Whitten <ben.whitten@lairdtech.com>
> ---
>  drivers/net/lora/sx1301.c | 21 +++++++++++++--------
>  drivers/net/lora/sx1301.h | 18 ++++++++++++++++++
>  2 files changed, 31 insertions(+), 8 deletions(-)
>  create mode 100644 drivers/net/lora/sx1301.h
> 
> diff --git a/drivers/net/lora/sx1301.c b/drivers/net/lora/sx1301.c
> index 916ee40..8e81179 100644
> --- a/drivers/net/lora/sx1301.c
> +++ b/drivers/net/lora/sx1301.c
> @@ -21,6 +21,8 @@
>  #include <linux/lora/dev.h>
>  #include <linux/spi/spi.h>
>  
> +#include "sx1301.h"
> +
>  #define REG_PAGE_RESET			0
>  #define REG_VERSION			1
>  #define REG_MCU_PROM_ADDR		9
> @@ -293,7 +295,7 @@ static int sx1301_load_firmware(struct sx1301_priv *priv, int mcu, const struct
>  	u8 val, rst, select_mux;
>  	int ret;
>  
> -	if (fw->size != 8192) {
> +	if (fw->size != SX1301_MCU_FW_BYTE) {

I think that should be BYTES, but we can still rename it later.

>  		dev_err(priv->dev, "Unexpected firmware size\n");
>  		return -EINVAL;
>  	}
[...]
> diff --git a/drivers/net/lora/sx1301.h b/drivers/net/lora/sx1301.h
> new file mode 100644
> index 0000000..b37ac56
> --- /dev/null
> +++ b/drivers/net/lora/sx1301.h
> @@ -0,0 +1,18 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later

Header files must use /* ... */ or checkpatch.pl complains.

> +/*
> + * Semtech SX1301 lora concentrator

LoRa

> + *
> + * Copyright (c) 2018   Ben Whitten

Any reason for the multiple whitespaces?

> + */
> +
> +#ifndef _SX1301_
> +#define _SX1301_
> +
> +#define SX1301_CHIP_VERSION 103
> +
> +#define SX1301_MCU_FW_BYTE 8192
> +#define SX1301_MCU_ARB_FW_VERSION 1
> +#define SX1301_MCU_AGC_FW_VERSION 4
> +#define SX1301_MCU_AGC_CAL_FW_VERSION 2
> +
> +#endif

Applied.

Thanks,
Andreas
diff mbox series

Patch

diff --git a/drivers/net/lora/sx1301.c b/drivers/net/lora/sx1301.c
index 916ee40..8e81179 100644
--- a/drivers/net/lora/sx1301.c
+++ b/drivers/net/lora/sx1301.c
@@ -21,6 +21,8 @@ 
 #include <linux/lora/dev.h>
 #include <linux/spi/spi.h>
 
+#include "sx1301.h"
+
 #define REG_PAGE_RESET			0
 #define REG_VERSION			1
 #define REG_MCU_PROM_ADDR		9
@@ -293,7 +295,7 @@  static int sx1301_load_firmware(struct sx1301_priv *priv, int mcu, const struct
 	u8 val, rst, select_mux;
 	int ret;
 
-	if (fw->size != 8192) {
+	if (fw->size != SX1301_MCU_FW_BYTE) {
 		dev_err(priv->dev, "Unexpected firmware size\n");
 		return -EINVAL;
 	}
@@ -445,8 +447,9 @@  static int sx1301_agc_calibrate(struct sx1301_priv *priv)
 
 	dev_info(priv->dev, "AGC calibration firmware version %u\n", (unsigned)val);
 
-	if (val != 2) {
-		dev_err(priv->dev, "unexpected firmware version, expecting %u\n", 2);
+	if (val != SX1301_MCU_AGC_CAL_FW_VERSION) {
+		dev_err(priv->dev, "unexpected firmware version, expecting %u\n",
+				SX1301_MCU_AGC_CAL_FW_VERSION);
 		return -ENXIO;
 	}
 
@@ -572,8 +575,9 @@  static int sx1301_load_all_firmware(struct sx1301_priv *priv)
 
 	dev_info(priv->dev, "AGC firmware version %u\n", (unsigned)val);
 
-	if (val != 4) {
-		dev_err(priv->dev, "unexpected firmware version, expecting %u\n", 4);
+	if (val != SX1301_MCU_AGC_FW_VERSION) {
+		dev_err(priv->dev, "unexpected firmware version, expecting %u\n",
+				SX1301_MCU_AGC_FW_VERSION);
 		return -ENXIO;
 	}
 
@@ -585,8 +589,9 @@  static int sx1301_load_all_firmware(struct sx1301_priv *priv)
 
 	dev_info(priv->dev, "ARB firmware version %u\n", (unsigned)val);
 
-	if (val != 1) {
-		dev_err(priv->dev, "unexpected firmware version, expecting %u\n", 1);
+	if (val != SX1301_MCU_ARB_FW_VERSION) {
+		dev_err(priv->dev, "unexpected firmware version, expecting %u\n",
+				SX1301_MCU_ARB_FW_VERSION);
 		return -ENXIO;
 	}
 
@@ -642,7 +647,7 @@  static int sx1301_probe(struct spi_device *spi)
 		return ret;
 	}
 
-	if (val != 103) {
+	if (val != SX1301_CHIP_VERSION) {
 		dev_err(&spi->dev, "unexpected version: %u\n", val);
 		return -ENXIO;
 	}
diff --git a/drivers/net/lora/sx1301.h b/drivers/net/lora/sx1301.h
new file mode 100644
index 0000000..b37ac56
--- /dev/null
+++ b/drivers/net/lora/sx1301.h
@@ -0,0 +1,18 @@ 
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Semtech SX1301 lora concentrator
+ *
+ * Copyright (c) 2018   Ben Whitten
+ */
+
+#ifndef _SX1301_
+#define _SX1301_
+
+#define SX1301_CHIP_VERSION 103
+
+#define SX1301_MCU_FW_BYTE 8192
+#define SX1301_MCU_ARB_FW_VERSION 1
+#define SX1301_MCU_AGC_FW_VERSION 4
+#define SX1301_MCU_AGC_CAL_FW_VERSION 2
+
+#endif