dsi_phy_hw.h 14 KB

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