driver: input: update RK remote control driver

This patch updates the RC driver to accommodate the new framework

Signed-off-by: Lei Chen <lei.chen@rock-chips.com>
Change-Id: I3ff2b5844ce5f1776ac2f94b3cbd42eb5d73cc41
This commit is contained in:
Lei Chen 2020-04-01 14:08:30 +08:00 committed by Jianhong Chen
parent f3a2c32e2d
commit f21c060e4b
3 changed files with 40 additions and 34 deletions

View File

@ -27,7 +27,7 @@ int rc_get_repeat(struct udevice *dev)
return ops->get_repeat(dev); return ops->get_repeat(dev);
} }
UCLASS_DRIVER(key) = { UCLASS_DRIVER(rc) = {
.id = UCLASS_RC, .id = UCLASS_RC,
.name = "rc", .name = "rc",
}; };

View File

@ -1,11 +1,11 @@
/* /*
* (C) Copyright 2017 Rockchip Electronics Co., Ltd * (C) Copyright 2017 Rockchip Electronics Co., Ltd
* *
* SPDX-License-Identifier: GPL-2.0+ * SPDX-License-Identifier: GPL-2.0+
*/ */
#include <clk.h>
#include <common.h> #include <common.h>
#include <clk.h>
#include <dm.h> #include <dm.h>
#include <dm/pinctrl.h> #include <dm/pinctrl.h>
#include <errno.h> #include <errno.h>
@ -19,7 +19,7 @@
#include <asm/arch/periph.h> #include <asm/arch/periph.h>
#include <asm/io.h> #include <asm/io.h>
#include <dm/ofnode.h>
DECLARE_GLOBAL_DATA_PTR; DECLARE_GLOBAL_DATA_PTR;
static struct nec_dec nec; static struct nec_dec nec;
@ -71,26 +71,29 @@ static int ir_parse_keys(struct udevice *dev)
int i, j; int i, j;
int len; int len;
int ret; int ret;
int subnode; u32 val;
int node = dev_of_offset(dev); ofnode node;
const void *blob = gd->fdt_blob;
i = 0; i = 0;
fdt_for_each_subnode(subnode, blob, node) { dev_for_each_subnode(node, dev) {
rc_map[i].usercode = fdtdec_get_uint(blob, subnode, ret = ofnode_read_u32(node, "rockchip,usercode", &val);
"rockchip,usercode", if (ret) {
1234u); debug("unable to get usercode\n");
if (rc_map[i].usercode == 1234u) { return -1;
}
rc_map[i].usercode = val;
if (rc_map[i].usercode == 0) {
debug("missing usercode property in the dts\n"); debug("missing usercode property in the dts\n");
return -1; return -1;
} }
debug("add new usercode:0x%x\n", rc_map[i].usercode); debug("add new usercode:0x%x\n", rc_map[i].usercode);
fdt_get_property(blob, subnode, "rockchip,key_table", &len); len = ofnode_read_size(node, "rockchip,key_table");
len /= sizeof(u32); len /= sizeof(u32);
debug("len:%d\n", len); debug("len:%d\n", len);
rc_map[i].nbuttons = len / 2; rc_map[i].nbuttons = len / 2;
ret = fdtdec_get_int_array(blob, subnode, "rockchip,key_table",
(u32 *)rc_map[i].scan, len); ret = ofnode_read_u32_array(node, "rockchip,key_table",
(u32 *)rc_map[i].scan, len);
if (ret) { if (ret) {
debug("missing key_table property in the dts\n"); debug("missing key_table property in the dts\n");
return -1; return -1;
@ -120,9 +123,6 @@ static int ir_nec_decode(struct rockchip_ir_priv *priv, struct ir_raw_event *ev)
u8 __maybe_unused address, not_address, command, not_command; u8 __maybe_unused address, not_address, command, not_command;
struct nec_dec *data = &nec; struct nec_dec *data = &nec;
debug("NEC decode started at state %d (%uus %s)\n",
data->state, TO_US(ev->duration), TO_STR(ev->pulse));
switch (data->state) { switch (data->state) {
case STATE_INACTIVE: case STATE_INACTIVE:
if (!ev->pulse) if (!ev->pulse)
@ -161,11 +161,12 @@ static int ir_nec_decode(struct rockchip_ir_priv *priv, struct ir_raw_event *ev)
break; break;
data->bits <<= 1; data->bits <<= 1;
if (eq_margin(ev->duration, NEC_BIT_1_SPACE, NEC_UNIT / 2)) if (eq_margin(ev->duration, NEC_BIT_1_SPACE, NEC_UNIT / 2)) {
data->bits |= 1; data->bits |= 1;
else if (!eq_margin(ev->duration, NEC_BIT_0_SPACE, } else if (!eq_margin(ev->duration, NEC_BIT_0_SPACE,
NEC_UNIT / 2)) NEC_UNIT / 2)) {
break; break;
}
data->count++; data->count++;
if (data->count == NEC_NBITS) { if (data->count == NEC_NBITS) {
@ -180,11 +181,12 @@ static int ir_nec_decode(struct rockchip_ir_priv *priv, struct ir_raw_event *ev)
} }
usercode = address << 8 | not_address; usercode = address << 8 | not_address;
scancode = command << 8 | not_command; scancode = command << 8 | not_command;
debug("raw usercode 0x%04x scancode 0x%04x\n",
usercode, scancode);
/* change to dts format */ /* change to dts format */
usercode = bitrev16(usercode); usercode = bitrev16(usercode);
scancode = (bitrev16(scancode) >> 8) & 0xFF; scancode = (bitrev16(scancode) >> 8) & 0xFF;
debug("usercode 0x%04x scancode 0x%04x\n",
usercode, scancode);
data->state = STATE_INACTIVE; data->state = STATE_INACTIVE;
ret = ir_lookup_by_scancode(priv, usercode, scancode); ret = ir_lookup_by_scancode(priv, usercode, scancode);
@ -226,6 +228,7 @@ static void rockchip_ir_irq(int irq, void *data)
} }
writel(PWM_CH_INT(priv->id), writel(PWM_CH_INT(priv->id),
priv->base + PWM_STA_REG(priv->id)); priv->base + PWM_STA_REG(priv->id));
ev.duration = cycle * priv->period; ev.duration = cycle * priv->period;
ir_nec_decode(priv, &ev); ir_nec_decode(priv, &ev);
} }
@ -253,16 +256,25 @@ static void rockchip_ir_hw_init(struct udevice *dev)
static int rockchip_ir_ofdata_to_platdata(struct udevice *dev) static int rockchip_ir_ofdata_to_platdata(struct udevice *dev)
{ {
int node = dev_of_offset(dev); ofnode node;
const void *blob = gd->fdt_blob; int ret;
int subnode_num = 0;
u32 val;
struct rockchip_ir_priv *priv = dev_get_priv(dev); struct rockchip_ir_priv *priv = dev_get_priv(dev);
priv->num = fdtdec_get_child_count(blob, node); dev_for_each_subnode(node, dev) {
ret = ofnode_read_u32(node, "rockchip,usercode", &val);
if (!ret)
subnode_num++;
}
priv->num = subnode_num;
if (priv->num == 0) { if (priv->num == 0) {
debug("no ir map in dts\n"); debug("no ir map in dts\n");
return -1; return -1;
} }
priv->base = devfdt_get_addr(dev); priv->base = dev_read_addr(dev);
priv->id = (priv->base >> 4) & 0xF; priv->id = (priv->base >> 4) & 0xF;
return 0; return 0;
@ -286,7 +298,6 @@ static int rockchip_ir_probe(struct udevice *dev)
debug("%s: failed to parse keys\n", __func__); debug("%s: failed to parse keys\n", __func__);
return -EINVAL; return -EINVAL;
} }
/* /*
* The PWM does not have decicated interrupt number in dts and can * The PWM does not have decicated interrupt number in dts and can
* not get periph_id by pinctrl framework, so let's init then here. * not get periph_id by pinctrl framework, so let's init then here.
@ -297,12 +308,6 @@ static int rockchip_ir_probe(struct udevice *dev)
return -EINVAL; return -EINVAL;
} }
ret = pinctrl_request_noflags(pinctrl, PERIPH_ID_PWM0 + priv->id);
if (ret) {
debug("%s pwm%d pinctrl init fail\n", __func__, priv->id);
return -EINVAL;
}
ret = clk_get_by_index(dev, 0, &clk); ret = clk_get_by_index(dev, 0, &clk);
if (ret) { if (ret) {
debug("%s get clock fail!\n", __func__); debug("%s get clock fail!\n", __func__);

View File

@ -149,5 +149,6 @@
#define KEY_RIGHTMETA 126 #define KEY_RIGHTMETA 126
#define KEY_COMPOSE 127 #define KEY_COMPOSE 127
#define KEY_FN 0x1d0 #define KEY_FN 0x1d0
#define KEY_REPLY 232 /* AC Reply */
#endif #endif