drm: omapdrm: dss: Pass DSS pointer to dss_ops operations
[linux-2.6-microblaze.git] / drivers / gpu / drm / omapdrm / dss / dss.h
1 /*
2  * Copyright (C) 2009 Nokia Corporation
3  * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
4  *
5  * Some code and ideas taken from drivers/video/omap/ driver
6  * by Imre Deak.
7  *
8  * This program is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU General Public License version 2 as published by
10  * the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15  * more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program.  If not, see <http://www.gnu.org/licenses/>.
19  */
20
21 #ifndef __OMAP2_DSS_H
22 #define __OMAP2_DSS_H
23
24 #include <linux/interrupt.h>
25
26 #include "omapdss.h"
27
28 #define MAX_DSS_LCD_MANAGERS    3
29 #define MAX_NUM_DSI             2
30
31 #ifdef pr_fmt
32 #undef pr_fmt
33 #endif
34
35 #ifdef DSS_SUBSYS_NAME
36 #define pr_fmt(fmt) DSS_SUBSYS_NAME ": " fmt
37 #else
38 #define pr_fmt(fmt) fmt
39 #endif
40
41 #define DSSDBG(format, ...) \
42         pr_debug(format, ## __VA_ARGS__)
43
44 #ifdef DSS_SUBSYS_NAME
45 #define DSSERR(format, ...) \
46         pr_err("omapdss " DSS_SUBSYS_NAME " error: " format, ##__VA_ARGS__)
47 #else
48 #define DSSERR(format, ...) \
49         pr_err("omapdss error: " format, ##__VA_ARGS__)
50 #endif
51
52 #ifdef DSS_SUBSYS_NAME
53 #define DSSINFO(format, ...) \
54         pr_info("omapdss " DSS_SUBSYS_NAME ": " format, ##__VA_ARGS__)
55 #else
56 #define DSSINFO(format, ...) \
57         pr_info("omapdss: " format, ## __VA_ARGS__)
58 #endif
59
60 #ifdef DSS_SUBSYS_NAME
61 #define DSSWARN(format, ...) \
62         pr_warn("omapdss " DSS_SUBSYS_NAME ": " format, ##__VA_ARGS__)
63 #else
64 #define DSSWARN(format, ...) \
65         pr_warn("omapdss: " format, ##__VA_ARGS__)
66 #endif
67
68 /* OMAP TRM gives bitfields as start:end, where start is the higher bit
69    number. For example 7:0 */
70 #define FLD_MASK(start, end)    (((1 << ((start) - (end) + 1)) - 1) << (end))
71 #define FLD_VAL(val, start, end) (((val) << (end)) & FLD_MASK(start, end))
72 #define FLD_GET(val, start, end) (((val) & FLD_MASK(start, end)) >> (end))
73 #define FLD_MOD(orig, val, start, end) \
74         (((orig) & ~FLD_MASK(start, end)) | FLD_VAL(val, start, end))
75
76 enum dss_model {
77         DSS_MODEL_OMAP2,
78         DSS_MODEL_OMAP3,
79         DSS_MODEL_OMAP4,
80         DSS_MODEL_OMAP5,
81         DSS_MODEL_DRA7,
82 };
83
84 enum dss_io_pad_mode {
85         DSS_IO_PAD_MODE_RESET,
86         DSS_IO_PAD_MODE_RFBI,
87         DSS_IO_PAD_MODE_BYPASS,
88 };
89
90 enum dss_hdmi_venc_clk_source_select {
91         DSS_VENC_TV_CLK = 0,
92         DSS_HDMI_M_PCLK = 1,
93 };
94
95 enum dss_dsi_content_type {
96         DSS_DSI_CONTENT_DCS,
97         DSS_DSI_CONTENT_GENERIC,
98 };
99
100 enum dss_writeback_channel {
101         DSS_WB_LCD1_MGR =       0,
102         DSS_WB_LCD2_MGR =       1,
103         DSS_WB_TV_MGR =         2,
104         DSS_WB_OVL0 =           3,
105         DSS_WB_OVL1 =           4,
106         DSS_WB_OVL2 =           5,
107         DSS_WB_OVL3 =           6,
108         DSS_WB_LCD3_MGR =       7,
109 };
110
111 enum dss_clk_source {
112         DSS_CLK_SRC_FCK = 0,
113
114         DSS_CLK_SRC_PLL1_1,
115         DSS_CLK_SRC_PLL1_2,
116         DSS_CLK_SRC_PLL1_3,
117
118         DSS_CLK_SRC_PLL2_1,
119         DSS_CLK_SRC_PLL2_2,
120         DSS_CLK_SRC_PLL2_3,
121
122         DSS_CLK_SRC_HDMI_PLL,
123 };
124
125 enum dss_pll_id {
126         DSS_PLL_DSI1,
127         DSS_PLL_DSI2,
128         DSS_PLL_HDMI,
129         DSS_PLL_VIDEO1,
130         DSS_PLL_VIDEO2,
131 };
132
133 struct dss_pll;
134
135 #define DSS_PLL_MAX_HSDIVS 4
136
137 enum dss_pll_type {
138         DSS_PLL_TYPE_A,
139         DSS_PLL_TYPE_B,
140 };
141
142 /*
143  * Type-A PLLs: clkout[]/mX[] refer to hsdiv outputs m4, m5, m6, m7.
144  * Type-B PLLs: clkout[0] refers to m2.
145  */
146 struct dss_pll_clock_info {
147         /* rates that we get with dividers below */
148         unsigned long fint;
149         unsigned long clkdco;
150         unsigned long clkout[DSS_PLL_MAX_HSDIVS];
151
152         /* dividers */
153         u16 n;
154         u16 m;
155         u32 mf;
156         u16 mX[DSS_PLL_MAX_HSDIVS];
157         u16 sd;
158 };
159
160 struct dss_pll_ops {
161         int (*enable)(struct dss_pll *pll);
162         void (*disable)(struct dss_pll *pll);
163         int (*set_config)(struct dss_pll *pll,
164                 const struct dss_pll_clock_info *cinfo);
165 };
166
167 struct dss_pll_hw {
168         enum dss_pll_type type;
169
170         unsigned int n_max;
171         unsigned int m_min;
172         unsigned int m_max;
173         unsigned int mX_max;
174
175         unsigned long fint_min, fint_max;
176         unsigned long clkdco_min, clkdco_low, clkdco_max;
177
178         u8 n_msb, n_lsb;
179         u8 m_msb, m_lsb;
180         u8 mX_msb[DSS_PLL_MAX_HSDIVS], mX_lsb[DSS_PLL_MAX_HSDIVS];
181
182         bool has_stopmode;
183         bool has_freqsel;
184         bool has_selfreqdco;
185         bool has_refsel;
186
187         /* DRA7 errata i886: use high N & M to avoid jitter */
188         bool errata_i886;
189 };
190
191 struct dss_pll {
192         const char *name;
193         enum dss_pll_id id;
194         struct dss_device *dss;
195
196         struct clk *clkin;
197         struct regulator *regulator;
198
199         void __iomem *base;
200
201         const struct dss_pll_hw *hw;
202
203         const struct dss_pll_ops *ops;
204
205         struct dss_pll_clock_info cinfo;
206 };
207
208 /* Defines a generic omap register field */
209 struct dss_reg_field {
210         u8 start, end;
211 };
212
213 struct dispc_clock_info {
214         /* rates that we get with dividers below */
215         unsigned long lck;
216         unsigned long pck;
217
218         /* dividers */
219         u16 lck_div;
220         u16 pck_div;
221 };
222
223 struct dss_lcd_mgr_config {
224         enum dss_io_pad_mode io_pad_mode;
225
226         bool stallmode;
227         bool fifohandcheck;
228
229         struct dispc_clock_info clock_info;
230
231         int video_port_width;
232
233         int lcden_sig_polarity;
234 };
235
236 struct seq_file;
237 struct platform_device;
238
239 #define DSS_SZ_REGS                     SZ_512
240
241 struct dss_device {
242         struct platform_device *pdev;
243         void __iomem    *base;
244         struct regmap   *syscon_pll_ctrl;
245         u32             syscon_pll_ctrl_offset;
246
247         struct clk      *parent_clk;
248         struct clk      *dss_clk;
249         unsigned long   dss_clk_rate;
250
251         unsigned long   cache_req_pck;
252         unsigned long   cache_prate;
253         struct dispc_clock_info cache_dispc_cinfo;
254
255         enum dss_clk_source dsi_clk_source[MAX_NUM_DSI];
256         enum dss_clk_source dispc_clk_source;
257         enum dss_clk_source lcd_clk_source[MAX_DSS_LCD_MANAGERS];
258
259         bool            ctx_valid;
260         u32             ctx[DSS_SZ_REGS / sizeof(u32)];
261
262         const struct dss_features *feat;
263
264         struct dss_pll  *video1_pll;
265         struct dss_pll  *video2_pll;
266 };
267
268 /* core */
269 static inline int dss_set_min_bus_tput(struct device *dev, unsigned long tput)
270 {
271         /* To be implemented when the OMAP platform will provide this feature */
272         return 0;
273 }
274
275 static inline bool dss_mgr_is_lcd(enum omap_channel id)
276 {
277         if (id == OMAP_DSS_CHANNEL_LCD || id == OMAP_DSS_CHANNEL_LCD2 ||
278                         id == OMAP_DSS_CHANNEL_LCD3)
279                 return true;
280         else
281                 return false;
282 }
283
284 /* DSS */
285 #if defined(CONFIG_OMAP2_DSS_DEBUGFS)
286 int dss_debugfs_create_file(const char *name, void (*write)(struct seq_file *));
287 #else
288 static inline int dss_debugfs_create_file(const char *name,
289                                           void (*write)(struct seq_file *))
290 {
291         return 0;
292 }
293 #endif /* CONFIG_OMAP2_DSS_DEBUGFS */
294
295 struct dss_device *dss_get_device(struct device *dev);
296
297 int dss_runtime_get(struct dss_device *dss);
298 void dss_runtime_put(struct dss_device *dss);
299
300 unsigned long dss_get_dispc_clk_rate(void);
301 unsigned long dss_get_max_fck_rate(void);
302 enum omap_dss_output_id dss_get_supported_outputs(enum omap_channel channel);
303 int dss_dpi_select_source(struct dss_device *dss, int port,
304                           enum omap_channel channel);
305 void dss_select_hdmi_venc_clk_source(struct dss_device *dss,
306                                      enum dss_hdmi_venc_clk_source_select src);
307 const char *dss_get_clk_source_name(enum dss_clk_source clk_src);
308
309 /* DSS VIDEO PLL */
310 struct dss_pll *dss_video_pll_init(struct dss_device *dss,
311                                    struct platform_device *pdev, int id,
312                                    struct regulator *regulator);
313 void dss_video_pll_uninit(struct dss_pll *pll);
314
315 void dss_ctrl_pll_enable(struct dss_pll *pll, bool enable);
316
317 void dss_sdi_init(struct dss_device *dss, int datapairs);
318 int dss_sdi_enable(struct dss_device *dss);
319 void dss_sdi_disable(struct dss_device *dss);
320
321 void dss_select_dsi_clk_source(struct dss_device *dss, int dsi_module,
322                                enum dss_clk_source clk_src);
323 void dss_select_lcd_clk_source(struct dss_device *dss,
324                                enum omap_channel channel,
325                                enum dss_clk_source clk_src);
326 enum dss_clk_source dss_get_dispc_clk_source(void);
327 enum dss_clk_source dss_get_dsi_clk_source(int dsi_module);
328 enum dss_clk_source dss_get_lcd_clk_source(enum omap_channel channel);
329
330 void dss_set_venc_output(enum omap_dss_venc_type type);
331 void dss_set_dac_pwrdn_bgz(bool enable);
332
333 int dss_set_fck_rate(unsigned long rate);
334
335 typedef bool (*dss_div_calc_func)(unsigned long fck, void *data);
336 bool dss_div_calc(unsigned long pck, unsigned long fck_min,
337                 dss_div_calc_func func, void *data);
338
339 /* SDI */
340 #ifdef CONFIG_OMAP2_DSS_SDI
341 int sdi_init_port(struct dss_device *dss, struct platform_device *pdev,
342                   struct device_node *port);
343 void sdi_uninit_port(struct device_node *port);
344 #else
345 static inline int sdi_init_port(struct dss_device *dss,
346                                 struct platform_device *pdev,
347                                 struct device_node *port)
348 {
349         return 0;
350 }
351 static inline void sdi_uninit_port(struct device_node *port)
352 {
353 }
354 #endif
355
356 /* DSI */
357
358 #ifdef CONFIG_OMAP2_DSS_DSI
359
360 struct dentry;
361 struct file_operations;
362
363 void dsi_dump_clocks(struct seq_file *s);
364
365 void dsi_irq_handler(void);
366
367 #endif
368
369 /* DPI */
370 #ifdef CONFIG_OMAP2_DSS_DPI
371 int dpi_init_port(struct dss_device *dss, struct platform_device *pdev,
372                   struct device_node *port, enum dss_model dss_model);
373 void dpi_uninit_port(struct device_node *port);
374 #else
375 static inline int dpi_init_port(struct dss_device *port,
376                                 struct platform_device *pdev,
377                                 struct device_node *port,
378                                 enum dss_model dss_model)
379 {
380         return 0;
381 }
382 static inline void dpi_uninit_port(struct device_node *port)
383 {
384 }
385 #endif
386
387 /* DISPC */
388 void dispc_dump_clocks(struct seq_file *s);
389
390 int dispc_runtime_get(void);
391 void dispc_runtime_put(void);
392
393 void dispc_enable_sidle(void);
394 void dispc_disable_sidle(void);
395
396 void dispc_lcd_enable_signal(bool enable);
397 void dispc_pck_free_enable(bool enable);
398 void dispc_enable_fifomerge(bool enable);
399
400 typedef bool (*dispc_div_calc_func)(int lckd, int pckd, unsigned long lck,
401                 unsigned long pck, void *data);
402 bool dispc_div_calc(unsigned long dispc,
403                 unsigned long pck_min, unsigned long pck_max,
404                 dispc_div_calc_func func, void *data);
405
406 bool dispc_mgr_timings_ok(enum omap_channel channel, const struct videomode *vm);
407 int dispc_calc_clock_rates(unsigned long dispc_fclk_rate,
408                 struct dispc_clock_info *cinfo);
409
410
411 void dispc_ovl_set_fifo_threshold(enum omap_plane_id plane, u32 low,
412                                   u32 high);
413 void dispc_ovl_compute_fifo_thresholds(enum omap_plane_id plane,
414                 u32 *fifo_low, u32 *fifo_high, bool use_fifomerge,
415                 bool manual_update);
416
417 void dispc_mgr_set_clock_div(enum omap_channel channel,
418                 const struct dispc_clock_info *cinfo);
419 int dispc_mgr_get_clock_div(enum omap_channel channel,
420                 struct dispc_clock_info *cinfo);
421 void dispc_set_tv_pclk(unsigned long pclk);
422
423 u32 dispc_wb_get_framedone_irq(void);
424 bool dispc_wb_go_busy(void);
425 void dispc_wb_go(void);
426 void dispc_wb_set_channel_in(enum dss_writeback_channel channel);
427 int dispc_wb_setup(const struct omap_dss_writeback_info *wi,
428                 bool mem_to_mem, const struct videomode *vm);
429
430 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
431 static inline void dss_collect_irq_stats(u32 irqstatus, unsigned int *irq_arr)
432 {
433         int b;
434         for (b = 0; b < 32; ++b) {
435                 if (irqstatus & (1 << b))
436                         irq_arr[b]++;
437         }
438 }
439 #endif
440
441 /* PLL */
442 typedef bool (*dss_pll_calc_func)(int n, int m, unsigned long fint,
443                 unsigned long clkdco, void *data);
444 typedef bool (*dss_hsdiv_calc_func)(int m_dispc, unsigned long dispc,
445                 void *data);
446
447 int dss_pll_register(struct dss_pll *pll);
448 void dss_pll_unregister(struct dss_pll *pll);
449 struct dss_pll *dss_pll_find(const char *name);
450 struct dss_pll *dss_pll_find_by_src(enum dss_clk_source src);
451 unsigned int dss_pll_get_clkout_idx_for_src(enum dss_clk_source src);
452 int dss_pll_enable(struct dss_pll *pll);
453 void dss_pll_disable(struct dss_pll *pll);
454 int dss_pll_set_config(struct dss_pll *pll,
455                 const struct dss_pll_clock_info *cinfo);
456
457 bool dss_pll_hsdiv_calc_a(const struct dss_pll *pll, unsigned long clkdco,
458                 unsigned long out_min, unsigned long out_max,
459                 dss_hsdiv_calc_func func, void *data);
460 bool dss_pll_calc_a(const struct dss_pll *pll, unsigned long clkin,
461                 unsigned long pll_min, unsigned long pll_max,
462                 dss_pll_calc_func func, void *data);
463
464 bool dss_pll_calc_b(const struct dss_pll *pll, unsigned long clkin,
465         unsigned long target_clkout, struct dss_pll_clock_info *cinfo);
466
467 int dss_pll_write_config_type_a(struct dss_pll *pll,
468                 const struct dss_pll_clock_info *cinfo);
469 int dss_pll_write_config_type_b(struct dss_pll *pll,
470                 const struct dss_pll_clock_info *cinfo);
471 int dss_pll_wait_reset_done(struct dss_pll *pll);
472
473 extern struct platform_driver omap_dsshw_driver;
474 extern struct platform_driver omap_dispchw_driver;
475 #ifdef CONFIG_OMAP2_DSS_DSI
476 extern struct platform_driver omap_dsihw_driver;
477 #endif
478 #ifdef CONFIG_OMAP2_DSS_VENC
479 extern struct platform_driver omap_venchw_driver;
480 #endif
481 #ifdef CONFIG_OMAP4_DSS_HDMI
482 extern struct platform_driver omapdss_hdmi4hw_driver;
483 #endif
484 #ifdef CONFIG_OMAP5_DSS_HDMI
485 extern struct platform_driver omapdss_hdmi5hw_driver;
486 #endif
487
488 #endif