From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933694AbdCJOlx (ORCPT ); Fri, 10 Mar 2017 09:41:53 -0500 Received: from pegase1.c-s.fr ([93.17.236.30]:50147 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932784AbdCJOlu (ORCPT ); Fri, 10 Mar 2017 09:41:50 -0500 Subject: Re: [PATCH] powerpc: sysdev: cpm1: Optimise gpio bit calculation To: Segher Boessenkool References: <20170309094206.A832167992@localhost.localdomain> <87a88tle0y.fsf@concordia.ellerman.id.au> <534d8795-ce21-9af6-498d-22597213a3a2@c-s.fr> <20170310130630.GH31469@gate.crashing.org> <906c025b-47d0-f906-2613-291f350bd48d@c-s.fr> <20170310143241.GJ31469@gate.crashing.org> Cc: Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Scott Wood , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org From: Christophe LEROY Message-ID: <777e903f-b816-5efa-2ece-e4e16fab27c6@c-s.fr> Date: Fri, 10 Mar 2017 15:41:23 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.7.1 MIME-Version: 1.0 In-Reply-To: <20170310143241.GJ31469@gate.crashing.org> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Le 10/03/2017 à 15:32, Segher Boessenkool a écrit : > On Fri, Mar 10, 2017 at 03:04:48PM +0100, Christophe LEROY wrote: >> Le 10/03/2017 à 14:06, Segher Boessenkool a écrit : >>> On Fri, Mar 10, 2017 at 11:54:19AM +0100, Christophe LEROY wrote: >>>> gpio_get() and gpio_set() are used extensively by some GPIO based >>>> drivers like SPI, NAND, so it may be worth it as it doesn't impair >>>> readability (if anyone prefers, we could write (1 << 31) >> i instead >>>> of 0x80000000 >> i ) >>> >>> 1 << 31 is undefined behaviour, of course. >>> >> >> Shall it be 1U << 31 ? > > Sure, that works. "1 << (31 - i)" is most readable (but it doesn't yet > generate the code you want). > > Euh .... I'm a bit lost. Do you mean the form we have today is the driver is wrong ? @@ -684,9 +682,7 @@ static int cpm1_gpio32_get(struct gpio_chip *gc, unsigned int gpio) { struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc); struct cpm_ioport32b __iomem *iop = mm_gc->regs; - u32 pin_mask; - - pin_mask = 1 << (31 - gpio); + u32 pin_mask = 0x80000000 >> gpio; return !!(in_be32(&iop->dat) & pin_mask); } Which I thought could also become @@ -684,9 +682,7 @@ static int cpm1_gpio32_get(struct gpio_chip *gc, unsigned int gpio) { struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc); struct cpm_ioport32b __iomem *iop = mm_gc->regs; - u32 pin_mask; - - pin_mask = 1 << (31 - gpio); + u32 pin_mask = (1 << 31) >> gpio; return !!(in_be32(&iop->dat) & pin_mask); } Christophe