1351f683bSMiguel Ojeda // SPDX-License-Identifier: GPL-2.0
270e84049SMiguel Ojeda Sandonis /*
370e84049SMiguel Ojeda Sandonis * Filename: cfag12864bfb.c
470e84049SMiguel Ojeda Sandonis * Version: 0.1.0
570e84049SMiguel Ojeda Sandonis * Description: cfag12864b LCD framebuffer driver
670e84049SMiguel Ojeda Sandonis * Depends: cfag12864b
770e84049SMiguel Ojeda Sandonis *
8c131bd0bSMiguel Ojeda * Author: Copyright (C) Miguel Ojeda <ojeda@kernel.org>
970e84049SMiguel Ojeda Sandonis * Date: 2006-10-31
1070e84049SMiguel Ojeda Sandonis */
1170e84049SMiguel Ojeda Sandonis
1270e84049SMiguel Ojeda Sandonis #include <linux/init.h>
1370e84049SMiguel Ojeda Sandonis #include <linux/module.h>
1470e84049SMiguel Ojeda Sandonis #include <linux/kernel.h>
1570e84049SMiguel Ojeda Sandonis #include <linux/errno.h>
1670e84049SMiguel Ojeda Sandonis #include <linux/fb.h>
1770e84049SMiguel Ojeda Sandonis #include <linux/mm.h>
1870e84049SMiguel Ojeda Sandonis #include <linux/platform_device.h>
1970e84049SMiguel Ojeda Sandonis #include <linux/cfag12864b.h>
2070e84049SMiguel Ojeda Sandonis
2170e84049SMiguel Ojeda Sandonis #define CFAG12864BFB_NAME "cfag12864bfb"
2270e84049SMiguel Ojeda Sandonis
237223310fSGustavo A. R. Silva static const struct fb_fix_screeninfo cfag12864bfb_fix = {
2470e84049SMiguel Ojeda Sandonis .id = "cfag12864b",
2570e84049SMiguel Ojeda Sandonis .type = FB_TYPE_PACKED_PIXELS,
2670e84049SMiguel Ojeda Sandonis .visual = FB_VISUAL_MONO10,
2770e84049SMiguel Ojeda Sandonis .xpanstep = 0,
2870e84049SMiguel Ojeda Sandonis .ypanstep = 0,
2970e84049SMiguel Ojeda Sandonis .ywrapstep = 0,
3070e84049SMiguel Ojeda Sandonis .line_length = CFAG12864B_WIDTH / 8,
3170e84049SMiguel Ojeda Sandonis .accel = FB_ACCEL_NONE,
3270e84049SMiguel Ojeda Sandonis };
3370e84049SMiguel Ojeda Sandonis
347223310fSGustavo A. R. Silva static const struct fb_var_screeninfo cfag12864bfb_var = {
3570e84049SMiguel Ojeda Sandonis .xres = CFAG12864B_WIDTH,
3670e84049SMiguel Ojeda Sandonis .yres = CFAG12864B_HEIGHT,
3770e84049SMiguel Ojeda Sandonis .xres_virtual = CFAG12864B_WIDTH,
3870e84049SMiguel Ojeda Sandonis .yres_virtual = CFAG12864B_HEIGHT,
3970e84049SMiguel Ojeda Sandonis .bits_per_pixel = 1,
4070e84049SMiguel Ojeda Sandonis .red = { 0, 1, 0 },
4170e84049SMiguel Ojeda Sandonis .green = { 0, 1, 0 },
4270e84049SMiguel Ojeda Sandonis .blue = { 0, 1, 0 },
4370e84049SMiguel Ojeda Sandonis .left_margin = 0,
4470e84049SMiguel Ojeda Sandonis .right_margin = 0,
4570e84049SMiguel Ojeda Sandonis .upper_margin = 0,
4670e84049SMiguel Ojeda Sandonis .lower_margin = 0,
4770e84049SMiguel Ojeda Sandonis .vmode = FB_VMODE_NONINTERLACED,
4870e84049SMiguel Ojeda Sandonis };
4970e84049SMiguel Ojeda Sandonis
cfag12864bfb_mmap(struct fb_info * info,struct vm_area_struct * vma)5070e84049SMiguel Ojeda Sandonis static int cfag12864bfb_mmap(struct fb_info *info, struct vm_area_struct *vma)
5170e84049SMiguel Ojeda Sandonis {
52461e274bSSouptick Joarder struct page *pages = virt_to_page(cfag12864b_buffer);
53461e274bSSouptick Joarder
5476f92201SThomas Zimmermann vma->vm_page_prot = pgprot_decrypted(vma->vm_page_prot);
5576f92201SThomas Zimmermann
56461e274bSSouptick Joarder return vm_map_pages_zero(vma, &pages, 1);
5770e84049SMiguel Ojeda Sandonis }
5870e84049SMiguel Ojeda Sandonis
59bd223ac6SJani Nikula static const struct fb_ops cfag12864bfb_ops = {
6070e84049SMiguel Ojeda Sandonis .owner = THIS_MODULE,
6136e6cacdSThomas Zimmermann __FB_DEFAULT_SYSMEM_OPS_RDWR,
6236e6cacdSThomas Zimmermann __FB_DEFAULT_SYSMEM_OPS_DRAW,
6370e84049SMiguel Ojeda Sandonis .fb_mmap = cfag12864bfb_mmap,
6470e84049SMiguel Ojeda Sandonis };
6570e84049SMiguel Ojeda Sandonis
cfag12864bfb_probe(struct platform_device * device)660fe763c5SGreg Kroah-Hartman static int cfag12864bfb_probe(struct platform_device *device)
6770e84049SMiguel Ojeda Sandonis {
6870e84049SMiguel Ojeda Sandonis int ret = -EINVAL;
6970e84049SMiguel Ojeda Sandonis struct fb_info *info = framebuffer_alloc(0, &device->dev);
7070e84049SMiguel Ojeda Sandonis
7170e84049SMiguel Ojeda Sandonis if (!info)
7270e84049SMiguel Ojeda Sandonis goto none;
7370e84049SMiguel Ojeda Sandonis
74eba14189SThomas Zimmermann info->flags = FBINFO_VIRTFB;
7511f373c3SThomas Zimmermann info->screen_buffer = cfag12864b_buffer;
7670e84049SMiguel Ojeda Sandonis info->screen_size = CFAG12864B_SIZE;
7770e84049SMiguel Ojeda Sandonis info->fbops = &cfag12864bfb_ops;
7870e84049SMiguel Ojeda Sandonis info->fix = cfag12864bfb_fix;
7970e84049SMiguel Ojeda Sandonis info->var = cfag12864bfb_var;
8070e84049SMiguel Ojeda Sandonis info->pseudo_palette = NULL;
8170e84049SMiguel Ojeda Sandonis info->par = NULL;
8270e84049SMiguel Ojeda Sandonis
8370e84049SMiguel Ojeda Sandonis if (register_framebuffer(info) < 0)
8470e84049SMiguel Ojeda Sandonis goto fballoced;
8570e84049SMiguel Ojeda Sandonis
8670e84049SMiguel Ojeda Sandonis platform_set_drvdata(device, info);
8770e84049SMiguel Ojeda Sandonis
8831b6780cSJoe Perches fb_info(info, "%s frame buffer device\n", info->fix.id);
8970e84049SMiguel Ojeda Sandonis
9070e84049SMiguel Ojeda Sandonis return 0;
9170e84049SMiguel Ojeda Sandonis
9270e84049SMiguel Ojeda Sandonis fballoced:
9370e84049SMiguel Ojeda Sandonis framebuffer_release(info);
9470e84049SMiguel Ojeda Sandonis
9570e84049SMiguel Ojeda Sandonis none:
9670e84049SMiguel Ojeda Sandonis return ret;
9770e84049SMiguel Ojeda Sandonis }
9870e84049SMiguel Ojeda Sandonis
cfag12864bfb_remove(struct platform_device * device)99*07d03559SUwe Kleine-König static void cfag12864bfb_remove(struct platform_device *device)
10070e84049SMiguel Ojeda Sandonis {
10170e84049SMiguel Ojeda Sandonis struct fb_info *info = platform_get_drvdata(device);
10270e84049SMiguel Ojeda Sandonis
10370e84049SMiguel Ojeda Sandonis if (info) {
10470e84049SMiguel Ojeda Sandonis unregister_framebuffer(info);
10570e84049SMiguel Ojeda Sandonis framebuffer_release(info);
10670e84049SMiguel Ojeda Sandonis }
10770e84049SMiguel Ojeda Sandonis }
10870e84049SMiguel Ojeda Sandonis
10970e84049SMiguel Ojeda Sandonis static struct platform_driver cfag12864bfb_driver = {
11070e84049SMiguel Ojeda Sandonis .probe = cfag12864bfb_probe,
111*07d03559SUwe Kleine-König .remove_new = cfag12864bfb_remove,
11270e84049SMiguel Ojeda Sandonis .driver = {
11370e84049SMiguel Ojeda Sandonis .name = CFAG12864BFB_NAME,
11470e84049SMiguel Ojeda Sandonis },
11570e84049SMiguel Ojeda Sandonis };
11670e84049SMiguel Ojeda Sandonis
11770e84049SMiguel Ojeda Sandonis static struct platform_device *cfag12864bfb_device;
11870e84049SMiguel Ojeda Sandonis
cfag12864bfb_init(void)11970e84049SMiguel Ojeda Sandonis static int __init cfag12864bfb_init(void)
12070e84049SMiguel Ojeda Sandonis {
12134173a4aSMiguel Ojeda int ret = -EINVAL;
12234173a4aSMiguel Ojeda
12334173a4aSMiguel Ojeda /* cfag12864b_init() must be called first */
12434173a4aSMiguel Ojeda if (!cfag12864b_isinited()) {
12534173a4aSMiguel Ojeda printk(KERN_ERR CFAG12864BFB_NAME ": ERROR: "
12634173a4aSMiguel Ojeda "cfag12864b is not initialized\n");
12734173a4aSMiguel Ojeda goto none;
12834173a4aSMiguel Ojeda }
12970e84049SMiguel Ojeda Sandonis
13070e84049SMiguel Ojeda Sandonis if (cfag12864b_enable()) {
13170e84049SMiguel Ojeda Sandonis printk(KERN_ERR CFAG12864BFB_NAME ": ERROR: "
13270e84049SMiguel Ojeda Sandonis "can't enable cfag12864b refreshing (being used)\n");
13370e84049SMiguel Ojeda Sandonis return -ENODEV;
13470e84049SMiguel Ojeda Sandonis }
13570e84049SMiguel Ojeda Sandonis
13670e84049SMiguel Ojeda Sandonis ret = platform_driver_register(&cfag12864bfb_driver);
13770e84049SMiguel Ojeda Sandonis
13870e84049SMiguel Ojeda Sandonis if (!ret) {
13970e84049SMiguel Ojeda Sandonis cfag12864bfb_device =
14070e84049SMiguel Ojeda Sandonis platform_device_alloc(CFAG12864BFB_NAME, 0);
14170e84049SMiguel Ojeda Sandonis
14270e84049SMiguel Ojeda Sandonis if (cfag12864bfb_device)
14370e84049SMiguel Ojeda Sandonis ret = platform_device_add(cfag12864bfb_device);
14470e84049SMiguel Ojeda Sandonis else
14570e84049SMiguel Ojeda Sandonis ret = -ENOMEM;
14670e84049SMiguel Ojeda Sandonis
14770e84049SMiguel Ojeda Sandonis if (ret) {
14870e84049SMiguel Ojeda Sandonis platform_device_put(cfag12864bfb_device);
14970e84049SMiguel Ojeda Sandonis platform_driver_unregister(&cfag12864bfb_driver);
15070e84049SMiguel Ojeda Sandonis }
15170e84049SMiguel Ojeda Sandonis }
15270e84049SMiguel Ojeda Sandonis
15334173a4aSMiguel Ojeda none:
15470e84049SMiguel Ojeda Sandonis return ret;
15570e84049SMiguel Ojeda Sandonis }
15670e84049SMiguel Ojeda Sandonis
cfag12864bfb_exit(void)15770e84049SMiguel Ojeda Sandonis static void __exit cfag12864bfb_exit(void)
15870e84049SMiguel Ojeda Sandonis {
15970e84049SMiguel Ojeda Sandonis platform_device_unregister(cfag12864bfb_device);
16070e84049SMiguel Ojeda Sandonis platform_driver_unregister(&cfag12864bfb_driver);
16170e84049SMiguel Ojeda Sandonis cfag12864b_disable();
16270e84049SMiguel Ojeda Sandonis }
16370e84049SMiguel Ojeda Sandonis
16470e84049SMiguel Ojeda Sandonis module_init(cfag12864bfb_init);
16570e84049SMiguel Ojeda Sandonis module_exit(cfag12864bfb_exit);
16670e84049SMiguel Ojeda Sandonis
16770e84049SMiguel Ojeda Sandonis MODULE_LICENSE("GPL v2");
168c131bd0bSMiguel Ojeda MODULE_AUTHOR("Miguel Ojeda <ojeda@kernel.org>");
16970e84049SMiguel Ojeda Sandonis MODULE_DESCRIPTION("cfag12864b LCD framebuffer driver");
170