cfag12864bfb.c 3.8 KB

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