media-device.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  1. /*
  2. * Media device
  3. *
  4. * Copyright (C) 2010 Nokia Corporation
  5. *
  6. * Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
  7. * Sakari Ailus <sakari.ailus@iki.fi>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #ifndef _MEDIA_DEVICE_H
  23. #define _MEDIA_DEVICE_H
  24. #include <linux/list.h>
  25. #include <linux/mutex.h>
  26. #include <linux/spinlock.h>
  27. #include <media/media-devnode.h>
  28. #include <media/media-entity.h>
  29. /**
  30. * DOC: Media Controller
  31. *
  32. * The media controller userspace API is documented in DocBook format in
  33. * Documentation/DocBook/media/v4l/media-controller.xml. This document focus
  34. * on the kernel-side implementation of the media framework.
  35. *
  36. * * Abstract media device model:
  37. *
  38. * Discovering a device internal topology, and configuring it at runtime, is one
  39. * of the goals of the media framework. To achieve this, hardware devices are
  40. * modelled as an oriented graph of building blocks called entities connected
  41. * through pads.
  42. *
  43. * An entity is a basic media hardware building block. It can correspond to
  44. * a large variety of logical blocks such as physical hardware devices
  45. * (CMOS sensor for instance), logical hardware devices (a building block
  46. * in a System-on-Chip image processing pipeline), DMA channels or physical
  47. * connectors.
  48. *
  49. * A pad is a connection endpoint through which an entity can interact with
  50. * other entities. Data (not restricted to video) produced by an entity
  51. * flows from the entity's output to one or more entity inputs. Pads should
  52. * not be confused with physical pins at chip boundaries.
  53. *
  54. * A link is a point-to-point oriented connection between two pads, either
  55. * on the same entity or on different entities. Data flows from a source
  56. * pad to a sink pad.
  57. *
  58. *
  59. * * Media device:
  60. *
  61. * A media device is represented by a struct &media_device instance, defined in
  62. * include/media/media-device.h. Allocation of the structure is handled by the
  63. * media device driver, usually by embedding the &media_device instance in a
  64. * larger driver-specific structure.
  65. *
  66. * Drivers register media device instances by calling
  67. * __media_device_register() via the macro media_device_register()
  68. * and unregistered by calling
  69. * media_device_unregister().
  70. *
  71. * * Entities, pads and links:
  72. *
  73. * - Entities
  74. *
  75. * Entities are represented by a struct &media_entity instance, defined in
  76. * include/media/media-entity.h. The structure is usually embedded into a
  77. * higher-level structure, such as a v4l2_subdev or video_device instance,
  78. * although drivers can allocate entities directly.
  79. *
  80. * Drivers initialize entity pads by calling
  81. * media_entity_pads_init().
  82. *
  83. * Drivers register entities with a media device by calling
  84. * media_device_register_entity()
  85. * and unregistred by calling
  86. * media_device_unregister_entity().
  87. *
  88. * - Interfaces
  89. *
  90. * Interfaces are represented by a struct &media_interface instance, defined in
  91. * include/media/media-entity.h. Currently, only one type of interface is
  92. * defined: a device node. Such interfaces are represented by a struct
  93. * &media_intf_devnode.
  94. *
  95. * Drivers initialize and create device node interfaces by calling
  96. * media_devnode_create()
  97. * and remove them by calling:
  98. * media_devnode_remove().
  99. *
  100. * - Pads
  101. *
  102. * Pads are represented by a struct &media_pad instance, defined in
  103. * include/media/media-entity.h. Each entity stores its pads in a pads array
  104. * managed by the entity driver. Drivers usually embed the array in a
  105. * driver-specific structure.
  106. *
  107. * Pads are identified by their entity and their 0-based index in the pads
  108. * array.
  109. * Both information are stored in the &media_pad structure, making the
  110. * &media_pad pointer the canonical way to store and pass link references.
  111. *
  112. * Pads have flags that describe the pad capabilities and state.
  113. *
  114. * %MEDIA_PAD_FL_SINK indicates that the pad supports sinking data.
  115. * %MEDIA_PAD_FL_SOURCE indicates that the pad supports sourcing data.
  116. *
  117. * NOTE: One and only one of %MEDIA_PAD_FL_SINK and %MEDIA_PAD_FL_SOURCE must
  118. * be set for each pad.
  119. *
  120. * - Links
  121. *
  122. * Links are represented by a struct &media_link instance, defined in
  123. * include/media/media-entity.h. There are two types of links:
  124. *
  125. * 1. pad to pad links:
  126. *
  127. * Associate two entities via their PADs. Each entity has a list that points
  128. * to all links originating at or targeting any of its pads.
  129. * A given link is thus stored twice, once in the source entity and once in
  130. * the target entity.
  131. *
  132. * Drivers create pad to pad links by calling:
  133. * media_create_pad_link() and remove with media_entity_remove_links().
  134. *
  135. * 2. interface to entity links:
  136. *
  137. * Associate one interface to a Link.
  138. *
  139. * Drivers create interface to entity links by calling:
  140. * media_create_intf_link() and remove with media_remove_intf_links().
  141. *
  142. * NOTE:
  143. *
  144. * Links can only be created after having both ends already created.
  145. *
  146. * Links have flags that describe the link capabilities and state. The
  147. * valid values are described at media_create_pad_link() and
  148. * media_create_intf_link().
  149. *
  150. * Graph traversal:
  151. *
  152. * The media framework provides APIs to iterate over entities in a graph.
  153. *
  154. * To iterate over all entities belonging to a media device, drivers can use
  155. * the media_device_for_each_entity macro, defined in
  156. * include/media/media-device.h.
  157. *
  158. * struct media_entity *entity;
  159. *
  160. * media_device_for_each_entity(entity, mdev) {
  161. * // entity will point to each entity in turn
  162. * ...
  163. * }
  164. *
  165. * Drivers might also need to iterate over all entities in a graph that can be
  166. * reached only through enabled links starting at a given entity. The media
  167. * framework provides a depth-first graph traversal API for that purpose.
  168. *
  169. * Note that graphs with cycles (whether directed or undirected) are *NOT*
  170. * supported by the graph traversal API. To prevent infinite loops, the graph
  171. * traversal code limits the maximum depth to MEDIA_ENTITY_ENUM_MAX_DEPTH,
  172. * currently defined as 16.
  173. *
  174. * Drivers initiate a graph traversal by calling
  175. * media_entity_graph_walk_start()
  176. *
  177. * The graph structure, provided by the caller, is initialized to start graph
  178. * traversal at the given entity.
  179. *
  180. * Drivers can then retrieve the next entity by calling
  181. * media_entity_graph_walk_next()
  182. *
  183. * When the graph traversal is complete the function will return NULL.
  184. *
  185. * Graph traversal can be interrupted at any moment. No cleanup function call
  186. * is required and the graph structure can be freed normally.
  187. *
  188. * Helper functions can be used to find a link between two given pads, or a pad
  189. * connected to another pad through an enabled link
  190. * media_entity_find_link() and media_entity_remote_pad()
  191. *
  192. * Use count and power handling:
  193. *
  194. * Due to the wide differences between drivers regarding power management
  195. * needs, the media controller does not implement power management. However,
  196. * the &media_entity structure includes a use_count field that media drivers
  197. * can use to track the number of users of every entity for power management
  198. * needs.
  199. *
  200. * The &media_entity.@use_count field is owned by media drivers and must not be
  201. * touched by entity drivers. Access to the field must be protected by the
  202. * &media_device.@graph_mutex lock.
  203. *
  204. * Links setup:
  205. *
  206. * Link properties can be modified at runtime by calling
  207. * media_entity_setup_link()
  208. *
  209. * Pipelines and media streams:
  210. *
  211. * When starting streaming, drivers must notify all entities in the pipeline to
  212. * prevent link states from being modified during streaming by calling
  213. * media_entity_pipeline_start().
  214. *
  215. * The function will mark all entities connected to the given entity through
  216. * enabled links, either directly or indirectly, as streaming.
  217. *
  218. * The &media_pipeline instance pointed to by the pipe argument will be stored
  219. * in every entity in the pipeline. Drivers should embed the &media_pipeline
  220. * structure in higher-level pipeline structures and can then access the
  221. * pipeline through the &media_entity pipe field.
  222. *
  223. * Calls to media_entity_pipeline_start() can be nested. The pipeline pointer
  224. * must be identical for all nested calls to the function.
  225. *
  226. * media_entity_pipeline_start() may return an error. In that case, it will
  227. * clean up any of the changes it did by itself.
  228. *
  229. * When stopping the stream, drivers must notify the entities with
  230. * media_entity_pipeline_stop().
  231. *
  232. * If multiple calls to media_entity_pipeline_start() have been made the same
  233. * number of media_entity_pipeline_stop() calls are required to stop streaming.
  234. * The &media_entity pipe field is reset to NULL on the last nested stop call.
  235. *
  236. * Link configuration will fail with -%EBUSY by default if either end of the
  237. * link is a streaming entity. Links that can be modified while streaming must
  238. * be marked with the %MEDIA_LNK_FL_DYNAMIC flag.
  239. *
  240. * If other operations need to be disallowed on streaming entities (such as
  241. * changing entities configuration parameters) drivers can explicitly check the
  242. * media_entity stream_count field to find out if an entity is streaming. This
  243. * operation must be done with the media_device graph_mutex held.
  244. *
  245. * Link validation:
  246. *
  247. * Link validation is performed by media_entity_pipeline_start() for any
  248. * entity which has sink pads in the pipeline. The
  249. * &media_entity.@link_validate() callback is used for that purpose. In
  250. * @link_validate() callback, entity driver should check that the properties of
  251. * the source pad of the connected entity and its own sink pad match. It is up
  252. * to the type of the entity (and in the end, the properties of the hardware)
  253. * what matching actually means.
  254. *
  255. * Subsystems should facilitate link validation by providing subsystem specific
  256. * helper functions to provide easy access for commonly needed information, and
  257. * in the end provide a way to use driver-specific callbacks.
  258. */
  259. struct ida;
  260. struct device;
  261. /**
  262. * struct media_entity_notify - Media Entity Notify
  263. *
  264. * @list: List head
  265. * @notify_data: Input data to invoke the callback
  266. * @notify: Callback function pointer
  267. *
  268. * Drivers may register a callback to take action when
  269. * new entities get registered with the media device.
  270. */
  271. struct media_entity_notify {
  272. struct list_head list;
  273. void *notify_data;
  274. void (*notify)(struct media_entity *entity, void *notify_data);
  275. };
  276. /**
  277. * struct media_device - Media device
  278. * @dev: Parent device
  279. * @devnode: Media device node
  280. * @driver_name: Optional device driver name. If not set, calls to
  281. * %MEDIA_IOC_DEVICE_INFO will return dev->driver->name.
  282. * This is needed for USB drivers for example, as otherwise
  283. * they'll all appear as if the driver name was "usb".
  284. * @model: Device model name
  285. * @serial: Device serial number (optional)
  286. * @bus_info: Unique and stable device location identifier
  287. * @hw_revision: Hardware device revision
  288. * @driver_version: Device driver version
  289. * @topology_version: Monotonic counter for storing the version of the graph
  290. * topology. Should be incremented each time the topology changes.
  291. * @id: Unique ID used on the last registered graph object
  292. * @entity_internal_idx: Unique internal entity ID used by the graph traversal
  293. * algorithms
  294. * @entity_internal_idx_max: Allocated internal entity indices
  295. * @entities: List of registered entities
  296. * @interfaces: List of registered interfaces
  297. * @pads: List of registered pads
  298. * @links: List of registered links
  299. * @entity_notify: List of registered entity_notify callbacks
  300. * @lock: Entities list lock
  301. * @graph_mutex: Entities graph operation lock
  302. * @pm_count_walk: Graph walk for power state walk. Access serialised using
  303. * graph_mutex.
  304. *
  305. * @source_priv: Driver Private data for enable/disable source handlers
  306. * @enable_source: Enable Source Handler function pointer
  307. * @disable_source: Disable Source Handler function pointer
  308. *
  309. * @link_notify: Link state change notification callback
  310. *
  311. * This structure represents an abstract high-level media device. It allows easy
  312. * access to entities and provides basic media device-level support. The
  313. * structure can be allocated directly or embedded in a larger structure.
  314. *
  315. * The parent @dev is a physical device. It must be set before registering the
  316. * media device.
  317. *
  318. * @model is a descriptive model name exported through sysfs. It doesn't have to
  319. * be unique.
  320. *
  321. * @enable_source is a handler to find source entity for the
  322. * sink entity and activate the link between them if source
  323. * entity is free. Drivers should call this handler before
  324. * accessing the source.
  325. *
  326. * @disable_source is a handler to find source entity for the
  327. * sink entity and deactivate the link between them. Drivers
  328. * should call this handler to release the source.
  329. *
  330. * Note: Bridge driver is expected to implement and set the
  331. * handler when media_device is registered or when
  332. * bridge driver finds the media_device during probe.
  333. * Bridge driver sets source_priv with information
  334. * necessary to run enable/disable source handlers.
  335. *
  336. * Use-case: find tuner entity connected to the decoder
  337. * entity and check if it is available, and activate the
  338. * the link between them from enable_source and deactivate
  339. * from disable_source.
  340. */
  341. struct media_device {
  342. /* dev->driver_data points to this struct. */
  343. struct device *dev;
  344. struct media_devnode devnode;
  345. char model[32];
  346. char driver_name[32];
  347. char serial[40];
  348. char bus_info[32];
  349. u32 hw_revision;
  350. u32 driver_version;
  351. u64 topology_version;
  352. u32 id;
  353. struct ida entity_internal_idx;
  354. int entity_internal_idx_max;
  355. struct list_head entities;
  356. struct list_head interfaces;
  357. struct list_head pads;
  358. struct list_head links;
  359. /* notify callback list invoked when a new entity is registered */
  360. struct list_head entity_notify;
  361. /* Protects the graph objects creation/removal */
  362. spinlock_t lock;
  363. /* Serializes graph operations. */
  364. struct mutex graph_mutex;
  365. struct media_entity_graph pm_count_walk;
  366. void *source_priv;
  367. int (*enable_source)(struct media_entity *entity,
  368. struct media_pipeline *pipe);
  369. void (*disable_source)(struct media_entity *entity);
  370. int (*link_notify)(struct media_link *link, u32 flags,
  371. unsigned int notification);
  372. };
  373. /* We don't need to include pci.h or usb.h here */
  374. struct pci_dev;
  375. struct usb_device;
  376. #ifdef CONFIG_MEDIA_CONTROLLER
  377. /* Supported link_notify @notification values. */
  378. #define MEDIA_DEV_NOTIFY_PRE_LINK_CH 0
  379. #define MEDIA_DEV_NOTIFY_POST_LINK_CH 1
  380. /* media_devnode to media_device */
  381. #define to_media_device(node) container_of(node, struct media_device, devnode)
  382. /**
  383. * media_entity_enum_init - Initialise an entity enumeration
  384. *
  385. * @ent_enum: Entity enumeration to be initialised
  386. * @mdev: The related media device
  387. *
  388. * Returns zero on success or a negative error code.
  389. */
  390. static inline __must_check int media_entity_enum_init(
  391. struct media_entity_enum *ent_enum, struct media_device *mdev)
  392. {
  393. return __media_entity_enum_init(ent_enum,
  394. mdev->entity_internal_idx_max + 1);
  395. }
  396. /**
  397. * media_device_init() - Initializes a media device element
  398. *
  399. * @mdev: pointer to struct &media_device
  400. *
  401. * This function initializes the media device prior to its registration.
  402. * The media device initialization and registration is split in two functions
  403. * to avoid race conditions and make the media device available to user-space
  404. * before the media graph has been completed.
  405. *
  406. * So drivers need to first initialize the media device, register any entity
  407. * within the media device, create pad to pad links and then finally register
  408. * the media device by calling media_device_register() as a final step.
  409. */
  410. void media_device_init(struct media_device *mdev);
  411. /**
  412. * media_device_cleanup() - Cleanups a media device element
  413. *
  414. * @mdev: pointer to struct &media_device
  415. *
  416. * This function that will destroy the graph_mutex that is
  417. * initialized in media_device_init().
  418. */
  419. void media_device_cleanup(struct media_device *mdev);
  420. /**
  421. * __media_device_register() - Registers a media device element
  422. *
  423. * @mdev: pointer to struct &media_device
  424. * @owner: should be filled with %THIS_MODULE
  425. *
  426. * Users, should, instead, call the media_device_register() macro.
  427. *
  428. * The caller is responsible for initializing the media_device structure before
  429. * registration. The following fields must be set:
  430. *
  431. * - dev must point to the parent device (usually a &pci_dev, &usb_interface or
  432. * &platform_device instance).
  433. *
  434. * - model must be filled with the device model name as a NUL-terminated UTF-8
  435. * string. The device/model revision must not be stored in this field.
  436. *
  437. * The following fields are optional:
  438. *
  439. * - serial is a unique serial number stored as a NUL-terminated ASCII string.
  440. * The field is big enough to store a GUID in text form. If the hardware
  441. * doesn't provide a unique serial number this field must be left empty.
  442. *
  443. * - bus_info represents the location of the device in the system as a
  444. * NUL-terminated ASCII string. For PCI/PCIe devices bus_info must be set to
  445. * "PCI:" (or "PCIe:") followed by the value of pci_name(). For USB devices,
  446. * the usb_make_path() function must be used. This field is used by
  447. * applications to distinguish between otherwise identical devices that don't
  448. * provide a serial number.
  449. *
  450. * - hw_revision is the hardware device revision in a driver-specific format.
  451. * When possible the revision should be formatted with the KERNEL_VERSION
  452. * macro.
  453. *
  454. * - driver_version is formatted with the KERNEL_VERSION macro. The version
  455. * minor must be incremented when new features are added to the userspace API
  456. * without breaking binary compatibility. The version major must be
  457. * incremented when binary compatibility is broken.
  458. *
  459. * Notes:
  460. *
  461. * Upon successful registration a character device named media[0-9]+ is created.
  462. * The device major and minor numbers are dynamic. The model name is exported as
  463. * a sysfs attribute.
  464. *
  465. * Unregistering a media device that hasn't been registered is *NOT* safe.
  466. *
  467. * Return: returns zero on success or a negative error code.
  468. */
  469. int __must_check __media_device_register(struct media_device *mdev,
  470. struct module *owner);
  471. #define media_device_register(mdev) __media_device_register(mdev, THIS_MODULE)
  472. /**
  473. * media_device_unregister() - Unregisters a media device element
  474. *
  475. * @mdev: pointer to struct &media_device
  476. *
  477. *
  478. * It is safe to call this function on an unregistered (but initialised)
  479. * media device.
  480. */
  481. void media_device_unregister(struct media_device *mdev);
  482. /**
  483. * media_device_register_entity() - registers a media entity inside a
  484. * previously registered media device.
  485. *
  486. * @mdev: pointer to struct &media_device
  487. * @entity: pointer to struct &media_entity to be registered
  488. *
  489. * Entities are identified by a unique positive integer ID. The media
  490. * controller framework will such ID automatically. IDs are not guaranteed
  491. * to be contiguous, and the ID number can change on newer Kernel versions.
  492. * So, neither the driver nor userspace should hardcode ID numbers to refer
  493. * to the entities, but, instead, use the framework to find the ID, when
  494. * needed.
  495. *
  496. * The media_entity name, type and flags fields should be initialized before
  497. * calling media_device_register_entity(). Entities embedded in higher-level
  498. * standard structures can have some of those fields set by the higher-level
  499. * framework.
  500. *
  501. * If the device has pads, media_entity_pads_init() should be called before
  502. * this function. Otherwise, the &media_entity.@pad and &media_entity.@num_pads
  503. * should be zeroed before calling this function.
  504. *
  505. * Entities have flags that describe the entity capabilities and state:
  506. *
  507. * %MEDIA_ENT_FL_DEFAULT indicates the default entity for a given type.
  508. * This can be used to report the default audio and video devices or the
  509. * default camera sensor.
  510. *
  511. * NOTE: Drivers should set the entity function before calling this function.
  512. * Please notice that the values %MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN and
  513. * %MEDIA_ENT_F_UNKNOWN should not be used by the drivers.
  514. */
  515. int __must_check media_device_register_entity(struct media_device *mdev,
  516. struct media_entity *entity);
  517. /*
  518. * media_device_unregister_entity() - unregisters a media entity.
  519. *
  520. * @entity: pointer to struct &media_entity to be unregistered
  521. *
  522. * All links associated with the entity and all PADs are automatically
  523. * unregistered from the media_device when this function is called.
  524. *
  525. * Unregistering an entity will not change the IDs of the other entities and
  526. * the previoully used ID will never be reused for a newly registered entities.
  527. *
  528. * When a media device is unregistered, all its entities are unregistered
  529. * automatically. No manual entities unregistration is then required.
  530. *
  531. * Note: the media_entity instance itself must be freed explicitly by
  532. * the driver if required.
  533. */
  534. void media_device_unregister_entity(struct media_entity *entity);
  535. /**
  536. * media_device_register_entity_notify() - Registers a media entity_notify
  537. * callback
  538. *
  539. * @mdev: The media device
  540. * @nptr: The media_entity_notify
  541. *
  542. * Note: When a new entity is registered, all the registered
  543. * media_entity_notify callbacks are invoked.
  544. */
  545. int __must_check media_device_register_entity_notify(struct media_device *mdev,
  546. struct media_entity_notify *nptr);
  547. /**
  548. * media_device_unregister_entity_notify() - Unregister a media entity notify
  549. * callback
  550. *
  551. * @mdev: The media device
  552. * @nptr: The media_entity_notify
  553. *
  554. */
  555. void media_device_unregister_entity_notify(struct media_device *mdev,
  556. struct media_entity_notify *nptr);
  557. /**
  558. * media_device_get_devres() - get media device as device resource
  559. * creates if one doesn't exist
  560. *
  561. * @dev: pointer to struct &device.
  562. *
  563. * Sometimes, the media controller &media_device needs to be shared by more
  564. * than one driver. This function adds support for that, by dynamically
  565. * allocating the &media_device and allowing it to be obtained from the
  566. * struct &device associated with the common device where all sub-device
  567. * components belong. So, for example, on an USB device with multiple
  568. * interfaces, each interface may be handled by a separate per-interface
  569. * drivers. While each interface have its own &device, they all share a
  570. * common &device associated with the hole USB device.
  571. */
  572. struct media_device *media_device_get_devres(struct device *dev);
  573. /**
  574. * media_device_find_devres() - find media device as device resource
  575. *
  576. * @dev: pointer to struct &device.
  577. */
  578. struct media_device *media_device_find_devres(struct device *dev);
  579. /* Iterate over all entities. */
  580. #define media_device_for_each_entity(entity, mdev) \
  581. list_for_each_entry(entity, &(mdev)->entities, graph_obj.list)
  582. /* Iterate over all interfaces. */
  583. #define media_device_for_each_intf(intf, mdev) \
  584. list_for_each_entry(intf, &(mdev)->interfaces, graph_obj.list)
  585. /* Iterate over all pads. */
  586. #define media_device_for_each_pad(pad, mdev) \
  587. list_for_each_entry(pad, &(mdev)->pads, graph_obj.list)
  588. /* Iterate over all links. */
  589. #define media_device_for_each_link(link, mdev) \
  590. list_for_each_entry(link, &(mdev)->links, graph_obj.list)
  591. /**
  592. * media_device_pci_init() - create and initialize a
  593. * struct &media_device from a PCI device.
  594. *
  595. * @mdev: pointer to struct &media_device
  596. * @pci_dev: pointer to struct pci_dev
  597. * @name: media device name. If %NULL, the routine will use the default
  598. * name for the pci device, given by pci_name() macro.
  599. */
  600. void media_device_pci_init(struct media_device *mdev,
  601. struct pci_dev *pci_dev,
  602. const char *name);
  603. /**
  604. * __media_device_usb_init() - create and initialize a
  605. * struct &media_device from a PCI device.
  606. *
  607. * @mdev: pointer to struct &media_device
  608. * @udev: pointer to struct usb_device
  609. * @board_name: media device name. If %NULL, the routine will use the usb
  610. * product name, if available.
  611. * @driver_name: name of the driver. if %NULL, the routine will use the name
  612. * given by udev->dev->driver->name, with is usually the wrong
  613. * thing to do.
  614. *
  615. * NOTE: It is better to call media_device_usb_init() instead, as
  616. * such macro fills driver_name with %KBUILD_MODNAME.
  617. */
  618. void __media_device_usb_init(struct media_device *mdev,
  619. struct usb_device *udev,
  620. const char *board_name,
  621. const char *driver_name);
  622. #else
  623. static inline int media_device_register(struct media_device *mdev)
  624. {
  625. return 0;
  626. }
  627. static inline void media_device_unregister(struct media_device *mdev)
  628. {
  629. }
  630. static inline int media_device_register_entity(struct media_device *mdev,
  631. struct media_entity *entity)
  632. {
  633. return 0;
  634. }
  635. static inline void media_device_unregister_entity(struct media_entity *entity)
  636. {
  637. }
  638. static inline int media_device_register_entity_notify(
  639. struct media_device *mdev,
  640. struct media_entity_notify *nptr)
  641. {
  642. return 0;
  643. }
  644. static inline void media_device_unregister_entity_notify(
  645. struct media_device *mdev,
  646. struct media_entity_notify *nptr)
  647. {
  648. }
  649. static inline struct media_device *media_device_get_devres(struct device *dev)
  650. {
  651. return NULL;
  652. }
  653. static inline struct media_device *media_device_find_devres(struct device *dev)
  654. {
  655. return NULL;
  656. }
  657. static inline void media_device_pci_init(struct media_device *mdev,
  658. struct pci_dev *pci_dev,
  659. char *name)
  660. {
  661. }
  662. static inline void __media_device_usb_init(struct media_device *mdev,
  663. struct usb_device *udev,
  664. char *board_name,
  665. char *driver_name)
  666. {
  667. }
  668. #endif /* CONFIG_MEDIA_CONTROLLER */
  669. #define media_device_usb_init(mdev, udev, name) \
  670. __media_device_usb_init(mdev, udev, name, KBUILD_MODNAME)
  671. #endif