uboot-d1: add bootloader for upcoming d1 target
[openwrt/staging/mans0n.git] / package / boot / uboot-d1 / patches / 0049-gpio-axp-Use-DM_PMIC-functions-for-register-access.patch
1 From 532b81ac600b6a70a1421f86503cb6d8543edf1b Mon Sep 17 00:00:00 2001
2 From: Samuel Holland <samuel@sholland.org>
3 Date: Tue, 17 Aug 2021 20:01:55 -0500
4 Subject: [PATCH 49/90] gpio: axp: Use DM_PMIC functions for register access
5
6 Now that the PMIC driver implements the DM_PMIC uclass, those functions
7 can be used instead of the platform-specific "pmic_bus" functions.
8
9 Since the driver still uses the single set of register definitions from
10 axpXXX.h (as selected by AXPxxx_POWER), it still depends on one of those
11 choices, and therefore also AXP_PMIC_BUS.
12
13 Signed-off-by: Samuel Holland <samuel@sholland.org>
14 ---
15 drivers/gpio/axp_gpio.c | 27 ++++++++++++---------------
16 1 file changed, 12 insertions(+), 15 deletions(-)
17
18 --- a/drivers/gpio/axp_gpio.c
19 +++ b/drivers/gpio/axp_gpio.c
20 @@ -6,11 +6,11 @@
21 */
22
23 #include <common.h>
24 -#include <asm/arch/pmic_bus.h>
25 #include <asm/gpio.h>
26 #include <axp_pmic.h>
27 #include <dm.h>
28 #include <errno.h>
29 +#include <power/pmic.h>
30
31 #define AXP_GPIO_PREFIX "AXP0-"
32 #define AXP_GPIO_COUNT 4
33 @@ -40,7 +40,7 @@ static int axp_gpio_direction_input(stru
34 if (reg == 0)
35 return -EINVAL;
36
37 - return pmic_bus_write(reg, AXP_GPIO_CTRL_INPUT);
38 + return pmic_reg_write(dev->parent, reg, AXP_GPIO_CTRL_INPUT);
39 }
40
41 static int axp_gpio_direction_output(struct udevice *dev, unsigned pin,
42 @@ -52,26 +52,27 @@ static int axp_gpio_direction_output(str
43 if (reg == 0)
44 return -EINVAL;
45
46 - return pmic_bus_write(reg, val ? AXP_GPIO_CTRL_OUTPUT_HIGH :
47 - AXP_GPIO_CTRL_OUTPUT_LOW);
48 + return pmic_reg_write(dev->parent, reg,
49 + val ? AXP_GPIO_CTRL_OUTPUT_HIGH :
50 + AXP_GPIO_CTRL_OUTPUT_LOW);
51 }
52
53 static int axp_gpio_get_value(struct udevice *dev, unsigned pin)
54 {
55 - u8 reg, val, mask;
56 + u8 reg, mask;
57 int ret;
58
59 reg = axp_get_gpio_ctrl_reg(pin);
60 if (reg == 0)
61 return -EINVAL;
62
63 - ret = pmic_bus_read(AXP_GPIO_STATE, &val);
64 - if (ret)
65 + ret = pmic_reg_read(dev->parent, AXP_GPIO_STATE);
66 + if (ret < 0)
67 return ret;
68
69 mask = 1 << (pin + AXP_GPIO_STATE_OFFSET);
70
71 - return (val & mask) ? 1 : 0;
72 + return (ret & mask) ? 1 : 0;
73 }
74
75 static int axp_gpio_set_value(struct udevice *dev, unsigned pin, int val)
76 @@ -82,8 +83,9 @@ static int axp_gpio_set_value(struct ude
77 if (reg == 0)
78 return -EINVAL;
79
80 - return pmic_bus_write(reg, val ? AXP_GPIO_CTRL_OUTPUT_HIGH :
81 - AXP_GPIO_CTRL_OUTPUT_LOW);
82 + return pmic_reg_write(dev->parent, reg,
83 + val ? AXP_GPIO_CTRL_OUTPUT_HIGH :
84 + AXP_GPIO_CTRL_OUTPUT_LOW);
85 }
86
87 static const struct dm_gpio_ops axp_gpio_ops = {
88 @@ -96,11 +98,6 @@ static const struct dm_gpio_ops axp_gpio
89 static int axp_gpio_probe(struct udevice *dev)
90 {
91 struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
92 - int ret;
93 -
94 - ret = pmic_bus_init();
95 - if (ret)
96 - return ret;
97
98 /* Tell the uclass how many GPIOs we have */
99 uc_priv->bank_name = AXP_GPIO_PREFIX;