au1100fb.c 20 KB

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