From: "David Härdeman" <david@hardeman.nu>
To: linux-media@vger.kernel.org
Cc: mchehab@redhat.com, jarod@redhat.com
Subject: [PATCH 18/43] rc-core: add an ioctl for setting IR RX settings
Date: Wed, 23 May 2012 11:43:35 +0200 [thread overview]
Message-ID: <20120523094335.14474.26432.stgit@felix.hardeman.nu> (raw)
In-Reply-To: <20120523094157.14474.24367.stgit@felix.hardeman.nu>
This adds a complementary ioctl to allow IR RX settings to be
changed.
Userspace is expected to first call RCIOCGIRRX, change the relevant parameters
in struct rc_ir_rx and then call RCIOCSIRRX.
The struct will be updated to reflect what the driver actually set the
parameters to (as all values may not be possible and some might have
to be approximated, e.g. because the hardware only supports some fixed
values) so that userspace knows the end result.
The LIRC driver is also changed to use the new RCIOCGIRRX and RCIOCSIRRX
methods as an alternative to the old functionality. This allows several
operations in struct rc_dev to be deprecated.
Signed-off-by: David Härdeman <david@hardeman.nu>
---
drivers/media/rc/ir-lirc-codec.c | 53 +++++++++++++++++++++++++++++---------
drivers/media/rc/rc-core-priv.h | 3 ++
drivers/media/rc/rc-main.c | 53 +++++++++++++++++++++++++++++---------
include/media/rc-core.h | 13 ++++++---
4 files changed, 92 insertions(+), 30 deletions(-)
diff --git a/drivers/media/rc/ir-lirc-codec.c b/drivers/media/rc/ir-lirc-codec.c
index 795cbdf..767fd06 100644
--- a/drivers/media/rc/ir-lirc-codec.c
+++ b/drivers/media/rc/ir-lirc-codec.c
@@ -160,6 +160,7 @@ static long ir_lirc_ioctl(struct file *filep, unsigned int cmd,
u32 __user *argp = (u32 __user *)(arg);
int ret = 0;
__u32 val = 0, tmp;
+ struct rc_ir_rx rx;
lirc = lirc_get_pdata(filep);
if (!lirc)
@@ -211,15 +212,23 @@ static long ir_lirc_ioctl(struct file *filep, unsigned int cmd,
/* RX settings */
case LIRC_SET_REC_CARRIER:
- if (!dev->s_rx_carrier_range)
- return -ENOSYS;
-
- if (val <= 0)
+ if (val <= 0 || val < dev->raw->lirc.carrier_low)
return -EINVAL;
- return dev->s_rx_carrier_range(dev,
- dev->raw->lirc.carrier_low,
- val);
+ if (dev->s_rx_carrier_range)
+ return dev->s_rx_carrier_range(dev,
+ dev->raw->lirc.carrier_low,
+ val);
+
+ if (dev->get_ir_rx && dev->set_ir_rx) {
+ rc_init_ir_rx(dev, &rx);
+ dev->get_ir_rx(dev, &rx);
+ rx.freq_min = dev->raw->lirc.carrier_low;
+ rx.freq_max = val;
+ return dev->set_ir_rx(dev, &rx);
+ }
+
+ return -ENOSYS;
case LIRC_SET_REC_CARRIER_RANGE:
if (val <= 0)
@@ -233,16 +242,34 @@ static long ir_lirc_ioctl(struct file *filep, unsigned int cmd,
break;
case LIRC_SET_WIDEBAND_RECEIVER:
- if (!dev->s_learning_mode)
- return -ENOSYS;
+ if (dev->s_learning_mode)
+ return dev->s_learning_mode(dev, !!val);
+
+ if (dev->get_ir_rx && dev->set_ir_rx) {
+ rc_init_ir_rx(dev, &rx);
+ dev->get_ir_rx(dev, &rx);
+ rx.rx_enabled = (!!val) ? rx.rx_learning : ~rx.rx_learning;
+ rx.rx_enabled &= rx.rx_supported;
+ return dev->set_ir_rx(dev, &rx);
+ }
- return dev->s_learning_mode(dev, !!val);
+ return -ENOSYS;
case LIRC_SET_MEASURE_CARRIER_MODE:
- if (!dev->s_carrier_report)
- return -ENOSYS;
+ if (dev->s_carrier_report)
+ return dev->s_carrier_report(dev, !!val);
+
+ if (dev->get_ir_rx && dev->set_ir_rx) {
+ rc_init_ir_rx(dev, &rx);
+ dev->get_ir_rx(dev, &rx);
+ if (!!val)
+ rx.flags |= RC_IR_RX_MEASURE_CARRIER;
+ else
+ rx.flags &= ~RC_IR_RX_MEASURE_CARRIER;
+ return dev->set_ir_rx(dev, &rx);
+ }
- return dev->s_carrier_report(dev, !!val);
+ return -ENOSYS;
/* Generic timeout support */
case LIRC_GET_MIN_TIMEOUT:
diff --git a/drivers/media/rc/rc-core-priv.h b/drivers/media/rc/rc-core-priv.h
index 6a40bc9..8db5bbc 100644
--- a/drivers/media/rc/rc-core-priv.h
+++ b/drivers/media/rc/rc-core-priv.h
@@ -149,6 +149,9 @@ int ir_raw_handler_register(struct ir_raw_handler *ir_raw_handler);
void ir_raw_handler_unregister(struct ir_raw_handler *ir_raw_handler);
void ir_raw_init(void);
+/* Only to be used by rc-core and ir-lirc-codec */
+void rc_init_ir_rx(struct rc_dev *dev, struct rc_ir_rx *rx);
+
/*
* Decoder initialization code
*
diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
index 2d3f421..390673c 100644
--- a/drivers/media/rc/rc-main.c
+++ b/drivers/media/rc/rc-main.c
@@ -1664,6 +1664,31 @@ static int rc_fasync(int fd, struct file *file, int on)
}
/**
+ * rc_init_ir_rx() - initializes a &struct rc_ir_rx to sane defaults
+ * @dev: the &struct rc_dev to take initial settings from
+ * @rx: the &struct rx_ir_rx to fill in with default values
+ *
+ * This function should only to be used by rc-core and ir-lirc-codec.
+ */
+void rc_init_ir_rx(struct rc_dev *dev, struct rc_ir_rx *rx)
+{
+ memset(rx, 0, sizeof(*rx));
+ rx->rx_supported = 0x1;
+ rx->rx_enabled = 0x1;
+ rx->rx_connected = 0x1;
+ rx->protocols_enabled[0] = dev->enabled_protocols;
+ if (dev->driver_type == RC_DRIVER_SCANCODE)
+ rx->protocols_supported[0] = dev->allowed_protos;
+ else
+ rx->protocols_supported[0] = ir_raw_get_allowed_protocols();
+ rx->timeout = dev->timeout;
+ rx->timeout_min = dev->min_timeout;
+ rx->timeout_max = dev->max_timeout;
+ rx->resolution = dev->rx_resolution;
+}
+EXPORT_SYMBOL_GPL(rc_init_ir_rx);
+
+/**
* rc_do_ioctl() - internal implementation of ioctl handling
* @dev: the &struct rc_dev to perform the command on
* @cmd: the ioctl command to perform
@@ -1678,6 +1703,7 @@ static long rc_do_ioctl(struct rc_dev *dev, unsigned int cmd, unsigned long arg)
void __user *p = (void __user *)arg;
unsigned int __user *ip = (unsigned int __user *)p;
struct rc_ir_rx rx;
+ int error;
switch (cmd) {
@@ -1690,20 +1716,21 @@ static long rc_do_ioctl(struct rc_dev *dev, unsigned int cmd, unsigned long arg)
case RCIOCGIRPSIZE:
return put_user(ARRAY_SIZE(rx.protocols_supported), ip);
+ case RCIOCSIRRX:
+ if (!dev->set_ir_rx)
+ return -ENOSYS;
+
+ if (copy_from_user(&rx, p, sizeof(rx)))
+ return -EFAULT;
+
+ error = dev->set_ir_rx(dev, &rx);
+ if (error)
+ return error;
+
+ /* Fall through */
+
case RCIOCGIRRX:
- memset(&rx, 0, sizeof(rx));
- rx.rx_supported = 0x1;
- rx.rx_enabled = 0x1;
- rx.rx_connected = 0x1;
- rx.protocols_enabled[0] = dev->enabled_protocols;
- if (dev->driver_type == RC_DRIVER_SCANCODE)
- rx.protocols_supported[0] = dev->allowed_protos;
- else
- rx.protocols_supported[0] = ir_raw_get_allowed_protocols();
- rx.timeout = dev->timeout;
- rx.timeout_min = dev->min_timeout;
- rx.timeout_max = dev->max_timeout;
- rx.resolution = dev->rx_resolution;
+ rc_init_ir_rx(dev, &rx);
/* See if the driver wishes to override anything */
if (dev->get_ir_rx)
diff --git a/include/media/rc-core.h b/include/media/rc-core.h
index 5669b64..213b642 100644
--- a/include/media/rc-core.h
+++ b/include/media/rc-core.h
@@ -53,8 +53,11 @@ do { \
/* get ir rx parameters */
#define RCIOCGIRRX _IOC(_IOC_READ, RC_IOC_MAGIC, 0x04, sizeof(struct rc_ir_rx))
+/* set ir rx parameters */
+#define RCIOCSIRRX _IOC(_IOC_WRITE, RC_IOC_MAGIC, 0x04, sizeof(struct rc_ir_rx))
+
/**
- * struct rc_ir_rx - used to get all IR RX parameters in one go
+ * struct rc_ir_rx - used to get/set all IR RX parameters in one go
* @flags: device specific flags (only %RC_IR_RX_MEASURE_CARRIER is
* currently defined)
* @rx_supported: bitmask of supported (i.e. possible) receivers
@@ -202,13 +205,14 @@ struct ir_raw_event {
* @s_tx_mask: set transmitter mask (for devices with multiple tx outputs)
* @s_tx_carrier: set transmit carrier frequency
* @s_tx_duty_cycle: set transmit duty cycle (0% - 100%)
- * @s_rx_carrier: inform driver about carrier it is expected to handle
+ * @s_rx_carrier: inform driver about expected carrier (deprecated)
* @tx_ir: transmit IR
* @s_idle: enable/disable hardware idle mode, upon which,
* device doesn't interrupt host until it sees IR pulses
- * @s_learning_mode: enable wide band receiver used for learning
- * @s_carrier_report: enable carrier reports
+ * @s_learning_mode: enable wide band receiver used for learning (deprecated)
+ * @s_carrier_report: enable carrier reports (deprecated)
* @get_ir_rx: allow driver to provide rx settings
+ * @set_ir_rx: allow driver to change rx settings
*/
struct rc_dev {
struct device dev;
@@ -260,6 +264,7 @@ struct rc_dev {
int (*s_learning_mode)(struct rc_dev *dev, int enable);
int (*s_carrier_report) (struct rc_dev *dev, int enable);
void (*get_ir_rx)(struct rc_dev *dev, struct rc_ir_rx *rx);
+ int (*set_ir_rx)(struct rc_dev *dev, struct rc_ir_rx *rx);
};
#define to_rc_dev(d) container_of(d, struct rc_dev, dev)
next prev parent reply other threads:[~2012-05-23 9:54 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-23 9:42 [PATCH 00/43] rc-core: feature parity with LIRC David Härdeman
2012-05-23 9:42 ` [PATCH 01/43] rc-core: move timeout and checks to lirc David Härdeman
2012-05-23 9:42 ` [PATCH 02/43] rc-core: add separate defines for protocol bitmaps and numbers David Härdeman
2012-05-23 9:42 ` [PATCH 03/43] rc-core: don't throw away protocol information David Härdeman
2012-05-23 9:42 ` [PATCH 04/43] rc-core: use the full 32 bits for NEC scancodes David Härdeman
2012-05-23 9:42 ` [PATCH 05/43] rc-core: merge rc5 and streamzap decoders David Härdeman
2012-05-23 9:42 ` [PATCH 06/43] rc-core: rename ir_input_class to rc_class David Härdeman
2012-05-23 9:42 ` [PATCH 07/43] rc-core: initialize rc-core earlier if built-in David Härdeman
2012-05-23 9:42 ` [PATCH 08/43] rc-core: use a device table rather than an atomic number David Härdeman
2012-05-23 9:42 ` [PATCH 09/43] rc-core: add chardev David Härdeman
2012-05-23 9:42 ` [PATCH 10/43] rc-core: allow chardev to be read David Härdeman
2012-05-23 9:42 ` [PATCH 11/43] mceusb: remove pointless kmalloc David Härdeman
2012-05-23 9:43 ` [PATCH 12/43] redrat: cleanup debug functions David Härdeman
2012-05-23 9:43 ` [PATCH 13/43] rc-core: use a kfifo for TX data David Härdeman
2012-05-23 9:43 ` [PATCH 14/43] rc-core: allow chardev to be written David Härdeman
2012-05-23 9:43 ` [PATCH 15/43] rc-core: add ioctl support to the rc chardev David Härdeman
2012-05-23 9:43 ` [PATCH 16/43] rc-core: add an ioctl for getting IR RX settings David Härdeman
2012-05-23 9:43 ` [PATCH 17/43] rc-loopback: add RCIOCGIRRX ioctl support David Härdeman
2012-05-23 9:43 ` David Härdeman [this message]
2012-05-23 9:43 ` [PATCH 19/43] rc-loopback: add RCIOCSIRRX " David Härdeman
2012-05-23 9:43 ` [PATCH 20/43] rc-core: add an ioctl for getting IR TX settings David Härdeman
2012-05-23 9:43 ` [PATCH 21/43] rc-loopback: add RCIOCGIRTX ioctl support David Härdeman
2012-05-23 9:43 ` [PATCH 22/43] rc-core: add an ioctl for setting IR TX settings David Härdeman
2012-05-23 9:44 ` [PATCH 23/43] rc-loopback: add RCIOCSIRTX ioctl support David Härdeman
2012-05-23 9:44 ` [PATCH 24/43] rc-core: leave the internals of rc_dev alone David Härdeman
2012-05-23 9:44 ` [PATCH 25/43] rc-core: prepare for multiple keytables David Härdeman
2012-05-23 9:44 ` [PATCH 26/43] rc-core: do not take mutex on rc_dev registration David Härdeman
2012-05-23 9:44 ` [PATCH 27/43] rc-core: make the keytable of rc_dev an array David Härdeman
2012-05-23 9:44 ` [PATCH 28/43] rc-core: add ioctls for adding/removing keytables from userspace David Härdeman
2012-05-23 9:44 ` [PATCH 29/43] rc-core: remove redundant spinlock David Härdeman
2012-05-23 9:44 ` [PATCH 30/43] rc-core: make keytable RCU-friendly David Härdeman
2012-05-23 9:44 ` [PATCH 31/43] rc-core: allow empty keymaps David Härdeman
2012-05-23 9:44 ` [PATCH 32/43] rc-core: split IR raw handling to a separate module David Härdeman
2012-05-23 9:44 ` [PATCH 33/43] rc-ir-raw: simplify locking David Härdeman
2012-05-23 9:44 ` [PATCH 34/43] rc-core: rename mutex David Härdeman
2012-05-23 9:45 ` [PATCH 35/43] rc-ir-raw: atomic reads of protocols David Härdeman
2012-05-23 9:45 ` [PATCH 36/43] rc-core: fix various sparse warnings David Härdeman
2012-05-23 9:45 ` [PATCH 37/43] rc-core: don't report scancodes via input devices David Härdeman
2012-05-23 9:45 ` [PATCH 38/43] rc-ir-raw: add various rc_events David Härdeman
2012-05-23 9:45 ` [PATCH 39/43] rc-core: use struct rc_event to signal TX events from userspace David Härdeman
2012-05-23 9:45 ` [PATCH 40/43] rc-core: use struct rc_event for all rc communication David Härdeman
2012-05-23 9:45 ` [PATCH 41/43] rc-core: add keytable events David Härdeman
2012-05-23 9:45 ` [PATCH 42/43] rc-core: move remaining keytable functions David Härdeman
2012-05-23 9:45 ` [PATCH 43/43] rc-core: make rc-core.h userspace friendly David Härdeman
2012-06-22 17:37 ` [PATCH 00/43] rc-core: feature parity with LIRC 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=20120523094335.14474.26432.stgit@felix.hardeman.nu \
--to=david@hardeman.nu \
--cc=jarod@redhat.com \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@redhat.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.