From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Peter Griffin <peter.griffin@linaro.org>,
Alim Akhtar <alim.akhtar@samsung.com>,
Russell King <linux@armlinux.org.uk>,
Mark Brown <broonie@kernel.org>,
Linus Walleij <linusw@kernel.org>,
Charles Keepax <ckeepax@opensource.cirrus.com>,
Sam Protsenko <semen.protsenko@linaro.org>,
Arnd Bergmann <arnd@arndb.de>,
Bartosz Golaszewski <brgl@bgdev.pl>
Cc: Krzysztof Kozlowski <krzk@kernel.org>,
linux-input@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-samsung-soc@vger.kernel.org,
patches@opensource.cirrus.com
Subject: [PATCH v2 02/11] Input: samsung-keypad - handle compact binding
Date: Wed, 08 Jul 2026 21:53:00 -0700 [thread overview]
Message-ID: <20260708-samsung-kp-v2-2-3c6ed4c9b3b6@gmail.com> (raw)
In-Reply-To: <20260708-samsung-kp-v2-0-3c6ed4c9b3b6@gmail.com>
Add support for standard matrix keymap binding (in addition to the
existing verbose binding with a sub-node for each key). This will
allow easier conversions from platform data to device properties when
using static device properties.
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/input/keyboard/samsung-keypad.c | 130 ++++++++++++++++----------------
1 file changed, 66 insertions(+), 64 deletions(-)
diff --git a/drivers/input/keyboard/samsung-keypad.c b/drivers/input/keyboard/samsung-keypad.c
index 17127269e3f0..b9d4ea5f202a 100644
--- a/drivers/input/keyboard/samsung-keypad.c
+++ b/drivers/input/keyboard/samsung-keypad.c
@@ -231,83 +231,83 @@ static void samsung_keypad_close(struct input_dev *input_dev)
samsung_keypad_stop(keypad);
}
-#ifdef CONFIG_OF
-static struct samsung_keypad_platdata *
-samsung_keypad_parse_dt(struct device *dev)
+static const struct matrix_keymap_data *
+samsung_parse_verbose_keymap(struct device *dev)
{
- struct samsung_keypad_platdata *pdata;
struct matrix_keymap_data *keymap_data;
- uint32_t *keymap, num_rows = 0, num_cols = 0;
- struct device_node *np = dev->of_node, *key_np;
+ struct fwnode_handle *child;
+ u32 *keymap;
unsigned int key_count;
- if (!np) {
- dev_err(dev, "missing device tree data\n");
- return ERR_PTR(-EINVAL);
+ keymap_data = devm_kzalloc(dev, sizeof(*keymap_data), GFP_KERNEL);
+ if (!keymap_data)
+ return ERR_PTR(-ENOMEM);
+
+ key_count = device_get_child_node_count(dev);
+ keymap = devm_kcalloc(dev, key_count, sizeof(*keymap), GFP_KERNEL);
+ if (!keymap)
+ return ERR_PTR(-ENOMEM);
+
+ keymap_data->keymap_size = key_count;
+ keymap_data->keymap = keymap;
+
+ device_for_each_child_node(dev, child) {
+ u32 row, col, key_code;
+
+ fwnode_property_read_u32(child, "keypad,row", &row);
+ fwnode_property_read_u32(child, "keypad,column", &col);
+ fwnode_property_read_u32(child, "linux,code", &key_code);
+
+ *keymap++ = KEY(row, col, key_code);
}
+ return keymap_data;
+}
+
+static const struct samsung_keypad_platdata *
+samsung_keypad_parse_properties(struct device *dev)
+{
+ const struct matrix_keymap_data *keymap_data;
+ struct samsung_keypad_platdata *pdata;
+ u32 num_rows = 0, num_cols = 0;
+ int error;
+
pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
- if (!pdata) {
- dev_err(dev, "could not allocate memory for platform data\n");
+ if (!pdata)
return ERR_PTR(-ENOMEM);
- }
- of_property_read_u32(np, "samsung,keypad-num-rows", &num_rows);
- of_property_read_u32(np, "samsung,keypad-num-columns", &num_cols);
- if (!num_rows || !num_cols) {
- dev_err(dev, "number of keypad rows/columns not specified\n");
- return ERR_PTR(-EINVAL);
- }
+ device_property_read_u32(dev, "samsung,keypad-num-rows", &num_rows);
+ device_property_read_u32(dev, "samsung,keypad-num-columns", &num_cols);
+
+ error = matrix_keypad_parse_properties(dev, &num_rows, &num_cols);
+ if (error)
+ return ERR_PTR(error);
+
pdata->rows = num_rows;
pdata->cols = num_cols;
- keymap_data = devm_kzalloc(dev, sizeof(*keymap_data), GFP_KERNEL);
- if (!keymap_data) {
- dev_err(dev, "could not allocate memory for keymap data\n");
- return ERR_PTR(-ENOMEM);
- }
- pdata->keymap_data = keymap_data;
+ if (!device_property_present(dev, "linux,keymap")) {
+ keymap_data = samsung_parse_verbose_keymap(dev);
+ if (IS_ERR(keymap_data))
+ return ERR_CAST(keymap_data);
- key_count = of_get_child_count(np);
- keymap_data->keymap_size = key_count;
- keymap = devm_kcalloc(dev, key_count, sizeof(uint32_t), GFP_KERNEL);
- if (!keymap) {
- dev_err(dev, "could not allocate memory for keymap\n");
- return ERR_PTR(-ENOMEM);
+ pdata->keymap_data = keymap_data;
}
- keymap_data->keymap = keymap;
- for_each_child_of_node(np, key_np) {
- u32 row, col, key_code;
- of_property_read_u32(key_np, "keypad,row", &row);
- of_property_read_u32(key_np, "keypad,column", &col);
- of_property_read_u32(key_np, "linux,code", &key_code);
- *keymap++ = KEY(row, col, key_code);
- }
- pdata->no_autorepeat = of_property_read_bool(np, "linux,input-no-autorepeat");
+ pdata->no_autorepeat =
+ device_property_read_bool(dev, "linux,input-no-autorepeat");
- pdata->wakeup = of_property_read_bool(np, "wakeup-source") ||
+ pdata->wakeup = device_property_read_bool(dev, "wakeup-source") ||
/* legacy name */
- of_property_read_bool(np, "linux,input-wakeup");
-
+ device_property_read_bool(dev, "linux,input-wakeup");
return pdata;
}
-#else
-static struct samsung_keypad_platdata *
-samsung_keypad_parse_dt(struct device *dev)
-{
- dev_err(dev, "no platform data defined\n");
-
- return ERR_PTR(-EINVAL);
-}
-#endif
static int samsung_keypad_probe(struct platform_device *pdev)
{
const struct samsung_keypad_platdata *pdata;
- const struct matrix_keymap_data *keymap_data;
const struct platform_device_id *id;
struct samsung_keypad *keypad;
struct resource *res;
@@ -316,18 +316,17 @@ static int samsung_keypad_probe(struct platform_device *pdev)
int error;
pdata = dev_get_platdata(&pdev->dev);
- if (!pdata) {
- pdata = samsung_keypad_parse_dt(&pdev->dev);
+ if (pdata) {
+ if (!pdata->keymap_data) {
+ dev_err(&pdev->dev, "no keymap data defined\n");
+ return -EINVAL;
+ }
+ } else {
+ pdata = samsung_keypad_parse_properties(&pdev->dev);
if (IS_ERR(pdata))
return PTR_ERR(pdata);
}
- keymap_data = pdata->keymap_data;
- if (!keymap_data) {
- dev_err(&pdev->dev, "no keymap data defined\n");
- return -EINVAL;
- }
-
if (!pdata->rows || pdata->rows > SAMSUNG_MAX_ROWS)
return -EINVAL;
@@ -391,7 +390,7 @@ static int samsung_keypad_probe(struct platform_device *pdev)
input_dev->open = samsung_keypad_open;
input_dev->close = samsung_keypad_close;
- error = matrix_keypad_build_keymap(keymap_data, NULL,
+ error = matrix_keypad_build_keymap(pdata->keymap_data, NULL,
pdata->rows, pdata->cols,
keypad->keycodes, input_dev);
if (error) {
@@ -430,11 +429,14 @@ static int samsung_keypad_probe(struct platform_device *pdev)
if (error)
return error;
- if (pdev->dev.of_node) {
- devm_kfree(&pdev->dev, (void *)pdata->keymap_data->keymap);
- devm_kfree(&pdev->dev, (void *)pdata->keymap_data);
+ if (!dev_get_platdata(&pdev->dev)) {
+ if (pdata->keymap_data) {
+ devm_kfree(&pdev->dev, (void *)pdata->keymap_data->keymap);
+ devm_kfree(&pdev->dev, (void *)pdata->keymap_data);
+ }
devm_kfree(&pdev->dev, (void *)pdata);
}
+
return 0;
}
--
2.55.0.795.g602f6c329a-goog
next prev parent reply other threads:[~2026-07-09 4:53 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-09 4:52 [PATCH v2 00/11] Remove support for platform data from samsung keypad Dmitry Torokhov
2026-07-09 4:52 ` [PATCH v2 01/11] dt-bindings: input: samsung,s3c6410-keypad: introduce compact binding Dmitry Torokhov
2026-07-09 17:56 ` Conor Dooley
2026-07-09 4:53 ` Dmitry Torokhov [this message]
2026-07-09 4:53 ` [PATCH v2 03/11] ARM: s3c: register and attach software nodes for Samsung gpio_chips Dmitry Torokhov
2026-07-09 4:53 ` [PATCH v2 04/11] ARM: s3c: crag6410: switch keypad device to software properties Dmitry Torokhov
2026-07-09 4:53 ` [PATCH v2 05/11] Input: samsung-keypad - remove support for platform data Dmitry Torokhov
2026-07-09 4:53 ` [PATCH v2 06/11] ARM: s3c: crag6410: use software nodes/properties to set up GPIO keys Dmitry Torokhov
2026-07-09 4:53 ` [PATCH v2 07/11] regulator: wm831x: support software node in platform data Dmitry Torokhov
2026-07-09 4:53 ` [PATCH v2 08/11] ARM: s3c: crag6410: convert PMIC to software properties Dmitry Torokhov
2026-07-09 4:53 ` [PATCH v2 09/11] regulator: wm831x: remove legacy DVS platform data Dmitry Torokhov
2026-07-09 4:53 ` [PATCH v2 10/11] ARM: s3c: crag6410: convert remaining GPIO lookup tables to property entries Dmitry Torokhov
2026-07-09 4:53 ` [PATCH v2 11/11] ARM: s3c: crag6410: convert basic-mmio-gpio and LEDs to software properties Dmitry Torokhov
2026-07-09 8:10 ` [PATCH v2 00/11] Remove support for platform data from samsung keypad Bartosz Golaszewski
2026-07-10 19:41 ` Linus Walleij
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260708-samsung-kp-v2-2-3c6ed4c9b3b6@gmail.com \
--to=dmitry.torokhov@gmail.com \
--cc=alim.akhtar@samsung.com \
--cc=arnd@arndb.de \
--cc=brgl@bgdev.pl \
--cc=broonie@kernel.org \
--cc=ckeepax@opensource.cirrus.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=krzk+dt@kernel.org \
--cc=krzk@kernel.org \
--cc=linusw@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-samsung-soc@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=patches@opensource.cirrus.com \
--cc=peter.griffin@linaro.org \
--cc=robh@kernel.org \
--cc=semen.protsenko@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox