Commit cdfaa01c authored by Sean Young's avatar Sean Young Committed by Mauro Carvalho Chehab

media: lirc: use the correct carrier for scancode transmit

If the lirc device supports it, set the carrier for the protocol.
Signed-off-by: default avatarSean Young <sean@mess.org>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
parent 9b619258
...@@ -212,6 +212,7 @@ static struct ir_raw_handler jvc_handler = { ...@@ -212,6 +212,7 @@ static struct ir_raw_handler jvc_handler = {
.protocols = RC_PROTO_BIT_JVC, .protocols = RC_PROTO_BIT_JVC,
.decode = ir_jvc_decode, .decode = ir_jvc_decode,
.encode = ir_jvc_encode, .encode = ir_jvc_encode,
.carrier = 38000,
}; };
static int __init ir_jvc_decode_init(void) static int __init ir_jvc_decode_init(void)
......
...@@ -122,6 +122,17 @@ static ssize_t ir_lirc_transmit_ir(struct file *file, const char __user *buf, ...@@ -122,6 +122,17 @@ static ssize_t ir_lirc_transmit_ir(struct file *file, const char __user *buf,
if (!lirc) if (!lirc)
return -EFAULT; return -EFAULT;
dev = lirc->dev;
if (!dev) {
ret = -EFAULT;
goto out;
}
if (!dev->tx_ir) {
ret = -EINVAL;
goto out;
}
if (lirc->send_mode == LIRC_MODE_SCANCODE) { if (lirc->send_mode == LIRC_MODE_SCANCODE) {
struct lirc_scancode scan; struct lirc_scancode scan;
...@@ -154,6 +165,13 @@ static ssize_t ir_lirc_transmit_ir(struct file *file, const char __user *buf, ...@@ -154,6 +165,13 @@ static ssize_t ir_lirc_transmit_ir(struct file *file, const char __user *buf,
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
/* Convert from NS to US */ /* Convert from NS to US */
txbuf[i] = DIV_ROUND_UP(raw[i].duration, 1000); txbuf[i] = DIV_ROUND_UP(raw[i].duration, 1000);
if (dev->s_tx_carrier) {
int carrier = ir_raw_encode_carrier(scan.rc_proto);
if (carrier > 0)
dev->s_tx_carrier(dev, carrier);
}
} else { } else {
if (n < sizeof(unsigned int) || n % sizeof(unsigned int)) if (n < sizeof(unsigned int) || n % sizeof(unsigned int))
return -EINVAL; return -EINVAL;
...@@ -167,17 +185,6 @@ static ssize_t ir_lirc_transmit_ir(struct file *file, const char __user *buf, ...@@ -167,17 +185,6 @@ static ssize_t ir_lirc_transmit_ir(struct file *file, const char __user *buf,
return PTR_ERR(txbuf); return PTR_ERR(txbuf);
} }
dev = lirc->dev;
if (!dev) {
ret = -EFAULT;
goto out;
}
if (!dev->tx_ir) {
ret = -EINVAL;
goto out;
}
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
if (txbuf[i] > IR_MAX_DURATION / 1000 - duration || !txbuf[i]) { if (txbuf[i] > IR_MAX_DURATION / 1000 - duration || !txbuf[i]) {
ret = -EINVAL; ret = -EINVAL;
......
...@@ -473,6 +473,7 @@ static struct ir_raw_handler mce_kbd_handler = { ...@@ -473,6 +473,7 @@ static struct ir_raw_handler mce_kbd_handler = {
.encode = ir_mce_kbd_encode, .encode = ir_mce_kbd_encode,
.raw_register = ir_mce_kbd_register, .raw_register = ir_mce_kbd_register,
.raw_unregister = ir_mce_kbd_unregister, .raw_unregister = ir_mce_kbd_unregister,
.carrier = 36000,
}; };
static int __init ir_mce_kbd_decode_init(void) static int __init ir_mce_kbd_decode_init(void)
......
...@@ -254,6 +254,7 @@ static struct ir_raw_handler nec_handler = { ...@@ -254,6 +254,7 @@ static struct ir_raw_handler nec_handler = {
RC_PROTO_BIT_NEC32, RC_PROTO_BIT_NEC32,
.decode = ir_nec_decode, .decode = ir_nec_decode,
.encode = ir_nec_encode, .encode = ir_nec_encode,
.carrier = 38000,
}; };
static int __init ir_nec_decode_init(void) static int __init ir_nec_decode_init(void)
......
...@@ -273,6 +273,7 @@ static struct ir_raw_handler rc5_handler = { ...@@ -273,6 +273,7 @@ static struct ir_raw_handler rc5_handler = {
RC_PROTO_BIT_RC5_SZ, RC_PROTO_BIT_RC5_SZ,
.decode = ir_rc5_decode, .decode = ir_rc5_decode,
.encode = ir_rc5_encode, .encode = ir_rc5_encode,
.carrier = 36000,
}; };
static int __init ir_rc5_decode_init(void) static int __init ir_rc5_decode_init(void)
......
...@@ -408,6 +408,7 @@ static struct ir_raw_handler rc6_handler = { ...@@ -408,6 +408,7 @@ static struct ir_raw_handler rc6_handler = {
RC_PROTO_BIT_RC6_MCE, RC_PROTO_BIT_RC6_MCE,
.decode = ir_rc6_decode, .decode = ir_rc6_decode,
.encode = ir_rc6_encode, .encode = ir_rc6_encode,
.carrier = 36000,
}; };
static int __init ir_rc6_decode_init(void) static int __init ir_rc6_decode_init(void)
......
...@@ -209,6 +209,7 @@ static struct ir_raw_handler sanyo_handler = { ...@@ -209,6 +209,7 @@ static struct ir_raw_handler sanyo_handler = {
.protocols = RC_PROTO_BIT_SANYO, .protocols = RC_PROTO_BIT_SANYO,
.decode = ir_sanyo_decode, .decode = ir_sanyo_decode,
.encode = ir_sanyo_encode, .encode = ir_sanyo_encode,
.carrier = 38000,
}; };
static int __init ir_sanyo_decode_init(void) static int __init ir_sanyo_decode_init(void)
......
...@@ -226,6 +226,7 @@ static struct ir_raw_handler sharp_handler = { ...@@ -226,6 +226,7 @@ static struct ir_raw_handler sharp_handler = {
.protocols = RC_PROTO_BIT_SHARP, .protocols = RC_PROTO_BIT_SHARP,
.decode = ir_sharp_decode, .decode = ir_sharp_decode,
.encode = ir_sharp_encode, .encode = ir_sharp_encode,
.carrier = 38000,
}; };
static int __init ir_sharp_decode_init(void) static int __init ir_sharp_decode_init(void)
......
...@@ -221,6 +221,7 @@ static struct ir_raw_handler sony_handler = { ...@@ -221,6 +221,7 @@ static struct ir_raw_handler sony_handler = {
RC_PROTO_BIT_SONY20, RC_PROTO_BIT_SONY20,
.decode = ir_sony_decode, .decode = ir_sony_decode,
.encode = ir_sony_encode, .encode = ir_sony_encode,
.carrier = 40000,
}; };
static int __init ir_sony_decode_init(void) static int __init ir_sony_decode_init(void)
......
...@@ -19,6 +19,7 @@ struct ir_raw_handler { ...@@ -19,6 +19,7 @@ struct ir_raw_handler {
int (*decode)(struct rc_dev *dev, struct ir_raw_event event); int (*decode)(struct rc_dev *dev, struct ir_raw_event event);
int (*encode)(enum rc_proto protocol, u32 scancode, int (*encode)(enum rc_proto protocol, u32 scancode,
struct ir_raw_event *events, unsigned int max); struct ir_raw_event *events, unsigned int max);
u32 carrier;
/* These two should only be used by the lirc decoder */ /* These two should only be used by the lirc decoder */
int (*raw_register)(struct rc_dev *dev); int (*raw_register)(struct rc_dev *dev);
......
...@@ -484,6 +484,36 @@ static void edge_handle(struct timer_list *t) ...@@ -484,6 +484,36 @@ static void edge_handle(struct timer_list *t)
ir_raw_event_handle(dev); ir_raw_event_handle(dev);
} }
/**
* ir_raw_encode_carrier() - Get carrier used for protocol
*
* @protocol: protocol
*
* Attempts to find the carrier for the specified protocol
*
* Returns: The carrier in Hz
* -EINVAL if the protocol is invalid, or if no
* compatible encoder was found.
*/
int ir_raw_encode_carrier(enum rc_proto protocol)
{
struct ir_raw_handler *handler;
int ret = -EINVAL;
u64 mask = BIT_ULL(protocol);
mutex_lock(&ir_raw_handler_lock);
list_for_each_entry(handler, &ir_raw_handler_list, list) {
if (handler->protocols & mask && handler->encode) {
ret = handler->carrier;
break;
}
}
mutex_unlock(&ir_raw_handler_lock);
return ret;
}
EXPORT_SYMBOL(ir_raw_encode_carrier);
/* /*
* Used to (un)register raw event clients * Used to (un)register raw event clients
*/ */
......
...@@ -309,6 +309,7 @@ int ir_raw_event_store_with_filter(struct rc_dev *dev, ...@@ -309,6 +309,7 @@ int ir_raw_event_store_with_filter(struct rc_dev *dev,
void ir_raw_event_set_idle(struct rc_dev *dev, bool idle); void ir_raw_event_set_idle(struct rc_dev *dev, bool idle);
int ir_raw_encode_scancode(enum rc_proto protocol, u32 scancode, int ir_raw_encode_scancode(enum rc_proto protocol, u32 scancode,
struct ir_raw_event *events, unsigned int max); struct ir_raw_event *events, unsigned int max);
int ir_raw_encode_carrier(enum rc_proto protocol);
static inline void ir_raw_event_reset(struct rc_dev *dev) static inline void ir_raw_event_reset(struct rc_dev *dev)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment