summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYacine Belkadi2012-04-13 10:38:27 +0200
committerYacine Belkadi2012-06-13 16:28:55 +0200
commitfeb61ad879f685b3567afb7545c0fa4be72e8045 (patch)
tree224d2b245d051d6530701bf172300a39838f97a8
parent205dbe772472e30c8960a503c2b967be69a7df3d (diff)
cleo/linux/drv/afe: add new AFE api, refs #3082
Add a new API for AFE related operations, that better handles error cases like when there is no AFE device. The previous API is tagged as "deprecated", but no removed yet.
-rw-r--r--cleopatre/linux-2.6.25.10-spc300/drivers/afe/Makefile3
-rw-r--r--cleopatre/linux-2.6.25.10-spc300/drivers/afe/afe.c84
-rw-r--r--cleopatre/linux-2.6.25.10-spc300/include/linux/afe.h55
3 files changed, 141 insertions, 1 deletions
diff --git a/cleopatre/linux-2.6.25.10-spc300/drivers/afe/Makefile b/cleopatre/linux-2.6.25.10-spc300/drivers/afe/Makefile
index 7513ca75a8..e33d38f991 100644
--- a/cleopatre/linux-2.6.25.10-spc300/drivers/afe/Makefile
+++ b/cleopatre/linux-2.6.25.10-spc300/drivers/afe/Makefile
@@ -2,4 +2,5 @@
# Makefile for the kernel AFE device drivers.
#
-obj-$(CONFIG_AD986X) += ad986x.o
+obj-$(CONFIG_AFE) += afe.o
+obj-$(CONFIG_AD986X) += ad986x.o
diff --git a/cleopatre/linux-2.6.25.10-spc300/drivers/afe/afe.c b/cleopatre/linux-2.6.25.10-spc300/drivers/afe/afe.c
new file mode 100644
index 0000000000..5676114650
--- /dev/null
+++ b/cleopatre/linux-2.6.25.10-spc300/drivers/afe/afe.c
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2012 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "linux/afe.h"
+
+#include "linux/errno.h"
+#include "linux/kernel.h"
+#include "linux/module.h"
+
+/* The currently registered AFE. */
+static struct afe *registered_afe = NULL;
+
+int
+afe_register(struct afe *afe)
+{
+ BUG_ON(afe == NULL);
+
+ if (registered_afe != NULL) {
+ printk (KERN_WARNING "An AFE is already registered.\n");
+ return -EBUSY;
+ }
+
+ registered_afe = afe;
+
+ return 0;
+}
+EXPORT_SYMBOL(afe_register);
+
+int
+afe_unregister(struct afe *afe)
+{
+ BUG_ON (afe == NULL);
+
+ if (registered_afe != afe) {
+ printk (KERN_WARNING
+ "An AFE can only unregister itself, not another AFE.\n");
+ return -EFAULT;
+ }
+
+ registered_afe = NULL;
+
+ return 0;
+}
+EXPORT_SYMBOL(afe_unregister);
+
+struct afe*
+afe_get(void)
+{
+ return registered_afe;
+}
+EXPORT_SYMBOL(afe_get);
+
+int
+afe_read(struct afe *afe, uint8_t reg, uint8_t *val)
+{
+ BUG_ON(afe == NULL);
+
+ return registered_afe->read(reg, val);
+}
+EXPORT_SYMBOL(afe_read);
+
+int
+afe_write(struct afe *afe, uint8_t reg, uint8_t val)
+{
+ BUG_ON(afe == NULL);
+
+ return registered_afe->write(reg, val);
+}
+EXPORT_SYMBOL(afe_write);
diff --git a/cleopatre/linux-2.6.25.10-spc300/include/linux/afe.h b/cleopatre/linux-2.6.25.10-spc300/include/linux/afe.h
index 42f300a16a..b71feb5ff4 100644
--- a/cleopatre/linux-2.6.25.10-spc300/include/linux/afe.h
+++ b/cleopatre/linux-2.6.25.10-spc300/include/linux/afe.h
@@ -25,9 +25,64 @@
#ifdef __KERNEL__
+/* Deprecated. */
int afe_read_reg(uint8_t reg, uint8_t *val);
+/* Deprecated. */
int afe_write_reg(uint8_t reg, uint8_t val);
+/**
+ * struct afe - An Analog Front End (AFE).
+ * @read: read from a register of the AFE.
+ * @write: write to a register of the AFE.
+ */
+struct afe {
+ int (*read)(uint8_t reg, uint8_t *val);
+ int (*write)(uint8_t reg, uint8_t val);
+};
+
+/**
+ * afe_register - Register an AFE.
+ * @afe: the AFE.
+ *
+ * Returns 0 on success.
+ */
+int afe_register(struct afe *afe);
+
+/**
+ * afe_unregister - Unregister an AFE.
+ * @afe: the AFE.
+ *
+ * Returns 0 on success.
+ */
+int afe_unregister(struct afe *afe);
+
+/**
+ * afe_get - Get the AFE.
+ *
+ * Returns the AFE, if one is registered. NULL, otherwise.
+ */
+struct afe* afe_get(void);
+
+/**
+ * afe_read - Read a register of the AFE.
+ * @afe: AFE.
+ * @reg: register.
+ * @val: [out]value of the register.
+ *
+ * Returns 0, on success. -EFAULT, on error.
+ */
+int afe_read(struct afe *afe, uint8_t reg, uint8_t *val);
+
+/**
+ * afe_write - Write to a register of the AFE.
+ * @afe: AFE.
+ * @reg: register.
+ * @val: value to write.
+ *
+ * Returns 0, on success. -EFAULT, on error.
+ */
+int afe_write(struct afe *afe, uint8_t reg, uint8_t val);
+
#endif /* __KERNEL__ */
#define AFE_IOCTL_BASE 'A'