Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 1 | /* linux/drivers/video/s3c-fb.c |
| 2 | * |
| 3 | * Copyright 2008 Openmoko Inc. |
Ben Dooks | 50a5503 | 2010-08-10 18:02:33 -0700 | [diff] [blame] | 4 | * Copyright 2008-2010 Simtec Electronics |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 5 | * Ben Dooks <ben@simtec.co.uk> |
| 6 | * http://armlinux.simtec.co.uk/ |
| 7 | * |
| 8 | * Samsung SoC Framebuffer driver |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License version 2 as |
Ben Dooks | c4bb6ff | 2010-08-10 18:02:34 -0700 | [diff] [blame^] | 12 | * published by the Free Software FoundatIon. |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 13 | */ |
| 14 | |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/module.h> |
| 17 | #include <linux/platform_device.h> |
| 18 | #include <linux/dma-mapping.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 19 | #include <linux/slab.h> |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 20 | #include <linux/init.h> |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 21 | #include <linux/clk.h> |
| 22 | #include <linux/fb.h> |
| 23 | #include <linux/io.h> |
| 24 | |
| 25 | #include <mach/map.h> |
Ben Dooks | c4bb6ff | 2010-08-10 18:02:34 -0700 | [diff] [blame^] | 26 | #include <plat/regs-fb-v4.h> |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 27 | #include <plat/fb.h> |
| 28 | |
| 29 | /* This driver will export a number of framebuffer interfaces depending |
| 30 | * on the configuration passed in via the platform data. Each fb instance |
| 31 | * maps to a hardware window. Currently there is no support for runtime |
| 32 | * setting of the alpha-blending functions that each window has, so only |
| 33 | * window 0 is actually useful. |
| 34 | * |
| 35 | * Window 0 is treated specially, it is used for the basis of the LCD |
| 36 | * output timings and as the control for the output power-down state. |
| 37 | */ |
| 38 | |
Ben Dooks | 50a5503 | 2010-08-10 18:02:33 -0700 | [diff] [blame] | 39 | /* note, the previous use of <mach/regs-fb.h> to get platform specific data |
| 40 | * has been replaced by using the platform device name to pick the correct |
| 41 | * configuration data for the system. |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 42 | */ |
| 43 | |
| 44 | #ifdef CONFIG_FB_S3C_DEBUG_REGWRITE |
| 45 | #undef writel |
| 46 | #define writel(v, r) do { \ |
| 47 | printk(KERN_DEBUG "%s: %08x => %p\n", __func__, (unsigned int)v, r); \ |
| 48 | __raw_writel(v, r); } while(0) |
| 49 | #endif /* FB_S3C_DEBUG_REGWRITE */ |
| 50 | |
| 51 | struct s3c_fb; |
| 52 | |
Ben Dooks | 50a5503 | 2010-08-10 18:02:33 -0700 | [diff] [blame] | 53 | #define VALID_BPP(x) (1 << ((x) - 1)) |
| 54 | |
Ben Dooks | c4bb6ff | 2010-08-10 18:02:34 -0700 | [diff] [blame^] | 55 | #define OSD_BASE(win, variant) ((variant).osd + ((win) * (variant).osd_stride)) |
| 56 | #define VIDOSD_A(win, variant) (OSD_BASE(win, variant) + 0x00) |
| 57 | #define VIDOSD_B(win, variant) (OSD_BASE(win, variant) + 0x04) |
| 58 | #define VIDOSD_C(win, variant) (OSD_BASE(win, variant) + 0x08) |
| 59 | #define VIDOSD_D(win, variant) (OSD_BASE(win, variant) + 0x0C) |
| 60 | |
Ben Dooks | 50a5503 | 2010-08-10 18:02:33 -0700 | [diff] [blame] | 61 | /** |
| 62 | * struct s3c_fb_variant - fb variant information |
Ben Dooks | c4bb6ff | 2010-08-10 18:02:34 -0700 | [diff] [blame^] | 63 | * @is_2443: Set if S3C2443/S3C2416 style hardware. |
Ben Dooks | 50a5503 | 2010-08-10 18:02:33 -0700 | [diff] [blame] | 64 | * @nr_windows: The number of windows. |
Ben Dooks | c4bb6ff | 2010-08-10 18:02:34 -0700 | [diff] [blame^] | 65 | * @vidtcon: The base for the VIDTCONx registers |
| 66 | * @wincon: The base for the WINxCON registers. |
| 67 | * @winmap: The base for the WINxMAP registers. |
| 68 | * @keycon: The abse for the WxKEYCON registers. |
| 69 | * @buf_start: Offset of buffer start registers. |
| 70 | * @buf_size: Offset of buffer size registers. |
| 71 | * @buf_end: Offset of buffer end registers. |
| 72 | * @osd: The base for the OSD registers. |
Ben Dooks | 50a5503 | 2010-08-10 18:02:33 -0700 | [diff] [blame] | 73 | * @palette: Address of palette memory, or 0 if none. |
| 74 | */ |
| 75 | struct s3c_fb_variant { |
Ben Dooks | c4bb6ff | 2010-08-10 18:02:34 -0700 | [diff] [blame^] | 76 | unsigned int is_2443:1; |
Ben Dooks | 50a5503 | 2010-08-10 18:02:33 -0700 | [diff] [blame] | 77 | unsigned short nr_windows; |
Ben Dooks | c4bb6ff | 2010-08-10 18:02:34 -0700 | [diff] [blame^] | 78 | unsigned short vidtcon; |
| 79 | unsigned short wincon; |
| 80 | unsigned short winmap; |
| 81 | unsigned short keycon; |
| 82 | unsigned short buf_start; |
| 83 | unsigned short buf_end; |
| 84 | unsigned short buf_size; |
| 85 | unsigned short osd; |
| 86 | unsigned short osd_stride; |
Ben Dooks | 50a5503 | 2010-08-10 18:02:33 -0700 | [diff] [blame] | 87 | unsigned short palette[S3C_FB_MAX_WIN]; |
| 88 | }; |
| 89 | |
| 90 | /** |
| 91 | * struct s3c_fb_win_variant |
| 92 | * @has_osd_c: Set if has OSD C register. |
| 93 | * @has_osd_d: Set if has OSD D register. |
| 94 | * @palette_sz: Size of palette in entries. |
| 95 | * @palette_16bpp: Set if palette is 16bits wide. |
| 96 | * @valid_bpp: 1 bit per BPP setting to show valid bits-per-pixel. |
| 97 | * |
| 98 | * valid_bpp bit x is set if (x+1)BPP is supported. |
| 99 | */ |
| 100 | struct s3c_fb_win_variant { |
| 101 | unsigned int has_osd_c:1; |
| 102 | unsigned int has_osd_d:1; |
| 103 | unsigned int palette_16bpp:1; |
| 104 | unsigned short palette_sz; |
| 105 | u32 valid_bpp; |
| 106 | }; |
| 107 | |
| 108 | /** |
| 109 | * struct s3c_fb_driverdata - per-device type driver data for init time. |
| 110 | * @variant: The variant information for this driver. |
| 111 | * @win: The window information for each window. |
| 112 | */ |
| 113 | struct s3c_fb_driverdata { |
| 114 | struct s3c_fb_variant variant; |
| 115 | struct s3c_fb_win_variant *win[S3C_FB_MAX_WIN]; |
| 116 | }; |
| 117 | |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 118 | /** |
| 119 | * struct s3c_fb_win - per window private data for each framebuffer. |
| 120 | * @windata: The platform data supplied for the window configuration. |
| 121 | * @parent: The hardware that this window is part of. |
| 122 | * @fbinfo: Pointer pack to the framebuffer info for this window. |
Ben Dooks | 50a5503 | 2010-08-10 18:02:33 -0700 | [diff] [blame] | 123 | * @varint: The variant information for this window. |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 124 | * @palette_buffer: Buffer/cache to hold palette entries. |
| 125 | * @pseudo_palette: For use in TRUECOLOUR modes for entries 0..15/ |
| 126 | * @index: The window number of this window. |
| 127 | * @palette: The bitfields for changing r/g/b into a hardware palette entry. |
| 128 | */ |
| 129 | struct s3c_fb_win { |
| 130 | struct s3c_fb_pd_win *windata; |
| 131 | struct s3c_fb *parent; |
| 132 | struct fb_info *fbinfo; |
| 133 | struct s3c_fb_palette palette; |
Ben Dooks | 50a5503 | 2010-08-10 18:02:33 -0700 | [diff] [blame] | 134 | struct s3c_fb_win_variant variant; |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 135 | |
| 136 | u32 *palette_buffer; |
| 137 | u32 pseudo_palette[16]; |
| 138 | unsigned int index; |
| 139 | }; |
| 140 | |
| 141 | /** |
| 142 | * struct s3c_fb - overall hardware state of the hardware |
| 143 | * @dev: The device that we bound to, for printing, etc. |
| 144 | * @regs_res: The resource we claimed for the IO registers. |
| 145 | * @bus_clk: The clk (hclk) feeding our interface and possibly pixclk. |
| 146 | * @regs: The mapped hardware registers. |
Ben Dooks | 50a5503 | 2010-08-10 18:02:33 -0700 | [diff] [blame] | 147 | * @variant: Variant information for this hardware. |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 148 | * @enabled: A bitmask of enabled hardware windows. |
| 149 | * @pdata: The platform configuration data passed with the device. |
| 150 | * @windows: The hardware windows that have been claimed. |
| 151 | */ |
| 152 | struct s3c_fb { |
| 153 | struct device *dev; |
| 154 | struct resource *regs_res; |
| 155 | struct clk *bus_clk; |
| 156 | void __iomem *regs; |
Ben Dooks | 50a5503 | 2010-08-10 18:02:33 -0700 | [diff] [blame] | 157 | struct s3c_fb_variant variant; |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 158 | |
| 159 | unsigned char enabled; |
| 160 | |
| 161 | struct s3c_fb_platdata *pdata; |
| 162 | struct s3c_fb_win *windows[S3C_FB_MAX_WIN]; |
| 163 | }; |
| 164 | |
| 165 | /** |
Ben Dooks | 50a5503 | 2010-08-10 18:02:33 -0700 | [diff] [blame] | 166 | * s3c_fb_validate_win_bpp - validate the bits-per-pixel for this mode. |
| 167 | * @win: The device window. |
| 168 | * @bpp: The bit depth. |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 169 | */ |
Ben Dooks | 50a5503 | 2010-08-10 18:02:33 -0700 | [diff] [blame] | 170 | static bool s3c_fb_validate_win_bpp(struct s3c_fb_win *win, unsigned int bpp) |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 171 | { |
Ben Dooks | 50a5503 | 2010-08-10 18:02:33 -0700 | [diff] [blame] | 172 | return win->variant.valid_bpp & VALID_BPP(bpp); |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | /** |
| 176 | * s3c_fb_check_var() - framebuffer layer request to verify a given mode. |
| 177 | * @var: The screen information to verify. |
| 178 | * @info: The framebuffer device. |
| 179 | * |
| 180 | * Framebuffer layer call to verify the given information and allow us to |
| 181 | * update various information depending on the hardware capabilities. |
| 182 | */ |
| 183 | static int s3c_fb_check_var(struct fb_var_screeninfo *var, |
| 184 | struct fb_info *info) |
| 185 | { |
| 186 | struct s3c_fb_win *win = info->par; |
| 187 | struct s3c_fb_pd_win *windata = win->windata; |
| 188 | struct s3c_fb *sfb = win->parent; |
| 189 | |
| 190 | dev_dbg(sfb->dev, "checking parameters\n"); |
| 191 | |
| 192 | var->xres_virtual = max((unsigned int)windata->virtual_x, var->xres); |
| 193 | var->yres_virtual = max((unsigned int)windata->virtual_y, var->yres); |
| 194 | |
Ben Dooks | 50a5503 | 2010-08-10 18:02:33 -0700 | [diff] [blame] | 195 | if (!s3c_fb_validate_win_bpp(win, var->bits_per_pixel)) { |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 196 | dev_dbg(sfb->dev, "win %d: unsupported bpp %d\n", |
| 197 | win->index, var->bits_per_pixel); |
| 198 | return -EINVAL; |
| 199 | } |
| 200 | |
| 201 | /* always ensure these are zero, for drop through cases below */ |
| 202 | var->transp.offset = 0; |
| 203 | var->transp.length = 0; |
| 204 | |
| 205 | switch (var->bits_per_pixel) { |
| 206 | case 1: |
| 207 | case 2: |
| 208 | case 4: |
| 209 | case 8: |
Ben Dooks | 50a5503 | 2010-08-10 18:02:33 -0700 | [diff] [blame] | 210 | if (sfb->variant.palette[win->index] != 0) { |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 211 | /* non palletised, A:1,R:2,G:3,B:2 mode */ |
| 212 | var->red.offset = 4; |
| 213 | var->green.offset = 2; |
| 214 | var->blue.offset = 0; |
| 215 | var->red.length = 5; |
| 216 | var->green.length = 3; |
| 217 | var->blue.length = 2; |
| 218 | var->transp.offset = 7; |
| 219 | var->transp.length = 1; |
| 220 | } else { |
| 221 | var->red.offset = 0; |
| 222 | var->red.length = var->bits_per_pixel; |
| 223 | var->green = var->red; |
| 224 | var->blue = var->red; |
| 225 | } |
| 226 | break; |
| 227 | |
| 228 | case 19: |
| 229 | /* 666 with one bit alpha/transparency */ |
| 230 | var->transp.offset = 18; |
| 231 | var->transp.length = 1; |
| 232 | case 18: |
| 233 | var->bits_per_pixel = 32; |
| 234 | |
| 235 | /* 666 format */ |
| 236 | var->red.offset = 12; |
| 237 | var->green.offset = 6; |
| 238 | var->blue.offset = 0; |
| 239 | var->red.length = 6; |
| 240 | var->green.length = 6; |
| 241 | var->blue.length = 6; |
| 242 | break; |
| 243 | |
| 244 | case 16: |
| 245 | /* 16 bpp, 565 format */ |
| 246 | var->red.offset = 11; |
| 247 | var->green.offset = 5; |
| 248 | var->blue.offset = 0; |
| 249 | var->red.length = 5; |
| 250 | var->green.length = 6; |
| 251 | var->blue.length = 5; |
| 252 | break; |
| 253 | |
| 254 | case 28: |
| 255 | case 25: |
| 256 | var->transp.length = var->bits_per_pixel - 24; |
| 257 | var->transp.offset = 24; |
| 258 | /* drop through */ |
| 259 | case 24: |
| 260 | /* our 24bpp is unpacked, so 32bpp */ |
| 261 | var->bits_per_pixel = 32; |
| 262 | case 32: |
| 263 | var->red.offset = 16; |
| 264 | var->red.length = 8; |
| 265 | var->green.offset = 8; |
| 266 | var->green.length = 8; |
| 267 | var->blue.offset = 0; |
| 268 | var->blue.length = 8; |
| 269 | break; |
| 270 | |
| 271 | default: |
| 272 | dev_err(sfb->dev, "invalid bpp\n"); |
| 273 | } |
| 274 | |
| 275 | dev_dbg(sfb->dev, "%s: verified parameters\n", __func__); |
| 276 | return 0; |
| 277 | } |
| 278 | |
| 279 | /** |
| 280 | * s3c_fb_calc_pixclk() - calculate the divider to create the pixel clock. |
| 281 | * @sfb: The hardware state. |
| 282 | * @pixclock: The pixel clock wanted, in picoseconds. |
| 283 | * |
| 284 | * Given the specified pixel clock, work out the necessary divider to get |
| 285 | * close to the output frequency. |
| 286 | */ |
Mark Brown | eb29a5c | 2010-01-15 17:01:40 -0800 | [diff] [blame] | 287 | static int s3c_fb_calc_pixclk(struct s3c_fb *sfb, unsigned int pixclk) |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 288 | { |
| 289 | unsigned long clk = clk_get_rate(sfb->bus_clk); |
Mark Brown | eb29a5c | 2010-01-15 17:01:40 -0800 | [diff] [blame] | 290 | unsigned long long tmp; |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 291 | unsigned int result; |
| 292 | |
Mark Brown | eb29a5c | 2010-01-15 17:01:40 -0800 | [diff] [blame] | 293 | tmp = (unsigned long long)clk; |
| 294 | tmp *= pixclk; |
| 295 | |
| 296 | do_div(tmp, 1000000000UL); |
| 297 | result = (unsigned int)tmp / 1000; |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 298 | |
| 299 | dev_dbg(sfb->dev, "pixclk=%u, clk=%lu, div=%d (%lu)\n", |
| 300 | pixclk, clk, result, clk / result); |
| 301 | |
| 302 | return result; |
| 303 | } |
| 304 | |
| 305 | /** |
| 306 | * s3c_fb_align_word() - align pixel count to word boundary |
| 307 | * @bpp: The number of bits per pixel |
| 308 | * @pix: The value to be aligned. |
| 309 | * |
| 310 | * Align the given pixel count so that it will start on an 32bit word |
| 311 | * boundary. |
| 312 | */ |
| 313 | static int s3c_fb_align_word(unsigned int bpp, unsigned int pix) |
| 314 | { |
| 315 | int pix_per_word; |
| 316 | |
| 317 | if (bpp > 16) |
| 318 | return pix; |
| 319 | |
| 320 | pix_per_word = (8 * 32) / bpp; |
| 321 | return ALIGN(pix, pix_per_word); |
| 322 | } |
| 323 | |
| 324 | /** |
| 325 | * s3c_fb_set_par() - framebuffer request to set new framebuffer state. |
| 326 | * @info: The framebuffer to change. |
| 327 | * |
| 328 | * Framebuffer layer request to set a new mode for the specified framebuffer |
| 329 | */ |
| 330 | static int s3c_fb_set_par(struct fb_info *info) |
| 331 | { |
| 332 | struct fb_var_screeninfo *var = &info->var; |
| 333 | struct s3c_fb_win *win = info->par; |
| 334 | struct s3c_fb *sfb = win->parent; |
| 335 | void __iomem *regs = sfb->regs; |
Ben Dooks | c4bb6ff | 2010-08-10 18:02:34 -0700 | [diff] [blame^] | 336 | void __iomem *buf = regs; |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 337 | int win_no = win->index; |
InKi Dae | 600ce1a | 2009-07-05 12:08:21 -0700 | [diff] [blame] | 338 | u32 osdc_data = 0; |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 339 | u32 data; |
| 340 | u32 pagewidth; |
| 341 | int clkdiv; |
| 342 | |
| 343 | dev_dbg(sfb->dev, "setting framebuffer parameters\n"); |
| 344 | |
| 345 | switch (var->bits_per_pixel) { |
| 346 | case 32: |
| 347 | case 24: |
| 348 | case 16: |
| 349 | case 12: |
| 350 | info->fix.visual = FB_VISUAL_TRUECOLOR; |
| 351 | break; |
| 352 | case 8: |
Ben Dooks | 50a5503 | 2010-08-10 18:02:33 -0700 | [diff] [blame] | 353 | if (win->variant.palette_sz >= 256) |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 354 | info->fix.visual = FB_VISUAL_PSEUDOCOLOR; |
| 355 | else |
| 356 | info->fix.visual = FB_VISUAL_TRUECOLOR; |
| 357 | break; |
| 358 | case 1: |
| 359 | info->fix.visual = FB_VISUAL_MONO01; |
| 360 | break; |
| 361 | default: |
| 362 | info->fix.visual = FB_VISUAL_PSEUDOCOLOR; |
| 363 | break; |
| 364 | } |
| 365 | |
| 366 | info->fix.line_length = (var->xres_virtual * var->bits_per_pixel) / 8; |
| 367 | |
| 368 | /* disable the window whilst we update it */ |
| 369 | writel(0, regs + WINCON(win_no)); |
| 370 | |
InKi Dae | ad04490 | 2010-08-10 18:02:31 -0700 | [diff] [blame] | 371 | /* use platform specified window as the basis for the lcd timings */ |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 372 | |
InKi Dae | ad04490 | 2010-08-10 18:02:31 -0700 | [diff] [blame] | 373 | if (win_no == sfb->pdata->default_win) { |
Mark Brown | eb29a5c | 2010-01-15 17:01:40 -0800 | [diff] [blame] | 374 | clkdiv = s3c_fb_calc_pixclk(sfb, var->pixclock); |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 375 | |
| 376 | data = sfb->pdata->vidcon0; |
| 377 | data &= ~(VIDCON0_CLKVAL_F_MASK | VIDCON0_CLKDIR); |
| 378 | |
| 379 | if (clkdiv > 1) |
| 380 | data |= VIDCON0_CLKVAL_F(clkdiv-1) | VIDCON0_CLKDIR; |
| 381 | else |
| 382 | data &= ~VIDCON0_CLKDIR; /* 1:1 clock */ |
| 383 | |
| 384 | /* write the timing data to the panel */ |
| 385 | |
Ben Dooks | c4bb6ff | 2010-08-10 18:02:34 -0700 | [diff] [blame^] | 386 | if (sfb->variant.is_2443) |
| 387 | data |= (1 << 5); |
| 388 | |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 389 | data |= VIDCON0_ENVID | VIDCON0_ENVID_F; |
| 390 | writel(data, regs + VIDCON0); |
| 391 | |
| 392 | data = VIDTCON0_VBPD(var->upper_margin - 1) | |
| 393 | VIDTCON0_VFPD(var->lower_margin - 1) | |
| 394 | VIDTCON0_VSPW(var->vsync_len - 1); |
| 395 | |
Ben Dooks | c4bb6ff | 2010-08-10 18:02:34 -0700 | [diff] [blame^] | 396 | writel(data, regs + sfb->variant.vidtcon); |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 397 | |
| 398 | data = VIDTCON1_HBPD(var->left_margin - 1) | |
| 399 | VIDTCON1_HFPD(var->right_margin - 1) | |
| 400 | VIDTCON1_HSPW(var->hsync_len - 1); |
| 401 | |
Ben Dooks | c4bb6ff | 2010-08-10 18:02:34 -0700 | [diff] [blame^] | 402 | /* VIDTCON1 */ |
| 403 | writel(data, regs + sfb->variant.vidtcon + 4); |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 404 | |
| 405 | data = VIDTCON2_LINEVAL(var->yres - 1) | |
| 406 | VIDTCON2_HOZVAL(var->xres - 1); |
Ben Dooks | c4bb6ff | 2010-08-10 18:02:34 -0700 | [diff] [blame^] | 407 | writel(data, regs +sfb->variant.vidtcon + 8 ); |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | /* write the buffer address */ |
| 411 | |
Ben Dooks | c4bb6ff | 2010-08-10 18:02:34 -0700 | [diff] [blame^] | 412 | /* start and end registers stride is 8 */ |
| 413 | buf = regs + win_no * 8; |
| 414 | |
| 415 | writel(info->fix.smem_start, buf + sfb->variant.buf_start); |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 416 | |
| 417 | data = info->fix.smem_start + info->fix.line_length * var->yres; |
Ben Dooks | c4bb6ff | 2010-08-10 18:02:34 -0700 | [diff] [blame^] | 418 | writel(data, buf + sfb->variant.buf_end); |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 419 | |
| 420 | pagewidth = (var->xres * var->bits_per_pixel) >> 3; |
| 421 | data = VIDW_BUF_SIZE_OFFSET(info->fix.line_length - pagewidth) | |
| 422 | VIDW_BUF_SIZE_PAGEWIDTH(pagewidth); |
Ben Dooks | c4bb6ff | 2010-08-10 18:02:34 -0700 | [diff] [blame^] | 423 | writel(data, regs + sfb->variant.buf_size + (win_no * 4)); |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 424 | |
| 425 | /* write 'OSD' registers to control position of framebuffer */ |
| 426 | |
| 427 | data = VIDOSDxA_TOPLEFT_X(0) | VIDOSDxA_TOPLEFT_Y(0); |
Ben Dooks | c4bb6ff | 2010-08-10 18:02:34 -0700 | [diff] [blame^] | 428 | writel(data, regs + VIDOSD_A(win_no, sfb->variant)); |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 429 | |
| 430 | data = VIDOSDxB_BOTRIGHT_X(s3c_fb_align_word(var->bits_per_pixel, |
| 431 | var->xres - 1)) | |
| 432 | VIDOSDxB_BOTRIGHT_Y(var->yres - 1); |
| 433 | |
Ben Dooks | c4bb6ff | 2010-08-10 18:02:34 -0700 | [diff] [blame^] | 434 | writel(data, regs + VIDOSD_B(win_no, sfb->variant)); |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 435 | |
| 436 | data = var->xres * var->yres; |
InKi Dae | 39000d6 | 2009-06-16 15:34:27 -0700 | [diff] [blame] | 437 | |
InKi Dae | 39000d6 | 2009-06-16 15:34:27 -0700 | [diff] [blame] | 438 | osdc_data = VIDISD14C_ALPHA1_R(0xf) | |
| 439 | VIDISD14C_ALPHA1_G(0xf) | |
| 440 | VIDISD14C_ALPHA1_B(0xf); |
| 441 | |
Ben Dooks | 50a5503 | 2010-08-10 18:02:33 -0700 | [diff] [blame] | 442 | if (win->variant.has_osd_d) { |
Ben Dooks | c4bb6ff | 2010-08-10 18:02:34 -0700 | [diff] [blame^] | 443 | writel(data, regs + VIDOSD_D(win_no, sfb->variant)); |
| 444 | writel(osdc_data, regs + VIDOSD_C(win_no, sfb->variant)); |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 445 | } else |
Ben Dooks | c4bb6ff | 2010-08-10 18:02:34 -0700 | [diff] [blame^] | 446 | writel(data, regs + VIDOSD_C(win_no, sfb->variant)); |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 447 | |
| 448 | data = WINCONx_ENWIN; |
| 449 | |
| 450 | /* note, since we have to round up the bits-per-pixel, we end up |
| 451 | * relying on the bitfield information for r/g/b/a to work out |
| 452 | * exactly which mode of operation is intended. */ |
| 453 | |
| 454 | switch (var->bits_per_pixel) { |
| 455 | case 1: |
| 456 | data |= WINCON0_BPPMODE_1BPP; |
| 457 | data |= WINCONx_BITSWP; |
| 458 | data |= WINCONx_BURSTLEN_4WORD; |
| 459 | break; |
| 460 | case 2: |
| 461 | data |= WINCON0_BPPMODE_2BPP; |
| 462 | data |= WINCONx_BITSWP; |
| 463 | data |= WINCONx_BURSTLEN_8WORD; |
| 464 | break; |
| 465 | case 4: |
| 466 | data |= WINCON0_BPPMODE_4BPP; |
| 467 | data |= WINCONx_BITSWP; |
| 468 | data |= WINCONx_BURSTLEN_8WORD; |
| 469 | break; |
| 470 | case 8: |
| 471 | if (var->transp.length != 0) |
| 472 | data |= WINCON1_BPPMODE_8BPP_1232; |
| 473 | else |
| 474 | data |= WINCON0_BPPMODE_8BPP_PALETTE; |
| 475 | data |= WINCONx_BURSTLEN_8WORD; |
| 476 | data |= WINCONx_BYTSWP; |
| 477 | break; |
| 478 | case 16: |
| 479 | if (var->transp.length != 0) |
| 480 | data |= WINCON1_BPPMODE_16BPP_A1555; |
| 481 | else |
| 482 | data |= WINCON0_BPPMODE_16BPP_565; |
| 483 | data |= WINCONx_HAWSWP; |
| 484 | data |= WINCONx_BURSTLEN_16WORD; |
| 485 | break; |
| 486 | case 24: |
| 487 | case 32: |
| 488 | if (var->red.length == 6) { |
| 489 | if (var->transp.length != 0) |
| 490 | data |= WINCON1_BPPMODE_19BPP_A1666; |
| 491 | else |
| 492 | data |= WINCON1_BPPMODE_18BPP_666; |
InKi Dae | 39000d6 | 2009-06-16 15:34:27 -0700 | [diff] [blame] | 493 | } else if (var->transp.length == 1) |
| 494 | data |= WINCON1_BPPMODE_25BPP_A1888 |
| 495 | | WINCON1_BLD_PIX; |
| 496 | else if (var->transp.length == 4) |
| 497 | data |= WINCON1_BPPMODE_28BPP_A4888 |
| 498 | | WINCON1_BLD_PIX | WINCON1_ALPHA_SEL; |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 499 | else |
| 500 | data |= WINCON0_BPPMODE_24BPP_888; |
| 501 | |
InKi Dae | dc8498c | 2010-08-10 18:02:32 -0700 | [diff] [blame] | 502 | data |= WINCONx_WSWP; |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 503 | data |= WINCONx_BURSTLEN_16WORD; |
| 504 | break; |
| 505 | } |
| 506 | |
Ben Dooks | c4bb6ff | 2010-08-10 18:02:34 -0700 | [diff] [blame^] | 507 | /* Enable the colour keying for the window below this one */ |
InKi Dae | 39000d6 | 2009-06-16 15:34:27 -0700 | [diff] [blame] | 508 | if (win_no > 0) { |
| 509 | u32 keycon0_data = 0, keycon1_data = 0; |
Ben Dooks | c4bb6ff | 2010-08-10 18:02:34 -0700 | [diff] [blame^] | 510 | void __iomem *keycon = regs + sfb->variant.keycon; |
InKi Dae | 39000d6 | 2009-06-16 15:34:27 -0700 | [diff] [blame] | 511 | |
| 512 | keycon0_data = ~(WxKEYCON0_KEYBL_EN | |
| 513 | WxKEYCON0_KEYEN_F | |
| 514 | WxKEYCON0_DIRCON) | WxKEYCON0_COMPKEY(0); |
| 515 | |
| 516 | keycon1_data = WxKEYCON1_COLVAL(0xffffff); |
| 517 | |
Ben Dooks | c4bb6ff | 2010-08-10 18:02:34 -0700 | [diff] [blame^] | 518 | keycon += (win_no - 1) * 8; |
| 519 | |
| 520 | writel(keycon0_data, keycon + WKEYCON0); |
| 521 | writel(keycon1_data, keycon + WKEYCON1); |
InKi Dae | 39000d6 | 2009-06-16 15:34:27 -0700 | [diff] [blame] | 522 | } |
| 523 | |
Ben Dooks | c4bb6ff | 2010-08-10 18:02:34 -0700 | [diff] [blame^] | 524 | writel(data, regs + sfb->variant.wincon + (win_no * 4)); |
| 525 | writel(0x0, regs + sfb->variant.winmap + (win_no * 4)); |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 526 | |
| 527 | return 0; |
| 528 | } |
| 529 | |
| 530 | /** |
| 531 | * s3c_fb_update_palette() - set or schedule a palette update. |
| 532 | * @sfb: The hardware information. |
| 533 | * @win: The window being updated. |
| 534 | * @reg: The palette index being changed. |
| 535 | * @value: The computed palette value. |
| 536 | * |
| 537 | * Change the value of a palette register, either by directly writing to |
| 538 | * the palette (this requires the palette RAM to be disconnected from the |
| 539 | * hardware whilst this is in progress) or schedule the update for later. |
| 540 | * |
| 541 | * At the moment, since we have no VSYNC interrupt support, we simply set |
| 542 | * the palette entry directly. |
| 543 | */ |
| 544 | static void s3c_fb_update_palette(struct s3c_fb *sfb, |
| 545 | struct s3c_fb_win *win, |
| 546 | unsigned int reg, |
| 547 | u32 value) |
| 548 | { |
| 549 | void __iomem *palreg; |
| 550 | u32 palcon; |
| 551 | |
Ben Dooks | 50a5503 | 2010-08-10 18:02:33 -0700 | [diff] [blame] | 552 | palreg = sfb->regs + sfb->variant.palette[win->index]; |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 553 | |
| 554 | dev_dbg(sfb->dev, "%s: win %d, reg %d (%p): %08x\n", |
| 555 | __func__, win->index, reg, palreg, value); |
| 556 | |
| 557 | win->palette_buffer[reg] = value; |
| 558 | |
| 559 | palcon = readl(sfb->regs + WPALCON); |
| 560 | writel(palcon | WPALCON_PAL_UPDATE, sfb->regs + WPALCON); |
| 561 | |
Ben Dooks | 50a5503 | 2010-08-10 18:02:33 -0700 | [diff] [blame] | 562 | if (win->variant.palette_16bpp) |
| 563 | writew(value, palreg + (reg * 2)); |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 564 | else |
Ben Dooks | 50a5503 | 2010-08-10 18:02:33 -0700 | [diff] [blame] | 565 | writel(value, palreg + (reg * 4)); |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 566 | |
| 567 | writel(palcon, sfb->regs + WPALCON); |
| 568 | } |
| 569 | |
| 570 | static inline unsigned int chan_to_field(unsigned int chan, |
| 571 | struct fb_bitfield *bf) |
| 572 | { |
| 573 | chan &= 0xffff; |
| 574 | chan >>= 16 - bf->length; |
| 575 | return chan << bf->offset; |
| 576 | } |
| 577 | |
| 578 | /** |
| 579 | * s3c_fb_setcolreg() - framebuffer layer request to change palette. |
| 580 | * @regno: The palette index to change. |
| 581 | * @red: The red field for the palette data. |
| 582 | * @green: The green field for the palette data. |
| 583 | * @blue: The blue field for the palette data. |
| 584 | * @trans: The transparency (alpha) field for the palette data. |
| 585 | * @info: The framebuffer being changed. |
| 586 | */ |
| 587 | static int s3c_fb_setcolreg(unsigned regno, |
| 588 | unsigned red, unsigned green, unsigned blue, |
| 589 | unsigned transp, struct fb_info *info) |
| 590 | { |
| 591 | struct s3c_fb_win *win = info->par; |
| 592 | struct s3c_fb *sfb = win->parent; |
| 593 | unsigned int val; |
| 594 | |
| 595 | dev_dbg(sfb->dev, "%s: win %d: %d => rgb=%d/%d/%d\n", |
| 596 | __func__, win->index, regno, red, green, blue); |
| 597 | |
| 598 | switch (info->fix.visual) { |
| 599 | case FB_VISUAL_TRUECOLOR: |
| 600 | /* true-colour, use pseudo-palette */ |
| 601 | |
| 602 | if (regno < 16) { |
| 603 | u32 *pal = info->pseudo_palette; |
| 604 | |
| 605 | val = chan_to_field(red, &info->var.red); |
| 606 | val |= chan_to_field(green, &info->var.green); |
| 607 | val |= chan_to_field(blue, &info->var.blue); |
| 608 | |
| 609 | pal[regno] = val; |
| 610 | } |
| 611 | break; |
| 612 | |
| 613 | case FB_VISUAL_PSEUDOCOLOR: |
Ben Dooks | 50a5503 | 2010-08-10 18:02:33 -0700 | [diff] [blame] | 614 | if (regno < win->variant.palette_sz) { |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 615 | val = chan_to_field(red, &win->palette.r); |
| 616 | val |= chan_to_field(green, &win->palette.g); |
| 617 | val |= chan_to_field(blue, &win->palette.b); |
| 618 | |
| 619 | s3c_fb_update_palette(sfb, win, regno, val); |
| 620 | } |
| 621 | |
| 622 | break; |
| 623 | |
| 624 | default: |
| 625 | return 1; /* unknown type */ |
| 626 | } |
| 627 | |
| 628 | return 0; |
| 629 | } |
| 630 | |
| 631 | /** |
| 632 | * s3c_fb_enable() - Set the state of the main LCD output |
| 633 | * @sfb: The main framebuffer state. |
| 634 | * @enable: The state to set. |
| 635 | */ |
| 636 | static void s3c_fb_enable(struct s3c_fb *sfb, int enable) |
| 637 | { |
| 638 | u32 vidcon0 = readl(sfb->regs + VIDCON0); |
| 639 | |
| 640 | if (enable) |
| 641 | vidcon0 |= VIDCON0_ENVID | VIDCON0_ENVID_F; |
| 642 | else { |
| 643 | /* see the note in the framebuffer datasheet about |
| 644 | * why you cannot take both of these bits down at the |
| 645 | * same time. */ |
| 646 | |
| 647 | if (!(vidcon0 & VIDCON0_ENVID)) |
| 648 | return; |
| 649 | |
| 650 | vidcon0 |= VIDCON0_ENVID; |
| 651 | vidcon0 &= ~VIDCON0_ENVID_F; |
| 652 | } |
| 653 | |
| 654 | writel(vidcon0, sfb->regs + VIDCON0); |
| 655 | } |
| 656 | |
| 657 | /** |
| 658 | * s3c_fb_blank() - blank or unblank the given window |
| 659 | * @blank_mode: The blank state from FB_BLANK_* |
| 660 | * @info: The framebuffer to blank. |
| 661 | * |
| 662 | * Framebuffer layer request to change the power state. |
| 663 | */ |
| 664 | static int s3c_fb_blank(int blank_mode, struct fb_info *info) |
| 665 | { |
| 666 | struct s3c_fb_win *win = info->par; |
| 667 | struct s3c_fb *sfb = win->parent; |
| 668 | unsigned int index = win->index; |
| 669 | u32 wincon; |
| 670 | |
| 671 | dev_dbg(sfb->dev, "blank mode %d\n", blank_mode); |
| 672 | |
Ben Dooks | c4bb6ff | 2010-08-10 18:02:34 -0700 | [diff] [blame^] | 673 | wincon = readl(sfb->regs + sfb->variant.wincon + (index * 4)); |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 674 | |
| 675 | switch (blank_mode) { |
| 676 | case FB_BLANK_POWERDOWN: |
| 677 | wincon &= ~WINCONx_ENWIN; |
| 678 | sfb->enabled &= ~(1 << index); |
| 679 | /* fall through to FB_BLANK_NORMAL */ |
| 680 | |
| 681 | case FB_BLANK_NORMAL: |
| 682 | /* disable the DMA and display 0x0 (black) */ |
| 683 | writel(WINxMAP_MAP | WINxMAP_MAP_COLOUR(0x0), |
Ben Dooks | c4bb6ff | 2010-08-10 18:02:34 -0700 | [diff] [blame^] | 684 | sfb->regs + sfb->variant.winmap + (index * 4)); |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 685 | break; |
| 686 | |
| 687 | case FB_BLANK_UNBLANK: |
Ben Dooks | c4bb6ff | 2010-08-10 18:02:34 -0700 | [diff] [blame^] | 688 | writel(0x0, sfb->regs + sfb->variant.winmap + (index * 4)); |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 689 | wincon |= WINCONx_ENWIN; |
| 690 | sfb->enabled |= (1 << index); |
| 691 | break; |
| 692 | |
| 693 | case FB_BLANK_VSYNC_SUSPEND: |
| 694 | case FB_BLANK_HSYNC_SUSPEND: |
| 695 | default: |
| 696 | return 1; |
| 697 | } |
| 698 | |
Ben Dooks | c4bb6ff | 2010-08-10 18:02:34 -0700 | [diff] [blame^] | 699 | writel(wincon, sfb->regs + sfb->variant.wincon + (index * 4)); |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 700 | |
| 701 | /* Check the enabled state to see if we need to be running the |
| 702 | * main LCD interface, as if there are no active windows then |
| 703 | * it is highly likely that we also do not need to output |
| 704 | * anything. |
| 705 | */ |
| 706 | |
| 707 | /* We could do something like the following code, but the current |
| 708 | * system of using framebuffer events means that we cannot make |
| 709 | * the distinction between just window 0 being inactive and all |
| 710 | * the windows being down. |
| 711 | * |
| 712 | * s3c_fb_enable(sfb, sfb->enabled ? 1 : 0); |
| 713 | */ |
| 714 | |
| 715 | /* we're stuck with this until we can do something about overriding |
| 716 | * the power control using the blanking event for a single fb. |
| 717 | */ |
InKi Dae | ad04490 | 2010-08-10 18:02:31 -0700 | [diff] [blame] | 718 | if (index == sfb->pdata->default_win) |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 719 | s3c_fb_enable(sfb, blank_mode != FB_BLANK_POWERDOWN ? 1 : 0); |
| 720 | |
| 721 | return 0; |
| 722 | } |
| 723 | |
| 724 | static struct fb_ops s3c_fb_ops = { |
| 725 | .owner = THIS_MODULE, |
| 726 | .fb_check_var = s3c_fb_check_var, |
| 727 | .fb_set_par = s3c_fb_set_par, |
| 728 | .fb_blank = s3c_fb_blank, |
| 729 | .fb_setcolreg = s3c_fb_setcolreg, |
| 730 | .fb_fillrect = cfb_fillrect, |
| 731 | .fb_copyarea = cfb_copyarea, |
| 732 | .fb_imageblit = cfb_imageblit, |
| 733 | }; |
| 734 | |
| 735 | /** |
| 736 | * s3c_fb_alloc_memory() - allocate display memory for framebuffer window |
| 737 | * @sfb: The base resources for the hardware. |
| 738 | * @win: The window to initialise memory for. |
| 739 | * |
| 740 | * Allocate memory for the given framebuffer. |
| 741 | */ |
| 742 | static int __devinit s3c_fb_alloc_memory(struct s3c_fb *sfb, |
| 743 | struct s3c_fb_win *win) |
| 744 | { |
| 745 | struct s3c_fb_pd_win *windata = win->windata; |
| 746 | unsigned int real_size, virt_size, size; |
| 747 | struct fb_info *fbi = win->fbinfo; |
| 748 | dma_addr_t map_dma; |
| 749 | |
| 750 | dev_dbg(sfb->dev, "allocating memory for display\n"); |
| 751 | |
| 752 | real_size = windata->win_mode.xres * windata->win_mode.yres; |
| 753 | virt_size = windata->virtual_x * windata->virtual_y; |
| 754 | |
| 755 | dev_dbg(sfb->dev, "real_size=%u (%u.%u), virt_size=%u (%u.%u)\n", |
| 756 | real_size, windata->win_mode.xres, windata->win_mode.yres, |
| 757 | virt_size, windata->virtual_x, windata->virtual_y); |
| 758 | |
| 759 | size = (real_size > virt_size) ? real_size : virt_size; |
| 760 | size *= (windata->max_bpp > 16) ? 32 : windata->max_bpp; |
| 761 | size /= 8; |
| 762 | |
| 763 | fbi->fix.smem_len = size; |
| 764 | size = PAGE_ALIGN(size); |
| 765 | |
| 766 | dev_dbg(sfb->dev, "want %u bytes for window\n", size); |
| 767 | |
| 768 | fbi->screen_base = dma_alloc_writecombine(sfb->dev, size, |
| 769 | &map_dma, GFP_KERNEL); |
| 770 | if (!fbi->screen_base) |
| 771 | return -ENOMEM; |
| 772 | |
| 773 | dev_dbg(sfb->dev, "mapped %x to %p\n", |
| 774 | (unsigned int)map_dma, fbi->screen_base); |
| 775 | |
| 776 | memset(fbi->screen_base, 0x0, size); |
| 777 | fbi->fix.smem_start = map_dma; |
| 778 | |
| 779 | return 0; |
| 780 | } |
| 781 | |
| 782 | /** |
| 783 | * s3c_fb_free_memory() - free the display memory for the given window |
| 784 | * @sfb: The base resources for the hardware. |
| 785 | * @win: The window to free the display memory for. |
| 786 | * |
| 787 | * Free the display memory allocated by s3c_fb_alloc_memory(). |
| 788 | */ |
| 789 | static void s3c_fb_free_memory(struct s3c_fb *sfb, struct s3c_fb_win *win) |
| 790 | { |
| 791 | struct fb_info *fbi = win->fbinfo; |
| 792 | |
| 793 | dma_free_writecombine(sfb->dev, PAGE_ALIGN(fbi->fix.smem_len), |
| 794 | fbi->screen_base, fbi->fix.smem_start); |
| 795 | } |
| 796 | |
| 797 | /** |
| 798 | * s3c_fb_release_win() - release resources for a framebuffer window. |
| 799 | * @win: The window to cleanup the resources for. |
| 800 | * |
| 801 | * Release the resources that where claimed for the hardware window, |
| 802 | * such as the framebuffer instance and any memory claimed for it. |
| 803 | */ |
| 804 | static void s3c_fb_release_win(struct s3c_fb *sfb, struct s3c_fb_win *win) |
| 805 | { |
Krzysztof Helt | ddc518d | 2009-06-16 15:34:33 -0700 | [diff] [blame] | 806 | if (win->fbinfo) { |
| 807 | unregister_framebuffer(win->fbinfo); |
| 808 | fb_dealloc_cmap(&win->fbinfo->cmap); |
| 809 | s3c_fb_free_memory(sfb, win); |
| 810 | framebuffer_release(win->fbinfo); |
| 811 | } |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | /** |
| 815 | * s3c_fb_probe_win() - register an hardware window |
| 816 | * @sfb: The base resources for the hardware |
Ben Dooks | 50a5503 | 2010-08-10 18:02:33 -0700 | [diff] [blame] | 817 | * @variant: The variant information for this window. |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 818 | * @res: Pointer to where to place the resultant window. |
| 819 | * |
| 820 | * Allocate and do the basic initialisation for one of the hardware's graphics |
| 821 | * windows. |
| 822 | */ |
| 823 | static int __devinit s3c_fb_probe_win(struct s3c_fb *sfb, unsigned int win_no, |
Ben Dooks | 50a5503 | 2010-08-10 18:02:33 -0700 | [diff] [blame] | 824 | struct s3c_fb_win_variant *variant, |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 825 | struct s3c_fb_win **res) |
| 826 | { |
| 827 | struct fb_var_screeninfo *var; |
| 828 | struct fb_videomode *initmode; |
| 829 | struct s3c_fb_pd_win *windata; |
| 830 | struct s3c_fb_win *win; |
| 831 | struct fb_info *fbinfo; |
| 832 | int palette_size; |
| 833 | int ret; |
| 834 | |
Ben Dooks | c4bb6ff | 2010-08-10 18:02:34 -0700 | [diff] [blame^] | 835 | dev_dbg(sfb->dev, "probing window %d, variant %p\n", win_no, variant); |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 836 | |
Ben Dooks | 50a5503 | 2010-08-10 18:02:33 -0700 | [diff] [blame] | 837 | palette_size = variant->palette_sz * 4; |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 838 | |
| 839 | fbinfo = framebuffer_alloc(sizeof(struct s3c_fb_win) + |
| 840 | palette_size * sizeof(u32), sfb->dev); |
| 841 | if (!fbinfo) { |
| 842 | dev_err(sfb->dev, "failed to allocate framebuffer\n"); |
| 843 | return -ENOENT; |
| 844 | } |
| 845 | |
| 846 | windata = sfb->pdata->win[win_no]; |
| 847 | initmode = &windata->win_mode; |
| 848 | |
| 849 | WARN_ON(windata->max_bpp == 0); |
| 850 | WARN_ON(windata->win_mode.xres == 0); |
| 851 | WARN_ON(windata->win_mode.yres == 0); |
| 852 | |
| 853 | win = fbinfo->par; |
| 854 | var = &fbinfo->var; |
Ben Dooks | 50a5503 | 2010-08-10 18:02:33 -0700 | [diff] [blame] | 855 | win->variant = *variant; |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 856 | win->fbinfo = fbinfo; |
| 857 | win->parent = sfb; |
| 858 | win->windata = windata; |
| 859 | win->index = win_no; |
| 860 | win->palette_buffer = (u32 *)(win + 1); |
| 861 | |
| 862 | ret = s3c_fb_alloc_memory(sfb, win); |
| 863 | if (ret) { |
| 864 | dev_err(sfb->dev, "failed to allocate display memory\n"); |
Krzysztof Helt | ddc518d | 2009-06-16 15:34:33 -0700 | [diff] [blame] | 865 | return ret; |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 866 | } |
| 867 | |
| 868 | /* setup the r/b/g positions for the window's palette */ |
| 869 | s3c_fb_init_palette(win_no, &win->palette); |
| 870 | |
| 871 | /* setup the initial video mode from the window */ |
| 872 | fb_videomode_to_var(&fbinfo->var, initmode); |
| 873 | |
| 874 | fbinfo->fix.type = FB_TYPE_PACKED_PIXELS; |
| 875 | fbinfo->fix.accel = FB_ACCEL_NONE; |
| 876 | fbinfo->var.activate = FB_ACTIVATE_NOW; |
| 877 | fbinfo->var.vmode = FB_VMODE_NONINTERLACED; |
| 878 | fbinfo->var.bits_per_pixel = windata->default_bpp; |
| 879 | fbinfo->fbops = &s3c_fb_ops; |
| 880 | fbinfo->flags = FBINFO_FLAG_DEFAULT; |
| 881 | fbinfo->pseudo_palette = &win->pseudo_palette; |
| 882 | |
| 883 | /* prepare to actually start the framebuffer */ |
| 884 | |
| 885 | ret = s3c_fb_check_var(&fbinfo->var, fbinfo); |
| 886 | if (ret < 0) { |
| 887 | dev_err(sfb->dev, "check_var failed on initial video params\n"); |
Krzysztof Helt | ddc518d | 2009-06-16 15:34:33 -0700 | [diff] [blame] | 888 | return ret; |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 889 | } |
| 890 | |
| 891 | /* create initial colour map */ |
| 892 | |
Ben Dooks | 50a5503 | 2010-08-10 18:02:33 -0700 | [diff] [blame] | 893 | ret = fb_alloc_cmap(&fbinfo->cmap, win->variant.palette_sz, 1); |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 894 | if (ret == 0) |
| 895 | fb_set_cmap(&fbinfo->cmap, fbinfo); |
| 896 | else |
| 897 | dev_err(sfb->dev, "failed to allocate fb cmap\n"); |
| 898 | |
| 899 | s3c_fb_set_par(fbinfo); |
| 900 | |
| 901 | dev_dbg(sfb->dev, "about to register framebuffer\n"); |
| 902 | |
| 903 | /* run the check_var and set_par on our configuration. */ |
| 904 | |
| 905 | ret = register_framebuffer(fbinfo); |
| 906 | if (ret < 0) { |
| 907 | dev_err(sfb->dev, "failed to register framebuffer\n"); |
Krzysztof Helt | ddc518d | 2009-06-16 15:34:33 -0700 | [diff] [blame] | 908 | return ret; |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | *res = win; |
| 912 | dev_info(sfb->dev, "window %d: fb %s\n", win_no, fbinfo->fix.id); |
| 913 | |
| 914 | return 0; |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 915 | } |
| 916 | |
| 917 | /** |
| 918 | * s3c_fb_clear_win() - clear hardware window registers. |
| 919 | * @sfb: The base resources for the hardware. |
| 920 | * @win: The window to process. |
| 921 | * |
| 922 | * Reset the specific window registers to a known state. |
| 923 | */ |
| 924 | static void s3c_fb_clear_win(struct s3c_fb *sfb, int win) |
| 925 | { |
| 926 | void __iomem *regs = sfb->regs; |
| 927 | |
Ben Dooks | c4bb6ff | 2010-08-10 18:02:34 -0700 | [diff] [blame^] | 928 | writel(0, regs + sfb->variant.wincon + (win * 4)); |
| 929 | writel(0, regs + VIDOSD_A(win, sfb->variant)); |
| 930 | writel(0, regs + VIDOSD_B(win, sfb->variant)); |
| 931 | writel(0, regs + VIDOSD_C(win, sfb->variant)); |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 932 | } |
| 933 | |
| 934 | static int __devinit s3c_fb_probe(struct platform_device *pdev) |
| 935 | { |
Ben Dooks | 50a5503 | 2010-08-10 18:02:33 -0700 | [diff] [blame] | 936 | struct s3c_fb_driverdata *fbdrv; |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 937 | struct device *dev = &pdev->dev; |
| 938 | struct s3c_fb_platdata *pd; |
| 939 | struct s3c_fb *sfb; |
| 940 | struct resource *res; |
| 941 | int win; |
| 942 | int ret = 0; |
| 943 | |
Ben Dooks | 50a5503 | 2010-08-10 18:02:33 -0700 | [diff] [blame] | 944 | fbdrv = (struct s3c_fb_driverdata *)platform_get_device_id(pdev)->driver_data; |
| 945 | |
| 946 | if (fbdrv->variant.nr_windows > S3C_FB_MAX_WIN) { |
| 947 | dev_err(dev, "too many windows, cannot attach\n"); |
| 948 | return -EINVAL; |
| 949 | } |
| 950 | |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 951 | pd = pdev->dev.platform_data; |
| 952 | if (!pd) { |
| 953 | dev_err(dev, "no platform data specified\n"); |
| 954 | return -EINVAL; |
| 955 | } |
| 956 | |
| 957 | sfb = kzalloc(sizeof(struct s3c_fb), GFP_KERNEL); |
| 958 | if (!sfb) { |
| 959 | dev_err(dev, "no memory for framebuffers\n"); |
| 960 | return -ENOMEM; |
| 961 | } |
| 962 | |
Ben Dooks | c4bb6ff | 2010-08-10 18:02:34 -0700 | [diff] [blame^] | 963 | dev_dbg(dev, "allocate new framebuffer %p\n", sfb); |
| 964 | |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 965 | sfb->dev = dev; |
| 966 | sfb->pdata = pd; |
Ben Dooks | 50a5503 | 2010-08-10 18:02:33 -0700 | [diff] [blame] | 967 | sfb->variant = fbdrv->variant; |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 968 | |
| 969 | sfb->bus_clk = clk_get(dev, "lcd"); |
| 970 | if (IS_ERR(sfb->bus_clk)) { |
| 971 | dev_err(dev, "failed to get bus clock\n"); |
| 972 | goto err_sfb; |
| 973 | } |
| 974 | |
| 975 | clk_enable(sfb->bus_clk); |
| 976 | |
| 977 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 978 | if (!res) { |
| 979 | dev_err(dev, "failed to find registers\n"); |
| 980 | ret = -ENOENT; |
| 981 | goto err_clk; |
| 982 | } |
| 983 | |
| 984 | sfb->regs_res = request_mem_region(res->start, resource_size(res), |
| 985 | dev_name(dev)); |
| 986 | if (!sfb->regs_res) { |
| 987 | dev_err(dev, "failed to claim register region\n"); |
| 988 | ret = -ENOENT; |
| 989 | goto err_clk; |
| 990 | } |
| 991 | |
| 992 | sfb->regs = ioremap(res->start, resource_size(res)); |
| 993 | if (!sfb->regs) { |
| 994 | dev_err(dev, "failed to map registers\n"); |
| 995 | ret = -ENXIO; |
| 996 | goto err_req_region; |
| 997 | } |
| 998 | |
| 999 | dev_dbg(dev, "got resources (regs %p), probing windows\n", sfb->regs); |
| 1000 | |
| 1001 | /* setup gpio and output polarity controls */ |
| 1002 | |
| 1003 | pd->setup_gpio(); |
| 1004 | |
| 1005 | writel(pd->vidcon1, sfb->regs + VIDCON1); |
| 1006 | |
| 1007 | /* zero all windows before we do anything */ |
| 1008 | |
Ben Dooks | 50a5503 | 2010-08-10 18:02:33 -0700 | [diff] [blame] | 1009 | for (win = 0; win < fbdrv->variant.nr_windows; win++) |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 1010 | s3c_fb_clear_win(sfb, win); |
| 1011 | |
Ben Dooks | 9494703 | 2010-08-10 18:02:32 -0700 | [diff] [blame] | 1012 | /* initialise colour key controls */ |
Ben Dooks | 50a5503 | 2010-08-10 18:02:33 -0700 | [diff] [blame] | 1013 | for (win = 0; win < (fbdrv->variant.nr_windows - 1); win++) { |
Ben Dooks | c4bb6ff | 2010-08-10 18:02:34 -0700 | [diff] [blame^] | 1014 | void __iomem *regs = sfb->regs + sfb->variant.keycon; |
| 1015 | |
| 1016 | regs += (win * 8); |
| 1017 | writel(0xffffff, regs + WKEYCON0); |
| 1018 | writel(0xffffff, regs + WKEYCON1); |
Ben Dooks | 9494703 | 2010-08-10 18:02:32 -0700 | [diff] [blame] | 1019 | } |
| 1020 | |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 1021 | /* we have the register setup, start allocating framebuffers */ |
| 1022 | |
Ben Dooks | 50a5503 | 2010-08-10 18:02:33 -0700 | [diff] [blame] | 1023 | for (win = 0; win < fbdrv->variant.nr_windows; win++) { |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 1024 | if (!pd->win[win]) |
| 1025 | continue; |
| 1026 | |
Ben Dooks | 50a5503 | 2010-08-10 18:02:33 -0700 | [diff] [blame] | 1027 | ret = s3c_fb_probe_win(sfb, win, fbdrv->win[win], |
| 1028 | &sfb->windows[win]); |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 1029 | if (ret < 0) { |
| 1030 | dev_err(dev, "failed to create window %d\n", win); |
| 1031 | for (; win >= 0; win--) |
| 1032 | s3c_fb_release_win(sfb, sfb->windows[win]); |
| 1033 | goto err_ioremap; |
| 1034 | } |
| 1035 | } |
| 1036 | |
| 1037 | platform_set_drvdata(pdev, sfb); |
| 1038 | |
| 1039 | return 0; |
| 1040 | |
| 1041 | err_ioremap: |
| 1042 | iounmap(sfb->regs); |
| 1043 | |
| 1044 | err_req_region: |
| 1045 | release_resource(sfb->regs_res); |
| 1046 | kfree(sfb->regs_res); |
| 1047 | |
| 1048 | err_clk: |
| 1049 | clk_disable(sfb->bus_clk); |
| 1050 | clk_put(sfb->bus_clk); |
| 1051 | |
| 1052 | err_sfb: |
| 1053 | kfree(sfb); |
| 1054 | return ret; |
| 1055 | } |
| 1056 | |
| 1057 | /** |
| 1058 | * s3c_fb_remove() - Cleanup on module finalisation |
| 1059 | * @pdev: The platform device we are bound to. |
| 1060 | * |
| 1061 | * Shutdown and then release all the resources that the driver allocated |
| 1062 | * on initialisation. |
| 1063 | */ |
| 1064 | static int __devexit s3c_fb_remove(struct platform_device *pdev) |
| 1065 | { |
| 1066 | struct s3c_fb *sfb = platform_get_drvdata(pdev); |
| 1067 | int win; |
| 1068 | |
Pawel Osciak | c42b110 | 2009-07-29 15:02:10 -0700 | [diff] [blame] | 1069 | for (win = 0; win < S3C_FB_MAX_WIN; win++) |
Marek Szyprowski | 17663e5 | 2009-05-28 14:34:35 -0700 | [diff] [blame] | 1070 | if (sfb->windows[win]) |
| 1071 | s3c_fb_release_win(sfb, sfb->windows[win]); |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 1072 | |
| 1073 | iounmap(sfb->regs); |
| 1074 | |
| 1075 | clk_disable(sfb->bus_clk); |
| 1076 | clk_put(sfb->bus_clk); |
| 1077 | |
| 1078 | release_resource(sfb->regs_res); |
| 1079 | kfree(sfb->regs_res); |
| 1080 | |
| 1081 | kfree(sfb); |
| 1082 | |
| 1083 | return 0; |
| 1084 | } |
| 1085 | |
| 1086 | #ifdef CONFIG_PM |
| 1087 | static int s3c_fb_suspend(struct platform_device *pdev, pm_message_t state) |
| 1088 | { |
| 1089 | struct s3c_fb *sfb = platform_get_drvdata(pdev); |
| 1090 | struct s3c_fb_win *win; |
| 1091 | int win_no; |
| 1092 | |
Pawel Osciak | c42b110 | 2009-07-29 15:02:10 -0700 | [diff] [blame] | 1093 | for (win_no = S3C_FB_MAX_WIN - 1; win_no >= 0; win_no--) { |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 1094 | win = sfb->windows[win_no]; |
| 1095 | if (!win) |
| 1096 | continue; |
| 1097 | |
| 1098 | /* use the blank function to push into power-down */ |
| 1099 | s3c_fb_blank(FB_BLANK_POWERDOWN, win->fbinfo); |
| 1100 | } |
| 1101 | |
| 1102 | clk_disable(sfb->bus_clk); |
| 1103 | return 0; |
| 1104 | } |
| 1105 | |
| 1106 | static int s3c_fb_resume(struct platform_device *pdev) |
| 1107 | { |
| 1108 | struct s3c_fb *sfb = platform_get_drvdata(pdev); |
Marek Szyprowski | 17663e5 | 2009-05-28 14:34:35 -0700 | [diff] [blame] | 1109 | struct s3c_fb_platdata *pd = sfb->pdata; |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 1110 | struct s3c_fb_win *win; |
| 1111 | int win_no; |
| 1112 | |
| 1113 | clk_enable(sfb->bus_clk); |
| 1114 | |
Marek Szyprowski | 17663e5 | 2009-05-28 14:34:35 -0700 | [diff] [blame] | 1115 | /* setup registers */ |
| 1116 | writel(pd->vidcon1, sfb->regs + VIDCON1); |
| 1117 | |
| 1118 | /* zero all windows before we do anything */ |
Ben Dooks | 50a5503 | 2010-08-10 18:02:33 -0700 | [diff] [blame] | 1119 | for (win_no = 0; win_no < sfb->variant.nr_windows; win_no++) |
Marek Szyprowski | 17663e5 | 2009-05-28 14:34:35 -0700 | [diff] [blame] | 1120 | s3c_fb_clear_win(sfb, win_no); |
| 1121 | |
Ben Dooks | 50a5503 | 2010-08-10 18:02:33 -0700 | [diff] [blame] | 1122 | for (win_no = 0; win_no < sfb->variant.nr_windows - 1; win_no++) { |
Ben Dooks | c4bb6ff | 2010-08-10 18:02:34 -0700 | [diff] [blame^] | 1123 | void __iomem *regs = sfb->regs + sfb->variant.keycon; |
| 1124 | |
| 1125 | regs += (win_no * 8); |
| 1126 | writel(0xffffff, regs + WKEYCON0); |
| 1127 | writel(0xffffff, regs + WKEYCON1); |
Ben Dooks | 9494703 | 2010-08-10 18:02:32 -0700 | [diff] [blame] | 1128 | } |
| 1129 | |
Marek Szyprowski | 17663e5 | 2009-05-28 14:34:35 -0700 | [diff] [blame] | 1130 | /* restore framebuffers */ |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 1131 | for (win_no = 0; win_no < S3C_FB_MAX_WIN; win_no++) { |
| 1132 | win = sfb->windows[win_no]; |
| 1133 | if (!win) |
| 1134 | continue; |
| 1135 | |
| 1136 | dev_dbg(&pdev->dev, "resuming window %d\n", win_no); |
| 1137 | s3c_fb_set_par(win->fbinfo); |
| 1138 | } |
| 1139 | |
| 1140 | return 0; |
| 1141 | } |
| 1142 | #else |
| 1143 | #define s3c_fb_suspend NULL |
| 1144 | #define s3c_fb_resume NULL |
| 1145 | #endif |
| 1146 | |
Ben Dooks | 50a5503 | 2010-08-10 18:02:33 -0700 | [diff] [blame] | 1147 | |
| 1148 | #define VALID_BPP124 (VALID_BPP(1) | VALID_BPP(2) | VALID_BPP(4)) |
| 1149 | #define VALID_BPP1248 (VALID_BPP124 | VALID_BPP(8)) |
| 1150 | |
| 1151 | static struct s3c_fb_win_variant s3c_fb_data_64xx_wins[] __devinitdata = { |
| 1152 | [0] = { |
| 1153 | .has_osd_c = 1, |
| 1154 | .palette_sz = 256, |
| 1155 | .valid_bpp = VALID_BPP1248 | VALID_BPP(16) | VALID_BPP(24), |
| 1156 | }, |
| 1157 | [1] = { |
| 1158 | .has_osd_c = 1, |
| 1159 | .has_osd_d = 1, |
| 1160 | .palette_sz = 256, |
| 1161 | .valid_bpp = (VALID_BPP1248 | VALID_BPP(16) | |
| 1162 | VALID_BPP(18) | VALID_BPP(19) | |
| 1163 | VALID_BPP(24) | VALID_BPP(25)), |
| 1164 | }, |
| 1165 | [2] = { |
| 1166 | .has_osd_c = 1, |
| 1167 | .has_osd_d = 1, |
| 1168 | .palette_sz = 16, |
| 1169 | .palette_16bpp = 1, |
| 1170 | .valid_bpp = (VALID_BPP1248 | VALID_BPP(16) | |
| 1171 | VALID_BPP(18) | VALID_BPP(19) | |
| 1172 | VALID_BPP(24) | VALID_BPP(25)), |
| 1173 | }, |
| 1174 | [3] = { |
| 1175 | .has_osd_c = 1, |
| 1176 | .has_osd_d = 1, |
| 1177 | .palette_sz = 16, |
| 1178 | .palette_16bpp = 1, |
| 1179 | .valid_bpp = (VALID_BPP124 | VALID_BPP(16) | |
| 1180 | VALID_BPP(18) | VALID_BPP(19) | |
| 1181 | VALID_BPP(24) | VALID_BPP(25)), |
| 1182 | }, |
| 1183 | [4] = { |
| 1184 | .has_osd_c = 1, |
| 1185 | .palette_sz = 4, |
| 1186 | .palette_16bpp = 1, |
| 1187 | .valid_bpp = (VALID_BPP(1) | VALID_BPP(2) | |
| 1188 | VALID_BPP(16) | VALID_BPP(18) | |
| 1189 | VALID_BPP(24) | VALID_BPP(25)), |
| 1190 | }, |
| 1191 | }; |
| 1192 | |
| 1193 | static struct s3c_fb_driverdata s3c_fb_data_64xx __devinitdata = { |
| 1194 | .variant = { |
| 1195 | .nr_windows = 5, |
Ben Dooks | c4bb6ff | 2010-08-10 18:02:34 -0700 | [diff] [blame^] | 1196 | .vidtcon = VIDTCON0, |
| 1197 | .wincon = WINCON(0), |
| 1198 | .winmap = WINxMAP(0), |
| 1199 | .keycon = WKEYCON, |
| 1200 | .osd = VIDOSD_BASE, |
| 1201 | .osd_stride = 16, |
| 1202 | .buf_start = VIDW_BUF_START(0), |
| 1203 | .buf_size = VIDW_BUF_SIZE(0), |
| 1204 | .buf_end = VIDW_BUF_END(0), |
Ben Dooks | 50a5503 | 2010-08-10 18:02:33 -0700 | [diff] [blame] | 1205 | |
| 1206 | .palette = { |
| 1207 | [0] = 0x400, |
| 1208 | [1] = 0x800, |
| 1209 | [2] = 0x300, |
| 1210 | [3] = 0x320, |
| 1211 | [4] = 0x340, |
| 1212 | }, |
| 1213 | }, |
| 1214 | .win[0] = &s3c_fb_data_64xx_wins[0], |
| 1215 | .win[1] = &s3c_fb_data_64xx_wins[1], |
| 1216 | .win[2] = &s3c_fb_data_64xx_wins[2], |
| 1217 | .win[3] = &s3c_fb_data_64xx_wins[3], |
| 1218 | .win[4] = &s3c_fb_data_64xx_wins[4], |
| 1219 | }; |
| 1220 | |
| 1221 | static struct s3c_fb_driverdata s3c_fb_data_s5p __devinitdata = { |
| 1222 | .variant = { |
| 1223 | .nr_windows = 5, |
Ben Dooks | c4bb6ff | 2010-08-10 18:02:34 -0700 | [diff] [blame^] | 1224 | .vidtcon = VIDTCON0, |
| 1225 | .wincon = WINCON(0), |
| 1226 | .winmap = WINxMAP(0), |
| 1227 | .keycon = WKEYCON, |
| 1228 | .osd = VIDOSD_BASE, |
| 1229 | .osd_stride = 16, |
| 1230 | .buf_start = VIDW_BUF_START(0), |
| 1231 | .buf_size = VIDW_BUF_SIZE(0), |
| 1232 | .buf_end = VIDW_BUF_END(0), |
Ben Dooks | 50a5503 | 2010-08-10 18:02:33 -0700 | [diff] [blame] | 1233 | |
| 1234 | .palette = { |
| 1235 | [0] = 0x2400, |
| 1236 | [1] = 0x2800, |
| 1237 | [2] = 0x2c00, |
| 1238 | [3] = 0x3000, |
| 1239 | [4] = 0x3400, |
| 1240 | }, |
| 1241 | }, |
| 1242 | .win[0] = &s3c_fb_data_64xx_wins[0], |
| 1243 | .win[1] = &s3c_fb_data_64xx_wins[1], |
| 1244 | .win[2] = &s3c_fb_data_64xx_wins[2], |
| 1245 | .win[3] = &s3c_fb_data_64xx_wins[3], |
| 1246 | .win[4] = &s3c_fb_data_64xx_wins[4], |
| 1247 | }; |
| 1248 | |
Ben Dooks | c4bb6ff | 2010-08-10 18:02:34 -0700 | [diff] [blame^] | 1249 | /* S3C2443/S3C2416 style hardware */ |
| 1250 | static struct s3c_fb_driverdata s3c_fb_data_s3c2443 __devinitdata = { |
| 1251 | .variant = { |
| 1252 | .nr_windows = 2, |
| 1253 | .is_2443 = 1, |
| 1254 | |
| 1255 | .vidtcon = 0x08, |
| 1256 | .wincon = 0x14, |
| 1257 | .winmap = 0xd0, |
| 1258 | .keycon = 0xb0, |
| 1259 | .osd = 0x28, |
| 1260 | .osd_stride = 12, |
| 1261 | .buf_start = 0x64, |
| 1262 | .buf_size = 0x94, |
| 1263 | .buf_end = 0x7c, |
| 1264 | |
| 1265 | .palette = { |
| 1266 | [0] = 0x400, |
| 1267 | [1] = 0x800, |
| 1268 | }, |
| 1269 | }, |
| 1270 | .win[0] = &(struct s3c_fb_win_variant) { |
| 1271 | .palette_sz = 256, |
| 1272 | .valid_bpp = VALID_BPP1248 | VALID_BPP(16) | VALID_BPP(24), |
| 1273 | }, |
| 1274 | .win[1] = &(struct s3c_fb_win_variant) { |
| 1275 | .has_osd_c = 1, |
| 1276 | .palette_sz = 256, |
| 1277 | .valid_bpp = (VALID_BPP1248 | VALID_BPP(16) | |
| 1278 | VALID_BPP(18) | VALID_BPP(19) | |
| 1279 | VALID_BPP(24) | VALID_BPP(25) | |
| 1280 | VALID_BPP(28)), |
| 1281 | }, |
| 1282 | }; |
| 1283 | |
Ben Dooks | 50a5503 | 2010-08-10 18:02:33 -0700 | [diff] [blame] | 1284 | static struct platform_device_id s3c_fb_driver_ids[] = { |
| 1285 | { |
| 1286 | .name = "s3c-fb", |
| 1287 | .driver_data = (unsigned long)&s3c_fb_data_64xx, |
| 1288 | }, { |
| 1289 | .name = "s5p-fb", |
| 1290 | .driver_data = (unsigned long)&s3c_fb_data_s5p, |
Ben Dooks | c4bb6ff | 2010-08-10 18:02:34 -0700 | [diff] [blame^] | 1291 | }, { |
| 1292 | .name = "s3c2443-fb", |
| 1293 | .driver_data = (unsigned long)&s3c_fb_data_s3c2443, |
Ben Dooks | 50a5503 | 2010-08-10 18:02:33 -0700 | [diff] [blame] | 1294 | }, |
| 1295 | {}, |
| 1296 | }; |
| 1297 | MODULE_DEVICE_TABLE(platform, s3c_fb_driver_ids); |
| 1298 | |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 1299 | static struct platform_driver s3c_fb_driver = { |
| 1300 | .probe = s3c_fb_probe, |
Peter Korsgaard | 3163eaba | 2009-09-22 16:47:55 -0700 | [diff] [blame] | 1301 | .remove = __devexit_p(s3c_fb_remove), |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 1302 | .suspend = s3c_fb_suspend, |
| 1303 | .resume = s3c_fb_resume, |
Ben Dooks | 50a5503 | 2010-08-10 18:02:33 -0700 | [diff] [blame] | 1304 | .id_table = s3c_fb_driver_ids, |
Ben Dooks | ec549a0 | 2009-03-31 15:25:39 -0700 | [diff] [blame] | 1305 | .driver = { |
| 1306 | .name = "s3c-fb", |
| 1307 | .owner = THIS_MODULE, |
| 1308 | }, |
| 1309 | }; |
| 1310 | |
| 1311 | static int __init s3c_fb_init(void) |
| 1312 | { |
| 1313 | return platform_driver_register(&s3c_fb_driver); |
| 1314 | } |
| 1315 | |
| 1316 | static void __exit s3c_fb_cleanup(void) |
| 1317 | { |
| 1318 | platform_driver_unregister(&s3c_fb_driver); |
| 1319 | } |
| 1320 | |
| 1321 | module_init(s3c_fb_init); |
| 1322 | module_exit(s3c_fb_cleanup); |
| 1323 | |
| 1324 | MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>"); |
| 1325 | MODULE_DESCRIPTION("Samsung S3C SoC Framebuffer driver"); |
| 1326 | MODULE_LICENSE("GPL"); |
| 1327 | MODULE_ALIAS("platform:s3c-fb"); |