misc-uclass.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. int misc_set_enabled(struct udevice *dev, bool val)
  44. {
  45. const struct misc_ops *ops = device_get_ops(dev);
  46. if (!ops->set_enabled)
  47. return -ENOSYS;
  48. return ops->set_enabled(dev, val);
  49. }
  50. UCLASS_DRIVER(misc) = {
  51. .id = UCLASS_MISC,
  52. .name = "misc",
  53. #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
  54. .post_bind = dm_scan_fdt_dev,
  55. #endif
  56. };