cam_subdev.h 4.4 KB

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