media-dev.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd.
  4. */
  5. #ifndef FIMC_MDEVICE_H_
  6. #define FIMC_MDEVICE_H_
  7. #include <linux/clk.h>
  8. #include <linux/clk-provider.h>
  9. #include <linux/platform_device.h>
  10. #include <linux/mutex.h>
  11. #include <linux/of.h>
  12. #include <linux/pinctrl/consumer.h>
  13. #include <media/media-device.h>
  14. #include <media/media-entity.h>
  15. #include <media/v4l2-device.h>
  16. #include <media/v4l2-subdev.h>
  17. #include <media/drv-intf/exynos-fimc.h>
  18. #include "fimc-core.h"
  19. #include "fimc-lite.h"
  20. #include "mipi-csis.h"
  21. #define FIMC_OF_NODE_NAME "fimc"
  22. #define FIMC_LITE_OF_NODE_NAME "fimc-lite"
  23. #define FIMC_IS_OF_NODE_NAME "fimc-is"
  24. #define CSIS_OF_NODE_NAME "csis"
  25. #define PINCTRL_STATE_IDLE "idle"
  26. #define FIMC_MAX_SENSORS 4
  27. #define FIMC_MAX_CAMCLKS 2
  28. #define DEFAULT_SENSOR_CLK_FREQ 24000000U
  29. /* LCD/ISP Writeback clocks (PIXELASYNCMx) */
  30. enum {
  31. CLK_IDX_WB_A,
  32. CLK_IDX_WB_B,
  33. FIMC_MAX_WBCLKS
  34. };
  35. enum fimc_subdev_index {
  36. IDX_SENSOR,
  37. IDX_CSIS,
  38. IDX_FLITE,
  39. IDX_IS_ISP,
  40. IDX_FIMC,
  41. IDX_MAX,
  42. };
  43. /*
  44. * This structure represents a chain of media entities, including a data
  45. * source entity (e.g. an image sensor subdevice), a data capture entity
  46. * - a video capture device node and any remaining entities.
  47. */
  48. struct fimc_pipeline {
  49. struct exynos_media_pipeline ep;
  50. struct list_head list;
  51. struct media_entity *vdev_entity;
  52. struct v4l2_subdev *subdevs[IDX_MAX];
  53. };
  54. #define to_fimc_pipeline(_ep) container_of(_ep, struct fimc_pipeline, ep)
  55. struct fimc_csis_info {
  56. struct v4l2_subdev *sd;
  57. int id;
  58. };
  59. struct fimc_camclk_info {
  60. struct clk *clock;
  61. int use_count;
  62. unsigned long frequency;
  63. };
  64. /**
  65. * struct fimc_sensor_info - image data source subdev information
  66. * @pdata: sensor's attributes passed as media device's platform data
  67. * @asd: asynchronous subdev registration data structure
  68. * @subdev: image sensor v4l2 subdev
  69. * @host: fimc device the sensor is currently linked to
  70. *
  71. * This data structure applies to image sensor and the writeback subdevs.
  72. */
  73. struct fimc_sensor_info {
  74. struct fimc_source_info pdata;
  75. struct v4l2_async_subdev asd;
  76. struct v4l2_subdev *subdev;
  77. struct fimc_dev *host;
  78. };
  79. struct cam_clk {
  80. struct clk_hw hw;
  81. struct fimc_md *fmd;
  82. };
  83. #define to_cam_clk(_hw) container_of(_hw, struct cam_clk, hw)
  84. /**
  85. * struct fimc_md - fimc media device information
  86. * @csis: MIPI CSIS subdevs data
  87. * @sensor: array of registered sensor subdevs
  88. * @num_sensors: actual number of registered sensors
  89. * @camclk: external sensor clock information
  90. * @fimc: array of registered fimc devices
  91. * @fimc_is: fimc-is data structure
  92. * @use_isp: set to true when FIMC-IS subsystem is used
  93. * @pmf: handle to the CAMCLK clock control FIMC helper device
  94. * @media_dev: top level media device
  95. * @v4l2_dev: top level v4l2_device holding up the subdevs
  96. * @pdev: platform device this media device is hooked up into
  97. * @pinctrl: camera port pinctrl handle
  98. * @state_default: pinctrl default state handle
  99. * @state_idle: pinctrl idle state handle
  100. * @cam_clk_provider: CAMCLK clock provider structure
  101. * @user_subdev_api: true if subdevs are not configured by the host driver
  102. * @slock: spinlock protecting @sensor array
  103. */
  104. struct fimc_md {
  105. struct fimc_csis_info csis[CSIS_MAX_ENTITIES];
  106. struct fimc_sensor_info sensor[FIMC_MAX_SENSORS];
  107. int num_sensors;
  108. struct fimc_camclk_info camclk[FIMC_MAX_CAMCLKS];
  109. struct clk *wbclk[FIMC_MAX_WBCLKS];
  110. struct fimc_lite *fimc_lite[FIMC_LITE_MAX_DEVS];
  111. struct fimc_dev *fimc[FIMC_MAX_DEVS];
  112. struct fimc_is *fimc_is;
  113. bool use_isp;
  114. struct device *pmf;
  115. struct media_device media_dev;
  116. struct v4l2_device v4l2_dev;
  117. struct platform_device *pdev;
  118. struct fimc_pinctrl {
  119. struct pinctrl *pinctrl;
  120. struct pinctrl_state *state_default;
  121. struct pinctrl_state *state_idle;
  122. } pinctl;
  123. struct cam_clk_provider {
  124. struct clk *clks[FIMC_MAX_CAMCLKS];
  125. struct clk_onecell_data clk_data;
  126. struct device_node *of_node;
  127. struct cam_clk camclk[FIMC_MAX_CAMCLKS];
  128. int num_clocks;
  129. } clk_provider;
  130. struct v4l2_async_notifier subdev_notifier;
  131. bool user_subdev_api;
  132. spinlock_t slock;
  133. struct list_head pipelines;
  134. struct media_graph link_setup_graph;
  135. };
  136. static inline
  137. struct fimc_sensor_info *source_to_sensor_info(struct fimc_source_info *si)
  138. {
  139. return container_of(si, struct fimc_sensor_info, pdata);
  140. }
  141. static inline struct fimc_md *entity_to_fimc_mdev(struct media_entity *me)
  142. {
  143. return me->graph_obj.mdev == NULL ? NULL :
  144. container_of(me->graph_obj.mdev, struct fimc_md, media_dev);
  145. }
  146. static inline struct fimc_md *notifier_to_fimc_md(struct v4l2_async_notifier *n)
  147. {
  148. return container_of(n, struct fimc_md, subdev_notifier);
  149. }
  150. static inline void fimc_md_graph_lock(struct exynos_video_entity *ve)
  151. {
  152. mutex_lock(&ve->vdev.entity.graph_obj.mdev->graph_mutex);
  153. }
  154. static inline void fimc_md_graph_unlock(struct exynos_video_entity *ve)
  155. {
  156. mutex_unlock(&ve->vdev.entity.graph_obj.mdev->graph_mutex);
  157. }
  158. int fimc_md_set_camclk(struct v4l2_subdev *sd, bool on);
  159. #ifdef CONFIG_OF
  160. static inline bool fimc_md_is_isp_available(struct device_node *node)
  161. {
  162. node = of_get_child_by_name(node, FIMC_IS_OF_NODE_NAME);
  163. return node ? of_device_is_available(node) : false;
  164. }
  165. #else
  166. #define fimc_md_is_isp_available(node) (false)
  167. #endif /* CONFIG_OF */
  168. static inline struct v4l2_subdev *__fimc_md_get_subdev(
  169. struct exynos_media_pipeline *ep,
  170. unsigned int index)
  171. {
  172. struct fimc_pipeline *p = to_fimc_pipeline(ep);
  173. if (!p || index >= IDX_MAX)
  174. return NULL;
  175. else
  176. return p->subdevs[index];
  177. }
  178. #endif