cfag12864bfb.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 <ojeda@kernel.org>
  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. vma->vm_page_prot = pgprot_decrypted(vma->vm_page_prot);
  49. return vm_map_pages_zero(vma, &pages, 1);
  50. }
  51. static const struct fb_ops cfag12864bfb_ops = {
  52. .owner = THIS_MODULE,
  53. __FB_DEFAULT_SYSMEM_OPS_RDWR,
  54. __FB_DEFAULT_SYSMEM_OPS_DRAW,
  55. .fb_mmap = cfag12864bfb_mmap,
  56. };
  57. static int cfag12864bfb_probe(struct platform_device *device)
  58. {
  59. int ret = -EINVAL;
  60. struct fb_info *info = framebuffer_alloc(0, &device->dev);
  61. if (!info)
  62. goto none;
  63. info->flags = FBINFO_VIRTFB;
  64. info->screen_buffer = cfag12864b_buffer;
  65. info->screen_size = CFAG12864B_SIZE;
  66. info->fbops = &cfag12864bfb_ops;
  67. info->fix = cfag12864bfb_fix;
  68. info->var = cfag12864bfb_var;
  69. info->pseudo_palette = NULL;
  70. info->par = NULL;
  71. if (register_framebuffer(info) < 0)
  72. goto fballoced;
  73. platform_set_drvdata(device, info);
  74. fb_info(info, "%s frame buffer device\n", info->fix.id);
  75. return 0;
  76. fballoced:
  77. framebuffer_release(info);
  78. none:
  79. return ret;
  80. }
  81. static void cfag12864bfb_remove(struct platform_device *device)
  82. {
  83. struct fb_info *info = platform_get_drvdata(device);
  84. if (info) {
  85. unregister_framebuffer(info);
  86. framebuffer_release(info);
  87. }
  88. }
  89. static struct platform_driver cfag12864bfb_driver = {
  90. .probe = cfag12864bfb_probe,
  91. .remove = cfag12864bfb_remove,
  92. .driver = {
  93. .name = CFAG12864BFB_NAME,
  94. },
  95. };
  96. static struct platform_device *cfag12864bfb_device;
  97. static int __init cfag12864bfb_init(void)
  98. {
  99. int ret = -EINVAL;
  100. /* cfag12864b_init() must be called first */
  101. if (!cfag12864b_isinited()) {
  102. printk(KERN_ERR CFAG12864BFB_NAME ": ERROR: "
  103. "cfag12864b is not initialized\n");
  104. goto none;
  105. }
  106. if (cfag12864b_enable()) {
  107. printk(KERN_ERR CFAG12864BFB_NAME ": ERROR: "
  108. "can't enable cfag12864b refreshing (being used)\n");
  109. return -ENODEV;
  110. }
  111. ret = platform_driver_register(&cfag12864bfb_driver);
  112. if (!ret) {
  113. cfag12864bfb_device =
  114. platform_device_alloc(CFAG12864BFB_NAME, 0);
  115. if (cfag12864bfb_device)
  116. ret = platform_device_add(cfag12864bfb_device);
  117. else
  118. ret = -ENOMEM;
  119. if (ret) {
  120. platform_device_put(cfag12864bfb_device);
  121. platform_driver_unregister(&cfag12864bfb_driver);
  122. }
  123. }
  124. none:
  125. return ret;
  126. }
  127. static void __exit cfag12864bfb_exit(void)
  128. {
  129. platform_device_unregister(cfag12864bfb_device);
  130. platform_driver_unregister(&cfag12864bfb_driver);
  131. cfag12864b_disable();
  132. }
  133. module_init(cfag12864bfb_init);
  134. module_exit(cfag12864bfb_exit);
  135. MODULE_LICENSE("GPL v2");
  136. MODULE_AUTHOR("Miguel Ojeda <ojeda@kernel.org>");
  137. MODULE_DESCRIPTION("cfag12864b LCD framebuffer driver");