cam_subdev.h 4.9 KB

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