// SPDX-License-Identifier: GPL-2.0-only
/*
* Freescale i.MX Frame Buffer device driver
*
* Copyright (C) 2004 Sascha Hauer, Pengutronix
* Based on acornfb.c Copyright (C) Russell King.
*
* 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/clk.h>
#include <linux/platform_device.h>
#include <linux/dma-mapping.h>
#include <linux/io.h>
#include <linux/lcd.h>
#include <linux/math64.h>
#include <linux/of.h>
#include <linux/of_device.h>
#include <linux/bitfield.h>
#include <linux/regulator/consumer.h>
#include <video/of_display_timing.h>
#include <video/of_videomode.h>
#include <video/videomode.h>
struct imx_fb_videomode {
struct fb_videomode mode;
u32 pcr;
bool aus_mode;
unsigned char bpp;
};
/*
* 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_MASK GENMASK(25, 20)
#define YMAX_MASK_IMX1 GENMASK(8, 0)
#define YMAX_MASK_IMX21 GENMASK(9, 0)
#define LCDC_VPW 0x08
#define VPW_VPW_MASK GENMASK(9, 0)
#define LCDC_CPOS 0x0C
#define CPOS_CC1 BIT(31)
#define CPOS_CC0 BIT(30)
#define CPOS_OP BIT(28)
#define CPOS_CXP_MASK GENMASK(25, 16)
#define LCDC_LCWHB 0x10
#define LCWHB_BK_EN BIT(31)
#define LCWHB_CW_MASK GENMASK(28, 24)
#define LCWHB_CH_MASK GENMASK(20, 16)
#define LCWHB_BD_MASK GENMASK(7, 0)
#define LCDC_LCHCC 0x14
#define LCDC_PCR 0x18
#define PCR_TFT BIT(31)
#define PCR_COLOR BIT(30)
#define PCR_BPIX_MASK GENMASK(27, 25)
#define PCR_BPIX_8 3
#define PCR_BPIX_12 4
#define PCR_BPIX_16 5
#define PCR_BPIX_18 6
#define PCR_PCD_MASK GENMASK(5, 0)
#define LCDC_HCR 0x1C
#define HCR_H_WIDTH_MASK GENMASK(31, 26)
#define HCR_H_WAIT_1_MASK GENMASK(15, 8)
#define HCR_H_WAIT_2_MASK GENMASK(7, 0)
#define LCDC_VCR 0x20
#define VCR_V_WIDTH_MASK GENMASK(31, 26)
#define VCR_V_WAIT_1_MASK GENMASK(15, 8)
#define VCR_V_WAIT_2_MASK GENMASK(7, 0)
#define LCDC_POS 0x24
#define POS_POS_MASK GENMASK(4, 0)
#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_MX1 BIT(1)
#define RMCR_SELF_REF BIT(0)
#define LCDC_LCDICR 0x38
#define LCDICR_INT_SYN BIT(2)
#define LCDICR_INT_CON BIT(0)
#define LCDC_LCDISR 0x40
#define LCDISR_UDR_ERR BIT(3)
#define LCDISR_ERR_RES BIT(2)
#define LCDISR_EOF BIT(1)
#define LCDISR_BOF BIT(0)
#define IMXFB_LSCR1_DEFAULT 0x00120300
#define LCDC_LAUSCR 0x80
#define LAUSCR_AUS_MODE BIT(31)
/* Used fb-mode. Can be set on kernel command line, therefore file-static. */
static const char *fb_mode;
/*
* 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;
};
enum imxfb_type {
IMX1_FB,
IMX21_FB,
};
enum imxfb_panel_type {
PANEL_TYPE_MONOCHROME,
PANEL_TYPE_CSTN,
PANEL_TYPE_TFT,
};
struct imxfb_info {
struct platform_device *pdev;
void __iomem *regs;
struct clk *clk_ipg;
struct clk *clk_ahb;
struct clk *clk_per;
enum imxfb_type devtype;
enum imxfb_panel_type panel_type;
bool enabled;
/*
* 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 lauscr;
u_int pwmr;
u_int lscr1;
u_int dmacr;
bool cmap_inverse;
bool cmap_static;
struct imx_fb_videomode *mode;
int num_modes;
struct regulator *lcd_pwr;
int lcd_pwr_enabled;
};
static const 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);
static const 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);
static inline int is_imx1_fb(struct imxfb_info *fbi)
{
return fbi->devtype == IMX1_FB;
}
#define IMX_NAME "IMX"
/*
* Minimum X and Y resolutions
*/
#define MIN_XRES 64
#define MIN_YRES 64
/* 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,},
};
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 = {
.red = {.offset = 8, .length =