Пример #1
0
static void bma250_set_enable(struct device *dev, int enable)
{
	struct i2c_client *client = to_i2c_client(dev);
	struct bma250_data *bma250 = i2c_get_clientdata(client);
	int pre_enable = atomic_read(&bma250->enable);

	mutex_lock(&bma250->enable_mutex);
	if (enable) {
		if (pre_enable == 0) {
			bma250_set_mode(bma250->bma250_client,
					BMA250_MODE_NORMAL);
			schedule_delayed_work(&bma250->work,
					      msecs_to_jiffies(atomic_read
							       (&bma250->
								delay)));
			atomic_set(&bma250->enable, 1);
		}

	} else {
		if (pre_enable == 1) {
			bma250_set_mode(bma250->bma250_client,
					BMA250_MODE_SUSPEND);
			cancel_delayed_work_sync(&bma250->work);
			atomic_set(&bma250->enable, 0);
		}
	}
	mutex_unlock(&bma250->enable_mutex);

}
Пример #2
0
static void bma250_late_resume(struct early_suspend *h)
{
#ifdef BMA250_DEBUG
    printk(KERN_INFO "%s\n",__FUNCTION__);
#endif		
    bma250_set_mode(bma250_MODE_NORMAL);
}
Пример #3
0
static void bma250_early_suspend(struct early_suspend *h)
{
#ifdef BMA250_DEBUG
    printk(KERN_INFO "%s\n",__FUNCTION__);
#endif	
    bma250_set_mode(bma250_MODE_SUSPEND);
}
Пример #4
0
static int bma250_resume(struct i2c_client *client)
{
#ifdef BMA250_DEBUG
    printk(KERN_INFO "%s\n",__FUNCTION__);
#endif	
    bma250_set_mode(bma250_MODE_NORMAL);
    return 0;	
}
Пример #5
0
static int bma250_suspend(struct i2c_client *client,pm_message_t mesg)
{
#ifdef BMA250_DEBUG
    printk(KERN_INFO "%s\n",__FUNCTION__);
#endif	
    bma250_set_mode(bma250_MODE_SUSPEND);
    return 0;	
}
Пример #6
0
void bma250_calibration(struct bmasensor_data *sensor_data)
{
	struct i2c_client *client = sensor_data->i2cClient;
	printk(KERN_INFO" bma250_calibration start \n");

	tcc_sensor_set_enable_by_client_for_calibration(sensor_data,0);
	
	bma250_set_mode(client,BMA250_MODE_NORMAL);
	//bma250_print_calib(client);
	bma250_set_fast_calibration_x(client,0);
	bma250_set_fast_calibration_y(client,0);
	bma250_set_fast_calibration_z(client,2);
	//bma250_print_calib(client);
	bma250_set_mode(client,BMA250_MODE_LOWPOWER);

	tcc_sensor_set_enable_by_client_for_calibration(sensor_data,1);

	printk(KERN_INFO" bma250_calibration end\n");
}
Пример #7
0
static void bma250_early_suspend(struct early_suspend *h)
{
	struct bma250_data *data =
	    container_of(h, struct bma250_data, early_suspend);

	mutex_lock(&data->enable_mutex);
	if (atomic_read(&data->enable) == 1) {
		bma250_set_mode(data->bma250_client, BMA250_MODE_SUSPEND);
		cancel_delayed_work_sync(&data->work);
	}
	mutex_unlock(&data->enable_mutex);
}
Пример #8
0
static ssize_t bma250_enable_interrupt(struct device *dev,
		struct device_attribute *attr,
		const char *buf, size_t count)
{
	unsigned long enable;
	int error;

	error = strict_strtoul(buf, 10, &enable);
		if (error)
		    return error;
	printk(KERN_INFO "[BMA250] bma250_enable_interrupt, power_key_pressed = %d\n", power_key_pressed);
	if(enable == 1 && !power_key_pressed){ 
		

	    
	    if(gsensor_power_LPM){
		I("Non Low Power Mode\n");
		gsensor_power_LPM(0);

	    }
	    
	    error = bma250_set_Int_Mode(g_mlsl_handle, g_pdata, 1);

	    error += bma250_set_slope_duration(g_mlsl_handle, g_pdata, 0x01);
	    error += bma250_set_slope_threshold(g_mlsl_handle, g_pdata, 0x07);
	    
	    error += bma250_set_Int_Enable(g_mlsl_handle, g_pdata,5, 1);
	    error += bma250_set_Int_Enable(g_mlsl_handle, g_pdata,6, 1);
	    error += bma250_set_Int_Enable(g_mlsl_handle, g_pdata,7, 0);
	    error += bma250_set_int1_pad_sel(g_mlsl_handle, g_pdata, PAD_SLOP);
	    error += bma250_set_mode(g_mlsl_handle, g_pdata, BMA250_MODE_NORMAL);

	    cir_flag = 1;
	    if (error)
		return error;
	    printk(KERN_INFO "[BMA250] enable = 1 \n");
		
	} else if(enable == 0){

	    error += bma250_set_Int_Enable(g_mlsl_handle, g_pdata,5, 0);
	    error += bma250_set_Int_Enable(g_mlsl_handle, g_pdata,6, 0);
	    error += bma250_set_Int_Enable(g_mlsl_handle, g_pdata,7, 0);
	
	    power_key_pressed = 0;
	    cir_flag = 0;
	    if (error)
		return error;
	    printk(KERN_INFO "[BMA250] enable = 0 , power_key_pressed = %d\n", power_key_pressed);

	}
	return count;
}
Пример #9
0
static void bma250_late_resume(struct early_suspend *h)
{
	struct bma250_data *data =
		container_of(h, struct bma250_data, early_suspend);

	mutex_lock(&data->enable_mutex);
	if (atomic_read(&data->enable) == 1) {
		bma250_set_mode(data->bma250_client, BMA250_MODE_NORMAL);
		schedule_delayed_work(&data->work,
				msecs_to_jiffies(atomic_read(&data->delay)));
	}
	mutex_unlock(&data->enable_mutex);
}
Пример #10
0
static ssize_t bma250_mode_store(struct device *dev,
				 struct device_attribute *attr,
				 const char *buf, size_t count)
{
	unsigned long data;
	int error;
	struct i2c_client *client = to_i2c_client(dev);
	struct bma250_data *bma250 = i2c_get_clientdata(client);

	error = strict_strtoul(buf, 10, &data);
	if (error)
		return error;
	if (bma250_set_mode(bma250->bma250_client, (unsigned char)data) < 0)
		return -EINVAL;

	return count;
}
Пример #11
0
/*	ioctl command for BMA250 device file	*/
static long bma250_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
    void __user *pa = (void __user *)arg;
	int err = 0;
    bma250acc_t acc;
	int vec[3] = {0};

