demo-uclass.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 <log.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. .name = "demo",
  20. .id = UCLASS_DEMO,
  21. };
  22. int demo_hello(struct udevice *dev, int ch)
  23. {
  24. const struct demo_ops *ops = device_get_ops(dev);
  25. if (!ops->hello)
  26. return -ENOSYS;
  27. return ops->hello(dev, ch);
  28. }
  29. int demo_status(struct udevice *dev, int *status)
  30. {
  31. const struct demo_ops *ops = device_get_ops(dev);
  32. if (!ops->status)
  33. return -ENOSYS;
  34. return ops->status(dev, status);
  35. }
  36. int demo_get_light(struct udevice *dev)
  37. {
  38. const struct demo_ops *ops = device_get_ops(dev);
  39. if (!ops->get_light)
  40. return -ENOSYS;
  41. return ops->get_light(dev);
  42. }
  43. int demo_set_light(struct udevice *dev, int light)
  44. {
  45. const struct demo_ops *ops = device_get_ops(dev);
  46. if (!ops->set_light)
  47. return -ENOSYS;
  48. return ops->set_light(dev, light);
  49. }
  50. int demo_parse_dt(struct udevice *dev)
  51. {
  52. struct dm_demo_pdata *pdata = dev_get_platdata(dev);
  53. int dn = dev_of_offset(dev);
  54. pdata->sides = fdtdec_get_int(gd->fdt_blob, dn, "sides", 0);
  55. pdata->colour = fdt_getprop(gd->fdt_blob, dn, "colour", NULL);
  56. if (!pdata->sides || !pdata->colour) {
  57. debug("%s: Invalid device tree data\n", __func__);
  58. return -EINVAL;
  59. }
  60. return 0;
  61. }