dsi_phy_hw.h 12 KB

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