Esempio n. 1
0
static int lis331dlh_init(void *mlsl_handle,
			  struct ext_slave_descr *slave,
			  struct ext_slave_platform_data *pdata)
{
	struct lis331dlh_private_data *private_data;
	private_data = (struct lis331dlh_private_data *)
		MLOSMalloc(sizeof(struct lis331dlh_private_data));

	if (!private_data)
		return ML_ERROR_MEMORY_EXAUSTED;

	pdata->private_data = private_data;

	private_data->resume.ctrl_reg1 = 0x37;
	private_data->suspend.ctrl_reg1 = 0x47;

	lis331dlh_set_odr(&private_data->suspend, 50000);
	lis331dlh_set_odr(&private_data->resume, 200000);
	lis331dlh_set_fsr(&private_data->suspend, 2048);
	lis331dlh_set_fsr(&private_data->resume, 2048);
	lis331dlh_set_ths(&private_data->suspend, 80);
	lis331dlh_set_ths(&private_data->resume, 40);
	lis331dlh_set_dur(&private_data->suspend, 1000);
	lis331dlh_set_dur(&private_data->resume,  2540);
	return ML_SUCCESS;
}
Esempio n. 2
0
static int lis331dlh_config(void *mlsl_handle,
			    struct ext_slave_descr *slave,
			    struct ext_slave_platform_data *pdata,
			    struct ext_slave_config *data)
{
	struct lis331dlh_private_data *private_data = pdata->private_data;
	if (!data->data)
		return INV_ERROR_INVALID_PARAMETER;

	switch (data->key) {
	case MPU_SLAVE_CONFIG_ODR_SUSPEND:
		return lis331dlh_set_odr(mlsl_handle, pdata,
					 &private_data->suspend,
					 data->apply, *((long *)data->data));
	case MPU_SLAVE_CONFIG_ODR_RESUME:
		return lis331dlh_set_odr(mlsl_handle, pdata,
					 &private_data->resume,
					 data->apply, *((long *)data->data));
	case MPU_SLAVE_CONFIG_FSR_SUSPEND:
		return lis331dlh_set_fsr(mlsl_handle, pdata,
					 &private_data->suspend,
					 data->apply, *((long *)data->data));
	case MPU_SLAVE_CONFIG_FSR_RESUME:
		return lis331dlh_set_fsr(mlsl_handle, pdata,
					 &private_data->resume,
					 data->apply, *((long *)data->data));
	case MPU_SLAVE_CONFIG_MOT_THS:
		return lis331dlh_set_ths(mlsl_handle, pdata,
					 &private_data->suspend,
					 data->apply, *((long *)data->data));
	case MPU_SLAVE_CONFIG_NMOT_THS:
		return lis331dlh_set_ths(mlsl_handle, pdata,
					 &private_data->resume,
					 data->apply, *((long *)data->data));
	case MPU_SLAVE_CONFIG_MOT_DUR:
		return lis331dlh_set_dur(mlsl_handle, pdata,
					 &private_data->suspend,
					 data->apply, *((long *)data->data));
	case MPU_SLAVE_CONFIG_NMOT_DUR:
		return lis331dlh_set_dur(mlsl_handle, pdata,
					 &private_data->resume,
					 data->apply, *((long *)data->data));
	case MPU_SLAVE_CONFIG_IRQ_SUSPEND:
		return lis331dlh_set_irq(mlsl_handle, pdata,
					 &private_data->suspend,
					 data->apply, *((long *)data->data));
	case MPU_SLAVE_CONFIG_IRQ_RESUME:
		return lis331dlh_set_irq(mlsl_handle, pdata,
					 &private_data->resume,
					 data->apply, *((long *)data->data));
	default:
		LOG_RESULT_LOCATION(INV_ERROR_FEATURE_NOT_IMPLEMENTED);
		return INV_ERROR_FEATURE_NOT_IMPLEMENTED;
	};

	return INV_SUCCESS;
}
Esempio n. 3
0
static int lis331dlh_config(void *mlsl_handle,
			struct ext_slave_descr *slave,
			struct ext_slave_platform_data *pdata,
			struct ext_slave_config *data)
{
	struct lis331dlh_private_data *private_data = pdata->private_data;
	if (!data->data)
		return ML_ERROR_INVALID_PARAMETER;

	switch (data->key) {
	case MPU_SLAVE_CONFIG_ODR_SUSPEND:
		lis331dlh_set_odr(&private_data->suspend,
				*((long *)data->data));
		break;
	case MPU_SLAVE_CONFIG_ODR_RESUME:
		lis331dlh_set_odr(&private_data->resume,
				*((long *)data->data));
		break;
	case MPU_SLAVE_CONFIG_FSR_SUSPEND:
		lis331dlh_set_fsr(&private_data->suspend,
				*((long *)data->data));
		break;
	case MPU_SLAVE_CONFIG_FSR_RESUME:
		lis331dlh_set_fsr(&private_data->resume,
				*((long *)data->data));
		break;
	case MPU_SLAVE_CONFIG_MOT_THS:
		lis331dlh_set_ths(&private_data->suspend,
				*((long *)data->data));
		break;
	case MPU_SLAVE_CONFIG_NMOT_THS:
		lis331dlh_set_ths(&private_data->resume,
				*((long *)data->data));
		break;
	case MPU_SLAVE_CONFIG_MOT_DUR:
		lis331dlh_set_dur(&private_data->suspend,
				*((long *)data->data));
		break;
	case MPU_SLAVE_CONFIG_NMOT_DUR:
		lis331dlh_set_dur(&private_data->resume,
				*((long *)data->data));
		break;
	default:
		return ML_ERROR_FEATURE_NOT_IMPLEMENTED;
	};

