vsc3316_3308.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. /*
  2. * Copyright 2012 Freescale Semiconductor, Inc.
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include "vsc3316_3308.h"
  7. #define REVISION_ID_REG 0x7E
  8. #define INTERFACE_MODE_REG 0x79
  9. #define CURRENT_PAGE_REGISTER 0x7F
  10. #define CONNECTION_CONFIG_PAGE 0x00
  11. #define INPUT_STATE_REG 0x13
  12. #define GLOBAL_INPUT_ISE1 0x51
  13. #define GLOBAL_INPUT_ISE2 0x52
  14. #define GLOBAL_INPUT_GAIN 0x53
  15. #define GLOBAL_INPUT_LOS 0x55
  16. #define GLOBAL_OUTPUT_PE1 0x56
  17. #define GLOBAL_OUTPUT_PE2 0x57
  18. #define GLOBAL_OUTPUT_LEVEL 0x58
  19. #define GLOBAL_OUTPUT_TERMINATION 0x5A
  20. #define GLOBAL_CORE_CNTRL 0x5D
  21. #define OUTPUT_MODE_PAGE 0x23
  22. #define CORE_CONTROL_PAGE 0x25
  23. #define CORE_CONFIG_REG 0x75
  24. int vsc_if_enable(unsigned int vsc_addr)
  25. {
  26. u8 data;
  27. debug("VSC:Configuring VSC at I2C address 0x%2x"
  28. " for 2-wire interface\n", vsc_addr);
  29. /* enable 2-wire Serial InterFace (I2C) */
  30. data = 0x02;
  31. return i2c_write(vsc_addr, INTERFACE_MODE_REG, 1, &data, 1);
  32. }
  33. int vsc3316_config(unsigned int vsc_addr, int8_t con_arr[][2],
  34. unsigned int num_con)
  35. {
  36. unsigned int i;
  37. u8 rev_id = 0;
  38. int ret;
  39. debug("VSC:Initializing VSC3316 at I2C address 0x%2x"
  40. " for Tx\n", vsc_addr);
  41. ret = i2c_read(vsc_addr, REVISION_ID_REG, 1, &rev_id, 1);
  42. if (ret < 0) {
  43. printf("VSC:0x%x could not read REV_ID from device.\n",
  44. vsc_addr);
  45. return ret;
  46. }
  47. if (rev_id != 0xab) {
  48. printf("VSC: device at address 0x%x is not VSC3316/3308.\n",
  49. vsc_addr);
  50. return -ENODEV;
  51. }
  52. ret = vsc_if_enable(vsc_addr);
  53. if (ret) {
  54. printf("VSC:0x%x could not configured for 2-wire I/F.\n",
  55. vsc_addr);
  56. return ret;
  57. }
  58. /* config connections - page 0x00 */
  59. i2c_reg_write(vsc_addr, CURRENT_PAGE_REGISTER, CONNECTION_CONFIG_PAGE);
  60. /* Making crosspoint connections, by connecting required
  61. * input to output */
  62. for (i = 0; i < num_con ; i++)
  63. i2c_reg_write(vsc_addr, con_arr[i][1], con_arr[i][0]);
  64. /* input state - page 0x13 */
  65. i2c_reg_write(vsc_addr, CURRENT_PAGE_REGISTER, INPUT_STATE_REG);
  66. /* Configuring the required input of the switch */
  67. for (i = 0; i < num_con ; i++)
  68. i2c_reg_write(vsc_addr, con_arr[i][0], 0x80);
  69. /* Setting Global Input LOS threshold value */
  70. i2c_reg_write(vsc_addr, GLOBAL_INPUT_LOS, 0x60);
  71. /* config output mode - page 0x23 */
  72. i2c_reg_write(vsc_addr, CURRENT_PAGE_REGISTER, OUTPUT_MODE_PAGE);
  73. /* Turn ON the Output driver correspond to required output*/
  74. for (i = 0; i < num_con ; i++)
  75. i2c_reg_write(vsc_addr, con_arr[i][1], 0);
  76. /* configure global core control register, Turn on Global core power */
  77. i2c_reg_write(vsc_addr, GLOBAL_CORE_CNTRL, 0);
  78. vsc_wp_config(vsc_addr);
  79. return 0;
  80. }
  81. #ifdef CONFIG_SYS_FSL_B4860QDS_XFI_ERR
  82. int vsc3308_config_adjust(unsigned int vsc_addr, const int8_t con_arr[][2],
  83. unsigned int num_con)
  84. {
  85. unsigned int i;
  86. u8 rev_id = 0;
  87. int ret;
  88. debug("VSC:Initializing VSC3308 at I2C address 0x%x for Tx\n",
  89. vsc_addr);
  90. ret = i2c_read(vsc_addr, REVISION_ID_REG, 1, &rev_id, 1);
  91. if (ret < 0) {
  92. printf("VSC:0x%x could not read REV_ID from device.\n",
  93. vsc_addr);
  94. return ret;
  95. }
  96. if (rev_id != 0xab) {
  97. printf("VSC: device at address 0x%x is not VSC3316/3308.\n",
  98. vsc_addr);
  99. return -ENODEV;
  100. }
  101. ret = vsc_if_enable(vsc_addr);
  102. if (ret) {
  103. printf("VSC:0x%x could not configured for 2-wire I/F.\n",
  104. vsc_addr);
  105. return ret;
  106. }
  107. /* config connections - page 0x00 */
  108. i2c_reg_write(vsc_addr, CURRENT_PAGE_REGISTER, CONNECTION_CONFIG_PAGE);
  109. /* Configure Global Input ISE */
  110. i2c_reg_write(vsc_addr, GLOBAL_INPUT_ISE1, 0);
  111. i2c_reg_write(vsc_addr, GLOBAL_INPUT_ISE2, 0);
  112. /* Configure Tx/Rx Global Output PE1 */
  113. i2c_reg_write(vsc_addr, GLOBAL_OUTPUT_PE1, 0);
  114. /* Configure Tx/Rx Global Output PE2 */
  115. i2c_reg_write(vsc_addr, GLOBAL_OUTPUT_PE2, 0);
  116. /* Configure Tx/Rx Global Input GAIN */
  117. i2c_reg_write(vsc_addr, GLOBAL_INPUT_GAIN, 0x3F);
  118. /* Setting Global Input LOS threshold value */
  119. i2c_reg_write(vsc_addr, GLOBAL_INPUT_LOS, 0xE0);
  120. /* Setting Global output termination */
  121. i2c_reg_write(vsc_addr, GLOBAL_OUTPUT_TERMINATION, 0);
  122. /* Configure Tx/Rx Global Output level */
  123. if (vsc_addr == VSC3308_TX_ADDRESS)
  124. i2c_reg_write(vsc_addr, GLOBAL_OUTPUT_LEVEL, 4);
  125. else
  126. i2c_reg_write(vsc_addr, GLOBAL_OUTPUT_LEVEL, 2);
  127. /* Making crosspoint connections, by connecting required
  128. * input to output */
  129. for (i = 0; i < num_con ; i++)
  130. i2c_reg_write(vsc_addr, con_arr[i][1], con_arr[i][0]);
  131. /* input state - page 0x13 */
  132. i2c_reg_write(vsc_addr, CURRENT_PAGE_REGISTER, INPUT_STATE_REG);
  133. /* Turning off all the required input of the switch */
  134. for (i = 0; i < num_con; i++)
  135. i2c_reg_write(vsc_addr, con_arr[i][0], 1);
  136. /* only turn on specific Tx/Rx requested by the XFI erratum */
  137. if (vsc_addr == VSC3308_TX_ADDRESS) {
  138. i2c_reg_write(vsc_addr, 2, 0);
  139. i2c_reg_write(vsc_addr, 3, 0);
  140. } else {
  141. i2c_reg_write(vsc_addr, 0, 0);
  142. i2c_reg_write(vsc_addr, 1, 0);
  143. }
  144. /* config output mode - page 0x23 */
  145. i2c_reg_write(vsc_addr, CURRENT_PAGE_REGISTER, OUTPUT_MODE_PAGE);
  146. /* Turn off the Output driver correspond to required output*/
  147. for (i = 0; i < num_con ; i++)
  148. i2c_reg_write(vsc_addr, con_arr[i][1], 1);
  149. /* only turn on specific Tx/Rx requested by the XFI erratum */
  150. if (vsc_addr == VSC3308_TX_ADDRESS) {
  151. i2c_reg_write(vsc_addr, 0, 0);
  152. i2c_reg_write(vsc_addr, 1, 0);
  153. } else {
  154. i2c_reg_write(vsc_addr, 3, 0);
  155. i2c_reg_write(vsc_addr, 4, 0);
  156. }
  157. /* configure global core control register, Turn on Global core power */
  158. i2c_reg_write(vsc_addr, GLOBAL_CORE_CNTRL, 0);
  159. vsc_wp_config(vsc_addr);
  160. return 0;
  161. }
  162. #endif
  163. int vsc3308_config(unsigned int vsc_addr, const int8_t con_arr[][2],
  164. unsigned int num_con)
  165. {
  166. unsigned int i;
  167. u8 rev_id = 0;
  168. int ret;
  169. debug("VSC:Initializing VSC3308 at I2C address 0x%x"
  170. " for Tx\n", vsc_addr);
  171. ret = i2c_read(vsc_addr, REVISION_ID_REG, 1, &rev_id, 1);
  172. if (ret < 0) {
  173. printf("VSC:0x%x could not read REV_ID from device.\n",
  174. vsc_addr);
  175. return ret;
  176. }
  177. if (rev_id != 0xab) {
  178. printf("VSC: device at address 0x%x is not VSC3316/3308.\n",
  179. vsc_addr);
  180. return -ENODEV;
  181. }
  182. ret = vsc_if_enable(vsc_addr);
  183. if (ret) {
  184. printf("VSC:0x%x could not configured for 2-wire I/F.\n",
  185. vsc_addr);
  186. return ret;
  187. }
  188. /* config connections - page 0x00 */
  189. i2c_reg_write(vsc_addr, CURRENT_PAGE_REGISTER, CONNECTION_CONFIG_PAGE);
  190. /* Making crosspoint connections, by connecting required
  191. * input to output */
  192. for (i = 0; i < num_con ; i++)
  193. i2c_reg_write(vsc_addr, con_arr[i][1], con_arr[i][0]);
  194. /*Configure Global Input ISE and gain */
  195. i2c_reg_write(vsc_addr, GLOBAL_INPUT_ISE1, 0x12);
  196. i2c_reg_write(vsc_addr, GLOBAL_INPUT_ISE2, 0x12);
  197. /* input state - page 0x13 */
  198. i2c_reg_write(vsc_addr, CURRENT_PAGE_REGISTER, INPUT_STATE_REG);
  199. /* Turning ON the required input of the switch */
  200. for (i = 0; i < num_con ; i++)
  201. i2c_reg_write(vsc_addr, con_arr[i][0], 0);
  202. /* Setting Global Input LOS threshold value */
  203. i2c_reg_write(vsc_addr, GLOBAL_INPUT_LOS, 0x60);
  204. /* config output mode - page 0x23 */
  205. i2c_reg_write(vsc_addr, CURRENT_PAGE_REGISTER, OUTPUT_MODE_PAGE);
  206. /* Turn ON the Output driver correspond to required output*/
  207. for (i = 0; i < num_con ; i++)
  208. i2c_reg_write(vsc_addr, con_arr[i][1], 0);
  209. /* configure global core control register, Turn on Global core power */
  210. i2c_reg_write(vsc_addr, GLOBAL_CORE_CNTRL, 0);
  211. vsc_wp_config(vsc_addr);
  212. return 0;
  213. }
  214. void vsc_wp_config(unsigned int vsc_addr)
  215. {
  216. debug("VSC:Configuring VSC at address:0x%x for WP\n", vsc_addr);
  217. /* For new crosspoint configuration to occur, WP bit of
  218. * CORE_CONFIG_REG should be set 1 and then reset to 0 */
  219. i2c_reg_write(vsc_addr, CORE_CONFIG_REG, 0x01);
  220. i2c_reg_write(vsc_addr, CORE_CONFIG_REG, 0x0);
  221. }