Hi all,
It seems the patch that I mentioned in my previous mail has been trashed, here
is this path:
>From 97ad3082149695f14e621861e73ef03fa1b33ec7 Mon Sep 17 00:00:00 2001
From: Mathieu SOULARD <[email protected]>
Date: Fri, 27 Aug 2010 10:33:11 +0200
Subject: [PATCH] Add controller_data ioctl accessor to spidev.c
Signed-off-by: Mathieu SOULARD <[email protected]>
---
drivers/spi/spidev.c | 70 ++++++++++++++++++++++++++++++--------------
include/linux/spi/spidev.h | 3 ++
2 files changed, 51 insertions(+), 22 deletions(-)
diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c
index ea1bec3..21d7991 100644
--- a/drivers/spi/spidev.c
+++ b/drivers/spi/spidev.c
@@ -433,36 +433,62 @@ spidev_ioctl(struct file *filp, unsigned int cmd,
unsigned long arg)
default:
/* segmented and/or full-duplex I/O request */
- if (_IOC_NR(cmd) != _IOC_NR(SPI_IOC_MESSAGE(0))
+ if ((_IOC_NR(cmd) != _IOC_NR(SPI_IOC_MESSAGE(0)) &&
+ _IOC_NR(cmd) !=
_IOC_NR(SPI_IOC_WR_CTRL_DATA(0)))
|| _IOC_DIR(cmd) !=
_IOC_WRITE) {
retval = -ENOTTY;
break;
}
- tmp = _IOC_SIZE(cmd);
- if ((tmp % sizeof(struct spi_ioc_transfer)) != 0)
{
- retval = -EINVAL;
- break;
- }
- n_ioc = tmp / sizeof(struct spi_ioc_transfer);
- if (n_ioc == 0)
- break;
+ if (_IOC_NR(cmd) == _IOC_NR(SPI_IOC_MESSAGE(0))) {
+ tmp = _IOC_SIZE(cmd);
+ if ((tmp % sizeof(struct
spi_ioc_transfer)) != 0) {
+ retval = -EINVAL;
+ break;
+ }
+ n_ioc = tmp / sizeof(struct
spi_ioc_transfer);
+ if (n_ioc == 0)
+ break;
- /* copy into scratch area */
- ioc = kmalloc(tmp, GFP_KERNEL);
- if (!ioc) {
- retval = -ENOMEM;
- break;
- }
- if (__copy_from_user(ioc, (void __user *)arg,
tmp)) {
+ /* copy into scratch area */
+ ioc = kmalloc(tmp, GFP_KERNEL);
+ if (!ioc) {
+ retval = -ENOMEM;
+ break;
+ }
+ if (__copy_from_user(ioc, (void
__user *)arg, tmp)) {
+ kfree(ioc);
+ retval = -EFAULT;
+ break;
+ }
+ /* translate to spi_message,
execute */
+ retval = spidev_message(spidev,
ioc, n_ioc);
kfree(ioc);
- retval = -EFAULT;
- break;
+ } else if (_IOC_NR(cmd) ==
_IOC_NR(SPI_IOC_WR_CTRL_DATA(0))) {
+ void *save = spi->controller_data;
+
+ tmp = _IOC_SIZE(cmd);
+ if (tmp == 0) {
+ spi->controller_data
= NULL;
+ } else {
+ spi->controller_data
= kmalloc(tmp, GFP_KERNEL);
+ if
(!spi->controller_data) {
+
spi->controller_data = save;
+
retval = -ENOMEM;
+ break;
+ }
+ if
(__copy_from_user(spi->controller_data,
+
(void __user *)arg, tmp)) {
+
kfree(spi->controller_data);
+
spi->controller_data = save;
+
retval = -EFAULT;
+ break;
+ }
+ retval =
spi_setup(spi);
+ }
+ if (!save)
+ kfree(save);
}
-
- /* translate to spi_message, execute */
- retval = spidev_message(spidev, ioc, n_ioc);
- kfree(ioc);
break;
}
diff --git a/include/linux/spi/spidev.h b/include/linux/spi/spidev.h
index bf0570a..dbc3796 100644
--- a/include/linux/spi/spidev.h
+++ b/include/linux/spi/spidev.h
@@ -126,6 +126,9 @@ struct spi_ioc_transfer {
#define SPI_IOC_RD_MAX_SPEED_HZ _IOR(SPI_IOC_MAGIC, 4,
__u32)
#define SPI_IOC_WR_MAX_SPEED_HZ _IOW(SPI_IOC_MAGIC, 4,
__u32)
+/* Write SPI controller_data */
+#define SPI_IOC_WR_CTRL_DATA(size) _IOW(SPI_IOC_MAGIC, 5, char[size])
+
#endif /* SPIDEV_H */
--
1.6.5.2
---------------------------------------------------------------------
Intel Corporation SAS (French simplified joint stock company)
Registered headquarters: "Les Montalets"- 2, rue de Paris,
92196 Meudon Cedex, France
Registration Number: 302 456 199 R.C.S. NANTERRE
Capital: 4,572,000 Euros
This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
------------------------------------------------------------------------------
This SF.net Dev2Dev email is sponsored by:
Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd
_______________________________________________
spi-devel-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spi-devel-general