SPI core refresh
Subsystems (4)
cover SPI core refresh
Greetings,
this message fill be followed by the following three ones:
1) updated SPI core from Dmitry Pervushin/Vitaly Wool
2) Atmel MTD dataflash driver port for this core
3) SPI controller driver for Philips SPI controller
This SPI core features:
* multiple SPI controller support
* multiple devices on the same bus support
* DMA support
* DMA-unsafety check
* synchronous and asynchronous transfers
* library for asynchronous transfers on the bus using kernel threads
* character device interface
* custom lightweight SPI message allocation mechanism
* ability to call transfer function from the interrupt context
* no more explicit redundant memory allocations/copys.
The main differences between the previous version and this one:
* handling DMA-unsafe buffer is now completely up to the bus driver
* spi-dev compilation error fixed
* redundant non-NULL check in bus_suspend/bus_resume removed
* mutexes changed to spinlocks in queueing function for spi-thread to make it callable from the interrupt context.
I'd also like to encourage those who interested to use CVS on SourceForge to get the latest updates of the SPI core. The CVS root is ':pserver:[email protected]:/cvsroot/spi-devel', the module to checkout is spi-core. Hope that helps.
Vitaly
PATCH 1/3 SPI core refresh: the core
Documentation/spi.txt | 134 +++++++++ arch/arm/Kconfig | 2 drivers/Kconfig | 2 drivers/Makefile | 1 drivers/spi/Kconfig | 46 +++ drivers/spi/Makefile | 19 + drivers/spi/spi-alloc.c | 101 +++++++ drivers/spi/spi-alloc.h | 54 +++ drivers/spi/spi-core.c | 658 +++++++++++++++++++++++++++++++++++++++++++++++ drivers/spi/spi-core.h | 32 ++ drivers/spi/spi-dev.c | 209 ++++++++++++++ drivers/spi/spi-thread.c | 187 +++++++++++++ drivers/spi/spi-thread.h | 42 +++ include/linux/spi.h | 252 ++++++++++++++++++ 14 files changed, 1739 insertions(+)
Documentation/spi.txt new file +134 -0
@@ -0,0 +1,134 @@ +Documentation/spi.txt +======================================================== +Table of contents +1. Introduction -- what is SPI ? +2. Purposes of this code +3. SPI devices stack +3.1 SPI outline +3.2 How the SPI devices gets discovered and probed ? +3.3 DMA and SPI messages +4. SPI functions and structures reference +5. How to contact authors +======================================================== + +1. What is SPI ? +---------------- +SPI stands for "Serial Peripheral Interface", a full-duplex synchronous +serial interface for connecting low-/medium-bandwidth external devices +using four wires. SPI devices communicate using a master/slave relation- +ship over two data lines and two control lines: +- Master Out Slave In (MOSI): supplies the output data from the master + to the inputs of the slaves; +- Master In Slave Out (MISO): supplies the output data from a slave to + the input of the master. It is important to note that there can be no + more than one slave that is transmitting data during any particular + transfer; +- Serial Clock (SCLK): a control line driven by the master, regulating + the flow of data bits; +- Slave Select (SS): a control line that allows slaves to be turned on + and off with hardware control. +More information is also available at http://en.wikipedia.org/wiki/Serial_Peripheral_Interface + +2. Purposes of this code +------------------------ +The supplied patch is starting point for implementing drivers for various +SPI busses as well as devices connected to these busses. Currently, the +SPI core supports only for MASTER mode for system running Linux. + +3. SPI devices stack +-------------------- + +3.1 The SPI outline + +The SPI infrastructure deals with several levels of abstraction. They are +"SPI bus", "SPI bus driver", "SPI slave device" and "SPI device driver". The +"SPI bus" is hardware device, which usually called "SPI adapter", and has +"SPI slave devices" connected. From the Linux' point of view, the "SPI bus" is +structure of type platform_device, and "SPI slave device" is structure of type +spi_device. The "SPI bus driver" is the driver which controls the whole +SPI bus (and, particularly, creates and destroys "SPI slave devices" on the bus), +and "SPI device driver" is driver that controls the only device on the SPI +bus, controlled by "SPI bus driver". "SPI device driver" can indirectly +call "SPI bus driver" to send/receive messages using API provided by SPI +core, and provide its own interface to the kernel and/or userland. +So, the device stack looks as follows: + + +--------------+ +---------+ + | some_bus | | spi_bus | + +--------------+ +---------+ + |..| | + |..|--------+ +---------------+ + +------------+| is parent to | SPI devices | + | SPI busses |+-------------> | | + +------------+ +---------------+ + | | + +----------------+ +----------------------+ + | SPI bus driver | | SPI device driver | + +----------------+ +----------------------+ + +3.2 How do the SPI devices get discovered and probed ? + +In general, the SPI bus driver cannot effectively discover devices +on its bus. Fortunately, the devices on SPI bus usually implemented +onboard, so you need to create array of structures spi_device_desc and +pass this array to function spi_bus_populate, like this: + struct spi_device_desc spi_slaves[] = { + [0] = { + .name = "device1", + .param = device1_params, + }, + [1] = { + .name = "device2", + .param = NULL, + } + [2] = { + NULL, NULL + }; + err = spi_bus_populate( the_spi_bus, spi_slaves, callback ); + +3.3. DMA and SPI messages +------------------------- + +The core provides additional robustness when the buffer suppiled is not +DMA-safe. If it is, the core will allocate DMA-safe buffer and copy user- +supplied buffer to it (before operation in WRITE case, and after in READ case). +This two situations are distinguished by specific flag SPI_M_DMAUNSAFE. +Bus driver should use spimsg_get_buffer and spimsg_put_buffer to access buffer. +The buffer received from spimsg_get_buffer will be always DMA-safe and suitable for +DMA mapping. + +4. SPI functions are structures reference +----------------------------------------- +Please refer to kerneldocs for the information. To create it, use command + $ scripts/kernel-doc -html drivers/spi/* > spi.html + +5. Getting the latest sources +----------------------------- +The stable snapshots are available at + http://spi-devel.sourceforge.net/downloads +The most recent sources can be obtained via the CVS. +Use the following CVS setup to grab them: +* set CVSROOT environment variable to + :pserver:[email protected]:/cvsroot/spi-devel, i. e. +$ export CVSROOT=:pserver:[email protected]:/cvsroot/spi-devel +* login into the anonymous CVS using 'cvs login'. When prompted for password, + just type Enter, i. e. +$ cvs login +Logging in to :pserver:[email protected]:2401/cvsroot/spi-devel +CVS password: +$ +* checkout the 'spi-core' CVS repo: +$ cvs co cpi-core +You'll get a set of patches to be applied to the most recent 2.6-git kernel. + +6. How to contact authors +------------------------- +Do you have any comments ? Enhancements ? Device driver ? Feel free +to contact me: + [email protected] + [email protected] +Visit our project page: + http://spi-devel.sourceforge.net +Subscribe to mailing list: + [email protected] +
arch/arm/Kconfig +2 -0
@@ -753,6 +753,8 @@ source "drivers/usb/Kconfig" source "drivers/mmc/Kconfig" +source "drivers/spi/Kconfig" + endmenu source "fs/Kconfig"
drivers/Kconfig +2 -0
@@ -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
@@ -69,3 +69,4 @@ obj-$(CONFIG_SGI_IOC4) += sn/ obj-y += firmware/ obj-$(CONFIG_CRYPTO) += crypto/ obj-$(CONFIG_SUPERH) += sh/ +obj-$(CONFIG_SPI) += spi/
drivers/spi/Kconfig new file +46 -0
46 lines not on this page · raw message
drivers/spi/Makefile new file +19 -0
@@ -0,0 +1,19 @@ +# +# Makefile for the kernel spi bus driver. +# + +spi-y += spi-core.o +spi-$(CONFIG_SPI_CHARDEV) += spi-dev.o +spi-$(CONFIG_SPI_THREAD) += spi-thread.o +spi-$(CONFIG_SPI_CUSTOM_ALLOC) += spi-alloc.o +# bus drivers +obj-$(CONFIG_SPI_PNX) += spipnx.o +# ...functional drivers +obj-$(CONFIG_SPI_PNX4008_EEPROM) += pnx4008-eeprom.o +# ...and the common spi-dev driver +obj-$(CONFIG_SPI) += spi.o + +ifeq ($(CONFIG_SPI_DEBUG),y) +EXTRA_CFLAGS += -DDEBUG +endif +
drivers/spi/spi-core.c new file +658 -0
658 lines not on this page · raw message
drivers/spi/spi-core.h new file +32 -0
@@ -0,0 +1,32 @@ +/* +* linux/drivers/spi/spi-core.h +* +* Copyright (C) 2005 MontaVista Software, Inc <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License. +* +*/ +#ifndef __SPI_CORE_H +#define __SPI_CORE_H + +struct spi_msg { +u32 flags; +u16 len;/* msg length */ +u32 clock; +struct spi_device *device; +void *context; + +struct completion sync; + +struct spi_msg *next; + +struct list_head link; + +void (*status) (struct spi_msg * msg,int code); + +void *buf_ptr; +}; + +#endif /* __SPI_CORE_H */
drivers/spi/spi-dev.c new file +209 -0
209 lines not on this page · raw message
drivers/spi/spi-thread.c new file +187 -0
187 lines not on this page · raw message
drivers/spi/spi-thread.h new file +42 -0
42 lines not on this page · raw message
include/linux/spi.h new file +252 -0
252 lines not on this page · raw message
drivers/spi/spi-alloc.c new file +101 -0
101 lines not on this page · raw message
drivers/spi/spi-alloc.h new file +54 -0
54 lines not on this page · raw message
Re: [PATCH 2.6-git 2/3] SPI core refresh: MTD dataflash driver
drivers/mtd/devices/Kconfig | 8 drivers/mtd/devices/Makefile | 1 drivers/mtd/devices/mtd_dataflash.c | 601 ++++++++++++++++++++++++++++++++++++ include/linux/spi/flash.h | 27 + 4 files changed, 637 insertions(+)
drivers/mtd/devices/Kconfig +8 -0
@@ -255,5 +255,13 @@ config MTD_DOCPROBE_55AA LinuxBIOS or if you need to recover a DiskOnChip Millennium on which you have managed to wipe the first block. +config MTD_DATAFLASH + tristate "Support for AT45xxx DataFlash" + depends on MTD && SPI && 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. + endmenu
drivers/mtd/devices/Makefile +1 -0
@@ -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 +601 -0
601 lines not on this page · raw message
include/linux/spi/flash.h new file +27 -0
@@ -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
PATCH 3/3 SPI core refresh: SPI/PNX bus driver and EEPROM driver
Kconfig | 8 pnx4008-eeprom.c | 121 +++++++++++++ spipnx-init.h | 9 spipnx.c | 510 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ spipnx.h | 58 ++++++ 5 files changed, 706 insertions(+)
drivers/spi/Kconfig +8 -0
@@ -42,5 +42,13 @@ config SPI_CHARDEV Say Y here to use /dev/spiNN device files. They make it possible to have user-space programs use the SPI bus. +config SPI_PNX + tristate "PNX SPI bus support" + depends on ARCH_PNX4008 && SPI + +config SPI_PNX4008_EEPROM + tristate "Dummy EEPROM driver" + depends on SPI && SPI_PNX && ARCH_PNX4008 + endmenu
drivers/spi/pnx4008-eeprom.c new file +121 -0
121 lines not on this page · raw message
drivers/spi/spipnx-init.h new file +9 -0
@@ -0,0 +1,9 @@ +#include <linux/kernel.h> +#include <asm/arch/spi.h> + +#ifdef CONFIG_ARCH_PNX4008 +struct spipnx_wifi_params spipnx_wifi_params = { + .gpio_cs_line =GPIO_03 , +}; +#endif +
drivers/spi/spipnx.c new file +510 -0
510 lines not on this page · raw message
drivers/spi/spipnx.h new file +58 -0
58 lines not on this page · raw message
Re: [PATCH 2.6-git 3/3] SPI core refresh: SPI/PNX bus driver and EEPROM driver
drivers/spi/pnx4008-eeprom.c line 15
Quoted 7 lines
drivers/spi/pnx4008-eeprom.c new file +3
-0@@ -0,0 +1,121 @@ +#define EEPROM_SIZE 256 +#define DRIVER_NAME "EEPROM" +#define READ_BUFF_SIZE 160
Wouldn't it be better to have an EEPROM driver that's not hard-wired to this particular devel board? And which could work on at least all chips using eight bit addressing?
This seems to match the 25020 series SPI EEPROMS. (2 Kbits, 256 bytes.) But the 25010 and 25040 also use 8 bit address protoocol ... and then there are also chips using 16 bit addresses, and 24 bit ones.
Shouldn't board init code be able to just say "25640 at spi1 chipselect 3", and have the driver know that means 8 KBytes with pagesize 32?
- Dave
Re: [PATCH 2.6-git 3/3] SPI core refresh: SPI/PNX bus driver and EEPROM driver
Quoted 14 lines · David Brownell
drivers/spi/pnx4008-eeprom.c line 15
Quoted 9 lines
drivers/spi/pnx4008-eeprom.c new file +3
-0@@ -0,0 +1,121 @@ +#define EEPROM_SIZE 256 +#define DRIVER_NAME "EEPROM" +#define READ_BUFF_SIZE 160Wouldn't it be better to have an EEPROM driver that's not hard-wired to this particular devel board? And which could work on at least all chips using eight bit addressing?
Quoted 9 lines
This seems to match the 25020 series SPI EEPROMS. (2 Kbits, 256 bytes.) But the 25010 and 25040 also use 8 bit address protoocol ... and then there are also chips using 16 bit addresses, and 24 bit ones.
Shouldn't board init code be able to just say "25640 at spi1 chipselect 3", and have the driver know that means 8 KBytes with pagesize 32?
Looks reasonable to me, thanks. Anyway - not today :)
Vitaly