Exemple #1
0
static int wait_busy(void)
{
	int timeout = I2C_MAX_TIMEOUT;

	while ((!(__REG16(i2c_port_addr[i2c_port_num] + I2SR) & I2SR_IBB) && (--timeout))) {
		__REG16(i2c_port_addr[i2c_port_num] + I2SR) = 0;
		udelay(I2C_TIMEOUT_TICKET);
		//printf("@");
	}
	return timeout ? timeout : (__REG16(i2c_port_addr[i2c_port_num] + I2SR) & I2SR_IBB);
}
Exemple #2
0
int i2c_probe(uchar chip)
{
	int ret = 0;
	__REG16(i2c_port_addr[i2c_port_num] + I2CR) = 0;	/* Reset module */
	__REG16(i2c_port_addr[i2c_port_num] + I2CR) = I2CR_IEN;
	udelay(1000);
	__REG16(i2c_port_addr[i2c_port_num] + I2CR) = I2CR_IEN | I2CR_MSTA | I2CR_MTX;
	__REG16(i2c_port_addr[i2c_port_num] + I2DR) = (chip << 1);
	wait_complete();
	__REG16(i2c_port_addr[i2c_port_num] + I2CR) = I2CR_IEN;
	return ret;
}
Exemple #3
0
static int wait_idle(void)
{
	int timeout = I2C_MAX_TIMEOUT;

	while ((__REG16(i2c_port_addr[i2c_port_num] + I2SR) & I2SR_IBB) && --timeout) {
		__REG16(i2c_port_addr[i2c_port_num] + I2SR) = 0;
		udelay(I2C_TIMEOUT_TICKET);
		//printf("%");
	}
	DPRINTF("%s:%x, timeout: %d\n", __func__, __REG16(i2c_port_addr[i2c_port_num] + I2SR), timeout);
	return timeout ? timeout : (!(__REG16(i2c_port_addr[i2c_port_num] + I2SR) & I2SR_IBB));
}
Exemple #4
0
int i2c_write(uchar chip, uint addr, int alen, uchar *buf, int len)
{
	int timeout = I2C_MAX_TIMEOUT;
	char i = 0;
	//printf("%s chip: 0x%02x addr: 0x%04x alen: %d len: %d, data: %d\n", __func__, chip, addr, alen, len, *buf);
	__REG16(i2c_port_addr[i2c_port_num] + I2SR) = 0;
	__REG16(i2c_port_addr[i2c_port_num] + I2CR) = I2CR_IEN;
	/* Wait controller to be stable */
	udelay(50);
	__REG16(i2c_port_addr[i2c_port_num] + I2CR) |= I2CR_MSTA;
	/* Start I2C transaction */
	wait_busy();
	
	__REG16(i2c_port_addr[i2c_port_num] + I2CR) |= I2CR_IIEN | I2CR_MTX | I2CR_TX_NO_AK;
	__REG16(i2c_port_addr[i2c_port_num] + I2DR) = chip << 1;
	wait_complete();
	for(i = 0; i < len; i++){
		__REG16(i2c_port_addr[i2c_port_num] + I2DR) = *(buf+i);
		wait_complete();
	}	
	__REG16(i2c_port_addr[i2c_port_num] + I2CR) &= ~(I2CR_MSTA | I2CR_MTX);
	wait_idle();
	__REG16(i2c_port_addr[i2c_port_num] + I2CR)  = 0;
	return 0;
}
Exemple #5
0
static int wait_complete(void)
{
	int timeout = I2C_MAX_TIMEOUT;

	while ((!(__REG16(i2c_port_addr[i2c_port_num] + I2SR) & I2SR_ICF)) && (--timeout)) {
		__REG16(i2c_port_addr[i2c_port_num] + I2SR) = 0;
		udelay(I2C_TIMEOUT_TICKET);
		//printf("#");
	}
	udelay(500);

	/*
	while( (__REG16(i2c_port_addr[i2c_port_num] + I2SR) & I2SR_RX_NO_AK) && (--timeout)){
		__REG16(i2c_port_addr[i2c_port_num] + I2SR) = 0;
		udelay(I2C_TIMEOUT_TICKET);
		printf("$");
	}
	*/
	DPRINTF("%s:%x\n", __func__, __REG16(i2c_port_addr[i2c_port_num] + I2SR));
	__REG16(i2c_port_addr[i2c_port_num] + I2SR) = 0;	/* clear interrupt */

	return timeout;
}
Exemple #6
0
void i2c_init(int speed, int unused)
{
	int freq;
	int i;

#ifdef CONFIG_MX31
	freq = mx31_get_ipg_clk();
#else
	freq = mxc_get_clock(MXC_IPG_CLK);
#endif
	for (i = 0; i < 0x1f; i++)
		if (freq / div[i] <= speed)
			break;

	__REG16(i2c_port_addr[i2c_port_num] + IFDR) = i;
	i2c_reset();
}
Exemple #7
0
static inline void i2c_reset(void)
{
	__REG16(i2c_port_addr[i2c_port_num] + I2CR) = 0;	/* Reset module */
	__REG16(i2c_port_addr[i2c_port_num] + I2SR) = 0;
	__REG16(i2c_port_addr[i2c_port_num] + I2CR) = I2CR_IEN;
}
Exemple #8
0
int i2c_read(uchar chip, uint addr, int alen, uchar *buf, int len)
{
	int timeout = I2C_MAX_TIMEOUT;
	char i = 0;
	uchar temp = 0;
	uchar temp2 = 0;
	DPRINTF("%s chip: 0x%02x addr: 0x%04x alen: %d len: %d\n", __func__, chip, addr, alen, len);

	__REG16(i2c_port_addr[i2c_port_num] + I2SR) = 0;
	__REG16(i2c_port_addr[i2c_port_num] + I2CR) = I2CR_IEN;
	/* Wait controller to be stable */
	udelay(50);
	__REG16(i2c_port_addr[i2c_port_num] + I2CR) |= I2CR_MSTA;
	/* Start I2C transaction */
	wait_busy();
	
	__REG16(i2c_port_addr[i2c_port_num] + I2CR) |= I2CR_IIEN | I2CR_MTX | I2CR_TX_NO_AK;
	__REG16(i2c_port_addr[i2c_port_num] + I2DR) = chip << 1;
	wait_complete();
	__REG16(i2c_port_addr[i2c_port_num] + I2DR) = addr;		// address 0 -> version
	wait_complete();	// write finish: address and addr
	//DPRINTF("i2c_read: write addr done\n");
	udelay(500);
	__REG16(i2c_port_addr[i2c_port_num] + I2CR) = I2CR_IEN | I2CR_MSTA | I2CR_MTX | I2CR_RSTA;
	/* Restart I2C transaction */
	wait_busy();
	__REG16(i2c_port_addr[i2c_port_num] + I2DR) = (chip << 1) | 0x01;
	wait_complete();
	//DPRINTF("i2c_read: read action send\n");	
	udelay(500);
	__REG16(i2c_port_addr[i2c_port_num] + I2CR) = I2CR_IEN | I2CR_MSTA | I2CR_TX_NO_AK;
	temp = __REG16(i2c_port_addr[i2c_port_num] + I2DR);
	wait_complete();
	__REG16(i2c_port_addr[i2c_port_num] + I2CR) &= ~(I2CR_MSTA | I2CR_MTX);
	wait_idle();
	*buf =  __REG16(i2c_port_addr[i2c_port_num] + I2DR);
	DPRINTF("i2c_read temp: 0x%x, buf: 0x%x\n", temp, *buf);
	__REG16(i2c_port_addr[i2c_port_num] + I2CR)  = 0;
	return 0;
}
Exemple #9
0
void reset_cpu(ulong addr)
{
	__REG16(WDOG_BASE) = 4;
}
void reset_cpu(ulong addr)
{
	__REG16(WDOG1_BASE_ADDR) = 4;
}