dss.h 13 KB

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