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