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