Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* drivers/video/s1d13xxxfb.c |
| 2 | * |
| 3 | * (c) 2004 Simtec Electronics |
| 4 | * (c) 2005 Thibaut VARENE <varenet@parisc-linux.org> |
| 5 | * |
| 6 | * Driver for Epson S1D13xxx series framebuffer chips |
| 7 | * |
| 8 | * Adapted from |
| 9 | * linux/drivers/video/skeletonfb.c |
| 10 | * linux/drivers/video/epson1355fb.c |
| 11 | * linux/drivers/video/epson/s1d13xxxfb.c (2.4 driver by Epson) |
| 12 | * |
| 13 | * Note, currently only tested on S1D13806 with 16bit CRT. |
| 14 | * As such, this driver might still contain some hardcoded bits relating to |
| 15 | * S1D13806. |
| 16 | * Making it work on other S1D13XXX chips should merely be a matter of adding |
| 17 | * a few switch()s, some missing glue here and there maybe, and split header |
| 18 | * files. |
| 19 | * |
| 20 | * TODO: - handle dual screen display (CRT and LCD at the same time). |
| 21 | * - check_var(), mode change, etc. |
| 22 | * - PM untested. |
| 23 | * - Accelerated interfaces. |
| 24 | * - Probably not SMP safe :) |
| 25 | * |
| 26 | * This file is subject to the terms and conditions of the GNU General Public |
| 27 | * License. See the file COPYING in the main directory of this archive for |
| 28 | * more details. |
| 29 | */ |
| 30 | |
| 31 | #include <linux/config.h> |
| 32 | #include <linux/module.h> |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 33 | #include <linux/platform_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <linux/delay.h> |
| 35 | |
| 36 | #include <linux/types.h> |
| 37 | #include <linux/errno.h> |
| 38 | #include <linux/mm.h> |
| 39 | #include <linux/mman.h> |
| 40 | #include <linux/fb.h> |
| 41 | |
| 42 | #include <asm/io.h> |
| 43 | |
| 44 | #include <video/s1d13xxxfb.h> |
| 45 | |
| 46 | #define PFX "s1d13xxxfb: " |
| 47 | |
| 48 | #if 0 |
| 49 | #define dbg(fmt, args...) do { printk(KERN_INFO fmt, ## args); } while(0) |
| 50 | #else |
| 51 | #define dbg(fmt, args...) do { } while (0) |
| 52 | #endif |
| 53 | |
| 54 | /* |
| 55 | * Here we define the default struct fb_fix_screeninfo |
| 56 | */ |
| 57 | static struct fb_fix_screeninfo __devinitdata s1d13xxxfb_fix = { |
| 58 | .id = S1D_FBID, |
| 59 | .type = FB_TYPE_PACKED_PIXELS, |
| 60 | .visual = FB_VISUAL_PSEUDOCOLOR, |
| 61 | .xpanstep = 0, |
| 62 | .ypanstep = 1, |
| 63 | .ywrapstep = 0, |
| 64 | .accel = FB_ACCEL_NONE, |
| 65 | }; |
| 66 | |
| 67 | static inline u8 |
| 68 | s1d13xxxfb_readreg(struct s1d13xxxfb_par *par, u16 regno) |
| 69 | { |
Hirokazu Takata | 316240f | 2005-07-07 17:59:32 -0700 | [diff] [blame] | 70 | #if defined(CONFIG_PLAT_M32700UT) || defined(CONFIG_PLAT_OPSPUT) || defined(CONFIG_PLAT_MAPPI3) |
| 71 | regno=((regno & 1) ? (regno & ~1L) : (regno + 1)); |
| 72 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | return readb(par->regs + regno); |
| 74 | } |
| 75 | |
| 76 | static inline void |
| 77 | s1d13xxxfb_writereg(struct s1d13xxxfb_par *par, u16 regno, u8 value) |
| 78 | { |
Hirokazu Takata | 316240f | 2005-07-07 17:59:32 -0700 | [diff] [blame] | 79 | #if defined(CONFIG_PLAT_M32700UT) || defined(CONFIG_PLAT_OPSPUT) || defined(CONFIG_PLAT_MAPPI3) |
| 80 | regno=((regno & 1) ? (regno & ~1L) : (regno + 1)); |
| 81 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | writeb(value, par->regs + regno); |
| 83 | } |
| 84 | |
| 85 | static inline void |
| 86 | s1d13xxxfb_runinit(struct s1d13xxxfb_par *par, |
| 87 | const struct s1d13xxxfb_regval *initregs, |
| 88 | const unsigned int size) |
| 89 | { |
| 90 | int i; |
| 91 | |
| 92 | for (i = 0; i < size; i++) { |
| 93 | if ((initregs[i].addr == S1DREG_DELAYOFF) || |
| 94 | (initregs[i].addr == S1DREG_DELAYON)) |
| 95 | mdelay((int)initregs[i].value); |
| 96 | else { |
| 97 | s1d13xxxfb_writereg(par, initregs[i].addr, initregs[i].value); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | /* make sure the hardware can cope with us */ |
| 102 | mdelay(1); |
| 103 | } |
| 104 | |
| 105 | static inline void |
| 106 | lcd_enable(struct s1d13xxxfb_par *par, int enable) |
| 107 | { |
| 108 | u8 mode = s1d13xxxfb_readreg(par, S1DREG_COM_DISP_MODE); |
| 109 | |
| 110 | if (enable) |
| 111 | mode |= 0x01; |
| 112 | else |
| 113 | mode &= ~0x01; |
| 114 | |
| 115 | s1d13xxxfb_writereg(par, S1DREG_COM_DISP_MODE, mode); |
| 116 | } |
| 117 | |
| 118 | static inline void |
| 119 | crt_enable(struct s1d13xxxfb_par *par, int enable) |
| 120 | { |
| 121 | u8 mode = s1d13xxxfb_readreg(par, S1DREG_COM_DISP_MODE); |
| 122 | |
| 123 | if (enable) |
| 124 | mode |= 0x02; |
| 125 | else |
| 126 | mode &= ~0x02; |
| 127 | |
| 128 | s1d13xxxfb_writereg(par, S1DREG_COM_DISP_MODE, mode); |
| 129 | } |
| 130 | |
| 131 | /* framebuffer control routines */ |
| 132 | |
| 133 | static inline void |
| 134 | s1d13xxxfb_setup_pseudocolour(struct fb_info *info) |
| 135 | { |
| 136 | info->fix.visual = FB_VISUAL_PSEUDOCOLOR; |
| 137 | |
| 138 | info->var.red.length = 4; |
| 139 | info->var.green.length = 4; |
| 140 | info->var.blue.length = 4; |
| 141 | } |
| 142 | |
| 143 | static inline void |
| 144 | s1d13xxxfb_setup_truecolour(struct fb_info *info) |
| 145 | { |
| 146 | info->fix.visual = FB_VISUAL_TRUECOLOR; |
| 147 | info->var.bits_per_pixel = 16; |
| 148 | |
| 149 | info->var.red.length = 5; |
| 150 | info->var.red.offset = 11; |
| 151 | |
| 152 | info->var.green.length = 6; |
| 153 | info->var.green.offset = 5; |
| 154 | |
| 155 | info->var.blue.length = 5; |
| 156 | info->var.blue.offset = 0; |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * s1d13xxxfb_set_par - Alters the hardware state. |
| 161 | * @info: frame buffer structure |
| 162 | * |
| 163 | * Using the fb_var_screeninfo in fb_info we set the depth of the |
| 164 | * framebuffer. This function alters the par AND the |
| 165 | * fb_fix_screeninfo stored in fb_info. It doesn't not alter var in |
| 166 | * fb_info since we are using that data. This means we depend on the |
| 167 | * data in var inside fb_info to be supported by the hardware. |
| 168 | * xxxfb_check_var is always called before xxxfb_set_par to ensure this. |
| 169 | * |
| 170 | * XXX TODO: write proper s1d13xxxfb_check_var(), without which that |
| 171 | * function is quite useless. |
| 172 | */ |
| 173 | static int |
| 174 | s1d13xxxfb_set_par(struct fb_info *info) |
| 175 | { |
| 176 | struct s1d13xxxfb_par *s1dfb = info->par; |
| 177 | unsigned int val; |
| 178 | |
| 179 | dbg("s1d13xxxfb_set_par: bpp=%d\n", info->var.bits_per_pixel); |
| 180 | |
| 181 | if ((s1dfb->display & 0x01)) /* LCD */ |
| 182 | val = s1d13xxxfb_readreg(s1dfb, S1DREG_LCD_DISP_MODE); /* read colour control */ |
| 183 | else /* CRT */ |
| 184 | val = s1d13xxxfb_readreg(s1dfb, S1DREG_CRT_DISP_MODE); /* read colour control */ |
| 185 | |
| 186 | val &= ~0x07; |
| 187 | |
| 188 | switch (info->var.bits_per_pixel) { |
| 189 | case 4: |
| 190 | dbg("pseudo colour 4\n"); |
| 191 | s1d13xxxfb_setup_pseudocolour(info); |
| 192 | val |= 2; |
| 193 | break; |
| 194 | case 8: |
| 195 | dbg("pseudo colour 8\n"); |
| 196 | s1d13xxxfb_setup_pseudocolour(info); |
| 197 | val |= 3; |
| 198 | break; |
| 199 | case 16: |
| 200 | dbg("true colour\n"); |
| 201 | s1d13xxxfb_setup_truecolour(info); |
| 202 | val |= 5; |
| 203 | break; |
| 204 | |
| 205 | default: |
| 206 | dbg("bpp not supported!\n"); |
| 207 | return -EINVAL; |
| 208 | } |
| 209 | |
| 210 | dbg("writing %02x to display mode register\n", val); |
| 211 | |
| 212 | if ((s1dfb->display & 0x01)) /* LCD */ |
| 213 | s1d13xxxfb_writereg(s1dfb, S1DREG_LCD_DISP_MODE, val); |
| 214 | else /* CRT */ |
| 215 | s1d13xxxfb_writereg(s1dfb, S1DREG_CRT_DISP_MODE, val); |
| 216 | |
| 217 | info->fix.line_length = info->var.xres * info->var.bits_per_pixel; |
| 218 | info->fix.line_length /= 8; |
| 219 | |
| 220 | dbg("setting line_length to %d\n", info->fix.line_length); |
| 221 | |
| 222 | dbg("done setup\n"); |
| 223 | |
| 224 | return 0; |
| 225 | } |
| 226 | |
| 227 | /** |
| 228 | * s1d13xxxfb_setcolreg - sets a color register. |
| 229 | * @regno: Which register in the CLUT we are programming |
| 230 | * @red: The red value which can be up to 16 bits wide |
| 231 | * @green: The green value which can be up to 16 bits wide |
| 232 | * @blue: The blue value which can be up to 16 bits wide. |
| 233 | * @transp: If supported the alpha value which can be up to 16 bits wide. |
| 234 | * @info: frame buffer info structure |
| 235 | * |
| 236 | * Returns negative errno on error, or zero on success. |
| 237 | */ |
| 238 | static int |
| 239 | s1d13xxxfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue, |
| 240 | u_int transp, struct fb_info *info) |
| 241 | { |
| 242 | struct s1d13xxxfb_par *s1dfb = info->par; |
| 243 | unsigned int pseudo_val; |
| 244 | |
| 245 | if (regno >= S1D_PALETTE_SIZE) |
| 246 | return -EINVAL; |
| 247 | |
| 248 | dbg("s1d13xxxfb_setcolreg: %d: rgb=%d,%d,%d, tr=%d\n", |
| 249 | regno, red, green, blue, transp); |
| 250 | |
| 251 | if (info->var.grayscale) |
| 252 | red = green = blue = (19595*red + 38470*green + 7471*blue) >> 16; |
| 253 | |
| 254 | switch (info->fix.visual) { |
| 255 | case FB_VISUAL_TRUECOLOR: |
| 256 | if (regno >= 16) |
| 257 | return -EINVAL; |
| 258 | |
| 259 | /* deal with creating pseudo-palette entries */ |
| 260 | |
| 261 | pseudo_val = (red >> 11) << info->var.red.offset; |
| 262 | pseudo_val |= (green >> 10) << info->var.green.offset; |
| 263 | pseudo_val |= (blue >> 11) << info->var.blue.offset; |
| 264 | |
| 265 | dbg("s1d13xxxfb_setcolreg: pseudo %d, val %08x\n", |
| 266 | regno, pseudo_val); |
| 267 | |
Hirokazu Takata | 316240f | 2005-07-07 17:59:32 -0700 | [diff] [blame] | 268 | #if defined(CONFIG_PLAT_MAPPI) |
| 269 | ((u32 *)info->pseudo_palette)[regno] = cpu_to_le16(pseudo_val); |
| 270 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | ((u32 *)info->pseudo_palette)[regno] = pseudo_val; |
Hirokazu Takata | 316240f | 2005-07-07 17:59:32 -0700 | [diff] [blame] | 272 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | |
| 274 | break; |
| 275 | case FB_VISUAL_PSEUDOCOLOR: |
| 276 | s1d13xxxfb_writereg(s1dfb, S1DREG_LKUP_ADDR, regno); |
| 277 | s1d13xxxfb_writereg(s1dfb, S1DREG_LKUP_DATA, red); |
| 278 | s1d13xxxfb_writereg(s1dfb, S1DREG_LKUP_DATA, green); |
| 279 | s1d13xxxfb_writereg(s1dfb, S1DREG_LKUP_DATA, blue); |
| 280 | |
| 281 | break; |
| 282 | default: |
| 283 | return -ENOSYS; |
| 284 | } |
| 285 | |
| 286 | dbg("s1d13xxxfb_setcolreg: done\n"); |
| 287 | |
| 288 | return 0; |
| 289 | } |
| 290 | |
| 291 | /** |
| 292 | * s1d13xxxfb_blank - blanks the display. |
| 293 | * @blank_mode: the blank mode we want. |
| 294 | * @info: frame buffer structure that represents a single frame buffer |
| 295 | * |
| 296 | * Blank the screen if blank_mode != 0, else unblank. Return 0 if |
| 297 | * blanking succeeded, != 0 if un-/blanking failed due to e.g. a |
| 298 | * video mode which doesn't support it. Implements VESA suspend |
| 299 | * and powerdown modes on hardware that supports disabling hsync/vsync: |
| 300 | * blank_mode == 2: suspend vsync |
| 301 | * blank_mode == 3: suspend hsync |
| 302 | * blank_mode == 4: powerdown |
| 303 | * |
| 304 | * Returns negative errno on error, or zero on success. |
| 305 | */ |
| 306 | static int |
| 307 | s1d13xxxfb_blank(int blank_mode, struct fb_info *info) |
| 308 | { |
| 309 | struct s1d13xxxfb_par *par = info->par; |
| 310 | |
| 311 | dbg("s1d13xxxfb_blank: blank=%d, info=%p\n", blank_mode, info); |
| 312 | |
| 313 | switch (blank_mode) { |
| 314 | case FB_BLANK_UNBLANK: |
| 315 | case FB_BLANK_NORMAL: |
| 316 | if ((par->display & 0x01) != 0) |
| 317 | lcd_enable(par, 1); |
| 318 | if ((par->display & 0x02) != 0) |
| 319 | crt_enable(par, 1); |
| 320 | break; |
| 321 | case FB_BLANK_VSYNC_SUSPEND: |
| 322 | case FB_BLANK_HSYNC_SUSPEND: |
| 323 | break; |
| 324 | case FB_BLANK_POWERDOWN: |
| 325 | lcd_enable(par, 0); |
| 326 | crt_enable(par, 0); |
| 327 | break; |
| 328 | default: |
| 329 | return -EINVAL; |
| 330 | } |
| 331 | |
| 332 | /* let fbcon do a soft blank for us */ |
| 333 | return ((blank_mode == FB_BLANK_NORMAL) ? 1 : 0); |
| 334 | } |
| 335 | |
| 336 | /** |
| 337 | * s1d13xxxfb_pan_display - Pans the display. |
| 338 | * @var: frame buffer variable screen structure |
| 339 | * @info: frame buffer structure that represents a single frame buffer |
| 340 | * |
| 341 | * Pan (or wrap, depending on the `vmode' field) the display using the |
| 342 | * `yoffset' field of the `var' structure (`xoffset' not yet supported). |
| 343 | * If the values don't fit, return -EINVAL. |
| 344 | * |
| 345 | * Returns negative errno on error, or zero on success. |
| 346 | */ |
| 347 | static int |
| 348 | s1d13xxxfb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info) |
| 349 | { |
| 350 | struct s1d13xxxfb_par *par = info->par; |
| 351 | u32 start; |
| 352 | |
| 353 | if (var->xoffset != 0) /* not yet ... */ |
| 354 | return -EINVAL; |
| 355 | |
| 356 | if (var->yoffset + info->var.yres > info->var.yres_virtual) |
| 357 | return -EINVAL; |
| 358 | |
| 359 | start = (info->fix.line_length >> 1) * var->yoffset; |
| 360 | |
| 361 | if ((par->display & 0x01)) { |
| 362 | /* LCD */ |
| 363 | s1d13xxxfb_writereg(par, S1DREG_LCD_DISP_START0, (start & 0xff)); |
| 364 | s1d13xxxfb_writereg(par, S1DREG_LCD_DISP_START1, ((start >> 8) & 0xff)); |
| 365 | s1d13xxxfb_writereg(par, S1DREG_LCD_DISP_START2, ((start >> 16) & 0x0f)); |
| 366 | } else { |
| 367 | /* CRT */ |
| 368 | s1d13xxxfb_writereg(par, S1DREG_CRT_DISP_START0, (start & 0xff)); |
| 369 | s1d13xxxfb_writereg(par, S1DREG_CRT_DISP_START1, ((start >> 8) & 0xff)); |
| 370 | s1d13xxxfb_writereg(par, S1DREG_CRT_DISP_START2, ((start >> 16) & 0x0f)); |
| 371 | } |
| 372 | |
| 373 | return 0; |
| 374 | } |
| 375 | |
| 376 | |
| 377 | /* framebuffer information structures */ |
| 378 | |
| 379 | static struct fb_ops s1d13xxxfb_fbops = { |
| 380 | .owner = THIS_MODULE, |
| 381 | .fb_set_par = s1d13xxxfb_set_par, |
| 382 | .fb_setcolreg = s1d13xxxfb_setcolreg, |
| 383 | .fb_blank = s1d13xxxfb_blank, |
| 384 | |
| 385 | .fb_pan_display = s1d13xxxfb_pan_display, |
| 386 | |
| 387 | /* to be replaced by any acceleration we can */ |
| 388 | .fb_fillrect = cfb_fillrect, |
| 389 | .fb_copyarea = cfb_copyarea, |
| 390 | .fb_imageblit = cfb_imageblit, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | }; |
| 392 | |
| 393 | static int s1d13xxxfb_width_tab[2][4] __devinitdata = { |
| 394 | {4, 8, 16, -1}, |
| 395 | {9, 12, 18, -1}, |
| 396 | }; |
| 397 | |
| 398 | /** |
| 399 | * s1d13xxxfb_fetch_hw_state - Configure the framebuffer according to |
| 400 | * hardware setup. |
| 401 | * @info: frame buffer structure |
| 402 | * |
| 403 | * We setup the framebuffer structures according to the current |
| 404 | * hardware setup. On some machines, the BIOS will have filled |
| 405 | * the chip registers with such info, on others, these values will |
| 406 | * have been written in some init procedure. In any case, the |
| 407 | * software values needs to match the hardware ones. This is what |
| 408 | * this function ensures. |
| 409 | * |
| 410 | * Note: some of the hardcoded values here might need some love to |
| 411 | * work on various chips, and might need to no longer be hardcoded. |
| 412 | */ |
| 413 | static void __devinit |
| 414 | s1d13xxxfb_fetch_hw_state(struct fb_info *info) |
| 415 | { |
| 416 | struct fb_var_screeninfo *var = &info->var; |
| 417 | struct fb_fix_screeninfo *fix = &info->fix; |
| 418 | struct s1d13xxxfb_par *par = info->par; |
| 419 | u8 panel, display; |
| 420 | u16 offset; |
| 421 | u32 xres, yres; |
| 422 | u32 xres_virtual, yres_virtual; |
| 423 | int bpp, lcd_bpp; |
| 424 | int is_color, is_dual, is_tft; |
| 425 | int lcd_enabled, crt_enabled; |
| 426 | |
| 427 | fix->type = FB_TYPE_PACKED_PIXELS; |
| 428 | |
| 429 | /* general info */ |
| 430 | par->display = s1d13xxxfb_readreg(par, S1DREG_COM_DISP_MODE); |
| 431 | crt_enabled = (par->display & 0x02) != 0; |
| 432 | lcd_enabled = (par->display & 0x01) != 0; |
| 433 | |
| 434 | if (lcd_enabled && crt_enabled) |
| 435 | printk(KERN_WARNING PFX "Warning: LCD and CRT detected, using LCD\n"); |
| 436 | |
| 437 | if (lcd_enabled) |
| 438 | display = s1d13xxxfb_readreg(par, S1DREG_LCD_DISP_MODE); |
| 439 | else /* CRT */ |
| 440 | display = s1d13xxxfb_readreg(par, S1DREG_CRT_DISP_MODE); |
| 441 | |
| 442 | bpp = display & 0x07; |
| 443 | |
| 444 | switch (bpp) { |
| 445 | case 2: /* 4 bpp */ |
| 446 | case 3: /* 8 bpp */ |
| 447 | var->bits_per_pixel = 8; |
| 448 | var->red.offset = var->green.offset = var->blue.offset = 0; |
| 449 | var->red.length = var->green.length = var->blue.length = 8; |
| 450 | break; |
| 451 | case 5: /* 16 bpp */ |
| 452 | s1d13xxxfb_setup_truecolour(info); |
| 453 | break; |
| 454 | default: |
| 455 | dbg("bpp: %i\n", bpp); |
| 456 | } |
| 457 | fb_alloc_cmap(&info->cmap, 256, 0); |
| 458 | |
| 459 | /* LCD info */ |
| 460 | panel = s1d13xxxfb_readreg(par, S1DREG_PANEL_TYPE); |
| 461 | is_color = (panel & 0x04) != 0; |
| 462 | is_dual = (panel & 0x02) != 0; |
| 463 | is_tft = (panel & 0x01) != 0; |
| 464 | lcd_bpp = s1d13xxxfb_width_tab[is_tft][(panel >> 4) & 3]; |
| 465 | |
| 466 | if (lcd_enabled) { |
| 467 | xres = (s1d13xxxfb_readreg(par, S1DREG_LCD_DISP_HWIDTH) + 1) * 8; |
| 468 | yres = (s1d13xxxfb_readreg(par, S1DREG_LCD_DISP_VHEIGHT0) + |
| 469 | ((s1d13xxxfb_readreg(par, S1DREG_LCD_DISP_VHEIGHT1) & 0x03) << 8) + 1); |
| 470 | |
| 471 | offset = (s1d13xxxfb_readreg(par, S1DREG_LCD_MEM_OFF0) + |
| 472 | ((s1d13xxxfb_readreg(par, S1DREG_LCD_MEM_OFF1) & 0x7) << 8)); |
| 473 | } else { /* crt */ |
| 474 | xres = (s1d13xxxfb_readreg(par, S1DREG_CRT_DISP_HWIDTH) + 1) * 8; |
| 475 | yres = (s1d13xxxfb_readreg(par, S1DREG_CRT_DISP_VHEIGHT0) + |
| 476 | ((s1d13xxxfb_readreg(par, S1DREG_CRT_DISP_VHEIGHT1) & 0x03) << 8) + 1); |
| 477 | |
| 478 | offset = (s1d13xxxfb_readreg(par, S1DREG_CRT_MEM_OFF0) + |
| 479 | ((s1d13xxxfb_readreg(par, S1DREG_CRT_MEM_OFF1) & 0x7) << 8)); |
| 480 | } |
| 481 | xres_virtual = offset * 16 / var->bits_per_pixel; |
| 482 | yres_virtual = fix->smem_len / (offset * 2); |
| 483 | |
| 484 | var->xres = xres; |
| 485 | var->yres = yres; |
| 486 | var->xres_virtual = xres_virtual; |
| 487 | var->yres_virtual = yres_virtual; |
| 488 | var->xoffset = var->yoffset = 0; |
| 489 | |
| 490 | fix->line_length = offset * 2; |
| 491 | |
| 492 | var->grayscale = !is_color; |
| 493 | |
| 494 | var->activate = FB_ACTIVATE_NOW; |
| 495 | |
| 496 | dbg(PFX "bpp=%d, lcd_bpp=%d, " |
| 497 | "crt_enabled=%d, lcd_enabled=%d\n", |
| 498 | var->bits_per_pixel, lcd_bpp, crt_enabled, lcd_enabled); |
| 499 | dbg(PFX "xres=%d, yres=%d, vxres=%d, vyres=%d " |
| 500 | "is_color=%d, is_dual=%d, is_tft=%d\n", |
| 501 | xres, yres, xres_virtual, yres_virtual, is_color, is_dual, is_tft); |
| 502 | } |
| 503 | |
| 504 | |
Andrew Morton | 27f931d | 2005-06-21 17:16:55 -0700 | [diff] [blame] | 505 | static int |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 506 | s1d13xxxfb_remove(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 508 | struct fb_info *info = platform_get_drvdata(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | struct s1d13xxxfb_par *par = NULL; |
| 510 | |
| 511 | if (info) { |
| 512 | par = info->par; |
| 513 | if (par && par->regs) { |
| 514 | /* disable output & enable powersave */ |
| 515 | s1d13xxxfb_writereg(par, S1DREG_COM_DISP_MODE, 0x00); |
| 516 | s1d13xxxfb_writereg(par, S1DREG_PS_CNF, 0x11); |
| 517 | iounmap(par->regs); |
| 518 | } |
| 519 | |
| 520 | fb_dealloc_cmap(&info->cmap); |
| 521 | |
| 522 | if (info->screen_base) |
| 523 | iounmap(info->screen_base); |
| 524 | |
| 525 | framebuffer_release(info); |
| 526 | } |
| 527 | |
| 528 | release_mem_region(pdev->resource[0].start, |
| 529 | pdev->resource[0].end - pdev->resource[0].start +1); |
| 530 | release_mem_region(pdev->resource[1].start, |
| 531 | pdev->resource[1].end - pdev->resource[1].start +1); |
| 532 | return 0; |
| 533 | } |
| 534 | |
| 535 | static int __devinit |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 536 | s1d13xxxfb_probe(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | struct s1d13xxxfb_par *default_par; |
| 539 | struct fb_info *info; |
| 540 | struct s1d13xxxfb_pdata *pdata = NULL; |
| 541 | int ret = 0; |
| 542 | u8 revision; |
| 543 | |
| 544 | dbg("probe called: device is %p\n", dev); |
| 545 | |
| 546 | printk(KERN_INFO "Epson S1D13XXX FB Driver\n"); |
| 547 | |
| 548 | /* enable platform-dependent hardware glue, if any */ |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 549 | if (pdev->dev.platform_data) |
| 550 | pdata = pdev->dev.platform_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | |
| 552 | if (pdata && pdata->platform_init_video) |
| 553 | pdata->platform_init_video(); |
| 554 | |
| 555 | |
| 556 | if (pdev->num_resources != 2) { |
| 557 | dev_err(&pdev->dev, "invalid num_resources: %i\n", |
| 558 | pdev->num_resources); |
| 559 | ret = -ENODEV; |
| 560 | goto bail; |
| 561 | } |
| 562 | |
| 563 | /* resource[0] is VRAM, resource[1] is registers */ |
| 564 | if (pdev->resource[0].flags != IORESOURCE_MEM |
| 565 | || pdev->resource[1].flags != IORESOURCE_MEM) { |
| 566 | dev_err(&pdev->dev, "invalid resource type\n"); |
| 567 | ret = -ENODEV; |
| 568 | goto bail; |
| 569 | } |
| 570 | |
| 571 | if (!request_mem_region(pdev->resource[0].start, |
| 572 | pdev->resource[0].end - pdev->resource[0].start +1, "s1d13xxxfb mem")) { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 573 | dev_dbg(&pdev->dev, "request_mem_region failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | ret = -EBUSY; |
| 575 | goto bail; |
| 576 | } |
| 577 | |
| 578 | if (!request_mem_region(pdev->resource[1].start, |
| 579 | pdev->resource[1].end - pdev->resource[1].start +1, "s1d13xxxfb regs")) { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 580 | dev_dbg(&pdev->dev, "request_mem_region failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | ret = -EBUSY; |
| 582 | goto bail; |
| 583 | } |
| 584 | |
| 585 | info = framebuffer_alloc(sizeof(struct s1d13xxxfb_par) + sizeof(u32) * 256, &pdev->dev); |
| 586 | if (!info) { |
| 587 | ret = -ENOMEM; |
| 588 | goto bail; |
| 589 | } |
| 590 | |
Antonino A. Daplas | 98365f5 | 2006-03-11 03:27:23 -0800 | [diff] [blame] | 591 | platform_set_drvdata(pdev, info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | default_par = info->par; |
| 593 | default_par->regs = ioremap_nocache(pdev->resource[1].start, |
| 594 | pdev->resource[1].end - pdev->resource[1].start +1); |
| 595 | if (!default_par->regs) { |
| 596 | printk(KERN_ERR PFX "unable to map registers\n"); |
| 597 | ret = -ENOMEM; |
| 598 | goto bail; |
| 599 | } |
| 600 | info->pseudo_palette = default_par->pseudo_palette; |
| 601 | |
| 602 | info->screen_base = ioremap_nocache(pdev->resource[0].start, |
| 603 | pdev->resource[0].end - pdev->resource[0].start +1); |
| 604 | |
| 605 | if (!info->screen_base) { |
| 606 | printk(KERN_ERR PFX "unable to map framebuffer\n"); |
| 607 | ret = -ENOMEM; |
| 608 | goto bail; |
| 609 | } |
| 610 | |
| 611 | revision = s1d13xxxfb_readreg(default_par, S1DREG_REV_CODE); |
| 612 | if ((revision >> 2) != S1D_CHIP_REV) { |
| 613 | printk(KERN_INFO PFX "chip not found: %i\n", (revision >> 2)); |
| 614 | ret = -ENODEV; |
| 615 | goto bail; |
| 616 | } |
| 617 | |
| 618 | info->fix = s1d13xxxfb_fix; |
| 619 | info->fix.mmio_start = pdev->resource[1].start; |
| 620 | info->fix.mmio_len = pdev->resource[1].end - pdev->resource[1].start +1; |
| 621 | info->fix.smem_start = pdev->resource[0].start; |
| 622 | info->fix.smem_len = pdev->resource[0].end - pdev->resource[0].start +1; |
| 623 | |
| 624 | printk(KERN_INFO PFX "regs mapped at 0x%p, fb %d KiB mapped at 0x%p\n", |
| 625 | default_par->regs, info->fix.smem_len / 1024, info->screen_base); |
| 626 | |
| 627 | info->par = default_par; |
| 628 | info->fbops = &s1d13xxxfb_fbops; |
| 629 | info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN; |
| 630 | |
| 631 | /* perform "manual" chip initialization, if needed */ |
| 632 | if (pdata && pdata->initregs) |
| 633 | s1d13xxxfb_runinit(info->par, pdata->initregs, pdata->initregssize); |
| 634 | |
| 635 | s1d13xxxfb_fetch_hw_state(info); |
| 636 | |
| 637 | if (register_framebuffer(info) < 0) { |
| 638 | ret = -EINVAL; |
| 639 | goto bail; |
| 640 | } |
| 641 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | printk(KERN_INFO "fb%d: %s frame buffer device\n", |
| 643 | info->node, info->fix.id); |
| 644 | |
| 645 | return 0; |
| 646 | |
| 647 | bail: |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 648 | s1d13xxxfb_remove(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | return ret; |
| 650 | |
| 651 | } |
| 652 | |
| 653 | #ifdef CONFIG_PM |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 654 | static int s1d13xxxfb_suspend(struct platform_device *dev, pm_message_t state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 656 | struct fb_info *info = platform_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | struct s1d13xxxfb_par *s1dfb = info->par; |
| 658 | struct s1d13xxxfb_pdata *pdata = NULL; |
| 659 | |
| 660 | /* disable display */ |
| 661 | lcd_enable(s1dfb, 0); |
| 662 | crt_enable(s1dfb, 0); |
| 663 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 664 | if (dev->dev.platform_data) |
| 665 | pdata = dev->dev.platform_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | |
| 667 | #if 0 |
| 668 | if (!s1dfb->disp_save) |
| 669 | s1dfb->disp_save = kmalloc(info->fix.smem_len, GFP_KERNEL); |
| 670 | |
| 671 | if (!s1dfb->disp_save) { |
| 672 | printk(KERN_ERR PFX "no memory to save screen"); |
| 673 | return -ENOMEM; |
| 674 | } |
| 675 | |
| 676 | memcpy_fromio(s1dfb->disp_save, info->screen_base, info->fix.smem_len); |
| 677 | #else |
| 678 | s1dfb->disp_save = NULL; |
| 679 | #endif |
| 680 | |
| 681 | if (!s1dfb->regs_save) |
| 682 | s1dfb->regs_save = kmalloc(info->fix.mmio_len, GFP_KERNEL); |
| 683 | |
| 684 | if (!s1dfb->regs_save) { |
| 685 | printk(KERN_ERR PFX "no memory to save registers"); |
| 686 | return -ENOMEM; |
| 687 | } |
| 688 | |
| 689 | /* backup all registers */ |
| 690 | memcpy_fromio(s1dfb->regs_save, s1dfb->regs, info->fix.mmio_len); |
| 691 | |
| 692 | /* now activate power save mode */ |
| 693 | s1d13xxxfb_writereg(s1dfb, S1DREG_PS_CNF, 0x11); |
| 694 | |
| 695 | if (pdata && pdata->platform_suspend_video) |
| 696 | return pdata->platform_suspend_video(); |
| 697 | else |
| 698 | return 0; |
| 699 | } |
| 700 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 701 | static int s1d13xxxfb_resume(struct platform_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 703 | struct fb_info *info = platform_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | struct s1d13xxxfb_par *s1dfb = info->par; |
| 705 | struct s1d13xxxfb_pdata *pdata = NULL; |
| 706 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | /* awaken the chip */ |
| 708 | s1d13xxxfb_writereg(s1dfb, S1DREG_PS_CNF, 0x10); |
| 709 | |
| 710 | /* do not let go until SDRAM "wakes up" */ |
| 711 | while ((s1d13xxxfb_readreg(s1dfb, S1DREG_PS_STATUS) & 0x01)) |
| 712 | udelay(10); |
| 713 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 714 | if (dev->dev.platform_data) |
| 715 | pdata = dev->dev.platform_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | |
| 717 | if (s1dfb->regs_save) { |
| 718 | /* will write RO regs, *should* get away with it :) */ |
| 719 | memcpy_toio(s1dfb->regs, s1dfb->regs_save, info->fix.mmio_len); |
| 720 | kfree(s1dfb->regs_save); |
| 721 | } |
| 722 | |
| 723 | if (s1dfb->disp_save) { |
| 724 | memcpy_toio(info->screen_base, s1dfb->disp_save, |
| 725 | info->fix.smem_len); |
| 726 | kfree(s1dfb->disp_save); /* XXX kmalloc()'d when? */ |
| 727 | } |
| 728 | |
| 729 | if ((s1dfb->display & 0x01) != 0) |
| 730 | lcd_enable(s1dfb, 1); |
| 731 | if ((s1dfb->display & 0x02) != 0) |
| 732 | crt_enable(s1dfb, 1); |
| 733 | |
| 734 | if (pdata && pdata->platform_resume_video) |
| 735 | return pdata->platform_resume_video(); |
| 736 | else |
| 737 | return 0; |
| 738 | } |
| 739 | #endif /* CONFIG_PM */ |
| 740 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 741 | static struct platform_driver s1d13xxxfb_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | .probe = s1d13xxxfb_probe, |
| 743 | .remove = s1d13xxxfb_remove, |
| 744 | #ifdef CONFIG_PM |
| 745 | .suspend = s1d13xxxfb_suspend, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 746 | .resume = s1d13xxxfb_resume, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | #endif |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 748 | .driver = { |
| 749 | .name = S1D_DEVICENAME, |
| 750 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | }; |
| 752 | |
| 753 | |
| 754 | static int __init |
| 755 | s1d13xxxfb_init(void) |
| 756 | { |
| 757 | if (fb_get_options("s1d13xxxfb", NULL)) |
| 758 | return -ENODEV; |
| 759 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 760 | return platform_driver_register(&s1d13xxxfb_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | |
| 764 | static void __exit |
| 765 | s1d13xxxfb_exit(void) |
| 766 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 767 | platform_driver_unregister(&s1d13xxxfb_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | } |
| 769 | |
| 770 | module_init(s1d13xxxfb_init); |
| 771 | module_exit(s1d13xxxfb_exit); |
| 772 | |
| 773 | |
| 774 | MODULE_LICENSE("GPL"); |
| 775 | MODULE_DESCRIPTION("Framebuffer driver for S1D13xxx devices"); |
| 776 | MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>, Thibaut VARENE <varenet@parisc-linux.org>"); |