Пример #1
0
/*
************************************************************************************************************
*
*                                             function
*
*    函数名称:
*
*    参数列表:
*
*    返回值  :
*
*    说明    :
*
*
************************************************************************************************************
*/
int power_oz_probe(void)
{
	int ret;
	u32 oz_power_hd;
	user_gpio_set_t oz_gpio_cfg[1];

	memset(oz_gpio_cfg, 0, sizeof(oz_gpio_cfg));
	ret = script_parser_fetch("external_power", "a15_pwr_en", (int*)&oz_gpio_cfg[0], sizeof(oz_gpio_cfg[0])/sizeof(int));
	if(ret)
	{
		printf("get a15_pwr_en cfg failed\n");
		return -1;
	}

	oz_gpio_cfg[0].data = 1;

	//配置使能gpio
	ret = script_parser_patch("external_power", "a15_pwr_en", (int*)&oz_gpio_cfg[0], sizeof(oz_gpio_cfg[0])/sizeof(int));
	if(ret)
	{
		printf("patch a15_pwr_en config failed\n");
		return -2;
	}

	oz_power_hd = gpio_request_simple("external_power", "a15_pwr_en");
	if(oz_power_hd)
	{
		printf("set gpio failed\n");
		return -3;
	}
	return 0;
}
Пример #2
0
/*
************************************************************************************************************
*
*                                             function
*
*    name          :	modify_uboot_uart
*
*    parmeters     :
*
*    return        :
*
*    note          :	[email protected]
*
*
************************************************************************************************************
*/
int modify_uboot_uart(void)
{
    script_gpio_set_t fetch_cfg_gpio[2];
    u32  reg = 0;
    int uart_port_id = 0;
//disable uart0
    if(script_parser_fetch("uart_para","uart_debug_rx",(int *)(&fetch_cfg_gpio[0]),sizeof(script_gpio_set_t)/4))
    {
        printf("debug_mode_error: can't find card0_rx \n");
        return -1;
    }
	fetch_cfg_gpio[0].mul_sel = 0;
    if(script_parser_patch("uart_para","uart_debug_rx",(void*)&fetch_cfg_gpio[0],sizeof(script_gpio_set_t)/4))
    {
        printf("debug_mode_error : can't patch uart_debug_rx\n");
        return -1;
    }
    //config uart_tx
    if(script_parser_fetch("uart_para","uart_debug_tx",(int *)(&fetch_cfg_gpio[1]),sizeof(script_gpio_set_t)/4))
    {
        printf("debug_mode_error: can't find card0_tx \n");
        return -1;
    }
	fetch_cfg_gpio[1].mul_sel = 0;
    if(script_parser_patch("uart_para","uart_debug_tx",(void*)&fetch_cfg_gpio[1],sizeof(script_gpio_set_t)/4))
    {
        printf("debug_mode_error : can't patch uart_debug_tx\n");
        return -1;
    }
	//disable uart0
	gpio_request_simple("uart_para",NULL);
    //port_id
    if(script_parser_fetch("force_uart_para","force_uart_port",(int *)(&uart_port_id),sizeof(int)/4))
    {
        printf("debug_mode_error: can't find card0_tx \n");
        return -1;
    }
	if(script_parser_patch("uart_para","uart_debug_port",(int *)(&uart_port_id),sizeof(int)/4))
    {
        printf("debug_mode_error: can't find card0_tx \n");
        return -1;
    }
	if(script_parser_fetch("force_uart_para","force_uart_tx",(int *)(&fetch_cfg_gpio[0]),sizeof(script_gpio_set_t)/4))
    {
        printf("debug_mode_error: can't find card0_tx \n");
        return -1;
    }
    if(script_parser_patch("uart_para","uart_debug_tx",(void*)&fetch_cfg_gpio[0],sizeof(script_gpio_set_t)/4))
    {
        printf("debug_mode_error : can't patch uart_debug_tx\n");
        return -1;
    }
	if(script_parser_fetch("force_uart_para","force_uart_rx",(int *)(&fetch_cfg_gpio[1]),sizeof(script_gpio_set_t)/4))
    {
        printf("debug_mode_error: can't find card0_tx \n");
        return -1;
    }
    if(script_parser_patch("uart_para","uart_debug_rx",(void*)&fetch_cfg_gpio[1],sizeof(script_gpio_set_t)/4))
    {
        printf("debug_mode_error : can't patch uart_debug_tx\n");
        return -1;
    }

    printf("uart_port_id = %d\n",uart_port_id);
    uboot_spare_head.boot_data.uart_port = uart_port_id;
    //reset
#ifdef UART_RST_CTRL
	reg = readl(UART_RST_CTRL);
	reg &= ~(1 << (16 + uart_port_id));
	reg |=  (1 << (16 + uart_port_id));
        writel(reg,UART_RST_CTRL);
#endif
    //gate
	reg = readl(UART_GATE_CTRL);
    reg &= ~(1 << (16 + uart_port_id));
	reg |=  (1 << (16 + uart_port_id));
    writel(reg,UART_GATE_CTRL);
	//enable card0
	gpio_request_simple("uart_para",NULL);
    serial_init();
	return 0;
}
Пример #3
0
/*
************************************************************************************************************
*
*                                             function
*
*    函数名称:
*
*    参数列表:
*				int set_vol: not using
*				  int onoff: not using	
*    返回值  :
*
*    说明    :根据sys_config.fex 配置进行设置电压, 先设置电压,在使能或者关闭
*
*
************************************************************************************************************
*/
int power_oz_set_dcdc(int set_vol, int onoff)
{
	int ret;
	u32 oz_power_hd;
	user_gpio_set_t oz_gpio_cfg[1];

	//配置输出电压
	if(set_vol > 0)
	{
		ret = power_oz_patch_gpio(set_vol);
		if(ret)
		{
			printf("oz power patch config failed\n");
			return -1;
		}

		oz_power_hd = gpio_request_simple("external_power", "a15_vset1");
		if(oz_power_hd)
		{
			printf("set gpio failed\n");
			return -3;
		}

		oz_power_hd = gpio_request_simple("external_power", "a15_vset2");
		if(oz_power_hd)
		{
			printf("set gpio failed\n");
			return -3;
		}

		oz_power_hd = gpio_request_simple("external_power", "a15_vset3");
		if(oz_power_hd)
		{
			printf("set gpio failed\n");
			return -3;
		}
	}

	if(onoff < 0)
	{
		return 0;
	}

	memset(oz_gpio_cfg, 0, sizeof(oz_gpio_cfg));
	ret = script_parser_fetch("external_power", "a15_pwr_en", (int*)&oz_gpio_cfg[0], sizeof(oz_gpio_cfg[0])/sizeof(int));
	if(ret)
	{
		printf("get a15_pwr_en cfg failed\n");
		return -1;
	}

	if(onoff == 0)
	{
		oz_gpio_cfg[0].data = 0;
	}
	else
	{
		oz_gpio_cfg[0].data = 1;
	}

	//配置使能gpio
	ret = script_parser_patch("external_power", "a15_pwr_en", (int*)&oz_gpio_cfg[0], sizeof(oz_gpio_cfg[0])/sizeof(int));
	if(ret)
	{
		printf("patch a15_pwr_en config failed\n");
		return -2;
	}

	oz_power_hd = gpio_request_simple("external_power", "a15_pwr_en");
	if(oz_power_hd)
	{
		printf("set gpio failed\n");
		return -3;
	}
	return 0;
}
Пример #4
0
/*
**********************************************************************************************************************
*                                               i2c_init
*
* Description:
*
* Arguments  :
*
* Returns    :    none
*
* Notes      :    none
*
**********************************************************************************************************************
*/
void i2c_init(int bus_id, int speed, int slaveaddr)
{
	int i, clk_n, clk_m;
    int reg_value = 0;
	char twi_para[16] = {0};
	uint twi_host = 0;
    struct sunxi_twi_reg *i2c = NULL;

	if(bus_id < SUNXI_TWI_COUNT)
	{
		twi_host = SUNXI_TWI0_BASE + SUNXI_TWI_OFFSET * bus_id;
	}
	else
	{
		printf("i2c bus id %d is error\n", bus_id);
		return ;
	}

    i2c = (struct sunxi_twi_reg *)twi_host;
	sprintf(twi_para, "twi%d", bus_id);

#if defined(CONFIG_ARCH_SUN9IW1P1)
    //reset apb1 twi[bus_id]
    reg_value = *((unsigned int *)CCM_APB1_RST_REG0);
    reg_value |= (0x01 << bus_id);
    *((unsigned int *)CCM_APB1_RST_REG0) = reg_value;
	__msdelay(1);

	//set apb1 twi[bus_id] gating
	reg_value = *((unsigned int *)CCM_APB1_GATE0_CTRL);
    reg_value |= (0x01 << bus_id);
    *((unsigned int *)CCM_APB1_GATE0_CTRL) = reg_value;
#else
#if defined(CONFIG_ARCH_SUN8IW6P1)
    reg_value = *((unsigned int *)CCMU_BUS_SOFT_RST_REG4);
    reg_value |= (0x01 << bus_id);
    *((unsigned int *)CCMU_BUS_SOFT_RST_REG4) = reg_value;
	__msdelay(1);

	reg_value = *((unsigned int *)CCMU_BUS_CLK_GATING_REG3);
	reg_value |= (0x01 << bus_id);
	*((unsigned int *)CCMU_BUS_CLK_GATING_REG3) = reg_value ;
#else
	struct sunxi_ccm_reg *ccm_reg = (struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
#if !defined(CONFIG_ARCH_SUN5I)||!defined(CONFIG_ARCH_SUN7I)
        /* reset i2c clock    */
        /* reset apb2 twi0*/
        reg_value = *((unsigned int *)0x01c202d8);
        reg_value |= 0x01;
       *((unsigned int *)0x01c202d8) = reg_value;
	__msdelay(1);
#endif
	ccm_reg->apb1_gate &= ~1;
	__msdelay(1);
	ccm_reg->apb1_gate |=  1;
#endif
#endif
	/* set i2c gpio */
    //gpio_request_early((void *)uboot_spare_head.boot_data.twi_gpio, 2, 1);
    gpio_request_simple(twi_para, NULL);
	/* reset i2c control  */
    i = 0xffff;
    i2c->srst = 1;
    while((i2c->srst) && (i))
    {
    	i --;
    }
    if((i2c->lcr & 0x30) != 0x30 )
    {
    	/* toggle I2CSCL until bus idle */
    	i2c->lcr = 0x05;
    	__usdelay(500);
    	i = 10;
		while ((i > 0) && ((i2c->lcr & 0x02) != 2))
		{
			i2c->lcr |= 0x08;
			__usdelay(1000);
			i2c->lcr &= ~0x08;
			__usdelay(1000);
			i--;
		}
		i2c->lcr = 0x0;
		__usdelay(500);
    }

	if(speed < 100)
	{
		speed = 100;
	}
	else if(speed > 400)
	{
		speed = 400;
	}
	clk_n = 1;
	clk_m = (24000/10)/((2^clk_n) * speed) - 1;

    i2c->clk = (clk_m<<3) | clk_n;
    i2c->ctl = 0x40;
    i2c->eft = 0;
    return ;
}