aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEven Xu <even.xu@intel.com>2016-11-10 20:40:23 -0500
committerJiri Kosina <jkosina@suse.cz>2016-11-16 05:42:39 -0500
commit7ede704d746e7c02219cdd44abe22c0b606e70db (patch)
tree7ebe9ae99814988b35b31dc93c3b97e93d9e14df
parentfa39baa9700c86a73b2203eab92dbba7eb2d4d69 (diff)
HID: intel-ish-hid: ipc: change timed_wait_for_timeout() to be a function
The macro timed_wait_for_timeout() only be used in one function, so move this marco from header file and change it to a function in ipc.c, where it is used. Signed-off-by: Even Xu <even.xu@intel.com> Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
-rw-r--r--drivers/hid/intel-ish-hid/ipc/ipc.c62
-rw-r--r--drivers/hid/intel-ish-hid/ipc/utils.h43
2 files changed, 57 insertions, 48 deletions
diff --git a/drivers/hid/intel-ish-hid/ipc/ipc.c b/drivers/hid/intel-ish-hid/ipc/ipc.c
index 0c9ac4d5d850..3d46cc0eec70 100644
--- a/drivers/hid/intel-ish-hid/ipc/ipc.c
+++ b/drivers/hid/intel-ish-hid/ipc/ipc.c
@@ -19,7 +19,6 @@
19#include <linux/jiffies.h> 19#include <linux/jiffies.h>
20#include "client.h" 20#include "client.h"
21#include "hw-ish.h" 21#include "hw-ish.h"
22#include "utils.h"
23#include "hbm.h" 22#include "hbm.h"
24 23
25/* For FW reset flow */ 24/* For FW reset flow */
@@ -427,6 +426,59 @@ static int ipc_send_mng_msg(struct ishtp_device *dev, uint32_t msg_code,
427 sizeof(uint32_t) + size); 426 sizeof(uint32_t) + size);
428} 427}
429 428
429#define WAIT_FOR_FW_RDY 0x1
430#define WAIT_FOR_INPUT_RDY 0x2
431
432/**
433 * timed_wait_for_timeout() - wait special event with timeout
434 * @dev: ISHTP device pointer
435 * @condition: indicate the condition for waiting
436 * @timeinc: time slice for every wait cycle, in ms
437 * @timeout: time in ms for timeout
438 *
439 * This function will check special event to be ready in a loop, the loop
440 * period is specificd in timeinc. Wait timeout will causes failure.
441 *
442 * Return: 0 for success else failure code
443 */
444static int timed_wait_for_timeout(struct ishtp_device *dev, int condition,
445 unsigned int timeinc, unsigned int timeout)
446{
447 bool complete = false;
448 int ret;
449
450 do {
451 if (condition == WAIT_FOR_FW_RDY) {
452 complete = ishtp_fw_is_ready(dev);
453 } else if (condition == WAIT_FOR_INPUT_RDY) {
454 complete = ish_is_input_ready(dev);
455 } else {
456 ret = -EINVAL;
457 goto out;
458 }
459
460 if (!complete) {
461 unsigned long left_time;
462
463 left_time = msleep_interruptible(timeinc);
464 timeout -= (timeinc - left_time);
465 }
466 } while (!complete && timeout > 0);
467
468 if (complete)
469 ret = 0;
470 else
471 ret = -EBUSY;
472
473out:
474 return ret;
475}
476
477#define TIME_SLICE_FOR_FW_RDY_MS 100
478#define TIME_SLICE_FOR_INPUT_RDY_MS 100
479#define TIMEOUT_FOR_FW_RDY_MS 2000
480#define TIMEOUT_FOR_INPUT_RDY_MS 2000
481
430/** 482/**
431 * ish_fw_reset_handler() - FW reset handler 483 * ish_fw_reset_handler() - FW reset handler
432 * @dev: ishtp device pointer 484 * @dev: ishtp device pointer
@@ -456,8 +508,8 @@ static int ish_fw_reset_handler(struct ishtp_device *dev)
456 ishtp_reset_handler(dev); 508 ishtp_reset_handler(dev);
457 509
458 if (!ish_is_input_ready(dev)) 510 if (!ish_is_input_ready(dev))
459 timed_wait_for_timeout(WAIT_FOR_SEND_SLICE, 511 timed_wait_for_timeout(dev, WAIT_FOR_INPUT_RDY,
460 ish_is_input_ready(dev), (2 * HZ)); 512 TIME_SLICE_FOR_INPUT_RDY_MS, TIMEOUT_FOR_INPUT_RDY_MS);
461 513
462 /* ISH FW is dead */ 514 /* ISH FW is dead */
463 if (!ish_is_input_ready(dev)) 515 if (!ish_is_input_ready(dev))
@@ -472,8 +524,8 @@ static int ish_fw_reset_handler(struct ishtp_device *dev)
472 sizeof(uint32_t)); 524 sizeof(uint32_t));
473 525
474 /* Wait for ISH FW'es ILUP and ISHTP_READY */ 526 /* Wait for ISH FW'es ILUP and ISHTP_READY */
475 timed_wait_for_timeout(WAIT_FOR_SEND_SLICE, ishtp_fw_is_ready(dev), 527 timed_wait_for_timeout(dev, WAIT_FOR_FW_RDY,
476 (2 * HZ)); 528 TIME_SLICE_FOR_FW_RDY_MS, TIMEOUT_FOR_FW_RDY_MS);
477 if (!ishtp_fw_is_ready(dev)) { 529 if (!ishtp_fw_is_ready(dev)) {
478 /* ISH FW is dead */ 530 /* ISH FW is dead */
479 uint32_t ish_status; 531 uint32_t ish_status;
diff --git a/drivers/hid/intel-ish-hid/ipc/utils.h b/drivers/hid/intel-ish-hid/ipc/utils.h
deleted file mode 100644
index dc39dfe2464e..000000000000
--- a/drivers/hid/intel-ish-hid/ipc/utils.h
+++ /dev/null
@@ -1,43 +0,0 @@
1/*
2 * Utility macros of ISH
3 *
4 * Copyright (c) 2014-2016, Intel Corporation.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 */
15#ifndef UTILS__H
16#define UTILS__H
17
18#define WAIT_FOR_SEND_SLICE (HZ / 10)
19#define WAIT_FOR_CONNECT_SLICE (HZ / 10)
20
21/*
22 * Waits for specified event when a thread that triggers event
23 * can't signal with timeout (use whenever we may hang)
24 */
25#define timed_wait_for_timeout(timeinc, condition, timeout) \
26 do { \
27 int t = timeout; \
28 do { \
29 unsigned long j; \
30 int done = 0; \
31 \
32 for (j = jiffies, done = 0; !done; ) { \
33 schedule_timeout(timeinc); \
34 if (time_is_before_eq_jiffies(j + timeinc)) \
35 done = 1; \
36 } \
37 t -= timeinc; \
38 if (t <= 0) \
39 break; \
40 } while (!(condition)); \
41 } while (0)
42
43#endif /* UTILS__H */