cfag12864bfb.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. * Filename: cfag12864bfb.c
  3. * Version: 0.1.0
  4. * Description: cfag12864b LCD framebuffer driver
  5. * License: GPLv2
  6. * Depends: cfag12864b
  7. *
  8. * Author: Copyright (C) Miguel Ojeda Sandonis
  9. * Date: 2006-10-31
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License version 2 as
  13. * published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. *
  24. */
  25. #include <linux/init.h>
  26. #include <linux/module.h>
  27. #include <linux/kernel.h>
  28. #include <linux/delay.h>
  29. #include <linux/errno.h>
  30. #include <linux/fb.h>
  31. #include <linux/mm.h>
  32. #include <linux/platform_device.h>
  33. #include <linux/string.h>
  34. #include <linux/uaccess.h>
  35. #include <linux/cfag12864b.h>
  36. #define CFAG12864BFB_NAME "cfag12864bfb"
  37. static struct fb_fix_screeninfo cfag12864bfb_fix = {
  38. .id = "cfag12864b",
  39. .type = FB_TYPE_PACKED_PIXELS,
  40. .visual = FB_VISUAL_MONO10,
  41. .xpanstep = 0,
  42. .ypanstep = 0,
  43. .ywrapstep = 0,
  44. .line_length = CFAG12864B_WIDTH / 8,
  45. .accel = FB_ACCEL_NONE,
  46. };
  47. static struct fb_var_screeninfo cfag12864bfb_var = {
  48. .xres = CFAG12864B_WIDTH,
  49. .yres = CFAG12864B_HEIGHT,
  50. .xres_virtual = CFAG12864B_WIDTH,
  51. .yres_virtual = CFAG12864B_HEIGHT,
  52. .bits_per_pixel = 1,
  53. .red = { 0, 1, 0 },
  54. .green = { 0, 1, 0 },
  55. .blue = { 0, 1, 0 },
  56. .left_margin = 0,
  57. .right_margin = 0,
  58. .upper_margin = 0,
  59. .lower_margin = 0,
  60. .vmode = FB_VMODE_NONINTERLACED,
  61. };
  62. static int cfag12864bfb_mmap(struct fb_info *info, struct vm_area_struct *vma)
  63. {
  64. return vm_insert_page(vma, vma->vm_start,
  65. virt_to_page(cfag12864b_buffer));
  66. }
  67. static struct fb_ops cfag12864bfb_ops = {
  68. .owner = THIS_MODULE,
  69. .fb_read = fb_sys_read,
  70. .fb_write = fb_sys_write,
  71. .fb_fillrect = sys_fillrect,
  72. .fb_copyarea = sys_copyarea,
  73. .fb_imageblit = sys_imageblit,
  74. .fb_mmap = cfag12864bfb_mmap,
  75. };
  76. static int cfag12864bfb_probe(struct platform_device *device)
  77. {
  78. int ret = -EINVAL;
  79. struct fb_info *info = framebuffer_alloc(0, &device->dev);
  80. if (!info)
  81. goto none;
  82. info->screen_base = (char __iomem *) cfag12864b_buffer;
  83. info->screen_size = CFAG12864B_SIZE;
  84. info->fbops = &cfag12864bfb_ops;
  85. info->fix = cfag12864bfb_fix;
  86. info->var = cfag12864bfb_var;
  87. info->pseudo_palette = NULL;
  88. info->par = NULL;
  89. info->flags = FBINFO_FLAG_DEFAULT;
  90. if (register_framebuffer(info) < 0)
  91. goto fballoced;
  92. platform_set_drvdata(device, info);
  93. fb_info(info, "%s frame buffer device\n", info->fix.id);
  94. return 0;
  95. fballoced:
  96. framebuffer_release(info);
  97. none:
  98. return ret;
  99. }
  100. static int cfag12864bfb_remove(struct platform_device *device)
  101. {
  102. struct fb_info *info = platform_get_drvdata(device);
  103. if (info) {
  104. unregister_framebuffer(info);
  105. framebuffer_release(info);
  106. }
  107. return 0;
  108. }
  109. static struct platform_driver cfag12864bfb_driver = {
  110. .probe = cfag12864bfb_probe,
  111. .remove = cfag12864bfb_remove,
  112. .driver = {
  113. .name = CFAG12864BFB_NAME,
  114. },
  115. };
  116. static struct platform_device *cfag12864bfb_device;
  117. static int __init cfag12864bfb_init(void)
  118. {
  119. int ret = -EINVAL;
  120. /* cfag12864b_init() must be called first */
  121. if (!cfag12864b_isinited()) {
  122. printk(KERN_ERR CFAG12864BFB_NAME ": ERROR: "
  123. "cfag12864b is not initialized\n");
  124. goto none;
  125. }
  126. if (cfag12864b_enable()) {
  127. printk(KERN_ERR CFAG12864BFB_NAME ": ERROR: "
  128. "can't enable cfag12864b refreshing (being used)\n");
  129. return -ENODEV;
  130. }
  131. ret = platform_driver_register(&cfag12864bfb_driver);
  132. if (!ret) {
  133. cfag12864bfb_device =
  134. platform_device_alloc(CFAG12864BFB_NAME, 0);
  135. if (cfag12864bfb_device)
  136. ret = platform_device_add(cfag12864bfb_device);
  137. else
  138. ret = -ENOMEM;
  139. if (ret) {
  140. platform_device_put(cfag12864bfb_device);
  141. platform_driver_unregister(&cfag12864bfb_driver);
  142. }
  143. }
  144. none:
  145. return ret;
  146. }
  147. static void __exit cfag12864bfb_exit(void)
  148. {
  149. platform_device_unregister(cfag12864bfb_device);
  150. platform_driver_unregister(&cfag12864bfb_driver);
  151. cfag12864b_disable();
  152. }
  153. module_init(cfag12864bfb_init);
  154. module_exit(cfag12864bfb_exit);
  155. MODULE_LICENSE("GPL v2");
  156. MODULE_AUTHOR("Miguel Ojeda Sandonis <miguel.ojeda.sandonis@gmail.com>");
  157. MODULE_DESCRIPTION("cfag12864b LCD framebuffer driver");