oxfw-command.c 3.9 KB

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