Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Framebuffer driver for TI OMAP boards |
| 3 | * |
| 4 | * Copyright (C) 2004 Nokia Corporation |
| 5 | * Author: Imre Deak <imre.deak@nokia.com> |
| 6 | * |
| 7 | * Acknowledgements: |
| 8 | * Alex McMains <aam@ridgerun.com> - Original driver |
| 9 | * Juha Yrjola <juha.yrjola@nokia.com> - Original driver and improvements |
| 10 | * Dirk Behme <dirk.behme@de.bosch.com> - changes for 2.6 kernel API |
| 11 | * Texas Instruments - H3 support |
| 12 | * |
| 13 | * This program is free software; you can redistribute it and/or modify it |
| 14 | * under the terms of the GNU General Public License as published by the |
| 15 | * Free Software Foundation; either version 2 of the License, or (at your |
| 16 | * option) any later version. |
| 17 | * |
| 18 | * This program is distributed in the hope that it will be useful, but |
| 19 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 21 | * General Public License for more details. |
| 22 | * |
| 23 | * You should have received a copy of the GNU General Public License along |
| 24 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 25 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 26 | */ |
| 27 | #include <linux/platform_device.h> |
Andrea Righi | 27ac792 | 2008-07-23 21:28:13 -0700 | [diff] [blame] | 28 | #include <linux/mm.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 29 | #include <linux/slab.h> |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 30 | #include <linux/uaccess.h> |
Paul Gortmaker | 355b200 | 2011-07-03 16:17:28 -0400 | [diff] [blame] | 31 | #include <linux/module.h> |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 32 | |
Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 33 | #include <plat/dma.h> |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 34 | |
Tomi Valkeinen | 91773a0 | 2009-08-03 15:06:36 +0300 | [diff] [blame] | 35 | #include "omapfb.h" |
Russell King | 7c8ad98 | 2008-09-05 15:13:24 +0100 | [diff] [blame] | 36 | #include "lcdc.h" |
Russell King | 7c8ad98 | 2008-09-05 15:13:24 +0100 | [diff] [blame] | 37 | |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 38 | #define MODULE_NAME "omapfb" |
| 39 | |
| 40 | static unsigned int def_accel; |
| 41 | static unsigned long def_vram[OMAPFB_PLANE_NUM]; |
Russell King | 7c8ad98 | 2008-09-05 15:13:24 +0100 | [diff] [blame] | 42 | static unsigned int def_vram_cnt; |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 43 | static unsigned long def_vxres; |
| 44 | static unsigned long def_vyres; |
| 45 | static unsigned int def_rotate; |
| 46 | static unsigned int def_mirror; |
| 47 | |
| 48 | #ifdef CONFIG_FB_OMAP_MANUAL_UPDATE |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 49 | static bool manual_update = 1; |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 50 | #else |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 51 | static bool manual_update; |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 52 | #endif |
| 53 | |
| 54 | static struct platform_device *fbdev_pdev; |
| 55 | static struct lcd_panel *fbdev_panel; |
| 56 | static struct omapfb_device *omapfb_dev; |
| 57 | |
| 58 | struct caps_table_struct { |
| 59 | unsigned long flag; |
| 60 | const char *name; |
| 61 | }; |
| 62 | |
| 63 | static struct caps_table_struct ctrl_caps[] = { |
| 64 | { OMAPFB_CAPS_MANUAL_UPDATE, "manual update" }, |
| 65 | { OMAPFB_CAPS_TEARSYNC, "tearing synchronization" }, |
| 66 | { OMAPFB_CAPS_PLANE_RELOCATE_MEM, "relocate plane memory" }, |
| 67 | { OMAPFB_CAPS_PLANE_SCALE, "scale plane" }, |
| 68 | { OMAPFB_CAPS_WINDOW_PIXEL_DOUBLE, "pixel double window" }, |
| 69 | { OMAPFB_CAPS_WINDOW_SCALE, "scale window" }, |
| 70 | { OMAPFB_CAPS_WINDOW_OVERLAY, "overlay window" }, |
Rodrigo Vivi | 2f21a62 | 2009-09-22 16:46:53 -0700 | [diff] [blame] | 71 | { OMAPFB_CAPS_WINDOW_ROTATE, "rotate window" }, |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 72 | { OMAPFB_CAPS_SET_BACKLIGHT, "backlight setting" }, |
| 73 | }; |
| 74 | |
| 75 | static struct caps_table_struct color_caps[] = { |
| 76 | { 1 << OMAPFB_COLOR_RGB565, "RGB565", }, |
| 77 | { 1 << OMAPFB_COLOR_YUV422, "YUV422", }, |
| 78 | { 1 << OMAPFB_COLOR_YUV420, "YUV420", }, |
| 79 | { 1 << OMAPFB_COLOR_CLUT_8BPP, "CLUT8", }, |
| 80 | { 1 << OMAPFB_COLOR_CLUT_4BPP, "CLUT4", }, |
| 81 | { 1 << OMAPFB_COLOR_CLUT_2BPP, "CLUT2", }, |
| 82 | { 1 << OMAPFB_COLOR_CLUT_1BPP, "CLUT1", }, |
| 83 | { 1 << OMAPFB_COLOR_RGB444, "RGB444", }, |
| 84 | { 1 << OMAPFB_COLOR_YUY422, "YUY422", }, |
| 85 | }; |
| 86 | |
Tomi Valkeinen | b64a5a1 | 2010-01-07 11:56:14 +0200 | [diff] [blame] | 87 | static void omapdss_release(struct device *dev) |
| 88 | { |
| 89 | } |
| 90 | |
Tomi Valkeinen | f778a12 | 2009-12-16 13:18:07 +0200 | [diff] [blame] | 91 | /* dummy device for clocks */ |
| 92 | static struct platform_device omapdss_device = { |
Tomi Valkeinen | c96c92d | 2011-04-21 19:11:16 +0300 | [diff] [blame] | 93 | .name = "omapdss_dss", |
Tomi Valkeinen | f778a12 | 2009-12-16 13:18:07 +0200 | [diff] [blame] | 94 | .id = -1, |
Tomi Valkeinen | b64a5a1 | 2010-01-07 11:56:14 +0200 | [diff] [blame] | 95 | .dev = { |
| 96 | .release = omapdss_release, |
| 97 | }, |
Tomi Valkeinen | f778a12 | 2009-12-16 13:18:07 +0200 | [diff] [blame] | 98 | }; |
| 99 | |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 100 | /* |
| 101 | * --------------------------------------------------------------------------- |
| 102 | * LCD panel |
| 103 | * --------------------------------------------------------------------------- |
| 104 | */ |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 105 | extern struct lcd_ctrl hwa742_ctrl; |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 106 | |
Russell King | 7c8ad98 | 2008-09-05 15:13:24 +0100 | [diff] [blame] | 107 | static const struct lcd_ctrl *ctrls[] = { |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 108 | &omap1_int_ctrl, |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 109 | |
| 110 | #ifdef CONFIG_FB_OMAP_LCDC_HWA742 |
| 111 | &hwa742_ctrl, |
| 112 | #endif |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 113 | }; |
| 114 | |
| 115 | #ifdef CONFIG_FB_OMAP_LCDC_EXTERNAL |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 116 | extern struct lcd_ctrl_extif omap1_ext_if; |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 117 | #endif |
| 118 | |
| 119 | static void omapfb_rqueue_lock(struct omapfb_device *fbdev) |
| 120 | { |
| 121 | mutex_lock(&fbdev->rqueue_mutex); |
| 122 | } |
| 123 | |
| 124 | static void omapfb_rqueue_unlock(struct omapfb_device *fbdev) |
| 125 | { |
| 126 | mutex_unlock(&fbdev->rqueue_mutex); |
| 127 | } |
| 128 | |
| 129 | /* |
| 130 | * --------------------------------------------------------------------------- |
| 131 | * LCD controller and LCD DMA |
| 132 | * --------------------------------------------------------------------------- |
| 133 | */ |
| 134 | /* Lookup table to map elem size to elem type. */ |
| 135 | static const int dma_elem_type[] = { |
| 136 | 0, |
| 137 | OMAP_DMA_DATA_TYPE_S8, |
| 138 | OMAP_DMA_DATA_TYPE_S16, |
| 139 | 0, |
| 140 | OMAP_DMA_DATA_TYPE_S32, |
| 141 | }; |
| 142 | |
| 143 | /* |
| 144 | * Allocate resources needed for LCD controller and LCD DMA operations. Video |
| 145 | * memory is allocated from system memory according to the virtual display |
| 146 | * size, except if a bigger memory size is specified explicitly as a kernel |
| 147 | * parameter. |
| 148 | */ |
| 149 | static int ctrl_init(struct omapfb_device *fbdev) |
| 150 | { |
| 151 | int r; |
| 152 | int i; |
| 153 | |
| 154 | /* kernel/module vram parameters override boot tags/board config */ |
| 155 | if (def_vram_cnt) { |
| 156 | for (i = 0; i < def_vram_cnt; i++) |
| 157 | fbdev->mem_desc.region[i].size = |
| 158 | PAGE_ALIGN(def_vram[i]); |
| 159 | fbdev->mem_desc.region_cnt = i; |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | if (!fbdev->mem_desc.region_cnt) { |
| 163 | struct lcd_panel *panel = fbdev->panel; |
| 164 | int def_size; |
| 165 | int bpp = panel->bpp; |
| 166 | |
| 167 | /* 12 bpp is packed in 16 bits */ |
| 168 | if (bpp == 12) |
| 169 | bpp = 16; |
| 170 | def_size = def_vxres * def_vyres * bpp / 8; |
| 171 | fbdev->mem_desc.region_cnt = 1; |
| 172 | fbdev->mem_desc.region[0].size = PAGE_ALIGN(def_size); |
| 173 | } |
| 174 | r = fbdev->ctrl->init(fbdev, 0, &fbdev->mem_desc); |
| 175 | if (r < 0) { |
| 176 | dev_err(fbdev->dev, "controller initialization failed (%d)\n", |
| 177 | r); |
| 178 | return r; |
| 179 | } |
| 180 | |
| 181 | #ifdef DEBUG |
| 182 | for (i = 0; i < fbdev->mem_desc.region_cnt; i++) { |
| 183 | dev_dbg(fbdev->dev, "region%d phys %08x virt %p size=%lu\n", |
| 184 | i, |
| 185 | fbdev->mem_desc.region[i].paddr, |
| 186 | fbdev->mem_desc.region[i].vaddr, |
| 187 | fbdev->mem_desc.region[i].size); |
| 188 | } |
| 189 | #endif |
| 190 | return 0; |
| 191 | } |
| 192 | |
| 193 | static void ctrl_cleanup(struct omapfb_device *fbdev) |
| 194 | { |
| 195 | fbdev->ctrl->cleanup(); |
| 196 | } |
| 197 | |
| 198 | /* Must be called with fbdev->rqueue_mutex held. */ |
| 199 | static int ctrl_change_mode(struct fb_info *fbi) |
| 200 | { |
| 201 | int r; |
| 202 | unsigned long offset; |
| 203 | struct omapfb_plane_struct *plane = fbi->par; |
| 204 | struct omapfb_device *fbdev = plane->fbdev; |
| 205 | struct fb_var_screeninfo *var = &fbi->var; |
| 206 | |
| 207 | offset = var->yoffset * fbi->fix.line_length + |
| 208 | var->xoffset * var->bits_per_pixel / 8; |
| 209 | |
| 210 | if (fbdev->ctrl->sync) |
| 211 | fbdev->ctrl->sync(); |
| 212 | r = fbdev->ctrl->setup_plane(plane->idx, plane->info.channel_out, |
| 213 | offset, var->xres_virtual, |
| 214 | plane->info.pos_x, plane->info.pos_y, |
| 215 | var->xres, var->yres, plane->color_mode); |
Rodrigo Vivi | 2f21a62 | 2009-09-22 16:46:53 -0700 | [diff] [blame] | 216 | if (r < 0) |
| 217 | return r; |
| 218 | |
| 219 | if (fbdev->ctrl->set_rotate != NULL) { |
| 220 | r = fbdev->ctrl->set_rotate(var->rotate); |
| 221 | if (r < 0) |
| 222 | return r; |
| 223 | } |
| 224 | |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 225 | if (fbdev->ctrl->set_scale != NULL) |
| 226 | r = fbdev->ctrl->set_scale(plane->idx, |
| 227 | var->xres, var->yres, |
| 228 | plane->info.out_width, |
| 229 | plane->info.out_height); |
| 230 | |
| 231 | return r; |
| 232 | } |
| 233 | |
| 234 | /* |
| 235 | * --------------------------------------------------------------------------- |
| 236 | * fbdev framework callbacks and the ioctl interface |
| 237 | * --------------------------------------------------------------------------- |
| 238 | */ |
| 239 | /* Called each time the omapfb device is opened */ |
| 240 | static int omapfb_open(struct fb_info *info, int user) |
| 241 | { |
| 242 | return 0; |
| 243 | } |
| 244 | |
| 245 | static void omapfb_sync(struct fb_info *info); |
| 246 | |
| 247 | /* Called when the omapfb device is closed. We make sure that any pending |
| 248 | * gfx DMA operations are ended, before we return. */ |
| 249 | static int omapfb_release(struct fb_info *info, int user) |
| 250 | { |
| 251 | omapfb_sync(info); |
| 252 | return 0; |
| 253 | } |
| 254 | |
| 255 | /* Store a single color palette entry into a pseudo palette or the hardware |
| 256 | * palette if one is available. For now we support only 16bpp and thus store |
| 257 | * the entry only to the pseudo palette. |
| 258 | */ |
| 259 | static int _setcolreg(struct fb_info *info, u_int regno, u_int red, u_int green, |
| 260 | u_int blue, u_int transp, int update_hw_pal) |
| 261 | { |
| 262 | struct omapfb_plane_struct *plane = info->par; |
| 263 | struct omapfb_device *fbdev = plane->fbdev; |
| 264 | struct fb_var_screeninfo *var = &info->var; |
| 265 | int r = 0; |
| 266 | |
| 267 | switch (plane->color_mode) { |
| 268 | case OMAPFB_COLOR_YUV422: |
| 269 | case OMAPFB_COLOR_YUV420: |
| 270 | case OMAPFB_COLOR_YUY422: |
| 271 | r = -EINVAL; |
| 272 | break; |
| 273 | case OMAPFB_COLOR_CLUT_8BPP: |
| 274 | case OMAPFB_COLOR_CLUT_4BPP: |
| 275 | case OMAPFB_COLOR_CLUT_2BPP: |
| 276 | case OMAPFB_COLOR_CLUT_1BPP: |
| 277 | if (fbdev->ctrl->setcolreg) |
| 278 | r = fbdev->ctrl->setcolreg(regno, red, green, blue, |
| 279 | transp, update_hw_pal); |
| 280 | /* Fallthrough */ |
| 281 | case OMAPFB_COLOR_RGB565: |
| 282 | case OMAPFB_COLOR_RGB444: |
| 283 | if (r != 0) |
| 284 | break; |
| 285 | |
| 286 | if (regno < 0) { |
| 287 | r = -EINVAL; |
| 288 | break; |
| 289 | } |
| 290 | |
| 291 | if (regno < 16) { |
| 292 | u16 pal; |
| 293 | pal = ((red >> (16 - var->red.length)) << |
| 294 | var->red.offset) | |
| 295 | ((green >> (16 - var->green.length)) << |
| 296 | var->green.offset) | |
| 297 | (blue >> (16 - var->blue.length)); |
| 298 | ((u32 *)(info->pseudo_palette))[regno] = pal; |
| 299 | } |
| 300 | break; |
| 301 | default: |
| 302 | BUG(); |
| 303 | } |
| 304 | return r; |
| 305 | } |
| 306 | |
| 307 | static int omapfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue, |
| 308 | u_int transp, struct fb_info *info) |
| 309 | { |
| 310 | return _setcolreg(info, regno, red, green, blue, transp, 1); |
| 311 | } |
| 312 | |
| 313 | static int omapfb_setcmap(struct fb_cmap *cmap, struct fb_info *info) |
| 314 | { |
| 315 | int count, index, r; |
| 316 | u16 *red, *green, *blue, *transp; |
| 317 | u16 trans = 0xffff; |
| 318 | |
| 319 | red = cmap->red; |
| 320 | green = cmap->green; |
| 321 | blue = cmap->blue; |
| 322 | transp = cmap->transp; |
| 323 | index = cmap->start; |
| 324 | |
| 325 | for (count = 0; count < cmap->len; count++) { |
| 326 | if (transp) |
| 327 | trans = *transp++; |
| 328 | r = _setcolreg(info, index++, *red++, *green++, *blue++, trans, |
| 329 | count == cmap->len - 1); |
| 330 | if (r != 0) |
| 331 | return r; |
| 332 | } |
| 333 | |
| 334 | return 0; |
| 335 | } |
| 336 | |
| 337 | static int omapfb_update_full_screen(struct fb_info *fbi); |
| 338 | |
| 339 | static int omapfb_blank(int blank, struct fb_info *fbi) |
| 340 | { |
| 341 | struct omapfb_plane_struct *plane = fbi->par; |
| 342 | struct omapfb_device *fbdev = plane->fbdev; |
| 343 | int do_update = 0; |
| 344 | int r = 0; |
| 345 | |
| 346 | omapfb_rqueue_lock(fbdev); |
| 347 | switch (blank) { |
Felipe Contreras | c958557 | 2009-03-31 15:25:42 -0700 | [diff] [blame] | 348 | case FB_BLANK_UNBLANK: |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 349 | if (fbdev->state == OMAPFB_SUSPENDED) { |
| 350 | if (fbdev->ctrl->resume) |
| 351 | fbdev->ctrl->resume(); |
| 352 | fbdev->panel->enable(fbdev->panel); |
| 353 | fbdev->state = OMAPFB_ACTIVE; |
| 354 | if (fbdev->ctrl->get_update_mode() == |
| 355 | OMAPFB_MANUAL_UPDATE) |
| 356 | do_update = 1; |
| 357 | } |
| 358 | break; |
Felipe Contreras | c958557 | 2009-03-31 15:25:42 -0700 | [diff] [blame] | 359 | case FB_BLANK_POWERDOWN: |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 360 | if (fbdev->state == OMAPFB_ACTIVE) { |
| 361 | fbdev->panel->disable(fbdev->panel); |
| 362 | if (fbdev->ctrl->suspend) |
| 363 | fbdev->ctrl->suspend(); |
| 364 | fbdev->state = OMAPFB_SUSPENDED; |
| 365 | } |
| 366 | break; |
| 367 | default: |
| 368 | r = -EINVAL; |
| 369 | } |
| 370 | omapfb_rqueue_unlock(fbdev); |
| 371 | |
| 372 | if (r == 0 && do_update) |
| 373 | r = omapfb_update_full_screen(fbi); |
| 374 | |
| 375 | return r; |
| 376 | } |
| 377 | |
| 378 | static void omapfb_sync(struct fb_info *fbi) |
| 379 | { |
| 380 | struct omapfb_plane_struct *plane = fbi->par; |
| 381 | struct omapfb_device *fbdev = plane->fbdev; |
| 382 | |
| 383 | omapfb_rqueue_lock(fbdev); |
| 384 | if (fbdev->ctrl->sync) |
| 385 | fbdev->ctrl->sync(); |
| 386 | omapfb_rqueue_unlock(fbdev); |
| 387 | } |
| 388 | |
| 389 | /* |
| 390 | * Set fb_info.fix fields and also updates fbdev. |
| 391 | * When calling this fb_info.var must be set up already. |
| 392 | */ |
Sergio Aguirre | 03bb2b4 | 2009-10-05 13:31:46 -0700 | [diff] [blame] | 393 | static void set_fb_fix(struct fb_info *fbi, int from_init) |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 394 | { |
| 395 | struct fb_fix_screeninfo *fix = &fbi->fix; |
| 396 | struct fb_var_screeninfo *var = &fbi->var; |
| 397 | struct omapfb_plane_struct *plane = fbi->par; |
| 398 | struct omapfb_mem_region *rg; |
| 399 | int bpp; |
| 400 | |
| 401 | rg = &plane->fbdev->mem_desc.region[plane->idx]; |
Russell King | 020f970 | 2008-12-01 17:40:54 +0000 | [diff] [blame] | 402 | fbi->screen_base = rg->vaddr; |
Sergio Aguirre | 03bb2b4 | 2009-10-05 13:31:46 -0700 | [diff] [blame] | 403 | |
| 404 | if (!from_init) { |
| 405 | mutex_lock(&fbi->mm_lock); |
| 406 | fix->smem_start = rg->paddr; |
| 407 | fix->smem_len = rg->size; |
| 408 | mutex_unlock(&fbi->mm_lock); |
| 409 | } else { |
| 410 | fix->smem_start = rg->paddr; |
| 411 | fix->smem_len = rg->size; |
| 412 | } |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 413 | |
| 414 | fix->type = FB_TYPE_PACKED_PIXELS; |
| 415 | bpp = var->bits_per_pixel; |
| 416 | if (var->nonstd) |
| 417 | fix->visual = FB_VISUAL_PSEUDOCOLOR; |
| 418 | else switch (var->bits_per_pixel) { |
| 419 | case 16: |
| 420 | case 12: |
| 421 | fix->visual = FB_VISUAL_TRUECOLOR; |
| 422 | /* 12bpp is stored in 16 bits */ |
| 423 | bpp = 16; |
| 424 | break; |
| 425 | case 1: |
| 426 | case 2: |
| 427 | case 4: |
| 428 | case 8: |
| 429 | fix->visual = FB_VISUAL_PSEUDOCOLOR; |
| 430 | break; |
| 431 | } |
| 432 | fix->accel = FB_ACCEL_OMAP1610; |
| 433 | fix->line_length = var->xres_virtual * bpp / 8; |
| 434 | } |
| 435 | |
| 436 | static int set_color_mode(struct omapfb_plane_struct *plane, |
| 437 | struct fb_var_screeninfo *var) |
| 438 | { |
| 439 | switch (var->nonstd) { |
| 440 | case 0: |
| 441 | break; |
| 442 | case OMAPFB_COLOR_YUV422: |
| 443 | var->bits_per_pixel = 16; |
| 444 | plane->color_mode = var->nonstd; |
| 445 | return 0; |
| 446 | case OMAPFB_COLOR_YUV420: |
| 447 | var->bits_per_pixel = 12; |
| 448 | plane->color_mode = var->nonstd; |
| 449 | return 0; |
| 450 | case OMAPFB_COLOR_YUY422: |
| 451 | var->bits_per_pixel = 16; |
| 452 | plane->color_mode = var->nonstd; |
| 453 | return 0; |
| 454 | default: |
| 455 | return -EINVAL; |
| 456 | } |
| 457 | |
| 458 | switch (var->bits_per_pixel) { |
| 459 | case 1: |
| 460 | plane->color_mode = OMAPFB_COLOR_CLUT_1BPP; |
| 461 | return 0; |
| 462 | case 2: |
| 463 | plane->color_mode = OMAPFB_COLOR_CLUT_2BPP; |
| 464 | return 0; |
| 465 | case 4: |
| 466 | plane->color_mode = OMAPFB_COLOR_CLUT_4BPP; |
| 467 | return 0; |
| 468 | case 8: |
| 469 | plane->color_mode = OMAPFB_COLOR_CLUT_8BPP; |
| 470 | return 0; |
| 471 | case 12: |
| 472 | var->bits_per_pixel = 16; |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 473 | case 16: |
Janusz Krzysztofik | 3e9ff04 | 2010-01-14 21:25:43 +0100 | [diff] [blame] | 474 | if (plane->fbdev->panel->bpp == 12) |
| 475 | plane->color_mode = OMAPFB_COLOR_RGB444; |
| 476 | else |
| 477 | plane->color_mode = OMAPFB_COLOR_RGB565; |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 478 | return 0; |
| 479 | default: |
| 480 | return -EINVAL; |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | /* |
| 485 | * Check the values in var against our capabilities and in case of out of |
| 486 | * bound values try to adjust them. |
| 487 | */ |
| 488 | static int set_fb_var(struct fb_info *fbi, |
| 489 | struct fb_var_screeninfo *var) |
| 490 | { |
| 491 | int bpp; |
| 492 | unsigned long max_frame_size; |
| 493 | unsigned long line_size; |
| 494 | int xres_min, xres_max; |
| 495 | int yres_min, yres_max; |
| 496 | struct omapfb_plane_struct *plane = fbi->par; |
| 497 | struct omapfb_device *fbdev = plane->fbdev; |
| 498 | struct lcd_panel *panel = fbdev->panel; |
| 499 | |
| 500 | if (set_color_mode(plane, var) < 0) |
| 501 | return -EINVAL; |
| 502 | |
| 503 | bpp = var->bits_per_pixel; |
| 504 | if (plane->color_mode == OMAPFB_COLOR_RGB444) |
| 505 | bpp = 16; |
| 506 | |
| 507 | switch (var->rotate) { |
| 508 | case 0: |
| 509 | case 180: |
| 510 | xres_min = OMAPFB_PLANE_XRES_MIN; |
| 511 | xres_max = panel->x_res; |
| 512 | yres_min = OMAPFB_PLANE_YRES_MIN; |
| 513 | yres_max = panel->y_res; |
| 514 | if (cpu_is_omap15xx()) { |
| 515 | var->xres = panel->x_res; |
| 516 | var->yres = panel->y_res; |
| 517 | } |
| 518 | break; |
| 519 | case 90: |
| 520 | case 270: |
| 521 | xres_min = OMAPFB_PLANE_YRES_MIN; |
| 522 | xres_max = panel->y_res; |
| 523 | yres_min = OMAPFB_PLANE_XRES_MIN; |
| 524 | yres_max = panel->x_res; |
| 525 | if (cpu_is_omap15xx()) { |
| 526 | var->xres = panel->y_res; |
| 527 | var->yres = panel->x_res; |
| 528 | } |
| 529 | break; |
| 530 | default: |
| 531 | return -EINVAL; |
| 532 | } |
| 533 | |
| 534 | if (var->xres < xres_min) |
| 535 | var->xres = xres_min; |
| 536 | if (var->yres < yres_min) |
| 537 | var->yres = yres_min; |
| 538 | if (var->xres > xres_max) |
| 539 | var->xres = xres_max; |
| 540 | if (var->yres > yres_max) |
| 541 | var->yres = yres_max; |
| 542 | |
| 543 | if (var->xres_virtual < var->xres) |
| 544 | var->xres_virtual = var->xres; |
| 545 | if (var->yres_virtual < var->yres) |
| 546 | var->yres_virtual = var->yres; |
| 547 | max_frame_size = fbdev->mem_desc.region[plane->idx].size; |
| 548 | line_size = var->xres_virtual * bpp / 8; |
| 549 | if (line_size * var->yres_virtual > max_frame_size) { |
| 550 | /* Try to keep yres_virtual first */ |
| 551 | line_size = max_frame_size / var->yres_virtual; |
| 552 | var->xres_virtual = line_size * 8 / bpp; |
| 553 | if (var->xres_virtual < var->xres) { |
| 554 | /* Still doesn't fit. Shrink yres_virtual too */ |
| 555 | var->xres_virtual = var->xres; |
| 556 | line_size = var->xres * bpp / 8; |
| 557 | var->yres_virtual = max_frame_size / line_size; |
| 558 | } |
| 559 | /* Recheck this, as the virtual size changed. */ |
| 560 | if (var->xres_virtual < var->xres) |
| 561 | var->xres = var->xres_virtual; |
| 562 | if (var->yres_virtual < var->yres) |
| 563 | var->yres = var->yres_virtual; |
| 564 | if (var->xres < xres_min || var->yres < yres_min) |
| 565 | return -EINVAL; |
| 566 | } |
| 567 | if (var->xres + var->xoffset > var->xres_virtual) |
| 568 | var->xoffset = var->xres_virtual - var->xres; |
| 569 | if (var->yres + var->yoffset > var->yres_virtual) |
| 570 | var->yoffset = var->yres_virtual - var->yres; |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 571 | |
| 572 | if (plane->color_mode == OMAPFB_COLOR_RGB444) { |
| 573 | var->red.offset = 8; var->red.length = 4; |
| 574 | var->red.msb_right = 0; |
| 575 | var->green.offset = 4; var->green.length = 4; |
| 576 | var->green.msb_right = 0; |
| 577 | var->blue.offset = 0; var->blue.length = 4; |
| 578 | var->blue.msb_right = 0; |
| 579 | } else { |
| 580 | var->red.offset = 11; var->red.length = 5; |
| 581 | var->red.msb_right = 0; |
| 582 | var->green.offset = 5; var->green.length = 6; |
| 583 | var->green.msb_right = 0; |
| 584 | var->blue.offset = 0; var->blue.length = 5; |
| 585 | var->blue.msb_right = 0; |
| 586 | } |
| 587 | |
| 588 | var->height = -1; |
| 589 | var->width = -1; |
| 590 | var->grayscale = 0; |
| 591 | |
| 592 | /* pixclock in ps, the rest in pixclock */ |
| 593 | var->pixclock = 10000000 / (panel->pixel_clock / 100); |
| 594 | var->left_margin = panel->hfp; |
| 595 | var->right_margin = panel->hbp; |
| 596 | var->upper_margin = panel->vfp; |
| 597 | var->lower_margin = panel->vbp; |
| 598 | var->hsync_len = panel->hsw; |
| 599 | var->vsync_len = panel->vsw; |
| 600 | |
| 601 | /* TODO: get these from panel->config */ |
| 602 | var->vmode = FB_VMODE_NONINTERLACED; |
| 603 | var->sync = 0; |
| 604 | |
| 605 | return 0; |
| 606 | } |
| 607 | |
| 608 | |
| 609 | /* Set rotation (0, 90, 180, 270 degree), and switch to the new mode. */ |
| 610 | static void omapfb_rotate(struct fb_info *fbi, int rotate) |
| 611 | { |
| 612 | struct omapfb_plane_struct *plane = fbi->par; |
| 613 | struct omapfb_device *fbdev = plane->fbdev; |
| 614 | |
| 615 | omapfb_rqueue_lock(fbdev); |
Rodrigo Vivi | 2f21a62 | 2009-09-22 16:46:53 -0700 | [diff] [blame] | 616 | if (rotate != fbi->var.rotate) { |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 617 | struct fb_var_screeninfo *new_var = &fbdev->new_var; |
| 618 | |
| 619 | memcpy(new_var, &fbi->var, sizeof(*new_var)); |
| 620 | new_var->rotate = rotate; |
| 621 | if (set_fb_var(fbi, new_var) == 0 && |
| 622 | memcmp(new_var, &fbi->var, sizeof(*new_var))) { |
| 623 | memcpy(&fbi->var, new_var, sizeof(*new_var)); |
| 624 | ctrl_change_mode(fbi); |
| 625 | } |
| 626 | } |
| 627 | omapfb_rqueue_unlock(fbdev); |
| 628 | } |
| 629 | |
| 630 | /* |
| 631 | * Set new x,y offsets in the virtual display for the visible area and switch |
| 632 | * to the new mode. |
| 633 | */ |
| 634 | static int omapfb_pan_display(struct fb_var_screeninfo *var, |
| 635 | struct fb_info *fbi) |
| 636 | { |
| 637 | struct omapfb_plane_struct *plane = fbi->par; |
| 638 | struct omapfb_device *fbdev = plane->fbdev; |
| 639 | int r = 0; |
| 640 | |
| 641 | omapfb_rqueue_lock(fbdev); |
| 642 | if (var->xoffset != fbi->var.xoffset || |
| 643 | var->yoffset != fbi->var.yoffset) { |
| 644 | struct fb_var_screeninfo *new_var = &fbdev->new_var; |
| 645 | |
| 646 | memcpy(new_var, &fbi->var, sizeof(*new_var)); |
| 647 | new_var->xoffset = var->xoffset; |
| 648 | new_var->yoffset = var->yoffset; |
| 649 | if (set_fb_var(fbi, new_var)) |
| 650 | r = -EINVAL; |
| 651 | else { |
| 652 | memcpy(&fbi->var, new_var, sizeof(*new_var)); |
| 653 | ctrl_change_mode(fbi); |
| 654 | } |
| 655 | } |
| 656 | omapfb_rqueue_unlock(fbdev); |
| 657 | |
| 658 | return r; |
| 659 | } |
| 660 | |
| 661 | /* Set mirror to vertical axis and switch to the new mode. */ |
| 662 | static int omapfb_mirror(struct fb_info *fbi, int mirror) |
| 663 | { |
| 664 | struct omapfb_plane_struct *plane = fbi->par; |
| 665 | struct omapfb_device *fbdev = plane->fbdev; |
| 666 | int r = 0; |
| 667 | |
| 668 | omapfb_rqueue_lock(fbdev); |
| 669 | mirror = mirror ? 1 : 0; |
| 670 | if (cpu_is_omap15xx()) |
| 671 | r = -EINVAL; |
| 672 | else if (mirror != plane->info.mirror) { |
| 673 | plane->info.mirror = mirror; |
| 674 | r = ctrl_change_mode(fbi); |
| 675 | } |
| 676 | omapfb_rqueue_unlock(fbdev); |
| 677 | |
| 678 | return r; |
| 679 | } |
| 680 | |
| 681 | /* |
| 682 | * Check values in var, try to adjust them in case of out of bound values if |
| 683 | * possible, or return error. |
| 684 | */ |
| 685 | static int omapfb_check_var(struct fb_var_screeninfo *var, struct fb_info *fbi) |
| 686 | { |
| 687 | struct omapfb_plane_struct *plane = fbi->par; |
| 688 | struct omapfb_device *fbdev = plane->fbdev; |
| 689 | int r; |
| 690 | |
| 691 | omapfb_rqueue_lock(fbdev); |
| 692 | if (fbdev->ctrl->sync != NULL) |
| 693 | fbdev->ctrl->sync(); |
| 694 | r = set_fb_var(fbi, var); |
| 695 | omapfb_rqueue_unlock(fbdev); |
| 696 | |
| 697 | return r; |
| 698 | } |
| 699 | |
| 700 | /* |
| 701 | * Switch to a new mode. The parameters for it has been check already by |
| 702 | * omapfb_check_var. |
| 703 | */ |
| 704 | static int omapfb_set_par(struct fb_info *fbi) |
| 705 | { |
| 706 | struct omapfb_plane_struct *plane = fbi->par; |
| 707 | struct omapfb_device *fbdev = plane->fbdev; |
| 708 | int r = 0; |
| 709 | |
| 710 | omapfb_rqueue_lock(fbdev); |
Sergio Aguirre | 03bb2b4 | 2009-10-05 13:31:46 -0700 | [diff] [blame] | 711 | set_fb_fix(fbi, 0); |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 712 | r = ctrl_change_mode(fbi); |
| 713 | omapfb_rqueue_unlock(fbdev); |
| 714 | |
| 715 | return r; |
| 716 | } |
| 717 | |
| 718 | int omapfb_update_window_async(struct fb_info *fbi, |
| 719 | struct omapfb_update_window *win, |
| 720 | void (*callback)(void *), |
| 721 | void *callback_data) |
| 722 | { |
Rodrigo Vivi | 2f21a62 | 2009-09-22 16:46:53 -0700 | [diff] [blame] | 723 | int xres, yres; |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 724 | struct omapfb_plane_struct *plane = fbi->par; |
| 725 | struct omapfb_device *fbdev = plane->fbdev; |
Rodrigo Vivi | 2f21a62 | 2009-09-22 16:46:53 -0700 | [diff] [blame] | 726 | struct fb_var_screeninfo *var = &fbi->var; |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 727 | |
Rodrigo Vivi | 2f21a62 | 2009-09-22 16:46:53 -0700 | [diff] [blame] | 728 | switch (var->rotate) { |
| 729 | case 0: |
| 730 | case 180: |
| 731 | xres = fbdev->panel->x_res; |
| 732 | yres = fbdev->panel->y_res; |
| 733 | break; |
| 734 | case 90: |
| 735 | case 270: |
| 736 | xres = fbdev->panel->y_res; |
| 737 | yres = fbdev->panel->x_res; |
| 738 | break; |
| 739 | default: |
| 740 | return -EINVAL; |
| 741 | } |
| 742 | |
| 743 | if (win->x >= xres || win->y >= yres || |
| 744 | win->out_x > xres || win->out_y > yres) |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 745 | return -EINVAL; |
| 746 | |
| 747 | if (!fbdev->ctrl->update_window || |
| 748 | fbdev->ctrl->get_update_mode() != OMAPFB_MANUAL_UPDATE) |
| 749 | return -ENODEV; |
| 750 | |
Rodrigo Vivi | 2f21a62 | 2009-09-22 16:46:53 -0700 | [diff] [blame] | 751 | if (win->x + win->width > xres) |
| 752 | win->width = xres - win->x; |
| 753 | if (win->y + win->height > yres) |
| 754 | win->height = yres - win->y; |
| 755 | if (win->out_x + win->out_width > xres) |
| 756 | win->out_width = xres - win->out_x; |
| 757 | if (win->out_y + win->out_height > yres) |
| 758 | win->out_height = yres - win->out_y; |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 759 | if (!win->width || !win->height || !win->out_width || !win->out_height) |
| 760 | return 0; |
| 761 | |
| 762 | return fbdev->ctrl->update_window(fbi, win, callback, callback_data); |
| 763 | } |
| 764 | EXPORT_SYMBOL(omapfb_update_window_async); |
| 765 | |
| 766 | static int omapfb_update_win(struct fb_info *fbi, |
| 767 | struct omapfb_update_window *win) |
| 768 | { |
| 769 | struct omapfb_plane_struct *plane = fbi->par; |
| 770 | int ret; |
| 771 | |
| 772 | omapfb_rqueue_lock(plane->fbdev); |
Russell King | c0fc18c5 | 2008-09-05 15:10:27 +0100 | [diff] [blame] | 773 | ret = omapfb_update_window_async(fbi, win, NULL, NULL); |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 774 | omapfb_rqueue_unlock(plane->fbdev); |
| 775 | |
| 776 | return ret; |
| 777 | } |
| 778 | |
| 779 | static int omapfb_update_full_screen(struct fb_info *fbi) |
| 780 | { |
| 781 | struct omapfb_plane_struct *plane = fbi->par; |
| 782 | struct omapfb_device *fbdev = plane->fbdev; |
| 783 | struct omapfb_update_window win; |
| 784 | int r; |
| 785 | |
| 786 | if (!fbdev->ctrl->update_window || |
| 787 | fbdev->ctrl->get_update_mode() != OMAPFB_MANUAL_UPDATE) |
| 788 | return -ENODEV; |
| 789 | |
| 790 | win.x = 0; |
| 791 | win.y = 0; |
| 792 | win.width = fbi->var.xres; |
| 793 | win.height = fbi->var.yres; |
| 794 | win.out_x = 0; |
| 795 | win.out_y = 0; |
| 796 | win.out_width = fbi->var.xres; |
| 797 | win.out_height = fbi->var.yres; |
| 798 | win.format = 0; |
| 799 | |
| 800 | omapfb_rqueue_lock(fbdev); |
Russell King | c0fc18c5 | 2008-09-05 15:10:27 +0100 | [diff] [blame] | 801 | r = fbdev->ctrl->update_window(fbi, &win, NULL, NULL); |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 802 | omapfb_rqueue_unlock(fbdev); |
| 803 | |
| 804 | return r; |
| 805 | } |
| 806 | |
| 807 | static int omapfb_setup_plane(struct fb_info *fbi, struct omapfb_plane_info *pi) |
| 808 | { |
| 809 | struct omapfb_plane_struct *plane = fbi->par; |
| 810 | struct omapfb_device *fbdev = plane->fbdev; |
| 811 | struct lcd_panel *panel = fbdev->panel; |
| 812 | struct omapfb_plane_info old_info; |
| 813 | int r = 0; |
| 814 | |
| 815 | if (pi->pos_x + pi->out_width > panel->x_res || |
| 816 | pi->pos_y + pi->out_height > panel->y_res) |
| 817 | return -EINVAL; |
| 818 | |
| 819 | omapfb_rqueue_lock(fbdev); |
| 820 | if (pi->enabled && !fbdev->mem_desc.region[plane->idx].size) { |
| 821 | /* |
| 822 | * This plane's memory was freed, can't enable it |
| 823 | * until it's reallocated. |
| 824 | */ |
| 825 | r = -EINVAL; |
| 826 | goto out; |
| 827 | } |
| 828 | old_info = plane->info; |
| 829 | plane->info = *pi; |
| 830 | if (pi->enabled) { |
| 831 | r = ctrl_change_mode(fbi); |
| 832 | if (r < 0) { |
| 833 | plane->info = old_info; |
| 834 | goto out; |
| 835 | } |
| 836 | } |
| 837 | r = fbdev->ctrl->enable_plane(plane->idx, pi->enabled); |
| 838 | if (r < 0) { |
| 839 | plane->info = old_info; |
| 840 | goto out; |
| 841 | } |
| 842 | out: |
| 843 | omapfb_rqueue_unlock(fbdev); |
| 844 | return r; |
| 845 | } |
| 846 | |
| 847 | static int omapfb_query_plane(struct fb_info *fbi, struct omapfb_plane_info *pi) |
| 848 | { |
| 849 | struct omapfb_plane_struct *plane = fbi->par; |
| 850 | |
| 851 | *pi = plane->info; |
| 852 | return 0; |
| 853 | } |
| 854 | |
| 855 | static int omapfb_setup_mem(struct fb_info *fbi, struct omapfb_mem_info *mi) |
| 856 | { |
| 857 | struct omapfb_plane_struct *plane = fbi->par; |
| 858 | struct omapfb_device *fbdev = plane->fbdev; |
| 859 | struct omapfb_mem_region *rg = &fbdev->mem_desc.region[plane->idx]; |
| 860 | size_t size; |
| 861 | int r = 0; |
| 862 | |
| 863 | if (fbdev->ctrl->setup_mem == NULL) |
| 864 | return -ENODEV; |
Tomi Valkeinen | 1896e2f | 2011-09-20 10:07:24 +0300 | [diff] [blame] | 865 | if (mi->type != OMAPFB_MEMTYPE_SDRAM) |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 866 | return -EINVAL; |
| 867 | |
| 868 | size = PAGE_ALIGN(mi->size); |
| 869 | omapfb_rqueue_lock(fbdev); |
| 870 | if (plane->info.enabled) { |
| 871 | r = -EBUSY; |
| 872 | goto out; |
| 873 | } |
| 874 | if (rg->size != size || rg->type != mi->type) { |
| 875 | struct fb_var_screeninfo *new_var = &fbdev->new_var; |
| 876 | unsigned long old_size = rg->size; |
| 877 | u8 old_type = rg->type; |
| 878 | unsigned long paddr; |
| 879 | |
| 880 | rg->size = size; |
| 881 | rg->type = mi->type; |
| 882 | /* |
| 883 | * size == 0 is a special case, for which we |
| 884 | * don't check / adjust the screen parameters. |
| 885 | * This isn't a problem since the plane can't |
| 886 | * be reenabled unless its size is > 0. |
| 887 | */ |
| 888 | if (old_size != size && size) { |
| 889 | if (size) { |
| 890 | memcpy(new_var, &fbi->var, sizeof(*new_var)); |
| 891 | r = set_fb_var(fbi, new_var); |
| 892 | if (r < 0) |
| 893 | goto out; |
| 894 | } |
| 895 | } |
| 896 | |
| 897 | if (fbdev->ctrl->sync) |
| 898 | fbdev->ctrl->sync(); |
| 899 | r = fbdev->ctrl->setup_mem(plane->idx, size, mi->type, &paddr); |
| 900 | if (r < 0) { |
| 901 | /* Revert changes. */ |
| 902 | rg->size = old_size; |
| 903 | rg->type = old_type; |
| 904 | goto out; |
| 905 | } |
| 906 | rg->paddr = paddr; |
| 907 | |
| 908 | if (old_size != size) { |
| 909 | if (size) { |
| 910 | memcpy(&fbi->var, new_var, sizeof(fbi->var)); |
Sergio Aguirre | 03bb2b4 | 2009-10-05 13:31:46 -0700 | [diff] [blame] | 911 | set_fb_fix(fbi, 0); |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 912 | } else { |
| 913 | /* |
| 914 | * Set these explicitly to indicate that the |
| 915 | * plane memory is dealloce'd, the other |
| 916 | * screen parameters in var / fix are invalid. |
| 917 | */ |
Krzysztof Helt | 537a1bf | 2009-06-30 11:41:29 -0700 | [diff] [blame] | 918 | mutex_lock(&fbi->mm_lock); |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 919 | fbi->fix.smem_start = 0; |
| 920 | fbi->fix.smem_len = 0; |
Krzysztof Helt | 537a1bf | 2009-06-30 11:41:29 -0700 | [diff] [blame] | 921 | mutex_unlock(&fbi->mm_lock); |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 922 | } |
| 923 | } |
| 924 | } |
| 925 | out: |
| 926 | omapfb_rqueue_unlock(fbdev); |
| 927 | |
| 928 | return r; |
| 929 | } |
| 930 | |
| 931 | static int omapfb_query_mem(struct fb_info *fbi, struct omapfb_mem_info *mi) |
| 932 | { |
| 933 | struct omapfb_plane_struct *plane = fbi->par; |
| 934 | struct omapfb_device *fbdev = plane->fbdev; |
| 935 | struct omapfb_mem_region *rg; |
| 936 | |
| 937 | rg = &fbdev->mem_desc.region[plane->idx]; |
| 938 | memset(mi, 0, sizeof(*mi)); |
| 939 | mi->size = rg->size; |
| 940 | mi->type = rg->type; |
| 941 | |
| 942 | return 0; |
| 943 | } |
| 944 | |
| 945 | static int omapfb_set_color_key(struct omapfb_device *fbdev, |
| 946 | struct omapfb_color_key *ck) |
| 947 | { |
| 948 | int r; |
| 949 | |
| 950 | if (!fbdev->ctrl->set_color_key) |
| 951 | return -ENODEV; |
| 952 | |
| 953 | omapfb_rqueue_lock(fbdev); |
| 954 | r = fbdev->ctrl->set_color_key(ck); |
| 955 | omapfb_rqueue_unlock(fbdev); |
| 956 | |
| 957 | return r; |
| 958 | } |
| 959 | |
| 960 | static int omapfb_get_color_key(struct omapfb_device *fbdev, |
| 961 | struct omapfb_color_key *ck) |
| 962 | { |
| 963 | int r; |
| 964 | |
| 965 | if (!fbdev->ctrl->get_color_key) |
| 966 | return -ENODEV; |
| 967 | |
| 968 | omapfb_rqueue_lock(fbdev); |
| 969 | r = fbdev->ctrl->get_color_key(ck); |
| 970 | omapfb_rqueue_unlock(fbdev); |
| 971 | |
| 972 | return r; |
| 973 | } |
| 974 | |
| 975 | static struct blocking_notifier_head omapfb_client_list[OMAPFB_PLANE_NUM]; |
| 976 | static int notifier_inited; |
| 977 | |
| 978 | static void omapfb_init_notifier(void) |
| 979 | { |
| 980 | int i; |
| 981 | |
| 982 | for (i = 0; i < OMAPFB_PLANE_NUM; i++) |
| 983 | BLOCKING_INIT_NOTIFIER_HEAD(&omapfb_client_list[i]); |
| 984 | } |
| 985 | |
| 986 | int omapfb_register_client(struct omapfb_notifier_block *omapfb_nb, |
| 987 | omapfb_notifier_callback_t callback, |
| 988 | void *callback_data) |
| 989 | { |
| 990 | int r; |
| 991 | |
| 992 | if ((unsigned)omapfb_nb->plane_idx > OMAPFB_PLANE_NUM) |
| 993 | return -EINVAL; |
| 994 | |
| 995 | if (!notifier_inited) { |
| 996 | omapfb_init_notifier(); |
| 997 | notifier_inited = 1; |
| 998 | } |
| 999 | |
| 1000 | omapfb_nb->nb.notifier_call = (int (*)(struct notifier_block *, |
| 1001 | unsigned long, void *))callback; |
| 1002 | omapfb_nb->data = callback_data; |
| 1003 | r = blocking_notifier_chain_register( |
| 1004 | &omapfb_client_list[omapfb_nb->plane_idx], |
| 1005 | &omapfb_nb->nb); |
| 1006 | if (r) |
| 1007 | return r; |
| 1008 | if (omapfb_dev != NULL && |
| 1009 | omapfb_dev->ctrl && omapfb_dev->ctrl->bind_client) { |
| 1010 | omapfb_dev->ctrl->bind_client(omapfb_nb); |
| 1011 | } |
| 1012 | |
| 1013 | return 0; |
| 1014 | } |
| 1015 | EXPORT_SYMBOL(omapfb_register_client); |
| 1016 | |
| 1017 | int omapfb_unregister_client(struct omapfb_notifier_block *omapfb_nb) |
| 1018 | { |
| 1019 | return blocking_notifier_chain_unregister( |
| 1020 | &omapfb_client_list[omapfb_nb->plane_idx], &omapfb_nb->nb); |
| 1021 | } |
| 1022 | EXPORT_SYMBOL(omapfb_unregister_client); |
| 1023 | |
| 1024 | void omapfb_notify_clients(struct omapfb_device *fbdev, unsigned long event) |
| 1025 | { |
| 1026 | int i; |
| 1027 | |
| 1028 | if (!notifier_inited) |
| 1029 | /* no client registered yet */ |
| 1030 | return; |
| 1031 | |
| 1032 | for (i = 0; i < OMAPFB_PLANE_NUM; i++) |
| 1033 | blocking_notifier_call_chain(&omapfb_client_list[i], event, |
| 1034 | fbdev->fb_info[i]); |
| 1035 | } |
| 1036 | EXPORT_SYMBOL(omapfb_notify_clients); |
| 1037 | |
| 1038 | static int omapfb_set_update_mode(struct omapfb_device *fbdev, |
| 1039 | enum omapfb_update_mode mode) |
| 1040 | { |
| 1041 | int r; |
| 1042 | |
| 1043 | omapfb_rqueue_lock(fbdev); |
| 1044 | r = fbdev->ctrl->set_update_mode(mode); |
| 1045 | omapfb_rqueue_unlock(fbdev); |
| 1046 | |
| 1047 | return r; |
| 1048 | } |
| 1049 | |
| 1050 | static enum omapfb_update_mode omapfb_get_update_mode(struct omapfb_device *fbdev) |
| 1051 | { |
| 1052 | int r; |
| 1053 | |
| 1054 | omapfb_rqueue_lock(fbdev); |
| 1055 | r = fbdev->ctrl->get_update_mode(); |
| 1056 | omapfb_rqueue_unlock(fbdev); |
| 1057 | |
| 1058 | return r; |
| 1059 | } |
| 1060 | |
| 1061 | static void omapfb_get_caps(struct omapfb_device *fbdev, int plane, |
| 1062 | struct omapfb_caps *caps) |
| 1063 | { |
| 1064 | memset(caps, 0, sizeof(*caps)); |
| 1065 | fbdev->ctrl->get_caps(plane, caps); |
| 1066 | caps->ctrl |= fbdev->panel->get_caps(fbdev->panel); |
| 1067 | } |
| 1068 | |
| 1069 | /* For lcd testing */ |
| 1070 | void omapfb_write_first_pixel(struct omapfb_device *fbdev, u16 pixval) |
| 1071 | { |
| 1072 | omapfb_rqueue_lock(fbdev); |
| 1073 | *(u16 *)fbdev->mem_desc.region[0].vaddr = pixval; |
| 1074 | if (fbdev->ctrl->get_update_mode() == OMAPFB_MANUAL_UPDATE) { |
| 1075 | struct omapfb_update_window win; |
| 1076 | |
| 1077 | memset(&win, 0, sizeof(win)); |
| 1078 | win.width = 2; |
| 1079 | win.height = 2; |
| 1080 | win.out_width = 2; |
| 1081 | win.out_height = 2; |
Russell King | c0fc18c5 | 2008-09-05 15:10:27 +0100 | [diff] [blame] | 1082 | fbdev->ctrl->update_window(fbdev->fb_info[0], &win, NULL, NULL); |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 1083 | } |
| 1084 | omapfb_rqueue_unlock(fbdev); |
| 1085 | } |
| 1086 | EXPORT_SYMBOL(omapfb_write_first_pixel); |
| 1087 | |
| 1088 | /* |
| 1089 | * Ioctl interface. Part of the kernel mode frame buffer API is duplicated |
| 1090 | * here to be accessible by user mode code. |
| 1091 | */ |
| 1092 | static int omapfb_ioctl(struct fb_info *fbi, unsigned int cmd, |
| 1093 | unsigned long arg) |
| 1094 | { |
| 1095 | struct omapfb_plane_struct *plane = fbi->par; |
| 1096 | struct omapfb_device *fbdev = plane->fbdev; |
| 1097 | struct fb_ops *ops = fbi->fbops; |
| 1098 | union { |
| 1099 | struct omapfb_update_window update_window; |
| 1100 | struct omapfb_plane_info plane_info; |
| 1101 | struct omapfb_mem_info mem_info; |
| 1102 | struct omapfb_color_key color_key; |
| 1103 | enum omapfb_update_mode update_mode; |
| 1104 | struct omapfb_caps caps; |
| 1105 | unsigned int mirror; |
| 1106 | int plane_out; |
| 1107 | int enable_plane; |
| 1108 | } p; |
| 1109 | int r = 0; |
| 1110 | |
| 1111 | BUG_ON(!ops); |
| 1112 | switch (cmd) { |
| 1113 | case OMAPFB_MIRROR: |
| 1114 | if (get_user(p.mirror, (int __user *)arg)) |
| 1115 | r = -EFAULT; |
| 1116 | else |
| 1117 | omapfb_mirror(fbi, p.mirror); |
| 1118 | break; |
| 1119 | case OMAPFB_SYNC_GFX: |
| 1120 | omapfb_sync(fbi); |
| 1121 | break; |
| 1122 | case OMAPFB_VSYNC: |
| 1123 | break; |
| 1124 | case OMAPFB_SET_UPDATE_MODE: |
| 1125 | if (get_user(p.update_mode, (int __user *)arg)) |
| 1126 | r = -EFAULT; |
| 1127 | else |
| 1128 | r = omapfb_set_update_mode(fbdev, p.update_mode); |
| 1129 | break; |
| 1130 | case OMAPFB_GET_UPDATE_MODE: |
| 1131 | p.update_mode = omapfb_get_update_mode(fbdev); |
| 1132 | if (put_user(p.update_mode, |
| 1133 | (enum omapfb_update_mode __user *)arg)) |
| 1134 | r = -EFAULT; |
| 1135 | break; |
| 1136 | case OMAPFB_UPDATE_WINDOW_OLD: |
| 1137 | if (copy_from_user(&p.update_window, (void __user *)arg, |
| 1138 | sizeof(struct omapfb_update_window_old))) |
| 1139 | r = -EFAULT; |
| 1140 | else { |
| 1141 | struct omapfb_update_window *u = &p.update_window; |
| 1142 | u->out_x = u->x; |
| 1143 | u->out_y = u->y; |
| 1144 | u->out_width = u->width; |
| 1145 | u->out_height = u->height; |
| 1146 | memset(u->reserved, 0, sizeof(u->reserved)); |
| 1147 | r = omapfb_update_win(fbi, u); |
| 1148 | } |
| 1149 | break; |
| 1150 | case OMAPFB_UPDATE_WINDOW: |
| 1151 | if (copy_from_user(&p.update_window, (void __user *)arg, |
| 1152 | sizeof(p.update_window))) |
| 1153 | r = -EFAULT; |
| 1154 | else |
| 1155 | r = omapfb_update_win(fbi, &p.update_window); |
| 1156 | break; |
| 1157 | case OMAPFB_SETUP_PLANE: |
| 1158 | if (copy_from_user(&p.plane_info, (void __user *)arg, |
| 1159 | sizeof(p.plane_info))) |
| 1160 | r = -EFAULT; |
| 1161 | else |
| 1162 | r = omapfb_setup_plane(fbi, &p.plane_info); |
| 1163 | break; |
| 1164 | case OMAPFB_QUERY_PLANE: |
| 1165 | if ((r = omapfb_query_plane(fbi, &p.plane_info)) < 0) |
| 1166 | break; |
| 1167 | if (copy_to_user((void __user *)arg, &p.plane_info, |
| 1168 | sizeof(p.plane_info))) |
| 1169 | r = -EFAULT; |
| 1170 | break; |
| 1171 | case OMAPFB_SETUP_MEM: |
| 1172 | if (copy_from_user(&p.mem_info, (void __user *)arg, |
| 1173 | sizeof(p.mem_info))) |
| 1174 | r = -EFAULT; |
| 1175 | else |
| 1176 | r = omapfb_setup_mem(fbi, &p.mem_info); |
| 1177 | break; |
| 1178 | case OMAPFB_QUERY_MEM: |
| 1179 | if ((r = omapfb_query_mem(fbi, &p.mem_info)) < 0) |
| 1180 | break; |
| 1181 | if (copy_to_user((void __user *)arg, &p.mem_info, |
| 1182 | sizeof(p.mem_info))) |
| 1183 | r = -EFAULT; |
| 1184 | break; |
| 1185 | case OMAPFB_SET_COLOR_KEY: |
| 1186 | if (copy_from_user(&p.color_key, (void __user *)arg, |
| 1187 | sizeof(p.color_key))) |
| 1188 | r = -EFAULT; |
| 1189 | else |
| 1190 | r = omapfb_set_color_key(fbdev, &p.color_key); |
| 1191 | break; |
| 1192 | case OMAPFB_GET_COLOR_KEY: |
| 1193 | if ((r = omapfb_get_color_key(fbdev, &p.color_key)) < 0) |
| 1194 | break; |
| 1195 | if (copy_to_user((void __user *)arg, &p.color_key, |
| 1196 | sizeof(p.color_key))) |
| 1197 | r = -EFAULT; |
| 1198 | break; |
| 1199 | case OMAPFB_GET_CAPS: |
| 1200 | omapfb_get_caps(fbdev, plane->idx, &p.caps); |
| 1201 | if (copy_to_user((void __user *)arg, &p.caps, sizeof(p.caps))) |
| 1202 | r = -EFAULT; |
| 1203 | break; |
| 1204 | case OMAPFB_LCD_TEST: |
| 1205 | { |
| 1206 | int test_num; |
| 1207 | |
| 1208 | if (get_user(test_num, (int __user *)arg)) { |
| 1209 | r = -EFAULT; |
| 1210 | break; |
| 1211 | } |
| 1212 | if (!fbdev->panel->run_test) { |
| 1213 | r = -EINVAL; |
| 1214 | break; |
| 1215 | } |
| 1216 | r = fbdev->panel->run_test(fbdev->panel, test_num); |
| 1217 | break; |
| 1218 | } |
| 1219 | case OMAPFB_CTRL_TEST: |
| 1220 | { |
| 1221 | int test_num; |
| 1222 | |
| 1223 | if (get_user(test_num, (int __user *)arg)) { |
| 1224 | r = -EFAULT; |
| 1225 | break; |
| 1226 | } |
| 1227 | if (!fbdev->ctrl->run_test) { |
| 1228 | r = -EINVAL; |
| 1229 | break; |
| 1230 | } |
| 1231 | r = fbdev->ctrl->run_test(test_num); |
| 1232 | break; |
| 1233 | } |
| 1234 | default: |
| 1235 | r = -EINVAL; |
| 1236 | } |
| 1237 | |
| 1238 | return r; |
| 1239 | } |
| 1240 | |
| 1241 | static int omapfb_mmap(struct fb_info *info, struct vm_area_struct *vma) |
| 1242 | { |
| 1243 | struct omapfb_plane_struct *plane = info->par; |
| 1244 | struct omapfb_device *fbdev = plane->fbdev; |
| 1245 | int r; |
| 1246 | |
| 1247 | omapfb_rqueue_lock(fbdev); |
| 1248 | r = fbdev->ctrl->mmap(info, vma); |
| 1249 | omapfb_rqueue_unlock(fbdev); |
| 1250 | |
| 1251 | return r; |
| 1252 | } |
| 1253 | |
| 1254 | /* |
| 1255 | * Callback table for the frame buffer framework. Some of these pointers |
| 1256 | * will be changed according to the current setting of fb_info->accel_flags. |
| 1257 | */ |
| 1258 | static struct fb_ops omapfb_ops = { |
| 1259 | .owner = THIS_MODULE, |
| 1260 | .fb_open = omapfb_open, |
| 1261 | .fb_release = omapfb_release, |
| 1262 | .fb_setcolreg = omapfb_setcolreg, |
| 1263 | .fb_setcmap = omapfb_setcmap, |
| 1264 | .fb_fillrect = cfb_fillrect, |
| 1265 | .fb_copyarea = cfb_copyarea, |
| 1266 | .fb_imageblit = cfb_imageblit, |
| 1267 | .fb_blank = omapfb_blank, |
| 1268 | .fb_ioctl = omapfb_ioctl, |
| 1269 | .fb_check_var = omapfb_check_var, |
| 1270 | .fb_set_par = omapfb_set_par, |
| 1271 | .fb_rotate = omapfb_rotate, |
| 1272 | .fb_pan_display = omapfb_pan_display, |
| 1273 | }; |
| 1274 | |
| 1275 | /* |
| 1276 | * --------------------------------------------------------------------------- |
| 1277 | * Sysfs interface |
| 1278 | * --------------------------------------------------------------------------- |
| 1279 | */ |
| 1280 | /* omapfbX sysfs entries */ |
| 1281 | static ssize_t omapfb_show_caps_num(struct device *dev, |
| 1282 | struct device_attribute *attr, char *buf) |
| 1283 | { |
Greg Kroah-Hartman | 5e9a8bd | 2009-06-23 08:31:46 -0700 | [diff] [blame] | 1284 | struct omapfb_device *fbdev = dev_get_drvdata(dev); |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 1285 | int plane; |
| 1286 | size_t size; |
| 1287 | struct omapfb_caps caps; |
| 1288 | |
| 1289 | plane = 0; |
| 1290 | size = 0; |
| 1291 | while (size < PAGE_SIZE && plane < OMAPFB_PLANE_NUM) { |
| 1292 | omapfb_get_caps(fbdev, plane, &caps); |
| 1293 | size += snprintf(&buf[size], PAGE_SIZE - size, |
| 1294 | "plane#%d %#010x %#010x %#010x\n", |
| 1295 | plane, caps.ctrl, caps.plane_color, caps.wnd_color); |
| 1296 | plane++; |
| 1297 | } |
| 1298 | return size; |
| 1299 | } |
| 1300 | |
| 1301 | static ssize_t omapfb_show_caps_text(struct device *dev, |
| 1302 | struct device_attribute *attr, char *buf) |
| 1303 | { |
Greg Kroah-Hartman | 5e9a8bd | 2009-06-23 08:31:46 -0700 | [diff] [blame] | 1304 | struct omapfb_device *fbdev = dev_get_drvdata(dev); |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 1305 | int i; |
| 1306 | struct omapfb_caps caps; |
| 1307 | int plane; |
| 1308 | size_t size; |
| 1309 | |
| 1310 | plane = 0; |
| 1311 | size = 0; |
| 1312 | while (size < PAGE_SIZE && plane < OMAPFB_PLANE_NUM) { |
| 1313 | omapfb_get_caps(fbdev, plane, &caps); |
| 1314 | size += snprintf(&buf[size], PAGE_SIZE - size, |
| 1315 | "plane#%d:\n", plane); |
| 1316 | for (i = 0; i < ARRAY_SIZE(ctrl_caps) && |
| 1317 | size < PAGE_SIZE; i++) { |
| 1318 | if (ctrl_caps[i].flag & caps.ctrl) |
| 1319 | size += snprintf(&buf[size], PAGE_SIZE - size, |
| 1320 | " %s\n", ctrl_caps[i].name); |
| 1321 | } |
| 1322 | size += snprintf(&buf[size], PAGE_SIZE - size, |
| 1323 | " plane colors:\n"); |
| 1324 | for (i = 0; i < ARRAY_SIZE(color_caps) && |
| 1325 | size < PAGE_SIZE; i++) { |
| 1326 | if (color_caps[i].flag & caps.plane_color) |
| 1327 | size += snprintf(&buf[size], PAGE_SIZE - size, |
| 1328 | " %s\n", color_caps[i].name); |
| 1329 | } |
| 1330 | size += snprintf(&buf[size], PAGE_SIZE - size, |
| 1331 | " window colors:\n"); |
| 1332 | for (i = 0; i < ARRAY_SIZE(color_caps) && |
| 1333 | size < PAGE_SIZE; i++) { |
| 1334 | if (color_caps[i].flag & caps.wnd_color) |
| 1335 | size += snprintf(&buf[size], PAGE_SIZE - size, |
| 1336 | " %s\n", color_caps[i].name); |
| 1337 | } |
| 1338 | |
| 1339 | plane++; |
| 1340 | } |
| 1341 | return size; |
| 1342 | } |
| 1343 | |
| 1344 | static DEVICE_ATTR(caps_num, 0444, omapfb_show_caps_num, NULL); |
| 1345 | static DEVICE_ATTR(caps_text, 0444, omapfb_show_caps_text, NULL); |
| 1346 | |
| 1347 | /* panel sysfs entries */ |
| 1348 | static ssize_t omapfb_show_panel_name(struct device *dev, |
| 1349 | struct device_attribute *attr, char *buf) |
| 1350 | { |
Greg Kroah-Hartman | 5e9a8bd | 2009-06-23 08:31:46 -0700 | [diff] [blame] | 1351 | struct omapfb_device *fbdev = dev_get_drvdata(dev); |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 1352 | |
| 1353 | return snprintf(buf, PAGE_SIZE, "%s\n", fbdev->panel->name); |
| 1354 | } |
| 1355 | |
| 1356 | static ssize_t omapfb_show_bklight_level(struct device *dev, |
| 1357 | struct device_attribute *attr, |
| 1358 | char *buf) |
| 1359 | { |
Greg Kroah-Hartman | 5e9a8bd | 2009-06-23 08:31:46 -0700 | [diff] [blame] | 1360 | struct omapfb_device *fbdev = dev_get_drvdata(dev); |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 1361 | int r; |
| 1362 | |
| 1363 | if (fbdev->panel->get_bklight_level) { |
| 1364 | r = snprintf(buf, PAGE_SIZE, "%d\n", |
| 1365 | fbdev->panel->get_bklight_level(fbdev->panel)); |
| 1366 | } else |
| 1367 | r = -ENODEV; |
| 1368 | return r; |
| 1369 | } |
| 1370 | |
| 1371 | static ssize_t omapfb_store_bklight_level(struct device *dev, |
| 1372 | struct device_attribute *attr, |
| 1373 | const char *buf, size_t size) |
| 1374 | { |
Greg Kroah-Hartman | 5e9a8bd | 2009-06-23 08:31:46 -0700 | [diff] [blame] | 1375 | struct omapfb_device *fbdev = dev_get_drvdata(dev); |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 1376 | int r; |
| 1377 | |
| 1378 | if (fbdev->panel->set_bklight_level) { |
| 1379 | unsigned int level; |
| 1380 | |
| 1381 | if (sscanf(buf, "%10d", &level) == 1) { |
| 1382 | r = fbdev->panel->set_bklight_level(fbdev->panel, |
| 1383 | level); |
| 1384 | } else |
| 1385 | r = -EINVAL; |
| 1386 | } else |
| 1387 | r = -ENODEV; |
| 1388 | return r ? r : size; |
| 1389 | } |
| 1390 | |
| 1391 | static ssize_t omapfb_show_bklight_max(struct device *dev, |
| 1392 | struct device_attribute *attr, char *buf) |
| 1393 | { |
Greg Kroah-Hartman | 5e9a8bd | 2009-06-23 08:31:46 -0700 | [diff] [blame] | 1394 | struct omapfb_device *fbdev = dev_get_drvdata(dev); |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 1395 | int r; |
| 1396 | |
| 1397 | if (fbdev->panel->get_bklight_level) { |
| 1398 | r = snprintf(buf, PAGE_SIZE, "%d\n", |
| 1399 | fbdev->panel->get_bklight_max(fbdev->panel)); |
| 1400 | } else |
| 1401 | r = -ENODEV; |
| 1402 | return r; |
| 1403 | } |
| 1404 | |
| 1405 | static struct device_attribute dev_attr_panel_name = |
| 1406 | __ATTR(name, 0444, omapfb_show_panel_name, NULL); |
| 1407 | static DEVICE_ATTR(backlight_level, 0664, |
| 1408 | omapfb_show_bklight_level, omapfb_store_bklight_level); |
| 1409 | static DEVICE_ATTR(backlight_max, 0444, omapfb_show_bklight_max, NULL); |
| 1410 | |
| 1411 | static struct attribute *panel_attrs[] = { |
| 1412 | &dev_attr_panel_name.attr, |
| 1413 | &dev_attr_backlight_level.attr, |
| 1414 | &dev_attr_backlight_max.attr, |
| 1415 | NULL, |
| 1416 | }; |
| 1417 | |
| 1418 | static struct attribute_group panel_attr_grp = { |
| 1419 | .name = "panel", |
| 1420 | .attrs = panel_attrs, |
| 1421 | }; |
| 1422 | |
| 1423 | /* ctrl sysfs entries */ |
| 1424 | static ssize_t omapfb_show_ctrl_name(struct device *dev, |
| 1425 | struct device_attribute *attr, char *buf) |
| 1426 | { |
Greg Kroah-Hartman | 5e9a8bd | 2009-06-23 08:31:46 -0700 | [diff] [blame] | 1427 | struct omapfb_device *fbdev = dev_get_drvdata(dev); |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 1428 | |
| 1429 | return snprintf(buf, PAGE_SIZE, "%s\n", fbdev->ctrl->name); |
| 1430 | } |
| 1431 | |
| 1432 | static struct device_attribute dev_attr_ctrl_name = |
| 1433 | __ATTR(name, 0444, omapfb_show_ctrl_name, NULL); |
| 1434 | |
| 1435 | static struct attribute *ctrl_attrs[] = { |
| 1436 | &dev_attr_ctrl_name.attr, |
| 1437 | NULL, |
| 1438 | }; |
| 1439 | |
| 1440 | static struct attribute_group ctrl_attr_grp = { |
| 1441 | .name = "ctrl", |
| 1442 | .attrs = ctrl_attrs, |
| 1443 | }; |
| 1444 | |
| 1445 | static int omapfb_register_sysfs(struct omapfb_device *fbdev) |
| 1446 | { |
| 1447 | int r; |
| 1448 | |
| 1449 | if ((r = device_create_file(fbdev->dev, &dev_attr_caps_num))) |
| 1450 | goto fail0; |
| 1451 | |
| 1452 | if ((r = device_create_file(fbdev->dev, &dev_attr_caps_text))) |
| 1453 | goto fail1; |
| 1454 | |
| 1455 | if ((r = sysfs_create_group(&fbdev->dev->kobj, &panel_attr_grp))) |
| 1456 | goto fail2; |
| 1457 | |
| 1458 | if ((r = sysfs_create_group(&fbdev->dev->kobj, &ctrl_attr_grp))) |
| 1459 | goto fail3; |
| 1460 | |
| 1461 | return 0; |
| 1462 | fail3: |
| 1463 | sysfs_remove_group(&fbdev->dev->kobj, &panel_attr_grp); |
| 1464 | fail2: |
| 1465 | device_remove_file(fbdev->dev, &dev_attr_caps_text); |
| 1466 | fail1: |
| 1467 | device_remove_file(fbdev->dev, &dev_attr_caps_num); |
| 1468 | fail0: |
| 1469 | dev_err(fbdev->dev, "unable to register sysfs interface\n"); |
| 1470 | return r; |
| 1471 | } |
| 1472 | |
| 1473 | static void omapfb_unregister_sysfs(struct omapfb_device *fbdev) |
| 1474 | { |
| 1475 | sysfs_remove_group(&fbdev->dev->kobj, &ctrl_attr_grp); |
| 1476 | sysfs_remove_group(&fbdev->dev->kobj, &panel_attr_grp); |
| 1477 | device_remove_file(fbdev->dev, &dev_attr_caps_num); |
| 1478 | device_remove_file(fbdev->dev, &dev_attr_caps_text); |
| 1479 | } |
| 1480 | |
| 1481 | /* |
| 1482 | * --------------------------------------------------------------------------- |
| 1483 | * LDM callbacks |
| 1484 | * --------------------------------------------------------------------------- |
| 1485 | */ |
| 1486 | /* Initialize system fb_info object and set the default video mode. |
| 1487 | * The frame buffer memory already allocated by lcddma_init |
| 1488 | */ |
| 1489 | static int fbinfo_init(struct omapfb_device *fbdev, struct fb_info *info) |
| 1490 | { |
| 1491 | struct fb_var_screeninfo *var = &info->var; |
| 1492 | struct fb_fix_screeninfo *fix = &info->fix; |
| 1493 | int r = 0; |
| 1494 | |
| 1495 | info->fbops = &omapfb_ops; |
| 1496 | info->flags = FBINFO_FLAG_DEFAULT; |
| 1497 | |
| 1498 | strncpy(fix->id, MODULE_NAME, sizeof(fix->id)); |
| 1499 | |
| 1500 | info->pseudo_palette = fbdev->pseudo_palette; |
| 1501 | |
| 1502 | var->accel_flags = def_accel ? FB_ACCELF_TEXT : 0; |
| 1503 | var->xres = def_vxres; |
| 1504 | var->yres = def_vyres; |
| 1505 | var->xres_virtual = def_vxres; |
| 1506 | var->yres_virtual = def_vyres; |
| 1507 | var->rotate = def_rotate; |
| 1508 | var->bits_per_pixel = fbdev->panel->bpp; |
| 1509 | |
| 1510 | set_fb_var(info, var); |
Sergio Aguirre | 03bb2b4 | 2009-10-05 13:31:46 -0700 | [diff] [blame] | 1511 | set_fb_fix(info, 1); |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 1512 | |
| 1513 | r = fb_alloc_cmap(&info->cmap, 16, 0); |
| 1514 | if (r != 0) |
| 1515 | dev_err(fbdev->dev, "unable to allocate color map memory\n"); |
| 1516 | |
| 1517 | return r; |
| 1518 | } |
| 1519 | |
| 1520 | /* Release the fb_info object */ |
| 1521 | static void fbinfo_cleanup(struct omapfb_device *fbdev, struct fb_info *fbi) |
| 1522 | { |
| 1523 | fb_dealloc_cmap(&fbi->cmap); |
| 1524 | } |
| 1525 | |
| 1526 | static void planes_cleanup(struct omapfb_device *fbdev) |
| 1527 | { |
| 1528 | int i; |
| 1529 | |
| 1530 | for (i = 0; i < fbdev->mem_desc.region_cnt; i++) { |
| 1531 | if (fbdev->fb_info[i] == NULL) |
| 1532 | break; |
| 1533 | fbinfo_cleanup(fbdev, fbdev->fb_info[i]); |
| 1534 | framebuffer_release(fbdev->fb_info[i]); |
| 1535 | } |
| 1536 | } |
| 1537 | |
| 1538 | static int planes_init(struct omapfb_device *fbdev) |
| 1539 | { |
| 1540 | struct fb_info *fbi; |
| 1541 | int i; |
| 1542 | int r; |
| 1543 | |
| 1544 | for (i = 0; i < fbdev->mem_desc.region_cnt; i++) { |
| 1545 | struct omapfb_plane_struct *plane; |
| 1546 | fbi = framebuffer_alloc(sizeof(struct omapfb_plane_struct), |
| 1547 | fbdev->dev); |
| 1548 | if (fbi == NULL) { |
| 1549 | dev_err(fbdev->dev, |
| 1550 | "unable to allocate memory for plane info\n"); |
| 1551 | planes_cleanup(fbdev); |
| 1552 | return -ENOMEM; |
| 1553 | } |
| 1554 | plane = fbi->par; |
| 1555 | plane->idx = i; |
| 1556 | plane->fbdev = fbdev; |
| 1557 | plane->info.mirror = def_mirror; |
| 1558 | fbdev->fb_info[i] = fbi; |
| 1559 | |
| 1560 | if ((r = fbinfo_init(fbdev, fbi)) < 0) { |
| 1561 | framebuffer_release(fbi); |
| 1562 | planes_cleanup(fbdev); |
| 1563 | return r; |
| 1564 | } |
| 1565 | plane->info.out_width = fbi->var.xres; |
| 1566 | plane->info.out_height = fbi->var.yres; |
| 1567 | } |
| 1568 | return 0; |
| 1569 | } |
| 1570 | |
| 1571 | /* |
| 1572 | * Free driver resources. Can be called to rollback an aborted initialization |
| 1573 | * sequence. |
| 1574 | */ |
| 1575 | static void omapfb_free_resources(struct omapfb_device *fbdev, int state) |
| 1576 | { |
| 1577 | int i; |
| 1578 | |
| 1579 | switch (state) { |
| 1580 | case OMAPFB_ACTIVE: |
| 1581 | for (i = 0; i < fbdev->mem_desc.region_cnt; i++) |
| 1582 | unregister_framebuffer(fbdev->fb_info[i]); |
| 1583 | case 7: |
| 1584 | omapfb_unregister_sysfs(fbdev); |
| 1585 | case 6: |
| 1586 | fbdev->panel->disable(fbdev->panel); |
| 1587 | case 5: |
| 1588 | omapfb_set_update_mode(fbdev, OMAPFB_UPDATE_DISABLED); |
| 1589 | case 4: |
| 1590 | planes_cleanup(fbdev); |
| 1591 | case 3: |
| 1592 | ctrl_cleanup(fbdev); |
| 1593 | case 2: |
| 1594 | fbdev->panel->cleanup(fbdev->panel); |
| 1595 | case 1: |
| 1596 | dev_set_drvdata(fbdev->dev, NULL); |
| 1597 | kfree(fbdev); |
| 1598 | case 0: |
| 1599 | /* nothing to free */ |
| 1600 | break; |
| 1601 | default: |
| 1602 | BUG(); |
| 1603 | } |
| 1604 | } |
| 1605 | |
| 1606 | static int omapfb_find_ctrl(struct omapfb_device *fbdev) |
| 1607 | { |
| 1608 | struct omapfb_platform_data *conf; |
| 1609 | char name[17]; |
| 1610 | int i; |
| 1611 | |
| 1612 | conf = fbdev->dev->platform_data; |
| 1613 | |
| 1614 | fbdev->ctrl = NULL; |
| 1615 | |
| 1616 | strncpy(name, conf->lcd.ctrl_name, sizeof(name) - 1); |
| 1617 | name[sizeof(name) - 1] = '\0'; |
| 1618 | |
| 1619 | if (strcmp(name, "internal") == 0) { |
| 1620 | fbdev->ctrl = fbdev->int_ctrl; |
| 1621 | return 0; |
| 1622 | } |
| 1623 | |
| 1624 | for (i = 0; i < ARRAY_SIZE(ctrls); i++) { |
| 1625 | dev_dbg(fbdev->dev, "ctrl %s\n", ctrls[i]->name); |
| 1626 | if (strcmp(ctrls[i]->name, name) == 0) { |
| 1627 | fbdev->ctrl = ctrls[i]; |
| 1628 | break; |
| 1629 | } |
| 1630 | } |
| 1631 | |
| 1632 | if (fbdev->ctrl == NULL) { |
| 1633 | dev_dbg(fbdev->dev, "ctrl %s not supported\n", name); |
| 1634 | return -1; |
| 1635 | } |
| 1636 | |
| 1637 | return 0; |
| 1638 | } |
| 1639 | |
| 1640 | static void check_required_callbacks(struct omapfb_device *fbdev) |
| 1641 | { |
| 1642 | #define _C(x) (fbdev->ctrl->x != NULL) |
| 1643 | #define _P(x) (fbdev->panel->x != NULL) |
| 1644 | BUG_ON(fbdev->ctrl == NULL || fbdev->panel == NULL); |
| 1645 | BUG_ON(!(_C(init) && _C(cleanup) && _C(get_caps) && |
| 1646 | _C(set_update_mode) && _C(setup_plane) && _C(enable_plane) && |
| 1647 | _P(init) && _P(cleanup) && _P(enable) && _P(disable) && |
| 1648 | _P(get_caps))); |
| 1649 | #undef _P |
| 1650 | #undef _C |
| 1651 | } |
| 1652 | |
| 1653 | /* |
| 1654 | * Called by LDM binding to probe and attach a new device. |
| 1655 | * Initialization sequence: |
| 1656 | * 1. allocate system omapfb_device structure |
| 1657 | * 2. select controller type according to platform configuration |
| 1658 | * init LCD panel |
| 1659 | * 3. init LCD controller and LCD DMA |
| 1660 | * 4. init system fb_info structure for all planes |
| 1661 | * 5. setup video mode for first plane and enable it |
| 1662 | * 6. enable LCD panel |
| 1663 | * 7. register sysfs attributes |
| 1664 | * OMAPFB_ACTIVE: register system fb_info structure for all planes |
| 1665 | */ |
| 1666 | static int omapfb_do_probe(struct platform_device *pdev, |
| 1667 | struct lcd_panel *panel) |
| 1668 | { |
| 1669 | struct omapfb_device *fbdev = NULL; |
| 1670 | int init_state; |
| 1671 | unsigned long phz, hhz, vhz; |
| 1672 | unsigned long vram; |
| 1673 | int i; |
| 1674 | int r = 0; |
| 1675 | |
| 1676 | init_state = 0; |
| 1677 | |
| 1678 | if (pdev->num_resources != 0) { |
| 1679 | dev_err(&pdev->dev, "probed for an unknown device\n"); |
| 1680 | r = -ENODEV; |
| 1681 | goto cleanup; |
| 1682 | } |
| 1683 | |
| 1684 | if (pdev->dev.platform_data == NULL) { |
| 1685 | dev_err(&pdev->dev, "missing platform data\n"); |
| 1686 | r = -ENOENT; |
| 1687 | goto cleanup; |
| 1688 | } |
| 1689 | |
| 1690 | fbdev = kzalloc(sizeof(struct omapfb_device), GFP_KERNEL); |
| 1691 | if (fbdev == NULL) { |
| 1692 | dev_err(&pdev->dev, |
| 1693 | "unable to allocate memory for device info\n"); |
| 1694 | r = -ENOMEM; |
| 1695 | goto cleanup; |
| 1696 | } |
| 1697 | init_state++; |
| 1698 | |
| 1699 | fbdev->dev = &pdev->dev; |
| 1700 | fbdev->panel = panel; |
Tomi Valkeinen | f778a12 | 2009-12-16 13:18:07 +0200 | [diff] [blame] | 1701 | fbdev->dssdev = &omapdss_device; |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 1702 | platform_set_drvdata(pdev, fbdev); |
| 1703 | |
| 1704 | mutex_init(&fbdev->rqueue_mutex); |
| 1705 | |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 1706 | fbdev->int_ctrl = &omap1_int_ctrl; |
| 1707 | #ifdef CONFIG_FB_OMAP_LCDC_EXTERNAL |
| 1708 | fbdev->ext_if = &omap1_ext_if; |
| 1709 | #endif |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 1710 | if (omapfb_find_ctrl(fbdev) < 0) { |
| 1711 | dev_err(fbdev->dev, |
| 1712 | "LCD controller not found, board not supported\n"); |
| 1713 | r = -ENODEV; |
| 1714 | goto cleanup; |
| 1715 | } |
| 1716 | |
| 1717 | r = fbdev->panel->init(fbdev->panel, fbdev); |
| 1718 | if (r) |
| 1719 | goto cleanup; |
| 1720 | |
| 1721 | pr_info("omapfb: configured for panel %s\n", fbdev->panel->name); |
| 1722 | |
arun c | 5910d35 | 2009-09-22 16:46:59 -0700 | [diff] [blame] | 1723 | def_vxres = def_vxres ? def_vxres : fbdev->panel->x_res; |
| 1724 | def_vyres = def_vyres ? def_vyres : fbdev->panel->y_res; |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 1725 | |
| 1726 | init_state++; |
| 1727 | |
| 1728 | r = ctrl_init(fbdev); |
| 1729 | if (r) |
| 1730 | goto cleanup; |
| 1731 | if (fbdev->ctrl->mmap != NULL) |
| 1732 | omapfb_ops.fb_mmap = omapfb_mmap; |
| 1733 | init_state++; |
| 1734 | |
| 1735 | check_required_callbacks(fbdev); |
| 1736 | |
| 1737 | r = planes_init(fbdev); |
| 1738 | if (r) |
| 1739 | goto cleanup; |
| 1740 | init_state++; |
| 1741 | |
| 1742 | #ifdef CONFIG_FB_OMAP_DMA_TUNE |
| 1743 | /* Set DMA priority for EMIFF access to highest */ |
Tomi Valkeinen | ae7e1f2 | 2012-01-24 11:00:54 +0200 | [diff] [blame] | 1744 | omap_set_dma_priority(0, OMAP_DMA_PORT_EMIFF, 15); |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 1745 | #endif |
| 1746 | |
| 1747 | r = ctrl_change_mode(fbdev->fb_info[0]); |
| 1748 | if (r) { |
| 1749 | dev_err(fbdev->dev, "mode setting failed\n"); |
| 1750 | goto cleanup; |
| 1751 | } |
| 1752 | |
| 1753 | /* GFX plane is enabled by default */ |
| 1754 | r = fbdev->ctrl->enable_plane(OMAPFB_PLANE_GFX, 1); |
| 1755 | if (r) |
| 1756 | goto cleanup; |
| 1757 | |
| 1758 | omapfb_set_update_mode(fbdev, manual_update ? |
| 1759 | OMAPFB_MANUAL_UPDATE : OMAPFB_AUTO_UPDATE); |
| 1760 | init_state++; |
| 1761 | |
| 1762 | r = fbdev->panel->enable(fbdev->panel); |
| 1763 | if (r) |
| 1764 | goto cleanup; |
| 1765 | init_state++; |
| 1766 | |
| 1767 | r = omapfb_register_sysfs(fbdev); |
| 1768 | if (r) |
| 1769 | goto cleanup; |
| 1770 | init_state++; |
| 1771 | |
| 1772 | vram = 0; |
| 1773 | for (i = 0; i < fbdev->mem_desc.region_cnt; i++) { |
| 1774 | r = register_framebuffer(fbdev->fb_info[i]); |
| 1775 | if (r != 0) { |
| 1776 | dev_err(fbdev->dev, |
| 1777 | "registering framebuffer %d failed\n", i); |
| 1778 | goto cleanup; |
| 1779 | } |
| 1780 | vram += fbdev->mem_desc.region[i].size; |
| 1781 | } |
| 1782 | |
| 1783 | fbdev->state = OMAPFB_ACTIVE; |
| 1784 | |
| 1785 | panel = fbdev->panel; |
| 1786 | phz = panel->pixel_clock * 1000; |
| 1787 | hhz = phz * 10 / (panel->hfp + panel->x_res + panel->hbp + panel->hsw); |
| 1788 | vhz = hhz / (panel->vfp + panel->y_res + panel->vbp + panel->vsw); |
| 1789 | |
| 1790 | omapfb_dev = fbdev; |
| 1791 | |
| 1792 | pr_info("omapfb: Framebuffer initialized. Total vram %lu planes %d\n", |
| 1793 | vram, fbdev->mem_desc.region_cnt); |
| 1794 | pr_info("omapfb: Pixclock %lu kHz hfreq %lu.%lu kHz " |
| 1795 | "vfreq %lu.%lu Hz\n", |
| 1796 | phz / 1000, hhz / 10000, hhz % 10, vhz / 10, vhz % 10); |
| 1797 | |
| 1798 | return 0; |
| 1799 | |
| 1800 | cleanup: |
| 1801 | omapfb_free_resources(fbdev, init_state); |
| 1802 | |
| 1803 | return r; |
| 1804 | } |
| 1805 | |
| 1806 | static int omapfb_probe(struct platform_device *pdev) |
| 1807 | { |
Tomi Valkeinen | f778a12 | 2009-12-16 13:18:07 +0200 | [diff] [blame] | 1808 | int r; |
| 1809 | |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 1810 | BUG_ON(fbdev_pdev != NULL); |
| 1811 | |
Tomi Valkeinen | f778a12 | 2009-12-16 13:18:07 +0200 | [diff] [blame] | 1812 | r = platform_device_register(&omapdss_device); |
| 1813 | if (r) { |
| 1814 | dev_err(&pdev->dev, "can't register omapdss device\n"); |
| 1815 | return r; |
| 1816 | } |
| 1817 | |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 1818 | /* Delay actual initialization until the LCD is registered */ |
| 1819 | fbdev_pdev = pdev; |
| 1820 | if (fbdev_panel != NULL) |
| 1821 | omapfb_do_probe(fbdev_pdev, fbdev_panel); |
| 1822 | return 0; |
| 1823 | } |
| 1824 | |
| 1825 | void omapfb_register_panel(struct lcd_panel *panel) |
| 1826 | { |
| 1827 | BUG_ON(fbdev_panel != NULL); |
| 1828 | |
| 1829 | fbdev_panel = panel; |
| 1830 | if (fbdev_pdev != NULL) |
| 1831 | omapfb_do_probe(fbdev_pdev, fbdev_panel); |
| 1832 | } |
| 1833 | |
| 1834 | /* Called when the device is being detached from the driver */ |
| 1835 | static int omapfb_remove(struct platform_device *pdev) |
| 1836 | { |
| 1837 | struct omapfb_device *fbdev = platform_get_drvdata(pdev); |
| 1838 | enum omapfb_state saved_state = fbdev->state; |
| 1839 | |
| 1840 | /* FIXME: wait till completion of pending events */ |
| 1841 | |
| 1842 | fbdev->state = OMAPFB_DISABLED; |
| 1843 | omapfb_free_resources(fbdev, saved_state); |
| 1844 | |
Tomi Valkeinen | f778a12 | 2009-12-16 13:18:07 +0200 | [diff] [blame] | 1845 | platform_device_unregister(&omapdss_device); |
| 1846 | fbdev->dssdev = NULL; |
| 1847 | |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 1848 | return 0; |
| 1849 | } |
| 1850 | |
| 1851 | /* PM suspend */ |
| 1852 | static int omapfb_suspend(struct platform_device *pdev, pm_message_t mesg) |
| 1853 | { |
| 1854 | struct omapfb_device *fbdev = platform_get_drvdata(pdev); |
| 1855 | |
Jouni Hogander | b6c2b66 | 2009-09-22 16:46:58 -0700 | [diff] [blame] | 1856 | if (fbdev != NULL) |
| 1857 | omapfb_blank(FB_BLANK_POWERDOWN, fbdev->fb_info[0]); |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 1858 | return 0; |
| 1859 | } |
| 1860 | |
| 1861 | /* PM resume */ |
| 1862 | static int omapfb_resume(struct platform_device *pdev) |
| 1863 | { |
| 1864 | struct omapfb_device *fbdev = platform_get_drvdata(pdev); |
| 1865 | |
Jouni Hogander | b6c2b66 | 2009-09-22 16:46:58 -0700 | [diff] [blame] | 1866 | if (fbdev != NULL) |
| 1867 | omapfb_blank(FB_BLANK_UNBLANK, fbdev->fb_info[0]); |
Imre Deak | 8b08cf2 | 2007-07-17 04:05:54 -0700 | [diff] [blame] | 1868 | return 0; |
| 1869 | } |
| 1870 | |
| 1871 | static struct platform_driver omapfb_driver = { |
| 1872 | .probe = omapfb_probe, |
| 1873 | .remove = omapfb_remove, |
| 1874 | .suspend = omapfb_suspend, |
| 1875 | .resume = omapfb_resume, |
| 1876 | .driver = { |
| 1877 | .name = MODULE_NAME, |
| 1878 | .owner = THIS_MODULE, |
| 1879 | }, |
| 1880 | }; |
| 1881 | |
| 1882 | #ifndef MODULE |
| 1883 | |
| 1884 | /* Process kernel command line parameters */ |
| 1885 | static int __init omapfb_setup(char *options) |
| 1886 | { |
| 1887 | char *this_opt = NULL; |
| 1888 | int r = 0; |
| 1889 | |
| 1890 | pr_debug("omapfb: options %s\n", options); |
| 1891 | |
| 1892 | if (!options || !*options) |
| 1893 | return 0; |
| 1894 | |
| 1895 | while (!r && (this_opt = strsep(&options, ",")) != NULL) { |
| 1896 | if (!strncmp(this_opt, "accel", 5)) |
| 1897 | def_accel = 1; |
| 1898 | else if (!strncmp(this_opt, "vram:", 5)) { |
| 1899 | char *suffix; |
| 1900 | unsigned long vram; |
| 1901 | vram = (simple_strtoul(this_opt + 5, &suffix, 0)); |
| 1902 | switch (suffix[0]) { |
| 1903 | case '\0': |
| 1904 | break; |
| 1905 | case 'm': |
| 1906 | case 'M': |
| 1907 | vram *= 1024; |
| 1908 | /* Fall through */ |
| 1909 | case 'k': |
| 1910 | case 'K': |
| 1911 | vram *= 1024; |
| 1912 | break; |
| 1913 | default: |
| 1914 | pr_debug("omapfb: invalid vram suffix %c\n", |
| 1915 | suffix[0]); |
| 1916 | r = -1; |
| 1917 | } |
| 1918 | def_vram[def_vram_cnt++] = vram; |
| 1919 | } |
| 1920 | else if (!strncmp(this_opt, "vxres:", 6)) |
| 1921 | def_vxres = simple_strtoul(this_opt + 6, NULL, 0); |
| 1922 | else if (!strncmp(this_opt, "vyres:", 6)) |
| 1923 | def_vyres = simple_strtoul(this_opt + 6, NULL, 0); |
| 1924 | else if (!strncmp(this_opt, "rotate:", 7)) |
| 1925 | def_rotate = (simple_strtoul(this_opt + 7, NULL, 0)); |
| 1926 | else if (!strncmp(this_opt, "mirror:", 7)) |
| 1927 | def_mirror = (simple_strtoul(this_opt + 7, NULL, 0)); |
| 1928 | else if (!strncmp(this_opt, "manual_update", 13)) |
| 1929 | manual_update = 1; |
| 1930 | else { |
| 1931 | pr_debug("omapfb: invalid option\n"); |
| 1932 | r = -1; |
| 1933 | } |
| 1934 | } |
| 1935 | |
| 1936 | return r; |
| 1937 | } |
| 1938 | |
| 1939 | #endif |
| 1940 | |
| 1941 | /* Register both the driver and the device */ |
| 1942 | static int __init omapfb_init(void) |
| 1943 | { |
| 1944 | #ifndef MODULE |
| 1945 | char *option; |
| 1946 | |
| 1947 | if (fb_get_options("omapfb", &option)) |
| 1948 | return -ENODEV; |
| 1949 | omapfb_setup(option); |
| 1950 | #endif |
| 1951 | /* Register the driver with LDM */ |
| 1952 | if (platform_driver_register(&omapfb_driver)) { |
| 1953 | pr_debug("failed to register omapfb driver\n"); |
| 1954 | return -ENODEV; |
| 1955 | } |
| 1956 | |
| 1957 | return 0; |
| 1958 | } |
| 1959 | |
| 1960 | static void __exit omapfb_cleanup(void) |
| 1961 | { |
| 1962 | platform_driver_unregister(&omapfb_driver); |
| 1963 | } |
| 1964 | |
| 1965 | module_param_named(accel, def_accel, uint, 0664); |
| 1966 | module_param_array_named(vram, def_vram, ulong, &def_vram_cnt, 0664); |
| 1967 | module_param_named(vxres, def_vxres, long, 0664); |
| 1968 | module_param_named(vyres, def_vyres, long, 0664); |
| 1969 | module_param_named(rotate, def_rotate, uint, 0664); |
| 1970 | module_param_named(mirror, def_mirror, uint, 0664); |
| 1971 | module_param_named(manual_update, manual_update, bool, 0664); |
| 1972 | |
| 1973 | module_init(omapfb_init); |
| 1974 | module_exit(omapfb_cleanup); |
| 1975 | |
| 1976 | MODULE_DESCRIPTION("TI OMAP framebuffer driver"); |
| 1977 | MODULE_AUTHOR("Imre Deak <imre.deak@nokia.com>"); |
| 1978 | MODULE_LICENSE("GPL"); |