fram.c 1.5 KB

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