spi: new orion_spi driver
PATCH 1/1 spi: new orion_spi driver
From: Shadi Ammouri <[email protected]>
Date: Fri, 27 Jun 2008 19:10:06 +0200
Subject: [PATCH] spi: driver for Marvell Orion SPI controllers
This adds a SPI driver for the SPI controller found in various Marvell Orion ARM SoCs. It currently supports only one slave, which must use SPI mode 0.
---
Applies on top of the patch cleaning up drivers/spi/Kconfig. The code generated by orion_spi_write_read() could stand speedup, but such performance work can wait.
drivers/spi/Kconfig | 6 drivers/spi/Makefile | 1 drivers/spi/orion_spi.c | 572 ++++++++++++++++++++++++++++++++++++++++++ include/linux/spi/orion_spi.h | 17 + 4 files changed, 596 insertions(+)
drivers/spi/Kconfig +6 -0
@@ -156,6 +156,12 @@ config SPI_OMAP24XX SPI master controller for OMAP24xx/OMAP34xx Multichannel SPI (McSPI) modules. +config SPI_ORION + tristate "Orion SPI master (EXPERIMENTAL)" + depends on PLAT_ORION && EXPERIMENTAL + help + This enables using the SPI master controller on the Orion chips. + config SPI_PXA2XX tristate "PXA2xx SSP SPI master" depends on ARCH_PXA && EXPERIMENTAL
drivers/spi/Makefile +1 -0
@@ -21,6 +21,7 @@ obj-$(CONFIG_SPI_LM70_LLP) += spi_lm70l obj-$(CONFIG_SPI_PXA2XX) += pxa2xx_spi.o obj-$(CONFIG_SPI_OMAP_UWIRE) += omap_uwire.o obj-$(CONFIG_SPI_OMAP24XX) += omap2_mcspi.o +obj-$(CONFIG_SPI_ORION) += orion_spi.o obj-$(CONFIG_SPI_MPC52xx_PSC) += mpc52xx_psc_spi.o obj-$(CONFIG_SPI_MPC83xx) += spi_mpc83xx.o obj-$(CONFIG_SPI_S3C24XX_GPIO) += spi_s3c24xx_gpio.o
drivers/spi/orion_spi.c new file +572 -0
572 lines not on this page · raw message
include/linux/spi/orion_spi.h new file +17 -0
@@ -0,0 +1,17 @@ +/* +* orion_spi.h +* +* This file is licensed under the terms of the GNU General Public +* License version 2. This program is licensed "as is" without any +* warranty of any kind, whether express or implied. +*/ + +#ifndef __LINUX_SPI_ORION_SPI_H +#define __LINUX_SPI_ORION_SPI_H + +struct orion_spi_info { +u32 tclk;/* no <linux/clk.h> support yet */ +}; + + +#endif
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
A message that is not in the archive (sent off-list or not yet received): 200807221228.00958.david-b-yBeKhBN/[email protected]
Quoted 29 lines · On Tue, 22 Jul 2008 12:28:00 -0700 David Brownell…
From: Shadi Ammouri <[email protected]>
Date: Fri, 27 Jun 2008 19:10:06 +0200
Subject: [PATCH] spi: driver for Marvell Orion SPI controllersThis adds a SPI driver for the SPI controller found in various Marvell Orion ARM SoCs. It currently supports only one slave, which must use SPI mode 0.
[ [email protected]: cleanups, meet specs, pass "sparse" ]Signed-off-by Shadi Ammouri <[email protected]>Signed-off-by Saeed Bishara <[email protected]>Signed-off-by Lennert Buytenhek <[email protected]>Signed-off-by David Brownell <[email protected]>...
drivers/spi/orion_spi.c new file +13
-0+/* +* called only when no transfer is active on the bus +*/ +static int +orion_spi_setup_transfer (struct spi_device *spi,struct spi_transfer *t) +{ +struct orion_spi *orion_spi; +unsigned int speed = spi->max_speed_hz; +unsigned int bits_per_word = spi->bits_per_word; + + orion_spi =spi_master_get_devdata (spi->master); + +if ((t !=NULL ) && t->speed_hz)
drivers/spi/orion_spi.c line 154
Quoted 10 lines
drivers/spi/orion_spi.c new file +10
-0+ speed = t->speed_hz; + +if ((t !=NULL ) && t->bits_per_word) + bits_per_word = t->bits_per_word; + +if (orion_spi_baudrate_set (spi, speed) !=0 ) +return -EINVAL ; + +if (orion_spi_set_transfer_size (orion_spi, bits_per_word) !=0 ) +return -EINVAL ;
Given that orion_spi_baudrate_set() and orion_spi_set_transfer_size() carefully return an -EFOO value, it's a bit unkind to just rub that out and return a hard-coded -EINVAL.
drivers/spi/orion_spi.c line 567
Quoted 8 lines
...
drivers/spi/orion_spi.c new file +6
-0+static void __exit orion_spi_exit(void) +{ +platform_driver_unregister (&orion_spi_driver); + +destroy_workqueue (orion_spi_wq); +}
Please double-check the workqueue handling. Without looking at it too closely, I think that this is waaaay too late to be running destroy_workqueue(). If a work is still pending, all the data upon which it will be operating will have been rubbed out. I'm suspecting that an earlier flush_work() (or similar) will be needed.
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
A message that is not in the archive (sent off-list or not yet received): 20080728211655.4d51e921.akpm-de/[email protected]
Quoted 10 lines · Andrew Morton
drivers/spi/orion_spi.c line 154
Quoted 6 lines
drivers/spi/orion_spi.c new file +6
-0+ + if (orion_spi_baudrate_set(spi, speed) != 0) + return -EINVAL; + + if (orion_spi_set_transfer_size(orion_spi, bits_per_word) != 0) + return -EINVAL;Given that
orion_spi_baudrate_set()andorion_spi_set_transfer_size()carefully return an-EFOOvalue, it's a bit unkind to just rub that out and return a hard-coded-EINVAL.
Right; I suppose I was so glad to see the previous issue fixed that I ended up overlookig that one!
Shadi ... can you provide updates for these issues?
- Dave
Quoted 15 lines
drivers/spi/orion_spi.c line 567
Quoted 8 lines
...
drivers/spi/orion_spi.c new file +6
-0+static void __exit orion_spi_exit(void) +{ + platform_driver_unregister(&orion_spi_driver); + + destroy_workqueue(orion_spi_wq); +}Please double-check the workqueue handling. Without looking at it too closely, I think that this is waaaay too late to be running
destroy_workqueue(). If a work is still pending, all the data upon which it will be operating will have been rubbed out. I'm suspecting that an earlierflush_work()(or similar) will be needed.
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
A message that is not in the archive (sent off-list or not yet received): 200807282343.25058.david-b-yBeKhBN/[email protected]
Quoted 10 lines
Quoted 10 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+ +Â Â Â Â Â if (orion_spi_baudrate_set(spi, speed) != 0) +Â Â Â Â Â Â Â Â Â Â Â Â Â return -EINVAL; + +Â Â Â Â Â if (orion_spi_set_transfer_size(orion_spi, bits_per_word) != 0) +Â Â Â Â Â Â Â Â Â Â Â Â Â return -EINVAL;Given that
orion_spi_baudrate_set()andorion_spi_set_transfer_size()carefully return an-EFOOvalue, it's a bit unkind to just rub that out and return a hard-coded-EINVAL.
right, done in the patch below
Quoted 13 lines
Quoted 13 lines
Review
Quoted 7 lines
(quoted diff) +6
-0+static void __exit orion_spi_exit(void) +{ +Â Â Â Â Â platform_driver_unregister(&orion_spi_driver); + +Â Â Â Â Â destroy_workqueue(orion_spi_wq); +}Please double-check the workqueue handling. Â Without looking at it too closely, I think that this is waaaay too late to be running
destroy_workqueue(). Â If a work is still pending, all the data upon which it will be operating will have been rubbed out. Â I'm suspecting that an earlierflush_work()(or similar) will be needed.
added cancel_work_sync to cancel the work of the device when removing it, and flush_workqueue on the driver's removal.
here is the patch with the modifications needed by the two comments:
------------------>8
drivers/spi/orion_spi.c +9 -7
@@ -138,6 +138,7 @@ orion_spi_setup_transfer(struct spi_device *spi, struct spi_transfer *t)struct orion_spi *orion_spi;unsigned int speed = spi->max_speed_hz;unsigned int bits_per_word = spi->bits_per_word; +int rc; orion_spi =spi_master_get_devdata (spi->master);
@@ -147,13 +148,11 @@ orion_spi_setup_transfer(struct spi_device *spi, struct spi_transfer *t)if ((t !=NULL ) && t->bits_per_word) bits_per_word = t->bits_per_word; -if (orion_spi_baudrate_set (spi, speed) !=0 ) -return -EINVAL ; - -if (orion_spi_set_transfer_size (orion_spi, bits_per_word) !=0 ) -return -EINVAL ; - -return 0 ; + rc =orion_spi_baudrate_set (spi, speed); +if (rc) +return rc; + +return orion_spi_set_transfer_size (orion_spi, bits_per_word); }static void orion_spi_set_cs (struct orion_spi *orion_spi,int enable)
@@ -530,6 +529,8 @@ static int __exit orion_spi_remove(struct platform_device *pdev) master =dev_get_drvdata (&pdev->dev); spi =spi_master_get_devdata (master); +cancel_work_sync (&spi->work); + r =platform_get_resource (pdev,IORESOURCE_MEM ,0 );release_mem_region (r->start, (r->end - r->start) +1 );
@@ -561,6 +562,7 @@ module_init(orion_spi_init); static void __exit orion_spi_exit(void) { +flush_workqueue (orion_spi_wq);platform_driver_unregister (&orion_spi_driver);destroy_workqueue (orion_spi_wq);
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
spi-devel-general mailing list spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/spi-devel-general