Commit | Line | Data |
---|---|---|
176fb0d1 LP |
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 | ||
176fb0d1 | 26 | #include <linux/list.h> |
503c3d82 | 27 | #include <linux/mutex.h> |
53e269c1 | 28 | #include <linux/spinlock.h> |
176fb0d1 LP |
29 | |
30 | #include <media/media-devnode.h> | |
53e269c1 | 31 | #include <media/media-entity.h> |
176fb0d1 | 32 | |
313162d0 PG |
33 | struct device; |
34 | ||
176fb0d1 LP |
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 | |
bfab2aac | 44 | * @entity_id: Unique ID used on the last entity registered |
18710dc6 | 45 | * @pad_id: Unique ID used on the last pad registered |
6b6a4278 | 46 | * @link_id: Unique ID used on the last link registered |
27e543fa | 47 | * @intf_devnode_id: Unique ID used on the last interface devnode registered |
53e269c1 | 48 | * @entities: List of registered entities |
57cf79b7 | 49 | * @interfaces: List of registered interfaces |
9155d859 MCC |
50 | * @pads: List of registered pads |
51 | * @links: List of registered links | |
53e269c1 | 52 | * @lock: Entities list lock |
503c3d82 | 53 | * @graph_mutex: Entities graph operation lock |
813f5c0a | 54 | * @link_notify: Link state change notification callback |
176fb0d1 LP |
55 | * |
56 | * This structure represents an abstract high-level media device. It allows easy | |
57 | * access to entities and provides basic media device-level support. The | |
58 | * structure can be allocated directly or embedded in a larger structure. | |
59 | * | |
60 | * The parent @dev is a physical device. It must be set before registering the | |
61 | * media device. | |
62 | * | |
63 | * @model is a descriptive model name exported through sysfs. It doesn't have to | |
64 | * be unique. | |
65 | */ | |
66 | struct media_device { | |
67 | /* dev->driver_data points to this struct. */ | |
68 | struct device *dev; | |
69 | struct media_devnode devnode; | |
70 | ||
71 | char model[32]; | |
72 | char serial[40]; | |
73 | char bus_info[32]; | |
74 | u32 hw_revision; | |
75 | u32 driver_version; | |
53e269c1 LP |
76 | |
77 | u32 entity_id; | |
18710dc6 | 78 | u32 pad_id; |
6b6a4278 | 79 | u32 link_id; |
27e543fa | 80 | u32 intf_devnode_id; |
bfab2aac | 81 | |
53e269c1 | 82 | struct list_head entities; |
57cf79b7 | 83 | struct list_head interfaces; |
9155d859 MCC |
84 | struct list_head pads; |
85 | struct list_head links; | |
53e269c1 LP |
86 | |
87 | /* Protects the entities list */ | |
88 | spinlock_t lock; | |
503c3d82 LP |
89 | /* Serializes graph operations. */ |
90 | struct mutex graph_mutex; | |
97548ed4 | 91 | |
813f5c0a SN |
92 | int (*link_notify)(struct media_link *link, u32 flags, |
93 | unsigned int notification); | |
176fb0d1 LP |
94 | }; |
95 | ||
e576d60b SK |
96 | #ifdef CONFIG_MEDIA_CONTROLLER |
97 | ||
813f5c0a SN |
98 | /* Supported link_notify @notification values. */ |
99 | #define MEDIA_DEV_NOTIFY_PRE_LINK_CH 0 | |
100 | #define MEDIA_DEV_NOTIFY_POST_LINK_CH 1 | |
101 | ||
176fb0d1 LP |
102 | /* media_devnode to media_device */ |
103 | #define to_media_device(node) container_of(node, struct media_device, devnode) | |
104 | ||
85de721c SA |
105 | int __must_check __media_device_register(struct media_device *mdev, |
106 | struct module *owner); | |
107 | #define media_device_register(mdev) __media_device_register(mdev, THIS_MODULE) | |
176fb0d1 LP |
108 | void media_device_unregister(struct media_device *mdev); |
109 | ||
53e269c1 LP |
110 | int __must_check media_device_register_entity(struct media_device *mdev, |
111 | struct media_entity *entity); | |
112 | void media_device_unregister_entity(struct media_entity *entity); | |
d062f911 SK |
113 | struct media_device *media_device_get_devres(struct device *dev); |
114 | struct media_device *media_device_find_devres(struct device *dev); | |
53e269c1 LP |
115 | |
116 | /* Iterate over all entities. */ | |
117 | #define media_device_for_each_entity(entity, mdev) \ | |
05bfa9fa | 118 | list_for_each_entry(entity, &(mdev)->entities, graph_obj.list) |
53e269c1 | 119 | |
cf975a4b MCC |
120 | /* Iterate over all interfaces. */ |
121 | #define media_device_for_each_intf(intf, mdev) \ | |
05bfa9fa | 122 | list_for_each_entry(intf, &(mdev)->interfaces, graph_obj.list) |
cf975a4b | 123 | |
9155d859 MCC |
124 | /* Iterate over all pads. */ |
125 | #define media_device_for_each_pad(pad, mdev) \ | |
126 | list_for_each_entry(pad, &(mdev)->pads, graph_obj.list) | |
127 | ||
128 | /* Iterate over all links. */ | |
129 | #define media_device_for_each_link(link, mdev) \ | |
130 | list_for_each_entry(link, &(mdev)->links, graph_obj.list) | |
131 | ||
cf975a4b | 132 | |
e576d60b SK |
133 | #else |
134 | static inline int media_device_register(struct media_device *mdev) | |
135 | { | |
136 | return 0; | |
137 | } | |
138 | static inline void media_device_unregister(struct media_device *mdev) | |
139 | { | |
140 | } | |
141 | static inline int media_device_register_entity(struct media_device *mdev, | |
142 | struct media_entity *entity) | |
143 | { | |
144 | return 0; | |
145 | } | |
146 | static inline void media_device_unregister_entity(struct media_entity *entity) | |
147 | { | |
148 | } | |
149 | static inline struct media_device *media_device_get_devres(struct device *dev) | |
150 | { | |
151 | return NULL; | |
152 | } | |
153 | static inline struct media_device *media_device_find_devres(struct device *dev) | |
154 | { | |
155 | return NULL; | |
156 | } | |
157 | #endif /* CONFIG_MEDIA_CONTROLLER */ | |
176fb0d1 | 158 | #endif |