Skip to contentSkip to conversation

SPI patches for 2.6.15

PATCH In review Greg KH 4 participants 18 messages Jan 14, 2006 – Jan 16, 2006 1 message not in the archive

Subsystems (4)
lore
Share & tools
lore

Greg KH

author
#0 lore raw

PATCH 1/1 SPI patches for 2.6.15

Here are a few patches for 2.6.15 that add a SPI driver subsystem to the kernel tree. All of these patches have been in the -mm tree for a long time, and David and Vitaly have finally agreed that this code base is the proper one to work from for future SPI development.

These patches also add a few SPI drivers that use the subsystem, with more promised to be coming soon.

Please pull from:

	rsync://rsync.kernel.org/pub/scm/linux/kernel/git/gregkh/spi-2.6.git/
or if master.kernel.org hasn't synced up yet:
	master.kernel.org:/pub/scm/linux/kernel/git/gregkh/spi-2.6.git/

The full patches will be sent to the linux-kernel mailing list, if anyone wants to see them.

thanks,

greg k-h

 Documentation/spi/butterfly         |   57 ++
 Documentation/spi/spi-summary       |  497 +++++++++++++++++++++-
 arch/arm/Kconfig                    |    2 
 drivers/Kconfig                     |    2 
 drivers/Makefile                    |    1 
 drivers/input/touchscreen/Kconfig   |   13 
 drivers/input/touchscreen/Makefile  |    1 
 drivers/input/touchscreen/ads7846.c |  717 ++++++++++++++++++++++++++++++--
 drivers/mtd/devices/Kconfig         |   16 
 drivers/mtd/devices/Makefile        |    2 
 drivers/mtd/devices/m25p80.c        |  634 +++++++++++++++++++++++++++--
 drivers/mtd/devices/mtd_dataflash.c |  653 +++++++++++++++++++++++++++++
 drivers/spi/Kconfig                 |  109 ++++
 drivers/spi/Makefile                |   25 +
 drivers/spi/spi.c                   |  756 ++++++++++++++++++++++++++++++++--
 drivers/spi/spi_bitbang.c           |  546 +++++++++++++++++++++++--
 drivers/spi/spi_butterfly.c         |  423 +++++++++++++++++++
 include/linux/spi/ads7846.h         |   20 
 include/linux/spi/flash.h           |   31 +
 include/linux/spi/spi.h             |  786 +++++++++++++++++++++++++++++++++---
 include/linux/spi/spi_bitbang.h     |  135 ++++++
 21 files changed, 5168 insertions(+), 258 deletions(-)

Andrew Morton:
spi: remove fastcall crap

David Brownell:
spi: mtd dataflash driver
spi: simple SPI framework
spi: add spi_driver to SPI framework
spi: ads7846 driver
SPI core tweaks, bugfix
spi: ads7836 uses spi_driver
spi: add spi_bitbang driver
SPI: add spi_butterfly driver
spi: misc fixes

Mike Lavender:
spi: M25 series SPI flash

Vitaly Wool:
spi: use linked lists rather than an array

#1 lore raw
Quoted 7 lines · Greg KH

Here are a few patches for 2.6.15 that add a SPI driver subsystem to the kernel tree. All of these patches have been in the -mm tree for a long time, and David and Vitaly have finally agreed that this code base is the proper one to work from for future SPI development.

These patches also add a few SPI drivers that use the subsystem, with more promised to be coming soon.

Well, it turns out that google does not (yet) know what a SPI driver subsystem is yet... And SPI can be any of these in LKML context:

SCSI Parallel Interface
Serial Peripheral Interface
Service Provider Interface
Stateful Packet Inspection
System Packet Interface

http://en.wikipedia.org/wiki/SPI

Betting on the last, based on the filenames in the changelog...

Quoted 7 lines

Please pull from:

	rsync://rsync.kernel.org/pub/scm/linux/kernel/git/gregkh/spi-2.6.git/
or if master.kernel.org hasn't synced up yet:
	master.kernel.org:/pub/scm/linux/kernel/git/gregkh/spi-2.6.git/

The full patches will be sent to the linux-kernel mailing list, if anyone wants to see them.

May be just a browser accessible URL for Documentation/spi/spi-summary or at least a definition of SPI in the header of the mail.

