Skip to content

Commit

Permalink
dts: msm8952: Add support for HMD Global Nokia 5
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgigena committed Nov 23, 2024
1 parent d76b47d commit 246b3b1
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 50 deletions.
1 change: 1 addition & 0 deletions Documentation/devices.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
### lk2nd-msm8952

- BQ X5 Plus (Longcheer L9360)
- HMD Global Nokia 5 (nd1)
- HMD Global Nokia 6 (ple)
- Huawei Honor 7C (aum-l41) (quirky - see comment in `lk2nd/device/dts/msm8952/msm8937-huawei-aum.dts`)
- Leeco s2
Expand Down
29 changes: 29 additions & 0 deletions lk2nd/device/dts/msm8952/msm8937-nokia-nd1.dts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// SPDX-License-Identifier: BSD-3-Clause

#include <skeleton64.dtsi>
#include <lk2nd.dtsi>

/ {
qcom,msm-id = <QCOM_ID_MSM8937 0x2000>;
qcom,board-id = <0x94 0>;
};

&lk2nd {
model = "HMD Global Nokia 5 (nd1)";
compatible = "nokia,nd1";
lk2nd,match-device = "ND1";
lk2nd,match-panel;
lk2nd,dtb-files = "msm8937-nokia-nd1";

gpio-keys {
compatible = "gpio-keys";
invert-volume-keys = <1>;
};

panel {
compatible = "nokia,nd1-panel", "lk2nd,panel";
qcom,mdss_dsi_nt35521s_720p_video {
compatible = "nokia,nd1-nt35521s";
};
};
};
1 change: 1 addition & 0 deletions lk2nd/device/dts/msm8952/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ ADTBS += \
$(LOCAL_DIR)/msm8937-huawei-aum.dtb \
$(LOCAL_DIR)/msm8937-motorola-jeter.dtb \
$(LOCAL_DIR)/msm8937-mtp.dtb \
$(LOCAL_DIR)/msm8937-nokia-nd1.dtb \
$(LOCAL_DIR)/msm8937-nokia-ple.dtb \
$(LOCAL_DIR)/msm8937-xiaomi-land.dtb \
$(LOCAL_DIR)/msm8940-mtp.dtb \
Expand Down
122 changes: 72 additions & 50 deletions lk2nd/device/keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ struct lk2nd_keymap {
struct gpiol_desc gpio;
};
static struct lk2nd_keymap keymap[LK2ND_MAX_KEYS] = {0};
static bool invert_volume_keys = false;

static bool target_powerkey(void)
{
Expand Down Expand Up @@ -53,16 +54,24 @@ bool lk2nd_keys_pressed(uint32_t keycode)
return false;

/* fallback to default handlers only if the keycode wasn't set in the DT */
switch (keycode) {
case KEY_VOLUMEDOWN:
return target_volume_down();
case KEY_VOLUMEUP:
return target_volume_up();
case KEY_POWER:
return target_powerkey();
default:
return false;
}
switch (keycode) {
case KEY_VOLUMEDOWN:
if (invert_volume_keys) {
return target_volume_up();
} else {
return target_volume_down();
}
case KEY_VOLUMEUP:
if (invert_volume_keys) {
return target_volume_down();
} else {
return target_volume_up();
}
case KEY_POWER:
return target_powerkey();
default:
return false;
}
}

static const uint16_t published_keys[] = {
Expand All @@ -85,49 +94,62 @@ static void lk2nd_keys_publish(void)
}
LK2ND_INIT(lk2nd_keys_publish);

static int lk2nd_keys_init(const void *dtb, int node)
static void lk2nd_keys_set_invert(const void *dtb, int node)
{
int i = 0, subnode, keycode, len, ret;
struct gpiol_desc gpio;
const uint32_t *val;

dprintf(SPEW, " | label | code | gpio |\n");

fdt_for_each_subnode(subnode, dtb, node) {
if (i == LK2ND_MAX_KEYS) {
dprintf(CRITICAL, "keys: Too many keys defined, ignoring rest\n");
break;
}

ret = gpiol_get(dtb, subnode, NULL, &gpio, GPIOL_FLAGS_IN);
if (ret) {
dprintf(CRITICAL, "keys: Failed to get gpio for %s: %d\n",
fdt_get_name(dtb, subnode, NULL), ret);
continue;
}
const uint32_t *val = fdt_getprop(dtb, node, "invert-volume-keys", NULL);

val = fdt_getprop(dtb, subnode, "lk2nd,code", &len);
if (len < 0) {
dprintf(CRITICAL, "keys: Failed to get keycode for %s: %d\n",
fdt_get_name(dtb, subnode, NULL), len);
continue;
}
keycode = fdt32_to_cpu(*val);

dprintf(SPEW, " | %5s | %5d | 0x%02x 0x%04x |\n",
fdt_get_name(dtb, subnode, NULL), keycode, gpio.dev, gpio.pin);

keymap[i].keycode = keycode;
keymap[i].gpio = gpio;
i++;
}
dprintf(INFO, "keys: %d keymap overrides applied\n", i);
if (val) {
invert_volume_keys = fdt32_to_cpu(*val);
dprintf(INFO, "keys: Inverting volume keys: %s\n", invert_volume_keys ? "enabled" : "disabled");
}
}

if (subnode < 0 && subnode != -FDT_ERR_NOTFOUND) {
dprintf(CRITICAL, "keys: Failed to parse subnodes: %d\n", subnode);
return subnode;
}

return 0;
static int lk2nd_keys_init(const void *dtb, int node)
{
int i = 0, subnode, keycode, len, ret;
struct gpiol_desc gpio;
const uint32_t *val;

dprintf(SPEW, " | label | code | gpio |\n");

lk2nd_keys_set_invert(dtb, node);

fdt_for_each_subnode(subnode, dtb, node) {
if (i == LK2ND_MAX_KEYS) {
dprintf(CRITICAL, "keys: Too many keys defined, ignoring rest\n");
break;
}

ret = gpiol_get(dtb, subnode, NULL, &gpio, GPIOL_FLAGS_IN);
if (ret) {
dprintf(CRITICAL, "keys: Failed to get gpio for %s: %d\n",
fdt_get_name(dtb, subnode, NULL), ret);
continue;
}

val = fdt_getprop(dtb, subnode, "lk2nd,code", &len);
if (len < 0) {
dprintf(CRITICAL, "keys: Failed to get keycode for %s: %d\n",
fdt_get_name(dtb, subnode, NULL), len);
continue;
}
keycode = fdt32_to_cpu(*val);

dprintf(SPEW, " | %5s | %5d | 0x%02x 0x%04x |\n",
fdt_get_name(dtb, subnode, NULL), keycode, gpio.dev, gpio.pin);

keymap[i].keycode = keycode;
keymap[i].gpio = gpio;
i++;
}
dprintf(INFO, "keys: %d keymap overrides applied\n", i);

if (subnode < 0 && subnode != -FDT_ERR_NOTFOUND) {
dprintf(CRITICAL, "keys: Failed to parse subnodes: %d\n", subnode);
return subnode;
}

return 0;
}
LK2ND_DEVICE_INIT("gpio-keys", lk2nd_keys_init);

0 comments on commit 246b3b1

Please sign in to comment.