vsc3316_3308.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. * Copyright 2012 Freescale Semiconductor, Inc.
  3. *
  4. * See file CREDITS for list of people who contributed to this
  5. * project.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. */
  22. #include "vsc3316_3308.h"
  23. #define REVISION_ID_REG 0x7E
  24. #define INTERFACE_MODE_REG 0x79
  25. #define CURRENT_PAGE_REGISTER 0x7F
  26. #define CONNECTION_CONFIG_PAGE 0x00
  27. #define INPUT_STATE_REG 0x13
  28. #define GLOBAL_INPUT_ISE1 0x51
  29. #define GLOBAL_INPUT_ISE2 0x52
  30. #define GLOBAL_INPUT_LOS 0x55
  31. #define GLOBAL_CORE_CNTRL 0x5D
  32. #define OUTPUT_MODE_PAGE 0x23
  33. #define CORE_CONTROL_PAGE 0x25
  34. #define CORE_CONFIG_REG 0x75
  35. int vsc_if_enable(unsigned int vsc_addr)
  36. {
  37. u8 data;
  38. debug("VSC:Configuring VSC at I2C address 0x%2x"
  39. " for 2-wire interface\n", vsc_addr);
  40. /* enable 2-wire Serial InterFace (I2C) */
  41. data = 0x02;
  42. return i2c_write(vsc_addr, INTERFACE_MODE_REG, 1, &data, 1);
  43. }
  44. int vsc3316_config(unsigned int vsc_addr, const int8_t con_arr[][2],
  45. unsigned int num_con)
  46. {
  47. unsigned int i;
  48. u8 rev_id = 0;
  49. int ret;
  50. debug("VSC:Initializing VSC3316 at I2C address 0x%2x"
  51. " for Tx\n", vsc_addr);
  52. ret = i2c_read(vsc_addr, REVISION_ID_REG, 1, &rev_id, 1);
  53. if (ret < 0) {
  54. printf("VSC:0x%x could not read REV_ID from device.\n",
  55. vsc_addr);
  56. return ret;
  57. }
  58. if (rev_id != 0xab) {
  59. printf("VSC: device at address 0x%x is not VSC3316/3308.\n",
  60. vsc_addr);
  61. return -ENODEV;
  62. }
  63. ret = vsc_if_enable(vsc_addr);
  64. if (ret) {
  65. printf("VSC:0x%x could not configured for 2-wire I/F.\n",
  66. vsc_addr);
  67. return ret;
  68. }
  69. /* config connections - page 0x00 */
  70. i2c_reg_write(vsc_addr, CURRENT_PAGE_REGISTER, CONNECTION_CONFIG_PAGE);
  71. /* Making crosspoint connections, by connecting required
  72. * input to output */
  73. for (i = 0; i < num_con ; i++)
  74. i2c_reg_write(vsc_addr, con_arr[i][1], con_arr[i][0]);
  75. /* input state - page 0x13 */
  76. i2c_reg_write(vsc_addr, CURRENT_PAGE_REGISTER, INPUT_STATE_REG);
  77. /* Configuring the required input of the switch */
  78. for (i = 0; i < num_con ; i++)
  79. i2c_reg_write(vsc_addr, con_arr[i][0], 0x80);
  80. /* Setting Global Input LOS threshold value */
  81. i2c_reg_write(vsc_addr, GLOBAL_INPUT_LOS, 0x60);
  82. /* config output mode - page 0x23 */
  83. i2c_reg_write(vsc_addr, CURRENT_PAGE_REGISTER, OUTPUT_MODE_PAGE);
  84. /* Turn ON the Output driver correspond to required output*/
  85. for (i = 0; i < num_con ; i++)
  86. i2c_reg_write(vsc_addr, con_arr[i][1], 0);
  87. /* configure global core control register, Turn on Global core power */
  88. i2c_reg_write(vsc_addr, GLOBAL_CORE_CNTRL, 0);
  89. vsc_wp_config(vsc_addr);
  90. return 0;
  91. }
  92. int vsc3308_config(unsigned int vsc_addr, const int8_t con_arr[][2],
  93. unsigned int num_con)
  94. {
  95. unsigned int i;
  96. u8 rev_id = 0;
  97. int ret;
  98. debug("VSC:Initializing VSC3308 at I2C address 0x%x"
  99. " for Tx\n", vsc_addr);
  100. ret = i2c_read(vsc_addr, REVISION_ID_REG, 1, &rev_id, 1);
  101. if (ret < 0) {
  102. printf("VSC:0x%x could not read REV_ID from device.\n",
  103. vsc_addr);
  104. return ret;
  105. }
  106. if (rev_id != 0xab) {
  107. printf("VSC: device at address 0x%x is not VSC3316/3308.\n",
  108. vsc_addr);
  109. return -ENODEV;
  110. }
  111. ret = vsc_if_enable(vsc_addr);
  112. if (ret) {
  113. printf("VSC:0x%x could not configured for 2-wire I/F.\n",
  114. vsc_addr);
  115. return ret;
  116. }
  117. /* config connections - page 0x00 */
  118. i2c_reg_write(vsc_addr, CURRENT_PAGE_REGISTER, CONNECTION_CONFIG_PAGE);
  119. /* Making crosspoint connections, by connecting required
  120. * input to output */
  121. for (i = 0; i < num_con ; i++)
  122. i2c_reg_write(vsc_addr, con_arr[i][1], con_arr[i][0]);
  123. /*Configure Global Input ISE and gain */
  124. i2c_reg_write(vsc_addr, GLOBAL_INPUT_ISE1, 0x12);
  125. i2c_reg_write(vsc_addr, GLOBAL_INPUT_ISE2, 0x12);
  126. /* input state - page 0x13 */
  127. i2c_reg_write(vsc_addr, CURRENT_PAGE_REGISTER, INPUT_STATE_REG);
  128. /* Turning ON the required input of the switch */
  129. for (i = 0; i < num_con ; i++)
  130. i2c_reg_write(vsc_addr, con_arr[i][0], 0);
  131. /* Setting Global Input LOS threshold value */
  132. i2c_reg_write(vsc_addr, GLOBAL_INPUT_LOS, 0x60);
  133. /* config output mode - page 0x23 */
  134. i2c_reg_write(vsc_addr, CURRENT_PAGE_REGISTER, OUTPUT_MODE_PAGE);
  135. /* Turn ON the Output driver correspond to required output*/
  136. for (i = 0; i < num_con ; i++)
  137. i2c_reg_write(vsc_addr, con_arr[i][1], 0);
  138. /* configure global core control register, Turn on Global core power */
  139. i2c_reg_write(vsc_addr, GLOBAL_CORE_CNTRL, 0);
  140. vsc_wp_config(vsc_addr);
  141. return 0;
  142. }
  143. void vsc_wp_config(unsigned int vsc_addr)
  144. {
  145. debug("VSC:Configuring VSC at address:0x%x for WP\n", vsc_addr);
  146. /* For new crosspoint configuration to occur, WP bit of
  147. * CORE_CONFIG_REG should be set 1 and then reset to 0 */
  148. i2c_reg_write(vsc_addr, CORE_CONFIG_REG, 0x01);
  149. i2c_reg_write(vsc_addr, CORE_CONFIG_REG, 0x0);
  150. }