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/slab.h>
17 #include <linux/init.h>
18 #include <linux/types.h>
19 #include <linux/interrupt.h>
20 #include <linux/device.h>
21 #include <linux/backlight.h>
22 #include <linux/lcd.h>
23 #include <linux/dma-mapping.h>
24 #include <linux/platform_device.h>
25 #include <linux/spi/spi.h>
27 #include <asm/blackfin.h>
30 #include <asm/portmux.h>
31 #include <asm/gptimers.h>
33 #include <asm/bfin-lq035q1.h>
35 #if defined(BF533_FAMILY) || defined(BF538_FAMILY)
36 #define TIMER_HSYNC_id TIMER1_id
37 #define TIMER_HSYNCbit TIMER1bit
38 #define TIMER_HSYNC_STATUS_TRUN TIMER_STATUS_TRUN1
39 #define TIMER_HSYNC_STATUS_TIMIL TIMER_STATUS_TIMIL1
40 #define TIMER_HSYNC_STATUS_TOVF TIMER_STATUS_TOVF1
42 #define TIMER_VSYNC_id TIMER2_id
43 #define TIMER_VSYNCbit TIMER2bit
44 #define TIMER_VSYNC_STATUS_TRUN TIMER_STATUS_TRUN2
45 #define TIMER_VSYNC_STATUS_TIMIL TIMER_STATUS_TIMIL2
46 #define TIMER_VSYNC_STATUS_TOVF TIMER_STATUS_TOVF2
48 #define TIMER_HSYNC_id TIMER0_id
49 #define TIMER_HSYNCbit TIMER0bit
50 #define TIMER_HSYNC_STATUS_TRUN TIMER_STATUS_TRUN0
51 #define TIMER_HSYNC_STATUS_TIMIL TIMER_STATUS_TIMIL0
52 #define TIMER_HSYNC_STATUS_TOVF TIMER_STATUS_TOVF0
54 #define TIMER_VSYNC_id TIMER1_id
55 #define TIMER_VSYNCbit TIMER1bit
56 #define TIMER_VSYNC_STATUS_TRUN TIMER_STATUS_TRUN1
57 #define TIMER_VSYNC_STATUS_TIMIL TIMER_STATUS_TIMIL1
58 #define TIMER_VSYNC_STATUS_TOVF TIMER_STATUS_TOVF1
61 #define LCD_X_RES 320 /* Horizontal Resolution */
62 #define LCD_Y_RES 240 /* Vertical Resolution */
63 #define DMA_BUS_SIZE 16
64 #define U_LINE 4 /* Blanking Lines */
67 /* Interface 16/18-bit TFT over an 8-bit wide PPI using a small Programmable Logic Device (CPLD)
68 * http://blackfin.uclinux.org/gf/project/stamp/frs/?action=FrsReleaseBrowse&frs_package_id=165
72 #define BFIN_LCD_NBR_PALETTE_ENTRIES 256
74 #define PPI_TX_MODE 0x2
75 #define PPI_XFER_TYPE_11 0xC
76 #define PPI_PORT_CFG_01 0x10
77 #define PPI_POLS_1 0x8000
79 #define LQ035_INDEX 0x74
80 #define LQ035_DATA 0x76
82 #define LQ035_DRIVER_OUTPUT_CTL 0x1
83 #define LQ035_SHUT_CTL 0x11
85 #define LQ035_DRIVER_OUTPUT_MASK (LQ035_LR | LQ035_TB | LQ035_BGR | LQ035_REV)
86 #define LQ035_DRIVER_OUTPUT_DEFAULT (0x2AEF & ~LQ035_DRIVER_OUTPUT_MASK)
88 #define LQ035_SHUT (1 << 0) /* Shutdown */
89 #define LQ035_ON (0 << 0) /* Shutdown */
91 struct bfin_lq035q1fb_info
{
94 struct spi_driver spidrv
;
95 struct bfin_lq035q1fb_disp_info
*disp_info
;
96 unsigned char *fb_buffer
; /* RGB Buffer */
97 dma_addr_t dma_handle
;
100 spinlock_t lock
; /* lock */
114 module_param(nocursor
, int, 0644);
115 MODULE_PARM_DESC(nocursor
, "cursor enable/disable");
121 static int lq035q1_control(struct spi_device
*spi
, unsigned char reg
, unsigned short value
)
124 u8 regs
[3] = { LQ035_INDEX
, 0, 0 };
125 u8 dat
[3] = { LQ035_DATA
, 0, 0 };
132 dat
[2] = value
& 0xFF;
134 ret
= spi_write(spi
, regs
, ARRAY_SIZE(regs
));
135 ret
|= spi_write(spi
, dat
, ARRAY_SIZE(dat
));
139 static int __devinit
lq035q1_spidev_probe(struct spi_device
*spi
)
142 struct spi_control
*ctl
;
143 struct bfin_lq035q1fb_info
*info
= container_of(spi
->dev
.driver
,
144 struct bfin_lq035q1fb_info
,
147 ctl
= kzalloc(sizeof(*ctl
), GFP_KERNEL
);
152 ctl
->mode
= (info
->disp_info
->mode
&
153 LQ035_DRIVER_OUTPUT_MASK
) | LQ035_DRIVER_OUTPUT_DEFAULT
;
155 ret
= lq035q1_control(spi
, LQ035_SHUT_CTL
, LQ035_ON
);
156 ret
|= lq035q1_control(spi
, LQ035_DRIVER_OUTPUT_CTL
, ctl
->mode
);
160 spi_set_drvdata(spi
, ctl
);
165 static int lq035q1_spidev_remove(struct spi_device
*spi
)
167 return lq035q1_control(spi
, LQ035_SHUT_CTL
, LQ035_SHUT
);
171 static int lq035q1_spidev_suspend(struct spi_device
*spi
, pm_message_t state
)
173 return lq035q1_control(spi
, LQ035_SHUT_CTL
, LQ035_SHUT
);
176 static int lq035q1_spidev_resume(struct spi_device
*spi
)
179 struct spi_control
*ctl
= spi_get_drvdata(spi
);
181 ret
= lq035q1_control(spi
, LQ035_DRIVER_OUTPUT_CTL
, ctl
->mode
);
185 return lq035q1_control(spi
, LQ035_SHUT_CTL
, LQ035_ON
);
188 # define lq035q1_spidev_suspend NULL
189 # define lq035q1_spidev_resume NULL
192 /* Power down all displays on reboot, poweroff or halt */
193 static void lq035q1_spidev_shutdown(struct spi_device
*spi
)
195 lq035q1_control(spi
, LQ035_SHUT_CTL
, LQ035_SHUT
);
198 static int lq035q1_backlight(struct bfin_lq035q1fb_info
*info
, unsigned arg
)
200 if (info
->disp_info
->use_bl
)
201 gpio_set_value(info
->disp_info
->gpio_bl
, arg
);
206 static int bfin_lq035q1_calc_timing(struct bfin_lq035q1fb_info
*fbi
)
208 unsigned long clocks_per_pix
, cpld_pipeline_delay_cor
;
211 * Interface 16/18-bit TFT over an 8-bit wide PPI using a small
212 * Programmable Logic Device (CPLD)
213 * http://blackfin.uclinux.org/gf/project/stamp/frs/?action=FrsReleaseBrowse&frs_package_id=165
216 switch (fbi
->disp_info
->ppi_mode
) {
217 case USE_RGB565_16_BIT_PPI
:
220 cpld_pipeline_delay_cor
= 0;
222 case USE_RGB565_8_BIT_PPI
:
225 cpld_pipeline_delay_cor
= 3;
227 case USE_RGB888_8_BIT_PPI
:
230 cpld_pipeline_delay_cor
= 5;
237 * HS and VS timing parameters (all in number of PPI clk ticks)
240 fbi
->h_actpix
= (LCD_X_RES
* clocks_per_pix
); /* active horizontal pixel */
241 fbi
->h_period
= (336 * clocks_per_pix
); /* HS period */
242 fbi
->h_pulse
= (2 * clocks_per_pix
); /* HS pulse width */
243 fbi
->h_start
= (7 * clocks_per_pix
+ cpld_pipeline_delay_cor
); /* first valid pixel */
245 fbi
->v_lines
= (LCD_Y_RES
+ U_LINE
); /* total vertical lines */
246 fbi
->v_pulse
= (2 * clocks_per_pix
); /* VS pulse width (1-5 H_PERIODs) */
247 fbi
->v_period
= (fbi
->h_period
* fbi
->v_lines
); /* VS period */
252 static void bfin_lq035q1_config_ppi(struct bfin_lq035q1fb_info
*fbi
)
256 if (fbi
->disp_info
->ppi_mode
== USE_RGB565_16_BIT_PPI
)
259 ppi_pmode
= (DLEN_8
| PACK_EN
);
261 bfin_write_PPI_DELAY(fbi
->h_start
);
262 bfin_write_PPI_COUNT(fbi
->h_actpix
- 1);
263 bfin_write_PPI_FRAME(fbi
->v_lines
);
265 bfin_write_PPI_CONTROL(PPI_TX_MODE
| /* output mode , PORT_DIR */
266 PPI_XFER_TYPE_11
| /* sync mode XFR_TYPE */
267 PPI_PORT_CFG_01
| /* two frame sync PORT_CFG */
268 ppi_pmode
| /* 8/16 bit data length / PACK_EN? */
269 PPI_POLS_1
); /* faling edge syncs POLS */
272 static inline void bfin_lq035q1_disable_ppi(void)
274 bfin_write_PPI_CONTROL(bfin_read_PPI_CONTROL() & ~PORT_EN
);
277 static inline void bfin_lq035q1_enable_ppi(void)
279 bfin_write_PPI_CONTROL(bfin_read_PPI_CONTROL() | PORT_EN
);
282 static void bfin_lq035q1_start_timers(void)
284 enable_gptimers(TIMER_VSYNCbit
| TIMER_HSYNCbit
);
287 static void bfin_lq035q1_stop_timers(void)
289 disable_gptimers(TIMER_HSYNCbit
| TIMER_VSYNCbit
);
291 set_gptimer_status(0, TIMER_HSYNC_STATUS_TRUN
| TIMER_VSYNC_STATUS_TRUN
|
292 TIMER_HSYNC_STATUS_TIMIL
| TIMER_VSYNC_STATUS_TIMIL
|
293 TIMER_HSYNC_STATUS_TOVF
| TIMER_VSYNC_STATUS_TOVF
);
297 static void bfin_lq035q1_init_timers(struct bfin_lq035q1fb_info
*fbi
)
300 bfin_lq035q1_stop_timers();
302 set_gptimer_period(TIMER_HSYNC_id
, fbi
->h_period
);
303 set_gptimer_pwidth(TIMER_HSYNC_id
, fbi
->h_pulse
);
304 set_gptimer_config(TIMER_HSYNC_id
, TIMER_MODE_PWM
| TIMER_PERIOD_CNT
|
305 TIMER_TIN_SEL
| TIMER_CLK_SEL
|
308 set_gptimer_period(TIMER_VSYNC_id
, fbi
->v_period
);
309 set_gptimer_pwidth(TIMER_VSYNC_id
, fbi
->v_pulse
);
310 set_gptimer_config(TIMER_VSYNC_id
, TIMER_MODE_PWM
| TIMER_PERIOD_CNT
|
311 TIMER_TIN_SEL
| TIMER_CLK_SEL
|
316 static void bfin_lq035q1_config_dma(struct bfin_lq035q1fb_info
*fbi
)
320 set_dma_config(CH_PPI
,
321 set_bfin_dma_config(DIR_READ
, DMA_FLOW_AUTO
,
322 INTR_DISABLE
, DIMENSION_2D
,
324 DMA_NOSYNC_KEEP_DMA_BUF
));
325 set_dma_x_count(CH_PPI
, (LCD_X_RES
* fbi
->lcd_bpp
) / DMA_BUS_SIZE
);
326 set_dma_x_modify(CH_PPI
, DMA_BUS_SIZE
/ 8);
327 set_dma_y_count(CH_PPI
, fbi
->v_lines
);
329 set_dma_y_modify(CH_PPI
, DMA_BUS_SIZE
/ 8);
330 set_dma_start_addr(CH_PPI
, (unsigned long)fbi
->fb_buffer
);
334 static const u16 ppi0_req_16
[] = {P_PPI0_CLK
, P_PPI0_FS1
, P_PPI0_FS2
,
335 P_PPI0_D0
, P_PPI0_D1
, P_PPI0_D2
,
336 P_PPI0_D3
, P_PPI0_D4
, P_PPI0_D5
,
337 P_PPI0_D6
, P_PPI0_D7
, P_PPI0_D8
,
338 P_PPI0_D9
, P_PPI0_D10
, P_PPI0_D11
,
339 P_PPI0_D12
, P_PPI0_D13
, P_PPI0_D14
,
342 static const u16 ppi0_req_8
[] = {P_PPI0_CLK
, P_PPI0_FS1
, P_PPI0_FS2
,
343 P_PPI0_D0
, P_PPI0_D1
, P_PPI0_D2
,
344 P_PPI0_D3
, P_PPI0_D4
, P_PPI0_D5
,
345 P_PPI0_D6
, P_PPI0_D7
, 0};
347 static inline void bfin_lq035q1_free_ports(unsigned ppi16
)
350 peripheral_free_list(ppi0_req_16
);
352 peripheral_free_list(ppi0_req_8
);
354 if (ANOMALY_05000400
)
355 gpio_free(P_IDENT(P_PPI0_FS3
));
358 static int __devinit
bfin_lq035q1_request_ports(struct platform_device
*pdev
,
362 /* ANOMALY_05000400 - PPI Does Not Start Properly In Specific Mode:
365 if (ANOMALY_05000400
) {
366 int ret
= gpio_request(P_IDENT(P_PPI0_FS3
), "PPI_FS3");
369 gpio_direction_output(P_IDENT(P_PPI0_FS3
), 0);
373 ret
= peripheral_request_list(ppi0_req_16
, DRIVER_NAME
);
375 ret
= peripheral_request_list(ppi0_req_8
, DRIVER_NAME
);
378 dev_err(&pdev
->dev
, "requesting peripherals failed\n");
385 static int bfin_lq035q1_fb_open(struct fb_info
*info
, int user
)
387 struct bfin_lq035q1fb_info
*fbi
= info
->par
;
389 spin_lock(&fbi
->lock
);
390 fbi
->lq035_open_cnt
++;
392 if (fbi
->lq035_open_cnt
<= 1) {
394 bfin_lq035q1_disable_ppi();
397 bfin_lq035q1_config_dma(fbi
);
398 bfin_lq035q1_config_ppi(fbi
);
399 bfin_lq035q1_init_timers(fbi
);
403 bfin_lq035q1_enable_ppi();
404 bfin_lq035q1_start_timers();
405 lq035q1_backlight(fbi
, 1);
408 spin_unlock(&fbi
->lock
);
413 static int bfin_lq035q1_fb_release(struct fb_info
*info
, int user
)
415 struct bfin_lq035q1fb_info
*fbi
= info
->par
;
417 spin_lock(&fbi
->lock
);
419 fbi
->lq035_open_cnt
--;
421 if (fbi
->lq035_open_cnt
<= 0) {
422 lq035q1_backlight(fbi
, 0);
423 bfin_lq035q1_disable_ppi();
426 bfin_lq035q1_stop_timers();
429 spin_unlock(&fbi
->lock
);
434 static int bfin_lq035q1_fb_check_var(struct fb_var_screeninfo
*var
,
435 struct fb_info
*info
)
437 struct bfin_lq035q1fb_info
*fbi
= info
->par
;
439 if (var
->bits_per_pixel
== fbi
->lcd_bpp
) {
440 var
->red
.offset
= info
->var
.red
.offset
;
441 var
->green
.offset
= info
->var
.green
.offset
;
442 var
->blue
.offset
= info
->var
.blue
.offset
;
443 var
->red
.length
= info
->var
.red
.length
;
444 var
->green
.length
= info
->var
.green
.length
;
445 var
->blue
.length
= info
->var
.blue
.length
;
446 var
->transp
.offset
= 0;
447 var
->transp
.length
= 0;
448 var
->transp
.msb_right
= 0;
449 var
->red
.msb_right
= 0;
450 var
->green
.msb_right
= 0;
451 var
->blue
.msb_right
= 0;
453 pr_debug("%s: depth not supported: %u BPP\n", __func__
,
454 var
->bits_per_pixel
);
458 if (info
->var
.xres
!= var
->xres
|| info
->var
.yres
!= var
->yres
||
459 info
->var
.xres_virtual
!= var
->xres_virtual
||
460 info
->var
.yres_virtual
!= var
->yres_virtual
) {
461 pr_debug("%s: Resolution not supported: X%u x Y%u \n",
462 __func__
, var
->xres
, var
->yres
);
470 if ((info
->fix
.line_length
* var
->yres_virtual
) > info
->fix
.smem_len
) {
471 pr_debug("%s: Memory Limit requested yres_virtual = %u\n",
472 __func__
, var
->yres_virtual
);
480 int bfin_lq035q1_fb_cursor(struct fb_info
*info
, struct fb_cursor
*cursor
)
485 return -EINVAL
; /* just to force soft_cursor() call */
488 static int bfin_lq035q1_fb_setcolreg(u_int regno
, u_int red
, u_int green
,
489 u_int blue
, u_int transp
,
490 struct fb_info
*info
)
492 if (regno
>= BFIN_LCD_NBR_PALETTE_ENTRIES
)
495 if (info
->var
.grayscale
) {
496 /* grayscale = 0.30*R + 0.59*G + 0.11*B */
497 red
= green
= blue
= (red
* 77 + green
* 151 + blue
* 28) >> 8;
500 if (info
->fix
.visual
== FB_VISUAL_TRUECOLOR
) {
503 /* Place color in the pseudopalette */
507 red
>>= (16 - info
->var
.red
.length
);
508 green
>>= (16 - info
->var
.green
.length
);
509 blue
>>= (16 - info
->var
.blue
.length
);
511 value
= (red
<< info
->var
.red
.offset
) |
512 (green
<< info
->var
.green
.offset
) |
513 (blue
<< info
->var
.blue
.offset
);
516 ((u32
*) (info
->pseudo_palette
))[regno
] = value
;
523 static struct fb_ops bfin_lq035q1_fb_ops
= {
524 .owner
= THIS_MODULE
,
525 .fb_open
= bfin_lq035q1_fb_open
,
526 .fb_release
= bfin_lq035q1_fb_release
,
527 .fb_check_var
= bfin_lq035q1_fb_check_var
,
528 .fb_fillrect
= cfb_fillrect
,
529 .fb_copyarea
= cfb_copyarea
,
530 .fb_imageblit
= cfb_imageblit
,
531 .fb_cursor
= bfin_lq035q1_fb_cursor
,
532 .fb_setcolreg
= bfin_lq035q1_fb_setcolreg
,
535 static irqreturn_t
bfin_lq035q1_irq_error(int irq
, void *dev_id
)
537 /*struct bfin_lq035q1fb_info *info = (struct bfin_lq035q1fb_info *)dev_id;*/
539 u16 status
= bfin_read_PPI_STATUS();
540 bfin_write_PPI_STATUS(-1);
543 bfin_lq035q1_disable_ppi();
548 bfin_lq035q1_enable_ppi();
549 bfin_write_PPI_STATUS(-1);
555 static int __devinit
bfin_lq035q1_probe(struct platform_device
*pdev
)
557 struct bfin_lq035q1fb_info
*info
;
558 struct fb_info
*fbinfo
;
559 u32 active_video_mem_offset
;
562 ret
= request_dma(CH_PPI
, DRIVER_NAME
"_CH_PPI");
564 dev_err(&pdev
->dev
, "PPI DMA unavailable\n");
568 fbinfo
= framebuffer_alloc(sizeof(*info
), &pdev
->dev
);
576 info
->dev
= &pdev
->dev
;
578 info
->disp_info
= pdev
->dev
.platform_data
;
580 platform_set_drvdata(pdev
, fbinfo
);
582 ret
= bfin_lq035q1_calc_timing(info
);
584 dev_err(&pdev
->dev
, "Failed PPI Mode\n");
588 strcpy(fbinfo
->fix
.id
, DRIVER_NAME
);
590 fbinfo
->fix
.type
= FB_TYPE_PACKED_PIXELS
;
591 fbinfo
->fix
.type_aux
= 0;
592 fbinfo
->fix
.xpanstep
= 0;
593 fbinfo
->fix
.ypanstep
= 0;
594 fbinfo
->fix
.ywrapstep
= 0;
595 fbinfo
->fix
.accel
= FB_ACCEL_NONE
;
596 fbinfo
->fix
.visual
= FB_VISUAL_TRUECOLOR
;
598 fbinfo
->var
.nonstd
= 0;
599 fbinfo
->var
.activate
= FB_ACTIVATE_NOW
;
600 fbinfo
->var
.height
= -1;
601 fbinfo
->var
.width
= -1;
602 fbinfo
->var
.accel_flags
= 0;
603 fbinfo
->var
.vmode
= FB_VMODE_NONINTERLACED
;
605 fbinfo
->var
.xres
= LCD_X_RES
;
606 fbinfo
->var
.xres_virtual
= LCD_X_RES
;
607 fbinfo
->var
.yres
= LCD_Y_RES
;
608 fbinfo
->var
.yres_virtual
= LCD_Y_RES
;
609 fbinfo
->var
.bits_per_pixel
= info
->lcd_bpp
;
611 if (info
->disp_info
->mode
& LQ035_BGR
) {
612 if (info
->lcd_bpp
== 24) {
613 fbinfo
->var
.red
.offset
= 0;
614 fbinfo
->var
.green
.offset
= 8;
615 fbinfo
->var
.blue
.offset
= 16;
617 fbinfo
->var
.red
.offset
= 0;
618 fbinfo
->var
.green
.offset
= 5;
619 fbinfo
->var
.blue
.offset
= 11;
622 if (info
->lcd_bpp
== 24) {
623 fbinfo
->var
.red
.offset
= 16;
624 fbinfo
->var
.green
.offset
= 8;
625 fbinfo
->var
.blue
.offset
= 0;
627 fbinfo
->var
.red
.offset
= 11;
628 fbinfo
->var
.green
.offset
= 5;
629 fbinfo
->var
.blue
.offset
= 0;
633 fbinfo
->var
.transp
.offset
= 0;
635 if (info
->lcd_bpp
== 24) {
636 fbinfo
->var
.red
.length
= 8;
637 fbinfo
->var
.green
.length
= 8;
638 fbinfo
->var
.blue
.length
= 8;
640 fbinfo
->var
.red
.length
= 5;
641 fbinfo
->var
.green
.length
= 6;
642 fbinfo
->var
.blue
.length
= 5;
645 fbinfo
->var
.transp
.length
= 0;
647 active_video_mem_offset
= ((U_LINE
/ 2) * LCD_X_RES
* (info
->lcd_bpp
/ 8));
649 fbinfo
->fix
.smem_len
= LCD_X_RES
* LCD_Y_RES
* info
->lcd_bpp
/ 8
650 + active_video_mem_offset
;
652 fbinfo
->fix
.line_length
= fbinfo
->var
.xres_virtual
*
653 fbinfo
->var
.bits_per_pixel
/ 8;
656 fbinfo
->fbops
= &bfin_lq035q1_fb_ops
;
657 fbinfo
->flags
= FBINFO_FLAG_DEFAULT
;
660 dma_alloc_coherent(NULL
, fbinfo
->fix
.smem_len
, &info
->dma_handle
,
663 if (NULL
== info
->fb_buffer
) {
664 dev_err(&pdev
->dev
, "couldn't allocate dma buffer\n");
669 fbinfo
->screen_base
= (void *)info
->fb_buffer
+ active_video_mem_offset
;
670 fbinfo
->fix
.smem_start
= (int)info
->fb_buffer
+ active_video_mem_offset
;
672 fbinfo
->fbops
= &bfin_lq035q1_fb_ops
;
674 fbinfo
->pseudo_palette
= &info
->pseudo_pal
;
676 ret
= fb_alloc_cmap(&fbinfo
->cmap
, BFIN_LCD_NBR_PALETTE_ENTRIES
, 0);
678 dev_err(&pdev
->dev
, "failed to allocate colormap (%d entries)\n",
679 BFIN_LCD_NBR_PALETTE_ENTRIES
);
683 ret
= bfin_lq035q1_request_ports(pdev
,
684 info
->disp_info
->ppi_mode
== USE_RGB565_16_BIT_PPI
);
686 dev_err(&pdev
->dev
, "couldn't request gpio port\n");
690 info
->irq
= platform_get_irq(pdev
, 0);
696 ret
= request_irq(info
->irq
, bfin_lq035q1_irq_error
, IRQF_DISABLED
,
697 DRIVER_NAME
" PPI ERROR", info
);
699 dev_err(&pdev
->dev
, "unable to request PPI ERROR IRQ\n");
703 info
->spidrv
.driver
.name
= DRIVER_NAME
"-spi";
704 info
->spidrv
.probe
= lq035q1_spidev_probe
;
705 info
->spidrv
.remove
= __devexit_p(lq035q1_spidev_remove
);
706 info
->spidrv
.shutdown
= lq035q1_spidev_shutdown
;
707 info
->spidrv
.suspend
= lq035q1_spidev_suspend
;
708 info
->spidrv
.resume
= lq035q1_spidev_resume
;
710 ret
= spi_register_driver(&info
->spidrv
);
712 dev_err(&pdev
->dev
, "couldn't register SPI Interface\n");
716 if (info
->disp_info
->use_bl
) {
717 ret
= gpio_request(info
->disp_info
->gpio_bl
, "LQ035 Backlight");
720 dev_err(&pdev
->dev
, "failed to request GPIO %d\n",
721 info
->disp_info
->gpio_bl
);
724 gpio_direction_output(info
->disp_info
->gpio_bl
, 0);
727 ret
= register_framebuffer(fbinfo
);
729 dev_err(&pdev
->dev
, "unable to register framebuffer\n");
733 dev_info(&pdev
->dev
, "%dx%d %d-bit RGB FrameBuffer initialized\n",
734 LCD_X_RES
, LCD_Y_RES
, info
->lcd_bpp
);
739 if (info
->disp_info
->use_bl
)
740 gpio_free(info
->disp_info
->gpio_bl
);
742 spi_unregister_driver(&info
->spidrv
);
744 free_irq(info
->irq
, info
);
746 bfin_lq035q1_free_ports(info
->disp_info
->ppi_mode
==
747 USE_RGB565_16_BIT_PPI
);
749 fb_dealloc_cmap(&fbinfo
->cmap
);
751 dma_free_coherent(NULL
, fbinfo
->fix
.smem_len
, info
->fb_buffer
,
754 framebuffer_release(fbinfo
);
758 platform_set_drvdata(pdev
, NULL
);
763 static int __devexit
bfin_lq035q1_remove(struct platform_device
*pdev
)
765 struct fb_info
*fbinfo
= platform_get_drvdata(pdev
);
766 struct bfin_lq035q1fb_info
*info
= fbinfo
->par
;
768 if (info
->disp_info
->use_bl
)
769 gpio_free(info
->disp_info
->gpio_bl
);
771 spi_unregister_driver(&info
->spidrv
);
773 unregister_framebuffer(fbinfo
);
776 free_irq(info
->irq
, info
);
778 if (info
->fb_buffer
!= NULL
)
779 dma_free_coherent(NULL
, fbinfo
->fix
.smem_len
, info
->fb_buffer
,
782 fb_dealloc_cmap(&fbinfo
->cmap
);
784 bfin_lq035q1_free_ports(info
->disp_info
->ppi_mode
==
785 USE_RGB565_16_BIT_PPI
);
787 platform_set_drvdata(pdev
, NULL
);
788 framebuffer_release(fbinfo
);
790 dev_info(&pdev
->dev
, "unregistered LCD driver\n");
796 static int bfin_lq035q1_suspend(struct device
*dev
)
798 struct fb_info
*fbinfo
= dev_get_drvdata(dev
);
799 struct bfin_lq035q1fb_info
*info
= fbinfo
->par
;
801 if (info
->lq035_open_cnt
) {
802 lq035q1_backlight(info
, 0);
803 bfin_lq035q1_disable_ppi();
806 bfin_lq035q1_stop_timers();
807 bfin_write_PPI_STATUS(-1);
813 static int bfin_lq035q1_resume(struct device
*dev
)
815 struct fb_info
*fbinfo
= dev_get_drvdata(dev
);
816 struct bfin_lq035q1fb_info
*info
= fbinfo
->par
;
818 if (info
->lq035_open_cnt
) {
819 bfin_lq035q1_disable_ppi();
822 bfin_lq035q1_config_dma(info
);
823 bfin_lq035q1_config_ppi(info
);
824 bfin_lq035q1_init_timers(info
);
828 bfin_lq035q1_enable_ppi();
829 bfin_lq035q1_start_timers();
830 lq035q1_backlight(info
, 1);
836 static struct dev_pm_ops bfin_lq035q1_dev_pm_ops
= {
837 .suspend
= bfin_lq035q1_suspend
,
838 .resume
= bfin_lq035q1_resume
,
842 static struct platform_driver bfin_lq035q1_driver
= {
843 .probe
= bfin_lq035q1_probe
,
844 .remove
= __devexit_p(bfin_lq035q1_remove
),
848 .pm
= &bfin_lq035q1_dev_pm_ops
,
853 static int __init
bfin_lq035q1_driver_init(void)
855 return platform_driver_register(&bfin_lq035q1_driver
);
857 module_init(bfin_lq035q1_driver_init
);
859 static void __exit
bfin_lq035q1_driver_cleanup(void)
861 platform_driver_unregister(&bfin_lq035q1_driver
);
863 module_exit(bfin_lq035q1_driver_cleanup
);
865 MODULE_DESCRIPTION("Blackfin TFT LCD Driver");
866 MODULE_LICENSE("GPL");