All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Antti Seppälä" <a.seppala@gmail.com>
To: Mauro Carvalho Chehab <m.chehab@samsung.com>
Cc: linux-media@vger.kernel.org, "Antti Seppälä" <a.seppala@gmail.com>
Subject: [RFC PATCH 4/4] nuvoton-cir: Add support for reading/writing wakeup scancodes via sysfs
Date: Mon, 20 Jan 2014 21:39:47 +0200	[thread overview]
Message-ID: <1390246787-15616-5-git-send-email-a.seppala@gmail.com> (raw)
In-Reply-To: <1390246787-15616-1-git-send-email-a.seppala@gmail.com>

This patch adds support for reading/writing wakeup scancodes via sysfs
to nuvoton-cir hardware.

Signed-off-by: Antti Seppälä <a.seppala@gmail.com>
---
 drivers/media/rc/nuvoton-cir.c | 81 ++++++++++++++++++++++++++++++++++++++++++
 drivers/media/rc/nuvoton-cir.h |  2 ++
 2 files changed, 83 insertions(+)

diff --git a/drivers/media/rc/nuvoton-cir.c b/drivers/media/rc/nuvoton-cir.c
index 21ee0dc..c1b0cf2 100644
--- a/drivers/media/rc/nuvoton-cir.c
+++ b/drivers/media/rc/nuvoton-cir.c
@@ -531,6 +531,86 @@ static int nvt_set_tx_carrier(struct rc_dev *dev, u32 carrier)
 	return 0;
 }
 
