/*
* arch/arch/mach-tegra/mipi-cal.c
*
- * Copyright (C) 2013 NVIDIA Corporation.
+ * Copyright (C) 2013 NVIDIA Corporation. All rights reserved.
*
* Author:
* Charlie Huang <chahuang@nvidia.com>
*
- * 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 free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
*
- * 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.
+ * This program is distributed in the hope 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.
*
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <linux/init.h>
#include <linux/fs.h>
#include <linux/mm.h>
-#include <linux/platform_device.h>
#include <linux/miscdevice.h>
-#include <linux/export.h>
#include <linux/module.h>
-#include <linux/io.h>
+#include <linux/clk.h>
#include "iomap.h"
-#define CLK_OUT_ENB_H 0x014
-
-#define clk_writel(value, reg) __raw_writel(value, clk_base + (reg))
-#define clk_readl(reg) __raw_readl(clk_base + (reg))
+struct mipi_cal_info {
+ struct clk *clk;
+ struct clk *clk72mhz;
+};
-static void __iomem *clk_base = IO_ADDRESS(TEGRA_CLK_RESET_BASE);
+static struct mipi_cal_info pm;
static atomic_t mipi_cal_in_use;
-static u32 saved_bit;
static int mipi_cal_open(struct inode *inode, struct file *filp);
static int mipi_cal_release(struct inode *inode, struct file *filp);
static int mipi_cal_open(struct inode *inode, struct file *filp)
{
- u32 val;
-
- /* only one client can work on the mipi-cal registers at one time. */
if (atomic_xchg(&mipi_cal_in_use, 1))
return -EBUSY;
- /* Save enable bit to MIPI CAL Logic */
- val = clk_readl(CLK_OUT_ENB_H);
- saved_bit = val & 0x1000000;
- /* Enable clock to MIPI CAL Logic */
- val |= 0x1000000;
- clk_writel(val, CLK_OUT_ENB_H);
+ if (pm.clk72mhz)
+ clk_prepare_enable(pm.clk72mhz);
+ if (pm.clk)
+ clk_prepare_enable(pm.clk);
+
return nonseekable_open(inode, filp);
}
static int mipi_cal_release(struct inode *inode, struct file *filp)
{
- u32 val;
+ if (pm.clk)
+ clk_disable_unprepare(pm.clk);
+ if (pm.clk72mhz)
+ clk_disable_unprepare(pm.clk72mhz);
- val = clk_readl(CLK_OUT_ENB_H);
- val &= ~0x1000000;
- /* Restore enable bit to MIPI CAL Logic */
- val |= saved_bit;
- clk_writel(val, CLK_OUT_ENB_H);
WARN_ON(!atomic_xchg(&mipi_cal_in_use, 0));
return 0;
}
static int __init mipi_cal_dev_init(void)
{
+ pm.clk = clk_get_sys("mipi-cal", NULL);
+ if (IS_ERR_OR_NULL(pm.clk)) {
+ pr_warn("%s: cannot get mipi-cal clk.\n", __func__);
+ pm.clk = NULL;
+ }
+
+ pm.clk72mhz = clk_get_sys("clk72mhz", NULL);
+ if (IS_ERR_OR_NULL(pm.clk72mhz)) {
+ pr_warn("%s: cannot get mipi-cal clk.\n", __func__);
+ pm.clk72mhz = NULL;
+ }
+
return misc_register(&mipi_cal_dev);
}
module_init(mipi_cal_dev_init);
-MODULE_LICENSE("GPL");
+MODULE_LICENSE("GPL v2");