media-dev.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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/platform_device.h>
  12. #include <linux/mutex.h>
  13. #include <linux/of.h>
  14. #include <linux/pinctrl/consumer.h>
  15. #include <media/media-device.h>
  16. #include <media/media-entity.h>
  17. #include <media/v4l2-device.h>
  18. #include <media/v4l2-subdev.h>
  19. #include <media/s5p_fimc.h>
  20. #include "fimc-core.h"
  21. #include "fimc-lite.h"
  22. #include "mipi-csis.h"
  23. #define FIMC_OF_NODE_NAME "fimc"
  24. #define FIMC_LITE_OF_NODE_NAME "fimc-lite"
  25. #define FIMC_IS_OF_NODE_NAME "fimc-is"
  26. #define CSIS_OF_NODE_NAME "csis"
  27. #define PINCTRL_STATE_IDLE "idle"
  28. #define FIMC_MAX_SENSORS 8
  29. #define FIMC_MAX_CAMCLKS 2
  30. /* LCD/ISP Writeback clocks (PIXELASYNCMx) */
  31. enum {
  32. CLK_IDX_WB_A,
  33. CLK_IDX_WB_B,
  34. FIMC_MAX_WBCLKS
  35. };
  36. enum fimc_subdev_index {
  37. IDX_SENSOR,
  38. IDX_CSIS,
  39. IDX_FLITE,
  40. IDX_IS_ISP,
  41. IDX_FIMC,
  42. IDX_MAX,
  43. };
  44. /*
  45. * This structure represents a chain of media entities, including a data
  46. * source entity (e.g. an image sensor subdevice), a data capture entity
  47. * - a video capture device node and any remaining entities.
  48. */
  49. struct fimc_pipeline {
  50. struct exynos_media_pipeline ep;
  51. struct list_head list;
  52. struct media_entity *vdev_entity;
  53. struct v4l2_subdev *subdevs[IDX_MAX];
  54. };
  55. #define to_fimc_pipeline(_ep) container_of(_ep, struct fimc_pipeline, ep)
  56. struct fimc_csis_info {
  57. struct v4l2_subdev *sd;
  58. int id;
  59. };
  60. struct fimc_camclk_info {
  61. struct clk *clock;
  62. int use_count;
  63. unsigned long frequency;
  64. };
  65. /**
  66. * struct fimc_sensor_info - image data source subdev information
  67. * @pdata: sensor's atrributes passed as media device's platform data
  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_subdev *subdev;
  76. struct fimc_dev *host;
  77. };
  78. /**
  79. * struct fimc_md - fimc media device information
  80. * @csis: MIPI CSIS subdevs data
  81. * @sensor: array of registered sensor subdevs
  82. * @num_sensors: actual number of registered sensors
  83. * @camclk: external sensor clock information
  84. * @fimc: array of registered fimc devices
  85. * @fimc_is: fimc-is data structure
  86. * @use_isp: set to true when FIMC-IS subsystem is used
  87. * @pmf: handle to the CAMCLK clock control FIMC helper device
  88. * @media_dev: top level media device
  89. * @v4l2_dev: top level v4l2_device holding up the subdevs
  90. * @pdev: platform device this media device is hooked up into
  91. * @pinctrl: camera port pinctrl handle
  92. * @state_default: pinctrl default state handle
  93. * @state_idle: pinctrl idle state handle
  94. * @user_subdev_api: true if subdevs are not configured by the host driver
  95. * @slock: spinlock protecting @sensor array
  96. */
  97. struct fimc_md {
  98. struct fimc_csis_info csis[CSIS_MAX_ENTITIES];
  99. struct fimc_sensor_info sensor[FIMC_MAX_SENSORS];
  100. int num_sensors;
  101. struct fimc_camclk_info camclk[FIMC_MAX_CAMCLKS];
  102. struct clk *wbclk[FIMC_MAX_WBCLKS];
  103. struct fimc_lite *fimc_lite[FIMC_LITE_MAX_DEVS];
  104. struct fimc_dev *fimc[FIMC_MAX_DEVS];
  105. struct fimc_is *fimc_is;
  106. bool use_isp;
  107. struct device *pmf;
  108. struct media_device media_dev;
  109. struct v4l2_device v4l2_dev;
  110. struct platform_device *pdev;
  111. struct fimc_pinctrl {
  112. struct pinctrl *pinctrl;
  113. struct pinctrl_state *state_default;
  114. struct pinctrl_state *state_idle;
  115. } pinctl;
  116. bool user_subdev_api;
  117. spinlock_t slock;
  118. struct list_head pipelines;
  119. };
  120. static inline
  121. struct fimc_sensor_info *source_to_sensor_info(struct fimc_source_info *si)
  122. {
  123. return container_of(si, struct fimc_sensor_info, pdata);
  124. }
  125. static inline struct fimc_md *entity_to_fimc_mdev(struct media_entity *me)
  126. {
  127. return me->parent == NULL ? NULL :
  128. container_of(me->parent, struct fimc_md, media_dev);
  129. }
  130. static inline void fimc_md_graph_lock(struct exynos_video_entity *ve)
  131. {
  132. mutex_lock(&ve->vdev.entity.parent->graph_mutex);
  133. }
  134. static inline void fimc_md_graph_unlock(struct exynos_video_entity *ve)
  135. {
  136. mutex_unlock(&ve->vdev.entity.parent->graph_mutex);
  137. }
  138. int fimc_md_set_camclk(struct v4l2_subdev *sd, bool on);
  139. #ifdef CONFIG_OF
  140. static inline bool fimc_md_is_isp_available(struct device_node *node)
  141. {
  142. node = of_get_child_by_name(node, FIMC_IS_OF_NODE_NAME);
  143. return node ? of_device_is_available(node) : false;
  144. }
  145. #else
  146. #define fimc_md_is_isp_available(node) (false)
  147. #endif /* CONFIG_OF */
  148. static inline struct v4l2_subdev *__fimc_md_get_subdev(
  149. struct exynos_media_pipeline *ep,
  150. unsigned int index)
  151. {
  152. struct fimc_pipeline *p = to_fimc_pipeline(ep);
  153. if (!p || index >= IDX_MAX)
  154. return NULL;
  155. else
  156. return p->subdevs[index];
  157. }
  158. #endif