York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2008 Freescale Semiconductor, Inc. All Rights Reserved. |
| 3 | * |
| 4 | * Freescale DIU Frame Buffer device driver |
| 5 | * |
| 6 | * Authors: Hongjun Chen <hong-jun.chen@freescale.com> |
| 7 | * Paul Widmer <paul.widmer@freescale.com> |
| 8 | * Srikanth Srinivasan <srikanth.srinivasan@freescale.com> |
| 9 | * York Sun <yorksun@freescale.com> |
| 10 | * |
| 11 | * Based on imxfb.c Copyright (C) 2004 S.Hauer, Pengutronix |
| 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 | */ |
| 19 | |
| 20 | #include <linux/module.h> |
| 21 | #include <linux/kernel.h> |
| 22 | #include <linux/errno.h> |
| 23 | #include <linux/string.h> |
| 24 | #include <linux/slab.h> |
| 25 | #include <linux/fb.h> |
| 26 | #include <linux/init.h> |
| 27 | #include <linux/dma-mapping.h> |
| 28 | #include <linux/platform_device.h> |
| 29 | #include <linux/interrupt.h> |
| 30 | #include <linux/clk.h> |
| 31 | #include <linux/uaccess.h> |
| 32 | #include <linux/vmalloc.h> |
Timur Tabi | b715f9f | 2011-09-28 16:19:48 -0500 | [diff] [blame] | 33 | #include <linux/spinlock.h> |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 34 | |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 35 | #include <sysdev/fsl_soc.h> |
Anatolij Gustschin | 0814a97 | 2010-07-23 04:00:36 +0000 | [diff] [blame] | 36 | #include <linux/fsl-diu-fb.h> |
Anatolij Gustschin | 8b856f0 | 2010-07-23 04:00:39 +0000 | [diff] [blame] | 37 | #include "edid.h" |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 38 | |
Timur Tabi | ddd3d90 | 2011-12-02 17:03:27 -0600 | [diff] [blame] | 39 | #define NUM_AOIS 5 /* 1 for plane 0, 2 for planes 1 & 2 each */ |
Timur Tabi | b715f9f | 2011-09-28 16:19:48 -0500 | [diff] [blame] | 40 | |
| 41 | /* HW cursor parameters */ |
| 42 | #define MAX_CURS 32 |
| 43 | |
| 44 | /* INT_STATUS/INT_MASK field descriptions */ |
| 45 | #define INT_VSYNC 0x01 /* Vsync interrupt */ |
| 46 | #define INT_VSYNC_WB 0x02 /* Vsync interrupt for write back operation */ |
| 47 | #define INT_UNDRUN 0x04 /* Under run exception interrupt */ |
| 48 | #define INT_PARERR 0x08 /* Display parameters error interrupt */ |
| 49 | #define INT_LS_BF_VS 0x10 /* Lines before vsync. interrupt */ |
| 50 | |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 51 | /* |
Timur Tabi | 63cf8df | 2011-09-15 16:44:51 -0500 | [diff] [blame] | 52 | * List of supported video modes |
| 53 | * |
Timur Tabi | 760af8f | 2011-09-28 16:19:50 -0500 | [diff] [blame] | 54 | * The first entry is the default video mode. The remain entries are in |
| 55 | * order if increasing resolution and frequency. The 320x240-60 mode is |
| 56 | * the initial AOI for the second and third planes. |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 57 | */ |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 58 | static struct fb_videomode __devinitdata fsl_diu_mode_db[] = { |
| 59 | { |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 60 | .refresh = 60, |
| 61 | .xres = 1024, |
| 62 | .yres = 768, |
| 63 | .pixclock = 15385, |
| 64 | .left_margin = 160, |
| 65 | .right_margin = 24, |
| 66 | .upper_margin = 29, |
| 67 | .lower_margin = 3, |
| 68 | .hsync_len = 136, |
| 69 | .vsync_len = 6, |
| 70 | .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, |
| 71 | .vmode = FB_VMODE_NONINTERLACED |
| 72 | }, |
| 73 | { |
Timur Tabi | 760af8f | 2011-09-28 16:19:50 -0500 | [diff] [blame] | 74 | .refresh = 60, |
| 75 | .xres = 320, |
| 76 | .yres = 240, |
| 77 | .pixclock = 79440, |
| 78 | .left_margin = 16, |
| 79 | .right_margin = 16, |
| 80 | .upper_margin = 16, |
| 81 | .lower_margin = 5, |
| 82 | .hsync_len = 48, |
| 83 | .vsync_len = 1, |
| 84 | .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, |
| 85 | .vmode = FB_VMODE_NONINTERLACED |
| 86 | }, |
| 87 | { |
| 88 | .refresh = 60, |
| 89 | .xres = 640, |
| 90 | .yres = 480, |
| 91 | .pixclock = 39722, |
| 92 | .left_margin = 48, |
| 93 | .right_margin = 16, |
| 94 | .upper_margin = 33, |
| 95 | .lower_margin = 10, |
| 96 | .hsync_len = 96, |
| 97 | .vsync_len = 2, |
| 98 | .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, |
| 99 | .vmode = FB_VMODE_NONINTERLACED |
| 100 | }, |
| 101 | { |
| 102 | .refresh = 72, |
| 103 | .xres = 640, |
| 104 | .yres = 480, |
| 105 | .pixclock = 32052, |
| 106 | .left_margin = 128, |
| 107 | .right_margin = 24, |
| 108 | .upper_margin = 28, |
| 109 | .lower_margin = 9, |
| 110 | .hsync_len = 40, |
| 111 | .vsync_len = 3, |
| 112 | .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, |
| 113 | .vmode = FB_VMODE_NONINTERLACED |
| 114 | }, |
| 115 | { |
| 116 | .refresh = 75, |
| 117 | .xres = 640, |
| 118 | .yres = 480, |
| 119 | .pixclock = 31747, |
| 120 | .left_margin = 120, |
| 121 | .right_margin = 16, |
| 122 | .upper_margin = 16, |
| 123 | .lower_margin = 1, |
| 124 | .hsync_len = 64, |
| 125 | .vsync_len = 3, |
| 126 | .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, |
| 127 | .vmode = FB_VMODE_NONINTERLACED |
| 128 | }, |
| 129 | { |
| 130 | .refresh = 90, |
| 131 | .xres = 640, |
| 132 | .yres = 480, |
| 133 | .pixclock = 25057, |
| 134 | .left_margin = 120, |
| 135 | .right_margin = 32, |
| 136 | .upper_margin = 14, |
| 137 | .lower_margin = 25, |
| 138 | .hsync_len = 40, |
| 139 | .vsync_len = 14, |
| 140 | .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, |
| 141 | .vmode = FB_VMODE_NONINTERLACED |
| 142 | }, |
| 143 | { |
| 144 | .refresh = 100, |
| 145 | .xres = 640, |
| 146 | .yres = 480, |
| 147 | .pixclock = 22272, |
| 148 | .left_margin = 48, |
| 149 | .right_margin = 32, |
| 150 | .upper_margin = 17, |
| 151 | .lower_margin = 22, |
| 152 | .hsync_len = 128, |
| 153 | .vsync_len = 12, |
| 154 | .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, |
| 155 | .vmode = FB_VMODE_NONINTERLACED |
| 156 | }, |
| 157 | { |
| 158 | .refresh = 60, |
| 159 | .xres = 800, |
| 160 | .yres = 480, |
| 161 | .pixclock = 33805, |
| 162 | .left_margin = 96, |
| 163 | .right_margin = 24, |
| 164 | .upper_margin = 10, |
| 165 | .lower_margin = 3, |
| 166 | .hsync_len = 72, |
| 167 | .vsync_len = 7, |
| 168 | .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, |
| 169 | .vmode = FB_VMODE_NONINTERLACED |
| 170 | }, |
| 171 | { |
| 172 | .refresh = 60, |
| 173 | .xres = 800, |
| 174 | .yres = 600, |
| 175 | .pixclock = 25000, |
| 176 | .left_margin = 88, |
| 177 | .right_margin = 40, |
| 178 | .upper_margin = 23, |
| 179 | .lower_margin = 1, |
| 180 | .hsync_len = 128, |
| 181 | .vsync_len = 4, |
| 182 | .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, |
| 183 | .vmode = FB_VMODE_NONINTERLACED |
| 184 | }, |
| 185 | { |
| 186 | .refresh = 60, |
| 187 | .xres = 854, |
| 188 | .yres = 480, |
| 189 | .pixclock = 31518, |
| 190 | .left_margin = 104, |
| 191 | .right_margin = 16, |
| 192 | .upper_margin = 13, |
| 193 | .lower_margin = 1, |
| 194 | .hsync_len = 88, |
| 195 | .vsync_len = 3, |
| 196 | .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, |
| 197 | .vmode = FB_VMODE_NONINTERLACED |
| 198 | }, |
| 199 | { |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 200 | .refresh = 70, |
| 201 | .xres = 1024, |
| 202 | .yres = 768, |
| 203 | .pixclock = 16886, |
| 204 | .left_margin = 3, |
| 205 | .right_margin = 3, |
| 206 | .upper_margin = 2, |
| 207 | .lower_margin = 2, |
| 208 | .hsync_len = 40, |
| 209 | .vsync_len = 18, |
| 210 | .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, |
| 211 | .vmode = FB_VMODE_NONINTERLACED |
| 212 | }, |
| 213 | { |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 214 | .refresh = 75, |
| 215 | .xres = 1024, |
| 216 | .yres = 768, |
| 217 | .pixclock = 15009, |
| 218 | .left_margin = 3, |
| 219 | .right_margin = 3, |
| 220 | .upper_margin = 2, |
| 221 | .lower_margin = 2, |
| 222 | .hsync_len = 80, |
| 223 | .vsync_len = 32, |
| 224 | .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, |
| 225 | .vmode = FB_VMODE_NONINTERLACED |
| 226 | }, |
| 227 | { |
Timur Tabi | 760af8f | 2011-09-28 16:19:50 -0500 | [diff] [blame] | 228 | .refresh = 60, |
| 229 | .xres = 1280, |
| 230 | .yres = 480, |
| 231 | .pixclock = 18939, |
| 232 | .left_margin = 353, |
| 233 | .right_margin = 47, |
| 234 | .upper_margin = 39, |
| 235 | .lower_margin = 4, |
| 236 | .hsync_len = 8, |
| 237 | .vsync_len = 2, |
| 238 | .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, |
| 239 | .vmode = FB_VMODE_NONINTERLACED |
| 240 | }, |
| 241 | { |
| 242 | .refresh = 60, |
| 243 | .xres = 1280, |
| 244 | .yres = 720, |
| 245 | .pixclock = 13426, |
| 246 | .left_margin = 192, |
| 247 | .right_margin = 64, |
| 248 | .upper_margin = 22, |
| 249 | .lower_margin = 1, |
| 250 | .hsync_len = 136, |
| 251 | .vsync_len = 3, |
| 252 | .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, |
| 253 | .vmode = FB_VMODE_NONINTERLACED |
| 254 | }, |
| 255 | { |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 256 | .refresh = 60, |
| 257 | .xres = 1280, |
| 258 | .yres = 1024, |
| 259 | .pixclock = 9375, |
| 260 | .left_margin = 38, |
| 261 | .right_margin = 128, |
| 262 | .upper_margin = 2, |
| 263 | .lower_margin = 7, |
| 264 | .hsync_len = 216, |
| 265 | .vsync_len = 37, |
| 266 | .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, |
| 267 | .vmode = FB_VMODE_NONINTERLACED |
| 268 | }, |
| 269 | { |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 270 | .refresh = 70, |
| 271 | .xres = 1280, |
| 272 | .yres = 1024, |
| 273 | .pixclock = 9380, |
| 274 | .left_margin = 6, |
| 275 | .right_margin = 6, |
| 276 | .upper_margin = 4, |
| 277 | .lower_margin = 4, |
| 278 | .hsync_len = 60, |
| 279 | .vsync_len = 94, |
| 280 | .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, |
| 281 | .vmode = FB_VMODE_NONINTERLACED |
| 282 | }, |
| 283 | { |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 284 | .refresh = 75, |
| 285 | .xres = 1280, |
| 286 | .yres = 1024, |
| 287 | .pixclock = 9380, |
| 288 | .left_margin = 6, |
| 289 | .right_margin = 6, |
| 290 | .upper_margin = 4, |
| 291 | .lower_margin = 4, |
| 292 | .hsync_len = 60, |
| 293 | .vsync_len = 15, |
| 294 | .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, |
| 295 | .vmode = FB_VMODE_NONINTERLACED |
| 296 | }, |
| 297 | { |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 298 | .refresh = 60, |
Timur Tabi | 760af8f | 2011-09-28 16:19:50 -0500 | [diff] [blame] | 299 | .xres = 1920, |
| 300 | .yres = 1080, |
| 301 | .pixclock = 5787, |
| 302 | .left_margin = 328, |
| 303 | .right_margin = 120, |
| 304 | .upper_margin = 34, |
| 305 | .lower_margin = 1, |
| 306 | .hsync_len = 208, |
| 307 | .vsync_len = 3, |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 308 | .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, |
| 309 | .vmode = FB_VMODE_NONINTERLACED |
| 310 | }, |
| 311 | }; |
| 312 | |
Timur Tabi | 760af8f | 2011-09-28 16:19:50 -0500 | [diff] [blame] | 313 | static char *fb_mode; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 314 | static unsigned long default_bpp = 32; |
Timur Tabi | 7653aaa | 2011-07-09 15:38:14 -0500 | [diff] [blame] | 315 | static enum fsl_diu_monitor_port monitor_port; |
| 316 | static char *monitor_string; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 317 | |
| 318 | #if defined(CONFIG_NOT_COHERENT_CACHE) |
| 319 | static u8 *coherence_data; |
| 320 | static size_t coherence_data_size; |
| 321 | static unsigned int d_cache_line_size; |
| 322 | #endif |
| 323 | |
| 324 | static DEFINE_SPINLOCK(diu_lock); |
| 325 | |
Timur Tabi | 2572df9 | 2011-09-28 16:19:51 -0500 | [diff] [blame] | 326 | enum mfb_index { |
| 327 | PLANE0 = 0, /* Plane 0, only one AOI that fills the screen */ |
| 328 | PLANE1_AOI0, /* Plane 1, first AOI */ |
| 329 | PLANE1_AOI1, /* Plane 1, second AOI */ |
| 330 | PLANE2_AOI0, /* Plane 2, first AOI */ |
| 331 | PLANE2_AOI1, /* Plane 2, second AOI */ |
| 332 | }; |
| 333 | |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 334 | struct mfb_info { |
Timur Tabi | 2572df9 | 2011-09-28 16:19:51 -0500 | [diff] [blame] | 335 | enum mfb_index index; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 336 | char *id; |
| 337 | int registered; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 338 | unsigned long pseudo_palette[16]; |
| 339 | struct diu_ad *ad; |
| 340 | int cursor_reset; |
| 341 | unsigned char g_alpha; |
| 342 | unsigned int count; |
| 343 | int x_aoi_d; /* aoi display x offset to physical screen */ |
| 344 | int y_aoi_d; /* aoi display y offset to physical screen */ |
| 345 | struct fsl_diu_data *parent; |
Anatolij Gustschin | 8b856f0 | 2010-07-23 04:00:39 +0000 | [diff] [blame] | 346 | u8 *edid_data; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 347 | }; |
| 348 | |
Timur Tabi | ddd3d90 | 2011-12-02 17:03:27 -0600 | [diff] [blame] | 349 | /** |
| 350 | * struct fsl_diu_data - per-DIU data structure |
| 351 | * @dma_addr: DMA address of this structure |
| 352 | * @fsl_diu_info: fb_info objects, one per AOI |
| 353 | * @dev_attr: sysfs structure |
| 354 | * @irq: IRQ |
| 355 | * @fb_enabled: TRUE if the DIU is enabled, FALSE if not |
| 356 | * @monitor_port: the monitor port this DIU is connected to |
| 357 | * @diu_reg: pointer to the DIU hardware registers |
| 358 | * @reg_lock: spinlock for register access |
| 359 | * @dummy_aoi: video buffer for the 4x4 32-bit dummy AOI |
| 360 | * dummy_ad: DIU Area Descriptor for the dummy AOI |
| 361 | * @ad[]: Area Descriptors for each real AOI |
| 362 | * @gamma: gamma color table |
| 363 | * @cursor: hardware cursor data |
| 364 | * |
| 365 | * This data structure must be allocated with 32-byte alignment, so that the |
| 366 | * internal fields can be aligned properly. |
| 367 | */ |
| 368 | struct fsl_diu_data { |
| 369 | dma_addr_t dma_addr; |
| 370 | struct fb_info fsl_diu_info[NUM_AOIS]; |
| 371 | struct mfb_info mfb[NUM_AOIS]; |
| 372 | struct device_attribute dev_attr; |
| 373 | unsigned int irq; |
| 374 | int fb_enabled; |
| 375 | enum fsl_diu_monitor_port monitor_port; |
| 376 | struct diu __iomem *diu_reg; |
| 377 | spinlock_t reg_lock; |
| 378 | u8 dummy_aoi[4 * 4 * 4]; |
| 379 | struct diu_ad dummy_ad __aligned(8); |
| 380 | struct diu_ad ad[NUM_AOIS] __aligned(8); |
| 381 | u8 gamma[256 * 3] __aligned(32); |
| 382 | u8 cursor[MAX_CURS * MAX_CURS * 2] __aligned(32); |
| 383 | } __aligned(32); |
| 384 | |
| 385 | /* Determine the DMA address of a member of the fsl_diu_data structure */ |
| 386 | #define DMA_ADDR(p, f) ((p)->dma_addr + offsetof(struct fsl_diu_data, f)) |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 387 | |
| 388 | static struct mfb_info mfb_template[] = { |
Timur Tabi | 2572df9 | 2011-09-28 16:19:51 -0500 | [diff] [blame] | 389 | { |
| 390 | .index = PLANE0, |
Timur Tabi | 4a85dc8b | 2011-09-15 16:44:46 -0500 | [diff] [blame] | 391 | .id = "Panel0", |
| 392 | .registered = 0, |
| 393 | .count = 0, |
| 394 | .x_aoi_d = 0, |
| 395 | .y_aoi_d = 0, |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 396 | }, |
Timur Tabi | 2572df9 | 2011-09-28 16:19:51 -0500 | [diff] [blame] | 397 | { |
| 398 | .index = PLANE1_AOI0, |
Timur Tabi | 4a85dc8b | 2011-09-15 16:44:46 -0500 | [diff] [blame] | 399 | .id = "Panel1 AOI0", |
| 400 | .registered = 0, |
| 401 | .g_alpha = 0xff, |
| 402 | .count = 0, |
| 403 | .x_aoi_d = 0, |
| 404 | .y_aoi_d = 0, |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 405 | }, |
Timur Tabi | 2572df9 | 2011-09-28 16:19:51 -0500 | [diff] [blame] | 406 | { |
| 407 | .index = PLANE1_AOI1, |
Timur Tabi | 4a85dc8b | 2011-09-15 16:44:46 -0500 | [diff] [blame] | 408 | .id = "Panel1 AOI1", |
| 409 | .registered = 0, |
| 410 | .g_alpha = 0xff, |
| 411 | .count = 0, |
| 412 | .x_aoi_d = 0, |
| 413 | .y_aoi_d = 480, |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 414 | }, |
Timur Tabi | 2572df9 | 2011-09-28 16:19:51 -0500 | [diff] [blame] | 415 | { |
| 416 | .index = PLANE2_AOI0, |
Timur Tabi | 4a85dc8b | 2011-09-15 16:44:46 -0500 | [diff] [blame] | 417 | .id = "Panel2 AOI0", |
| 418 | .registered = 0, |
| 419 | .g_alpha = 0xff, |
| 420 | .count = 0, |
| 421 | .x_aoi_d = 640, |
| 422 | .y_aoi_d = 0, |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 423 | }, |
Timur Tabi | 2572df9 | 2011-09-28 16:19:51 -0500 | [diff] [blame] | 424 | { |
| 425 | .index = PLANE2_AOI1, |
Timur Tabi | 4a85dc8b | 2011-09-15 16:44:46 -0500 | [diff] [blame] | 426 | .id = "Panel2 AOI1", |
| 427 | .registered = 0, |
| 428 | .g_alpha = 0xff, |
| 429 | .count = 0, |
| 430 | .x_aoi_d = 640, |
| 431 | .y_aoi_d = 480, |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 432 | }, |
| 433 | }; |
| 434 | |
Timur Tabi | 6b51d51 | 2008-07-23 21:31:39 -0700 | [diff] [blame] | 435 | /** |
Timur Tabi | 7653aaa | 2011-07-09 15:38:14 -0500 | [diff] [blame] | 436 | * fsl_diu_name_to_port - convert a port name to a monitor port enum |
| 437 | * |
| 438 | * Takes the name of a monitor port ("dvi", "lvds", or "dlvds") and returns |
| 439 | * the enum fsl_diu_monitor_port that corresponds to that string. |
| 440 | * |
| 441 | * For compatibility with older versions, a number ("0", "1", or "2") is also |
| 442 | * supported. |
| 443 | * |
| 444 | * If the string is unknown, DVI is assumed. |
| 445 | * |
| 446 | * If the particular port is not supported by the platform, another port |
| 447 | * (platform-specific) is chosen instead. |
| 448 | */ |
| 449 | static enum fsl_diu_monitor_port fsl_diu_name_to_port(const char *s) |
| 450 | { |
| 451 | enum fsl_diu_monitor_port port = FSL_DIU_PORT_DVI; |
| 452 | unsigned long val; |
| 453 | |
| 454 | if (s) { |
| 455 | if (!strict_strtoul(s, 10, &val) && (val <= 2)) |
| 456 | port = (enum fsl_diu_monitor_port) val; |
| 457 | else if (strncmp(s, "lvds", 4) == 0) |
| 458 | port = FSL_DIU_PORT_LVDS; |
| 459 | else if (strncmp(s, "dlvds", 5) == 0) |
| 460 | port = FSL_DIU_PORT_DLVDS; |
| 461 | } |
| 462 | |
| 463 | return diu_ops.valid_monitor_port(port); |
| 464 | } |
| 465 | |
| 466 | /** |
Timur Tabi | 6b51d51 | 2008-07-23 21:31:39 -0700 | [diff] [blame] | 467 | * fsl_diu_alloc - allocate memory for the DIU |
| 468 | * @size: number of bytes to allocate |
| 469 | * @param: returned physical address of memory |
| 470 | * |
| 471 | * This function allocates a physically-contiguous block of memory. |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 472 | */ |
Timur Tabi | 6b51d51 | 2008-07-23 21:31:39 -0700 | [diff] [blame] | 473 | static void *fsl_diu_alloc(size_t size, phys_addr_t *phys) |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 474 | { |
| 475 | void *virt; |
| 476 | |
Timur Tabi | 6b51d51 | 2008-07-23 21:31:39 -0700 | [diff] [blame] | 477 | virt = alloc_pages_exact(size, GFP_DMA | __GFP_ZERO); |
Timur Tabi | 154152a | 2011-09-15 16:44:47 -0500 | [diff] [blame] | 478 | if (virt) |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 479 | *phys = virt_to_phys(virt); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 480 | |
| 481 | return virt; |
| 482 | } |
| 483 | |
Timur Tabi | 6b51d51 | 2008-07-23 21:31:39 -0700 | [diff] [blame] | 484 | /** |
| 485 | * fsl_diu_free - release DIU memory |
| 486 | * @virt: pointer returned by fsl_diu_alloc() |
| 487 | * @size: number of bytes allocated by fsl_diu_alloc() |
| 488 | * |
| 489 | * This function releases memory allocated by fsl_diu_alloc(). |
| 490 | */ |
| 491 | static void fsl_diu_free(void *virt, size_t size) |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 492 | { |
Timur Tabi | 6b51d51 | 2008-07-23 21:31:39 -0700 | [diff] [blame] | 493 | if (virt && size) |
| 494 | free_pages_exact(virt, size); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 495 | } |
| 496 | |
Anatolij Gustschin | 0d9dab3 | 2010-07-23 04:00:35 +0000 | [diff] [blame] | 497 | /* |
| 498 | * Workaround for failed writing desc register of planes. |
| 499 | * Needed with MPC5121 DIU rev 2.0 silicon. |
| 500 | */ |
| 501 | void wr_reg_wa(u32 *reg, u32 val) |
| 502 | { |
| 503 | do { |
| 504 | out_be32(reg, val); |
| 505 | } while (in_be32(reg) != val); |
| 506 | } |
| 507 | |
Timur Tabi | 7e47c21 | 2011-09-28 16:19:52 -0500 | [diff] [blame] | 508 | static void fsl_diu_enable_panel(struct fb_info *info) |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 509 | { |
| 510 | struct mfb_info *pmfbi, *cmfbi, *mfbi = info->par; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 511 | struct diu_ad *ad = mfbi->ad; |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 512 | struct fsl_diu_data *data = mfbi->parent; |
| 513 | struct diu __iomem *hw = data->diu_reg; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 514 | |
Timur Tabi | 7e47c21 | 2011-09-28 16:19:52 -0500 | [diff] [blame] | 515 | switch (mfbi->index) { |
| 516 | case PLANE0: |
| 517 | if (hw->desc[0] != ad->paddr) |
| 518 | wr_reg_wa(&hw->desc[0], ad->paddr); |
| 519 | break; |
| 520 | case PLANE1_AOI0: |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 521 | cmfbi = &data->mfb[2]; |
Timur Tabi | 7e47c21 | 2011-09-28 16:19:52 -0500 | [diff] [blame] | 522 | if (hw->desc[1] != ad->paddr) { /* AOI0 closed */ |
| 523 | if (cmfbi->count > 0) /* AOI1 open */ |
| 524 | ad->next_ad = |
| 525 | cpu_to_le32(cmfbi->ad->paddr); |
| 526 | else |
| 527 | ad->next_ad = 0; |
| 528 | wr_reg_wa(&hw->desc[1], ad->paddr); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 529 | } |
Timur Tabi | 7e47c21 | 2011-09-28 16:19:52 -0500 | [diff] [blame] | 530 | break; |
| 531 | case PLANE2_AOI0: |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 532 | cmfbi = &data->mfb[4]; |
Timur Tabi | 7e47c21 | 2011-09-28 16:19:52 -0500 | [diff] [blame] | 533 | if (hw->desc[2] != ad->paddr) { /* AOI0 closed */ |
| 534 | if (cmfbi->count > 0) /* AOI1 open */ |
| 535 | ad->next_ad = |
| 536 | cpu_to_le32(cmfbi->ad->paddr); |
| 537 | else |
| 538 | ad->next_ad = 0; |
| 539 | wr_reg_wa(&hw->desc[2], ad->paddr); |
| 540 | } |
| 541 | break; |
| 542 | case PLANE1_AOI1: |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 543 | pmfbi = &data->mfb[1]; |
Timur Tabi | 7e47c21 | 2011-09-28 16:19:52 -0500 | [diff] [blame] | 544 | ad->next_ad = 0; |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 545 | if (hw->desc[1] == data->dummy_ad.paddr) |
Timur Tabi | 7e47c21 | 2011-09-28 16:19:52 -0500 | [diff] [blame] | 546 | wr_reg_wa(&hw->desc[1], ad->paddr); |
| 547 | else /* AOI0 open */ |
| 548 | pmfbi->ad->next_ad = cpu_to_le32(ad->paddr); |
| 549 | break; |
| 550 | case PLANE2_AOI1: |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 551 | pmfbi = &data->mfb[3]; |
Timur Tabi | 7e47c21 | 2011-09-28 16:19:52 -0500 | [diff] [blame] | 552 | ad->next_ad = 0; |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 553 | if (hw->desc[2] == data->dummy_ad.paddr) |
Timur Tabi | 7e47c21 | 2011-09-28 16:19:52 -0500 | [diff] [blame] | 554 | wr_reg_wa(&hw->desc[2], ad->paddr); |
| 555 | else /* AOI0 was open */ |
| 556 | pmfbi->ad->next_ad = cpu_to_le32(ad->paddr); |
| 557 | break; |
| 558 | } |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 559 | } |
| 560 | |
Timur Tabi | 2572df9 | 2011-09-28 16:19:51 -0500 | [diff] [blame] | 561 | static void fsl_diu_disable_panel(struct fb_info *info) |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 562 | { |
| 563 | struct mfb_info *pmfbi, *cmfbi, *mfbi = info->par; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 564 | struct diu_ad *ad = mfbi->ad; |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 565 | struct fsl_diu_data *data = mfbi->parent; |
| 566 | struct diu __iomem *hw = data->diu_reg; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 567 | |
| 568 | switch (mfbi->index) { |
Timur Tabi | 2572df9 | 2011-09-28 16:19:51 -0500 | [diff] [blame] | 569 | case PLANE0: |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 570 | if (hw->desc[0] != data->dummy_ad.paddr) |
| 571 | wr_reg_wa(&hw->desc[0], data->dummy_ad.paddr); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 572 | break; |
Timur Tabi | 2572df9 | 2011-09-28 16:19:51 -0500 | [diff] [blame] | 573 | case PLANE1_AOI0: |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 574 | cmfbi = &data->mfb[2]; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 575 | if (cmfbi->count > 0) /* AOI1 is open */ |
Anatolij Gustschin | 0d9dab3 | 2010-07-23 04:00:35 +0000 | [diff] [blame] | 576 | wr_reg_wa(&hw->desc[1], cmfbi->ad->paddr); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 577 | /* move AOI1 to the first */ |
| 578 | else /* AOI1 was closed */ |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 579 | wr_reg_wa(&hw->desc[1], data->dummy_ad.paddr); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 580 | /* close AOI 0 */ |
| 581 | break; |
Timur Tabi | 2572df9 | 2011-09-28 16:19:51 -0500 | [diff] [blame] | 582 | case PLANE2_AOI0: |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 583 | cmfbi = &data->mfb[4]; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 584 | if (cmfbi->count > 0) /* AOI1 is open */ |
Anatolij Gustschin | 0d9dab3 | 2010-07-23 04:00:35 +0000 | [diff] [blame] | 585 | wr_reg_wa(&hw->desc[2], cmfbi->ad->paddr); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 586 | /* move AOI1 to the first */ |
| 587 | else /* AOI1 was closed */ |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 588 | wr_reg_wa(&hw->desc[2], data->dummy_ad.paddr); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 589 | /* close AOI 0 */ |
| 590 | break; |
Timur Tabi | 2572df9 | 2011-09-28 16:19:51 -0500 | [diff] [blame] | 591 | case PLANE1_AOI1: |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 592 | pmfbi = &data->mfb[1]; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 593 | if (hw->desc[1] != ad->paddr) { |
| 594 | /* AOI1 is not the first in the chain */ |
| 595 | if (pmfbi->count > 0) |
| 596 | /* AOI0 is open, must be the first */ |
| 597 | pmfbi->ad->next_ad = 0; |
| 598 | } else /* AOI1 is the first in the chain */ |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 599 | wr_reg_wa(&hw->desc[1], data->dummy_ad.paddr); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 600 | /* close AOI 1 */ |
| 601 | break; |
Timur Tabi | 2572df9 | 2011-09-28 16:19:51 -0500 | [diff] [blame] | 602 | case PLANE2_AOI1: |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 603 | pmfbi = &data->mfb[3]; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 604 | if (hw->desc[2] != ad->paddr) { |
| 605 | /* AOI1 is not the first in the chain */ |
| 606 | if (pmfbi->count > 0) |
| 607 | /* AOI0 is open, must be the first */ |
| 608 | pmfbi->ad->next_ad = 0; |
| 609 | } else /* AOI1 is the first in the chain */ |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 610 | wr_reg_wa(&hw->desc[2], data->dummy_ad.paddr); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 611 | /* close AOI 1 */ |
| 612 | break; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 613 | } |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | static void enable_lcdc(struct fb_info *info) |
| 617 | { |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 618 | struct mfb_info *mfbi = info->par; |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 619 | struct fsl_diu_data *data = mfbi->parent; |
| 620 | struct diu __iomem *hw = data->diu_reg; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 621 | |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 622 | if (!data->fb_enabled) { |
Timur Tabi | c4e5a02 | 2011-09-28 16:19:53 -0500 | [diff] [blame] | 623 | out_be32(&hw->diu_mode, MFB_MODE1); |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 624 | data->fb_enabled++; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 625 | } |
| 626 | } |
| 627 | |
| 628 | static void disable_lcdc(struct fb_info *info) |
| 629 | { |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 630 | struct mfb_info *mfbi = info->par; |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 631 | struct fsl_diu_data *data = mfbi->parent; |
| 632 | struct diu __iomem *hw = data->diu_reg; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 633 | |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 634 | if (data->fb_enabled) { |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 635 | out_be32(&hw->diu_mode, 0); |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 636 | data->fb_enabled = 0; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 637 | } |
| 638 | } |
| 639 | |
| 640 | static void adjust_aoi_size_position(struct fb_var_screeninfo *var, |
| 641 | struct fb_info *info) |
| 642 | { |
| 643 | struct mfb_info *lower_aoi_mfbi, *upper_aoi_mfbi, *mfbi = info->par; |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 644 | struct fsl_diu_data *data = mfbi->parent; |
Timur Tabi | 2572df9 | 2011-09-28 16:19:51 -0500 | [diff] [blame] | 645 | int available_height, upper_aoi_bottom; |
| 646 | enum mfb_index index = mfbi->index; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 647 | int lower_aoi_is_open, upper_aoi_is_open; |
| 648 | __u32 base_plane_width, base_plane_height, upper_aoi_height; |
| 649 | |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 650 | base_plane_width = data->fsl_diu_info[0].var.xres; |
| 651 | base_plane_height = data->fsl_diu_info[0].var.yres; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 652 | |
York Sun | fdfaa48 | 2008-08-15 00:40:29 -0700 | [diff] [blame] | 653 | if (mfbi->x_aoi_d < 0) |
| 654 | mfbi->x_aoi_d = 0; |
| 655 | if (mfbi->y_aoi_d < 0) |
| 656 | mfbi->y_aoi_d = 0; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 657 | switch (index) { |
Timur Tabi | 2572df9 | 2011-09-28 16:19:51 -0500 | [diff] [blame] | 658 | case PLANE0: |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 659 | if (mfbi->x_aoi_d != 0) |
| 660 | mfbi->x_aoi_d = 0; |
| 661 | if (mfbi->y_aoi_d != 0) |
| 662 | mfbi->y_aoi_d = 0; |
| 663 | break; |
Timur Tabi | 2572df9 | 2011-09-28 16:19:51 -0500 | [diff] [blame] | 664 | case PLANE1_AOI0: |
| 665 | case PLANE2_AOI0: |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 666 | lower_aoi_mfbi = data->fsl_diu_info[index+1].par; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 667 | lower_aoi_is_open = lower_aoi_mfbi->count > 0 ? 1 : 0; |
| 668 | if (var->xres > base_plane_width) |
| 669 | var->xres = base_plane_width; |
| 670 | if ((mfbi->x_aoi_d + var->xres) > base_plane_width) |
| 671 | mfbi->x_aoi_d = base_plane_width - var->xres; |
| 672 | |
| 673 | if (lower_aoi_is_open) |
| 674 | available_height = lower_aoi_mfbi->y_aoi_d; |
| 675 | else |
| 676 | available_height = base_plane_height; |
| 677 | if (var->yres > available_height) |
| 678 | var->yres = available_height; |
| 679 | if ((mfbi->y_aoi_d + var->yres) > available_height) |
| 680 | mfbi->y_aoi_d = available_height - var->yres; |
| 681 | break; |
Timur Tabi | 2572df9 | 2011-09-28 16:19:51 -0500 | [diff] [blame] | 682 | case PLANE1_AOI1: |
| 683 | case PLANE2_AOI1: |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 684 | upper_aoi_mfbi = data->fsl_diu_info[index-1].par; |
| 685 | upper_aoi_height = data->fsl_diu_info[index-1].var.yres; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 686 | upper_aoi_bottom = upper_aoi_mfbi->y_aoi_d + upper_aoi_height; |
| 687 | upper_aoi_is_open = upper_aoi_mfbi->count > 0 ? 1 : 0; |
| 688 | if (var->xres > base_plane_width) |
| 689 | var->xres = base_plane_width; |
| 690 | if ((mfbi->x_aoi_d + var->xres) > base_plane_width) |
| 691 | mfbi->x_aoi_d = base_plane_width - var->xres; |
| 692 | if (mfbi->y_aoi_d < 0) |
| 693 | mfbi->y_aoi_d = 0; |
| 694 | if (upper_aoi_is_open) { |
| 695 | if (mfbi->y_aoi_d < upper_aoi_bottom) |
| 696 | mfbi->y_aoi_d = upper_aoi_bottom; |
| 697 | available_height = base_plane_height |
| 698 | - upper_aoi_bottom; |
| 699 | } else |
| 700 | available_height = base_plane_height; |
| 701 | if (var->yres > available_height) |
| 702 | var->yres = available_height; |
| 703 | if ((mfbi->y_aoi_d + var->yres) > base_plane_height) |
| 704 | mfbi->y_aoi_d = base_plane_height - var->yres; |
| 705 | break; |
| 706 | } |
| 707 | } |
| 708 | /* |
| 709 | * Checks to see if the hardware supports the state requested by var passed |
| 710 | * in. This function does not alter the hardware state! If the var passed in |
| 711 | * is slightly off by what the hardware can support then we alter the var |
| 712 | * PASSED in to what we can do. If the hardware doesn't support mode change |
| 713 | * a -EINVAL will be returned by the upper layers. |
| 714 | */ |
| 715 | static int fsl_diu_check_var(struct fb_var_screeninfo *var, |
| 716 | struct fb_info *info) |
| 717 | { |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 718 | if (var->xres_virtual < var->xres) |
| 719 | var->xres_virtual = var->xres; |
| 720 | if (var->yres_virtual < var->yres) |
| 721 | var->yres_virtual = var->yres; |
| 722 | |
| 723 | if (var->xoffset < 0) |
| 724 | var->xoffset = 0; |
| 725 | |
| 726 | if (var->yoffset < 0) |
| 727 | var->yoffset = 0; |
| 728 | |
| 729 | if (var->xoffset + info->var.xres > info->var.xres_virtual) |
| 730 | var->xoffset = info->var.xres_virtual - info->var.xres; |
| 731 | |
| 732 | if (var->yoffset + info->var.yres > info->var.yres_virtual) |
| 733 | var->yoffset = info->var.yres_virtual - info->var.yres; |
| 734 | |
| 735 | if ((var->bits_per_pixel != 32) && (var->bits_per_pixel != 24) && |
| 736 | (var->bits_per_pixel != 16)) |
| 737 | var->bits_per_pixel = default_bpp; |
| 738 | |
| 739 | switch (var->bits_per_pixel) { |
| 740 | case 16: |
| 741 | var->red.length = 5; |
| 742 | var->red.offset = 11; |
| 743 | var->red.msb_right = 0; |
| 744 | |
| 745 | var->green.length = 6; |
| 746 | var->green.offset = 5; |
| 747 | var->green.msb_right = 0; |
| 748 | |
| 749 | var->blue.length = 5; |
| 750 | var->blue.offset = 0; |
| 751 | var->blue.msb_right = 0; |
| 752 | |
| 753 | var->transp.length = 0; |
| 754 | var->transp.offset = 0; |
| 755 | var->transp.msb_right = 0; |
| 756 | break; |
| 757 | case 24: |
| 758 | var->red.length = 8; |
| 759 | var->red.offset = 0; |
| 760 | var->red.msb_right = 0; |
| 761 | |
| 762 | var->green.length = 8; |
| 763 | var->green.offset = 8; |
| 764 | var->green.msb_right = 0; |
| 765 | |
| 766 | var->blue.length = 8; |
| 767 | var->blue.offset = 16; |
| 768 | var->blue.msb_right = 0; |
| 769 | |
| 770 | var->transp.length = 0; |
| 771 | var->transp.offset = 0; |
| 772 | var->transp.msb_right = 0; |
| 773 | break; |
| 774 | case 32: |
| 775 | var->red.length = 8; |
| 776 | var->red.offset = 16; |
| 777 | var->red.msb_right = 0; |
| 778 | |
| 779 | var->green.length = 8; |
| 780 | var->green.offset = 8; |
| 781 | var->green.msb_right = 0; |
| 782 | |
| 783 | var->blue.length = 8; |
| 784 | var->blue.offset = 0; |
| 785 | var->blue.msb_right = 0; |
| 786 | |
| 787 | var->transp.length = 8; |
| 788 | var->transp.offset = 24; |
| 789 | var->transp.msb_right = 0; |
| 790 | |
| 791 | break; |
| 792 | } |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 793 | |
| 794 | var->height = -1; |
| 795 | var->width = -1; |
| 796 | var->grayscale = 0; |
| 797 | |
| 798 | /* Copy nonstd field to/from sync for fbset usage */ |
| 799 | var->sync |= var->nonstd; |
| 800 | var->nonstd |= var->sync; |
| 801 | |
| 802 | adjust_aoi_size_position(var, info); |
| 803 | return 0; |
| 804 | } |
| 805 | |
| 806 | static void set_fix(struct fb_info *info) |
| 807 | { |
| 808 | struct fb_fix_screeninfo *fix = &info->fix; |
| 809 | struct fb_var_screeninfo *var = &info->var; |
| 810 | struct mfb_info *mfbi = info->par; |
| 811 | |
Timur Tabi | ec02dd2 | 2011-09-15 16:44:54 -0500 | [diff] [blame] | 812 | strncpy(fix->id, mfbi->id, sizeof(fix->id)); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 813 | fix->line_length = var->xres_virtual * var->bits_per_pixel / 8; |
| 814 | fix->type = FB_TYPE_PACKED_PIXELS; |
| 815 | fix->accel = FB_ACCEL_NONE; |
| 816 | fix->visual = FB_VISUAL_TRUECOLOR; |
| 817 | fix->xpanstep = 1; |
| 818 | fix->ypanstep = 1; |
| 819 | } |
| 820 | |
| 821 | static void update_lcdc(struct fb_info *info) |
| 822 | { |
| 823 | struct fb_var_screeninfo *var = &info->var; |
| 824 | struct mfb_info *mfbi = info->par; |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 825 | struct fsl_diu_data *data = mfbi->parent; |
Timur Tabi | 3c755b7 | 2011-10-04 19:36:51 -0500 | [diff] [blame] | 826 | struct diu __iomem *hw; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 827 | int i, j; |
Timur Tabi | ddd3d90 | 2011-12-02 17:03:27 -0600 | [diff] [blame] | 828 | u8 *gamma_table_base; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 829 | |
| 830 | u32 temp; |
| 831 | |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 832 | hw = data->diu_reg; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 833 | |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 834 | diu_ops.set_monitor_port(data->monitor_port); |
| 835 | gamma_table_base = data->gamma; |
Timur Tabi | ddd3d90 | 2011-12-02 17:03:27 -0600 | [diff] [blame] | 836 | |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 837 | /* Prep for DIU init - gamma table, cursor table */ |
| 838 | |
| 839 | for (i = 0; i <= 2; i++) |
Timur Tabi | 4a85dc8b | 2011-09-15 16:44:46 -0500 | [diff] [blame] | 840 | for (j = 0; j <= 255; j++) |
| 841 | *gamma_table_base++ = j; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 842 | |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 843 | diu_ops.set_gamma_table(data->monitor_port, data->gamma); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 844 | |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 845 | disable_lcdc(info); |
| 846 | |
| 847 | /* Program DIU registers */ |
| 848 | |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 849 | out_be32(&hw->gamma, DMA_ADDR(data, gamma)); |
| 850 | out_be32(&hw->cursor, DMA_ADDR(data, cursor)); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 851 | |
| 852 | out_be32(&hw->bgnd, 0x007F7F7F); /* BGND */ |
| 853 | out_be32(&hw->bgnd_wb, 0); /* BGND_WB */ |
| 854 | out_be32(&hw->disp_size, (var->yres << 16 | var->xres)); |
| 855 | /* DISP SIZE */ |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 856 | out_be32(&hw->wb_size, 0); /* WB SIZE */ |
| 857 | out_be32(&hw->wb_mem_addr, 0); /* WB MEM ADDR */ |
| 858 | |
| 859 | /* Horizontal and vertical configuration register */ |
| 860 | temp = var->left_margin << 22 | /* BP_H */ |
| 861 | var->hsync_len << 11 | /* PW_H */ |
| 862 | var->right_margin; /* FP_H */ |
| 863 | |
| 864 | out_be32(&hw->hsyn_para, temp); |
| 865 | |
| 866 | temp = var->upper_margin << 22 | /* BP_V */ |
| 867 | var->vsync_len << 11 | /* PW_V */ |
| 868 | var->lower_margin; /* FP_V */ |
| 869 | |
| 870 | out_be32(&hw->vsyn_para, temp); |
| 871 | |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 872 | diu_ops.set_pixel_clock(var->pixclock); |
| 873 | |
| 874 | out_be32(&hw->syn_pol, 0); /* SYNC SIGNALS POLARITY */ |
| 875 | out_be32(&hw->thresholds, 0x00037800); /* The Thresholds */ |
| 876 | out_be32(&hw->int_status, 0); /* INTERRUPT STATUS */ |
| 877 | out_be32(&hw->plut, 0x01F5F666); |
| 878 | |
| 879 | /* Enable the DIU */ |
| 880 | enable_lcdc(info); |
| 881 | } |
| 882 | |
| 883 | static int map_video_memory(struct fb_info *info) |
| 884 | { |
| 885 | phys_addr_t phys; |
Krzysztof Helt | 537a1bf | 2009-06-30 11:41:29 -0700 | [diff] [blame] | 886 | u32 smem_len = info->fix.line_length * info->var.yres_virtual; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 887 | |
Krzysztof Helt | 537a1bf | 2009-06-30 11:41:29 -0700 | [diff] [blame] | 888 | info->screen_base = fsl_diu_alloc(smem_len, &phys); |
Anton Vorontsov | 05946bc | 2008-07-04 09:59:38 -0700 | [diff] [blame] | 889 | if (info->screen_base == NULL) { |
Timur Tabi | 154152a | 2011-09-15 16:44:47 -0500 | [diff] [blame] | 890 | dev_err(info->dev, "unable to allocate fb memory\n"); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 891 | return -ENOMEM; |
| 892 | } |
Krzysztof Helt | 537a1bf | 2009-06-30 11:41:29 -0700 | [diff] [blame] | 893 | mutex_lock(&info->mm_lock); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 894 | info->fix.smem_start = (unsigned long) phys; |
Krzysztof Helt | 537a1bf | 2009-06-30 11:41:29 -0700 | [diff] [blame] | 895 | info->fix.smem_len = smem_len; |
| 896 | mutex_unlock(&info->mm_lock); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 897 | info->screen_size = info->fix.smem_len; |
| 898 | |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 899 | return 0; |
| 900 | } |
| 901 | |
| 902 | static void unmap_video_memory(struct fb_info *info) |
| 903 | { |
| 904 | fsl_diu_free(info->screen_base, info->fix.smem_len); |
Krzysztof Helt | 537a1bf | 2009-06-30 11:41:29 -0700 | [diff] [blame] | 905 | mutex_lock(&info->mm_lock); |
Anton Vorontsov | 05946bc | 2008-07-04 09:59:38 -0700 | [diff] [blame] | 906 | info->screen_base = NULL; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 907 | info->fix.smem_start = 0; |
| 908 | info->fix.smem_len = 0; |
Krzysztof Helt | 537a1bf | 2009-06-30 11:41:29 -0700 | [diff] [blame] | 909 | mutex_unlock(&info->mm_lock); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 910 | } |
| 911 | |
| 912 | /* |
York Sun | ae5591e | 2008-08-15 00:40:28 -0700 | [diff] [blame] | 913 | * Using the fb_var_screeninfo in fb_info we set the aoi of this |
| 914 | * particular framebuffer. It is a light version of fsl_diu_set_par. |
| 915 | */ |
| 916 | static int fsl_diu_set_aoi(struct fb_info *info) |
| 917 | { |
| 918 | struct fb_var_screeninfo *var = &info->var; |
| 919 | struct mfb_info *mfbi = info->par; |
| 920 | struct diu_ad *ad = mfbi->ad; |
| 921 | |
| 922 | /* AOI should not be greater than display size */ |
| 923 | ad->offset_xyi = cpu_to_le32((var->yoffset << 16) | var->xoffset); |
| 924 | ad->offset_xyd = cpu_to_le32((mfbi->y_aoi_d << 16) | mfbi->x_aoi_d); |
| 925 | return 0; |
| 926 | } |
| 927 | |
| 928 | /* |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 929 | * Using the fb_var_screeninfo in fb_info we set the resolution of this |
| 930 | * particular framebuffer. This function alters the fb_fix_screeninfo stored |
| 931 | * in fb_info. It does not alter var in fb_info since we are using that |
| 932 | * data. This means we depend on the data in var inside fb_info to be |
| 933 | * supported by the hardware. fsl_diu_check_var is always called before |
| 934 | * fsl_diu_set_par to ensure this. |
| 935 | */ |
| 936 | static int fsl_diu_set_par(struct fb_info *info) |
| 937 | { |
| 938 | unsigned long len; |
| 939 | struct fb_var_screeninfo *var = &info->var; |
| 940 | struct mfb_info *mfbi = info->par; |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 941 | struct fsl_diu_data *data = mfbi->parent; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 942 | struct diu_ad *ad = mfbi->ad; |
Timur Tabi | 3c755b7 | 2011-10-04 19:36:51 -0500 | [diff] [blame] | 943 | struct diu __iomem *hw; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 944 | |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 945 | hw = data->diu_reg; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 946 | |
| 947 | set_fix(info); |
| 948 | mfbi->cursor_reset = 1; |
| 949 | |
| 950 | len = info->var.yres_virtual * info->fix.line_length; |
| 951 | /* Alloc & dealloc each time resolution/bpp change */ |
| 952 | if (len != info->fix.smem_len) { |
| 953 | if (info->fix.smem_start) |
| 954 | unmap_video_memory(info); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 955 | |
| 956 | /* Memory allocation for framebuffer */ |
| 957 | if (map_video_memory(info)) { |
Timur Tabi | 154152a | 2011-09-15 16:44:47 -0500 | [diff] [blame] | 958 | dev_err(info->dev, "unable to allocate fb memory 1\n"); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 959 | return -ENOMEM; |
| 960 | } |
| 961 | } |
| 962 | |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 963 | ad->pix_fmt = diu_ops.get_pixel_format(data->monitor_port, |
Timur Tabi | 7653aaa | 2011-07-09 15:38:14 -0500 | [diff] [blame] | 964 | var->bits_per_pixel); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 965 | ad->addr = cpu_to_le32(info->fix.smem_start); |
York Sun | ae5591e | 2008-08-15 00:40:28 -0700 | [diff] [blame] | 966 | ad->src_size_g_alpha = cpu_to_le32((var->yres_virtual << 12) | |
| 967 | var->xres_virtual) | mfbi->g_alpha; |
| 968 | /* AOI should not be greater than display size */ |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 969 | ad->aoi_size = cpu_to_le32((var->yres << 16) | var->xres); |
York Sun | ae5591e | 2008-08-15 00:40:28 -0700 | [diff] [blame] | 970 | ad->offset_xyi = cpu_to_le32((var->yoffset << 16) | var->xoffset); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 971 | ad->offset_xyd = cpu_to_le32((mfbi->y_aoi_d << 16) | mfbi->x_aoi_d); |
| 972 | |
| 973 | /* Disable chroma keying function */ |
| 974 | ad->ckmax_r = 0; |
| 975 | ad->ckmax_g = 0; |
| 976 | ad->ckmax_b = 0; |
| 977 | |
| 978 | ad->ckmin_r = 255; |
| 979 | ad->ckmin_g = 255; |
| 980 | ad->ckmin_b = 255; |
| 981 | |
Timur Tabi | 2572df9 | 2011-09-28 16:19:51 -0500 | [diff] [blame] | 982 | if (mfbi->index == PLANE0) |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 983 | update_lcdc(info); |
| 984 | return 0; |
| 985 | } |
| 986 | |
| 987 | static inline __u32 CNVT_TOHW(__u32 val, __u32 width) |
| 988 | { |
Timur Tabi | 4a85dc8b | 2011-09-15 16:44:46 -0500 | [diff] [blame] | 989 | return ((val << width) + 0x7FFF - val) >> 16; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 990 | } |
| 991 | |
| 992 | /* |
| 993 | * Set a single color register. The values supplied have a 16 bit magnitude |
| 994 | * which needs to be scaled in this function for the hardware. Things to take |
| 995 | * into consideration are how many color registers, if any, are supported with |
| 996 | * the current color visual. With truecolor mode no color palettes are |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 997 | * supported. Here a pseudo palette is created which we store the value in |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 998 | * pseudo_palette in struct fb_info. For pseudocolor mode we have a limited |
| 999 | * color palette. |
| 1000 | */ |
Timur Tabi | 4a85dc8b | 2011-09-15 16:44:46 -0500 | [diff] [blame] | 1001 | static int fsl_diu_setcolreg(unsigned int regno, unsigned int red, |
| 1002 | unsigned int green, unsigned int blue, |
| 1003 | unsigned int transp, struct fb_info *info) |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1004 | { |
| 1005 | int ret = 1; |
| 1006 | |
| 1007 | /* |
| 1008 | * If greyscale is true, then we convert the RGB value |
| 1009 | * to greyscale no matter what visual we are using. |
| 1010 | */ |
| 1011 | if (info->var.grayscale) |
| 1012 | red = green = blue = (19595 * red + 38470 * green + |
| 1013 | 7471 * blue) >> 16; |
| 1014 | switch (info->fix.visual) { |
| 1015 | case FB_VISUAL_TRUECOLOR: |
| 1016 | /* |
| 1017 | * 16-bit True Colour. We encode the RGB value |
| 1018 | * according to the RGB bitfield information. |
| 1019 | */ |
| 1020 | if (regno < 16) { |
| 1021 | u32 *pal = info->pseudo_palette; |
| 1022 | u32 v; |
| 1023 | |
| 1024 | red = CNVT_TOHW(red, info->var.red.length); |
| 1025 | green = CNVT_TOHW(green, info->var.green.length); |
| 1026 | blue = CNVT_TOHW(blue, info->var.blue.length); |
| 1027 | transp = CNVT_TOHW(transp, info->var.transp.length); |
| 1028 | |
| 1029 | v = (red << info->var.red.offset) | |
| 1030 | (green << info->var.green.offset) | |
| 1031 | (blue << info->var.blue.offset) | |
| 1032 | (transp << info->var.transp.offset); |
| 1033 | |
| 1034 | pal[regno] = v; |
| 1035 | ret = 0; |
| 1036 | } |
| 1037 | break; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1038 | } |
| 1039 | |
| 1040 | return ret; |
| 1041 | } |
| 1042 | |
| 1043 | /* |
| 1044 | * Pan (or wrap, depending on the `vmode' field) the display using the |
| 1045 | * 'xoffset' and 'yoffset' fields of the 'var' structure. If the values |
| 1046 | * don't fit, return -EINVAL. |
| 1047 | */ |
| 1048 | static int fsl_diu_pan_display(struct fb_var_screeninfo *var, |
| 1049 | struct fb_info *info) |
| 1050 | { |
| 1051 | if ((info->var.xoffset == var->xoffset) && |
| 1052 | (info->var.yoffset == var->yoffset)) |
| 1053 | return 0; /* No change, do nothing */ |
| 1054 | |
| 1055 | if (var->xoffset < 0 || var->yoffset < 0 |
| 1056 | || var->xoffset + info->var.xres > info->var.xres_virtual |
| 1057 | || var->yoffset + info->var.yres > info->var.yres_virtual) |
| 1058 | return -EINVAL; |
| 1059 | |
| 1060 | info->var.xoffset = var->xoffset; |
| 1061 | info->var.yoffset = var->yoffset; |
| 1062 | |
| 1063 | if (var->vmode & FB_VMODE_YWRAP) |
| 1064 | info->var.vmode |= FB_VMODE_YWRAP; |
| 1065 | else |
| 1066 | info->var.vmode &= ~FB_VMODE_YWRAP; |
| 1067 | |
York Sun | ae5591e | 2008-08-15 00:40:28 -0700 | [diff] [blame] | 1068 | fsl_diu_set_aoi(info); |
| 1069 | |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1070 | return 0; |
| 1071 | } |
| 1072 | |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1073 | static int fsl_diu_ioctl(struct fb_info *info, unsigned int cmd, |
| 1074 | unsigned long arg) |
| 1075 | { |
| 1076 | struct mfb_info *mfbi = info->par; |
| 1077 | struct diu_ad *ad = mfbi->ad; |
| 1078 | struct mfb_chroma_key ck; |
| 1079 | unsigned char global_alpha; |
| 1080 | struct aoi_display_offset aoi_d; |
| 1081 | __u32 pix_fmt; |
| 1082 | void __user *buf = (void __user *)arg; |
| 1083 | |
| 1084 | if (!arg) |
| 1085 | return -EINVAL; |
| 1086 | switch (cmd) { |
Timur Tabi | 36b0b1d | 2011-10-04 19:36:44 -0500 | [diff] [blame] | 1087 | case MFB_SET_PIXFMT_OLD: |
| 1088 | dev_warn(info->dev, |
| 1089 | "MFB_SET_PIXFMT value of 0x%08x is deprecated.\n", |
| 1090 | MFB_SET_PIXFMT_OLD); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1091 | case MFB_SET_PIXFMT: |
| 1092 | if (copy_from_user(&pix_fmt, buf, sizeof(pix_fmt))) |
| 1093 | return -EFAULT; |
| 1094 | ad->pix_fmt = pix_fmt; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1095 | break; |
Timur Tabi | 36b0b1d | 2011-10-04 19:36:44 -0500 | [diff] [blame] | 1096 | case MFB_GET_PIXFMT_OLD: |
| 1097 | dev_warn(info->dev, |
| 1098 | "MFB_GET_PIXFMT value of 0x%08x is deprecated.\n", |
| 1099 | MFB_GET_PIXFMT_OLD); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1100 | case MFB_GET_PIXFMT: |
| 1101 | pix_fmt = ad->pix_fmt; |
| 1102 | if (copy_to_user(buf, &pix_fmt, sizeof(pix_fmt))) |
| 1103 | return -EFAULT; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1104 | break; |
| 1105 | case MFB_SET_AOID: |
| 1106 | if (copy_from_user(&aoi_d, buf, sizeof(aoi_d))) |
| 1107 | return -EFAULT; |
| 1108 | mfbi->x_aoi_d = aoi_d.x_aoi_d; |
| 1109 | mfbi->y_aoi_d = aoi_d.y_aoi_d; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1110 | fsl_diu_check_var(&info->var, info); |
York Sun | ae5591e | 2008-08-15 00:40:28 -0700 | [diff] [blame] | 1111 | fsl_diu_set_aoi(info); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1112 | break; |
| 1113 | case MFB_GET_AOID: |
| 1114 | aoi_d.x_aoi_d = mfbi->x_aoi_d; |
| 1115 | aoi_d.y_aoi_d = mfbi->y_aoi_d; |
| 1116 | if (copy_to_user(buf, &aoi_d, sizeof(aoi_d))) |
| 1117 | return -EFAULT; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1118 | break; |
| 1119 | case MFB_GET_ALPHA: |
| 1120 | global_alpha = mfbi->g_alpha; |
| 1121 | if (copy_to_user(buf, &global_alpha, sizeof(global_alpha))) |
| 1122 | return -EFAULT; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1123 | break; |
| 1124 | case MFB_SET_ALPHA: |
| 1125 | /* set panel information */ |
| 1126 | if (copy_from_user(&global_alpha, buf, sizeof(global_alpha))) |
| 1127 | return -EFAULT; |
| 1128 | ad->src_size_g_alpha = (ad->src_size_g_alpha & (~0xff)) | |
| 1129 | (global_alpha & 0xff); |
| 1130 | mfbi->g_alpha = global_alpha; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1131 | break; |
| 1132 | case MFB_SET_CHROMA_KEY: |
| 1133 | /* set panel winformation */ |
| 1134 | if (copy_from_user(&ck, buf, sizeof(ck))) |
| 1135 | return -EFAULT; |
| 1136 | |
| 1137 | if (ck.enable && |
| 1138 | (ck.red_max < ck.red_min || |
| 1139 | ck.green_max < ck.green_min || |
| 1140 | ck.blue_max < ck.blue_min)) |
| 1141 | return -EINVAL; |
| 1142 | |
| 1143 | if (!ck.enable) { |
| 1144 | ad->ckmax_r = 0; |
| 1145 | ad->ckmax_g = 0; |
| 1146 | ad->ckmax_b = 0; |
| 1147 | ad->ckmin_r = 255; |
| 1148 | ad->ckmin_g = 255; |
| 1149 | ad->ckmin_b = 255; |
| 1150 | } else { |
| 1151 | ad->ckmax_r = ck.red_max; |
| 1152 | ad->ckmax_g = ck.green_max; |
| 1153 | ad->ckmax_b = ck.blue_max; |
| 1154 | ad->ckmin_r = ck.red_min; |
| 1155 | ad->ckmin_g = ck.green_min; |
| 1156 | ad->ckmin_b = ck.blue_min; |
| 1157 | } |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1158 | break; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1159 | default: |
Timur Tabi | 154152a | 2011-09-15 16:44:47 -0500 | [diff] [blame] | 1160 | dev_err(info->dev, "unknown ioctl command (0x%08X)\n", cmd); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1161 | return -ENOIOCTLCMD; |
| 1162 | } |
| 1163 | |
| 1164 | return 0; |
| 1165 | } |
| 1166 | |
| 1167 | /* turn on fb if count == 1 |
| 1168 | */ |
| 1169 | static int fsl_diu_open(struct fb_info *info, int user) |
| 1170 | { |
| 1171 | struct mfb_info *mfbi = info->par; |
| 1172 | int res = 0; |
| 1173 | |
Anatolij Gustschin | 4b5006e | 2010-07-23 04:00:37 +0000 | [diff] [blame] | 1174 | /* free boot splash memory on first /dev/fb0 open */ |
Timur Tabi | 2572df9 | 2011-09-28 16:19:51 -0500 | [diff] [blame] | 1175 | if ((mfbi->index == PLANE0) && diu_ops.release_bootmem) |
Anatolij Gustschin | 4b5006e | 2010-07-23 04:00:37 +0000 | [diff] [blame] | 1176 | diu_ops.release_bootmem(); |
| 1177 | |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1178 | spin_lock(&diu_lock); |
| 1179 | mfbi->count++; |
| 1180 | if (mfbi->count == 1) { |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1181 | fsl_diu_check_var(&info->var, info); |
| 1182 | res = fsl_diu_set_par(info); |
| 1183 | if (res < 0) |
| 1184 | mfbi->count--; |
Timur Tabi | 7e47c21 | 2011-09-28 16:19:52 -0500 | [diff] [blame] | 1185 | else |
| 1186 | fsl_diu_enable_panel(info); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1187 | } |
| 1188 | |
| 1189 | spin_unlock(&diu_lock); |
| 1190 | return res; |
| 1191 | } |
| 1192 | |
| 1193 | /* turn off fb if count == 0 |
| 1194 | */ |
| 1195 | static int fsl_diu_release(struct fb_info *info, int user) |
| 1196 | { |
| 1197 | struct mfb_info *mfbi = info->par; |
| 1198 | int res = 0; |
| 1199 | |
| 1200 | spin_lock(&diu_lock); |
| 1201 | mfbi->count--; |
Timur Tabi | 2572df9 | 2011-09-28 16:19:51 -0500 | [diff] [blame] | 1202 | if (mfbi->count == 0) |
| 1203 | fsl_diu_disable_panel(info); |
| 1204 | |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1205 | spin_unlock(&diu_lock); |
| 1206 | return res; |
| 1207 | } |
| 1208 | |
| 1209 | static struct fb_ops fsl_diu_ops = { |
| 1210 | .owner = THIS_MODULE, |
| 1211 | .fb_check_var = fsl_diu_check_var, |
| 1212 | .fb_set_par = fsl_diu_set_par, |
| 1213 | .fb_setcolreg = fsl_diu_setcolreg, |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1214 | .fb_pan_display = fsl_diu_pan_display, |
| 1215 | .fb_fillrect = cfb_fillrect, |
| 1216 | .fb_copyarea = cfb_copyarea, |
| 1217 | .fb_imageblit = cfb_imageblit, |
| 1218 | .fb_ioctl = fsl_diu_ioctl, |
| 1219 | .fb_open = fsl_diu_open, |
| 1220 | .fb_release = fsl_diu_release, |
| 1221 | }; |
| 1222 | |
| 1223 | static int init_fbinfo(struct fb_info *info) |
| 1224 | { |
| 1225 | struct mfb_info *mfbi = info->par; |
| 1226 | |
| 1227 | info->device = NULL; |
| 1228 | info->var.activate = FB_ACTIVATE_NOW; |
| 1229 | info->fbops = &fsl_diu_ops; |
| 1230 | info->flags = FBINFO_FLAG_DEFAULT; |
| 1231 | info->pseudo_palette = &mfbi->pseudo_palette; |
| 1232 | |
| 1233 | /* Allocate colormap */ |
| 1234 | fb_alloc_cmap(&info->cmap, 16, 0); |
| 1235 | return 0; |
| 1236 | } |
| 1237 | |
Anton Vorontsov | 05946bc | 2008-07-04 09:59:38 -0700 | [diff] [blame] | 1238 | static int __devinit install_fb(struct fb_info *info) |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1239 | { |
| 1240 | int rc; |
| 1241 | struct mfb_info *mfbi = info->par; |
| 1242 | const char *aoi_mode, *init_aoi_mode = "320x240"; |
Anatolij Gustschin | 8b856f0 | 2010-07-23 04:00:39 +0000 | [diff] [blame] | 1243 | struct fb_videomode *db = fsl_diu_mode_db; |
| 1244 | unsigned int dbsize = ARRAY_SIZE(fsl_diu_mode_db); |
| 1245 | int has_default_mode = 1; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1246 | |
| 1247 | if (init_fbinfo(info)) |
| 1248 | return -EINVAL; |
| 1249 | |
Timur Tabi | 2572df9 | 2011-09-28 16:19:51 -0500 | [diff] [blame] | 1250 | if (mfbi->index == PLANE0) { |
Anatolij Gustschin | 8b856f0 | 2010-07-23 04:00:39 +0000 | [diff] [blame] | 1251 | if (mfbi->edid_data) { |
| 1252 | /* Now build modedb from EDID */ |
| 1253 | fb_edid_to_monspecs(mfbi->edid_data, &info->monspecs); |
| 1254 | fb_videomode_to_modelist(info->monspecs.modedb, |
| 1255 | info->monspecs.modedb_len, |
| 1256 | &info->modelist); |
| 1257 | db = info->monspecs.modedb; |
| 1258 | dbsize = info->monspecs.modedb_len; |
| 1259 | } |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1260 | aoi_mode = fb_mode; |
Anatolij Gustschin | 8b856f0 | 2010-07-23 04:00:39 +0000 | [diff] [blame] | 1261 | } else { |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1262 | aoi_mode = init_aoi_mode; |
Anatolij Gustschin | 8b856f0 | 2010-07-23 04:00:39 +0000 | [diff] [blame] | 1263 | } |
Timur Tabi | 63cf8df | 2011-09-15 16:44:51 -0500 | [diff] [blame] | 1264 | rc = fb_find_mode(&info->var, info, aoi_mode, db, dbsize, NULL, |
| 1265 | default_bpp); |
Timur Tabi | 154152a | 2011-09-15 16:44:47 -0500 | [diff] [blame] | 1266 | if (!rc) { |
Anatolij Gustschin | 8b856f0 | 2010-07-23 04:00:39 +0000 | [diff] [blame] | 1267 | /* |
| 1268 | * For plane 0 we continue and look into |
| 1269 | * driver's internal modedb. |
| 1270 | */ |
Timur Tabi | 2572df9 | 2011-09-28 16:19:51 -0500 | [diff] [blame] | 1271 | if ((mfbi->index == PLANE0) && mfbi->edid_data) |
Anatolij Gustschin | 8b856f0 | 2010-07-23 04:00:39 +0000 | [diff] [blame] | 1272 | has_default_mode = 0; |
| 1273 | else |
| 1274 | return -EINVAL; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1275 | } |
| 1276 | |
Anatolij Gustschin | 8b856f0 | 2010-07-23 04:00:39 +0000 | [diff] [blame] | 1277 | if (!has_default_mode) { |
| 1278 | rc = fb_find_mode(&info->var, info, aoi_mode, fsl_diu_mode_db, |
Timur Tabi | 63cf8df | 2011-09-15 16:44:51 -0500 | [diff] [blame] | 1279 | ARRAY_SIZE(fsl_diu_mode_db), NULL, default_bpp); |
| 1280 | if (rc) |
Anatolij Gustschin | 8b856f0 | 2010-07-23 04:00:39 +0000 | [diff] [blame] | 1281 | has_default_mode = 1; |
| 1282 | } |
| 1283 | |
| 1284 | /* Still not found, use preferred mode from database if any */ |
| 1285 | if (!has_default_mode && info->monspecs.modedb) { |
| 1286 | struct fb_monspecs *specs = &info->monspecs; |
| 1287 | struct fb_videomode *modedb = &specs->modedb[0]; |
| 1288 | |
| 1289 | /* |
| 1290 | * Get preferred timing. If not found, |
| 1291 | * first mode in database will be used. |
| 1292 | */ |
| 1293 | if (specs->misc & FB_MISC_1ST_DETAIL) { |
| 1294 | int i; |
| 1295 | |
| 1296 | for (i = 0; i < specs->modedb_len; i++) { |
| 1297 | if (specs->modedb[i].flag & FB_MODE_IS_FIRST) { |
| 1298 | modedb = &specs->modedb[i]; |
| 1299 | break; |
| 1300 | } |
| 1301 | } |
| 1302 | } |
| 1303 | |
| 1304 | info->var.bits_per_pixel = default_bpp; |
| 1305 | fb_videomode_to_var(&info->var, modedb); |
| 1306 | } |
| 1307 | |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1308 | if (fsl_diu_check_var(&info->var, info)) { |
Timur Tabi | 154152a | 2011-09-15 16:44:47 -0500 | [diff] [blame] | 1309 | dev_err(info->dev, "fsl_diu_check_var failed\n"); |
Timur Tabi | 589c797 | 2011-09-15 16:44:55 -0500 | [diff] [blame] | 1310 | unmap_video_memory(info); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1311 | fb_dealloc_cmap(&info->cmap); |
| 1312 | return -EINVAL; |
| 1313 | } |
| 1314 | |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1315 | if (register_framebuffer(info) < 0) { |
Timur Tabi | 154152a | 2011-09-15 16:44:47 -0500 | [diff] [blame] | 1316 | dev_err(info->dev, "register_framebuffer failed\n"); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1317 | unmap_video_memory(info); |
| 1318 | fb_dealloc_cmap(&info->cmap); |
| 1319 | return -EINVAL; |
| 1320 | } |
| 1321 | |
| 1322 | mfbi->registered = 1; |
Timur Tabi | 154152a | 2011-09-15 16:44:47 -0500 | [diff] [blame] | 1323 | dev_info(info->dev, "%s registered successfully\n", mfbi->id); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1324 | |
| 1325 | return 0; |
| 1326 | } |
| 1327 | |
Anton Vorontsov | 05946bc | 2008-07-04 09:59:38 -0700 | [diff] [blame] | 1328 | static void uninstall_fb(struct fb_info *info) |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1329 | { |
| 1330 | struct mfb_info *mfbi = info->par; |
| 1331 | |
| 1332 | if (!mfbi->registered) |
| 1333 | return; |
| 1334 | |
Timur Tabi | 2572df9 | 2011-09-28 16:19:51 -0500 | [diff] [blame] | 1335 | if (mfbi->index == PLANE0) |
Anatolij Gustschin | 8b856f0 | 2010-07-23 04:00:39 +0000 | [diff] [blame] | 1336 | kfree(mfbi->edid_data); |
| 1337 | |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1338 | unregister_framebuffer(info); |
| 1339 | unmap_video_memory(info); |
| 1340 | if (&info->cmap) |
| 1341 | fb_dealloc_cmap(&info->cmap); |
| 1342 | |
| 1343 | mfbi->registered = 0; |
| 1344 | } |
| 1345 | |
| 1346 | static irqreturn_t fsl_diu_isr(int irq, void *dev_id) |
| 1347 | { |
Timur Tabi | 3c755b7 | 2011-10-04 19:36:51 -0500 | [diff] [blame] | 1348 | struct diu __iomem *hw = dev_id; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1349 | unsigned int status = in_be32(&hw->int_status); |
| 1350 | |
| 1351 | if (status) { |
| 1352 | /* This is the workaround for underrun */ |
| 1353 | if (status & INT_UNDRUN) { |
| 1354 | out_be32(&hw->diu_mode, 0); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1355 | udelay(1); |
| 1356 | out_be32(&hw->diu_mode, 1); |
| 1357 | } |
| 1358 | #if defined(CONFIG_NOT_COHERENT_CACHE) |
| 1359 | else if (status & INT_VSYNC) { |
| 1360 | unsigned int i; |
Timur Tabi | 4a85dc8b | 2011-09-15 16:44:46 -0500 | [diff] [blame] | 1361 | |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1362 | for (i = 0; i < coherence_data_size; |
| 1363 | i += d_cache_line_size) |
| 1364 | __asm__ __volatile__ ( |
| 1365 | "dcbz 0, %[input]" |
| 1366 | ::[input]"r"(&coherence_data[i])); |
| 1367 | } |
| 1368 | #endif |
| 1369 | return IRQ_HANDLED; |
| 1370 | } |
| 1371 | return IRQ_NONE; |
| 1372 | } |
| 1373 | |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 1374 | static int request_irq_local(struct fsl_diu_data *data) |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1375 | { |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 1376 | struct diu __iomem *hw = data->diu_reg; |
Timur Tabi | bada04f | 2011-09-15 16:44:52 -0500 | [diff] [blame] | 1377 | u32 ints; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1378 | int ret; |
| 1379 | |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1380 | /* Read to clear the status */ |
Timur Tabi | bada04f | 2011-09-15 16:44:52 -0500 | [diff] [blame] | 1381 | in_be32(&hw->int_status); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1382 | |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 1383 | ret = request_irq(data->irq, fsl_diu_isr, 0, "fsl-diu-fb", hw); |
Timur Tabi | 154152a | 2011-09-15 16:44:47 -0500 | [diff] [blame] | 1384 | if (!ret) { |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1385 | ints = INT_PARERR | INT_LS_BF_VS; |
| 1386 | #if !defined(CONFIG_NOT_COHERENT_CACHE) |
| 1387 | ints |= INT_VSYNC; |
| 1388 | #endif |
Timur Tabi | 4a85dc8b | 2011-09-15 16:44:46 -0500 | [diff] [blame] | 1389 | |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1390 | /* Read to clear the status */ |
Timur Tabi | bada04f | 2011-09-15 16:44:52 -0500 | [diff] [blame] | 1391 | in_be32(&hw->int_status); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1392 | out_be32(&hw->int_mask, ints); |
| 1393 | } |
Timur Tabi | 4a85dc8b | 2011-09-15 16:44:46 -0500 | [diff] [blame] | 1394 | |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1395 | return ret; |
| 1396 | } |
| 1397 | |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 1398 | static void free_irq_local(struct fsl_diu_data *data) |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1399 | { |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 1400 | struct diu __iomem *hw = data->diu_reg; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1401 | |
| 1402 | /* Disable all LCDC interrupt */ |
| 1403 | out_be32(&hw->int_mask, 0x1f); |
| 1404 | |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 1405 | free_irq(data->irq, NULL); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1406 | } |
| 1407 | |
| 1408 | #ifdef CONFIG_PM |
| 1409 | /* |
| 1410 | * Power management hooks. Note that we won't be called from IRQ context, |
| 1411 | * unlike the blank functions above, so we may sleep. |
| 1412 | */ |
Grant Likely | 2dc1158 | 2010-08-06 09:25:50 -0600 | [diff] [blame] | 1413 | static int fsl_diu_suspend(struct platform_device *ofdev, pm_message_t state) |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1414 | { |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 1415 | struct fsl_diu_data *data; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1416 | |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 1417 | data = dev_get_drvdata(&ofdev->dev); |
| 1418 | disable_lcdc(data->fsl_diu_info[0]); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1419 | |
| 1420 | return 0; |
| 1421 | } |
| 1422 | |
Grant Likely | 2dc1158 | 2010-08-06 09:25:50 -0600 | [diff] [blame] | 1423 | static int fsl_diu_resume(struct platform_device *ofdev) |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1424 | { |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 1425 | struct fsl_diu_data *data; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1426 | |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 1427 | data = dev_get_drvdata(&ofdev->dev); |
| 1428 | enable_lcdc(data->fsl_diu_info[0]); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1429 | |
| 1430 | return 0; |
| 1431 | } |
| 1432 | |
| 1433 | #else |
| 1434 | #define fsl_diu_suspend NULL |
| 1435 | #define fsl_diu_resume NULL |
| 1436 | #endif /* CONFIG_PM */ |
| 1437 | |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1438 | static ssize_t store_monitor(struct device *device, |
| 1439 | struct device_attribute *attr, const char *buf, size_t count) |
| 1440 | { |
Timur Tabi | 7653aaa | 2011-07-09 15:38:14 -0500 | [diff] [blame] | 1441 | enum fsl_diu_monitor_port old_monitor_port; |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 1442 | struct fsl_diu_data *data = |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1443 | container_of(attr, struct fsl_diu_data, dev_attr); |
| 1444 | |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 1445 | old_monitor_port = data->monitor_port; |
| 1446 | data->monitor_port = fsl_diu_name_to_port(buf); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1447 | |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 1448 | if (old_monitor_port != data->monitor_port) { |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1449 | /* All AOIs need adjust pixel format |
| 1450 | * fsl_diu_set_par only change the pixsel format here |
| 1451 | * unlikely to fail. */ |
Timur Tabi | ddd3d90 | 2011-12-02 17:03:27 -0600 | [diff] [blame] | 1452 | unsigned int i; |
| 1453 | |
| 1454 | for (i=0; i < NUM_AOIS; i++) |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 1455 | fsl_diu_set_par(&data->fsl_diu_info[i]); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1456 | } |
| 1457 | return count; |
| 1458 | } |
| 1459 | |
| 1460 | static ssize_t show_monitor(struct device *device, |
| 1461 | struct device_attribute *attr, char *buf) |
| 1462 | { |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 1463 | struct fsl_diu_data *data = |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1464 | container_of(attr, struct fsl_diu_data, dev_attr); |
Timur Tabi | 7653aaa | 2011-07-09 15:38:14 -0500 | [diff] [blame] | 1465 | |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 1466 | switch (data->monitor_port) { |
Timur Tabi | 7653aaa | 2011-07-09 15:38:14 -0500 | [diff] [blame] | 1467 | case FSL_DIU_PORT_DVI: |
| 1468 | return sprintf(buf, "DVI\n"); |
| 1469 | case FSL_DIU_PORT_LVDS: |
| 1470 | return sprintf(buf, "Single-link LVDS\n"); |
| 1471 | case FSL_DIU_PORT_DLVDS: |
| 1472 | return sprintf(buf, "Dual-link LVDS\n"); |
| 1473 | } |
| 1474 | |
| 1475 | return 0; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1476 | } |
| 1477 | |
Timur Tabi | 9e52ba6 | 2011-09-15 16:44:50 -0500 | [diff] [blame] | 1478 | static int __devinit fsl_diu_probe(struct platform_device *pdev) |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1479 | { |
Timur Tabi | 9e52ba6 | 2011-09-15 16:44:50 -0500 | [diff] [blame] | 1480 | struct device_node *np = pdev->dev.of_node; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1481 | struct mfb_info *mfbi; |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 1482 | struct fsl_diu_data *data; |
Anatolij Gustschin | 4b5006e | 2010-07-23 04:00:37 +0000 | [diff] [blame] | 1483 | int diu_mode; |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 1484 | dma_addr_t dma_addr; /* DMA addr of fsl_diu_data struct */ |
Timur Tabi | ddd3d90 | 2011-12-02 17:03:27 -0600 | [diff] [blame] | 1485 | unsigned int i; |
| 1486 | int ret; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1487 | |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 1488 | data = dma_alloc_coherent(&pdev->dev, sizeof(struct fsl_diu_data), |
| 1489 | &dma_addr, GFP_DMA | __GFP_ZERO); |
| 1490 | if (!data) |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1491 | return -ENOMEM; |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 1492 | data->dma_addr = dma_addr; |
Timur Tabi | ddd3d90 | 2011-12-02 17:03:27 -0600 | [diff] [blame] | 1493 | |
| 1494 | /* |
| 1495 | * dma_alloc_coherent() uses a page allocator, so the address is |
| 1496 | * always page-aligned. We need the memory to be 32-byte aligned, |
| 1497 | * so that's good. However, if one day the allocator changes, we |
| 1498 | * need to catch that. It's not worth the effort to handle unaligned |
| 1499 | * alloctions now because it's highly unlikely to ever be a problem. |
| 1500 | */ |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 1501 | if ((unsigned long)data & 31) { |
Timur Tabi | ddd3d90 | 2011-12-02 17:03:27 -0600 | [diff] [blame] | 1502 | dev_err(&pdev->dev, "misaligned allocation"); |
| 1503 | ret = -ENOMEM; |
| 1504 | goto error; |
| 1505 | } |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1506 | |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 1507 | spin_lock_init(&data->reg_lock); |
Timur Tabi | 3c755b7 | 2011-10-04 19:36:51 -0500 | [diff] [blame] | 1508 | |
Timur Tabi | ddd3d90 | 2011-12-02 17:03:27 -0600 | [diff] [blame] | 1509 | for (i = 0; i < NUM_AOIS; i++) { |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 1510 | struct fb_info *info = &data->fsl_diu_info[i]; |
Timur Tabi | ddd3d90 | 2011-12-02 17:03:27 -0600 | [diff] [blame] | 1511 | |
| 1512 | info->device = &pdev->dev; |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 1513 | info->par = &data->mfb[i]; |
Timur Tabi | ddd3d90 | 2011-12-02 17:03:27 -0600 | [diff] [blame] | 1514 | |
| 1515 | /* |
| 1516 | * We store the physical address of the AD in the reserved |
| 1517 | * 'paddr' field of the AD itself. |
| 1518 | */ |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 1519 | data->ad[i].paddr = DMA_ADDR(data, ad[i]); |
Timur Tabi | ddd3d90 | 2011-12-02 17:03:27 -0600 | [diff] [blame] | 1520 | |
| 1521 | info->fix.smem_start = 0; |
| 1522 | |
| 1523 | /* Initialize the AOI data structure */ |
| 1524 | mfbi = info->par; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1525 | memcpy(mfbi, &mfb_template[i], sizeof(struct mfb_info)); |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 1526 | mfbi->parent = data; |
| 1527 | mfbi->ad = &data->ad[i]; |
Anatolij Gustschin | 8b856f0 | 2010-07-23 04:00:39 +0000 | [diff] [blame] | 1528 | |
Timur Tabi | 2572df9 | 2011-09-28 16:19:51 -0500 | [diff] [blame] | 1529 | if (mfbi->index == PLANE0) { |
Anatolij Gustschin | 8b856f0 | 2010-07-23 04:00:39 +0000 | [diff] [blame] | 1530 | const u8 *prop; |
| 1531 | int len; |
| 1532 | |
| 1533 | /* Get EDID */ |
| 1534 | prop = of_get_property(np, "edid", &len); |
| 1535 | if (prop && len == EDID_LENGTH) |
| 1536 | mfbi->edid_data = kmemdup(prop, EDID_LENGTH, |
| 1537 | GFP_KERNEL); |
| 1538 | } |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1539 | } |
| 1540 | |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 1541 | data->diu_reg = of_iomap(np, 0); |
| 1542 | if (!data->diu_reg) { |
Timur Tabi | 9e52ba6 | 2011-09-15 16:44:50 -0500 | [diff] [blame] | 1543 | dev_err(&pdev->dev, "cannot map DIU registers\n"); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1544 | ret = -EFAULT; |
Timur Tabi | ddd3d90 | 2011-12-02 17:03:27 -0600 | [diff] [blame] | 1545 | goto error; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1546 | } |
| 1547 | |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 1548 | diu_mode = in_be32(&data->diu_reg->diu_mode); |
Timur Tabi | c4e5a02 | 2011-09-28 16:19:53 -0500 | [diff] [blame] | 1549 | if (diu_mode == MFB_MODE0) |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 1550 | out_be32(&data->diu_reg->diu_mode, 0); /* disable DIU */ |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1551 | |
| 1552 | /* Get the IRQ of the DIU */ |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 1553 | data->irq = irq_of_parse_and_map(np, 0); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1554 | |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 1555 | if (!data->irq) { |
Timur Tabi | 9e52ba6 | 2011-09-15 16:44:50 -0500 | [diff] [blame] | 1556 | dev_err(&pdev->dev, "could not get DIU IRQ\n"); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1557 | ret = -EINVAL; |
| 1558 | goto error; |
| 1559 | } |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 1560 | data->monitor_port = monitor_port; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1561 | |
Timur Tabi | ddd3d90 | 2011-12-02 17:03:27 -0600 | [diff] [blame] | 1562 | /* Initialize the dummy Area Descriptor */ |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 1563 | data->dummy_ad.addr = cpu_to_le32(DMA_ADDR(data, dummy_aoi)); |
| 1564 | data->dummy_ad.pix_fmt = 0x88882317; |
| 1565 | data->dummy_ad.src_size_g_alpha = cpu_to_le32((4 << 12) | 4); |
| 1566 | data->dummy_ad.aoi_size = cpu_to_le32((4 << 16) | 2); |
| 1567 | data->dummy_ad.offset_xyi = 0; |
| 1568 | data->dummy_ad.offset_xyd = 0; |
| 1569 | data->dummy_ad.next_ad = 0; |
| 1570 | data->dummy_ad.paddr = DMA_ADDR(data, dummy_ad); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1571 | |
Anatolij Gustschin | 4b5006e | 2010-07-23 04:00:37 +0000 | [diff] [blame] | 1572 | /* |
| 1573 | * Let DIU display splash screen if it was pre-initialized |
| 1574 | * by the bootloader, set dummy area descriptor otherwise. |
| 1575 | */ |
Timur Tabi | c4e5a02 | 2011-09-28 16:19:53 -0500 | [diff] [blame] | 1576 | if (diu_mode == MFB_MODE0) |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 1577 | out_be32(&data->diu_reg->desc[0], data->dummy_ad.paddr); |
Anatolij Gustschin | 4b5006e | 2010-07-23 04:00:37 +0000 | [diff] [blame] | 1578 | |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 1579 | out_be32(&data->diu_reg->desc[1], data->dummy_ad.paddr); |
| 1580 | out_be32(&data->diu_reg->desc[2], data->dummy_ad.paddr); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1581 | |
Timur Tabi | ddd3d90 | 2011-12-02 17:03:27 -0600 | [diff] [blame] | 1582 | for (i = 0; i < NUM_AOIS; i++) { |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 1583 | ret = install_fb(&data->fsl_diu_info[i]); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1584 | if (ret) { |
Timur Tabi | 9e52ba6 | 2011-09-15 16:44:50 -0500 | [diff] [blame] | 1585 | dev_err(&pdev->dev, "could not register fb %d\n", i); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1586 | goto error; |
| 1587 | } |
| 1588 | } |
| 1589 | |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 1590 | if (request_irq_local(data)) { |
Timur Tabi | 9e52ba6 | 2011-09-15 16:44:50 -0500 | [diff] [blame] | 1591 | dev_err(&pdev->dev, "could not claim irq\n"); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1592 | goto error; |
| 1593 | } |
| 1594 | |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 1595 | sysfs_attr_init(&data->dev_attr.attr); |
| 1596 | data->dev_attr.attr.name = "monitor"; |
| 1597 | data->dev_attr.attr.mode = S_IRUGO|S_IWUSR; |
| 1598 | data->dev_attr.show = show_monitor; |
| 1599 | data->dev_attr.store = store_monitor; |
| 1600 | ret = device_create_file(&pdev->dev, &data->dev_attr); |
Timur Tabi | ddd3d90 | 2011-12-02 17:03:27 -0600 | [diff] [blame] | 1601 | if (ret) { |
Timur Tabi | 9e52ba6 | 2011-09-15 16:44:50 -0500 | [diff] [blame] | 1602 | dev_err(&pdev->dev, "could not create sysfs file %s\n", |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 1603 | data->dev_attr.attr.name); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1604 | } |
| 1605 | |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 1606 | dev_set_drvdata(&pdev->dev, data); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1607 | return 0; |
| 1608 | |
| 1609 | error: |
Timur Tabi | ddd3d90 | 2011-12-02 17:03:27 -0600 | [diff] [blame] | 1610 | for (i = 0; i < NUM_AOIS; i++) |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 1611 | uninstall_fb(&data->fsl_diu_info[i]); |
Timur Tabi | 3f78bbd | 2011-09-15 16:44:56 -0500 | [diff] [blame] | 1612 | |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 1613 | iounmap(data->diu_reg); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1614 | |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 1615 | dma_free_coherent(&pdev->dev, sizeof(struct fsl_diu_data), data, |
| 1616 | data->dma_addr); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1617 | |
| 1618 | return ret; |
| 1619 | } |
| 1620 | |
Timur Tabi | 9e52ba6 | 2011-09-15 16:44:50 -0500 | [diff] [blame] | 1621 | static int fsl_diu_remove(struct platform_device *pdev) |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1622 | { |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 1623 | struct fsl_diu_data *data; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1624 | int i; |
| 1625 | |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 1626 | data = dev_get_drvdata(&pdev->dev); |
| 1627 | disable_lcdc(&data->fsl_diu_info[0]); |
| 1628 | free_irq_local(data); |
Timur Tabi | ddd3d90 | 2011-12-02 17:03:27 -0600 | [diff] [blame] | 1629 | |
| 1630 | for (i = 0; i < NUM_AOIS; i++) |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 1631 | uninstall_fb(&data->fsl_diu_info[i]); |
Timur Tabi | ddd3d90 | 2011-12-02 17:03:27 -0600 | [diff] [blame] | 1632 | |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 1633 | iounmap(data->diu_reg); |
Timur Tabi | ddd3d90 | 2011-12-02 17:03:27 -0600 | [diff] [blame] | 1634 | |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame^] | 1635 | dma_free_coherent(&pdev->dev, sizeof(struct fsl_diu_data), data, |
| 1636 | data->dma_addr); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1637 | |
| 1638 | return 0; |
| 1639 | } |
| 1640 | |
| 1641 | #ifndef MODULE |
| 1642 | static int __init fsl_diu_setup(char *options) |
| 1643 | { |
| 1644 | char *opt; |
| 1645 | unsigned long val; |
| 1646 | |
| 1647 | if (!options || !*options) |
| 1648 | return 0; |
| 1649 | |
| 1650 | while ((opt = strsep(&options, ",")) != NULL) { |
| 1651 | if (!*opt) |
| 1652 | continue; |
| 1653 | if (!strncmp(opt, "monitor=", 8)) { |
Timur Tabi | 7653aaa | 2011-07-09 15:38:14 -0500 | [diff] [blame] | 1654 | monitor_port = fsl_diu_name_to_port(opt + 8); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1655 | } else if (!strncmp(opt, "bpp=", 4)) { |
| 1656 | if (!strict_strtoul(opt + 4, 10, &val)) |
| 1657 | default_bpp = val; |
| 1658 | } else |
| 1659 | fb_mode = opt; |
| 1660 | } |
| 1661 | |
| 1662 | return 0; |
| 1663 | } |
| 1664 | #endif |
| 1665 | |
| 1666 | static struct of_device_id fsl_diu_match[] = { |
Anatolij Gustschin | d24720a | 2010-02-17 07:33:22 -0700 | [diff] [blame] | 1667 | #ifdef CONFIG_PPC_MPC512x |
| 1668 | { |
| 1669 | .compatible = "fsl,mpc5121-diu", |
| 1670 | }, |
| 1671 | #endif |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1672 | { |
| 1673 | .compatible = "fsl,diu", |
| 1674 | }, |
| 1675 | {} |
| 1676 | }; |
| 1677 | MODULE_DEVICE_TABLE(of, fsl_diu_match); |
| 1678 | |
Grant Likely | 28541d0 | 2011-02-22 21:07:43 -0700 | [diff] [blame] | 1679 | static struct platform_driver fsl_diu_driver = { |
Grant Likely | 4018294 | 2010-04-13 16:13:02 -0700 | [diff] [blame] | 1680 | .driver = { |
Timur Tabi | f8c6bf6 | 2011-09-15 16:44:53 -0500 | [diff] [blame] | 1681 | .name = "fsl-diu-fb", |
Grant Likely | 4018294 | 2010-04-13 16:13:02 -0700 | [diff] [blame] | 1682 | .owner = THIS_MODULE, |
| 1683 | .of_match_table = fsl_diu_match, |
| 1684 | }, |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1685 | .probe = fsl_diu_probe, |
| 1686 | .remove = fsl_diu_remove, |
| 1687 | .suspend = fsl_diu_suspend, |
| 1688 | .resume = fsl_diu_resume, |
| 1689 | }; |
| 1690 | |
| 1691 | static int __init fsl_diu_init(void) |
| 1692 | { |
| 1693 | #ifdef CONFIG_NOT_COHERENT_CACHE |
| 1694 | struct device_node *np; |
| 1695 | const u32 *prop; |
| 1696 | #endif |
| 1697 | int ret; |
| 1698 | #ifndef MODULE |
| 1699 | char *option; |
| 1700 | |
| 1701 | /* |
| 1702 | * For kernel boot options (in 'video=xxxfb:<options>' format) |
| 1703 | */ |
| 1704 | if (fb_get_options("fslfb", &option)) |
| 1705 | return -ENODEV; |
| 1706 | fsl_diu_setup(option); |
Timur Tabi | 7653aaa | 2011-07-09 15:38:14 -0500 | [diff] [blame] | 1707 | #else |
| 1708 | monitor_port = fsl_diu_name_to_port(monitor_string); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1709 | #endif |
Timur Tabi | 154152a | 2011-09-15 16:44:47 -0500 | [diff] [blame] | 1710 | pr_info("Freescale Display Interface Unit (DIU) framebuffer driver\n"); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1711 | |
| 1712 | #ifdef CONFIG_NOT_COHERENT_CACHE |
| 1713 | np = of_find_node_by_type(NULL, "cpu"); |
| 1714 | if (!np) { |
Timur Tabi | 154152a | 2011-09-15 16:44:47 -0500 | [diff] [blame] | 1715 | pr_err("fsl-diu-fb: can't find 'cpu' device node\n"); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1716 | return -ENODEV; |
| 1717 | } |
| 1718 | |
| 1719 | prop = of_get_property(np, "d-cache-size", NULL); |
Julia Lawall | 5394ba0 | 2008-08-05 13:01:28 -0700 | [diff] [blame] | 1720 | if (prop == NULL) { |
Timur Tabi | 154152a | 2011-09-15 16:44:47 -0500 | [diff] [blame] | 1721 | pr_err("fsl-diu-fb: missing 'd-cache-size' property' " |
| 1722 | "in 'cpu' node\n"); |
Julia Lawall | 5394ba0 | 2008-08-05 13:01:28 -0700 | [diff] [blame] | 1723 | of_node_put(np); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1724 | return -ENODEV; |
Julia Lawall | 5394ba0 | 2008-08-05 13:01:28 -0700 | [diff] [blame] | 1725 | } |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1726 | |
Timur Tabi | 4a85dc8b | 2011-09-15 16:44:46 -0500 | [diff] [blame] | 1727 | /* |
| 1728 | * Freescale PLRU requires 13/8 times the cache size to do a proper |
| 1729 | * displacement flush |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1730 | */ |
Timur Tabi | 9e52ba6 | 2011-09-15 16:44:50 -0500 | [diff] [blame] | 1731 | coherence_data_size = be32_to_cpup(prop) * 13; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1732 | coherence_data_size /= 8; |
| 1733 | |
| 1734 | prop = of_get_property(np, "d-cache-line-size", NULL); |
Julia Lawall | 5394ba0 | 2008-08-05 13:01:28 -0700 | [diff] [blame] | 1735 | if (prop == NULL) { |
Timur Tabi | 154152a | 2011-09-15 16:44:47 -0500 | [diff] [blame] | 1736 | pr_err("fsl-diu-fb: missing 'd-cache-line-size' property' " |
| 1737 | "in 'cpu' node\n"); |
Julia Lawall | 5394ba0 | 2008-08-05 13:01:28 -0700 | [diff] [blame] | 1738 | of_node_put(np); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1739 | return -ENODEV; |
Julia Lawall | 5394ba0 | 2008-08-05 13:01:28 -0700 | [diff] [blame] | 1740 | } |
Timur Tabi | 9e52ba6 | 2011-09-15 16:44:50 -0500 | [diff] [blame] | 1741 | d_cache_line_size = be32_to_cpup(prop); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1742 | |
| 1743 | of_node_put(np); |
| 1744 | coherence_data = vmalloc(coherence_data_size); |
| 1745 | if (!coherence_data) |
| 1746 | return -ENOMEM; |
| 1747 | #endif |
Timur Tabi | 4a85dc8b | 2011-09-15 16:44:46 -0500 | [diff] [blame] | 1748 | |
Grant Likely | 28541d0 | 2011-02-22 21:07:43 -0700 | [diff] [blame] | 1749 | ret = platform_driver_register(&fsl_diu_driver); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1750 | if (ret) { |
Timur Tabi | 154152a | 2011-09-15 16:44:47 -0500 | [diff] [blame] | 1751 | pr_err("fsl-diu-fb: failed to register platform driver\n"); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1752 | #if defined(CONFIG_NOT_COHERENT_CACHE) |
| 1753 | vfree(coherence_data); |
| 1754 | #endif |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1755 | } |
| 1756 | return ret; |
| 1757 | } |
| 1758 | |
| 1759 | static void __exit fsl_diu_exit(void) |
| 1760 | { |
Grant Likely | 28541d0 | 2011-02-22 21:07:43 -0700 | [diff] [blame] | 1761 | platform_driver_unregister(&fsl_diu_driver); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1762 | #if defined(CONFIG_NOT_COHERENT_CACHE) |
| 1763 | vfree(coherence_data); |
| 1764 | #endif |
| 1765 | } |
| 1766 | |
| 1767 | module_init(fsl_diu_init); |
| 1768 | module_exit(fsl_diu_exit); |
| 1769 | |
| 1770 | MODULE_AUTHOR("York Sun <yorksun@freescale.com>"); |
| 1771 | MODULE_DESCRIPTION("Freescale DIU framebuffer driver"); |
| 1772 | MODULE_LICENSE("GPL"); |
| 1773 | |
| 1774 | module_param_named(mode, fb_mode, charp, 0); |
| 1775 | MODULE_PARM_DESC(mode, |
| 1776 | "Specify resolution as \"<xres>x<yres>[-<bpp>][@<refresh>]\" "); |
| 1777 | module_param_named(bpp, default_bpp, ulong, 0); |
Timur Tabi | 154152a | 2011-09-15 16:44:47 -0500 | [diff] [blame] | 1778 | MODULE_PARM_DESC(bpp, "Specify bit-per-pixel if not specified in 'mode'"); |
Timur Tabi | 7653aaa | 2011-07-09 15:38:14 -0500 | [diff] [blame] | 1779 | module_param_named(monitor, monitor_string, charp, 0); |
| 1780 | MODULE_PARM_DESC(monitor, "Specify the monitor port " |
| 1781 | "(\"dvi\", \"lvds\", or \"dlvds\") if supported by the platform"); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1782 | |