metronomefb.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792
  1. /*
  2. * linux/drivers/video/metronomefb.c -- FB driver for Metronome controller
  3. *
  4. * Copyright (C) 2008, Jaya Kumar
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file COPYING in the main directory of this archive for
  8. * more details.
  9. *
  10. * Layout is based on skeletonfb.c by James Simmons and Geert Uytterhoeven.
  11. *
  12. * This work was made possible by help and equipment support from E-Ink
  13. * Corporation. http://www.eink.com/
  14. *
  15. * This driver is written to be used with the Metronome display controller.
  16. * It is intended to be architecture independent. A board specific driver
  17. * must be used to perform all the physical IO interactions. An example
  18. * is provided as am200epd.c
  19. *
  20. */
  21. #include <linux/module.h>
  22. #include <linux/kernel.h>
  23. #include <linux/errno.h>
  24. #include <linux/string.h>
  25. #include <linux/mm.h>
  26. #include <linux/vmalloc.h>
  27. #include <linux/delay.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/fb.h>
  30. #include <linux/init.h>
  31. #include <linux/platform_device.h>
  32. #include <linux/list.h>
  33. #include <linux/firmware.h>
  34. #include <linux/dma-mapping.h>
  35. #include <linux/uaccess.h>
  36. #include <linux/irq.h>
  37. #include <video/metronomefb.h>
  38. #include <asm/unaligned.h>
  39. /* Display specific information */
  40. #define DPY_W 832
  41. #define DPY_H 622
  42. static int user_wfm_size;
  43. /* frame differs from image. frame includes non-visible pixels */
  44. struct epd_frame {
  45. int fw; /* frame width */
  46. int fh; /* frame height */
  47. u16 config[4];
  48. int wfm_size;
  49. };
  50. static struct epd_frame epd_frame_table[] = {
  51. {
  52. .fw = 832,
  53. .fh = 622,
  54. .config = {
  55. 15 /* sdlew */
  56. | 2 << 8 /* sdosz */
  57. | 0 << 11 /* sdor */
  58. | 0 << 12 /* sdces */
  59. | 0 << 15, /* sdcer */
  60. 42 /* gdspl */
  61. | 1 << 8 /* gdr1 */
  62. | 1 << 9 /* sdshr */
  63. | 0 << 15, /* gdspp */
  64. 18 /* gdspw */
  65. | 0 << 15, /* dispc */
  66. 599 /* vdlc */
  67. | 0 << 11 /* dsi */
  68. | 0 << 12, /* dsic */
  69. },
  70. .wfm_size = 47001,
  71. },
  72. {
  73. .fw = 1088,
  74. .fh = 791,
  75. .config = {
  76. 0x0104,
  77. 0x031f,
  78. 0x0088,
  79. 0x02ff,
  80. },
  81. .wfm_size = 46770,
  82. },
  83. {
  84. .fw = 1200,
  85. .fh = 842,
  86. .config = {
  87. 0x0101,
  88. 0x030e,
  89. 0x0012,
  90. 0x0280,
  91. },
  92. .wfm_size = 46770,
  93. },
  94. };
  95. static struct fb_fix_screeninfo metronomefb_fix __devinitdata = {
  96. .id = "metronomefb",
  97. .type = FB_TYPE_PACKED_PIXELS,
  98. .visual = FB_VISUAL_STATIC_PSEUDOCOLOR,
  99. .xpanstep = 0,
  100. .ypanstep = 0,
  101. .ywrapstep = 0,
  102. .line_length = DPY_W,
  103. .accel = FB_ACCEL_NONE,
  104. };
  105. static struct fb_var_screeninfo metronomefb_var __devinitdata = {
  106. .xres = DPY_W,
  107. .yres = DPY_H,
  108. .xres_virtual = DPY_W,
  109. .yres_virtual = DPY_H,
  110. .bits_per_pixel = 8,
  111. .grayscale = 1,
  112. .nonstd = 1,
  113. .red = { 4, 3, 0 },
  114. .green = { 0, 0, 0 },
  115. .blue = { 0, 0, 0 },
  116. .transp = { 0, 0, 0 },
  117. };
  118. /* the waveform structure that is coming from userspace firmware */
  119. struct waveform_hdr {
  120. u8 stuff[32];
  121. u8 wmta[3];
  122. u8 fvsn;
  123. u8 luts;
  124. u8 mc;
  125. u8 trc;
  126. u8 stuff3;
  127. u8 endb;
  128. u8 swtb;
  129. u8 stuff2a[2];
  130. u8 stuff2b[3];
  131. u8 wfm_cs;
  132. } __attribute__ ((packed));
  133. /* main metronomefb functions */
  134. static u8 calc_cksum(int start, int end, u8 *mem)
  135. {
  136. u8 tmp = 0;
  137. int i;
  138. for (i = start; i < end; i++)
  139. tmp += mem[i];
  140. return tmp;
  141. }
  142. static u16 calc_img_cksum(u16 *start, int length)
  143. {
  144. u16 tmp = 0;
  145. while (length--)
  146. tmp += *start++;
  147. return tmp;
  148. }
  149. /* here we decode the incoming waveform file and populate metromem */
  150. static int __devinit load_waveform(u8 *mem, size_t size, int m, int t,
  151. struct metronomefb_par *par)
  152. {
  153. int tta;
  154. int wmta;
  155. int trn = 0;
  156. int i;
  157. unsigned char v;
  158. u8 cksum;
  159. int cksum_idx;
  160. int wfm_idx, owfm_idx;
  161. int mem_idx = 0;
  162. struct waveform_hdr *wfm_hdr;
  163. u8 *metromem = par->metromem_wfm;
  164. struct device *dev = par->info->dev;
  165. if (user_wfm_size)
  166. epd_frame_table[par->dt].wfm_size = user_wfm_size;
  167. if (size != epd_frame_table[par->dt].wfm_size) {
  168. dev_err(dev, "Error: unexpected size %Zd != %d\n", size,
  169. epd_frame_table[par->dt].wfm_size);
  170. return -EINVAL;
  171. }
  172. wfm_hdr = (struct waveform_hdr *) mem;
  173. if (wfm_hdr->fvsn != 1) {
  174. dev_err(dev, "Error: bad fvsn %x\n", wfm_hdr->fvsn);
  175. return -EINVAL;
  176. }
  177. if (wfm_hdr->luts != 0) {
  178. dev_err(dev, "Error: bad luts %x\n", wfm_hdr->luts);
  179. return -EINVAL;
  180. }
  181. cksum = calc_cksum(32, 47, mem);
  182. if (cksum != wfm_hdr->wfm_cs) {
  183. dev_err(dev, "Error: bad cksum %x != %x\n", cksum,
  184. wfm_hdr->wfm_cs);
  185. return -EINVAL;
  186. }
  187. wfm_hdr->mc += 1;
  188. wfm_hdr->trc += 1;
  189. for (i = 0; i < 5; i++) {
  190. if (*(wfm_hdr->stuff2a + i) != 0) {
  191. dev_err(dev, "Error: unexpected value in padding\n");
  192. return -EINVAL;
  193. }
  194. }
  195. /* calculating trn. trn is something used to index into
  196. the waveform. presumably selecting the right one for the
  197. desired temperature. it works out the offset of the first
  198. v that exceeds the specified temperature */
  199. if ((sizeof(*wfm_hdr) + wfm_hdr->trc) > size)
  200. return -EINVAL;
  201. for (i = sizeof(*wfm_hdr); i <= sizeof(*wfm_hdr) + wfm_hdr->trc; i++) {
  202. if (mem[i] > t) {
  203. trn = i - sizeof(*wfm_hdr) - 1;
  204. break;
  205. }
  206. }
  207. /* check temperature range table checksum */
  208. cksum_idx = sizeof(*wfm_hdr) + wfm_hdr->trc + 1;
  209. if (cksum_idx > size)
  210. return -EINVAL;
  211. cksum = calc_cksum(sizeof(*wfm_hdr), cksum_idx, mem);
  212. if (cksum != mem[cksum_idx]) {
  213. dev_err(dev, "Error: bad temperature range table cksum"
  214. " %x != %x\n", cksum, mem[cksum_idx]);
  215. return -EINVAL;
  216. }
  217. /* check waveform mode table address checksum */
  218. wmta = get_unaligned_le32(wfm_hdr->wmta) & 0x00FFFFFF;
  219. cksum_idx = wmta + m*4 + 3;
  220. if (cksum_idx > size)
  221. return -EINVAL;
  222. cksum = calc_cksum(cksum_idx - 3, cksum_idx, mem);
  223. if (cksum != mem[cksum_idx]) {
  224. dev_err(dev, "Error: bad mode table address cksum"
  225. " %x != %x\n", cksum, mem[cksum_idx]);
  226. return -EINVAL;
  227. }
  228. /* check waveform temperature table address checksum */
  229. tta = get_unaligned_le32(mem + wmta + m * 4) & 0x00FFFFFF;
  230. cksum_idx = tta + trn*4 + 3;
  231. if (cksum_idx > size)
  232. return -EINVAL;
  233. cksum = calc_cksum(cksum_idx - 3, cksum_idx, mem);
  234. if (cksum != mem[cksum_idx]) {
  235. dev_err(dev, "Error: bad temperature table address cksum"
  236. " %x != %x\n", cksum, mem[cksum_idx]);
  237. return -EINVAL;
  238. }
  239. /* here we do the real work of putting the waveform into the
  240. metromem buffer. this does runlength decoding of the waveform */
  241. wfm_idx = get_unaligned_le32(mem + tta + trn * 4) & 0x00FFFFFF;
  242. owfm_idx = wfm_idx;
  243. if (wfm_idx > size)
  244. return -EINVAL;
  245. while (wfm_idx < size) {
  246. unsigned char rl;
  247. v = mem[wfm_idx++];
  248. if (v == wfm_hdr->swtb) {
  249. while (((v = mem[wfm_idx++]) != wfm_hdr->swtb) &&
  250. wfm_idx < size)
  251. metromem[mem_idx++] = v;
  252. continue;
  253. }
  254. if (v == wfm_hdr->endb)
  255. break;
  256. rl = mem[wfm_idx++];
  257. for (i = 0; i <= rl; i++)
  258. metromem[mem_idx++] = v;
  259. }
  260. cksum_idx = wfm_idx;
  261. if (cksum_idx > size)
  262. return -EINVAL;
  263. cksum = calc_cksum(owfm_idx, cksum_idx, mem);
  264. if (cksum != mem[cksum_idx]) {
  265. dev_err(dev, "Error: bad waveform data cksum"
  266. " %x != %x\n", cksum, mem[cksum_idx]);
  267. return -EINVAL;
  268. }
  269. par->frame_count = (mem_idx/64);
  270. return 0;
  271. }
  272. static int metronome_display_cmd(struct metronomefb_par *par)
  273. {
  274. int i;
  275. u16 cs;
  276. u16 opcode;
  277. static u8 borderval;
  278. /* setup display command
  279. we can't immediately set the opcode since the controller
  280. will try parse the command before we've set it all up
  281. so we just set cs here and set the opcode at the end */
  282. if (par->metromem_cmd->opcode == 0xCC40)
  283. opcode = cs = 0xCC41;
  284. else
  285. opcode = cs = 0xCC40;
  286. /* set the args ( 2 bytes ) for display */
  287. i = 0;
  288. par->metromem_cmd->args[i] = 1 << 3 /* border update */
  289. | ((borderval++ % 4) & 0x0F) << 4
  290. | (par->frame_count - 1) << 8;
  291. cs += par->metromem_cmd->args[i++];
  292. /* the rest are 0 */
  293. memset((u8 *) (par->metromem_cmd->args + i), 0, (32-i)*2);
  294. par->metromem_cmd->csum = cs;
  295. par->metromem_cmd->opcode = opcode; /* display cmd */
  296. return par->board->met_wait_event_intr(par);
  297. }
  298. static int __devinit metronome_powerup_cmd(struct metronomefb_par *par)
  299. {
  300. int i;
  301. u16 cs;
  302. /* setup power up command */
  303. par->metromem_cmd->opcode = 0x1234; /* pwr up pseudo cmd */
  304. cs = par->metromem_cmd->opcode;
  305. /* set pwr1,2,3 to 1024 */
  306. for (i = 0; i < 3; i++) {
  307. par->metromem_cmd->args[i] = 1024;
  308. cs += par->metromem_cmd->args[i];
  309. }
  310. /* the rest are 0 */
  311. memset((u8 *) (par->metromem_cmd->args + i), 0, (32-i)*2);
  312. par->metromem_cmd->csum = cs;
  313. msleep(1);
  314. par->board->set_rst(par, 1);
  315. msleep(1);
  316. par->board->set_stdby(par, 1);
  317. return par->board->met_wait_event(par);
  318. }
  319. static int __devinit metronome_config_cmd(struct metronomefb_par *par)
  320. {
  321. /* setup config command
  322. we can't immediately set the opcode since the controller
  323. will try parse the command before we've set it all up */
  324. memcpy(par->metromem_cmd->args, epd_frame_table[par->dt].config,
  325. sizeof(epd_frame_table[par->dt].config));
  326. /* the rest are 0 */
  327. memset((u8 *) (par->metromem_cmd->args + 4), 0, (32-4)*2);
  328. par->metromem_cmd->csum = 0xCC10;
  329. par->metromem_cmd->csum += calc_img_cksum(par->metromem_cmd->args, 4);
  330. par->metromem_cmd->opcode = 0xCC10; /* config cmd */
  331. return par->board->met_wait_event(par);
  332. }
  333. static int __devinit metronome_init_cmd(struct metronomefb_par *par)
  334. {
  335. int i;
  336. u16 cs;
  337. /* setup init command
  338. we can't immediately set the opcode since the controller
  339. will try parse the command before we've set it all up
  340. so we just set cs here and set the opcode at the end */
  341. cs = 0xCC20;
  342. /* set the args ( 2 bytes ) for init */
  343. i = 0;
  344. par->metromem_cmd->args[i] = 0;
  345. cs += par->metromem_cmd->args[i++];
  346. /* the rest are 0 */
  347. memset((u8 *) (par->metromem_cmd->args + i), 0, (32-i)*2);
  348. par->metromem_cmd->csum = cs;
  349. par->metromem_cmd->opcode = 0xCC20; /* init cmd */
  350. return par->board->met_wait_event(par);
  351. }
  352. static int __devinit metronome_init_regs(struct metronomefb_par *par)
  353. {
  354. int res;
  355. res = par->board->setup_io(par);
  356. if (res)
  357. return res;
  358. res = metronome_powerup_cmd(par);
  359. if (res)
  360. return res;
  361. res = metronome_config_cmd(par);
  362. if (res)
  363. return res;
  364. res = metronome_init_cmd(par);
  365. return res;
  366. }
  367. static void metronomefb_dpy_update(struct metronomefb_par *par)
  368. {
  369. int fbsize;
  370. u16 cksum;
  371. unsigned char *buf = (unsigned char __force *)par->info->screen_base;
  372. fbsize = par->info->fix.smem_len;
  373. /* copy from vm to metromem */
  374. memcpy(par->metromem_img, buf, fbsize);
  375. cksum = calc_img_cksum((u16 *) par->metromem_img, fbsize/2);
  376. *((u16 *)(par->metromem_img) + fbsize/2) = cksum;
  377. metronome_display_cmd(par);
  378. }
  379. static u16 metronomefb_dpy_update_page(struct metronomefb_par *par, int index)
  380. {
  381. int i;
  382. u16 csum = 0;
  383. u16 *buf = (u16 __force *)(par->info->screen_base + index);
  384. u16 *img = (u16 *)(par->metromem_img + index);
  385. /* swizzle from vm to metromem and recalc cksum at the same time*/
  386. for (i = 0; i < PAGE_SIZE/2; i++) {
  387. *(img + i) = (buf[i] << 5) & 0xE0E0;
  388. csum += *(img + i);
  389. }
  390. return csum;
  391. }
  392. /* this is called back from the deferred io workqueue */
  393. static void metronomefb_dpy_deferred_io(struct fb_info *info,
  394. struct list_head *pagelist)
  395. {
  396. u16 cksum;
  397. struct page *cur;
  398. struct fb_deferred_io *fbdefio = info->fbdefio;
  399. struct metronomefb_par *par = info->par;
  400. /* walk the written page list and swizzle the data */
  401. list_for_each_entry(cur, &fbdefio->pagelist, lru) {
  402. cksum = metronomefb_dpy_update_page(par,
  403. (cur->index << PAGE_SHIFT));
  404. par->metromem_img_csum -= par->csum_table[cur->index];
  405. par->csum_table[cur->index] = cksum;
  406. par->metromem_img_csum += cksum;
  407. }
  408. metronome_display_cmd(par);
  409. }
  410. static void metronomefb_fillrect(struct fb_info *info,
  411. const struct fb_fillrect *rect)
  412. {
  413. struct metronomefb_par *par = info->par;
  414. sys_fillrect(info, rect);
  415. metronomefb_dpy_update(par);
  416. }
  417. static void metronomefb_copyarea(struct fb_info *info,
  418. const struct fb_copyarea *area)
  419. {
  420. struct metronomefb_par *par = info->par;
  421. sys_copyarea(info, area);
  422. metronomefb_dpy_update(par);
  423. }
  424. static void metronomefb_imageblit(struct fb_info *info,
  425. const struct fb_image *image)
  426. {
  427. struct metronomefb_par *par = info->par;
  428. sys_imageblit(info, image);
  429. metronomefb_dpy_update(par);
  430. }
  431. /*
  432. * this is the slow path from userspace. they can seek and write to
  433. * the fb. it is based on fb_sys_write
  434. */
  435. static ssize_t metronomefb_write(struct fb_info *info, const char __user *buf,
  436. size_t count, loff_t *ppos)
  437. {
  438. struct metronomefb_par *par = info->par;
  439. unsigned long p = *ppos;
  440. void *dst;
  441. int err = 0;
  442. unsigned long total_size;
  443. if (info->state != FBINFO_STATE_RUNNING)
  444. return -EPERM;
  445. total_size = info->fix.smem_len;
  446. if (p > total_size)
  447. return -EFBIG;
  448. if (count > total_size) {
  449. err = -EFBIG;
  450. count = total_size;
  451. }
  452. if (count + p > total_size) {
  453. if (!err)
  454. err = -ENOSPC;
  455. count = total_size - p;
  456. }
  457. dst = (void __force *)(info->screen_base + p);
  458. if (copy_from_user(dst, buf, count))
  459. err = -EFAULT;
  460. if (!err)
  461. *ppos += count;
  462. metronomefb_dpy_update(par);
  463. return (err) ? err : count;
  464. }
  465. static struct fb_ops metronomefb_ops = {
  466. .owner = THIS_MODULE,
  467. .fb_write = metronomefb_write,
  468. .fb_fillrect = metronomefb_fillrect,
  469. .fb_copyarea = metronomefb_copyarea,
  470. .fb_imageblit = metronomefb_imageblit,
  471. };
  472. static struct fb_deferred_io metronomefb_defio = {
  473. .delay = HZ,
  474. .deferred_io = metronomefb_dpy_deferred_io,
  475. };
  476. static int __devinit metronomefb_probe(struct platform_device *dev)
  477. {
  478. struct fb_info *info;
  479. struct metronome_board *board;
  480. int retval = -ENOMEM;
  481. int videomemorysize;
  482. unsigned char *videomemory;
  483. struct metronomefb_par *par;
  484. const struct firmware *fw_entry;
  485. int i;
  486. int panel_type;
  487. int fw, fh;
  488. int epd_dt_index;
  489. /* pick up board specific routines */
  490. board = dev->dev.platform_data;
  491. if (!board)
  492. return -EINVAL;
  493. /* try to count device specific driver, if can't, platform recalls */
  494. if (!try_module_get(board->owner))
  495. return -ENODEV;
  496. info = framebuffer_alloc(sizeof(struct metronomefb_par), &dev->dev);
  497. if (!info)
  498. goto err;
  499. /* we have two blocks of memory.
  500. info->screen_base which is vm, and is the fb used by apps.
  501. par->metromem which is physically contiguous memory and
  502. contains the display controller commands, waveform,
  503. processed image data and padding. this is the data pulled
  504. by the device's LCD controller and pushed to Metronome.
  505. the metromem memory is allocated by the board driver and
  506. is provided to us */
  507. panel_type = board->get_panel_type();
  508. switch (panel_type) {
  509. case 6:
  510. epd_dt_index = 0;
  511. break;
  512. case 8:
  513. epd_dt_index = 1;
  514. break;
  515. case 97:
  516. epd_dt_index = 2;
  517. break;
  518. default:
  519. dev_err(&dev->dev, "Unexpected panel type. Defaulting to 6\n");
  520. epd_dt_index = 0;
  521. break;
  522. }
  523. fw = epd_frame_table[epd_dt_index].fw;
  524. fh = epd_frame_table[epd_dt_index].fh;
  525. /* we need to add a spare page because our csum caching scheme walks
  526. * to the end of the page */
  527. videomemorysize = PAGE_SIZE + (fw * fh);
  528. videomemory = vzalloc(videomemorysize);
  529. if (!videomemory)
  530. goto err_fb_rel;
  531. info->screen_base = (char __force __iomem *)videomemory;
  532. info->fbops = &metronomefb_ops;
  533. metronomefb_fix.line_length = fw;
  534. metronomefb_var.xres = fw;
  535. metronomefb_var.yres = fh;
  536. metronomefb_var.xres_virtual = fw;
  537. metronomefb_var.yres_virtual = fh;
  538. info->var = metronomefb_var;
  539. info->fix = metronomefb_fix;
  540. info->fix.smem_len = videomemorysize;
  541. par = info->par;
  542. par->info = info;
  543. par->board = board;
  544. par->dt = epd_dt_index;
  545. init_waitqueue_head(&par->waitq);
  546. /* this table caches per page csum values. */
  547. par->csum_table = vmalloc(videomemorysize/PAGE_SIZE);
  548. if (!par->csum_table)
  549. goto err_vfree;
  550. /* the physical framebuffer that we use is setup by
  551. * the platform device driver. It will provide us
  552. * with cmd, wfm and image memory in a contiguous area. */
  553. retval = board->setup_fb(par);
  554. if (retval) {
  555. dev_err(&dev->dev, "Failed to setup fb\n");
  556. goto err_csum_table;
  557. }
  558. /* after this point we should have a framebuffer */
  559. if ((!par->metromem_wfm) || (!par->metromem_img) ||
  560. (!par->metromem_dma)) {
  561. dev_err(&dev->dev, "fb access failure\n");
  562. retval = -EINVAL;
  563. goto err_csum_table;
  564. }
  565. info->fix.smem_start = par->metromem_dma;
  566. /* load the waveform in. assume mode 3, temp 31 for now
  567. a) request the waveform file from userspace
  568. b) process waveform and decode into metromem */
  569. retval = request_firmware(&fw_entry, "metronome.wbf", &dev->dev);
  570. if (retval < 0) {
  571. dev_err(&dev->dev, "Failed to get waveform\n");
  572. goto err_csum_table;
  573. }
  574. retval = load_waveform((u8 *) fw_entry->data, fw_entry->size, 3, 31,
  575. par);
  576. release_firmware(fw_entry);
  577. if (retval < 0) {
  578. dev_err(&dev->dev, "Failed processing waveform\n");
  579. goto err_csum_table;
  580. }
  581. if (board->setup_irq(info))
  582. goto err_csum_table;
  583. retval = metronome_init_regs(par);
  584. if (retval < 0)
  585. goto err_free_irq;
  586. info->flags = FBINFO_FLAG_DEFAULT | FBINFO_VIRTFB;
  587. info->fbdefio = &metronomefb_defio;
  588. fb_deferred_io_init(info);
  589. retval = fb_alloc_cmap(&info->cmap, 8, 0);
  590. if (retval < 0) {
  591. dev_err(&dev->dev, "Failed to allocate colormap\n");
  592. goto err_free_irq;
  593. }
  594. /* set cmap */
  595. for (i = 0; i < 8; i++)
  596. info->cmap.red[i] = (((2*i)+1)*(0xFFFF))/16;
  597. memcpy(info->cmap.green, info->cmap.red, sizeof(u16)*8);
  598. memcpy(info->cmap.blue, info->cmap.red, sizeof(u16)*8);
  599. retval = register_framebuffer(info);
  600. if (retval < 0)
  601. goto err_cmap;
  602. platform_set_drvdata(dev, info);
  603. dev_dbg(&dev->dev,
  604. "fb%d: Metronome frame buffer device, using %dK of video"
  605. " memory\n", info->node, videomemorysize >> 10);
  606. return 0;
  607. err_cmap:
  608. fb_dealloc_cmap(&info->cmap);
  609. err_free_irq:
  610. board->cleanup(par);
  611. err_csum_table:
  612. vfree(par->csum_table);
  613. err_vfree:
  614. vfree(videomemory);
  615. err_fb_rel:
  616. framebuffer_release(info);
  617. err:
  618. module_put(board->owner);
  619. return retval;
  620. }
  621. static int __devexit metronomefb_remove(struct platform_device *dev)
  622. {
  623. struct fb_info *info = platform_get_drvdata(dev);
  624. if (info) {
  625. struct metronomefb_par *par = info->par;
  626. unregister_framebuffer(info);
  627. fb_deferred_io_cleanup(info);
  628. fb_dealloc_cmap(&info->cmap);
  629. par->board->cleanup(par);
  630. vfree(par->csum_table);
  631. vfree((void __force *)info->screen_base);
  632. module_put(par->board->owner);
  633. dev_dbg(&dev->dev, "calling release\n");
  634. framebuffer_release(info);
  635. }
  636. return 0;
  637. }
  638. static struct platform_driver metronomefb_driver = {
  639. .probe = metronomefb_probe,
  640. .remove = __devexit_p(metronomefb_remove),
  641. .driver = {
  642. .owner = THIS_MODULE,
  643. .name = "metronomefb",
  644. },
  645. };
  646. static int __init metronomefb_init(void)
  647. {
  648. return platform_driver_register(&metronomefb_driver);
  649. }
  650. static void __exit metronomefb_exit(void)
  651. {
  652. platform_driver_unregister(&metronomefb_driver);
  653. }
  654. module_param(user_wfm_size, uint, 0);
  655. MODULE_PARM_DESC(user_wfm_size, "Set custom waveform size");
  656. module_init(metronomefb_init);
  657. module_exit(metronomefb_exit);
  658. MODULE_DESCRIPTION("fbdev driver for Metronome controller");
  659. MODULE_AUTHOR("Jaya Kumar");
  660. MODULE_LICENSE("GPL");