Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/video/s3c2410fb.c |
| 3 | * Copyright (c) Arnaud Patard, Ben Dooks |
| 4 | * |
| 5 | * This file is subject to the terms and conditions of the GNU General Public |
| 6 | * License. See the file COPYING in the main directory of this archive for |
| 7 | * more details. |
| 8 | * |
| 9 | * S3C2410 LCD Controller Frame Buffer Driver |
| 10 | * based on skeletonfb.c, sa1100fb.c and others |
| 11 | * |
| 12 | * ChangeLog |
| 13 | * 2005-04-07: Arnaud Patard <arnaud.patard@rtp-net.org> |
| 14 | * - u32 state -> pm_message_t state |
| 15 | * - S3C2410_{VA,SZ}_LCD -> S3C24XX |
| 16 | * |
| 17 | * 2005-03-15: Arnaud Patard <arnaud.patard@rtp-net.org> |
| 18 | * - Removed the ioctl |
| 19 | * - use readl/writel instead of __raw_writel/__raw_readl |
| 20 | * |
| 21 | * 2004-12-04: Arnaud Patard <arnaud.patard@rtp-net.org> |
| 22 | * - Added the possibility to set on or off the |
| 23 | * debugging mesaages |
| 24 | * - Replaced 0 and 1 by on or off when reading the |
| 25 | * /sys files |
| 26 | * |
| 27 | * 2005-03-23: Ben Dooks <ben-linux@fluff.org> |
| 28 | * - added non 16bpp modes |
| 29 | * - updated platform information for range of x/y/bpp |
| 30 | * - add code to ensure palette is written correctly |
| 31 | * - add pixel clock divisor control |
| 32 | * |
| 33 | * 2004-11-11: Arnaud Patard <arnaud.patard@rtp-net.org> |
Krzysztof Helt | b083194 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 34 | * - Removed the use of currcon as it no more exist |
| 35 | * - Added LCD power sysfs interface |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 36 | * |
| 37 | * 2004-11-03: Ben Dooks <ben-linux@fluff.org> |
| 38 | * - minor cleanups |
| 39 | * - add suspend/resume support |
| 40 | * - s3c2410fb_setcolreg() not valid in >8bpp modes |
| 41 | * - removed last CONFIG_FB_S3C2410_FIXED |
| 42 | * - ensure lcd controller stopped before cleanup |
| 43 | * - added sysfs interface for backlight power |
| 44 | * - added mask for gpio configuration |
| 45 | * - ensured IRQs disabled during GPIO configuration |
| 46 | * - disable TPAL before enabling video |
| 47 | * |
| 48 | * 2004-09-20: Arnaud Patard <arnaud.patard@rtp-net.org> |
| 49 | * - Suppress command line options |
| 50 | * |
| 51 | * 2004-09-15: Arnaud Patard <arnaud.patard@rtp-net.org> |
Krzysztof Helt | b083194 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 52 | * - code cleanup |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 53 | * |
| 54 | * 2004-09-07: Arnaud Patard <arnaud.patard@rtp-net.org> |
Krzysztof Helt | b083194 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 55 | * - Renamed from h1940fb.c to s3c2410fb.c |
| 56 | * - Add support for different devices |
| 57 | * - Backlight support |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 58 | * |
| 59 | * 2004-09-05: Herbert Pötzl <herbert@13thfloor.at> |
| 60 | * - added clock (de-)allocation code |
| 61 | * - added fixem fbmem option |
| 62 | * |
| 63 | * 2004-07-27: Arnaud Patard <arnaud.patard@rtp-net.org> |
| 64 | * - code cleanup |
| 65 | * - added a forgotten return in h1940fb_init |
| 66 | * |
| 67 | * 2004-07-19: Herbert Pötzl <herbert@13thfloor.at> |
| 68 | * - code cleanup and extended debugging |
| 69 | * |
| 70 | * 2004-07-15: Arnaud Patard <arnaud.patard@rtp-net.org> |
| 71 | * - First version |
| 72 | */ |
| 73 | |
| 74 | #include <linux/module.h> |
| 75 | #include <linux/kernel.h> |
| 76 | #include <linux/errno.h> |
| 77 | #include <linux/string.h> |
| 78 | #include <linux/mm.h> |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 79 | #include <linux/slab.h> |
| 80 | #include <linux/delay.h> |
| 81 | #include <linux/fb.h> |
| 82 | #include <linux/init.h> |
| 83 | #include <linux/dma-mapping.h> |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 84 | #include <linux/interrupt.h> |
| 85 | #include <linux/workqueue.h> |
| 86 | #include <linux/wait.h> |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 87 | #include <linux/platform_device.h> |
Russell King | f8ce254 | 2006-01-07 16:15:52 +0000 | [diff] [blame] | 88 | #include <linux/clk.h> |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 89 | |
| 90 | #include <asm/io.h> |
| 91 | #include <asm/uaccess.h> |
| 92 | #include <asm/div64.h> |
| 93 | |
| 94 | #include <asm/mach/map.h> |
| 95 | #include <asm/arch/regs-lcd.h> |
| 96 | #include <asm/arch/regs-gpio.h> |
| 97 | #include <asm/arch/fb.h> |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 98 | |
| 99 | #ifdef CONFIG_PM |
| 100 | #include <linux/pm.h> |
| 101 | #endif |
| 102 | |
| 103 | #include "s3c2410fb.h" |
| 104 | |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 105 | static struct s3c2410fb_mach_info *mach_info; |
| 106 | |
| 107 | /* Debugging stuff */ |
| 108 | #ifdef CONFIG_FB_S3C2410_DEBUG |
Krzysztof Helt | b083194 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 109 | static int debug = 1; |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 110 | #else |
Krzysztof Helt | b083194 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 111 | static int debug = 0; |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 112 | #endif |
| 113 | |
| 114 | #define dprintk(msg...) if (debug) { printk(KERN_DEBUG "s3c2410fb: " msg); } |
| 115 | |
| 116 | /* useful functions */ |
| 117 | |
| 118 | /* s3c2410fb_set_lcdaddr |
| 119 | * |
| 120 | * initialise lcd controller address pointers |
Krzysztof Helt | b083194 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 121 | */ |
Krzysztof Helt | 110c1fa | 2007-10-16 01:28:55 -0700 | [diff] [blame] | 122 | static void s3c2410fb_set_lcdaddr(struct fb_info *info) |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 123 | { |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 124 | unsigned long saddr1, saddr2, saddr3; |
Krzysztof Helt | 110c1fa | 2007-10-16 01:28:55 -0700 | [diff] [blame] | 125 | int line_length = info->var.xres * info->var.bits_per_pixel; |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 126 | |
Krzysztof Helt | 110c1fa | 2007-10-16 01:28:55 -0700 | [diff] [blame] | 127 | saddr1 = info->fix.smem_start >> 1; |
| 128 | saddr2 = info->fix.smem_start; |
| 129 | saddr2 += (line_length * info->var.yres) / 8; |
Krzysztof Helt | b083194 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 130 | saddr2 >>= 1; |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 131 | |
Krzysztof Helt | b083194 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 132 | saddr3 = S3C2410_OFFSIZE(0) | |
| 133 | S3C2410_PAGEWIDTH((line_length / 16) & 0x3ff); |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 134 | |
| 135 | dprintk("LCDSADDR1 = 0x%08lx\n", saddr1); |
| 136 | dprintk("LCDSADDR2 = 0x%08lx\n", saddr2); |
| 137 | dprintk("LCDSADDR3 = 0x%08lx\n", saddr3); |
| 138 | |
| 139 | writel(saddr1, S3C2410_LCDSADDR1); |
| 140 | writel(saddr2, S3C2410_LCDSADDR2); |
| 141 | writel(saddr3, S3C2410_LCDSADDR3); |
| 142 | } |
| 143 | |
| 144 | /* s3c2410fb_calc_pixclk() |
| 145 | * |
| 146 | * calculate divisor for clk->pixclk |
Krzysztof Helt | b083194 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 147 | */ |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 148 | static unsigned int s3c2410fb_calc_pixclk(struct s3c2410fb_info *fbi, |
| 149 | unsigned long pixclk) |
| 150 | { |
| 151 | unsigned long clk = clk_get_rate(fbi->clk); |
| 152 | unsigned long long div; |
| 153 | |
| 154 | /* pixclk is in picoseoncds, our clock is in Hz |
| 155 | * |
| 156 | * Hz -> picoseconds is / 10^-12 |
| 157 | */ |
| 158 | |
| 159 | div = (unsigned long long)clk * pixclk; |
Krzysztof Helt | b083194 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 160 | do_div(div, 1000000UL); |
| 161 | do_div(div, 1000000UL); |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 162 | |
| 163 | dprintk("pixclk %ld, divisor is %ld\n", pixclk, (long)div); |
| 164 | return div; |
| 165 | } |
| 166 | |
| 167 | /* |
| 168 | * s3c2410fb_check_var(): |
| 169 | * Get the video params out of 'var'. If a value doesn't fit, round it up, |
| 170 | * if it's too big, return -EINVAL. |
| 171 | * |
| 172 | */ |
| 173 | static int s3c2410fb_check_var(struct fb_var_screeninfo *var, |
| 174 | struct fb_info *info) |
| 175 | { |
| 176 | struct s3c2410fb_info *fbi = info->par; |
Krzysztof Helt | 09fe75f | 2007-10-16 01:28:56 -0700 | [diff] [blame] | 177 | struct s3c2410fb_mach_info *mach_info = fbi->mach_info; |
| 178 | struct s3c2410fb_display *display = NULL; |
| 179 | unsigned i; |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 180 | |
| 181 | dprintk("check_var(var=%p, info=%p)\n", var, info); |
| 182 | |
| 183 | /* validate x/y resolution */ |
| 184 | |
Krzysztof Helt | 09fe75f | 2007-10-16 01:28:56 -0700 | [diff] [blame] | 185 | for (i = 0; i < mach_info->num_displays; i++) |
| 186 | if (var->yres == mach_info->displays[i].yres && |
| 187 | var->xres == mach_info->displays[i].xres && |
| 188 | var->bits_per_pixel == mach_info->displays[i].bpp) { |
| 189 | display = mach_info->displays + i; |
| 190 | fbi->current_display = i; |
| 191 | break; |
| 192 | } |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 193 | |
Krzysztof Helt | 09fe75f | 2007-10-16 01:28:56 -0700 | [diff] [blame] | 194 | if (!display) { |
| 195 | dprintk("wrong resolution or depth %dx%d at %d bpp\n", |
| 196 | var->xres, var->yres, var->bits_per_pixel); |
| 197 | return -EINVAL; |
| 198 | } |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 199 | |
Krzysztof Helt | 9939a48 | 2007-10-16 01:28:57 -0700 | [diff] [blame] | 200 | /* it is always the size as the display */ |
| 201 | var->xres_virtual = display->xres; |
| 202 | var->yres_virtual = display->yres; |
| 203 | |
| 204 | /* copy lcd settings */ |
| 205 | var->left_margin = display->left_margin; |
| 206 | var->right_margin = display->right_margin; |
| 207 | |
Krzysztof Helt | b083194 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 208 | var->transp.offset = 0; |
| 209 | var->transp.length = 0; |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 210 | /* set r/g/b positions */ |
Arnaud Patard (Rtp | 357b819 | 2006-12-08 02:40:23 -0800 | [diff] [blame] | 211 | switch (var->bits_per_pixel) { |
Krzysztof Helt | b083194 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 212 | case 1: |
| 213 | case 2: |
| 214 | case 4: |
| 215 | var->red.offset = 0; |
| 216 | var->red.length = var->bits_per_pixel; |
| 217 | var->green = var->red; |
| 218 | var->blue = var->red; |
| 219 | break; |
| 220 | case 8: |
Krzysztof Helt | 09fe75f | 2007-10-16 01:28:56 -0700 | [diff] [blame] | 221 | if (display->type != S3C2410_LCDCON1_TFT) { |
Krzysztof Helt | b083194 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 222 | /* 8 bpp 332 */ |
| 223 | var->red.length = 3; |
| 224 | var->red.offset = 5; |
| 225 | var->green.length = 3; |
| 226 | var->green.offset = 2; |
| 227 | var->blue.length = 2; |
Arnaud Patard (Rtp | 357b819 | 2006-12-08 02:40:23 -0800 | [diff] [blame] | 228 | var->blue.offset = 0; |
Krzysztof Helt | b083194 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 229 | } else { |
| 230 | var->red.offset = 0; |
Arnaud Patard (Rtp | 357b819 | 2006-12-08 02:40:23 -0800 | [diff] [blame] | 231 | var->red.length = 8; |
Krzysztof Helt | b083194 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 232 | var->green = var->red; |
| 233 | var->blue = var->red; |
| 234 | } |
| 235 | break; |
| 236 | case 12: |
| 237 | /* 12 bpp 444 */ |
| 238 | var->red.length = 4; |
| 239 | var->red.offset = 8; |
| 240 | var->green.length = 4; |
| 241 | var->green.offset = 4; |
| 242 | var->blue.length = 4; |
| 243 | var->blue.offset = 0; |
| 244 | break; |
| 245 | |
| 246 | default: |
| 247 | case 16: |
Krzysztof Helt | f28ef57 | 2007-10-16 01:28:58 -0700 | [diff] [blame] | 248 | if (display->lcdcon5 & S3C2410_LCDCON5_FRM565) { |
Krzysztof Helt | b083194 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 249 | /* 16 bpp, 565 format */ |
| 250 | var->red.offset = 11; |
| 251 | var->green.offset = 5; |
Arnaud Patard (Rtp | 357b819 | 2006-12-08 02:40:23 -0800 | [diff] [blame] | 252 | var->blue.offset = 0; |
Krzysztof Helt | b083194 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 253 | var->red.length = 5; |
| 254 | var->green.length = 6; |
| 255 | var->blue.length = 5; |
| 256 | } else { |
| 257 | /* 16 bpp, 5551 format */ |
| 258 | var->red.offset = 11; |
| 259 | var->green.offset = 6; |
| 260 | var->blue.offset = 1; |
| 261 | var->red.length = 5; |
| 262 | var->green.length = 5; |
| 263 | var->blue.length = 5; |
| 264 | } |
| 265 | break; |
| 266 | case 24: |
| 267 | /* 24 bpp 888 */ |
| 268 | var->red.length = 8; |
| 269 | var->red.offset = 16; |
| 270 | var->green.length = 8; |
| 271 | var->green.offset = 8; |
| 272 | var->blue.length = 8; |
| 273 | var->blue.offset = 0; |
| 274 | break; |
Arnaud Patard (Rtp | 357b819 | 2006-12-08 02:40:23 -0800 | [diff] [blame] | 275 | |
| 276 | |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 277 | } |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 278 | return 0; |
| 279 | } |
| 280 | |
Krzysztof Helt | 9939a48 | 2007-10-16 01:28:57 -0700 | [diff] [blame] | 281 | /* s3c2410fb_calculate_stn_lcd_regs |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 282 | * |
Krzysztof Helt | 9939a48 | 2007-10-16 01:28:57 -0700 | [diff] [blame] | 283 | * calculate register values from var settings |
Krzysztof Helt | b083194 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 284 | */ |
Krzysztof Helt | 9939a48 | 2007-10-16 01:28:57 -0700 | [diff] [blame] | 285 | static void s3c2410fb_calculate_stn_lcd_regs(const struct fb_info *info, |
| 286 | struct s3c2410fb_hw *regs) |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 287 | { |
Krzysztof Helt | 9939a48 | 2007-10-16 01:28:57 -0700 | [diff] [blame] | 288 | const struct s3c2410fb_info *fbi = info->par; |
| 289 | const struct fb_var_screeninfo *var = &info->var; |
| 290 | int type = regs->lcdcon1 & ~S3C2410_LCDCON1_TFT; |
| 291 | int hs = var->xres >> 2; |
| 292 | unsigned wdly = (var->left_margin >> 4) - 1; |
Krzysztof Helt | 93d11f5 | 2007-10-16 01:29:00 -0700 | [diff] [blame^] | 293 | unsigned wlh = (var->hsync_len >> 4) - 1; |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 294 | |
| 295 | dprintk("%s: var->xres = %d\n", __FUNCTION__, var->xres); |
| 296 | dprintk("%s: var->yres = %d\n", __FUNCTION__, var->yres); |
| 297 | dprintk("%s: var->bpp = %d\n", __FUNCTION__, var->bits_per_pixel); |
| 298 | |
Krzysztof Helt | 9939a48 | 2007-10-16 01:28:57 -0700 | [diff] [blame] | 299 | if (type != S3C2410_LCDCON1_STN4) |
| 300 | hs >>= 1; |
| 301 | |
| 302 | regs->lcdcon1 &= ~S3C2410_LCDCON1_MODEMASK; |
| 303 | |
| 304 | switch (var->bits_per_pixel) { |
| 305 | case 1: |
| 306 | regs->lcdcon1 |= S3C2410_LCDCON1_STN1BPP; |
| 307 | break; |
| 308 | case 2: |
| 309 | regs->lcdcon1 |= S3C2410_LCDCON1_STN2GREY; |
| 310 | break; |
| 311 | case 4: |
| 312 | regs->lcdcon1 |= S3C2410_LCDCON1_STN4GREY; |
| 313 | break; |
| 314 | case 8: |
| 315 | regs->lcdcon1 |= S3C2410_LCDCON1_STN8BPP; |
| 316 | hs *= 3; |
| 317 | break; |
| 318 | case 12: |
| 319 | regs->lcdcon1 |= S3C2410_LCDCON1_STN12BPP; |
| 320 | hs *= 3; |
| 321 | break; |
| 322 | |
| 323 | default: |
| 324 | /* invalid pixel depth */ |
| 325 | dev_err(fbi->dev, "invalid bpp %d\n", |
| 326 | var->bits_per_pixel); |
| 327 | } |
| 328 | /* update X/Y info */ |
Krzysztof Helt | 9939a48 | 2007-10-16 01:28:57 -0700 | [diff] [blame] | 329 | dprintk("setting horz: lft=%d, rt=%d, sync=%d\n", |
| 330 | var->left_margin, var->right_margin, var->hsync_len); |
| 331 | |
Krzysztof Helt | 3c9ffd0 | 2007-10-16 01:28:59 -0700 | [diff] [blame] | 332 | regs->lcdcon2 = S3C2410_LCDCON2_LINEVAL(var->yres - 1); |
Krzysztof Helt | 9939a48 | 2007-10-16 01:28:57 -0700 | [diff] [blame] | 333 | |
| 334 | if (wdly > 3) |
| 335 | wdly = 3; |
| 336 | |
Krzysztof Helt | 93d11f5 | 2007-10-16 01:29:00 -0700 | [diff] [blame^] | 337 | if (wlh > 3) |
| 338 | wlh = 3; |
| 339 | |
Krzysztof Helt | 9939a48 | 2007-10-16 01:28:57 -0700 | [diff] [blame] | 340 | regs->lcdcon3 = S3C2410_LCDCON3_WDLY(wdly) | |
| 341 | S3C2410_LCDCON3_LINEBLANK(var->right_margin / 8) | |
| 342 | S3C2410_LCDCON3_HOZVAL(hs - 1); |
Krzysztof Helt | 93d11f5 | 2007-10-16 01:29:00 -0700 | [diff] [blame^] | 343 | |
| 344 | regs->lcdcon4 &= ~S3C2410_LCDCON4_HSPW(0xff); |
| 345 | regs->lcdcon4 |= S3C2410_LCDCON4_HSPW(wlh); |
Krzysztof Helt | 9939a48 | 2007-10-16 01:28:57 -0700 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | /* s3c2410fb_calculate_tft_lcd_regs |
| 349 | * |
| 350 | * calculate register values from var settings |
| 351 | */ |
| 352 | static void s3c2410fb_calculate_tft_lcd_regs(const struct fb_info *info, |
| 353 | struct s3c2410fb_hw *regs) |
| 354 | { |
| 355 | const struct s3c2410fb_info *fbi = info->par; |
| 356 | const struct fb_var_screeninfo *var = &info->var; |
| 357 | |
| 358 | dprintk("%s: var->xres = %d\n", __FUNCTION__, var->xres); |
| 359 | dprintk("%s: var->yres = %d\n", __FUNCTION__, var->yres); |
| 360 | dprintk("%s: var->bpp = %d\n", __FUNCTION__, var->bits_per_pixel); |
| 361 | |
| 362 | regs->lcdcon1 &= ~S3C2410_LCDCON1_MODEMASK; |
| 363 | |
| 364 | switch (var->bits_per_pixel) { |
| 365 | case 1: |
| 366 | regs->lcdcon1 |= S3C2410_LCDCON1_TFT1BPP; |
| 367 | break; |
| 368 | case 2: |
| 369 | regs->lcdcon1 |= S3C2410_LCDCON1_TFT2BPP; |
| 370 | break; |
| 371 | case 4: |
| 372 | regs->lcdcon1 |= S3C2410_LCDCON1_TFT4BPP; |
| 373 | break; |
| 374 | case 8: |
| 375 | regs->lcdcon1 |= S3C2410_LCDCON1_TFT8BPP; |
| 376 | break; |
| 377 | case 16: |
| 378 | regs->lcdcon1 |= S3C2410_LCDCON1_TFT16BPP; |
| 379 | break; |
| 380 | |
| 381 | default: |
| 382 | /* invalid pixel depth */ |
| 383 | dev_err(fbi->dev, "invalid bpp %d\n", |
| 384 | var->bits_per_pixel); |
| 385 | } |
| 386 | /* update X/Y info */ |
| 387 | dprintk("setting vert: up=%d, low=%d, sync=%d\n", |
| 388 | var->upper_margin, var->lower_margin, var->vsync_len); |
| 389 | |
| 390 | dprintk("setting horz: lft=%d, rt=%d, sync=%d\n", |
| 391 | var->left_margin, var->right_margin, var->hsync_len); |
| 392 | |
Krzysztof Helt | 93d11f5 | 2007-10-16 01:29:00 -0700 | [diff] [blame^] | 393 | regs->lcdcon2 = S3C2410_LCDCON2_LINEVAL(var->yres - 1) | |
| 394 | S3C2410_LCDCON2_VBPD(var->upper_margin - 1) | |
| 395 | S3C2410_LCDCON2_VFPD(var->lower_margin - 1) | |
| 396 | S3C2410_LCDCON2_VSPW(var->vsync_len - 1); |
Krzysztof Helt | 9939a48 | 2007-10-16 01:28:57 -0700 | [diff] [blame] | 397 | |
| 398 | regs->lcdcon3 = S3C2410_LCDCON3_HBPD(var->right_margin - 1) | |
| 399 | S3C2410_LCDCON3_HFPD(var->left_margin - 1) | |
| 400 | S3C2410_LCDCON3_HOZVAL(var->xres - 1); |
Krzysztof Helt | 93d11f5 | 2007-10-16 01:29:00 -0700 | [diff] [blame^] | 401 | |
| 402 | regs->lcdcon4 &= ~S3C2410_LCDCON4_HSPW(0xff); |
| 403 | regs->lcdcon4 |= S3C2410_LCDCON4_HSPW(var->hsync_len - 1); |
Krzysztof Helt | 9939a48 | 2007-10-16 01:28:57 -0700 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | /* s3c2410fb_activate_var |
| 407 | * |
| 408 | * activate (set) the controller from the given framebuffer |
| 409 | * information |
| 410 | */ |
| 411 | static void s3c2410fb_activate_var(struct fb_info *info) |
| 412 | { |
| 413 | struct s3c2410fb_info *fbi = info->par; |
| 414 | struct fb_var_screeninfo *var = &info->var; |
| 415 | struct s3c2410fb_mach_info *mach_info = fbi->mach_info; |
| 416 | struct s3c2410fb_display *display = mach_info->displays + |
| 417 | fbi->current_display; |
| 418 | |
| 419 | /* set display type */ |
| 420 | fbi->regs.lcdcon1 &= ~S3C2410_LCDCON1_TFT; |
Krzysztof Helt | 09fe75f | 2007-10-16 01:28:56 -0700 | [diff] [blame] | 421 | fbi->regs.lcdcon1 |= display->type; |
Arnaud Patard (Rtp | 357b819 | 2006-12-08 02:40:23 -0800 | [diff] [blame] | 422 | |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 423 | if (var->pixclock > 0) { |
| 424 | int clkdiv = s3c2410fb_calc_pixclk(fbi, var->pixclock); |
| 425 | |
Krzysztof Helt | 09fe75f | 2007-10-16 01:28:56 -0700 | [diff] [blame] | 426 | if (display->type == S3C2410_LCDCON1_TFT) { |
Krzysztof Helt | b083194 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 427 | clkdiv = (clkdiv / 2) - 1; |
Arnaud Patard (Rtp | 357b819 | 2006-12-08 02:40:23 -0800 | [diff] [blame] | 428 | if (clkdiv < 0) |
| 429 | clkdiv = 0; |
Krzysztof Helt | b083194 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 430 | } else { |
Arnaud Patard (Rtp | 357b819 | 2006-12-08 02:40:23 -0800 | [diff] [blame] | 431 | clkdiv = (clkdiv / 2); |
| 432 | if (clkdiv < 2) |
| 433 | clkdiv = 2; |
| 434 | } |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 435 | |
| 436 | fbi->regs.lcdcon1 &= ~S3C2410_LCDCON1_CLKVAL(0x3ff); |
| 437 | fbi->regs.lcdcon1 |= S3C2410_LCDCON1_CLKVAL(clkdiv); |
| 438 | } |
| 439 | |
Krzysztof Helt | 9939a48 | 2007-10-16 01:28:57 -0700 | [diff] [blame] | 440 | if (display->type == S3C2410_LCDCON1_TFT) |
| 441 | s3c2410fb_calculate_tft_lcd_regs(info, &fbi->regs); |
| 442 | else |
| 443 | s3c2410fb_calculate_stn_lcd_regs(info, &fbi->regs); |
| 444 | |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 445 | /* write new registers */ |
| 446 | |
| 447 | dprintk("new register set:\n"); |
| 448 | dprintk("lcdcon[1] = 0x%08lx\n", fbi->regs.lcdcon1); |
| 449 | dprintk("lcdcon[2] = 0x%08lx\n", fbi->regs.lcdcon2); |
| 450 | dprintk("lcdcon[3] = 0x%08lx\n", fbi->regs.lcdcon3); |
| 451 | dprintk("lcdcon[4] = 0x%08lx\n", fbi->regs.lcdcon4); |
| 452 | dprintk("lcdcon[5] = 0x%08lx\n", fbi->regs.lcdcon5); |
| 453 | |
| 454 | writel(fbi->regs.lcdcon1 & ~S3C2410_LCDCON1_ENVID, S3C2410_LCDCON1); |
| 455 | writel(fbi->regs.lcdcon2, S3C2410_LCDCON2); |
| 456 | writel(fbi->regs.lcdcon3, S3C2410_LCDCON3); |
| 457 | writel(fbi->regs.lcdcon4, S3C2410_LCDCON4); |
| 458 | writel(fbi->regs.lcdcon5, S3C2410_LCDCON5); |
| 459 | |
| 460 | /* set lcd address pointers */ |
Krzysztof Helt | 110c1fa | 2007-10-16 01:28:55 -0700 | [diff] [blame] | 461 | s3c2410fb_set_lcdaddr(info); |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 462 | |
| 463 | writel(fbi->regs.lcdcon1, S3C2410_LCDCON1); |
| 464 | } |
| 465 | |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 466 | /* |
Krzysztof Helt | b083194 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 467 | * s3c2410fb_set_par - Alters the hardware state. |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 468 | * @info: frame buffer structure that represents a single frame buffer |
| 469 | * |
| 470 | */ |
| 471 | static int s3c2410fb_set_par(struct fb_info *info) |
| 472 | { |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 473 | struct fb_var_screeninfo *var = &info->var; |
| 474 | |
Krzysztof Helt | b083194 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 475 | switch (var->bits_per_pixel) { |
| 476 | case 16: |
| 477 | info->fix.visual = FB_VISUAL_TRUECOLOR; |
| 478 | break; |
| 479 | case 1: |
| 480 | info->fix.visual = FB_VISUAL_MONO01; |
| 481 | break; |
| 482 | default: |
| 483 | info->fix.visual = FB_VISUAL_PSEUDOCOLOR; |
| 484 | break; |
Arnaud Patard (Rtp | 357b819 | 2006-12-08 02:40:23 -0800 | [diff] [blame] | 485 | } |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 486 | |
Krzysztof Helt | b083194 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 487 | info->fix.line_length = (var->width * var->bits_per_pixel) / 8; |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 488 | |
| 489 | /* activate this new configuration */ |
| 490 | |
Krzysztof Helt | 9939a48 | 2007-10-16 01:28:57 -0700 | [diff] [blame] | 491 | s3c2410fb_activate_var(info); |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 492 | return 0; |
| 493 | } |
| 494 | |
| 495 | static void schedule_palette_update(struct s3c2410fb_info *fbi, |
| 496 | unsigned int regno, unsigned int val) |
| 497 | { |
| 498 | unsigned long flags; |
| 499 | unsigned long irqen; |
Ben Dooks | aff39a8 | 2007-07-31 00:37:37 -0700 | [diff] [blame] | 500 | void __iomem *regs = fbi->io; |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 501 | |
| 502 | local_irq_save(flags); |
| 503 | |
| 504 | fbi->palette_buffer[regno] = val; |
| 505 | |
| 506 | if (!fbi->palette_ready) { |
| 507 | fbi->palette_ready = 1; |
| 508 | |
| 509 | /* enable IRQ */ |
Ben Dooks | aff39a8 | 2007-07-31 00:37:37 -0700 | [diff] [blame] | 510 | irqen = readl(regs + S3C2410_LCDINTMSK); |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 511 | irqen &= ~S3C2410_LCDINT_FRSYNC; |
Ben Dooks | aff39a8 | 2007-07-31 00:37:37 -0700 | [diff] [blame] | 512 | writel(irqen, regs + S3C2410_LCDINTMSK); |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | local_irq_restore(flags); |
| 516 | } |
| 517 | |
| 518 | /* from pxafb.c */ |
Krzysztof Helt | b083194 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 519 | static inline unsigned int chan_to_field(unsigned int chan, |
| 520 | struct fb_bitfield *bf) |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 521 | { |
| 522 | chan &= 0xffff; |
| 523 | chan >>= 16 - bf->length; |
| 524 | return chan << bf->offset; |
| 525 | } |
| 526 | |
| 527 | static int s3c2410fb_setcolreg(unsigned regno, |
| 528 | unsigned red, unsigned green, unsigned blue, |
| 529 | unsigned transp, struct fb_info *info) |
| 530 | { |
| 531 | struct s3c2410fb_info *fbi = info->par; |
| 532 | unsigned int val; |
| 533 | |
Krzysztof Helt | b083194 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 534 | /* dprintk("setcol: regno=%d, rgb=%d,%d,%d\n", |
| 535 | regno, red, green, blue); */ |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 536 | |
Krzysztof Helt | b083194 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 537 | switch (info->fix.visual) { |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 538 | case FB_VISUAL_TRUECOLOR: |
Krzysztof Helt | b083194 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 539 | /* true-colour, use pseudo-palette */ |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 540 | |
| 541 | if (regno < 16) { |
Krzysztof Helt | b083194 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 542 | u32 *pal = info->pseudo_palette; |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 543 | |
Krzysztof Helt | b083194 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 544 | val = chan_to_field(red, &info->var.red); |
| 545 | val |= chan_to_field(green, &info->var.green); |
| 546 | val |= chan_to_field(blue, &info->var.blue); |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 547 | |
| 548 | pal[regno] = val; |
| 549 | } |
| 550 | break; |
| 551 | |
| 552 | case FB_VISUAL_PSEUDOCOLOR: |
| 553 | if (regno < 256) { |
| 554 | /* currently assume RGB 5-6-5 mode */ |
| 555 | |
| 556 | val = ((red >> 0) & 0xf800); |
| 557 | val |= ((green >> 5) & 0x07e0); |
| 558 | val |= ((blue >> 11) & 0x001f); |
| 559 | |
| 560 | writel(val, S3C2410_TFTPAL(regno)); |
| 561 | schedule_palette_update(fbi, regno, val); |
| 562 | } |
| 563 | |
| 564 | break; |
| 565 | |
| 566 | default: |
Krzysztof Helt | b083194 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 567 | return 1; /* unknown type */ |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | return 0; |
| 571 | } |
| 572 | |
Krzysztof Helt | b083194 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 573 | /* |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 574 | * s3c2410fb_blank |
| 575 | * @blank_mode: the blank mode we want. |
| 576 | * @info: frame buffer structure that represents a single frame buffer |
| 577 | * |
| 578 | * Blank the screen if blank_mode != 0, else unblank. Return 0 if |
| 579 | * blanking succeeded, != 0 if un-/blanking failed due to e.g. a |
| 580 | * video mode which doesn't support it. Implements VESA suspend |
| 581 | * and powerdown modes on hardware that supports disabling hsync/vsync: |
| 582 | * blank_mode == 2: suspend vsync |
| 583 | * blank_mode == 3: suspend hsync |
| 584 | * blank_mode == 4: powerdown |
| 585 | * |
| 586 | * Returns negative errno on error, or zero on success. |
| 587 | * |
| 588 | */ |
| 589 | static int s3c2410fb_blank(int blank_mode, struct fb_info *info) |
| 590 | { |
| 591 | dprintk("blank(mode=%d, info=%p)\n", blank_mode, info); |
| 592 | |
| 593 | if (mach_info == NULL) |
| 594 | return -EINVAL; |
| 595 | |
| 596 | if (blank_mode == FB_BLANK_UNBLANK) |
| 597 | writel(0x0, S3C2410_TPAL); |
| 598 | else { |
| 599 | dprintk("setting TPAL to output 0x000000\n"); |
| 600 | writel(S3C2410_TPAL_EN, S3C2410_TPAL); |
| 601 | } |
| 602 | |
| 603 | return 0; |
| 604 | } |
| 605 | |
Krzysztof Helt | b083194 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 606 | static int s3c2410fb_debug_show(struct device *dev, |
| 607 | struct device_attribute *attr, char *buf) |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 608 | { |
| 609 | return snprintf(buf, PAGE_SIZE, "%s\n", debug ? "on" : "off"); |
| 610 | } |
Krzysztof Helt | b083194 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 611 | static int s3c2410fb_debug_store(struct device *dev, |
| 612 | struct device_attribute *attr, |
| 613 | const char *buf, size_t len) |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 614 | { |
| 615 | if (mach_info == NULL) |
| 616 | return -EINVAL; |
| 617 | |
| 618 | if (len < 1) |
| 619 | return -EINVAL; |
| 620 | |
| 621 | if (strnicmp(buf, "on", 2) == 0 || |
| 622 | strnicmp(buf, "1", 1) == 0) { |
| 623 | debug = 1; |
| 624 | printk(KERN_DEBUG "s3c2410fb: Debug On"); |
| 625 | } else if (strnicmp(buf, "off", 3) == 0 || |
| 626 | strnicmp(buf, "0", 1) == 0) { |
| 627 | debug = 0; |
| 628 | printk(KERN_DEBUG "s3c2410fb: Debug Off"); |
| 629 | } else { |
| 630 | return -EINVAL; |
| 631 | } |
| 632 | |
| 633 | return len; |
| 634 | } |
| 635 | |
Krzysztof Helt | b083194 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 636 | static DEVICE_ATTR(debug, 0666, s3c2410fb_debug_show, s3c2410fb_debug_store); |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 637 | |
| 638 | static struct fb_ops s3c2410fb_ops = { |
| 639 | .owner = THIS_MODULE, |
| 640 | .fb_check_var = s3c2410fb_check_var, |
| 641 | .fb_set_par = s3c2410fb_set_par, |
| 642 | .fb_blank = s3c2410fb_blank, |
| 643 | .fb_setcolreg = s3c2410fb_setcolreg, |
| 644 | .fb_fillrect = cfb_fillrect, |
| 645 | .fb_copyarea = cfb_copyarea, |
| 646 | .fb_imageblit = cfb_imageblit, |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 647 | }; |
| 648 | |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 649 | /* |
| 650 | * s3c2410fb_map_video_memory(): |
| 651 | * Allocates the DRAM memory for the frame buffer. This buffer is |
| 652 | * remapped into a non-cached, non-buffered, memory region to |
| 653 | * allow palette and pixel writes to occur without flushing the |
| 654 | * cache. Once this area is remapped, all virtual memory |
| 655 | * access to the video memory should occur at the new region. |
| 656 | */ |
Krzysztof Helt | 110c1fa | 2007-10-16 01:28:55 -0700 | [diff] [blame] | 657 | static int __init s3c2410fb_map_video_memory(struct fb_info *info) |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 658 | { |
Krzysztof Helt | 110c1fa | 2007-10-16 01:28:55 -0700 | [diff] [blame] | 659 | struct s3c2410fb_info *fbi = info->par; |
| 660 | |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 661 | dprintk("map_video_memory(fbi=%p)\n", fbi); |
| 662 | |
Krzysztof Helt | 110c1fa | 2007-10-16 01:28:55 -0700 | [diff] [blame] | 663 | fbi->map_size = PAGE_ALIGN(info->fix.smem_len + PAGE_SIZE); |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 664 | fbi->map_cpu = dma_alloc_writecombine(fbi->dev, fbi->map_size, |
| 665 | &fbi->map_dma, GFP_KERNEL); |
| 666 | |
Krzysztof Helt | 110c1fa | 2007-10-16 01:28:55 -0700 | [diff] [blame] | 667 | fbi->map_size = info->fix.smem_len; |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 668 | |
| 669 | if (fbi->map_cpu) { |
| 670 | /* prevent initial garbage on screen */ |
| 671 | dprintk("map_video_memory: clear %p:%08x\n", |
| 672 | fbi->map_cpu, fbi->map_size); |
| 673 | memset(fbi->map_cpu, 0xf0, fbi->map_size); |
| 674 | |
| 675 | fbi->screen_dma = fbi->map_dma; |
Krzysztof Helt | 110c1fa | 2007-10-16 01:28:55 -0700 | [diff] [blame] | 676 | info->screen_base = fbi->map_cpu; |
| 677 | info->fix.smem_start = fbi->screen_dma; |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 678 | |
| 679 | dprintk("map_video_memory: dma=%08x cpu=%p size=%08x\n", |
Krzysztof Helt | 110c1fa | 2007-10-16 01:28:55 -0700 | [diff] [blame] | 680 | fbi->map_dma, fbi->map_cpu, info->fix.smem_len); |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | return fbi->map_cpu ? 0 : -ENOMEM; |
| 684 | } |
| 685 | |
| 686 | static inline void s3c2410fb_unmap_video_memory(struct s3c2410fb_info *fbi) |
| 687 | { |
Krzysztof Helt | b083194 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 688 | dma_free_writecombine(fbi->dev, fbi->map_size, fbi->map_cpu, |
| 689 | fbi->map_dma); |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | static inline void modify_gpio(void __iomem *reg, |
| 693 | unsigned long set, unsigned long mask) |
| 694 | { |
| 695 | unsigned long tmp; |
| 696 | |
| 697 | tmp = readl(reg) & ~mask; |
| 698 | writel(tmp | set, reg); |
| 699 | } |
| 700 | |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 701 | /* |
| 702 | * s3c2410fb_init_registers - Initialise all LCD-related registers |
| 703 | */ |
Krzysztof Helt | 110c1fa | 2007-10-16 01:28:55 -0700 | [diff] [blame] | 704 | static int s3c2410fb_init_registers(struct fb_info *info) |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 705 | { |
Krzysztof Helt | 110c1fa | 2007-10-16 01:28:55 -0700 | [diff] [blame] | 706 | struct s3c2410fb_info *fbi = info->par; |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 707 | unsigned long flags; |
Ben Dooks | aff39a8 | 2007-07-31 00:37:37 -0700 | [diff] [blame] | 708 | void __iomem *regs = fbi->io; |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 709 | |
| 710 | /* Initialise LCD with values from haret */ |
| 711 | |
| 712 | local_irq_save(flags); |
| 713 | |
| 714 | /* modify the gpio(s) with interrupts set (bjd) */ |
| 715 | |
| 716 | modify_gpio(S3C2410_GPCUP, mach_info->gpcup, mach_info->gpcup_mask); |
| 717 | modify_gpio(S3C2410_GPCCON, mach_info->gpccon, mach_info->gpccon_mask); |
| 718 | modify_gpio(S3C2410_GPDUP, mach_info->gpdup, mach_info->gpdup_mask); |
| 719 | modify_gpio(S3C2410_GPDCON, mach_info->gpdcon, mach_info->gpdcon_mask); |
| 720 | |
| 721 | local_irq_restore(flags); |
| 722 | |
Ben Dooks | aff39a8 | 2007-07-31 00:37:37 -0700 | [diff] [blame] | 723 | writel(fbi->regs.lcdcon1, regs + S3C2410_LCDCON1); |
| 724 | writel(fbi->regs.lcdcon2, regs + S3C2410_LCDCON2); |
| 725 | writel(fbi->regs.lcdcon3, regs + S3C2410_LCDCON3); |
| 726 | writel(fbi->regs.lcdcon4, regs + S3C2410_LCDCON4); |
| 727 | writel(fbi->regs.lcdcon5, regs + S3C2410_LCDCON5); |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 728 | |
Krzysztof Helt | 110c1fa | 2007-10-16 01:28:55 -0700 | [diff] [blame] | 729 | s3c2410fb_set_lcdaddr(info); |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 730 | |
| 731 | dprintk("LPCSEL = 0x%08lx\n", mach_info->lpcsel); |
Ben Dooks | aff39a8 | 2007-07-31 00:37:37 -0700 | [diff] [blame] | 732 | writel(mach_info->lpcsel, regs + S3C2410_LPCSEL); |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 733 | |
Ben Dooks | aff39a8 | 2007-07-31 00:37:37 -0700 | [diff] [blame] | 734 | dprintk("replacing TPAL %08x\n", readl(regs + S3C2410_TPAL)); |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 735 | |
| 736 | /* ensure temporary palette disabled */ |
Ben Dooks | aff39a8 | 2007-07-31 00:37:37 -0700 | [diff] [blame] | 737 | writel(0x00, regs + S3C2410_TPAL); |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 738 | |
| 739 | /* Enable video by setting the ENVID bit to 1 */ |
| 740 | fbi->regs.lcdcon1 |= S3C2410_LCDCON1_ENVID; |
Ben Dooks | aff39a8 | 2007-07-31 00:37:37 -0700 | [diff] [blame] | 741 | writel(fbi->regs.lcdcon1, regs + S3C2410_LCDCON1); |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 742 | return 0; |
| 743 | } |
| 744 | |
| 745 | static void s3c2410fb_write_palette(struct s3c2410fb_info *fbi) |
| 746 | { |
| 747 | unsigned int i; |
Ben Dooks | aff39a8 | 2007-07-31 00:37:37 -0700 | [diff] [blame] | 748 | void __iomem *regs = fbi->io; |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 749 | |
| 750 | fbi->palette_ready = 0; |
| 751 | |
| 752 | for (i = 0; i < 256; i++) { |
Krzysztof Helt | b083194 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 753 | unsigned long ent = fbi->palette_buffer[i]; |
| 754 | if (ent == PALETTE_BUFF_CLEAR) |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 755 | continue; |
| 756 | |
Ben Dooks | aff39a8 | 2007-07-31 00:37:37 -0700 | [diff] [blame] | 757 | writel(ent, regs + S3C2410_TFTPAL(i)); |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 758 | |
| 759 | /* it seems the only way to know exactly |
| 760 | * if the palette wrote ok, is to check |
| 761 | * to see if the value verifies ok |
| 762 | */ |
| 763 | |
Ben Dooks | aff39a8 | 2007-07-31 00:37:37 -0700 | [diff] [blame] | 764 | if (readw(regs + S3C2410_TFTPAL(i)) == ent) |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 765 | fbi->palette_buffer[i] = PALETTE_BUFF_CLEAR; |
| 766 | else |
| 767 | fbi->palette_ready = 1; /* retry */ |
| 768 | } |
| 769 | } |
| 770 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 771 | static irqreturn_t s3c2410fb_irq(int irq, void *dev_id) |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 772 | { |
| 773 | struct s3c2410fb_info *fbi = dev_id; |
Ben Dooks | aff39a8 | 2007-07-31 00:37:37 -0700 | [diff] [blame] | 774 | void __iomem *regs = fbi->io; |
| 775 | unsigned long lcdirq = readl(regs + S3C2410_LCDINTPND); |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 776 | |
| 777 | if (lcdirq & S3C2410_LCDINT_FRSYNC) { |
| 778 | if (fbi->palette_ready) |
| 779 | s3c2410fb_write_palette(fbi); |
| 780 | |
Ben Dooks | aff39a8 | 2007-07-31 00:37:37 -0700 | [diff] [blame] | 781 | writel(S3C2410_LCDINT_FRSYNC, regs + S3C2410_LCDINTPND); |
| 782 | writel(S3C2410_LCDINT_FRSYNC, regs + S3C2410_LCDSRCPND); |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 783 | } |
| 784 | |
| 785 | return IRQ_HANDLED; |
| 786 | } |
| 787 | |
Krzysztof Helt | b083194 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 788 | static char driver_name[] = "s3c2410fb"; |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 789 | |
Arnaud Patard | 740f14b | 2006-01-09 20:53:41 -0800 | [diff] [blame] | 790 | static int __init s3c2410fb_probe(struct platform_device *pdev) |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 791 | { |
| 792 | struct s3c2410fb_info *info; |
Krzysztof Helt | 09fe75f | 2007-10-16 01:28:56 -0700 | [diff] [blame] | 793 | struct s3c2410fb_display *display; |
Krzysztof Helt | b083194 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 794 | struct fb_info *fbinfo; |
Ben Dooks | aff39a8 | 2007-07-31 00:37:37 -0700 | [diff] [blame] | 795 | struct resource *res; |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 796 | int ret; |
| 797 | int irq; |
| 798 | int i; |
Ben Dooks | aff39a8 | 2007-07-31 00:37:37 -0700 | [diff] [blame] | 799 | int size; |
Arnaud Patard | 6931a76 | 2006-06-26 00:26:45 -0700 | [diff] [blame] | 800 | u32 lcdcon1; |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 801 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 802 | mach_info = pdev->dev.platform_data; |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 803 | if (mach_info == NULL) { |
Krzysztof Helt | b083194 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 804 | dev_err(&pdev->dev, |
| 805 | "no platform data for lcd, cannot attach\n"); |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 806 | return -EINVAL; |
| 807 | } |
| 808 | |
Krzysztof Helt | 09fe75f | 2007-10-16 01:28:56 -0700 | [diff] [blame] | 809 | display = mach_info->displays + mach_info->default_display; |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 810 | |
| 811 | irq = platform_get_irq(pdev, 0); |
| 812 | if (irq < 0) { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 813 | dev_err(&pdev->dev, "no irq for device\n"); |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 814 | return -ENOENT; |
| 815 | } |
| 816 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 817 | fbinfo = framebuffer_alloc(sizeof(struct s3c2410fb_info), &pdev->dev); |
Krzysztof Helt | b083194 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 818 | if (!fbinfo) |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 819 | return -ENOMEM; |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 820 | |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 821 | info = fbinfo->par; |
Ben Dooks | 0187f22 | 2007-02-16 01:28:42 -0800 | [diff] [blame] | 822 | info->dev = &pdev->dev; |
| 823 | |
Ben Dooks | aff39a8 | 2007-07-31 00:37:37 -0700 | [diff] [blame] | 824 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 825 | if (res == NULL) { |
Krzysztof Helt | b083194 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 826 | dev_err(&pdev->dev, "failed to get memory registers\n"); |
Ben Dooks | aff39a8 | 2007-07-31 00:37:37 -0700 | [diff] [blame] | 827 | ret = -ENXIO; |
| 828 | goto dealloc_fb; |
| 829 | } |
| 830 | |
Krzysztof Helt | b083194 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 831 | size = (res->end - res->start) + 1; |
Ben Dooks | aff39a8 | 2007-07-31 00:37:37 -0700 | [diff] [blame] | 832 | info->mem = request_mem_region(res->start, size, pdev->name); |
| 833 | if (info->mem == NULL) { |
| 834 | dev_err(&pdev->dev, "failed to get memory region\n"); |
| 835 | ret = -ENOENT; |
| 836 | goto dealloc_fb; |
| 837 | } |
| 838 | |
| 839 | info->io = ioremap(res->start, size); |
| 840 | if (info->io == NULL) { |
| 841 | dev_err(&pdev->dev, "ioremap() of registers failed\n"); |
| 842 | ret = -ENXIO; |
| 843 | goto release_mem; |
| 844 | } |
| 845 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 846 | platform_set_drvdata(pdev, fbinfo); |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 847 | |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 848 | dprintk("devinit\n"); |
| 849 | |
| 850 | strcpy(fbinfo->fix.id, driver_name); |
| 851 | |
Krzysztof Helt | f28ef57 | 2007-10-16 01:28:58 -0700 | [diff] [blame] | 852 | info->regs.lcdcon1 = display->lcdcon1; |
| 853 | info->regs.lcdcon2 = display->lcdcon2; |
| 854 | info->regs.lcdcon4 = display->lcdcon4; |
| 855 | info->regs.lcdcon5 = display->lcdcon5; |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 856 | |
Arnaud Patard | 6931a76 | 2006-06-26 00:26:45 -0700 | [diff] [blame] | 857 | /* Stop the video and unset ENVID if set */ |
| 858 | info->regs.lcdcon1 &= ~S3C2410_LCDCON1_ENVID; |
Ben Dooks | aff39a8 | 2007-07-31 00:37:37 -0700 | [diff] [blame] | 859 | lcdcon1 = readl(info->io + S3C2410_LCDCON1); |
| 860 | writel(lcdcon1 & ~S3C2410_LCDCON1_ENVID, info->io + S3C2410_LCDCON1); |
Arnaud Patard | 6931a76 | 2006-06-26 00:26:45 -0700 | [diff] [blame] | 861 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 862 | info->mach_info = pdev->dev.platform_data; |
Krzysztof Helt | 09fe75f | 2007-10-16 01:28:56 -0700 | [diff] [blame] | 863 | info->current_display = mach_info->default_display; |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 864 | |
| 865 | fbinfo->fix.type = FB_TYPE_PACKED_PIXELS; |
| 866 | fbinfo->fix.type_aux = 0; |
| 867 | fbinfo->fix.xpanstep = 0; |
| 868 | fbinfo->fix.ypanstep = 0; |
| 869 | fbinfo->fix.ywrapstep = 0; |
| 870 | fbinfo->fix.accel = FB_ACCEL_NONE; |
| 871 | |
| 872 | fbinfo->var.nonstd = 0; |
| 873 | fbinfo->var.activate = FB_ACTIVATE_NOW; |
Krzysztof Helt | 09fe75f | 2007-10-16 01:28:56 -0700 | [diff] [blame] | 874 | fbinfo->var.height = display->height; |
| 875 | fbinfo->var.width = display->width; |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 876 | fbinfo->var.accel_flags = 0; |
| 877 | fbinfo->var.vmode = FB_VMODE_NONINTERLACED; |
| 878 | |
| 879 | fbinfo->fbops = &s3c2410fb_ops; |
| 880 | fbinfo->flags = FBINFO_FLAG_DEFAULT; |
| 881 | fbinfo->pseudo_palette = &info->pseudo_pal; |
| 882 | |
Krzysztof Helt | 09fe75f | 2007-10-16 01:28:56 -0700 | [diff] [blame] | 883 | fbinfo->var.xres = display->xres; |
| 884 | fbinfo->var.xres_virtual = display->xres; |
| 885 | fbinfo->var.yres = display->yres; |
| 886 | fbinfo->var.yres_virtual = display->yres; |
| 887 | fbinfo->var.bits_per_pixel = display->bpp; |
Krzysztof Helt | 9939a48 | 2007-10-16 01:28:57 -0700 | [diff] [blame] | 888 | fbinfo->var.left_margin = display->left_margin; |
| 889 | fbinfo->var.right_margin = display->right_margin; |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 890 | |
Krzysztof Helt | 3c9ffd0 | 2007-10-16 01:28:59 -0700 | [diff] [blame] | 891 | fbinfo->var.upper_margin = display->upper_margin; |
| 892 | fbinfo->var.lower_margin = display->lower_margin; |
Krzysztof Helt | 93d11f5 | 2007-10-16 01:29:00 -0700 | [diff] [blame^] | 893 | fbinfo->var.vsync_len = display->vsync_len; |
| 894 | fbinfo->var.hsync_len = display->hsync_len; |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 895 | |
| 896 | fbinfo->var.red.offset = 11; |
| 897 | fbinfo->var.green.offset = 5; |
| 898 | fbinfo->var.blue.offset = 0; |
| 899 | fbinfo->var.transp.offset = 0; |
| 900 | fbinfo->var.red.length = 5; |
| 901 | fbinfo->var.green.length = 6; |
| 902 | fbinfo->var.blue.length = 5; |
| 903 | fbinfo->var.transp.length = 0; |
Krzysztof Helt | 09fe75f | 2007-10-16 01:28:56 -0700 | [diff] [blame] | 904 | |
| 905 | /* find maximum required memory size for display */ |
| 906 | for (i = 0; i < mach_info->num_displays; i++) { |
| 907 | unsigned long smem_len = mach_info->displays[i].xres; |
| 908 | |
| 909 | smem_len *= mach_info->displays[i].yres; |
| 910 | smem_len *= mach_info->displays[i].bpp; |
| 911 | smem_len >>= 3; |
| 912 | if (fbinfo->fix.smem_len < smem_len) |
| 913 | fbinfo->fix.smem_len = smem_len; |
| 914 | } |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 915 | |
| 916 | for (i = 0; i < 256; i++) |
| 917 | info->palette_buffer[i] = PALETTE_BUFF_CLEAR; |
| 918 | |
Thomas Gleixner | 63a4339 | 2006-07-01 19:29:45 -0700 | [diff] [blame] | 919 | ret = request_irq(irq, s3c2410fb_irq, IRQF_DISABLED, pdev->name, info); |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 920 | if (ret) { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 921 | dev_err(&pdev->dev, "cannot get irq %d - err %d\n", irq, ret); |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 922 | ret = -EBUSY; |
Ben Dooks | aff39a8 | 2007-07-31 00:37:37 -0700 | [diff] [blame] | 923 | goto release_regs; |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 924 | } |
| 925 | |
| 926 | info->clk = clk_get(NULL, "lcd"); |
| 927 | if (!info->clk || IS_ERR(info->clk)) { |
| 928 | printk(KERN_ERR "failed to get lcd clock source\n"); |
| 929 | ret = -ENOENT; |
| 930 | goto release_irq; |
| 931 | } |
| 932 | |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 933 | clk_enable(info->clk); |
| 934 | dprintk("got and enabled clock\n"); |
| 935 | |
| 936 | msleep(1); |
| 937 | |
| 938 | /* Initialize video memory */ |
Krzysztof Helt | 110c1fa | 2007-10-16 01:28:55 -0700 | [diff] [blame] | 939 | ret = s3c2410fb_map_video_memory(fbinfo); |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 940 | if (ret) { |
Krzysztof Helt | b083194 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 941 | printk(KERN_ERR "Failed to allocate video RAM: %d\n", ret); |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 942 | ret = -ENOMEM; |
| 943 | goto release_clock; |
| 944 | } |
Ben Dooks | aff39a8 | 2007-07-31 00:37:37 -0700 | [diff] [blame] | 945 | |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 946 | dprintk("got video memory\n"); |
| 947 | |
Krzysztof Helt | 110c1fa | 2007-10-16 01:28:55 -0700 | [diff] [blame] | 948 | s3c2410fb_init_registers(fbinfo); |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 949 | |
Krzysztof Helt | b083194 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 950 | s3c2410fb_check_var(&fbinfo->var, fbinfo); |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 951 | |
| 952 | ret = register_framebuffer(fbinfo); |
| 953 | if (ret < 0) { |
Krzysztof Helt | b083194 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 954 | printk(KERN_ERR "Failed to register framebuffer device: %d\n", |
| 955 | ret); |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 956 | goto free_video_memory; |
| 957 | } |
| 958 | |
| 959 | /* create device files */ |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 960 | device_create_file(&pdev->dev, &dev_attr_debug); |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 961 | |
| 962 | printk(KERN_INFO "fb%d: %s frame buffer device\n", |
| 963 | fbinfo->node, fbinfo->fix.id); |
| 964 | |
| 965 | return 0; |
| 966 | |
| 967 | free_video_memory: |
| 968 | s3c2410fb_unmap_video_memory(info); |
| 969 | release_clock: |
| 970 | clk_disable(info->clk); |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 971 | clk_put(info->clk); |
| 972 | release_irq: |
Krzysztof Helt | b083194 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 973 | free_irq(irq, info); |
Ben Dooks | aff39a8 | 2007-07-31 00:37:37 -0700 | [diff] [blame] | 974 | release_regs: |
| 975 | iounmap(info->io); |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 976 | release_mem: |
Ben Dooks | aff39a8 | 2007-07-31 00:37:37 -0700 | [diff] [blame] | 977 | release_resource(info->mem); |
| 978 | kfree(info->mem); |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 979 | dealloc_fb: |
| 980 | framebuffer_release(fbinfo); |
| 981 | return ret; |
| 982 | } |
| 983 | |
| 984 | /* s3c2410fb_stop_lcd |
| 985 | * |
| 986 | * shutdown the lcd controller |
Krzysztof Helt | b083194 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 987 | */ |
Arnaud Patard | 6931a76 | 2006-06-26 00:26:45 -0700 | [diff] [blame] | 988 | static void s3c2410fb_stop_lcd(struct s3c2410fb_info *fbi) |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 989 | { |
| 990 | unsigned long flags; |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 991 | |
| 992 | local_irq_save(flags); |
| 993 | |
Arnaud Patard | 6931a76 | 2006-06-26 00:26:45 -0700 | [diff] [blame] | 994 | fbi->regs.lcdcon1 &= ~S3C2410_LCDCON1_ENVID; |
Ben Dooks | aff39a8 | 2007-07-31 00:37:37 -0700 | [diff] [blame] | 995 | writel(fbi->regs.lcdcon1, fbi->io + S3C2410_LCDCON1); |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 996 | |
| 997 | local_irq_restore(flags); |
| 998 | } |
| 999 | |
| 1000 | /* |
| 1001 | * Cleanup |
| 1002 | */ |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1003 | static int s3c2410fb_remove(struct platform_device *pdev) |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 1004 | { |
Krzysztof Helt | b083194 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 1005 | struct fb_info *fbinfo = platform_get_drvdata(pdev); |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 1006 | struct s3c2410fb_info *info = fbinfo->par; |
| 1007 | int irq; |
| 1008 | |
Arnaud Patard | 6931a76 | 2006-06-26 00:26:45 -0700 | [diff] [blame] | 1009 | s3c2410fb_stop_lcd(info); |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 1010 | msleep(1); |
| 1011 | |
| 1012 | s3c2410fb_unmap_video_memory(info); |
| 1013 | |
Krzysztof Helt | b083194 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 1014 | if (info->clk) { |
| 1015 | clk_disable(info->clk); |
| 1016 | clk_put(info->clk); |
| 1017 | info->clk = NULL; |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 1018 | } |
| 1019 | |
| 1020 | irq = platform_get_irq(pdev, 0); |
Krzysztof Helt | b083194 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 1021 | free_irq(irq, info); |
Ben Dooks | aff39a8 | 2007-07-31 00:37:37 -0700 | [diff] [blame] | 1022 | |
| 1023 | release_resource(info->mem); |
| 1024 | kfree(info->mem); |
| 1025 | iounmap(info->io); |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 1026 | unregister_framebuffer(fbinfo); |
| 1027 | |
| 1028 | return 0; |
| 1029 | } |
| 1030 | |
| 1031 | #ifdef CONFIG_PM |
| 1032 | |
| 1033 | /* suspend and resume support for the lcd controller */ |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1034 | static int s3c2410fb_suspend(struct platform_device *dev, pm_message_t state) |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 1035 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1036 | struct fb_info *fbinfo = platform_get_drvdata(dev); |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 1037 | struct s3c2410fb_info *info = fbinfo->par; |
| 1038 | |
Arnaud Patard | 6931a76 | 2006-06-26 00:26:45 -0700 | [diff] [blame] | 1039 | s3c2410fb_stop_lcd(info); |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 1040 | |
Russell King | 9480e30 | 2005-10-28 09:52:56 -0700 | [diff] [blame] | 1041 | /* sleep before disabling the clock, we need to ensure |
| 1042 | * the LCD DMA engine is not going to get back on the bus |
| 1043 | * before the clock goes off again (bjd) */ |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 1044 | |
Russell King | 9480e30 | 2005-10-28 09:52:56 -0700 | [diff] [blame] | 1045 | msleep(1); |
| 1046 | clk_disable(info->clk); |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 1047 | |
| 1048 | return 0; |
| 1049 | } |
| 1050 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1051 | static int s3c2410fb_resume(struct platform_device *dev) |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 1052 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1053 | struct fb_info *fbinfo = platform_get_drvdata(dev); |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 1054 | struct s3c2410fb_info *info = fbinfo->par; |
| 1055 | |
Russell King | 9480e30 | 2005-10-28 09:52:56 -0700 | [diff] [blame] | 1056 | clk_enable(info->clk); |
| 1057 | msleep(1); |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 1058 | |
Russell King | 9480e30 | 2005-10-28 09:52:56 -0700 | [diff] [blame] | 1059 | s3c2410fb_init_registers(info); |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 1060 | |
| 1061 | return 0; |
| 1062 | } |
| 1063 | |
| 1064 | #else |
| 1065 | #define s3c2410fb_suspend NULL |
| 1066 | #define s3c2410fb_resume NULL |
| 1067 | #endif |
| 1068 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1069 | static struct platform_driver s3c2410fb_driver = { |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 1070 | .probe = s3c2410fb_probe, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1071 | .remove = s3c2410fb_remove, |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 1072 | .suspend = s3c2410fb_suspend, |
| 1073 | .resume = s3c2410fb_resume, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1074 | .driver = { |
| 1075 | .name = "s3c2410-lcd", |
| 1076 | .owner = THIS_MODULE, |
| 1077 | }, |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 1078 | }; |
| 1079 | |
| 1080 | int __devinit s3c2410fb_init(void) |
| 1081 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1082 | return platform_driver_register(&s3c2410fb_driver); |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 1083 | } |
| 1084 | |
| 1085 | static void __exit s3c2410fb_cleanup(void) |
| 1086 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1087 | platform_driver_unregister(&s3c2410fb_driver); |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 1088 | } |
| 1089 | |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 1090 | module_init(s3c2410fb_init); |
| 1091 | module_exit(s3c2410fb_cleanup); |
| 1092 | |
Krzysztof Helt | b083194 | 2007-10-16 01:28:54 -0700 | [diff] [blame] | 1093 | MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>, " |
| 1094 | "Ben Dooks <ben-linux@fluff.org>"); |
Arnaud Patard | 20fd576 | 2005-09-09 13:10:07 -0700 | [diff] [blame] | 1095 | MODULE_DESCRIPTION("Framebuffer driver for the s3c2410"); |
| 1096 | MODULE_LICENSE("GPL"); |