SPI core
RFC 1/1 SPI core
Hello guys,
In order to support the specific board, we have ported the generic SPI core to the 2.6 kernel. This core provides basic API to create/manage SPI devices like the I2C core does. We need to continue providing support of SPI devices and would like to maintain the SPI subtree. It would be nice if SPI core patch were applied to the vanilla kernel. I2C people do not like to mainain this code as well as I2C, so...
KernelVersion: 2.6.12-rc4
PATCH FOLLOWS
drivers/spi/Kconfig +26 -0
@@ -0,0 +1,26 @@ +# +# Character device configuration +# + +menu "SPI support" + +config SPI + tristate "SPI support" + +config SPI_ALGOBIT + tristate "SPI bit-banging interfaces" + depends on SPI + +config SPI_CHARDEV + 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. Information on how to do this is + contained in the file <file:Documentation/spi/dev-interface>. + + This support is also available as a module. If so, the module + will be called spi-dev. + +endmenu
drivers/spi/Makefile +12 -0
@@ -0,0 +1,12 @@ +# +# Makefile for the kernel spi bus driver. +# + +# Init order: core, chardev, bit adapters, pcf adapters + +obj-$(CONFIG_SPI) += spi-core.o +obj-$(CONFIG_SPI_CHARDEV) += spi-dev.o + +# Bit adapters + +# PCF adapters
drivers/spi/spi-core.c +385 -0
385 lines not on this page · raw message
drivers/spi/spi-dev.c +514 -0
514 lines not on this page · raw message
include/linux/spi/spi.h +265 -0
265 lines not on this page · raw message
On Tue, 31 May 2005 20:09:16 +0400 dmitry pervushin wrote:
| Hello guys, | | In order to support the specific board, we have ported the generic SPI core to the 2.6 kernel. This core provides basic API to create/manage SPI devices like the I2C core does. We need to continue providing support of SPI devices and would like to maintain the SPI subtree. It would be nice if SPI core patch were applied to the vanilla kernel. | I2C people do not like to mainain this code as well as I2C, so... | | Signed-off-by: dmitry pervushin <[email protected]> | | KernelVersion: 2.6.12-rc4
Hi,
Are there more parts to the patch (other than "core")? E.g., the patch refers to some Documentation/spi/, but those parts are missing.
I was going to read that to see what SPI means.... so what does it mean?
Also, a diffstat summary would be nice to see:
drivers/spi/Kconfig | 26 ++ drivers/spi/Makefile | 12 + drivers/spi/spi-core.c | 385 +++++++++++++++++++++++++++++++++++ drivers/spi/spi-dev.c | 514 ++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/spi/spi.h | 266 ++++++++++++++++++++++++ 5 files changed, 1202 insertions(+), 1 deletion(-)
| diff -uNr -X dontdiff linux-2.6.12-rc4/drivers/spi/Makefile linux/drivers/spi/Makefile | --- linux-2.6.12-rc4/drivers/spi/Makefile 1970-01-01 03:00:00.000000000 +0300 | +++ linux/drivers/spi/Makefile 2005-05-31 19:59:01.000000000 +0400 | @@ -0,0 +1,12 @@ | +# | +# Makefile for the kernel spi bus driver.
Don't need such obvious comments.
| diff -uNr -X dontdiff linux-2.6.12-rc4/drivers/spi/spi-core.c linux/drivers/spi/spi-core.c | --- linux-2.6.12-rc4/drivers/spi/spi-core.c 1970-01-01 03:00:00.000000000 +0300 | +++ linux/drivers/spi/spi-core.c 2005-05-31 19:59:12.000000000 +0400 | @@ -0,0 +1,385 @@ | +#include <linux/module.h> | +#include <linux/config.h> | +#include <linux/kernel.h> | +#include <linux/errno.h> | +#include <linux/slab.h> | +#include <linux/device.h> | +#include <linux/proc_fs.h> | +#include <linux/kmod.h> | +#include <linux/init.h> | +#include <linux/spi/spi.h>
Please put those in alphabetical order as much as possible.
| +/** | + * spi_get_adapter - get a reference to an adapter | + * @id: driver id | + * | + * Obtain a spi_adapter structure for the specified adapter. If the adapter | + * is not currently load, then load it. The adapter will be locked in core
loaded
| + * until all references are released via spi_put_adapter.
| + */
| +struct spi_adapter *spi_get_adapter(int id)
| +{
| + struct list_head *item;
| + struct spi_adapter *adapter;
| +
| + down(&adapter_lock);
| + list_for_each(item, &adapter_list) {
| + adapter = list_entry(item, struct spi_adapter, adapters);
| + if (id == adapter->nr && try_module_get(adapter->owner)) {
| + up(&adapter_lock);
| + return adapter;
| + }
| + }
| + up(&adapter_lock);
| + return NULL;
| +
| +}
| +
| +/**
| + * spi_get_driver - get a reference to a driver
| + * @name: driver name
| + *
| + * Obtain a spi_driver structure for the specified driver. If the driver is
| + * not currently load, then load it. The driver will be locked in coreloaded
| + * until all references are released via spi_put_driver. | + */
| +/** | + * spi_detach_client - detach a client from an adapter and driver | + * @client: client structure to detach | + * | + * Detach the client from the adapter and driver.
* Returns 0
| diff -uNr -X dontdiff linux-2.6.12-rc4/drivers/spi/spi-dev.c linux/drivers/spi/spi-dev.c | --- linux-2.6.12-rc4/drivers/spi/spi-dev.c 1970-01-01 03:00:00.000000000 +0300 | +++ linux/drivers/spi/spi-dev.c 2005-05-31 19:59:18.000000000 +0400 | @@ -0,0 +1,514 @@ | + | +#include <linux/init.h> | +#include <linux/config.h> | +#include <linux/kernel.h> | +#include <linux/module.h> | +#include <linux/device.h> | +#include <linux/fs.h> | +#include <linux/slab.h> | +#include <linux/version.h> | +#include <linux/smp_lock.h>
Alpha order as much as possible, please.
| +#ifdef CONFIG_DEVFS_FS | +#include <linux/devfs_fs_kernel.h> | +#endif
Shouldn't need to surround #includes with #ifdef/#endif.
| +#include <linux/init.h> | +#include <asm/uaccess.h> | +#include <linux/spi/spi.h> | + | +#define SPI_TRANSFER_MAX 65535 | +#define SPI_ADAP_MAX 32
What is SPI_ADAP_MAX used for? It's not used in the core patch at all. And it's #defined in 2 places, should just be put into a header file and #included if it's needed at all. Oh, it's in spi.h, so it's not needed here.
| +extern struct spi_adapter *spi_get_adapter(int id); /* spi-core.c ? */
| +extern void spi_put_adapter(struct spi_adapter *);
These should be declared in some header file, please.
| +/* struct file_operations changed too often in the 2.1 series for nice code */
Does that comment need to be here?
| +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 int spidev_open(struct inode *inode, struct file *file);
| +static int spidev_release(struct inode *inode, struct file *file);
| +static int spidev_ioctl(struct inode *inode, struct file *file,
| + unsigned int cmd, unsigned long arg);
| +static int spidev_attach_adapter(struct spi_adapter *);
| +static int spidev_detach_adapter(struct spi_adapter *);
| +static int __init spi_dev_init(void);
| +static void spidev_cleanup(void);
| +
| +static struct file_operations spidev_fops = {
| + owner:THIS_MODULE,
| + llseek:no_llseek,
| + read:spidev_read,
| + write:spidev_write,
| + open:spidev_open,
| + release:spidev_release,
| + ioctl:spidev_ioctl,
| +};Please use C99-style initializers and align the init values so that it is more readable.
| +static struct spi_driver spidev_driver = {
| + name:"spi",
| + attach_adapter:spidev_attach_adapter,
| + detach_adapter:spidev_detach_adapter,
| + owner:THIS_MODULE,
| +};ditto
| +static struct spi_client spidev_client_template = {
| + driver:&spidev_driver
| +};ditto
| +struct spi_dev {
| + int minor;
| + struct spi_adapter *adap;
| + struct class_device class_dev;
| + struct completion released; /* FIXME, we need a class_device_unregister() */
| +};| +struct spi_dev *spi_dev_get_by_minor(unsigned index)
| +{
| + struct spi_dev *spi_dev;
| +
| + spin_lock(&spi_dev_array_lock);
| + spi_dev = spi_dev_array[index];
| + spin_unlock(&spi_dev_array_lock);
| + return spi_dev;
| +}Should this increment a reference count?
| +struct spi_dev *spi_dev_get_by_adapter(struct spi_adapter *adap)
| +{
| + struct spi_dev *spi_dev = NULL;
| +
| + spin_lock(&spi_dev_array_lock);
| + if ((spi_dev_array[adap->nr]) &&
| + (spi_dev_array[adap->nr]->adap == adap))
| + spi_dev = spi_dev_array[adap->nr];
| + spin_unlock(&spi_dev_array_lock);
| + return spi_dev;
| +}same question.
| +static void return_spi_dev(struct spi_dev *spi_dev)
| +{
| + spin_lock(&spi_dev_array_lock);
| + spi_dev_array[spi_dev->minor] = NULL;
| + spin_unlock(&spi_dev_array_lock);
| +}same question (with decrement)
| +static int spidev_ioctl(struct inode *inode, struct file *file,
| + unsigned int cmd, unsigned long arg)
| +{
| + struct spi_client *client = (struct spi_client *)file->private_data;
| + struct spi_rdwr_ioctl_data rdwr_arg;
| + struct spi_msg *rdwr_pa;
| + int res, i;
| + unsigned long (*cpy_to_user) (void *to_user, const void *from,
| + unsigned long len);
| + unsigned long (*cpy_from_user) (void *to, const void *from_user,
| + unsigned long len);
| + void *(*alloc) (size_t, int);
| + void (*free) (const void *);
| +
| + cpy_to_user =
| + client->adapter->copy_to_user ? client->adapter->
| + copy_to_user : copy_to_user;
| + cpy_from_user =
| + client->adapter->copy_from_user ? client->adapter->
| + copy_from_user : copy_from_user;
| + alloc = client->adapter->alloc ? client->adapter->alloc : kmalloc;
| + free = client->adapter->free ? client->adapter->free : kfree;
| +
| + switch (cmd) {
| + case SPI_RDWR:
| + if (copy_from_user(&rdwr_arg,
| + (struct spi_rdwr_ioctl_data *)arg,
| + sizeof(rdwr_arg)))
| + return -EFAULT;
| +
| + rdwr_pa = (struct spi_msg *)
| + kmalloc(rdwr_arg.nmsgs * sizeof(struct spi_msg),
| + GFP_KERNEL);
| +
| + if (rdwr_pa == NULL)
| + return -ENOMEM;
| +
| + res = 0;
| + for (i = 0; i < rdwr_arg.nmsgs; i++) {
| + if (copy_from_user(&(rdwr_pa[i]),
| + &(rdwr_arg.msgs[i]),
| + sizeof(rdwr_pa[i]))) {
| + res = -EFAULT;
| + break;
| + }
| + rdwr_pa[i].buf = alloc(rdwr_pa[i].len, GFP_KERNEL);
| + if (rdwr_pa[i].buf == NULL) {
| + res = -ENOMEM;
| + break;
| + }when do you user copy_from_user() vs. cpy_from_user() ?
| + if (cpy_from_user(rdwr_pa[i].buf,
| + rdwr_arg.msgs[i].buf,
| + rdwr_pa[i].len)) {
| + free(rdwr_pa[i].buf);
| + res = -EFAULT;
| + break;
| + }
| + }
| + if (!res) {
| + res = spi_transfer(client->adapter,
| + rdwr_pa, rdwr_arg.nmsgs);
| + }
| + while (i-- > 0) {
| + if (res >= 0 && (rdwr_pa[i].flags & SPI_M_RD))
| + if (cpy_to_user(rdwr_arg.msgs[i].buf,
| + rdwr_pa[i].buf,
| + rdwr_pa[i].len)) {
| + res = -EFAULT;
| + }
| + free(rdwr_pa[i].buf);
| + }
| + kfree(rdwr_pa);
| + return res;
| +
| + case SPI_CLK_RATE:
| + default:
| + break;
| + }
| +
| + return 0;
| +}
| +| +static ssize_t spidev_read(struct file *file, char *buf, size_t count,
| + loff_t * offset)
| +{
| + char *tmp;
| + int ret;
| +#ifdef SPIDEV_DEBUG
| + struct inode *inode = file->f_dentry->d_inode;
| +#endif
| +
| + struct spi_client *client = (struct spi_client *)file->private_data;
| + unsigned long (*cpy_to_user) (void *to_user, const void *from,
| + unsigned long len);
| + void *(*alloc) (size_t, int);
| + void (*free) (const void *);insert blank line here (at end of data), please.
| + if (count > SPI_TRANSFER_MAX) | + count = SPI_TRANSFER_MAX; | + | + cpy_to_user = | + client->adapter->copy_to_user ? client->adapter-> | + copy_to_user : copy_to_user; | + alloc = client->adapter->alloc ? client->adapter->alloc : kmalloc; | + free = client->adapter->free ? client->adapter->free : kfree; | + | + /* copy user space data to kernel space. */ | + tmp = alloc(count, GFP_KERNEL); | + if (tmp == NULL) | + return -ENOMEM; | + | + ret = spi_read(client, 0, tmp, count); | + if (ret >= 0) | + ret = cpy_to_user(buf, tmp, count) ? -EFAULT : ret; | + free(tmp); | + return ret; | +}
| +int spidev_open(struct inode *inode, struct file *file) Can't this be static?
| +{
---
~Randy
drivers/spi/spi-dev.c line 53
Quoted 8 lines · dmitry pervushin
In order to support the specific board, we have ported the generic SPI core to the 2.6 kernel. This core provides basic API to create/manage SPI devices like the I2C core does. We need to continue providing support of SPI devices and would like to maintain the SPI subtree.
drivers/spi/spi-dev.c +3
-0+#ifdef CONFIG_DEVFS_FS +#include <linux/devfs_fs_kernel.h> +#endif
devfs will be removed from mainline in a month.
SPI is serial-peripheral interface. A very common 3 wire bus in embedded systems, especially m68k arch's. That fact that it's not there already is actually a little weird IMHO.
NZG.
Quoted 16 lines · Alexey Dobriyan
drivers/spi/spi-dev.c line 53
Quoted 8 lines · dmitry pervushin
In order to support the specific board, we have ported the generic SPI core to the 2.6 kernel. This core provides basic API to create/manage SPI devices like the I2C core does. We need to continue providing support of SPI devices and would like to maintain the SPI subtree.
drivers/spi/spi-dev.c +3
-0+#ifdef CONFIG_DEVFS_FS +#include <linux/devfs_fs_kernel.h> +#endif devfs will be removed from mainline in a month.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Quoted 11 lines · Alexey Dobriyan
drivers/spi/spi-dev.c line 53
Quoted 8 lines · dmitry pervushin
In order to support the specific board, we have ported the generic SPI core to the 2.6 kernel. This core provides basic API to create/manage SPI devices like the I2C core does. We need to continue providing support of SPI devices and would like to maintain the SPI subtree.
drivers/spi/spi-dev.c +3
-0+#ifdef CONFIG_DEVFS_FS +#include <linux/devfs_fs_kernel.h> +#endif devfs will be removed from mainline in a month.
True, but the #ifdef should never be there in the first place...
thanks,
greg k-h
Quoted 8 lines · dmitry pervushin
Hello guys,
In order to support the specific board, we have ported the generic SPI core to the 2.6 kernel. This core provides basic API to create/manage SPI devices like the I2C core does. We need to continue providing support of SPI devices and would like to maintain the SPI subtree. It would be nice if SPI core patch were applied to the vanilla kernel. I2C people do not like to mainain this code as well as I2C, so...
What do you mean by this? Which i2c people?
Is this code intergrated into the driver model?
What does the /sys/ tree look like?
Why are you using a char device node?
Quoted 8 lines
+/**
+ *spi_add_adapter- register a new SPI bus adapter
+ * @adap:spi_adapterstructure for the registering adapter
+ *
+ * Make the adapter available for use by clients using nameadap->name.
+ * Theadap->adapterslist is initialised by this function.
+ *
+ * Returns 0;
You have this a lot. If the function can not fail, just make it a void type :)
drivers/spi/spi-core.c line 51
Quoted 11 lines
drivers/spi/spi-core.c +11
-0+int spi_add_adapter (struct spi_adapter *adap) +{ +struct list_head *l; + +INIT_LIST_HEAD (&adap->clients); +down (&adapter_lock); +init_MUTEX (&adap->lock); +list_add (&adap->adapters, &adapter_list); +up (&adapter_lock); + +list_for_each (l, &driver_list) {
list_for_each_entry() please.
Quoted 52 lines
drivers/spi/spi-core.c +52
-0+struct spi_driver *drv = + list_entry(l, struct spi_driver, drivers); + +if (drv->attach_adapter) + drv->attach_adapter (adap); + } + +return 0 ; +} + +/** +* spi_del_adapter - unregister a SPI bus adapter +* @adap: spi_adapter structure to unregister +* +* Remove an adapter from the list of available SPI Bus adapters. +* +* Returns 0; +*/ +int spi_del_adapter (struct spi_adapter *adap) +{ +struct list_head *l; + +down (&adapter_lock); +list_del (&adap->adapters); +up (&adapter_lock); + +list_for_each (l, &driver_list) { +struct spi_driver *drv = + list_entry(l, struct spi_driver, drivers); + +if (drv->detach_adapter) + drv->detach_adapter (adap); + } + +return 0 ; +} + +/** +* spi_get_adapter - get a reference to an adapter +* @id: driver id +* +* Obtain a spi_adapter structure for the specified adapter. If the adapter +* is not currently load, then load it. The adapter will be locked in core +* until all references are released via spi_put_adapter. +*/ +struct spi_adapter *spi_get_adapter (int id) +{ +struct list_head *item; +struct spi_adapter *adapter; + +down (&adapter_lock); +list_for_each (item, &adapter_list) {
drivers/spi/spi-core.c line 113
Quoted 10 lines
drivers/spi/spi-core.c +10
-0+ adapter = list_entry(item, struct spi_adapter, adapters); +if (id == adapter->nr &&try_module_get (adapter->owner)) { +up (&adapter_lock); +return adapter; + } + } +up (&adapter_lock); +return NULL ; + +}
Hm, that comment is not correct. Please fix it as nothing is "loaded".
Quoted 5 lines
drivers/spi/spi-core.c +5
-0+/** +* spi_put_adapter - release a reference to an adapter +* @adap: driver to release reference +* +* Indicate to the SPI core that you no longer require the adapter reference.
drivers/spi/spi-core.c line 129
Quoted 10 lines
drivers/spi/spi-core.c +10
-0+* The adapter module may be unloaded when there are no references to its +* data structure. +* +* You must not use the reference after calling this function. +*/ +void spi_put_adapter (struct spi_adapter *adap) +{ +if (adap && adap->owner) +module_put (adap->owner); +}
Then why not use the traditional kref style of reference counting? That ensures that if you try to use the reference, bad things will happen? Right now all you are doing is relying on module references, and you aren't cleaning up the memory.
Quoted 6 lines
drivers/spi/spi-core.c +6
-0+EXPORT_SYMBOL (spi_add_adapter); +EXPORT_SYMBOL (spi_del_adapter); +EXPORT_SYMBOL (spi_get_adapter); +EXPORT_SYMBOL (spi_put_adapter); + +EXPORT_SYMBOL (spi_add_driver);
drivers/spi/spi-core.c line 385
Quoted 10 lines
drivers/spi/spi-core.c +10
-0+EXPORT_SYMBOL (spi_del_driver); +EXPORT_SYMBOL (spi_get_driver); +EXPORT_SYMBOL (spi_put_driver); + +EXPORT_SYMBOL (spi_attach_client); +EXPORT_SYMBOL (spi_detach_client); + +EXPORT_SYMBOL (spi_transfer); +EXPORT_SYMBOL (spi_write); +EXPORT_SYMBOL (spi_read);
EXPORT_SYMBOL_GPL() perhaps?
drivers/spi/spi-dev.c line 56
Quoted 2 lines
drivers/spi/spi-dev.c +2
-0+/* Define SPIDEV_DEBUG for debugging info */ +#undef SPIDEV_DEBUG
Use a Kconfig entry instead.
drivers/spi/spi-dev.c line 62
Quoted 5 lines
drivers/spi/spi-dev.c +5
-0+#ifdef SPIDEV_DEBUG +#define DBG(args...) printk(KERN_INFO"spi-dev.o: " args) +#else +#define DBG(args...) +#endif
Please use dev_dbg() and friends instead of your own debugging macros. The error log people will thank you (along with your users...)
drivers/spi/spi-dev.c line 66
Quoted 3 lines
drivers/spi/spi-dev.c +3
-0+#include <linux/init.h> +#include <asm/uaccess.h> +#include <linux/spi/spi.h>
Why a separate subdir for spi.h?
drivers/spi/spi-dev.c line 195
Quoted 2 lines
drivers/spi/spi-dev.c +2
-0+static int spidev_ioctl (struct inode *inode,struct file *file, +unsigned int cmd,unsigned long arg)
Ick, please do NOT add new ioctls to the kernel. Especially one as complex and hard to audit as this one :(
The i2c dev interface is a mess, please don't duplicate it, there is no need to do so.
Also, please run the code through sparse, I think it will spit out a lot of errors here.
drivers/spi/spi-dev.c line 302
Quoted 13 lines
drivers/spi/spi-dev.c +13
-0+static int spidev_attach_adapter (struct spi_adapter *adap) +{ +struct spi_dev *spi_dev; +int retval; + + spi_dev =get_free_spi_dev (adap); +if (IS_ERR (spi_dev)) +return PTR_ERR (spi_dev); + +#if defined(CONFIG_DEVFS_FS ) +devfs_mk_cdev (MKDEV (SPI_MAJOR , spi_dev->minor), +S_IFCHR |S_IRUSR |S_IWUSR ,"spi/%d" , spi_dev->minor); +#endif
No #if needed. You do this a lot.
include/linux/spi/spi.h line 60
Quoted 6 lines
include/linux/spi/spi.h +6
-0+/* +* A driver is capable of handling one or more physical devices present on +* SPI adapters. This information is used to inform the driver of adapter +* events. +*/ +struct spi_driver {
Please use the driver model code. That's what it is there for.
include/linux/spi/spi.h line 123
Quoted 5 lines
include/linux/spi/spi.h +5
-0+/* +* spi_adapter is the structure used to identify a physical SPI bus along +* with the access algorithms necessary to access it. +*/ +struct spi_adapter {
<snip> Ick, don't copy the mess I did in the i2c core for i2c adapter structures please. It was a hack then, and I regret it still. Please fix it up properly.
This code is _very_ close to just a copy of the i2c core code. Why duplicate it and not work with the i2c people instead?
thanks,
greg k-h
Hi Greg, Dmitry:
Quoted 7 lines · dmitry pervushin
Quoted 6 lines
In order to support the specific board, we have ported the generic SPI core to the 2.6 kernel. This core provides basic API to create/manage SPI devices like the I2C core does. We need to continue providing support of SPI devices and would like to maintain the SPI subtree. It would be nice if SPI core patch were applied to the vanilla kernel. I2C people do not like to mainain this code as well as I2C, so...
Quoted 1 line · Greg KH
What do you mean by this? Which i2c people?
(...)
Quoted 2 lines · Greg KH
This code is _very_ close to just a copy of the i2c core code. Why duplicate it and not work with the i2c people instead?
It was discussed briefly on the lm-sensors mailing list [1]. I didn't reply at the time, but I do agree that SPI and I2C/SMBus are different enough to warrant independent subsystems.
[1] http://lists.lm-sensors.org/pipermail/lm-sensors/2005-May/012385.html
Regards,
Signature · 2 lines
Mark M. Hoffman [email protected]
Quoted 7 lines · Mark M. Hoffman
Quoted 2 lines · Greg KH
This code is _very_ close to just a copy of the i2c core code. Why duplicate it and not work with the i2c people instead?
It was discussed briefly on the lm-sensors mailing list [1]. I didn't reply at the time, but I do agree that SPI and I2C/SMBus are different enough to warrant independent subsystems.
Independant is fine. But direct copies, including making the same mistakes (i2c dev interface, i2c driver model mess) isn't :)
thanks,
greg k-h
Hi Greg,
Quoted 11 lines · Greg KH
Quoted 7 lines · Mark M. Hoffman
Quoted 2 lines · Greg KH
This code is _very_ close to just a copy of the i2c core code. Why duplicate it and not work with the i2c people instead?
It was discussed briefly on the lm-sensors mailing list [1]. I didn't reply at the time, but I do agree that SPI and I2C/SMBus are different enough to warrant independent subsystems.
Independant is fine. But direct copies, including making the same mistakes (i2c dev interface, i2c driver model mess) isn't :)
I have also worked on a(nother) SPI layer implementation. Like Dmitry, I ended up following closely the i2c implementation, so, I'm curious to know more details on what you call "i2c driver model mess".
Quoted 3 lines
thanks,
greg k-h
Thanks,
Rui
Quoted 12 lines · Rui Sousa
Hi Greg,
Quoted 9 lines · Greg KH
Quoted 7 lines · Mark M. Hoffman
Quoted 2 lines · Greg KH
This code is _very_ close to just a copy of the i2c core code. Why duplicate it and not work with the i2c people instead?
It was discussed briefly on the lm-sensors mailing list [1]. I didn't reply at the time, but I do agree that SPI and I2C/SMBus are different enough to warrant independent subsystems.
Quoted 6 lines
Quoted 2 lines
Independant is fine. But direct copies, including making the same mistakes (i2c dev interface, i2c driver model mess) isn't :)
I have also worked on a(nother) SPI layer implementation. Like Dmitry, I ended up following closely the i2c implementation, so, I'm curious to know more details on what you call "i2c driver model mess".
The fact that the i2c drivers are not really true "drivers" in the driver model. We bind them by hand to the device and then register the device with the core. That isn't a nice thing to do...
Also the sysfs representation of the sensor stuff is tied to the i2c sysfs code very tightly, which isn't good for other types of sensors. It should be in the class portion of sysfs, and the recent hwmon patches are moving it in that direction.
thanks,
greg k-h
Quoted 4 lines · Greg KH
The fact that the i2c drivers are not really true "drivers" in the driver model. We bind them by hand to the device and then register the device with the core. That isn't a nice thing to do...
And introduces alot of code do simple stuff that SPI is supposed to do. I also ported i2c-core,i2c-dev, i2c-bit-algo and parport bus to work with SPI device. Resulting SPI code base was huge and I was confused in the begining why, and later wondered if there is need for such a design.
I dumped evrything and created three functions : spi_access, spi_transfer and spi_release. First and last functions only assert/deassert CS line, respectevely. Spi_transfer is the core function and is more-or-less different on every CPU (if not using bit-banging). As every CPU has different approach in handling SPI interface is almost neccesary to write CPU dependent SPI part for each CPU out there (at least transfer function). Also you can use CPUs synchronous serial interface (if one supports it) or just use bit-bang algo to get bits in and out.
I have two devices on SPI and I drive them both by bit-banging bits in and out. While I was using I2C-like-SPI model I wanted to make it base for all other SPI devices my board would/could hold. Sad thing is that every manufacturer and/or device (let it be serial flash, audio codec, A/D converter, ...) has its own concept of accessing and transfering data to and from the SPI device. I experienced this a short while ago while trying to make tsc2301 audio codec and datakey spi serial flash to use common SPI code. I ended up duplicating the three aforementioned functions in the each driver and still SPI code is ~10-15 times smaller than initial I2C-to-SPI port I did.
I would also like to see SPI core in linux driver model, but nothing like I2C stuff. SPI is far to simple (and yet so diverse) that much more simple concept could be used.
just my .2 €
regards,
hinko k
Signature · 4 lines
..because under Linux "if something is possible in principle, then it is already implemented or somebody is working on it". --LKI
Quoted 5 lines · Hinko Kocevar
I would also like to see SPI core in linux driver model, but nothing like I2C
stuff. SPI is far to simple (and yet so diverse) that much more simple concept
could be used.
Did you look at sound/i2c/i2c.c? ALSA has its own i2c implementation, only 333 lines, due to the kernel i2c core being overly complex for ALSA's needs.
"Although there is a standard i2c layer on Linux, ALSA has its own i2c codes for some cards, because the soundcard needs only a simple operation and the standard i2c API is too complicated for such a purpose."
(from http://www.alsa-project.org/~iwai/writing-an-alsa-driver/x77.htm)
Personally, I would start with this, then add any needed functionality.
Lee
On Tue, 2005-05-31 at 16:32 -0700, Greg KH wrote:
Thanks for you comments; my answers follow. This patch will be reworked in short time.
Quoted 1 line
Is this code intergrated into the driver model?
It will be.
Quoted 2 lines
What does the
/sys/tree look like?
Why are you using a char device node?
Because it's not a block device :) I assume that's common practice to access low-level devices, isn't it ?
Quoted 10 lines
Quoted 9 lines
+/**
+ *spi_add_adapter- register a new SPI bus adapter
+ * @adap:spi_adapterstructure for the registering adapter
+ *
+ * Make the adapter available for use by clients using nameadap->name.
+ * Theadap->adapterslist is initialised by this function.
+ *
+ * Returns 0;
Quoted 2 lines
You have this a lot. If the function can not fail, just make it a void type :)
I'd like to keep this of type int because of possible future enhancements
Quoted 3 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ list_for_each(l, &driver_list) {
list_for_each_entry()please.
Looks reasonable, thank you
Quoted 11 lines
Quoted 9 lines
+/**
+ *spi_get_adapter- get a reference to an adapter
+ * @id: driver id
+ *
+ * Obtain aspi_adapterstructure for the specified adapter. If the adapter
+ * is not currently load, then load it. The adapter will be locked in core
+ * until all references are released viaspi_put_adapter.
+ */Hm, that comment is not correct. Please fix it as nothing is "loaded".
OK
Quoted 10 lines
drivers/spi/spi-core.c line 129
Quoted 5 lines
drivers/spi/spi-core.c +5
-0+void spi_put_adapter (struct spi_adapter *adap) +{ +if (adap && adap->owner) +module_put (adap->owner); +}Then why not use the traditional kref style of reference counting? That ensures that if you try to use the reference, bad things will happen? Right now all you are doing is relying on module references, and you aren't cleaning up the memory.
I'll consider this during rework
Quoted 5 lines
drivers/spi/spi-core.c line 385
Quoted 3 lines
drivers/spi/spi-core.c +3
-0+EXPORT_SYMBOL (spi_transfer); +EXPORT_SYMBOL (spi_write); +EXPORT_SYMBOL (spi_read);
EXPORT_SYMBOL_GPL()perhaps?
Yup.
Quoted 2 lines
Please use
dev_dbg()and friends instead of your own debugging macros. The error log people will thank you (along with your users...)
I'd rather use pr_debug
Quoted 3 lines
Quoted 1 line
+#include <
linux/spi/spi.h>Why a separate subdir for
spi.h?
Due to historical reasons :) And functional drivers can pput their public headers to separate directory.
Quoted 3 lines
drivers/spi/spi-dev.c line 195
Quoted 3 lines
drivers/spi/spi-dev.c +2
-0+static int spidev_ioctl (struct inode *inode,struct file *file, +unsigned int cmd,unsigned long arg)
This function will be removed, because its functionality is duplicated by spidev_read/spidev_write.
Quoted 7 lines
Quoted 7 lines
drivers/spi/spi-dev.c +7
-0+static int spidev_attach_adapter (struct spi_adapter *adap) +{ +struct spi_dev *spi_dev; +int retval; + + spi_dev =get_free_spi_dev (adap); +if (IS_ERR (spi_dev))
Quoted 8 lines
drivers/spi/spi-dev.c line 302
Quoted 6 lines
drivers/spi/spi-dev.c +6
-0+return PTR_ERR (spi_dev); + +#if defined(CONFIG_DEVFS_FS ) +devfs_mk_cdev (MKDEV (SPI_MAJOR , spi_dev->minor), +S_IFCHR |S_IRUSR |S_IWUSR ,"spi/%d" , spi_dev->minor); +#endif No #if needed. You do this a lot.
As devfs is going to become obsolete, maybe just drop all the devfs-related code?
Quoted 10 lines
include/linux/spi/spi.h line 123
Quoted 5 lines
include/linux/spi/spi.h +5
-0+/* +* spi_adapter is the structure used to identify a physical SPI bus along +* with the access algorithms necessary to access it. +*/ +struct spi_adapter {<snip> Ick, don't copy the mess I did in the i2c core for i2c adapter structures please. It was a hack then, and I regret it still. Please fix it up properly.
Quoted 2 lines
This code is _very_ close to just a copy of the i2c core code. Why duplicate it and not work with the i2c people instead?
Well, those two are both simple serial interfaces, so their similarity is just reflected in driver structures.
Hi,
Here are some coding style comments. Sorry for any duplicates, I read other comments only after I reviewed the patch.
Pekka
drivers/spi/spi-core.c line 47
Quoted 10 lines · dmitry pervushin
diff -uNr -X dontdiff
linux-2.6.12-rc4/drivers/spi/spi-core.clinux/drivers/spi/spi-core.cdrivers/spi/spi-core.c +7
-0+int spi_add_adapter (struct spi_adapter *adap) +{ +struct list_head *l; + +INIT_LIST_HEAD (&adap->clients); +down (&adapter_lock); +init_MUTEX (&adap->lock);
adapter_lock protects adapter_list, not adap. Therefore, please move adap->lock initialization outside the critical region.
drivers/spi/spi-core.c line 107
Quoted 11 lines
drivers/spi/spi-core.c +11
-0+struct spi_adapter *spi_get_adapter (int id) +{ +struct list_head *item; +struct spi_adapter *adapter; + +down (&adapter_lock); +list_for_each (item, &adapter_list) { + adapter = list_entry(item, struct spi_adapter, adapters); +if (id == adapter->nr &&try_module_get (adapter->owner)) { +up (&adapter_lock); +return adapter;
One exit path please. You can use goto here.
Quoted 7 lines
drivers/spi/spi-core.c +7
-0+ +EXPORT_SYMBOL (spi_add_adapter); +EXPORT_SYMBOL (spi_del_adapter); +EXPORT_SYMBOL (spi_get_adapter); +EXPORT_SYMBOL (spi_put_adapter); + +EXPORT_SYMBOL (spi_add_driver);
drivers/spi/spi-core.c line 385
Quoted 10 lines
drivers/spi/spi-core.c +10
-0+EXPORT_SYMBOL (spi_del_driver); +EXPORT_SYMBOL (spi_get_driver); +EXPORT_SYMBOL (spi_put_driver); + +EXPORT_SYMBOL (spi_attach_client); +EXPORT_SYMBOL (spi_detach_client); + +EXPORT_SYMBOL (spi_transfer); +EXPORT_SYMBOL (spi_write); +EXPORT_SYMBOL (spi_read);
Preferred location for EXPORT_SYMBOLs is immediately after the function definition.
drivers/spi/spi-dev.c line 6
Quoted 10 lines
diff -uNr -X dontdiff
linux-2.6.12-rc4/drivers/spi/spi-dev.clinux/drivers/spi/spi-dev.cdrivers/spi/spi-dev.c +6
-0@@ -0,0 +1,514 @@ +#include <linux/init.h> +#include <asm/uaccess.h> +#include <linux/spi/spi.h> + +#define SPI_TRANSFER_MAX 65535 +#define SPI_ADAP_MAX 32
Unused define.
drivers/spi/spi-dev.c line 97
Quoted 8 lines
drivers/spi/spi-dev.c +8
-0+static struct file_operations spidev_fops = { + owner:THIS_MODULE , + llseek:no_llseek, + read:spidev_read, + write:spidev_write, + open:spidev_open, + release:spidev_release, + ioctl:spidev_ioctl,
Use C99 struct initializers.
drivers/spi/spi-dev.c line 104
Quoted 7 lines
drivers/spi/spi-dev.c +7
-0+}; + +static struct spi_driver spidev_driver = { + name:"spi" , + attach_adapter:spidev_attach_adapter, + detach_adapter:spidev_detach_adapter, + owner:THIS_MODULE ,
Ditto.
drivers/spi/spi-dev.c line 108
Quoted 4 lines
drivers/spi/spi-dev.c +4
-0+}; + +static struct spi_client spidev_client_template = { + driver:&spidev_driver
Same here.
drivers/spi/spi-dev.c line 153
Quoted 8 lines
drivers/spi/spi-dev.c +8
-0+static struct spi_dev *get_free_spi_dev (struct spi_adapter *adap) +{ +struct spi_dev *spi_dev; + + spi_dev =kmalloc (sizeof (*spi_dev),GFP_KERNEL ); +if (!spi_dev) +return ERR_PTR (-ENOMEM ); +memset (spi_dev,0x00 ,sizeof (*spi_dev));
See below.
drivers/spi/spi-dev.c line 157
Quoted 4 lines
drivers/spi/spi-dev.c +4
-0+ +spin_lock (&spi_dev_array_lock); +if (spi_dev_array[adap->nr]) { +spin_unlock (&spi_dev_array_lock);
One spin_unlock, please. Use gotos here.
drivers/spi/spi-dev.c line 162
Quoted 5 lines
drivers/spi/spi-dev.c +5
-0+dev_err (&adap->dev, +"spi-dev already has a device assigned to this adapter\n" ); + goto error; + } + spi_dev->minor = adap->nr;
Instead of memset() followed by assignment, you can use C99 struct initializers like this:
*spi_dev = (struct spi_dev) { .minor = adap->nr; };drivers/spi/spi-dev.c line 166
Quoted 4 lines
drivers/spi/spi-dev.c +4
-0+ spi_dev_array[adap->nr] = spi_dev; +spin_unlock (&spi_dev_array_lock); +return spi_dev; + error:
The placement of this label is strange.
drivers/spi/spi-dev.c line 197
Quoted 4 lines
drivers/spi/spi-dev.c +4
-0+static int spidev_ioctl (struct inode *inode,struct file *file, +unsigned int cmd,unsigned long arg) +{ +struct spi_client *client = (struct spi_client *)file->private_data;
Please remove the redundant cast.
drivers/spi/spi-dev.c line 206
Quoted 9 lines
drivers/spi/spi-dev.c +9
-0+struct spi_rdwr_ioctl_data rdwr_arg; +struct spi_msg *rdwr_pa; +int res, i; +unsigned long (*cpy_to_user) (void *to_user,const void *from, +unsigned long len); +unsigned long (*cpy_from_user) (void *to,const void *from_user, +unsigned long len); +void *(*alloc) (size_t ,int ); +void (*free) (const void *);
No type declarations within function body, please.
Quoted 13 lines
drivers/spi/spi-dev.c +13
-0+ +DBG ("spi-%d ioctl, cmd: 0x%x, arg: %lx.\n" , +MINOR (inode->i_rdev), cmd, arg); + + cpy_to_user = + client->adapter->copy_to_user ? client->adapter-> + copy_to_user : copy_to_user; + cpy_from_user = + client->adapter->copy_from_user ? client->adapter-> + copy_from_user : copy_from_user; + alloc = client->adapter->alloc ? client->adapter->alloc : kmalloc; + free = client->adapter->free ? client->adapter->free : kfree; +
drivers/spi/spi-dev.c line 229
Quoted 10 lines
drivers/spi/spi-dev.c +10
-0+switch (cmd) { +case SPI_RDWR : +if (copy_from_user (&rdwr_arg, + (struct spi_rdwr_ioctl_data *)arg, +sizeof (rdwr_arg))) +return -EFAULT ; + + rdwr_pa = (struct spi_msg *) +kmalloc (rdwr_arg.nmsgs *sizeof (struct spi_msg ), +GFP_KERNEL );
Redundant cast.
Quoted 21 lines
drivers/spi/spi-dev.c +21
-0+static int spidev_attach_adapter (struct spi_adapter *adap) +{ +struct spi_dev *spi_dev; +int retval; + + spi_dev =get_free_spi_dev (adap); +if (IS_ERR (spi_dev)) +return PTR_ERR (spi_dev); + +#if defined(CONFIG_DEVFS_FS ) +devfs_mk_cdev (MKDEV (SPI_MAJOR , spi_dev->minor), +S_IFCHR |S_IRUSR |S_IWUSR ,"spi/%d" , spi_dev->minor); +#endif +dev_dbg (&adap->dev,"Registered as minor %d\n" , spi_dev->minor); + +/* register this spi device with the driver core */ + spi_dev->adap = adap; +if (adap->dev.parent == &platform_bus) + spi_dev->class_dev.dev = &adap->dev; +else + spi_dev->class_dev.dev = adap->dev.parent;
drivers/spi/spi-dev.c line 320
Quoted 10 lines
drivers/spi/spi-dev.c +10
-0+ spi_dev->class_dev.class = &spi_dev_class; +snprintf (spi_dev->class_dev.class_id,BUS_ID_SIZE ,"spi-%d" , + spi_dev->minor); + retval =class_device_register (&spi_dev->class_dev); +if (retval) + goto error; +class_device_create_file (&spi_dev->class_dev, &class_device_attr_dev); +class_device_create_file (&spi_dev->class_dev, &class_device_attr_name); +return 0 ; + error:
The placement of this label is strange.
Quoted 4 lines
drivers/spi/spi-dev.c +4
-0+static ssize_t spidev_read (struct file *file,char *buf,size_t count, +loff_t * offset) +{ +char *tmp;
drivers/spi/spi-dev.c line 362
Quoted 10 lines
drivers/spi/spi-dev.c +10
-0+int ret; +#ifdef SPIDEV_DEBUG +struct inode *inode = file->f_dentry->d_inode; +#endif + +struct spi_client *client = (struct spi_client *)file->private_data; +unsigned long (*cpy_to_user) (void *to_user,const void *from, +unsigned long len); +void *(*alloc) (size_t ,int ); +void (*free) (const void *);
Please remove the duplicate function pointer type declarations.
drivers/spi/spi-dev.c line 370
Quoted 8 lines
drivers/spi/spi-dev.c +8
-0+if (count >SPI_TRANSFER_MAX ) + count =SPI_TRANSFER_MAX ; + + cpy_to_user = + client->adapter->copy_to_user ? client->adapter-> + copy_to_user : copy_to_user; + alloc = client->adapter->alloc ? client->adapter->alloc : kmalloc; + free = client->adapter->free ? client->adapter->free : kfree;
More duplicate code.
Quoted 18 lines
drivers/spi/spi-dev.c +18
-0+ +/* copy user space data to kernel space. */ + tmp =alloc (count,GFP_KERNEL ); +if (tmp ==NULL ) +return -ENOMEM ; + +DBG ("spi-%d reading %d bytes.\n" ,MINOR (inode->i_rdev), count); + + ret =spi_read (client,0 , tmp, count); +if (ret >=0 ) + ret =cpy_to_user (buf, tmp, count) ? -EFAULT : ret; +free (tmp); +return ret; +} + +static ssize_t spidev_write (struct file *file,const char *buf,size_t count, +loff_t * offset) +{
drivers/spi/spi-dev.c line 398
Quoted 10 lines
drivers/spi/spi-dev.c +10
-0+int ret; +char *tmp; +struct spi_client *client = (struct spi_client *)file->private_data; +#ifdef SPIDEV_DEBUG +struct inode *inode = file->f_dentry->d_inode; +#endif +unsigned long (*cpy_from_user) (void *to,const void *from_user, +unsigned long len); +void *(*alloc) (size_t ,int ); +void (*free) (const void *);
Aiie! Duplicates.
drivers/spi/spi-dev.c line 407
Quoted 9 lines
drivers/spi/spi-dev.c +9
-0+ +if (count >SPI_TRANSFER_MAX ) + count =SPI_TRANSFER_MAX ; + + cpy_from_user = + client->adapter->copy_from_user ? client->adapter-> + copy_from_user : copy_from_user; + alloc = client->adapter->alloc ? client->adapter->alloc : kmalloc; + free = client->adapter->free ? client->adapter->free : kfree;
More of the same.
Quoted 14 lines
drivers/spi/spi-dev.c +14
-0+int spidev_open (struct inode *inode,struct file *file) +{ +unsigned int minor =iminor (inode); +struct spi_client *client; +struct spi_adapter *adap; +struct spi_dev *spi_dev; + + spi_dev =spi_dev_get_by_minor (minor); +if (!spi_dev) +return -ENODEV ; + + adap =spi_get_adapter (spi_dev->adap->nr); +if (!adap) +return -ENODEV ;
drivers/spi/spi-dev.c line 448
Quoted 10 lines
drivers/spi/spi-dev.c +10
-0+ + client =kmalloc (sizeof (*client),GFP_KERNEL ); +if (!client) { +spi_put_adapter (adap); +return -ENOMEM ; + } +memcpy (client, &spidev_client_template,sizeof (*client)); + +/* registered with adapter, passed as client to user */ + client->adapter = adap;
Please use C99 struct initializer here.
Quoted 14 lines
drivers/spi/spi-dev.c +14
-0+static int __init spi_dev_init (void ) +{ +int res; + +printk (KERN_INFO "spi /dev entries driver\n" ); + + res =register_chrdev (SPI_MAJOR ,"spi" , &spidev_fops); +if (res) + goto out; + + res =class_register (&spi_dev_class); +if (res) + goto out_unreg_chrdev; +
drivers/spi/spi-dev.c line 489
Quoted 10 lines
drivers/spi/spi-dev.c +10
-0+ res =spi_add_driver (&spidev_driver); +if (res) + goto out_unreg_class; + +#ifdef CONFIG_DEVFS_FS +devfs_mk_dir ("spi" ); +#endif +return 0 ; + + out_unreg_class:
The label indentation is strange.
drivers/spi/spi-dev.c line 491
Quoted 2 lines
drivers/spi/spi-dev.c +2
-0+class_unregister (&spi_dev_class); + out_unreg_chrdev:
Ditto.
drivers/spi/spi-dev.c line 493
Quoted 2 lines
drivers/spi/spi-dev.c +2
-0+unregister_chrdev (SPI_MAJOR ,"spi" ); + out:
Here as well.
Quoted 14 lines
diff -uNr -X dontdiff
linux-2.6.12-rc4/include/linux/spi/spi.hlinux/include/linux/spi/spi.hinclude/linux/spi/spi.h +10
-0@@ -0,0 +1,265 @@ +/* +* linux/include/linux/spi/spi.h +* +* Copyright (C) 2001 Russell King, All Rights Reserved. +* Copyright (C) 2002 Compaq Computer Corporation, All Rights Reserved. +* +* 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. +*
include/linux/spi/spi.h line 20
Quoted 10 lines
include/linux/spi/spi.h +10
-0+* Derived from l3.h by Jamey Hicks +*/ +#ifndef SPI_H +#define SPI_H + +struct spi_msg { + unsigned char addr; /* slave address */ + unsigned char flags; +#define SPI_M_RD 0x01 +#define SPI_M_NOADDR 0x02
Please use enums instead.
include/linux/spi/spi.h line 30
Quoted 10 lines
include/linux/spi/spi.h +10
-0+unsigned short len;/* msg length */ +unsigned char *buf;/* pointer to msg data */ +}; + +/* TODO: should be in a separate header file? */ + +/* Commands for the ioctl call */ +#define SPI_RDWR 0x0801/* Read/write transfer in a single transaction */ +#define SPI_CLK_RATE 0x0802/* Sets SPI clock divisor (int type) */ +#define SPI_SDMA 0x0803/* Turns on/off SDMA usage (int type). */
Same here.
include/linux/spi/spi.h line 36
Quoted 6 lines
include/linux/spi/spi.h +6
-0+/* Pass non-zero value to turn SDMA on */ +struct spi_rdwr_ioctl_data { +struct spi_msg *msgs;/* pointers to spi_msgs */ +int nmsgs;/* number of spi_msgs */ +}; +/*------------^^^^^^^^^^^^^^^--------------*/
Please drop the above ASCII art.
include/linux/spi/spi.h line 43
Quoted 7 lines
include/linux/spi/spi.h +7
-0+ +#ifdef __KERNEL__ + +#include <linux/types.h> +#include <linux/list.h> + +#define SPI_ADAP_MAX 32
Unused constant.
Quoted 12 lines · Pekka Enberg
Quoted 11 lines · dmitry pervushin
drivers/spi/spi-core.c +11
-0+EXPORT_SYMBOL (spi_add_adapter); +EXPORT_SYMBOL (spi_del_adapter); +EXPORT_SYMBOL (spi_get_adapter); +EXPORT_SYMBOL (spi_put_adapter); + +EXPORT_SYMBOL (spi_add_driver); +EXPORT_SYMBOL (spi_del_driver); +EXPORT_SYMBOL (spi_get_driver); +EXPORT_SYMBOL (spi_put_driver); + +EXPORT_SYMBOL (spi_attach_client);
Quoted 8 lines
drivers/spi/spi-core.c line 385
Quoted 5 lines
drivers/spi/spi-core.c +5
-0+EXPORT_SYMBOL (spi_detach_client); + +EXPORT_SYMBOL (spi_transfer); +EXPORT_SYMBOL (spi_write); +EXPORT_SYMBOL (spi_read);Preferred location for
EXPORT_SYMBOLsis immediately after the function definition.
New files can choose any style.
Hi,
Quoted 2 lines · Pekka Enberg
Quoted 2 lines
Preferred location for
EXPORT_SYMBOLsis immediately after the function definition.
Quoted 1 line · Alexey Dobriyan
New files can choose any style.
Sure they can but hopefully they choose a style that make sense. Putting EXPORT_SYMBOLs immediately after function definition makes most sense to me. You can immediately see if a function is exported or not plus you can get listing of all symbols with grep. So there's really no good reason why you should put them at the end of a file (and one good reason to put them after definition).
You are right, though, that authors and maintainers decide what style they use. I only provide suggestions and hope for the best ;).
Pekka