v4l2-fwnode.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * V4L2 fwnode binding parsing library
  4. *
  5. * Copyright (c) 2016 Intel Corporation.
  6. * Author: Sakari Ailus <[email protected]>
  7. *
  8. * Copyright (C) 2012 - 2013 Samsung Electronics Co., Ltd.
  9. * Author: Sylwester Nawrocki <[email protected]>
  10. *
  11. * Copyright (C) 2012 Renesas Electronics Corp.
  12. * Author: Guennadi Liakhovetski <[email protected]>
  13. */
  14. #ifndef _V4L2_FWNODE_H
  15. #define _V4L2_FWNODE_H
  16. #include <linux/errno.h>
  17. #include <linux/fwnode.h>
  18. #include <linux/list.h>
  19. #include <linux/types.h>
  20. #include <media/v4l2-mediabus.h>
  21. struct fwnode_handle;
  22. struct v4l2_async_notifier;
  23. struct v4l2_async_subdev;
  24. /**
  25. * struct v4l2_fwnode_endpoint - the endpoint data structure
  26. * @base: fwnode endpoint of the v4l2_fwnode
  27. * @bus_type: bus type
  28. * @bus: bus configuration data structure
  29. * @bus.parallel: embedded &struct v4l2_mbus_config_parallel.
  30. * Used if the bus is parallel.
  31. * @bus.mipi_csi1: embedded &struct v4l2_mbus_config_mipi_csi1.
  32. * Used if the bus is MIPI Alliance's Camera Serial
  33. * Interface version 1 (MIPI CSI1) or Standard
  34. * Mobile Imaging Architecture's Compact Camera Port 2
  35. * (SMIA CCP2).
  36. * @bus.mipi_csi2: embedded &struct v4l2_mbus_config_mipi_csi2.
  37. * Used if the bus is MIPI Alliance's Camera Serial
  38. * Interface version 2 (MIPI CSI2).
  39. * @link_frequencies: array of supported link frequencies
  40. * @nr_of_link_frequencies: number of elements in link_frequenccies array
  41. */
  42. struct v4l2_fwnode_endpoint {
  43. struct fwnode_endpoint base;
  44. enum v4l2_mbus_type bus_type;
  45. struct {
  46. struct v4l2_mbus_config_parallel parallel;
  47. struct v4l2_mbus_config_mipi_csi1 mipi_csi1;
  48. struct v4l2_mbus_config_mipi_csi2 mipi_csi2;
  49. } bus;
  50. u64 *link_frequencies;
  51. unsigned int nr_of_link_frequencies;
  52. };
  53. /**
  54. * V4L2_FWNODE_PROPERTY_UNSET - identify a non initialized property
  55. *
  56. * All properties in &struct v4l2_fwnode_device_properties are initialized
  57. * to this value.
  58. */
  59. #define V4L2_FWNODE_PROPERTY_UNSET (-1U)
  60. /**
  61. * enum v4l2_fwnode_orientation - possible device orientation
  62. * @V4L2_FWNODE_ORIENTATION_FRONT: device installed on the front side
  63. * @V4L2_FWNODE_ORIENTATION_BACK: device installed on the back side
  64. * @V4L2_FWNODE_ORIENTATION_EXTERNAL: device externally located
  65. */
  66. enum v4l2_fwnode_orientation {
  67. V4L2_FWNODE_ORIENTATION_FRONT,
  68. V4L2_FWNODE_ORIENTATION_BACK,
  69. V4L2_FWNODE_ORIENTATION_EXTERNAL
  70. };
  71. /**
  72. * struct v4l2_fwnode_device_properties - fwnode device properties
  73. * @orientation: device orientation. See &enum v4l2_fwnode_orientation
  74. * @rotation: device rotation
  75. */
  76. struct v4l2_fwnode_device_properties {
  77. enum v4l2_fwnode_orientation orientation;
  78. unsigned int rotation;
  79. };
  80. /**
  81. * struct v4l2_fwnode_link - a link between two endpoints
  82. * @local_node: pointer to device_node of this endpoint
  83. * @local_port: identifier of the port this endpoint belongs to
  84. * @local_id: identifier of the id this endpoint belongs to
  85. * @remote_node: pointer to device_node of the remote endpoint
  86. * @remote_port: identifier of the port the remote endpoint belongs to
  87. * @remote_id: identifier of the id the remote endpoint belongs to
  88. */
  89. struct v4l2_fwnode_link {
  90. struct fwnode_handle *local_node;
  91. unsigned int local_port;
  92. unsigned int local_id;
  93. struct fwnode_handle *remote_node;
  94. unsigned int remote_port;
  95. unsigned int remote_id;
  96. };
  97. /**
  98. * enum v4l2_connector_type - connector type
  99. * @V4L2_CONN_UNKNOWN: unknown connector type, no V4L2 connector configuration
  100. * @V4L2_CONN_COMPOSITE: analog composite connector
  101. * @V4L2_CONN_SVIDEO: analog svideo connector
  102. */
  103. enum v4l2_connector_type {
  104. V4L2_CONN_UNKNOWN,
  105. V4L2_CONN_COMPOSITE,
  106. V4L2_CONN_SVIDEO,
  107. };
  108. /**
  109. * struct v4l2_connector_link - connector link data structure
  110. * @head: structure to be used to add the link to the
  111. * &struct v4l2_fwnode_connector
  112. * @fwnode_link: &struct v4l2_fwnode_link link between the connector and the
  113. * device the connector belongs to.
  114. */
  115. struct v4l2_connector_link {
  116. struct list_head head;
  117. struct v4l2_fwnode_link fwnode_link;
  118. };
  119. /**
  120. * struct v4l2_fwnode_connector_analog - analog connector data structure
  121. * @sdtv_stds: sdtv standards this connector supports, set to V4L2_STD_ALL
  122. * if no restrictions are specified.
  123. */
  124. struct v4l2_fwnode_connector_analog {
  125. v4l2_std_id sdtv_stds;
  126. };
  127. /**
  128. * struct v4l2_fwnode_connector - the connector data structure
  129. * @name: the connector device name
  130. * @label: optional connector label
  131. * @type: connector type
  132. * @links: list of all connector &struct v4l2_connector_link links
  133. * @nr_of_links: total number of links
  134. * @connector: connector configuration
  135. * @connector.analog: analog connector configuration
  136. * &struct v4l2_fwnode_connector_analog
  137. */
  138. struct v4l2_fwnode_connector {
  139. const char *name;
  140. const char *label;
  141. enum v4l2_connector_type type;
  142. struct list_head links;
  143. unsigned int nr_of_links;
  144. union {
  145. struct v4l2_fwnode_connector_analog analog;
  146. /* future connectors */
  147. } connector;
  148. };
  149. /**
  150. * enum v4l2_fwnode_bus_type - Video bus types defined by firmware properties
  151. * @V4L2_FWNODE_BUS_TYPE_GUESS: Default value if no bus-type fwnode property
  152. * @V4L2_FWNODE_BUS_TYPE_CSI2_CPHY: MIPI CSI-2 bus, C-PHY physical layer
  153. * @V4L2_FWNODE_BUS_TYPE_CSI1: MIPI CSI-1 bus
  154. * @V4L2_FWNODE_BUS_TYPE_CCP2: SMIA Compact Camera Port 2 bus
  155. * @V4L2_FWNODE_BUS_TYPE_CSI2_DPHY: MIPI CSI-2 bus, D-PHY physical layer
  156. * @V4L2_FWNODE_BUS_TYPE_PARALLEL: Camera Parallel Interface bus
  157. * @V4L2_FWNODE_BUS_TYPE_BT656: BT.656 video format bus-type
  158. * @V4L2_FWNODE_BUS_TYPE_DPI: Video Parallel Interface bus
  159. * @NR_OF_V4L2_FWNODE_BUS_TYPE: Number of bus-types
  160. */
  161. enum v4l2_fwnode_bus_type {
  162. V4L2_FWNODE_BUS_TYPE_GUESS = 0,
  163. V4L2_FWNODE_BUS_TYPE_CSI2_CPHY,
  164. V4L2_FWNODE_BUS_TYPE_CSI1,
  165. V4L2_FWNODE_BUS_TYPE_CCP2,
  166. V4L2_FWNODE_BUS_TYPE_CSI2_DPHY,
  167. V4L2_FWNODE_BUS_TYPE_PARALLEL,
  168. V4L2_FWNODE_BUS_TYPE_BT656,
  169. V4L2_FWNODE_BUS_TYPE_DPI,
  170. NR_OF_V4L2_FWNODE_BUS_TYPE
  171. };
  172. /**
  173. * v4l2_fwnode_endpoint_parse() - parse all fwnode node properties
  174. * @fwnode: pointer to the endpoint's fwnode handle
  175. * @vep: pointer to the V4L2 fwnode data structure
  176. *
  177. * This function parses the V4L2 fwnode endpoint specific parameters from the
  178. * firmware. There are two ways to use this function, either by letting it
  179. * obtain the type of the bus (by setting the @vep.bus_type field to
  180. * V4L2_MBUS_UNKNOWN) or specifying the bus type explicitly to one of the &enum
  181. * v4l2_mbus_type types.
  182. *
  183. * When @vep.bus_type is V4L2_MBUS_UNKNOWN, the function will use the "bus-type"
  184. * property to determine the type when it is available. The caller is
  185. * responsible for validating the contents of @vep.bus_type field after the call
  186. * returns.
  187. *
  188. * As a deprecated functionality to support older DT bindings without "bus-type"
  189. * property for devices that support multiple types, if the "bus-type" property
  190. * does not exist, the function will attempt to guess the type based on the
  191. * endpoint properties available. NEVER RELY ON GUESSING THE BUS TYPE IN NEW
  192. * DRIVERS OR BINDINGS.
  193. *
  194. * It is also possible to set @vep.bus_type corresponding to an actual bus. In
  195. * this case the function will only attempt to parse properties related to this
  196. * bus, and it will return an error if the value of the "bus-type" property
  197. * corresponds to a different bus.
  198. *
  199. * The caller is required to initialise all fields of @vep, either with
  200. * explicitly values, or by zeroing them.
  201. *
  202. * The function does not change the V4L2 fwnode endpoint state if it fails.
  203. *
  204. * NOTE: This function does not parse "link-frequencies" property as its size is
  205. * not known in advance. Please use v4l2_fwnode_endpoint_alloc_parse() if you
  206. * need properties of variable size.
  207. *
  208. * Return: %0 on success or a negative error code on failure:
  209. * %-ENOMEM on memory allocation failure
  210. * %-EINVAL on parsing failure
  211. * %-ENXIO on mismatching bus types
  212. */
  213. int v4l2_fwnode_endpoint_parse(struct fwnode_handle *fwnode,
  214. struct v4l2_fwnode_endpoint *vep);
  215. /**
  216. * v4l2_fwnode_endpoint_free() - free the V4L2 fwnode acquired by
  217. * v4l2_fwnode_endpoint_alloc_parse()
  218. * @vep: the V4L2 fwnode the resources of which are to be released
  219. *
  220. * It is safe to call this function with NULL argument or on a V4L2 fwnode the
  221. * parsing of which failed.
  222. */
  223. void v4l2_fwnode_endpoint_free(struct v4l2_fwnode_endpoint *vep);
  224. /**
  225. * v4l2_fwnode_endpoint_alloc_parse() - parse all fwnode node properties
  226. * @fwnode: pointer to the endpoint's fwnode handle
  227. * @vep: pointer to the V4L2 fwnode data structure
  228. *
  229. * This function parses the V4L2 fwnode endpoint specific parameters from the
  230. * firmware. There are two ways to use this function, either by letting it
  231. * obtain the type of the bus (by setting the @vep.bus_type field to
  232. * V4L2_MBUS_UNKNOWN) or specifying the bus type explicitly to one of the &enum
  233. * v4l2_mbus_type types.
  234. *
  235. * When @vep.bus_type is V4L2_MBUS_UNKNOWN, the function will use the "bus-type"
  236. * property to determine the type when it is available. The caller is
  237. * responsible for validating the contents of @vep.bus_type field after the call
  238. * returns.
  239. *
  240. * As a deprecated functionality to support older DT bindings without "bus-type"
  241. * property for devices that support multiple types, if the "bus-type" property
  242. * does not exist, the function will attempt to guess the type based on the
  243. * endpoint properties available. NEVER RELY ON GUESSING THE BUS TYPE IN NEW
  244. * DRIVERS OR BINDINGS.
  245. *
  246. * It is also possible to set @vep.bus_type corresponding to an actual bus. In
  247. * this case the function will only attempt to parse properties related to this
  248. * bus, and it will return an error if the value of the "bus-type" property
  249. * corresponds to a different bus.
  250. *
  251. * The caller is required to initialise all fields of @vep, either with
  252. * explicitly values, or by zeroing them.
  253. *
  254. * The function does not change the V4L2 fwnode endpoint state if it fails.
  255. *
  256. * v4l2_fwnode_endpoint_alloc_parse() has two important differences to
  257. * v4l2_fwnode_endpoint_parse():
  258. *
  259. * 1. It also parses variable size data.
  260. *
  261. * 2. The memory it has allocated to store the variable size data must be freed
  262. * using v4l2_fwnode_endpoint_free() when no longer needed.
  263. *
  264. * Return: %0 on success or a negative error code on failure:
  265. * %-ENOMEM on memory allocation failure
  266. * %-EINVAL on parsing failure
  267. * %-ENXIO on mismatching bus types
  268. */
  269. int v4l2_fwnode_endpoint_alloc_parse(struct fwnode_handle *fwnode,
  270. struct v4l2_fwnode_endpoint *vep);
  271. /**
  272. * v4l2_fwnode_parse_link() - parse a link between two endpoints
  273. * @fwnode: pointer to the endpoint's fwnode at the local end of the link
  274. * @link: pointer to the V4L2 fwnode link data structure
  275. *
  276. * Fill the link structure with the local and remote nodes and port numbers.
  277. * The local_node and remote_node fields are set to point to the local and
  278. * remote port's parent nodes respectively (the port parent node being the
  279. * parent node of the port node if that node isn't a 'ports' node, or the
  280. * grand-parent node of the port node otherwise).
  281. *
  282. * A reference is taken to both the local and remote nodes, the caller must use
  283. * v4l2_fwnode_put_link() to drop the references when done with the
  284. * link.
  285. *
  286. * Return: 0 on success, or -ENOLINK if the remote endpoint fwnode can't be
  287. * found.
  288. */
  289. int v4l2_fwnode_parse_link(struct fwnode_handle *fwnode,
  290. struct v4l2_fwnode_link *link);
  291. /**
  292. * v4l2_fwnode_put_link() - drop references to nodes in a link
  293. * @link: pointer to the V4L2 fwnode link data structure
  294. *
  295. * Drop references to the local and remote nodes in the link. This function
  296. * must be called on every link parsed with v4l2_fwnode_parse_link().
  297. */
  298. void v4l2_fwnode_put_link(struct v4l2_fwnode_link *link);
  299. /**
  300. * v4l2_fwnode_connector_free() - free the V4L2 connector acquired memory
  301. * @connector: the V4L2 connector resources of which are to be released
  302. *
  303. * Free all allocated memory and put all links acquired by
  304. * v4l2_fwnode_connector_parse() and v4l2_fwnode_connector_add_link().
  305. *
  306. * It is safe to call this function with NULL argument or on a V4L2 connector
  307. * the parsing of which failed.
  308. */
  309. void v4l2_fwnode_connector_free(struct v4l2_fwnode_connector *connector);
  310. /**
  311. * v4l2_fwnode_connector_parse() - initialize the 'struct v4l2_fwnode_connector'
  312. * @fwnode: pointer to the subdev endpoint's fwnode handle where the connector
  313. * is connected to or to the connector endpoint fwnode handle.
  314. * @connector: pointer to the V4L2 fwnode connector data structure
  315. *
  316. * Fill the &struct v4l2_fwnode_connector with the connector type, label and
  317. * all &enum v4l2_connector_type specific connector data. The label is optional
  318. * so it is set to %NULL if no one was found. The function initialize the links
  319. * to zero. Adding links to the connector is done by calling
  320. * v4l2_fwnode_connector_add_link().
  321. *
  322. * The memory allocated for the label must be freed when no longer needed.
  323. * Freeing the memory is done by v4l2_fwnode_connector_free().
  324. *
  325. * Return:
  326. * * %0 on success or a negative error code on failure:
  327. * * %-EINVAL if @fwnode is invalid
  328. * * %-ENOTCONN if connector type is unknown or connector device can't be found
  329. */
  330. int v4l2_fwnode_connector_parse(struct fwnode_handle *fwnode,
  331. struct v4l2_fwnode_connector *connector);
  332. /**
  333. * v4l2_fwnode_connector_add_link - add a link between a connector node and
  334. * a v4l2-subdev node.
  335. * @fwnode: pointer to the subdev endpoint's fwnode handle where the connector
  336. * is connected to
  337. * @connector: pointer to the V4L2 fwnode connector data structure
  338. *
  339. * Add a new &struct v4l2_connector_link link to the
  340. * &struct v4l2_fwnode_connector connector links list. The link local_node
  341. * points to the connector node, the remote_node to the host v4l2 (sub)dev.
  342. *
  343. * The taken references to remote_node and local_node must be dropped and the
  344. * allocated memory must be freed when no longer needed. Both is done by calling
  345. * v4l2_fwnode_connector_free().
  346. *
  347. * Return:
  348. * * %0 on success or a negative error code on failure:
  349. * * %-EINVAL if @fwnode or @connector is invalid or @connector type is unknown
  350. * * %-ENOMEM on link memory allocation failure
  351. * * %-ENOTCONN if remote connector device can't be found
  352. * * %-ENOLINK if link parsing between v4l2 (sub)dev and connector fails
  353. */
  354. int v4l2_fwnode_connector_add_link(struct fwnode_handle *fwnode,
  355. struct v4l2_fwnode_connector *connector);
  356. /**
  357. * v4l2_fwnode_device_parse() - parse fwnode device properties
  358. * @dev: pointer to &struct device
  359. * @props: pointer to &struct v4l2_fwnode_device_properties where to store the
  360. * parsed properties values
  361. *
  362. * This function parses and validates the V4L2 fwnode device properties from the
  363. * firmware interface, and fills the @struct v4l2_fwnode_device_properties
  364. * provided by the caller.
  365. *
  366. * Return:
  367. * % 0 on success
  368. * %-EINVAL if a parsed property value is not valid
  369. */
  370. int v4l2_fwnode_device_parse(struct device *dev,
  371. struct v4l2_fwnode_device_properties *props);
  372. /**
  373. * typedef parse_endpoint_func - Driver's callback function to be called on
  374. * each V4L2 fwnode endpoint.
  375. *
  376. * @dev: pointer to &struct device
  377. * @vep: pointer to &struct v4l2_fwnode_endpoint
  378. * @asd: pointer to &struct v4l2_async_subdev
  379. *
  380. * Return:
  381. * * %0 on success
  382. * * %-ENOTCONN if the endpoint is to be skipped but this
  383. * should not be considered as an error
  384. * * %-EINVAL if the endpoint configuration is invalid
  385. */
  386. typedef int (*parse_endpoint_func)(struct device *dev,
  387. struct v4l2_fwnode_endpoint *vep,
  388. struct v4l2_async_subdev *asd);
  389. /**
  390. * v4l2_async_nf_parse_fwnode_endpoints - Parse V4L2 fwnode endpoints in a
  391. * device node
  392. * @dev: the device the endpoints of which are to be parsed
  393. * @notifier: notifier for @dev
  394. * @asd_struct_size: size of the driver's async sub-device struct, including
  395. * sizeof(struct v4l2_async_subdev). The &struct
  396. * v4l2_async_subdev shall be the first member of
  397. * the driver's async sub-device struct, i.e. both
  398. * begin at the same memory address.
  399. * @parse_endpoint: Driver's callback function called on each V4L2 fwnode
  400. * endpoint. Optional.
  401. *
  402. * DEPRECATED! This function is deprecated. Don't use it in new drivers.
  403. * Instead see an example in cio2_parse_firmware() function in
  404. * drivers/media/pci/intel/ipu3/ipu3-cio2.c .
  405. *
  406. * Parse the fwnode endpoints of the @dev device and populate the async sub-
  407. * devices list in the notifier. The @parse_endpoint callback function is
  408. * called for each endpoint with the corresponding async sub-device pointer to
  409. * let the caller initialize the driver-specific part of the async sub-device
  410. * structure.
  411. *
  412. * The notifier memory shall be zeroed before this function is called on the
  413. * notifier.
  414. *
  415. * This function may not be called on a registered notifier and may be called on
  416. * a notifier only once.
  417. *
  418. * The &struct v4l2_fwnode_endpoint passed to the callback function
  419. * @parse_endpoint is released once the function is finished. If there is a need
  420. * to retain that configuration, the user needs to allocate memory for it.
  421. *
  422. * Any notifier populated using this function must be released with a call to
  423. * v4l2_async_nf_cleanup() after it has been unregistered and the async
  424. * sub-devices are no longer in use, even if the function returned an error.
  425. *
  426. * Return: %0 on success, including when no async sub-devices are found
  427. * %-ENOMEM if memory allocation failed
  428. * %-EINVAL if graph or endpoint parsing failed
  429. * Other error codes as returned by @parse_endpoint
  430. */
  431. int
  432. v4l2_async_nf_parse_fwnode_endpoints(struct device *dev,
  433. struct v4l2_async_notifier *notifier,
  434. size_t asd_struct_size,
  435. parse_endpoint_func parse_endpoint);
  436. /* Helper macros to access the connector links. */
  437. /** v4l2_connector_last_link - Helper macro to get the first
  438. * &struct v4l2_fwnode_connector link
  439. * @v4l2c: &struct v4l2_fwnode_connector owning the connector links
  440. *
  441. * This marco returns the first added &struct v4l2_connector_link connector
  442. * link or @NULL if the connector has no links.
  443. */
  444. #define v4l2_connector_first_link(v4l2c) \
  445. list_first_entry_or_null(&(v4l2c)->links, \
  446. struct v4l2_connector_link, head)
  447. /** v4l2_connector_last_link - Helper macro to get the last
  448. * &struct v4l2_fwnode_connector link
  449. * @v4l2c: &struct v4l2_fwnode_connector owning the connector links
  450. *
  451. * This marco returns the last &struct v4l2_connector_link added connector link.
  452. */
  453. #define v4l2_connector_last_link(v4l2c) \
  454. list_last_entry(&(v4l2c)->links, struct v4l2_connector_link, head)
  455. #endif /* _V4L2_FWNODE_H */