fram.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. };
  36. #define FRAM_MINOR 0
  37. static struct miscdevice fram_dev = {
  38. FRAM_MINOR,
  39. "fram",
  40. &fram_fops
  41. };
  42. static int __init
  43. fram_init(void)
  44. {
  45. int ret;
  46. ret = misc_register(&fram_dev);
  47. if (ret) {
  48. printk(KERN_ERR "fram: can't misc_register on minor=%d\n",
  49. FRAM_MINOR);
  50. return ret;
  51. }
  52. printk(KERN_INFO "FRAM memory driver v" FRAM_VERSION "\n");
  53. return 0;
  54. }
  55. static void __exit
  56. fram_cleanup_module(void)
  57. {
  58. misc_deregister(&fram_dev);
  59. }
  60. module_init(fram_init);
  61. module_exit(fram_cleanup_module);
  62. MODULE_LICENSE("GPL");
  63. MODULE_ALIAS_MISCDEV(FRAM_MINOR);