misc-uclass.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright (C) 2010 Thomas Chou <thomas@wytron.com.tw>
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <dm.h>
  8. #include <errno.h>
  9. #include <misc.h>
  10. /*
  11. * Implement a miscellaneous uclass for those do not fit other more
  12. * general classes. A set of generic read, write and ioctl methods may
  13. * be used to access the device.
  14. */
  15. int misc_read(struct udevice *dev, int offset, void *buf, int size)
  16. {
  17. const struct misc_ops *ops = device_get_ops(dev);
  18. if (!ops->read)
  19. return -ENOSYS;
  20. return ops->read(dev, offset, buf, size);
  21. }
  22. int misc_write(struct udevice *dev, int offset, void *buf, int size)
  23. {
  24. const struct misc_ops *ops = device_get_ops(dev);
  25. if (!ops->write)
  26. return -ENOSYS;
  27. return ops->write(dev, offset, buf, size);
  28. }
  29. int misc_ioctl(struct udevice *dev, unsigned long request, void *buf)
  30. {
  31. const struct misc_ops *ops = device_get_ops(dev);
  32. if (!ops->ioctl)
  33. return -ENOSYS;
  34. return ops->ioctl(dev, request, buf);
  35. }
  36. UCLASS_DRIVER(misc) = {
  37. .id = UCLASS_MISC,
  38. .name = "misc",
  39. };