• Linus Walleij's avatar
    spi: Optionally use GPIO descriptors for CS GPIOs · f3186dd8
    Linus Walleij authored
    This augments the SPI core to optionally use GPIO descriptors
    for chip select on a per-master-driver opt-in basis.
    
    Drivers using this will rely on the SPI core to look up
    GPIO descriptors associated with the device, such as
    when using device tree or board files with GPIO descriptor
    tables.
    
    When getting descriptors from the device tree, this will in
    turn activate the code in gpiolib that was
    added in commit 6953c57a
    ("gpio: of: Handle SPI chipselect legacy bindings")
    which means that these descriptors are aware of the active
    low semantics that is the default for SPI CS GPIO lines
    and we can assume that all of these are "active high" and
    thus assign SPI_CS_HIGH to all CS lines on the DT path.
    
    The previously used gpio_set_value() would call down into
    gpiod_set_raw_value() and ignore the polarity inversion
    semantics.
    
    It seems like many drivers go to great lengths to set up the
    CS GPIO line as non-asserted, respecting SPI_CS_HIGH. We pull
    this out of the SPI drivers and into the core, and by simply
    requesting the line as GPIOD_OUT_LOW when retrieveing it from
    the device and relying on the gpiolib to handle any inversion
    semantics. This way a lot of code can be simplified and
    removed in each converted driver.
    
    The end goal after dealing with each driver in turn, is to
    delete the non-descriptor path (of_spi_register_master() for
    example) and let the core deal with only descriptors.
    
    The different SPI drivers have complex interactions with the
    core so we cannot simply change them all over, we need to use
    a stepwise, bisectable approach so that each driver can be
    converted and fixed in isolation.
    
    This patch has the intended side effect of adding support for
    ACPI GPIOs as it starts relying on gpiod_get_*() to get
    the GPIO handle associated with the device.
    
    Cc: Linuxarm <linuxarm@huawei.com>
    Acked-by: default avatarJonathan Cameron <jonathan.cameron@huawei.com>
    Tested-by: default avatarFangjian (Turing) <f.fangjian@huawei.com>
    Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
    Signed-off-by: default avatarMark Brown <broonie@kernel.org>
    f3186dd8
spi.c 99.6 KB