diff mbox

[U-Boot,v2,04/33] dm: gpio: Add a function to read an ID from a list of GPIOs

Message ID 1415667650-14899-5-git-send-email-sjg@chromium.org
State Superseded
Delegated to: Simon Glass
Headers show

Commit Message

Simon Glass Nov. 11, 2014, 1 a.m. UTC
For board IDs a common approach is to set aside several GPIOs for use in
determining the board ID. This can provide information about board features
and the revision.

Add a function that turns a list of GPIOs into an integer by assigning
each GPIO to a single bit.

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

Changes in v2: None

 drivers/gpio/gpio-uclass.c | 19 +++++++++++++++++++
 include/asm-generic/gpio.h | 11 ++++++++++-
 2 files changed, 29 insertions(+), 1 deletion(-)

Comments

Simon Glass Nov. 13, 2014, 5:24 a.m. UTC | #1
On 10 November 2014 18:00, Simon Glass <sjg@chromium.org> wrote:
> For board IDs a common approach is to set aside several GPIOs for use in
> determining the board ID. This can provide information about board features
> and the revision.
>
> Add a function that turns a list of GPIOs into an integer by assigning
> each GPIO to a single bit.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
> Changes in v2: None
>
>  drivers/gpio/gpio-uclass.c | 19 +++++++++++++++++++
>  include/asm-generic/gpio.h | 11 ++++++++++-
>  2 files changed, 29 insertions(+), 1 deletion(-)

Applied to u-boot-x86.
diff mbox

Patch

diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c
index 45e9a5a..255700a 100644
--- a/drivers/gpio/gpio-uclass.c
+++ b/drivers/gpio/gpio-uclass.c
@@ -390,6 +390,25 @@  int gpio_get_status(struct udevice *dev, int offset, char *buf, int buffsize)
 	return 0;
 }
 
+/*
+ * get a number comprised of multiple GPIO values. gpio_num_array points to
+ * the array of gpio pin numbers to scan, terminated by -1.
+ */
+unsigned gpio_get_values_as_int(const int *gpio_num_array)
+{
+	int gpio;
+	unsigned bitmask = 1;
+	unsigned vector = 0;
+
+	while (bitmask &&
+	       ((gpio = *gpio_num_array++) != -1)) {
+		if (gpio_get_value(gpio))
+			vector |= bitmask;
+		bitmask <<= 1;
+	}
+	return vector;
+}
+
 /* We need to renumber the GPIOs when any driver is probed/removed */
 static int gpio_renumber(struct udevice *removed_dev)
 {
diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h
index f81b51a..36a36c6 100644
--- a/include/asm-generic/gpio.h
+++ b/include/asm-generic/gpio.h
@@ -257,6 +257,15 @@  const char *gpio_get_bank_info(struct udevice *dev, int *offset_count);
 int gpio_lookup_name(const char *name, struct udevice **devp,
 		     unsigned int *offsetp, unsigned int *gpiop);
 
-int name_to_gpio(const char *name);
+/**
+ * get_gpios() - Turn the values of a list of GPIOs into an integer
+ *
+ * This puts the value of the first GPIO into bit 0, the second into bit 1,
+ * etc. then returns the resulting integer.
+ *
+ * @gpio_list: List of GPIOs to collect
+ * @return resulting integer value
+ */
+unsigned gpio_get_values_as_int(const int *gpio_list);
 
 #endif	/* _ASM_GENERIC_GPIO_H_ */