dt_helpers.c 936 B

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