hid-picolcd_fb.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  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. #include <linux/hid.h>
  20. #include <linux/vmalloc.h>
  21. #include <linux/fb.h>
  22. #include <linux/module.h>
  23. #include "hid-picolcd.h"
  24. /* Framebuffer
  25. *
  26. * The PicoLCD use a Topway LCD module of 256x64 pixel
  27. * This display area is tiled over 4 controllers with 8 tiles
  28. * each. Each tile has 8x64 pixel, each data byte representing
  29. * a 1-bit wide vertical line of the tile.
  30. *
  31. * The display can be updated at a tile granularity.
  32. *
  33. * Chip 1 Chip 2 Chip 3 Chip 4
  34. * +----------------+----------------+----------------+----------------+
  35. * | Tile 1 | Tile 1 | Tile 1 | Tile 1 |
  36. * +----------------+----------------+----------------+----------------+
  37. * | Tile 2 | Tile 2 | Tile 2 | Tile 2 |
  38. * +----------------+----------------+----------------+----------------+
  39. * ...
  40. * +----------------+----------------+----------------+----------------+
  41. * | Tile 8 | Tile 8 | Tile 8 | Tile 8 |
  42. * +----------------+----------------+----------------+----------------+
  43. */
  44. #define PICOLCDFB_NAME "picolcdfb"
  45. #define PICOLCDFB_WIDTH (256)
  46. #define PICOLCDFB_HEIGHT (64)
  47. #define PICOLCDFB_SIZE (PICOLCDFB_WIDTH * PICOLCDFB_HEIGHT / 8)
  48. #define PICOLCDFB_UPDATE_RATE_LIMIT 10
  49. #define PICOLCDFB_UPDATE_RATE_DEFAULT 2
  50. /* Framebuffer visual structures */
  51. static const struct fb_fix_screeninfo picolcdfb_fix = {
  52. .id = PICOLCDFB_NAME,
  53. .type = FB_TYPE_PACKED_PIXELS,
  54. .visual = FB_VISUAL_MONO01,
  55. .xpanstep = 0,
  56. .ypanstep = 0,
  57. .ywrapstep = 0,
  58. .line_length = PICOLCDFB_WIDTH / 8,
  59. .accel = FB_ACCEL_NONE,
  60. };
  61. static const struct fb_var_screeninfo picolcdfb_var = {
  62. .xres = PICOLCDFB_WIDTH,
  63. .yres = PICOLCDFB_HEIGHT,
  64. .xres_virtual = PICOLCDFB_WIDTH,
  65. .yres_virtual = PICOLCDFB_HEIGHT,
  66. .width = 103,
  67. .height = 26,
  68. .bits_per_pixel = 1,
  69. .grayscale = 1,
  70. .red = {
  71. .offset = 0,
  72. .length = 1,
  73. .msb_right = 0,
  74. },
  75. .green = {
  76. .offset = 0,
  77. .length = 1,
  78. .msb_right = 0,
  79. },
  80. .blue = {
  81. .offset = 0,
  82. .length = 1,
  83. .msb_right = 0,
  84. },
  85. .transp = {
  86. .offset = 0,
  87. .length = 0,
  88. .msb_right = 0,
  89. },
  90. };
  91. /* Send a given tile to PicoLCD */
  92. static int picolcd_fb_send_tile(struct picolcd_data *data, u8 *vbitmap,
  93. int chip, int tile)
  94. {
  95. struct hid_report *report1, *report2;
  96. unsigned long flags;
  97. u8 *tdata;
  98. int i;
  99. report1 = picolcd_out_report(REPORT_LCD_CMD_DATA, data->hdev);
  100. if (!report1 || report1->maxfield != 1)
  101. return -ENODEV;
  102. report2 = picolcd_out_report(REPORT_LCD_DATA, data->hdev);
  103. if (!report2 || report2->maxfield != 1)
  104. return -ENODEV;
  105. spin_lock_irqsave(&data->lock, flags);
  106. if ((data->status & PICOLCD_FAILED)) {
  107. spin_unlock_irqrestore(&data->lock, flags);
  108. return -ENODEV;
  109. }
  110. hid_set_field(report1->field[0], 0, chip << 2);
  111. hid_set_field(report1->field[0], 1, 0x02);
  112. hid_set_field(report1->field[0], 2, 0x00);
  113. hid_set_field(report1->field[0], 3, 0x00);
  114. hid_set_field(report1->field[0], 4, 0xb8 | tile);
  115. hid_set_field(report1->field[0], 5, 0x00);
  116. hid_set_field(report1->field[0], 6, 0x00);
  117. hid_set_field(report1->field[0], 7, 0x40);
  118. hid_set_field(report1->field[0], 8, 0x00);
  119. hid_set_field(report1->field[0], 9, 0x00);
  120. hid_set_field(report1->field[0], 10, 32);
  121. hid_set_field(report2->field[0], 0, (chip << 2) | 0x01);
  122. hid_set_field(report2->field[0], 1, 0x00);
  123. hid_set_field(report2->field[0], 2, 0x00);
  124. hid_set_field(report2->field[0], 3, 32);
  125. tdata = vbitmap + (tile * 4 + chip) * 64;
  126. for (i = 0; i < 64; i++)
  127. if (i < 32)
  128. hid_set_field(report1->field[0], 11 + i, tdata[i]);
  129. else
  130. hid_set_field(report2->field[0], 4 + i - 32, tdata[i]);
  131. hid_hw_request(data->hdev, report1, HID_REQ_SET_REPORT);
  132. hid_hw_request(data->hdev, report2, HID_REQ_SET_REPORT);
  133. spin_unlock_irqrestore(&data->lock, flags);
  134. return 0;
  135. }
  136. /* Translate a single tile*/
  137. static int picolcd_fb_update_tile(u8 *vbitmap, const u8 *bitmap, int bpp,
  138. int chip, int tile)
  139. {
  140. int i, b, changed = 0;
  141. u8 tdata[64];
  142. u8 *vdata = vbitmap + (tile * 4 + chip) * 64;
  143. if (bpp == 1) {
  144. for (b = 7; b >= 0; b--) {
  145. const u8 *bdata = bitmap + tile * 256 + chip * 8 + b * 32;
  146. for (i = 0; i < 64; i++) {
  147. tdata[i] <<= 1;
  148. tdata[i] |= (bdata[i/8] >> (i % 8)) & 0x01;
  149. }
  150. }
  151. } else if (bpp == 8) {
  152. for (b = 7; b >= 0; b--) {
  153. const u8 *bdata = bitmap + (tile * 256 + chip * 8 + b * 32) * 8;
  154. for (i = 0; i < 64; i++) {
  155. tdata[i] <<= 1;
  156. tdata[i] |= (bdata[i] & 0x80) ? 0x01 : 0x00;
  157. }
  158. }
  159. } else {
  160. /* Oops, we should never get here! */
  161. WARN_ON(1);
  162. return 0;
  163. }
  164. for (i = 0; i < 64; i++)
  165. if (tdata[i] != vdata[i]) {
  166. changed = 1;
  167. vdata[i] = tdata[i];
  168. }
  169. return changed;
  170. }
  171. void picolcd_fb_refresh(struct picolcd_data *data)
  172. {
  173. if (data->fb_info)
  174. schedule_delayed_work(&data->fb_info->deferred_work, 0);
  175. }
  176. /* Reconfigure LCD display */
  177. int picolcd_fb_reset(struct picolcd_data *data, int clear)
  178. {
  179. struct hid_report *report = picolcd_out_report(REPORT_LCD_CMD, data->hdev);
  180. struct picolcd_fb_data *fbdata = data->fb_info->par;
  181. int i, j;
  182. unsigned long flags;
  183. static const u8 mapcmd[8] = { 0x00, 0x02, 0x00, 0x64, 0x3f, 0x00, 0x64, 0xc0 };
  184. if (!report || report->maxfield != 1)
  185. return -ENODEV;
  186. spin_lock_irqsave(&data->lock, flags);
  187. for (i = 0; i < 4; i++) {
  188. for (j = 0; j < report->field[0]->maxusage; j++)
  189. if (j == 0)
  190. hid_set_field(report->field[0], j, i << 2);
  191. else if (j < sizeof(mapcmd))
  192. hid_set_field(report->field[0], j, mapcmd[j]);
  193. else
  194. hid_set_field(report->field[0], j, 0);
  195. hid_hw_request(data->hdev, report, HID_REQ_SET_REPORT);
  196. }
  197. spin_unlock_irqrestore(&data->lock, flags);
  198. if (clear) {
  199. memset(fbdata->vbitmap, 0, PICOLCDFB_SIZE);
  200. memset(fbdata->bitmap, 0, PICOLCDFB_SIZE*fbdata->bpp);
  201. }
  202. fbdata->force = 1;
  203. /* schedule first output of framebuffer */
  204. if (fbdata->ready)
  205. schedule_delayed_work(&data->fb_info->deferred_work, 0);
  206. else
  207. fbdata->ready = 1;
  208. return 0;
  209. }
  210. /* Update fb_vbitmap from the screen_base and send changed tiles to device */
  211. static void picolcd_fb_update(struct fb_info *info)
  212. {
  213. int chip, tile, n;
  214. unsigned long flags;
  215. struct picolcd_fb_data *fbdata = info->par;
  216. struct picolcd_data *data;
  217. mutex_lock(&info->lock);
  218. spin_lock_irqsave(&fbdata->lock, flags);
  219. if (!fbdata->ready && fbdata->picolcd)
  220. picolcd_fb_reset(fbdata->picolcd, 0);
  221. spin_unlock_irqrestore(&fbdata->lock, flags);
  222. /*
  223. * Translate the framebuffer into the format needed by the PicoLCD.
  224. * See display layout above.
  225. * Do this one tile after the other and push those tiles that changed.
  226. *
  227. * Wait for our IO to complete as otherwise we might flood the queue!
  228. */
  229. n = 0;
  230. for (chip = 0; chip < 4; chip++)
  231. for (tile = 0; tile < 8; tile++) {
  232. if (!fbdata->force && !picolcd_fb_update_tile(
  233. fbdata->vbitmap, fbdata->bitmap,
  234. fbdata->bpp, chip, tile))
  235. continue;
  236. n += 2;
  237. if (n >= HID_OUTPUT_FIFO_SIZE / 2) {
  238. spin_lock_irqsave(&fbdata->lock, flags);
  239. data = fbdata->picolcd;
  240. spin_unlock_irqrestore(&fbdata->lock, flags);
  241. mutex_unlock(&info->lock);
  242. if (!data)
  243. return;
  244. hid_hw_wait(data->hdev);
  245. mutex_lock(&info->lock);
  246. n = 0;
  247. }
  248. spin_lock_irqsave(&fbdata->lock, flags);
  249. data = fbdata->picolcd;
  250. spin_unlock_irqrestore(&fbdata->lock, flags);
  251. if (!data || picolcd_fb_send_tile(data,
  252. fbdata->vbitmap, chip, tile))
  253. goto out;
  254. }
  255. fbdata->force = false;
  256. if (n) {
  257. spin_lock_irqsave(&fbdata->lock, flags);
  258. data = fbdata->picolcd;
  259. spin_unlock_irqrestore(&fbdata->lock, flags);
  260. mutex_unlock(&info->lock);
  261. if (data)
  262. hid_hw_wait(data->hdev);
  263. return;
  264. }
  265. out:
  266. mutex_unlock(&info->lock);
  267. }
  268. /* Stub to call the system default and update the image on the picoLCD */
  269. static void picolcd_fb_fillrect(struct fb_info *info,
  270. const struct fb_fillrect *rect)
  271. {
  272. if (!info->par)
  273. return;
  274. sys_fillrect(info, rect);
  275. schedule_delayed_work(&info->deferred_work, 0);
  276. }
  277. /* Stub to call the system default and update the image on the picoLCD */
  278. static void picolcd_fb_copyarea(struct fb_info *info,
  279. const struct fb_copyarea *area)
  280. {
  281. if (!info->par)
  282. return;
  283. sys_copyarea(info, area);
  284. schedule_delayed_work(&info->deferred_work, 0);
  285. }
  286. /* Stub to call the system default and update the image on the picoLCD */
  287. static void picolcd_fb_imageblit(struct fb_info *info, const struct fb_image *image)
  288. {
  289. if (!info->par)
  290. return;
  291. sys_imageblit(info, image);
  292. schedule_delayed_work(&info->deferred_work, 0);
  293. }
  294. /*
  295. * this is the slow path from userspace. they can seek and write to
  296. * the fb. it's inefficient to do anything less than a full screen draw
  297. */
  298. static ssize_t picolcd_fb_write(struct fb_info *info, const char __user *buf,
  299. size_t count, loff_t *ppos)
  300. {
  301. ssize_t ret;
  302. if (!info->par)
  303. return -ENODEV;
  304. ret = fb_sys_write(info, buf, count, ppos);
  305. if (ret >= 0)
  306. schedule_delayed_work(&info->deferred_work, 0);
  307. return ret;
  308. }
  309. static int picolcd_fb_blank(int blank, struct fb_info *info)
  310. {
  311. /* We let fb notification do this for us via lcd/backlight device */
  312. return 0;
  313. }
  314. static void picolcd_fb_destroy(struct fb_info *info)
  315. {
  316. struct picolcd_fb_data *fbdata = info->par;
  317. /* make sure no work is deferred */
  318. fb_deferred_io_cleanup(info);
  319. /* No thridparty should ever unregister our framebuffer! */
  320. WARN_ON(fbdata->picolcd != NULL);
  321. vfree((u8 *)info->fix.smem_start);
  322. framebuffer_release(info);
  323. }
  324. static int picolcd_fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
  325. {
  326. __u32 bpp = var->bits_per_pixel;
  327. __u32 activate = var->activate;
  328. /* only allow 1/8 bit depth (8-bit is grayscale) */
  329. *var = picolcdfb_var;
  330. var->activate = activate;
  331. if (bpp >= 8) {
  332. var->bits_per_pixel = 8;
  333. var->red.length = 8;
  334. var->green.length = 8;
  335. var->blue.length = 8;
  336. } else {
  337. var->bits_per_pixel = 1;
  338. var->red.length = 1;
  339. var->green.length = 1;
  340. var->blue.length = 1;
  341. }
  342. return 0;
  343. }
  344. static int picolcd_set_par(struct fb_info *info)
  345. {
  346. struct picolcd_fb_data *fbdata = info->par;
  347. u8 *tmp_fb, *o_fb;
  348. if (info->var.bits_per_pixel == fbdata->bpp)
  349. return 0;
  350. /* switch between 1/8 bit depths */
  351. if (info->var.bits_per_pixel != 1 && info->var.bits_per_pixel != 8)
  352. return -EINVAL;
  353. o_fb = fbdata->bitmap;
  354. tmp_fb = kmalloc_array(PICOLCDFB_SIZE, info->var.bits_per_pixel,
  355. GFP_KERNEL);
  356. if (!tmp_fb)
  357. return -ENOMEM;
  358. /* translate FB content to new bits-per-pixel */
  359. if (info->var.bits_per_pixel == 1) {
  360. int i, b;
  361. for (i = 0; i < PICOLCDFB_SIZE; i++) {
  362. u8 p = 0;
  363. for (b = 0; b < 8; b++) {
  364. p <<= 1;
  365. p |= o_fb[i*8+b] ? 0x01 : 0x00;
  366. }
  367. tmp_fb[i] = p;
  368. }
  369. memcpy(o_fb, tmp_fb, PICOLCDFB_SIZE);
  370. info->fix.visual = FB_VISUAL_MONO01;
  371. info->fix.line_length = PICOLCDFB_WIDTH / 8;
  372. } else {
  373. int i;
  374. memcpy(tmp_fb, o_fb, PICOLCDFB_SIZE);
  375. for (i = 0; i < PICOLCDFB_SIZE * 8; i++)
  376. o_fb[i] = tmp_fb[i/8] & (0x01 << (7 - i % 8)) ? 0xff : 0x00;
  377. info->fix.visual = FB_VISUAL_DIRECTCOLOR;
  378. info->fix.line_length = PICOLCDFB_WIDTH;
  379. }
  380. kfree(tmp_fb);
  381. fbdata->bpp = info->var.bits_per_pixel;
  382. return 0;
  383. }
  384. /* Note this can't be const because of struct fb_info definition */
  385. static struct fb_ops picolcdfb_ops = {
  386. .owner = THIS_MODULE,
  387. .fb_destroy = picolcd_fb_destroy,
  388. .fb_read = fb_sys_read,
  389. .fb_write = picolcd_fb_write,
  390. .fb_blank = picolcd_fb_blank,
  391. .fb_fillrect = picolcd_fb_fillrect,
  392. .fb_copyarea = picolcd_fb_copyarea,
  393. .fb_imageblit = picolcd_fb_imageblit,
  394. .fb_check_var = picolcd_fb_check_var,
  395. .fb_set_par = picolcd_set_par,
  396. };
  397. /* Callback from deferred IO workqueue */
  398. static void picolcd_fb_deferred_io(struct fb_info *info, struct list_head *pagelist)
  399. {
  400. picolcd_fb_update(info);
  401. }
  402. static const struct fb_deferred_io picolcd_fb_defio = {
  403. .delay = HZ / PICOLCDFB_UPDATE_RATE_DEFAULT,
  404. .deferred_io = picolcd_fb_deferred_io,
  405. };
  406. /*
  407. * The "fb_update_rate" sysfs attribute
  408. */
  409. static ssize_t picolcd_fb_update_rate_show(struct device *dev,
  410. struct device_attribute *attr, char *buf)
  411. {
  412. struct picolcd_data *data = dev_get_drvdata(dev);
  413. struct picolcd_fb_data *fbdata = data->fb_info->par;
  414. unsigned i, fb_update_rate = fbdata->update_rate;
  415. size_t ret = 0;
  416. for (i = 1; i <= PICOLCDFB_UPDATE_RATE_LIMIT; i++)
  417. if (ret >= PAGE_SIZE)
  418. break;
  419. else if (i == fb_update_rate)
  420. ret += snprintf(buf+ret, PAGE_SIZE-ret, "[%u] ", i);
  421. else
  422. ret += snprintf(buf+ret, PAGE_SIZE-ret, "%u ", i);
  423. if (ret > 0)
  424. buf[min(ret, (size_t)PAGE_SIZE)-1] = '\n';
  425. return ret;
  426. }
  427. static ssize_t picolcd_fb_update_rate_store(struct device *dev,
  428. struct device_attribute *attr, const char *buf, size_t count)
  429. {
  430. struct picolcd_data *data = dev_get_drvdata(dev);
  431. struct picolcd_fb_data *fbdata = data->fb_info->par;
  432. int i;
  433. unsigned u;
  434. if (count < 1 || count > 10)
  435. return -EINVAL;
  436. i = sscanf(buf, "%u", &u);
  437. if (i != 1)
  438. return -EINVAL;
  439. if (u > PICOLCDFB_UPDATE_RATE_LIMIT)
  440. return -ERANGE;
  441. else if (u == 0)
  442. u = PICOLCDFB_UPDATE_RATE_DEFAULT;
  443. fbdata->update_rate = u;
  444. data->fb_info->fbdefio->delay = HZ / fbdata->update_rate;
  445. return count;
  446. }
  447. static DEVICE_ATTR(fb_update_rate, 0664, picolcd_fb_update_rate_show,
  448. picolcd_fb_update_rate_store);
  449. /* initialize Framebuffer device */
  450. int picolcd_init_framebuffer(struct picolcd_data *data)
  451. {
  452. struct device *dev = &data->hdev->dev;
  453. struct fb_info *info = NULL;
  454. struct picolcd_fb_data *fbdata = NULL;
  455. int i, error = -ENOMEM;
  456. u32 *palette;
  457. /* The extra memory is:
  458. * - 256*u32 for pseudo_palette
  459. * - struct fb_deferred_io
  460. */
  461. info = framebuffer_alloc(256 * sizeof(u32) +
  462. sizeof(struct fb_deferred_io) +
  463. sizeof(struct picolcd_fb_data) +
  464. PICOLCDFB_SIZE, dev);
  465. if (info == NULL) {
  466. dev_err(dev, "failed to allocate a framebuffer\n");
  467. goto err_nomem;
  468. }
  469. info->fbdefio = info->par;
  470. *info->fbdefio = picolcd_fb_defio;
  471. info->par += sizeof(struct fb_deferred_io);
  472. palette = info->par;
  473. info->par += 256 * sizeof(u32);
  474. for (i = 0; i < 256; i++)
  475. palette[i] = i > 0 && i < 16 ? 0xff : 0;
  476. info->pseudo_palette = palette;
  477. info->fbops = &picolcdfb_ops;
  478. info->var = picolcdfb_var;
  479. info->fix = picolcdfb_fix;
  480. info->fix.smem_len = PICOLCDFB_SIZE*8;
  481. info->flags = FBINFO_FLAG_DEFAULT;
  482. fbdata = info->par;
  483. spin_lock_init(&fbdata->lock);
  484. fbdata->picolcd = data;
  485. fbdata->update_rate = PICOLCDFB_UPDATE_RATE_DEFAULT;
  486. fbdata->bpp = picolcdfb_var.bits_per_pixel;
  487. fbdata->force = 1;
  488. fbdata->vbitmap = info->par + sizeof(struct picolcd_fb_data);
  489. fbdata->bitmap = vmalloc(PICOLCDFB_SIZE*8);
  490. if (fbdata->bitmap == NULL) {
  491. dev_err(dev, "can't get a free page for framebuffer\n");
  492. goto err_nomem;
  493. }
  494. info->screen_base = (char __force __iomem *)fbdata->bitmap;
  495. info->fix.smem_start = (unsigned long)fbdata->bitmap;
  496. memset(fbdata->vbitmap, 0xff, PICOLCDFB_SIZE);
  497. data->fb_info = info;
  498. error = picolcd_fb_reset(data, 1);
  499. if (error) {
  500. dev_err(dev, "failed to configure display\n");
  501. goto err_cleanup;
  502. }
  503. error = device_create_file(dev, &dev_attr_fb_update_rate);
  504. if (error) {
  505. dev_err(dev, "failed to create sysfs attributes\n");
  506. goto err_cleanup;
  507. }
  508. fb_deferred_io_init(info);
  509. error = register_framebuffer(info);
  510. if (error) {
  511. dev_err(dev, "failed to register framebuffer\n");
  512. goto err_sysfs;
  513. }
  514. return 0;
  515. err_sysfs:
  516. device_remove_file(dev, &dev_attr_fb_update_rate);
  517. fb_deferred_io_cleanup(info);
  518. err_cleanup:
  519. data->fb_info = NULL;
  520. err_nomem:
  521. if (fbdata)
  522. vfree(fbdata->bitmap);
  523. framebuffer_release(info);
  524. return error;
  525. }
  526. void picolcd_exit_framebuffer(struct picolcd_data *data)
  527. {
  528. struct fb_info *info = data->fb_info;
  529. struct picolcd_fb_data *fbdata;
  530. unsigned long flags;
  531. if (!info)
  532. return;
  533. device_remove_file(&data->hdev->dev, &dev_attr_fb_update_rate);
  534. fbdata = info->par;
  535. /* disconnect framebuffer from HID dev */
  536. spin_lock_irqsave(&fbdata->lock, flags);
  537. fbdata->picolcd = NULL;
  538. spin_unlock_irqrestore(&fbdata->lock, flags);
  539. /* make sure there is no running update - thus that fbdata->picolcd
  540. * once obtained under lock is guaranteed not to get free() under
  541. * the feet of the deferred work */
  542. flush_delayed_work(&info->deferred_work);
  543. data->fb_info = NULL;
  544. unregister_framebuffer(info);
  545. }