21 Dec, 2018

1 commit


13 Jul, 2018

1 commit

  • Gcc cannot always see that BUG_ON(1) is guaranteed to not
    return, so we get a warning message in some configurations:

    drivers/gpio/gpio-aspeed.c: In function 'bank_reg':
    drivers/gpio/gpio-aspeed.c:244:1: error: control reaches end of non-void function [-Werror=return-type]

    Using a plain BUG() is easier here and avoids the problem.

    Fixes: 44ddf559d579 ("gpio: aspeed: Rework register type accessors")
    Signed-off-by: Arnd Bergmann
    Acked-by: Benjamin Herrenschmidt
    Signed-off-by: Linus Walleij

    Arnd Bergmann
     

02 Jul, 2018

4 commits

  • On the Aspeed chip, the GPIOs can be under control of the ARM
    chip or of the ColdFire coprocessor. (There's a third command
    source, the LPC bus, which we don't use or support yet).

    The control of which master is allowed to modify a given
    GPIO is per-bank (8 GPIOs).

    Unfortunately, systems already exist for which we want to
    use GPIOs of both sources in the same bank.

    This provides an API exported by the gpio-aspeed driver
    that an aspeed coprocessor driver can use to "grab" some
    GPIOs for use by the coprocessor, and allow the coprocessor
    driver to provide callbacks for arbitrating access.

    Once at least one GPIO of a given bank has been "grabbed"
    by the coprocessor, the entire bank is marked as being
    under coprocessor control. It's command source is switched
    to the coprocessor.

    If the ARM then tries to write to a GPIO in such a marked bank,
    the provided callbacks are used to request access from the
    coprocessor driver, which is responsible to doing whatever
    is necessary to "pause" the coprocessor or prevent it from
    trying to use the GPIOs while the ARM is doing its accesses.

    During that time, the command source for the bank is temporarily
    switched back to the ARM.

    Signed-off-by: Benjamin Herrenschmidt
    Reviewed-by: Joel Stanley
    Reviewed-by: Andrew Jeffery
    Signed-off-by: Linus Walleij

    Benjamin Herrenschmidt
     
  • This adds the definitions for the command source registers
    and a helper to set them.

    Those registers allow to control which bus master on the
    SoC is allowed to modify a given bank of GPIOs and will
    be used by subsequent patches.

    Signed-off-by: Benjamin Herrenschmidt
    Reviewed-by: Joel Stanley
    Reviewed-by: Andrew Jeffery
    Signed-off-by: Linus Walleij

    Benjamin Herrenschmidt
     
  • The Aspeed GPIO hardware has a quirk: the value register, for an
    output GPIO, doesn't contain the last value written (the write
    latch content) but the sampled input value.

    This means that when reading back shortly after writing, you can
    get an incorrect value as the input value is delayed by a few
    synchronizers.

    The HW supports a separate read-only register "Data Read Register"
    which allows you to read the write latch instead.

    This adds the definition for it, and uses it for the initial
    population of the GPIO value cache. It will be used more in
    subsequent patches.

    Signed-off-by: Benjamin Herrenschmidt
    Reviewed-by: Joel Stanley
    Reviewed-by: Andrew Jeffery
    Signed-off-by: Linus Walleij

    Benjamin Herrenschmidt
     
  • Use a single accessor function for all register types instead
    of several spread around. This will make it easier/cleaner
    to introduce new registers and keep the mechanism in one
    place.

    The big switch/case is optimized at compile time since the
    switch value is a constant.

    Signed-off-by: Benjamin Herrenschmidt
    Reviewed-by: Joel Stanley
    Reviewed-by: Andrew Jeffery
    Signed-off-by: Linus Walleij

    Benjamin Herrenschmidt
     

13 Jun, 2018

