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