Laurent Pinchart | 176fb0d | 2009-12-09 08:39:58 -0300 | [diff] [blame] | 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 | |
| 23 | #ifndef _MEDIA_DEVICE_H |
| 24 | #define _MEDIA_DEVICE_H |
| 25 | |
Laurent Pinchart | 176fb0d | 2009-12-09 08:39:58 -0300 | [diff] [blame] | 26 | #include <linux/list.h> |
Laurent Pinchart | 503c3d82 | 2010-03-07 15:04:59 -0300 | [diff] [blame] | 27 | #include <linux/mutex.h> |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 28 | #include <linux/spinlock.h> |
Laurent Pinchart | 176fb0d | 2009-12-09 08:39:58 -0300 | [diff] [blame] | 29 | |
| 30 | #include <media/media-devnode.h> |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 31 | #include <media/media-entity.h> |
Laurent Pinchart | 176fb0d | 2009-12-09 08:39:58 -0300 | [diff] [blame] | 32 | |
Paul Gortmaker | 313162d | 2012-01-30 11:46:54 -0500 | [diff] [blame] | 33 | struct device; |
| 34 | |
Laurent Pinchart | 176fb0d | 2009-12-09 08:39:58 -0300 | [diff] [blame] | 35 | /** |
| 36 | * struct media_device - Media device |
| 37 | * @dev: Parent device |
| 38 | * @devnode: Media device node |
| 39 | * @model: Device model name |
| 40 | * @serial: Device serial number (optional) |
| 41 | * @bus_info: Unique and stable device location identifier |
| 42 | * @hw_revision: Hardware device revision |
| 43 | * @driver_version: Device driver version |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 44 | * @entity_id: ID of the next entity to be registered |
| 45 | * @entities: List of registered entities |
| 46 | * @lock: Entities list lock |
Laurent Pinchart | 503c3d82 | 2010-03-07 15:04:59 -0300 | [diff] [blame] | 47 | * @graph_mutex: Entities graph operation lock |
Sylwester Nawrocki | 813f5c0 | 2013-05-31 10:37:26 -0300 | [diff] [blame] | 48 | * @link_notify: Link state change notification callback |
Laurent Pinchart | 176fb0d | 2009-12-09 08:39:58 -0300 | [diff] [blame] | 49 | * |
| 50 | * This structure represents an abstract high-level media device. It allows easy |
| 51 | * access to entities and provides basic media device-level support. The |
| 52 | * structure can be allocated directly or embedded in a larger structure. |
| 53 | * |
| 54 | * The parent @dev is a physical device. It must be set before registering the |
| 55 | * media device. |
| 56 | * |
| 57 | * @model is a descriptive model name exported through sysfs. It doesn't have to |
| 58 | * be unique. |
| 59 | */ |
| 60 | struct media_device { |
| 61 | /* dev->driver_data points to this struct. */ |
| 62 | struct device *dev; |
| 63 | struct media_devnode devnode; |
| 64 | |
| 65 | char model[32]; |
| 66 | char serial[40]; |
| 67 | char bus_info[32]; |
| 68 | u32 hw_revision; |
| 69 | u32 driver_version; |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 70 | |
| 71 | u32 entity_id; |
| 72 | struct list_head entities; |
| 73 | |
| 74 | /* Protects the entities list */ |
| 75 | spinlock_t lock; |
Laurent Pinchart | 503c3d82 | 2010-03-07 15:04:59 -0300 | [diff] [blame] | 76 | /* Serializes graph operations. */ |
| 77 | struct mutex graph_mutex; |
Laurent Pinchart | 97548ed | 2009-12-09 08:40:03 -0300 | [diff] [blame] | 78 | |
Sylwester Nawrocki | 813f5c0 | 2013-05-31 10:37:26 -0300 | [diff] [blame] | 79 | int (*link_notify)(struct media_link *link, u32 flags, |
| 80 | unsigned int notification); |
Laurent Pinchart | 176fb0d | 2009-12-09 08:39:58 -0300 | [diff] [blame] | 81 | }; |
| 82 | |
Sylwester Nawrocki | 813f5c0 | 2013-05-31 10:37:26 -0300 | [diff] [blame] | 83 | /* Supported link_notify @notification values. */ |
| 84 | #define MEDIA_DEV_NOTIFY_PRE_LINK_CH 0 |
| 85 | #define MEDIA_DEV_NOTIFY_POST_LINK_CH 1 |
| 86 | |
Laurent Pinchart | 176fb0d | 2009-12-09 08:39:58 -0300 | [diff] [blame] | 87 | /* media_devnode to media_device */ |
| 88 | #define to_media_device(node) container_of(node, struct media_device, devnode) |
| 89 | |
| 90 | int __must_check media_device_register(struct media_device *mdev); |
| 91 | void media_device_unregister(struct media_device *mdev); |
| 92 | |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 93 | int __must_check media_device_register_entity(struct media_device *mdev, |
| 94 | struct media_entity *entity); |
| 95 | void media_device_unregister_entity(struct media_entity *entity); |
| 96 | |
| 97 | /* Iterate over all entities. */ |
| 98 | #define media_device_for_each_entity(entity, mdev) \ |
| 99 | list_for_each_entry(entity, &(mdev)->entities, list) |
| 100 | |
Laurent Pinchart | 176fb0d | 2009-12-09 08:39:58 -0300 | [diff] [blame] | 101 | #endif |