rk322x: fix NEC/NECX/NEC32 protocol handling for rockchip-ir driver

This commit is contained in:
Paolo Sabatino
2023-10-11 22:48:45 +02:00
committed by Paolo
parent c2b148add7
commit 022183eb6e
2 changed files with 41 additions and 28 deletions

View File

@@ -46,10 +46,10 @@ index a9285266e944..057d5b64c121 100644
obj-$(CONFIG_IR_SPI) += ir-spi.o
diff --git a/drivers/media/rc/rockchip-ir.c b/drivers/media/rc/rockchip-ir.c
new file mode 100644
index 000000000000..06c483cd8d5b
index 000000000000..43ade8c4adce
--- /dev/null
+++ b/drivers/media/rc/rockchip-ir.c
@@ -0,0 +1,723 @@
@@ -0,0 +1,732 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/* Copyright (c) 2012, Code Aurora Forum. All rights reserved.
+*/
@@ -377,7 +377,8 @@ index 000000000000..06c483cd8d5b
+
+ struct rc_map *key_map;
+ struct rc_map_table *key;
+ int idx, scancode;
+ int idx, key_scancode, rev_scancode;
+ int tee_scancode;
+
+ key_map = &gpio_dev->rcdev->rc_map;
+
@@ -389,14 +390,22 @@ index 000000000000..06c483cd8d5b
+
+ if (key->keycode != KEY_POWER)
+ continue;
+
+ key_scancode = key->scancode;
+ rev_scancode = ~key_scancode;
+
+ // If key_scancode has higher 16 bits set to 0, then the scancode is NEC protocol, otherwise it is NECX/NEC32
+ if ((key_scancode & 0xffff) == key_scancode)
+ tee_scancode = (key_scancode & 0xff00) | ((rev_scancode & 0xff00) << 8); // NEC protocol
+ else
+ tee_scancode = ((key_scancode & 0xff0000) >> 8) | ((key_scancode & 0xff00) << 8); // NECX/NEC32 protocol
+
+ tee_scancode |= rev_scancode & 0xff;
+ tee_scancode <<= 8;
+
+ sip_smc_remotectl_config(REMOTECTL_SET_PWRKEY, tee_scancode);
+
+ scancode = ((key->scancode & 0xff0000) >> 8) | ((key->scancode & 0xff00) << 8);
+ scancode |= (~key->scancode) & 0xff;
+ scancode <<= 8;
+
+ sip_smc_remotectl_config(REMOTECTL_SET_PWRKEY, scancode);
+
+ dev_info(dev, "registered scancode %08llx (SIP: %8x)\n", key->scancode, scancode);
+ dev_info(dev, "registered scancode %08x (SIP: %8x)\n", key_scancode, tee_scancode);
+
+ }
+
@@ -752,7 +761,7 @@ index 000000000000..06c483cd8d5b
+#endif
+
+static const struct of_device_id rockchip_ir_recv_of_match[] = {
+ { .compatible = "rockchip-ir", },
+ { .compatible = "rockchip-ir-receiver", },
+ { },
+};
+MODULE_DEVICE_TABLE(of, rockchip_ir_recv_of_match);
@@ -773,6 +782,3 @@ index 000000000000..06c483cd8d5b
+
+MODULE_DESCRIPTION("Rockchip IR Receiver driver");
+MODULE_LICENSE("GPL v2");
--
2.34.1

View File

@@ -46,10 +46,10 @@ index a9285266e944..057d5b64c121 100644
obj-$(CONFIG_IR_SPI) += ir-spi.o
diff --git a/drivers/media/rc/rockchip-ir.c b/drivers/media/rc/rockchip-ir.c
new file mode 100644
index 000000000000..06c483cd8d5b
index 000000000000..43ade8c4adce
--- /dev/null
+++ b/drivers/media/rc/rockchip-ir.c
@@ -0,0 +1,723 @@
@@ -0,0 +1,733 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/* Copyright (c) 2012, Code Aurora Forum. All rights reserved.
+*/
@@ -59,6 +59,7 @@ index 000000000000..06c483cd8d5b
+#include <linux/module.h>
+#include <linux/interrupt.h>
+#include <linux/gpio/consumer.h>
+#include <linux/pinctrl/consumer.h>
+#include <linux/slab.h>
+#include <linux/of.h>
+#include <linux/of_gpio.h>
@@ -377,7 +378,8 @@ index 000000000000..06c483cd8d5b
+
+ struct rc_map *key_map;
+ struct rc_map_table *key;
+ int idx, scancode;
+ int idx, key_scancode, rev_scancode;
+ int tee_scancode;
+
+ key_map = &gpio_dev->rcdev->rc_map;
+
@@ -389,14 +391,22 @@ index 000000000000..06c483cd8d5b
+
+ if (key->keycode != KEY_POWER)
+ continue;
+
+ key_scancode = key->scancode;
+ rev_scancode = ~key_scancode;
+
+ // If key_scancode has higher 16 bits set to 0, then the scancode is NEC protocol, otherwise it is NECX/NEC32
+ if ((key_scancode & 0xffff) == key_scancode)
+ tee_scancode = (key_scancode & 0xff00) | ((rev_scancode & 0xff00) << 8); // NEC protocol
+ else
+ tee_scancode = ((key_scancode & 0xff0000) >> 8) | ((key_scancode & 0xff00) << 8); // NECX/NEC32 protocol
+
+ tee_scancode |= rev_scancode & 0xff;
+ tee_scancode <<= 8;
+
+ sip_smc_remotectl_config(REMOTECTL_SET_PWRKEY, tee_scancode);
+
+ scancode = ((key->scancode & 0xff0000) >> 8) | ((key->scancode & 0xff00) << 8);
+ scancode |= (~key->scancode) & 0xff;
+ scancode <<= 8;
+
+ sip_smc_remotectl_config(REMOTECTL_SET_PWRKEY, scancode);
+
+ dev_info(dev, "registered scancode %08llx (SIP: %8x)\n", key->scancode, scancode);
+ dev_info(dev, "registered scancode %08x (SIP: %8x)\n", key_scancode, tee_scancode);
+
+ }
+
@@ -752,7 +762,7 @@ index 000000000000..06c483cd8d5b
+#endif
+
+static const struct of_device_id rockchip_ir_recv_of_match[] = {
+ { .compatible = "rockchip-ir", },
+ { .compatible = "rockchip-ir-receiver", },
+ { },
+};
+MODULE_DEVICE_TABLE(of, rockchip_ir_recv_of_match);
@@ -773,6 +783,3 @@ index 000000000000..06c483cd8d5b
+
+MODULE_DESCRIPTION("Rockchip IR Receiver driver");
+MODULE_LICENSE("GPL v2");
--
2.34.1