From: "Antti Seppälä" <a.seppala@gmail.com>
To: James Hogan <james.hogan@imgtec.com>
Cc: "Mauro Carvalho Chehab" <m.chehab@samsung.com>,
linux-media@vger.kernel.org,
"Antti Seppälä" <a.seppala@gmail.com>
Subject: [RFC PATCH 3/3] nuvoton-cir: Add support for writing wakeup samples via sysfs filter callback
Date: Sat, 8 Feb 2014 14:07:30 +0200 [thread overview]
Message-ID: <1391861250-26068-4-git-send-email-a.seppala@gmail.com> (raw)
In-Reply-To: <1391861250-26068-1-git-send-email-a.seppala@gmail.com>
Nuvoton-cir utilizes the encoding capabilities of currently active protocols
to convert scancodes from user space to pulse/space format understood by the
underlying hardware.
Samples are then written to the wakeup fifo along with other necessary
configuration to enable wake up functionality.
Signed-off-by: Antti Seppälä <a.seppala@gmail.com>
---
drivers/media/rc/nuvoton-cir.c | 121 +++++++++++++++++++++++++++++++++++++++++
drivers/media/rc/nuvoton-cir.h | 1 +
include/media/rc-core.h | 1 +
3 files changed, 123 insertions(+)
diff --git a/drivers/media/rc/nuvoton-cir.c b/drivers/media/rc/nuvoton-cir.c
index b41e52e..e4a4c5d 100644
--- a/drivers/media/rc/nuvoton-cir.c
+++ b/drivers/media/rc/nuvoton-cir.c
@@ -527,6 +527,126 @@ static int nvt_set_tx_carrier(struct rc_dev *dev, u32 carrier)
return 0;
}
+static int nvt_write_wakeup_codes(struct rc_dev *dev,
+ const u8 *wakeup_sample_buf, int count)
+{
+ int i = 0;
+ u8 reg, reg_learn_mode;
+ unsigned long flags;
+ struct nvt_dev *nvt = dev->priv;
+
+ nvt_dbg_wake("writing wakeup samples");
+
+ 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);
+
+ if (count)
+ pr_info("Wake samples (%d) =", count);
+ else
+ pr_info("Wake sample fifo cleared");
+
+ /* Write wake samples to fifo */
+ for (i = 0; i < count; i++) {
+ pr_cont(" %02x", wakeup_sample_buf[i]);
+ nvt_cir_wake_reg_write(nvt, wakeup_sample_buf[i],
+ CIR_WAKE_WR_FIFO_DATA);
+ }
+ pr_cont("\n");
+
+ /* 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, count ? count :
+ CIR_WAKE_FIFO_CMP_BYTES,
+ CIR_WAKE_FIFO_CMP_DEEP);
+
+ spin_unlock_irqrestore(&nvt->nvt_lock, flags);
+
+ return 0;
+}
+
+static int nvt_ir_raw_set_filter(struct rc_dev *dev, enum rc_filter_type type,
+ struct rc_scancode_filter *sc_filter)
+{
+ u8 *reg_buf;
+ int i, ret, count = 0;
+ unsigned int val;
+ struct ir_raw_event *raw;
+
+ /* Other types are not valid for nuvoton */
+ if (type != RC_FILTER_WAKEUP)
+ return -EINVAL;
+
+ /* Require both mask and data to be set before actually committing */
+ if (!sc_filter->mask || !sc_filter->data)
+ return 0;
+
+ raw = kmalloc(WAKE_FIFO_LEN * sizeof(*raw), GFP_KERNEL);
+ if (!raw)
+ return -ENOMEM;
+
+ ret = ir_raw_encode_scancode(dev->enabled_protocols, sc_filter, raw,
+ WAKE_FIFO_LEN);
+ if (ret < 0)
+ goto out_raw;
+
+ if (ret > WAKE_FIFO_LEN) {
+ pr_info("Scancode size (%d) will not fit in wake fifo (%d)",
+ ret, WAKE_FIFO_LEN);
+ ret = -EINVAL;
+ goto out_raw;
+ }
+
+ reg_buf = kmalloc(sizeof(*reg_buf) * WAKE_FIFO_LEN, GFP_KERNEL);
+ if (!reg_buf) {
+ ret = -ENOMEM;
+ goto out_raw;
+ }
+
+ /* Inspect the ir samples */
+ for (i = 0; i < ret; ++i) {
+ val = NS_TO_US((raw[i]).duration) / SAMPLE_PERIOD;
+
+ /* Split too large values into several smaller ones */
+ while (val > BUF_LEN_MASK) {
+ if (count > WAKE_FIFO_LEN) {
+ ret = -EINVAL;
+ goto out_reg;
+ }
+ reg_buf[count] = BUF_LEN_MASK;
+ val -= BUF_LEN_MASK;
+ if ((raw[i]).pulse)
+ reg_buf[count] |= BUF_PULSE_BIT;
+ count++;
+ }
+
+ if ((raw[i]).pulse)
+ val |= BUF_PULSE_BIT;
+ reg_buf[count] = val;
+ count++;
+ }
+
+ ret = nvt_write_wakeup_codes(dev, reg_buf, count);
+
+out_reg:
+ kfree(reg_buf);
+out_raw:
+ kfree(raw);
+
+ return ret;
+}
+
/*
* nvt_tx_ir
*
@@ -1043,6 +1163,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_filter = nvt_ir_raw_set_filter;
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 e1cf23c..9d0e161 100644
--- a/drivers/media/rc/nuvoton-cir.h
+++ b/drivers/media/rc/nuvoton-cir.h
@@ -63,6 +63,7 @@ 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;
diff --git a/include/media/rc-core.h b/include/media/rc-core.h
index 81cddd3..6b12a1b 100644
--- a/include/media/rc-core.h
+++ b/include/media/rc-core.h
@@ -227,6 +227,7 @@ static inline void init_ir_raw_event(struct ir_raw_event *ev)
#define US_TO_NS(usec) ((usec) * 1000)
#define MS_TO_US(msec) ((msec) * 1000)
#define MS_TO_NS(msec) ((msec) * 1000 * 1000)
+#define NS_TO_US(nsec) DIV_ROUND_UP(nsec, 1000L)
void ir_raw_event_handle(struct rc_dev *dev);
int ir_raw_event_store(struct rc_dev *dev, struct ir_raw_event *ev);
--
1.8.3.2
next prev parent reply other threads:[~2014-02-08 12:08 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-06 19:59 [RFC 0/4] rc: ir-raw: Add encode, implement NEC encode James Hogan
2014-02-06 19:59 ` [RFC 1/4] rc: ir-raw: add scancode encoder callback James Hogan
2014-02-06 19:59 ` [RFC 2/4] rc: ir-raw: add modulation helpers James Hogan
2014-02-06 19:59 ` [RFC 3/4] rc: ir-nec-decoder: add encode capability James Hogan
2014-02-06 19:59 ` [RFC 4/4] DEBUG: rc: img-ir: raw: Add loopback on s_filter James Hogan
2014-02-08 11:30 ` [RFC 0/4] rc: ir-raw: Add encode, implement NEC encode Antti Seppälä
2014-02-08 12:07 ` [RFC PATCH 0/3] rc: add RC5-SZ encoder and utilize encoders in nuvoton-cir Antti Seppälä
2014-02-08 12:07 ` [RFC PATCH 1/3] rc-core: Add Manchester encoder (phase encoder) support to rc-core Antti Seppälä
2014-02-10 10:25 ` James Hogan
2014-02-10 19:56 ` Antti Seppälä
2014-02-08 12:07 ` [RFC PATCH 2/3] ir-rc5-sz: Add ir encoding support Antti Seppälä
2014-02-10 10:30 ` James Hogan
2014-02-10 20:09 ` Antti Seppälä
2014-02-10 20:50 ` James Hogan
2014-02-11 18:14 ` Antti Seppälä
2014-02-11 23:39 ` James Hogan
2014-02-16 17:04 ` Antti Seppälä
2014-02-27 22:43 ` James Hogan
2014-02-16 16:45 ` [RFCv2 PATCH 0/3] rc: add RC5-SZ encoder and utilize encoders in nuvoton-cir Antti Seppälä
2014-02-16 16:45 ` [RFCv2 PATCH 1/3] rc-core: Add Manchester encoder (phase encoder) support to rc-core Antti Seppälä
2014-02-16 16:45 ` [RFCv2 PATCH 2/3] ir-rc5-sz: Add ir encoding support Antti Seppälä
2014-02-16 16:45 ` [RFCv2 PATCH 3/3] nuvoton-cir: Add support for writing wakeup samples via sysfs filter callback Antti Seppälä
2014-02-08 12:07 ` Antti Seppälä [this message]
2014-02-10 9:58 ` [RFC 0/4] rc: ir-raw: Add encode, implement NEC encode James Hogan
2014-02-10 19:45 ` Antti Seppälä
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=1391861250-26068-4-git-send-email-a.seppala@gmail.com \
--to=a.seppala@gmail.com \
--cc=james.hogan@imgtec.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox