17 #include <linux/module.h>
18 #include <linux/kernel.h>
19 #include <linux/errno.h>
20 #include <linux/string.h>
22 #include <linux/slab.h>
36 #include <mach/hardware.h>
43 #if defined(CONFIG_BACKLIGHT_CLASS_DEVICE) || \
44 (defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE) && \
45 defined(CONFIG_FB_IMX_MODULE))
46 #define PWMR_BACKLIGHT_AVAILABLE
49 #define DRIVER_NAME "imx-fb"
53 #define LCDC_SIZE 0x04
54 #define SIZE_XMAX(x) ((((x) >> 4) & 0x3f) << 20)
56 #define YMAX_MASK (cpu_is_mx1() ? 0x1ff : 0x3ff)
57 #define SIZE_YMAX(y) ((y) & YMAX_MASK)
60 #define VPW_VPW(x) ((x) & 0x3ff)
62 #define LCDC_CPOS 0x0C
63 #define CPOS_CC1 (1<<31)
64 #define CPOS_CC0 (1<<30)
65 #define CPOS_OP (1<<28)
66 #define CPOS_CXP(x) (((x) & 3ff) << 16)
68 #define LCDC_LCWHB 0x10
69 #define LCWHB_BK_EN (1<<31)
70 #define LCWHB_CW(w) (((w) & 0x1f) << 24)
71 #define LCWHB_CH(h) (((h) & 0x1f) << 16)
72 #define LCWHB_BD(x) ((x) & 0xff)
74 #define LCDC_LCHCC 0x14
79 #define HCR_H_WIDTH(x) (((x) & 0x3f) << 26)
80 #define HCR_H_WAIT_1(x) (((x) & 0xff) << 8)
81 #define HCR_H_WAIT_2(x) ((x) & 0xff)
84 #define VCR_V_WIDTH(x) (((x) & 0x3f) << 26)
85 #define VCR_V_WAIT_1(x) (((x) & 0xff) << 8)
86 #define VCR_V_WAIT_2(x) ((x) & 0xff)
89 #define POS_POS(x) ((x) & 1f)
91 #define LCDC_LSCR1 0x28
94 #define LCDC_PWMR 0x2C
97 #define LCDC_DMACR 0x30
100 #define LCDC_RMCR 0x34
102 #define RMCR_LCDC_EN_MX1 (1<<1)
104 #define RMCR_SELF_REF (1<<0)
106 #define LCDC_LCDICR 0x38
107 #define LCDICR_INT_SYN (1<<2)
108 #define LCDICR_INT_CON (1)
110 #define LCDC_LCDISR 0x40
111 #define LCDISR_UDR_ERR (1<<3)
112 #define LCDISR_ERR_RES (1<<2)
113 #define LCDISR_EOF (1<<1)
114 #define LCDISR_BOF (1<<0)
117 static const char *fb_mode;
163 #ifdef PWMR_BACKLIGHT_AVAILABLE
171 #define IMX_NAME "IMX"
184 .red = {.offset = 16, .length = 8,},
185 .green = {.offset = 8, .length = 8,},
186 .blue = {.offset = 0, .length = 8,},
187 .transp = {.offset = 0, .length = 0,},
190 static struct imxfb_rgb def_rgb_16_tft = {
191 .red = {.offset = 11, .length = 5,},
192 .green = {.offset = 5, .length = 6,},
193 .blue = {.offset = 0, .length = 5,},
194 .transp = {.offset = 0, .length = 0,},
197 static struct imxfb_rgb def_rgb_16_stn = {
198 .red = {.offset = 8, .length = 4,},
199 .green = {.offset = 4, .length = 4,},
200 .blue = {.offset = 0, .length = 4,},
201 .transp = {.offset = 0, .length = 0,},
205 .red = {.offset = 0, .length = 8,},
206 .green = {.offset = 0, .length = 8,},
207 .blue = {.offset = 0, .length = 8,},
208 .transp = {.offset = 0, .length = 0,},
218 return chan << bf->
offset;
227 #define CNVT_TOHW(val,width) ((((val)<<(width))+0x7FFF-(val))>>16)
233 writel(val, fbi->
regs + 0x800 + (regno << 2));
254 green = 0xffff -
green;
255 blue = 0xffff -
blue;
262 if (info->
var.grayscale)
263 red = green = blue = (19595 * red + 38470 * green +
266 switch (info->
fix.visual) {
275 val = chan_to_field(red, &info->
var.red);
276 val |= chan_to_field(green, &info->
var.green);
277 val |= chan_to_field(blue, &info->
var.blue);
286 ret = imxfb_setpalettereg(regno, red, green, blue, trans, info);
298 for (i = 0, m = &fbi->
mode[0]; i < fbi->num_modes; i++, m++) {
316 unsigned long lcd_clk;
317 unsigned long long tmp;
325 imxfb_mode = imxfb_find_mode(fbi);
351 if (
do_div(tmp, 1000000) > 500000)
354 pcr = (
unsigned int)tmp;
375 rgb = &def_rgb_16_tft;
377 rgb = &def_rgb_16_stn;
386 pcr |= imxfb_mode->
pcr & ~(0x3f | (7 << 25));
399 pr_debug(
"RGBT length = %d:%d:%d:%d\n",
403 pr_debug(
"RGBT offset = %d:%d:%d:%d\n",
414 static int imxfb_set_par(
struct fb_info *info)
435 imxfb_activate_var(var, info);
440 #ifdef PWMR_BACKLIGHT_AVAILABLE
458 fbi->
pwmr = (fbi->
pwmr & ~0xFF) | brightness;
461 clk_prepare_enable(fbi->
clk_ipg);
462 clk_prepare_enable(fbi->
clk_ahb);
463 clk_prepare_enable(fbi->
clk_per);
467 clk_disable_unprepare(fbi->
clk_per);
468 clk_disable_unprepare(fbi->
clk_ahb);
469 clk_disable_unprepare(fbi->
clk_ipg);
477 .get_brightness = imxfb_bl_get_brightness,
480 static void imxfb_init_backlight(
struct imxfb_info *fbi)
489 props.max_brightness = 0xff;
494 &imxfb_lcdc_bl_ops, &
props);
496 dev_err(&fbi->
pdev->dev,
"error %ld on backlight register\n",
504 bl->
props.brightness = imxfb_bl_get_brightness(bl);
507 static void imxfb_exit_backlight(
struct imxfb_info *fbi)
514 static void imxfb_enable_controller(
struct imxfb_info *fbi)
516 pr_debug(
"Enabling LCD controller\n");
533 clk_prepare_enable(fbi->
clk_ipg);
534 clk_prepare_enable(fbi->
clk_ahb);
535 clk_prepare_enable(fbi->
clk_per);
543 static void imxfb_disable_controller(
struct imxfb_info *fbi)
545 pr_debug(
"Disabling LCD controller\n");
552 clk_disable_unprepare(fbi->
clk_per);
553 clk_disable_unprepare(fbi->
clk_ipg);
554 clk_disable_unprepare(fbi->
clk_ahb);
559 static int imxfb_blank(
int blank,
struct fb_info *info)
563 pr_debug(
"imxfb_blank: blank=%d\n", blank);
570 imxfb_disable_controller(fbi);
574 imxfb_enable_controller(fbi);
580 static struct fb_ops imxfb_ops = {
582 .fb_check_var = imxfb_check_var,
583 .fb_set_par = imxfb_set_par,
584 .fb_setcolreg = imxfb_setcolreg,
588 .fb_blank = imxfb_blank,
600 pr_debug(
"var: xres=%d hslen=%d lm=%d rm=%d\n",
603 pr_debug(
"var: yres=%d vslen=%d um=%d bm=%d\n",
608 if (var->
xres < 16 || var->
xres > 1024)
652 #ifndef PWMR_BACKLIGHT_AVAILABLE
668 struct fb_info *info = platform_get_drvdata(dev);
673 imxfb_disable_controller(fbi);
679 struct fb_info *info = platform_get_drvdata(dev);
684 imxfb_enable_controller(fbi);
688 #define imxfb_suspend NULL
689 #define imxfb_resume NULL
711 info->
fix.type_aux = 0;
712 info->
fix.xpanstep = 0;
713 info->
fix.ypanstep = 0;
714 info->
fix.ywrapstep = 0;
717 info->
var.nonstd = 0;
719 info->
var.height = -1;
720 info->
var.width = -1;
721 info->
var.accel_flags = 0;
724 info->
fbops = &imxfb_ops;
736 for (i = 0, m = &pdata->
mode[0]; i < pdata->num_modes; i++, m++)
737 info->
fix.smem_len =
max_t(
size_t, info->
fix.smem_len,
757 pdata = pdev->
dev.platform_data;
759 dev_err(&pdev->
dev,
"No platform_data available\n");
770 fb_mode = pdata->
mode[0].mode.name;
772 platform_set_drvdata(pdev, info);
774 ret = imxfb_init_fbinfo(pdev);
788 goto failed_getclock;
794 goto failed_getclock;
800 goto failed_getclock;
805 dev_err(&pdev->
dev,
"Cannot map frame buffer registers\n");
816 dev_err(&pdev->
dev,
"Failed to allocate video RAM: %d\n", ret);
838 goto failed_platform_init;
852 imxfb_check_var(&info->
var, info);
861 dev_err(&pdev->
dev,
"failed to register framebuffer\n");
862 goto failed_register;
865 imxfb_enable_controller(fbi);
867 #ifdef PWMR_BACKLIGHT_AVAILABLE
868 imxfb_init_backlight(fbi);
878 failed_platform_init:
890 platform_set_drvdata(pdev,
NULL);
898 struct fb_info *info = platform_get_drvdata(pdev);
904 imxfb_disable_controller(fbi);
906 #ifdef PWMR_BACKLIGHT_AVAILABLE
907 imxfb_exit_backlight(fbi);
911 pdata = pdev->
dev.platform_data;
922 platform_set_drvdata(pdev,
NULL);
929 struct fb_info *info = platform_get_drvdata(dev);
931 imxfb_disable_controller(fbi);
944 static int imxfb_setup(
void)
952 if (!options || !*options)
955 while ((opt =
strsep(&options,
",")) !=
NULL) {
967 int ret = imxfb_setup();
975 static void __exit imxfb_cleanup(
void)