Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/video/amba-clcd.c |
| 3 | * |
| 4 | * Copyright (C) 2001 ARM Limited, by David A Rusling |
| 5 | * Updated to 2.5, Deep Blue Solutions Ltd. |
| 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 |
| 9 | * for more details. |
| 10 | * |
| 11 | * ARM PrimeCell PL110 Color LCD Controller |
| 12 | */ |
Russell King | e0a8ba2 | 2013-06-27 10:29:32 +0100 | [diff] [blame] | 13 | #include <linux/dma-mapping.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/module.h> |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/errno.h> |
| 17 | #include <linux/string.h> |
| 18 | #include <linux/slab.h> |
| 19 | #include <linux/delay.h> |
| 20 | #include <linux/mm.h> |
| 21 | #include <linux/fb.h> |
| 22 | #include <linux/init.h> |
| 23 | #include <linux/ioport.h> |
| 24 | #include <linux/list.h> |
Russell King | a62c80e | 2006-01-07 13:52:45 +0000 | [diff] [blame] | 25 | #include <linux/amba/bus.h> |
| 26 | #include <linux/amba/clcd.h> |
Russell King | f8ce254 | 2006-01-07 16:15:52 +0000 | [diff] [blame] | 27 | #include <linux/clk.h> |
Russell King | 934848d | 2009-01-08 09:58:51 +0000 | [diff] [blame] | 28 | #include <linux/hardirq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
Russell King | c6b8fda | 2005-10-28 14:05:16 +0100 | [diff] [blame] | 30 | #include <asm/sizes.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #define to_clcd(info) container_of(info, struct clcd_fb, fb) |
| 33 | |
| 34 | /* This is limited to 16 characters when displayed by X startup */ |
| 35 | static const char *clcd_name = "CLCD FB"; |
| 36 | |
| 37 | /* |
| 38 | * Unfortunately, the enable/disable functions may be called either from |
| 39 | * process or IRQ context, and we _need_ to delay. This is _not_ good. |
| 40 | */ |
| 41 | static inline void clcdfb_sleep(unsigned int ms) |
| 42 | { |
| 43 | if (in_atomic()) { |
| 44 | mdelay(ms); |
| 45 | } else { |
| 46 | msleep(ms); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | static inline void clcdfb_set_start(struct clcd_fb *fb) |
| 51 | { |
| 52 | unsigned long ustart = fb->fb.fix.smem_start; |
| 53 | unsigned long lstart; |
| 54 | |
| 55 | ustart += fb->fb.var.yoffset * fb->fb.fix.line_length; |
| 56 | lstart = ustart + fb->fb.var.yres * fb->fb.fix.line_length / 2; |
| 57 | |
| 58 | writel(ustart, fb->regs + CLCD_UBAS); |
| 59 | writel(lstart, fb->regs + CLCD_LBAS); |
| 60 | } |
| 61 | |
| 62 | static void clcdfb_disable(struct clcd_fb *fb) |
| 63 | { |
| 64 | u32 val; |
| 65 | |
| 66 | if (fb->board->disable) |
| 67 | fb->board->disable(fb); |
| 68 | |
Russell King | 3f17522 | 2010-02-12 14:32:01 +0000 | [diff] [blame] | 69 | val = readl(fb->regs + fb->off_cntl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | if (val & CNTL_LCDPWR) { |
| 71 | val &= ~CNTL_LCDPWR; |
Russell King | 3f17522 | 2010-02-12 14:32:01 +0000 | [diff] [blame] | 72 | writel(val, fb->regs + fb->off_cntl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | |
| 74 | clcdfb_sleep(20); |
| 75 | } |
| 76 | if (val & CNTL_LCDEN) { |
| 77 | val &= ~CNTL_LCDEN; |
Russell King | 3f17522 | 2010-02-12 14:32:01 +0000 | [diff] [blame] | 78 | writel(val, fb->regs + fb->off_cntl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | /* |
| 82 | * Disable CLCD clock source. |
| 83 | */ |
Russell King | 99c796d | 2010-08-17 22:13:22 +0100 | [diff] [blame] | 84 | if (fb->clk_enabled) { |
| 85 | fb->clk_enabled = false; |
| 86 | clk_disable(fb->clk); |
| 87 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | static void clcdfb_enable(struct clcd_fb *fb, u32 cntl) |
| 91 | { |
| 92 | /* |
| 93 | * Enable the CLCD clock source. |
| 94 | */ |
Russell King | 99c796d | 2010-08-17 22:13:22 +0100 | [diff] [blame] | 95 | if (!fb->clk_enabled) { |
| 96 | fb->clk_enabled = true; |
| 97 | clk_enable(fb->clk); |
| 98 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | |
| 100 | /* |
| 101 | * Bring up by first enabling.. |
| 102 | */ |
| 103 | cntl |= CNTL_LCDEN; |
Russell King | 3f17522 | 2010-02-12 14:32:01 +0000 | [diff] [blame] | 104 | writel(cntl, fb->regs + fb->off_cntl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
| 106 | clcdfb_sleep(20); |
| 107 | |
| 108 | /* |
| 109 | * and now apply power. |
| 110 | */ |
| 111 | cntl |= CNTL_LCDPWR; |
Russell King | 3f17522 | 2010-02-12 14:32:01 +0000 | [diff] [blame] | 112 | writel(cntl, fb->regs + fb->off_cntl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | |
| 114 | /* |
| 115 | * finally, enable the interface. |
| 116 | */ |
| 117 | if (fb->board->enable) |
| 118 | fb->board->enable(fb); |
| 119 | } |
| 120 | |
| 121 | static int |
| 122 | clcdfb_set_bitfields(struct clcd_fb *fb, struct fb_var_screeninfo *var) |
| 123 | { |
Russell King | 7b4e9ce | 2011-01-21 14:03:28 +0000 | [diff] [blame] | 124 | u32 caps; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | int ret = 0; |
| 126 | |
Russell King | 7b4e9ce | 2011-01-21 14:03:28 +0000 | [diff] [blame] | 127 | if (fb->panel->caps && fb->board->caps) |
| 128 | caps = fb->panel->caps & fb->board->caps; |
| 129 | else { |
| 130 | /* Old way of specifying what can be used */ |
| 131 | caps = fb->panel->cntl & CNTL_BGR ? |
| 132 | CLCD_CAP_BGR : CLCD_CAP_RGB; |
| 133 | /* But mask out 444 modes as they weren't supported */ |
| 134 | caps &= ~CLCD_CAP_444; |
| 135 | } |
| 136 | |
| 137 | /* Only TFT panels can do RGB888/BGR888 */ |
| 138 | if (!(fb->panel->cntl & CNTL_LCDTFT)) |
| 139 | caps &= ~CLCD_CAP_888; |
| 140 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | memset(&var->transp, 0, sizeof(var->transp)); |
Russell King | c43e6f0 | 2006-01-26 14:12:06 +0000 | [diff] [blame] | 142 | |
| 143 | var->red.msb_right = 0; |
| 144 | var->green.msb_right = 0; |
| 145 | var->blue.msb_right = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | |
| 147 | switch (var->bits_per_pixel) { |
| 148 | case 1: |
| 149 | case 2: |
| 150 | case 4: |
| 151 | case 8: |
Russell King | 7b4e9ce | 2011-01-21 14:03:28 +0000 | [diff] [blame] | 152 | /* If we can't do 5551, reject */ |
| 153 | caps &= CLCD_CAP_5551; |
| 154 | if (!caps) { |
| 155 | ret = -EINVAL; |
| 156 | break; |
| 157 | } |
| 158 | |
Russell King | c4d12b9 | 2005-04-28 10:38:19 +0100 | [diff] [blame] | 159 | var->red.length = var->bits_per_pixel; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | var->red.offset = 0; |
Russell King | c4d12b9 | 2005-04-28 10:38:19 +0100 | [diff] [blame] | 161 | var->green.length = var->bits_per_pixel; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | var->green.offset = 0; |
Russell King | c4d12b9 | 2005-04-28 10:38:19 +0100 | [diff] [blame] | 163 | var->blue.length = var->bits_per_pixel; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | var->blue.offset = 0; |
| 165 | break; |
Russell King | 7b4e9ce | 2011-01-21 14:03:28 +0000 | [diff] [blame] | 166 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | case 16: |
Russell King | 7b4e9ce | 2011-01-21 14:03:28 +0000 | [diff] [blame] | 168 | /* If we can't do 444, 5551 or 565, reject */ |
| 169 | if (!(caps & (CLCD_CAP_444 | CLCD_CAP_5551 | CLCD_CAP_565))) { |
| 170 | ret = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | break; |
| 172 | } |
Russell King | 7b4e9ce | 2011-01-21 14:03:28 +0000 | [diff] [blame] | 173 | |
| 174 | /* |
| 175 | * Green length can be 4, 5 or 6 depending whether |
| 176 | * we're operating in 444, 5551 or 565 mode. |
| 177 | */ |
| 178 | if (var->green.length == 4 && caps & CLCD_CAP_444) |
| 179 | caps &= CLCD_CAP_444; |
| 180 | if (var->green.length == 5 && caps & CLCD_CAP_5551) |
| 181 | caps &= CLCD_CAP_5551; |
| 182 | else if (var->green.length == 6 && caps & CLCD_CAP_565) |
| 183 | caps &= CLCD_CAP_565; |
| 184 | else { |
| 185 | /* |
| 186 | * PL110 officially only supports RGB555, |
| 187 | * but may be wired up to allow RGB565. |
| 188 | */ |
| 189 | if (caps & CLCD_CAP_565) { |
| 190 | var->green.length = 6; |
| 191 | caps &= CLCD_CAP_565; |
| 192 | } else if (caps & CLCD_CAP_5551) { |
| 193 | var->green.length = 5; |
| 194 | caps &= CLCD_CAP_5551; |
| 195 | } else { |
| 196 | var->green.length = 4; |
| 197 | caps &= CLCD_CAP_444; |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | if (var->green.length >= 5) { |
| 202 | var->red.length = 5; |
| 203 | var->blue.length = 5; |
| 204 | } else { |
| 205 | var->red.length = 4; |
| 206 | var->blue.length = 4; |
| 207 | } |
| 208 | break; |
| 209 | case 32: |
| 210 | /* If we can't do 888, reject */ |
| 211 | caps &= CLCD_CAP_888; |
| 212 | if (!caps) { |
| 213 | ret = -EINVAL; |
| 214 | break; |
| 215 | } |
| 216 | |
| 217 | var->red.length = 8; |
| 218 | var->green.length = 8; |
| 219 | var->blue.length = 8; |
| 220 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | default: |
| 222 | ret = -EINVAL; |
| 223 | break; |
| 224 | } |
| 225 | |
Russell King | c43e6f0 | 2006-01-26 14:12:06 +0000 | [diff] [blame] | 226 | /* |
| 227 | * >= 16bpp displays have separate colour component bitfields |
| 228 | * encoded in the pixel data. Calculate their position from |
| 229 | * the bitfield length defined above. |
| 230 | */ |
| 231 | if (ret == 0 && var->bits_per_pixel >= 16) { |
Russell King | 7b4e9ce | 2011-01-21 14:03:28 +0000 | [diff] [blame] | 232 | bool bgr, rgb; |
| 233 | |
| 234 | bgr = caps & CLCD_CAP_BGR && var->blue.offset == 0; |
| 235 | rgb = caps & CLCD_CAP_RGB && var->red.offset == 0; |
| 236 | |
| 237 | if (!bgr && !rgb) |
| 238 | /* |
| 239 | * The requested format was not possible, try just |
| 240 | * our capabilities. One of BGR or RGB must be |
| 241 | * supported. |
| 242 | */ |
| 243 | bgr = caps & CLCD_CAP_BGR; |
| 244 | |
| 245 | if (bgr) { |
Russell King | c43e6f0 | 2006-01-26 14:12:06 +0000 | [diff] [blame] | 246 | var->blue.offset = 0; |
| 247 | var->green.offset = var->blue.offset + var->blue.length; |
| 248 | var->red.offset = var->green.offset + var->green.length; |
| 249 | } else { |
| 250 | var->red.offset = 0; |
| 251 | var->green.offset = var->red.offset + var->red.length; |
| 252 | var->blue.offset = var->green.offset + var->green.length; |
| 253 | } |
| 254 | } |
| 255 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | return ret; |
| 257 | } |
| 258 | |
| 259 | static int clcdfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info) |
| 260 | { |
| 261 | struct clcd_fb *fb = to_clcd(info); |
| 262 | int ret = -EINVAL; |
| 263 | |
| 264 | if (fb->board->check) |
| 265 | ret = fb->board->check(fb, var); |
Russell King | 82235e9 | 2005-04-28 10:43:52 +0100 | [diff] [blame] | 266 | |
| 267 | if (ret == 0 && |
| 268 | var->xres_virtual * var->bits_per_pixel / 8 * |
| 269 | var->yres_virtual > fb->fb.fix.smem_len) |
| 270 | ret = -EINVAL; |
| 271 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | if (ret == 0) |
| 273 | ret = clcdfb_set_bitfields(fb, var); |
| 274 | |
| 275 | return ret; |
| 276 | } |
| 277 | |
| 278 | static int clcdfb_set_par(struct fb_info *info) |
| 279 | { |
| 280 | struct clcd_fb *fb = to_clcd(info); |
| 281 | struct clcd_regs regs; |
| 282 | |
| 283 | fb->fb.fix.line_length = fb->fb.var.xres_virtual * |
| 284 | fb->fb.var.bits_per_pixel / 8; |
| 285 | |
| 286 | if (fb->fb.var.bits_per_pixel <= 8) |
| 287 | fb->fb.fix.visual = FB_VISUAL_PSEUDOCOLOR; |
| 288 | else |
| 289 | fb->fb.fix.visual = FB_VISUAL_TRUECOLOR; |
| 290 | |
| 291 | fb->board->decode(fb, ®s); |
| 292 | |
| 293 | clcdfb_disable(fb); |
| 294 | |
| 295 | writel(regs.tim0, fb->regs + CLCD_TIM0); |
| 296 | writel(regs.tim1, fb->regs + CLCD_TIM1); |
| 297 | writel(regs.tim2, fb->regs + CLCD_TIM2); |
| 298 | writel(regs.tim3, fb->regs + CLCD_TIM3); |
| 299 | |
| 300 | clcdfb_set_start(fb); |
| 301 | |
| 302 | clk_set_rate(fb->clk, (1000000000 / regs.pixclock) * 1000); |
| 303 | |
| 304 | fb->clcd_cntl = regs.cntl; |
| 305 | |
| 306 | clcdfb_enable(fb, regs.cntl); |
| 307 | |
| 308 | #ifdef DEBUG |
Joe Perches | ad361c9 | 2009-07-06 13:05:40 -0700 | [diff] [blame] | 309 | printk(KERN_INFO |
| 310 | "CLCD: Registers set to\n" |
| 311 | " %08x %08x %08x %08x\n" |
| 312 | " %08x %08x %08x %08x\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | readl(fb->regs + CLCD_TIM0), readl(fb->regs + CLCD_TIM1), |
| 314 | readl(fb->regs + CLCD_TIM2), readl(fb->regs + CLCD_TIM3), |
| 315 | readl(fb->regs + CLCD_UBAS), readl(fb->regs + CLCD_LBAS), |
Russell King | 3f17522 | 2010-02-12 14:32:01 +0000 | [diff] [blame] | 316 | readl(fb->regs + fb->off_ienb), readl(fb->regs + fb->off_cntl)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | #endif |
| 318 | |
| 319 | return 0; |
| 320 | } |
| 321 | |
| 322 | static inline u32 convert_bitfield(int val, struct fb_bitfield *bf) |
| 323 | { |
| 324 | unsigned int mask = (1 << bf->length) - 1; |
| 325 | |
| 326 | return (val >> (16 - bf->length) & mask) << bf->offset; |
| 327 | } |
| 328 | |
| 329 | /* |
| 330 | * Set a single color register. The values supplied have a 16 bit |
| 331 | * magnitude. Return != 0 for invalid regno. |
| 332 | */ |
| 333 | static int |
| 334 | clcdfb_setcolreg(unsigned int regno, unsigned int red, unsigned int green, |
| 335 | unsigned int blue, unsigned int transp, struct fb_info *info) |
| 336 | { |
| 337 | struct clcd_fb *fb = to_clcd(info); |
| 338 | |
| 339 | if (regno < 16) |
| 340 | fb->cmap[regno] = convert_bitfield(transp, &fb->fb.var.transp) | |
| 341 | convert_bitfield(blue, &fb->fb.var.blue) | |
| 342 | convert_bitfield(green, &fb->fb.var.green) | |
| 343 | convert_bitfield(red, &fb->fb.var.red); |
| 344 | |
Russell King | 1ddb8a1 | 2005-04-30 22:39:51 +0100 | [diff] [blame] | 345 | if (fb->fb.fix.visual == FB_VISUAL_PSEUDOCOLOR && regno < 256) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | int hw_reg = CLCD_PALETTE + ((regno * 2) & ~3); |
| 347 | u32 val, mask, newval; |
| 348 | |
| 349 | newval = (red >> 11) & 0x001f; |
| 350 | newval |= (green >> 6) & 0x03e0; |
| 351 | newval |= (blue >> 1) & 0x7c00; |
| 352 | |
| 353 | /* |
| 354 | * 3.2.11: if we're configured for big endian |
| 355 | * byte order, the palette entries are swapped. |
| 356 | */ |
| 357 | if (fb->clcd_cntl & CNTL_BEBO) |
| 358 | regno ^= 1; |
| 359 | |
| 360 | if (regno & 1) { |
| 361 | newval <<= 16; |
| 362 | mask = 0x0000ffff; |
| 363 | } else { |
| 364 | mask = 0xffff0000; |
| 365 | } |
| 366 | |
| 367 | val = readl(fb->regs + hw_reg) & mask; |
| 368 | writel(val | newval, fb->regs + hw_reg); |
| 369 | } |
| 370 | |
| 371 | return regno > 255; |
| 372 | } |
| 373 | |
| 374 | /* |
| 375 | * Blank the screen if blank_mode != 0, else unblank. If blank == NULL |
| 376 | * then the caller blanks by setting the CLUT (Color Look Up Table) to all |
| 377 | * black. Return 0 if blanking succeeded, != 0 if un-/blanking failed due |
| 378 | * to e.g. a video mode which doesn't support it. Implements VESA suspend |
| 379 | * and powerdown modes on hardware that supports disabling hsync/vsync: |
| 380 | * blank_mode == 2: suspend vsync |
| 381 | * blank_mode == 3: suspend hsync |
| 382 | * blank_mode == 4: powerdown |
| 383 | */ |
| 384 | static int clcdfb_blank(int blank_mode, struct fb_info *info) |
| 385 | { |
| 386 | struct clcd_fb *fb = to_clcd(info); |
| 387 | |
| 388 | if (blank_mode != 0) { |
| 389 | clcdfb_disable(fb); |
| 390 | } else { |
| 391 | clcdfb_enable(fb, fb->clcd_cntl); |
| 392 | } |
| 393 | return 0; |
| 394 | } |
| 395 | |
Christoph Hellwig | 216d526 | 2006-01-14 13:21:25 -0800 | [diff] [blame] | 396 | static int clcdfb_mmap(struct fb_info *info, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | struct vm_area_struct *vma) |
| 398 | { |
| 399 | struct clcd_fb *fb = to_clcd(info); |
| 400 | unsigned long len, off = vma->vm_pgoff << PAGE_SHIFT; |
| 401 | int ret = -EINVAL; |
| 402 | |
| 403 | len = info->fix.smem_len; |
| 404 | |
| 405 | if (off <= len && vma->vm_end - vma->vm_start <= len - off && |
| 406 | fb->board->mmap) |
| 407 | ret = fb->board->mmap(fb, vma); |
| 408 | |
| 409 | return ret; |
| 410 | } |
| 411 | |
| 412 | static struct fb_ops clcdfb_ops = { |
| 413 | .owner = THIS_MODULE, |
| 414 | .fb_check_var = clcdfb_check_var, |
| 415 | .fb_set_par = clcdfb_set_par, |
| 416 | .fb_setcolreg = clcdfb_setcolreg, |
| 417 | .fb_blank = clcdfb_blank, |
| 418 | .fb_fillrect = cfb_fillrect, |
| 419 | .fb_copyarea = cfb_copyarea, |
| 420 | .fb_imageblit = cfb_imageblit, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | .fb_mmap = clcdfb_mmap, |
| 422 | }; |
| 423 | |
| 424 | static int clcdfb_register(struct clcd_fb *fb) |
| 425 | { |
| 426 | int ret; |
| 427 | |
Russell King | 3f17522 | 2010-02-12 14:32:01 +0000 | [diff] [blame] | 428 | /* |
| 429 | * ARM PL111 always has IENB at 0x1c; it's only PL110 |
| 430 | * which is reversed on some platforms. |
| 431 | */ |
| 432 | if (amba_manf(fb->dev) == 0x41 && amba_part(fb->dev) == 0x111) { |
| 433 | fb->off_ienb = CLCD_PL111_IENB; |
| 434 | fb->off_cntl = CLCD_PL111_CNTL; |
| 435 | } else { |
| 436 | #ifdef CONFIG_ARCH_VERSATILE |
| 437 | fb->off_ienb = CLCD_PL111_IENB; |
| 438 | fb->off_cntl = CLCD_PL111_CNTL; |
| 439 | #else |
| 440 | fb->off_ienb = CLCD_PL110_IENB; |
| 441 | fb->off_cntl = CLCD_PL110_CNTL; |
| 442 | #endif |
| 443 | } |
| 444 | |
Russell King | ee569c4 | 2008-11-30 17:38:14 +0000 | [diff] [blame] | 445 | fb->clk = clk_get(&fb->dev->dev, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | if (IS_ERR(fb->clk)) { |
| 447 | ret = PTR_ERR(fb->clk); |
| 448 | goto out; |
| 449 | } |
| 450 | |
Russell King | 99df4ee | 2011-09-22 12:34:31 +0100 | [diff] [blame] | 451 | ret = clk_prepare(fb->clk); |
| 452 | if (ret) |
| 453 | goto free_clk; |
| 454 | |
Loïc Minier | 17e8c4e | 2011-06-20 20:44:17 +0000 | [diff] [blame] | 455 | fb->fb.device = &fb->dev->dev; |
| 456 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | fb->fb.fix.mmio_start = fb->dev->res.start; |
Linus Walleij | dc890c2 | 2009-06-07 23:27:31 +0100 | [diff] [blame] | 458 | fb->fb.fix.mmio_len = resource_size(&fb->dev->res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | |
| 460 | fb->regs = ioremap(fb->fb.fix.mmio_start, fb->fb.fix.mmio_len); |
| 461 | if (!fb->regs) { |
| 462 | printk(KERN_ERR "CLCD: unable to remap registers\n"); |
| 463 | ret = -ENOMEM; |
Russell King | 99df4ee | 2011-09-22 12:34:31 +0100 | [diff] [blame] | 464 | goto clk_unprep; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | fb->fb.fbops = &clcdfb_ops; |
| 468 | fb->fb.flags = FBINFO_FLAG_DEFAULT; |
| 469 | fb->fb.pseudo_palette = fb->cmap; |
| 470 | |
| 471 | strncpy(fb->fb.fix.id, clcd_name, sizeof(fb->fb.fix.id)); |
| 472 | fb->fb.fix.type = FB_TYPE_PACKED_PIXELS; |
| 473 | fb->fb.fix.type_aux = 0; |
| 474 | fb->fb.fix.xpanstep = 0; |
| 475 | fb->fb.fix.ypanstep = 0; |
| 476 | fb->fb.fix.ywrapstep = 0; |
| 477 | fb->fb.fix.accel = FB_ACCEL_NONE; |
| 478 | |
| 479 | fb->fb.var.xres = fb->panel->mode.xres; |
| 480 | fb->fb.var.yres = fb->panel->mode.yres; |
| 481 | fb->fb.var.xres_virtual = fb->panel->mode.xres; |
| 482 | fb->fb.var.yres_virtual = fb->panel->mode.yres; |
| 483 | fb->fb.var.bits_per_pixel = fb->panel->bpp; |
| 484 | fb->fb.var.grayscale = fb->panel->grayscale; |
| 485 | fb->fb.var.pixclock = fb->panel->mode.pixclock; |
| 486 | fb->fb.var.left_margin = fb->panel->mode.left_margin; |
| 487 | fb->fb.var.right_margin = fb->panel->mode.right_margin; |
| 488 | fb->fb.var.upper_margin = fb->panel->mode.upper_margin; |
| 489 | fb->fb.var.lower_margin = fb->panel->mode.lower_margin; |
| 490 | fb->fb.var.hsync_len = fb->panel->mode.hsync_len; |
| 491 | fb->fb.var.vsync_len = fb->panel->mode.vsync_len; |
| 492 | fb->fb.var.sync = fb->panel->mode.sync; |
| 493 | fb->fb.var.vmode = fb->panel->mode.vmode; |
| 494 | fb->fb.var.activate = FB_ACTIVATE_NOW; |
| 495 | fb->fb.var.nonstd = 0; |
| 496 | fb->fb.var.height = fb->panel->height; |
| 497 | fb->fb.var.width = fb->panel->width; |
| 498 | fb->fb.var.accel_flags = 0; |
| 499 | |
| 500 | fb->fb.monspecs.hfmin = 0; |
| 501 | fb->fb.monspecs.hfmax = 100000; |
| 502 | fb->fb.monspecs.vfmin = 0; |
| 503 | fb->fb.monspecs.vfmax = 400; |
| 504 | fb->fb.monspecs.dclkmin = 1000000; |
| 505 | fb->fb.monspecs.dclkmax = 100000000; |
| 506 | |
| 507 | /* |
| 508 | * Make sure that the bitfields are set appropriately. |
| 509 | */ |
| 510 | clcdfb_set_bitfields(fb, &fb->fb.var); |
| 511 | |
| 512 | /* |
| 513 | * Allocate colourmap. |
| 514 | */ |
Andres Salomon | 909baf0 | 2009-03-31 15:25:29 -0700 | [diff] [blame] | 515 | ret = fb_alloc_cmap(&fb->fb.cmap, 256, 0); |
| 516 | if (ret) |
| 517 | goto unmap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | |
| 519 | /* |
| 520 | * Ensure interrupts are disabled. |
| 521 | */ |
Russell King | 3f17522 | 2010-02-12 14:32:01 +0000 | [diff] [blame] | 522 | writel(0, fb->regs + fb->off_ienb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | |
| 524 | fb_set_var(&fb->fb, &fb->fb.var); |
| 525 | |
Russell King | ff64332 | 2011-01-19 21:10:24 +0000 | [diff] [blame] | 526 | dev_info(&fb->dev->dev, "%s hardware, %s display\n", |
| 527 | fb->board->name, fb->panel->mode.name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | |
| 529 | ret = register_framebuffer(&fb->fb); |
| 530 | if (ret == 0) |
| 531 | goto out; |
| 532 | |
| 533 | printk(KERN_ERR "CLCD: cannot register framebuffer (%d)\n", ret); |
| 534 | |
Andres Salomon | 909baf0 | 2009-03-31 15:25:29 -0700 | [diff] [blame] | 535 | fb_dealloc_cmap(&fb->fb.cmap); |
| 536 | unmap: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | iounmap(fb->regs); |
Russell King | 99df4ee | 2011-09-22 12:34:31 +0100 | [diff] [blame] | 538 | clk_unprep: |
| 539 | clk_unprepare(fb->clk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | free_clk: |
| 541 | clk_put(fb->clk); |
| 542 | out: |
| 543 | return ret; |
| 544 | } |
| 545 | |
Russell King | aa25afa | 2011-02-19 15:55:00 +0000 | [diff] [blame] | 546 | static int clcdfb_probe(struct amba_device *dev, const struct amba_id *id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | { |
Jingoo Han | 46d2db8 | 2013-09-17 14:03:53 +0900 | [diff] [blame] | 548 | struct clcd_board *board = dev_get_platdata(&dev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | struct clcd_fb *fb; |
| 550 | int ret; |
| 551 | |
| 552 | if (!board) |
| 553 | return -EINVAL; |
| 554 | |
Russell King | e0a8ba2 | 2013-06-27 10:29:32 +0100 | [diff] [blame] | 555 | ret = dma_set_mask_and_coherent(&dev->dev, DMA_BIT_MASK(32)); |
| 556 | if (ret) |
| 557 | goto out; |
| 558 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | ret = amba_request_regions(dev, NULL); |
| 560 | if (ret) { |
| 561 | printk(KERN_ERR "CLCD: unable to reserve regs region\n"); |
| 562 | goto out; |
| 563 | } |
| 564 | |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 565 | fb = kzalloc(sizeof(struct clcd_fb), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | if (!fb) { |
| 567 | printk(KERN_INFO "CLCD: could not allocate new clcd_fb struct\n"); |
| 568 | ret = -ENOMEM; |
| 569 | goto free_region; |
| 570 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | |
| 572 | fb->dev = dev; |
| 573 | fb->board = board; |
| 574 | |
Russell King | ff64332 | 2011-01-19 21:10:24 +0000 | [diff] [blame] | 575 | dev_info(&fb->dev->dev, "PL%03x rev%u at 0x%08llx\n", |
| 576 | amba_part(dev), amba_rev(dev), |
| 577 | (unsigned long long)dev->res.start); |
| 578 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | ret = fb->board->setup(fb); |
| 580 | if (ret) |
| 581 | goto free_fb; |
| 582 | |
| 583 | ret = clcdfb_register(fb); |
| 584 | if (ret == 0) { |
| 585 | amba_set_drvdata(dev, fb); |
| 586 | goto out; |
| 587 | } |
| 588 | |
| 589 | fb->board->remove(fb); |
| 590 | free_fb: |
| 591 | kfree(fb); |
| 592 | free_region: |
| 593 | amba_release_regions(dev); |
| 594 | out: |
| 595 | return ret; |
| 596 | } |
| 597 | |
| 598 | static int clcdfb_remove(struct amba_device *dev) |
| 599 | { |
| 600 | struct clcd_fb *fb = amba_get_drvdata(dev); |
| 601 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | clcdfb_disable(fb); |
| 603 | unregister_framebuffer(&fb->fb); |
Andres Salomon | 909baf0 | 2009-03-31 15:25:29 -0700 | [diff] [blame] | 604 | if (fb->fb.cmap.len) |
| 605 | fb_dealloc_cmap(&fb->fb.cmap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | iounmap(fb->regs); |
Russell King | 99df4ee | 2011-09-22 12:34:31 +0100 | [diff] [blame] | 607 | clk_unprepare(fb->clk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | clk_put(fb->clk); |
| 609 | |
| 610 | fb->board->remove(fb); |
| 611 | |
| 612 | kfree(fb); |
| 613 | |
| 614 | amba_release_regions(dev); |
| 615 | |
| 616 | return 0; |
| 617 | } |
| 618 | |
| 619 | static struct amba_id clcdfb_id_table[] = { |
| 620 | { |
| 621 | .id = 0x00041110, |
Russell King | e831556 | 2005-11-02 14:40:35 +0000 | [diff] [blame] | 622 | .mask = 0x000ffffe, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | }, |
| 624 | { 0, 0 }, |
| 625 | }; |
| 626 | |
Dave Martin | 6054f9b | 2011-10-05 15:15:23 +0100 | [diff] [blame] | 627 | MODULE_DEVICE_TABLE(amba, clcdfb_id_table); |
| 628 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | static struct amba_driver clcd_driver = { |
| 630 | .drv = { |
Russell King | e831556 | 2005-11-02 14:40:35 +0000 | [diff] [blame] | 631 | .name = "clcd-pl11x", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | }, |
| 633 | .probe = clcdfb_probe, |
| 634 | .remove = clcdfb_remove, |
| 635 | .id_table = clcdfb_id_table, |
| 636 | }; |
| 637 | |
Russell King | 2c25013 | 2005-11-08 14:44:15 +0000 | [diff] [blame] | 638 | static int __init amba_clcdfb_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | { |
| 640 | if (fb_get_options("ambafb", NULL)) |
| 641 | return -ENODEV; |
| 642 | |
| 643 | return amba_driver_register(&clcd_driver); |
| 644 | } |
| 645 | |
| 646 | module_init(amba_clcdfb_init); |
| 647 | |
| 648 | static void __exit amba_clcdfb_exit(void) |
| 649 | { |
| 650 | amba_driver_unregister(&clcd_driver); |
| 651 | } |
| 652 | |
| 653 | module_exit(amba_clcdfb_exit); |
| 654 | |
| 655 | MODULE_DESCRIPTION("ARM PrimeCell PL110 CLCD core driver"); |
| 656 | MODULE_LICENSE("GPL"); |