fram.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  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. #define FRAM_VERSION "1.0"
  11. #include <linux/miscdevice.h>
  12. #include <linux/proc_fs.h>
  13. #include <linux/mm.h>
  14. #include <linux/io.h>
  15. #define FRAM_BASE 0xac000000
  16. #define FRAM_SIZE 0x20000
  17. /*
  18. * The are the file operation function for user access to /dev/fram
  19. */
  20. static int fram_mmap(struct file *filp, struct vm_area_struct *vma)
  21. {
  22. int ret;
  23. ret = remap_pfn_range(vma,
  24. vma->vm_start,
  25. virt_to_phys((void *)((unsigned long)FRAM_BASE)) >> PAGE_SHIFT,
  26. vma->vm_end-vma->vm_start,
  27. PAGE_SHARED);
  28. if (ret != 0)
  29. return -EAGAIN;
  30. return 0;
  31. }
  32. static const struct file_operations fram_fops = {
  33. .owner = THIS_MODULE,
  34. .mmap = fram_mmap,
  35. .llseek = noop_llseek,
  36. };
  37. #define FRAM_MINOR 0
  38. static struct miscdevice fram_dev = {
  39. FRAM_MINOR,
  40. "fram",
  41. &fram_fops
  42. };
  43. static int __init
  44. fram_init(void)
  45. {
  46. int ret;
  47. ret = misc_register(&fram_dev);
  48. if (ret) {
  49. printk(KERN_ERR "fram: can't misc_register on minor=%d\n",
  50. FRAM_MINOR);
  51. return ret;
  52. }
  53. printk(KERN_INFO "FRAM memory driver v" FRAM_VERSION "\n");
  54. return 0;
  55. }
  56. static void __exit
  57. fram_cleanup_module(void)
  58. {
  59. misc_deregister(&fram_dev);
  60. }
  61. module_init(fram_init);
  62. module_exit(fram_cleanup_module);
  63. MODULE_LICENSE("GPL");
  64. MODULE_ALIAS_MISCDEV(FRAM_MINOR);