temp revert rk change
[firefly-linux-kernel-4.4.55.git] / drivers / video / tegra / dc / dc_priv.h
1 /*
2  * drivers/video/tegra/dc/dc_priv.h
3  *
4  * Copyright (C) 2010 Google, Inc.
5  * Author: Erik Gilling <konkers@android.com>
6  *
7  * This software is licensed under the terms of the GNU General Public
8  * License version 2, as published by the Free Software Foundation, and
9  * may be copied, distributed, and modified under those terms.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  */
17
18 #ifndef __DRIVERS_VIDEO_TEGRA_DC_DC_PRIV_H
19 #define __DRIVERS_VIDEO_TEGRA_DC_DC_PRIV_H
20
21 #include <linux/io.h>
22 #include <linux/list.h>
23 #include <linux/mutex.h>
24 #include <linux/wait.h>
25 #include "../host/dev.h"
26
27 struct tegra_dc;
28
29 struct tegra_dc_blend {
30         unsigned z[DC_N_WINDOWS];
31         unsigned flags[DC_N_WINDOWS];
32 };
33
34 struct tegra_dc_out_ops {
35         /* initialize output.  dc clocks are not on at this point */
36         int (*init)(struct tegra_dc *dc);
37         /* destroy output.  dc clocks are not on at this point */
38         void (*destroy)(struct tegra_dc *dc);
39         /* detect connected display.  can sleep.*/
40         bool (*detect)(struct tegra_dc *dc);
41         /* enable output.  dc clocks are on at this point */
42         void (*enable)(struct tegra_dc *dc);
43         /* disable output.  dc clocks are on at this point */
44         void (*disable)(struct tegra_dc *dc);
45
46         /* suspend output.  dc clocks are on at this point */
47         void (*suspend)(struct tegra_dc *dc);
48         /* resume output.  dc clocks are on at this point */
49         void (*resume)(struct tegra_dc *dc);
50 };
51
52 struct tegra_dc {
53         struct list_head                list;
54
55         struct nvhost_device            *ndev;
56         struct tegra_dc_platform_data   *pdata;
57
58         struct resource                 *base_res;
59         void __iomem                    *base;
60         int                             irq;
61
62         struct clk                      *clk;
63         struct clk                      *emc_clk;
64
65         bool                            enabled;
66         bool                            suspended;
67
68         struct tegra_dc_out             *out;
69         struct tegra_dc_out_ops         *out_ops;
70         void                            *out_data;
71
72         struct tegra_dc_mode            mode;
73
74         struct tegra_dc_win             windows[DC_N_WINDOWS];
75         struct tegra_dc_blend           blend;
76         int                             n_windows;
77
78         wait_queue_head_t               wq;
79
80         struct mutex                    lock;
81
82         struct resource                 *fb_mem;
83         struct tegra_fb_info            *fb;
84
85         u32                             syncpt_id;
86         u32                             syncpt_min;
87         u32                             syncpt_max;
88
89         unsigned long                   underflow_mask;
90         struct work_struct              reset_work;
91 };
92
93 static inline void tegra_dc_io_start(struct tegra_dc *dc)
94 {
95         nvhost_module_busy(&dc->ndev->host->mod);
96 }
97
98 static inline void tegra_dc_io_end(struct tegra_dc *dc)
99 {
100         nvhost_module_idle(&dc->ndev->host->mod);
101 }
102
103 static inline unsigned long tegra_dc_readl(struct tegra_dc *dc,
104                                            unsigned long reg)
105 {
106         BUG_ON(!nvhost_module_powered(&dc->ndev->host->mod));
107         return readl(dc->base + reg * 4);
108 }
109
110 static inline void tegra_dc_writel(struct tegra_dc *dc, unsigned long val,
111                                    unsigned long reg)
112 {
113         BUG_ON(!nvhost_module_powered(&dc->ndev->host->mod));
114         writel(val, dc->base + reg * 4);
115 }
116
117 static inline void _tegra_dc_write_table(struct tegra_dc *dc, const u32 *table,
118                                          unsigned len)
119 {
120         int i;
121
122         for (i = 0; i < len; i++)
123                 tegra_dc_writel(dc, table[i * 2 + 1], table[i * 2]);
124 }
125
126 #define tegra_dc_write_table(dc, table)         \
127         _tegra_dc_write_table(dc, table, ARRAY_SIZE(table) / 2)
128
129 static inline void tegra_dc_set_outdata(struct tegra_dc *dc, void *data)
130 {
131         dc->out_data = data;
132 }
133
134 static inline void *tegra_dc_get_outdata(struct tegra_dc *dc)
135 {
136         return dc->out_data;
137 }
138
139 void tegra_dc_setup_clk(struct tegra_dc *dc, struct clk *clk);
140
141 extern struct tegra_dc_out_ops tegra_dc_rgb_ops;
142 extern struct tegra_dc_out_ops tegra_dc_hdmi_ops;
143
144 #endif