xref: /openbmc/linux/sound/usb/line6/toneport.c (revision 247d95ee6dd22e5323ecf7a73ff64110ef2fa2da)
161864d84STakashi Iwai /*
2c078a4aaSChris Rorvick  * Line 6 Linux USB driver
361864d84STakashi Iwai  *
461864d84STakashi Iwai  * Copyright (C) 2004-2010 Markus Grabner (grabner@icg.tugraz.at)
561864d84STakashi Iwai  *                         Emil Myhrman (emil.myhrman@gmail.com)
661864d84STakashi Iwai  *
761864d84STakashi Iwai  *	This program is free software; you can redistribute it and/or
861864d84STakashi Iwai  *	modify it under the terms of the GNU General Public License as
961864d84STakashi Iwai  *	published by the Free Software Foundation, version 2.
1061864d84STakashi Iwai  *
1161864d84STakashi Iwai  */
1261864d84STakashi Iwai 
1361864d84STakashi Iwai #include <linux/wait.h>
14ccddbe4aSTakashi Iwai #include <linux/usb.h>
15ccddbe4aSTakashi Iwai #include <linux/slab.h>
16ccddbe4aSTakashi Iwai #include <linux/module.h>
17f44edd7bSTakashi Iwai #include <linux/leds.h>
18ccddbe4aSTakashi Iwai #include <sound/core.h>
1961864d84STakashi Iwai #include <sound/control.h>
2061864d84STakashi Iwai 
2161864d84STakashi Iwai #include "capture.h"
2261864d84STakashi Iwai #include "driver.h"
2361864d84STakashi Iwai #include "playback.h"
24ccddbe4aSTakashi Iwai #include "usbdefs.h"
25ccddbe4aSTakashi Iwai 
26ccddbe4aSTakashi Iwai enum line6_device_type {
27ccddbe4aSTakashi Iwai 	LINE6_GUITARPORT,
28ccddbe4aSTakashi Iwai 	LINE6_PODSTUDIO_GX,
29ccddbe4aSTakashi Iwai 	LINE6_PODSTUDIO_UX1,
30ccddbe4aSTakashi Iwai 	LINE6_PODSTUDIO_UX2,
31ccddbe4aSTakashi Iwai 	LINE6_TONEPORT_GX,
32ccddbe4aSTakashi Iwai 	LINE6_TONEPORT_UX1,
33ccddbe4aSTakashi Iwai 	LINE6_TONEPORT_UX2,
34ccddbe4aSTakashi Iwai };
35ccddbe4aSTakashi Iwai 
36f44edd7bSTakashi Iwai struct usb_line6_toneport;
37f44edd7bSTakashi Iwai 
38f44edd7bSTakashi Iwai struct toneport_led {
39f44edd7bSTakashi Iwai 	struct led_classdev dev;
40f44edd7bSTakashi Iwai 	char name[64];
41f44edd7bSTakashi Iwai 	struct usb_line6_toneport *toneport;
42f44edd7bSTakashi Iwai 	bool registered;
43f44edd7bSTakashi Iwai };
44f44edd7bSTakashi Iwai 
45ccddbe4aSTakashi Iwai struct usb_line6_toneport {
46ccddbe4aSTakashi Iwai 	/**
47ccddbe4aSTakashi Iwai 		Generic Line 6 USB data.
48ccddbe4aSTakashi Iwai 	*/
49ccddbe4aSTakashi Iwai 	struct usb_line6 line6;
50ccddbe4aSTakashi Iwai 
51ccddbe4aSTakashi Iwai 	/**
52ccddbe4aSTakashi Iwai 		Source selector.
53ccddbe4aSTakashi Iwai 	*/
54ccddbe4aSTakashi Iwai 	int source;
55ccddbe4aSTakashi Iwai 
56ccddbe4aSTakashi Iwai 	/**
57ccddbe4aSTakashi Iwai 		Serial number of device.
58ccddbe4aSTakashi Iwai 	*/
59ccddbe4aSTakashi Iwai 	int serial_number;
60ccddbe4aSTakashi Iwai 
61ccddbe4aSTakashi Iwai 	/**
62ccddbe4aSTakashi Iwai 		Firmware version (x 100).
63ccddbe4aSTakashi Iwai 	*/
64ccddbe4aSTakashi Iwai 	int firmware_version;
65ccddbe4aSTakashi Iwai 
66ccddbe4aSTakashi Iwai 	/**
67ccddbe4aSTakashi Iwai 		 Timer for delayed PCM startup.
68ccddbe4aSTakashi Iwai 	*/
69ccddbe4aSTakashi Iwai 	struct timer_list timer;
70ccddbe4aSTakashi Iwai 
71ccddbe4aSTakashi Iwai 	/**
72ccddbe4aSTakashi Iwai 		 Device type.
73ccddbe4aSTakashi Iwai 	*/
74ccddbe4aSTakashi Iwai 	enum line6_device_type type;
75f44edd7bSTakashi Iwai 
76f44edd7bSTakashi Iwai 	/* LED instances */
77f44edd7bSTakashi Iwai 	struct toneport_led leds[2];
78ccddbe4aSTakashi Iwai };
7961864d84STakashi Iwai 
8061864d84STakashi Iwai static int toneport_send_cmd(struct usb_device *usbdev, int cmd1, int cmd2);
8161864d84STakashi Iwai 
8261864d84STakashi Iwai #define TONEPORT_PCM_DELAY 1
8361864d84STakashi Iwai 
8461864d84STakashi Iwai static struct snd_ratden toneport_ratden = {
8561864d84STakashi Iwai 	.num_min = 44100,
8661864d84STakashi Iwai 	.num_max = 44100,
8761864d84STakashi Iwai 	.num_step = 1,
8861864d84STakashi Iwai 	.den = 1
8961864d84STakashi Iwai };
9061864d84STakashi Iwai 
9161864d84STakashi Iwai static struct line6_pcm_properties toneport_pcm_properties = {
9261864d84STakashi Iwai 	.snd_line6_playback_hw = {
9361864d84STakashi Iwai 				  .info = (SNDRV_PCM_INFO_MMAP |
9461864d84STakashi Iwai 					   SNDRV_PCM_INFO_INTERLEAVED |
9561864d84STakashi Iwai 					   SNDRV_PCM_INFO_BLOCK_TRANSFER |
9661864d84STakashi Iwai 					   SNDRV_PCM_INFO_MMAP_VALID |
9761864d84STakashi Iwai 					   SNDRV_PCM_INFO_PAUSE |
9861864d84STakashi Iwai 					   SNDRV_PCM_INFO_SYNC_START),
9961864d84STakashi Iwai 				  .formats = SNDRV_PCM_FMTBIT_S16_LE,
10061864d84STakashi Iwai 				  .rates = SNDRV_PCM_RATE_KNOT,
10161864d84STakashi Iwai 				  .rate_min = 44100,
10261864d84STakashi Iwai 				  .rate_max = 44100,
10361864d84STakashi Iwai 				  .channels_min = 2,
10461864d84STakashi Iwai 				  .channels_max = 2,
10561864d84STakashi Iwai 				  .buffer_bytes_max = 60000,
10661864d84STakashi Iwai 				  .period_bytes_min = 64,
10761864d84STakashi Iwai 				  .period_bytes_max = 8192,
10861864d84STakashi Iwai 				  .periods_min = 1,
10961864d84STakashi Iwai 				  .periods_max = 1024},
11061864d84STakashi Iwai 	.snd_line6_capture_hw = {
11161864d84STakashi Iwai 				 .info = (SNDRV_PCM_INFO_MMAP |
11261864d84STakashi Iwai 					  SNDRV_PCM_INFO_INTERLEAVED |
11361864d84STakashi Iwai 					  SNDRV_PCM_INFO_BLOCK_TRANSFER |
11461864d84STakashi Iwai 					  SNDRV_PCM_INFO_MMAP_VALID |
11561864d84STakashi Iwai 					  SNDRV_PCM_INFO_SYNC_START),
11661864d84STakashi Iwai 				 .formats = SNDRV_PCM_FMTBIT_S16_LE,
11761864d84STakashi Iwai 				 .rates = SNDRV_PCM_RATE_KNOT,
11861864d84STakashi Iwai 				 .rate_min = 44100,
11961864d84STakashi Iwai 				 .rate_max = 44100,
12061864d84STakashi Iwai 				 .channels_min = 2,
12161864d84STakashi Iwai 				 .channels_max = 2,
12261864d84STakashi Iwai 				 .buffer_bytes_max = 60000,
12361864d84STakashi Iwai 				 .period_bytes_min = 64,
12461864d84STakashi Iwai 				 .period_bytes_max = 8192,
12561864d84STakashi Iwai 				 .periods_min = 1,
12661864d84STakashi Iwai 				 .periods_max = 1024},
12761864d84STakashi Iwai 	.snd_line6_rates = {
12861864d84STakashi Iwai 			    .nrats = 1,
12961864d84STakashi Iwai 			    .rats = &toneport_ratden},
13061864d84STakashi Iwai 	.bytes_per_frame = 4
13161864d84STakashi Iwai };
13261864d84STakashi Iwai 
13361864d84STakashi Iwai static const struct {
13461864d84STakashi Iwai 	const char *name;
13561864d84STakashi Iwai 	int code;
13661864d84STakashi Iwai } toneport_source_info[] = {
13761864d84STakashi Iwai 	{"Microphone", 0x0a01},
13861864d84STakashi Iwai 	{"Line", 0x0801},
13961864d84STakashi Iwai 	{"Instrument", 0x0b01},
14061864d84STakashi Iwai 	{"Inst & Mic", 0x0901}
14161864d84STakashi Iwai };
14261864d84STakashi Iwai 
14361864d84STakashi Iwai static int toneport_send_cmd(struct usb_device *usbdev, int cmd1, int cmd2)
14461864d84STakashi Iwai {
14561864d84STakashi Iwai 	int ret;
14661864d84STakashi Iwai 
14761864d84STakashi Iwai 	ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67,
14861864d84STakashi Iwai 			      USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
14961864d84STakashi Iwai 			      cmd1, cmd2, NULL, 0, LINE6_TIMEOUT * HZ);
15061864d84STakashi Iwai 
15161864d84STakashi Iwai 	if (ret < 0) {
15261864d84STakashi Iwai 		dev_err(&usbdev->dev, "send failed (error %d)\n", ret);
15361864d84STakashi Iwai 		return ret;
15461864d84STakashi Iwai 	}
15561864d84STakashi Iwai 
15661864d84STakashi Iwai 	return 0;
15761864d84STakashi Iwai }
15861864d84STakashi Iwai 
15961864d84STakashi Iwai /* monitor info callback */
16061864d84STakashi Iwai static int snd_toneport_monitor_info(struct snd_kcontrol *kcontrol,
16161864d84STakashi Iwai 				     struct snd_ctl_elem_info *uinfo)
16261864d84STakashi Iwai {
16361864d84STakashi Iwai 	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
16461864d84STakashi Iwai 	uinfo->count = 1;
16561864d84STakashi Iwai 	uinfo->value.integer.min = 0;
16661864d84STakashi Iwai 	uinfo->value.integer.max = 256;
16761864d84STakashi Iwai 	return 0;
16861864d84STakashi Iwai }
16961864d84STakashi Iwai 
17061864d84STakashi Iwai /* monitor get callback */
17161864d84STakashi Iwai static int snd_toneport_monitor_get(struct snd_kcontrol *kcontrol,
17261864d84STakashi Iwai 				    struct snd_ctl_elem_value *ucontrol)
17361864d84STakashi Iwai {
17461864d84STakashi Iwai 	struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
17561864d84STakashi Iwai 
17661864d84STakashi Iwai 	ucontrol->value.integer.value[0] = line6pcm->volume_monitor;
17761864d84STakashi Iwai 	return 0;
17861864d84STakashi Iwai }
17961864d84STakashi Iwai 
18061864d84STakashi Iwai /* monitor put callback */
18161864d84STakashi Iwai static int snd_toneport_monitor_put(struct snd_kcontrol *kcontrol,
18261864d84STakashi Iwai 				    struct snd_ctl_elem_value *ucontrol)
18361864d84STakashi Iwai {
18461864d84STakashi Iwai 	struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
185*247d95eeSTakashi Iwai 	int err;
18661864d84STakashi Iwai 
18761864d84STakashi Iwai 	if (ucontrol->value.integer.value[0] == line6pcm->volume_monitor)
18861864d84STakashi Iwai 		return 0;
18961864d84STakashi Iwai 
19061864d84STakashi Iwai 	line6pcm->volume_monitor = ucontrol->value.integer.value[0];
19161864d84STakashi Iwai 
192*247d95eeSTakashi Iwai 	if (line6pcm->volume_monitor > 0) {
193*247d95eeSTakashi Iwai 		err = line6_pcm_acquire(line6pcm, LINE6_STREAM_MONITOR);
194*247d95eeSTakashi Iwai 		if (err < 0) {
195*247d95eeSTakashi Iwai 			line6pcm->volume_monitor = 0;
19663e20df1STakashi Iwai 			line6_pcm_release(line6pcm, LINE6_STREAM_MONITOR);
197*247d95eeSTakashi Iwai 			return err;
198*247d95eeSTakashi Iwai 		}
199*247d95eeSTakashi Iwai 	} else {
200*247d95eeSTakashi Iwai 		line6_pcm_release(line6pcm, LINE6_STREAM_MONITOR);
201*247d95eeSTakashi Iwai 	}
20261864d84STakashi Iwai 
20361864d84STakashi Iwai 	return 1;
20461864d84STakashi Iwai }
20561864d84STakashi Iwai 
20661864d84STakashi Iwai /* source info callback */
20761864d84STakashi Iwai static int snd_toneport_source_info(struct snd_kcontrol *kcontrol,
20861864d84STakashi Iwai 				    struct snd_ctl_elem_info *uinfo)
20961864d84STakashi Iwai {
21061864d84STakashi Iwai 	const int size = ARRAY_SIZE(toneport_source_info);
21161864d84STakashi Iwai 
21261864d84STakashi Iwai 	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
21361864d84STakashi Iwai 	uinfo->count = 1;
21461864d84STakashi Iwai 	uinfo->value.enumerated.items = size;
21561864d84STakashi Iwai 
21661864d84STakashi Iwai 	if (uinfo->value.enumerated.item >= size)
21761864d84STakashi Iwai 		uinfo->value.enumerated.item = size - 1;
21861864d84STakashi Iwai 
21961864d84STakashi Iwai 	strcpy(uinfo->value.enumerated.name,
22061864d84STakashi Iwai 	       toneport_source_info[uinfo->value.enumerated.item].name);
22161864d84STakashi Iwai 
22261864d84STakashi Iwai 	return 0;
22361864d84STakashi Iwai }
22461864d84STakashi Iwai 
22561864d84STakashi Iwai /* source get callback */
22661864d84STakashi Iwai static int snd_toneport_source_get(struct snd_kcontrol *kcontrol,
22761864d84STakashi Iwai 				   struct snd_ctl_elem_value *ucontrol)
22861864d84STakashi Iwai {
22961864d84STakashi Iwai 	struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
23061864d84STakashi Iwai 	struct usb_line6_toneport *toneport =
23161864d84STakashi Iwai 	    (struct usb_line6_toneport *)line6pcm->line6;
23261864d84STakashi Iwai 	ucontrol->value.enumerated.item[0] = toneport->source;
23361864d84STakashi Iwai 	return 0;
23461864d84STakashi Iwai }
23561864d84STakashi Iwai 
23661864d84STakashi Iwai /* source put callback */
23761864d84STakashi Iwai static int snd_toneport_source_put(struct snd_kcontrol *kcontrol,
23861864d84STakashi Iwai 				   struct snd_ctl_elem_value *ucontrol)
23961864d84STakashi Iwai {
24061864d84STakashi Iwai 	struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
24161864d84STakashi Iwai 	struct usb_line6_toneport *toneport =
24261864d84STakashi Iwai 	    (struct usb_line6_toneport *)line6pcm->line6;
24361864d84STakashi Iwai 	unsigned int source;
24461864d84STakashi Iwai 
24561864d84STakashi Iwai 	source = ucontrol->value.enumerated.item[0];
24661864d84STakashi Iwai 	if (source >= ARRAY_SIZE(toneport_source_info))
24761864d84STakashi Iwai 		return -EINVAL;
24861864d84STakashi Iwai 	if (source == toneport->source)
24961864d84STakashi Iwai 		return 0;
25061864d84STakashi Iwai 
25161864d84STakashi Iwai 	toneport->source = source;
25261864d84STakashi Iwai 	toneport_send_cmd(toneport->line6.usbdev,
25361864d84STakashi Iwai 			  toneport_source_info[source].code, 0x0000);
25461864d84STakashi Iwai 	return 1;
25561864d84STakashi Iwai }
25661864d84STakashi Iwai 
25761864d84STakashi Iwai static void toneport_start_pcm(unsigned long arg)
25861864d84STakashi Iwai {
25961864d84STakashi Iwai 	struct usb_line6_toneport *toneport = (struct usb_line6_toneport *)arg;
26061864d84STakashi Iwai 	struct usb_line6 *line6 = &toneport->line6;
26161864d84STakashi Iwai 
26263e20df1STakashi Iwai 	line6_pcm_acquire(line6->line6pcm, LINE6_STREAM_MONITOR);
26361864d84STakashi Iwai }
26461864d84STakashi Iwai 
26561864d84STakashi Iwai /* control definition */
26661864d84STakashi Iwai static struct snd_kcontrol_new toneport_control_monitor = {
26761864d84STakashi Iwai 	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
26861864d84STakashi Iwai 	.name = "Monitor Playback Volume",
26961864d84STakashi Iwai 	.index = 0,
27061864d84STakashi Iwai 	.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
27161864d84STakashi Iwai 	.info = snd_toneport_monitor_info,
27261864d84STakashi Iwai 	.get = snd_toneport_monitor_get,
27361864d84STakashi Iwai 	.put = snd_toneport_monitor_put
27461864d84STakashi Iwai };
27561864d84STakashi Iwai 
27661864d84STakashi Iwai /* source selector definition */
27761864d84STakashi Iwai static struct snd_kcontrol_new toneport_control_source = {
27861864d84STakashi Iwai 	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
27961864d84STakashi Iwai 	.name = "PCM Capture Source",
28061864d84STakashi Iwai 	.index = 0,
28161864d84STakashi Iwai 	.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
28261864d84STakashi Iwai 	.info = snd_toneport_source_info,
28361864d84STakashi Iwai 	.get = snd_toneport_source_get,
28461864d84STakashi Iwai 	.put = snd_toneport_source_put
28561864d84STakashi Iwai };
28661864d84STakashi Iwai 
28761864d84STakashi Iwai /*
288f44edd7bSTakashi Iwai 	For the led on Guitarport.
289f44edd7bSTakashi Iwai 	Brightness goes from 0x00 to 0x26. Set a value above this to have led
290f44edd7bSTakashi Iwai 	blink.
291f44edd7bSTakashi Iwai 	(void cmd_0x02(byte red, byte green)
292f44edd7bSTakashi Iwai */
293f44edd7bSTakashi Iwai 
294f44edd7bSTakashi Iwai static bool toneport_has_led(enum line6_device_type type)
295f44edd7bSTakashi Iwai {
296f44edd7bSTakashi Iwai 	return
297f44edd7bSTakashi Iwai 	    (type == LINE6_GUITARPORT) ||
298f44edd7bSTakashi Iwai 	    (type == LINE6_TONEPORT_GX);
299f44edd7bSTakashi Iwai 	/* add your device here if you are missing support for the LEDs */
300f44edd7bSTakashi Iwai }
301f44edd7bSTakashi Iwai 
302f44edd7bSTakashi Iwai static const char * const led_colors[2] = { "red", "green" };
303f44edd7bSTakashi Iwai static const int led_init_vals[2] = { 0x00, 0x26 };
304f44edd7bSTakashi Iwai 
305f44edd7bSTakashi Iwai static void toneport_update_led(struct usb_line6_toneport *toneport)
306f44edd7bSTakashi Iwai {
307f44edd7bSTakashi Iwai 	toneport_send_cmd(toneport->line6.usbdev,
308f44edd7bSTakashi Iwai 			  (toneport->leds[0].dev.brightness << 8) | 0x0002,
309f44edd7bSTakashi Iwai 			  toneport->leds[1].dev.brightness);
310f44edd7bSTakashi Iwai }
311f44edd7bSTakashi Iwai 
312f44edd7bSTakashi Iwai static void toneport_led_brightness_set(struct led_classdev *led_cdev,
313f44edd7bSTakashi Iwai 					enum led_brightness brightness)
314f44edd7bSTakashi Iwai {
315f44edd7bSTakashi Iwai 	struct toneport_led *leds =
316f44edd7bSTakashi Iwai 		container_of(led_cdev, struct toneport_led, dev);
317f44edd7bSTakashi Iwai 	toneport_update_led(leds->toneport);
318f44edd7bSTakashi Iwai }
319f44edd7bSTakashi Iwai 
320f44edd7bSTakashi Iwai static int toneport_init_leds(struct usb_line6_toneport *toneport)
321f44edd7bSTakashi Iwai {
322f44edd7bSTakashi Iwai 	struct device *dev = &toneport->line6.usbdev->dev;
323f44edd7bSTakashi Iwai 	int i, err;
324f44edd7bSTakashi Iwai 
325f44edd7bSTakashi Iwai 	for (i = 0; i < 2; i++) {
326f44edd7bSTakashi Iwai 		struct toneport_led *led = &toneport->leds[i];
327f44edd7bSTakashi Iwai 		struct led_classdev *leddev = &led->dev;
328f44edd7bSTakashi Iwai 
329f44edd7bSTakashi Iwai 		led->toneport = toneport;
330f44edd7bSTakashi Iwai 		snprintf(led->name, sizeof(led->name), "%s::%s",
331f44edd7bSTakashi Iwai 			 dev_name(dev), led_colors[i]);
332f44edd7bSTakashi Iwai 		leddev->name = led->name;
333f44edd7bSTakashi Iwai 		leddev->brightness = led_init_vals[i];
334f44edd7bSTakashi Iwai 		leddev->max_brightness = 0x26;
335f44edd7bSTakashi Iwai 		leddev->brightness_set = toneport_led_brightness_set;
336f44edd7bSTakashi Iwai 		err = led_classdev_register(dev, leddev);
337f44edd7bSTakashi Iwai 		if (err)
338f44edd7bSTakashi Iwai 			return err;
339f44edd7bSTakashi Iwai 		led->registered = true;
340f44edd7bSTakashi Iwai 	}
341f44edd7bSTakashi Iwai 
342f44edd7bSTakashi Iwai 	return 0;
343f44edd7bSTakashi Iwai }
344f44edd7bSTakashi Iwai 
345f44edd7bSTakashi Iwai static void toneport_remove_leds(struct usb_line6_toneport *toneport)
346f44edd7bSTakashi Iwai {
347f44edd7bSTakashi Iwai 	struct toneport_led *led;
348f44edd7bSTakashi Iwai 	int i;
349f44edd7bSTakashi Iwai 
350f44edd7bSTakashi Iwai 	for (i = 0; i < 2; i++) {
351f44edd7bSTakashi Iwai 		led = &toneport->leds[i];
352f44edd7bSTakashi Iwai 		if (!led->registered)
353f44edd7bSTakashi Iwai 			break;
354f44edd7bSTakashi Iwai 		led_classdev_unregister(&led->dev);
355f44edd7bSTakashi Iwai 		led->registered = false;
356f44edd7bSTakashi Iwai 	}
357f44edd7bSTakashi Iwai }
358f44edd7bSTakashi Iwai 
359f44edd7bSTakashi Iwai /*
36061864d84STakashi Iwai 	Setup Toneport device.
36161864d84STakashi Iwai */
36261864d84STakashi Iwai static void toneport_setup(struct usb_line6_toneport *toneport)
36361864d84STakashi Iwai {
36461864d84STakashi Iwai 	int ticks;
36561864d84STakashi Iwai 	struct usb_line6 *line6 = &toneport->line6;
36661864d84STakashi Iwai 	struct usb_device *usbdev = line6->usbdev;
36761864d84STakashi Iwai 
36861864d84STakashi Iwai 	/* sync time on device with host: */
36961864d84STakashi Iwai 	ticks = (int)get_seconds();
37061864d84STakashi Iwai 	line6_write_data(line6, 0x80c6, &ticks, 4);
37161864d84STakashi Iwai 
37261864d84STakashi Iwai 	/* enable device: */
37361864d84STakashi Iwai 	toneport_send_cmd(usbdev, 0x0301, 0x0000);
37461864d84STakashi Iwai 
37561864d84STakashi Iwai 	/* initialize source select: */
376ccddbe4aSTakashi Iwai 	switch (toneport->type) {
37761864d84STakashi Iwai 	case LINE6_TONEPORT_UX1:
37861864d84STakashi Iwai 	case LINE6_TONEPORT_UX2:
37961864d84STakashi Iwai 	case LINE6_PODSTUDIO_UX1:
38061864d84STakashi Iwai 	case LINE6_PODSTUDIO_UX2:
38161864d84STakashi Iwai 		toneport_send_cmd(usbdev,
38261864d84STakashi Iwai 				  toneport_source_info[toneport->source].code,
38361864d84STakashi Iwai 				  0x0000);
38461864d84STakashi Iwai 	default:
38561864d84STakashi Iwai 		break;
38661864d84STakashi Iwai 	}
38761864d84STakashi Iwai 
388ccddbe4aSTakashi Iwai 	if (toneport_has_led(toneport->type))
389f44edd7bSTakashi Iwai 		toneport_update_led(toneport);
3906dd1c05cSTakashi Iwai 
3916dd1c05cSTakashi Iwai 	mod_timer(&toneport->timer, jiffies + TONEPORT_PCM_DELAY * HZ);
39261864d84STakashi Iwai }
39361864d84STakashi Iwai 
39461864d84STakashi Iwai /*
39561864d84STakashi Iwai 	Toneport device disconnected.
39661864d84STakashi Iwai */
397f66fd990STakashi Iwai static void line6_toneport_disconnect(struct usb_line6 *line6)
39861864d84STakashi Iwai {
399f66fd990STakashi Iwai 	struct usb_line6_toneport *toneport =
400f66fd990STakashi Iwai 		(struct usb_line6_toneport *)line6;
40161864d84STakashi Iwai 
40261864d84STakashi Iwai 	del_timer_sync(&toneport->timer);
40361864d84STakashi Iwai 
404f44edd7bSTakashi Iwai 	if (toneport_has_led(toneport->type))
405f44edd7bSTakashi Iwai 		toneport_remove_leds(toneport);
40661864d84STakashi Iwai }
40761864d84STakashi Iwai 
40861864d84STakashi Iwai 
40961864d84STakashi Iwai /*
41061864d84STakashi Iwai 	 Try to init Toneport device.
41161864d84STakashi Iwai */
412f66fd990STakashi Iwai static int toneport_init(struct usb_line6 *line6,
413f66fd990STakashi Iwai 			 const struct usb_device_id *id)
41461864d84STakashi Iwai {
41561864d84STakashi Iwai 	int err;
41661864d84STakashi Iwai 	struct usb_line6_toneport *toneport =  (struct usb_line6_toneport *) line6;
41761864d84STakashi Iwai 
418f66fd990STakashi Iwai 	toneport->type = id->driver_info;
4196dd1c05cSTakashi Iwai 	setup_timer(&toneport->timer, toneport_start_pcm,
4206dd1c05cSTakashi Iwai 		    (unsigned long)toneport);
4216dd1c05cSTakashi Iwai 
42261864d84STakashi Iwai 	line6->disconnect = line6_toneport_disconnect;
42361864d84STakashi Iwai 
42461864d84STakashi Iwai 	/* initialize PCM subsystem: */
42561864d84STakashi Iwai 	err = line6_init_pcm(line6, &toneport_pcm_properties);
42661864d84STakashi Iwai 	if (err < 0)
42761864d84STakashi Iwai 		return err;
42861864d84STakashi Iwai 
42961864d84STakashi Iwai 	/* register monitor control: */
43061864d84STakashi Iwai 	err = snd_ctl_add(line6->card,
43161864d84STakashi Iwai 			  snd_ctl_new1(&toneport_control_monitor,
43261864d84STakashi Iwai 				       line6->line6pcm));
43361864d84STakashi Iwai 	if (err < 0)
43461864d84STakashi Iwai 		return err;
43561864d84STakashi Iwai 
43661864d84STakashi Iwai 	/* register source select control: */
437ccddbe4aSTakashi Iwai 	switch (toneport->type) {
43861864d84STakashi Iwai 	case LINE6_TONEPORT_UX1:
43961864d84STakashi Iwai 	case LINE6_TONEPORT_UX2:
44061864d84STakashi Iwai 	case LINE6_PODSTUDIO_UX1:
44161864d84STakashi Iwai 	case LINE6_PODSTUDIO_UX2:
44261864d84STakashi Iwai 		err =
44361864d84STakashi Iwai 		    snd_ctl_add(line6->card,
44461864d84STakashi Iwai 				snd_ctl_new1(&toneport_control_source,
44561864d84STakashi Iwai 					     line6->line6pcm));
44661864d84STakashi Iwai 		if (err < 0)
44761864d84STakashi Iwai 			return err;
44861864d84STakashi Iwai 
44961864d84STakashi Iwai 	default:
45061864d84STakashi Iwai 		break;
45161864d84STakashi Iwai 	}
45261864d84STakashi Iwai 
45361864d84STakashi Iwai 	line6_read_serial_number(line6, &toneport->serial_number);
45461864d84STakashi Iwai 	line6_read_data(line6, 0x80c2, &toneport->firmware_version, 1);
45561864d84STakashi Iwai 
456ccddbe4aSTakashi Iwai 	if (toneport_has_led(toneport->type)) {
457f44edd7bSTakashi Iwai 		err = toneport_init_leds(toneport);
458b2a3b023STakashi Iwai 		if (err < 0)
459b2a3b023STakashi Iwai 			return err;
46061864d84STakashi Iwai 	}
46161864d84STakashi Iwai 
46261864d84STakashi Iwai 	toneport_setup(toneport);
46361864d84STakashi Iwai 
46485a9339bSTakashi Iwai 	/* register audio system: */
46585a9339bSTakashi Iwai 	return snd_card_register(line6->card);
46661864d84STakashi Iwai }
46761864d84STakashi Iwai 
468ccddbe4aSTakashi Iwai #ifdef CONFIG_PM
46961864d84STakashi Iwai /*
47061864d84STakashi Iwai 	Resume Toneport device after reset.
47161864d84STakashi Iwai */
472ccddbe4aSTakashi Iwai static int toneport_reset_resume(struct usb_interface *interface)
47361864d84STakashi Iwai {
474ccddbe4aSTakashi Iwai 	toneport_setup(usb_get_intfdata(interface));
475ccddbe4aSTakashi Iwai 	return line6_resume(interface);
47661864d84STakashi Iwai }
477ccddbe4aSTakashi Iwai #endif
478ccddbe4aSTakashi Iwai 
479ccddbe4aSTakashi Iwai #define LINE6_DEVICE(prod) USB_DEVICE(0x0e41, prod)
480ccddbe4aSTakashi Iwai #define LINE6_IF_NUM(prod, n) USB_DEVICE_INTERFACE_NUMBER(0x0e41, prod, n)
481ccddbe4aSTakashi Iwai 
482ccddbe4aSTakashi Iwai /* table of devices that work with this driver */
483ccddbe4aSTakashi Iwai static const struct usb_device_id toneport_id_table[] = {
484ccddbe4aSTakashi Iwai 	{ LINE6_DEVICE(0x4750),    .driver_info = LINE6_GUITARPORT },
485ccddbe4aSTakashi Iwai 	{ LINE6_DEVICE(0x4153),    .driver_info = LINE6_PODSTUDIO_GX },
486ccddbe4aSTakashi Iwai 	{ LINE6_DEVICE(0x4150),    .driver_info = LINE6_PODSTUDIO_UX1 },
487ccddbe4aSTakashi Iwai 	{ LINE6_IF_NUM(0x4151, 0), .driver_info = LINE6_PODSTUDIO_UX2 },
488ccddbe4aSTakashi Iwai 	{ LINE6_DEVICE(0x4147),    .driver_info = LINE6_TONEPORT_GX },
489ccddbe4aSTakashi Iwai 	{ LINE6_DEVICE(0x4141),    .driver_info = LINE6_TONEPORT_UX1 },
490ccddbe4aSTakashi Iwai 	{ LINE6_IF_NUM(0x4142, 0), .driver_info = LINE6_TONEPORT_UX2 },
491ccddbe4aSTakashi Iwai 	{}
492ccddbe4aSTakashi Iwai };
493ccddbe4aSTakashi Iwai 
494ccddbe4aSTakashi Iwai MODULE_DEVICE_TABLE(usb, toneport_id_table);
495ccddbe4aSTakashi Iwai 
496ccddbe4aSTakashi Iwai static const struct line6_properties toneport_properties_table[] = {
497ccddbe4aSTakashi Iwai 	[LINE6_GUITARPORT] = {
498ccddbe4aSTakashi Iwai 		.id = "GuitarPort",
499ccddbe4aSTakashi Iwai 		.name = "GuitarPort",
500ccddbe4aSTakashi Iwai 		.capabilities	= LINE6_CAP_PCM,
501ccddbe4aSTakashi Iwai 		.altsetting = 2,  /* 1..4 seem to be ok */
502ccddbe4aSTakashi Iwai 		/* no control channel */
503ccddbe4aSTakashi Iwai 		.ep_audio_r = 0x82,
504ccddbe4aSTakashi Iwai 		.ep_audio_w = 0x01,
505ccddbe4aSTakashi Iwai 	},
506ccddbe4aSTakashi Iwai 	[LINE6_PODSTUDIO_GX] = {
507ccddbe4aSTakashi Iwai 		.id = "PODStudioGX",
508ccddbe4aSTakashi Iwai 		.name = "POD Studio GX",
509ccddbe4aSTakashi Iwai 		.capabilities	= LINE6_CAP_PCM,
510ccddbe4aSTakashi Iwai 		.altsetting = 2,  /* 1..4 seem to be ok */
511ccddbe4aSTakashi Iwai 		/* no control channel */
512ccddbe4aSTakashi Iwai 		.ep_audio_r = 0x82,
513ccddbe4aSTakashi Iwai 		.ep_audio_w = 0x01,
514ccddbe4aSTakashi Iwai 	},
515ccddbe4aSTakashi Iwai 	[LINE6_PODSTUDIO_UX1] = {
516ccddbe4aSTakashi Iwai 		.id = "PODStudioUX1",
517ccddbe4aSTakashi Iwai 		.name = "POD Studio UX1",
518ccddbe4aSTakashi Iwai 		.capabilities	= LINE6_CAP_PCM,
519ccddbe4aSTakashi Iwai 		.altsetting = 2,  /* 1..4 seem to be ok */
520ccddbe4aSTakashi Iwai 		/* no control channel */
521ccddbe4aSTakashi Iwai 		.ep_audio_r = 0x82,
522ccddbe4aSTakashi Iwai 		.ep_audio_w = 0x01,
523ccddbe4aSTakashi Iwai 	},
524ccddbe4aSTakashi Iwai 	[LINE6_PODSTUDIO_UX2] = {
525ccddbe4aSTakashi Iwai 		.id = "PODStudioUX2",
526ccddbe4aSTakashi Iwai 		.name = "POD Studio UX2",
527ccddbe4aSTakashi Iwai 		.capabilities	= LINE6_CAP_PCM,
528ccddbe4aSTakashi Iwai 		.altsetting = 2,  /* defaults to 44.1kHz, 16-bit */
529ccddbe4aSTakashi Iwai 		/* no control channel */
530ccddbe4aSTakashi Iwai 		.ep_audio_r = 0x82,
531ccddbe4aSTakashi Iwai 		.ep_audio_w = 0x01,
532ccddbe4aSTakashi Iwai 	},
533ccddbe4aSTakashi Iwai 	[LINE6_TONEPORT_GX] = {
534ccddbe4aSTakashi Iwai 		.id = "TonePortGX",
535ccddbe4aSTakashi Iwai 		.name = "TonePort GX",
536ccddbe4aSTakashi Iwai 		.capabilities	= LINE6_CAP_PCM,
537ccddbe4aSTakashi Iwai 		.altsetting = 2,  /* 1..4 seem to be ok */
538ccddbe4aSTakashi Iwai 		/* no control channel */
539ccddbe4aSTakashi Iwai 		.ep_audio_r = 0x82,
540ccddbe4aSTakashi Iwai 		.ep_audio_w = 0x01,
541ccddbe4aSTakashi Iwai 	},
542ccddbe4aSTakashi Iwai 	[LINE6_TONEPORT_UX1] = {
543ccddbe4aSTakashi Iwai 		.id = "TonePortUX1",
544ccddbe4aSTakashi Iwai 		.name = "TonePort UX1",
545ccddbe4aSTakashi Iwai 		.capabilities	= LINE6_CAP_PCM,
546ccddbe4aSTakashi Iwai 		.altsetting = 2,  /* 1..4 seem to be ok */
547ccddbe4aSTakashi Iwai 		/* no control channel */
548ccddbe4aSTakashi Iwai 		.ep_audio_r = 0x82,
549ccddbe4aSTakashi Iwai 		.ep_audio_w = 0x01,
550ccddbe4aSTakashi Iwai 	},
551ccddbe4aSTakashi Iwai 	[LINE6_TONEPORT_UX2] = {
552ccddbe4aSTakashi Iwai 		.id = "TonePortUX2",
553ccddbe4aSTakashi Iwai 		.name = "TonePort UX2",
554ccddbe4aSTakashi Iwai 		.capabilities	= LINE6_CAP_PCM,
555ccddbe4aSTakashi Iwai 		.altsetting = 2,  /* defaults to 44.1kHz, 16-bit */
556ccddbe4aSTakashi Iwai 		/* no control channel */
557ccddbe4aSTakashi Iwai 		.ep_audio_r = 0x82,
558ccddbe4aSTakashi Iwai 		.ep_audio_w = 0x01,
559ccddbe4aSTakashi Iwai 	},
560ccddbe4aSTakashi Iwai };
561ccddbe4aSTakashi Iwai 
562ccddbe4aSTakashi Iwai /*
563ccddbe4aSTakashi Iwai 	Probe USB device.
564ccddbe4aSTakashi Iwai */
565ccddbe4aSTakashi Iwai static int toneport_probe(struct usb_interface *interface,
566ccddbe4aSTakashi Iwai 			  const struct usb_device_id *id)
567ccddbe4aSTakashi Iwai {
568aca514b8STakashi Iwai 	return line6_probe(interface, id,
569ccddbe4aSTakashi Iwai 			   &toneport_properties_table[id->driver_info],
570aca514b8STakashi Iwai 			   toneport_init, sizeof(struct usb_line6_toneport));
571ccddbe4aSTakashi Iwai }
572ccddbe4aSTakashi Iwai 
573ccddbe4aSTakashi Iwai static struct usb_driver toneport_driver = {
574ccddbe4aSTakashi Iwai 	.name = KBUILD_MODNAME,
575ccddbe4aSTakashi Iwai 	.probe = toneport_probe,
576ccddbe4aSTakashi Iwai 	.disconnect = line6_disconnect,
577ccddbe4aSTakashi Iwai #ifdef CONFIG_PM
578ccddbe4aSTakashi Iwai 	.suspend = line6_suspend,
579ccddbe4aSTakashi Iwai 	.resume = line6_resume,
580ccddbe4aSTakashi Iwai 	.reset_resume = toneport_reset_resume,
581ccddbe4aSTakashi Iwai #endif
582ccddbe4aSTakashi Iwai 	.id_table = toneport_id_table,
583ccddbe4aSTakashi Iwai };
584ccddbe4aSTakashi Iwai 
585ccddbe4aSTakashi Iwai module_usb_driver(toneport_driver);
586ccddbe4aSTakashi Iwai 
587ccddbe4aSTakashi Iwai MODULE_DESCRIPTION("TonePort USB driver");
588ccddbe4aSTakashi Iwai MODULE_LICENSE("GPL");
589