static void mpu_accel_data_work_fcn(struct work_struct *work)
{
	struct mpuirq_dev_data *mpuirq_dev_data =
		(struct mpuirq_dev_data *) work;
	struct mldl_cfg *mldl_cfg =
		(struct mldl_cfg *)
		i2c_get_clientdata(mpuirq_dev_data->mpu_client);
	struct i2c_adapter *accel_adapter;
	unsigned char wbuff[16];
	unsigned char rbuff[16];
	int ii;

	accel_adapter = i2c_get_adapter(mldl_cfg->pdata->accel.adapt_num);
	mldl_cfg->accel->read(accel_adapter,
				mldl_cfg->accel,
				&mldl_cfg->pdata->accel, rbuff);


	/* @todo add other data formats here as well */
	if (EXT_SLAVE_BIG_ENDIAN == mldl_cfg->accel->endian) {
		for (ii = 0; ii < 3; ii++) {
			wbuff[2 * ii + 1] = rbuff[2 * ii + 1];
			wbuff[2 * ii + 2] = rbuff[2 * ii + 0];
		}
	} else {
		memcpy(wbuff + 1, rbuff, mldl_cfg->accel->len);
	}

	wbuff[7] = 0;
	wbuff[8] = 1;		/*set semaphore */

	mpu_memory_write(mpuirq_dev_data->mpu_client->adapter,
			 mldl_cfg->addr, 0x0108, 8, wbuff);
}
Esempio n. 2
0
int inv_serial_write_mem(
	void *sl_handle,
	unsigned char slave_addr,
	unsigned short mem_addr,
	unsigned short length,
	unsigned char const *data)
{
	int result;
	unsigned short bytes_written = 0;

	if ((mem_addr & 0xFF) + length > MPU_MEM_BANK_SIZE) {
		pr_err("memory read length (%d B) extends beyond its"
		       " limits (%d) if started at location %d\n", length,
		       MPU_MEM_BANK_SIZE, mem_addr & 0xFF);
		return INV_ERROR_INVALID_PARAMETER;
	}
	while (bytes_written < length) {
		unsigned short this_len =
		    min(SERIAL_MAX_TRANSFER_SIZE, length - bytes_written);
		result = mpu_memory_write((struct i2c_adapter *)sl_handle,
					  slave_addr, mem_addr + bytes_written,
					  this_len, &data[bytes_written]);
		if (result) {
			LOG_RESULT_LOCATION(result);
			return result;
		}
		bytes_written += this_len;
	}
	return 0;
}
/**
 *  @brief  used to write multiple bytes of data to the memory.
 *          This should be sent by I2C.
 *
 *  @param  slaveAddr       I2C slave address of device.
 *  @param  memAddr         The location in the memory to write to.
 *  @param  length          Length of burst data.
 *  @param  data            Pointer to block of data.
 *
 *  @return Zero if successful; an error code otherwise
 */
tMLError MLSLSerialWriteMem(void *sl_handle,
			    unsigned char slaveAddr,
			    unsigned short memAddr,
			    unsigned short length,
			    unsigned char const *data)
{
	tMLError result;
	unsigned short bytesWritten = 0;

	if ((memAddr & 0xFF) + length > MPU_MEM_BANK_SIZE) {
		printk
		    ("memory read length (%d B) extends beyond its limits (%d) "
		     "if started at location %d\n", length,
		     MPU_MEM_BANK_SIZE, memAddr & 0xFF);
		return ML_ERROR_INVALID_PARAMETER;
	}
	while (bytesWritten < length) {
		unsigned short thisLen =
		    min(SERIAL_MAX_TRANSFER_SIZE, length - bytesWritten);
		result =
		    mpu_memory_write((struct i2c_adapter *) sl_handle,
				     slaveAddr, memAddr + bytesWritten,
				     thisLen, &data[bytesWritten]);
		if (ML_SUCCESS != result)
			return result;
		bytesWritten += thisLen;
	}
	return ML_SUCCESS;
}