int wait_for_keypress(ulong msec) { ulong kv; ulong ini, end; int ret = 0; int handled = 0; pressed_key = 0;/* Reset KEY press */ ulong usec = msec * 1000;/* milli sec to micro sec */ /* scan for key at one first */ keypad_scan(); /* set bit 1 in KEYPAD_IRQ_EN register to enable IRQ */ writel(0x01, KEYPAD_IRQ_EN); /* For delays mor than 10 sec we need loop for every chunks of 10 sec */ do { kv = usec > PERIOD ? PERIOD : usec; ini = get_curr_timer(); end = ini + (ulong)usec2ticks(kv); while ((signed)(end - get_curr_timer()) > 0) { if (readl(KEYPAD_IRQ_STATUS)) keypad_scan(); } usec -= kv; } while (usec); /* set bit 1 in KEYPAD_IRQ_CLEAR register to clear IRQ */ writel(0x01, KEYPAD_IRQ_CLEAR); /* set bit 0 in KEYPAD_IRQ_EN register to disable IRQ */ writel(0x00, KEYPAD_IRQ_EN); look_up_key_comb(pressed_key, &handled); return ret; }
int wait_for_keypress_forever(void) { int handled = 0; int ret = 0; ulong ini, end; /* Reset KEY press */ pressed_key = 0; /* set bit 1 in KEYPAD_IRQ_EN register to enable IRQ */ writel(0x01, KEYPAD_IRQ_EN); do { ini = get_curr_timer(); end = ini + (ulong)usec2ticks(PERIOD); while ((signed)(end - get_curr_timer()) > 0) { if (readl(KEYPAD_IRQ_STATUS)) keypad_scan(); } ret = look_up_key_comb(pressed_key, &handled); if (handled == 1) break; } while (1); /* set bit 1 in KEYPAD_IRQ_CLEAR register to clear IRQ */ writel(0x01, KEYPAD_IRQ_CLEAR); /* set bit 0 in KEYPAD_IRQ_EN register to disable IRQ */ writel(0x00, KEYPAD_IRQ_EN); return ret; }
/* * We implement the delay by converting the delay (the number of * microseconds to wait) into a number of time base ticks; then we * watch the time base until it has incremented by that amount. */ void udelay(unsigned long usec) { ulong ticks, kv; do { kv = usec > CONFIG_WD_PERIOD ? CONFIG_WD_PERIOD : usec; ticks = usec2ticks (kv); wait_ticks (ticks); usec -= kv; } while(usec); }
int run_descriptor_jr(uint32_t *desc) { unsigned long long timeval = get_ticks(); unsigned long long timeout = usec2ticks(CONFIG_SEC_DEQ_TIMEOUT); struct result op; int ret = 0; memset(&op, sizeof(op), 0); ret = jr_enqueue(desc, desc_done, &op); if (ret) { debug("Error in SEC enq\n"); ret = JQ_ENQ_ERR; goto out; } timeval = get_ticks(); timeout = usec2ticks(CONFIG_SEC_DEQ_TIMEOUT); while (op.done != 1) { ret = jr_dequeue(); if (ret) { debug("Error in SEC deq\n"); ret = JQ_DEQ_ERR; goto out; } if ((get_ticks() - timeval) > timeout) { debug("SEC Dequeue timed out\n"); ret = JQ_DEQ_TO_ERR; goto out; } } if (!op.status) { debug("Error %x\n", op.status); ret = op.status; } out: return ret; }
/* * We implement the delay by converting the delay (the number of * microseconds to wait) into a number of time base ticks; then we * watch the time base until it has incremented by that amount. */ void __udelay(unsigned long usec) { ulong ticks = usec2ticks(usec); wait_ticks(ticks); }