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 |
Timur Tabi | ddd3d90 | 2011-12-02 17:03:27 -0600 | [diff] [blame] | 355 | * @monitor_port: the monitor port this DIU is connected to |
| 356 | * @diu_reg: pointer to the DIU hardware registers |
| 357 | * @reg_lock: spinlock for register access |
| 358 | * @dummy_aoi: video buffer for the 4x4 32-bit dummy AOI |
| 359 | * dummy_ad: DIU Area Descriptor for the dummy AOI |
| 360 | * @ad[]: Area Descriptors for each real AOI |
| 361 | * @gamma: gamma color table |
| 362 | * @cursor: hardware cursor data |
| 363 | * |
| 364 | * This data structure must be allocated with 32-byte alignment, so that the |
| 365 | * internal fields can be aligned properly. |
| 366 | */ |
| 367 | struct fsl_diu_data { |
| 368 | dma_addr_t dma_addr; |
| 369 | struct fb_info fsl_diu_info[NUM_AOIS]; |
| 370 | struct mfb_info mfb[NUM_AOIS]; |
| 371 | struct device_attribute dev_attr; |
| 372 | unsigned int irq; |
Timur Tabi | ddd3d90 | 2011-12-02 17:03:27 -0600 | [diff] [blame] | 373 | enum fsl_diu_monitor_port monitor_port; |
| 374 | struct diu __iomem *diu_reg; |
| 375 | spinlock_t reg_lock; |
| 376 | u8 dummy_aoi[4 * 4 * 4]; |
| 377 | struct diu_ad dummy_ad __aligned(8); |
| 378 | struct diu_ad ad[NUM_AOIS] __aligned(8); |
| 379 | u8 gamma[256 * 3] __aligned(32); |
| 380 | u8 cursor[MAX_CURS * MAX_CURS * 2] __aligned(32); |
| 381 | } __aligned(32); |
| 382 | |
| 383 | /* Determine the DMA address of a member of the fsl_diu_data structure */ |
| 384 | #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] | 385 | |
| 386 | static struct mfb_info mfb_template[] = { |
Timur Tabi | 2572df9 | 2011-09-28 16:19:51 -0500 | [diff] [blame] | 387 | { |
| 388 | .index = PLANE0, |
Timur Tabi | 4a85dc8b | 2011-09-15 16:44:46 -0500 | [diff] [blame] | 389 | .id = "Panel0", |
| 390 | .registered = 0, |
| 391 | .count = 0, |
| 392 | .x_aoi_d = 0, |
| 393 | .y_aoi_d = 0, |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 394 | }, |
Timur Tabi | 2572df9 | 2011-09-28 16:19:51 -0500 | [diff] [blame] | 395 | { |
| 396 | .index = PLANE1_AOI0, |
Timur Tabi | 4a85dc8b | 2011-09-15 16:44:46 -0500 | [diff] [blame] | 397 | .id = "Panel1 AOI0", |
| 398 | .registered = 0, |
| 399 | .g_alpha = 0xff, |
| 400 | .count = 0, |
| 401 | .x_aoi_d = 0, |
| 402 | .y_aoi_d = 0, |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 403 | }, |
Timur Tabi | 2572df9 | 2011-09-28 16:19:51 -0500 | [diff] [blame] | 404 | { |
| 405 | .index = PLANE1_AOI1, |
Timur Tabi | 4a85dc8b | 2011-09-15 16:44:46 -0500 | [diff] [blame] | 406 | .id = "Panel1 AOI1", |
| 407 | .registered = 0, |
| 408 | .g_alpha = 0xff, |
| 409 | .count = 0, |
| 410 | .x_aoi_d = 0, |
| 411 | .y_aoi_d = 480, |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 412 | }, |
Timur Tabi | 2572df9 | 2011-09-28 16:19:51 -0500 | [diff] [blame] | 413 | { |
| 414 | .index = PLANE2_AOI0, |
Timur Tabi | 4a85dc8b | 2011-09-15 16:44:46 -0500 | [diff] [blame] | 415 | .id = "Panel2 AOI0", |
| 416 | .registered = 0, |
| 417 | .g_alpha = 0xff, |
| 418 | .count = 0, |
| 419 | .x_aoi_d = 640, |
| 420 | .y_aoi_d = 0, |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 421 | }, |
Timur Tabi | 2572df9 | 2011-09-28 16:19:51 -0500 | [diff] [blame] | 422 | { |
| 423 | .index = PLANE2_AOI1, |
Timur Tabi | 4a85dc8b | 2011-09-15 16:44:46 -0500 | [diff] [blame] | 424 | .id = "Panel2 AOI1", |
| 425 | .registered = 0, |
| 426 | .g_alpha = 0xff, |
| 427 | .count = 0, |
| 428 | .x_aoi_d = 640, |
| 429 | .y_aoi_d = 480, |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 430 | }, |
| 431 | }; |
| 432 | |
Timur Tabi | 5cc2a36 | 2012-10-16 17:33:46 -0500 | [diff] [blame^] | 433 | #ifdef DEBUG |
| 434 | static void __attribute__ ((unused)) fsl_diu_dump(struct diu __iomem *hw) |
| 435 | { |
| 436 | mb(); |
| 437 | pr_debug("DIU: desc=%08x,%08x,%08x, gamma=%08x pallete=%08x " |
| 438 | "cursor=%08x curs_pos=%08x diu_mode=%08x bgnd=%08x " |
| 439 | "disp_size=%08x hsyn_para=%08x vsyn_para=%08x syn_pol=%08x " |
| 440 | "thresholds=%08x int_mask=%08x plut=%08x\n", |
| 441 | hw->desc[0], hw->desc[1], hw->desc[2], hw->gamma, |
| 442 | hw->pallete, hw->cursor, hw->curs_pos, hw->diu_mode, |
| 443 | hw->bgnd, hw->disp_size, hw->hsyn_para, hw->vsyn_para, |
| 444 | hw->syn_pol, hw->thresholds, hw->int_mask, hw->plut); |
| 445 | rmb(); |
| 446 | } |
| 447 | #endif |
| 448 | |
Timur Tabi | 6b51d51 | 2008-07-23 21:31:39 -0700 | [diff] [blame] | 449 | /** |
Timur Tabi | 7653aaa | 2011-07-09 15:38:14 -0500 | [diff] [blame] | 450 | * fsl_diu_name_to_port - convert a port name to a monitor port enum |
| 451 | * |
| 452 | * Takes the name of a monitor port ("dvi", "lvds", or "dlvds") and returns |
| 453 | * the enum fsl_diu_monitor_port that corresponds to that string. |
| 454 | * |
| 455 | * For compatibility with older versions, a number ("0", "1", or "2") is also |
| 456 | * supported. |
| 457 | * |
| 458 | * If the string is unknown, DVI is assumed. |
| 459 | * |
| 460 | * If the particular port is not supported by the platform, another port |
| 461 | * (platform-specific) is chosen instead. |
| 462 | */ |
| 463 | static enum fsl_diu_monitor_port fsl_diu_name_to_port(const char *s) |
| 464 | { |
| 465 | enum fsl_diu_monitor_port port = FSL_DIU_PORT_DVI; |
| 466 | unsigned long val; |
| 467 | |
| 468 | if (s) { |
| 469 | if (!strict_strtoul(s, 10, &val) && (val <= 2)) |
| 470 | port = (enum fsl_diu_monitor_port) val; |
| 471 | else if (strncmp(s, "lvds", 4) == 0) |
| 472 | port = FSL_DIU_PORT_LVDS; |
| 473 | else if (strncmp(s, "dlvds", 5) == 0) |
| 474 | port = FSL_DIU_PORT_DLVDS; |
| 475 | } |
| 476 | |
| 477 | return diu_ops.valid_monitor_port(port); |
| 478 | } |
| 479 | |
Anatolij Gustschin | 0d9dab39 | 2010-07-23 04:00:35 +0000 | [diff] [blame] | 480 | /* |
| 481 | * Workaround for failed writing desc register of planes. |
| 482 | * Needed with MPC5121 DIU rev 2.0 silicon. |
| 483 | */ |
| 484 | void wr_reg_wa(u32 *reg, u32 val) |
| 485 | { |
| 486 | do { |
| 487 | out_be32(reg, val); |
| 488 | } while (in_be32(reg) != val); |
| 489 | } |
| 490 | |
Timur Tabi | 7e47c21 | 2011-09-28 16:19:52 -0500 | [diff] [blame] | 491 | static void fsl_diu_enable_panel(struct fb_info *info) |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 492 | { |
| 493 | struct mfb_info *pmfbi, *cmfbi, *mfbi = info->par; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 494 | struct diu_ad *ad = mfbi->ad; |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 495 | struct fsl_diu_data *data = mfbi->parent; |
| 496 | struct diu __iomem *hw = data->diu_reg; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 497 | |
Timur Tabi | 7e47c21 | 2011-09-28 16:19:52 -0500 | [diff] [blame] | 498 | switch (mfbi->index) { |
| 499 | case PLANE0: |
| 500 | if (hw->desc[0] != ad->paddr) |
| 501 | wr_reg_wa(&hw->desc[0], ad->paddr); |
| 502 | break; |
| 503 | case PLANE1_AOI0: |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 504 | cmfbi = &data->mfb[2]; |
Timur Tabi | 7e47c21 | 2011-09-28 16:19:52 -0500 | [diff] [blame] | 505 | if (hw->desc[1] != ad->paddr) { /* AOI0 closed */ |
| 506 | if (cmfbi->count > 0) /* AOI1 open */ |
| 507 | ad->next_ad = |
| 508 | cpu_to_le32(cmfbi->ad->paddr); |
| 509 | else |
| 510 | ad->next_ad = 0; |
| 511 | wr_reg_wa(&hw->desc[1], ad->paddr); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 512 | } |
Timur Tabi | 7e47c21 | 2011-09-28 16:19:52 -0500 | [diff] [blame] | 513 | break; |
| 514 | case PLANE2_AOI0: |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 515 | cmfbi = &data->mfb[4]; |
Timur Tabi | 7e47c21 | 2011-09-28 16:19:52 -0500 | [diff] [blame] | 516 | if (hw->desc[2] != ad->paddr) { /* AOI0 closed */ |
| 517 | if (cmfbi->count > 0) /* AOI1 open */ |
| 518 | ad->next_ad = |
| 519 | cpu_to_le32(cmfbi->ad->paddr); |
| 520 | else |
| 521 | ad->next_ad = 0; |
| 522 | wr_reg_wa(&hw->desc[2], ad->paddr); |
| 523 | } |
| 524 | break; |
| 525 | case PLANE1_AOI1: |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 526 | pmfbi = &data->mfb[1]; |
Timur Tabi | 7e47c21 | 2011-09-28 16:19:52 -0500 | [diff] [blame] | 527 | ad->next_ad = 0; |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 528 | if (hw->desc[1] == data->dummy_ad.paddr) |
Timur Tabi | 7e47c21 | 2011-09-28 16:19:52 -0500 | [diff] [blame] | 529 | wr_reg_wa(&hw->desc[1], ad->paddr); |
| 530 | else /* AOI0 open */ |
| 531 | pmfbi->ad->next_ad = cpu_to_le32(ad->paddr); |
| 532 | break; |
| 533 | case PLANE2_AOI1: |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 534 | pmfbi = &data->mfb[3]; |
Timur Tabi | 7e47c21 | 2011-09-28 16:19:52 -0500 | [diff] [blame] | 535 | ad->next_ad = 0; |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 536 | if (hw->desc[2] == data->dummy_ad.paddr) |
Timur Tabi | 7e47c21 | 2011-09-28 16:19:52 -0500 | [diff] [blame] | 537 | wr_reg_wa(&hw->desc[2], ad->paddr); |
| 538 | else /* AOI0 was open */ |
| 539 | pmfbi->ad->next_ad = cpu_to_le32(ad->paddr); |
| 540 | break; |
| 541 | } |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 542 | } |
| 543 | |
Timur Tabi | 2572df9 | 2011-09-28 16:19:51 -0500 | [diff] [blame] | 544 | static void fsl_diu_disable_panel(struct fb_info *info) |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 545 | { |
| 546 | struct mfb_info *pmfbi, *cmfbi, *mfbi = info->par; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 547 | struct diu_ad *ad = mfbi->ad; |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 548 | struct fsl_diu_data *data = mfbi->parent; |
| 549 | struct diu __iomem *hw = data->diu_reg; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 550 | |
| 551 | switch (mfbi->index) { |
Timur Tabi | 2572df9 | 2011-09-28 16:19:51 -0500 | [diff] [blame] | 552 | case PLANE0: |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 553 | if (hw->desc[0] != data->dummy_ad.paddr) |
| 554 | wr_reg_wa(&hw->desc[0], data->dummy_ad.paddr); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 555 | break; |
Timur Tabi | 2572df9 | 2011-09-28 16:19:51 -0500 | [diff] [blame] | 556 | case PLANE1_AOI0: |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 557 | cmfbi = &data->mfb[2]; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 558 | if (cmfbi->count > 0) /* AOI1 is open */ |
Anatolij Gustschin | 0d9dab39 | 2010-07-23 04:00:35 +0000 | [diff] [blame] | 559 | wr_reg_wa(&hw->desc[1], cmfbi->ad->paddr); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 560 | /* move AOI1 to the first */ |
| 561 | else /* AOI1 was closed */ |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 562 | wr_reg_wa(&hw->desc[1], data->dummy_ad.paddr); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 563 | /* close AOI 0 */ |
| 564 | break; |
Timur Tabi | 2572df9 | 2011-09-28 16:19:51 -0500 | [diff] [blame] | 565 | case PLANE2_AOI0: |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 566 | cmfbi = &data->mfb[4]; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 567 | if (cmfbi->count > 0) /* AOI1 is open */ |
Anatolij Gustschin | 0d9dab39 | 2010-07-23 04:00:35 +0000 | [diff] [blame] | 568 | wr_reg_wa(&hw->desc[2], cmfbi->ad->paddr); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 569 | /* move AOI1 to the first */ |
| 570 | else /* AOI1 was closed */ |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 571 | wr_reg_wa(&hw->desc[2], data->dummy_ad.paddr); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 572 | /* close AOI 0 */ |
| 573 | break; |
Timur Tabi | 2572df9 | 2011-09-28 16:19:51 -0500 | [diff] [blame] | 574 | case PLANE1_AOI1: |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 575 | pmfbi = &data->mfb[1]; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 576 | if (hw->desc[1] != ad->paddr) { |
| 577 | /* AOI1 is not the first in the chain */ |
| 578 | if (pmfbi->count > 0) |
| 579 | /* AOI0 is open, must be the first */ |
| 580 | pmfbi->ad->next_ad = 0; |
| 581 | } else /* AOI1 is the first in the chain */ |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 582 | wr_reg_wa(&hw->desc[1], data->dummy_ad.paddr); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 583 | /* close AOI 1 */ |
| 584 | break; |
Timur Tabi | 2572df9 | 2011-09-28 16:19:51 -0500 | [diff] [blame] | 585 | case PLANE2_AOI1: |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 586 | pmfbi = &data->mfb[3]; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 587 | if (hw->desc[2] != ad->paddr) { |
| 588 | /* AOI1 is not the first in the chain */ |
| 589 | if (pmfbi->count > 0) |
| 590 | /* AOI0 is open, must be the first */ |
| 591 | pmfbi->ad->next_ad = 0; |
| 592 | } else /* AOI1 is the first in the chain */ |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 593 | wr_reg_wa(&hw->desc[2], data->dummy_ad.paddr); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 594 | /* close AOI 1 */ |
| 595 | break; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 596 | } |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | static void enable_lcdc(struct fb_info *info) |
| 600 | { |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 601 | struct mfb_info *mfbi = info->par; |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 602 | struct fsl_diu_data *data = mfbi->parent; |
| 603 | struct diu __iomem *hw = data->diu_reg; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 604 | |
Timur Tabi | d397e916 | 2011-12-19 16:26:16 -0600 | [diff] [blame] | 605 | out_be32(&hw->diu_mode, MFB_MODE1); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | static void disable_lcdc(struct fb_info *info) |
| 609 | { |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 610 | struct mfb_info *mfbi = info->par; |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 611 | struct fsl_diu_data *data = mfbi->parent; |
| 612 | struct diu __iomem *hw = data->diu_reg; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 613 | |
Timur Tabi | d397e916 | 2011-12-19 16:26:16 -0600 | [diff] [blame] | 614 | out_be32(&hw->diu_mode, 0); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | static void adjust_aoi_size_position(struct fb_var_screeninfo *var, |
| 618 | struct fb_info *info) |
| 619 | { |
| 620 | struct mfb_info *lower_aoi_mfbi, *upper_aoi_mfbi, *mfbi = info->par; |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 621 | struct fsl_diu_data *data = mfbi->parent; |
Timur Tabi | 2572df9 | 2011-09-28 16:19:51 -0500 | [diff] [blame] | 622 | int available_height, upper_aoi_bottom; |
| 623 | enum mfb_index index = mfbi->index; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 624 | int lower_aoi_is_open, upper_aoi_is_open; |
| 625 | __u32 base_plane_width, base_plane_height, upper_aoi_height; |
| 626 | |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 627 | base_plane_width = data->fsl_diu_info[0].var.xres; |
| 628 | base_plane_height = data->fsl_diu_info[0].var.yres; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 629 | |
York Sun | fdfaa48 | 2008-08-15 00:40:29 -0700 | [diff] [blame] | 630 | if (mfbi->x_aoi_d < 0) |
| 631 | mfbi->x_aoi_d = 0; |
| 632 | if (mfbi->y_aoi_d < 0) |
| 633 | mfbi->y_aoi_d = 0; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 634 | switch (index) { |
Timur Tabi | 2572df9 | 2011-09-28 16:19:51 -0500 | [diff] [blame] | 635 | case PLANE0: |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 636 | if (mfbi->x_aoi_d != 0) |
| 637 | mfbi->x_aoi_d = 0; |
| 638 | if (mfbi->y_aoi_d != 0) |
| 639 | mfbi->y_aoi_d = 0; |
| 640 | break; |
Timur Tabi | 2572df9 | 2011-09-28 16:19:51 -0500 | [diff] [blame] | 641 | case PLANE1_AOI0: |
| 642 | case PLANE2_AOI0: |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 643 | lower_aoi_mfbi = data->fsl_diu_info[index+1].par; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 644 | lower_aoi_is_open = lower_aoi_mfbi->count > 0 ? 1 : 0; |
| 645 | if (var->xres > base_plane_width) |
| 646 | var->xres = base_plane_width; |
| 647 | if ((mfbi->x_aoi_d + var->xres) > base_plane_width) |
| 648 | mfbi->x_aoi_d = base_plane_width - var->xres; |
| 649 | |
| 650 | if (lower_aoi_is_open) |
| 651 | available_height = lower_aoi_mfbi->y_aoi_d; |
| 652 | else |
| 653 | available_height = base_plane_height; |
| 654 | if (var->yres > available_height) |
| 655 | var->yres = available_height; |
| 656 | if ((mfbi->y_aoi_d + var->yres) > available_height) |
| 657 | mfbi->y_aoi_d = available_height - var->yres; |
| 658 | break; |
Timur Tabi | 2572df9 | 2011-09-28 16:19:51 -0500 | [diff] [blame] | 659 | case PLANE1_AOI1: |
| 660 | case PLANE2_AOI1: |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 661 | upper_aoi_mfbi = data->fsl_diu_info[index-1].par; |
| 662 | upper_aoi_height = data->fsl_diu_info[index-1].var.yres; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 663 | upper_aoi_bottom = upper_aoi_mfbi->y_aoi_d + upper_aoi_height; |
| 664 | upper_aoi_is_open = upper_aoi_mfbi->count > 0 ? 1 : 0; |
| 665 | if (var->xres > base_plane_width) |
| 666 | var->xres = base_plane_width; |
| 667 | if ((mfbi->x_aoi_d + var->xres) > base_plane_width) |
| 668 | mfbi->x_aoi_d = base_plane_width - var->xres; |
| 669 | if (mfbi->y_aoi_d < 0) |
| 670 | mfbi->y_aoi_d = 0; |
| 671 | if (upper_aoi_is_open) { |
| 672 | if (mfbi->y_aoi_d < upper_aoi_bottom) |
| 673 | mfbi->y_aoi_d = upper_aoi_bottom; |
| 674 | available_height = base_plane_height |
| 675 | - upper_aoi_bottom; |
| 676 | } else |
| 677 | available_height = base_plane_height; |
| 678 | if (var->yres > available_height) |
| 679 | var->yres = available_height; |
| 680 | if ((mfbi->y_aoi_d + var->yres) > base_plane_height) |
| 681 | mfbi->y_aoi_d = base_plane_height - var->yres; |
| 682 | break; |
| 683 | } |
| 684 | } |
| 685 | /* |
| 686 | * Checks to see if the hardware supports the state requested by var passed |
| 687 | * in. This function does not alter the hardware state! If the var passed in |
| 688 | * is slightly off by what the hardware can support then we alter the var |
| 689 | * PASSED in to what we can do. If the hardware doesn't support mode change |
| 690 | * a -EINVAL will be returned by the upper layers. |
| 691 | */ |
| 692 | static int fsl_diu_check_var(struct fb_var_screeninfo *var, |
| 693 | struct fb_info *info) |
| 694 | { |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 695 | if (var->xres_virtual < var->xres) |
| 696 | var->xres_virtual = var->xres; |
| 697 | if (var->yres_virtual < var->yres) |
| 698 | var->yres_virtual = var->yres; |
| 699 | |
| 700 | if (var->xoffset < 0) |
| 701 | var->xoffset = 0; |
| 702 | |
| 703 | if (var->yoffset < 0) |
| 704 | var->yoffset = 0; |
| 705 | |
| 706 | if (var->xoffset + info->var.xres > info->var.xres_virtual) |
| 707 | var->xoffset = info->var.xres_virtual - info->var.xres; |
| 708 | |
| 709 | if (var->yoffset + info->var.yres > info->var.yres_virtual) |
| 710 | var->yoffset = info->var.yres_virtual - info->var.yres; |
| 711 | |
| 712 | if ((var->bits_per_pixel != 32) && (var->bits_per_pixel != 24) && |
| 713 | (var->bits_per_pixel != 16)) |
| 714 | var->bits_per_pixel = default_bpp; |
| 715 | |
| 716 | switch (var->bits_per_pixel) { |
| 717 | case 16: |
| 718 | var->red.length = 5; |
| 719 | var->red.offset = 11; |
| 720 | var->red.msb_right = 0; |
| 721 | |
| 722 | var->green.length = 6; |
| 723 | var->green.offset = 5; |
| 724 | var->green.msb_right = 0; |
| 725 | |
| 726 | var->blue.length = 5; |
| 727 | var->blue.offset = 0; |
| 728 | var->blue.msb_right = 0; |
| 729 | |
| 730 | var->transp.length = 0; |
| 731 | var->transp.offset = 0; |
| 732 | var->transp.msb_right = 0; |
| 733 | break; |
| 734 | case 24: |
| 735 | var->red.length = 8; |
| 736 | var->red.offset = 0; |
| 737 | var->red.msb_right = 0; |
| 738 | |
| 739 | var->green.length = 8; |
| 740 | var->green.offset = 8; |
| 741 | var->green.msb_right = 0; |
| 742 | |
| 743 | var->blue.length = 8; |
| 744 | var->blue.offset = 16; |
| 745 | var->blue.msb_right = 0; |
| 746 | |
| 747 | var->transp.length = 0; |
| 748 | var->transp.offset = 0; |
| 749 | var->transp.msb_right = 0; |
| 750 | break; |
| 751 | case 32: |
| 752 | var->red.length = 8; |
| 753 | var->red.offset = 16; |
| 754 | var->red.msb_right = 0; |
| 755 | |
| 756 | var->green.length = 8; |
| 757 | var->green.offset = 8; |
| 758 | var->green.msb_right = 0; |
| 759 | |
| 760 | var->blue.length = 8; |
| 761 | var->blue.offset = 0; |
| 762 | var->blue.msb_right = 0; |
| 763 | |
| 764 | var->transp.length = 8; |
| 765 | var->transp.offset = 24; |
| 766 | var->transp.msb_right = 0; |
| 767 | |
| 768 | break; |
| 769 | } |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 770 | |
| 771 | var->height = -1; |
| 772 | var->width = -1; |
| 773 | var->grayscale = 0; |
| 774 | |
| 775 | /* Copy nonstd field to/from sync for fbset usage */ |
| 776 | var->sync |= var->nonstd; |
| 777 | var->nonstd |= var->sync; |
| 778 | |
| 779 | adjust_aoi_size_position(var, info); |
| 780 | return 0; |
| 781 | } |
| 782 | |
| 783 | static void set_fix(struct fb_info *info) |
| 784 | { |
| 785 | struct fb_fix_screeninfo *fix = &info->fix; |
| 786 | struct fb_var_screeninfo *var = &info->var; |
| 787 | struct mfb_info *mfbi = info->par; |
| 788 | |
Timur Tabi | ec02dd2 | 2011-09-15 16:44:54 -0500 | [diff] [blame] | 789 | strncpy(fix->id, mfbi->id, sizeof(fix->id)); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 790 | fix->line_length = var->xres_virtual * var->bits_per_pixel / 8; |
| 791 | fix->type = FB_TYPE_PACKED_PIXELS; |
| 792 | fix->accel = FB_ACCEL_NONE; |
| 793 | fix->visual = FB_VISUAL_TRUECOLOR; |
| 794 | fix->xpanstep = 1; |
| 795 | fix->ypanstep = 1; |
| 796 | } |
| 797 | |
| 798 | static void update_lcdc(struct fb_info *info) |
| 799 | { |
| 800 | struct fb_var_screeninfo *var = &info->var; |
| 801 | struct mfb_info *mfbi = info->par; |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 802 | struct fsl_diu_data *data = mfbi->parent; |
Timur Tabi | 3c755b7 | 2011-10-04 19:36:51 -0500 | [diff] [blame] | 803 | struct diu __iomem *hw; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 804 | int i, j; |
Timur Tabi | ddd3d90 | 2011-12-02 17:03:27 -0600 | [diff] [blame] | 805 | u8 *gamma_table_base; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 806 | |
| 807 | u32 temp; |
| 808 | |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 809 | hw = data->diu_reg; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 810 | |
Timur Tabi | 2867173 | 2012-10-16 17:33:43 -0500 | [diff] [blame] | 811 | if (diu_ops.set_monitor_port) |
| 812 | diu_ops.set_monitor_port(data->monitor_port); |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 813 | gamma_table_base = data->gamma; |
Timur Tabi | ddd3d90 | 2011-12-02 17:03:27 -0600 | [diff] [blame] | 814 | |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 815 | /* Prep for DIU init - gamma table, cursor table */ |
| 816 | |
| 817 | for (i = 0; i <= 2; i++) |
Timur Tabi | 4a85dc8b | 2011-09-15 16:44:46 -0500 | [diff] [blame] | 818 | for (j = 0; j <= 255; j++) |
| 819 | *gamma_table_base++ = j; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 820 | |
Timur Tabi | e09a8c3 | 2011-12-19 16:26:17 -0600 | [diff] [blame] | 821 | if (diu_ops.set_gamma_table) |
| 822 | diu_ops.set_gamma_table(data->monitor_port, data->gamma); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 823 | |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 824 | disable_lcdc(info); |
| 825 | |
| 826 | /* Program DIU registers */ |
| 827 | |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 828 | out_be32(&hw->gamma, DMA_ADDR(data, gamma)); |
| 829 | out_be32(&hw->cursor, DMA_ADDR(data, cursor)); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 830 | |
| 831 | out_be32(&hw->bgnd, 0x007F7F7F); /* BGND */ |
| 832 | out_be32(&hw->bgnd_wb, 0); /* BGND_WB */ |
| 833 | out_be32(&hw->disp_size, (var->yres << 16 | var->xres)); |
| 834 | /* DISP SIZE */ |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 835 | out_be32(&hw->wb_size, 0); /* WB SIZE */ |
| 836 | out_be32(&hw->wb_mem_addr, 0); /* WB MEM ADDR */ |
| 837 | |
| 838 | /* Horizontal and vertical configuration register */ |
| 839 | temp = var->left_margin << 22 | /* BP_H */ |
| 840 | var->hsync_len << 11 | /* PW_H */ |
| 841 | var->right_margin; /* FP_H */ |
| 842 | |
| 843 | out_be32(&hw->hsyn_para, temp); |
| 844 | |
| 845 | temp = var->upper_margin << 22 | /* BP_V */ |
| 846 | var->vsync_len << 11 | /* PW_V */ |
| 847 | var->lower_margin; /* FP_V */ |
| 848 | |
| 849 | out_be32(&hw->vsyn_para, temp); |
| 850 | |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 851 | diu_ops.set_pixel_clock(var->pixclock); |
| 852 | |
| 853 | out_be32(&hw->syn_pol, 0); /* SYNC SIGNALS POLARITY */ |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 854 | out_be32(&hw->int_status, 0); /* INTERRUPT STATUS */ |
| 855 | out_be32(&hw->plut, 0x01F5F666); |
| 856 | |
| 857 | /* Enable the DIU */ |
| 858 | enable_lcdc(info); |
| 859 | } |
| 860 | |
| 861 | static int map_video_memory(struct fb_info *info) |
| 862 | { |
Krzysztof Helt | 537a1bf | 2009-06-30 11:41:29 -0700 | [diff] [blame] | 863 | u32 smem_len = info->fix.line_length * info->var.yres_virtual; |
Timur Tabi | 05342c0 | 2011-12-19 16:26:18 -0600 | [diff] [blame] | 864 | void *p; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 865 | |
Timur Tabi | 05342c0 | 2011-12-19 16:26:18 -0600 | [diff] [blame] | 866 | p = alloc_pages_exact(smem_len, GFP_DMA | __GFP_ZERO); |
| 867 | if (!p) { |
Timur Tabi | 154152a | 2011-09-15 16:44:47 -0500 | [diff] [blame] | 868 | dev_err(info->dev, "unable to allocate fb memory\n"); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 869 | return -ENOMEM; |
| 870 | } |
Krzysztof Helt | 537a1bf | 2009-06-30 11:41:29 -0700 | [diff] [blame] | 871 | mutex_lock(&info->mm_lock); |
Timur Tabi | 05342c0 | 2011-12-19 16:26:18 -0600 | [diff] [blame] | 872 | info->screen_base = p; |
| 873 | info->fix.smem_start = virt_to_phys(info->screen_base); |
Krzysztof Helt | 537a1bf | 2009-06-30 11:41:29 -0700 | [diff] [blame] | 874 | info->fix.smem_len = smem_len; |
| 875 | mutex_unlock(&info->mm_lock); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 876 | info->screen_size = info->fix.smem_len; |
| 877 | |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 878 | return 0; |
| 879 | } |
| 880 | |
| 881 | static void unmap_video_memory(struct fb_info *info) |
| 882 | { |
Timur Tabi | 05342c0 | 2011-12-19 16:26:18 -0600 | [diff] [blame] | 883 | void *p = info->screen_base; |
| 884 | size_t l = info->fix.smem_len; |
| 885 | |
Krzysztof Helt | 537a1bf | 2009-06-30 11:41:29 -0700 | [diff] [blame] | 886 | mutex_lock(&info->mm_lock); |
Anton Vorontsov | 05946bc | 2008-07-04 09:59:38 -0700 | [diff] [blame] | 887 | info->screen_base = NULL; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 888 | info->fix.smem_start = 0; |
| 889 | info->fix.smem_len = 0; |
Krzysztof Helt | 537a1bf | 2009-06-30 11:41:29 -0700 | [diff] [blame] | 890 | mutex_unlock(&info->mm_lock); |
Timur Tabi | 05342c0 | 2011-12-19 16:26:18 -0600 | [diff] [blame] | 891 | |
| 892 | if (p) |
| 893 | free_pages_exact(p, l); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 894 | } |
| 895 | |
| 896 | /* |
York Sun | ae5591e | 2008-08-15 00:40:28 -0700 | [diff] [blame] | 897 | * Using the fb_var_screeninfo in fb_info we set the aoi of this |
| 898 | * particular framebuffer. It is a light version of fsl_diu_set_par. |
| 899 | */ |
| 900 | static int fsl_diu_set_aoi(struct fb_info *info) |
| 901 | { |
| 902 | struct fb_var_screeninfo *var = &info->var; |
| 903 | struct mfb_info *mfbi = info->par; |
| 904 | struct diu_ad *ad = mfbi->ad; |
| 905 | |
| 906 | /* AOI should not be greater than display size */ |
| 907 | ad->offset_xyi = cpu_to_le32((var->yoffset << 16) | var->xoffset); |
| 908 | ad->offset_xyd = cpu_to_le32((mfbi->y_aoi_d << 16) | mfbi->x_aoi_d); |
| 909 | return 0; |
| 910 | } |
| 911 | |
Timur Tabi | e09a8c3 | 2011-12-19 16:26:17 -0600 | [diff] [blame] | 912 | /** |
| 913 | * fsl_diu_get_pixel_format: return the pixel format for a given color depth |
| 914 | * |
| 915 | * The pixel format is a 32-bit value that determine which bits in each |
| 916 | * pixel are to be used for each color. This is the default function used |
| 917 | * if the platform does not define its own version. |
| 918 | */ |
| 919 | static u32 fsl_diu_get_pixel_format(unsigned int bits_per_pixel) |
| 920 | { |
| 921 | #define PF_BYTE_F 0x10000000 |
| 922 | #define PF_ALPHA_C_MASK 0x0E000000 |
| 923 | #define PF_ALPHA_C_SHIFT 25 |
| 924 | #define PF_BLUE_C_MASK 0x01800000 |
| 925 | #define PF_BLUE_C_SHIFT 23 |
| 926 | #define PF_GREEN_C_MASK 0x00600000 |
| 927 | #define PF_GREEN_C_SHIFT 21 |
| 928 | #define PF_RED_C_MASK 0x00180000 |
| 929 | #define PF_RED_C_SHIFT 19 |
| 930 | #define PF_PALETTE 0x00040000 |
| 931 | #define PF_PIXEL_S_MASK 0x00030000 |
| 932 | #define PF_PIXEL_S_SHIFT 16 |
| 933 | #define PF_COMP_3_MASK 0x0000F000 |
| 934 | #define PF_COMP_3_SHIFT 12 |
| 935 | #define PF_COMP_2_MASK 0x00000F00 |
| 936 | #define PF_COMP_2_SHIFT 8 |
| 937 | #define PF_COMP_1_MASK 0x000000F0 |
| 938 | #define PF_COMP_1_SHIFT 4 |
| 939 | #define PF_COMP_0_MASK 0x0000000F |
| 940 | #define PF_COMP_0_SHIFT 0 |
| 941 | |
| 942 | #define MAKE_PF(alpha, red, blue, green, size, c0, c1, c2, c3) \ |
| 943 | cpu_to_le32(PF_BYTE_F | (alpha << PF_ALPHA_C_SHIFT) | \ |
| 944 | (blue << PF_BLUE_C_SHIFT) | (green << PF_GREEN_C_SHIFT) | \ |
| 945 | (red << PF_RED_C_SHIFT) | (c3 << PF_COMP_3_SHIFT) | \ |
| 946 | (c2 << PF_COMP_2_SHIFT) | (c1 << PF_COMP_1_SHIFT) | \ |
| 947 | (c0 << PF_COMP_0_SHIFT) | (size << PF_PIXEL_S_SHIFT)) |
| 948 | |
| 949 | switch (bits_per_pixel) { |
| 950 | case 32: |
| 951 | /* 0x88883316 */ |
| 952 | return MAKE_PF(3, 2, 0, 1, 3, 8, 8, 8, 8); |
| 953 | case 24: |
| 954 | /* 0x88082219 */ |
| 955 | return MAKE_PF(4, 0, 1, 2, 2, 0, 8, 8, 8); |
| 956 | case 16: |
| 957 | /* 0x65053118 */ |
| 958 | return MAKE_PF(4, 2, 1, 0, 1, 5, 6, 5, 0); |
| 959 | default: |
| 960 | pr_err("fsl-diu: unsupported color depth %u\n", bits_per_pixel); |
| 961 | return 0; |
| 962 | } |
| 963 | } |
| 964 | |
York Sun | ae5591e | 2008-08-15 00:40:28 -0700 | [diff] [blame] | 965 | /* |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 966 | * Using the fb_var_screeninfo in fb_info we set the resolution of this |
| 967 | * particular framebuffer. This function alters the fb_fix_screeninfo stored |
| 968 | * in fb_info. It does not alter var in fb_info since we are using that |
| 969 | * data. This means we depend on the data in var inside fb_info to be |
| 970 | * supported by the hardware. fsl_diu_check_var is always called before |
| 971 | * fsl_diu_set_par to ensure this. |
| 972 | */ |
| 973 | static int fsl_diu_set_par(struct fb_info *info) |
| 974 | { |
| 975 | unsigned long len; |
| 976 | struct fb_var_screeninfo *var = &info->var; |
| 977 | struct mfb_info *mfbi = info->par; |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 978 | struct fsl_diu_data *data = mfbi->parent; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 979 | struct diu_ad *ad = mfbi->ad; |
Timur Tabi | 3c755b7 | 2011-10-04 19:36:51 -0500 | [diff] [blame] | 980 | struct diu __iomem *hw; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 981 | |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 982 | hw = data->diu_reg; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 983 | |
| 984 | set_fix(info); |
| 985 | mfbi->cursor_reset = 1; |
| 986 | |
| 987 | len = info->var.yres_virtual * info->fix.line_length; |
| 988 | /* Alloc & dealloc each time resolution/bpp change */ |
| 989 | if (len != info->fix.smem_len) { |
| 990 | if (info->fix.smem_start) |
| 991 | unmap_video_memory(info); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 992 | |
| 993 | /* Memory allocation for framebuffer */ |
| 994 | if (map_video_memory(info)) { |
Timur Tabi | 154152a | 2011-09-15 16:44:47 -0500 | [diff] [blame] | 995 | dev_err(info->dev, "unable to allocate fb memory 1\n"); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 996 | return -ENOMEM; |
| 997 | } |
| 998 | } |
| 999 | |
Timur Tabi | e09a8c3 | 2011-12-19 16:26:17 -0600 | [diff] [blame] | 1000 | if (diu_ops.get_pixel_format) |
| 1001 | ad->pix_fmt = diu_ops.get_pixel_format(data->monitor_port, |
| 1002 | var->bits_per_pixel); |
| 1003 | else |
| 1004 | ad->pix_fmt = fsl_diu_get_pixel_format(var->bits_per_pixel); |
| 1005 | |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1006 | ad->addr = cpu_to_le32(info->fix.smem_start); |
York Sun | ae5591e | 2008-08-15 00:40:28 -0700 | [diff] [blame] | 1007 | ad->src_size_g_alpha = cpu_to_le32((var->yres_virtual << 12) | |
| 1008 | var->xres_virtual) | mfbi->g_alpha; |
| 1009 | /* AOI should not be greater than display size */ |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1010 | ad->aoi_size = cpu_to_le32((var->yres << 16) | var->xres); |
York Sun | ae5591e | 2008-08-15 00:40:28 -0700 | [diff] [blame] | 1011 | ad->offset_xyi = cpu_to_le32((var->yoffset << 16) | var->xoffset); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1012 | ad->offset_xyd = cpu_to_le32((mfbi->y_aoi_d << 16) | mfbi->x_aoi_d); |
| 1013 | |
| 1014 | /* Disable chroma keying function */ |
| 1015 | ad->ckmax_r = 0; |
| 1016 | ad->ckmax_g = 0; |
| 1017 | ad->ckmax_b = 0; |
| 1018 | |
| 1019 | ad->ckmin_r = 255; |
| 1020 | ad->ckmin_g = 255; |
| 1021 | ad->ckmin_b = 255; |
| 1022 | |
Timur Tabi | 2572df9 | 2011-09-28 16:19:51 -0500 | [diff] [blame] | 1023 | if (mfbi->index == PLANE0) |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1024 | update_lcdc(info); |
| 1025 | return 0; |
| 1026 | } |
| 1027 | |
| 1028 | static inline __u32 CNVT_TOHW(__u32 val, __u32 width) |
| 1029 | { |
Timur Tabi | 4a85dc8b | 2011-09-15 16:44:46 -0500 | [diff] [blame] | 1030 | return ((val << width) + 0x7FFF - val) >> 16; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1031 | } |
| 1032 | |
| 1033 | /* |
| 1034 | * Set a single color register. The values supplied have a 16 bit magnitude |
| 1035 | * which needs to be scaled in this function for the hardware. Things to take |
| 1036 | * into consideration are how many color registers, if any, are supported with |
| 1037 | * the current color visual. With truecolor mode no color palettes are |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1038 | * 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] | 1039 | * pseudo_palette in struct fb_info. For pseudocolor mode we have a limited |
| 1040 | * color palette. |
| 1041 | */ |
Timur Tabi | 4a85dc8b | 2011-09-15 16:44:46 -0500 | [diff] [blame] | 1042 | static int fsl_diu_setcolreg(unsigned int regno, unsigned int red, |
| 1043 | unsigned int green, unsigned int blue, |
| 1044 | unsigned int transp, struct fb_info *info) |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1045 | { |
| 1046 | int ret = 1; |
| 1047 | |
| 1048 | /* |
| 1049 | * If greyscale is true, then we convert the RGB value |
| 1050 | * to greyscale no matter what visual we are using. |
| 1051 | */ |
| 1052 | if (info->var.grayscale) |
| 1053 | red = green = blue = (19595 * red + 38470 * green + |
| 1054 | 7471 * blue) >> 16; |
| 1055 | switch (info->fix.visual) { |
| 1056 | case FB_VISUAL_TRUECOLOR: |
| 1057 | /* |
| 1058 | * 16-bit True Colour. We encode the RGB value |
| 1059 | * according to the RGB bitfield information. |
| 1060 | */ |
| 1061 | if (regno < 16) { |
| 1062 | u32 *pal = info->pseudo_palette; |
| 1063 | u32 v; |
| 1064 | |
| 1065 | red = CNVT_TOHW(red, info->var.red.length); |
| 1066 | green = CNVT_TOHW(green, info->var.green.length); |
| 1067 | blue = CNVT_TOHW(blue, info->var.blue.length); |
| 1068 | transp = CNVT_TOHW(transp, info->var.transp.length); |
| 1069 | |
| 1070 | v = (red << info->var.red.offset) | |
| 1071 | (green << info->var.green.offset) | |
| 1072 | (blue << info->var.blue.offset) | |
| 1073 | (transp << info->var.transp.offset); |
| 1074 | |
| 1075 | pal[regno] = v; |
| 1076 | ret = 0; |
| 1077 | } |
| 1078 | break; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1079 | } |
| 1080 | |
| 1081 | return ret; |
| 1082 | } |
| 1083 | |
| 1084 | /* |
| 1085 | * Pan (or wrap, depending on the `vmode' field) the display using the |
| 1086 | * 'xoffset' and 'yoffset' fields of the 'var' structure. If the values |
| 1087 | * don't fit, return -EINVAL. |
| 1088 | */ |
| 1089 | static int fsl_diu_pan_display(struct fb_var_screeninfo *var, |
| 1090 | struct fb_info *info) |
| 1091 | { |
| 1092 | if ((info->var.xoffset == var->xoffset) && |
| 1093 | (info->var.yoffset == var->yoffset)) |
| 1094 | return 0; /* No change, do nothing */ |
| 1095 | |
| 1096 | if (var->xoffset < 0 || var->yoffset < 0 |
| 1097 | || var->xoffset + info->var.xres > info->var.xres_virtual |
| 1098 | || var->yoffset + info->var.yres > info->var.yres_virtual) |
| 1099 | return -EINVAL; |
| 1100 | |
| 1101 | info->var.xoffset = var->xoffset; |
| 1102 | info->var.yoffset = var->yoffset; |
| 1103 | |
| 1104 | if (var->vmode & FB_VMODE_YWRAP) |
| 1105 | info->var.vmode |= FB_VMODE_YWRAP; |
| 1106 | else |
| 1107 | info->var.vmode &= ~FB_VMODE_YWRAP; |
| 1108 | |
York Sun | ae5591e | 2008-08-15 00:40:28 -0700 | [diff] [blame] | 1109 | fsl_diu_set_aoi(info); |
| 1110 | |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1111 | return 0; |
| 1112 | } |
| 1113 | |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1114 | static int fsl_diu_ioctl(struct fb_info *info, unsigned int cmd, |
| 1115 | unsigned long arg) |
| 1116 | { |
| 1117 | struct mfb_info *mfbi = info->par; |
| 1118 | struct diu_ad *ad = mfbi->ad; |
| 1119 | struct mfb_chroma_key ck; |
| 1120 | unsigned char global_alpha; |
| 1121 | struct aoi_display_offset aoi_d; |
| 1122 | __u32 pix_fmt; |
| 1123 | void __user *buf = (void __user *)arg; |
| 1124 | |
| 1125 | if (!arg) |
| 1126 | return -EINVAL; |
Timur Tabi | 5cc2a36 | 2012-10-16 17:33:46 -0500 | [diff] [blame^] | 1127 | |
| 1128 | dev_dbg(info->dev, "ioctl %08x (dir=%s%s type=%u nr=%u size=%u)\n", cmd, |
| 1129 | _IOC_DIR(cmd) & _IOC_READ ? "R" : "", |
| 1130 | _IOC_DIR(cmd) & _IOC_WRITE ? "W" : "", |
| 1131 | _IOC_TYPE(cmd), _IOC_NR(cmd), _IOC_SIZE(cmd)); |
| 1132 | |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1133 | switch (cmd) { |
Timur Tabi | 36b0b1d | 2011-10-04 19:36:44 -0500 | [diff] [blame] | 1134 | case MFB_SET_PIXFMT_OLD: |
| 1135 | dev_warn(info->dev, |
| 1136 | "MFB_SET_PIXFMT value of 0x%08x is deprecated.\n", |
| 1137 | MFB_SET_PIXFMT_OLD); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1138 | case MFB_SET_PIXFMT: |
| 1139 | if (copy_from_user(&pix_fmt, buf, sizeof(pix_fmt))) |
| 1140 | return -EFAULT; |
| 1141 | ad->pix_fmt = pix_fmt; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1142 | break; |
Timur Tabi | 36b0b1d | 2011-10-04 19:36:44 -0500 | [diff] [blame] | 1143 | case MFB_GET_PIXFMT_OLD: |
| 1144 | dev_warn(info->dev, |
| 1145 | "MFB_GET_PIXFMT value of 0x%08x is deprecated.\n", |
| 1146 | MFB_GET_PIXFMT_OLD); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1147 | case MFB_GET_PIXFMT: |
| 1148 | pix_fmt = ad->pix_fmt; |
| 1149 | if (copy_to_user(buf, &pix_fmt, sizeof(pix_fmt))) |
| 1150 | return -EFAULT; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1151 | break; |
| 1152 | case MFB_SET_AOID: |
| 1153 | if (copy_from_user(&aoi_d, buf, sizeof(aoi_d))) |
| 1154 | return -EFAULT; |
| 1155 | mfbi->x_aoi_d = aoi_d.x_aoi_d; |
| 1156 | mfbi->y_aoi_d = aoi_d.y_aoi_d; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1157 | fsl_diu_check_var(&info->var, info); |
York Sun | ae5591e | 2008-08-15 00:40:28 -0700 | [diff] [blame] | 1158 | fsl_diu_set_aoi(info); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1159 | break; |
| 1160 | case MFB_GET_AOID: |
| 1161 | aoi_d.x_aoi_d = mfbi->x_aoi_d; |
| 1162 | aoi_d.y_aoi_d = mfbi->y_aoi_d; |
| 1163 | if (copy_to_user(buf, &aoi_d, sizeof(aoi_d))) |
| 1164 | return -EFAULT; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1165 | break; |
| 1166 | case MFB_GET_ALPHA: |
| 1167 | global_alpha = mfbi->g_alpha; |
| 1168 | if (copy_to_user(buf, &global_alpha, sizeof(global_alpha))) |
| 1169 | return -EFAULT; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1170 | break; |
| 1171 | case MFB_SET_ALPHA: |
| 1172 | /* set panel information */ |
| 1173 | if (copy_from_user(&global_alpha, buf, sizeof(global_alpha))) |
| 1174 | return -EFAULT; |
| 1175 | ad->src_size_g_alpha = (ad->src_size_g_alpha & (~0xff)) | |
| 1176 | (global_alpha & 0xff); |
| 1177 | mfbi->g_alpha = global_alpha; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1178 | break; |
| 1179 | case MFB_SET_CHROMA_KEY: |
| 1180 | /* set panel winformation */ |
| 1181 | if (copy_from_user(&ck, buf, sizeof(ck))) |
| 1182 | return -EFAULT; |
| 1183 | |
| 1184 | if (ck.enable && |
| 1185 | (ck.red_max < ck.red_min || |
| 1186 | ck.green_max < ck.green_min || |
| 1187 | ck.blue_max < ck.blue_min)) |
| 1188 | return -EINVAL; |
| 1189 | |
| 1190 | if (!ck.enable) { |
| 1191 | ad->ckmax_r = 0; |
| 1192 | ad->ckmax_g = 0; |
| 1193 | ad->ckmax_b = 0; |
| 1194 | ad->ckmin_r = 255; |
| 1195 | ad->ckmin_g = 255; |
| 1196 | ad->ckmin_b = 255; |
| 1197 | } else { |
| 1198 | ad->ckmax_r = ck.red_max; |
| 1199 | ad->ckmax_g = ck.green_max; |
| 1200 | ad->ckmax_b = ck.blue_max; |
| 1201 | ad->ckmin_r = ck.red_min; |
| 1202 | ad->ckmin_g = ck.green_min; |
| 1203 | ad->ckmin_b = ck.blue_min; |
| 1204 | } |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1205 | break; |
Timur Tabi | e95c17e | 2012-10-16 17:33:44 -0500 | [diff] [blame] | 1206 | #ifdef CONFIG_PPC_MPC512x |
| 1207 | case MFB_SET_GAMMA: { |
| 1208 | struct fsl_diu_data *data = mfbi->parent; |
| 1209 | |
| 1210 | if (copy_from_user(data->gamma, buf, sizeof(data->gamma))) |
| 1211 | return -EFAULT; |
| 1212 | setbits32(&data->diu_reg->gamma, 0); /* Force table reload */ |
| 1213 | break; |
| 1214 | } |
| 1215 | case MFB_GET_GAMMA: { |
| 1216 | struct fsl_diu_data *data = mfbi->parent; |
| 1217 | |
| 1218 | if (copy_to_user(buf, data->gamma, sizeof(data->gamma))) |
| 1219 | return -EFAULT; |
| 1220 | break; |
| 1221 | } |
| 1222 | #endif |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1223 | default: |
Timur Tabi | 154152a | 2011-09-15 16:44:47 -0500 | [diff] [blame] | 1224 | dev_err(info->dev, "unknown ioctl command (0x%08X)\n", cmd); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1225 | return -ENOIOCTLCMD; |
| 1226 | } |
| 1227 | |
| 1228 | return 0; |
| 1229 | } |
| 1230 | |
| 1231 | /* turn on fb if count == 1 |
| 1232 | */ |
| 1233 | static int fsl_diu_open(struct fb_info *info, int user) |
| 1234 | { |
| 1235 | struct mfb_info *mfbi = info->par; |
| 1236 | int res = 0; |
| 1237 | |
Anatolij Gustschin | 4b5006e | 2010-07-23 04:00:37 +0000 | [diff] [blame] | 1238 | /* free boot splash memory on first /dev/fb0 open */ |
Timur Tabi | 2572df9 | 2011-09-28 16:19:51 -0500 | [diff] [blame] | 1239 | if ((mfbi->index == PLANE0) && diu_ops.release_bootmem) |
Anatolij Gustschin | 4b5006e | 2010-07-23 04:00:37 +0000 | [diff] [blame] | 1240 | diu_ops.release_bootmem(); |
| 1241 | |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1242 | spin_lock(&diu_lock); |
| 1243 | mfbi->count++; |
| 1244 | if (mfbi->count == 1) { |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1245 | fsl_diu_check_var(&info->var, info); |
| 1246 | res = fsl_diu_set_par(info); |
| 1247 | if (res < 0) |
| 1248 | mfbi->count--; |
Timur Tabi | f74de50 | 2012-10-16 17:33:45 -0500 | [diff] [blame] | 1249 | else { |
| 1250 | struct fsl_diu_data *data = mfbi->parent; |
| 1251 | |
| 1252 | #ifdef CONFIG_NOT_COHERENT_CACHE |
| 1253 | /* |
| 1254 | * Enable underrun detection and vertical sync |
| 1255 | * interrupts. |
| 1256 | */ |
| 1257 | clrbits32(&data->diu_reg->int_mask, |
| 1258 | INT_UNDRUN | INT_VSYNC); |
| 1259 | #else |
| 1260 | /* Enable underrun detection */ |
| 1261 | clrbits32(&data->diu_reg->int_mask, INT_UNDRUN); |
| 1262 | #endif |
Timur Tabi | 7e47c21 | 2011-09-28 16:19:52 -0500 | [diff] [blame] | 1263 | fsl_diu_enable_panel(info); |
Timur Tabi | f74de50 | 2012-10-16 17:33:45 -0500 | [diff] [blame] | 1264 | } |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1265 | } |
| 1266 | |
| 1267 | spin_unlock(&diu_lock); |
| 1268 | return res; |
| 1269 | } |
| 1270 | |
| 1271 | /* turn off fb if count == 0 |
| 1272 | */ |
| 1273 | static int fsl_diu_release(struct fb_info *info, int user) |
| 1274 | { |
| 1275 | struct mfb_info *mfbi = info->par; |
| 1276 | int res = 0; |
| 1277 | |
| 1278 | spin_lock(&diu_lock); |
| 1279 | mfbi->count--; |
Timur Tabi | f74de50 | 2012-10-16 17:33:45 -0500 | [diff] [blame] | 1280 | if (mfbi->count == 0) { |
| 1281 | struct fsl_diu_data *data = mfbi->parent; |
| 1282 | |
| 1283 | /* Disable interrupts */ |
| 1284 | out_be32(&data->diu_reg->int_mask, 0xffffffff); |
Timur Tabi | 2572df9 | 2011-09-28 16:19:51 -0500 | [diff] [blame] | 1285 | fsl_diu_disable_panel(info); |
Timur Tabi | f74de50 | 2012-10-16 17:33:45 -0500 | [diff] [blame] | 1286 | } |
Timur Tabi | 2572df9 | 2011-09-28 16:19:51 -0500 | [diff] [blame] | 1287 | |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1288 | spin_unlock(&diu_lock); |
| 1289 | return res; |
| 1290 | } |
| 1291 | |
| 1292 | static struct fb_ops fsl_diu_ops = { |
| 1293 | .owner = THIS_MODULE, |
| 1294 | .fb_check_var = fsl_diu_check_var, |
| 1295 | .fb_set_par = fsl_diu_set_par, |
| 1296 | .fb_setcolreg = fsl_diu_setcolreg, |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1297 | .fb_pan_display = fsl_diu_pan_display, |
| 1298 | .fb_fillrect = cfb_fillrect, |
| 1299 | .fb_copyarea = cfb_copyarea, |
| 1300 | .fb_imageblit = cfb_imageblit, |
| 1301 | .fb_ioctl = fsl_diu_ioctl, |
| 1302 | .fb_open = fsl_diu_open, |
| 1303 | .fb_release = fsl_diu_release, |
| 1304 | }; |
| 1305 | |
Anton Vorontsov | 05946bc | 2008-07-04 09:59:38 -0700 | [diff] [blame] | 1306 | static int __devinit install_fb(struct fb_info *info) |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1307 | { |
| 1308 | int rc; |
| 1309 | struct mfb_info *mfbi = info->par; |
| 1310 | const char *aoi_mode, *init_aoi_mode = "320x240"; |
Anatolij Gustschin | 8b856f0 | 2010-07-23 04:00:39 +0000 | [diff] [blame] | 1311 | struct fb_videomode *db = fsl_diu_mode_db; |
| 1312 | unsigned int dbsize = ARRAY_SIZE(fsl_diu_mode_db); |
| 1313 | int has_default_mode = 1; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1314 | |
Timur Tabi | f934fbd | 2011-12-19 16:26:14 -0600 | [diff] [blame] | 1315 | info->var.activate = FB_ACTIVATE_NOW; |
| 1316 | info->fbops = &fsl_diu_ops; |
Timur Tabi | 934dbee | 2011-12-19 16:26:15 -0600 | [diff] [blame] | 1317 | info->flags = FBINFO_DEFAULT | FBINFO_VIRTFB | FBINFO_PARTIAL_PAN_OK | |
| 1318 | FBINFO_READS_FAST; |
Timur Tabi | f934fbd | 2011-12-19 16:26:14 -0600 | [diff] [blame] | 1319 | info->pseudo_palette = mfbi->pseudo_palette; |
| 1320 | |
| 1321 | rc = fb_alloc_cmap(&info->cmap, 16, 0); |
| 1322 | if (rc) |
| 1323 | return rc; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1324 | |
Timur Tabi | 2572df9 | 2011-09-28 16:19:51 -0500 | [diff] [blame] | 1325 | if (mfbi->index == PLANE0) { |
Anatolij Gustschin | 8b856f0 | 2010-07-23 04:00:39 +0000 | [diff] [blame] | 1326 | if (mfbi->edid_data) { |
| 1327 | /* Now build modedb from EDID */ |
| 1328 | fb_edid_to_monspecs(mfbi->edid_data, &info->monspecs); |
| 1329 | fb_videomode_to_modelist(info->monspecs.modedb, |
| 1330 | info->monspecs.modedb_len, |
| 1331 | &info->modelist); |
| 1332 | db = info->monspecs.modedb; |
| 1333 | dbsize = info->monspecs.modedb_len; |
| 1334 | } |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1335 | aoi_mode = fb_mode; |
Anatolij Gustschin | 8b856f0 | 2010-07-23 04:00:39 +0000 | [diff] [blame] | 1336 | } else { |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1337 | aoi_mode = init_aoi_mode; |
Anatolij Gustschin | 8b856f0 | 2010-07-23 04:00:39 +0000 | [diff] [blame] | 1338 | } |
Timur Tabi | 63cf8df | 2011-09-15 16:44:51 -0500 | [diff] [blame] | 1339 | rc = fb_find_mode(&info->var, info, aoi_mode, db, dbsize, NULL, |
| 1340 | default_bpp); |
Timur Tabi | 154152a | 2011-09-15 16:44:47 -0500 | [diff] [blame] | 1341 | if (!rc) { |
Anatolij Gustschin | 8b856f0 | 2010-07-23 04:00:39 +0000 | [diff] [blame] | 1342 | /* |
| 1343 | * For plane 0 we continue and look into |
| 1344 | * driver's internal modedb. |
| 1345 | */ |
Timur Tabi | 2572df9 | 2011-09-28 16:19:51 -0500 | [diff] [blame] | 1346 | if ((mfbi->index == PLANE0) && mfbi->edid_data) |
Anatolij Gustschin | 8b856f0 | 2010-07-23 04:00:39 +0000 | [diff] [blame] | 1347 | has_default_mode = 0; |
| 1348 | else |
| 1349 | return -EINVAL; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1350 | } |
| 1351 | |
Anatolij Gustschin | 8b856f0 | 2010-07-23 04:00:39 +0000 | [diff] [blame] | 1352 | if (!has_default_mode) { |
| 1353 | 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] | 1354 | ARRAY_SIZE(fsl_diu_mode_db), NULL, default_bpp); |
| 1355 | if (rc) |
Anatolij Gustschin | 8b856f0 | 2010-07-23 04:00:39 +0000 | [diff] [blame] | 1356 | has_default_mode = 1; |
| 1357 | } |
| 1358 | |
| 1359 | /* Still not found, use preferred mode from database if any */ |
| 1360 | if (!has_default_mode && info->monspecs.modedb) { |
| 1361 | struct fb_monspecs *specs = &info->monspecs; |
| 1362 | struct fb_videomode *modedb = &specs->modedb[0]; |
| 1363 | |
| 1364 | /* |
| 1365 | * Get preferred timing. If not found, |
| 1366 | * first mode in database will be used. |
| 1367 | */ |
| 1368 | if (specs->misc & FB_MISC_1ST_DETAIL) { |
| 1369 | int i; |
| 1370 | |
| 1371 | for (i = 0; i < specs->modedb_len; i++) { |
| 1372 | if (specs->modedb[i].flag & FB_MODE_IS_FIRST) { |
| 1373 | modedb = &specs->modedb[i]; |
| 1374 | break; |
| 1375 | } |
| 1376 | } |
| 1377 | } |
| 1378 | |
| 1379 | info->var.bits_per_pixel = default_bpp; |
| 1380 | fb_videomode_to_var(&info->var, modedb); |
| 1381 | } |
| 1382 | |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1383 | if (fsl_diu_check_var(&info->var, info)) { |
Timur Tabi | 154152a | 2011-09-15 16:44:47 -0500 | [diff] [blame] | 1384 | dev_err(info->dev, "fsl_diu_check_var failed\n"); |
Timur Tabi | 589c797 | 2011-09-15 16:44:55 -0500 | [diff] [blame] | 1385 | unmap_video_memory(info); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1386 | fb_dealloc_cmap(&info->cmap); |
| 1387 | return -EINVAL; |
| 1388 | } |
| 1389 | |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1390 | if (register_framebuffer(info) < 0) { |
Timur Tabi | 154152a | 2011-09-15 16:44:47 -0500 | [diff] [blame] | 1391 | dev_err(info->dev, "register_framebuffer failed\n"); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1392 | unmap_video_memory(info); |
| 1393 | fb_dealloc_cmap(&info->cmap); |
| 1394 | return -EINVAL; |
| 1395 | } |
| 1396 | |
| 1397 | mfbi->registered = 1; |
Timur Tabi | 154152a | 2011-09-15 16:44:47 -0500 | [diff] [blame] | 1398 | dev_info(info->dev, "%s registered successfully\n", mfbi->id); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1399 | |
| 1400 | return 0; |
| 1401 | } |
| 1402 | |
Anton Vorontsov | 05946bc | 2008-07-04 09:59:38 -0700 | [diff] [blame] | 1403 | static void uninstall_fb(struct fb_info *info) |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1404 | { |
| 1405 | struct mfb_info *mfbi = info->par; |
| 1406 | |
| 1407 | if (!mfbi->registered) |
| 1408 | return; |
| 1409 | |
Timur Tabi | 2572df9 | 2011-09-28 16:19:51 -0500 | [diff] [blame] | 1410 | if (mfbi->index == PLANE0) |
Anatolij Gustschin | 8b856f0 | 2010-07-23 04:00:39 +0000 | [diff] [blame] | 1411 | kfree(mfbi->edid_data); |
| 1412 | |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1413 | unregister_framebuffer(info); |
| 1414 | unmap_video_memory(info); |
| 1415 | if (&info->cmap) |
| 1416 | fb_dealloc_cmap(&info->cmap); |
| 1417 | |
| 1418 | mfbi->registered = 0; |
| 1419 | } |
| 1420 | |
| 1421 | static irqreturn_t fsl_diu_isr(int irq, void *dev_id) |
| 1422 | { |
Timur Tabi | 3c755b7 | 2011-10-04 19:36:51 -0500 | [diff] [blame] | 1423 | struct diu __iomem *hw = dev_id; |
Timur Tabi | f74de50 | 2012-10-16 17:33:45 -0500 | [diff] [blame] | 1424 | uint32_t status = in_be32(&hw->int_status); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1425 | |
| 1426 | if (status) { |
| 1427 | /* This is the workaround for underrun */ |
| 1428 | if (status & INT_UNDRUN) { |
| 1429 | out_be32(&hw->diu_mode, 0); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1430 | udelay(1); |
| 1431 | out_be32(&hw->diu_mode, 1); |
| 1432 | } |
| 1433 | #if defined(CONFIG_NOT_COHERENT_CACHE) |
| 1434 | else if (status & INT_VSYNC) { |
| 1435 | unsigned int i; |
Timur Tabi | 4a85dc8b | 2011-09-15 16:44:46 -0500 | [diff] [blame] | 1436 | |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1437 | for (i = 0; i < coherence_data_size; |
| 1438 | i += d_cache_line_size) |
| 1439 | __asm__ __volatile__ ( |
| 1440 | "dcbz 0, %[input]" |
| 1441 | ::[input]"r"(&coherence_data[i])); |
| 1442 | } |
| 1443 | #endif |
| 1444 | return IRQ_HANDLED; |
| 1445 | } |
| 1446 | return IRQ_NONE; |
| 1447 | } |
| 1448 | |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1449 | #ifdef CONFIG_PM |
| 1450 | /* |
| 1451 | * Power management hooks. Note that we won't be called from IRQ context, |
| 1452 | * unlike the blank functions above, so we may sleep. |
| 1453 | */ |
Grant Likely | 2dc1158 | 2010-08-06 09:25:50 -0600 | [diff] [blame] | 1454 | 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] | 1455 | { |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 1456 | struct fsl_diu_data *data; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1457 | |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 1458 | data = dev_get_drvdata(&ofdev->dev); |
Michael Neuling | f7f5ef0 | 2012-01-28 19:35:24 +0000 | [diff] [blame] | 1459 | disable_lcdc(data->fsl_diu_info); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1460 | |
| 1461 | return 0; |
| 1462 | } |
| 1463 | |
Grant Likely | 2dc1158 | 2010-08-06 09:25:50 -0600 | [diff] [blame] | 1464 | static int fsl_diu_resume(struct platform_device *ofdev) |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1465 | { |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 1466 | struct fsl_diu_data *data; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1467 | |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 1468 | data = dev_get_drvdata(&ofdev->dev); |
Michael Neuling | f7f5ef0 | 2012-01-28 19:35:24 +0000 | [diff] [blame] | 1469 | enable_lcdc(data->fsl_diu_info); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1470 | |
| 1471 | return 0; |
| 1472 | } |
| 1473 | |
| 1474 | #else |
| 1475 | #define fsl_diu_suspend NULL |
| 1476 | #define fsl_diu_resume NULL |
| 1477 | #endif /* CONFIG_PM */ |
| 1478 | |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1479 | static ssize_t store_monitor(struct device *device, |
| 1480 | struct device_attribute *attr, const char *buf, size_t count) |
| 1481 | { |
Timur Tabi | 7653aaa | 2011-07-09 15:38:14 -0500 | [diff] [blame] | 1482 | enum fsl_diu_monitor_port old_monitor_port; |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 1483 | struct fsl_diu_data *data = |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1484 | container_of(attr, struct fsl_diu_data, dev_attr); |
| 1485 | |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 1486 | old_monitor_port = data->monitor_port; |
| 1487 | data->monitor_port = fsl_diu_name_to_port(buf); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1488 | |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 1489 | if (old_monitor_port != data->monitor_port) { |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1490 | /* All AOIs need adjust pixel format |
| 1491 | * fsl_diu_set_par only change the pixsel format here |
| 1492 | * unlikely to fail. */ |
Timur Tabi | ddd3d90 | 2011-12-02 17:03:27 -0600 | [diff] [blame] | 1493 | unsigned int i; |
| 1494 | |
| 1495 | for (i=0; i < NUM_AOIS; i++) |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 1496 | fsl_diu_set_par(&data->fsl_diu_info[i]); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1497 | } |
| 1498 | return count; |
| 1499 | } |
| 1500 | |
| 1501 | static ssize_t show_monitor(struct device *device, |
| 1502 | struct device_attribute *attr, char *buf) |
| 1503 | { |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 1504 | struct fsl_diu_data *data = |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1505 | container_of(attr, struct fsl_diu_data, dev_attr); |
Timur Tabi | 7653aaa | 2011-07-09 15:38:14 -0500 | [diff] [blame] | 1506 | |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 1507 | switch (data->monitor_port) { |
Timur Tabi | 7653aaa | 2011-07-09 15:38:14 -0500 | [diff] [blame] | 1508 | case FSL_DIU_PORT_DVI: |
| 1509 | return sprintf(buf, "DVI\n"); |
| 1510 | case FSL_DIU_PORT_LVDS: |
| 1511 | return sprintf(buf, "Single-link LVDS\n"); |
| 1512 | case FSL_DIU_PORT_DLVDS: |
| 1513 | return sprintf(buf, "Dual-link LVDS\n"); |
| 1514 | } |
| 1515 | |
| 1516 | return 0; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1517 | } |
| 1518 | |
Timur Tabi | 9e52ba6 | 2011-09-15 16:44:50 -0500 | [diff] [blame] | 1519 | static int __devinit fsl_diu_probe(struct platform_device *pdev) |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1520 | { |
Timur Tabi | 9e52ba6 | 2011-09-15 16:44:50 -0500 | [diff] [blame] | 1521 | struct device_node *np = pdev->dev.of_node; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1522 | struct mfb_info *mfbi; |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 1523 | struct fsl_diu_data *data; |
Anatolij Gustschin | 4b5006e | 2010-07-23 04:00:37 +0000 | [diff] [blame] | 1524 | int diu_mode; |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 1525 | dma_addr_t dma_addr; /* DMA addr of fsl_diu_data struct */ |
Timur Tabi | ddd3d90 | 2011-12-02 17:03:27 -0600 | [diff] [blame] | 1526 | unsigned int i; |
| 1527 | int ret; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1528 | |
Damien Cassou | c1f383d | 2012-07-31 18:39:20 +0200 | [diff] [blame] | 1529 | data = dmam_alloc_coherent(&pdev->dev, sizeof(struct fsl_diu_data), |
| 1530 | &dma_addr, GFP_DMA | __GFP_ZERO); |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 1531 | if (!data) |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1532 | return -ENOMEM; |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 1533 | data->dma_addr = dma_addr; |
Timur Tabi | ddd3d90 | 2011-12-02 17:03:27 -0600 | [diff] [blame] | 1534 | |
| 1535 | /* |
| 1536 | * dma_alloc_coherent() uses a page allocator, so the address is |
| 1537 | * always page-aligned. We need the memory to be 32-byte aligned, |
| 1538 | * so that's good. However, if one day the allocator changes, we |
| 1539 | * need to catch that. It's not worth the effort to handle unaligned |
| 1540 | * alloctions now because it's highly unlikely to ever be a problem. |
| 1541 | */ |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 1542 | if ((unsigned long)data & 31) { |
Timur Tabi | ddd3d90 | 2011-12-02 17:03:27 -0600 | [diff] [blame] | 1543 | dev_err(&pdev->dev, "misaligned allocation"); |
| 1544 | ret = -ENOMEM; |
| 1545 | goto error; |
| 1546 | } |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1547 | |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 1548 | spin_lock_init(&data->reg_lock); |
Timur Tabi | 3c755b7 | 2011-10-04 19:36:51 -0500 | [diff] [blame] | 1549 | |
Timur Tabi | ddd3d90 | 2011-12-02 17:03:27 -0600 | [diff] [blame] | 1550 | for (i = 0; i < NUM_AOIS; i++) { |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 1551 | struct fb_info *info = &data->fsl_diu_info[i]; |
Timur Tabi | ddd3d90 | 2011-12-02 17:03:27 -0600 | [diff] [blame] | 1552 | |
| 1553 | info->device = &pdev->dev; |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 1554 | info->par = &data->mfb[i]; |
Timur Tabi | ddd3d90 | 2011-12-02 17:03:27 -0600 | [diff] [blame] | 1555 | |
| 1556 | /* |
| 1557 | * We store the physical address of the AD in the reserved |
| 1558 | * 'paddr' field of the AD itself. |
| 1559 | */ |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 1560 | data->ad[i].paddr = DMA_ADDR(data, ad[i]); |
Timur Tabi | ddd3d90 | 2011-12-02 17:03:27 -0600 | [diff] [blame] | 1561 | |
| 1562 | info->fix.smem_start = 0; |
| 1563 | |
| 1564 | /* Initialize the AOI data structure */ |
| 1565 | mfbi = info->par; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1566 | memcpy(mfbi, &mfb_template[i], sizeof(struct mfb_info)); |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 1567 | mfbi->parent = data; |
| 1568 | mfbi->ad = &data->ad[i]; |
Anatolij Gustschin | 8b856f0 | 2010-07-23 04:00:39 +0000 | [diff] [blame] | 1569 | |
Timur Tabi | 2572df9 | 2011-09-28 16:19:51 -0500 | [diff] [blame] | 1570 | if (mfbi->index == PLANE0) { |
Anatolij Gustschin | 8b856f0 | 2010-07-23 04:00:39 +0000 | [diff] [blame] | 1571 | const u8 *prop; |
| 1572 | int len; |
| 1573 | |
| 1574 | /* Get EDID */ |
| 1575 | prop = of_get_property(np, "edid", &len); |
| 1576 | if (prop && len == EDID_LENGTH) |
| 1577 | mfbi->edid_data = kmemdup(prop, EDID_LENGTH, |
| 1578 | GFP_KERNEL); |
| 1579 | } |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1580 | } |
| 1581 | |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 1582 | data->diu_reg = of_iomap(np, 0); |
| 1583 | if (!data->diu_reg) { |
Timur Tabi | 9e52ba6 | 2011-09-15 16:44:50 -0500 | [diff] [blame] | 1584 | dev_err(&pdev->dev, "cannot map DIU registers\n"); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1585 | ret = -EFAULT; |
Timur Tabi | ddd3d90 | 2011-12-02 17:03:27 -0600 | [diff] [blame] | 1586 | goto error; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1587 | } |
| 1588 | |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 1589 | diu_mode = in_be32(&data->diu_reg->diu_mode); |
Timur Tabi | c4e5a02 | 2011-09-28 16:19:53 -0500 | [diff] [blame] | 1590 | if (diu_mode == MFB_MODE0) |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 1591 | out_be32(&data->diu_reg->diu_mode, 0); /* disable DIU */ |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1592 | |
| 1593 | /* Get the IRQ of the DIU */ |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 1594 | data->irq = irq_of_parse_and_map(np, 0); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1595 | |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 1596 | if (!data->irq) { |
Timur Tabi | 9e52ba6 | 2011-09-15 16:44:50 -0500 | [diff] [blame] | 1597 | dev_err(&pdev->dev, "could not get DIU IRQ\n"); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1598 | ret = -EINVAL; |
| 1599 | goto error; |
| 1600 | } |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 1601 | data->monitor_port = monitor_port; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1602 | |
Timur Tabi | ddd3d90 | 2011-12-02 17:03:27 -0600 | [diff] [blame] | 1603 | /* Initialize the dummy Area Descriptor */ |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 1604 | data->dummy_ad.addr = cpu_to_le32(DMA_ADDR(data, dummy_aoi)); |
| 1605 | data->dummy_ad.pix_fmt = 0x88882317; |
| 1606 | data->dummy_ad.src_size_g_alpha = cpu_to_le32((4 << 12) | 4); |
| 1607 | data->dummy_ad.aoi_size = cpu_to_le32((4 << 16) | 2); |
| 1608 | data->dummy_ad.offset_xyi = 0; |
| 1609 | data->dummy_ad.offset_xyd = 0; |
| 1610 | data->dummy_ad.next_ad = 0; |
| 1611 | data->dummy_ad.paddr = DMA_ADDR(data, dummy_ad); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1612 | |
Anatolij Gustschin | 4b5006e | 2010-07-23 04:00:37 +0000 | [diff] [blame] | 1613 | /* |
| 1614 | * Let DIU display splash screen if it was pre-initialized |
| 1615 | * by the bootloader, set dummy area descriptor otherwise. |
| 1616 | */ |
Timur Tabi | c4e5a02 | 2011-09-28 16:19:53 -0500 | [diff] [blame] | 1617 | if (diu_mode == MFB_MODE0) |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 1618 | out_be32(&data->diu_reg->desc[0], data->dummy_ad.paddr); |
Anatolij Gustschin | 4b5006e | 2010-07-23 04:00:37 +0000 | [diff] [blame] | 1619 | |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 1620 | out_be32(&data->diu_reg->desc[1], data->dummy_ad.paddr); |
| 1621 | out_be32(&data->diu_reg->desc[2], data->dummy_ad.paddr); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1622 | |
Timur Tabi | ddd3d90 | 2011-12-02 17:03:27 -0600 | [diff] [blame] | 1623 | for (i = 0; i < NUM_AOIS; i++) { |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 1624 | ret = install_fb(&data->fsl_diu_info[i]); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1625 | if (ret) { |
Timur Tabi | 9e52ba6 | 2011-09-15 16:44:50 -0500 | [diff] [blame] | 1626 | dev_err(&pdev->dev, "could not register fb %d\n", i); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1627 | goto error; |
| 1628 | } |
| 1629 | } |
| 1630 | |
Timur Tabi | f74de50 | 2012-10-16 17:33:45 -0500 | [diff] [blame] | 1631 | /* |
| 1632 | * Older versions of U-Boot leave interrupts enabled, so disable |
| 1633 | * all of them and clear the status register. |
| 1634 | */ |
| 1635 | out_be32(&data->diu_reg->int_mask, 0xffffffff); |
| 1636 | in_be32(&data->diu_reg->int_status); |
| 1637 | |
| 1638 | ret = request_irq(data->irq, fsl_diu_isr, 0, "fsl-diu-fb", |
| 1639 | &data->diu_reg); |
| 1640 | if (ret) { |
Timur Tabi | 9e52ba6 | 2011-09-15 16:44:50 -0500 | [diff] [blame] | 1641 | dev_err(&pdev->dev, "could not claim irq\n"); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1642 | goto error; |
| 1643 | } |
| 1644 | |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 1645 | sysfs_attr_init(&data->dev_attr.attr); |
| 1646 | data->dev_attr.attr.name = "monitor"; |
| 1647 | data->dev_attr.attr.mode = S_IRUGO|S_IWUSR; |
| 1648 | data->dev_attr.show = show_monitor; |
| 1649 | data->dev_attr.store = store_monitor; |
| 1650 | ret = device_create_file(&pdev->dev, &data->dev_attr); |
Timur Tabi | ddd3d90 | 2011-12-02 17:03:27 -0600 | [diff] [blame] | 1651 | if (ret) { |
Timur Tabi | 9e52ba6 | 2011-09-15 16:44:50 -0500 | [diff] [blame] | 1652 | dev_err(&pdev->dev, "could not create sysfs file %s\n", |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 1653 | data->dev_attr.attr.name); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1654 | } |
| 1655 | |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 1656 | dev_set_drvdata(&pdev->dev, data); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1657 | return 0; |
| 1658 | |
| 1659 | error: |
Timur Tabi | ddd3d90 | 2011-12-02 17:03:27 -0600 | [diff] [blame] | 1660 | for (i = 0; i < NUM_AOIS; i++) |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 1661 | uninstall_fb(&data->fsl_diu_info[i]); |
Timur Tabi | 3f78bbd | 2011-09-15 16:44:56 -0500 | [diff] [blame] | 1662 | |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 1663 | iounmap(data->diu_reg); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1664 | |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1665 | return ret; |
| 1666 | } |
| 1667 | |
Timur Tabi | 9e52ba6 | 2011-09-15 16:44:50 -0500 | [diff] [blame] | 1668 | static int fsl_diu_remove(struct platform_device *pdev) |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1669 | { |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 1670 | struct fsl_diu_data *data; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1671 | int i; |
| 1672 | |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 1673 | data = dev_get_drvdata(&pdev->dev); |
| 1674 | disable_lcdc(&data->fsl_diu_info[0]); |
Timur Tabi | f74de50 | 2012-10-16 17:33:45 -0500 | [diff] [blame] | 1675 | |
| 1676 | free_irq(data->irq, &data->diu_reg); |
Timur Tabi | ddd3d90 | 2011-12-02 17:03:27 -0600 | [diff] [blame] | 1677 | |
| 1678 | for (i = 0; i < NUM_AOIS; i++) |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 1679 | uninstall_fb(&data->fsl_diu_info[i]); |
Timur Tabi | ddd3d90 | 2011-12-02 17:03:27 -0600 | [diff] [blame] | 1680 | |
Timur Tabi | b779505 | 2011-12-08 17:27:31 -0600 | [diff] [blame] | 1681 | iounmap(data->diu_reg); |
Timur Tabi | ddd3d90 | 2011-12-02 17:03:27 -0600 | [diff] [blame] | 1682 | |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1683 | return 0; |
| 1684 | } |
| 1685 | |
| 1686 | #ifndef MODULE |
| 1687 | static int __init fsl_diu_setup(char *options) |
| 1688 | { |
| 1689 | char *opt; |
| 1690 | unsigned long val; |
| 1691 | |
| 1692 | if (!options || !*options) |
| 1693 | return 0; |
| 1694 | |
| 1695 | while ((opt = strsep(&options, ",")) != NULL) { |
| 1696 | if (!*opt) |
| 1697 | continue; |
| 1698 | if (!strncmp(opt, "monitor=", 8)) { |
Timur Tabi | 7653aaa | 2011-07-09 15:38:14 -0500 | [diff] [blame] | 1699 | monitor_port = fsl_diu_name_to_port(opt + 8); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1700 | } else if (!strncmp(opt, "bpp=", 4)) { |
| 1701 | if (!strict_strtoul(opt + 4, 10, &val)) |
| 1702 | default_bpp = val; |
| 1703 | } else |
| 1704 | fb_mode = opt; |
| 1705 | } |
| 1706 | |
| 1707 | return 0; |
| 1708 | } |
| 1709 | #endif |
| 1710 | |
| 1711 | static struct of_device_id fsl_diu_match[] = { |
Anatolij Gustschin | d24720a | 2010-02-17 07:33:22 -0700 | [diff] [blame] | 1712 | #ifdef CONFIG_PPC_MPC512x |
| 1713 | { |
| 1714 | .compatible = "fsl,mpc5121-diu", |
| 1715 | }, |
| 1716 | #endif |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1717 | { |
| 1718 | .compatible = "fsl,diu", |
| 1719 | }, |
| 1720 | {} |
| 1721 | }; |
| 1722 | MODULE_DEVICE_TABLE(of, fsl_diu_match); |
| 1723 | |
Grant Likely | 28541d0 | 2011-02-22 21:07:43 -0700 | [diff] [blame] | 1724 | static struct platform_driver fsl_diu_driver = { |
Grant Likely | 4018294 | 2010-04-13 16:13:02 -0700 | [diff] [blame] | 1725 | .driver = { |
Timur Tabi | f8c6bf6 | 2011-09-15 16:44:53 -0500 | [diff] [blame] | 1726 | .name = "fsl-diu-fb", |
Grant Likely | 4018294 | 2010-04-13 16:13:02 -0700 | [diff] [blame] | 1727 | .owner = THIS_MODULE, |
| 1728 | .of_match_table = fsl_diu_match, |
| 1729 | }, |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1730 | .probe = fsl_diu_probe, |
| 1731 | .remove = fsl_diu_remove, |
| 1732 | .suspend = fsl_diu_suspend, |
| 1733 | .resume = fsl_diu_resume, |
| 1734 | }; |
| 1735 | |
| 1736 | static int __init fsl_diu_init(void) |
| 1737 | { |
| 1738 | #ifdef CONFIG_NOT_COHERENT_CACHE |
| 1739 | struct device_node *np; |
| 1740 | const u32 *prop; |
| 1741 | #endif |
| 1742 | int ret; |
| 1743 | #ifndef MODULE |
| 1744 | char *option; |
| 1745 | |
| 1746 | /* |
| 1747 | * For kernel boot options (in 'video=xxxfb:<options>' format) |
| 1748 | */ |
| 1749 | if (fb_get_options("fslfb", &option)) |
| 1750 | return -ENODEV; |
| 1751 | fsl_diu_setup(option); |
Timur Tabi | 7653aaa | 2011-07-09 15:38:14 -0500 | [diff] [blame] | 1752 | #else |
| 1753 | monitor_port = fsl_diu_name_to_port(monitor_string); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1754 | #endif |
Timur Tabi | 154152a | 2011-09-15 16:44:47 -0500 | [diff] [blame] | 1755 | pr_info("Freescale Display Interface Unit (DIU) framebuffer driver\n"); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1756 | |
| 1757 | #ifdef CONFIG_NOT_COHERENT_CACHE |
| 1758 | np = of_find_node_by_type(NULL, "cpu"); |
| 1759 | if (!np) { |
Timur Tabi | 154152a | 2011-09-15 16:44:47 -0500 | [diff] [blame] | 1760 | pr_err("fsl-diu-fb: can't find 'cpu' device node\n"); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1761 | return -ENODEV; |
| 1762 | } |
| 1763 | |
| 1764 | prop = of_get_property(np, "d-cache-size", NULL); |
Julia Lawall | 5394ba0 | 2008-08-05 13:01:28 -0700 | [diff] [blame] | 1765 | if (prop == NULL) { |
Timur Tabi | 154152a | 2011-09-15 16:44:47 -0500 | [diff] [blame] | 1766 | pr_err("fsl-diu-fb: missing 'd-cache-size' property' " |
| 1767 | "in 'cpu' node\n"); |
Julia Lawall | 5394ba0 | 2008-08-05 13:01:28 -0700 | [diff] [blame] | 1768 | of_node_put(np); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1769 | return -ENODEV; |
Julia Lawall | 5394ba0 | 2008-08-05 13:01:28 -0700 | [diff] [blame] | 1770 | } |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1771 | |
Timur Tabi | 4a85dc8b | 2011-09-15 16:44:46 -0500 | [diff] [blame] | 1772 | /* |
| 1773 | * Freescale PLRU requires 13/8 times the cache size to do a proper |
| 1774 | * displacement flush |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1775 | */ |
Timur Tabi | 9e52ba6 | 2011-09-15 16:44:50 -0500 | [diff] [blame] | 1776 | coherence_data_size = be32_to_cpup(prop) * 13; |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1777 | coherence_data_size /= 8; |
| 1778 | |
Timur Tabi | 5cc2a36 | 2012-10-16 17:33:46 -0500 | [diff] [blame^] | 1779 | pr_debug("fsl-diu-fb: coherence data size is %zu bytes\n", |
| 1780 | coherence_data_size); |
| 1781 | |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1782 | prop = of_get_property(np, "d-cache-line-size", NULL); |
Julia Lawall | 5394ba0 | 2008-08-05 13:01:28 -0700 | [diff] [blame] | 1783 | if (prop == NULL) { |
Timur Tabi | 154152a | 2011-09-15 16:44:47 -0500 | [diff] [blame] | 1784 | pr_err("fsl-diu-fb: missing 'd-cache-line-size' property' " |
| 1785 | "in 'cpu' node\n"); |
Julia Lawall | 5394ba0 | 2008-08-05 13:01:28 -0700 | [diff] [blame] | 1786 | of_node_put(np); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1787 | return -ENODEV; |
Julia Lawall | 5394ba0 | 2008-08-05 13:01:28 -0700 | [diff] [blame] | 1788 | } |
Timur Tabi | 9e52ba6 | 2011-09-15 16:44:50 -0500 | [diff] [blame] | 1789 | d_cache_line_size = be32_to_cpup(prop); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1790 | |
Timur Tabi | 5cc2a36 | 2012-10-16 17:33:46 -0500 | [diff] [blame^] | 1791 | pr_debug("fsl-diu-fb: cache lines size is %u bytes\n", |
| 1792 | d_cache_line_size); |
| 1793 | |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1794 | of_node_put(np); |
| 1795 | coherence_data = vmalloc(coherence_data_size); |
Timur Tabi | 5cc2a36 | 2012-10-16 17:33:46 -0500 | [diff] [blame^] | 1796 | if (!coherence_data) { |
| 1797 | pr_err("fsl-diu-fb: could not allocate coherence data " |
| 1798 | "(size=%zu)\n", coherence_data_size); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1799 | return -ENOMEM; |
Timur Tabi | 5cc2a36 | 2012-10-16 17:33:46 -0500 | [diff] [blame^] | 1800 | } |
| 1801 | |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1802 | #endif |
Timur Tabi | 4a85dc8b | 2011-09-15 16:44:46 -0500 | [diff] [blame] | 1803 | |
Grant Likely | 28541d0 | 2011-02-22 21:07:43 -0700 | [diff] [blame] | 1804 | ret = platform_driver_register(&fsl_diu_driver); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1805 | if (ret) { |
Timur Tabi | 154152a | 2011-09-15 16:44:47 -0500 | [diff] [blame] | 1806 | pr_err("fsl-diu-fb: failed to register platform driver\n"); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1807 | #if defined(CONFIG_NOT_COHERENT_CACHE) |
| 1808 | vfree(coherence_data); |
| 1809 | #endif |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1810 | } |
| 1811 | return ret; |
| 1812 | } |
| 1813 | |
| 1814 | static void __exit fsl_diu_exit(void) |
| 1815 | { |
Grant Likely | 28541d0 | 2011-02-22 21:07:43 -0700 | [diff] [blame] | 1816 | platform_driver_unregister(&fsl_diu_driver); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1817 | #if defined(CONFIG_NOT_COHERENT_CACHE) |
| 1818 | vfree(coherence_data); |
| 1819 | #endif |
| 1820 | } |
| 1821 | |
| 1822 | module_init(fsl_diu_init); |
| 1823 | module_exit(fsl_diu_exit); |
| 1824 | |
| 1825 | MODULE_AUTHOR("York Sun <yorksun@freescale.com>"); |
| 1826 | MODULE_DESCRIPTION("Freescale DIU framebuffer driver"); |
| 1827 | MODULE_LICENSE("GPL"); |
| 1828 | |
| 1829 | module_param_named(mode, fb_mode, charp, 0); |
| 1830 | MODULE_PARM_DESC(mode, |
| 1831 | "Specify resolution as \"<xres>x<yres>[-<bpp>][@<refresh>]\" "); |
| 1832 | module_param_named(bpp, default_bpp, ulong, 0); |
Timur Tabi | 154152a | 2011-09-15 16:44:47 -0500 | [diff] [blame] | 1833 | 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] | 1834 | module_param_named(monitor, monitor_string, charp, 0); |
| 1835 | MODULE_PARM_DESC(monitor, "Specify the monitor port " |
| 1836 | "(\"dvi\", \"lvds\", or \"dlvds\") if supported by the platform"); |
York Sun | 9b53a9e | 2008-04-28 02:15:34 -0700 | [diff] [blame] | 1837 | |