cam_subdev.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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 for indicating CSID event */
  17. enum cam_subdev_phy_csid_state {
  18. CAM_SUBDEV_PHY_CSID_HALT = 1,
  19. CAM_SUBDEV_PHY_CSID_RESUME,
  20. };
  21. /**
  22. * struct cam_subdev_msg_phy_conn_csid_info: Contains phy num and connected CSID info
  23. *
  24. * @phy_idx: Phy idx value indicating which phy is connected to csid core
  25. * @lane_cfg: This value is similar to lane_assign in the PHY
  26. * driver, and is used to identify the particular
  27. * PHY instance with which this IFE session is
  28. * connected to.
  29. * @core_idx: Primary(in case of dual ife) core idx for the csid to which the phy
  30. * is connected, -1 while disconnecting
  31. */
  32. struct cam_subdev_msg_phy_conn_csid_info {
  33. uint32_t phy_idx;
  34. uint32_t lane_cfg;
  35. int32_t core_idx;
  36. };
  37. /**
  38. * struct cam_subdev_msg_phy_drv_info: Contains drv config info
  39. *
  40. * @phy_idx: Phy idx value indicating which phy is connected to csid core
  41. * @lane_cfg: This value is similar to lane_assign in the PHY
  42. * driver, and is used to identify the particular
  43. * PHY instance with which this IFE session is
  44. * connected to.
  45. * @use_hw_client_voting: Whether to use hw client voting for csiphy clk
  46. * @is_drv_config_en: If DRV config is enabled in CSID
  47. */
  48. struct cam_subdev_msg_phy_drv_info {
  49. uint32_t phy_idx;
  50. uint32_t lane_cfg;
  51. bool use_hw_client_voting;
  52. bool is_drv_config_en;
  53. };
  54. /**
  55. * struct cam_subdev_msg_phy_halt_resume_info: Contains csid halt resume info
  56. *
  57. * @phy_idx: Phy idx value indicating which phy is connected to csid core
  58. * @lane_cfg: This value is similar to lane_assign in the PHY
  59. * driver, and is used to identify the particular
  60. * PHY instance with which this IFE session is
  61. * connected to.
  62. * @csid_state: Notification of CSID state
  63. */
  64. struct cam_subdev_msg_phy_halt_resume_info {
  65. uint32_t phy_idx;
  66. uint32_t lane_cfg;
  67. enum cam_subdev_phy_csid_state csid_state;
  68. };
  69. enum cam_subdev_message_type_t {
  70. CAM_SUBDEV_MESSAGE_REG_DUMP = 0x1,
  71. CAM_SUBDEV_MESSAGE_APPLY_CSIPHY_AUX,
  72. CAM_SUBDEV_MESSAGE_DOMAIN_ID_SECURE_PARAMS,
  73. CAM_SUBDEV_MESSAGE_CONN_CSID_INFO,
  74. CAM_SUBDEV_MESSAGE_DRV_INFO,
  75. CAM_SUBDEV_MESSAGE_NOTIFY_HALT_RESUME,
  76. };
  77. /* Enum for close sequence priority */
  78. enum cam_subdev_close_seq_priority {
  79. CAM_SD_CLOSE_HIGH_PRIORITY,
  80. CAM_SD_CLOSE_MEDIUM_PRIORITY,
  81. CAM_SD_CLOSE_MEDIUM_LOW_PRIORITY,
  82. CAM_SD_CLOSE_LOW_PRIORITY
  83. };
  84. enum cam_subdev_rwsem {
  85. CAM_SUBDEV_LOCK = 1,
  86. CAM_SUBDEV_UNLOCK,
  87. };
  88. /**
  89. * struct cam_subdev - describes a camera sub-device
  90. *
  91. * @pdev: Pointer to the platform device
  92. * @sd: V4l2 subdevice
  93. * @ops: V4l2 subdecie operations
  94. * @internal_ops: V4l2 subdevice internal operations
  95. * @name: Name of the sub-device. Please notice that the name
  96. * must be unique.
  97. * @sd_flags: Subdev flags. Can be:
  98. * %V4L2_SUBDEV_FL_HAS_DEVNODE - Set this flag if
  99. * this subdev needs a device node.
  100. * %V4L2_SUBDEV_FL_HAS_EVENTS - Set this flag if
  101. * this subdev generates events.
  102. * @token: Pointer to cookie of the client driver
  103. * @ent_function: Media entity function type. Can be:
  104. * %CAM_IFE_DEVICE_TYPE - identifies as IFE device.
  105. * %CAM_ICP_DEVICE_TYPE - identifies as ICP device.
  106. * @list: list pointer
  107. * @close_seq_prior: cam_subdev_close_seq_priority type
  108. *
  109. * Each instance of a subdev driver should create this struct, either
  110. * stand-alone or embedded in a larger struct. This structure should be
  111. * initialized/registered by cam_register_subdev
  112. *
  113. */
  114. struct cam_subdev {
  115. struct platform_device *pdev;
  116. struct v4l2_subdev sd;
  117. const struct v4l2_subdev_ops *ops;
  118. const struct v4l2_subdev_internal_ops *internal_ops;
  119. char *name;
  120. u32 sd_flags;
  121. void *token;
  122. u32 ent_function;
  123. void (*msg_cb)(
  124. struct v4l2_subdev *sd,
  125. enum cam_subdev_message_type_t msg_type,
  126. void *data);
  127. struct list_head list;
  128. enum cam_subdev_close_seq_priority close_seq_prior;
  129. };
  130. /**
  131. * cam_subdev_notify_message()
  132. *
  133. * @brief: Notify message to a subdevs of specific type
  134. *
  135. * @subdev_type: Subdev type
  136. * @message_type: message type
  137. * @data: data to be delivered.
  138. *
  139. */
  140. void cam_subdev_notify_message(u32 subdev_type,
  141. enum cam_subdev_message_type_t message_type,
  142. void *data);
  143. /**
  144. * cam_subdev_probe()
  145. *
  146. * @brief: Camera Subdevice node probe function for v4l2 setup
  147. *
  148. * @sd: Camera subdevice object
  149. * @name: Name of the subdevice node
  150. * @dev_type: Subdevice node type
  151. *
  152. */
  153. int cam_subdev_probe(struct cam_subdev *sd, struct platform_device *pdev,
  154. char *name, uint32_t dev_type);
  155. /**
  156. * cam_subdev_remove()
  157. *
  158. * @brief: Called when subdevice node is unloaded
  159. *
  160. * @sd: Camera subdevice node object
  161. *
  162. */
  163. int cam_subdev_remove(struct cam_subdev *sd);
  164. /**
  165. * cam_register_subdev()
  166. *
  167. * @brief: This is the common utility function to be called by each camera
  168. * subdevice node when it tries to register itself to the camera
  169. * request manager
  170. *
  171. * @sd: Pointer to struct cam_subdev.
  172. */
  173. int cam_register_subdev(struct cam_subdev *sd);
  174. /**
  175. * cam_unregister_subdev()
  176. *
  177. * @brief: This is the common utility function to be called by each camera
  178. * subdevice node when it tries to unregister itself from the
  179. * camera request manger
  180. *
  181. * @sd: Pointer to struct cam_subdev.
  182. */
  183. int cam_unregister_subdev(struct cam_subdev *sd);
  184. /**
  185. * cam_req_mgr_rwsem_read_op()
  186. *
  187. * @brief : API to acquire read semaphore lock to platform framework.
  188. *
  189. * @lock : value indicates to lock or unlock the read lock
  190. */
  191. void cam_req_mgr_rwsem_read_op(enum cam_subdev_rwsem lock);
  192. /**
  193. * cam_req_mgr_is_open()
  194. *
  195. * @brief: This common utility function returns the crm active status
  196. *
  197. */
  198. bool cam_req_mgr_is_open(void);
  199. /**
  200. * cam_req_mgr_is_shutdown()
  201. *
  202. * @brief: This common utility function returns the shutdown state
  203. */
  204. bool cam_req_mgr_is_shutdown(void);
  205. #endif /* _CAM_SUBDEV_H_ */