blob: 5ad3bad2b0a53ecf0aa57d656f7aaf5a01752152 [file] [log] [blame]
Miguel Ojeda Sandonis70e84042007-02-10 01:44:32 -08001/*
2 * Filename: cfag12864bfb.c
3 * Version: 0.1.0
4 * Description: cfag12864b LCD framebuffer driver
5 * License: GPLv2
6 * Depends: cfag12864b
7 *
Miguel Ojeda450c6222008-07-04 09:59:33 -07008 * Author: Copyright (C) Miguel Ojeda Sandonis
Miguel Ojeda Sandonis70e84042007-02-10 01:44:32 -08009 * 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>
Miguel Ojeda Sandonis70e84042007-02-10 01:44:32 -080034#include <linux/string.h>
35#include <linux/uaccess.h>
36#include <linux/cfag12864b.h>
37
38#define CFAG12864BFB_NAME "cfag12864bfb"
39
Henrik Kretzschmarbf87eae2010-05-24 14:34:09 -070040static struct fb_fix_screeninfo cfag12864bfb_fix __devinitdata = {
Miguel Ojeda Sandonis70e84042007-02-10 01:44:32 -080041 .id = "cfag12864b",
42 .type = FB_TYPE_PACKED_PIXELS,
43 .visual = FB_VISUAL_MONO10,
44 .xpanstep = 0,
45 .ypanstep = 0,
46 .ywrapstep = 0,
47 .line_length = CFAG12864B_WIDTH / 8,
48 .accel = FB_ACCEL_NONE,
49};
50
Henrik Kretzschmarbf87eae2010-05-24 14:34:09 -070051static struct fb_var_screeninfo cfag12864bfb_var __devinitdata = {
Miguel Ojeda Sandonis70e84042007-02-10 01:44:32 -080052 .xres = CFAG12864B_WIDTH,
53 .yres = CFAG12864B_HEIGHT,
54 .xres_virtual = CFAG12864B_WIDTH,
55 .yres_virtual = CFAG12864B_HEIGHT,
56 .bits_per_pixel = 1,
57 .red = { 0, 1, 0 },
58 .green = { 0, 1, 0 },
59 .blue = { 0, 1, 0 },
60 .left_margin = 0,
61 .right_margin = 0,
62 .upper_margin = 0,
63 .lower_margin = 0,
64 .vmode = FB_VMODE_NONINTERLACED,
65};
66
67static int cfag12864bfb_mmap(struct fb_info *info, struct vm_area_struct *vma)
68{
69 return vm_insert_page(vma, vma->vm_start,
70 virt_to_page(cfag12864b_buffer));
71}
72
73static struct fb_ops cfag12864bfb_ops = {
74 .owner = THIS_MODULE,
Avuton Olrichbfeeffb2007-06-01 00:46:45 -070075 .fb_read = fb_sys_read,
76 .fb_write = fb_sys_write,
77 .fb_fillrect = sys_fillrect,
78 .fb_copyarea = sys_copyarea,
79 .fb_imageblit = sys_imageblit,
Miguel Ojeda Sandonis70e84042007-02-10 01:44:32 -080080 .fb_mmap = cfag12864bfb_mmap,
81};
82
Uwe Kleine-König57f1e872010-02-04 20:56:56 +010083static int __devinit cfag12864bfb_probe(struct platform_device *device)
Miguel Ojeda Sandonis70e84042007-02-10 01:44:32 -080084{
85 int ret = -EINVAL;
86 struct fb_info *info = framebuffer_alloc(0, &device->dev);
87
88 if (!info)
89 goto none;
90
91 info->screen_base = (char __iomem *) cfag12864b_buffer;
92 info->screen_size = CFAG12864B_SIZE;
93 info->fbops = &cfag12864bfb_ops;
94 info->fix = cfag12864bfb_fix;
95 info->var = cfag12864bfb_var;
96 info->pseudo_palette = NULL;
97 info->par = NULL;
98 info->flags = FBINFO_FLAG_DEFAULT;
99
100 if (register_framebuffer(info) < 0)
101 goto fballoced;
102
103 platform_set_drvdata(device, info);
104
105 printk(KERN_INFO "fb%d: %s frame buffer device\n", info->node,
106 info->fix.id);
107
108 return 0;
109
110fballoced:
111 framebuffer_release(info);
112
113none:
114 return ret;
115}
116
Henrik Kretzschmarbf87eae2010-05-24 14:34:09 -0700117static int __devexit cfag12864bfb_remove(struct platform_device *device)
Miguel Ojeda Sandonis70e84042007-02-10 01:44:32 -0800118{
119 struct fb_info *info = platform_get_drvdata(device);
120
121 if (info) {
122 unregister_framebuffer(info);
123 framebuffer_release(info);
124 }
125
126 return 0;
127}
128
129static struct platform_driver cfag12864bfb_driver = {
130 .probe = cfag12864bfb_probe,
Henrik Kretzschmarbf87eae2010-05-24 14:34:09 -0700131 .remove = __devexit_p(cfag12864bfb_remove),
Miguel Ojeda Sandonis70e84042007-02-10 01:44:32 -0800132 .driver = {
133 .name = CFAG12864BFB_NAME,
134 },
135};
136
137static struct platform_device *cfag12864bfb_device;
138
139static int __init cfag12864bfb_init(void)
140{
Miguel Ojeda34173a42007-02-20 13:58:00 -0800141 int ret = -EINVAL;
142
143 /* cfag12864b_init() must be called first */
144 if (!cfag12864b_isinited()) {
145 printk(KERN_ERR CFAG12864BFB_NAME ": ERROR: "
146 "cfag12864b is not initialized\n");
147 goto none;
148 }
Miguel Ojeda Sandonis70e84042007-02-10 01:44:32 -0800149
150 if (cfag12864b_enable()) {
151 printk(KERN_ERR CFAG12864BFB_NAME ": ERROR: "
152 "can't enable cfag12864b refreshing (being used)\n");
153 return -ENODEV;
154 }
155
156 ret = platform_driver_register(&cfag12864bfb_driver);
157
158 if (!ret) {
159 cfag12864bfb_device =
160 platform_device_alloc(CFAG12864BFB_NAME, 0);
161
162 if (cfag12864bfb_device)
163 ret = platform_device_add(cfag12864bfb_device);
164 else
165 ret = -ENOMEM;
166
167 if (ret) {
168 platform_device_put(cfag12864bfb_device);
169 platform_driver_unregister(&cfag12864bfb_driver);
170 }
171 }
172
Miguel Ojeda34173a42007-02-20 13:58:00 -0800173none:
Miguel Ojeda Sandonis70e84042007-02-10 01:44:32 -0800174 return ret;
175}
176
177static void __exit cfag12864bfb_exit(void)
178{
179 platform_device_unregister(cfag12864bfb_device);
180 platform_driver_unregister(&cfag12864bfb_driver);
181 cfag12864b_disable();
182}
183
184module_init(cfag12864bfb_init);
185module_exit(cfag12864bfb_exit);
186
187MODULE_LICENSE("GPL v2");
Miguel Ojeda450c6222008-07-04 09:59:33 -0700188MODULE_AUTHOR("Miguel Ojeda Sandonis <miguel.ojeda.sandonis@gmail.com>");
Miguel Ojeda Sandonis70e84042007-02-10 01:44:32 -0800189MODULE_DESCRIPTION("cfag12864b LCD framebuffer driver");