summaryrefslogtreecommitdiffstats
path: root/arch/avr32/boards/mimc200/fram.c
blob: 9764a1a1073e933aa1c2d6a73e51483553da2dfa (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
/*
 * FRAM driver for MIMC200 board
 *
 * Copyright 2008 Mark Jackson <mpfj@mimc.co.uk>
 *
 * This module adds *very* simply support for the system's FRAM device.
 * At the moment, this is hard-coded to the MIMC200 platform, and only
 * supports mmap().
 */

#define FRAM_VERSION	"1.0"

#include <linux/miscdevice.h>
#include <linux/proc_fs.h>
#include <linux/mm.h>
#include <linux/io.h>

#define FRAM_BASE	0xac000000
#define FRAM_SIZE	0x20000

/*
 * The are the file operation function for user access to /dev/fram
 */

static int fram_mmap(struct file *filp, struct vm_area_struct *vma)
{
	int ret;

	ret = remap_pfn_range(vma,
		vma->vm_start,
		virt_to_phys((void *)((unsigned long)FRAM_BASE)) >> PAGE_SHIFT,
		vma->vm_end-vma->vm_start,
		PAGE_SHARED);

	if (ret != 0)
		return -EAGAIN;

	return 0;
}

static const struct file_operations fram_fops = {
	.owner			= THIS_MODULE,
	.mmap			= fram_mmap,
	.llseek			= noop_llseek,
};

#define FRAM_MINOR	0

static struct miscdevice fram_dev = {
	FRAM_MINOR,
	"fram",
	&fram_fops
};

static int __init
fram_init(void)
{
	int ret;

	ret = misc_register(&fram_dev);
	if (ret) {
		printk(KERN_ERR "fram: can't misc_register on minor=%d\n",
		    FRAM_MINOR);
		return ret;
	}
	printk(KERN_INFO "FRAM memory driver v" FRAM_VERSION "\n");
	return 0;
}

static void __exit
fram_cleanup_module(void)
{
	misc_deregister(&fram_dev);
}

module_init(fram_init);
module_exit(fram_cleanup_module);

MODULE_LICENSE("GPL");

MODULE_ALIAS_MISCDEV(FRAM_MINOR);