All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [PATCH v4 13/16] gpio: x86: Drop the deprecated methods in intel_gpio
Date: Thu,  4 Feb 2021 21:22:06 -0700	[thread overview]
Message-ID: <20210205042210.2949365-14-sjg@chromium.org> (raw)
In-Reply-To: <20210205042210.2949365-1-sjg@chromium.org>

We don't need to implement direction_input() and direction_output()
anymore. Drop them and use update_flags() instead.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

(no changes since v1)

 arch/x86/include/asm/intel_pinctrl_defs.h |  5 ++
 drivers/gpio/intel_gpio.c                 | 72 ++++++++++++-----------
 2 files changed, 43 insertions(+), 34 deletions(-)

diff --git a/arch/x86/include/asm/intel_pinctrl_defs.h b/arch/x86/include/asm/intel_pinctrl_defs.h
index 1ea141f082f..5d83d24bae2 100644
--- a/arch/x86/include/asm/intel_pinctrl_defs.h
+++ b/arch/x86/include/asm/intel_pinctrl_defs.h
@@ -11,6 +11,11 @@
 
 /* This file is included by device trees, so avoid BIT() macros */
 
+#define GPIO_DW_SIZE(x)			(sizeof(u32) * (x))
+#define PAD_CFG_OFFSET(x, dw_num)	((x) + GPIO_DW_SIZE(dw_num))
+#define PAD_CFG0_OFFSET(x)		PAD_CFG_OFFSET(x, 0)
+#define PAD_CFG1_OFFSET(x)		PAD_CFG_OFFSET(x, 1)
+
 #define PAD_CFG0_TX_STATE_BIT		0
 #define PAD_CFG0_TX_STATE		(1 << PAD_CFG0_TX_STATE_BIT)
 #define PAD_CFG0_RX_STATE_BIT		1
diff --git a/drivers/gpio/intel_gpio.c b/drivers/gpio/intel_gpio.c
index eda95485c93..ab46a94dbc1 100644
--- a/drivers/gpio/intel_gpio.c
+++ b/drivers/gpio/intel_gpio.c
@@ -3,6 +3,8 @@
  * Copyright 2019 Google LLC
  */
 
+#define LOG_CATEGORY	UCLASS_GPIO
+
 #include <common.h>
 #include <dm.h>
 #include <errno.h>
@@ -23,38 +25,6 @@
 #include <dm/acpi.h>
 #include <dt-bindings/gpio/x86-gpio.h>
 
