dsi_phy_hw.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2015-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2021-2023, 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. * @data_lanes: Bitmask of enum dsi_data_lanes.
  109. * @lane_map: DSI logical to PHY lane mapping.
  110. * @force_clk_lane_hs:Boolean whether to force clock lane in HS mode.
  111. * @phy_type: Phy-type (Dphy/Cphy).
  112. * @bit_clk_rate_hz: DSI bit clk rate in HZ.
  113. * @split_link: DSI split link config data.
  114. */
  115. struct dsi_phy_cfg {
  116. struct dsi_phy_per_lane_cfgs lanecfg;
  117. struct dsi_phy_per_lane_cfgs strength;
  118. struct dsi_phy_per_lane_cfgs timing;
  119. bool is_phy_timing_present;
  120. struct dsi_phy_per_lane_cfgs regulators;
  121. enum dsi_phy_pll_source pll_source;
  122. struct dsi_lane_map lane_map;
  123. bool force_clk_lane_hs;
  124. enum dsi_phy_type phy_type;
  125. unsigned long bit_clk_rate_hz;
  126. struct dsi_split_link_config split_link;
  127. u32 data_lanes;
  128. };
  129. struct dsi_phy_hw;
  130. struct phy_ulps_config_ops {
  131. /**
  132. * wait_for_lane_idle() - wait for DSI lanes to go to idle state
  133. * @phy: Pointer to DSI PHY hardware instance.
  134. * @lanes: ORed list of lanes (enum dsi_data_lanes) which need
  135. * to be checked to be in idle state.
  136. */
  137. int (*wait_for_lane_idle)(struct dsi_phy_hw *phy, u32 lanes);
  138. /**
  139. * ulps_request() - request ulps entry for specified lanes
  140. * @phy: Pointer to DSI PHY hardware instance.
  141. * @cfg: Per lane configurations for timing, strength and lane
  142. * configurations.
  143. * @lanes: ORed list of lanes (enum dsi_data_lanes) which need
  144. * to enter ULPS.
  145. *
  146. * Caller should check if lanes are in ULPS mode by calling
  147. * get_lanes_in_ulps() operation.
  148. */
  149. void (*ulps_request)(struct dsi_phy_hw *phy,
  150. struct dsi_phy_cfg *cfg, u32 lanes);
  151. /**
  152. * ulps_exit() - exit ULPS on specified lanes
  153. * @phy: Pointer to DSI PHY hardware instance.
  154. * @cfg: Per lane configurations for timing, strength and lane
  155. * configurations.
  156. * @lanes: ORed list of lanes (enum dsi_data_lanes) which need
  157. * to exit ULPS.
  158. *
  159. * Caller should check if lanes are in active mode by calling
  160. * get_lanes_in_ulps() operation.
  161. */
  162. void (*ulps_exit)(struct dsi_phy_hw *phy,
  163. struct dsi_phy_cfg *cfg, u32 lanes);
  164. /**
  165. * get_lanes_in_ulps() - returns the list of lanes in ULPS mode
  166. * @phy: Pointer to DSI PHY hardware instance.
  167. *
  168. * Returns an ORed list of lanes (enum dsi_data_lanes) that are in ULPS
  169. * state.
  170. *
  171. * Return: List of lanes in ULPS state.
  172. */
  173. u32 (*get_lanes_in_ulps)(struct dsi_phy_hw *phy);
  174. /**
  175. * is_lanes_in_ulps() - checks if the given lanes are in ulps
  176. * @lanes: lanes to be checked.
  177. * @ulps_lanes: lanes in ulps currenly.
  178. *
  179. * Return: true if all the given lanes are in ulps; false otherwise.
  180. */
  181. bool (*is_lanes_in_ulps)(u32 ulps, u32 ulps_lanes);
  182. };
  183. struct phy_dyn_refresh_ops {
  184. /**
  185. * dyn_refresh_helper - helper function to config particular registers
  186. * @phy: Pointer to DSI PHY hardware instance.
  187. * @offset: register offset to program.
  188. */
  189. void (*dyn_refresh_helper)(struct dsi_phy_hw *phy, u32 offset);
  190. /**
  191. * dyn_refresh_trigger_sel - configure trigger_sel to frame flush
  192. * @phy: Pointer to DSI PHY hardware instance.
  193. * @is_master: Boolean to indicate whether master or slave.
  194. */
  195. void (*dyn_refresh_trigger_sel)(struct dsi_phy_hw *phy,
  196. bool is_master);
  197. /**
  198. * dyn_refresh_config - configure dynamic refresh ctrl registers
  199. * @phy: Pointer to DSI PHY hardware instance.
  200. * @cfg: Pointer to DSI PHY timings.
  201. * @is_master: Boolean to indicate whether for master or slave.
  202. */
  203. void (*dyn_refresh_config)(struct dsi_phy_hw *phy,
  204. struct dsi_phy_cfg *cfg, bool is_master);
  205. /**
  206. * dyn_refresh_pipe_delay - configure pipe delay registers for dynamic
  207. * refresh.
  208. * @phy: Pointer to DSI PHY hardware instance.
  209. * @delay: structure containing all the delays to be programed.
  210. */
  211. void (*dyn_refresh_pipe_delay)(struct dsi_phy_hw *phy,
  212. struct dsi_dyn_clk_delay *delay);
  213. /**
  214. * cache_phy_timings - cache the phy timings calculated as part of
  215. * dynamic refresh.
  216. * @timings: Pointer to calculated phy timing parameters.
  217. * @dst: Pointer to cache location.
  218. * @size: Number of phy lane settings.
  219. */
  220. int (*cache_phy_timings)(struct dsi_phy_per_lane_cfgs *timings,
  221. u32 *dst, u32 size);
  222. };
  223. /**
  224. * struct dsi_phy_hw_ops - Operations for DSI PHY hardware.
  225. * @regulator_enable: Enable PHY regulators.
  226. * @regulator_disable: Disable PHY regulators.
  227. * @enable: Enable PHY.
  228. * @disable: Disable PHY.
  229. * @calculate_timing_params: Calculate PHY timing params from mode information
  230. */
  231. struct dsi_phy_hw_ops {
  232. /**
  233. * regulator_enable() - enable regulators for DSI PHY
  234. * @phy: Pointer to DSI PHY hardware object.
  235. * @reg_cfg: Regulator configuration for all DSI lanes.
  236. */
  237. void (*regulator_enable)(struct dsi_phy_hw *phy,
  238. struct dsi_phy_per_lane_cfgs *reg_cfg);
  239. /**
  240. * regulator_disable() - disable regulators
  241. * @phy: Pointer to DSI PHY hardware object.
  242. */
  243. void (*regulator_disable)(struct dsi_phy_hw *phy);
  244. /**
  245. * enable() - Enable PHY hardware
  246. * @phy: Pointer to DSI PHY hardware object.
  247. * @cfg: Per lane configurations for timing, strength and lane
  248. * configurations.
  249. */
  250. void (*enable)(struct dsi_phy_hw *phy, struct dsi_phy_cfg *cfg);
  251. /**
  252. * disable() - Disable PHY hardware
  253. * @phy: Pointer to DSI PHY hardware object.
  254. * @cfg: Per lane configurations for timing, strength and lane
  255. * configurations.
  256. */
  257. void (*disable)(struct dsi_phy_hw *phy, struct dsi_phy_cfg *cfg);
  258. /**
  259. * phy_idle_on() - Enable PHY hardware when entering idle screen
  260. * @phy: Pointer to DSI PHY hardware object.
  261. * @cfg: Per lane configurations for timing, strength and lane
  262. * configurations.
  263. */
  264. void (*phy_idle_on)(struct dsi_phy_hw *phy, struct dsi_phy_cfg *cfg);
  265. /**
  266. * phy_idle_off() - Disable PHY hardware when exiting idle screen
  267. * @phy: Pointer to DSI PHY hardware object.
  268. * @cfg: Per lane configurations for timing, strength and lane
  269. * configurations.
  270. */
  271. void (*phy_idle_off)(struct dsi_phy_hw *phy, struct dsi_phy_cfg *cfg);
  272. /**
  273. * calculate_timing_params() - calculates timing parameters.
  274. * @phy: Pointer to DSI PHY hardware object.
  275. * @mode: Mode information for which timing has to be calculated.
  276. * @config: DSI host configuration for this mode.
  277. * @timing: Timing parameters for each lane which will be returned.
  278. * @use_mode_bit_clk: Boolean to indicate whether reacalculate dsi
  279. * bitclk or use the existing bitclk(for dynamic clk case).
  280. */
  281. int (*calculate_timing_params)(struct dsi_phy_hw *phy,
  282. struct dsi_mode_info *mode,
  283. struct dsi_host_common_cfg *config,
  284. struct dsi_phy_per_lane_cfgs *timing,
  285. bool use_mode_bit_clk);
  286. /**
  287. * phy_timing_val() - Gets PHY timing values.
  288. * @timing_val: Timing parameters for each lane which will be returned.
  289. * @timing: Array containing PHY timing values
  290. * @size: Size of the array
  291. */
  292. int (*phy_timing_val)(struct dsi_phy_per_lane_cfgs *timing_val,
  293. u32 *timing, u32 size);
  294. /**
  295. * clamp_ctrl() - configure clamps for DSI lanes
  296. * @phy: DSI PHY handle.
  297. * @enable: boolean to specify clamp enable/disable.
  298. * Return: error code.
  299. */
  300. void (*clamp_ctrl)(struct dsi_phy_hw *phy, bool enable);
  301. /**
  302. * phy_lane_reset() - Reset dsi phy lanes in case of error.
  303. * @phy: Pointer to DSI PHY hardware object.
  304. * Return: error code.
  305. */
  306. int (*phy_lane_reset)(struct dsi_phy_hw *phy);
  307. /**
  308. * toggle_resync_fifo() - toggle resync retime FIFO to sync data paths
  309. * @phy: Pointer to DSI PHY hardware object.
  310. * Return: error code.
  311. */
  312. void (*toggle_resync_fifo)(struct dsi_phy_hw *phy);
  313. /**
  314. * reset_clk_en_sel() - reset clk_en_sel on phy cmn_clk_cfg1 register
  315. * @phy: Pointer to DSI PHY hardware object.
  316. */
  317. void (*reset_clk_en_sel)(struct dsi_phy_hw *phy);
  318. /**
  319. * set_continuous_clk() - Set continuous clock
  320. * @phy: Pointer to DSI PHY hardware object
  321. * @enable: Bool to control continuous clock request.
  322. */
  323. void (*set_continuous_clk)(struct dsi_phy_hw *phy, bool enable);
  324. /**
  325. * commit_phy_timing() - Commit PHY timing
  326. * @phy: Pointer to DSI PHY hardware object.
  327. * @timing: Pointer to PHY timing array
  328. */
  329. void (*commit_phy_timing)(struct dsi_phy_hw *phy,
  330. struct dsi_phy_per_lane_cfgs *timing);
  331. void *timing_ops;
  332. struct phy_ulps_config_ops ulps_ops;
  333. struct phy_dyn_refresh_ops dyn_refresh_ops;
  334. /**
  335. * configure() - Configure the DSI PHY PLL
  336. * @pll: Pointer to DSI PLL.
  337. * @commit: boolean to specify if calculated PHY configuration
  338. needs to be committed. Set to false in case of
  339. dynamic clock switch.
  340. */
  341. int (*configure)(void *pll, bool commit);
  342. /**
  343. * pll_toggle() - Toggle the DSI PHY PLL
  344. * @pll: Pointer to DSI PLL.
  345. * @prepare: specify if PLL needs to be turned on or off.
  346. */
  347. int (*pll_toggle)(void *pll, bool prepare);
  348. };
  349. /**
  350. * struct dsi_phy_hw - DSI phy hardware object specific to an instance
  351. * @base: VA for the DSI PHY base address.
  352. * @length: Length of the DSI PHY register base map.
  353. * @dyn_pll_base: VA for the DSI dynamic refresh base address.
  354. * @length: Length of the DSI dynamic refresh register base map.
  355. * @index: Instance ID of the controller.
  356. * @phy_pll_bypass: DSI PHY bypass
  357. * @version: DSI PHY version.
  358. * @phy_clamp_base: Base address of phy clamp register map.
  359. * @feature_map: Features supported by DSI PHY.
  360. * @ops: Function pointer to PHY operations.
  361. */
  362. struct dsi_phy_hw {
  363. void __iomem *base;
  364. u32 length;
  365. void __iomem *dyn_pll_base;
  366. u32 dyn_refresh_len;
  367. u32 index;
  368. bool phy_pll_bypass;
  369. enum dsi_phy_version version;
  370. void __iomem *phy_clamp_base;
  371. DECLARE_BITMAP(feature_map, DSI_PHY_MAX_FEATURES);
  372. struct dsi_phy_hw_ops ops;
  373. };
  374. /**
  375. * dsi_phy_conv_phy_to_logical_lane() - Convert physical to logical lane
  376. * @lane_map: logical lane
  377. * @phy_lane: physical lane
  378. *
  379. * Return: Error code on failure. Lane number on success.
  380. */
  381. int dsi_phy_conv_phy_to_logical_lane(
  382. struct dsi_lane_map *lane_map, enum dsi_phy_data_lanes phy_lane);
  383. /**
  384. * dsi_phy_conv_logical_to_phy_lane() - Convert logical to physical lane
  385. * @lane_map: physical lane
  386. * @lane: logical lane
  387. *
  388. * Return: Error code on failure. Lane number on success.
  389. */
  390. int dsi_phy_conv_logical_to_phy_lane(
  391. struct dsi_lane_map *lane_map, enum dsi_logical_lane lane);
  392. #endif /* _DSI_PHY_HW_H_ */