blob: 54fbd95cee9b40cc583fa6df49767b2f859a5598 [file] [log] [blame]
Mark Jackson5b50c162008-10-13 13:14:50 +00001/*
2 * FRAM driver for MIMC200 board
3 *
4 * Copyright 2008 Mark Jackson <mpfj@mimc.co.uk>
5 *
6 * This module adds *very* simply support for the system's FRAM device.
7 * At the moment, this is hard-coded to the MIMC200 platform, and only
8 * supports mmap().
9 */
10
11#define FRAM_VERSION "1.0"
12
13#include <linux/miscdevice.h>
14#include <linux/proc_fs.h>
15#include <linux/mm.h>
16#include <linux/io.h>
17
18#define FRAM_BASE 0xac000000
19#define FRAM_SIZE 0x20000
20
21/*
22 * The are the file operation function for user access to /dev/fram
23 */
24
25static int fram_mmap(struct file *filp, struct vm_area_struct *vma)
26{
27 int ret;
28
29 ret = remap_pfn_range(vma,
30 vma->vm_start,
31 virt_to_phys((void *)((unsigned long)FRAM_BASE)) >> PAGE_SHIFT,
32 vma->vm_end-vma->vm_start,
33 PAGE_SHARED);
34
35 if (ret != 0)
36 return -EAGAIN;
37
38 return 0;
39}
40
41static const struct file_operations fram_fops = {
42 .owner = THIS_MODULE,
43 .mmap = fram_mmap,
44};
45
46#define FRAM_MINOR 0
47
48static struct miscdevice fram_dev = {
49 FRAM_MINOR,
50 "fram",
51 &fram_fops
52};
53
54static int __init
55fram_init(void)
56{
57 int ret;
58
59 ret = misc_register(&fram_dev);
60 if (ret) {
61 printk(KERN_ERR "fram: can't misc_register on minor=%d\n",
62 FRAM_MINOR);
63 return ret;
64 }
65 printk(KERN_INFO "FRAM memory driver v" FRAM_VERSION "\n");
66 return 0;
67}
68
69static void __exit
70fram_cleanup_module(void)
71{
72 misc_deregister(&fram_dev);
73}
74
75module_init(fram_init);
76module_exit(fram_cleanup_module);
77
78MODULE_LICENSE("GPL");
79
80MODULE_ALIAS_MISCDEV(FRAM_MINOR);