[U-Boot] gpio: dm: Support manual relocation for gpio

Message ID ab569212739a7b810644f547c5502db1115fd5af.1531395412.git.michal.simek@xilinx.com
State New
Delegated to: Simon Glass
Headers show
Series
  • [U-Boot] gpio: dm: Support manual relocation for gpio
Related show

Commit Message

Michal Simek July 12, 2018, 11:36 a.m.
Relocate gpio ops as was done by:
"dm: Add support for all targets which requires MANUAL_RELOC"
(sha1: 484fdf5ba058b07be5ca82763aa2b72063540ef3)

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
---

 drivers/gpio/gpio-uclass.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

Comments

Simon Glass July 15, 2018, 9:21 p.m. | #1
On 12 July 2018 at 05:36, Michal Simek <michal.simek@xilinx.com> wrote:
> Relocate gpio ops as was done by:
> "dm: Add support for all targets which requires MANUAL_RELOC"
> (sha1: 484fdf5ba058b07be5ca82763aa2b72063540ef3)
>
> Signed-off-by: Michal Simek <michal.simek@xilinx.com>
> ---
>
>  drivers/gpio/gpio-uclass.c | 35 +++++++++++++++++++++++++++++++++++
>  1 file changed, 35 insertions(+)
>

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

Patch

diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c
index e9d08e2ebc25..da5e9ba6e524 100644
--- a/drivers/gpio/gpio-uclass.c
+++ b/drivers/gpio/gpio-uclass.c
@@ -854,11 +854,46 @@  static int gpio_pre_remove(struct udevice *dev)
 	return gpio_renumber(dev);
 }
 
+static int gpio_post_bind(struct udevice *dev)
+{
+#if defined(CONFIG_NEEDS_MANUAL_RELOC)
+	struct dm_gpio_ops *ops = (struct dm_gpio_ops *)device_get_ops(dev);
+	static int reloc_done;
+
+	if (!reloc_done) {
+		if (ops->request)
+			ops->request += gd->reloc_off;
+		if (ops->free)
+			ops->free += gd->reloc_off;
+		if (ops->direction_input)
+			ops->direction_input += gd->reloc_off;
+		if (ops->direction_output)
+			ops->direction_output += gd->reloc_off;
+		if (ops->get_value)
+			ops->get_value += gd->reloc_off;
+		if (ops->set_value)
+			ops->set_value += gd->reloc_off;
+		if (ops->get_open_drain)
+			ops->get_open_drain += gd->reloc_off;
+		if (ops->set_open_drain)
+			ops->set_open_drain += gd->reloc_off;
+		if (ops->get_function)
+			ops->get_function += gd->reloc_off;
+		if (ops->xlate)
+			ops->xlate += gd->reloc_off;
+
+		reloc_done++;
+	}
+#endif
+	return 0;
+}
+
 UCLASS_DRIVER(gpio) = {
 	.id		= UCLASS_GPIO,
 	.name		= "gpio",
 	.flags		= DM_UC_FLAG_SEQ_ALIAS,
 	.post_probe	= gpio_post_probe,
+	.post_bind	= gpio_post_bind,
 	.pre_remove	= gpio_pre_remove,
 	.per_device_auto_alloc_size = sizeof(struct gpio_dev_priv),
 };