spi: spi-ep93xx: simplify GPIO chip selects
PATCH v2 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 use the spi core GPIO handling for the chip selects.
Fix all the ep93xx platforms that use this driver and remove the old Documentation.
--- Documentation/spi/ep93xx_spi | 105 ----------------------- arch/arm/mach-ep93xx/edb93xx.c | 31 ++----- arch/arm/mach-ep93xx/simone.c | 64 +++----------- arch/arm/mach-ep93xx/vision_ep9307.c | 88 +++---------------- drivers/spi/spi-ep93xx.c | 139 ++++++++++--------------------- include/linux/platform_data/spi-ep93xx.h | 17 +--- 6 files changed, 74 insertions(+), 370 deletions(-) delete mode 100644 Documentation/spi/ep93xx_spi
Documentation/spi/ep93xx_spi deleted +0 -105
@@ -1,105 +0,0 @@ -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. - -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). - -You need to select CONFIG_MMC_SPI to use mmc_spi driver. - -arch/arm/mach-ep93xx/ts72xx.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 = { - { - .modalias = "mmc_spi", - .controller_data = &ts72xx_mmc_spi_ops, - /* - * We use 10 MHz even though the maximum is 7.4 MHz. The driver - * will limit it automatically to max. frequency. - */ - .max_speed_hz = 10 * 1000 * 1000, - .bus_num = 0, - .chip_select = 0, - .mode = SPI_MODE_0, - }, -}; - -static struct ep93xx_spi_info ts72xx_spi_info = { - .num_chipselect = ARRAY_SIZE(ts72xx_spi_devices), -}; - -static void __init ts72xx_init_machine(void) -{ - ... - ep93xx_register_spi(&ts72xx_spi_info, ts72xx_spi_devices, - ARRAY_SIZE(ts72xx_spi_devices)); -} - -The driver can use DMA for the transfers also. In this case ts72xx_spi_info -becomes: - -static struct ep93xx_spi_info ts72xx_spi_info = { - .num_chipselect = ARRAY_SIZE(ts72xx_spi_devices), - .use_dma = true; -}; - -Note that CONFIG_EP93XX_DMA should be enabled as well. - -Thanks to -========= -Martin Guy, H. Hartley Sweeten and others who helped me during development of -the driver. Simplemachines.it donated me a Sim.One board which I used testing -the driver on EP9307.
arch/arm/mach-ep93xx/edb93xx.c +6 -25
@@ -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,10 @@ 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, .max_speed_hz =6000000 , .bus_num =0 , .chip_select =0 ,
@@ -140,8 +116,13 @@ static struct spi_board_info edb93xx_spi_board_info[] __initdata = { }, }; +static int edb93xx_spi_chipselects[]__initdata = { +EP93XX_GPIO_LINE_EGPIO6 , +}; +static struct ep93xx_spi_info edb93xx_spi_info__initdata = { - .num_chipselect =ARRAY_SIZE (edb93xx_spi_board_info), + .chipselect = edb93xx_spi_chipselects, + .num_chipselect =ARRAY_SIZE (edb93xx_spi_chipselects), };static void __init edb93xx_register_spi (void )
arch/arm/mach-ep93xx/simone.c +11 -53
89 lines not on this page · raw message
arch/arm/mach-ep93xx/vision_ep9307.c +10 -78
140 lines not on this page · raw message
drivers/spi/spi-ep93xx.c +44 -95
204 lines not on this page · raw message
include/linux/platform_data/spi-ep93xx.h +3 -14
@@ -5,25 +5,14 @@ struct spi_device;/** * struct ep93xx_spi_info - EP93xx specific SPI descriptor -* @num_chipselect: number of chip selects on this board, must be -* at least one +* @chipselect: array of gpio numbers to use as chip selects +* @num_chipselect: ARRAY_SIZE(chipselect) * @use_dma: use DMA for the transfers */ struct ep93xx_spi_info { +int *chipselect;int num_chipselect;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): 20170216182614.47941-1-hsweeten-3FF4nKcrg1dE2c76skzGb0EOCMrvLtNR@public.gmane.org
Quoted 2 lines · H Hartley Sweeten
This driver requires a GPIO line to be used for the chip select of each SPI device.
This doesn't apply against current code, there's conflicts in the arch code. What's the story here (should I just apply after -rc1?)?
A message that is not in the archive (sent off-list or not yet received): 20170216190109.kvsgigo4wlnaacvm-GFdadSzt00ze9xe1eoZjHA@public.gmane.org
Quoted 6 lines · Mark Brown
Quoted 2 lines · H Hartley Sweeten
This driver requires a GPIO line to be used for the chip select of each SPI device.
This doesn't apply against current code, there's conflicts in the arch code. What's the story here (should I just apply after -rc1?)?
Oops. The conflict is probably with arch/arm/mach-ep93xx/simone.c.
I have another patch to that file that is still under review.
I'll rebase this and post a v3 shortly.
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