cfag12864bfb.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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 __devinitdata = {
  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 __devinitdata = {
  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 __devinit 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. printk(KERN_INFO "fb%d: %s frame buffer device\n", info->node,
  94. info->fix.id);
  95. return 0;
  96. fballoced:
  97. framebuffer_release(info);
  98. none:
  99. return ret;
  100. }
  101. static int __devexit cfag12864bfb_remove(struct platform_device *device)
  102. {
  103. struct fb_info *info = platform_get_drvdata(device);
  104. if (info) {
  105. unregister_framebuffer(info);
  106. framebuffer_release(info);
  107. }
  108. return 0;
  109. }
  110. static struct platform_driver cfag12864bfb_driver = {
  111. .probe = cfag12864bfb_probe,
  112. .remove = __devexit_p(cfag12864bfb_remove),
  113. .driver = {
  114. .name = CFAG12864BFB_NAME,
  115. },
  116. };
  117. static struct platform_device *cfag12864bfb_device;
  118. static int __init cfag12864bfb_init(void)
  119. {
  120. int ret = -EINVAL;
  121. /* cfag12864b_init() must be called first */
  122. if (!cfag12864b_isinited()) {
  123. printk(KERN_ERR CFAG12864BFB_NAME ": ERROR: "
  124. "cfag12864b is not initialized\n");
  125. goto none;
  126. }
  127. if (cfag12864b_enable()) {
  128. printk(KERN_ERR CFAG12864BFB_NAME ": ERROR: "
  129. "can't enable cfag12864b refreshing (being used)\n");
  130. return -ENODEV;
  131. }
  132. ret = platform_driver_register(&cfag12864bfb_driver);
  133. if (!ret) {
  134. cfag12864bfb_device =
  135. platform_device_alloc(CFAG12864BFB_NAME, 0);
  136. if (cfag12864bfb_device)
  137. ret = platform_device_add(cfag12864bfb_device);
  138. else
  139. ret = -ENOMEM;
  140. if (ret) {
  141. platform_device_put(cfag12864bfb_device);
  142. platform_driver_unregister(&cfag12864bfb_driver);
  143. }
  144. }
  145. none:
  146. return ret;
  147. }
  148. static void __exit cfag12864bfb_exit(void)
  149. {
  150. platform_device_unregister(cfag12864bfb_device);
  151. platform_driver_unregister(&cfag12864bfb_driver);
  152. cfag12864b_disable();
  153. }
  154. module_init(cfag12864bfb_init);
  155. module_exit(cfag12864bfb_exit);
  156. MODULE_LICENSE("GPL v2");
  157. MODULE_AUTHOR("Miguel Ojeda Sandonis <miguel.ojeda.sandonis@gmail.com>");
  158. MODULE_DESCRIPTION("cfag12864b LCD framebuffer driver");