-static int intel_gpio_direction_input(struct udevice *dev, uint offset)
-{
-	struct udevice *pinctrl = dev_get_parent(dev);
-	uint config_offset;
-
-	config_offset = intel_pinctrl_get_config_reg_offset(pinctrl, offset);
-
-	pcr_clrsetbits32(pinctrl, config_offset,
-			 PAD_CFG0_MODE_MASK | PAD_CFG0_TX_STATE |
-				  PAD_CFG0_RX_DISABLE,
-			 PAD_CFG0_MODE_GPIO | PAD_CFG0_TX_DISABLE);
-
-	return 0;
-}
-
-static int intel_gpio_direction_output(struct udevice *dev, uint offset,
-				       int value)
-{
-	struct udevice *pinctrl = dev_get_parent(dev);
-	uint config_offset;
-
-	config_offset = intel_pinctrl_get_config_reg_offset(pinctrl, offset);
-
-	pcr_clrsetbits32(pinctrl, config_offset,
-			 PAD_CFG0_MODE_MASK | PAD_CFG0_RX_STATE |
-				  PAD_CFG0_TX_DISABLE | PAD_CFG0_TX_STATE,
-			 PAD_CFG0_MODE_GPIO | PAD_CFG0_RX_DISABLE |
-				  (value ? PAD_CFG0_TX_STATE : 0));
-
-	return 0;
-}
-
 static int intel_gpio_get_value(struct udevice *dev, uint offset)
 {
 	struct udevice *pinctrl = dev_get_parent(dev);
@@ -130,6 +100,41 @@ static int intel_gpio_xlate(struct udevice *orig_dev, struct gpio_desc *desc,
 	return 0;
 }
 
+static int intel_gpio_set_flags(struct udevice *dev, unsigned int offset,
+				ulong flags)
+{
+	struct udevice *pinctrl = dev_get_parent(dev);
+	u32 bic0 = 0, bic1 = 0;
+	u32 or0, or1;
+	uint config_offset;
+
+	config_offset = intel_pinctrl_get_config_reg_offset(pinctrl, offset);
+
+	if (flags & GPIOD_IS_OUT) {
+		bic0 |= PAD_CFG0_MODE_MASK | PAD_CFG0_RX_STATE |
+			PAD_CFG0_TX_DISABLE;
+		or0 |= PAD_CFG0_MODE_GPIO | PAD_CFG0_RX_DISABLE;
+	} else if (flags & GPIOD_IS_IN) {
+		bic0 |= PAD_CFG0_MODE_MASK | PAD_CFG0_TX_STATE |
+			PAD_CFG0_RX_DISABLE;
+		or0 |= PAD_CFG0_MODE_GPIO | PAD_CFG0_TX_DISABLE;
+	}
+	if (flags & GPIOD_PULL_UP) {
+		bic1 |= PAD_CFG1_PULL_MASK;
+		or1 |= PAD_CFG1_PULL_UP_20K;
+	} else if (flags & GPIOD_PULL_DOWN) {
+		bic1 |= PAD_CFG1_PULL_MASK;
+		or1 |= PAD_CFG1_PULL_DN_20K;
+	}
+
+	pcr_clrsetbits32(pinctrl, PAD_CFG0_OFFSET(config_offset), bic0, or0);
+	pcr_clrsetbits32(pinctrl, PAD_CFG1_OFFSET(config_offset), bic1, or1);
+	log_debug("%s: flags=%lx, offset=%x, config_offset=%x, %x/%x %x/%x\n",
+		  dev->name, flags, offset, config_offset, bic0, or0, bic1, or1);
+
+	return 0;
+}
+
 #if CONFIG_IS_ENABLED(ACPIGEN)
 static int intel_gpio_get_acpi(const struct gpio_desc *desc,
 			       struct acpi_gpio *gpio)
@@ -177,12 +182,11 @@ static int intel_gpio_of_to_plat(struct udevice *dev)
 }
 
 static const struct dm_gpio_ops gpio_intel_ops = {
-	.direction_input	= intel_gpio_direction_input,
-	.direction_output	= intel_gpio_direction_output,
 	.get_value		= intel_gpio_get_value,
 	.set_value		= intel_gpio_set_value,
 	.get_function		= intel_gpio_get_function,
 	.xlate			= intel_gpio_xlate,
+	.set_flags		= intel_gpio_set_flags,
 #if CONFIG_IS_ENABLED(ACPIGEN)
 	.get_acpi		= intel_gpio_get_acpi,
 #endif
-- 
2.30.0.478.g8a0d178c01-goog

  parent reply	other threads:[~2021-02-05  4:22 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-05  4:21 [PATCH v4 00/16] gpio: Update and simplify the uclass API Simon Glass
2021-02-05  4:21 ` [PATCH v4 01/16] gpio: Disable functions not used with of-platdata Simon Glass
2021-03-04 18:13   ` Tom Rini
2021-02-05  4:21 ` [PATCH v4 02/16] dm: gpio: Rename set_dir_flags() method to update_flags() Simon Glass
2021-03-04 18:14   ` Tom Rini
2021-02-05  4:21 ` [PATCH v4 03/16] dm: gpio: Rename get_dir_flags() method to get_flags() Simon Glass
2021-03-04 18:14   ` Tom Rini
2021-02-05  4:21 ` [PATCH v4 04/16] gpio: Rename dm_gpio_get_dir_flags() to dm_gpio_get_flags() Simon Glass
2021-03-04 18:14   ` Tom Rini
2021-02-05  4:21 ` [PATCH v4 05/16] gpio: Drop dm_gpio_set_dir() Simon Glass
2021-03-03 20:39   ` Tom Rini
2021-03-04 14:22     ` Simon Glass
2021-03-04 15:09       ` Tom Rini
2021-02-05  4:21 ` [PATCH v4 06/16] gpio: sandbox: Rename GPIO dir_flags to flags Simon Glass
2021-03-04 18:14   ` Tom Rini
2021-02-05  4:22 ` [PATCH v4 07/16] gpio: sandbox: Use a separate flag for the value Simon Glass
2021-03-04 18:14   ` Tom Rini
2021-02-05  4:22 ` [PATCH v4 08/16] gpio: sandbox: Fully separate pin value from output value Simon Glass
2021-03-04 18:14   ` Tom Rini
2021-02-05  4:22 ` [PATCH v4 09/16] gpio: sandbox: Make sandbox_gpio_set_flags() set all flags Simon Glass
2021-03-04 18:14   ` Tom Rini
2021-02-05  4:22 ` [PATCH v4 10/16] dm: gpio: Add a way to update flags Simon Glass
2021-02-08  9:00   ` Köry Maincent
2021-02-08 17:33   ` Patrick DELAUNAY
2021-02-09  4:28     ` Simon Glass
2021-02-10  8:38       ` Patrick DELAUNAY
2021-02-13  4:17         ` Simon Glass
2021-03-04 18:14   ` Tom Rini
2021-02-05  4:22 ` [PATCH v4 11/16] gpio: Replace direction_input() and direction_output() Simon Glass
2021-03-04 18:14   ` Tom Rini
2021-02-05  4:22 ` [PATCH v4 12/16] gpio: Use an 'ops' variable everywhere Simon Glass
2021-03-04 18:14   ` Tom Rini
2021-02-05  4:22 ` Simon Glass [this message]
2021-03-04 18:15   ` [PATCH v4 13/16] gpio: x86: Drop the deprecated methods in intel_gpio Tom Rini
2021-02-05  4:22 ` [PATCH v4 14/16] gpio: sandbox: Track whether a GPIO is driven Simon Glass
2021-03-04 18:15   ` Tom Rini
2021-02-05  4:22 ` [PATCH v4 15/16] gpio: Define the log category in the uclass Simon Glass
2021-03-04 18:15   ` Tom Rini
2021-02-05  4:22 ` [PATCH v4 16/16] gpio: Add a way to read 3-way strapping pins Simon Glass
2021-02-08 18:13   ` Patrick DELAUNAY
2021-02-08 23:41     ` Simon Glass
2021-03-04 18:15   ` Tom Rini

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=20210205042210.2949365-14-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.