From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ben Whitten Subject: [PATCH lora-next v2 6/8] net: lora: sx1301: replace version and size magic numbers with defines Date: Thu, 9 Aug 2018 13:33:36 +0100 Message-ID: <1533818018-29005-6-git-send-email-ben.whitten@lairdtech.com> References: <1533818018-29005-1-git-send-email-ben.whitten@lairdtech.com> Cc: starnight@g.ncu.edu.tw, hasnain.virk@arm.com, netdev@vger.kernel.org, liuxuenetmail@gmail.com, shess@hessware.de, Ben Whitten To: afaerber@suse.de Return-path: Received: from mail-wm0-f65.google.com ([74.125.82.65]:39969 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727786AbeHIO7V (ORCPT ); Thu, 9 Aug 2018 10:59:21 -0400 Received: by mail-wm0-f65.google.com with SMTP id y9-v6so108169wma.5 for ; Thu, 09 Aug 2018 05:34:39 -0700 (PDT) In-Reply-To: <1533818018-29005-1-git-send-email-ben.whitten@lairdtech.com> Sender: netdev-owner@vger.kernel.org List-ID: 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_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 -- 2.7.4