demo-uclass.c 1.5 KB

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