bebob_command.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. /*
  2. * bebob_command.c - driver for BeBoB based devices
  3. *
  4. * Copyright (c) 2013-2014 Takashi Sakamoto
  5. *
  6. * Licensed under the terms of the GNU General Public License, version 2.
  7. */
  8. #include "./bebob.h"
  9. int avc_audio_set_selector(struct fw_unit *unit, unsigned int subunit_id,
  10. unsigned int fb_id, unsigned int num)
  11. {
  12. u8 *buf;
  13. int err;
  14. buf = kzalloc(12, GFP_KERNEL);
  15. if (buf == NULL)
  16. return -ENOMEM;
  17. buf[0] = 0x00; /* AV/C CONTROL */
  18. buf[1] = 0x08 | (0x07 & subunit_id); /* AUDIO SUBUNIT ID */
  19. buf[2] = 0xb8; /* FUNCTION BLOCK */
  20. buf[3] = 0x80; /* type is 'selector'*/
  21. buf[4] = 0xff & fb_id; /* function block id */
  22. buf[5] = 0x10; /* control attribute is CURRENT */
  23. buf[6] = 0x02; /* selector length is 2 */
  24. buf[7] = 0xff & num; /* input function block plug number */
  25. buf[8] = 0x01; /* control selector is SELECTOR_CONTROL */
  26. err = fcp_avc_transaction(unit, buf, 12, buf, 12,
  27. BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(5) |
  28. BIT(6) | BIT(7) | BIT(8));
  29. if (err > 0 && err < 9)
  30. err = -EIO;
  31. else if (buf[0] == 0x08) /* NOT IMPLEMENTED */
  32. err = -ENOSYS;
  33. else if (buf[0] == 0x0a) /* REJECTED */
  34. err = -EINVAL;
  35. else if (err > 0)
  36. err = 0;
  37. kfree(buf);
  38. return err;
  39. }
  40. int avc_audio_get_selector(struct fw_unit *unit, unsigned int subunit_id,
  41. unsigned int fb_id, unsigned int *num)
  42. {
  43. u8 *buf;
  44. int err;
  45. buf = kzalloc(12, GFP_KERNEL);
  46. if (buf == NULL)
  47. return -ENOMEM;
  48. buf[0] = 0x01; /* AV/C STATUS */
  49. buf[1] = 0x08 | (0x07 & subunit_id); /* AUDIO SUBUNIT ID */
  50. buf[2] = 0xb8; /* FUNCTION BLOCK */
  51. buf[3] = 0x80; /* type is 'selector'*/
  52. buf[4] = 0xff & fb_id; /* function block id */
  53. buf[5] = 0x10; /* control attribute is CURRENT */
  54. buf[6] = 0x02; /* selector length is 2 */
  55. buf[7] = 0xff; /* input function block plug number */
  56. buf[8] = 0x01; /* control selector is SELECTOR_CONTROL */
  57. err = fcp_avc_transaction(unit, buf, 12, buf, 12,
  58. BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(5) |
  59. BIT(6) | BIT(8));
  60. if (err > 0 && err < 9)
  61. err = -EIO;
  62. else if (buf[0] == 0x08) /* NOT IMPLEMENTED */
  63. err = -ENOSYS;
  64. else if (buf[0] == 0x0a) /* REJECTED */
  65. err = -EINVAL;
  66. else if (buf[0] == 0x0b) /* IN TRANSITION */
  67. err = -EAGAIN;
  68. if (err < 0)
  69. goto end;
  70. *num = buf[7];
  71. err = 0;
  72. end:
  73. kfree(buf);
  74. return err;
  75. }
  76. static inline void
  77. avc_bridgeco_fill_extension_addr(u8 *buf, u8 *addr)
  78. {
  79. buf[1] = addr[0];
  80. memcpy(buf + 4, addr + 1, 5);
  81. }
  82. static inline void
  83. avc_bridgeco_fill_plug_info_extension_command(u8 *buf, u8 *addr,
  84. unsigned int itype)
  85. {
  86. buf[0] = 0x01; /* AV/C STATUS */
  87. buf[2] = 0x02; /* AV/C GENERAL PLUG INFO */
  88. buf[3] = 0xc0; /* BridgeCo extension */
  89. avc_bridgeco_fill_extension_addr(buf, addr);
  90. buf[9] = itype; /* info type */
  91. }
  92. int avc_bridgeco_get_plug_type(struct fw_unit *unit,
  93. u8 addr[AVC_BRIDGECO_ADDR_BYTES],
  94. enum avc_bridgeco_plug_type *type)
  95. {
  96. u8 *buf;
  97. int err;
  98. buf = kzalloc(12, GFP_KERNEL);
  99. if (buf == NULL)
  100. return -ENOMEM;
  101. /* Info type is 'plug type'. */
  102. avc_bridgeco_fill_plug_info_extension_command(buf, addr, 0x00);
  103. err = fcp_avc_transaction(unit, buf, 12, buf, 12,
  104. BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(5) |
  105. BIT(6) | BIT(7) | BIT(9));
  106. if ((err >= 0) && (err < 8))
  107. err = -EIO;
  108. else if (buf[0] == 0x08) /* NOT IMPLEMENTED */
  109. err = -ENOSYS;
  110. else if (buf[0] == 0x0a) /* REJECTED */
  111. err = -EINVAL;
  112. else if (buf[0] == 0x0b) /* IN TRANSITION */
  113. err = -EAGAIN;
  114. if (err < 0)
  115. goto end;
  116. *type = buf[10];
  117. err = 0;
  118. end:
  119. kfree(buf);
  120. return err;
  121. }
  122. int avc_bridgeco_get_plug_ch_pos(struct fw_unit *unit,
  123. u8 addr[AVC_BRIDGECO_ADDR_BYTES],
  124. u8 *buf, unsigned int len)
  125. {
  126. int err;
  127. /* Info type is 'channel position'. */
  128. avc_bridgeco_fill_plug_info_extension_command(buf, addr, 0x03);
  129. err = fcp_avc_transaction(unit, buf, 12, buf, 256,
  130. BIT(1) | BIT(2) | BIT(3) | BIT(4) |
  131. BIT(5) | BIT(6) | BIT(7) | BIT(9));
  132. if ((err >= 0) && (err < 8))
  133. err = -EIO;
  134. else if (buf[0] == 0x08) /* NOT IMPLEMENTED */
  135. err = -ENOSYS;
  136. else if (buf[0] == 0x0a) /* REJECTED */
  137. err = -EINVAL;
  138. else if (buf[0] == 0x0b) /* IN TRANSITION */
  139. err = -EAGAIN;
  140. if (err < 0)
  141. goto end;
  142. /* Pick up specific data. */
  143. memmove(buf, buf + 10, err - 10);
  144. err = 0;
  145. end:
  146. return err;
  147. }
  148. int avc_bridgeco_get_plug_section_type(struct fw_unit *unit,
  149. u8 addr[AVC_BRIDGECO_ADDR_BYTES],
  150. unsigned int id, u8 *type)
  151. {
  152. u8 *buf;
  153. int err;
  154. /* section info includes charactors but this module don't need it */
  155. buf = kzalloc(12, GFP_KERNEL);
  156. if (buf == NULL)
  157. return -ENOMEM;
  158. /* Info type is 'section info'. */
  159. avc_bridgeco_fill_plug_info_extension_command(buf, addr, 0x07);
  160. buf[10] = 0xff & ++id; /* section id */
  161. err = fcp_avc_transaction(unit, buf, 12, buf, 12,
  162. BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(5) |
  163. BIT(6) | BIT(7) | BIT(9) | BIT(10));
  164. if ((err >= 0) && (err < 8))
  165. err = -EIO;
  166. else if (buf[0] == 0x08) /* NOT IMPLEMENTED */
  167. err = -ENOSYS;
  168. else if (buf[0] == 0x0a) /* REJECTED */
  169. err = -EINVAL;
  170. else if (buf[0] == 0x0b) /* IN TRANSITION */
  171. err = -EAGAIN;
  172. if (err < 0)
  173. goto end;
  174. *type = buf[11];
  175. err = 0;
  176. end:
  177. kfree(buf);
  178. return err;
  179. }
  180. int avc_bridgeco_get_plug_input(struct fw_unit *unit,
  181. u8 addr[AVC_BRIDGECO_ADDR_BYTES], u8 input[7])
  182. {
  183. int err;
  184. u8 *buf;
  185. buf = kzalloc(18, GFP_KERNEL);
  186. if (buf == NULL)
  187. return -ENOMEM;
  188. /* Info type is 'plug input'. */
  189. avc_bridgeco_fill_plug_info_extension_command(buf, addr, 0x05);
  190. err = fcp_avc_transaction(unit, buf, 16, buf, 16,
  191. BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(5) |
  192. BIT(6) | BIT(7));
  193. if ((err >= 0) && (err < 8))
  194. err = -EIO;
  195. else if (buf[0] == 0x08) /* NOT IMPLEMENTED */
  196. err = -ENOSYS;
  197. else if (buf[0] == 0x0a) /* REJECTED */
  198. err = -EINVAL;
  199. else if (buf[0] == 0x0b) /* IN TRANSITION */
  200. err = -EAGAIN;
  201. if (err < 0)
  202. goto end;
  203. memcpy(input, buf + 10, 5);
  204. err = 0;
  205. end:
  206. kfree(buf);
  207. return err;
  208. }
  209. int avc_bridgeco_get_plug_strm_fmt(struct fw_unit *unit,
  210. u8 addr[AVC_BRIDGECO_ADDR_BYTES], u8 *buf,
  211. unsigned int *len, unsigned int eid)
  212. {
  213. int err;
  214. /* check given buffer */
  215. if ((buf == NULL) || (*len < 12)) {
  216. err = -EINVAL;
  217. goto end;
  218. }
  219. buf[0] = 0x01; /* AV/C STATUS */
  220. buf[2] = 0x2f; /* AV/C STREAM FORMAT SUPPORT */
  221. buf[3] = 0xc1; /* Bridgeco extension - List Request */
  222. avc_bridgeco_fill_extension_addr(buf, addr);
  223. buf[10] = 0xff & eid; /* Entry ID */
  224. err = fcp_avc_transaction(unit, buf, 12, buf, *len,
  225. BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(5) |
  226. BIT(6) | BIT(7) | BIT(10));
  227. if ((err >= 0) && (err < 12))
  228. err = -EIO;
  229. else if (buf[0] == 0x08) /* NOT IMPLEMENTED */
  230. err = -ENOSYS;
  231. else if (buf[0] == 0x0a) /* REJECTED */
  232. err = -EINVAL;
  233. else if (buf[0] == 0x0b) /* IN TRANSITION */
  234. err = -EAGAIN;
  235. else if (buf[10] != eid)
  236. err = -EIO;
  237. if (err < 0)
  238. goto end;
  239. /* Pick up 'stream format info'. */
  240. memmove(buf, buf + 11, err - 11);
  241. *len = err - 11;
  242. err = 0;
  243. end:
  244. return err;
  245. }