dsi_phy_hw.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2015-2021, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef _DSI_PHY_HW_H_
  6. #define _DSI_PHY_HW_H_
  7. #include "dsi_defs.h"
  8. #define DSI_MAX_SETTINGS 8
  9. #define DSI_PHY_TIMING_V3_SIZE 12
  10. #define DSI_PHY_TIMING_V4_SIZE 14
  11. #define DSI_PHY_DBG(p, fmt, ...) DRM_DEV_DEBUG(NULL, "[msm-dsi-debug]: DSI_%d: "\
  12. fmt, p ? p->index : -1, ##__VA_ARGS__)
  13. #define DSI_PHY_ERR(p, fmt, ...) DRM_DEV_ERROR(NULL, "[msm-dsi-error]: DSI_%d: "\
  14. fmt, p ? p->index : -1, ##__VA_ARGS__)
  15. #define DSI_PHY_INFO(p, fmt, ...) DRM_DEV_INFO(NULL, "[msm-dsi-info]: DSI_%d: "\
  16. fmt, p ? p->index : -1, ##__VA_ARGS__)
  17. #define DSI_PHY_WARN(p, fmt, ...) DRM_WARN("[msm-dsi-warn]: DSI_%d: " fmt,\
  18. p ? p->index : -1, ##__VA_ARGS__)
  19. /**
  20. * enum dsi_phy_version - DSI PHY version enumeration
  21. * @DSI_PHY_VERSION_UNKNOWN: Unknown version.
  22. * @DSI_PHY_VERSION_0_0_HPM: 28nm-HPM.
  23. * @DSI_PHY_VERSION_0_0_LPM: 28nm-HPM.
  24. * @DSI_PHY_VERSION_1_0: 20nm
  25. * @DSI_PHY_VERSION_2_0: 14nm
  26. * @DSI_PHY_VERSION_3_0: 10nm
  27. * @DSI_PHY_VERSION_4_0: 7nm
  28. * @DSI_PHY_VERSION_4_1: 7nm
  29. * @DSI_PHY_VERSION_4_2: 5nm
  30. * @DSI_PHY_VERSION_4_3: 5nm
  31. * @DSI_PHY_VERSION_MAX:
  32. */
  33. enum dsi_phy_version {
  34. DSI_PHY_VERSION_UNKNOWN,
  35. DSI_PHY_VERSION_0_0_HPM, /* 28nm-HPM */
  36. DSI_PHY_VERSION_0_0_LPM, /* 28nm-LPM */
  37. DSI_PHY_VERSION_1_0, /* 20nm */
  38. DSI_PHY_VERSION_2_0, /* 14nm */
  39. DSI_PHY_VERSION_3_0, /* 10nm */
  40. DSI_PHY_VERSION_4_0, /* 7nm */
  41. DSI_PHY_VERSION_4_1, /* 7nm */
  42. DSI_PHY_VERSION_4_2, /* 5nm */
  43. DSI_PHY_VERSION_4_3, /* 5nm */
  44. DSI_PHY_VERSION_MAX
  45. };
  46. /**
  47. * enum dsi_pll_version - DSI PHY PLL version enumeration
  48. * @DSI_PLL_VERSION_5NM: 5nm PLL
  49. * @DSI_PLL_VERSION_10NM: 10nm PLL
  50. * @DSI_PLL_VERSION_UNKNOWN: Unknown PLL version
  51. */
  52. enum dsi_pll_version {
  53. DSI_PLL_VERSION_5NM,
  54. DSI_PLL_VERSION_10NM,
  55. DSI_PLL_VERSION_UNKNOWN
  56. };
  57. /**
  58. * enum dsi_phy_hw_features - features supported by DSI PHY hardware
  59. * @DSI_PHY_DPHY: Supports DPHY
  60. * @DSI_PHY_CPHY: Supports CPHY
  61. * @DSI_PHY_SPLIT_LINK: Supports Split Link
  62. * @DSI_PHY_MAX_FEATURES:
  63. */
  64. enum dsi_phy_hw_features {
  65. DSI_PHY_DPHY,
  66. DSI_PHY_CPHY,
  67. DSI_PHY_SPLIT_LINK,
  68. DSI_PHY_MAX_FEATURES
  69. };
  70. /**
  71. * enum dsi_phy_pll_source - pll clock source for PHY.
  72. * @DSI_PLL_SOURCE_STANDALONE: Clock is sourced from native PLL and is not
  73. * shared by other PHYs.
  74. * @DSI_PLL_SOURCE_NATIVE: Clock is sourced from native PLL and is
  75. * shared by other PHYs.
  76. * @DSI_PLL_SOURCE_NON_NATIVE: Clock is sourced from other PHYs.
  77. * @DSI_PLL_SOURCE_MAX:
  78. */
  79. enum dsi_phy_pll_source {
  80. DSI_PLL_SOURCE_STANDALONE = 0,
  81. DSI_PLL_SOURCE_NATIVE,
  82. DSI_PLL_SOURCE_NON_NATIVE,
  83. DSI_PLL_SOURCE_MAX
  84. };
  85. /**
  86. * struct dsi_phy_per_lane_cfgs - Holds register values for PHY parameters
  87. * @lane: A set of maximum 8 values for each lane.
  88. * @lane_v3: A set of maximum 12 values for each lane.
  89. * @count_per_lane: Number of values per each lane.
  90. */
  91. struct dsi_phy_per_lane_cfgs {
  92. u8 lane[DSI_LANE_MAX][DSI_MAX_SETTINGS];
  93. u8 lane_v3[DSI_PHY_TIMING_V3_SIZE];
  94. u8 lane_v4[DSI_PHY_TIMING_V4_SIZE];
  95. u32 count_per_lane;
  96. };
  97. /**
  98. * struct dsi_phy_cfg - DSI PHY configuration
  99. * @lanecfg: Lane configuration settings.
  100. * @strength: Strength settings for lanes.
  101. * @timing: Timing parameters for lanes.
  102. * @is_phy_timing_present: Boolean whether phy timings are defined.
  103. * @regulators: Regulator settings for lanes.
  104. * @pll_source: PLL source.
  105. * @lane_map: DSI logical to PHY lane mapping.
  106. * @force_clk_lane_hs:Boolean whether to force clock lane in HS mode.
  107. * @phy_type: Phy-type (Dphy/Cphy).
  108. * @bit_clk_rate_hz: DSI bit clk rate in HZ.
  109. * @split_link: DSI split link config data.
  110. */
  111. struct dsi_phy_cfg {
  112. struct dsi_phy_per_lane_cfgs lanecfg;
  113. struct dsi_phy_per_lane_cfgs strength;
  114. struct dsi_phy_per_lane_cfgs timing;
  115. bool is_phy_timing_present;
  116. struct dsi_phy_per_lane_cfgs regulators;
  117. enum dsi_phy_pll_source pll_source;
  118. struct dsi_lane_map lane_map;
  119. bool force_clk_lane_hs;
  120. enum dsi_phy_type phy_type;
  121. unsigned long bit_clk_rate_hz;
  122. struct dsi_split_link_config split_link;
  123. };
  124. struct dsi_phy_hw;
  125. struct phy_ulps_config_ops {
  126. /**
  127. * wait_for_lane_idle() - wait for DSI lanes to go to idle state
  128. * @phy: Pointer to DSI PHY hardware instance.
  129. * @lanes: ORed list of lanes (enum dsi_data_lanes) which need
  130. * to be checked to be in idle state.
  131. */
  132. int (*wait_for_lane_idle)(struct dsi_phy_hw *phy, u32 lanes);
  133. /**
  134. * ulps_request() - request ulps entry for specified lanes
  135. * @phy: Pointer to DSI PHY hardware instance.
  136. * @cfg: Per lane configurations for timing, strength and lane
  137. * configurations.
  138. * @lanes: ORed list of lanes (enum dsi_data_lanes) which need
  139. * to enter ULPS.
  140. *
  141. * Caller should check if lanes are in ULPS mode by calling
  142. * get_lanes_in_ulps() operation.
  143. */
  144. void (*ulps_request)(struct dsi_phy_hw *phy,
  145. struct dsi_phy_cfg *cfg, u32 lanes);
  146. /**
  147. * ulps_exit() - exit ULPS on specified lanes
  148. * @phy: Pointer to DSI PHY hardware instance.
  149. * @cfg: Per lane configurations for timing, strength and lane
  150. * configurations.
  151. * @lanes: ORed list of lanes (enum dsi_data_lanes) which need
  152. * to exit ULPS.
  153. *
  154. * Caller should check if lanes are in active mode by calling
  155. * get_lanes_in_ulps() operation.
  156. */
  157. void (*ulps_exit)(struct dsi_phy_hw *phy,
  158. struct dsi_phy_cfg *cfg, u32 lanes);
  159. /**
  160. * get_lanes_in_ulps() - returns the list of lanes in ULPS mode
  161. * @phy: Pointer to DSI PHY hardware instance.
  162. *
  163. * Returns an ORed list of lanes (enum dsi_data_lanes) that are in ULPS
  164. * state.
  165. *
  166. * Return: List of lanes in ULPS state.
  167. */
  168. u32 (*get_lanes_in_ulps)(struct dsi_phy_hw *phy);
  169. /**
  170. * is_lanes_in_ulps() - checks if the given lanes are in ulps
  171. * @lanes: lanes to be checked.
  172. * @ulps_lanes: lanes in ulps currenly.
  173. *
  174. * Return: true if all the given lanes are in ulps; false otherwise.
  175. */
  176. bool (*is_lanes_in_ulps)(u32 ulps, u32 ulps_lanes);
  177. };
  178. struct phy_dyn_refresh_ops {
  179. /**
  180. * dyn_refresh_helper - helper function to config particular registers
  181. * @phy: Pointer to DSI PHY hardware instance.
  182. * @offset: register offset to program.
  183. */
  184. void (*dyn_refresh_helper)(struct dsi_phy_hw *phy, u32 offset);
  185. /**
  186. * dyn_refresh_trigger_sel - configure trigger_sel to frame flush
  187. * @phy: Pointer to DSI PHY hardware instance.
  188. * @is_master: Boolean to indicate whether master or slave.
  189. */
  190. void (*dyn_refresh_trigger_sel)(struct dsi_phy_hw *phy,
  191. bool is_master);
  192. /**
  193. * dyn_refresh_config - configure dynamic refresh ctrl registers
  194. * @phy: Pointer to DSI PHY hardware instance.
  195. * @cfg: Pointer to DSI PHY timings.
  196. * @is_master: Boolean to indicate whether for master or slave.
  197. */
  198. void (*dyn_refresh_config)(struct dsi_phy_hw *phy,
  199. struct dsi_phy_cfg *cfg, bool is_master);
  200. /**
  201. * dyn_refresh_pipe_delay - configure pipe delay registers for dynamic
  202. * refresh.
  203. * @phy: Pointer to DSI PHY hardware instance.
  204. * @delay: structure containing all the delays to be programed.
  205. */
  206. void (*dyn_refresh_pipe_delay)(struct dsi_phy_hw *phy,
  207. struct dsi_dyn_clk_delay *delay);
  208. /**
  209. * cache_phy_timings - cache the phy timings calculated as part of
  210. * dynamic refresh.
  211. * @timings: Pointer to calculated phy timing parameters.
  212. * @dst: Pointer to cache location.
  213. * @size: Number of phy lane settings.
  214. */
  215. int (*cache_phy_timings)(struct dsi_phy_per_lane_cfgs *timings,
  216. u32 *dst, u32 size);
  217. };
  218. /**
  219. * struct dsi_phy_hw_ops - Operations for DSI PHY hardware.
  220. * @regulator_enable: Enable PHY regulators.
  221. * @regulator_disable: Disable PHY regulators.
  222. * @enable: Enable PHY.
  223. * @disable: Disable PHY.
  224. * @calculate_timing_params: Calculate PHY timing params from mode information
  225. */
  226. struct dsi_phy_hw_ops {
  227. /**
  228. * regulator_enable() - enable regulators for DSI PHY
  229. * @phy: Pointer to DSI PHY hardware object.
  230. * @reg_cfg: Regulator configuration for all DSI lanes.
  231. */
  232. void (*regulator_enable)(struct dsi_phy_hw *phy,
  233. struct dsi_phy_per_lane_cfgs *reg_cfg);
  234. /**
  235. * regulator_disable() - disable regulators
  236. * @phy: Pointer to DSI PHY hardware object.
  237. */
  238. void (*regulator_disable)(struct dsi_phy_hw *phy);
  239. /**
  240. * enable() - Enable PHY hardware
  241. * @phy: Pointer to DSI PHY hardware object.
  242. * @cfg: Per lane configurations for timing, strength and lane
  243. * configurations.
  244. */
  245. void (*enable)(struct dsi_phy_hw *phy, struct dsi_phy_cfg *cfg);
  246. /**
  247. * disable() - Disable PHY hardware
  248. * @phy: Pointer to DSI PHY hardware object.
  249. * @cfg: Per lane configurations for timing, strength and lane
  250. * configurations.
  251. */
  252. void (*disable)(struct dsi_phy_hw *phy, struct dsi_phy_cfg *cfg);
  253. /**
  254. * phy_idle_on() - Enable PHY hardware when entering idle screen
  255. * @phy: Pointer to DSI PHY hardware object.
  256. * @cfg: Per lane configurations for timing, strength and lane
  257. * configurations.
  258. */
  259. void (*phy_idle_on)(struct dsi_phy_hw *phy, struct dsi_phy_cfg *cfg);
  260. /**
  261. * phy_idle_off() - Disable PHY hardware when exiting idle screen
  262. * @phy: Pointer to DSI PHY hardware object.
  263. */
  264. void (*phy_idle_off)(struct dsi_phy_hw *phy);
  265. /**
  266. * calculate_timing_params() - calculates timing parameters.
  267. * @phy: Pointer to DSI PHY hardware object.
  268. * @mode: Mode information for which timing has to be calculated.
  269. * @config: DSI host configuration for this mode.
  270. * @timing: Timing parameters for each lane which will be returned.
  271. * @use_mode_bit_clk: Boolean to indicate whether reacalculate dsi
  272. * bitclk or use the existing bitclk(for dynamic clk case).
  273. */
  274. int (*calculate_timing_params)(struct dsi_phy_hw *phy,
  275. struct dsi_mode_info *mode,
  276. struct dsi_host_common_cfg *config,
  277. struct dsi_phy_per_lane_cfgs *timing,
  278. bool use_mode_bit_clk);
  279. /**
  280. * phy_timing_val() - Gets PHY timing values.
  281. * @timing_val: Timing parameters for each lane which will be returned.
  282. * @timing: Array containing PHY timing values
  283. * @size: Size of the array
  284. */
  285. int (*phy_timing_val)(struct dsi_phy_per_lane_cfgs *timing_val,
  286. u32 *timing, u32 size);
  287. /**
  288. * clamp_ctrl() - configure clamps for DSI lanes
  289. * @phy: DSI PHY handle.
  290. * @enable: boolean to specify clamp enable/disable.
  291. * Return: error code.
  292. */
  293. void (*clamp_ctrl)(struct dsi_phy_hw *phy, bool enable);
  294. /**
  295. * phy_lane_reset() - Reset dsi phy lanes in case of error.
  296. * @phy: Pointer to DSI PHY hardware object.
  297. * Return: error code.
  298. */
  299. int (*phy_lane_reset)(struct dsi_phy_hw *phy);
  300. /**
  301. * toggle_resync_fifo() - toggle resync retime FIFO to sync data paths
  302. * @phy: Pointer to DSI PHY hardware object.
  303. * Return: error code.
  304. */
  305. void (*toggle_resync_fifo)(struct dsi_phy_hw *phy);
  306. /**
  307. * reset_clk_en_sel() - reset clk_en_sel on phy cmn_clk_cfg1 register
  308. * @phy: Pointer to DSI PHY hardware object.
  309. */
  310. void (*reset_clk_en_sel)(struct dsi_phy_hw *phy);
  311. /**
  312. * set_continuous_clk() - Set continuous clock
  313. * @phy: Pointer to DSI PHY hardware object
  314. * @enable: Bool to control continuous clock request.
  315. */
  316. void (*set_continuous_clk)(struct dsi_phy_hw *phy, bool enable);
  317. /**
  318. * commit_phy_timing() - Commit PHY timing
  319. * @phy: Pointer to DSI PHY hardware object.
  320. * @timing: Pointer to PHY timing array
  321. */
  322. void (*commit_phy_timing)(struct dsi_phy_hw *phy,
  323. struct dsi_phy_per_lane_cfgs *timing);
  324. void *timing_ops;
  325. struct phy_ulps_config_ops ulps_ops;
  326. struct phy_dyn_refresh_ops dyn_refresh_ops;
  327. /**
  328. * configure() - Configure the DSI PHY PLL
  329. * @pll: Pointer to DSI PLL.
  330. * @commit: boolean to specify if calculated PHY configuration
  331. needs to be committed. Set to false in case of
  332. dynamic clock switch.
  333. */
  334. int (*configure)(void *pll, bool commit);
  335. /**
  336. * pll_toggle() - Toggle the DSI PHY PLL
  337. * @pll: Pointer to DSI PLL.
  338. * @prepare: specify if PLL needs to be turned on or off.
  339. */
  340. int (*pll_toggle)(void *pll, bool prepare);
  341. };
  342. /**
  343. * struct dsi_phy_hw - DSI phy hardware object specific to an instance
  344. * @base: VA for the DSI PHY base address.
  345. * @length: Length of the DSI PHY register base map.
  346. * @dyn_pll_base: VA for the DSI dynamic refresh base address.
  347. * @length: Length of the DSI dynamic refresh register base map.
  348. * @index: Instance ID of the controller.
  349. * @version: DSI PHY version.
  350. * @phy_clamp_base: Base address of phy clamp register map.
  351. * @feature_map: Features supported by DSI PHY.
  352. * @ops: Function pointer to PHY operations.
  353. */
  354. struct dsi_phy_hw {
  355. void __iomem *base;
  356. u32 length;
  357. void __iomem *dyn_pll_base;
  358. u32 dyn_refresh_len;
  359. u32 index;
  360. enum dsi_phy_version version;
  361. void __iomem *phy_clamp_base;
  362. DECLARE_BITMAP(feature_map, DSI_PHY_MAX_FEATURES);
  363. struct dsi_phy_hw_ops ops;
  364. };
  365. /**
  366. * dsi_phy_conv_phy_to_logical_lane() - Convert physical to logical lane
  367. * @lane_map: logical lane
  368. * @phy_lane: physical lane
  369. *
  370. * Return: Error code on failure. Lane number on success.
  371. */
  372. int dsi_phy_conv_phy_to_logical_lane(
  373. struct dsi_lane_map *lane_map, enum dsi_phy_data_lanes phy_lane);
  374. /**
  375. * dsi_phy_conv_logical_to_phy_lane() - Convert logical to physical lane
  376. * @lane_map: physical lane
  377. * @lane: logical lane
  378. *
  379. * Return: Error code on failure. Lane number on success.
  380. */
  381. int dsi_phy_conv_logical_to_phy_lane(
  382. struct dsi_lane_map *lane_map, enum dsi_logical_lane lane);
  383. #endif /* _DSI_PHY_HW_H_ */