Miguel Ojeda Sandonis | 70e8404 | 2007-02-10 01:44:32 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Filename: cfag12864bfb.c |
| 3 | * Version: 0.1.0 |
| 4 | * Description: cfag12864b LCD framebuffer driver |
| 5 | * License: GPLv2 |
| 6 | * Depends: cfag12864b |
| 7 | * |
Miguel Ojeda | 450c622 | 2008-07-04 09:59:33 -0700 | [diff] [blame^] | 8 | * Author: Copyright (C) Miguel Ojeda Sandonis |
Miguel Ojeda Sandonis | 70e8404 | 2007-02-10 01:44:32 -0800 | [diff] [blame] | 9 | * Date: 2006-10-31 |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License version 2 as |
| 13 | * published by the Free Software Foundation. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 23 | * |
| 24 | */ |
| 25 | |
| 26 | #include <linux/init.h> |
| 27 | #include <linux/module.h> |
| 28 | #include <linux/kernel.h> |
| 29 | #include <linux/delay.h> |
| 30 | #include <linux/errno.h> |
| 31 | #include <linux/fb.h> |
| 32 | #include <linux/mm.h> |
| 33 | #include <linux/platform_device.h> |
| 34 | #include <linux/slab.h> |
| 35 | #include <linux/string.h> |
| 36 | #include <linux/uaccess.h> |
| 37 | #include <linux/cfag12864b.h> |
| 38 | |
| 39 | #define CFAG12864BFB_NAME "cfag12864bfb" |
| 40 | |
| 41 | static struct fb_fix_screeninfo cfag12864bfb_fix __initdata = { |
| 42 | .id = "cfag12864b", |
| 43 | .type = FB_TYPE_PACKED_PIXELS, |
| 44 | .visual = FB_VISUAL_MONO10, |
| 45 | .xpanstep = 0, |
| 46 | .ypanstep = 0, |
| 47 | .ywrapstep = 0, |
| 48 | .line_length = CFAG12864B_WIDTH / 8, |
| 49 | .accel = FB_ACCEL_NONE, |
| 50 | }; |
| 51 | |
| 52 | static struct fb_var_screeninfo cfag12864bfb_var __initdata = { |
| 53 | .xres = CFAG12864B_WIDTH, |
| 54 | .yres = CFAG12864B_HEIGHT, |
| 55 | .xres_virtual = CFAG12864B_WIDTH, |
| 56 | .yres_virtual = CFAG12864B_HEIGHT, |
| 57 | .bits_per_pixel = 1, |
| 58 | .red = { 0, 1, 0 }, |
| 59 | .green = { 0, 1, 0 }, |
| 60 | .blue = { 0, 1, 0 }, |
| 61 | .left_margin = 0, |
| 62 | .right_margin = 0, |
| 63 | .upper_margin = 0, |
| 64 | .lower_margin = 0, |
| 65 | .vmode = FB_VMODE_NONINTERLACED, |
| 66 | }; |
| 67 | |
| 68 | static int cfag12864bfb_mmap(struct fb_info *info, struct vm_area_struct *vma) |
| 69 | { |
| 70 | return vm_insert_page(vma, vma->vm_start, |
| 71 | virt_to_page(cfag12864b_buffer)); |
| 72 | } |
| 73 | |
| 74 | static struct fb_ops cfag12864bfb_ops = { |
| 75 | .owner = THIS_MODULE, |
Avuton Olrich | bfeeffb | 2007-06-01 00:46:45 -0700 | [diff] [blame] | 76 | .fb_read = fb_sys_read, |
| 77 | .fb_write = fb_sys_write, |
| 78 | .fb_fillrect = sys_fillrect, |
| 79 | .fb_copyarea = sys_copyarea, |
| 80 | .fb_imageblit = sys_imageblit, |
Miguel Ojeda Sandonis | 70e8404 | 2007-02-10 01:44:32 -0800 | [diff] [blame] | 81 | .fb_mmap = cfag12864bfb_mmap, |
| 82 | }; |
| 83 | |
| 84 | static int __init cfag12864bfb_probe(struct platform_device *device) |
| 85 | { |
| 86 | int ret = -EINVAL; |
| 87 | struct fb_info *info = framebuffer_alloc(0, &device->dev); |
| 88 | |
| 89 | if (!info) |
| 90 | goto none; |
| 91 | |
| 92 | info->screen_base = (char __iomem *) cfag12864b_buffer; |
| 93 | info->screen_size = CFAG12864B_SIZE; |
| 94 | info->fbops = &cfag12864bfb_ops; |
| 95 | info->fix = cfag12864bfb_fix; |
| 96 | info->var = cfag12864bfb_var; |
| 97 | info->pseudo_palette = NULL; |
| 98 | info->par = NULL; |
| 99 | info->flags = FBINFO_FLAG_DEFAULT; |
| 100 | |
| 101 | if (register_framebuffer(info) < 0) |
| 102 | goto fballoced; |
| 103 | |
| 104 | platform_set_drvdata(device, info); |
| 105 | |
| 106 | printk(KERN_INFO "fb%d: %s frame buffer device\n", info->node, |
| 107 | info->fix.id); |
| 108 | |
| 109 | return 0; |
| 110 | |
| 111 | fballoced: |
| 112 | framebuffer_release(info); |
| 113 | |
| 114 | none: |
| 115 | return ret; |
| 116 | } |
| 117 | |
| 118 | static int cfag12864bfb_remove(struct platform_device *device) |
| 119 | { |
| 120 | struct fb_info *info = platform_get_drvdata(device); |
| 121 | |
| 122 | if (info) { |
| 123 | unregister_framebuffer(info); |
| 124 | framebuffer_release(info); |
| 125 | } |
| 126 | |
| 127 | return 0; |
| 128 | } |
| 129 | |
| 130 | static struct platform_driver cfag12864bfb_driver = { |
| 131 | .probe = cfag12864bfb_probe, |
| 132 | .remove = cfag12864bfb_remove, |
| 133 | .driver = { |
| 134 | .name = CFAG12864BFB_NAME, |
| 135 | }, |
| 136 | }; |
| 137 | |
| 138 | static struct platform_device *cfag12864bfb_device; |
| 139 | |
| 140 | static int __init cfag12864bfb_init(void) |
| 141 | { |
Miguel Ojeda | 34173a4 | 2007-02-20 13:58:00 -0800 | [diff] [blame] | 142 | int ret = -EINVAL; |
| 143 | |
| 144 | /* cfag12864b_init() must be called first */ |
| 145 | if (!cfag12864b_isinited()) { |
| 146 | printk(KERN_ERR CFAG12864BFB_NAME ": ERROR: " |
| 147 | "cfag12864b is not initialized\n"); |
| 148 | goto none; |
| 149 | } |
Miguel Ojeda Sandonis | 70e8404 | 2007-02-10 01:44:32 -0800 | [diff] [blame] | 150 | |
| 151 | if (cfag12864b_enable()) { |
| 152 | printk(KERN_ERR CFAG12864BFB_NAME ": ERROR: " |
| 153 | "can't enable cfag12864b refreshing (being used)\n"); |
| 154 | return -ENODEV; |
| 155 | } |
| 156 | |
| 157 | ret = platform_driver_register(&cfag12864bfb_driver); |
| 158 | |
| 159 | if (!ret) { |
| 160 | cfag12864bfb_device = |
| 161 | platform_device_alloc(CFAG12864BFB_NAME, 0); |
| 162 | |
| 163 | if (cfag12864bfb_device) |
| 164 | ret = platform_device_add(cfag12864bfb_device); |
| 165 | else |
| 166 | ret = -ENOMEM; |
| 167 | |
| 168 | if (ret) { |
| 169 | platform_device_put(cfag12864bfb_device); |
| 170 | platform_driver_unregister(&cfag12864bfb_driver); |
| 171 | } |
| 172 | } |
| 173 | |
Miguel Ojeda | 34173a4 | 2007-02-20 13:58:00 -0800 | [diff] [blame] | 174 | none: |
Miguel Ojeda Sandonis | 70e8404 | 2007-02-10 01:44:32 -0800 | [diff] [blame] | 175 | return ret; |
| 176 | } |
| 177 | |
| 178 | static void __exit cfag12864bfb_exit(void) |
| 179 | { |
| 180 | platform_device_unregister(cfag12864bfb_device); |
| 181 | platform_driver_unregister(&cfag12864bfb_driver); |
| 182 | cfag12864b_disable(); |
| 183 | } |
| 184 | |
| 185 | module_init(cfag12864bfb_init); |
| 186 | module_exit(cfag12864bfb_exit); |
| 187 | |
| 188 | MODULE_LICENSE("GPL v2"); |
Miguel Ojeda | 450c622 | 2008-07-04 09:59:33 -0700 | [diff] [blame^] | 189 | MODULE_AUTHOR("Miguel Ojeda Sandonis <miguel.ojeda.sandonis@gmail.com>"); |
Miguel Ojeda Sandonis | 70e8404 | 2007-02-10 01:44:32 -0800 | [diff] [blame] | 190 | MODULE_DESCRIPTION("cfag12864b LCD framebuffer driver"); |