dss.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. /*
  2. * Copyright (C) 2009 Nokia Corporation
  3. * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
  4. *
  5. * Some code and ideas taken from drivers/video/omap/ driver
  6. * by Imre Deak.
  7. *
  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.
  11. *
  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
  15. * more details.
  16. *
  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/>.
  19. */
  20. #ifndef __OMAP2_DSS_H
  21. #define __OMAP2_DSS_H
  22. #include <linux/interrupt.h>
  23. #include "omapdss.h"
  24. #define MAX_DSS_LCD_MANAGERS 3
  25. #define MAX_NUM_DSI 2
  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_model {
  65. DSS_MODEL_OMAP2,
  66. DSS_MODEL_OMAP3,
  67. DSS_MODEL_OMAP4,
  68. DSS_MODEL_OMAP5,
  69. DSS_MODEL_DRA7,
  70. };
  71. enum dss_io_pad_mode {
  72. DSS_IO_PAD_MODE_RESET,
  73. DSS_IO_PAD_MODE_RFBI,
  74. DSS_IO_PAD_MODE_BYPASS,
  75. };
  76. enum dss_hdmi_venc_clk_source_select {
  77. DSS_VENC_TV_CLK = 0,
  78. DSS_HDMI_M_PCLK = 1,
  79. };
  80. enum dss_dsi_content_type {
  81. DSS_DSI_CONTENT_DCS,
  82. DSS_DSI_CONTENT_GENERIC,
  83. };
  84. enum dss_writeback_channel {
  85. DSS_WB_LCD1_MGR = 0,
  86. DSS_WB_LCD2_MGR = 1,
  87. DSS_WB_TV_MGR = 2,
  88. DSS_WB_OVL0 = 3,
  89. DSS_WB_OVL1 = 4,
  90. DSS_WB_OVL2 = 5,
  91. DSS_WB_OVL3 = 6,
  92. DSS_WB_LCD3_MGR = 7,
  93. };
  94. enum dss_clk_source {
  95. DSS_CLK_SRC_FCK = 0,
  96. DSS_CLK_SRC_PLL1_1,
  97. DSS_CLK_SRC_PLL1_2,
  98. DSS_CLK_SRC_PLL1_3,
  99. DSS_CLK_SRC_PLL2_1,
  100. DSS_CLK_SRC_PLL2_2,
  101. DSS_CLK_SRC_PLL2_3,
  102. DSS_CLK_SRC_HDMI_PLL,
  103. };
  104. enum dss_pll_id {
  105. DSS_PLL_DSI1,
  106. DSS_PLL_DSI2,
  107. DSS_PLL_HDMI,
  108. DSS_PLL_VIDEO1,
  109. DSS_PLL_VIDEO2,
  110. };
  111. struct dss_pll;
  112. #define DSS_PLL_MAX_HSDIVS 4
  113. enum dss_pll_type {
  114. DSS_PLL_TYPE_A,
  115. DSS_PLL_TYPE_B,
  116. };
  117. /*
  118. * Type-A PLLs: clkout[]/mX[] refer to hsdiv outputs m4, m5, m6, m7.
  119. * Type-B PLLs: clkout[0] refers to m2.
  120. */
  121. struct dss_pll_clock_info {
  122. /* rates that we get with dividers below */
  123. unsigned long fint;
  124. unsigned long clkdco;
  125. unsigned long clkout[DSS_PLL_MAX_HSDIVS];
  126. /* dividers */
  127. u16 n;
  128. u16 m;
  129. u32 mf;
  130. u16 mX[DSS_PLL_MAX_HSDIVS];
  131. u16 sd;
  132. };
  133. struct dss_pll_ops {
  134. int (*enable)(struct dss_pll *pll);
  135. void (*disable)(struct dss_pll *pll);
  136. int (*set_config)(struct dss_pll *pll,
  137. const struct dss_pll_clock_info *cinfo);
  138. };
  139. struct dss_pll_hw {
  140. enum dss_pll_type type;
  141. unsigned n_max;
  142. unsigned m_min;
  143. unsigned m_max;
  144. unsigned mX_max;
  145. unsigned long fint_min, fint_max;
  146. unsigned long clkdco_min, clkdco_low, clkdco_max;
  147. u8 n_msb, n_lsb;
  148. u8 m_msb, m_lsb;
  149. u8 mX_msb[DSS_PLL_MAX_HSDIVS], mX_lsb[DSS_PLL_MAX_HSDIVS];
  150. bool has_stopmode;
  151. bool has_freqsel;
  152. bool has_selfreqdco;
  153. bool has_refsel;
  154. /* DRA7 errata i886: use high N & M to avoid jitter */
  155. bool errata_i886;
  156. };
  157. struct dss_pll {
  158. const char *name;
  159. enum dss_pll_id id;
  160. struct clk *clkin;
  161. struct regulator *regulator;
  162. void __iomem *base;
  163. const struct dss_pll_hw *hw;
  164. const struct dss_pll_ops *ops;
  165. struct dss_pll_clock_info cinfo;
  166. };
  167. /* Defines a generic omap register field */
  168. struct dss_reg_field {
  169. u8 start, end;
  170. };
  171. struct dispc_clock_info {
  172. /* rates that we get with dividers below */
  173. unsigned long lck;
  174. unsigned long pck;
  175. /* dividers */
  176. u16 lck_div;
  177. u16 pck_div;
  178. };
  179. struct dss_lcd_mgr_config {
  180. enum dss_io_pad_mode io_pad_mode;
  181. bool stallmode;
  182. bool fifohandcheck;
  183. struct dispc_clock_info clock_info;
  184. int video_port_width;
  185. int lcden_sig_polarity;
  186. };
  187. struct seq_file;
  188. struct platform_device;
  189. /* core */
  190. static inline int dss_set_min_bus_tput(struct device *dev, unsigned long tput)
  191. {
  192. /* To be implemented when the OMAP platform will provide this feature */
  193. return 0;
  194. }
  195. static inline bool dss_mgr_is_lcd(enum omap_channel id)
  196. {
  197. if (id == OMAP_DSS_CHANNEL_LCD || id == OMAP_DSS_CHANNEL_LCD2 ||
  198. id == OMAP_DSS_CHANNEL_LCD3)
  199. return true;
  200. else
  201. return false;
  202. }
  203. /* DSS */
  204. #if defined(CONFIG_OMAP2_DSS_DEBUGFS)
  205. int dss_debugfs_create_file(const char *name, void (*write)(struct seq_file *));
  206. #else
  207. static inline int dss_debugfs_create_file(const char *name,
  208. void (*write)(struct seq_file *))
  209. {
  210. return 0;
  211. }
  212. #endif /* CONFIG_OMAP2_DSS_DEBUGFS */
  213. int dss_runtime_get(void);
  214. void dss_runtime_put(void);
  215. unsigned long dss_get_dispc_clk_rate(void);
  216. unsigned long dss_get_max_fck_rate(void);
  217. enum omap_dss_output_id dss_get_supported_outputs(enum omap_channel channel);
  218. int dss_dpi_select_source(int port, enum omap_channel channel);
  219. void dss_select_hdmi_venc_clk_source(enum dss_hdmi_venc_clk_source_select);
  220. enum dss_hdmi_venc_clk_source_select dss_get_hdmi_venc_clk_source(void);
  221. const char *dss_get_clk_source_name(enum dss_clk_source clk_src);
  222. /* DSS VIDEO PLL */
  223. struct dss_pll *dss_video_pll_init(struct platform_device *pdev, int id,
  224. struct regulator *regulator);
  225. void dss_video_pll_uninit(struct dss_pll *pll);
  226. void dss_ctrl_pll_enable(enum dss_pll_id pll_id, bool enable);
  227. void dss_sdi_init(int datapairs);
  228. int dss_sdi_enable(void);
  229. void dss_sdi_disable(void);
  230. void dss_select_dsi_clk_source(int dsi_module,
  231. enum dss_clk_source clk_src);
  232. void dss_select_lcd_clk_source(enum omap_channel channel,
  233. enum dss_clk_source clk_src);
  234. enum dss_clk_source dss_get_dispc_clk_source(void);
  235. enum dss_clk_source dss_get_dsi_clk_source(int dsi_module);
  236. enum dss_clk_source dss_get_lcd_clk_source(enum omap_channel channel);
  237. void dss_set_venc_output(enum omap_dss_venc_type type);
  238. void dss_set_dac_pwrdn_bgz(bool enable);
  239. int dss_set_fck_rate(unsigned long rate);
  240. typedef bool (*dss_div_calc_func)(unsigned long fck, void *data);
  241. bool dss_div_calc(unsigned long pck, unsigned long fck_min,
  242. dss_div_calc_func func, void *data);
  243. /* SDI */
  244. #ifdef CONFIG_OMAP2_DSS_SDI
  245. int sdi_init_port(struct platform_device *pdev, struct device_node *port);
  246. void sdi_uninit_port(struct device_node *port);
  247. #else
  248. static inline int sdi_init_port(struct platform_device *pdev,
  249. struct device_node *port)
  250. {
  251. return 0;
  252. }
  253. static inline void sdi_uninit_port(struct device_node *port)
  254. {
  255. }
  256. #endif
  257. /* DSI */
  258. #ifdef CONFIG_OMAP2_DSS_DSI
  259. struct dentry;
  260. struct file_operations;
  261. void dsi_dump_clocks(struct seq_file *s);
  262. void dsi_irq_handler(void);
  263. #endif
  264. /* DPI */
  265. #ifdef CONFIG_OMAP2_DSS_DPI
  266. int dpi_init_port(struct platform_device *pdev, struct device_node *port,
  267. enum dss_model dss_model);
  268. void dpi_uninit_port(struct device_node *port);
  269. #else
  270. static inline int dpi_init_port(struct platform_device *pdev,
  271. struct device_node *port, enum dss_model dss_model)
  272. {
  273. return 0;
  274. }
  275. static inline void dpi_uninit_port(struct device_node *port)
  276. {
  277. }
  278. #endif
  279. /* DISPC */
  280. void dispc_dump_clocks(struct seq_file *s);
  281. int dispc_runtime_get(void);
  282. void dispc_runtime_put(void);
  283. void dispc_enable_sidle(void);
  284. void dispc_disable_sidle(void);
  285. void dispc_lcd_enable_signal(bool enable);
  286. void dispc_pck_free_enable(bool enable);
  287. void dispc_enable_fifomerge(bool enable);
  288. void dispc_enable_gamma_table(bool enable);
  289. typedef bool (*dispc_div_calc_func)(int lckd, int pckd, unsigned long lck,
  290. unsigned long pck, void *data);
  291. bool dispc_div_calc(unsigned long dispc,
  292. unsigned long pck_min, unsigned long pck_max,
  293. dispc_div_calc_func func, void *data);
  294. bool dispc_mgr_timings_ok(enum omap_channel channel, const struct videomode *vm);
  295. int dispc_calc_clock_rates(unsigned long dispc_fclk_rate,
  296. struct dispc_clock_info *cinfo);
  297. void dispc_ovl_set_fifo_threshold(enum omap_plane_id plane, u32 low,
  298. u32 high);
  299. void dispc_ovl_compute_fifo_thresholds(enum omap_plane_id plane,
  300. u32 *fifo_low, u32 *fifo_high, bool use_fifomerge,
  301. bool manual_update);
  302. void dispc_mgr_set_clock_div(enum omap_channel channel,
  303. const struct dispc_clock_info *cinfo);
  304. int dispc_mgr_get_clock_div(enum omap_channel channel,
  305. struct dispc_clock_info *cinfo);
  306. void dispc_set_tv_pclk(unsigned long pclk);
  307. u32 dispc_wb_get_framedone_irq(void);
  308. bool dispc_wb_go_busy(void);
  309. void dispc_wb_go(void);
  310. void dispc_wb_set_channel_in(enum dss_writeback_channel channel);
  311. int dispc_wb_setup(const struct omap_dss_writeback_info *wi,
  312. bool mem_to_mem, const struct videomode *vm);
  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. extern struct platform_driver omap_dsshw_driver;
  351. extern struct platform_driver omap_dispchw_driver;
  352. #ifdef CONFIG_OMAP2_DSS_DSI
  353. extern struct platform_driver omap_dsihw_driver;
  354. #endif
  355. #ifdef CONFIG_OMAP2_DSS_VENC
  356. extern struct platform_driver omap_venchw_driver;
  357. #endif
  358. #ifdef CONFIG_OMAP4_DSS_HDMI
  359. extern struct platform_driver omapdss_hdmi4hw_driver;
  360. #endif
  361. #ifdef CONFIG_OMAP5_DSS_HDMI
  362. extern struct platform_driver omapdss_hdmi5hw_driver;
  363. #endif
  364. #endif