video: tegra: mipi_cal: Implement driver for mipi calibration
Animesh Kishore [Tue, 9 Oct 2012 04:44:37 +0000 (21:44 -0700)]
All mipi calibration has been moved to this block
from t11x onwards.

Bug 1054040

Change-Id: I6918fb229215208d63d4200073aeb42a2f2f37d3
Signed-off-by: Animesh Kishore <ankishore@nvidia.com>
Reviewed-on: http://git-master/r/142564
(cherry picked from commit 5cd4821c5bd138811a848518e129ce239c4fc1cd)
Signed-off-by: Gaurav Batra <gbatra@nvidia.com>
Reviewed-on: http://git-master/r/146696
Reviewed-by: Simone Willett <swillett@nvidia.com>
Tested-by: Simone Willett <swillett@nvidia.com>

drivers/video/tegra/Kconfig
drivers/video/tegra/dc/Makefile
drivers/video/tegra/dc/mipi_cal.c [new file with mode: 0644]
drivers/video/tegra/dc/mipi_cal.h [new file with mode: 0644]
drivers/video/tegra/dc/mipi_cal_regs.h [new file with mode: 0644]

index 02dc459..ab99135 100644 (file)
@@ -41,6 +41,11 @@ config TEGRA_DC_CMU
     default n if ARCH_TEGRA_2x_SOC || ARCH_TEGRA_3x_SOC
     default y
 
+config TEGRA_MIPI_CAL
+    bool
+    default n if ARCH_TEGRA_2x_SOC || ARCH_TEGRA_3x_SOC
+    default y
+
 config TEGRA_DC_SCAN_COLUMN
     bool
     default y if ARCH_TEGRA_11x_SOC
index 965db83..0aa3119 100644 (file)
@@ -5,6 +5,7 @@ obj-y += rgb.o
 obj-y += hdmi.o
 obj-y += dsi2lvds.o
 obj-y += tc358770_dsi2edp.o
+obj-$(CONFIG_TEGRA_MIPI_CAL) += mipi_cal.o
 obj-$(CONFIG_TEGRA_NVHDCP) += nvhdcp.o
 obj-y += edid.o
 obj-y += nvsd.o
diff --git a/drivers/video/tegra/dc/mipi_cal.c b/drivers/video/tegra/dc/mipi_cal.c
new file mode 100644 (file)
index 0000000..f53154c
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ * drivers/video/tegra/dc/mipi_cal.c
+ *
+ * Copyright (c) 2012, NVIDIA CORPORATION, All rights reserved.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * 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/ioport.h>
+#include <linux/gfp.h>
+#include "dc_priv.h"
+#include "mipi_cal.h"
+#include "mipi_cal_regs.h"
+
+/* must be called with clocks enabled */
+void tegra_mipi_cal_init_hw(struct tegra_mipi_cal *mipi_cal)
+{
+       unsigned cnt = MIPI_CAL_MIPI_CAL_CTRL_0;
+
+       mutex_lock(&mipi_cal->lock);
+
+       for (; cnt <= MIPI_CAL_MIPI_BIAS_PAD_CFG2_0; cnt += 4)
+               tegra_mipi_cal_write(mipi_cal, 0, cnt);
+
+       mutex_unlock(&mipi_cal->lock);
+}
+EXPORT_SYMBOL(tegra_mipi_cal_init_hw);
+
+struct tegra_mipi_cal *tegra_mipi_cal_init_sw(struct tegra_dc *dc)
+{
+       struct tegra_mipi_cal *mipi_cal;
+       struct resource *res;
+       struct clk *clk;
+       void __iomem *base;
+       int err = 0;
+
+       mipi_cal = devm_kzalloc(&dc->ndev->dev, sizeof(*mipi_cal), GFP_KERNEL);
+       if (!mipi_cal) {
+               dev_err(&dc->ndev->dev, "mipi_cal: memory allocation fail\n");
+               err = -ENOMEM;
+               goto fail;
+       }
+
+       res = nvhost_get_resource_byname(dc->ndev, IORESOURCE_MEM, "mipi_cal");
+       if (!res) {
+               dev_err(&dc->ndev->dev, "mipi_cal: no entry in resource\n");
+               err = -ENOENT;
+               goto fail_free_mipi_cal;
+       }
+
+       base = devm_request_and_ioremap(&dc->ndev->dev, res);
+       if (!base) {
+               dev_err(&dc->ndev->dev, "mipi_cal: bus to virtual mapping failed\n");
+               err = -EBUSY;
+               goto fail_free_res;
+       }
+
+       clk = clk_get_sys("mipi-cal", NULL);
+       if (IS_ERR_OR_NULL(clk)) {
+               dev_err(&dc->ndev->dev, "mipi_cal: clk get failed\n");
+               err = PTR_ERR(clk);
+               goto fail_free_map;
+       }
+
+       mutex_init(&mipi_cal->lock);
+       mipi_cal->dc = dc;
+       mipi_cal->res = res;
+       mipi_cal->base = base;
+       mipi_cal->clk = clk;
+       mipi_cal->power_on = false;
+
+       return mipi_cal;
+
+fail_free_map:
+       devm_iounmap(&dc->ndev->dev, base);
+       devm_release_mem_region(&dc->ndev->dev, res->start, resource_size(res));
+fail_free_res:
+       release_resource(res);
+fail_free_mipi_cal:
+       devm_kfree(&dc->ndev->dev, mipi_cal);
+fail:
+       return ERR_PTR(err);
+}
+EXPORT_SYMBOL(tegra_mipi_cal_init_sw);
+
diff --git a/drivers/video/tegra/dc/mipi_cal.h b/drivers/video/tegra/dc/mipi_cal.h
new file mode 100644 (file)
index 0000000..6253999
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ * drivers/video/tegra/dc/mipi_cal.h
+ *
+ * Copyright (c) 2012, NVIDIA CORPORATION, All rights reserved.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * 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.
+ *
+ */
+
+#ifndef __DRIVERS_VIDEO_TEGRA_DC_MIPI_CAL_H__
+#define __DRIVERS_VIDEO_TEGRA_DC_MIPI_CAL_H__
+
+struct tegra_mipi_cal {
+       struct tegra_dc *dc;
+       struct resource *res;
+       struct clk *clk;
+       void __iomem *base;
+       struct mutex lock;
+       bool power_on;
+};
+
+#ifdef CONFIG_TEGRA_MIPI_CAL
+static inline void tegra_mipi_cal_clk_enable(struct tegra_mipi_cal  *mipi_cal)
+{
+       if (!mipi_cal->power_on) {
+               clk_enable(mipi_cal->clk);
+               mipi_cal->power_on = true;
+       }
+}
+
+static inline void tegra_mipi_cal_clk_disable(struct tegra_mipi_cal  *mipi_cal)
+{
+       if (mipi_cal->power_on) {
+               clk_disable(mipi_cal->clk);
+               mipi_cal->power_on = false;
+       }
+}
+
+/* reg is word offset */
+static inline unsigned long tegra_mipi_cal_read(
+                                       struct tegra_mipi_cal *mipi_cal,
+                                       unsigned long reg)
+{
+       return readl(mipi_cal->base + reg);
+}
+
+/* reg is word offset */
+static inline void tegra_mipi_cal_write(struct tegra_mipi_cal *mipi_cal,
+                                                       unsigned long val,
+                                                       unsigned long reg)
+{
+       writel(val,  mipi_cal->base + reg);
+}
+
+extern struct tegra_mipi_cal *tegra_mipi_cal_init_sw(struct tegra_dc *dc);
+extern void tegra_mipi_cal_init_hw(struct tegra_mipi_cal *mipi_cal);
+#else
+static inline void tegra_mipi_cal_clk_enable(struct tegra_mipi_cal  *mipi_cal)
+{
+       /* dummy */
+}
+
+static inline void tegra_mipi_cal_clk_disable(struct tegra_mipi_cal  *mipi_cal)
+{
+       /* dummy */
+}
+
+static inline unsigned long tegra_mipi_cal_read(
+                                               struct tegra_mipi_cal *mipi_cal,
+                                               unsigned long reg)
+{
+       /* dummy */
+       return 0;
+}
+
+static inline void tegra_mipi_cal_write(struct tegra_mipi_cal *mipi_cal,
+                                               unsigned long val,
+                                               unsigned long reg)
+{
+       /* dummy */
+}
+
+struct tegra_mipi_cal *tegra_mipi_cal_init(struct tegra_dc *dc)
+{
+       /* dummy */
+       return NULL;
+}
+
+void tegra_mipi_cal_init_hw(struct tegra_mipi_cal *mipi_cal)
+{
+       /* dummy */
+}
+#endif
+#endif
diff --git a/drivers/video/tegra/dc/mipi_cal_regs.h b/drivers/video/tegra/dc/mipi_cal_regs.h
new file mode 100644 (file)
index 0000000..2c19953
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * drivers/video/tegra/dc/mipi_cal_regs.h
+ *
+ * Copyright (c) 2012, NVIDIA CORPORATION, All rights reserved.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * 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.
+ *
+ */
+
+#ifndef __DRIVERS_VIDEO_TEGRA_DC_MIPI_CAL_REG_H__
+#define __DRIVERS_VIDEO_TEGRA_DC_MIPI_CAL_REG_H__
+
+#define MIPI_CAL_MIPI_CAL_CTRL_0       0x0
+#define MIPI_CAL_NOISE_FLT(x)          (((x) & 0xf) << 26)
+#define MIPI_CAL_PRESCALE(x)           (((x) & 0x3) << 24)
+#define MIPI_CAL_CLKEN_OVR(x)          (((x) & 0x1) << 4)
+#define MIPI_CAL_AUTOCAL_EN(x)         (((x) & 0x1) << 1)
+#define MIPI_CAL_STARTCAL(x)           (((x) & 0x1) << 0)
+
+#define MIPI_CAL_MIPI_BIAS_PAD_CFG0_0  0x58
+#define MIPI_BIAS_PAD_PDVCLAMP(x)      (((x) & 0x1) << 1)
+#define MIPI_BIAS_PAD_E_VCLAMP_REF(x)  (((x) & 0x1) << 0)
+
+#define MIPI_CAL_MIPI_BIAS_PAD_CFG1_0  0x5c
+#define PAD_TEST_SEL(x)                        (((x) & 0x7) << 24)
+#define PAD_DRIV_DN_REF(x)             (((x) & 0x7) << 16)
+#define PAD_DRIV_UP_REF(x)             (((x) & 0x7) << 8)
+#define PAD_TERM_REF(x)                        (((x) & 0x7) << 0)
+
+#define MIPI_CAL_MIPI_BIAS_PAD_CFG2_0  0x60
+#define PAD_VCLAMP_LEVEL(x)            (((x) & 0x7) << 16)
+#define PAD_SPARE(x)                   (((x) & 0xff) << 8)
+#define PAD_VAUXP_LEVEL(x)             (((x) & 0x7) << 4)
+#define PAD_PDVREG(x)                  (((x) & 0x1) << 1)
+#define PAD_VBYPASS(x)                 (((x) & 0x1) << 0)
+
+#endif