cfag12864bfb.c 4.5 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/slab.h>
  34. #include <linux/string.h>
  35. #include <linux/uaccess.h>
  36. #include <linux/cfag12864b.h>
  37. #define CFAG12864BFB_NAME "cfag12864bfb"
  38. static struct fb_fix_screeninfo cfag12864bfb_fix __initdata = {
  39. .id = "cfag12864b",
  40. .type = FB_TYPE_PACKED_PIXELS,
  41. .visual = FB_VISUAL_MONO10,
  42. .xpanstep = 0,
  43. .ypanstep = 0,
  44. .ywrapstep = 0,
  45. .line_length = CFAG12864B_WIDTH / 8,
  46. .accel = FB_ACCEL_NONE,
  47. };
  48. static struct fb_var_screeninfo cfag12864bfb_var __initdata = {
  49. .xres = CFAG12864B_WIDTH,
  50. .yres = CFAG12864B_HEIGHT,
  51. .xres_virtual = CFAG12864B_WIDTH,
  52. .yres_virtual = CFAG12864B_HEIGHT,
  53. .bits_per_pixel = 1,
  54. .red = { 0, 1, 0 },
  55. .green = { 0, 1, 0 },
  56. .blue = { 0, 1, 0 },
  57. .left_margin = 0,
  58. .right_margin = 0,
  59. .upper_margin = 0,
  60. .lower_margin = 0,
  61. .vmode = FB_VMODE_NONINTERLACED,
  62. };
  63. static int cfag12864bfb_mmap(struct fb_info *info, struct vm_area_struct *vma)
  64. {
  65. return vm_insert_page(vma, vma->vm_start,
  66. virt_to_page(cfag12864b_buffer));
  67. }
  68. static struct fb_ops cfag12864bfb_ops = {
  69. .owner = THIS_MODULE,
  70. .fb_read = fb_sys_read,
  71. .fb_write = fb_sys_write,
  72. .fb_fillrect = sys_fillrect,
  73. .fb_copyarea = sys_copyarea,
  74. .fb_imageblit = sys_imageblit,
  75. .fb_mmap = cfag12864bfb_mmap,
  76. };
  77. static int __init cfag12864bfb_probe(struct platform_device *device)
  78. {
  79. int ret = -EINVAL;
  80. struct fb_info *info = framebuffer_alloc(0, &device->dev);
  81. if (!info)
  82. goto none;
  83. info->screen_base = (char __iomem *) cfag12864b_buffer;
  84. info->screen_size = CFAG12864B_SIZE;
  85. info->fbops = &cfag12864bfb_ops;
  86. info->fix = cfag12864bfb_fix;
  87. info->var = cfag12864bfb_var;
  88. info->pseudo_palette = NULL;
  89. info->par = NULL;
  90. info->flags = FBINFO_FLAG_DEFAULT;
  91. if (register_framebuffer(info) < 0)
  92. goto fballoced;
  93. platform_set_drvdata(device, info);
  94. printk(KERN_INFO "fb%d: %s frame buffer device\n", info->node,
  95. info->fix.id);
  96. return 0;
  97. fballoced:
  98. framebuffer_release(info);
  99. none:
  100. return ret;
  101. }
  102. static int cfag12864bfb_remove(struct platform_device *device)
  103. {
  104. struct fb_info *info = platform_get_drvdata(device);
  105. if (info) {
  106. unregister_framebuffer(info);
  107. framebuffer_release(info);
  108. }
  109. return 0;
  110. }
  111. static struct platform_driver cfag12864bfb_driver = {
  112. .probe = cfag12864bfb_probe,
  113. .remove = cfag12864bfb_remove,
  114. .driver = {
  115. .name = CFAG12864BFB_NAME,
  116. },
  117. };
  118. static struct platform_device *cfag12864bfb_device;
  119. static int __init cfag12864bfb_init(void)
  120. {
  121. int ret = -EINVAL;
  122. /* cfag12864b_init() must be called first */
  123. if (!cfag12864b_isinited()) {
  124. printk(KERN_ERR CFAG12864BFB_NAME ": ERROR: "
  125. "cfag12864b is not initialized\n");
  126. goto none;
  127. }
  128. if (cfag12864b_enable()) {
  129. printk(KERN_ERR CFAG12864BFB_NAME ": ERROR: "
  130. "can't enable cfag12864b refreshing (being used)\n");
  131. return -ENODEV;
  132. }
  133. ret = platform_driver_register(&cfag12864bfb_driver);
  134. if (!ret) {
  135. cfag12864bfb_device =
  136. platform_device_alloc(CFAG12864BFB_NAME, 0);
  137. if (cfag12864bfb_device)
  138. ret = platform_device_add(cfag12864bfb_device);
  139. else
  140. ret = -ENOMEM;
  141. if (ret) {
  142. platform_device_put(cfag12864bfb_device);
  143. platform_driver_unregister(&cfag12864bfb_driver);
  144. }
  145. }
  146. none:
  147. return ret;
  148. }
  149. static void __exit cfag12864bfb_exit(void)
  150. {
  151. platform_device_unregister(cfag12864bfb_device);
  152. platform_driver_unregister(&cfag12864bfb_driver);
  153. cfag12864b_disable();
  154. }
  155. module_init(cfag12864bfb_init);
  156. module_exit(cfag12864bfb_exit);
  157. MODULE_LICENSE("GPL v2");
  158. MODULE_AUTHOR("Miguel Ojeda Sandonis <miguel.ojeda.sandonis@gmail.com>");
  159. MODULE_DESCRIPTION("cfag12864b LCD framebuffer driver");