[PATCH 1/2] SPI: control CS via standard GPIO operations instead of SPI-HW
Marc Kleine-Budde
mkl at pengutronix.de
Wed Mar 4 09:01:20 PST 2015
On 03/04/2015 05:40 PM, kernel at martin.sperl.org wrote:
> From: Martin Sperl <kernel at martin.sperl.org>
>
> Allow the cs-gpios property in DT to be used instead of the
> fixed two chip-selects provided by the SPI-HW itself
>
> Signed-off-by: Martin Sperl <kernel at martin.sperl.org>
>
> ---
>
> There is the question if we still need to support the chip_selects
> provided by the hardware (plus the buggy CSPOL_HIGH support for those cases)
> or if we could just make the cs-gpios a required setting for this driver.
> Going with the GPIO only solution would clean up the code a bit.
>
> drivers/spi/spi-bcm2835.c | 53 +++++++++++++++++++++++++++++++++++++++------
> 1 file changed, 46 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/spi/spi-bcm2835.c b/drivers/spi/spi-bcm2835.c
> index 419a782..128a152 100644
> --- a/drivers/spi/spi-bcm2835.c
> +++ b/drivers/spi/spi-bcm2835.c
> @@ -3,6 +3,7 @@
> *
> * Copyright (C) 2012 Chris Boot
> * Copyright (C) 2013 Stephen Warren
> + * Copyright (C) 2015 Martin Sperl
> *
> * This driver is inspired by:
> * spi-ath79.c, Copyright (C) 2009-2011 Gabor Juhos <juhosg at openwrt.org>
> @@ -30,6 +31,7 @@
> #include <linux/of.h>
> #include <linux/of_irq.h>
> #include <linux/of_device.h>
> +#include <linux/of_gpio.h>
> #include <linux/spi/spi.h>
>
> /* SPI register offsets */
> @@ -116,6 +118,18 @@ static inline void bcm2835_wr_fifo(struct bcm2835_spi *bs, int len)
> }
> }
>
> +/* ideally spi_set_cs would be exported by spi-core */
> +static inline void bcm2835_set_cs(struct spi_device *spi, bool enable)
> +{
> +
> + if (spi->mode & SPI_CS_HIGH)
> + enable = !enable;
> +
> + if (spi->cs_gpio >= 0)
You might want to use gpio_is_valid() instead of open coding it.
Marc
--
Pengutronix e.K. | Marc Kleine-Budde |
Industrial Linux Solutions | Phone: +49-231-2826-924 |
Vertretung West/Dortmund | Fax: +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de |
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://lists.infradead.org/pipermail/linux-rpi-kernel/attachments/20150304/e3d80641/attachment.sig>
More information about the linux-rpi-kernel
mailing list