LKML Archive on lore.kernel.org help / color / mirror / Atom feed
From: "H. Nikolaus Schaller" <email@example.com> To: Pavel Machek <firstname.lastname@example.org> Cc: Andy Shevchenko <email@example.com>, Kumar Gala <firstname.lastname@example.org>, Rob Herring <email@example.com>, Pawel Moll <firstname.lastname@example.org>, Mark Rutland <email@example.com>, Ian Campbell <firstname.lastname@example.org>, Linus Walleij <email@example.com>, Alexandre Courbot <firstname.lastname@example.org>, devicetree <email@example.com>, "open list:GPIO SUBSYSTEM" <firstname.lastname@example.org>, Linux Kernel Mailing List <email@example.com>, Discussions about the Letux Kernel <firstname.lastname@example.org>, email@example.com Subject: Re: [PATCH v7 3/3] gpio: pca953x: fix address calculation for pcal6524 Date: Wed, 6 Jun 2018 07:33:32 +0200 [thread overview] Message-ID: <A639885E-0E5D-4FB0-BE51-AFF35BF4F76B@computer.org> (raw) In-Reply-To: <20180605203941.GA28143@amd> Hi, > Am 05.06.2018 um 22:39 schrieb Pavel Machek <firstname.lastname@example.org>: > > On Tue 2018-06-05 18:37:21, Andy Shevchenko wrote: >> On Wed, May 23, 2018 at 5:06 PM, Pavel Machek <email@example.com> 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 <firstname.lastname@example.org>. >> >>>> 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
next prev parent reply other threads:[~2018-06-06 5:33 UTC|newest] Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-05-17 4:59 [PATCH v7 0/3] pcal6524 extensions and fixes for pca953x driver H. Nikolaus Schaller 2018-05-17 4:59 ` [PATCH v7 1/3] gpio: pca953x: set the PCA_PCAL flag also when matching by DT H. Nikolaus Schaller 2018-05-23 11:46 ` Linus Walleij 2018-05-17 4:59 ` [PATCH v7 2/3] gpio: pca953x: define masks for addressing common and extended registers H. Nikolaus Schaller 2018-05-23 11:47 ` Linus Walleij 2018-05-17 4:59 ` [PATCH v7 3/3] gpio: pca953x: fix address calculation for pcal6524 H. Nikolaus Schaller 2018-05-23 11:48 ` Linus Walleij 2018-05-23 14:06 ` Pavel Machek 2018-06-05 15:37 ` Andy Shevchenko 2018-06-05 20:39 ` Pavel Machek 2018-06-06 5:33 ` H. Nikolaus Schaller [this message] 2018-06-06 7:35 ` Pavel Machek 2018-05-19 18:58 ` [PATCH v7 0/3] pcal6524 extensions and fixes for pca953x driver Andy Shevchenko
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=A639885E-0E5D-4FB0-BE51-AFF35BF4F76B@computer.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).