2 * Blackfin LCD Framebuffer driver SHARP LQ035Q1DH02
4 * Copyright 2008-2009 Analog Devices Inc.
5 * Licensed under the GPL-2 or later.
8 #define DRIVER_NAME "bfin-lq035q1"
9 #define pr_fmt(fmt) DRIVER_NAME ": " fmt
11 #include <linux/module.h>
12 #include <linux/kernel.h>
13 #include <linux/errno.h>
14 #include <linux/string.h>
16 #include <linux/gpio.h>
17 #include <linux/slab.h>
18 #include <linux/init.h>
19 #include <linux/types.h>
20 #include <linux/interrupt.h>
21 #include <linux/device.h>
22 #include <linux/backlight.h>
23 #include <linux/lcd.h>
24 #include <linux/dma-mapping.h>
25 #include <linux/platform_device.h>
26 #include <linux/spi/spi.h>
28 #include <asm/blackfin.h>
31 #include <asm/portmux.h>
32 #include <asm/gptimers.h>
34 #include <asm/bfin-lq035q1.h>
36 #if defined(BF533_FAMILY) || defined(BF538_FAMILY)
37 #define TIMER_HSYNC_id TIMER1_id
38 #define TIMER_HSYNCbit TIMER1bit
39 #define TIMER_HSYNC_STATUS_TRUN TIMER_STATUS_TRUN1
40 #define TIMER_HSYNC_STATUS_TIMIL TIMER_STATUS_TIMIL1
41 #define TIMER_HSYNC_STATUS_TOVF TIMER_STATUS_TOVF1
43 #define TIMER_VSYNC_id TIMER2_id
44 #define TIMER_VSYNCbit TIMER2bit
45 #define TIMER_VSYNC_STATUS_TRUN TIMER_STATUS_TRUN2
46 #define TIMER_VSYNC_STATUS_TIMIL TIMER_STATUS_TIMIL2
47 #define TIMER_VSYNC_STATUS_TOVF TIMER_STATUS_TOVF2
49 #define TIMER_HSYNC_id TIMER0_id
50 #define TIMER_HSYNCbit TIMER0bit
51 #define TIMER_HSYNC_STATUS_TRUN TIMER_STATUS_TRUN0
52 #define TIMER_HSYNC_STATUS_TIMIL TIMER_STATUS_TIMIL0
53 #define TIMER_HSYNC_STATUS_TOVF TIMER_STATUS_TOVF0
55 #define TIMER_VSYNC_id TIMER1_id
56 #define TIMER_VSYNCbit TIMER1bit
57 #define TIMER_VSYNC_STATUS_TRUN TIMER_STATUS_TRUN1
58 #define TIMER_VSYNC_STATUS_TIMIL TIMER_STATUS_TIMIL1
59 #define TIMER_VSYNC_STATUS_TOVF TIMER_STATUS_TOVF1
62 #define LCD_X_RES 320 /* Horizontal Resolution */
63 #define LCD_Y_RES 240 /* Vertical Resolution */
64 #define DMA_BUS_SIZE 16
65 #define U_LINE 4 /* Blanking Lines */
68 /* Interface 16/18-bit TFT over an 8-bit wide PPI using a small Programmable Logic Device (CPLD)
69 * http://blackfin.uclinux.org/gf/project/stamp/frs/?action=FrsReleaseBrowse&frs_package_id=165
73 #define BFIN_LCD_NBR_PALETTE_ENTRIES 256
75 #define PPI_TX_MODE 0x2
76 #define PPI_XFER_TYPE_11 0xC
77 #define PPI_PORT_CFG_01 0x10
78 #define PPI_POLS_1 0x8000
80 #define LQ035_INDEX 0x74
81 #define LQ035_DATA 0x76
83 #define LQ035_DRIVER_OUTPUT_CTL 0x1
84 #define LQ035_SHUT_CTL 0x11
86 #define LQ035_DRIVER_OUTPUT_MASK (LQ035_LR | LQ035_TB | LQ035_BGR | LQ035_REV)
87 #define LQ035_DRIVER_OUTPUT_DEFAULT (0x2AEF & ~LQ035_DRIVER_OUTPUT_MASK)
89 #define LQ035_SHUT (1 << 0) /* Shutdown */
90 #define LQ035_ON (0 << 0) /* Shutdown */
92 struct bfin_lq035q1fb_info
{
95 struct spi_driver spidrv
;
96 struct bfin_lq035q1fb_disp_info
*disp_info
;
97 unsigned char *fb_buffer
; /* RGB Buffer */
98 dma_addr_t dma_handle
;
101 spinlock_t lock
; /* lock */
115 module_param(nocursor
, int, 0644);
116 MODULE_PARM_DESC(nocursor
, "cursor enable/disable");
122 static int lq035q1_control(struct spi_device
*spi
, unsigned char reg
, unsigned short value
)
125 u8 regs
[3] = { LQ035_INDEX
, 0, 0 };
126 u8 dat
[3] = { LQ035_DATA
, 0, 0 };
133 dat
[2] = value
& 0xFF;
135 ret
= spi_write(spi
, regs
, ARRAY_SIZE(regs
));
136 ret
|= spi_write(spi
, dat
, ARRAY_SIZE(dat
));
140 static int __devinit
lq035q1_spidev_probe(struct spi_device
*spi
)
143 struct spi_control
*ctl
;
144 struct bfin_lq035q1fb_info
*info
= container_of(spi
->dev
.driver
,
145 struct bfin_lq035q1fb_info
,
148 ctl
= kzalloc(sizeof(*ctl
), GFP_KERNEL
);
153 ctl
->mode
= (info
->disp_info
->mode
&
154 LQ035_DRIVER_OUTPUT_MASK
) | LQ035_DRIVER_OUTPUT_DEFAULT
;
156 ret
= lq035q1_control(spi
, LQ035_SHUT_CTL
, LQ035_ON
);
157 ret
|= lq035q1_control(spi
, LQ035_DRIVER_OUTPUT_CTL
, ctl
->mode
);
163 spi_set_drvdata(spi
, ctl
);
168 static int lq035q1_spidev_remove(struct spi_device
*spi
)
170 return lq035q1_control(spi
, LQ035_SHUT_CTL
, LQ035_SHUT
);
174 static int lq035q1_spidev_suspend(struct spi_device
*spi
, pm_message_t state
)
176 return lq035q1_control(spi
, LQ035_SHUT_CTL
, LQ035_SHUT
);
179 static int lq035q1_spidev_resume(struct spi_device
*spi
)
182 struct spi_control
*ctl
= spi_get_drvdata(spi
);
184 ret
= lq035q1_control(spi
, LQ035_DRIVER_OUTPUT_CTL
, ctl
->mode
);
188 return lq035q1_control(spi
, LQ035_SHUT_CTL
, LQ035_ON
);
191 # define lq035q1_spidev_suspend NULL
192 # define lq035q1_spidev_resume NULL
195 /* Power down all displays on reboot, poweroff or halt */
196 static void lq035q1_spidev_shutdown(struct spi_device
*spi
)
198 lq035q1_control(spi
, LQ035_SHUT_CTL
, LQ035_SHUT
);
201 static int lq035q1_backlight(struct bfin_lq035q1fb_info
*info
, unsigned arg
)
203 if (info
->disp_info
->use_bl
)
204 gpio_set_value(info
->disp_info
->gpio_bl
, arg
);
209 static int bfin_lq035q1_calc_timing(struct bfin_lq035q1fb_info
*fbi
)
211 unsigned long clocks_per_pix
, cpld_pipeline_delay_cor
;
214 * Interface 16/18-bit TFT over an 8-bit wide PPI using a small
215 * Programmable Logic Device (CPLD)
216 * http://blackfin.uclinux.org/gf/project/stamp/frs/?action=FrsReleaseBrowse&frs_package_id=165
219 switch (fbi
->disp_info
->ppi_mode
) {
220 case USE_RGB565_16_BIT_PPI
:
223 cpld_pipeline_delay_cor
= 0;
225 case USE_RGB565_8_BIT_PPI
:
228 cpld_pipeline_delay_cor
= 3;
230 case USE_RGB888_8_BIT_PPI
:
233 cpld_pipeline_delay_cor
= 5;
240 * HS and VS timing parameters (all in number of PPI clk ticks)
243 fbi
->h_actpix
= (LCD_X_RES
* clocks_per_pix
); /* active horizontal pixel */
244 fbi
->h_period
= (336 * clocks_per_pix
); /* HS period */
245 fbi
->h_pulse
= (2 * clocks_per_pix
); /* HS pulse width */
246 fbi
->h_start
= (7 * clocks_per_pix
+ cpld_pipeline_delay_cor
); /* first valid pixel */
248 fbi
->v_lines
= (LCD_Y_RES
+ U_LINE
); /* total vertical lines */
249 fbi
->v_pulse
= (2 * clocks_per_pix
); /* VS pulse width (1-5 H_PERIODs) */
250 fbi
->v_period
= (fbi
->h_period
* fbi
->v_lines
); /* VS period */
255 static void bfin_lq035q1_config_ppi(struct bfin_lq035q1fb_info
*fbi
)
259 if (fbi
->disp_info
->ppi_mode
== USE_RGB565_16_BIT_PPI
)
262 ppi_pmode
= (DLEN_8
| PACK_EN
);
264 bfin_write_PPI_DELAY(fbi
->h_start
);
265 bfin_write_PPI_COUNT(fbi
->h_actpix
- 1);
266 bfin_write_PPI_FRAME(fbi
->v_lines
);
268 bfin_write_PPI_CONTROL(PPI_TX_MODE
| /* output mode , PORT_DIR */
269 PPI_XFER_TYPE_11
| /* sync mode XFR_TYPE */
270 PPI_PORT_CFG_01
| /* two frame sync PORT_CFG */
271 ppi_pmode
| /* 8/16 bit data length / PACK_EN? */
272 PPI_POLS_1
); /* faling edge syncs POLS */
275 static inline void bfin_lq035q1_disable_ppi(void)
277 bfin_write_PPI_CONTROL(bfin_read_PPI_CONTROL() & ~PORT_EN
);
280 static inline void bfin_lq035q1_enable_ppi(void)
282 bfin_write_PPI_CONTROL(bfin_read_PPI_CONTROL() | PORT_EN
);
285 static void bfin_lq035q1_start_timers(void)
287 enable_gptimers(TIMER_VSYNCbit
| TIMER_HSYNCbit
);
290 static void bfin_lq035q1_stop_timers(void)
292 disable_gptimers(TIMER_HSYNCbit
| TIMER_VSYNCbit
);
294 set_gptimer_status(0, TIMER_HSYNC_STATUS_TRUN
| TIMER_VSYNC_STATUS_TRUN
|
295 TIMER_HSYNC_STATUS_TIMIL
| TIMER_VSYNC_STATUS_TIMIL
|
296 TIMER_HSYNC_STATUS_TOVF
| TIMER_VSYNC_STATUS_TOVF
);
300 static void bfin_lq035q1_init_timers(struct bfin_lq035q1fb_info
*fbi
)
303 bfin_lq035q1_stop_timers();
305 set_gptimer_period(TIMER_HSYNC_id
, fbi
->h_period
);
306 set_gptimer_pwidth(TIMER_HSYNC_id
, fbi
->h_pulse
);
307 set_gptimer_config(TIMER_HSYNC_id
, TIMER_MODE_PWM
| TIMER_PERIOD_CNT
|
308 TIMER_TIN_SEL
| TIMER_CLK_SEL
|
311 set_gptimer_period(TIMER_VSYNC_id
, fbi
->v_period
);
312 set_gptimer_pwidth(TIMER_VSYNC_id
, fbi
->v_pulse
);
313 set_gptimer_config(TIMER_VSYNC_id
, TIMER_MODE_PWM
| TIMER_PERIOD_CNT
|
314 TIMER_TIN_SEL
| TIMER_CLK_SEL
|
319 static void bfin_lq035q1_config_dma(struct bfin_lq035q1fb_info
*fbi
)
323 set_dma_config(CH_PPI
,
324 set_bfin_dma_config(DIR_READ
, DMA_FLOW_AUTO
,
325 INTR_DISABLE
, DIMENSION_2D
,
327 DMA_NOSYNC_KEEP_DMA_BUF
));
328 set_dma_x_count(CH_PPI
, (LCD_X_RES
* fbi
->lcd_bpp
) / DMA_BUS_SIZE
);
329 set_dma_x_modify(CH_PPI
, DMA_BUS_SIZE
/ 8);
330 set_dma_y_count(CH_PPI
, fbi
->v_lines
);
332 set_dma_y_modify(CH_PPI
, DMA_BUS_SIZE
/ 8);
333 set_dma_start_addr(CH_PPI
, (unsigned long)fbi
->fb_buffer
);
337 static const u16 ppi0_req_16
[] = {P_PPI0_CLK
, P_PPI0_FS1
, P_PPI0_FS2
,
338 P_PPI0_D0
, P_PPI0_D1
, P_PPI0_D2
,
339 P_PPI0_D3
, P_PPI0_D4
, P_PPI0_D5
,
340 P_PPI0_D6
, P_PPI0_D7
, P_PPI0_D8
,
341 P_PPI0_D9
, P_PPI0_D10
, P_PPI0_D11
,
342 P_PPI0_D12
, P_PPI0_D13
, P_PPI0_D14
,
345 static const u16 ppi0_req_8
[] = {P_PPI0_CLK
, P_PPI0_FS1
, P_PPI0_FS2
,
346 P_PPI0_D0
, P_PPI0_D1
, P_PPI0_D2
,
347 P_PPI0_D3
, P_PPI0_D4
, P_PPI0_D5
,
348 P_PPI0_D6
, P_PPI0_D7
, 0};
350 static inline void bfin_lq035q1_free_ports(unsigned ppi16
)
353 peripheral_free_list(ppi0_req_16
);
355 peripheral_free_list(ppi0_req_8
);
357 if (ANOMALY_05000400
)
358 gpio_free(P_IDENT(P_PPI0_FS3
));
361 static int __devinit
bfin_lq035q1_request_ports(struct platform_device
*pdev
,
365 /* ANOMALY_05000400 - PPI Does Not Start Properly In Specific Mode:
368 if (ANOMALY_05000400
) {
369 int ret
= gpio_request_one(P_IDENT(P_PPI0_FS3
),
370 GPIOF_OUT_INIT_LOW
, "PPI_FS3");
376 ret
= peripheral_request_list(ppi0_req_16
, DRIVER_NAME
);
378 ret
= peripheral_request_list(ppi0_req_8
, DRIVER_NAME
);
381 dev_err(&pdev
->dev
, "requesting peripherals failed\n");
388 static int bfin_lq035q1_fb_open(struct fb_info
*info
, int user
)
390 struct bfin_lq035q1fb_info
*fbi
= info
->par
;
392 spin_lock(&fbi
->lock
);
393 fbi
->lq035_open_cnt
++;
395 if (fbi
->lq035_open_cnt
<= 1) {
397 bfin_lq035q1_disable_ppi();
400 bfin_lq035q1_config_dma(fbi
);
401 bfin_lq035q1_config_ppi(fbi
);
402 bfin_lq035q1_init_timers(fbi
);
406 bfin_lq035q1_enable_ppi();
407 bfin_lq035q1_start_timers();
408 lq035q1_backlight(fbi
, 1);
411 spin_unlock(&fbi
->lock
);
416 static int bfin_lq035q1_fb_release(struct fb_info
*info
, int user
)
418 struct bfin_lq035q1fb_info
*fbi
= info
->par
;
420 spin_lock(&fbi
->lock
);
422 fbi
->lq035_open_cnt
--;
424 if (fbi
->lq035_open_cnt
<= 0) {
425 lq035q1_backlight(fbi
, 0);
426 bfin_lq035q1_disable_ppi();
429 bfin_lq035q1_stop_timers();
432 spin_unlock(&fbi
->lock
);
437 static int bfin_lq035q1_fb_check_var(struct fb_var_screeninfo
*var
,
438 struct fb_info
*info
)
440 struct bfin_lq035q1fb_info
*fbi
= info
->par
;
442 if (var
->bits_per_pixel
== fbi
->lcd_bpp
) {
443 var
->red
.offset
= info
->var
.red
.offset
;
444 var
->green
.offset
= info
->var
.green
.offset
;
445 var
->blue
.offset
= info
->var
.blue
.offset
;
446 var
->red
.length
= info
->var
.red
.length
;
447 var
->green
.length
= info
->var
.green
.length
;
448 var
->blue
.length
= info
->var
.blue
.length
;
449 var
->transp
.offset
= 0;
450 var
->transp
.length
= 0;
451 var
->transp
.msb_right
= 0;
452 var
->red
.msb_right
= 0;
453 var
->green
.msb_right
= 0;
454 var
->blue
.msb_right
= 0;
456 pr_debug("%s: depth not supported: %u BPP\n", __func__
,
457 var
->bits_per_pixel
);
461 if (info
->var
.xres
!= var
->xres
|| info
->var
.yres
!= var
->yres
||
462 info
->var
.xres_virtual
!= var
->xres_virtual
||
463 info
->var
.yres_virtual
!= var
->yres_virtual
) {
464 pr_debug("%s: Resolution not supported: X%u x Y%u \n",
465 __func__
, var
->xres
, var
->yres
);
473 if ((info
->fix
.line_length
* var
->yres_virtual
) > info
->fix
.smem_len
) {
474 pr_debug("%s: Memory Limit requested yres_virtual = %u\n",
475 __func__
, var
->yres_virtual
);
483 int bfin_lq035q1_fb_cursor(struct fb_info
*info
, struct fb_cursor
*cursor
)
488 return -EINVAL
; /* just to force soft_cursor() call */
491 static int bfin_lq035q1_fb_setcolreg(u_int regno
, u_int red
, u_int green
,
492 u_int blue
, u_int transp
,
493 struct fb_info
*info
)
495 if (regno
>= BFIN_LCD_NBR_PALETTE_ENTRIES
)
498 if (info
->var
.grayscale
) {
499 /* grayscale = 0.30*R + 0.59*G + 0.11*B */
500 red
= green
= blue
= (red
* 77 + green
* 151 + blue
* 28) >> 8;
503 if (info
->fix
.visual
== FB_VISUAL_TRUECOLOR
) {
506 /* Place color in the pseudopalette */
510 red
>>= (16 - info
->var
.red
.length
);
511 green
>>= (16 - info
->var
.green
.length
);
512 blue
>>= (16 - info
->var
.blue
.length
);
514 value
= (red
<< info
->var
.red
.offset
) |
515 (green
<< info
->var
.green
.offset
) |
516 (blue
<< info
->var
.blue
.offset
);
519 ((u32
*) (info
->pseudo_palette
))[regno
] = value
;
526 static struct fb_ops bfin_lq035q1_fb_ops
= {
527 .owner
= THIS_MODULE
,
528 .fb_open
= bfin_lq035q1_fb_open
,
529 .fb_release
= bfin_lq035q1_fb_release
,
530 .fb_check_var
= bfin_lq035q1_fb_check_var
,
531 .fb_fillrect
= cfb_fillrect
,
532 .fb_copyarea
= cfb_copyarea
,
533 .fb_imageblit
= cfb_imageblit
,
534 .fb_cursor
= bfin_lq035q1_fb_cursor
,
535 .fb_setcolreg
= bfin_lq035q1_fb_setcolreg
,
538 static irqreturn_t
bfin_lq035q1_irq_error(int irq
, void *dev_id
)
540 /*struct bfin_lq035q1fb_info *info = (struct bfin_lq035q1fb_info *)dev_id;*/
542 u16 status
= bfin_read_PPI_STATUS();
543 bfin_write_PPI_STATUS(-1);
546 bfin_lq035q1_disable_ppi();
551 bfin_lq035q1_enable_ppi();
552 bfin_write_PPI_STATUS(-1);
558 static int __devinit
bfin_lq035q1_probe(struct platform_device
*pdev
)
560 struct bfin_lq035q1fb_info
*info
;
561 struct fb_info
*fbinfo
;
562 u32 active_video_mem_offset
;
565 ret
= request_dma(CH_PPI
, DRIVER_NAME
"_CH_PPI");
567 dev_err(&pdev
->dev
, "PPI DMA unavailable\n");
571 fbinfo
= framebuffer_alloc(sizeof(*info
), &pdev
->dev
);
579 info
->dev
= &pdev
->dev
;
581 info
->disp_info
= pdev
->dev
.platform_data
;
583 platform_set_drvdata(pdev
, fbinfo
);
585 ret
= bfin_lq035q1_calc_timing(info
);
587 dev_err(&pdev
->dev
, "Failed PPI Mode\n");
591 strcpy(fbinfo
->fix
.id
, DRIVER_NAME
);
593 fbinfo
->fix
.type
= FB_TYPE_PACKED_PIXELS
;
594 fbinfo
->fix
.type_aux
= 0;
595 fbinfo
->fix
.xpanstep
= 0;
596 fbinfo
->fix
.ypanstep
= 0;
597 fbinfo
->fix
.ywrapstep
= 0;
598 fbinfo
->fix
.accel
= FB_ACCEL_NONE
;
599 fbinfo
->fix
.visual
= FB_VISUAL_TRUECOLOR
;
601 fbinfo
->var
.nonstd
= 0;
602 fbinfo
->var
.activate
= FB_ACTIVATE_NOW
;
603 fbinfo
->var
.height
= -1;
604 fbinfo
->var
.width
= -1;
605 fbinfo
->var
.accel_flags
= 0;
606 fbinfo
->var
.vmode
= FB_VMODE_NONINTERLACED
;
608 fbinfo
->var
.xres
= LCD_X_RES
;
609 fbinfo
->var
.xres_virtual
= LCD_X_RES
;
610 fbinfo
->var
.yres
= LCD_Y_RES
;
611 fbinfo
->var
.yres_virtual
= LCD_Y_RES
;
612 fbinfo
->var
.bits_per_pixel
= info
->lcd_bpp
;
614 if (info
->disp_info
->mode
& LQ035_BGR
) {
615 if (info
->lcd_bpp
== 24) {
616 fbinfo
->var
.red
.offset
= 0;
617 fbinfo
->var
.green
.offset
= 8;
618 fbinfo
->var
.blue
.offset
= 16;
620 fbinfo
->var
.red
.offset
= 0;
621 fbinfo
->var
.green
.offset
= 5;
622 fbinfo
->var
.blue
.offset
= 11;
625 if (info
->lcd_bpp
== 24) {
626 fbinfo
->var
.red
.offset
= 16;
627 fbinfo
->var
.green
.offset
= 8;
628 fbinfo
->var
.blue
.offset
= 0;
630 fbinfo
->var
.red
.offset
= 11;
631 fbinfo
->var
.green
.offset
= 5;
632 fbinfo
->var
.blue
.offset
= 0;
636 fbinfo
->var
.transp
.offset
= 0;
638 if (info
->lcd_bpp
== 24) {
639 fbinfo
->var
.red
.length
= 8;
640 fbinfo
->var
.green
.length
= 8;
641 fbinfo
->var
.blue
.length
= 8;
643 fbinfo
->var
.red
.length
= 5;
644 fbinfo
->var
.green
.length
= 6;
645 fbinfo
->var
.blue
.length
= 5;
648 fbinfo
->var
.transp
.length
= 0;
650 active_video_mem_offset
= ((U_LINE
/ 2) * LCD_X_RES
* (info
->lcd_bpp
/ 8));
652 fbinfo
->fix
.smem_len
= LCD_X_RES
* LCD_Y_RES
* info
->lcd_bpp
/ 8
653 + active_video_mem_offset
;
655 fbinfo
->fix
.line_length
= fbinfo
->var
.xres_virtual
*
656 fbinfo
->var
.bits_per_pixel
/ 8;
659 fbinfo
->fbops
= &bfin_lq035q1_fb_ops
;
660 fbinfo
->flags
= FBINFO_FLAG_DEFAULT
;
663 dma_alloc_coherent(NULL
, fbinfo
->fix
.smem_len
, &info
->dma_handle
,
666 if (NULL
== info
->fb_buffer
) {
667 dev_err(&pdev
->dev
, "couldn't allocate dma buffer\n");
672 fbinfo
->screen_base
= (void *)info
->fb_buffer
+ active_video_mem_offset
;
673 fbinfo
->fix
.smem_start
= (int)info
->fb_buffer
+ active_video_mem_offset
;
675 fbinfo
->fbops
= &bfin_lq035q1_fb_ops
;
677 fbinfo
->pseudo_palette
= &info
->pseudo_pal
;
679 ret
= fb_alloc_cmap(&fbinfo
->cmap
, BFIN_LCD_NBR_PALETTE_ENTRIES
, 0);
681 dev_err(&pdev
->dev
, "failed to allocate colormap (%d entries)\n",
682 BFIN_LCD_NBR_PALETTE_ENTRIES
);
686 ret
= bfin_lq035q1_request_ports(pdev
,
687 info
->disp_info
->ppi_mode
== USE_RGB565_16_BIT_PPI
);
689 dev_err(&pdev
->dev
, "couldn't request gpio port\n");
693 info
->irq
= platform_get_irq(pdev
, 0);
699 ret
= request_irq(info
->irq
, bfin_lq035q1_irq_error
, 0,
700 DRIVER_NAME
" PPI ERROR", info
);
702 dev_err(&pdev
->dev
, "unable to request PPI ERROR IRQ\n");
706 info
->spidrv
.driver
.name
= DRIVER_NAME
"-spi";
707 info
->spidrv
.probe
= lq035q1_spidev_probe
;
708 info
->spidrv
.remove
= __devexit_p(lq035q1_spidev_remove
);
709 info
->spidrv
.shutdown
= lq035q1_spidev_shutdown
;
710 info
->spidrv
.suspend
= lq035q1_spidev_suspend
;
711 info
->spidrv
.resume
= lq035q1_spidev_resume
;
713 ret
= spi_register_driver(&info
->spidrv
);
715 dev_err(&pdev
->dev
, "couldn't register SPI Interface\n");
719 if (info
->disp_info
->use_bl
) {
720 ret
= gpio_request_one(info
->disp_info
->gpio_bl
,
721 GPIOF_OUT_INIT_LOW
, "LQ035 Backlight");
724 dev_err(&pdev
->dev
, "failed to request GPIO %d\n",
725 info
->disp_info
->gpio_bl
);
730 ret
= register_framebuffer(fbinfo
);
732 dev_err(&pdev
->dev
, "unable to register framebuffer\n");
736 dev_info(&pdev
->dev
, "%dx%d %d-bit RGB FrameBuffer initialized\n",
737 LCD_X_RES
, LCD_Y_RES
, info
->lcd_bpp
);
742 if (info
->disp_info
->use_bl
)
743 gpio_free(info
->disp_info
->gpio_bl
);
745 spi_unregister_driver(&info
->spidrv
);
747 free_irq(info
->irq
, info
);
749 bfin_lq035q1_free_ports(info
->disp_info
->ppi_mode
==
750 USE_RGB565_16_BIT_PPI
);
752 fb_dealloc_cmap(&fbinfo
->cmap
);
754 dma_free_coherent(NULL
, fbinfo
->fix
.smem_len
, info
->fb_buffer
,
757 framebuffer_release(fbinfo
);
761 platform_set_drvdata(pdev
, NULL
);
766 static int __devexit
bfin_lq035q1_remove(struct platform_device
*pdev
)
768 struct fb_info
*fbinfo
= platform_get_drvdata(pdev
);
769 struct bfin_lq035q1fb_info
*info
= fbinfo
->par
;
771 if (info
->disp_info
->use_bl
)
772 gpio_free(info
->disp_info
->gpio_bl
);
774 spi_unregister_driver(&info
->spidrv
);
776 unregister_framebuffer(fbinfo
);
779 free_irq(info
->irq
, info
);
781 if (info
->fb_buffer
!= NULL
)
782 dma_free_coherent(NULL
, fbinfo
->fix
.smem_len
, info
->fb_buffer
,
785 fb_dealloc_cmap(&fbinfo
->cmap
);
787 bfin_lq035q1_free_ports(info
->disp_info
->ppi_mode
==
788 USE_RGB565_16_BIT_PPI
);
790 platform_set_drvdata(pdev
, NULL
);
791 framebuffer_release(fbinfo
);
793 dev_info(&pdev
->dev
, "unregistered LCD driver\n");
799 static int bfin_lq035q1_suspend(struct device
*dev
)
801 struct fb_info
*fbinfo
= dev_get_drvdata(dev
);
802 struct bfin_lq035q1fb_info
*info
= fbinfo
->par
;
804 if (info
->lq035_open_cnt
) {
805 lq035q1_backlight(info
, 0);
806 bfin_lq035q1_disable_ppi();
809 bfin_lq035q1_stop_timers();
810 bfin_write_PPI_STATUS(-1);
816 static int bfin_lq035q1_resume(struct device
*dev
)
818 struct fb_info
*fbinfo
= dev_get_drvdata(dev
);
819 struct bfin_lq035q1fb_info
*info
= fbinfo
->par
;
821 if (info
->lq035_open_cnt
) {
822 bfin_lq035q1_disable_ppi();
825 bfin_lq035q1_config_dma(info
);
826 bfin_lq035q1_config_ppi(info
);
827 bfin_lq035q1_init_timers(info
);
831 bfin_lq035q1_enable_ppi();
832 bfin_lq035q1_start_timers();
833 lq035q1_backlight(info
, 1);
839 static struct dev_pm_ops bfin_lq035q1_dev_pm_ops
= {
840 .suspend
= bfin_lq035q1_suspend
,
841 .resume
= bfin_lq035q1_resume
,
845 static struct platform_driver bfin_lq035q1_driver
= {
846 .probe
= bfin_lq035q1_probe
,
847 .remove
= __devexit_p(bfin_lq035q1_remove
),
851 .pm
= &bfin_lq035q1_dev_pm_ops
,
856 static int __init
bfin_lq035q1_driver_init(void)
858 return platform_driver_register(&bfin_lq035q1_driver
);
860 module_init(bfin_lq035q1_driver_init
);
862 static void __exit
bfin_lq035q1_driver_cleanup(void)
864 platform_driver_unregister(&bfin_lq035q1_driver
);
866 module_exit(bfin_lq035q1_driver_cleanup
);
868 MODULE_DESCRIPTION("Blackfin TFT LCD Driver");
869 MODULE_LICENSE("GPL");