📄 s3c2410fb.c
字号:
/* * linux/drivers/video/s3c2410fb.c * Copyright (c) Arnaud Patard, Ben Dooks * * This file is subject to the terms and conditions of the GNU General Public * License. See the file COPYING in the main directory of this archive for * more details. * * S3C2410 LCD Controller Frame Buffer Driver * based on skeletonfb.c, sa1100fb.c and others * * ChangeLog * 2005-04-07: Arnaud Patard <arnaud.patard@rtp-net.org> * - u32 state -> pm_message_t state * - S3C2410_{VA,SZ}_LCD -> S3C24XX * * 2005-03-15: Arnaud Patard <arnaud.patard@rtp-net.org> * - Removed the ioctl * - use readl/writel instead of __raw_writel/__raw_readl * * 2004-12-04: Arnaud Patard <arnaud.patard@rtp-net.org> * - Added the possibility to set on or off the * debugging mesaages * - Replaced 0 and 1 by on or off when reading the * /sys files * * 2005-03-23: Ben Dooks <ben-linux@fluff.org> * - added non 16bpp modes * - updated platform information for range of x/y/bpp * - add code to ensure palette is written correctly * - add pixel clock divisor control * * 2004-11-11: Arnaud Patard <arnaud.patard@rtp-net.org> * - Removed the use of currcon as it no more exist * - Added LCD power sysfs interface * * 2004-11-03: Ben Dooks <ben-linux@fluff.org> * - minor cleanups * - add suspend/resume support * - s3c2410fb_setcolreg() not valid in >8bpp modes * - removed last CONFIG_FB_S3C2410_FIXED * - ensure lcd controller stopped before cleanup * - added sysfs interface for backlight power * - added mask for gpio configuration * - ensured IRQs disabled during GPIO configuration * - disable TPAL before enabling video * * 2004-09-20: Arnaud Patard <arnaud.patard@rtp-net.org> * - Suppress command line options * * 2004-09-15: Arnaud Patard <arnaud.patard@rtp-net.org> * - code cleanup * * 2004-09-07: Arnaud Patard <arnaud.patard@rtp-net.org> * - Renamed from h1940fb.c to s3c2410fb.c * - Add support for different devices * - Backlight support * * 2004-09-05: Herbert P鰐zl <herbert@13thfloor.at> * - added clock (de-)allocation code * - added fixem fbmem option * * 2004-07-27: Arnaud Patard <arnaud.patard@rtp-net.org> * - code cleanup * - added a forgotten return in h1940fb_init * * 2004-07-19: Herbert P鰐zl <herbert@13thfloor.at> * - code cleanup and extended debugging * * 2004-07-15: Arnaud Patard <arnaud.patard@rtp-net.org> * - First version */#include <linux/module.h>#include <linux/kernel.h>#include <linux/errno.h>#include <linux/string.h>#include <linux/mm.h>#include <linux/slab.h>#include <linux/delay.h>#include <linux/fb.h>#include <linux/init.h>#include <linux/dma-mapping.h>#include <linux/interrupt.h>#include <linux/workqueue.h>#include <linux/wait.h>#include <linux/platform_device.h>#include <linux/clk.h>#include <asm/io.h>#include <asm/uaccess.h>#include <asm/div64.h>#include <asm/mach/map.h>#include <asm/arch/regs-lcd.h>#include <asm/arch/regs-gpio.h>#include <asm/arch/fb.h>#ifdef CONFIG_PM#include <linux/pm.h>#endif#include "s3c2410fb.h"static int display_type = -1;static struct s3c2410fb_mach_info *mach_info;/* Debugging stuff */#ifdef CONFIG_FB_S3C2410_DEBUGstatic int debug = 1;#elsestatic int debug = 0;#endif#define dprintk(msg...) if (debug) { printk(KERN_DEBUG "s3c2410fb: " msg); }/* useful functions */static int __init display_setup(char *str){ if (strcmp(str, "shp240")==0) { display_type = DISPLAY_TYPE_SHP240; } else if (strcmp(str, "shp640")==0) { display_type = DISPLAY_TYPE_SHP640; } else if (strcmp(str, "mit640")==0) { display_type = DISPLAY_TYPE_MIT640; } else if (strcmp(str, "vga640")==0) { display_type = DISPLAY_TYPE_VGA640; } return 1;}__setup("display=", display_setup);static void update_display_mach_info(struct s3c2410fb_mach_info * npd){ switch (display_type) { case DISPLAY_TYPE_SHP240: printk("framebuffer device is shp240, Sharp 240x320, supported!!\n"); npd->type = S3C2410_LCDCON1_TFT; npd->regs.lcdcon1 = S3C2410_LCDCON1_TFT16BPP | S3C2410_LCDCON1_TFT | S3C2410_LCDCON1_CLKVAL(10); npd->regs.lcdcon2 = S3C2410_LCDCON2_VBPD(2) | S3C2410_LCDCON2_LINEVAL(0) | S3C2410_LCDCON2_VFPD(2) | S3C2410_LCDCON2_VSPW(4); npd->regs.lcdcon3 = S3C2410_LCDCON3_HBPD(8) | S3C2410_LCDCON3_HOZVAL(0) | S3C2410_LCDCON3_HFPD(8); npd->regs.lcdcon4 = S3C2410_LCDCON4_MVAL(13) | S3C2410_LCDCON4_HSPW(6); npd->regs.lcdcon5 = S3C2410_LCDCON5_FRM565 | S3C2410_LCDCON5_PWREN | S3C2410_LCDCON5_HWSWP; npd->width = 240; npd->height = 320; npd->xres.defval = 240; npd->yres.defval = 320; break; case DISPLAY_TYPE_SHP640: printk("framebuffer device is shp640, Sharp 640x480, supported!!\n"); npd->type = S3C2410_LCDCON1_TFT; npd->regs.lcdcon1 = S3C2410_LCDCON1_TFT16BPP | S3C2410_LCDCON1_TFT | S3C2410_LCDCON1_MMODE | S3C2410_LCDCON1_CLKVAL(1); npd->regs.lcdcon2 = S3C2410_LCDCON2_VBPD(31) | S3C2410_LCDCON2_LINEVAL(0) | S3C2410_LCDCON2_VFPD(10) | S3C2410_LCDCON2_VSPW(1); npd->regs.lcdcon3 = S3C2410_LCDCON3_HBPD(39) | S3C2410_LCDCON3_HOZVAL(0) | S3C2410_LCDCON3_HFPD(23); npd->regs.lcdcon4 = S3C2410_LCDCON4_MVAL(13) | S3C2410_LCDCON4_HSPW(95); npd->regs.lcdcon5 = S3C2410_LCDCON5_FRM565 | S3C2410_LCDCON5_INVVCLK | S3C2410_LCDCON5_PWREN | S3C2410_LCDCON5_HWSWP; npd->width = 640; npd->height = 480; npd->xres.defval = 640; npd->yres.defval = 480; break; case DISPLAY_TYPE_MIT640: printk("framebuffer device is mit640, Mitsubishi 640x480, supported!!\n"); npd->type = S3C2410_LCDCON1_TFT; npd->regs.lcdcon1 = S3C2410_LCDCON1_TFT16BPP | S3C2410_LCDCON1_TFT | S3C2410_LCDCON1_CLKVAL(3); npd->regs.lcdcon2 = S3C2410_LCDCON2_VBPD(8) | S3C2410_LCDCON2_LINEVAL(0) | S3C2410_LCDCON2_VFPD(2) | S3C2410_LCDCON2_VSPW(2); npd->regs.lcdcon3 = S3C2410_LCDCON3_HBPD(20) | S3C2410_LCDCON3_HOZVAL(0) | S3C2410_LCDCON3_HFPD(0); npd->regs.lcdcon4 = S3C2410_LCDCON4_MVAL(0) | S3C2410_LCDCON4_HSPW(6); npd->regs.lcdcon5 = S3C2410_LCDCON5_FRM565 | S3C2410_LCDCON5_INVVLINE | S3C2410_LCDCON5_INVVFRAME | S3C2410_LCDCON5_PWREN | S3C2410_LCDCON5_HWSWP; npd->width = 640; npd->height = 480; npd->xres.defval = 640; npd->yres.defval = 480; break; case DISPLAY_TYPE_VGA640: printk("framebuffer device is vga640, VGA 640x480, supported!!\n"); npd->type = S3C2410_LCDCON1_TFT; npd->regs.lcdcon1 = S3C2410_LCDCON1_TFT16BPP | S3C2410_LCDCON1_TFT | S3C2410_LCDCON1_MMODE | S3C2410_LCDCON1_CLKVAL(8); npd->regs.lcdcon2 = S3C2410_LCDCON2_VBPD(31) | S3C2410_LCDCON2_LINEVAL(0) | S3C2410_LCDCON2_VFPD(6) | S3C2410_LCDCON2_VSPW(1); npd->regs.lcdcon3 = S3C2410_LCDCON3_HBPD(39) | S3C2410_LCDCON3_HOZVAL(0) | S3C2410_LCDCON3_HFPD(23); npd->regs.lcdcon4 = S3C2410_LCDCON4_MVAL(13) | S3C2410_LCDCON4_HSPW(95); npd->regs.lcdcon5 = S3C2410_LCDCON5_FRM565 | S3C2410_LCDCON5_INVVCLK | S3C2410_LCDCON5_PWREN | S3C2410_LCDCON5_HWSWP; npd->width = 640; npd->height = 480; npd->xres.defval = 640; npd->yres.defval = 480; break; default: /* use default in mach-xxxx.c, see mach-ljd2410.c or mach-yl2440.c for examples. */ printk("framebuffer device unknown, use default (see your mach-xxxx.c in .../arch/arm/mach-s3c2410/)!!\n"); break; }}/* s3c2410fb_set_lcdaddr * * initialise lcd controller address pointers*/static void s3c2410fb_set_lcdaddr(struct s3c2410fb_info *fbi){ struct fb_var_screeninfo *var = &fbi->fb->var; unsigned long saddr1, saddr2, saddr3; saddr1 = fbi->fb->fix.smem_start >> 1; saddr2 = fbi->fb->fix.smem_start; saddr2 += (var->xres * var->yres * var->bits_per_pixel)/8; saddr2>>= 1; saddr3 = S3C2410_OFFSIZE(0) | S3C2410_PAGEWIDTH((var->xres * var->bits_per_pixel / 16) & 0x3ff); dprintk("LCDSADDR1 = 0x%08lx\n", saddr1); dprintk("LCDSADDR2 = 0x%08lx\n", saddr2); dprintk("LCDSADDR3 = 0x%08lx\n", saddr3); writel(saddr1, S3C2410_LCDSADDR1); writel(saddr2, S3C2410_LCDSADDR2); writel(saddr3, S3C2410_LCDSADDR3);}/* s3c2410fb_calc_pixclk() * * calculate divisor for clk->pixclk*/static unsigned int s3c2410fb_calc_pixclk(struct s3c2410fb_info *fbi, unsigned long pixclk){ unsigned long clk = clk_get_rate(fbi->clk); unsigned long long div; /* pixclk is in picoseoncds, our clock is in Hz * * Hz -> picoseconds is / 10^-12 */ div = (unsigned long long)clk * pixclk; do_div(div,1000000UL); do_div(div,1000000UL); dprintk("pixclk %ld, divisor is %ld\n", pixclk, (long)div); return div;}/* * s3c2410fb_check_var(): * Get the video params out of 'var'. If a value doesn't fit, round it up, * if it's too big, return -EINVAL. * */static int s3c2410fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info){ struct s3c2410fb_info *fbi = info->par; dprintk("check_var(var=%p, info=%p)\n", var, info); /* validate x/y resolution */ if (var->yres > fbi->mach_info->yres.max) var->yres = fbi->mach_info->yres.max; else if (var->yres < fbi->mach_info->yres.min) var->yres = fbi->mach_info->yres.min; if (var->xres > fbi->mach_info->xres.max) var->xres = fbi->mach_info->xres.max; else if (var->xres < fbi->mach_info->xres.min) var->xres = fbi->mach_info->xres.min; /* validate bpp */ if (var->bits_per_pixel > fbi->mach_info->bpp.max) var->bits_per_pixel = fbi->mach_info->bpp.max; else if (var->bits_per_pixel < fbi->mach_info->bpp.min) var->bits_per_pixel = fbi->mach_info->bpp.min; /* set r/g/b positions */ switch (var->bits_per_pixel) { case 1: case 2: case 4: var->red.offset = 0; var->red.length = var->bits_per_pixel; var->green = var->red; var->blue = var->red; var->transp.offset = 0; var->transp.length = 0; break; case 8: if ( fbi->mach_info->type != S3C2410_LCDCON1_TFT ) { /* 8 bpp 332 */ var->red.length = 3; var->red.offset = 5; var->green.length = 3; var->green.offset = 2; var->blue.length = 2; var->blue.offset = 0; var->transp.length = 0; } else { var->red.offset = 0; var->red.length = var->bits_per_pixel; var->green = var->red; var->blue = var->red; var->transp.offset = 0; var->transp.length = 0; } break; case 12: /* 12 bpp 444 */ var->red.length = 4; var->red.offset = 8; var->green.length = 4; var->green.offset = 4; var->blue.length = 4; var->blue.offset = 0; var->transp.length = 0; break; default: case 16: if (fbi->regs.lcdcon5 & S3C2410_LCDCON5_FRM565 ) { /* 16 bpp, 565 format */ var->red.offset = 11; var->green.offset = 5; var->blue.offset = 0; var->red.length = 5; var->green.length = 6; var->blue.length = 5; var->transp.length = 0; } else { /* 16 bpp, 5551 format */ var->red.offset = 11; var->green.offset = 6; var->blue.offset = 1; var->red.length = 5; var->green.length = 5; var->blue.length = 5; var->transp.length = 0; } break; case 24: /* 24 bpp 888 */ var->red.length = 8; var->red.offset = 16; var->green.length = 8; var->green.offset = 8; var->blue.length = 8; var->blue.offset = 0; var->transp.length = 0; break; } return 0;}/* s3c2410fb_activate_var * * activate (set) the controller from the given framebuffer * information*/static void s3c2410fb_activate_var(struct s3c2410fb_info *fbi, struct fb_var_screeninfo *var){ int hs; fbi->regs.lcdcon1 &= ~S3C2410_LCDCON1_MODEMASK; fbi->regs.lcdcon1 &= ~S3C2410_LCDCON1_TFT; dprintk("%s: var->xres = %d\n", __FUNCTION__, var->xres); dprintk("%s: var->yres = %d\n", __FUNCTION__, var->yres); dprintk("%s: var->bpp = %d\n", __FUNCTION__, var->bits_per_pixel); fbi->regs.lcdcon1 |= fbi->mach_info->type; if (fbi->mach_info->type == S3C2410_LCDCON1_TFT) switch (var->bits_per_pixel) { case 1: fbi->regs.lcdcon1 |= S3C2410_LCDCON1_TFT1BPP; break; case 2: fbi->regs.lcdcon1 |= S3C2410_LCDCON1_TFT2BPP; break; case 4: fbi->regs.lcdcon1 |= S3C2410_LCDCON1_TFT4BPP; break; case 8: fbi->regs.lcdcon1 |= S3C2410_LCDCON1_TFT8BPP; break; case 16: fbi->regs.lcdcon1 |= S3C2410_LCDCON1_TFT16BPP; break; default: /* invalid pixel depth */ dev_err(fbi->dev, "invalid bpp %d\n", var->bits_per_pixel); } else switch (var->bits_per_pixel) { case 1: fbi->regs.lcdcon1 |= S3C2410_LCDCON1_STN1BPP; break; case 2: fbi->regs.lcdcon1 |= S3C2410_LCDCON1_STN2GREY; break; case 4: fbi->regs.lcdcon1 |= S3C2410_LCDCON1_STN4GREY; break; case 8: fbi->regs.lcdcon1 |= S3C2410_LCDCON1_STN8BPP; break; case 12: fbi->regs.lcdcon1 |= S3C2410_LCDCON1_STN12BPP; break; default: /* invalid pixel depth */ dev_err(fbi->dev, "invalid bpp %d\n", var->bits_per_pixel); } /* check to see if we need to update sync/borders */ if (!fbi->mach_info->fixed_syncs) { dprintk("setting vert: up=%d, low=%d, sync=%d\n", var->upper_margin, var->lower_margin, var->vsync_len); dprintk("setting horz: lft=%d, rt=%d, sync=%d\n", var->left_margin, var->right_margin, var->hsync_len); fbi->regs.lcdcon2 = S3C2410_LCDCON2_VBPD(var->upper_margin - 1) | S3C2410_LCDCON2_VFPD(var->lower_margin - 1) | S3C2410_LCDCON2_VSPW(var->vsync_len - 1); fbi->regs.lcdcon3 = S3C2410_LCDCON3_HBPD(var->right_margin - 1) | S3C2410_LCDCON3_HFPD(var->left_margin - 1); fbi->regs.lcdcon4 &= ~S3C2410_LCDCON4_HSPW(0xff); fbi->regs.lcdcon4 |= S3C2410_LCDCON4_HSPW(var->hsync_len - 1); } /* update X/Y info */ fbi->regs.lcdcon2 &= ~S3C2410_LCDCON2_LINEVAL(0x3ff); fbi->regs.lcdcon2 |= S3C2410_LCDCON2_LINEVAL(var->yres - 1); switch(fbi->mach_info->type) { case S3C2410_LCDCON1_DSCAN4: case S3C2410_LCDCON1_STN8: hs = var->xres / 8; break; case S3C2410_LCDCON1_STN4: hs = var->xres / 4; break; default: case S3C2410_LCDCON1_TFT: hs = var->xres; break; } /* Special cases : STN color displays */ if ( ((fbi->regs.lcdcon1 & S3C2410_LCDCON1_MODEMASK) == S3C2410_LCDCON1_STN8BPP) \ || ((fbi->regs.lcdcon1 & S3C2410_LCDCON1_MODEMASK) == S3C2410_LCDCON1_STN12BPP) ) { hs = hs * 3; } fbi->regs.lcdcon3 &= ~S3C2410_LCDCON3_HOZVAL(0x7ff); fbi->regs.lcdcon3 |= S3C2410_LCDCON3_HOZVAL(hs - 1); if (var->pixclock > 0) { int clkdiv = s3c2410fb_calc_pixclk(fbi, var->pixclock); if (fbi->mach_info->type == S3C2410_LCDCON1_TFT) { clkdiv = (clkdiv / 2) -1; if (clkdiv < 0) clkdiv = 0; } else { clkdiv = (clkdiv / 2); if (clkdiv < 2) clkdiv = 2; } fbi->regs.lcdcon1 &= ~S3C2410_LCDCON1_CLKVAL(0x3ff); fbi->regs.lcdcon1 |= S3C2410_LCDCON1_CLKVAL(clkdiv); } /* write new registers */ dprintk("new register set:\n"); dprintk("lcdcon[1] = 0x%08lx\n", fbi->regs.lcdcon1); dprintk("lcdcon[2] = 0x%08lx\n", fbi->regs.lcdcon2); dprintk("lcdcon[3] = 0x%08lx\n", fbi->regs.lcdcon3); dprintk("lcdcon[4] = 0x%08lx\n", fbi->regs.lcdcon4); dprintk("lcdcon[5] = 0x%08lx\n", fbi->regs.lcdcon5); writel(fbi->regs.lcdcon1 & ~S3C2410_LCDCON1_ENVID, S3C2410_LCDCON1); writel(fbi->regs.lcdcon2, S3C2410_LCDCON2); writel(fbi->regs.lcdcon3, S3C2410_LCDCON3); writel(fbi->regs.lcdcon4, S3C2410_LCDCON4); writel(fbi->regs.lcdcon5, S3C2410_LCDCON5); /* set lcd address pointers */ s3c2410fb_set_lcdaddr(fbi); writel(fbi->regs.lcdcon1, S3C2410_LCDCON1);}/* * s3c2410fb_set_par - Optional function. Alters the hardware state. * @info: frame buffer structure that represents a single frame buffer * */static int s3c2410fb_set_par(struct fb_info *info){ struct s3c2410fb_info *fbi = info->par; struct fb_var_screeninfo *var = &info->var; switch (var->bits_per_pixel) { case 16: fbi->fb->fix.visual = FB_VISUAL_TRUECOLOR; break; case 1: fbi->fb->fix.visual = FB_VISUAL_MONO01; break; default: fbi->fb->fix.visual = FB_VISUAL_PSEUDOCOLOR; break; } fbi->fb->fix.line_length = (var->width*var->bits_per_pixel)/8; /* activate this new configuration */ s3c2410fb_activate_var(fbi, var); return 0;}static void schedule_palette_update(struct s3c2410fb_info *fbi,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -