Esempio n. 1
0
static int lm3559_flash(unsigned char timeout)                                                                       
{                                                                                                                    
	unsigned char value;                                                                                          
	if (timeout > 0x1f)                                                                                           
		return	-1;                                                                                           
	                                                                                                              
	// Set flash brightness                                                                                       
	lm3559_write(FLASH_BRIGHTNESS_REG_INDEX, (flash_brightness << 4) | flash_brightness);                         
	                                                                                                              
	value	=	lm3559_read(FLASH_DURATION_REG_INDEX);                                                        
                                                                                                                     
	clrbits(value, 0x1F);                                                                                         
	setbits(value, timeout);                                                                                      
	lm3559_write(FLASH_DURATION_REG_INDEX, value);                                                                
	                                                                                                              
                                                                                                                     
	value	=	lm3559_read(ENABLE_REG_INDEX);                                                                
	setbits(value, 0x03);                                                                                         
	lm3559_write(ENABLE_REG_INDEX, value);                                                                        
	                                                                                                              
	return 0;                                                                                                     
}                                                                                                                    
Esempio n. 2
0
static int lm3559_set_mode(struct lm3559 *flash, unsigned int mode)
{
	u8 val;
	int ret;

	val = lm3559_read(flash, LM3559_ENABLE_REG);
	val &= ~LM3559_MODE_MASK;
	val |= (mode & LM3559_MODE_MASK) << LM3559_MODE_SHIFT;

	ret = lm3559_write(flash, LM3559_ENABLE_REG, val);
	if (ret == 0)
		flash->mode = mode;
	return ret;
}
Esempio n. 3
0
static int lm3559_torch(unsigned char brightness)                                                                    
{                                                                                                                    
	unsigned char value;                                                                                          
                                                                                                                     
	if (brightness > 0x1F)                                                                                        
		brightness	=	0x1F;                                                                         
                                                                                                                     
	lm3559_write(TORCH_BRIGHTNESS_REG_INDEX, brightness);//set torch brightness                                   
                                                                                                                     
	value = lm3559_read(ENABLE_REG_INDEX);                                                                        
	clrbits(value, 0x01);                                                                                         
	setbits(value, 0x02);                                                                                         
	lm3559_write(ENABLE_REG_INDEX,value);                                                                         
                                                                                                                     
	return	0;                                                                                                    
}                                                                                                                    
Esempio n. 4
0
/* Put device into known state. */
static int lm3559_setup(struct lm3559 *flash)
{
	struct i2c_client *client = v4l2_get_subdevdata(&flash->sd);
	unsigned int flash_current_limit = flash->pdata->flash_current_limit;
	int ret;

	/* clear the flags register */
	ret = lm3559_read(flash, LM3559_FLAGS_REG);
	if (ret < 0)
		return ret;

	dev_dbg(&client->dev, "Fault info: %02x\n", ret);

	ret = lm3559_set_config(flash);
	if (ret < 0)
		return ret;

	flash->timeout = LM3559_DEFAULT_TIMEOUT_SETTING;
	ret = lm3559_set_duration(flash);
	if (ret < 0)
		return ret;

	flash->torch_current = LM3559_TORCH_DEFAULT;
	ret = lm3559_set_torch(flash);
	if (ret < 0)
		return ret;

	if (flash_current_limit == 0)
		flash_current_limit = LM3559_FLASH_MAX_CURRENT;
	flash->flash_current = LM3559_FLASH_DEFAULT_BRIGHTNESS *
				flash_current_limit / LM3559_MAX_PERCENT;
	ret = lm3559_set_flash(flash);
	if (ret < 0)
		return ret;

	/* read status */
	ret = lm3559_read_status(flash);
	if (ret < 0)
		return ret;

	return ret ? -EIO : 0;
}
Esempio n. 5
0
static int lm3559_read_status(struct lm3559 *flash)
{
	int ret;
	struct i2c_client *client = v4l2_get_subdevdata(&flash->sd);

	/* NOTE: reading register clear fault status */
	ret = lm3559_read(flash, LM3559_FLAGS_REG);
	if (ret < 0)
		return ret;

	/*
	 * Do not take TX1/TX2 signal as an error
	 * because MSIC will not turn off flash, but turn to
	 * torch mode according to gsm modem signal by hardware.
	 */
	ret &= ~(LM3559_FLAG_TX1_INTERRUPT | LM3559_FLAG_TX2_INTERRUPT);

	if (ret > 0)
		dev_dbg(&client->dev, "LM3559 flag status: %02x\n", ret);

	return ret;
}