misc-uclass.c 1.3 KB

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