1 // SPDX-License-Identifier: GPL-2.0
3 * Filename: cfag12864bfb.c
5 * Description: cfag12864b LCD framebuffer driver
8 * Author: Copyright (C) Miguel Ojeda <ojeda@kernel.org>
12 #include <linux/init.h>
13 #include <linux/module.h>
14 #include <linux/kernel.h>
15 #include <linux/errno.h>
18 #include <linux/platform_device.h>
19 #include <linux/cfag12864b.h>
21 #define CFAG12864BFB_NAME "cfag12864bfb"
23 static const struct fb_fix_screeninfo cfag12864bfb_fix = {
25 .type = FB_TYPE_PACKED_PIXELS,
26 .visual = FB_VISUAL_MONO10,
30 .line_length = CFAG12864B_WIDTH / 8,
31 .accel = FB_ACCEL_NONE,
34 static const struct fb_var_screeninfo cfag12864bfb_var = {
35 .xres = CFAG12864B_WIDTH,
36 .yres = CFAG12864B_HEIGHT,
37 .xres_virtual = CFAG12864B_WIDTH,
38 .yres_virtual = CFAG12864B_HEIGHT,
47 .vmode = FB_VMODE_NONINTERLACED,
50 static int cfag12864bfb_mmap(struct fb_info *info, struct vm_area_struct *vma)
52 struct page *pages = virt_to_page(cfag12864b_buffer);
54 return vm_map_pages_zero(vma, &pages, 1);
57 static const struct fb_ops cfag12864bfb_ops = {
59 .fb_read = fb_sys_read,
60 .fb_write = fb_sys_write,
61 .fb_fillrect = sys_fillrect,
62 .fb_copyarea = sys_copyarea,
63 .fb_imageblit = sys_imageblit,
64 .fb_mmap = cfag12864bfb_mmap,
67 static int cfag12864bfb_probe(struct platform_device *device)
70 struct fb_info *info = framebuffer_alloc(0, &device->dev);
75 info->screen_buffer = cfag12864b_buffer;
76 info->screen_size = CFAG12864B_SIZE;
77 info->fbops = &cfag12864bfb_ops;
78 info->fix = cfag12864bfb_fix;
79 info->var = cfag12864bfb_var;
80 info->pseudo_palette = NULL;
83 if (register_framebuffer(info) < 0)
86 platform_set_drvdata(device, info);
88 fb_info(info, "%s frame buffer device\n", info->fix.id);
93 framebuffer_release(info);
99 static int cfag12864bfb_remove(struct platform_device *device)
101 struct fb_info *info = platform_get_drvdata(device);
104 unregister_framebuffer(info);
105 framebuffer_release(info);
111 static struct platform_driver cfag12864bfb_driver = {
112 .probe = cfag12864bfb_probe,
113 .remove = cfag12864bfb_remove,
115 .name = CFAG12864BFB_NAME,
119 static struct platform_device *cfag12864bfb_device;
121 static int __init cfag12864bfb_init(void)
125 /* cfag12864b_init() must be called first */
126 if (!cfag12864b_isinited()) {
127 printk(KERN_ERR CFAG12864BFB_NAME ": ERROR: "
128 "cfag12864b is not initialized\n");
132 if (cfag12864b_enable()) {
133 printk(KERN_ERR CFAG12864BFB_NAME ": ERROR: "
134 "can't enable cfag12864b refreshing (being used)\n");
138 ret = platform_driver_register(&cfag12864bfb_driver);
141 cfag12864bfb_device =
142 platform_device_alloc(CFAG12864BFB_NAME, 0);
144 if (cfag12864bfb_device)
145 ret = platform_device_add(cfag12864bfb_device);
150 platform_device_put(cfag12864bfb_device);
151 platform_driver_unregister(&cfag12864bfb_driver);
159 static void __exit cfag12864bfb_exit(void)
161 platform_device_unregister(cfag12864bfb_device);
162 platform_driver_unregister(&cfag12864bfb_driver);
163 cfag12864b_disable();
166 module_init(cfag12864bfb_init);
167 module_exit(cfag12864bfb_exit);
169 MODULE_LICENSE("GPL v2");
170 MODULE_AUTHOR("Miguel Ojeda <ojeda@kernel.org>");
171 MODULE_DESCRIPTION("cfag12864b LCD framebuffer driver");