Skip to contentSkip to conversation

Remove support for platform data from samsung keypad

PATCH In review Dmitry Torokhov 5 participants 39 messages Aug 19, 2024 – Oct 4, 2024

Subsystems (7)
lore
Share & tools
lore

Dmitry Torokhov

author maintainer
#0 lore raw

cover Remove support for platform data from samsung keypad

Hi,

This series attempts to rework samsumg=keypad driver to stop using platform data and instead rely on generic device properties only.

The first 8 patches are general cleanup/facelift patches.

The 9th patch introduces alternative binding that is more compact that the original one, which makes it more suitable for use in legacy (non DT) boards with static device properties. Note that the "new" binding is the standard binding for matrix keypads.

Patch #10 implements the new binding in the driver, #11 converts the only user of platform data in the mainline tree to the static device properties, and #12 drops support for platform data from the driver.

Patches #13 and #14 are "bonus" converting the rest of crag6410 to use software nodes/properties to describe GPIO keys, LEDs and other peripherals. Note that I believe they fix and issue with recent conversion to GPIO lookup tables - the names of gpiochip structures I think are "GP<N>" ("GPK", "GPL", etc) and not "GPIO<N>".

Mark, you said you are using this board, it would be great if you could give this a spin.

Thanks!

Dmitry Torokhov (14):
Input: samsung-keypad - switch to using devm_clk_get_prepared()
Input: samsung-keypad - do not set input device's parent explicitly
Input: samsung-keypad - do not combine memory allocation checks
Input: samsung-keypad - use struct_size() helper
Input: samsung-keypad - use devm to disable runtime PM
Input: samsung-keypad - use guard notation to acquire mutex
Input: samsung-keypad - use per-chip parameters
Input: samsung-keypad - use BIT() and GENMASK() where appropriate
dt-bindings: input: samsung,s3c6410-keypad: introduce compact binding
Input: samsung-keypad - handle compact binding
ARM: s3c: crag6410: switch keypad device to software properties
Input: samsung-keypad - remove support for platform data
ARM: s3c: crag6410: use software nodes/properties to set up GPIO keys
ARM: s3c: crag6410 - convert GPIO lookup tables to property entries

 .../input/samsung,s3c6410-keypad.yaml         |  57 +++-
 arch/arm/mach-s3c/Kconfig                     |   5 -
 arch/arm/mach-s3c/Kconfig.s3c64xx             |   1 -
 arch/arm/mach-s3c/Makefile.s3c64xx            |   1 -
 arch/arm/mach-s3c/devs.c                      |  62 ----
 arch/arm/mach-s3c/devs.h                      |   2 -
 arch/arm/mach-s3c/gpio-samsung-s3c64xx.h      |   5 +
 arch/arm/mach-s3c/gpio-samsung.c              |  35 ++
 arch/arm/mach-s3c/keypad.h                    |  27 --
 arch/arm/mach-s3c/mach-crag6410.c             | 242 ++++++++-----
 arch/arm/mach-s3c/setup-keypad-s3c64xx.c      |  20 --
 drivers/input/keyboard/samsung-keypad.c       | 318 ++++++++----------
 include/linux/input/samsung-keypad.h          |  39 ---
 13 files changed, 398 insertions(+), 416 deletions(-)
 delete mode 100644 arch/arm/mach-s3c/keypad.h
 delete mode 100644 arch/arm/mach-s3c/setup-keypad-s3c64xx.c
 delete mode 100644 include/linux/input/samsung-keypad.h
Signature · 1 line
Dmitry
author maintainer
#1 lore raw

PATCH 1/14 Input: samsung-keypad - switch to using devm_clk_get_prepared()

Switch to using devm_clk_get_prepared() instead of combining devm_clk_get() with clk_prepare(), which simplifies the code and ensures that the clock is unprepared at the right time relative to releasing other managed resources.

---
 drivers/input/keyboard/samsung-keypad.c | 22 ++++------------------
 1 file changed, 4 insertions(+), 18 deletions(-)
drivers/input/keyboard/samsung-keypad.c +4 -18
index e212eff7687c..a5fac7de8b5d 100644
@@ -361,18 +361,12 @@ static int samsung_keypad_probe(struct platform_device *pdev)
 	if (!keypad->base)
 		return -EBUSY;
 
-	keypad->clk = devm_clk_get(&pdev->dev, "keypad");
+	keypad->clk = devm_clk_get_prepared(&pdev->dev, "keypad");
 	if (IS_ERR(keypad->clk)) {
 		dev_err(&pdev->dev, "failed to get keypad clk\n");
 		return PTR_ERR(keypad->clk);
 	}
 
-	error = clk_prepare(keypad->clk);
-	if (error) {
-		dev_err(&pdev->dev, "keypad clock prepare failed\n");
-		return error;
-	}
-
 	keypad->input_dev = input_dev;
 	keypad->pdev = pdev;
 	keypad->row_shift = row_shift;
@@ -399,7 +393,7 @@ static int samsung_keypad_probe(struct platform_device *pdev)
 					   keypad->keycodes, input_dev);
 	if (error) {
 		dev_err(&pdev->dev, "failed to build keymap\n");
-		goto err_unprepare_clk;
+		return error;
 	}
 
 	input_set_capability(input_dev, EV_MSC, MSC_SCAN);
@@ -411,7 +405,7 @@ static int samsung_keypad_probe(struct platform_device *pdev)
 	keypad->irq = platform_get_irq(pdev, 0);
 	if (keypad->irq < 0) {
 		error = keypad->irq;
-		goto err_unprepare_clk;
+		return error;
 	}
 
 	error = devm_request_threaded_irq(&pdev->dev, keypad->irq, NULL,
@@ -419,7 +413,7 @@ static int samsung_keypad_probe(struct platform_device *pdev)
 					  dev_name(&pdev->dev), keypad);
 	if (error) {
 		dev_err(&pdev->dev, "failed to register keypad interrupt\n");
-		goto err_unprepare_clk;
+		return error;
 	}
 
 	device_init_wakeup(&pdev->dev, pdata->wakeup);
@@ -439,20 +433,12 @@ static int samsung_keypad_probe(struct platform_device *pdev)
 
 err_disable_runtime_pm:
 	pm_runtime_disable(&pdev->dev);
-err_unprepare_clk:
-	clk_unprepare(keypad->clk);
 	return error;
 }
 
 static void samsung_keypad_remove(struct platform_device *pdev)
 {
-	struct samsung_keypad *keypad = platform_get_drvdata(pdev);
-
 	pm_runtime_disable(&pdev->dev);
-
-	input_unregister_device(keypad->input_dev);
-
-	clk_unprepare(keypad->clk);
 }
 
 static int samsung_keypad_runtime_suspend(struct device *dev)
Signature · 1 line
2.46.0.184.g6999bdac58-goog
#2 lore raw

Re: [PATCH 01/14] Input: samsung-keypad - switch to using devm_clk_get_prepared()

Quoted 4 lines · Dmitry Torokhov

Switch to using devm_clk_get_prepared() instead of combining devm_clk_get() with clk_prepare(), which simplifies the code and ensures that the clock is unprepared at the right time relative to releasing other managed resources.

...

Quoted 7 lines
drivers/input/keyboard/samsung-keypad.c +0 -2
 	device_init_wakeup(&pdev->dev, pdata->wakeup);
@@ -439,20 +433,12 @@ static int samsung_keypad_probe(struct platform_device *pdev)
 
 err_disable_runtime_pm:
 	pm_runtime_disable(&pdev->dev);
-err_unprepare_clk:
-	clk_unprepare(keypad->clk);

drivers/input/keyboard/samsung-keypad.c static int samsung_keypad_probe(struct platform_device *pdev) · line 453

Quoted 10 lines
drivers/input/keyboard/samsung-keypad.c +0 -4
 	return error;
 }
 
 static void samsung_keypad_remove(struct platform_device *pdev)
 {
-	struct samsung_keypad *keypad = platform_get_drvdata(pdev);
-
 	pm_runtime_disable(&pdev->dev);
-
-	input_unregister_device(keypad->input_dev);

This looks unrelated.

Best regards,
Krzysztof

author maintainer
#3 lore raw

Re: [PATCH 01/14] Input: samsung-keypad - switch to using devm_clk_get_prepared()

Quoted 18 lines · Krzysztof Kozlowski
Quoted 4 lines · Dmitry Torokhov

Switch to using devm_clk_get_prepared() instead of combining devm_clk_get() with clk_prepare(), which simplifies the code and ensures that the clock is unprepared at the right time relative to releasing other managed resources.

...

Quoted 10 lines
drivers/input/keyboard/samsung-keypad.c +0 -2
 	device_init_wakeup(&pdev->dev, pdata->wakeup);
@@ -439,20 +433,12 @@ static int samsung_keypad_probe(struct platform_device *pdev)
 
 err_disable_runtime_pm:
 	pm_runtime_disable(&pdev->dev);
-err_unprepare_clk:
-	clk_unprepare(keypad->clk);
 	return error;
 }
 
Quoted 9 lines

drivers/input/keyboard/samsung-keypad.c static int samsung_keypad_probe(struct platform_device *pdev) · line 453

