| .. | .. |
|---|
| 560 | 560 | int zero_batocv_to_cap; |
|---|
| 561 | 561 | int zero_xsoc; |
|---|
| 562 | 562 | unsigned long finish_base; |
|---|
| 563 | | - time_t rtc_base; |
|---|
| 563 | + time64_t rtc_base; |
|---|
| 564 | 564 | int sm_remain_cap; |
|---|
| 565 | 565 | int sm_linek; |
|---|
| 566 | 566 | int sm_chrg_dsoc; |
|---|
| .. | .. |
|---|
| 631 | 631 | |
|---|
| 632 | 632 | static u64 get_boot_sec(void) |
|---|
| 633 | 633 | { |
|---|
| 634 | | - struct timespec ts; |
|---|
| 634 | + struct timespec64 ts; |
|---|
| 635 | 635 | |
|---|
| 636 | | - get_monotonic_boottime(&ts); |
|---|
| 636 | + ktime_get_boottime_ts64(&ts); |
|---|
| 637 | 637 | |
|---|
| 638 | 638 | return ts.tv_sec; |
|---|
| 639 | 639 | } |
|---|
| .. | .. |
|---|
| 650 | 650 | { |
|---|
| 651 | 651 | u8 i; |
|---|
| 652 | 652 | u16 d; |
|---|
| 653 | + |
|---|
| 654 | + if (size < 2) |
|---|
| 655 | + return 0; |
|---|
| 653 | 656 | |
|---|
| 654 | 657 | for (i = 0; i < size; i++) { |
|---|
| 655 | 658 | if (value < table[i]) |
|---|
| .. | .. |
|---|
| 710 | 713 | unsigned int val) |
|---|
| 711 | 714 | { |
|---|
| 712 | 715 | return regmap_field_write(battery->rmap_fields[field_id], val); |
|---|
| 713 | | -} |
|---|
| 714 | | - |
|---|
| 715 | | -static bool rk817_is_bat_exist(struct rk817_battery_device *battery) |
|---|
| 716 | | -{ |
|---|
| 717 | | - if (battery->chip_id == RK817_ID) |
|---|
| 718 | | - return rk817_bat_field_read(battery, BAT_EXS) ? true : false; |
|---|
| 719 | | - |
|---|
| 720 | | - return true; |
|---|
| 721 | 716 | } |
|---|
| 722 | 717 | |
|---|
| 723 | 718 | /*cal_offset: current offset value*/ |
|---|
| .. | .. |
|---|
| 1186 | 1181 | buf = (cap >> 0) & 0xff; |
|---|
| 1187 | 1182 | rk817_bat_field_write(battery, Q_INIT_L0, buf); |
|---|
| 1188 | 1183 | |
|---|
| 1189 | | - battery->rsoc = capacity * 1000 * 100 / battery->fcc; |
|---|
| 1184 | + battery->rsoc = capacity * 1000 * 100 / DIV(battery->fcc); |
|---|
| 1190 | 1185 | battery->remain_cap = capacity * 1000; |
|---|
| 1191 | 1186 | DBG("new remaincap: %d\n", battery->remain_cap); |
|---|
| 1192 | 1187 | fuel_gauge_q_init_info(battery); |
|---|
| .. | .. |
|---|
| 1607 | 1602 | battery->pwron_voltage) * 1000;/* uAH */ |
|---|
| 1608 | 1603 | battery->dsoc = battery->rsoc; |
|---|
| 1609 | 1604 | battery->fcc = battery->pdata->design_capacity; |
|---|
| 1605 | + if (battery->fcc < MIN_FCC) |
|---|
| 1606 | + battery->fcc = MIN_FCC; |
|---|
| 1607 | + |
|---|
| 1610 | 1608 | battery->nac = rk817_bat_vol_to_cap(battery, battery->pwron_voltage); |
|---|
| 1611 | 1609 | |
|---|
| 1612 | 1610 | rk817_bat_update_qmax(battery, battery->qmax); |
|---|
| .. | .. |
|---|
| 1809 | 1807 | } |
|---|
| 1810 | 1808 | |
|---|
| 1811 | 1809 | pdata->ocv_size = length / sizeof(u32); |
|---|
| 1812 | | - if (pdata->ocv_size <= 0) { |
|---|
| 1810 | + if (pdata->ocv_size < 2) { |
|---|
| 1813 | 1811 | dev_err(dev, "invalid ocv table\n"); |
|---|
| 1814 | 1812 | return -EINVAL; |
|---|
| 1815 | 1813 | } |
|---|
| .. | .. |
|---|
| 1874 | 1872 | ret = of_property_read_u32(np, "virtual_power", &pdata->bat_mode); |
|---|
| 1875 | 1873 | if (ret < 0) |
|---|
| 1876 | 1874 | dev_err(dev, "virtual_power missing!\n"); |
|---|
| 1877 | | - if (!rk817_is_bat_exist(battery)) |
|---|
| 1878 | | - battery->pdata->bat_mode = MODE_VIRTUAL; |
|---|
| 1879 | 1875 | |
|---|
| 1880 | 1876 | ret = of_property_read_u32(np, "bat_res", &pdata->bat_res); |
|---|
| 1881 | 1877 | if (ret < 0) |
|---|
| .. | .. |
|---|
| 2783 | 2779 | finish_sec = base2sec(battery->finish_base); |
|---|
| 2784 | 2780 | |
|---|
| 2785 | 2781 | soc_sec = battery->fcc * 3600 / 100 / DIV(finish_current); |
|---|
| 2782 | + if (soc_sec == 0) |
|---|
| 2783 | + soc_sec = 1; |
|---|
| 2786 | 2784 | plus_soc = finish_sec / DIV(soc_sec); |
|---|
| 2787 | 2785 | if (finish_sec > soc_sec) { |
|---|
| 2788 | 2786 | rest = finish_sec % soc_sec; |
|---|
| .. | .. |
|---|
| 3089 | 3087 | { |
|---|
| 3090 | 3088 | } |
|---|
| 3091 | 3089 | |
|---|
| 3092 | | -static time_t rk817_get_rtc_sec(void) |
|---|
| 3090 | +static time64_t rk817_get_rtc_sec(void) |
|---|
| 3093 | 3091 | { |
|---|
| 3094 | 3092 | int err; |
|---|
| 3095 | 3093 | struct rtc_time tm; |
|---|
| 3096 | | - struct timespec tv = { .tv_nsec = NSEC_PER_SEC >> 1, }; |
|---|
| 3097 | 3094 | struct rtc_device *rtc = rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE); |
|---|
| 3098 | | - time_t sec; |
|---|
| 3099 | 3095 | |
|---|
| 3100 | 3096 | err = rtc_read_time(rtc, &tm); |
|---|
| 3101 | 3097 | if (err) { |
|---|
| .. | .. |
|---|
| 3109 | 3105 | return 0; |
|---|
| 3110 | 3106 | } |
|---|
| 3111 | 3107 | |
|---|
| 3112 | | - rtc_tm_to_time(&tm, &tv.tv_sec); |
|---|
| 3113 | | - sec = tv.tv_sec; |
|---|
| 3114 | | - |
|---|
| 3115 | | - return sec; |
|---|
| 3108 | + return rtc_tm_to_time64(&tm); |
|---|
| 3116 | 3109 | } |
|---|
| 3117 | 3110 | |
|---|
| 3118 | 3111 | #ifdef CONFIG_PM_SLEEP |
|---|