v4l2-fwnode.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * V4L2 fwnode binding parsing library
  4. *
  5. * The origins of the V4L2 fwnode library are in V4L2 OF library that
  6. * formerly was located in v4l2-of.c.
  7. *
  8. * Copyright (c) 2016 Intel Corporation.
  9. * Author: Sakari Ailus <sakari.ailus@linux.intel.com>
  10. *
  11. * Copyright (C) 2012 - 2013 Samsung Electronics Co., Ltd.
  12. * Author: Sylwester Nawrocki <s.nawrocki@samsung.com>
  13. *
  14. * Copyright (C) 2012 Renesas Electronics Corp.
  15. * Author: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
  16. */
  17. #include <linux/acpi.h>
  18. #include <linux/kernel.h>
  19. #include <linux/mm.h>
  20. #include <linux/module.h>
  21. #include <linux/of.h>
  22. #include <linux/property.h>
  23. #include <linux/slab.h>
  24. #include <linux/string.h>
  25. #include <linux/types.h>
  26. #include <media/v4l2-async.h>
  27. #include <media/v4l2-fwnode.h>
  28. #include <media/v4l2-subdev.h>
  29. #include "v4l2-subdev-priv.h"
  30. static const struct v4l2_fwnode_bus_conv {
  31. enum v4l2_fwnode_bus_type fwnode_bus_type;
  32. enum v4l2_mbus_type mbus_type;
  33. const char *name;
  34. } buses[] = {
  35. {
  36. V4L2_FWNODE_BUS_TYPE_GUESS,
  37. V4L2_MBUS_UNKNOWN,
  38. "not specified",
  39. }, {
  40. V4L2_FWNODE_BUS_TYPE_CSI2_CPHY,
  41. V4L2_MBUS_CSI2_CPHY,
  42. "MIPI CSI-2 C-PHY",
  43. }, {
  44. V4L2_FWNODE_BUS_TYPE_CSI1,
  45. V4L2_MBUS_CSI1,
  46. "MIPI CSI-1",
  47. }, {
  48. V4L2_FWNODE_BUS_TYPE_CCP2,
  49. V4L2_MBUS_CCP2,
  50. "compact camera port 2",
  51. }, {
  52. V4L2_FWNODE_BUS_TYPE_CSI2_DPHY,
  53. V4L2_MBUS_CSI2_DPHY,
  54. "MIPI CSI-2 D-PHY",
  55. }, {
  56. V4L2_FWNODE_BUS_TYPE_PARALLEL,
  57. V4L2_MBUS_PARALLEL,
  58. "parallel",
  59. }, {
  60. V4L2_FWNODE_BUS_TYPE_BT656,
  61. V4L2_MBUS_BT656,
  62. "Bt.656",
  63. }, {
  64. V4L2_FWNODE_BUS_TYPE_DPI,
  65. V4L2_MBUS_DPI,
  66. "DPI",
  67. }
  68. };
  69. static const struct v4l2_fwnode_bus_conv *
  70. get_v4l2_fwnode_bus_conv_by_fwnode_bus(enum v4l2_fwnode_bus_type type)
  71. {
  72. unsigned int i;
  73. for (i = 0; i < ARRAY_SIZE(buses); i++)
  74. if (buses[i].fwnode_bus_type == type)
  75. return &buses[i];
  76. return NULL;
  77. }
  78. static enum v4l2_mbus_type
  79. v4l2_fwnode_bus_type_to_mbus(enum v4l2_fwnode_bus_type type)
  80. {
  81. const struct v4l2_fwnode_bus_conv *conv =
  82. get_v4l2_fwnode_bus_conv_by_fwnode_bus(type);
  83. return conv ? conv->mbus_type : V4L2_MBUS_INVALID;
  84. }
  85. static const char *
  86. v4l2_fwnode_bus_type_to_string(enum v4l2_fwnode_bus_type type)
  87. {
  88. const struct v4l2_fwnode_bus_conv *conv =
  89. get_v4l2_fwnode_bus_conv_by_fwnode_bus(type);
  90. return conv ? conv->name : "not found";
  91. }
  92. static const struct v4l2_fwnode_bus_conv *
  93. get_v4l2_fwnode_bus_conv_by_mbus(enum v4l2_mbus_type type)
  94. {
  95. unsigned int i;
  96. for (i = 0; i < ARRAY_SIZE(buses); i++)
  97. if (buses[i].mbus_type == type)
  98. return &buses[i];
  99. return NULL;
  100. }
  101. static const char *
  102. v4l2_fwnode_mbus_type_to_string(enum v4l2_mbus_type type)
  103. {
  104. const struct v4l2_fwnode_bus_conv *conv =
  105. get_v4l2_fwnode_bus_conv_by_mbus(type);
  106. return conv ? conv->name : "not found";
  107. }
  108. static int v4l2_fwnode_endpoint_parse_csi2_bus(struct fwnode_handle *fwnode,
  109. struct v4l2_fwnode_endpoint *vep,
  110. enum v4l2_mbus_type bus_type)
  111. {
  112. struct v4l2_mbus_config_mipi_csi2 *bus = &vep->bus.mipi_csi2;
  113. bool have_clk_lane = false, have_data_lanes = false,
  114. have_lane_polarities = false;
  115. unsigned int flags = 0, lanes_used = 0;
  116. u32 array[1 + V4L2_MBUS_CSI2_MAX_DATA_LANES];
  117. u32 clock_lane = 0;
  118. unsigned int num_data_lanes = 0;
  119. bool use_default_lane_mapping = false;
  120. unsigned int i;
  121. u32 v;
  122. int rval;
  123. if (bus_type == V4L2_MBUS_CSI2_DPHY ||
  124. bus_type == V4L2_MBUS_CSI2_CPHY) {
  125. use_default_lane_mapping = true;
  126. num_data_lanes = min_t(u32, bus->num_data_lanes,
  127. V4L2_MBUS_CSI2_MAX_DATA_LANES);
  128. clock_lane = bus->clock_lane;
  129. if (clock_lane)
  130. use_default_lane_mapping = false;
  131. for (i = 0; i < num_data_lanes; i++) {
  132. array[i] = bus->data_lanes[i];
  133. if (array[i])
  134. use_default_lane_mapping = false;
  135. }
  136. if (use_default_lane_mapping)
  137. pr_debug("no lane mapping given, using defaults\n");
  138. }
  139. rval = fwnode_property_count_u32(fwnode, "data-lanes");
  140. if (rval > 0) {
  141. num_data_lanes =
  142. min_t(int, V4L2_MBUS_CSI2_MAX_DATA_LANES, rval);
  143. fwnode_property_read_u32_array(fwnode, "data-lanes", array,
  144. num_data_lanes);
  145. have_data_lanes = true;
  146. if (use_default_lane_mapping) {
  147. pr_debug("data-lanes property exists; disabling default mapping\n");
  148. use_default_lane_mapping = false;
  149. }
  150. }
  151. for (i = 0; i < num_data_lanes; i++) {
  152. if (lanes_used & BIT(array[i])) {
  153. if (have_data_lanes || !use_default_lane_mapping)
  154. pr_warn("duplicated lane %u in data-lanes, using defaults\n",
  155. array[i]);
  156. use_default_lane_mapping = true;
  157. }
  158. lanes_used |= BIT(array[i]);
  159. if (have_data_lanes)
  160. pr_debug("lane %u position %u\n", i, array[i]);
  161. }
  162. rval = fwnode_property_count_u32(fwnode, "lane-polarities");
  163. if (rval > 0) {
  164. if (rval != 1 + num_data_lanes /* clock+data */) {
  165. pr_warn("invalid number of lane-polarities entries (need %u, got %u)\n",
  166. 1 + num_data_lanes, rval);
  167. return -EINVAL;
  168. }
  169. have_lane_polarities = true;
  170. }
  171. if (!fwnode_property_read_u32(fwnode, "clock-lanes", &v)) {
  172. clock_lane = v;
  173. pr_debug("clock lane position %u\n", v);
  174. have_clk_lane = true;
  175. }
  176. if (have_clk_lane && lanes_used & BIT(clock_lane) &&
  177. !use_default_lane_mapping) {
  178. pr_warn("duplicated lane %u in clock-lanes, using defaults\n",
  179. v);
  180. use_default_lane_mapping = true;
  181. }
  182. if (fwnode_property_present(fwnode, "clock-noncontinuous")) {
  183. flags |= V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK;
  184. pr_debug("non-continuous clock\n");
  185. }
  186. if (bus_type == V4L2_MBUS_CSI2_DPHY ||
  187. bus_type == V4L2_MBUS_CSI2_CPHY ||
  188. lanes_used || have_clk_lane || flags) {
  189. /* Only D-PHY has a clock lane. */
  190. unsigned int dfl_data_lane_index =
  191. bus_type == V4L2_MBUS_CSI2_DPHY;
  192. bus->flags = flags;
  193. if (bus_type == V4L2_MBUS_UNKNOWN)
  194. vep->bus_type = V4L2_MBUS_CSI2_DPHY;
  195. bus->num_data_lanes = num_data_lanes;
  196. if (use_default_lane_mapping) {
  197. bus->clock_lane = 0;
  198. for (i = 0; i < num_data_lanes; i++)
  199. bus->data_lanes[i] = dfl_data_lane_index + i;
  200. } else {
  201. bus->clock_lane = clock_lane;
  202. for (i = 0; i < num_data_lanes; i++)
  203. bus->data_lanes[i] = array[i];
  204. }
  205. if (have_lane_polarities) {
  206. fwnode_property_read_u32_array(fwnode,
  207. "lane-polarities", array,
  208. 1 + num_data_lanes);
  209. for (i = 0; i < 1 + num_data_lanes; i++) {
  210. bus->lane_polarities[i] = array[i];
  211. pr_debug("lane %u polarity %sinverted",
  212. i, array[i] ? "" : "not ");
  213. }
  214. } else {
  215. pr_debug("no lane polarities defined, assuming not inverted\n");
  216. }
  217. }
  218. return 0;
  219. }
  220. #define PARALLEL_MBUS_FLAGS (V4L2_MBUS_HSYNC_ACTIVE_HIGH | \
  221. V4L2_MBUS_HSYNC_ACTIVE_LOW | \
  222. V4L2_MBUS_VSYNC_ACTIVE_HIGH | \
  223. V4L2_MBUS_VSYNC_ACTIVE_LOW | \
  224. V4L2_MBUS_FIELD_EVEN_HIGH | \
  225. V4L2_MBUS_FIELD_EVEN_LOW)
  226. static void
  227. v4l2_fwnode_endpoint_parse_parallel_bus(struct fwnode_handle *fwnode,
  228. struct v4l2_fwnode_endpoint *vep,
  229. enum v4l2_mbus_type bus_type)
  230. {
  231. struct v4l2_mbus_config_parallel *bus = &vep->bus.parallel;
  232. unsigned int flags = 0;
  233. u32 v;
  234. if (bus_type == V4L2_MBUS_PARALLEL || bus_type == V4L2_MBUS_BT656)
  235. flags = bus->flags;
  236. if (!fwnode_property_read_u32(fwnode, "hsync-active", &v)) {
  237. flags &= ~(V4L2_MBUS_HSYNC_ACTIVE_HIGH |
  238. V4L2_MBUS_HSYNC_ACTIVE_LOW);
  239. flags |= v ? V4L2_MBUS_HSYNC_ACTIVE_HIGH :
  240. V4L2_MBUS_HSYNC_ACTIVE_LOW;
  241. pr_debug("hsync-active %s\n", v ? "high" : "low");
  242. }
  243. if (!fwnode_property_read_u32(fwnode, "vsync-active", &v)) {
  244. flags &= ~(V4L2_MBUS_VSYNC_ACTIVE_HIGH |
  245. V4L2_MBUS_VSYNC_ACTIVE_LOW);
  246. flags |= v ? V4L2_MBUS_VSYNC_ACTIVE_HIGH :
  247. V4L2_MBUS_VSYNC_ACTIVE_LOW;
  248. pr_debug("vsync-active %s\n", v ? "high" : "low");
  249. }
  250. if (!fwnode_property_read_u32(fwnode, "field-even-active", &v)) {
  251. flags &= ~(V4L2_MBUS_FIELD_EVEN_HIGH |
  252. V4L2_MBUS_FIELD_EVEN_LOW);
  253. flags |= v ? V4L2_MBUS_FIELD_EVEN_HIGH :
  254. V4L2_MBUS_FIELD_EVEN_LOW;
  255. pr_debug("field-even-active %s\n", v ? "high" : "low");
  256. }
  257. if (!fwnode_property_read_u32(fwnode, "pclk-sample", &v)) {
  258. flags &= ~(V4L2_MBUS_PCLK_SAMPLE_RISING |
  259. V4L2_MBUS_PCLK_SAMPLE_FALLING |
  260. V4L2_MBUS_PCLK_SAMPLE_DUALEDGE);
  261. switch (v) {
  262. case 0:
  263. flags |= V4L2_MBUS_PCLK_SAMPLE_FALLING;
  264. pr_debug("pclk-sample low\n");
  265. break;
  266. case 1:
  267. flags |= V4L2_MBUS_PCLK_SAMPLE_RISING;
  268. pr_debug("pclk-sample high\n");
  269. break;
  270. case 2:
  271. flags |= V4L2_MBUS_PCLK_SAMPLE_DUALEDGE;
  272. pr_debug("pclk-sample dual edge\n");
  273. break;
  274. default:
  275. pr_warn("invalid argument for pclk-sample");
  276. break;
  277. }
  278. }
  279. if (!fwnode_property_read_u32(fwnode, "data-active", &v)) {
  280. flags &= ~(V4L2_MBUS_DATA_ACTIVE_HIGH |
  281. V4L2_MBUS_DATA_ACTIVE_LOW);
  282. flags |= v ? V4L2_MBUS_DATA_ACTIVE_HIGH :
  283. V4L2_MBUS_DATA_ACTIVE_LOW;
  284. pr_debug("data-active %s\n", v ? "high" : "low");
  285. }
  286. if (fwnode_property_present(fwnode, "slave-mode")) {
  287. pr_debug("slave mode\n");
  288. flags &= ~V4L2_MBUS_MASTER;
  289. flags |= V4L2_MBUS_SLAVE;
  290. } else {
  291. flags &= ~V4L2_MBUS_SLAVE;
  292. flags |= V4L2_MBUS_MASTER;
  293. }
  294. if (!fwnode_property_read_u32(fwnode, "bus-width", &v)) {
  295. bus->bus_width = v;
  296. pr_debug("bus-width %u\n", v);
  297. }
  298. if (!fwnode_property_read_u32(fwnode, "data-shift", &v)) {
  299. bus->data_shift = v;
  300. pr_debug("data-shift %u\n", v);
  301. }
  302. if (!fwnode_property_read_u32(fwnode, "sync-on-green-active", &v)) {
  303. flags &= ~(V4L2_MBUS_VIDEO_SOG_ACTIVE_HIGH |
  304. V4L2_MBUS_VIDEO_SOG_ACTIVE_LOW);
  305. flags |= v ? V4L2_MBUS_VIDEO_SOG_ACTIVE_HIGH :
  306. V4L2_MBUS_VIDEO_SOG_ACTIVE_LOW;
  307. pr_debug("sync-on-green-active %s\n", v ? "high" : "low");
  308. }
  309. if (!fwnode_property_read_u32(fwnode, "data-enable-active", &v)) {
  310. flags &= ~(V4L2_MBUS_DATA_ENABLE_HIGH |
  311. V4L2_MBUS_DATA_ENABLE_LOW);
  312. flags |= v ? V4L2_MBUS_DATA_ENABLE_HIGH :
  313. V4L2_MBUS_DATA_ENABLE_LOW;
  314. pr_debug("data-enable-active %s\n", v ? "high" : "low");
  315. }
  316. switch (bus_type) {
  317. default:
  318. bus->flags = flags;
  319. if (flags & PARALLEL_MBUS_FLAGS)
  320. vep->bus_type = V4L2_MBUS_PARALLEL;
  321. else
  322. vep->bus_type = V4L2_MBUS_BT656;
  323. break;
  324. case V4L2_MBUS_PARALLEL:
  325. vep->bus_type = V4L2_MBUS_PARALLEL;
  326. bus->flags = flags;
  327. break;
  328. case V4L2_MBUS_BT656:
  329. vep->bus_type = V4L2_MBUS_BT656;
  330. bus->flags = flags & ~PARALLEL_MBUS_FLAGS;
  331. break;
  332. }
  333. }
  334. static void
  335. v4l2_fwnode_endpoint_parse_csi1_bus(struct fwnode_handle *fwnode,
  336. struct v4l2_fwnode_endpoint *vep,
  337. enum v4l2_mbus_type bus_type)
  338. {
  339. struct v4l2_mbus_config_mipi_csi1 *bus = &vep->bus.mipi_csi1;
  340. u32 v;
  341. if (!fwnode_property_read_u32(fwnode, "clock-inv", &v)) {
  342. bus->clock_inv = v;
  343. pr_debug("clock-inv %u\n", v);
  344. }
  345. if (!fwnode_property_read_u32(fwnode, "strobe", &v)) {
  346. bus->strobe = v;
  347. pr_debug("strobe %u\n", v);
  348. }
  349. if (!fwnode_property_read_u32(fwnode, "data-lanes", &v)) {
  350. bus->data_lane = v;
  351. pr_debug("data-lanes %u\n", v);
  352. }
  353. if (!fwnode_property_read_u32(fwnode, "clock-lanes", &v)) {
  354. bus->clock_lane = v;
  355. pr_debug("clock-lanes %u\n", v);
  356. }
  357. if (bus_type == V4L2_MBUS_CCP2)
  358. vep->bus_type = V4L2_MBUS_CCP2;
  359. else
  360. vep->bus_type = V4L2_MBUS_CSI1;
  361. }
  362. static int __v4l2_fwnode_endpoint_parse(struct fwnode_handle *fwnode,
  363. struct v4l2_fwnode_endpoint *vep)
  364. {
  365. u32 bus_type = V4L2_FWNODE_BUS_TYPE_GUESS;
  366. enum v4l2_mbus_type mbus_type;
  367. int rval;
  368. pr_debug("===== begin parsing endpoint %pfw\n", fwnode);
  369. fwnode_property_read_u32(fwnode, "bus-type", &bus_type);
  370. pr_debug("fwnode video bus type %s (%u), mbus type %s (%u)\n",
  371. v4l2_fwnode_bus_type_to_string(bus_type), bus_type,
  372. v4l2_fwnode_mbus_type_to_string(vep->bus_type),
  373. vep->bus_type);
  374. mbus_type = v4l2_fwnode_bus_type_to_mbus(bus_type);
  375. if (mbus_type == V4L2_MBUS_INVALID) {
  376. pr_debug("unsupported bus type %u\n", bus_type);
  377. return -EINVAL;
  378. }
  379. if (vep->bus_type != V4L2_MBUS_UNKNOWN) {
  380. if (mbus_type != V4L2_MBUS_UNKNOWN &&
  381. vep->bus_type != mbus_type) {
  382. pr_debug("expecting bus type %s\n",
  383. v4l2_fwnode_mbus_type_to_string(vep->bus_type));
  384. return -ENXIO;
  385. }
  386. } else {
  387. vep->bus_type = mbus_type;
  388. }
  389. switch (vep->bus_type) {
  390. case V4L2_MBUS_UNKNOWN:
  391. rval = v4l2_fwnode_endpoint_parse_csi2_bus(fwnode, vep,
  392. V4L2_MBUS_UNKNOWN);
  393. if (rval)
  394. return rval;
  395. if (vep->bus_type == V4L2_MBUS_UNKNOWN)
  396. v4l2_fwnode_endpoint_parse_parallel_bus(fwnode, vep,
  397. V4L2_MBUS_UNKNOWN);
  398. pr_debug("assuming media bus type %s (%u)\n",
  399. v4l2_fwnode_mbus_type_to_string(vep->bus_type),
  400. vep->bus_type);
  401. break;
  402. case V4L2_MBUS_CCP2:
  403. case V4L2_MBUS_CSI1:
  404. v4l2_fwnode_endpoint_parse_csi1_bus(fwnode, vep, vep->bus_type);
  405. break;
  406. case V4L2_MBUS_CSI2_DPHY:
  407. case V4L2_MBUS_CSI2_CPHY:
  408. rval = v4l2_fwnode_endpoint_parse_csi2_bus(fwnode, vep,
  409. vep->bus_type);
  410. if (rval)
  411. return rval;
  412. break;
  413. case V4L2_MBUS_PARALLEL:
  414. case V4L2_MBUS_BT656:
  415. v4l2_fwnode_endpoint_parse_parallel_bus(fwnode, vep,
  416. vep->bus_type);
  417. break;
  418. default:
  419. pr_warn("unsupported bus type %u\n", mbus_type);
  420. return -EINVAL;
  421. }
  422. fwnode_graph_parse_endpoint(fwnode, &vep->base);
  423. return 0;
  424. }
  425. int v4l2_fwnode_endpoint_parse(struct fwnode_handle *fwnode,
  426. struct v4l2_fwnode_endpoint *vep)
  427. {
  428. int ret;
  429. ret = __v4l2_fwnode_endpoint_parse(fwnode, vep);
  430. pr_debug("===== end parsing endpoint %pfw\n", fwnode);
  431. return ret;
  432. }
  433. EXPORT_SYMBOL_GPL(v4l2_fwnode_endpoint_parse);
  434. void v4l2_fwnode_endpoint_free(struct v4l2_fwnode_endpoint *vep)
  435. {
  436. if (IS_ERR_OR_NULL(vep))
  437. return;
  438. kfree(vep->link_frequencies);
  439. vep->link_frequencies = NULL;
  440. }
  441. EXPORT_SYMBOL_GPL(v4l2_fwnode_endpoint_free);
  442. int v4l2_fwnode_endpoint_alloc_parse(struct fwnode_handle *fwnode,
  443. struct v4l2_fwnode_endpoint *vep)
  444. {
  445. int rval;
  446. rval = __v4l2_fwnode_endpoint_parse(fwnode, vep);
  447. if (rval < 0)
  448. return rval;
  449. rval = fwnode_property_count_u64(fwnode, "link-frequencies");
  450. if (rval > 0) {
  451. unsigned int i;
  452. vep->link_frequencies =
  453. kmalloc_array(rval, sizeof(*vep->link_frequencies),
  454. GFP_KERNEL);
  455. if (!vep->link_frequencies)
  456. return -ENOMEM;
  457. vep->nr_of_link_frequencies = rval;
  458. rval = fwnode_property_read_u64_array(fwnode,
  459. "link-frequencies",
  460. vep->link_frequencies,
  461. vep->nr_of_link_frequencies);
  462. if (rval < 0) {
  463. v4l2_fwnode_endpoint_free(vep);
  464. return rval;
  465. }
  466. for (i = 0; i < vep->nr_of_link_frequencies; i++)
  467. pr_debug("link-frequencies %u value %llu\n", i,
  468. vep->link_frequencies[i]);
  469. }
  470. pr_debug("===== end parsing endpoint %pfw\n", fwnode);
  471. return 0;
  472. }
  473. EXPORT_SYMBOL_GPL(v4l2_fwnode_endpoint_alloc_parse);
  474. int v4l2_fwnode_parse_link(struct fwnode_handle *fwnode,
  475. struct v4l2_fwnode_link *link)
  476. {
  477. struct fwnode_endpoint fwep;
  478. memset(link, 0, sizeof(*link));
  479. fwnode_graph_parse_endpoint(fwnode, &fwep);
  480. link->local_id = fwep.id;
  481. link->local_port = fwep.port;
  482. link->local_node = fwnode_graph_get_port_parent(fwnode);
  483. if (!link->local_node)
  484. return -ENOLINK;
  485. fwnode = fwnode_graph_get_remote_endpoint(fwnode);
  486. if (!fwnode)
  487. goto err_put_local_node;
  488. fwnode_graph_parse_endpoint(fwnode, &fwep);
  489. link->remote_id = fwep.id;
  490. link->remote_port = fwep.port;
  491. link->remote_node = fwnode_graph_get_port_parent(fwnode);
  492. if (!link->remote_node)
  493. goto err_put_remote_endpoint;
  494. return 0;
  495. err_put_remote_endpoint:
  496. fwnode_handle_put(fwnode);
  497. err_put_local_node:
  498. fwnode_handle_put(link->local_node);
  499. return -ENOLINK;
  500. }
  501. EXPORT_SYMBOL_GPL(v4l2_fwnode_parse_link);
  502. void v4l2_fwnode_put_link(struct v4l2_fwnode_link *link)
  503. {
  504. fwnode_handle_put(link->local_node);
  505. fwnode_handle_put(link->remote_node);
  506. }
  507. EXPORT_SYMBOL_GPL(v4l2_fwnode_put_link);
  508. static const struct v4l2_fwnode_connector_conv {
  509. enum v4l2_connector_type type;
  510. const char *compatible;
  511. } connectors[] = {
  512. {
  513. .type = V4L2_CONN_COMPOSITE,
  514. .compatible = "composite-video-connector",
  515. }, {
  516. .type = V4L2_CONN_SVIDEO,
  517. .compatible = "svideo-connector",
  518. },
  519. };
  520. static enum v4l2_connector_type
  521. v4l2_fwnode_string_to_connector_type(const char *con_str)
  522. {
  523. unsigned int i;
  524. for (i = 0; i < ARRAY_SIZE(connectors); i++)
  525. if (!strcmp(con_str, connectors[i].compatible))
  526. return connectors[i].type;
  527. return V4L2_CONN_UNKNOWN;
  528. }
  529. static void
  530. v4l2_fwnode_connector_parse_analog(struct fwnode_handle *fwnode,
  531. struct v4l2_fwnode_connector *vc)
  532. {
  533. u32 stds;
  534. int ret;
  535. ret = fwnode_property_read_u32(fwnode, "sdtv-standards", &stds);
  536. /* The property is optional. */
  537. vc->connector.analog.sdtv_stds = ret ? V4L2_STD_ALL : stds;
  538. }
  539. void v4l2_fwnode_connector_free(struct v4l2_fwnode_connector *connector)
  540. {
  541. struct v4l2_connector_link *link, *tmp;
  542. if (IS_ERR_OR_NULL(connector) || connector->type == V4L2_CONN_UNKNOWN)
  543. return;
  544. list_for_each_entry_safe(link, tmp, &connector->links, head) {
  545. v4l2_fwnode_put_link(&link->fwnode_link);
  546. list_del(&link->head);
  547. kfree(link);
  548. }
  549. kfree(connector->label);
  550. connector->label = NULL;
  551. connector->type = V4L2_CONN_UNKNOWN;
  552. }
  553. EXPORT_SYMBOL_GPL(v4l2_fwnode_connector_free);
  554. static enum v4l2_connector_type
  555. v4l2_fwnode_get_connector_type(struct fwnode_handle *fwnode)
  556. {
  557. const char *type_name;
  558. int err;
  559. if (!fwnode)
  560. return V4L2_CONN_UNKNOWN;
  561. /* The connector-type is stored within the compatible string. */
  562. err = fwnode_property_read_string(fwnode, "compatible", &type_name);
  563. if (err)
  564. return V4L2_CONN_UNKNOWN;
  565. return v4l2_fwnode_string_to_connector_type(type_name);
  566. }
  567. int v4l2_fwnode_connector_parse(struct fwnode_handle *fwnode,
  568. struct v4l2_fwnode_connector *connector)
  569. {
  570. struct fwnode_handle *connector_node;
  571. enum v4l2_connector_type connector_type;
  572. const char *label;
  573. int err;
  574. if (!fwnode)
  575. return -EINVAL;
  576. memset(connector, 0, sizeof(*connector));
  577. INIT_LIST_HEAD(&connector->links);
  578. connector_node = fwnode_graph_get_port_parent(fwnode);
  579. connector_type = v4l2_fwnode_get_connector_type(connector_node);
  580. if (connector_type == V4L2_CONN_UNKNOWN) {
  581. fwnode_handle_put(connector_node);
  582. connector_node = fwnode_graph_get_remote_port_parent(fwnode);
  583. connector_type = v4l2_fwnode_get_connector_type(connector_node);
  584. }
  585. if (connector_type == V4L2_CONN_UNKNOWN) {
  586. pr_err("Unknown connector type\n");
  587. err = -ENOTCONN;
  588. goto out;
  589. }
  590. connector->type = connector_type;
  591. connector->name = fwnode_get_name(connector_node);
  592. err = fwnode_property_read_string(connector_node, "label", &label);
  593. connector->label = err ? NULL : kstrdup_const(label, GFP_KERNEL);
  594. /* Parse the connector specific properties. */
  595. switch (connector->type) {
  596. case V4L2_CONN_COMPOSITE:
  597. case V4L2_CONN_SVIDEO:
  598. v4l2_fwnode_connector_parse_analog(connector_node, connector);
  599. break;
  600. /* Avoid compiler warnings */
  601. case V4L2_CONN_UNKNOWN:
  602. break;
  603. }
  604. out:
  605. fwnode_handle_put(connector_node);
  606. return err;
  607. }
  608. EXPORT_SYMBOL_GPL(v4l2_fwnode_connector_parse);
  609. int v4l2_fwnode_connector_add_link(struct fwnode_handle *fwnode,
  610. struct v4l2_fwnode_connector *connector)
  611. {
  612. struct fwnode_handle *connector_ep;
  613. struct v4l2_connector_link *link;
  614. int err;
  615. if (!fwnode || !connector || connector->type == V4L2_CONN_UNKNOWN)
  616. return -EINVAL;
  617. connector_ep = fwnode_graph_get_remote_endpoint(fwnode);
  618. if (!connector_ep)
  619. return -ENOTCONN;
  620. link = kzalloc(sizeof(*link), GFP_KERNEL);
  621. if (!link) {
  622. err = -ENOMEM;
  623. goto err;
  624. }
  625. err = v4l2_fwnode_parse_link(connector_ep, &link->fwnode_link);
  626. if (err)
  627. goto err;
  628. fwnode_handle_put(connector_ep);
  629. list_add(&link->head, &connector->links);
  630. connector->nr_of_links++;
  631. return 0;
  632. err:
  633. kfree(link);
  634. fwnode_handle_put(connector_ep);
  635. return err;
  636. }
  637. EXPORT_SYMBOL_GPL(v4l2_fwnode_connector_add_link);
  638. int v4l2_fwnode_device_parse(struct device *dev,
  639. struct v4l2_fwnode_device_properties *props)
  640. {
  641. struct fwnode_handle *fwnode = dev_fwnode(dev);
  642. u32 val;
  643. int ret;
  644. memset(props, 0, sizeof(*props));
  645. props->orientation = V4L2_FWNODE_PROPERTY_UNSET;
  646. ret = fwnode_property_read_u32(fwnode, "orientation", &val);
  647. if (!ret) {
  648. switch (val) {
  649. case V4L2_FWNODE_ORIENTATION_FRONT:
  650. case V4L2_FWNODE_ORIENTATION_BACK:
  651. case V4L2_FWNODE_ORIENTATION_EXTERNAL:
  652. break;
  653. default:
  654. dev_warn(dev, "Unsupported device orientation: %u\n", val);
  655. return -EINVAL;
  656. }
  657. props->orientation = val;
  658. dev_dbg(dev, "device orientation: %u\n", val);
  659. }
  660. props->rotation = V4L2_FWNODE_PROPERTY_UNSET;
  661. ret = fwnode_property_read_u32(fwnode, "rotation", &val);
  662. if (!ret) {
  663. if (val >= 360) {
  664. dev_warn(dev, "Unsupported device rotation: %u\n", val);
  665. return -EINVAL;
  666. }
  667. props->rotation = val;
  668. dev_dbg(dev, "device rotation: %u\n", val);
  669. }
  670. return 0;
  671. }
  672. EXPORT_SYMBOL_GPL(v4l2_fwnode_device_parse);
  673. /*
  674. * v4l2_fwnode_reference_parse - parse references for async sub-devices
  675. * @dev: the device node the properties of which are parsed for references
  676. * @notifier: the async notifier where the async subdevs will be added
  677. * @prop: the name of the property
  678. *
  679. * Return: 0 on success
  680. * -ENOENT if no entries were found
  681. * -ENOMEM if memory allocation failed
  682. * -EINVAL if property parsing failed
  683. */
  684. static int v4l2_fwnode_reference_parse(struct device *dev,
  685. struct v4l2_async_notifier *notifier,
  686. const char *prop)
  687. {
  688. struct fwnode_reference_args args;
  689. unsigned int index;
  690. int ret;
  691. for (index = 0;
  692. !(ret = fwnode_property_get_reference_args(dev_fwnode(dev), prop,
  693. NULL, 0, index, &args));
  694. index++) {
  695. struct v4l2_async_connection *asd;
  696. asd = v4l2_async_nf_add_fwnode(notifier, args.fwnode,
  697. struct v4l2_async_connection);
  698. fwnode_handle_put(args.fwnode);
  699. if (IS_ERR(asd)) {
  700. /* not an error if asd already exists */
  701. if (PTR_ERR(asd) == -EEXIST)
  702. continue;
  703. return PTR_ERR(asd);
  704. }
  705. }
  706. /* -ENOENT here means successful parsing */
  707. if (ret != -ENOENT)
  708. return ret;
  709. /* Return -ENOENT if no references were found */
  710. return index ? 0 : -ENOENT;
  711. }
  712. /*
  713. * v4l2_fwnode_reference_get_int_prop - parse a reference with integer
  714. * arguments
  715. * @fwnode: fwnode to read @prop from
  716. * @notifier: notifier for @dev
  717. * @prop: the name of the property
  718. * @index: the index of the reference to get
  719. * @props: the array of integer property names
  720. * @nprops: the number of integer property names in @nprops
  721. *
  722. * First find an fwnode referred to by the reference at @index in @prop.
  723. *
  724. * Then under that fwnode, @nprops times, for each property in @props,
  725. * iteratively follow child nodes starting from fwnode such that they have the
  726. * property in @props array at the index of the child node distance from the
  727. * root node and the value of that property matching with the integer argument
  728. * of the reference, at the same index.
  729. *
  730. * The child fwnode reached at the end of the iteration is then returned to the
  731. * caller.
  732. *
  733. * The core reason for this is that you cannot refer to just any node in ACPI.
  734. * So to refer to an endpoint (easy in DT) you need to refer to a device, then
  735. * provide a list of (property name, property value) tuples where each tuple
  736. * uniquely identifies a child node. The first tuple identifies a child directly
  737. * underneath the device fwnode, the next tuple identifies a child node
  738. * underneath the fwnode identified by the previous tuple, etc. until you
  739. * reached the fwnode you need.
  740. *
  741. * THIS EXAMPLE EXISTS MERELY TO DOCUMENT THIS FUNCTION. DO NOT USE IT AS A
  742. * REFERENCE IN HOW ACPI TABLES SHOULD BE WRITTEN!! See documentation under
  743. * Documentation/firmware-guide/acpi/dsd/ instead and especially graph.txt,
  744. * data-node-references.txt and leds.txt .
  745. *
  746. * Scope (\_SB.PCI0.I2C2)
  747. * {
  748. * Device (CAM0)
  749. * {
  750. * Name (_DSD, Package () {
  751. * ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
  752. * Package () {
  753. * Package () {
  754. * "compatible",
  755. * Package () { "nokia,smia" }
  756. * },
  757. * },
  758. * ToUUID("dbb8e3e6-5886-4ba6-8795-1319f52a966b"),
  759. * Package () {
  760. * Package () { "port0", "PRT0" },
  761. * }
  762. * })
  763. * Name (PRT0, Package() {
  764. * ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
  765. * Package () {
  766. * Package () { "port", 0 },
  767. * },
  768. * ToUUID("dbb8e3e6-5886-4ba6-8795-1319f52a966b"),
  769. * Package () {
  770. * Package () { "endpoint0", "EP00" },
  771. * }
  772. * })
  773. * Name (EP00, Package() {
  774. * ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
  775. * Package () {
  776. * Package () { "endpoint", 0 },
  777. * Package () {
  778. * "remote-endpoint",
  779. * Package() {
  780. * \_SB.PCI0.ISP, 4, 0
  781. * }
  782. * },
  783. * }
  784. * })
  785. * }
  786. * }
  787. *
  788. * Scope (\_SB.PCI0)
  789. * {
  790. * Device (ISP)
  791. * {
  792. * Name (_DSD, Package () {
  793. * ToUUID("dbb8e3e6-5886-4ba6-8795-1319f52a966b"),
  794. * Package () {
  795. * Package () { "port4", "PRT4" },
  796. * }
  797. * })
  798. *
  799. * Name (PRT4, Package() {
  800. * ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
  801. * Package () {
  802. * Package () { "port", 4 },
  803. * },
  804. * ToUUID("dbb8e3e6-5886-4ba6-8795-1319f52a966b"),
  805. * Package () {
  806. * Package () { "endpoint0", "EP40" },
  807. * }
  808. * })
  809. *
  810. * Name (EP40, Package() {
  811. * ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
  812. * Package () {
  813. * Package () { "endpoint", 0 },
  814. * Package () {
  815. * "remote-endpoint",
  816. * Package () {
  817. * \_SB.PCI0.I2C2.CAM0,
  818. * 0, 0
  819. * }
  820. * },
  821. * }
  822. * })
  823. * }
  824. * }
  825. *
  826. * From the EP40 node under ISP device, you could parse the graph remote
  827. * endpoint using v4l2_fwnode_reference_get_int_prop with these arguments:
  828. *
  829. * @fwnode: fwnode referring to EP40 under ISP.
  830. * @prop: "remote-endpoint"
  831. * @index: 0
  832. * @props: "port", "endpoint"
  833. * @nprops: 2
  834. *
  835. * And you'd get back fwnode referring to EP00 under CAM0.
  836. *
  837. * The same works the other way around: if you use EP00 under CAM0 as the
  838. * fwnode, you'll get fwnode referring to EP40 under ISP.
  839. *
  840. * The same example in DT syntax would look like this:
  841. *
  842. * cam: cam0 {
  843. * compatible = "nokia,smia";
  844. *
  845. * port {
  846. * port = <0>;
  847. * endpoint {
  848. * endpoint = <0>;
  849. * remote-endpoint = <&isp 4 0>;
  850. * };
  851. * };
  852. * };
  853. *
  854. * isp: isp {
  855. * ports {
  856. * port@4 {
  857. * port = <4>;
  858. * endpoint {
  859. * endpoint = <0>;
  860. * remote-endpoint = <&cam 0 0>;
  861. * };
  862. * };
  863. * };
  864. * };
  865. *
  866. * Return: 0 on success
  867. * -ENOENT if no entries (or the property itself) were found
  868. * -EINVAL if property parsing otherwise failed
  869. * -ENOMEM if memory allocation failed
  870. */
  871. static struct fwnode_handle *
  872. v4l2_fwnode_reference_get_int_prop(struct fwnode_handle *fwnode,
  873. const char *prop,
  874. unsigned int index,
  875. const char * const *props,
  876. unsigned int nprops)
  877. {
  878. struct fwnode_reference_args fwnode_args;
  879. u64 *args = fwnode_args.args;
  880. struct fwnode_handle *child;
  881. int ret;
  882. /*
  883. * Obtain remote fwnode as well as the integer arguments.
  884. *
  885. * Note that right now both -ENODATA and -ENOENT may signal
  886. * out-of-bounds access. Return -ENOENT in that case.
  887. */
  888. ret = fwnode_property_get_reference_args(fwnode, prop, NULL, nprops,
  889. index, &fwnode_args);
  890. if (ret)
  891. return ERR_PTR(ret == -ENODATA ? -ENOENT : ret);
  892. /*
  893. * Find a node in the tree under the referred fwnode corresponding to
  894. * the integer arguments.
  895. */
  896. fwnode = fwnode_args.fwnode;
  897. while (nprops--) {
  898. u32 val;
  899. /* Loop over all child nodes under fwnode. */
  900. fwnode_for_each_child_node(fwnode, child) {
  901. if (fwnode_property_read_u32(child, *props, &val))
  902. continue;
  903. /* Found property, see if its value matches. */
  904. if (val == *args)
  905. break;
  906. }
  907. fwnode_handle_put(fwnode);
  908. /* No property found; return an error here. */
  909. if (!child) {
  910. fwnode = ERR_PTR(-ENOENT);
  911. break;
  912. }
  913. props++;
  914. args++;
  915. fwnode = child;
  916. }
  917. return fwnode;
  918. }
  919. struct v4l2_fwnode_int_props {
  920. const char *name;
  921. const char * const *props;
  922. unsigned int nprops;
  923. };
  924. /*
  925. * v4l2_fwnode_reference_parse_int_props - parse references for async
  926. * sub-devices
  927. * @dev: struct device pointer
  928. * @notifier: notifier for @dev
  929. * @prop: the name of the property
  930. * @props: the array of integer property names
  931. * @nprops: the number of integer properties
  932. *
  933. * Use v4l2_fwnode_reference_get_int_prop to find fwnodes through reference in
  934. * property @prop with integer arguments with child nodes matching in properties
  935. * @props. Then, set up V4L2 async sub-devices for those fwnodes in the notifier
  936. * accordingly.
  937. *
  938. * While it is technically possible to use this function on DT, it is only
  939. * meaningful on ACPI. On Device tree you can refer to any node in the tree but
  940. * on ACPI the references are limited to devices.
  941. *
  942. * Return: 0 on success
  943. * -ENOENT if no entries (or the property itself) were found
  944. * -EINVAL if property parsing otherwisefailed
  945. * -ENOMEM if memory allocation failed
  946. */
  947. static int
  948. v4l2_fwnode_reference_parse_int_props(struct device *dev,
  949. struct v4l2_async_notifier *notifier,
  950. const struct v4l2_fwnode_int_props *p)
  951. {
  952. struct fwnode_handle *fwnode;
  953. unsigned int index;
  954. int ret;
  955. const char *prop = p->name;
  956. const char * const *props = p->props;
  957. unsigned int nprops = p->nprops;
  958. index = 0;
  959. do {
  960. fwnode = v4l2_fwnode_reference_get_int_prop(dev_fwnode(dev),
  961. prop, index,
  962. props, nprops);
  963. if (IS_ERR(fwnode)) {
  964. /*
  965. * Note that right now both -ENODATA and -ENOENT may
  966. * signal out-of-bounds access. Return the error in
  967. * cases other than that.
  968. */
  969. if (PTR_ERR(fwnode) != -ENOENT &&
  970. PTR_ERR(fwnode) != -ENODATA)
  971. return PTR_ERR(fwnode);
  972. break;
  973. }
  974. fwnode_handle_put(fwnode);
  975. index++;
  976. } while (1);
  977. for (index = 0;
  978. !IS_ERR((fwnode = v4l2_fwnode_reference_get_int_prop(dev_fwnode(dev),
  979. prop, index,
  980. props,
  981. nprops)));
  982. index++) {
  983. struct v4l2_async_connection *asd;
  984. asd = v4l2_async_nf_add_fwnode(notifier, fwnode,
  985. struct v4l2_async_connection);
  986. fwnode_handle_put(fwnode);
  987. if (IS_ERR(asd)) {
  988. ret = PTR_ERR(asd);
  989. /* not an error if asd already exists */
  990. if (ret == -EEXIST)
  991. continue;
  992. return PTR_ERR(asd);
  993. }
  994. }
  995. return !fwnode || PTR_ERR(fwnode) == -ENOENT ? 0 : PTR_ERR(fwnode);
  996. }
  997. /**
  998. * v4l2_async_nf_parse_fwnode_sensor - parse common references on
  999. * sensors for async sub-devices
  1000. * @dev: the device node the properties of which are parsed for references
  1001. * @notifier: the async notifier where the async subdevs will be added
  1002. *
  1003. * Parse common sensor properties for remote devices related to the
  1004. * sensor and set up async sub-devices for them.
  1005. *
  1006. * Any notifier populated using this function must be released with a call to
  1007. * v4l2_async_nf_release() after it has been unregistered and the async
  1008. * sub-devices are no longer in use, even in the case the function returned an
  1009. * error.
  1010. *
  1011. * Return: 0 on success
  1012. * -ENOMEM if memory allocation failed
  1013. * -EINVAL if property parsing failed
  1014. */
  1015. static int
  1016. v4l2_async_nf_parse_fwnode_sensor(struct device *dev,
  1017. struct v4l2_async_notifier *notifier)
  1018. {
  1019. static const char * const led_props[] = { "led" };
  1020. static const struct v4l2_fwnode_int_props props[] = {
  1021. { "flash-leds", led_props, ARRAY_SIZE(led_props) },
  1022. { "mipi-img-flash-leds", },
  1023. { "lens-focus", },
  1024. { "mipi-img-lens-focus", },
  1025. };
  1026. unsigned int i;
  1027. for (i = 0; i < ARRAY_SIZE(props); i++) {
  1028. int ret;
  1029. if (props[i].props && is_acpi_node(dev_fwnode(dev)))
  1030. ret = v4l2_fwnode_reference_parse_int_props(dev,
  1031. notifier,
  1032. &props[i]);
  1033. else
  1034. ret = v4l2_fwnode_reference_parse(dev, notifier,
  1035. props[i].name);
  1036. if (ret && ret != -ENOENT) {
  1037. dev_warn(dev, "parsing property \"%s\" failed (%d)\n",
  1038. props[i].name, ret);
  1039. return ret;
  1040. }
  1041. }
  1042. return 0;
  1043. }
  1044. int v4l2_async_register_subdev_sensor(struct v4l2_subdev *sd)
  1045. {
  1046. struct v4l2_async_notifier *notifier;
  1047. int ret;
  1048. if (WARN_ON(!sd->dev))
  1049. return -ENODEV;
  1050. notifier = kzalloc(sizeof(*notifier), GFP_KERNEL);
  1051. if (!notifier)
  1052. return -ENOMEM;
  1053. v4l2_async_subdev_nf_init(notifier, sd);
  1054. ret = v4l2_subdev_get_privacy_led(sd);
  1055. if (ret < 0)
  1056. goto out_cleanup;
  1057. ret = v4l2_async_nf_parse_fwnode_sensor(sd->dev, notifier);
  1058. if (ret < 0)
  1059. goto out_cleanup;
  1060. ret = v4l2_async_nf_register(notifier);
  1061. if (ret < 0)
  1062. goto out_cleanup;
  1063. ret = v4l2_async_register_subdev(sd);
  1064. if (ret < 0)
  1065. goto out_unregister;
  1066. sd->subdev_notifier = notifier;
  1067. return 0;
  1068. out_unregister:
  1069. v4l2_async_nf_unregister(notifier);
  1070. out_cleanup:
  1071. v4l2_subdev_put_privacy_led(sd);
  1072. v4l2_async_nf_cleanup(notifier);
  1073. kfree(notifier);
  1074. return ret;
  1075. }
  1076. EXPORT_SYMBOL_GPL(v4l2_async_register_subdev_sensor);
  1077. MODULE_DESCRIPTION("V4L2 fwnode binding parsing library");
  1078. MODULE_LICENSE("GPL");
  1079. MODULE_AUTHOR("Sakari Ailus <sakari.ailus@linux.intel.com>");
  1080. MODULE_AUTHOR("Sylwester Nawrocki <s.nawrocki@samsung.com>");
  1081. MODULE_AUTHOR("Guennadi Liakhovetski <g.liakhovetski@gmx.de>");