xref: /linux/drivers/auxdisplay/cfag12864bfb.c (revision 7223310f4ef3ba8a8b1b34983b565546cd5098ca)
170e84049SMiguel Ojeda Sandonis /*
270e84049SMiguel Ojeda Sandonis  *    Filename: cfag12864bfb.c
370e84049SMiguel Ojeda Sandonis  *     Version: 0.1.0
470e84049SMiguel Ojeda Sandonis  * Description: cfag12864b LCD framebuffer driver
570e84049SMiguel Ojeda Sandonis  *     License: GPLv2
670e84049SMiguel Ojeda Sandonis  *     Depends: cfag12864b
770e84049SMiguel Ojeda Sandonis  *
8450c622eSMiguel Ojeda  *      Author: Copyright (C) Miguel Ojeda Sandonis
970e84049SMiguel Ojeda Sandonis  *        Date: 2006-10-31
1070e84049SMiguel Ojeda Sandonis  *
1170e84049SMiguel Ojeda Sandonis  *  This program is free software; you can redistribute it and/or modify
1270e84049SMiguel Ojeda Sandonis  *  it under the terms of the GNU General Public License version 2 as
1370e84049SMiguel Ojeda Sandonis  *  published by the Free Software Foundation.
1470e84049SMiguel Ojeda Sandonis  *
1570e84049SMiguel Ojeda Sandonis  *  This program is distributed in the hope that it will be useful,
1670e84049SMiguel Ojeda Sandonis  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
1770e84049SMiguel Ojeda Sandonis  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1870e84049SMiguel Ojeda Sandonis  *  GNU General Public License for more details.
1970e84049SMiguel Ojeda Sandonis  *
2070e84049SMiguel Ojeda Sandonis  *  You should have received a copy of the GNU General Public License
2170e84049SMiguel Ojeda Sandonis  *  along with this program; if not, write to the Free Software
2270e84049SMiguel Ojeda Sandonis  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
2370e84049SMiguel Ojeda Sandonis  *
2470e84049SMiguel Ojeda Sandonis  */
2570e84049SMiguel Ojeda Sandonis 
2670e84049SMiguel Ojeda Sandonis #include <linux/init.h>
2770e84049SMiguel Ojeda Sandonis #include <linux/module.h>
2870e84049SMiguel Ojeda Sandonis #include <linux/kernel.h>
2970e84049SMiguel Ojeda Sandonis #include <linux/delay.h>
3070e84049SMiguel Ojeda Sandonis #include <linux/errno.h>
3170e84049SMiguel Ojeda Sandonis #include <linux/fb.h>
3270e84049SMiguel Ojeda Sandonis #include <linux/mm.h>
3370e84049SMiguel Ojeda Sandonis #include <linux/platform_device.h>
3470e84049SMiguel Ojeda Sandonis #include <linux/string.h>
3570e84049SMiguel Ojeda Sandonis #include <linux/uaccess.h>
3670e84049SMiguel Ojeda Sandonis #include <linux/cfag12864b.h>
3770e84049SMiguel Ojeda Sandonis 
3870e84049SMiguel Ojeda Sandonis #define CFAG12864BFB_NAME "cfag12864bfb"
3970e84049SMiguel Ojeda Sandonis 
40*7223310fSGustavo A. R. Silva static const struct fb_fix_screeninfo cfag12864bfb_fix = {
4170e84049SMiguel Ojeda Sandonis 	.id = "cfag12864b",
4270e84049SMiguel Ojeda Sandonis 	.type = FB_TYPE_PACKED_PIXELS,
4370e84049SMiguel Ojeda Sandonis 	.visual = FB_VISUAL_MONO10,
4470e84049SMiguel Ojeda Sandonis 	.xpanstep = 0,
4570e84049SMiguel Ojeda Sandonis 	.ypanstep = 0,
4670e84049SMiguel Ojeda Sandonis 	.ywrapstep = 0,
4770e84049SMiguel Ojeda Sandonis 	.line_length = CFAG12864B_WIDTH / 8,
4870e84049SMiguel Ojeda Sandonis 	.accel = FB_ACCEL_NONE,
4970e84049SMiguel Ojeda Sandonis };
5070e84049SMiguel Ojeda Sandonis 
51*7223310fSGustavo A. R. Silva static const struct fb_var_screeninfo cfag12864bfb_var = {
5270e84049SMiguel Ojeda Sandonis 	.xres = CFAG12864B_WIDTH,
5370e84049SMiguel Ojeda Sandonis 	.yres = CFAG12864B_HEIGHT,
5470e84049SMiguel Ojeda Sandonis 	.xres_virtual = CFAG12864B_WIDTH,
5570e84049SMiguel Ojeda Sandonis 	.yres_virtual = CFAG12864B_HEIGHT,
5670e84049SMiguel Ojeda Sandonis 	.bits_per_pixel = 1,
5770e84049SMiguel Ojeda Sandonis 	.red = { 0, 1, 0 },
5870e84049SMiguel Ojeda Sandonis       	.green = { 0, 1, 0 },
5970e84049SMiguel Ojeda Sandonis       	.blue = { 0, 1, 0 },
6070e84049SMiguel Ojeda Sandonis 	.left_margin = 0,
6170e84049SMiguel Ojeda Sandonis 	.right_margin = 0,
6270e84049SMiguel Ojeda Sandonis 	.upper_margin = 0,
6370e84049SMiguel Ojeda Sandonis 	.lower_margin = 0,
6470e84049SMiguel Ojeda Sandonis 	.vmode = FB_VMODE_NONINTERLACED,
6570e84049SMiguel Ojeda Sandonis };
6670e84049SMiguel Ojeda Sandonis 
6770e84049SMiguel Ojeda Sandonis static int cfag12864bfb_mmap(struct fb_info *info, struct vm_area_struct *vma)
6870e84049SMiguel Ojeda Sandonis {
6970e84049SMiguel Ojeda Sandonis 	return vm_insert_page(vma, vma->vm_start,
7070e84049SMiguel Ojeda Sandonis 		virt_to_page(cfag12864b_buffer));
7170e84049SMiguel Ojeda Sandonis }
7270e84049SMiguel Ojeda Sandonis 
7370e84049SMiguel Ojeda Sandonis static struct fb_ops cfag12864bfb_ops = {
7470e84049SMiguel Ojeda Sandonis 	.owner = THIS_MODULE,
75bfeeffbbSAvuton Olrich 	.fb_read = fb_sys_read,
76bfeeffbbSAvuton Olrich 	.fb_write = fb_sys_write,
77bfeeffbbSAvuton Olrich 	.fb_fillrect = sys_fillrect,
78bfeeffbbSAvuton Olrich 	.fb_copyarea = sys_copyarea,
79bfeeffbbSAvuton Olrich 	.fb_imageblit = sys_imageblit,
8070e84049SMiguel Ojeda Sandonis 	.fb_mmap = cfag12864bfb_mmap,
8170e84049SMiguel Ojeda Sandonis };
8270e84049SMiguel Ojeda Sandonis 
830fe763c5SGreg Kroah-Hartman static int cfag12864bfb_probe(struct platform_device *device)
8470e84049SMiguel Ojeda Sandonis {
8570e84049SMiguel Ojeda Sandonis 	int ret = -EINVAL;
8670e84049SMiguel Ojeda Sandonis  	struct fb_info *info = framebuffer_alloc(0, &device->dev);
8770e84049SMiguel Ojeda Sandonis 
8870e84049SMiguel Ojeda Sandonis 	if (!info)
8970e84049SMiguel Ojeda Sandonis 		goto none;
9070e84049SMiguel Ojeda Sandonis 
9170e84049SMiguel Ojeda Sandonis 	info->screen_base = (char __iomem *) cfag12864b_buffer;
9270e84049SMiguel Ojeda Sandonis 	info->screen_size = CFAG12864B_SIZE;
9370e84049SMiguel Ojeda Sandonis 	info->fbops = &cfag12864bfb_ops;
9470e84049SMiguel Ojeda Sandonis 	info->fix = cfag12864bfb_fix;
9570e84049SMiguel Ojeda Sandonis 	info->var = cfag12864bfb_var;
9670e84049SMiguel Ojeda Sandonis 	info->pseudo_palette = NULL;
9770e84049SMiguel Ojeda Sandonis 	info->par = NULL;
9870e84049SMiguel Ojeda Sandonis 	info->flags = FBINFO_FLAG_DEFAULT;
9970e84049SMiguel Ojeda Sandonis 
10070e84049SMiguel Ojeda Sandonis 	if (register_framebuffer(info) < 0)
10170e84049SMiguel Ojeda Sandonis 		goto fballoced;
10270e84049SMiguel Ojeda Sandonis 
10370e84049SMiguel Ojeda Sandonis 	platform_set_drvdata(device, info);
10470e84049SMiguel Ojeda Sandonis 
10531b6780cSJoe Perches 	fb_info(info, "%s frame buffer device\n", info->fix.id);
10670e84049SMiguel Ojeda Sandonis 
10770e84049SMiguel Ojeda Sandonis 	return 0;
10870e84049SMiguel Ojeda Sandonis 
10970e84049SMiguel Ojeda Sandonis fballoced:
11070e84049SMiguel Ojeda Sandonis 	framebuffer_release(info);
11170e84049SMiguel Ojeda Sandonis 
11270e84049SMiguel Ojeda Sandonis none:
11370e84049SMiguel Ojeda Sandonis 	return ret;
11470e84049SMiguel Ojeda Sandonis }
11570e84049SMiguel Ojeda Sandonis 
1160fe763c5SGreg Kroah-Hartman static int cfag12864bfb_remove(struct platform_device *device)
11770e84049SMiguel Ojeda Sandonis {
11870e84049SMiguel Ojeda Sandonis 	struct fb_info *info = platform_get_drvdata(device);
11970e84049SMiguel Ojeda Sandonis 
12070e84049SMiguel Ojeda Sandonis 	if (info) {
12170e84049SMiguel Ojeda Sandonis 		unregister_framebuffer(info);
12270e84049SMiguel Ojeda Sandonis 		framebuffer_release(info);
12370e84049SMiguel Ojeda Sandonis 	}
12470e84049SMiguel Ojeda Sandonis 
12570e84049SMiguel Ojeda Sandonis 	return 0;
12670e84049SMiguel Ojeda Sandonis }
12770e84049SMiguel Ojeda Sandonis 
12870e84049SMiguel Ojeda Sandonis static struct platform_driver cfag12864bfb_driver = {
12970e84049SMiguel Ojeda Sandonis 	.probe	= cfag12864bfb_probe,
1300fe763c5SGreg Kroah-Hartman 	.remove = cfag12864bfb_remove,
13170e84049SMiguel Ojeda Sandonis 	.driver = {
13270e84049SMiguel Ojeda Sandonis 		.name	= CFAG12864BFB_NAME,
13370e84049SMiguel Ojeda Sandonis 	},
13470e84049SMiguel Ojeda Sandonis };
13570e84049SMiguel Ojeda Sandonis 
13670e84049SMiguel Ojeda Sandonis static struct platform_device *cfag12864bfb_device;
13770e84049SMiguel Ojeda Sandonis 
13870e84049SMiguel Ojeda Sandonis static int __init cfag12864bfb_init(void)
13970e84049SMiguel Ojeda Sandonis {
14034173a4aSMiguel Ojeda 	int ret = -EINVAL;
14134173a4aSMiguel Ojeda 
14234173a4aSMiguel Ojeda 	/* cfag12864b_init() must be called first */
14334173a4aSMiguel Ojeda 	if (!cfag12864b_isinited()) {
14434173a4aSMiguel Ojeda 		printk(KERN_ERR CFAG12864BFB_NAME ": ERROR: "
14534173a4aSMiguel Ojeda 			"cfag12864b is not initialized\n");
14634173a4aSMiguel Ojeda 		goto none;
14734173a4aSMiguel Ojeda 	}
14870e84049SMiguel Ojeda Sandonis 
14970e84049SMiguel Ojeda Sandonis 	if (cfag12864b_enable()) {
15070e84049SMiguel Ojeda Sandonis 		printk(KERN_ERR CFAG12864BFB_NAME ": ERROR: "
15170e84049SMiguel Ojeda Sandonis 			"can't enable cfag12864b refreshing (being used)\n");
15270e84049SMiguel Ojeda Sandonis 		return -ENODEV;
15370e84049SMiguel Ojeda Sandonis 	}
15470e84049SMiguel Ojeda Sandonis 
15570e84049SMiguel Ojeda Sandonis 	ret = platform_driver_register(&cfag12864bfb_driver);
15670e84049SMiguel Ojeda Sandonis 
15770e84049SMiguel Ojeda Sandonis 	if (!ret) {
15870e84049SMiguel Ojeda Sandonis 		cfag12864bfb_device =
15970e84049SMiguel Ojeda Sandonis 			platform_device_alloc(CFAG12864BFB_NAME, 0);
16070e84049SMiguel Ojeda Sandonis 
16170e84049SMiguel Ojeda Sandonis 		if (cfag12864bfb_device)
16270e84049SMiguel Ojeda Sandonis 			ret = platform_device_add(cfag12864bfb_device);
16370e84049SMiguel Ojeda Sandonis 		else
16470e84049SMiguel Ojeda Sandonis 			ret = -ENOMEM;
16570e84049SMiguel Ojeda Sandonis 
16670e84049SMiguel Ojeda Sandonis 		if (ret) {
16770e84049SMiguel Ojeda Sandonis 			platform_device_put(cfag12864bfb_device);
16870e84049SMiguel Ojeda Sandonis 			platform_driver_unregister(&cfag12864bfb_driver);
16970e84049SMiguel Ojeda Sandonis 		}
17070e84049SMiguel Ojeda Sandonis 	}
17170e84049SMiguel Ojeda Sandonis 
17234173a4aSMiguel Ojeda none:
17370e84049SMiguel Ojeda Sandonis 	return ret;
17470e84049SMiguel Ojeda Sandonis }
17570e84049SMiguel Ojeda Sandonis 
17670e84049SMiguel Ojeda Sandonis static void __exit cfag12864bfb_exit(void)
17770e84049SMiguel Ojeda Sandonis {
17870e84049SMiguel Ojeda Sandonis 	platform_device_unregister(cfag12864bfb_device);
17970e84049SMiguel Ojeda Sandonis 	platform_driver_unregister(&cfag12864bfb_driver);
18070e84049SMiguel Ojeda Sandonis 	cfag12864b_disable();
18170e84049SMiguel Ojeda Sandonis }
18270e84049SMiguel Ojeda Sandonis 
18370e84049SMiguel Ojeda Sandonis module_init(cfag12864bfb_init);
18470e84049SMiguel Ojeda Sandonis module_exit(cfag12864bfb_exit);
18570e84049SMiguel Ojeda Sandonis 
18670e84049SMiguel Ojeda Sandonis MODULE_LICENSE("GPL v2");
187450c622eSMiguel Ojeda MODULE_AUTHOR("Miguel Ojeda Sandonis <miguel.ojeda.sandonis@gmail.com>");
18870e84049SMiguel Ojeda Sandonis MODULE_DESCRIPTION("cfag12864b LCD framebuffer driver");
189