dss.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  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. #ifdef pr_fmt
  26. #undef pr_fmt
  27. #endif
  28. #ifdef DSS_SUBSYS_NAME
  29. #define pr_fmt(fmt) DSS_SUBSYS_NAME ": " fmt
  30. #else
  31. #define pr_fmt(fmt) fmt
  32. #endif
  33. #define DSSDBG(format, ...) \
  34. pr_debug(format, ## __VA_ARGS__)
  35. #ifdef DSS_SUBSYS_NAME
  36. #define DSSERR(format, ...) \
  37. printk(KERN_ERR "omapdss " DSS_SUBSYS_NAME " error: " format, \
  38. ## __VA_ARGS__)
  39. #else
  40. #define DSSERR(format, ...) \
  41. printk(KERN_ERR "omapdss error: " format, ## __VA_ARGS__)
  42. #endif
  43. #ifdef DSS_SUBSYS_NAME
  44. #define DSSINFO(format, ...) \
  45. printk(KERN_INFO "omapdss " DSS_SUBSYS_NAME ": " format, \
  46. ## __VA_ARGS__)
  47. #else
  48. #define DSSINFO(format, ...) \
  49. printk(KERN_INFO "omapdss: " format, ## __VA_ARGS__)
  50. #endif
  51. #ifdef DSS_SUBSYS_NAME
  52. #define DSSWARN(format, ...) \
  53. printk(KERN_WARNING "omapdss " DSS_SUBSYS_NAME ": " format, \
  54. ## __VA_ARGS__)
  55. #else
  56. #define DSSWARN(format, ...) \
  57. printk(KERN_WARNING "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_io_pad_mode {
  67. DSS_IO_PAD_MODE_RESET,
  68. DSS_IO_PAD_MODE_RFBI,
  69. DSS_IO_PAD_MODE_BYPASS,
  70. };
  71. enum dss_hdmi_venc_clk_source_select {
  72. DSS_VENC_TV_CLK = 0,
  73. DSS_HDMI_M_PCLK = 1,
  74. };
  75. enum dss_dsi_content_type {
  76. DSS_DSI_CONTENT_DCS,
  77. DSS_DSI_CONTENT_GENERIC,
  78. };
  79. enum dss_writeback_channel {
  80. DSS_WB_LCD1_MGR = 0,
  81. DSS_WB_LCD2_MGR = 1,
  82. DSS_WB_TV_MGR = 2,
  83. DSS_WB_OVL0 = 3,
  84. DSS_WB_OVL1 = 4,
  85. DSS_WB_OVL2 = 5,
  86. DSS_WB_OVL3 = 6,
  87. DSS_WB_LCD3_MGR = 7,
  88. };
  89. enum dss_pll_id {
  90. DSS_PLL_DSI1,
  91. DSS_PLL_DSI2,
  92. DSS_PLL_HDMI,
  93. DSS_PLL_VIDEO1,
  94. DSS_PLL_VIDEO2,
  95. };
  96. struct dss_pll;
  97. #define DSS_PLL_MAX_HSDIVS 4
  98. /*
  99. * Type-A PLLs: clkout[]/mX[] refer to hsdiv outputs m4, m5, m6, m7.
  100. * Type-B PLLs: clkout[0] refers to m2.
  101. */
  102. struct dss_pll_clock_info {
  103. /* rates that we get with dividers below */
  104. unsigned long fint;
  105. unsigned long clkdco;
  106. unsigned long clkout[DSS_PLL_MAX_HSDIVS];
  107. /* dividers */
  108. u16 n;
  109. u16 m;
  110. u32 mf;
  111. u16 mX[DSS_PLL_MAX_HSDIVS];
  112. u16 sd;
  113. };
  114. struct dss_pll_ops {
  115. int (*enable)(struct dss_pll *pll);
  116. void (*disable)(struct dss_pll *pll);
  117. int (*set_config)(struct dss_pll *pll,
  118. const struct dss_pll_clock_info *cinfo);
  119. };
  120. struct dss_pll_hw {
  121. unsigned n_max;
  122. unsigned m_min;
  123. unsigned m_max;
  124. unsigned mX_max;
  125. unsigned long fint_min, fint_max;
  126. unsigned long clkdco_min, clkdco_low, clkdco_max;
  127. u8 n_msb, n_lsb;
  128. u8 m_msb, m_lsb;
  129. u8 mX_msb[DSS_PLL_MAX_HSDIVS], mX_lsb[DSS_PLL_MAX_HSDIVS];
  130. bool has_stopmode;
  131. bool has_freqsel;
  132. bool has_selfreqdco;
  133. bool has_refsel;
  134. };
  135. struct dss_pll {
  136. const char *name;
  137. enum dss_pll_id id;
  138. struct clk *clkin;
  139. struct regulator *regulator;
  140. void __iomem *base;
  141. const struct dss_pll_hw *hw;
  142. const struct dss_pll_ops *ops;
  143. struct dss_pll_clock_info cinfo;
  144. };
  145. struct dispc_clock_info {
  146. /* rates that we get with dividers below */
  147. unsigned long lck;
  148. unsigned long pck;
  149. /* dividers */
  150. u16 lck_div;
  151. u16 pck_div;
  152. };
  153. struct dss_lcd_mgr_config {
  154. enum dss_io_pad_mode io_pad_mode;
  155. bool stallmode;
  156. bool fifohandcheck;
  157. struct dispc_clock_info clock_info;
  158. int video_port_width;
  159. int lcden_sig_polarity;
  160. };
  161. struct seq_file;
  162. struct platform_device;
  163. /* core */
  164. struct platform_device *dss_get_core_pdev(void);
  165. int dss_dsi_enable_pads(int dsi_id, unsigned lane_mask);
  166. void dss_dsi_disable_pads(int dsi_id, unsigned lane_mask);
  167. int dss_set_min_bus_tput(struct device *dev, unsigned long tput);
  168. int dss_debugfs_create_file(const char *name, void (*write)(struct seq_file *));
  169. /* display */
  170. int dss_suspend_all_devices(void);
  171. int dss_resume_all_devices(void);
  172. void dss_disable_all_devices(void);
  173. int display_init_sysfs(struct platform_device *pdev);
  174. void display_uninit_sysfs(struct platform_device *pdev);
  175. /* manager */
  176. int dss_init_overlay_managers(void);
  177. void dss_uninit_overlay_managers(void);
  178. int dss_init_overlay_managers_sysfs(struct platform_device *pdev);
  179. void dss_uninit_overlay_managers_sysfs(struct platform_device *pdev);
  180. int dss_mgr_simple_check(struct omap_overlay_manager *mgr,
  181. const struct omap_overlay_manager_info *info);
  182. int dss_mgr_check_timings(struct omap_overlay_manager *mgr,
  183. const struct omap_video_timings *timings);
  184. int dss_mgr_check(struct omap_overlay_manager *mgr,
  185. struct omap_overlay_manager_info *info,
  186. const struct omap_video_timings *mgr_timings,
  187. const struct dss_lcd_mgr_config *config,
  188. struct omap_overlay_info **overlay_infos);
  189. static inline bool dss_mgr_is_lcd(enum omap_channel id)
  190. {
  191. if (id == OMAP_DSS_CHANNEL_LCD || id == OMAP_DSS_CHANNEL_LCD2 ||
  192. id == OMAP_DSS_CHANNEL_LCD3)
  193. return true;
  194. else
  195. return false;
  196. }
  197. int dss_manager_kobj_init(struct omap_overlay_manager *mgr,
  198. struct platform_device *pdev);
  199. void dss_manager_kobj_uninit(struct omap_overlay_manager *mgr);
  200. /* overlay */
  201. void dss_init_overlays(struct platform_device *pdev);
  202. void dss_uninit_overlays(struct platform_device *pdev);
  203. void dss_overlay_setup_dispc_manager(struct omap_overlay_manager *mgr);
  204. int dss_ovl_simple_check(struct omap_overlay *ovl,
  205. const struct omap_overlay_info *info);
  206. int dss_ovl_check(struct omap_overlay *ovl, struct omap_overlay_info *info,
  207. const struct omap_video_timings *mgr_timings);
  208. bool dss_ovl_use_replication(struct dss_lcd_mgr_config config,
  209. enum omap_color_mode mode);
  210. int dss_overlay_kobj_init(struct omap_overlay *ovl,
  211. struct platform_device *pdev);
  212. void dss_overlay_kobj_uninit(struct omap_overlay *ovl);
  213. /* DSS */
  214. int dss_init_platform_driver(void) __init;
  215. void dss_uninit_platform_driver(void);
  216. int dss_runtime_get(void);
  217. void dss_runtime_put(void);
  218. unsigned long dss_get_dispc_clk_rate(void);
  219. int dss_dpi_select_source(int port, enum omap_channel channel);
  220. void dss_select_hdmi_venc_clk_source(enum dss_hdmi_venc_clk_source_select);
  221. enum dss_hdmi_venc_clk_source_select dss_get_hdmi_venc_clk_source(void);
  222. const char *dss_get_generic_clk_source_name(enum omap_dss_clk_source clk_src);
  223. void dss_dump_clocks(struct seq_file *s);
  224. /* DSS VIDEO PLL */
  225. struct dss_pll *dss_video_pll_init(struct platform_device *pdev, int id,
  226. struct regulator *regulator);
  227. void dss_video_pll_uninit(struct dss_pll *pll);
  228. /* dss-of */
  229. struct device_node *dss_of_port_get_parent_device(struct device_node *port);
  230. u32 dss_of_port_get_port_number(struct device_node *port);
  231. #if defined(CONFIG_OMAP2_DSS_DEBUGFS)
  232. void dss_debug_dump_clocks(struct seq_file *s);
  233. #endif
  234. void dss_ctrl_pll_enable(enum dss_pll_id pll_id, bool enable);
  235. void dss_ctrl_pll_set_control_mux(enum dss_pll_id pll_id,
  236. enum omap_channel channel);
  237. void dss_sdi_init(int datapairs);
  238. int dss_sdi_enable(void);
  239. void dss_sdi_disable(void);
  240. void dss_select_dsi_clk_source(int dsi_module,
  241. enum omap_dss_clk_source clk_src);
  242. void dss_select_lcd_clk_source(enum omap_channel channel,
  243. enum omap_dss_clk_source clk_src);
  244. enum omap_dss_clk_source dss_get_dispc_clk_source(void);
  245. enum omap_dss_clk_source dss_get_dsi_clk_source(int dsi_module);
  246. enum omap_dss_clk_source dss_get_lcd_clk_source(enum omap_channel channel);
  247. void dss_set_venc_output(enum omap_dss_venc_type type);
  248. void dss_set_dac_pwrdn_bgz(bool enable);
  249. int dss_set_fck_rate(unsigned long rate);
  250. typedef bool (*dss_div_calc_func)(unsigned long fck, void *data);
  251. bool dss_div_calc(unsigned long pck, unsigned long fck_min,
  252. dss_div_calc_func func, void *data);
  253. /* SDI */
  254. int sdi_init_platform_driver(void) __init;
  255. void sdi_uninit_platform_driver(void);
  256. #ifdef CONFIG_OMAP2_DSS_SDI
  257. int sdi_init_port(struct platform_device *pdev, struct device_node *port);
  258. void sdi_uninit_port(struct device_node *port);
  259. #else
  260. static inline int sdi_init_port(struct platform_device *pdev,
  261. struct device_node *port)
  262. {
  263. return 0;
  264. }
  265. static inline void sdi_uninit_port(struct device_node *port)
  266. {
  267. }
  268. #endif
  269. /* DSI */
  270. #ifdef CONFIG_OMAP2_DSS_DSI
  271. struct dentry;
  272. struct file_operations;
  273. int dsi_init_platform_driver(void) __init;
  274. void dsi_uninit_platform_driver(void);
  275. void dsi_dump_clocks(struct seq_file *s);
  276. void dsi_irq_handler(void);
  277. u8 dsi_get_pixel_size(enum omap_dss_dsi_pixel_format fmt);
  278. #else
  279. static inline u8 dsi_get_pixel_size(enum omap_dss_dsi_pixel_format fmt)
  280. {
  281. WARN("%s: DSI not compiled in, returning pixel_size as 0\n", __func__);
  282. return 0;
  283. }
  284. #endif
  285. /* DPI */
  286. int dpi_init_platform_driver(void) __init;
  287. void dpi_uninit_platform_driver(void);
  288. #ifdef CONFIG_OMAP2_DSS_DPI
  289. int dpi_init_port(struct platform_device *pdev, struct device_node *port);
  290. void dpi_uninit_port(struct device_node *port);
  291. #else
  292. static inline int dpi_init_port(struct platform_device *pdev,
  293. struct device_node *port)
  294. {
  295. return 0;
  296. }
  297. static inline void dpi_uninit_port(struct device_node *port)
  298. {
  299. }
  300. #endif
  301. /* DISPC */
  302. int dispc_init_platform_driver(void) __init;
  303. void dispc_uninit_platform_driver(void);
  304. void dispc_dump_clocks(struct seq_file *s);
  305. void dispc_enable_sidle(void);
  306. void dispc_disable_sidle(void);
  307. void dispc_lcd_enable_signal(bool enable);
  308. void dispc_pck_free_enable(bool enable);
  309. void dispc_enable_fifomerge(bool enable);
  310. void dispc_enable_gamma_table(bool enable);
  311. void dispc_set_loadmode(enum omap_dss_load_mode mode);
  312. typedef bool (*dispc_div_calc_func)(int lckd, int pckd, unsigned long lck,
  313. unsigned long pck, void *data);
  314. bool dispc_div_calc(unsigned long dispc,
  315. unsigned long pck_min, unsigned long pck_max,
  316. dispc_div_calc_func func, void *data);
  317. bool dispc_mgr_timings_ok(enum omap_channel channel,
  318. const struct omap_video_timings *timings);
  319. unsigned long dispc_fclk_rate(void);
  320. int dispc_calc_clock_rates(unsigned long dispc_fclk_rate,
  321. struct dispc_clock_info *cinfo);
  322. void dispc_ovl_set_fifo_threshold(enum omap_plane plane, u32 low, u32 high);
  323. void dispc_ovl_compute_fifo_thresholds(enum omap_plane plane,
  324. u32 *fifo_low, u32 *fifo_high, bool use_fifomerge,
  325. bool manual_update);
  326. unsigned long dispc_mgr_lclk_rate(enum omap_channel channel);
  327. unsigned long dispc_mgr_pclk_rate(enum omap_channel channel);
  328. unsigned long dispc_core_clk_rate(void);
  329. void dispc_mgr_set_clock_div(enum omap_channel channel,
  330. const struct dispc_clock_info *cinfo);
  331. int dispc_mgr_get_clock_div(enum omap_channel channel,
  332. struct dispc_clock_info *cinfo);
  333. void dispc_set_tv_pclk(unsigned long pclk);
  334. u32 dispc_wb_get_framedone_irq(void);
  335. bool dispc_wb_go_busy(void);
  336. void dispc_wb_go(void);
  337. void dispc_wb_enable(bool enable);
  338. bool dispc_wb_is_enabled(void);
  339. void dispc_wb_set_channel_in(enum dss_writeback_channel channel);
  340. int dispc_wb_setup(const struct omap_dss_writeback_info *wi,
  341. bool mem_to_mem, const struct omap_video_timings *timings);
  342. /* VENC */
  343. int venc_init_platform_driver(void) __init;
  344. void venc_uninit_platform_driver(void);
  345. /* HDMI */
  346. int hdmi4_init_platform_driver(void) __init;
  347. void hdmi4_uninit_platform_driver(void);
  348. int hdmi5_init_platform_driver(void) __init;
  349. void hdmi5_uninit_platform_driver(void);
  350. /* RFBI */
  351. int rfbi_init_platform_driver(void) __init;
  352. void rfbi_uninit_platform_driver(void);
  353. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  354. static inline void dss_collect_irq_stats(u32 irqstatus, unsigned *irq_arr)
  355. {
  356. int b;
  357. for (b = 0; b < 32; ++b) {
  358. if (irqstatus & (1 << b))
  359. irq_arr[b]++;
  360. }
  361. }
  362. #endif
  363. /* PLL */
  364. typedef bool (*dss_pll_calc_func)(int n, int m, unsigned long fint,
  365. unsigned long clkdco, void *data);
  366. typedef bool (*dss_hsdiv_calc_func)(int m_dispc, unsigned long dispc,
  367. void *data);
  368. int dss_pll_register(struct dss_pll *pll);
  369. void dss_pll_unregister(struct dss_pll *pll);
  370. struct dss_pll *dss_pll_find(const char *name);
  371. int dss_pll_enable(struct dss_pll *pll);
  372. void dss_pll_disable(struct dss_pll *pll);
  373. int dss_pll_set_config(struct dss_pll *pll,
  374. const struct dss_pll_clock_info *cinfo);
  375. bool dss_pll_hsdiv_calc(const struct dss_pll *pll, unsigned long clkdco,
  376. unsigned long out_min, unsigned long out_max,
  377. dss_hsdiv_calc_func func, void *data);
  378. bool dss_pll_calc(const struct dss_pll *pll, unsigned long clkin,
  379. unsigned long pll_min, unsigned long pll_max,
  380. dss_pll_calc_func func, void *data);
  381. int dss_pll_write_config_type_a(struct dss_pll *pll,
  382. const struct dss_pll_clock_info *cinfo);
  383. int dss_pll_write_config_type_b(struct dss_pll *pll,
  384. const struct dss_pll_clock_info *cinfo);
  385. int dss_pll_wait_reset_done(struct dss_pll *pll);
  386. #endif