spi: spi-ep93xx: simplify GPIO chip selects
PATCH 1/1 spi: spi-ep93xx: simplify GPIO chip selects
This driver requires a GPIO line to be used for the chip select of each SPI device.
Remove the ep93xx_spi_chip_ops definition from the platform data and just pass the required GPIO line as the controller_data for each spi_board_info entry. Then handle the gpio directly in the driver.
Fix all the ep93xx platforms that use this driver and update the Documentation with an in-tree example.
--- Documentation/spi/ep93xx_spi | 57 ++++------------------ arch/arm/mach-ep93xx/edb93xx.c | 25 +--------- arch/arm/mach-ep93xx/simone.c | 59 ++--------------------- arch/arm/mach-ep93xx/vision_ep9307.c | 82 ++------------------------------ drivers/spi/spi-ep93xx.c | 27 +++++------ include/linux/platform_data/spi-ep93xx.h | 12 ----- 6 files changed, 33 insertions(+), 229 deletions(-)
Documentation/spi/ep93xx_spi +9 -48
@@ -4,68 +4,29 @@ Cirrus EP93xx SPI controller driver HOWTO ep93xx_spi driver brings SPI master support for EP93xx SPI controller. Chip selects are implemented with GPIO lines. -NOTE: If possible, don't use SFRMOUT (SFRM1) signal as a chip select. It will -not work correctly (it cannot be controlled by software). Use GPIO lines -instead. +NOTE: Don't use SFRMOUT (SFRM1) signal as a chip select. It will not work +correctly (it cannot be controlled by software). Use GPIO lines instead. Sample configuration ==================== -Typically driver configuration is done in platform board files (the files under -arch/arm/mach-ep93xx/*.c). In this example we configure MMC over SPI through -this driver on TS-7260 board. You can adapt the code to suit your needs. - -This example uses EGPIO9 as SD/MMC card chip select (this is wired in DIO1 -header on the board). +In this example we configure MMC over SPI on the sim.one board. This example +uses EGPIO1 as SD/MMC card chip select. You need to select CONFIG_MMC_SPI to use mmc_spi driver. -arch/arm/mach-ep93xx/ts72xx.c: +arch/arm/mach-ep93xx/simone.c: ... -#include <linux/gpio.h> #include <linux/spi/spi.h> #include <linux/platform_data/spi-ep93xx.h> -/* this is our GPIO line used for chip select */ -#define MMC_CHIP_SELECT_GPIO EP93XX_GPIO_LINE_EGPIO9 - -static int ts72xx_mmc_spi_setup(struct spi_device *spi) -{ - int err; - - err = gpio_request(MMC_CHIP_SELECT_GPIO, spi->modalias); - if (err) - return err; - - gpio_direction_output(MMC_CHIP_SELECT_GPIO, 1); - - return 0; -} - -static void ts72xx_mmc_spi_cleanup(struct spi_device *spi) -{ - gpio_set_value(MMC_CHIP_SELECT_GPIO, 1); - gpio_direction_input(MMC_CHIP_SELECT_GPIO); - gpio_free(MMC_CHIP_SELECT_GPIO); -} - -static void ts72xx_mmc_spi_cs_control(struct spi_device *spi, int value) -{ - gpio_set_value(MMC_CHIP_SELECT_GPIO, value); -} - -static struct ep93xx_spi_chip_ops ts72xx_mmc_spi_ops = { - .setup = ts72xx_mmc_spi_setup, - .cleanup = ts72xx_mmc_spi_cleanup, - .cs_control = ts72xx_mmc_spi_cs_control, -}; - -static struct spi_board_info ts72xx_spi_devices[] __initdata = { +static struct spi_board_info simone_spi_devices[] __initdata = { { .modalias = "mmc_spi", - .controller_data = &ts72xx_mmc_spi_ops, + /* .platform_data as needed by the mmc_spi driver */ + .controller_data = (void*)EP93XX_GPIO_LINE_EGPIO1, /* * We use 10 MHz even though the maximum is 7.4 MHz. The driver * will limit it automatically to max. frequency.
@@ -73,7 +34,7 @@ static struct spi_board_info ts72xx_spi_devices[] __initdata = { .max_speed_hz = 10 * 1000 * 1000, .bus_num = 0, .chip_select = 0, - .mode = SPI_MODE_0, + .mode = SPI_MODE_3, }, };
arch/arm/mach-ep93xx/edb93xx.c +1 -24
@@ -27,7 +27,6 @@#include <linux/kernel.h> #include <linux/init.h> #include <linux/platform_device.h> -#include <linux/gpio.h> #include <linux/i2c.h> #include <linux/i2c-gpio.h> #include <linux/spi/spi.h>
@@ -106,33 +105,11 @@ static struct cs4271_platform_data edb93xx_cs4271_data = { .gpio_nreset = -EINVAL, /* filled in later */ }; -static int edb93xx_cs4271_hw_setup (struct spi_device *spi) -{ -return gpio_request_one (EP93XX_GPIO_LINE_EGPIO6 , -GPIOF_OUT_INIT_HIGH , spi->modalias); -} - -static void edb93xx_cs4271_hw_cleanup (struct spi_device *spi) -{ -gpio_free (EP93XX_GPIO_LINE_EGPIO6 ); -} - -static void edb93xx_cs4271_hw_cs_control (struct spi_device *spi,int value) -{ -gpio_set_value (EP93XX_GPIO_LINE_EGPIO6 , value); -} - -static struct ep93xx_spi_chip_ops edb93xx_cs4271_hw = { - .setup = edb93xx_cs4271_hw_setup, - .cleanup = edb93xx_cs4271_hw_cleanup, - .cs_control = edb93xx_cs4271_hw_cs_control, -}; -static struct spi_board_info edb93xx_spi_board_info[]__initdata = { { .modalias ="cs4271" , .platform_data = &edb93xx_cs4271_data, - .controller_data = &edb93xx_cs4271_hw, + .controller_data = (void *)EP93XX_GPIO_LINE_EGPIO6 , .max_speed_hz =6000000 , .bus_num =0 , .chip_select =0 ,
arch/arm/mach-ep93xx/simone.c +5 -54
80 lines not on this page · raw message
arch/arm/mach-ep93xx/vision_ep9307.c +5 -77
127 lines not on this page · raw message
drivers/spi/spi-ep93xx.c +13 -14
@@ -28,6 +28,7 @@#include <linux/platform_device.h> #include <linux/sched.h> #include <linux/scatterlist.h> +#include <linux/gpio.h> #include <linux/spi/spi.h> #include <linux/platform_data/dma-ep93xx.h>
@@ -110,11 +111,11 @@ struct ep93xx_spi {/** * struct ep93xx_spi_chip - SPI device hardware settings * @spi: back pointer to the SPI device -* @ops: private chip operations +* @cs_gpio: gpio used to chip select the device */ struct ep93xx_spi_chip {const struct spi_device *spi; -struct ep93xx_spi_chip_ops *ops; +unsigned int cs_gpio; };/* converts bits per word to CR0.DSS value */
@@ -234,8 +235,7 @@ static void ep93xx_spi_cs_control(struct spi_device *spi, bool control)struct ep93xx_spi_chip *chip =spi_get_ctldata (spi);int value = (spi->mode &SPI_CS_HIGH ) ? control : !control; -if (chip->ops && chip->ops->cs_control) - chip->ops->cs_control (spi, value); +gpio_set_value (chip->cs_gpio, value); }/**
@@ -254,6 +254,8 @@ static int ep93xx_spi_setup(struct spi_device *spi) chip =spi_get_ctldata (spi);if (!chip) { +int ret; +dev_dbg (&espi->pdev->dev,"initial setup for %s\n" , spi->modalias);
@@ -262,15 +264,13 @@ static int ep93xx_spi_setup(struct spi_device *spi)return -ENOMEM ; chip->spi = spi; - chip->ops = spi->controller_data; - -if (chip->ops && chip->ops->setup) { -int ret = chip->ops->setup (spi); + chip->cs_gpio = (unsigned long )spi->controller_data; -if (ret) { -kfree (chip); -return ret; - } + ret =gpio_request_one (chip->cs_gpio,GPIOF_OUT_INIT_HIGH , + spi->modalias); +if (ret) { +kfree (chip); +return ret; }spi_set_ctldata (spi, chip);
@@ -293,8 +293,7 @@ static void ep93xx_spi_cleanup(struct spi_device *spi) chip =spi_get_ctldata (spi);if (chip) { -if (chip->ops && chip->ops->cleanup) - chip->ops->cleanup (spi); +gpio_free (chip->cs_gpio);spi_set_ctldata (spi,NULL );kfree (chip); }
include/linux/platform_data/spi-ep93xx.h +0 -12
@@ -14,16 +14,4 @@ struct ep93xx_spi_info { bool use_dma; }; -/** -* struct ep93xx_spi_chip_ops - operation callbacks for SPI slave device -* @setup: setup the chip select mechanism -* @cleanup: cleanup the chip select mechanism -* @cs_control: control the device chip select -*/ -struct ep93xx_spi_chip_ops { -int (*setup)(struct spi_device *spi); -void (*cleanup)(struct spi_device *spi); -void (*cs_control)(struct spi_device *spi,int value); -}; -#endif /* __ASM_MACH_EP93XX_SPI_H */
Signature · 6 lines
2.10.0 -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): 20170215164422.5957-1-hsweeten-3FF4nKcrg1dE2c76skzGb0EOCMrvLtNR@public.gmane.org
Quoted 7 lines · H Hartley Sweeten
This driver requires a GPIO line to be used for the chip select of each SPI device.
Remove the
ep93xx_spi_chip_opsdefinition from the platform data and just pass the required GPIO line as thecontroller_datafor eachspi_board_infoentry. Then handle the gpio directly in the driver.
Why not also use the core GPIO handling?
A message that is not in the archive (sent off-list or not yet received): 20170215190138.g7jsecekhtm4gvkr-GFdadSzt00ze9xe1eoZjHA@public.gmane.org
Quoted 10 lines · Mark Brown
Quoted 7 lines · H Hartley Sweeten
This driver requires a GPIO line to be used for the chip select of each SPI device.
Remove the
ep93xx_spi_chip_opsdefinition from the platform data and just pass the required GPIO line as thecontroller_datafor eachspi_board_infoentry. Then handle the gpio directly in the driver.Why not also use the core GPIO handling?
I didn't know the core had that functionality. I'll take a look.
Hartley
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 10 lines · Mark Brown
Quoted 7 lines · H Hartley Sweeten
This driver requires a GPIO line to be used for the chip select of each SPI device.
Remove the
ep93xx_spi_chip_opsdefinition from the platform data and just pass the required GPIO line as thecontroller_datafor eachspi_board_infoentry. Then handle the gpio directly in the driver.Why not also use the core GPIO handling?
Mark,
Unless I'm missing something, I don't think I can use the core GPIO handling with the spi-ep93xx driver.
spi_set_cs() is only called to enable the chip select by the default implementation of transfer_one_message() and the spi-ep93xx driver does not use that.
Regards,
Hartley
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 10 lines · Mark Brown
Quoted 7 lines · H Hartley Sweeten
This driver requires a GPIO line to be used for the chip select of each SPI device.
Remove the
ep93xx_spi_chip_opsdefinition from the platform data and just pass the required GPIO line as thecontroller_datafor eachspi_board_infoentry. Then handle the gpio directly in the driver.Why not also use the core GPIO handling?
Ignore the previous emails. I think I figured it out.
I need to test it tomorrow then I will send an updated patch.
Thanks,
Hartley
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html