dss.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  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_pll_id {
  91. DSS_PLL_DSI1,
  92. DSS_PLL_DSI2,
  93. DSS_PLL_HDMI,
  94. DSS_PLL_VIDEO1,
  95. DSS_PLL_VIDEO2,
  96. };
  97. struct dss_pll;
  98. #define DSS_PLL_MAX_HSDIVS 4
  99. /*
  100. * Type-A PLLs: clkout[]/mX[] refer to hsdiv outputs m4, m5, m6, m7.
  101. * Type-B PLLs: clkout[0] refers to m2.
  102. */
  103. struct dss_pll_clock_info {
  104. /* rates that we get with dividers below */
  105. unsigned long fint;
  106. unsigned long clkdco;
  107. unsigned long clkout[DSS_PLL_MAX_HSDIVS];
  108. /* dividers */
  109. u16 n;
  110. u16 m;
  111. u32 mf;
  112. u16 mX[DSS_PLL_MAX_HSDIVS];
  113. u16 sd;
  114. };
  115. struct dss_pll_ops {
  116. int (*enable)(struct dss_pll *pll);
  117. void (*disable)(struct dss_pll *pll);
  118. int (*set_config)(struct dss_pll *pll,
  119. const struct dss_pll_clock_info *cinfo);
  120. };
  121. struct dss_pll_hw {
  122. unsigned n_max;
  123. unsigned m_min;
  124. unsigned m_max;
  125. unsigned mX_max;
  126. unsigned long fint_min, fint_max;
  127. unsigned long clkdco_min, clkdco_low, clkdco_max;
  128. u8 n_msb, n_lsb;
  129. u8 m_msb, m_lsb;
  130. u8 mX_msb[DSS_PLL_MAX_HSDIVS], mX_lsb[DSS_PLL_MAX_HSDIVS];
  131. bool has_stopmode;
  132. bool has_freqsel;
  133. bool has_selfreqdco;
  134. bool has_refsel;
  135. };
  136. struct dss_pll {
  137. const char *name;
  138. enum dss_pll_id id;
  139. struct clk *clkin;
  140. struct regulator *regulator;
  141. void __iomem *base;
  142. const struct dss_pll_hw *hw;
  143. const struct dss_pll_ops *ops;
  144. struct dss_pll_clock_info cinfo;
  145. };
  146. struct dispc_clock_info {
  147. /* rates that we get with dividers below */
  148. unsigned long lck;
  149. unsigned long pck;
  150. /* dividers */
  151. u16 lck_div;
  152. u16 pck_div;
  153. };
  154. struct dss_lcd_mgr_config {
  155. enum dss_io_pad_mode io_pad_mode;
  156. bool stallmode;
  157. bool fifohandcheck;
  158. struct dispc_clock_info clock_info;
  159. int video_port_width;
  160. int lcden_sig_polarity;
  161. };
  162. struct seq_file;
  163. struct platform_device;
  164. /* core */
  165. struct platform_device *dss_get_core_pdev(void);
  166. int dss_dsi_enable_pads(int dsi_id, unsigned lane_mask);
  167. void dss_dsi_disable_pads(int dsi_id, unsigned lane_mask);
  168. int dss_set_min_bus_tput(struct device *dev, unsigned long tput);
  169. int dss_debugfs_create_file(const char *name, void (*write)(struct seq_file *));
  170. static inline bool dss_mgr_is_lcd(enum omap_channel id)
  171. {
  172. if (id == OMAP_DSS_CHANNEL_LCD || id == OMAP_DSS_CHANNEL_LCD2 ||
  173. id == OMAP_DSS_CHANNEL_LCD3)
  174. return true;
  175. else
  176. return false;
  177. }
  178. /* DSS */
  179. int dss_init_platform_driver(void) __init;
  180. void dss_uninit_platform_driver(void);
  181. int dss_runtime_get(void);
  182. void dss_runtime_put(void);
  183. unsigned long dss_get_dispc_clk_rate(void);
  184. int dss_dpi_select_source(int port, enum omap_channel channel);
  185. void dss_select_hdmi_venc_clk_source(enum dss_hdmi_venc_clk_source_select);
  186. enum dss_hdmi_venc_clk_source_select dss_get_hdmi_venc_clk_source(void);
  187. const char *dss_get_generic_clk_source_name(enum omap_dss_clk_source clk_src);
  188. void dss_dump_clocks(struct seq_file *s);
  189. /* DSS VIDEO PLL */
  190. struct dss_pll *dss_video_pll_init(struct platform_device *pdev, int id,
  191. struct regulator *regulator);
  192. void dss_video_pll_uninit(struct dss_pll *pll);
  193. /* dss-of */
  194. struct device_node *dss_of_port_get_parent_device(struct device_node *port);
  195. u32 dss_of_port_get_port_number(struct device_node *port);
  196. #if defined(CONFIG_OMAP2_DSS_DEBUGFS)
  197. void dss_debug_dump_clocks(struct seq_file *s);
  198. #endif
  199. void dss_ctrl_pll_enable(enum dss_pll_id pll_id, bool enable);
  200. void dss_ctrl_pll_set_control_mux(enum dss_pll_id pll_id,
  201. enum omap_channel channel);
  202. void dss_sdi_init(int datapairs);
  203. int dss_sdi_enable(void);
  204. void dss_sdi_disable(void);
  205. void dss_select_dsi_clk_source(int dsi_module,
  206. enum omap_dss_clk_source clk_src);
  207. void dss_select_lcd_clk_source(enum omap_channel channel,
  208. enum omap_dss_clk_source clk_src);
  209. enum omap_dss_clk_source dss_get_dispc_clk_source(void);
  210. enum omap_dss_clk_source dss_get_dsi_clk_source(int dsi_module);
  211. enum omap_dss_clk_source dss_get_lcd_clk_source(enum omap_channel channel);
  212. void dss_set_venc_output(enum omap_dss_venc_type type);
  213. void dss_set_dac_pwrdn_bgz(bool enable);
  214. int dss_set_fck_rate(unsigned long rate);
  215. typedef bool (*dss_div_calc_func)(unsigned long fck, void *data);
  216. bool dss_div_calc(unsigned long pck, unsigned long fck_min,
  217. dss_div_calc_func func, void *data);
  218. /* SDI */
  219. int sdi_init_platform_driver(void) __init;
  220. void sdi_uninit_platform_driver(void);
  221. #ifdef CONFIG_OMAP2_DSS_SDI
  222. int sdi_init_port(struct platform_device *pdev, struct device_node *port);
  223. void sdi_uninit_port(struct device_node *port);
  224. #else
  225. static inline int sdi_init_port(struct platform_device *pdev,
  226. struct device_node *port)
  227. {
  228. return 0;
  229. }
  230. static inline void sdi_uninit_port(struct device_node *port)
  231. {
  232. }
  233. #endif
  234. /* DSI */
  235. #ifdef CONFIG_OMAP2_DSS_DSI
  236. struct dentry;
  237. struct file_operations;
  238. int dsi_init_platform_driver(void) __init;
  239. void dsi_uninit_platform_driver(void);
  240. void dsi_dump_clocks(struct seq_file *s);
  241. void dsi_irq_handler(void);
  242. u8 dsi_get_pixel_size(enum omap_dss_dsi_pixel_format fmt);
  243. #else
  244. static inline u8 dsi_get_pixel_size(enum omap_dss_dsi_pixel_format fmt)
  245. {
  246. WARN(1, "%s: DSI not compiled in, returning pixel_size as 0\n",
  247. __func__);
  248. return 0;
  249. }
  250. #endif
  251. /* DPI */
  252. int dpi_init_platform_driver(void) __init;
  253. void dpi_uninit_platform_driver(void);
  254. #ifdef CONFIG_OMAP2_DSS_DPI
  255. int dpi_init_port(struct platform_device *pdev, struct device_node *port);
  256. void dpi_uninit_port(struct device_node *port);
  257. #else
  258. static inline int dpi_init_port(struct platform_device *pdev,
  259. struct device_node *port)
  260. {
  261. return 0;
  262. }
  263. static inline void dpi_uninit_port(struct device_node *port)
  264. {
  265. }
  266. #endif
  267. /* DISPC */
  268. int dispc_init_platform_driver(void) __init;
  269. void dispc_uninit_platform_driver(void);
  270. void dispc_dump_clocks(struct seq_file *s);
  271. void dispc_enable_sidle(void);
  272. void dispc_disable_sidle(void);
  273. void dispc_lcd_enable_signal(bool enable);
  274. void dispc_pck_free_enable(bool enable);
  275. void dispc_enable_fifomerge(bool enable);
  276. void dispc_enable_gamma_table(bool enable);
  277. typedef bool (*dispc_div_calc_func)(int lckd, int pckd, unsigned long lck,
  278. unsigned long pck, void *data);
  279. bool dispc_div_calc(unsigned long dispc,
  280. unsigned long pck_min, unsigned long pck_max,
  281. dispc_div_calc_func func, void *data);
  282. bool dispc_mgr_timings_ok(enum omap_channel channel,
  283. const struct omap_video_timings *timings);
  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 plane, u32 low, u32 high);
  287. void dispc_ovl_compute_fifo_thresholds(enum omap_plane plane,
  288. u32 *fifo_low, u32 *fifo_high, bool use_fifomerge,
  289. bool manual_update);
  290. void dispc_mgr_set_clock_div(enum omap_channel channel,
  291. const struct dispc_clock_info *cinfo);
  292. int dispc_mgr_get_clock_div(enum omap_channel channel,
  293. struct dispc_clock_info *cinfo);
  294. void dispc_set_tv_pclk(unsigned long pclk);
  295. u32 dispc_wb_get_framedone_irq(void);
  296. bool dispc_wb_go_busy(void);
  297. void dispc_wb_go(void);
  298. void dispc_wb_enable(bool enable);
  299. bool dispc_wb_is_enabled(void);
  300. void dispc_wb_set_channel_in(enum dss_writeback_channel channel);
  301. int dispc_wb_setup(const struct omap_dss_writeback_info *wi,
  302. bool mem_to_mem, const struct omap_video_timings *timings);
  303. /* VENC */
  304. int venc_init_platform_driver(void) __init;
  305. void venc_uninit_platform_driver(void);
  306. /* HDMI */
  307. int hdmi4_init_platform_driver(void) __init;
  308. void hdmi4_uninit_platform_driver(void);
  309. int hdmi5_init_platform_driver(void) __init;
  310. void hdmi5_uninit_platform_driver(void);
  311. /* RFBI */
  312. int rfbi_init_platform_driver(void) __init;
  313. void rfbi_uninit_platform_driver(void);
  314. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  315. static inline void dss_collect_irq_stats(u32 irqstatus, unsigned *irq_arr)
  316. {
  317. int b;
  318. for (b = 0; b < 32; ++b) {
  319. if (irqstatus & (1 << b))
  320. irq_arr[b]++;
  321. }
  322. }
  323. #endif
  324. /* PLL */
  325. typedef bool (*dss_pll_calc_func)(int n, int m, unsigned long fint,
  326. unsigned long clkdco, void *data);
  327. typedef bool (*dss_hsdiv_calc_func)(int m_dispc, unsigned long dispc,
  328. void *data);
  329. int dss_pll_register(struct dss_pll *pll);
  330. void dss_pll_unregister(struct dss_pll *pll);
  331. struct dss_pll *dss_pll_find(const char *name);
  332. int dss_pll_enable(struct dss_pll *pll);
  333. void dss_pll_disable(struct dss_pll *pll);
  334. int dss_pll_set_config(struct dss_pll *pll,
  335. const struct dss_pll_clock_info *cinfo);
  336. bool dss_pll_hsdiv_calc(const struct dss_pll *pll, unsigned long clkdco,
  337. unsigned long out_min, unsigned long out_max,
  338. dss_hsdiv_calc_func func, void *data);
  339. bool dss_pll_calc(const struct dss_pll *pll, unsigned long clkin,
  340. unsigned long pll_min, unsigned long pll_max,
  341. dss_pll_calc_func func, void *data);
  342. int dss_pll_write_config_type_a(struct dss_pll *pll,
  343. const struct dss_pll_clock_info *cinfo);
  344. int dss_pll_write_config_type_b(struct dss_pll *pll,
  345. const struct dss_pll_clock_info *cinfo);
  346. int dss_pll_wait_reset_done(struct dss_pll *pll);
  347. #endif