au1100fb.c 19 KB

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