Quoted 7 lines
drivers/input/keyboard/samsung-keypad.c +0 -4
 static void samsung_keypad_remove(struct platform_device *pdev)
 {
-	struct samsung_keypad *keypad = platform_get_drvdata(pdev);
-
 	pm_runtime_disable(&pdev->dev);
-
-	input_unregister_device(keypad->input_dev);

This looks unrelated.

It actually is related: with clk moved to devm we no longer need to unregister input device by hand to keep the right ordering and we can rely on devm to clean the input device as well (it already is being allocated with devm_input_allocate_device()).

Thanks.

Signature · 1 line
Dmitry
author maintainer
#4 lore raw

PATCH 2/14 Input: samsung-keypad - do not set input device's parent explicitly

In reply to Dmitry Torokhov

The driver uses devm_input_allocate_device() to allocate instances of input device, which sets the parent appropriately. Remove extraneous assignment.

---
 drivers/input/keyboard/samsung-keypad.c | 1 -
 1 file changed, 1 deletion(-)
drivers/input/keyboard/samsung-keypad.c +0 -1
index a5fac7de8b5d..46c0d0c900f6 100644
@@ -383,7 +383,6 @@ static int samsung_keypad_probe(struct platform_device *pdev)
 
 	input_dev->name = pdev->name;
 	input_dev->id.bustype = BUS_HOST;
-	input_dev->dev.parent = &pdev->dev;
 
 	input_dev->open = samsung_keypad_open;
 	input_dev->close = samsung_keypad_close;
Signature · 1 line
2.46.0.184.g6999bdac58-goog
author maintainer
#6 lore raw

PATCH 3/14 Input: samsung-keypad - do not combine memory allocation checks

In reply to Dmitry Torokhov

The driver uses devm API to allocate resources so there's no reason to do allocations first and then check and release everything at once.

Check results immediately after doing allocation of each resource.

---
 drivers/input/keyboard/samsung-keypad.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/input/keyboard/samsung-keypad.c +4 -1
index 46c0d0c900f6..2be3bfa87ce1 100644
@@ -349,8 +349,11 @@ static int samsung_keypad_probe(struct platform_device *pdev)
 
 	keypad = devm_kzalloc(&pdev->dev, sizeof(*keypad) + keymap_size,
 			      GFP_KERNEL);
+	if (!keypad)
+		return -ENOMEM;
+
 	input_dev = devm_input_allocate_device(&pdev->dev);
-	if (!keypad || !input_dev)
+	if (!input_dev)
 		return -ENOMEM;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Signature · 1 line
2.46.0.184.g6999bdac58-goog
maintainer Reviewed-by on v1 3/14
#7 lore raw

Re: [PATCH 03/14] Input: samsung-keypad - do not combine memory allocation checks

Quoted 8 lines · Dmitry Torokhov

The driver uses devm API to allocate resources so there's no reason to do allocations first and then check and release everything at once.

Check results immediately after doing allocation of each resource.

---
 drivers/input/keyboard/samsung-keypad.c | 5 ++++-

Best regards,
Krzysztof

author maintainer
#8 lore raw

PATCH 4/14 Input: samsung-keypad - use struct_size() helper

In reply to Dmitry Torokhov

When allocating memory for the keypad use struct_size() helper to be protected from overflows.

---
 drivers/input/keyboard/samsung-keypad.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/input/keyboard/samsung-keypad.c +3 -3
index 2be3bfa87ce1..7adcd2657bca 100644
@@ -318,7 +318,6 @@ static int samsung_keypad_probe(struct platform_device *pdev)
 	struct resource *res;
 	struct input_dev *input_dev;
 	unsigned int row_shift;
-	unsigned int keymap_size;
 	int error;
 
 	pdata = dev_get_platdata(&pdev->dev);
@@ -345,9 +344,10 @@ static int samsung_keypad_probe(struct platform_device *pdev)
 		pdata->cfg_gpio(pdata->rows, pdata->cols);
 
 	row_shift = get_count_order(pdata->cols);
-	keymap_size = (pdata->rows << row_shift) * sizeof(keypad->keycodes[0]);
 
-	keypad = devm_kzalloc(&pdev->dev, sizeof(*keypad) + keymap_size,
+	keypad = devm_kzalloc(&pdev->dev,
+			      struct_size(keypad, keycodes,
+					  pdata->rows << row_shift),
 			      GFP_KERNEL);
 	if (!keypad)
 		return -ENOMEM;
Signature · 1 line
2.46.0.184.g6999bdac58-goog
maintainer Reviewed-by on v1 4/14
#9 lore raw

Re: [PATCH 04/14] Input: samsung-keypad - use struct_size() helper

Quoted 7 lines · Dmitry Torokhov

When allocating memory for the keypad use struct_size() helper to be protected from overflows.

---
 drivers/input/keyboard/samsung-keypad.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Best regards,
Krzysztof

author maintainer
#10 lore raw

PATCH 5/14 Input: samsung-keypad - use devm to disable runtime PM

In reply to Dmitry Torokhov

To make sure that runtime PM is disabled at the right time relative to all other devm-managed resources use devm_add_action_or_reset() to register a handler that will disable it.

---
 drivers/input/keyboard/samsung-keypad.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)
drivers/input/keyboard/samsung-keypad.c +13 -11
index 7adcd2657bca..924327de4d8f 100644
@@ -310,6 +310,13 @@ samsung_keypad_parse_dt(struct device *dev)
 }
 #endif
 
+static void samsung_disable_runtime_pm(void *data)
+{
+	struct samsung_keypad *keypad = data;
+
+	pm_runtime_disable(&keypad->pdev->dev);
+}
+
 static int samsung_keypad_probe(struct platform_device *pdev)
 {
 	const struct samsung_keypad_platdata *pdata;
@@ -420,11 +427,16 @@ static int samsung_keypad_probe(struct platform_device *pdev)
 
 	device_init_wakeup(&pdev->dev, pdata->wakeup);
 	platform_set_drvdata(pdev, keypad);
+
 	pm_runtime_enable(&pdev->dev);
+	error = devm_add_action_or_reset(&pdev->dev, samsung_disable_runtime_pm,
+					 keypad);
+	if (error)
+		return error;
 
 	error = input_register_device(keypad->input_dev);
 	if (error)
-		goto err_disable_runtime_pm;
+		return error;
 
 	if (pdev->dev.of_node) {
 		devm_kfree(&pdev->dev, (void *)pdata->keymap_data->keymap);
@@ -432,15 +444,6 @@ static int samsung_keypad_probe(struct platform_device *pdev)
 		devm_kfree(&pdev->dev, (void *)pdata);
 	}
 	return 0;
-
-err_disable_runtime_pm:
-	pm_runtime_disable(&pdev->dev);
-	return error;
-}
-
-static void samsung_keypad_remove(struct platform_device *pdev)
-{
-	pm_runtime_disable(&pdev->dev);
 }
 
 static int samsung_keypad_runtime_suspend(struct device *dev)
@@ -575,7 +578,6 @@ MODULE_DEVICE_TABLE(platform, samsung_keypad_driver_ids);
 
 static struct platform_driver samsung_keypad_driver = {
 	.probe		= samsung_keypad_probe,
-	.remove_new	= samsung_keypad_remove,
 	.driver		= {
 		.name	= "samsung-keypad",
 		.of_match_table = of_match_ptr(samsung_keypad_dt_match),
Signature · 1 line
2.46.0.184.g6999bdac58-goog
#11 lore raw

Re: [PATCH 05/14] Input: samsung-keypad - use devm to disable runtime PM

Quoted 28 lines · Dmitry Torokhov

To make sure that runtime PM is disabled at the right time relative to all other devm-managed resources use devm_add_action_or_reset() to register a handler that will disable it.

---
 drivers/input/keyboard/samsung-keypad.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)
drivers/input/keyboard/samsung-keypad.c +7 -0
index 7adcd2657bca..924327de4d8f 100644
@@ -310,6 +310,13 @@ samsung_keypad_parse_dt(struct device *dev)
 }
 #endif
 
+static void samsung_disable_runtime_pm(void *data)
+{
+	struct samsung_keypad *keypad = data;
+
+	pm_runtime_disable(&keypad->pdev->dev);
+}
+
 static int samsung_keypad_probe(struct platform_device *pdev)
 {
 	const struct samsung_keypad_platdata *pdata;

drivers/input/keyboard/samsung-keypad.c static int samsung_keypad_probe(struct platform_device *pdev) · line 435

Quoted 9 lines
drivers/input/keyboard/samsung-keypad.c +5 -0
@@ -420,11 +427,16 @@ static int samsung_keypad_probe(struct platform_device *pdev)
 
 	device_init_wakeup(&pdev->dev, pdata->wakeup);
 	platform_set_drvdata(pdev, keypad);
+
 	pm_runtime_enable(&pdev->dev);
+	error = devm_add_action_or_reset(&pdev->dev, samsung_disable_runtime_pm,
+					 keypad);
+	if (error)
+		return error;

I think you are open-coding devm_pm_runtime_enable().

author maintainer
#12 lore raw

Re: [PATCH 05/14] Input: samsung-keypad - use devm to disable runtime PM

Quoted 30 lines · Krzysztof Kozlowski
Quoted 29 lines · Dmitry Torokhov

To make sure that runtime PM is disabled at the right time relative to all other devm-managed resources use devm_add_action_or_reset() to register a handler that will disable it.

---
 drivers/input/keyboard/samsung-keypad.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)
drivers/input/keyboard/samsung-keypad.c +7 -0
index 7adcd2657bca..924327de4d8f 100644
@@ -310,6 +310,13 @@ samsung_keypad_parse_dt(struct device *dev)
 }
 #endif
 
+static void samsung_disable_runtime_pm(void *data)
+{
+	struct samsung_keypad *keypad = data;
+
+	pm_runtime_disable(&keypad->pdev->dev);
+}
+
 static int samsung_keypad_probe(struct platform_device *pdev)
 {
 	const struct samsung_keypad_platdata *pdata;
@@ -420,11 +427,16 @@ static int samsung_keypad_probe(struct platform_device *pdev)
 
Quoted 10 lines

drivers/input/keyboard/samsung-keypad.c static int samsung_keypad_probe(struct platform_device *pdev) · line 435

Quoted 8 lines
drivers/input/keyboard/samsung-keypad.c +5 -0
 	device_init_wakeup(&pdev->dev, pdata->wakeup);
 	platform_set_drvdata(pdev, keypad);
+
 	pm_runtime_enable(&pdev->dev);
+	error = devm_add_action_or_reset(&pdev->dev, samsung_disable_runtime_pm,
+					 keypad);
+	if (error)
+		return error;

I think you are open-coding devm_pm_runtime_enable().

Ah, I didn't realize we had it. Thanks!

Signature · 1 line
Dmitry
author maintainer
#13 lore raw

PATCH 6/14 Input: samsung-keypad - use guard notation to acquire mutex

In reply to Dmitry Torokhov

Guard notation is more compact and ensures that the mutex will be released when control leaves the function.

---
 drivers/input/keyboard/samsung-keypad.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/input/keyboard/samsung-keypad.c +2 -6
index 924327de4d8f..71f5b85b02bd 100644
@@ -519,15 +519,13 @@ static int samsung_keypad_suspend(struct device *dev)
 	struct samsung_keypad *keypad = platform_get_drvdata(pdev);
 	struct input_dev *input_dev = keypad->input_dev;
 
-	mutex_lock(&input_dev->mutex);
+	guard(mutex)(&input_dev->mutex);
 
 	if (input_device_enabled(input_dev))
 		samsung_keypad_stop(keypad);
 
 	samsung_keypad_toggle_wakeup(keypad, true);
 
-	mutex_unlock(&input_dev->mutex);
-
 	return 0;
 }
 
@@ -537,15 +535,13 @@ static int samsung_keypad_resume(struct device *dev)
 	struct samsung_keypad *keypad = platform_get_drvdata(pdev);
 	struct input_dev *input_dev = keypad->input_dev;
 
