Commit | Line | Data |
---|---|---|
99eeed47 MH |
1 | /* |
2 | * File: drivers/video/bfin-t350mcqb-fb.c | |
3 | * Based on: | |
4 | * Author: Michael Hennerich <hennerich@blackfin.uclinux.org> | |
5 | * | |
6 | * Created: | |
7 | * Description: Blackfin LCD 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/fb.h> | |
36 | #include <linux/init.h> | |
37 | #include <linux/types.h> | |
38 | #include <linux/interrupt.h> | |
39 | #include <linux/device.h> | |
40 | #include <linux/backlight.h> | |
41 | #include <linux/lcd.h> | |
42 | #include <linux/dma-mapping.h> | |
43 | #include <linux/platform_device.h> | |
44 | ||
45 | #include <asm/blackfin.h> | |
46 | #include <asm/irq.h> | |
47 | #include <asm/dma-mapping.h> | |
48 | #include <asm/dma.h> | |
49 | #include <asm/portmux.h> | |
50 | #include <asm/gptimers.h> | |
51 | ||
52 | #define NO_BL_SUPPORT | |
53 | ||
54 | #define LCD_X_RES 320 /* Horizontal Resolution */ | |
55 | #define LCD_Y_RES 240 /* Vertical Resolution */ | |
56 | #define LCD_BPP 24 /* Bit Per Pixel */ | |
57 | ||
58 | #define DMA_BUS_SIZE 16 | |
59 | #define LCD_CLK (12*1000*1000) /* 12MHz */ | |
60 | ||
61 | #define CLOCKS_PER_PIX 3 | |
62 | ||
63 | /* | |
64 | * HS and VS timing parameters (all in number of PPI clk ticks) | |
65 | */ | |
66 | ||
67 | #define U_LINE 1 /* Blanking Lines */ | |
68 | ||
69 | #define H_ACTPIX (LCD_X_RES * CLOCKS_PER_PIX) /* active horizontal pixel */ | |
70 | #define H_PERIOD (408 * CLOCKS_PER_PIX) /* HS period */ | |
71 | #define H_PULSE 90 /* HS pulse width */ | |
72 | #define H_START 204 /* first valid pixel */ | |
73 | ||
74 | #define V_LINES (LCD_Y_RES + U_LINE) /* total vertical lines */ | |
75 | #define V_PULSE (3 * H_PERIOD) /* VS pulse width (1-5 H_PERIODs) */ | |
76 | #define V_PERIOD (H_PERIOD * V_LINES) /* VS period */ | |
77 | ||
78 | #define ACTIVE_VIDEO_MEM_OFFSET (U_LINE * H_ACTPIX) | |
79 | ||
80 | #define BFIN_LCD_NBR_PALETTE_ENTRIES 256 | |
81 | ||
82 | #define DRIVER_NAME "bfin-t350mcqb" | |
83 | static char driver_name[] = DRIVER_NAME; | |
84 | ||
85 | struct bfin_t350mcqbfb_info { | |
86 | struct fb_info *fb; | |
87 | struct device *dev; | |
88 | unsigned char *fb_buffer; /* RGB Buffer */ | |
89 | dma_addr_t dma_handle; | |
99eeed47 MH |
90 | int lq043_open_cnt; |
91 | int irq; | |
92 | spinlock_t lock; /* lock */ | |
7ef9861c | 93 | u32 pseudo_pal[16]; |
99eeed47 MH |
94 | }; |
95 | ||
96 | static int nocursor; | |
97 | module_param(nocursor, int, 0644); | |
98 | MODULE_PARM_DESC(nocursor, "cursor enable/disable"); | |
99 | ||
100 | #define PPI_TX_MODE 0x2 | |
101 | #define PPI_XFER_TYPE_11 0xC | |
102 | #define PPI_PORT_CFG_01 0x10 | |
103 | #define PPI_PACK_EN 0x80 | |
104 | #define PPI_POLS_1 0x8000 | |
105 | ||
106 | static void bfin_t350mcqb_config_ppi(struct bfin_t350mcqbfb_info *fbi) | |
107 | { | |
108 | bfin_write_PPI_DELAY(H_START); | |
109 | bfin_write_PPI_COUNT(H_ACTPIX-1); | |
110 | bfin_write_PPI_FRAME(V_LINES); | |
111 | ||
112 | bfin_write_PPI_CONTROL(PPI_TX_MODE | /* output mode , PORT_DIR */ | |
113 | PPI_XFER_TYPE_11 | /* sync mode XFR_TYPE */ | |
114 | PPI_PORT_CFG_01 | /* two frame sync PORT_CFG */ | |
115 | PPI_PACK_EN | /* packing enabled PACK_EN */ | |
116 | PPI_POLS_1); /* faling edge syncs POLS */ | |
117 | } | |
118 | ||
119 | static inline void bfin_t350mcqb_disable_ppi(void) | |
120 | { | |
121 | bfin_write_PPI_CONTROL(bfin_read_PPI_CONTROL() & ~PORT_EN); | |
122 | } | |
123 | ||
124 | static inline void bfin_t350mcqb_enable_ppi(void) | |
125 | { | |
126 | bfin_write_PPI_CONTROL(bfin_read_PPI_CONTROL() | PORT_EN); | |
127 | } | |
128 | ||
129 | static void bfin_t350mcqb_start_timers(void) | |
130 | { | |
131 | unsigned long flags; | |
132 | ||
133 | local_irq_save(flags); | |
134 | enable_gptimers(TIMER1bit); | |
135 | enable_gptimers(TIMER0bit); | |
136 | local_irq_restore(flags); | |
137 | } | |
138 | ||
139 | static void bfin_t350mcqb_stop_timers(void) | |
140 | { | |
141 | disable_gptimers(TIMER0bit | TIMER1bit); | |
142 | ||
143 | set_gptimer_status(0, TIMER_STATUS_TRUN0 | TIMER_STATUS_TRUN1 | | |
144 | TIMER_STATUS_TIMIL0 | TIMER_STATUS_TIMIL1 | | |
145 | TIMER_STATUS_TOVF0 | TIMER_STATUS_TOVF1); | |
146 | ||
147 | } | |
148 | ||
149 | static void bfin_t350mcqb_init_timers(void) | |
150 | { | |
151 | ||
152 | bfin_t350mcqb_stop_timers(); | |
153 | ||
154 | set_gptimer_period(TIMER0_id, H_PERIOD); | |
155 | set_gptimer_pwidth(TIMER0_id, H_PULSE); | |
156 | set_gptimer_config(TIMER0_id, TIMER_MODE_PWM | TIMER_PERIOD_CNT | | |
157 | TIMER_TIN_SEL | TIMER_CLK_SEL| | |
158 | TIMER_EMU_RUN); | |
159 | ||
160 | set_gptimer_period(TIMER1_id, V_PERIOD); | |
161 | set_gptimer_pwidth(TIMER1_id, V_PULSE); | |
162 | set_gptimer_config(TIMER1_id, TIMER_MODE_PWM | TIMER_PERIOD_CNT | | |
163 | TIMER_TIN_SEL | TIMER_CLK_SEL | | |
164 | TIMER_EMU_RUN); | |
165 | ||
166 | } | |
167 | ||
168 | static void bfin_t350mcqb_config_dma(struct bfin_t350mcqbfb_info *fbi) | |
169 | { | |
170 | ||
171 | set_dma_config(CH_PPI, | |
172 | set_bfin_dma_config(DIR_READ, DMA_FLOW_AUTO, | |
173 | INTR_DISABLE, DIMENSION_2D, | |
174 | DATA_SIZE_16, | |
175 | DMA_NOSYNC_KEEP_DMA_BUF)); | |
176 | set_dma_x_count(CH_PPI, (LCD_X_RES * LCD_BPP) / DMA_BUS_SIZE); | |
177 | set_dma_x_modify(CH_PPI, DMA_BUS_SIZE / 8); | |
178 | set_dma_y_count(CH_PPI, V_LINES); | |
179 | ||
180 | set_dma_y_modify(CH_PPI, DMA_BUS_SIZE / 8); | |
181 | set_dma_start_addr(CH_PPI, (unsigned long)fbi->fb_buffer); | |
182 | ||
183 | } | |
184 | ||
7ef9861c | 185 | static u16 ppi0_req_8[] = {P_PPI0_CLK, P_PPI0_FS1, P_PPI0_FS2, |
99eeed47 MH |
186 | P_PPI0_D0, P_PPI0_D1, P_PPI0_D2, |
187 | P_PPI0_D3, P_PPI0_D4, P_PPI0_D5, | |
188 | P_PPI0_D6, P_PPI0_D7, 0}; | |
189 | ||
7ef9861c BW |
190 | static int bfin_t350mcqb_request_ports(int action) |
191 | { | |
99eeed47 MH |
192 | if (action) { |
193 | if (peripheral_request_list(ppi0_req_8, DRIVER_NAME)) { | |
194 | printk(KERN_ERR "Requesting Peripherals faild\n"); | |
195 | return -EFAULT; | |
196 | } | |
197 | } else | |
198 | peripheral_free_list(ppi0_req_8); | |
199 | ||
200 | return 0; | |
201 | } | |
202 | ||
203 | static int bfin_t350mcqb_fb_open(struct fb_info *info, int user) | |
204 | { | |
205 | struct bfin_t350mcqbfb_info *fbi = info->par; | |
206 | ||
207 | spin_lock(&fbi->lock); | |
208 | fbi->lq043_open_cnt++; | |
209 | ||
210 | if (fbi->lq043_open_cnt <= 1) { | |
211 | ||
212 | bfin_t350mcqb_disable_ppi(); | |
213 | SSYNC(); | |
214 | ||
215 | bfin_t350mcqb_config_dma(fbi); | |
216 | bfin_t350mcqb_config_ppi(fbi); | |
217 | bfin_t350mcqb_init_timers(); | |
218 | ||
219 | /* start dma */ | |
220 | enable_dma(CH_PPI); | |
221 | bfin_t350mcqb_enable_ppi(); | |
222 | bfin_t350mcqb_start_timers(); | |
223 | } | |
224 | ||
225 | spin_unlock(&fbi->lock); | |
226 | ||
227 | return 0; | |
228 | } | |
229 | ||
230 | static int bfin_t350mcqb_fb_release(struct fb_info *info, int user) | |
231 | { | |
232 | struct bfin_t350mcqbfb_info *fbi = info->par; | |
233 | ||
234 | spin_lock(&fbi->lock); | |
235 | ||
236 | fbi->lq043_open_cnt--; | |
99eeed47 MH |
237 | |
238 | if (fbi->lq043_open_cnt <= 0) { | |
239 | bfin_t350mcqb_disable_ppi(); | |
240 | SSYNC(); | |
241 | disable_dma(CH_PPI); | |
242 | bfin_t350mcqb_stop_timers(); | |
99eeed47 MH |
243 | } |
244 | ||
245 | spin_unlock(&fbi->lock); | |
246 | ||
247 | return 0; | |
248 | } | |
249 | ||
250 | static int bfin_t350mcqb_fb_check_var(struct fb_var_screeninfo *var, | |
251 | struct fb_info *info) | |
252 | { | |
253 | ||
b46578ed MH |
254 | switch (var->bits_per_pixel) { |
255 | case 24:/* TRUECOLOUR, 16m */ | |
256 | var->red.offset = 0; | |
257 | var->green.offset = 8; | |
258 | var->blue.offset = 16; | |
259 | var->red.length = var->green.length = var->blue.length = 8; | |
260 | var->transp.offset = 0; | |
261 | var->transp.length = 0; | |
262 | var->transp.msb_right = 0; | |
263 | var->red.msb_right = 0; | |
264 | var->green.msb_right = 0; | |
265 | var->blue.msb_right = 0; | |
266 | break; | |
267 | default: | |
729f77bb | 268 | pr_debug("%s: depth not supported: %u BPP\n", __func__, |
99eeed47 MH |
269 | var->bits_per_pixel); |
270 | return -EINVAL; | |
271 | } | |
272 | ||
273 | if (info->var.xres != var->xres || info->var.yres != var->yres || | |
274 | info->var.xres_virtual != var->xres_virtual || | |
275 | info->var.yres_virtual != var->yres_virtual) { | |
276 | pr_debug("%s: Resolution not supported: X%u x Y%u \n", | |
729f77bb | 277 | __func__, var->xres, var->yres); |
99eeed47 MH |
278 | return -EINVAL; |
279 | } | |
280 | ||
281 | /* | |
282 | * Memory limit | |
283 | */ | |
284 | ||
285 | if ((info->fix.line_length * var->yres_virtual) > info->fix.smem_len) { | |
286 | pr_debug("%s: Memory Limit requested yres_virtual = %u\n", | |
729f77bb | 287 | __func__, var->yres_virtual); |
99eeed47 MH |
288 | return -ENOMEM; |
289 | } | |
290 | ||
291 | return 0; | |
292 | } | |
293 | ||
99eeed47 MH |
294 | int bfin_t350mcqb_fb_cursor(struct fb_info *info, struct fb_cursor *cursor) |
295 | { | |
296 | if (nocursor) | |
297 | return 0; | |
298 | else | |
299 | return -EINVAL; /* just to force soft_cursor() call */ | |
300 | } | |
301 | ||
302 | static int bfin_t350mcqb_fb_setcolreg(u_int regno, u_int red, u_int green, | |
303 | u_int blue, u_int transp, | |
304 | struct fb_info *info) | |
305 | { | |
306 | if (regno >= BFIN_LCD_NBR_PALETTE_ENTRIES) | |
307 | return -EINVAL; | |
308 | ||
309 | if (info->var.grayscale) { | |
310 | /* grayscale = 0.30*R + 0.59*G + 0.11*B */ | |
311 | red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8; | |
312 | } | |
313 | ||
314 | if (info->fix.visual == FB_VISUAL_TRUECOLOR) { | |
315 | ||
316 | u32 value; | |
317 | /* Place color in the pseudopalette */ | |
318 | if (regno > 16) | |
319 | return -EINVAL; | |
320 | ||
321 | red >>= (16 - info->var.red.length); | |
322 | green >>= (16 - info->var.green.length); | |
323 | blue >>= (16 - info->var.blue.length); | |
324 | ||
325 | value = (red << info->var.red.offset) | | |
326 | (green << info->var.green.offset) | | |
327 | (blue << info->var.blue.offset); | |
328 | value &= 0xFFFFFF; | |
329 | ||
330 | ((u32 *) (info->pseudo_palette))[regno] = value; | |
331 | ||
332 | } | |
333 | ||
334 | return 0; | |
335 | } | |
336 | ||
337 | static struct fb_ops bfin_t350mcqb_fb_ops = { | |
338 | .owner = THIS_MODULE, | |
339 | .fb_open = bfin_t350mcqb_fb_open, | |
340 | .fb_release = bfin_t350mcqb_fb_release, | |
341 | .fb_check_var = bfin_t350mcqb_fb_check_var, | |
342 | .fb_fillrect = cfb_fillrect, | |
343 | .fb_copyarea = cfb_copyarea, | |
344 | .fb_imageblit = cfb_imageblit, | |
99eeed47 MH |
345 | .fb_cursor = bfin_t350mcqb_fb_cursor, |
346 | .fb_setcolreg = bfin_t350mcqb_fb_setcolreg, | |
347 | }; | |
348 | ||
349 | #ifndef NO_BL_SUPPORT | |
350 | static int bl_get_brightness(struct backlight_device *bd) | |
351 | { | |
352 | return 0; | |
353 | } | |
354 | ||
355 | static struct backlight_ops bfin_lq043fb_bl_ops = { | |
356 | .get_brightness = bl_get_brightness, | |
357 | }; | |
358 | ||
359 | static struct backlight_device *bl_dev; | |
360 | ||
361 | static int bfin_lcd_get_power(struct lcd_device *dev) | |
362 | { | |
363 | return 0; | |
364 | } | |
365 | ||
366 | static int bfin_lcd_set_power(struct lcd_device *dev, int power) | |
367 | { | |
368 | return 0; | |
369 | } | |
370 | ||
371 | static int bfin_lcd_get_contrast(struct lcd_device *dev) | |
372 | { | |
373 | return 0; | |
374 | } | |
375 | ||
376 | static int bfin_lcd_set_contrast(struct lcd_device *dev, int contrast) | |
377 | { | |
378 | ||
379 | return 0; | |
380 | } | |
381 | ||
0c531360 | 382 | static int bfin_lcd_check_fb(struct lcd_device *dev, struct fb_info *fi) |
99eeed47 MH |
383 | { |
384 | if (!fi || (fi == &bfin_t350mcqb_fb)) | |
385 | return 1; | |
386 | return 0; | |
387 | } | |
388 | ||
389 | static struct lcd_ops bfin_lcd_ops = { | |
390 | .get_power = bfin_lcd_get_power, | |
391 | .set_power = bfin_lcd_set_power, | |
392 | .get_contrast = bfin_lcd_get_contrast, | |
393 | .set_contrast = bfin_lcd_set_contrast, | |
394 | .check_fb = bfin_lcd_check_fb, | |
395 | }; | |
396 | ||
397 | static struct lcd_device *lcd_dev; | |
398 | #endif | |
399 | ||
400 | static irqreturn_t bfin_t350mcqb_irq_error(int irq, void *dev_id) | |
401 | { | |
402 | /*struct bfin_t350mcqbfb_info *info = (struct bfin_t350mcqbfb_info *)dev_id;*/ | |
403 | ||
404 | u16 status = bfin_read_PPI_STATUS(); | |
405 | bfin_write_PPI_STATUS(0xFFFF); | |
406 | ||
407 | if (status) { | |
408 | bfin_t350mcqb_disable_ppi(); | |
409 | disable_dma(CH_PPI); | |
410 | ||
411 | /* start dma */ | |
412 | enable_dma(CH_PPI); | |
413 | bfin_t350mcqb_enable_ppi(); | |
414 | bfin_write_PPI_STATUS(0xFFFF); | |
415 | } | |
416 | ||
417 | return IRQ_HANDLED; | |
418 | } | |
419 | ||
d4097456 | 420 | static int __devinit bfin_t350mcqb_probe(struct platform_device *pdev) |
99eeed47 | 421 | { |
a19a6ee6 | 422 | struct backlight_properties props; |
99eeed47 MH |
423 | struct bfin_t350mcqbfb_info *info; |
424 | struct fb_info *fbinfo; | |
425 | int ret; | |
426 | ||
427 | printk(KERN_INFO DRIVER_NAME ": %dx%d %d-bit RGB FrameBuffer initializing...\n", | |
428 | LCD_X_RES, LCD_Y_RES, LCD_BPP); | |
429 | ||
430 | if (request_dma(CH_PPI, "CH_PPI") < 0) { | |
431 | printk(KERN_ERR DRIVER_NAME | |
432 | ": couldn't request CH_PPI DMA\n"); | |
433 | ret = -EFAULT; | |
434 | goto out1; | |
435 | } | |
436 | ||
437 | fbinfo = | |
438 | framebuffer_alloc(sizeof(struct bfin_t350mcqbfb_info), &pdev->dev); | |
439 | if (!fbinfo) { | |
440 | ret = -ENOMEM; | |
441 | goto out2; | |
442 | } | |
443 | ||
444 | info = fbinfo->par; | |
445 | info->fb = fbinfo; | |
446 | info->dev = &pdev->dev; | |
447 | ||
448 | platform_set_drvdata(pdev, fbinfo); | |
449 | ||
450 | strcpy(fbinfo->fix.id, driver_name); | |
451 | ||
452 | fbinfo->fix.type = FB_TYPE_PACKED_PIXELS; | |
453 | fbinfo->fix.type_aux = 0; | |
454 | fbinfo->fix.xpanstep = 0; | |
455 | fbinfo->fix.ypanstep = 0; | |
456 | fbinfo->fix.ywrapstep = 0; | |
457 | fbinfo->fix.accel = FB_ACCEL_NONE; | |
458 | fbinfo->fix.visual = FB_VISUAL_TRUECOLOR; | |
459 | ||
460 | fbinfo->var.nonstd = 0; | |
461 | fbinfo->var.activate = FB_ACTIVATE_NOW; | |
09335865 MH |
462 | fbinfo->var.height = 53; |
463 | fbinfo->var.width = 70; | |
99eeed47 MH |
464 | fbinfo->var.accel_flags = 0; |
465 | fbinfo->var.vmode = FB_VMODE_NONINTERLACED; | |
466 | ||
467 | fbinfo->var.xres = LCD_X_RES; | |
468 | fbinfo->var.xres_virtual = LCD_X_RES; | |
469 | fbinfo->var.yres = LCD_Y_RES; | |
470 | fbinfo->var.yres_virtual = LCD_Y_RES; | |
471 | fbinfo->var.bits_per_pixel = LCD_BPP; | |
472 | ||
473 | fbinfo->var.red.offset = 0; | |
474 | fbinfo->var.green.offset = 8; | |
475 | fbinfo->var.blue.offset = 16; | |
476 | fbinfo->var.transp.offset = 0; | |
477 | fbinfo->var.red.length = 8; | |
478 | fbinfo->var.green.length = 8; | |
479 | fbinfo->var.blue.length = 8; | |
480 | fbinfo->var.transp.length = 0; | |
481 | fbinfo->fix.smem_len = LCD_X_RES * LCD_Y_RES * LCD_BPP / 8; | |
482 | ||
483 | fbinfo->fix.line_length = fbinfo->var.xres_virtual * | |
484 | fbinfo->var.bits_per_pixel / 8; | |
485 | ||
486 | ||
487 | fbinfo->fbops = &bfin_t350mcqb_fb_ops; | |
488 | fbinfo->flags = FBINFO_FLAG_DEFAULT; | |
489 | ||
490 | info->fb_buffer = | |
491 | dma_alloc_coherent(NULL, fbinfo->fix.smem_len, &info->dma_handle, | |
492 | GFP_KERNEL); | |
493 | ||
494 | if (NULL == info->fb_buffer) { | |
495 | printk(KERN_ERR DRIVER_NAME | |
496 | ": couldn't allocate dma buffer.\n"); | |
497 | ret = -ENOMEM; | |
498 | goto out3; | |
499 | } | |
500 | ||
99eeed47 MH |
501 | fbinfo->screen_base = (void *)info->fb_buffer + ACTIVE_VIDEO_MEM_OFFSET; |
502 | fbinfo->fix.smem_start = (int)info->fb_buffer + ACTIVE_VIDEO_MEM_OFFSET; | |
503 | ||
504 | fbinfo->fbops = &bfin_t350mcqb_fb_ops; | |
505 | ||
7ef9861c | 506 | fbinfo->pseudo_palette = &info->pseudo_pal; |
99eeed47 MH |
507 | |
508 | if (fb_alloc_cmap(&fbinfo->cmap, BFIN_LCD_NBR_PALETTE_ENTRIES, 0) | |
509 | < 0) { | |
510 | printk(KERN_ERR DRIVER_NAME | |
511 | "Fail to allocate colormap (%d entries)\n", | |
512 | BFIN_LCD_NBR_PALETTE_ENTRIES); | |
513 | ret = -EFAULT; | |
7ef9861c | 514 | goto out4; |
99eeed47 MH |
515 | } |
516 | ||
517 | if (bfin_t350mcqb_request_ports(1)) { | |
518 | printk(KERN_ERR DRIVER_NAME ": couldn't request gpio port.\n"); | |
519 | ret = -EFAULT; | |
520 | goto out6; | |
521 | } | |
522 | ||
523 | info->irq = platform_get_irq(pdev, 0); | |
524 | if (info->irq < 0) { | |
525 | ret = -EINVAL; | |
526 | goto out7; | |
527 | } | |
528 | ||
7ef9861c BW |
529 | ret = request_irq(info->irq, bfin_t350mcqb_irq_error, IRQF_DISABLED, |
530 | "PPI ERROR", info); | |
531 | if (ret < 0) { | |
99eeed47 MH |
532 | printk(KERN_ERR DRIVER_NAME |
533 | ": unable to request PPI ERROR IRQ\n"); | |
99eeed47 MH |
534 | goto out7; |
535 | } | |
536 | ||
537 | if (register_framebuffer(fbinfo) < 0) { | |
538 | printk(KERN_ERR DRIVER_NAME | |
539 | ": unable to register framebuffer.\n"); | |
540 | ret = -EINVAL; | |
541 | goto out8; | |
542 | } | |
543 | #ifndef NO_BL_SUPPORT | |
a19a6ee6 MG |
544 | memset(&props, 0, sizeof(struct backlight_properties)); |
545 | props.max_brightness = 255; | |
546 | bl_dev = backlight_device_register("bf52x-bl", NULL, NULL, | |
547 | &bfin_lq043fb_bl_ops, &props); | |
99eeed47 MH |
548 | |
549 | lcd_dev = lcd_device_register(DRIVER_NAME, NULL, &bfin_lcd_ops); | |
550 | lcd_dev->props.max_contrast = 255, printk(KERN_INFO "Done.\n"); | |
551 | #endif | |
552 | ||
553 | return 0; | |
554 | ||
555 | out8: | |
556 | free_irq(info->irq, info); | |
557 | out7: | |
558 | bfin_t350mcqb_request_ports(0); | |
559 | out6: | |
560 | fb_dealloc_cmap(&fbinfo->cmap); | |
99eeed47 MH |
561 | out4: |
562 | dma_free_coherent(NULL, fbinfo->fix.smem_len, info->fb_buffer, | |
563 | info->dma_handle); | |
564 | out3: | |
565 | framebuffer_release(fbinfo); | |
566 | out2: | |
567 | free_dma(CH_PPI); | |
568 | out1: | |
569 | platform_set_drvdata(pdev, NULL); | |
570 | ||
571 | return ret; | |
572 | } | |
573 | ||
8f09d74a | 574 | static int __devexit bfin_t350mcqb_remove(struct platform_device *pdev) |
99eeed47 MH |
575 | { |
576 | ||
577 | struct fb_info *fbinfo = platform_get_drvdata(pdev); | |
578 | struct bfin_t350mcqbfb_info *info = fbinfo->par; | |
579 | ||
7ef9861c BW |
580 | unregister_framebuffer(fbinfo); |
581 | ||
99eeed47 MH |
582 | free_dma(CH_PPI); |
583 | free_irq(info->irq, info); | |
584 | ||
585 | if (info->fb_buffer != NULL) | |
586 | dma_free_coherent(NULL, fbinfo->fix.smem_len, info->fb_buffer, | |
587 | info->dma_handle); | |
588 | ||
99eeed47 MH |
589 | fb_dealloc_cmap(&fbinfo->cmap); |
590 | ||
591 | #ifndef NO_BL_SUPPORT | |
592 | lcd_device_unregister(lcd_dev); | |
593 | backlight_device_unregister(bl_dev); | |
594 | #endif | |
595 | ||
99eeed47 MH |
596 | bfin_t350mcqb_request_ports(0); |
597 | ||
7ef9861c BW |
598 | platform_set_drvdata(pdev, NULL); |
599 | framebuffer_release(fbinfo); | |
600 | ||
99eeed47 MH |
601 | printk(KERN_INFO DRIVER_NAME ": Unregister LCD driver.\n"); |
602 | ||
603 | return 0; | |
604 | } | |
605 | ||
606 | #ifdef CONFIG_PM | |
607 | static int bfin_t350mcqb_suspend(struct platform_device *pdev, pm_message_t state) | |
608 | { | |
6841bcfa MH |
609 | struct fb_info *fbinfo = platform_get_drvdata(pdev); |
610 | struct bfin_t350mcqbfb_info *fbi = fbinfo->par; | |
611 | ||
612 | if (fbi->lq043_open_cnt) { | |
613 | bfin_t350mcqb_disable_ppi(); | |
614 | disable_dma(CH_PPI); | |
615 | bfin_t350mcqb_stop_timers(); | |
616 | bfin_write_PPI_STATUS(-1); | |
617 | } | |
618 | ||
99eeed47 MH |
619 | |
620 | return 0; | |
621 | } | |
622 | ||
623 | static int bfin_t350mcqb_resume(struct platform_device *pdev) | |
624 | { | |
6841bcfa MH |
625 | struct fb_info *fbinfo = platform_get_drvdata(pdev); |
626 | struct bfin_t350mcqbfb_info *fbi = fbinfo->par; | |
627 | ||
628 | if (fbi->lq043_open_cnt) { | |
629 | bfin_t350mcqb_config_dma(fbi); | |
630 | bfin_t350mcqb_config_ppi(fbi); | |
631 | bfin_t350mcqb_init_timers(); | |
632 | ||
633 | /* start dma */ | |
634 | enable_dma(CH_PPI); | |
635 | bfin_t350mcqb_enable_ppi(); | |
636 | bfin_t350mcqb_start_timers(); | |
637 | } | |
99eeed47 MH |
638 | |
639 | return 0; | |
640 | } | |
641 | #else | |
642 | #define bfin_t350mcqb_suspend NULL | |
643 | #define bfin_t350mcqb_resume NULL | |
644 | #endif | |
645 | ||
646 | static struct platform_driver bfin_t350mcqb_driver = { | |
647 | .probe = bfin_t350mcqb_probe, | |
8f09d74a | 648 | .remove = __devexit_p(bfin_t350mcqb_remove), |
99eeed47 MH |
649 | .suspend = bfin_t350mcqb_suspend, |
650 | .resume = bfin_t350mcqb_resume, | |
651 | .driver = { | |
652 | .name = DRIVER_NAME, | |
653 | .owner = THIS_MODULE, | |
654 | }, | |
655 | }; | |
656 | ||
8f09d74a | 657 | static int __init bfin_t350mcqb_driver_init(void) |
99eeed47 MH |
658 | { |
659 | return platform_driver_register(&bfin_t350mcqb_driver); | |
660 | } | |
661 | ||
662 | static void __exit bfin_t350mcqb_driver_cleanup(void) | |
663 | { | |
664 | platform_driver_unregister(&bfin_t350mcqb_driver); | |
665 | } | |
666 | ||
667 | MODULE_DESCRIPTION("Blackfin TFT LCD Driver"); | |
668 | MODULE_LICENSE("GPL"); | |
669 | ||
670 | module_init(bfin_t350mcqb_driver_init); | |
671 | module_exit(bfin_t350mcqb_driver_cleanup); |