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

2018-08-09 Thread Andreas Färber
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 
> ---
>  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 
>  #include 
>  
> +#include "sx1301.h"
> +
>  #define REG_PAGE_RESET   0
>  #define REG_VERSION  1
>  #define REG_MCU_PROM_ADDR9
> @@ -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 000..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

-- 
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)


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

2018-08-09 Thread Ben Whitten
We replace the hard coded numbers for size and version with meaningful
names.

Signed-off-by: Ben Whitten 
---
 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 
 #include 
 
+#include "sx1301.h"
+
 #define REG_PAGE_RESET 0
 #define REG_VERSION1
 #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 000..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
-- 
2.7.4