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 <maxextreme@gmail.com>
  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_fillrect = cfb_fillrect,
  71. .fb_copyarea = cfb_copyarea,
  72. .fb_imageblit = cfb_imageblit,
  73. .fb_mmap = cfag12864bfb_mmap,
  74. };
  75. static int __init cfag12864bfb_probe(struct platform_device *device)
  76. {
  77. int ret = -EINVAL;
  78. struct fb_info *info = framebuffer_alloc(0, &device->dev);
  79. if (!info)
  80. goto none;
  81. info->screen_base = (char __iomem *) cfag12864b_buffer;
  82. info->screen_size = CFAG12864B_SIZE;
  83. info->fbops = &cfag12864bfb_ops;
  84. info->fix = cfag12864bfb_fix;
  85. info->var = cfag12864bfb_var;
  86. info->pseudo_palette = NULL;
  87. info->par = NULL;
  88. info->flags = FBINFO_FLAG_DEFAULT;
  89. if (register_framebuffer(info) < 0)
  90. goto fballoced;
  91. platform_set_drvdata(device, info);
  92. printk(KERN_INFO "fb%d: %s frame buffer device\n", info->node,
  93. 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 <maxextreme@gmail.com>");
  157. MODULE_DESCRIPTION("cfag12864b LCD framebuffer driver");