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> |
Sascha Hauer | f909ef6 | 2009-01-15 15:21:00 +0100 | [diff] [blame] | 29 | #include <linux/clk.h> |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 30 | #include <linux/platform_device.h> |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 31 | #include <linux/dma-mapping.h> |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 32 | #include <linux/io.h> |
Sascha Hauer | f909ef6 | 2009-01-15 15:21:00 +0100 | [diff] [blame] | 33 | #include <linux/math64.h> |
Markus Pargmann | 1b6c793 | 2013-05-26 12:35:38 +0200 | [diff] [blame] | 34 | #include <linux/of.h> |
| 35 | #include <linux/of_device.h> |
| 36 | |
| 37 | #include <video/of_display_timing.h> |
| 38 | #include <video/of_videomode.h> |
| 39 | #include <video/videomode.h> |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 40 | |
Arnd Bergmann | 82906b1 | 2012-08-24 15:14:29 +0200 | [diff] [blame] | 41 | #include <linux/platform_data/video-imxfb.h> |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 42 | |
| 43 | /* |
| 44 | * Complain if VAR is out of range. |
| 45 | */ |
| 46 | #define DEBUG_VAR 1 |
| 47 | |
Eric Bénard | 81ef806 | 2010-08-02 08:39:55 +0100 | [diff] [blame] | 48 | #if defined(CONFIG_BACKLIGHT_CLASS_DEVICE) || \ |
| 49 | (defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE) && \ |
| 50 | defined(CONFIG_FB_IMX_MODULE)) |
| 51 | #define PWMR_BACKLIGHT_AVAILABLE |
| 52 | #endif |
| 53 | |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 54 | #define DRIVER_NAME "imx-fb" |
| 55 | |
| 56 | #define LCDC_SSA 0x00 |
| 57 | |
| 58 | #define LCDC_SIZE 0x04 |
| 59 | #define SIZE_XMAX(x) ((((x) >> 4) & 0x3f) << 20) |
Sascha Hauer | 1d0f987 | 2009-01-26 17:29:10 +0100 | [diff] [blame] | 60 | |
Shawn Guo | e69dc9a | 2012-09-16 19:59:53 +0800 | [diff] [blame] | 61 | #define YMAX_MASK_IMX1 0x1ff |
| 62 | #define YMAX_MASK_IMX21 0x3ff |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 63 | |
| 64 | #define LCDC_VPW 0x08 |
| 65 | #define VPW_VPW(x) ((x) & 0x3ff) |
| 66 | |
| 67 | #define LCDC_CPOS 0x0C |
| 68 | #define CPOS_CC1 (1<<31) |
| 69 | #define CPOS_CC0 (1<<30) |
| 70 | #define CPOS_OP (1<<28) |
| 71 | #define CPOS_CXP(x) (((x) & 3ff) << 16) |
Sascha Hauer | 1d0f987 | 2009-01-26 17:29:10 +0100 | [diff] [blame] | 72 | |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 73 | #define LCDC_LCWHB 0x10 |
| 74 | #define LCWHB_BK_EN (1<<31) |
| 75 | #define LCWHB_CW(w) (((w) & 0x1f) << 24) |
| 76 | #define LCWHB_CH(h) (((h) & 0x1f) << 16) |
| 77 | #define LCWHB_BD(x) ((x) & 0xff) |
| 78 | |
| 79 | #define LCDC_LCHCC 0x14 |
Sascha Hauer | 1d0f987 | 2009-01-26 17:29:10 +0100 | [diff] [blame] | 80 | |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 81 | #define LCDC_PCR 0x18 |
| 82 | |
| 83 | #define LCDC_HCR 0x1C |
| 84 | #define HCR_H_WIDTH(x) (((x) & 0x3f) << 26) |
| 85 | #define HCR_H_WAIT_1(x) (((x) & 0xff) << 8) |
| 86 | #define HCR_H_WAIT_2(x) ((x) & 0xff) |
| 87 | |
| 88 | #define LCDC_VCR 0x20 |
| 89 | #define VCR_V_WIDTH(x) (((x) & 0x3f) << 26) |
| 90 | #define VCR_V_WAIT_1(x) (((x) & 0xff) << 8) |
| 91 | #define VCR_V_WAIT_2(x) ((x) & 0xff) |
| 92 | |
| 93 | #define LCDC_POS 0x24 |
| 94 | #define POS_POS(x) ((x) & 1f) |
| 95 | |
| 96 | #define LCDC_LSCR1 0x28 |
| 97 | /* bit fields in imxfb.h */ |
| 98 | |
| 99 | #define LCDC_PWMR 0x2C |
| 100 | /* bit fields in imxfb.h */ |
| 101 | |
| 102 | #define LCDC_DMACR 0x30 |
| 103 | /* bit fields in imxfb.h */ |
| 104 | |
| 105 | #define LCDC_RMCR 0x34 |
Sascha Hauer | 1d0f987 | 2009-01-26 17:29:10 +0100 | [diff] [blame] | 106 | |
Sascha Hauer | f142b61 | 2011-03-03 15:12:44 +0100 | [diff] [blame] | 107 | #define RMCR_LCDC_EN_MX1 (1<<1) |
Sascha Hauer | 1d0f987 | 2009-01-26 17:29:10 +0100 | [diff] [blame] | 108 | |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 109 | #define RMCR_SELF_REF (1<<0) |
| 110 | |
| 111 | #define LCDC_LCDICR 0x38 |
| 112 | #define LCDICR_INT_SYN (1<<2) |
| 113 | #define LCDICR_INT_CON (1) |
| 114 | |
| 115 | #define LCDC_LCDISR 0x40 |
| 116 | #define LCDISR_UDR_ERR (1<<3) |
| 117 | #define LCDISR_ERR_RES (1<<2) |
| 118 | #define LCDISR_EOF (1<<1) |
| 119 | #define LCDISR_BOF (1<<0) |
| 120 | |
Markus Pargmann | 1b6c793 | 2013-05-26 12:35:38 +0200 | [diff] [blame] | 121 | #define IMXFB_LSCR1_DEFAULT 0x00120300 |
| 122 | |
Sascha Hauer | 343684f | 2009-03-19 08:25:41 +0100 | [diff] [blame] | 123 | /* Used fb-mode. Can be set on kernel command line, therefore file-static. */ |
| 124 | static const char *fb_mode; |
| 125 | |
Sascha Hauer | 24b9baf | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 126 | /* |
| 127 | * These are the bitfields for each |
| 128 | * display depth that we support. |
| 129 | */ |
| 130 | struct imxfb_rgb { |
| 131 | struct fb_bitfield red; |
| 132 | struct fb_bitfield green; |
| 133 | struct fb_bitfield blue; |
| 134 | struct fb_bitfield transp; |
| 135 | }; |
| 136 | |
Shawn Guo | e69dc9a | 2012-09-16 19:59:53 +0800 | [diff] [blame] | 137 | enum imxfb_type { |
| 138 | IMX1_FB, |
| 139 | IMX21_FB, |
| 140 | }; |
| 141 | |
Sascha Hauer | 24b9baf | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 142 | struct imxfb_info { |
| 143 | struct platform_device *pdev; |
| 144 | void __iomem *regs; |
Sascha Hauer | 13aaea0 | 2012-03-07 09:30:36 +0100 | [diff] [blame] | 145 | struct clk *clk_ipg; |
| 146 | struct clk *clk_ahb; |
| 147 | struct clk *clk_per; |
Shawn Guo | e69dc9a | 2012-09-16 19:59:53 +0800 | [diff] [blame] | 148 | enum imxfb_type devtype; |
Fabio Estevam | e6b267c | 2013-01-16 10:58:41 -0200 | [diff] [blame] | 149 | bool enabled; |
Sascha Hauer | 24b9baf | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 150 | |
Sascha Hauer | 24b9baf | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 151 | /* |
| 152 | * These are the addresses we mapped |
| 153 | * the framebuffer memory region to. |
| 154 | */ |
| 155 | dma_addr_t map_dma; |
| 156 | u_char *map_cpu; |
| 157 | u_int map_size; |
| 158 | |
| 159 | u_char *screen_cpu; |
| 160 | dma_addr_t screen_dma; |
| 161 | u_int palette_size; |
| 162 | |
| 163 | dma_addr_t dbar1; |
| 164 | dma_addr_t dbar2; |
| 165 | |
| 166 | u_int pcr; |
| 167 | u_int pwmr; |
| 168 | u_int lscr1; |
| 169 | u_int dmacr; |
| 170 | u_int cmap_inverse:1, |
| 171 | cmap_static:1, |
| 172 | unused:30; |
| 173 | |
Sascha Hauer | 343684f | 2009-03-19 08:25:41 +0100 | [diff] [blame] | 174 | struct imx_fb_videomode *mode; |
| 175 | int num_modes; |
Eric Bénard | 81ef806 | 2010-08-02 08:39:55 +0100 | [diff] [blame] | 176 | #ifdef PWMR_BACKLIGHT_AVAILABLE |
Eric Bénard | 7a2bb23 | 2010-07-16 15:09:07 +0200 | [diff] [blame] | 177 | struct backlight_device *bl; |
Eric Bénard | 81ef806 | 2010-08-02 08:39:55 +0100 | [diff] [blame] | 178 | #endif |
Sascha Hauer | 343684f | 2009-03-19 08:25:41 +0100 | [diff] [blame] | 179 | |
Sascha Hauer | 24b9baf | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 180 | void (*lcd_power)(int); |
| 181 | void (*backlight_power)(int); |
| 182 | }; |
| 183 | |
Shawn Guo | e69dc9a | 2012-09-16 19:59:53 +0800 | [diff] [blame] | 184 | static struct platform_device_id imxfb_devtype[] = { |
| 185 | { |
| 186 | .name = "imx1-fb", |
| 187 | .driver_data = IMX1_FB, |
| 188 | }, { |
| 189 | .name = "imx21-fb", |
| 190 | .driver_data = IMX21_FB, |
| 191 | }, { |
| 192 | /* sentinel */ |
| 193 | } |
| 194 | }; |
| 195 | MODULE_DEVICE_TABLE(platform, imxfb_devtype); |
| 196 | |
Markus Pargmann | 1b6c793 | 2013-05-26 12:35:38 +0200 | [diff] [blame] | 197 | static struct of_device_id imxfb_of_dev_id[] = { |
| 198 | { |
| 199 | .compatible = "fsl,imx1-fb", |
| 200 | .data = &imxfb_devtype[IMX1_FB], |
| 201 | }, { |
| 202 | .compatible = "fsl,imx21-fb", |
| 203 | .data = &imxfb_devtype[IMX21_FB], |
| 204 | }, { |
| 205 | /* sentinel */ |
| 206 | } |
| 207 | }; |
| 208 | MODULE_DEVICE_TABLE(of, imxfb_of_dev_id); |
| 209 | |
Shawn Guo | e69dc9a | 2012-09-16 19:59:53 +0800 | [diff] [blame] | 210 | static inline int is_imx1_fb(struct imxfb_info *fbi) |
| 211 | { |
| 212 | return fbi->devtype == IMX1_FB; |
| 213 | } |
| 214 | |
Sascha Hauer | 24b9baf | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 215 | #define IMX_NAME "IMX" |
| 216 | |
| 217 | /* |
| 218 | * Minimum X and Y resolutions |
| 219 | */ |
| 220 | #define MIN_XRES 64 |
| 221 | #define MIN_YRES 64 |
| 222 | |
Sascha Hauer | 1512222 | 2009-01-26 17:31:02 +0100 | [diff] [blame] | 223 | /* Actually this really is 18bit support, the lowest 2 bits of each colour |
| 224 | * are unused in hardware. We claim to have 24bit support to make software |
| 225 | * like X work, which does not support 18bit. |
| 226 | */ |
| 227 | static struct imxfb_rgb def_rgb_18 = { |
| 228 | .red = {.offset = 16, .length = 8,}, |
| 229 | .green = {.offset = 8, .length = 8,}, |
| 230 | .blue = {.offset = 0, .length = 8,}, |
| 231 | .transp = {.offset = 0, .length = 0,}, |
| 232 | }; |
| 233 | |
Sascha Hauer | 80eee6b | 2008-12-16 11:44:09 +0100 | [diff] [blame] | 234 | static struct imxfb_rgb def_rgb_16_tft = { |
| 235 | .red = {.offset = 11, .length = 5,}, |
| 236 | .green = {.offset = 5, .length = 6,}, |
| 237 | .blue = {.offset = 0, .length = 5,}, |
| 238 | .transp = {.offset = 0, .length = 0,}, |
| 239 | }; |
| 240 | |
| 241 | static struct imxfb_rgb def_rgb_16_stn = { |
Sascha Hauer | 66c8719 | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 242 | .red = {.offset = 8, .length = 4,}, |
| 243 | .green = {.offset = 4, .length = 4,}, |
| 244 | .blue = {.offset = 0, .length = 4,}, |
| 245 | .transp = {.offset = 0, .length = 0,}, |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 246 | }; |
| 247 | |
| 248 | static struct imxfb_rgb def_rgb_8 = { |
Sascha Hauer | 66c8719 | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 249 | .red = {.offset = 0, .length = 8,}, |
| 250 | .green = {.offset = 0, .length = 8,}, |
| 251 | .blue = {.offset = 0, .length = 8,}, |
| 252 | .transp = {.offset = 0, .length = 0,}, |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 253 | }; |
| 254 | |
Sascha Hauer | 66c8719 | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 255 | static int imxfb_activate_var(struct fb_var_screeninfo *var, |
| 256 | struct fb_info *info); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 257 | |
| 258 | static inline u_int chan_to_field(u_int chan, struct fb_bitfield *bf) |
| 259 | { |
| 260 | chan &= 0xffff; |
| 261 | chan >>= 16 - bf->length; |
| 262 | return chan << bf->offset; |
| 263 | } |
| 264 | |
Sascha Hauer | 66c8719 | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 265 | static int imxfb_setpalettereg(u_int regno, u_int red, u_int green, u_int blue, |
| 266 | u_int trans, struct fb_info *info) |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 267 | { |
| 268 | struct imxfb_info *fbi = info->par; |
| 269 | u_int val, ret = 1; |
| 270 | |
| 271 | #define CNVT_TOHW(val,width) ((((val)<<(width))+0x7FFF-(val))>>16) |
| 272 | if (regno < fbi->palette_size) { |
| 273 | val = (CNVT_TOHW(red, 4) << 8) | |
| 274 | (CNVT_TOHW(green,4) << 4) | |
| 275 | CNVT_TOHW(blue, 4); |
| 276 | |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 277 | writel(val, fbi->regs + 0x800 + (regno << 2)); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 278 | ret = 0; |
| 279 | } |
| 280 | return ret; |
| 281 | } |
| 282 | |
Sascha Hauer | 66c8719 | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 283 | 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] | 284 | u_int trans, struct fb_info *info) |
| 285 | { |
| 286 | struct imxfb_info *fbi = info->par; |
| 287 | unsigned int val; |
| 288 | int ret = 1; |
| 289 | |
| 290 | /* |
| 291 | * If inverse mode was selected, invert all the colours |
| 292 | * rather than the register number. The register number |
| 293 | * is what you poke into the framebuffer to produce the |
| 294 | * colour you requested. |
| 295 | */ |
| 296 | if (fbi->cmap_inverse) { |
| 297 | red = 0xffff - red; |
| 298 | green = 0xffff - green; |
| 299 | blue = 0xffff - blue; |
| 300 | } |
| 301 | |
| 302 | /* |
| 303 | * If greyscale is true, then we convert the RGB value |
| 304 | * to greyscale no mater what visual we are using. |
| 305 | */ |
| 306 | if (info->var.grayscale) |
| 307 | red = green = blue = (19595 * red + 38470 * green + |
| 308 | 7471 * blue) >> 16; |
| 309 | |
| 310 | switch (info->fix.visual) { |
| 311 | case FB_VISUAL_TRUECOLOR: |
| 312 | /* |
| 313 | * 12 or 16-bit True Colour. We encode the RGB value |
| 314 | * according to the RGB bitfield information. |
| 315 | */ |
| 316 | if (regno < 16) { |
| 317 | u32 *pal = info->pseudo_palette; |
| 318 | |
| 319 | val = chan_to_field(red, &info->var.red); |
| 320 | val |= chan_to_field(green, &info->var.green); |
| 321 | val |= chan_to_field(blue, &info->var.blue); |
| 322 | |
| 323 | pal[regno] = val; |
| 324 | ret = 0; |
| 325 | } |
| 326 | break; |
| 327 | |
| 328 | case FB_VISUAL_STATIC_PSEUDOCOLOR: |
| 329 | case FB_VISUAL_PSEUDOCOLOR: |
| 330 | ret = imxfb_setpalettereg(regno, red, green, blue, trans, info); |
| 331 | break; |
| 332 | } |
| 333 | |
| 334 | return ret; |
| 335 | } |
| 336 | |
Sascha Hauer | 343684f | 2009-03-19 08:25:41 +0100 | [diff] [blame] | 337 | static const struct imx_fb_videomode *imxfb_find_mode(struct imxfb_info *fbi) |
| 338 | { |
| 339 | struct imx_fb_videomode *m; |
| 340 | int i; |
| 341 | |
Markus Pargmann | 1b6c793 | 2013-05-26 12:35:38 +0200 | [diff] [blame] | 342 | if (!fb_mode) |
| 343 | return &fbi->mode[0]; |
| 344 | |
Sascha Hauer | 343684f | 2009-03-19 08:25:41 +0100 | [diff] [blame] | 345 | for (i = 0, m = &fbi->mode[0]; i < fbi->num_modes; i++, m++) { |
| 346 | if (!strcmp(m->mode.name, fb_mode)) |
| 347 | return m; |
| 348 | } |
| 349 | return NULL; |
| 350 | } |
| 351 | |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 352 | /* |
| 353 | * imxfb_check_var(): |
| 354 | * Round up in the following order: bits_per_pixel, xres, |
| 355 | * yres, xres_virtual, yres_virtual, xoffset, yoffset, grayscale, |
| 356 | * bitfields, horizontal timing, vertical timing. |
| 357 | */ |
Sascha Hauer | 66c8719 | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 358 | 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] | 359 | { |
| 360 | struct imxfb_info *fbi = info->par; |
Sascha Hauer | 80eee6b | 2008-12-16 11:44:09 +0100 | [diff] [blame] | 361 | struct imxfb_rgb *rgb; |
Sascha Hauer | 343684f | 2009-03-19 08:25:41 +0100 | [diff] [blame] | 362 | const struct imx_fb_videomode *imxfb_mode; |
| 363 | unsigned long lcd_clk; |
| 364 | unsigned long long tmp; |
| 365 | u32 pcr = 0; |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 366 | |
| 367 | if (var->xres < MIN_XRES) |
| 368 | var->xres = MIN_XRES; |
| 369 | if (var->yres < MIN_YRES) |
| 370 | var->yres = MIN_YRES; |
Sascha Hauer | 343684f | 2009-03-19 08:25:41 +0100 | [diff] [blame] | 371 | |
| 372 | imxfb_mode = imxfb_find_mode(fbi); |
| 373 | if (!imxfb_mode) |
| 374 | return -EINVAL; |
| 375 | |
| 376 | var->xres = imxfb_mode->mode.xres; |
| 377 | var->yres = imxfb_mode->mode.yres; |
| 378 | var->bits_per_pixel = imxfb_mode->bpp; |
| 379 | var->pixclock = imxfb_mode->mode.pixclock; |
| 380 | var->hsync_len = imxfb_mode->mode.hsync_len; |
| 381 | var->left_margin = imxfb_mode->mode.left_margin; |
| 382 | var->right_margin = imxfb_mode->mode.right_margin; |
| 383 | var->vsync_len = imxfb_mode->mode.vsync_len; |
| 384 | var->upper_margin = imxfb_mode->mode.upper_margin; |
| 385 | var->lower_margin = imxfb_mode->mode.lower_margin; |
| 386 | var->sync = imxfb_mode->mode.sync; |
| 387 | var->xres_virtual = max(var->xres_virtual, var->xres); |
| 388 | var->yres_virtual = max(var->yres_virtual, var->yres); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 389 | |
| 390 | pr_debug("var->bits_per_pixel=%d\n", var->bits_per_pixel); |
Sascha Hauer | 343684f | 2009-03-19 08:25:41 +0100 | [diff] [blame] | 391 | |
Sascha Hauer | 13aaea0 | 2012-03-07 09:30:36 +0100 | [diff] [blame] | 392 | lcd_clk = clk_get_rate(fbi->clk_per); |
Sascha Hauer | 343684f | 2009-03-19 08:25:41 +0100 | [diff] [blame] | 393 | |
| 394 | tmp = var->pixclock * (unsigned long long)lcd_clk; |
| 395 | |
| 396 | do_div(tmp, 1000000); |
| 397 | |
| 398 | if (do_div(tmp, 1000000) > 500000) |
| 399 | tmp++; |
| 400 | |
| 401 | pcr = (unsigned int)tmp; |
| 402 | |
| 403 | if (--pcr > 0x3F) { |
| 404 | pcr = 0x3F; |
| 405 | printk(KERN_WARNING "Must limit pixel clock to %luHz\n", |
| 406 | lcd_clk / pcr); |
| 407 | } |
| 408 | |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 409 | switch (var->bits_per_pixel) { |
Sascha Hauer | 1512222 | 2009-01-26 17:31:02 +0100 | [diff] [blame] | 410 | case 32: |
Sascha Hauer | 343684f | 2009-03-19 08:25:41 +0100 | [diff] [blame] | 411 | pcr |= PCR_BPIX_18; |
Sascha Hauer | 1512222 | 2009-01-26 17:31:02 +0100 | [diff] [blame] | 412 | rgb = &def_rgb_18; |
| 413 | break; |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 414 | case 16: |
Sascha Hauer | 80eee6b | 2008-12-16 11:44:09 +0100 | [diff] [blame] | 415 | default: |
Shawn Guo | e69dc9a | 2012-09-16 19:59:53 +0800 | [diff] [blame] | 416 | if (is_imx1_fb(fbi)) |
Sascha Hauer | 343684f | 2009-03-19 08:25:41 +0100 | [diff] [blame] | 417 | pcr |= PCR_BPIX_12; |
| 418 | else |
| 419 | pcr |= PCR_BPIX_16; |
| 420 | |
| 421 | if (imxfb_mode->pcr & PCR_TFT) |
Sascha Hauer | 80eee6b | 2008-12-16 11:44:09 +0100 | [diff] [blame] | 422 | rgb = &def_rgb_16_tft; |
| 423 | else |
| 424 | rgb = &def_rgb_16_stn; |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 425 | break; |
| 426 | case 8: |
Sascha Hauer | 343684f | 2009-03-19 08:25:41 +0100 | [diff] [blame] | 427 | pcr |= PCR_BPIX_8; |
Sascha Hauer | 80eee6b | 2008-12-16 11:44:09 +0100 | [diff] [blame] | 428 | rgb = &def_rgb_8; |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 429 | break; |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 430 | } |
| 431 | |
Sascha Hauer | 343684f | 2009-03-19 08:25:41 +0100 | [diff] [blame] | 432 | /* add sync polarities */ |
| 433 | pcr |= imxfb_mode->pcr & ~(0x3f | (7 << 25)); |
| 434 | |
| 435 | fbi->pcr = pcr; |
| 436 | |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 437 | /* |
| 438 | * Copy the RGB parameters for this display |
| 439 | * from the machine specific parameters. |
| 440 | */ |
Sascha Hauer | 80eee6b | 2008-12-16 11:44:09 +0100 | [diff] [blame] | 441 | var->red = rgb->red; |
| 442 | var->green = rgb->green; |
| 443 | var->blue = rgb->blue; |
| 444 | var->transp = rgb->transp; |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 445 | |
| 446 | pr_debug("RGBT length = %d:%d:%d:%d\n", |
| 447 | var->red.length, var->green.length, var->blue.length, |
| 448 | var->transp.length); |
| 449 | |
| 450 | pr_debug("RGBT offset = %d:%d:%d:%d\n", |
| 451 | var->red.offset, var->green.offset, var->blue.offset, |
| 452 | var->transp.offset); |
| 453 | |
| 454 | return 0; |
| 455 | } |
| 456 | |
| 457 | /* |
| 458 | * imxfb_set_par(): |
| 459 | * Set the user defined part of the display for the specified console |
| 460 | */ |
| 461 | static int imxfb_set_par(struct fb_info *info) |
| 462 | { |
| 463 | struct imxfb_info *fbi = info->par; |
| 464 | struct fb_var_screeninfo *var = &info->var; |
| 465 | |
Sascha Hauer | 1512222 | 2009-01-26 17:31:02 +0100 | [diff] [blame] | 466 | if (var->bits_per_pixel == 16 || var->bits_per_pixel == 32) |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 467 | info->fix.visual = FB_VISUAL_TRUECOLOR; |
| 468 | else if (!fbi->cmap_static) |
| 469 | info->fix.visual = FB_VISUAL_PSEUDOCOLOR; |
| 470 | else { |
| 471 | /* |
| 472 | * Some people have weird ideas about wanting static |
| 473 | * pseudocolor maps. I suspect their user space |
| 474 | * applications are broken. |
| 475 | */ |
| 476 | info->fix.visual = FB_VISUAL_STATIC_PSEUDOCOLOR; |
| 477 | } |
| 478 | |
Sascha Hauer | 66c8719 | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 479 | info->fix.line_length = var->xres_virtual * var->bits_per_pixel / 8; |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 480 | fbi->palette_size = var->bits_per_pixel == 8 ? 256 : 16; |
| 481 | |
| 482 | imxfb_activate_var(var, info); |
| 483 | |
| 484 | return 0; |
| 485 | } |
| 486 | |
Eric Bénard | 81ef806 | 2010-08-02 08:39:55 +0100 | [diff] [blame] | 487 | #ifdef PWMR_BACKLIGHT_AVAILABLE |
Eric Bénard | 7a2bb23 | 2010-07-16 15:09:07 +0200 | [diff] [blame] | 488 | static int imxfb_bl_get_brightness(struct backlight_device *bl) |
| 489 | { |
| 490 | struct imxfb_info *fbi = bl_get_data(bl); |
| 491 | |
| 492 | return readl(fbi->regs + LCDC_PWMR) & 0xFF; |
| 493 | } |
| 494 | |
| 495 | static int imxfb_bl_update_status(struct backlight_device *bl) |
| 496 | { |
| 497 | struct imxfb_info *fbi = bl_get_data(bl); |
| 498 | int brightness = bl->props.brightness; |
| 499 | |
Markus Pargmann | 1b6c793 | 2013-05-26 12:35:38 +0200 | [diff] [blame] | 500 | if (!fbi->pwmr) |
| 501 | return 0; |
| 502 | |
Eric Bénard | 7a2bb23 | 2010-07-16 15:09:07 +0200 | [diff] [blame] | 503 | if (bl->props.power != FB_BLANK_UNBLANK) |
| 504 | brightness = 0; |
| 505 | if (bl->props.fb_blank != FB_BLANK_UNBLANK) |
| 506 | brightness = 0; |
| 507 | |
| 508 | fbi->pwmr = (fbi->pwmr & ~0xFF) | brightness; |
| 509 | |
Sascha Hauer | 13aaea0 | 2012-03-07 09:30:36 +0100 | [diff] [blame] | 510 | if (bl->props.fb_blank != FB_BLANK_UNBLANK) { |
| 511 | clk_prepare_enable(fbi->clk_ipg); |
| 512 | clk_prepare_enable(fbi->clk_ahb); |
| 513 | clk_prepare_enable(fbi->clk_per); |
| 514 | } |
Eric Bénard | 7a2bb23 | 2010-07-16 15:09:07 +0200 | [diff] [blame] | 515 | writel(fbi->pwmr, fbi->regs + LCDC_PWMR); |
Sascha Hauer | 13aaea0 | 2012-03-07 09:30:36 +0100 | [diff] [blame] | 516 | if (bl->props.fb_blank != FB_BLANK_UNBLANK) { |
| 517 | clk_disable_unprepare(fbi->clk_per); |
| 518 | clk_disable_unprepare(fbi->clk_ahb); |
| 519 | clk_disable_unprepare(fbi->clk_ipg); |
| 520 | } |
Eric Bénard | 7a2bb23 | 2010-07-16 15:09:07 +0200 | [diff] [blame] | 521 | |
| 522 | return 0; |
| 523 | } |
| 524 | |
| 525 | static const struct backlight_ops imxfb_lcdc_bl_ops = { |
| 526 | .update_status = imxfb_bl_update_status, |
| 527 | .get_brightness = imxfb_bl_get_brightness, |
| 528 | }; |
| 529 | |
| 530 | static void imxfb_init_backlight(struct imxfb_info *fbi) |
| 531 | { |
| 532 | struct backlight_properties props; |
| 533 | struct backlight_device *bl; |
| 534 | |
| 535 | if (fbi->bl) |
| 536 | return; |
| 537 | |
| 538 | memset(&props, 0, sizeof(struct backlight_properties)); |
| 539 | props.max_brightness = 0xff; |
Matthew Garrett | bb7ca74 | 2011-03-22 16:30:21 -0700 | [diff] [blame] | 540 | props.type = BACKLIGHT_RAW; |
Eric Bénard | 7a2bb23 | 2010-07-16 15:09:07 +0200 | [diff] [blame] | 541 | writel(fbi->pwmr, fbi->regs + LCDC_PWMR); |
| 542 | |
| 543 | bl = backlight_device_register("imxfb-bl", &fbi->pdev->dev, fbi, |
| 544 | &imxfb_lcdc_bl_ops, &props); |
| 545 | if (IS_ERR(bl)) { |
| 546 | dev_err(&fbi->pdev->dev, "error %ld on backlight register\n", |
| 547 | PTR_ERR(bl)); |
| 548 | return; |
| 549 | } |
| 550 | |
| 551 | fbi->bl = bl; |
| 552 | bl->props.power = FB_BLANK_UNBLANK; |
| 553 | bl->props.fb_blank = FB_BLANK_UNBLANK; |
| 554 | bl->props.brightness = imxfb_bl_get_brightness(bl); |
| 555 | } |
| 556 | |
| 557 | static void imxfb_exit_backlight(struct imxfb_info *fbi) |
| 558 | { |
| 559 | if (fbi->bl) |
| 560 | backlight_device_unregister(fbi->bl); |
| 561 | } |
Eric Bénard | 81ef806 | 2010-08-02 08:39:55 +0100 | [diff] [blame] | 562 | #endif |
Eric Bénard | 7a2bb23 | 2010-07-16 15:09:07 +0200 | [diff] [blame] | 563 | |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 564 | static void imxfb_enable_controller(struct imxfb_info *fbi) |
| 565 | { |
Fabio Estevam | e6b267c | 2013-01-16 10:58:41 -0200 | [diff] [blame] | 566 | |
| 567 | if (fbi->enabled) |
| 568 | return; |
| 569 | |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 570 | pr_debug("Enabling LCD controller\n"); |
| 571 | |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 572 | writel(fbi->screen_dma, fbi->regs + LCDC_SSA); |
| 573 | |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 574 | /* panning offset 0 (0 pixel offset) */ |
| 575 | writel(0x00000000, fbi->regs + LCDC_POS); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 576 | |
| 577 | /* disable hardware cursor */ |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 578 | writel(readl(fbi->regs + LCDC_CPOS) & ~(CPOS_CC0 | CPOS_CC1), |
| 579 | fbi->regs + LCDC_CPOS); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 580 | |
Sascha Hauer | f142b61 | 2011-03-03 15:12:44 +0100 | [diff] [blame] | 581 | /* |
| 582 | * RMCR_LCDC_EN_MX1 is present on i.MX1 only, but doesn't hurt |
| 583 | * on other SoCs |
| 584 | */ |
| 585 | writel(RMCR_LCDC_EN_MX1, fbi->regs + LCDC_RMCR); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 586 | |
Sascha Hauer | 13aaea0 | 2012-03-07 09:30:36 +0100 | [diff] [blame] | 587 | clk_prepare_enable(fbi->clk_ipg); |
| 588 | clk_prepare_enable(fbi->clk_ahb); |
| 589 | clk_prepare_enable(fbi->clk_per); |
Fabio Estevam | e6b267c | 2013-01-16 10:58:41 -0200 | [diff] [blame] | 590 | fbi->enabled = true; |
Sascha Hauer | f909ef6 | 2009-01-15 15:21:00 +0100 | [diff] [blame] | 591 | |
Sascha Hauer | 66c8719 | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 592 | if (fbi->backlight_power) |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 593 | fbi->backlight_power(1); |
Sascha Hauer | 66c8719 | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 594 | if (fbi->lcd_power) |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 595 | fbi->lcd_power(1); |
| 596 | } |
| 597 | |
| 598 | static void imxfb_disable_controller(struct imxfb_info *fbi) |
| 599 | { |
Fabio Estevam | e6b267c | 2013-01-16 10:58:41 -0200 | [diff] [blame] | 600 | if (!fbi->enabled) |
| 601 | return; |
| 602 | |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 603 | pr_debug("Disabling LCD controller\n"); |
| 604 | |
Sascha Hauer | 66c8719 | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 605 | if (fbi->backlight_power) |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 606 | fbi->backlight_power(0); |
Sascha Hauer | 66c8719 | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 607 | if (fbi->lcd_power) |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 608 | fbi->lcd_power(0); |
| 609 | |
Sascha Hauer | 13aaea0 | 2012-03-07 09:30:36 +0100 | [diff] [blame] | 610 | clk_disable_unprepare(fbi->clk_per); |
| 611 | clk_disable_unprepare(fbi->clk_ipg); |
| 612 | clk_disable_unprepare(fbi->clk_ahb); |
Fabio Estevam | e6b267c | 2013-01-16 10:58:41 -0200 | [diff] [blame] | 613 | fbi->enabled = false; |
Sascha Hauer | f909ef6 | 2009-01-15 15:21:00 +0100 | [diff] [blame] | 614 | |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 615 | writel(0, fbi->regs + LCDC_RMCR); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | static int imxfb_blank(int blank, struct fb_info *info) |
| 619 | { |
| 620 | struct imxfb_info *fbi = info->par; |
| 621 | |
| 622 | pr_debug("imxfb_blank: blank=%d\n", blank); |
| 623 | |
| 624 | switch (blank) { |
| 625 | case FB_BLANK_POWERDOWN: |
| 626 | case FB_BLANK_VSYNC_SUSPEND: |
| 627 | case FB_BLANK_HSYNC_SUSPEND: |
| 628 | case FB_BLANK_NORMAL: |
| 629 | imxfb_disable_controller(fbi); |
| 630 | break; |
| 631 | |
| 632 | case FB_BLANK_UNBLANK: |
| 633 | imxfb_enable_controller(fbi); |
| 634 | break; |
| 635 | } |
| 636 | return 0; |
| 637 | } |
| 638 | |
| 639 | static struct fb_ops imxfb_ops = { |
| 640 | .owner = THIS_MODULE, |
| 641 | .fb_check_var = imxfb_check_var, |
| 642 | .fb_set_par = imxfb_set_par, |
| 643 | .fb_setcolreg = imxfb_setcolreg, |
| 644 | .fb_fillrect = cfb_fillrect, |
| 645 | .fb_copyarea = cfb_copyarea, |
| 646 | .fb_imageblit = cfb_imageblit, |
| 647 | .fb_blank = imxfb_blank, |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 648 | }; |
| 649 | |
| 650 | /* |
| 651 | * imxfb_activate_var(): |
| 652 | * Configures LCD Controller based on entries in var parameter. Settings are |
| 653 | * only written to the controller if changes were made. |
| 654 | */ |
| 655 | static int imxfb_activate_var(struct fb_var_screeninfo *var, struct fb_info *info) |
| 656 | { |
| 657 | struct imxfb_info *fbi = info->par; |
Shawn Guo | e69dc9a | 2012-09-16 19:59:53 +0800 | [diff] [blame] | 658 | u32 ymax_mask = is_imx1_fb(fbi) ? YMAX_MASK_IMX1 : YMAX_MASK_IMX21; |
Sascha Hauer | f909ef6 | 2009-01-15 15:21:00 +0100 | [diff] [blame] | 659 | |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 660 | pr_debug("var: xres=%d hslen=%d lm=%d rm=%d\n", |
| 661 | var->xres, var->hsync_len, |
| 662 | var->left_margin, var->right_margin); |
| 663 | pr_debug("var: yres=%d vslen=%d um=%d bm=%d\n", |
| 664 | var->yres, var->vsync_len, |
| 665 | var->upper_margin, var->lower_margin); |
| 666 | |
| 667 | #if DEBUG_VAR |
| 668 | if (var->xres < 16 || var->xres > 1024) |
| 669 | printk(KERN_ERR "%s: invalid xres %d\n", |
| 670 | info->fix.id, var->xres); |
| 671 | if (var->hsync_len < 1 || var->hsync_len > 64) |
| 672 | printk(KERN_ERR "%s: invalid hsync_len %d\n", |
| 673 | info->fix.id, var->hsync_len); |
| 674 | if (var->left_margin > 255) |
| 675 | printk(KERN_ERR "%s: invalid left_margin %d\n", |
| 676 | info->fix.id, var->left_margin); |
| 677 | if (var->right_margin > 255) |
| 678 | printk(KERN_ERR "%s: invalid right_margin %d\n", |
| 679 | info->fix.id, var->right_margin); |
Shawn Guo | e69dc9a | 2012-09-16 19:59:53 +0800 | [diff] [blame] | 680 | if (var->yres < 1 || var->yres > ymax_mask) |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 681 | printk(KERN_ERR "%s: invalid yres %d\n", |
| 682 | info->fix.id, var->yres); |
| 683 | if (var->vsync_len > 100) |
| 684 | printk(KERN_ERR "%s: invalid vsync_len %d\n", |
| 685 | info->fix.id, var->vsync_len); |
| 686 | if (var->upper_margin > 63) |
| 687 | printk(KERN_ERR "%s: invalid upper_margin %d\n", |
| 688 | info->fix.id, var->upper_margin); |
| 689 | if (var->lower_margin > 255) |
| 690 | printk(KERN_ERR "%s: invalid lower_margin %d\n", |
| 691 | info->fix.id, var->lower_margin); |
| 692 | #endif |
| 693 | |
Sascha Hauer | 343684f | 2009-03-19 08:25:41 +0100 | [diff] [blame] | 694 | /* physical screen start address */ |
| 695 | writel(VPW_VPW(var->xres * var->bits_per_pixel / 8 / 4), |
| 696 | fbi->regs + LCDC_VPW); |
| 697 | |
Sascha Hauer | 7e8549b | 2009-02-14 16:29:38 +0100 | [diff] [blame] | 698 | writel(HCR_H_WIDTH(var->hsync_len - 1) | |
| 699 | HCR_H_WAIT_1(var->right_margin - 1) | |
| 700 | HCR_H_WAIT_2(var->left_margin - 3), |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 701 | fbi->regs + LCDC_HCR); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 702 | |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 703 | writel(VCR_V_WIDTH(var->vsync_len) | |
Sascha Hauer | d6ed575 | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 704 | VCR_V_WAIT_1(var->lower_margin) | |
| 705 | VCR_V_WAIT_2(var->upper_margin), |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 706 | fbi->regs + LCDC_VCR); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 707 | |
Shawn Guo | e69dc9a | 2012-09-16 19:59:53 +0800 | [diff] [blame] | 708 | writel(SIZE_XMAX(var->xres) | (var->yres & ymax_mask), |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 709 | fbi->regs + LCDC_SIZE); |
Sascha Hauer | f909ef6 | 2009-01-15 15:21:00 +0100 | [diff] [blame] | 710 | |
Sascha Hauer | 343684f | 2009-03-19 08:25:41 +0100 | [diff] [blame] | 711 | writel(fbi->pcr, fbi->regs + LCDC_PCR); |
Eric Bénard | 81ef806 | 2010-08-02 08:39:55 +0100 | [diff] [blame] | 712 | #ifndef PWMR_BACKLIGHT_AVAILABLE |
Markus Pargmann | 1b6c793 | 2013-05-26 12:35:38 +0200 | [diff] [blame] | 713 | if (fbi->pwmr) |
| 714 | writel(fbi->pwmr, fbi->regs + LCDC_PWMR); |
Eric Bénard | 81ef806 | 2010-08-02 08:39:55 +0100 | [diff] [blame] | 715 | #endif |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 716 | writel(fbi->lscr1, fbi->regs + LCDC_LSCR1); |
Markus Pargmann | 1b6c793 | 2013-05-26 12:35:38 +0200 | [diff] [blame] | 717 | |
| 718 | /* dmacr = 0 is no valid value, as we need DMA control marks. */ |
| 719 | if (fbi->dmacr) |
| 720 | writel(fbi->dmacr, fbi->regs + LCDC_DMACR); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 721 | |
| 722 | return 0; |
| 723 | } |
| 724 | |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 725 | #ifdef CONFIG_PM |
| 726 | /* |
| 727 | * Power management hooks. Note that we won't be called from IRQ context, |
| 728 | * unlike the blank functions above, so we may sleep. |
| 729 | */ |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 730 | static int imxfb_suspend(struct platform_device *dev, pm_message_t state) |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 731 | { |
Uwe Kleine-König | 1ec5620 | 2010-02-02 13:44:10 -0800 | [diff] [blame] | 732 | struct fb_info *info = platform_get_drvdata(dev); |
| 733 | struct imxfb_info *fbi = info->par; |
Sascha Hauer | 66c8719 | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 734 | |
| 735 | pr_debug("%s\n", __func__); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 736 | |
Russell King | 9480e30 | 2005-10-28 09:52:56 -0700 | [diff] [blame] | 737 | imxfb_disable_controller(fbi); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 738 | return 0; |
| 739 | } |
| 740 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 741 | static int imxfb_resume(struct platform_device *dev) |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 742 | { |
Uwe Kleine-König | 1ec5620 | 2010-02-02 13:44:10 -0800 | [diff] [blame] | 743 | struct fb_info *info = platform_get_drvdata(dev); |
| 744 | struct imxfb_info *fbi = info->par; |
Sascha Hauer | 66c8719 | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 745 | |
| 746 | pr_debug("%s\n", __func__); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 747 | |
Russell King | 9480e30 | 2005-10-28 09:52:56 -0700 | [diff] [blame] | 748 | imxfb_enable_controller(fbi); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 749 | return 0; |
| 750 | } |
| 751 | #else |
| 752 | #define imxfb_suspend NULL |
| 753 | #define imxfb_resume NULL |
| 754 | #endif |
| 755 | |
Markus Pargmann | 1b6c793 | 2013-05-26 12:35:38 +0200 | [diff] [blame] | 756 | static int imxfb_init_fbinfo(struct platform_device *pdev) |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 757 | { |
Sascha Hauer | 2788927 | 2008-12-16 11:44:09 +0100 | [diff] [blame] | 758 | struct imx_fb_platform_data *pdata = pdev->dev.platform_data; |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 759 | struct fb_info *info = dev_get_drvdata(&pdev->dev); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 760 | struct imxfb_info *fbi = info->par; |
Markus Pargmann | 1b6c793 | 2013-05-26 12:35:38 +0200 | [diff] [blame] | 761 | struct device_node *np; |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 762 | |
Harvey Harrison | 5ae1217 | 2008-04-28 02:15:47 -0700 | [diff] [blame] | 763 | pr_debug("%s\n",__func__); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 764 | |
Sascha Hauer | 66c8719 | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 765 | info->pseudo_palette = kmalloc(sizeof(u32) * 16, GFP_KERNEL); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 766 | if (!info->pseudo_palette) |
| 767 | return -ENOMEM; |
| 768 | |
| 769 | memset(fbi, 0, sizeof(struct imxfb_info)); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 770 | |
Gwenhael Goavec-Merou | afc1030 | 2013-01-13 16:56:43 +0100 | [diff] [blame] | 771 | fbi->devtype = pdev->id_entry->driver_data; |
| 772 | |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 773 | strlcpy(info->fix.id, IMX_NAME, sizeof(info->fix.id)); |
| 774 | |
Sascha Hauer | 66c8719 | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 775 | info->fix.type = FB_TYPE_PACKED_PIXELS; |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 776 | info->fix.type_aux = 0; |
| 777 | info->fix.xpanstep = 0; |
| 778 | info->fix.ypanstep = 0; |
| 779 | info->fix.ywrapstep = 0; |
Sascha Hauer | 66c8719 | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 780 | info->fix.accel = FB_ACCEL_NONE; |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 781 | |
| 782 | info->var.nonstd = 0; |
| 783 | info->var.activate = FB_ACTIVATE_NOW; |
| 784 | info->var.height = -1; |
| 785 | info->var.width = -1; |
| 786 | info->var.accel_flags = 0; |
Sascha Hauer | 66c8719 | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 787 | info->var.vmode = FB_VMODE_NONINTERLACED; |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 788 | |
| 789 | info->fbops = &imxfb_ops; |
Sascha Hauer | 66c8719 | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 790 | info->flags = FBINFO_FLAG_DEFAULT | |
| 791 | FBINFO_READS_FAST; |
Markus Pargmann | 1b6c793 | 2013-05-26 12:35:38 +0200 | [diff] [blame] | 792 | if (pdata) { |
| 793 | info->var.grayscale = pdata->cmap_greyscale; |
| 794 | fbi->cmap_inverse = pdata->cmap_inverse; |
| 795 | fbi->cmap_static = pdata->cmap_static; |
| 796 | fbi->lscr1 = pdata->lscr1; |
| 797 | fbi->dmacr = pdata->dmacr; |
| 798 | fbi->pwmr = pdata->pwmr; |
| 799 | fbi->lcd_power = pdata->lcd_power; |
| 800 | fbi->backlight_power = pdata->backlight_power; |
| 801 | } else { |
| 802 | np = pdev->dev.of_node; |
| 803 | info->var.grayscale = of_property_read_bool(np, |
| 804 | "cmap-greyscale"); |
| 805 | fbi->cmap_inverse = of_property_read_bool(np, "cmap-inverse"); |
| 806 | fbi->cmap_static = of_property_read_bool(np, "cmap-static"); |
Sascha Hauer | 343684f | 2009-03-19 08:25:41 +0100 | [diff] [blame] | 807 | |
Markus Pargmann | 1b6c793 | 2013-05-26 12:35:38 +0200 | [diff] [blame] | 808 | fbi->lscr1 = IMXFB_LSCR1_DEFAULT; |
| 809 | of_property_read_u32(np, "fsl,lscr1", &fbi->lscr1); |
| 810 | |
| 811 | of_property_read_u32(np, "fsl,dmacr", &fbi->dmacr); |
| 812 | |
| 813 | /* These two function pointers could be used by some specific |
| 814 | * platforms. */ |
| 815 | fbi->lcd_power = NULL; |
| 816 | fbi->backlight_power = NULL; |
| 817 | } |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 818 | |
| 819 | return 0; |
| 820 | } |
| 821 | |
Markus Pargmann | 1b6c793 | 2013-05-26 12:35:38 +0200 | [diff] [blame] | 822 | static int imxfb_of_read_mode(struct device *dev, struct device_node *np, |
| 823 | struct imx_fb_videomode *imxfb_mode) |
| 824 | { |
| 825 | int ret; |
| 826 | struct fb_videomode *of_mode = &imxfb_mode->mode; |
| 827 | u32 bpp; |
| 828 | u32 pcr; |
| 829 | |
| 830 | ret = of_property_read_string(np, "model", &of_mode->name); |
| 831 | if (ret) |
| 832 | of_mode->name = NULL; |
| 833 | |
| 834 | ret = of_get_fb_videomode(np, of_mode, OF_USE_NATIVE_MODE); |
| 835 | if (ret) { |
| 836 | dev_err(dev, "Failed to get videomode from DT\n"); |
| 837 | return ret; |
| 838 | } |
| 839 | |
| 840 | ret = of_property_read_u32(np, "bits-per-pixel", &bpp); |
| 841 | ret |= of_property_read_u32(np, "fsl,pcr", &pcr); |
| 842 | |
| 843 | if (ret) { |
| 844 | dev_err(dev, "Failed to read bpp and pcr from DT\n"); |
| 845 | return -EINVAL; |
| 846 | } |
| 847 | |
| 848 | if (bpp < 1 || bpp > 255) { |
| 849 | dev_err(dev, "Bits per pixel have to be between 1 and 255\n"); |
| 850 | return -EINVAL; |
| 851 | } |
| 852 | |
| 853 | imxfb_mode->bpp = bpp; |
| 854 | imxfb_mode->pcr = pcr; |
| 855 | |
| 856 | return 0; |
| 857 | } |
| 858 | |
| 859 | static int imxfb_probe(struct platform_device *pdev) |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 860 | { |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 861 | struct imxfb_info *fbi; |
| 862 | struct fb_info *info; |
Sascha Hauer | 2788927 | 2008-12-16 11:44:09 +0100 | [diff] [blame] | 863 | struct imx_fb_platform_data *pdata; |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 864 | struct resource *res; |
Markus Pargmann | 1b6c793 | 2013-05-26 12:35:38 +0200 | [diff] [blame] | 865 | struct imx_fb_videomode *m; |
| 866 | const struct of_device_id *of_id; |
Sascha Hauer | 343684f | 2009-03-19 08:25:41 +0100 | [diff] [blame] | 867 | int ret, i; |
Markus Pargmann | 1b6c793 | 2013-05-26 12:35:38 +0200 | [diff] [blame] | 868 | int bytes_per_pixel; |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 869 | |
Sascha Hauer | d6b5150 | 2009-06-29 11:41:09 +0200 | [diff] [blame] | 870 | dev_info(&pdev->dev, "i.MX Framebuffer driver\n"); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 871 | |
Markus Pargmann | 1b6c793 | 2013-05-26 12:35:38 +0200 | [diff] [blame] | 872 | of_id = of_match_device(imxfb_of_dev_id, &pdev->dev); |
| 873 | if (of_id) |
| 874 | pdev->id_entry = of_id->data; |
| 875 | |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 876 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Sascha Hauer | 66c8719 | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 877 | if (!res) |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 878 | return -ENODEV; |
| 879 | |
Sascha Hauer | 2788927 | 2008-12-16 11:44:09 +0100 | [diff] [blame] | 880 | pdata = pdev->dev.platform_data; |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 881 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 882 | info = framebuffer_alloc(sizeof(struct imxfb_info), &pdev->dev); |
Sascha Hauer | 66c8719 | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 883 | if (!info) |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 884 | return -ENOMEM; |
| 885 | |
| 886 | fbi = info->par; |
| 887 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 888 | platform_set_drvdata(pdev, info); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 889 | |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 890 | ret = imxfb_init_fbinfo(pdev); |
Sascha Hauer | 66c8719 | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 891 | if (ret < 0) |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 892 | goto failed_init; |
| 893 | |
Markus Pargmann | 1b6c793 | 2013-05-26 12:35:38 +0200 | [diff] [blame] | 894 | if (pdata) { |
| 895 | if (!fb_mode) |
| 896 | fb_mode = pdata->mode[0].mode.name; |
| 897 | |
| 898 | fbi->mode = pdata->mode; |
| 899 | fbi->num_modes = pdata->num_modes; |
| 900 | } else { |
| 901 | struct device_node *display_np; |
| 902 | fb_mode = NULL; |
| 903 | |
| 904 | display_np = of_parse_phandle(pdev->dev.of_node, "display", 0); |
| 905 | if (!display_np) { |
| 906 | dev_err(&pdev->dev, "No display defined in devicetree\n"); |
| 907 | ret = -EINVAL; |
| 908 | goto failed_of_parse; |
| 909 | } |
| 910 | |
| 911 | /* |
| 912 | * imxfb does not support more modes, we choose only the native |
| 913 | * mode. |
| 914 | */ |
| 915 | fbi->num_modes = 1; |
| 916 | |
| 917 | fbi->mode = devm_kzalloc(&pdev->dev, |
| 918 | sizeof(struct imx_fb_videomode), GFP_KERNEL); |
| 919 | if (!fbi->mode) { |
| 920 | ret = -ENOMEM; |
| 921 | goto failed_of_parse; |
| 922 | } |
| 923 | |
| 924 | ret = imxfb_of_read_mode(&pdev->dev, display_np, fbi->mode); |
| 925 | if (ret) |
| 926 | goto failed_of_parse; |
| 927 | } |
| 928 | |
| 929 | /* Calculate maximum bytes used per pixel. In most cases this should |
| 930 | * be the same as m->bpp/8 */ |
| 931 | m = &fbi->mode[0]; |
| 932 | bytes_per_pixel = (m->bpp + 7) / 8; |
| 933 | for (i = 0; i < fbi->num_modes; i++, m++) |
| 934 | info->fix.smem_len = max_t(size_t, info->fix.smem_len, |
| 935 | m->mode.xres * m->mode.yres * bytes_per_pixel); |
| 936 | |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 937 | res = request_mem_region(res->start, resource_size(res), |
| 938 | DRIVER_NAME); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 939 | if (!res) { |
| 940 | ret = -EBUSY; |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 941 | goto failed_req; |
| 942 | } |
| 943 | |
Sascha Hauer | 13aaea0 | 2012-03-07 09:30:36 +0100 | [diff] [blame] | 944 | fbi->clk_ipg = devm_clk_get(&pdev->dev, "ipg"); |
| 945 | if (IS_ERR(fbi->clk_ipg)) { |
| 946 | ret = PTR_ERR(fbi->clk_ipg); |
| 947 | goto failed_getclock; |
| 948 | } |
| 949 | |
| 950 | fbi->clk_ahb = devm_clk_get(&pdev->dev, "ahb"); |
| 951 | if (IS_ERR(fbi->clk_ahb)) { |
| 952 | ret = PTR_ERR(fbi->clk_ahb); |
| 953 | goto failed_getclock; |
| 954 | } |
| 955 | |
| 956 | fbi->clk_per = devm_clk_get(&pdev->dev, "per"); |
| 957 | if (IS_ERR(fbi->clk_per)) { |
| 958 | ret = PTR_ERR(fbi->clk_per); |
Sascha Hauer | f909ef6 | 2009-01-15 15:21:00 +0100 | [diff] [blame] | 959 | goto failed_getclock; |
| 960 | } |
| 961 | |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 962 | fbi->regs = ioremap(res->start, resource_size(res)); |
| 963 | if (fbi->regs == NULL) { |
Sascha Hauer | d6b5150 | 2009-06-29 11:41:09 +0200 | [diff] [blame] | 964 | dev_err(&pdev->dev, "Cannot map frame buffer registers\n"); |
Peter Senna Tschudin | caf0a5c | 2012-09-18 14:07:56 +0200 | [diff] [blame] | 965 | ret = -ENOMEM; |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 966 | goto failed_ioremap; |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 967 | } |
| 968 | |
Markus Pargmann | 1b6c793 | 2013-05-26 12:35:38 +0200 | [diff] [blame] | 969 | /* Seems not being used by anyone, so no support for oftree */ |
| 970 | if (!pdata || !pdata->fixed_screen_cpu) { |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 971 | fbi->map_size = PAGE_ALIGN(info->fix.smem_len); |
| 972 | fbi->map_cpu = dma_alloc_writecombine(&pdev->dev, |
| 973 | fbi->map_size, &fbi->map_dma, GFP_KERNEL); |
| 974 | |
| 975 | if (!fbi->map_cpu) { |
Pavel Pisa | f99c892 | 2006-01-07 10:44:32 +0000 | [diff] [blame] | 976 | dev_err(&pdev->dev, "Failed to allocate video RAM: %d\n", ret); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 977 | ret = -ENOMEM; |
| 978 | goto failed_map; |
| 979 | } |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 980 | |
| 981 | info->screen_base = fbi->map_cpu; |
| 982 | fbi->screen_cpu = fbi->map_cpu; |
| 983 | fbi->screen_dma = fbi->map_dma; |
| 984 | info->fix.smem_start = fbi->screen_dma; |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 985 | } else { |
| 986 | /* Fixed framebuffer mapping enables location of the screen in eSRAM */ |
Sascha Hauer | 2788927 | 2008-12-16 11:44:09 +0100 | [diff] [blame] | 987 | fbi->map_cpu = pdata->fixed_screen_cpu; |
| 988 | fbi->map_dma = pdata->fixed_screen_dma; |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 989 | info->screen_base = fbi->map_cpu; |
| 990 | fbi->screen_cpu = fbi->map_cpu; |
| 991 | fbi->screen_dma = fbi->map_dma; |
| 992 | info->fix.smem_start = fbi->screen_dma; |
| 993 | } |
| 994 | |
Markus Pargmann | 1b6c793 | 2013-05-26 12:35:38 +0200 | [diff] [blame] | 995 | if (pdata && pdata->init) { |
Sascha Hauer | c0b90a3 | 2009-01-15 15:37:22 +0100 | [diff] [blame] | 996 | ret = pdata->init(fbi->pdev); |
| 997 | if (ret) |
| 998 | goto failed_platform_init; |
| 999 | } |
| 1000 | |
Sascha Hauer | 343684f | 2009-03-19 08:25:41 +0100 | [diff] [blame] | 1001 | |
| 1002 | INIT_LIST_HEAD(&info->modelist); |
Markus Pargmann | 1b6c793 | 2013-05-26 12:35:38 +0200 | [diff] [blame] | 1003 | for (i = 0; i < fbi->num_modes; i++) |
| 1004 | fb_add_videomode(&fbi->mode[i].mode, &info->modelist); |
Sascha Hauer | 343684f | 2009-03-19 08:25:41 +0100 | [diff] [blame] | 1005 | |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 1006 | /* |
| 1007 | * This makes sure that our colour bitfield |
| 1008 | * descriptors are correctly initialised. |
| 1009 | */ |
| 1010 | imxfb_check_var(&info->var, info); |
| 1011 | |
Sascha Hauer | 66c8719 | 2008-12-16 11:44:08 +0100 | [diff] [blame] | 1012 | 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] | 1013 | if (ret < 0) |
| 1014 | goto failed_cmap; |
| 1015 | |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 1016 | imxfb_set_par(info); |
| 1017 | ret = register_framebuffer(info); |
| 1018 | if (ret < 0) { |
Pavel Pisa | f99c892 | 2006-01-07 10:44:32 +0000 | [diff] [blame] | 1019 | dev_err(&pdev->dev, "failed to register framebuffer\n"); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 1020 | goto failed_register; |
| 1021 | } |
| 1022 | |
| 1023 | imxfb_enable_controller(fbi); |
Eric Bénard | 7a2bb23 | 2010-07-16 15:09:07 +0200 | [diff] [blame] | 1024 | fbi->pdev = pdev; |
Eric Bénard | 81ef806 | 2010-08-02 08:39:55 +0100 | [diff] [blame] | 1025 | #ifdef PWMR_BACKLIGHT_AVAILABLE |
Eric Bénard | 7a2bb23 | 2010-07-16 15:09:07 +0200 | [diff] [blame] | 1026 | imxfb_init_backlight(fbi); |
Eric Bénard | 81ef806 | 2010-08-02 08:39:55 +0100 | [diff] [blame] | 1027 | #endif |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 1028 | |
| 1029 | return 0; |
| 1030 | |
| 1031 | failed_register: |
| 1032 | fb_dealloc_cmap(&info->cmap); |
| 1033 | failed_cmap: |
Markus Pargmann | 1b6c793 | 2013-05-26 12:35:38 +0200 | [diff] [blame] | 1034 | if (pdata && pdata->exit) |
Sascha Hauer | c0b90a3 | 2009-01-15 15:37:22 +0100 | [diff] [blame] | 1035 | pdata->exit(fbi->pdev); |
| 1036 | failed_platform_init: |
Markus Pargmann | 1b6c793 | 2013-05-26 12:35:38 +0200 | [diff] [blame] | 1037 | if (pdata && !pdata->fixed_screen_cpu) |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1038 | dma_free_writecombine(&pdev->dev,fbi->map_size,fbi->map_cpu, |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 1039 | fbi->map_dma); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 1040 | failed_map: |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 1041 | iounmap(fbi->regs); |
| 1042 | failed_ioremap: |
Julia Lawall | 609d3bb | 2011-06-01 17:10:11 +0000 | [diff] [blame] | 1043 | failed_getclock: |
Sascha Hauer | d6b5150 | 2009-06-29 11:41:09 +0200 | [diff] [blame] | 1044 | release_mem_region(res->start, resource_size(res)); |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 1045 | failed_req: |
Markus Pargmann | 1b6c793 | 2013-05-26 12:35:38 +0200 | [diff] [blame] | 1046 | failed_of_parse: |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 1047 | kfree(info->pseudo_palette); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 1048 | failed_init: |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 1049 | framebuffer_release(info); |
| 1050 | return ret; |
| 1051 | } |
| 1052 | |
Greg Kroah-Hartman | 48c68c4 | 2012-12-21 13:07:39 -0800 | [diff] [blame] | 1053 | static int imxfb_remove(struct platform_device *pdev) |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 1054 | { |
Sascha Hauer | c0b90a3 | 2009-01-15 15:37:22 +0100 | [diff] [blame] | 1055 | struct imx_fb_platform_data *pdata; |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1056 | struct fb_info *info = platform_get_drvdata(pdev); |
Sascha Hauer | 772a9e6 | 2005-07-17 20:15:36 +0100 | [diff] [blame] | 1057 | struct imxfb_info *fbi = info->par; |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 1058 | struct resource *res; |
| 1059 | |
| 1060 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1061 | |
Sascha Hauer | 772a9e6 | 2005-07-17 20:15:36 +0100 | [diff] [blame] | 1062 | imxfb_disable_controller(fbi); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 1063 | |
Eric Bénard | 81ef806 | 2010-08-02 08:39:55 +0100 | [diff] [blame] | 1064 | #ifdef PWMR_BACKLIGHT_AVAILABLE |
Eric Bénard | 7a2bb23 | 2010-07-16 15:09:07 +0200 | [diff] [blame] | 1065 | imxfb_exit_backlight(fbi); |
Eric Bénard | 81ef806 | 2010-08-02 08:39:55 +0100 | [diff] [blame] | 1066 | #endif |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 1067 | unregister_framebuffer(info); |
| 1068 | |
Sascha Hauer | c0b90a3 | 2009-01-15 15:37:22 +0100 | [diff] [blame] | 1069 | pdata = pdev->dev.platform_data; |
Markus Pargmann | 1b6c793 | 2013-05-26 12:35:38 +0200 | [diff] [blame] | 1070 | if (pdata && pdata->exit) |
Sascha Hauer | c0b90a3 | 2009-01-15 15:37:22 +0100 | [diff] [blame] | 1071 | pdata->exit(fbi->pdev); |
| 1072 | |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 1073 | fb_dealloc_cmap(&info->cmap); |
| 1074 | kfree(info->pseudo_palette); |
| 1075 | framebuffer_release(info); |
| 1076 | |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 1077 | iounmap(fbi->regs); |
Sascha Hauer | d6b5150 | 2009-06-29 11:41:09 +0200 | [diff] [blame] | 1078 | release_mem_region(res->start, resource_size(res)); |
Sascha Hauer | f909ef6 | 2009-01-15 15:21:00 +0100 | [diff] [blame] | 1079 | |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 1080 | return 0; |
| 1081 | } |
| 1082 | |
Sachin Kamat | 486dd6d | 2013-05-10 17:25:08 +0530 | [diff] [blame] | 1083 | static void imxfb_shutdown(struct platform_device *dev) |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 1084 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1085 | struct fb_info *info = platform_get_drvdata(dev); |
Sascha Hauer | 772a9e6 | 2005-07-17 20:15:36 +0100 | [diff] [blame] | 1086 | struct imxfb_info *fbi = info->par; |
| 1087 | imxfb_disable_controller(fbi); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 1088 | } |
| 1089 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1090 | static struct platform_driver imxfb_driver = { |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 1091 | .suspend = imxfb_suspend, |
| 1092 | .resume = imxfb_resume, |
Greg Kroah-Hartman | 48c68c4 | 2012-12-21 13:07:39 -0800 | [diff] [blame] | 1093 | .remove = imxfb_remove, |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 1094 | .shutdown = imxfb_shutdown, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1095 | .driver = { |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 1096 | .name = DRIVER_NAME, |
Markus Pargmann | 1b6c793 | 2013-05-26 12:35:38 +0200 | [diff] [blame] | 1097 | .of_match_table = imxfb_of_dev_id, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1098 | }, |
Shawn Guo | e69dc9a | 2012-09-16 19:59:53 +0800 | [diff] [blame] | 1099 | .id_table = imxfb_devtype, |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 1100 | }; |
| 1101 | |
Sascha Hauer | 343684f | 2009-03-19 08:25:41 +0100 | [diff] [blame] | 1102 | static int imxfb_setup(void) |
| 1103 | { |
| 1104 | #ifndef MODULE |
| 1105 | char *opt, *options = NULL; |
| 1106 | |
| 1107 | if (fb_get_options("imxfb", &options)) |
| 1108 | return -ENODEV; |
| 1109 | |
| 1110 | if (!options || !*options) |
| 1111 | return 0; |
| 1112 | |
| 1113 | while ((opt = strsep(&options, ",")) != NULL) { |
| 1114 | if (!*opt) |
| 1115 | continue; |
| 1116 | else |
| 1117 | fb_mode = opt; |
| 1118 | } |
| 1119 | #endif |
| 1120 | return 0; |
| 1121 | } |
| 1122 | |
Sachin Kamat | 486dd6d | 2013-05-10 17:25:08 +0530 | [diff] [blame] | 1123 | static int __init imxfb_init(void) |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 1124 | { |
Sascha Hauer | 343684f | 2009-03-19 08:25:41 +0100 | [diff] [blame] | 1125 | int ret = imxfb_setup(); |
| 1126 | |
| 1127 | if (ret < 0) |
| 1128 | return ret; |
| 1129 | |
Juergen Beisert | 72330b0 | 2008-12-16 11:44:07 +0100 | [diff] [blame] | 1130 | return platform_driver_probe(&imxfb_driver, imxfb_probe); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 1131 | } |
| 1132 | |
| 1133 | static void __exit imxfb_cleanup(void) |
| 1134 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1135 | platform_driver_unregister(&imxfb_driver); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 1136 | } |
| 1137 | |
| 1138 | module_init(imxfb_init); |
| 1139 | module_exit(imxfb_cleanup); |
| 1140 | |
Fabio Estevam | e3d5fb7 | 2011-01-10 09:47:41 -0200 | [diff] [blame] | 1141 | MODULE_DESCRIPTION("Freescale i.MX framebuffer driver"); |
Sascha Hauer | 7c2f891c | 2005-05-01 08:59:24 -0700 | [diff] [blame] | 1142 | MODULE_AUTHOR("Sascha Hauer, Pengutronix"); |
| 1143 | MODULE_LICENSE("GPL"); |