Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753719AbdLMRpK (ORCPT ); Wed, 13 Dec 2017 12:45:10 -0500 Received: from mail.CARNet.hr ([161.53.123.6]:44981 "EHLO mail.carnet.hr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753301AbdLMRpF (ORCPT ); Wed, 13 Dec 2017 12:45:05 -0500 From: Valentin Vidic To: Marcus Wolf Cc: =?UTF-8?q?Simon=20Sandstr=C3=B6m?= , Marcin Ciupak , Marcus Wolf , devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Valentin Vidic Date: Wed, 13 Dec 2017 18:44:44 +0100 Message-Id: <20171213174444.21088-1-Valentin.Vidic@CARNet.hr> X-Mailer: git-send-email 2.15.0 In-Reply-To: <38352026-045b-a082-93bb-10e9e70f9f55@smarthome-wolf.de> References: <20171213142156.3201-1-Valentin.Vidic@CARNet.hr> <20171213142156.3201-6-Valentin.Vidic@CARNet.hr> <70c9a1fc-31eb-27c4-1283-35590f8b80f6@smarthome-wolf.de> <20171213165514.12509-1-Valentin.Vidic@CARNet.hr> <38352026-045b-a082-93bb-10e9e70f9f55@smarthome-wolf.de> X-SA-Exim-Connect-IP: 2001:b68:ff:12::131 Subject: [PATCH 6/8 v3] staging: pi433: use defines for shifting register values X-SA-Exim-Version: 4.2.1 (built Mon, 26 Dec 2011 16:24:06 +0000) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2280 Lines: 59 Avoid shifting by magic numbers and use defines instead. Signed-off-by: Valentin Vidic --- v2: - drop change for SHIFT_DATAMODUL_MODULATION_TYPE - move shifting to the header file v3: - drop auto case - use CURRENT suffix - precompute define values drivers/staging/pi433/rf69.c | 15 +++++++-------- drivers/staging/pi433/rf69_registers.h | 6 ++++++ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/drivers/staging/pi433/rf69.c b/drivers/staging/pi433/rf69.c index f77ecd60f43a..0889c65d5a31 100644 --- a/drivers/staging/pi433/rf69.c +++ b/drivers/staging/pi433/rf69.c @@ -340,14 +340,13 @@ enum lnaGain rf69_get_lna_gain(struct spi_device *spi) currentValue = rf69_read_reg(spi, REG_LNA); - switch (currentValue & MASK_LNA_CURRENT_GAIN >> 3) { // improvement: change 3 to define - case LNA_GAIN_AUTO: return automatic; - case LNA_GAIN_MAX: return max; - case LNA_GAIN_MAX_MINUS_6: return maxMinus6; - case LNA_GAIN_MAX_MINUS_12: return maxMinus12; - case LNA_GAIN_MAX_MINUS_24: return maxMinus24; - case LNA_GAIN_MAX_MINUS_36: return maxMinus36; - case LNA_GAIN_MAX_MINUS_48: return maxMinus48; + switch (currentValue & MASK_LNA_CURRENT_GAIN) { + case LNA_GAIN_MAX_CURRENT: return max; + case LNA_GAIN_MAX_MINUS_6_CURRENT: return maxMinus6; + case LNA_GAIN_MAX_MINUS_12_CURRENT: return maxMinus12; + case LNA_GAIN_MAX_MINUS_24_CURRENT: return maxMinus24; + case LNA_GAIN_MAX_MINUS_36_CURRENT: return maxMinus36; + case LNA_GAIN_MAX_MINUS_48_CURRENT: return maxMinus48; default: return undefined; } } diff --git a/drivers/staging/pi433/rf69_registers.h b/drivers/staging/pi433/rf69_registers.h index d23b8b668ef5..4a189c6a4ab3 100644 --- a/drivers/staging/pi433/rf69_registers.h +++ b/drivers/staging/pi433/rf69_registers.h @@ -246,6 +246,12 @@ #define LNA_GAIN_MAX_MINUS_36 0x05 #define LNA_GAIN_MAX_MINUS_48 0x06 +#define LNA_GAIN_MAX_CURRENT 0x08 +#define LNA_GAIN_MAX_MINUS_6_CURRENT 0x10 +#define LNA_GAIN_MAX_MINUS_12_CURRENT 0x18 +#define LNA_GAIN_MAX_MINUS_24_CURRENT 0x20 +#define LNA_GAIN_MAX_MINUS_36_CURRENT 0x28 +#define LNA_GAIN_MAX_MINUS_48_CURRENT 0x30 /* RegRxBw (0x19) and RegAfcBw (0x1A) */ #define MASK_BW_DCC_FREQ 0xE0 -- 2.15.0