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