int axp202_set_rapid_time(int time) { int val; switch (time) { case 360: val = 0x00; break; case 480: val = 0x01; break; case 600: val = 0x02; break; case 720: val = 0x03; break; default: printf("%s, wrong rapid charge timeout:%d\n", __func__, time); return -1; } return axp_update(0x34, val, 0x03); }
int axp202_set_trickle_time(int time) { int val; switch (time) { case 40: val = 0x00; break; case 50: val = 0x40; break; case 60: val = 0x80; break; case 70: val = 0xc0; break; default: printf("%s, wrong trickle charge timeout:%d\n", __func__, time); return -1; } return axp_update(0x34, val, 0xc0); }
int axp202_set_full_charge_voltage(int voltage) { int val; switch (voltage) { case 4100000: val = 0x00; break; case 4150000: val = 0x20; break; case 4200000: val = 0x40; break; case 4360000: val = 0x60; break; default : printf("%s, wrong charge target voltage:%d\n", __func__, voltage); return -1; } return axp_update(0x33, val, 0x60); }
static void axp_set_charge(struct axp_charger *charger) { uint8_t val=0x00; uint8_t tmp=0x00; if(charger->chgvol < AXP81X_CHARGE_VOLTAGE_LEVEL1){ val &= ~(3 << 5); }else if (charger->chgvol<AXP81X_CHARGE_VOLTAGE_LEVEL2){ val &= ~(3 << 5); val |= 1 << 5; }else if (charger->chgvol<AXP81X_CHARGE_VOLTAGE_LEVEL3){ val &= ~(3 << 5); val |= 1 << 6; }else val |= 3 << 5; spin_lock(&charger->charger_lock); if(charger->chgcur == 0) charger->chgen = 0; if(charger->chgcur< 200000) charger->chgcur = 200000; else if(charger->chgcur > 2800000) charger->chgcur = 2800000; spin_unlock(&charger->charger_lock); val |= (charger->chgcur - 200000) / 200000 ; if(charger ->chgend == 10) val &= ~(1 << 4); else val |= 1 << 4; val &= 0x7F; val |= charger->chgen << 7; spin_lock(&charger->charger_lock); if(charger->chgpretime < 30) charger->chgpretime = 30; if(charger->chgcsttime < 360) charger->chgcsttime = 360; spin_unlock(&charger->charger_lock); tmp = ((((charger->chgpretime - 40) / 10) << 6) \ | ((charger->chgcsttime - 360) / 120)); axp_write(charger->master, AXP81X_CHARGE_CONTROL1,val); axp_update(charger->master, AXP81X_CHARGE_CONTROL2,tmp,0xC2); }
static void axp_earlysuspend(struct early_suspend *h) { uint8_t tmp; DBG_PSY_MSG(DEBUG_SPLY, "======early suspend=======\n"); #if defined (CONFIG_AXP_CHGCHANGE) early_suspend_flag = 1; if(axp81x_config.pmu_earlysuspend_chgcur == 0) axp_clr_bits(axp_charger->master,AXP81X_CHARGE_CONTROL1,0x80); else axp_set_bits(axp_charger->master,AXP81X_CHARGE_CONTROL1,0x80); if(axp81x_config.pmu_earlysuspend_chgcur >= 300000 && axp81x_config.pmu_earlysuspend_chgcur <= 2550000){ tmp = (axp81x_config.pmu_earlysuspend_chgcur -200001)/150000; axp_update(axp_charger->master, AXP81X_CHARGE_CONTROL1, tmp,0x0F); } #endif }
/* AXP common operations */ static int axp_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV,unsigned *selector) { struct axp_regulator_info *info = rdev_get_drvdata(rdev); struct device *axp_dev = to_axp_dev(rdev); uint8_t val, mask; if (check_range(info, min_uV, max_uV)) { pr_err("invalid voltage range (%d, %d) uV\n", min_uV, max_uV); return -EINVAL; } val = (min_uV - info->min_uV + info->step1_uV - 1) / info->step1_uV; val <<= info->vol_shift; mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; return axp_update(axp_dev, info->vol_reg, val, mask); }
/* AXP common operations */ static int axp_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV) { struct axp_regulator_info *info = rdev_get_drvdata(rdev); struct device *axp_dev = to_axp_dev(rdev); uint8_t val, mask; if (check_range(info, min_uV, max_uV)) { pr_err("invalid voltage range (%d, %d) uV\n", min_uV, max_uV); return -EINVAL; } val = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV; val <<= info->vol_shift; mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; //printk("rdev.desc.name = %s\n",rdev->desc->name); //printk("reg=[%x],val=%d,mask=%d,line=%d\n",info->vol_reg,val,mask,__LINE__); return axp_update(axp_dev, info->vol_reg, val, mask); }
static void axp81x_shutdown(struct platform_device *dev) { uint8_t tmp; struct axp_charger *charger = platform_get_drvdata(dev); cancel_delayed_work_sync(&charger->work); #if defined (CONFIG_AXP_CHGCHANGE) if(axp81x_config.pmu_shutdown_chgcur == 0) axp_clr_bits(charger->master,AXP81X_CHARGE_CONTROL1,0x80); else axp_set_bits(charger->master,AXP81X_CHARGE_CONTROL1,0x80); printk("pmu_shutdown_chgcur = %d\n", axp81x_config.pmu_shutdown_chgcur); if(axp81x_config.pmu_shutdown_chgcur >= 300000 && axp81x_config.pmu_shutdown_chgcur <= 2550000){ tmp = (axp81x_config.pmu_shutdown_chgcur -200001)/150000; charger->chgcur = tmp *150000 + 300000; axp_update(charger->master, AXP81X_CHARGE_CONTROL1, tmp, 0x0F); } #endif return; }
static int axp81x_resume(struct platform_device *dev) { struct axp_charger *charger = platform_get_drvdata(dev); int pre_rest_vol; uint8_t val,tmp; axp_enable_irq(charger); pre_rest_vol = charger->rest_vol; axp_read(charger->master, AXP81X_CAP,&val); charger->rest_vol = val & 0x7f; if(charger->rest_vol - pre_rest_vol){ printk("battery vol change: %d->%d \n", pre_rest_vol, charger->rest_vol); pre_rest_vol = charger->rest_vol; axp_write(charger->master,AXP81X_DATA_BUFFER1,charger->rest_vol | 0x80); } #if defined (CONFIG_AXP_CHGCHANGE) if(axp81x_config.pmu_runtime_chgcur == 0) axp_clr_bits(charger->master,AXP81X_CHARGE_CONTROL1,0x80); else axp_set_bits(charger->master,AXP81X_CHARGE_CONTROL1,0x80); printk("pmu_runtime_chgcur = %d\n", axp81x_config.pmu_runtime_chgcur); if(axp81x_config.pmu_runtime_chgcur >= 300000 && axp81x_config.pmu_runtime_chgcur <= 2550000){ tmp = (axp81x_config.pmu_runtime_chgcur -200001)/150000; charger->chgcur = tmp *150000 + 300000; axp_update(charger->master, AXP81X_CHARGE_CONTROL1, tmp,0x0F); }else if(axp81x_config.pmu_runtime_chgcur < 300000){ axp_clr_bits(axp_charger->master, AXP81X_CHARGE_CONTROL1,0x0F); }else{ axp_set_bits(axp_charger->master, AXP81X_CHARGE_CONTROL1,0x0F); } #endif charger->disvbat = 0; charger->disibat = 0; axp_charger_update_state(charger); axp_charger_update(charger, &axp81x_config); power_supply_changed(&charger->batt); power_supply_changed(&charger->ac); power_supply_changed(&charger->usb); schedule_delayed_work(&charger->work, charger->interval); return 0; }
static int axp81x_suspend(struct platform_device *dev, pm_message_t state) { uint8_t tmp, ret; struct axp_charger *charger = platform_get_drvdata(dev); ret = axp_disable_irq(charger); if (ret < 0) return ret; cancel_delayed_work_sync(&charger->work); #if defined (CONFIG_AXP_CHGCHANGE) if(axp81x_config.pmu_suspend_chgcur == 0) axp_clr_bits(charger->master,AXP81X_CHARGE_CONTROL1,0x80); else axp_set_bits(charger->master,AXP81X_CHARGE_CONTROL1,0x80); printk("pmu_suspend_chgcur = %d\n", axp81x_config.pmu_suspend_chgcur); if(axp81x_config.pmu_suspend_chgcur >= 300000 && axp81x_config.pmu_suspend_chgcur <= 2550000){ tmp = (axp81x_config.pmu_suspend_chgcur -200001)/150000; charger->chgcur = tmp *150000 + 300000; axp_update(charger->master, AXP81X_CHARGE_CONTROL1, tmp,0x0F); } #endif return 0; }
int axp81x_chg_current_limit(int current_limit) { uint8_t tmp = 0; #if defined (CONFIG_AXP_CHGCHANGE) if(current_limit == 0) axp_clr_bits(axp_charger->master,AXP81X_CHARGE_CONTROL1,0x80); else axp_set_bits(axp_charger->master,AXP81X_CHARGE_CONTROL1,0x80); DBG_PSY_MSG(DEBUG_SPLY, "current_limit = %d\n", current_limit); if(current_limit >= AXP81X_CHARGE_CURRENT_MIN && current_limit <= AXP81X_CHARGE_CURRENT_MAX){ tmp = (current_limit -AXP81X_CHARGE_CURRENT_STEP)/AXP81X_CHARGE_CURRENT_STEP; spin_lock(&axp_charger->charger_lock); axp_charger->chgcur = tmp *AXP81X_CHARGE_CURRENT_STEP + AXP81X_CHARGE_CURRENT_MIN; spin_unlock(&axp_charger->charger_lock); axp_update(axp_charger->master, AXP81X_CHARGE_CONTROL1, tmp,0x0F); }else if(current_limit < AXP81X_CHARGE_CURRENT_MIN){ axp_clr_bits(axp_charger->master, AXP81X_CHARGE_CONTROL1,0x0F); }else{ axp_set_bits(axp_charger->master, AXP81X_CHARGE_CONTROL1,0x0F); } #endif return 0; }
static int axp_set_aldo12_voltage(struct regulator_dev *rdev, int min_uV, int max_uV) { struct axp_regulator_info *info = rdev_get_drvdata(rdev); struct device *axp_dev = to_axp_dev(rdev); uint8_t val, mask; int i; if (check_range(info, min_uV, max_uV)) { pr_err("invalid voltage range (%d, %d) uV\n", min_uV, max_uV); return -EINVAL; } for(i = 0,val = 0; i < sizeof(axp15_aldo12_data);i++){ if(min_uV <= axp15_aldo12_data[i] * 1000){ val = i; break; } } val <<= info->vol_shift; mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; return axp_update(axp_dev, info->vol_reg, val, mask); }
static void axp_power_off(void) { uint8_t val; preempt_count() = 0; #if defined (CONFIG_AW_AXP18) axp_set_bits(&axp->dev, POWER18_ONOFF, 0x80); #endif #if defined (CONFIG_AW_AXP19) axp_set_bits(&axp->dev, POWER19_OFF_CTL, 0x80); #endif #if defined (CONFIG_AW_AXP20) if(pmu_pwroff_vol >= 2600 && pmu_pwroff_vol <= 3300){ if (pmu_pwroff_vol > 3200){ val = 0x7; } else if (pmu_pwroff_vol > 3100){ val = 0x6; } else if (pmu_pwroff_vol > 3000){ val = 0x5; } else if (pmu_pwroff_vol > 2900){ val = 0x4; } else if (pmu_pwroff_vol > 2800){ val = 0x3; } else if (pmu_pwroff_vol > 2700){ val = 0x2; } else if (pmu_pwroff_vol > 2600){ val = 0x1; } else val = 0x0; axp_update(&axp->dev, POWER20_VOFF_SET, val, 0x7); } val = 0xff; axp_read(&axp->dev, POWER20_COULOMB_CTL, &val); val &= 0x3f; axp_write(&axp->dev, POWER20_COULOMB_CTL, val); val |= 0x80; val &= 0xbf; axp_write(&axp->dev, POWER20_COULOMB_CTL, val); //led auto axp_clr_bits(&axp->dev,0x32,0x38); axp_clr_bits(&axp->dev,0xb9,0x80); printk("[axp] send power-off command!\n"); mdelay(20); if(power_start != 1){ axp_read(&axp->dev, POWER20_STATUS, &val); if(val & 0xF0){ axp_read(&axp->dev, POWER20_MODE_CHGSTATUS, &val); if(val & 0x20){ printk("[axp] set flag!\n"); axp_write(&axp->dev, POWER20_DATA_BUFFERC, 0x0f); mdelay(20); printk("[axp] reboot!\n"); machine_restart(NULL); printk("[axp] warning!!! arch can't ,reboot, maybe some error happend!\n"); } } } axp_write(&axp->dev, POWER20_DATA_BUFFERC, 0x00); mdelay(20); axp_set_bits(&axp->dev, POWER20_OFF_CTL, 0x80); mdelay(20); printk("[axp] warning!!! axp can't power-off, maybe some error happend!\n"); #endif }
static ssize_t workmode_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct regulator_dev *rdev = dev_get_drvdata(dev); struct axp_regulator_info *info = rdev_get_drvdata(rdev); struct device *axp_dev = to_axp_dev(rdev); char mode; uint8_t val; if( buf[0] > '0' && buf[0] < '9' )// 1/AUTO: auto mode; 2/PWM: pwm mode; mode = buf[0]; else mode = buf[1]; switch(mode) { case 'U': case 'u': case '1': val = 0; break; case 'W': case 'w': case '2': val = 1; break; case 'F': case 'f': case '4': val = 2; break; default: val = 3; break; } if(info->desc.id == AXP18_ID_BUCK1) { if(val == 0) axp_clr_bits(axp_dev, AXP18_BUCKMODE,0x80); else if(val == 1) axp_update(axp_dev, AXP18_BUCKMODE,0x80,0x84); else if(val == 2) axp_update(axp_dev,AXP18_BUCKMODE,0x84,0x84); else return -EINVAL; } else if(info->desc.id == AXP18_ID_BUCK2) { if(val == 0) axp_clr_bits(axp_dev, AXP19_BUCKMODE,0x40); else if(val == 1) axp_update(axp_dev, AXP18_BUCKMODE,0x40,0x42); else if(val == 2) axp_update(axp_dev,AXP18_BUCKMODE,0x42,0x42); else return -EINVAL; } else if(info->desc.id == AXP18_ID_BUCK3) { if(val == 0) axp_clr_bits(axp_dev, AXP18_BUCKMODE,0x20); else if(val == 1) axp_update(axp_dev, AXP19_BUCKMODE,0x20,0x21); else if(val == 2) axp_update(axp_dev, AXP19_BUCKMODE,0x21,0x21); else return -EINVAL; } else return -ENXIO; return count; }
static void axp_usb(struct work_struct *work) { int var; uint8_t tmp,val; DBG_PSY_MSG(DEBUG_CHG, "[axp_usb]axp_usbcurflag = %d\n",axp_usbcurflag); axp_read(axp_charger->master, AXP_CHARGE_STATUS, &val); if ((val & 0x02)) { /* usb and ac in short*/ if((val & 0x10) == 0x00){/*usb or usb adapter can not be used*/ DBG_PSY_MSG(DEBUG_CHG, "USB not insert!\n"); tmp = 0x10; axp_update(axp_charger->master, AXP_CHARGE_CONTROL3, tmp,0xf0); }else if(CHARGE_USB_20 == axp_usbcurflag){ DBG_PSY_MSG(DEBUG_CHG, "set usbcur_pc %d mA\n",axp_config->pmu_usbcur_pc); if(axp_config->pmu_usbcur_pc){ var = axp_config->pmu_usbcur_pc; if(var < 500) { tmp = 0x00; /* 100mA */ axp_update(axp_charger->master, AXP_CHARGE_CONTROL3, tmp,0xf0); } else if (var < 900) { tmp = 0x10; /* 500mA */ axp_update(axp_charger->master, AXP_CHARGE_CONTROL3, tmp,0xf0); } else if (var < 1500) { tmp = 0x20; /* 900mA */ axp_update(axp_charger->master, AXP_CHARGE_CONTROL3, tmp,0xf0); } else if (var < 2000) { tmp = 0x30; /* 1500mA */ axp_update(axp_charger->master, AXP_CHARGE_CONTROL3, tmp,0xf0); } else if (var < 2500) { tmp = 0x40; /* 2000mA */ axp_update(axp_charger->master, AXP_CHARGE_CONTROL3, tmp,0xf0); } else if (var < 3000) { tmp = 0x50; /* 2500mA */ axp_update(axp_charger->master, AXP_CHARGE_CONTROL3, tmp,0xf0); } else if (var < 3500) { tmp = 0x60; /* 3000mA */ axp_update(axp_charger->master, AXP_CHARGE_CONTROL3, tmp,0xf0); } else if (var < 3500) { tmp = 0x70; /* 3500mA */ axp_update(axp_charger->master, AXP_CHARGE_CONTROL3, tmp,0xf0); } else { tmp = 0x80; /* 4000mA */ axp_update(axp_charger->master, AXP_CHARGE_CONTROL3, tmp,0xf0); } } else { tmp = 0x10; /* 500mA */ axp_update(axp_charger->master, AXP_CHARGE_CONTROL3, tmp,0xf0); } }else if (CHARGE_USB_30 == axp_usbcurflag){ tmp = 0x20; /* 900mA */ axp_update(axp_charger->master, AXP_CHARGE_CONTROL3, tmp,0xf0); }else { DBG_PSY_MSG(DEBUG_CHG, "set usbcur %d mA\n",axp_config->pmu_usbcur); if((axp_config->pmu_usbcur) && (axp_config->pmu_usbcur_limit)){ var = axp_config->pmu_usbcur; if(var < 500) { tmp = 0x00; /* 100mA */ axp_update(axp_charger->master, AXP_CHARGE_CONTROL3, tmp,0xf0); } else if (var < 900) { tmp = 0x10; /* 500mA */ axp_update(axp_charger->master, AXP_CHARGE_CONTROL3, tmp,0xf0); } else if (var < 1500) { tmp = 0x20; /* 900mA */ axp_update(axp_charger->master, AXP_CHARGE_CONTROL3, tmp,0xf0); } else if (var < 2000) { tmp = 0x30; /* 1500mA */ axp_update(axp_charger->master, AXP_CHARGE_CONTROL3, tmp,0xf0); } else if (var < 2500) { tmp = 0x40; /* 2000mA */ axp_update(axp_charger->master, AXP_CHARGE_CONTROL3, tmp,0xf0); } else if (var < 3000) { tmp = 0x50; /* 2500mA */ axp_update(axp_charger->master, AXP_CHARGE_CONTROL3, tmp,0xf0); } else if (var < 3500) { tmp = 0x60; /* 3000mA */ axp_update(axp_charger->master, AXP_CHARGE_CONTROL3, tmp,0xf0); } else if (var < 4000) { tmp = 0x70; /* 3500mA */ axp_update(axp_charger->master, AXP_CHARGE_CONTROL3, tmp,0xf0); } else { tmp = 0x80; /* 4000mA */ axp_update(axp_charger->master, AXP_CHARGE_CONTROL3, tmp,0xf0); } } else { tmp = 0x50; /* 2500mA */ DBG_PSY_MSG(DEBUG_CHG, "%s: %d,set usbcur 2500 mA\n",__func__, __LINE__); axp_update(axp_charger->master, AXP_CHARGE_CONTROL3, tmp,0xf0); } } if(!vbus_curr_limit_debug){ //usb current not limit DBG_PSY_MSG(DEBUG_CHG, "vbus_curr_limit_debug = %d\n",vbus_curr_limit_debug); tmp = 0x50; /* 2500mA */ axp_update(axp_charger->master, AXP_CHARGE_CONTROL3, tmp,0xf0); } if(CHARGE_USB_20 == axp_usbvolflag){ DBG_PSY_MSG(DEBUG_CHG, "set usbvol_pc %d mV\n",axp_config->pmu_usbvol_pc); if(axp_config->pmu_usbvol_pc){ var = axp_config->pmu_usbvol_pc * 1000; if(var >= 4000000 && var <=4700000){ tmp = (var - 4000000)/100000; val = tmp << 3; axp_update(axp_charger->master, AXP_CHARGE_VBUS, val,0x38); }else DBG_PSY_MSG(DEBUG_CHG, "set usb limit voltage error,%d mV\n",axp_config->pmu_usbvol_pc); } }else if(CHARGE_USB_30 == axp_usbvolflag) { val = 7 << 3; axp_update(axp_charger->master, AXP_CHARGE_VBUS, val,0x38); }else { DBG_PSY_MSG(DEBUG_CHG, "set usbvol %d mV\n",axp_config->pmu_usbvol); if((axp_config->pmu_usbvol) && (axp_config->pmu_usbvol_limit)){ var = axp_config->pmu_usbvol * 1000; if(var >= 4000000 && var <=4700000){ tmp = (var - 4000000)/100000; val = tmp << 3; axp_update(axp_charger->master, AXP_CHARGE_VBUS, val,0x38); }else DBG_PSY_MSG(DEBUG_CHG, "set usb limit voltage error,%d mV\n",axp_config->pmu_usbvol); } } }else { if((val & 0x50) == 0x00){/*usb and ac can not be used*/ DBG_PSY_MSG(DEBUG_CHG, "USB not insert!\n"); tmp = 0x10; /* 500mA */ axp_update(axp_charger->master, AXP_CHARGE_CONTROL3, tmp,0xf0); tmp = 0x0; /* 1500mA */ axp_update(axp_charger->master, AXP_CHARGE_AC, tmp,0x07); }else if(CHARGE_USB_20 == axp_usbcurflag){ DBG_PSY_MSG(DEBUG_CHG, "set usbcur_pc %d mA\n",axp_config->pmu_usbcur_pc); if(axp_config->pmu_usbcur_pc){ var = axp_config->pmu_usbcur_pc; if(var < 500) { tmp = 0x00; /* 100mA */ axp_update(axp_charger->master, AXP_CHARGE_CONTROL3, tmp,0xf0); } else if (var < 900) { tmp = 0x10; /* 500mA */ axp_update(axp_charger->master, AXP_CHARGE_CONTROL3, tmp,0xf0); } else if (var < 1500) { tmp = 0x20; /* 900mA */ axp_update(axp_charger->master, AXP_CHARGE_CONTROL3, tmp,0xf0); } else if (var < 2000) { tmp = 0x30; /* 1500mA */ axp_update(axp_charger->master, AXP_CHARGE_CONTROL3, tmp,0xf0); } else if (var < 2500) { tmp = 0x40; /* 2000mA */ axp_update(axp_charger->master, AXP_CHARGE_CONTROL3, tmp,0xf0); } else if (var < 3000) { tmp = 0x50; /* 2500mA */ axp_update(axp_charger->master, AXP_CHARGE_CONTROL3, tmp,0xf0); } else if (var < 3500) { tmp = 0x60; /* 3000mA */ axp_update(axp_charger->master, AXP_CHARGE_CONTROL3, tmp,0xf0); } else if (var < 4000) { tmp = 0x70; /* 3500mA */ axp_update(axp_charger->master, AXP_CHARGE_CONTROL3, tmp,0xf0); } else { tmp = 0x80; /* 4000mA */ axp_update(axp_charger->master, AXP_CHARGE_CONTROL3, tmp,0xf0); } } else { tmp = 0x10; /* 500mA */ axp_update(axp_charger->master, AXP_CHARGE_CONTROL3, tmp,0xf0); } }else if (CHARGE_USB_30 == axp_usbcurflag){ tmp = 0x20; /* 900mA */ axp_update(axp_charger->master, AXP_CHARGE_CONTROL3, tmp,0xf0); }else { DBG_PSY_MSG(DEBUG_CHG, "set usbcur %d mA\n",axp_config->pmu_usbcur); if((axp_config->pmu_usbcur) && (axp_config->pmu_usbcur_limit)){ var = axp_config->pmu_usbcur; if (var < 2000) { tmp = 0x01; /* 1500mA */ axp_update(axp_charger->master, AXP_CHARGE_AC, tmp,0x07); } else if (var < 2500) { tmp = 0x02; /* 2000mA */ axp_update(axp_charger->master, AXP_CHARGE_AC, tmp,0x07); } else if (var < 3000) { tmp = 0x03; /* 2500mA */ axp_update(axp_charger->master, AXP_CHARGE_AC, tmp,0x07); } else if (var < 3500) { tmp = 0x04; /* 3000mA */ axp_update(axp_charger->master, AXP_CHARGE_AC, tmp,0x07); } else if (var < 3500) { tmp = 0x05; /* 3500mA */ axp_update(axp_charger->master, AXP_CHARGE_AC, tmp,0x07); } else { tmp = 0x06; /* 4000mA */ axp_update(axp_charger->master, AXP_CHARGE_AC, tmp,0x07); } } else { tmp = 0x05; /* 4000mA */ axp_update(axp_charger->master, AXP_CHARGE_AC, tmp,0x07); } } if(!vbus_curr_limit_debug){ //usb current not limit DBG_PSY_MSG(DEBUG_CHG, "vbus_curr_limit_debug = %d\n",vbus_curr_limit_debug); tmp = 0x03; /* 2500mA */ axp_update(axp_charger->master, AXP_CHARGE_AC, tmp,0xf0); } if(CHARGE_USB_20 == axp_usbvolflag){ DBG_PSY_MSG(DEBUG_CHG, "set usbvol_pc %d mV\n",axp_config->pmu_usbvol_pc); if(axp_config->pmu_usbvol_pc){ var = axp_config->pmu_usbvol_pc * 1000; if(var >= 4000000 && var <=4700000){ tmp = (var - 4000000)/100000; val = tmp << 3; axp_update(axp_charger->master, AXP_CHARGE_VBUS, val,0x38); }else DBG_PSY_MSG(DEBUG_CHG, "set usb limit voltage error,%d mV\n",axp_config->pmu_usbvol_pc); } }else if(CHARGE_USB_30 == axp_usbvolflag) { val |= 7 << 3; axp_update(axp_charger->master, AXP_CHARGE_VBUS, val,0x38); }else { DBG_PSY_MSG(DEBUG_CHG, "set usbvol %d mV\n",axp_config->pmu_usbvol); if((axp_config->pmu_usbvol) && (axp_config->pmu_usbvol_limit)){ var = axp_config->pmu_usbvol * 1000; if(var >= 4000000 && var <=4700000){ tmp = (var - 4000000)/100000; val = tmp << 3; axp_update(axp_charger->master, AXP_CHARGE_AC, val,0x38); }else DBG_PSY_MSG(DEBUG_CHG, "set usb limit voltage error,%d mV\n",axp_config->pmu_usbvol); } } } }
void axp20_power_off(int power_start) { uint8_t val; struct axp_dev *axp; axp = axp_dev_lookup(AXP20); if (NULL == axp) { printk("%s: axp data is null\n", __func__); return; } if(axp20_config.pmu_pwroff_vol >= 2600 && axp20_config.pmu_pwroff_vol <= 3300){ if (axp20_config.pmu_pwroff_vol > 3200){ val = 0x7; } else if (axp20_config.pmu_pwroff_vol > 3100){ val = 0x6; } else if (axp20_config.pmu_pwroff_vol > 3000){ val = 0x5; } else if (axp20_config.pmu_pwroff_vol > 2900){ val = 0x4; } else if (axp20_config.pmu_pwroff_vol > 2800){ val = 0x3; } else if (axp20_config.pmu_pwroff_vol > 2700){ val = 0x2; } else if (axp20_config.pmu_pwroff_vol > 2600){ val = 0x1; } else val = 0x0; axp_update(axp->dev, POWER20_VOFF_SET, val, 0x7); } val = 0xff; if (!use_cou){ axp_read(axp->dev, POWER20_COULOMB_CTL, &val); val &= 0x3f; axp_write(axp->dev, POWER20_COULOMB_CTL, val); val |= 0x80; val &= 0xbf; axp_write(axp->dev, POWER20_COULOMB_CTL, val); } //led auto axp_clr_bits(axp->dev,0x32,0x38); axp_clr_bits(axp->dev,0xb9,0x80); printk("[axp] send power-off command!\n"); mdelay(20); if(axp20_config.power_start != 1){ axp_write(axp->dev, POWER20_INTSTS3, 0x03); axp_read(axp->dev, POWER20_STATUS, &val); if(val & 0xF0){ axp_read(axp->dev, POWER20_MODE_CHGSTATUS, &val); if(val & 0x20){ printk("[axp] set flag!\n"); axp_write(axp->dev, POWER20_DATA_BUFFERC, 0x0f); mdelay(20); printk("[axp] reboot!\n"); machine_restart(NULL); printk("[axp] warning!!! arch can't ,reboot, maybe some error happend!\n"); } } } axp_write(axp->dev, POWER20_DATA_BUFFERC, 0x00); //axp_write(&axp->dev, 0xf4, 0x06); //axp_write(&axp->dev, 0xf2, 0x04); //axp_write(&axp->dev, 0xff, 0x01); //axp_write(&axp->dev, 0x04, 0x01); //axp_clr_bits(&axp->dev, 0x03, 0xc0); //axp_write(&axp->dev, 0xff, 0x00); //mdelay(20); axp_set_bits(axp->dev, POWER20_OFF_CTL, 0x80); mdelay(20); printk("[axp] warning!!! axp can't power-off, maybe some error happend!\n"); }
s32 axp81x_usb_ac_current_limit(struct axp_charger *charger, aw_charge_type port_type, u32 current_limit) { u8 tmp = 0; if( (CHARGE_USB_20 == port_type) || (CHARGE_USB_30 == port_type)) { if(current_limit < 500) { tmp = 0x00; /* 100mA */ axp_update(axp_charger->master, AXP81X_CHARGE_CONTROL3, tmp,0xf0); } else if (current_limit < 900) { tmp = 0x10; /* 500mA */ axp_update(axp_charger->master, AXP81X_CHARGE_CONTROL3, tmp,0xf0); } else if (current_limit < 1500) { tmp = 0x20; /* 900mA */ axp_update(axp_charger->master, AXP81X_CHARGE_CONTROL3, tmp,0xf0); } else if (current_limit < 2000) { tmp = 0x30; /* 1500mA */ axp_update(axp_charger->master, AXP81X_CHARGE_CONTROL3, tmp,0xf0); } else if (current_limit < 2500) { tmp = 0x40; /* 2000mA */ axp_update(axp_charger->master, AXP81X_CHARGE_CONTROL3, tmp,0xf0); } else if (current_limit < 3000) { tmp = 0x50; /* 2500mA */ axp_update(axp_charger->master, AXP81X_CHARGE_CONTROL3, tmp,0xf0); } else if (current_limit < 3500) { tmp = 0x60; /* 3000mA */ axp_update(axp_charger->master, AXP81X_CHARGE_CONTROL3, tmp,0xf0); } else if (current_limit < 4000) { tmp = 0x70; /* 3500mA */ axp_update(axp_charger->master, AXP81X_CHARGE_CONTROL3, tmp,0xf0); } else { tmp = 0x80; /* 4000mA */ axp_update(axp_charger->master, AXP81X_CHARGE_CONTROL3, tmp,0xf0); } }else if (CHARGE_AC == port_type) { #ifdef BPI-M3 #else current_limit =4000; #endif if (current_limit < 2000) { tmp = 0x00; /* 1500mA */ axp_update(axp_charger->master, AXP81X_CHARGE_AC, tmp,0x07); } else if (current_limit < 2500) { tmp = 0x01; /* 2000mA */ axp_update(axp_charger->master, AXP81X_CHARGE_AC, tmp,0x07); } else if (current_limit < 3000) { tmp = 0x02; /* 2500mA */ axp_update(axp_charger->master, AXP81X_CHARGE_AC, tmp,0x07); } else if (current_limit < 3500) { tmp = 0x03; /* 3000mA */ axp_update(axp_charger->master, AXP81X_CHARGE_AC, tmp,0x07); } else if (current_limit < 4000) { tmp = 0x04; /* 3500mA */ axp_update(axp_charger->master, AXP81X_CHARGE_AC, tmp,0x07); } else { tmp = 0x05; /* 4000mA */ axp_update(axp_charger->master, AXP81X_CHARGE_AC, tmp,0x07); } } else return -1; return 0; }
int axp81x_init(struct axp_charger *charger) { int ret = 0, var = 0; uint8_t val = 0; uint8_t ocv_cap[63]; int Cur_CoulombCounter,rdc; ret = axp_battery_first_init(charger); if (ret) goto err_charger_init; /* usb /ac voltage limit */ if(axp81x_config.pmu_usbvol){ axp81x_usb_ac_vol_limit(charger, CHARGE_AC, axp81x_config.pmu_usbvol); } if(axp81x_config.pmu_usbvol_pc){ axp81x_usb_ac_vol_limit(charger, CHARGE_USB_20, axp81x_config.pmu_usbvol_pc); } /* ac current limit */ if(axp81x_config.pmu_usbcur){ axp81x_usb_ac_current_limit(charger, CHARGE_AC, axp81x_config.pmu_usbcur); } else { #ifdef BPI-M3 axp81x_usb_ac_current_limit(charger, CHARGE_AC, 2500); #else axp81x_usb_ac_current_limit(charger, CHARGE_AC, 4000); #endif } #ifdef BPI-M3 #else printk("BPI-M3: set PMIC AC 4000mA\n"); axp81x_usb_ac_current_limit(charger, CHARGE_AC, 4000); #endif axp81x_chg_current_limit(axp81x_config.pmu_runtime_chgcur); /* set lowe power warning/shutdown level */ axp_write(charger->master, AXP81X_WARNING_LEVEL,((axp81x_config.pmu_battery_warning_level1-5) << 4)+axp81x_config.pmu_battery_warning_level2); ocv_cap[0] = axp81x_config.pmu_bat_para1; ocv_cap[1] = 0xC1; ocv_cap[2] = axp81x_config.pmu_bat_para2; ocv_cap[3] = 0xC2; ocv_cap[4] = axp81x_config.pmu_bat_para3; ocv_cap[5] = 0xC3; ocv_cap[6] = axp81x_config.pmu_bat_para4; ocv_cap[7] = 0xC4; ocv_cap[8] = axp81x_config.pmu_bat_para5; ocv_cap[9] = 0xC5; ocv_cap[10] = axp81x_config.pmu_bat_para6; ocv_cap[11] = 0xC6; ocv_cap[12] = axp81x_config.pmu_bat_para7; ocv_cap[13] = 0xC7; ocv_cap[14] = axp81x_config.pmu_bat_para8; ocv_cap[15] = 0xC8; ocv_cap[16] = axp81x_config.pmu_bat_para9; ocv_cap[17] = 0xC9; ocv_cap[18] = axp81x_config.pmu_bat_para10; ocv_cap[19] = 0xCA; ocv_cap[20] = axp81x_config.pmu_bat_para11; ocv_cap[21] = 0xCB; ocv_cap[22] = axp81x_config.pmu_bat_para12; ocv_cap[23] = 0xCC; ocv_cap[24] = axp81x_config.pmu_bat_para13; ocv_cap[25] = 0xCD; ocv_cap[26] = axp81x_config.pmu_bat_para14; ocv_cap[27] = 0xCE; ocv_cap[28] = axp81x_config.pmu_bat_para15; ocv_cap[29] = 0xCF; ocv_cap[30] = axp81x_config.pmu_bat_para16; ocv_cap[31] = 0xD0; ocv_cap[32] = axp81x_config.pmu_bat_para17; ocv_cap[33] = 0xD1; ocv_cap[34] = axp81x_config.pmu_bat_para18; ocv_cap[35] = 0xD2; ocv_cap[36] = axp81x_config.pmu_bat_para19; ocv_cap[37] = 0xD3; ocv_cap[38] = axp81x_config.pmu_bat_para20; ocv_cap[39] = 0xD4; ocv_cap[40] = axp81x_config.pmu_bat_para21; ocv_cap[41] = 0xD5; ocv_cap[42] = axp81x_config.pmu_bat_para22; ocv_cap[43] = 0xD6; ocv_cap[44] = axp81x_config.pmu_bat_para23; ocv_cap[45] = 0xD7; ocv_cap[46] = axp81x_config.pmu_bat_para24; ocv_cap[47] = 0xD8; ocv_cap[48] = axp81x_config.pmu_bat_para25; ocv_cap[49] = 0xD9; ocv_cap[50] = axp81x_config.pmu_bat_para26; ocv_cap[51] = 0xDA; ocv_cap[52] = axp81x_config.pmu_bat_para27; ocv_cap[53] = 0xDB; ocv_cap[54] = axp81x_config.pmu_bat_para28; ocv_cap[55] = 0xDC; ocv_cap[56] = axp81x_config.pmu_bat_para29; ocv_cap[57] = 0xDD; ocv_cap[58] = axp81x_config.pmu_bat_para30; ocv_cap[59] = 0xDE; ocv_cap[60] = axp81x_config.pmu_bat_para31; ocv_cap[61] = 0xDF; ocv_cap[62] = axp81x_config.pmu_bat_para32; axp_writes(charger->master, 0xC0,63,ocv_cap); /* pok open time set */ if(axp81x_config.pmu_pekon_time < 1000) val = 0x00; else if(axp81x_config.pmu_pekon_time < 2000){ val = 0x40; }else if(axp81x_config.pmu_pekon_time < 3000){ val = 0x80; }else { val = 0xc0; } axp_update(charger->master, AXP81X_POK_SET, val, 0xc0); var = axp81x_config.pmu_peklong_time; /* pok long time set*/ if(axp81x_config.pmu_peklong_time < 1000) var = 1000; if(axp81x_config.pmu_peklong_time > 2500) var = 2500; val = (((var - 1000) / 500) << 4); axp_update(charger->master, AXP81X_POK_SET, val, 0x30); /* pek offlevel poweroff en set*/ if(axp81x_config.pmu_pekoff_en) var = 1; else var = 0; val = (var << 3); axp_update(charger->master, AXP81X_POK_SET, val, 0x8); /*Init offlevel restart or not */ if(axp81x_config.pmu_pekoff_func) axp_set_bits(charger->master,AXP81X_POK_SET,0x04); //restart else axp_clr_bits(charger->master,AXP81X_POK_SET,0x04); //not restart if(10 > axp81x_config.pmu_pekoff_delay_time) val = 0x00; else if(20 > axp81x_config.pmu_pekoff_delay_time) val = 0x01; else if(30 > axp81x_config.pmu_pekoff_delay_time) val = 0x02; else if(40 > axp81x_config.pmu_pekoff_delay_time) val = 0x03; else if(50 > axp81x_config.pmu_pekoff_delay_time) val = 0x04; else if(60 > axp81x_config.pmu_pekoff_delay_time) val = 0x05; else if(70 > axp81x_config.pmu_pekoff_delay_time) val = 0x06; else val = 0x07; axp_write(charger->master,AXP81X_POK_DELAY_SET,val); /* pek delay set */ if (axp81x_config.pmu_pwrok_time < 32) val = ((axp81x_config.pmu_pwrok_time / 8) - 1); else val = ((axp81x_config.pmu_pwrok_time / 32) + 1); axp_update(charger->master, AXP81X_OFF_CTL, val, 0x3); //axp_read(charger->master,AXP81X_DCDC_MONITOR,&val); //if(axp81x_config.pmu_pwrok_shutdown_en) // val |= 0x40; //axp_write(charger->master,AXP81X_DCDC_MONITOR,val); if(axp81x_config.pmu_reset_shutdown_en) axp_set_bits(charger->master,AXP81X_HOTOVER_CTL,0x01); //restart shutdown ldo/dcdc /* pek offlevel time set */ if(axp81x_config.pmu_pekoff_time < 4000) var = 4000; if(axp81x_config.pmu_pekoff_time > 10000) var =10000; var = (axp81x_config.pmu_pekoff_time - 4000) / 2000 ; val = var ; axp_update(charger->master, AXP81X_POK_SET, val, 0x3); /*Init 16's Reset PMU en */ if(axp81x_config.pmu_reset) axp_set_bits(charger->master,0x8F,0x08); //enable else axp_clr_bits(charger->master,0x8F,0x08); //disable /*Init IRQ wakeup en*/ if(axp81x_config.pmu_IRQ_wakeup) axp_set_bits(charger->master,0x8F,0x80); //enable else axp_clr_bits(charger->master,0x8F,0x80); //disable /*Init N_VBUSEN status*/ if(axp81x_config.pmu_vbusen_func) axp_set_bits(charger->master,0x8F,0x10); //output else axp_clr_bits(charger->master,0x8F,0x10); //input /*Init InShort status*/ if(axp81x_config.pmu_inshort) axp_set_bits(charger->master,0x8F,0x60); //InShort else axp_clr_bits(charger->master,0x8F,0x60); //auto detect /*Init CHGLED function*/ if(axp81x_config.pmu_chgled_func) axp_set_bits(charger->master,0x32,0x08); //control by charger else axp_clr_bits(charger->master,0x32,0x08); //drive MOTO /*set CHGLED Indication Type*/ if(axp81x_config.pmu_chgled_type) axp_set_bits(charger->master,0x34,0x10); //Type B else axp_clr_bits(charger->master,0x34,0x10); //Type A /*Init PMU Over Temperature protection*/ if(axp81x_config.pmu_hot_shutdowm) axp_set_bits(charger->master,0x8f,0x04); //enable else axp_clr_bits(charger->master,0x8f,0x04); //disable /*Init battery capacity correct function*/ if(axp81x_config.pmu_batt_cap_correct) axp_set_bits(charger->master,0xb8,0x20); //enable else axp_clr_bits(charger->master,0xb8,0x20); //disable /* Init battery regulator enable or not when charge finish*/ if(axp81x_config.pmu_bat_regu_en) axp_set_bits(charger->master,0x34,0x20); //enable else axp_clr_bits(charger->master,0x34,0x20); //disable if(!axp81x_config.pmu_batdeten) axp_clr_bits(charger->master,AXP81X_PDBC,0x40); else axp_set_bits(charger->master,AXP81X_PDBC,0x40); /* RDC initial */ axp_read(charger->master, AXP81X_RDC0,&val); if((axp81x_config.pmu_battery_rdc) && (!(val & 0x40))){ rdc = (axp81x_config.pmu_battery_rdc * 10000 + 5371) / 10742; axp_write(charger->master, AXP81X_RDC0, ((rdc >> 8) & 0x1F)|0x80); axp_write(charger->master,AXP81X_RDC1,rdc & 0x00FF); }