lib.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #ifndef SOUND_FIREWIRE_LIB_H_INCLUDED
  2. #define SOUND_FIREWIRE_LIB_H_INCLUDED
  3. #include <linux/firewire-constants.h>
  4. #include <linux/types.h>
  5. #include <linux/sched.h>
  6. #include <sound/rawmidi.h>
  7. struct fw_unit;
  8. #define FW_GENERATION_MASK 0x00ff
  9. #define FW_FIXED_GENERATION 0x0100
  10. #define FW_QUIET 0x0200
  11. int snd_fw_transaction(struct fw_unit *unit, int tcode,
  12. u64 offset, void *buffer, size_t length,
  13. unsigned int flags);
  14. /* returns true if retrying the transaction would not make sense */
  15. static inline bool rcode_is_permanent_error(int rcode)
  16. {
  17. return rcode == RCODE_TYPE_ERROR || rcode == RCODE_ADDRESS_ERROR;
  18. }
  19. struct snd_fw_async_midi_port;
  20. typedef int (*snd_fw_async_midi_port_fill)(
  21. struct snd_rawmidi_substream *substream,
  22. u8 *buf);
  23. struct snd_fw_async_midi_port {
  24. struct fw_device *parent;
  25. struct work_struct work;
  26. bool idling;
  27. ktime_t next_ktime;
  28. bool error;
  29. u64 addr;
  30. struct fw_transaction transaction;
  31. u8 *buf;
  32. unsigned int len;
  33. struct snd_rawmidi_substream *substream;
  34. snd_fw_async_midi_port_fill fill;
  35. int consume_bytes;
  36. };
  37. int snd_fw_async_midi_port_init(struct snd_fw_async_midi_port *port,
  38. struct fw_unit *unit, u64 addr, unsigned int len,
  39. snd_fw_async_midi_port_fill fill);
  40. void snd_fw_async_midi_port_destroy(struct snd_fw_async_midi_port *port);
  41. /**
  42. * snd_fw_async_midi_port_run - run transactions for the async MIDI port
  43. * @port: the asynchronous MIDI port
  44. * @substream: the MIDI substream
  45. */
  46. static inline void
  47. snd_fw_async_midi_port_run(struct snd_fw_async_midi_port *port,
  48. struct snd_rawmidi_substream *substream)
  49. {
  50. if (!port->error) {
  51. port->substream = substream;
  52. schedule_work(&port->work);
  53. }
  54. }
  55. /**
  56. * snd_fw_async_midi_port_finish - finish the asynchronous MIDI port
  57. * @port: the asynchronous MIDI port
  58. */
  59. static inline void
  60. snd_fw_async_midi_port_finish(struct snd_fw_async_midi_port *port)
  61. {
  62. port->substream = NULL;
  63. port->error = false;
  64. }
  65. #endif