/** * alarm_clock_get - posix clock_get interface * @which_clock: clockid * @tp: timespec to fill. * * Provides the underlying alarm base time. */ static int alarm_clock_get(clockid_t which_clock, struct timespec *tp) { struct alarm_base *base = &alarm_bases[clock2alarm(which_clock)]; if (!alarmtimer_get_rtcdev()) return -ENOTSUPP; *tp = ktime_to_timespec(base->gettime()); return 0; }
static int timeval_sub( struct timespec *result, struct timespec x, struct timespec y) { ktime_t kx = timespec_to_ktime(x); ktime_t ky = timespec_to_ktime(y); ktime_t kresult = ktime_sub(kx, ky); *result = ktime_to_timespec(kresult); return !(kresult.tv64 > 0); }
/** * hrtimer_get_res - get the timer resolution for a clock * @which_clock: which clock to query * @tp: pointer to timespec variable to store the resolution * * Store the resolution of the clock selected by @which_clock in the * variable pointed to by @tp. */ int hrtimer_get_res(const clockid_t which_clock, struct timespec *tp) { struct hrtimer_cpu_base *cpu_base; int base = hrtimer_clockid_to_base(which_clock); cpu_base = &__raw_get_cpu_var(hrtimer_bases); *tp = ktime_to_timespec(cpu_base->clock_base[base].resolution); return 0; }
static void s3c_bat_discharge_reason(struct chg_data *chg) { int discharge_reason; ktime_t ktime; struct timespec cur_time; discharge_reason = chg->bat_info.dis_reason & 0xf; if(chg->bat_info.batt_percentage >= 100) { chg->set_batt_full = 1; chg->bat_info.batt_is_full = true; } if (discharge_reason & DISCONNECT_BAT_FULL && /*chg->bat_info.batt_vcell < RECHARGE_COND_VOLTAGE*/ chg->bat_info.batt_percentage < 100) chg->bat_info.dis_reason &= ~DISCONNECT_BAT_FULL; if (discharge_reason & DISCONNECT_TEMP_OVERHEAT && chg->bat_info.batt_temp <= HIGH_RECOVER_TEMP) chg->bat_info.dis_reason &= ~DISCONNECT_TEMP_OVERHEAT; if (discharge_reason & DISCONNECT_TEMP_FREEZE && chg->bat_info.batt_temp >= LOW_RECOVER_TEMP) chg->bat_info.dis_reason &= ~DISCONNECT_TEMP_FREEZE; if (discharge_reason & DISCONNECT_OVER_TIME && /*chg->bat_info.batt_vcell < RECHARGE_COND_VOLTAGE*/ chg->bat_info.batt_percentage < 100) chg->bat_info.dis_reason &= ~DISCONNECT_OVER_TIME; if (chg->set_batt_full) chg->bat_info.dis_reason |= DISCONNECT_BAT_FULL; if (chg->bat_info.batt_health != POWER_SUPPLY_HEALTH_GOOD) chg->bat_info.dis_reason |= chg->bat_info.batt_health == POWER_SUPPLY_HEALTH_OVERHEAT ? DISCONNECT_TEMP_OVERHEAT : DISCONNECT_TEMP_FREEZE; ktime = alarm_get_elapsed_realtime(); cur_time = ktime_to_timespec(ktime); if (chg->discharging_time && cur_time.tv_sec > chg->discharging_time) { chg->set_charge_timeout = true; chg->bat_info.dis_reason |= DISCONNECT_OVER_TIME; } pr_debug("%s : Current charge level : %d%%\n\ Current time : %ld discharging_time : %ld\n\ discharging reason : %d\n",\ __func__, chg->bat_info.batt_percentage, cur_time.tv_sec, chg->discharging_time, chg->bat_info.dis_reason); }
/** * i40e_ptp_init - Initialize the 1588 support after device probe or reset * @pf: Board private structure * * This function sets device up for 1588 support. The first time it is run, it * will create a PHC clock device. It does not create a clock device if one * already exists. It also reconfigures the device after a reset. **/ void i40e_ptp_init(struct i40e_pf *pf) { struct i40e_hw *hw = &pf->hw; u32 pf_id; long err; /* Only one PF is assigned to control 1588 logic per port. Do not * enable any support for PFs not assigned via PRTTSYN_CTL0.PF_ID */ pf_id = (rd32(hw, I40E_PRTTSYN_CTL0) & I40E_PRTTSYN_CTL0_PF_ID_MASK) >> I40E_PRTTSYN_CTL0_PF_ID_SHIFT; if (hw->pf_id != pf_id) { pf->flags &= ~I40E_FLAG_PTP; dev_info(&pf->pdev->dev, "PTP not supported on this device\n"); return; } /* we have to initialize the spinlock first, since we can't control * when the user will enter the PHC device entry points */ spin_lock_init(&pf->tmreg_lock); /* ensure we have a clock device */ err = i40e_ptp_create_clock(pf); if (err) { pf->ptp_clock = NULL; dev_err(&pf->pdev->dev, "PTP clock register failed: %ld\n", err); } else { struct timespec ts; u32 regval; dev_info(&pf->pdev->dev, "PHC enabled\n"); pf->flags |= I40E_FLAG_PTP; /* Ensure the clocks are running. */ regval = rd32(hw, I40E_PRTTSYN_CTL0); regval |= I40E_PRTTSYN_CTL0_TSYNENA_MASK; wr32(hw, I40E_PRTTSYN_CTL0, regval); regval = rd32(hw, I40E_PRTTSYN_CTL1); regval |= I40E_PRTTSYN_CTL1_TSYNENA_MASK; wr32(hw, I40E_PRTTSYN_CTL1, regval); /* Set the increment value per clock tick. */ i40e_ptp_set_increment(pf); /* reset timestamping mode */ i40e_ptp_set_timestamp_mode(pf, &pf->tstamp_config); /* Set the clock value. */ ts = ktime_to_timespec(ktime_get_real()); i40e_ptp_settime(&pf->ptp_caps, &ts); } }
static int vibrator_get_time(struct timed_output_dev *dev) { struct timespec time_tmp; if (hrtimer_active(&vibe_timer)) { ktime_t r = hrtimer_get_remaining(&vibe_timer); time_tmp = ktime_to_timespec(r); //return r.tv.sec * 1000 + r.tv.nsec/1000000; return time_tmp.tv_sec* 1000 + time_tmp.tv_nsec/1000000; } else return 0; }
/* * Get the time remaining on a POSIX.1b interval timer. This function * is ALWAYS called with spin_lock_irq on the timer, thus it must not * mess with irq. * * We have a couple of messes to clean up here. First there is the case * of a timer that has a requeue pending. These timers should appear to * be in the timer list with an expiry as if we were to requeue them * now. * * The second issue is the SIGEV_NONE timer which may be active but is * not really ever put in the timer list (to save system resources). * This timer may be expired, and if so, we will do it here. Otherwise * it is the same as a requeue pending timer WRT to what we should * report. */ static void common_timer_get(struct k_itimer *timr, struct itimerspec *cur_setting) { ktime_t now, remaining, iv; struct hrtimer *timer = &timr->it.real.timer; memset(cur_setting, 0, sizeof(struct itimerspec)); iv = timr->it.real.interval; /* interval timer ? */ if (iv.tv64) cur_setting->it_interval = ktime_to_timespec(iv); else if (!hrtimer_active(timer) && (timr->it_sigev_notify & ~SIGEV_THREAD_ID) != SIGEV_NONE) return; now = timer->base->get_time(); /* * When a requeue is pending or this is a SIGEV_NONE * timer move the expiry time forward by intervals, so * expiry is > now. */ if (iv.tv64 && (timr->it_requeue_pending & REQUEUE_PENDING || (timr->it_sigev_notify & ~SIGEV_THREAD_ID) == SIGEV_NONE)) timr->it_overrun += (unsigned int) hrtimer_forward(timer, now, iv); remaining = ktime_sub(hrtimer_get_expires(timer), now); /* Return 0 only, when the timer is expired and not pending */ if (remaining.tv64 <= 0) { /* * A single shot SIGEV_NONE timer must return 0, when * it is expired ! */ if ((timr->it_sigev_notify & ~SIGEV_THREAD_ID) != SIGEV_NONE) cur_setting->it_value.tv_nsec = 1; } else cur_setting->it_value = ktime_to_timespec(remaining); }
static irqreturn_t sensordata_irq_thread_fn(int iIrq, void *dev_id) { struct ssp_data *data = dev_id; struct timespec ts; ts = ktime_to_timespec(ktime_get_boottime()); data->timestamp = ts.tv_sec * 1000000000ULL + ts.tv_nsec; select_irq_msg(data); data->uIrqCnt++; return IRQ_HANDLED; }
struct rtc_time rtc_ktime_to_tm(ktime_t kt) { struct timespec ts; struct rtc_time ret; ts = ktime_to_timespec(kt); if (ts.tv_nsec) ts.tv_sec++; rtc_time_to_tm(ts.tv_sec, &ret); return ret; }
int compat_sock_get_timestampns(struct sock *sk, struct timespec __user *userstamp) { struct compat_timespec __user *ctv = (struct compat_timespec __user *) userstamp; int err = -ENOENT; struct timespec ts; if (!sock_flag(sk, SOCK_TIMESTAMP)) sock_enable_timestamp(sk, SOCK_TIMESTAMP); ts = ktime_to_timespec(sk->sk_stamp); if (ts.tv_sec == -1) return err; if (ts.tv_sec == 0) { sk->sk_stamp = ktime_get_real(); ts = ktime_to_timespec(sk->sk_stamp); } err = 0; if (put_user(ts.tv_sec, &ctv->tv_sec) || put_user(ts.tv_nsec, &ctv->tv_nsec)) err = -EFAULT; return err; }
/* * Get the time remaining on a POSIX.1b interval timer. This function * is ALWAYS called with spin_lock_irq on the timer, thus it must not * mess with irq. * * We have a couple of messes to clean up here. First there is the case * of a timer that has a requeue pending. These timers should appear to * be in the timer list with an expiry as if we were to requeue them * now. * * The second issue is the SIGEV_NONE timer which may be active but is * not really ever put in the timer list (to save system resources). * This timer may be expired, and if so, we will do it here. Otherwise * it is the same as a requeue pending timer WRT to what we should * report. */ static void common_timer_get(struct k_itimer *timr, struct itimerspec *cur_setting) { ktime_t remaining; struct hrtimer *timer = &timr->it.real.timer; memset(cur_setting, 0, sizeof(struct itimerspec)); remaining = hrtimer_get_remaining(timer); /* Time left ? or timer pending */ if (remaining.tv64 > 0 || hrtimer_active(timer)) goto calci; /* interval timer ? */ if (timr->it.real.interval.tv64 == 0) return; /* * When a requeue is pending or this is a SIGEV_NONE timer * move the expiry time forward by intervals, so expiry is > * now. */ if (timr->it_requeue_pending & REQUEUE_PENDING || (timr->it_sigev_notify & ~SIGEV_THREAD_ID) == SIGEV_NONE) { timr->it_overrun += hrtimer_forward(timer, timr->it.real.interval); remaining = hrtimer_get_remaining(timer); } calci: /* interval timer ? */ if (timr->it.real.interval.tv64 != 0) cur_setting->it_interval = ktime_to_timespec(timr->it.real.interval); /* Return 0 only, when the timer is expired and not pending */ if (remaining.tv64 <= 0) cur_setting->it_value.tv_nsec = 1; else cur_setting->it_value = ktime_to_timespec(remaining); }
static int update_rmtp(struct hrtimer *timer, struct timespec __user *rmtp) { struct timespec rmt; ktime_t rem; rem = hrtimer_expires_remaining(timer); if (rem.tv64 <= 0) return 0; rmt = ktime_to_timespec(rem); if (copy_to_user(rmtp, &rmt, sizeof(*rmtp))) return -EFAULT; return 1; }
static int update_rmtp(struct hrtimer *timer, struct timespec __user *rmtp) { struct timespec rmt; ktime_t rem; rem = ktime_sub(timer->expires, timer->base->get_time()); if (rem.tv64 <= 0) return 0; rmt = ktime_to_timespec(rem); if (copy_to_user(rmtp, &rmt, sizeof(*rmtp))) return -EFAULT; return 1; }
int sched_wait_interval(int flags, const struct timespec __user * rqtp, struct timespec __user * rmtp) { struct hrtimer_sleeper t; enum hrtimer_mode mode = flags & TIMER_ABSTIME ? HRTIMER_MODE_ABS : HRTIMER_MODE_REL; int ret = 0; hrtimer_init_on_stack(&t.timer, CLOCK_MONOTONIC, mode); hrtimer_set_expires(&t.timer, timespec_to_ktime(*rqtp)); hrtimer_init_sleeper(&t, current); do { set_current_state(TASK_INTERRUPTIBLE); hrtimer_start_expires(&t.timer, mode); if (!hrtimer_active(&t.timer)) t.task = NULL; if (likely(t.task)) { t.task->dl.flags |= DL_NEW; schedule(); } hrtimer_cancel(&t.timer); mode = HRTIMER_MODE_ABS; } while (t.task && !signal_pending(current)); __set_current_state(TASK_RUNNING); if (t.task == NULL) goto out; if (mode == HRTIMER_MODE_ABS) { ret = -ERESTARTNOHAND; goto out; } if (rmtp) { ktime_t rmt; struct timespec rmt_ts; rmt = hrtimer_expires_remaining(&t.timer); if (rmt.tv64 > 0) goto out; rmt_ts = ktime_to_timespec(rmt); if (!timespec_valid(&rmt_ts)) goto out; *rmtp = rmt_ts; } out: destroy_hrtimer_on_stack(&t.timer); return ret; }
static struct timespec ktime_to_timespec(ktime_t ktime) { return (struct timespec){ .tv_sec = (long)ktime.tv.sec, .tv_nsec = (long)ktime.tv.nsec}; } static void ktime_to_timespec_test() { ktime_t yestoday; yestoday = ktime_set(1, 1000); struct timespec sometime = ktime_to_timespec(yestoday); printf(" tv_sec = %ld \n", sometime.tv_sec); printf("tv_nsec = %ld\n", sometime.tv_nsec); }
static void p3_set_time_for_charging(struct battery_data *battery, int mode) { if (mode) { ktime_t ktime; struct timespec cur_time; ktime = alarm_get_elapsed_realtime(); cur_time = ktime_to_timespec(ktime); /* record start time for abs timer */ battery->charging_start_time = cur_time.tv_sec; } else { /* initialize start time for abs timer */ battery->charging_start_time = 0; } }
static void sec_set_time_for_charging(struct sec_bat_info *info, int mode) { if (mode) { ktime_t ktime; struct timespec cur_time; ktime = alarm_get_elapsed_realtime(); cur_time = ktime_to_timespec(ktime); /* record start time for abs timer */ info->charging_start_time = cur_time.tv_sec; } else { /* initialize start time for abs timer */ info->charging_start_time = 0; } }
static void rk2918_get_bat_capacity(struct rk2918_battery_data *bat) { int deltatime = 0; ktime_t ktmietmp; struct timespec ts; ktmietmp = ktime_get_real(); ts = ktime_to_timespec(ktmietmp); deltatime = ts.tv_sec - batteryspendcnt; //deltatime = ktmietmp.tv.sec - batteryspendcnt; if (first_flag || (openfailflag && (openfailcount > 1))) //多次打开,刚开始采样时不准,多次采样。。 { if(first_flag == 1) first_flag--; openfailcount--; printk("%s,first_flag=%d,openfailflag=%d,openfailcount=%d\n",__func__,first_flag,openfailflag,openfailcount); gBatCapacity = rk2918_battery_load_capacity(); if (gBatCapacity == 0) gBatCapacity = 1; } else if ((deltatime > 600) && (first_flag == 0))//处理休眠之后的电量回复,如果超过十分钟 { gBatCapacity = rk2918_battery_resume_get_Capacity(deltatime); } else { gBatCapacity = rk2918_get_bat_capacity_ext(gBatVoltage); /* if(deltatime>1) { if(gBatCapacity--<2) gBatCapacity = 50; if(gBatCapacity==15) gBatCapacity = 4; batteryspendcnt = ktmietmp.tv.sec; } */ } //batteryspendcnt = ktmietmp.tv.sec; batteryspendcnt=ts.tv_sec; }
static irqreturn_t sensordata_irq_thread_fn(int iIrq, void *dev_id) { struct ssp_data *data = dev_id; struct timespec ts; ts = ktime_to_timespec(ktime_get_boottime()); data->timestamp = ts.tv_sec * 1000000000ULL + ts.tv_nsec; if (gpio_get_value(data->mcu_int1)) { ssp_info("MCU int HIGH"); return IRQ_HANDLED; } select_irq_msg(data); data->uIrqCnt++; return IRQ_HANDLED; }
static int sec_is_over_abs_time(struct sec_bat_info *info, unsigned int abs_time) { ktime_t ktime; struct timespec cur_time; if (!info->charging_start_time) return 0; ktime = alarm_get_elapsed_realtime(); cur_time = ktime_to_timespec(ktime); if (info->charging_start_time + abs_time < cur_time.tv_sec) { pr_info("Charging time out"); return 1; } else return 0; }
/** * igb_ptp_reset - Re-enable the adapter for PTP following a reset. * @adapter: Board private structure. * * This function handles the reset work required to re-enable the PTP device. **/ void igb_ptp_reset(struct igb_adapter *adapter) { struct e1000_hw *hw = &adapter->hw; unsigned long flags; if (!(adapter->flags & IGB_FLAG_PTP)) return; /* reset the tstamp_config */ igb_ptp_set_timestamp_mode(adapter, &adapter->tstamp_config); spin_lock_irqsave(&adapter->tmreg_lock, flags); switch (adapter->hw.mac.type) { case e1000_82576: /* Dial the nominal frequency. */ wr32(E1000_TIMINCA, INCPERIOD_82576 | INCVALUE_82576); break; case e1000_82580: case e1000_i354: case e1000_i350: case e1000_i210: case e1000_i211: wr32(E1000_TSAUXC, 0x0); wr32(E1000_TSSDP, 0x0); wr32(E1000_TSIM, TSYNC_INTERRUPTS); wr32(E1000_IMS, E1000_IMS_TS); break; default: /* No work to do. */ goto out; } /* Re-initialize the timer. */ if ((hw->mac.type == e1000_i210) || (hw->mac.type == e1000_i211)) { struct timespec ts = ktime_to_timespec(ktime_get_real()); igb_ptp_write_i210(adapter, &ts); } else { timecounter_init(&adapter->tc, &adapter->cc, ktime_to_ns(ktime_get_real())); } out: spin_unlock_irqrestore(&adapter->tmreg_lock, flags); }
/** * update_rmtp - Update remaining timespec value * @exp: expiration time * @type: timer type * @rmtp: user pointer to remaining timepsec value * * Helper function that fills in rmtp value with time between * now and the exp value */ static int update_rmtp(ktime_t exp, enum alarmtimer_type type, struct timespec __user *rmtp) { struct timespec rmt; ktime_t rem; rem = ktime_sub(exp, alarm_bases[type].gettime()); if (rem.tv64 <= 0) return 0; rmt = ktime_to_timespec(rem); if (copy_to_user(rmtp, &rmt, sizeof(*rmtp))) return -EFAULT; return 1; }
/** * i40e_ptp_init - Initialize the 1588 support after device probe or reset * @pf: Board private structure * * This function sets device up for 1588 support. The first time it is run, it * will create a PHC clock device. It does not create a clock device if one * already exists. It also reconfigures the device after a reset. **/ void i40e_ptp_init(struct i40e_pf *pf) { struct net_device *netdev = pf->vsi[pf->lan_vsi]->netdev; struct i40e_hw *hw = &pf->hw; long err; /* we have to initialize the lock first, since we can't control * when the user will enter the PHC device entry points */ spin_lock_init(&pf->tmreg_lock); /* ensure we have a clock device */ err = i40e_ptp_create_clock(pf); if (err) { pf->ptp_clock = NULL; dev_err(&pf->pdev->dev, "%s: ptp_clock_register failed\n", __func__); } else { struct timespec ts; u32 regval; dev_info(&pf->pdev->dev, "%s: added PHC on %s\n", __func__, netdev->name); pf->flags |= I40E_FLAG_PTP; /* Ensure the clocks are running. */ regval = rd32(hw, I40E_PRTTSYN_CTL0); regval |= I40E_PRTTSYN_CTL0_TSYNENA_MASK; wr32(hw, I40E_PRTTSYN_CTL0, regval); regval = rd32(hw, I40E_PRTTSYN_CTL1); regval |= I40E_PRTTSYN_CTL1_TSYNENA_MASK; wr32(hw, I40E_PRTTSYN_CTL1, regval); /* Set the increment value per clock tick. */ i40e_ptp_set_increment(pf); /* reset timestamping mode */ i40e_ptp_set_timestamp_mode(pf, &pf->tstamp_config); /* Set the clock value. */ ts = ktime_to_timespec(ktime_get_real()); i40e_ptp_settime(&pf->ptp_caps, &ts); } }
static int msm_evtlog_debugfs_dump(struct seq_file *s, void *data) { struct msm_evtlog *log = s->private; unsigned long cnt; /* # of samples since clear */ unsigned long n; /* # of samples to print, also head index */ unsigned long i; struct timespec timespec; /** * Prints in chronological order, oldest -> newest * Note due to lock-less design, the first few printed entries * may be corrupted by new writer not oldest. * This is a tradeoff for speed of sampling */ cnt = atomic_read(&log->cnt); if (!cnt) return 0; n = cnt & SIZE_MASK(log->size); /** * If not full, print from first log * (which is index 1 since atomic_inc_return is prefix operator) */ i = (cnt < log->size) ? 0 : n; seq_puts(s, "time_ns, pid, func, line, val1, val2, msg\n"); do { i = (i + 1) & SIZE_MASK(log->size); timespec = ktime_to_timespec(log->events[i].ktime); seq_printf(s, "[%5lu.%06lu], %d, %s, %d, %llu, %llu, %s\n", timespec.tv_sec, timespec.tv_nsec / 1000, log->events[i].pid, log->events[i].func, log->events[i].line, log->events[i].val1, log->events[i].val2, log->events[i].msg); } while (i != n); return 0; }
static void printl(const char *fmt, ...) { va_list args; int len; struct timespec tv; char tbuf[256]; va_start(args, fmt); /* want monotonic time since start of tcp_probe */ tv = ktime_to_timespec(ktime_sub(ktime_get(), tcpw.start)); len = sprintf(tbuf, "%lu.%09lu ", (unsigned long) tv.tv_sec, (unsigned long) tv.tv_nsec); len += vscnprintf(tbuf+len, sizeof(tbuf)-len, fmt, args); va_end(args); kfifo_put(tcpw.fifo, tbuf, len); wake_up(&tcpw.wait); }
static irqreturn_t yas_trigger_handler(int irq, void *p) { struct iio_poll_func *pf = p; struct iio_dev *indio_dev = pf->indio_dev; struct iio_buffer *buffer = indio_dev->buffer; struct yas_state *st = iio_priv(indio_dev); int len = 0, i, j; size_t datasize = buffer->access->get_bytes_per_datum(buffer); int32_t *mag; struct timespec ts; s64 timestamp; mag = (int32_t *) kmalloc(datasize, GFP_KERNEL); if (mag == NULL) goto done; if (!bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength)) { j = 0; for (i = 0; i < 3; i++) { if (test_bit(i, indio_dev->active_scan_mask)) { mag[j] = st->compass_data[i]; j++; } } len = j * 4; } /* Guaranteed to be aligned with 8 byte boundary */ //if (indio_dev->scan_timestamp) // *(s64 *)((u8 *)mag + ALIGN(len, sizeof(s64))) = pf->timestamp; ts = ktime_to_timespec(ktime_get_boottime()); timestamp = ts.tv_sec * 1000000000ULL + ts.tv_nsec; *(s64 *)((u8 *)mag + ALIGN(len, sizeof(s64))) = timestamp; if (timestamp <= 0) pr_err("[%s] invalid time = %lld\n", __func__, timestamp); iio_push_to_buffer(indio_dev->buffer, (u8 *)mag, 0); kfree(mag); done: iio_trigger_notify_done(indio_dev->trig); return IRQ_HANDLED; }
/** * igb_ptp_reset - Re-enable the adapter for PTP following a reset. * @adapter: Board private structure. * * This function handles the reset work required to re-enable the PTP device. **/ void igb_ptp_reset(struct igb_adapter *adapter) { struct e1000_hw *hw = &adapter->hw; if (!(adapter->flags & IGB_FLAG_PTP)) return; switch (adapter->hw.mac.type) { case e1000_82576: /* Dial the nominal frequency. */ E1000_WRITE_REG(hw, E1000_TIMINCA, INCPERIOD_82576 | INCVALUE_82576); break; case e1000_82580: case e1000_i350: case e1000_i354: case e1000_i210: case e1000_i211: /* Enable the timer functions and interrupts. */ E1000_WRITE_REG(hw, E1000_TSAUXC, 0x0); E1000_WRITE_REG(hw, E1000_TSIM, E1000_TSIM_TXTS); E1000_WRITE_REG(hw, E1000_IMS, E1000_IMS_TS); break; default: /* No work to do. */ return; } /* Re-initialize the timer. */ if ((hw->mac.type == e1000_i210) || (hw->mac.type == e1000_i211)) { struct timespec ts = ktime_to_timespec(ktime_get_real()); igb_ptp_settime_i210(&adapter->ptp_caps, &ts); } else { timecounter_init(&adapter->tc, &adapter->cc, ktime_to_ns(ktime_get_real())); } }
static int is_over_abs_time(struct battery_data *battery) { unsigned int total_time; ktime_t ktime; struct timespec cur_time; if (!battery->charging_start_time) return 0; ktime = alarm_get_elapsed_realtime(); cur_time = ktime_to_timespec(ktime); if (battery->info.batt_is_recharging) total_time = battery->pdata->recharge_duration; else total_time = battery->pdata->charge_duration; if (battery->charging_start_time + total_time < cur_time.tv_sec) { pr_info("Charging time out"); return 1; } else return 0; }
static void rk2918_get_bat_capacity(struct rk2918_battery_data *bat) { s32 deltatime = 0; ktime_t ktmietmp; struct timespec ts; dprint("func=%s, line=%d :\n", __func__, __LINE__); ktmietmp = ktime_get_real(); ts = ktime_to_timespec(ktmietmp); deltatime = ts.tv_sec - batteryspendcnt; if (first_flag || (openfailflag && (openfailcount > 1))) //多次打开,刚开始采样时不准,多次采样。。 { if(first_flag == 1) first_flag--; openfailcount--; printk("%s,first_flag=%d,openfailflag=%d,openfailcount=%d\n",__func__,first_flag,openfailflag,openfailcount); gBatCapacity = rk2918_battery_load_capacity(); if (gBatCapacity == 0) gBatCapacity = 1; } else if ((deltatime > 1) && (first_flag == 0) &&(!time_chg_flag))//处理休眠之后的电量回复,如果超过十分钟 { //printk("---->time_chg_flag =%d\n", time_chg_flag); gBatCapacity = rk2918_battery_resume_get_Capacity(deltatime); } else { gBatCapacity = rk2918_get_bat_capacity_ext(gBatVoltage); } if(time_chg_flag) time_chg_flag = 0; batteryspendcnt = ts.tv_sec; }
int battery_info_proc(char *buf, char **start, off_t offset, int count, int *eof, void *data) { struct battery_info *info = data; struct timespec cur_time; ktime_t ktime; int len = 0; /* Guess we need no more than 100 bytes. */ int size = 100; ktime = alarm_get_elapsed_realtime(); cur_time = ktime_to_timespec(ktime); len = snprintf(buf, size, "%lu\t%u\t%u\t%u\t%u\t%d\t%u\t%d\t%d\t%u\t" "%u\t%u\t%u\t%u\t%u\t%u\t%d\t%u\t%u\n", cur_time.tv_sec, info->battery_raw_soc, info->battery_soc, info->battery_vcell / 1000, info->battery_vfocv / 1000, info->battery_full_soc, info->battery_present, info->battery_temper, info->battery_temper_adc, info->battery_health, info->charge_real_state, info->charge_virt_state, info->cable_type, info->charge_current, info->full_charged_state, info->recharge_phase, info->abstimer_state, info->monitor_interval, info->charge_start_time); return len; }