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>
17 #include <linux/slab.h>
19 #include <linux/types.h>
21 #include <linux/device.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
64 #define DMA_BUS_SIZE 16
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)
90 #define LQ035_ON (0 << 0)
133 dat[2] = value & 0xFF;
163 spi_set_drvdata(spi, ctl);
168 static int lq035q1_spidev_remove(
struct spi_device *spi)
191 # define lq035q1_spidev_suspend NULL
192 # define lq035q1_spidev_resume NULL
196 static void lq035q1_spidev_shutdown(
struct spi_device *spi)
211 unsigned long clocks_per_pix, cpld_pipeline_delay_cor;
223 cpld_pipeline_delay_cor = 0;
228 cpld_pipeline_delay_cor = 3;
233 cpld_pipeline_delay_cor = 5;
244 fbi->
h_period = (336 * clocks_per_pix);
245 fbi->
h_pulse = (2 * clocks_per_pix);
246 fbi->
h_start = (7 * clocks_per_pix + cpld_pipeline_delay_cor);
249 fbi->
v_pulse = (2 * clocks_per_pix);
275 static inline void bfin_lq035q1_disable_ppi(
void)
280 static inline void bfin_lq035q1_enable_ppi(
void)
285 static void bfin_lq035q1_start_timers(
void)
290 static void bfin_lq035q1_stop_timers(
void)
303 bfin_lq035q1_stop_timers();
350 static inline void bfin_lq035q1_free_ports(
unsigned ppi16)
381 dev_err(&pdev->
dev,
"requesting peripherals failed\n");
388 static int bfin_lq035q1_fb_open(
struct fb_info *info,
int user)
392 spin_lock(&fbi->
lock);
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)
420 spin_lock(&fbi->
lock);
425 lq035q1_backlight(fbi, 0);
426 bfin_lq035q1_disable_ppi();
429 bfin_lq035q1_stop_timers();
432 spin_unlock(&fbi->
lock);
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;
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__,
464 pr_debug(
"%s: Resolution not supported: X%u x Y%u \n",
474 pr_debug(
"%s: Memory Limit requested yres_virtual = %u\n",
498 if (info->
var.grayscale) {
500 red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8;
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);
526 static struct fb_ops bfin_lq035q1_fb_ops = {
528 .fb_open = bfin_lq035q1_fb_open,
529 .fb_release = bfin_lq035q1_fb_release,
530 .fb_check_var = bfin_lq035q1_fb_check_var,
535 .fb_setcolreg = bfin_lq035q1_fb_setcolreg,
546 bfin_lq035q1_disable_ppi();
551 bfin_lq035q1_enable_ppi();
562 u32 active_video_mem_offset;
584 platform_set_drvdata(pdev, fbinfo);
586 ret = bfin_lq035q1_calc_timing(info);
595 fbinfo->
fix.type_aux = 0;
596 fbinfo->
fix.xpanstep = 0;
597 fbinfo->
fix.ypanstep = 0;
598 fbinfo->
fix.ywrapstep = 0;
602 fbinfo->
var.nonstd = 0;
604 fbinfo->
var.height = -1;
605 fbinfo->
var.width = -1;
606 fbinfo->
var.accel_flags = 0;
617 fbinfo->
var.red.offset = 0;
618 fbinfo->
var.green.offset = 8;
619 fbinfo->
var.blue.offset = 16;
621 fbinfo->
var.red.offset = 0;
622 fbinfo->
var.green.offset = 5;
623 fbinfo->
var.blue.offset = 11;
627 fbinfo->
var.red.offset = 16;
628 fbinfo->
var.green.offset = 8;
629 fbinfo->
var.blue.offset = 0;
631 fbinfo->
var.red.offset = 11;
632 fbinfo->
var.green.offset = 5;
633 fbinfo->
var.blue.offset = 0;
637 fbinfo->
var.transp.offset = 0;
640 fbinfo->
var.red.length = 8;
641 fbinfo->
var.green.length = 8;
642 fbinfo->
var.blue.length = 8;
644 fbinfo->
var.red.length = 5;
645 fbinfo->
var.green.length = 6;
646 fbinfo->
var.blue.length = 5;
649 fbinfo->
var.transp.length = 0;
654 + active_video_mem_offset;
656 fbinfo->
fix.line_length = fbinfo->
var.xres_virtual *
657 fbinfo->
var.bits_per_pixel / 8;
660 fbinfo->
fbops = &bfin_lq035q1_fb_ops;
668 dev_err(&pdev->
dev,
"couldn't allocate dma buffer\n");
674 fbinfo->
fix.smem_start = (
int)info->
fb_buffer + active_video_mem_offset;
676 fbinfo->
fbops = &bfin_lq035q1_fb_ops;
682 dev_err(&pdev->
dev,
"failed to allocate colormap (%d entries)\n",
687 ret = bfin_lq035q1_request_ports(pdev,
690 dev_err(&pdev->
dev,
"couldn't request gpio port\n");
703 dev_err(&pdev->
dev,
"unable to request PPI ERROR IRQ\n");
708 info->
spidrv.probe = lq035q1_spidev_probe;
710 info->
spidrv.shutdown = lq035q1_spidev_shutdown;
716 dev_err(&pdev->
dev,
"couldn't register SPI Interface\n");
725 dev_err(&pdev->
dev,
"failed to request GPIO %d\n",
733 dev_err(&pdev->
dev,
"unable to register framebuffer\n");
737 dev_info(&pdev->
dev,
"%dx%d %d-bit RGB FrameBuffer initialized\n",
746 spi_unregister_driver(&info->
spidrv);
750 bfin_lq035q1_free_ports(info->
disp_info->ppi_mode ==
762 platform_set_drvdata(pdev,
NULL);
769 struct fb_info *fbinfo = platform_get_drvdata(pdev);
775 spi_unregister_driver(&info->
spidrv);
788 bfin_lq035q1_free_ports(info->
disp_info->ppi_mode ==
791 platform_set_drvdata(pdev,
NULL);
800 static int bfin_lq035q1_suspend(
struct device *
dev)
806 lq035q1_backlight(info, 0);
807 bfin_lq035q1_disable_ppi();
810 bfin_lq035q1_stop_timers();
817 static int bfin_lq035q1_resume(
struct device *dev)
823 bfin_lq035q1_disable_ppi();
826 bfin_lq035q1_config_dma(info);
827 bfin_lq035q1_config_ppi(info);
828 bfin_lq035q1_init_timers(info);
832 bfin_lq035q1_enable_ppi();
833 bfin_lq035q1_start_timers();
834 lq035q1_backlight(info, 1);
840 static struct dev_pm_ops bfin_lq035q1_dev_pm_ops = {
841 .
suspend = bfin_lq035q1_suspend,
842 .resume = bfin_lq035q1_resume,
847 .probe = bfin_lq035q1_probe,
852 .pm = &bfin_lq035q1_dev_pm_ops,