dss.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  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. struct dss_debugfs_entry;
  25. struct platform_device;
  26. struct seq_file;
  27. #define MAX_DSS_LCD_MANAGERS 3
  28. #define MAX_NUM_DSI 2
  29. #ifdef pr_fmt
  30. #undef pr_fmt
  31. #endif
  32. #ifdef DSS_SUBSYS_NAME
  33. #define pr_fmt(fmt) DSS_SUBSYS_NAME ": " fmt
  34. #else
  35. #define pr_fmt(fmt) fmt
  36. #endif
  37. #define DSSDBG(format, ...) \
  38. pr_debug(format, ## __VA_ARGS__)
  39. #ifdef DSS_SUBSYS_NAME
  40. #define DSSERR(format, ...) \
  41. pr_err("omapdss " DSS_SUBSYS_NAME " error: " format, ##__VA_ARGS__)
  42. #else
  43. #define DSSERR(format, ...) \
  44. pr_err("omapdss error: " format, ##__VA_ARGS__)
  45. #endif
  46. #ifdef DSS_SUBSYS_NAME
  47. #define DSSINFO(format, ...) \
  48. pr_info("omapdss " DSS_SUBSYS_NAME ": " format, ##__VA_ARGS__)
  49. #else
  50. #define DSSINFO(format, ...) \
  51. pr_info("omapdss: " format, ## __VA_ARGS__)
  52. #endif
  53. #ifdef DSS_SUBSYS_NAME
  54. #define DSSWARN(format, ...) \
  55. pr_warn("omapdss " DSS_SUBSYS_NAME ": " format, ##__VA_ARGS__)
  56. #else
  57. #define DSSWARN(format, ...) \
  58. pr_warn("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_model {
  68. DSS_MODEL_OMAP2,
  69. DSS_MODEL_OMAP3,
  70. DSS_MODEL_OMAP4,
  71. DSS_MODEL_OMAP5,
  72. DSS_MODEL_DRA7,
  73. };
  74. enum dss_io_pad_mode {
  75. DSS_IO_PAD_MODE_RESET,
  76. DSS_IO_PAD_MODE_RFBI,
  77. DSS_IO_PAD_MODE_BYPASS,
  78. };
  79. enum dss_hdmi_venc_clk_source_select {
  80. DSS_VENC_TV_CLK = 0,
  81. DSS_HDMI_M_PCLK = 1,
  82. };
  83. enum dss_dsi_content_type {
  84. DSS_DSI_CONTENT_DCS,
  85. DSS_DSI_CONTENT_GENERIC,
  86. };
  87. enum dss_writeback_channel {
  88. DSS_WB_LCD1_MGR = 0,
  89. DSS_WB_LCD2_MGR = 1,
  90. DSS_WB_TV_MGR = 2,
  91. DSS_WB_OVL0 = 3,
  92. DSS_WB_OVL1 = 4,
  93. DSS_WB_OVL2 = 5,
  94. DSS_WB_OVL3 = 6,
  95. DSS_WB_LCD3_MGR = 7,
  96. };
  97. enum dss_clk_source {
  98. DSS_CLK_SRC_FCK = 0,
  99. DSS_CLK_SRC_PLL1_1,
  100. DSS_CLK_SRC_PLL1_2,
  101. DSS_CLK_SRC_PLL1_3,
  102. DSS_CLK_SRC_PLL2_1,
  103. DSS_CLK_SRC_PLL2_2,
  104. DSS_CLK_SRC_PLL2_3,
  105. DSS_CLK_SRC_HDMI_PLL,
  106. };
  107. enum dss_pll_id {
  108. DSS_PLL_DSI1,
  109. DSS_PLL_DSI2,
  110. DSS_PLL_HDMI,
  111. DSS_PLL_VIDEO1,
  112. DSS_PLL_VIDEO2,
  113. };
  114. struct dss_pll;
  115. #define DSS_PLL_MAX_HSDIVS 4
  116. enum dss_pll_type {
  117. DSS_PLL_TYPE_A,
  118. DSS_PLL_TYPE_B,
  119. };
  120. /*
  121. * Type-A PLLs: clkout[]/mX[] refer to hsdiv outputs m4, m5, m6, m7.
  122. * Type-B PLLs: clkout[0] refers to m2.
  123. */
  124. struct dss_pll_clock_info {
  125. /* rates that we get with dividers below */
  126. unsigned long fint;
  127. unsigned long clkdco;
  128. unsigned long clkout[DSS_PLL_MAX_HSDIVS];
  129. /* dividers */
  130. u16 n;
  131. u16 m;
  132. u32 mf;
  133. u16 mX[DSS_PLL_MAX_HSDIVS];
  134. u16 sd;
  135. };
  136. struct dss_pll_ops {
  137. int (*enable)(struct dss_pll *pll);
  138. void (*disable)(struct dss_pll *pll);
  139. int (*set_config)(struct dss_pll *pll,
  140. const struct dss_pll_clock_info *cinfo);
  141. };
  142. struct dss_pll_hw {
  143. enum dss_pll_type type;
  144. unsigned int n_max;
  145. unsigned int m_min;
  146. unsigned int m_max;
  147. unsigned int mX_max;
  148. unsigned long fint_min, fint_max;
  149. unsigned long clkdco_min, clkdco_low, clkdco_max;
  150. u8 n_msb, n_lsb;
  151. u8 m_msb, m_lsb;
  152. u8 mX_msb[DSS_PLL_MAX_HSDIVS], mX_lsb[DSS_PLL_MAX_HSDIVS];
  153. bool has_stopmode;
  154. bool has_freqsel;
  155. bool has_selfreqdco;
  156. bool has_refsel;
  157. /* DRA7 errata i886: use high N & M to avoid jitter */
  158. bool errata_i886;
  159. };
  160. struct dss_pll {
  161. const char *name;
  162. enum dss_pll_id id;
  163. struct dss_device *dss;
  164. struct clk *clkin;
  165. struct regulator *regulator;
  166. void __iomem *base;
  167. const struct dss_pll_hw *hw;
  168. const struct dss_pll_ops *ops;
  169. struct dss_pll_clock_info cinfo;
  170. };
  171. /* Defines a generic omap register field */
  172. struct dss_reg_field {
  173. u8 start, end;
  174. };
  175. struct dispc_clock_info {
  176. /* rates that we get with dividers below */
  177. unsigned long lck;
  178. unsigned long pck;
  179. /* dividers */
  180. u16 lck_div;
  181. u16 pck_div;
  182. };
  183. struct dss_lcd_mgr_config {
  184. enum dss_io_pad_mode io_pad_mode;
  185. bool stallmode;
  186. bool fifohandcheck;
  187. struct dispc_clock_info clock_info;
  188. int video_port_width;
  189. int lcden_sig_polarity;
  190. };
  191. #define DSS_SZ_REGS SZ_512
  192. struct dss_device {
  193. struct platform_device *pdev;
  194. void __iomem *base;
  195. struct regmap *syscon_pll_ctrl;
  196. u32 syscon_pll_ctrl_offset;
  197. struct clk *parent_clk;
  198. struct clk *dss_clk;
  199. unsigned long dss_clk_rate;
  200. unsigned long cache_req_pck;
  201. unsigned long cache_prate;
  202. struct dispc_clock_info cache_dispc_cinfo;
  203. enum dss_clk_source dsi_clk_source[MAX_NUM_DSI];
  204. enum dss_clk_source dispc_clk_source;
  205. enum dss_clk_source lcd_clk_source[MAX_DSS_LCD_MANAGERS];
  206. bool ctx_valid;
  207. u32 ctx[DSS_SZ_REGS / sizeof(u32)];
  208. const struct dss_features *feat;
  209. struct {
  210. struct dentry *root;
  211. struct dss_debugfs_entry *clk;
  212. struct dss_debugfs_entry *dss;
  213. } debugfs;
  214. struct dss_pll *plls[4];
  215. struct dss_pll *video1_pll;
  216. struct dss_pll *video2_pll;
  217. const struct dispc_ops *dispc_ops;
  218. };
  219. /* core */
  220. static inline int dss_set_min_bus_tput(struct device *dev, unsigned long tput)
  221. {
  222. /* To be implemented when the OMAP platform will provide this feature */
  223. return 0;
  224. }
  225. static inline bool dss_mgr_is_lcd(enum omap_channel id)
  226. {
  227. if (id == OMAP_DSS_CHANNEL_LCD || id == OMAP_DSS_CHANNEL_LCD2 ||
  228. id == OMAP_DSS_CHANNEL_LCD3)
  229. return true;
  230. else
  231. return false;
  232. }
  233. /* DSS */
  234. #if defined(CONFIG_OMAP2_DSS_DEBUGFS)
  235. struct dss_debugfs_entry *
  236. dss_debugfs_create_file(struct dss_device *dss, const char *name,
  237. int (*show_fn)(struct seq_file *s, void *data),
  238. void *data);
  239. void dss_debugfs_remove_file(struct dss_debugfs_entry *entry);
  240. #else
  241. static inline struct dss_debugfs_entry *
  242. dss_debugfs_create_file(struct dss_device *dss, const char *name,
  243. int (*show_fn)(struct seq_file *s, void *data),
  244. void *data)
  245. {
  246. return NULL;
  247. }
  248. static inline void dss_debugfs_remove_file(struct dss_debugfs_entry *entry)
  249. {
  250. }
  251. #endif /* CONFIG_OMAP2_DSS_DEBUGFS */
  252. struct dss_device *dss_get_device(struct device *dev);
  253. int dss_runtime_get(struct dss_device *dss);
  254. void dss_runtime_put(struct dss_device *dss);
  255. unsigned long dss_get_dispc_clk_rate(struct dss_device *dss);
  256. unsigned long dss_get_max_fck_rate(struct dss_device *dss);
  257. enum omap_dss_output_id dss_get_supported_outputs(struct dss_device *dss,
  258. enum omap_channel channel);
  259. int dss_dpi_select_source(struct dss_device *dss, int port,
  260. enum omap_channel channel);
  261. void dss_select_hdmi_venc_clk_source(struct dss_device *dss,
  262. enum dss_hdmi_venc_clk_source_select src);
  263. const char *dss_get_clk_source_name(enum dss_clk_source clk_src);
  264. /* DSS VIDEO PLL */
  265. struct dss_pll *dss_video_pll_init(struct dss_device *dss,
  266. struct platform_device *pdev, int id,
  267. struct regulator *regulator);
  268. void dss_video_pll_uninit(struct dss_pll *pll);
  269. void dss_ctrl_pll_enable(struct dss_pll *pll, bool enable);
  270. void dss_sdi_init(struct dss_device *dss, int datapairs);
  271. int dss_sdi_enable(struct dss_device *dss);
  272. void dss_sdi_disable(struct dss_device *dss);
  273. void dss_select_dsi_clk_source(struct dss_device *dss, int dsi_module,
  274. enum dss_clk_source clk_src);
  275. void dss_select_lcd_clk_source(struct dss_device *dss,
  276. enum omap_channel channel,
  277. enum dss_clk_source clk_src);
  278. enum dss_clk_source dss_get_dispc_clk_source(struct dss_device *dss);
  279. enum dss_clk_source dss_get_dsi_clk_source(struct dss_device *dss,
  280. int dsi_module);
  281. enum dss_clk_source dss_get_lcd_clk_source(struct dss_device *dss,
  282. enum omap_channel channel);
  283. void dss_set_venc_output(struct dss_device *dss, enum omap_dss_venc_type type);
  284. void dss_set_dac_pwrdn_bgz(struct dss_device *dss, bool enable);
  285. int dss_set_fck_rate(struct dss_device *dss, unsigned long rate);
  286. typedef bool (*dss_div_calc_func)(unsigned long fck, void *data);
  287. bool dss_div_calc(struct dss_device *dss, unsigned long pck,
  288. unsigned long fck_min, dss_div_calc_func func, void *data);
  289. /* SDI */
  290. #ifdef CONFIG_OMAP2_DSS_SDI
  291. int sdi_init_port(struct dss_device *dss, struct platform_device *pdev,
  292. struct device_node *port);
  293. void sdi_uninit_port(struct device_node *port);
  294. #else
  295. static inline int sdi_init_port(struct dss_device *dss,
  296. struct platform_device *pdev,
  297. struct device_node *port)
  298. {
  299. return 0;
  300. }
  301. static inline void sdi_uninit_port(struct device_node *port)
  302. {
  303. }
  304. #endif
  305. /* DSI */
  306. #ifdef CONFIG_OMAP2_DSS_DSI
  307. void dsi_dump_clocks(struct seq_file *s);
  308. void dsi_irq_handler(void);
  309. #endif
  310. /* DPI */
  311. #ifdef CONFIG_OMAP2_DSS_DPI
  312. int dpi_init_port(struct dss_device *dss, struct platform_device *pdev,
  313. struct device_node *port, enum dss_model dss_model);
  314. void dpi_uninit_port(struct device_node *port);
  315. #else
  316. static inline int dpi_init_port(struct dss_device *port,
  317. struct platform_device *pdev,
  318. struct device_node *port,
  319. enum dss_model dss_model)
  320. {
  321. return 0;
  322. }
  323. static inline void dpi_uninit_port(struct device_node *port)
  324. {
  325. }
  326. #endif
  327. /* DISPC */
  328. void dispc_dump_clocks(struct seq_file *s);
  329. int dispc_runtime_get(void);
  330. void dispc_runtime_put(void);
  331. void dispc_enable_sidle(void);
  332. void dispc_disable_sidle(void);
  333. void dispc_lcd_enable_signal(bool enable);
  334. void dispc_pck_free_enable(bool enable);
  335. void dispc_enable_fifomerge(bool enable);
  336. typedef bool (*dispc_div_calc_func)(int lckd, int pckd, unsigned long lck,
  337. unsigned long pck, void *data);
  338. bool dispc_div_calc(unsigned long dispc,
  339. unsigned long pck_min, unsigned long pck_max,
  340. dispc_div_calc_func func, void *data);
  341. bool dispc_mgr_timings_ok(enum omap_channel channel, const struct videomode *vm);
  342. int dispc_calc_clock_rates(unsigned long dispc_fclk_rate,
  343. struct dispc_clock_info *cinfo);
  344. void dispc_ovl_set_fifo_threshold(enum omap_plane_id plane, u32 low,
  345. u32 high);
  346. void dispc_ovl_compute_fifo_thresholds(enum omap_plane_id plane,
  347. u32 *fifo_low, u32 *fifo_high, bool use_fifomerge,
  348. bool manual_update);
  349. void dispc_mgr_set_clock_div(enum omap_channel channel,
  350. const struct dispc_clock_info *cinfo);
  351. int dispc_mgr_get_clock_div(enum omap_channel channel,
  352. struct dispc_clock_info *cinfo);
  353. void dispc_set_tv_pclk(unsigned long pclk);
  354. u32 dispc_wb_get_framedone_irq(void);
  355. bool dispc_wb_go_busy(void);
  356. void dispc_wb_go(void);
  357. void dispc_wb_set_channel_in(enum dss_writeback_channel channel);
  358. int dispc_wb_setup(const struct omap_dss_writeback_info *wi,
  359. bool mem_to_mem, const struct videomode *vm);
  360. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  361. static inline void dss_collect_irq_stats(u32 irqstatus, unsigned int *irq_arr)
  362. {
  363. int b;
  364. for (b = 0; b < 32; ++b) {
  365. if (irqstatus & (1 << b))
  366. irq_arr[b]++;
  367. }
  368. }
  369. #endif
  370. /* PLL */
  371. typedef bool (*dss_pll_calc_func)(int n, int m, unsigned long fint,
  372. unsigned long clkdco, void *data);
  373. typedef bool (*dss_hsdiv_calc_func)(int m_dispc, unsigned long dispc,
  374. void *data);
  375. int dss_pll_register(struct dss_device *dss, struct dss_pll *pll);
  376. void dss_pll_unregister(struct dss_pll *pll);
  377. struct dss_pll *dss_pll_find(struct dss_device *dss, const char *name);
  378. struct dss_pll *dss_pll_find_by_src(struct dss_device *dss,
  379. enum dss_clk_source src);
  380. unsigned int dss_pll_get_clkout_idx_for_src(enum dss_clk_source src);
  381. int dss_pll_enable(struct dss_pll *pll);
  382. void dss_pll_disable(struct dss_pll *pll);
  383. int dss_pll_set_config(struct dss_pll *pll,
  384. const struct dss_pll_clock_info *cinfo);
  385. bool dss_pll_hsdiv_calc_a(const struct dss_pll *pll, unsigned long clkdco,
  386. unsigned long out_min, unsigned long out_max,
  387. dss_hsdiv_calc_func func, void *data);
  388. bool dss_pll_calc_a(const struct dss_pll *pll, unsigned long clkin,
  389. unsigned long pll_min, unsigned long pll_max,
  390. dss_pll_calc_func func, void *data);
  391. bool dss_pll_calc_b(const struct dss_pll *pll, unsigned long clkin,
  392. unsigned long target_clkout, struct dss_pll_clock_info *cinfo);
  393. int dss_pll_write_config_type_a(struct dss_pll *pll,
  394. const struct dss_pll_clock_info *cinfo);
  395. int dss_pll_write_config_type_b(struct dss_pll *pll,
  396. const struct dss_pll_clock_info *cinfo);
  397. int dss_pll_wait_reset_done(struct dss_pll *pll);
  398. extern struct platform_driver omap_dsshw_driver;
  399. extern struct platform_driver omap_dispchw_driver;
  400. #ifdef CONFIG_OMAP2_DSS_DSI
  401. extern struct platform_driver omap_dsihw_driver;
  402. #endif
  403. #ifdef CONFIG_OMAP2_DSS_VENC
  404. extern struct platform_driver omap_venchw_driver;
  405. #endif
  406. #ifdef CONFIG_OMAP4_DSS_HDMI
  407. extern struct platform_driver omapdss_hdmi4hw_driver;
  408. #endif
  409. #ifdef CONFIG_OMAP5_DSS_HDMI
  410. extern struct platform_driver omapdss_hdmi5hw_driver;
  411. #endif
  412. #endif