static int pmic_get_charger_coulomb(int *coulomb) { int ret; unsigned int value; int calibration; unsigned int time_diff_msec; ret = pmic_read_reg(REG_ACC0, &value, BITFMASK(ACC_CCOUT)); if (ret != 0) return -1; value = BITFEXT(value, ACC_CCOUT); pr_debug("counter value = %x\n", value); *coulomb = ((s16)((u16)value)) * ACC_COULOMB_PER_LSB; if (abs(*coulomb) >= ACC_COULOMB_PER_LSB) { /* calibrate */ time_diff_msec = jiffies_to_msecs(jiffies); time_diff_msec = (time_diff_msec > coulomb_counter_start_time_msecs) ? (time_diff_msec - coulomb_counter_start_time_msecs) : (0xffffffff - coulomb_counter_start_time_msecs + time_diff_msec); calibration = coulomb_counter_calibration * (int)time_diff_msec / (ACC_ONEC_VALUE * ACC_CALIBRATION_DURATION_MSECS); *coulomb -= calibration; } return 0; }
static int pmic_calibrate_coulomb_counter(void) { int ret; unsigned int value; /* set scaler */ CHECK_ERROR(pmic_write_reg(REG_ACC1, 0x1, BITFMASK(ACC1_ONEC))); CHECK_ERROR(pmic_write_reg( REG_ACC0, ACC_CALIBRATION, ACC_CONTROL_BIT_MASK)); msleep(ACC_CALIBRATION_DURATION_MSECS); ret = pmic_read_reg(REG_ACC0, &value, BITFMASK(ACC_CCOUT)); if (ret != 0) return -1; value = BITFEXT(value, ACC_CCOUT); pr_debug("calibrate value = %x\n", value); coulomb_counter_calibration = (int)((s16)((u16) value)); pr_debug("coulomb_counter_calibration = %d\n", coulomb_counter_calibration); return 0; }
static int mc34708_vdac_get_voltage(struct regulator_dev *reg) { unsigned int register_val = 0; int voltage = 0, mV = 0; CHECK_ERROR(pmic_read_reg(MC34708_REG_REGULATOR_SETTING0, ®ister_val, PMIC_ALL_BITS)); voltage = BITFEXT(register_val, VDAC); switch (voltage) { case VDAC_2_5V: mV = 2500; break; case VDAC_2_6V: mV = 2600; break; case VDAC_2_7V: mV = 2700; break; case VDAC_2_775V: mV = 2775; break; default: return -EINVAL; } return mV * 1000; }
static int mc34708_vpll_get_voltage(struct regulator_dev *reg) { unsigned int register_val = 0; int voltage = 0, mV = 0; CHECK_ERROR(pmic_read_reg(MC34708_REG_REGULATOR_SETTING0, ®ister_val, PMIC_ALL_BITS)); voltage = BITFEXT(register_val, VPLL); switch (voltage) { case VPLL_1_2V: mV = 1200; break; case VPLL_1_25V: mV = 1250; break; case VPLL_1_5V: mV = 1500; break; case VPLL_1_8V: mV = 1800; break; default: return -EINVAL; } return mV * 1000; }
/*! * This function is used to retrive the charger setting. * * @param chgr Charger as defined in \b t_batt_charger. * @param c_voltage Output parameter for charging voltage setting. * @param c_current Output parameter for charging current setting. * * @return This function returns PMIC_SUCCESS if successful. */ PMIC_STATUS pmic_batt_get_charger_setting(t_batt_charger chgr, unsigned char *c_voltage, unsigned char *c_current) { unsigned int val, reg; reg = 0; if (suspend_flag == 1) return PMIC_ERROR; switch (chgr) { case BATT_MAIN_CHGR: case BATT_TRCKLE_CHGR: reg = REG_CHARGER; break; case BATT_CELL_CHGR: reg = REG_POWER_CONTROL_0; break; default: return PMIC_PARAMETER_ERROR; } CHECK_ERROR(pmic_read_reg(reg, &val, PMIC_ALL_BITS)); switch (chgr) { case BATT_MAIN_CHGR: *c_voltage = BITFEXT(val, MC13783_BATT_DAC_V_DAC);; *c_current = BITFEXT(val, MC13783_BATT_DAC_DAC); break; case BATT_CELL_CHGR: *c_voltage = BITFEXT(val, MC13783_BATT_DAC_V_COIN); *c_current = 0; break; case BATT_TRCKLE_CHGR: *c_voltage = 0; *c_current = BITFEXT(val, MC13783_BATT_DAC_TRCKLE); break; default: return PMIC_PARAMETER_ERROR; } return PMIC_SUCCESS; }
static int max17135_vcom_get_voltage(struct regulator_dev *reg) { struct max17135 *max17135 = rdev_get_drvdata(reg); unsigned int reg_val; max17135_reg_read(REG_MAX17135_DVR, ®_val); return vcom_rs_to_uV(BITFEXT(reg_val, DVR), max17135->pass_num-1); }
static void mc13892_battery_update_status(struct mc13892_dev_info *di) { #ifndef CONFIG_MACH_MX51_ERDOS unsigned int value; #endif /* CONFIG_MACH_MX51_ERDOS */ int retval; int old_battery_status = di->battery_status; if (di->battery_status == POWER_SUPPLY_STATUS_UNKNOWN) di->full_counter = 0; if (di->charger_online) { #ifdef CONFIG_MACH_MX51_ERDOS retval = gpio_charge_status(); switch (retval) { case 0x1: /* STAT2: charged */ di->battery_status = POWER_SUPPLY_STATUS_FULL; break; case 0x2: /* STAT1: now charging */ di->battery_status = POWER_SUPPLY_STATUS_CHARGING; break; default: di->battery_status = POWER_SUPPLY_STATUS_NOT_CHARGING; break; } if (di->battery_status == POWER_SUPPLY_STATUS_FULL) di->full_counter++; else di->full_counter = 0; #else retval = pmic_read_reg(REG_INT_SENSE0, &value, BITFMASK(BIT_CHG_CURRS)); if (retval == 0) { value = BITFEXT(value, BIT_CHG_CURRS); if (value) di->battery_status = POWER_SUPPLY_STATUS_CHARGING; else di->battery_status = POWER_SUPPLY_STATUS_NOT_CHARGING; } if (di->battery_status == POWER_SUPPLY_STATUS_NOT_CHARGING) di->full_counter++; else di->full_counter = 0; #endif /* CONFIG_MACH_MX51_ERDOS */ } else { di->battery_status = POWER_SUPPLY_STATUS_DISCHARGING; di->full_counter = 0; } dev_dbg(di->bat.dev, "bat status: %d\n", di->battery_status); if (di->battery_status != old_battery_status) power_supply_changed(&di->bat); }
static int __devinit is_chip_onboard(struct i2c_client *client) { unsigned int ret = 0; /*bind the right device to the driver */ if (pmic_i2c_24bit_read(client, REG_IDENTIFICATION, &ret) == -1) return -1; if ((MC13892_GEN_ID_VALUE != BITFEXT(ret, MC13892_GENERATION_ID)) && (MC34708_GEN_ID_VALUE != BITFEXT(ret, MC34708_GENERATION_ID))) { /*compare the address value */ dev_err(&client->dev, "read generation ID 0x%x is not equal to 0x%x!\n", BITFEXT(ret, MC13892_GENERATION_ID), MC13892_GEN_ID_VALUE); return -1; } return 0; }
/*! * This function get the real time clock of PMIC * * @param pmic_time return value of date and time * * @return This function returns PMIC_SUCCESS if successful. */ PMIC_STATUS pmic_rtc_get_time(struct timeval *pmic_time) { unsigned int tod_reg_val = 0; unsigned int day_reg_val = 0; unsigned int mask, value; mask = BITFMASK(MC13783_RTCTIME_TIME); CHECK_ERROR(pmic_read_reg(REG_RTC_TIME, &value, mask)); tod_reg_val = BITFEXT(value, MC13783_RTCTIME_TIME); mask = BITFMASK(MC13783_RTCDAY_DAY); CHECK_ERROR(pmic_read_reg(REG_RTC_DAY, &value, mask)); day_reg_val = BITFEXT(value, MC13783_RTCDAY_DAY); pmic_time->tv_sec = (unsigned long)((unsigned long)(tod_reg_val & 0x0001FFFF) + (unsigned long)(day_reg_val * 86400)); return PMIC_SUCCESS; }
static int mc34708_vgen1_get_voltage(struct regulator_dev *reg) { unsigned int register_val = 0; int voltage = 0, mV = 0; CHECK_ERROR(pmic_read_reg(MC34708_REG_REGULATOR_SETTING0, ®ister_val, PMIC_ALL_BITS)); voltage = BITFEXT(register_val, VGEN1); mV = bit_value_to_mv(voltage, VGEN1_MIN_MV, VGEN1_STEP_MV); return mV * 1000; }
//static int pmic_get_chg_value(unsigned int *value) //{ // t_channel channel; // unsigned short result[8], max1 = 0, min1 = 0, max2 = 0, min2 = 0, i; // unsigned int average = 0, average1 = 0, average2 = 0; // // channel = CHARGE_CURRENT; // CHECK_ERROR(pmic_adc_convert(channel, result)); // // // for (i = 0; i < 8; i++) { // if ((result[i] & 0x200) != 0) { // result[i] = 0x400 - result[i]; // average2 += result[i]; // if ((max2 == 0) || (max2 < result[i])) // max2 = result[i]; // if ((min2 == 0) || (min2 > result[i])) // min2 = result[i]; // } else { // average1 += result[i]; // if ((max1 == 0) || (max1 < result[i])) // max1 = result[i]; // if ((min1 == 0) || (min1 > result[i])) // min1 = result[i]; // } // } // // if (max1 != 0) { // average1 -= max1; // if (max2 != 0) // average2 -= max2; // else // average1 -= min1; // } else // average2 -= max2 + min2; // // if (average1 >= average2) { // average = (average1 - average2) / 6; // *value = average; // } else { // average = (average2 - average1) / 6; // *value = ((~average) + 1) & 0x3FF; // } // // return 0; //} // static int get_charger_state(void) { unsigned int value = 0; int charger =0; int retval=-1; retval = pmic_read_reg(REG_INT_SENSE0, &value, BITFMASK(BIT_CHG_DETS)); if(retval == 0){ charger = BITFEXT(value, BIT_CHG_DETS); } bConnectState = charger; return charger; }
static int pmic_get_charger_coulomb_raw(int *coulomb) { int ret; unsigned int value; ret = pmic_read_reg(REG_ACC0, &value, BITFMASK(ACC_CCOUT)); if (ret != 0) return -1; value = BITFEXT(value, ACC_CCOUT); //printk("counter value = %x\n", value); *coulomb = ((s16)((u16)value)) * ACC_COULOMB_PER_LSB; return 0; }
static int mxc_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) { unsigned int tod_reg_val = 0; unsigned int day_reg_val = 0; unsigned int mask, value; unsigned long time; mask = BITFMASK(RTCALARM_TIME); CHECK_ERROR(pmic_read_reg(REG_RTC_ALARM, &value, mask)); tod_reg_val = BITFEXT(value, RTCALARM_TIME); mask = BITFMASK(RTCALARM_DAY); CHECK_ERROR(pmic_read_reg(REG_RTC_DAY_ALARM, &value, mask)); day_reg_val = BITFEXT(value, RTCALARM_DAY); time = (unsigned long)((unsigned long)(tod_reg_val & 0x0001FFFF) + (unsigned long)(day_reg_val * 86400)); rtc_time_to_tm(time, &(alrm->time)); return 0; }
static int mc13892_charger_update_status(struct mc13892_dev_info *di) { int ret; unsigned int value; int online; ret = pmic_read_reg(REG_INT_SENSE0, &value, BITFMASK(BIT_CHG_DETS)); if (ret == 0) { online = BITFEXT(value, BIT_CHG_DETS); if (online != di->charger_online) { di->charger_online = online; dev_info(di->charger.dev, "charger status: %s\n", online ? "online" : "offline"); power_supply_changed(&di->charger); if (online) { cancel_delayed_work_sync(&di->calc_capacity); queue_delayed_work(di->monitor_wqueue, &di->calc_capacity,0); } else { cancel_delayed_work_sync(&di->calc_capacity); queue_delayed_work(di->monitor_wqueue, &di->calc_capacity, HZ * 10); } cancel_delayed_work(&di->monitor_work); queue_delayed_work(di->monitor_wqueue, &di->monitor_work, HZ / 10); if (online) { //pmic_restart_charging(); //queue_delayed_work(chg_wq, &chg_work, 100); chg_wa_timer = 1; } else { //cancel_delayed_work(&chg_work); chg_wa_timer = 0; } } } //////////////////////////////////////////////// bChargerIsDCDC = false; return ret; }
static int mc34708_vgen2_get_voltage(struct regulator_dev *reg) { unsigned int register_val = 0; int voltage = 0, mV = 0; CHECK_ERROR(pmic_read_reg(MC34708_REG_REGULATOR_SETTING0, ®ister_val, PMIC_ALL_BITS)); voltage = BITFEXT(register_val, VGEN2); switch (voltage) { case VGEN2_2_5V: mV = 2500; break; case VGEN2_2_7V: mV = 2700; break; case VGEN2_2_8V: mV = 2800; break; case VGEN2_2_9V: mV = 2900; break; case VGEN2_3V: mV = 3000; break; case VGEN2_3_1V: mV = 3100; break; case VGEN2_3_15V: mV = 3150; break; case VGEN2_3_3V: mV = 3300; break; default: return -EINVAL; } return mV * 1000; }
static int mc13892_vgen3_get_voltage(struct regulator *reg) { unsigned int register_val = 0; int voltage = 0, mV = 0; CHECK_ERROR(pmic_read_reg(REG_SETTING_0, ®ister_val, PMIC_ALL_BITS)); voltage = BITFEXT(register_val, VGEN3); switch (voltage) { case VGEN3_1_8V: mV = 1800; break; case VGEN3_2_9V: mV = 2900; break; default: return -EINVAL; } return mV * 1000; }
static void mc13892_battery_update_status(struct mc13892_dev_info *di) { unsigned int value; int retval; int old_battery_status = di->battery_status; if (di->battery_status == POWER_SUPPLY_STATUS_UNKNOWN) di->full_counter = 0; if (di->charger_online) { retval = pmic_read_reg(REG_INT_SENSE0, &value, BITFMASK(BIT_CHG_CURRS)); if (retval == 0) { value = BITFEXT(value, BIT_CHG_CURRS); if (value) di->battery_status = POWER_SUPPLY_STATUS_CHARGING; else di->battery_status = POWER_SUPPLY_STATUS_NOT_CHARGING; } if (di->battery_status == POWER_SUPPLY_STATUS_NOT_CHARGING) di->full_counter++; else di->full_counter = 0; } else { di->battery_status = POWER_SUPPLY_STATUS_DISCHARGING; di->full_counter = 0; } dev_dbg(di->bat.dev, "bat status: %d\n", di->battery_status); if (old_battery_status != POWER_SUPPLY_STATUS_UNKNOWN && di->battery_status != old_battery_status) power_supply_changed(&di->bat); }
static int mc13892_vsd_get_voltage(struct regulator *reg) { unsigned int register_val = 0; int voltage = 0, mV = 0; CHECK_ERROR(pmic_read_reg(REG_SETTING_1, ®ister_val, PMIC_ALL_BITS)); voltage = BITFEXT(register_val, VSD); switch (voltage) { case VSD_1_8V: mV = 1800; break; case VSD_2_0V: mV = 2000; break; case VSD_2_6V: mV = 2600; break; case VSD_2_7V: mV = 2700; break; case VSD_2_8V: mV = 2800; break; case VSD_2_9V: mV = 2900; break; case VSD_3_0V: mV = 3000; break; case VSD_3_15V: mV = 3150; break; default: return -EINVAL; } return mV * 1000; }
static int tps6518x_vcom_get_voltage(struct regulator_dev *reg) { struct tps6518x *tps6518x = rdev_get_drvdata(reg); unsigned int cur_reg_val; /* current register value */ unsigned int cur_reg2_val; /* current register value */ unsigned int cur_fld_val; /* current bitfield value*/ int vcomValue; /* * this will not work on tps65182 */ if (tps6518x->revID == 65182) return 0; switch (tps6518x->revID & 15) { case 0 : /* TPS65180 */ case 1 : /* TPS65181 */ case 4 : /* TPS65180-rev1 */ tps6518x_reg_read(REG_TPS65180_VCOM_ADJUST, &cur_reg_val); cur_fld_val = BITFEXT(cur_reg_val, VCOM_SET); vcomValue = vcom_rs_to_uV(cur_fld_val); break; case 5 : /* TPS65185 */ case 6 : /* TPS65186 */ tps6518x_reg_read(REG_TPS65185_VCOM1,&cur_reg_val); tps6518x_reg_read(REG_TPS65185_VCOM2,&cur_reg2_val); cur_reg_val |= 256 * (1 & cur_reg2_val); vcomValue = vcom2_rs_to_uV(cur_reg_val); break; default: vcomValue = 0; } return vcomValue; }
static int mc13892_charger_update_status(struct mc13892_dev_info *di) { int ret; #ifndef CONFIG_MACH_MX51_ERDOS unsigned int value; #endif /* CONFIG_MACH_MX51_ERDOS */ int online; #ifdef CONFIG_MACH_MX51_ERDOS ret = pmic_get_dcinput_voltage ((unsigned short *)0); if (ret == 0) { online = 1; } else if (ret == 1) { online = 0; } else { online = di->charger_online; /* keep previous */ } ret = 0; /* * Battery/DCinput update */ if (online == 1) { gpio_battery_enable ( 0 ); } else if (online == 0) { gpio_battery_enable ( 1 ); } if (online != di->charger_online) { di->charger_online = online; /* * check power_supply_register. */ if (di->charger.dev != 0) { dev_info(di->charger.dev, "charger status: %s\n", online ? "online" : "offline"); power_supply_changed(&di->charger); } else { printk ("mc13892_charger_update_status: charger status: %s\n", online ? "online" : "offline"); } } #else ret = pmic_read_reg(REG_INT_SENSE0, &value, BITFMASK(BIT_CHG_DETS)); if (ret == 0) { online = BITFEXT(value, BIT_CHG_DETS); if (online != di->charger_online) { di->charger_online = online; dev_info(di->charger.dev, "charger status: %s\n", online ? "online" : "offline"); power_supply_changed(&di->charger); cancel_delayed_work(&di->monitor_work); queue_delayed_work(di->monitor_wqueue, &di->monitor_work, HZ / 10); if (online) { pmic_start_coulomb_counter(); pmic_restart_charging(); } else pmic_stop_coulomb_counter(); } } #endif /* CONFIG_MACH_MX51_ERDOS */ return ret; }
static int mc34708_sw_get_normal_voltage(struct regulator_dev *reg) { unsigned int register_val = 0; int voltage = 0, mV = 0; int id = rdev_get_id(reg); switch (id) { case MC34708_SW1A: CHECK_ERROR(pmic_read_reg(MC34708_REG_SW1AB, ®ister_val, PMIC_ALL_BITS)); voltage = BITFEXT(register_val, SW1A); mV = bit_value_to_uv(voltage, SW1_MIN_UV, SW1_STEP_UV) / 1000; break; case MC34708_SW1B: CHECK_ERROR(pmic_read_reg(MC34708_REG_SW1AB, ®ister_val, PMIC_ALL_BITS)); voltage = BITFEXT(register_val, SW1B); mV = bit_value_to_uv(voltage, SW1_MIN_UV, SW1_STEP_UV) / 1000; break; case MC34708_SW2: CHECK_ERROR(pmic_read_reg(MC34708_REG_SW2_3, ®ister_val, PMIC_ALL_BITS)); voltage = BITFEXT(register_val, SW2); mV = bit_value_to_uv(voltage, SW2_MIN_UV, SW2_STEP_UV) / 1000; break; case MC34708_SW3: CHECK_ERROR(pmic_read_reg(MC34708_REG_SW2_3, ®ister_val, PMIC_ALL_BITS)); voltage = BITFEXT(register_val, SW3); mV = bit_value_to_mv(voltage, SW3_MIN_MV, SW3_STEP_MV); break; case MC34708_SW4A: CHECK_ERROR(pmic_read_reg(MC34708_REG_SW4AB, ®ister_val, PMIC_ALL_BITS)); voltage = BITFEXT(register_val, SW4AHI); if (voltage == 0) { voltage = BITFEXT(register_val, SW4A); mV = bit_value_to_mv(voltage, SW4_MIN_MV, SW4_STEP_MV); } else if (voltage == 1) mV = SW4_HI_2500_MV; else if (voltage == 2) mV = SW4_HI_3150_MV; else mV = SW4_HI_3300_MV; break; case MC34708_SW4B: CHECK_ERROR(pmic_read_reg(MC34708_REG_SW4AB, ®ister_val, PMIC_ALL_BITS)); voltage = BITFEXT(register_val, SW4BHI); if (voltage == 0) { voltage = BITFEXT(register_val, SW4B); mV = bit_value_to_mv(voltage, SW4_MIN_MV, SW4_STEP_MV); } else if (voltage == 1) mV = SW4_HI_2500_MV; else if (voltage == 2) mV = SW4_HI_3150_MV; else mV = SW4_HI_3300_MV; break; case MC34708_SW5: CHECK_ERROR(pmic_read_reg(MC34708_REG_SW5, ®ister_val, PMIC_ALL_BITS)); voltage = BITFEXT(register_val, SW5); mV = bit_value_to_mv(voltage, SW5_MIN_MV, SW5_STEP_MV); break; default: break; } if (mV == 0) return -EINVAL; else return mV * 1000; }
PMIC_STATUS mc13892_bklit_get_current(enum lit_channel channel, unsigned char *level) { unsigned int reg_value = 0; unsigned int mask = 0; int reg, mode; CHECK_ERROR(mc13892_bklit_get_hi_current(channel, &mode)); switch (channel) { case LIT_MAIN: mask = BITFMASK(BIT_CL_MAIN); reg = REG_LED_CTL0; break; case LIT_AUX: mask = BITFMASK(BIT_CL_AUX); reg = REG_LED_CTL0; break; case LIT_KEY: mask = BITFMASK(BIT_CL_KEY); reg = REG_LED_CTL1; break; case LIT_RED: mask = BITFMASK(BIT_CL_RED); reg = REG_LED_CTL2; break; case LIT_GREEN: mask = BITFMASK(BIT_CL_GREEN); reg = REG_LED_CTL2; break; case LIT_BLUE: mask = BITFMASK(BIT_CL_BLUE); reg = REG_LED_CTL3; break; default: return PMIC_PARAMETER_ERROR; } CHECK_ERROR(pmic_read_reg(reg, ®_value, mask)); switch (channel) { case LIT_MAIN: *level = BITFEXT(reg_value, BIT_CL_MAIN); break; case LIT_AUX: *level = BITFEXT(reg_value, BIT_CL_AUX); break; case LIT_KEY: *level = BITFEXT(reg_value, BIT_CL_KEY); break; case LIT_RED: *level = BITFEXT(reg_value, BIT_CL_RED); break; case LIT_GREEN: *level = BITFEXT(reg_value, BIT_CL_GREEN); break; case LIT_BLUE: *level = BITFEXT(reg_value, BIT_CL_BLUE); break; default: return PMIC_PARAMETER_ERROR; } if (mode == 1) *level += LIT_CURR_HI_0; return PMIC_SUCCESS; }