au1100fb.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. /*
  2. * BRIEF MODULE DESCRIPTION
  3. * Au1100 LCD Driver.
  4. *
  5. * Rewritten for 2.6 by Embedded Alley Solutions
  6. * <source@embeddedalley.com>, based on submissions by
  7. * Karl Lessard <klessard@sunrisetelecom.com>
  8. * <c.pellegrin@exadron.com>
  9. *
  10. * PM support added by Rodolfo Giometti <giometti@linux.it>
  11. * Cursor enable/disable by Rodolfo Giometti <giometti@linux.it>
  12. *
  13. * Copyright 2002 MontaVista Software
  14. * Author: MontaVista Software, Inc.
  15. * ppopov@mvista.com or source@mvista.com
  16. *
  17. * Copyright 2002 Alchemy Semiconductor
  18. * Author: Alchemy Semiconductor
  19. *
  20. * Based on:
  21. * linux/drivers/video/skeletonfb.c -- Skeleton for a frame buffer device
  22. * Created 28 Dec 1997 by Geert Uytterhoeven
  23. *
  24. * This program is free software; you can redistribute it and/or modify it
  25. * under the terms of the GNU General Public License as published by the
  26. * Free Software Foundation; either version 2 of the License, or (at your
  27. * option) any later version.
  28. *
  29. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  30. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  31. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  32. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  33. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  34. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  35. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  36. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  37. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  38. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  39. *
  40. * You should have received a copy of the GNU General Public License along
  41. * with this program; if not, write to the Free Software Foundation, Inc.,
  42. * 675 Mass Ave, Cambridge, MA 02139, USA.
  43. */
  44. #include <linux/clk.h>
  45. #include <linux/module.h>
  46. #include <linux/kernel.h>
  47. #include <linux/errno.h>
  48. #include <linux/string.h>
  49. #include <linux/mm.h>
  50. #include <linux/fb.h>
  51. #include <linux/init.h>
  52. #include <linux/interrupt.h>
  53. #include <linux/ctype.h>
  54. #include <linux/dma-mapping.h>
  55. #include <linux/platform_device.h>
  56. #include <linux/slab.h>
  57. #include <asm/mach-au1x00/au1000.h>
  58. #define DEBUG 0
  59. #include "au1100fb.h"
  60. #define DRIVER_NAME "au1100fb"
  61. #define DRIVER_DESC "LCD controller driver for AU1100 processors"
  62. #define to_au1100fb_device(_info) \
  63. (_info ? container_of(_info, struct au1100fb_device, info) : NULL);
  64. /* Bitfields format supported by the controller. Note that the order of formats
  65. * SHOULD be the same as in the LCD_CONTROL_SBPPF field, so we can retrieve the
  66. * right pixel format by doing rgb_bitfields[LCD_CONTROL_SBPPF_XXX >> LCD_CONTROL_SBPPF]
  67. */
  68. struct fb_bitfield rgb_bitfields[][4] =
  69. {
  70. /* Red, Green, Blue, Transp */
  71. { { 10, 6, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
  72. { { 11, 5, 0 }, { 5, 6, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
  73. { { 11, 5, 0 }, { 6, 5, 0 }, { 0, 6, 0 }, { 0, 0, 0 } },
  74. { { 10, 5, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 15, 1, 0 } },
  75. { { 11, 5, 0 }, { 6, 5, 0 }, { 1, 5, 0 }, { 0, 1, 0 } },
  76. /* The last is used to describe 12bpp format */
  77. { { 8, 4, 0 }, { 4, 4, 0 }, { 0, 4, 0 }, { 0, 0, 0 } },
  78. };
  79. static struct fb_fix_screeninfo au1100fb_fix = {
  80. .id = "AU1100 FB",
  81. .xpanstep = 1,
  82. .ypanstep = 1,
  83. .type = FB_TYPE_PACKED_PIXELS,
  84. .accel = FB_ACCEL_NONE,
  85. };
  86. static struct fb_var_screeninfo au1100fb_var = {
  87. .activate = FB_ACTIVATE_NOW,
  88. .height = -1,
  89. .width = -1,
  90. .vmode = FB_VMODE_NONINTERLACED,
  91. };
  92. /* fb_blank
  93. * Blank the screen. Depending on the mode, the screen will be
  94. * activated with the backlight color, or desactivated
  95. */
  96. static int au1100fb_fb_blank(int blank_mode, struct fb_info *fbi)
  97. {
  98. struct au1100fb_device *fbdev = to_au1100fb_device(fbi);
  99. print_dbg("fb_blank %d %p", blank_mode, fbi);
  100. switch (blank_mode) {
  101. case VESA_NO_BLANKING:
  102. /* Turn on panel */
  103. fbdev->regs->lcd_control |= LCD_CONTROL_GO;
  104. wmb(); /* drain writebuffer */
  105. break;
  106. case VESA_VSYNC_SUSPEND:
  107. case VESA_HSYNC_SUSPEND:
  108. case VESA_POWERDOWN:
  109. /* Turn off panel */
  110. fbdev->regs->lcd_control &= ~LCD_CONTROL_GO;
  111. wmb(); /* drain writebuffer */
  112. break;
  113. default:
  114. break;
  115. }
  116. return 0;
  117. }
  118. /*
  119. * Set hardware with var settings. This will enable the controller with a specific
  120. * mode, normally validated with the fb_check_var method
  121. */
  122. int au1100fb_setmode(struct au1100fb_device *fbdev)
  123. {
  124. struct fb_info *info = &fbdev->info;
  125. u32 words;
  126. int index;
  127. if (!fbdev)
  128. return -EINVAL;
  129. /* Update var-dependent FB info */
  130. if (panel_is_active(fbdev->panel) || panel_is_color(fbdev->panel)) {
  131. if (info->var.bits_per_pixel <= 8) {
  132. /* palettized */
  133. info->var.red.offset = 0;
  134. info->var.red.length = info->var.bits_per_pixel;
  135. info->var.red.msb_right = 0;
  136. info->var.green.offset = 0;
  137. info->var.green.length = info->var.bits_per_pixel;
  138. info->var.green.msb_right = 0;
  139. info->var.blue.offset = 0;
  140. info->var.blue.length = info->var.bits_per_pixel;
  141. info->var.blue.msb_right = 0;
  142. info->var.transp.offset = 0;
  143. info->var.transp.length = 0;
  144. info->var.transp.msb_right = 0;
  145. info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
  146. info->fix.line_length = info->var.xres_virtual /
  147. (8/info->var.bits_per_pixel);
  148. } else {
  149. /* non-palettized */
  150. index = (fbdev->panel->control_base & LCD_CONTROL_SBPPF_MASK) >> LCD_CONTROL_SBPPF_BIT;
  151. info->var.red = rgb_bitfields[index][0];
  152. info->var.green = rgb_bitfields[index][1];
  153. info->var.blue = rgb_bitfields[index][2];
  154. info->var.transp = rgb_bitfields[index][3];
  155. info->fix.visual = FB_VISUAL_TRUECOLOR;
  156. info->fix.line_length = info->var.xres_virtual << 1; /* depth=16 */
  157. }
  158. } else {
  159. /* mono */
  160. info->fix.visual = FB_VISUAL_MONO10;
  161. info->fix.line_length = info->var.xres_virtual / 8;
  162. }
  163. info->screen_size = info->fix.line_length * info->var.yres_virtual;
  164. info->var.rotate = ((fbdev->panel->control_base&LCD_CONTROL_SM_MASK) \
  165. >> LCD_CONTROL_SM_BIT) * 90;
  166. /* Determine BPP mode and format */
  167. fbdev->regs->lcd_control = fbdev->panel->control_base;
  168. fbdev->regs->lcd_horztiming = fbdev->panel->horztiming;
  169. fbdev->regs->lcd_verttiming = fbdev->panel->verttiming;
  170. fbdev->regs->lcd_clkcontrol = fbdev->panel->clkcontrol_base;
  171. fbdev->regs->lcd_intenable = 0;
  172. fbdev->regs->lcd_intstatus = 0;
  173. fbdev->regs->lcd_dmaaddr0 = LCD_DMA_SA_N(fbdev->fb_phys);
  174. if (panel_is_dual(fbdev->panel)) {
  175. /* Second panel display seconf half of screen if possible,
  176. * otherwise display the same as the first panel */
  177. if (info->var.yres_virtual >= (info->var.yres << 1)) {
  178. fbdev->regs->lcd_dmaaddr1 = LCD_DMA_SA_N(fbdev->fb_phys +
  179. (info->fix.line_length *
  180. (info->var.yres_virtual >> 1)));
  181. } else {
  182. fbdev->regs->lcd_dmaaddr1 = LCD_DMA_SA_N(fbdev->fb_phys);
  183. }
  184. }
  185. words = info->fix.line_length / sizeof(u32);
  186. if (!info->var.rotate || (info->var.rotate == 180)) {
  187. words *= info->var.yres_virtual;
  188. if (info->var.rotate /* 180 */) {
  189. words -= (words % 8); /* should be divisable by 8 */
  190. }
  191. }
  192. fbdev->regs->lcd_words = LCD_WRD_WRDS_N(words);
  193. fbdev->regs->lcd_pwmdiv = 0;
  194. fbdev->regs->lcd_pwmhi = 0;
  195. /* Resume controller */
  196. fbdev->regs->lcd_control |= LCD_CONTROL_GO;
  197. mdelay(10);
  198. au1100fb_fb_blank(VESA_NO_BLANKING, info);
  199. return 0;
  200. }
  201. /* fb_setcolreg
  202. * Set color in LCD palette.
  203. */
  204. int au1100fb_fb_setcolreg(unsigned regno, unsigned red, unsigned green, unsigned blue, unsigned transp, struct fb_info *fbi)
  205. {
  206. struct au1100fb_device *fbdev;
  207. u32 *palette;
  208. u32 value;
  209. fbdev = to_au1100fb_device(fbi);
  210. palette = fbdev->regs->lcd_pallettebase;
  211. if (regno > (AU1100_LCD_NBR_PALETTE_ENTRIES - 1))
  212. return -EINVAL;
  213. if (fbi->var.grayscale) {
  214. /* Convert color to grayscale */
  215. red = green = blue =
  216. (19595 * red + 38470 * green + 7471 * blue) >> 16;
  217. }
  218. if (fbi->fix.visual == FB_VISUAL_TRUECOLOR) {
  219. /* Place color in the pseudopalette */
  220. if (regno > 16)
  221. return -EINVAL;
  222. palette = (u32*)fbi->pseudo_palette;
  223. red >>= (16 - fbi->var.red.length);
  224. green >>= (16 - fbi->var.green.length);
  225. blue >>= (16 - fbi->var.blue.length);
  226. value = (red << fbi->var.red.offset) |
  227. (green << fbi->var.green.offset)|
  228. (blue << fbi->var.blue.offset);
  229. value &= 0xFFFF;
  230. } else if (panel_is_active(fbdev->panel)) {
  231. /* COLOR TFT PALLETTIZED (use RGB 565) */
  232. value = (red & 0xF800)|((green >> 5) & 0x07E0)|((blue >> 11) & 0x001F);
  233. value &= 0xFFFF;
  234. } else if (panel_is_color(fbdev->panel)) {
  235. /* COLOR STN MODE */
  236. value = (((panel_swap_rgb(fbdev->panel) ? blue : red) >> 12) & 0x000F) |
  237. ((green >> 8) & 0x00F0) |
  238. (((panel_swap_rgb(fbdev->panel) ? red : blue) >> 4) & 0x0F00);
  239. value &= 0xFFF;
  240. } else {
  241. /* MONOCHROME MODE */
  242. value = (green >> 12) & 0x000F;
  243. value &= 0xF;
  244. }
  245. palette[regno] = value;
  246. return 0;
  247. }
  248. /* fb_pan_display
  249. * Pan display in x and/or y as specified
  250. */
  251. int au1100fb_fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *fbi)
  252. {
  253. struct au1100fb_device *fbdev;
  254. int dy;
  255. fbdev = to_au1100fb_device(fbi);
  256. print_dbg("fb_pan_display %p %p", var, fbi);
  257. if (!var || !fbdev) {
  258. return -EINVAL;
  259. }
  260. if (var->xoffset - fbi->var.xoffset) {
  261. /* No support for X panning for now! */
  262. return -EINVAL;
  263. }
  264. print_dbg("fb_pan_display 2 %p %p", var, fbi);
  265. dy = var->yoffset - fbi->var.yoffset;
  266. if (dy) {
  267. u32 dmaaddr;
  268. print_dbg("Panning screen of %d lines", dy);
  269. dmaaddr = fbdev->regs->lcd_dmaaddr0;
  270. dmaaddr += (fbi->fix.line_length * dy);
  271. /* TODO: Wait for current frame to finished */
  272. fbdev->regs->lcd_dmaaddr0 = LCD_DMA_SA_N(dmaaddr);
  273. if (panel_is_dual(fbdev->panel)) {
  274. dmaaddr = fbdev->regs->lcd_dmaaddr1;
  275. dmaaddr += (fbi->fix.line_length * dy);
  276. fbdev->regs->lcd_dmaaddr0 = LCD_DMA_SA_N(dmaaddr);
  277. }
  278. }
  279. print_dbg("fb_pan_display 3 %p %p", var, fbi);
  280. return 0;
  281. }
  282. /* fb_rotate
  283. * Rotate the display of this angle. This doesn't seems to be used by the core,
  284. * but as our hardware supports it, so why not implementing it...
  285. */
  286. void au1100fb_fb_rotate(struct fb_info *fbi, int angle)
  287. {
  288. struct au1100fb_device *fbdev = to_au1100fb_device(fbi);
  289. print_dbg("fb_rotate %p %d", fbi, angle);
  290. if (fbdev && (angle > 0) && !(angle % 90)) {
  291. fbdev->regs->lcd_control &= ~LCD_CONTROL_GO;
  292. fbdev->regs->lcd_control &= ~(LCD_CONTROL_SM_MASK);
  293. fbdev->regs->lcd_control |= ((angle/90) << LCD_CONTROL_SM_BIT);
  294. fbdev->regs->lcd_control |= LCD_CONTROL_GO;
  295. }
  296. }
  297. /* fb_mmap
  298. * Map video memory in user space. We don't use the generic fb_mmap method mainly
  299. * to allow the use of the TLB streaming flag (CCA=6)
  300. */
  301. int au1100fb_fb_mmap(struct fb_info *fbi, struct vm_area_struct *vma)
  302. {
  303. struct au1100fb_device *fbdev;
  304. fbdev = to_au1100fb_device(fbi);
  305. vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
  306. pgprot_val(vma->vm_page_prot) |= (6 << 9); //CCA=6
  307. return vm_iomap_memory(vma, fbdev->fb_phys, fbdev->fb_len);
  308. }
  309. static struct fb_ops au1100fb_ops =
  310. {
  311. .owner = THIS_MODULE,
  312. .fb_setcolreg = au1100fb_fb_setcolreg,
  313. .fb_blank = au1100fb_fb_blank,
  314. .fb_pan_display = au1100fb_fb_pan_display,
  315. .fb_fillrect = cfb_fillrect,
  316. .fb_copyarea = cfb_copyarea,
  317. .fb_imageblit = cfb_imageblit,
  318. .fb_rotate = au1100fb_fb_rotate,
  319. .fb_mmap = au1100fb_fb_mmap,
  320. };
  321. /*-------------------------------------------------------------------------*/
  322. static int au1100fb_setup(struct au1100fb_device *fbdev)
  323. {
  324. char *this_opt, *options;
  325. int num_panels = ARRAY_SIZE(known_lcd_panels);
  326. if (num_panels <= 0) {
  327. print_err("No LCD panels supported by driver!");
  328. return -ENODEV;
  329. }
  330. if (fb_get_options(DRIVER_NAME, &options))
  331. return -ENODEV;
  332. if (!options)
  333. return -ENODEV;
  334. while ((this_opt = strsep(&options, ",")) != NULL) {
  335. /* Panel option */
  336. if (!strncmp(this_opt, "panel:", 6)) {
  337. int i;
  338. this_opt += 6;
  339. for (i = 0; i < num_panels; i++) {
  340. if (!strncmp(this_opt, known_lcd_panels[i].name,
  341. strlen(this_opt))) {
  342. fbdev->panel = &known_lcd_panels[i];
  343. fbdev->panel_idx = i;
  344. break;
  345. }
  346. }
  347. if (i >= num_panels) {
  348. print_warn("Panel '%s' not supported!", this_opt);
  349. return -ENODEV;
  350. }
  351. }
  352. /* Unsupported option */
  353. else
  354. print_warn("Unsupported option \"%s\"", this_opt);
  355. }
  356. print_info("Panel=%s", fbdev->panel->name);
  357. return 0;
  358. }
  359. static int au1100fb_drv_probe(struct platform_device *dev)
  360. {
  361. struct au1100fb_device *fbdev = NULL;
  362. struct resource *regs_res;
  363. unsigned long page;
  364. struct clk *c;
  365. /* Allocate new device private */
  366. fbdev = devm_kzalloc(&dev->dev, sizeof(struct au1100fb_device),
  367. GFP_KERNEL);
  368. if (!fbdev) {
  369. print_err("fail to allocate device private record");
  370. return -ENOMEM;
  371. }
  372. if (au1100fb_setup(fbdev))
  373. goto failed;
  374. platform_set_drvdata(dev, (void *)fbdev);
  375. /* Allocate region for our registers and map them */
  376. regs_res = platform_get_resource(dev, IORESOURCE_MEM, 0);
  377. if (!regs_res) {
  378. print_err("fail to retrieve registers resource");
  379. return -EFAULT;
  380. }
  381. au1100fb_fix.mmio_start = regs_res->start;
  382. au1100fb_fix.mmio_len = resource_size(regs_res);
  383. if (!devm_request_mem_region(&dev->dev,
  384. au1100fb_fix.mmio_start,
  385. au1100fb_fix.mmio_len,
  386. DRIVER_NAME)) {
  387. print_err("fail to lock memory region at 0x%08lx",
  388. au1100fb_fix.mmio_start);
  389. return -EBUSY;
  390. }
  391. fbdev->regs = (struct au1100fb_regs*)KSEG1ADDR(au1100fb_fix.mmio_start);
  392. print_dbg("Register memory map at %p", fbdev->regs);
  393. print_dbg("phys=0x%08x, size=%d", fbdev->regs_phys, fbdev->regs_len);
  394. c = clk_get(NULL, "lcd_intclk");
  395. if (!IS_ERR(c)) {
  396. fbdev->lcdclk = c;
  397. clk_set_rate(c, 48000000);
  398. clk_prepare_enable(c);
  399. }
  400. /* Allocate the framebuffer to the maximum screen size * nbr of video buffers */
  401. fbdev->fb_len = fbdev->panel->xres * fbdev->panel->yres *
  402. (fbdev->panel->bpp >> 3) * AU1100FB_NBR_VIDEO_BUFFERS;
  403. fbdev->fb_mem = dmam_alloc_coherent(&dev->dev,
  404. PAGE_ALIGN(fbdev->fb_len),
  405. &fbdev->fb_phys, GFP_KERNEL);
  406. if (!fbdev->fb_mem) {
  407. print_err("fail to allocate frambuffer (size: %dK))",
  408. fbdev->fb_len / 1024);
  409. return -ENOMEM;
  410. }
  411. au1100fb_fix.smem_start = fbdev->fb_phys;
  412. au1100fb_fix.smem_len = fbdev->fb_len;
  413. /*
  414. * Set page reserved so that mmap will work. This is necessary
  415. * since we'll be remapping normal memory.
  416. */
  417. for (page = (unsigned long)fbdev->fb_mem;
  418. page < PAGE_ALIGN((unsigned long)fbdev->fb_mem + fbdev->fb_len);
  419. page += PAGE_SIZE) {
  420. #ifdef CONFIG_DMA_NONCOHERENT
  421. SetPageReserved(virt_to_page(CAC_ADDR((void *)page)));
  422. #else
  423. SetPageReserved(virt_to_page(page));
  424. #endif
  425. }
  426. print_dbg("Framebuffer memory map at %p", fbdev->fb_mem);
  427. print_dbg("phys=0x%08x, size=%dK", fbdev->fb_phys, fbdev->fb_len / 1024);
  428. /* load the panel info into the var struct */
  429. au1100fb_var.bits_per_pixel = fbdev->panel->bpp;
  430. au1100fb_var.xres = fbdev->panel->xres;
  431. au1100fb_var.xres_virtual = au1100fb_var.xres;
  432. au1100fb_var.yres = fbdev->panel->yres;
  433. au1100fb_var.yres_virtual = au1100fb_var.yres;
  434. fbdev->info.screen_base = fbdev->fb_mem;
  435. fbdev->info.fbops = &au1100fb_ops;
  436. fbdev->info.fix = au1100fb_fix;
  437. fbdev->info.pseudo_palette =
  438. devm_kzalloc(&dev->dev, sizeof(u32) * 16, GFP_KERNEL);
  439. if (!fbdev->info.pseudo_palette)
  440. return -ENOMEM;
  441. if (fb_alloc_cmap(&fbdev->info.cmap, AU1100_LCD_NBR_PALETTE_ENTRIES, 0) < 0) {
  442. print_err("Fail to allocate colormap (%d entries)",
  443. AU1100_LCD_NBR_PALETTE_ENTRIES);
  444. return -EFAULT;
  445. }
  446. fbdev->info.var = au1100fb_var;
  447. /* Set h/w registers */
  448. au1100fb_setmode(fbdev);
  449. /* Register new framebuffer */
  450. if (register_framebuffer(&fbdev->info) < 0) {
  451. print_err("cannot register new framebuffer");
  452. goto failed;
  453. }
  454. return 0;
  455. failed:
  456. if (fbdev->lcdclk) {
  457. clk_disable_unprepare(fbdev->lcdclk);
  458. clk_put(fbdev->lcdclk);
  459. }
  460. if (fbdev->fb_mem) {
  461. dma_free_noncoherent(&dev->dev, fbdev->fb_len, fbdev->fb_mem,
  462. fbdev->fb_phys);
  463. }
  464. if (fbdev->info.cmap.len != 0) {
  465. fb_dealloc_cmap(&fbdev->info.cmap);
  466. }
  467. return -ENODEV;
  468. }
  469. int au1100fb_drv_remove(struct platform_device *dev)
  470. {
  471. struct au1100fb_device *fbdev = NULL;
  472. if (!dev)
  473. return -ENODEV;
  474. fbdev = platform_get_drvdata(dev);
  475. #if !defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_LOGO)
  476. au1100fb_fb_blank(VESA_POWERDOWN, &fbdev->info);
  477. #endif
  478. fbdev->regs->lcd_control &= ~LCD_CONTROL_GO;
  479. /* Clean up all probe data */
  480. unregister_framebuffer(&fbdev->info);
  481. fb_dealloc_cmap(&fbdev->info.cmap);
  482. if (fbdev->lcdclk) {
  483. clk_disable_unprepare(fbdev->lcdclk);
  484. clk_put(fbdev->lcdclk);
  485. }
  486. return 0;
  487. }
  488. #ifdef CONFIG_PM
  489. static struct au1100fb_regs fbregs;
  490. int au1100fb_drv_suspend(struct platform_device *dev, pm_message_t state)
  491. {
  492. struct au1100fb_device *fbdev = platform_get_drvdata(dev);
  493. if (!fbdev)
  494. return 0;
  495. /* Blank the LCD */
  496. au1100fb_fb_blank(VESA_POWERDOWN, &fbdev->info);
  497. if (fbdev->lcdclk)
  498. clk_disable(fbdev->lcdclk);
  499. memcpy(&fbregs, fbdev->regs, sizeof(struct au1100fb_regs));
  500. return 0;
  501. }
  502. int au1100fb_drv_resume(struct platform_device *dev)
  503. {
  504. struct au1100fb_device *fbdev = platform_get_drvdata(dev);
  505. if (!fbdev)
  506. return 0;
  507. memcpy(fbdev->regs, &fbregs, sizeof(struct au1100fb_regs));
  508. if (fbdev->lcdclk)
  509. clk_enable(fbdev->lcdclk);
  510. /* Unblank the LCD */
  511. au1100fb_fb_blank(VESA_NO_BLANKING, &fbdev->info);
  512. return 0;
  513. }
  514. #else
  515. #define au1100fb_drv_suspend NULL
  516. #define au1100fb_drv_resume NULL
  517. #endif
  518. static struct platform_driver au1100fb_driver = {
  519. .driver = {
  520. .name = "au1100-lcd",
  521. },
  522. .probe = au1100fb_drv_probe,
  523. .remove = au1100fb_drv_remove,
  524. .suspend = au1100fb_drv_suspend,
  525. .resume = au1100fb_drv_resume,
  526. };
  527. module_platform_driver(au1100fb_driver);
  528. MODULE_DESCRIPTION(DRIVER_DESC);
  529. MODULE_LICENSE("GPL");