-	mutex_lock(&input_dev->mutex);
+	guard(mutex)(&input_dev->mutex);
 
 	samsung_keypad_toggle_wakeup(keypad, false);
 
 	if (input_device_enabled(input_dev))
 		samsung_keypad_start(keypad);
 
-	mutex_unlock(&input_dev->mutex);
-
 	return 0;
 }
 
Signature · 1 line
2.46.0.184.g6999bdac58-goog
#14 lore raw

Re: [PATCH 06/14] Input: samsung-keypad - use guard notation to acquire mutex

Quoted 8 lines · Dmitry Torokhov

Guard notation is more compact and ensures that the mutex will be released when control leaves the function.

---
 drivers/input/keyboard/samsung-keypad.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

You need to include cleanup.h (unless some other patch already did it and I missed it?)

Best regards,
Krzysztof

author maintainer
#15 lore raw

Re: [PATCH 06/14] Input: samsung-keypad - use guard notation to acquire mutex

Quoted 4 lines · Krzysztof Kozlowski
Quoted 3 lines · Dmitry Torokhov

Guard notation is more compact and ensures that the mutex will be released when control leaves the function.

Quoted 8 lines
Quoted 5 lines
---
 drivers/input/keyboard/samsung-keypad.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

You need to include cleanup.h (unless some other patch already did it and I missed it?)

Guard for mutexes defined in mutex.h which is pulled in indirectly, and cleanup.h is included there.

If we want to list all the headers that we need instead of relying on indirect inclusions I think we need a separate patch. But even then I wonder if things like cleanup.h should be included by drivers directly...

Thanks.

Signature · 1 line
Dmitry
maintainer Reviewed-by
#16 lore raw

Re: [PATCH 06/14] Input: samsung-keypad - use guard notation to acquire mutex

Quoted 11 lines · Dmitry Torokhov
Quoted 10 lines · Krzysztof Kozlowski
Quoted 8 lines · Dmitry Torokhov

Guard notation is more compact and ensures that the mutex will be released when control leaves the function.

---
 drivers/input/keyboard/samsung-keypad.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
Quoted 4 lines
Quoted 2 lines

You need to include cleanup.h (unless some other patch already did it and I missed it?)

Guard for mutexes defined in mutex.h which is pulled in indirectly, and

guard() is not in mutex.h and in general we are including headers for the things directly used in the unit.

Quoted 3 lines

cleanup.h is included there.

If we want to list all the headers that we need instead of relying on

Fixing existing code is another thing. I only propose to add new code with the header.

I don't have strong opinion anyway, so:

Best regards,
Krzysztof

author maintainer
#17 lore raw

Re: [PATCH 06/14] Input: samsung-keypad - use guard notation to acquire mutex

Quoted 12 lines · Krzysztof Kozlowski
Quoted 11 lines · Dmitry Torokhov
Quoted 10 lines · Krzysztof Kozlowski
Quoted 8 lines · Dmitry Torokhov

Guard notation is more compact and ensures that the mutex will be released when control leaves the function.

---
 drivers/input/keyboard/samsung-keypad.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

You need to include cleanup.h (unless some other patch already did it and I missed it?)

Guard for mutexes defined in mutex.h which is pulled in indirectly, and

guard() is not in mutex.h and in general we are including headers for the things directly used in the unit.

Oh, but it is:

https://elixir.bootlin.com/linux/v6.10/source/include/linux/mutex.h#L196

DEFINE_GUARD(mutex, struct mutex *, mutex_lock(_T), mutex_unlock(_T))

Quoted 11 lines
Quoted 4 lines

cleanup.h is included there.

If we want to list all the headers that we need instead of relying on

Fixing existing code is another thing. I only propose to add new code with the header.

I don't have strong opinion anyway, so:

Thanks!

Signature · 1 line
Dmitry
#18 lore raw

Re: [PATCH 06/14] Input: samsung-keypad - use guard notation to acquire mutex

Quoted 18 lines · Dmitry Torokhov
Quoted 17 lines · Krzysztof Kozlowski
Quoted 15 lines · Dmitry Torokhov
Quoted 4 lines · Krzysztof Kozlowski
Quoted 3 lines · Dmitry Torokhov

Guard notation is more compact and ensures that the mutex will be released when control leaves the function.

Quoted 8 lines
Quoted 5 lines
---
 drivers/input/keyboard/samsung-keypad.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

You need to include cleanup.h (unless some other patch already did it and I missed it?)

Guard for mutexes defined in mutex.h which is pulled in indirectly, and

Quoted 8 lines
Quoted 2 lines

guard() is not in mutex.h and in general we are including headers for the things directly used in the unit.

Oh, but it is:

https://elixir.bootlin.com/linux/v6.10/source/include/linux/mutex.h#L196

DEFINE_GUARD(mutex, struct mutex *, mutex_lock(_T), mutex_unlock(_T))

That's DEFINE_GUARD, not guard().

Best regards,
Krzysztof

author maintainer
#19 lore raw

Re: [PATCH 06/14] Input: samsung-keypad - use guard notation to acquire mutex

Quoted 22 lines · Krzysztof Kozlowski
Quoted 21 lines · Dmitry Torokhov
Quoted 19 lines · Krzysztof Kozlowski
Quoted 11 lines · Dmitry Torokhov
Quoted 10 lines · Krzysztof Kozlowski
Quoted 8 lines · Dmitry Torokhov

Guard notation is more compact and ensures that the mutex will be released when control leaves the function.

---
 drivers/input/keyboard/samsung-keypad.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
Quoted 4 lines
Quoted 2 lines

You need to include cleanup.h (unless some other patch already did it and I missed it?)

Guard for mutexes defined in mutex.h which is pulled in indirectly, and

guard() is not in mutex.h and in general we are including headers for the things directly used in the unit.

Quoted 7 lines
Quoted 5 lines

Oh, but it is:

https://elixir.bootlin.com/linux/v6.10/source/include/linux/mutex.h#L196

DEFINE_GUARD(mutex, struct mutex *, mutex_lock(_T), mutex_unlock(_T))

That's DEFINE_GUARD, not guard().

OK, I see what you mean. I believe that cleanup.h is too low level to include directly by anyone who does not actually define a new guard or destructor routine. The concrete implementations of needed guards and all necessary support is pulled together with the headers defining the primary objects (mutex, spinlock, etc).

Thanks.

Signature · 1 line
Dmitry
author maintainer
#20 lore raw

PATCH 7/14 Input: samsung-keypad - use per-chip parameters

In reply to Dmitry Torokhov

Instead of doing conditional logic based on the chip type, define per-chip parameter structure, and reference it in the match data (either of_device_id or platform_device_id).

---
 drivers/input/keyboard/samsung-keypad.c | 61 +++++++++++++++----------
 1 file changed, 37 insertions(+), 24 deletions(-)
drivers/input/keyboard/samsung-keypad.c +37 -24
index 71f5b85b02bd..ccc1186e43b6 100644
@@ -44,8 +44,7 @@
 #define S5PV210_KEYIFSTSCLR_R_INT_OFFSET	16
 
 /* SAMSUNG_KEYIFCOL */
-#define SAMSUNG_KEYIFCOL_MASK			(0xff << 0)
-#define S5PV210_KEYIFCOLEN_MASK			(0xff << 8)
+#define SAMSUNG_KEYIFCOL_MASK			0xff
 
 /* SAMSUNG_KEYIFROW */
 #define SAMSUNG_KEYIFROW_MASK			(0xff << 0)
@@ -54,12 +53,12 @@
 /* SAMSUNG_KEYIFFC */
 #define SAMSUNG_KEYIFFC_MASK			(0x3ff << 0)
 
