dsi_phy_hw.h 12 KB

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