Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp483979imm; Wed, 6 Jun 2018 00:36:27 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJ9TxvVkgQFJ51UfBcyZyTrrOzJcPnUdxiKzsMCz418n5K21U32QgmlTVoIB3opMzyaK1AB X-Received: by 2002:a17:902:8ec2:: with SMTP id x2-v6mr2093755plo.370.1528270587049; Wed, 06 Jun 2018 00:36:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528270587; cv=none; d=google.com; s=arc-20160816; b=IhpIJAYnvUSrlzeBTypFy+hjOMxd8c3t2YET5GR963a+l7ay7bdNBNlWVcqoVtojOZ C/U1rCZiLSjgOFz+2lVCR1Bef6iYgwBTF5Ki0E021yeW7WFdzytfAeTvUczw0p2XpBTh WFTY1BCca2bXqJNgJbYT7Ev2tAO9KMtwI1/DY9ctBN45mW8+2fnI6JjS49ATQDJ3s4Fg SL+0r4vaKLtDTwZ41HSh9aWNbq0esG6kec8+RgzUebEAy8bqS6slbW9Y9Bm8WBjqYY1i bNQ0DQvTkCjgEFYbgegiLgfvZWdWlYuPohCN05KJFKmdeE5tbmMoQHuXT6hfJ9NsV6/U nFNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=kOcURMwUN6e8ohwJph83JABoVz3kbVQ/U6085uHzmP0=; b=EB3xI44RdkS88ml9RBoi7OxNuRHVDdyaUZZsmF5WhYlgOqmRhEqDPE85ssoXP6/Pl7 BwUlhWQMC+Ixd9y7PE2/nAmcDnn6/O91dSN/s0mEZCtmcnuNpEvv/gvg7wty7SJOoHSG lk3PcSSc7rrwVd4tWKbEI3v/LBwi/hu4cS5zQGddnufaghfPzDK1S12laUZh+5k/gnvY TJfx3rgU49bTbEZcjc7rShya++SE5Imm1N3QAv19lM9SJ8uwHp80LswwaSVafDNTF7je ioq1rCqKJFAbHohix9dy/cBGX7yGYAOKpQxoD5GBX0ta2F3Bf3azxcmJHb6IA2+1d7lX C/gw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m26-v6si12685274pfe.306.2018.06.06.00.36.12; Wed, 06 Jun 2018 00:36:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932291AbeFFHf3 (ORCPT + 99 others); Wed, 6 Jun 2018 03:35:29 -0400 Received: from atrey.karlin.mff.cuni.cz ([195.113.26.193]:39101 "EHLO atrey.karlin.mff.cuni.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932114AbeFFHf1 (ORCPT ); Wed, 6 Jun 2018 03:35:27 -0400 Received: by atrey.karlin.mff.cuni.cz (Postfix, from userid 512) id C2568805DA; Wed, 6 Jun 2018 09:35:25 +0200 (CEST) Date: Wed, 6 Jun 2018 09:35:25 +0200 From: Pavel Machek To: "H. Nikolaus Schaller" Cc: Andy Shevchenko , Kumar Gala , Rob Herring , Pawel Moll , Mark Rutland , Ian Campbell , Linus Walleij , Alexandre Courbot , devicetree , "open list:GPIO SUBSYSTEM" , Linux Kernel Mailing List , Discussions about the Letux Kernel , kernel@pyra-handheld.com Subject: Re: [PATCH v7 3/3] gpio: pca953x: fix address calculation for pcal6524 Message-ID: <20180606073525.GA18743@amd> References: <20180523140635.GB27215@amd> <20180605203941.GA28143@amd> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="4Ckj6UjgE2iN1+kY" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --4Ckj6UjgE2iN1+kY Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed 2018-06-06 07:33:32, H. Nikolaus Schaller wrote: > Hi, >=20 > > Am 05.06.2018 um 22:39 schrieb Pavel Machek : > >=20 > > On Tue 2018-06-05 18:37:21, Andy Shevchenko wrote: > >> On Wed, May 23, 2018 at 5:06 PM, Pavel Machek wrote: > >>> On Thu 2018-05-17 06:59:49, H. Nikolaus Schaller wrote: > >>>> The register constants are so far defined in a way that they fit > >>>> for the pcal9555a when shifted by the number of banks, i.e. are > >>>> multiplied by 2 in the accessor function. > >>>>=20 > >>>> Now, the pcal6524 has 3 banks which means the relative offset > >>>> is multiplied by 4 for the standard registers. > >>>>=20 > >>>> Simply applying the bit shift to the extended registers gives > >>>> a wrong result, since the base offset is already included in > >>>> the offset. > >>>>=20 > >>>> Therefore, we have to add code to the 24 bit accessor functions > >>>> that adjusts the register number for these exended registers. > >>>>=20 > >>>> The formula finally used was developed and proposed by > >>>> Andy Shevchenko . > >>=20 > >>>> int bank_shift =3D fls((chip->gpio_chip.ngpio - 1) / BANK_SZ); > >>>> + int addr =3D (reg & PCAL_GPIO_MASK) << bank_shift; > >>>> + int pinctrl =3D (reg & PCAL_PINCTRL_MASK) << 1; > >>=20 > >>> Is this reasonable to do on each register access? Compiler will not be > >>> able to optimize out fls and shifts, right? > >>=20 > >> On modern CPUs fls() is one assembly command. OTOH, any proposal to do > >> this better? > >>=20 > >> What I can see is that bank_shift is invariant to the function, and > >> maybe cached. > >=20 > > Yes, I thought that caching bank_shift might be good idea. I thought > > it was constant for given chip... >=20 > Yes, it is an f(chip), but the question that comes to my mind is if > optimization is worth any effort. This is an accessor method over It will also be less ugly. Copy&pasted complex exprepsion all over the driver is not nice. Pavel --=20 (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blo= g.html --4Ckj6UjgE2iN1+kY Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iEYEARECAAYFAlsXjr0ACgkQMOfwapXb+vIc1wCggj6eiSaPQ5SgwApWF99NsdKs vqoAoMPTlFh+Gg+YVlfFIoV6TYdftu6l =1hdR -----END PGP SIGNATURE----- --4Ckj6UjgE2iN1+kY--