12 #include <linux/module.h>
13 #include <linux/kernel.h>
15 #include <linux/sched.h>
16 #include <linux/errno.h>
17 #include <linux/string.h>
19 #include <linux/slab.h>
31 #include <mach/hardware.h>
36 #include <asm/uaccess.h>
38 #define MX3FB_NAME "mx3_sdc_fb"
40 #define MX3FB_REG_OFFSET 0xB4
43 #define SDC_COM_CONF (0xB4 - MX3FB_REG_OFFSET)
44 #define SDC_GW_CTRL (0xB8 - MX3FB_REG_OFFSET)
45 #define SDC_FG_POS (0xBC - MX3FB_REG_OFFSET)
46 #define SDC_BG_POS (0xC0 - MX3FB_REG_OFFSET)
47 #define SDC_CUR_POS (0xC4 - MX3FB_REG_OFFSET)
48 #define SDC_PWM_CTRL (0xC8 - MX3FB_REG_OFFSET)
49 #define SDC_CUR_MAP (0xCC - MX3FB_REG_OFFSET)
50 #define SDC_HOR_CONF (0xD0 - MX3FB_REG_OFFSET)
51 #define SDC_VER_CONF (0xD4 - MX3FB_REG_OFFSET)
52 #define SDC_SHARP_CONF_1 (0xD8 - MX3FB_REG_OFFSET)
53 #define SDC_SHARP_CONF_2 (0xDC - MX3FB_REG_OFFSET)
56 #define SDC_COM_TFT_COLOR 0x00000001UL
57 #define SDC_COM_FG_EN 0x00000010UL
58 #define SDC_COM_GWSEL 0x00000020UL
59 #define SDC_COM_GLB_A 0x00000040UL
60 #define SDC_COM_KEY_COLOR_G 0x00000080UL
61 #define SDC_COM_BG_EN 0x00000200UL
62 #define SDC_COM_SHARP 0x00001000UL
64 #define SDC_V_SYNC_WIDTH_L 0x00000001UL
67 #define DI_DISP_IF_CONF (0x0124 - MX3FB_REG_OFFSET)
68 #define DI_DISP_SIG_POL (0x0128 - MX3FB_REG_OFFSET)
69 #define DI_SER_DISP1_CONF (0x012C - MX3FB_REG_OFFSET)
70 #define DI_SER_DISP2_CONF (0x0130 - MX3FB_REG_OFFSET)
71 #define DI_HSP_CLK_PER (0x0134 - MX3FB_REG_OFFSET)
72 #define DI_DISP0_TIME_CONF_1 (0x0138 - MX3FB_REG_OFFSET)
73 #define DI_DISP0_TIME_CONF_2 (0x013C - MX3FB_REG_OFFSET)
74 #define DI_DISP0_TIME_CONF_3 (0x0140 - MX3FB_REG_OFFSET)
75 #define DI_DISP1_TIME_CONF_1 (0x0144 - MX3FB_REG_OFFSET)
76 #define DI_DISP1_TIME_CONF_2 (0x0148 - MX3FB_REG_OFFSET)
77 #define DI_DISP1_TIME_CONF_3 (0x014C - MX3FB_REG_OFFSET)
78 #define DI_DISP2_TIME_CONF_1 (0x0150 - MX3FB_REG_OFFSET)
79 #define DI_DISP2_TIME_CONF_2 (0x0154 - MX3FB_REG_OFFSET)
80 #define DI_DISP2_TIME_CONF_3 (0x0158 - MX3FB_REG_OFFSET)
81 #define DI_DISP3_TIME_CONF (0x015C - MX3FB_REG_OFFSET)
82 #define DI_DISP0_DB0_MAP (0x0160 - MX3FB_REG_OFFSET)
83 #define DI_DISP0_DB1_MAP (0x0164 - MX3FB_REG_OFFSET)
84 #define DI_DISP0_DB2_MAP (0x0168 - MX3FB_REG_OFFSET)
85 #define DI_DISP0_CB0_MAP (0x016C - MX3FB_REG_OFFSET)
86 #define DI_DISP0_CB1_MAP (0x0170 - MX3FB_REG_OFFSET)
87 #define DI_DISP0_CB2_MAP (0x0174 - MX3FB_REG_OFFSET)
88 #define DI_DISP1_DB0_MAP (0x0178 - MX3FB_REG_OFFSET)
89 #define DI_DISP1_DB1_MAP (0x017C - MX3FB_REG_OFFSET)
90 #define DI_DISP1_DB2_MAP (0x0180 - MX3FB_REG_OFFSET)
91 #define DI_DISP1_CB0_MAP (0x0184 - MX3FB_REG_OFFSET)
92 #define DI_DISP1_CB1_MAP (0x0188 - MX3FB_REG_OFFSET)
93 #define DI_DISP1_CB2_MAP (0x018C - MX3FB_REG_OFFSET)
94 #define DI_DISP2_DB0_MAP (0x0190 - MX3FB_REG_OFFSET)
95 #define DI_DISP2_DB1_MAP (0x0194 - MX3FB_REG_OFFSET)
96 #define DI_DISP2_DB2_MAP (0x0198 - MX3FB_REG_OFFSET)
97 #define DI_DISP2_CB0_MAP (0x019C - MX3FB_REG_OFFSET)
98 #define DI_DISP2_CB1_MAP (0x01A0 - MX3FB_REG_OFFSET)
99 #define DI_DISP2_CB2_MAP (0x01A4 - MX3FB_REG_OFFSET)
100 #define DI_DISP3_B0_MAP (0x01A8 - MX3FB_REG_OFFSET)
101 #define DI_DISP3_B1_MAP (0x01AC - MX3FB_REG_OFFSET)
102 #define DI_DISP3_B2_MAP (0x01B0 - MX3FB_REG_OFFSET)
103 #define DI_DISP_ACC_CC (0x01B4 - MX3FB_REG_OFFSET)
104 #define DI_DISP_LLA_CONF (0x01B8 - MX3FB_REG_OFFSET)
105 #define DI_DISP_LLA_DATA (0x01BC - MX3FB_REG_OFFSET)
108 #define DI_D3_VSYNC_POL_SHIFT 28
109 #define DI_D3_HSYNC_POL_SHIFT 27
110 #define DI_D3_DRDY_SHARP_POL_SHIFT 26
111 #define DI_D3_CLK_POL_SHIFT 25
112 #define DI_D3_DATA_POL_SHIFT 24
115 #define DI_D3_CLK_IDLE_SHIFT 26
116 #define DI_D3_CLK_SEL_SHIFT 25
117 #define DI_D3_DATAMSK_SHIFT 24
138 .name =
"Sharp-QVGA",
164 .lower_margin = 9 + 287,
196 .right_margin = 858 - 640 - 38 - 3,
198 .lower_margin = 518 - 480 - 36 - 1,
212 .right_margin = 960 - 640 - 38 - 32,
214 .lower_margin = 555 - 480 - 32 - 3,
275 static void mx3fb_dma_done(
void *);
278 static const char *fb_mode;
279 static unsigned long default_bpp = 16;
295 static const struct di_mapping di_mappings[] = {
301 static void sdc_fb_init(
struct mx3fb_info *fbi)
324 static void sdc_enable_channel(
struct mx3fb_info *mx3_fbi)
333 dev_dbg(mx3fb->
dev,
"mx3fbi %p, desc %p, sg %p\n", mx3_fbi,
336 dev_dbg(mx3fb->
dev,
"mx3fbi %p, txd = NULL\n", mx3_fbi);
339 if (mx3_fbi->
cookie < 0) {
340 mx3_fbi->
txd = dmaengine_prep_slave_sg(dma_chan,
343 dev_err(mx3fb->
dev,
"Cannot allocate descriptor on %d\n",
348 mx3_fbi->
txd->callback_param = mx3_fbi->
txd;
349 mx3_fbi->
txd->callback = mx3fb_dma_done;
351 cookie = mx3_fbi->
txd->tx_submit(mx3_fbi->
txd);
352 dev_dbg(mx3fb->
dev,
"%d: Submit %p #%d [%c]\n", __LINE__,
353 mx3_fbi->
txd, cookie, list_empty(&ichan->
queue) ?
'-' :
'+');
355 if (!mx3_fbi->
txd || !mx3_fbi->
txd->tx_submit) {
356 dev_err(mx3fb->
dev,
"Cannot enable channel %d\n",
362 dma_async_issue_pending(dma_chan);
364 dev_dbg(mx3fb->
dev,
"%d: Re-submit %p #%d [%c]\n", __LINE__,
365 mx3_fbi->
txd, cookie, list_empty(&ichan->
queue) ?
'-' :
'+');
370 sdc_fb_init(mx3_fbi);
372 spin_unlock_irqrestore(&mx3fb->
lock, flags);
383 static void sdc_disable_channel(
struct mx3fb_info *mx3_fbi)
394 enabled = sdc_fb_uninit(mx3_fbi);
396 spin_unlock_irqrestore(&mx3fb->
lock, flags);
398 mx3_fbi->
txd->chan->device->device_control(mx3_fbi->
txd->chan,
421 mx3fb_write_reg(mx3fb, (x_pos << 16) | y_pos,
SDC_BG_POS);
460 dev_dbg(mx3fb->
dev,
"panel size = %d x %d", width, height);
462 if (v_sync_width == 0 || h_sync_width == 0)
466 reg = ((
uint32_t) (h_sync_width - 1) << 26) |
467 ((
uint32_t) (width + h_start_width + h_end_width - 1) << 16);
475 ((
uint32_t) (height + v_start_width + v_end_width - 1) << 16);
506 if (!IS_ERR(ipu_clk)) {
515 "InitPanel() - Pixel clock divider less than 4\n");
519 dev_dbg(mx3fb->
dev,
"pixel clk = %u, divider %u.%u\n",
520 pixel_clk, div >> 4, (div & 7) * 125);
551 spin_unlock_irqrestore(&mx3fb->
lock, lock_flags);
553 dev_dbg(mx3fb->
dev,
"DI_DISP_IF_CONF = 0x%08X\n",
555 dev_dbg(mx3fb->
dev,
"DI_DISP_SIG_POL = 0x%08X\n",
557 dev_dbg(mx3fb->
dev,
"DI_DISP3_TIME_CONF = 0x%08X\n",
587 mx3fb_write_reg(mx3fb, reg | (color_key & 0x00FFFFFFL),
596 spin_unlock_irqrestore(&mx3fb->
lock, lock_flags);
627 spin_unlock_irqrestore(&mx3fb->
lock, lock_flags);
634 dev_dbg(mx3fb->
dev,
"%s: value = %d\n", __func__, value);
636 mx3fb_write_reg(mx3fb, 0x03000000UL | value << 16,
SDC_PWM_CTRL);
657 static int mx3fb_blank(
int blank,
struct fb_info *fbi);
658 static int mx3fb_map_video_memory(
struct fb_info *fbi,
unsigned int mem_len,
660 static int mx3fb_unmap_video_memory(
struct fb_info *fbi);
667 static int mx3fb_set_fix(
struct fb_info *fbi)
685 static void mx3fb_dma_done(
void *
arg)
688 struct dma_chan *
chan = tx_desc->
txd.chan;
701 static bool mx3fb_must_set_par(
struct fb_info *fbi)
721 static int __set_par(
struct fb_info *fbi,
bool lock)
723 u32 mem_len, cur_xoffset, cur_yoffset;
734 sdc_disable_channel(mx3_fbi);
738 mem_len = fbi->
var.yres_virtual * fbi->
fix.line_length;
739 if (mem_len > fbi->
fix.smem_len) {
740 if (fbi->
fix.smem_start)
741 mx3fb_unmap_video_memory(fbi);
743 if (mx3fb_map_video_memory(fbi, mem_len, lock) < 0)
756 memset(&sig_cfg, 0,
sizeof(sig_cfg));
758 sig_cfg.Hsync_pol =
true;
760 sig_cfg.Vsync_pol =
true;
762 sig_cfg.clk_pol =
true;
764 sig_cfg.data_pol =
true;
766 sig_cfg.enable_pol =
true;
768 sig_cfg.clkidle_en =
true;
770 sig_cfg.clksel_en =
true;
777 if (sdc_init_panel(mx3fb, mode,
779 fbi->
var.xres, fbi->
var.yres,
780 fbi->
var.left_margin,
782 fbi->
var.right_margin +
784 fbi->
var.upper_margin,
786 fbi->
var.lower_margin +
787 fbi->
var.vsync_len, sig_cfg) != 0) {
789 "mx3fb: Error initializing panel.\n");
794 sdc_set_window_pos(mx3fb, mx3_fbi->
ipu_ch, 0, 0);
804 sdc_enable_channel(mx3_fbi);
817 cur_xoffset = mx3_fbi->
cur_var.xoffset;
818 cur_yoffset = mx3_fbi->
cur_var.yoffset;
820 mx3_fbi->
cur_var.xoffset = cur_xoffset;
821 mx3_fbi->
cur_var.yoffset = cur_yoffset;
831 static int mx3fb_set_par(
struct fb_info *fbi)
838 dev_dbg(mx3fb->
dev,
"%s [%c]\n", __func__, list_empty(&ichan->
queue) ?
'-' :
'+');
842 ret = mx3fb_must_set_par(fbi) ? __set_par(fbi,
true) : 0;
874 var->
red.offset = 11;
875 var->
red.msb_right = 0;
877 var->
green.length = 6;
878 var->
green.offset = 5;
879 var->
green.msb_right = 0;
881 var->
blue.length = 5;
882 var->
blue.offset = 0;
883 var->
blue.msb_right = 0;
887 var->
transp.msb_right = 0;
891 var->
red.offset = 16;
892 var->
red.msb_right = 0;
894 var->
green.length = 8;
895 var->
green.offset = 8;
896 var->
green.msb_right = 0;
898 var->
blue.length = 8;
899 var->
blue.offset = 0;
900 var->
blue.msb_right = 0;
904 var->
transp.msb_right = 0;
908 var->
red.offset = 16;
909 var->
red.msb_right = 0;
911 var->
green.length = 8;
912 var->
green.offset = 8;
913 var->
green.msb_right = 0;
915 var->
blue.length = 8;
916 var->
blue.offset = 0;
917 var->
blue.msb_right = 0;
921 var->
transp.msb_right = 0;
932 dev_dbg(fbi->
device,
"pixclock set for 60Hz refresh = %u ps\n",
951 return chan << bf->
offset;
954 static int mx3fb_setcolreg(
unsigned int regno,
unsigned int red,
969 if (fbi->
var.grayscale)
970 red = green = blue = (19595 * red + 38470 * green +
972 switch (fbi->
fix.visual) {
981 val = chan_to_field(red, &fbi->
var.red);
982 val |= chan_to_field(green, &fbi->
var.green);
983 val |= chan_to_field(blue, &fbi->
var.blue);
1004 int was_blank = mx3_fbi->
blank;
1006 mx3_fbi->
blank = blank;
1022 sdc_set_brightness(mx3fb, 0);
1026 sdc_disable_channel(mx3_fbi);
1029 sdc_enable_channel(mx3_fbi);
1038 static int mx3fb_blank(
int blank,
struct fb_info *fbi)
1042 dev_dbg(fbi->
device,
"%s, blank = %d, base %p, len %u\n", __func__,
1045 if (mx3_fbi->
blank == blank)
1049 __blank(blank, fbi);
1071 struct dma_chan *dma_chan = &mx3_fbi->
idmac_channel->dma_chan;
1090 y_bottom += fbi->
var.yres;
1092 if (y_bottom > fbi->
var.yres_virtual)
1098 + var->
xoffset * (fbi->
var.bits_per_pixel / 8);
1101 dev_dbg(fbi->
device,
"Updating SDC BG buf %d address=0x%08lX\n",
1116 "user interrupt" :
"timeout");
1129 async_tx_ack(mx3_fbi->
txd);
1131 txd = dmaengine_prep_slave_sg(dma_chan, sg +
1135 "Error preparing a DMA transaction descriptor.\n");
1148 dev_dbg(fbi->
device,
"%d: Submit %p #%d\n", __LINE__, txd, cookie);
1151 "Error updating SDC buf %d to address=0x%08lX\n",
1181 static struct fb_ops mx3fb_ops = {
1183 .fb_set_par = mx3fb_set_par,
1184 .fb_check_var = mx3fb_check_var,
1185 .fb_setcolreg = mx3fb_setcolreg,
1186 .fb_pan_display = mx3fb_pan_display,
1190 .fb_blank = mx3fb_blank,
1204 struct mx3fb_data *mx3fb = platform_get_drvdata(pdev);
1212 sdc_disable_channel(mx3_fbi);
1213 sdc_set_brightness(mx3fb, 0);
1224 struct mx3fb_data *mx3fb = platform_get_drvdata(pdev);
1228 sdc_enable_channel(mx3_fbi);
1239 #define mx3fb_suspend NULL
1240 #define mx3fb_resume NULL
1259 static int mx3fb_map_video_memory(
struct fb_info *fbi,
unsigned int mem_len,
1270 dev_err(fbi->
device,
"Cannot allocate %u bytes framebuffer memory\n",
1279 fbi->
fix.smem_len = mem_len;
1283 dev_dbg(fbi->
device,
"allocated fb @ p=0x%08x, v=0x%p, size=%d.\n",
1294 fbi->
fix.smem_len = 0;
1295 fbi->
fix.smem_start = 0;
1305 static int mx3fb_unmap_video_memory(
struct fb_info *fbi)
1312 fbi->
fix.smem_start = 0;
1313 fbi->
fix.smem_len = 0;
1359 const char *
name = mx3fb_pdata->
name;
1367 dev_err(dev,
"Illegal display data format %d\n",
1378 fbi = mx3fb_init_fbinfo(dev, &mx3fb_ops);
1391 mode = mx3fb_pdata->
mode;
1394 mode = mx3fb_modedb;
1399 num_modes,
NULL, default_bpp)) {
1407 fbi->
var.yres_virtual = fbi->
var.yres * 2;
1415 sdc_set_brightness(mx3fb, 255);
1416 sdc_set_global_alpha(mx3fb,
true, 0xFF);
1422 mx3fbi->
mx3fb = mx3fb;
1430 ret = __set_par(fbi,
false);
1436 dev_info(dev,
"registered, using mode %s\n", fb_mode);
1453 static bool chan_filter(
struct dma_chan *
chan,
void *
arg)
1459 if (!imx_dma_is_ipu(chan))
1465 dev = rq->
mx3fb->dev;
1472 static void release_fbi(
struct fb_info *fbi)
1474 mx3fb_unmap_video_memory(fbi);
1489 struct dma_chan *chan;
1518 platform_set_drvdata(pdev, mx3fb);
1547 dev_err(dev,
"mx3fb: failed to register fb\n");
1553 struct mx3fb_data *mx3fb = platform_get_drvdata(dev);
1556 struct dma_chan *chan;
1574 .probe = mx3fb_probe,
1575 .remove = mx3fb_remove,
1585 static int __init mx3fb_setup(
void)
1593 if (!options || !*options)
1596 while ((opt =
strsep(&options,
",")) !=
NULL) {
1609 static int __init mx3fb_init(
void)
1611 int ret = mx3fb_setup();
1620 static void __exit mx3fb_exit(
void)