upport for the i.MX6 processor family.
aboutsummaryrefslogblamecommitdiffstats
path: root/drivers/regulator/virtual.c
blob: 01c66e9712a4aa236ba36ed409abbbce51cd66f2 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
















                                                                     
                       
                         



                                    
                     






                          

                                                                          




                                              

                                                    
                                                            
                                                                    
                               

                                                                             




                                                             
                                                     

                                                        
                                             
                    
                                                                       



                                                               
                                                      

                                                         
                                              
                    
                                                                        



                                     

                                                                             




                                              

                                                    


                                                                    


                                                                             




                                             
                                                     

                                                        
                                             
                    
                                                                       



                                                               
                                                      

                                                         
                                              
                    
                                                                        
















                                                                            
                                        




                                
                                              


















                                                                            
                                        




                                
                                              


















                                                                            
                                        




                                
                                                    


















                                                                            
                                        




                                
                                                    































                                                                          



                                                                              
                                       
                                           
                                              
                                             
                                            
                                           
                                               






















                                                                    






                                                           

  



                                                                    
                                                                


                                               
                
 

                                                                                
                            
                               


                                   
                                                                    

                                                  

                                                                         
                           

         




                                                                       
                           






                                                               

 
                                                                 

                                                                           
 

                                                                           

                                                      
 

                                         



                                                                   
                                                  
                                                   

                                                      
                                              


          
                                                          



                                                                  
                                           
/*
 * reg-virtual-consumer.c
 *
 * Copyright 2008 Wolfson Microelectronics PLC.
 *
 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
 *
 * 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.
 */

#include <linux/err.h>
#include <linux/mutex.h>
#include <linux/platform_device.h>
#include <linux/regulator/consumer.h>
#include <linux/slab.h>
#include <linux/module.h>

struct virtual_consumer_data {
	struct mutex lock;
	struct regulator *regulator;
	bool enabled;
	int min_uV;
	int max_uV;
	int min_uA;
	int max_uA;
	unsigned int mode;
};

static void update_voltage_constraints(struct device *dev,
				       struct virtual_consumer_data *data)
{
	int ret;

	if (data->min_uV && data->max_uV
	    && data->min_uV <= data->max_uV) {
		dev_dbg(dev, "Requesting %d-%duV\n",
			data->min_uV, data->max_uV);
		ret = regulator_set_voltage(data->regulator,
					data->min_uV, data->max_uV);
		if (ret != 0) {
			dev_err(dev,
				"regulator_set_voltage() failed: %d\n", ret);
			return;
		}
	}

	if (data->min_uV && data->max_uV && !data->enabled) {
		dev_dbg(dev, "Enabling regulator\n");
		ret = regulator_enable(data->regulator);
		if (ret == 0)
			data->enabled = true;
		else
			dev_err(dev, "regulator_enable() failed: %d\n",
				ret);
	}

	if (!(data->min_uV && data->max_uV) && data->enabled) {
		dev_dbg(dev, "Disabling regulator\n");
		ret = regulator_disable(data->regulator);
		if (ret == 0)
			data->enabled = false;
		else
			dev_err(dev, "regulator_disable() failed: %d\n",
				ret);
	}
}

static void update_current_limit_constraints(struct device *dev,
					  struct virtual_consumer_data *data)
{
	int ret;