-enum samsung_keypad_type {
-	KEYPAD_TYPE_SAMSUNG,
-	KEYPAD_TYPE_S5PV210,
+struct samsung_chip_info {
+	unsigned int column_shift;
 };
 
 struct samsung_keypad {
+	const struct samsung_chip_info *chip;
 	struct input_dev *input_dev;
 	struct platform_device *pdev;
 	struct clk *clk;
@@ -68,7 +67,6 @@ struct samsung_keypad {
 	bool stopped;
 	bool wake_enabled;
 	int irq;
-	enum samsung_keypad_type type;
 	unsigned int row_shift;
 	unsigned int rows;
 	unsigned int cols;
@@ -83,13 +81,8 @@ static void samsung_keypad_scan(struct samsung_keypad *keypad,
 	unsigned int val;
 
 	for (col = 0; col < keypad->cols; col++) {
-		if (keypad->type == KEYPAD_TYPE_S5PV210) {
-			val = S5PV210_KEYIFCOLEN_MASK;
-			val &= ~(1 << col) << 8;
-		} else {
-			val = SAMSUNG_KEYIFCOL_MASK;
-			val &= ~(1 << col);
-		}
+		val = SAMSUNG_KEYIFCOL_MASK & ~(1 << col);
+		val <<= keypad->chip->column_shift;
 
 		writel(val, keypad->base + SAMSUNG_KEYIFCOL);
 		mdelay(1);
@@ -321,6 +314,7 @@ 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;
 	struct input_dev *input_dev;
@@ -385,11 +379,17 @@ static int samsung_keypad_probe(struct platform_device *pdev)
 	keypad->stopped = true;
 	init_waitqueue_head(&keypad->wait);
 
-	if (pdev->dev.of_node)
-		keypad->type = of_device_is_compatible(pdev->dev.of_node,
-					"samsung,s5pv210-keypad");
-	else
-		keypad->type = platform_get_device_id(pdev)->driver_data;
+	keypad->chip = device_get_match_data(&pdev->dev);
+	if (!keypad->chip) {
+		id = platform_get_device_id(pdev);
+		if (id)
+			keypad->chip = (const void *)id->driver_data;
+	}
+
+	if (!keypad->chip) {
+		dev_err(&pdev->dev, "Unable to determine chip type");
+		return -EINVAL;
+	}
 
 	input_dev->name = pdev->name;
 	input_dev->id.bustype = BUS_HOST;
@@ -551,11 +551,24 @@ static const struct dev_pm_ops samsung_keypad_pm_ops = {
 		       samsung_keypad_runtime_resume, NULL)
 };
 
+static const struct samsung_chip_info samsung_s3c6410_chip_info = {
+	.column_shift = 0,
+};
+
+static const struct samsung_chip_info samsung_s5pv210_chip_info = {
+	.column_shift = 8,
+};
+
 #ifdef CONFIG_OF
 static const struct of_device_id samsung_keypad_dt_match[] = {
-	{ .compatible = "samsung,s3c6410-keypad" },
-	{ .compatible = "samsung,s5pv210-keypad" },
-	{},
+	{
+		.compatible = "samsung,s3c6410-keypad",
+		.data = &samsung_s3c6410_chip_info,
+	}, {
+		.compatible = "samsung,s5pv210-keypad",
+		.data = &samsung_s5pv210_chip_info,
+	},
+	{ }
 };
 MODULE_DEVICE_TABLE(of, samsung_keypad_dt_match);
 #endif
@@ -563,12 +576,12 @@ MODULE_DEVICE_TABLE(of, samsung_keypad_dt_match);
 static const struct platform_device_id samsung_keypad_driver_ids[] = {
 	{
 		.name		= "samsung-keypad",
-		.driver_data	= KEYPAD_TYPE_SAMSUNG,
+		.driver_data	= (kernel_ulong_t)&samsung_s3c6410_chip_info,
 	}, {
 		.name		= "s5pv210-keypad",
-		.driver_data	= KEYPAD_TYPE_S5PV210,
+		.driver_data	= (kernel_ulong_t)&samsung_s5pv210_chip_info,
 	},
-	{ },
+	{ }
 };
 MODULE_DEVICE_TABLE(platform, samsung_keypad_driver_ids);
 
Signature · 1 line
2.46.0.184.g6999bdac58-goog
maintainer Reviewed-by on v1 7/14
#21 lore raw

Re: [PATCH 07/14] Input: samsung-keypad - use per-chip parameters

Quoted 7 lines · Dmitry Torokhov

Instead of doing conditional logic based on the chip type, define per-chip parameter structure, and reference it in the match data (either of_device_id or platform_device_id).

---
 drivers/input/keyboard/samsung-keypad.c | 61 +++++++++++++++----------

Best regards,
Krzysztof

author maintainer
#22 lore raw

PATCH 8/14 Input: samsung-keypad - use BIT() and GENMASK() where appropriate

In reply to Dmitry Torokhov

Instead of using (1 << <shift>) construct use BIT() helper. Convert (1 << <shift>) - 1 to GENMASK().

---
 drivers/input/keyboard/samsung-keypad.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)
drivers/input/keyboard/samsung-keypad.c +10 -9
index ccc1186e43b6..e262137b6838 100644
@@ -7,6 +7,7 @@
  * Author: Donghwa Lee <[email protected]>
  */
 
+#include <linux/bits.h>
 #include <linux/clk.h>
 #include <linux/delay.h>
 #include <linux/err.h>
@@ -29,11 +30,11 @@
 #define SAMSUNG_KEYIFFC				0x10
 
 /* SAMSUNG_KEYIFCON */
-#define SAMSUNG_KEYIFCON_INT_F_EN		(1 << 0)
-#define SAMSUNG_KEYIFCON_INT_R_EN		(1 << 1)
-#define SAMSUNG_KEYIFCON_DF_EN			(1 << 2)
-#define SAMSUNG_KEYIFCON_FC_EN			(1 << 3)
-#define SAMSUNG_KEYIFCON_WAKEUPEN		(1 << 4)
+#define SAMSUNG_KEYIFCON_INT_F_EN		BIT(0)
+#define SAMSUNG_KEYIFCON_INT_R_EN		BIT(1)
+#define SAMSUNG_KEYIFCON_DF_EN			BIT(2)
+#define SAMSUNG_KEYIFCON_FC_EN			BIT(3)
+#define SAMSUNG_KEYIFCON_WAKEUPEN		BIT(4)
 
 /* SAMSUNG_KEYIFSTSCLR */
 #define SAMSUNG_KEYIFSTSCLR_P_INT_MASK		(0xff << 0)
@@ -81,14 +82,14 @@ static void samsung_keypad_scan(struct samsung_keypad *keypad,
 	unsigned int val;
 
 	for (col = 0; col < keypad->cols; col++) {
-		val = SAMSUNG_KEYIFCOL_MASK & ~(1 << col);
+		val = SAMSUNG_KEYIFCOL_MASK & ~BIT(col);
 		val <<= keypad->chip->column_shift;
 
 		writel(val, keypad->base + SAMSUNG_KEYIFCOL);
 		mdelay(1);
 
 		val = readl(keypad->base + SAMSUNG_KEYIFROW);
-		row_state[col] = ~val & ((1 << keypad->rows) - 1);
+		row_state[col] = ~val & GENMASK(keypad->rows - 1, 0);
 	}
 
 	/* KEYIFCOL reg clear */
@@ -112,10 +113,10 @@ static bool samsung_keypad_report(struct samsung_keypad *keypad,
 			continue;
 
 		for (row = 0; row < keypad->rows; row++) {
-			if (!(changed & (1 << row)))
+			if (!(changed & BIT(row)))
 				continue;
 
-			pressed = row_state[col] & (1 << row);
+			pressed = row_state[col] & BIT(row);
 
 			dev_dbg(&keypad->input_dev->dev,
 				"key %s, row: %d, col: %d\n",
Signature · 1 line
2.46.0.184.g6999bdac58-goog
author maintainer
#23 lore raw

PATCH 9/14 dt-bindings: input: samsung,s3c6410-keypad: introduce compact binding

In reply to Dmitry Torokhov

The binding with a sub-node per each key is very verbose and is hard to use with static device properties. Allow standard matrix keymap binding in addition to the verbose one.

---
 .../input/samsung,s3c6410-keypad.yaml         | 57 ++++++++++++++++++-
 1 file changed, 54 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/input/samsung,s3c6410-keypad.yaml +54 -3
index a53569aa0ee7..28a318a0ff7e 100644
@@ -16,6 +16,10 @@ description:
 maintainers:
   - Krzysztof Kozlowski <[email protected]>
 
+allOf:
+  - $ref: input.yaml#
+  - $ref: matrix-keymap.yaml#
+
 properties:
   compatible:
     enum:
@@ -37,6 +41,10 @@ properties:
 
   wakeup-source: true
 
+  keypad,num-columns: true
+  keypad,num-rows: true
+  linux,keymap: true
+
   linux,input-no-autorepeat:
     type: boolean
     description:
@@ -81,12 +89,33 @@ patternProperties:
       - keypad,row
       - linux,code
 
+dependencies:
+  linux,keymap:
+    required:
+      - keypad,num-columns
+      - keypad,num-rows
+
 required:
   - compatible
   - reg
   - interrupts
-  - samsung,keypad-num-columns
-  - samsung,keypad-num-rows
+
+if:
+  required:
+    - linux,keymap
+then:
+  properties:
+    samsung,keypad-num-columns: false
+    samsung,keypad-num-rows: false
+  patternProperties:
+    '^key-[0-9a-z]+$': false
+else:
+  properties:
+    keypad,num-columns: false
+    keypad,num-rows: false
+  required:
+    - samsung,keypad-num-columns
+    - samsung,keypad-num-rows
 
 additionalProperties: false
 
@@ -94,8 +123,9 @@ examples:
   - |
     #include <dt-bindings/clock/exynos4.h>
     #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/input/input.h>
 
-    keypad@100a0000 {
+    keypad1@100a0000 {
         compatible = "samsung,s5pv210-keypad";
         reg = <0x100a0000 0x100>;
         interrupts = <GIC_SPI 109 IRQ_TYPE_LEVEL_HIGH>;
@@ -119,3 +149,24 @@ examples:
             linux,code = <3>;
         };
     };
+  - |
+    #include <dt-bindings/clock/exynos4.h>
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/input/input.h>
+
+    keypad2@100a0000 {
+        compatible = "samsung,s5pv210-keypad";
+        reg = <0x100a0000 0x100>;
+        interrupts = <GIC_SPI 109 IRQ_TYPE_LEVEL_HIGH>;
+        clocks = <&clock CLK_KEYIF>;
+        clock-names = "keypad";
+
+        keypad,num-rows = <2>;
+        keypad,num-columns = <8>;
+        linux,keymap = <
+          MATRIX_KEY(0, 3, 2)
+          MATRIX_KEY(0, 4, 3)
+        >;
+        linux,input-no-autorepeat;
+        wakeup-source;
+    };
Signature · 1 line
2.46.0.184.g6999bdac58-goog
#24 lore raw

Re: [PATCH 09/14] dt-bindings: input: samsung,s3c6410-keypad: introduce compact binding

Quoted 36 lines · Dmitry Torokhov

The binding with a sub-node per each key is very verbose and is hard to use with static device properties. Allow standard matrix keymap binding in addition to the verbose one.

---
 .../input/samsung,s3c6410-keypad.yaml         | 57 ++++++++++++++++++-
 1 file changed, 54 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/input/samsung,s3c6410-keypad.yaml +8 -0
index a53569aa0ee7..28a318a0ff7e 100644
@@ -16,6 +16,10 @@ description:
 maintainers:
   - Krzysztof Kozlowski <[email protected]>
 
+allOf:
+  - $ref: input.yaml#
+  - $ref: matrix-keymap.yaml#
+
 properties:
   compatible:
     enum:
@@ -37,6 +41,10 @@ properties:
 
   wakeup-source: true
 
+  keypad,num-columns: true
+  keypad,num-rows: true
+  linux,keymap: true
+
   linux,input-no-autorepeat:
     type: boolean
     description:

Documentation/devicetree/bindings/input/samsung,s3c6410-keypad.yaml patternProperties: · line 94

Quoted 6 lines
Documentation/devicetree/bindings/input/samsung,s3c6410-keypad.yaml +3 -0
@@ -81,12 +89,33 @@ patternProperties:
       - keypad,row
       - linux,code
 
+dependencies:
+  linux,keymap:
+    required:

Why "required" keyword? The dependencies should have just list of properties. See example-schema.

Documentation/devicetree/bindings/input/samsung,s3c6410-keypad.yaml patternProperties: · line 103

Quoted 11 lines
Documentation/devicetree/bindings/input/samsung,s3c6410-keypad.yaml +5 -2
+      - keypad,num-columns
+      - keypad,num-rows
+
 required:
   - compatible
   - reg
   - interrupts
-  - samsung,keypad-num-columns
-  - samsung,keypad-num-rows
+
+if:

put allOf: here and this within allOf, so you the "if" could grow in the future.

Best regards,
Krzysztof

author maintainer
#25 lore raw

Re: [PATCH 09/14] dt-bindings: input: samsung,s3c6410-keypad: introduce compact binding

Quoted 40 lines · Krzysztof Kozlowski
Quoted 39 lines · Dmitry Torokhov

The binding with a sub-node per each key is very verbose and is hard to use with static device properties. Allow standard matrix keymap binding in addition to the verbose one.

---
 .../input/samsung,s3c6410-keypad.yaml         | 57 ++++++++++++++++++-
 1 file changed, 54 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/input/samsung,s3c6410-keypad.yaml +8 -0
index a53569aa0ee7..28a318a0ff7e 100644
@@ -16,6 +16,10 @@ description:
 maintainers:
   - Krzysztof Kozlowski <[email protected]>
 
+allOf:
+  - $ref: input.yaml#
+  - $ref: matrix-keymap.yaml#
+
 properties:
   compatible:
     enum:
@@ -37,6 +41,10 @@ properties:
 
   wakeup-source: true
 
+  keypad,num-columns: true
+  keypad,num-rows: true
+  linux,keymap: true
+
   linux,input-no-autorepeat:
     type: boolean
     description:
@@ -81,12 +89,33 @@ patternProperties:
       - keypad,row
       - linux,code
 
Quoted 6 lines

Documentation/devicetree/bindings/input/samsung,s3c6410-keypad.yaml patternProperties: · line 94

Quoted 3 lines
Documentation/devicetree/bindings/input/samsung,s3c6410-keypad.yaml +3 -0
+dependencies:
+  linux,keymap:
+    required:

Why "required" keyword? The dependencies should have just list of properties. See example-schema.

OK, changed this to

dependencies:
linux,keymap: [ "keypad,num-columns", "keypad,num-rows" ]

Quoted 15 lines

Documentation/devicetree/bindings/input/samsung,s3c6410-keypad.yaml patternProperties: · line 103

Quoted 12 lines
Documentation/devicetree/bindings/input/samsung,s3c6410-keypad.yaml +5 -2
+      - keypad,num-columns
+      - keypad,num-rows
+
 required:
   - compatible
   - reg
   - interrupts
-  - samsung,keypad-num-columns
-  - samsung,keypad-num-rows
+
+if:

put allOf: here and this within allOf, so you the "if" could grow in the future.

Hmm, there is already "allOf" at the beginning of the file, so adding another one results in complaints about duplicate "allOf". I can move it all to the top, like this:

allOf:
- $ref: input.yaml#
- $ref: matrix-keymap.yaml#
- if:
required:
- linux,keymap
then:
properties:
samsung,keypad-num-columns: false
samsung,keypad-num-rows: false
patternProperties:
'^key-[0-9a-z]+$': false
else:
properties:
keypad,num-columns: false
keypad,num-rows: false
required:
- samsung,keypad-num-columns
- samsung,keypad-num-rows

Is this OK? I don't quite like that "tweaks" are listed before main body of properties.

Thanks.

Signature · 1 line
Dmitry
#26 lore raw

Re: [PATCH 09/14] dt-bindings: input: samsung,s3c6410-keypad: introduce compact binding

Quoted 43 lines · Dmitry Torokhov
Quoted 17 lines · Krzysztof Kozlowski

Documentation/devicetree/bindings/input/samsung,s3c6410-keypad.yaml patternProperties: · line 103

Quoted 11 lines · Dmitry Torokhov
Documentation/devicetree/bindings/input/samsung,s3c6410-keypad.yaml +5 -2
+      - keypad,num-columns
+      - keypad,num-rows
+
 required:
   - compatible
   - reg
   - interrupts
-  - samsung,keypad-num-columns
-  - samsung,keypad-num-rows
+
+if:

put allOf: here and this within allOf, so you the "if" could grow in the future.

Hmm, there is already "allOf" at the beginning of the file, so adding another one results in complaints about duplicate "allOf". I can move it all to the top, like this:

allOf:
- $ref: input.yaml#
- $ref: matrix-keymap.yaml#
- if:
required:
- linux,keymap
then:
properties:
samsung,keypad-num-columns: false
samsung,keypad-num-rows: false
patternProperties:
'^key-[0-9a-z]+$': false
else:
properties:
keypad,num-columns: false
keypad,num-rows: false
required:
- samsung,keypad-num-columns
- samsung,keypad-num-rows

Quoted 2 lines

Is this OK? I don't quite like that "tweaks" are listed before main body of properties.

The normal thing to do is to put the allOf at the end, not the start, in cases like this, for the reason you mention.

author maintainer
#27 lore raw

Re: [PATCH 09/14] dt-bindings: input: samsung,s3c6410-keypad: introduce compact binding

Quoted 44 lines · Conor Dooley
Quoted 43 lines · Dmitry Torokhov
Quoted 17 lines · Krzysztof Kozlowski

Documentation/devicetree/bindings/input/samsung,s3c6410-keypad.yaml patternProperties: · line 103

Quoted 11 lines · Dmitry Torokhov
Documentation/devicetree/bindings/input/samsung,s3c6410-keypad.yaml +5 -2
+      - keypad,num-columns
+      - keypad,num-rows
+
 required:
   - compatible
   - reg
   - interrupts
-  - samsung,keypad-num-columns
-  - samsung,keypad-num-rows
+
+if:

put allOf: here and this within allOf, so you the "if" could grow in the future.

Hmm, there is already "allOf" at the beginning of the file, so adding another one results in complaints about duplicate "allOf". I can move it all to the top, like this:

allOf:
- $ref: input.yaml#
- $ref: matrix-keymap.yaml#
- if:
required:
- linux,keymap
then:
properties:
samsung,keypad-num-columns: false
samsung,keypad-num-rows: false
patternProperties:
'^key-[0-9a-z]+$': false
else:
properties:
keypad,num-columns: false
keypad,num-rows: false
required:
- samsung,keypad-num-columns
- samsung,keypad-num-rows

Quoted 5 lines
Quoted 2 lines

Is this OK? I don't quite like that "tweaks" are listed before main body of properties.

The normal thing to do is to put the allOf at the end, not the start, in cases like this, for the reason you mention.

I see, thanks. It would be nice if it could combine several "allOf"s into one internally.

Thanks.

Signature · 1 line
Dmitry
author maintainer
#28 lore raw

PATCH 10/14 Input: samsung-keypad - handle compact binding

In reply to Dmitry Torokhov

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.

---
 drivers/input/keyboard/samsung-keypad.c | 122 +++++++++++++-----------
 1 file changed, 64 insertions(+), 58 deletions(-)
drivers/input/keyboard/samsung-keypad.c +64 -58
index e262137b6838..df2427ac63d7 100644
@@ -231,78 +231,85 @@ 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);
-	}
-
-	pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
-	if (!pdata) {
-		dev_err(dev, "could not allocate memory for platform data\n");
-		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);
-	}
-	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;
 
-	key_count = of_get_child_count(np);
-	keymap_data->keymap_size = key_count;
-	keymap = devm_kcalloc(dev, key_count, sizeof(uint32_t), GFP_KERNEL);
+	key_count = device_get_child_node_count(dev);
+	keymap = devm_kcalloc(dev, key_count, sizeof(*keymap), GFP_KERNEL);
 	if (!keymap) {
 		dev_err(dev, "could not allocate memory for keymap\n");
 		return ERR_PTR(-ENOMEM);
 	}
+
+	keymap_data->keymap_size = key_count;
 	keymap_data->keymap = keymap;
 
-	for_each_child_of_node(np, key_np) {
+	device_for_each_child_node(dev, child) {
 		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);
+
+		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);
 	}
 
-	pdata->no_autorepeat = of_property_read_bool(np, "linux,input-no-autorepeat");
+	return keymap_data;
+}
 
-	pdata->wakeup = of_property_read_bool(np, "wakeup-source") ||
-			/* legacy name */
-			of_property_read_bool(np, "linux,input-wakeup");
+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");
+		return ERR_PTR(-ENOMEM);
+	}
 
+	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;
+
+	if (!device_property_present(dev, "linux,keymap")) {
+		keymap_data = samsung_parse_verbose_keymap(dev);
+		if (IS_ERR(keymap_data))
+			return ERR_CAST(keymap_data);
+
+		pdata->keymap_data = keymap_data;
+	}
 
-	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);
+	pdata->no_autorepeat =
+		device_property_read_bool(dev, "linux,input-no-autorepeat");
+
+	pdata->wakeup = device_property_read_bool(dev, "wakeup-source") ||
+			/* legacy name */
+			device_property_read_bool(dev, "linux,input-wakeup");
+
+	return pdata;
 }
