dss.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. /*
  2. * linux/drivers/video/omap2/dss/dss.h
  3. *
  4. * Copyright (C) 2009 Nokia Corporation
  5. * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
  6. *
  7. * Some code and ideas taken from drivers/video/omap/ driver
  8. * by Imre Deak.
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License version 2 as published by
  12. * the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful, but WITHOUT
  15. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  16. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  17. * more details.
  18. *
  19. * You should have received a copy of the GNU General Public License along with
  20. * this program. If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. #ifndef __OMAP2_DSS_H
  23. #define __OMAP2_DSS_H
  24. #include <linux/interrupt.h>
  25. #ifdef pr_fmt
  26. #undef pr_fmt
  27. #endif
  28. #ifdef DSS_SUBSYS_NAME
  29. #define pr_fmt(fmt) DSS_SUBSYS_NAME ": " fmt
  30. #else
  31. #define pr_fmt(fmt) fmt
  32. #endif
  33. #define DSSDBG(format, ...) \
  34. pr_debug(format, ## __VA_ARGS__)
  35. #ifdef DSS_SUBSYS_NAME
  36. #define DSSERR(format, ...) \
  37. printk(KERN_ERR "omapdss " DSS_SUBSYS_NAME " error: " format, \
  38. ## __VA_ARGS__)
  39. #else
  40. #define DSSERR(format, ...) \
  41. printk(KERN_ERR "omapdss error: " format, ## __VA_ARGS__)
  42. #endif
  43. #ifdef DSS_SUBSYS_NAME
  44. #define DSSINFO(format, ...) \
  45. printk(KERN_INFO "omapdss " DSS_SUBSYS_NAME ": " format, \
  46. ## __VA_ARGS__)
  47. #else
  48. #define DSSINFO(format, ...) \
  49. printk(KERN_INFO "omapdss: " format, ## __VA_ARGS__)
  50. #endif
  51. #ifdef DSS_SUBSYS_NAME
  52. #define DSSWARN(format, ...) \
  53. printk(KERN_WARNING "omapdss " DSS_SUBSYS_NAME ": " format, \
  54. ## __VA_ARGS__)
  55. #else
  56. #define DSSWARN(format, ...) \
  57. printk(KERN_WARNING "omapdss: " format, ## __VA_ARGS__)
  58. #endif
  59. /* OMAP TRM gives bitfields as start:end, where start is the higher bit
  60. number. For example 7:0 */
  61. #define FLD_MASK(start, end) (((1 << ((start) - (end) + 1)) - 1) << (end))
  62. #define FLD_VAL(val, start, end) (((val) << (end)) & FLD_MASK(start, end))
  63. #define FLD_GET(val, start, end) (((val) & FLD_MASK(start, end)) >> (end))
  64. #define FLD_MOD(orig, val, start, end) \
  65. (((orig) & ~FLD_MASK(start, end)) | FLD_VAL(val, start, end))
  66. enum dss_io_pad_mode {
  67. DSS_IO_PAD_MODE_RESET,
  68. DSS_IO_PAD_MODE_RFBI,
  69. DSS_IO_PAD_MODE_BYPASS,
  70. };
  71. enum dss_hdmi_venc_clk_source_select {
  72. DSS_VENC_TV_CLK = 0,
  73. DSS_HDMI_M_PCLK = 1,
  74. };
  75. enum dss_dsi_content_type {
  76. DSS_DSI_CONTENT_DCS,
  77. DSS_DSI_CONTENT_GENERIC,
  78. };
  79. enum dss_writeback_channel {
  80. DSS_WB_LCD1_MGR = 0,
  81. DSS_WB_LCD2_MGR = 1,
  82. DSS_WB_TV_MGR = 2,
  83. DSS_WB_OVL0 = 3,
  84. DSS_WB_OVL1 = 4,
  85. DSS_WB_OVL2 = 5,
  86. DSS_WB_OVL3 = 6,
  87. DSS_WB_LCD3_MGR = 7,
  88. };
  89. struct dss_pll;
  90. #define DSS_PLL_MAX_HSDIVS 4
  91. /*
  92. * Type-A PLLs: clkout[]/mX[] refer to hsdiv outputs m4, m5, m6, m7.
  93. * Type-B PLLs: clkout[0] refers to m2.
  94. */
  95. struct dss_pll_clock_info {
  96. /* rates that we get with dividers below */
  97. unsigned long fint;
  98. unsigned long clkdco;
  99. unsigned long clkout[DSS_PLL_MAX_HSDIVS];
  100. /* dividers */
  101. u16 n;
  102. u16 m;
  103. u32 mf;
  104. u16 mX[DSS_PLL_MAX_HSDIVS];
  105. u16 sd;
  106. };
  107. struct dss_pll_ops {
  108. int (*enable)(struct dss_pll *pll);
  109. void (*disable)(struct dss_pll *pll);
  110. int (*set_config)(struct dss_pll *pll,
  111. const struct dss_pll_clock_info *cinfo);
  112. };
  113. struct dss_pll_hw {
  114. unsigned n_max;
  115. unsigned m_min;
  116. unsigned m_max;
  117. unsigned mX_max;
  118. unsigned long fint_min, fint_max;
  119. unsigned long clkdco_min, clkdco_low, clkdco_max;
  120. u8 n_msb, n_lsb;
  121. u8 m_msb, m_lsb;
  122. u8 mX_msb[DSS_PLL_MAX_HSDIVS], mX_lsb[DSS_PLL_MAX_HSDIVS];
  123. bool has_stopmode;
  124. bool has_freqsel;
  125. bool has_selfreqdco;
  126. bool has_refsel;
  127. };
  128. struct dss_pll {
  129. const char *name;
  130. struct clk *clkin;
  131. struct regulator *regulator;
  132. void __iomem *base;
  133. const struct dss_pll_hw *hw;
  134. const struct dss_pll_ops *ops;
  135. struct dss_pll_clock_info cinfo;
  136. };
  137. struct dispc_clock_info {
  138. /* rates that we get with dividers below */
  139. unsigned long lck;
  140. unsigned long pck;
  141. /* dividers */
  142. u16 lck_div;
  143. u16 pck_div;
  144. };
  145. struct dss_lcd_mgr_config {
  146. enum dss_io_pad_mode io_pad_mode;
  147. bool stallmode;
  148. bool fifohandcheck;
  149. struct dispc_clock_info clock_info;
  150. int video_port_width;
  151. int lcden_sig_polarity;
  152. };
  153. struct seq_file;
  154. struct platform_device;
  155. /* core */
  156. struct platform_device *dss_get_core_pdev(void);
  157. int dss_dsi_enable_pads(int dsi_id, unsigned lane_mask);
  158. void dss_dsi_disable_pads(int dsi_id, unsigned lane_mask);
  159. int dss_set_min_bus_tput(struct device *dev, unsigned long tput);
  160. int dss_debugfs_create_file(const char *name, void (*write)(struct seq_file *));
  161. /* display */
  162. int dss_suspend_all_devices(void);
  163. int dss_resume_all_devices(void);
  164. void dss_disable_all_devices(void);
  165. int display_init_sysfs(struct platform_device *pdev);
  166. void display_uninit_sysfs(struct platform_device *pdev);
  167. /* manager */
  168. int dss_init_overlay_managers(void);
  169. void dss_uninit_overlay_managers(void);
  170. int dss_init_overlay_managers_sysfs(struct platform_device *pdev);
  171. void dss_uninit_overlay_managers_sysfs(struct platform_device *pdev);
  172. int dss_mgr_simple_check(struct omap_overlay_manager *mgr,
  173. const struct omap_overlay_manager_info *info);
  174. int dss_mgr_check_timings(struct omap_overlay_manager *mgr,
  175. const struct omap_video_timings *timings);
  176. int dss_mgr_check(struct omap_overlay_manager *mgr,
  177. struct omap_overlay_manager_info *info,
  178. const struct omap_video_timings *mgr_timings,
  179. const struct dss_lcd_mgr_config *config,
  180. struct omap_overlay_info **overlay_infos);
  181. static inline bool dss_mgr_is_lcd(enum omap_channel id)
  182. {
  183. if (id == OMAP_DSS_CHANNEL_LCD || id == OMAP_DSS_CHANNEL_LCD2 ||
  184. id == OMAP_DSS_CHANNEL_LCD3)
  185. return true;
  186. else
  187. return false;
  188. }
  189. int dss_manager_kobj_init(struct omap_overlay_manager *mgr,
  190. struct platform_device *pdev);
  191. void dss_manager_kobj_uninit(struct omap_overlay_manager *mgr);
  192. /* overlay */
  193. void dss_init_overlays(struct platform_device *pdev);
  194. void dss_uninit_overlays(struct platform_device *pdev);
  195. void dss_overlay_setup_dispc_manager(struct omap_overlay_manager *mgr);
  196. int dss_ovl_simple_check(struct omap_overlay *ovl,
  197. const struct omap_overlay_info *info);
  198. int dss_ovl_check(struct omap_overlay *ovl, struct omap_overlay_info *info,
  199. const struct omap_video_timings *mgr_timings);
  200. bool dss_ovl_use_replication(struct dss_lcd_mgr_config config,
  201. enum omap_color_mode mode);
  202. int dss_overlay_kobj_init(struct omap_overlay *ovl,
  203. struct platform_device *pdev);
  204. void dss_overlay_kobj_uninit(struct omap_overlay *ovl);
  205. /* DSS */
  206. int dss_init_platform_driver(void) __init;
  207. void dss_uninit_platform_driver(void);
  208. unsigned long dss_get_dispc_clk_rate(void);
  209. int dss_dpi_select_source(int port, enum omap_channel channel);
  210. void dss_select_hdmi_venc_clk_source(enum dss_hdmi_venc_clk_source_select);
  211. enum dss_hdmi_venc_clk_source_select dss_get_hdmi_venc_clk_source(void);
  212. const char *dss_get_generic_clk_source_name(enum omap_dss_clk_source clk_src);
  213. void dss_dump_clocks(struct seq_file *s);
  214. /* dss-of */
  215. struct device_node *dss_of_port_get_parent_device(struct device_node *port);
  216. u32 dss_of_port_get_port_number(struct device_node *port);
  217. #if defined(CONFIG_OMAP2_DSS_DEBUGFS)
  218. void dss_debug_dump_clocks(struct seq_file *s);
  219. #endif
  220. void dss_sdi_init(int datapairs);
  221. int dss_sdi_enable(void);
  222. void dss_sdi_disable(void);
  223. void dss_select_dsi_clk_source(int dsi_module,
  224. enum omap_dss_clk_source clk_src);
  225. void dss_select_lcd_clk_source(enum omap_channel channel,
  226. enum omap_dss_clk_source clk_src);
  227. enum omap_dss_clk_source dss_get_dispc_clk_source(void);
  228. enum omap_dss_clk_source dss_get_dsi_clk_source(int dsi_module);
  229. enum omap_dss_clk_source dss_get_lcd_clk_source(enum omap_channel channel);
  230. void dss_set_venc_output(enum omap_dss_venc_type type);
  231. void dss_set_dac_pwrdn_bgz(bool enable);
  232. int dss_set_fck_rate(unsigned long rate);
  233. typedef bool (*dss_div_calc_func)(unsigned long fck, void *data);
  234. bool dss_div_calc(unsigned long pck, unsigned long fck_min,
  235. dss_div_calc_func func, void *data);
  236. /* SDI */
  237. int sdi_init_platform_driver(void) __init;
  238. void sdi_uninit_platform_driver(void) __exit;
  239. #ifdef CONFIG_OMAP2_DSS_SDI
  240. int sdi_init_port(struct platform_device *pdev, struct device_node *port) __init;
  241. void sdi_uninit_port(struct device_node *port) __exit;
  242. #else
  243. static inline int __init sdi_init_port(struct platform_device *pdev,
  244. struct device_node *port)
  245. {
  246. return 0;
  247. }
  248. static inline void __exit sdi_uninit_port(struct device_node *port)
  249. {
  250. }
  251. #endif
  252. /* DSI */
  253. #ifdef CONFIG_OMAP2_DSS_DSI
  254. struct dentry;
  255. struct file_operations;
  256. int dsi_init_platform_driver(void) __init;
  257. void dsi_uninit_platform_driver(void) __exit;
  258. void dsi_dump_clocks(struct seq_file *s);
  259. void dsi_irq_handler(void);
  260. u8 dsi_get_pixel_size(enum omap_dss_dsi_pixel_format fmt);
  261. #else
  262. static inline u8 dsi_get_pixel_size(enum omap_dss_dsi_pixel_format fmt)
  263. {
  264. WARN("%s: DSI not compiled in, returning pixel_size as 0\n", __func__);
  265. return 0;
  266. }
  267. #endif
  268. /* DPI */
  269. int dpi_init_platform_driver(void) __init;
  270. void dpi_uninit_platform_driver(void) __exit;
  271. #ifdef CONFIG_OMAP2_DSS_DPI
  272. int dpi_init_port(struct platform_device *pdev, struct device_node *port) __init;
  273. void dpi_uninit_port(struct device_node *port) __exit;
  274. #else
  275. static inline int __init dpi_init_port(struct platform_device *pdev,
  276. struct device_node *port)
  277. {
  278. return 0;
  279. }
  280. static inline void __exit dpi_uninit_port(struct device_node *port)
  281. {
  282. }
  283. #endif
  284. /* DISPC */
  285. int dispc_init_platform_driver(void) __init;
  286. void dispc_uninit_platform_driver(void) __exit;
  287. void dispc_dump_clocks(struct seq_file *s);
  288. void dispc_enable_sidle(void);
  289. void dispc_disable_sidle(void);
  290. void dispc_lcd_enable_signal(bool enable);
  291. void dispc_pck_free_enable(bool enable);
  292. void dispc_enable_fifomerge(bool enable);
  293. void dispc_enable_gamma_table(bool enable);
  294. void dispc_set_loadmode(enum omap_dss_load_mode mode);
  295. typedef bool (*dispc_div_calc_func)(int lckd, int pckd, unsigned long lck,
  296. unsigned long pck, void *data);
  297. bool dispc_div_calc(unsigned long dispc,
  298. unsigned long pck_min, unsigned long pck_max,
  299. dispc_div_calc_func func, void *data);
  300. bool dispc_mgr_timings_ok(enum omap_channel channel,
  301. const struct omap_video_timings *timings);
  302. unsigned long dispc_fclk_rate(void);
  303. int dispc_calc_clock_rates(unsigned long dispc_fclk_rate,
  304. struct dispc_clock_info *cinfo);
  305. void dispc_ovl_set_fifo_threshold(enum omap_plane plane, u32 low, u32 high);
  306. void dispc_ovl_compute_fifo_thresholds(enum omap_plane plane,
  307. u32 *fifo_low, u32 *fifo_high, bool use_fifomerge,
  308. bool manual_update);
  309. unsigned long dispc_mgr_lclk_rate(enum omap_channel channel);
  310. unsigned long dispc_mgr_pclk_rate(enum omap_channel channel);
  311. unsigned long dispc_core_clk_rate(void);
  312. void dispc_mgr_set_clock_div(enum omap_channel channel,
  313. const struct dispc_clock_info *cinfo);
  314. int dispc_mgr_get_clock_div(enum omap_channel channel,
  315. struct dispc_clock_info *cinfo);
  316. void dispc_set_tv_pclk(unsigned long pclk);
  317. u32 dispc_wb_get_framedone_irq(void);
  318. bool dispc_wb_go_busy(void);
  319. void dispc_wb_go(void);
  320. void dispc_wb_enable(bool enable);
  321. bool dispc_wb_is_enabled(void);
  322. void dispc_wb_set_channel_in(enum dss_writeback_channel channel);
  323. int dispc_wb_setup(const struct omap_dss_writeback_info *wi,
  324. bool mem_to_mem, const struct omap_video_timings *timings);
  325. /* VENC */
  326. int venc_init_platform_driver(void) __init;
  327. void venc_uninit_platform_driver(void) __exit;
  328. /* HDMI */
  329. int hdmi4_init_platform_driver(void) __init;
  330. void hdmi4_uninit_platform_driver(void) __exit;
  331. int hdmi5_init_platform_driver(void) __init;
  332. void hdmi5_uninit_platform_driver(void) __exit;
  333. /* RFBI */
  334. int rfbi_init_platform_driver(void) __init;
  335. void rfbi_uninit_platform_driver(void) __exit;
  336. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  337. static inline void dss_collect_irq_stats(u32 irqstatus, unsigned *irq_arr)
  338. {
  339. int b;
  340. for (b = 0; b < 32; ++b) {
  341. if (irqstatus & (1 << b))
  342. irq_arr[b]++;
  343. }
  344. }
  345. #endif
  346. /* PLL */
  347. typedef bool (*dss_pll_calc_func)(int n, int m, unsigned long fint,
  348. unsigned long clkdco, void *data);
  349. typedef bool (*dss_hsdiv_calc_func)(int m_dispc, unsigned long dispc,
  350. void *data);
  351. int dss_pll_register(struct dss_pll *pll);
  352. void dss_pll_unregister(struct dss_pll *pll);
  353. struct dss_pll *dss_pll_find(const char *name);
  354. int dss_pll_enable(struct dss_pll *pll);
  355. void dss_pll_disable(struct dss_pll *pll);
  356. int dss_pll_set_config(struct dss_pll *pll,
  357. const struct dss_pll_clock_info *cinfo);
  358. bool dss_pll_hsdiv_calc(const struct dss_pll *pll, unsigned long clkdco,
  359. unsigned long out_min, unsigned long out_max,
  360. dss_hsdiv_calc_func func, void *data);
  361. bool dss_pll_calc(const struct dss_pll *pll, unsigned long clkin,
  362. unsigned long pll_min, unsigned long pll_max,
  363. dss_pll_calc_func func, void *data);
  364. int dss_pll_write_config_type_a(struct dss_pll *pll,
  365. const struct dss_pll_clock_info *cinfo);
  366. int dss_pll_write_config_type_b(struct dss_pll *pll,
  367. const struct dss_pll_clock_info *cinfo);
  368. #endif