From 538331371777deebe2eda442996ed4889696c252 Mon Sep 17 00:00:00 2001 From: Mark Kettenis Date: Wed, 27 Jul 2016 21:13:50 +0000 Subject: Add interface to facilitate iterating over gpios. ok patrick@ --- sys/dev/ofw/ofw_gpio.c | 15 ++++++++++++++- sys/dev/ofw/ofw_gpio.h | 3 ++- 2 files changed, 16 insertions(+), 2 deletions(-) (limited to 'sys/dev') diff --git a/sys/dev/ofw/ofw_gpio.c b/sys/dev/ofw/ofw_gpio.c index 668210ae955..5f814ac7322 100644 --- a/sys/dev/ofw/ofw_gpio.c +++ b/sys/dev/ofw/ofw_gpio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ofw_gpio.c,v 1.1 2016/07/11 14:49:41 kettenis Exp $ */ +/* $OpenBSD: ofw_gpio.c,v 1.2 2016/07/27 21:13:49 kettenis Exp $ */ /* * Copyright (c) 2016 Mark Kettenis * @@ -82,3 +82,16 @@ gpio_controller_set_pin(uint32_t *cells, int val) if (gc && gc->gc_set_pin) gc->gc_set_pin(gc->gc_cookie, &cells[1], val); } + +uint32_t * +gpio_controller_next_pin(uint32_t *cells) +{ + struct gpio_controller *gc; + uint32_t phandle = cells[0]; + + LIST_FOREACH(gc, &gpio_controllers, gc_list) + if (gc->gc_phandle == phandle) + return cells + gc->gc_cells + 1; + + return NULL; +} diff --git a/sys/dev/ofw/ofw_gpio.h b/sys/dev/ofw/ofw_gpio.h index 52f00b0f530..52b2fe08453 100644 --- a/sys/dev/ofw/ofw_gpio.h +++ b/sys/dev/ofw/ofw_gpio.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ofw_gpio.h,v 1.1 2016/07/11 14:49:41 kettenis Exp $ */ +/* $OpenBSD: ofw_gpio.h,v 1.2 2016/07/27 21:13:49 kettenis Exp $ */ /* * Copyright (c) 2016 Mark Kettenis * @@ -41,5 +41,6 @@ void gpio_controller_config_pin(uint32_t *, int); int gpio_controller_get_pin(uint32_t *); void gpio_controller_set_pin(uint32_t *, int); +uint32_t *gpio_controller_next_pin(uint32_t *); #endif /* _DEV_OFW_GPIO_H_ */ -- cgit v1.2.3