Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753719AbdLMRPV (ORCPT ); Wed, 13 Dec 2017 12:15:21 -0500 Received: from dd39320.kasserver.com ([85.13.155.146]:58782 "EHLO dd39320.kasserver.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752816AbdLMRPU (ORCPT ); Wed, 13 Dec 2017 12:15:20 -0500 Subject: Re: [PATCH 6/8 v2] staging: pi433: use defines for shifting register values To: Valentin Vidic Cc: =?UTF-8?Q?Simon_Sandstr=c3=b6m?= , Marcin Ciupak , Marcus Wolf , devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, Greg Kroah-Hartman 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> From: Marcus Wolf Message-ID: <38352026-045b-a082-93bb-10e9e70f9f55@smarthome-wolf.de> Date: Wed, 13 Dec 2017 19:15:09 +0200 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <20171213165514.12509-1-Valentin.Vidic@CARNet.hr> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: de-DE Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3666 Lines: 88 Am 13.12.2017 um 18:55 schrieb Valentin Vidic: > 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 > > drivers/staging/pi433/rf69.c | 16 ++++++++-------- > drivers/staging/pi433/rf69_registers.h | 8 ++++++++ > 2 files changed, 16 insertions(+), 8 deletions(-) > > diff --git a/drivers/staging/pi433/rf69.c b/drivers/staging/pi433/rf69.c > index f77ecd60f43a..ce259b4f0b0e 100644 > --- a/drivers/staging/pi433/rf69.c > +++ b/drivers/staging/pi433/rf69.c > @@ -340,14 +340,14 @@ 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_AUTO_SHIFTED: return automatic; > + case LNA_GAIN_MAX_SHIFTED: return max; > + case LNA_GAIN_MAX_MINUS_6_SHIFTED: return maxMinus6; > + case LNA_GAIN_MAX_MINUS_12_SHIFTED: return maxMinus12; > + case LNA_GAIN_MAX_MINUS_24_SHIFTED: return maxMinus24; > + case LNA_GAIN_MAX_MINUS_36_SHIFTED: return maxMinus36; > + case LNA_GAIN_MAX_MINUS_48_SHIFTED: return maxMinus48; > default: return undefined; > } > } > diff --git a/drivers/staging/pi433/rf69_registers.h b/drivers/staging/pi433/rf69_registers.h > index d23b8b668ef5..6329bbf9e499 100644 > --- a/drivers/staging/pi433/rf69_registers.h > +++ b/drivers/staging/pi433/rf69_registers.h > @@ -237,6 +237,7 @@ > #define MASK_LNA_ZIN 0x80 > #define MASK_LNA_CURRENT_GAIN 0x38 > #define MASK_LNA_GAIN 0x07 > +#define SHIFT_LNA_CURRENT_GAIN 3 > > #define LNA_GAIN_AUTO 0x00 /* default */ > #define LNA_GAIN_MAX 0x01 > @@ -246,6 +247,13 @@ > #define LNA_GAIN_MAX_MINUS_36 0x05 > #define LNA_GAIN_MAX_MINUS_48 0x06 > > +#define LNA_GAIN_AUTO_SHIFTED (LNA_GAIN_AUTO << SHIFT_LNA_CURRENT_GAIN) > +#define LNA_GAIN_MAX_SHIFTED (LNA_GAIN_MAX << SHIFT_LNA_CURRENT_GAIN) > +#define LNA_GAIN_MAX_MINUS_6_SHIFTED (LNA_GAIN_MAX_MINUS_6 << SHIFT_LNA_CURRENT_GAIN) > +#define LNA_GAIN_MAX_MINUS_12_SHIFTED (LNA_GAIN_MAX_MINUS_12 << SHIFT_LNA_CURRENT_GAIN) > +#define LNA_GAIN_MAX_MINUS_24_SHIFTED (LNA_GAIN_MAX_MINUS_24 << SHIFT_LNA_CURRENT_GAIN) > +#define LNA_GAIN_MAX_MINUS_36_SHIFTED (LNA_GAIN_MAX_MINUS_36 << SHIFT_LNA_CURRENT_GAIN) > +#define LNA_GAIN_MAX_MINUS_48_SHIFTED (LNA_GAIN_MAX_MINUS_48 << SHIFT_LNA_CURRENT_GAIN) > > /* RegRxBw (0x19) and RegAfcBw (0x1A) */ > #define MASK_BW_DCC_FREQ 0xE0 > Hi Valentin, nice :-) Name is a bit strange, since it's not really shifted. If you have a look at the datasheet (RegLNA, page 68), there are two sections "by chance" both using the max, -6, -12 ... But auto is not needed for current gain (was already bad in my old implementation!), since the current gain will always report a real value, never auto. So maybe it is a little(!) better not to derive the "current" defines from the "select" defines and use names like LNA_GAIN_MAX_SELECT and LNA_GAIN_MAX_CURRENT. Never the less - I like patch 6/8 v2 a lot more, than the original one :-) Thank you very much for your help, Marcus