Staging: line6: fix checkpatch errors in dumprequest.c
[linux-2.6] / drivers / staging / line6 / toneport.c
1 /*
2  * Line6 Linux USB driver - 0.8.0
3  *
4  * Copyright (C) 2004-2009 Markus Grabner (grabner@icg.tugraz.at)
5  *                         Emil Myhrman (emil.myhrman@gmail.com)
6  *
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.
10  *
11  */
12
13 #include "driver.h"
14
15 #include "audio.h"
16 #include "capture.h"
17 #include "playback.h"
18 #include "toneport.h"
19
20
21 static int toneport_send_cmd(struct usb_device *usbdev, int cmd1, int cmd2);
22
23
24 static struct snd_ratden toneport_ratden = {
25         .num_min = 44100,
26         .num_max = 44100,
27         .num_step = 1,
28         .den = 1
29 };
30
31 static struct line6_pcm_properties toneport_pcm_properties = {
32   .snd_line6_playback_hw = {
33                 .info = (SNDRV_PCM_INFO_MMAP |
34                                                  SNDRV_PCM_INFO_INTERLEAVED |
35                                                  SNDRV_PCM_INFO_BLOCK_TRANSFER |
36                                                  SNDRV_PCM_INFO_MMAP_VALID |
37                                                  SNDRV_PCM_INFO_PAUSE |
38                                                  SNDRV_PCM_INFO_SYNC_START),
39                 .formats =          SNDRV_PCM_FMTBIT_S16_LE,
40                 .rates =            SNDRV_PCM_RATE_KNOT,
41                 .rate_min =         44100,
42                 .rate_max =         44100,
43                 .channels_min =     2,
44                 .channels_max =     2,
45                 .buffer_bytes_max = 60000,
46                 .period_bytes_min = 180 * 4,
47                 .period_bytes_max = 8192,
48                 .periods_min =      1,
49                 .periods_max =      1024
50         },
51   .snd_line6_capture_hw = {
52                 .info = (SNDRV_PCM_INFO_MMAP |
53                                                  SNDRV_PCM_INFO_INTERLEAVED |
54                                                  SNDRV_PCM_INFO_BLOCK_TRANSFER |
55                                                  SNDRV_PCM_INFO_MMAP_VALID |
56                                                  SNDRV_PCM_INFO_SYNC_START),
57                 .formats =          SNDRV_PCM_FMTBIT_S16_LE,
58                 .rates =            SNDRV_PCM_RATE_KNOT,
59                 .rate_min =         44100,
60                 .rate_max =         44100,
61                 .channels_min =     2,
62                 .channels_max =     2,
63                 .buffer_bytes_max = 60000,
64                 .period_bytes_min = 188 * 4,
65                 .period_bytes_max = 8192,
66                 .periods_min =      1,
67                 .periods_max =      1024
68         },
69         .snd_line6_rates = {
70                 .nrats = 1,
71                 .rats = &toneport_ratden
72         },
73         .bytes_per_frame = 4
74 };
75
76 /*
77         For the led on Guitarport.
78         Brightness goes from 0x00 to 0x26. Set a value above this to have led blink.
79         (void cmd_0x02(byte red, byte green)
80 */
81 static int led_red = 0x00;
82 static int led_green = 0x26;
83
84 static void toneport_update_led(struct device *dev)  {
85         struct usb_interface *interface;
86         struct usb_line6_toneport *tp;
87         struct usb_line6* line6;
88
89         if ((interface = to_usb_interface(dev)) &&
90                 (tp = usb_get_intfdata(interface)) &&
91                 (line6 = &tp->line6))
92                         toneport_send_cmd(line6->usbdev, (led_red<<8)|0x0002, led_green);       // for setting the LED on Guitarport
93 }
94 static ssize_t toneport_set_led_red(struct device *dev,
95                                     struct device_attribute *attr,
96                                     const char *buf, size_t count)  {
97         char* c;
98         led_red = simple_strtol(buf, &c, 10);
99         toneport_update_led(dev);
100         return count;
101 }
102 static ssize_t toneport_set_led_green(struct device *dev,
103                                       struct device_attribute *attr,
104                                       const char *buf, size_t count)  {
105         char* c;
106         led_green = simple_strtol(buf, &c, 10);
107         toneport_update_led(dev);
108         return count;
109 }
110
111 static DEVICE_ATTR(led_red, S_IWUGO | S_IRUGO, line6_nop_read, toneport_set_led_red);
112 static DEVICE_ATTR(led_green, S_IWUGO | S_IRUGO, line6_nop_read, toneport_set_led_green);
113
114
115 static int toneport_send_cmd(struct usb_device *usbdev, int cmd1, int cmd2)
116 {
117         int ret;
118         ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev,0), 0x67,
119                                                                                                 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
120                                                                                                 cmd1, cmd2, NULL, 0, LINE6_TIMEOUT * HZ);
121
122         if(ret < 0)     {
123                 err("send failed (error %d)\n", ret);
124                 return ret;
125         }
126
127         return 0;
128 }
129
130 /*
131         Toneport destructor.
132 */
133 static void toneport_destruct(struct usb_interface *interface)
134 {
135         struct usb_line6_toneport *toneport = usb_get_intfdata(interface);
136         struct usb_line6 *line6;
137
138         if(toneport == NULL) return;
139         line6 = &toneport->line6;
140         if(line6 == NULL) return;
141         line6_cleanup_audio(line6);
142 }
143
144 /*
145          Init Toneport device.
146 */
147 int toneport_init(struct usb_interface *interface, struct usb_line6_toneport *toneport)
148 {
149         int err, ticks;
150         struct usb_line6 *line6 = &toneport->line6;
151         struct usb_device *usbdev;
152
153         if((interface == NULL) || (toneport == NULL))
154                 return -ENODEV;
155
156         /* initialize audio system: */
157         if((err = line6_init_audio(line6)) < 0) {
158                 toneport_destruct(interface);
159                 return err;
160         }
161
162         /* initialize PCM subsystem: */
163         if((err = line6_init_pcm(line6, &toneport_pcm_properties)) < 0) {
164                 toneport_destruct(interface);
165                 return err;
166         }
167
168         /* register audio system: */
169         if((err = line6_register_audio(line6)) < 0) {
170                 toneport_destruct(interface);
171                 return err;
172         }
173
174         usbdev = line6->usbdev;
175         line6_read_serial_number(line6, &toneport->serial_number);
176         line6_read_data(line6, 0x80c2, &toneport->firmware_version, 1);
177
178         /* sync time on device with host: */
179         ticks = (int)get_seconds();
180         line6_write_data(line6, 0x80c6, &ticks, 4);
181
182         /*
183         seems to work without the first two...
184         */
185         //toneport_send_cmd(usbdev, 0x0201, 0x0002);  // ..
186         //toneport_send_cmd(usbdev, 0x0801, 0x0000);  // ..
187         toneport_send_cmd(usbdev, 0x0301, 0x0000);      // only one that works for me; on GP, TP might be different?
188
189         if (usbdev->descriptor.idProduct!=LINE6_DEVID_GUITARPORT) {
190                 CHECK_RETURN(device_create_file(&interface->dev, &dev_attr_led_red));
191                 CHECK_RETURN(device_create_file(&interface->dev, &dev_attr_led_green));
192                 toneport_update_led(&usbdev->dev);
193         }
194
195         return 0;
196 }
197
198 /*
199         Toneport device disconnected.
200 */
201 void toneport_disconnect(struct usb_interface *interface)
202 {
203         struct usb_line6_toneport *toneport;
204
205         if(interface == NULL) return;
206         toneport = usb_get_intfdata(interface);
207
208         if (toneport->line6.usbdev->descriptor.idProduct != LINE6_DEVID_GUITARPORT) {
209                 device_remove_file(&interface->dev, &dev_attr_led_red);
210                 device_remove_file(&interface->dev, &dev_attr_led_green);
211         }
212
213         if(toneport != NULL) {
214                 struct snd_line6_pcm *line6pcm = toneport->line6.line6pcm;
215
216                 if(line6pcm != NULL) {
217                         unlink_wait_clear_audio_out_urbs(line6pcm);
218                         unlink_wait_clear_audio_in_urbs(line6pcm);
219                 }
220         }
221
222         toneport_destruct(interface);
223 }