[ALSA] caiaq - support for Native Instrument's RigKontrol3

This patch adds support for Native Instrument's upcoming
RigKontrol3 sound interface.

Signed-off-by: Daniel Mack <daniel@caiaq.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Jaroslav Kysela <perex@suse.cz>
diff --git a/sound/usb/Kconfig b/sound/usb/Kconfig
index 315360f..7061438 100644
--- a/sound/usb/Kconfig
+++ b/sound/usb/Kconfig
@@ -40,6 +40,7 @@
 	   namely:
 
 	    * Native Instruments RigKontrol2
+	    * Native Instruments RigKontrol3
 	    * Native Instruments Kore Controller
 	    * Native Instruments Audio Kontrol 1
 	    * Native Instruments Audio 8 DJ
@@ -55,6 +56,7 @@
 	  alpha dials and analog pedals on the following products:
 
 	   * Native Instruments RigKontrol2
+	   * Native Instruments RigKontrol3
 	   * Native Instruments Audio Kontrol 1
 
 endmenu
diff --git a/sound/usb/caiaq/caiaq-audio.c b/sound/usb/caiaq/caiaq-audio.c
index 0414d76..0666908 100644
--- a/sound/usb/caiaq/caiaq-audio.c
+++ b/sound/usb/caiaq/caiaq-audio.c
@@ -648,6 +648,7 @@
 	dev->samplerates = dev->pcm_info.rates;
 	switch (dev->chip.usb_id) {
 	case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AK1):
+	case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL3):
 		dev->samplerates |= SNDRV_PCM_RATE_88200;
 		dev->samplerates |= SNDRV_PCM_RATE_192000;
 		break;
diff --git a/sound/usb/caiaq/caiaq-device.c b/sound/usb/caiaq/caiaq-device.c
index 4709347..58af814 100644
--- a/sound/usb/caiaq/caiaq-device.c
+++ b/sound/usb/caiaq/caiaq-device.c
@@ -41,9 +41,10 @@
 #endif
 
 MODULE_AUTHOR("Daniel Mack <daniel@caiaq.de>");
-MODULE_DESCRIPTION("caiaq USB audio, version 1.1.0");
+MODULE_DESCRIPTION("caiaq USB audio, version 1.2.0");
 MODULE_LICENSE("GPL");
 MODULE_SUPPORTED_DEVICE("{{Native Instruments, RigKontrol2},"
+			 "{Native Instruments, RigKontrol3},"
 			 "{Native Instruments, Kore Controller},"
 			 "{Native Instruments, Audio Kontrol 1}"
 			 "{Native Instruments, Audio 8 DJ}}");
