dss.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  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. #include "omapdss.h"
  26. #ifdef pr_fmt
  27. #undef pr_fmt
  28. #endif
  29. #ifdef DSS_SUBSYS_NAME
  30. #define pr_fmt(fmt) DSS_SUBSYS_NAME ": " fmt
  31. #else
  32. #define pr_fmt(fmt) fmt
  33. #endif
  34. #define DSSDBG(format, ...) \
  35. pr_debug(format, ## __VA_ARGS__)
  36. #ifdef DSS_SUBSYS_NAME
  37. #define DSSERR(format, ...) \
  38. pr_err("omapdss " DSS_SUBSYS_NAME " error: " format, ##__VA_ARGS__)
  39. #else
  40. #define DSSERR(format, ...) \
  41. pr_err("omapdss error: " format, ##__VA_ARGS__)
  42. #endif
  43. #ifdef DSS_SUBSYS_NAME
  44. #define DSSINFO(format, ...) \
  45. pr_info("omapdss " DSS_SUBSYS_NAME ": " format, ##__VA_ARGS__)
  46. #else
  47. #define DSSINFO(format, ...) \
  48. pr_info("omapdss: " format, ## __VA_ARGS__)
  49. #endif
  50. #ifdef DSS_SUBSYS_NAME
  51. #define DSSWARN(format, ...) \
  52. pr_warn("omapdss " DSS_SUBSYS_NAME ": " format, ##__VA_ARGS__)
  53. #else
  54. #define DSSWARN(format, ...) \
  55. pr_warn("omapdss: " format, ##__VA_ARGS__)
  56. #endif
  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))
  64. enum dss_io_pad_mode {
  65. DSS_IO_PAD_MODE_RESET,
  66. DSS_IO_PAD_MODE_RFBI,
  67. DSS_IO_PAD_MODE_BYPASS,
  68. };
  69. enum dss_hdmi_venc_clk_source_select {
  70. DSS_VENC_TV_CLK = 0,
  71. DSS_HDMI_M_PCLK = 1,
  72. };
  73. enum dss_dsi_content_type {
  74. DSS_DSI_CONTENT_DCS,
  75. DSS_DSI_CONTENT_GENERIC,
  76. };
  77. enum dss_writeback_channel {
  78. DSS_WB_LCD1_MGR = 0,
  79. DSS_WB_LCD2_MGR = 1,
  80. DSS_WB_TV_MGR = 2,
  81. DSS_WB_OVL0 = 3,
  82. DSS_WB_OVL1 = 4,
  83. DSS_WB_OVL2 = 5,
  84. DSS_WB_OVL3 = 6,
  85. DSS_WB_LCD3_MGR = 7,
  86. };
  87. enum dss_clk_source {
  88. DSS_CLK_SRC_FCK = 0,
  89. DSS_CLK_SRC_PLL1_1,
  90. DSS_CLK_SRC_PLL1_2,
  91. DSS_CLK_SRC_PLL1_3,
  92. DSS_CLK_SRC_PLL2_1,
  93. DSS_CLK_SRC_PLL2_2,
  94. DSS_CLK_SRC_PLL2_3,
  95. DSS_CLK_SRC_HDMI_PLL,
  96. };
  97. enum dss_pll_id {
  98. DSS_PLL_DSI1,
  99. DSS_PLL_DSI2,
  100. DSS_PLL_HDMI,
  101. DSS_PLL_VIDEO1,
  102. DSS_PLL_VIDEO2,
  103. };
  104. struct dss_pll;
  105. #define DSS_PLL_MAX_HSDIVS 4
  106. enum dss_pll_type {
  107. DSS_PLL_TYPE_A,
  108. DSS_PLL_TYPE_B,
  109. };
  110. /*
  111. * Type-A PLLs: clkout[]/mX[] refer to hsdiv outputs m4, m5, m6, m7.
  112. * Type-B PLLs: clkout[0] refers to m2.
  113. */
  114. struct dss_pll_clock_info {
  115. /* rates that we get with dividers below */
  116. unsigned long fint;
  117. unsigned long clkdco;
  118. unsigned long clkout[DSS_PLL_MAX_HSDIVS];
  119. /* dividers */
  120. u16 n;
  121. u16 m;
  122. u32 mf;
  123. u16 mX[DSS_PLL_MAX_HSDIVS];
  124. u16 sd;
  125. };
  126. struct dss_pll_ops {
  127. int (*enable)(struct dss_pll *pll);
  128. void (*disable)(struct dss_pll *pll);
  129. int (*set_config)(struct dss_pll *pll,
  130. const struct dss_pll_clock_info *cinfo);
  131. };
  132. struct dss_pll_hw {
  133. enum dss_pll_type type;
  134. unsigned n_max;
  135. unsigned m_min;
  136. unsigned m_max;
  137. unsigned mX_max;
  138. unsigned long fint_min, fint_max;
  139. unsigned long clkdco_min, clkdco_low, clkdco_max;
  140. u8 n_msb, n_lsb;
  141. u8 m_msb, m_lsb;
  142. u8 mX_msb[DSS_PLL_MAX_HSDIVS], mX_lsb[DSS_PLL_MAX_HSDIVS];
  143. bool has_stopmode;
  144. bool has_freqsel;
  145. bool has_selfreqdco;
  146. bool has_refsel;
  147. };
  148. struct dss_pll {
  149. const char *name;
  150. enum dss_pll_id id;
  151. struct clk *clkin;
  152. struct regulator *regulator;
  153. void __iomem *base;
  154. const struct dss_pll_hw *hw;
  155. const struct dss_pll_ops *ops;
  156. struct dss_pll_clock_info cinfo;
  157. };
  158. struct dispc_clock_info {
  159. /* rates that we get with dividers below */
  160. unsigned long lck;
  161. unsigned long pck;
  162. /* dividers */
  163. u16 lck_div;
  164. u16 pck_div;
  165. };
  166. struct dss_lcd_mgr_config {
  167. enum dss_io_pad_mode io_pad_mode;
  168. bool stallmode;
  169. bool fifohandcheck;
  170. struct dispc_clock_info clock_info;
  171. int video_port_width;
  172. int lcden_sig_polarity;
  173. };
  174. struct seq_file;
  175. struct platform_device;
  176. /* core */
  177. struct platform_device *dss_get_core_pdev(void);
  178. int dss_dsi_enable_pads(int dsi_id, unsigned lane_mask);
  179. void dss_dsi_disable_pads(int dsi_id, unsigned lane_mask);
  180. int dss_set_min_bus_tput(struct device *dev, unsigned long tput);
  181. int dss_debugfs_create_file(const char *name, void (*write)(struct seq_file *));
  182. static inline bool dss_mgr_is_lcd(enum omap_channel id)
  183. {
  184. if (id == OMAP_DSS_CHANNEL_LCD || id == OMAP_DSS_CHANNEL_LCD2 ||
  185. id == OMAP_DSS_CHANNEL_LCD3)
  186. return true;
  187. else
  188. return false;
  189. }
  190. /* DSS */
  191. int dss_init_platform_driver(void) __init;
  192. void dss_uninit_platform_driver(void);
  193. int dss_runtime_get(void);
  194. void dss_runtime_put(void);
  195. unsigned long dss_get_dispc_clk_rate(void);
  196. int dss_dpi_select_source(int port, enum omap_channel channel);
  197. void dss_select_hdmi_venc_clk_source(enum dss_hdmi_venc_clk_source_select);
  198. enum dss_hdmi_venc_clk_source_select dss_get_hdmi_venc_clk_source(void);
  199. const char *dss_get_clk_source_name(enum dss_clk_source clk_src);
  200. void dss_dump_clocks(struct seq_file *s);
  201. /* DSS VIDEO PLL */
  202. struct dss_pll *dss_video_pll_init(struct platform_device *pdev, int id,
  203. struct regulator *regulator);
  204. void dss_video_pll_uninit(struct dss_pll *pll);
  205. #if defined(CONFIG_OMAP2_DSS_DEBUGFS)
  206. void dss_debug_dump_clocks(struct seq_file *s);
  207. #endif
  208. void dss_ctrl_pll_enable(enum dss_pll_id pll_id, bool enable);
  209. void dss_sdi_init(int datapairs);
  210. int dss_sdi_enable(void);
  211. void dss_sdi_disable(void);
  212. void dss_select_dsi_clk_source(int dsi_module,
  213. enum dss_clk_source clk_src);
  214. void dss_select_lcd_clk_source(enum omap_channel channel,
  215. enum dss_clk_source clk_src);
  216. enum dss_clk_source dss_get_dispc_clk_source(void);
  217. enum dss_clk_source dss_get_dsi_clk_source(int dsi_module);
  218. enum dss_clk_source dss_get_lcd_clk_source(enum omap_channel channel);
  219. void dss_set_venc_output(enum omap_dss_venc_type type);
  220. void dss_set_dac_pwrdn_bgz(bool enable);
  221. int dss_set_fck_rate(unsigned long rate);
  222. typedef bool (*dss_div_calc_func)(unsigned long fck, void *data);
  223. bool dss_div_calc(unsigned long pck, unsigned long fck_min,
  224. dss_div_calc_func func, void *data);
  225. /* SDI */
  226. int sdi_init_platform_driver(void) __init;
  227. void sdi_uninit_platform_driver(void);
  228. #ifdef CONFIG_OMAP2_DSS_SDI
  229. int sdi_init_port(struct platform_device *pdev, struct device_node *port);
  230. void sdi_uninit_port(struct device_node *port);
  231. #else
  232. static inline int sdi_init_port(struct platform_device *pdev,
  233. struct device_node *port)
  234. {
  235. return 0;
  236. }
  237. static inline void sdi_uninit_port(struct device_node *port)
  238. {
  239. }
  240. #endif
  241. /* DSI */
  242. #ifdef CONFIG_OMAP2_DSS_DSI
  243. struct dentry;
  244. struct file_operations;
  245. int dsi_init_platform_driver(void) __init;
  246. void dsi_uninit_platform_driver(void);
  247. void dsi_dump_clocks(struct seq_file *s);
  248. void dsi_irq_handler(void);
  249. #endif
  250. /* DPI */
  251. int dpi_init_platform_driver(void) __init;
  252. void dpi_uninit_platform_driver(void);
  253. #ifdef CONFIG_OMAP2_DSS_DPI
  254. int dpi_init_port(struct platform_device *pdev, struct device_node *port);
  255. void dpi_uninit_port(struct device_node *port);
  256. #else
  257. static inline int dpi_init_port(struct platform_device *pdev,
  258. struct device_node *port)
  259. {
  260. return 0;
  261. }
  262. static inline void dpi_uninit_port(struct device_node *port)
  263. {
  264. }
  265. #endif
  266. /* DISPC */
  267. int dispc_init_platform_driver(void) __init;
  268. void dispc_uninit_platform_driver(void);
  269. void dispc_dump_clocks(struct seq_file *s);
  270. int dispc_runtime_get(void);
  271. void dispc_runtime_put(void);
  272. void dispc_enable_sidle(void);
  273. void dispc_disable_sidle(void);
  274. void dispc_lcd_enable_signal(bool enable);
  275. void dispc_pck_free_enable(bool enable);
  276. void dispc_enable_fifomerge(bool enable);
  277. void dispc_enable_gamma_table(bool enable);
  278. typedef bool (*dispc_div_calc_func)(int lckd, int pckd, unsigned long lck,
  279. unsigned long pck, void *data);
  280. bool dispc_div_calc(unsigned long dispc,
  281. unsigned long pck_min, unsigned long pck_max,
  282. dispc_div_calc_func func, void *data);
  283. bool dispc_mgr_timings_ok(enum omap_channel channel, const struct videomode *vm);
  284. int dispc_calc_clock_rates(unsigned long dispc_fclk_rate,
  285. struct dispc_clock_info *cinfo);
  286. void dispc_ovl_set_fifo_threshold(enum omap_plane_id plane, u32 low,
  287. u32 high);
  288. void dispc_ovl_compute_fifo_thresholds(enum omap_plane_id plane,
  289. u32 *fifo_low, u32 *fifo_high, bool use_fifomerge,
  290. bool manual_update);
  291. void dispc_mgr_set_clock_div(enum omap_channel channel,
  292. const struct dispc_clock_info *cinfo);
  293. int dispc_mgr_get_clock_div(enum omap_channel channel,
  294. struct dispc_clock_info *cinfo);
  295. void dispc_set_tv_pclk(unsigned long pclk);
  296. u32 dispc_wb_get_framedone_irq(void);
  297. bool dispc_wb_go_busy(void);
  298. void dispc_wb_go(void);
  299. void dispc_wb_set_channel_in(enum dss_writeback_channel channel);
  300. int dispc_wb_setup(const struct omap_dss_writeback_info *wi,
  301. bool mem_to_mem, const struct videomode *vm);
  302. /* VENC */
  303. int venc_init_platform_driver(void) __init;
  304. void venc_uninit_platform_driver(void);
  305. /* HDMI */
  306. int hdmi4_init_platform_driver(void) __init;
  307. void hdmi4_uninit_platform_driver(void);
  308. int hdmi5_init_platform_driver(void) __init;
  309. void hdmi5_uninit_platform_driver(void);
  310. /* RFBI */
  311. int rfbi_init_platform_driver(void) __init;
  312. void rfbi_uninit_platform_driver(void);
  313. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  314. static inline void dss_collect_irq_stats(u32 irqstatus, unsigned *irq_arr)
  315. {
  316. int b;
  317. for (b = 0; b < 32; ++b) {
  318. if (irqstatus & (1 << b))
  319. irq_arr[b]++;
  320. }
  321. }
  322. #endif
  323. /* PLL */
  324. typedef bool (*dss_pll_calc_func)(int n, int m, unsigned long fint,
  325. unsigned long clkdco, void *data);
  326. typedef bool (*dss_hsdiv_calc_func)(int m_dispc, unsigned long dispc,
  327. void *data);
  328. int dss_pll_register(struct dss_pll *pll);
  329. void dss_pll_unregister(struct dss_pll *pll);
  330. struct dss_pll *dss_pll_find(const char *name);
  331. struct dss_pll *dss_pll_find_by_src(enum dss_clk_source src);
  332. unsigned dss_pll_get_clkout_idx_for_src(enum dss_clk_source src);
  333. int dss_pll_enable(struct dss_pll *pll);
  334. void dss_pll_disable(struct dss_pll *pll);
  335. int dss_pll_set_config(struct dss_pll *pll,
  336. const struct dss_pll_clock_info *cinfo);
  337. bool dss_pll_hsdiv_calc_a(const struct dss_pll *pll, unsigned long clkdco,
  338. unsigned long out_min, unsigned long out_max,
  339. dss_hsdiv_calc_func func, void *data);
  340. bool dss_pll_calc_a(const struct dss_pll *pll, unsigned long clkin,
  341. unsigned long pll_min, unsigned long pll_max,
  342. dss_pll_calc_func func, void *data);
  343. bool dss_pll_calc_b(const struct dss_pll *pll, unsigned long clkin,
  344. unsigned long target_clkout, struct dss_pll_clock_info *cinfo);
  345. int dss_pll_write_config_type_a(struct dss_pll *pll,
  346. const struct dss_pll_clock_info *cinfo);
  347. int dss_pll_write_config_type_b(struct dss_pll *pll,
  348. const struct dss_pll_clock_info *cinfo);
  349. int dss_pll_wait_reset_done(struct dss_pll *pll);
  350. #endif