Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 1 | /* |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 2 | * Freescale i.MX Frame Buffer device driver |
| 3 | * |
| 4 | * Copyright (C) 2004 Sascha Hauer, Pengutronix |
| 5 | * Based on acornfb.c Copyright (C) Russell King. |
| 6 | * |
| 7 | * This file is subject to the terms and conditions of the GNU General Public |
| 8 | * License. See the file COPYING in the main directory of this archive for |
| 9 | * more details. |
| 10 | * |
| 11 | * Please direct your questions and comments on this driver to the following |
| 12 | * email address: |
| 13 | * |
| 14 | * linux-arm-kernel@lists.arm.linux.org.uk |
| 15 | */ |
| 16 | |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 17 | #include <linux/module.h> |
| 18 | #include <linux/kernel.h> |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 19 | #include <linux/errno.h> |
| 20 | #include <linux/string.h> |
| 21 | #include <linux/interrupt.h> |
| 22 | #include <linux/slab.h> |
Andrea Righi | 27ac792 | 2008-07-23 21:28:13 -0700 | [diff] [blame] | 23 | #include <linux/mm.h> |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 24 | #include <linux/fb.h> |
| 25 | #include <linux/delay.h> |
| 26 | #include <linux/init.h> |
| 27 | #include <linux/ioport.h> |
| 28 | #include <linux/cpufreq.h> |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 29 | #include <linux/platform_device.h> |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 30 | #include <linux/dma-mapping.h> |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 31 | #include <linux/io.h> |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 32 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 33 | #include <mach/imxfb.h> |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 34 | |
| 35 | /* |
| 36 | * Complain if VAR is out of range. |
| 37 | */ |
| 38 | #define DEBUG_VAR 1 |
| 39 | |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 40 | #define DRIVER_NAME "imx-fb" |
| 41 | |
| 42 | #define LCDC_SSA 0x00 |
| 43 | |
| 44 | #define LCDC_SIZE 0x04 |
| 45 | #define SIZE_XMAX(x) ((((x) >> 4) & 0x3f) << 20) |
| 46 | #define SIZE_YMAX(y) ((y) & 0x1ff) |
| 47 | |
| 48 | #define LCDC_VPW 0x08 |
| 49 | #define VPW_VPW(x) ((x) & 0x3ff) |
| 50 | |
| 51 | #define LCDC_CPOS 0x0C |
| 52 | #define CPOS_CC1 (1<<31) |
| 53 | #define CPOS_CC0 (1<<30) |
| 54 | #define CPOS_OP (1<<28) |
| 55 | #define CPOS_CXP(x) (((x) & 3ff) << 16) |
| 56 | #define CPOS_CYP(y) ((y) & 0x1ff) |
| 57 | |
| 58 | #define LCDC_LCWHB 0x10 |
| 59 | #define LCWHB_BK_EN (1<<31) |
| 60 | #define LCWHB_CW(w) (((w) & 0x1f) << 24) |
| 61 | #define LCWHB_CH(h) (((h) & 0x1f) << 16) |
| 62 | #define LCWHB_BD(x) ((x) & 0xff) |
| 63 | |
| 64 | #define LCDC_LCHCC 0x14 |
| 65 | #define LCHCC_CUR_COL_R(r) (((r) & 0x1f) << 11) |
| 66 | #define LCHCC_CUR_COL_G(g) (((g) & 0x3f) << 5) |
| 67 | #define LCHCC_CUR_COL_B(b) ((b) & 0x1f) |
| 68 | |
| 69 | #define LCDC_PCR 0x18 |
| 70 | |
| 71 | #define LCDC_HCR 0x1C |
| 72 | #define HCR_H_WIDTH(x) (((x) & 0x3f) << 26) |
| 73 | #define HCR_H_WAIT_1(x) (((x) & 0xff) << 8) |
| 74 | #define HCR_H_WAIT_2(x) ((x) & 0xff) |
| 75 | |
| 76 | #define LCDC_VCR 0x20 |
| 77 | #define VCR_V_WIDTH(x) (((x) & 0x3f) << 26) |
| 78 | #define VCR_V_WAIT_1(x) (((x) & 0xff) << 8) |
| 79 | #define VCR_V_WAIT_2(x) ((x) & 0xff) |
| 80 | |
| 81 | #define LCDC_POS 0x24 |
| 82 | #define POS_POS(x) ((x) & 1f) |
| 83 | |
| 84 | #define LCDC_LSCR1 0x28 |
| 85 | /* bit fields in imxfb.h */ |
| 86 | |
| 87 | #define LCDC_PWMR 0x2C |
| 88 | /* bit fields in imxfb.h */ |
| 89 | |
| 90 | #define LCDC_DMACR 0x30 |
| 91 | /* bit fields in imxfb.h */ |
| 92 | |
| 93 | #define LCDC_RMCR 0x34 |
| 94 | #define RMCR_LCDC_EN (1<<1) |
| 95 | #define RMCR_SELF_REF (1<<0) |
| 96 | |
| 97 | #define LCDC_LCDICR 0x38 |
| 98 | #define LCDICR_INT_SYN (1<<2) |
| 99 | #define LCDICR_INT_CON (1) |
| 100 | |
| 101 | #define LCDC_LCDISR 0x40 |
| 102 | #define LCDISR_UDR_ERR (1<<3) |
| 103 | #define LCDISR_ERR_RES (1<<2) |
| 104 | #define LCDISR_EOF (1<<1) |
| 105 | #define LCDISR_BOF (1<<0) |
| 106 | |
Sascha Hauer | 24b9baf | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 107 | /* |
| 108 | * These are the bitfields for each |
| 109 | * display depth that we support. |
| 110 | */ |
| 111 | struct imxfb_rgb { |
| 112 | struct fb_bitfield red; |
| 113 | struct fb_bitfield green; |
| 114 | struct fb_bitfield blue; |
| 115 | struct fb_bitfield transp; |
| 116 | }; |
| 117 | |
Sascha Hauer | 24b9baf | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 118 | struct imxfb_info { |
| 119 | struct platform_device *pdev; |
| 120 | void __iomem *regs; |
| 121 | |
Sascha Hauer | 24b9baf | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 122 | u_int max_bpp; |
| 123 | u_int max_xres; |
| 124 | u_int max_yres; |
| 125 | |
| 126 | /* |
| 127 | * These are the addresses we mapped |
| 128 | * the framebuffer memory region to. |
| 129 | */ |
| 130 | dma_addr_t map_dma; |
| 131 | u_char *map_cpu; |
| 132 | u_int map_size; |
| 133 | |
| 134 | u_char *screen_cpu; |
| 135 | dma_addr_t screen_dma; |
| 136 | u_int palette_size; |
| 137 | |
| 138 | dma_addr_t dbar1; |
| 139 | dma_addr_t dbar2; |
| 140 | |
| 141 | u_int pcr; |
| 142 | u_int pwmr; |
| 143 | u_int lscr1; |
| 144 | u_int dmacr; |
| 145 | u_int cmap_inverse:1, |
| 146 | cmap_static:1, |
| 147 | unused:30; |
| 148 | |
| 149 | void (*lcd_power)(int); |
| 150 | void (*backlight_power)(int); |
| 151 | }; |
| 152 | |
| 153 | #define IMX_NAME "IMX" |
| 154 | |
| 155 | /* |
| 156 | * Minimum X and Y resolutions |
| 157 | */ |
| 158 | #define MIN_XRES 64 |
| 159 | #define MIN_YRES 64 |
| 160 | |
Sascha Hauer | 1512222 | 2009-01-26 17:31:02 +0100 | [diff] [blame^] | 161 | /* Actually this really is 18bit support, the lowest 2 bits of each colour |
| 162 | * are unused in hardware. We claim to have 24bit support to make software |
| 163 | * like X work, which does not support 18bit. |
| 164 | */ |
| 165 | static struct imxfb_rgb def_rgb_18 = { |
| 166 | .red = {.offset = 16, .length = 8,}, |
| 167 | .green = {.offset = 8, .length = 8,}, |
| 168 | .blue = {.offset = 0, .length = 8,}, |
| 169 | .transp = {.offset = 0, .length = 0,}, |
| 170 | }; |
| 171 | |
Sascha Hauer | 80eee6b | 2008-12-16 11:44:09 +0100 | [diff] [blame] | 172 | static struct imxfb_rgb def_rgb_16_tft = { |
| 173 | .red = {.offset = 11, .length = 5,}, |
| 174 | .green = {.offset = 5, .length = 6,}, |
| 175 | .blue = {.offset = 0, .length = 5,}, |
| 176 | .transp = {.offset = 0, .length = 0,}, |
| 177 | }; |
| 178 | |
| 179 | static struct imxfb_rgb def_rgb_16_stn = { |
Sascha Hauer | 66c8719 | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 180 | .red = {.offset = 8, .length = 4,}, |
| 181 | .green = {.offset = 4, .length = 4,}, |
| 182 | .blue = {.offset = 0, .length = 4,}, |
| 183 | .transp = {.offset = 0, .length = 0,}, |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 184 | }; |
| 185 | |
| 186 | static struct imxfb_rgb def_rgb_8 = { |
Sascha Hauer | 66c8719 | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 187 | .red = {.offset = 0, .length = 8,}, |
| 188 | .green = {.offset = 0, .length = 8,}, |
| 189 | .blue = {.offset = 0, .length = 8,}, |
| 190 | .transp = {.offset = 0, .length = 0,}, |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 191 | }; |
| 192 | |
Sascha Hauer | 66c8719 | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 193 | static int imxfb_activate_var(struct fb_var_screeninfo *var, |
| 194 | struct fb_info *info); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 195 | |
| 196 | static inline u_int chan_to_field(u_int chan, struct fb_bitfield *bf) |
| 197 | { |
| 198 | chan &= 0xffff; |
| 199 | chan >>= 16 - bf->length; |
| 200 | return chan << bf->offset; |
| 201 | } |
| 202 | |
Sascha Hauer | 66c8719 | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 203 | static int imxfb_setpalettereg(u_int regno, u_int red, u_int green, u_int blue, |
| 204 | u_int trans, struct fb_info *info) |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 205 | { |
| 206 | struct imxfb_info *fbi = info->par; |
| 207 | u_int val, ret = 1; |
| 208 | |
| 209 | #define CNVT_TOHW(val,width) ((((val)<<(width))+0x7FFF-(val))>>16) |
| 210 | if (regno < fbi->palette_size) { |
| 211 | val = (CNVT_TOHW(red, 4) << 8) | |
| 212 | (CNVT_TOHW(green,4) << 4) | |
| 213 | CNVT_TOHW(blue, 4); |
| 214 | |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 215 | writel(val, fbi->regs + 0x800 + (regno << 2)); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 216 | ret = 0; |
| 217 | } |
| 218 | return ret; |
| 219 | } |
| 220 | |
Sascha Hauer | 66c8719 | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 221 | static int imxfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue, |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 222 | u_int trans, struct fb_info *info) |
| 223 | { |
| 224 | struct imxfb_info *fbi = info->par; |
| 225 | unsigned int val; |
| 226 | int ret = 1; |
| 227 | |
| 228 | /* |
| 229 | * If inverse mode was selected, invert all the colours |
| 230 | * rather than the register number. The register number |
| 231 | * is what you poke into the framebuffer to produce the |
| 232 | * colour you requested. |
| 233 | */ |
| 234 | if (fbi->cmap_inverse) { |
| 235 | red = 0xffff - red; |
| 236 | green = 0xffff - green; |
| 237 | blue = 0xffff - blue; |
| 238 | } |
| 239 | |
| 240 | /* |
| 241 | * If greyscale is true, then we convert the RGB value |
| 242 | * to greyscale no mater what visual we are using. |
| 243 | */ |
| 244 | if (info->var.grayscale) |
| 245 | red = green = blue = (19595 * red + 38470 * green + |
| 246 | 7471 * blue) >> 16; |
| 247 | |
| 248 | switch (info->fix.visual) { |
| 249 | case FB_VISUAL_TRUECOLOR: |
| 250 | /* |
| 251 | * 12 or 16-bit True Colour. We encode the RGB value |
| 252 | * according to the RGB bitfield information. |
| 253 | */ |
| 254 | if (regno < 16) { |
| 255 | u32 *pal = info->pseudo_palette; |
| 256 | |
| 257 | val = chan_to_field(red, &info->var.red); |
| 258 | val |= chan_to_field(green, &info->var.green); |
| 259 | val |= chan_to_field(blue, &info->var.blue); |
| 260 | |
| 261 | pal[regno] = val; |
| 262 | ret = 0; |
| 263 | } |
| 264 | break; |
| 265 | |
| 266 | case FB_VISUAL_STATIC_PSEUDOCOLOR: |
| 267 | case FB_VISUAL_PSEUDOCOLOR: |
| 268 | ret = imxfb_setpalettereg(regno, red, green, blue, trans, info); |
| 269 | break; |
| 270 | } |
| 271 | |
| 272 | return ret; |
| 273 | } |
| 274 | |
| 275 | /* |
| 276 | * imxfb_check_var(): |
| 277 | * Round up in the following order: bits_per_pixel, xres, |
| 278 | * yres, xres_virtual, yres_virtual, xoffset, yoffset, grayscale, |
| 279 | * bitfields, horizontal timing, vertical timing. |
| 280 | */ |
Sascha Hauer | 66c8719 | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 281 | static int imxfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info) |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 282 | { |
| 283 | struct imxfb_info *fbi = info->par; |
Sascha Hauer | 80eee6b | 2008-12-16 11:44:09 +0100 | [diff] [blame] | 284 | struct imxfb_rgb *rgb; |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 285 | |
| 286 | if (var->xres < MIN_XRES) |
| 287 | var->xres = MIN_XRES; |
| 288 | if (var->yres < MIN_YRES) |
| 289 | var->yres = MIN_YRES; |
| 290 | if (var->xres > fbi->max_xres) |
| 291 | var->xres = fbi->max_xres; |
| 292 | if (var->yres > fbi->max_yres) |
| 293 | var->yres = fbi->max_yres; |
| 294 | var->xres_virtual = max(var->xres_virtual, var->xres); |
| 295 | var->yres_virtual = max(var->yres_virtual, var->yres); |
| 296 | |
| 297 | pr_debug("var->bits_per_pixel=%d\n", var->bits_per_pixel); |
| 298 | switch (var->bits_per_pixel) { |
Sascha Hauer | 1512222 | 2009-01-26 17:31:02 +0100 | [diff] [blame^] | 299 | case 32: |
| 300 | rgb = &def_rgb_18; |
| 301 | break; |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 302 | case 16: |
Sascha Hauer | 80eee6b | 2008-12-16 11:44:09 +0100 | [diff] [blame] | 303 | default: |
| 304 | if (readl(fbi->regs + LCDC_PCR) & PCR_TFT) |
| 305 | rgb = &def_rgb_16_tft; |
| 306 | else |
| 307 | rgb = &def_rgb_16_stn; |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 308 | break; |
| 309 | case 8: |
Sascha Hauer | 80eee6b | 2008-12-16 11:44:09 +0100 | [diff] [blame] | 310 | rgb = &def_rgb_8; |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 311 | break; |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | /* |
| 315 | * Copy the RGB parameters for this display |
| 316 | * from the machine specific parameters. |
| 317 | */ |
Sascha Hauer | 80eee6b | 2008-12-16 11:44:09 +0100 | [diff] [blame] | 318 | var->red = rgb->red; |
| 319 | var->green = rgb->green; |
| 320 | var->blue = rgb->blue; |
| 321 | var->transp = rgb->transp; |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 322 | |
| 323 | pr_debug("RGBT length = %d:%d:%d:%d\n", |
| 324 | var->red.length, var->green.length, var->blue.length, |
| 325 | var->transp.length); |
| 326 | |
| 327 | pr_debug("RGBT offset = %d:%d:%d:%d\n", |
| 328 | var->red.offset, var->green.offset, var->blue.offset, |
| 329 | var->transp.offset); |
| 330 | |
| 331 | return 0; |
| 332 | } |
| 333 | |
| 334 | /* |
| 335 | * imxfb_set_par(): |
| 336 | * Set the user defined part of the display for the specified console |
| 337 | */ |
| 338 | static int imxfb_set_par(struct fb_info *info) |
| 339 | { |
| 340 | struct imxfb_info *fbi = info->par; |
| 341 | struct fb_var_screeninfo *var = &info->var; |
| 342 | |
Sascha Hauer | 1512222 | 2009-01-26 17:31:02 +0100 | [diff] [blame^] | 343 | if (var->bits_per_pixel == 16 || var->bits_per_pixel == 32) |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 344 | info->fix.visual = FB_VISUAL_TRUECOLOR; |
| 345 | else if (!fbi->cmap_static) |
| 346 | info->fix.visual = FB_VISUAL_PSEUDOCOLOR; |
| 347 | else { |
| 348 | /* |
| 349 | * Some people have weird ideas about wanting static |
| 350 | * pseudocolor maps. I suspect their user space |
| 351 | * applications are broken. |
| 352 | */ |
| 353 | info->fix.visual = FB_VISUAL_STATIC_PSEUDOCOLOR; |
| 354 | } |
| 355 | |
Sascha Hauer | 66c8719 | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 356 | info->fix.line_length = var->xres_virtual * var->bits_per_pixel / 8; |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 357 | fbi->palette_size = var->bits_per_pixel == 8 ? 256 : 16; |
| 358 | |
| 359 | imxfb_activate_var(var, info); |
| 360 | |
| 361 | return 0; |
| 362 | } |
| 363 | |
| 364 | static void imxfb_enable_controller(struct imxfb_info *fbi) |
| 365 | { |
| 366 | pr_debug("Enabling LCD controller\n"); |
| 367 | |
| 368 | /* initialize LCDC */ |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 369 | writel(readl(fbi->regs + LCDC_RMCR) & ~RMCR_LCDC_EN, |
| 370 | fbi->regs + LCDC_RMCR); /* just to be safe... */ |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 371 | |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 372 | writel(fbi->screen_dma, fbi->regs + LCDC_SSA); |
| 373 | |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 374 | /* physical screen start address */ |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 375 | writel(VPW_VPW(fbi->max_xres * fbi->max_bpp / 8 / 4), |
| 376 | fbi->regs + LCDC_VPW); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 377 | |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 378 | /* panning offset 0 (0 pixel offset) */ |
| 379 | writel(0x00000000, fbi->regs + LCDC_POS); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 380 | |
| 381 | /* disable hardware cursor */ |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 382 | writel(readl(fbi->regs + LCDC_CPOS) & ~(CPOS_CC0 | CPOS_CC1), |
| 383 | fbi->regs + LCDC_CPOS); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 384 | |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 385 | writel(RMCR_LCDC_EN, fbi->regs + LCDC_RMCR); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 386 | |
Sascha Hauer | 66c8719 | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 387 | if (fbi->backlight_power) |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 388 | fbi->backlight_power(1); |
Sascha Hauer | 66c8719 | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 389 | if (fbi->lcd_power) |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 390 | fbi->lcd_power(1); |
| 391 | } |
| 392 | |
| 393 | static void imxfb_disable_controller(struct imxfb_info *fbi) |
| 394 | { |
| 395 | pr_debug("Disabling LCD controller\n"); |
| 396 | |
Sascha Hauer | 66c8719 | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 397 | if (fbi->backlight_power) |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 398 | fbi->backlight_power(0); |
Sascha Hauer | 66c8719 | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 399 | if (fbi->lcd_power) |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 400 | fbi->lcd_power(0); |
| 401 | |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 402 | writel(0, fbi->regs + LCDC_RMCR); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | static int imxfb_blank(int blank, struct fb_info *info) |
| 406 | { |
| 407 | struct imxfb_info *fbi = info->par; |
| 408 | |
| 409 | pr_debug("imxfb_blank: blank=%d\n", blank); |
| 410 | |
| 411 | switch (blank) { |
| 412 | case FB_BLANK_POWERDOWN: |
| 413 | case FB_BLANK_VSYNC_SUSPEND: |
| 414 | case FB_BLANK_HSYNC_SUSPEND: |
| 415 | case FB_BLANK_NORMAL: |
| 416 | imxfb_disable_controller(fbi); |
| 417 | break; |
| 418 | |
| 419 | case FB_BLANK_UNBLANK: |
| 420 | imxfb_enable_controller(fbi); |
| 421 | break; |
| 422 | } |
| 423 | return 0; |
| 424 | } |
| 425 | |
| 426 | static struct fb_ops imxfb_ops = { |
| 427 | .owner = THIS_MODULE, |
| 428 | .fb_check_var = imxfb_check_var, |
| 429 | .fb_set_par = imxfb_set_par, |
| 430 | .fb_setcolreg = imxfb_setcolreg, |
| 431 | .fb_fillrect = cfb_fillrect, |
| 432 | .fb_copyarea = cfb_copyarea, |
| 433 | .fb_imageblit = cfb_imageblit, |
| 434 | .fb_blank = imxfb_blank, |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 435 | }; |
| 436 | |
| 437 | /* |
| 438 | * imxfb_activate_var(): |
| 439 | * Configures LCD Controller based on entries in var parameter. Settings are |
| 440 | * only written to the controller if changes were made. |
| 441 | */ |
| 442 | static int imxfb_activate_var(struct fb_var_screeninfo *var, struct fb_info *info) |
| 443 | { |
| 444 | struct imxfb_info *fbi = info->par; |
| 445 | pr_debug("var: xres=%d hslen=%d lm=%d rm=%d\n", |
| 446 | var->xres, var->hsync_len, |
| 447 | var->left_margin, var->right_margin); |
| 448 | pr_debug("var: yres=%d vslen=%d um=%d bm=%d\n", |
| 449 | var->yres, var->vsync_len, |
| 450 | var->upper_margin, var->lower_margin); |
| 451 | |
| 452 | #if DEBUG_VAR |
| 453 | if (var->xres < 16 || var->xres > 1024) |
| 454 | printk(KERN_ERR "%s: invalid xres %d\n", |
| 455 | info->fix.id, var->xres); |
| 456 | if (var->hsync_len < 1 || var->hsync_len > 64) |
| 457 | printk(KERN_ERR "%s: invalid hsync_len %d\n", |
| 458 | info->fix.id, var->hsync_len); |
| 459 | if (var->left_margin > 255) |
| 460 | printk(KERN_ERR "%s: invalid left_margin %d\n", |
| 461 | info->fix.id, var->left_margin); |
| 462 | if (var->right_margin > 255) |
| 463 | printk(KERN_ERR "%s: invalid right_margin %d\n", |
| 464 | info->fix.id, var->right_margin); |
| 465 | if (var->yres < 1 || var->yres > 511) |
| 466 | printk(KERN_ERR "%s: invalid yres %d\n", |
| 467 | info->fix.id, var->yres); |
| 468 | if (var->vsync_len > 100) |
| 469 | printk(KERN_ERR "%s: invalid vsync_len %d\n", |
| 470 | info->fix.id, var->vsync_len); |
| 471 | if (var->upper_margin > 63) |
| 472 | printk(KERN_ERR "%s: invalid upper_margin %d\n", |
| 473 | info->fix.id, var->upper_margin); |
| 474 | if (var->lower_margin > 255) |
| 475 | printk(KERN_ERR "%s: invalid lower_margin %d\n", |
| 476 | info->fix.id, var->lower_margin); |
| 477 | #endif |
| 478 | |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 479 | writel(HCR_H_WIDTH(var->hsync_len) | |
Sascha Hauer | d6ed575 | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 480 | HCR_H_WAIT_1(var->right_margin) | |
| 481 | HCR_H_WAIT_2(var->left_margin), |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 482 | fbi->regs + LCDC_HCR); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 483 | |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 484 | writel(VCR_V_WIDTH(var->vsync_len) | |
Sascha Hauer | d6ed575 | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 485 | VCR_V_WAIT_1(var->lower_margin) | |
| 486 | VCR_V_WAIT_2(var->upper_margin), |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 487 | fbi->regs + LCDC_VCR); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 488 | |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 489 | writel(SIZE_XMAX(var->xres) | SIZE_YMAX(var->yres), |
| 490 | fbi->regs + LCDC_SIZE); |
| 491 | writel(fbi->pcr, fbi->regs + LCDC_PCR); |
| 492 | writel(fbi->pwmr, fbi->regs + LCDC_PWMR); |
| 493 | writel(fbi->lscr1, fbi->regs + LCDC_LSCR1); |
| 494 | writel(fbi->dmacr, fbi->regs + LCDC_DMACR); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 495 | |
| 496 | return 0; |
| 497 | } |
| 498 | |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 499 | #ifdef CONFIG_PM |
| 500 | /* |
| 501 | * Power management hooks. Note that we won't be called from IRQ context, |
| 502 | * unlike the blank functions above, so we may sleep. |
| 503 | */ |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 504 | static int imxfb_suspend(struct platform_device *dev, pm_message_t state) |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 505 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 506 | struct imxfb_info *fbi = platform_get_drvdata(dev); |
Sascha Hauer | 66c8719 | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 507 | |
| 508 | pr_debug("%s\n", __func__); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 509 | |
Russell King | 9480e30 | 2005-10-28 09:52:56 -0700 | [diff] [blame] | 510 | imxfb_disable_controller(fbi); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 511 | return 0; |
| 512 | } |
| 513 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 514 | static int imxfb_resume(struct platform_device *dev) |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 515 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 516 | struct imxfb_info *fbi = platform_get_drvdata(dev); |
Sascha Hauer | 66c8719 | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 517 | |
| 518 | pr_debug("%s\n", __func__); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 519 | |
Russell King | 9480e30 | 2005-10-28 09:52:56 -0700 | [diff] [blame] | 520 | imxfb_enable_controller(fbi); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 521 | return 0; |
| 522 | } |
| 523 | #else |
| 524 | #define imxfb_suspend NULL |
| 525 | #define imxfb_resume NULL |
| 526 | #endif |
| 527 | |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 528 | static int __init imxfb_init_fbinfo(struct platform_device *pdev) |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 529 | { |
Sascha Hauer | 2788927 | 2008-12-16 11:44:09 +0100 | [diff] [blame] | 530 | struct imx_fb_platform_data *pdata = pdev->dev.platform_data; |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 531 | struct fb_info *info = dev_get_drvdata(&pdev->dev); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 532 | struct imxfb_info *fbi = info->par; |
| 533 | |
Harvey Harrison | 5ae1217 | 2008-04-28 02:15:47 -0700 | [diff] [blame] | 534 | pr_debug("%s\n",__func__); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 535 | |
Sascha Hauer | 66c8719 | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 536 | info->pseudo_palette = kmalloc(sizeof(u32) * 16, GFP_KERNEL); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 537 | if (!info->pseudo_palette) |
| 538 | return -ENOMEM; |
| 539 | |
| 540 | memset(fbi, 0, sizeof(struct imxfb_info)); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 541 | |
| 542 | strlcpy(info->fix.id, IMX_NAME, sizeof(info->fix.id)); |
| 543 | |
Sascha Hauer | 66c8719 | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 544 | info->fix.type = FB_TYPE_PACKED_PIXELS; |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 545 | info->fix.type_aux = 0; |
| 546 | info->fix.xpanstep = 0; |
| 547 | info->fix.ypanstep = 0; |
| 548 | info->fix.ywrapstep = 0; |
Sascha Hauer | 66c8719 | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 549 | info->fix.accel = FB_ACCEL_NONE; |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 550 | |
| 551 | info->var.nonstd = 0; |
| 552 | info->var.activate = FB_ACTIVATE_NOW; |
| 553 | info->var.height = -1; |
| 554 | info->var.width = -1; |
| 555 | info->var.accel_flags = 0; |
Sascha Hauer | 66c8719 | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 556 | info->var.vmode = FB_VMODE_NONINTERLACED; |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 557 | |
| 558 | info->fbops = &imxfb_ops; |
Sascha Hauer | 66c8719 | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 559 | info->flags = FBINFO_FLAG_DEFAULT | |
| 560 | FBINFO_READS_FAST; |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 561 | |
Sascha Hauer | 2788927 | 2008-12-16 11:44:09 +0100 | [diff] [blame] | 562 | fbi->max_xres = pdata->xres; |
| 563 | info->var.xres = pdata->xres; |
| 564 | info->var.xres_virtual = pdata->xres; |
| 565 | fbi->max_yres = pdata->yres; |
| 566 | info->var.yres = pdata->yres; |
| 567 | info->var.yres_virtual = pdata->yres; |
| 568 | fbi->max_bpp = pdata->bpp; |
| 569 | info->var.bits_per_pixel = pdata->bpp; |
| 570 | info->var.nonstd = pdata->nonstd; |
| 571 | info->var.pixclock = pdata->pixclock; |
| 572 | info->var.hsync_len = pdata->hsync_len; |
| 573 | info->var.left_margin = pdata->left_margin; |
| 574 | info->var.right_margin = pdata->right_margin; |
| 575 | info->var.vsync_len = pdata->vsync_len; |
| 576 | info->var.upper_margin = pdata->upper_margin; |
| 577 | info->var.lower_margin = pdata->lower_margin; |
| 578 | info->var.sync = pdata->sync; |
| 579 | info->var.grayscale = pdata->cmap_greyscale; |
| 580 | fbi->cmap_inverse = pdata->cmap_inverse; |
| 581 | fbi->cmap_static = pdata->cmap_static; |
| 582 | fbi->pcr = pdata->pcr; |
| 583 | fbi->lscr1 = pdata->lscr1; |
| 584 | fbi->dmacr = pdata->dmacr; |
| 585 | fbi->pwmr = pdata->pwmr; |
| 586 | fbi->lcd_power = pdata->lcd_power; |
| 587 | fbi->backlight_power = pdata->backlight_power; |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 588 | info->fix.smem_len = fbi->max_xres * fbi->max_yres * |
| 589 | fbi->max_bpp / 8; |
| 590 | |
| 591 | return 0; |
| 592 | } |
| 593 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 594 | static int __init imxfb_probe(struct platform_device *pdev) |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 595 | { |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 596 | struct imxfb_info *fbi; |
| 597 | struct fb_info *info; |
Sascha Hauer | 2788927 | 2008-12-16 11:44:09 +0100 | [diff] [blame] | 598 | struct imx_fb_platform_data *pdata; |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 599 | struct resource *res; |
| 600 | int ret; |
| 601 | |
| 602 | printk("i.MX Framebuffer driver\n"); |
| 603 | |
| 604 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Sascha Hauer | 66c8719 | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 605 | if (!res) |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 606 | return -ENODEV; |
| 607 | |
Sascha Hauer | 2788927 | 2008-12-16 11:44:09 +0100 | [diff] [blame] | 608 | pdata = pdev->dev.platform_data; |
| 609 | if (!pdata) { |
Pavel Pisa | f99c892 | 2006-01-07 10:44:32 +0000 | [diff] [blame] | 610 | dev_err(&pdev->dev,"No platform_data available\n"); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 611 | return -ENOMEM; |
| 612 | } |
| 613 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 614 | info = framebuffer_alloc(sizeof(struct imxfb_info), &pdev->dev); |
Sascha Hauer | 66c8719 | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 615 | if (!info) |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 616 | return -ENOMEM; |
| 617 | |
| 618 | fbi = info->par; |
| 619 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 620 | platform_set_drvdata(pdev, info); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 621 | |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 622 | ret = imxfb_init_fbinfo(pdev); |
Sascha Hauer | 66c8719 | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 623 | if (ret < 0) |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 624 | goto failed_init; |
| 625 | |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 626 | res = request_mem_region(res->start, resource_size(res), |
| 627 | DRIVER_NAME); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 628 | if (!res) { |
| 629 | ret = -EBUSY; |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 630 | goto failed_req; |
| 631 | } |
| 632 | |
| 633 | fbi->regs = ioremap(res->start, resource_size(res)); |
| 634 | if (fbi->regs == NULL) { |
| 635 | printk(KERN_ERR"Cannot map frame buffer registers\n"); |
| 636 | goto failed_ioremap; |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 637 | } |
| 638 | |
Sascha Hauer | 2788927 | 2008-12-16 11:44:09 +0100 | [diff] [blame] | 639 | if (!pdata->fixed_screen_cpu) { |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 640 | fbi->map_size = PAGE_ALIGN(info->fix.smem_len); |
| 641 | fbi->map_cpu = dma_alloc_writecombine(&pdev->dev, |
| 642 | fbi->map_size, &fbi->map_dma, GFP_KERNEL); |
| 643 | |
| 644 | if (!fbi->map_cpu) { |
Pavel Pisa | f99c892 | 2006-01-07 10:44:32 +0000 | [diff] [blame] | 645 | dev_err(&pdev->dev, "Failed to allocate video RAM: %d\n", ret); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 646 | ret = -ENOMEM; |
| 647 | goto failed_map; |
| 648 | } |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 649 | |
| 650 | info->screen_base = fbi->map_cpu; |
| 651 | fbi->screen_cpu = fbi->map_cpu; |
| 652 | fbi->screen_dma = fbi->map_dma; |
| 653 | info->fix.smem_start = fbi->screen_dma; |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 654 | } else { |
| 655 | /* Fixed framebuffer mapping enables location of the screen in eSRAM */ |
Sascha Hauer | 2788927 | 2008-12-16 11:44:09 +0100 | [diff] [blame] | 656 | fbi->map_cpu = pdata->fixed_screen_cpu; |
| 657 | fbi->map_dma = pdata->fixed_screen_dma; |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 658 | info->screen_base = fbi->map_cpu; |
| 659 | fbi->screen_cpu = fbi->map_cpu; |
| 660 | fbi->screen_dma = fbi->map_dma; |
| 661 | info->fix.smem_start = fbi->screen_dma; |
| 662 | } |
| 663 | |
Sascha Hauer | c0b90a3 | 2009-01-15 15:37:22 +0100 | [diff] [blame] | 664 | if (pdata->init) { |
| 665 | ret = pdata->init(fbi->pdev); |
| 666 | if (ret) |
| 667 | goto failed_platform_init; |
| 668 | } |
| 669 | |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 670 | /* |
| 671 | * This makes sure that our colour bitfield |
| 672 | * descriptors are correctly initialised. |
| 673 | */ |
| 674 | imxfb_check_var(&info->var, info); |
| 675 | |
Sascha Hauer | 66c8719 | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 676 | ret = fb_alloc_cmap(&info->cmap, 1 << info->var.bits_per_pixel, 0); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 677 | if (ret < 0) |
| 678 | goto failed_cmap; |
| 679 | |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 680 | imxfb_set_par(info); |
| 681 | ret = register_framebuffer(info); |
| 682 | if (ret < 0) { |
Pavel Pisa | f99c892 | 2006-01-07 10:44:32 +0000 | [diff] [blame] | 683 | dev_err(&pdev->dev, "failed to register framebuffer\n"); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 684 | goto failed_register; |
| 685 | } |
| 686 | |
| 687 | imxfb_enable_controller(fbi); |
| 688 | |
| 689 | return 0; |
| 690 | |
| 691 | failed_register: |
| 692 | fb_dealloc_cmap(&info->cmap); |
| 693 | failed_cmap: |
Sascha Hauer | c0b90a3 | 2009-01-15 15:37:22 +0100 | [diff] [blame] | 694 | if (pdata->exit) |
| 695 | pdata->exit(fbi->pdev); |
| 696 | failed_platform_init: |
Sascha Hauer | 2788927 | 2008-12-16 11:44:09 +0100 | [diff] [blame] | 697 | if (!pdata->fixed_screen_cpu) |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 698 | dma_free_writecombine(&pdev->dev,fbi->map_size,fbi->map_cpu, |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 699 | fbi->map_dma); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 700 | failed_map: |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 701 | iounmap(fbi->regs); |
| 702 | failed_ioremap: |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 703 | release_mem_region(res->start, res->end - res->start); |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 704 | failed_req: |
| 705 | kfree(info->pseudo_palette); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 706 | failed_init: |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 707 | platform_set_drvdata(pdev, NULL); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 708 | framebuffer_release(info); |
| 709 | return ret; |
| 710 | } |
| 711 | |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 712 | static int __devexit imxfb_remove(struct platform_device *pdev) |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 713 | { |
Sascha Hauer | c0b90a3 | 2009-01-15 15:37:22 +0100 | [diff] [blame] | 714 | struct imx_fb_platform_data *pdata; |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 715 | struct fb_info *info = platform_get_drvdata(pdev); |
Sascha Hauer | 772a9e63 | 2005-07-17 20:15:36 +0100 | [diff] [blame] | 716 | struct imxfb_info *fbi = info->par; |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 717 | struct resource *res; |
| 718 | |
| 719 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 720 | |
Sascha Hauer | 772a9e63 | 2005-07-17 20:15:36 +0100 | [diff] [blame] | 721 | imxfb_disable_controller(fbi); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 722 | |
| 723 | unregister_framebuffer(info); |
| 724 | |
Sascha Hauer | c0b90a3 | 2009-01-15 15:37:22 +0100 | [diff] [blame] | 725 | pdata = pdev->dev.platform_data; |
| 726 | if (pdata->exit) |
| 727 | pdata->exit(fbi->pdev); |
| 728 | |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 729 | fb_dealloc_cmap(&info->cmap); |
| 730 | kfree(info->pseudo_palette); |
| 731 | framebuffer_release(info); |
| 732 | |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 733 | iounmap(fbi->regs); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 734 | release_mem_region(res->start, res->end - res->start + 1); |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 735 | platform_set_drvdata(pdev, NULL); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 736 | |
| 737 | return 0; |
| 738 | } |
| 739 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 740 | void imxfb_shutdown(struct platform_device * dev) |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 741 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 742 | struct fb_info *info = platform_get_drvdata(dev); |
Sascha Hauer | 772a9e63 | 2005-07-17 20:15:36 +0100 | [diff] [blame] | 743 | struct imxfb_info *fbi = info->par; |
| 744 | imxfb_disable_controller(fbi); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 745 | } |
| 746 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 747 | static struct platform_driver imxfb_driver = { |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 748 | .suspend = imxfb_suspend, |
| 749 | .resume = imxfb_resume, |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 750 | .remove = __devexit_p(imxfb_remove), |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 751 | .shutdown = imxfb_shutdown, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 752 | .driver = { |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 753 | .name = DRIVER_NAME, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 754 | }, |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 755 | }; |
| 756 | |
| 757 | int __init imxfb_init(void) |
| 758 | { |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 759 | return platform_driver_probe(&imxfb_driver, imxfb_probe); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | static void __exit imxfb_cleanup(void) |
| 763 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 764 | platform_driver_unregister(&imxfb_driver); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 765 | } |
| 766 | |
| 767 | module_init(imxfb_init); |
| 768 | module_exit(imxfb_cleanup); |
| 769 | |
| 770 | MODULE_DESCRIPTION("Motorola i.MX framebuffer driver"); |
| 771 | MODULE_AUTHOR("Sascha Hauer, Pengutronix"); |
| 772 | MODULE_LICENSE("GPL"); |