@@ -85,6 +86,11 @@
 	{
 		.match_flags =	USB_DEVICE_ID_MATCH_DEVICE,
 		.idVendor =	USB_VID_NATIVEINSTRUMENTS,
+		.idProduct =	USB_PID_RIGKONTROL3
+	},
+	{
+		.match_flags =	USB_DEVICE_ID_MATCH_DEVICE,
+		.idVendor =	USB_VID_NATIVEINSTRUMENTS,
 		.idProduct =	USB_PID_KORECONTROLLER
 	},
 	{
@@ -226,7 +232,7 @@
 static void setup_card(struct snd_usb_caiaqdev *dev)
 {
 	int ret;
-	char val[3];
+	char val[4];
 	
 	/* device-specific startup specials */
 	switch (dev->chip.usb_id) {
@@ -237,6 +243,14 @@
 		val[2] = 0x01;
 		send_command(dev, EP1_CMD_WRITE_IO, val, 3);
 		break;
+	case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL3):
+		/* RigKontrol2 - display two centered dashes ('--') */
+		val[0] = 0x00;
+		val[1] = 0x40;
+		val[2] = 0x40;
+		val[3] = 0x00;
+		send_command(dev, EP1_CMD_WRITE_IO, val, 4);
+		break;
 	case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AK1):
 		/* Audio Kontrol 1 - make USB-LED stop blinking */
 		val[0] = 0x00;
diff --git a/sound/usb/caiaq/caiaq-device.h b/sound/usb/caiaq/caiaq-device.h
index 088d5ec..79bc5be 100644
--- a/sound/usb/caiaq/caiaq-device.h
+++ b/sound/usb/caiaq/caiaq-device.h
@@ -6,6 +6,7 @@
 #define USB_VID_NATIVEINSTRUMENTS 0x17cc
 
 #define USB_PID_RIGKONTROL2	0x1969
+#define USB_PID_RIGKONTROL3	0x1940
 #define USB_PID_KORECONTROLLER 	0x4711
 #define USB_PID_AK1		0x0815
 #define USB_PID_AUDIO8DJ	0x1978
diff --git a/sound/usb/caiaq/caiaq-input.c b/sound/usb/caiaq/caiaq-input.c
index 6978dab..a1de0c6 100644
--- a/sound/usb/caiaq/caiaq-input.c
+++ b/sound/usb/caiaq/caiaq-input.c
@@ -34,6 +34,8 @@
 static unsigned char keycode_ak1[] =  { KEY_C, KEY_B, KEY_A };
 static unsigned char keycode_rk2[] =  { KEY_1, KEY_2, KEY_3, KEY_4, 
 					KEY_5, KEY_6, KEY_7 };
+static unsigned char keycode_rk3[] =  { KEY_1, KEY_2, KEY_3, KEY_4,
+					KEY_5, KEY_6, KEY_7, KEY_5, KEY_6 };
 
 #define DEG90  (range/2)
 #define DEG180 (range)
@@ -107,7 +109,8 @@
 
 
 static void snd_caiaq_input_read_analog(struct snd_usb_caiaqdev *dev, 
-					const char *buf, unsigned int len)
+					const unsigned char *buf,
+					unsigned int len)
 {
 	switch(dev->input_dev->id.product) {
 	case USB_PID_RIGKONTROL2:
@@ -116,6 +119,12 @@
 		input_report_abs(dev->input_dev, ABS_Z, (buf[2] << 8) |buf[3]);
 		input_sync(dev->input_dev);
 		break;
+	case USB_PID_RIGKONTROL3:
+		input_report_abs(dev->input_dev, ABS_X, (buf[0] << 8) |buf[1]);
+		input_report_abs(dev->input_dev, ABS_Y, (buf[2] << 8) |buf[3]);
+		input_report_abs(dev->input_dev, ABS_Z, (buf[4] << 8) |buf[5]);
+		input_sync(dev->input_dev);
+		break;
 	}
 }
 
@@ -128,7 +137,7 @@
 	case USB_PID_AK1:
 		i = decode_erp(buf[0], buf[1]);
 		input_report_abs(dev->input_dev, ABS_X, i);
-		input_sync(dev->input_dev);	
+		input_sync(dev->input_dev);
 		break;
 	}
 }
@@ -204,6 +213,20 @@
 		input_set_abs_params(input, ABS_Z, 0, 4096, 0, 10);
 		snd_usb_caiaq_set_auto_msg(dev, 1, 10, 0);
 		break;
+	case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL3):
+		input->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
+		input->absbit[0] = BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_Z);
+		input->keycode = keycode_rk3;
+		input->keycodesize = sizeof(char);
+		input->keycodemax = ARRAY_SIZE(keycode_rk3);
+		for (i=0; i<ARRAY_SIZE(keycode_rk3); i++)
+			set_bit(keycode_rk3[i], input->keybit);
+
+		input_set_abs_params(input, ABS_X, 0, 1024, 0, 10);
+		input_set_abs_params(input, ABS_Y, 0, 1024, 0, 10);
+		input_set_abs_params(input, ABS_Z, 0, 1024, 0, 10);
+		snd_usb_caiaq_set_auto_msg(dev, 1, 10, 0);
+		break;
 	case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AK1):
 		input->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
 		input->absbit[0] = BIT(ABS_X);