Michael Hennerich | e9fa7c4 | 2007-10-16 01:29:38 -0700 | [diff] [blame] | 1 | /* |
| 2 | * File: drivers/video/bf54x-lq043.c |
| 3 | * Based on: |
| 4 | * Author: Michael Hennerich <hennerich@blackfin.uclinux.org> |
| 5 | * |
| 6 | * Created: |
| 7 | * Description: ADSP-BF54x Framebufer driver |
| 8 | * |
| 9 | * |
| 10 | * Modified: |
Michael Hennerich | 5e9e4ad | 2008-03-10 11:44:03 -0700 | [diff] [blame] | 11 | * Copyright 2007-2008 Analog Devices Inc. |
Michael Hennerich | e9fa7c4 | 2007-10-16 01:29:38 -0700 | [diff] [blame] | 12 | * |
| 13 | * Bugs: Enter bugs at http://blackfin.uclinux.org/ |
| 14 | * |
| 15 | * This program is free software; you can redistribute it and/or modify |
| 16 | * it under the terms of the GNU General Public License as published by |
| 17 | * the Free Software Foundation; either version 2 of the License, or |
| 18 | * (at your option) any later version. |
| 19 | * |
| 20 | * This program is distributed in the hope that it will be useful, |
| 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 23 | * GNU General Public License for more details. |
| 24 | * |
| 25 | * You should have received a copy of the GNU General Public License |
| 26 | * along with this program; if not, see the file COPYING, or write |
| 27 | * to the Free Software Foundation, Inc., |
| 28 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 29 | */ |
| 30 | |
| 31 | #include <linux/module.h> |
| 32 | #include <linux/kernel.h> |
| 33 | #include <linux/errno.h> |
| 34 | #include <linux/string.h> |
| 35 | #include <linux/mm.h> |
| 36 | #include <linux/tty.h> |
| 37 | #include <linux/slab.h> |
| 38 | #include <linux/delay.h> |
| 39 | #include <linux/fb.h> |
| 40 | #include <linux/ioport.h> |
| 41 | #include <linux/init.h> |
| 42 | #include <linux/types.h> |
| 43 | #include <linux/interrupt.h> |
| 44 | #include <linux/sched.h> |
| 45 | #include <linux/timer.h> |
| 46 | #include <linux/device.h> |
| 47 | #include <linux/backlight.h> |
| 48 | #include <linux/lcd.h> |
| 49 | #include <linux/spinlock.h> |
| 50 | #include <linux/dma-mapping.h> |
| 51 | #include <linux/platform_device.h> |
| 52 | |
| 53 | #include <asm/blackfin.h> |
| 54 | #include <asm/irq.h> |
| 55 | #include <asm/dpmc.h> |
| 56 | #include <asm/dma-mapping.h> |
| 57 | #include <asm/dma.h> |
| 58 | #include <asm/gpio.h> |
| 59 | #include <asm/portmux.h> |
| 60 | |
Bryan Wu | 639f657 | 2008-08-27 10:51:02 +0800 | [diff] [blame] | 61 | #include <mach/bf54x-lq043.h> |
Michael Hennerich | e9fa7c4 | 2007-10-16 01:29:38 -0700 | [diff] [blame] | 62 | |
| 63 | #define NO_BL_SUPPORT |
| 64 | |
| 65 | #define DRIVER_NAME "bf54x-lq043" |
| 66 | static char driver_name[] = DRIVER_NAME; |
| 67 | |
| 68 | #define BFIN_LCD_NBR_PALETTE_ENTRIES 256 |
| 69 | |
| 70 | #define EPPI0_18 {P_PPI0_CLK, P_PPI0_FS1, P_PPI0_FS2, P_PPI0_D0, P_PPI0_D1, P_PPI0_D2, P_PPI0_D3, \ |
| 71 | P_PPI0_D4, P_PPI0_D5, P_PPI0_D6, P_PPI0_D7, P_PPI0_D8, P_PPI0_D9, P_PPI0_D10, \ |
| 72 | P_PPI0_D11, P_PPI0_D12, P_PPI0_D13, P_PPI0_D14, P_PPI0_D15, P_PPI0_D16, P_PPI0_D17, 0} |
| 73 | |
| 74 | #define EPPI0_24 {P_PPI0_D18, P_PPI0_D19, P_PPI0_D20, P_PPI0_D21, P_PPI0_D22, P_PPI0_D23, 0} |
| 75 | |
| 76 | struct bfin_bf54xfb_info { |
| 77 | struct fb_info *fb; |
| 78 | struct device *dev; |
| 79 | |
| 80 | struct bfin_bf54xfb_mach_info *mach_info; |
| 81 | |
| 82 | unsigned char *fb_buffer; /* RGB Buffer */ |
| 83 | |
| 84 | dma_addr_t dma_handle; |
Michael Hennerich | e9fa7c4 | 2007-10-16 01:29:38 -0700 | [diff] [blame] | 85 | int lq043_open_cnt; |
| 86 | int irq; |
| 87 | spinlock_t lock; /* lock */ |
| 88 | }; |
| 89 | |
| 90 | static int nocursor; |
| 91 | module_param(nocursor, int, 0644); |
| 92 | MODULE_PARM_DESC(nocursor, "cursor enable/disable"); |
| 93 | |
| 94 | static int outp_rgb666; |
| 95 | module_param(outp_rgb666, int, 0); |
| 96 | MODULE_PARM_DESC(outp_rgb666, "Output 18-bit RGB666"); |
| 97 | |
| 98 | #define LCD_X_RES 480 /*Horizontal Resolution */ |
| 99 | #define LCD_Y_RES 272 /* Vertical Resolution */ |
| 100 | |
| 101 | #define LCD_BPP 24 /* Bit Per Pixel */ |
| 102 | #define DMA_BUS_SIZE 32 |
| 103 | |
| 104 | /* -- Horizontal synchronizing -- |
| 105 | * |
| 106 | * Timing characteristics taken from the SHARP LQ043T1DG01 datasheet |
| 107 | * (LCY-W-06602A Page 9 of 22) |
| 108 | * |
| 109 | * Clock Frequency 1/Tc Min 7.83 Typ 9.00 Max 9.26 MHz |
| 110 | * |
| 111 | * Period TH - 525 - Clock |
| 112 | * Pulse width THp - 41 - Clock |
| 113 | * Horizontal period THd - 480 - Clock |
| 114 | * Back porch THb - 2 - Clock |
| 115 | * Front porch THf - 2 - Clock |
| 116 | * |
| 117 | * -- Vertical synchronizing -- |
| 118 | * Period TV - 286 - Line |
| 119 | * Pulse width TVp - 10 - Line |
| 120 | * Vertical period TVd - 272 - Line |
| 121 | * Back porch TVb - 2 - Line |
| 122 | * Front porch TVf - 2 - Line |
| 123 | */ |
| 124 | |
| 125 | #define LCD_CLK (8*1000*1000) /* 8MHz */ |
| 126 | |
| 127 | /* # active data to transfer after Horizontal Delay clock */ |
| 128 | #define EPPI_HCOUNT LCD_X_RES |
| 129 | |
| 130 | /* # active lines to transfer after Vertical Delay clock */ |
| 131 | #define EPPI_VCOUNT LCD_Y_RES |
| 132 | |
| 133 | /* Samples per Line = 480 (active data) + 45 (padding) */ |
| 134 | #define EPPI_LINE 525 |
| 135 | |
| 136 | /* Lines per Frame = 272 (active data) + 14 (padding) */ |
| 137 | #define EPPI_FRAME 286 |
| 138 | |
| 139 | /* FS1 (Hsync) Width (Typical)*/ |
| 140 | #define EPPI_FS1W_HBL 41 |
| 141 | |
| 142 | /* FS1 (Hsync) Period (Typical) */ |
| 143 | #define EPPI_FS1P_AVPL EPPI_LINE |
| 144 | |
| 145 | /* Horizontal Delay clock after assertion of Hsync (Typical) */ |
| 146 | #define EPPI_HDELAY 43 |
| 147 | |
| 148 | /* FS2 (Vsync) Width = FS1 (Hsync) Period * 10 */ |
| 149 | #define EPPI_FS2W_LVB (EPPI_LINE * 10) |
| 150 | |
| 151 | /* FS2 (Vsync) Period = FS1 (Hsync) Period * Lines per Frame */ |
| 152 | #define EPPI_FS2P_LAVF (EPPI_LINE * EPPI_FRAME) |
| 153 | |
| 154 | /* Vertical Delay after assertion of Vsync (2 Lines) */ |
| 155 | #define EPPI_VDELAY 12 |
| 156 | |
| 157 | #define EPPI_CLIP 0xFF00FF00 |
| 158 | |
| 159 | /* EPPI Control register configuration value for RGB out |
| 160 | * - EPPI as Output |
| 161 | * GP 2 frame sync mode, |
| 162 | * Internal Clock generation disabled, Internal FS generation enabled, |
| 163 | * Receives samples on EPPI_CLK raising edge, Transmits samples on EPPI_CLK falling edge, |
| 164 | * FS1 & FS2 are active high, |
| 165 | * DLEN = 6 (24 bits for RGB888 out) or 5 (18 bits for RGB666 out) |
| 166 | * DMA Unpacking disabled when RGB Formating is enabled, otherwise DMA unpacking enabled |
| 167 | * Swapping Enabled, |
| 168 | * One (DMA) Channel Mode, |
| 169 | * RGB Formatting Enabled for RGB666 output, disabled for RGB888 output |
| 170 | * Regular watermark - when FIFO is 100% full, |
| 171 | * Urgent watermark - when FIFO is 75% full |
| 172 | */ |
| 173 | |
| 174 | #define EPPI_CONTROL (0x20136E2E | SWAPEN) |
| 175 | |
| 176 | static inline u16 get_eppi_clkdiv(u32 target_ppi_clk) |
| 177 | { |
| 178 | u32 sclk = get_sclk(); |
| 179 | |
| 180 | /* EPPI_CLK = (SCLK) / (2 * (EPPI_CLKDIV[15:0] + 1)) */ |
| 181 | |
| 182 | return (((sclk / target_ppi_clk) / 2) - 1); |
| 183 | } |
| 184 | |
| 185 | static void config_ppi(struct bfin_bf54xfb_info *fbi) |
| 186 | { |
| 187 | |
| 188 | u16 eppi_clkdiv = get_eppi_clkdiv(LCD_CLK); |
| 189 | |
| 190 | bfin_write_EPPI0_FS1W_HBL(EPPI_FS1W_HBL); |
| 191 | bfin_write_EPPI0_FS1P_AVPL(EPPI_FS1P_AVPL); |
| 192 | bfin_write_EPPI0_FS2W_LVB(EPPI_FS2W_LVB); |
| 193 | bfin_write_EPPI0_FS2P_LAVF(EPPI_FS2P_LAVF); |
| 194 | bfin_write_EPPI0_CLIP(EPPI_CLIP); |
| 195 | |
| 196 | bfin_write_EPPI0_FRAME(EPPI_FRAME); |
| 197 | bfin_write_EPPI0_LINE(EPPI_LINE); |
| 198 | |
| 199 | bfin_write_EPPI0_HCOUNT(EPPI_HCOUNT); |
| 200 | bfin_write_EPPI0_HDELAY(EPPI_HDELAY); |
| 201 | bfin_write_EPPI0_VCOUNT(EPPI_VCOUNT); |
| 202 | bfin_write_EPPI0_VDELAY(EPPI_VDELAY); |
| 203 | |
| 204 | bfin_write_EPPI0_CLKDIV(eppi_clkdiv); |
| 205 | |
| 206 | /* |
| 207 | * DLEN = 6 (24 bits for RGB888 out) or 5 (18 bits for RGB666 out) |
| 208 | * RGB Formatting Enabled for RGB666 output, disabled for RGB888 output |
| 209 | */ |
| 210 | if (outp_rgb666) |
| 211 | bfin_write_EPPI0_CONTROL((EPPI_CONTROL & ~DLENGTH) | DLEN_18 | |
| 212 | RGB_FMT_EN); |
| 213 | else |
| 214 | bfin_write_EPPI0_CONTROL(((EPPI_CONTROL & ~DLENGTH) | DLEN_24) & |
| 215 | ~RGB_FMT_EN); |
| 216 | |
| 217 | |
| 218 | } |
| 219 | |
| 220 | static int config_dma(struct bfin_bf54xfb_info *fbi) |
| 221 | { |
| 222 | |
| 223 | set_dma_config(CH_EPPI0, |
| 224 | set_bfin_dma_config(DIR_READ, DMA_FLOW_AUTO, |
| 225 | INTR_DISABLE, DIMENSION_2D, |
Michael Hennerich | 2047e40 | 2008-01-22 15:29:18 +0800 | [diff] [blame] | 226 | DATA_SIZE_32, |
| 227 | DMA_NOSYNC_KEEP_DMA_BUF)); |
Michael Hennerich | e9fa7c4 | 2007-10-16 01:29:38 -0700 | [diff] [blame] | 228 | set_dma_x_count(CH_EPPI0, (LCD_X_RES * LCD_BPP) / DMA_BUS_SIZE); |
| 229 | set_dma_x_modify(CH_EPPI0, DMA_BUS_SIZE / 8); |
| 230 | set_dma_y_count(CH_EPPI0, LCD_Y_RES); |
| 231 | set_dma_y_modify(CH_EPPI0, DMA_BUS_SIZE / 8); |
| 232 | set_dma_start_addr(CH_EPPI0, (unsigned long)fbi->fb_buffer); |
| 233 | |
| 234 | return 0; |
| 235 | } |
| 236 | |
| 237 | static int request_ports(struct bfin_bf54xfb_info *fbi) |
| 238 | { |
| 239 | |
| 240 | u16 eppi_req_18[] = EPPI0_18; |
| 241 | u16 disp = fbi->mach_info->disp; |
| 242 | |
Michael Hennerich | fdcc535 | 2008-03-10 11:44:02 -0700 | [diff] [blame] | 243 | if (gpio_request(disp, DRIVER_NAME)) { |
Paul Bolle | 426d310 | 2010-08-07 12:30:03 +0200 | [diff] [blame] | 244 | printk(KERN_ERR "Requesting GPIO %d failed\n", disp); |
Michael Hennerich | e9fa7c4 | 2007-10-16 01:29:38 -0700 | [diff] [blame] | 245 | return -EFAULT; |
| 246 | } |
| 247 | |
| 248 | if (peripheral_request_list(eppi_req_18, DRIVER_NAME)) { |
Paul Bolle | 426d310 | 2010-08-07 12:30:03 +0200 | [diff] [blame] | 249 | printk(KERN_ERR "Requesting Peripherals failed\n"); |
Michael Hennerich | e9fa7c4 | 2007-10-16 01:29:38 -0700 | [diff] [blame] | 250 | gpio_free(disp); |
| 251 | return -EFAULT; |
| 252 | } |
| 253 | |
| 254 | if (!outp_rgb666) { |
| 255 | |
| 256 | u16 eppi_req_24[] = EPPI0_24; |
| 257 | |
| 258 | if (peripheral_request_list(eppi_req_24, DRIVER_NAME)) { |
Paul Bolle | 426d310 | 2010-08-07 12:30:03 +0200 | [diff] [blame] | 259 | printk(KERN_ERR "Requesting Peripherals failed\n"); |
Michael Hennerich | e9fa7c4 | 2007-10-16 01:29:38 -0700 | [diff] [blame] | 260 | peripheral_free_list(eppi_req_18); |
| 261 | gpio_free(disp); |
| 262 | return -EFAULT; |
| 263 | } |
| 264 | } |
| 265 | |
Michael Hennerich | acbcd26 | 2008-01-22 18:36:20 +0800 | [diff] [blame] | 266 | gpio_direction_output(disp, 1); |
Michael Hennerich | e9fa7c4 | 2007-10-16 01:29:38 -0700 | [diff] [blame] | 267 | |
| 268 | return 0; |
| 269 | } |
| 270 | |
| 271 | static void free_ports(struct bfin_bf54xfb_info *fbi) |
| 272 | { |
| 273 | |
| 274 | u16 eppi_req_18[] = EPPI0_18; |
| 275 | |
| 276 | gpio_free(fbi->mach_info->disp); |
| 277 | |
| 278 | peripheral_free_list(eppi_req_18); |
| 279 | |
| 280 | if (!outp_rgb666) { |
| 281 | u16 eppi_req_24[] = EPPI0_24; |
| 282 | peripheral_free_list(eppi_req_24); |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | static int bfin_bf54x_fb_open(struct fb_info *info, int user) |
| 287 | { |
| 288 | struct bfin_bf54xfb_info *fbi = info->par; |
| 289 | |
| 290 | spin_lock(&fbi->lock); |
| 291 | fbi->lq043_open_cnt++; |
| 292 | |
| 293 | if (fbi->lq043_open_cnt <= 1) { |
| 294 | |
| 295 | bfin_write_EPPI0_CONTROL(0); |
| 296 | SSYNC(); |
| 297 | |
| 298 | config_dma(fbi); |
| 299 | config_ppi(fbi); |
| 300 | |
| 301 | /* start dma */ |
| 302 | enable_dma(CH_EPPI0); |
| 303 | bfin_write_EPPI0_CONTROL(bfin_read_EPPI0_CONTROL() | EPPI_EN); |
| 304 | } |
| 305 | |
| 306 | spin_unlock(&fbi->lock); |
| 307 | |
| 308 | return 0; |
| 309 | } |
| 310 | |
| 311 | static int bfin_bf54x_fb_release(struct fb_info *info, int user) |
| 312 | { |
| 313 | struct bfin_bf54xfb_info *fbi = info->par; |
| 314 | |
| 315 | spin_lock(&fbi->lock); |
| 316 | |
| 317 | fbi->lq043_open_cnt--; |
Michael Hennerich | e9fa7c4 | 2007-10-16 01:29:38 -0700 | [diff] [blame] | 318 | |
| 319 | if (fbi->lq043_open_cnt <= 0) { |
| 320 | |
| 321 | bfin_write_EPPI0_CONTROL(0); |
| 322 | SSYNC(); |
| 323 | disable_dma(CH_EPPI0); |
Michael Hennerich | e9fa7c4 | 2007-10-16 01:29:38 -0700 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | spin_unlock(&fbi->lock); |
| 327 | |
| 328 | return 0; |
| 329 | } |
| 330 | |
| 331 | static int bfin_bf54x_fb_check_var(struct fb_var_screeninfo *var, |
| 332 | struct fb_info *info) |
| 333 | { |
| 334 | |
Michael Hennerich | b46578e | 2009-01-15 13:50:46 -0800 | [diff] [blame] | 335 | switch (var->bits_per_pixel) { |
| 336 | case 24:/* TRUECOLOUR, 16m */ |
| 337 | var->red.offset = 16; |
| 338 | var->green.offset = 8; |
| 339 | var->blue.offset = 0; |
| 340 | var->red.length = var->green.length = var->blue.length = 8; |
| 341 | var->transp.offset = 0; |
| 342 | var->transp.length = 0; |
| 343 | var->transp.msb_right = 0; |
| 344 | var->red.msb_right = 0; |
| 345 | var->green.msb_right = 0; |
| 346 | var->blue.msb_right = 0; |
| 347 | break; |
| 348 | default: |
Harvey Harrison | 5ae1217 | 2008-04-28 02:15:47 -0700 | [diff] [blame] | 349 | pr_debug("%s: depth not supported: %u BPP\n", __func__, |
Michael Hennerich | e9fa7c4 | 2007-10-16 01:29:38 -0700 | [diff] [blame] | 350 | var->bits_per_pixel); |
| 351 | return -EINVAL; |
| 352 | } |
| 353 | |
| 354 | if (info->var.xres != var->xres || info->var.yres != var->yres || |
| 355 | info->var.xres_virtual != var->xres_virtual || |
| 356 | info->var.yres_virtual != var->yres_virtual) { |
| 357 | pr_debug("%s: Resolution not supported: X%u x Y%u \n", |
Harvey Harrison | 5ae1217 | 2008-04-28 02:15:47 -0700 | [diff] [blame] | 358 | __func__, var->xres, var->yres); |
Michael Hennerich | e9fa7c4 | 2007-10-16 01:29:38 -0700 | [diff] [blame] | 359 | return -EINVAL; |
| 360 | } |
| 361 | |
| 362 | /* |
| 363 | * Memory limit |
| 364 | */ |
| 365 | |
| 366 | if ((info->fix.line_length * var->yres_virtual) > info->fix.smem_len) { |
| 367 | pr_debug("%s: Memory Limit requested yres_virtual = %u\n", |
Harvey Harrison | 5ae1217 | 2008-04-28 02:15:47 -0700 | [diff] [blame] | 368 | __func__, var->yres_virtual); |
Michael Hennerich | e9fa7c4 | 2007-10-16 01:29:38 -0700 | [diff] [blame] | 369 | return -ENOMEM; |
| 370 | } |
| 371 | |
| 372 | return 0; |
| 373 | } |
| 374 | |
Michael Hennerich | e9fa7c4 | 2007-10-16 01:29:38 -0700 | [diff] [blame] | 375 | int bfin_bf54x_fb_cursor(struct fb_info *info, struct fb_cursor *cursor) |
| 376 | { |
| 377 | if (nocursor) |
| 378 | return 0; |
| 379 | else |
| 380 | return -EINVAL; /* just to force soft_cursor() call */ |
| 381 | } |
| 382 | |
| 383 | static int bfin_bf54x_fb_setcolreg(u_int regno, u_int red, u_int green, |
| 384 | u_int blue, u_int transp, |
| 385 | struct fb_info *info) |
| 386 | { |
| 387 | if (regno >= BFIN_LCD_NBR_PALETTE_ENTRIES) |
| 388 | return -EINVAL; |
| 389 | |
| 390 | if (info->var.grayscale) { |
| 391 | /* grayscale = 0.30*R + 0.59*G + 0.11*B */ |
| 392 | red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8; |
| 393 | } |
| 394 | |
| 395 | if (info->fix.visual == FB_VISUAL_TRUECOLOR) { |
| 396 | |
| 397 | u32 value; |
| 398 | /* Place color in the pseudopalette */ |
| 399 | if (regno > 16) |
| 400 | return -EINVAL; |
| 401 | |
| 402 | red >>= (16 - info->var.red.length); |
| 403 | green >>= (16 - info->var.green.length); |
| 404 | blue >>= (16 - info->var.blue.length); |
| 405 | |
| 406 | value = (red << info->var.red.offset) | |
| 407 | (green << info->var.green.offset) | |
| 408 | (blue << info->var.blue.offset); |
| 409 | value &= 0xFFFFFF; |
| 410 | |
| 411 | ((u32 *) (info->pseudo_palette))[regno] = value; |
| 412 | |
| 413 | } |
| 414 | |
| 415 | return 0; |
| 416 | } |
| 417 | |
| 418 | static struct fb_ops bfin_bf54x_fb_ops = { |
| 419 | .owner = THIS_MODULE, |
| 420 | .fb_open = bfin_bf54x_fb_open, |
| 421 | .fb_release = bfin_bf54x_fb_release, |
| 422 | .fb_check_var = bfin_bf54x_fb_check_var, |
| 423 | .fb_fillrect = cfb_fillrect, |
| 424 | .fb_copyarea = cfb_copyarea, |
| 425 | .fb_imageblit = cfb_imageblit, |
Michael Hennerich | e9fa7c4 | 2007-10-16 01:29:38 -0700 | [diff] [blame] | 426 | .fb_cursor = bfin_bf54x_fb_cursor, |
| 427 | .fb_setcolreg = bfin_bf54x_fb_setcolreg, |
| 428 | }; |
| 429 | |
| 430 | #ifndef NO_BL_SUPPORT |
| 431 | static int bl_get_brightness(struct backlight_device *bd) |
| 432 | { |
| 433 | return 0; |
| 434 | } |
| 435 | |
Bruno Prémont | fa11de0 | 2010-02-26 13:04:54 +0100 | [diff] [blame] | 436 | static const struct backlight_ops bfin_lq043fb_bl_ops = { |
Michael Hennerich | e9fa7c4 | 2007-10-16 01:29:38 -0700 | [diff] [blame] | 437 | .get_brightness = bl_get_brightness, |
| 438 | }; |
| 439 | |
| 440 | static struct backlight_device *bl_dev; |
| 441 | |
| 442 | static int bfin_lcd_get_power(struct lcd_device *dev) |
| 443 | { |
| 444 | return 0; |
| 445 | } |
| 446 | |
| 447 | static int bfin_lcd_set_power(struct lcd_device *dev, int power) |
| 448 | { |
| 449 | return 0; |
| 450 | } |
| 451 | |
| 452 | static int bfin_lcd_get_contrast(struct lcd_device *dev) |
| 453 | { |
| 454 | return 0; |
| 455 | } |
| 456 | |
| 457 | static int bfin_lcd_set_contrast(struct lcd_device *dev, int contrast) |
| 458 | { |
| 459 | |
| 460 | return 0; |
| 461 | } |
| 462 | |
Ben Dooks | 0c53136 | 2008-07-23 21:31:38 -0700 | [diff] [blame] | 463 | static int bfin_lcd_check_fb(struct lcd_device *dev, struct fb_info *fi) |
Michael Hennerich | e9fa7c4 | 2007-10-16 01:29:38 -0700 | [diff] [blame] | 464 | { |
| 465 | if (!fi || (fi == &bfin_bf54x_fb)) |
| 466 | return 1; |
| 467 | return 0; |
| 468 | } |
| 469 | |
| 470 | static struct lcd_ops bfin_lcd_ops = { |
| 471 | .get_power = bfin_lcd_get_power, |
| 472 | .set_power = bfin_lcd_set_power, |
| 473 | .get_contrast = bfin_lcd_get_contrast, |
| 474 | .set_contrast = bfin_lcd_set_contrast, |
| 475 | .check_fb = bfin_lcd_check_fb, |
| 476 | }; |
| 477 | |
| 478 | static struct lcd_device *lcd_dev; |
| 479 | #endif |
| 480 | |
| 481 | static irqreturn_t bfin_bf54x_irq_error(int irq, void *dev_id) |
| 482 | { |
Jeff Garzik | 15aafa2 | 2008-02-06 01:36:20 -0800 | [diff] [blame] | 483 | /*struct bfin_bf54xfb_info *info = dev_id;*/ |
Michael Hennerich | e9fa7c4 | 2007-10-16 01:29:38 -0700 | [diff] [blame] | 484 | |
| 485 | u16 status = bfin_read_EPPI0_STATUS(); |
| 486 | |
| 487 | bfin_write_EPPI0_STATUS(0xFFFF); |
| 488 | |
| 489 | if (status) { |
| 490 | bfin_write_EPPI0_CONTROL(bfin_read_EPPI0_CONTROL() & ~EPPI_EN); |
| 491 | disable_dma(CH_EPPI0); |
| 492 | |
| 493 | /* start dma */ |
| 494 | enable_dma(CH_EPPI0); |
| 495 | bfin_write_EPPI0_CONTROL(bfin_read_EPPI0_CONTROL() | EPPI_EN); |
| 496 | bfin_write_EPPI0_STATUS(0xFFFF); |
| 497 | } |
| 498 | |
| 499 | return IRQ_HANDLED; |
| 500 | } |
| 501 | |
Mike Frysinger | 8f09d74 | 2009-06-16 15:34:42 -0700 | [diff] [blame] | 502 | static int __devinit bfin_bf54x_probe(struct platform_device *pdev) |
Michael Hennerich | e9fa7c4 | 2007-10-16 01:29:38 -0700 | [diff] [blame] | 503 | { |
Mike Frysinger | 8fc809d | 2010-05-26 14:42:31 -0700 | [diff] [blame] | 504 | #ifndef NO_BL_SUPPORT |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 505 | struct backlight_properties props; |
Mike Frysinger | 8fc809d | 2010-05-26 14:42:31 -0700 | [diff] [blame] | 506 | #endif |
Michael Hennerich | e9fa7c4 | 2007-10-16 01:29:38 -0700 | [diff] [blame] | 507 | struct bfin_bf54xfb_info *info; |
| 508 | struct fb_info *fbinfo; |
| 509 | int ret; |
| 510 | |
| 511 | printk(KERN_INFO DRIVER_NAME ": FrameBuffer initializing...\n"); |
| 512 | |
| 513 | if (request_dma(CH_EPPI0, "CH_EPPI0") < 0) { |
| 514 | printk(KERN_ERR DRIVER_NAME |
| 515 | ": couldn't request CH_EPPI0 DMA\n"); |
| 516 | ret = -EFAULT; |
| 517 | goto out1; |
| 518 | } |
| 519 | |
| 520 | fbinfo = |
| 521 | framebuffer_alloc(sizeof(struct bfin_bf54xfb_info), &pdev->dev); |
| 522 | if (!fbinfo) { |
| 523 | ret = -ENOMEM; |
| 524 | goto out2; |
| 525 | } |
| 526 | |
| 527 | info = fbinfo->par; |
| 528 | info->fb = fbinfo; |
| 529 | info->dev = &pdev->dev; |
| 530 | |
| 531 | platform_set_drvdata(pdev, fbinfo); |
| 532 | |
| 533 | strcpy(fbinfo->fix.id, driver_name); |
| 534 | |
| 535 | info->mach_info = pdev->dev.platform_data; |
| 536 | |
| 537 | if (info->mach_info == NULL) { |
| 538 | dev_err(&pdev->dev, |
| 539 | "no platform data for lcd, cannot attach\n"); |
| 540 | ret = -EINVAL; |
| 541 | goto out3; |
| 542 | } |
| 543 | |
| 544 | fbinfo->fix.type = FB_TYPE_PACKED_PIXELS; |
| 545 | fbinfo->fix.type_aux = 0; |
| 546 | fbinfo->fix.xpanstep = 0; |
| 547 | fbinfo->fix.ypanstep = 0; |
| 548 | fbinfo->fix.ywrapstep = 0; |
| 549 | fbinfo->fix.accel = FB_ACCEL_NONE; |
| 550 | fbinfo->fix.visual = FB_VISUAL_TRUECOLOR; |
| 551 | |
| 552 | fbinfo->var.nonstd = 0; |
| 553 | fbinfo->var.activate = FB_ACTIVATE_NOW; |
| 554 | fbinfo->var.height = info->mach_info->height; |
| 555 | fbinfo->var.width = info->mach_info->width; |
| 556 | fbinfo->var.accel_flags = 0; |
| 557 | fbinfo->var.vmode = FB_VMODE_NONINTERLACED; |
| 558 | |
| 559 | fbinfo->fbops = &bfin_bf54x_fb_ops; |
| 560 | fbinfo->flags = FBINFO_FLAG_DEFAULT; |
| 561 | |
| 562 | fbinfo->var.xres = info->mach_info->xres.defval; |
| 563 | fbinfo->var.xres_virtual = info->mach_info->xres.defval; |
| 564 | fbinfo->var.yres = info->mach_info->yres.defval; |
| 565 | fbinfo->var.yres_virtual = info->mach_info->yres.defval; |
| 566 | fbinfo->var.bits_per_pixel = info->mach_info->bpp.defval; |
| 567 | |
| 568 | fbinfo->var.upper_margin = 0; |
| 569 | fbinfo->var.lower_margin = 0; |
| 570 | fbinfo->var.vsync_len = 0; |
| 571 | |
| 572 | fbinfo->var.left_margin = 0; |
| 573 | fbinfo->var.right_margin = 0; |
| 574 | fbinfo->var.hsync_len = 0; |
| 575 | |
| 576 | fbinfo->var.red.offset = 16; |
| 577 | fbinfo->var.green.offset = 8; |
| 578 | fbinfo->var.blue.offset = 0; |
| 579 | fbinfo->var.transp.offset = 0; |
| 580 | fbinfo->var.red.length = 8; |
| 581 | fbinfo->var.green.length = 8; |
| 582 | fbinfo->var.blue.length = 8; |
| 583 | fbinfo->var.transp.length = 0; |
| 584 | fbinfo->fix.smem_len = info->mach_info->xres.max * |
| 585 | info->mach_info->yres.max * info->mach_info->bpp.max / 8; |
| 586 | |
| 587 | fbinfo->fix.line_length = fbinfo->var.xres_virtual * |
| 588 | fbinfo->var.bits_per_pixel / 8; |
| 589 | |
| 590 | info->fb_buffer = |
| 591 | dma_alloc_coherent(NULL, fbinfo->fix.smem_len, &info->dma_handle, |
| 592 | GFP_KERNEL); |
| 593 | |
| 594 | if (NULL == info->fb_buffer) { |
| 595 | printk(KERN_ERR DRIVER_NAME |
| 596 | ": couldn't allocate dma buffer.\n"); |
| 597 | ret = -ENOMEM; |
| 598 | goto out3; |
| 599 | } |
| 600 | |
Michael Hennerich | e9fa7c4 | 2007-10-16 01:29:38 -0700 | [diff] [blame] | 601 | fbinfo->screen_base = (void *)info->fb_buffer; |
| 602 | fbinfo->fix.smem_start = (int)info->fb_buffer; |
| 603 | |
| 604 | fbinfo->fbops = &bfin_bf54x_fb_ops; |
| 605 | |
Mike Frysinger | a34601c | 2009-06-16 15:34:43 -0700 | [diff] [blame] | 606 | fbinfo->pseudo_palette = kzalloc(sizeof(u32) * 16, GFP_KERNEL); |
Michael Hennerich | e9fa7c4 | 2007-10-16 01:29:38 -0700 | [diff] [blame] | 607 | if (!fbinfo->pseudo_palette) { |
| 608 | printk(KERN_ERR DRIVER_NAME |
| 609 | "Fail to allocate pseudo_palette\n"); |
| 610 | |
| 611 | ret = -ENOMEM; |
| 612 | goto out4; |
| 613 | } |
| 614 | |
Michael Hennerich | e9fa7c4 | 2007-10-16 01:29:38 -0700 | [diff] [blame] | 615 | if (fb_alloc_cmap(&fbinfo->cmap, BFIN_LCD_NBR_PALETTE_ENTRIES, 0) |
| 616 | < 0) { |
| 617 | printk(KERN_ERR DRIVER_NAME |
| 618 | "Fail to allocate colormap (%d entries)\n", |
| 619 | BFIN_LCD_NBR_PALETTE_ENTRIES); |
| 620 | ret = -EFAULT; |
| 621 | goto out5; |
| 622 | } |
| 623 | |
| 624 | if (request_ports(info)) { |
| 625 | printk(KERN_ERR DRIVER_NAME ": couldn't request gpio port.\n"); |
| 626 | ret = -EFAULT; |
| 627 | goto out6; |
| 628 | } |
| 629 | |
| 630 | info->irq = platform_get_irq(pdev, 0); |
| 631 | if (info->irq < 0) { |
| 632 | ret = -EINVAL; |
| 633 | goto out7; |
| 634 | } |
| 635 | |
Mike Frysinger | 6002db8 | 2008-04-28 02:15:46 -0700 | [diff] [blame] | 636 | if (request_irq(info->irq, bfin_bf54x_irq_error, IRQF_DISABLED, |
Michael Hennerich | e9fa7c4 | 2007-10-16 01:29:38 -0700 | [diff] [blame] | 637 | "PPI ERROR", info) < 0) { |
| 638 | printk(KERN_ERR DRIVER_NAME |
| 639 | ": unable to request PPI ERROR IRQ\n"); |
| 640 | ret = -EFAULT; |
| 641 | goto out7; |
| 642 | } |
| 643 | |
| 644 | if (register_framebuffer(fbinfo) < 0) { |
| 645 | printk(KERN_ERR DRIVER_NAME |
| 646 | ": unable to register framebuffer.\n"); |
| 647 | ret = -EINVAL; |
| 648 | goto out8; |
| 649 | } |
| 650 | #ifndef NO_BL_SUPPORT |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 651 | memset(&props, 0, sizeof(struct backlight_properties)); |
Matthew Garrett | bb7ca74 | 2011-03-22 16:30:21 -0700 | [diff] [blame] | 652 | props.type = BACKLIGHT_RAW; |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 653 | props.max_brightness = 255; |
| 654 | bl_dev = backlight_device_register("bf54x-bl", NULL, NULL, |
| 655 | &bfin_lq043fb_bl_ops, &props); |
Bruno Prémont | fa11de0 | 2010-02-26 13:04:54 +0100 | [diff] [blame] | 656 | if (IS_ERR(bl_dev)) { |
| 657 | printk(KERN_ERR DRIVER_NAME |
| 658 | ": unable to register backlight.\n"); |
| 659 | ret = -EINVAL; |
Mike Frysinger | 8fc809d | 2010-05-26 14:42:31 -0700 | [diff] [blame] | 660 | unregister_framebuffer(fbinfo); |
| 661 | goto out8; |
Bruno Prémont | fa11de0 | 2010-02-26 13:04:54 +0100 | [diff] [blame] | 662 | } |
Michael Hennerich | e9fa7c4 | 2007-10-16 01:29:38 -0700 | [diff] [blame] | 663 | |
Bryan Wu | b3544ea | 2008-03-10 11:44:03 -0700 | [diff] [blame] | 664 | lcd_dev = lcd_device_register(DRIVER_NAME, &pdev->dev, NULL, &bfin_lcd_ops); |
Michael Hennerich | e9fa7c4 | 2007-10-16 01:29:38 -0700 | [diff] [blame] | 665 | lcd_dev->props.max_contrast = 255, printk(KERN_INFO "Done.\n"); |
| 666 | #endif |
| 667 | |
| 668 | return 0; |
| 669 | |
| 670 | out8: |
| 671 | free_irq(info->irq, info); |
| 672 | out7: |
| 673 | free_ports(info); |
| 674 | out6: |
| 675 | fb_dealloc_cmap(&fbinfo->cmap); |
| 676 | out5: |
| 677 | kfree(fbinfo->pseudo_palette); |
| 678 | out4: |
| 679 | dma_free_coherent(NULL, fbinfo->fix.smem_len, info->fb_buffer, |
| 680 | info->dma_handle); |
| 681 | out3: |
| 682 | framebuffer_release(fbinfo); |
| 683 | out2: |
| 684 | free_dma(CH_EPPI0); |
| 685 | out1: |
| 686 | platform_set_drvdata(pdev, NULL); |
| 687 | |
| 688 | return ret; |
| 689 | } |
| 690 | |
Mike Frysinger | 8f09d74 | 2009-06-16 15:34:42 -0700 | [diff] [blame] | 691 | static int __devexit bfin_bf54x_remove(struct platform_device *pdev) |
Michael Hennerich | e9fa7c4 | 2007-10-16 01:29:38 -0700 | [diff] [blame] | 692 | { |
| 693 | |
| 694 | struct fb_info *fbinfo = platform_get_drvdata(pdev); |
| 695 | struct bfin_bf54xfb_info *info = fbinfo->par; |
| 696 | |
| 697 | free_dma(CH_EPPI0); |
| 698 | free_irq(info->irq, info); |
| 699 | |
| 700 | if (info->fb_buffer != NULL) |
| 701 | dma_free_coherent(NULL, fbinfo->fix.smem_len, info->fb_buffer, |
| 702 | info->dma_handle); |
| 703 | |
| 704 | kfree(fbinfo->pseudo_palette); |
| 705 | fb_dealloc_cmap(&fbinfo->cmap); |
| 706 | |
| 707 | #ifndef NO_BL_SUPPORT |
| 708 | lcd_device_unregister(lcd_dev); |
| 709 | backlight_device_unregister(bl_dev); |
| 710 | #endif |
| 711 | |
| 712 | unregister_framebuffer(fbinfo); |
| 713 | |
| 714 | free_ports(info); |
| 715 | |
| 716 | printk(KERN_INFO DRIVER_NAME ": Unregister LCD driver.\n"); |
| 717 | |
| 718 | return 0; |
| 719 | } |
| 720 | |
| 721 | #ifdef CONFIG_PM |
| 722 | static int bfin_bf54x_suspend(struct platform_device *pdev, pm_message_t state) |
| 723 | { |
| 724 | struct fb_info *fbinfo = platform_get_drvdata(pdev); |
Michael Hennerich | e9fa7c4 | 2007-10-16 01:29:38 -0700 | [diff] [blame] | 725 | |
| 726 | bfin_write_EPPI0_CONTROL(bfin_read_EPPI0_CONTROL() & ~EPPI_EN); |
| 727 | disable_dma(CH_EPPI0); |
| 728 | bfin_write_EPPI0_STATUS(0xFFFF); |
| 729 | |
| 730 | return 0; |
| 731 | } |
| 732 | |
| 733 | static int bfin_bf54x_resume(struct platform_device *pdev) |
| 734 | { |
| 735 | struct fb_info *fbinfo = platform_get_drvdata(pdev); |
| 736 | struct bfin_bf54xfb_info *info = fbinfo->par; |
| 737 | |
Michael Hennerich | 141d87e | 2008-08-20 14:09:16 -0700 | [diff] [blame] | 738 | if (info->lq043_open_cnt) { |
| 739 | |
| 740 | bfin_write_EPPI0_CONTROL(0); |
| 741 | SSYNC(); |
| 742 | |
| 743 | config_dma(info); |
| 744 | config_ppi(info); |
| 745 | |
| 746 | /* start dma */ |
| 747 | enable_dma(CH_EPPI0); |
| 748 | bfin_write_EPPI0_CONTROL(bfin_read_EPPI0_CONTROL() | EPPI_EN); |
| 749 | } |
Michael Hennerich | e9fa7c4 | 2007-10-16 01:29:38 -0700 | [diff] [blame] | 750 | |
| 751 | return 0; |
| 752 | } |
| 753 | #else |
| 754 | #define bfin_bf54x_suspend NULL |
| 755 | #define bfin_bf54x_resume NULL |
| 756 | #endif |
| 757 | |
| 758 | static struct platform_driver bfin_bf54x_driver = { |
| 759 | .probe = bfin_bf54x_probe, |
Mike Frysinger | 8f09d74 | 2009-06-16 15:34:42 -0700 | [diff] [blame] | 760 | .remove = __devexit_p(bfin_bf54x_remove), |
Michael Hennerich | e9fa7c4 | 2007-10-16 01:29:38 -0700 | [diff] [blame] | 761 | .suspend = bfin_bf54x_suspend, |
| 762 | .resume = bfin_bf54x_resume, |
| 763 | .driver = { |
| 764 | .name = DRIVER_NAME, |
| 765 | .owner = THIS_MODULE, |
| 766 | }, |
| 767 | }; |
| 768 | |
Mike Frysinger | 8f09d74 | 2009-06-16 15:34:42 -0700 | [diff] [blame] | 769 | static int __init bfin_bf54x_driver_init(void) |
Michael Hennerich | e9fa7c4 | 2007-10-16 01:29:38 -0700 | [diff] [blame] | 770 | { |
| 771 | return platform_driver_register(&bfin_bf54x_driver); |
| 772 | } |
| 773 | |
| 774 | static void __exit bfin_bf54x_driver_cleanup(void) |
| 775 | { |
| 776 | platform_driver_unregister(&bfin_bf54x_driver); |
| 777 | } |
| 778 | |
| 779 | MODULE_DESCRIPTION("Blackfin BF54x TFT LCD Driver"); |
| 780 | MODULE_LICENSE("GPL"); |
| 781 | |
| 782 | module_init(bfin_bf54x_driver_init); |
| 783 | module_exit(bfin_bf54x_driver_cleanup); |