git is just too complex for me at htemoment (haven't found the time to learn it)

Sorry for bugging you, Greg :-|

Kalin.

Signature · 3 lines
|[ ~~~~~~~~~~~~~~~~~~~~~~ ]|
+-> http://ThinRope.net/ <-+
|[ ______________________ ]|
#2 lore raw
Quoted 11 lines · Kalin KOZHUHAROV
Quoted 5 lines · Greg KH

Here are a few patches for 2.6.15 that add a SPI driver subsystem to the kernel tree.

Please pull from:

	rsync://rsync.kernel.org/pub/scm/linux/kernel/git/gregkh/spi-2.6.git/

May be just a browser accessible URL for Documentation/spi/spi-summary or at least a definition of SPI in the header of the mail.

git is just too complex for me at htemoment (haven't found the time to learn it)

If the git web interface is "too complex" for you, then you may not need to know what SPI is too. :)

http://www.kernel.org/git/?p=linux/kernel/git/gregkh/spi-2.6.git;a=commitdiff;h=8ae12a0d85987dc138f8c944cb78a92bf466cea0

Take care,
Kay

author
#10 lore raw

PATCH 1/1 spi: ads7846 driver

In reply to Greg KH

[PATCH] spi: ads7846 driver

This is a driver for the ADS7846 touchscreen sensor, derived from the corgi_ts and omap_ts drivers. Key differences from those two:

- Uses the new SPI framework (minimalist version)
- <linux/spi/ads7846.h> abstracts board-specific touchscreen info
- Sysfs attributes for the temperature and voltage sensors
- Uses fewer ARM-specific IRQ primitives

The temperature and voltage sensors show up in sysfs like this:

  $ pwd
  /sys/devices/platform/omap-uwire/spi2.0
  $ ls
  bus@          input:event0@ power/        temp1         vbatt
  driver@       modalias      temp0         vaux
  $ cat modalias
  ads7846
  $ cat temp0
  991
  $ cat temp1
  1177
  $

So far only basic testing has been done. There's a fair amount of hardware that uses this sensor, and which also runs Linux, which should eventually be able to use this driver.

One portability note may be of special interest. It turns out that not all SPI controllers are happy issuing requests that do things like "write 8 bit command, read 12 bit response". Most of them seem happy to handle various word sizes, so the issue isn't "12 bit response" but rather "different rx and tx write sizes", despite that being a common MicroWire convention. So this version of the driver no longer reads 12 bit native-endian words; it reads 16-bit big-endian responses, then byteswaps them and shifts the results to discard the noise.

---
commit ffa458c1bd9b6f653008d450f337602f3d52a646
tree 0e42f7d36790dd7088586b32d9c5290d34b10831
parent 8ae12a0d85987dc138f8c944cb78a92bf466cea0
author David Brownell <[email protected]> Sun, 08 Jan 2006 13:34:21 -0800 committer Greg Kroah-Hartman <[email protected]> Fri, 13 Jan 2006 16:29:54 -0800

 drivers/input/touchscreen/Kconfig   |   13 +
 drivers/input/touchscreen/Makefile  |    1 
 drivers/input/touchscreen/ads7846.c |  621 +++++++++++++++++++++++++++++++++++
 include/linux/spi/ads7846.h         |   18 +
 4 files changed, 653 insertions(+), 0 deletions(-)
drivers/input/touchscreen/Kconfig +13 -0
index 21d55ed..2c67402 100644
@@ -11,6 +11,19 @@ menuconfig INPUT_TOUCHSCREEN
 
 if INPUT_TOUCHSCREEN
 
+config TOUCHSCREEN_ADS7846
+	tristate "ADS 7846 based touchscreens"
+	depends on SPI_MASTER
+	help
+	  Say Y here if you have a touchscreen interface using the
+	  ADS7846 controller, and your board-specific initialization
+	  code includes that in its table of SPI devices.
+
+	  If unsure, say N (but it's safe to say "Y").
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called ads7846.
+
 config TOUCHSCREEN_BITSY
 	tristate "Compaq iPAQ H3600 (Bitsy) touchscreen"
 	depends on SA1100_BITSY
drivers/input/touchscreen/Makefile +1 -0
index 6842869..5e5557c 100644
@@ -4,6 +4,7 @@
 
 # Each configuration option enables a list of files.
 
+obj-$(CONFIG_TOUCHSCREEN_ADS7846)	+= ads7846.o
 obj-$(CONFIG_TOUCHSCREEN_BITSY)	+= h3600_ts_input.o
 obj-$(CONFIG_TOUCHSCREEN_CORGI)	+= corgi_ts.o
 obj-$(CONFIG_TOUCHSCREEN_GUNZE)	+= gunze.o
drivers/input/touchscreen/ads7846.c new file +621 -0

621 lines not on this page · raw message

include/linux/spi/ads7846.h new file +18 -0
new file mode 100644
index 0000000..84a2701
@@ -0,0 +1,18 @@
+/* linux/spi/ads7846.h */
+
+/* Touchscreen characteristics vary between boards and models.  The
+ * platform_data for the device's "struct device" holts this information.
+ *
+ * It's OK if the min/max values are zero.
+ */
+struct ads7846_platform_data {
+	u16	model;			/* 7843, 7845, 7846. */
+	u16	vref_delay_usecs;	/* 0 for external vref; etc */
+	u16	x_plate_ohms;
+	u16	y_plate_ohms;
+
+	u16	x_min, x_max;
+	u16	y_min, y_max;
+	u16	pressure_min, pressure_max;
+};
+
author
#14 lore raw

PATCH 1/1 spi: add spi_bitbang driver

In reply to Greg KH

[PATCH] spi: add spi_bitbang driver

This adds a bitbanging spi master, hooking up to board/adapter-specific glue code which knows how to set and read the signals (gpios etc).

This code kicks in after the glue code creates a platform_device with the right platform_data. That data includes I/O loops, which will usually come from expanding an inline function (provided in the header). One goal is that the I/O loops should be easily optimized down to a few GPIO register accesses, in common cases, for speed and minimized overhead.

This understands all the currently defined protocol tweaking options in the SPI framework, and might eventually serve as as reference implementation.

- different word sizes (1..32 bits)
- differing clock rates
- SPI modes differing by CPOL (affecting chip select and I/O loops)
- SPI modes differing by CPHA (affecting I/O loops)
- delays (usecs) after transfers
- temporarily deselecting chips in mid-transfer

A lot of hardware could work with this framework, though common types of controller can't reach peak performance without switching to a driver structure that supports pipelining of transfers (e.g. DMA queues) and maybe controllers (e.g. IRQ driven).

---
commit 9904f22a7202c6b54e96b0cc9870817013c350a1
tree 02d526b1bf54b1c64e58a9f903269f9cdc6ec83c
parent 2e5a7bd978bf4118a0c8edf2e6ff81d0a72fee47
author David Brownell <[email protected]> Sun, 08 Jan 2006 13:34:26 -0800 committer Greg Kroah-Hartman <[email protected]> Fri, 13 Jan 2006 16:29:55 -0800

 drivers/spi/Kconfig             |   13 +
 drivers/spi/Makefile            |    1 
 drivers/spi/spi_bitbang.c       |  460 +++++++++++++++++++++++++++++++++++++++
 include/linux/spi/spi_bitbang.h |  128 +++++++++++
 4 files changed, 602 insertions(+), 0 deletions(-)
drivers/spi/Kconfig +13 -0
index d310510..9b21c5d 100644
@@ -51,6 +51,19 @@ config SPI_MASTER
 comment "SPI Master Controller Drivers"
 	depends on SPI_MASTER
 
+config SPI_BITBANG
+	tristate "Bitbanging SPI master"
+	depends on SPI_MASTER && EXPERIMENTAL
+	help
+	  With a few GPIO pins, your system can bitbang the SPI protocol.
+	  Select this to get SPI support through I/O pins (GPIO, parallel
+	  port, etc).  Or, some systems' SPI master controller drivers use
+	  this code to manage the per-word or per-transfer accesses to the
+	  hardware shift registers.
+
+	  This is library code, and is automatically selected by drivers that
+	  need it.  You only need to select this explicitly to support driver
+	  modules that aren't part of this kernel tree.
 
 #
 # Add new SPI master controllers in alphabetical order above this line
drivers/spi/Makefile +1 -0
index afd2321..5da6a4d 100644
@@ -11,6 +11,7 @@ endif
 obj-$(CONFIG_SPI_MASTER)		+= spi.o
 
 # SPI master controller drivers (bus)
+obj-$(CONFIG_SPI_BITBANG)		+= spi_bitbang.o
 # 	... add above this line ...
 
 # SPI protocol drivers (device/link on bus)
drivers/spi/spi_bitbang.c new file +460 -0

460 lines not on this page · raw message

include/linux/spi/spi_bitbang.h new file +128 -0

128 lines not on this page · raw message

author
#12 lore raw

PATCH 1/1 spi: ads7836 uses spi_driver

In reply to Greg KH

[PATCH] spi: ads7836 uses spi_driver

This updates the ads7864 driver to use the new "spi_driver" struct, and includes some minor unrelated cleanup.

---
commit 2e5a7bd978bf4118a0c8edf2e6ff81d0a72fee47
tree ee5b09d090c7a4a6cbf19ddf9f252d315b46eda1
parent 0c868461fcb8413cb9f691d68e5b99b0fd3c0737
author David Brownell <[email protected]> Sun, 08 Jan 2006 13:34:25 -0800 committer Greg Kroah-Hartman <[email protected]> Fri, 13 Jan 2006 16:29:55 -0800

 drivers/input/touchscreen/ads7846.c |   84 ++++++++++++++++++-----------------
 include/linux/spi/ads7846.h         |    2 -
 2 files changed, 43 insertions(+), 43 deletions(-)
drivers/input/touchscreen/ads7846.c +42 -42
index 24ff6c5..c741776 100644
@@ -345,19 +345,15 @@ static irqreturn_t ads7846_irq(int irq, 
 
 /*--------------------------------------------------------------------------*/
 
-/* non-empty "extra" is needed before 2.6.14-git5 or so */
-#define	EXTRA	//	, u32 level
-#define	EXTRA2	//	, 0
-
 static int
-ads7846_suspend(struct device *dev, pm_message_t message EXTRA)
+ads7846_suspend(struct spi_device *spi, pm_message_t message)
 {
-	struct ads7846 *ts = dev_get_drvdata(dev);
+	struct ads7846 *ts = dev_get_drvdata(&spi->dev);
 	unsigned long	flags;
 
 	spin_lock_irqsave(&ts->lock, flags);
 
-	ts->spi->dev.power.power_state = message;
+	spi->dev.power.power_state = message;
 
 	/* are we waiting for IRQ, or polling? */
 	if (!ts->pendown) {
@@ -387,36 +383,35 @@ ads7846_suspend(struct device *dev, pm_m
 	return 0;
 }
 
-static int ads7846_resume(struct device *dev EXTRA)
+static int ads7846_resume(struct spi_device *spi)
 {
-	struct ads7846 *ts = dev_get_drvdata(dev);
+	struct ads7846 *ts = dev_get_drvdata(&spi->dev);
 
 	ts->irq_disabled = 0;
 	enable_irq(ts->spi->irq);
-	dev->power.power_state = PMSG_ON;
+	spi->dev.power.power_state = PMSG_ON;
 	return 0;
 }
 
-static int __init ads7846_probe(struct device *dev)
+static int __devinit ads7846_probe(struct spi_device *spi)
 {
-	struct spi_device		*spi = to_spi_device(dev);
 	struct ads7846			*ts;
-	struct ads7846_platform_data	*pdata = dev->platform_data;
+	struct ads7846_platform_data	*pdata = spi->dev.platform_data;
 	struct spi_transfer		*x;
 
 	if (!spi->irq) {
-		dev_dbg(dev, "no IRQ?\n");
+		dev_dbg(&spi->dev, "no IRQ?\n");
 		return -ENODEV;
 	}
 
 	if (!pdata) {
-		dev_dbg(dev, "no platform data?\n");
+		dev_dbg(&spi->dev, "no platform data?\n");
 		return -ENODEV;
 	}
 
 	/* don't exceed max specified sample rate */
 	if (spi->max_speed_hz > (125000 * 16)) {
-		dev_dbg(dev, "f(sample) %d KHz?\n",
+		dev_dbg(&spi->dev, "f(sample) %d KHz?\n",
 				(spi->max_speed_hz/16)/1000);
 		return -EINVAL;
 	}
@@ -430,7 +425,7 @@ static int __init ads7846_probe(struct d
 	if (!(ts = kzalloc(sizeof(struct ads7846), GFP_KERNEL)))
 		return -ENOMEM;
 
-	dev_set_drvdata(dev, ts);
+	dev_set_drvdata(&spi->dev, ts);
 
 	ts->spi = spi;
 	spi->dev.power.power_state = PMSG_ON;
@@ -445,9 +440,9 @@ static int __init ads7846_probe(struct d
 
 	init_input_dev(&ts->input);
 
-	ts->input.dev = dev;
+	ts->input.dev = &spi->dev;
 	ts->input.name = "ADS784x Touchscreen";
-	snprintf(ts->phys, sizeof ts->phys, "%s/input0", dev->bus_id);
+	snprintf(ts->phys, sizeof ts->phys, "%s/input0", spi->dev.bus_id);
 	ts->input.phys = ts->phys;
 
 	ts->input.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
@@ -511,65 +506,68 @@ static int __init ads7846_probe(struct d
 	ts->msg.context = ts;
 
 	if (request_irq(spi->irq, ads7846_irq, SA_SAMPLE_RANDOM,
-				dev->bus_id, ts)) {
-		dev_dbg(dev, "irq %d busy?\n", spi->irq);
+				spi->dev.bus_id, ts)) {
+		dev_dbg(&spi->dev, "irq %d busy?\n", spi->irq);
 		input_unregister_device(&ts->input);
 		kfree(ts);
 		return -EBUSY;
 	}
 	set_irq_type(spi->irq, IRQT_FALLING);
 
-	dev_info(dev, "touchscreen, irq %d\n", spi->irq);
+	dev_info(&spi->dev, "touchscreen, irq %d\n", spi->irq);
 
 	/* take a first sample, leaving nPENIRQ active; avoid
 	 * the touchscreen, in case it's not connected.
 	 */
-	(void) ads7846_read12_ser(dev,
+	(void) ads7846_read12_ser(&spi->dev,
 			  READ_12BIT_SER(vaux) | ADS_PD10_ALL_ON);
 
 	/* ads7843/7845 don't have temperature sensors, and
 	 * use the other sensors a bit differently too
 	 */
 	if (ts->model == 7846) {
-		device_create_file(dev, &dev_attr_temp0);
-		device_create_file(dev, &dev_attr_temp1);
+		device_create_file(&spi->dev, &dev_attr_temp0);
+		device_create_file(&spi->dev, &dev_attr_temp1);
 	}
 	if (ts->model != 7845)
-		device_create_file(dev, &dev_attr_vbatt);
-	device_create_file(dev, &dev_attr_vaux);
+		device_create_file(&spi->dev, &dev_attr_vbatt);
+	device_create_file(&spi->dev, &dev_attr_vaux);
 
 	return 0;
 }
 
-static int __exit ads7846_remove(struct device *dev)
+static int __devexit ads7846_remove(struct spi_device *spi)
 {
-	struct ads7846		*ts = dev_get_drvdata(dev);
+	struct ads7846		*ts = dev_get_drvdata(&spi->dev);
 
-	ads7846_suspend(dev, PMSG_SUSPEND EXTRA2);
+	ads7846_suspend(spi, PMSG_SUSPEND);
 	free_irq(ts->spi->irq, ts);
 	if (ts->irq_disabled)
 		enable_irq(ts->spi->irq);
 
 	if (ts->model == 7846) {
-		device_remove_file(dev, &dev_attr_temp0);
-		device_remove_file(dev, &dev_attr_temp1);
+		device_remove_file(&spi->dev, &dev_attr_temp0);
+		device_remove_file(&spi->dev, &dev_attr_temp1);
 	}
 	if (ts->model != 7845)
-		device_remove_file(dev, &dev_attr_vbatt);
-	device_remove_file(dev, &dev_attr_vaux);
+		device_remove_file(&spi->dev, &dev_attr_vbatt);
+	device_remove_file(&spi->dev, &dev_attr_vaux);
 
 	input_unregister_device(&ts->input);
 	kfree(ts);
 
-	dev_dbg(dev, "unregistered touchscreen\n");
+	dev_dbg(&spi->dev, "unregistered touchscreen\n");
 	return 0;
 }
 
-static struct device_driver ads7846_driver = {
-	.name		= "ads7846",
-	.bus		= &spi_bus_type,
+static struct spi_driver ads7846_driver = {
+	.driver = {
+		.name	= "ads7846",
+		.bus	= &spi_bus_type,
+		.owner	= THIS_MODULE,
+	},
 	.probe		= ads7846_probe,
-	.remove		= __exit_p(ads7846_remove),
+	.remove		= __devexit_p(ads7846_remove),
 	.suspend	= ads7846_suspend,
 	.resume		= ads7846_resume,
 };
@@ -594,18 +592,20 @@ static int __init ads7846_init(void)
 	// PXA:
 	// also Dell Axim X50
 	// also HP iPaq H191x/H192x/H415x/H435x
-	// also Intel Lubbock (alternate to UCB1400)
+	// also Intel Lubbock (additional to UCB1400; as temperature sensor)
 	// also Sharp Zaurus C7xx, C8xx (corgi/sheperd/husky)
 
+	// Atmel at91sam9261-EK uses ads7843
+
 	// also various AMD Au1x00 devel boards
 
-	return driver_register(&ads7846_driver);
+	return spi_register_driver(&ads7846_driver);
 }
 module_init(ads7846_init);
 
 static void __exit ads7846_exit(void)
 {
-	driver_unregister(&ads7846_driver);
+	spi_unregister_driver(&ads7846_driver);
 
 #ifdef	CONFIG_ARCH_OMAP
 	if (machine_is_omap_osk()) {
include/linux/spi/ads7846.h +1 -1
index 84a2701..72261e0 100644
@@ -1,7 +1,7 @@
 /* linux/spi/ads7846.h */
 
 /* Touchscreen characteristics vary between boards and models.  The
- * platform_data for the device's "struct device" holts this information.
+ * platform_data for the device's "struct device" holds this information.
  *
  * It's OK if the min/max values are zero.
  */
author
#16 lore raw

PATCH 1/1 spi: remove fastcall crap

In reply to Greg KH

[PATCH] spi: remove fastcall crap

gcc4 generates warnings when a non-FASTCALL function pointer is assigned to a FASTCALL one. Perhaps it has taste.

---
commit 5d870c8e216f121307445c71caa72e7e10a20061
tree d1d73cf5e520a10086f9a50a00fecb6041def89d
parent 7111763d391b0c5a949a4f2575aa88cd585f0ff6
author Andrew Morton <[email protected]> Wed, 11 Jan 2006 11:23:49 -0800 committer Greg Kroah-Hartman <[email protected]> Fri, 13 Jan 2006 16:29:56 -0800

 drivers/spi/spi.c       |    7 ++++++-
 include/linux/spi/spi.h |    2 +-
 2 files changed, 7 insertions(+), 2 deletions(-)
drivers/spi/spi.c +6 -1
index cdb242d..791c4dc 100644
@@ -480,6 +480,11 @@ EXPORT_SYMBOL_GPL(spi_busnum_to_master);
 
 /*-------------------------------------------------------------------------*/
 
+static void spi_complete(void *arg)
+{
+	complete(arg);
+}
+
 /**
  * spi_sync - blocking/synchronous SPI data transfers
  * @spi: device with which data will be exchanged
@@ -508,7 +513,7 @@ int spi_sync(struct spi_device *spi, str
 	DECLARE_COMPLETION(done);
 	int status;
 
-	message->complete = (void (*)(void *)) complete;
+	message->complete = spi_complete;
 	message->context = &done;
 	status = spi_async(spi, message);
 	if (status == 0)
include/linux/spi/spi.h +1 -1
index 939afd3..b05f146 100644
@@ -374,7 +374,7 @@ struct spi_message {
 	 */
 
 	/* completion is reported through a callback */
-	void 			FASTCALL((*complete)(void *context));
+	void 			(*complete)(void *context);
 	void			*context;
 	unsigned		actual_length;
 	int			status;
author
#13 lore raw

PATCH 1/1 spi: M25 series SPI flash

In reply to Greg KH

[PATCH] spi: M25 series SPI flash

This was originally a driver for the ST M25P80 SPI flash. It's been updated slightly to handle other M25P series chips.

For many of these chips, the specific type could be probed, but for now this just requires static setup with flash_platform_data that lists the chip type (size, format) and any default partitioning to use.

---
commit 2f9f762879015d738a5ec2ac8a16be94b3a4a06d
tree 73efe8bcdb970ee9c815c08358fb707b46aab983
parent 9904f22a7202c6b54e96b0cc9870817013c350a1
author Mike Lavender <[email protected]> Sun, 08 Jan 2006 13:34:27 -0800 committer Greg Kroah-Hartman <[email protected]> Fri, 13 Jan 2006 16:29:55 -0800

 drivers/mtd/devices/Kconfig  |    8 +
 drivers/mtd/devices/Makefile |    1 
 drivers/mtd/devices/m25p80.c |  580 ++++++++++++++++++++++++++++++++++++++++++
 include/linux/spi/flash.h    |    4 
 4 files changed, 593 insertions(+), 0 deletions(-)
drivers/mtd/devices/Kconfig +8 -0
index 84f2eb1..5038e90 100644
@@ -55,6 +55,14 @@ config MTD_DATAFLASH
 	  Sometimes DataFlash chips are packaged inside MMC-format
 	  cards; at this writing, the MMC stack won't handle those.
 
+config MTD_M25P80
+	tristate "Support for M25 SPI Flash"
+	depends on MTD && SPI_MASTER && EXPERIMENTAL
+	help
+	  This enables access to ST M25P80 and similar SPI flash chips,
+	  used for program and data storage.  Set up your spi devices
+	  with the right board-specific platform data.
+
 config MTD_SLRAM
 	tristate "Uncached system RAM"
 	depends on MTD
drivers/mtd/devices/Makefile +1 -0
index cd8d807..7c5ed21 100644
@@ -24,3 +24,4 @@ obj-$(CONFIG_MTD_LART)		+= lart.o
 obj-$(CONFIG_MTD_BLKMTD)	+= blkmtd.o
 obj-$(CONFIG_MTD_BLOCK2MTD)	+= block2mtd.o
 obj-$(CONFIG_MTD_DATAFLASH)	+= mtd_dataflash.o
+obj-$(CONFIG_MTD_M25P80)	+= m25p80.o
drivers/mtd/devices/m25p80.c new file +580 -0

580 lines not on this page · raw message

include/linux/spi/flash.h +4 -0
index 2ce6558..3f22932 100644
@@ -8,6 +8,8 @@ struct mtd_partition;
  * @name: optional flash device name (eg, as used with mtdparts=)
  * @parts: optional array of mtd_partitions for static partitioning
  * @nr_parts: number of mtd_partitions for static partitoning
+ * @type: optional flash device type (e.g. m25p80 vs m25p64), for use
+ *	with chips that can't be queried for JEDEC or other IDs
  *
  * Board init code (in arch/.../mach-xxx/board-yyy.c files) can
  * provide information about SPI flash parts (such as DataFlash) to
@@ -21,6 +23,8 @@ struct flash_platform_data {
 	struct mtd_partition *parts;
 	unsigned int	nr_parts;
 
+	char		*type;
+
 	/* we'll likely add more ... use JEDEC IDs, etc */
 };
 
author
#15 lore raw

PATCH 1/1 SPI: add spi_butterfly driver

In reply to Greg KH

[PATCH] SPI: add spi_butterfly driver

This adds a bitbanging parport based adaptor cable for AVR Butterfly, giving SPI links to its DataFlash chip and (eventually) firmware running in the card.

---
commit 2e10c84b9cf0b2d269c5629048d8d6e35eaf6b2b
tree 2b338e8282d4e740529aeb3d5f303c4883f8d667
parent 5d870c8e216f121307445c71caa72e7e10a20061
author David Brownell <[email protected]> Wed, 11 Jan 2006 11:23:49 -0800 committer Greg Kroah-Hartman <[email protected]> Fri, 13 Jan 2006 16:29:56 -0800

 Documentation/spi/butterfly |   57 ++++++
 drivers/spi/Kconfig         |   10 +
 drivers/spi/spi_butterfly.c |  423 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 490 insertions(+), 0 deletions(-)
Documentation/spi/butterfly new file +57 -0
new file mode 100644
index 0000000..a2e8c8d
@@ -0,0 +1,57 @@
+spi_butterfly - parport-to-butterfly adapter driver
+===================================================
+
+This is a hardware and software project that includes building and using
+a parallel port adapter cable, together with an "AVR Butterfly" to run
+firmware for user interfacing and/or sensors.  A Butterfly is a $US20
+battery powered card with an AVR microcontroller and lots of goodies:
+sensors, LCD, flash, toggle stick, and more.  You can use AVR-GCC to
+develop firmware for this, and flash it using this adapter cable.
+
+You can make this adapter from an old printer cable and solder things
+directly to the Butterfly.  Or (if you have the parts and skills) you
+can come up with something fancier, providing ciruit protection to the
+Butterfly and the printer port, or with a better power supply than two
+signal pins from the printer port.
+
+
+The first cable connections will hook Linux up to one SPI bus, with the
+AVR and a DataFlash chip; and to the AVR reset line.  This is all you
+need to reflash the firmware, and the pins are the standard Atmel "ISP"
+connector pins (used also on non-Butterfly AVR boards).
+
+	Signal	  Butterfly	  Parport (DB-25)
+	------	  ---------	  ---------------
+	SCK	= J403.PB1/SCK	= pin 2/D0
+	RESET	= J403.nRST	= pin 3/D1
+	VCC	= J403.VCC_EXT	= pin 8/D6
+	MOSI	= J403.PB2/MOSI	= pin 9/D7
+	MISO	= J403.PB3/MISO	= pin 11/S7,nBUSY
+	GND	= J403.GND	= pin 23/GND
+
+Then to let Linux master that bus to talk to the DataFlash chip, you must
+(a) flash new firmware that disables SPI (set PRR.2, and disable pullups
+by clearing PORTB.[0-3]); (b) configure the mtd_dataflash driver; and
+(c) cable in the chipselect.
+
+	Signal	  Butterfly	  Parport (DB-25)
+	------	  ---------	  ---------------
+	VCC	= J400.VCC_EXT	= pin 7/D5
+	SELECT	= J400.PB0/nSS	= pin 17/C3,nSELECT
+	GND	= J400.GND	= pin 24/GND
+
+The "USI" controller, using J405, can be used for a second SPI bus.  That
+would let you talk to the AVR over SPI, running firmware that makes it act
+as an SPI slave, while letting either Linux or the AVR use the DataFlash.
+There are plenty of spare parport pins to wire this one up, such as:
+
+	Signal	  Butterfly	  Parport (DB-25)
+	------	  ---------	  ---------------
+	SCK	= J403.PE4/USCK	= pin 5/D3
+	MOSI	= J403.PE5/DI	= pin 6/D4
+	MISO	= J403.PE6/DO	= pin 12/S5,nPAPEROUT
+	GND	= J403.GND	= pin 22/GND
+
+	IRQ	= J402.PF4	= pin 10/S6,ACK
+	GND	= J402.GND(P2)	= pin 25/GND
+
drivers/spi/Kconfig +10 -0
index 7a75fae..b77dbd6 100644
@@ -75,6 +75,16 @@ config SPI_BUTTERFLY
 	  inexpensive battery powered microcontroller evaluation board.
 	  This same cable can be used to flash new firmware.
 
+config SPI_BUTTERFLY
+	tristate "Parallel port adapter for AVR Butterfly (DEVELOPMENT)"
+	depends on SPI_MASTER && PARPORT && EXPERIMENTAL
+	select SPI_BITBANG
+	help
+	  This uses a custom parallel port cable to connect to an AVR
+	  Butterfly <http://www.atmel.com/products/avr/butterfly>, an
+	  inexpensive battery powered microcontroller evaluation board.
+	  This same cable can be used to flash new firmware.
+
 #
 # Add new SPI master controllers in alphabetical order above this line
 #
drivers/spi/spi_butterfly.c new file +423 -0

423 lines not on this page · raw message

author
#17 lore raw

PATCH 1/1 spi: misc fixes

In reply to Greg KH

[PATCH] spi: misc fixes

This collects some small SPI patches that seem to be missing from the MM tree:

- spi_butterfly kbuild hooks got dropped somehow; this restores them
- quick fix for a (theoretical?) m25p80_write() oops noted by Andrew
- quick fix for a potential config-specific oops for mtd_dataflash()
- minor doc tweaks

---
commit 7111763d391b0c5a949a4f2575aa88cd585f0ff6
tree 376eef5003b71c6445c02bbe87950b2e365e0758
parent 8275c642ccdce09a2146d0a9eb022e3698ee927e
author David Brownell <[email protected]> Sun, 08 Jan 2006 13:34:29 -0800 committer Greg Kroah-Hartman <[email protected]> Fri, 13 Jan 2006 16:29:56 -0800

 Documentation/spi/spi-summary       |   13 +++++++++++++
 drivers/mtd/devices/m25p80.c        |    4 +++-
 drivers/mtd/devices/mtd_dataflash.c |    2 +-
 drivers/spi/Kconfig                 |   10 ++++++++++
 drivers/spi/Makefile                |    1 +
 5 files changed, 28 insertions(+), 2 deletions(-)
Documentation/spi/spi-summary +13 -0
index 761debf..a5ffba3 100644
@@ -115,6 +115,9 @@ shows up in sysfs in several locations:
    /sys/devices/.../CTLR/spiB.C ... spi_device for on bus "B",
 	chipselect C, accessed through CTLR.
 
+   /sys/devices/.../CTLR/spiB.C/modalias ... identifies the driver
+	that should be used with this device (for hotplug/coldplug)
+
    /sys/bus/spi/devices/spiB.C ... symlink to the physical
    	spiB-C device
 
@@ -247,6 +250,12 @@ driver is registered:
 
 Like with other static board-specific setup, you won't unregister those.
 
+The widely used "card" style computers bundle memory, cpu, and little else
+onto a card that's maybe just thirty square centimeters.  On such systems,
+your arch/.../mach-.../board-*.c file would primarily provide information
+about the devices on the mainboard into which such a card is plugged.  That
+certainly includes SPI devices hooked up through the card connectors!
+
 
 NON-STATIC CONFIGURATIONS
 
@@ -258,6 +267,10 @@ up the spi bus master, and will likely n
 board info based on the board that was hotplugged.  Of course, you'd later
 call at least spi_unregister_device() when that board is removed.
 
+When Linux includes support for MMC/SD/SDIO/DataFlash cards through SPI, those
+configurations will also be dynamic.  Fortunately, those devices all support
+basic device identification probes, so that support should hotplug normally.
+
 
 How do I write an "SPI Protocol Driver"?
 ----------------------------------------
drivers/mtd/devices/m25p80.c +3 -1
index 45108ed..d5f2408 100644
@@ -378,7 +378,9 @@ static int m25p80_write(struct mtd_info 
 
 			spi_sync(flash->spi, &m);
 
-			*retlen += m.actual_length - sizeof(flash->command);
+			if (retlen)
+				*retlen += m.actual_length
+					- sizeof(flash->command);
 	        }
  	}
 
drivers/mtd/devices/mtd_dataflash.c +1 -1
index 99d3a03..155737e 100644
@@ -508,7 +508,7 @@ add_dataflash(struct spi_device *spi, ch
 			priv->partitioned = 1;
 			return add_mtd_partitions(device, parts, nr_parts);
 		}
-	} else if (pdata->nr_parts)
+	} else if (pdata && pdata->nr_parts)
 		dev_warn(&spi->dev, "ignoring %d default partitions on %s\n",
 				pdata->nr_parts, device->name);
 
drivers/spi/Kconfig +10 -0
index 9b21c5d..7a75fae 100644
@@ -65,6 +65,16 @@ config SPI_BITBANG
 	  need it.  You only need to select this explicitly to support driver
 	  modules that aren't part of this kernel tree.
 
+config SPI_BUTTERFLY
+	tristate "Parallel port adapter for AVR Butterfly (DEVELOPMENT)"
+	depends on SPI_MASTER && PARPORT && EXPERIMENTAL
+	select SPI_BITBANG
+	help
+	  This uses a custom parallel port cable to connect to an AVR
+	  Butterfly <http://www.atmel.com/products/avr/butterfly>, an
+	  inexpensive battery powered microcontroller evaluation board.
+	  This same cable can be used to flash new firmware.
+
 #
 # Add new SPI master controllers in alphabetical order above this line
 #
drivers/spi/Makefile +1 -0
index 5da6a4d..c2c87e8 100644
@@ -12,6 +12,7 @@ obj-$(CONFIG_SPI_MASTER)		+= spi.o
 
 # SPI master controller drivers (bus)
 obj-$(CONFIG_SPI_BITBANG)		+= spi_bitbang.o
+obj-$(CONFIG_SPI_BUTTERFLY)		+= spi_butterfly.o
 # 	... add above this line ...
 
 # SPI protocol drivers (device/link on bus)
author
#11 lore raw

PATCH 1/1 SPI core tweaks, bugfix

In reply to Greg KH

[PATCH] SPI core tweaks, bugfix

This includes various updates to the SPI core:

- Fixes a driver model refcount bug in spi_unregister_master() paths.

- The spi_master structures now have wrappers which help keep drivers from needing class-level get/put for device data or for refcounts.

- Check for a few setup errors that would cause oopsing later.

- Docs say more about memory management. Highlights the use of DMA-safe i/o buffers, and zero-initializing spi_message and such metadata.

- Provide a simple alloc/free for spi_message and its spi_transfer; this is only one of the possible memory management policies.

Nothing to break code that already works.

---
commit 0c868461fcb8413cb9f691d68e5b99b0fd3c0737
tree b43db6239f5d72a279b35b14de85cf34d8f6bc74
parent b885244eb2628e0b8206e7edaaa6a314da78e9a4
author David Brownell <[email protected]> Sun, 08 Jan 2006 13:34:25 -0800 committer Greg Kroah-Hartman <[email protected]> Fri, 13 Jan 2006 16:29:55 -0800

 Documentation/spi/spi-summary |   16 +++++++++
 drivers/spi/spi.c             |   45 +++++++++++++++----------
 include/linux/spi/spi.h       |   75 ++++++++++++++++++++++++++++++++++++++---
 3 files changed, 113 insertions(+), 23 deletions(-)
Documentation/spi/spi-summary +16 -0
index c6152d1..761debf 100644
@@ -363,6 +363,22 @@ upper boundaries might include sysfs (es
 the input layer, ALSA, networking, MTD, the character device framework,
 or other Linux subsystems.
 
+Note that there are two types of memory your driver must manage as part
+of interacting with SPI devices.
+
+  - I/O buffers use the usual Linux rules, and must be DMA-safe.
+    You'd normally allocate them from the heap or free page pool.
+    Don't use the stack, or anything that's declared "static".
+
+  - The spi_message and spi_transfer metadata used to glue those
+    I/O buffers into a group of protocol transactions.  These can
+    be allocated anywhere it's convenient, including as part of
+    other allocate-once driver data structures.  Zero-init these.
+
+If you like, spi_message_alloc() and spi_message_free() convenience
+routines are available to allocate and zero-initialize an spi_message
+with several transfers.
+
 
 How do I write an "SPI Master Controller Driver"?
 -------------------------------------------------
drivers/spi/spi.c +28 -17

142 lines not on this page · raw message

include/linux/spi/spi.h +69 -6

127 lines not on this page · raw message

author
#18 lore raw

PATCH 1/1 spi: use linked lists rather than an array

In reply to Greg KH

[PATCH] spi: use linked lists rather than an array

This makes the SPI core and its users access transfers in the SPI message structure as linked list not as an array, as discussed on LKML.

From: David Brownell <[email protected]>

Updates including doc, bugfixes to the list code, add spi_message_add_tail(). Plus, initialize things _before_ grabbing the locks in some cases (in case it grows more expensive). This also merges some bitbang updates of mine that didn't yet make it into the mm tree.

---
commit 8275c642ccdce09a2146d0a9eb022e3698ee927e
tree ea330810f665fcbdf36d31b0da1643db528ad83f
parent 2f9f762879015d738a5ec2ac8a16be94b3a4a06d
author Vitaly Wool <[email protected]> Sun, 08 Jan 2006 13:34:28 -0800 committer Greg Kroah-Hartman <[email protected]> Fri, 13 Jan 2006 16:29:56 -0800

 drivers/input/touchscreen/ads7846.c |   12 +++--
 drivers/mtd/devices/m25p80.c        |   50 ++++++++++---------
 drivers/mtd/devices/mtd_dataflash.c |   28 ++++++-----
 drivers/spi/spi.c                   |   18 ++++---
 drivers/spi/spi_bitbang.c           |   86 +++++++++++++++++++--------------
 include/linux/spi/spi.h             |   92 ++++++++++++++++++++++++-----------
 include/linux/spi/spi_bitbang.h     |    7 +++
 7 files changed, 180 insertions(+), 113 deletions(-)
drivers/input/touchscreen/ads7846.c +8 -4
index c741776..dd8c6a9 100644
@@ -155,10 +155,13 @@ static int ads7846_read12_ser(struct dev
 	struct ser_req		*req = kzalloc(sizeof *req, SLAB_KERNEL);
 	int			status;
 	int			sample;
+	int 			i;
 
 	if (!req)
 		return -ENOMEM;
 
+	INIT_LIST_HEAD(&req->msg.transfers);
+
 	/* activate reference, so it has time to settle; */
 	req->xfer[0].tx_buf = &ref_on;
 	req->xfer[0].len = 1;
@@ -192,8 +195,8 @@ static int ads7846_read12_ser(struct dev
 	/* group all the transfers together, so we can't interfere with
 	 * reading touchscreen state; disable penirq while sampling
 	 */
-	req->msg.transfers = req->xfer;
-	req->msg.n_transfer = 6;
+	for (i = 0; i < 6; i++)
+		spi_message_add_tail(&req->xfer[i], &req->msg);
 
 	disable_irq(spi->irq);
 	status = spi_sync(spi, &req->msg);
@@ -398,6 +401,7 @@ static int __devinit ads7846_probe(struc
 	struct ads7846			*ts;
 	struct ads7846_platform_data	*pdata = spi->dev.platform_data;
 	struct spi_transfer		*x;
+	int				i;
 
 	if (!spi->irq) {
 		dev_dbg(&spi->dev, "no IRQ?\n");
@@ -500,8 +504,8 @@ static int __devinit ads7846_probe(struc
 
 	CS_CHANGE(x[-1]);
 
-	ts->msg.transfers = ts->xfer;
-	ts->msg.n_transfer = x - ts->xfer;
+	for (i = 0; i < x - ts->xfer; i++)
+		spi_message_add_tail(&ts->xfer[i], &ts->msg);
 	ts->msg.complete = ads7846_rx;
 	ts->msg.context = ts;
 
drivers/mtd/devices/m25p80.c +25 -25

97 lines not on this page · raw message

drivers/mtd/devices/mtd_dataflash.c +17 -11
index a39b3b6..99d3a03 100644
@@ -147,7 +147,7 @@ static int dataflash_erase(struct mtd_in
 {
 	struct dataflash	*priv = (struct dataflash *)mtd->priv;
 	struct spi_device	*spi = priv->spi;
-	struct spi_transfer	x[1] = { { .tx_dma = 0, }, };
+	struct spi_transfer	x = { .tx_dma = 0, };
 	struct spi_message	msg;
 	unsigned		blocksize = priv->page_size << 3;
 	u8			*command;
@@ -162,10 +162,11 @@ static int dataflash_erase(struct mtd_in
 			|| (instr->addr % priv->page_size) != 0)
 		return -EINVAL;
 
-	x[0].tx_buf = command = priv->command;
-	x[0].len = 4;
-	msg.transfers = x;
-	msg.n_transfer = 1;
+	spi_message_init(&msg);
+
+	x.tx_buf = command = priv->command;
+	x.len = 4;
+	spi_message_add_tail(&x, &msg);
 
 	down(&priv->lock);
 	while (instr->len > 0) {
@@ -256,12 +257,15 @@ static int dataflash_read(struct mtd_inf
 	DEBUG(MTD_DEBUG_LEVEL3, "READ: (%x) %x %x %x\n",
 		command[0], command[1], command[2], command[3]);
 
+	spi_message_init(&msg);
+
 	x[0].tx_buf = command;
 	x[0].len = 8;
+	spi_message_add_tail(&x[0], &msg);
+
 	x[1].rx_buf = buf;
 	x[1].len = len;
-	msg.transfers = x;
-	msg.n_transfer = 2;
+	spi_message_add_tail(&x[1], &msg);
 
 	down(&priv->lock);
 
@@ -320,9 +324,11 @@ static int dataflash_write(struct mtd_in
 	if ((to + len) > mtd->size)
 		return -EINVAL;
 
+	spi_message_init(&msg);
+
 	x[0].tx_buf = command = priv->command;
 	x[0].len = 4;
-	msg.transfers = x;
+	spi_message_add_tail(&x[0], &msg);
 
 	pageaddr = ((unsigned)to / priv->page_size);
 	offset = ((unsigned)to % priv->page_size);
@@ -364,7 +370,6 @@ static int dataflash_write(struct mtd_in
 			DEBUG(MTD_DEBUG_LEVEL3, "TRANSFER: (%x) %x %x %x\n",
 				command[0], command[1], command[2], command[3]);
 
-			msg.n_transfer = 1;
 			status = spi_sync(spi, &msg);
 			if (status < 0)
 				DEBUG(MTD_DEBUG_LEVEL1, "%s: xfer %u -> %d \n",
@@ -385,14 +390,16 @@ static int dataflash_write(struct mtd_in
 
 		x[1].tx_buf = writebuf;
 		x[1].len = writelen;
-		msg.n_transfer = 2;
+		spi_message_add_tail(x + 1, &msg);
 		status = spi_sync(spi, &msg);
+		spi_transfer_del(x + 1);
 		if (status < 0)
 			DEBUG(MTD_DEBUG_LEVEL1, "%s: pgm %u/%u -> %d \n",
 				spi->dev.bus_id, addr, writelen, status);
 
 		(void) dataflash_waitready(priv->spi);
 
+
 #ifdef	CONFIG_DATAFLASH_WRITE_VERIFY
 
 		/* (3) Compare to Buffer1 */
@@ -405,7 +412,6 @@ static int dataflash_write(struct mtd_in
 		DEBUG(MTD_DEBUG_LEVEL3, "COMPARE: (%x) %x %x %x\n",
 			command[0], command[1], command[2], command[3]);
 
-		msg.n_transfer = 1;
 		status = spi_sync(spi, &msg);
 		if (status < 0)
 			DEBUG(MTD_DEBUG_LEVEL1, "%s: compare %u -> %d \n",
drivers/spi/spi.c +11 -7
index 3ecedcc..cdb242d 100644
@@ -557,6 +557,17 @@ int spi_write_then_read(struct spi_devic
 	if ((n_tx + n_rx) > SPI_BUFSIZ)
 		return -EINVAL;
 
+	spi_message_init(&message);
+	memset(x, 0, sizeof x);
+	if (n_tx) {
+		x[0].len = n_tx;
+		spi_message_add_tail(&x[0], &message);
+	}
+	if (n_rx) {
+		x[1].len = n_rx;
+		spi_message_add_tail(&x[1], &message);
+	}
+
 	/* ... unless someone else is using the pre-allocated buffer */
 	if (down_trylock(&lock)) {
 		local_buf = kmalloc(SPI_BUFSIZ, GFP_KERNEL);
@@ -565,18 +576,11 @@ int spi_write_then_read(struct spi_devic
 	} else
 		local_buf = buf;
 
-	memset(x, 0, sizeof x);
-
 	memcpy(local_buf, txbuf, n_tx);
 	x[0].tx_buf = local_buf;
-	x[0].len = n_tx;
-
 	x[1].rx_buf = local_buf + n_tx;
-	x[1].len = n_rx;
 
 	/* do the i/o */
-	message.transfers = x;
-	message.n_transfer = ARRAY_SIZE(x);
 	status = spi_sync(spi, &message);
 	if (status == 0) {
 		memcpy(rxbuf, x[1].rx_buf, n_rx);
drivers/spi/spi_bitbang.c +49 -37

150 lines not on this page · raw message

include/linux/spi/spi.h +63 -29

173 lines not on this page · raw message

include/linux/spi/spi_bitbang.h +7 -0
index 8dfe61a..c961fe9 100644
@@ -31,8 +31,15 @@ struct spi_bitbang {
 	struct spi_master	*master;
 
 	void	(*chipselect)(struct spi_device *spi, int is_on);
+#define	BITBANG_CS_ACTIVE	1	/* normally nCS, active low */
+#define	BITBANG_CS_INACTIVE	0
 
+	/* txrx_bufs() may handle dma mapping for transfers that don't
+	 * already have one (transfer.{tx,rx}_dma is zero), or use PIO
+	 */
 	int	(*txrx_bufs)(struct spi_device *spi, struct spi_transfer *t);
+
+	/* txrx_word[SPI_MODE_*]() just looks like a shift register */
 	u32	(*txrx_word[4])(struct spi_device *spi,
 			unsigned nsecs,
 			u32 word, u8 bits);
author
#7 lore raw

PATCH 1/1 spi: mtd dataflash driver

In reply to Greg KH

[PATCH] spi: mtd dataflash driver

This is a conversion of the AT91rm9200 DataFlash MTD driver to use the lightweight SPI framework, and no longer be AT91-specific. It compiles down to less than 3KBytes on ARM.

The driver allows board-specific init code to provide platform_data with the relevant MTD partitioning information, and hotplugs.

This version has been lightly tested. Its parent at91_dataflash driver has been pretty well banged on, although kernel.org JFFS2 dataflash support was acting broken the last time I tried it.

---
commit 1d6432fe10c3e724e307dd7137cd293a0edcae80
tree e32ba2eaecff99b2b86455ed2df8365b082cd396
parent ffa458c1bd9b6f653008d450f337602f3d52a646
author David Brownell <[email protected]> Sun, 08 Jan 2006 13:34:22 -0800 committer Greg Kroah-Hartman <[email protected]> Fri, 13 Jan 2006 16:29:54 -0800

 drivers/mtd/devices/Kconfig         |    8 
 drivers/mtd/devices/Makefile        |    1 
 drivers/mtd/devices/mtd_dataflash.c |  623 +++++++++++++++++++++++++++++++++++
 include/linux/spi/flash.h           |   27 ++
 4 files changed, 659 insertions(+), 0 deletions(-)
drivers/mtd/devices/Kconfig +8 -0
index 9a2aa40..84f2eb1 100644
@@ -47,6 +47,14 @@ config MTD_MS02NV
 	  accelerator.  Say Y here if you have a DECstation 5000/2x0 or a
 	  DECsystem 5900 equipped with such a module.
 
+config MTD_DATAFLASH
+	tristate "Support for AT45xxx DataFlash"
+	depends on MTD && SPI_MASTER && EXPERIMENTAL
+	help
+	  This enables access to AT45xxx DataFlash chips, using SPI.
+	  Sometimes DataFlash chips are packaged inside MMC-format
+	  cards; at this writing, the MMC stack won't handle those.
+
 config MTD_SLRAM
 	tristate "Uncached system RAM"
 	depends on MTD
drivers/mtd/devices/Makefile +1 -0
index e38db34..cd8d807 100644
@@ -23,3 +23,4 @@ obj-$(CONFIG_MTD_MTDRAM)	+= mtdram.o
 obj-$(CONFIG_MTD_LART)		+= lart.o
 obj-$(CONFIG_MTD_BLKMTD)	+= blkmtd.o
 obj-$(CONFIG_MTD_BLOCK2MTD)	+= block2mtd.o
+obj-$(CONFIG_MTD_DATAFLASH)	+= mtd_dataflash.o
drivers/mtd/devices/mtd_dataflash.c new file +623 -0

623 lines not on this page · raw message

include/linux/spi/flash.h new file +27 -0
new file mode 100644
index 0000000..2ce6558
@@ -0,0 +1,27 @@
+#ifndef LINUX_SPI_FLASH_H
+#define LINUX_SPI_FLASH_H
+
+struct mtd_partition;
+
+/**
+ * struct flash_platform_data: board-specific flash data
+ * @name: optional flash device name (eg, as used with mtdparts=)
+ * @parts: optional array of mtd_partitions for static partitioning
+ * @nr_parts: number of mtd_partitions for static partitoning
+ *
+ * Board init code (in arch/.../mach-xxx/board-yyy.c files) can
+ * provide information about SPI flash parts (such as DataFlash) to
+ * help set up the device and its appropriate default partitioning.
+ *
+ * Note that for DataFlash, sizes for pages, blocks, and sectors are
+ * rarely powers of two; and partitions should be sector-aligned.
+ */
+struct flash_platform_data {
+	char		*name;
+	struct mtd_partition *parts;
+	unsigned int	nr_parts;
+
+	/* we'll likely add more ... use JEDEC IDs, etc */
+};
+
+#endif
author
#9 lore raw

PATCH 1/1 spi: add spi_driver to SPI framework

In reply to Greg KH

[PATCH] spi: add spi_driver to SPI framework

This is a refresh of the "Simple SPI Framework" found in 2.6.15-rc3-mm1 which makes the following changes:

* There's now a "struct spi_driver". This increase the footprint of the core a bit, since it now includes code to do what the driver core was previously handling directly. Documentation and comments were updated to match.

* spi_alloc_master() now does class_device_initialize(), so it can at least be refcounted before spi_register_master(). To match, spi_register_master() switched over to class_device_add().

* States explicitly that after transfer errors, spi_devices will be deselected. We want fault recovery procedures to work the same for all controller drivers.

* Minor tweaks: controller_data no longer points to readonly data; prevent some potential cast-from-null bugs with container_of calls; clarifies some existing kerneldoc,

And a few small cleanups.

---
commit b885244eb2628e0b8206e7edaaa6a314da78e9a4
tree e548fb3a94603c4a5406920c97246a78fe16b64a
parent 1d6432fe10c3e724e307dd7137cd293a0edcae80
author David Brownell <[email protected]> Sun, 08 Jan 2006 13:34:23 -0800 committer Greg Kroah-Hartman <[email protected]> Fri, 13 Jan 2006 16:29:54 -0800

 Documentation/spi/spi-summary |   52 +++++++++++-------
 drivers/spi/spi.c             |  118 ++++++++++++++++++++++++++++++-----------
 include/linux/spi/spi.h       |   75 ++++++++++++++++++--------
 3 files changed, 170 insertions(+), 75 deletions(-)
Documentation/spi/spi-summary +32 -20
index 00497f9..c6152d1 100644
@@ -1,18 +1,19 @@
 Overview of Linux kernel SPI support
 ====================================
 
-22-Nov-2005
+02-Dec-2005
 
 What is SPI?
 ------------
-The "Serial Peripheral Interface" (SPI) is a four-wire point-to-point
-serial link used to connect microcontrollers to sensors and memory.
+The "Serial Peripheral Interface" (SPI) is a synchronous four wire serial
+link used to connect microcontrollers to sensors, memory, and peripherals.
 
 The three signal wires hold a clock (SCLK, often on the order of 10 MHz),
 and parallel data lines with "Master Out, Slave In" (MOSI) or "Master In,
 Slave Out" (MISO) signals.  (Other names are also used.)  There are four
 clocking modes through which data is exchanged; mode-0 and mode-3 are most
-commonly used.
+commonly used.  Each clock cycle shifts data out and data in; the clock
+doesn't cycle except when there is data to shift.
 
 SPI masters may use a "chip select" line to activate a given SPI slave
 device, so those three signal wires may be connected to several chips
@@ -79,11 +80,18 @@ The <linux/spi/spi.h> header file includ
 main source code, and you should certainly read that.  This is just
 an overview, so you get the big picture before the details.
 
+SPI requests always go into I/O queues.  Requests for a given SPI device
+are always executed in FIFO order, and complete asynchronously through
+completion callbacks.  There are also some simple synchronous wrappers
+for those calls, including ones for common transaction types like writing
+a command and then reading its response.
+
 There are two types of SPI driver, here called:
 
   Controller drivers ... these are often built in to System-On-Chip
 	processors, and often support both Master and Slave roles.
 	These drivers touch hardware registers and may use DMA.
+	Or they can be PIO bitbangers, needing just GPIO pins.
 
   Protocol drivers ... these pass messages through the controller
 	driver to communicate with a Slave or Master device on the
@@ -116,11 +124,6 @@ shows up in sysfs in several locations:
 	managing bus "B".  All the spiB.* devices share the same
 	physical SPI bus segment, with SCLK, MOSI, and MISO.
 
-The basic I/O primitive submits an asynchronous message to an I/O queue
-maintained by the controller driver.  A completion callback is issued
-asynchronously when the data transfer(s) in that message completes.
-There are also some simple synchronous wrappers for those calls.
-
 
 How does board-specific init code declare SPI devices?
 ------------------------------------------------------
@@ -263,33 +266,40 @@ would just be another kernel driver, pro
 access through aio_read(), aio_write(), and ioctl() calls and using the
 standard userspace sysfs mechanisms to bind to a given SPI device.
 
-SPI protocol drivers are normal device drivers, with no more wrapper
-than needed by platform devices:
+SPI protocol drivers somewhat resemble platform device drivers:
+
+	static struct spi_driver CHIP_driver = {
+		.driver = {
+			.name		= "CHIP",
+			.bus		= &spi_bus_type,
+			.owner		= THIS_MODULE,
+		},
 
-	static struct device_driver CHIP_driver = {
-		.name		= "CHIP",
-		.bus		= &spi_bus_type,
 		.probe		= CHIP_probe,
-		.remove		= __exit_p(CHIP_remove),
+		.remove		= __devexit_p(CHIP_remove),
 		.suspend	= CHIP_suspend,
 		.resume		= CHIP_resume,
 	};
 
-The SPI core will autmatically attempt to bind this driver to any SPI
+The driver core will autmatically attempt to bind this driver to any SPI
 device whose board_info gave a modalias of "CHIP".  Your probe() code
 might look like this unless you're creating a class_device:
 
-	static int __init CHIP_probe(struct device *dev)
+	static int __devinit CHIP_probe(struct spi_device *spi)
 	{
-		struct spi_device		*spi = to_spi_device(dev);
 		struct CHIP			*chip;
-		struct CHIP_platform_data	*pdata = dev->platform_data;
+		struct CHIP_platform_data	*pdata;
+
+		/* assuming the driver requires board-specific data: */
+		pdata = &spi->dev.platform_data;
+		if (!pdata)
+			return -ENODEV;
 
 		/* get memory for driver's per-chip state */
 		chip = kzalloc(sizeof *chip, GFP_KERNEL);
 		if (!chip)
 			return -ENOMEM;
-		dev_set_drvdata(dev, chip);
+		dev_set_drvdata(&spi->dev, chip);
 
 		... etc
 		return 0;
@@ -328,6 +338,8 @@ the driver guarantees that it won't subm
   - The basic I/O primitive is spi_async().  Async requests may be
     issued in any context (irq handler, task, etc) and completion
     is reported using a callback provided with the message.
+    After any detected error, the chip is deselected and processing
+    of that spi_message is aborted.
 
   - There are also synchronous wrappers like spi_sync(), and wrappers
     like spi_read(), spi_write(), and spi_write_then_read().  These
drivers/spi/spi.c +86 -32

211 lines not on this page · raw message

include/linux/spi/spi.h +52 -23

157 lines not on this page · raw message

author
#8 lore raw

PATCH 1/1 spi: simple SPI framework

In reply to Greg KH

[PATCH] spi: simple SPI framework

This is the core of a small SPI framework, implementing the model of a queue of messages which complete asynchronously (with thin synchronous wrappers on top).

- It's still less than 2KB of ".text" (ARM). If there's got to be a mid-layer for something so simple, that's the right size budget. :)

- The guts use board-specific SPI device tables to build the driver model tree. (Hardware probing is rarely an option.)

- This version of Kconfig includes no drivers. At this writing there are two known master controller drivers (PXA/SSP, OMAP MicroWire) and three protocol drivers (CS8415a, ADS7846, DataFlash) with LKML mentions of other drivers in development.

- No userspace API. There are several implementations to compare. Implement them like any other driver, and bind them with sysfs.

The changes from last version posted to LKML (on 11-Nov-2005) are minor, and include:

- One bugfix (removes a FIXME), with the visible effect of making device names be "spiB.C" where B is the bus number and C is the chipselect.

- The "caller provides DMA mappings" mechanism now has kerneldoc, for DMA drivers that want to be fancy.

- Hey, the framework init can be subsys_init. Even though board init logic fires earlier, at arch_init ... since the framework init is for driver support, and the board init support uses static init.

- Various additional spec/doc clarifications based on discussions with other folk. It adds a brief "thank you" at the end, for folk who've helped nudge this framework into existence.

As I've said before, I think that "protocol tweaking" is the main support that this driver framework will need to evolve.

From: Mark Underwood <[email protected]>

Update the SPI framework to remove a potential priority inversion case by reverting to kmalloc if the pre-allocated DMA-safe buffer isn't available.

---
commit 8ae12a0d85987dc138f8c944cb78a92bf466cea0
tree ca032f25bb26f88cc35d68c6f8065143ce64a6a8
parent 67daf5f11f06b9b15f8320de1d237ccc2e74fe43
author David Brownell <[email protected]> Sun, 08 Jan 2006 13:34:19 -0800 committer Greg Kroah-Hartman <[email protected]> Fri, 13 Jan 2006 16:29:54 -0800

 Documentation/spi/spi-summary |  416 ++++++++++++++++++++++++++++++
 arch/arm/Kconfig              |    2 
 drivers/Kconfig               |    2 
 drivers/Makefile              |    1 
 drivers/spi/Kconfig           |   76 +++++
 drivers/spi/Makefile          |   23 ++
 drivers/spi/spi.c             |  568 +++++++++++++++++++++++++++++++++++++++++
 include/linux/spi/spi.h       |  542 +++++++++++++++++++++++++++++++++++++++
 8 files changed, 1630 insertions(+), 0 deletions(-)
Documentation/spi/spi-summary new file +416 -0
new file mode 100644
index 0000000..00497f9
@@ -0,0 +1,416 @@
+Overview of Linux kernel SPI support
+====================================
+
+22-Nov-2005
+
+What is SPI?
+------------
+The "Serial Peripheral Interface" (SPI) is a four-wire point-to-point
+serial link used to connect microcontrollers to sensors and memory.
+
+The three signal wires hold a clock (SCLK, often on the order of 10 MHz),
+and parallel data lines with "Master Out, Slave In" (MOSI) or "Master In,
+Slave Out" (MISO) signals.  (Other names are also used.)  There are four
+clocking modes through which data is exchanged; mode-0 and mode-3 are most
+commonly used.
+
+SPI masters may use a "chip select" line to activate a given SPI slave
+device, so those three signal wires may be connected to several chips
+in parallel.  All SPI slaves support chipselects.  Some devices have
+other signals, often including an interrupt to the master.
+
+Unlike serial busses like USB or SMBUS, even low level protocols for
+SPI slave functions are usually not interoperable between vendors
+(except for cases like SPI memory chips).
+
+  - SPI may be used for request/response style device protocols, as with
+    touchscreen sensors and memory chips.
+
+  - It may also be used to stream data in either direction (half duplex),
+    or both of them at the same time (full duplex).
+
+  - Some devices may use eight bit words.  Others may different word
+    lengths, such as streams of 12-bit or 20-bit digital samples.
+
+In the same way, SPI slaves will only rarely support any kind of automatic
+discovery/enumeration protocol.  The tree of slave devices accessible from
+a given SPI master will normally be set up manually, with configuration
+tables.
+
+SPI is only one of the names used by such four-wire protocols, and
+most controllers have no problem handling "MicroWire" (think of it as
+half-duplex SPI, for request/response protocols), SSP ("Synchronous
+Serial Protocol"), PSP ("Programmable Serial Protocol"), and other
+related protocols.
+
+Microcontrollers often support both master and slave sides of the SPI
+protocol.  This document (and Linux) currently only supports the master
+side of SPI interactions.
+
+
+Who uses it?  On what kinds of systems?
+---------------------------------------
+Linux developers using SPI are probably writing device drivers for embedded
+systems boards.  SPI is used to control external chips, and it is also a
+protocol supported by every MMC or SD memory card.  (The older "DataFlash"
+cards, predating MMC cards but using the same connectors and card shape,
+support only SPI.)  Some PC hardware uses SPI flash for BIOS code.
+
+SPI slave chips range from digital/analog converters used for analog
+sensors and codecs, to memory, to peripherals like USB controllers
+or Ethernet adapters; and more.
+
+Most systems using SPI will integrate a few devices on a mainboard.
+Some provide SPI links on expansion connectors; in cases where no
+dedicated SPI controller exists, GPIO pins can be used to create a
+low speed "bitbanging" adapter.  Very few systems will "hotplug" an SPI
+controller; the reasons to use SPI focus on low cost and simple operation,
+and if dynamic reconfiguration is important, USB will often be a more
+appropriate low-pincount peripheral bus.
+
+Many microcontrollers that can run Linux integrate one or more I/O
+interfaces with SPI modes.  Given SPI support, they could use MMC or SD
+cards without needing a special purpose MMC/SD/SDIO controller.
+
+
+How do these driver programming interfaces work?
+------------------------------------------------
+The <linux/spi/spi.h> header file includes kerneldoc, as does the
+main source code, and you should certainly read that.  This is just
+an overview, so you get the big picture before the details.
+
+There are two types of SPI driver, here called:
+
+  Controller drivers ... these are often built in to System-On-Chip
+	processors, and often support both Master and Slave roles.
+	These drivers touch hardware registers and may use DMA.
+
+  Protocol drivers ... these pass messages through the controller
+	driver to communicate with a Slave or Master device on the
+	other side of an SPI link.
+
+So for example one protocol driver might talk to the MTD layer to export
+data to filesystems stored on SPI flash like DataFlash; and others might
+control audio interfaces, present touchscreen sensors as input interfaces,
+or monitor temperature and voltage levels during industrial processing.
+And those might all be sharing the same controller driver.
+
+A "struct spi_device" encapsulates the master-side interface between
+those two types of driver.  At this writing, Linux has no slave side
+programming interface.
+
+There is a minimal core of SPI programming interfaces, focussing on
+using driver model to connect controller and protocol drivers using
+device tables provided by board specific initialization code.  SPI
+shows up in sysfs in several locations:
+
+   /sys/devices/.../CTLR/spiB.C ... spi_device for on bus "B",
+	chipselect C, accessed through CTLR.
+
+   /sys/bus/spi/devices/spiB.C ... symlink to the physical
+   	spiB-C device
+
+   /sys/bus/spi/drivers/D ... driver for one or more spi*.* devices
+
+   /sys/class/spi_master/spiB ... class device for the controller
+	managing bus "B".  All the spiB.* devices share the same
+	physical SPI bus segment, with SCLK, MOSI, and MISO.
+
+The basic I/O primitive submits an asynchronous message to an I/O queue
+maintained by the controller driver.  A completion callback is issued
+asynchronously when the data transfer(s) in that message completes.
+There are also some simple synchronous wrappers for those calls.
+
+
+How does board-specific init code declare SPI devices?
+------------------------------------------------------
+Linux needs several kinds of information to properly configure SPI devices.
+That information is normally provided by board-specific code, even for
+chips that do support some of automated discovery/enumeration.
+
+DECLARE CONTROLLERS
+
+The first kind of information is a list of what SPI controllers exist.
+For System-on-Chip (SOC) based boards, these will usually be platform
+devices, and the controller may need some platform_data in order to
+operate properly.  The "struct platform_device" will include resources
+like the physical address of the controller's first register and its IRQ.
+
+Platforms will often abstract the "register SPI controller" operation,
+maybe coupling it with code to initialize pin configurations, so that
+the arch/.../mach-*/board-*.c files for several boards can all share the
+same basic controller setup code.  This is because most SOCs have several
+SPI-capable controllers, and only the ones actually usable on a given
+board should normally be set up and registered.
+
+So for example arch/.../mach-*/board-*.c files might have code like:
+
+	#include <asm/arch/spi.h>	/* for mysoc_spi_data */
+
+	/* if your mach-* infrastructure doesn't support kernels that can
+	 * run on multiple boards, pdata wouldn't benefit from "__init".
+	 */
+	static struct mysoc_spi_data __init pdata = { ... };
+
+	static __init board_init(void)
+	{
+		...
+		/* this board only uses SPI controller #2 */
+		mysoc_register_spi(2, &pdata);
+		...
+	}
+
+And SOC-specific utility code might look something like:
+
+	#include <asm/arch/spi.h>
+
+	static struct platform_device spi2 = { ... };
+
+	void mysoc_register_spi(unsigned n, struct mysoc_spi_data *pdata)
+	{
+		struct mysoc_spi_data *pdata2;
+
+		pdata2 = kmalloc(sizeof *pdata2, GFP_KERNEL);
+		*pdata2 = pdata;
+		...
+		if (n == 2) {
+			spi2->dev.platform_data = pdata2;
+			register_platform_device(&spi2);
+
+			/* also: set up pin modes so the spi2 signals are
+			 * visible on the relevant pins ... bootloaders on
+			 * production boards may already have done this, but
+			 * developer boards will often need Linux to do it.
+			 */
+		}
+		...
+	}
+
+Notice how the platform_data for boards may be different, even if the
+same SOC controller is used.  For example, on one board SPI might use
+an external clock, where another derives the SPI clock from current
+settings of some master clock.
+
+
+DECLARE SLAVE DEVICES
+
+The second kind of information is a list of what SPI slave devices exist
+on the target board, often with some board-specific data needed for the
+driver to work correctly.
+
+Normally your arch/.../mach-*/board-*.c files would provide a small table
+listing the SPI devices on each board.  (This would typically be only a
+small handful.)  That might look like:
+
+	static struct ads7846_platform_data ads_info = {
+		.vref_delay_usecs	= 100,
+		.x_plate_ohms		= 580,
+		.y_plate_ohms		= 410,
+	};
+
+	static struct spi_board_info spi_board_info[] __initdata = {
+	{
+		.modalias	= "ads7846",
+		.platform_data	= &ads_info,
+		.mode		= SPI_MODE_0,
+		.irq		= GPIO_IRQ(31),
+		.max_speed_hz	= 120000 /* max sample rate at 3V */ * 16,
+		.bus_num	= 1,
+		.chip_select	= 0,
+	},
+	};
+
+Again, notice how board-specific information is provided; each chip may need
+several types.  This example shows generic constraints like the fastest SPI
+clock to allow (a function of board voltage in this case) or how an IRQ pin
+is wired, plus chip-specific constraints like an important delay that's
+changed by the capacitance at one pin.
+
+(There's also "controller_data", information that may be useful to the
+controller driver.  An example would be peripheral-specific DMA tuning
+data or chipselect callbacks.  This is stored in spi_device later.)
+
+The board_info should provide enough information to let the system work
+without the chip's driver being loaded.  The most troublesome aspect of
+that is likely the SPI_CS_HIGH bit in the spi_device.mode field, since
+sharing a bus with a device that interprets chipselect "backwards" is
+not possible.
+
+Then your board initialization code would register that table with the SPI
+infrastructure, so that it's available later when the SPI master controller
+driver is registered:
+
+	spi_register_board_info(spi_board_info, ARRAY_SIZE(spi_board_info));
+
+Like with other static board-specific setup, you won't unregister those.
+
+
+NON-STATIC CONFIGURATIONS
+
+Developer boards often play by different rules than product boards, and one
+example is the potential need to hotplug SPI devices and/or controllers.
+
+For those cases you might need to use use spi_busnum_to_master() to look
+up the spi bus master, and will likely need spi_new_device() to provide the
+board info based on the board that was hotplugged.  Of course, you'd later
+call at least spi_unregister_device() when that board is removed.
+
+
+How do I write an "SPI Protocol Driver"?
+----------------------------------------
+All SPI drivers are currently kernel drivers.  A userspace driver API
+would just be another kernel driver, probably offering some lowlevel
+access through aio_read(), aio_write(), and ioctl() calls and using the
+standard userspace sysfs mechanisms to bind to a given SPI device.
+
+SPI protocol drivers are normal device drivers, with no more wrapper
+than needed by platform devices:
+
+	static struct device_driver CHIP_driver = {
+		.name		= "CHIP",
+		.bus		= &spi_bus_type,
+		.probe		= CHIP_probe,
+		.remove		= __exit_p(CHIP_remove),
+		.suspend	= CHIP_suspend,
+		.resume		= CHIP_resume,
+	};
+
+The SPI core will autmatically attempt to bind this driver to any SPI
+device whose board_info gave a modalias of "CHIP".  Your probe() code
+might look like this unless you're creating a class_device:
+
+	static int __init CHIP_probe(struct device *dev)
+	{
+		struct spi_device		*spi = to_spi_device(dev);
+		struct CHIP			*chip;
+		struct CHIP_platform_data	*pdata = dev->platform_data;
+
+		/* get memory for driver's per-chip state */
+		chip = kzalloc(sizeof *chip, GFP_KERNEL);
+		if (!chip)
+			return -ENOMEM;
+		dev_set_drvdata(dev, chip);
+
+		... etc
+		return 0;
+	}
+
+As soon as it enters probe(), the driver may issue I/O requests to
+the SPI device using "struct spi_message".  When remove() returns,
+the driver guarantees that it won't submit any more such messages.
+
+  - An spi_message is a sequence of of protocol operations, executed
+    as one atomic sequence.  SPI driver controls include:
+
+      + when bidirectional reads and writes start ... by how its
+        sequence of spi_transfer requests is arranged;
+
+      + optionally defining short delays after transfers ... using
+        the spi_transfer.delay_usecs setting;
+
+      + whether the chipselect becomes inactive after a transfer and
+        any delay ... by using the spi_transfer.cs_change flag;
+
+      + hinting whether the next message is likely to go to this same
+        device ... using the spi_transfer.cs_change flag on the last
+	transfer in that atomic group, and potentially saving costs
+	for chip deselect and select operations.
+
+  - Follow standard kernel rules, and provide DMA-safe buffers in
+    your messages.  That way controller drivers using DMA aren't forced
+    to make extra copies unless the hardware requires it (e.g. working
+    around hardware errata that force the use of bounce buffering).
+
+    If standard dma_map_single() handling of these buffers is inappropriate,
+    you can use spi_message.is_dma_mapped to tell the controller driver
+    that you've already provided the relevant DMA addresses.
+
+  - The basic I/O primitive is spi_async().  Async requests may be
+    issued in any context (irq handler, task, etc) and completion
+    is reported using a callback provided with the message.
+
+  - There are also synchronous wrappers like spi_sync(), and wrappers
+    like spi_read(), spi_write(), and spi_write_then_read().  These
+    may be issued only in contexts that may sleep, and they're all
+    clean (and small, and "optional") layers over spi_async().
+
+  - The spi_write_then_read() call, and convenience wrappers around
+    it, should only be used with small amounts of data where the
+    cost of an extra copy may be ignored.  It's designed to support
+    common RPC-style requests, such as writing an eight bit command
+    and reading a sixteen bit response -- spi_w8r16() being one its
+    wrappers, doing exactly that.
+
+Some drivers may need to modify spi_device characteristics like the
+transfer mode, wordsize, or clock rate.  This is done with spi_setup(),
+which would normally be called from probe() before the first I/O is
+done to the device.
+
+While "spi_device" would be the bottom boundary of the driver, the
+upper boundaries might include sysfs (especially for sensor readings),
+the input layer, ALSA, networking, MTD, the character device framework,
+or other Linux subsystems.
+
+
+How do I write an "SPI Master Controller Driver"?
+-------------------------------------------------
+An SPI controller will probably be registered on the platform_bus; write
+a driver to bind to the device, whichever bus is involved.
+
+The main task of this type of driver is to provide an "spi_master".
+Use spi_alloc_master() to allocate the master, and class_get_devdata()
+to get the driver-private data allocated for that device.
+
+	struct spi_master	*master;
+	struct CONTROLLER	*c;
+
+	master = spi_alloc_master(dev, sizeof *c);
+	if (!master)
+		return -ENODEV;
+
+	c = class_get_devdata(&master->cdev);
+
+The driver will initialize the fields of that spi_master, including the
+bus number (maybe the same as the platform device ID) and three methods
+used to interact with the SPI core and SPI protocol drivers.  It will
+also initialize its own internal state.
+
+    master->setup(struct spi_device *spi)
+	This sets up the device clock rate, SPI mode, and word sizes.
+	Drivers may change the defaults provided by board_info, and then
+	call spi_setup(spi) to invoke this routine.  It may sleep.
+
+    master->transfer(struct spi_device *spi, struct spi_message *message)
+    	This must not sleep.  Its responsibility is arrange that the
+	transfer happens and its complete() callback is issued; the two
+	will normally happen later, after other transfers complete.
+
+    master->cleanup(struct spi_device *spi)
+	Your controller driver may use spi_device.controller_state to hold
+	state it dynamically associates with that device.  If you do that,
+	be sure to provide the cleanup() method to free that state.
+
+The bulk of the driver will be managing the I/O queue fed by transfer().
+
+That queue could be purely conceptual.  For example, a driver used only
+for low-frequency sensor acess might be fine using synchronous PIO.
+
+But the queue will probably be very real, using message->queue, PIO,
+often DMA (especially if the root filesystem is in SPI flash), and
+execution contexts like IRQ handlers, tasklets, or workqueues (such
+as keventd).  Your driver can be as fancy, or as simple, as you need.
+
+
+THANKS TO
+---------
+Contributors to Linux-SPI discussions include (in alphabetical order,
+by last name):
+
+David Brownell
+Russell King
+Dmitry Pervushin
+Stephen Street
+Mark Underwood
+Andrew Victor
+Vitaly Wool
+
arch/arm/Kconfig +2 -0
index 50b9afa..3cfd82a 100644
@@ -729,6 +729,8 @@ source "drivers/char/Kconfig"
 
 source "drivers/i2c/Kconfig"
 
+source "drivers/spi/Kconfig"
+
 source "drivers/hwmon/Kconfig"
 
 #source "drivers/l3/Kconfig"
drivers/Kconfig +2 -0
index 48f446d..283c089 100644
@@ -44,6 +44,8 @@ source "drivers/char/Kconfig"
 
 source "drivers/i2c/Kconfig"
 
+source "drivers/spi/Kconfig"
+
 source "drivers/w1/Kconfig"
 
 source "drivers/hwmon/Kconfig"
drivers/Makefile +1 -0
index 7fc3f0f..7c45050 100644
@@ -41,6 +41,7 @@ obj-$(CONFIG_FUSION)		+= message/
 obj-$(CONFIG_IEEE1394)		+= ieee1394/
 obj-y				+= cdrom/
 obj-$(CONFIG_MTD)		+= mtd/
+obj-$(CONFIG_SPI)		+= spi/
 obj-$(CONFIG_PCCARD)		+= pcmcia/
 obj-$(CONFIG_DIO)		+= dio/
 obj-$(CONFIG_SBUS)		+= sbus/
drivers/spi/Kconfig new file +76 -0

76 lines not on this page · raw message

drivers/spi/Makefile new file +23 -0
new file mode 100644
index 0000000..afd2321
@@ -0,0 +1,23 @@
+#
+# Makefile for kernel SPI drivers.
+#
+
+ifeq ($(CONFIG_SPI_DEBUG),y)
+EXTRA_CFLAGS += -DDEBUG
+endif
+
+# small core, mostly translating board-specific
+# config declarations into driver model code
+obj-$(CONFIG_SPI_MASTER)		+= spi.o
+
+# SPI master controller drivers (bus)
+# 	... add above this line ...
+
+# SPI protocol drivers (device/link on bus)
+# 	... add above this line ...
+
+# SPI slave controller drivers (upstream link)
+# 	... add above this line ...
+
+# SPI slave drivers (protocol for that link)
+# 	... add above this line ...
drivers/spi/spi.c new file +568 -0

568 lines not on this page · raw message

include/linux/spi/spi.h new file +542 -0

542 lines not on this page · raw message

#3 lore raw
In reply to Kay Sievers
Quoted 11 lines · Kay Sievers
Quoted 10 lines · Kalin KOZHUHAROV
Quoted 5 lines · Greg KH

Here are a few patches for 2.6.15 that add a SPI driver subsystem to the kernel tree.

Please pull from:

	rsync://rsync.kernel.org/pub/scm/linux/kernel/git/gregkh/spi-2.6.git/

May be just a browser accessible URL for Documentation/spi/spi-summary or at least a definition of SPI in the header of the mail.

Quoted 6 lines
Quoted 1 line

git is just too complex for me at htemoment (haven't found the time to learn it)

If the git web interface is "too complex" for you, then you may not need to know what SPI is too. :)

http://www.kernel.org/git/?p=linux/kernel/git/gregkh/spi-2.6.git;a=commitdiff;h=8ae12a0d85987dc138f8c944cb78a92bf466cea0

Thank you for the link, it turns I wasn't right about the meaning... What I had in mind is to include say the beginning two lines of Documentation/spi/spi-summary in the first mail (the usual procedure for patch-00 as I can see):

The "Serial Peripheral Interface" (SPI) is a synchronous four wire serial link used to connect microcontrollers to sensors, memory, and peripherals.

I always give the -ck patches as an example: even if you don't know what are they about, what does -ck mean and so on, just reading the first one or two sentences is enough to decide: to read on or to go next thread.

By seeing this most people will be able to decide whether there are interested or not and those who are interested should spend the time to find the patch (learn to use git if needed), etc.

I know we are not talking Web design here, but "Don't let me think" is an excellent book that I just finished and it teaches exactly what the title says is a good design, not only web.

And I know Greg posts and comments and everything is very professional, I know basically who he is and how important he is. /me is mostly reading here and trying to be helpful, eventually asking for help/explanation of issues I run into.

Thank you again for the time.

Kalin.

Signature · 3 lines
|[ ~~~~~~~~~~~~~~~~~~~~~~ ]|
+-> http://ThinRope.net/ <-+
|[ ______________________ ]|
#5 lore raw
In reply to a message not in the archive

[email protected] (Kalin KOZHUHAROV) wrote on 14.01.06 in <[email protected]>:

Quoted 3 lines

I know we are not talking Web design here, but "Don't let me think" is an excellent book that I just finished and it teaches exactly what the title says is a good design, not only web.

Anything that supports an "Don't let me think" attitude just helps Gates convert the world population into morons.

No, I don't think that's what he *wants* - what he wants is to get filthy rich. But that's what he *does*. Microsoft's message is "you don't have to learn anything" ... and we're already seeing the consequences.

MfG Kai

#6 lore raw
Quoted 8 lines · Kai Henningsen

[email protected] (Kalin KOZHUHAROV) wrote on 14.01.06 in <[email protected]>:

Quoted 3 lines

I know we are not talking Web design here, but "Don't let me think" is an excellent book that I just finished and it teaches exactly what the title says is a good design, not only web.

Anything that supports an "Don't let me think" attitude just helps Gates convert the world population into morons.

/me bad, /me bad :-)

"Don't *make* me think" was the book and sure if you change _make_ with _let_ then the whole meaning is changed a lot.
Here, I wanted to be let (i.e. allowed) to think by being given a piece of the most relevant information (WTF is SPI?), as opposed to being made (i.e. forced) to think by searching here and there to find out what is SPI. The result - I didn't find out, so I wrote this mail. But I am a person that usually manages to find everything, so this made me at least frustrated. And of course, nobody really forced me to think, I was just curious. Now I know SPI is not related to me, at least not now, but I have the concept of SPI that might come helpful some day.

Quoted 3 lines

No, I don't think that's what he *wants* - what he wants is to get filthy rich. But that's what he *does*. Microsoft's message is "you don't have to learn anything" ... and we're already seeing the consequences.

Completely agree! Although it goes a lot off-topic, let me just say that I think everybody needs a license to work with a tool as powerful and sophisticated as a Net connected PC! Yes, everyone should be obeyed to pass the test and there should be minimal age as well, same as a driving license. You might not kill people directly, but you may let your PC help steal money, spread viruses and SPAM, hog resources and whatever.
So, I don't get it why most people are happy enough to muddle through the other OS ('cause windoze is a swear word) without even thinking about that.

A happy Gentoo user since 2002, trying to become a dev; "in IT" since the age of 6; M.Sc in Computer Engineering

Hmm, I should actually put a page with these thoughts instead of explaining them over and over... now that they are getting clearer.

Sorry for the bandwidth,
Kalin.

Signature · 3 lines
|[ ~~~~~~~~~~~~~~~~~~~~~~ ]|
+-> http://ThinRope.net/ <-+
|[ ______________________ ]|