Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/video/epson1355fb.c -- Epson S1D13505 frame buffer for 2.5. |
| 3 | * |
| 4 | * Epson Research S1D13505 Embedded RAMDAC LCD/CRT Controller |
| 5 | * (previously known as SED1355) |
| 6 | * |
| 7 | * Cf. http://www.erd.epson.com/vdc/html/S1D13505.html |
| 8 | * |
| 9 | * |
| 10 | * Copyright (C) Hewlett-Packard Company. All rights reserved. |
| 11 | * |
| 12 | * Written by Christopher Hoover <ch@hpl.hp.com> |
| 13 | * |
| 14 | * Adapted from: |
| 15 | * |
| 16 | * linux/drivers/video/skeletonfb.c |
| 17 | * Modified to new api Jan 2001 by James Simmons (jsimmons@infradead.org) |
| 18 | * Created 28 Dec 1997 by Geert Uytterhoeven |
| 19 | * |
| 20 | * linux/drivers/video/epson1355fb.c (2.4 driver) |
| 21 | * Copyright (C) 2000 Philipp Rumpf <prumpf@tux.org> |
| 22 | * |
| 23 | * This file is subject to the terms and conditions of the GNU General Public |
| 24 | * License. See the file COPYING in the main directory of this archive for |
| 25 | * more details. |
| 26 | * |
| 27 | * |
| 28 | * Noteworthy Issues |
| 29 | * ----------------- |
| 30 | * |
| 31 | * This driver is complicated by the fact that this is a 16-bit chip |
| 32 | * and, on at least one platform (ceiva), we can only do 16-bit reads |
| 33 | * and writes to the framebuffer. We hide this from user space |
| 34 | * except in the case of mmap(). |
| 35 | * |
| 36 | * |
| 37 | * To Do |
| 38 | * ----- |
| 39 | * |
| 40 | * - Test 8-bit pseudocolor mode |
| 41 | * - Allow setting bpp, virtual resolution |
| 42 | * - Implement horizontal panning |
| 43 | * - (maybe) Implement hardware cursor |
| 44 | */ |
| 45 | |
| 46 | #include <linux/module.h> |
| 47 | #include <linux/kernel.h> |
| 48 | #include <linux/errno.h> |
| 49 | #include <linux/string.h> |
| 50 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #include <linux/slab.h> |
| 52 | #include <linux/delay.h> |
| 53 | #include <linux/fb.h> |
| 54 | #include <linux/init.h> |
| 55 | #include <linux/ioport.h> |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 56 | #include <linux/platform_device.h> |
| 57 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | #include <asm/types.h> |
| 59 | #include <asm/io.h> |
Krzysztof Helt | 84902b7 | 2007-10-16 01:29:04 -0700 | [diff] [blame] | 60 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
| 62 | #include <video/epson1355.h> |
| 63 | |
| 64 | struct epson1355_par { |
| 65 | unsigned long reg_addr; |
Antonino A. Daplas | 4a1b927 | 2007-07-17 04:05:36 -0700 | [diff] [blame] | 66 | u32 pseudo_palette[16]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | /* ------------------------------------------------------------------------- */ |
| 70 | |
Paul Mundt | 1a3f288 | 2007-07-17 04:05:48 -0700 | [diff] [blame] | 71 | #if defined(CONFIG_ARM) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
| 73 | # ifdef CONFIG_ARCH_CEIVA |
| 74 | # include <asm/arch/hardware.h> |
| 75 | # define EPSON1355FB_BASE_PHYS (CEIVA_PHYS_SED1355) |
| 76 | # endif |
| 77 | |
| 78 | static inline u8 epson1355_read_reg(struct epson1355_par *par, int index) |
| 79 | { |
| 80 | return __raw_readb(par->reg_addr + index); |
| 81 | } |
| 82 | |
| 83 | static inline void epson1355_write_reg(struct epson1355_par *par, u8 data, int index) |
| 84 | { |
| 85 | __raw_writeb(data, par->reg_addr + index); |
| 86 | } |
| 87 | |
| 88 | #else |
| 89 | # error "no architecture-specific epson1355_{read,write}_reg" |
| 90 | #endif |
| 91 | |
| 92 | #ifndef EPSON1355FB_BASE_PHYS |
| 93 | # error "EPSON1355FB_BASE_PHYS is not defined" |
| 94 | #endif |
| 95 | |
| 96 | #define EPSON1355FB_REGS_OFS (0) |
| 97 | #define EPSON1355FB_REGS_PHYS (EPSON1355FB_BASE_PHYS + EPSON1355FB_REGS_OFS) |
| 98 | #define EPSON1355FB_REGS_LEN (64) |
| 99 | |
| 100 | #define EPSON1355FB_FB_OFS (0x00200000) |
| 101 | #define EPSON1355FB_FB_PHYS (EPSON1355FB_BASE_PHYS + EPSON1355FB_FB_OFS) |
| 102 | #define EPSON1355FB_FB_LEN (2 * 1024 * 1024) |
| 103 | |
| 104 | /* ------------------------------------------------------------------------- */ |
| 105 | |
| 106 | static inline u16 epson1355_read_reg16(struct epson1355_par *par, int index) |
| 107 | { |
| 108 | u8 lo = epson1355_read_reg(par, index); |
| 109 | u8 hi = epson1355_read_reg(par, index + 1); |
| 110 | |
| 111 | return (hi << 8) | lo; |
| 112 | } |
| 113 | |
| 114 | static inline void epson1355_write_reg16(struct epson1355_par *par, u16 data, int index) |
| 115 | { |
| 116 | u8 lo = data & 0xff; |
| 117 | u8 hi = (data >> 8) & 0xff; |
| 118 | |
| 119 | epson1355_write_reg(par, lo, index); |
| 120 | epson1355_write_reg(par, hi, index + 1); |
| 121 | } |
| 122 | |
| 123 | static inline u32 epson1355_read_reg20(struct epson1355_par *par, int index) |
| 124 | { |
| 125 | u8 b0 = epson1355_read_reg(par, index); |
| 126 | u8 b1 = epson1355_read_reg(par, index + 1); |
| 127 | u8 b2 = epson1355_read_reg(par, index + 2); |
| 128 | |
| 129 | return (b2 & 0x0f) << 16 | (b1 << 8) | b0; |
| 130 | } |
| 131 | |
| 132 | static inline void epson1355_write_reg20(struct epson1355_par *par, u32 data, int index) |
| 133 | { |
| 134 | u8 b0 = data & 0xff; |
| 135 | u8 b1 = (data >> 8) & 0xff; |
| 136 | u8 b2 = (data >> 16) & 0x0f; |
| 137 | |
| 138 | epson1355_write_reg(par, b0, index); |
| 139 | epson1355_write_reg(par, b1, index + 1); |
| 140 | epson1355_write_reg(par, b2, index + 2); |
| 141 | } |
| 142 | |
| 143 | /* ------------------------------------------------------------------------- */ |
| 144 | |
| 145 | static void set_lut(struct epson1355_par *par, u8 index, u8 r, u8 g, u8 b) |
| 146 | { |
| 147 | epson1355_write_reg(par, index, REG_LUT_ADDR); |
| 148 | epson1355_write_reg(par, r, REG_LUT_DATA); |
| 149 | epson1355_write_reg(par, g, REG_LUT_DATA); |
| 150 | epson1355_write_reg(par, b, REG_LUT_DATA); |
| 151 | } |
| 152 | |
| 153 | |
| 154 | /** |
| 155 | * epson1355fb_setcolreg - sets a color register. |
| 156 | * @regno: Which register in the CLUT we are programming |
| 157 | * @red: The red value which can be up to 16 bits wide |
| 158 | * @green: The green value which can be up to 16 bits wide |
| 159 | * @blue: The blue value which can be up to 16 bits wide. |
| 160 | * @transp: If supported the alpha value which can be up to 16 bits wide. |
| 161 | * @info: frame buffer info structure |
| 162 | * |
| 163 | * Returns negative errno on error, or zero on success. |
| 164 | */ |
| 165 | static int epson1355fb_setcolreg(unsigned regno, unsigned r, unsigned g, |
| 166 | unsigned b, unsigned transp, |
| 167 | struct fb_info *info) |
| 168 | { |
| 169 | struct epson1355_par *par = info->par; |
| 170 | |
| 171 | if (info->var.grayscale) |
| 172 | r = g = b = (19595 * r + 38470 * g + 7471 * b) >> 16; |
| 173 | |
| 174 | switch (info->fix.visual) { |
| 175 | case FB_VISUAL_TRUECOLOR: |
| 176 | if (regno >= 16) |
| 177 | return -EINVAL; |
| 178 | |
| 179 | ((u32 *) info->pseudo_palette)[regno] = |
| 180 | (r & 0xf800) | (g & 0xfc00) >> 5 | (b & 0xf800) >> 11; |
| 181 | |
| 182 | break; |
| 183 | case FB_VISUAL_PSEUDOCOLOR: |
| 184 | if (regno >= 256) |
| 185 | return -EINVAL; |
| 186 | |
| 187 | set_lut(par, regno, r >> 8, g >> 8, b >> 8); |
| 188 | |
| 189 | break; |
| 190 | default: |
| 191 | return -ENOSYS; |
| 192 | } |
| 193 | return 0; |
| 194 | } |
| 195 | |
| 196 | /* ------------------------------------------------------------------------- */ |
| 197 | |
| 198 | /** |
| 199 | * epson1355fb_pan_display - Pans the display. |
| 200 | * @var: frame buffer variable screen structure |
| 201 | * @info: frame buffer structure that represents a single frame buffer |
| 202 | * |
| 203 | * Pan (or wrap, depending on the `vmode' field) the display using the |
| 204 | * `xoffset' and `yoffset' fields of the `var' structure. |
| 205 | * If the values don't fit, return -EINVAL. |
| 206 | * |
| 207 | * Returns negative errno on error, or zero on success. |
| 208 | */ |
| 209 | static int epson1355fb_pan_display(struct fb_var_screeninfo *var, |
| 210 | struct fb_info *info) |
| 211 | { |
| 212 | struct epson1355_par *par = info->par; |
| 213 | u32 start; |
| 214 | |
| 215 | if (var->xoffset != 0) /* not yet ... */ |
| 216 | return -EINVAL; |
| 217 | |
| 218 | if (var->yoffset + info->var.yres > info->var.yres_virtual) |
| 219 | return -EINVAL; |
| 220 | |
| 221 | start = (info->fix.line_length >> 1) * var->yoffset; |
| 222 | |
| 223 | epson1355_write_reg20(par, start, REG_SCRN1_DISP_START_ADDR0); |
| 224 | |
| 225 | return 0; |
| 226 | } |
| 227 | |
| 228 | /* ------------------------------------------------------------------------- */ |
| 229 | |
| 230 | static void lcd_enable(struct epson1355_par *par, int enable) |
| 231 | { |
| 232 | u8 mode = epson1355_read_reg(par, REG_DISPLAY_MODE); |
| 233 | |
| 234 | if (enable) |
| 235 | mode |= 1; |
| 236 | else |
| 237 | mode &= ~1; |
| 238 | |
| 239 | epson1355_write_reg(par, mode, REG_DISPLAY_MODE); |
| 240 | } |
| 241 | |
| 242 | #if defined(CONFIG_ARCH_CEIVA) |
| 243 | static void backlight_enable(int enable) |
| 244 | { |
| 245 | /* ### this should be protected by a spinlock ... */ |
| 246 | u8 pddr = clps_readb(PDDR); |
| 247 | if (enable) |
| 248 | pddr |= (1 << 5); |
| 249 | else |
| 250 | pddr &= ~(1 << 5); |
| 251 | clps_writeb(pddr, PDDR); |
| 252 | } |
| 253 | #else |
| 254 | static void backlight_enable(int enable) |
| 255 | { |
| 256 | } |
| 257 | #endif |
| 258 | |
| 259 | |
| 260 | /** |
| 261 | * epson1355fb_blank - blanks the display. |
| 262 | * @blank_mode: the blank mode we want. |
| 263 | * @info: frame buffer structure that represents a single frame buffer |
| 264 | * |
| 265 | * Blank the screen if blank_mode != 0, else unblank. Return 0 if |
| 266 | * blanking succeeded, != 0 if un-/blanking failed due to e.g. a |
| 267 | * video mode which doesn't support it. Implements VESA suspend |
| 268 | * and powerdown modes on hardware that supports disabling hsync/vsync: |
| 269 | * blank_mode == 2: suspend vsync |
| 270 | * blank_mode == 3: suspend hsync |
| 271 | * blank_mode == 4: powerdown |
| 272 | * |
| 273 | * Returns negative errno on error, or zero on success. |
| 274 | * |
| 275 | */ |
| 276 | static int epson1355fb_blank(int blank_mode, struct fb_info *info) |
| 277 | { |
| 278 | struct epson1355_par *par = info->par; |
| 279 | |
| 280 | switch (blank_mode) { |
Paul Mundt | 1a3f288 | 2007-07-17 04:05:48 -0700 | [diff] [blame] | 281 | case FB_BLANK_UNBLANK: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | case FB_BLANK_NORMAL: |
| 283 | lcd_enable(par, 1); |
| 284 | backlight_enable(1); |
| 285 | break; |
| 286 | case FB_BLANK_VSYNC_SUSPEND: |
| 287 | case FB_BLANK_HSYNC_SUSPEND: |
| 288 | backlight_enable(0); |
| 289 | break; |
| 290 | case FB_BLANK_POWERDOWN: |
| 291 | backlight_enable(0); |
| 292 | lcd_enable(par, 0); |
| 293 | break; |
| 294 | default: |
| 295 | return -EINVAL; |
| 296 | } |
| 297 | |
| 298 | /* let fbcon do a soft blank for us */ |
| 299 | return (blank_mode == FB_BLANK_NORMAL) ? 1 : 0; |
| 300 | } |
| 301 | |
| 302 | /* ------------------------------------------------------------------------- */ |
| 303 | |
| 304 | /* |
| 305 | * We can't use the cfb generic routines, as we have to limit |
| 306 | * ourselves to 16-bit or 8-bit loads and stores to this 16-bit |
| 307 | * chip. |
| 308 | */ |
| 309 | |
| 310 | static inline void epson1355fb_fb_writel(unsigned long v, unsigned long *a) |
| 311 | { |
| 312 | u16 *p = (u16 *) a; |
| 313 | u16 l = v & 0xffff; |
| 314 | u16 h = v >> 16; |
| 315 | |
| 316 | fb_writew(l, p); |
| 317 | fb_writew(h, p + 1); |
| 318 | } |
| 319 | |
| 320 | static inline unsigned long epson1355fb_fb_readl(const unsigned long *a) |
| 321 | { |
| 322 | const u16 *p = (u16 *) a; |
| 323 | u16 l = fb_readw(p); |
| 324 | u16 h = fb_readw(p + 1); |
| 325 | |
| 326 | return (h << 16) | l; |
| 327 | } |
| 328 | |
| 329 | #define FB_READL epson1355fb_fb_readl |
| 330 | #define FB_WRITEL epson1355fb_fb_writel |
| 331 | |
| 332 | /* ------------------------------------------------------------------------- */ |
| 333 | |
| 334 | static inline unsigned long copy_from_user16(void *to, const void *from, |
| 335 | unsigned long n) |
| 336 | { |
| 337 | u16 *dst = (u16 *) to; |
| 338 | u16 *src = (u16 *) from; |
| 339 | |
| 340 | if (!access_ok(VERIFY_READ, from, n)) |
| 341 | return n; |
| 342 | |
| 343 | while (n > 1) { |
| 344 | u16 v; |
| 345 | if (__get_user(v, src)) |
| 346 | return n; |
| 347 | |
| 348 | fb_writew(v, dst); |
| 349 | |
| 350 | src++, dst++; |
| 351 | n -= 2; |
| 352 | } |
| 353 | |
| 354 | if (n) { |
| 355 | u8 v; |
| 356 | |
| 357 | if (__get_user(v, ((u8 *) src))) |
| 358 | return n; |
| 359 | |
| 360 | fb_writeb(v, dst); |
| 361 | } |
| 362 | return 0; |
| 363 | } |
| 364 | |
| 365 | static inline unsigned long copy_to_user16(void *to, const void *from, |
| 366 | unsigned long n) |
| 367 | { |
| 368 | u16 *dst = (u16 *) to; |
| 369 | u16 *src = (u16 *) from; |
| 370 | |
| 371 | if (!access_ok(VERIFY_WRITE, to, n)) |
| 372 | return n; |
| 373 | |
| 374 | while (n > 1) { |
| 375 | u16 v = fb_readw(src); |
| 376 | |
| 377 | if (__put_user(v, dst)) |
| 378 | return n; |
| 379 | |
| 380 | src++, dst++; |
| 381 | n -= 2; |
| 382 | } |
| 383 | |
| 384 | if (n) { |
| 385 | u8 v = fb_readb(src); |
| 386 | |
| 387 | if (__put_user(v, ((u8 *) dst))) |
| 388 | return n; |
| 389 | } |
| 390 | return 0; |
| 391 | } |
| 392 | |
| 393 | |
| 394 | static ssize_t |
Antonino A. Daplas | 3f9b088 | 2007-05-08 00:39:02 -0700 | [diff] [blame] | 395 | epson1355fb_read(struct fb_info *info, char *buf, size_t count, loff_t * ppos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | unsigned long p = *ppos; |
| 398 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | if (p >= info->fix.smem_len) |
| 400 | return 0; |
| 401 | if (count >= info->fix.smem_len) |
| 402 | count = info->fix.smem_len; |
| 403 | if (count + p > info->fix.smem_len) |
| 404 | count = info->fix.smem_len - p; |
| 405 | |
| 406 | if (count) { |
| 407 | char *base_addr; |
| 408 | |
| 409 | base_addr = info->screen_base; |
| 410 | count -= copy_to_user16(buf, base_addr + p, count); |
| 411 | if (!count) |
| 412 | return -EFAULT; |
| 413 | *ppos += count; |
| 414 | } |
| 415 | return count; |
| 416 | } |
| 417 | |
| 418 | static ssize_t |
Antonino A. Daplas | 3f9b088 | 2007-05-08 00:39:02 -0700 | [diff] [blame] | 419 | epson1355fb_write(struct fb_info *info, const char *buf, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | size_t count, loff_t * ppos) |
| 421 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | unsigned long p = *ppos; |
| 423 | int err; |
| 424 | |
| 425 | /* from fbmem.c except for our own copy_*_user */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | if (p > info->fix.smem_len) |
| 427 | return -ENOSPC; |
| 428 | if (count >= info->fix.smem_len) |
| 429 | count = info->fix.smem_len; |
| 430 | err = 0; |
| 431 | if (count + p > info->fix.smem_len) { |
| 432 | count = info->fix.smem_len - p; |
| 433 | err = -ENOSPC; |
| 434 | } |
| 435 | |
| 436 | if (count) { |
| 437 | char *base_addr; |
| 438 | |
| 439 | base_addr = info->screen_base; |
| 440 | count -= copy_from_user16(base_addr + p, buf, count); |
| 441 | *ppos += count; |
| 442 | err = -EFAULT; |
| 443 | } |
| 444 | if (count) |
| 445 | return count; |
| 446 | return err; |
| 447 | } |
| 448 | |
| 449 | /* ------------------------------------------------------------------------- */ |
| 450 | |
| 451 | static struct fb_ops epson1355fb_fbops = { |
| 452 | .owner = THIS_MODULE, |
| 453 | .fb_setcolreg = epson1355fb_setcolreg, |
| 454 | .fb_pan_display = epson1355fb_pan_display, |
| 455 | .fb_blank = epson1355fb_blank, |
| 456 | .fb_fillrect = cfb_fillrect, |
| 457 | .fb_copyarea = cfb_copyarea, |
| 458 | .fb_imageblit = cfb_imageblit, |
| 459 | .fb_read = epson1355fb_read, |
| 460 | .fb_write = epson1355fb_write, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | }; |
| 462 | |
| 463 | /* ------------------------------------------------------------------------- */ |
| 464 | |
| 465 | static __init unsigned int get_fb_size(struct fb_info *info) |
| 466 | { |
| 467 | unsigned int size = 2 * 1024 * 1024; |
| 468 | char *p = info->screen_base; |
| 469 | |
| 470 | /* the 512k framebuffer is aliased at start + 0x80000 * n */ |
| 471 | fb_writeb(1, p); |
| 472 | fb_writeb(0, p + 0x80000); |
| 473 | if (!fb_readb(p)) |
| 474 | size = 512 * 1024; |
| 475 | |
| 476 | fb_writeb(0, p); |
| 477 | |
| 478 | return size; |
| 479 | } |
| 480 | |
| 481 | static int epson1355_width_tab[2][4] __initdata = |
| 482 | { {4, 8, 16, -1}, {9, 12, 16, -1} }; |
| 483 | static int epson1355_bpp_tab[8] __initdata = { 1, 2, 4, 8, 15, 16 }; |
| 484 | |
| 485 | static void __init fetch_hw_state(struct fb_info *info, struct epson1355_par *par) |
| 486 | { |
| 487 | struct fb_var_screeninfo *var = &info->var; |
| 488 | struct fb_fix_screeninfo *fix = &info->fix; |
| 489 | u8 panel, display; |
| 490 | u16 offset; |
| 491 | u32 xres, yres; |
| 492 | u32 xres_virtual, yres_virtual; |
| 493 | int bpp, lcd_bpp; |
| 494 | int is_color, is_dual, is_tft; |
| 495 | int lcd_enabled, crt_enabled; |
| 496 | |
| 497 | fix->type = FB_TYPE_PACKED_PIXELS; |
| 498 | |
| 499 | display = epson1355_read_reg(par, REG_DISPLAY_MODE); |
| 500 | bpp = epson1355_bpp_tab[(display >> 2) & 7]; |
| 501 | |
| 502 | switch (bpp) { |
| 503 | case 8: |
| 504 | fix->visual = FB_VISUAL_PSEUDOCOLOR; |
| 505 | var->bits_per_pixel = 8; |
| 506 | var->red.offset = var->green.offset = var->blue.offset = 0; |
| 507 | var->red.length = var->green.length = var->blue.length = 8; |
| 508 | break; |
| 509 | case 16: |
| 510 | /* 5-6-5 RGB */ |
| 511 | fix->visual = FB_VISUAL_TRUECOLOR; |
| 512 | var->bits_per_pixel = 16; |
| 513 | var->red.offset = 11; |
| 514 | var->red.length = 5; |
| 515 | var->green.offset = 5; |
| 516 | var->green.length = 6; |
| 517 | var->blue.offset = 0; |
| 518 | var->blue.length = 5; |
| 519 | break; |
| 520 | default: |
| 521 | BUG(); |
| 522 | } |
| 523 | fb_alloc_cmap(&(info->cmap), 256, 0); |
| 524 | |
| 525 | panel = epson1355_read_reg(par, REG_PANEL_TYPE); |
| 526 | is_color = (panel & 0x04) != 0; |
| 527 | is_dual = (panel & 0x02) != 0; |
| 528 | is_tft = (panel & 0x01) != 0; |
| 529 | crt_enabled = (display & 0x02) != 0; |
| 530 | lcd_enabled = (display & 0x01) != 0; |
| 531 | lcd_bpp = epson1355_width_tab[is_tft][(panel >> 4) & 3]; |
| 532 | |
| 533 | xres = (epson1355_read_reg(par, REG_HORZ_DISP_WIDTH) + 1) * 8; |
| 534 | yres = (epson1355_read_reg16(par, REG_VERT_DISP_HEIGHT0) + 1) * |
| 535 | ((is_dual && !crt_enabled) ? 2 : 1); |
| 536 | offset = epson1355_read_reg16(par, REG_MEM_ADDR_OFFSET0) & 0x7ff; |
| 537 | xres_virtual = offset * 16 / bpp; |
| 538 | yres_virtual = fix->smem_len / (offset * 2); |
| 539 | |
| 540 | var->xres = xres; |
| 541 | var->yres = yres; |
| 542 | var->xres_virtual = xres_virtual; |
| 543 | var->yres_virtual = yres_virtual; |
| 544 | var->xoffset = var->yoffset = 0; |
| 545 | |
| 546 | fix->line_length = offset * 2; |
| 547 | |
| 548 | fix->xpanstep = 0; /* no pan yet */ |
| 549 | fix->ypanstep = 1; |
| 550 | fix->ywrapstep = 0; |
| 551 | fix->accel = FB_ACCEL_NONE; |
| 552 | |
| 553 | var->grayscale = !is_color; |
| 554 | |
| 555 | #ifdef DEBUG |
| 556 | printk(KERN_INFO |
| 557 | "epson1355fb: xres=%d, yres=%d, " |
| 558 | "is_color=%d, is_dual=%d, is_tft=%d\n", |
| 559 | xres, yres, is_color, is_dual, is_tft); |
| 560 | printk(KERN_INFO |
| 561 | "epson1355fb: bpp=%d, lcd_bpp=%d, " |
| 562 | "crt_enabled=%d, lcd_enabled=%d\n", |
| 563 | bpp, lcd_bpp, crt_enabled, lcd_enabled); |
| 564 | #endif |
| 565 | } |
| 566 | |
| 567 | |
| 568 | static void clearfb16(struct fb_info *info) |
| 569 | { |
| 570 | u16 *dst = (u16 *) info->screen_base; |
| 571 | unsigned long n = info->fix.smem_len; |
| 572 | |
| 573 | while (n > 1) { |
| 574 | fb_writew(0, dst); |
| 575 | dst++, n -= 2; |
| 576 | } |
| 577 | |
| 578 | if (n) |
| 579 | fb_writeb(0, dst); |
| 580 | } |
| 581 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 582 | static int epson1355fb_remove(struct platform_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 584 | struct fb_info *info = platform_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | struct epson1355_par *par = info->par; |
| 586 | |
| 587 | backlight_enable(0); |
| 588 | if (par) { |
| 589 | lcd_enable(par, 0); |
| 590 | if (par && par->reg_addr) |
| 591 | iounmap((void *) par->reg_addr); |
| 592 | } |
| 593 | |
| 594 | if (info) { |
| 595 | fb_dealloc_cmap(&info->cmap); |
| 596 | if (info->screen_base) |
| 597 | iounmap(info->screen_base); |
| 598 | framebuffer_release(info); |
| 599 | } |
| 600 | release_mem_region(EPSON1355FB_FB_PHYS, EPSON1355FB_FB_LEN); |
| 601 | release_mem_region(EPSON1355FB_REGS_PHYS, EPSON1355FB_REGS_LEN); |
| 602 | return 0; |
| 603 | } |
| 604 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 605 | int __init epson1355fb_probe(struct platform_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | struct epson1355_par *default_par; |
| 608 | struct fb_info *info; |
| 609 | u8 revision; |
| 610 | int rc = 0; |
| 611 | |
| 612 | if (!request_mem_region(EPSON1355FB_REGS_PHYS, EPSON1355FB_REGS_LEN, "S1D13505 registers")) { |
| 613 | printk(KERN_ERR "epson1355fb: unable to reserve " |
| 614 | "registers at 0x%0x\n", EPSON1355FB_REGS_PHYS); |
| 615 | rc = -EBUSY; |
| 616 | goto bail; |
| 617 | } |
| 618 | |
| 619 | if (!request_mem_region(EPSON1355FB_FB_PHYS, EPSON1355FB_FB_LEN, |
| 620 | "S1D13505 framebuffer")) { |
| 621 | printk(KERN_ERR "epson1355fb: unable to reserve " |
| 622 | "framebuffer at 0x%0x\n", EPSON1355FB_FB_PHYS); |
| 623 | rc = -EBUSY; |
| 624 | goto bail; |
| 625 | } |
| 626 | |
Antonino A. Daplas | 4a1b927 | 2007-07-17 04:05:36 -0700 | [diff] [blame] | 627 | info = framebuffer_alloc(sizeof(struct epson1355_par), &dev->dev); |
Roland Stigge | 19f3d3a | 2007-05-08 00:38:31 -0700 | [diff] [blame] | 628 | if (!info) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | rc = -ENOMEM; |
| 630 | goto bail; |
Roland Stigge | 19f3d3a | 2007-05-08 00:38:31 -0700 | [diff] [blame] | 631 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | |
| 633 | default_par = info->par; |
| 634 | default_par->reg_addr = (unsigned long) ioremap(EPSON1355FB_REGS_PHYS, EPSON1355FB_REGS_LEN); |
| 635 | if (!default_par->reg_addr) { |
| 636 | printk(KERN_ERR "epson1355fb: unable to map registers\n"); |
| 637 | rc = -ENOMEM; |
| 638 | goto bail; |
| 639 | } |
Antonino A. Daplas | 4a1b927 | 2007-07-17 04:05:36 -0700 | [diff] [blame] | 640 | info->pseudo_palette = default_par->pseudo_palette; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | |
| 642 | info->screen_base = ioremap(EPSON1355FB_FB_PHYS, EPSON1355FB_FB_LEN); |
| 643 | if (!info->screen_base) { |
| 644 | printk(KERN_ERR "epson1355fb: unable to map framebuffer\n"); |
| 645 | rc = -ENOMEM; |
| 646 | goto bail; |
| 647 | } |
| 648 | |
| 649 | revision = epson1355_read_reg(default_par, REG_REVISION_CODE); |
| 650 | if ((revision >> 2) != 3) { |
| 651 | printk(KERN_INFO "epson1355fb: epson1355 not found\n"); |
| 652 | rc = -ENODEV; |
| 653 | goto bail; |
| 654 | } |
| 655 | |
| 656 | info->fix.mmio_start = EPSON1355FB_REGS_PHYS; |
| 657 | info->fix.mmio_len = EPSON1355FB_REGS_LEN; |
| 658 | info->fix.smem_start = EPSON1355FB_FB_PHYS; |
| 659 | info->fix.smem_len = get_fb_size(info); |
| 660 | |
| 661 | printk(KERN_INFO "epson1355fb: regs mapped at 0x%lx, fb %d KiB mapped at 0x%p\n", |
| 662 | default_par->reg_addr, info->fix.smem_len / 1024, info->screen_base); |
| 663 | |
| 664 | strcpy(info->fix.id, "S1D13505"); |
| 665 | info->par = default_par; |
| 666 | info->fbops = &epson1355fb_fbops; |
| 667 | info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN; |
| 668 | |
| 669 | /* we expect the boot loader to have initialized the chip |
| 670 | with appropriate parameters from which we can determinte |
| 671 | the flavor of lcd panel attached */ |
| 672 | fetch_hw_state(info, default_par); |
| 673 | |
| 674 | /* turn this puppy on ... */ |
| 675 | clearfb16(info); |
| 676 | backlight_enable(1); |
| 677 | lcd_enable(default_par, 1); |
| 678 | |
| 679 | if (register_framebuffer(info) < 0) { |
| 680 | rc = -EINVAL; |
| 681 | goto bail; |
| 682 | } |
| 683 | /* |
| 684 | * Our driver data. |
| 685 | */ |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 686 | platform_set_drvdata(dev, info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | |
| 688 | printk(KERN_INFO "fb%d: %s frame buffer device\n", |
| 689 | info->node, info->fix.id); |
| 690 | |
| 691 | return 0; |
| 692 | |
| 693 | bail: |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 694 | epson1355fb_remove(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | return rc; |
| 696 | } |
| 697 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 698 | static struct platform_driver epson1355fb_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | .probe = epson1355fb_probe, |
| 700 | .remove = epson1355fb_remove, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 701 | .driver = { |
| 702 | .name = "epson1355fb", |
| 703 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | }; |
| 705 | |
Antonino A. Daplas | 673681c | 2006-06-26 00:26:33 -0700 | [diff] [blame] | 706 | static struct platform_device *epson1355fb_device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | |
| 708 | int __init epson1355fb_init(void) |
| 709 | { |
| 710 | int ret = 0; |
| 711 | |
| 712 | if (fb_get_options("epson1355fb", NULL)) |
| 713 | return -ENODEV; |
| 714 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 715 | ret = platform_driver_register(&epson1355fb_driver); |
Antonino A. Daplas | 673681c | 2006-06-26 00:26:33 -0700 | [diff] [blame] | 716 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | if (!ret) { |
Antonino A. Daplas | 673681c | 2006-06-26 00:26:33 -0700 | [diff] [blame] | 718 | epson1355fb_device = platform_device_alloc("epson1355fb", 0); |
| 719 | |
| 720 | if (epson1355fb_device) |
| 721 | ret = platform_device_add(epson1355fb_device); |
| 722 | else |
| 723 | ret = -ENOMEM; |
| 724 | |
| 725 | if (ret) { |
| 726 | platform_device_put(epson1355fb_device); |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 727 | platform_driver_unregister(&epson1355fb_driver); |
Antonino A. Daplas | 673681c | 2006-06-26 00:26:33 -0700 | [diff] [blame] | 728 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | } |
Antonino A. Daplas | 673681c | 2006-06-26 00:26:33 -0700 | [diff] [blame] | 730 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | return ret; |
| 732 | } |
| 733 | |
| 734 | module_init(epson1355fb_init); |
| 735 | |
| 736 | #ifdef MODULE |
| 737 | static void __exit epson1355fb_exit(void) |
| 738 | { |
Antonino A. Daplas | 673681c | 2006-06-26 00:26:33 -0700 | [diff] [blame] | 739 | platform_device_unregister(epson1355fb_device); |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 740 | platform_driver_unregister(&epson1355fb_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | } |
| 742 | |
| 743 | /* ------------------------------------------------------------------------- */ |
| 744 | |
| 745 | module_exit(epson1355fb_exit); |
| 746 | #endif |
| 747 | |
| 748 | MODULE_AUTHOR("Christopher Hoover <ch@hpl.hp.com>"); |
| 749 | MODULE_DESCRIPTION("Framebuffer driver for Epson S1D13505"); |
| 750 | MODULE_LICENSE("GPL"); |