/sound/pci/

>
path: root/sound/usb/usbmidi.c
blob: 6676a177c99e3342117051a179c4588bdbdd0335 (plain) (tree)
1
2
3
4


                                   
                                          
































                                                                             







                            
                        

                       
                          
                             







                                     





                                                                            





















                                                      


                                 

                         

                                                                       
                                                                               

                                                                       


                     
                                   
                                    

                                                

                                                  
                                      
                             

                                      

                                                      

                                        
                                   


                                  
                                   







                                                                

                                                        















                                                               
                                   

                                
                                                        
                                         
                      

                          


                         
                                                                        







                                                      
                                                               











                                                                 







                                                       


                     




                                                               




                                 
                                                                                    

                                                             
                                                           
























                                                                            
                                                        
 
                                                           





                                                                               






                                                                         
                               
                 

         

                                                

 
                                                         
 
                                                            




                                      




                                                                         
                               
                 







                                                                    
                                                                       























                                                                              
                                                                                         



                                  


                                                                       
                                                                 

              




                                               
                                                  
                                                                             







                                                                       
                                       

 
                                                               
                                                                      


                                                           
                                                   

                               












                                                                            
                                                                           











                                                                                  
                                                                          












                                                                             







































                                                                                  













                                                                             































                                                                                    
                                                                    




























































































                                                                                                  
                                                                             





                                                                          
                                                              
























                                                                                





                                                                               





                                                            





                                                                           
                                                                           






                                                                             
                                                                             
























                                                            
                                             

   
                                                                      
                                                                     



                                                             
                                                                        














                                                              


                                                      





                                                                  
                                                                             















                                                                    
                                                                               














                                                                    
                                                                         

                                                                        







                                            





                                             


























                                                                        
                                                                           








                                                                    
                                                                    



























                                                                              



                                                          










                                                                      
                                                                           
 

                                                                    

















                                                                                               
                                                                            



                 
                                                                                       
 
                                                                                                   













                                                                       
                                                                          



                 
                                                                           



                 
                                                                                      
 
                                                                    






                                                                      
                                                        




                                              
                                                       








                                                            
                                                                               

                      



                                                                







                                      


                                                                                     
 
                                            




                          
                                              













                                                                         

                                                                       




                                                   


                                                                         
            

                                                                           
                                                          






                                                          
                          
 

                                 






                                                            
                                                                                 
 
                      


                                                                       







                                                            


                                                                                      
 
                                             




                          
                                              








                                                    



                                                                          




                                                                                

                                                                      



                                                    







                                                                                
                                                          



















                                                                               
                                                        



                                                  
                                                                        










                                                                    
                                                
 
                                   

              
                                                         







                                                                 
                                                  
                                                                        

                                                        




                                                                                      
                           

                                                  
                                            

 
                                                               
 
                                                         


                                
                                                                                           




                                                                                  
                                                                                                               










                                                                        
                         
               




































                                                                
                           
                                                      
                            





                                                              
                        

                                                      
                            


                                                             
                           


                                                             
                           


                                                             
                           
                                                      
                          



                                                               
                           
                                                      
                          


                                                              
                          



                                                               
                           

                                                      
                           


                                                             
                        


                                                    
                        

                                                      
                            

                                                      
                          


                                                    
                          


                                                    
                           
                                                      
                                   

                                                      
                           

                                                      
                                     


                                                         

  

























                                                                               
                                                                  
                                                              
                                                                                  
 
                                    

                                
                                                                                                    





                                                                                   

                                                                 








                                                                        

                                                                                     






































                                                                                                         

                                                                                















































                                                                                                     






                                                                                      












                                                                                                     

                                                                                      











                                                                                       
                                                                            
























                                                                                                             

                                                                                    







                                                          
                                                         

                                                            


                                                    































                                                                                                      

                                                                                              















                                                                                 

                                                                                 




















                                                                           
                                                        














                                                                                       

                                                                                            
 
                                                  














































































                                                                                                             



                                                        
                                                                 

                                                                  
                                  










                                                              
                                      













                                                                                         
                                   

              
                                                         
                                                  
                                                                        




                                                  
                                                                           












                                                         
                                   

              
                                                         






                                                                          
                                                             
                                                              
                                                                          
 

                                                                        


                                
                                                    





                                                            
                                        
                                          

                                                              


                                                

                                                                      
                                                                


                                                                              


                                                  
                                                                  







                                                                            
                                                                  












                                                                              
                                                                  

                                                                            
                            
                                                               





                                                                              







































                                                                                 
/*
 * usbmidi.c - ALSA USB MIDI driver
 *
 * Copyright (c) 2002-2007 Clemens Ladisch
 * All rights reserved.
 *
 * Based on the OSS usb-midi driver by NAGANO Daisuke,
 *          NetBSD's umidi driver by Takuya SHIOZAKI,
 *          the "USB Device Class Definition for MIDI Devices" by Roland
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions, and the following disclaimer,
 *    without modification.
 * 2. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * Alternatively, this software may be distributed and/or modified under the
 * terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/bitops.h>
#include <linux/interrupt.h>
#include <linux/spinlock.h>
#include <linux/string.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/timer.h>
#include <linux/usb.h>
#include <sound/core.h>
#include <sound/rawmidi.h>
#include <sound/asequencer.h>
#include "usbaudio.h"


/*
 * define this to log all USB packets
 */
/* #define DUMP_PACKETS */

/*
 * how long to wait after some USB errors, so that khubd can disconnect() us
 * without too many spurious errors
 */
#define ERROR_DELAY_JIFFIES (HZ / 10)


MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
MODULE_DESCRIPTION("USB Audio/MIDI helper module");
MODULE_LICENSE("Dual BSD/GPL");


struct usb_ms_header_descriptor {
	__u8  bLength;
	__u8  bDescriptorType;
	__u8  bDescriptorSubtype;
	__u8  bcdMSC[2];
	__le16 wTotalLength;
} __attribute__ ((packed));

struct usb_ms_endpoint_descriptor {
	__u8  bLength;
	__u8  bDescriptorType;
	__u8  bDescriptorSubtype;
	__u8  bNumEmbMIDIJack;
	__u8  baAssocJackID[0];
} __attribute__ ((packed));

struct snd_usb_midi_in_endpoint;
struct snd_usb_midi_out_endpoint;
struct snd_usb_midi_endpoint;

struct usb_protocol_ops {
	void (*input)(struct snd_usb_midi_in_endpoint*, uint8_t*, int);
	void (*output)(struct snd_usb_midi_out_endpoint*);
	void (*output_packet)(struct urb*, uint8_t, uint8_t, uint8_t, uint8_t);
	void (*init_out_endpoint)(struct snd_usb_midi_out_endpoint*);
	void (*finish_out_endpoint)(struct snd_usb_midi_out_endpoint*);
};

struct snd_usb_midi {
	struct snd_usb_audio *chip;
	struct usb_interface *iface;
	const struct snd_usb_audio_quirk *quirk;
	struct snd_rawmidi *rmidi;
	struct usb_protocol_ops* usb_protocol_ops;
	struct list_head list;
	struct timer_list error_timer;
	spinlock_t disc_lock;