	return ML_SUCCESS;
}
Esempio n. 4
0
static int lis331dlh_init(void *mlsl_handle,
			  struct ext_slave_descr *slave,
			  struct ext_slave_platform_data *pdata)
{
	struct lis331dlh_private_data *private_data;
	long range;
	private_data = (struct lis331dlh_private_data *)
	    kzalloc(sizeof(struct lis331dlh_private_data), GFP_KERNEL);

	if (!private_data)
		return INV_ERROR_MEMORY_EXAUSTED;

	pdata->private_data = private_data;

	private_data->resume.ctrl_reg1 = 0x37;
	private_data->suspend.ctrl_reg1 = 0x47;
	private_data->resume.mot_int1_cfg = 0x95;
	private_data->suspend.mot_int1_cfg = 0x2a;

	lis331dlh_set_odr(mlsl_handle, pdata, &private_data->suspend, false, 0);
	lis331dlh_set_odr(mlsl_handle, pdata, &private_data->resume,
			  false, 200000);

	range = range_fixedpoint_to_long_mg(slave->range);
	lis331dlh_set_fsr(mlsl_handle, pdata, &private_data->suspend,
			false, range);
	lis331dlh_set_fsr(mlsl_handle, pdata, &private_data->resume,
			false, range);

	lis331dlh_set_ths(mlsl_handle, pdata, &private_data->suspend,
			  false, 80);
	lis331dlh_set_ths(mlsl_handle, pdata, &private_data->resume, false, 40);


	lis331dlh_set_dur(mlsl_handle, pdata, &private_data->suspend,
			  false, 1000);
	lis331dlh_set_dur(mlsl_handle, pdata, &private_data->resume,
			  false, 2540);

	lis331dlh_set_irq(mlsl_handle, pdata, &private_data->suspend,
			  false, MPU_SLAVE_IRQ_TYPE_NONE);
	lis331dlh_set_irq(mlsl_handle, pdata, &private_data->resume,
			  false, MPU_SLAVE_IRQ_TYPE_NONE);
	return INV_SUCCESS;
}
Esempio n. 5
0
static int lis331dlh_init(void *mlsl_handle,
			  struct ext_slave_descr *slave,
			  struct ext_slave_platform_data *pdata)
{
	struct lis331dlh_private_data *private_data;
	private_data = (struct lis331dlh_private_data *)
		MLOSMalloc(sizeof(struct lis331dlh_private_data));

	if (!private_data)
		return ML_ERROR_MEMORY_EXAUSTED;

	pdata->private_data = private_data;

	private_data->resume.ctrl_reg1 = 0x37;
	private_data->suspend.ctrl_reg1 = 0x47;
	private_data->resume.mot_int1_cfg = 0x95;
	private_data->suspend.mot_int1_cfg = 0x2a;

	lis331dlh_set_odr(mlsl_handle, pdata, &private_data->suspend,
			FALSE, 0);
	lis331dlh_set_odr(mlsl_handle, pdata, &private_data->resume,
			FALSE, 200000);
	lis331dlh_set_fsr(mlsl_handle, pdata, &private_data->suspend,
			FALSE, 2048);
	lis331dlh_set_fsr(mlsl_handle, pdata, &private_data->resume,
			FALSE, 2048);
	lis331dlh_set_ths(mlsl_handle, pdata, &private_data->suspend,
			FALSE, 80);
	lis331dlh_set_ths(mlsl_handle, pdata, &private_data->resume,
			FALSE, 40);
	lis331dlh_set_dur(mlsl_handle, pdata, &private_data->suspend,
			FALSE, 1000);
	lis331dlh_set_dur(mlsl_handle, pdata, &private_data->resume,
			FALSE,  2540);
	lis331dlh_set_irq(mlsl_handle, pdata, &private_data->suspend,
			FALSE,
			MPU_SLAVE_IRQ_TYPE_NONE);
	lis331dlh_set_irq(mlsl_handle, pdata, &private_data->resume,
			FALSE,
			MPU_SLAVE_IRQ_TYPE_NONE);
	return ML_SUCCESS;
}
Esempio n. 6
0
/**
 * Set the Output data rate for the particular configuration
 *
 * @param config Config to modify with new ODR
 * @param odr Output data rate in units of 1/1000Hz
 */
