generic-poky/meta-moblin/packages/linux/linux-moblin-2.6.33.2/linux-2.6.34-moorestown-ipc...

269 lines
7.8 KiB
Diff

From 60bb8e915a1e55c5a562e59e694d37559d62de92 Mon Sep 17 00:00:00 2001
From: Sreenidhi Gurudatt <sreenidhi.b.gurudatt@intel.com>
Date: Mon, 3 Aug 2009 14:46:37 +0530
Subject: [PATCH 073/104] IPC Host driver for MRSTN. It is disabled by default. This driver implements basic ioctls to support testing of IPC driver from user space. It supports Device firmware upgrade feature to be invoked by user-space application.
modified: drivers/misc/Kconfig
modified: drivers/misc/Makefile
new file: drivers/misc/mrst_test_ipc/Makefile
new file: drivers/misc/mrst_test_ipc/ipc_module.c
Signed-off-by: Sreenidhi Gurudatt <sreenidhi.b.gurudatt@intel.com>
---
drivers/misc/Kconfig | 9 ++
drivers/misc/Makefile | 1 +
drivers/misc/mrst_test_ipc/Makefile | 5 +
drivers/misc/mrst_test_ipc/ipc_module.c | 196 +++++++++++++++++++++++++++++++
4 files changed, 211 insertions(+), 0 deletions(-)
create mode 100644 drivers/misc/mrst_test_ipc/Makefile
create mode 100644 drivers/misc/mrst_test_ipc/ipc_module.c
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index feb9cd9..5a7c342 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -260,6 +260,15 @@ config MRST_RAR_HANDLER
If unsure, say N.
+config MRST_IPC_TEST
+ tristate "IPC driver for testing IPC on Moorestown platform"
+ depends on X86
+ ---help---
+ IPC test driver for Intel Moorestown platform
+ Intel Moorestown platform.
+
+ If unsure, say N.
+
config MRST_VIB
tristate "vibrator driver for Intel Moorestown platform"
help
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 0c24f0f..bce8396 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -14,6 +14,7 @@ obj-$(CONFIG_TIFM_CORE) += tifm_core.o
obj-$(CONFIG_TIFM_7XX1) += tifm_7xx1.o
obj-$(CONFIG_PHANTOM) += phantom.o
obj-$(CONFIG_SGI_IOC4) += ioc4.o
+obj-$(CONFIG_MRST_IPC_TEST) += mrst_test_ipc/
obj-$(CONFIG_ENCLOSURE_SERVICES) += enclosure.o
obj-$(CONFIG_KGDB_TESTS) += kgdbts.o
obj-$(CONFIG_SGI_XP) += sgi-xp/
diff --git a/drivers/misc/mrst_test_ipc/Makefile b/drivers/misc/mrst_test_ipc/Makefile
new file mode 100644
index 0000000..047d7db
--- /dev/null
+++ b/drivers/misc/mrst_test_ipc/Makefile
@@ -0,0 +1,5 @@
+
+obj-$(CONFIG_MRST_IPC_TEST) := test_ipc_mrst.o
+
+test_ipc_mrst-y := ipc_module.o \
+
diff --git a/drivers/misc/mrst_test_ipc/ipc_module.c b/drivers/misc/mrst_test_ipc/ipc_module.c
new file mode 100644
index 0000000..51ef8de
--- /dev/null
+++ b/drivers/misc/mrst_test_ipc/ipc_module.c
@@ -0,0 +1,196 @@
+/*
+ * ipc_module.c - Interface for IPC driver funtions exported by IPC driver
+ * interfaces for Moorsetown platform.
+ *
+ * Copyright (C) 2009 Intel Corp
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * 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; version 2 of the License.
+ *
+ * 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.
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * This driver provides IOCTL interfaces to call IPC driver module for
+ * Moorestown platform.
+ *
+ * Author: Sreenidhi Gurudatt <sreenidhi.b.gurudatt@intel.com>
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+
+#include <linux/slab.h>
+#include <linux/fs.h>
+#include <linux/errno.h>
+#include <linux/types.h>
+#include <linux/proc_fs.h>
+#include <linux/fcntl.h>
+#include <linux/init.h>
+#include <linux/delay.h>
+#include <linux/sched.h>
+#include <linux/ioport.h>
+
+#include <linux/io.h>
+#include <linux/uaccess.h>
+#include <linux/time.h>
+
+#include <asm/ipc_defs.h>
+
+static u32 major;
+#define MAX_FW_SIZE 264192
+
+int init_ipc_driver(void);
+int ipc_ioctl(struct inode *inode, struct file *filp, u32 cmd,
+ unsigned long arg);
+const struct file_operations ipc_fops = {
+ioctl:ipc_ioctl,
+};
+
+
+int ipc_ioctl(struct inode *inode, struct file *filp, u32 cmd,
+ unsigned long arg)
+{
+ u32 upper = 0;
+ struct ipc_pmic_reg_data p_read_reg_data = { 0 };
+ struct ipc_pmic_mod_reg_data p_read_mod_reg_data = { 0 };
+ struct ipc_pmic_reg_data p_write_reg_data = { 0 };
+ u8 ipc_blocking_flag = TRUE;
+
+ int ret_val;
+ /*Device FW upgrade support*/
+ u8 *fw_buf = NULL ;
+
+ switch (cmd) {
+ case IPC_PMIC_REGISTER_READ:
+ {
+ printk(KERN_INFO
+ "ipc_driver IPC_PMIC_REGISTER_READ received\n");
+ ret_val =
+ copy_from_user(&p_read_reg_data,
+ (struct ipc_pmic_reg_data *)arg,
+ sizeof(struct ipc_pmic_reg_data));
+ if (ret_val < 0) {
+ printk(KERN_DEBUG
+ "copy_from_user FAILED!! <%s> function\
+ in <%s> file at <%d> line no\n",\
+ __func__, __FILE__, __LINE__);
+ return E_READ_USER_DATA;
+ }
+
+ ipc_pmic_register_read(&p_read_reg_data);
+ ret_val =
+ copy_to_user((struct ipc_pmic_reg_data *)arg,
+ &p_read_reg_data,
+ sizeof(struct ipc_pmic_reg_data));
+ break;
+ }
+ case IPC_PMIC_REGISTER_READ_MODIFY:
+ {
+ printk(KERN_INFO "ioctl\
+ IPC_PMIC_REGISTER_READ_MODIFY received\n");
+ ret_val =
+ copy_from_user(&p_read_mod_reg_data,
+ (struct ipc_pmic_mod_reg_data *)arg,
+ sizeof(struct ipc_pmic_mod_reg_data));
+ if (ret_val < 0) {
+ printk(KERN_DEBUG
+ "copy_from_user FAILED!! <%s> function\
+ in <%s> file at <%d> line no\n",\
+ __func__, __FILE__, __LINE__);
+ return E_READ_USER_DATA;
+ }
+ ipc_pmic_register_read_modify(&p_read_mod_reg_data);
+ ret_val =
+ copy_to_user((struct ipc_pmic_mod_reg_data *)arg,
+ &p_read_mod_reg_data,
+ sizeof(struct ipc_pmic_mod_reg_data));
+ break;
+ }
+ case IPC_PMIC_REGISTER_WRITE:
+ {
+ ret_val =
+ copy_from_user(&p_write_reg_data,
+ (struct ipc_pmic_reg_data *)arg,
+ sizeof(struct ipc_pmic_reg_data));
+ if (ret_val < 0) {
+ printk(KERN_DEBUG
+ "copy_from_user FAILED!! <%s> function\
+ in <%s> file at <%d> line no\n",\
+ __func__, __FILE__, __LINE__);
+ return E_WRITE_USER_DATA;
+ }
+ ipc_pmic_register_write(&p_write_reg_data,
+ ipc_blocking_flag);
+ ret_val =
+ copy_to_user((struct ipc_pmic_reg_data *)arg,
+ &p_write_reg_data,
+ sizeof(struct ipc_pmic_reg_data));
+ break;
+ }
+ case DEVICE_FW_UPGRADE:
+ {
+ printk(KERN_INFO "ioctl DEVICE_FW_UPGRADE received\n");
+ fw_buf = kmalloc(MAX_FW_SIZE, GFP_KERNEL);
+ if (fw_buf == NULL) {
+ printk(KERN_ERR "ipc_test: kmalloc failed! \n");
+ return -EBUSY;
+ }
+ ret_val = copy_from_user(fw_buf, (u8 *)arg,
+ MAX_FW_SIZE);
+ if (ret_val < 0) {
+ printk(KERN_DEBUG
+ "copy_from_user FAILED!! <%s> function\
+ in <%s> file at <%d> line no\n",\
+ __func__, __FILE__, __LINE__);
+ return -EINVAL;
+ }
+ ipc_device_fw_upgrade(fw_buf, MAX_FW_SIZE);
+ break;
+ }
+ default:
+ {
+ printk(KERN_INFO
+ "ioctl <UNRECOGNIZED> received\n");
+ break;
+ }
+ }
+ return upper;
+}
+
+static int __init ipc_module_init(void)
+{
+ printk(KERN_INFO "Init ipc_module\n");
+
+ major = register_chrdev(0, "mid_ipc", &ipc_fops);
+ if (major < 0) {
+ printk(KERN_ERR "ipc_test : failed to get major\n");
+ return major;
+ }
+
+ init_ipc_driver ( ) ;
+ return SUCCESS;
+
+}
+
+static void __exit ipc_module_exit(void)
+{
+ unregister_chrdev(major, "mid_ipc");
+}
+
+module_init(ipc_module_init);
+module_exit(ipc_module_exit);
+
+MODULE_LICENSE("GPL V2");
+MODULE_DESCRIPTION("Test Driver for MRST IPC driver");
+MODULE_AUTHOR("Sreenidhi Gurudatt")
+
--
1.6.2.5