aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/misc/tzic.c
diff options
context:
space:
mode:
authorcodeworkx <daniel.hillenbrand@codeworkx.de>2012-06-02 13:09:29 +0200
committercodeworkx <daniel.hillenbrand@codeworkx.de>2012-06-02 13:09:29 +0200
commitc6da2cfeb05178a11c6d062a06f8078150ee492f (patch)
treef3b4021d252c52d6463a9b3c1bb7245e399b009c /drivers/misc/tzic.c
parentc6d7c4dbff353eac7919342ae6b3299a378160a6 (diff)
downloadkernel_samsung_smdk4412-c6da2cfeb05178a11c6d062a06f8078150ee492f.zip
kernel_samsung_smdk4412-c6da2cfeb05178a11c6d062a06f8078150ee492f.tar.gz
kernel_samsung_smdk4412-c6da2cfeb05178a11c6d062a06f8078150ee492f.tar.bz2
samsung update 1
Diffstat (limited to 'drivers/misc/tzic.c')
-rw-r--r--drivers/misc/tzic.c185
1 files changed, 185 insertions, 0 deletions
diff --git a/drivers/misc/tzic.c b/drivers/misc/tzic.c
new file mode 100644
index 0000000..966de5a
--- /dev/null
+++ b/drivers/misc/tzic.c
@@ -0,0 +1,185 @@
+/*
+ * Samsung TZIC Driver
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * 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.
+ */
+
+#define KMSG_COMPONENT "TZIC"
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/fs.h>
+#include <linux/platform_device.h>
+#include <linux/debugfs.h>
+#include <linux/cdev.h>
+#include <linux/uaccess.h>
+#include <linux/sched.h>
+#include <linux/list.h>
+#include <linux/mutex.h>
+#include <linux/android_pmem.h>
+#include <linux/io.h>
+#include <linux/types.h>
+#include <asm/smc.h>
+
+#define TZIC_DEV "tzic"
+#define SMC_CMD_STORE_BINFO (-201)
+
+static int gotoCpu0(void);
+static int gotoAllCpu(void) __attribute__ ((unused));
+
+u32 exynos_smc1(u32 cmd, u32 arg1, u32 arg2, u32 arg3)
+{
+ register u32 reg0 __asm__("r0") = cmd;
+ register u32 reg1 __asm__("r1") = arg1;
+ register u32 reg2 __asm__("r2") = arg2;
+ register u32 reg3 __asm__("r3") = arg3;
+
+ __asm__ volatile (
+ "smc 0\n"
+ : "+r"(reg0), "+r"(reg1), "+r"(reg2), "+r"(reg3)
+ );
+
+ return reg0;
+}
+
+static DEFINE_MUTEX(tzic_mutex);
+static struct class *driver_class;
+static dev_t tzic_device_no;
+static struct cdev tzic_cdev;
+
+#define LOG printk
+
+static long tzic_ioctl(struct file *file, unsigned cmd,
+ unsigned long arg)
+{
+ int ret = 0;
+
+ ret = gotoCpu0();
+ if (0 != ret) {
+ LOG(KERN_INFO "changing core failed!");
+ return -1;
+ }
+
+ LOG(KERN_INFO "set_fuse");
+ exynos_smc1(SMC_CMD_STORE_BINFO, 0x80010001, 0, 0);
+ exynos_smc1(SMC_CMD_STORE_BINFO, 0x00000001, 0, 0);
+
+ gotoAllCpu();
+
+ return 0;
+}
+
+static const struct file_operations tzic_fops = {
+ .owner = THIS_MODULE,
+ .unlocked_ioctl = tzic_ioctl,
+};
+
+static int __init tzic_init(void)
+{
+ int rc;
+ struct device *class_dev;
+
+ rc = alloc_chrdev_region(&tzic_device_no, 0, 1, TZIC_DEV);
+ if (rc < 0) {
+ LOG(KERN_INFO "alloc_chrdev_region failed %d", rc);
+ return rc;
+ }
+
+ driver_class = class_create(THIS_MODULE, TZIC_DEV);
+ if (IS_ERR(driver_class)) {
+ rc = -ENOMEM;
+ LOG(KERN_INFO "class_create failed %d", rc);
+ goto unregister_chrdev_region;
+ }
+
+ class_dev = device_create(driver_class, NULL, tzic_device_no, NULL,
+ TZIC_DEV);
+ if (!class_dev) {
+ LOG(KERN_INFO "class_device_create failed %d", rc);
+ rc = -ENOMEM;
+ goto class_destroy;
+ }
+
+ cdev_init(&tzic_cdev, &tzic_fops);
+ tzic_cdev.owner = THIS_MODULE;
+
+ rc = cdev_add(&tzic_cdev, MKDEV(MAJOR(tzic_device_no), 0), 1);
+ if (rc < 0) {
+ LOG(KERN_INFO "cdev_add failed %d", rc);
+ goto class_device_destroy;
+ }
+
+ return 0;
+
+class_device_destroy:
+ device_destroy(driver_class, tzic_device_no);
+class_destroy:
+ class_destroy(driver_class);
+unregister_chrdev_region:
+ unregister_chrdev_region(tzic_device_no, 1);
+ return rc;
+}
+
+static void __exit tzic_exit(void)
+{
+ device_destroy(driver_class, tzic_device_no);
+ class_destroy(driver_class);
+ unregister_chrdev_region(tzic_device_no, 1);
+}
+
+static int gotoCpu0(void)
+{
+ int ret = 0;
+ struct cpumask mask = CPU_MASK_CPU0;
+
+ LOG(KERN_INFO "System has %d CPU's, we are on CPU #%d\n"
+ "\tBinding this process to CPU #0.\n"
+ "\tactive mask is %lx, setting it to mask=%lx\n",
+ nr_cpu_ids,
+ raw_smp_processor_id(),
+ cpu_active_mask->bits[0],
+ mask.bits[0]);
+ ret = set_cpus_allowed_ptr(current, &mask);
+ if (0 != ret)
+ LOG(KERN_INFO "set_cpus_allowed_ptr=%d.\n", ret);
+ LOG(KERN_INFO "And now we are on CPU #%d",
+ raw_smp_processor_id());
+
+ return ret;
+}
+
+static int gotoAllCpu(void)
+{
+ int ret = 0;
+ struct cpumask mask = CPU_MASK_ALL;
+
+ LOG(KERN_INFO "System has %d CPU's, we are on CPU #%d\n"
+ "\tBinding this process to CPU #0.\n"
+ "\tactive mask is %lx, setting it to mask=%lx\n",
+ nr_cpu_ids,
+ raw_smp_processor_id(),
+ cpu_active_mask->bits[0],
+ mask.bits[0]);
+ ret = set_cpus_allowed_ptr(current, &mask);
+ if (0 != ret)
+ LOG(KERN_INFO "set_cpus_allowed_ptr=%d.\n", ret);
+ LOG(KERN_INFO "And now we are on CPU #%d",
+ raw_smp_processor_id());
+
+ return ret;
+}
+
+MODULE_LICENSE("GPL v2");
+MODULE_DESCRIPTION("Samsung TZIC Driver");
+MODULE_VERSION("1.00");
+
+module_init(tzic_init);
+module_exit(tzic_exit);
+