1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * linux/drivers/video/omap2/dss/dss.h
5 * Copyright (C) 2009 Nokia Corporation
6 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
8 * Some code and ideas taken from drivers/video/omap/ driver
15 #include <linux/interrupt.h>
21 #ifdef DSS_SUBSYS_NAME
22 #define pr_fmt(fmt) DSS_SUBSYS_NAME ": " fmt
24 #define pr_fmt(fmt) fmt
27 #define DSSDBG(format, ...) \
28 pr_debug(format, ## __VA_ARGS__)
30 #ifdef DSS_SUBSYS_NAME
31 #define DSSERR(format, ...) \
32 printk(KERN_ERR "omapdss " DSS_SUBSYS_NAME " error: " format, \
35 #define DSSERR(format, ...) \
36 printk(KERN_ERR "omapdss error: " format, ## __VA_ARGS__)
39 #ifdef DSS_SUBSYS_NAME
40 #define DSSINFO(format, ...) \
41 printk(KERN_INFO "omapdss " DSS_SUBSYS_NAME ": " format, \
44 #define DSSINFO(format, ...) \
45 printk(KERN_INFO "omapdss: " format, ## __VA_ARGS__)
48 #ifdef DSS_SUBSYS_NAME
49 #define DSSWARN(format, ...) \
50 printk(KERN_WARNING "omapdss " DSS_SUBSYS_NAME ": " format, \
53 #define DSSWARN(format, ...) \
54 printk(KERN_WARNING "omapdss: " format, ## __VA_ARGS__)
57 /* OMAP TRM gives bitfields as start:end, where start is the higher bit
58 number. For example 7:0 */
59 #define FLD_MASK(start, end) (((1 << ((start) - (end) + 1)) - 1) << (end))
60 #define FLD_VAL(val, start, end) (((val) << (end)) & FLD_MASK(start, end))
61 #define FLD_GET(val, start, end) (((val) & FLD_MASK(start, end)) >> (end))
62 #define FLD_MOD(orig, val, start, end) \
63 (((orig) & ~FLD_MASK(start, end)) | FLD_VAL(val, start, end))
65 enum omap_dss_clk_source
{
66 OMAP_DSS_CLK_SRC_FCK
= 0, /* OMAP2/3: DSS1_ALWON_FCLK
68 OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC
, /* OMAP3: DSI1_PLL_FCLK
70 OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI
, /* OMAP3: DSI2_PLL_FCLK
72 OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC
, /* OMAP4: PLL2_CLK1 */
73 OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DSI
, /* OMAP4: PLL2_CLK2 */
76 enum dss_io_pad_mode
{
77 DSS_IO_PAD_MODE_RESET
,
79 DSS_IO_PAD_MODE_BYPASS
,
82 enum dss_hdmi_venc_clk_source_select
{
87 enum dss_dsi_content_type
{
89 DSS_DSI_CONTENT_GENERIC
,
102 #define DSS_PLL_MAX_HSDIVS 4
105 * Type-A PLLs: clkout[]/mX[] refer to hsdiv outputs m4, m5, m6, m7.
106 * Type-B PLLs: clkout[0] refers to m2.
108 struct dss_pll_clock_info
{
109 /* rates that we get with dividers below */
111 unsigned long clkdco
;
112 unsigned long clkout
[DSS_PLL_MAX_HSDIVS
];
118 u16 mX
[DSS_PLL_MAX_HSDIVS
];
123 int (*enable
)(struct dss_pll
*pll
);
124 void (*disable
)(struct dss_pll
*pll
);
125 int (*set_config
)(struct dss_pll
*pll
,
126 const struct dss_pll_clock_info
*cinfo
);
135 unsigned long fint_min
, fint_max
;
136 unsigned long clkdco_min
, clkdco_low
, clkdco_max
;
140 u8 mX_msb
[DSS_PLL_MAX_HSDIVS
], mX_lsb
[DSS_PLL_MAX_HSDIVS
];
153 struct regulator
*regulator
;
157 const struct dss_pll_hw
*hw
;
159 const struct dss_pll_ops
*ops
;
161 struct dss_pll_clock_info cinfo
;
164 struct dispc_clock_info
{
165 /* rates that we get with dividers below */
174 struct dss_lcd_mgr_config
{
175 enum dss_io_pad_mode io_pad_mode
;
180 struct dispc_clock_info clock_info
;
182 int video_port_width
;
184 int lcden_sig_polarity
;
188 struct platform_device
;
191 struct platform_device
*dss_get_core_pdev(void);
192 int dss_dsi_enable_pads(int dsi_id
, unsigned lane_mask
);
193 void dss_dsi_disable_pads(int dsi_id
, unsigned lane_mask
);
194 int dss_set_min_bus_tput(struct device
*dev
, unsigned long tput
);
195 void dss_debugfs_create_file(const char *name
, void (*write
)(struct seq_file
*));
198 int dss_suspend_all_devices(void);
199 int dss_resume_all_devices(void);
200 void dss_disable_all_devices(void);
202 int display_init_sysfs(struct platform_device
*pdev
);
203 void display_uninit_sysfs(struct platform_device
*pdev
);
206 int dss_init_overlay_managers(void);
207 void dss_uninit_overlay_managers(void);
208 int dss_init_overlay_managers_sysfs(struct platform_device
*pdev
);
209 void dss_uninit_overlay_managers_sysfs(struct platform_device
*pdev
);
210 int dss_mgr_simple_check(struct omap_overlay_manager
*mgr
,
211 const struct omap_overlay_manager_info
*info
);
212 int dss_mgr_check_timings(struct omap_overlay_manager
*mgr
,
213 const struct omap_video_timings
*timings
);
214 int dss_mgr_check(struct omap_overlay_manager
*mgr
,
215 struct omap_overlay_manager_info
*info
,
216 const struct omap_video_timings
*mgr_timings
,
217 const struct dss_lcd_mgr_config
*config
,
218 struct omap_overlay_info
**overlay_infos
);
220 static inline bool dss_mgr_is_lcd(enum omap_channel id
)
222 if (id
== OMAP_DSS_CHANNEL_LCD
|| id
== OMAP_DSS_CHANNEL_LCD2
||
223 id
== OMAP_DSS_CHANNEL_LCD3
)
229 int dss_manager_kobj_init(struct omap_overlay_manager
*mgr
,
230 struct platform_device
*pdev
);
231 void dss_manager_kobj_uninit(struct omap_overlay_manager
*mgr
);
234 void dss_init_overlays(struct platform_device
*pdev
);
235 void dss_uninit_overlays(struct platform_device
*pdev
);
236 void dss_overlay_setup_dispc_manager(struct omap_overlay_manager
*mgr
);
237 int dss_ovl_simple_check(struct omap_overlay
*ovl
,
238 const struct omap_overlay_info
*info
);
239 int dss_ovl_check(struct omap_overlay
*ovl
, struct omap_overlay_info
*info
,
240 const struct omap_video_timings
*mgr_timings
);
241 bool dss_ovl_use_replication(struct dss_lcd_mgr_config config
,
242 enum omap_color_mode mode
);
243 int dss_overlay_kobj_init(struct omap_overlay
*ovl
,
244 struct platform_device
*pdev
);
245 void dss_overlay_kobj_uninit(struct omap_overlay
*ovl
);
248 int dss_init_platform_driver(void) __init
;
249 void dss_uninit_platform_driver(void);
251 int dss_runtime_get(void);
252 void dss_runtime_put(void);
254 unsigned long dss_get_dispc_clk_rate(void);
255 int dss_dpi_select_source(int port
, enum omap_channel channel
);
256 void dss_select_hdmi_venc_clk_source(enum dss_hdmi_venc_clk_source_select
);
257 enum dss_hdmi_venc_clk_source_select
dss_get_hdmi_venc_clk_source(void);
258 const char *dss_get_generic_clk_source_name(enum omap_dss_clk_source clk_src
);
259 void dss_dump_clocks(struct seq_file
*s
);
262 struct dss_pll
*dss_video_pll_init(struct platform_device
*pdev
, int id
,
263 struct regulator
*regulator
);
264 void dss_video_pll_uninit(struct dss_pll
*pll
);
267 struct device_node
*dss_of_port_get_parent_device(struct device_node
*port
);
268 u32
dss_of_port_get_port_number(struct device_node
*port
);
270 #if defined(CONFIG_FB_OMAP2_DSS_DEBUGFS)
271 void dss_debug_dump_clocks(struct seq_file
*s
);
274 void dss_ctrl_pll_enable(enum dss_pll_id pll_id
, bool enable
);
275 void dss_ctrl_pll_set_control_mux(enum dss_pll_id pll_id
,
276 enum omap_channel channel
);
278 void dss_sdi_init(int datapairs
);
279 int dss_sdi_enable(void);
280 void dss_sdi_disable(void);
282 void dss_select_dsi_clk_source(int dsi_module
,
283 enum omap_dss_clk_source clk_src
);
284 void dss_select_lcd_clk_source(enum omap_channel channel
,
285 enum omap_dss_clk_source clk_src
);
286 enum omap_dss_clk_source
dss_get_dispc_clk_source(void);
287 enum omap_dss_clk_source
dss_get_dsi_clk_source(int dsi_module
);
288 enum omap_dss_clk_source
dss_get_lcd_clk_source(enum omap_channel channel
);
290 void dss_set_venc_output(enum omap_dss_venc_type type
);
291 void dss_set_dac_pwrdn_bgz(bool enable
);
293 int dss_set_fck_rate(unsigned long rate
);
295 typedef bool (*dss_div_calc_func
)(unsigned long fck
, void *data
);
296 bool dss_div_calc(unsigned long pck
, unsigned long fck_min
,
297 dss_div_calc_func func
, void *data
);
300 int sdi_init_platform_driver(void) __init
;
301 void sdi_uninit_platform_driver(void);
303 #ifdef CONFIG_FB_OMAP2_DSS_SDI
304 int sdi_init_port(struct platform_device
*pdev
, struct device_node
*port
);
305 void sdi_uninit_port(struct device_node
*port
);
307 static inline int sdi_init_port(struct platform_device
*pdev
,
308 struct device_node
*port
)
312 static inline void sdi_uninit_port(struct device_node
*port
)
319 #ifdef CONFIG_FB_OMAP2_DSS_DSI
322 struct file_operations
;
324 int dsi_init_platform_driver(void) __init
;
325 void dsi_uninit_platform_driver(void);
327 void dsi_dump_clocks(struct seq_file
*s
);
329 void dsi_irq_handler(void);
330 u8
dsi_get_pixel_size(enum omap_dss_dsi_pixel_format fmt
);
333 static inline u8
dsi_get_pixel_size(enum omap_dss_dsi_pixel_format fmt
)
335 WARN(1, "%s: DSI not compiled in, returning pixel_size as 0\n",
342 int dpi_init_platform_driver(void) __init
;
343 void dpi_uninit_platform_driver(void);
345 #ifdef CONFIG_FB_OMAP2_DSS_DPI
346 int dpi_init_port(struct platform_device
*pdev
, struct device_node
*port
);
347 void dpi_uninit_port(struct device_node
*port
);
349 static inline int dpi_init_port(struct platform_device
*pdev
,
350 struct device_node
*port
)
354 static inline void dpi_uninit_port(struct device_node
*port
)
360 int dispc_init_platform_driver(void) __init
;
361 void dispc_uninit_platform_driver(void);
362 void dispc_dump_clocks(struct seq_file
*s
);
364 void dispc_enable_sidle(void);
365 void dispc_disable_sidle(void);
367 void dispc_lcd_enable_signal(bool enable
);
368 void dispc_pck_free_enable(bool enable
);
369 void dispc_enable_gamma_table(bool enable
);
371 typedef bool (*dispc_div_calc_func
)(int lckd
, int pckd
, unsigned long lck
,
372 unsigned long pck
, void *data
);
373 bool dispc_div_calc(unsigned long dispc
,
374 unsigned long pck_min
, unsigned long pck_max
,
375 dispc_div_calc_func func
, void *data
);
377 bool dispc_mgr_timings_ok(enum omap_channel channel
,
378 const struct omap_video_timings
*timings
);
379 int dispc_calc_clock_rates(unsigned long dispc_fclk_rate
,
380 struct dispc_clock_info
*cinfo
);
383 void dispc_ovl_set_fifo_threshold(enum omap_plane plane
, u32 low
, u32 high
);
384 void dispc_ovl_compute_fifo_thresholds(enum omap_plane plane
,
385 u32
*fifo_low
, u32
*fifo_high
, bool use_fifomerge
,
388 void dispc_mgr_set_clock_div(enum omap_channel channel
,
389 const struct dispc_clock_info
*cinfo
);
390 void dispc_set_tv_pclk(unsigned long pclk
);
392 u32
dispc_read_irqstatus(void);
393 void dispc_clear_irqstatus(u32 mask
);
394 u32
dispc_read_irqenable(void);
395 void dispc_write_irqenable(u32 mask
);
397 int dispc_request_irq(irq_handler_t handler
, void *dev_id
);
398 void dispc_free_irq(void *dev_id
);
400 int dispc_runtime_get(void);
401 void dispc_runtime_put(void);
403 void dispc_mgr_enable(enum omap_channel channel
, bool enable
);
404 bool dispc_mgr_is_enabled(enum omap_channel channel
);
405 u32
dispc_mgr_get_vsync_irq(enum omap_channel channel
);
406 u32
dispc_mgr_get_framedone_irq(enum omap_channel channel
);
407 u32
dispc_mgr_get_sync_lost_irq(enum omap_channel channel
);
408 bool dispc_mgr_go_busy(enum omap_channel channel
);
409 void dispc_mgr_go(enum omap_channel channel
);
410 void dispc_mgr_set_lcd_config(enum omap_channel channel
,
411 const struct dss_lcd_mgr_config
*config
);
412 void dispc_mgr_set_timings(enum omap_channel channel
,
413 const struct omap_video_timings
*timings
);
414 void dispc_mgr_setup(enum omap_channel channel
,
415 const struct omap_overlay_manager_info
*info
);
417 int dispc_ovl_check(enum omap_plane plane
, enum omap_channel channel
,
418 const struct omap_overlay_info
*oi
,
419 const struct omap_video_timings
*timings
,
420 int *x_predecim
, int *y_predecim
);
422 int dispc_ovl_enable(enum omap_plane plane
, bool enable
);
423 bool dispc_ovl_enabled(enum omap_plane plane
);
424 void dispc_ovl_set_channel_out(enum omap_plane plane
,
425 enum omap_channel channel
);
426 int dispc_ovl_setup(enum omap_plane plane
, const struct omap_overlay_info
*oi
,
427 bool replication
, const struct omap_video_timings
*mgr_timings
,
431 int venc_init_platform_driver(void) __init
;
432 void venc_uninit_platform_driver(void);
435 int hdmi4_init_platform_driver(void) __init
;
436 void hdmi4_uninit_platform_driver(void);
438 int hdmi5_init_platform_driver(void) __init
;
439 void hdmi5_uninit_platform_driver(void);
442 #ifdef CONFIG_FB_OMAP2_DSS_COLLECT_IRQ_STATS
443 static inline void dss_collect_irq_stats(u32 irqstatus
, unsigned *irq_arr
)
446 for (b
= 0; b
< 32; ++b
) {
447 if (irqstatus
& (1 << b
))
454 typedef bool (*dss_pll_calc_func
)(int n
, int m
, unsigned long fint
,
455 unsigned long clkdco
, void *data
);
456 typedef bool (*dss_hsdiv_calc_func
)(int m_dispc
, unsigned long dispc
,
459 int dss_pll_register(struct dss_pll
*pll
);
460 void dss_pll_unregister(struct dss_pll
*pll
);
461 struct dss_pll
*dss_pll_find(const char *name
);
462 int dss_pll_enable(struct dss_pll
*pll
);
463 void dss_pll_disable(struct dss_pll
*pll
);
464 int dss_pll_set_config(struct dss_pll
*pll
,
465 const struct dss_pll_clock_info
*cinfo
);
467 bool dss_pll_hsdiv_calc(const struct dss_pll
*pll
, unsigned long clkdco
,
468 unsigned long out_min
, unsigned long out_max
,
469 dss_hsdiv_calc_func func
, void *data
);
470 bool dss_pll_calc(const struct dss_pll
*pll
, unsigned long clkin
,
471 unsigned long pll_min
, unsigned long pll_max
,
472 dss_pll_calc_func func
, void *data
);
473 int dss_pll_write_config_type_a(struct dss_pll
*pll
,
474 const struct dss_pll_clock_info
*cinfo
);
475 int dss_pll_write_config_type_b(struct dss_pll
*pll
,
476 const struct dss_pll_clock_info
*cinfo
);
477 int dss_pll_wait_reset_done(struct dss_pll
*pll
);
482 int (*connect
)(struct omap_overlay_manager
*mgr
,
483 struct omap_dss_device
*dst
);
484 void (*disconnect
)(struct omap_overlay_manager
*mgr
,
485 struct omap_dss_device
*dst
);
487 void (*start_update
)(struct omap_overlay_manager
*mgr
);
488 int (*enable
)(struct omap_overlay_manager
*mgr
);
489 void (*disable
)(struct omap_overlay_manager
*mgr
);
490 void (*set_timings
)(struct omap_overlay_manager
*mgr
,
491 const struct omap_video_timings
*timings
);
492 void (*set_lcd_config
)(struct omap_overlay_manager
*mgr
,
493 const struct dss_lcd_mgr_config
*config
);
494 int (*register_framedone_handler
)(struct omap_overlay_manager
*mgr
,
495 void (*handler
)(void *), void *data
);
496 void (*unregister_framedone_handler
)(struct omap_overlay_manager
*mgr
,
497 void (*handler
)(void *), void *data
);
500 int dss_install_mgr_ops(const struct dss_mgr_ops
*mgr_ops
);
501 void dss_uninstall_mgr_ops(void);
503 int dss_mgr_connect(struct omap_overlay_manager
*mgr
,
504 struct omap_dss_device
*dst
);
505 void dss_mgr_disconnect(struct omap_overlay_manager
*mgr
,
506 struct omap_dss_device
*dst
);
507 void dss_mgr_set_timings(struct omap_overlay_manager
*mgr
,
508 const struct omap_video_timings
*timings
);
509 void dss_mgr_set_lcd_config(struct omap_overlay_manager
*mgr
,
510 const struct dss_lcd_mgr_config
*config
);
511 int dss_mgr_enable(struct omap_overlay_manager
*mgr
);
512 void dss_mgr_disable(struct omap_overlay_manager
*mgr
);
513 void dss_mgr_start_update(struct omap_overlay_manager
*mgr
);
514 int dss_mgr_register_framedone_handler(struct omap_overlay_manager
*mgr
,
515 void (*handler
)(void *), void *data
);
516 void dss_mgr_unregister_framedone_handler(struct omap_overlay_manager
*mgr
,
517 void (*handler
)(void *), void *data
);