All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 11/31] cros_ec: Support systems with no EC interrupt
Date: Thu, 27 Feb 2014 13:26:05 -0700	[thread overview]
Message-ID: <1393532785-9020-12-git-send-email-sjg@chromium.org> (raw)
In-Reply-To: <1393532785-9020-1-git-send-email-sjg@chromium.org>

Some systems do not have an EC interrupt. Rather than assuming that the
interrupt is always present, and hanging forever waiting for more input,
handle the missing interrupt. This works by reading key scans only until
we get an identical one. This means the EC keyscan FIFO is empty.

Tested-by: Che-Liang Chiou <clchiou@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v2: None

 drivers/input/cros_ec_keyb.c | 34 ++++++++++++++++++++++++++++++----
 1 file changed, 30 insertions(+), 4 deletions(-)

diff --git a/drivers/input/cros_ec_keyb.c b/drivers/input/cros_ec_keyb.c
index e8dac23..a2501e0 100644
--- a/drivers/input/cros_ec_keyb.c
+++ b/drivers/input/cros_ec_keyb.c
@@ -8,6 +8,7 @@
 
 #include <common.h>
 #include <cros_ec.h>
+#include <errno.h>
 #include <fdtdec.h>
 #include <input.h>
 #include <key_matrix.h>
@@ -39,20 +40,34 @@ static struct keyb {
  * @param config	Keyboard config
  * @param keys		List of keys that we have detected
  * @param max_count	Maximum number of keys to return
- * @return number of pressed keys, 0 for none
+ * @param samep		Set to true if this scan repeats the last, else false
+ * @return number of pressed keys, 0 for none, -EIO on error
  */
 static int check_for_keys(struct keyb *config,
-			   struct key_matrix_key *keys, int max_count)
+			   struct key_matrix_key *keys, int max_count,
+			   bool *samep)
 {
 	struct key_matrix_key *key;
+	static struct mbkp_keyscan last_scan;
+	static bool last_scan_valid;
 	struct mbkp_keyscan scan;
 	unsigned int row, col, bit, data;
 	int num_keys;
 
 	if (cros_ec_scan_keyboard(config->dev, &scan)) {
 		debug("%s: keyboard scan failed\n", __func__);
-		return -1;
+		return -EIO;
 	}
+	*samep = last_scan_valid && !memcmp(&last_scan, &scan, sizeof(scan));
+
+	/*
+	 * This is a bit odd. The EC has no way to tell us that it has run
+	 * out of key scans. It just returns the same scan over and over
+	 * again. So the only way to detect that we have run out is to detect
+	 * that this scan is the same as the last.
+	 */
+	last_scan_valid = true;
+	memcpy(&last_scan, &scan, sizeof(last_scan));
 
 	for (col = num_keys = bit = 0; col < config->matrix.num_cols;
 			col++) {
@@ -112,6 +127,7 @@ int cros_ec_kbc_check(struct input_config *input)
 	int keycodes[KBC_MAX_KEYS];
 	int num_keys, num_keycodes;
 	int irq_pending, sent;
+	bool same = false;
 
 	/*
 	 * Loop until the EC has no more keyscan records, or we have
@@ -125,7 +141,10 @@ int cros_ec_kbc_check(struct input_config *input)
 	do {
 		irq_pending = cros_ec_interrupt_pending(config.dev);
 		if (irq_pending) {
-			num_keys = check_for_keys(&config, keys, KBC_MAX_KEYS);
+			num_keys = check_for_keys(&config, keys, KBC_MAX_KEYS,
+						  &same);
+			if (num_keys < 0)
+				return 0;
 			last_num_keys = num_keys;
 			memcpy(last_keys, keys, sizeof(keys));
 		} else {
@@ -142,6 +161,13 @@ int cros_ec_kbc_check(struct input_config *input)
 		num_keycodes = key_matrix_decode(&config.matrix, keys,
 				num_keys, keycodes, KBC_MAX_KEYS);
 		sent = input_send_keycodes(input, keycodes, num_keycodes);
+
+		/*
+		 * For those ECs without an interrupt, stop scanning when we
+		 * see that the scan is the same as last time.
+		 */
+		if ((irq_pending < 0) && same)
+			break;
 	} while (irq_pending && !sent);
 
 	return 1;
-- 
1.9.0.279.gdc9e3eb

  parent reply	other threads:[~2014-02-27 20:26 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-27 20:25 [PATCH v2 0/31] Add additional sandbox features and infrastructure Simon Glass
2014-02-27 20:25 ` [U-Boot] " Simon Glass
2014-02-27 20:25 ` [U-Boot] [PATCH v2 01/31] Use a const pointer for map_to_sysmem() Simon Glass
2014-02-27 20:25 ` [U-Boot] [PATCH v2 02/31] sandbox: Increase memory size to 32MB Simon Glass
2014-02-27 20:25 ` [U-Boot] [PATCH v2 03/31] sandbox: Build a device tree file for sandbox Simon Glass
2014-02-27 20:25 ` [U-Boot] [PATCH v2 04/31] sandbox: Use os functions to read host device tree Simon Glass
     [not found] ` <1393532785-9020-1-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2014-02-27 20:25   ` [PATCH v2 05/31] sandbox: dts: Add display and keyboard to sandbox Simon Glass
2014-02-27 20:25     ` [U-Boot] " Simon Glass
2014-02-27 20:26 ` [U-Boot] [PATCH v2 06/31] cros_ec: Add an enum for the number of flash regions Simon Glass
2014-02-27 20:26 ` [U-Boot] [PATCH v2 07/31] cros_ec: Add a function for reading a flash map entry Simon Glass
2014-02-27 20:26 ` [U-Boot] [PATCH v2 08/31] cros_ec: Move EC interface into common library Simon Glass
2014-02-27 20:26 ` [U-Boot] [PATCH v2 09/31] cros_ec: Add a function for decoding the Chrome OS EC flashmap Simon Glass
2014-02-27 20:26 ` [U-Boot] [PATCH v2 10/31] cros_ec: Drop old EC version support from EC driver Simon Glass
2014-02-27 20:26 ` Simon Glass [this message]
2014-02-27 20:26 ` [U-Boot] [PATCH v2 12/31] cros_ec: Move #ifdef to permit flash region access Simon Glass
2014-02-27 20:26 ` [U-Boot] [PATCH v2 13/31] cros_ec: Sync up with latest Chrome OS EC version Simon Glass
2014-02-27 20:26 ` [U-Boot] [PATCH v2 14/31] cros_ec: Clean up multiple EC protocol support Simon Glass
2014-02-27 20:26 ` [U-Boot] [PATCH v2 15/31] cros_ec: Add base support for protocol v3 Simon Glass
2014-02-27 20:26 ` [U-Boot] [PATCH v2 16/31] cros_ec: spi: Add support for EC protocol version 3 Simon Glass
2014-02-27 20:26 ` [U-Boot] [PATCH v2 17/31] cros_ec: Correct comparison between signed and unsigned numbers Simon Glass
2014-02-27 20:26 ` [U-Boot] [PATCH v2 18/31] cros_ec: sandbox: Add Chrome OS EC emulation Simon Glass
2014-02-27 20:26 ` [U-Boot] [PATCH v2 19/31] sandbox: Plumb in " Simon Glass
2014-02-27 20:26 ` [U-Boot] [PATCH v2 20/31] cros_ec: Implement I2C pass-through Simon Glass
2014-02-27 20:26 ` [U-Boot] [PATCH v2 21/31] sandbox: Add os_jump_to_image() to run another executable Simon Glass
2014-02-27 20:26 ` [U-Boot] [PATCH v2 22/31] sandbox: Add -j option to indicate a jump from a previous U-Boot Simon Glass
2014-02-27 20:26 ` [U-Boot] [PATCH v2 23/31] sandbox: Add SDL library for LCD, keyboard, audio Simon Glass
2014-02-27 20:26 ` [U-Boot] [PATCH v2 24/31] sandbox: Add a simple sound driver Simon Glass
2014-02-27 20:26 ` [U-Boot] [PATCH v2 25/31] sandbox: Add LCD driver Simon Glass
2014-02-27 20:26 ` [U-Boot] [PATCH v2 26/31] sound: Move Samsung-specific code into its own file Simon Glass
2014-02-27 20:26 ` [U-Boot] [PATCH v2 27/31] sandbox: Deal with conflicting getenv() for SDL Simon Glass
2014-02-27 20:26 ` [U-Boot] [PATCH v2 28/31] sandbox: Allow Ctrl-C to work in sandbox Simon Glass
2014-02-27 20:26 ` [U-Boot] [PATCH v2 29/31] sandbox: Add options to clean up temporary files Simon Glass
2014-02-27 20:26 ` [U-Boot] [PATCH v2 30/31] sandbox: Add implementation of spi_setup_slave_fdt() Simon Glass
2014-02-27 20:26 ` [U-Boot] [PATCH v2 31/31] sandbox: config: Enable cros_ec emulation and related items Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1393532785-9020-12-git-send-email-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.