0009-csi0-csi1-can-be-configured-to-the-same-ISP.patch 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. From a24624e164f041e86d9c864a4eb83ab8c2befee4 Mon Sep 17 00:00:00 2001
  2. From: sw.multimedia <sw.multimedia@starfivetech.com>
  3. Date: Thu, 16 Dec 2021 17:46:03 +0800
  4. Subject: [PATCH 09/10] csi0/csi1 can be configured to the same ISP
  5. ---
  6. src/libcamera/pipeline/starfive/starfive.cpp | 146 +++++++++++--------
  7. 1 file changed, 89 insertions(+), 57 deletions(-)
  8. diff --git a/src/libcamera/pipeline/starfive/starfive.cpp b/src/libcamera/pipeline/starfive/starfive.cpp
  9. index 864addfa..61a2ddc6 100644
  10. --- a/src/libcamera/pipeline/starfive/starfive.cpp
  11. +++ b/src/libcamera/pipeline/starfive/starfive.cpp
  12. @@ -182,11 +182,11 @@ class StarFiveCameraData : public Camera::Private
  13. public:
  14. StarFiveCameraData(PipelineHandler *pipe, MediaDevice *media,
  15. std::string entityName,
  16. - std::string sensorEntityName)
  17. + SensorConfig sensorConfig)
  18. : Camera::Private(pipe), media_(media)
  19. {
  20. LOG(STARFIVE, Debug) << __func__;
  21. - sensorEntityName_ = sensorEntityName;
  22. + sensorConfig_ = sensorConfig;
  23. videoEntityName_ = entityName;
  24. if ( videoEntityName_ == "stf_vin0_isp0_video1")
  25. ispEntityName_ = "stf_isp0";
  26. @@ -221,10 +221,12 @@ public:
  27. bool haveRaw() const { return haveRaw_; }
  28. bool rawActive() const { return rawActive_; }
  29. void setRawActive(bool val) { rawActive_ = val; }
  30. + SensorConfig getSensorConfig() {return sensorConfig_; }
  31. std::vector<SizeRange> sensorSizes() const;
  32. std::vector<PixelFormat> sensorFormats() const;
  33. std::vector<PixelFormat> videoFormats() const;
  34. void paramsFilled(unsigned int id){}
  35. + int ispLoadFW(const char *filename);
  36. MediaDevice *media_;
  37. V4L2VideoDevice *video_;
  38. @@ -240,8 +242,8 @@ private:
  39. bool haveRaw_;
  40. bool rawActive_;
  41. std::string videoEntityName_;
  42. - std::string sensorEntityName_;
  43. std::string ispEntityName_;
  44. + SensorConfig sensorConfig_;
  45. std::string getRawVideoEntityName()
  46. {
  47. LOG(STARFIVE, Debug) << __func__;
  48. @@ -252,7 +254,6 @@ private:
  49. else
  50. return "unknow";
  51. }
  52. - int ispLoadFW(const char *filename);
  53. };
  54. std::vector<PixelFormat> StarFiveCameraData::videoFormats() const
  55. @@ -334,17 +335,12 @@ int StarFiveCameraData::init(MediaDevice *media)
  56. int ret;
  57. LOG(STARFIVE, Debug) << __func__;
  58. - if (sensorEntityName_ != "unknow") {
  59. - sensor_ =
  60. - new CameraSensor(media_->getEntityByName(sensorEntityName_));
  61. - ret = sensor_->init();
  62. - if (ret)
  63. - return ret;
  64. - LOG(STARFIVE, Debug) << "sensor id: " << sensor_->id();
  65. - } else {
  66. - LOG(STARFIVE, Debug) << " Can't find sensorEntityName!";
  67. - return -ENODEV;
  68. - }
  69. + sensor_ =
  70. + new CameraSensor(media_->getEntityByName(sensorConfig_.sensorEntityName_));
  71. + ret = sensor_->init();
  72. + if (ret)
  73. + return ret;
  74. + LOG(STARFIVE, Debug) << "sensor id: " << sensor_->id();
  75. if (ispEntityName_ != "unknow") {
  76. ispSubDev_ =
  77. @@ -352,13 +348,6 @@ int StarFiveCameraData::init(MediaDevice *media)
  78. LOG(STARFIVE, Debug) << "ispEntityName: " << ispEntityName_;
  79. if (ispSubDev_->open())
  80. return -ENODEV;
  81. -
  82. - for (SensorConfig it : sensorConfigs) {
  83. - if (it.sensorEntityName_ == sensorEntityName_) {
  84. - ispLoadFW(it.sensorFwImageName_.c_str());
  85. - break;
  86. - }
  87. - }
  88. }
  89. video_ = new V4L2VideoDevice(media_->getEntityByName(videoEntityName_));
  90. @@ -550,10 +539,20 @@ PipelineHandlerStarFive::generateConfiguration(Camera *camera,
  91. StarFiveCameraData *data = cameraData(camera);
  92. StarFiveCameraConfiguration *config =
  93. new StarFiveCameraConfiguration(data);
  94. + SensorConfig sensorConfig = data->getSensorConfig();
  95. if (roles.empty())
  96. return config;
  97. + int ret = enableLinks(pipelineConfigs[sensorConfig.sensorType_]);
  98. + if (ret < 0) {
  99. + LOG(STARFIVE, Error)
  100. + << sensorConfig.sensorEntityName_
  101. + << " enableLinks failed!";
  102. + return config;
  103. + }
  104. + data->ispLoadFW(sensorConfig.sensorFwImageName_.c_str());
  105. +
  106. for (const StreamRole role : roles) {
  107. std::map<PixelFormat, std::vector<SizeRange>> streamFormats;
  108. unsigned int bufferCount;
  109. @@ -1002,9 +1001,43 @@ int PipelineHandlerStarFive::registerCameras()
  110. unsigned int numCameras = 0;
  111. LOG(STARFIVE, Debug) << __func__;
  112. - for (unsigned int id = 0;
  113. - id < STF_MAX_CAMERAS
  114. - && numCameras < STF_MAX_CAMERAS; ++id) {
  115. + for (SensorConfig it : sensorConfigs) {
  116. + std::string cameraName;
  117. + int id = 0;
  118. +
  119. + switch (it.sensorType_) {
  120. + case DVP_YUV:
  121. + case MIPICSI0_YUV:
  122. + case MIPICSI1_YUV:
  123. + id = 0;
  124. + break;
  125. + case DVP_ISP0:
  126. + case MIPICSI0_ISP0:
  127. + case MIPICSI1_ISP0:
  128. + id = 1;
  129. + break;
  130. + case DVP_ISP1:
  131. + case MIPICSI0_ISP1:
  132. + case MIPICSI1_ISP1:
  133. + id = 2;
  134. + break;
  135. + default:
  136. + continue;
  137. + }
  138. +
  139. + MediaEntity *sensorEntity =
  140. + starFiveMediaDev_->getEntityByName(it.sensorEntityName_);
  141. + if (sensorEntity != nullptr) {
  142. + int ret = enableLinks(pipelineConfigs[it.sensorType_]);
  143. + if (ret < 0) {
  144. + LOG(STARFIVE, Error)
  145. + << it.sensorEntityName_
  146. + << " enableLinks failed!";
  147. + continue;
  148. + }
  149. + } else
  150. + continue;
  151. +
  152. std::string videoEntiryName;
  153. videoEntiryName = getVideoEntityNameById(id);
  154. if (videoEntiryName == "unknow")
  155. @@ -1012,12 +1045,17 @@ int PipelineHandlerStarFive::registerCameras()
  156. std::string sensorEntityName;
  157. sensorEntityName = findSensorEntityName(videoEntiryName);
  158. - if (sensorEntityName == "unknow")
  159. - continue;
  160. + if (sensorEntityName != it.sensorEntityName_)
  161. + continue;
  162. +
  163. + if (id != 0)
  164. + cameraName = it.sensorEntityName_ + " isp" + std::to_string(id - 1);
  165. + else
  166. + cameraName = it.sensorEntityName_ + " wr";
  167. std::unique_ptr<StarFiveCameraData> data =
  168. std::make_unique<StarFiveCameraData>(this, starFiveMediaDev_,
  169. - videoEntiryName, sensorEntityName);
  170. + videoEntiryName, it);
  171. /* Locate and open the capture video node. */
  172. if (data->init(starFiveMediaDev_))
  173. @@ -1034,18 +1072,17 @@ int PipelineHandlerStarFive::registerCameras()
  174. data->ipa_->init(IPASettings{ conf, data->sensor_->model() });
  175. /* Create and register the camera. */
  176. - LOG(STARFIVE, Debug) << "register deviceName: "
  177. - << videoEntiryName;
  178. + LOG(STARFIVE, Debug) << "register deviceName: " << cameraName;
  179. if (data->haveRaw()) {
  180. std::set<Stream *> streams{ &data->outStream_,
  181. &data->rawStream_ };
  182. std::shared_ptr<Camera> camera =
  183. - Camera::create(std::move(data), videoEntiryName, streams);
  184. + Camera::create(std::move(data), cameraName, streams);
  185. registerCamera(std::move(camera));
  186. } else {
  187. std::set<Stream *> streams{ &data->outStream_ };
  188. std::shared_ptr<Camera> camera =
  189. - Camera::create(std::move(data), videoEntiryName, streams);
  190. + Camera::create(std::move(data), cameraName, streams);
  191. registerCamera(std::move(camera));
  192. }
  193. numCameras++;
  194. @@ -1064,9 +1101,26 @@ int PipelineHandlerStarFive::enableLinks(std::vector<PipelineConfigLink> config)
  195. if (!link)
  196. return -ENODEV;
  197. - ret = link->setEnabled(true);
  198. - if (ret < 0)
  199. - return ret;
  200. + MediaEntity *remote = link->sink()->entity();
  201. + for (MediaPad *pad : remote->pads()) {
  202. + for (MediaLink *e : pad->links()) {
  203. + if (link == e)
  204. + continue;
  205. +
  206. + if ((e->flags() & MEDIA_LNK_FL_ENABLED) &&
  207. + !(e->flags() & MEDIA_LNK_FL_IMMUTABLE)) {
  208. + ret = e->setEnabled(false);
  209. + if (ret < 0)
  210. + return ret;
  211. + }
  212. + }
  213. + }
  214. +
  215. + if (!(link->flags() & MEDIA_LNK_FL_ENABLED)) {
  216. + ret = link->setEnabled(true);
  217. + if (ret < 0)
  218. + return ret;
  219. + }
  220. }
  221. return ret;
  222. @@ -1136,30 +1190,8 @@ bool PipelineHandlerStarFive::match(DeviceEnumerator *enumerator)
  223. if (!starFiveMediaDev_)
  224. return false;
  225. - if (starFiveMediaDev_->disableLinks())
  226. - return false;
  227. -
  228. parserPipelineConfig(PIPELINE_CONFIG_FILENAME);
  229. - for (SensorConfig it : sensorConfigs) {
  230. - MediaEntity *sensorEntity =
  231. - starFiveMediaDev_->getEntityByName(it.sensorEntityName_);
  232. - int ret;
  233. -
  234. - if (sensorEntity != nullptr) {
  235. - if (it.sensorType_ < DVP_YUV
  236. - || it.sensorType_ >= SENSORTYPE_MAX)
  237. - continue;
  238. - ret = enableLinks(pipelineConfigs[it.sensorType_]);
  239. - if (ret < 0) {
  240. - LOG(STARFIVE, Error)
  241. - << it.sensorEntityName_
  242. - << " enableLinks failed!";
  243. - continue;
  244. - }
  245. - }
  246. - }
  247. -
  248. numCameras = registerCameras();
  249. if (numCameras)
  250. LOG(STARFIVE, Debug)
  251. --
  252. 2.25.1