18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef CAIAQ_DEVICE_H
38c2ecf20Sopenharmony_ci#define CAIAQ_DEVICE_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#include "../usbaudio.h"
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#define USB_VID_NATIVEINSTRUMENTS 0x17cc
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#define USB_PID_RIGKONTROL2		0x1969
108c2ecf20Sopenharmony_ci#define USB_PID_RIGKONTROL3		0x1940
118c2ecf20Sopenharmony_ci#define USB_PID_KORECONTROLLER		0x4711
128c2ecf20Sopenharmony_ci#define USB_PID_KORECONTROLLER2		0x4712
138c2ecf20Sopenharmony_ci#define USB_PID_AK1			0x0815
148c2ecf20Sopenharmony_ci#define USB_PID_AUDIO2DJ		0x041c
158c2ecf20Sopenharmony_ci#define USB_PID_AUDIO4DJ		0x0839
168c2ecf20Sopenharmony_ci#define USB_PID_AUDIO8DJ		0x1978
178c2ecf20Sopenharmony_ci#define USB_PID_SESSIONIO		0x1915
188c2ecf20Sopenharmony_ci#define USB_PID_GUITARRIGMOBILE		0x0d8d
198c2ecf20Sopenharmony_ci#define USB_PID_TRAKTORKONTROLX1	0x2305
208c2ecf20Sopenharmony_ci#define USB_PID_TRAKTORKONTROLS4	0xbaff
218c2ecf20Sopenharmony_ci#define USB_PID_TRAKTORAUDIO2		0x041d
228c2ecf20Sopenharmony_ci#define USB_PID_MASCHINECONTROLLER  0x0808
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci#define EP1_BUFSIZE 64
258c2ecf20Sopenharmony_ci#define EP4_BUFSIZE 512
268c2ecf20Sopenharmony_ci#define CAIAQ_USB_STR_LEN 0xff
278c2ecf20Sopenharmony_ci#define MAX_STREAMS 32
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci#define MODNAME "snd-usb-caiaq"
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci#define EP1_CMD_GET_DEVICE_INFO	0x1
328c2ecf20Sopenharmony_ci#define EP1_CMD_READ_ERP	0x2
338c2ecf20Sopenharmony_ci#define EP1_CMD_READ_ANALOG	0x3
348c2ecf20Sopenharmony_ci#define EP1_CMD_READ_IO		0x4
358c2ecf20Sopenharmony_ci#define EP1_CMD_WRITE_IO	0x5
368c2ecf20Sopenharmony_ci#define EP1_CMD_MIDI_READ	0x6
378c2ecf20Sopenharmony_ci#define EP1_CMD_MIDI_WRITE	0x7
388c2ecf20Sopenharmony_ci#define EP1_CMD_AUDIO_PARAMS	0x9
398c2ecf20Sopenharmony_ci#define EP1_CMD_AUTO_MSG	0xb
408c2ecf20Sopenharmony_ci#define EP1_CMD_DIMM_LEDS       0xc
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_cistruct caiaq_device_spec {
438c2ecf20Sopenharmony_ci	unsigned short fw_version;
448c2ecf20Sopenharmony_ci	unsigned char hw_subtype;
458c2ecf20Sopenharmony_ci	unsigned char num_erp;
468c2ecf20Sopenharmony_ci	unsigned char num_analog_in;
478c2ecf20Sopenharmony_ci	unsigned char num_digital_in;
488c2ecf20Sopenharmony_ci	unsigned char num_digital_out;
498c2ecf20Sopenharmony_ci	unsigned char num_analog_audio_out;
508c2ecf20Sopenharmony_ci	unsigned char num_analog_audio_in;
518c2ecf20Sopenharmony_ci	unsigned char num_digital_audio_out;
528c2ecf20Sopenharmony_ci	unsigned char num_digital_audio_in;
538c2ecf20Sopenharmony_ci	unsigned char num_midi_out;
548c2ecf20Sopenharmony_ci	unsigned char num_midi_in;
558c2ecf20Sopenharmony_ci	unsigned char data_alignment;
568c2ecf20Sopenharmony_ci} __attribute__ ((packed));
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_cistruct snd_usb_caiaq_cb_info;
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_cistruct snd_usb_caiaqdev {
618c2ecf20Sopenharmony_ci	struct snd_usb_audio chip;
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci	struct urb ep1_in_urb;
648c2ecf20Sopenharmony_ci	struct urb midi_out_urb;
658c2ecf20Sopenharmony_ci	struct urb **data_urbs_in;
668c2ecf20Sopenharmony_ci	struct urb **data_urbs_out;
678c2ecf20Sopenharmony_ci	struct snd_usb_caiaq_cb_info *data_cb_info;
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci	unsigned char ep1_in_buf[EP1_BUFSIZE];
708c2ecf20Sopenharmony_ci	unsigned char ep1_out_buf[EP1_BUFSIZE];
718c2ecf20Sopenharmony_ci	unsigned char midi_out_buf[EP1_BUFSIZE];
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci	struct caiaq_device_spec spec;
748c2ecf20Sopenharmony_ci	spinlock_t spinlock;
758c2ecf20Sopenharmony_ci	wait_queue_head_t ep1_wait_queue;
768c2ecf20Sopenharmony_ci	wait_queue_head_t prepare_wait_queue;
778c2ecf20Sopenharmony_ci	int spec_received, audio_parm_answer;
788c2ecf20Sopenharmony_ci	int midi_out_active;
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci	char vendor_name[CAIAQ_USB_STR_LEN];
818c2ecf20Sopenharmony_ci	char product_name[CAIAQ_USB_STR_LEN];
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci	int n_streams, n_audio_in, n_audio_out;
848c2ecf20Sopenharmony_ci	int streaming, first_packet, output_running;
858c2ecf20Sopenharmony_ci	int audio_in_buf_pos[MAX_STREAMS];
868c2ecf20Sopenharmony_ci	int audio_out_buf_pos[MAX_STREAMS];
878c2ecf20Sopenharmony_ci	int period_in_count[MAX_STREAMS];
888c2ecf20Sopenharmony_ci	int period_out_count[MAX_STREAMS];
898c2ecf20Sopenharmony_ci	int input_panic, output_panic, warned;
908c2ecf20Sopenharmony_ci	char *audio_in_buf, *audio_out_buf;
918c2ecf20Sopenharmony_ci	unsigned int samplerates, bpp;
928c2ecf20Sopenharmony_ci	unsigned long outurb_active_mask;
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci	struct snd_pcm_substream *sub_playback[MAX_STREAMS];
958c2ecf20Sopenharmony_ci	struct snd_pcm_substream *sub_capture[MAX_STREAMS];
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci	/* Controls */
988c2ecf20Sopenharmony_ci	unsigned char control_state[256];
998c2ecf20Sopenharmony_ci	unsigned char ep8_out_buf[2];
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci	/* Linux input */
1028c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_USB_CAIAQ_INPUT
1038c2ecf20Sopenharmony_ci	struct input_dev *input_dev;
1048c2ecf20Sopenharmony_ci	char phys[64];			/* physical device path */
1058c2ecf20Sopenharmony_ci	unsigned short keycode[128];
1068c2ecf20Sopenharmony_ci	struct urb *ep4_in_urb;
1078c2ecf20Sopenharmony_ci	unsigned char ep4_in_buf[EP4_BUFSIZE];
1088c2ecf20Sopenharmony_ci#endif
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci	/* ALSA */
1118c2ecf20Sopenharmony_ci	struct snd_pcm *pcm;
1128c2ecf20Sopenharmony_ci	struct snd_pcm_hardware pcm_info;
1138c2ecf20Sopenharmony_ci	struct snd_rawmidi *rmidi;
1148c2ecf20Sopenharmony_ci	struct snd_rawmidi_substream *midi_receive_substream;
1158c2ecf20Sopenharmony_ci	struct snd_rawmidi_substream *midi_out_substream;
1168c2ecf20Sopenharmony_ci};
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_cistruct snd_usb_caiaq_cb_info {
1198c2ecf20Sopenharmony_ci	struct snd_usb_caiaqdev *cdev;
1208c2ecf20Sopenharmony_ci	int index;
1218c2ecf20Sopenharmony_ci};
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ci#define caiaqdev(c) ((struct snd_usb_caiaqdev*)(c)->private_data)
1248c2ecf20Sopenharmony_ci#define caiaqdev_to_dev(d)	(d->chip.card->dev)
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ciint snd_usb_caiaq_set_audio_params (struct snd_usb_caiaqdev *cdev, int rate, int depth, int bbp);
1278c2ecf20Sopenharmony_ciint snd_usb_caiaq_set_auto_msg (struct snd_usb_caiaqdev *cdev, int digital, int analog, int erp);
1288c2ecf20Sopenharmony_ciint snd_usb_caiaq_send_command(struct snd_usb_caiaqdev *cdev,
1298c2ecf20Sopenharmony_ci			       unsigned char command,
1308c2ecf20Sopenharmony_ci			       const unsigned char *buffer,
1318c2ecf20Sopenharmony_ci			       int len);
1328c2ecf20Sopenharmony_ciint snd_usb_caiaq_send_command_bank(struct snd_usb_caiaqdev *cdev,
1338c2ecf20Sopenharmony_ci			       unsigned char command,
1348c2ecf20Sopenharmony_ci			       unsigned char bank,
1358c2ecf20Sopenharmony_ci			       const unsigned char *buffer,
1368c2ecf20Sopenharmony_ci			       int len);
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci#endif /* CAIAQ_DEVICE_H */
139