cam_subdev.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022-2023 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. CAM_SUBDEV_MESSAGE_CLOCK_UPDATE
  77. };
  78. /* Enum for close sequence priority */
  79. enum cam_subdev_close_seq_priority {
  80. CAM_SD_CLOSE_HIGH_PRIORITY,
  81. CAM_SD_CLOSE_MEDIUM_PRIORITY,
  82. CAM_SD_CLOSE_MEDIUM_LOW_PRIORITY,
  83. CAM_SD_CLOSE_LOW_PRIORITY
  84. };
  85. enum cam_subdev_rwsem {
  86. CAM_SUBDEV_LOCK = 1,
  87. CAM_SUBDEV_UNLOCK,
  88. };
  89. /**
  90. * struct cam_subdev - describes a camera sub-device
  91. *
  92. * @pdev: Pointer to the platform device
  93. * @sd: V4l2 subdevice
  94. * @ops: V4l2 subdecie operations
  95. * @internal_ops: V4l2 subdevice internal operations
  96. * @name: Name of the sub-device. Please notice that the name
  97. * must be unique.
  98. * @sd_flags: Subdev flags. Can be:
  99. * %V4L2_SUBDEV_FL_HAS_DEVNODE - Set this flag if
  100. * this subdev needs a device node.
  101. * %V4L2_SUBDEV_FL_HAS_EVENTS - Set this flag if
  102. * this subdev generates events.
  103. * @token: Pointer to cookie of the client driver
  104. * @ent_function: Media entity function type. Can be:
  105. * %CAM_IFE_DEVICE_TYPE - identifies as IFE device.
  106. * %CAM_ICP_DEVICE_TYPE - identifies as ICP device.
  107. * @list: list pointer
  108. * @close_seq_prior: cam_subdev_close_seq_priority type
  109. *
  110. * Each instance of a subdev driver should create this struct, either
  111. * stand-alone or embedded in a larger struct. This structure should be
  112. * initialized/registered by cam_register_subdev
  113. *
  114. */
  115. struct cam_subdev {
  116. struct platform_device *pdev;
  117. struct v4l2_subdev sd;
  118. const struct v4l2_subdev_ops *ops;
  119. const struct v4l2_subdev_internal_ops *internal_ops;
  120. char *name;
  121. u32 sd_flags;
  122. void *token;
  123. u32 ent_function;
  124. void (*msg_cb)(
  125. struct v4l2_subdev *sd,
  126. enum cam_subdev_message_type_t msg_type,
  127. void *data);
  128. struct list_head list;
  129. enum cam_subdev_close_seq_priority close_seq_prior;
  130. };
  131. /**
  132. * cam_subdev_notify_message()
  133. *
  134. * @brief: Notify message to a subdevs of specific type
  135. *
  136. * @subdev_type: Subdev type
  137. * @message_type: message type
  138. * @data: data to be delivered.
  139. *
  140. */
  141. void cam_subdev_notify_message(u32 subdev_type,
  142. enum cam_subdev_message_type_t message_type,
  143. void *data);
  144. /**
  145. * cam_subdev_probe()
  146. *
  147. * @brief: Camera Subdevice node probe function for v4l2 setup
  148. *
  149. * @sd: Camera subdevice object
  150. * @name: Name of the subdevice node
  151. * @dev_type: Subdevice node type
  152. *
  153. */
  154. int cam_subdev_probe(struct cam_subdev *sd, struct platform_device *pdev,
  155. char *name, uint32_t dev_type);
  156. /**
  157. * cam_subdev_remove()
  158. *
  159. * @brief: Called when subdevice node is unloaded
  160. *
  161. * @sd: Camera subdevice node object
  162. *
  163. */
  164. int cam_subdev_remove(struct cam_subdev *sd);
  165. /**
  166. * cam_register_subdev()
  167. *
  168. * @brief: This is the common utility function to be called by each camera
  169. * subdevice node when it tries to register itself to the camera
  170. * request manager
  171. *
  172. * @sd: Pointer to struct cam_subdev.
  173. */
  174. int cam_register_subdev(struct cam_subdev *sd);
  175. /**
  176. * cam_unregister_subdev()
  177. *
  178. * @brief: This is the common utility function to be called by each camera
  179. * subdevice node when it tries to unregister itself from the
  180. * camera request manger
  181. *
  182. * @sd: Pointer to struct cam_subdev.
  183. */
  184. int cam_unregister_subdev(struct cam_subdev *sd);
  185. /**
  186. * cam_req_mgr_rwsem_read_op()
  187. *
  188. * @brief : API to acquire read semaphore lock to platform framework.
  189. *
  190. * @lock : value indicates to lock or unlock the read lock
  191. */
  192. void cam_req_mgr_rwsem_read_op(enum cam_subdev_rwsem lock);
  193. /**
  194. * cam_req_mgr_is_open()
  195. *
  196. * @brief: This common utility function returns the crm active status
  197. *
  198. */
  199. bool cam_req_mgr_is_open(void);
  200. /**
  201. * cam_req_mgr_is_shutdown()
  202. *
  203. * @brief: This common utility function returns the shutdown state
  204. */
  205. bool cam_req_mgr_is_shutdown(void);
  206. #endif /* _CAM_SUBDEV_H_ */