1 commit

  • The devm_kzalloc() function has a 2-factor argument form, devm_kcalloc().
    This patch replaces cases of:

    devm_kzalloc(handle, a * b, gfp)

    with:
    devm_kcalloc(handle, a * b, gfp)

    as well as handling cases of:

    devm_kzalloc(handle, a * b * c, gfp)

    with:

    devm_kzalloc(handle, array3_size(a, b, c), gfp)

    as it's slightly less ugly than:

    devm_kcalloc(handle, array_size(a, b), c, gfp)

    This does, however, attempt to ignore constant size factors like:

    devm_kzalloc(handle, 4 * 1024, gfp)

    though any constants defined via macros get caught up in the conversion.

    Any factors with a sizeof() of "unsigned char", "char", and "u8" were
    dropped, since they're redundant.

    Some manual whitespace fixes were needed in this patch, as Coccinelle
    really liked to write "=devm_kcalloc..." instead of "= devm_kcalloc...".

    The Coccinelle script used for this was:

    // Fix redundant parens around sizeof().
    @@
    expression HANDLE;
    type TYPE;
    expression THING, E;
    @@

    (
    devm_kzalloc(HANDLE,
    - (sizeof(TYPE)) * E
    + sizeof(TYPE) * E
    , ...)
    |
    devm_kzalloc(HANDLE,
    - (sizeof(THING)) * E
    + sizeof(THING) * E
    , ...)
    )

    // Drop single-byte sizes and redundant parens.
    @@
    expression HANDLE;
    expression COUNT;
    typedef u8;
    typedef __u8;
    @@

    (
    devm_kzalloc(HANDLE,
    - sizeof(u8) * (COUNT)
    + COUNT
    , ...)
    |
    devm_kzalloc(HANDLE,
    - sizeof(__u8) * (COUNT)
    + COUNT
    , ...)
    |
    devm_kzalloc(HANDLE,
    - sizeof(char) * (COUNT)
    + COUNT
    , ...)
    |
    devm_kzalloc(HANDLE,
    - sizeof(unsigned char) * (COUNT)
    + COUNT
    , ...)
    |
    devm_kzalloc(HANDLE,
    - sizeof(u8) * COUNT
    + COUNT
    , ...)
    |
    devm_kzalloc(HANDLE,
    - sizeof(__u8) * COUNT
    + COUNT
    , ...)
    |
    devm_kzalloc(HANDLE,
    - sizeof(char) * COUNT
    + COUNT
    , ...)
    |
    devm_kzalloc(HANDLE,
    - sizeof(unsigned char) * COUNT
    + COUNT
    , ...)
    )

    // 2-factor product with sizeof(type/expression) and identifier or constant.
    @@
    expression HANDLE;
    type TYPE;
    expression THING;
    identifier COUNT_ID;
    constant COUNT_CONST;
    @@

    (
    - devm_kzalloc
    + devm_kcalloc
    (HANDLE,
    - sizeof(TYPE) * (COUNT_ID)
    + COUNT_ID, sizeof(TYPE)
    , ...)
    |
    - devm_kzalloc
    + devm_kcalloc
    (HANDLE,
    - sizeof(TYPE) * COUNT_ID
    + COUNT_ID, sizeof(TYPE)
    , ...)
    |
    - devm_kzalloc
    + devm_kcalloc
    (HANDLE,
    - sizeof(TYPE) * (COUNT_CONST)
    + COUNT_CONST, sizeof(TYPE)
    , ...)
    |
    - devm_kzalloc
    + devm_kcalloc
    (HANDLE,
    - sizeof(TYPE) * COUNT_CONST
    + COUNT_CONST, sizeof(TYPE)
    , ...)
    |
    - devm_kzalloc
    + devm_kcalloc
    (HANDLE,
    - sizeof(THING) * (COUNT_ID)
    + COUNT_ID, sizeof(THING)
    , ...)
    |
    - devm_kzalloc
    + devm_kcalloc
    (HANDLE,
    - sizeof(THING) * COUNT_ID
    + COUNT_ID, sizeof(THING)
    , ...)
    |
    - devm_kzalloc
    + devm_kcalloc
    (HANDLE,
    - sizeof(THING) * (COUNT_CONST)
    + COUNT_CONST, sizeof(THING)
    , ...)
    |
    - devm_kzalloc
    + devm_kcalloc
    (HANDLE,
    - sizeof(THING) * COUNT_CONST
    + COUNT_CONST, sizeof(THING)
    , ...)
    )

    // 2-factor product, only identifiers.
    @@
    expression HANDLE;
    identifier SIZE, COUNT;
    @@

    - devm_kzalloc
    + devm_kcalloc
    (HANDLE,
    - SIZE * COUNT
    + COUNT, SIZE
    , ...)

    // 3-factor product with 1 sizeof(type) or sizeof(expression), with
    // redundant parens removed.
    @@
    expression HANDLE;
    expression THING;
    identifier STRIDE, COUNT;
    type TYPE;
    @@

    (
    devm_kzalloc(HANDLE,
    - sizeof(TYPE) * (COUNT) * (STRIDE)
    + array3_size(COUNT, STRIDE, sizeof(TYPE))
    , ...)
    |
    devm_kzalloc(HANDLE,
    - sizeof(TYPE) * (COUNT) * STRIDE
    + array3_size(COUNT, STRIDE, sizeof(TYPE))
    , ...)
    |
    devm_kzalloc(HANDLE,
    - sizeof(TYPE) * COUNT * (STRIDE)
    + array3_size(COUNT, STRIDE, sizeof(TYPE))
    , ...)
    |
    devm_kzalloc(HANDLE,
    - sizeof(TYPE) * COUNT * STRIDE
    + array3_size(COUNT, STRIDE, sizeof(TYPE))
    , ...)
    |
    devm_kzalloc(HANDLE,
    - sizeof(THING) * (COUNT) * (STRIDE)
    + array3_size(COUNT, STRIDE, sizeof(THING))
    , ...)
    |
    devm_kzalloc(HANDLE,
    - sizeof(THING) * (COUNT) * STRIDE
    + array3_size(COUNT, STRIDE, sizeof(THING))
    , ...)
    |
    devm_kzalloc(HANDLE,
    - sizeof(THING) * COUNT * (STRIDE)
    + array3_size(COUNT, STRIDE, sizeof(THING))
    , ...)
    |
    devm_kzalloc(HANDLE,
    - sizeof(THING) * COUNT * STRIDE
    + array3_size(COUNT, STRIDE, sizeof(THING))
    , ...)
    )

    // 3-factor product with 2 sizeof(variable), with redundant parens removed.
    @@
    expression HANDLE;
    expression THING1, THING2;
    identifier COUNT;
    type TYPE1, TYPE2;
    @@

    (
    devm_kzalloc(HANDLE,
    - sizeof(TYPE1) * sizeof(TYPE2) * COUNT
    + array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
    , ...)
    |
    devm_kzalloc(HANDLE,
    - sizeof(TYPE1) * sizeof(THING2) * (COUNT)
    + array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
    , ...)
    |
    devm_kzalloc(HANDLE,
    - sizeof(THING1) * sizeof(THING2) * COUNT
    + array3_size(COUNT, sizeof(THING1), sizeof(THING2))
    , ...)
    |
    devm_kzalloc(HANDLE,
    - sizeof(THING1) * sizeof(THING2) * (COUNT)
    + array3_size(COUNT, sizeof(THING1), sizeof(THING2))
    , ...)
    |
    devm_kzalloc(HANDLE,
    - sizeof(TYPE1) * sizeof(THING2) * COUNT
    + array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
    , ...)
    |
    devm_kzalloc(HANDLE,
    - sizeof(TYPE1) * sizeof(THING2) * (COUNT)
    + array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
    , ...)
    )

    // 3-factor product, only identifiers, with redundant parens removed.
    @@
    expression HANDLE;
    identifier STRIDE, SIZE, COUNT;
    @@

    (
    devm_kzalloc(HANDLE,
    - (COUNT) * STRIDE * SIZE
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    devm_kzalloc(HANDLE,
    - COUNT * (STRIDE) * SIZE
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    devm_kzalloc(HANDLE,
    - COUNT * STRIDE * (SIZE)
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    devm_kzalloc(HANDLE,
    - (COUNT) * (STRIDE) * SIZE
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    devm_kzalloc(HANDLE,
    - COUNT * (STRIDE) * (SIZE)
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    devm_kzalloc(HANDLE,
    - (COUNT) * STRIDE * (SIZE)
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    devm_kzalloc(HANDLE,
    - (COUNT) * (STRIDE) * (SIZE)
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    devm_kzalloc(HANDLE,
    - COUNT * STRIDE * SIZE
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    )

    // Any remaining multi-factor products, first at least 3-factor products,
    // when they're not all constants...
    @@
    expression HANDLE;
    expression E1, E2, E3;
    constant C1, C2, C3;
    @@

    (
    devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
    |
    devm_kzalloc(HANDLE,
    - (E1) * E2 * E3
    + array3_size(E1, E2, E3)
    , ...)
    |
    devm_kzalloc(HANDLE,
    - (E1) * (E2) * E3
    + array3_size(E1, E2, E3)
    , ...)
    |
    devm_kzalloc(HANDLE,
    - (E1) * (E2) * (E3)
    + array3_size(E1, E2, E3)
    , ...)
    |
    devm_kzalloc(HANDLE,
    - E1 * E2 * E3
    + array3_size(E1, E2, E3)
    , ...)
    )

    // And then all remaining 2 factors products when they're not all constants,
    // keeping sizeof() as the second factor argument.
    @@
    expression HANDLE;
    expression THING, E1, E2;
    type TYPE;
    constant C1, C2, C3;
    @@

    (
    devm_kzalloc(HANDLE, sizeof(THING) * C2, ...)
    |
    devm_kzalloc(HANDLE, sizeof(TYPE) * C2, ...)
    |
    devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
    |
    devm_kzalloc(HANDLE, C1 * C2, ...)
    |
    - devm_kzalloc
    + devm_kcalloc
    (HANDLE,
    - sizeof(TYPE) * (E2)
    + E2, sizeof(TYPE)
    , ...)
    |
    - devm_kzalloc
    + devm_kcalloc
    (HANDLE,
    - sizeof(TYPE) * E2
    + E2, sizeof(TYPE)
    , ...)
    |
    - devm_kzalloc
    + devm_kcalloc
    (HANDLE,
    - sizeof(THING) * (E2)
    + E2, sizeof(THING)
    , ...)
    |
    - devm_kzalloc
    + devm_kcalloc
    (HANDLE,
    - sizeof(THING) * E2
    + E2, sizeof(THING)
    , ...)
    |
    - devm_kzalloc
    + devm_kcalloc
    (HANDLE,
    - (E1) * E2
    + E1, E2
    , ...)
    |
    - devm_kzalloc
    + devm_kcalloc
    (HANDLE,
    - (E1) * (E2)
    + E1, E2
    , ...)
    |
    - devm_kzalloc
    + devm_kcalloc
    (HANDLE,
    - E1 * E2
    + E1, E2
    , ...)
    )

    Signed-off-by: Kees Cook

    Kees Cook
     

09 Jun, 2018

1 commit

  • Pull GPIO updates from Linus Walleij:
    "This is the bulk of GPIO changes for the v4.18 development cycle.

    Core changes:

    - We have killed off VLA from the core library and all drivers.

    The background should be clear for everyone at this point:

    https://lwn.net/Articles/749064/

    Also I just don't like VLA's, kernel developers hate it when
    compilers do things behind their back. It's as simple as that.

    I'm sorry that they even slipped in to begin with. Kudos to Laura
    Abbott for exorcising them.

    - Support GPIO hogs in machines/board files.

    New drivers and chip support:

    - R-Car r8a77470 (RZ/G1C)

    - R-Car r8a77965 (M3-N)

    - R-Car r8a77990 (E3)

    - PCA953x driver improvements to accomodate more variants.

    Improvements and new features:

    - Support one interrupt per line on port A in the DesignWare dwapb
    driver.

    Misc:

    - Random cleanups, right header files in the drivers, some size
    optimizations etc"

    * tag 'gpio-v4.18-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio: (73 commits)
    gpio: davinci: fix build warning when !CONFIG_OF
    gpio: dwapb: Fix rework support for 1 interrupt per port A GPIO
    gpio: pxa: Include the right header
    gpio: pl061: Include the right header
    gpio: pch: Include the right header
    gpio: pcf857x: Include the right header
    gpio: pca953x: Include the right header
    gpio: palmas: Include the right header
    gpio: omap: Include the right header
    gpio: octeon: Include the right header
    gpio: mxs: Switch to SPDX identifier
    gpio: Remove VLA from stmpe driver
    gpio: mxc: Switch to SPDX identifier
    gpio: mxc: add clock operation
    gpio: Remove VLA from gpiolib
    gpio: aspeed: Use a cache of output data registers
    gpio: aspeed: Set output latch before changing direction
    gpio: pca953x: fix address calculation for pcal6524
    gpio: pca953x: define masks for addressing common and extended registers
    gpio: pca953x: set the PCA_PCAL flag also when matching by DT
    ...

    Linus Torvalds
     

23 May, 2018

2 commits

  • The current driver does a read/modify/write of the output
    registers when changing a bit in __aspeed_gpio_set().

    This is sub-optimal for a couple of reasons:

    - If any of the neighbouring GPIOs (sharing the shared
    register) isn't (yet) configured as an output, it will
    read the current input value, and then apply it to the
    output latch, which may not be what the user expects. There
    should be no bug in practice as aspeed_gpio_dir_out() will
    establish a new value but it's not great either.

    - The GPIO block in the aspeed chip is clocked rather
    slowly (typically 25Mhz). That extra MMIO read halves the maximum
    speed at which we can toggle the GPIO.

    This provides a significant performance improvement to the GPIO
    based FSI master.

    Signed-off-by: Benjamin Herrenschmidt
    Reviewed-by: Christopher Bostic
    Reviewed-by: Andrew Jeffery
    Tested-by: Joel Stanley
    Signed-off-by: Linus Walleij

    Benjamin Herrenschmidt
     
  • In aspeed_gpio_dir_out(), we need to establish the new output
    value in the output latch *before* we change the direction
    to output in order to avoid a glitch on the output line if
    the previous value of the latch was different.

    Signed-off-by: Benjamin Herrenschmidt
    Reviewed-by: Christopher Bostic
    Reviewed-by: Andrew Jeffery
    Tested-by: Joel Stanley
    Signed-off-by: Linus Walleij

    Benjamin Herrenschmidt
     

26 Apr, 2018

1 commit


28 Dec, 2017

1 commit


03 Dec, 2017

1 commit


09 Nov, 2017

1 commit


08 Nov, 2017

2 commits


20 Oct, 2017

1 commit


22 Sep, 2017

1 commit


15 Aug, 2017

1 commit


22 May, 2017

1 commit

  • We warn the user at driver probe time that debouncing is disabled.
    However, if they request debouncing later on we print a confusing error
    message:

    gpio_aspeed 1e780000.gpio: Failed to convert 5000us to cycles at 0Hz: -524

    Instead bail out when the clock is not present.

    Fixes: 5ae4cb94b3133 (gpio: aspeed: Add debounce support)
    Signed-off-by: Joel Stanley
    Signed-off-by: Linus Walleij

    Joel Stanley
     

24 Apr, 2017

2 commits

  • As per the datasheet, manage the IO and value states to implement
    open-source/open-drain, but do this by falling back to gpiolib's
    emulation.

    This commit simply makes the behaviour explicit for clarity, rather than
    relying on the implicit return of -ENOTSUPP to trigger the emulation.

    Signed-off-by: Andrew Jeffery
    Signed-off-by: Linus Walleij

    Andrew Jeffery
     
  • Each GPIO in the Aspeed GPIO controller can choose one of four input
    debounce states: to disable debouncing for an input, or select from one
    of three programmable debounce timer values. Each GPIO in a
    four-bank-set is assigned one bit in each of two debounce configuration
    registers dedicated to the set, and selects a debounce state by
    configuring the two bits to select one of the four options.

    The limitation on debounce timer values is managed by mapping offsets
    onto a configured timer value and keeping count of the number of users
    a timer has. Timer values are configured on a first-come-first-served
    basis.

    A small twist in the hardware design is that the debounce configuration
    register numbering is reversed with respect to the binary representation
    of the debounce timer of interest (i.e. debounce register 1 represents
    bit 1, and debounce register 2 represents bit 0 of the timer numbering).

    Tested on an AST2500EVB with additional inspection under QEMU's
    romulus-bmc machine.

    Signed-off-by: Andrew Jeffery
    Signed-off-by: Linus Walleij

    Andrew Jeffery
     

05 Feb, 2017

1 commit

  • 1736f75d35e47409ad776273133d0f558a4c8253 is a (v2) patch which had
    unresolved review comments[1]. Address the comments by removing the use
    of macros from the consumer header (this patch represents the diff
    between v2 and v3[2]).

    [1] https://lkml.org/lkml/2017/1/26/337
    [2] https://lkml.org/lkml/2017/1/26/786

    Fixes: 1736f75d35e4 ("gpio: aspeed: Add banks Y, Z, AA, AB and AC")
    Signed-off-by: Andrew Jeffery
    Acked-by: Joel Stanley
    Signed-off-by: Linus Walleij

    Andrew Jeffery
     

26 Jan, 2017

2 commits

  • This is less straight-forward than one would hope, as some banks only
    have 4 pins rather than 8, others are output only, yet more (W and
    X, already supported) are input-only, and in the case of the g4 SoC bank
    AC doesn't exist.

    Add some structs to describe the varying properties of different banks
    and integrate mechanisms to deny requests for unsupported
    configurations.

    Signed-off-by: Andrew Jeffery
    Signed-off-by: Linus Walleij

    Andrew Jeffery
     
  • The Aspeed SoCs have more GPIOs than can be represented with A-Z. The
    documentation uses two letter names such as AA and AB, so make the names
    a three-character array in the bank struct to accommodate this.

    Signed-off-by: Joel Stanley
    Signed-off-by: Andrew Jeffery
    Signed-off-by: Linus Walleij

    Joel Stanley
     

23 Sep, 2016

1 commit


15 Sep, 2016

1 commit


13 Sep, 2016

1 commit

  • The build complains about missing MODULE_LICENSE() in
    the Aspeed GPIO driver. The license is evident from the
    file header, put in "GPL".

    Reported-by: Stephen Rothwell
    Cc: Alistair Popple
    Cc: Jeremy Kerr
    Cc: Andrew Jeffery
    Acked-by: Joel Stanley
    Signed-off-by: Linus Walleij

    Linus Walleij
     

07 Sep, 2016

1 commit

  • The Aspeed SoCs contain GPIOs banked by letter, where each bank contains
    8 pins. The GPIO banks are then grouped in sets of four in the register
    layout.

    The implementation exposes multiple banks through the one driver and
    requests and releases pins via the pinctrl subsystem. The hardware
    supports generation of interrupts from all GPIO-capable pins.

    A number of hardware features are not yet supported: Configuration of
    interrupt direction (ARM or LPC), debouncing, and WDT reset tolerance
    for output ports.

    Signed-off-by: Joel Stanley
    Signed-off-by: Alistair Popple
    Signed-off-by: Jeremy Kerr
    Signed-off-by: Andrew Jeffery
    Signed-off-by: Linus Walleij

    Joel Stanley