dp_parser.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2021-2023, Qualcomm Innovation Center, Inc. All rights reserved.
  4. * Copyright (c) 2012-2021, The Linux Foundation. All rights reserved.
  5. */
  6. #ifndef _DP_PARSER_H_
  7. #define _DP_PARSER_H_
  8. #include <linux/sde_io_util.h>
  9. #define DP_LABEL "MDSS DP DISPLAY"
  10. #define AUX_CFG_LEN 10
  11. #define DP_MAX_PIXEL_CLK_KHZ 675000
  12. #define DP_MAX_LINK_CLK_KHZ 810000
  13. #define MAX_DP_MST_STREAMS 2
  14. #define MAX_SWING_LEVELS 4
  15. #define MAX_PRE_EMP_LEVELS 4
  16. enum dp_pm_type {
  17. DP_CORE_PM,
  18. DP_CTRL_PM,
  19. DP_PHY_PM,
  20. DP_STREAM0_PM,
  21. DP_STREAM1_PM,
  22. DP_LINK_PM,
  23. DP_PLL_PM,
  24. DP_MAX_PM
  25. };
  26. static inline const char *dp_parser_pm_name(enum dp_pm_type module)
  27. {
  28. switch (module) {
  29. case DP_CORE_PM: return "DP_CORE_PM";
  30. case DP_CTRL_PM: return "DP_CTRL_PM";
  31. case DP_PHY_PM: return "DP_PHY_PM";
  32. case DP_STREAM0_PM: return "DP_STREAM0_PM";
  33. case DP_STREAM1_PM: return "DP_STREAM1_PM";
  34. case DP_LINK_PM: return "DP_LINK_PM";
  35. case DP_PLL_PM: return "DP_PLL_PM";
  36. default: return "???";
  37. }
  38. }
  39. /**
  40. * struct dp_display_data - display related device tree data.
  41. *
  42. * @ctrl_node: referece to controller device
  43. * @phy_node: reference to phy device
  44. * @is_active: is the controller currently active
  45. * @name: name of the display
  46. * @display_type: type of the display
  47. */
  48. struct dp_display_data {
  49. struct device_node *ctrl_node;
  50. struct device_node *phy_node;
  51. bool is_active;
  52. const char *name;
  53. const char *display_type;
  54. };
  55. /**
  56. * struct dp_io_data - data structure to store DP IO related info
  57. * @name: name of the IO
  58. * @buf: buffer corresponding to IO for debugging
  59. * @io: io data which give len and mapped address
  60. */
  61. struct dp_io_data {
  62. const char *name;
  63. u8 *buf;
  64. struct dss_io_data io;
  65. };
  66. /**
  67. * struct dp_io - data struct to store array of DP IO info
  68. * @len: total number of IOs
  69. * @data: pointer to an array of DP IO data structures.
  70. */
  71. struct dp_io {
  72. u32 len;
  73. struct dp_io_data *data;
  74. };
  75. /**
  76. * struct dp_pinctrl - DP's pin control
  77. *
  78. * @pin: pin-controller's instance
  79. * @state_active: active state pin control
  80. * @state_hpd_active: hpd active state pin control
  81. * @state_suspend: suspend state pin control
  82. */
  83. struct dp_pinctrl {
  84. struct pinctrl *pin;
  85. struct pinctrl_state *state_active;
  86. struct pinctrl_state *state_hpd_active;
  87. struct pinctrl_state *state_hpd_tlmm;
  88. struct pinctrl_state *state_hpd_ctrl;
  89. struct pinctrl_state *state_suspend;
  90. };
  91. #define DP_ENUM_STR(x) #x
  92. #define DP_AUX_CFG_MAX_VALUE_CNT 3
  93. /**
  94. * struct dp_aux_cfg - DP's AUX configuration settings
  95. *
  96. * @cfg_cnt: count of the configurable settings for the AUX register
  97. * @current_index: current index of the AUX config lut
  98. * @offset: register offset of the AUX config register
  99. * @lut: look up table for the AUX config values for this register
  100. */
  101. struct dp_aux_cfg {
  102. u32 cfg_cnt;
  103. u32 current_index;
  104. u32 offset;
  105. u32 lut[DP_AUX_CFG_MAX_VALUE_CNT];
  106. };
  107. /* PHY AUX config registers */
  108. enum dp_phy_aux_config_type {
  109. PHY_AUX_CFG0,
  110. PHY_AUX_CFG1,
  111. PHY_AUX_CFG2,
  112. PHY_AUX_CFG3,
  113. PHY_AUX_CFG4,
  114. PHY_AUX_CFG5,
  115. PHY_AUX_CFG6,
  116. PHY_AUX_CFG7,
  117. PHY_AUX_CFG8,
  118. PHY_AUX_CFG9,
  119. PHY_AUX_CFG_MAX,
  120. };
  121. /**
  122. * enum dp_phy_version - version of the dp phy
  123. * @DP_PHY_VERSION_UNKNOWN: Unknown controller version
  124. * @DP_PHY_VERSION_4_2_0: DP phy v4.2.0 controller
  125. * @DP_PHY_VERSION_6_0_0: DP phy v6.0.0 controller
  126. * @DP_PHY_VERSION_MAX: max version
  127. */
  128. enum dp_phy_version {
  129. DP_PHY_VERSION_UNKNOWN,
  130. DP_PHY_VERSION_2_0_0 = 0x200,
  131. DP_PHY_VERSION_4_2_0 = 0x420,
  132. DP_PHY_VERSION_6_0_0 = 0x600,
  133. DP_PHY_VERSION_MAX
  134. };
  135. /**
  136. * struct dp_hw_cfg - DP HW specific configuration
  137. *
  138. * @phy_version: DP PHY HW version
  139. */
  140. struct dp_hw_cfg {
  141. enum dp_phy_version phy_version;
  142. };
  143. static inline char *dp_phy_aux_config_type_to_string(u32 cfg_type)
  144. {
  145. switch (cfg_type) {
  146. case PHY_AUX_CFG0:
  147. return DP_ENUM_STR(PHY_AUX_CFG0);
  148. case PHY_AUX_CFG1:
  149. return DP_ENUM_STR(PHY_AUX_CFG1);
  150. case PHY_AUX_CFG2:
  151. return DP_ENUM_STR(PHY_AUX_CFG2);
  152. case PHY_AUX_CFG3:
  153. return DP_ENUM_STR(PHY_AUX_CFG3);
  154. case PHY_AUX_CFG4:
  155. return DP_ENUM_STR(PHY_AUX_CFG4);
  156. case PHY_AUX_CFG5:
  157. return DP_ENUM_STR(PHY_AUX_CFG5);
  158. case PHY_AUX_CFG6:
  159. return DP_ENUM_STR(PHY_AUX_CFG6);
  160. case PHY_AUX_CFG7:
  161. return DP_ENUM_STR(PHY_AUX_CFG7);
  162. case PHY_AUX_CFG8:
  163. return DP_ENUM_STR(PHY_AUX_CFG8);
  164. case PHY_AUX_CFG9:
  165. return DP_ENUM_STR(PHY_AUX_CFG9);
  166. default:
  167. return "unknown";
  168. }
  169. }
  170. #if defined(CONFIG_SECDP)
  171. enum secdp_phy_pre_emphasis_type {
  172. PHY_PRE_EMP0, /* 0 db */
  173. PHY_PRE_EMP1, /* 3.5 db */
  174. PHY_PRE_EMP2, /* 6.0 db */
  175. PHY_PRE_EMP3, /* 9.5 db */
  176. // MAX_PRE_EMP_LEVELS,
  177. };
  178. enum secdp_phy_voltage_type {
  179. PHY_VOLTAGE_SWING0, /* 0.4 v */
  180. PHY_VOLTAGE_SWING1, /* 0.6 v */
  181. PHY_VOLTAGE_SWING2, /* 0.8 v */
  182. PHY_VOLTAGE_SWING3, /* 1.2 v, optional */
  183. MAX_VOLTAGE_LEVELS,
  184. };
  185. #if IS_ENABLED(CONFIG_COMBO_REDRIVER_PS5169)
  186. enum secdp_ps5169_pre_emphasis_type {
  187. PHY_PS5169_EMP0, /* 0 db */
  188. PHY_PS5169_EMP1, /* 3.5 db */
  189. PHY_PS5169_EMP2, /* 6.0 db */
  190. PHY_PS5169_EMP3, /* 9.5 db */
  191. MAX_PS5169_EMP_LEVELS,
  192. };
  193. enum secdp_PS5169_voltage_type {
  194. PHY_PS5169_SWING0, /* 0.4 v */
  195. PHY_PS5169_SWING1, /* 0.6 v */
  196. PHY_PS5169_SWING2, /* 0.8 v */
  197. PHY_PS5169_SWING3, /* 1.2 v, optional */
  198. MAX_PS5169_SWING_LEVELS,
  199. };
  200. #endif/*CONFIG_COMBO_REDRIVER_PS5169*/
  201. #endif/*CONFIG_SECDP*/
  202. /**
  203. * struct dp_parser - DP parser's data exposed to clients
  204. *
  205. * @pdev: platform data of the client
  206. * @msm_hdcp_dev: device pointer for the HDCP driver
  207. * @mp: gpio, regulator and clock related data
  208. * @pinctrl: pin-control related data
  209. * @disp_data: controller's display related data
  210. * @l_pnswap: P/N swap status on each lane
  211. * @max_pclk_khz: maximum pixel clock supported for the platform
  212. * @max_lclk_khz: maximum link clock supported for the platform
  213. * @hw_cfg: DP HW specific settings
  214. * @has_mst: MST feature enable status
  215. * @has_mst_sideband: MST sideband feature enable status
  216. * @gpio_aux_switch: presence GPIO AUX switch status
  217. * @dsc_feature_enable: DSC feature enable status
  218. * @fec_feature_enable: FEC feature enable status
  219. * @dsc_continuous_pps: PPS sent every frame by HW
  220. * @has_widebus: widebus (2PPC) feature eanble status
  221. *@mst_fixed_port: mst port_num reserved for fixed topology
  222. * @qos_cpu_mask: CPU mask for QOS
  223. * @qos_cpu_latency: CPU Latency setting for QOS
  224. * @swing_hbr2_3: Voltage swing levels for HBR2 and HBR3 rates
  225. * @pre_emp_hbr2_3: Pre-emphasis for HBR2 and HBR3 rates
  226. * @swing_hbr_rbr: Voltage swing levels for HBR and RBR rates
  227. * @pre_emp_hbr_rbr: Pre-emphasis for HBR and RBR rates
  228. * @valid_lt_params: valid lt params
  229. * @parse: function to be called by client to parse device tree.
  230. * @get_io: function to be called by client to get io data.
  231. * @get_io_buf: function to be called by client to get io buffers.
  232. * @clear_io_buf: function to be called by client to clear io buffers.
  233. */
  234. struct dp_parser {
  235. struct platform_device *pdev;
  236. struct device *msm_hdcp_dev;
  237. struct dss_module_power mp[DP_MAX_PM];
  238. struct dp_pinctrl pinctrl;
  239. struct dp_io io;
  240. struct dp_display_data disp_data;
  241. u8 l_map[4];
  242. u8 l_pnswap;
  243. struct dp_aux_cfg aux_cfg[AUX_CFG_LEN];
  244. u32 max_pclk_khz;
  245. u32 max_lclk_khz;
  246. struct dp_hw_cfg hw_cfg;
  247. bool has_mst;
  248. bool has_mst_sideband;
  249. bool dsc_feature_enable;
  250. bool fec_feature_enable;
  251. bool dsc_continuous_pps;
  252. bool has_widebus;
  253. bool gpio_aux_switch;
  254. u32 mst_fixed_port[MAX_DP_MST_STREAMS];
  255. u32 qos_cpu_mask;
  256. unsigned long qos_cpu_latency;
  257. u8 *swing_hbr2_3;
  258. u8 *pre_emp_hbr2_3;
  259. u8 *swing_hbr_rbr;
  260. u8 *pre_emp_hbr_rbr;
  261. bool valid_lt_params;
  262. #if defined(CONFIG_SECDP)
  263. struct regulator *aux_pullup_vreg;
  264. bool cc_dir_inv; /* CC_DIR is inversed, e.g, T865 */
  265. bool aux_sel_inv; /* inverse control of AUX_SEL e.g, D2Xq hwid 01,02 */
  266. int use_redrv; /* ptn36502 needs NOT AUX switch SEL control */
  267. int dex_dft_res; /* DeX default resolution, e.g, HG950 */
  268. bool prefer_support; /* true if prefer resolution has high priority */
  269. bool mrr_fps_nolimit; /* true if mirroring refresh rate has no limit */
  270. bool rf_tx_backoff; /* true if it RF TX Backoff is supported, for SHELL-less type connector */
  271. bool mst_support; /* true if MST is supported */
  272. #if IS_ENABLED(CONFIG_COMBO_REDRIVER_PS5169)
  273. u8 ps5169_rbr_eq0[MAX_PS5169_SWING_LEVELS][MAX_PS5169_EMP_LEVELS];
  274. u8 ps5169_rbr_eq1[MAX_PS5169_SWING_LEVELS][MAX_PS5169_EMP_LEVELS];
  275. u8 ps5169_hbr_eq0[MAX_PS5169_SWING_LEVELS][MAX_PS5169_EMP_LEVELS];
  276. u8 ps5169_hbr_eq1[MAX_PS5169_SWING_LEVELS][MAX_PS5169_EMP_LEVELS];
  277. u8 ps5169_hbr2_eq0[MAX_PS5169_SWING_LEVELS][MAX_PS5169_EMP_LEVELS];
  278. u8 ps5169_hbr2_eq1[MAX_PS5169_SWING_LEVELS][MAX_PS5169_EMP_LEVELS];
  279. u8 ps5169_hbr3_eq0[MAX_PS5169_SWING_LEVELS][MAX_PS5169_EMP_LEVELS];
  280. u8 ps5169_hbr3_eq1[MAX_PS5169_SWING_LEVELS][MAX_PS5169_EMP_LEVELS];
  281. #endif/*CONFIG_COMBO_REDRIVER_PS5169*/
  282. #endif/*CONFIG_SECDP*/
  283. int (*parse)(struct dp_parser *parser);
  284. struct dp_io_data *(*get_io)(struct dp_parser *parser, char *name);
  285. void (*get_io_buf)(struct dp_parser *parser, char *name);
  286. void (*clear_io_buf)(struct dp_parser *parser);
  287. };
  288. enum dp_phy_lane_num {
  289. DP_PHY_LN0 = 0,
  290. DP_PHY_LN1 = 1,
  291. DP_PHY_LN2 = 2,
  292. DP_PHY_LN3 = 3,
  293. DP_MAX_PHY_LN = 4,
  294. };
  295. enum dp_mainlink_lane_num {
  296. DP_ML0 = 0,
  297. DP_ML1 = 1,
  298. DP_ML2 = 2,
  299. DP_ML3 = 3,
  300. };
  301. /**
  302. * dp_parser_get() - get the DP's device tree parser module
  303. *
  304. * @pdev: platform data of the client
  305. * return: pointer to dp_parser structure.
  306. *
  307. * This function provides client capability to parse the
  308. * device tree and populate the data structures. The data
  309. * related to clock, regulators, pin-control and other
  310. * can be parsed using this module.
  311. */
  312. struct dp_parser *dp_parser_get(struct platform_device *pdev);
  313. /**
  314. * dp_parser_put() - cleans the dp_parser module
  315. *
  316. * @parser: pointer to the parser's data.
  317. */
  318. void dp_parser_put(struct dp_parser *parser);
  319. #if defined(CONFIG_SECDP) && IS_ENABLED(CONFIG_COMBO_REDRIVER_PS5169)
  320. enum secdp_ps5169_eq_t {
  321. DP_PS5169_EQ0,
  322. DP_PS5169_EQ1,
  323. DP_PS5169_EQ_MAX,
  324. };
  325. enum secdp_ps5169_link_rate_t {
  326. DP_PS5169_RATE_RBR,
  327. DP_PS5169_RATE_HBR,
  328. DP_PS5169_RATE_HBR2,
  329. DP_PS5169_RATE_HBR3,
  330. DP_PS5169_RATE_MAX,
  331. };
  332. #endif
  333. #if defined(CONFIG_SECDP_DBG)
  334. enum secdp_link_rate_t {
  335. DP_LR_NONE = 0x0,
  336. DP_LR_HBR_RBR = 0x1,
  337. DP_LR_HBR2_3 = 0x2,
  338. };
  339. static inline char *secdp_link_rate_to_string(int lr)
  340. {
  341. switch (lr) {
  342. case DP_LR_HBR_RBR:
  343. return DP_ENUM_STR(DP_LR_HBR_RBR);
  344. case DP_LR_HBR2_3:
  345. return DP_ENUM_STR(DP_LR_HBR2_3);
  346. default:
  347. return "unknown";
  348. }
  349. }
  350. enum secdp_phy_param_t {
  351. DP_PARAM_NONE = 0x0,
  352. DP_PARAM_VX = 0x1, /* voltage swing */
  353. DP_PARAM_PX = 0x2, /* pre-emphasis */
  354. };
  355. static inline char *secdp_phy_type_to_string(int param)
  356. {
  357. switch (param) {
  358. case DP_PARAM_VX:
  359. return DP_ENUM_STR(DP_PARAM_VX);
  360. case DP_PARAM_PX:
  361. return DP_ENUM_STR(DP_PARAM_PX);
  362. default:
  363. return "unknown";
  364. }
  365. }
  366. /* voltage swing, pre-emphasis */
  367. int secdp_parse_vxpx_show(struct dp_parser *parser, enum secdp_link_rate_t lr,
  368. enum secdp_phy_param_t vxpx, char *buf);
  369. int secdp_parse_vxpx_store(struct dp_parser *parser, enum secdp_link_rate_t lr,
  370. enum secdp_phy_param_t vxpx, char *buf);
  371. int secdp_show_phy_param(struct dp_parser *parser, char *buf);
  372. #if IS_ENABLED(CONFIG_COMBO_REDRIVER_PS5169)
  373. static inline char *secdp_ps5169_eq_to_string(int hw)
  374. {
  375. switch (hw) {
  376. case DP_PS5169_EQ0:
  377. return DP_ENUM_STR(DP_PS5169_EQ0);
  378. case DP_PS5169_EQ1:
  379. return DP_ENUM_STR(DP_PS5169_EQ1);
  380. default:
  381. return "unknown";
  382. }
  383. }
  384. static inline char *secdp_ps5169_rate_to_string(int hw)
  385. {
  386. switch (hw) {
  387. case DP_PS5169_RATE_RBR:
  388. return DP_ENUM_STR(DP_PS5169_RATE_RBR);
  389. case DP_PS5169_RATE_HBR:
  390. return DP_ENUM_STR(DP_PS5169_RATE_HBR);
  391. case DP_PS5169_RATE_HBR2:
  392. return DP_ENUM_STR(DP_PS5169_RATE_HBR2);
  393. case DP_PS5169_RATE_HBR3:
  394. return DP_ENUM_STR(DP_PS5169_RATE_HBR3);
  395. default:
  396. return "unknown";
  397. }
  398. }
  399. int secdp_parse_ps5169_show(struct dp_parser *parser, enum secdp_ps5169_eq_t eq,
  400. enum secdp_ps5169_link_rate_t link_rate, char *buf);
  401. int secdp_parse_ps5169_store(struct dp_parser *parser, enum secdp_ps5169_eq_t eq,
  402. enum secdp_ps5169_link_rate_t link_rate, char *buf);
  403. int secdp_show_ps5169_param(struct dp_parser *parser, char *buf);
  404. #endif/*CONFIG_COMBO_REDRIVER_PS5169*/
  405. /* AUX configuration */
  406. int secdp_aux_cfg_show(struct dp_parser *parser, char *buf);
  407. int secdp_aux_cfg_store(struct dp_parser *parser, char *buf);
  408. #endif/*CONFIG_SECDP_DBG*/
  409. #endif