[PATCH 5/7] DRM: add i.MX kms simple driver

2012-04-11 Thread Sascha Hauer
This adds a sdrm driver for the Freescale i.MX LCDC controller. It
is found on i.MX1, i.MX21, i.MX25 and i.MX27. Currently only the
base framebuffer is supported, no overlay. This has been tested
on an i.MX27 custom board with the xf86 modesetting driver.

Signed-off-by: Sascha Hauer 
---
 arch/arm/plat-mxc/include/mach/imxfb.h |8 +-
 drivers/gpu/drm/Kconfig|2 +
 drivers/gpu/drm/Makefile   |1 +
 drivers/gpu/drm/imx/Kconfig|8 +
 drivers/gpu/drm/imx/Makefile   |1 +
 drivers/gpu/drm/imx/imx-lcdc-crtc.c|  506 
 6 files changed, 525 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/imx/Kconfig
 create mode 100644 drivers/gpu/drm/imx/Makefile
 create mode 100644 drivers/gpu/drm/imx/imx-lcdc-crtc.c

diff --git a/arch/arm/plat-mxc/include/mach/imxfb.h 
b/arch/arm/plat-mxc/include/mach/imxfb.h
index 9de8f06..5d4aa61 100644
--- a/arch/arm/plat-mxc/include/mach/imxfb.h
+++ b/arch/arm/plat-mxc/include/mach/imxfb.h
@@ -80,5 +80,11 @@ struct imx_fb_platform_data {
void (*backlight_power)(int);
 };

-void set_imx_fb_info(struct imx_fb_platform_data *);
+/* drm platform data */
+struct imx_drm_platform_data {
+   u32 lscr1;
+   u32 pcr;
+   u32 pwmr;
+};
+
 #endif /* ifndef __MACH_IMXFB_H__ */
diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
index 93d9f79..4650d65 100644
--- a/drivers/gpu/drm/Kconfig
+++ b/drivers/gpu/drm/Kconfig
@@ -188,3 +188,5 @@ source "drivers/gpu/drm/gma500/Kconfig"
 source "drivers/gpu/drm/udl/Kconfig"

 source "drivers/gpu/drm/sdrm/Kconfig"
+
+source "drivers/gpu/drm/imx/Kconfig"
diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index 44c5949..b0c283e 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -43,4 +43,5 @@ obj-$(CONFIG_DRM_EXYNOS) +=exynos/
 obj-$(CONFIG_DRM_GMA500) += gma500/
 obj-$(CONFIG_DRM_UDL) += udl/
 obj-$(CONFIG_DRM_SDRM) += sdrm/
+obj-$(CONFIG_DRM_IMX) +=imx/
 obj-y  += i2c/
diff --git a/drivers/gpu/drm/imx/Kconfig b/drivers/gpu/drm/imx/Kconfig
new file mode 100644
index 000..d5ad7ed
--- /dev/null
+++ b/drivers/gpu/drm/imx/Kconfig
@@ -0,0 +1,8 @@
+config DRM_IMX_LCDC
+   tristate "DRM Support for Freescale i.MX1 and i.MX2"
+   depends on DRM && ARCH_MXC
+   select DRM_SDRM
+   select DRM_SDRM_ENCON
+   help
+ Choose this if you have a i.MX1, i.MX21, i.MX25 or i.MX27 processor.
+
diff --git a/drivers/gpu/drm/imx/Makefile b/drivers/gpu/drm/imx/Makefile
new file mode 100644
index 000..cc84f65
--- /dev/null
+++ b/drivers/gpu/drm/imx/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_DRM_IMX_LCDC) += imx-lcdc-crtc.o
diff --git a/drivers/gpu/drm/imx/imx-lcdc-crtc.c 
b/drivers/gpu/drm/imx/imx-lcdc-crtc.c
new file mode 100644
index 000..620b04b
--- /dev/null
+++ b/drivers/gpu/drm/imx/imx-lcdc-crtc.c
@@ -0,0 +1,506 @@
+/*
+ * i.MX crtc driver
+ *
+ * Copyright (C) 2012 Sascha Hauer, Pengutronix
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define LCDC_SSA   0x00
+#define LCDC_SIZE  0x04
+#define LCDC_VPW   0x08
+#define LCDC_CPOS  0x0C
+#define LCDC_LCWHB 0x10
+#define LCDC_LCHCC 0x14
+#define LCDC_PCR   0x18
+#define LCDC_HCR   0x1C
+#define LCDC_VCR   0x20
+#define LCDC_POS   0x24
+#define LCDC_LSCR1 0x28
+#define LCDC_PWMR  0x2C
+#define LCDC_DMACR 0x30
+#define LCDC_RMCR  0x34
+#define LCDC_LCDICR0x38
+#define LCDC_LIER  0x3c
+#define LCDC_LISR  0x40
+
+#define SIZE_XMAX(x)   x) >> 4) & 0x3f) << 20)
+
+#define YMAX_MASK  (cpu_is_mx1() ? 0x1ff : 0x3ff)
+#define SIZE_YMAX(y)   ((y) & YMAX_MASK)
+
+#define VPW_VPW(x) ((x) & 0x3ff)
+
+#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 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 RMCR_LCDC_EN_MX1   (1 << 1)
+
+#define RMCR_SELF_REF  (1 << 0)
+
+#define LIER_EOF   (1 << 1)
+
+struct 

[PATCH 5/7] DRM: add i.MX kms simple driver

2012-04-11 Thread Sascha Hauer
This adds a sdrm driver for the Freescale i.MX LCDC controller. It
is found on i.MX1, i.MX21, i.MX25 and i.MX27. Currently only the
base framebuffer is supported, no overlay. This has been tested
on an i.MX27 custom board with the xf86 modesetting driver.

Signed-off-by: Sascha Hauer s.ha...@pengutronix.de
---
 arch/arm/plat-mxc/include/mach/imxfb.h |8 +-
 drivers/gpu/drm/Kconfig|2 +
 drivers/gpu/drm/Makefile   |1 +
 drivers/gpu/drm/imx/Kconfig|8 +
 drivers/gpu/drm/imx/Makefile   |1 +
 drivers/gpu/drm/imx/imx-lcdc-crtc.c|  506 
 6 files changed, 525 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/imx/Kconfig
 create mode 100644 drivers/gpu/drm/imx/Makefile
 create mode 100644 drivers/gpu/drm/imx/imx-lcdc-crtc.c

diff --git a/arch/arm/plat-mxc/include/mach/imxfb.h 
b/arch/arm/plat-mxc/include/mach/imxfb.h
index 9de8f06..5d4aa61 100644
--- a/arch/arm/plat-mxc/include/mach/imxfb.h
+++ b/arch/arm/plat-mxc/include/mach/imxfb.h
@@ -80,5 +80,11 @@ struct imx_fb_platform_data {
void (*backlight_power)(int);
 };
 
-void set_imx_fb_info(struct imx_fb_platform_data *);
+/* drm platform data */
+struct imx_drm_platform_data {
+   u32 lscr1;
+   u32 pcr;
+   u32 pwmr;
+};
+
 #endif /* ifndef __MACH_IMXFB_H__ */
diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
index 93d9f79..4650d65 100644
--- a/drivers/gpu/drm/Kconfig
+++ b/drivers/gpu/drm/Kconfig
@@ -188,3 +188,5 @@ source drivers/gpu/drm/gma500/Kconfig
 source drivers/gpu/drm/udl/Kconfig
 
 source drivers/gpu/drm/sdrm/Kconfig
+
+source drivers/gpu/drm/imx/Kconfig
diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index 44c5949..b0c283e 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -43,4 +43,5 @@ obj-$(CONFIG_DRM_EXYNOS) +=exynos/
 obj-$(CONFIG_DRM_GMA500) += gma500/
 obj-$(CONFIG_DRM_UDL) += udl/
 obj-$(CONFIG_DRM_SDRM) += sdrm/
+obj-$(CONFIG_DRM_IMX) +=imx/
 obj-y  += i2c/
diff --git a/drivers/gpu/drm/imx/Kconfig b/drivers/gpu/drm/imx/Kconfig
new file mode 100644
index 000..d5ad7ed
--- /dev/null
+++ b/drivers/gpu/drm/imx/Kconfig
@@ -0,0 +1,8 @@
+config DRM_IMX_LCDC
+   tristate DRM Support for Freescale i.MX1 and i.MX2
+   depends on DRM  ARCH_MXC
+   select DRM_SDRM
+   select DRM_SDRM_ENCON
+   help
+ Choose this if you have a i.MX1, i.MX21, i.MX25 or i.MX27 processor.
+
diff --git a/drivers/gpu/drm/imx/Makefile b/drivers/gpu/drm/imx/Makefile
new file mode 100644
index 000..cc84f65
--- /dev/null
+++ b/drivers/gpu/drm/imx/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_DRM_IMX_LCDC) += imx-lcdc-crtc.o
diff --git a/drivers/gpu/drm/imx/imx-lcdc-crtc.c 
b/drivers/gpu/drm/imx/imx-lcdc-crtc.c
new file mode 100644
index 000..620b04b
--- /dev/null
+++ b/drivers/gpu/drm/imx/imx-lcdc-crtc.c
@@ -0,0 +1,506 @@
+/*
+ * i.MX crtc driver
+ *
+ * Copyright (C) 2012 Sascha Hauer, Pengutronix
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+#include linux/device.h
+#include linux/platform_device.h
+#include drm/drmP.h
+#include drm/drm_fb_helper.h
+#include drm/drm_crtc_helper.h
+#include linux/fb.h
+#include linux/clk.h
+#include asm/fb.h
+#include linux/module.h
+#include drm/sdrm.h
+#include drm/sdrm_encon.h
+#include mach/hardware.h
+#include mach/imxfb.h
+#include generated/mach-types.h
+
+#define LCDC_SSA   0x00
+#define LCDC_SIZE  0x04
+#define LCDC_VPW   0x08
+#define LCDC_CPOS  0x0C
+#define LCDC_LCWHB 0x10
+#define LCDC_LCHCC 0x14
+#define LCDC_PCR   0x18
+#define LCDC_HCR   0x1C
+#define LCDC_VCR   0x20
+#define LCDC_POS   0x24
+#define LCDC_LSCR1 0x28
+#define LCDC_PWMR  0x2C
+#define LCDC_DMACR 0x30
+#define LCDC_RMCR  0x34
+#define LCDC_LCDICR0x38
+#define LCDC_LIER  0x3c
+#define LCDC_LISR  0x40
+
+#define SIZE_XMAX(x)   x)  4)  0x3f)  20)
+
+#define YMAX_MASK  (cpu_is_mx1() ? 0x1ff : 0x3ff)
+#define SIZE_YMAX(y)   ((y)  YMAX_MASK)
+
+#define VPW_VPW(x) ((x)  0x3ff)
+
+#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 VCR_V_WIDTH(x) (((x)  0x3f)  26)
+#define VCR_V_WAIT_1(x)(((x)