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 25ccddbe4aSTakashi Iwai enum line6_device_type { 26ccddbe4aSTakashi Iwai LINE6_GUITARPORT, 27ccddbe4aSTakashi Iwai LINE6_PODSTUDIO_GX, 28ccddbe4aSTakashi Iwai LINE6_PODSTUDIO_UX1, 29ccddbe4aSTakashi Iwai LINE6_PODSTUDIO_UX2, 30ccddbe4aSTakashi Iwai LINE6_TONEPORT_GX, 31ccddbe4aSTakashi Iwai LINE6_TONEPORT_UX1, 32ccddbe4aSTakashi Iwai LINE6_TONEPORT_UX2, 33ccddbe4aSTakashi Iwai }; 34ccddbe4aSTakashi Iwai 35f44edd7bSTakashi Iwai struct usb_line6_toneport; 36f44edd7bSTakashi Iwai 37f44edd7bSTakashi Iwai struct toneport_led { 38f44edd7bSTakashi Iwai struct led_classdev dev; 39f44edd7bSTakashi Iwai char name[64]; 40f44edd7bSTakashi Iwai struct usb_line6_toneport *toneport; 41f44edd7bSTakashi Iwai bool registered; 42f44edd7bSTakashi Iwai }; 43f44edd7bSTakashi Iwai 44ccddbe4aSTakashi Iwai struct usb_line6_toneport { 45cddbd4f1STakashi Iwai /* Generic Line 6 USB data */ 46ccddbe4aSTakashi Iwai struct usb_line6 line6; 47ccddbe4aSTakashi Iwai 48cddbd4f1STakashi Iwai /* Source selector */ 49ccddbe4aSTakashi Iwai int source; 50ccddbe4aSTakashi Iwai 51cddbd4f1STakashi Iwai /* Serial number of device */ 52ccddbe4aSTakashi Iwai int serial_number; 53ccddbe4aSTakashi Iwai 54cddbd4f1STakashi Iwai /* Firmware version (x 100) */ 55ccddbe4aSTakashi Iwai int firmware_version; 56ccddbe4aSTakashi Iwai 57cddbd4f1STakashi Iwai /* Timer for delayed PCM startup */ 58ccddbe4aSTakashi Iwai struct timer_list timer; 59ccddbe4aSTakashi Iwai 60cddbd4f1STakashi Iwai /* Device type */ 61ccddbe4aSTakashi Iwai enum line6_device_type type; 62f44edd7bSTakashi Iwai 63f44edd7bSTakashi Iwai /* LED instances */ 64f44edd7bSTakashi Iwai struct toneport_led leds[2]; 65ccddbe4aSTakashi Iwai }; 6661864d84STakashi Iwai 6761864d84STakashi Iwai static int toneport_send_cmd(struct usb_device *usbdev, int cmd1, int cmd2); 6861864d84STakashi Iwai 6961864d84STakashi Iwai #define TONEPORT_PCM_DELAY 1 7061864d84STakashi Iwai 7161864d84STakashi Iwai static struct snd_ratden toneport_ratden = { 7261864d84STakashi Iwai .num_min = 44100, 7361864d84STakashi Iwai .num_max = 44100, 7461864d84STakashi Iwai .num_step = 1, 7561864d84STakashi Iwai .den = 1 7661864d84STakashi Iwai }; 7761864d84STakashi Iwai 7861864d84STakashi Iwai static struct line6_pcm_properties toneport_pcm_properties = { 791263f611STakashi Iwai .playback_hw = { 8061864d84STakashi Iwai .info = (SNDRV_PCM_INFO_MMAP | 8161864d84STakashi Iwai SNDRV_PCM_INFO_INTERLEAVED | 8261864d84STakashi Iwai SNDRV_PCM_INFO_BLOCK_TRANSFER | 8361864d84STakashi Iwai SNDRV_PCM_INFO_MMAP_VALID | 8461864d84STakashi Iwai SNDRV_PCM_INFO_PAUSE | 8561864d84STakashi Iwai SNDRV_PCM_INFO_SYNC_START), 8661864d84STakashi Iwai .formats = SNDRV_PCM_FMTBIT_S16_LE, 8761864d84STakashi Iwai .rates = SNDRV_PCM_RATE_KNOT, 8861864d84STakashi Iwai .rate_min = 44100, 8961864d84STakashi Iwai .rate_max = 44100, 9061864d84STakashi Iwai .channels_min = 2, 9161864d84STakashi Iwai .channels_max = 2, 9261864d84STakashi Iwai .buffer_bytes_max = 60000, 9361864d84STakashi Iwai .period_bytes_min = 64, 9461864d84STakashi Iwai .period_bytes_max = 8192, 9561864d84STakashi Iwai .periods_min = 1, 9661864d84STakashi Iwai .periods_max = 1024}, 971263f611STakashi Iwai .capture_hw = { 9861864d84STakashi Iwai .info = (SNDRV_PCM_INFO_MMAP | 9961864d84STakashi Iwai SNDRV_PCM_INFO_INTERLEAVED | 10061864d84STakashi Iwai SNDRV_PCM_INFO_BLOCK_TRANSFER | 10161864d84STakashi Iwai SNDRV_PCM_INFO_MMAP_VALID | 10261864d84STakashi Iwai SNDRV_PCM_INFO_SYNC_START), 10361864d84STakashi Iwai .formats = SNDRV_PCM_FMTBIT_S16_LE, 10461864d84STakashi Iwai .rates = SNDRV_PCM_RATE_KNOT, 10561864d84STakashi Iwai .rate_min = 44100, 10661864d84STakashi Iwai .rate_max = 44100, 10761864d84STakashi Iwai .channels_min = 2, 10861864d84STakashi Iwai .channels_max = 2, 10961864d84STakashi Iwai .buffer_bytes_max = 60000, 11061864d84STakashi Iwai .period_bytes_min = 64, 11161864d84STakashi Iwai .period_bytes_max = 8192, 11261864d84STakashi Iwai .periods_min = 1, 11361864d84STakashi Iwai .periods_max = 1024}, 1141263f611STakashi Iwai .rates = { 11561864d84STakashi Iwai .nrats = 1, 11661864d84STakashi Iwai .rats = &toneport_ratden}, 11761864d84STakashi Iwai .bytes_per_frame = 4 11861864d84STakashi Iwai }; 11961864d84STakashi Iwai 12061864d84STakashi Iwai static const struct { 12161864d84STakashi Iwai const char *name; 12261864d84STakashi Iwai int code; 12361864d84STakashi Iwai } toneport_source_info[] = { 12461864d84STakashi Iwai {"Microphone", 0x0a01}, 12561864d84STakashi Iwai {"Line", 0x0801}, 12661864d84STakashi Iwai {"Instrument", 0x0b01}, 12761864d84STakashi Iwai {"Inst & Mic", 0x0901} 12861864d84STakashi Iwai }; 12961864d84STakashi Iwai 13061864d84STakashi Iwai static int toneport_send_cmd(struct usb_device *usbdev, int cmd1, int cmd2) 13161864d84STakashi Iwai { 13261864d84STakashi Iwai int ret; 13361864d84STakashi Iwai 13461864d84STakashi Iwai ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67, 13561864d84STakashi Iwai USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT, 13661864d84STakashi Iwai cmd1, cmd2, NULL, 0, LINE6_TIMEOUT * HZ); 13761864d84STakashi Iwai 13861864d84STakashi Iwai if (ret < 0) { 13961864d84STakashi Iwai dev_err(&usbdev->dev, "send failed (error %d)\n", ret); 14061864d84STakashi Iwai return ret; 14161864d84STakashi Iwai } 14261864d84STakashi Iwai 14361864d84STakashi Iwai return 0; 14461864d84STakashi Iwai } 14561864d84STakashi Iwai 14661864d84STakashi Iwai /* monitor info callback */ 14761864d84STakashi Iwai static int snd_toneport_monitor_info(struct snd_kcontrol *kcontrol, 14861864d84STakashi Iwai struct snd_ctl_elem_info *uinfo) 14961864d84STakashi Iwai { 15061864d84STakashi Iwai uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 15161864d84STakashi Iwai uinfo->count = 1; 15261864d84STakashi Iwai uinfo->value.integer.min = 0; 15361864d84STakashi Iwai uinfo->value.integer.max = 256; 15461864d84STakashi Iwai return 0; 15561864d84STakashi Iwai } 15661864d84STakashi Iwai 15761864d84STakashi Iwai /* monitor get callback */ 15861864d84STakashi Iwai static int snd_toneport_monitor_get(struct snd_kcontrol *kcontrol, 15961864d84STakashi Iwai struct snd_ctl_elem_value *ucontrol) 16061864d84STakashi Iwai { 16161864d84STakashi Iwai struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol); 16261864d84STakashi Iwai 16361864d84STakashi Iwai ucontrol->value.integer.value[0] = line6pcm->volume_monitor; 16461864d84STakashi Iwai return 0; 16561864d84STakashi Iwai } 16661864d84STakashi Iwai 16761864d84STakashi Iwai /* monitor put callback */ 16861864d84STakashi Iwai static int snd_toneport_monitor_put(struct snd_kcontrol *kcontrol, 16961864d84STakashi Iwai struct snd_ctl_elem_value *ucontrol) 17061864d84STakashi Iwai { 17161864d84STakashi Iwai struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol); 172247d95eeSTakashi Iwai int err; 17361864d84STakashi Iwai 17461864d84STakashi Iwai if (ucontrol->value.integer.value[0] == line6pcm->volume_monitor) 17561864d84STakashi Iwai return 0; 17661864d84STakashi Iwai 17761864d84STakashi Iwai line6pcm->volume_monitor = ucontrol->value.integer.value[0]; 17861864d84STakashi Iwai 179247d95eeSTakashi Iwai if (line6pcm->volume_monitor > 0) { 180247d95eeSTakashi Iwai err = line6_pcm_acquire(line6pcm, LINE6_STREAM_MONITOR); 181247d95eeSTakashi Iwai if (err < 0) { 182247d95eeSTakashi Iwai line6pcm->volume_monitor = 0; 18363e20df1STakashi Iwai line6_pcm_release(line6pcm, LINE6_STREAM_MONITOR); 184247d95eeSTakashi Iwai return err; 185247d95eeSTakashi Iwai } 186247d95eeSTakashi Iwai } else { 187247d95eeSTakashi Iwai line6_pcm_release(line6pcm, LINE6_STREAM_MONITOR); 188247d95eeSTakashi Iwai } 18961864d84STakashi Iwai 19061864d84STakashi Iwai return 1; 19161864d84STakashi Iwai } 19261864d84STakashi Iwai 19361864d84STakashi Iwai /* source info callback */ 19461864d84STakashi Iwai static int snd_toneport_source_info(struct snd_kcontrol *kcontrol, 19561864d84STakashi Iwai struct snd_ctl_elem_info *uinfo) 19661864d84STakashi Iwai { 19761864d84STakashi Iwai const int size = ARRAY_SIZE(toneport_source_info); 19861864d84STakashi Iwai 19961864d84STakashi Iwai uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 20061864d84STakashi Iwai uinfo->count = 1; 20161864d84STakashi Iwai uinfo->value.enumerated.items = size; 20261864d84STakashi Iwai 20361864d84STakashi Iwai if (uinfo->value.enumerated.item >= size) 20461864d84STakashi Iwai uinfo->value.enumerated.item = size - 1; 20561864d84STakashi Iwai 20661864d84STakashi Iwai strcpy(uinfo->value.enumerated.name, 20761864d84STakashi Iwai toneport_source_info[uinfo->value.enumerated.item].name); 20861864d84STakashi Iwai 20961864d84STakashi Iwai return 0; 21061864d84STakashi Iwai } 21161864d84STakashi Iwai 21261864d84STakashi Iwai /* source get callback */ 21361864d84STakashi Iwai static int snd_toneport_source_get(struct snd_kcontrol *kcontrol, 21461864d84STakashi Iwai struct snd_ctl_elem_value *ucontrol) 21561864d84STakashi Iwai { 21661864d84STakashi Iwai struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol); 21761864d84STakashi Iwai struct usb_line6_toneport *toneport = 21861864d84STakashi Iwai (struct usb_line6_toneport *)line6pcm->line6; 21961864d84STakashi Iwai ucontrol->value.enumerated.item[0] = toneport->source; 22061864d84STakashi Iwai return 0; 22161864d84STakashi Iwai } 22261864d84STakashi Iwai 22361864d84STakashi Iwai /* source put callback */ 22461864d84STakashi Iwai static int snd_toneport_source_put(struct snd_kcontrol *kcontrol, 22561864d84STakashi Iwai struct snd_ctl_elem_value *ucontrol) 22661864d84STakashi Iwai { 22761864d84STakashi Iwai struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol); 22861864d84STakashi Iwai struct usb_line6_toneport *toneport = 22961864d84STakashi Iwai (struct usb_line6_toneport *)line6pcm->line6; 23061864d84STakashi Iwai unsigned int source; 23161864d84STakashi Iwai 23261864d84STakashi Iwai source = ucontrol->value.enumerated.item[0]; 23361864d84STakashi Iwai if (source >= ARRAY_SIZE(toneport_source_info)) 23461864d84STakashi Iwai return -EINVAL; 23561864d84STakashi Iwai if (source == toneport->source) 23661864d84STakashi Iwai return 0; 23761864d84STakashi Iwai 23861864d84STakashi Iwai toneport->source = source; 23961864d84STakashi Iwai toneport_send_cmd(toneport->line6.usbdev, 24061864d84STakashi Iwai toneport_source_info[source].code, 0x0000); 24161864d84STakashi Iwai return 1; 24261864d84STakashi Iwai } 24361864d84STakashi Iwai 24461864d84STakashi Iwai static void toneport_start_pcm(unsigned long arg) 24561864d84STakashi Iwai { 24661864d84STakashi Iwai struct usb_line6_toneport *toneport = (struct usb_line6_toneport *)arg; 24761864d84STakashi Iwai struct usb_line6 *line6 = &toneport->line6; 24861864d84STakashi Iwai 24963e20df1STakashi Iwai line6_pcm_acquire(line6->line6pcm, LINE6_STREAM_MONITOR); 25061864d84STakashi Iwai } 25161864d84STakashi Iwai 25261864d84STakashi Iwai /* control definition */ 25361864d84STakashi Iwai static struct snd_kcontrol_new toneport_control_monitor = { 25461864d84STakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 25561864d84STakashi Iwai .name = "Monitor Playback Volume", 25661864d84STakashi Iwai .index = 0, 25761864d84STakashi Iwai .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, 25861864d84STakashi Iwai .info = snd_toneport_monitor_info, 25961864d84STakashi Iwai .get = snd_toneport_monitor_get, 26061864d84STakashi Iwai .put = snd_toneport_monitor_put 26161864d84STakashi Iwai }; 26261864d84STakashi Iwai 26361864d84STakashi Iwai /* source selector definition */ 26461864d84STakashi Iwai static struct snd_kcontrol_new toneport_control_source = { 26561864d84STakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 26661864d84STakashi Iwai .name = "PCM Capture Source", 26761864d84STakashi Iwai .index = 0, 26861864d84STakashi Iwai .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, 26961864d84STakashi Iwai .info = snd_toneport_source_info, 27061864d84STakashi Iwai .get = snd_toneport_source_get, 27161864d84STakashi Iwai .put = snd_toneport_source_put 27261864d84STakashi Iwai }; 27361864d84STakashi Iwai 27461864d84STakashi Iwai /* 275f44edd7bSTakashi Iwai For the led on Guitarport. 276f44edd7bSTakashi Iwai Brightness goes from 0x00 to 0x26. Set a value above this to have led 277f44edd7bSTakashi Iwai blink. 278f44edd7bSTakashi Iwai (void cmd_0x02(byte red, byte green) 279f44edd7bSTakashi Iwai */ 280f44edd7bSTakashi Iwai 281*f2bd242fSChris Rorvick static bool toneport_has_led(struct usb_line6_toneport *toneport) 282f44edd7bSTakashi Iwai { 283*f2bd242fSChris Rorvick switch (toneport->type) { 284*f2bd242fSChris Rorvick case LINE6_GUITARPORT: 285*f2bd242fSChris Rorvick case LINE6_TONEPORT_GX: 286f44edd7bSTakashi Iwai /* add your device here if you are missing support for the LEDs */ 287*f2bd242fSChris Rorvick return true; 288*f2bd242fSChris Rorvick 289*f2bd242fSChris Rorvick default: 290*f2bd242fSChris Rorvick return false; 291*f2bd242fSChris Rorvick } 292f44edd7bSTakashi Iwai } 293f44edd7bSTakashi Iwai 294f44edd7bSTakashi Iwai static const char * const led_colors[2] = { "red", "green" }; 295f44edd7bSTakashi Iwai static const int led_init_vals[2] = { 0x00, 0x26 }; 296f44edd7bSTakashi Iwai 297f44edd7bSTakashi Iwai static void toneport_update_led(struct usb_line6_toneport *toneport) 298f44edd7bSTakashi Iwai { 299f44edd7bSTakashi Iwai toneport_send_cmd(toneport->line6.usbdev, 300f44edd7bSTakashi Iwai (toneport->leds[0].dev.brightness << 8) | 0x0002, 301f44edd7bSTakashi Iwai toneport->leds[1].dev.brightness); 302f44edd7bSTakashi Iwai } 303f44edd7bSTakashi Iwai 304f44edd7bSTakashi Iwai static void toneport_led_brightness_set(struct led_classdev *led_cdev, 305f44edd7bSTakashi Iwai enum led_brightness brightness) 306f44edd7bSTakashi Iwai { 307f44edd7bSTakashi Iwai struct toneport_led *leds = 308f44edd7bSTakashi Iwai container_of(led_cdev, struct toneport_led, dev); 309f44edd7bSTakashi Iwai toneport_update_led(leds->toneport); 310f44edd7bSTakashi Iwai } 311f44edd7bSTakashi Iwai 312f44edd7bSTakashi Iwai static int toneport_init_leds(struct usb_line6_toneport *toneport) 313f44edd7bSTakashi Iwai { 314f44edd7bSTakashi Iwai struct device *dev = &toneport->line6.usbdev->dev; 315f44edd7bSTakashi Iwai int i, err; 316f44edd7bSTakashi Iwai 317f44edd7bSTakashi Iwai for (i = 0; i < 2; i++) { 318f44edd7bSTakashi Iwai struct toneport_led *led = &toneport->leds[i]; 319f44edd7bSTakashi Iwai struct led_classdev *leddev = &led->dev; 320f44edd7bSTakashi Iwai 321f44edd7bSTakashi Iwai led->toneport = toneport; 322f44edd7bSTakashi Iwai snprintf(led->name, sizeof(led->name), "%s::%s", 323f44edd7bSTakashi Iwai dev_name(dev), led_colors[i]); 324f44edd7bSTakashi Iwai leddev->name = led->name; 325f44edd7bSTakashi Iwai leddev->brightness = led_init_vals[i]; 326f44edd7bSTakashi Iwai leddev->max_brightness = 0x26; 327f44edd7bSTakashi Iwai leddev->brightness_set = toneport_led_brightness_set; 328f44edd7bSTakashi Iwai err = led_classdev_register(dev, leddev); 329f44edd7bSTakashi Iwai if (err) 330f44edd7bSTakashi Iwai return err; 331f44edd7bSTakashi Iwai led->registered = true; 332f44edd7bSTakashi Iwai } 333f44edd7bSTakashi Iwai 334f44edd7bSTakashi Iwai return 0; 335f44edd7bSTakashi Iwai } 336f44edd7bSTakashi Iwai 337f44edd7bSTakashi Iwai static void toneport_remove_leds(struct usb_line6_toneport *toneport) 338f44edd7bSTakashi Iwai { 339f44edd7bSTakashi Iwai struct toneport_led *led; 340f44edd7bSTakashi Iwai int i; 341f44edd7bSTakashi Iwai 342f44edd7bSTakashi Iwai for (i = 0; i < 2; i++) { 343f44edd7bSTakashi Iwai led = &toneport->leds[i]; 344f44edd7bSTakashi Iwai if (!led->registered) 345f44edd7bSTakashi Iwai break; 346f44edd7bSTakashi Iwai led_classdev_unregister(&led->dev); 347f44edd7bSTakashi Iwai led->registered = false; 348f44edd7bSTakashi Iwai } 349f44edd7bSTakashi Iwai } 350f44edd7bSTakashi Iwai 35189444601SChris Rorvick static bool toneport_has_source_select(struct usb_line6_toneport *toneport) 35289444601SChris Rorvick { 35389444601SChris Rorvick switch (toneport->type) { 35489444601SChris Rorvick case LINE6_TONEPORT_UX1: 35589444601SChris Rorvick case LINE6_TONEPORT_UX2: 35689444601SChris Rorvick case LINE6_PODSTUDIO_UX1: 35789444601SChris Rorvick case LINE6_PODSTUDIO_UX2: 35889444601SChris Rorvick return true; 35989444601SChris Rorvick 36089444601SChris Rorvick default: 36189444601SChris Rorvick return false; 36289444601SChris Rorvick } 36389444601SChris Rorvick } 36489444601SChris Rorvick 365f44edd7bSTakashi Iwai /* 36661864d84STakashi Iwai Setup Toneport device. 36761864d84STakashi Iwai */ 36861864d84STakashi Iwai static void toneport_setup(struct usb_line6_toneport *toneport) 36961864d84STakashi Iwai { 37061864d84STakashi Iwai int ticks; 37161864d84STakashi Iwai struct usb_line6 *line6 = &toneport->line6; 37261864d84STakashi Iwai struct usb_device *usbdev = line6->usbdev; 37361864d84STakashi Iwai 37461864d84STakashi Iwai /* sync time on device with host: */ 37561864d84STakashi Iwai ticks = (int)get_seconds(); 37661864d84STakashi Iwai line6_write_data(line6, 0x80c6, &ticks, 4); 37761864d84STakashi Iwai 37861864d84STakashi Iwai /* enable device: */ 37961864d84STakashi Iwai toneport_send_cmd(usbdev, 0x0301, 0x0000); 38061864d84STakashi Iwai 38161864d84STakashi Iwai /* initialize source select: */ 38289444601SChris Rorvick if (toneport_has_source_select(toneport)) 38361864d84STakashi Iwai toneport_send_cmd(usbdev, 38461864d84STakashi Iwai toneport_source_info[toneport->source].code, 38561864d84STakashi Iwai 0x0000); 38661864d84STakashi Iwai 387*f2bd242fSChris Rorvick if (toneport_has_led(toneport)) 388f44edd7bSTakashi Iwai toneport_update_led(toneport); 3896dd1c05cSTakashi Iwai 3906dd1c05cSTakashi Iwai mod_timer(&toneport->timer, jiffies + TONEPORT_PCM_DELAY * HZ); 39161864d84STakashi Iwai } 39261864d84STakashi Iwai 39361864d84STakashi Iwai /* 39461864d84STakashi Iwai Toneport device disconnected. 39561864d84STakashi Iwai */ 396f66fd990STakashi Iwai static void line6_toneport_disconnect(struct usb_line6 *line6) 39761864d84STakashi Iwai { 398f66fd990STakashi Iwai struct usb_line6_toneport *toneport = 399f66fd990STakashi Iwai (struct usb_line6_toneport *)line6; 40061864d84STakashi Iwai 40161864d84STakashi Iwai del_timer_sync(&toneport->timer); 40261864d84STakashi Iwai 403*f2bd242fSChris Rorvick if (toneport_has_led(toneport)) 404f44edd7bSTakashi Iwai toneport_remove_leds(toneport); 40561864d84STakashi Iwai } 40661864d84STakashi Iwai 40761864d84STakashi Iwai 40861864d84STakashi Iwai /* 40961864d84STakashi Iwai Try to init Toneport device. 41061864d84STakashi Iwai */ 411f66fd990STakashi Iwai static int toneport_init(struct usb_line6 *line6, 412f66fd990STakashi Iwai const struct usb_device_id *id) 41361864d84STakashi Iwai { 41461864d84STakashi Iwai int err; 41561864d84STakashi Iwai struct usb_line6_toneport *toneport = (struct usb_line6_toneport *) line6; 41661864d84STakashi Iwai 417f66fd990STakashi Iwai toneport->type = id->driver_info; 4186dd1c05cSTakashi Iwai setup_timer(&toneport->timer, toneport_start_pcm, 4196dd1c05cSTakashi Iwai (unsigned long)toneport); 4206dd1c05cSTakashi Iwai 42161864d84STakashi Iwai line6->disconnect = line6_toneport_disconnect; 42261864d84STakashi Iwai 42361864d84STakashi Iwai /* initialize PCM subsystem: */ 42461864d84STakashi Iwai err = line6_init_pcm(line6, &toneport_pcm_properties); 42561864d84STakashi Iwai if (err < 0) 42661864d84STakashi Iwai return err; 42761864d84STakashi Iwai 42861864d84STakashi Iwai /* register monitor control: */ 42961864d84STakashi Iwai err = snd_ctl_add(line6->card, 43061864d84STakashi Iwai snd_ctl_new1(&toneport_control_monitor, 43161864d84STakashi Iwai line6->line6pcm)); 43261864d84STakashi Iwai if (err < 0) 43361864d84STakashi Iwai return err; 43461864d84STakashi Iwai 43561864d84STakashi Iwai /* register source select control: */ 43689444601SChris Rorvick if (toneport_has_source_select(toneport)) { 43761864d84STakashi Iwai err = 43861864d84STakashi Iwai snd_ctl_add(line6->card, 43961864d84STakashi Iwai snd_ctl_new1(&toneport_control_source, 44061864d84STakashi Iwai line6->line6pcm)); 44161864d84STakashi Iwai if (err < 0) 44261864d84STakashi Iwai return err; 44361864d84STakashi Iwai } 44461864d84STakashi Iwai 44561864d84STakashi Iwai line6_read_serial_number(line6, &toneport->serial_number); 44661864d84STakashi Iwai line6_read_data(line6, 0x80c2, &toneport->firmware_version, 1); 44761864d84STakashi Iwai 448*f2bd242fSChris Rorvick if (toneport_has_led(toneport)) { 449f44edd7bSTakashi Iwai err = toneport_init_leds(toneport); 450b2a3b023STakashi Iwai if (err < 0) 451b2a3b023STakashi Iwai return err; 45261864d84STakashi Iwai } 45361864d84STakashi Iwai 45461864d84STakashi Iwai toneport_setup(toneport); 45561864d84STakashi Iwai 45685a9339bSTakashi Iwai /* register audio system: */ 45785a9339bSTakashi Iwai return snd_card_register(line6->card); 45861864d84STakashi Iwai } 45961864d84STakashi Iwai 460ccddbe4aSTakashi Iwai #ifdef CONFIG_PM 46161864d84STakashi Iwai /* 46261864d84STakashi Iwai Resume Toneport device after reset. 46361864d84STakashi Iwai */ 464ccddbe4aSTakashi Iwai static int toneport_reset_resume(struct usb_interface *interface) 46561864d84STakashi Iwai { 466ccddbe4aSTakashi Iwai toneport_setup(usb_get_intfdata(interface)); 467ccddbe4aSTakashi Iwai return line6_resume(interface); 46861864d84STakashi Iwai } 469ccddbe4aSTakashi Iwai #endif 470ccddbe4aSTakashi Iwai 471ccddbe4aSTakashi Iwai #define LINE6_DEVICE(prod) USB_DEVICE(0x0e41, prod) 472ccddbe4aSTakashi Iwai #define LINE6_IF_NUM(prod, n) USB_DEVICE_INTERFACE_NUMBER(0x0e41, prod, n) 473ccddbe4aSTakashi Iwai 474ccddbe4aSTakashi Iwai /* table of devices that work with this driver */ 475ccddbe4aSTakashi Iwai static const struct usb_device_id toneport_id_table[] = { 476ccddbe4aSTakashi Iwai { LINE6_DEVICE(0x4750), .driver_info = LINE6_GUITARPORT }, 477ccddbe4aSTakashi Iwai { LINE6_DEVICE(0x4153), .driver_info = LINE6_PODSTUDIO_GX }, 478ccddbe4aSTakashi Iwai { LINE6_DEVICE(0x4150), .driver_info = LINE6_PODSTUDIO_UX1 }, 479ccddbe4aSTakashi Iwai { LINE6_IF_NUM(0x4151, 0), .driver_info = LINE6_PODSTUDIO_UX2 }, 480ccddbe4aSTakashi Iwai { LINE6_DEVICE(0x4147), .driver_info = LINE6_TONEPORT_GX }, 481ccddbe4aSTakashi Iwai { LINE6_DEVICE(0x4141), .driver_info = LINE6_TONEPORT_UX1 }, 482ccddbe4aSTakashi Iwai { LINE6_IF_NUM(0x4142, 0), .driver_info = LINE6_TONEPORT_UX2 }, 483ccddbe4aSTakashi Iwai {} 484ccddbe4aSTakashi Iwai }; 485ccddbe4aSTakashi Iwai 486ccddbe4aSTakashi Iwai MODULE_DEVICE_TABLE(usb, toneport_id_table); 487ccddbe4aSTakashi Iwai 488ccddbe4aSTakashi Iwai static const struct line6_properties toneport_properties_table[] = { 489ccddbe4aSTakashi Iwai [LINE6_GUITARPORT] = { 490ccddbe4aSTakashi Iwai .id = "GuitarPort", 491ccddbe4aSTakashi Iwai .name = "GuitarPort", 492ccddbe4aSTakashi Iwai .capabilities = LINE6_CAP_PCM, 493ccddbe4aSTakashi Iwai .altsetting = 2, /* 1..4 seem to be ok */ 494ccddbe4aSTakashi Iwai /* no control channel */ 495ccddbe4aSTakashi Iwai .ep_audio_r = 0x82, 496ccddbe4aSTakashi Iwai .ep_audio_w = 0x01, 497ccddbe4aSTakashi Iwai }, 498ccddbe4aSTakashi Iwai [LINE6_PODSTUDIO_GX] = { 499ccddbe4aSTakashi Iwai .id = "PODStudioGX", 500ccddbe4aSTakashi Iwai .name = "POD Studio GX", 501ccddbe4aSTakashi Iwai .capabilities = LINE6_CAP_PCM, 502ccddbe4aSTakashi Iwai .altsetting = 2, /* 1..4 seem to be ok */ 503ccddbe4aSTakashi Iwai /* no control channel */ 504ccddbe4aSTakashi Iwai .ep_audio_r = 0x82, 505ccddbe4aSTakashi Iwai .ep_audio_w = 0x01, 506ccddbe4aSTakashi Iwai }, 507ccddbe4aSTakashi Iwai [LINE6_PODSTUDIO_UX1] = { 508ccddbe4aSTakashi Iwai .id = "PODStudioUX1", 509ccddbe4aSTakashi Iwai .name = "POD Studio UX1", 510ccddbe4aSTakashi Iwai .capabilities = LINE6_CAP_PCM, 511ccddbe4aSTakashi Iwai .altsetting = 2, /* 1..4 seem to be ok */ 512ccddbe4aSTakashi Iwai /* no control channel */ 513ccddbe4aSTakashi Iwai .ep_audio_r = 0x82, 514ccddbe4aSTakashi Iwai .ep_audio_w = 0x01, 515ccddbe4aSTakashi Iwai }, 516ccddbe4aSTakashi Iwai [LINE6_PODSTUDIO_UX2] = { 517ccddbe4aSTakashi Iwai .id = "PODStudioUX2", 518ccddbe4aSTakashi Iwai .name = "POD Studio UX2", 519ccddbe4aSTakashi Iwai .capabilities = LINE6_CAP_PCM, 520ccddbe4aSTakashi Iwai .altsetting = 2, /* defaults to 44.1kHz, 16-bit */ 521ccddbe4aSTakashi Iwai /* no control channel */ 522ccddbe4aSTakashi Iwai .ep_audio_r = 0x82, 523ccddbe4aSTakashi Iwai .ep_audio_w = 0x01, 524ccddbe4aSTakashi Iwai }, 525ccddbe4aSTakashi Iwai [LINE6_TONEPORT_GX] = { 526ccddbe4aSTakashi Iwai .id = "TonePortGX", 527ccddbe4aSTakashi Iwai .name = "TonePort GX", 528ccddbe4aSTakashi Iwai .capabilities = LINE6_CAP_PCM, 529ccddbe4aSTakashi Iwai .altsetting = 2, /* 1..4 seem to be ok */ 530ccddbe4aSTakashi Iwai /* no control channel */ 531ccddbe4aSTakashi Iwai .ep_audio_r = 0x82, 532ccddbe4aSTakashi Iwai .ep_audio_w = 0x01, 533ccddbe4aSTakashi Iwai }, 534ccddbe4aSTakashi Iwai [LINE6_TONEPORT_UX1] = { 535ccddbe4aSTakashi Iwai .id = "TonePortUX1", 536ccddbe4aSTakashi Iwai .name = "TonePort UX1", 537ccddbe4aSTakashi Iwai .capabilities = LINE6_CAP_PCM, 538ccddbe4aSTakashi Iwai .altsetting = 2, /* 1..4 seem to be ok */ 539ccddbe4aSTakashi Iwai /* no control channel */ 540ccddbe4aSTakashi Iwai .ep_audio_r = 0x82, 541ccddbe4aSTakashi Iwai .ep_audio_w = 0x01, 542ccddbe4aSTakashi Iwai }, 543ccddbe4aSTakashi Iwai [LINE6_TONEPORT_UX2] = { 544ccddbe4aSTakashi Iwai .id = "TonePortUX2", 545ccddbe4aSTakashi Iwai .name = "TonePort UX2", 546ccddbe4aSTakashi Iwai .capabilities = LINE6_CAP_PCM, 547ccddbe4aSTakashi Iwai .altsetting = 2, /* defaults to 44.1kHz, 16-bit */ 548ccddbe4aSTakashi Iwai /* no control channel */ 549ccddbe4aSTakashi Iwai .ep_audio_r = 0x82, 550ccddbe4aSTakashi Iwai .ep_audio_w = 0x01, 551ccddbe4aSTakashi Iwai }, 552ccddbe4aSTakashi Iwai }; 553ccddbe4aSTakashi Iwai 554ccddbe4aSTakashi Iwai /* 555ccddbe4aSTakashi Iwai Probe USB device. 556ccddbe4aSTakashi Iwai */ 557ccddbe4aSTakashi Iwai static int toneport_probe(struct usb_interface *interface, 558ccddbe4aSTakashi Iwai const struct usb_device_id *id) 559ccddbe4aSTakashi Iwai { 560aca514b8STakashi Iwai return line6_probe(interface, id, 561ccddbe4aSTakashi Iwai &toneport_properties_table[id->driver_info], 562aca514b8STakashi Iwai toneport_init, sizeof(struct usb_line6_toneport)); 563ccddbe4aSTakashi Iwai } 564ccddbe4aSTakashi Iwai 565ccddbe4aSTakashi Iwai static struct usb_driver toneport_driver = { 566ccddbe4aSTakashi Iwai .name = KBUILD_MODNAME, 567ccddbe4aSTakashi Iwai .probe = toneport_probe, 568ccddbe4aSTakashi Iwai .disconnect = line6_disconnect, 569ccddbe4aSTakashi Iwai #ifdef CONFIG_PM 570ccddbe4aSTakashi Iwai .suspend = line6_suspend, 571ccddbe4aSTakashi Iwai .resume = line6_resume, 572ccddbe4aSTakashi Iwai .reset_resume = toneport_reset_resume, 573ccddbe4aSTakashi Iwai #endif 574ccddbe4aSTakashi Iwai .id_table = toneport_id_table, 575ccddbe4aSTakashi Iwai }; 576ccddbe4aSTakashi Iwai 577ccddbe4aSTakashi Iwai module_usb_driver(toneport_driver); 578ccddbe4aSTakashi Iwai 579ccddbe4aSTakashi Iwai MODULE_DESCRIPTION("TonePort USB driver"); 580ccddbe4aSTakashi Iwai MODULE_LICENSE("GPL"); 581