dss.h 12 KB

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