au1100fb.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  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;
  186. u32 *palette;
  187. u32 value;
  188. fbdev = to_au1100fb_device(fbi);
  189. palette = fbdev->regs->lcd_pallettebase;
  190. if (regno > (AU1100_LCD_NBR_PALETTE_ENTRIES - 1))
  191. return -EINVAL;
  192. if (fbi->var.grayscale) {
  193. /* Convert color to grayscale */
  194. red = green = blue =
  195. (19595 * red + 38470 * green + 7471 * blue) >> 16;
  196. }
  197. if (fbi->fix.visual == FB_VISUAL_TRUECOLOR) {
  198. /* Place color in the pseudopalette */
  199. if (regno > 16)
  200. return -EINVAL;
  201. palette = (u32*)fbi->pseudo_palette;
  202. red >>= (16 - fbi->var.red.length);
  203. green >>= (16 - fbi->var.green.length);
  204. blue >>= (16 - fbi->var.blue.length);
  205. value = (red << fbi->var.red.offset) |
  206. (green << fbi->var.green.offset)|
  207. (blue << fbi->var.blue.offset);
  208. value &= 0xFFFF;
  209. } else if (panel_is_active(fbdev->panel)) {
  210. /* COLOR TFT PALLETTIZED (use RGB 565) */
  211. value = (red & 0xF800)|((green >> 5) & 0x07E0)|((blue >> 11) & 0x001F);
  212. value &= 0xFFFF;
  213. } else if (panel_is_color(fbdev->panel)) {
  214. /* COLOR STN MODE */
  215. value = (((panel_swap_rgb(fbdev->panel) ? blue : red) >> 12) & 0x000F) |
  216. ((green >> 8) & 0x00F0) |
  217. (((panel_swap_rgb(fbdev->panel) ? red : blue) >> 4) & 0x0F00);
  218. value &= 0xFFF;
  219. } else {
  220. /* MONOCHROME MODE */
  221. value = (green >> 12) & 0x000F;
  222. value &= 0xF;
  223. }
  224. palette[regno] = value;
  225. return 0;
  226. }
  227. /* fb_blank
  228. * Blank the screen. Depending on the mode, the screen will be
  229. * activated with the backlight color, or desactivated
  230. */
  231. int au1100fb_fb_blank(int blank_mode, struct fb_info *fbi)
  232. {
  233. struct au1100fb_device *fbdev = to_au1100fb_device(fbi);
  234. print_dbg("fb_blank %d %p", blank_mode, fbi);
  235. switch (blank_mode) {
  236. case VESA_NO_BLANKING:
  237. /* Turn on panel */
  238. fbdev->regs->lcd_control |= LCD_CONTROL_GO;
  239. #ifdef CONFIG_MIPS_PB1100
  240. if (drv_info.panel_idx == 1) {
  241. au_writew(au_readw(PB1100_G_CONTROL)
  242. | (PB1100_G_CONTROL_BL | PB1100_G_CONTROL_VDD),
  243. PB1100_G_CONTROL);
  244. }
  245. #endif
  246. au_sync();
  247. break;
  248. case VESA_VSYNC_SUSPEND:
  249. case VESA_HSYNC_SUSPEND:
  250. case VESA_POWERDOWN:
  251. /* Turn off panel */
  252. fbdev->regs->lcd_control &= ~LCD_CONTROL_GO;
  253. #ifdef CONFIG_MIPS_PB1100
  254. if (drv_info.panel_idx == 1) {
  255. au_writew(au_readw(PB1100_G_CONTROL)
  256. & ~(PB1100_G_CONTROL_BL | PB1100_G_CONTROL_VDD),
  257. PB1100_G_CONTROL);
  258. }
  259. #endif
  260. au_sync();
  261. break;
  262. default:
  263. break;
  264. }
  265. return 0;
  266. }
  267. /* fb_pan_display
  268. * Pan display in x and/or y as specified
  269. */
  270. int au1100fb_fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *fbi)
  271. {
  272. struct au1100fb_device *fbdev;
  273. int dy;
  274. fbdev = to_au1100fb_device(fbi);
  275. print_dbg("fb_pan_display %p %p", var, fbi);
  276. if (!var || !fbdev) {
  277. return -EINVAL;
  278. }
  279. if (var->xoffset - fbi->var.xoffset) {
  280. /* No support for X panning for now! */
  281. return -EINVAL;
  282. }
  283. print_dbg("fb_pan_display 2 %p %p", var, fbi);
  284. dy = var->yoffset - fbi->var.yoffset;
  285. if (dy) {
  286. u32 dmaaddr;
  287. print_dbg("Panning screen of %d lines", dy);
  288. dmaaddr = fbdev->regs->lcd_dmaaddr0;
  289. dmaaddr += (fbi->fix.line_length * dy);
  290. /* TODO: Wait for current frame to finished */
  291. fbdev->regs->lcd_dmaaddr0 = LCD_DMA_SA_N(dmaaddr);
  292. if (panel_is_dual(fbdev->panel)) {
  293. dmaaddr = fbdev->regs->lcd_dmaaddr1;
  294. dmaaddr += (fbi->fix.line_length * dy);
  295. fbdev->regs->lcd_dmaaddr0 = LCD_DMA_SA_N(dmaaddr);
  296. }
  297. }
  298. print_dbg("fb_pan_display 3 %p %p", var, fbi);
  299. return 0;
  300. }
  301. /* fb_rotate
  302. * Rotate the display of this angle. This doesn't seems to be used by the core,
  303. * but as our hardware supports it, so why not implementing it...
  304. */
  305. void au1100fb_fb_rotate(struct fb_info *fbi, int angle)
  306. {
  307. struct au1100fb_device *fbdev = to_au1100fb_device(fbi);
  308. print_dbg("fb_rotate %p %d", fbi, angle);
  309. if (fbdev && (angle > 0) && !(angle % 90)) {
  310. fbdev->regs->lcd_control &= ~LCD_CONTROL_GO;
  311. fbdev->regs->lcd_control &= ~(LCD_CONTROL_SM_MASK);
  312. fbdev->regs->lcd_control |= ((angle/90) << LCD_CONTROL_SM_BIT);
  313. fbdev->regs->lcd_control |= LCD_CONTROL_GO;
  314. }
  315. }
  316. /* fb_mmap
  317. * Map video memory in user space. We don't use the generic fb_mmap method mainly
  318. * to allow the use of the TLB streaming flag (CCA=6)
  319. */
  320. int au1100fb_fb_mmap(struct fb_info *fbi, struct vm_area_struct *vma)
  321. {
  322. struct au1100fb_device *fbdev;
  323. unsigned int len;
  324. unsigned long start=0, off;
  325. fbdev = to_au1100fb_device(fbi);
  326. if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT)) {
  327. return -EINVAL;
  328. }
  329. start = fbdev->fb_phys & PAGE_MASK;
  330. len = PAGE_ALIGN((start & ~PAGE_MASK) + fbdev->fb_len);
  331. off = vma->vm_pgoff << PAGE_SHIFT;
  332. if ((vma->vm_end - vma->vm_start + off) > len) {
  333. return -EINVAL;
  334. }
  335. off += start;
  336. vma->vm_pgoff = off >> PAGE_SHIFT;
  337. vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
  338. pgprot_val(vma->vm_page_prot) |= (6 << 9); //CCA=6
  339. vma->vm_flags |= VM_IO;
  340. if (io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT,
  341. vma->vm_end - vma->vm_start,
  342. vma->vm_page_prot)) {
  343. return -EAGAIN;
  344. }
  345. return 0;
  346. }
  347. static struct fb_ops au1100fb_ops =
  348. {
  349. .owner = THIS_MODULE,
  350. .fb_setcolreg = au1100fb_fb_setcolreg,
  351. .fb_blank = au1100fb_fb_blank,
  352. .fb_pan_display = au1100fb_fb_pan_display,
  353. .fb_fillrect = cfb_fillrect,
  354. .fb_copyarea = cfb_copyarea,
  355. .fb_imageblit = cfb_imageblit,
  356. .fb_rotate = au1100fb_fb_rotate,
  357. .fb_mmap = au1100fb_fb_mmap,
  358. };
  359. /*-------------------------------------------------------------------------*/
  360. /* AU1100 LCD controller device driver */
  361. int au1100fb_drv_probe(struct device *dev)
  362. {
  363. struct au1100fb_device *fbdev = NULL;
  364. struct resource *regs_res;
  365. unsigned long page;
  366. u32 sys_clksrc;
  367. if (!dev)
  368. return -EINVAL;
  369. /* Allocate new device private */
  370. if (!(fbdev = kmalloc(sizeof(struct au1100fb_device), GFP_KERNEL))) {
  371. print_err("fail to allocate device private record");
  372. return -ENOMEM;
  373. }
  374. memset((void*)fbdev, 0, sizeof(struct au1100fb_device));
  375. fbdev->panel = &known_lcd_panels[drv_info.panel_idx];
  376. dev_set_drvdata(dev, (void*)fbdev);
  377. /* Allocate region for our registers and map them */
  378. if (!(regs_res = platform_get_resource(to_platform_device(dev),
  379. IORESOURCE_MEM, 0))) {
  380. print_err("fail to retrieve registers resource");
  381. return -EFAULT;
  382. }
  383. au1100fb_fix.mmio_start = regs_res->start;
  384. au1100fb_fix.mmio_len = regs_res->end - regs_res->start + 1;
  385. if (!request_mem_region(au1100fb_fix.mmio_start, 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. /* Allocate the framebuffer to the maximum screen size * nbr of video buffers */
  395. fbdev->fb_len = fbdev->panel->xres * fbdev->panel->yres *
  396. (fbdev->panel->bpp >> 3) * AU1100FB_NBR_VIDEO_BUFFERS;
  397. fbdev->fb_mem = dma_alloc_coherent(dev, PAGE_ALIGN(fbdev->fb_len),
  398. &fbdev->fb_phys, GFP_KERNEL);
  399. if (!fbdev->fb_mem) {
  400. print_err("fail to allocate frambuffer (size: %dK))",
  401. fbdev->fb_len / 1024);
  402. return -ENOMEM;
  403. }
  404. au1100fb_fix.smem_start = fbdev->fb_phys;
  405. au1100fb_fix.smem_len = fbdev->fb_len;
  406. /*
  407. * Set page reserved so that mmap will work. This is necessary
  408. * since we'll be remapping normal memory.
  409. */
  410. for (page = (unsigned long)fbdev->fb_mem;
  411. page < PAGE_ALIGN((unsigned long)fbdev->fb_mem + fbdev->fb_len);
  412. page += PAGE_SIZE) {
  413. #if CONFIG_DMA_NONCOHERENT
  414. SetPageReserved(virt_to_page(CAC_ADDR(page)));
  415. #else
  416. SetPageReserved(virt_to_page(page));
  417. #endif
  418. }
  419. print_dbg("Framebuffer memory map at %p", fbdev->fb_mem);
  420. print_dbg("phys=0x%08x, size=%dK", fbdev->fb_phys, fbdev->fb_len / 1024);
  421. /* Setup LCD clock to AUX (48 MHz) */
  422. sys_clksrc = au_readl(SYS_CLKSRC) & ~(SYS_CS_ML_MASK | SYS_CS_DL | SYS_CS_CL);
  423. au_writel((sys_clksrc | (1 << SYS_CS_ML_BIT)), SYS_CLKSRC);
  424. /* load the panel info into the var struct */
  425. au1100fb_var.bits_per_pixel = fbdev->panel->bpp;
  426. au1100fb_var.xres = fbdev->panel->xres;
  427. au1100fb_var.xres_virtual = au1100fb_var.xres;
  428. au1100fb_var.yres = fbdev->panel->yres;
  429. au1100fb_var.yres_virtual = au1100fb_var.yres;
  430. fbdev->info.screen_base = fbdev->fb_mem;
  431. fbdev->info.fbops = &au1100fb_ops;
  432. fbdev->info.fix = au1100fb_fix;
  433. if (!(fbdev->info.pseudo_palette = kmalloc(sizeof(u32) * 16, GFP_KERNEL))) {
  434. return -ENOMEM;
  435. }
  436. memset(fbdev->info.pseudo_palette, 0, sizeof(u32) * 16);
  437. if (fb_alloc_cmap(&fbdev->info.cmap, AU1100_LCD_NBR_PALETTE_ENTRIES, 0) < 0) {
  438. print_err("Fail to allocate colormap (%d entries)",
  439. AU1100_LCD_NBR_PALETTE_ENTRIES);
  440. kfree(fbdev->info.pseudo_palette);
  441. return -EFAULT;
  442. }
  443. fbdev->info.var = au1100fb_var;
  444. /* Set h/w registers */
  445. au1100fb_setmode(fbdev);
  446. /* Register new framebuffer */
  447. if (register_framebuffer(&fbdev->info) < 0) {
  448. print_err("cannot register new framebuffer");
  449. goto failed;
  450. }
  451. return 0;
  452. failed:
  453. if (fbdev->regs) {
  454. release_mem_region(fbdev->regs_phys, fbdev->regs_len);
  455. }
  456. if (fbdev->fb_mem) {
  457. dma_free_noncoherent(dev, fbdev->fb_len, fbdev->fb_mem, fbdev->fb_phys);
  458. }
  459. if (fbdev->info.cmap.len != 0) {
  460. fb_dealloc_cmap(&fbdev->info.cmap);
  461. }
  462. kfree(fbdev);
  463. dev_set_drvdata(dev, NULL);
  464. return 0;
  465. }
  466. int au1100fb_drv_remove(struct device *dev)
  467. {
  468. struct au1100fb_device *fbdev = NULL;
  469. if (!dev)
  470. return -ENODEV;
  471. fbdev = (struct au1100fb_device*) dev_get_drvdata(dev);
  472. #if !defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_LOGO)
  473. au1100fb_fb_blank(VESA_POWERDOWN, &fbdev->info);
  474. #endif
  475. fbdev->regs->lcd_control &= ~LCD_CONTROL_GO;
  476. /* Clean up all probe data */
  477. unregister_framebuffer(&fbdev->info);
  478. release_mem_region(fbdev->regs_phys, fbdev->regs_len);
  479. dma_free_coherent(dev, PAGE_ALIGN(fbdev->fb_len), fbdev->fb_mem, fbdev->fb_phys);
  480. fb_dealloc_cmap(&fbdev->info.cmap);
  481. kfree(fbdev->info.pseudo_palette);
  482. kfree((void*)fbdev);
  483. return 0;
  484. }
  485. int au1100fb_drv_suspend(struct device *dev, pm_message_t state)
  486. {
  487. /* TODO */
  488. return 0;
  489. }
  490. int au1100fb_drv_resume(struct device *dev)
  491. {
  492. /* TODO */
  493. return 0;
  494. }
  495. static struct device_driver au1100fb_driver = {
  496. .name = "au1100-lcd",
  497. .bus = &platform_bus_type,
  498. .probe = au1100fb_drv_probe,
  499. .remove = au1100fb_drv_remove,
  500. .suspend = au1100fb_drv_suspend,
  501. .resume = au1100fb_drv_resume,
  502. };
  503. /*-------------------------------------------------------------------------*/
  504. /* Kernel driver */
  505. int au1100fb_setup(char *options)
  506. {
  507. char* this_opt;
  508. int num_panels = ARRAY_SIZE(known_lcd_panels);
  509. char* mode = NULL;
  510. int panel_idx = 0;
  511. if (num_panels <= 0) {
  512. print_err("No LCD panels supported by driver!");
  513. return -EFAULT;
  514. }
  515. if (options) {
  516. while ((this_opt = strsep(&options,",")) != NULL) {
  517. /* Panel option */
  518. if (!strncmp(this_opt, "panel:", 6)) {
  519. int i;
  520. this_opt += 6;
  521. for (i = 0; i < num_panels; i++) {
  522. if (!strncmp(this_opt,
  523. known_lcd_panels[i].name,
  524. strlen(this_opt))) {
  525. panel_idx = i;
  526. break;
  527. }
  528. }
  529. if (i >= num_panels) {
  530. print_warn("Panel %s not supported!", this_opt);
  531. }
  532. }
  533. /* Mode option (only option that start with digit) */
  534. else if (isdigit(this_opt[0])) {
  535. mode = kmalloc(strlen(this_opt) + 1, GFP_KERNEL);
  536. strncpy(mode, this_opt, strlen(this_opt) + 1);
  537. }
  538. /* Unsupported option */
  539. else {
  540. print_warn("Unsupported option \"%s\"", this_opt);
  541. }
  542. }
  543. }
  544. drv_info.panel_idx = panel_idx;
  545. drv_info.opt_mode = mode;
  546. print_info("Panel=%s Mode=%s",
  547. known_lcd_panels[drv_info.panel_idx].name,
  548. drv_info.opt_mode ? drv_info.opt_mode : "default");
  549. return 0;
  550. }
  551. int __init au1100fb_init(void)
  552. {
  553. char* options;
  554. int ret;
  555. print_info("" DRIVER_DESC "");
  556. memset(&drv_info, 0, sizeof(drv_info));
  557. if (fb_get_options(DRIVER_NAME, &options))
  558. return -ENODEV;
  559. /* Setup driver with options */
  560. ret = au1100fb_setup(options);
  561. if (ret < 0) {
  562. print_err("Fail to setup driver");
  563. return ret;
  564. }
  565. return driver_register(&au1100fb_driver);
  566. }
  567. void __exit au1100fb_cleanup(void)
  568. {
  569. driver_unregister(&au1100fb_driver);
  570. if (drv_info.opt_mode)
  571. kfree(drv_info.opt_mode);
  572. }
  573. module_init(au1100fb_init);
  574. module_exit(au1100fb_cleanup);
  575. MODULE_DESCRIPTION(DRIVER_DESC);
  576. MODULE_LICENSE("GPL");