-#endif
 
 static void samsung_disable_runtime_pm(void *data)
 {
@@ -314,7 +321,6 @@ static void samsung_disable_runtime_pm(void *data)
 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;
@@ -323,18 +329,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;
 
@@ -398,7 +403,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) {
@@ -439,11 +444,12 @@ static int samsung_keypad_probe(struct platform_device *pdev)
 	if (error)
 		return error;
 
-	if (pdev->dev.of_node) {
+	if (!dev_get_platdata(&pdev->dev)) {
 		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;
 }
 
Signature · 1 line
2.46.0.184.g6999bdac58-goog
author maintainer
#29 lore raw

PATCH 11/14 ARM: s3c: crag6410: switch keypad device to software properties

In reply to Dmitry Torokhov

Switch the keypad device to use software properties to describe the keypad. This will allow dropping support for platform data from the samsung-keypad driver.

---
 arch/arm/mach-s3c/Kconfig                |  5 ---
 arch/arm/mach-s3c/Kconfig.s3c64xx        |  1 -
 arch/arm/mach-s3c/Makefile.s3c64xx       |  1 -
 arch/arm/mach-s3c/devs.c                 | 27 ------------
 arch/arm/mach-s3c/devs.h                 |  1 -
 arch/arm/mach-s3c/keypad.h               | 27 ------------
 arch/arm/mach-s3c/mach-crag6410.c        | 56 ++++++++++++++++++------
 arch/arm/mach-s3c/setup-keypad-s3c64xx.c | 20 ---------
 8 files changed, 42 insertions(+), 96 deletions(-)
 delete mode 100644 arch/arm/mach-s3c/keypad.h
 delete mode 100644 arch/arm/mach-s3c/setup-keypad-s3c64xx.c
arch/arm/mach-s3c/Kconfig +0 -5
index b3656109f1f7..2e77bb4f3a8c 100644
@@ -111,11 +111,6 @@ config S3C64XX_DEV_SPI0
 	  Compile in platform device definitions for S3C64XX's type
 	  SPI controller 0
 
-config SAMSUNG_DEV_KEYPAD
-	bool
-	help
-	  Compile in platform device definitions for keypad
-
 config SAMSUNG_DEV_PWM
 	bool
 	help
arch/arm/mach-s3c/Kconfig.s3c64xx +0 -1
index 8f40af063ad6..cc1257fbf642 100644
@@ -116,7 +116,6 @@ config MACH_WLF_CRAGG_6410
 	select S3C_DEV_I2C1
 	select S3C_DEV_USB_HOST
 	select S3C_DEV_USB_HSOTG
-	select SAMSUNG_DEV_KEYPAD
 	select SAMSUNG_DEV_PWM
 	help
 	  Machine support for the Wolfson Cragganmore S3C6410 variant.
arch/arm/mach-s3c/Makefile.s3c64xx +0 -1
index 61287ad2ea42..1686b1f344f8 100644
@@ -32,7 +32,6 @@ obj-y				+= dev-audio-s3c64xx.o
 obj-$(CONFIG_S3C64XX_SETUP_FB_24BPP)	+= setup-fb-24bpp-s3c64xx.o
 obj-$(CONFIG_S3C64XX_SETUP_I2C0)	+= setup-i2c0-s3c64xx.o
 obj-$(CONFIG_S3C64XX_SETUP_I2C1)	+= setup-i2c1-s3c64xx.o
-obj-$(CONFIG_S3C64XX_SETUP_KEYPAD)	+= setup-keypad-s3c64xx.o
 obj-$(CONFIG_S3C64XX_SETUP_SDHCI_GPIO)	+= setup-sdhci-gpio-s3c64xx.o
 obj-$(CONFIG_S3C64XX_SETUP_SPI)		+= setup-spi-s3c64xx.o
 obj-$(CONFIG_S3C64XX_SETUP_USB_PHY) += setup-usb-phy-s3c64xx.o
arch/arm/mach-s3c/devs.c +0 -27
index 8c26d592d2a3..31827cfc5700 100644
@@ -40,7 +40,6 @@
 #include "devs.h"
 #include "fb.h"
 #include <linux/platform_data/i2c-s3c2410.h>
-#include "keypad.h"
 #include "pwm-core.h"
 #include "sdhci.h"
 #include "usb-phy.h"
@@ -266,32 +265,6 @@ void __init s3c_i2c1_set_platdata(struct s3c2410_platform_i2c *pd)
 }
 #endif /* CONFIG_S3C_DEV_I2C1 */
 
-/* KEYPAD */
-
-#ifdef CONFIG_SAMSUNG_DEV_KEYPAD
-static struct resource samsung_keypad_resources[] = {
-	[0] = DEFINE_RES_MEM(SAMSUNG_PA_KEYPAD, SZ_32),
-	[1] = DEFINE_RES_IRQ(IRQ_KEYPAD),
-};
-
-struct platform_device samsung_device_keypad = {
-	.name		= "samsung-keypad",
-	.id		= -1,
-	.num_resources	= ARRAY_SIZE(samsung_keypad_resources),
-	.resource	= samsung_keypad_resources,
-};
-
-void __init samsung_keypad_set_platdata(struct samsung_keypad_platdata *pd)
-{
-	struct samsung_keypad_platdata *npd;
-
-	npd = s3c_set_platdata(pd, sizeof(*npd), &samsung_device_keypad);
-
-	if (!npd->cfg_gpio)
-		npd->cfg_gpio = samsung_keypad_cfg_gpio;
-}
-#endif /* CONFIG_SAMSUNG_DEV_KEYPAD */
-
 /* PWM Timer */
 
 #ifdef CONFIG_SAMSUNG_DEV_PWM
arch/arm/mach-s3c/devs.h +0 -1
index 21c00786c264..2737990063b1 100644
@@ -39,7 +39,6 @@ extern struct platform_device s3c_device_i2c1;
 extern struct platform_device s3c_device_ohci;
 extern struct platform_device s3c_device_usb_hsotg;
 
-extern struct platform_device samsung_device_keypad;
 extern struct platform_device samsung_device_pwm;
 
 /**
arch/arm/mach-s3c/keypad.h deleted +0 -27
deleted file mode 100644
index 9754b9a29945..000000000000
@@ -1,27 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0+ */
-/*
- * Samsung Platform - Keypad platform data definitions
- *
- * Copyright (C) 2010 Samsung Electronics Co.Ltd
- * Author: Joonyoung Shim <[email protected]>
- */
-
-#ifndef __PLAT_SAMSUNG_KEYPAD_H
-#define __PLAT_SAMSUNG_KEYPAD_H
-
-#include <linux/input/samsung-keypad.h>
-
-/**
- * samsung_keypad_set_platdata - Set platform data for Samsung Keypad device.
- * @pd: Platform data to register to device.
- *
- * Register the given platform data for use with Samsung Keypad device.
- * The call will copy the platform data, so the board definitions can
- * make the structure itself __initdata.
- */
-extern void samsung_keypad_set_platdata(struct samsung_keypad_platdata *pd);
-
-/* defined by architecture to configure gpio. */
-extern void samsung_keypad_cfg_gpio(unsigned int rows, unsigned int cols);
-
-#endif /* __PLAT_SAMSUNG_KEYPAD_H */
arch/arm/mach-s3c/mach-crag6410.c +42 -14

107 lines not on this page · raw message

arch/arm/mach-s3c/setup-keypad-s3c64xx.c deleted +0 -20
deleted file mode 100644
index 8463ad37c6ab..000000000000
@@ -1,20 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-//
-// Copyright (c) 2010 Samsung Electronics Co., Ltd.
-//		http://www.samsung.com/
-//
-// GPIO configuration for S3C64XX KeyPad device
-
-#include <linux/gpio.h>
-#include "gpio-cfg.h"
-#include "keypad.h"
-#include "gpio-samsung.h"
-
-void samsung_keypad_cfg_gpio(unsigned int rows, unsigned int cols)
-{
-	/* Set all the necessary GPK pins to special-function 3: KP_ROW[x] */
-	s3c_gpio_cfgrange_nopull(S3C64XX_GPK(8), rows, S3C_GPIO_SFN(3));
-
-	/* Set all the necessary GPL pins to special-function 3: KP_COL[x] */
-	s3c_gpio_cfgrange_nopull(S3C64XX_GPL(0), cols, S3C_GPIO_SFN(3));
-}
Signature · 1 line
2.46.0.184.g6999bdac58-goog
maintainer Acked-by on v1 11/14
#30 lore raw

Re: [PATCH 11/14] ARM: s3c: crag6410: switch keypad device to software properties

Quoted 5 lines · Dmitry Torokhov

Switch the keypad device to use software properties to describe the keypad. This will allow dropping support for platform data from the samsung-keypad driver.

Quoted 12 lines
---
 arch/arm/mach-s3c/Kconfig                |  5 ---
 arch/arm/mach-s3c/Kconfig.s3c64xx        |  1 -
 arch/arm/mach-s3c/Makefile.s3c64xx       |  1 -
 arch/arm/mach-s3c/devs.c                 | 27 ------------
 arch/arm/mach-s3c/devs.h                 |  1 -
 arch/arm/mach-s3c/keypad.h               | 27 ------------
 arch/arm/mach-s3c/mach-crag6410.c        | 56 ++++++++++++++++++------
 arch/arm/mach-s3c/setup-keypad-s3c64xx.c | 20 ---------
 8 files changed, 42 insertions(+), 96 deletions(-)
 delete mode 100644 arch/arm/mach-s3c/keypad.h
 delete mode 100644 arch/arm/mach-s3c/setup-keypad-s3c64xx.c

Best regards,
Krzysztof

author maintainer
#31 lore raw

PATCH 12/14 Input: samsung-keypad - remove support for platform data

In reply to Dmitry Torokhov

Because there are no more users of samsung_keypad_platdata left in the kernel remove support for it from the driver.

The driver supports generic device properties so all configuration should be done using them instead of a custom platform data.

---
 drivers/input/keyboard/samsung-keypad.c | 190 +++++++++---------------
 include/linux/input/samsung-keypad.h    |  39 -----
 2 files changed, 70 insertions(+), 159 deletions(-)
 delete mode 100644 include/linux/input/samsung-keypad.h
drivers/input/keyboard/samsung-keypad.c +70 -120
index df2427ac63d7..78fa55498fc3 100644
@@ -12,6 +12,7 @@
 #include <linux/delay.h>
 #include <linux/err.h>
 #include <linux/input.h>
+#include <linux/input/matrix_keypad.h>
 #include <linux/interrupt.h>
 #include <linux/io.h>
 #include <linux/module.h>
@@ -21,7 +22,9 @@
 #include <linux/slab.h>
 #include <linux/of.h>
 #include <linux/sched.h>
-#include <linux/input/samsung-keypad.h>
+
+#define SAMSUNG_MAX_ROWS			8
+#define SAMSUNG_MAX_COLS			8
 
 #define SAMSUNG_KEYIFCON			0x00
 #define SAMSUNG_KEYIFSTSCLR			0x04
@@ -231,84 +234,43 @@ static void samsung_keypad_close(struct input_dev *input_dev)
 	samsung_keypad_stop(keypad);
 }
 