#ifdef BMA250_DEBUG
	//printk(KERN_INFO "%s,cmd = %d , BMA250_IOC_READXYZ = %d\n",__FUNCTION__,cmd,BMA250_IOC_READXYZ);	
#endif

	/* cmd mapping */

	switch(cmd)
	{
    case BMA250_IOC_READXYZ:
		bma250_read_accel_xyz(&acc);

	
		vec[0] = acc.x;		
		vec[1] = acc.y;		
		vec[2] = acc.z;		
//		printk("[X - %d] [Y - %d] [Z - %d]\n", 
//			vec[0], vec[1], vec[2]);			
//		printk("[acc.x - %d] [acc.y - %d] [acc.z - %d]\n", 
//			acc.x, acc.y, acc.z);					
        if (copy_to_user(pa, vec, sizeof(vec))) {
#ifdef BMA250_DEBUG
			printk(KERN_INFO "copy_to error\n");
#endif
			return -EFAULT;
		}
		break;
    case BMA250_IOC_READSTATUS:
		bma250_read_accel_xyz(&acc);
		
		vec[0] = acc.x;		
		vec[1] = acc.y;		
		vec[2] = acc.z;		

        if (copy_to_user(pa, vec, sizeof(vec))) {
#ifdef BMA250_DEBUG
			printk(KERN_INFO "copy_to error\n");
#endif
			return -EFAULT;
		}
		break;
    case BMA250_IOC_PWRDN:

		bma250_set_mode(bma250_MODE_SUSPEND);
        break;

    case BMA250_IOC_PWRON:
        
        bma250_set_mode(bma250_MODE_NORMAL);
		break;

	default:
		return 0;
	}
		return 0;	
}
Пример #12
0
static int bma250_probe(struct i2c_client *client,
			const struct i2c_device_id *id)
{
	int err = 0;
	int tempvalue;
	struct bma250_data *data;

	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
		printk(KERN_INFO "i2c_check_functionality error\n");
		goto exit;
	}
	data = kzalloc(sizeof(struct bma250_data), GFP_KERNEL);
	if (!data) {
		err = -ENOMEM;
		goto exit;
	}
	/* read chip id */
	tempvalue = 0;
	tempvalue = i2c_smbus_read_word_data(client, BMA250_CHIP_ID_REG) & 0x00FF;
	/* SKUD board is using BMA250E chip! */
	if (tempvalue == BMA250E_CHIP_ID1 || tempvalue == BMA250E_CHIP_ID2) {
		printk(KERN_INFO "Bosch Sensortec Device detected!\n"
		       "BMA250 registered I2C driver!\n");
	} else {
		printk(KERN_INFO "Bosch Sensortec Device not found, \
				i2c error %d \n", tempvalue);
		err = -1;
		goto kfree_exit;
	}
	i2c_set_clientdata(client, data);
	data->bma250_client = client;
	mutex_init(&data->value_mutex);
	mutex_init(&data->mode_mutex);
	mutex_init(&data->enable_mutex);
	bma250_set_bandwidth(client, BMA250_BW_SET);
	bma250_set_range(client, BMA250_RANGE_SET);

	INIT_DELAYED_WORK(&data->work, bma250_work_func);
	atomic_set(&data->delay, BMA250_MAX_DELAY);
	atomic_set(&data->enable, 0);
	err = bma250_input_init(data);
	if (err < 0)
		goto kfree_exit;

	err = sysfs_create_group(&data->input->dev.kobj,
				 &bma250_attribute_group);
	if (err < 0)
		goto error_sysfs;

	data->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
	data->early_suspend.suspend = bma250_early_suspend;
	data->early_suspend.resume = bma250_late_resume;
	register_early_suspend(&data->early_suspend);
	/* try to reduce the power comsuption */
	bma250_set_mode(data->bma250_client, BMA250_MODE_SUSPEND);

	return 0;

