au1100fb.c 19 KB

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