media-dev.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 "fimc-core.h"
  20. #include "fimc-lite.h"
  21. #include "mipi-csis.h"
  22. #define FIMC_OF_NODE_NAME "fimc"
  23. #define FIMC_LITE_OF_NODE_NAME "fimc-lite"
  24. #define FIMC_IS_OF_NODE_NAME "fimc-is"
  25. #define CSIS_OF_NODE_NAME "csis"
  26. #define PINCTRL_STATE_IDLE "idle"
  27. #define FIMC_MAX_SENSORS 8
  28. #define FIMC_MAX_CAMCLKS 2
  29. /* LCD/ISP Writeback clocks (PIXELASYNCMx) */
  30. enum {
  31. CLK_IDX_WB_A,
  32. CLK_IDX_WB_B,
  33. FIMC_MAX_WBCLKS
  34. };
  35. struct fimc_csis_info {
  36. struct v4l2_subdev *sd;
  37. int id;
  38. };
  39. struct fimc_camclk_info {
  40. struct clk *clock;
  41. int use_count;
  42. unsigned long frequency;
  43. };
  44. /**
  45. * struct fimc_sensor_info - image data source subdev information
  46. * @pdata: sensor's atrributes passed as media device's platform data
  47. * @subdev: image sensor v4l2 subdev
  48. * @host: fimc device the sensor is currently linked to
  49. *
  50. * This data structure applies to image sensor and the writeback subdevs.
  51. */
  52. struct fimc_sensor_info {
  53. struct fimc_source_info pdata;
  54. struct v4l2_subdev *subdev;
  55. struct fimc_dev *host;
  56. };
  57. /**
  58. * struct fimc_md - fimc media device information
  59. * @csis: MIPI CSIS subdevs data
  60. * @sensor: array of registered sensor subdevs
  61. * @num_sensors: actual number of registered sensors
  62. * @camclk: external sensor clock information
  63. * @fimc: array of registered fimc devices
  64. * @fimc_is: fimc-is data structure
  65. * @use_isp: set to true when FIMC-IS subsystem is used
  66. * @pmf: handle to the CAMCLK clock control FIMC helper device
  67. * @media_dev: top level media device
  68. * @v4l2_dev: top level v4l2_device holding up the subdevs
  69. * @pdev: platform device this media device is hooked up into
  70. * @pinctrl: camera port pinctrl handle
  71. * @state_default: pinctrl default state handle
  72. * @state_idle: pinctrl idle state handle
  73. * @user_subdev_api: true if subdevs are not configured by the host driver
  74. * @slock: spinlock protecting @sensor array
  75. */
  76. struct fimc_md {
  77. struct fimc_csis_info csis[CSIS_MAX_ENTITIES];
  78. struct fimc_sensor_info sensor[FIMC_MAX_SENSORS];
  79. int num_sensors;
  80. struct fimc_camclk_info camclk[FIMC_MAX_CAMCLKS];
  81. struct clk *wbclk[FIMC_MAX_WBCLKS];
  82. struct fimc_lite *fimc_lite[FIMC_LITE_MAX_DEVS];
  83. struct fimc_dev *fimc[FIMC_MAX_DEVS];
  84. struct fimc_is *fimc_is;
  85. bool use_isp;
  86. struct device *pmf;
  87. struct media_device media_dev;
  88. struct v4l2_device v4l2_dev;
  89. struct platform_device *pdev;
  90. struct fimc_pinctrl {
  91. struct pinctrl *pinctrl;
  92. struct pinctrl_state *state_default;
  93. struct pinctrl_state *state_idle;
  94. } pinctl;
  95. bool user_subdev_api;
  96. spinlock_t slock;
  97. };
  98. #define is_subdev_pad(pad) (pad == NULL || \
  99. media_entity_type(pad->entity) == MEDIA_ENT_T_V4L2_SUBDEV)
  100. #define me_subtype(me) \
  101. ((me->type) & (MEDIA_ENT_TYPE_MASK | MEDIA_ENT_SUBTYPE_MASK))
  102. #define subdev_has_devnode(__sd) (__sd->flags & V4L2_SUBDEV_FL_HAS_DEVNODE)
  103. static inline
  104. struct fimc_sensor_info *source_to_sensor_info(struct fimc_source_info *si)
  105. {
  106. return container_of(si, struct fimc_sensor_info, pdata);
  107. }
  108. static inline struct fimc_md *entity_to_fimc_mdev(struct media_entity *me)
  109. {
  110. return me->parent == NULL ? NULL :
  111. container_of(me->parent, struct fimc_md, media_dev);
  112. }
  113. static inline void fimc_md_graph_lock(struct fimc_dev *fimc)
  114. {
  115. mutex_lock(&fimc->vid_cap.vfd.entity.parent->graph_mutex);
  116. }
  117. static inline void fimc_md_graph_unlock(struct fimc_dev *fimc)
  118. {
  119. mutex_unlock(&fimc->vid_cap.vfd.entity.parent->graph_mutex);
  120. }
  121. int fimc_md_set_camclk(struct v4l2_subdev *sd, bool on);
  122. #ifdef CONFIG_OF
  123. static inline bool fimc_md_is_isp_available(struct device_node *node)
  124. {
  125. node = of_get_child_by_name(node, FIMC_IS_OF_NODE_NAME);
  126. return node ? of_device_is_available(node) : false;
  127. }
  128. #else
  129. #define fimc_md_is_isp_available(node) (false)
  130. #endif /* CONFIG_OF */
  131. #endif