From: "Antti Seppälä" <a.seppala@gmail.com>
To: linux-media@vger.kernel.org
Cc: "Mauro Carvalho Chehab" <m.chehab@samsung.com>,
"Sean Young" <sean@mess.org>,
"Antti Seppälä" <a.seppala@gmail.com>
Subject: [RFCv2 PATCH 4/5] nuvoton-cir: Add support for reading/writing wakeup samples via sysfs
Date: Sun, 26 Jan 2014 23:50:25 +0200 [thread overview]
Message-ID: <1390773026-567-5-git-send-email-a.seppala@gmail.com> (raw)
In-Reply-To: <1390773026-567-1-git-send-email-a.seppala@gmail.com>
This patch adds support for reading/writing wakeup samples via sysfs
to nuvoton-cir hardware.
The sysfs interface for nuvoton-cir contains raw IR pulse/space lengths.
If value is negative it is a space, otherwise it is a pulse.
Signed-off-by: Antti Seppälä <a.seppala@gmail.com>
---
drivers/media/rc/nuvoton-cir.c | 118 +++++++++++++++++++++++++++++++++++++++++
drivers/media/rc/nuvoton-cir.h | 2 +
2 files changed, 120 insertions(+)
diff --git a/drivers/media/rc/nuvoton-cir.c b/drivers/media/rc/nuvoton-cir.c
index 21ee0dc..015f3a8 100644
--- a/drivers/media/rc/nuvoton-cir.c
+++ b/drivers/media/rc/nuvoton-cir.c
@@ -531,6 +531,121 @@ static int nvt_set_tx_carrier(struct rc_dev *dev, u32 carrier)
return 0;
}
+static int nvt_validate_wakeup_codes(struct list_head *wakeup_code_list)
+{
+ int i = 0;
+ const int MAX_SAMPLE = US_TO_NS(BUF_LEN_MASK * SAMPLE_PERIOD);
+ struct rc_wakeup_code *code;
+ list_for_each_entry(code, wakeup_code_list, list_item) {
+
+ /* Prevent writing too many or invalid codes */
+ if (++i > WAKE_FIFO_LEN)
+ return -EINVAL;
+ if (abs(code->value) > MAX_SAMPLE)
+ return -EINVAL;
+ }
+
+ return i;
+}
+
+static int nvt_wakeup_codes(struct rc_dev *dev,
+ struct list_head *wakeup_code_list, int write)
+{
+ int i = 0;
+ u8 cnt, val, reg, reg_learn_mode;
+ unsigned long flags;
+ struct rc_wakeup_code *code;
+ struct nvt_dev *nvt = dev->priv;
+
+ nvt_dbg_wake("%sing wakeup codes", write ? "writ" : "read");
+
+ if (write) {
+
+ /* Validate wake codes (count and values) */
+ i = nvt_validate_wakeup_codes(wakeup_code_list);
+ if (i < 0)
+ return -EINVAL;
+
+ 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);
+
+ pr_info("Wake samples (%d) =", i);
+
+ /* Write wake samples to fifo */
+ list_for_each_entry(code, wakeup_code_list, list_item) {
+
+ /* Convert to driver format */
+ val = DIV_ROUND_UP(abs(code->value), 1000L)
+ / SAMPLE_PERIOD;
+
+ if (code->value > 0)
+ val |= BUF_PULSE_BIT;
+
+ pr_cont(" %02x", val);
+ nvt_cir_wake_reg_write(nvt, val,
+ 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, i ? i :
+ CIR_WAKE_FIFO_CMP_BYTES,
+ CIR_WAKE_FIFO_CMP_DEEP);
+
+ spin_unlock_irqrestore(&nvt->nvt_lock, flags);
+
+ } else {
+
+ /* 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++) {
+ code = kmalloc(sizeof(struct rc_wakeup_code),
+ GFP_KERNEL | GFP_ATOMIC);
+ if (!code)
+ return -ENOMEM;
+
+ val = nvt_cir_wake_reg_read(nvt,
+ CIR_WAKE_RD_FIFO_ONLY);
+
+ /* Convert to human readable sample-pulse format */
+ code->value = US_TO_NS((val & BUF_LEN_MASK)
+ * SAMPLE_PERIOD);
+ if (!(val & BUF_PULSE_BIT))
+ code->value *= -1;
+
+ list_add_tail(&code->list_item, wakeup_code_list);
+ }
+
+ return cnt;
+ }
+
+ return 0;
+}
/*
* nvt_tx_ir
*
@@ -1043,10 +1158,13 @@ static int nvt_probe(struct pnp_dev *pdev, const struct pnp_device_id *dev_id)
rdev->priv = nvt;
rdev->driver_type = RC_DRIVER_IR_RAW;
rdev->allowed_protos = RC_BIT_ALL;
+ rdev->allowed_wake_protos = RC_BIT_OTHER;
+ rdev->enabled_wake_protos = RC_BIT_OTHER;
rdev->open = nvt_open;
rdev->close = nvt_close;
rdev->tx_ir = nvt_tx_ir;
rdev->s_tx_carrier = nvt_set_tx_carrier;
+ rdev->s_wakeup_codes = nvt_wakeup_codes;
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
next prev parent reply other threads:[~2014-01-26 21:51 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-26 21:50 [RFCv2 PATCH 0/5] rc: Add generic sysfs interface for handling wakeup codes Antti Seppälä
2014-01-26 21:50 ` [RFCv2 PATCH 1/5] rc-core: Add defintions needed for sysfs callback Antti Seppälä
2014-01-26 21:50 ` [RFCv2 PATCH 2/5] rc-core: Add support for reading/writing wakeup codes via sysfs Antti Seppälä
2014-01-26 21:50 ` [RFCv2 PATCH 3/5] rc-loopback: Add support for reading/writing wakeup scancodes " Antti Seppälä
2014-01-26 21:50 ` Antti Seppälä [this message]
2014-01-26 21:50 ` [RFCv2 PATCH 5/5] winbond-cir: " Antti Seppälä
2014-01-30 19:24 ` Sean Young
2014-01-31 13:34 ` 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=1390773026-567-5-git-send-email-a.seppala@gmail.com \
--to=a.seppala@gmail.com \
--cc=linux-media@vger.kernel.org \
--cc=m.chehab@samsung.com \
--cc=sean@mess.org \
/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