or' content='cgit v1.2.2'/>
aboutsummaryrefslogblamecommitdiffstats
path: root/drivers/media/usb/au0828/au0828-i2c.c
blob: ae7ac6669769f3cdcc2d2ba01db5cc0c73ce5039 (plain) (tree)
1
2
3
4


                                            
                                                      
















                                                                        

                   



                              
                     
 
                        

                              
                    


                                                          

                           



                                                                       

                                                        




                                                                      

                                                        




















                                                                

                                                        




















                                                                 

                                                        




















                                                            

                                                        























                                                          
                                                  
 
                                       
 
                                                               
 

                                                         









                                                                         
         

                                                                 

                                            
                                                                    
 
                                              
 







                                                                               


                                                         








                                                
                                    
 
                                                   
 
                                                                          







                                                          


                                                                         
                            

                                                                         












                                                           
                         








                                                      
                                                  

              
                                       
 
                                                               
 








                                                                    
                               
                                                                 

                                            
                                                                    
 
                               


                                


                                                         




                                                
                                    



                                 


                                                                 
                    

                                                                 



                                                  

                                                                            
 
                                                     



                                     
                         








                                                  
                                                    
 
                                   
                                                                      
                                                                  
























                                                                           












                                                                             
                                            
                                         
                                                       






                                                       


                                     











                                                         
                                                                    



                                                                        
                                 

                                               
                                       
 


                                                     


                                                     
                                                   

                                            
                                            
                                      
                               
                                                         


                                              




                                                 
                                                
                             
                                                                      
              
                                                     
 








                                                 
/*
 *  Driver for the Auvitek AU0828 USB bridge
 *
 *  Copyright (c) 2008 Steven Toth <stoth@linuxtv.org>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it 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 program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include "au0828.h"

#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/io.h>

#include "media/tuner.h"
#include <media/v4l2-common.h>

static int i2c_scan;
module_param(i2c_scan, int, 0444);
MODULE_PARM_DESC(i2c_scan, "scan i2c bus at insmod time");

#define I2C_WAIT_DELAY 25
#define I2C_WAIT_RETRY 1000

static inline int i2c_slave_did_write_ack(struct i2c_adapter *i2c_adap)
{
	struct au0828_dev *dev = i2c_adap->algo_data;
	return au0828_read(dev, AU0828_I2C_STATUS_201) &
		AU0828_I2C_STATUS_NO_WRITE_ACK ? 0 : 1;
}

static inline int i2c_slave_did_read_ack(struct i2c_adapter *i2c_adap)
{
	struct au0828_dev *dev = i2c_adap->algo_data;
	return au0828_read(dev, AU0828_I2C_STATUS_201) &
		AU0828_I2C_STATUS_NO_READ_ACK ? 0 : 1;
}

static int i2c_wait_read_ack(struct i2c_adapter *i2c_adap)
{
	int count;

	for (count = 0; count < I2C_WAIT_RETRY; count++) {
		if (!i2c_slave_did_read_ack(i2c_adap))
			break;
		udelay(I2C_WAIT_DELAY);
	}

	if (I2C_WAIT_RETRY == count)
		return 0;

	return 1;
}

static inline int i2c_is_read_busy(struct i2c_adapter *i2c_adap)
{
	struct au0828_dev *dev = i2c_adap->algo_data;
	return au0828_read(dev, AU0828_I2C_STATUS_201) &
		AU0828_I2C_STATUS_READ_DONE ? 0 : 1;
}

static int i2c_wait_read_done(struct i2c_adapter *i2c_adap)
{
	int count;

	for (count = 0; count < I2C_WAIT_RETRY; count++) {
		if (!i2c_is_read_busy(i2c_adap))
			break;
		udelay(I2C_WAIT_DELAY);
	}

	if (I2C_WAIT_RETRY == count)
		return 0;

	return 1;
}

static inline int i2c_is_write_done(struct i2c_adapter *i2c_adap)
{
	struct au0828_dev *dev = i2c_adap->algo_data;
	return au0828_read(dev, AU0828_I2C_STATUS_201) &
		AU0828_I2C_STATUS_WRITE_DONE ? 1 : 0;
}

static int i2c_wait_write_done(struct i2c_adapter *i2c_adap)
{
	int count;

	for (count = 0; count < I2C_WAIT_RETRY; count++) {
		if (i2c_is_write_done(i2c_adap))
			break;