mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Janusz Krzysztofik <jmkrzyszt@gmail.com>
To: Tony Lindgren <tony@atomide.com>,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Boris Brezillon <boris.brezillon@bootlin.com>,
	Tomi Valkeinen <tomi.valkeinen@ti.com>,
	Mark Brown <broonie@kernel.org>
Cc: Aaro Koskinen <aaro.koskinen@iki.fi>,
	Richard Weinberger <richard@nod.at>,
	Peter Ujfalusi <peter.ujfalusi@ti.com>,
	Jarkko Nikula <jarkko.nikula@bitmer.com>,
	Liam Girdwood <lgirdwood@gmail.com>,
	linux-arm-kernel@lists.infradead.org, linux-omap@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-input@vger.kernel.org,
	linux-mtd@lists.infradead.org, linux-fbdev@vger.kernel.org,
	alsa-devel@alsa-project.org,
	Janusz Krzysztofik <jmkrzyszt@gmail.com>
Subject: [PATCH 2/6] Input: ams_delta_serio: use GPIO lookup table
Date: Fri, 18 May 2018 23:09:50 +0200	[thread overview]
Message-ID: <20180518210954.29044-2-jmkrzyszt@gmail.com> (raw)
In-Reply-To: <20180518210954.29044-1-jmkrzyszt@gmail.com>

Now as the Amstrad Delta board provides GPIO lookup tables, switch from
GPIO numbers to GPIO descriptors and use the table to locate required
GPIO pins.

Declare static variables for storing GPIO descriptors and replace
gpio_ functions with their gpiod_ equivalents.

Pin naming used by the driver should be followed while respective GPIO
lookup table is initialized by a board init code.

Created and tested against linux-4.17-rc3, on top of patch 1/6 "ARM:
OMAP1: ams-delta: add GPIO lookup tables"

Signed-off-by: Janusz Krzysztofik <jmkrzyszt@gmail.com>
---
 drivers/input/serio/ams_delta_serio.c | 98 +++++++++++++++++++----------------
 1 file changed, 53 insertions(+), 45 deletions(-)

diff --git a/drivers/input/serio/ams_delta_serio.c b/drivers/input/serio/ams_delta_serio.c
index 3df501c3421b..dd1f8f118c08 100644
--- a/drivers/input/serio/ams_delta_serio.c
+++ b/drivers/input/serio/ams_delta_serio.c
@@ -20,14 +20,13 @@
  * However, when used with the E3 mailboard that producecs non-standard
  * scancodes, a custom key table must be prepared and loaded from userspace.
  */
-#include <linux/gpio.h>
+#include <linux/gpio/consumer.h>
 #include <linux/irq.h>
 #include <linux/serio.h>
 #include <linux/slab.h>
 #include <linux/module.h>
 
 #include <asm/mach-types.h>
-#include <mach/board-ams-delta.h>
 
 #include <mach/ams-delta-fiq.h>
 
@@ -36,6 +35,10 @@ MODULE_DESCRIPTION("AMS Delta (E3) keyboard port driver");
 MODULE_LICENSE("GPL");
 
 static struct serio *ams_delta_serio;
