misc-uclass.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. int misc_call(struct udevice *dev, int msgid, void *tx_msg, int tx_size,
  37. void *rx_msg, int rx_size)
  38. {
  39. const struct misc_ops *ops = device_get_ops(dev);
  40. if (!ops->call)
  41. return -ENOSYS;
  42. return ops->call(dev, msgid, tx_msg, tx_size, rx_msg, rx_size);
  43. }
  44. UCLASS_DRIVER(misc) = {
  45. .id = UCLASS_MISC,
  46. .name = "misc",
  47. };