summaryrefstree
path: root/kernel/drivers/misc/tzdev/efuse_test.c
blob: b81a78a9e9eb41179bd0554b3f877201f64b66e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
 * Copyright (C) 2015 Samsung Electronics, Inc.
 *
 * This software is licensed under the terms of the GNU General Public
 * License version 2, as published by the Free Software Foundation, and
 * may be copied, distributed, and modified under those terms.
 *
 * 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.
 */

#include <linux/kernel.h>
#include <linux/module.h>

#include <linux/slab.h>
#include <linux/debugfs.h>
#include <linux/uaccess.h>

#include <mach/hardware.h>

#include <asm/io.h>
#include <linux/ioport.h>

static struct dentry  *file;


static int efuse_open(struct inode *inode, struct file *filp)
{
	return 0; /* success */
}

static int efuse_release(struct inode *inode, struct file *filp)
{
	return 0; /* success */
}


static int read_word(unsigned long addr)
{
	const unsigned int size = 4;
	void *base = 0;
	unsigned int val = 0;

	if (check_mem_region(addr, size)) {
		printk(KERN_ERR "efuse: address already in use\n");
		return -2;
	}

	request_mem_region(addr, size, "efuse_test");
	base = ioremap(addr, size); /* get virtuall address */

	val = readl(base);

	iounmap(base);
	release_mem_region(addr, size);

	return (int)val;
}

#define EFUSE_IOC_MAGIC 'r'
#define EFUSE_GET_TICK_CNT   _IOW(EFUSE_IOC_MAGIC,  0, unsigned long)
#define EFUSE_GET_EFUSE      _IOW(EFUSE_IOC_MAGIC,  1, unsigned long)

static long efuse_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
	switch(cmd)
	{
	case EFUSE_GET_TICK_CNT:
		return read_word(0x10050100);

	case EFUSE_GET_EFUSE:
		return read_word(0x10100000);

	default:
		return -ENOTTY;
	}
}

static struct file_operations efuse_fops =
{
	.open =  efuse_open,
	.release = efuse_release,
	.unlocked_ioctl = efuse_ioctl,
};


static int __init efuse_module_init(void)
{
	file = debugfs_create_file("efuse_test", 0644, NULL, NULL, &efuse_fops);
	if(file <= 0) {
		printk(KERN_ERR "efuse test - file creation failed!!!\n");
		return PTR_ERR(file);
	}


	return 0;
}

static void __exit efuse_module_exit(void)
{
	debugfs_remove(file);
}

module_init(efuse_module_init);
module_exit(efuse_module_exit);

MODULE_AUTHOR("Oleg Isakov");
MODULE_DESCRIPTION("Read device key test module");
MODULE_LICENSE("GPL");