PageRenderTime 124ms CodeModel.GetById 38ms RepoModel.GetById 1ms app.codeStats 0ms

/drivers/staging/sbe-2t3e3/exar7300.c

https://bitbucket.org/wisechild/galaxy-nexus
C | 182 lines | 145 code | 23 blank | 14 comment | 14 complexity | 8c89b6768c3254683a28e6effbc8cb42 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
  1. /*
  2. * SBE 2T3E3 synchronous serial card driver for Linux
  3. *
  4. * Copyright (C) 2009-2010 Krzysztof Halasa <khc@pm.waw.pl>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of version 2 of the GNU General Public License
  8. * as published by the Free Software Foundation.
  9. *
  10. * This code is based on a driver written by SBE Inc.
  11. */
  12. #include "2t3e3.h"
  13. #include "ctrl.h"
  14. void exar7300_init(struct channel *sc)
  15. {
  16. exar7300_write(sc, SBE_2T3E3_LIU_REG_REG1, 0);
  17. /* enable line decodeer and encoder */
  18. exar7300_write(sc, SBE_2T3E3_LIU_REG_REG2, 0);
  19. exar7300_write(sc, SBE_2T3E3_LIU_REG_REG3, 0);
  20. exar7300_write(sc, SBE_2T3E3_LIU_REG_REG4,
  21. SBE_2T3E3_LIU_VAL_T3_MODE_SELECT |
  22. SBE_2T3E3_LIU_VAL_LOOPBACK_OFF);
  23. }
  24. void exar7300_set_loopback(struct channel *sc, u32 mode)
  25. {
  26. u32 val;
  27. switch (mode) {
  28. case SBE_2T3E3_LIU_VAL_LOOPBACK_OFF:
  29. case SBE_2T3E3_LIU_VAL_LOOPBACK_REMOTE:
  30. case SBE_2T3E3_LIU_VAL_LOOPBACK_ANALOG:
  31. case SBE_2T3E3_LIU_VAL_LOOPBACK_DIGITAL:
  32. break;
  33. default:
  34. return;
  35. }
  36. val = exar7300_read(sc, SBE_2T3E3_LIU_REG_REG4);
  37. val &= ~(SBE_2T3E3_LIU_VAL_LOCAL_LOOPBACK | SBE_2T3E3_LIU_VAL_REMOTE_LOOPBACK);
  38. val |= mode;
  39. exar7300_write(sc, SBE_2T3E3_LIU_REG_REG4, val);
  40. #if 0
  41. /* TODO - is it necessary? idea from 2T3E3_HW_Test_code */
  42. switch (mode) {
  43. case SBE_2T3E3_LIU_VAL_LOOPBACK_OFF:
  44. break;
  45. case SBE_2T3E3_LIU_VAL_LOOPBACK_REMOTE:
  46. exar7300_receive_equalization_onoff(sc, SBE_2T3E3_ON);
  47. break;
  48. case SBE_2T3E3_LIU_VAL_LOOPBACK_ANALOG:
  49. exar7300_receive_equalization_onoff(sc, SBE_2T3E3_OFF);
  50. break;
  51. case SBE_2T3E3_LIU_VAL_LOOPBACK_DIGITAL:
  52. exar7300_receive_equalization_onoff(sc, SBE_2T3E3_ON);
  53. break;
  54. }
  55. #endif
  56. }
  57. void exar7300_set_frame_type(struct channel *sc, u32 type)
  58. {
  59. u32 val;
  60. switch (type) {
  61. case SBE_2T3E3_FRAME_TYPE_T3_CBIT:
  62. case SBE_2T3E3_FRAME_TYPE_T3_M13:
  63. case SBE_2T3E3_FRAME_TYPE_E3_G751:
  64. case SBE_2T3E3_FRAME_TYPE_E3_G832:
  65. break;
  66. default:
  67. return;
  68. }
  69. val = exar7300_read(sc, SBE_2T3E3_LIU_REG_REG4);
  70. val &= ~(SBE_2T3E3_LIU_VAL_T3_MODE_SELECT |
  71. SBE_2T3E3_LIU_VAL_E3_MODE_SELECT);
  72. switch (type) {
  73. case SBE_2T3E3_FRAME_TYPE_T3_CBIT:
  74. case SBE_2T3E3_FRAME_TYPE_T3_M13:
  75. val |= SBE_2T3E3_LIU_VAL_T3_MODE_SELECT;
  76. break;
  77. case SBE_2T3E3_FRAME_TYPE_E3_G751:
  78. case SBE_2T3E3_FRAME_TYPE_E3_G832:
  79. val |= SBE_2T3E3_LIU_VAL_E3_MODE_SELECT;
  80. break;
  81. default:
  82. return;
  83. }
  84. exar7300_write(sc, SBE_2T3E3_LIU_REG_REG4, val);
  85. }
  86. void exar7300_transmit_all_ones_onoff(struct channel *sc, u32 mode)
  87. {
  88. if (sc->p.transmit_all_ones == mode)
  89. return;
  90. switch (mode) {
  91. case SBE_2T3E3_ON:
  92. exar7300_set_bit(sc, SBE_2T3E3_LIU_REG_REG1,
  93. SBE_2T3E3_LIU_VAL_TRANSMIT_ALL_ONES);
  94. break;
  95. case SBE_2T3E3_OFF:
  96. exar7300_clear_bit(sc, SBE_2T3E3_LIU_REG_REG1,
  97. SBE_2T3E3_LIU_VAL_TRANSMIT_ALL_ONES);
  98. break;
  99. default:
  100. return;
  101. }
  102. sc->p.transmit_all_ones = mode;
  103. }
  104. void exar7300_receive_equalization_onoff(struct channel *sc, u32 mode)
  105. {
  106. if (sc->p.receive_equalization == mode)
  107. return;
  108. switch (mode) {
  109. case SBE_2T3E3_OFF:
  110. exar7300_set_bit(sc, SBE_2T3E3_LIU_REG_REG2,
  111. SBE_2T3E3_LIU_VAL_RECEIVE_EQUALIZATION_DISABLE);
  112. break;
  113. case SBE_2T3E3_ON:
  114. exar7300_clear_bit(sc, SBE_2T3E3_LIU_REG_REG2,
  115. SBE_2T3E3_LIU_VAL_RECEIVE_EQUALIZATION_DISABLE);
  116. break;
  117. default:
  118. return;
  119. }
  120. sc->p.receive_equalization = mode;
  121. }
  122. void exar7300_line_build_out_onoff(struct channel *sc, u32 mode)
  123. {
  124. if (sc->p.line_build_out == mode)
  125. return;
  126. switch (mode) {
  127. case SBE_2T3E3_OFF:
  128. exar7300_set_bit(sc, SBE_2T3E3_LIU_REG_REG1,
  129. SBE_2T3E3_LIU_VAL_TRANSMIT_LEVEL_SELECT);
  130. exar7300_receive_equalization_onoff(sc, SBE_2T3E3_OFF);
  131. break;
  132. case SBE_2T3E3_ON:
  133. exar7300_clear_bit(sc, SBE_2T3E3_LIU_REG_REG1,
  134. SBE_2T3E3_LIU_VAL_TRANSMIT_LEVEL_SELECT);
  135. exar7300_receive_equalization_onoff(sc, SBE_2T3E3_ON);
  136. break;
  137. default:
  138. return;
  139. }
  140. sc->p.line_build_out = mode;
  141. }
  142. /* TODO - what about encoder in raw mode??? disable it too? */
  143. void exar7300_unipolar_onoff(struct channel *sc, u32 mode)
  144. {
  145. switch (mode) {
  146. case SBE_2T3E3_OFF:
  147. exar7300_clear_bit(sc, SBE_2T3E3_LIU_REG_REG3,
  148. SBE_2T3E3_LIU_VAL_DECODER_DISABLE);
  149. exar7300_clear_bit(sc, SBE_2T3E3_LIU_REG_REG1,
  150. SBE_2T3E3_LIU_VAL_TRANSMIT_BINARY_DATA);
  151. break;
  152. case SBE_2T3E3_ON:
  153. exar7300_set_bit(sc, SBE_2T3E3_LIU_REG_REG3,
  154. SBE_2T3E3_LIU_VAL_DECODER_DISABLE);
  155. exar7300_set_bit(sc, SBE_2T3E3_LIU_REG_REG1,
  156. SBE_2T3E3_LIU_VAL_TRANSMIT_BINARY_DATA);
  157. break;
  158. }
  159. }