+static int nvt_wakeup_scancodes(struct rc_dev *dev,
+				struct list_head *scancode_list, int write)
+{
+	int i = 0;
+	u8 cnt, reg, reg_learn_mode;
+	unsigned long flags;
+	struct rc_wakeup_scancode *scancode;
+	struct nvt_dev *nvt = dev->priv;
+
+	if (write) {
+		nvt_dbg_wake("%s firing, write", __func__);
+
+		reg = nvt_cir_wake_reg_read(nvt, CIR_WAKE_IRCON);
+		reg_learn_mode = reg & ~CIR_WAKE_IRCON_MODE0;
+		reg_learn_mode |= CIR_WAKE_IRCON_MODE1;
+
+		/* Lock the learn area to prevent racing with wake-isr */
+		spin_lock_irqsave(&nvt->nvt_lock, flags);
+
+		/* Enable fifo writes */
+		nvt_cir_wake_reg_write(nvt, reg_learn_mode, CIR_WAKE_IRCON);
+
+		/* Clear cir wake rx fifo */
+		nvt_clear_cir_wake_fifo(nvt);
+
+		/* Write wake samples to fifo */
+		list_for_each_entry_reverse(scancode, scancode_list,
+					    list_item) {
+			/* Prevent writing too many codes */
+			if (++i > WAKE_FIFO_LEN)
+				break;
+			nvt_cir_wake_reg_write(nvt, scancode->value,
+					       CIR_WAKE_WR_FIFO_DATA);
+		}
+
+		/* Switch cir to wakeup mode and disable fifo writing */
+		nvt_cir_wake_reg_write(nvt, reg, CIR_WAKE_IRCON);
+
+		/* Set number of bytes needed for wake */
+		nvt_cir_wake_reg_write(nvt, i ? i :
+				       CIR_WAKE_FIFO_CMP_BYTES,
+				       CIR_WAKE_FIFO_CMP_DEEP);
+
+		spin_unlock_irqrestore(&nvt->nvt_lock, flags);
+
+		if (i > WAKE_FIFO_LEN)
+			return -EINVAL;
+	} else {
+		nvt_dbg_wake("%s firing, read", __func__);
+
+		/* Scroll to index 0 */
+		while (nvt_cir_wake_reg_read(nvt, CIR_WAKE_RD_FIFO_ONLY_IDX)) {
+			nvt_cir_wake_reg_read(nvt, CIR_WAKE_RD_FIFO_ONLY);
+
+			/* Stuck index guardian */
+			if (++i > 255) {
+				nvt_dbg_wake("Idx reg is stuck!");
+				break;
+			}
+		}
+
+		/* Get size of wake fifo and allocate memory for the bytes */
+		cnt = nvt_cir_wake_reg_read(nvt, CIR_WAKE_FIFO_COUNT);
+
+		for (i = 0; i < cnt; i++) {
+			scancode = kmalloc(sizeof(struct rc_wakeup_scancode),
+					   GFP_KERNEL | GFP_ATOMIC);
+			if (!scancode)
+				return -ENOMEM;
+			scancode->value =
+				nvt_cir_wake_reg_read(nvt,
+						      CIR_WAKE_RD_FIFO_ONLY);
+			list_add(&scancode->list_item, scancode_list);
+		}
+
+		return cnt;
+	}
+
+	return 0;
+}
 /*
  * nvt_tx_ir
  *
@@ -1047,6 +1127,7 @@ static int nvt_probe(struct pnp_dev *pdev, const struct pnp_device_id *dev_id)
 	rdev->close = nvt_close;
 	rdev->tx_ir = nvt_tx_ir;
 	rdev->s_tx_carrier = nvt_set_tx_carrier;
+	rdev->s_wakeup_scancodes = nvt_wakeup_scancodes;
 	rdev->input_name = "Nuvoton w836x7hg Infrared Remote Transceiver";
 	rdev->input_phys = "nuvoton/cir0";
 	rdev->input_id.bustype = BUS_HOST;
diff --git a/drivers/media/rc/nuvoton-cir.h b/drivers/media/rc/nuvoton-cir.h
index 07e8310..24ff630 100644
--- a/drivers/media/rc/nuvoton-cir.h
+++ b/drivers/media/rc/nuvoton-cir.h
@@ -64,6 +64,8 @@ static int debug;
 #define TX_BUF_LEN 256
 #define RX_BUF_LEN 32
 
+#define WAKE_FIFO_LEN 67
+
 struct nvt_dev {
 	struct pnp_dev *pdev;
 	struct rc_dev *rdev;
-- 
1.8.3.2


  parent reply	other threads:[~2014-01-20 19:40 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-03 14:18 [PATCH] nuvoton-cir: Add support for user configurable wake-up codes Antti Seppälä
2014-01-15 19:35 ` Mauro Carvalho Chehab
2014-01-20 19:39   ` [RFC PATCH 0/4] rc: Adding support for sysfs wakeup scancodes Antti Seppälä
2014-01-20 19:39     ` [RFC PATCH 1/4] rc-core: Add defintions needed for sysfs callback Antti Seppälä
2014-01-20 19:39     ` [RFC PATCH 2/4] rc-core: Add support for reading/writing wakeup scancodes via sysfs Antti Seppälä
2014-01-20 19:39     ` [RFC PATCH 3/4] rc-loopback: " Antti Seppälä
2014-01-20 19:39     ` Antti Seppälä [this message]
2014-01-21 12:28     ` [RFC PATCH 0/4] rc: Adding support for sysfs wakeup scancodes Sean Young
2014-01-22 15:46       ` Antti Seppälä
2014-01-22 16:29         ` Sean Young
2014-01-22 19:10           ` Antti Seppälä
2014-01-22 19:21             ` Antti Palosaari
2014-01-22 21:00             ` Sean Young
2014-01-22 22:01               ` Mauro Carvalho Chehab
2014-01-23 19:11                 ` Antti Seppälä
2014-02-04 17:54                   ` Mauro Carvalho Chehab
2014-02-05  7:03                     ` Antti Seppälä
2014-02-05  9:36                       ` Mauro Carvalho Chehab
2014-02-05  9:39                       ` James Hogan
2014-02-05  9:42                         ` James Hogan
2014-02-05 18:16                           ` Antti Seppälä
2014-02-05 21:21                             ` Mauro Carvalho Chehab
2014-02-06 10:46                               ` James Hogan
2014-02-06 14:55                                 ` Mauro Carvalho Chehab

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=1390246787-15616-5-git-send-email-a.seppala@gmail.com \
    --to=a.seppala@gmail.com \
    --cc=linux-media@vger.kernel.org \
    --cc=m.chehab@samsung.com \
    /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.