-static const struct matrix_keymap_data *
-samsung_parse_verbose_keymap(struct device *dev)
+static int samsung_keypad_parse_keymap(struct samsung_keypad *keypad)
 {
-	struct matrix_keymap_data *keymap_data;
+	struct matrix_keymap_data keymap_data = { 0 };
+	struct device *dev = &keypad->pdev->dev;
 	struct fwnode_handle *child;
 	u32 *keymap;
 	unsigned int key_count;
-
-	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);
-	}
+	int retval;
 
 	key_count = device_get_child_node_count(dev);
-	keymap = devm_kcalloc(dev, key_count, sizeof(*keymap), GFP_KERNEL);
-	if (!keymap) {
-		dev_err(dev, "could not allocate memory for keymap\n");
-		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;
+	if (key_count) {
+		keymap = kcalloc(key_count, sizeof(*keymap), GFP_KERNEL);
+		if (!keymap) {
+			dev_err(dev, "could not allocate memory for keymap\n");
+			return -ENOMEM;
+		}
 
-	pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
-	if (!pdata) {
-		dev_err(dev, "could not allocate memory for platform data\n");
-		return ERR_PTR(-ENOMEM);
-	}
+		keymap_data.keymap = keymap;
+		keymap_data.keymap_size = key_count;
 
-	device_property_read_u32(dev, "samsung,keypad-num-rows", &num_rows);
-	device_property_read_u32(dev, "samsung,keypad-num-columns", &num_cols);
+		device_for_each_child_node(dev, child) {
+			u32 row, col, key_code;
 
-	error = matrix_keypad_parse_properties(dev, &num_rows, &num_cols);
-	if (error)
-		return ERR_PTR(error);
+			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);
 
-	pdata->rows = num_rows;
-	pdata->cols = num_cols;
-
-	if (!device_property_present(dev, "linux,keymap")) {
-		keymap_data = samsung_parse_verbose_keymap(dev);
-		if (IS_ERR(keymap_data))
-			return ERR_CAST(keymap_data);
-
-		pdata->keymap_data = keymap_data;
+			*keymap++ = KEY(row, col, key_code);
+		}
 	}
 
-
-	pdata->no_autorepeat =
-		device_property_read_bool(dev, "linux,input-no-autorepeat");
-
-	pdata->wakeup = device_property_read_bool(dev, "wakeup-source") ||
-			/* legacy name */
-			device_property_read_bool(dev, "linux,input-wakeup");
-
-	return pdata;
+	retval = matrix_keypad_build_keymap(key_count ? &keymap_data : NULL,
+					    NULL, keypad->rows, keypad->cols,
+					    keypad->keycodes,
+					    keypad->input_dev);
+	kfree(keymap_data.keymap);
+	return retval;
 }
 
 static void samsung_disable_runtime_pm(void *data)
