Path: blob/master/drivers/auxdisplay/cfag12864bfb.c
15109 views
/*1* Filename: cfag12864bfb.c2* Version: 0.1.03* Description: cfag12864b LCD framebuffer driver4* License: GPLv25* Depends: cfag12864b6*7* Author: Copyright (C) Miguel Ojeda Sandonis8* Date: 2006-10-319*10* This program is free software; you can redistribute it and/or modify11* it under the terms of the GNU General Public License version 2 as12* published by the Free Software Foundation.13*14* This program is distributed in the hope that it will be useful,15* but WITHOUT ANY WARRANTY; without even the implied warranty of16* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the17* GNU General Public License for more details.18*19* You should have received a copy of the GNU General Public License20* along with this program; if not, write to the Free Software21* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA22*23*/2425#include <linux/init.h>26#include <linux/module.h>27#include <linux/kernel.h>28#include <linux/delay.h>29#include <linux/errno.h>30#include <linux/fb.h>31#include <linux/mm.h>32#include <linux/platform_device.h>33#include <linux/string.h>34#include <linux/uaccess.h>35#include <linux/cfag12864b.h>3637#define CFAG12864BFB_NAME "cfag12864bfb"3839static struct fb_fix_screeninfo cfag12864bfb_fix __devinitdata = {40.id = "cfag12864b",41.type = FB_TYPE_PACKED_PIXELS,42.visual = FB_VISUAL_MONO10,43.xpanstep = 0,44.ypanstep = 0,45.ywrapstep = 0,46.line_length = CFAG12864B_WIDTH / 8,47.accel = FB_ACCEL_NONE,48};4950static struct fb_var_screeninfo cfag12864bfb_var __devinitdata = {51.xres = CFAG12864B_WIDTH,52.yres = CFAG12864B_HEIGHT,53.xres_virtual = CFAG12864B_WIDTH,54.yres_virtual = CFAG12864B_HEIGHT,55.bits_per_pixel = 1,56.red = { 0, 1, 0 },57.green = { 0, 1, 0 },58.blue = { 0, 1, 0 },59.left_margin = 0,60.right_margin = 0,61.upper_margin = 0,62.lower_margin = 0,63.vmode = FB_VMODE_NONINTERLACED,64};6566static int cfag12864bfb_mmap(struct fb_info *info, struct vm_area_struct *vma)67{68return vm_insert_page(vma, vma->vm_start,69virt_to_page(cfag12864b_buffer));70}7172static struct fb_ops cfag12864bfb_ops = {73.owner = THIS_MODULE,74.fb_read = fb_sys_read,75.fb_write = fb_sys_write,76.fb_fillrect = sys_fillrect,77.fb_copyarea = sys_copyarea,78.fb_imageblit = sys_imageblit,79.fb_mmap = cfag12864bfb_mmap,80};8182static int __devinit cfag12864bfb_probe(struct platform_device *device)83{84int ret = -EINVAL;85struct fb_info *info = framebuffer_alloc(0, &device->dev);8687if (!info)88goto none;8990info->screen_base = (char __iomem *) cfag12864b_buffer;91info->screen_size = CFAG12864B_SIZE;92info->fbops = &cfag12864bfb_ops;93info->fix = cfag12864bfb_fix;94info->var = cfag12864bfb_var;95info->pseudo_palette = NULL;96info->par = NULL;97info->flags = FBINFO_FLAG_DEFAULT;9899if (register_framebuffer(info) < 0)100goto fballoced;101102platform_set_drvdata(device, info);103104printk(KERN_INFO "fb%d: %s frame buffer device\n", info->node,105info->fix.id);106107return 0;108109fballoced:110framebuffer_release(info);111112none:113return ret;114}115116static int __devexit cfag12864bfb_remove(struct platform_device *device)117{118struct fb_info *info = platform_get_drvdata(device);119120if (info) {121unregister_framebuffer(info);122framebuffer_release(info);123}124125return 0;126}127128static struct platform_driver cfag12864bfb_driver = {129.probe = cfag12864bfb_probe,130.remove = __devexit_p(cfag12864bfb_remove),131.driver = {132.name = CFAG12864BFB_NAME,133},134};135136static struct platform_device *cfag12864bfb_device;137138static int __init cfag12864bfb_init(void)139{140int ret = -EINVAL;141142/* cfag12864b_init() must be called first */143if (!cfag12864b_isinited()) {144printk(KERN_ERR CFAG12864BFB_NAME ": ERROR: "145"cfag12864b is not initialized\n");146goto none;147}148149if (cfag12864b_enable()) {150printk(KERN_ERR CFAG12864BFB_NAME ": ERROR: "151"can't enable cfag12864b refreshing (being used)\n");152return -ENODEV;153}154155ret = platform_driver_register(&cfag12864bfb_driver);156157if (!ret) {158cfag12864bfb_device =159platform_device_alloc(CFAG12864BFB_NAME, 0);160161if (cfag12864bfb_device)162ret = platform_device_add(cfag12864bfb_device);163else164ret = -ENOMEM;165166if (ret) {167platform_device_put(cfag12864bfb_device);168platform_driver_unregister(&cfag12864bfb_driver);169}170}171172none:173return ret;174}175176static void __exit cfag12864bfb_exit(void)177{178platform_device_unregister(cfag12864bfb_device);179platform_driver_unregister(&cfag12864bfb_driver);180cfag12864b_disable();181}182183module_init(cfag12864bfb_init);184module_exit(cfag12864bfb_exit);185186MODULE_LICENSE("GPL v2");187MODULE_AUTHOR("Miguel Ojeda Sandonis <[email protected]>");188MODULE_DESCRIPTION("cfag12864b LCD framebuffer driver");189190191