示例#1
0
/*
 *----------------------------------------------------------------------------
 * Function : tiload_write
 *
 * Purpose  : write method for aic3262_tiload programming interface
 *----------------------------------------------------------------------------
 */
static ssize_t tiload_write(struct file *file, const char __user * buf,
			    size_t count, loff_t * offset)
{
	static char wr_data[8];
	u8 pg_no;
	unsigned int reg;
	#ifdef DEBUG
	int i;
	#endif
	struct aic3262 *control = aic3262_codec->control_data;

	dprintk("TiLoad DRIVER : %s\n", __FUNCTION__);
	/* copy buffer from user space  */
	if (copy_from_user(wr_data, buf, count)) {
		printk("copy_from_user failure\n");
		return -1;
	}
#ifdef DEBUG
	dprintk(KERN_ERR "write size = %d\n", (int)count);
	for (i = 0; i < (int)count; i++) {
		printk(KERN_INFO "\nwr_data[%d]=%x\n", i, wr_data[i]);
	}
#endif
	if(wr_data[0] == 0)
	{
		//change of page seen, but will only be registered		
		aic_reg.aic326x_register.page = wr_data[1];
		return count;// trick
		
	}	
	else
	if(wr_data[0] == 127 /* && aic_reg.aic326x_register.page == 0*/) 
	{	
		//change of book seen, but will not be sent for I2C write
		aic_reg.aic326x_register.book = wr_data[1];
		return count; //trick
		 
	}
	else
	{ 
		aic_reg.aic326x_register.offset = wr_data[0];	
		aic3262_bulk_write(control, aic_reg.aic326x_register_int, count - 1,&wr_data[1]); 
		return count;
	}
/*	if (wr_data[0] == 0) {
		aic3262_change_page(aic3262_codec, wr_data[1]);
		return count;
	}
	pg_no = aic3262_private->page_no;

	if ((wr_data[0] == 127) && (pg_no == 0)) {
		aic3262_change_book(aic3262_codec, wr_data[1]);
		return count;
	}
	return i2c_master_send(i2c, wr_data, count);*/
	
}
int aic3262_ops_bulk_write(void *p, unsigned int reg, int count, const u8 *buf)
{
	struct aic3262_priv *ps = p;
	union aic326x_reg_union mreg;
	union cfw_register *c = (union cfw_register *) &reg;

	mreg.aic326x_register.offset = c->offset;
	mreg.aic326x_register.page = c->page;
	mreg.aic326x_register.book = c->book;
	mreg.aic326x_register.reserved = 0;
	DBG("bulk_write: ncmd %d page %d book %d offset %d data[0] %d\n",
	    count, mreg.aic326x_register.page, mreg.aic326x_register.book,
	    mreg.aic326x_register.offset, buf[0]);

	return aic3262_bulk_write(ps->codec->control_data,
				  mreg.aic326x_register_int, count, buf);
}