as10x_cmd_cfg.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*
  2. * Abilis Systems Single DVB-T Receiver
  3. * Copyright (C) 2008 Pierrick Hascoet <pierrick.hascoet@abilis.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2, or (at your option)
  8. * any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #include <linux/kernel.h>
  16. #include "as102_drv.h"
  17. #include "as10x_cmd.h"
  18. /***************************/
  19. /* FUNCTION DEFINITION */
  20. /***************************/
  21. /**
  22. * as10x_cmd_get_context - Send get context command to AS10x
  23. * @adap: pointer to AS10x bus adapter
  24. * @tag: context tag
  25. * @pvalue: pointer where to store context value read
  26. *
  27. * Return 0 on success or negative value in case of error.
  28. */
  29. int as10x_cmd_get_context(struct as10x_bus_adapter_t *adap, uint16_t tag,
  30. uint32_t *pvalue)
  31. {
  32. int error;
  33. struct as10x_cmd_t *pcmd, *prsp;
  34. pcmd = adap->cmd;
  35. prsp = adap->rsp;
  36. /* prepare command */
  37. as10x_cmd_build(pcmd, (++adap->cmd_xid),
  38. sizeof(pcmd->body.context.req));
  39. /* fill command */
  40. pcmd->body.context.req.proc_id = cpu_to_le16(CONTROL_PROC_CONTEXT);
  41. pcmd->body.context.req.tag = cpu_to_le16(tag);
  42. pcmd->body.context.req.type = cpu_to_le16(GET_CONTEXT_DATA);
  43. /* send command */
  44. if (adap->ops->xfer_cmd) {
  45. error = adap->ops->xfer_cmd(adap,
  46. (uint8_t *) pcmd,
  47. sizeof(pcmd->body.context.req)
  48. + HEADER_SIZE,
  49. (uint8_t *) prsp,
  50. sizeof(prsp->body.context.rsp)
  51. + HEADER_SIZE);
  52. } else {
  53. error = AS10X_CMD_ERROR;
  54. }
  55. if (error < 0)
  56. goto out;
  57. /* parse response: context command do not follow the common response */
  58. /* structure -> specific handling response parse required */
  59. error = as10x_context_rsp_parse(prsp, CONTROL_PROC_CONTEXT_RSP);
  60. if (error == 0) {
  61. /* Response OK -> get response data */
  62. *pvalue = le32_to_cpu((__force __le32)prsp->body.context.rsp.reg_val.u.value32);
  63. /* value returned is always a 32-bit value */
  64. }
  65. out:
  66. return error;
  67. }
  68. /**
  69. * as10x_cmd_set_context - send set context command to AS10x
  70. * @adap: pointer to AS10x bus adapter
  71. * @tag: context tag
  72. * @value: value to set in context
  73. *
  74. * Return 0 on success or negative value in case of error.
  75. */
  76. int as10x_cmd_set_context(struct as10x_bus_adapter_t *adap, uint16_t tag,
  77. uint32_t value)
  78. {
  79. int error;
  80. struct as10x_cmd_t *pcmd, *prsp;
  81. pcmd = adap->cmd;
  82. prsp = adap->rsp;
  83. /* prepare command */
  84. as10x_cmd_build(pcmd, (++adap->cmd_xid),
  85. sizeof(pcmd->body.context.req));
  86. /* fill command */
  87. pcmd->body.context.req.proc_id = cpu_to_le16(CONTROL_PROC_CONTEXT);
  88. /* pcmd->body.context.req.reg_val.mode initialization is not required */
  89. pcmd->body.context.req.reg_val.u.value32 = (__force u32)cpu_to_le32(value);
  90. pcmd->body.context.req.tag = cpu_to_le16(tag);
  91. pcmd->body.context.req.type = cpu_to_le16(SET_CONTEXT_DATA);
  92. /* send command */
  93. if (adap->ops->xfer_cmd) {
  94. error = adap->ops->xfer_cmd(adap,
  95. (uint8_t *) pcmd,
  96. sizeof(pcmd->body.context.req)
  97. + HEADER_SIZE,
  98. (uint8_t *) prsp,
  99. sizeof(prsp->body.context.rsp)
  100. + HEADER_SIZE);
  101. } else {
  102. error = AS10X_CMD_ERROR;
  103. }
  104. if (error < 0)
  105. goto out;
  106. /* parse response: context command do not follow the common response */
  107. /* structure -> specific handling response parse required */
  108. error = as10x_context_rsp_parse(prsp, CONTROL_PROC_CONTEXT_RSP);
  109. out:
  110. return error;
  111. }
  112. /**
  113. * as10x_cmd_eLNA_change_mode - send eLNA change mode command to AS10x
  114. * @adap: pointer to AS10x bus adapter
  115. * @mode: mode selected:
  116. * - ON : 0x0 => eLNA always ON
  117. * - OFF : 0x1 => eLNA always OFF
  118. * - AUTO : 0x2 => eLNA follow hysteresis parameters
  119. * to be ON or OFF
  120. *
  121. * Return 0 on success or negative value in case of error.
  122. */
  123. int as10x_cmd_eLNA_change_mode(struct as10x_bus_adapter_t *adap, uint8_t mode)
  124. {
  125. int error;
  126. struct as10x_cmd_t *pcmd, *prsp;
  127. pcmd = adap->cmd;
  128. prsp = adap->rsp;
  129. /* prepare command */
  130. as10x_cmd_build(pcmd, (++adap->cmd_xid),
  131. sizeof(pcmd->body.cfg_change_mode.req));
  132. /* fill command */
  133. pcmd->body.cfg_change_mode.req.proc_id =
  134. cpu_to_le16(CONTROL_PROC_ELNA_CHANGE_MODE);
  135. pcmd->body.cfg_change_mode.req.mode = mode;
  136. /* send command */
  137. if (adap->ops->xfer_cmd) {
  138. error = adap->ops->xfer_cmd(adap, (uint8_t *) pcmd,
  139. sizeof(pcmd->body.cfg_change_mode.req)
  140. + HEADER_SIZE, (uint8_t *) prsp,
  141. sizeof(prsp->body.cfg_change_mode.rsp)
  142. + HEADER_SIZE);
  143. } else {
  144. error = AS10X_CMD_ERROR;
  145. }
  146. if (error < 0)
  147. goto out;
  148. /* parse response */
  149. error = as10x_rsp_parse(prsp, CONTROL_PROC_ELNA_CHANGE_MODE_RSP);
  150. out:
  151. return error;
  152. }
  153. /**
  154. * as10x_context_rsp_parse - Parse context command response
  155. * @prsp: pointer to AS10x command response buffer
  156. * @proc_id: id of the command
  157. *
  158. * Since the contex command response does not follow the common
  159. * response, a specific parse function is required.
  160. * Return 0 on success or negative value in case of error.
  161. */
  162. int as10x_context_rsp_parse(struct as10x_cmd_t *prsp, uint16_t proc_id)
  163. {
  164. int err;
  165. err = prsp->body.context.rsp.error;
  166. if ((err == 0) &&
  167. (le16_to_cpu(prsp->body.context.rsp.proc_id) == proc_id)) {
  168. return 0;
  169. }
  170. return AS10X_CMD_ERROR;
  171. }