oxfw-command.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * oxfw_command.c - a part of driver for OXFW970/971 based devices
  3. *
  4. * Copyright (c) 2014 Takashi Sakamoto
  5. *
  6. * Licensed under the terms of the GNU General Public License, version 2.
  7. */
  8. #include "oxfw.h"
  9. int avc_stream_set_format(struct fw_unit *unit, enum avc_general_plug_dir dir,
  10. unsigned int pid, u8 *format, unsigned int len)
  11. {
  12. u8 *buf;
  13. int err;
  14. buf = kmalloc(len + 10, GFP_KERNEL);
  15. if (buf == NULL)
  16. return -ENOMEM;
  17. buf[0] = 0x00; /* CONTROL */
  18. buf[1] = 0xff; /* UNIT */
  19. buf[2] = 0xbf; /* EXTENDED STREAM FORMAT INFORMATION */
  20. buf[3] = 0xc0; /* SINGLE subfunction */
  21. buf[4] = dir; /* Plug Direction */
  22. buf[5] = 0x00; /* UNIT */
  23. buf[6] = 0x00; /* PCR (Isochronous Plug) */
  24. buf[7] = 0xff & pid; /* Plug ID */
  25. buf[8] = 0xff; /* Padding */
  26. buf[9] = 0xff; /* Support status in response */
  27. memcpy(buf + 10, format, len);
  28. /* do transaction and check buf[1-8] are the same against command */
  29. err = fcp_avc_transaction(unit, buf, len + 10, buf, len + 10,
  30. BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(5) |
  31. BIT(6) | BIT(7) | BIT(8));
  32. if (err < 0)
  33. ;
  34. else if (err < len + 10)
  35. err = -EIO;
  36. else if (buf[0] == 0x08) /* NOT IMPLEMENTED */
  37. err = -ENOSYS;
  38. else if (buf[0] == 0x0a) /* REJECTED */
  39. err = -EINVAL;
  40. else
  41. err = 0;
  42. kfree(buf);
  43. return err;
  44. }
  45. int avc_stream_get_format(struct fw_unit *unit,
  46. enum avc_general_plug_dir dir, unsigned int pid,
  47. u8 *buf, unsigned int *len, unsigned int eid)
  48. {
  49. unsigned int subfunc;
  50. int err;
  51. if (eid == 0xff)
  52. subfunc = 0xc0; /* SINGLE */
  53. else
  54. subfunc = 0xc1; /* LIST */
  55. buf[0] = 0x01; /* STATUS */
  56. buf[1] = 0xff; /* UNIT */
  57. buf[2] = 0xbf; /* EXTENDED STREAM FORMAT INFORMATION */
  58. buf[3] = subfunc; /* SINGLE or LIST */
  59. buf[4] = dir; /* Plug Direction */
  60. buf[5] = 0x00; /* Unit */
  61. buf[6] = 0x00; /* PCR (Isochronous Plug) */
  62. buf[7] = 0xff & pid; /* Plug ID */
  63. buf[8] = 0xff; /* Padding */
  64. buf[9] = 0xff; /* support status in response */
  65. buf[10] = 0xff & eid; /* entry ID for LIST subfunction */
  66. buf[11] = 0xff; /* padding */
  67. /* do transaction and check buf[1-7] are the same against command */
  68. err = fcp_avc_transaction(unit, buf, 12, buf, *len,
  69. BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(5) |
  70. BIT(6) | BIT(7));
  71. if (err < 0)
  72. ;
  73. else if (err < 12)
  74. err = -EIO;
  75. else if (buf[0] == 0x08) /* NOT IMPLEMENTED */
  76. err = -ENOSYS;
  77. else if (buf[0] == 0x0a) /* REJECTED */
  78. err = -EINVAL;
  79. else if (buf[0] == 0x0b) /* IN TRANSITION */
  80. err = -EAGAIN;
  81. /* LIST subfunction has entry ID */
  82. else if ((subfunc == 0xc1) && (buf[10] != eid))
  83. err = -EIO;
  84. if (err < 0)
  85. goto end;
  86. /* keep just stream format information */
  87. if (subfunc == 0xc0) {
  88. memmove(buf, buf + 10, err - 10);
  89. *len = err - 10;
  90. } else {
  91. memmove(buf, buf + 11, err - 11);
  92. *len = err - 11;
  93. }
  94. err = 0;
  95. end:
  96. return err;
  97. }
  98. int avc_general_inquiry_sig_fmt(struct fw_unit *unit, unsigned int rate,
  99. enum avc_general_plug_dir dir,
  100. unsigned short pid)
  101. {
  102. unsigned int sfc;
  103. u8 *buf;
  104. int err;
  105. for (sfc = 0; sfc < CIP_SFC_COUNT; sfc++) {
  106. if (amdtp_rate_table[sfc] == rate)
  107. break;
  108. }
  109. if (sfc == CIP_SFC_COUNT)
  110. return -EINVAL;
  111. buf = kzalloc(8, GFP_KERNEL);
  112. if (buf == NULL)
  113. return -ENOMEM;
  114. buf[0] = 0x02; /* SPECIFIC INQUIRY */
  115. buf[1] = 0xff; /* UNIT */
  116. if (dir == AVC_GENERAL_PLUG_DIR_IN)
  117. buf[2] = 0x19; /* INPUT PLUG SIGNAL FORMAT */
  118. else
  119. buf[2] = 0x18; /* OUTPUT PLUG SIGNAL FORMAT */
  120. buf[3] = 0xff & pid; /* plug id */
  121. buf[4] = 0x90; /* EOH_1, Form_1, FMT. AM824 */
  122. buf[5] = 0x07 & sfc; /* FDF-hi. AM824, frequency */
  123. buf[6] = 0xff; /* FDF-mid. AM824, SYT hi (not used) */
  124. buf[7] = 0xff; /* FDF-low. AM824, SYT lo (not used) */
  125. /* do transaction and check buf[1-5] are the same against command */
  126. err = fcp_avc_transaction(unit, buf, 8, buf, 8,
  127. BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(5));
  128. if (err < 0)
  129. ;
  130. else if (err < 8)
  131. err = -EIO;
  132. else if (buf[0] == 0x08) /* NOT IMPLEMENTED */
  133. err = -ENOSYS;
  134. if (err < 0)
  135. goto end;
  136. err = 0;
  137. end:
  138. kfree(buf);
  139. return err;
  140. }