+static struct gpio_desc *gpiod_data;
+static struct gpio_desc *gpiod_clock;
+static struct gpio_desc *gpiod_power;
+static struct gpio_desc *gpiod_dataout;
 
 static int check_data(int data)
 {
@@ -92,7 +95,7 @@ static irqreturn_t ams_delta_serio_interrupt(int irq, void *dev_id)
 static int ams_delta_serio_open(struct serio *serio)
 {
 	/* enable keyboard */
-	gpio_set_value(AMS_DELTA_GPIO_PIN_KEYBRD_PWR, 1);
+	gpiod_set_value(gpiod_power, 1);
 
 	return 0;
 }
@@ -100,32 +103,9 @@ static int ams_delta_serio_open(struct serio *serio)
 static void ams_delta_serio_close(struct serio *serio)
 {
 	/* disable keyboard */
-	gpio_set_value(AMS_DELTA_GPIO_PIN_KEYBRD_PWR, 0);
+	gpiod_set_value(gpiod_power, 0);
 }
 
-static const struct gpio ams_delta_gpios[] __initconst_or_module = {
-	{
-		.gpio	= AMS_DELTA_GPIO_PIN_KEYBRD_DATA,
-		.flags	= GPIOF_DIR_IN,
-		.label	= "serio-data",
-	},
-	{
-		.gpio	= AMS_DELTA_GPIO_PIN_KEYBRD_CLK,
-		.flags	= GPIOF_DIR_IN,
-		.label	= "serio-clock",
-	},
-	{
-		.gpio	= AMS_DELTA_GPIO_PIN_KEYBRD_PWR,
-		.flags	= GPIOF_OUT_INIT_LOW,
-		.label	= "serio-power",
-	},
-	{
-		.gpio	= AMS_DELTA_GPIO_PIN_KEYBRD_DATAOUT,
-		.flags	= GPIOF_OUT_INIT_LOW,
-		.label	= "serio-dataout",
-	},
-};
-
 static int __init ams_delta_serio_init(void)
 {
 	int err;
@@ -145,36 +125,62 @@ static int __init ams_delta_serio_init(void)
 	strlcpy(ams_delta_serio->phys, "GPIO/serio0",
 			sizeof(ams_delta_serio->phys));
 
-	err = gpio_request_array(ams_delta_gpios,
-				ARRAY_SIZE(ams_delta_gpios));
-	if (err) {
-		pr_err("ams_delta_serio: Couldn't request gpio pins\n");
+	gpiod_data = gpiod_get(NULL, "data", GPIOD_IN);
+	if (IS_ERR(gpiod_data)) {
+		err = PTR_ERR(gpiod_data);
+		pr_err("%s: 'data' GPIO request failed (%d)\n", __func__,
+		       err);
 		goto serio;
 	}
+	gpiod_clock = gpiod_get(NULL, "clock", GPIOD_IN);
+	if (IS_ERR(gpiod_clock)) {
+		err = PTR_ERR(gpiod_clock);
+		pr_err("%s: 'clock' GPIO request failed (%d)\n", __func__,
+		       err);
+		goto gpio_data;
+	}
+	gpiod_power = gpiod_get(NULL, "power", GPIOD_OUT_LOW);
+	if (IS_ERR(gpiod_power)) {
+		err = PTR_ERR(gpiod_power);
+		pr_err("%s: 'power' GPIO request failed (%d)\n", __func__,
+		       err);
+		goto gpio_clock;
+	}
+	gpiod_dataout = gpiod_get(NULL, "dataout", GPIOD_OUT_LOW);
+	if (IS_ERR(gpiod_dataout)) {
+		err = PTR_ERR(gpiod_dataout);
+		pr_err("%s: 'dataout' GPIO request failed (%d)\n",
+		       __func__, err);
+		goto gpio_power;
+	}
 
-	err = request_irq(gpio_to_irq(AMS_DELTA_GPIO_PIN_KEYBRD_CLK),
-			ams_delta_serio_interrupt, IRQ_TYPE_EDGE_RISING,
-			"ams-delta-serio", 0);
+	err = request_irq(gpiod_to_irq(gpiod_clock),
+			  ams_delta_serio_interrupt, IRQ_TYPE_EDGE_RISING,
+			  "ams-delta-serio", 0);
 	if (err < 0) {
-		pr_err("ams_delta_serio: couldn't request gpio interrupt %d\n",
-				gpio_to_irq(AMS_DELTA_GPIO_PIN_KEYBRD_CLK));
-		goto gpio;
+		pr_err("%s: 'clock' GPIO interrupt request failed (%d)\n",
+		       __func__, err);
+		goto gpio_dataout;
 	}
 	/*
 	 * Since GPIO register handling for keyboard clock pin is performed
 	 * at FIQ level, switch back from edge to simple interrupt handler
 	 * to avoid bad interaction.
 	 */
-	irq_set_handler(gpio_to_irq(AMS_DELTA_GPIO_PIN_KEYBRD_CLK),
-			handle_simple_irq);
+	irq_set_handler(gpiod_to_irq(gpiod_clock), handle_simple_irq);
 
 	serio_register_port(ams_delta_serio);
 	dev_info(&ams_delta_serio->dev, "%s\n", ams_delta_serio->name);
 
 	return 0;
-gpio:
-	gpio_free_array(ams_delta_gpios,
-			ARRAY_SIZE(ams_delta_gpios));
+gpio_dataout:
+	gpiod_put(gpiod_dataout);
+gpio_power:
+	gpiod_put(gpiod_power);
+gpio_clock:
+	gpiod_put(gpiod_clock);
+gpio_data:
+	gpiod_put(gpiod_data);
 serio:
 	kfree(ams_delta_serio);
 	return err;
@@ -184,8 +190,10 @@ module_init(ams_delta_serio_init);
 static void __exit ams_delta_serio_exit(void)
 {
 	serio_unregister_port(ams_delta_serio);
-	free_irq(gpio_to_irq(AMS_DELTA_GPIO_PIN_KEYBRD_CLK), 0);
-	gpio_free_array(ams_delta_gpios,
-			ARRAY_SIZE(ams_delta_gpios));
+	free_irq(gpiod_to_irq(gpiod_clock), 0);
+	gpiod_put(gpiod_dataout);
+	gpiod_put(gpiod_power);
+	gpiod_put(gpiod_clock);
+	gpiod_put(gpiod_data);
 }
 module_exit(ams_delta_serio_exit);
-- 
2.16.1

  reply	other threads:[~2018-05-18 21:10 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-18 21:09 [PATCH 1/6] ARM: OMAP1: ams-delta: add GPIO lookup tables Janusz Krzysztofik
2018-05-18 21:09 ` Janusz Krzysztofik [this message]
2018-05-20 20:17   ` [PATCH 2/6] Input: ams_delta_serio: use GPIO lookup table Dmitry Torokhov
2018-05-18 21:09 ` [PATCH 3/6] ASoC: ams_delta: " Janusz Krzysztofik
2018-05-21 10:05   ` Mark Brown
2018-05-23 18:52     ` Tony Lindgren
2018-05-24 20:35       ` Janusz Krzysztofik
2018-05-18 21:09 ` [PATCH 4/6] fbdev: omapfb: lcd_ams_delta: " Janusz Krzysztofik
2018-05-25 22:49   ` [Resend] " Janusz Krzysztofik
2018-07-09 19:16   ` [PATCH v2] video: " Janusz Krzysztofik
2018-07-17 16:54     ` [PATCH RESEND " Janusz Krzysztofik
2018-07-17 21:40       ` Janusz Krzysztofik
2018-05-18 21:09 ` [PATCH 5/6] mtd: rawnand: ams-delta: " Janusz Krzysztofik
2018-05-18 21:21   ` Andy Shevchenko
2018-05-18 23:15     ` Janusz Krzysztofik
2018-05-19 18:00       ` Andy Shevchenko
2018-05-19 21:55         ` Janusz Krzysztofik
2018-05-20 14:44           ` Andy Shevchenko
2018-05-20 15:37             ` Janusz Krzysztofik
2018-05-20 16:17               ` Andy Shevchenko
2018-05-20 17:25                 ` Miquel Raynal
2018-05-21  6:44                   ` Andy Shevchenko
2018-05-25 22:20             ` [PATCH 5/6 v2] " Janusz Krzysztofik
2018-05-30  9:05               ` Boris Brezillon
2018-05-30 17:43                 ` Janusz Krzysztofik
2018-05-30 17:52                   ` Boris Brezillon
2018-05-30 20:39                     ` Janusz Krzysztofik
2018-06-04  9:55                       ` Boris Brezillon
2018-06-04 16:48                         ` Janusz Krzysztofik
2018-06-04 23:09                           ` Boris Brezillon
2018-06-04 23:30                             ` Boris Brezillon
2018-07-09 19:38               ` [PATCH v3] " Janusz Krzysztofik
2018-07-17 17:05                 ` [PATCH RESEND " Janusz Krzysztofik
2018-07-17 20:31                   ` Boris Brezillon
2018-07-17 19:37                 ` [PATCH " Boris Brezillon
2018-07-17 20:20                   ` Janusz Krzysztofik
2018-07-17 20:22                     ` Boris Brezillon
2018-05-20 19:27           ` [alsa-devel] [PATCH 5/6] " Ladislav Michl
2018-05-20 20:08             ` Dmitry Torokhov
2018-05-21 20:21               ` Janusz Krzysztofik
2018-05-21 20:57                 ` Dmitry Torokhov
2018-05-18 21:09 ` [PATCH 6/6] ARM: OMAP1: ams-delta: make board header file local to mach-omap1 Janusz Krzysztofik
2018-05-21 17:35 ` [PATCH 1/6] ARM: OMAP1: ams-delta: add GPIO lookup tables Tony Lindgren
2018-05-21 18:10   ` Janusz Krzysztofik
2018-07-17 23:14 ` [PATCH v2 0/3] ARM: OMAP1: ams-delta: Complete driver gpiod migration Janusz Krzysztofik
2018-07-17 23:14   ` [PATCH v2 1/3 v2] video: fbdev: omapfb: lcd_ams_delta: use GPIO lookup table Janusz Krzysztofik
2018-07-17 23:14   ` [PATCH v2 2/3 v4] mtd: rawnand: ams-delta: " Janusz Krzysztofik
2018-07-18  7:20     ` Miquel Raynal
2018-07-19  6:39       ` Tony Lindgren
2018-07-17 23:14   ` [PATCH v2 3/3] ARM: OMAP1: ams-delta: make board header file local to mach-omap1 Janusz Krzysztofik
2018-07-18 14:18   ` [PATCH v2 0/3] ARM: OMAP1: ams-delta: Complete driver gpiod migration Gregory CLEMENT
2018-09-09 22:56   ` [PATCH v3 " Janusz Krzysztofik
2018-09-09 22:56     ` [PATCH v3 1/3] video: fbdev: omapfb: lcd_ams_delta: use GPIO lookup table Janusz Krzysztofik
2018-09-10  7:15       ` Linus Walleij
2018-10-03 13:03       ` [PATCH v4] " Janusz Krzysztofik
2018-10-08 10:50         ` Bartlomiej Zolnierkiewicz
2018-09-09 22:56     ` [PATCH v3 2/3] mtd: rawnand: ams-delta: " Janusz Krzysztofik
2018-09-19 22:17       ` [PATCH v5] " Janusz Krzysztofik
2018-09-20 15:33         ` Linus Walleij
2018-09-23 11:35         ` Miquel Raynal
2018-09-09 22:56     ` [PATCH v3 3/3] ARM: OMAP1: ams-delta: make board header file local to mach-omap1 Janusz Krzysztofik
2018-09-19 18:10     ` [PATCH v3 0/3] ARM: OMAP1: ams-delta: Complete driver gpiod migration Janusz Krzysztofik
2018-09-20 20:58       ` Tony Lindgren

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=20180518210954.29044-2-jmkrzyszt@gmail.com \
    --to=jmkrzyszt@gmail.com \
    --cc=aaro.koskinen@iki.fi \
    --cc=alsa-devel@alsa-project.org \
    --cc=boris.brezillon@bootlin.com \
    --cc=broonie@kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=jarkko.nikula@bitmer.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-fbdev@vger.kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=peter.ujfalusi@ti.com \
    --cc=richard@nod.at \
    --cc=tomi.valkeinen@ti.com \
    --cc=tony@atomide.com \
    /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

all inboxes | Powered by JetHome®