示例#1
0
/*----------------------------------------------------------------------------*/
static void st480_power(struct mag_hw *hw, unsigned int on) 
{
	static unsigned int power_on = 0;

	if(hw->power_id != POWER_NONE_MACRO)
	{        
		MSE_LOG("power %s\n", on ? "on" : "off");
		if(power_on == on)
		{
			MSE_LOG("ignore power control: %d\n", on);
		}
		else if(on)
		{
			if(!hwPowerOn(hw->power_id, hw->power_vol, "st480")) 
			{
				MSE_ERR("power on fails!!\n");
			}
		}
		else
		{
			if(!hwPowerDown(hw->power_id, "st480")) 
			{
				MSE_ERR("power off fail!!\n");
			}
		}
	}
	power_on = on;
}
static int yas_device_read(int32_t type, uint8_t addr, uint8_t *buf, int len)
{

	struct mt_i2c_msg msg[2];
	int err = 0;
	struct yas_state *st= i2c_get_clientdata(this_client);

	//memset(msg, 0, sizeof(msg));
	msg[0].addr = this_client->addr;
	msg[0].flags = 0;
	msg[0].len = 1;
	msg[0].buf = &addr;
	msg[0].timing = this_client->timing;	//add for mtk i2c
	msg[0].ext_flag = this_client->ext_flag & I2C_MASK_FLAG;//add for mtk i2c
	msg[1].addr = this_client->addr;
	msg[1].flags = I2C_M_RD;
	msg[1].len = len;
	msg[1].buf = buf;
	msg[1].timing = this_client->timing;	//add for mtk i2c
	msg[1].ext_flag = this_client->ext_flag & I2C_MASK_FLAG;//add for mtk i2c

	if((len > 8 ) && (st->dma_va != NULL))
	{
		msg[1].ext_flag = this_client->ext_flag | I2C_DMA_FLAG;//add for mtk i2c
	}
	mutex_lock(&yas537_i2c_mutex);
//#if 0
	if(len <= 8)
	{
		err = i2c_transfer(this_client->adapter, (struct i2c_msg *)msg, 2);
		if (err != 2) {
			dev_err(&this_client->dev,
					"i2c_transfer() read error: "
					"adapter num = %d,slave_addr=%02x, reg_addr=%02x, err=%d\n",
					this_client->adapter->nr, this_client->addr, addr, err);
			mutex_unlock(&yas537_i2c_mutex);
			return err;
		}
	}

//#else
	else
	{
	#if 0
		if(unlikely(NULL == st->dma_va))
		{
			this_client->ext_flag &= I2C_MASK_FLAG; //CLEAR DMA FLAG	
			memset(buf, 0,len);
			buf = &addr;
			err = i2c_master_send(this_client, buf,1);
			if(err < 0)
			{
				MSE_ERR("%s  i2c_master_send failed err = %d\n", __FUNCTION__, err);
				mutex_unlock(&yas537_i2c_mutex);
				return err;
			}
			
			for(i=0; i<=len; i=i+8)
			{
				trans_len = ((i+8)<=len) ? 8 : (len-i);
				MSE_LOG("%s   trans_len = %d\n", __FUNCTION__,trans_len);

				err = i2c_master_recv(this_client, &buf[i], trans_len);

				if(err < 0)
				{
					MSE_ERR("%s  i2c_master_recv failed err = %d\n", __FUNCTION__, err);
					mutex_unlock(&yas537_i2c_mutex);
					return err;
				}
			}
		}
		else
	#endif
		{
			memset(st->dma_va, 0, 1024);
			msg[1].buf = (char *)(st->dma_pa);
			err = i2c_transfer(this_client->adapter, (struct i2c_msg *)msg, 2);
			if (err != 2) {
				dev_err(&this_client->dev,
						"i2c_transfer() read error: "
						"adapter num = %d,slave_addr=%02x, reg_addr=%02x, err=%d\n",
						this_client->adapter->nr, this_client->addr, addr, err);

				mutex_unlock(&yas537_i2c_mutex);
				return err;
			}
			memcpy(buf, st->dma_va, len);
		}
	}
//#endif
//	MSE_LOG("%s   successful\n", __FUNCTION__);

	mutex_unlock(&yas537_i2c_mutex);
	return 0;
}