xref: /openbmc/u-boot/board/gdsys/a38x/dt_helpers.c (revision ebce73f0)
1 /*
2  * (C) Copyright 2016
3  * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
4  *
5  * SPDX-License-Identifier:    GPL-2.0+
6  */
7 
8 #include <common.h>
9 #include <i2c.h>
10 #include <fdt_support.h>
11 #include <asm-generic/gpio.h>
12 #include <dm.h>
13 
14 int fdt_disable_by_ofname(void *rw_fdt_blob, char *ofname)
15 {
16 	int offset = fdt_path_offset(rw_fdt_blob, ofname);
17 
18 	return fdt_status_disabled(rw_fdt_blob, offset);
19 }
20 
21 bool dm_i2c_simple_probe(struct udevice *bus, uint chip_addr)
22 {
23 	struct udevice *dev;
24 
25 	return !dm_i2c_probe(bus, chip_addr, DM_I2C_CHIP_RD_ADDRESS |
26 			     DM_I2C_CHIP_WR_ADDRESS, &dev);
27 }
28 
29 int request_gpio_by_name(struct gpio_desc *gpio, const char *gpio_dev_name,
30 			 uint offset, char *gpio_name)
31 {
32 	struct udevice *gpio_dev = NULL;
33 
34 	if (uclass_get_device_by_name(UCLASS_GPIO, gpio_dev_name, &gpio_dev))
35 		return 1;
36 
37 	gpio->dev = gpio_dev;
38 	gpio->offset = offset;
39 	gpio->flags = 0;
40 
41 	return dm_gpio_request(gpio, gpio_name);
42 }
43 
44