static int serial_ir_tx(struct rc_dev *dev, unsigned int *txbuf, unsigned int count) { unsigned long flags; ktime_t edge; s64 delta; int i; spin_lock_irqsave(&hardware[type].lock, flags); if (type == IR_IRDEO) { /* DTR, RTS down */ on(); } edge = ktime_get(); for (i = 0; i < count; i++) { if (i % 2) hardware[type].send_space(); else hardware[type].send_pulse(txbuf[i], edge); edge = ktime_add_us(edge, txbuf[i]); delta = ktime_us_delta(edge, ktime_get()); if (delta > 25) { spin_unlock_irqrestore(&hardware[type].lock, flags); usleep_range(delta - 25, delta + 25); spin_lock_irqsave(&hardware[type].lock, flags); } else if (delta > 0) { udelay(delta); } } off(); spin_unlock_irqrestore(&hardware[type].lock, flags); return count; }
static void send_pulse_homebrew_softcarrier(unsigned int length, ktime_t edge) { ktime_t now, target = ktime_add_us(edge, length); /* * delta should never exceed 4 seconds and on m68k * ndelay(s64) does not compile; so use s32 rather than s64. */ s32 delta; for (;;) { now = ktime_get(); if (ktime_compare(now, target) >= 0) break; on(); edge = ktime_add_ns(edge, serial_ir.pulse_width); delta = ktime_to_ns(ktime_sub(edge, now)); if (delta > 0) ndelay(delta); now = ktime_get(); off(); if (ktime_compare(now, target) >= 0) break; edge = ktime_add_ns(edge, serial_ir.space_width); delta = ktime_to_ns(ktime_sub(edge, now)); if (delta > 0) ndelay(delta); } }
static inline int meson_ao_cec_wait_busy(struct meson_ao_cec_device *ao_cec) { ktime_t timeout = ktime_add_us(ktime_get(), 5000); while (readl_relaxed(ao_cec->base + CEC_RW_REG) & CEC_RW_BUS_BUSY) { if (ktime_compare(ktime_get(), timeout) > 0) return -ETIMEDOUT; } return 0; }
static void softing_initialize_timestamp(struct softing *card) { uint64_t ovf; card->ts_ref = ktime_get(); /* 16MHz is the reference */ ovf = 0x100000000ULL * 16; do_div(ovf, card->pdat->freq ?: 16); card->ts_overflow = ktime_add_us(ktime_set(0, 0), ovf); }
static void xyref5260_lcd_off(void) { gpio_request_one(EXYNOS5260_GPD2(2), GPIOF_OUT_INIT_LOW, "GPD2"); gpio_free(EXYNOS5260_GPD2(2)); usleep_range(5000, 6000); #ifndef CONFIG_BACKLIGHT_PWM gpio_request_one(EXYNOS5260_GPD2(1), GPIOF_OUT_INIT_LOW, "GPD2"); usleep_range(5000, 6000); gpio_free(EXYNOS5260_GPD2(1)); #endif lcd_on_time = ktime_add_us(ktime_get_boottime(), LCD_POWER_OFF_TIME_US); }
static int arasan_phy_addr_poll(struct sdhci_host *host, u32 offset, u32 mask) { ktime_t timeout = ktime_add_us(ktime_get(), 100); bool failed; u8 val = 0; while (1) { failed = ktime_after(ktime_get(), timeout); val = sdhci_readw(host, PHY_ADDR_REG); if (!(val & mask)) return 0; if (failed) return -EBUSY; } }
/* * compute time according to current ts and time_ref data */ void peak_usb_get_ts_time(struct peak_time_ref *time_ref, u32 ts, ktime_t *time) { /* protect from getting time before setting now */ if (ktime_to_ns(time_ref->tv_host)) { u64 delta_us; delta_us = ts - time_ref->ts_dev_2; if (ts < time_ref->ts_dev_2) delta_us &= (1 << time_ref->adapter->ts_used_bits) - 1; delta_us += time_ref->ts_total; delta_us *= time_ref->adapter->us_per_ts_scale; delta_us >>= time_ref->adapter->us_per_ts_shift; *time = ktime_add_us(time_ref->tv_host_0, delta_us); } else {
static void thermal_rtc_setup(void) { ktime_t wakeup_time; ktime_t curr_time; curr_time = alarm_get_elapsed_realtime(); wakeup_time = ktime_add_us(curr_time, (wakeup_ms * USEC_PER_MSEC)); alarm_start_range(&thermal_rtc, wakeup_time, wakeup_time); pr_debug("%s: Current Time: %ld %ld, Alarm set to: %ld %ld\n", KBUILD_MODNAME, ktime_to_timeval(curr_time).tv_sec, ktime_to_timeval(curr_time).tv_usec, ktime_to_timeval(wakeup_time).tv_sec, ktime_to_timeval(wakeup_time).tv_usec); }
static int arasan_phy_sts_poll(struct sdhci_host *host, u32 offset, u32 mask) { int ret; ktime_t timeout = ktime_add_us(ktime_get(), 100); bool failed; u8 val = 0; while (1) { failed = ktime_after(ktime_get(), timeout); ret = arasan_phy_read(host, offset, &val); if (ret) return -EBUSY; else if (val & mask) return 0; if (failed) return -EBUSY; } }
static void wakefunc_rtc_start(void) { ktime_t wakeup_time; ktime_t curr_time; if (!dt2w_switch && !s2w_switch) return; wakefunc_triggered = false; curr_time = alarm_get_elapsed_realtime(); wakeup_time = ktime_add_us(curr_time, (wake_timeout * 1000LL * 60000LL)); alarm_start_range(&wakefunc_rtc, wakeup_time, wakeup_time); pr_info("%s: Current Time: %ld, Alarm set to: %ld\n", WAKEFUNC, ktime_to_timeval(curr_time).tv_sec, ktime_to_timeval(wakeup_time).tv_sec); pr_info("%s: Timeout started for %llu minutes\n", WAKEFUNC, wake_timeout); }
ktime_t softing_raw2ktime(struct softing *card, u32 raw) { uint64_t rawl; ktime_t now, real_offset; ktime_t target; ktime_t tmp; now = ktime_get(); real_offset = ktime_sub(ktime_get_real(), now); /* find nsec from card */ rawl = raw * 16; do_div(rawl, card->pdat->freq ?: 16); target = ktime_add_us(card->ts_ref, rawl); /* test for overflows */ tmp = ktime_add(target, card->ts_overflow); while (unlikely(ktime_to_ns(tmp) > ktime_to_ns(now))) { card->ts_ref = ktime_add(card->ts_ref, card->ts_overflow); target = tmp; tmp = ktime_add(target, card->ts_overflow); } return ktime_add(target, real_offset); }
static ssize_t ir_lirc_transmit_ir(struct file *file, const char __user *buf, size_t n, loff_t *ppos) { struct lirc_codec *lirc; struct rc_dev *dev; unsigned int *txbuf; /* buffer with values to transmit */ ssize_t ret = -EINVAL; size_t count; ktime_t start; s64 towait; unsigned int duration = 0; /* signal duration in us */ int i; start = ktime_get(); lirc = lirc_get_pdata(file); if (!lirc) return -EFAULT; if (n < sizeof(unsigned) || n % sizeof(unsigned)) return -EINVAL; count = n / sizeof(unsigned); if (count > LIRCBUF_SIZE || count % 2 == 0) return -EINVAL; txbuf = memdup_user(buf, n); if (IS_ERR(txbuf)) return PTR_ERR(txbuf); dev = lirc->dev; if (!dev) { ret = -EFAULT; goto out; } if (!dev->tx_ir) { ret = -ENOSYS; goto out; } ret = dev->tx_ir(dev, txbuf, count); if (ret < 0) goto out; for (i = 0; i < ret; i++) duration += txbuf[i]; ret *= sizeof(unsigned int); /* * The lircd gap calculation expects the write function to * wait for the actual IR signal to be transmitted before * returning. */ towait = ktime_us_delta(ktime_add_us(start, duration), ktime_get()); if (towait > 0) { set_current_state(TASK_INTERRUPTIBLE); schedule_timeout(usecs_to_jiffies(towait)); } out: kfree(txbuf); return ret; }
static void manta_lcd_off(void) { gpio_set_value(GPIO_LCD_EN, 0); lcd_on_time = ktime_add_us(ktime_get_boottime(), LCD_POWER_OFF_TIME_US); }