dss.h 11 KB

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