cam_subdev.h 4.9 KB

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