2 * Copyright (C) 2009 Nokia Corporation
3 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
5 * Some code and ideas taken from drivers/video/omap/ driver
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.
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
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/>.
24 #include <linux/interrupt.h>
28 #define MAX_DSS_LCD_MANAGERS 3
35 #ifdef DSS_SUBSYS_NAME
36 #define pr_fmt(fmt) DSS_SUBSYS_NAME ": " fmt
38 #define pr_fmt(fmt) fmt
41 #define DSSDBG(format, ...) \
42 pr_debug(format, ## __VA_ARGS__)
44 #ifdef DSS_SUBSYS_NAME
45 #define DSSERR(format, ...) \
46 pr_err("omapdss " DSS_SUBSYS_NAME " error: " format, ##__VA_ARGS__)
48 #define DSSERR(format, ...) \
49 pr_err("omapdss error: " format, ##__VA_ARGS__)
52 #ifdef DSS_SUBSYS_NAME
53 #define DSSINFO(format, ...) \
54 pr_info("omapdss " DSS_SUBSYS_NAME ": " format, ##__VA_ARGS__)
56 #define DSSINFO(format, ...) \
57 pr_info("omapdss: " format, ## __VA_ARGS__)
60 #ifdef DSS_SUBSYS_NAME
61 #define DSSWARN(format, ...) \
62 pr_warn("omapdss " DSS_SUBSYS_NAME ": " format, ##__VA_ARGS__)
64 #define DSSWARN(format, ...) \
65 pr_warn("omapdss: " format, ##__VA_ARGS__)
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))
84 enum dss_io_pad_mode
{
85 DSS_IO_PAD_MODE_RESET
,
87 DSS_IO_PAD_MODE_BYPASS
,
90 enum dss_hdmi_venc_clk_source_select
{
95 enum dss_dsi_content_type
{
97 DSS_DSI_CONTENT_GENERIC
,
100 enum dss_writeback_channel
{
111 enum dss_clk_source
{
122 DSS_CLK_SRC_HDMI_PLL
,
135 #define DSS_PLL_MAX_HSDIVS 4
143 * Type-A PLLs: clkout[]/mX[] refer to hsdiv outputs m4, m5, m6, m7.
144 * Type-B PLLs: clkout[0] refers to m2.
146 struct dss_pll_clock_info
{
147 /* rates that we get with dividers below */
149 unsigned long clkdco
;
150 unsigned long clkout
[DSS_PLL_MAX_HSDIVS
];
156 u16 mX
[DSS_PLL_MAX_HSDIVS
];
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
);
168 enum dss_pll_type type
;
175 unsigned long fint_min
, fint_max
;
176 unsigned long clkdco_min
, clkdco_low
, clkdco_max
;
180 u8 mX_msb
[DSS_PLL_MAX_HSDIVS
], mX_lsb
[DSS_PLL_MAX_HSDIVS
];
187 /* DRA7 errata i886: use high N & M to avoid jitter */
196 struct regulator
*regulator
;
200 const struct dss_pll_hw
*hw
;
202 const struct dss_pll_ops
*ops
;
204 struct dss_pll_clock_info cinfo
;
207 /* Defines a generic omap register field */
208 struct dss_reg_field
{
212 struct dispc_clock_info
{
213 /* rates that we get with dividers below */
222 struct dss_lcd_mgr_config
{
223 enum dss_io_pad_mode io_pad_mode
;
228 struct dispc_clock_info clock_info
;
230 int video_port_width
;
232 int lcden_sig_polarity
;
236 struct platform_device
;
239 static inline int dss_set_min_bus_tput(struct device
*dev
, unsigned long tput
)
241 /* To be implemented when the OMAP platform will provide this feature */
245 static inline bool dss_mgr_is_lcd(enum omap_channel id
)
247 if (id
== OMAP_DSS_CHANNEL_LCD
|| id
== OMAP_DSS_CHANNEL_LCD2
||
248 id
== OMAP_DSS_CHANNEL_LCD3
)
255 #if defined(CONFIG_OMAP2_DSS_DEBUGFS)
256 int dss_debugfs_create_file(const char *name
, void (*write
)(struct seq_file
*));
258 static inline int dss_debugfs_create_file(const char *name
,
259 void (*write
)(struct seq_file
*))
263 #endif /* CONFIG_OMAP2_DSS_DEBUGFS */
265 int dss_runtime_get(void);
266 void dss_runtime_put(void);
268 unsigned long dss_get_dispc_clk_rate(void);
269 unsigned long dss_get_max_fck_rate(void);
270 enum omap_dss_output_id
dss_get_supported_outputs(enum omap_channel channel
);
271 int dss_dpi_select_source(int port
, enum omap_channel channel
);
272 void dss_select_hdmi_venc_clk_source(enum dss_hdmi_venc_clk_source_select
);
273 const char *dss_get_clk_source_name(enum dss_clk_source clk_src
);
276 struct dss_pll
*dss_video_pll_init(struct platform_device
*pdev
, int id
,
277 struct regulator
*regulator
);
278 void dss_video_pll_uninit(struct dss_pll
*pll
);
280 void dss_ctrl_pll_enable(enum dss_pll_id pll_id
, bool enable
);
282 void dss_sdi_init(int datapairs
);
283 int dss_sdi_enable(void);
284 void dss_sdi_disable(void);
286 void dss_select_dsi_clk_source(int dsi_module
,
287 enum dss_clk_source clk_src
);
288 void dss_select_lcd_clk_source(enum omap_channel channel
,
289 enum dss_clk_source clk_src
);
290 enum dss_clk_source
dss_get_dispc_clk_source(void);
291 enum dss_clk_source
dss_get_dsi_clk_source(int dsi_module
);
292 enum dss_clk_source
dss_get_lcd_clk_source(enum omap_channel channel
);
294 void dss_set_venc_output(enum omap_dss_venc_type type
);
295 void dss_set_dac_pwrdn_bgz(bool enable
);
297 int dss_set_fck_rate(unsigned long rate
);
299 typedef bool (*dss_div_calc_func
)(unsigned long fck
, void *data
);
300 bool dss_div_calc(unsigned long pck
, unsigned long fck_min
,
301 dss_div_calc_func func
, void *data
);
304 #ifdef CONFIG_OMAP2_DSS_SDI
305 int sdi_init_port(struct platform_device
*pdev
, struct device_node
*port
);
306 void sdi_uninit_port(struct device_node
*port
);
308 static inline int sdi_init_port(struct platform_device
*pdev
,
309 struct device_node
*port
)
313 static inline void sdi_uninit_port(struct device_node
*port
)
320 #ifdef CONFIG_OMAP2_DSS_DSI
323 struct file_operations
;
325 void dsi_dump_clocks(struct seq_file
*s
);
327 void dsi_irq_handler(void);
332 #ifdef CONFIG_OMAP2_DSS_DPI
333 int dpi_init_port(struct platform_device
*pdev
, struct device_node
*port
,
334 enum dss_model dss_model
);
335 void dpi_uninit_port(struct device_node
*port
);
337 static inline int dpi_init_port(struct platform_device
*pdev
,
338 struct device_node
*port
, enum dss_model dss_model
)
342 static inline void dpi_uninit_port(struct device_node
*port
)
348 void dispc_dump_clocks(struct seq_file
*s
);
350 int dispc_runtime_get(void);
351 void dispc_runtime_put(void);
353 void dispc_enable_sidle(void);
354 void dispc_disable_sidle(void);
356 void dispc_lcd_enable_signal(bool enable
);
357 void dispc_pck_free_enable(bool enable
);
358 void dispc_enable_fifomerge(bool enable
);
360 typedef bool (*dispc_div_calc_func
)(int lckd
, int pckd
, unsigned long lck
,
361 unsigned long pck
, void *data
);
362 bool dispc_div_calc(unsigned long dispc
,
363 unsigned long pck_min
, unsigned long pck_max
,
364 dispc_div_calc_func func
, void *data
);
366 bool dispc_mgr_timings_ok(enum omap_channel channel
, const struct videomode
*vm
);
367 int dispc_calc_clock_rates(unsigned long dispc_fclk_rate
,
368 struct dispc_clock_info
*cinfo
);
371 void dispc_ovl_set_fifo_threshold(enum omap_plane_id plane
, u32 low
,
373 void dispc_ovl_compute_fifo_thresholds(enum omap_plane_id plane
,
374 u32
*fifo_low
, u32
*fifo_high
, bool use_fifomerge
,
377 void dispc_mgr_set_clock_div(enum omap_channel channel
,
378 const struct dispc_clock_info
*cinfo
);
379 int dispc_mgr_get_clock_div(enum omap_channel channel
,
380 struct dispc_clock_info
*cinfo
);
381 void dispc_set_tv_pclk(unsigned long pclk
);
383 u32
dispc_wb_get_framedone_irq(void);
384 bool dispc_wb_go_busy(void);
385 void dispc_wb_go(void);
386 void dispc_wb_set_channel_in(enum dss_writeback_channel channel
);
387 int dispc_wb_setup(const struct omap_dss_writeback_info
*wi
,
388 bool mem_to_mem
, const struct videomode
*vm
);
390 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
391 static inline void dss_collect_irq_stats(u32 irqstatus
, unsigned int *irq_arr
)
394 for (b
= 0; b
< 32; ++b
) {
395 if (irqstatus
& (1 << b
))
402 typedef bool (*dss_pll_calc_func
)(int n
, int m
, unsigned long fint
,
403 unsigned long clkdco
, void *data
);
404 typedef bool (*dss_hsdiv_calc_func
)(int m_dispc
, unsigned long dispc
,
407 int dss_pll_register(struct dss_pll
*pll
);
408 void dss_pll_unregister(struct dss_pll
*pll
);
409 struct dss_pll
*dss_pll_find(const char *name
);
410 struct dss_pll
*dss_pll_find_by_src(enum dss_clk_source src
);
411 unsigned int dss_pll_get_clkout_idx_for_src(enum dss_clk_source src
);
412 int dss_pll_enable(struct dss_pll
*pll
);
413 void dss_pll_disable(struct dss_pll
*pll
);
414 int dss_pll_set_config(struct dss_pll
*pll
,
415 const struct dss_pll_clock_info
*cinfo
);
417 bool dss_pll_hsdiv_calc_a(const struct dss_pll
*pll
, unsigned long clkdco
,
418 unsigned long out_min
, unsigned long out_max
,
419 dss_hsdiv_calc_func func
, void *data
);
420 bool dss_pll_calc_a(const struct dss_pll
*pll
, unsigned long clkin
,
421 unsigned long pll_min
, unsigned long pll_max
,
422 dss_pll_calc_func func
, void *data
);
424 bool dss_pll_calc_b(const struct dss_pll
*pll
, unsigned long clkin
,
425 unsigned long target_clkout
, struct dss_pll_clock_info
*cinfo
);
427 int dss_pll_write_config_type_a(struct dss_pll
*pll
,
428 const struct dss_pll_clock_info
*cinfo
);
429 int dss_pll_write_config_type_b(struct dss_pll
*pll
,
430 const struct dss_pll_clock_info
*cinfo
);
431 int dss_pll_wait_reset_done(struct dss_pll
*pll
);
433 extern struct platform_driver omap_dsshw_driver
;
434 extern struct platform_driver omap_dispchw_driver
;
435 #ifdef CONFIG_OMAP2_DSS_DSI
436 extern struct platform_driver omap_dsihw_driver
;
438 #ifdef CONFIG_OMAP2_DSS_VENC
439 extern struct platform_driver omap_venchw_driver
;
441 #ifdef CONFIG_OMAP4_DSS_HDMI
442 extern struct platform_driver omapdss_hdmi4hw_driver
;
444 #ifdef CONFIG_OMAP5_DSS_HDMI
445 extern struct platform_driver omapdss_hdmi5hw_driver
;