cfag12864bfb.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Filename: cfag12864bfb.c
  4. * Version: 0.1.0
  5. * Description: cfag12864b LCD framebuffer driver
  6. * Depends: cfag12864b
  7. *
  8. * Author: Copyright (C) Miguel Ojeda Sandonis
  9. * Date: 2006-10-31
  10. */
  11. #include <linux/init.h>
  12. #include <linux/module.h>
  13. #include <linux/kernel.h>
  14. #include <linux/delay.h>
  15. #include <linux/errno.h>
  16. #include <linux/fb.h>
  17. #include <linux/mm.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/string.h>
  20. #include <linux/uaccess.h>
  21. #include <linux/cfag12864b.h>
  22. #define CFAG12864BFB_NAME "cfag12864bfb"
  23. static const struct fb_fix_screeninfo cfag12864bfb_fix = {
  24. .id = "cfag12864b",
  25. .type = FB_TYPE_PACKED_PIXELS,
  26. .visual = FB_VISUAL_MONO10,
  27. .xpanstep = 0,
  28. .ypanstep = 0,
  29. .ywrapstep = 0,
  30. .line_length = CFAG12864B_WIDTH / 8,
  31. .accel = FB_ACCEL_NONE,
  32. };
  33. static const struct fb_var_screeninfo cfag12864bfb_var = {
  34. .xres = CFAG12864B_WIDTH,
  35. .yres = CFAG12864B_HEIGHT,
  36. .xres_virtual = CFAG12864B_WIDTH,
  37. .yres_virtual = CFAG12864B_HEIGHT,
  38. .bits_per_pixel = 1,
  39. .red = { 0, 1, 0 },
  40. .green = { 0, 1, 0 },
  41. .blue = { 0, 1, 0 },
  42. .left_margin = 0,
  43. .right_margin = 0,
  44. .upper_margin = 0,
  45. .lower_margin = 0,
  46. .vmode = FB_VMODE_NONINTERLACED,
  47. };
  48. static int cfag12864bfb_mmap(struct fb_info *info, struct vm_area_struct *vma)
  49. {
  50. struct page *pages = virt_to_page(cfag12864b_buffer);
  51. return vm_map_pages_zero(vma, &pages, 1);
  52. }
  53. static const struct fb_ops cfag12864bfb_ops = {
  54. .owner = THIS_MODULE,
  55. .fb_read = fb_sys_read,
  56. .fb_write = fb_sys_write,
  57. .fb_fillrect = sys_fillrect,
  58. .fb_copyarea = sys_copyarea,
  59. .fb_imageblit = sys_imageblit,
  60. .fb_mmap = cfag12864bfb_mmap,
  61. };
  62. static int cfag12864bfb_probe(struct platform_device *device)
  63. {
  64. int ret = -EINVAL;
  65. struct fb_info *info = framebuffer_alloc(0, &device->dev);
  66. if (!info)
  67. goto none;
  68. info->screen_base = (char __iomem *) cfag12864b_buffer;
  69. info->screen_size = CFAG12864B_SIZE;
  70. info->fbops = &cfag12864bfb_ops;
  71. info->fix = cfag12864bfb_fix;
  72. info->var = cfag12864bfb_var;
  73. info->pseudo_palette = NULL;
  74. info->par = NULL;
  75. info->flags = FBINFO_FLAG_DEFAULT;
  76. if (register_framebuffer(info) < 0)
  77. goto fballoced;
  78. platform_set_drvdata(device, info);
  79. fb_info(info, "%s frame buffer device\n", info->fix.id);
  80. return 0;
  81. fballoced:
  82. framebuffer_release(info);
  83. none:
  84. return ret;
  85. }
  86. static int cfag12864bfb_remove(struct platform_device *device)
  87. {
  88. struct fb_info *info = platform_get_drvdata(device);
  89. if (info) {
  90. unregister_framebuffer(info);
  91. framebuffer_release(info);
  92. }
  93. return 0;
  94. }
  95. static struct platform_driver cfag12864bfb_driver = {
  96. .probe = cfag12864bfb_probe,
  97. .remove = cfag12864bfb_remove,
  98. .driver = {
  99. .name = CFAG12864BFB_NAME,
  100. },
  101. };
  102. static struct platform_device *cfag12864bfb_device;
  103. static int __init cfag12864bfb_init(void)
  104. {
  105. int ret = -EINVAL;
  106. /* cfag12864b_init() must be called first */
  107. if (!cfag12864b_isinited()) {
  108. printk(KERN_ERR CFAG12864BFB_NAME ": ERROR: "
  109. "cfag12864b is not initialized\n");
  110. goto none;
  111. }
  112. if (cfag12864b_enable()) {
  113. printk(KERN_ERR CFAG12864BFB_NAME ": ERROR: "
  114. "can't enable cfag12864b refreshing (being used)\n");
  115. return -ENODEV;
  116. }
  117. ret = platform_driver_register(&cfag12864bfb_driver);
  118. if (!ret) {
  119. cfag12864bfb_device =
  120. platform_device_alloc(CFAG12864BFB_NAME, 0);
  121. if (cfag12864bfb_device)
  122. ret = platform_device_add(cfag12864bfb_device);
  123. else
  124. ret = -ENOMEM;
  125. if (ret) {
  126. platform_device_put(cfag12864bfb_device);
  127. platform_driver_unregister(&cfag12864bfb_driver);
  128. }
  129. }
  130. none:
  131. return ret;
  132. }
  133. static void __exit cfag12864bfb_exit(void)
  134. {
  135. platform_device_unregister(cfag12864bfb_device);
  136. platform_driver_unregister(&cfag12864bfb_driver);
  137. cfag12864b_disable();
  138. }
  139. module_init(cfag12864bfb_init);
  140. module_exit(cfag12864bfb_exit);
  141. MODULE_LICENSE("GPL v2");
  142. MODULE_AUTHOR("Miguel Ojeda Sandonis <miguel.ojeda.sandonis@gmail.com>");
  143. MODULE_DESCRIPTION("cfag12864b LCD framebuffer driver");