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