demo-uclass.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (c) 2013 Google, Inc
  4. *
  5. * (C) Copyright 2012
  6. * Pavel Herrmann <morpheus.ibis@gmail.com>
  7. */
  8. #include <common.h>
  9. #include <dm.h>
  10. #include <dm-demo.h>
  11. #include <errno.h>
  12. #include <fdtdec.h>
  13. #include <malloc.h>
  14. #include <asm/io.h>
  15. #include <linux/list.h>
  16. DECLARE_GLOBAL_DATA_PTR;
  17. UCLASS_DRIVER(demo) = {
  18. .name = "demo",
  19. .id = UCLASS_DEMO,
  20. };
  21. int demo_hello(struct udevice *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 udevice *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_get_light(struct udevice *dev)
  36. {
  37. const struct demo_ops *ops = device_get_ops(dev);
  38. if (!ops->get_light)
  39. return -ENOSYS;
  40. return ops->get_light(dev);
  41. }
  42. int demo_set_light(struct udevice *dev, int light)
  43. {
  44. const struct demo_ops *ops = device_get_ops(dev);
  45. if (!ops->set_light)
  46. return -ENOSYS;
  47. return ops->set_light(dev, light);
  48. }
  49. int demo_parse_dt(struct udevice *dev)
  50. {
  51. struct dm_demo_pdata *pdata = dev_get_platdata(dev);
  52. int dn = dev_of_offset(dev);
  53. pdata->sides = fdtdec_get_int(gd->fdt_blob, dn, "sides", 0);
  54. pdata->colour = fdt_getprop(gd->fdt_blob, dn, "colour", NULL);
  55. if (!pdata->sides || !pdata->colour) {
  56. debug("%s: Invalid device tree data\n", __func__);
  57. return -EINVAL;
  58. }
  59. return 0;
  60. }