summaryrefslogtreecommitdiff
path: root/cleopatre/linux-2.6.25.10-spc300
diff options
context:
space:
mode:
authorYacine Belkadi2011-08-11 15:41:01 +0200
committerYacine Belkadi2011-09-15 11:14:00 +0200
commitb35ff0e96de82b987ded07656b0ee5ded18f6dbd (patch)
treef23f2f705f1a656ae75502f995079b07d81670e5 /cleopatre/linux-2.6.25.10-spc300
parent5c2a363da4a534ce27d8a5fe17217db4670254cd (diff)
cleo/{devkit/plcdrv,linux/drv/ad9865}: move AFE /proc code from plcdrv to ad9865, refs #453
The code providing a /proc entry to read/write the content of the AFE registers was in plcdrv. It seems more appropriate to put it in the AFE driver. As a consequence, the path to read/write the AFE registers becomes /proc/driver/afe instead of /proc/net/plc/afe.
Diffstat (limited to 'cleopatre/linux-2.6.25.10-spc300')
-rw-r--r--cleopatre/linux-2.6.25.10-spc300/drivers/char/ad986x.c175
1 files changed, 174 insertions, 1 deletions
diff --git a/cleopatre/linux-2.6.25.10-spc300/drivers/char/ad986x.c b/cleopatre/linux-2.6.25.10-spc300/drivers/char/ad986x.c
index 332ed49d49..76279ceb85 100644
--- a/cleopatre/linux-2.6.25.10-spc300/drivers/char/ad986x.c
+++ b/cleopatre/linux-2.6.25.10-spc300/drivers/char/ad986x.c
@@ -27,6 +27,7 @@
#include <linux/miscdevice.h>
#include <linux/fs.h>
#include <asm/uaccess.h>
+#include <linux/proc_fs.h>
#include <linux/spi/spi.h>
#include <linux/afe.h>
@@ -165,6 +166,165 @@ static int ad986x_ioctl(struct inode *inode, struct file *file, unsigned int cmd
}
}
+static int ad986x_read_proc_helper(char **p, uint8_t reg)
+{
+ uint8_t val;
+
+ int ret = ad986x_read_reg(reg, &val);
+
+ if (ret)
+ return ret;
+
+ *p += sprintf(*p, "@0x%02x = 0x%02x\n", reg, val);
+
+ return 0;
+}
+
+/**
+ * Read the AFE configuration by /proc.
+ *
+ * \param file file structure.
+ * \param buffer string pointer given by user.
+ * \param start string pointer begin.
+ * \param offset offset value.
+ * \param count count parameter.
+ * \param eof end of file.
+ * \param data network device structure.
+ * \return new pointer position.
+ */
+static int ad986x_read_proc(char *buf, char **start, off_t offset, int count, int *eof, void *data)
+{
+ char *p;
+ p = buf;
+
+ p += sprintf(p, "\n%s:\n", "SPI port configuration");
+
+ if (ad986x_read_proc_helper(&p, 0x00))
+ goto error;
+
+ p += sprintf(p, "\n%s:\n", "Power control registers");
+
+ if (ad986x_read_proc_helper(&p, 0x01)
+ || ad986x_read_proc_helper(&p, 0x02))
+ goto error;
+
+ p += sprintf(p, "\n%s:\n", "Half-Duplex power control");
+
+ if (ad986x_read_proc_helper(&p, 0x03))
+ goto error;
+
+ p += sprintf(p, "\n%s:\n", "PLL clock multiplier/synthesizer control");
+
+ if (ad986x_read_proc_helper(&p, 0x04)
+ || ad986x_read_proc_helper(&p, 0x05)
+ || ad986x_read_proc_helper(&p, 0x06))
+ goto error;
+
+ p += sprintf(p, "\n%s:\n", "RX path control");
+
+
+ if (ad986x_read_proc_helper(&p, 0x07)
+ || ad986x_read_proc_helper(&p, 0x08))
+ goto error;
+
+ p += sprintf(p, "\n%s:\n", "TX/RX path gain control");
+
+ if (ad986x_read_proc_helper(&p, 0x09)
+ || ad986x_read_proc_helper(&p, 0x0A))
+ goto error;
+
+ p += sprintf(p, "\n%s:\n", "TX and RX PGA control");
+
+ if (ad986x_read_proc_helper(&p, 0x0B))
+ goto error;
+
+ p += sprintf(p, "\n%s:\n", "TX digital filter and interface");
+
+ if (ad986x_read_proc_helper(&p, 0x0C))
+ goto error;
+
+ p += sprintf(p, "\n%s:\n", "RX interface and analog/digital loopback");
+
+ if (ad986x_read_proc_helper(&p, 0x0D))
+ goto error;
+
+ p += sprintf(p, "\n%s:\n", "Digital output drive strength, TxDAC output and rev id");
+
+ if (ad986x_read_proc_helper(&p, 0x0E)
+ || ad986x_read_proc_helper(&p, 0x0F))
+ goto error;
+
+ p += sprintf(p, "\n%s:\n", "TX IAMP gain and BIAS control");
+
+ if (ad986x_read_proc_helper(&p, 0x10)
+ || ad986x_read_proc_helper(&p, 0x11)
+ || ad986x_read_proc_helper(&p, 0x12)
+ || ad986x_read_proc_helper(&p, 0x13))
+ goto error;
+
+ p += sprintf(p, "\n");
+
+ *eof = 1;
+
+ return p-buf+1;
+
+error:
+ return -1;
+}
+
+/**
+ * Change the AFE configuration by /proc.
+ *
+ * \param file file structure.
+ * \param buffer string pointer given by user.
+ * \param count count parameter.
+ * \param data network device structure.
+ * \return counter value.
+ */
+static int ad986x_write_proc(struct file *file, const char *buffer, unsigned long count, void *data)
+{
+ uint32_t reg;
+ uint32_t value;
+
+ if(sscanf(buffer, "0x%02x=0x%02x", &reg, &value) == 2)
+ {
+ if(reg <= 0x13)
+ {
+ ad986x_write_reg((uint8_t)reg, (uint8_t)value);
+ }
+ }
+ else
+ {
+ printk("Syntax: reg=value example: 0x12=0xa3\n");
+ }
+
+ return count;
+}
+
+/**
+ * Create the entry in /proc.
+ *
+ * \return 0, on success.
+ * -EFAULT, on error.
+ */
+static inline int ad986x_create_proc_entry(void)
+{
+ struct proc_dir_entry *entry;
+
+ //Create proc entry for AFE configuration
+ entry = create_proc_entry("driver/afe", 0, NULL);
+ if (entry == NULL)
+ {
+ /* dev_err( , "error while registering proc_entry\n"); */
+ return -EFAULT;
+ }
+
+ entry->read_proc = ad986x_read_proc;
+ entry->write_proc = ad986x_write_proc;
+
+ return 0;
+}
+
/**
* Initialise AFE driver.
* \param spi spi device structure.
@@ -192,6 +352,18 @@ static int __devinit ad986x_probe(struct spi_device *spi)
if((res = misc_register(&ad986x_miscdev)) != 0)
return res;
+ if (ad986x_create_proc_entry())
+ {
+ dev_err(&spi_dev->dev, "failed to create proc entry\n");
+
+ res = misc_deregister(&ad986x_miscdev);
+ if (res)
+ {
+ dev_err(&spi_dev->dev, "failed to unregister misc driver %d\n", res);
+ }
+ return -EFAULT;
+ }
+
dev_info(&spi_dev->dev, "AFE Driver enabled\n");
return 0;
@@ -206,6 +378,8 @@ static int __devexit ad986x_remove(struct spi_device *spi)
{
int res;
+ remove_proc_entry("afe", proc_root_driver);
+
//Unregister Misc device
res = misc_deregister(&ad986x_miscdev);
if(!res)
@@ -253,4 +427,3 @@ MODULE_LICENSE("GPL");
MODULE_AUTHOR("SPiDCOM Technologies");
MODULE_DESCRIPTION("SPI driver for AD986X chips family");
MODULE_ALIAS_MISCDEV(AFE_MINOR);
-