2005-05-01 15:59:24 +00: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 04:28:13 +00:00
|
|
|
#include <linux/mm.h>
|
2005-05-01 15:59:24 +00:00
|
|
|
#include <linux/fb.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/ioport.h>
|
|
|
|
#include <linux/cpufreq.h>
|
2009-01-15 14:21:00 +00:00
|
|
|
#include <linux/clk.h>
|
2005-10-29 18:07:23 +00:00
|
|
|
#include <linux/platform_device.h>
|
2005-05-01 15:59:24 +00:00
|
|
|
#include <linux/dma-mapping.h>
|
2008-12-16 10:44:07 +00:00
|
|
|
#include <linux/io.h>
|
2013-12-21 11:08:00 +00:00
|
|
|
#include <linux/lcd.h>
|
2009-01-15 14:21:00 +00:00
|
|
|
#include <linux/math64.h>
|
2013-05-26 10:35:38 +00:00
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/of_device.h>
|
|
|
|
|
2013-12-21 11:08:00 +00:00
|
|
|
#include <linux/regulator/consumer.h>
|
|
|
|
|
2013-05-26 10:35:38 +00:00
|
|
|
#include <video/of_display_timing.h>
|
|
|
|
#include <video/of_videomode.h>
|
|
|
|
#include <video/videomode.h>
|
2005-05-01 15:59:24 +00:00
|
|
|
|
2012-08-24 13:14:29 +00:00
|
|
|
#include <linux/platform_data/video-imxfb.h>
|
2005-05-01 15:59:24 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Complain if VAR is out of range.
|
|
|
|
*/
|
|
|
|
#define DEBUG_VAR 1
|
|
|
|
|
2008-12-16 10:44:07 +00:00
|
|
|
#define DRIVER_NAME "imx-fb"
|
|
|
|
|
|
|
|
#define LCDC_SSA 0x00
|
|
|
|
|
|
|
|
#define LCDC_SIZE 0x04
|
|
|
|
#define SIZE_XMAX(x) ((((x) >> 4) & 0x3f) << 20)
|
2009-01-26 16:29:10 +00:00
|
|
|
|
2012-09-16 11:59:53 +00:00
|
|
|
#define YMAX_MASK_IMX1 0x1ff
|
|
|
|
#define YMAX_MASK_IMX21 0x3ff
|
2008-12-16 10:44:07 +00:00
|
|
|
|
|
|
|
#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)
|
2009-01-26 16:29:10 +00:00
|
|
|
|
2008-12-16 10:44:07 +00:00
|
|
|
#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
|
2009-01-26 16:29:10 +00:00
|
|
|
|
2008-12-16 10:44:07 +00:00
|
|
|
#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
|
2009-01-26 16:29:10 +00:00
|
|
|
|
2011-03-03 14:12:44 +00:00
|
|
|
#define RMCR_LCDC_EN_MX1 (1<<1)
|
2009-01-26 16:29:10 +00:00
|
|
|
|
2008-12-16 10:44:07 +00:00
|
|
|
#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)
|
|
|
|
|
2013-05-26 10:35:38 +00:00
|
|
|
#define IMXFB_LSCR1_DEFAULT 0x00120300
|
|
|
|
|
2009-03-19 07:25:41 +00:00
|
|
|
/* Used fb-mode. Can be set on kernel command line, therefore file-static. */
|
|
|
|
static const char *fb_mode;
|
|
|
|
|
2008-12-16 10:44:08 +00: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;
|
|
|
|
};
|
|
|
|
|
2012-09-16 11:59:53 +00:00
|
|
|
enum imxfb_type {
|
|
|
|
IMX1_FB,
|
|
|
|
IMX21_FB,
|
|
|
|
};
|
|
|
|
|
2008-12-16 10:44:08 +00:00
|
|
|
struct imxfb_info {
|
|
|
|
struct platform_device *pdev;
|
|
|
|
void __iomem *regs;
|
2012-03-07 08:30:36 +00:00
|
|
|
struct clk *clk_ipg;
|
|
|
|
struct clk *clk_ahb;
|
|
|
|
struct clk *clk_per;
|
2012-09-16 11:59:53 +00:00
|
|
|
enum imxfb_type devtype;
|
2013-01-16 12:58:41 +00:00
|
|
|
bool enabled;
|
2008-12-16 10:44:08 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* These are the addresses we mapped
|
|
|
|
* the framebuffer memory region to.
|
|
|
|
*/
|
|
|
|
dma_addr_t map_dma;
|
|
|
|
u_int map_size;
|
|
|
|
|
|
|
|
u_int palette_size;
|
|
|
|
|
|
|
|
dma_addr_t dbar1;
|
|
|
|
dma_addr_t dbar2;
|
|
|
|
|
|
|
|
u_int pcr;
|
|
|
|
u_int pwmr;
|
|
|
|
u_int lscr1;
|
|
|
|
u_int dmacr;
|
2014-02-15 05:56:23 +00:00
|
|
|
bool cmap_inverse;
|
|
|
|
bool cmap_static;
|
2008-12-16 10:44:08 +00:00
|
|
|
|
2009-03-19 07:25:41 +00:00
|
|
|
struct imx_fb_videomode *mode;
|
|
|
|
int num_modes;
|
|
|
|
|
2013-12-21 11:08:00 +00:00
|
|
|
struct regulator *lcd_pwr;
|
2008-12-16 10:44:08 +00:00
|
|
|
};
|
|
|
|
|
2012-09-16 11:59:53 +00:00
|
|
|
static struct platform_device_id imxfb_devtype[] = {
|
|
|
|
{
|
|
|
|
.name = "imx1-fb",
|
|
|
|
.driver_data = IMX1_FB,
|
|
|
|
}, {
|
|
|
|
.name = "imx21-fb",
|
|
|
|
.driver_data = IMX21_FB,
|
|
|
|
}, {
|
|
|
|
/* sentinel */
|
|
|
|
}
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(platform, imxfb_devtype);
|
|
|
|
|
2013-05-26 10:35:38 +00:00
|
|
|
static struct of_device_id imxfb_of_dev_id[] = {
|
|
|
|
{
|
|
|
|
.compatible = "fsl,imx1-fb",
|
|
|
|
.data = &imxfb_devtype[IMX1_FB],
|
|
|
|
}, {
|
|
|
|
.compatible = "fsl,imx21-fb",
|
|
|
|
.data = &imxfb_devtype[IMX21_FB],
|
|
|
|
}, {
|
|
|
|
/* sentinel */
|
|
|
|
}
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, imxfb_of_dev_id);
|
|
|
|
|
2012-09-16 11:59:53 +00:00
|
|
|
static inline int is_imx1_fb(struct imxfb_info *fbi)
|
|
|
|
{
|
|
|
|
return fbi->devtype == IMX1_FB;
|
|
|
|
}
|
|
|
|
|
2008-12-16 10:44:08 +00:00
|
|
|
#define IMX_NAME "IMX"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Minimum X and Y resolutions
|
|
|
|
*/
|
|
|
|
#define MIN_XRES 64
|
|
|
|
#define MIN_YRES 64
|
|
|
|
|
2009-01-26 16:31:02 +00:00
|
|
|
/* Actually this really is 18bit support, the lowest 2 bits of each colour
|
|
|
|
* are unused in hardware. We claim to have 24bit support to make software
|
|
|
|
* like X work, which does not support 18bit.
|
|
|
|
*/
|
|
|
|
static struct imxfb_rgb def_rgb_18 = {
|
|
|
|
.red = {.offset = 16, .length = 8,},
|
|
|
|
.green = {.offset = 8, .length = 8,},
|
|
|
|
.blue = {.offset = 0, .length = 8,},
|
|
|
|
.transp = {.offset = 0, .length = 0,},
|
|
|
|
};
|
|
|
|
|
2008-12-16 10:44:09 +00:00
|
|
|
static 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 = {
|
2008-12-16 10:44:08 +00:00
|
|
|
.red = {.offset = 8, .length = 4,},
|
|
|
|
.green = {.offset = 4, .length = 4,},
|
|
|
|
.blue = {.offset = 0, .length = 4,},
|
|
|
|
.transp = {.offset = 0, .length = 0,},
|
2005-05-01 15:59:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct imxfb_rgb def_rgb_8 = {
|
2008-12-16 10:44:08 +00:00
|
|
|
.red = {.offset = 0, .length = 8,},
|
|
|
|
.green = {.offset = 0, .length = 8,},
|
|
|
|
.blue = {.offset = 0, .length = 8,},
|
|
|
|
.transp = {.offset = 0, .length = 0,},
|
2005-05-01 15:59:24 +00:00
|
|
|
};
|
|
|
|
|
2008-12-16 10:44:08 +00:00
|
|
|
static int imxfb_activate_var(struct fb_var_screeninfo *var,
|
|
|
|
struct fb_info *info);
|
2005-05-01 15:59:24 +00: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 10:44:08 +00: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 15:59:24 +00: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 10:44:07 +00:00
|
|
|
writel(val, fbi->regs + 0x800 + (regno << 2));
|
2005-05-01 15:59:24 +00:00
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-12-16 10:44:08 +00:00
|
|
|
static int imxfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
|
2005-05-01 15:59:24 +00: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;
|
|
|
|
}
|
|
|
|
|
2009-03-19 07:25:41 +00:00
|
|
|
static const struct imx_fb_videomode *imxfb_find_mode(struct imxfb_info *fbi)
|
|
|
|
{
|
|
|
|
struct imx_fb_videomode *m;
|
|
|
|
int i;
|
|
|
|
|
2013-05-26 10:35:38 +00:00
|
|
|
if (!fb_mode)
|
|
|
|
return &fbi->mode[0];
|
|
|
|
|
2009-03-19 07:25:41 +00:00
|
|
|
for (i = 0, m = &fbi->mode[0]; i < fbi->num_modes; i++, m++) {
|
|
|
|
if (!strcmp(m->mode.name, fb_mode))
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-05-01 15:59:24 +00:00
|
|
|
/*
|
|
|
|
* 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 10:44:08 +00:00
|
|
|
static int imxfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
|
2005-05-01 15:59:24 +00:00
|
|
|
{
|
|
|
|
struct imxfb_info *fbi = info->par;
|
2008-12-16 10:44:09 +00:00
|
|
|
struct imxfb_rgb *rgb;
|
2009-03-19 07:25:41 +00:00
|
|
|
const struct imx_fb_videomode *imxfb_mode;
|
|
|
|
unsigned long lcd_clk;
|
|
|
|
unsigned long long tmp;
|
|
|
|
u32 pcr = 0;
|
2005-05-01 15:59:24 +00:00
|
|
|
|
|
|
|
if (var->xres < MIN_XRES)
|
|
|
|
var->xres = MIN_XRES;
|
|
|
|
if (var->yres < MIN_YRES)
|
|
|
|
var->yres = MIN_YRES;
|
2009-03-19 07:25:41 +00:00
|
|
|
|
|
|
|
imxfb_mode = imxfb_find_mode(fbi);
|
|
|
|
if (!imxfb_mode)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
var->xres = imxfb_mode->mode.xres;
|
|
|
|
var->yres = imxfb_mode->mode.yres;
|
|
|
|
var->bits_per_pixel = imxfb_mode->bpp;
|
|
|
|
var->pixclock = imxfb_mode->mode.pixclock;
|
|
|
|
var->hsync_len = imxfb_mode->mode.hsync_len;
|
|
|
|
var->left_margin = imxfb_mode->mode.left_margin;
|
|
|
|
var->right_margin = imxfb_mode->mode.right_margin;
|
|
|
|
var->vsync_len = imxfb_mode->mode.vsync_len;
|
|
|
|
var->upper_margin = imxfb_mode->mode.upper_margin;
|
|
|
|
var->lower_margin = imxfb_mode->mode.lower_margin;
|
|
|
|
var->sync = imxfb_mode->mode.sync;
|
|
|
|
var->xres_virtual = max(var->xres_virtual, var->xres);
|
|
|
|
var->yres_virtual = max(var->yres_virtual, var->yres);
|
2005-05-01 15:59:24 +00:00
|
|
|
|
|
|
|
pr_debug("var->bits_per_pixel=%d\n", var->bits_per_pixel);
|
2009-03-19 07:25:41 +00:00
|
|
|
|
2012-03-07 08:30:36 +00:00
|
|
|
lcd_clk = clk_get_rate(fbi->clk_per);
|
2009-03-19 07:25:41 +00:00
|
|
|
|
|
|
|
tmp = var->pixclock * (unsigned long long)lcd_clk;
|
|
|
|
|
|
|
|
do_div(tmp, 1000000);
|
|
|
|
|
|
|
|
if (do_div(tmp, 1000000) > 500000)
|
|
|
|
tmp++;
|
|
|
|
|
|
|
|
pcr = (unsigned int)tmp;
|
|
|
|
|
|
|
|
if (--pcr > 0x3F) {
|
|
|
|
pcr = 0x3F;
|
|
|
|
printk(KERN_WARNING "Must limit pixel clock to %luHz\n",
|
|
|
|
lcd_clk / pcr);
|
|
|
|
}
|
|
|
|
|
2005-05-01 15:59:24 +00:00
|
|
|
switch (var->bits_per_pixel) {
|
2009-01-26 16:31:02 +00:00
|
|
|
case 32:
|
2009-03-19 07:25:41 +00:00
|
|
|
pcr |= PCR_BPIX_18;
|
2009-01-26 16:31:02 +00:00
|
|
|
rgb = &def_rgb_18;
|
|
|
|
break;
|
2005-05-01 15:59:24 +00:00
|
|
|
case 16:
|
2008-12-16 10:44:09 +00:00
|
|
|
default:
|
2012-09-16 11:59:53 +00:00
|
|
|
if (is_imx1_fb(fbi))
|
2009-03-19 07:25:41 +00:00
|
|
|
pcr |= PCR_BPIX_12;
|
|
|
|
else
|
|
|
|
pcr |= PCR_BPIX_16;
|
|
|
|
|
|
|
|
if (imxfb_mode->pcr & PCR_TFT)
|
2008-12-16 10:44:09 +00:00
|
|
|
rgb = &def_rgb_16_tft;
|
|
|
|
else
|
|
|
|
rgb = &def_rgb_16_stn;
|
2005-05-01 15:59:24 +00:00
|
|
|
break;
|
|
|
|
case 8:
|
2009-03-19 07:25:41 +00:00
|
|
|
pcr |= PCR_BPIX_8;
|
2008-12-16 10:44:09 +00:00
|
|
|
rgb = &def_rgb_8;
|
2005-05-01 15:59:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-03-19 07:25:41 +00:00
|
|
|
/* add sync polarities */
|
|
|
|
pcr |= imxfb_mode->pcr & ~(0x3f | (7 << 25));
|
|
|
|
|
|
|
|
fbi->pcr = pcr;
|
|
|
|
|
2005-05-01 15:59:24 +00:00
|
|
|
/*
|
|
|
|
* Copy the RGB parameters for this display
|
|
|
|
* from the machine specific parameters.
|
|
|
|
*/
|
2008-12-16 10:44:09 +00:00
|
|
|
var->red = rgb->red;
|
|
|
|
var->green = rgb->green;
|
|
|
|
var->blue = rgb->blue;
|
|
|
|
var->transp = rgb->transp;
|
2005-05-01 15:59:24 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2009-01-26 16:31:02 +00:00
|
|
|
if (var->bits_per_pixel == 16 || var->bits_per_pixel == 32)
|
2005-05-01 15:59:24 +00:00
|
|
|
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 10:44:08 +00:00
|
|
|
info->fix.line_length = var->xres_virtual * var->bits_per_pixel / 8;
|
2005-05-01 15:59:24 +00: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)
|
|
|
|
{
|
2013-01-16 12:58:41 +00:00
|
|
|
|
|
|
|
if (fbi->enabled)
|
|
|
|
return;
|
|
|
|
|
2005-05-01 15:59:24 +00:00
|
|
|
pr_debug("Enabling LCD controller\n");
|
|
|
|
|
2014-02-15 05:56:23 +00:00
|
|
|
writel(fbi->map_dma, fbi->regs + LCDC_SSA);
|
2005-05-01 15:59:24 +00:00
|
|
|
|
2008-12-16 10:44:07 +00:00
|
|
|
/* panning offset 0 (0 pixel offset) */
|
|
|
|
writel(0x00000000, fbi->regs + LCDC_POS);
|
2005-05-01 15:59:24 +00:00
|
|
|
|
|
|
|
/* disable hardware cursor */
|
2008-12-16 10:44:07 +00:00
|
|
|
writel(readl(fbi->regs + LCDC_CPOS) & ~(CPOS_CC0 | CPOS_CC1),
|
|
|
|
fbi->regs + LCDC_CPOS);
|
2005-05-01 15:59:24 +00:00
|
|
|
|
2011-03-03 14:12:44 +00:00
|
|
|
/*
|
|
|
|
* RMCR_LCDC_EN_MX1 is present on i.MX1 only, but doesn't hurt
|
|
|
|
* on other SoCs
|
|
|
|
*/
|
|
|
|
writel(RMCR_LCDC_EN_MX1, fbi->regs + LCDC_RMCR);
|
2005-05-01 15:59:24 +00:00
|
|
|
|
2012-03-07 08:30:36 +00:00
|
|
|
clk_prepare_enable(fbi->clk_ipg);
|
|
|
|
clk_prepare_enable(fbi->clk_ahb);
|
|
|
|
clk_prepare_enable(fbi->clk_per);
|
2013-01-16 12:58:41 +00:00
|
|
|
fbi->enabled = true;
|
2005-05-01 15:59:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void imxfb_disable_controller(struct imxfb_info *fbi)
|
|
|
|
{
|
2013-01-16 12:58:41 +00:00
|
|
|
if (!fbi->enabled)
|
|
|
|
return;
|
|
|
|
|
2005-05-01 15:59:24 +00:00
|
|
|
pr_debug("Disabling LCD controller\n");
|
|
|
|
|
2012-03-07 08:30:36 +00:00
|
|
|
clk_disable_unprepare(fbi->clk_per);
|
|
|
|
clk_disable_unprepare(fbi->clk_ipg);
|
|
|
|
clk_disable_unprepare(fbi->clk_ahb);
|
2013-01-16 12:58:41 +00:00
|
|
|
fbi->enabled = false;
|
2009-01-15 14:21:00 +00:00
|
|
|
|
2008-12-16 10:44:07 +00:00
|
|
|
writel(0, fbi->regs + LCDC_RMCR);
|
2005-05-01 15:59:24 +00: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;
|
2012-09-16 11:59:53 +00:00
|
|
|
u32 ymax_mask = is_imx1_fb(fbi) ? YMAX_MASK_IMX1 : YMAX_MASK_IMX21;
|
2009-01-15 14:21:00 +00:00
|
|
|
|
2005-05-01 15:59:24 +00:00
|
|
|
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);
|
2012-09-16 11:59:53 +00:00
|
|
|
if (var->yres < 1 || var->yres > ymax_mask)
|
2005-05-01 15:59:24 +00:00
|
|
|
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
|
|
|
|
|
2009-03-19 07:25:41 +00:00
|
|
|
/* physical screen start address */
|
|
|
|
writel(VPW_VPW(var->xres * var->bits_per_pixel / 8 / 4),
|
|
|
|
fbi->regs + LCDC_VPW);
|
|
|
|
|
2009-02-14 15:29:38 +00:00
|
|
|
writel(HCR_H_WIDTH(var->hsync_len - 1) |
|
|
|
|
HCR_H_WAIT_1(var->right_margin - 1) |
|
|
|
|
HCR_H_WAIT_2(var->left_margin - 3),
|
2008-12-16 10:44:07 +00:00
|
|
|
fbi->regs + LCDC_HCR);
|
2005-05-01 15:59:24 +00:00
|
|
|
|
2008-12-16 10:44:07 +00:00
|
|
|
writel(VCR_V_WIDTH(var->vsync_len) |
|
2008-12-16 10:44:08 +00:00
|
|
|
VCR_V_WAIT_1(var->lower_margin) |
|
|
|
|
VCR_V_WAIT_2(var->upper_margin),
|
2008-12-16 10:44:07 +00:00
|
|
|
fbi->regs + LCDC_VCR);
|
2005-05-01 15:59:24 +00:00
|
|
|
|
2012-09-16 11:59:53 +00:00
|
|
|
writel(SIZE_XMAX(var->xres) | (var->yres & ymax_mask),
|
2008-12-16 10:44:07 +00:00
|
|
|
fbi->regs + LCDC_SIZE);
|
2009-01-15 14:21:00 +00:00
|
|
|
|
2009-03-19 07:25:41 +00:00
|
|
|
writel(fbi->pcr, fbi->regs + LCDC_PCR);
|
2013-05-26 10:35:38 +00:00
|
|
|
if (fbi->pwmr)
|
|
|
|
writel(fbi->pwmr, fbi->regs + LCDC_PWMR);
|
2008-12-16 10:44:07 +00:00
|
|
|
writel(fbi->lscr1, fbi->regs + LCDC_LSCR1);
|
2013-05-26 10:35:38 +00:00
|
|
|
|
|
|
|
/* dmacr = 0 is no valid value, as we need DMA control marks. */
|
|
|
|
if (fbi->dmacr)
|
|
|
|
writel(fbi->dmacr, fbi->regs + LCDC_DMACR);
|
2005-05-01 15:59:24 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-05-26 10:35:38 +00:00
|
|
|
static int imxfb_init_fbinfo(struct platform_device *pdev)
|
2005-05-01 15:59:24 +00:00
|
|
|
{
|
2013-09-17 05:08:58 +00:00
|
|
|
struct imx_fb_platform_data *pdata = dev_get_platdata(&pdev->dev);
|
2008-12-16 10:44:07 +00:00
|
|
|
struct fb_info *info = dev_get_drvdata(&pdev->dev);
|
2005-05-01 15:59:24 +00:00
|
|
|
struct imxfb_info *fbi = info->par;
|
2013-05-26 10:35:38 +00:00
|
|
|
struct device_node *np;
|
2005-05-01 15:59:24 +00:00
|
|
|
|
2008-04-28 09:15:47 +00:00
|
|
|
pr_debug("%s\n",__func__);
|
2005-05-01 15:59:24 +00:00
|
|
|
|
2008-12-16 10:44:08 +00:00
|
|
|
info->pseudo_palette = kmalloc(sizeof(u32) * 16, GFP_KERNEL);
|
2005-05-01 15:59:24 +00:00
|
|
|
if (!info->pseudo_palette)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
memset(fbi, 0, sizeof(struct imxfb_info));
|
|
|
|
|
2013-01-13 15:56:43 +00:00
|
|
|
fbi->devtype = pdev->id_entry->driver_data;
|
|
|
|
|
2005-05-01 15:59:24 +00:00
|
|
|
strlcpy(info->fix.id, IMX_NAME, sizeof(info->fix.id));
|
|
|
|
|
2008-12-16 10:44:08 +00:00
|
|
|
info->fix.type = FB_TYPE_PACKED_PIXELS;
|
2005-05-01 15:59:24 +00:00
|
|
|
info->fix.type_aux = 0;
|
|
|
|
info->fix.xpanstep = 0;
|
|
|
|
info->fix.ypanstep = 0;
|
|
|
|
info->fix.ywrapstep = 0;
|
2008-12-16 10:44:08 +00:00
|
|
|
info->fix.accel = FB_ACCEL_NONE;
|
2005-05-01 15:59:24 +00: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 10:44:08 +00:00
|
|
|
info->var.vmode = FB_VMODE_NONINTERLACED;
|
2005-05-01 15:59:24 +00:00
|
|
|
|
|
|
|
info->fbops = &imxfb_ops;
|
2008-12-16 10:44:08 +00:00
|
|
|
info->flags = FBINFO_FLAG_DEFAULT |
|
|
|
|
FBINFO_READS_FAST;
|
2013-05-26 10:35:38 +00:00
|
|
|
if (pdata) {
|
|
|
|
fbi->lscr1 = pdata->lscr1;
|
|
|
|
fbi->dmacr = pdata->dmacr;
|
|
|
|
fbi->pwmr = pdata->pwmr;
|
|
|
|
} else {
|
|
|
|
np = pdev->dev.of_node;
|
|
|
|
info->var.grayscale = of_property_read_bool(np,
|
|
|
|
"cmap-greyscale");
|
|
|
|
fbi->cmap_inverse = of_property_read_bool(np, "cmap-inverse");
|
|
|
|
fbi->cmap_static = of_property_read_bool(np, "cmap-static");
|
|
|
|
|
|
|
|
fbi->lscr1 = IMXFB_LSCR1_DEFAULT;
|
|
|
|
of_property_read_u32(np, "fsl,lscr1", &fbi->lscr1);
|
|
|
|
|
|
|
|
of_property_read_u32(np, "fsl,dmacr", &fbi->dmacr);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int imxfb_of_read_mode(struct device *dev, struct device_node *np,
|
|
|
|
struct imx_fb_videomode *imxfb_mode)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct fb_videomode *of_mode = &imxfb_mode->mode;
|
|
|
|
u32 bpp;
|
|
|
|
u32 pcr;
|
|
|
|
|
|
|
|
ret = of_property_read_string(np, "model", &of_mode->name);
|
|
|
|
if (ret)
|
|
|
|
of_mode->name = NULL;
|
|
|
|
|
|
|
|
ret = of_get_fb_videomode(np, of_mode, OF_USE_NATIVE_MODE);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(dev, "Failed to get videomode from DT\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = of_property_read_u32(np, "bits-per-pixel", &bpp);
|
|
|
|
ret |= of_property_read_u32(np, "fsl,pcr", &pcr);
|
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
dev_err(dev, "Failed to read bpp and pcr from DT\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bpp < 1 || bpp > 255) {
|
|
|
|
dev_err(dev, "Bits per pixel have to be between 1 and 255\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
imxfb_mode->bpp = bpp;
|
|
|
|
imxfb_mode->pcr = pcr;
|
2005-05-01 15:59:24 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-12-21 11:08:00 +00:00
|
|
|
static int imxfb_lcd_check_fb(struct lcd_device *lcddev, struct fb_info *fi)
|
|
|
|
{
|
|
|
|
struct imxfb_info *fbi = dev_get_drvdata(&lcddev->dev);
|
|
|
|
|
|
|
|
if (!fi || fi->par == fbi)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-02-15 05:56:25 +00:00
|
|
|
static int imxfb_lcd_get_contrast(struct lcd_device *lcddev)
|
|
|
|
{
|
|
|
|
struct imxfb_info *fbi = dev_get_drvdata(&lcddev->dev);
|
|
|
|
|
|
|
|
return fbi->pwmr & 0xff;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int imxfb_lcd_set_contrast(struct lcd_device *lcddev, int contrast)
|
|
|
|
{
|
|
|
|
struct imxfb_info *fbi = dev_get_drvdata(&lcddev->dev);
|
|
|
|
|
|
|
|
if (fbi->pwmr && fbi->enabled) {
|
|
|
|
if (contrast > 255)
|
|
|
|
contrast = 255;
|
|
|
|
else if (contrast < 0)
|
|
|
|
contrast = 0;
|
|
|
|
|
|
|
|
fbi->pwmr &= ~0xff;
|
|
|
|
fbi->pwmr |= contrast;
|
|
|
|
|
|
|
|
writel(fbi->pwmr, fbi->regs + LCDC_PWMR);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-12-21 11:08:00 +00:00
|
|
|
static int imxfb_lcd_get_power(struct lcd_device *lcddev)
|
|
|
|
{
|
|
|
|
struct imxfb_info *fbi = dev_get_drvdata(&lcddev->dev);
|
|
|
|
|
|
|
|
if (!IS_ERR(fbi->lcd_pwr))
|
|
|
|
return regulator_is_enabled(fbi->lcd_pwr);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int imxfb_lcd_set_power(struct lcd_device *lcddev, int power)
|
|
|
|
{
|
|
|
|
struct imxfb_info *fbi = dev_get_drvdata(&lcddev->dev);
|
|
|
|
|
|
|
|
if (!IS_ERR(fbi->lcd_pwr)) {
|
|
|
|
if (power)
|
|
|
|
return regulator_enable(fbi->lcd_pwr);
|
|
|
|
else
|
|
|
|
return regulator_disable(fbi->lcd_pwr);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct lcd_ops imxfb_lcd_ops = {
|
|
|
|
.check_fb = imxfb_lcd_check_fb,
|
2014-02-15 05:56:25 +00:00
|
|
|
.get_contrast = imxfb_lcd_get_contrast,
|
|
|
|
.set_contrast = imxfb_lcd_set_contrast,
|
2013-12-21 11:08:00 +00:00
|
|
|
.get_power = imxfb_lcd_get_power,
|
|
|
|
.set_power = imxfb_lcd_set_power,
|
|
|
|
};
|
|
|
|
|
2014-02-15 05:56:24 +00:00
|
|
|
static int imxfb_setup(void)
|
|
|
|
{
|
|
|
|
char *opt, *options = NULL;
|
|
|
|
|
|
|
|
if (fb_get_options("imxfb", &options))
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
if (!options || !*options)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
while ((opt = strsep(&options, ",")) != NULL) {
|
|
|
|
if (!*opt)
|
|
|
|
continue;
|
|
|
|
else
|
|
|
|
fb_mode = opt;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-05-26 10:35:38 +00:00
|
|
|
static int imxfb_probe(struct platform_device *pdev)
|
2005-05-01 15:59:24 +00:00
|
|
|
{
|
|
|
|
struct imxfb_info *fbi;
|
2013-12-21 11:08:00 +00:00
|
|
|
struct lcd_device *lcd;
|
2005-05-01 15:59:24 +00:00
|
|
|
struct fb_info *info;
|
2008-12-16 10:44:09 +00:00
|
|
|
struct imx_fb_platform_data *pdata;
|
2005-05-01 15:59:24 +00:00
|
|
|
struct resource *res;
|
2013-05-26 10:35:38 +00:00
|
|
|
struct imx_fb_videomode *m;
|
|
|
|
const struct of_device_id *of_id;
|
2009-03-19 07:25:41 +00:00
|
|
|
int ret, i;
|
2013-05-26 10:35:38 +00:00
|
|
|
int bytes_per_pixel;
|
2005-05-01 15:59:24 +00:00
|
|
|
|
2009-06-29 09:41:09 +00:00
|
|
|
dev_info(&pdev->dev, "i.MX Framebuffer driver\n");
|
2005-05-01 15:59:24 +00:00
|
|
|
|
2014-02-15 05:56:24 +00:00
|
|
|
ret = imxfb_setup();
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
2013-05-26 10:35:38 +00:00
|
|
|
of_id = of_match_device(imxfb_of_dev_id, &pdev->dev);
|
|
|
|
if (of_id)
|
|
|
|
pdev->id_entry = of_id->data;
|
|
|
|
|
2005-05-01 15:59:24 +00:00
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
2008-12-16 10:44:08 +00:00
|
|
|
if (!res)
|
2005-05-01 15:59:24 +00:00
|
|
|
return -ENODEV;
|
|
|
|
|
2013-09-17 05:08:58 +00:00
|
|
|
pdata = dev_get_platdata(&pdev->dev);
|
2005-05-01 15:59:24 +00:00
|
|
|
|
2005-11-09 22:32:44 +00:00
|
|
|
info = framebuffer_alloc(sizeof(struct imxfb_info), &pdev->dev);
|
2008-12-16 10:44:08 +00:00
|
|
|
if (!info)
|
2005-05-01 15:59:24 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
fbi = info->par;
|
|
|
|
|
2005-11-09 22:32:44 +00:00
|
|
|
platform_set_drvdata(pdev, info);
|
2005-05-01 15:59:24 +00:00
|
|
|
|
2008-12-16 10:44:07 +00:00
|
|
|
ret = imxfb_init_fbinfo(pdev);
|
2008-12-16 10:44:08 +00:00
|
|
|
if (ret < 0)
|
2005-05-01 15:59:24 +00:00
|
|
|
goto failed_init;
|
|
|
|
|
2013-05-26 10:35:38 +00:00
|
|
|
if (pdata) {
|
|
|
|
if (!fb_mode)
|
|
|
|
fb_mode = pdata->mode[0].mode.name;
|
|
|
|
|
|
|
|
fbi->mode = pdata->mode;
|
|
|
|
fbi->num_modes = pdata->num_modes;
|
|
|
|
} else {
|
|
|
|
struct device_node *display_np;
|
|
|
|
fb_mode = NULL;
|
|
|
|
|
|
|
|
display_np = of_parse_phandle(pdev->dev.of_node, "display", 0);
|
|
|
|
if (!display_np) {
|
|
|
|
dev_err(&pdev->dev, "No display defined in devicetree\n");
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto failed_of_parse;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* imxfb does not support more modes, we choose only the native
|
|
|
|
* mode.
|
|
|
|
*/
|
|
|
|
fbi->num_modes = 1;
|
|
|
|
|
|
|
|
fbi->mode = devm_kzalloc(&pdev->dev,
|
|
|
|
sizeof(struct imx_fb_videomode), GFP_KERNEL);
|
|
|
|
if (!fbi->mode) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto failed_of_parse;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = imxfb_of_read_mode(&pdev->dev, display_np, fbi->mode);
|
|
|
|
if (ret)
|
|
|
|
goto failed_of_parse;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Calculate maximum bytes used per pixel. In most cases this should
|
|
|
|
* be the same as m->bpp/8 */
|
|
|
|
m = &fbi->mode[0];
|
|
|
|
bytes_per_pixel = (m->bpp + 7) / 8;
|
|
|
|
for (i = 0; i < fbi->num_modes; i++, m++)
|
|
|
|
info->fix.smem_len = max_t(size_t, info->fix.smem_len,
|
|
|
|
m->mode.xres * m->mode.yres * bytes_per_pixel);
|
|
|
|
|
2008-12-16 10:44:07 +00:00
|
|
|
res = request_mem_region(res->start, resource_size(res),
|
|
|
|
DRIVER_NAME);
|
2005-05-01 15:59:24 +00:00
|
|
|
if (!res) {
|
|
|
|
ret = -EBUSY;
|
2008-12-16 10:44:07 +00:00
|
|
|
goto failed_req;
|
|
|
|
}
|
|
|
|
|
2012-03-07 08:30:36 +00:00
|
|
|
fbi->clk_ipg = devm_clk_get(&pdev->dev, "ipg");
|
|
|
|
if (IS_ERR(fbi->clk_ipg)) {
|
|
|
|
ret = PTR_ERR(fbi->clk_ipg);
|
|
|
|
goto failed_getclock;
|
|
|
|
}
|
|
|
|
|
|
|
|
fbi->clk_ahb = devm_clk_get(&pdev->dev, "ahb");
|
|
|
|
if (IS_ERR(fbi->clk_ahb)) {
|
|
|
|
ret = PTR_ERR(fbi->clk_ahb);
|
|
|
|
goto failed_getclock;
|
|
|
|
}
|
|
|
|
|
|
|
|
fbi->clk_per = devm_clk_get(&pdev->dev, "per");
|
|
|
|
if (IS_ERR(fbi->clk_per)) {
|
|
|
|
ret = PTR_ERR(fbi->clk_per);
|
2009-01-15 14:21:00 +00:00
|
|
|
goto failed_getclock;
|
|
|
|
}
|
|
|
|
|
2008-12-16 10:44:07 +00:00
|
|
|
fbi->regs = ioremap(res->start, resource_size(res));
|
|
|
|
if (fbi->regs == NULL) {
|
2009-06-29 09:41:09 +00:00
|
|
|
dev_err(&pdev->dev, "Cannot map frame buffer registers\n");
|
2012-09-18 12:07:56 +00:00
|
|
|
ret = -ENOMEM;
|
2008-12-16 10:44:07 +00:00
|
|
|
goto failed_ioremap;
|
2005-05-01 15:59:24 +00:00
|
|
|
}
|
|
|
|
|
2014-02-15 05:56:23 +00:00
|
|
|
fbi->map_size = PAGE_ALIGN(info->fix.smem_len);
|
|
|
|
info->screen_base = dma_alloc_writecombine(&pdev->dev, fbi->map_size,
|
|
|
|
&fbi->map_dma, GFP_KERNEL);
|
2008-12-16 10:44:07 +00:00
|
|
|
|
2014-02-15 05:56:23 +00:00
|
|
|
if (!info->screen_base) {
|
|
|
|
dev_err(&pdev->dev, "Failed to allocate video RAM: %d\n", ret);
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto failed_map;
|
2005-05-01 15:59:24 +00:00
|
|
|
}
|
|
|
|
|
2014-02-15 05:56:23 +00:00
|
|
|
info->fix.smem_start = fbi->map_dma;
|
|
|
|
|
2013-05-26 10:35:38 +00:00
|
|
|
if (pdata && pdata->init) {
|
2009-01-15 14:37:22 +00:00
|
|
|
ret = pdata->init(fbi->pdev);
|
|
|
|
if (ret)
|
|
|
|
goto failed_platform_init;
|
|
|
|
}
|
|
|
|
|
2009-03-19 07:25:41 +00:00
|
|
|
|
|
|
|
INIT_LIST_HEAD(&info->modelist);
|
2013-05-26 10:35:38 +00:00
|
|
|
for (i = 0; i < fbi->num_modes; i++)
|
|
|
|
fb_add_videomode(&fbi->mode[i].mode, &info->modelist);
|
2009-03-19 07:25:41 +00:00
|
|
|
|
2005-05-01 15:59:24 +00:00
|
|
|
/*
|
|
|
|
* This makes sure that our colour bitfield
|
|
|
|
* descriptors are correctly initialised.
|
|
|
|
*/
|
|
|
|
imxfb_check_var(&info->var, info);
|
|
|
|
|
2008-12-16 10:44:08 +00:00
|
|
|
ret = fb_alloc_cmap(&info->cmap, 1 << info->var.bits_per_pixel, 0);
|
2005-05-01 15:59:24 +00:00
|
|
|
if (ret < 0)
|
|
|
|
goto failed_cmap;
|
|
|
|
|
|
|
|
imxfb_set_par(info);
|
|
|
|
ret = register_framebuffer(info);
|
|
|
|
if (ret < 0) {
|
2006-01-07 10:44:32 +00:00
|
|
|
dev_err(&pdev->dev, "failed to register framebuffer\n");
|
2005-05-01 15:59:24 +00:00
|
|
|
goto failed_register;
|
|
|
|
}
|
|
|
|
|
2013-12-21 11:08:00 +00:00
|
|
|
fbi->lcd_pwr = devm_regulator_get(&pdev->dev, "lcd");
|
|
|
|
if (IS_ERR(fbi->lcd_pwr) && (PTR_ERR(fbi->lcd_pwr) == -EPROBE_DEFER)) {
|
|
|
|
ret = -EPROBE_DEFER;
|
|
|
|
goto failed_lcd;
|
|
|
|
}
|
|
|
|
|
|
|
|
lcd = devm_lcd_device_register(&pdev->dev, "imxfb-lcd", &pdev->dev, fbi,
|
|
|
|
&imxfb_lcd_ops);
|
|
|
|
if (IS_ERR(lcd)) {
|
|
|
|
ret = PTR_ERR(lcd);
|
|
|
|
goto failed_lcd;
|
|
|
|
}
|
|
|
|
|
2014-02-15 05:56:25 +00:00
|
|
|
lcd->props.max_contrast = 0xff;
|
|
|
|
|
2005-05-01 15:59:24 +00:00
|
|
|
imxfb_enable_controller(fbi);
|
2010-07-16 13:09:07 +00:00
|
|
|
fbi->pdev = pdev;
|
2005-05-01 15:59:24 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2013-12-21 11:08:00 +00:00
|
|
|
failed_lcd:
|
|
|
|
unregister_framebuffer(info);
|
|
|
|
|
2005-05-01 15:59:24 +00:00
|
|
|
failed_register:
|
|
|
|
fb_dealloc_cmap(&info->cmap);
|
|
|
|
failed_cmap:
|
2013-05-26 10:35:38 +00:00
|
|
|
if (pdata && pdata->exit)
|
2009-01-15 14:37:22 +00:00
|
|
|
pdata->exit(fbi->pdev);
|
|
|
|
failed_platform_init:
|
2014-02-15 05:56:23 +00:00
|
|
|
dma_free_writecombine(&pdev->dev, fbi->map_size, info->screen_base,
|
|
|
|
fbi->map_dma);
|
2005-05-01 15:59:24 +00:00
|
|
|
failed_map:
|
2008-12-16 10:44:07 +00:00
|
|
|
iounmap(fbi->regs);
|
|
|
|
failed_ioremap:
|
2011-06-01 17:10:11 +00:00
|
|
|
failed_getclock:
|
2009-06-29 09:41:09 +00:00
|
|
|
release_mem_region(res->start, resource_size(res));
|
2008-12-16 10:44:07 +00:00
|
|
|
failed_req:
|
2013-05-26 10:35:38 +00:00
|
|
|
failed_of_parse:
|
2008-12-16 10:44:07 +00:00
|
|
|
kfree(info->pseudo_palette);
|
2005-05-01 15:59:24 +00:00
|
|
|
failed_init:
|
|
|
|
framebuffer_release(info);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-12-21 21:07:39 +00:00
|
|
|
static int imxfb_remove(struct platform_device *pdev)
|
2005-05-01 15:59:24 +00:00
|
|
|
{
|
2009-01-15 14:37:22 +00:00
|
|
|
struct imx_fb_platform_data *pdata;
|
2005-11-09 22:32:44 +00:00
|
|
|
struct fb_info *info = platform_get_drvdata(pdev);
|
2005-07-17 19:15:36 +00:00
|
|
|
struct imxfb_info *fbi = info->par;
|
2005-05-01 15:59:24 +00:00
|
|
|
struct resource *res;
|
|
|
|
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
|
|
|
2005-07-17 19:15:36 +00:00
|
|
|
imxfb_disable_controller(fbi);
|
2005-05-01 15:59:24 +00:00
|
|
|
|
|
|
|
unregister_framebuffer(info);
|
|
|
|
|
2013-09-17 05:08:58 +00:00
|
|
|
pdata = dev_get_platdata(&pdev->dev);
|
2013-05-26 10:35:38 +00:00
|
|
|
if (pdata && pdata->exit)
|
2009-01-15 14:37:22 +00:00
|
|
|
pdata->exit(fbi->pdev);
|
|
|
|
|
2005-05-01 15:59:24 +00:00
|
|
|
fb_dealloc_cmap(&info->cmap);
|
|
|
|
kfree(info->pseudo_palette);
|
|
|
|
framebuffer_release(info);
|
|
|
|
|
2014-02-15 05:56:23 +00:00
|
|
|
dma_free_writecombine(&pdev->dev, fbi->map_size, info->screen_base,
|
|
|
|
fbi->map_dma);
|
|
|
|
|
2008-12-16 10:44:07 +00:00
|
|
|
iounmap(fbi->regs);
|
2009-06-29 09:41:09 +00:00
|
|
|
release_mem_region(res->start, resource_size(res));
|
2009-01-15 14:21:00 +00:00
|
|
|
|
2005-05-01 15:59:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-02-15 05:56:26 +00:00
|
|
|
static int __maybe_unused imxfb_suspend(struct device *dev)
|
2005-05-01 15:59:24 +00:00
|
|
|
{
|
2014-02-15 05:56:26 +00:00
|
|
|
struct fb_info *info = dev_get_drvdata(dev);
|
2005-07-17 19:15:36 +00:00
|
|
|
struct imxfb_info *fbi = info->par;
|
2014-02-15 05:56:26 +00:00
|
|
|
|
2005-07-17 19:15:36 +00:00
|
|
|
imxfb_disable_controller(fbi);
|
2014-02-15 05:56:26 +00:00
|
|
|
|
|
|
|
return 0;
|
2005-05-01 15:59:24 +00:00
|
|
|
}
|
|
|
|
|
2014-02-15 05:56:26 +00:00
|
|
|
static int __maybe_unused imxfb_resume(struct device *dev)
|
|
|
|
{
|
|
|
|
struct fb_info *info = dev_get_drvdata(dev);
|
|
|
|
struct imxfb_info *fbi = info->par;
|
|
|
|
|
|
|
|
imxfb_enable_controller(fbi);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static SIMPLE_DEV_PM_OPS(imxfb_pm_ops, imxfb_suspend, imxfb_resume);
|
|
|
|
|
2005-11-09 22:32:44 +00:00
|
|
|
static struct platform_driver imxfb_driver = {
|
|
|
|
.driver = {
|
2008-12-16 10:44:07 +00:00
|
|
|
.name = DRIVER_NAME,
|
2013-05-26 10:35:38 +00:00
|
|
|
.of_match_table = imxfb_of_dev_id,
|
2014-02-15 05:56:26 +00:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.pm = &imxfb_pm_ops,
|
2005-11-09 22:32:44 +00:00
|
|
|
},
|
2014-02-15 05:56:26 +00:00
|
|
|
.probe = imxfb_probe,
|
|
|
|
.remove = imxfb_remove,
|
2012-09-16 11:59:53 +00:00
|
|
|
.id_table = imxfb_devtype,
|
2005-05-01 15:59:24 +00:00
|
|
|
};
|
2014-02-15 05:56:24 +00:00
|
|
|
module_platform_driver(imxfb_driver);
|
2005-05-01 15:59:24 +00:00
|
|
|
|
2011-01-10 11:47:41 +00:00
|
|
|
MODULE_DESCRIPTION("Freescale i.MX framebuffer driver");
|
2005-05-01 15:59:24 +00:00
|
|
|
MODULE_AUTHOR("Sascha Hauer, Pengutronix");
|
|
|
|
MODULE_LICENSE("GPL");
|