lib.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. void snd_fw_schedule_registration(struct fw_unit *unit,
  20. struct delayed_work *dwork);
  21. struct snd_fw_async_midi_port;
  22. typedef int (*snd_fw_async_midi_port_fill)(
  23. struct snd_rawmidi_substream *substream,
  24. u8 *buf);
  25. struct snd_fw_async_midi_port {
  26. struct fw_device *parent;
  27. struct work_struct work;
  28. bool idling;
  29. ktime_t next_ktime;
  30. bool error;
  31. u64 addr;
  32. struct fw_transaction transaction;
  33. u8 *buf;
  34. unsigned int len;
  35. struct snd_rawmidi_substream *substream;
  36. snd_fw_async_midi_port_fill fill;
  37. int consume_bytes;
  38. };
  39. int snd_fw_async_midi_port_init(struct snd_fw_async_midi_port *port,
  40. struct fw_unit *unit, u64 addr, unsigned int len,
  41. snd_fw_async_midi_port_fill fill);
  42. void snd_fw_async_midi_port_destroy(struct snd_fw_async_midi_port *port);
  43. /**
  44. * snd_fw_async_midi_port_run - run transactions for the async MIDI port
  45. * @port: the asynchronous MIDI port
  46. * @substream: the MIDI substream
  47. */
  48. static inline void
  49. snd_fw_async_midi_port_run(struct snd_fw_async_midi_port *port,
  50. struct snd_rawmidi_substream *substream)
  51. {
  52. if (!port->error) {
  53. port->substream = substream;
  54. schedule_work(&port->work);
  55. }
  56. }
  57. /**
  58. * snd_fw_async_midi_port_finish - finish the asynchronous MIDI port
  59. * @port: the asynchronous MIDI port
  60. */
  61. static inline void
  62. snd_fw_async_midi_port_finish(struct snd_fw_async_midi_port *port)
  63. {
  64. port->substream = NULL;
  65. port->error = false;
  66. }
  67. #endif