xref: /linux/drivers/auxdisplay/cfag12864bfb.c (revision 450c622e9ff19888818d4e2c4d31adb97a5242b2)
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  *
8*450c622eSMiguel 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/slab.h>
3570e84049SMiguel Ojeda Sandonis #include <linux/string.h>
3670e84049SMiguel Ojeda Sandonis #include <linux/uaccess.h>
3770e84049SMiguel Ojeda Sandonis #include <linux/cfag12864b.h>
3870e84049SMiguel Ojeda Sandonis 
3970e84049SMiguel Ojeda Sandonis #define CFAG12864BFB_NAME "cfag12864bfb"
4070e84049SMiguel Ojeda Sandonis 
4170e84049SMiguel Ojeda Sandonis static struct fb_fix_screeninfo cfag12864bfb_fix __initdata = {
4270e84049SMiguel Ojeda Sandonis 	.id = "cfag12864b",
4370e84049SMiguel Ojeda Sandonis 	.type = FB_TYPE_PACKED_PIXELS,
4470e84049SMiguel Ojeda Sandonis 	.visual = FB_VISUAL_MONO10,
4570e84049SMiguel Ojeda Sandonis 	.xpanstep = 0,
4670e84049SMiguel Ojeda Sandonis 	.ypanstep = 0,
4770e84049SMiguel Ojeda Sandonis 	.ywrapstep = 0,
4870e84049SMiguel Ojeda Sandonis 	.line_length = CFAG12864B_WIDTH / 8,
4970e84049SMiguel Ojeda Sandonis 	.accel = FB_ACCEL_NONE,
5070e84049SMiguel Ojeda Sandonis };
5170e84049SMiguel Ojeda Sandonis 
5270e84049SMiguel Ojeda Sandonis static struct fb_var_screeninfo cfag12864bfb_var __initdata = {
5370e84049SMiguel Ojeda Sandonis 	.xres = CFAG12864B_WIDTH,
5470e84049SMiguel Ojeda Sandonis 	.yres = CFAG12864B_HEIGHT,
5570e84049SMiguel Ojeda Sandonis 	.xres_virtual = CFAG12864B_WIDTH,
5670e84049SMiguel Ojeda Sandonis 	.yres_virtual = CFAG12864B_HEIGHT,
5770e84049SMiguel Ojeda Sandonis 	.bits_per_pixel = 1,
5870e84049SMiguel Ojeda Sandonis 	.red = { 0, 1, 0 },
5970e84049SMiguel Ojeda Sandonis       	.green = { 0, 1, 0 },
6070e84049SMiguel Ojeda Sandonis       	.blue = { 0, 1, 0 },
6170e84049SMiguel Ojeda Sandonis 	.left_margin = 0,
6270e84049SMiguel Ojeda Sandonis 	.right_margin = 0,
6370e84049SMiguel Ojeda Sandonis 	.upper_margin = 0,
6470e84049SMiguel Ojeda Sandonis 	.lower_margin = 0,
6570e84049SMiguel Ojeda Sandonis 	.vmode = FB_VMODE_NONINTERLACED,
6670e84049SMiguel Ojeda Sandonis };
6770e84049SMiguel Ojeda Sandonis 
6870e84049SMiguel Ojeda Sandonis static int cfag12864bfb_mmap(struct fb_info *info, struct vm_area_struct *vma)
6970e84049SMiguel Ojeda Sandonis {
7070e84049SMiguel Ojeda Sandonis 	return vm_insert_page(vma, vma->vm_start,
7170e84049SMiguel Ojeda Sandonis 		virt_to_page(cfag12864b_buffer));
7270e84049SMiguel Ojeda Sandonis }
7370e84049SMiguel Ojeda Sandonis 
7470e84049SMiguel Ojeda Sandonis static struct fb_ops cfag12864bfb_ops = {
7570e84049SMiguel Ojeda Sandonis 	.owner = THIS_MODULE,
76bfeeffbbSAvuton Olrich 	.fb_read = fb_sys_read,
77bfeeffbbSAvuton Olrich 	.fb_write = fb_sys_write,
78bfeeffbbSAvuton Olrich 	.fb_fillrect = sys_fillrect,
79bfeeffbbSAvuton Olrich 	.fb_copyarea = sys_copyarea,
80bfeeffbbSAvuton Olrich 	.fb_imageblit = sys_imageblit,
8170e84049SMiguel Ojeda Sandonis 	.fb_mmap = cfag12864bfb_mmap,
8270e84049SMiguel Ojeda Sandonis };
8370e84049SMiguel Ojeda Sandonis 
8470e84049SMiguel Ojeda Sandonis static int __init cfag12864bfb_probe(struct platform_device *device)
8570e84049SMiguel Ojeda Sandonis {
8670e84049SMiguel Ojeda Sandonis 	int ret = -EINVAL;
8770e84049SMiguel Ojeda Sandonis  	struct fb_info *info = framebuffer_alloc(0, &device->dev);
8870e84049SMiguel Ojeda Sandonis 
8970e84049SMiguel Ojeda Sandonis 	if (!info)
9070e84049SMiguel Ojeda Sandonis 		goto none;
9170e84049SMiguel Ojeda Sandonis 
9270e84049SMiguel Ojeda Sandonis 	info->screen_base = (char __iomem *) cfag12864b_buffer;
9370e84049SMiguel Ojeda Sandonis 	info->screen_size = CFAG12864B_SIZE;
9470e84049SMiguel Ojeda Sandonis 	info->fbops = &cfag12864bfb_ops;
9570e84049SMiguel Ojeda Sandonis 	info->fix = cfag12864bfb_fix;
9670e84049SMiguel Ojeda Sandonis 	info->var = cfag12864bfb_var;
9770e84049SMiguel Ojeda Sandonis 	info->pseudo_palette = NULL;
9870e84049SMiguel Ojeda Sandonis 	info->par = NULL;
9970e84049SMiguel Ojeda Sandonis 	info->flags = FBINFO_FLAG_DEFAULT;
10070e84049SMiguel Ojeda Sandonis 
10170e84049SMiguel Ojeda Sandonis 	if (register_framebuffer(info) < 0)
10270e84049SMiguel Ojeda Sandonis 		goto fballoced;
10370e84049SMiguel Ojeda Sandonis 
10470e84049SMiguel Ojeda Sandonis 	platform_set_drvdata(device, info);
10570e84049SMiguel Ojeda Sandonis 
10670e84049SMiguel Ojeda Sandonis 	printk(KERN_INFO "fb%d: %s frame buffer device\n", info->node,
10770e84049SMiguel Ojeda Sandonis 		info->fix.id);
10870e84049SMiguel Ojeda Sandonis 
10970e84049SMiguel Ojeda Sandonis 	return 0;
11070e84049SMiguel Ojeda Sandonis 
11170e84049SMiguel Ojeda Sandonis fballoced:
11270e84049SMiguel Ojeda Sandonis 	framebuffer_release(info);
11370e84049SMiguel Ojeda Sandonis 
11470e84049SMiguel Ojeda Sandonis none:
11570e84049SMiguel Ojeda Sandonis 	return ret;
11670e84049SMiguel Ojeda Sandonis }
11770e84049SMiguel Ojeda Sandonis 
11870e84049SMiguel Ojeda Sandonis static int cfag12864bfb_remove(struct platform_device *device)
11970e84049SMiguel Ojeda Sandonis {
12070e84049SMiguel Ojeda Sandonis 	struct fb_info *info = platform_get_drvdata(device);
12170e84049SMiguel Ojeda Sandonis 
12270e84049SMiguel Ojeda Sandonis 	if (info) {
12370e84049SMiguel Ojeda Sandonis 		unregister_framebuffer(info);
12470e84049SMiguel Ojeda Sandonis 		framebuffer_release(info);
12570e84049SMiguel Ojeda Sandonis 	}
12670e84049SMiguel Ojeda Sandonis 
12770e84049SMiguel Ojeda Sandonis 	return 0;
12870e84049SMiguel Ojeda Sandonis }
12970e84049SMiguel Ojeda Sandonis 
13070e84049SMiguel Ojeda Sandonis static struct platform_driver cfag12864bfb_driver = {
13170e84049SMiguel Ojeda Sandonis 	.probe	= cfag12864bfb_probe,
13270e84049SMiguel Ojeda Sandonis 	.remove = cfag12864bfb_remove,
13370e84049SMiguel Ojeda Sandonis 	.driver = {
13470e84049SMiguel Ojeda Sandonis 		.name	= CFAG12864BFB_NAME,
13570e84049SMiguel Ojeda Sandonis 	},
13670e84049SMiguel Ojeda Sandonis };
13770e84049SMiguel Ojeda Sandonis 
13870e84049SMiguel Ojeda Sandonis static struct platform_device *cfag12864bfb_device;
13970e84049SMiguel Ojeda Sandonis 
14070e84049SMiguel Ojeda Sandonis static int __init cfag12864bfb_init(void)
14170e84049SMiguel Ojeda Sandonis {
14234173a4aSMiguel Ojeda 	int ret = -EINVAL;
14334173a4aSMiguel Ojeda 
14434173a4aSMiguel Ojeda 	/* cfag12864b_init() must be called first */
14534173a4aSMiguel Ojeda 	if (!cfag12864b_isinited()) {
14634173a4aSMiguel Ojeda 		printk(KERN_ERR CFAG12864BFB_NAME ": ERROR: "
14734173a4aSMiguel Ojeda 			"cfag12864b is not initialized\n");
14834173a4aSMiguel Ojeda 		goto none;
14934173a4aSMiguel Ojeda 	}
15070e84049SMiguel Ojeda Sandonis 
15170e84049SMiguel Ojeda Sandonis 	if (cfag12864b_enable()) {
15270e84049SMiguel Ojeda Sandonis 		printk(KERN_ERR CFAG12864BFB_NAME ": ERROR: "
15370e84049SMiguel Ojeda Sandonis 			"can't enable cfag12864b refreshing (being used)\n");
15470e84049SMiguel Ojeda Sandonis 		return -ENODEV;
15570e84049SMiguel Ojeda Sandonis 	}
15670e84049SMiguel Ojeda Sandonis 
15770e84049SMiguel Ojeda Sandonis 	ret = platform_driver_register(&cfag12864bfb_driver);
15870e84049SMiguel Ojeda Sandonis 
15970e84049SMiguel Ojeda Sandonis 	if (!ret) {
16070e84049SMiguel Ojeda Sandonis 		cfag12864bfb_device =
16170e84049SMiguel Ojeda Sandonis 			platform_device_alloc(CFAG12864BFB_NAME, 0);
16270e84049SMiguel Ojeda Sandonis 
16370e84049SMiguel Ojeda Sandonis 		if (cfag12864bfb_device)
16470e84049SMiguel Ojeda Sandonis 			ret = platform_device_add(cfag12864bfb_device);
16570e84049SMiguel Ojeda Sandonis 		else
16670e84049SMiguel Ojeda Sandonis 			ret = -ENOMEM;
16770e84049SMiguel Ojeda Sandonis 
16870e84049SMiguel Ojeda Sandonis 		if (ret) {
16970e84049SMiguel Ojeda Sandonis 			platform_device_put(cfag12864bfb_device);
17070e84049SMiguel Ojeda Sandonis 			platform_driver_unregister(&cfag12864bfb_driver);
17170e84049SMiguel Ojeda Sandonis 		}
17270e84049SMiguel Ojeda Sandonis 	}
17370e84049SMiguel Ojeda Sandonis 
17434173a4aSMiguel Ojeda none:
17570e84049SMiguel Ojeda Sandonis 	return ret;
17670e84049SMiguel Ojeda Sandonis }
17770e84049SMiguel Ojeda Sandonis 
17870e84049SMiguel Ojeda Sandonis static void __exit cfag12864bfb_exit(void)
17970e84049SMiguel Ojeda Sandonis {
18070e84049SMiguel Ojeda Sandonis 	platform_device_unregister(cfag12864bfb_device);
18170e84049SMiguel Ojeda Sandonis 	platform_driver_unregister(&cfag12864bfb_driver);
18270e84049SMiguel Ojeda Sandonis 	cfag12864b_disable();
18370e84049SMiguel Ojeda Sandonis }
18470e84049SMiguel Ojeda Sandonis 
18570e84049SMiguel Ojeda Sandonis module_init(cfag12864bfb_init);
18670e84049SMiguel Ojeda Sandonis module_exit(cfag12864bfb_exit);
18770e84049SMiguel Ojeda Sandonis 
18870e84049SMiguel Ojeda Sandonis MODULE_LICENSE("GPL v2");
189*450c622eSMiguel Ojeda MODULE_AUTHOR("Miguel Ojeda Sandonis <miguel.ojeda.sandonis@gmail.com>");
19070e84049SMiguel Ojeda Sandonis MODULE_DESCRIPTION("cfag12864b LCD framebuffer driver");
191