summaryrefslogtreecommitdiff
path: root/cleopatre/linux-2.6.25.10-spc300/drivers/char
diff options
context:
space:
mode:
authorsave2009-04-24 13:16:19 +0000
committersave2009-04-24 13:16:19 +0000
commit362a141485b56cc194fd550c6e8b0836f44ee9f9 (patch)
tree73f5b9363b39637a2018605979b411c959a14cf6 /cleopatre/linux-2.6.25.10-spc300/drivers/char
parent174c0a3ac9aaaf6b62a0230497dd0f24b6cf09a6 (diff)
[CLEO][LNXDRV]Created AFE driver
git-svn-id: svn+ssh://pessac/svn/cesar/trunk@4518 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'cleopatre/linux-2.6.25.10-spc300/drivers/char')
-rw-r--r--cleopatre/linux-2.6.25.10-spc300/drivers/char/Kconfig7
-rw-r--r--cleopatre/linux-2.6.25.10-spc300/drivers/char/Makefile2
-rw-r--r--cleopatre/linux-2.6.25.10-spc300/drivers/char/ad9865.c187
3 files changed, 196 insertions, 0 deletions
diff --git a/cleopatre/linux-2.6.25.10-spc300/drivers/char/Kconfig b/cleopatre/linux-2.6.25.10-spc300/drivers/char/Kconfig
index 47c6be84fc..01ef9f2f7a 100644
--- a/cleopatre/linux-2.6.25.10-spc300/drivers/char/Kconfig
+++ b/cleopatre/linux-2.6.25.10-spc300/drivers/char/Kconfig
@@ -1049,5 +1049,12 @@ config DEVPORT
source "drivers/s390/char/Kconfig"
+config AD9865
+ tristate "Support for AD9865 Analog Front End"
+ depends on SPI_MASTER
+ help
+ This option enables support for the AD9865 Analog Font End devices
+ family. These devices are driven by SPI.
+
endmenu
diff --git a/cleopatre/linux-2.6.25.10-spc300/drivers/char/Makefile b/cleopatre/linux-2.6.25.10-spc300/drivers/char/Makefile
index 5407b76156..4aedc43252 100644
--- a/cleopatre/linux-2.6.25.10-spc300/drivers/char/Makefile
+++ b/cleopatre/linux-2.6.25.10-spc300/drivers/char/Makefile
@@ -112,6 +112,8 @@ obj-$(CONFIG_PS3_FLASH) += ps3flash.o
obj-$(CONFIG_JS_RTC) += js-rtc.o
js-rtc-y = rtc.o
+obj-$(CONFIG_AD9865) += ad9865.o
+
# Files generated that shall be removed upon make clean
clean-files := consolemap_deftbl.c defkeymap.c
diff --git a/cleopatre/linux-2.6.25.10-spc300/drivers/char/ad9865.c b/cleopatre/linux-2.6.25.10-spc300/drivers/char/ad9865.c
new file mode 100644
index 0000000000..8d60979b7c
--- /dev/null
+++ b/cleopatre/linux-2.6.25.10-spc300/drivers/char/ad9865.c
@@ -0,0 +1,187 @@
+/*
+ * Driver for Analog Front End AD9865 devices family
+ *
+ * (C) Copyright 2009 SPiDCOM Technologies
+ *
+ * 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, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <linux/types.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/device.h>
+#include <linux/miscdevice.h>
+#include <linux/fs.h>
+#include <asm/uaccess.h>
+#include <linux/spi/spi.h>
+#include <linux/afe.h>
+
+static int ad9865_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg);
+
+/** Misc device structures */
+static const struct file_operations ad9865_fops = {
+ .owner = THIS_MODULE,
+ .ioctl = ad9865_ioctl,
+};
+static struct miscdevice ad9865_miscdev = {
+ .minor = AFE_MINOR,
+ .name = "ad9865",
+ .fops = &ad9865_fops,
+};
+
+/**
+ * IOCTL commands for AD9865 device.
+ *
+ * \param inode inode structure.
+ * \param file user exchange structure.
+ * \param cmd command to execute.
+ * \param arg arguments.
+ * \return error code.
+ */
+static int ad9865_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
+{
+ void __user *argp = (void __user *)arg;
+ struct spi_device *spi;
+ struct afe_info info;
+ uint8_t command[2];
+
+ //Find SPI structure pointer
+ if(ad9865_miscdev.parent)
+ spi = container_of(ad9865_miscdev.parent, struct spi_device, dev);
+ else
+ return -EFAULT;
+
+ switch(cmd)
+ {
+ case AFEIOC_GETREG:
+ //Restore register number given by user
+ if(copy_from_user(&info, argp, sizeof(struct afe_info)))
+ return -EFAULT;
+
+ //Create SPI tx command : 1b(r/w) + 2b(nbbytes) + 5b(addr)
+ command[0] = (uint8_t)((1 << 7) | (1 << 5) | (info.reg & 0x1F));
+
+ //Send it and wait the response
+ if(spi_write_then_read(spi, &command[0], 1, &info.val, 1))
+ return -EFAULT;
+
+ //Give the response to user
+ return copy_to_user(argp, &info, sizeof(struct afe_info)) ? -EFAULT : 0;
+
+
+ case AFEIOC_SETREG:
+ //Restore register number and it value given by user
+ if(copy_from_user(&info, argp, sizeof(struct afe_info)))
+ return -EFAULT;
+
+ //Create SPI tx command : 1b(r/w) + 2b(nbbytes) + 5b(addr) + 8b(data)
+ if(spi->mode & SPI_LSB_FIRST)
+ {
+ command[0] = info.val;
+ command[1] = (uint8_t)((0 << 7) | (2 << 5) | (info.reg & 0x1F));
+ }
+ else //MSB first need to swap
+ {
+ command[0] = (uint8_t)((0 << 7) | (2 << 5) | (info.reg & 0x1F));
+ command[1] = info.val;
+ }
+
+ //Send it
+ return spi_write(spi, &command[0], 2) ? -EFAULT : 0;
+
+
+ default:
+ return -EFAULT;
+ }
+}
+
+/**
+ * Initialise AFE driver.
+ * \param spi spi device structure.
+ * \return error code.
+ */
+static int __devinit ad9865_probe(struct spi_device *spi)
+{
+ int res;
+
+ if(ad9865_miscdev.parent)
+ return -EBUSY;
+ ad9865_miscdev.parent = &spi->dev;
+
+ if((res = misc_register(&ad9865_miscdev)) != 0)
+ return res;
+
+ dev_info(&spi->dev, "AFE Driver enabled\n");
+
+ return 0;
+}
+
+/**
+ * Uninitialise AFE driver.
+ * \param spi spi device structure.
+ * \return error code.
+ */
+static int __devexit ad9865_remove(struct spi_device *spi)
+{
+ int res;
+
+ res = misc_deregister(&ad9865_miscdev);
+ if(!res)
+ ad9865_miscdev.parent = NULL;
+
+ return res;
+}
+
+/** Module structure */
+static struct spi_driver ad9865_driver = {
+ .driver = {
+ .name = "ad9865",
+ .bus = &spi_bus_type,
+ .owner = THIS_MODULE,
+ },
+ .probe = ad9865_probe,
+ .suspend = NULL,
+ .resume = NULL,
+ .remove = __devexit_p(ad9865_remove),
+};
+
+/**
+ * Module initialization.
+ * \return error code.
+ */
+static int ad9865_init(void)
+{
+ return spi_register_driver(&ad9865_driver);
+}
+
+/**
+ * Module uninitialization.
+ * \return error code.
+ */
+static void ad9865_exit(void)
+{
+ spi_unregister_driver(&ad9865_driver);
+}
+
+module_init(ad9865_init);
+module_exit(ad9865_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("SPiDCOM Technologies");
+MODULE_DESCRIPTION("SPI driver for AD9865 chips family");
+MODULE_ALIAS_MISCDEV(AFE_MINOR);
+