SPI
Subsystems (3)
Hello guys,
I am attaching the next incarnation of SPI core; feel free to comment it.
Documentation/spi.txt | 351 +++++++++++++++++++++++++++++++++++++ arch/arm/Kconfig | 2 drivers/Kconfig | 2 drivers/Makefile | 1 drivers/spi/Kconfig | 33 +++ drivers/spi/Makefile | 11 + drivers/spi/spi-core.c | 456 +++++++++++++++++++++++++++++++++++++++++++++++++ drivers/spi/spi-dev.c | 236 +++++++++++++++++++++++++ include/linux/spi.h | 214 ++++++++++++++++++++++ 9 files changed, 1306 insertions(+)
arch/arm/Kconfig +2 -0
@@ -834,6 +834,8 @@ source "drivers/ssi/Kconfig" source "drivers/mmc/Kconfig" +source "drivers/spi/Kconfig" + endmenu source "ktools/Kconfig"
drivers/Kconfig +2 -0
@@ -42,6 +42,8 @@ source "drivers/char/Kconfig" source "drivers/i2c/Kconfig" +source "drivers/spi/Kconfig" + source "drivers/w1/Kconfig" source "drivers/misc/Kconfig"
drivers/Makefile +1 -0
@@ -67,3 +67,4 @@ obj-$(CONFIG_DPM) += dpm/ obj-$(CONFIG_MMC) += mmc/ obj-y += firmware/ obj-$(CONFIG_EVENT_BROKER) += evb/ +obj-$(CONFIG_SPI) += spi/
drivers/spi/Kconfig new file +33 -0
@@ -0,0 +1,33 @@ +# +# SPI device configuration +# +menu "SPI support" + +config SPI + default Y + tristate "SPI support" + default false + help + Say Y if you need to enable SPI support on your kernel + +config SPI_DEBUG + bool "SPI debug output" + depends on SPI + default false + help + Say Y there if you'd like to see debug output from SPI drivers. + If unsure, say N + +config SPI_CHARDEV + default Y + tristate "SPI device interface" + depends on SPI + help + Say Y here to use spi-* device files, usually found in the /dev + directory on your system. They make it possible to have user-space + programs use the SPI bus. + This support is also available as a module. If so, the module + will be called spi-dev. + +endmenu +
drivers/spi/Makefile new file +11 -0
@@ -0,0 +1,11 @@ +# +# Makefile for the kernel spi bus driver. +# + +obj-$(CONFIG_SPI) += spi-core.o +obj-$(CONFIG_SPI_CHARDEV) += spi-dev.o + +ifeq ($(CONFIG_SPI_DEBUG),y) +EXTRA_CFLAGS += -DDEBUG +endif +
drivers/spi/spi-core.c new file +456 -0
456 lines not on this page · raw message
drivers/spi/spi-dev.c new file +236 -0
236 lines not on this page · raw message
include/linux/spi.h new file +214 -0
214 lines not on this page · raw message
Documentation/spi.txt new file +351 -0
351 lines not on this page · raw message
Quoted 3 lines · dmitry pervushin wrote/
Hello guys,
I am attaching the next incarnation of SPI core; feel free to comment it.
Hello,
Very little comments...
Quoted 6 lines
Index: linux-2.6.10/drivers/spi/Kconfig
===================================================================drivers/spi/Kconfig new file +1
-0@@ -0,0 +1,33 @@ +#
drivers/spi/Kconfig line 11
Quoted 10 lines
drivers/spi/Kconfig new file +10
-0+# SPI device configuration +# +menu "SPI support" + +config SPI + default Y + tristate "SPI support" + default false + help + Say Y if you need to enable SPI support on your kernel
SPI is far from being well know, please put more help. At least define SPI as "Serial Peripheral Interface" and suggest the user to have a look at Documentation/spi.txt . IMHO, it's also convenient if you give the name of the module that will be created (spi?).
Documentation/spi.txt
Quoted 4 lines
Index:
linux-2.6.10/Documentation/spi.txt
===================================================================Documentation/spi.txt new file +0
-0
:
:
Quoted 8 lines
Documentation/spi.txt new file +8
-0+ +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
Documentation/spi.txt line 30
Quoted 10 lines
Documentation/spi.txt new file +10
-0+ 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/ .
Broken link, it is http://en.wikipedia.org/wiki/Serial_Peripheral_Interface (no trailing /)
Cheers,
Eric
Quoted 5 lines · Eric Piel
drivers/spi/Kconfig line 11
Quoted 1 line
drivers/spi/Kconfig new file +1
-0+ Say Y if you need to enable SPI support on your kernelSPI is far from being well know, please put more help. At least define SPI as "Serial Peripheral Interface" and suggest the user to have a look at
Documentation/spi.txt. IMHO, it's also convenient if you give the name of the module that will be created (spi?).
The module name is spi-core. If one who configures the kernel does not know about the SPI, it seems that it is better to keep the option unchanged... However, I edit the text in Kconfig.
Quoted 2 lines
Broken link, it is
http://en.wikipedia.org/wiki/Serial_Peripheral_Interface (no trailing /)
Fixed.
Thank you for comments,
dmitry
resend; sorry. Forgot to cc: the list.
Quoted 3 lines · dmitry pervushin
Hello guys,
I am attaching the next incarnation of SPI core; feel free to comment it.
===================================================================
Documentation/spi.txt line 44
Quoted 9 lines
Documentation/spi.txt new file +5
-0@@ -0,0 +1,351 @@ +Documentation/spi.txt +3.1 The SPI outline + +The SPI infrastructure deals with several levels of abstraction. They are +"SPI bus", "SPI bus driver", "SPI device" and "SPI device driver". The
Would "SPI slave" or "SPI slave device" be better terminology than "SPI device"? That way the terminology matches how SPI hardware docs are usually written. (not a big deal, just thought I'd ask)
Quoted 13 lines
+"SPI bus" is hardware device, which usually called "SPI adapter", and has +"SPI devices" connected. From the Linux' point of view, the "SPI bus" is
Documentation/spi.txt new file +11
-0+structure of type platform_device, and "SPI 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 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: + + +--------------+ +---------+ + | platform_bus | | spi_bus |
Documentation/spi.txt line 67
Quoted 10 lines
Documentation/spi.txt new file +10
-0+ +--------------+ +---------+ + |..| | + |..|--------+ +---------------+ + +------------+| is parent to | SPI devices | + | SPI busses |+-------------> | | + +------------+ +---------------+ + | | + +----------------+ +----------------------+ + | SPI bus driver | | SPI device driver | + +----------------+ +----------------------+
Helpful diagram. :)
Quoted 4 lines
Documentation/spi.txt new file +4
-0+ +3.2 How do the SPI devices gets discovered and probed ? + +In general, the SPI bus driver cannot effective discover devices
Documentation/spi.txt line 81
Quoted 10 lines
Documentation/spi.txt new file +10
-0+on its bus. Fortunately, the devices on SPI bus usually implemented +onboard, so the following method has been chosen: the SPI bus driver +calls the function named spi_bus_populate and passed the `topology +string' to it. The function will parse the string and call the callback +for each device, just before registering it. This allows bus driver +to determine parameters like CS# for each device, retrieve them from +string and store somewhere like spi_device->platform_data. An example: + err = spi_bus_populate( the_spi_bus, + "Dev1 0 1 2\0" "Dev2 2 1 0\0", + extract_name )
In my mind, this is not ideal. For example, the MPC5200 has 4 PSC ports which can be in SPI mode. The SPI bus driver should/will not know what devices are attached to it. It should be the responsibility of the board setup code to populate the bus.... on the other hand, perhaps the bus driver should look to it's platform_device structure to find a table of attached devices. Generic platform_device parsing code could be used by all SPI bus drivers.
Along the same lines, an SPI bus driver may not know the board specific way SS lines are driven. If GPIO is used as SS lines then each SPI bus will need a different SS routine. However, it looks like this is not an issue for your infrastructure. The individual SPI bus driver can be handed a SS callback by the board setup code for each SPI bus.
Documentation/spi.txt line 84
Quoted 3 lines
Documentation/spi.txt new file +3
-0+In this example, function like extract_name would put the '\0' on the +1st space of device's name, so names will become just "Dev1", "Dev2", +and the rest of string will become parameters of device.
I don't think it's wise to use '\0' as a delimiter. Sure it makes parsing really simple when the string passed in is formed correctly, but if someone misses the last '\0' you have no way to know where the string ends. It also makes it difficult support passing a device string from the kernel command line.
Documentation/spi.txt line 113
Quoted 4 lines
+4. SPI functions are structures reference
+-----------------------------------------Documentation/spi.txt new file +2
-0+This section describes structures and functions that listed +in include/linux/spi.h
I would like to see this function and structure reference in the spi.h file itself rather than here. Better chance of it being kept up to date that way.
Quoted 7 lines
Documentation/spi.txt new file +7
-0+ +i. struct spi_msg +~~~~~~~~~~~~~~~~~ + +struct spi_msg { + unsigned char flags; + unsigned short len;
Documentation/spi.txt line 130
Quoted 10 lines
Documentation/spi.txt new file +10
-0+ unsigned long clock; + struct spi_device* device; + void *context; + struct list_head link; + void (*status)( struct spi_msg* msg, int code ); + void *devbuf_rd, *devbuf_wr; + u8 *databuf_rd, *databuf_wr; +}; +This structure represents the message that SPI device driver sends to the +SPI bus driver to handle.
Is there any way for the SPI device to constrain the clock rate for a transfer? For example, if the devices maximum speed is lower than the bus maximum speed.
I looked over the code and I didn't notice anything obviously incorrect. I greatly appreciate the large block of documentation.
Overall, I like. It looks like it does what I need it to. If I get a chance this week I'll port my SPI drivers to it and try it out on my MPC5200 board.
Thanks!
g.
Quoted 3 lines · Grant Likely
Would "SPI slave" or "SPI slave device" be better terminology than "SPI device"? That way the terminology matches how SPI hardware docs are usually written. (not a big deal, just thought I'd ask)
The term "SPI slave device" looks correct.. I am correcting the doc :)
Quoted 10 lines
Documentation/spi.txt line 81
Quoted 3 lines
Documentation/spi.txt new file +3
-0+ err = spi_bus_populate( the_spi_bus, + "Dev1 0 1 2\0" "Dev2 2 1 0\0", + extract_name )In my mind, this is not ideal. For example, the MPC5200 has 4 PSC ports which can be in SPI mode. The SPI bus driver should/will not know what devices are attached to it. It should be the responsibility of the board setup code to populate the bus.... on the other hand, perhaps the bus driver should look to it's
platform_devicestructure to find a table of attached devices. Genericplatform_deviceparsing code could be used by all SPI bus drivers.
The spi_bus_populate is not the only way to populate the bus; the bus driver can discover SPI devices on his own and directly call spi_device_add, isn't it ?
Quoted 8 lines
Documentation/spi.txt line 84
Quoted 3 lines
Documentation/spi.txt new file +3
-0+In this example, function like extract_name would put the '\0' on the +1st space of device's name, so names will become just "Dev1", "Dev2", +and the rest of string will become parameters of device.I don't think it's wise to use '\0' as a delimiter. Sure it makes parsing really simple when the string passed in is formed correctly, but if someone misses the last '\0' you have no way to know where the string ends. It also makes it difficult support passing a device string from the kernel command line.
You're right. Using spi_populate_bus is the simplest way, that may lead to errors... From the other hand, if we used another char to delimit device name and its parameters, there would be person who would want this character in device name... I think that we can add another approach to populate the bus ?
Quoted 8 lines
Documentation/spi.txt line 113
Quoted 5 lines
+4. SPI functions are structures reference
+-----------------------------------------Documentation/spi.txt new file +2
-0+This section describes structures and functions that listed +in include/linux/spi.hI would like to see this function and structure reference in the
spi.hfile itself rather than here. Better chance of it being kept up to date that way.
Yes; but I personally prefer to look to the only place instead of spi.h/spi-core.c. I'll try to keep the things consistent :)
Quoted 5 lines
Documentation/spi.txt line 130
Quoted 2 lines
Documentation/spi.txt new file +2
-0+This structure represents the message that SPI device driver sends to the +SPI bus driver to handle.Is there any way for the SPI device to constrain the clock rate for a transfer? For example, if the devices maximum speed is lower than the bus maximum speed.
Thank you for this comment; the `clock' field is initially intended to do this. Device driver might set the field to maximum speed, and bus driver would analyze the field in its xfer function and send the message on lower speed. Moreover, there is the `set_clock' callback in spi_bus_driver. If msg specifies its own clock value, the bus driver's set_clock will be called just before transferring the message.
Quoted 3 lines
Overall, I like. It looks like it does what I need it to. If I get a chance this week I'll port my SPI drivers to it and try it out on my MPC5200 board.
Thank you! If your drivers are going to open source, could you also sent them to spi mailing list, to prepare the consolidated patch ? I hope if there is no significant troubles, the current core will go to the mainstream kernel :)
drivers/spi/spi-dev.c line 38
Quoted 10 lines · dmitry pervushin
Hello guys,
I am attaching the next incarnation of SPI core; feel free to comment it.
drivers/spi/spi-dev.c new file +5
-0+/* The devfs code is contributed by Philipp Matthias Hahn +<[email protected]> */ +/* devfs code corrected to support automatic device addition/deletion +by Vitaly Wool <[email protected]> (C) 2004 MontaVista Software, Inc. +*/
I'd like to thank Vitaly and Philipp for their work, which was probably useful at the time, but I've always wondered - when cleaning up code, should such comments be removed too, or left as historical reminders? The MAINTAINERS file seems to get cleaned most of the time, the CREDITS doesn't - which way should in-source comments go?
My POV is that those lines should go away.
Best regards,
Vitaly
Quoted 32 lines · [email protected] wrote:
Quoted 10 lines · dmitry pervushin
Hello guys,
I am attaching the next incarnation of SPI core; feel free to comment it.
drivers/spi/spi-dev.c line 38
Quoted 10 lines
drivers/spi/spi-dev.c new file +5
-0+/* The devfs code is contributed by Philipp Matthias Hahn +<[email protected]> */ +/* devfs code corrected to support automatic device addition/deletion +by Vitaly Wool <[email protected]> (C) 2004 MontaVista Software, Inc. +*/ I'd like to thank Vitaly and Philipp for their work, which was probably useful at the time, but I've always wondered - when cleaning up code, should such comments be removed too, or left as historical reminders? The
MAINTAINERSfile seems to get cleaned most of the time, the CREDITS doesn't - which way should in-source comments go?
Quoted 4 lines · dmitry pervushin
Hello guys,
I am attaching the next incarnation of SPI core; feel free to comment it.
A few small style comments below.
General notes:
Please use only tabs for indentation.
Please get rid of all the trailing whitespace. A small sed script
like this will do: sed -r s/"[ \t]+$"/""/
Please use only one statement pr line.
Please get rid of the extra whitespace after opening paren and before
closing paren: not like ( this ), but like (this).
Please use a single space after if. Like this: if (foo), not if(foo). For pointer variables, "type *name" is usually prefered,
not "type* name" or "type * name".
See the changes I've made below for more details (note: I may have missed some
bits, if so, please correct what I missed as well) :-)
See Documentation/CodingStyle for yet more details and rationale.
[snip]
drivers/spi/spi-core.c line 37
Quoted 4 lines
+ */
drivers/spi/spi-core.c new file +3
-0+static int spi_bus_match_name (struct device *dev,struct device_driver *drv) +{ + return !strcmp (drv->name, SPI_DEV_CHAR) ||
return !strcmp(drv->name, SPI_DEV_CHAR) ||
[snip]
Quoted 3 lines
+ * Parameters:
+ * struct device* dev the 'bus' device
+ * void* context not used. Will be NULL
* struct device *dev the 'bus' device
* void *context not used. Will be NULL
[snip]
drivers/spi/spi-core.c line 105
Quoted 9 lines
drivers/spi/spi-core.c new file +9
-0+int __spi_bus_free (struct device *dev,void *context) +{ +struct spi_bus_data *pd = dev->platform_data; + +atomic_inc (&pd->exiting); +kthread_stop (pd->thread); +kfree (pd); + +dev_dbg ( dev,"unregistering children\n" );
dev_dbg(dev, "unregistering children\n");
drivers/spi/spi-core.c line 115
Quoted 10 lines
drivers/spi/spi-core.c new file +10
-0+/* +* NOTE: the loop below might needs redesign. Currently +* we delete devices from the head of children list +* until the list is empty; that's because the function +* device_for_each_child will hold the semaphore needed +* for deletion of device +*/ +while ( !list_empty ( &dev->children ) ) { + struct device* child = list_entry ( dev->children.next, struct device, node ); +spi_device_del (TO_SPI_DEV (child) );
while(!list_empty(&dev->children)) {
struct device *child = list_entry(dev->children.next, struct device, node);
spi_device_del(TO_SPI_DEV(child));[snip]
Quoted 7 lines
+ *
spi_bus_driver_unregister
+ *
+ * unregisters the SPI bus from the system. Before unregistering, it deletes
+ * each SPI device on the bus using call to__spi_device_free
+ *
+ * Parameters:
+ * struct spi_bus_driver*bus_driverthe bus driver
* struct spi_bus_driver *bus_driver the bus driver
[snip]
drivers/spi/spi-core.c line 134
Quoted 4 lines
drivers/spi/spi-core.c new file +4
-0+void spi_bus_driver_unregister (struct spi_bus_driver *bus_driver) +{ +if (bus_driver) { +driver_for_each_dev ( &bus_driver->driver,NULL , __spi_bus_free);
driver_for_each_dev(&bus_driver->driver, NULL, __spi_bus_free);
[snip]
Quoted 1 line
+ * struct device* dev
* struct device *dev
Quoted 4 lines
+ * Return value:
+ * none
+ */
+voidspi_device_release( struct device* dev )
void spi_device_release(struct device *dev)
[snip]
Quoted 3 lines
+ * struct device* parent the 'bus' device
+ * struct spi_device* dev new device to be added
+ * char* name name of device. Should not be NULL
* struct device *parent the 'bus' device
* struct spi_device *dev new device to be added
* char *name name of device. Should not be NULL
[snip]
drivers/spi/spi-core.c line 176
Quoted 10 lines
drivers/spi/spi-core.c new file +10
-0+int spi_device_add (struct device *parent,struct spi_device *dev,char *name) +{ +if (!name || !dev) +return -EINVAL ; + +memset (&dev->dev,0 ,sizeof (dev->dev)); + dev->dev.parent = parent; + dev->dev.bus = &spi_bus; +strncpy ( dev->name, name,sizeof (dev->name)); +strncpy ( dev->dev.bus_id, name,sizeof ( dev->dev.bus_id ) );
strncpy(dev->dev.bus_id, name, sizeof(dev->dev.bus_id));
[snip]
Quoted 6 lines
+ *
spi_queue
+ *
+ * Queue the message to be processed asynchronously
+ *
+ * Parameters:
+ * struct spi_msg* msg message to be sent
* struct spi_msg *msg message to be sent
Quoted 4 lines
+ * Return value:
+ * 0 on no errors, negative error code otherwise
+ */
+intspi_queue( struct spi_msg *msg)
int spi_queue(struct spi_msg *msg)
Review
Quoted 2 lines
(quoted diff) +2
-0+{ + struct device* dev = &msg->device->dev;
struct device *dev = &msg->device->dev;
drivers/spi/spi-core.c line 199
Quoted 5 lines
drivers/spi/spi-core.c new file +5
-0+struct spi_bus_data *pd = dev->parent->platform_data; + +down (&pd->lock); +list_add_tail (&msg->link, &pd->msgs); +dev_dbg (dev->parent,"message has been queued\n" );
dev_dbg(dev->parent, "message has been queued\n");
[snip]
Quoted 9 lines
+ *
__spi_transfer_callback
+ *
+ * callback for synchronously processed message. Ifspi_transferdetermines
+ * that there is no callback provided neither bymsg->statusnor callback
+ * parameter, the__spi_transfer_callbackwill be used, andspi_transfer
+ * does not return until transfer is finished
+ *
+ * Parameters:
+ * struct spimsg* msg message that is being processed now
* struct spimsg *msg message that is being processed now
Quoted 3 lines
+ * int code status of processing
+ */
+static void__spi_transfer_callback( struct spi_msg* msg, int code )
static void __spi_transfer_callback(struct spi_msg *msg, int code)
drivers/spi/spi-core.c line 220
Quoted 3 lines
drivers/spi/spi-core.c new file +3
-0+{ +if ( code & (SPIMSG_OK |SPIMSG_FAILED ) ) +complete ( (struct completion *)msg->context );
if (code & (SPIMSG_OK|SPIMSG_FAILED)) complete((struct completion*)msg->context);
[snip]
Quoted 7 lines
+ *
spi_transfer
+ *
+ * Process the SPI message, by queuing it to the driver and either
+ * immediately return or waiting till the end-of-processing
+ *
+ * Parameters:
+ * struct spi_msg* msg message to process
* struct spi_msg *msg message to process
[snip]
Quoted 1 line
+int
spi_transfer( struct spi_msg* msg, void (*callback)( struct spi_msg*, int ) )
int spi_transfer(struct spi_msg *msg, void (*callback)(struct spi_msg*, int))
drivers/spi/spi-core.c line 243
Quoted 5 lines
drivers/spi/spi-core.c new file +5
-0+{ +struct completion msg_done; +int err = -EINVAL ; + +if ( callback && !msg->status ) {
if (callback && !msg->status) {[snip]
drivers/spi/spi-core.c line 257
Quoted 10 lines
drivers/spi/spi-core.c new file +10
-0+if ( !callback ) { +if ( !msg->status ) { +init_completion ( &msg_done ); + msg->context = &msg_done; + msg->status = __spi_transfer_callback; +spi_queue ( msg ); +wait_for_completion ( &msg_done ); + err =0 ; + }else { + err =spi_queue ( msg );
if (!callback) {
if (!msg->status) {
init_completion(&msg_done);
msg->context = &msg_done;
msg->status = __spi_transfer_callback;
spi_queue(msg);
wait_for_completion(&msg_done);
err = 0;
} else {
err = spi_queue(msg);[snip]
Quoted 7 lines
+ *
spi_thread
+ *
+ * This function is started as separate thread to perform actual
+ * transfers on SPI bus
+ *
+ * Parameters:
+ * void* context pointer to structspi_bus_data
* void *context pointer to struct spi_bus_data
[snip]
drivers/spi/spi-core.c line 293
Quoted 2 lines
drivers/spi/spi-core.c new file +2
-0+while (!kthread_should_stop ()) { +
^^^^^ superfluous blank line.
Quoted 1 line
drivers/spi/spi-core.c new file +1
-0+wait_event_interruptible (bd->queue,spi_thread_awake (bd));
[snip]
drivers/spi/spi-core.c line 349
Quoted 4 lines
drivers/spi/spi-core.c new file +4
-0+if ( bd->bus->set_clock && msg->clock ) + bd->bus->set_clock ( + msg->device->dev.parent, msg->clock ); + xfer_status = bd->bus->xfer ( msg );
if (bd->bus->set_clock && msg->clock) bd->bus->set_clock( <-- this line has trailing whitespace. msg->device->dev.parent, msg->clock); xfer_status = bd->bus->xfer(msg);
[snip]
Quoted 5 lines
+ *
spi_write
+ * send data to a device on an SPI bus
+ * Parameters:
+ * spi_device* dev the target device
+ * char* buf buffer to be sent
* spi_device *dev the target device
* char *buf buffer to be sent
[snip]
Review
Quoted 1 line
(quoted diff) +1
-0+ ret = spi_transfer( msg, NULL );
ret = spi_transfer(msg, NULL);
[snip]
Quoted 5 lines
+ *
spi_write
+ * receive data from a device on an SPI bus
+ * Parameters:
+ * spi_device* dev the target device
+ * char* buf buffer to be sent
* spi_device *dev the target device
* char *buf buffer to be sent
[snip]
drivers/spi/spi-core.c line 406
Quoted 6 lines
drivers/spi/spi-core.c new file +6
-0+int spi_read (struct spi_device *dev,char *buf,int len) +{ +int ret; +struct spimsg *msg =spimsg_alloc (dev,SPI_M_RD , len,NULL ); + + ret =spi_transfer ( msg,NULL );
ret = spi_transfer(msg, NULL);
[snip]
drivers/spi/spi-core.c line 414
Quoted 4 lines
drivers/spi/spi-core.c new file +4
-0+int spi_bus_populate (struct device *parent, +char *devices, +void (*callback) (struct device * bus, +struct spi_device * new_dev))
int spi_bus_populate(struct device *parent,
char *devices,
void (*callback)(struct device *bus,
struct spi_device *new_dev))
[snip]
drivers/spi/spi-core.c line 431
Quoted 13 lines
drivers/spi/spi-core.c new file +13
-0+while (devices[0 ]) { +dev_dbg (parent,"discovered new SPI device, name '%s'\n" , + devices); + new_device =kmalloc (sizeof (struct spi_device ),GFP_KERNEL ); +if (!new_device) { +break ; + } +if (spi_device_add (parent, new_device, devices)) { +break ; + } +if (callback) { +callback (parent, new_device); + }
if (!new_device) break; if (spi_device_add(parent, new_device, devices)) break; if (callback) callback(parent, new_device);
We usually don't use curly braces for if statements when the body of the if is only a single statement.
[snip]
Quoted 1 line
+int
__initspi_core_init( void )
int __init spi_core_init(void)
[snip]
Quoted 1 line
+++
linux-2.6.10/drivers/spi/spi-dev.c
[snip]
[snip]
drivers/spi/spi-dev.c line 51
Quoted 3 lines
drivers/spi/spi-dev.c new file +3
-0+#include <linux/init.h> +#include <asm/uaccess.h> +#include <linux/spi.h>
#include <linux/init.h>
#include <linux/spi.h>
#include <asm/uaccess.h>
conventionally, asm/ includes are placed last.
[snip]
drivers/spi/spi-dev.c line 63
Quoted 4 lines
drivers/spi/spi-dev.c new file +4
-0+static ssize_t spidev_read (struct file *file,char *buf,size_t count, +loff_t * offset); +static ssize_t spidev_write (struct file *file,const char *buf,size_t count, +loff_t * offset);
static ssize_t spidev_read(struct file *file, char *buf, size_t count,
loff_t *offset); static ssize_t spidev_write(struct file *file, const char *buf, size_t count, loff_t *offset);
[snip]
drivers/spi/spi-dev.c line 101
Quoted 7 lines
drivers/spi/spi-dev.c new file +7
-0+static int spidev_probe (struct device *dev) +{ +struct spidev_driver_data *drvdata; + + drvdata =kmalloc (sizeof (struct spidev_driver_data ),GFP_KERNEL ); +if ( !drvdata) { +dev_dbg ( dev,"allocating drvdata failed\n" );
if (!drvdata) {
dev_dbg(dev, "allocating drvdata failed\n");[snip]
drivers/spi/spi-dev.c line 113
Quoted 1 line
drivers/spi/spi-dev.c new file +1
-0+dev_dbg ( dev," added\n" );
dev_dbg(dev, " added\n");
[snip]
drivers/spi/spi-dev.c line 124
Quoted 8 lines
drivers/spi/spi-dev.c new file +8
-0+static int spidev_remove (struct device *dev) +{ +struct spidev_driver_data *drvdata; + + drvdata = (struct spidev_driver_data *)dev_get_drvdata (dev); +class_simple_device_remove (MKDEV (SPI_MAJOR , drvdata->minor)); +kfree (drvdata); +dev_dbg ( dev," removed\n" );
dev_dbg(dev, " removed\n");
[snip]
Review
Quoted 2 lines
(quoted diff) +2
-0+static ssize_t spidev_read(struct file *file, char *buf, size_t count, + loff_t * offset)
static ssize_t spidev_read(struct file *file, char *buf, size_t count,
loff_t *offset)
drivers/spi/spi-dev.c line 133
Quoted 4 lines
drivers/spi/spi-dev.c new file +4
-0+{ +struct spi_device *dev = (struct spi_device *)file->private_data; +if ( count >SPI_TRANSFER_MAX ) count =SPI_TRANSFER_MAX ; +return spi_read (dev, buf, count );
if (count > SPI_TRANSFER_MAX) count = SPI_TRANSFER_MAX; return spi_read(dev, buf, count);
[snip]
drivers/spi/spi-dev.c line 137
Quoted 2 lines
drivers/spi/spi-dev.c new file +2
-0+static ssize_t spidev_write (struct file *file,const char *buf,size_t count, +loff_t * offset)
static ssize_t spidev_write(struct file *file, const char *buf, size_t count,
loff_t *offset)
drivers/spi/spi-dev.c line 141
Quoted 4 lines
drivers/spi/spi-dev.c new file +4
-0+{ +struct spi_device *dev = (struct spi_device *)file->private_data; +if ( count >SPI_TRANSFER_MAX ) count =SPI_TRANSFER_MAX ; +return spi_write ( dev, buf, count );
if (count > SPI_TRANSFER_MAX) count = SPI_TRANSFER_MAX; return spi_write(dev, buf, count);
[snip]
drivers/spi/spi-dev.c line 156
Quoted 1 line
drivers/spi/spi-dev.c new file +1
-0+if (NULL == drvdata) {
if (drvdata == NULL) {debatable, but I believe the most common style is what I changed it to.
[snip]
Quoted 1 line
+++
linux-2.6.10/include/linux/spi.h
[snip]
Quoted 11 lines
+/*
+ *linux/include/linux/spi/spi.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.
+ *
+ * Derived froml3.hby Jamey Hicks
+ */
+
Quoted 1 line
+#ifndef
SPI_H
Blank line between end of comment and start of code at the top of file seems to be most common.
[snip]
include/linux/spi.h line 32
Quoted 9 lines
include/linux/spi.h new file +9
-0+struct spi_bus_data +{ +struct semaphore lock; +struct list_head msgs; +atomic_t exiting; +struct task_struct * thread; +wait_queue_head_t queue; +struct spi_device * selected_device; +struct spi_bus_driver * bus;
struct task_struct *thread; wait_queue_head_t queue; struct spi_device *selected_device; struct spi_bus_driver *bus;
[snip]
Quoted 1 line
+#define
TO_SPI_BUS_DRIVER(drv)container_of( drv, struct spi_bus_driver, driver )
#define TO_SPI_BUS_DRIVER(drv) container_of(drv, struct spi_bus_driver, driver)
include/linux/spi.h line 42
Quoted 7 lines
include/linux/spi.h new file +7
-0+struct spi_bus_driver +{ +int (*xfer)(struct spi_msg * msg ); +void (*select)(struct spi_device * dev ); +void (*deselect)(struct spi_device * dev ); +void (*set_clock)(struct device * bus_device,u32 clock_hz ); +struct device_driver driver;
int (*xfer)(struct spi_msg *msg); void (*select)(struct spi_device *dev); void (*deselect)(struct spi_device *dev); void (*set_clock)(struct device *bus_device, u32 clock_hz);
[snip]
Quoted 1 line
+#define
TO_SPI_DEV(device)container_of( device, struct spi_device, dev )
#define TO_SPI_DEV(device) container_of(device, struct spi_device, dev)
include/linux/spi.h line 48
Quoted 3 lines
include/linux/spi.h new file +3
-0+struct spi_device +{ +char name[BUS_ID_SIZE ];
char name[BUS_ID_SIZE];
[snip]
Quoted 1 line
+#define
TO_SPI_DRIVER(drv)container_of( drv, struct spi_driver, driver )
#define TO_SPI_DRIVER(drv) container_of(drv, struct spi_driver, driver)
include/linux/spi.h line 58
Quoted 6 lines
include/linux/spi.h new file +6
-0+struct spi_driver { +void * (*alloc)(size_t ,int ); +void (*free)(const void * ); +unsigned char * (*get_buffer)(struct spi_device *,void * ); +void (*release_buffer)(struct spi_device *,unsigned char *); +void (*control)(struct spi_device *,int mode,u32 ctl );
struct spi_driver {
void *(*alloc)(size_t, int);
void (*free)(const void *);
unsigned char *(*get_buffer)(struct spi_device *, void *);
void (*release_buffer)(struct spi_device *, unsigned char *);
void (*control)(struct spi_device *, int mode, u32 ctl);[snip]
Quoted 1 line
+#define
SPI_DEV_DRV( device )TO_SPI_DRIVER( (device)->dev.driver )
#define SPI_DEV_DRV(device) TO_SPI_DRIVER((device)->dev.driver)
include/linux/spi.h line 65
Quoted 3 lines
include/linux/spi.h new file +3
-0+ +#define spi_device_lock ( dev )/* down( dev->dev.sem ) */ +#define spi_device_unlock ( dev )/* up( dev->dev.sem ) */
#define spi_device_lock(dev) /* down(dev->dev.sem) */ #define spi_device_unlock(dev) /* up(dev->dev.sem) */
Quoted 5 lines
+/*
+ * structspi_msg
+ *
+ * This structure represent the SPI message internally. You should never use fields of this structure directly
+ * Please use corresponding functions to create/destroy/access fields
* This structure represent the SPI message internally.
* You should never use fields of this structure directly.
* Please use corresponding functions to create/destroy/access fields
[snip]
Quoted 4 lines
include/linux/spi.h new file +4
-0+struct spi_msg { +unsigned char flags; +#define SPI_M_RD 0x01 +#define SPI_M_WR 0x02/**< Write mode flag */
include/linux/spi.h line 87
Quoted 10 lines
include/linux/spi.h new file +10
-0+#define SPI_M_CSREL 0x04/**< CS release level at end of the frame */ +#define SPI_M_CS 0x08/**< CS active level at begining of frame ( default low ) */ +#define SPI_M_CPOL 0x10/**< Clock polarity */ +#define SPI_M_CPHA 0x20/**< Clock Phase */ +unsigned short len;/* msg length */ +unsigned long clock; +struct spi_device * device; +void *context; +struct list_head link; +void (*status)(struct spi_msg * msg,int code );
#define SPI_M_WR 0x02 /* Write mode flag */
#define SPI_M_CSREL 0x04 /* CS release level at end of the frame */
#define SPI_M_CS 0x08 /* CS active level at begining of frame (default low) */
#define SPI_M_CPOL 0x10 /* Clock polarity */
#define SPI_M_CPHA 0x20 /* Clock Phase */ unsigned short len; /* msg length */ unsigned long clock; struct spi_device *device; void *context; struct list_head link; void (*status)(struct spi_msg *msg, int code);
[snip]
include/linux/spi.h line 95
Quoted 4 lines
include/linux/spi.h new file +4
-0+static inline struct spi_msg *spimsg_alloc (struct spi_device * device, +unsigned flags, +unsigned short len, +void (*status)(struct spi_msg *,int code ) )
static inline struct spi_msg* spimsg_alloc( struct spi_device* device,
unsigned flags, unsigned short len,
void (*status)(struct spi_msg *, int code))
include/linux/spi.h line 103
Quoted 8 lines
include/linux/spi.h new file +8
-0+{ +struct spi_msg * msg; +struct spi_driver * drv =SPI_DEV_DRV ( device ); + + msg =kmalloc (sizeof (struct spi_msg ),GFP_KERNEL ); +if ( !msg ) +return NULL ; +memset ( msg,0 ,sizeof (struct spi_msg ) );
struct spi_msg *msg;
struct spi_driver *drv = SPI_DEV_DRV(device);
msg = kmalloc(sizeof(struct spi_msg), GFP_KERNEL);
if (!msg)
return NULL;
memset(msg, 0, sizeof(struct spi_msg));In addition to the spacing changes you also seem to be using spaces for indentation here instead of tabs. Please use only tabs for indentation - this is true for other locations in the file as well, but I'm only mentioning it once here.
[snip]
include/linux/spi.h line 114
Quoted 7 lines
include/linux/spi.h new file +7
-0+INIT_LIST_HEAD ( &msg->link ); +if ( flags &SPI_M_RD ) { + msg->devbuf_rd = drv->alloc ? + drv->alloc ( len,GFP_KERNEL ):kmalloc ( len,GFP_KERNEL ); + msg->databuf_rd = drv->get_buffer ? + drv->get_buffer ( device, msg->devbuf_rd ) : msg->devbuf_rd; + }
INIT_LIST_HEAD(&msg->link);
if (flags & SPI_M_RD) {
msg->devbuf_rd = drv->alloc ?
drv->alloc(len, GFP_KERNEL) : kmalloc(len, GFP_KERNEL);
msg->databuf_rd = drv->get_buffer ?
drv->get_buffer(device, msg->devbuf_rd) : msg->devbuf_rd;
}include/linux/spi.h line 120
Quoted 6 lines
include/linux/spi.h new file +6
-0+if ( flags &SPI_M_WR ) { + msg->devbuf_wr = drv->alloc ? + drv->alloc ( len,GFP_KERNEL ):kmalloc ( len,GFP_KERNEL ); + msg->databuf_wr = drv->get_buffer ? + drv->get_buffer ( device, msg->devbuf_wr ) : msg->devbuf_wr; + }
if (flags & SPI_M_WR) {
msg->devbuf_wr = drv->alloc ?
drv->alloc(len, GFP_KERNEL) :
kmalloc(len, GFP_KERNEL);
msg->databuf_wr = drv->get_buffer ?
drv->get_buffer(device, msg->devbuf_wr) :
msg->devbuf_wr;
}include/linux/spi.h line 127
Quoted 7 lines
include/linux/spi.h new file +7
-0+pr_debug ("%s: msg = %p, RD=(%p,%p) WR=(%p,%p). Actual flags = %s+%s\n" , + __FUNCTION__, + msg, + msg->devbuf_rd, msg->databuf_rd, + msg->devbuf_wr, msg->databuf_wr, + msg->flags &SPI_M_RD ?"RD" :"~rd" , + msg->flags &SPI_M_WR ?"WR" :"~wr" );
pr_debug("%s: msg = %p, RD=(%p,%p) WR=(%p,%p). Actual flags = %s+%s\n",
__FUNCTION__, msg, msg->devbuf_rd, msg->databuf_rd, msg->devbuf_wr, msg->databuf_wr, msg->flags & SPI_M_RD ? "RD" : "~rd", msg->flags & SPI_M_WR ? "WR" : "~wr");
[snip]
include/linux/spi.h line 134
Quoted 4 lines
include/linux/spi.h new file +4
-0+static inline void spimsg_free (struct spi_msg * msg ) +{ +void (*do_free)(const void * ) = kfree; +struct spi_driver * drv =SPI_DEV_DRV ( msg->device );
static inline void spimsg_free(struct spi_msg *msg)
{
void (*do_free)(const void *) = kfree;
struct spi_driver *drv = SPI_DEV_DRV(msg->device);Quoted 6 lines
include/linux/spi.h new file +6
-0+ +if ( msg ) { +if ( drv->free ) + do_free = drv->free; +if ( drv->release_buffer ) { +if ( msg->databuf_rd)
include/linux/spi.h line 150
Quoted 10 lines
include/linux/spi.h new file +10
-0+ drv->release_buffer ( msg->device, msg->databuf_rd ); +if ( msg->databuf_wr) + drv->release_buffer ( msg->device, msg->databuf_wr ); + } +if ( msg->devbuf_rd ) +do_free ( msg->devbuf_rd ); +if ( msg->devbuf_wr) +do_free ( msg->devbuf_wr ); +kfree ( msg ); + }
if (msg) {
if (drv->free)
do_free = drv->free;
if (drv->release_buffer) {
if (msg->databuf_rd)
drv->release_buffer(msg->device, msg->databuf_rd);
if (msg->databuf_wr)
drv->release_buffer( msg->device, msg->databuf_wr);
}
if (msg->devbuf_rd)
do_free( msg->devbuf_rd);
if (msg->devbuf_wr)
do_free( msg->devbuf_wr);
kfree(msg);
}[snip]
Quoted 1 line
+static inline u8*
spimsg_buffer_rd( struct spi_msg* msg )
static inline u8 *spimsg_buffer_rd(struct spi_msg *msg)
[snip]
Quoted 1 line
+static inline u8*
spimsg_buffer_wr( struct spi_msg* msg )
static inline u8 *spimsg_buffer_wr(struct spi_msg *msg)
[snip]
include/linux/spi.h line 172
Quoted 10 lines
include/linux/spi.h new file +10
-0+static inline u8 *spimsg_buffer (struct spi_msg * msg ) +{ +if ( !msg )return NULL ; +if ( ( msg->flags & (SPI_M_RD |SPI_M_WR ) ) == (SPI_M_RD |SPI_M_WR ) ) { +printk (KERN_ERR "%s: what buffer do you really want ?\n" , __FUNCTION__ ); +return NULL ; + } +if ( msg->flags &SPI_M_RD )return msg->databuf_rd; +if ( msg->flags &SPI_M_WR )return msg->databuf_wr; +}
static inline u8 *spimsg_buffer(struct spi_msg* msg)
{
if (!msg)
return NULL;
if ((msg->flags & (SPI_M_RD|SPI_M_WR)) == (SPI_M_RD|SPI_M_WR)) {
printk(KERN_ERR "%s: what buffer do you really want ?\n",
__FUNCTION__ );
return NULL;
}
if (msg->flags & SPI_M_RD)
return msg->databuf_rd;
if (msg->flags & SPI_M_WR)
return msg->databuf_wr;
}include/linux/spi.h line 179
Quoted 7 lines
include/linux/spi.h new file +7
-0+ +#define SPIMSG_OK 0x01 +#define SPIMSG_FAILED 0x80 +#define SPIMSG_STARTED 0x02 +#define SPIMSG_DONE 0x04 + +#define SPI_MAJOR 98
#define SPIMSG_OK 0x01
#define SPIMSG_FAILED 0x80
#define SPIMSG_STARTED 0x02
#define SPIMSG_DONE 0x04
#define SPI_MAJOR 98
It may not be obvious what change I made here, so I'll tell you. You were mixing spaces and tabs between the defined named and the value, I've changed it to only use a single tab (it still lines up nicely).
[snip]
include/linux/spi.h line 187
Quoted 4 lines
include/linux/spi.h new file +4
-0+static inline int spi_bus_driver_register (struct spi_bus_driver * bus_driver ) +{ +return driver_register ( &bus_driver->driver ); +}
static inline int spi_bus_driver_register(struct spi_bus_driver *bus_driver)
{
return driver_register(&bus_driver->driver);
}include/linux/spi.h line 191
Quoted 4 lines
include/linux/spi.h new file +4
-0+ +void spi_bus_driver_unregister (struct spi_bus_driver * ); +int spi_bus_driver_init (struct spi_bus_driver * driver,struct device * dev ); +int spi_device_add (struct device * parent,struct spi_device *,char * name );
void spi_bus_driver_unregister(struct spi_bus_driver *);
int spi_bus_driver_init(struct spi_bus_driver * driver, struct device *dev); int spi_device_add(struct device *parent, struct spi_device *, char *name);
include/linux/spi.h line 195
Quoted 4 lines
include/linux/spi.h new file +4
-0+static inline void spi_device_del (struct spi_device * dev ) +{ +device_unregister ( &dev->dev ); +}
static inline void spi_device_del(struct spi_device *dev)
{
device_unregister(&dev->dev);
}include/linux/spi.h line 199
Quoted 4 lines
include/linux/spi.h new file +4
-0+static inline int spi_driver_add (struct spi_driver * drv ) +{ +return driver_register ( &drv->driver ); +}
static inline int spi_driver_add(struct spi_driver *drv)
{
return driver_register(&drv->driver);
}include/linux/spi.h line 203
Quoted 4 lines
include/linux/spi.h new file +4
-0+static inline void spi_driver_del (struct spi_driver * drv ) +{ +driver_unregister ( &drv->driver ); +}
static inline void spi_driver_del(struct spi_driver *drv)
{
driver_unregister(&drv->driver);
}[snip]
include/linux/spi.h line 212
Quoted 3 lines
include/linux/spi.h new file +3
-0+extern int spi_queue (struct spi_msg * message ); +extern int spi_transfer (struct spi_msg * message,void (*status)(struct spi_msg *,int ) ); +extern int spi_bus_populate (struct device * parent,char * device,void (*assign)(struct device * parent,struct spi_device * ) );
extern int spi_queue(struct spi_msg* message);
extern int spi_transfer(struct spi_msg *message,
void (*status)(struct spi_msg *, int)); extern int spi_bus_populate(struct device *parent, char *device, void (*assign)(struct device *parent, struct spi_device *));
include/linux/spi.h line 214
Quoted 2 lines
include/linux/spi.h new file +2
-0+ +#endif /* SPI_H */
#endif /* SPI_H */
Signature · 1 line
Jesper Juhl <[email protected]>
Quoted 5 lines · dmitry pervushin
drivers/spi/spi-core.c new file +5
-0+/* +* spi_device_release +* +* Pointer to this function will be put to dev->release place +* This function gets called as a part of device removing
drivers/spi/spi-core.c line 153
Quoted 10 lines
drivers/spi/spi-core.c new file +10
-0+* +* Parameters: +* struct device* dev +* Return value: +* none +*/ +void spi_device_release (struct device * dev ) +{ +/* just a placeholder */ +}
This is ALWAYS wrong, please fix your code. See the many times I have been over this issue in the archives.
Also, please fix your coding style to match the kernel if you wish to have a chance to get it included. :)
thanks,
greg k-h
Quoted 2 lines · Greg KH
This is ALWAYS wrong, please fix your code. See the many times I have been over this issue in the archives.
Do you mean this comment ? The spi_device_release does nothing, just to prevent compains from device_release function :)
Quoted 3 lines
Also, please fix your coding style to match the kernel if you wish to have a chance to get it included. :)
Hmm... running Lindent... done. Thank you once more, for your valuable comments :)
Quoted 5 lines · dmitry pervushin
Quoted 2 lines · Greg KH
This is ALWAYS wrong, please fix your code. See the many times I have been over this issue in the archives.
Do you mean this comment ? The
spi_device_releasedoes nothing, just to prevent compains fromdevice_releasefunction :)
Think about why the kernel complains about a non-existant release function. Just replacing that complaint with a function that does nothing does NOT solve the issue, it only makes the warning go away.
Please read up on how the lifetime rules work for devices, and what needs to happen in the release function (hint, take a look at other busses, like USB and PCI for examples of what needs to be done.)
thanks,
greg k-h
Quoted 3 lines · Greg KH
Please read up on how the lifetime rules work for devices, and what needs to happen in the release function (hint, take a look at other busses, like USB and PCI for examples of what needs to be done.)
As far as I can see, pci_release_device deletes the pci_dev using kfree. But here we have statically allocated spi_device structures -- spi_device_add does not allocate spi_device, but uses caller-allocated one.
Quoted 17 lines
thanks,
greg k-h
-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download it for free - -and be entered to win a 42" plasma tv or your very own Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
spi-devel-general mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/spi-devel-general
Quoted 5 lines · dmitry pervushin
Quoted 3 lines · Greg KH
Please read up on how the lifetime rules work for devices, and what needs to happen in the release function (hint, take a look at other busses, like USB and PCI for examples of what needs to be done.)
As far as I can see,
pci_release_devicedeletes thepci_devusing kfree.
Yes.
Quoted 3 lines
But here we have statically allocated
spi_devicestructures --spi_device_adddoes not allocatespi_device, but uses caller-allocated one.
Not good, reference counted structures almost always should be dynamically created. Please change this to also be true for SPI, otherwise you will have a lot of nasty issues with devices that can be removed at any point in time.
thanks,
greg k-h
Quoted 4 lines · Greg KH
Not good, reference counted structures almost always should be dynamically created. Please change this to also be true for SPI, otherwise you will have a lot of nasty issues with devices that can be removed at any point in time.
Hmm. I thought a bit about this and it seems reasonable. I'll change this to dynamic allocation.
Quoted 3 lines
thanks,
greg k-h
PATCH 1/1 SPI
In reply to Greg KHHello people,
Here is the revised SPI-core patch. Changes are as follows:
- spi_device_add now allocates and returns struct spi_device* instead of taking caller-allocated spi_device* as parameter;
- spi_device_release changed to deallocate spi_device* allocated by call to spi_device_add;
- new function spi_bus_populate2; it populates bus in the same manner as spi_bus_populate does, but parameter is array of struct spi_device_desc instead of string delimited by '\0's;
- code style fixes;
- documentation fixes.
-----------------8<- cut here ------------------------------------ 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 systems running Linux.
Documentation/spi.txt | 374 ++++++++++++++++++++++++++++++++++++ arch/arm/Kconfig | 2 drivers/Kconfig | 2 drivers/Makefile | 1 drivers/spi/Kconfig | 33 +++ drivers/spi/Makefile | 14 + drivers/spi/spi-core.c | 506 +++++++++++++++++++++++++++++++++++++++++++++++++ drivers/spi/spi-dev.c | 219 +++++++++++++++++++++ include/linux/spi.h | 232 ++++++++++++++++++++++
PATCH FOLLOWS
arch/arm/Kconfig +2 -0
@@ -834,6 +834,8 @@ source "drivers/ssi/Kconfig" source "drivers/mmc/Kconfig" +source "drivers/spi/Kconfig" + endmenu source "ktools/Kconfig"
drivers/Kconfig +2 -0
@@ -42,6 +42,8 @@ source "drivers/char/Kconfig" source "drivers/i2c/Kconfig" +source "drivers/spi/Kconfig" + source "drivers/w1/Kconfig" source "drivers/misc/Kconfig"
drivers/Makefile +1 -0
@@ -67,3 +67,4 @@ obj-$(CONFIG_DPM) += dpm/ obj-$(CONFIG_MMC) += mmc/ obj-y += firmware/ obj-$(CONFIG_EVENT_BROKER) += evb/ +obj-$(CONFIG_SPI) += spi/
drivers/spi/Kconfig new file +33 -0
@@ -0,0 +1,33 @@ +# +# SPI device configuration +# +menu "SPI support" + +config SPI + default Y + tristate "SPI (Serial Peripheral Interface) bus support" + default false + help + Say Y if you need to enable SPI support on your kernel. + Say M if you want to create the spi-core loadable module. + +config SPI_DEBUG + bool "SPI debug output" + depends on SPI + default false + help + Say Y there if you'd like to see debug output from SPI drivers + If unsure, say N + +config SPI_CHARDEV + default Y + tristate "SPI device interface" + depends on SPI + help + Say Y here to use /dev/spiNN device files. They make it possible to have user-space + programs use the SPI bus. + This support is also available as a module. If so, the module + will be called spi-dev. + +endmenu +
drivers/spi/Makefile new file +14 -0
@@ -0,0 +1,14 @@ +# +# Makefile for the kernel spi bus driver. +# + +obj-$(CONFIG_SPI) += spi-core.o +# bus drivers +# ...functional drivers +# ...and the common spi-dev driver +obj-$(CONFIG_SPI_CHARDEV) += spi-dev.o + +ifeq ($(CONFIG_SPI_DEBUG),y) +EXTRA_CFLAGS += -DDEBUG +endif +
drivers/spi/spi-core.c new file +506 -0
506 lines not on this page · raw message
drivers/spi/spi-dev.c new file +219 -0
219 lines not on this page · raw message
Documentation/spi.txt new file +374 -0
374 lines not on this page · raw message
include/linux/spi.h new file +232 -0
232 lines not on this page · raw message