/* ************************************************************************************************************ * * function * * 函数名称: * * 参数列表: * * 返回值 : * * 说明 : * * ************************************************************************************************************ */ int power_oz_set_power_output(void) { uint ret; int onoff; int power_vol; int power_vol_d; ret = script_parser_fetch_subkey_start("slave_power_sply"); if(!ret) { printf("unable to set slave power supply\n"); return -1; } ret = script_parser_fetch("slave_power_sply", "dcdc_vol", &power_vol, 1); if(ret) { printf("unable to get dcdc vol\n"); return -1; } onoff = -1; power_vol_d = 0; if(power_vol > 10000) { onoff = 1; power_vol_d = power_vol%10000; } #if defined(CONFIG_SUNXI_AXP_CONFIG_ONOFF) else if(power_vol > 0) { onoff = 0; power_vol_d = power_vol; } #endif else if(power_vol == 0) { onoff = 0; } #if defined(CONFIG_SUNXI_AXP_CONFIG_ONOFF) printf("oz dcdc = %d, onoff=%d\n", power_vol_d, onoff); #else printf("oz dcdc = %d\n", power_vol_d); #endif power_oz_set_dcdc(power_vol_d, onoff); return 0; }
int power_config_gpio_bias(void) { char gpio_bias[32], gpio_name[32]; char *gpio_name_const="pa_bias"; char port_index; char *axp=NULL, *supply=NULL, *vol=NULL; uint main_hd; uint bias_vol_set; int index, ret, i; uint port_bias_addr; uint vol_index, config_type; int pmu_vol; struct bias_set bias_vol_config[8] = { {1800, 0}, {2500, 6}, {2800, 9}, {3000, 0xa}, {3300, 0xd}, {0, 0} }; main_hd = script_parser_fetch_subkey_start("gpio_bias"); if(main_hd == 0) { printf("gpio_bias not exist\n"); return 0; } index = 0; while(1) { memset(gpio_bias, 0, 32); memset(gpio_name, 0, 32); ret = script_parser_fetch_subkey_next(main_hd, gpio_name, (int *)gpio_bias, &index); if(!ret) { lower(gpio_name); lower(gpio_bias); port_index = gpio_name[1]; gpio_name[1] = 'a'; if(strcmp(gpio_name_const, gpio_name)) { printf("invalid gpio bias name %s\n", gpio_name); continue; } gpio_name[1] = port_index; i=0; axp = gpio_bias; while( (gpio_bias[i]!=':') && (gpio_bias[i]!='\0') ) { i++; } gpio_bias[i++]='\0'; if(!strcmp(axp, "constant")) { config_type = 1; } else if(!strcmp(axp, "floating")) { printf("ignore %s bias config\n", gpio_name); continue; } else { config_type = 0; } if(config_type == 0) { supply = gpio_bias + i; while( (gpio_bias[i]!=':') && (gpio_bias[i]!='\0') ) { i++; } gpio_bias[i++]='\0'; } printf("supply=%s\n", supply); vol = gpio_bias + i; while( (gpio_bias[i]!=':') && (gpio_bias[i]!='\0') ) { i++; } bias_vol_set = simple_strtoul(vol, NULL, 10); for(i=0;i<5;i++) { if(bias_vol_config[i].vol == bias_vol_set) { break; } } if(i==5) { printf("invalid gpio bias set vol %d, at name %s\n", bias_vol_set, gpio_name); break; } vol_index = bias_vol_config[i].index; if((port_index >= 'a') && (port_index <= 'h')) { //获取寄存器地址 port_bias_addr = SUNXI_PIO_BASE + 0x300 + 0x4 * (port_index - 'a'); } else if(port_index == 'j') { //获取寄存器地址 port_bias_addr = SUNXI_PIO_BASE + 0x300 + 0x4 * (port_index - 'a'); } else if((port_index == 'l') || (port_index == 'm')) { //获取寄存器地址 port_bias_addr = SUNXI_RPIO_BASE + 0x300 + 0x4 * (port_index - 'l'); } else { printf("invalid gpio port at name %s\n", gpio_name); continue; } printf("axp=%s, supply=%s, vol=%d\n", axp, supply, bias_vol_set); if(config_type == 1) { smc_writel(vol_index, port_bias_addr); } else { pmu_vol = axp_probe_supply_status_byname(axp, supply); if(pmu_vol < 0) { printf("sunxi board read %s %s failed\n", axp, supply); continue; } if(pmu_vol > bias_vol_set) //pmu实际电压超过需要设置的电压 { //电压降低到需要电压 axp_set_supply_status_byname(axp, supply, bias_vol_set, 1); //设置寄存器 smc_writel(vol_index, port_bias_addr); } else if(pmu_vol < bias_vol_set) //pmu实际电压低于需要设置的电压 { //设置寄存器 smc_writel(vol_index, port_bias_addr); //把pmu电压调整到需要的电压 axp_set_supply_status_byname(axp, supply, bias_vol_set, 1); } else { //如果实际电压等于需要设置电压,直接设置即可 smc_writel(vol_index, port_bias_addr); } } printf("reg addr=0x%x, value=0x%x, pmu_vol=%d\n", port_bias_addr, smc_readl(port_bias_addr), bias_vol_set); } else { printf("config gpio bias voltage finish\n"); break; } } return 0; }
/* ************************************************************************************************************ * * function * * 函数名称: * * 参数列表: * * 返回值 : * * 说明 : * * ************************************************************************************************************ */ int axp_slave_set_power_supply_output(void) { int ret, onoff; uint slave_power_sply; char power_name[16]; int power_vol, power_index = 0; int index = -1; int i; int power_vol_d; slave_power_sply = script_parser_fetch_subkey_start("slave_power_sply"); if(!slave_power_sply) { printf("unable to set slave power supply\n"); return -1; } for(i=1;i<SUNXI_AXP_DEV_MAX;i++) { if(sunxi_axp_dev[i] != NULL) { if(strcmp(sunxi_axp_dev[0]->pmu_name, sunxi_axp_dev[i]->pmu_name)) { index = i; break; } } } if(index == -1) { printf("unable to find slave pmu\n"); return -1; } printf("slave power\n"); do { memset(power_name, 0, 16); ret = script_parser_fetch_subkey_next(slave_power_sply, power_name, &power_vol, &power_index); if(ret < 0) { printf("find slave power sply to end\n"); return 0; } onoff = -1; power_vol_d = 0; if(power_vol > 10000) { onoff = 1; power_vol_d = power_vol%10000; } #if defined(CONFIG_SUNXI_AXP_CONFIG_ONOFF) else if(power_vol > 0) { onoff = 0; power_vol_d = power_vol; } #endif else if(power_vol == 0) { onoff = 0; } #if defined(CONFIG_SUNXI_AXP_CONFIG_ONOFF) printf("%s = %d, onoff=%d\n", power_name, power_vol_d, onoff); #else printf("%s = %d\n", power_name, power_vol_d); #endif if(sunxi_axp_dev[index]->set_supply_status_byname(power_name, power_vol_d, onoff)) { printf("axp set %s to %d failed\n", power_name, power_vol_d); } } while(1); return 0; }
/* ************************************************************************************************************ * * function * * 函数名称: * * 参数列表: * * 返回值 : * * 说明 : * * ************************************************************************************************************ */ int axp_set_power_supply_output(void) { int ret, onoff; uint power_supply_hd; char power_name[16]; int power_vol, power_index = 0; int power_vol_d; #if defined(CONFIG_SUNXI_AXP20) #if defined(CONFIG_SUNXI_SUN7I) power_supply_hd = script_parser_fetch_subkey_start("target"); #else power_supply_hd = script_parser_fetch_subkey_start("power_sply"); #endif #elif defined(CONFIG_SUNXI_AXP15) power_supply_hd = script_parser_fetch_subkey_start("axp15_para"); #elif (defined(CONFIG_ARCH_SUN8IW6) && defined(CONFIG_ARCH_HOMELET)) int chipid; //0x18:axp_818, 0x13:axp_813 0x03:axp_803 0x0: key not burn chipid = plat_get_chip_id(); if(chipid == 0x03) { power_supply_hd = script_parser_fetch_subkey_start("power_sply_ext"); } else { power_supply_hd = script_parser_fetch_subkey_start("power_sply"); } #else power_supply_hd = script_parser_fetch_subkey_start("power_sply"); #endif if(!power_supply_hd) { printf("unable to set power supply\n"); return -1; } do { memset(power_name, 0, 16); ret = script_parser_fetch_subkey_next(power_supply_hd, power_name, &power_vol, &power_index); if(ret < 0) { printf("find power_sply to end\n"); return 0; } onoff = -1; power_vol_d = 0; #if defined(CONFIG_SUNXI_AXP_CONFIG_ONOFF) if(power_vol > 10000) { onoff = 1; power_vol_d = power_vol%10000; } else if(power_vol >= 0) { onoff = 0; power_vol_d = power_vol; } #else if(power_vol > 0 ) { onoff = 1; power_vol_d = power_vol; } else if(power_vol == 0) { onoff = 0; } #endif #if defined(CONFIG_SUNXI_AXP_CONFIG_ONOFF) printf("%s = %d, onoff=%d\n", power_name, power_vol_d, onoff); #else printf("%s = %d\n", power_name, power_vol_d); #endif if(sunxi_axp_dev[0]->set_supply_status_byname(power_name, power_vol_d, onoff)) { printf("axp set %s to %d failed\n", power_name, power_vol_d); } } while(1); return 0; }