demo-uclass.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright (c) 2013 Google, Inc
  3. *
  4. * (C) Copyright 2012
  5. * Pavel Herrmann <morpheus.ibis@gmail.com>
  6. *
  7. * SPDX-License-Identifier: GPL-2.0+
  8. */
  9. #include <common.h>
  10. #include <dm.h>
  11. #include <dm-demo.h>
  12. #include <errno.h>
  13. #include <fdtdec.h>
  14. #include <malloc.h>
  15. #include <asm/io.h>
  16. #include <linux/list.h>
  17. DECLARE_GLOBAL_DATA_PTR;
  18. UCLASS_DRIVER(demo) = {
  19. .id = UCLASS_DEMO,
  20. };
  21. int demo_hello(struct device *dev, int ch)
  22. {
  23. const struct demo_ops *ops = device_get_ops(dev);
  24. if (!ops->hello)
  25. return -ENOSYS;
  26. return ops->hello(dev, ch);
  27. }
  28. int demo_status(struct device *dev, int *status)
  29. {
  30. const struct demo_ops *ops = device_get_ops(dev);
  31. if (!ops->status)
  32. return -ENOSYS;
  33. return ops->status(dev, status);
  34. }
  35. int demo_parse_dt(struct device *dev)
  36. {
  37. struct dm_demo_pdata *pdata = dev_get_platdata(dev);
  38. int dn = dev->of_offset;
  39. pdata->sides = fdtdec_get_int(gd->fdt_blob, dn, "sides", 0);
  40. pdata->colour = fdt_getprop(gd->fdt_blob, dn, "colour", NULL);
  41. if (!pdata->sides || !pdata->colour) {
  42. debug("%s: Invalid device tree data\n", __func__);
  43. return -EINVAL;
  44. }
  45. return 0;
  46. }