summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorHal Feng <hal.feng@starfivetech.com>2023-03-28 10:09:02 +0300
committerHal Feng <hal.feng@starfivetech.com>2023-03-28 12:44:50 +0300
commite403bfb4a219d037d0b308320331c7625b10caf1 (patch)
treefecbaa181e0af104a84423022cf47dcc87a00bac /drivers
parentbf37dcc53806f21f1e64912d5dfd00b99cb8d105 (diff)
downloadu-boot-e403bfb4a219d037d0b308320331c7625b10caf1.tar.xz
pinctrl: starfive: Add .get_function ops for the gpio driver
Support getting direction of gpio. Signed-off-by: Hal Feng <hal.feng@starfivetech.com>
Diffstat (limited to 'drivers')
-rwxr-xr-xdrivers/pinctrl/starfive/pinctrl-starfive.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/drivers/pinctrl/starfive/pinctrl-starfive.c b/drivers/pinctrl/starfive/pinctrl-starfive.c
index fc72699a2c..990d7ac526 100755
--- a/drivers/pinctrl/starfive/pinctrl-starfive.c
+++ b/drivers/pinctrl/starfive/pinctrl-starfive.c
@@ -275,6 +275,21 @@ const struct pinctrl_ops starfive_pinctrl_ops = {
.pinconf_set = starfive_pinconf_set,
};
+static int starfive_gpio_get_direction(struct udevice *dev, unsigned int off)
+{
+ struct udevice *pdev = dev->parent;
+ struct starfive_pinctrl_priv *priv = dev_get_priv(pdev);
+ struct starfive_pinctrl_soc_info *info = priv->info;
+
+ unsigned int offset = 4 * (off / 4);
+ unsigned int shift = 8 * (off % 4);
+ u32 doen = readl(priv->base + info->doen_reg_base + offset);
+
+ doen = (doen >> shift) & info->doen_mask;
+
+ return doen == GPOEN_ENABLE ? GPIOF_OUTPUT : GPIOF_INPUT;
+}
+
static int starfive_gpio_direction_input(struct udevice *dev, unsigned int off)
{
struct udevice *pdev = dev->parent;
@@ -365,6 +380,7 @@ static int starfive_gpio_probe(struct udevice *dev)
}
static const struct dm_gpio_ops starfive_gpio_ops = {
+ .get_function = starfive_gpio_get_direction,
.direction_input = starfive_gpio_direction_input,
.direction_output = starfive_gpio_direction_output,
.get_value = starfive_gpio_get_value,