aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hid/hid-picolcd_fb.c
diff options
context:
space:
mode:
authorBruno Prémont <bonbons@linux-vserver.org>2012-07-30 15:38:28 -0400
committerJiri Kosina <jkosina@suse.cz>2012-08-15 04:08:57 -0400
commitfabdbf2fd22fa170b4c5340dbdda5c8cd88fb205 (patch)
tree25d6b1bbfee02aadca929130cb0d35bf8e8f9c17 /drivers/hid/hid-picolcd_fb.c
parente8ff13b0bf88b5e696323a1eec877783d965b3c6 (diff)
HID: picoLCD: split driver code
In order to make code maintenance easier, split the vairous functions into individial files (this removes a bunch of #ifdefs). Signed-off-by: Bruno Prémont <bonbons@linux-vserver.org> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'drivers/hid/hid-picolcd_fb.c')
-rw-r--r--drivers/hid/hid-picolcd_fb.c673
1 files changed, 673 insertions, 0 deletions
diff --git a/drivers/hid/hid-picolcd_fb.c b/drivers/hid/hid-picolcd_fb.c
new file mode 100644
index 000000000000..b2124f566c61
--- /dev/null
+++ b/drivers/hid/hid-picolcd_fb.c
@@ -0,0 +1,673 @@
1/***************************************************************************
2 * Copyright (C) 2010-2012 by Bruno Prémont <bonbons@linux-vserver.org> *
3 * *
4 * Based on Logitech G13 driver (v0.4) *
5 * Copyright (C) 2009 by Rick L. Vinyard, Jr. <rvinyard@cs.nmsu.edu> *
6 * *
7 * This program is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation, version 2 of the License. *
10 * *
11 * This driver is distributed in the hope that it will be useful, but *
12 * WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14 * General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this software. If not see <http://www.gnu.org/licenses/>. *
18 ***************************************************************************/
19
20#include <linux/hid.h>
21#include "usbhid/usbhid.h"
22#include <linux/usb.h>
23
24#include <linux/fb.h>
25#include <linux/module.h>
26
27#include "hid-picolcd.h"
28
29/* Framebuffer
30 *
31 * The PicoLCD use a Topway LCD module of 256x64 pixel
32 * This display area is tiled over 4 controllers with 8 tiles
33 * each. Each tile has 8x64 pixel, each data byte representing
34 * a 1-bit wide vertical line of the tile.
35 *
36 * The display can be updated at a tile granularity.
37 *
38 * Chip 1 Chip 2 Chip 3 Chip 4
39 * +----------------+----------------+----------------+----------------+
40 * | Tile 1 | Tile 1 | Tile 1 | Tile 1 |
41 * +----------------+----------------+----------------+----------------+
42 * | Tile 2 | Tile 2 | Tile 2 | Tile 2 |
43 * +----------------+----------------+----------------+----------------+
44 * ...
45 * +----------------+----------------+----------------+----------------+
46 * | Tile 8 | Tile 8 | Tile 8 | Tile 8 |
47 * +----------------+----------------+----------------+----------------+
48 */
49#define PICOLCDFB_NAME "picolcdfb"
50#define PICOLCDFB_WIDTH (256)
51#define PICOLCDFB_HEIGHT (64)
52#define PICOLCDFB_SIZE (PICOLCDFB_WIDTH * PICOLCDFB_HEIGHT / 8)
53
54#define PICOLCDFB_UPDATE_RATE_LIMIT 10
55#define PICOLCDFB_UPDATE_RATE_DEFAULT 2
56
57/* Framebuffer visual structures */
58static const struct fb_fix_screeninfo picolcdfb_fix = {
59 .id = PICOLCDFB_NAME,
60 .type = FB_TYPE_PACKED_PIXELS,
61 .visual = FB_VISUAL_MONO01,
62 .xpanstep = 0,
63 .ypanstep = 0,
64 .ywrapstep = 0,
65 .line_length = PICOLCDFB_WIDTH / 8,
66 .accel = FB_ACCEL_NONE,
67};
68
69static const struct fb_var_screeninfo picolcdfb_var = {
70 .xres = PICOLCDFB_WIDTH,
71 .yres = PICOLCDFB_HEIGHT,
72 .xres_virtual = PICOLCDFB_WIDTH,
73 .yres_virtual = PICOLCDFB_HEIGHT,
74 .width = 103,
75 .height = 26,
76 .bits_per_pixel = 1,
77 .grayscale = 1,
78 .red = {
79 .offset = 0,
80 .length = 1,
81 .msb_right = 0,
82 },
83 .green = {
84 .offset = 0,
85 .length = 1,
86 .msb_right = 0,
87 },
88 .blue = {
89 .offset = 0,
90 .length = 1,
91 .msb_right = 0,
92 },
93 .transp = {
94 .offset = 0,
95 .length = 0,
96 .msb_right = 0,
97 },
98};
99
100/* Send a given tile to PicoLCD */
101static int picolcd_fb_send_tile(struct hid_device *hdev, int chip, int tile)
102{
103 struct picolcd_data *data = hid_get_drvdata(hdev);
104 struct hid_report *report1 = picolcd_out_report(REPORT_LCD_CMD_DATA, hdev);
105 struct hid_report *report2 = picolcd_out_report(REPORT_LCD_DATA, hdev);
106 unsigned long flags;
107 u8 *tdata;
108 int i;
109
110 if (!report1 || report1->maxfield != 1 || !report2 || report2->maxfield != 1)
111 return -ENODEV;
112
113 spin_lock_irqsave(&data->lock, flags);
114 hid_set_field(report1->field[0], 0, chip << 2);
115 hid_set_field(report1->field[0], 1, 0x02);
116 hid_set_field(report1->field[0], 2, 0x00);
117 hid_set_field(report1->field[0], 3, 0x00);
118 hid_set_field(report1->field[0], 4, 0xb8 | tile);
119 hid_set_field(report1->field[0], 5, 0x00);
120 hid_set_field(report1->field[0], 6, 0x00);
121 hid_set_field(report1->field[0], 7, 0x40);
122 hid_set_field(report1->field[0], 8, 0x00);
123 hid_set_field(report1->field[0], 9, 0x00);
124 hid_set_field(report1->field[0], 10, 32);
125
126 hid_set_field(report2->field[0], 0, (chip << 2) | 0x01);
127 hid_set_field(report2->field[0], 1, 0x00);
128 hid_set_field(report2->field[0], 2, 0x00);
129 hid_set_field(report2->field[0], 3, 32);
130
131 tdata = data->fb_vbitmap + (tile * 4 + chip) * 64;
132 for (i = 0; i < 64; i++)
133 if (i < 32)
134 hid_set_field(report1->field[0], 11 + i, tdata[i]);
135 else
136 hid_set_field(report2->field[0], 4 + i - 32, tdata[i]);
137
138 usbhid_submit_report(data->hdev, report1, USB_DIR_OUT);
139 usbhid_submit_report(data->hdev, report2, USB_DIR_OUT);
140 spin_unlock_irqrestore(&data->lock, flags);
141 return 0;
142}
143
144/* Translate a single tile*/
145static int picolcd_fb_update_tile(u8 *vbitmap, const u8 *bitmap, int bpp,
146 int chip, int tile)
147{
148 int i, b, changed = 0;
149 u8 tdata[64];
150 u8 *vdata = vbitmap + (tile * 4 + chip) * 64;
151
152 if (bpp == 1) {
153 for (b = 7; b >= 0; b--) {
154 const u8 *bdata = bitmap + tile * 256 + chip * 8 + b * 32;
155 for (i = 0; i < 64; i++) {
156 tdata[i] <<= 1;
157 tdata[i] |= (bdata[i/8] >> (i % 8)) & 0x01;
158 }
159 }
160 } else if (bpp == 8) {
161 for (b = 7; b >= 0; b--) {
162 const u8 *bdata = bitmap + (tile * 256 + chip * 8 + b * 32) * 8;
163 for (i = 0; i < 64; i++) {
164 tdata[i] <<= 1;
165 tdata[i] |= (bdata[i] & 0x80) ? 0x01 : 0x00;
166 }
167 }
168 } else {
169 /* Oops, we should never get here! */
170 WARN_ON(1);
171 return 0;
172 }
173
174 for (i = 0; i < 64; i++)
175 if (tdata[i] != vdata[i]) {
176 changed = 1;
177 vdata[i] = tdata[i];
178 }
179 return changed;
180}
181
182void picolcd_fb_refresh(struct picolcd_data *data)
183{
184 if (data->fb_info)
185 schedule_delayed_work(&data->fb_info->deferred_work, 0);
186}
187
188/* Reconfigure LCD display */
189int picolcd_fb_reset(struct picolcd_data *data, int clear)
190{
191 struct hid_report *report = picolcd_out_report(REPORT_LCD_CMD, data->hdev);
192 int i, j;
193 unsigned long flags;
194 static const u8 mapcmd[8] = { 0x00, 0x02, 0x00, 0x64, 0x3f, 0x00, 0x64, 0xc0 };
195
196 if (!report || report->maxfield != 1)
197 return -ENODEV;
198
199 spin_lock_irqsave(&data->lock, flags);
200 for (i = 0; i < 4; i++) {
201 for (j = 0; j < report->field[0]->maxusage; j++)
202 if (j == 0)
203 hid_set_field(report->field[0], j, i << 2);
204 else if (j < sizeof(mapcmd))
205 hid_set_field(report->field[0], j, mapcmd[j]);
206 else
207 hid_set_field(report->field[0], j, 0);
208 usbhid_submit_report(data->hdev, report, USB_DIR_OUT);
209 }
210
211 data->status |= PICOLCD_READY_FB;
212 spin_unlock_irqrestore(&data->lock, flags);
213
214 if (data->fb_bitmap) {
215 if (clear) {
216 memset(data->fb_vbitmap, 0, PICOLCDFB_SIZE);
217 memset(data->fb_bitmap, 0, PICOLCDFB_SIZE*data->fb_bpp);
218 }
219 data->fb_force = 1;
220 }
221
222 /* schedule first output of framebuffer */
223 picolcd_fb_refresh(data);
224
225 return 0;
226}
227
228/* Update fb_vbitmap from the screen_base and send changed tiles to device */
229static void picolcd_fb_update(struct picolcd_data *data)
230{
231 int chip, tile, n;
232 unsigned long flags;
233
234 if (!data)
235 return;
236
237 spin_lock_irqsave(&data->lock, flags);
238 if (!(data->status & PICOLCD_READY_FB)) {
239 spin_unlock_irqrestore(&data->lock, flags);
240 picolcd_fb_reset(data, 0);
241 } else {
242 spin_unlock_irqrestore(&data->lock, flags);
243 }
244
245 /*
246 * Translate the framebuffer into the format needed by the PicoLCD.
247 * See display layout above.
248 * Do this one tile after the other and push those tiles that changed.
249 *
250 * Wait for our IO to complete as otherwise we might flood the queue!
251 */
252 n = 0;
253 for (chip = 0; chip < 4; chip++)
254 for (tile = 0; tile < 8; tile++)
255 if (picolcd_fb_update_tile(data->fb_vbitmap,
256 data->fb_bitmap, data->fb_bpp, chip, tile) ||
257 data->fb_force) {
258 n += 2;
259 if (!data->fb_info->par)
260 return; /* device lost! */
261 if (n >= HID_OUTPUT_FIFO_SIZE / 2) {
262 usbhid_wait_io(data->hdev);
263 n = 0;
264 }
265 picolcd_fb_send_tile(data->hdev, chip, tile);
266 }
267 data->fb_force = false;
268 if (n)
269 usbhid_wait_io(data->hdev);
270}
271
272/* Stub to call the system default and update the image on the picoLCD */
273static void picolcd_fb_fillrect(struct fb_info *info,
274 const struct fb_fillrect *rect)
275{
276 if (!info->par)
277 return;
278 sys_fillrect(info, rect);
279
280 schedule_delayed_work(&info->deferred_work, 0);
281}
282
283/* Stub to call the system default and update the image on the picoLCD */
284static void picolcd_fb_copyarea(struct fb_info *info,
285 const struct fb_copyarea *area)
286{
287 if (!info->par)
288 return;
289 sys_copyarea(info, area);
290
291 schedule_delayed_work(&info->deferred_work, 0);
292}
293
294/* Stub to call the system default and update the image on the picoLCD */
295static void picolcd_fb_imageblit(struct fb_info *info, const struct fb_image *image)
296{
297 if (!info->par)
298 return;
299 sys_imageblit(info, image);
300
301 schedule_delayed_work(&info->deferred_work, 0);
302}
303
304/*
305 * this is the slow path from userspace. they can seek and write to
306 * the fb. it's inefficient to do anything less than a full screen draw
307 */
308static ssize_t picolcd_fb_write(struct fb_info *info, const char __user *buf,
309 size_t count, loff_t *ppos)
310{
311 ssize_t ret;
312 if (!info->par)
313 return -ENODEV;
314 ret = fb_sys_write(info, buf, count, ppos);
315 if (ret >= 0)
316 schedule_delayed_work(&info->deferred_work, 0);
317 return ret;
318}
319
320static int picolcd_fb_blank(int blank, struct fb_info *info)
321{
322 if (!info->par)
323 return -ENODEV;
324 /* We let fb notification do this for us via lcd/backlight device */
325 return 0;
326}
327
328static void picolcd_fb_destroy(struct fb_info *info)
329{
330 struct picolcd_data *data = info->par;
331 u32 *ref_cnt = info->pseudo_palette;
332 int may_release;
333
334 info->par = NULL;
335 if (data)
336 data->fb_info = NULL;
337 fb_deferred_io_cleanup(info);
338
339 ref_cnt--;
340 mutex_lock(&info->lock);
341 (*ref_cnt)--;
342 may_release = !*ref_cnt;
343 mutex_unlock(&info->lock);
344 if (may_release) {
345 vfree((u8 *)info->fix.smem_start);
346 framebuffer_release(info);
347 }
348}
349
350static int picolcd_fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
351{
352 __u32 bpp = var->bits_per_pixel;
353 __u32 activate = var->activate;
354
355 /* only allow 1/8 bit depth (8-bit is grayscale) */
356 *var = picolcdfb_var;
357 var->activate = activate;
358 if (bpp >= 8) {
359 var->bits_per_pixel = 8;
360 var->red.length = 8;
361 var->green.length = 8;
362 var->blue.length = 8;
363 } else {
364 var->bits_per_pixel = 1;
365 var->red.length = 1;
366 var->green.length = 1;
367 var->blue.length = 1;
368 }
369 return 0;
370}
371
372static int picolcd_set_par(struct fb_info *info)
373{
374 struct picolcd_data *data = info->par;
375 u8 *tmp_fb, *o_fb;
376 if (!data)
377 return -ENODEV;
378 if (info->var.bits_per_pixel == data->fb_bpp)
379 return 0;
380 /* switch between 1/8 bit depths */
381 if (info->var.bits_per_pixel != 1 && info->var.bits_per_pixel != 8)
382 return -EINVAL;
383
384 o_fb = data->fb_bitmap;
385 tmp_fb = kmalloc(PICOLCDFB_SIZE*info->var.bits_per_pixel, GFP_KERNEL);
386 if (!tmp_fb)
387 return -ENOMEM;
388
389 /* translate FB content to new bits-per-pixel */
390 if (info->var.bits_per_pixel == 1) {
391 int i, b;
392 for (i = 0; i < PICOLCDFB_SIZE; i++) {
393 u8 p = 0;
394 for (b = 0; b < 8; b++) {
395 p <<= 1;
396 p |= o_fb[i*8+b] ? 0x01 : 0x00;
397 }
398 tmp_fb[i] = p;
399 }
400 memcpy(o_fb, tmp_fb, PICOLCDFB_SIZE);
401 info->fix.visual = FB_VISUAL_MONO01;
402 info->fix.line_length = PICOLCDFB_WIDTH / 8;
403 } else {
404 int i;
405 memcpy(tmp_fb, o_fb, PICOLCDFB_SIZE);
406 for (i = 0; i < PICOLCDFB_SIZE * 8; i++)
407 o_fb[i] = tmp_fb[i/8] & (0x01 << (7 - i % 8)) ? 0xff : 0x00;
408 info->fix.visual = FB_VISUAL_DIRECTCOLOR;
409 info->fix.line_length = PICOLCDFB_WIDTH;
410 }
411
412 kfree(tmp_fb);
413 data->fb_bpp = info->var.bits_per_pixel;
414 return 0;
415}
416
417/* Do refcounting on our FB and cleanup per worker if FB is
418 * closed after unplug of our device
419 * (fb_release holds info->lock and still touches info after
420 * we return so we can't release it immediately.
421 */
422struct picolcd_fb_cleanup_item {
423 struct fb_info *info;
424 struct picolcd_fb_cleanup_item *next;
425};
426static struct picolcd_fb_cleanup_item *fb_pending;
427static DEFINE_SPINLOCK(fb_pending_lock);
428
429static void picolcd_fb_do_cleanup(struct work_struct *data)
430{
431 struct picolcd_fb_cleanup_item *item;
432 unsigned long flags;
433
434 do {
435 spin_lock_irqsave(&fb_pending_lock, flags);
436 item = fb_pending;
437 fb_pending = item ? item->next : NULL;
438 spin_unlock_irqrestore(&fb_pending_lock, flags);
439
440 if (item) {
441 u8 *fb = (u8 *)item->info->fix.smem_start;
442 /* make sure we do not race against fb core when
443 * releasing */
444 mutex_lock(&item->info->lock);
445 mutex_unlock(&item->info->lock);
446 framebuffer_release(item->info);
447 vfree(fb);
448 }
449 } while (item);
450}
451
452static DECLARE_WORK(picolcd_fb_cleanup, picolcd_fb_do_cleanup);
453
454static int picolcd_fb_open(struct fb_info *info, int u)
455{
456 u32 *ref_cnt = info->pseudo_palette;
457 ref_cnt--;
458
459 (*ref_cnt)++;
460 return 0;
461}
462
463static int picolcd_fb_release(struct fb_info *info, int u)
464{
465 u32 *ref_cnt = info->pseudo_palette;
466 ref_cnt--;
467
468 (*ref_cnt)++;
469 if (!*ref_cnt) {
470 unsigned long flags;
471 struct picolcd_fb_cleanup_item *item = (struct picolcd_fb_cleanup_item *)ref_cnt;
472 item--;
473 spin_lock_irqsave(&fb_pending_lock, flags);
474 item->next = fb_pending;
475 fb_pending = item;
476 spin_unlock_irqrestore(&fb_pending_lock, flags);
477 schedule_work(&picolcd_fb_cleanup);
478 }
479 return 0;
480}
481
482/* Note this can't be const because of struct fb_info definition */
483static struct fb_ops picolcdfb_ops = {
484 .owner = THIS_MODULE,
485 .fb_destroy = picolcd_fb_destroy,
486 .fb_open = picolcd_fb_open,
487 .fb_release = picolcd_fb_release,
488 .fb_read = fb_sys_read,
489 .fb_write = picolcd_fb_write,
490 .fb_blank = picolcd_fb_blank,
491 .fb_fillrect = picolcd_fb_fillrect,
492 .fb_copyarea = picolcd_fb_copyarea,
493 .fb_imageblit = picolcd_fb_imageblit,
494 .fb_check_var = picolcd_fb_check_var,
495 .fb_set_par = picolcd_set_par,
496};
497
498
499/* Callback from deferred IO workqueue */
500static void picolcd_fb_deferred_io(struct fb_info *info, struct list_head *pagelist)
501{
502 picolcd_fb_update(info->par);
503}
504
505static const struct fb_deferred_io picolcd_fb_defio = {
506 .delay = HZ / PICOLCDFB_UPDATE_RATE_DEFAULT,
507 .deferred_io = picolcd_fb_deferred_io,
508};
509
510
511/*
512 * The "fb_update_rate" sysfs attribute
513 */
514static ssize_t picolcd_fb_update_rate_show(struct device *dev,
515 struct device_attribute *attr, char *buf)
516{
517 struct picolcd_data *data = dev_get_drvdata(dev);
518 unsigned i, fb_update_rate = data->fb_update_rate;
519 size_t ret = 0;
520
521 for (i = 1; i <= PICOLCDFB_UPDATE_RATE_LIMIT; i++)
522 if (ret >= PAGE_SIZE)
523 break;
524 else if (i == fb_update_rate)
525 ret += snprintf(buf+ret, PAGE_SIZE-ret, "[%u] ", i);
526 else
527 ret += snprintf(buf+ret, PAGE_SIZE-ret, "%u ", i);
528 if (ret > 0)
529 buf[min(ret, (size_t)PAGE_SIZE)-1] = '\n';
530 return ret;
531}
532
533static ssize_t picolcd_fb_update_rate_store(struct device *dev,
534 struct device_attribute *attr, const char *buf, size_t count)
535{
536 struct picolcd_data *data = dev_get_drvdata(dev);
537 int i;
538 unsigned u;
539
540 if (count < 1 || count > 10)
541 return -EINVAL;
542
543 i = sscanf(buf, "%u", &u);
544 if (i != 1)
545 return -EINVAL;
546
547 if (u > PICOLCDFB_UPDATE_RATE_LIMIT)
548 return -ERANGE;
549 else if (u == 0)
550 u = PICOLCDFB_UPDATE_RATE_DEFAULT;
551
552 data->fb_update_rate = u;
553 data->fb_defio.delay = HZ / data->fb_update_rate;
554 return count;
555}
556
557static DEVICE_ATTR(fb_update_rate, 0666, picolcd_fb_update_rate_show,
558 picolcd_fb_update_rate_store);
559
560/* initialize Framebuffer device */
561int picolcd_init_framebuffer(struct picolcd_data *data)
562{
563 struct device *dev = &data->hdev->dev;
564 struct fb_info *info = NULL;
565 int i, error = -ENOMEM;
566 u8 *fb_vbitmap = NULL;
567 u8 *fb_bitmap = NULL;
568 u32 *palette;
569
570 fb_bitmap = vmalloc(PICOLCDFB_SIZE*8);
571 if (fb_bitmap == NULL) {
572 dev_err(dev, "can't get a free page for framebuffer\n");
573 goto err_nomem;
574 }
575
576 fb_vbitmap = kmalloc(PICOLCDFB_SIZE, GFP_KERNEL);
577 if (fb_vbitmap == NULL) {
578 dev_err(dev, "can't alloc vbitmap image buffer\n");
579 goto err_nomem;
580 }
581
582 data->fb_update_rate = PICOLCDFB_UPDATE_RATE_DEFAULT;
583 data->fb_defio = picolcd_fb_defio;
584 /* The extra memory is:
585 * - struct picolcd_fb_cleanup_item
586 * - u32 for ref_count
587 * - 256*u32 for pseudo_palette
588 */
589 info = framebuffer_alloc(257 * sizeof(u32) + sizeof(struct picolcd_fb_cleanup_item), dev);
590 if (info == NULL) {
591 dev_err(dev, "failed to allocate a framebuffer\n");
592 goto err_nomem;
593 }
594
595 palette = info->par + sizeof(struct picolcd_fb_cleanup_item);
596 *palette = 1;
597 palette++;
598 for (i = 0; i < 256; i++)
599 palette[i] = i > 0 && i < 16 ? 0xff : 0;
600 info->pseudo_palette = palette;
601 info->fbdefio = &data->fb_defio;
602 info->screen_base = (char __force __iomem *)fb_bitmap;
603 info->fbops = &picolcdfb_ops;
604 info->var = picolcdfb_var;
605 info->fix = picolcdfb_fix;
606 info->fix.smem_len = PICOLCDFB_SIZE*8;
607 info->fix.smem_start = (unsigned long)fb_bitmap;
608 info->par = data;
609 info->flags = FBINFO_FLAG_DEFAULT;
610
611 data->fb_vbitmap = fb_vbitmap;
612 data->fb_bitmap = fb_bitmap;
613 data->fb_bpp = picolcdfb_var.bits_per_pixel;
614 error = picolcd_fb_reset(data, 1);
615 if (error) {
616 dev_err(dev, "failed to configure display\n");
617 goto err_cleanup;
618 }
619 error = device_create_file(dev, &dev_attr_fb_update_rate);
620 if (error) {
621 dev_err(dev, "failed to create sysfs attributes\n");
622 goto err_cleanup;
623 }
624 fb_deferred_io_init(info);
625 data->fb_info = info;
626 error = register_framebuffer(info);
627 if (error) {
628 dev_err(dev, "failed to register framebuffer\n");
629 goto err_sysfs;
630 }
631 /* schedule first output of framebuffer */
632 data->fb_force = 1;
633 schedule_delayed_work(&info->deferred_work, 0);
634 return 0;
635
636err_sysfs:
637 fb_deferred_io_cleanup(info);
638 device_remove_file(dev, &dev_attr_fb_update_rate);
639err_cleanup:
640 data->fb_vbitmap = NULL;
641 data->fb_bitmap = NULL;
642 data->fb_bpp = 0;
643 data->fb_info = NULL;
644
645err_nomem:
646 framebuffer_release(info);
647 vfree(fb_bitmap);
648 kfree(fb_vbitmap);
649 return error;
650}
651
652void picolcd_exit_framebuffer(struct picolcd_data *data)
653{
654 struct fb_info *info = data->fb_info;
655 u8 *fb_vbitmap = data->fb_vbitmap;
656
657 if (!info)
658 return;
659
660 device_remove_file(&data->hdev->dev, &dev_attr_fb_update_rate);
661 unregister_framebuffer(info);
662 data->fb_vbitmap = NULL;
663 data->fb_bitmap = NULL;
664 data->fb_bpp = 0;
665 data->fb_info = NULL;
666 kfree(fb_vbitmap);
667}
668
669void picolcd_fb_unload()
670{
671 flush_work_sync(&picolcd_fb_cleanup);
672 WARN_ON(fb_pending);
673}