tc-dwc-g210.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. /*
  2. * Synopsys G210 Test Chip driver
  3. *
  4. * Copyright (C) 2015-2016 Synopsys, Inc. (www.synopsys.com)
  5. *
  6. * Authors: Joao Pinto <jpinto@synopsys.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include "ufshcd.h"
  13. #include "unipro.h"
  14. #include "ufshcd-dwc.h"
  15. #include "ufshci-dwc.h"
  16. #include "tc-dwc-g210.h"
  17. /**
  18. * tc_dwc_g210_setup_40bit_rmmi()
  19. * This function configures Synopsys TC specific atributes (40-bit RMMI)
  20. * @hba: Pointer to drivers structure
  21. *
  22. * Returns 0 on success or non-zero value on failure
  23. */
  24. static int tc_dwc_g210_setup_40bit_rmmi(struct ufs_hba *hba)
  25. {
  26. const struct ufshcd_dme_attr_val setup_attrs[] = {
  27. { UIC_ARG_MIB(TX_GLOBALHIBERNATE), 0x00, DME_LOCAL },
  28. { UIC_ARG_MIB(REFCLKMODE), 0x01, DME_LOCAL },
  29. { UIC_ARG_MIB(CDIRECTCTRL6), 0x80, DME_LOCAL },
  30. { UIC_ARG_MIB(CBDIVFACTOR), 0x08, DME_LOCAL },
  31. { UIC_ARG_MIB(CBDCOCTRL5), 0x64, DME_LOCAL },
  32. { UIC_ARG_MIB(CBPRGTUNING), 0x09, DME_LOCAL },
  33. { UIC_ARG_MIB(RTOBSERVESELECT), 0x00, DME_LOCAL },
  34. { UIC_ARG_MIB_SEL(TX_REFCLKFREQ, SELIND_LN0_TX), 0x01,
  35. DME_LOCAL },
  36. { UIC_ARG_MIB_SEL(TX_CFGCLKFREQVAL, SELIND_LN0_TX), 0x19,
  37. DME_LOCAL },
  38. { UIC_ARG_MIB_SEL(CFGEXTRATTR, SELIND_LN0_TX), 0x14,
  39. DME_LOCAL },
  40. { UIC_ARG_MIB_SEL(DITHERCTRL2, SELIND_LN0_TX), 0xd6,
  41. DME_LOCAL },
  42. { UIC_ARG_MIB_SEL(RX_REFCLKFREQ, SELIND_LN0_RX), 0x01,
  43. DME_LOCAL },
  44. { UIC_ARG_MIB_SEL(RX_CFGCLKFREQVAL, SELIND_LN0_RX), 0x19,
  45. DME_LOCAL },
  46. { UIC_ARG_MIB_SEL(CFGWIDEINLN, SELIND_LN0_RX), 4,
  47. DME_LOCAL },
  48. { UIC_ARG_MIB_SEL(CFGRXCDR8, SELIND_LN0_RX), 0x80,
  49. DME_LOCAL },
  50. { UIC_ARG_MIB(DIRECTCTRL10), 0x04, DME_LOCAL },
  51. { UIC_ARG_MIB(DIRECTCTRL19), 0x02, DME_LOCAL },
  52. { UIC_ARG_MIB_SEL(CFGRXCDR8, SELIND_LN0_RX), 0x80,
  53. DME_LOCAL },
  54. { UIC_ARG_MIB_SEL(ENARXDIRECTCFG4, SELIND_LN0_RX), 0x03,
  55. DME_LOCAL },
  56. { UIC_ARG_MIB_SEL(CFGRXOVR8, SELIND_LN0_RX), 0x16,
  57. DME_LOCAL },
  58. { UIC_ARG_MIB_SEL(RXDIRECTCTRL2, SELIND_LN0_RX), 0x42,
  59. DME_LOCAL },
  60. { UIC_ARG_MIB_SEL(ENARXDIRECTCFG3, SELIND_LN0_RX), 0xa4,
  61. DME_LOCAL },
  62. { UIC_ARG_MIB_SEL(RXCALCTRL, SELIND_LN0_RX), 0x01,
  63. DME_LOCAL },
  64. { UIC_ARG_MIB_SEL(ENARXDIRECTCFG2, SELIND_LN0_RX), 0x01,
  65. DME_LOCAL },
  66. { UIC_ARG_MIB_SEL(CFGRXOVR4, SELIND_LN0_RX), 0x28,
  67. DME_LOCAL },
  68. { UIC_ARG_MIB_SEL(RXSQCTRL, SELIND_LN0_RX), 0x1E,
  69. DME_LOCAL },
  70. { UIC_ARG_MIB_SEL(CFGRXOVR6, SELIND_LN0_RX), 0x2f,
  71. DME_LOCAL },
  72. { UIC_ARG_MIB_SEL(CFGRXOVR6, SELIND_LN0_RX), 0x2f,
  73. DME_LOCAL },
  74. { UIC_ARG_MIB(CBPRGPLL2), 0x00, DME_LOCAL },
  75. };
  76. return ufshcd_dwc_dme_set_attrs(hba, setup_attrs,
  77. ARRAY_SIZE(setup_attrs));
  78. }
  79. /**
  80. * tc_dwc_g210_setup_20bit_rmmi_lane0()
  81. * This function configures Synopsys TC 20-bit RMMI Lane 0
  82. * @hba: Pointer to drivers structure
  83. *
  84. * Returns 0 on success or non-zero value on failure
  85. */
  86. static int tc_dwc_g210_setup_20bit_rmmi_lane0(struct ufs_hba *hba)
  87. {
  88. const struct ufshcd_dme_attr_val setup_attrs[] = {
  89. { UIC_ARG_MIB_SEL(TX_REFCLKFREQ, SELIND_LN0_TX), 0x01,
  90. DME_LOCAL },
  91. { UIC_ARG_MIB_SEL(TX_CFGCLKFREQVAL, SELIND_LN0_TX), 0x19,
  92. DME_LOCAL },
  93. { UIC_ARG_MIB_SEL(RX_CFGCLKFREQVAL, SELIND_LN0_RX), 0x19,
  94. DME_LOCAL },
  95. { UIC_ARG_MIB_SEL(CFGEXTRATTR, SELIND_LN0_TX), 0x12,
  96. DME_LOCAL },
  97. { UIC_ARG_MIB_SEL(DITHERCTRL2, SELIND_LN0_TX), 0xd6,
  98. DME_LOCAL },
  99. { UIC_ARG_MIB_SEL(RX_REFCLKFREQ, SELIND_LN0_RX), 0x01,
  100. DME_LOCAL },
  101. { UIC_ARG_MIB_SEL(CFGWIDEINLN, SELIND_LN0_RX), 2,
  102. DME_LOCAL },
  103. { UIC_ARG_MIB_SEL(CFGRXCDR8, SELIND_LN0_RX), 0x80,
  104. DME_LOCAL },
  105. { UIC_ARG_MIB(DIRECTCTRL10), 0x04, DME_LOCAL },
  106. { UIC_ARG_MIB(DIRECTCTRL19), 0x02, DME_LOCAL },
  107. { UIC_ARG_MIB_SEL(ENARXDIRECTCFG4, SELIND_LN0_RX), 0x03,
  108. DME_LOCAL },
  109. { UIC_ARG_MIB_SEL(CFGRXOVR8, SELIND_LN0_RX), 0x16,
  110. DME_LOCAL },
  111. { UIC_ARG_MIB_SEL(RXDIRECTCTRL2, SELIND_LN0_RX), 0x42,
  112. DME_LOCAL },
  113. { UIC_ARG_MIB_SEL(ENARXDIRECTCFG3, SELIND_LN0_RX), 0xa4,
  114. DME_LOCAL },
  115. { UIC_ARG_MIB_SEL(RXCALCTRL, SELIND_LN0_RX), 0x01,
  116. DME_LOCAL },
  117. { UIC_ARG_MIB_SEL(ENARXDIRECTCFG2, SELIND_LN0_RX), 0x01,
  118. DME_LOCAL },
  119. { UIC_ARG_MIB_SEL(CFGRXOVR4, SELIND_LN0_RX), 0x28,
  120. DME_LOCAL },
  121. { UIC_ARG_MIB_SEL(RXSQCTRL, SELIND_LN0_RX), 0x1E,
  122. DME_LOCAL },
  123. { UIC_ARG_MIB_SEL(CFGRXOVR6, SELIND_LN0_RX), 0x2f,
  124. DME_LOCAL },
  125. { UIC_ARG_MIB(CBPRGPLL2), 0x00, DME_LOCAL },
  126. };
  127. return ufshcd_dwc_dme_set_attrs(hba, setup_attrs,
  128. ARRAY_SIZE(setup_attrs));
  129. }
  130. /**
  131. * tc_dwc_g210_setup_20bit_rmmi_lane1()
  132. * This function configures Synopsys TC 20-bit RMMI Lane 1
  133. * @hba: Pointer to drivers structure
  134. *
  135. * Returns 0 on success or non-zero value on failure
  136. */
  137. static int tc_dwc_g210_setup_20bit_rmmi_lane1(struct ufs_hba *hba)
  138. {
  139. int connected_rx_lanes = 0;
  140. int connected_tx_lanes = 0;
  141. int ret = 0;
  142. const struct ufshcd_dme_attr_val setup_tx_attrs[] = {
  143. { UIC_ARG_MIB_SEL(TX_REFCLKFREQ, SELIND_LN1_TX), 0x0d,
  144. DME_LOCAL },
  145. { UIC_ARG_MIB_SEL(TX_CFGCLKFREQVAL, SELIND_LN1_TX), 0x19,
  146. DME_LOCAL },
  147. { UIC_ARG_MIB_SEL(CFGEXTRATTR, SELIND_LN1_TX), 0x12,
  148. DME_LOCAL },
  149. { UIC_ARG_MIB_SEL(DITHERCTRL2, SELIND_LN0_TX), 0xd6,
  150. DME_LOCAL },
  151. };
  152. const struct ufshcd_dme_attr_val setup_rx_attrs[] = {
  153. { UIC_ARG_MIB_SEL(RX_REFCLKFREQ, SELIND_LN1_RX), 0x01,
  154. DME_LOCAL },
  155. { UIC_ARG_MIB_SEL(RX_CFGCLKFREQVAL, SELIND_LN1_RX), 0x19,
  156. DME_LOCAL },
  157. { UIC_ARG_MIB_SEL(CFGWIDEINLN, SELIND_LN1_RX), 2,
  158. DME_LOCAL },
  159. { UIC_ARG_MIB_SEL(CFGRXCDR8, SELIND_LN1_RX), 0x80,
  160. DME_LOCAL },
  161. { UIC_ARG_MIB_SEL(ENARXDIRECTCFG4, SELIND_LN1_RX), 0x03,
  162. DME_LOCAL },
  163. { UIC_ARG_MIB_SEL(CFGRXOVR8, SELIND_LN1_RX), 0x16,
  164. DME_LOCAL },
  165. { UIC_ARG_MIB_SEL(RXDIRECTCTRL2, SELIND_LN1_RX), 0x42,
  166. DME_LOCAL },
  167. { UIC_ARG_MIB_SEL(ENARXDIRECTCFG3, SELIND_LN1_RX), 0xa4,
  168. DME_LOCAL },
  169. { UIC_ARG_MIB_SEL(RXCALCTRL, SELIND_LN1_RX), 0x01,
  170. DME_LOCAL },
  171. { UIC_ARG_MIB_SEL(ENARXDIRECTCFG2, SELIND_LN1_RX), 0x01,
  172. DME_LOCAL },
  173. { UIC_ARG_MIB_SEL(CFGRXOVR4, SELIND_LN1_RX), 0x28,
  174. DME_LOCAL },
  175. { UIC_ARG_MIB_SEL(RXSQCTRL, SELIND_LN1_RX), 0x1E,
  176. DME_LOCAL },
  177. { UIC_ARG_MIB_SEL(CFGRXOVR6, SELIND_LN1_RX), 0x2f,
  178. DME_LOCAL },
  179. };
  180. /* Get the available lane count */
  181. ufshcd_dme_get(hba, UIC_ARG_MIB(PA_AVAILRXDATALANES),
  182. &connected_rx_lanes);
  183. ufshcd_dme_get(hba, UIC_ARG_MIB(PA_AVAILTXDATALANES),
  184. &connected_tx_lanes);
  185. if (connected_tx_lanes == 2) {
  186. ret = ufshcd_dwc_dme_set_attrs(hba, setup_tx_attrs,
  187. ARRAY_SIZE(setup_tx_attrs));
  188. if (ret)
  189. goto out;
  190. }
  191. if (connected_rx_lanes == 2) {
  192. ret = ufshcd_dwc_dme_set_attrs(hba, setup_rx_attrs,
  193. ARRAY_SIZE(setup_rx_attrs));
  194. }
  195. out:
  196. return ret;
  197. }
  198. /**
  199. * tc_dwc_g210_setup_20bit_rmmi()
  200. * This function configures Synopsys TC specific atributes (20-bit RMMI)
  201. * @hba: Pointer to drivers structure
  202. *
  203. * Returns 0 on success or non-zero value on failure
  204. */
  205. static int tc_dwc_g210_setup_20bit_rmmi(struct ufs_hba *hba)
  206. {
  207. int ret = 0;
  208. const struct ufshcd_dme_attr_val setup_attrs[] = {
  209. { UIC_ARG_MIB(TX_GLOBALHIBERNATE), 0x00, DME_LOCAL },
  210. { UIC_ARG_MIB(REFCLKMODE), 0x01, DME_LOCAL },
  211. { UIC_ARG_MIB(CDIRECTCTRL6), 0xc0, DME_LOCAL },
  212. { UIC_ARG_MIB(CBDIVFACTOR), 0x44, DME_LOCAL },
  213. { UIC_ARG_MIB(CBDCOCTRL5), 0x64, DME_LOCAL },
  214. { UIC_ARG_MIB(CBPRGTUNING), 0x09, DME_LOCAL },
  215. { UIC_ARG_MIB(RTOBSERVESELECT), 0x00, DME_LOCAL },
  216. };
  217. ret = ufshcd_dwc_dme_set_attrs(hba, setup_attrs,
  218. ARRAY_SIZE(setup_attrs));
  219. if (ret)
  220. goto out;
  221. /* Lane 0 configuration*/
  222. ret = tc_dwc_g210_setup_20bit_rmmi_lane0(hba);
  223. if (ret)
  224. goto out;
  225. /* Lane 1 configuration*/
  226. ret = tc_dwc_g210_setup_20bit_rmmi_lane1(hba);
  227. if (ret)
  228. goto out;
  229. out:
  230. return ret;
  231. }
  232. /**
  233. * tc_dwc_g210_config_40_bit()
  234. * This function configures Local (host) Synopsys 40-bit TC specific attributes
  235. *
  236. * @hba: Pointer to drivers structure
  237. *
  238. * Returns 0 on success non-zero value on failure
  239. */
  240. int tc_dwc_g210_config_40_bit(struct ufs_hba *hba)
  241. {
  242. int ret = 0;
  243. dev_info(hba->dev, "Configuring Test Chip 40-bit RMMI\n");
  244. ret = tc_dwc_g210_setup_40bit_rmmi(hba);
  245. if (ret) {
  246. dev_err(hba->dev, "Configuration failed\n");
  247. goto out;
  248. }
  249. /* To write Shadow register bank to effective configuration block */
  250. ret = ufshcd_dme_set(hba, UIC_ARG_MIB(VS_MPHYCFGUPDT), 0x01);
  251. if (ret)
  252. goto out;
  253. /* To configure Debug OMC */
  254. ret = ufshcd_dme_set(hba, UIC_ARG_MIB(VS_DEBUGOMC), 0x01);
  255. out:
  256. return ret;
  257. }
  258. EXPORT_SYMBOL(tc_dwc_g210_config_40_bit);
  259. /**
  260. * tc_dwc_g210_config_20_bit()
  261. * This function configures Local (host) Synopsys 20-bit TC specific attributes
  262. *
  263. * @hba: Pointer to drivers structure
  264. *
  265. * Returns 0 on success non-zero value on failure
  266. */
  267. int tc_dwc_g210_config_20_bit(struct ufs_hba *hba)
  268. {
  269. int ret = 0;
  270. dev_info(hba->dev, "Configuring Test Chip 20-bit RMMI\n");
  271. ret = tc_dwc_g210_setup_20bit_rmmi(hba);
  272. if (ret) {
  273. dev_err(hba->dev, "Configuration failed\n");
  274. goto out;
  275. }
  276. /* To write Shadow register bank to effective configuration block */
  277. ret = ufshcd_dme_set(hba, UIC_ARG_MIB(VS_MPHYCFGUPDT), 0x01);
  278. if (ret)
  279. goto out;
  280. /* To configure Debug OMC */
  281. ret = ufshcd_dme_set(hba, UIC_ARG_MIB(VS_DEBUGOMC), 0x01);
  282. out:
  283. return ret;
  284. }
  285. EXPORT_SYMBOL(tc_dwc_g210_config_20_bit);
  286. MODULE_AUTHOR("Joao Pinto <Joao.Pinto@synopsys.com>");
  287. MODULE_DESCRIPTION("Synopsys G210 Test Chip driver");
  288. MODULE_LICENSE("Dual BSD/GPL");