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