📄 imxfb.c
字号:
/* * Freescale i.MX Frame Buffer device driver * * Copyright (C) 2004 Sascha Hauer, Pengutronix * Based on acornfb.c Copyright (C) Russell King. * * 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. * * Please direct your questions and comments on this driver to the following * email address: * * linux-arm-kernel@lists.arm.linux.org.uk */#include <linux/module.h>#include <linux/kernel.h>#include <linux/errno.h>#include <linux/string.h>#include <linux/interrupt.h>#include <linux/slab.h>#include <linux/mm.h>#include <linux/fb.h>#include <linux/delay.h>#include <linux/init.h>#include <linux/ioport.h>#include <linux/cpufreq.h>#include <linux/platform_device.h>#include <linux/dma-mapping.h>#include <linux/io.h>#include <mach/imxfb.h>/* * Complain if VAR is out of range. */#define DEBUG_VAR 1#define DRIVER_NAME "imx-fb"#define LCDC_SSA 0x00#define LCDC_SIZE 0x04#define SIZE_XMAX(x) ((((x) >> 4) & 0x3f) << 20)#define SIZE_YMAX(y) ((y) & 0x1ff)#define LCDC_VPW 0x08#define VPW_VPW(x) ((x) & 0x3ff)#define LCDC_CPOS 0x0C#define CPOS_CC1 (1<<31)#define CPOS_CC0 (1<<30)#define CPOS_OP (1<<28)#define CPOS_CXP(x) (((x) & 3ff) << 16)#define CPOS_CYP(y) ((y) & 0x1ff)#define LCDC_LCWHB 0x10#define LCWHB_BK_EN (1<<31)#define LCWHB_CW(w) (((w) & 0x1f) << 24)#define LCWHB_CH(h) (((h) & 0x1f) << 16)#define LCWHB_BD(x) ((x) & 0xff)#define LCDC_LCHCC 0x14#define LCHCC_CUR_COL_R(r) (((r) & 0x1f) << 11)#define LCHCC_CUR_COL_G(g) (((g) & 0x3f) << 5)#define LCHCC_CUR_COL_B(b) ((b) & 0x1f)#define LCDC_PCR 0x18#define LCDC_HCR 0x1C#define HCR_H_WIDTH(x) (((x) & 0x3f) << 26)#define HCR_H_WAIT_1(x) (((x) & 0xff) << 8)#define HCR_H_WAIT_2(x) ((x) & 0xff)#define LCDC_VCR 0x20#define VCR_V_WIDTH(x) (((x) & 0x3f) << 26)#define VCR_V_WAIT_1(x) (((x) & 0xff) << 8)#define VCR_V_WAIT_2(x) ((x) & 0xff)#define LCDC_POS 0x24#define POS_POS(x) ((x) & 1f)#define LCDC_LSCR1 0x28/* bit fields in imxfb.h */#define LCDC_PWMR 0x2C/* bit fields in imxfb.h */#define LCDC_DMACR 0x30/* bit fields in imxfb.h */#define LCDC_RMCR 0x34#define RMCR_LCDC_EN (1<<1)#define RMCR_SELF_REF (1<<0)#define LCDC_LCDICR 0x38#define LCDICR_INT_SYN (1<<2)#define LCDICR_INT_CON (1)#define LCDC_LCDISR 0x40#define LCDISR_UDR_ERR (1<<3)#define LCDISR_ERR_RES (1<<2)#define LCDISR_EOF (1<<1)#define LCDISR_BOF (1<<0)/* * These are the bitfields for each * display depth that we support. */struct imxfb_rgb { struct fb_bitfield red; struct fb_bitfield green; struct fb_bitfield blue; struct fb_bitfield transp;};struct imxfb_info { struct platform_device *pdev; void __iomem *regs; u_int max_bpp; u_int max_xres; u_int max_yres; /* * These are the addresses we mapped * the framebuffer memory region to. */ dma_addr_t map_dma; u_char *map_cpu; u_int map_size; u_char *screen_cpu; dma_addr_t screen_dma; u_int palette_size; dma_addr_t dbar1; dma_addr_t dbar2; u_int pcr; u_int pwmr; u_int lscr1; u_int dmacr; u_int cmap_inverse:1, cmap_static:1, unused:30; void (*lcd_power)(int); void (*backlight_power)(int);};#define IMX_NAME "IMX"/* * Minimum X and Y resolutions */#define MIN_XRES 64#define MIN_YRES 64static struct imxfb_rgb def_rgb_16_tft = { .red = {.offset = 11, .length = 5,}, .green = {.offset = 5, .length = 6,}, .blue = {.offset = 0, .length = 5,}, .transp = {.offset = 0, .length = 0,},};static struct imxfb_rgb def_rgb_16_stn = { .red = {.offset = 8, .length = 4,}, .green = {.offset = 4, .length = 4,}, .blue = {.offset = 0, .length = 4,}, .transp = {.offset = 0, .length = 0,},};static struct imxfb_rgb def_rgb_8 = { .red = {.offset = 0, .length = 8,}, .green = {.offset = 0, .length = 8,}, .blue = {.offset = 0, .length = 8,}, .transp = {.offset = 0, .length = 0,},};static int imxfb_activate_var(struct fb_var_screeninfo *var, struct fb_info *info);static inline u_int chan_to_field(u_int chan, struct fb_bitfield *bf){ chan &= 0xffff; chan >>= 16 - bf->length; return chan << bf->offset;}static int imxfb_setpalettereg(u_int regno, u_int red, u_int green, u_int blue, u_int trans, struct fb_info *info){ struct imxfb_info *fbi = info->par; u_int val, ret = 1;#define CNVT_TOHW(val,width) ((((val)<<(width))+0x7FFF-(val))>>16) if (regno < fbi->palette_size) { val = (CNVT_TOHW(red, 4) << 8) | (CNVT_TOHW(green,4) << 4) | CNVT_TOHW(blue, 4); writel(val, fbi->regs + 0x800 + (regno << 2)); ret = 0; } return ret;}static int imxfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue, u_int trans, struct fb_info *info){ struct imxfb_info *fbi = info->par; unsigned int val; int ret = 1; /* * If inverse mode was selected, invert all the colours * rather than the register number. The register number * is what you poke into the framebuffer to produce the * colour you requested. */ if (fbi->cmap_inverse) { red = 0xffff - red; green = 0xffff - green; blue = 0xffff - blue; } /* * If greyscale is true, then we convert the RGB value * to greyscale no mater what visual we are using. */ if (info->var.grayscale) red = green = blue = (19595 * red + 38470 * green + 7471 * blue) >> 16; switch (info->fix.visual) { case FB_VISUAL_TRUECOLOR: /* * 12 or 16-bit True Colour. We encode the RGB value * according to the RGB bitfield information. */ if (regno < 16) { u32 *pal = info->pseudo_palette; val = chan_to_field(red, &info->var.red); val |= chan_to_field(green, &info->var.green); val |= chan_to_field(blue, &info->var.blue); pal[regno] = val; ret = 0; } break; case FB_VISUAL_STATIC_PSEUDOCOLOR: case FB_VISUAL_PSEUDOCOLOR: ret = imxfb_setpalettereg(regno, red, green, blue, trans, info); break; } return ret;}/* * imxfb_check_var(): * Round up in the following order: bits_per_pixel, xres, * yres, xres_virtual, yres_virtual, xoffset, yoffset, grayscale, * bitfields, horizontal timing, vertical timing. */static int imxfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info){ struct imxfb_info *fbi = info->par; struct imxfb_rgb *rgb; if (var->xres < MIN_XRES) var->xres = MIN_XRES; if (var->yres < MIN_YRES) var->yres = MIN_YRES; if (var->xres > fbi->max_xres) var->xres = fbi->max_xres; if (var->yres > fbi->max_yres) var->yres = fbi->max_yres; var->xres_virtual = max(var->xres_virtual, var->xres); var->yres_virtual = max(var->yres_virtual, var->yres); pr_debug("var->bits_per_pixel=%d\n", var->bits_per_pixel); switch (var->bits_per_pixel) { case 16: default: if (readl(fbi->regs + LCDC_PCR) & PCR_TFT) rgb = &def_rgb_16_tft; else rgb = &def_rgb_16_stn; break; case 8: rgb = &def_rgb_8; break; } /* * Copy the RGB parameters for this display * from the machine specific parameters. */ var->red = rgb->red; var->green = rgb->green; var->blue = rgb->blue; var->transp = rgb->transp; pr_debug("RGBT length = %d:%d:%d:%d\n", var->red.length, var->green.length, var->blue.length, var->transp.length); pr_debug("RGBT offset = %d:%d:%d:%d\n", var->red.offset, var->green.offset, var->blue.offset, var->transp.offset); return 0;}/* * imxfb_set_par(): * Set the user defined part of the display for the specified console */static int imxfb_set_par(struct fb_info *info){ struct imxfb_info *fbi = info->par; struct fb_var_screeninfo *var = &info->var; pr_debug("set_par\n"); if (var->bits_per_pixel == 16) info->fix.visual = FB_VISUAL_TRUECOLOR; else if (!fbi->cmap_static) info->fix.visual = FB_VISUAL_PSEUDOCOLOR; else { /* * Some people have weird ideas about wanting static * pseudocolor maps. I suspect their user space * applications are broken. */ info->fix.visual = FB_VISUAL_STATIC_PSEUDOCOLOR; } info->fix.line_length = var->xres_virtual * var->bits_per_pixel / 8; fbi->palette_size = var->bits_per_pixel == 8 ? 256 : 16; imxfb_activate_var(var, info); return 0;}static void imxfb_enable_controller(struct imxfb_info *fbi){ pr_debug("Enabling LCD controller\n"); /* initialize LCDC */ writel(readl(fbi->regs + LCDC_RMCR) & ~RMCR_LCDC_EN, fbi->regs + LCDC_RMCR); /* just to be safe... */ writel(fbi->screen_dma, fbi->regs + LCDC_SSA); /* physical screen start address */ writel(VPW_VPW(fbi->max_xres * fbi->max_bpp / 8 / 4), fbi->regs + LCDC_VPW); /* panning offset 0 (0 pixel offset) */ writel(0x00000000, fbi->regs + LCDC_POS); /* disable hardware cursor */ writel(readl(fbi->regs + LCDC_CPOS) & ~(CPOS_CC0 | CPOS_CC1), fbi->regs + LCDC_CPOS); writel(RMCR_LCDC_EN, fbi->regs + LCDC_RMCR);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -