blob: 4aecf7e2cef7a30d4db2cbe056d94240361f51b4 [file] [log] [blame]
Chris Packham0e316662019-01-10 21:01:00 +13001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2018 Allied Telesis Labs
4 */
5
6#include <common.h>
7#include <dm.h>
Simon Glass401d1c42020-10-30 21:38:53 -06008#include <asm/global_data.h>
Chris Packham0e316662019-01-10 21:01:00 +13009#include <asm/gpio.h>
10
11DECLARE_GLOBAL_DATA_PTR;
12
13int gpio_hog_list(struct gpio_desc *gpiod, int max_count,
14 const char *node_name, const char *gpio_name, int value)
15{
16 int node;
17 int count;
18 int i;
19
20 node = fdt_node_offset_by_compatible(gd->fdt_blob, 0, node_name);
21 if (node < 0)
22 return -ENODEV;
23
24 if (!dm_gpio_is_valid(gpiod)) {
25 count =
26 gpio_request_list_by_name_nodev(offset_to_ofnode(node),
27 gpio_name, gpiod, max_count,
28 GPIOD_IS_OUT);
29 if (count < 0)
30 return count;
31
32 for (i = 0; i < count; i++)
33 dm_gpio_set_value(&gpiod[i], value);
34 }
35
36 return 0;
37}