Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp394595imm; Tue, 5 Jun 2018 22:34:27 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJJlfWE06yK0tpd/ELbs5ZkKmYmp9ICOHhJtV17XIG6zDRhnzO7VpCH71fqJ6CMTzh1LpvI X-Received: by 2002:a63:82c7:: with SMTP id w190-v6mr1438796pgd.172.1528263267112; Tue, 05 Jun 2018 22:34:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528263267; cv=none; d=google.com; s=arc-20160816; b=HmVBIIfhFeFyTJ34EhsSQTWt/Gv1QbgjPkeg/2v8oj/AhQGkbK2LitRZHZUVl6qn6A GBBh/KWvkVqNpQ4hFZEfRMC7hvVTqUQmucPu/BJ3r/v+j/LoKlH3CMRvUSRNaIHcBuaJ di/YlJUCPnrYyvJNEL5aQhlIqvrr2tFCI1gQrXiZXC1+TSSSJuyZN5lMXTUGZLa5m0of 9xv+rsJHsZUUfkWhaJ+Onfw7Me/LFxzwHv2D8GRd9Gxwa6jn7K+h2A1M6BO9HBEkvR01 gyxkT2rpd+yiafNFNjBmWAzCAKyJp5hF5AyPJk4t+RIWrRUYYr9TAxBGAX8tsHQUwj34 gc2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version:dkim-signature:arc-authentication-results; bh=LyVPdQPnkSnF8KHsjb8ihMDxnnvIXdPYc7BMsGICL6U=; b=ubBV/raKuamVH8VUEYEAIMgzr4x6EzV/r8J6m4xS2b7ZGhsHir9qPyLzbyqrhjUiNE 4s9pMmTW20KyIhKNWj9oYaD/ku3LhSw95FkBHSbV3Y0bxyg8I5AgixayNa9dmiVEKtvW +mFUe6K/wDOFbvcYYtOWH+Pf47r54a6XoSG5w8gbznGZ0B6yqzj3kjSzIAlIdJC8FYnJ hfD0lXij19qXoakVrYnr7zdJs+g3HpKiqO+oVuNsE/UPyqLrRyxGmwtZ5IgHyPL2RWR6 /gD2ekrGLcHseoCQIF5NuKAPlC6MzNHaDv8etIXmK8Y/ENeYWvTdK8EciydPq4RGKelh WkLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@dsitri.de header.s=strato-dkim-0002 header.b=b8xW1VmH; 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 l68-v6si10709393pgl.84.2018.06.05.22.34.12; Tue, 05 Jun 2018 22:34: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; dkim=fail header.i=@dsitri.de header.s=strato-dkim-0002 header.b=b8xW1VmH; 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 S1752205AbeFFFdr (ORCPT + 99 others); Wed, 6 Jun 2018 01:33:47 -0400 Received: from mo4-p05-ob.smtp.rzone.de ([85.215.255.133]:27421 "EHLO mo4-p05-ob.smtp.rzone.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750817AbeFFFdp (ORCPT ); Wed, 6 Jun 2018 01:33:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1528263221; s=strato-dkim-0002; d=dsitri.de; h=To:References:Message-Id:Cc:Date:In-Reply-To:From:Subject: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=LyVPdQPnkSnF8KHsjb8ihMDxnnvIXdPYc7BMsGICL6U=; b=b8xW1VmHx9Ye40vWu67AMVQMx5+RoGR4yxqmnCiJo/ra9/zcR8GQAmjuknS3Gek4A8 Rjt78WRg88S0vJO7HJKiKcCHdiH4NPZfMZ69U21mjjcHBqOAFoQokmIY8X6s1y0vCIQV 8URB9I2MVjJ+KFXybwff1PlBM3awZBz2GzIEUMtDE+wWznjkv8cdYlCszANOl+CvqzBX bP256FaU+RfNAy2Gwi9iBnxpBBhWQfXdPct/YkNLAJfLCh5cR0+qNuFm2/Y9FNtTeoqW AJQrGiaSBlLte19ziiMAqocREK6U5flpgWwem+QixpFjjZb1GEUDwex2XaTWoY0U8pNi QUBw== X-RZG-AUTH: ":JGIXVUS7cutRB/49FwqZ7WcJeFKiMgPgp8VKxflSZ1P34KBi5Qpz9LpBMKKLaHMpnzg=" X-RZG-CLASS-ID: mo05 Received: from mbp-13-nikolaus.fritz.box by smtp.strato.de (RZmta 43.10 DYNA|AUTH) with ESMTPSA id L04479u565XW8E1 (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (curve secp521r1 with 521 ECDH bits, eq. 15360 bits RSA)) (Client did not present a certificate); Wed, 6 Jun 2018 07:33:32 +0200 (CEST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 9.3 \(3124\)) Subject: Re: [PATCH v7 3/3] gpio: pca953x: fix address calculation for pcal6524 From: "H. Nikolaus Schaller" In-Reply-To: <20180605203941.GA28143@amd> Date: Wed, 6 Jun 2018 07:33:32 +0200 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 Content-Transfer-Encoding: 7bit Message-Id: References: <20180523140635.GB27215@amd> <20180605203941.GA28143@amd> To: Pavel Machek X-Mailer: Apple Mail (2.3124) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, > Am 05.06.2018 um 22:39 schrieb Pavel Machek : > > 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. >>>> >>>> Now, the pcal6524 has 3 banks which means the relative offset >>>> is multiplied by 4 for the standard registers. >>>> >>>> Simply applying the bit shift to the extended registers gives >>>> a wrong result, since the base offset is already included in >>>> the offset. >>>> >>>> Therefore, we have to add code to the 24 bit accessor functions >>>> that adjusts the register number for these exended registers. >>>> >>>> The formula finally used was developed and proposed by >>>> Andy Shevchenko . >> >>>> int bank_shift = fls((chip->gpio_chip.ngpio - 1) / BANK_SZ); >>>> + int addr = (reg & PCAL_GPIO_MASK) << bank_shift; >>>> + int pinctrl = (reg & PCAL_PINCTRL_MASK) << 1; >> >>> Is this reasonable to do on each register access? Compiler will not be >>> able to optimize out fls and shifts, right? >> >> On modern CPUs fls() is one assembly command. OTOH, any proposal to do >> this better? >> >> What I can see is that bank_shift is invariant to the function, and >> maybe cached. > > Yes, I thought that caching bank_shift might be good idea. I thought > it was constant for given chip... 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 i2c which tends to be slow (100 / 400kHz SCL) compared to the CPU. So saving 1 or 2 CPU cycles here doesn't seem to be a significant improvement. Maybe it is more valuable to improve the code path through the i2c core? BR, Nikolaus