misc-uclass.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2010 Thomas Chou <thomas@wytron.com.tw>
  4. */
  5. #define LOG_CATEGORY UCLASS_MISC
  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. int misc_set_enabled(struct udevice *dev, bool val)
  45. {
  46. const struct misc_ops *ops = device_get_ops(dev);
  47. if (!ops->set_enabled)
  48. return -ENOSYS;
  49. return ops->set_enabled(dev, val);
  50. }
  51. UCLASS_DRIVER(misc) = {
  52. .id = UCLASS_MISC,
  53. .name = "misc",
  54. #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
  55. .post_bind = dm_scan_fdt_dev,
  56. #endif
  57. };