2005-05-01 23:59:24 +08:00
|
|
|
/*
|
|
|
|
* 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>
|
2008-07-24 12:28:13 +08:00
|
|
|
#include <linux/mm.h>
|
2005-05-01 23:59:24 +08:00
|
|
|
#include <linux/fb.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/ioport.h>
|
|
|
|
#include <linux/cpufreq.h>
|
2005-10-30 02:07:23 +08:00
|
|
|
#include <linux/platform_device.h>
|
2005-05-01 23:59:24 +08:00
|
|
|
#include <linux/dma-mapping.h>
|
2008-12-16 18:44:07 +08:00
|
|
|
#include <linux/io.h>
|
2005-05-01 23:59:24 +08:00
|
|
|
|
2008-08-05 23:14:15 +08:00
|
|
|
#include <mach/imxfb.h>
|
2005-05-01 23:59:24 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Complain if VAR is out of range.
|
|
|
|
*/
|
|
|
|
#define DEBUG_VAR 1
|
|
|
|
|
2008-12-16 18:44:07 +08:00
|
|
|
#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)
|
|
|
|
|
2008-12-16 18:44:08 +08:00
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define RGB_16 (0)
|
|
|
|
#define RGB_8 (1)
|
|
|
|
#define NR_RGB 2
|
|
|
|
|
|
|
|
struct imxfb_info {
|
|
|
|
struct platform_device *pdev;
|
|
|
|
void __iomem *regs;
|
|
|
|
|
|
|
|
struct imxfb_rgb *rgb[NR_RGB];
|
|
|
|
|
|
|
|
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 64
|
|
|
|
|
2005-05-01 23:59:24 +08:00
|
|
|
static struct imxfb_rgb def_rgb_16 = {
|
2008-12-16 18:44:08 +08:00
|
|
|
.red = {.offset = 8, .length = 4,},
|
|
|
|
.green = {.offset = 4, .length = 4,},
|
|
|
|
.blue = {.offset = 0, .length = 4,},
|
|
|
|
.transp = {.offset = 0, .length = 0,},
|
2005-05-01 23:59:24 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct imxfb_rgb def_rgb_8 = {
|
2008-12-16 18:44:08 +08:00
|
|
|
.red = {.offset = 0, .length = 8,},
|
|
|
|
.green = {.offset = 0, .length = 8,},
|
|
|
|
.blue = {.offset = 0, .length = 8,},
|
|
|
|
.transp = {.offset = 0, .length = 0,},
|
2005-05-01 23:59:24 +08:00
|
|
|
};
|
|
|
|
|
2008-12-16 18:44:08 +08:00
|
|
|
static int imxfb_activate_var(struct fb_var_screeninfo *var,
|
|
|
|
struct fb_info *info);
|
2005-05-01 23:59:24 +08:00
|
|
|
|
|
|
|
static inline u_int chan_to_field(u_int chan, struct fb_bitfield *bf)
|
|
|
|
{
|
|
|
|
chan &= 0xffff;
|
|
|
|
chan >>= 16 - bf->length;
|
|
|
|
return chan << bf->offset;
|
|
|
|
}
|
|
|
|
|
2008-12-16 18:44:08 +08:00
|
|
|
static int imxfb_setpalettereg(u_int regno, u_int red, u_int green, u_int blue,
|
|
|
|
u_int trans, struct fb_info *info)
|
2005-05-01 23:59:24 +08:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
2008-12-16 18:44:07 +08:00
|
|
|
writel(val, fbi->regs + 0x800 + (regno << 2));
|
2005-05-01 23:59:24 +08:00
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-12-16 18:44:08 +08:00
|
|
|
static int imxfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
|
2005-05-01 23:59:24 +08:00
|
|
|
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.
|
|
|
|
*/
|
2008-12-16 18:44:08 +08:00
|
|
|
static int imxfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
|
2005-05-01 23:59:24 +08:00
|
|
|
{
|
|
|
|
struct imxfb_info *fbi = info->par;
|
|
|
|
int rgbidx;
|
|
|
|
|
|
|
|
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:
|
|
|
|
rgbidx = RGB_16;
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
rgbidx = RGB_8;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
rgbidx = RGB_16;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy the RGB parameters for this display
|
|
|
|
* from the machine specific parameters.
|
|
|
|
*/
|
|
|
|
var->red = fbi->rgb[rgbidx]->red;
|
|
|
|
var->green = fbi->rgb[rgbidx]->green;
|
|
|
|
var->blue = fbi->rgb[rgbidx]->blue;
|
|
|
|
var->transp = fbi->rgb[rgbidx]->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;
|
|
|
|
}
|
|
|
|
|
2008-12-16 18:44:08 +08:00
|
|
|
info->fix.line_length = var->xres_virtual * var->bits_per_pixel / 8;
|
2005-05-01 23:59:24 +08:00
|
|
|
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 */
|
2008-12-16 18:44:07 +08:00
|
|
|
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);
|
2005-05-01 23:59:24 +08:00
|
|
|
|
|
|
|
/* physical screen start address */
|
2008-12-16 18:44:07 +08:00
|
|
|
writel(VPW_VPW(fbi->max_xres * fbi->max_bpp / 8 / 4),
|
|
|
|
fbi->regs + LCDC_VPW);
|
2005-05-01 23:59:24 +08:00
|
|
|
|
2008-12-16 18:44:07 +08:00
|
|
|
/* panning offset 0 (0 pixel offset) */
|
|
|
|
writel(0x00000000, fbi->regs + LCDC_POS);
|
2005-05-01 23:59:24 +08:00
|
|
|
|
|
|
|
/* disable hardware cursor */
|
2008-12-16 18:44:07 +08:00
|
|
|
writel(readl(fbi->regs + LCDC_CPOS) & ~(CPOS_CC0 | CPOS_CC1),
|
|
|
|
fbi->regs + LCDC_CPOS);
|
2005-05-01 23:59:24 +08:00
|
|
|
|
2008-12-16 18:44:07 +08:00
|
|
|
writel(RMCR_LCDC_EN, fbi->regs + LCDC_RMCR);
|
2005-05-01 23:59:24 +08:00
|
|
|
|
2008-12-16 18:44:08 +08:00
|
|
|
if (fbi->backlight_power)
|
2005-05-01 23:59:24 +08:00
|
|
|
fbi->backlight_power(1);
|
2008-12-16 18:44:08 +08:00
|
|
|
if (fbi->lcd_power)
|
2005-05-01 23:59:24 +08:00
|
|
|
fbi->lcd_power(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void imxfb_disable_controller(struct imxfb_info *fbi)
|
|
|
|
{
|
|
|
|
pr_debug("Disabling LCD controller\n");
|
|
|
|
|
2008-12-16 18:44:08 +08:00
|
|
|
if (fbi->backlight_power)
|
2005-05-01 23:59:24 +08:00
|
|
|
fbi->backlight_power(0);
|
2008-12-16 18:44:08 +08:00
|
|
|
if (fbi->lcd_power)
|
2005-05-01 23:59:24 +08:00
|
|
|
fbi->lcd_power(0);
|
|
|
|
|
2008-12-16 18:44:07 +08:00
|
|
|
writel(0, fbi->regs + LCDC_RMCR);
|
2005-05-01 23:59:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int imxfb_blank(int blank, struct fb_info *info)
|
|
|
|
{
|
|
|
|
struct imxfb_info *fbi = info->par;
|
|
|
|
|
|
|
|
pr_debug("imxfb_blank: blank=%d\n", blank);
|
|
|
|
|
|
|
|
switch (blank) {
|
|
|
|
case FB_BLANK_POWERDOWN:
|
|
|
|
case FB_BLANK_VSYNC_SUSPEND:
|
|
|
|
case FB_BLANK_HSYNC_SUSPEND:
|
|
|
|
case FB_BLANK_NORMAL:
|
|
|
|
imxfb_disable_controller(fbi);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FB_BLANK_UNBLANK:
|
|
|
|
imxfb_enable_controller(fbi);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct fb_ops imxfb_ops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.fb_check_var = imxfb_check_var,
|
|
|
|
.fb_set_par = imxfb_set_par,
|
|
|
|
.fb_setcolreg = imxfb_setcolreg,
|
|
|
|
.fb_fillrect = cfb_fillrect,
|
|
|
|
.fb_copyarea = cfb_copyarea,
|
|
|
|
.fb_imageblit = cfb_imageblit,
|
|
|
|
.fb_blank = imxfb_blank,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* imxfb_activate_var():
|
|
|
|
* Configures LCD Controller based on entries in var parameter. Settings are
|
|
|
|
* only written to the controller if changes were made.
|
|
|
|
*/
|
|
|
|
static int imxfb_activate_var(struct fb_var_screeninfo *var, struct fb_info *info)
|
|
|
|
{
|
|
|
|
struct imxfb_info *fbi = info->par;
|
|
|
|
pr_debug("var: xres=%d hslen=%d lm=%d rm=%d\n",
|
|
|
|
var->xres, var->hsync_len,
|
|
|
|
var->left_margin, var->right_margin);
|
|
|
|
pr_debug("var: yres=%d vslen=%d um=%d bm=%d\n",
|
|
|
|
var->yres, var->vsync_len,
|
|
|
|
var->upper_margin, var->lower_margin);
|
|
|
|
|
|
|
|
#if DEBUG_VAR
|
|
|
|
if (var->xres < 16 || var->xres > 1024)
|
|
|
|
printk(KERN_ERR "%s: invalid xres %d\n",
|
|
|
|
info->fix.id, var->xres);
|
|
|
|
if (var->hsync_len < 1 || var->hsync_len > 64)
|
|
|
|
printk(KERN_ERR "%s: invalid hsync_len %d\n",
|
|
|
|
info->fix.id, var->hsync_len);
|
|
|
|
if (var->left_margin > 255)
|
|
|
|
printk(KERN_ERR "%s: invalid left_margin %d\n",
|
|
|
|
info->fix.id, var->left_margin);
|
|
|
|
if (var->right_margin > 255)
|
|
|
|
printk(KERN_ERR "%s: invalid right_margin %d\n",
|
|
|
|
info->fix.id, var->right_margin);
|
|
|
|
if (var->yres < 1 || var->yres > 511)
|
|
|
|
printk(KERN_ERR "%s: invalid yres %d\n",
|
|
|
|
info->fix.id, var->yres);
|
|
|
|
if (var->vsync_len > 100)
|
|
|
|
printk(KERN_ERR "%s: invalid vsync_len %d\n",
|
|
|
|
info->fix.id, var->vsync_len);
|
|
|
|
if (var->upper_margin > 63)
|
|
|
|
printk(KERN_ERR "%s: invalid upper_margin %d\n",
|
|
|
|
info->fix.id, var->upper_margin);
|
|
|
|
if (var->lower_margin > 255)
|
|
|
|
printk(KERN_ERR "%s: invalid lower_margin %d\n",
|
|
|
|
info->fix.id, var->lower_margin);
|
|
|
|
#endif
|
|
|
|
|
2008-12-16 18:44:07 +08:00
|
|
|
writel(HCR_H_WIDTH(var->hsync_len) |
|
2008-12-16 18:44:08 +08:00
|
|
|
HCR_H_WAIT_1(var->right_margin) |
|
|
|
|
HCR_H_WAIT_2(var->left_margin),
|
2008-12-16 18:44:07 +08:00
|
|
|
fbi->regs + LCDC_HCR);
|
2005-05-01 23:59:24 +08:00
|
|
|
|
2008-12-16 18:44:07 +08:00
|
|
|
writel(VCR_V_WIDTH(var->vsync_len) |
|
2008-12-16 18:44:08 +08:00
|
|
|
VCR_V_WAIT_1(var->lower_margin) |
|
|
|
|
VCR_V_WAIT_2(var->upper_margin),
|
2008-12-16 18:44:07 +08:00
|
|
|
fbi->regs + LCDC_VCR);
|
2005-05-01 23:59:24 +08:00
|
|
|
|
2008-12-16 18:44:07 +08:00
|
|
|
writel(SIZE_XMAX(var->xres) | SIZE_YMAX(var->yres),
|
|
|
|
fbi->regs + LCDC_SIZE);
|
|
|
|
writel(fbi->pcr, fbi->regs + LCDC_PCR);
|
|
|
|
writel(fbi->pwmr, fbi->regs + LCDC_PWMR);
|
|
|
|
writel(fbi->lscr1, fbi->regs + LCDC_LSCR1);
|
|
|
|
writel(fbi->dmacr, fbi->regs + LCDC_DMACR);
|
2005-05-01 23:59:24 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_PM
|
|
|
|
/*
|
|
|
|
* Power management hooks. Note that we won't be called from IRQ context,
|
|
|
|
* unlike the blank functions above, so we may sleep.
|
|
|
|
*/
|
2005-11-10 06:32:44 +08:00
|
|
|
static int imxfb_suspend(struct platform_device *dev, pm_message_t state)
|
2005-05-01 23:59:24 +08:00
|
|
|
{
|
2005-11-10 06:32:44 +08:00
|
|
|
struct imxfb_info *fbi = platform_get_drvdata(dev);
|
2008-12-16 18:44:08 +08:00
|
|
|
|
|
|
|
pr_debug("%s\n", __func__);
|
2005-05-01 23:59:24 +08:00
|
|
|
|
2005-10-29 00:52:56 +08:00
|
|
|
imxfb_disable_controller(fbi);
|
2005-05-01 23:59:24 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-10 06:32:44 +08:00
|
|
|
static int imxfb_resume(struct platform_device *dev)
|
2005-05-01 23:59:24 +08:00
|
|
|
{
|
2005-11-10 06:32:44 +08:00
|
|
|
struct imxfb_info *fbi = platform_get_drvdata(dev);
|
2008-12-16 18:44:08 +08:00
|
|
|
|
|
|
|
pr_debug("%s\n", __func__);
|
2005-05-01 23:59:24 +08:00
|
|
|
|
2005-10-29 00:52:56 +08:00
|
|
|
imxfb_enable_controller(fbi);
|
2005-05-01 23:59:24 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define imxfb_suspend NULL
|
|
|
|
#define imxfb_resume NULL
|
|
|
|
#endif
|
|
|
|
|
2008-12-16 18:44:07 +08:00
|
|
|
static int __init imxfb_init_fbinfo(struct platform_device *pdev)
|
2005-05-01 23:59:24 +08:00
|
|
|
{
|
2008-12-16 18:44:09 +08:00
|
|
|
struct imx_fb_platform_data *pdata = pdev->dev.platform_data;
|
2008-12-16 18:44:07 +08:00
|
|
|
struct fb_info *info = dev_get_drvdata(&pdev->dev);
|
2005-05-01 23:59:24 +08:00
|
|
|
struct imxfb_info *fbi = info->par;
|
|
|
|
|
2008-04-28 17:15:47 +08:00
|
|
|
pr_debug("%s\n",__func__);
|
2005-05-01 23:59:24 +08:00
|
|
|
|
2008-12-16 18:44:08 +08:00
|
|
|
info->pseudo_palette = kmalloc(sizeof(u32) * 16, GFP_KERNEL);
|
2005-05-01 23:59:24 +08:00
|
|
|
if (!info->pseudo_palette)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
memset(fbi, 0, sizeof(struct imxfb_info));
|
|
|
|
|
|
|
|
strlcpy(info->fix.id, IMX_NAME, sizeof(info->fix.id));
|
|
|
|
|
2008-12-16 18:44:08 +08:00
|
|
|
info->fix.type = FB_TYPE_PACKED_PIXELS;
|
2005-05-01 23:59:24 +08:00
|
|
|
info->fix.type_aux = 0;
|
|
|
|
info->fix.xpanstep = 0;
|
|
|
|
info->fix.ypanstep = 0;
|
|
|
|
info->fix.ywrapstep = 0;
|
2008-12-16 18:44:08 +08:00
|
|
|
info->fix.accel = FB_ACCEL_NONE;
|
2005-05-01 23:59:24 +08:00
|
|
|
|
|
|
|
info->var.nonstd = 0;
|
|
|
|
info->var.activate = FB_ACTIVATE_NOW;
|
|
|
|
info->var.height = -1;
|
|
|
|
info->var.width = -1;
|
|
|
|
info->var.accel_flags = 0;
|
2008-12-16 18:44:08 +08:00
|
|
|
info->var.vmode = FB_VMODE_NONINTERLACED;
|
2005-05-01 23:59:24 +08:00
|
|
|
|
|
|
|
info->fbops = &imxfb_ops;
|
2008-12-16 18:44:08 +08:00
|
|
|
info->flags = FBINFO_FLAG_DEFAULT |
|
|
|
|
FBINFO_READS_FAST;
|
2005-05-01 23:59:24 +08:00
|
|
|
|
|
|
|
fbi->rgb[RGB_16] = &def_rgb_16;
|
|
|
|
fbi->rgb[RGB_8] = &def_rgb_8;
|
|
|
|
|
2008-12-16 18:44:09 +08:00
|
|
|
fbi->max_xres = pdata->xres;
|
|
|
|
info->var.xres = pdata->xres;
|
|
|
|
info->var.xres_virtual = pdata->xres;
|
|
|
|
fbi->max_yres = pdata->yres;
|
|
|
|
info->var.yres = pdata->yres;
|
|
|
|
info->var.yres_virtual = pdata->yres;
|
|
|
|
fbi->max_bpp = pdata->bpp;
|
|
|
|
info->var.bits_per_pixel = pdata->bpp;
|
|
|
|
info->var.nonstd = pdata->nonstd;
|
|
|
|
info->var.pixclock = pdata->pixclock;
|
|
|
|
info->var.hsync_len = pdata->hsync_len;
|
|
|
|
info->var.left_margin = pdata->left_margin;
|
|
|
|
info->var.right_margin = pdata->right_margin;
|
|
|
|
info->var.vsync_len = pdata->vsync_len;
|
|
|
|
info->var.upper_margin = pdata->upper_margin;
|
|
|
|
info->var.lower_margin = pdata->lower_margin;
|
|
|
|
info->var.sync = pdata->sync;
|
|
|
|
info->var.grayscale = pdata->cmap_greyscale;
|
|
|
|
fbi->cmap_inverse = pdata->cmap_inverse;
|
|
|
|
fbi->cmap_static = pdata->cmap_static;
|
|
|
|
fbi->pcr = pdata->pcr;
|
|
|
|
fbi->lscr1 = pdata->lscr1;
|
|
|
|
fbi->dmacr = pdata->dmacr;
|
|
|
|
fbi->pwmr = pdata->pwmr;
|
|
|
|
fbi->lcd_power = pdata->lcd_power;
|
|
|
|
fbi->backlight_power = pdata->backlight_power;
|
2005-05-01 23:59:24 +08:00
|
|
|
info->fix.smem_len = fbi->max_xres * fbi->max_yres *
|
|
|
|
fbi->max_bpp / 8;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-10 06:32:44 +08:00
|
|
|
static int __init imxfb_probe(struct platform_device *pdev)
|
2005-05-01 23:59:24 +08:00
|
|
|
{
|
|
|
|
struct imxfb_info *fbi;
|
|
|
|
struct fb_info *info;
|
2008-12-16 18:44:09 +08:00
|
|
|
struct imx_fb_platform_data *pdata;
|
2005-05-01 23:59:24 +08:00
|
|
|
struct resource *res;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
printk("i.MX Framebuffer driver\n");
|
|
|
|
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
2008-12-16 18:44:08 +08:00
|
|
|
if (!res)
|
2005-05-01 23:59:24 +08:00
|
|
|
return -ENODEV;
|
|
|
|
|
2008-12-16 18:44:09 +08:00
|
|
|
pdata = pdev->dev.platform_data;
|
|
|
|
if (!pdata) {
|
2006-01-07 18:44:32 +08:00
|
|
|
dev_err(&pdev->dev,"No platform_data available\n");
|
2005-05-01 23:59:24 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2005-11-10 06:32:44 +08:00
|
|
|
info = framebuffer_alloc(sizeof(struct imxfb_info), &pdev->dev);
|
2008-12-16 18:44:08 +08:00
|
|
|
if (!info)
|
2005-05-01 23:59:24 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
fbi = info->par;
|
|
|
|
|
2005-11-10 06:32:44 +08:00
|
|
|
platform_set_drvdata(pdev, info);
|
2005-05-01 23:59:24 +08:00
|
|
|
|
2008-12-16 18:44:07 +08:00
|
|
|
ret = imxfb_init_fbinfo(pdev);
|
2008-12-16 18:44:08 +08:00
|
|
|
if (ret < 0)
|
2005-05-01 23:59:24 +08:00
|
|
|
goto failed_init;
|
|
|
|
|
2008-12-16 18:44:07 +08:00
|
|
|
res = request_mem_region(res->start, resource_size(res),
|
|
|
|
DRIVER_NAME);
|
2005-05-01 23:59:24 +08:00
|
|
|
if (!res) {
|
|
|
|
ret = -EBUSY;
|
2008-12-16 18:44:07 +08:00
|
|
|
goto failed_req;
|
|
|
|
}
|
|
|
|
|
|
|
|
fbi->regs = ioremap(res->start, resource_size(res));
|
|
|
|
if (fbi->regs == NULL) {
|
|
|
|
printk(KERN_ERR"Cannot map frame buffer registers\n");
|
|
|
|
goto failed_ioremap;
|
2005-05-01 23:59:24 +08:00
|
|
|
}
|
|
|
|
|
2008-12-16 18:44:09 +08:00
|
|
|
if (!pdata->fixed_screen_cpu) {
|
2008-12-16 18:44:07 +08:00
|
|
|
fbi->map_size = PAGE_ALIGN(info->fix.smem_len);
|
|
|
|
fbi->map_cpu = dma_alloc_writecombine(&pdev->dev,
|
|
|
|
fbi->map_size, &fbi->map_dma, GFP_KERNEL);
|
|
|
|
|
|
|
|
if (!fbi->map_cpu) {
|
2006-01-07 18:44:32 +08:00
|
|
|
dev_err(&pdev->dev, "Failed to allocate video RAM: %d\n", ret);
|
2005-05-01 23:59:24 +08:00
|
|
|
ret = -ENOMEM;
|
|
|
|
goto failed_map;
|
|
|
|
}
|
2008-12-16 18:44:07 +08:00
|
|
|
|
|
|
|
info->screen_base = fbi->map_cpu;
|
|
|
|
fbi->screen_cpu = fbi->map_cpu;
|
|
|
|
fbi->screen_dma = fbi->map_dma;
|
|
|
|
info->fix.smem_start = fbi->screen_dma;
|
2005-05-01 23:59:24 +08:00
|
|
|
} else {
|
|
|
|
/* Fixed framebuffer mapping enables location of the screen in eSRAM */
|
2008-12-16 18:44:09 +08:00
|
|
|
fbi->map_cpu = pdata->fixed_screen_cpu;
|
|
|
|
fbi->map_dma = pdata->fixed_screen_dma;
|
2005-05-01 23:59:24 +08:00
|
|
|
info->screen_base = fbi->map_cpu;
|
|
|
|
fbi->screen_cpu = fbi->map_cpu;
|
|
|
|
fbi->screen_dma = fbi->map_dma;
|
|
|
|
info->fix.smem_start = fbi->screen_dma;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This makes sure that our colour bitfield
|
|
|
|
* descriptors are correctly initialised.
|
|
|
|
*/
|
|
|
|
imxfb_check_var(&info->var, info);
|
|
|
|
|
2008-12-16 18:44:08 +08:00
|
|
|
ret = fb_alloc_cmap(&info->cmap, 1 << info->var.bits_per_pixel, 0);
|
2005-05-01 23:59:24 +08:00
|
|
|
if (ret < 0)
|
|
|
|
goto failed_cmap;
|
|
|
|
|
|
|
|
imxfb_set_par(info);
|
|
|
|
ret = register_framebuffer(info);
|
|
|
|
if (ret < 0) {
|
2006-01-07 18:44:32 +08:00
|
|
|
dev_err(&pdev->dev, "failed to register framebuffer\n");
|
2005-05-01 23:59:24 +08:00
|
|
|
goto failed_register;
|
|
|
|
}
|
|
|
|
|
|
|
|
imxfb_enable_controller(fbi);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
failed_register:
|
|
|
|
fb_dealloc_cmap(&info->cmap);
|
|
|
|
failed_cmap:
|
2008-12-16 18:44:09 +08:00
|
|
|
if (!pdata->fixed_screen_cpu)
|
2005-11-10 06:32:44 +08:00
|
|
|
dma_free_writecombine(&pdev->dev,fbi->map_size,fbi->map_cpu,
|
2008-12-16 18:44:07 +08:00
|
|
|
fbi->map_dma);
|
2005-05-01 23:59:24 +08:00
|
|
|
failed_map:
|
2008-12-16 18:44:07 +08:00
|
|
|
iounmap(fbi->regs);
|
|
|
|
failed_ioremap:
|
2005-05-01 23:59:24 +08:00
|
|
|
release_mem_region(res->start, res->end - res->start);
|
2008-12-16 18:44:07 +08:00
|
|
|
failed_req:
|
|
|
|
kfree(info->pseudo_palette);
|
2005-05-01 23:59:24 +08:00
|
|
|
failed_init:
|
2005-11-10 06:32:44 +08:00
|
|
|
platform_set_drvdata(pdev, NULL);
|
2005-05-01 23:59:24 +08:00
|
|
|
framebuffer_release(info);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-12-16 18:44:07 +08:00
|
|
|
static int __devexit imxfb_remove(struct platform_device *pdev)
|
2005-05-01 23:59:24 +08:00
|
|
|
{
|
2005-11-10 06:32:44 +08:00
|
|
|
struct fb_info *info = platform_get_drvdata(pdev);
|
2005-07-18 03:15:36 +08:00
|
|
|
struct imxfb_info *fbi = info->par;
|
2005-05-01 23:59:24 +08:00
|
|
|
struct resource *res;
|
|
|
|
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
|
|
|
2005-07-18 03:15:36 +08:00
|
|
|
imxfb_disable_controller(fbi);
|
2005-05-01 23:59:24 +08:00
|
|
|
|
|
|
|
unregister_framebuffer(info);
|
|
|
|
|
|
|
|
fb_dealloc_cmap(&info->cmap);
|
|
|
|
kfree(info->pseudo_palette);
|
|
|
|
framebuffer_release(info);
|
|
|
|
|
2008-12-16 18:44:07 +08:00
|
|
|
iounmap(fbi->regs);
|
2005-05-01 23:59:24 +08:00
|
|
|
release_mem_region(res->start, res->end - res->start + 1);
|
2005-11-10 06:32:44 +08:00
|
|
|
platform_set_drvdata(pdev, NULL);
|
2005-05-01 23:59:24 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-10 06:32:44 +08:00
|
|
|
void imxfb_shutdown(struct platform_device * dev)
|
2005-05-01 23:59:24 +08:00
|
|
|
{
|
2005-11-10 06:32:44 +08:00
|
|
|
struct fb_info *info = platform_get_drvdata(dev);
|
2005-07-18 03:15:36 +08:00
|
|
|
struct imxfb_info *fbi = info->par;
|
|
|
|
imxfb_disable_controller(fbi);
|
2005-05-01 23:59:24 +08:00
|
|
|
}
|
|
|
|
|
2005-11-10 06:32:44 +08:00
|
|
|
static struct platform_driver imxfb_driver = {
|
2005-05-01 23:59:24 +08:00
|
|
|
.suspend = imxfb_suspend,
|
|
|
|
.resume = imxfb_resume,
|
2008-12-16 18:44:07 +08:00
|
|
|
.remove = __devexit_p(imxfb_remove),
|
2005-05-01 23:59:24 +08:00
|
|
|
.shutdown = imxfb_shutdown,
|
2005-11-10 06:32:44 +08:00
|
|
|
.driver = {
|
2008-12-16 18:44:07 +08:00
|
|
|
.name = DRIVER_NAME,
|
2005-11-10 06:32:44 +08:00
|
|
|
},
|
2005-05-01 23:59:24 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
int __init imxfb_init(void)
|
|
|
|
{
|
2008-12-16 18:44:07 +08:00
|
|
|
return platform_driver_probe(&imxfb_driver, imxfb_probe);
|
2005-05-01 23:59:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit imxfb_cleanup(void)
|
|
|
|
{
|
2005-11-10 06:32:44 +08:00
|
|
|
platform_driver_unregister(&imxfb_driver);
|
2005-05-01 23:59:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(imxfb_init);
|
|
|
|
module_exit(imxfb_cleanup);
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("Motorola i.MX framebuffer driver");
|
|
|
|
MODULE_AUTHOR("Sascha Hauer, Pengutronix");
|
|
|
|
MODULE_LICENSE("GPL");
|