forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 cde9070d9970eef1f7ec2360586c802a16230ad8
kernel/drivers/media/rc/rc-main.c
....@@ -70,6 +70,13 @@
7070 [RC_PROTO_CEC] = { .name = "cec", .repeat_period = 0 },
7171 [RC_PROTO_IMON] = { .name = "imon",
7272 .scancode_bits = 0x7fffffff, .repeat_period = 114 },
73
+ [RC_PROTO_RCMM12] = { .name = "rc-mm-12",
74
+ .scancode_bits = 0x00000fff, .repeat_period = 114 },
75
+ [RC_PROTO_RCMM24] = { .name = "rc-mm-24",
76
+ .scancode_bits = 0x00ffffff, .repeat_period = 114 },
77
+ [RC_PROTO_RCMM32] = { .name = "rc-mm-32",
78
+ .scancode_bits = 0xffffffff, .repeat_period = 114 },
79
+ [RC_PROTO_XBOX_DVD] = { .name = "xbox-dvd", .repeat_period = 64 },
7380 };
7481
7582 /* Used to keep track of known keymaps */
....@@ -155,6 +162,41 @@
155162 .name = RC_MAP_EMPTY,
156163 }
157164 };
165
+
166
+/**
167
+ * scancode_to_u64() - converts scancode in &struct input_keymap_entry
168
+ * @ke: keymap entry containing scancode to be converted.
169
+ * @scancode: pointer to the location where converted scancode should
170
+ * be stored.
171
+ *
172
+ * This function is a version of input_scancode_to_scalar specialized for
173
+ * rc-core.
174
+ */
175
+static int scancode_to_u64(const struct input_keymap_entry *ke, u64 *scancode)
176
+{
177
+ switch (ke->len) {
178
+ case 1:
179
+ *scancode = *((u8 *)ke->scancode);
180
+ break;
181
+
182
+ case 2:
183
+ *scancode = *((u16 *)ke->scancode);
184
+ break;
185
+
186
+ case 4:
187
+ *scancode = *((u32 *)ke->scancode);
188
+ break;
189
+
190
+ case 8:
191
+ *scancode = *((u64 *)ke->scancode);
192
+ break;
193
+
194
+ default:
195
+ return -EINVAL;
196
+ }
197
+
198
+ return 0;
199
+}
158200
159201 /**
160202 * ir_create_table() - initializes a scancode table
....@@ -278,13 +320,13 @@
278320
279321 /* Did the user wish to remove the mapping? */
280322 if (new_keycode == KEY_RESERVED || new_keycode == KEY_UNKNOWN) {
281
- dev_dbg(&dev->dev, "#%d: Deleting scan 0x%04x\n",
323
+ dev_dbg(&dev->dev, "#%d: Deleting scan 0x%04llx\n",
282324 index, rc_map->scan[index].scancode);
283325 rc_map->len--;
284326 memmove(&rc_map->scan[index], &rc_map->scan[index+ 1],
285327 (rc_map->len - index) * sizeof(struct rc_map_table));
286328 } else {
287
- dev_dbg(&dev->dev, "#%d: %s scan 0x%04x with key 0x%04x\n",
329
+ dev_dbg(&dev->dev, "#%d: %s scan 0x%04llx with key 0x%04x\n",
288330 index,
289331 old_keycode == KEY_RESERVED ? "New" : "Replacing",
290332 rc_map->scan[index].scancode, new_keycode);
....@@ -327,8 +369,7 @@
327369 */
328370 static unsigned int ir_establish_scancode(struct rc_dev *dev,
329371 struct rc_map *rc_map,
330
- unsigned int scancode,
331
- bool resize)
372
+ u64 scancode, bool resize)
332373 {
333374 unsigned int i;
334375
....@@ -387,7 +428,7 @@
387428 struct rc_dev *rdev = input_get_drvdata(idev);
388429 struct rc_map *rc_map = &rdev->rc_map;
389430 unsigned int index;
390
- unsigned int scancode;
431
+ u64 scancode;
391432 int retval = 0;
392433 unsigned long flags;
393434
....@@ -400,7 +441,7 @@
400441 goto out;
401442 }
402443 } else {
403
- retval = input_scancode_to_scalar(ke, &scancode);
444
+ retval = scancode_to_u64(ke, &scancode);
404445 if (retval)
405446 goto out;
406447
....@@ -427,8 +468,7 @@
427468 *
428469 * return: -ENOMEM if all keycodes could not be inserted, otherwise zero.
429470 */
430
-static int ir_setkeytable(struct rc_dev *dev,
431
- const struct rc_map *from)
471
+static int ir_setkeytable(struct rc_dev *dev, const struct rc_map *from)
432472 {
433473 struct rc_map *rc_map = &dev->rc_map;
434474 unsigned int i, index;
....@@ -459,7 +499,7 @@
459499
460500 static int rc_map_cmp(const void *key, const void *elt)
461501 {
462
- const unsigned int *scancode = key;
502
+ const u64 *scancode = key;
463503 const struct rc_map_table *e = elt;
464504
465505 if (*scancode < e->scancode)
....@@ -480,7 +520,7 @@
480520 * return: index in the table, -1U if not found
481521 */
482522 static unsigned int ir_lookup_by_scancode(const struct rc_map *rc_map,
483
- unsigned int scancode)
523
+ u64 scancode)
484524 {
485525 struct rc_map_table *res;
486526
....@@ -509,7 +549,7 @@
509549 struct rc_map_table *entry;
510550 unsigned long flags;
511551 unsigned int index;
512
- unsigned int scancode;
552
+ u64 scancode;
513553 int retval;
514554
515555 spin_lock_irqsave(&rc_map->lock, flags);
....@@ -517,7 +557,7 @@
517557 if (ke->flags & INPUT_KEYMAP_BY_INDEX) {
518558 index = ke->index;
519559 } else {
520
- retval = input_scancode_to_scalar(ke, &scancode);
560
+ retval = scancode_to_u64(ke, &scancode);
521561 if (retval)
522562 goto out;
523563
....@@ -531,7 +571,6 @@
531571 ke->keycode = entry->keycode;
532572 ke->len = sizeof(entry->scancode);
533573 memcpy(ke->scancode, &entry->scancode, sizeof(entry->scancode));
534
-
535574 } else if (!(ke->flags & INPUT_KEYMAP_BY_INDEX)) {
536575 /*
537576 * We do not really know the valid range of scancodes
....@@ -563,7 +602,7 @@
563602 *
564603 * return: the corresponding keycode, or KEY_RESERVED
565604 */
566
-u32 rc_g_keycode_from_table(struct rc_dev *dev, u32 scancode)
605
+u32 rc_g_keycode_from_table(struct rc_dev *dev, u64 scancode)
567606 {
568607 struct rc_map *rc_map = &dev->rc_map;
569608 unsigned int keycode;
....@@ -579,7 +618,7 @@
579618 spin_unlock_irqrestore(&rc_map->lock, flags);
580619
581620 if (keycode != KEY_RESERVED)
582
- dev_dbg(&dev->dev, "%s: scancode 0x%04x keycode 0x%02x\n",
621
+ dev_dbg(&dev->dev, "%s: scancode 0x%04llx keycode 0x%02x\n",
583622 dev->device_name, scancode, keycode);
584623
585624 return keycode;
....@@ -698,7 +737,7 @@
698737 void rc_repeat(struct rc_dev *dev)
699738 {
700739 unsigned long flags;
701
- unsigned int timeout = nsecs_to_jiffies(dev->timeout) +
740
+ unsigned int timeout = usecs_to_jiffies(dev->timeout) +
702741 msecs_to_jiffies(repeat_period(dev->last_protocol));
703742 struct lirc_scancode sc = {
704743 .scancode = dev->last_scancode, .rc_proto = dev->last_protocol,
....@@ -708,12 +747,15 @@
708747 };
709748
710749 if (dev->allowed_protocols != RC_PROTO_BIT_CEC)
711
- ir_lirc_scancode_event(dev, &sc);
750
+ lirc_scancode_event(dev, &sc);
712751
713752 spin_lock_irqsave(&dev->keylock, flags);
714753
715
- input_event(dev->input_dev, EV_MSC, MSC_SCAN, dev->last_scancode);
716
- input_sync(dev->input_dev);
754
+ if (dev->last_scancode <= U32_MAX) {
755
+ input_event(dev->input_dev, EV_MSC, MSC_SCAN,
756
+ dev->last_scancode);
757
+ input_sync(dev->input_dev);
758
+ }
717759
718760 if (dev->keypressed) {
719761 dev->keyup_jiffies = jiffies + timeout;
....@@ -736,7 +778,7 @@
736778 * called with keylock held.
737779 */
738780 static void ir_do_keydown(struct rc_dev *dev, enum rc_proto protocol,
739
- u32 scancode, u32 keycode, u8 toggle)
781
+ u64 scancode, u32 keycode, u8 toggle)
740782 {
741783 bool new_event = (!dev->keypressed ||
742784 dev->last_protocol != protocol ||
....@@ -749,12 +791,13 @@
749791 };
750792
751793 if (dev->allowed_protocols != RC_PROTO_BIT_CEC)
752
- ir_lirc_scancode_event(dev, &sc);
794
+ lirc_scancode_event(dev, &sc);
753795
754796 if (new_event && dev->keypressed)
755797 ir_do_keyup(dev, false);
756798
757
- input_event(dev->input_dev, EV_MSC, MSC_SCAN, scancode);
799
+ if (scancode <= U32_MAX)
800
+ input_event(dev->input_dev, EV_MSC, MSC_SCAN, scancode);
758801
759802 dev->last_protocol = protocol;
760803 dev->last_scancode = scancode;
....@@ -765,7 +808,7 @@
765808 /* Register a keypress */
766809 dev->keypressed = true;
767810
768
- dev_dbg(&dev->dev, "%s: key down event, key 0x%04x, protocol 0x%04x, scancode 0x%08x\n",
811
+ dev_dbg(&dev->dev, "%s: key down event, key 0x%04x, protocol 0x%04x, scancode 0x%08llx\n",
769812 dev->device_name, keycode, protocol, scancode);
770813 input_report_key(dev->input_dev, keycode, 1);
771814
....@@ -802,7 +845,7 @@
802845 * This routine is used to signal that a key has been pressed on the
803846 * remote control.
804847 */
805
-void rc_keydown(struct rc_dev *dev, enum rc_proto protocol, u32 scancode,
848
+void rc_keydown(struct rc_dev *dev, enum rc_proto protocol, u64 scancode,
806849 u8 toggle)
807850 {
808851 unsigned long flags;
....@@ -812,7 +855,7 @@
812855 ir_do_keydown(dev, protocol, scancode, keycode, toggle);
813856
814857 if (dev->keypressed) {
815
- dev->keyup_jiffies = jiffies + nsecs_to_jiffies(dev->timeout) +
858
+ dev->keyup_jiffies = jiffies + usecs_to_jiffies(dev->timeout) +
816859 msecs_to_jiffies(repeat_period(protocol));
817860 mod_timer(&dev->timer_keyup, dev->keyup_jiffies);
818861 }
....@@ -833,7 +876,7 @@
833876 * remote control. The driver must manually call rc_keyup() at a later stage.
834877 */
835878 void rc_keydown_notimeout(struct rc_dev *dev, enum rc_proto protocol,
836
- u32 scancode, u8 toggle)
879
+ u64 scancode, u8 toggle)
837880 {
838881 unsigned long flags;
839882 u32 keycode = rc_g_keycode_from_table(dev, scancode);
....@@ -1018,6 +1061,10 @@
10181061 { RC_PROTO_BIT_XMP, "xmp", "ir-xmp-decoder" },
10191062 { RC_PROTO_BIT_CEC, "cec", NULL },
10201063 { RC_PROTO_BIT_IMON, "imon", "ir-imon-decoder" },
1064
+ { RC_PROTO_BIT_RCMM12 |
1065
+ RC_PROTO_BIT_RCMM24 |
1066
+ RC_PROTO_BIT_RCMM32, "rc-mm", "ir-rcmm-decoder" },
1067
+ { RC_PROTO_BIT_XBOX_DVD, "xbox-dvd", NULL },
10211068 };
10221069
10231070 /**
....@@ -1047,7 +1094,7 @@
10471094 * @buf: a pointer to the output buffer
10481095 *
10491096 * This routine is a callback routine for input read the IR protocol type(s).
1050
- * it is trigged by reading /sys/class/rc/rc?/protocols.
1097
+ * it is triggered by reading /sys/class/rc/rc?/protocols.
10511098 * It returns the protocol names of supported protocols.
10521099 * Enabled protocols are printed in brackets.
10531100 *
....@@ -1218,7 +1265,7 @@
12181265 * @len: length of the input buffer
12191266 *
12201267 * This routine is for changing the IR protocol type.
1221
- * It is trigged by writing to /sys/class/rc/rc?/[wakeup_]protocols.
1268
+ * It is triggered by writing to /sys/class/rc/rc?/[wakeup_]protocols.
12221269 * See parse_protocol_change() for the valid commands.
12231270 * Returns @len on success or a negative error code.
12241271 *
....@@ -1306,7 +1353,7 @@
13061353 * @buf: a pointer to the output buffer
13071354 *
13081355 * This routine is a callback routine to read a scancode filter value or mask.
1309
- * It is trigged by reading /sys/class/rc/rc?/[wakeup_]filter[_mask].
1356
+ * It is triggered by reading /sys/class/rc/rc?/[wakeup_]filter[_mask].
13101357 * It prints the current scancode filter value or mask of the appropriate filter
13111358 * type in hexadecimal into @buf and returns the size of the buffer.
13121359 *
....@@ -1349,7 +1396,7 @@
13491396 * @len: length of the input buffer
13501397 *
13511398 * This routine is for changing a scancode filter value or mask.
1352
- * It is trigged by writing to /sys/class/rc/rc?/[wakeup_]filter[_mask].
1399
+ * It is triggered by writing to /sys/class/rc/rc?/[wakeup_]filter[_mask].
13531400 * Returns -EINVAL if an invalid filter value for the current protocol was
13541401 * specified or if scancode filtering is not supported by the driver, otherwise
13551402 * returns @len.
....@@ -1437,7 +1484,7 @@
14371484 * @buf: a pointer to the output buffer
14381485 *
14391486 * This routine is a callback routine for input read the IR protocol type(s).
1440
- * it is trigged by reading /sys/class/rc/rc?/wakeup_protocols.
1487
+ * it is triggered by reading /sys/class/rc/rc?/wakeup_protocols.
14411488 * It returns the protocol names of supported protocols.
14421489 * The enabled protocols are printed in brackets.
14431490 *
....@@ -1488,7 +1535,7 @@
14881535 * @len: length of the input buffer
14891536 *
14901537 * This routine is for changing the IR protocol type.
1491
- * It is trigged by writing to /sys/class/rc/rc?/wakeup_protocols.
1538
+ * It is triggered by writing to /sys/class/rc/rc?/wakeup_protocols.
14921539 * Returns @len on success or a negative error code.
14931540 *
14941541 * dev->lock is taken to guard against races between
....@@ -1499,7 +1546,7 @@
14991546 const char *buf, size_t len)
15001547 {
15011548 struct rc_dev *dev = to_rc_dev(device);
1502
- enum rc_proto protocol;
1549
+ enum rc_proto protocol = RC_PROTO_UNKNOWN;
15031550 ssize_t rc;
15041551 u64 allowed;
15051552 int i;
....@@ -1512,9 +1559,7 @@
15121559
15131560 allowed = dev->allowed_wakeup_protocols;
15141561
1515
- if (sysfs_streq(buf, "none")) {
1516
- protocol = RC_PROTO_UNKNOWN;
1517
- } else {
1562
+ if (!sysfs_streq(buf, "none")) {
15181563 for (i = 0; i < ARRAY_SIZE(protocols); i++) {
15191564 if ((allowed & (1ULL << i)) &&
15201565 sysfs_streq(buf, protocols[i].name)) {
....@@ -1769,10 +1814,18 @@
17691814 dev->enabled_protocols = rc_proto;
17701815 }
17711816
1817
+ /* Keyboard events */
17721818 set_bit(EV_KEY, dev->input_dev->evbit);
17731819 set_bit(EV_REP, dev->input_dev->evbit);
17741820 set_bit(EV_MSC, dev->input_dev->evbit);
17751821 set_bit(MSC_SCAN, dev->input_dev->mscbit);
1822
+
1823
+ /* Pointer/mouse events */
1824
+ set_bit(INPUT_PROP_POINTING_STICK, dev->input_dev->propbit);
1825
+ set_bit(EV_REL, dev->input_dev->evbit);
1826
+ set_bit(REL_X, dev->input_dev->relbit);
1827
+ set_bit(REL_Y, dev->input_dev->relbit);
1828
+
17761829 if (dev->open)
17771830 dev->input_dev->open = ir_open;
17781831 if (dev->close)
....@@ -1893,7 +1946,7 @@
18931946 * keycodes with rc_keydown, so lirc must be registered first.
18941947 */
18951948 if (dev->allowed_protocols != RC_PROTO_BIT_CEC) {
1896
- rc = ir_lirc_register(dev);
1949
+ rc = lirc_register(dev);
18971950 if (rc < 0)
18981951 goto out_dev;
18991952 }
....@@ -1919,7 +1972,7 @@
19191972 rc_free_rx_device(dev);
19201973 out_lirc:
19211974 if (dev->allowed_protocols != RC_PROTO_BIT_CEC)
1922
- ir_lirc_unregister(dev);
1975
+ lirc_unregister(dev);
19231976 out_dev:
19241977 device_del(&dev->dev);
19251978 out_rx_free:
....@@ -1983,7 +2036,7 @@
19832036 * that userspace polling will get notified.
19842037 */
19852038 if (dev->allowed_protocols != RC_PROTO_BIT_CEC)
1986
- ir_lirc_unregister(dev);
2039
+ lirc_unregister(dev);
19872040
19882041 device_del(&dev->dev);
19892042
....@@ -2011,11 +2064,14 @@
20112064 if (rc) {
20122065 pr_err("rc_core: unable to init lirc\n");
20132066 class_unregister(&rc_class);
2014
- return 0;
2067
+ return rc;
20152068 }
20162069
20172070 led_trigger_register_simple("rc-feedback", &led_feedback);
20182071 rc_map_register(&empty_map);
2072
+#ifdef CONFIG_MEDIA_CEC_RC
2073
+ rc_map_register(&cec_map);
2074
+#endif
20192075
20202076 return 0;
20212077 }
....@@ -2025,6 +2081,9 @@
20252081 lirc_dev_exit();
20262082 class_unregister(&rc_class);
20272083 led_trigger_unregister_simple(led_feedback);
2084
+#ifdef CONFIG_MEDIA_CEC_RC
2085
+ rc_map_unregister(&cec_map);
2086
+#endif
20282087 rc_map_unregister(&empty_map);
20292088 }
20302089