static int lis331dlh_set_odr(void *mlsl_handle,
			struct ext_slave_platform_data *pdata,
			struct lis331dlh_config *config,
			int apply,
			long odr)
{
	unsigned char bits;
	int result = ML_SUCCESS;

	if (odr > 400000) {
		config->odr = 1000000;
		bits = 0x38;
	} else if (odr > 100000) {
		config->odr = 400000;
		bits = 0x30;
	} else if (odr > 50000) {
		config->odr = 100000;
		bits = 0x28;
	} else if (odr > 10000) {
		config->odr = 50000;
		bits = 0x20;
	} else if (odr > 5000) {
		config->odr = 10000;
		bits = 0xC0;
	} else if (odr > 2000) {
		config->odr = 5000;
		bits = 0xB0;
	} else if (odr > 1000) {
		config->odr = 2000;
		bits = 0x80;
	} else if (odr > 500) {
		config->odr = 1000;
		bits = 0x60;
	} else if (odr > 0) {
		config->odr = 500;
		bits = 0x40;
	} else {
		config->odr = 0;
		bits = 0;
	}

	config->ctrl_reg1 = bits | (config->ctrl_reg1 & 0x7);
	lis331dlh_set_dur(mlsl_handle, pdata,
			config, apply, config->dur);
	MPL_LOGV("ODR: %d, 0x%02x\n", config->odr, (int)config->ctrl_reg1);
	if (apply)
		result = MLSLSerialWriteSingle(mlsl_handle, pdata->address,
					LIS331_CTRL_REG1,
					config->ctrl_reg1);
	return result;
}
Esempio n. 7
0
/**
 * Set the Output data rate for the particular configuration
 *
 * @param config Config to modify with new ODR
 * @param odr Output data rate in units of 1/1000Hz
 */
static int lis331dlh_set_odr(void *mlsl_handle,
			     struct ext_slave_platform_data *pdata,
			     struct lis331dlh_config *config,
			     int apply, long odr)
{
	unsigned char bits;
	int result = INV_SUCCESS;

	/* normal power modes */
	if (odr > 400000) {
		config->odr = 1000000;
		bits = LIS331DLH_PWR_MODE_NORMAL | 0x18;
	} else if (odr > 100000) {
		config->odr = 400000;
		bits = LIS331DLH_PWR_MODE_NORMAL | 0x10;
	} else if (odr > 50000) {
		config->odr = 100000;
		bits = LIS331DLH_PWR_MODE_NORMAL | 0x08;
	} else if (odr > 10000) {
		config->odr = 50000;
		bits = LIS331DLH_PWR_MODE_NORMAL | 0x00;
	/* low power modes */
	} else if (odr > 5000) {
		config->odr = 10000;
		bits = 0xC0;
	} else if (odr > 2000) {
		config->odr = 5000;
		bits = 0xA0;
	} else if (odr > 1000) {
		config->odr = 2000;
		bits = 0x80;
	} else if (odr > 500) {
		config->odr = 1000;
		bits = 0x60;
	} else if (odr > 0) {
		config->odr = 500;
		bits = 0x40;
	} else {
		config->odr = 0;
		bits = 0;
	}

	config->ctrl_reg1 = bits | (config->ctrl_reg1 & 0x7);
	lis331dlh_set_dur(mlsl_handle, pdata, config, apply, config->dur);
	MPL_LOGV("ODR: %d, 0x%02x\n", config->odr, (int)config->ctrl_reg1);
	if (apply)
		result = inv_serial_single_write(mlsl_handle, pdata->address,
						 LIS331DLH_CTRL_REG1,
						 config->ctrl_reg1);
	return result;
}
Esempio n. 8
0
/**
 * Set the Output data rate for the particular configuration
 *
 * @param config Config to modify with new ODR
 * @param odr Output data rate in units of 1/1000Hz
 */
static void lis331dlh_set_odr(
	struct lis331dlh_config *config,
	long odr)
{
	unsigned char bits;

	if (odr > 400000) {
		config->odr = 1000000;
		bits = 0x38;
	} else if (odr > 100000) {
		config->odr = 400000;
		bits = 0x30;
	} else if (odr > 50000) {
		config->odr = 100000;
		bits = 0x28;
	} else if (odr > 10000) {
		config->odr = 50000;
		bits = 0x20;
	} else if (odr > 5000) {
		config->odr = 10000;
		bits = 0xC0;
	} else if (odr > 2000) {
		config->odr = 5000;
		bits = 0xB0;
	} else if (odr > 1000) {
		config->odr = 2000;
		bits = 0x80;
	} else if (odr > 500) {
		config->odr = 1000;
		bits = 0x60;
	} else if (odr > 0) {
		config->odr = 500;
		bits = 0x40;
	} else {
		config->odr = 0;
		bits = 0;
	}

	config->ctrl_reg1 = bits | (config->ctrl_reg1 & 0x7);
	lis331dlh_set_dur(config, config->dur);
	MPL_LOGD("ODR: %d, 0x%02x\n", config->odr, (int)config->ctrl_reg1);
}