@@ -320,68 +282,39 @@ static void samsung_disable_runtime_pm(void *data)
 
 static int samsung_keypad_probe(struct platform_device *pdev)
 {
-	const struct samsung_keypad_platdata *pdata;
 	const struct platform_device_id *id;
+	struct device *dev = &pdev->dev;
 	struct samsung_keypad *keypad;
 	struct resource *res;
 	struct input_dev *input_dev;
 	unsigned int row_shift;
+	u32 num_rows = 0, num_cols = 0;
+	bool wakeup;
 	int error;
 
-	pdata = dev_get_platdata(&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);
-	}
+	device_property_read_u32(dev, "samsung,keypad-num-rows", &num_rows);
+	device_property_read_u32(dev, "samsung,keypad-num-columns", &num_cols);
 
-	if (!pdata->rows || pdata->rows > SAMSUNG_MAX_ROWS)
-		return -EINVAL;
+	error = matrix_keypad_parse_properties(dev, &num_rows, &num_cols);
+	if (error)
+		return error;
 
-	if (!pdata->cols || pdata->cols > SAMSUNG_MAX_COLS)
+	if (num_rows > SAMSUNG_MAX_ROWS || num_cols > SAMSUNG_MAX_COLS)
 		return -EINVAL;
 
-	/* initialize the gpio */
-	if (pdata->cfg_gpio)
-		pdata->cfg_gpio(pdata->rows, pdata->cols);
-
-	row_shift = get_count_order(pdata->cols);
+	row_shift = get_count_order(num_cols);
 
 	keypad = devm_kzalloc(&pdev->dev,
 			      struct_size(keypad, keycodes,
-					  pdata->rows << row_shift),
+					  num_rows << row_shift),
 			      GFP_KERNEL);
 	if (!keypad)
 		return -ENOMEM;
 
-	input_dev = devm_input_allocate_device(&pdev->dev);
-	if (!input_dev)
-		return -ENOMEM;
-
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!res)
-		return -ENODEV;
-
-	keypad->base = devm_ioremap(&pdev->dev, res->start, resource_size(res));
-	if (!keypad->base)
-		return -EBUSY;
-
-	keypad->clk = devm_clk_get_prepared(&pdev->dev, "keypad");
-	if (IS_ERR(keypad->clk)) {
-		dev_err(&pdev->dev, "failed to get keypad clk\n");
-		return PTR_ERR(keypad->clk);
-	}
-
-	keypad->input_dev = input_dev;
 	keypad->pdev = pdev;
 	keypad->row_shift = row_shift;
-	keypad->rows = pdata->rows;
-	keypad->cols = pdata->cols;
+	keypad->rows = num_rows;
+	keypad->cols = num_cols;
 	keypad->stopped = true;
 	init_waitqueue_head(&keypad->wait);
 
@@ -397,26 +330,45 @@ static int samsung_keypad_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
+	input_dev = devm_input_allocate_device(&pdev->dev);
+	if (!input_dev)
+		return -ENOMEM;
+
+	keypad->input_dev = input_dev;
+
 	input_dev->name = pdev->name;
 	input_dev->id.bustype = BUS_HOST;
 
 	input_dev->open = samsung_keypad_open;
 	input_dev->close = samsung_keypad_close;
 
-	error = matrix_keypad_build_keymap(pdata->keymap_data, NULL,
-					   pdata->rows, pdata->cols,
-					   keypad->keycodes, input_dev);
+	error = samsung_keypad_parse_keymap(keypad);
 	if (error) {
 		dev_err(&pdev->dev, "failed to build keymap\n");
 		return error;
 	}
 
 	input_set_capability(input_dev, EV_MSC, MSC_SCAN);
-	if (!pdata->no_autorepeat)
+
+	if (!device_property_read_bool(&pdev->dev, "linux,input-no-autorepeat"))
 		__set_bit(EV_REP, input_dev->evbit);
 
 	input_set_drvdata(input_dev, keypad);
 
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res)
+		return -ENODEV;
+
+	keypad->base = devm_ioremap(&pdev->dev, res->start, resource_size(res));
+	if (!keypad->base)
+		return -EBUSY;
+
+	keypad->clk = devm_clk_get_prepared(&pdev->dev, "keypad");
+	if (IS_ERR(keypad->clk)) {
+		dev_err(&pdev->dev, "failed to get keypad clk\n");
+		return PTR_ERR(keypad->clk);
+	}
+
 	keypad->irq = platform_get_irq(pdev, 0);
 	if (keypad->irq < 0) {
 		error = keypad->irq;
@@ -431,7 +383,11 @@ static int samsung_keypad_probe(struct platform_device *pdev)
 		return error;
 	}
 
-	device_init_wakeup(&pdev->dev, pdata->wakeup);
+	wakeup = device_property_read_bool(dev, "wakeup-source") ||
+		 /* legacy name */
+		 device_property_read_bool(dev, "linux,input-wakeup");
+	device_init_wakeup(&pdev->dev, wakeup);
+
 	platform_set_drvdata(pdev, keypad);
 
 	pm_runtime_enable(&pdev->dev);
@@ -444,12 +400,6 @@ static int samsung_keypad_probe(struct platform_device *pdev)
 	if (error)
 		return error;
 
-	if (!dev_get_platdata(&pdev->dev)) {
-		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;
 }
 
include/linux/input/samsung-keypad.h deleted +0 -39
deleted file mode 100644
index ab6b97114c08..000000000000
@@ -1,39 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-/*
- * Samsung Keypad platform data definitions
- *
- * Copyright (C) 2010 Samsung Electronics Co.Ltd
- * Author: Joonyoung Shim <[email protected]>
- */
-
-#ifndef __SAMSUNG_KEYPAD_H
-#define __SAMSUNG_KEYPAD_H
-
-#include <linux/input/matrix_keypad.h>
-
-#define SAMSUNG_MAX_ROWS	8
-#define SAMSUNG_MAX_COLS	8
-
-/**
- * struct samsung_keypad_platdata - Platform device data for Samsung Keypad.
- * @keymap_data: pointer to &matrix_keymap_data.
- * @rows: number of keypad row supported.
- * @cols: number of keypad col supported.
- * @no_autorepeat: disable key autorepeat.
- * @wakeup: controls whether the device should be set up as wakeup source.
- * @cfg_gpio: configure the GPIO.
- *
- * Initialisation data specific to either the machine or the platform
- * for the device driver to use or call-back when configuring gpio.
- */
-struct samsung_keypad_platdata {
-	const struct matrix_keymap_data	*keymap_data;
-	unsigned int rows;
-	unsigned int cols;
-	bool no_autorepeat;
-	bool wakeup;
-
-	void (*cfg_gpio)(unsigned int rows, unsigned int cols);
-};
-
-#endif /* __SAMSUNG_KEYPAD_H */
Signature · 1 line
2.46.0.184.g6999bdac58-goog
author maintainer
#32 lore raw

PATCH 13/14 ARM: s3c: crag6410: use software nodes/properties to set up GPIO keys

In reply to Dmitry Torokhov

Switch the gpio-keys device to use software inodes/properties to describe the buttons and switches. This will allow dropping support for platform data from the gpio-keys driver in the future.

---
 arch/arm/mach-s3c/gpio-samsung-s3c64xx.h |  5 ++
 arch/arm/mach-s3c/gpio-samsung.c         | 35 +++++++++++
 arch/arm/mach-s3c/mach-crag6410.c        | 80 +++++++++++++++++-------
 3 files changed, 99 insertions(+), 21 deletions(-)
arch/arm/mach-s3c/gpio-samsung-s3c64xx.h +5 -0
index 8ed144a0d474..7cf16cc085ea 100644
@@ -13,6 +13,8 @@
 
 #ifdef CONFIG_GPIO_SAMSUNG
 
+#include <linux/property.h>
+
 /* GPIO bank sizes */
 #define S3C64XX_GPIO_A_NR	(8)
 #define S3C64XX_GPIO_B_NR	(7)
@@ -89,6 +91,9 @@ enum s3c_gpio_number {
 /* define the number of gpios we need to the one after the GPQ() range */
 #define GPIO_BOARD_START (S3C64XX_GPQ(S3C64XX_GPIO_Q_NR) + 1)
 
+extern const struct software_node samsung_gpiochip_nodes[];
+#define SAMSUNG_GPIO_NODE(node)	&samsung_gpiochip_nodes[(node) - 'A']
+
 #endif /* GPIO_SAMSUNG */
 #endif /* GPIO_SAMSUNG_S3C64XX_H */
 
arch/arm/mach-s3c/gpio-samsung.c +35 -0
index 87daaa09e2c3..82f325112d30 100644
@@ -21,6 +21,7 @@
 #include <linux/device.h>
 #include <linux/ioport.h>
 #include <linux/of.h>
+#include <linux/property.h>
 #include <linux/slab.h>
 #include <linux/of_address.h>
 
@@ -788,6 +789,38 @@ static struct samsung_gpio_chip s3c64xx_gpios_2bit[] = {
 	},
 };
 
