uboot-d1: add bootloader for upcoming d1 target
[openwrt/staging/981213.git] / package / boot / uboot-d1 / patches / 0051-gpio-axp-Add-support-for-getting-the-pin-function.patch
1 From 37e19d9b8a23c88413dd845dbb3dd58dd3636a6d Mon Sep 17 00:00:00 2001
2 From: Samuel Holland <samuel@sholland.org>
3 Date: Sat, 28 Aug 2021 00:36:33 -0500
4 Subject: [PATCH 51/90] gpio: axp: Add support for getting the pin function
5
6 Implement the .get_function operation, so the gpio command can report
7 the current function. Since the GPIOF_FUNC (versus GPIOF_UNUSED) mux
8 values vary among the PMICs, report all non-GPIO mux values as UNKNOWN.
9
10 Signed-off-by: Samuel Holland <samuel@sholland.org>
11 ---
12 drivers/gpio/axp_gpio.c | 19 +++++++++++++++++++
13 1 file changed, 19 insertions(+)
14
15 --- a/drivers/gpio/axp_gpio.c
16 +++ b/drivers/gpio/axp_gpio.c
17 @@ -39,6 +39,24 @@ static int axp_gpio_get_value(struct ude
18 return !!(ret & BIT(desc->status_offset + pin));
19 }
20
21 +static int axp_gpio_get_function(struct udevice *dev, unsigned pin)
22 +{
23 + const struct axp_gpio_desc *desc = dev_get_priv(dev);
24 + int ret;
25 +
26 + ret = pmic_reg_read(dev->parent, desc->pins[pin]);
27 + if (ret < 0)
28 + return ret;
29 +
30 + ret &= AXP_GPIO_CTRL_MASK;
31 + if (ret == desc->input_mux)
32 + return GPIOF_INPUT;
33 + if (ret == AXP_GPIO_CTRL_OUTPUT_HIGH || ret == AXP_GPIO_CTRL_OUTPUT_LOW)
34 + return GPIOF_OUTPUT;
35 +
36 + return GPIOF_UNKNOWN;
37 +}
38 +
39 static int axp_gpio_set_flags(struct udevice *dev, unsigned pin, ulong flags)
40 {
41 const struct axp_gpio_desc *desc = dev_get_priv(dev);
42 @@ -60,6 +78,7 @@ static int axp_gpio_set_flags(struct ude
43
44 static const struct dm_gpio_ops axp_gpio_ops = {
45 .get_value = axp_gpio_get_value,
46 + .get_function = axp_gpio_get_function,
47 .xlate = gpio_xlate_offs_flags,
48 .set_flags = axp_gpio_set_flags,
49 };