dsi_phy_hw.h 11 KB

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