From: Sean Young Date: Tue, 6 Dec 2016 20:01:05 +0000 (-0200) Subject: [media] rc: ir-sanyo-decoder: Add encode capability X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=cb981257dc75a68f2134e9b2c562e323e2583324;p=GitHub%2Fmoto-9609%2Fandroid_kernel_motorola_exynos9610.git [media] rc: ir-sanyo-decoder: Add encode capability Add the capability to encode Sanyo scancodes as raw events. Signed-off-by: Sean Young Signed-off-by: Mauro Carvalho Chehab --- diff --git a/drivers/media/rc/ir-sanyo-decoder.c b/drivers/media/rc/ir-sanyo-decoder.c index b07d9caebeb1..520bb77dcb62 100644 --- a/drivers/media/rc/ir-sanyo-decoder.c +++ b/drivers/media/rc/ir-sanyo-decoder.c @@ -176,9 +176,52 @@ static int ir_sanyo_decode(struct rc_dev *dev, struct ir_raw_event ev) return -EINVAL; } +static const struct ir_raw_timings_pd ir_sanyo_timings = { + .header_pulse = SANYO_HEADER_PULSE, + .header_space = SANYO_HEADER_SPACE, + .bit_pulse = SANYO_BIT_PULSE, + .bit_space[0] = SANYO_BIT_0_SPACE, + .bit_space[1] = SANYO_BIT_1_SPACE, + .trailer_pulse = SANYO_TRAILER_PULSE, + .trailer_space = SANYO_TRAILER_SPACE, + .msb_first = 1, +}; + +/** + * ir_sanyo_encode() - Encode a scancode as a stream of raw events + * + * @protocol: protocol to encode + * @scancode: scancode to encode + * @events: array of raw ir events to write into + * @max: maximum size of @events + * + * Returns: The number of events written. + * -ENOBUFS if there isn't enough space in the array to fit the + * encoding. In this case all @max events will have been written. + */ +static int ir_sanyo_encode(enum rc_type protocol, u32 scancode, + struct ir_raw_event *events, unsigned int max) +{ + struct ir_raw_event *e = events; + int ret; + u64 raw; + + raw = ((u64)(bitrev16(scancode >> 8) & 0xfff8) << (8 + 8 + 13 - 3)) | + ((u64)(bitrev16(~scancode >> 8) & 0xfff8) << (8 + 8 + 0 - 3)) | + ((bitrev8(scancode) & 0xff) << 8) | + (bitrev8(~scancode) & 0xff); + + ret = ir_raw_gen_pd(&e, max, &ir_sanyo_timings, SANYO_NBITS, raw); + if (ret < 0) + return ret; + + return e - events; +} + static struct ir_raw_handler sanyo_handler = { .protocols = RC_BIT_SANYO, .decode = ir_sanyo_decode, + .encode = ir_sanyo_encode, }; static int __init ir_sanyo_decode_init(void)