lkml.org 
[lkml]   [2020]   [Nov]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    From
    Date
    SubjectRe: [RFT PATCH 5/7] gpio: exar: unduplicate address and offset computation
    On Mon, Oct 26, 2020 at 4:23 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote:

    ...

    > +static unsigned int
    > +exar_offset_to_sel_addr(struct exar_gpio_chip *exar_gpio, unsigned int offset)
    > +{
    > + return (offset + exar_gpio->first_pin) / 8 ? EXAR_OFFSET_MPIOSEL_HI
    > + : EXAR_OFFSET_MPIOSEL_LO;
    > +}
    > +
    > +static unsigned int
    > +exar_offset_to_lvl_addr(struct exar_gpio_chip *exar_gpio, unsigned int offset)
    > +{
    > + return (offset + exar_gpio->first_pin) / 8 ? EXAR_OFFSET_MPIOLVL_HI
    > + : EXAR_OFFSET_MPIOLVL_LO;
    > +}
    > +
    > +static unsigned int
    > +exar_offset_to_bit(struct exar_gpio_chip *exar_gpio, unsigned int offset)
    > +{
    > + return (offset + exar_gpio->first_pin) % 8;
    > +}

    Answering to your question...

    It can be done line this:

    static unsigned int exar_offset_to_bank_and_bit(..., *bit)
    {
    *bit = (offset + exar_gpio->first_pin) % 8;
    return (offset + exar_gpio->first_pin) / 8;
    }

    static unsigned int exar_offset_to_lvl_addr_and_bit(, *bit)
    {
    return exar_offset_to_bank_and_bit(..., bit) ?
    EXAR_OFFSET_MPIOLVL_HI : EXAR_OFFSET_MPIOLVL_LO;
    }

    ...

    > + unsigned int addr = exar_offset_to_lvl_addr(exar_gpio, offset);
    > + unsigned int bit = exar_offset_to_bit(exar_gpio, offset);

    unsigned int addr, bit;

    addr = exar_offset_to_lvl_addr_and_bit(..., &bit);

    --
    With Best Regards,
    Andy Shevchenko

    \
     
     \ /
      Last update: 2020-11-02 11:58    [W:3.894 / U:0.296 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site