dss.h 15 KB

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