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