Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/video/omap2/omapfb-main.c |
| 3 | * |
| 4 | * Copyright (C) 2008 Nokia Corporation |
| 5 | * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com> |
| 6 | * |
| 7 | * Some code and ideas taken from drivers/video/omap/ driver |
| 8 | * by Imre Deak. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify it |
| 11 | * under the terms of the GNU General Public License version 2 as published by |
| 12 | * the Free Software Foundation. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 17 | * more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License along with |
| 20 | * this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 | */ |
| 22 | |
| 23 | #include <linux/module.h> |
| 24 | #include <linux/delay.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 25 | #include <linux/slab.h> |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 26 | #include <linux/fb.h> |
| 27 | #include <linux/dma-mapping.h> |
| 28 | #include <linux/vmalloc.h> |
| 29 | #include <linux/device.h> |
| 30 | #include <linux/platform_device.h> |
| 31 | #include <linux/omapfb.h> |
| 32 | |
Tomi Valkeinen | a0b38cc | 2011-05-11 14:05:07 +0300 | [diff] [blame] | 33 | #include <video/omapdss.h> |
Tomi Valkeinen | 6a1c9f6 | 2012-10-08 14:52:24 +0300 | [diff] [blame] | 34 | #include <video/omapvrfb.h> |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 35 | |
| 36 | #include "omapfb.h" |
| 37 | |
| 38 | #define MODULE_NAME "omapfb" |
| 39 | |
| 40 | #define OMAPFB_PLANE_XRES_MIN 8 |
| 41 | #define OMAPFB_PLANE_YRES_MIN 8 |
| 42 | |
| 43 | static char *def_mode; |
| 44 | static char *def_vram; |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 45 | static bool def_vrfb; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 46 | static int def_rotate; |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 47 | static bool def_mirror; |
Tomi Valkeinen | 27cc213 | 2011-04-30 16:55:12 +0300 | [diff] [blame] | 48 | static bool auto_update; |
| 49 | static unsigned int auto_update_freq; |
| 50 | module_param(auto_update, bool, 0); |
| 51 | module_param(auto_update_freq, uint, 0644); |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 52 | |
| 53 | #ifdef DEBUG |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 54 | bool omapfb_debug; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 55 | module_param_named(debug, omapfb_debug, bool, 0644); |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 56 | static bool omapfb_test_pattern; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 57 | module_param_named(test, omapfb_test_pattern, bool, 0644); |
| 58 | #endif |
| 59 | |
| 60 | static int omapfb_fb_init(struct omapfb2_device *fbdev, struct fb_info *fbi); |
Tomi Valkeinen | a269950 | 2010-01-11 14:33:40 +0200 | [diff] [blame] | 61 | static int omapfb_get_recommended_bpp(struct omapfb2_device *fbdev, |
| 62 | struct omap_dss_device *dssdev); |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 63 | |
| 64 | #ifdef DEBUG |
| 65 | static void draw_pixel(struct fb_info *fbi, int x, int y, unsigned color) |
| 66 | { |
| 67 | struct fb_var_screeninfo *var = &fbi->var; |
| 68 | struct fb_fix_screeninfo *fix = &fbi->fix; |
| 69 | void __iomem *addr = fbi->screen_base; |
| 70 | const unsigned bytespp = var->bits_per_pixel >> 3; |
| 71 | const unsigned line_len = fix->line_length / bytespp; |
| 72 | |
| 73 | int r = (color >> 16) & 0xff; |
| 74 | int g = (color >> 8) & 0xff; |
| 75 | int b = (color >> 0) & 0xff; |
| 76 | |
| 77 | if (var->bits_per_pixel == 16) { |
| 78 | u16 __iomem *p = (u16 __iomem *)addr; |
| 79 | p += y * line_len + x; |
| 80 | |
| 81 | r = r * 32 / 256; |
| 82 | g = g * 64 / 256; |
| 83 | b = b * 32 / 256; |
| 84 | |
| 85 | __raw_writew((r << 11) | (g << 5) | (b << 0), p); |
| 86 | } else if (var->bits_per_pixel == 24) { |
| 87 | u8 __iomem *p = (u8 __iomem *)addr; |
| 88 | p += (y * line_len + x) * 3; |
| 89 | |
| 90 | __raw_writeb(b, p + 0); |
| 91 | __raw_writeb(g, p + 1); |
| 92 | __raw_writeb(r, p + 2); |
| 93 | } else if (var->bits_per_pixel == 32) { |
| 94 | u32 __iomem *p = (u32 __iomem *)addr; |
| 95 | p += y * line_len + x; |
| 96 | __raw_writel(color, p); |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | static void fill_fb(struct fb_info *fbi) |
| 101 | { |
| 102 | struct fb_var_screeninfo *var = &fbi->var; |
| 103 | const short w = var->xres_virtual; |
| 104 | const short h = var->yres_virtual; |
| 105 | void __iomem *addr = fbi->screen_base; |
| 106 | int y, x; |
| 107 | |
| 108 | if (!addr) |
| 109 | return; |
| 110 | |
| 111 | DBG("fill_fb %dx%d, line_len %d bytes\n", w, h, fbi->fix.line_length); |
| 112 | |
| 113 | for (y = 0; y < h; y++) { |
| 114 | for (x = 0; x < w; x++) { |
| 115 | if (x < 20 && y < 20) |
| 116 | draw_pixel(fbi, x, y, 0xffffff); |
| 117 | else if (x < 20 && (y > 20 && y < h - 20)) |
| 118 | draw_pixel(fbi, x, y, 0xff); |
| 119 | else if (y < 20 && (x > 20 && x < w - 20)) |
| 120 | draw_pixel(fbi, x, y, 0xff00); |
| 121 | else if (x > w - 20 && (y > 20 && y < h - 20)) |
| 122 | draw_pixel(fbi, x, y, 0xff0000); |
| 123 | else if (y > h - 20 && (x > 20 && x < w - 20)) |
| 124 | draw_pixel(fbi, x, y, 0xffff00); |
| 125 | else if (x == 20 || x == w - 20 || |
| 126 | y == 20 || y == h - 20) |
| 127 | draw_pixel(fbi, x, y, 0xffffff); |
| 128 | else if (x == y || w - x == h - y) |
| 129 | draw_pixel(fbi, x, y, 0xff00ff); |
| 130 | else if (w - x == y || x == h - y) |
| 131 | draw_pixel(fbi, x, y, 0x00ffff); |
| 132 | else if (x > 20 && y > 20 && x < w - 20 && y < h - 20) { |
| 133 | int t = x * 3 / w; |
| 134 | unsigned r = 0, g = 0, b = 0; |
| 135 | unsigned c; |
| 136 | if (var->bits_per_pixel == 16) { |
| 137 | if (t == 0) |
| 138 | b = (y % 32) * 256 / 32; |
| 139 | else if (t == 1) |
| 140 | g = (y % 64) * 256 / 64; |
| 141 | else if (t == 2) |
| 142 | r = (y % 32) * 256 / 32; |
| 143 | } else { |
| 144 | if (t == 0) |
| 145 | b = (y % 256); |
| 146 | else if (t == 1) |
| 147 | g = (y % 256); |
| 148 | else if (t == 2) |
| 149 | r = (y % 256); |
| 150 | } |
| 151 | c = (r << 16) | (g << 8) | (b << 0); |
| 152 | draw_pixel(fbi, x, y, c); |
| 153 | } else { |
| 154 | draw_pixel(fbi, x, y, 0); |
| 155 | } |
| 156 | } |
| 157 | } |
| 158 | } |
| 159 | #endif |
| 160 | |
Ville Syrjälä | a4c1a14 | 2010-02-23 23:36:26 +0100 | [diff] [blame] | 161 | static unsigned omapfb_get_vrfb_offset(const struct omapfb_info *ofbi, int rot) |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 162 | { |
Ville Syrjälä | 078ff54 | 2010-03-17 20:36:51 +0200 | [diff] [blame] | 163 | const struct vrfb *vrfb = &ofbi->region->vrfb; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 164 | unsigned offset; |
| 165 | |
| 166 | switch (rot) { |
| 167 | case FB_ROTATE_UR: |
| 168 | offset = 0; |
| 169 | break; |
| 170 | case FB_ROTATE_CW: |
| 171 | offset = vrfb->yoffset; |
| 172 | break; |
| 173 | case FB_ROTATE_UD: |
| 174 | offset = vrfb->yoffset * OMAP_VRFB_LINE_LEN + vrfb->xoffset; |
| 175 | break; |
| 176 | case FB_ROTATE_CCW: |
| 177 | offset = vrfb->xoffset * OMAP_VRFB_LINE_LEN; |
| 178 | break; |
| 179 | default: |
| 180 | BUG(); |
Tomi Valkeinen | 4a75cb8 | 2012-05-18 11:48:28 +0300 | [diff] [blame] | 181 | return 0; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | offset *= vrfb->bytespp; |
| 185 | |
| 186 | return offset; |
| 187 | } |
| 188 | |
Ville Syrjälä | a4c1a14 | 2010-02-23 23:36:26 +0100 | [diff] [blame] | 189 | static u32 omapfb_get_region_rot_paddr(const struct omapfb_info *ofbi, int rot) |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 190 | { |
| 191 | if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB) { |
Ville Syrjälä | 078ff54 | 2010-03-17 20:36:51 +0200 | [diff] [blame] | 192 | return ofbi->region->vrfb.paddr[rot] |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 193 | + omapfb_get_vrfb_offset(ofbi, rot); |
| 194 | } else { |
Ville Syrjälä | 078ff54 | 2010-03-17 20:36:51 +0200 | [diff] [blame] | 195 | return ofbi->region->paddr; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 196 | } |
| 197 | } |
| 198 | |
Ville Syrjälä | a4c1a14 | 2010-02-23 23:36:26 +0100 | [diff] [blame] | 199 | static u32 omapfb_get_region_paddr(const struct omapfb_info *ofbi) |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 200 | { |
| 201 | if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB) |
Ville Syrjälä | 078ff54 | 2010-03-17 20:36:51 +0200 | [diff] [blame] | 202 | return ofbi->region->vrfb.paddr[0]; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 203 | else |
Ville Syrjälä | 078ff54 | 2010-03-17 20:36:51 +0200 | [diff] [blame] | 204 | return ofbi->region->paddr; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 205 | } |
| 206 | |
Ville Syrjälä | a4c1a14 | 2010-02-23 23:36:26 +0100 | [diff] [blame] | 207 | static void __iomem *omapfb_get_region_vaddr(const struct omapfb_info *ofbi) |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 208 | { |
| 209 | if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB) |
Ville Syrjälä | 078ff54 | 2010-03-17 20:36:51 +0200 | [diff] [blame] | 210 | return ofbi->region->vrfb.vaddr[0]; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 211 | else |
Ville Syrjälä | 078ff54 | 2010-03-17 20:36:51 +0200 | [diff] [blame] | 212 | return ofbi->region->vaddr; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | static struct omapfb_colormode omapfb_colormodes[] = { |
| 216 | { |
| 217 | .dssmode = OMAP_DSS_COLOR_UYVY, |
| 218 | .bits_per_pixel = 16, |
| 219 | .nonstd = OMAPFB_COLOR_YUV422, |
| 220 | }, { |
| 221 | .dssmode = OMAP_DSS_COLOR_YUV2, |
| 222 | .bits_per_pixel = 16, |
| 223 | .nonstd = OMAPFB_COLOR_YUY422, |
| 224 | }, { |
| 225 | .dssmode = OMAP_DSS_COLOR_ARGB16, |
| 226 | .bits_per_pixel = 16, |
| 227 | .red = { .length = 4, .offset = 8, .msb_right = 0 }, |
| 228 | .green = { .length = 4, .offset = 4, .msb_right = 0 }, |
| 229 | .blue = { .length = 4, .offset = 0, .msb_right = 0 }, |
| 230 | .transp = { .length = 4, .offset = 12, .msb_right = 0 }, |
| 231 | }, { |
| 232 | .dssmode = OMAP_DSS_COLOR_RGB16, |
| 233 | .bits_per_pixel = 16, |
| 234 | .red = { .length = 5, .offset = 11, .msb_right = 0 }, |
| 235 | .green = { .length = 6, .offset = 5, .msb_right = 0 }, |
| 236 | .blue = { .length = 5, .offset = 0, .msb_right = 0 }, |
| 237 | .transp = { .length = 0, .offset = 0, .msb_right = 0 }, |
| 238 | }, { |
| 239 | .dssmode = OMAP_DSS_COLOR_RGB24P, |
| 240 | .bits_per_pixel = 24, |
| 241 | .red = { .length = 8, .offset = 16, .msb_right = 0 }, |
| 242 | .green = { .length = 8, .offset = 8, .msb_right = 0 }, |
| 243 | .blue = { .length = 8, .offset = 0, .msb_right = 0 }, |
| 244 | .transp = { .length = 0, .offset = 0, .msb_right = 0 }, |
| 245 | }, { |
| 246 | .dssmode = OMAP_DSS_COLOR_RGB24U, |
| 247 | .bits_per_pixel = 32, |
| 248 | .red = { .length = 8, .offset = 16, .msb_right = 0 }, |
| 249 | .green = { .length = 8, .offset = 8, .msb_right = 0 }, |
| 250 | .blue = { .length = 8, .offset = 0, .msb_right = 0 }, |
| 251 | .transp = { .length = 0, .offset = 0, .msb_right = 0 }, |
| 252 | }, { |
| 253 | .dssmode = OMAP_DSS_COLOR_ARGB32, |
| 254 | .bits_per_pixel = 32, |
| 255 | .red = { .length = 8, .offset = 16, .msb_right = 0 }, |
| 256 | .green = { .length = 8, .offset = 8, .msb_right = 0 }, |
| 257 | .blue = { .length = 8, .offset = 0, .msb_right = 0 }, |
| 258 | .transp = { .length = 8, .offset = 24, .msb_right = 0 }, |
| 259 | }, { |
| 260 | .dssmode = OMAP_DSS_COLOR_RGBA32, |
| 261 | .bits_per_pixel = 32, |
| 262 | .red = { .length = 8, .offset = 24, .msb_right = 0 }, |
| 263 | .green = { .length = 8, .offset = 16, .msb_right = 0 }, |
| 264 | .blue = { .length = 8, .offset = 8, .msb_right = 0 }, |
| 265 | .transp = { .length = 8, .offset = 0, .msb_right = 0 }, |
| 266 | }, { |
| 267 | .dssmode = OMAP_DSS_COLOR_RGBX32, |
| 268 | .bits_per_pixel = 32, |
| 269 | .red = { .length = 8, .offset = 24, .msb_right = 0 }, |
| 270 | .green = { .length = 8, .offset = 16, .msb_right = 0 }, |
| 271 | .blue = { .length = 8, .offset = 8, .msb_right = 0 }, |
| 272 | .transp = { .length = 0, .offset = 0, .msb_right = 0 }, |
| 273 | }, |
| 274 | }; |
| 275 | |
| 276 | static bool cmp_var_to_colormode(struct fb_var_screeninfo *var, |
| 277 | struct omapfb_colormode *color) |
| 278 | { |
| 279 | bool cmp_component(struct fb_bitfield *f1, struct fb_bitfield *f2) |
| 280 | { |
| 281 | return f1->length == f2->length && |
| 282 | f1->offset == f2->offset && |
| 283 | f1->msb_right == f2->msb_right; |
| 284 | } |
| 285 | |
| 286 | if (var->bits_per_pixel == 0 || |
| 287 | var->red.length == 0 || |
| 288 | var->blue.length == 0 || |
| 289 | var->green.length == 0) |
| 290 | return 0; |
| 291 | |
| 292 | return var->bits_per_pixel == color->bits_per_pixel && |
| 293 | cmp_component(&var->red, &color->red) && |
| 294 | cmp_component(&var->green, &color->green) && |
| 295 | cmp_component(&var->blue, &color->blue) && |
| 296 | cmp_component(&var->transp, &color->transp); |
| 297 | } |
| 298 | |
| 299 | static void assign_colormode_to_var(struct fb_var_screeninfo *var, |
| 300 | struct omapfb_colormode *color) |
| 301 | { |
| 302 | var->bits_per_pixel = color->bits_per_pixel; |
| 303 | var->nonstd = color->nonstd; |
| 304 | var->red = color->red; |
| 305 | var->green = color->green; |
| 306 | var->blue = color->blue; |
| 307 | var->transp = color->transp; |
| 308 | } |
| 309 | |
| 310 | static int fb_mode_to_dss_mode(struct fb_var_screeninfo *var, |
| 311 | enum omap_color_mode *mode) |
| 312 | { |
| 313 | enum omap_color_mode dssmode; |
| 314 | int i; |
| 315 | |
| 316 | /* first match with nonstd field */ |
| 317 | if (var->nonstd) { |
| 318 | for (i = 0; i < ARRAY_SIZE(omapfb_colormodes); ++i) { |
| 319 | struct omapfb_colormode *m = &omapfb_colormodes[i]; |
| 320 | if (var->nonstd == m->nonstd) { |
| 321 | assign_colormode_to_var(var, m); |
| 322 | *mode = m->dssmode; |
| 323 | return 0; |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | return -EINVAL; |
| 328 | } |
| 329 | |
| 330 | /* then try exact match of bpp and colors */ |
| 331 | for (i = 0; i < ARRAY_SIZE(omapfb_colormodes); ++i) { |
| 332 | struct omapfb_colormode *m = &omapfb_colormodes[i]; |
| 333 | if (cmp_var_to_colormode(var, m)) { |
| 334 | assign_colormode_to_var(var, m); |
| 335 | *mode = m->dssmode; |
| 336 | return 0; |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | /* match with bpp if user has not filled color fields |
| 341 | * properly */ |
| 342 | switch (var->bits_per_pixel) { |
| 343 | case 1: |
| 344 | dssmode = OMAP_DSS_COLOR_CLUT1; |
| 345 | break; |
| 346 | case 2: |
| 347 | dssmode = OMAP_DSS_COLOR_CLUT2; |
| 348 | break; |
| 349 | case 4: |
| 350 | dssmode = OMAP_DSS_COLOR_CLUT4; |
| 351 | break; |
| 352 | case 8: |
| 353 | dssmode = OMAP_DSS_COLOR_CLUT8; |
| 354 | break; |
| 355 | case 12: |
| 356 | dssmode = OMAP_DSS_COLOR_RGB12U; |
| 357 | break; |
| 358 | case 16: |
| 359 | dssmode = OMAP_DSS_COLOR_RGB16; |
| 360 | break; |
| 361 | case 24: |
| 362 | dssmode = OMAP_DSS_COLOR_RGB24P; |
| 363 | break; |
| 364 | case 32: |
| 365 | dssmode = OMAP_DSS_COLOR_RGB24U; |
| 366 | break; |
| 367 | default: |
| 368 | return -EINVAL; |
| 369 | } |
| 370 | |
| 371 | for (i = 0; i < ARRAY_SIZE(omapfb_colormodes); ++i) { |
| 372 | struct omapfb_colormode *m = &omapfb_colormodes[i]; |
| 373 | if (dssmode == m->dssmode) { |
| 374 | assign_colormode_to_var(var, m); |
| 375 | *mode = m->dssmode; |
| 376 | return 0; |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | return -EINVAL; |
| 381 | } |
| 382 | |
| 383 | static int check_fb_res_bounds(struct fb_var_screeninfo *var) |
| 384 | { |
| 385 | int xres_min = OMAPFB_PLANE_XRES_MIN; |
| 386 | int xres_max = 2048; |
| 387 | int yres_min = OMAPFB_PLANE_YRES_MIN; |
| 388 | int yres_max = 2048; |
| 389 | |
| 390 | /* XXX: some applications seem to set virtual res to 0. */ |
| 391 | if (var->xres_virtual == 0) |
| 392 | var->xres_virtual = var->xres; |
| 393 | |
| 394 | if (var->yres_virtual == 0) |
| 395 | var->yres_virtual = var->yres; |
| 396 | |
| 397 | if (var->xres_virtual < xres_min || var->yres_virtual < yres_min) |
| 398 | return -EINVAL; |
| 399 | |
| 400 | if (var->xres < xres_min) |
| 401 | var->xres = xres_min; |
| 402 | if (var->yres < yres_min) |
| 403 | var->yres = yres_min; |
| 404 | if (var->xres > xres_max) |
| 405 | var->xres = xres_max; |
| 406 | if (var->yres > yres_max) |
| 407 | var->yres = yres_max; |
| 408 | |
| 409 | if (var->xres > var->xres_virtual) |
| 410 | var->xres = var->xres_virtual; |
| 411 | if (var->yres > var->yres_virtual) |
| 412 | var->yres = var->yres_virtual; |
| 413 | |
| 414 | return 0; |
| 415 | } |
| 416 | |
| 417 | static void shrink_height(unsigned long max_frame_size, |
| 418 | struct fb_var_screeninfo *var) |
| 419 | { |
| 420 | DBG("can't fit FB into memory, reducing y\n"); |
| 421 | var->yres_virtual = max_frame_size / |
| 422 | (var->xres_virtual * var->bits_per_pixel >> 3); |
| 423 | |
| 424 | if (var->yres_virtual < OMAPFB_PLANE_YRES_MIN) |
| 425 | var->yres_virtual = OMAPFB_PLANE_YRES_MIN; |
| 426 | |
| 427 | if (var->yres > var->yres_virtual) |
| 428 | var->yres = var->yres_virtual; |
| 429 | } |
| 430 | |
| 431 | static void shrink_width(unsigned long max_frame_size, |
| 432 | struct fb_var_screeninfo *var) |
| 433 | { |
| 434 | DBG("can't fit FB into memory, reducing x\n"); |
| 435 | var->xres_virtual = max_frame_size / var->yres_virtual / |
| 436 | (var->bits_per_pixel >> 3); |
| 437 | |
| 438 | if (var->xres_virtual < OMAPFB_PLANE_XRES_MIN) |
| 439 | var->xres_virtual = OMAPFB_PLANE_XRES_MIN; |
| 440 | |
| 441 | if (var->xres > var->xres_virtual) |
| 442 | var->xres = var->xres_virtual; |
| 443 | } |
| 444 | |
| 445 | static int check_vrfb_fb_size(unsigned long region_size, |
| 446 | const struct fb_var_screeninfo *var) |
| 447 | { |
| 448 | unsigned long min_phys_size = omap_vrfb_min_phys_size(var->xres_virtual, |
| 449 | var->yres_virtual, var->bits_per_pixel >> 3); |
| 450 | |
| 451 | return min_phys_size > region_size ? -EINVAL : 0; |
| 452 | } |
| 453 | |
| 454 | static int check_fb_size(const struct omapfb_info *ofbi, |
| 455 | struct fb_var_screeninfo *var) |
| 456 | { |
Ville Syrjälä | 078ff54 | 2010-03-17 20:36:51 +0200 | [diff] [blame] | 457 | unsigned long max_frame_size = ofbi->region->size; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 458 | int bytespp = var->bits_per_pixel >> 3; |
| 459 | unsigned long line_size = var->xres_virtual * bytespp; |
| 460 | |
| 461 | if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB) { |
| 462 | /* One needs to check for both VRFB and OMAPFB limitations. */ |
| 463 | if (check_vrfb_fb_size(max_frame_size, var)) |
| 464 | shrink_height(omap_vrfb_max_height( |
| 465 | max_frame_size, var->xres_virtual, bytespp) * |
| 466 | line_size, var); |
| 467 | |
| 468 | if (check_vrfb_fb_size(max_frame_size, var)) { |
| 469 | DBG("cannot fit FB to memory\n"); |
| 470 | return -EINVAL; |
| 471 | } |
| 472 | |
| 473 | return 0; |
| 474 | } |
| 475 | |
| 476 | DBG("max frame size %lu, line size %lu\n", max_frame_size, line_size); |
| 477 | |
| 478 | if (line_size * var->yres_virtual > max_frame_size) |
| 479 | shrink_height(max_frame_size, var); |
| 480 | |
| 481 | if (line_size * var->yres_virtual > max_frame_size) { |
| 482 | shrink_width(max_frame_size, var); |
| 483 | line_size = var->xres_virtual * bytespp; |
| 484 | } |
| 485 | |
| 486 | if (line_size * var->yres_virtual > max_frame_size) { |
| 487 | DBG("cannot fit FB to memory\n"); |
| 488 | return -EINVAL; |
| 489 | } |
| 490 | |
| 491 | return 0; |
| 492 | } |
| 493 | |
| 494 | /* |
| 495 | * Consider if VRFB assisted rotation is in use and if the virtual space for |
| 496 | * the zero degree view needs to be mapped. The need for mapping also acts as |
| 497 | * the trigger for setting up the hardware on the context in question. This |
| 498 | * ensures that one does not attempt to access the virtual view before the |
| 499 | * hardware is serving the address translations. |
| 500 | */ |
| 501 | static int setup_vrfb_rotation(struct fb_info *fbi) |
| 502 | { |
| 503 | struct omapfb_info *ofbi = FB2OFB(fbi); |
Ville Syrjälä | 078ff54 | 2010-03-17 20:36:51 +0200 | [diff] [blame] | 504 | struct omapfb2_mem_region *rg = ofbi->region; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 505 | struct vrfb *vrfb = &rg->vrfb; |
| 506 | struct fb_var_screeninfo *var = &fbi->var; |
| 507 | struct fb_fix_screeninfo *fix = &fbi->fix; |
| 508 | unsigned bytespp; |
| 509 | bool yuv_mode; |
| 510 | enum omap_color_mode mode; |
| 511 | int r; |
| 512 | bool reconf; |
| 513 | |
| 514 | if (!rg->size || ofbi->rotation_type != OMAP_DSS_ROT_VRFB) |
| 515 | return 0; |
| 516 | |
| 517 | DBG("setup_vrfb_rotation\n"); |
| 518 | |
| 519 | r = fb_mode_to_dss_mode(var, &mode); |
| 520 | if (r) |
| 521 | return r; |
| 522 | |
| 523 | bytespp = var->bits_per_pixel >> 3; |
| 524 | |
| 525 | yuv_mode = mode == OMAP_DSS_COLOR_YUV2 || mode == OMAP_DSS_COLOR_UYVY; |
| 526 | |
| 527 | /* We need to reconfigure VRFB if the resolution changes, if yuv mode |
| 528 | * is enabled/disabled, or if bytes per pixel changes */ |
| 529 | |
| 530 | /* XXX we shouldn't allow this when framebuffer is mmapped */ |
| 531 | |
| 532 | reconf = false; |
| 533 | |
| 534 | if (yuv_mode != vrfb->yuv_mode) |
| 535 | reconf = true; |
| 536 | else if (bytespp != vrfb->bytespp) |
| 537 | reconf = true; |
| 538 | else if (vrfb->xres != var->xres_virtual || |
| 539 | vrfb->yres != var->yres_virtual) |
| 540 | reconf = true; |
| 541 | |
| 542 | if (vrfb->vaddr[0] && reconf) { |
| 543 | fbi->screen_base = NULL; |
| 544 | fix->smem_start = 0; |
| 545 | fix->smem_len = 0; |
| 546 | iounmap(vrfb->vaddr[0]); |
| 547 | vrfb->vaddr[0] = NULL; |
| 548 | DBG("setup_vrfb_rotation: reset fb\n"); |
| 549 | } |
| 550 | |
| 551 | if (vrfb->vaddr[0]) |
| 552 | return 0; |
| 553 | |
| 554 | omap_vrfb_setup(&rg->vrfb, rg->paddr, |
| 555 | var->xres_virtual, |
| 556 | var->yres_virtual, |
| 557 | bytespp, yuv_mode); |
| 558 | |
| 559 | /* Now one can ioremap the 0 angle view */ |
| 560 | r = omap_vrfb_map_angle(vrfb, var->yres_virtual, 0); |
| 561 | if (r) |
| 562 | return r; |
| 563 | |
| 564 | /* used by open/write in fbmem.c */ |
Ville Syrjälä | 078ff54 | 2010-03-17 20:36:51 +0200 | [diff] [blame] | 565 | fbi->screen_base = ofbi->region->vrfb.vaddr[0]; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 566 | |
Ville Syrjälä | 078ff54 | 2010-03-17 20:36:51 +0200 | [diff] [blame] | 567 | fix->smem_start = ofbi->region->vrfb.paddr[0]; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 568 | |
| 569 | switch (var->nonstd) { |
| 570 | case OMAPFB_COLOR_YUV422: |
| 571 | case OMAPFB_COLOR_YUY422: |
| 572 | fix->line_length = |
| 573 | (OMAP_VRFB_LINE_LEN * var->bits_per_pixel) >> 2; |
| 574 | break; |
| 575 | default: |
| 576 | fix->line_length = |
| 577 | (OMAP_VRFB_LINE_LEN * var->bits_per_pixel) >> 3; |
| 578 | break; |
| 579 | } |
| 580 | |
| 581 | fix->smem_len = var->yres_virtual * fix->line_length; |
| 582 | |
| 583 | return 0; |
| 584 | } |
| 585 | |
| 586 | int dss_mode_to_fb_mode(enum omap_color_mode dssmode, |
| 587 | struct fb_var_screeninfo *var) |
| 588 | { |
| 589 | int i; |
| 590 | |
| 591 | for (i = 0; i < ARRAY_SIZE(omapfb_colormodes); ++i) { |
| 592 | struct omapfb_colormode *mode = &omapfb_colormodes[i]; |
| 593 | if (dssmode == mode->dssmode) { |
| 594 | assign_colormode_to_var(var, mode); |
| 595 | return 0; |
| 596 | } |
| 597 | } |
| 598 | return -ENOENT; |
| 599 | } |
| 600 | |
| 601 | void set_fb_fix(struct fb_info *fbi) |
| 602 | { |
| 603 | struct fb_fix_screeninfo *fix = &fbi->fix; |
| 604 | struct fb_var_screeninfo *var = &fbi->var; |
| 605 | struct omapfb_info *ofbi = FB2OFB(fbi); |
Ville Syrjälä | 078ff54 | 2010-03-17 20:36:51 +0200 | [diff] [blame] | 606 | struct omapfb2_mem_region *rg = ofbi->region; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 607 | |
| 608 | DBG("set_fb_fix\n"); |
| 609 | |
| 610 | /* used by open/write in fbmem.c */ |
| 611 | fbi->screen_base = (char __iomem *)omapfb_get_region_vaddr(ofbi); |
| 612 | |
| 613 | /* used by mmap in fbmem.c */ |
| 614 | if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB) { |
| 615 | switch (var->nonstd) { |
| 616 | case OMAPFB_COLOR_YUV422: |
| 617 | case OMAPFB_COLOR_YUY422: |
| 618 | fix->line_length = |
| 619 | (OMAP_VRFB_LINE_LEN * var->bits_per_pixel) >> 2; |
| 620 | break; |
| 621 | default: |
| 622 | fix->line_length = |
| 623 | (OMAP_VRFB_LINE_LEN * var->bits_per_pixel) >> 3; |
| 624 | break; |
| 625 | } |
| 626 | |
| 627 | fix->smem_len = var->yres_virtual * fix->line_length; |
| 628 | } else { |
| 629 | fix->line_length = |
| 630 | (var->xres_virtual * var->bits_per_pixel) >> 3; |
| 631 | fix->smem_len = rg->size; |
| 632 | } |
| 633 | |
| 634 | fix->smem_start = omapfb_get_region_paddr(ofbi); |
| 635 | |
| 636 | fix->type = FB_TYPE_PACKED_PIXELS; |
| 637 | |
| 638 | if (var->nonstd) |
| 639 | fix->visual = FB_VISUAL_PSEUDOCOLOR; |
| 640 | else { |
| 641 | switch (var->bits_per_pixel) { |
| 642 | case 32: |
| 643 | case 24: |
| 644 | case 16: |
| 645 | case 12: |
| 646 | fix->visual = FB_VISUAL_TRUECOLOR; |
| 647 | /* 12bpp is stored in 16 bits */ |
| 648 | break; |
| 649 | case 1: |
| 650 | case 2: |
| 651 | case 4: |
| 652 | case 8: |
| 653 | fix->visual = FB_VISUAL_PSEUDOCOLOR; |
| 654 | break; |
| 655 | } |
| 656 | } |
| 657 | |
| 658 | fix->accel = FB_ACCEL_NONE; |
| 659 | |
| 660 | fix->xpanstep = 1; |
| 661 | fix->ypanstep = 1; |
| 662 | } |
| 663 | |
| 664 | /* check new var and possibly modify it to be ok */ |
| 665 | int check_fb_var(struct fb_info *fbi, struct fb_var_screeninfo *var) |
| 666 | { |
| 667 | struct omapfb_info *ofbi = FB2OFB(fbi); |
| 668 | struct omap_dss_device *display = fb2display(fbi); |
| 669 | enum omap_color_mode mode = 0; |
| 670 | int i; |
| 671 | int r; |
| 672 | |
| 673 | DBG("check_fb_var %d\n", ofbi->id); |
| 674 | |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 675 | r = fb_mode_to_dss_mode(var, &mode); |
| 676 | if (r) { |
| 677 | DBG("cannot convert var to omap dss mode\n"); |
| 678 | return r; |
| 679 | } |
| 680 | |
| 681 | for (i = 0; i < ofbi->num_overlays; ++i) { |
| 682 | if ((ofbi->overlays[i]->supported_modes & mode) == 0) { |
| 683 | DBG("invalid mode\n"); |
| 684 | return -EINVAL; |
| 685 | } |
| 686 | } |
| 687 | |
Jani Nikula | 86f2d7d | 2010-06-01 17:25:10 +0300 | [diff] [blame] | 688 | if (var->rotate > 3) |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 689 | return -EINVAL; |
| 690 | |
| 691 | if (check_fb_res_bounds(var)) |
| 692 | return -EINVAL; |
| 693 | |
Ville Syrjälä | 276a1d4 | 2010-03-17 20:05:38 +0200 | [diff] [blame] | 694 | /* When no memory is allocated ignore the size check */ |
Ville Syrjälä | 078ff54 | 2010-03-17 20:36:51 +0200 | [diff] [blame] | 695 | if (ofbi->region->size != 0 && check_fb_size(ofbi, var)) |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 696 | return -EINVAL; |
| 697 | |
| 698 | if (var->xres + var->xoffset > var->xres_virtual) |
| 699 | var->xoffset = var->xres_virtual - var->xres; |
| 700 | if (var->yres + var->yoffset > var->yres_virtual) |
| 701 | var->yoffset = var->yres_virtual - var->yres; |
| 702 | |
| 703 | DBG("xres = %d, yres = %d, vxres = %d, vyres = %d\n", |
| 704 | var->xres, var->yres, |
| 705 | var->xres_virtual, var->yres_virtual); |
| 706 | |
Jani Nikula | 7a0987b | 2010-06-16 15:26:36 +0300 | [diff] [blame] | 707 | if (display && display->driver->get_dimensions) { |
| 708 | u32 w, h; |
| 709 | display->driver->get_dimensions(display, &w, &h); |
| 710 | var->width = DIV_ROUND_CLOSEST(w, 1000); |
| 711 | var->height = DIV_ROUND_CLOSEST(h, 1000); |
| 712 | } else { |
| 713 | var->height = -1; |
| 714 | var->width = -1; |
| 715 | } |
| 716 | |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 717 | var->grayscale = 0; |
| 718 | |
Tomi Valkeinen | 69b2048 | 2010-01-20 12:11:25 +0200 | [diff] [blame] | 719 | if (display && display->driver->get_timings) { |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 720 | struct omap_video_timings timings; |
Tomi Valkeinen | 69b2048 | 2010-01-20 12:11:25 +0200 | [diff] [blame] | 721 | display->driver->get_timings(display, &timings); |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 722 | |
| 723 | /* pixclock in ps, the rest in pixclock */ |
| 724 | var->pixclock = timings.pixel_clock != 0 ? |
| 725 | KHZ2PICOS(timings.pixel_clock) : |
| 726 | 0; |
Tasslehoff Kjappfot | 87ba828 | 2010-09-08 12:46:14 +0200 | [diff] [blame] | 727 | var->left_margin = timings.hbp; |
| 728 | var->right_margin = timings.hfp; |
| 729 | var->upper_margin = timings.vbp; |
| 730 | var->lower_margin = timings.vfp; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 731 | var->hsync_len = timings.hsw; |
| 732 | var->vsync_len = timings.vsw; |
Archit Taneja | 783babf | 2012-06-15 07:39:47 +0530 | [diff] [blame] | 733 | var->sync |= timings.hsync_level == OMAPDSS_SIG_ACTIVE_HIGH ? |
| 734 | FB_SYNC_HOR_HIGH_ACT : 0; |
| 735 | var->sync |= timings.vsync_level == OMAPDSS_SIG_ACTIVE_HIGH ? |
| 736 | FB_SYNC_VERT_HIGH_ACT : 0; |
Archit Taneja | 23bae3a | 2012-06-28 18:23:18 +0530 | [diff] [blame] | 737 | var->vmode = timings.interlace ? |
| 738 | FB_VMODE_INTERLACED : FB_VMODE_NONINTERLACED; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 739 | } else { |
| 740 | var->pixclock = 0; |
| 741 | var->left_margin = 0; |
| 742 | var->right_margin = 0; |
| 743 | var->upper_margin = 0; |
| 744 | var->lower_margin = 0; |
| 745 | var->hsync_len = 0; |
| 746 | var->vsync_len = 0; |
Archit Taneja | 783babf | 2012-06-15 07:39:47 +0530 | [diff] [blame] | 747 | var->sync = 0; |
Archit Taneja | 23bae3a | 2012-06-28 18:23:18 +0530 | [diff] [blame] | 748 | var->vmode = FB_VMODE_NONINTERLACED; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 749 | } |
| 750 | |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 751 | return 0; |
| 752 | } |
| 753 | |
| 754 | /* |
| 755 | * --------------------------------------------------------------------------- |
| 756 | * fbdev framework callbacks |
| 757 | * --------------------------------------------------------------------------- |
| 758 | */ |
| 759 | static int omapfb_open(struct fb_info *fbi, int user) |
| 760 | { |
| 761 | return 0; |
| 762 | } |
| 763 | |
| 764 | static int omapfb_release(struct fb_info *fbi, int user) |
| 765 | { |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 766 | return 0; |
| 767 | } |
| 768 | |
Ville Syrjälä | a4c1a14 | 2010-02-23 23:36:26 +0100 | [diff] [blame] | 769 | static unsigned calc_rotation_offset_dma(const struct fb_var_screeninfo *var, |
| 770 | const struct fb_fix_screeninfo *fix, int rotation) |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 771 | { |
| 772 | unsigned offset; |
| 773 | |
| 774 | offset = var->yoffset * fix->line_length + |
| 775 | var->xoffset * (var->bits_per_pixel >> 3); |
| 776 | |
| 777 | return offset; |
| 778 | } |
| 779 | |
Ville Syrjälä | a4c1a14 | 2010-02-23 23:36:26 +0100 | [diff] [blame] | 780 | static unsigned calc_rotation_offset_vrfb(const struct fb_var_screeninfo *var, |
| 781 | const struct fb_fix_screeninfo *fix, int rotation) |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 782 | { |
| 783 | unsigned offset; |
| 784 | |
| 785 | if (rotation == FB_ROTATE_UD) |
| 786 | offset = (var->yres_virtual - var->yres) * |
| 787 | fix->line_length; |
| 788 | else if (rotation == FB_ROTATE_CW) |
| 789 | offset = (var->yres_virtual - var->yres) * |
| 790 | (var->bits_per_pixel >> 3); |
| 791 | else |
| 792 | offset = 0; |
| 793 | |
| 794 | if (rotation == FB_ROTATE_UR) |
| 795 | offset += var->yoffset * fix->line_length + |
| 796 | var->xoffset * (var->bits_per_pixel >> 3); |
| 797 | else if (rotation == FB_ROTATE_UD) |
| 798 | offset -= var->yoffset * fix->line_length + |
| 799 | var->xoffset * (var->bits_per_pixel >> 3); |
| 800 | else if (rotation == FB_ROTATE_CW) |
| 801 | offset -= var->xoffset * fix->line_length + |
| 802 | var->yoffset * (var->bits_per_pixel >> 3); |
| 803 | else if (rotation == FB_ROTATE_CCW) |
| 804 | offset += var->xoffset * fix->line_length + |
| 805 | var->yoffset * (var->bits_per_pixel >> 3); |
| 806 | |
| 807 | return offset; |
| 808 | } |
| 809 | |
Ville Syrjälä | 46d3524 | 2010-03-17 19:59:26 +0200 | [diff] [blame] | 810 | static void omapfb_calc_addr(const struct omapfb_info *ofbi, |
| 811 | const struct fb_var_screeninfo *var, |
| 812 | const struct fb_fix_screeninfo *fix, |
Tomi Valkeinen | 212b0d5 | 2011-09-26 19:16:59 +0300 | [diff] [blame] | 813 | int rotation, u32 *paddr) |
Ville Syrjälä | 46d3524 | 2010-03-17 19:59:26 +0200 | [diff] [blame] | 814 | { |
| 815 | u32 data_start_p; |
Ville Syrjälä | 46d3524 | 2010-03-17 19:59:26 +0200 | [diff] [blame] | 816 | int offset; |
| 817 | |
Tomi Valkeinen | 212b0d5 | 2011-09-26 19:16:59 +0300 | [diff] [blame] | 818 | if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB) |
Ville Syrjälä | 46d3524 | 2010-03-17 19:59:26 +0200 | [diff] [blame] | 819 | data_start_p = omapfb_get_region_rot_paddr(ofbi, rotation); |
Tomi Valkeinen | 212b0d5 | 2011-09-26 19:16:59 +0300 | [diff] [blame] | 820 | else |
Ville Syrjälä | 46d3524 | 2010-03-17 19:59:26 +0200 | [diff] [blame] | 821 | data_start_p = omapfb_get_region_paddr(ofbi); |
Ville Syrjälä | 46d3524 | 2010-03-17 19:59:26 +0200 | [diff] [blame] | 822 | |
| 823 | if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB) |
| 824 | offset = calc_rotation_offset_vrfb(var, fix, rotation); |
| 825 | else |
| 826 | offset = calc_rotation_offset_dma(var, fix, rotation); |
| 827 | |
| 828 | data_start_p += offset; |
Ville Syrjälä | 46d3524 | 2010-03-17 19:59:26 +0200 | [diff] [blame] | 829 | |
| 830 | if (offset) |
| 831 | DBG("offset %d, %d = %d\n", |
| 832 | var->xoffset, var->yoffset, offset); |
| 833 | |
Tomi Valkeinen | 212b0d5 | 2011-09-26 19:16:59 +0300 | [diff] [blame] | 834 | DBG("paddr %x\n", data_start_p); |
Ville Syrjälä | 46d3524 | 2010-03-17 19:59:26 +0200 | [diff] [blame] | 835 | |
| 836 | *paddr = data_start_p; |
Ville Syrjälä | 46d3524 | 2010-03-17 19:59:26 +0200 | [diff] [blame] | 837 | } |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 838 | |
| 839 | /* setup overlay according to the fb */ |
Ville Syrjälä | 078ff54 | 2010-03-17 20:36:51 +0200 | [diff] [blame] | 840 | int omapfb_setup_overlay(struct fb_info *fbi, struct omap_overlay *ovl, |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 841 | u16 posx, u16 posy, u16 outw, u16 outh) |
| 842 | { |
| 843 | int r = 0; |
| 844 | struct omapfb_info *ofbi = FB2OFB(fbi); |
| 845 | struct fb_var_screeninfo *var = &fbi->var; |
| 846 | struct fb_fix_screeninfo *fix = &fbi->fix; |
| 847 | enum omap_color_mode mode = 0; |
Ville Syrjälä | 46d3524 | 2010-03-17 19:59:26 +0200 | [diff] [blame] | 848 | u32 data_start_p = 0; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 849 | struct omap_overlay_info info; |
| 850 | int xres, yres; |
| 851 | int screen_width; |
| 852 | int mirror; |
| 853 | int rotation = var->rotate; |
| 854 | int i; |
| 855 | |
| 856 | for (i = 0; i < ofbi->num_overlays; i++) { |
| 857 | if (ovl != ofbi->overlays[i]) |
| 858 | continue; |
| 859 | |
| 860 | rotation = (rotation + ofbi->rotation[i]) % 4; |
| 861 | break; |
| 862 | } |
| 863 | |
| 864 | DBG("setup_overlay %d, posx %d, posy %d, outw %d, outh %d\n", ofbi->id, |
| 865 | posx, posy, outw, outh); |
| 866 | |
| 867 | if (rotation == FB_ROTATE_CW || rotation == FB_ROTATE_CCW) { |
| 868 | xres = var->yres; |
| 869 | yres = var->xres; |
| 870 | } else { |
| 871 | xres = var->xres; |
| 872 | yres = var->yres; |
| 873 | } |
| 874 | |
Ville Syrjälä | 078ff54 | 2010-03-17 20:36:51 +0200 | [diff] [blame] | 875 | if (ofbi->region->size) |
Tomi Valkeinen | 212b0d5 | 2011-09-26 19:16:59 +0300 | [diff] [blame] | 876 | omapfb_calc_addr(ofbi, var, fix, rotation, &data_start_p); |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 877 | |
| 878 | r = fb_mode_to_dss_mode(var, &mode); |
| 879 | if (r) { |
| 880 | DBG("fb_mode_to_dss_mode failed"); |
| 881 | goto err; |
| 882 | } |
| 883 | |
| 884 | switch (var->nonstd) { |
| 885 | case OMAPFB_COLOR_YUV422: |
| 886 | case OMAPFB_COLOR_YUY422: |
| 887 | if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB) { |
| 888 | screen_width = fix->line_length |
| 889 | / (var->bits_per_pixel >> 2); |
| 890 | break; |
| 891 | } |
| 892 | default: |
| 893 | screen_width = fix->line_length / (var->bits_per_pixel >> 3); |
| 894 | break; |
| 895 | } |
| 896 | |
| 897 | ovl->get_overlay_info(ovl, &info); |
| 898 | |
| 899 | if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB) |
| 900 | mirror = 0; |
| 901 | else |
| 902 | mirror = ofbi->mirror; |
| 903 | |
| 904 | info.paddr = data_start_p; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 905 | info.screen_width = screen_width; |
| 906 | info.width = xres; |
| 907 | info.height = yres; |
| 908 | info.color_mode = mode; |
| 909 | info.rotation_type = ofbi->rotation_type; |
| 910 | info.rotation = rotation; |
| 911 | info.mirror = mirror; |
| 912 | |
| 913 | info.pos_x = posx; |
| 914 | info.pos_y = posy; |
| 915 | info.out_width = outw; |
| 916 | info.out_height = outh; |
| 917 | |
| 918 | r = ovl->set_overlay_info(ovl, &info); |
| 919 | if (r) { |
| 920 | DBG("ovl->setup_overlay_info failed\n"); |
| 921 | goto err; |
| 922 | } |
| 923 | |
| 924 | return 0; |
| 925 | |
| 926 | err: |
| 927 | DBG("setup_overlay failed\n"); |
| 928 | return r; |
| 929 | } |
| 930 | |
| 931 | /* apply var to the overlay */ |
| 932 | int omapfb_apply_changes(struct fb_info *fbi, int init) |
| 933 | { |
| 934 | int r = 0; |
| 935 | struct omapfb_info *ofbi = FB2OFB(fbi); |
| 936 | struct fb_var_screeninfo *var = &fbi->var; |
| 937 | struct omap_overlay *ovl; |
| 938 | u16 posx, posy; |
| 939 | u16 outw, outh; |
| 940 | int i; |
| 941 | |
| 942 | #ifdef DEBUG |
| 943 | if (omapfb_test_pattern) |
| 944 | fill_fb(fbi); |
| 945 | #endif |
| 946 | |
| 947 | for (i = 0; i < ofbi->num_overlays; i++) { |
| 948 | ovl = ofbi->overlays[i]; |
| 949 | |
| 950 | DBG("apply_changes, fb %d, ovl %d\n", ofbi->id, ovl->id); |
| 951 | |
Ville Syrjälä | 078ff54 | 2010-03-17 20:36:51 +0200 | [diff] [blame] | 952 | if (ofbi->region->size == 0) { |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 953 | /* the fb is not available. disable the overlay */ |
| 954 | omapfb_overlay_enable(ovl, 0); |
| 955 | if (!init && ovl->manager) |
| 956 | ovl->manager->apply(ovl->manager); |
| 957 | continue; |
| 958 | } |
| 959 | |
| 960 | if (init || (ovl->caps & OMAP_DSS_OVL_CAP_SCALE) == 0) { |
| 961 | int rotation = (var->rotate + ofbi->rotation[i]) % 4; |
| 962 | if (rotation == FB_ROTATE_CW || |
| 963 | rotation == FB_ROTATE_CCW) { |
| 964 | outw = var->yres; |
| 965 | outh = var->xres; |
| 966 | } else { |
| 967 | outw = var->xres; |
| 968 | outh = var->yres; |
| 969 | } |
| 970 | } else { |
Tomi Valkeinen | c1a9feb | 2011-11-16 14:11:56 +0200 | [diff] [blame] | 971 | struct omap_overlay_info info; |
| 972 | ovl->get_overlay_info(ovl, &info); |
| 973 | outw = info.out_width; |
| 974 | outh = info.out_height; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 975 | } |
| 976 | |
| 977 | if (init) { |
| 978 | posx = 0; |
| 979 | posy = 0; |
| 980 | } else { |
Tomi Valkeinen | c1a9feb | 2011-11-16 14:11:56 +0200 | [diff] [blame] | 981 | struct omap_overlay_info info; |
| 982 | ovl->get_overlay_info(ovl, &info); |
| 983 | posx = info.pos_x; |
| 984 | posy = info.pos_y; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 985 | } |
| 986 | |
| 987 | r = omapfb_setup_overlay(fbi, ovl, posx, posy, outw, outh); |
| 988 | if (r) |
| 989 | goto err; |
| 990 | |
| 991 | if (!init && ovl->manager) |
| 992 | ovl->manager->apply(ovl->manager); |
| 993 | } |
| 994 | return 0; |
| 995 | err: |
| 996 | DBG("apply_changes failed\n"); |
| 997 | return r; |
| 998 | } |
| 999 | |
| 1000 | /* checks var and eventually tweaks it to something supported, |
| 1001 | * DO NOT MODIFY PAR */ |
| 1002 | static int omapfb_check_var(struct fb_var_screeninfo *var, struct fb_info *fbi) |
| 1003 | { |
Ville Syrjälä | 430571d | 2010-03-17 20:43:23 +0200 | [diff] [blame] | 1004 | struct omapfb_info *ofbi = FB2OFB(fbi); |
Tomi Valkeinen | b41deec | 2012-12-04 14:55:18 +0200 | [diff] [blame] | 1005 | struct omapfb2_device *fbdev = ofbi->fbdev; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1006 | int r; |
| 1007 | |
| 1008 | DBG("check_var(%d)\n", FB2OFB(fbi)->id); |
| 1009 | |
Tomi Valkeinen | b41deec | 2012-12-04 14:55:18 +0200 | [diff] [blame] | 1010 | omapfb_lock(fbdev); |
Ville Syrjälä | 430571d | 2010-03-17 20:43:23 +0200 | [diff] [blame] | 1011 | |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1012 | r = check_fb_var(fbi, var); |
| 1013 | |
Tomi Valkeinen | b41deec | 2012-12-04 14:55:18 +0200 | [diff] [blame] | 1014 | omapfb_unlock(fbdev); |
Ville Syrjälä | 430571d | 2010-03-17 20:43:23 +0200 | [diff] [blame] | 1015 | |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1016 | return r; |
| 1017 | } |
| 1018 | |
| 1019 | /* set the video mode according to info->var */ |
| 1020 | static int omapfb_set_par(struct fb_info *fbi) |
| 1021 | { |
Ville Syrjälä | 430571d | 2010-03-17 20:43:23 +0200 | [diff] [blame] | 1022 | struct omapfb_info *ofbi = FB2OFB(fbi); |
Tomi Valkeinen | b41deec | 2012-12-04 14:55:18 +0200 | [diff] [blame] | 1023 | struct omapfb2_device *fbdev = ofbi->fbdev; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1024 | int r; |
| 1025 | |
| 1026 | DBG("set_par(%d)\n", FB2OFB(fbi)->id); |
| 1027 | |
Tomi Valkeinen | b41deec | 2012-12-04 14:55:18 +0200 | [diff] [blame] | 1028 | omapfb_lock(fbdev); |
Ville Syrjälä | 430571d | 2010-03-17 20:43:23 +0200 | [diff] [blame] | 1029 | |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1030 | set_fb_fix(fbi); |
| 1031 | |
| 1032 | r = setup_vrfb_rotation(fbi); |
| 1033 | if (r) |
Ville Syrjälä | 430571d | 2010-03-17 20:43:23 +0200 | [diff] [blame] | 1034 | goto out; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1035 | |
| 1036 | r = omapfb_apply_changes(fbi, 0); |
| 1037 | |
Ville Syrjälä | 430571d | 2010-03-17 20:43:23 +0200 | [diff] [blame] | 1038 | out: |
Tomi Valkeinen | b41deec | 2012-12-04 14:55:18 +0200 | [diff] [blame] | 1039 | omapfb_unlock(fbdev); |
Ville Syrjälä | 430571d | 2010-03-17 20:43:23 +0200 | [diff] [blame] | 1040 | |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1041 | return r; |
| 1042 | } |
| 1043 | |
| 1044 | static int omapfb_pan_display(struct fb_var_screeninfo *var, |
| 1045 | struct fb_info *fbi) |
| 1046 | { |
Ville Syrjälä | 430571d | 2010-03-17 20:43:23 +0200 | [diff] [blame] | 1047 | struct omapfb_info *ofbi = FB2OFB(fbi); |
Tomi Valkeinen | b41deec | 2012-12-04 14:55:18 +0200 | [diff] [blame] | 1048 | struct omapfb2_device *fbdev = ofbi->fbdev; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1049 | struct fb_var_screeninfo new_var; |
| 1050 | int r; |
| 1051 | |
| 1052 | DBG("pan_display(%d)\n", FB2OFB(fbi)->id); |
| 1053 | |
| 1054 | if (var->xoffset == fbi->var.xoffset && |
| 1055 | var->yoffset == fbi->var.yoffset) |
| 1056 | return 0; |
| 1057 | |
| 1058 | new_var = fbi->var; |
| 1059 | new_var.xoffset = var->xoffset; |
| 1060 | new_var.yoffset = var->yoffset; |
| 1061 | |
| 1062 | fbi->var = new_var; |
| 1063 | |
Tomi Valkeinen | b41deec | 2012-12-04 14:55:18 +0200 | [diff] [blame] | 1064 | omapfb_lock(fbdev); |
Ville Syrjälä | 430571d | 2010-03-17 20:43:23 +0200 | [diff] [blame] | 1065 | |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1066 | r = omapfb_apply_changes(fbi, 0); |
| 1067 | |
Tomi Valkeinen | b41deec | 2012-12-04 14:55:18 +0200 | [diff] [blame] | 1068 | omapfb_unlock(fbdev); |
Ville Syrjälä | 430571d | 2010-03-17 20:43:23 +0200 | [diff] [blame] | 1069 | |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1070 | return r; |
| 1071 | } |
| 1072 | |
| 1073 | static void mmap_user_open(struct vm_area_struct *vma) |
| 1074 | { |
Ville Syrjälä | 078ff54 | 2010-03-17 20:36:51 +0200 | [diff] [blame] | 1075 | struct omapfb2_mem_region *rg = vma->vm_private_data; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1076 | |
Ville Syrjälä | 078ff54 | 2010-03-17 20:36:51 +0200 | [diff] [blame] | 1077 | atomic_inc(&rg->map_count); |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1078 | } |
| 1079 | |
| 1080 | static void mmap_user_close(struct vm_area_struct *vma) |
| 1081 | { |
Ville Syrjälä | 078ff54 | 2010-03-17 20:36:51 +0200 | [diff] [blame] | 1082 | struct omapfb2_mem_region *rg = vma->vm_private_data; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1083 | |
Ville Syrjälä | 078ff54 | 2010-03-17 20:36:51 +0200 | [diff] [blame] | 1084 | atomic_dec(&rg->map_count); |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1085 | } |
| 1086 | |
| 1087 | static struct vm_operations_struct mmap_user_ops = { |
| 1088 | .open = mmap_user_open, |
| 1089 | .close = mmap_user_close, |
| 1090 | }; |
| 1091 | |
| 1092 | static int omapfb_mmap(struct fb_info *fbi, struct vm_area_struct *vma) |
| 1093 | { |
| 1094 | struct omapfb_info *ofbi = FB2OFB(fbi); |
| 1095 | struct fb_fix_screeninfo *fix = &fbi->fix; |
Ville Syrjälä | 078ff54 | 2010-03-17 20:36:51 +0200 | [diff] [blame] | 1096 | struct omapfb2_mem_region *rg; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1097 | unsigned long off; |
| 1098 | unsigned long start; |
| 1099 | u32 len; |
Ville Syrjälä | 430571d | 2010-03-17 20:43:23 +0200 | [diff] [blame] | 1100 | int r = -EINVAL; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1101 | |
| 1102 | if (vma->vm_end - vma->vm_start == 0) |
| 1103 | return 0; |
| 1104 | if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT)) |
| 1105 | return -EINVAL; |
| 1106 | off = vma->vm_pgoff << PAGE_SHIFT; |
| 1107 | |
Tomi Valkeinen | b41deec | 2012-12-04 14:55:18 +0200 | [diff] [blame] | 1108 | rg = ofbi->region; |
Ville Syrjälä | 078ff54 | 2010-03-17 20:36:51 +0200 | [diff] [blame] | 1109 | |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1110 | start = omapfb_get_region_paddr(ofbi); |
| 1111 | len = fix->smem_len; |
| 1112 | if (off >= len) |
Ville Syrjälä | 430571d | 2010-03-17 20:43:23 +0200 | [diff] [blame] | 1113 | goto error; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1114 | if ((vma->vm_end - vma->vm_start + off) > len) |
Ville Syrjälä | 430571d | 2010-03-17 20:43:23 +0200 | [diff] [blame] | 1115 | goto error; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1116 | |
| 1117 | off += start; |
| 1118 | |
| 1119 | DBG("user mmap region start %lx, len %d, off %lx\n", start, len, off); |
| 1120 | |
| 1121 | vma->vm_pgoff = off >> PAGE_SHIFT; |
Konstantin Khlebnikov | 314e51b | 2012-10-08 16:29:02 -0700 | [diff] [blame] | 1122 | /* VM_IO | VM_DONTEXPAND | VM_DONTDUMP are set by remap_pfn_range() */ |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1123 | vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot); |
| 1124 | vma->vm_ops = &mmap_user_ops; |
Ville Syrjälä | 078ff54 | 2010-03-17 20:36:51 +0200 | [diff] [blame] | 1125 | vma->vm_private_data = rg; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1126 | if (io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT, |
Ville Syrjälä | 430571d | 2010-03-17 20:43:23 +0200 | [diff] [blame] | 1127 | vma->vm_end - vma->vm_start, |
| 1128 | vma->vm_page_prot)) { |
| 1129 | r = -EAGAIN; |
| 1130 | goto error; |
| 1131 | } |
| 1132 | |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1133 | /* vm_ops.open won't be called for mmap itself. */ |
Ville Syrjälä | 078ff54 | 2010-03-17 20:36:51 +0200 | [diff] [blame] | 1134 | atomic_inc(&rg->map_count); |
Ville Syrjälä | 430571d | 2010-03-17 20:43:23 +0200 | [diff] [blame] | 1135 | |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1136 | return 0; |
Ville Syrjälä | 430571d | 2010-03-17 20:43:23 +0200 | [diff] [blame] | 1137 | |
| 1138 | error: |
Ville Syrjälä | 430571d | 2010-03-17 20:43:23 +0200 | [diff] [blame] | 1139 | return r; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1140 | } |
| 1141 | |
| 1142 | /* Store a single color palette entry into a pseudo palette or the hardware |
| 1143 | * palette if one is available. For now we support only 16bpp and thus store |
| 1144 | * the entry only to the pseudo palette. |
| 1145 | */ |
| 1146 | static int _setcolreg(struct fb_info *fbi, u_int regno, u_int red, u_int green, |
| 1147 | u_int blue, u_int transp, int update_hw_pal) |
| 1148 | { |
| 1149 | /*struct omapfb_info *ofbi = FB2OFB(fbi);*/ |
| 1150 | /*struct omapfb2_device *fbdev = ofbi->fbdev;*/ |
| 1151 | struct fb_var_screeninfo *var = &fbi->var; |
| 1152 | int r = 0; |
| 1153 | |
| 1154 | enum omapfb_color_format mode = OMAPFB_COLOR_RGB24U; /* XXX */ |
| 1155 | |
| 1156 | /*switch (plane->color_mode) {*/ |
| 1157 | switch (mode) { |
| 1158 | case OMAPFB_COLOR_YUV422: |
| 1159 | case OMAPFB_COLOR_YUV420: |
| 1160 | case OMAPFB_COLOR_YUY422: |
| 1161 | r = -EINVAL; |
| 1162 | break; |
| 1163 | case OMAPFB_COLOR_CLUT_8BPP: |
| 1164 | case OMAPFB_COLOR_CLUT_4BPP: |
| 1165 | case OMAPFB_COLOR_CLUT_2BPP: |
| 1166 | case OMAPFB_COLOR_CLUT_1BPP: |
| 1167 | /* |
| 1168 | if (fbdev->ctrl->setcolreg) |
| 1169 | r = fbdev->ctrl->setcolreg(regno, red, green, blue, |
| 1170 | transp, update_hw_pal); |
| 1171 | */ |
| 1172 | /* Fallthrough */ |
| 1173 | r = -EINVAL; |
| 1174 | break; |
| 1175 | case OMAPFB_COLOR_RGB565: |
| 1176 | case OMAPFB_COLOR_RGB444: |
| 1177 | case OMAPFB_COLOR_RGB24P: |
| 1178 | case OMAPFB_COLOR_RGB24U: |
| 1179 | if (r != 0) |
| 1180 | break; |
| 1181 | |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1182 | if (regno < 16) { |
Grazvydas Ignotas | c1c5284 | 2012-08-21 09:09:48 +0300 | [diff] [blame] | 1183 | u32 pal; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1184 | pal = ((red >> (16 - var->red.length)) << |
| 1185 | var->red.offset) | |
| 1186 | ((green >> (16 - var->green.length)) << |
| 1187 | var->green.offset) | |
| 1188 | (blue >> (16 - var->blue.length)); |
| 1189 | ((u32 *)(fbi->pseudo_palette))[regno] = pal; |
| 1190 | } |
| 1191 | break; |
| 1192 | default: |
| 1193 | BUG(); |
| 1194 | } |
| 1195 | return r; |
| 1196 | } |
| 1197 | |
| 1198 | static int omapfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue, |
| 1199 | u_int transp, struct fb_info *info) |
| 1200 | { |
| 1201 | DBG("setcolreg\n"); |
| 1202 | |
| 1203 | return _setcolreg(info, regno, red, green, blue, transp, 1); |
| 1204 | } |
| 1205 | |
| 1206 | static int omapfb_setcmap(struct fb_cmap *cmap, struct fb_info *info) |
| 1207 | { |
| 1208 | int count, index, r; |
| 1209 | u16 *red, *green, *blue, *transp; |
| 1210 | u16 trans = 0xffff; |
| 1211 | |
| 1212 | DBG("setcmap\n"); |
| 1213 | |
| 1214 | red = cmap->red; |
| 1215 | green = cmap->green; |
| 1216 | blue = cmap->blue; |
| 1217 | transp = cmap->transp; |
| 1218 | index = cmap->start; |
| 1219 | |
| 1220 | for (count = 0; count < cmap->len; count++) { |
| 1221 | if (transp) |
| 1222 | trans = *transp++; |
| 1223 | r = _setcolreg(info, index++, *red++, *green++, *blue++, trans, |
| 1224 | count == cmap->len - 1); |
| 1225 | if (r != 0) |
| 1226 | return r; |
| 1227 | } |
| 1228 | |
| 1229 | return 0; |
| 1230 | } |
| 1231 | |
| 1232 | static int omapfb_blank(int blank, struct fb_info *fbi) |
| 1233 | { |
| 1234 | struct omapfb_info *ofbi = FB2OFB(fbi); |
| 1235 | struct omapfb2_device *fbdev = ofbi->fbdev; |
| 1236 | struct omap_dss_device *display = fb2display(fbi); |
Tomi Valkeinen | 27cc213 | 2011-04-30 16:55:12 +0300 | [diff] [blame] | 1237 | struct omapfb_display_data *d; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1238 | int r = 0; |
| 1239 | |
Jani Nikula | 9325588 | 2010-06-01 15:12:12 +0300 | [diff] [blame] | 1240 | if (!display) |
| 1241 | return -EINVAL; |
| 1242 | |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1243 | omapfb_lock(fbdev); |
| 1244 | |
Tomi Valkeinen | 27cc213 | 2011-04-30 16:55:12 +0300 | [diff] [blame] | 1245 | d = get_display_data(fbdev, display); |
| 1246 | |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1247 | switch (blank) { |
| 1248 | case FB_BLANK_UNBLANK: |
Tomi Valkeinen | 998c336 | 2012-05-30 13:26:00 +0300 | [diff] [blame] | 1249 | if (display->state == OMAP_DSS_DISPLAY_ACTIVE) |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1250 | goto exit; |
| 1251 | |
Tomi Valkeinen | 998c336 | 2012-05-30 13:26:00 +0300 | [diff] [blame] | 1252 | r = display->driver->enable(display); |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1253 | |
Tomi Valkeinen | 27cc213 | 2011-04-30 16:55:12 +0300 | [diff] [blame] | 1254 | if ((display->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE) && |
| 1255 | d->update_mode == OMAPFB_AUTO_UPDATE && |
| 1256 | !d->auto_update_work_enabled) |
| 1257 | omapfb_start_auto_update(fbdev, display); |
| 1258 | |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1259 | break; |
| 1260 | |
| 1261 | case FB_BLANK_NORMAL: |
| 1262 | /* FB_BLANK_NORMAL could be implemented. |
| 1263 | * Needs DSS additions. */ |
| 1264 | case FB_BLANK_VSYNC_SUSPEND: |
| 1265 | case FB_BLANK_HSYNC_SUSPEND: |
| 1266 | case FB_BLANK_POWERDOWN: |
| 1267 | if (display->state != OMAP_DSS_DISPLAY_ACTIVE) |
| 1268 | goto exit; |
| 1269 | |
Tomi Valkeinen | 27cc213 | 2011-04-30 16:55:12 +0300 | [diff] [blame] | 1270 | if (d->auto_update_work_enabled) |
| 1271 | omapfb_stop_auto_update(fbdev, display); |
| 1272 | |
Tomi Valkeinen | 998c336 | 2012-05-30 13:26:00 +0300 | [diff] [blame] | 1273 | display->driver->disable(display); |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1274 | |
| 1275 | break; |
| 1276 | |
| 1277 | default: |
| 1278 | r = -EINVAL; |
| 1279 | } |
| 1280 | |
| 1281 | exit: |
| 1282 | omapfb_unlock(fbdev); |
| 1283 | |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1284 | return r; |
| 1285 | } |
| 1286 | |
| 1287 | #if 0 |
| 1288 | /* XXX fb_read and fb_write are needed for VRFB */ |
| 1289 | ssize_t omapfb_write(struct fb_info *info, const char __user *buf, |
| 1290 | size_t count, loff_t *ppos) |
| 1291 | { |
| 1292 | DBG("omapfb_write %d, %lu\n", count, (unsigned long)*ppos); |
| 1293 | /* XXX needed for VRFB */ |
| 1294 | return count; |
| 1295 | } |
| 1296 | #endif |
| 1297 | |
| 1298 | static struct fb_ops omapfb_ops = { |
| 1299 | .owner = THIS_MODULE, |
| 1300 | .fb_open = omapfb_open, |
| 1301 | .fb_release = omapfb_release, |
| 1302 | .fb_fillrect = cfb_fillrect, |
| 1303 | .fb_copyarea = cfb_copyarea, |
| 1304 | .fb_imageblit = cfb_imageblit, |
| 1305 | .fb_blank = omapfb_blank, |
| 1306 | .fb_ioctl = omapfb_ioctl, |
| 1307 | .fb_check_var = omapfb_check_var, |
| 1308 | .fb_set_par = omapfb_set_par, |
| 1309 | .fb_pan_display = omapfb_pan_display, |
| 1310 | .fb_mmap = omapfb_mmap, |
| 1311 | .fb_setcolreg = omapfb_setcolreg, |
| 1312 | .fb_setcmap = omapfb_setcmap, |
| 1313 | /*.fb_write = omapfb_write,*/ |
| 1314 | }; |
| 1315 | |
| 1316 | static void omapfb_free_fbmem(struct fb_info *fbi) |
| 1317 | { |
| 1318 | struct omapfb_info *ofbi = FB2OFB(fbi); |
| 1319 | struct omapfb2_device *fbdev = ofbi->fbdev; |
| 1320 | struct omapfb2_mem_region *rg; |
| 1321 | |
Ville Syrjälä | 078ff54 | 2010-03-17 20:36:51 +0200 | [diff] [blame] | 1322 | rg = ofbi->region; |
| 1323 | |
Tomi Valkeinen | 0049fb2 | 2012-11-09 15:52:20 +0200 | [diff] [blame] | 1324 | if (rg->token == NULL) |
| 1325 | return; |
| 1326 | |
Ville Syrjälä | 078ff54 | 2010-03-17 20:36:51 +0200 | [diff] [blame] | 1327 | WARN_ON(atomic_read(&rg->map_count)); |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1328 | |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1329 | if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB) { |
| 1330 | /* unmap the 0 angle rotation */ |
| 1331 | if (rg->vrfb.vaddr[0]) { |
| 1332 | iounmap(rg->vrfb.vaddr[0]); |
Tomi Valkeinen | f3a82d1 | 2010-01-07 13:37:30 +0200 | [diff] [blame] | 1333 | rg->vrfb.vaddr[0] = NULL; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1334 | } |
Tomi Valkeinen | 0049fb2 | 2012-11-09 15:52:20 +0200 | [diff] [blame] | 1335 | |
| 1336 | omap_vrfb_release_ctx(&rg->vrfb); |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1337 | } |
| 1338 | |
Tomi Valkeinen | 0049fb2 | 2012-11-09 15:52:20 +0200 | [diff] [blame] | 1339 | dma_free_attrs(fbdev->dev, rg->size, rg->token, rg->dma_handle, |
| 1340 | &rg->attrs); |
| 1341 | |
| 1342 | rg->token = NULL; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1343 | rg->vaddr = NULL; |
| 1344 | rg->paddr = 0; |
| 1345 | rg->alloc = 0; |
| 1346 | rg->size = 0; |
| 1347 | } |
| 1348 | |
| 1349 | static void clear_fb_info(struct fb_info *fbi) |
| 1350 | { |
| 1351 | memset(&fbi->var, 0, sizeof(fbi->var)); |
| 1352 | memset(&fbi->fix, 0, sizeof(fbi->fix)); |
| 1353 | strlcpy(fbi->fix.id, MODULE_NAME, sizeof(fbi->fix.id)); |
| 1354 | } |
| 1355 | |
| 1356 | static int omapfb_free_all_fbmem(struct omapfb2_device *fbdev) |
| 1357 | { |
| 1358 | int i; |
| 1359 | |
| 1360 | DBG("free all fbmem\n"); |
| 1361 | |
| 1362 | for (i = 0; i < fbdev->num_fbs; i++) { |
| 1363 | struct fb_info *fbi = fbdev->fbs[i]; |
| 1364 | omapfb_free_fbmem(fbi); |
| 1365 | clear_fb_info(fbi); |
| 1366 | } |
| 1367 | |
| 1368 | return 0; |
| 1369 | } |
| 1370 | |
| 1371 | static int omapfb_alloc_fbmem(struct fb_info *fbi, unsigned long size, |
| 1372 | unsigned long paddr) |
| 1373 | { |
| 1374 | struct omapfb_info *ofbi = FB2OFB(fbi); |
| 1375 | struct omapfb2_device *fbdev = ofbi->fbdev; |
| 1376 | struct omapfb2_mem_region *rg; |
Tomi Valkeinen | 0049fb2 | 2012-11-09 15:52:20 +0200 | [diff] [blame] | 1377 | void *token; |
| 1378 | DEFINE_DMA_ATTRS(attrs); |
| 1379 | dma_addr_t dma_handle; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1380 | int r; |
| 1381 | |
Ville Syrjälä | 078ff54 | 2010-03-17 20:36:51 +0200 | [diff] [blame] | 1382 | rg = ofbi->region; |
| 1383 | |
| 1384 | rg->paddr = 0; |
| 1385 | rg->vaddr = NULL; |
| 1386 | memset(&rg->vrfb, 0, sizeof rg->vrfb); |
| 1387 | rg->size = 0; |
| 1388 | rg->type = 0; |
| 1389 | rg->alloc = false; |
| 1390 | rg->map = false; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1391 | |
| 1392 | size = PAGE_ALIGN(size); |
| 1393 | |
Tomi Valkeinen | 0049fb2 | 2012-11-09 15:52:20 +0200 | [diff] [blame] | 1394 | dma_set_attr(DMA_ATTR_WRITE_COMBINE, &attrs); |
| 1395 | |
| 1396 | if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB) |
| 1397 | dma_set_attr(DMA_ATTR_NO_KERNEL_MAPPING, &attrs); |
| 1398 | |
| 1399 | DBG("allocating %lu bytes for fb %d\n", size, ofbi->id); |
| 1400 | |
| 1401 | token = dma_alloc_attrs(fbdev->dev, size, &dma_handle, |
| 1402 | GFP_KERNEL, &attrs); |
| 1403 | |
| 1404 | if (token == NULL) { |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1405 | dev_err(fbdev->dev, "failed to allocate framebuffer\n"); |
| 1406 | return -ENOMEM; |
| 1407 | } |
| 1408 | |
Tomi Valkeinen | 0049fb2 | 2012-11-09 15:52:20 +0200 | [diff] [blame] | 1409 | DBG("allocated VRAM paddr %lx, vaddr %p\n", |
| 1410 | (unsigned long)dma_handle, token); |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1411 | |
Tomi Valkeinen | 0049fb2 | 2012-11-09 15:52:20 +0200 | [diff] [blame] | 1412 | if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB) { |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1413 | r = omap_vrfb_request_ctx(&rg->vrfb); |
| 1414 | if (r) { |
Tomi Valkeinen | 0049fb2 | 2012-11-09 15:52:20 +0200 | [diff] [blame] | 1415 | dma_free_attrs(fbdev->dev, size, token, dma_handle, |
| 1416 | &attrs); |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1417 | dev_err(fbdev->dev, "vrfb create ctx failed\n"); |
| 1418 | return r; |
| 1419 | } |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1420 | } |
| 1421 | |
Tomi Valkeinen | 0049fb2 | 2012-11-09 15:52:20 +0200 | [diff] [blame] | 1422 | rg->attrs = attrs; |
| 1423 | rg->token = token; |
| 1424 | rg->dma_handle = dma_handle; |
| 1425 | |
| 1426 | rg->paddr = (unsigned long)dma_handle; |
| 1427 | rg->vaddr = (void __iomem *)token; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1428 | rg->size = size; |
| 1429 | rg->alloc = 1; |
| 1430 | |
| 1431 | return 0; |
| 1432 | } |
| 1433 | |
| 1434 | /* allocate fbmem using display resolution as reference */ |
| 1435 | static int omapfb_alloc_fbmem_display(struct fb_info *fbi, unsigned long size, |
| 1436 | unsigned long paddr) |
| 1437 | { |
| 1438 | struct omapfb_info *ofbi = FB2OFB(fbi); |
Tomi Valkeinen | a269950 | 2010-01-11 14:33:40 +0200 | [diff] [blame] | 1439 | struct omapfb2_device *fbdev = ofbi->fbdev; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1440 | struct omap_dss_device *display; |
| 1441 | int bytespp; |
| 1442 | |
| 1443 | display = fb2display(fbi); |
| 1444 | |
| 1445 | if (!display) |
| 1446 | return 0; |
| 1447 | |
Tomi Valkeinen | a269950 | 2010-01-11 14:33:40 +0200 | [diff] [blame] | 1448 | switch (omapfb_get_recommended_bpp(fbdev, display)) { |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1449 | case 16: |
| 1450 | bytespp = 2; |
| 1451 | break; |
| 1452 | case 24: |
| 1453 | bytespp = 4; |
| 1454 | break; |
| 1455 | default: |
| 1456 | bytespp = 4; |
| 1457 | break; |
| 1458 | } |
| 1459 | |
| 1460 | if (!size) { |
| 1461 | u16 w, h; |
| 1462 | |
Tomi Valkeinen | 96adcec | 2010-01-11 13:54:33 +0200 | [diff] [blame] | 1463 | display->driver->get_resolution(display, &w, &h); |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1464 | |
| 1465 | if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB) { |
| 1466 | size = max(omap_vrfb_min_phys_size(w, h, bytespp), |
| 1467 | omap_vrfb_min_phys_size(h, w, bytespp)); |
| 1468 | |
| 1469 | DBG("adjusting fb mem size for VRFB, %u -> %lu\n", |
| 1470 | w * h * bytespp, size); |
| 1471 | } else { |
| 1472 | size = w * h * bytespp; |
| 1473 | } |
| 1474 | } |
| 1475 | |
| 1476 | if (!size) |
| 1477 | return 0; |
| 1478 | |
| 1479 | return omapfb_alloc_fbmem(fbi, size, paddr); |
| 1480 | } |
| 1481 | |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1482 | static int omapfb_parse_vram_param(const char *param, int max_entries, |
| 1483 | unsigned long *sizes, unsigned long *paddrs) |
| 1484 | { |
| 1485 | int fbnum; |
| 1486 | unsigned long size; |
| 1487 | unsigned long paddr = 0; |
| 1488 | char *p, *start; |
| 1489 | |
| 1490 | start = (char *)param; |
| 1491 | |
| 1492 | while (1) { |
| 1493 | p = start; |
| 1494 | |
| 1495 | fbnum = simple_strtoul(p, &p, 10); |
| 1496 | |
Tomi Valkeinen | 3a028bb | 2012-05-10 11:15:14 +0300 | [diff] [blame] | 1497 | if (p == start) |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1498 | return -EINVAL; |
| 1499 | |
| 1500 | if (*p != ':') |
| 1501 | return -EINVAL; |
| 1502 | |
| 1503 | if (fbnum >= max_entries) |
| 1504 | return -EINVAL; |
| 1505 | |
| 1506 | size = memparse(p + 1, &p); |
| 1507 | |
| 1508 | if (!size) |
| 1509 | return -EINVAL; |
| 1510 | |
| 1511 | paddr = 0; |
| 1512 | |
| 1513 | if (*p == '@') { |
| 1514 | paddr = simple_strtoul(p + 1, &p, 16); |
| 1515 | |
| 1516 | if (!paddr) |
| 1517 | return -EINVAL; |
| 1518 | |
| 1519 | } |
| 1520 | |
Tomi Valkeinen | 09a8c45 | 2012-12-04 16:26:09 +0200 | [diff] [blame] | 1521 | WARN_ONCE(paddr, |
| 1522 | "reserving memory at predefined address not supported\n"); |
| 1523 | |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1524 | paddrs[fbnum] = paddr; |
| 1525 | sizes[fbnum] = size; |
| 1526 | |
| 1527 | if (*p == 0) |
| 1528 | break; |
| 1529 | |
| 1530 | if (*p != ',') |
| 1531 | return -EINVAL; |
| 1532 | |
| 1533 | ++p; |
| 1534 | |
| 1535 | start = p; |
| 1536 | } |
| 1537 | |
| 1538 | return 0; |
| 1539 | } |
| 1540 | |
| 1541 | static int omapfb_allocate_all_fbs(struct omapfb2_device *fbdev) |
| 1542 | { |
| 1543 | int i, r; |
| 1544 | unsigned long vram_sizes[10]; |
| 1545 | unsigned long vram_paddrs[10]; |
| 1546 | |
| 1547 | memset(&vram_sizes, 0, sizeof(vram_sizes)); |
| 1548 | memset(&vram_paddrs, 0, sizeof(vram_paddrs)); |
| 1549 | |
| 1550 | if (def_vram && omapfb_parse_vram_param(def_vram, 10, |
| 1551 | vram_sizes, vram_paddrs)) { |
| 1552 | dev_err(fbdev->dev, "failed to parse vram parameter\n"); |
| 1553 | |
| 1554 | memset(&vram_sizes, 0, sizeof(vram_sizes)); |
| 1555 | memset(&vram_paddrs, 0, sizeof(vram_paddrs)); |
| 1556 | } |
| 1557 | |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1558 | for (i = 0; i < fbdev->num_fbs; i++) { |
| 1559 | /* allocate memory automatically only for fb0, or if |
| 1560 | * excplicitly defined with vram or plat data option */ |
| 1561 | if (i == 0 || vram_sizes[i] != 0) { |
| 1562 | r = omapfb_alloc_fbmem_display(fbdev->fbs[i], |
| 1563 | vram_sizes[i], vram_paddrs[i]); |
| 1564 | |
| 1565 | if (r) |
| 1566 | return r; |
| 1567 | } |
| 1568 | } |
| 1569 | |
| 1570 | for (i = 0; i < fbdev->num_fbs; i++) { |
| 1571 | struct omapfb_info *ofbi = FB2OFB(fbdev->fbs[i]); |
| 1572 | struct omapfb2_mem_region *rg; |
Ville Syrjälä | 078ff54 | 2010-03-17 20:36:51 +0200 | [diff] [blame] | 1573 | rg = ofbi->region; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1574 | |
| 1575 | DBG("region%d phys %08x virt %p size=%lu\n", |
| 1576 | i, |
| 1577 | rg->paddr, |
| 1578 | rg->vaddr, |
| 1579 | rg->size); |
| 1580 | } |
| 1581 | |
| 1582 | return 0; |
| 1583 | } |
| 1584 | |
Tomi Valkeinen | ca44415 | 2012-08-30 16:53:29 +0300 | [diff] [blame] | 1585 | static void omapfb_clear_fb(struct fb_info *fbi) |
| 1586 | { |
| 1587 | const struct fb_fillrect rect = { |
| 1588 | .dx = 0, |
| 1589 | .dy = 0, |
| 1590 | .width = fbi->var.xres_virtual, |
| 1591 | .height = fbi->var.yres_virtual, |
| 1592 | .color = 0, |
| 1593 | .rop = ROP_COPY, |
| 1594 | }; |
| 1595 | |
| 1596 | cfb_fillrect(fbi, &rect); |
| 1597 | } |
| 1598 | |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1599 | int omapfb_realloc_fbmem(struct fb_info *fbi, unsigned long size, int type) |
| 1600 | { |
| 1601 | struct omapfb_info *ofbi = FB2OFB(fbi); |
| 1602 | struct omapfb2_device *fbdev = ofbi->fbdev; |
Ville Syrjälä | 078ff54 | 2010-03-17 20:36:51 +0200 | [diff] [blame] | 1603 | struct omapfb2_mem_region *rg = ofbi->region; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1604 | unsigned long old_size = rg->size; |
| 1605 | unsigned long old_paddr = rg->paddr; |
| 1606 | int old_type = rg->type; |
| 1607 | int r; |
| 1608 | |
Tomi Valkeinen | 2a803c8 | 2011-04-18 13:18:20 +0300 | [diff] [blame] | 1609 | if (type != OMAPFB_MEMTYPE_SDRAM) |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1610 | return -EINVAL; |
| 1611 | |
| 1612 | size = PAGE_ALIGN(size); |
| 1613 | |
| 1614 | if (old_size == size && old_type == type) |
| 1615 | return 0; |
| 1616 | |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1617 | omapfb_free_fbmem(fbi); |
| 1618 | |
| 1619 | if (size == 0) { |
| 1620 | clear_fb_info(fbi); |
| 1621 | return 0; |
| 1622 | } |
| 1623 | |
| 1624 | r = omapfb_alloc_fbmem(fbi, size, 0); |
| 1625 | |
| 1626 | if (r) { |
| 1627 | if (old_size) |
| 1628 | omapfb_alloc_fbmem(fbi, old_size, old_paddr); |
| 1629 | |
| 1630 | if (rg->size == 0) |
| 1631 | clear_fb_info(fbi); |
| 1632 | |
| 1633 | return r; |
| 1634 | } |
| 1635 | |
| 1636 | if (old_size == size) |
| 1637 | return 0; |
| 1638 | |
| 1639 | if (old_size == 0) { |
| 1640 | DBG("initializing fb %d\n", ofbi->id); |
| 1641 | r = omapfb_fb_init(fbdev, fbi); |
| 1642 | if (r) { |
| 1643 | DBG("omapfb_fb_init failed\n"); |
| 1644 | goto err; |
| 1645 | } |
| 1646 | r = omapfb_apply_changes(fbi, 1); |
| 1647 | if (r) { |
| 1648 | DBG("omapfb_apply_changes failed\n"); |
| 1649 | goto err; |
| 1650 | } |
| 1651 | } else { |
| 1652 | struct fb_var_screeninfo new_var; |
| 1653 | memcpy(&new_var, &fbi->var, sizeof(new_var)); |
| 1654 | r = check_fb_var(fbi, &new_var); |
| 1655 | if (r) |
| 1656 | goto err; |
| 1657 | memcpy(&fbi->var, &new_var, sizeof(fbi->var)); |
| 1658 | set_fb_fix(fbi); |
| 1659 | r = setup_vrfb_rotation(fbi); |
| 1660 | if (r) |
| 1661 | goto err; |
| 1662 | } |
| 1663 | |
Tomi Valkeinen | ca44415 | 2012-08-30 16:53:29 +0300 | [diff] [blame] | 1664 | omapfb_clear_fb(fbi); |
| 1665 | |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1666 | return 0; |
| 1667 | err: |
| 1668 | omapfb_free_fbmem(fbi); |
| 1669 | clear_fb_info(fbi); |
| 1670 | return r; |
| 1671 | } |
| 1672 | |
Tomi Valkeinen | 27cc213 | 2011-04-30 16:55:12 +0300 | [diff] [blame] | 1673 | static void omapfb_auto_update_work(struct work_struct *work) |
| 1674 | { |
| 1675 | struct omap_dss_device *dssdev; |
| 1676 | struct omap_dss_driver *dssdrv; |
| 1677 | struct omapfb_display_data *d; |
| 1678 | u16 w, h; |
| 1679 | unsigned int freq; |
| 1680 | struct omapfb2_device *fbdev; |
| 1681 | |
| 1682 | d = container_of(work, struct omapfb_display_data, |
| 1683 | auto_update_work.work); |
| 1684 | |
| 1685 | dssdev = d->dssdev; |
| 1686 | dssdrv = dssdev->driver; |
| 1687 | fbdev = d->fbdev; |
| 1688 | |
| 1689 | if (!dssdrv || !dssdrv->update) |
| 1690 | return; |
| 1691 | |
| 1692 | if (dssdrv->sync) |
| 1693 | dssdrv->sync(dssdev); |
| 1694 | |
| 1695 | dssdrv->get_resolution(dssdev, &w, &h); |
| 1696 | dssdrv->update(dssdev, 0, 0, w, h); |
| 1697 | |
| 1698 | freq = auto_update_freq; |
| 1699 | if (freq == 0) |
| 1700 | freq = 20; |
| 1701 | queue_delayed_work(fbdev->auto_update_wq, |
| 1702 | &d->auto_update_work, HZ / freq); |
| 1703 | } |
| 1704 | |
| 1705 | void omapfb_start_auto_update(struct omapfb2_device *fbdev, |
| 1706 | struct omap_dss_device *display) |
| 1707 | { |
| 1708 | struct omapfb_display_data *d; |
| 1709 | |
| 1710 | if (fbdev->auto_update_wq == NULL) { |
| 1711 | struct workqueue_struct *wq; |
| 1712 | |
| 1713 | wq = create_singlethread_workqueue("omapfb_auto_update"); |
| 1714 | |
| 1715 | if (wq == NULL) { |
| 1716 | dev_err(fbdev->dev, "Failed to create workqueue for " |
| 1717 | "auto-update\n"); |
| 1718 | return; |
| 1719 | } |
| 1720 | |
| 1721 | fbdev->auto_update_wq = wq; |
| 1722 | } |
| 1723 | |
| 1724 | d = get_display_data(fbdev, display); |
| 1725 | |
| 1726 | INIT_DELAYED_WORK(&d->auto_update_work, omapfb_auto_update_work); |
| 1727 | |
| 1728 | d->auto_update_work_enabled = true; |
| 1729 | |
| 1730 | omapfb_auto_update_work(&d->auto_update_work.work); |
| 1731 | } |
| 1732 | |
| 1733 | void omapfb_stop_auto_update(struct omapfb2_device *fbdev, |
| 1734 | struct omap_dss_device *display) |
| 1735 | { |
| 1736 | struct omapfb_display_data *d; |
| 1737 | |
| 1738 | d = get_display_data(fbdev, display); |
| 1739 | |
| 1740 | cancel_delayed_work_sync(&d->auto_update_work); |
| 1741 | |
| 1742 | d->auto_update_work_enabled = false; |
| 1743 | } |
| 1744 | |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1745 | /* initialize fb_info, var, fix to something sane based on the display */ |
| 1746 | static int omapfb_fb_init(struct omapfb2_device *fbdev, struct fb_info *fbi) |
| 1747 | { |
| 1748 | struct fb_var_screeninfo *var = &fbi->var; |
| 1749 | struct omap_dss_device *display = fb2display(fbi); |
| 1750 | struct omapfb_info *ofbi = FB2OFB(fbi); |
| 1751 | int r = 0; |
| 1752 | |
| 1753 | fbi->fbops = &omapfb_ops; |
| 1754 | fbi->flags = FBINFO_FLAG_DEFAULT; |
| 1755 | fbi->pseudo_palette = fbdev->pseudo_palette; |
| 1756 | |
Ville Syrjälä | 078ff54 | 2010-03-17 20:36:51 +0200 | [diff] [blame] | 1757 | if (ofbi->region->size == 0) { |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1758 | clear_fb_info(fbi); |
| 1759 | return 0; |
| 1760 | } |
| 1761 | |
| 1762 | var->nonstd = 0; |
| 1763 | var->bits_per_pixel = 0; |
| 1764 | |
| 1765 | var->rotate = def_rotate; |
| 1766 | |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1767 | if (display) { |
| 1768 | u16 w, h; |
| 1769 | int rotation = (var->rotate + ofbi->rotation[0]) % 4; |
| 1770 | |
Tomi Valkeinen | 96adcec | 2010-01-11 13:54:33 +0200 | [diff] [blame] | 1771 | display->driver->get_resolution(display, &w, &h); |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1772 | |
| 1773 | if (rotation == FB_ROTATE_CW || |
| 1774 | rotation == FB_ROTATE_CCW) { |
| 1775 | var->xres = h; |
| 1776 | var->yres = w; |
| 1777 | } else { |
| 1778 | var->xres = w; |
| 1779 | var->yres = h; |
| 1780 | } |
| 1781 | |
| 1782 | var->xres_virtual = var->xres; |
| 1783 | var->yres_virtual = var->yres; |
| 1784 | |
| 1785 | if (!var->bits_per_pixel) { |
Tomi Valkeinen | a269950 | 2010-01-11 14:33:40 +0200 | [diff] [blame] | 1786 | switch (omapfb_get_recommended_bpp(fbdev, display)) { |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1787 | case 16: |
| 1788 | var->bits_per_pixel = 16; |
| 1789 | break; |
| 1790 | case 24: |
| 1791 | var->bits_per_pixel = 32; |
| 1792 | break; |
| 1793 | default: |
| 1794 | dev_err(fbdev->dev, "illegal display " |
| 1795 | "bpp\n"); |
| 1796 | return -EINVAL; |
| 1797 | } |
| 1798 | } |
| 1799 | } else { |
| 1800 | /* if there's no display, let's just guess some basic values */ |
| 1801 | var->xres = 320; |
| 1802 | var->yres = 240; |
| 1803 | var->xres_virtual = var->xres; |
| 1804 | var->yres_virtual = var->yres; |
| 1805 | if (!var->bits_per_pixel) |
| 1806 | var->bits_per_pixel = 16; |
| 1807 | } |
| 1808 | |
| 1809 | r = check_fb_var(fbi, var); |
| 1810 | if (r) |
| 1811 | goto err; |
| 1812 | |
| 1813 | set_fb_fix(fbi); |
| 1814 | r = setup_vrfb_rotation(fbi); |
| 1815 | if (r) |
| 1816 | goto err; |
| 1817 | |
| 1818 | r = fb_alloc_cmap(&fbi->cmap, 256, 0); |
| 1819 | if (r) |
| 1820 | dev_err(fbdev->dev, "unable to allocate color map memory\n"); |
| 1821 | |
| 1822 | err: |
| 1823 | return r; |
| 1824 | } |
| 1825 | |
| 1826 | static void fbinfo_cleanup(struct omapfb2_device *fbdev, struct fb_info *fbi) |
| 1827 | { |
| 1828 | fb_dealloc_cmap(&fbi->cmap); |
| 1829 | } |
| 1830 | |
| 1831 | |
| 1832 | static void omapfb_free_resources(struct omapfb2_device *fbdev) |
| 1833 | { |
| 1834 | int i; |
| 1835 | |
| 1836 | DBG("free_resources\n"); |
| 1837 | |
| 1838 | if (fbdev == NULL) |
| 1839 | return; |
| 1840 | |
| 1841 | for (i = 0; i < fbdev->num_fbs; i++) |
| 1842 | unregister_framebuffer(fbdev->fbs[i]); |
| 1843 | |
| 1844 | /* free the reserved fbmem */ |
| 1845 | omapfb_free_all_fbmem(fbdev); |
| 1846 | |
| 1847 | for (i = 0; i < fbdev->num_fbs; i++) { |
| 1848 | fbinfo_cleanup(fbdev, fbdev->fbs[i]); |
| 1849 | framebuffer_release(fbdev->fbs[i]); |
| 1850 | } |
| 1851 | |
| 1852 | for (i = 0; i < fbdev->num_displays; i++) { |
Tomi Valkeinen | 065a40b | 2011-04-30 12:13:14 +0300 | [diff] [blame] | 1853 | struct omap_dss_device *dssdev = fbdev->displays[i].dssdev; |
Tomi Valkeinen | 27cc213 | 2011-04-30 16:55:12 +0300 | [diff] [blame] | 1854 | |
| 1855 | if (fbdev->displays[i].auto_update_work_enabled) |
| 1856 | omapfb_stop_auto_update(fbdev, dssdev); |
| 1857 | |
Tomi Valkeinen | 065a40b | 2011-04-30 12:13:14 +0300 | [diff] [blame] | 1858 | if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) |
| 1859 | dssdev->driver->disable(dssdev); |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1860 | |
Tomi Valkeinen | 065a40b | 2011-04-30 12:13:14 +0300 | [diff] [blame] | 1861 | omap_dss_put_device(dssdev); |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1862 | } |
| 1863 | |
Tomi Valkeinen | 27cc213 | 2011-04-30 16:55:12 +0300 | [diff] [blame] | 1864 | if (fbdev->auto_update_wq != NULL) { |
| 1865 | flush_workqueue(fbdev->auto_update_wq); |
| 1866 | destroy_workqueue(fbdev->auto_update_wq); |
| 1867 | fbdev->auto_update_wq = NULL; |
| 1868 | } |
| 1869 | |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1870 | dev_set_drvdata(fbdev->dev, NULL); |
| 1871 | kfree(fbdev); |
| 1872 | } |
| 1873 | |
| 1874 | static int omapfb_create_framebuffers(struct omapfb2_device *fbdev) |
| 1875 | { |
| 1876 | int r, i; |
| 1877 | |
| 1878 | fbdev->num_fbs = 0; |
| 1879 | |
| 1880 | DBG("create %d framebuffers\n", CONFIG_FB_OMAP2_NUM_FBS); |
| 1881 | |
| 1882 | /* allocate fb_infos */ |
| 1883 | for (i = 0; i < CONFIG_FB_OMAP2_NUM_FBS; i++) { |
| 1884 | struct fb_info *fbi; |
| 1885 | struct omapfb_info *ofbi; |
| 1886 | |
| 1887 | fbi = framebuffer_alloc(sizeof(struct omapfb_info), |
| 1888 | fbdev->dev); |
| 1889 | |
| 1890 | if (fbi == NULL) { |
| 1891 | dev_err(fbdev->dev, |
| 1892 | "unable to allocate memory for plane info\n"); |
| 1893 | return -ENOMEM; |
| 1894 | } |
| 1895 | |
| 1896 | clear_fb_info(fbi); |
| 1897 | |
| 1898 | fbdev->fbs[i] = fbi; |
| 1899 | |
| 1900 | ofbi = FB2OFB(fbi); |
| 1901 | ofbi->fbdev = fbdev; |
| 1902 | ofbi->id = i; |
| 1903 | |
Ville Syrjälä | 078ff54 | 2010-03-17 20:36:51 +0200 | [diff] [blame] | 1904 | ofbi->region = &fbdev->regions[i]; |
| 1905 | ofbi->region->id = i; |
| 1906 | |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1907 | /* assign these early, so that fb alloc can use them */ |
| 1908 | ofbi->rotation_type = def_vrfb ? OMAP_DSS_ROT_VRFB : |
| 1909 | OMAP_DSS_ROT_DMA; |
| 1910 | ofbi->mirror = def_mirror; |
| 1911 | |
| 1912 | fbdev->num_fbs++; |
| 1913 | } |
| 1914 | |
| 1915 | DBG("fb_infos allocated\n"); |
| 1916 | |
| 1917 | /* assign overlays for the fbs */ |
| 1918 | for (i = 0; i < min(fbdev->num_fbs, fbdev->num_overlays); i++) { |
| 1919 | struct omapfb_info *ofbi = FB2OFB(fbdev->fbs[i]); |
| 1920 | |
| 1921 | ofbi->overlays[0] = fbdev->overlays[i]; |
| 1922 | ofbi->num_overlays = 1; |
| 1923 | } |
| 1924 | |
| 1925 | /* allocate fb memories */ |
| 1926 | r = omapfb_allocate_all_fbs(fbdev); |
| 1927 | if (r) { |
| 1928 | dev_err(fbdev->dev, "failed to allocate fbmem\n"); |
| 1929 | return r; |
| 1930 | } |
| 1931 | |
| 1932 | DBG("fbmems allocated\n"); |
| 1933 | |
| 1934 | /* setup fb_infos */ |
| 1935 | for (i = 0; i < fbdev->num_fbs; i++) { |
Ville Syrjälä | 430571d | 2010-03-17 20:43:23 +0200 | [diff] [blame] | 1936 | struct fb_info *fbi = fbdev->fbs[i]; |
Ville Syrjälä | 430571d | 2010-03-17 20:43:23 +0200 | [diff] [blame] | 1937 | |
Ville Syrjälä | 430571d | 2010-03-17 20:43:23 +0200 | [diff] [blame] | 1938 | r = omapfb_fb_init(fbdev, fbi); |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1939 | if (r) { |
| 1940 | dev_err(fbdev->dev, "failed to setup fb_info\n"); |
| 1941 | return r; |
| 1942 | } |
| 1943 | } |
| 1944 | |
Archit Taneja | fda7c36 | 2012-09-11 15:34:08 +0530 | [diff] [blame] | 1945 | for (i = 0; i < fbdev->num_fbs; i++) { |
| 1946 | struct fb_info *fbi = fbdev->fbs[i]; |
| 1947 | struct omapfb_info *ofbi = FB2OFB(fbi); |
| 1948 | |
| 1949 | if (ofbi->region->size == 0) |
| 1950 | continue; |
| 1951 | |
| 1952 | omapfb_clear_fb(fbi); |
| 1953 | } |
| 1954 | |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1955 | DBG("fb_infos initialized\n"); |
| 1956 | |
| 1957 | for (i = 0; i < fbdev->num_fbs; i++) { |
| 1958 | r = register_framebuffer(fbdev->fbs[i]); |
| 1959 | if (r != 0) { |
| 1960 | dev_err(fbdev->dev, |
| 1961 | "registering framebuffer %d failed\n", i); |
| 1962 | return r; |
| 1963 | } |
| 1964 | } |
| 1965 | |
| 1966 | DBG("framebuffers registered\n"); |
| 1967 | |
| 1968 | for (i = 0; i < fbdev->num_fbs; i++) { |
Ville Syrjälä | 430571d | 2010-03-17 20:43:23 +0200 | [diff] [blame] | 1969 | struct fb_info *fbi = fbdev->fbs[i]; |
Ville Syrjälä | 430571d | 2010-03-17 20:43:23 +0200 | [diff] [blame] | 1970 | |
Ville Syrjälä | 430571d | 2010-03-17 20:43:23 +0200 | [diff] [blame] | 1971 | r = omapfb_apply_changes(fbi, 1); |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1972 | if (r) { |
| 1973 | dev_err(fbdev->dev, "failed to change mode\n"); |
| 1974 | return r; |
| 1975 | } |
| 1976 | } |
| 1977 | |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1978 | /* Enable fb0 */ |
| 1979 | if (fbdev->num_fbs > 0) { |
| 1980 | struct omapfb_info *ofbi = FB2OFB(fbdev->fbs[0]); |
| 1981 | |
| 1982 | if (ofbi->num_overlays > 0) { |
| 1983 | struct omap_overlay *ovl = ofbi->overlays[0]; |
| 1984 | |
Tomi Valkeinen | aaa874a | 2011-11-15 16:37:53 +0200 | [diff] [blame] | 1985 | ovl->manager->apply(ovl->manager); |
| 1986 | |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 1987 | r = omapfb_overlay_enable(ovl, 1); |
| 1988 | |
| 1989 | if (r) { |
| 1990 | dev_err(fbdev->dev, |
| 1991 | "failed to enable overlay\n"); |
| 1992 | return r; |
| 1993 | } |
| 1994 | } |
| 1995 | } |
| 1996 | |
| 1997 | DBG("create_framebuffers done\n"); |
| 1998 | |
| 1999 | return 0; |
| 2000 | } |
| 2001 | |
| 2002 | static int omapfb_mode_to_timings(const char *mode_str, |
Archit Taneja | 783babf | 2012-06-15 07:39:47 +0530 | [diff] [blame] | 2003 | struct omap_dss_device *display, |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 2004 | struct omap_video_timings *timings, u8 *bpp) |
| 2005 | { |
Tomi Valkeinen | 897044e | 2011-04-30 15:26:40 +0300 | [diff] [blame] | 2006 | struct fb_info *fbi; |
| 2007 | struct fb_var_screeninfo *var; |
| 2008 | struct fb_ops *fbops; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 2009 | int r; |
| 2010 | |
| 2011 | #ifdef CONFIG_OMAP2_DSS_VENC |
| 2012 | if (strcmp(mode_str, "pal") == 0) { |
| 2013 | *timings = omap_dss_pal_timings; |
Maurus Cuelenaere | e8c66dc | 2010-07-22 00:40:58 +0200 | [diff] [blame] | 2014 | *bpp = 24; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 2015 | return 0; |
| 2016 | } else if (strcmp(mode_str, "ntsc") == 0) { |
| 2017 | *timings = omap_dss_ntsc_timings; |
Maurus Cuelenaere | e8c66dc | 2010-07-22 00:40:58 +0200 | [diff] [blame] | 2018 | *bpp = 24; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 2019 | return 0; |
| 2020 | } |
| 2021 | #endif |
| 2022 | |
| 2023 | /* this is quite a hack, but I wanted to use the modedb and for |
| 2024 | * that we need fb_info and var, so we create dummy ones */ |
| 2025 | |
Tomi Valkeinen | 897044e | 2011-04-30 15:26:40 +0300 | [diff] [blame] | 2026 | *bpp = 0; |
| 2027 | fbi = NULL; |
| 2028 | var = NULL; |
| 2029 | fbops = NULL; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 2030 | |
Tomi Valkeinen | 897044e | 2011-04-30 15:26:40 +0300 | [diff] [blame] | 2031 | fbi = kzalloc(sizeof(*fbi), GFP_KERNEL); |
| 2032 | if (fbi == NULL) { |
| 2033 | r = -ENOMEM; |
| 2034 | goto err; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 2035 | } |
Tomi Valkeinen | 897044e | 2011-04-30 15:26:40 +0300 | [diff] [blame] | 2036 | |
| 2037 | var = kzalloc(sizeof(*var), GFP_KERNEL); |
| 2038 | if (var == NULL) { |
| 2039 | r = -ENOMEM; |
| 2040 | goto err; |
| 2041 | } |
| 2042 | |
| 2043 | fbops = kzalloc(sizeof(*fbops), GFP_KERNEL); |
| 2044 | if (fbops == NULL) { |
| 2045 | r = -ENOMEM; |
| 2046 | goto err; |
| 2047 | } |
| 2048 | |
| 2049 | fbi->fbops = fbops; |
| 2050 | |
| 2051 | r = fb_find_mode(var, fbi, mode_str, NULL, 0, NULL, 24); |
| 2052 | if (r == 0) { |
| 2053 | r = -EINVAL; |
| 2054 | goto err; |
| 2055 | } |
| 2056 | |
Archit Taneja | 783babf | 2012-06-15 07:39:47 +0530 | [diff] [blame] | 2057 | if (display->driver->get_timings) { |
| 2058 | display->driver->get_timings(display, timings); |
| 2059 | } else { |
| 2060 | timings->data_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE; |
| 2061 | timings->de_level = OMAPDSS_SIG_ACTIVE_HIGH; |
| 2062 | timings->sync_pclk_edge = OMAPDSS_DRIVE_SIG_OPPOSITE_EDGES; |
| 2063 | } |
| 2064 | |
Tomi Valkeinen | 897044e | 2011-04-30 15:26:40 +0300 | [diff] [blame] | 2065 | timings->pixel_clock = PICOS2KHZ(var->pixclock); |
| 2066 | timings->hbp = var->left_margin; |
| 2067 | timings->hfp = var->right_margin; |
| 2068 | timings->vbp = var->upper_margin; |
| 2069 | timings->vfp = var->lower_margin; |
| 2070 | timings->hsw = var->hsync_len; |
| 2071 | timings->vsw = var->vsync_len; |
| 2072 | timings->x_res = var->xres; |
| 2073 | timings->y_res = var->yres; |
Archit Taneja | 783babf | 2012-06-15 07:39:47 +0530 | [diff] [blame] | 2074 | timings->hsync_level = var->sync & FB_SYNC_HOR_HIGH_ACT ? |
| 2075 | OMAPDSS_SIG_ACTIVE_HIGH : |
| 2076 | OMAPDSS_SIG_ACTIVE_LOW; |
| 2077 | timings->vsync_level = var->sync & FB_SYNC_VERT_HIGH_ACT ? |
| 2078 | OMAPDSS_SIG_ACTIVE_HIGH : |
| 2079 | OMAPDSS_SIG_ACTIVE_LOW; |
Archit Taneja | 23bae3a | 2012-06-28 18:23:18 +0530 | [diff] [blame] | 2080 | timings->interlace = var->vmode & FB_VMODE_INTERLACED; |
Tomi Valkeinen | 897044e | 2011-04-30 15:26:40 +0300 | [diff] [blame] | 2081 | |
| 2082 | switch (var->bits_per_pixel) { |
| 2083 | case 16: |
| 2084 | *bpp = 16; |
| 2085 | break; |
| 2086 | case 24: |
| 2087 | case 32: |
| 2088 | default: |
| 2089 | *bpp = 24; |
| 2090 | break; |
| 2091 | } |
| 2092 | |
| 2093 | r = 0; |
| 2094 | |
| 2095 | err: |
| 2096 | kfree(fbi); |
| 2097 | kfree(var); |
| 2098 | kfree(fbops); |
| 2099 | |
| 2100 | return r; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 2101 | } |
| 2102 | |
Tomi Valkeinen | a269950 | 2010-01-11 14:33:40 +0200 | [diff] [blame] | 2103 | static int omapfb_set_def_mode(struct omapfb2_device *fbdev, |
| 2104 | struct omap_dss_device *display, char *mode_str) |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 2105 | { |
| 2106 | int r; |
| 2107 | u8 bpp; |
Janorkar, Mayuresh | 371e208 | 2011-02-22 07:35:13 -0600 | [diff] [blame] | 2108 | struct omap_video_timings timings, temp_timings; |
Tomi Valkeinen | 065a40b | 2011-04-30 12:13:14 +0300 | [diff] [blame] | 2109 | struct omapfb_display_data *d; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 2110 | |
Archit Taneja | 783babf | 2012-06-15 07:39:47 +0530 | [diff] [blame] | 2111 | r = omapfb_mode_to_timings(mode_str, display, &timings, &bpp); |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 2112 | if (r) |
| 2113 | return r; |
| 2114 | |
Tomi Valkeinen | 065a40b | 2011-04-30 12:13:14 +0300 | [diff] [blame] | 2115 | d = get_display_data(fbdev, display); |
| 2116 | d->bpp_override = bpp; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 2117 | |
Janorkar, Mayuresh | 371e208 | 2011-02-22 07:35:13 -0600 | [diff] [blame] | 2118 | if (display->driver->check_timings) { |
| 2119 | r = display->driver->check_timings(display, &timings); |
| 2120 | if (r) |
| 2121 | return r; |
| 2122 | } else { |
| 2123 | /* If check_timings is not present compare xres and yres */ |
| 2124 | if (display->driver->get_timings) { |
| 2125 | display->driver->get_timings(display, &temp_timings); |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 2126 | |
Janorkar, Mayuresh | 371e208 | 2011-02-22 07:35:13 -0600 | [diff] [blame] | 2127 | if (temp_timings.x_res != timings.x_res || |
| 2128 | temp_timings.y_res != timings.y_res) |
| 2129 | return -EINVAL; |
| 2130 | } |
| 2131 | } |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 2132 | |
Janorkar, Mayuresh | 371e208 | 2011-02-22 07:35:13 -0600 | [diff] [blame] | 2133 | if (display->driver->set_timings) |
| 2134 | display->driver->set_timings(display, &timings); |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 2135 | |
| 2136 | return 0; |
| 2137 | } |
| 2138 | |
Tomi Valkeinen | a269950 | 2010-01-11 14:33:40 +0200 | [diff] [blame] | 2139 | static int omapfb_get_recommended_bpp(struct omapfb2_device *fbdev, |
| 2140 | struct omap_dss_device *dssdev) |
| 2141 | { |
Tomi Valkeinen | 065a40b | 2011-04-30 12:13:14 +0300 | [diff] [blame] | 2142 | struct omapfb_display_data *d; |
Tomi Valkeinen | a269950 | 2010-01-11 14:33:40 +0200 | [diff] [blame] | 2143 | |
| 2144 | BUG_ON(dssdev->driver->get_recommended_bpp == NULL); |
| 2145 | |
Tomi Valkeinen | 065a40b | 2011-04-30 12:13:14 +0300 | [diff] [blame] | 2146 | d = get_display_data(fbdev, dssdev); |
| 2147 | |
| 2148 | if (d->bpp_override != 0) |
| 2149 | return d->bpp_override; |
Tomi Valkeinen | a269950 | 2010-01-11 14:33:40 +0200 | [diff] [blame] | 2150 | |
| 2151 | return dssdev->driver->get_recommended_bpp(dssdev); |
| 2152 | } |
| 2153 | |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 2154 | static int omapfb_parse_def_modes(struct omapfb2_device *fbdev) |
| 2155 | { |
| 2156 | char *str, *options, *this_opt; |
| 2157 | int r = 0; |
| 2158 | |
Samreen | 36e8c27 | 2010-11-16 12:49:07 +0100 | [diff] [blame] | 2159 | str = kstrdup(def_mode, GFP_KERNEL); |
| 2160 | if (!str) |
| 2161 | return -ENOMEM; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 2162 | options = str; |
| 2163 | |
| 2164 | while (!r && (this_opt = strsep(&options, ",")) != NULL) { |
| 2165 | char *p, *display_str, *mode_str; |
| 2166 | struct omap_dss_device *display; |
| 2167 | int i; |
| 2168 | |
| 2169 | p = strchr(this_opt, ':'); |
| 2170 | if (!p) { |
| 2171 | r = -EINVAL; |
| 2172 | break; |
| 2173 | } |
| 2174 | |
| 2175 | *p = 0; |
| 2176 | display_str = this_opt; |
| 2177 | mode_str = p + 1; |
| 2178 | |
| 2179 | display = NULL; |
| 2180 | for (i = 0; i < fbdev->num_displays; ++i) { |
Tomi Valkeinen | 065a40b | 2011-04-30 12:13:14 +0300 | [diff] [blame] | 2181 | if (strcmp(fbdev->displays[i].dssdev->name, |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 2182 | display_str) == 0) { |
Tomi Valkeinen | 065a40b | 2011-04-30 12:13:14 +0300 | [diff] [blame] | 2183 | display = fbdev->displays[i].dssdev; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 2184 | break; |
| 2185 | } |
| 2186 | } |
| 2187 | |
| 2188 | if (!display) { |
| 2189 | r = -EINVAL; |
| 2190 | break; |
| 2191 | } |
| 2192 | |
Tomi Valkeinen | a269950 | 2010-01-11 14:33:40 +0200 | [diff] [blame] | 2193 | r = omapfb_set_def_mode(fbdev, display, mode_str); |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 2194 | if (r) |
| 2195 | break; |
| 2196 | } |
| 2197 | |
| 2198 | kfree(str); |
| 2199 | |
| 2200 | return r; |
| 2201 | } |
| 2202 | |
Tomi Valkeinen | dc891fa | 2011-08-25 17:15:14 +0300 | [diff] [blame] | 2203 | static void fb_videomode_to_omap_timings(struct fb_videomode *m, |
Archit Taneja | 783babf | 2012-06-15 07:39:47 +0530 | [diff] [blame] | 2204 | struct omap_dss_device *display, |
Tomi Valkeinen | dc891fa | 2011-08-25 17:15:14 +0300 | [diff] [blame] | 2205 | struct omap_video_timings *t) |
| 2206 | { |
Archit Taneja | 783babf | 2012-06-15 07:39:47 +0530 | [diff] [blame] | 2207 | if (display->driver->get_timings) { |
| 2208 | display->driver->get_timings(display, t); |
| 2209 | } else { |
| 2210 | t->data_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE; |
| 2211 | t->de_level = OMAPDSS_SIG_ACTIVE_HIGH; |
| 2212 | t->sync_pclk_edge = OMAPDSS_DRIVE_SIG_OPPOSITE_EDGES; |
| 2213 | } |
| 2214 | |
Tomi Valkeinen | dc891fa | 2011-08-25 17:15:14 +0300 | [diff] [blame] | 2215 | t->x_res = m->xres; |
| 2216 | t->y_res = m->yres; |
| 2217 | t->pixel_clock = PICOS2KHZ(m->pixclock); |
| 2218 | t->hsw = m->hsync_len; |
| 2219 | t->hfp = m->right_margin; |
| 2220 | t->hbp = m->left_margin; |
| 2221 | t->vsw = m->vsync_len; |
| 2222 | t->vfp = m->lower_margin; |
| 2223 | t->vbp = m->upper_margin; |
Archit Taneja | 783babf | 2012-06-15 07:39:47 +0530 | [diff] [blame] | 2224 | t->hsync_level = m->sync & FB_SYNC_HOR_HIGH_ACT ? |
| 2225 | OMAPDSS_SIG_ACTIVE_HIGH : |
| 2226 | OMAPDSS_SIG_ACTIVE_LOW; |
| 2227 | t->vsync_level = m->sync & FB_SYNC_VERT_HIGH_ACT ? |
| 2228 | OMAPDSS_SIG_ACTIVE_HIGH : |
| 2229 | OMAPDSS_SIG_ACTIVE_LOW; |
Archit Taneja | 23bae3a | 2012-06-28 18:23:18 +0530 | [diff] [blame] | 2230 | t->interlace = m->vmode & FB_VMODE_INTERLACED; |
Tomi Valkeinen | dc891fa | 2011-08-25 17:15:14 +0300 | [diff] [blame] | 2231 | } |
| 2232 | |
| 2233 | static int omapfb_find_best_mode(struct omap_dss_device *display, |
| 2234 | struct omap_video_timings *timings) |
| 2235 | { |
| 2236 | struct fb_monspecs *specs; |
| 2237 | u8 *edid; |
Tomi Valkeinen | 5e18e35 | 2012-10-12 15:44:29 +0300 | [diff] [blame] | 2238 | int r, i, best_idx, len; |
Tomi Valkeinen | dc891fa | 2011-08-25 17:15:14 +0300 | [diff] [blame] | 2239 | |
| 2240 | if (!display->driver->read_edid) |
| 2241 | return -ENODEV; |
| 2242 | |
| 2243 | len = 0x80 * 2; |
| 2244 | edid = kmalloc(len, GFP_KERNEL); |
| 2245 | |
| 2246 | r = display->driver->read_edid(display, edid, len); |
| 2247 | if (r < 0) |
| 2248 | goto err1; |
| 2249 | |
| 2250 | specs = kzalloc(sizeof(*specs), GFP_KERNEL); |
| 2251 | |
| 2252 | fb_edid_to_monspecs(edid, specs); |
| 2253 | |
Tomi Valkeinen | dc891fa | 2011-08-25 17:15:14 +0300 | [diff] [blame] | 2254 | best_idx = -1; |
| 2255 | |
| 2256 | for (i = 0; i < specs->modedb_len; ++i) { |
| 2257 | struct fb_videomode *m; |
| 2258 | struct omap_video_timings t; |
| 2259 | |
| 2260 | m = &specs->modedb[i]; |
| 2261 | |
| 2262 | if (m->pixclock == 0) |
| 2263 | continue; |
| 2264 | |
| 2265 | /* skip repeated pixel modes */ |
| 2266 | if (m->xres == 2880 || m->xres == 1440) |
| 2267 | continue; |
| 2268 | |
Tomi Valkeinen | 5e18e35 | 2012-10-12 15:44:29 +0300 | [diff] [blame] | 2269 | if (m->vmode & FB_VMODE_INTERLACED || |
| 2270 | m->vmode & FB_VMODE_DOUBLE) |
| 2271 | continue; |
| 2272 | |
Archit Taneja | 783babf | 2012-06-15 07:39:47 +0530 | [diff] [blame] | 2273 | fb_videomode_to_omap_timings(m, display, &t); |
Tomi Valkeinen | dc891fa | 2011-08-25 17:15:14 +0300 | [diff] [blame] | 2274 | |
| 2275 | r = display->driver->check_timings(display, &t); |
Tomi Valkeinen | 5e18e35 | 2012-10-12 15:44:29 +0300 | [diff] [blame] | 2276 | if (r == 0) { |
Tomi Valkeinen | dc891fa | 2011-08-25 17:15:14 +0300 | [diff] [blame] | 2277 | best_idx = i; |
Tomi Valkeinen | 5e18e35 | 2012-10-12 15:44:29 +0300 | [diff] [blame] | 2278 | break; |
Tomi Valkeinen | dc891fa | 2011-08-25 17:15:14 +0300 | [diff] [blame] | 2279 | } |
| 2280 | } |
| 2281 | |
Tomi Valkeinen | 5e18e35 | 2012-10-12 15:44:29 +0300 | [diff] [blame] | 2282 | if (best_idx == -1) { |
Tomi Valkeinen | dc891fa | 2011-08-25 17:15:14 +0300 | [diff] [blame] | 2283 | r = -ENOENT; |
| 2284 | goto err2; |
| 2285 | } |
| 2286 | |
Archit Taneja | 783babf | 2012-06-15 07:39:47 +0530 | [diff] [blame] | 2287 | fb_videomode_to_omap_timings(&specs->modedb[best_idx], display, |
| 2288 | timings); |
Tomi Valkeinen | dc891fa | 2011-08-25 17:15:14 +0300 | [diff] [blame] | 2289 | |
| 2290 | r = 0; |
| 2291 | |
| 2292 | err2: |
| 2293 | fb_destroy_modedb(specs->modedb); |
| 2294 | kfree(specs); |
| 2295 | err1: |
| 2296 | kfree(edid); |
| 2297 | |
| 2298 | return r; |
| 2299 | } |
| 2300 | |
Tomi Valkeinen | 91ac27a | 2010-09-23 11:18:44 +0300 | [diff] [blame] | 2301 | static int omapfb_init_display(struct omapfb2_device *fbdev, |
| 2302 | struct omap_dss_device *dssdev) |
| 2303 | { |
| 2304 | struct omap_dss_driver *dssdrv = dssdev->driver; |
Tomi Valkeinen | 27cc213 | 2011-04-30 16:55:12 +0300 | [diff] [blame] | 2305 | struct omapfb_display_data *d; |
Tomi Valkeinen | 91ac27a | 2010-09-23 11:18:44 +0300 | [diff] [blame] | 2306 | int r; |
| 2307 | |
| 2308 | r = dssdrv->enable(dssdev); |
| 2309 | if (r) { |
| 2310 | dev_warn(fbdev->dev, "Failed to enable display '%s'\n", |
| 2311 | dssdev->name); |
| 2312 | return r; |
| 2313 | } |
| 2314 | |
Tomi Valkeinen | 27cc213 | 2011-04-30 16:55:12 +0300 | [diff] [blame] | 2315 | d = get_display_data(fbdev, dssdev); |
| 2316 | |
| 2317 | d->fbdev = fbdev; |
| 2318 | |
Tomi Valkeinen | 91ac27a | 2010-09-23 11:18:44 +0300 | [diff] [blame] | 2319 | if (dssdev->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE) { |
| 2320 | u16 w, h; |
Tomi Valkeinen | 27cc213 | 2011-04-30 16:55:12 +0300 | [diff] [blame] | 2321 | |
| 2322 | if (auto_update) { |
| 2323 | omapfb_start_auto_update(fbdev, dssdev); |
| 2324 | d->update_mode = OMAPFB_AUTO_UPDATE; |
| 2325 | } else { |
| 2326 | d->update_mode = OMAPFB_MANUAL_UPDATE; |
| 2327 | } |
| 2328 | |
Tomi Valkeinen | 91ac27a | 2010-09-23 11:18:44 +0300 | [diff] [blame] | 2329 | if (dssdrv->enable_te) { |
| 2330 | r = dssdrv->enable_te(dssdev, 1); |
| 2331 | if (r) { |
| 2332 | dev_err(fbdev->dev, "Failed to set TE\n"); |
| 2333 | return r; |
| 2334 | } |
| 2335 | } |
| 2336 | |
Tomi Valkeinen | 91ac27a | 2010-09-23 11:18:44 +0300 | [diff] [blame] | 2337 | dssdrv->get_resolution(dssdev, &w, &h); |
| 2338 | r = dssdrv->update(dssdev, 0, 0, w, h); |
| 2339 | if (r) { |
| 2340 | dev_err(fbdev->dev, |
| 2341 | "Failed to update display\n"); |
| 2342 | return r; |
| 2343 | } |
| 2344 | } else { |
Tomi Valkeinen | 27cc213 | 2011-04-30 16:55:12 +0300 | [diff] [blame] | 2345 | d->update_mode = OMAPFB_AUTO_UPDATE; |
Tomi Valkeinen | 91ac27a | 2010-09-23 11:18:44 +0300 | [diff] [blame] | 2346 | } |
| 2347 | |
| 2348 | return 0; |
| 2349 | } |
| 2350 | |
Tomi Valkeinen | 5d89bcc | 2012-08-06 15:27:17 +0300 | [diff] [blame] | 2351 | static int omapfb_init_connections(struct omapfb2_device *fbdev, |
Tomi Valkeinen | 6b6f1ed | 2012-12-04 13:12:39 +0200 | [diff] [blame] | 2352 | struct omap_dss_device *def_dssdev) |
Tomi Valkeinen | 5d89bcc | 2012-08-06 15:27:17 +0300 | [diff] [blame] | 2353 | { |
| 2354 | int i, r; |
Tomi Valkeinen | 6b6f1ed | 2012-12-04 13:12:39 +0200 | [diff] [blame] | 2355 | struct omap_overlay_manager *mgr; |
Tomi Valkeinen | 5d89bcc | 2012-08-06 15:27:17 +0300 | [diff] [blame] | 2356 | |
Tomi Valkeinen | 6b6f1ed | 2012-12-04 13:12:39 +0200 | [diff] [blame] | 2357 | if (!def_dssdev->output) { |
| 2358 | dev_err(fbdev->dev, "no output for the default display\n"); |
| 2359 | return -EINVAL; |
Tomi Valkeinen | 5d89bcc | 2012-08-06 15:27:17 +0300 | [diff] [blame] | 2360 | } |
| 2361 | |
Tomi Valkeinen | 6b6f1ed | 2012-12-04 13:12:39 +0200 | [diff] [blame] | 2362 | for (i = 0; i < fbdev->num_displays; ++i) { |
| 2363 | struct omap_dss_device *dssdev = fbdev->displays[i].dssdev; |
| 2364 | struct omap_dss_output *out = dssdev->output; |
Tomi Valkeinen | 5d89bcc | 2012-08-06 15:27:17 +0300 | [diff] [blame] | 2365 | |
Tomi Valkeinen | 6b6f1ed | 2012-12-04 13:12:39 +0200 | [diff] [blame] | 2366 | mgr = omap_dss_get_overlay_manager(dssdev->channel); |
Tomi Valkeinen | 5d89bcc | 2012-08-06 15:27:17 +0300 | [diff] [blame] | 2367 | |
Tomi Valkeinen | 6b6f1ed | 2012-12-04 13:12:39 +0200 | [diff] [blame] | 2368 | if (!mgr || !out) |
| 2369 | continue; |
| 2370 | |
| 2371 | if (mgr->output) |
| 2372 | mgr->unset_output(mgr); |
| 2373 | |
| 2374 | mgr->set_output(mgr, out); |
| 2375 | } |
| 2376 | |
| 2377 | mgr = def_dssdev->output->manager; |
| 2378 | |
| 2379 | if (!mgr) { |
| 2380 | dev_err(fbdev->dev, "no ovl manager for the default display\n"); |
| 2381 | return -EINVAL; |
| 2382 | } |
Tomi Valkeinen | 5d89bcc | 2012-08-06 15:27:17 +0300 | [diff] [blame] | 2383 | |
| 2384 | for (i = 0; i < fbdev->num_overlays; i++) { |
| 2385 | struct omap_overlay *ovl = fbdev->overlays[i]; |
| 2386 | |
| 2387 | if (ovl->manager) |
| 2388 | ovl->unset_manager(ovl); |
| 2389 | |
| 2390 | r = ovl->set_manager(ovl, mgr); |
| 2391 | if (r) |
| 2392 | dev_warn(fbdev->dev, |
| 2393 | "failed to connect overlay %s to manager %s\n", |
| 2394 | ovl->name, mgr->name); |
| 2395 | } |
| 2396 | |
| 2397 | return 0; |
| 2398 | } |
| 2399 | |
Tomi Valkeinen | d64f14e | 2012-02-17 17:43:03 +0200 | [diff] [blame] | 2400 | static int __init omapfb_probe(struct platform_device *pdev) |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 2401 | { |
| 2402 | struct omapfb2_device *fbdev = NULL; |
| 2403 | int r = 0; |
| 2404 | int i; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 2405 | struct omap_dss_device *def_display; |
| 2406 | struct omap_dss_device *dssdev; |
| 2407 | |
| 2408 | DBG("omapfb_probe\n"); |
| 2409 | |
| 2410 | if (pdev->num_resources != 0) { |
| 2411 | dev_err(&pdev->dev, "probed for an unknown device\n"); |
| 2412 | r = -ENODEV; |
| 2413 | goto err0; |
| 2414 | } |
| 2415 | |
| 2416 | fbdev = kzalloc(sizeof(struct omapfb2_device), GFP_KERNEL); |
| 2417 | if (fbdev == NULL) { |
| 2418 | r = -ENOMEM; |
| 2419 | goto err0; |
| 2420 | } |
| 2421 | |
Tomi Valkeinen | a89d1a8 | 2012-10-17 12:16:50 +0300 | [diff] [blame] | 2422 | if (def_vrfb && !omap_vrfb_supported()) { |
Senthilvadivu Guruswamy | 41814cf | 2010-10-08 08:44:33 +0200 | [diff] [blame] | 2423 | def_vrfb = 0; |
| 2424 | dev_warn(&pdev->dev, "VRFB is not supported on this hardware, " |
| 2425 | "ignoring the module parameter vrfb=y\n"); |
| 2426 | } |
| 2427 | |
| 2428 | |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 2429 | mutex_init(&fbdev->mtx); |
| 2430 | |
| 2431 | fbdev->dev = &pdev->dev; |
| 2432 | platform_set_drvdata(pdev, fbdev); |
| 2433 | |
| 2434 | fbdev->num_displays = 0; |
| 2435 | dssdev = NULL; |
| 2436 | for_each_dss_dev(dssdev) { |
Tomi Valkeinen | 27cc213 | 2011-04-30 16:55:12 +0300 | [diff] [blame] | 2437 | struct omapfb_display_data *d; |
| 2438 | |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 2439 | omap_dss_get_device(dssdev); |
Tomi Valkeinen | b3f91eb | 2010-02-17 12:00:01 +0200 | [diff] [blame] | 2440 | |
Tomi Valkeinen | 807a751 | 2010-01-07 17:45:03 +0200 | [diff] [blame] | 2441 | if (!dssdev->driver) { |
Tomi Valkeinen | bab59b4 | 2011-08-04 14:37:29 +0300 | [diff] [blame] | 2442 | dev_warn(&pdev->dev, "no driver for display: %s\n", |
Andy Doan | c5f18d7 | 2011-07-06 12:08:29 -0500 | [diff] [blame] | 2443 | dssdev->name); |
Tomi Valkeinen | bab59b4 | 2011-08-04 14:37:29 +0300 | [diff] [blame] | 2444 | omap_dss_put_device(dssdev); |
| 2445 | continue; |
Tomi Valkeinen | 807a751 | 2010-01-07 17:45:03 +0200 | [diff] [blame] | 2446 | } |
Tomi Valkeinen | b3f91eb | 2010-02-17 12:00:01 +0200 | [diff] [blame] | 2447 | |
Tomi Valkeinen | 27cc213 | 2011-04-30 16:55:12 +0300 | [diff] [blame] | 2448 | d = &fbdev->displays[fbdev->num_displays++]; |
| 2449 | d->dssdev = dssdev; |
| 2450 | if (dssdev->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE) |
| 2451 | d->update_mode = OMAPFB_MANUAL_UPDATE; |
| 2452 | else |
| 2453 | d->update_mode = OMAPFB_AUTO_UPDATE; |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 2454 | } |
| 2455 | |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 2456 | if (fbdev->num_displays == 0) { |
| 2457 | dev_err(&pdev->dev, "no displays\n"); |
| 2458 | r = -EINVAL; |
| 2459 | goto cleanup; |
| 2460 | } |
| 2461 | |
| 2462 | fbdev->num_overlays = omap_dss_get_num_overlays(); |
| 2463 | for (i = 0; i < fbdev->num_overlays; i++) |
| 2464 | fbdev->overlays[i] = omap_dss_get_overlay(i); |
| 2465 | |
| 2466 | fbdev->num_managers = omap_dss_get_num_overlay_managers(); |
| 2467 | for (i = 0; i < fbdev->num_managers; i++) |
| 2468 | fbdev->managers[i] = omap_dss_get_overlay_manager(i); |
| 2469 | |
Tomi Valkeinen | 5d89bcc | 2012-08-06 15:27:17 +0300 | [diff] [blame] | 2470 | def_display = NULL; |
| 2471 | |
| 2472 | for (i = 0; i < fbdev->num_displays; ++i) { |
| 2473 | struct omap_dss_device *dssdev; |
| 2474 | const char *def_name; |
| 2475 | |
| 2476 | def_name = omapdss_get_default_display_name(); |
| 2477 | |
| 2478 | dssdev = fbdev->displays[i].dssdev; |
| 2479 | |
| 2480 | if (def_name == NULL || |
| 2481 | (dssdev->name && strcmp(def_name, dssdev->name) == 0)) { |
| 2482 | def_display = dssdev; |
| 2483 | break; |
| 2484 | } |
| 2485 | } |
| 2486 | |
| 2487 | if (def_display == NULL) { |
| 2488 | dev_err(fbdev->dev, "failed to find default display\n"); |
| 2489 | r = -EINVAL; |
| 2490 | goto cleanup; |
| 2491 | } |
| 2492 | |
| 2493 | r = omapfb_init_connections(fbdev, def_display); |
| 2494 | if (r) { |
| 2495 | dev_err(fbdev->dev, "failed to init overlay connections\n"); |
| 2496 | goto cleanup; |
Tomi Valkeinen | dc891fa | 2011-08-25 17:15:14 +0300 | [diff] [blame] | 2497 | } |
| 2498 | |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 2499 | if (def_mode && strlen(def_mode) > 0) { |
| 2500 | if (omapfb_parse_def_modes(fbdev)) |
| 2501 | dev_warn(&pdev->dev, "cannot parse default modes\n"); |
Tomi Valkeinen | dc891fa | 2011-08-25 17:15:14 +0300 | [diff] [blame] | 2502 | } else if (def_display && def_display->driver->set_timings && |
| 2503 | def_display->driver->check_timings) { |
| 2504 | struct omap_video_timings t; |
| 2505 | |
| 2506 | r = omapfb_find_best_mode(def_display, &t); |
| 2507 | |
| 2508 | if (r == 0) |
| 2509 | def_display->driver->set_timings(def_display, &t); |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 2510 | } |
| 2511 | |
| 2512 | r = omapfb_create_framebuffers(fbdev); |
| 2513 | if (r) |
| 2514 | goto cleanup; |
| 2515 | |
| 2516 | for (i = 0; i < fbdev->num_managers; i++) { |
| 2517 | struct omap_overlay_manager *mgr; |
| 2518 | mgr = fbdev->managers[i]; |
| 2519 | r = mgr->apply(mgr); |
| 2520 | if (r) |
| 2521 | dev_warn(fbdev->dev, "failed to apply dispc config\n"); |
| 2522 | } |
| 2523 | |
| 2524 | DBG("mgr->apply'ed\n"); |
| 2525 | |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 2526 | if (def_display) { |
Tomi Valkeinen | 91ac27a | 2010-09-23 11:18:44 +0300 | [diff] [blame] | 2527 | r = omapfb_init_display(fbdev, def_display); |
Tomi Valkeinen | 6d2e0bd | 2010-02-17 13:38:08 +0200 | [diff] [blame] | 2528 | if (r) { |
Tomi Valkeinen | 91ac27a | 2010-09-23 11:18:44 +0300 | [diff] [blame] | 2529 | dev_err(fbdev->dev, |
| 2530 | "failed to initialize default " |
| 2531 | "display\n"); |
Tomi Valkeinen | 6d2e0bd | 2010-02-17 13:38:08 +0200 | [diff] [blame] | 2532 | goto cleanup; |
| 2533 | } |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 2534 | } |
| 2535 | |
Afzal Mohammed | e26ed44 | 2010-07-01 15:40:01 +0200 | [diff] [blame] | 2536 | DBG("create sysfs for fbs\n"); |
| 2537 | r = omapfb_create_sysfs(fbdev); |
| 2538 | if (r) { |
| 2539 | dev_err(fbdev->dev, "failed to create sysfs entries\n"); |
| 2540 | goto cleanup; |
| 2541 | } |
| 2542 | |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 2543 | return 0; |
| 2544 | |
| 2545 | cleanup: |
| 2546 | omapfb_free_resources(fbdev); |
| 2547 | err0: |
| 2548 | dev_err(&pdev->dev, "failed to setup omapfb\n"); |
| 2549 | return r; |
| 2550 | } |
| 2551 | |
Tomi Valkeinen | d64f14e | 2012-02-17 17:43:03 +0200 | [diff] [blame] | 2552 | static int __exit omapfb_remove(struct platform_device *pdev) |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 2553 | { |
| 2554 | struct omapfb2_device *fbdev = platform_get_drvdata(pdev); |
| 2555 | |
| 2556 | /* FIXME: wait till completion of pending events */ |
| 2557 | |
| 2558 | omapfb_remove_sysfs(fbdev); |
| 2559 | |
| 2560 | omapfb_free_resources(fbdev); |
| 2561 | |
| 2562 | return 0; |
| 2563 | } |
| 2564 | |
| 2565 | static struct platform_driver omapfb_driver = { |
Tomi Valkeinen | d64f14e | 2012-02-17 17:43:03 +0200 | [diff] [blame] | 2566 | .remove = __exit_p(omapfb_remove), |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 2567 | .driver = { |
| 2568 | .name = "omapfb", |
| 2569 | .owner = THIS_MODULE, |
| 2570 | }, |
| 2571 | }; |
| 2572 | |
| 2573 | static int __init omapfb_init(void) |
| 2574 | { |
| 2575 | DBG("omapfb_init\n"); |
| 2576 | |
Tomi Valkeinen | d64f14e | 2012-02-17 17:43:03 +0200 | [diff] [blame] | 2577 | if (platform_driver_probe(&omapfb_driver, omapfb_probe)) { |
Tomi Valkeinen | b39a982d | 2009-08-04 16:12:50 +0300 | [diff] [blame] | 2578 | printk(KERN_ERR "failed to register omapfb driver\n"); |
| 2579 | return -ENODEV; |
| 2580 | } |
| 2581 | |
| 2582 | return 0; |
| 2583 | } |
| 2584 | |
| 2585 | static void __exit omapfb_exit(void) |
| 2586 | { |
| 2587 | DBG("omapfb_exit\n"); |
| 2588 | platform_driver_unregister(&omapfb_driver); |
| 2589 | } |
| 2590 | |
| 2591 | module_param_named(mode, def_mode, charp, 0); |
| 2592 | module_param_named(vram, def_vram, charp, 0); |
| 2593 | module_param_named(rotate, def_rotate, int, 0); |
| 2594 | module_param_named(vrfb, def_vrfb, bool, 0); |
| 2595 | module_param_named(mirror, def_mirror, bool, 0); |
| 2596 | |
| 2597 | /* late_initcall to let panel/ctrl drivers loaded first. |
| 2598 | * I guess better option would be a more dynamic approach, |
| 2599 | * so that omapfb reacts to new panels when they are loaded */ |
| 2600 | late_initcall(omapfb_init); |
| 2601 | /*module_init(omapfb_init);*/ |
| 2602 | module_exit(omapfb_exit); |
| 2603 | |
| 2604 | MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>"); |
| 2605 | MODULE_DESCRIPTION("OMAP2/3 Framebuffer"); |
| 2606 | MODULE_LICENSE("GPL v2"); |