summaryrefstree
path: root/kernel/drivers/misc/tzdev/tzpc_test.c
blob: 1b9c081eb286f4d078ff290d43cca61e1b332999 (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
114
115
116
117
118
119
/*
 * 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.
 */

#define pr_fmt(fmt) "tzpc_test: " fmt
#define DEBUG

#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/miscdevice.h>
#include <linux/fs.h>
#include <linux/device.h>
#include <linux/sysfs.h>
#include <linux/mm.h>
#include <linux/clk.h>
#include <asm/io.h>

#define MAP_ADDRESS	0x10830000
#define MAP_SIZE	0x1000
#define CLK_NAME	"secss"

static struct clk *clk;

static int tzpc_test_open(struct inode *inodp, struct file *filp)
{
	clk_enable(clk);

	return 0;
}

static int tzpc_test_release(struct inode *inodp, struct file *filp)
{
	clk_disable(clk);

	return 0;
}

static int tzpc_test_mmap(struct file *filp, struct vm_area_struct *vma)
{
	unsigned long off = vma->vm_pgoff << PAGE_SHIFT;
	unsigned long phys = MAP_ADDRESS + off;
	unsigned long vsize = vma->vm_end - vma->vm_start;
	unsigned long psize = MAP_SIZE - off;
	int ret;

	if (vsize > psize) {
		return -EINVAL;
	}

	vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);

	ret = remap_pfn_range(vma, vma->vm_start, __phys_to_pfn(phys), vsize, vma->vm_page_prot);
	if (ret) {
		goto out;
	}

	return 0;
out:
	return ret;
}

static struct file_operations tzpc_test_fops = {
	.open = tzpc_test_open,
	.release = tzpc_test_release,
	.mmap = tzpc_test_mmap,
};

static struct miscdevice tzpc_test_dev = {
	.minor = MISC_DYNAMIC_MINOR,
	.name = "tzpc_test",
	.fops = &tzpc_test_fops,
};

static int __init tzpc_test_init(void)
{
	int ret;

	pr_devel("module init\n");

	clk = clk_get(NULL, CLK_NAME);
	if (IS_ERR(clk)) {
		pr_err("Clock get failed\n");
		ret = -ENOENT;
		goto out;
	}

	ret = misc_register(&tzpc_test_dev);
	if (ret) {
		pr_err("misc device registration failed\n");
		goto out;
	}

	return 0;

out:
	return ret;
}

static void __exit tzpc_test_exit(void)
{
	pr_devel("module exit\n");
	misc_deregister(&tzpc_test_dev);
}

module_init(tzpc_test_init);
module_exit(tzpc_test_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Sergey Fedorov <s.fedorov@samsung.com>");