summaryrefslogtreecommitdiff
path: root/lib/utils/gpio
AgeCommit message (Collapse)AuthorFilesLines
2024-11-28lib: utils/gpio: Use fdt_driver for initializationSamuel Holland5-36/+25
FDT gpio drivers have an extra .xlate operation, so they need to embed the `struct fdt_driver` inside the subsystem-specific type. The gpio subsystem always initializes the driver for a specific DT node. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-11-28treewide: Make carray arrays const and NULL-terminatedSamuel Holland1-3/+2
This allows the compiler to generate significantly better code, because it does not have to maintain either the loop counter or loop limit. Plus there are half as many symbols to relocate. This also simplifies passing carray arrays to helper functions. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-11-05lib: utils/gpio: Use FDT node offset as GPIO chip IDSamuel Holland4-21/+14
Since the FDT is not modified during driver initialization, node offsets are just as suitable as phandles for use as identifiers: they are stable and unique. With this change, it is no longer necessary to pass the phandle to the driver init functions, so these init functions now use the same prototype as other kinds of drivers. This matches what is already done for I2C adapters. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-11-05lib: utils/gpio: Remove fdt_gpio_driver() functionSamuel Holland1-16/+1
This function looks up a chip's driver by matching known drivers against chip->driver, but that is equivalent to using chip->driver directly. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-10-28lib: utils/gpio: designware: Allocate chips on the heapSamuel Holland1-10/+9
This reduces firmware size for SoCs which do not use this driver. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-08-24lib: utils/gpio: Constify FDT pointers in parsing functionsSamuel Holland4-6/+6
Indicate that none of these functions modify the devicetree by constifying the parameter type. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-07-04Makefile: change to using .carray.c for carray filesBen Dooks1-1/+1
We would like to clean any files generated by the carray scripts by just searching for the filename as the current make system turns f.carray into f.o. Change to make the make system turn f.carray into f.carray.o note, command to go through .mk files changing the .o in the .mk files is: find . -type f -name "*.carray" | xargs -t -I fname /bin/bash -x -c ' fn=`basename -s .carray fname`; echo "$fn"; sed -i `dirname fname `/objects.mk -e s/"$fn".o/"$fn".carray.o/g' Link: https://patchwork.ozlabs.org/project/opensbi/patch/20240401213438.590209-2-ivan.orlov0322@gmail.com/ Reported-by: Ivan Orlov <ivan.orlov0322@gmail.com> Suggested-by: Andrew Jones <ajones@ventanamicro.com> Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-05-23lib: utils/gpio: respect flag GPIO_FLAG_ACTIVE_LOWInochi Amaoto1-1/+13
"gpio-poweroff" and "gpio-restart" always set gpio to high to active the function, but some chips need a low signal to active. Fortunately, it can be achieved by setting GPIO_FLAG_ACTIVE_LOW for the gpio. Implement this flag support for the gpio library so the gpio reset can function well. Signed-off-by: Inochi Amaoto <inochiama@outlook.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2023-10-06gpio/starfive: redundant readl() callHeinrich Schuchardt1-1/+0
In starfive_gpio_direction_output() readl() is called twice to read the gpio direction register. The result of the first read is discarded. Remove the redundant read. Fixes: 908be1b85c8f ("gpio/starfive: add gpio driver and support gpio reset") Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2023-07-12lib: utils/gpio: Fix RV32 compile error for designware GPIO driverAnup Patel1-2/+2
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") Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Xiang W <wxjstz@126.com>
2023-07-07gpio/desginware: add Synopsys DesignWare APB GPIO supportBen Dooks3-0/+147
Add a driver for the Synopsys DesignWare APB GPIO IP block found in many SoCs. Signed-off-by: Ben Dooks <ben.dooks@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2023-06-05lib: utils/gpio: Use heap in SiFive and StartFive GPIO driversAnup Patel2-21/+20
Let's use heap allocation in SiFive and Starfive GPIO drivers instead of using a fixed size global array. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
2023-03-01gpio/starfive: add gpio driver and support gpio resetminda.chen3-0/+123
Add gpio driver and gpio reset function in Starfive JH7110 SOC platform. Signed-off-by: minda.chen <minda.chen@starfivetech.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2022-08-08lib: utils/fdt: Use kconfig for enabling/disablingAnup Patel1-0/+1
We update FDT support makefile to use kconfig for enabling/disabling. To avoid compilation errors, we also enable FDT for each platform. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Tested-by: Andrew Jones <ajones@ventanamicro.com> Acked-by: Atish Patra <atishp@rivosinc.com> Tested-by: Atish Patra <atishp@rivosinc.com>
2022-08-08lib: utils/gpio: Use kconfig for enabling/disabling driversAnup Patel2-5/+27
We update gpio drivers makefile to use kconfig for enabling/disabling drivers. To avoid compile errors, we also enable appropriate gpio drivers for each platform. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Tested-by: Andrew Jones <ajones@ventanamicro.com> Acked-by: Atish Patra <atishp@rivosinc.com> Tested-by: Atish Patra <atishp@rivosinc.com>
2022-05-13lib: utils/gpio: Generate FDT gpio driver list at compile-timeAnup Patel3-10/+15
Instead of having FDT gpio driver list hard-coded in the C source, we generate it using carray.sh at compile-time. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Atish Patra <atishp@rivosinc.com>
2021-11-03lib: utils/gpio: use list for driversNikita Shubin1-30/+12
Convert static array to sbi_list. This removes size limitation, makes add/remove more efficient and saves space. Signed-off-by: Nikita Shubin <n.shubin@yadro.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2021-08-14lib: utils: Extend fdt_get_node_addr_size() for multiple register setsAnup Patel1-1/+1
We add "index" parameter to fdt_get_node_addr_size() API so that calling function can specify index of desired register set. This will allow fdt_get_node_addr_size() to handle DT nodes with multiple register sets. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2021-08-07lib: utils/fdt: Change addr and size to uint64_tBin Meng1-1/+3
The maximum address and size encoded in DT are 64-bit numbers, so we should use uint64_t for 'addr' and 'size' in fdt_get_node_addr_size(). Signed-off-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2021-07-17lib: utils/gpio: Add minimal SiFive GPIO driverGreen Wan3-0/+109
We add a minimal SiFive GPIO driver so that we can do GPIO based system power-off and reset. Signed-off-by: Green Wan <green.wan@sifive.com> Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2021-07-17lib: utils/gpio: Add simple FDT based GPIO frameworkAnup Patel2-0/+133
We add a simple FDT based GPIO framework which is built on top of generic GPIO library. The phandle of FDT GPIO chip DT node is treated as unique GPIO chip ID required by the generic GPIO library. The FDT based GPIO chip drivers will be probed on-demand from fdt_gpio_pin_get() called by the GPIO client drivers. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2021-07-17lib: utils/gpio: Add generic GPIO configuration libraryAnup Patel2-0/+126
We add generic GPIO configuration library which is independent of hardware description format (FDT or ACPI). The OpenSBI platform support or GPIO drivers can register GPIO chip instances which can be discovered and used by different GPIO clients. Each GPIO chip instance has a unique ID which can be used by GPIO clients to lookup GPIO chip instance. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>