+const struct software_node samsung_gpiochip_nodes[] = {
+	SOFTWARE_NODE("GPA", NULL, NULL),
+	SOFTWARE_NODE("GPB", NULL, NULL),
+	SOFTWARE_NODE("GPC", NULL, NULL),
+	SOFTWARE_NODE("GPD", NULL, NULL),
+	SOFTWARE_NODE("GPE", NULL, NULL),
+	SOFTWARE_NODE("GPF", NULL, NULL),
+	SOFTWARE_NODE("GPG", NULL, NULL),
+	SOFTWARE_NODE("GPH", NULL, NULL),
+	SOFTWARE_NODE("GPI", NULL, NULL),
+	SOFTWARE_NODE("GPJ", NULL, NULL),
+	SOFTWARE_NODE("GPK", NULL, NULL),
+	SOFTWARE_NODE("GPL", NULL, NULL),
+	SOFTWARE_NODE("GPM", NULL, NULL),
+	SOFTWARE_NODE("GPN", NULL, NULL),
+	SOFTWARE_NODE("GPO", NULL, NULL),
+	SOFTWARE_NODE("GPP", NULL, NULL),
+	SOFTWARE_NODE("GPQ", NULL, NULL),
+};
+#define NUM_SAMSUNG_GPIOCHIPS ARRAY_SIZE(samsung_gpiochip_nodes)
+
+static void __init samsung_setup_gpiochip_nodes(void)
+{
+	const struct software_node *group[NUM_SAMSUNG_GPIOCHIPS + 1] = { 0 };
+	int i;
+
+	for (i = 0; i < NUM_SAMSUNG_GPIOCHIPS; i++)
+		group[i] = &samsung_gpiochip_nodes[i];
+
+	software_node_register_node_group(group);
+}
+
 /* TODO: cleanup soc_is_* */
 static __init int samsung_gpiolib_init(void)
 {
@@ -811,6 +844,8 @@ static __init int samsung_gpiolib_init(void)
 				S3C64XX_VA_GPIO);
 		samsung_gpiolib_add_4bit2_chips(s3c64xx_gpios_4bit2,
 				ARRAY_SIZE(s3c64xx_gpios_4bit2));
+
+		samsung_setup_gpiochip_nodes();
 	}
 
 	return 0;
arch/arm/mach-s3c/mach-crag6410.c +59 -21

115 lines not on this page · raw message

Signature · 1 line
2.46.0.184.g6999bdac58-goog
maintainer Acked-by on v1 13/14
#33 lore raw

Re: [PATCH 13/14] ARM: s3c: crag6410: use software nodes/properties to set up GPIO keys

Quoted 10 lines · Dmitry Torokhov

Switch the gpio-keys device to use software inodes/properties to describe the buttons and switches. This will allow dropping support for platform data from the gpio-keys driver in the future.

---
 arch/arm/mach-s3c/gpio-samsung-s3c64xx.h |  5 ++
 arch/arm/mach-s3c/gpio-samsung.c         | 35 +++++++++++
 arch/arm/mach-s3c/mach-crag6410.c        | 80 +++++++++++++++++-------
 3 files changed, 99 insertions(+), 21 deletions(-)

Best regards,
Krzysztof

author maintainer
#34 lore raw

PATCH 14/14 ARM: s3c: crag6410 - convert GPIO lookup tables to property entries

In reply to Dmitry Torokhov

Static property entries support defining GPIOs and are more similar to device tree properties and are not prone to losing link between device and a lookup table because of changes in device name. Convert the board to use them.

This also fixes issue with recent conversion to GPIO descriptors where GPIO lookup tables were specifying incorrect GPIO chip name ("GPIO<N>" vs "GP<N>").

Fixes 10a366f36e2a ("ASoC: wm1250-ev1: Convert to GPIO descriptors")
Fixes a45cf3cc72dd ("spi: s3c64xx: Convert to use GPIO descriptors")
Fixes 9a5ed0bac86e ("regulator: wm831x: Convert to use GPIO descriptors")
---
 arch/arm/mach-s3c/devs.c          |  35 ----------
 arch/arm/mach-s3c/devs.h          |   1 -
 arch/arm/mach-s3c/mach-crag6410.c | 108 ++++++++++++++++++------------
 3 files changed, 67 insertions(+), 77 deletions(-)
arch/arm/mach-s3c/devs.c +0 -35
index 31827cfc5700..e24967cc648b 100644
@@ -336,38 +336,3 @@ void __init dwc2_hsotg_set_platdata(struct dwc2_hsotg_plat *pd)
 		npd->phy_exit = s3c_usb_phy_exit;
 }
 #endif /* CONFIG_S3C_DEV_USB_HSOTG */
-
-#ifdef CONFIG_S3C64XX_DEV_SPI0
-static struct resource s3c64xx_spi0_resource[] = {
-	[0] = DEFINE_RES_MEM(S3C_PA_SPI0, SZ_256),
-	[1] = DEFINE_RES_IRQ(IRQ_SPI0),
-};
-
-struct platform_device s3c64xx_device_spi0 = {
-	.name		= "s3c6410-spi",
-	.id		= 0,
-	.num_resources	= ARRAY_SIZE(s3c64xx_spi0_resource),
-	.resource	= s3c64xx_spi0_resource,
-	.dev = {
-		.dma_mask		= &samsung_device_dma_mask,
-		.coherent_dma_mask	= DMA_BIT_MASK(32),
-	},
-};
-
-void __init s3c64xx_spi0_set_platdata(int src_clk_nr, int num_cs)
-{
-	struct s3c64xx_spi_info pd;
-
-	/* Reject invalid configuration */
-	if (!num_cs || src_clk_nr < 0) {
-		pr_err("%s: Invalid SPI configuration\n", __func__);
-		return;
-	}
-
-	pd.num_cs = num_cs;
-	pd.src_clk_nr = src_clk_nr;
-	pd.cfg_gpio = s3c64xx_spi0_cfg_gpio;
-
-	s3c_set_platdata(&pd, sizeof(pd), &s3c64xx_device_spi0);
-}
-#endif /* CONFIG_S3C64XX_DEV_SPI0 */
arch/arm/mach-s3c/devs.h +0 -1
index 2737990063b1..90a86ade3570 100644
@@ -27,7 +27,6 @@ extern struct platform_device *s3c24xx_uart_src[];
 
 extern struct platform_device s3c64xx_device_iis0;
 extern struct platform_device s3c64xx_device_iis1;
-extern struct platform_device s3c64xx_device_spi0;
 
 extern struct platform_device s3c_device_fb;
 extern struct platform_device s3c_device_hsmmc0;
arch/arm/mach-s3c/mach-crag6410.c +67 -41

160 lines not on this page · raw message

Signature · 1 line
2.46.0.184.g6999bdac58-goog
maintainer Acked-by on v1 14/14
#35 lore raw

Re: [PATCH 14/14] ARM: s3c: crag6410 - convert GPIO lookup tables to property entries

Quoted 13 lines · Dmitry Torokhov

Static property entries support defining GPIOs and are more similar to device tree properties and are not prone to losing link between device and a lookup table because of changes in device name. Convert the board to use them.

This also fixes issue with recent conversion to GPIO descriptors where GPIO lookup tables were specifying incorrect GPIO chip name ("GPIO<N>" vs "GP<N>").

Fixes 10a366f36e2a ("ASoC: wm1250-ev1: Convert to GPIO descriptors")
Fixes a45cf3cc72dd ("spi: s3c64xx: Convert to use GPIO descriptors")
Fixes 9a5ed0bac86e ("regulator: wm831x: Convert to use GPIO descriptors")
Quoted 5 lines
---
 arch/arm/mach-s3c/devs.c          |  35 ----------
 arch/arm/mach-s3c/devs.h          |   1 -
 arch/arm/mach-s3c/mach-crag6410.c | 108 ++++++++++++++++++------------
 3 files changed, 67 insertions(+), 77 deletions(-)

Best regards,
Krzysztof

#36 lore raw
In reply to Dmitry Torokhov
Quoted 15 lines · Dmitry Torokhov

This series attempts to rework samsumg=keypad driver to stop using platform data and instead rely on generic device properties only.

The first 8 patches are general cleanup/facelift patches.

The 9th patch introduces alternative binding that is more compact that the original one, which makes it more suitable for use in legacy (non DT) boards with static device properties. Note that the "new" binding is the standard binding for matrix keypads.

Patch #10 implements the new binding in the driver, #11 converts the only user of platform data in the mainline tree to the static device properties, and #12 drops support for platform data from the driver.

Quoted 5 lines

Patches #13 and #14 are "bonus" converting the rest of crag6410 to use software nodes/properties to describe GPIO keys, LEDs and other peripherals. Note that I believe they fix and issue with recent conversion to GPIO lookup tables - the names of gpiochip structures I think are "GP<N>" ("GPK", "GPL", etc) and not "GPIO<N>".

I had a (brief) look at the patches, everything looks fine to me, thanks for working on this! Let's see what Mark and Krzysztof think.

Arnd

author maintainer
#37 lore raw
Quoted 22 lines · Arnd Bergmann
Quoted 15 lines · Dmitry Torokhov

This series attempts to rework samsumg=keypad driver to stop using platform data and instead rely on generic device properties only.

The first 8 patches are general cleanup/facelift patches.

The 9th patch introduces alternative binding that is more compact that the original one, which makes it more suitable for use in legacy (non DT) boards with static device properties. Note that the "new" binding is the standard binding for matrix keypads.

Patch #10 implements the new binding in the driver, #11 converts the only user of platform data in the mainline tree to the static device properties, and #12 drops support for platform data from the driver.

Quoted 5 lines

Patches #13 and #14 are "bonus" converting the rest of crag6410 to use software nodes/properties to describe GPIO keys, LEDs and other peripherals. Note that I believe they fix and issue with recent conversion to GPIO lookup tables - the names of gpiochip structures I think are "GP<N>" ("GPK", "GPL", etc) and not "GPIO<N>".

Quoted 3 lines

I had a (brief) look at the patches, everything looks fine to me, thanks for working on this! Let's see what Mark and Krzysztof think.

Mark, were you able to give this a spin? Or should I address the DT binding comments from Krzysztof and Connor and resent for merge?

Thanks.

Signature · 1 line
Dmitry
#38 lore raw
Quoted 8 lines · Dmitry Torokhov
Quoted 3 lines · Arnd Bergmann

I had a (brief) look at the patches, everything looks fine to me, thanks for working on this! Let's see what Mark and Krzysztof think.

Mark, were you able to give this a spin? Or should I address the DT binding comments from Krzysztof and Connor and resent for merge?

Sorry, no - I've been some combination of ill, travelling and super busy since you posted it (sadly the bootloader for the board only supports booting from SD card so until I port u-boot it's not in my board farm and I need to specifically set it up on my desk whenver I want to do anything with it, especially for this where I need to poke at the keypad). I've got one more week of travel next week and one of the major sources of super busy just got better so I'm reasonably hopeful I'll get to it week of the 14th but probably worth respinning.