RT-AC56 3.0.0.4.374.37 core
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / drivers / staging / line6 / toneport.c
blobdb421781d5504d1b234f180ba580019f12e73e1b
1 /*
2 * Line6 Linux USB driver - 0.8.0
4 * Copyright (C) 2004-2009 Markus Grabner (grabner@icg.tugraz.at)
5 * Emil Myhrman (emil.myhrman@gmail.com)
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation, version 2.
13 #include "driver.h"
15 #include "audio.h"
16 #include "capture.h"
17 #include "playback.h"
18 #include "toneport.h"
20 static int toneport_send_cmd(struct usb_device *usbdev, int cmd1, int cmd2);
22 static struct snd_ratden toneport_ratden = {
23 .num_min = 44100,
24 .num_max = 44100,
25 .num_step = 1,
26 .den = 1
29 static struct line6_pcm_properties toneport_pcm_properties = {
30 .snd_line6_playback_hw = {
31 .info = (SNDRV_PCM_INFO_MMAP |
32 SNDRV_PCM_INFO_INTERLEAVED |
33 SNDRV_PCM_INFO_BLOCK_TRANSFER |
34 SNDRV_PCM_INFO_MMAP_VALID |
35 SNDRV_PCM_INFO_PAUSE |
36 SNDRV_PCM_INFO_SYNC_START),
37 .formats = SNDRV_PCM_FMTBIT_S16_LE,
38 .rates = SNDRV_PCM_RATE_KNOT,
39 .rate_min = 44100,
40 .rate_max = 44100,
41 .channels_min = 2,
42 .channels_max = 2,
43 .buffer_bytes_max = 60000,
44 .period_bytes_min = 180 * 4,
45 .period_bytes_max = 8192,
46 .periods_min = 1,
47 .periods_max = 1024},
48 .snd_line6_capture_hw = {
49 .info = (SNDRV_PCM_INFO_MMAP |
50 SNDRV_PCM_INFO_INTERLEAVED |
51 SNDRV_PCM_INFO_BLOCK_TRANSFER |
52 SNDRV_PCM_INFO_MMAP_VALID |
53 SNDRV_PCM_INFO_SYNC_START),
54 .formats = SNDRV_PCM_FMTBIT_S16_LE,
55 .rates = SNDRV_PCM_RATE_KNOT,
56 .rate_min = 44100,
57 .rate_max = 44100,
58 .channels_min = 2,
59 .channels_max = 2,
60 .buffer_bytes_max = 60000,
61 .period_bytes_min = 188 * 4,
62 .period_bytes_max = 8192,
63 .periods_min = 1,
64 .periods_max = 1024},
65 .snd_line6_rates = {
66 .nrats = 1,
67 .rats = &toneport_ratden},
68 .bytes_per_frame = 4
72 For the led on Guitarport.
73 Brightness goes from 0x00 to 0x26. Set a value above this to have led
74 blink.
75 (void cmd_0x02(byte red, byte green)
77 static int led_red = 0x00;
78 static int led_green = 0x26;
80 static void toneport_update_led(struct device *dev)
82 struct usb_interface *interface = to_usb_interface(dev);
83 struct usb_line6_toneport *tp = usb_get_intfdata(interface);
84 struct usb_line6 *line6;
86 if (!tp)
87 return;
89 line6 = &tp->line6;
90 if (line6)
91 toneport_send_cmd(line6->usbdev, (led_red << 8) | 0x0002,
92 led_green);
95 static ssize_t toneport_set_led_red(struct device *dev,
96 struct device_attribute *attr,
97 const char *buf, size_t count)
99 int retval;
100 long value;
102 retval = strict_strtol(buf, 10, &value);
103 if (retval)
104 return retval;
106 led_red = value;
107 toneport_update_led(dev);
108 return count;
111 static ssize_t toneport_set_led_green(struct device *dev,
112 struct device_attribute *attr,
113 const char *buf, size_t count)
115 int retval;
116 long value;
118 retval = strict_strtol(buf, 10, &value);
119 if (retval)
120 return retval;
122 led_green = value;
123 toneport_update_led(dev);
124 return count;
127 static DEVICE_ATTR(led_red, S_IWUSR | S_IRUGO, line6_nop_read,
128 toneport_set_led_red);
129 static DEVICE_ATTR(led_green, S_IWUSR | S_IRUGO, line6_nop_read,
130 toneport_set_led_green);
132 static int toneport_send_cmd(struct usb_device *usbdev, int cmd1, int cmd2)
134 int ret;
136 ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67,
137 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
138 cmd1, cmd2, NULL, 0, LINE6_TIMEOUT * HZ);
140 if (ret < 0) {
141 err("send failed (error %d)\n", ret);
142 return ret;
145 return 0;
149 Toneport destructor.
151 static void toneport_destruct(struct usb_interface *interface)
153 struct usb_line6_toneport *toneport = usb_get_intfdata(interface);
154 struct usb_line6 *line6;
156 if (toneport == NULL)
157 return;
158 line6 = &toneport->line6;
159 if (line6 == NULL)
160 return;
161 line6_cleanup_audio(line6);
165 Init Toneport device.
167 int toneport_init(struct usb_interface *interface,
168 struct usb_line6_toneport *toneport)
170 int err, ticks;
171 struct usb_line6 *line6 = &toneport->line6;
172 struct usb_device *usbdev;
174 if ((interface == NULL) || (toneport == NULL))
175 return -ENODEV;
177 /* initialize audio system: */
178 err = line6_init_audio(line6);
179 if (err < 0) {
180 toneport_destruct(interface);
181 return err;
184 /* initialize PCM subsystem: */
185 err = line6_init_pcm(line6, &toneport_pcm_properties);
186 if (err < 0) {
187 toneport_destruct(interface);
188 return err;
191 /* register audio system: */
192 err = line6_register_audio(line6);
193 if (err < 0) {
194 toneport_destruct(interface);
195 return err;
198 usbdev = line6->usbdev;
199 line6_read_serial_number(line6, &toneport->serial_number);
200 line6_read_data(line6, 0x80c2, &toneport->firmware_version, 1);
202 /* sync time on device with host: */
203 ticks = (int)get_seconds();
204 line6_write_data(line6, 0x80c6, &ticks, 4);
207 seems to work without the first two...
209 /* toneport_send_cmd(usbdev, 0x0201, 0x0002); */
210 /* toneport_send_cmd(usbdev, 0x0801, 0x0000); */
211 /* only one that works for me; on GP, TP might be different? */
212 toneport_send_cmd(usbdev, 0x0301, 0x0000);
214 if (usbdev->descriptor.idProduct != LINE6_DEVID_GUITARPORT) {
215 CHECK_RETURN(device_create_file
216 (&interface->dev, &dev_attr_led_red));
217 CHECK_RETURN(device_create_file
218 (&interface->dev, &dev_attr_led_green));
219 toneport_update_led(&usbdev->dev);
222 return 0;
226 Toneport device disconnected.
228 void toneport_disconnect(struct usb_interface *interface)
230 struct usb_line6_toneport *toneport;
232 if (interface == NULL)
233 return;
234 toneport = usb_get_intfdata(interface);
236 if (toneport->line6.usbdev->descriptor.idProduct !=
237 LINE6_DEVID_GUITARPORT) {
238 device_remove_file(&interface->dev, &dev_attr_led_red);
239 device_remove_file(&interface->dev, &dev_attr_led_green);
242 if (toneport != NULL) {
243 struct snd_line6_pcm *line6pcm = toneport->line6.line6pcm;
245 if (line6pcm != NULL) {
246 unlink_wait_clear_audio_out_urbs(line6pcm);
247 unlink_wait_clear_audio_in_urbs(line6pcm);
251 toneport_destruct(interface);