diff options
author | Michael Hennerich <michael.hennerich@analog.com> | 2007-10-16 04:29:38 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-10-16 12:43:20 -0400 |
commit | e9fa7c43aa74fae3a1db04092d2a51005f5b8a21 (patch) | |
tree | b03e1416a58d490e5029df6baf05d47dce6ccd3c /drivers/video/bf54x-lq043fb.c | |
parent | accaa24c492f1aa3b9c37226d868dc59c3007531 (diff) |
bf54x-lq043fb: framebuffer driver for Blackfin BF54x framebuffer device driver
Blackfin BF54x framebuffer device driver for a SHARP LQ043T1DG01 TFT LCD
[adaplas]
Add 'fb' suffix to driver name.
Move Makefile entry under platform device section
Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
Signed-off-by: Bryan Wu <bryan.wu@analog.com>
Signed-off-by: Antonino Daplas <adaplas@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/video/bf54x-lq043fb.c')
-rw-r--r-- | drivers/video/bf54x-lq043fb.c | 786 |
1 files changed, 786 insertions, 0 deletions
diff --git a/drivers/video/bf54x-lq043fb.c b/drivers/video/bf54x-lq043fb.c new file mode 100644 index 000000000000..74d11c318987 --- /dev/null +++ b/drivers/video/bf54x-lq043fb.c | |||
@@ -0,0 +1,786 @@ | |||
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: | ||
11 | * Copyright 2004-2007 Analog Devices Inc. | ||
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 | |||
61 | #include <asm/mach/bf54x-lq043.h> | ||
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; | ||
85 | int lq043_mmap; | ||
86 | int lq043_open_cnt; | ||
87 | int irq; | ||
88 | spinlock_t lock; /* lock */ | ||
89 | }; | ||
90 | |||
91 | static int nocursor; | ||
92 | module_param(nocursor, int, 0644); | ||
93 | MODULE_PARM_DESC(nocursor, "cursor enable/disable"); | ||
94 | |||
95 | static int outp_rgb666; | ||
96 | module_param(outp_rgb666, int, 0); | ||
97 | MODULE_PARM_DESC(outp_rgb666, "Output 18-bit RGB666"); | ||
98 | |||
99 | #define LCD_X_RES 480 /*Horizontal Resolution */ | ||
100 | #define LCD_Y_RES 272 /* Vertical Resolution */ | ||
101 | |||
102 | #define LCD_BPP 24 /* Bit Per Pixel */ | ||
103 | #define DMA_BUS_SIZE 32 | ||
104 | |||
105 | /* -- Horizontal synchronizing -- | ||
106 | * | ||
107 | * Timing characteristics taken from the SHARP LQ043T1DG01 datasheet | ||
108 | * (LCY-W-06602A Page 9 of 22) | ||
109 | * | ||
110 | * Clock Frequency 1/Tc Min 7.83 Typ 9.00 Max 9.26 MHz | ||
111 | * | ||
112 | * Period TH - 525 - Clock | ||
113 | * Pulse width THp - 41 - Clock | ||
114 | * Horizontal period THd - 480 - Clock | ||
115 | * Back porch THb - 2 - Clock | ||
116 | * Front porch THf - 2 - Clock | ||
117 | * | ||
118 | * -- Vertical synchronizing -- | ||
119 | * Period TV - 286 - Line | ||
120 | * Pulse width TVp - 10 - Line | ||
121 | * Vertical period TVd - 272 - Line | ||
122 | * Back porch TVb - 2 - Line | ||
123 | * Front porch TVf - 2 - Line | ||
124 | */ | ||
125 | |||
126 | #define LCD_CLK (8*1000*1000) /* 8MHz */ | ||
127 | |||
128 | /* # active data to transfer after Horizontal Delay clock */ | ||
129 | #define EPPI_HCOUNT LCD_X_RES | ||
130 | |||
131 | /* # active lines to transfer after Vertical Delay clock */ | ||
132 | #define EPPI_VCOUNT LCD_Y_RES | ||
133 | |||
134 | /* Samples per Line = 480 (active data) + 45 (padding) */ | ||
135 | #define EPPI_LINE 525 | ||
136 | |||
137 | /* Lines per Frame = 272 (active data) + 14 (padding) */ | ||
138 | #define EPPI_FRAME 286 | ||
139 | |||
140 | /* FS1 (Hsync) Width (Typical)*/ | ||
141 | #define EPPI_FS1W_HBL 41 | ||
142 | |||
143 | /* FS1 (Hsync) Period (Typical) */ | ||
144 | #define EPPI_FS1P_AVPL EPPI_LINE | ||
145 | |||
146 | /* Horizontal Delay clock after assertion of Hsync (Typical) */ | ||
147 | #define EPPI_HDELAY 43 | ||
148 | |||
149 | /* FS2 (Vsync) Width = FS1 (Hsync) Period * 10 */ | ||
150 | #define EPPI_FS2W_LVB (EPPI_LINE * 10) | ||
151 | |||
152 | /* FS2 (Vsync) Period = FS1 (Hsync) Period * Lines per Frame */ | ||
153 | #define EPPI_FS2P_LAVF (EPPI_LINE * EPPI_FRAME) | ||
154 | |||
155 | /* Vertical Delay after assertion of Vsync (2 Lines) */ | ||
156 | #define EPPI_VDELAY 12 | ||
157 | |||
158 | #define EPPI_CLIP 0xFF00FF00 | ||
159 | |||
160 | /* EPPI Control register configuration value for RGB out | ||
161 | * - EPPI as Output | ||
162 | * GP 2 frame sync mode, | ||
163 | * Internal Clock generation disabled, Internal FS generation enabled, | ||
164 | * Receives samples on EPPI_CLK raising edge, Transmits samples on EPPI_CLK falling edge, | ||
165 | * FS1 & FS2 are active high, | ||
166 | * DLEN = 6 (24 bits for RGB888 out) or 5 (18 bits for RGB666 out) | ||
167 | * DMA Unpacking disabled when RGB Formating is enabled, otherwise DMA unpacking enabled | ||
168 | * Swapping Enabled, | ||
169 | * One (DMA) Channel Mode, | ||
170 | * RGB Formatting Enabled for RGB666 output, disabled for RGB888 output | ||
171 | * Regular watermark - when FIFO is 100% full, | ||
172 | * Urgent watermark - when FIFO is 75% full | ||
173 | */ | ||
174 | |||
175 | #define EPPI_CONTROL (0x20136E2E | SWAPEN) | ||
176 | |||
177 | static inline u16 get_eppi_clkdiv(u32 target_ppi_clk) | ||
178 | { | ||
179 | u32 sclk = get_sclk(); | ||
180 | |||
181 | /* EPPI_CLK = (SCLK) / (2 * (EPPI_CLKDIV[15:0] + 1)) */ | ||
182 | |||
183 | return (((sclk / target_ppi_clk) / 2) - 1); | ||
184 | } | ||
185 | |||
186 | static void config_ppi(struct bfin_bf54xfb_info *fbi) | ||
187 | { | ||
188 | |||
189 | u16 eppi_clkdiv = get_eppi_clkdiv(LCD_CLK); | ||
190 | |||
191 | bfin_write_EPPI0_FS1W_HBL(EPPI_FS1W_HBL); | ||
192 | bfin_write_EPPI0_FS1P_AVPL(EPPI_FS1P_AVPL); | ||
193 | bfin_write_EPPI0_FS2W_LVB(EPPI_FS2W_LVB); | ||
194 | bfin_write_EPPI0_FS2P_LAVF(EPPI_FS2P_LAVF); | ||
195 | bfin_write_EPPI0_CLIP(EPPI_CLIP); | ||
196 | |||
197 | bfin_write_EPPI0_FRAME(EPPI_FRAME); | ||
198 | bfin_write_EPPI0_LINE(EPPI_LINE); | ||
199 | |||
200 | bfin_write_EPPI0_HCOUNT(EPPI_HCOUNT); | ||
201 | bfin_write_EPPI0_HDELAY(EPPI_HDELAY); | ||
202 | bfin_write_EPPI0_VCOUNT(EPPI_VCOUNT); | ||
203 | bfin_write_EPPI0_VDELAY(EPPI_VDELAY); | ||
204 | |||
205 | bfin_write_EPPI0_CLKDIV(eppi_clkdiv); | ||
206 | |||
207 | /* | ||
208 | * DLEN = 6 (24 bits for RGB888 out) or 5 (18 bits for RGB666 out) | ||
209 | * RGB Formatting Enabled for RGB666 output, disabled for RGB888 output | ||
210 | */ | ||
211 | if (outp_rgb666) | ||
212 | bfin_write_EPPI0_CONTROL((EPPI_CONTROL & ~DLENGTH) | DLEN_18 | | ||
213 | RGB_FMT_EN); | ||
214 | else | ||
215 | bfin_write_EPPI0_CONTROL(((EPPI_CONTROL & ~DLENGTH) | DLEN_24) & | ||
216 | ~RGB_FMT_EN); | ||
217 | |||
218 | |||
219 | } | ||
220 | |||
221 | static int config_dma(struct bfin_bf54xfb_info *fbi) | ||
222 | { | ||
223 | |||
224 | set_dma_config(CH_EPPI0, | ||
225 | set_bfin_dma_config(DIR_READ, DMA_FLOW_AUTO, | ||
226 | INTR_DISABLE, DIMENSION_2D, | ||
227 | DATA_SIZE_32)); | ||
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 | |||
243 | if (gpio_request(disp, NULL)) { | ||
244 | printk(KERN_ERR "Requesting GPIO %d faild\n", disp); | ||
245 | return -EFAULT; | ||
246 | } | ||
247 | |||
248 | if (peripheral_request_list(eppi_req_18, DRIVER_NAME)) { | ||
249 | printk(KERN_ERR "Requesting Peripherals faild\n"); | ||
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)) { | ||
259 | printk(KERN_ERR "Requesting Peripherals faild\n"); | ||
260 | peripheral_free_list(eppi_req_18); | ||
261 | gpio_free(disp); | ||
262 | return -EFAULT; | ||
263 | } | ||
264 | } | ||
265 | |||
266 | gpio_direction_output(disp); | ||
267 | gpio_set_value(disp, 1); | ||
268 | |||
269 | return 0; | ||
270 | } | ||
271 | |||
272 | static void free_ports(struct bfin_bf54xfb_info *fbi) | ||
273 | { | ||
274 | |||
275 | u16 eppi_req_18[] = EPPI0_18; | ||
276 | |||
277 | gpio_free(fbi->mach_info->disp); | ||
278 | |||
279 | peripheral_free_list(eppi_req_18); | ||
280 | |||
281 | if (!outp_rgb666) { | ||
282 | u16 eppi_req_24[] = EPPI0_24; | ||
283 | peripheral_free_list(eppi_req_24); | ||
284 | } | ||
285 | } | ||
286 | |||
287 | static int bfin_bf54x_fb_open(struct fb_info *info, int user) | ||
288 | { | ||
289 | struct bfin_bf54xfb_info *fbi = info->par; | ||
290 | |||
291 | spin_lock(&fbi->lock); | ||
292 | fbi->lq043_open_cnt++; | ||
293 | |||
294 | if (fbi->lq043_open_cnt <= 1) { | ||
295 | |||
296 | bfin_write_EPPI0_CONTROL(0); | ||
297 | SSYNC(); | ||
298 | |||
299 | config_dma(fbi); | ||
300 | config_ppi(fbi); | ||
301 | |||
302 | /* start dma */ | ||
303 | enable_dma(CH_EPPI0); | ||
304 | bfin_write_EPPI0_CONTROL(bfin_read_EPPI0_CONTROL() | EPPI_EN); | ||
305 | } | ||
306 | |||
307 | spin_unlock(&fbi->lock); | ||
308 | |||
309 | return 0; | ||
310 | } | ||
311 | |||
312 | static int bfin_bf54x_fb_release(struct fb_info *info, int user) | ||
313 | { | ||
314 | struct bfin_bf54xfb_info *fbi = info->par; | ||
315 | |||
316 | spin_lock(&fbi->lock); | ||
317 | |||
318 | fbi->lq043_open_cnt--; | ||
319 | fbi->lq043_mmap = 0; | ||
320 | |||
321 | if (fbi->lq043_open_cnt <= 0) { | ||
322 | |||
323 | bfin_write_EPPI0_CONTROL(0); | ||
324 | SSYNC(); | ||
325 | disable_dma(CH_EPPI0); | ||
326 | memset(fbi->fb_buffer, 0, info->fix.smem_len); | ||
327 | } | ||
328 | |||
329 | spin_unlock(&fbi->lock); | ||
330 | |||
331 | return 0; | ||
332 | } | ||
333 | |||
334 | static int bfin_bf54x_fb_check_var(struct fb_var_screeninfo *var, | ||
335 | struct fb_info *info) | ||
336 | { | ||
337 | |||
338 | if (var->bits_per_pixel != LCD_BPP) { | ||
339 | pr_debug("%s: depth not supported: %u BPP\n", __FUNCTION__, | ||
340 | var->bits_per_pixel); | ||
341 | return -EINVAL; | ||
342 | } | ||
343 | |||
344 | if (info->var.xres != var->xres || info->var.yres != var->yres || | ||
345 | info->var.xres_virtual != var->xres_virtual || | ||
346 | info->var.yres_virtual != var->yres_virtual) { | ||
347 | pr_debug("%s: Resolution not supported: X%u x Y%u \n", | ||
348 | __FUNCTION__, var->xres, var->yres); | ||
349 | return -EINVAL; | ||
350 | } | ||
351 | |||
352 | /* | ||
353 | * Memory limit | ||
354 | */ | ||
355 | |||
356 | if ((info->fix.line_length * var->yres_virtual) > info->fix.smem_len) { | ||
357 | pr_debug("%s: Memory Limit requested yres_virtual = %u\n", | ||
358 | __FUNCTION__, var->yres_virtual); | ||
359 | return -ENOMEM; | ||
360 | } | ||
361 | |||
362 | return 0; | ||
363 | } | ||
364 | |||
365 | static int bfin_bf54x_fb_mmap(struct fb_info *info, struct vm_area_struct *vma) | ||
366 | { | ||
367 | |||
368 | struct bfin_bf54xfb_info *fbi = info->par; | ||
369 | |||
370 | if (fbi->lq043_mmap) | ||
371 | return -1; | ||
372 | |||
373 | spin_lock(&fbi->lock); | ||
374 | fbi->lq043_mmap = 1; | ||
375 | spin_unlock(&fbi->lock); | ||
376 | |||
377 | vma->vm_start = (unsigned long)(fbi->fb_buffer); | ||
378 | |||
379 | vma->vm_end = vma->vm_start + info->fix.smem_len; | ||
380 | /* For those who don't understand how mmap works, go read | ||
381 | * Documentation/nommu-mmap.txt. | ||
382 | * For those that do, you will know that the VM_MAYSHARE flag | ||
383 | * must be set in the vma->vm_flags structure on noMMU | ||
384 | * Other flags can be set, and are documented in | ||
385 | * include/linux/mm.h | ||
386 | */ | ||
387 | vma->vm_flags |= VM_MAYSHARE; | ||
388 | |||
389 | return 0; | ||
390 | } | ||
391 | |||
392 | int bfin_bf54x_fb_cursor(struct fb_info *info, struct fb_cursor *cursor) | ||
393 | { | ||
394 | if (nocursor) | ||
395 | return 0; | ||
396 | else | ||
397 | return -EINVAL; /* just to force soft_cursor() call */ | ||
398 | } | ||
399 | |||
400 | static int bfin_bf54x_fb_setcolreg(u_int regno, u_int red, u_int green, | ||
401 | u_int blue, u_int transp, | ||
402 | struct fb_info *info) | ||
403 | { | ||
404 | if (regno >= BFIN_LCD_NBR_PALETTE_ENTRIES) | ||
405 | return -EINVAL; | ||
406 | |||
407 | if (info->var.grayscale) { | ||
408 | /* grayscale = 0.30*R + 0.59*G + 0.11*B */ | ||
409 | red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8; | ||
410 | } | ||
411 | |||
412 | if (info->fix.visual == FB_VISUAL_TRUECOLOR) { | ||
413 | |||
414 | u32 value; | ||
415 | /* Place color in the pseudopalette */ | ||
416 | if (regno > 16) | ||
417 | return -EINVAL; | ||
418 | |||
419 | red >>= (16 - info->var.red.length); | ||
420 | green >>= (16 - info->var.green.length); | ||
421 | blue >>= (16 - info->var.blue.length); | ||
422 | |||
423 | value = (red << info->var.red.offset) | | ||
424 | (green << info->var.green.offset) | | ||
425 | (blue << info->var.blue.offset); | ||
426 | value &= 0xFFFFFF; | ||
427 | |||
428 | ((u32 *) (info->pseudo_palette))[regno] = value; | ||
429 | |||
430 | } | ||
431 | |||
432 | return 0; | ||
433 | } | ||
434 | |||
435 | static struct fb_ops bfin_bf54x_fb_ops = { | ||
436 | .owner = THIS_MODULE, | ||
437 | .fb_open = bfin_bf54x_fb_open, | ||
438 | .fb_release = bfin_bf54x_fb_release, | ||
439 | .fb_check_var = bfin_bf54x_fb_check_var, | ||
440 | .fb_fillrect = cfb_fillrect, | ||
441 | .fb_copyarea = cfb_copyarea, | ||
442 | .fb_imageblit = cfb_imageblit, | ||
443 | .fb_mmap = bfin_bf54x_fb_mmap, | ||
444 | .fb_cursor = bfin_bf54x_fb_cursor, | ||
445 | .fb_setcolreg = bfin_bf54x_fb_setcolreg, | ||
446 | }; | ||
447 | |||
448 | #ifndef NO_BL_SUPPORT | ||
449 | static int bl_get_brightness(struct backlight_device *bd) | ||
450 | { | ||
451 | return 0; | ||
452 | } | ||
453 | |||
454 | static struct backlight_ops bfin_lq043fb_bl_ops = { | ||
455 | .get_brightness = bl_get_brightness, | ||
456 | }; | ||
457 | |||
458 | static struct backlight_device *bl_dev; | ||
459 | |||
460 | static int bfin_lcd_get_power(struct lcd_device *dev) | ||
461 | { | ||
462 | return 0; | ||
463 | } | ||
464 | |||
465 | static int bfin_lcd_set_power(struct lcd_device *dev, int power) | ||
466 | { | ||
467 | return 0; | ||
468 | } | ||
469 | |||
470 | static int bfin_lcd_get_contrast(struct lcd_device *dev) | ||
471 | { | ||
472 | return 0; | ||
473 | } | ||
474 | |||
475 | static int bfin_lcd_set_contrast(struct lcd_device *dev, int contrast) | ||
476 | { | ||
477 | |||
478 | return 0; | ||
479 | } | ||
480 | |||
481 | static int bfin_lcd_check_fb(struct fb_info *fi) | ||
482 | { | ||
483 | if (!fi || (fi == &bfin_bf54x_fb)) | ||
484 | return 1; | ||
485 | return 0; | ||
486 | } | ||
487 | |||
488 | static struct lcd_ops bfin_lcd_ops = { | ||
489 | .get_power = bfin_lcd_get_power, | ||
490 | .set_power = bfin_lcd_set_power, | ||
491 | .get_contrast = bfin_lcd_get_contrast, | ||
492 | .set_contrast = bfin_lcd_set_contrast, | ||
493 | .check_fb = bfin_lcd_check_fb, | ||
494 | }; | ||
495 | |||
496 | static struct lcd_device *lcd_dev; | ||
497 | #endif | ||
498 | |||
499 | static irqreturn_t bfin_bf54x_irq_error(int irq, void *dev_id) | ||
500 | { | ||
501 | |||
502 | /*struct bfin_bf54xfb_info *info = (struct bfin_bf54xfb_info *)dev_id;*/ | ||
503 | |||
504 | u16 status = bfin_read_EPPI0_STATUS(); | ||
505 | |||
506 | bfin_write_EPPI0_STATUS(0xFFFF); | ||
507 | |||
508 | if (status) { | ||
509 | bfin_write_EPPI0_CONTROL(bfin_read_EPPI0_CONTROL() & ~EPPI_EN); | ||
510 | disable_dma(CH_EPPI0); | ||
511 | |||
512 | /* start dma */ | ||
513 | enable_dma(CH_EPPI0); | ||
514 | bfin_write_EPPI0_CONTROL(bfin_read_EPPI0_CONTROL() | EPPI_EN); | ||
515 | bfin_write_EPPI0_STATUS(0xFFFF); | ||
516 | } | ||
517 | |||
518 | return IRQ_HANDLED; | ||
519 | } | ||
520 | |||
521 | static int __init bfin_bf54x_probe(struct platform_device *pdev) | ||
522 | { | ||
523 | struct bfin_bf54xfb_info *info; | ||
524 | struct fb_info *fbinfo; | ||
525 | int ret; | ||
526 | |||
527 | printk(KERN_INFO DRIVER_NAME ": FrameBuffer initializing...\n"); | ||
528 | |||
529 | if (request_dma(CH_EPPI0, "CH_EPPI0") < 0) { | ||
530 | printk(KERN_ERR DRIVER_NAME | ||
531 | ": couldn't request CH_EPPI0 DMA\n"); | ||
532 | ret = -EFAULT; | ||
533 | goto out1; | ||
534 | } | ||
535 | |||
536 | fbinfo = | ||
537 | framebuffer_alloc(sizeof(struct bfin_bf54xfb_info), &pdev->dev); | ||
538 | if (!fbinfo) { | ||
539 | ret = -ENOMEM; | ||
540 | goto out2; | ||
541 | } | ||
542 | |||
543 | info = fbinfo->par; | ||
544 | info->fb = fbinfo; | ||
545 | info->dev = &pdev->dev; | ||
546 | |||
547 | platform_set_drvdata(pdev, fbinfo); | ||
548 | |||
549 | strcpy(fbinfo->fix.id, driver_name); | ||
550 | |||
551 | info->mach_info = pdev->dev.platform_data; | ||
552 | |||
553 | if (info->mach_info == NULL) { | ||
554 | dev_err(&pdev->dev, | ||
555 | "no platform data for lcd, cannot attach\n"); | ||
556 | ret = -EINVAL; | ||
557 | goto out3; | ||
558 | } | ||
559 | |||
560 | fbinfo->fix.type = FB_TYPE_PACKED_PIXELS; | ||
561 | fbinfo->fix.type_aux = 0; | ||
562 | fbinfo->fix.xpanstep = 0; | ||
563 | fbinfo->fix.ypanstep = 0; | ||
564 | fbinfo->fix.ywrapstep = 0; | ||
565 | fbinfo->fix.accel = FB_ACCEL_NONE; | ||
566 | fbinfo->fix.visual = FB_VISUAL_TRUECOLOR; | ||
567 | |||
568 | fbinfo->var.nonstd = 0; | ||
569 | fbinfo->var.activate = FB_ACTIVATE_NOW; | ||
570 | fbinfo->var.height = info->mach_info->height; | ||
571 | fbinfo->var.width = info->mach_info->width; | ||
572 | fbinfo->var.accel_flags = 0; | ||
573 | fbinfo->var.vmode = FB_VMODE_NONINTERLACED; | ||
574 | |||
575 | fbinfo->fbops = &bfin_bf54x_fb_ops; | ||
576 | fbinfo->flags = FBINFO_FLAG_DEFAULT; | ||
577 | |||
578 | fbinfo->var.xres = info->mach_info->xres.defval; | ||
579 | fbinfo->var.xres_virtual = info->mach_info->xres.defval; | ||
580 | fbinfo->var.yres = info->mach_info->yres.defval; | ||
581 | fbinfo->var.yres_virtual = info->mach_info->yres.defval; | ||
582 | fbinfo->var.bits_per_pixel = info->mach_info->bpp.defval; | ||
583 | |||
584 | fbinfo->var.upper_margin = 0; | ||
585 | fbinfo->var.lower_margin = 0; | ||
586 | fbinfo->var.vsync_len = 0; | ||
587 | |||
588 | fbinfo->var.left_margin = 0; | ||
589 | fbinfo->var.right_margin = 0; | ||
590 | fbinfo->var.hsync_len = 0; | ||
591 | |||
592 | fbinfo->var.red.offset = 16; | ||
593 | fbinfo->var.green.offset = 8; | ||
594 | fbinfo->var.blue.offset = 0; | ||
595 | fbinfo->var.transp.offset = 0; | ||
596 | fbinfo->var.red.length = 8; | ||
597 | fbinfo->var.green.length = 8; | ||
598 | fbinfo->var.blue.length = 8; | ||
599 | fbinfo->var.transp.length = 0; | ||
600 | fbinfo->fix.smem_len = info->mach_info->xres.max * | ||
601 | info->mach_info->yres.max * info->mach_info->bpp.max / 8; | ||
602 | |||
603 | fbinfo->fix.line_length = fbinfo->var.xres_virtual * | ||
604 | fbinfo->var.bits_per_pixel / 8; | ||
605 | |||
606 | info->fb_buffer = | ||
607 | dma_alloc_coherent(NULL, fbinfo->fix.smem_len, &info->dma_handle, | ||
608 | GFP_KERNEL); | ||
609 | |||
610 | if (NULL == info->fb_buffer) { | ||
611 | printk(KERN_ERR DRIVER_NAME | ||
612 | ": couldn't allocate dma buffer.\n"); | ||
613 | ret = -ENOMEM; | ||
614 | goto out3; | ||
615 | } | ||
616 | |||
617 | memset(info->fb_buffer, 0, fbinfo->fix.smem_len); | ||
618 | |||
619 | fbinfo->screen_base = (void *)info->fb_buffer; | ||
620 | fbinfo->fix.smem_start = (int)info->fb_buffer; | ||
621 | |||
622 | fbinfo->fbops = &bfin_bf54x_fb_ops; | ||
623 | |||
624 | fbinfo->pseudo_palette = kmalloc(sizeof(u32) * 16, GFP_KERNEL); | ||
625 | if (!fbinfo->pseudo_palette) { | ||
626 | printk(KERN_ERR DRIVER_NAME | ||
627 | "Fail to allocate pseudo_palette\n"); | ||
628 | |||
629 | ret = -ENOMEM; | ||
630 | goto out4; | ||
631 | } | ||
632 | |||
633 | memset(fbinfo->pseudo_palette, 0, sizeof(u32) * 16); | ||
634 | |||
635 | if (fb_alloc_cmap(&fbinfo->cmap, BFIN_LCD_NBR_PALETTE_ENTRIES, 0) | ||
636 | < 0) { | ||
637 | printk(KERN_ERR DRIVER_NAME | ||
638 | "Fail to allocate colormap (%d entries)\n", | ||
639 | BFIN_LCD_NBR_PALETTE_ENTRIES); | ||
640 | ret = -EFAULT; | ||
641 | goto out5; | ||
642 | } | ||
643 | |||
644 | if (request_ports(info)) { | ||
645 | printk(KERN_ERR DRIVER_NAME ": couldn't request gpio port.\n"); | ||
646 | ret = -EFAULT; | ||
647 | goto out6; | ||
648 | } | ||
649 | |||
650 | info->irq = platform_get_irq(pdev, 0); | ||
651 | if (info->irq < 0) { | ||
652 | ret = -EINVAL; | ||
653 | goto out7; | ||
654 | } | ||
655 | |||
656 | if (request_irq(info->irq, (void *)bfin_bf54x_irq_error, IRQF_DISABLED, | ||
657 | "PPI ERROR", info) < 0) { | ||
658 | printk(KERN_ERR DRIVER_NAME | ||
659 | ": unable to request PPI ERROR IRQ\n"); | ||
660 | ret = -EFAULT; | ||
661 | goto out7; | ||
662 | } | ||
663 | |||
664 | if (register_framebuffer(fbinfo) < 0) { | ||
665 | printk(KERN_ERR DRIVER_NAME | ||
666 | ": unable to register framebuffer.\n"); | ||
667 | ret = -EINVAL; | ||
668 | goto out8; | ||
669 | } | ||
670 | #ifndef NO_BL_SUPPORT | ||
671 | bl_dev = | ||
672 | backlight_device_register("bf54x-bl", NULL, NULL, | ||
673 | &bfin_lq043fb_bl_ops); | ||
674 | bl_dev->props.max_brightness = 255; | ||
675 | |||
676 | lcd_dev = lcd_device_register(DRIVER_NAME, NULL, &bfin_lcd_ops); | ||
677 | lcd_dev->props.max_contrast = 255, printk(KERN_INFO "Done.\n"); | ||
678 | #endif | ||
679 | |||
680 | return 0; | ||
681 | |||
682 | out8: | ||
683 | free_irq(info->irq, info); | ||
684 | out7: | ||
685 | free_ports(info); | ||
686 | out6: | ||
687 | fb_dealloc_cmap(&fbinfo->cmap); | ||
688 | out5: | ||
689 | kfree(fbinfo->pseudo_palette); | ||
690 | out4: | ||
691 | dma_free_coherent(NULL, fbinfo->fix.smem_len, info->fb_buffer, | ||
692 | info->dma_handle); | ||
693 | out3: | ||
694 | framebuffer_release(fbinfo); | ||
695 | out2: | ||
696 | free_dma(CH_EPPI0); | ||
697 | out1: | ||
698 | platform_set_drvdata(pdev, NULL); | ||
699 | |||
700 | return ret; | ||
701 | } | ||
702 | |||
703 | static int bfin_bf54x_remove(struct platform_device *pdev) | ||
704 | { | ||
705 | |||
706 | struct fb_info *fbinfo = platform_get_drvdata(pdev); | ||
707 | struct bfin_bf54xfb_info *info = fbinfo->par; | ||
708 | |||
709 | free_dma(CH_EPPI0); | ||
710 | free_irq(info->irq, info); | ||
711 | |||
712 | if (info->fb_buffer != NULL) | ||
713 | dma_free_coherent(NULL, fbinfo->fix.smem_len, info->fb_buffer, | ||
714 | info->dma_handle); | ||
715 | |||
716 | kfree(fbinfo->pseudo_palette); | ||
717 | fb_dealloc_cmap(&fbinfo->cmap); | ||
718 | |||
719 | #ifndef NO_BL_SUPPORT | ||
720 | lcd_device_unregister(lcd_dev); | ||
721 | backlight_device_unregister(bl_dev); | ||
722 | #endif | ||
723 | |||
724 | unregister_framebuffer(fbinfo); | ||
725 | |||
726 | free_ports(info); | ||
727 | |||
728 | printk(KERN_INFO DRIVER_NAME ": Unregister LCD driver.\n"); | ||
729 | |||
730 | return 0; | ||
731 | } | ||
732 | |||
733 | #ifdef CONFIG_PM | ||
734 | static int bfin_bf54x_suspend(struct platform_device *pdev, pm_message_t state) | ||
735 | { | ||
736 | struct fb_info *fbinfo = platform_get_drvdata(pdev); | ||
737 | struct bfin_bf54xfb_info *info = fbinfo->par; | ||
738 | |||
739 | bfin_write_EPPI0_CONTROL(bfin_read_EPPI0_CONTROL() & ~EPPI_EN); | ||
740 | disable_dma(CH_EPPI0); | ||
741 | bfin_write_EPPI0_STATUS(0xFFFF); | ||
742 | |||
743 | return 0; | ||
744 | } | ||
745 | |||
746 | static int bfin_bf54x_resume(struct platform_device *pdev) | ||
747 | { | ||
748 | struct fb_info *fbinfo = platform_get_drvdata(pdev); | ||
749 | struct bfin_bf54xfb_info *info = fbinfo->par; | ||
750 | |||
751 | enable_dma(CH_EPPI0); | ||
752 | bfin_write_EPPI0_CONTROL(bfin_read_EPPI0_CONTROL() | EPPI_EN); | ||
753 | |||
754 | return 0; | ||
755 | } | ||
756 | #else | ||
757 | #define bfin_bf54x_suspend NULL | ||
758 | #define bfin_bf54x_resume NULL | ||
759 | #endif | ||
760 | |||
761 | static struct platform_driver bfin_bf54x_driver = { | ||
762 | .probe = bfin_bf54x_probe, | ||
763 | .remove = bfin_bf54x_remove, | ||
764 | .suspend = bfin_bf54x_suspend, | ||
765 | .resume = bfin_bf54x_resume, | ||
766 | .driver = { | ||
767 | .name = DRIVER_NAME, | ||
768 | .owner = THIS_MODULE, | ||
769 | }, | ||
770 | }; | ||
771 | |||
772 | static int __devinit bfin_bf54x_driver_init(void) | ||
773 | { | ||
774 | return platform_driver_register(&bfin_bf54x_driver); | ||
775 | } | ||
776 | |||
777 | static void __exit bfin_bf54x_driver_cleanup(void) | ||
778 | { | ||
779 | platform_driver_unregister(&bfin_bf54x_driver); | ||
780 | } | ||
781 | |||
782 | MODULE_DESCRIPTION("Blackfin BF54x TFT LCD Driver"); | ||
783 | MODULE_LICENSE("GPL"); | ||
784 | |||
785 | module_init(bfin_bf54x_driver_init); | ||
786 | module_exit(bfin_bf54x_driver_cleanup); | ||