+static const struct ir_raw_timings_manchester ir_mce_kbd_timings = {
+ .leader = MCIR2_PREFIX_PULSE,
+ .invert = 1,
+ .clock = MCIR2_UNIT,
+ .trailer_space = MCIR2_UNIT * 10,
+};
+
+/**
+ * ir_mce_kbd_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_mce_kbd_encode(enum rc_type protocol, u32 scancode,
+ struct ir_raw_event *events, unsigned int max)
+{
+ struct ir_raw_event *e = events;
+ int len, ret;
+ u64 raw;
+
+ if (protocol == RC_TYPE_MCIR2_KBD) {
+ raw = scancode |
+ ((u64)MCIR2_KEYBOARD_HEADER << MCIR2_KEYBOARD_NBITS);
+ len = MCIR2_KEYBOARD_NBITS + MCIR2_HEADER_NBITS + 1;
+ } else {
+ raw = scancode |
+ ((u64)MCIR2_MOUSE_HEADER << MCIR2_MOUSE_NBITS);
+ len = MCIR2_MOUSE_NBITS + MCIR2_HEADER_NBITS + 1;
+ }
+
+ ret = ir_raw_gen_manchester(&e, max, &ir_mce_kbd_timings, len, raw);
+ if (ret < 0)
+ return ret;
+
+ return e - events;
+}
+