video: tegra: dsi: Enable MIPI auto calibration
[linux-3.10.git] / drivers / video / tegra / dc / mipi_cal.h
1 /*
2  * drivers/video/tegra/dc/mipi_cal.h
3  *
4  * Copyright (c) 2012-2013, NVIDIA CORPORATION, All rights reserved.
5  *
6  * This software is licensed under the terms of the GNU General Public
7  * License version 2, as published by the Free Software Foundation, and
8  * may be copied, distributed, and modified under those terms.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  */
16
17 #ifndef __DRIVERS_VIDEO_TEGRA_DC_MIPI_CAL_H__
18 #define __DRIVERS_VIDEO_TEGRA_DC_MIPI_CAL_H__
19
20 #include "mipi_cal_regs.h"
21
22 struct tegra_mipi_cal {
23         struct tegra_dc *dc;
24         struct resource *res;
25         struct clk *clk;
26         struct clk *fixed_clk;
27         void __iomem *base;
28         struct mutex lock;
29 };
30
31 #ifdef CONFIG_TEGRA_MIPI_CAL
32 static inline void tegra_mipi_cal_clk_enable(struct tegra_mipi_cal *mipi_cal)
33 {
34         BUG_ON(IS_ERR_OR_NULL(mipi_cal));
35         clk_prepare_enable(mipi_cal->fixed_clk);
36         clk_prepare_enable(mipi_cal->clk);
37 }
38
39 static inline void tegra_mipi_cal_clk_disable(struct tegra_mipi_cal *mipi_cal)
40 {
41         BUG_ON(IS_ERR_OR_NULL(mipi_cal));
42         clk_disable_unprepare(mipi_cal->clk);
43         clk_disable_unprepare(mipi_cal->fixed_clk);
44 }
45
46 /* reg is word offset */
47 static inline unsigned long tegra_mipi_cal_read(
48                                         struct tegra_mipi_cal *mipi_cal,
49                                         unsigned long reg)
50 {
51         BUG_ON(IS_ERR_OR_NULL(mipi_cal) ||
52                 !tegra_is_clk_enabled(mipi_cal->clk));
53         return readl(mipi_cal->base + reg);
54 }
55
56 /* reg is word offset */
57 static inline void tegra_mipi_cal_write(struct tegra_mipi_cal *mipi_cal,
58                                                         unsigned long val,
59                                                         unsigned long reg)
60 {
61         BUG_ON(IS_ERR_OR_NULL(mipi_cal) ||
62                 !tegra_is_clk_enabled(mipi_cal->clk));
63         writel(val, mipi_cal->base + reg);
64 }
65
66 extern struct tegra_mipi_cal *tegra_mipi_cal_init_sw(struct tegra_dc *dc);
67 extern int tegra_mipi_cal_init_hw(struct tegra_mipi_cal *mipi_cal);
68 extern void tegra_mipi_cal_destroy(struct tegra_dc *dc);
69 #else
70 static inline void tegra_mipi_cal_clk_enable(struct tegra_mipi_cal *mipi_cal)
71 {
72         /* dummy */
73 }
74
75 static inline void tegra_mipi_cal_clk_disable(struct tegra_mipi_cal *mipi_cal)
76 {
77         /* dummy */
78 }
79
80 static inline unsigned long tegra_mipi_cal_read(
81                                                 struct tegra_mipi_cal *mipi_cal,
82                                                 unsigned long reg)
83 {
84         /* dummy */
85         return 0;
86 }
87
88 static inline void tegra_mipi_cal_write(struct tegra_mipi_cal *mipi_cal,
89                                                 unsigned long val,
90                                                 unsigned long reg)
91 {
92         /* dummy */
93 }
94
95 struct tegra_mipi_cal *tegra_mipi_cal_init_sw(struct tegra_dc *dc)
96 {
97         /* dummy */
98         return NULL;
99 }
100
101 int tegra_mipi_cal_init_hw(struct tegra_mipi_cal *mipi_cal)
102 {
103         /* dummy */
104         return 0;
105 }
106
107 void tegra_mipi_cal_destroy(struct tegra_dc *dc)
108 {
109         /* dummy */
110 }
111 #endif
112 #endif