Skip to contentSkip to conversation

lib: utils/gpio: Fix RV32 compile error for designware GPIO driver

PATCH New Anup Patel 3 participants 4 messages Jul 12, 2023 – Jul 13, 2023

lore
Share & tools
lore

Anup Patel

author
#0 lore raw

PATCH v2 1/1 lib: utils/gpio: Fix RV32 compile error for designware GPIO driver

Currently, we see following compile error in the designeware GPIO driver for RV32 systems:

lib/utils/gpio/fdt_gpio_designware.c:115:20: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
115 | chip->dr = (void *)addr + (bank * 0xc);
| ^
lib/utils/gpio/fdt_gpio_designware.c:116:21: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
116 | chip->ext = (void *)addr + (bank * 4) + 0x50;

We fix the above error using an explicit type-cast to 'unsigned long'.

Fixes 7828eebaaa77 ("gpio/desginware: add Synopsys DesignWare APB GPIO support")

---
Changes since v1:
- Use uintptr_t in-place of ulong data type.

---
 lib/utils/gpio/fdt_gpio_designware.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/utils/gpio/fdt_gpio_designware.c +2 -2
index 6223d7e..018e2d5 100644
@@ -112,8 +112,8 @@ static int dw_gpio_init_bank(void *fdt, int nodeoff, u32 phandle,
 
 	chip = &dw_gpio_chip_array[dw_gpio_chip_count];
 
-	chip->dr = (void *)addr + (bank * 0xc);
-	chip->ext = (void *)addr + (bank * 4) + 0x50;
+	chip->dr = (void *)(uintptr_t)addr + (bank * 0xc);
+	chip->ext = (void *)(uintptr_t)addr + (bank * 4) + 0x50;
 	chip->chip.driver = &fdt_gpio_designware;
 	chip->chip.id = phandle;
 	chip->chip.ngpio = nr_pins;
Signature · 1 line
2.34.1
Applied
#1 lore raw

PATCH v2 1/1 lib: utils/gpio: Fix RV32 compile error for designware GPIO driver

Quoted 10 lines · On Wed, Jul 12, 2023 at 9:33?AM Anup Patel <[email protected]> wrote:

Currently, we see following compile error in the designeware GPIO driver for RV32 systems:

lib/utils/gpio/fdt_gpio_designware.c:115:20: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
115 | chip->dr = (void *)addr + (bank * 0xc);
| ^
lib/utils/gpio/fdt_gpio_designware.c:116:21: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
116 | chip->ext = (void *)addr + (bank * 4) + 0x50;

Quoted 5 lines

We fix the above error using an explicit type-cast to 'unsigned long'.

Fixes 7828eebaaa77 ("gpio/desginware: add Synopsys DesignWare APB GPIO support")

Applied this patch to the riscv/opensbi repo.

Regards,
Anup

Quoted 25 lines

---
Changes since v1:
- Use uintptr_t in-place of ulong data type.

---
 lib/utils/gpio/fdt_gpio_designware.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/utils/gpio/fdt_gpio_designware.c +2 -3
index 6223d7e..018e2d5 100644
@@ -112,8 +112,8 @@ static int dw_gpio_init_bank(void *fdt, int nodeoff, u32 phandle,
 
        chip = &dw_gpio_chip_array[dw_gpio_chip_count];
 
-       chip->dr = (void *)addr + (bank * 0xc);
-       chip->ext = (void *)addr + (bank * 4) + 0x50;
+       chip->dr = (void *)(uintptr_t)addr + (bank * 0xc);
+       chip->ext = (void *)(uintptr_t)addr + (bank * 4) + 0x50;
        chip->chip.driver = &fdt_gpio_designware;
        chip->chip.id = phandle;
        chip->chip.ngpio = nr_pins;
--

2.34.1

#2 lore raw

PATCH v2 1/1 lib: utils/gpio: Fix RV32 compile error for designware GPIO driver

In reply to Anup Patel
Quoted 26 lines · Anup Patel

Currently, we see following compile error in the designeware GPIO driver for RV32 systems:

lib/utils/gpio/fdt_gpio_designware.c:115:20: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
115 | chip->dr = (void *)addr + (bank * 0xc);
| ^
lib/utils/gpio/fdt_gpio_designware.c:116:21: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
116 | chip->ext = (void *)addr + (bank * 4) + 0x50;

We fix the above error using an explicit type-cast to 'unsigned long'.

Fixes 7828eebaaa77 ("gpio/desginware: add Synopsys DesignWare APB GPIO support")

---
Changes since v1:
- Use uintptr_t in-place of ulong data type.

---
  lib/utils/gpio/fdt_gpio_designware.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
lib/utils/gpio/fdt_gpio_designware.c +0 -0
index 6223d7e..018e2d5 100644

lib/utils/gpio/fdt_gpio_designware.c static int dw_gpio_init_bank(void *fdt, int nodeoff, u32 phandle, · line 116

Quoted 7 lines
lib/utils/gpio/fdt_gpio_designware.c +2 -2
@@ -112,8 +112,8 @@ static int dw_gpio_init_bank(void *fdt, int nodeoff, u32 phandle,
 
  	chip = &dw_gpio_chip_array[dw_gpio_chip_count];
 
-	chip->dr = (void *)addr + (bank * 0xc);
-	chip->ext = (void *)addr + (bank * 4) + 0x50;
+	chip->dr = (void *)(uintptr_t)addr + (bank * 0xc);
+	chip->ext = (void *)(uintptr_t)addr + (bank * 4) + 0x50;

would a macro to do this, maybe called fdt_addr_to_ptr(addr) ?

Quoted 3 lines
lib/utils/gpio/fdt_gpio_designware.c +0 -0
  	chip->chip.driver = &fdt_gpio_designware;
  	chip->chip.id = phandle;
  	chip->chip.ngpio = nr_pins;
Signature · 4 lines
Ben Dooks				http://www.codethink.co.uk/
Senior Engineer				Codethink - Providing Genius

https://www.codethink.co.uk/privacy.html
#3 lore raw

PATCH v2 1/1 lib: utils/gpio: Fix RV32 compile error for designware GPIO driver

Quoted 29 lines · On Wed, Jul 12, 2023 at 2:49?PM Ben Dooks <[email protected]> wrote:
Quoted 27 lines · Anup Patel

Currently, we see following compile error in the designeware GPIO driver for RV32 systems:

lib/utils/gpio/fdt_gpio_designware.c:115:20: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
115 | chip->dr = (void *)addr + (bank * 0xc);
| ^
lib/utils/gpio/fdt_gpio_designware.c:116:21: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
116 | chip->ext = (void *)addr + (bank * 4) + 0x50;

We fix the above error using an explicit type-cast to 'unsigned long'.

Fixes 7828eebaaa77 ("gpio/desginware: add Synopsys DesignWare APB GPIO support")

---
Changes since v1:
- Use uintptr_t in-place of ulong data type.

---
  lib/utils/gpio/fdt_gpio_designware.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
lib/utils/gpio/fdt_gpio_designware.c +0 -0
index 6223d7e..018e2d5 100644
@@ -112,8 +112,8 @@ static int dw_gpio_init_bank(void *fdt, int nodeoff, u32 phandle,
 
Quoted 8 lines

lib/utils/gpio/fdt_gpio_designware.c static int dw_gpio_init_bank(void *fdt, int nodeoff, u32 phandle, · line 116

Quoted 6 lines
lib/utils/gpio/fdt_gpio_designware.c +2 -2
      chip = &dw_gpio_chip_array[dw_gpio_chip_count];
 
-     chip->dr = (void *)addr + (bank * 0xc);
-     chip->ext = (void *)addr + (bank * 4) + 0x50;
+     chip->dr = (void *)(uintptr_t)addr + (bank * 0xc);
+     chip->ext = (void *)(uintptr_t)addr + (bank * 4) + 0x50;

would a macro to do this, maybe called fdt_addr_to_ptr(addr) ?

Yes, some generic addr_to_ptr() macro would be useful to avoid compile error in future. It need not be FDT specific.

Quoted 11 lines

lib/utils/gpio/fdt_gpio_designware.c static int dw_gpio_init_bank(void *fdt, int nodeoff, u32 phandle, · line 119

Quoted 4 lines
lib/utils/gpio/fdt_gpio_designware.c +0 -0
      chip->chip.driver = &fdt_gpio_designware;
      chip->chip.id = phandle;
      chip->chip.ngpio = nr_pins;

--
Ben Dooks http://www.codethink.co.uk/
Senior Engineer Codethink - Providing Genius

https://www.codethink.co.uk/privacy.html

Regards,
Anup