cam_subdev.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef _CAM_SUBDEV_H_
  6. #define _CAM_SUBDEV_H_
  7. #include <linux/types.h>
  8. #include <linux/platform_device.h>
  9. #include <media/v4l2-fh.h>
  10. #include <media/v4l2-device.h>
  11. #include <media/v4l2-subdev.h>
  12. #include <media/v4l2-event.h>
  13. #include <media/v4l2-ioctl.h>
  14. #define CAM_SUBDEVICE_EVENT_MAX 30
  15. enum cam_subdev_message_type_t {
  16. CAM_SUBDEV_MESSAGE_IRQ_ERR = 0x1
  17. };
  18. /* Enum for close sequence priority */
  19. enum cam_subdev_close_seq_priority {
  20. CAM_SD_CLOSE_HIGH_PRIORITY,
  21. CAM_SD_CLOSE_MEDIUM_PRIORITY,
  22. CAM_SD_CLOSE_MEDIUM_LOW_PRIORITY,
  23. CAM_SD_CLOSE_LOW_PRIORITY
  24. };
  25. /**
  26. * struct cam_subdev - describes a camera sub-device
  27. *
  28. * @pdev: Pointer to the platform device
  29. * @sd: V4l2 subdevice
  30. * @ops: V4l2 subdecie operations
  31. * @internal_ops: V4l2 subdevice internal operations
  32. * @name: Name of the sub-device. Please notice that the name
  33. * must be unique.
  34. * @sd_flags: Subdev flags. Can be:
  35. * %V4L2_SUBDEV_FL_HAS_DEVNODE - Set this flag if
  36. * this subdev needs a device node.
  37. * %V4L2_SUBDEV_FL_HAS_EVENTS - Set this flag if
  38. * this subdev generates events.
  39. * @token: Pointer to cookie of the client driver
  40. * @ent_function: Media entity function type. Can be:
  41. * %CAM_IFE_DEVICE_TYPE - identifies as IFE device.
  42. * %CAM_ICP_DEVICE_TYPE - identifies as ICP device.
  43. * @list: list pointer
  44. * @close_seq_prior: cam_subdev_close_seq_priority type
  45. *
  46. * Each instance of a subdev driver should create this struct, either
  47. * stand-alone or embedded in a larger struct. This structure should be
  48. * initialized/registered by cam_register_subdev
  49. *
  50. */
  51. struct cam_subdev {
  52. struct platform_device *pdev;
  53. struct v4l2_subdev sd;
  54. const struct v4l2_subdev_ops *ops;
  55. const struct v4l2_subdev_internal_ops *internal_ops;
  56. char *name;
  57. u32 sd_flags;
  58. void *token;
  59. u32 ent_function;
  60. void (*msg_cb)(
  61. struct v4l2_subdev *sd,
  62. enum cam_subdev_message_type_t msg_type,
  63. void *data);
  64. struct list_head list;
  65. enum cam_subdev_close_seq_priority close_seq_prior;
  66. };
  67. /**
  68. * cam_subdev_notify_message()
  69. *
  70. * @brief: Notify message to a subdevs of specific type
  71. *
  72. * @subdev_type: Subdev type
  73. * @message_type: message type
  74. * @data: data to be delivered.
  75. *
  76. */
  77. void cam_subdev_notify_message(u32 subdev_type,
  78. enum cam_subdev_message_type_t message_type,
  79. void *data);
  80. /**
  81. * cam_subdev_probe()
  82. *
  83. * @brief: Camera Subdevice node probe function for v4l2 setup
  84. *
  85. * @sd: Camera subdevice object
  86. * @name: Name of the subdevice node
  87. * @dev_type: Subdevice node type
  88. *
  89. */
  90. int cam_subdev_probe(struct cam_subdev *sd, struct platform_device *pdev,
  91. char *name, uint32_t dev_type);
  92. /**
  93. * cam_subdev_remove()
  94. *
  95. * @brief: Called when subdevice node is unloaded
  96. *
  97. * @sd: Camera subdevice node object
  98. *
  99. */
  100. int cam_subdev_remove(struct cam_subdev *sd);
  101. /**
  102. * cam_register_subdev()
  103. *
  104. * @brief: This is the common utility function to be called by each camera
  105. * subdevice node when it tries to register itself to the camera
  106. * request manager
  107. *
  108. * @sd: Pointer to struct cam_subdev.
  109. */
  110. int cam_register_subdev(struct cam_subdev *sd);
  111. /**
  112. * cam_unregister_subdev()
  113. *
  114. * @brief: This is the common utility function to be called by each camera
  115. * subdevice node when it tries to unregister itself from the
  116. * camera request manger
  117. *
  118. * @sd: Pointer to struct cam_subdev.
  119. */
  120. int cam_unregister_subdev(struct cam_subdev *sd);
  121. /**
  122. * cam_req_mgr_is_open()
  123. *
  124. * @brief: This common utility function returns the crm active status
  125. *
  126. */
  127. bool cam_req_mgr_is_open(void);
  128. /**
  129. * cam_req_mgr_is_shutdown()
  130. *
  131. * @brief: This common utility function returns the shutdown state
  132. */
  133. bool cam_req_mgr_is_shutdown(void);
  134. #endif /* _CAM_SUBDEV_H_ */