oxfw-command.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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) && (err < len + 10))
  33. err = -EIO;
  34. else if (buf[0] == 0x08) /* NOT IMPLEMENTED */
  35. err = -ENOSYS;
  36. else if (buf[0] == 0x0a) /* REJECTED */
  37. err = -EINVAL;
  38. else
  39. err = 0;
  40. kfree(buf);
  41. return err;
  42. }
  43. int avc_stream_get_format(struct fw_unit *unit,
  44. enum avc_general_plug_dir dir, unsigned int pid,
  45. u8 *buf, unsigned int *len, unsigned int eid)
  46. {
  47. unsigned int subfunc;
  48. int err;
  49. if (eid == 0xff)
  50. subfunc = 0xc0; /* SINGLE */
  51. else
  52. subfunc = 0xc1; /* LIST */
  53. buf[0] = 0x01; /* STATUS */
  54. buf[1] = 0xff; /* UNIT */
  55. buf[2] = 0xbf; /* EXTENDED STREAM FORMAT INFORMATION */
  56. buf[3] = subfunc; /* SINGLE or LIST */
  57. buf[4] = dir; /* Plug Direction */
  58. buf[5] = 0x00; /* Unit */
  59. buf[6] = 0x00; /* PCR (Isochronous Plug) */
  60. buf[7] = 0xff & pid; /* Plug ID */
  61. buf[8] = 0xff; /* Padding */
  62. buf[9] = 0xff; /* support status in response */
  63. buf[10] = 0xff & eid; /* entry ID for LIST subfunction */
  64. buf[11] = 0xff; /* padding */
  65. /* do transaction and check buf[1-7] are the same against command */
  66. err = fcp_avc_transaction(unit, buf, 12, buf, *len,
  67. BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(5) |
  68. BIT(6) | BIT(7));
  69. if ((err > 0) && (err < 10))
  70. err = -EIO;
  71. else if (buf[0] == 0x08) /* NOT IMPLEMENTED */
  72. err = -ENOSYS;
  73. else if (buf[0] == 0x0a) /* REJECTED */
  74. err = -EINVAL;
  75. else if (buf[0] == 0x0b) /* IN TRANSITION */
  76. err = -EAGAIN;
  77. /* LIST subfunction has entry ID */
  78. else if ((subfunc == 0xc1) && (buf[10] != eid))
  79. err = -EIO;
  80. if (err < 0)
  81. goto end;
  82. /* keep just stream format information */
  83. if (subfunc == 0xc0) {
  84. memmove(buf, buf + 10, err - 10);
  85. *len = err - 10;
  86. } else {
  87. memmove(buf, buf + 11, err - 11);
  88. *len = err - 11;
  89. }
  90. err = 0;
  91. end:
  92. return err;
  93. }
  94. int avc_general_inquiry_sig_fmt(struct fw_unit *unit, unsigned int rate,
  95. enum avc_general_plug_dir dir,
  96. unsigned short pid)
  97. {
  98. unsigned int sfc;
  99. u8 *buf;
  100. int err;
  101. for (sfc = 0; sfc < CIP_SFC_COUNT; sfc++) {
  102. if (amdtp_rate_table[sfc] == rate)
  103. break;
  104. }
  105. if (sfc == CIP_SFC_COUNT)
  106. return -EINVAL;
  107. buf = kzalloc(8, GFP_KERNEL);
  108. if (buf == NULL)
  109. return -ENOMEM;
  110. buf[0] = 0x02; /* SPECIFIC INQUIRY */
  111. buf[1] = 0xff; /* UNIT */
  112. if (dir == AVC_GENERAL_PLUG_DIR_IN)
  113. buf[2] = 0x19; /* INPUT PLUG SIGNAL FORMAT */
  114. else
  115. buf[2] = 0x18; /* OUTPUT PLUG SIGNAL FORMAT */
  116. buf[3] = 0xff & pid; /* plug id */
  117. buf[4] = 0x90; /* EOH_1, Form_1, FMT. AM824 */
  118. buf[5] = 0x07 & sfc; /* FDF-hi. AM824, frequency */
  119. buf[6] = 0xff; /* FDF-mid. AM824, SYT hi (not used) */
  120. buf[7] = 0xff; /* FDF-low. AM824, SYT lo (not used) */
  121. /* do transaction and check buf[1-5] are the same against command */
  122. err = fcp_avc_transaction(unit, buf, 8, buf, 8,
  123. BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(5));
  124. if ((err > 0) && (err < 8))
  125. err = -EIO;
  126. else if (buf[0] == 0x08) /* NOT IMPLEMENTED */
  127. err = -ENOSYS;
  128. if (err < 0)
  129. goto end;
  130. err = 0;
  131. end:
  132. kfree(buf);
  133. return err;
  134. }