Exemple #1
0
/* make ec goto idle mode */
int ec_init_idle_mode(void)
{
	int timeout;
	unsigned char status = 0;
	int ret = 0;

	ec_query_seq(CMD_INIT_IDLE_MODE);

	/* make the action take active */
	timeout = EC_CMD_TIMEOUT;
	status = rdec(REG_POWER_MODE) & FLAG_IDLE_MODE;
	while(timeout--){
		if(status){
			udelay(EC_REG_DELAY);
			break;
		}
		status = rdec(REG_POWER_MODE) & FLAG_IDLE_MODE;
		udelay(EC_REG_DELAY);
	}
	if(timeout <= 0){
		printf("ec rom fixup : can't check idle status.\n");
		ret = -1;
	}

	//printf("entering idle mode ok...................\n");

	return ret;
}
Exemple #2
0
/* make ec exit from reset mode */
void ec_exit_reset_mode(void)
{
	unsigned char regval;

	udelay(EC_REG_DELAY);
	regval = rdec(REG_LPCCFG);
	regval |= (1 << 7);
	wrec(REG_LPCCFG, regval);
	regval = rdec(REG_PXCFG);
	regval &= ~(1 << 0);
	wrec(REG_PXCFG, regval);
	//printf("exit reset mode ok..................\n");

	return;
}
Exemple #3
0
/* enable the chip reset mode */
int ec_init_reset_mode(void)
{
	int timeout;
	unsigned char status = 0;
	int ret = 0;
	
	/* make chip goto reset mode */
	ret = ec_query_seq(CMD_INIT_RESET_MODE);
	if(ret < 0){
		printf("ec init reset mode failed.\n");
		goto out;
	}

	/* make the action take active */
	timeout = EC_CMD_TIMEOUT;
	status = rdec(REG_POWER_MODE) & FLAG_RESET_MODE;
	while(timeout--){
		if(status){
			udelay(EC_REG_DELAY);
			break;
		}
		status = rdec(REG_POWER_MODE) & FLAG_RESET_MODE;
		udelay(EC_REG_DELAY);
	}
	if(timeout <= 0){
		printf("ec rom fixup : can't check reset status.\n");
		ret = -1;
	}

	/* set MCU to reset mode */
	udelay(EC_REG_DELAY);
	status = rdec(REG_PXCFG);
	status |= (1 << 0);
	wrec(REG_PXCFG, status);
	udelay(EC_REG_DELAY);

	/* disable FWH/LPC */
	udelay(EC_REG_DELAY);
	status = rdec(REG_LPCCFG);
	status &= ~(1 << 7);
	wrec(REG_LPCCFG, status);
	udelay(EC_REG_DELAY);

	//printf("entering reset mode ok..............\n");

out :
	return ret;
}
Exemple #4
0
/* read one byte from xbi interface */
int ec_read_byte(unsigned int addr, unsigned char *byte)
{
	int ret = 0;

	/* enable spicmd writing. */
	ec_start_spi();

	/* enable write spi flash */
	wrec(REG_XBISPICMD, SPICMD_WRITE_ENABLE);
	if(rom_instruction_cycle(SPICMD_WRITE_ENABLE) == EC_STATE_BUSY){
			printf("EC_READ_BYTE : SPICMD_WRITE_ENABLE failed.\n");
			ret = -1;
			goto out;
	}
	
	/* write the address */
	wrec(REG_XBISPIA2, (addr & 0xff0000) >> 16);
	wrec(REG_XBISPIA1, (addr & 0x00ff00) >> 8);
	wrec(REG_XBISPIA0, (addr & 0x0000ff) >> 0);
	/* start action */
	wrec(REG_XBISPICMD, SPICMD_HIGH_SPEED_READ);
	if(rom_instruction_cycle(SPICMD_HIGH_SPEED_READ) == EC_STATE_BUSY){
			printf("EC_READ_BYTE : SPICMD_HIGH_SPEED_READ failed.\n");
			ret = -1;
			goto out;
	}
	
	*byte = rdec(REG_XBISPIDAT);

out :
	/* disable spicmd writing. */
	ec_stop_spi();

	return ret;
}
Exemple #5
0
/* To see if the ec is in busy state or not. */
static inline int ec_flash_busy(unsigned long timeout)
{
	/* assurance the first command be going to rom */
	if( ec_instruction_cycle() < 0 ){
		return EC_STATE_BUSY;
	}

	timeout = timeout / EC_MAX_DELAY_UNIT;
	while(timeout-- > 0){
		/* check the rom's status of busy flag */
		wrec(REG_XBISPICMD, SPICMD_READ_STATUS);
		if( ec_instruction_cycle() < 0 ){
			return EC_STATE_BUSY;
		}	
		if((rdec(REG_XBISPIDAT) & 0x01) == 0x00){
			return EC_STATE_IDLE;
		}
		udelay(EC_MAX_DELAY_UNIT);
	}
	if( timeout <= 0 ){
		printf("EC_FLASH_BUSY : timeout for check rom flag.\n");
		return EC_STATE_BUSY;
	}

	return EC_STATE_IDLE;
}
Exemple #6
0
/* stop the action to spi rom function */
void ec_stop_spi(void)
{
	unsigned char val;

	delay_spi(SPI_FINISH_WAIT_TIME);
	val = rdec(REG_XBISPICFG) & (~(SPICFG_EN_SPICMD | SPICFG_AUTO_CHECK));
	wrec(REG_XBISPICFG, val);
	delay_spi(SPI_FINISH_WAIT_TIME);
}
Exemple #7
0
Fichier : kbd.c Projet : kisom/pmon
/* we just ensure there is code in EC, and the keyboard will work. */
static int kb3310_test(void)
{
	unsigned char val;
	val = rdec(0x00);
	if(val == 0xff)
		return 1;
	
	return 0;
}
Exemple #8
0
/* Starts to execute the protect SPI ROM function. */
int EC_ROM_start_protect(void)
{
	unsigned char status;
	int j;

	/* we should start spi access firstly */
	ec_start_spi();

	/* enable write spi flash */
	wrec(REG_XBISPICMD, SPICMD_WRITE_ENABLE);
	if(rom_instruction_cycle(SPICMD_WRITE_ENABLE) == EC_STATE_BUSY){
			printf("EC_PROGRAM_ROM : SPICMD_WRITE_ENABLE failed.\n");
			goto out1;
	}
	
	/* protect the status register of rom */
	wrec(REG_XBISPICMD, SPICMD_READ_STATUS);
	if(rom_instruction_cycle(SPICMD_READ_STATUS) == EC_STATE_BUSY){
			printf("EC_PROGRAM_ROM : SPICMD_READ_STATUS failed.\n");
			goto out1;
	}
	status = rdec(REG_XBISPIDAT);

	wrec(REG_XBISPIDAT, status | 0x1C);
	if(ec_instruction_cycle() < 0){
			printf("EC_PROGRAM_ROM : write status value failed.\n");
			goto out1;
	}

	wrec(REG_XBISPICMD, SPICMD_WRITE_STATUS);
	if(rom_instruction_cycle(SPICMD_WRITE_STATUS) == EC_STATE_BUSY){
			printf("EC_PROGRAM_ROM : SPICMD_WRITE_STATUS failed.\n");
			goto out1;
	}

	/* disable the write action to spi rom */
	wrec(REG_XBISPICMD, SPICMD_WRITE_DISABLE);
	if(rom_instruction_cycle(SPICMD_WRITE_DISABLE) == EC_STATE_BUSY){
			printf("EC_PROGRAM_ROM : SPICMD_WRITE_DISABLE failed.\n");
			goto out1;
	}
	
out1:
	/* we should stop spi access firstly */
	ec_stop_spi();
out:
	/* for security */
	//for(j = 0; j < 2000; j++)
	//	udelay(1000);

	/* exit from the reset mode */
	//ec_exit_reset_mode();

	return 0;
}
Exemple #9
0
/* make ec enable WDD */
void ec_enable_WDD(void)
{
	unsigned char status;

	udelay(EC_REG_DELAY);
	status = rdec(REG_WDTCFG);
	wrec(REG_WDT, 0x28);		//set WDT 5sec(0x28)
	wrec(REG_WDTCFG, (status & 0x80) | 0x03);
	//printf("Enable WDD ok..................\n");

	return;
}
Exemple #10
0
/* make ec disable WDD */
void ec_disable_WDD(void)
{
	unsigned char status;

	udelay(EC_REG_DELAY);
	status = rdec(REG_WDTCFG);
	wrec(REG_WDTPF, 0x03);
	wrec(REG_WDTCFG, (status & 0x80) | 0x48);
	//printf("Disable WDD ok..................\n");

	return;
}
Exemple #11
0
/* erase one block or chip or sector as needed */
int ec_unit_erase(unsigned char erase_cmd, unsigned int addr)
{
	unsigned char status;
	int ret = 0, i = 0;
	int unprotect_count = 3;
	int check_flag =0;

	/* enable spicmd writing. */
	ec_start_spi();

#ifdef EC_ROM_PROTECTION
	/* added for re-check SPICMD_READ_STATUS */
	while(unprotect_count-- > 0){
		if(EC_ROM_unprotect()){
			ret = -1;
			goto out;
		}
		
		for(i = 0; i < ((2 - unprotect_count) * 100 + 10); i++)	//first time:500ms --> 5.5sec -->10.5sec
			udelay(50000);
		wrec(REG_XBISPICMD, SPICMD_READ_STATUS);
		if(rom_instruction_cycle(SPICMD_READ_STATUS) == EC_STATE_BUSY){
			printf("EC_PROGRAM_ROM : SPICMD_READ_STATUS failed.\n");
		} else {
			status = rdec(REG_XBISPIDAT);
			//printf("Read unprotect status : 0x%x\n", status);
			if((status & 0x1C) == 0x00){
				//printf("Read unprotect status OK1 : 0x%x\n", status & 0x1C);
				check_flag = 1;
				break;
			}
		}	
	}

	if(!check_flag){
		printf("SPI ROM unprotect fail.\n");
		return 1;
	}
#endif

	/* block address fill */
	if(erase_cmd == SPICMD_BLK_ERASE){
		wrec(REG_XBISPIA2, (addr & 0x00ff0000) >> 16);
		wrec(REG_XBISPIA1, (addr & 0x0000ff00) >> 8);
		wrec(REG_XBISPIA0, (addr & 0x000000ff) >> 0);
	}
Exemple #12
0
int ec_instruction_cycle(void)
{
	unsigned long timeout;
	int ret = 0;

	timeout = EC_FLASH_TIMEOUT;
	while(timeout-- >= 0){
		if( !(rdec(REG_XBISPICFG) & SPICFG_SPI_BUSY) )
				break;
	}
	if(timeout <= 0){
		printf("EC_INSTRUCTION_CYCLE : timeout for check flag.\n");
		ret = -1;
		goto out;
	}

out :
	return ret;
}
Exemple #13
0
/* EC_ROM_unprotect function code */
int EC_ROM_unprotect(void)
{
	unsigned char status;

	/* enable write spi flash */
	wrec(REG_XBISPICMD, SPICMD_WRITE_ENABLE);
	if(rom_instruction_cycle(SPICMD_WRITE_ENABLE) == EC_STATE_BUSY){
		printf("EC_UNIT_ERASE : SPICMD_WRITE_ENABLE failed.\n");
		return 1;
	}

	/* unprotect the status register of rom */
	wrec(REG_XBISPICMD, SPICMD_READ_STATUS);
	if(rom_instruction_cycle(SPICMD_READ_STATUS) == EC_STATE_BUSY){
		printf("EC_UNIT_ERASE : SPICMD_READ_STATUS failed.\n");
		return 1;
	}
	status = rdec(REG_XBISPIDAT);
	wrec(REG_XBISPIDAT, status & 0x02);
	if(ec_instruction_cycle() < 0){
		printf("EC_UNIT_ERASE : write status value failed.\n");
		return 1;
	}

	wrec(REG_XBISPICMD, SPICMD_WRITE_STATUS);
	if(rom_instruction_cycle(SPICMD_WRITE_STATUS) == EC_STATE_BUSY){
		printf("EC_UNIT_ERASE : SPICMD_WRITE_STATUS failed.\n");
		return 1;
	}

	/* enable write spi flash */
	wrec(REG_XBISPICMD, SPICMD_WRITE_ENABLE);
	if(rom_instruction_cycle(SPICMD_WRITE_ENABLE) == EC_STATE_BUSY){
		printf("EC_UNIT_ERASE : SPICMD_WRITE_ENABLE failed.\n");
		return 1;
	}

	return 0;
}
Exemple #14
0
/* Starts to execute the unprotect SPI ROM function. */
int EC_ROM_start_unprotect(void)
{
	unsigned char status;
	int ret = 0, i = 0;
	int unprotect_count = 3;
	int check_flag =0;

	/* added for re-check SPICMD_READ_STATUS */
	while(unprotect_count-- > 0){
		if(EC_ROM_unprotect()){
			ret = -1;
			return ret;
		}
		
		for(i = 0; i < ((2 - unprotect_count) * 100 + 10); i++)	//first time:500ms --> 5.5sec -->10.5sec
			udelay(50000);
		wrec(REG_XBISPICMD, SPICMD_READ_STATUS);
		if(rom_instruction_cycle(SPICMD_READ_STATUS) == EC_STATE_BUSY){
			printf("EC_PROGRAM_ROM : SPICMD_READ_STATUS failed.\n");
		} else {
			status = rdec(REG_XBISPIDAT);
			//printf("Read unprotect status : 0x%x\n", status);
			if((status & 0x1C) == 0x00){
				//printf("Read unprotect status OK1 : 0x%x\n", status & 0x1C);
				check_flag = 1;
				break;
			}
		}	
	}

	if(!check_flag){
		printf("SPI ROM unprotect fail.\n");
		return 1;
	}
	//printf("SPI ROM unprotect success.\n");

	return ret;
}