1 /* 2 * BRIEF MODULE DESCRIPTION 3 * Au1200 LCD Driver. 4 * 5 * Copyright 2004-2005 AMD 6 * Author: AMD 7 * 8 * Based on: 9 * linux/drivers/video/skeletonfb.c -- Skeleton for a frame buffer device 10 * Created 28 Dec 1997 by Geert Uytterhoeven 11 * 12 * This program is free software; you can redistribute it and/or modify it 13 * under the terms of the GNU General Public License as published by the 14 * Free Software Foundation; either version 2 of the License, or (at your 15 * option) any later version. 16 * 17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 20 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 23 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 * You should have received a copy of the GNU General Public License along 29 * with this program; if not, write to the Free Software Foundation, Inc., 30 * 675 Mass Ave, Cambridge, MA 02139, USA. 31 */ 32 33 #include <linux/clk.h> 34 #include <linux/module.h> 35 #include <linux/platform_device.h> 36 #include <linux/kernel.h> 37 #include <linux/errno.h> 38 #include <linux/string.h> 39 #include <linux/mm.h> 40 #include <linux/fb.h> 41 #include <linux/init.h> 42 #include <linux/interrupt.h> 43 #include <linux/ctype.h> 44 #include <linux/dma-mapping.h> 45 #include <linux/slab.h> 46 47 #include <asm/mach-au1x00/au1000.h> 48 #include <asm/mach-au1x00/au1200fb.h> /* platform_data */ 49 #include "au1200fb.h" 50 51 #define DRIVER_NAME "au1200fb" 52 #define DRIVER_DESC "LCD controller driver for AU1200 processors" 53 54 #define DEBUG 0 55 56 #define print_err(f, arg...) printk(KERN_ERR DRIVER_NAME ": " f "\n", ## arg) 57 #define print_warn(f, arg...) printk(KERN_WARNING DRIVER_NAME ": " f "\n", ## arg) 58 #define print_info(f, arg...) printk(KERN_INFO DRIVER_NAME ": " f "\n", ## arg) 59 60 #if DEBUG 61 #define print_dbg(f, arg...) printk(KERN_DEBUG __FILE__ ": " f "\n", ## arg) 62 #else 63 #define print_dbg(f, arg...) do {} while (0) 64 #endif 65 66 67 #define AU1200_LCD_FB_IOCTL 0x46FF 68 69 #define AU1200_LCD_SET_SCREEN 1 70 #define AU1200_LCD_GET_SCREEN 2 71 #define AU1200_LCD_SET_WINDOW 3 72 #define AU1200_LCD_GET_WINDOW 4 73 #define AU1200_LCD_SET_PANEL 5 74 #define AU1200_LCD_GET_PANEL 6 75 76 #define SCREEN_SIZE (1<< 1) 77 #define SCREEN_BACKCOLOR (1<< 2) 78 #define SCREEN_BRIGHTNESS (1<< 3) 79 #define SCREEN_COLORKEY (1<< 4) 80 #define SCREEN_MASK (1<< 5) 81 82 struct au1200_lcd_global_regs_t { 83 unsigned int flags; 84 unsigned int xsize; 85 unsigned int ysize; 86 unsigned int backcolor; 87 unsigned int brightness; 88 unsigned int colorkey; 89 unsigned int mask; 90 unsigned int panel_choice; 91 char panel_desc[80]; 92 93 }; 94 95 #define WIN_POSITION (1<< 0) 96 #define WIN_ALPHA_COLOR (1<< 1) 97 #define WIN_ALPHA_MODE (1<< 2) 98 #define WIN_PRIORITY (1<< 3) 99 #define WIN_CHANNEL (1<< 4) 100 #define WIN_BUFFER_FORMAT (1<< 5) 101 #define WIN_COLOR_ORDER (1<< 6) 102 #define WIN_PIXEL_ORDER (1<< 7) 103 #define WIN_SIZE (1<< 8) 104 #define WIN_COLORKEY_MODE (1<< 9) 105 #define WIN_DOUBLE_BUFFER_MODE (1<< 10) 106 #define WIN_RAM_ARRAY_MODE (1<< 11) 107 #define WIN_BUFFER_SCALE (1<< 12) 108 #define WIN_ENABLE (1<< 13) 109 110 struct au1200_lcd_window_regs_t { 111 unsigned int flags; 112 unsigned int xpos; 113 unsigned int ypos; 114 unsigned int alpha_color; 115 unsigned int alpha_mode; 116 unsigned int priority; 117 unsigned int channel; 118 unsigned int buffer_format; 119 unsigned int color_order; 120 unsigned int pixel_order; 121 unsigned int xsize; 122 unsigned int ysize; 123 unsigned int colorkey_mode; 124 unsigned int double_buffer_mode; 125 unsigned int ram_array_mode; 126 unsigned int xscale; 127 unsigned int yscale; 128 unsigned int enable; 129 }; 130 131 132 struct au1200_lcd_iodata_t { 133 unsigned int subcmd; 134 struct au1200_lcd_global_regs_t global; 135 struct au1200_lcd_window_regs_t window; 136 }; 137 138 #if defined(__BIG_ENDIAN) 139 #define LCD_CONTROL_DEFAULT_PO LCD_CONTROL_PO_11 140 #else 141 #define LCD_CONTROL_DEFAULT_PO LCD_CONTROL_PO_00 142 #endif 143 #define LCD_CONTROL_DEFAULT_SBPPF LCD_CONTROL_SBPPF_565 144 145 /* Private, per-framebuffer management information (independent of the panel itself) */ 146 struct au1200fb_device { 147 struct fb_info *fb_info; /* FB driver info record */ 148 struct au1200fb_platdata *pd; 149 150 int plane; 151 unsigned char* fb_mem; /* FrameBuffer memory map */ 152 unsigned int fb_len; 153 dma_addr_t fb_phys; 154 }; 155 156 /********************************************************************/ 157 158 /* LCD controller restrictions */ 159 #define AU1200_LCD_MAX_XRES 1280 160 #define AU1200_LCD_MAX_YRES 1024 161 #define AU1200_LCD_MAX_BPP 32 162 #define AU1200_LCD_MAX_CLK 96000000 /* fixme: this needs to go away ? */ 163 #define AU1200_LCD_NBR_PALETTE_ENTRIES 256 164 165 /* Default number of visible screen buffer to allocate */ 166 #define AU1200FB_NBR_VIDEO_BUFFERS 1 167 168 /* Default maximum number of fb devices to create */ 169 #define MAX_DEVICE_COUNT 4 170 171 /* Default window configuration entry to use (see windows[]) */ 172 #define DEFAULT_WINDOW_INDEX 2 173 174 /********************************************************************/ 175 176 static struct fb_info *_au1200fb_infos[MAX_DEVICE_COUNT]; 177 static struct au1200_lcd *lcd = (struct au1200_lcd *) AU1200_LCD_ADDR; 178 static int device_count = MAX_DEVICE_COUNT; 179 static int window_index = DEFAULT_WINDOW_INDEX; /* default is zero */ 180 static int panel_index = 2; /* default is zero */ 181 static struct window_settings *win; 182 static struct panel_settings *panel; 183 static int noblanking = 1; 184 static int nohwcursor = 0; 185 186 struct window_settings { 187 unsigned char name[64]; 188 uint32 mode_backcolor; 189 uint32 mode_colorkey; 190 uint32 mode_colorkeymsk; 191 struct { 192 int xres; 193 int yres; 194 int xpos; 195 int ypos; 196 uint32 mode_winctrl1; /* winctrl1[FRM,CCO,PO,PIPE] */ 197 uint32 mode_winenable; 198 } w[4]; 199 }; 200 201 #if defined(__BIG_ENDIAN) 202 #define LCD_WINCTRL1_PO_16BPP LCD_WINCTRL1_PO_00 203 #else 204 #define LCD_WINCTRL1_PO_16BPP LCD_WINCTRL1_PO_01 205 #endif 206 207 /* 208 * Default window configurations 209 */ 210 static struct window_settings windows[] = { 211 { /* Index 0 */ 212 "0-FS gfx, 1-video, 2-ovly gfx, 3-ovly gfx", 213 /* mode_backcolor */ 0x006600ff, 214 /* mode_colorkey,msk*/ 0, 0, 215 { 216 { 217 /* xres, yres, xpos, ypos */ 0, 0, 0, 0, 218 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 | 219 LCD_WINCTRL1_PO_16BPP, 220 /* mode_winenable*/ LCD_WINENABLE_WEN0, 221 }, 222 { 223 /* xres, yres, xpos, ypos */ 100, 100, 100, 100, 224 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 | 225 LCD_WINCTRL1_PO_16BPP | 226 LCD_WINCTRL1_PIPE, 227 /* mode_winenable*/ LCD_WINENABLE_WEN1, 228 }, 229 { 230 /* xres, yres, xpos, ypos */ 0, 0, 0, 0, 231 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 | 232 LCD_WINCTRL1_PO_16BPP, 233 /* mode_winenable*/ 0, 234 }, 235 { 236 /* xres, yres, xpos, ypos */ 0, 0, 0, 0, 237 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 | 238 LCD_WINCTRL1_PO_16BPP | 239 LCD_WINCTRL1_PIPE, 240 /* mode_winenable*/ 0, 241 }, 242 }, 243 }, 244 245 { /* Index 1 */ 246 "0-FS gfx, 1-video, 2-ovly gfx, 3-ovly gfx", 247 /* mode_backcolor */ 0x006600ff, 248 /* mode_colorkey,msk*/ 0, 0, 249 { 250 { 251 /* xres, yres, xpos, ypos */ 320, 240, 5, 5, 252 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_24BPP | 253 LCD_WINCTRL1_PO_00, 254 /* mode_winenable*/ LCD_WINENABLE_WEN0, 255 }, 256 { 257 /* xres, yres, xpos, ypos */ 0, 0, 0, 0, 258 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 259 | LCD_WINCTRL1_PO_16BPP, 260 /* mode_winenable*/ 0, 261 }, 262 { 263 /* xres, yres, xpos, ypos */ 100, 100, 0, 0, 264 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 | 265 LCD_WINCTRL1_PO_16BPP | 266 LCD_WINCTRL1_PIPE, 267 /* mode_winenable*/ 0/*LCD_WINENABLE_WEN2*/, 268 }, 269 { 270 /* xres, yres, xpos, ypos */ 200, 25, 0, 0, 271 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 | 272 LCD_WINCTRL1_PO_16BPP | 273 LCD_WINCTRL1_PIPE, 274 /* mode_winenable*/ 0, 275 }, 276 }, 277 }, 278 { /* Index 2 */ 279 "0-FS gfx, 1-video, 2-ovly gfx, 3-ovly gfx", 280 /* mode_backcolor */ 0x006600ff, 281 /* mode_colorkey,msk*/ 0, 0, 282 { 283 { 284 /* xres, yres, xpos, ypos */ 0, 0, 0, 0, 285 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 | 286 LCD_WINCTRL1_PO_16BPP, 287 /* mode_winenable*/ LCD_WINENABLE_WEN0, 288 }, 289 { 290 /* xres, yres, xpos, ypos */ 0, 0, 0, 0, 291 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 | 292 LCD_WINCTRL1_PO_16BPP, 293 /* mode_winenable*/ 0, 294 }, 295 { 296 /* xres, yres, xpos, ypos */ 0, 0, 0, 0, 297 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_32BPP | 298 LCD_WINCTRL1_PO_00|LCD_WINCTRL1_PIPE, 299 /* mode_winenable*/ 0/*LCD_WINENABLE_WEN2*/, 300 }, 301 { 302 /* xres, yres, xpos, ypos */ 0, 0, 0, 0, 303 /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 | 304 LCD_WINCTRL1_PO_16BPP | 305 LCD_WINCTRL1_PIPE, 306 /* mode_winenable*/ 0, 307 }, 308 }, 309 }, 310 /* Need VGA 640 @ 24bpp, @ 32bpp */ 311 /* Need VGA 800 @ 24bpp, @ 32bpp */ 312 /* Need VGA 1024 @ 24bpp, @ 32bpp */ 313 }; 314 315 /* 316 * Controller configurations for various panels. 317 */ 318 319 struct panel_settings 320 { 321 const char name[25]; /* Full name <vendor>_<model> */ 322 323 struct fb_monspecs monspecs; /* FB monitor specs */ 324 325 /* panel timings */ 326 uint32 mode_screen; 327 uint32 mode_horztiming; 328 uint32 mode_verttiming; 329 uint32 mode_clkcontrol; 330 uint32 mode_pwmdiv; 331 uint32 mode_pwmhi; 332 uint32 mode_outmask; 333 uint32 mode_fifoctrl; 334 uint32 mode_backlight; 335 uint32 lcdclk; 336 #define Xres min_xres 337 #define Yres min_yres 338 u32 min_xres; /* Minimum horizontal resolution */ 339 u32 max_xres; /* Maximum horizontal resolution */ 340 u32 min_yres; /* Minimum vertical resolution */ 341 u32 max_yres; /* Maximum vertical resolution */ 342 }; 343 344 /********************************************************************/ 345 /* fixme: Maybe a modedb for the CRT ? otherwise panels should be as-is */ 346 347 /* List of panels known to work with the AU1200 LCD controller. 348 * To add a new panel, enter the same specifications as the 349 * Generic_TFT one, and MAKE SURE that it doesn't conflicts 350 * with the controller restrictions. Restrictions are: 351 * 352 * STN color panels: max_bpp <= 12 353 * STN mono panels: max_bpp <= 4 354 * TFT panels: max_bpp <= 16 355 * max_xres <= 800 356 * max_yres <= 600 357 */ 358 static struct panel_settings known_lcd_panels[] = 359 { 360 [0] = { /* QVGA 320x240 H:33.3kHz V:110Hz */ 361 .name = "QVGA_320x240", 362 .monspecs = { 363 .modedb = NULL, 364 .modedb_len = 0, 365 .hfmin = 30000, 366 .hfmax = 70000, 367 .vfmin = 60, 368 .vfmax = 60, 369 .dclkmin = 6000000, 370 .dclkmax = 28000000, 371 .input = FB_DISP_RGB, 372 }, 373 .mode_screen = LCD_SCREEN_SX_N(320) | 374 LCD_SCREEN_SY_N(240), 375 .mode_horztiming = 0x00c4623b, 376 .mode_verttiming = 0x00502814, 377 .mode_clkcontrol = 0x00020002, /* /4=24Mhz */ 378 .mode_pwmdiv = 0x00000000, 379 .mode_pwmhi = 0x00000000, 380 .mode_outmask = 0x00FFFFFF, 381 .mode_fifoctrl = 0x2f2f2f2f, 382 .mode_backlight = 0x00000000, 383 .lcdclk = 96, 384 320, 320, 385 240, 240, 386 }, 387 388 [1] = { /* VGA 640x480 H:30.3kHz V:58Hz */ 389 .name = "VGA_640x480", 390 .monspecs = { 391 .modedb = NULL, 392 .modedb_len = 0, 393 .hfmin = 30000, 394 .hfmax = 70000, 395 .vfmin = 60, 396 .vfmax = 60, 397 .dclkmin = 6000000, 398 .dclkmax = 28000000, 399 .input = FB_DISP_RGB, 400 }, 401 .mode_screen = 0x13f9df80, 402 .mode_horztiming = 0x003c5859, 403 .mode_verttiming = 0x00741201, 404 .mode_clkcontrol = 0x00020001, /* /4=24Mhz */ 405 .mode_pwmdiv = 0x00000000, 406 .mode_pwmhi = 0x00000000, 407 .mode_outmask = 0x00FFFFFF, 408 .mode_fifoctrl = 0x2f2f2f2f, 409 .mode_backlight = 0x00000000, 410 .lcdclk = 96, 411 640, 480, 412 640, 480, 413 }, 414 415 [2] = { /* SVGA 800x600 H:46.1kHz V:69Hz */ 416 .name = "SVGA_800x600", 417 .monspecs = { 418 .modedb = NULL, 419 .modedb_len = 0, 420 .hfmin = 30000, 421 .hfmax = 70000, 422 .vfmin = 60, 423 .vfmax = 60, 424 .dclkmin = 6000000, 425 .dclkmax = 28000000, 426 .input = FB_DISP_RGB, 427 }, 428 .mode_screen = 0x18fa5780, 429 .mode_horztiming = 0x00dc7e77, 430 .mode_verttiming = 0x00584805, 431 .mode_clkcontrol = 0x00020000, /* /2=48Mhz */ 432 .mode_pwmdiv = 0x00000000, 433 .mode_pwmhi = 0x00000000, 434 .mode_outmask = 0x00FFFFFF, 435 .mode_fifoctrl = 0x2f2f2f2f, 436 .mode_backlight = 0x00000000, 437 .lcdclk = 96, 438 800, 800, 439 600, 600, 440 }, 441 442 [3] = { /* XVGA 1024x768 H:56.2kHz V:70Hz */ 443 .name = "XVGA_1024x768", 444 .monspecs = { 445 .modedb = NULL, 446 .modedb_len = 0, 447 .hfmin = 30000, 448 .hfmax = 70000, 449 .vfmin = 60, 450 .vfmax = 60, 451 .dclkmin = 6000000, 452 .dclkmax = 28000000, 453 .input = FB_DISP_RGB, 454 }, 455 .mode_screen = 0x1ffaff80, 456 .mode_horztiming = 0x007d0e57, 457 .mode_verttiming = 0x00740a01, 458 .mode_clkcontrol = 0x000A0000, /* /1 */ 459 .mode_pwmdiv = 0x00000000, 460 .mode_pwmhi = 0x00000000, 461 .mode_outmask = 0x00FFFFFF, 462 .mode_fifoctrl = 0x2f2f2f2f, 463 .mode_backlight = 0x00000000, 464 .lcdclk = 72, 465 1024, 1024, 466 768, 768, 467 }, 468 469 [4] = { /* XVGA XVGA 1280x1024 H:68.5kHz V:65Hz */ 470 .name = "XVGA_1280x1024", 471 .monspecs = { 472 .modedb = NULL, 473 .modedb_len = 0, 474 .hfmin = 30000, 475 .hfmax = 70000, 476 .vfmin = 60, 477 .vfmax = 60, 478 .dclkmin = 6000000, 479 .dclkmax = 28000000, 480 .input = FB_DISP_RGB, 481 }, 482 .mode_screen = 0x27fbff80, 483 .mode_horztiming = 0x00cdb2c7, 484 .mode_verttiming = 0x00600002, 485 .mode_clkcontrol = 0x000A0000, /* /1 */ 486 .mode_pwmdiv = 0x00000000, 487 .mode_pwmhi = 0x00000000, 488 .mode_outmask = 0x00FFFFFF, 489 .mode_fifoctrl = 0x2f2f2f2f, 490 .mode_backlight = 0x00000000, 491 .lcdclk = 120, 492 1280, 1280, 493 1024, 1024, 494 }, 495 496 [5] = { /* Samsung 1024x768 TFT */ 497 .name = "Samsung_1024x768_TFT", 498 .monspecs = { 499 .modedb = NULL, 500 .modedb_len = 0, 501 .hfmin = 30000, 502 .hfmax = 70000, 503 .vfmin = 60, 504 .vfmax = 60, 505 .dclkmin = 6000000, 506 .dclkmax = 28000000, 507 .input = FB_DISP_RGB, 508 }, 509 .mode_screen = 0x1ffaff80, 510 .mode_horztiming = 0x018cc677, 511 .mode_verttiming = 0x00241217, 512 .mode_clkcontrol = 0x00000000, /* SCB 0x1 /4=24Mhz */ 513 .mode_pwmdiv = 0x8000063f, /* SCB 0x0 */ 514 .mode_pwmhi = 0x03400000, /* SCB 0x0 */ 515 .mode_outmask = 0x00FFFFFF, 516 .mode_fifoctrl = 0x2f2f2f2f, 517 .mode_backlight = 0x00000000, 518 .lcdclk = 96, 519 1024, 1024, 520 768, 768, 521 }, 522 523 [6] = { /* Toshiba 640x480 TFT */ 524 .name = "Toshiba_640x480_TFT", 525 .monspecs = { 526 .modedb = NULL, 527 .modedb_len = 0, 528 .hfmin = 30000, 529 .hfmax = 70000, 530 .vfmin = 60, 531 .vfmax = 60, 532 .dclkmin = 6000000, 533 .dclkmax = 28000000, 534 .input = FB_DISP_RGB, 535 }, 536 .mode_screen = LCD_SCREEN_SX_N(640) | 537 LCD_SCREEN_SY_N(480), 538 .mode_horztiming = LCD_HORZTIMING_HPW_N(96) | 539 LCD_HORZTIMING_HND1_N(13) | LCD_HORZTIMING_HND2_N(51), 540 .mode_verttiming = LCD_VERTTIMING_VPW_N(2) | 541 LCD_VERTTIMING_VND1_N(11) | LCD_VERTTIMING_VND2_N(32), 542 .mode_clkcontrol = 0x00000000, /* /4=24Mhz */ 543 .mode_pwmdiv = 0x8000063f, 544 .mode_pwmhi = 0x03400000, 545 .mode_outmask = 0x00fcfcfc, 546 .mode_fifoctrl = 0x2f2f2f2f, 547 .mode_backlight = 0x00000000, 548 .lcdclk = 96, 549 640, 480, 550 640, 480, 551 }, 552 553 [7] = { /* Sharp 320x240 TFT */ 554 .name = "Sharp_320x240_TFT", 555 .monspecs = { 556 .modedb = NULL, 557 .modedb_len = 0, 558 .hfmin = 12500, 559 .hfmax = 20000, 560 .vfmin = 38, 561 .vfmax = 81, 562 .dclkmin = 4500000, 563 .dclkmax = 6800000, 564 .input = FB_DISP_RGB, 565 }, 566 .mode_screen = LCD_SCREEN_SX_N(320) | 567 LCD_SCREEN_SY_N(240), 568 .mode_horztiming = LCD_HORZTIMING_HPW_N(60) | 569 LCD_HORZTIMING_HND1_N(13) | LCD_HORZTIMING_HND2_N(2), 570 .mode_verttiming = LCD_VERTTIMING_VPW_N(2) | 571 LCD_VERTTIMING_VND1_N(2) | LCD_VERTTIMING_VND2_N(5), 572 .mode_clkcontrol = LCD_CLKCONTROL_PCD_N(7), /*16=6Mhz*/ 573 .mode_pwmdiv = 0x8000063f, 574 .mode_pwmhi = 0x03400000, 575 .mode_outmask = 0x00fcfcfc, 576 .mode_fifoctrl = 0x2f2f2f2f, 577 .mode_backlight = 0x00000000, 578 .lcdclk = 96, /* 96MHz AUXPLL */ 579 320, 320, 580 240, 240, 581 }, 582 583 [8] = { /* Toppoly TD070WGCB2 7" 856x480 TFT */ 584 .name = "Toppoly_TD070WGCB2", 585 .monspecs = { 586 .modedb = NULL, 587 .modedb_len = 0, 588 .hfmin = 30000, 589 .hfmax = 70000, 590 .vfmin = 60, 591 .vfmax = 60, 592 .dclkmin = 6000000, 593 .dclkmax = 28000000, 594 .input = FB_DISP_RGB, 595 }, 596 .mode_screen = LCD_SCREEN_SX_N(856) | 597 LCD_SCREEN_SY_N(480), 598 .mode_horztiming = LCD_HORZTIMING_HND2_N(43) | 599 LCD_HORZTIMING_HND1_N(43) | LCD_HORZTIMING_HPW_N(114), 600 .mode_verttiming = LCD_VERTTIMING_VND2_N(20) | 601 LCD_VERTTIMING_VND1_N(21) | LCD_VERTTIMING_VPW_N(4), 602 .mode_clkcontrol = 0x00020001, /* /4=24Mhz */ 603 .mode_pwmdiv = 0x8000063f, 604 .mode_pwmhi = 0x03400000, 605 .mode_outmask = 0x00fcfcfc, 606 .mode_fifoctrl = 0x2f2f2f2f, 607 .mode_backlight = 0x00000000, 608 .lcdclk = 96, 609 856, 856, 610 480, 480, 611 }, 612 [9] = { 613 .name = "DB1300_800x480", 614 .monspecs = { 615 .modedb = NULL, 616 .modedb_len = 0, 617 .hfmin = 30000, 618 .hfmax = 70000, 619 .vfmin = 60, 620 .vfmax = 60, 621 .dclkmin = 6000000, 622 .dclkmax = 28000000, 623 .input = FB_DISP_RGB, 624 }, 625 .mode_screen = LCD_SCREEN_SX_N(800) | 626 LCD_SCREEN_SY_N(480), 627 .mode_horztiming = LCD_HORZTIMING_HPW_N(5) | 628 LCD_HORZTIMING_HND1_N(16) | 629 LCD_HORZTIMING_HND2_N(8), 630 .mode_verttiming = LCD_VERTTIMING_VPW_N(4) | 631 LCD_VERTTIMING_VND1_N(8) | 632 LCD_VERTTIMING_VND2_N(5), 633 .mode_clkcontrol = LCD_CLKCONTROL_PCD_N(1) | 634 LCD_CLKCONTROL_IV | 635 LCD_CLKCONTROL_IH, 636 .mode_pwmdiv = 0x00000000, 637 .mode_pwmhi = 0x00000000, 638 .mode_outmask = 0x00FFFFFF, 639 .mode_fifoctrl = 0x2f2f2f2f, 640 .mode_backlight = 0x00000000, 641 .lcdclk = 96, 642 800, 800, 643 480, 480, 644 }, 645 }; 646 647 #define NUM_PANELS (ARRAY_SIZE(known_lcd_panels)) 648 649 /********************************************************************/ 650 651 static int winbpp (unsigned int winctrl1) 652 { 653 int bits = 0; 654 655 /* how many bits are needed for each pixel format */ 656 switch (winctrl1 & LCD_WINCTRL1_FRM) { 657 case LCD_WINCTRL1_FRM_1BPP: 658 bits = 1; 659 break; 660 case LCD_WINCTRL1_FRM_2BPP: 661 bits = 2; 662 break; 663 case LCD_WINCTRL1_FRM_4BPP: 664 bits = 4; 665 break; 666 case LCD_WINCTRL1_FRM_8BPP: 667 bits = 8; 668 break; 669 case LCD_WINCTRL1_FRM_12BPP: 670 case LCD_WINCTRL1_FRM_16BPP655: 671 case LCD_WINCTRL1_FRM_16BPP565: 672 case LCD_WINCTRL1_FRM_16BPP556: 673 case LCD_WINCTRL1_FRM_16BPPI1555: 674 case LCD_WINCTRL1_FRM_16BPPI5551: 675 case LCD_WINCTRL1_FRM_16BPPA1555: 676 case LCD_WINCTRL1_FRM_16BPPA5551: 677 bits = 16; 678 break; 679 case LCD_WINCTRL1_FRM_24BPP: 680 case LCD_WINCTRL1_FRM_32BPP: 681 bits = 32; 682 break; 683 } 684 685 return bits; 686 } 687 688 static int fbinfo2index (struct fb_info *fb_info) 689 { 690 int i; 691 692 for (i = 0; i < device_count; ++i) { 693 if (fb_info == _au1200fb_infos[i]) 694 return i; 695 } 696 printk("au1200fb: ERROR: fbinfo2index failed!\n"); 697 return -1; 698 } 699 700 static int au1200_setlocation (struct au1200fb_device *fbdev, int plane, 701 int xpos, int ypos) 702 { 703 uint32 winctrl0, winctrl1, winenable, fb_offset = 0; 704 int xsz, ysz; 705 706 /* FIX!!! NOT CHECKING FOR COMPLETE OFFSCREEN YET */ 707 708 winctrl0 = lcd->window[plane].winctrl0; 709 winctrl1 = lcd->window[plane].winctrl1; 710 winctrl0 &= (LCD_WINCTRL0_A | LCD_WINCTRL0_AEN); 711 winctrl1 &= ~(LCD_WINCTRL1_SZX | LCD_WINCTRL1_SZY); 712 713 /* Check for off-screen adjustments */ 714 xsz = win->w[plane].xres; 715 ysz = win->w[plane].yres; 716 if ((xpos + win->w[plane].xres) > panel->Xres) { 717 /* Off-screen to the right */ 718 xsz = panel->Xres - xpos; /* off by 1 ??? */ 719 /*printk("off screen right\n");*/ 720 } 721 722 if ((ypos + win->w[plane].yres) > panel->Yres) { 723 /* Off-screen to the bottom */ 724 ysz = panel->Yres - ypos; /* off by 1 ??? */ 725 /*printk("off screen bottom\n");*/ 726 } 727 728 if (xpos < 0) { 729 /* Off-screen to the left */ 730 xsz = win->w[plane].xres + xpos; 731 fb_offset += (((0 - xpos) * winbpp(lcd->window[plane].winctrl1))/8); 732 xpos = 0; 733 /*printk("off screen left\n");*/ 734 } 735 736 if (ypos < 0) { 737 /* Off-screen to the top */ 738 ysz = win->w[plane].yres + ypos; 739 /* fixme: fb_offset += ((0-ypos)*fb_pars[plane].line_length); */ 740 ypos = 0; 741 /*printk("off screen top\n");*/ 742 } 743 744 /* record settings */ 745 win->w[plane].xpos = xpos; 746 win->w[plane].ypos = ypos; 747 748 xsz -= 1; 749 ysz -= 1; 750 winctrl0 |= (xpos << 21); 751 winctrl0 |= (ypos << 10); 752 winctrl1 |= (xsz << 11); 753 winctrl1 |= (ysz << 0); 754 755 /* Disable the window while making changes, then restore WINEN */ 756 winenable = lcd->winenable & (1 << plane); 757 wmb(); /* drain writebuffer */ 758 lcd->winenable &= ~(1 << plane); 759 lcd->window[plane].winctrl0 = winctrl0; 760 lcd->window[plane].winctrl1 = winctrl1; 761 lcd->window[plane].winbuf0 = 762 lcd->window[plane].winbuf1 = fbdev->fb_phys; 763 lcd->window[plane].winbufctrl = 0; /* select winbuf0 */ 764 lcd->winenable |= winenable; 765 wmb(); /* drain writebuffer */ 766 767 return 0; 768 } 769 770 static void au1200_setpanel(struct panel_settings *newpanel, 771 struct au1200fb_platdata *pd) 772 { 773 /* 774 * Perform global setup/init of LCD controller 775 */ 776 uint32 winenable; 777 778 /* Make sure all windows disabled */ 779 winenable = lcd->winenable; 780 lcd->winenable = 0; 781 wmb(); /* drain writebuffer */ 782 /* 783 * Ensure everything is disabled before reconfiguring 784 */ 785 if (lcd->screen & LCD_SCREEN_SEN) { 786 /* Wait for vertical sync period */ 787 lcd->intstatus = LCD_INT_SS; 788 while ((lcd->intstatus & LCD_INT_SS) == 0) 789 ; 790 791 lcd->screen &= ~LCD_SCREEN_SEN; /*disable the controller*/ 792 793 do { 794 lcd->intstatus = lcd->intstatus; /*clear interrupts*/ 795 wmb(); /* drain writebuffer */ 796 /*wait for controller to shut down*/ 797 } while ((lcd->intstatus & LCD_INT_SD) == 0); 798 799 /* Call shutdown of current panel (if up) */ 800 /* this must occur last, because if an external clock is driving 801 the controller, the clock cannot be turned off before first 802 shutting down the controller. 803 */ 804 if (pd->panel_shutdown) 805 pd->panel_shutdown(); 806 } 807 808 /* Newpanel == NULL indicates a shutdown operation only */ 809 if (newpanel == NULL) 810 return; 811 812 panel = newpanel; 813 814 printk("Panel(%s), %dx%d\n", panel->name, panel->Xres, panel->Yres); 815 816 /* 817 * Setup clocking if internal LCD clock source (assumes sys_auxpll valid) 818 */ 819 if (!(panel->mode_clkcontrol & LCD_CLKCONTROL_EXT)) 820 { 821 struct clk *c = clk_get(NULL, "lcd_intclk"); 822 long r, pc = panel->lcdclk * 1000000; 823 824 if (!IS_ERR(c)) { 825 r = clk_round_rate(c, pc); 826 if ((pc - r) < (pc / 10)) { /* 10% slack */ 827 clk_set_rate(c, r); 828 clk_prepare_enable(c); 829 } 830 clk_put(c); 831 } 832 } 833 834 /* 835 * Configure panel timings 836 */ 837 lcd->screen = panel->mode_screen; 838 lcd->horztiming = panel->mode_horztiming; 839 lcd->verttiming = panel->mode_verttiming; 840 lcd->clkcontrol = panel->mode_clkcontrol; 841 lcd->pwmdiv = panel->mode_pwmdiv; 842 lcd->pwmhi = panel->mode_pwmhi; 843 lcd->outmask = panel->mode_outmask; 844 lcd->fifoctrl = panel->mode_fifoctrl; 845 wmb(); /* drain writebuffer */ 846 847 /* fixme: Check window settings to make sure still valid 848 * for new geometry */ 849 #if 0 850 au1200_setlocation(fbdev, 0, win->w[0].xpos, win->w[0].ypos); 851 au1200_setlocation(fbdev, 1, win->w[1].xpos, win->w[1].ypos); 852 au1200_setlocation(fbdev, 2, win->w[2].xpos, win->w[2].ypos); 853 au1200_setlocation(fbdev, 3, win->w[3].xpos, win->w[3].ypos); 854 #endif 855 lcd->winenable = winenable; 856 857 /* 858 * Re-enable screen now that it is configured 859 */ 860 lcd->screen |= LCD_SCREEN_SEN; 861 wmb(); /* drain writebuffer */ 862 863 /* Call init of panel */ 864 if (pd->panel_init) 865 pd->panel_init(); 866 867 /* FIX!!!! not appropriate on panel change!!! Global setup/init */ 868 lcd->intenable = 0; 869 lcd->intstatus = ~0; 870 lcd->backcolor = win->mode_backcolor; 871 872 /* Setup Color Key - FIX!!! */ 873 lcd->colorkey = win->mode_colorkey; 874 lcd->colorkeymsk = win->mode_colorkeymsk; 875 876 /* Setup HWCursor - FIX!!! Need to support this eventually */ 877 lcd->hwc.cursorctrl = 0; 878 lcd->hwc.cursorpos = 0; 879 lcd->hwc.cursorcolor0 = 0; 880 lcd->hwc.cursorcolor1 = 0; 881 lcd->hwc.cursorcolor2 = 0; 882 lcd->hwc.cursorcolor3 = 0; 883 884 885 #if 0 886 #define D(X) printk("%25s: %08X\n", #X, X) 887 D(lcd->screen); 888 D(lcd->horztiming); 889 D(lcd->verttiming); 890 D(lcd->clkcontrol); 891 D(lcd->pwmdiv); 892 D(lcd->pwmhi); 893 D(lcd->outmask); 894 D(lcd->fifoctrl); 895 D(lcd->window[0].winctrl0); 896 D(lcd->window[0].winctrl1); 897 D(lcd->window[0].winctrl2); 898 D(lcd->window[0].winbuf0); 899 D(lcd->window[0].winbuf1); 900 D(lcd->window[0].winbufctrl); 901 D(lcd->window[1].winctrl0); 902 D(lcd->window[1].winctrl1); 903 D(lcd->window[1].winctrl2); 904 D(lcd->window[1].winbuf0); 905 D(lcd->window[1].winbuf1); 906 D(lcd->window[1].winbufctrl); 907 D(lcd->window[2].winctrl0); 908 D(lcd->window[2].winctrl1); 909 D(lcd->window[2].winctrl2); 910 D(lcd->window[2].winbuf0); 911 D(lcd->window[2].winbuf1); 912 D(lcd->window[2].winbufctrl); 913 D(lcd->window[3].winctrl0); 914 D(lcd->window[3].winctrl1); 915 D(lcd->window[3].winctrl2); 916 D(lcd->window[3].winbuf0); 917 D(lcd->window[3].winbuf1); 918 D(lcd->window[3].winbufctrl); 919 D(lcd->winenable); 920 D(lcd->intenable); 921 D(lcd->intstatus); 922 D(lcd->backcolor); 923 D(lcd->winenable); 924 D(lcd->colorkey); 925 D(lcd->colorkeymsk); 926 D(lcd->hwc.cursorctrl); 927 D(lcd->hwc.cursorpos); 928 D(lcd->hwc.cursorcolor0); 929 D(lcd->hwc.cursorcolor1); 930 D(lcd->hwc.cursorcolor2); 931 D(lcd->hwc.cursorcolor3); 932 #endif 933 } 934 935 static void au1200_setmode(struct au1200fb_device *fbdev) 936 { 937 int plane = fbdev->plane; 938 /* Window/plane setup */ 939 lcd->window[plane].winctrl1 = ( 0 940 | LCD_WINCTRL1_PRI_N(plane) 941 | win->w[plane].mode_winctrl1 /* FRM,CCO,PO,PIPE */ 942 ) ; 943 944 au1200_setlocation(fbdev, plane, win->w[plane].xpos, win->w[plane].ypos); 945 946 lcd->window[plane].winctrl2 = ( 0 947 | LCD_WINCTRL2_CKMODE_00 948 | LCD_WINCTRL2_DBM 949 | LCD_WINCTRL2_BX_N(fbdev->fb_info->fix.line_length) 950 | LCD_WINCTRL2_SCX_1 951 | LCD_WINCTRL2_SCY_1 952 ) ; 953 lcd->winenable |= win->w[plane].mode_winenable; 954 wmb(); /* drain writebuffer */ 955 } 956 957 958 /* Inline helpers */ 959 960 /*#define panel_is_dual(panel) ((panel->mode_screen & LCD_SCREEN_PT) == LCD_SCREEN_PT_010)*/ 961 /*#define panel_is_active(panel)((panel->mode_screen & LCD_SCREEN_PT) == LCD_SCREEN_PT_010)*/ 962 963 #define panel_is_color(panel) ((panel->mode_screen & LCD_SCREEN_PT) <= LCD_SCREEN_PT_CDSTN) 964 965 /* Bitfields format supported by the controller. */ 966 static struct fb_bitfield rgb_bitfields[][4] = { 967 /* Red, Green, Blue, Transp */ 968 [LCD_WINCTRL1_FRM_16BPP655 >> 25] = 969 { { 10, 6, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 0, 0, 0 } }, 970 971 [LCD_WINCTRL1_FRM_16BPP565 >> 25] = 972 { { 11, 5, 0 }, { 5, 6, 0 }, { 0, 5, 0 }, { 0, 0, 0 } }, 973 974 [LCD_WINCTRL1_FRM_16BPP556 >> 25] = 975 { { 11, 5, 0 }, { 6, 5, 0 }, { 0, 6, 0 }, { 0, 0, 0 } }, 976 977 [LCD_WINCTRL1_FRM_16BPPI1555 >> 25] = 978 { { 10, 5, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 0, 0, 0 } }, 979 980 [LCD_WINCTRL1_FRM_16BPPI5551 >> 25] = 981 { { 11, 5, 0 }, { 6, 5, 0 }, { 1, 5, 0 }, { 0, 0, 0 } }, 982 983 [LCD_WINCTRL1_FRM_16BPPA1555 >> 25] = 984 { { 10, 5, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 15, 1, 0 } }, 985 986 [LCD_WINCTRL1_FRM_16BPPA5551 >> 25] = 987 { { 11, 5, 0 }, { 6, 5, 0 }, { 1, 5, 0 }, { 0, 1, 0 } }, 988 989 [LCD_WINCTRL1_FRM_24BPP >> 25] = 990 { { 16, 8, 0 }, { 8, 8, 0 }, { 0, 8, 0 }, { 0, 0, 0 } }, 991 992 [LCD_WINCTRL1_FRM_32BPP >> 25] = 993 { { 16, 8, 0 }, { 8, 8, 0 }, { 0, 8, 0 }, { 24, 0, 0 } }, 994 }; 995 996 /*-------------------------------------------------------------------------*/ 997 998 /* Helpers */ 999 1000 static void au1200fb_update_fbinfo(struct fb_info *fbi) 1001 { 1002 /* FIX!!!! This also needs to take the window pixel format into account!!! */ 1003 1004 /* Update var-dependent FB info */ 1005 if (panel_is_color(panel)) { 1006 if (fbi->var.bits_per_pixel <= 8) { 1007 /* palettized */ 1008 fbi->fix.visual = FB_VISUAL_PSEUDOCOLOR; 1009 fbi->fix.line_length = fbi->var.xres_virtual / 1010 (8/fbi->var.bits_per_pixel); 1011 } else { 1012 /* non-palettized */ 1013 fbi->fix.visual = FB_VISUAL_TRUECOLOR; 1014 fbi->fix.line_length = fbi->var.xres_virtual * (fbi->var.bits_per_pixel / 8); 1015 } 1016 } else { 1017 /* mono FIX!!! mono 8 and 4 bits */ 1018 fbi->fix.visual = FB_VISUAL_MONO10; 1019 fbi->fix.line_length = fbi->var.xres_virtual / 8; 1020 } 1021 1022 fbi->screen_size = fbi->fix.line_length * fbi->var.yres_virtual; 1023 print_dbg("line length: %d\n", fbi->fix.line_length); 1024 print_dbg("bits_per_pixel: %d\n", fbi->var.bits_per_pixel); 1025 } 1026 1027 /*-------------------------------------------------------------------------*/ 1028 1029 /* AU1200 framebuffer driver */ 1030 1031 /* fb_check_var 1032 * Validate var settings with hardware restrictions and modify it if necessary 1033 */ 1034 static int au1200fb_fb_check_var(struct fb_var_screeninfo *var, 1035 struct fb_info *fbi) 1036 { 1037 struct au1200fb_device *fbdev = fbi->par; 1038 u32 pixclock; 1039 int screen_size, plane; 1040 1041 plane = fbdev->plane; 1042 1043 /* Make sure that the mode respect all LCD controller and 1044 * panel restrictions. */ 1045 var->xres = win->w[plane].xres; 1046 var->yres = win->w[plane].yres; 1047 1048 /* No need for virtual resolution support */ 1049 var->xres_virtual = var->xres; 1050 var->yres_virtual = var->yres; 1051 1052 var->bits_per_pixel = winbpp(win->w[plane].mode_winctrl1); 1053 1054 screen_size = var->xres_virtual * var->yres_virtual; 1055 if (var->bits_per_pixel > 8) screen_size *= (var->bits_per_pixel / 8); 1056 else screen_size /= (8/var->bits_per_pixel); 1057 1058 if (fbdev->fb_len < screen_size) 1059 return -EINVAL; /* Virtual screen is to big, abort */ 1060 1061 /* FIX!!!! what are the implicaitons of ignoring this for windows ??? */ 1062 /* The max LCD clock is fixed to 48MHz (value of AUX_CLK). The pixel 1063 * clock can only be obtain by dividing this value by an even integer. 1064 * Fallback to a slower pixel clock if necessary. */ 1065 pixclock = max((u32)(PICOS2KHZ(var->pixclock) * 1000), fbi->monspecs.dclkmin); 1066 pixclock = min3(pixclock, fbi->monspecs.dclkmax, (u32)AU1200_LCD_MAX_CLK/2); 1067 1068 if (AU1200_LCD_MAX_CLK % pixclock) { 1069 int diff = AU1200_LCD_MAX_CLK % pixclock; 1070 pixclock -= diff; 1071 } 1072 1073 var->pixclock = KHZ2PICOS(pixclock/1000); 1074 #if 0 1075 if (!panel_is_active(panel)) { 1076 int pcd = AU1200_LCD_MAX_CLK / (pixclock * 2) - 1; 1077 1078 if (!panel_is_color(panel) 1079 && (panel->control_base & LCD_CONTROL_MPI) && (pcd < 3)) { 1080 /* STN 8bit mono panel support is up to 6MHz pixclock */ 1081 var->pixclock = KHZ2PICOS(6000); 1082 } else if (!pcd) { 1083 /* Other STN panel support is up to 12MHz */ 1084 var->pixclock = KHZ2PICOS(12000); 1085 } 1086 } 1087 #endif 1088 /* Set bitfield accordingly */ 1089 switch (var->bits_per_pixel) { 1090 case 16: 1091 { 1092 /* 16bpp True color. 1093 * These must be set to MATCH WINCTRL[FORM] */ 1094 int idx; 1095 idx = (win->w[0].mode_winctrl1 & LCD_WINCTRL1_FRM) >> 25; 1096 var->red = rgb_bitfields[idx][0]; 1097 var->green = rgb_bitfields[idx][1]; 1098 var->blue = rgb_bitfields[idx][2]; 1099 var->transp = rgb_bitfields[idx][3]; 1100 break; 1101 } 1102 1103 case 32: 1104 { 1105 /* 32bpp True color. 1106 * These must be set to MATCH WINCTRL[FORM] */ 1107 int idx; 1108 idx = (win->w[0].mode_winctrl1 & LCD_WINCTRL1_FRM) >> 25; 1109 var->red = rgb_bitfields[idx][0]; 1110 var->green = rgb_bitfields[idx][1]; 1111 var->blue = rgb_bitfields[idx][2]; 1112 var->transp = rgb_bitfields[idx][3]; 1113 break; 1114 } 1115 default: 1116 print_dbg("Unsupported depth %dbpp", var->bits_per_pixel); 1117 return -EINVAL; 1118 } 1119 1120 return 0; 1121 } 1122 1123 /* fb_set_par 1124 * Set hardware with var settings. This will enable the controller with a 1125 * specific mode, normally validated with the fb_check_var method 1126 */ 1127 static int au1200fb_fb_set_par(struct fb_info *fbi) 1128 { 1129 struct au1200fb_device *fbdev = fbi->par; 1130 1131 au1200fb_update_fbinfo(fbi); 1132 au1200_setmode(fbdev); 1133 1134 return 0; 1135 } 1136 1137 /* fb_setcolreg 1138 * Set color in LCD palette. 1139 */ 1140 static int au1200fb_fb_setcolreg(unsigned regno, unsigned red, unsigned green, 1141 unsigned blue, unsigned transp, struct fb_info *fbi) 1142 { 1143 volatile u32 *palette = lcd->palette; 1144 u32 value; 1145 1146 if (regno > (AU1200_LCD_NBR_PALETTE_ENTRIES - 1)) 1147 return -EINVAL; 1148 1149 if (fbi->var.grayscale) { 1150 /* Convert color to grayscale */ 1151 red = green = blue = 1152 (19595 * red + 38470 * green + 7471 * blue) >> 16; 1153 } 1154 1155 if (fbi->fix.visual == FB_VISUAL_TRUECOLOR) { 1156 /* Place color in the pseudopalette */ 1157 if (regno > 16) 1158 return -EINVAL; 1159 1160 palette = (u32*) fbi->pseudo_palette; 1161 1162 red >>= (16 - fbi->var.red.length); 1163 green >>= (16 - fbi->var.green.length); 1164 blue >>= (16 - fbi->var.blue.length); 1165 1166 value = (red << fbi->var.red.offset) | 1167 (green << fbi->var.green.offset)| 1168 (blue << fbi->var.blue.offset); 1169 value &= 0xFFFF; 1170 1171 } else if (1 /*FIX!!! panel_is_active(fbdev->panel)*/) { 1172 /* COLOR TFT PALLETTIZED (use RGB 565) */ 1173 value = (red & 0xF800)|((green >> 5) & 1174 0x07E0)|((blue >> 11) & 0x001F); 1175 value &= 0xFFFF; 1176 1177 } else if (0 /*panel_is_color(fbdev->panel)*/) { 1178 /* COLOR STN MODE */ 1179 value = 0x1234; 1180 value &= 0xFFF; 1181 } else { 1182 /* MONOCHROME MODE */ 1183 value = (green >> 12) & 0x000F; 1184 value &= 0xF; 1185 } 1186 1187 palette[regno] = value; 1188 1189 return 0; 1190 } 1191 1192 /* fb_blank 1193 * Blank the screen. Depending on the mode, the screen will be 1194 * activated with the backlight color, or desactivated 1195 */ 1196 static int au1200fb_fb_blank(int blank_mode, struct fb_info *fbi) 1197 { 1198 struct au1200fb_device *fbdev = fbi->par; 1199 1200 /* Short-circuit screen blanking */ 1201 if (noblanking) 1202 return 0; 1203 1204 switch (blank_mode) { 1205 1206 case FB_BLANK_UNBLANK: 1207 case FB_BLANK_NORMAL: 1208 /* printk("turn on panel\n"); */ 1209 au1200_setpanel(panel, fbdev->pd); 1210 break; 1211 case FB_BLANK_VSYNC_SUSPEND: 1212 case FB_BLANK_HSYNC_SUSPEND: 1213 case FB_BLANK_POWERDOWN: 1214 /* printk("turn off panel\n"); */ 1215 au1200_setpanel(NULL, fbdev->pd); 1216 break; 1217 default: 1218 break; 1219 1220 } 1221 1222 /* FB_BLANK_NORMAL is a soft blank */ 1223 return (blank_mode == FB_BLANK_NORMAL) ? -EINVAL : 0; 1224 } 1225 1226 /* fb_mmap 1227 * Map video memory in user space. We don't use the generic fb_mmap 1228 * method mainly to allow the use of the TLB streaming flag (CCA=6) 1229 */ 1230 static int au1200fb_fb_mmap(struct fb_info *info, struct vm_area_struct *vma) 1231 { 1232 struct au1200fb_device *fbdev = info->par; 1233 1234 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); 1235 pgprot_val(vma->vm_page_prot) |= _CACHE_MASK; /* CCA=7 */ 1236 1237 return vm_iomap_memory(vma, fbdev->fb_phys, fbdev->fb_len); 1238 } 1239 1240 static void set_global(u_int cmd, struct au1200_lcd_global_regs_t *pdata) 1241 { 1242 1243 unsigned int hi1, divider; 1244 1245 /* SCREEN_SIZE: user cannot reset size, must switch panel choice */ 1246 1247 if (pdata->flags & SCREEN_BACKCOLOR) 1248 lcd->backcolor = pdata->backcolor; 1249 1250 if (pdata->flags & SCREEN_BRIGHTNESS) { 1251 1252 // limit brightness pwm duty to >= 30/1600 1253 if (pdata->brightness < 30) { 1254 pdata->brightness = 30; 1255 } 1256 divider = (lcd->pwmdiv & 0x3FFFF) + 1; 1257 hi1 = (((pdata->brightness & 0xFF)+1) * divider >> 8); 1258 lcd->pwmhi &= 0xFFFF; 1259 lcd->pwmhi |= (hi1 << 16); 1260 } 1261 1262 if (pdata->flags & SCREEN_COLORKEY) 1263 lcd->colorkey = pdata->colorkey; 1264 1265 if (pdata->flags & SCREEN_MASK) 1266 lcd->colorkeymsk = pdata->mask; 1267 wmb(); /* drain writebuffer */ 1268 } 1269 1270 static void get_global(u_int cmd, struct au1200_lcd_global_regs_t *pdata) 1271 { 1272 unsigned int hi1, divider; 1273 1274 pdata->xsize = ((lcd->screen & LCD_SCREEN_SX) >> 19) + 1; 1275 pdata->ysize = ((lcd->screen & LCD_SCREEN_SY) >> 8) + 1; 1276 1277 pdata->backcolor = lcd->backcolor; 1278 pdata->colorkey = lcd->colorkey; 1279 pdata->mask = lcd->colorkeymsk; 1280 1281 // brightness 1282 hi1 = (lcd->pwmhi >> 16) + 1; 1283 divider = (lcd->pwmdiv & 0x3FFFF) + 1; 1284 pdata->brightness = ((hi1 << 8) / divider) - 1; 1285 wmb(); /* drain writebuffer */ 1286 } 1287 1288 static void set_window(unsigned int plane, 1289 struct au1200_lcd_window_regs_t *pdata) 1290 { 1291 unsigned int val, bpp; 1292 1293 /* Window control register 0 */ 1294 if (pdata->flags & WIN_POSITION) { 1295 val = lcd->window[plane].winctrl0 & ~(LCD_WINCTRL0_OX | 1296 LCD_WINCTRL0_OY); 1297 val |= ((pdata->xpos << 21) & LCD_WINCTRL0_OX); 1298 val |= ((pdata->ypos << 10) & LCD_WINCTRL0_OY); 1299 lcd->window[plane].winctrl0 = val; 1300 } 1301 if (pdata->flags & WIN_ALPHA_COLOR) { 1302 val = lcd->window[plane].winctrl0 & ~(LCD_WINCTRL0_A); 1303 val |= ((pdata->alpha_color << 2) & LCD_WINCTRL0_A); 1304 lcd->window[plane].winctrl0 = val; 1305 } 1306 if (pdata->flags & WIN_ALPHA_MODE) { 1307 val = lcd->window[plane].winctrl0 & ~(LCD_WINCTRL0_AEN); 1308 val |= ((pdata->alpha_mode << 1) & LCD_WINCTRL0_AEN); 1309 lcd->window[plane].winctrl0 = val; 1310 } 1311 1312 /* Window control register 1 */ 1313 if (pdata->flags & WIN_PRIORITY) { 1314 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_PRI); 1315 val |= ((pdata->priority << 30) & LCD_WINCTRL1_PRI); 1316 lcd->window[plane].winctrl1 = val; 1317 } 1318 if (pdata->flags & WIN_CHANNEL) { 1319 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_PIPE); 1320 val |= ((pdata->channel << 29) & LCD_WINCTRL1_PIPE); 1321 lcd->window[plane].winctrl1 = val; 1322 } 1323 if (pdata->flags & WIN_BUFFER_FORMAT) { 1324 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_FRM); 1325 val |= ((pdata->buffer_format << 25) & LCD_WINCTRL1_FRM); 1326 lcd->window[plane].winctrl1 = val; 1327 } 1328 if (pdata->flags & WIN_COLOR_ORDER) { 1329 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_CCO); 1330 val |= ((pdata->color_order << 24) & LCD_WINCTRL1_CCO); 1331 lcd->window[plane].winctrl1 = val; 1332 } 1333 if (pdata->flags & WIN_PIXEL_ORDER) { 1334 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_PO); 1335 val |= ((pdata->pixel_order << 22) & LCD_WINCTRL1_PO); 1336 lcd->window[plane].winctrl1 = val; 1337 } 1338 if (pdata->flags & WIN_SIZE) { 1339 val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_SZX | 1340 LCD_WINCTRL1_SZY); 1341 val |= (((pdata->xsize << 11) - 1) & LCD_WINCTRL1_SZX); 1342 val |= (((pdata->ysize) - 1) & LCD_WINCTRL1_SZY); 1343 lcd->window[plane].winctrl1 = val; 1344 /* program buffer line width */ 1345 bpp = winbpp(val) / 8; 1346 val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_BX); 1347 val |= (((pdata->xsize * bpp) << 8) & LCD_WINCTRL2_BX); 1348 lcd->window[plane].winctrl2 = val; 1349 } 1350 1351 /* Window control register 2 */ 1352 if (pdata->flags & WIN_COLORKEY_MODE) { 1353 val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_CKMODE); 1354 val |= ((pdata->colorkey_mode << 24) & LCD_WINCTRL2_CKMODE); 1355 lcd->window[plane].winctrl2 = val; 1356 } 1357 if (pdata->flags & WIN_DOUBLE_BUFFER_MODE) { 1358 val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_DBM); 1359 val |= ((pdata->double_buffer_mode << 23) & LCD_WINCTRL2_DBM); 1360 lcd->window[plane].winctrl2 = val; 1361 } 1362 if (pdata->flags & WIN_RAM_ARRAY_MODE) { 1363 val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_RAM); 1364 val |= ((pdata->ram_array_mode << 21) & LCD_WINCTRL2_RAM); 1365 lcd->window[plane].winctrl2 = val; 1366 } 1367 1368 /* Buffer line width programmed with WIN_SIZE */ 1369 1370 if (pdata->flags & WIN_BUFFER_SCALE) { 1371 val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_SCX | 1372 LCD_WINCTRL2_SCY); 1373 val |= ((pdata->xsize << 11) & LCD_WINCTRL2_SCX); 1374 val |= ((pdata->ysize) & LCD_WINCTRL2_SCY); 1375 lcd->window[plane].winctrl2 = val; 1376 } 1377 1378 if (pdata->flags & WIN_ENABLE) { 1379 val = lcd->winenable; 1380 val &= ~(1<<plane); 1381 val |= (pdata->enable & 1) << plane; 1382 lcd->winenable = val; 1383 } 1384 wmb(); /* drain writebuffer */ 1385 } 1386 1387 static void get_window(unsigned int plane, 1388 struct au1200_lcd_window_regs_t *pdata) 1389 { 1390 /* Window control register 0 */ 1391 pdata->xpos = (lcd->window[plane].winctrl0 & LCD_WINCTRL0_OX) >> 21; 1392 pdata->ypos = (lcd->window[plane].winctrl0 & LCD_WINCTRL0_OY) >> 10; 1393 pdata->alpha_color = (lcd->window[plane].winctrl0 & LCD_WINCTRL0_A) >> 2; 1394 pdata->alpha_mode = (lcd->window[plane].winctrl0 & LCD_WINCTRL0_AEN) >> 1; 1395 1396 /* Window control register 1 */ 1397 pdata->priority = (lcd->window[plane].winctrl1& LCD_WINCTRL1_PRI) >> 30; 1398 pdata->channel = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_PIPE) >> 29; 1399 pdata->buffer_format = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_FRM) >> 25; 1400 pdata->color_order = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_CCO) >> 24; 1401 pdata->pixel_order = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_PO) >> 22; 1402 pdata->xsize = ((lcd->window[plane].winctrl1 & LCD_WINCTRL1_SZX) >> 11) + 1; 1403 pdata->ysize = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_SZY) + 1; 1404 1405 /* Window control register 2 */ 1406 pdata->colorkey_mode = (lcd->window[plane].winctrl2 & LCD_WINCTRL2_CKMODE) >> 24; 1407 pdata->double_buffer_mode = (lcd->window[plane].winctrl2 & LCD_WINCTRL2_DBM) >> 23; 1408 pdata->ram_array_mode = (lcd->window[plane].winctrl2 & LCD_WINCTRL2_RAM) >> 21; 1409 1410 pdata->enable = (lcd->winenable >> plane) & 1; 1411 wmb(); /* drain writebuffer */ 1412 } 1413 1414 static int au1200fb_ioctl(struct fb_info *info, unsigned int cmd, 1415 unsigned long arg) 1416 { 1417 struct au1200fb_device *fbdev = info->par; 1418 int plane; 1419 int val; 1420 1421 plane = fbinfo2index(info); 1422 print_dbg("au1200fb: ioctl %d on plane %d\n", cmd, plane); 1423 1424 if (cmd == AU1200_LCD_FB_IOCTL) { 1425 struct au1200_lcd_iodata_t iodata; 1426 1427 if (copy_from_user(&iodata, (void __user *) arg, sizeof(iodata))) 1428 return -EFAULT; 1429 1430 print_dbg("FB IOCTL called\n"); 1431 1432 switch (iodata.subcmd) { 1433 case AU1200_LCD_SET_SCREEN: 1434 print_dbg("AU1200_LCD_SET_SCREEN\n"); 1435 set_global(cmd, &iodata.global); 1436 break; 1437 1438 case AU1200_LCD_GET_SCREEN: 1439 print_dbg("AU1200_LCD_GET_SCREEN\n"); 1440 get_global(cmd, &iodata.global); 1441 break; 1442 1443 case AU1200_LCD_SET_WINDOW: 1444 print_dbg("AU1200_LCD_SET_WINDOW\n"); 1445 set_window(plane, &iodata.window); 1446 break; 1447 1448 case AU1200_LCD_GET_WINDOW: 1449 print_dbg("AU1200_LCD_GET_WINDOW\n"); 1450 get_window(plane, &iodata.window); 1451 break; 1452 1453 case AU1200_LCD_SET_PANEL: 1454 print_dbg("AU1200_LCD_SET_PANEL\n"); 1455 if ((iodata.global.panel_choice >= 0) && 1456 (iodata.global.panel_choice < 1457 NUM_PANELS)) 1458 { 1459 struct panel_settings *newpanel; 1460 panel_index = iodata.global.panel_choice; 1461 newpanel = &known_lcd_panels[panel_index]; 1462 au1200_setpanel(newpanel, fbdev->pd); 1463 } 1464 break; 1465 1466 case AU1200_LCD_GET_PANEL: 1467 print_dbg("AU1200_LCD_GET_PANEL\n"); 1468 iodata.global.panel_choice = panel_index; 1469 break; 1470 1471 default: 1472 return -EINVAL; 1473 } 1474 1475 val = copy_to_user((void __user *) arg, &iodata, sizeof(iodata)); 1476 if (val) { 1477 print_dbg("error: could not copy %d bytes\n", val); 1478 return -EFAULT; 1479 } 1480 } 1481 1482 return 0; 1483 } 1484 1485 1486 static struct fb_ops au1200fb_fb_ops = { 1487 .owner = THIS_MODULE, 1488 .fb_check_var = au1200fb_fb_check_var, 1489 .fb_set_par = au1200fb_fb_set_par, 1490 .fb_setcolreg = au1200fb_fb_setcolreg, 1491 .fb_blank = au1200fb_fb_blank, 1492 .fb_fillrect = sys_fillrect, 1493 .fb_copyarea = sys_copyarea, 1494 .fb_imageblit = sys_imageblit, 1495 .fb_read = fb_sys_read, 1496 .fb_write = fb_sys_write, 1497 .fb_sync = NULL, 1498 .fb_ioctl = au1200fb_ioctl, 1499 .fb_mmap = au1200fb_fb_mmap, 1500 }; 1501 1502 /*-------------------------------------------------------------------------*/ 1503 1504 static irqreturn_t au1200fb_handle_irq(int irq, void* dev_id) 1505 { 1506 /* Nothing to do for now, just clear any pending interrupt */ 1507 lcd->intstatus = lcd->intstatus; 1508 wmb(); /* drain writebuffer */ 1509 1510 return IRQ_HANDLED; 1511 } 1512 1513 /*-------------------------------------------------------------------------*/ 1514 1515 /* AU1200 LCD device probe helpers */ 1516 1517 static int au1200fb_init_fbinfo(struct au1200fb_device *fbdev) 1518 { 1519 struct fb_info *fbi = fbdev->fb_info; 1520 int bpp; 1521 1522 fbi->fbops = &au1200fb_fb_ops; 1523 1524 bpp = winbpp(win->w[fbdev->plane].mode_winctrl1); 1525 1526 /* Copy monitor specs from panel data */ 1527 /* fixme: we're setting up LCD controller windows, so these dont give a 1528 damn as to what the monitor specs are (the panel itself does, but that 1529 isn't done here...so maybe need a generic catchall monitor setting??? */ 1530 memcpy(&fbi->monspecs, &panel->monspecs, sizeof(struct fb_monspecs)); 1531 1532 /* We first try the user mode passed in argument. If that failed, 1533 * or if no one has been specified, we default to the first mode of the 1534 * panel list. Note that after this call, var data will be set */ 1535 if (!fb_find_mode(&fbi->var, 1536 fbi, 1537 NULL, /* drv_info.opt_mode, */ 1538 fbi->monspecs.modedb, 1539 fbi->monspecs.modedb_len, 1540 fbi->monspecs.modedb, 1541 bpp)) { 1542 1543 print_err("Cannot find valid mode for panel %s", panel->name); 1544 return -EFAULT; 1545 } 1546 1547 fbi->pseudo_palette = kcalloc(16, sizeof(u32), GFP_KERNEL); 1548 if (!fbi->pseudo_palette) { 1549 return -ENOMEM; 1550 } 1551 1552 if (fb_alloc_cmap(&fbi->cmap, AU1200_LCD_NBR_PALETTE_ENTRIES, 0) < 0) { 1553 print_err("Fail to allocate colormap (%d entries)", 1554 AU1200_LCD_NBR_PALETTE_ENTRIES); 1555 kfree(fbi->pseudo_palette); 1556 return -EFAULT; 1557 } 1558 1559 strncpy(fbi->fix.id, "AU1200", sizeof(fbi->fix.id)); 1560 fbi->fix.smem_start = fbdev->fb_phys; 1561 fbi->fix.smem_len = fbdev->fb_len; 1562 fbi->fix.type = FB_TYPE_PACKED_PIXELS; 1563 fbi->fix.xpanstep = 0; 1564 fbi->fix.ypanstep = 0; 1565 fbi->fix.mmio_start = 0; 1566 fbi->fix.mmio_len = 0; 1567 fbi->fix.accel = FB_ACCEL_NONE; 1568 1569 fbi->screen_base = (char __iomem *) fbdev->fb_mem; 1570 1571 au1200fb_update_fbinfo(fbi); 1572 1573 return 0; 1574 } 1575 1576 /*-------------------------------------------------------------------------*/ 1577 1578 1579 static int au1200fb_setup(struct au1200fb_platdata *pd) 1580 { 1581 char *options = NULL; 1582 char *this_opt, *endptr; 1583 int num_panels = ARRAY_SIZE(known_lcd_panels); 1584 int panel_idx = -1; 1585 1586 fb_get_options(DRIVER_NAME, &options); 1587 1588 if (!options) 1589 goto out; 1590 1591 while ((this_opt = strsep(&options, ",")) != NULL) { 1592 /* Panel option - can be panel name, 1593 * "bs" for board-switch, or number/index */ 1594 if (!strncmp(this_opt, "panel:", 6)) { 1595 int i; 1596 long int li; 1597 char *endptr; 1598 this_opt += 6; 1599 /* First check for index, which allows 1600 * to short circuit this mess */ 1601 li = simple_strtol(this_opt, &endptr, 0); 1602 if (*endptr == '\0') 1603 panel_idx = (int)li; 1604 else if (strcmp(this_opt, "bs") == 0) 1605 panel_idx = pd->panel_index(); 1606 else { 1607 for (i = 0; i < num_panels; i++) { 1608 if (!strcmp(this_opt, 1609 known_lcd_panels[i].name)) { 1610 panel_idx = i; 1611 break; 1612 } 1613 } 1614 } 1615 if ((panel_idx < 0) || (panel_idx >= num_panels)) 1616 print_warn("Panel %s not supported!", this_opt); 1617 else 1618 panel_index = panel_idx; 1619 1620 } else if (strncmp(this_opt, "nohwcursor", 10) == 0) 1621 nohwcursor = 1; 1622 else if (strncmp(this_opt, "devices:", 8) == 0) { 1623 this_opt += 8; 1624 device_count = simple_strtol(this_opt, &endptr, 0); 1625 if ((device_count < 0) || 1626 (device_count > MAX_DEVICE_COUNT)) 1627 device_count = MAX_DEVICE_COUNT; 1628 } else if (strncmp(this_opt, "wincfg:", 7) == 0) { 1629 this_opt += 7; 1630 window_index = simple_strtol(this_opt, &endptr, 0); 1631 if ((window_index < 0) || 1632 (window_index >= ARRAY_SIZE(windows))) 1633 window_index = DEFAULT_WINDOW_INDEX; 1634 } else if (strncmp(this_opt, "off", 3) == 0) 1635 return 1; 1636 else 1637 print_warn("Unsupported option \"%s\"", this_opt); 1638 } 1639 1640 out: 1641 return 0; 1642 } 1643 1644 /* AU1200 LCD controller device driver */ 1645 static int au1200fb_drv_probe(struct platform_device *dev) 1646 { 1647 struct au1200fb_device *fbdev; 1648 struct au1200fb_platdata *pd; 1649 struct fb_info *fbi = NULL; 1650 unsigned long page; 1651 int bpp, plane, ret, irq; 1652 1653 print_info("" DRIVER_DESC ""); 1654 1655 pd = dev->dev.platform_data; 1656 if (!pd) 1657 return -ENODEV; 1658 1659 /* Setup driver with options */ 1660 if (au1200fb_setup(pd)) 1661 return -ENODEV; 1662 1663 /* Point to the panel selected */ 1664 panel = &known_lcd_panels[panel_index]; 1665 win = &windows[window_index]; 1666 1667 printk(DRIVER_NAME ": Panel %d %s\n", panel_index, panel->name); 1668 printk(DRIVER_NAME ": Win %d %s\n", window_index, win->name); 1669 1670 /* shut gcc up */ 1671 ret = 0; 1672 fbdev = NULL; 1673 1674 for (plane = 0; plane < device_count; ++plane) { 1675 bpp = winbpp(win->w[plane].mode_winctrl1); 1676 if (win->w[plane].xres == 0) 1677 win->w[plane].xres = panel->Xres; 1678 if (win->w[plane].yres == 0) 1679 win->w[plane].yres = panel->Yres; 1680 1681 fbi = framebuffer_alloc(sizeof(struct au1200fb_device), 1682 &dev->dev); 1683 if (!fbi) 1684 goto failed; 1685 1686 _au1200fb_infos[plane] = fbi; 1687 fbdev = fbi->par; 1688 fbdev->fb_info = fbi; 1689 fbdev->pd = pd; 1690 1691 fbdev->plane = plane; 1692 1693 /* Allocate the framebuffer to the maximum screen size */ 1694 fbdev->fb_len = (win->w[plane].xres * win->w[plane].yres * bpp) / 8; 1695 1696 fbdev->fb_mem = dmam_alloc_noncoherent(&dev->dev, 1697 PAGE_ALIGN(fbdev->fb_len), 1698 &fbdev->fb_phys, GFP_KERNEL); 1699 if (!fbdev->fb_mem) { 1700 print_err("fail to allocate frambuffer (size: %dK))", 1701 fbdev->fb_len / 1024); 1702 return -ENOMEM; 1703 } 1704 1705 /* 1706 * Set page reserved so that mmap will work. This is necessary 1707 * since we'll be remapping normal memory. 1708 */ 1709 for (page = (unsigned long)fbdev->fb_phys; 1710 page < PAGE_ALIGN((unsigned long)fbdev->fb_phys + 1711 fbdev->fb_len); 1712 page += PAGE_SIZE) { 1713 SetPageReserved(pfn_to_page(page >> PAGE_SHIFT)); /* LCD DMA is NOT coherent on Au1200 */ 1714 } 1715 print_dbg("Framebuffer memory map at %p", fbdev->fb_mem); 1716 print_dbg("phys=0x%08x, size=%dK", fbdev->fb_phys, fbdev->fb_len / 1024); 1717 1718 /* Init FB data */ 1719 if ((ret = au1200fb_init_fbinfo(fbdev)) < 0) 1720 goto failed; 1721 1722 /* Register new framebuffer */ 1723 ret = register_framebuffer(fbi); 1724 if (ret < 0) { 1725 print_err("cannot register new framebuffer"); 1726 goto failed; 1727 } 1728 1729 au1200fb_fb_set_par(fbi); 1730 1731 #if !defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_LOGO) 1732 if (plane == 0) 1733 if (fb_prepare_logo(fbi, FB_ROTATE_UR)) { 1734 /* Start display and show logo on boot */ 1735 fb_set_cmap(&fbi->cmap, fbi); 1736 fb_show_logo(fbi, FB_ROTATE_UR); 1737 } 1738 #endif 1739 } 1740 1741 /* Now hook interrupt too */ 1742 irq = platform_get_irq(dev, 0); 1743 ret = request_irq(irq, au1200fb_handle_irq, 1744 IRQF_SHARED, "lcd", (void *)dev); 1745 if (ret) { 1746 print_err("fail to request interrupt line %d (err: %d)", 1747 irq, ret); 1748 goto failed; 1749 } 1750 1751 platform_set_drvdata(dev, pd); 1752 1753 /* Kickstart the panel */ 1754 au1200_setpanel(panel, pd); 1755 1756 return 0; 1757 1758 failed: 1759 /* NOTE: This only does the current plane/window that failed; others are still active */ 1760 if (fbi) { 1761 if (fbi->cmap.len != 0) 1762 fb_dealloc_cmap(&fbi->cmap); 1763 kfree(fbi->pseudo_palette); 1764 } 1765 if (plane == 0) 1766 free_irq(AU1200_LCD_INT, (void*)dev); 1767 return ret; 1768 } 1769 1770 static int au1200fb_drv_remove(struct platform_device *dev) 1771 { 1772 struct au1200fb_platdata *pd = platform_get_drvdata(dev); 1773 struct au1200fb_device *fbdev; 1774 struct fb_info *fbi; 1775 int plane; 1776 1777 /* Turn off the panel */ 1778 au1200_setpanel(NULL, pd); 1779 1780 for (plane = 0; plane < device_count; ++plane) { 1781 fbi = _au1200fb_infos[plane]; 1782 fbdev = fbi->par; 1783 1784 /* Clean up all probe data */ 1785 unregister_framebuffer(fbi); 1786 if (fbi->cmap.len != 0) 1787 fb_dealloc_cmap(&fbi->cmap); 1788 kfree(fbi->pseudo_palette); 1789 1790 framebuffer_release(fbi); 1791 _au1200fb_infos[plane] = NULL; 1792 } 1793 1794 free_irq(platform_get_irq(dev, 0), (void *)dev); 1795 1796 return 0; 1797 } 1798 1799 #ifdef CONFIG_PM 1800 static int au1200fb_drv_suspend(struct device *dev) 1801 { 1802 struct au1200fb_platdata *pd = dev_get_drvdata(dev); 1803 au1200_setpanel(NULL, pd); 1804 1805 lcd->outmask = 0; 1806 wmb(); /* drain writebuffer */ 1807 1808 return 0; 1809 } 1810 1811 static int au1200fb_drv_resume(struct device *dev) 1812 { 1813 struct au1200fb_platdata *pd = dev_get_drvdata(dev); 1814 struct fb_info *fbi; 1815 int i; 1816 1817 /* Kickstart the panel */ 1818 au1200_setpanel(panel, pd); 1819 1820 for (i = 0; i < device_count; i++) { 1821 fbi = _au1200fb_infos[i]; 1822 au1200fb_fb_set_par(fbi); 1823 } 1824 1825 return 0; 1826 } 1827 1828 static const struct dev_pm_ops au1200fb_pmops = { 1829 .suspend = au1200fb_drv_suspend, 1830 .resume = au1200fb_drv_resume, 1831 .freeze = au1200fb_drv_suspend, 1832 .thaw = au1200fb_drv_resume, 1833 }; 1834 1835 #define AU1200FB_PMOPS (&au1200fb_pmops) 1836 1837 #else 1838 #define AU1200FB_PMOPS NULL 1839 #endif /* CONFIG_PM */ 1840 1841 static struct platform_driver au1200fb_driver = { 1842 .driver = { 1843 .name = "au1200-lcd", 1844 .pm = AU1200FB_PMOPS, 1845 }, 1846 .probe = au1200fb_drv_probe, 1847 .remove = au1200fb_drv_remove, 1848 }; 1849 module_platform_driver(au1200fb_driver); 1850 1851 MODULE_DESCRIPTION(DRIVER_DESC); 1852 MODULE_LICENSE("GPL"); 1853