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