media-dev.h 5.5 KB

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