error_sysfs:
	bma250_input_delete(data);

kfree_exit:
	kfree(data);
exit:
	return err;
}
Пример #13
0
static int bma250_probe(struct i2c_client *client,
		const struct i2c_device_id *id)
{
	int err = 0;
	int tempvalue;
	struct bma250_data *data;

	printk(KERN_INFO "%s: entry \r\n", __func__);
	if (bma250_set_power(true)) {
		printk(KERN_ERR "%s: bma250_set_power(true) fail \r\n", __func__);
		return -1;
	}
	msleep(10);

	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
		printk(KERN_INFO "i2c_check_functionality error\n");
		goto exit;
	}
	data = kzalloc(sizeof(struct bma250_data), GFP_KERNEL);
	if (!data) {
		err = -ENOMEM;
		goto exit;
	}
	/* read chip id */
	tempvalue = 0;
	tempvalue = i2c_smbus_read_word_data(client, BMA250_CHIP_ID_REG);

	if ((tempvalue&0x00FF) == BMA250_CHIP_ID) {
		printk(KERN_INFO "Bosch Sensortec Device detected!\n" \
				"BMA250 registered I2C driver!\n");
	} else{
		printk(KERN_INFO "Bosch Sensortec Device not found, \
				i2c error %d \n", tempvalue);
		err = -1;
		goto kfree_exit;
	}
	i2c_set_clientdata(client, data);
	data->bma250_client = client;
	mutex_init(&data->mode_mutex);
	mutex_init(&data->enable_mutex);
	bma250_set_bandwidth(client, BMA250_BW_SET);
	bma250_set_range(client, BMA250_RANGE_SET);

	INIT_DELAYED_WORK(&data->work, bma250_work_func);
	atomic_set(&data->delay, BMA250_DEFAULT_DELAY);
	atomic_set(&data->enable, 0);
	err = bma250_input_init(data);
	if (err < 0)
		goto kfree_exit;

	err = sysfs_create_group(&data->input->dev.kobj,
			&bma250_attribute_group);
	if (err < 0)
		goto error_sysfs;

#ifdef CONFIG_HAS_EARLYSUSPEND
	data->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
	data->early_suspend.suspend = bma250_early_suspend;
	data->early_suspend.resume = bma250_late_resume;
	register_early_suspend(&data->early_suspend);
#endif
	err = bma250_set_mode(client, BMA250_MODE_SUSPEND);
	if (err)
		goto error_sysfs;

	printk(KERN_INFO "%s: success \r\n", __func__);
	return 0;

error_sysfs:
	bma250_input_delete(data);

kfree_exit:
	kfree(data);
exit:
#if BMA250_PWROFF_EN
	if (bma250_set_power(false)) {
		printk(KERN_ERR "%s: bma250_set_power(false) fail \r\n", __func__);
	}
#endif
	return err;
}