au1100fb.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  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/module.h>
  45. #include <linux/kernel.h>
  46. #include <linux/errno.h>
  47. #include <linux/string.h>
  48. #include <linux/mm.h>
  49. #include <linux/fb.h>
  50. #include <linux/init.h>
  51. #include <linux/interrupt.h>
  52. #include <linux/ctype.h>
  53. #include <linux/dma-mapping.h>
  54. #include <linux/platform_device.h>
  55. #include <linux/slab.h>
  56. #include <asm/mach-au1x00/au1000.h>
  57. #define DEBUG 0
  58. #include "au1100fb.h"
  59. #define DRIVER_NAME "au1100fb"
  60. #define DRIVER_DESC "LCD controller driver for AU1100 processors"
  61. #define to_au1100fb_device(_info) \
  62. (_info ? container_of(_info, struct au1100fb_device, info) : NULL);
  63. /* Bitfields format supported by the controller. Note that the order of formats
  64. * SHOULD be the same as in the LCD_CONTROL_SBPPF field, so we can retrieve the
  65. * right pixel format by doing rgb_bitfields[LCD_CONTROL_SBPPF_XXX >> LCD_CONTROL_SBPPF]
  66. */
  67. struct fb_bitfield rgb_bitfields[][4] =
  68. {
  69. /* Red, Green, Blue, Transp */
  70. { { 10, 6, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
  71. { { 11, 5, 0 }, { 5, 6, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
  72. { { 11, 5, 0 }, { 6, 5, 0 }, { 0, 6, 0 }, { 0, 0, 0 } },
  73. { { 10, 5, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 15, 1, 0 } },
  74. { { 11, 5, 0 }, { 6, 5, 0 }, { 1, 5, 0 }, { 0, 1, 0 } },
  75. /* The last is used to describe 12bpp format */
  76. { { 8, 4, 0 }, { 4, 4, 0 }, { 0, 4, 0 }, { 0, 0, 0 } },
  77. };
  78. static struct fb_fix_screeninfo au1100fb_fix __devinitdata = {
  79. .id = "AU1100 FB",
  80. .xpanstep = 1,
  81. .ypanstep = 1,
  82. .type = FB_TYPE_PACKED_PIXELS,
  83. .accel = FB_ACCEL_NONE,
  84. };
  85. static struct fb_var_screeninfo au1100fb_var __devinitdata = {
  86. .activate = FB_ACTIVATE_NOW,
  87. .height = -1,
  88. .width = -1,
  89. .vmode = FB_VMODE_NONINTERLACED,
  90. };
  91. /* fb_blank
  92. * Blank the screen. Depending on the mode, the screen will be
  93. * activated with the backlight color, or desactivated
  94. */
  95. static int au1100fb_fb_blank(int blank_mode, struct fb_info *fbi)
  96. {
  97. struct au1100fb_device *fbdev = to_au1100fb_device(fbi);
  98. print_dbg("fb_blank %d %p", blank_mode, fbi);
  99. switch (blank_mode) {
  100. case VESA_NO_BLANKING:
  101. /* Turn on panel */
  102. fbdev->regs->lcd_control |= LCD_CONTROL_GO;
  103. #ifdef CONFIG_MIPS_PB1100
  104. if (fbdev->panel_idx == 1) {
  105. au_writew(au_readw(PB1100_G_CONTROL)
  106. | (PB1100_G_CONTROL_BL | PB1100_G_CONTROL_VDD),
  107. PB1100_G_CONTROL);
  108. }
  109. #endif
  110. au_sync();
  111. break;
  112. case VESA_VSYNC_SUSPEND:
  113. case VESA_HSYNC_SUSPEND:
  114. case VESA_POWERDOWN:
  115. /* Turn off panel */
  116. fbdev->regs->lcd_control &= ~LCD_CONTROL_GO;
  117. #ifdef CONFIG_MIPS_PB1100
  118. if (fbdev->panel_idx == 1) {
  119. au_writew(au_readw(PB1100_G_CONTROL)
  120. & ~(PB1100_G_CONTROL_BL | PB1100_G_CONTROL_VDD),
  121. PB1100_G_CONTROL);
  122. }
  123. #endif
  124. au_sync();
  125. break;
  126. default:
  127. break;
  128. }
  129. return 0;
  130. }
  131. /*
  132. * Set hardware with var settings. This will enable the controller with a specific
  133. * mode, normally validated with the fb_check_var method
  134. */
  135. int au1100fb_setmode(struct au1100fb_device *fbdev)
  136. {
  137. struct fb_info *info = &fbdev->info;
  138. u32 words;
  139. int index;
  140. if (!fbdev)
  141. return -EINVAL;
  142. /* Update var-dependent FB info */
  143. if (panel_is_active(fbdev->panel) || panel_is_color(fbdev->panel)) {
  144. if (info->var.bits_per_pixel <= 8) {
  145. /* palettized */
  146. info->var.red.offset = 0;
  147. info->var.red.length = info->var.bits_per_pixel;
  148. info->var.red.msb_right = 0;
  149. info->var.green.offset = 0;
  150. info->var.green.length = info->var.bits_per_pixel;
  151. info->var.green.msb_right = 0;
  152. info->var.blue.offset = 0;
  153. info->var.blue.length = info->var.bits_per_pixel;
  154. info->var.blue.msb_right = 0;
  155. info->var.transp.offset = 0;
  156. info->var.transp.length = 0;
  157. info->var.transp.msb_right = 0;
  158. info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
  159. info->fix.line_length = info->var.xres_virtual /
  160. (8/info->var.bits_per_pixel);
  161. } else {
  162. /* non-palettized */
  163. index = (fbdev->panel->control_base & LCD_CONTROL_SBPPF_MASK) >> LCD_CONTROL_SBPPF_BIT;
  164. info->var.red = rgb_bitfields[index][0];
  165. info->var.green = rgb_bitfields[index][1];
  166. info->var.blue = rgb_bitfields[index][2];
  167. info->var.transp = rgb_bitfields[index][3];
  168. info->fix.visual = FB_VISUAL_TRUECOLOR;
  169. info->fix.line_length = info->var.xres_virtual << 1; /* depth=16 */
  170. }
  171. } else {
  172. /* mono */
  173. info->fix.visual = FB_VISUAL_MONO10;
  174. info->fix.line_length = info->var.xres_virtual / 8;
  175. }
  176. info->screen_size = info->fix.line_length * info->var.yres_virtual;
  177. info->var.rotate = ((fbdev->panel->control_base&LCD_CONTROL_SM_MASK) \
  178. >> LCD_CONTROL_SM_BIT) * 90;
  179. /* Determine BPP mode and format */
  180. fbdev->regs->lcd_control = fbdev->panel->control_base;
  181. fbdev->regs->lcd_horztiming = fbdev->panel->horztiming;
  182. fbdev->regs->lcd_verttiming = fbdev->panel->verttiming;
  183. fbdev->regs->lcd_clkcontrol = fbdev->panel->clkcontrol_base;
  184. fbdev->regs->lcd_intenable = 0;
  185. fbdev->regs->lcd_intstatus = 0;
  186. fbdev->regs->lcd_dmaaddr0 = LCD_DMA_SA_N(fbdev->fb_phys);
  187. if (panel_is_dual(fbdev->panel)) {
  188. /* Second panel display seconf half of screen if possible,
  189. * otherwise display the same as the first panel */
  190. if (info->var.yres_virtual >= (info->var.yres << 1)) {
  191. fbdev->regs->lcd_dmaaddr1 = LCD_DMA_SA_N(fbdev->fb_phys +
  192. (info->fix.line_length *
  193. (info->var.yres_virtual >> 1)));
  194. } else {
  195. fbdev->regs->lcd_dmaaddr1 = LCD_DMA_SA_N(fbdev->fb_phys);
  196. }
  197. }
  198. words = info->fix.line_length / sizeof(u32);
  199. if (!info->var.rotate || (info->var.rotate == 180)) {
  200. words *= info->var.yres_virtual;
  201. if (info->var.rotate /* 180 */) {
  202. words -= (words % 8); /* should be divisable by 8 */
  203. }
  204. }
  205. fbdev->regs->lcd_words = LCD_WRD_WRDS_N(words);
  206. fbdev->regs->lcd_pwmdiv = 0;
  207. fbdev->regs->lcd_pwmhi = 0;
  208. /* Resume controller */
  209. fbdev->regs->lcd_control |= LCD_CONTROL_GO;
  210. mdelay(10);
  211. au1100fb_fb_blank(VESA_NO_BLANKING, info);
  212. return 0;
  213. }
  214. /* fb_setcolreg
  215. * Set color in LCD palette.
  216. */
  217. int au1100fb_fb_setcolreg(unsigned regno, unsigned red, unsigned green, unsigned blue, unsigned transp, struct fb_info *fbi)
  218. {
  219. struct au1100fb_device *fbdev;
  220. u32 *palette;
  221. u32 value;
  222. fbdev = to_au1100fb_device(fbi);
  223. palette = fbdev->regs->lcd_pallettebase;
  224. if (regno > (AU1100_LCD_NBR_PALETTE_ENTRIES - 1))
  225. return -EINVAL;
  226. if (fbi->var.grayscale) {
  227. /* Convert color to grayscale */
  228. red = green = blue =
  229. (19595 * red + 38470 * green + 7471 * blue) >> 16;
  230. }
  231. if (fbi->fix.visual == FB_VISUAL_TRUECOLOR) {
  232. /* Place color in the pseudopalette */
  233. if (regno > 16)
  234. return -EINVAL;
  235. palette = (u32*)fbi->pseudo_palette;
  236. red >>= (16 - fbi->var.red.length);
  237. green >>= (16 - fbi->var.green.length);
  238. blue >>= (16 - fbi->var.blue.length);
  239. value = (red << fbi->var.red.offset) |
  240. (green << fbi->var.green.offset)|
  241. (blue << fbi->var.blue.offset);
  242. value &= 0xFFFF;
  243. } else if (panel_is_active(fbdev->panel)) {
  244. /* COLOR TFT PALLETTIZED (use RGB 565) */
  245. value = (red & 0xF800)|((green >> 5) & 0x07E0)|((blue >> 11) & 0x001F);
  246. value &= 0xFFFF;
  247. } else if (panel_is_color(fbdev->panel)) {
  248. /* COLOR STN MODE */
  249. value = (((panel_swap_rgb(fbdev->panel) ? blue : red) >> 12) & 0x000F) |
  250. ((green >> 8) & 0x00F0) |
  251. (((panel_swap_rgb(fbdev->panel) ? red : blue) >> 4) & 0x0F00);
  252. value &= 0xFFF;
  253. } else {
  254. /* MONOCHROME MODE */
  255. value = (green >> 12) & 0x000F;
  256. value &= 0xF;
  257. }
  258. palette[regno] = value;
  259. return 0;
  260. }
  261. /* fb_pan_display
  262. * Pan display in x and/or y as specified
  263. */
  264. int au1100fb_fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *fbi)
  265. {
  266. struct au1100fb_device *fbdev;
  267. int dy;
  268. fbdev = to_au1100fb_device(fbi);
  269. print_dbg("fb_pan_display %p %p", var, fbi);
  270. if (!var || !fbdev) {
  271. return -EINVAL;
  272. }
  273. if (var->xoffset - fbi->var.xoffset) {
  274. /* No support for X panning for now! */
  275. return -EINVAL;
  276. }
  277. print_dbg("fb_pan_display 2 %p %p", var, fbi);
  278. dy = var->yoffset - fbi->var.yoffset;
  279. if (dy) {
  280. u32 dmaaddr;
  281. print_dbg("Panning screen of %d lines", dy);
  282. dmaaddr = fbdev->regs->lcd_dmaaddr0;
  283. dmaaddr += (fbi->fix.line_length * dy);
  284. /* TODO: Wait for current frame to finished */
  285. fbdev->regs->lcd_dmaaddr0 = LCD_DMA_SA_N(dmaaddr);
  286. if (panel_is_dual(fbdev->panel)) {
  287. dmaaddr = fbdev->regs->lcd_dmaaddr1;
  288. dmaaddr += (fbi->fix.line_length * dy);
  289. fbdev->regs->lcd_dmaaddr0 = LCD_DMA_SA_N(dmaaddr);
  290. }
  291. }
  292. print_dbg("fb_pan_display 3 %p %p", var, fbi);
  293. return 0;
  294. }
  295. /* fb_rotate
  296. * Rotate the display of this angle. This doesn't seems to be used by the core,
  297. * but as our hardware supports it, so why not implementing it...
  298. */
  299. void au1100fb_fb_rotate(struct fb_info *fbi, int angle)
  300. {
  301. struct au1100fb_device *fbdev = to_au1100fb_device(fbi);
  302. print_dbg("fb_rotate %p %d", fbi, angle);
  303. if (fbdev && (angle > 0) && !(angle % 90)) {
  304. fbdev->regs->lcd_control &= ~LCD_CONTROL_GO;
  305. fbdev->regs->lcd_control &= ~(LCD_CONTROL_SM_MASK);
  306. fbdev->regs->lcd_control |= ((angle/90) << LCD_CONTROL_SM_BIT);
  307. fbdev->regs->lcd_control |= LCD_CONTROL_GO;
  308. }
  309. }
  310. /* fb_mmap
  311. * Map video memory in user space. We don't use the generic fb_mmap method mainly
  312. * to allow the use of the TLB streaming flag (CCA=6)
  313. */
  314. int au1100fb_fb_mmap(struct fb_info *fbi, struct vm_area_struct *vma)
  315. {
  316. struct au1100fb_device *fbdev;
  317. fbdev = to_au1100fb_device(fbi);
  318. vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
  319. pgprot_val(vma->vm_page_prot) |= (6 << 9); //CCA=6
  320. return vm_iomap_memory(vma, fbdev->fb_phys, fbdev->fb_len);
  321. }
  322. static struct fb_ops au1100fb_ops =
  323. {
  324. .owner = THIS_MODULE,
  325. .fb_setcolreg = au1100fb_fb_setcolreg,
  326. .fb_blank = au1100fb_fb_blank,
  327. .fb_pan_display = au1100fb_fb_pan_display,
  328. .fb_fillrect = cfb_fillrect,
  329. .fb_copyarea = cfb_copyarea,
  330. .fb_imageblit = cfb_imageblit,
  331. .fb_rotate = au1100fb_fb_rotate,
  332. .fb_mmap = au1100fb_fb_mmap,
  333. };
  334. /*-------------------------------------------------------------------------*/
  335. static int au1100fb_setup(struct au1100fb_device *fbdev)
  336. {
  337. char *this_opt, *options;
  338. int num_panels = ARRAY_SIZE(known_lcd_panels);
  339. if (num_panels <= 0) {
  340. print_err("No LCD panels supported by driver!");
  341. return -ENODEV;
  342. }
  343. if (fb_get_options(DRIVER_NAME, &options))
  344. return -ENODEV;
  345. if (!options)
  346. return -ENODEV;
  347. while ((this_opt = strsep(&options, ",")) != NULL) {
  348. /* Panel option */
  349. if (!strncmp(this_opt, "panel:", 6)) {
  350. int i;
  351. this_opt += 6;
  352. for (i = 0; i < num_panels; i++) {
  353. if (!strncmp(this_opt, known_lcd_panels[i].name,
  354. strlen(this_opt))) {
  355. fbdev->panel = &known_lcd_panels[i];
  356. fbdev->panel_idx = i;
  357. break;
  358. }
  359. }
  360. if (i >= num_panels) {
  361. print_warn("Panel '%s' not supported!", this_opt);
  362. return -ENODEV;
  363. }
  364. }
  365. /* Unsupported option */
  366. else
  367. print_warn("Unsupported option \"%s\"", this_opt);
  368. }
  369. print_info("Panel=%s", fbdev->panel->name);
  370. return 0;
  371. }
  372. static int __devinit au1100fb_drv_probe(struct platform_device *dev)
  373. {
  374. struct au1100fb_device *fbdev = NULL;
  375. struct resource *regs_res;
  376. unsigned long page;
  377. u32 sys_clksrc;
  378. /* Allocate new device private */
  379. fbdev = devm_kzalloc(&dev->dev, sizeof(struct au1100fb_device),
  380. GFP_KERNEL);
  381. if (!fbdev) {
  382. print_err("fail to allocate device private record");
  383. return -ENOMEM;
  384. }
  385. if (au1100fb_setup(fbdev))
  386. goto failed;
  387. platform_set_drvdata(dev, (void *)fbdev);
  388. /* Allocate region for our registers and map them */
  389. regs_res = platform_get_resource(dev, IORESOURCE_MEM, 0);
  390. if (!regs_res) {
  391. print_err("fail to retrieve registers resource");
  392. return -EFAULT;
  393. }
  394. au1100fb_fix.mmio_start = regs_res->start;
  395. au1100fb_fix.mmio_len = resource_size(regs_res);
  396. if (!devm_request_mem_region(&dev->dev,
  397. au1100fb_fix.mmio_start,
  398. au1100fb_fix.mmio_len,
  399. DRIVER_NAME)) {
  400. print_err("fail to lock memory region at 0x%08lx",
  401. au1100fb_fix.mmio_start);
  402. return -EBUSY;
  403. }
  404. fbdev->regs = (struct au1100fb_regs*)KSEG1ADDR(au1100fb_fix.mmio_start);
  405. print_dbg("Register memory map at %p", fbdev->regs);
  406. print_dbg("phys=0x%08x, size=%d", fbdev->regs_phys, fbdev->regs_len);
  407. /* Allocate the framebuffer to the maximum screen size * nbr of video buffers */
  408. fbdev->fb_len = fbdev->panel->xres * fbdev->panel->yres *
  409. (fbdev->panel->bpp >> 3) * AU1100FB_NBR_VIDEO_BUFFERS;
  410. fbdev->fb_mem = dmam_alloc_coherent(&dev->dev,
  411. PAGE_ALIGN(fbdev->fb_len),
  412. &fbdev->fb_phys, GFP_KERNEL);
  413. if (!fbdev->fb_mem) {
  414. print_err("fail to allocate frambuffer (size: %dK))",
  415. fbdev->fb_len / 1024);
  416. return -ENOMEM;
  417. }
  418. au1100fb_fix.smem_start = fbdev->fb_phys;
  419. au1100fb_fix.smem_len = fbdev->fb_len;
  420. /*
  421. * Set page reserved so that mmap will work. This is necessary
  422. * since we'll be remapping normal memory.
  423. */
  424. for (page = (unsigned long)fbdev->fb_mem;
  425. page < PAGE_ALIGN((unsigned long)fbdev->fb_mem + fbdev->fb_len);
  426. page += PAGE_SIZE) {
  427. #if CONFIG_DMA_NONCOHERENT
  428. SetPageReserved(virt_to_page(CAC_ADDR((void *)page)));
  429. #else
  430. SetPageReserved(virt_to_page(page));
  431. #endif
  432. }
  433. print_dbg("Framebuffer memory map at %p", fbdev->fb_mem);
  434. print_dbg("phys=0x%08x, size=%dK", fbdev->fb_phys, fbdev->fb_len / 1024);
  435. /* Setup LCD clock to AUX (48 MHz) */
  436. sys_clksrc = au_readl(SYS_CLKSRC) & ~(SYS_CS_ML_MASK | SYS_CS_DL | SYS_CS_CL);
  437. au_writel((sys_clksrc | (1 << SYS_CS_ML_BIT)), SYS_CLKSRC);
  438. /* load the panel info into the var struct */
  439. au1100fb_var.bits_per_pixel = fbdev->panel->bpp;
  440. au1100fb_var.xres = fbdev->panel->xres;
  441. au1100fb_var.xres_virtual = au1100fb_var.xres;
  442. au1100fb_var.yres = fbdev->panel->yres;
  443. au1100fb_var.yres_virtual = au1100fb_var.yres;
  444. fbdev->info.screen_base = fbdev->fb_mem;
  445. fbdev->info.fbops = &au1100fb_ops;
  446. fbdev->info.fix = au1100fb_fix;
  447. fbdev->info.pseudo_palette =
  448. devm_kzalloc(&dev->dev, sizeof(u32) * 16, GFP_KERNEL);
  449. if (!fbdev->info.pseudo_palette)
  450. return -ENOMEM;
  451. if (fb_alloc_cmap(&fbdev->info.cmap, AU1100_LCD_NBR_PALETTE_ENTRIES, 0) < 0) {
  452. print_err("Fail to allocate colormap (%d entries)",
  453. AU1100_LCD_NBR_PALETTE_ENTRIES);
  454. return -EFAULT;
  455. }
  456. fbdev->info.var = au1100fb_var;
  457. /* Set h/w registers */
  458. au1100fb_setmode(fbdev);
  459. /* Register new framebuffer */
  460. if (register_framebuffer(&fbdev->info) < 0) {
  461. print_err("cannot register new framebuffer");
  462. goto failed;
  463. }
  464. return 0;
  465. failed:
  466. if (fbdev->fb_mem) {
  467. dma_free_noncoherent(&dev->dev, fbdev->fb_len, fbdev->fb_mem,
  468. fbdev->fb_phys);
  469. }
  470. if (fbdev->info.cmap.len != 0) {
  471. fb_dealloc_cmap(&fbdev->info.cmap);
  472. }
  473. platform_set_drvdata(dev, NULL);
  474. return -ENODEV;
  475. }
  476. int au1100fb_drv_remove(struct platform_device *dev)
  477. {
  478. struct au1100fb_device *fbdev = NULL;
  479. if (!dev)
  480. return -ENODEV;
  481. fbdev = (struct au1100fb_device *) platform_get_drvdata(dev);
  482. #if !defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_LOGO)
  483. au1100fb_fb_blank(VESA_POWERDOWN, &fbdev->info);
  484. #endif
  485. fbdev->regs->lcd_control &= ~LCD_CONTROL_GO;
  486. /* Clean up all probe data */
  487. unregister_framebuffer(&fbdev->info);
  488. fb_dealloc_cmap(&fbdev->info.cmap);
  489. return 0;
  490. }
  491. #ifdef CONFIG_PM
  492. static u32 sys_clksrc;
  493. static struct au1100fb_regs fbregs;
  494. int au1100fb_drv_suspend(struct platform_device *dev, pm_message_t state)
  495. {
  496. struct au1100fb_device *fbdev = platform_get_drvdata(dev);
  497. if (!fbdev)
  498. return 0;
  499. /* Save the clock source state */
  500. sys_clksrc = au_readl(SYS_CLKSRC);
  501. /* Blank the LCD */
  502. au1100fb_fb_blank(VESA_POWERDOWN, &fbdev->info);
  503. /* Stop LCD clocking */
  504. au_writel(sys_clksrc & ~SYS_CS_ML_MASK, SYS_CLKSRC);
  505. memcpy(&fbregs, fbdev->regs, sizeof(struct au1100fb_regs));
  506. return 0;
  507. }
  508. int au1100fb_drv_resume(struct platform_device *dev)
  509. {
  510. struct au1100fb_device *fbdev = platform_get_drvdata(dev);
  511. if (!fbdev)
  512. return 0;
  513. memcpy(fbdev->regs, &fbregs, sizeof(struct au1100fb_regs));
  514. /* Restart LCD clocking */
  515. au_writel(sys_clksrc, SYS_CLKSRC);
  516. /* Unblank the LCD */
  517. au1100fb_fb_blank(VESA_NO_BLANKING, &fbdev->info);
  518. return 0;
  519. }
  520. #else
  521. #define au1100fb_drv_suspend NULL
  522. #define au1100fb_drv_resume NULL
  523. #endif
  524. static struct platform_driver au1100fb_driver = {
  525. .driver = {
  526. .name = "au1100-lcd",
  527. .owner = THIS_MODULE,
  528. },
  529. .probe = au1100fb_drv_probe,
  530. .remove = au1100fb_drv_remove,
  531. .suspend = au1100fb_drv_suspend,
  532. .resume = au1100fb_drv_resume,
  533. };
  534. static int __init au1100fb_load(void)
  535. {
  536. return platform_driver_register(&au1100fb_driver);
  537. }
  538. static void __exit au1100fb_unload(void)
  539. {
  540. platform_driver_unregister(&au1100fb_driver);
  541. }
  542. module_init(au1100fb_load);
  543. module_exit(au1100fb_unload);
  544. MODULE_DESCRIPTION(DRIVER_DESC);
  545. MODULE_LICENSE("GPL");