blob: 51807efa505b5b988d01bd69ed3e0f1e2aa646e6 [file] [log] [blame]
Laurent Pinchart176fb0d2009-12-09 08:39:58 -03001/*
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 Pinchart176fb0d2009-12-09 08:39:58 -030026#include <linux/list.h>
Laurent Pinchart503c3d822010-03-07 15:04:59 -030027#include <linux/mutex.h>
Laurent Pinchart53e269c2009-12-09 08:40:00 -030028#include <linux/spinlock.h>
Laurent Pinchart176fb0d2009-12-09 08:39:58 -030029
30#include <media/media-devnode.h>
Laurent Pinchart53e269c2009-12-09 08:40:00 -030031#include <media/media-entity.h>
Laurent Pinchart176fb0d2009-12-09 08:39:58 -030032
Paul Gortmaker313162d2012-01-30 11:46:54 -050033struct device;
34
Laurent Pinchart176fb0d2009-12-09 08:39:58 -030035/**
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
Mauro Carvalho Chehabbfab2aac2015-08-14 12:47:48 -030044 * @entity_id: Unique ID used on the last entity registered
Mauro Carvalho Chehab18710dc2015-08-14 12:50:08 -030045 * @pad_id: Unique ID used on the last pad registered
Mauro Carvalho Chehab6b6a4272015-08-14 12:54:36 -030046 * @link_id: Unique ID used on the last link registered
Mauro Carvalho Chehab27e543f2015-08-20 09:07:34 -030047 * @intf_devnode_id: Unique ID used on the last interface devnode registered
Laurent Pinchart53e269c2009-12-09 08:40:00 -030048 * @entities: List of registered entities
Mauro Carvalho Chehab57cf79b2015-08-21 09:23:22 -030049 * @interfaces: List of registered interfaces
Laurent Pinchart53e269c2009-12-09 08:40:00 -030050 * @lock: Entities list lock
Laurent Pinchart503c3d822010-03-07 15:04:59 -030051 * @graph_mutex: Entities graph operation lock
Sylwester Nawrocki813f5c02013-05-31 10:37:26 -030052 * @link_notify: Link state change notification callback
Laurent Pinchart176fb0d2009-12-09 08:39:58 -030053 *
54 * This structure represents an abstract high-level media device. It allows easy
55 * access to entities and provides basic media device-level support. The
56 * structure can be allocated directly or embedded in a larger structure.
57 *
58 * The parent @dev is a physical device. It must be set before registering the
59 * media device.
60 *
61 * @model is a descriptive model name exported through sysfs. It doesn't have to
62 * be unique.
63 */
64struct media_device {
65 /* dev->driver_data points to this struct. */
66 struct device *dev;
67 struct media_devnode devnode;
68
69 char model[32];
70 char serial[40];
71 char bus_info[32];
72 u32 hw_revision;
73 u32 driver_version;
Laurent Pinchart53e269c2009-12-09 08:40:00 -030074
75 u32 entity_id;
Mauro Carvalho Chehab18710dc2015-08-14 12:50:08 -030076 u32 pad_id;
Mauro Carvalho Chehab6b6a4272015-08-14 12:54:36 -030077 u32 link_id;
Mauro Carvalho Chehab27e543f2015-08-20 09:07:34 -030078 u32 intf_devnode_id;
Mauro Carvalho Chehabbfab2aac2015-08-14 12:47:48 -030079
Laurent Pinchart53e269c2009-12-09 08:40:00 -030080 struct list_head entities;
Mauro Carvalho Chehab57cf79b2015-08-21 09:23:22 -030081 struct list_head interfaces;
Laurent Pinchart53e269c2009-12-09 08:40:00 -030082
83 /* Protects the entities list */
84 spinlock_t lock;
Laurent Pinchart503c3d822010-03-07 15:04:59 -030085 /* Serializes graph operations. */
86 struct mutex graph_mutex;
Laurent Pinchart97548ed2009-12-09 08:40:03 -030087
Sylwester Nawrocki813f5c02013-05-31 10:37:26 -030088 int (*link_notify)(struct media_link *link, u32 flags,
89 unsigned int notification);
Laurent Pinchart176fb0d2009-12-09 08:39:58 -030090};
91
Shuah Khane576d602015-06-05 17:11:54 -030092#ifdef CONFIG_MEDIA_CONTROLLER
93
Sylwester Nawrocki813f5c02013-05-31 10:37:26 -030094/* Supported link_notify @notification values. */
95#define MEDIA_DEV_NOTIFY_PRE_LINK_CH 0
96#define MEDIA_DEV_NOTIFY_POST_LINK_CH 1
97
Laurent Pinchart176fb0d2009-12-09 08:39:58 -030098/* media_devnode to media_device */
99#define to_media_device(node) container_of(node, struct media_device, devnode)
100
Sakari Ailus85de7212013-12-12 12:38:17 -0300101int __must_check __media_device_register(struct media_device *mdev,
102 struct module *owner);
103#define media_device_register(mdev) __media_device_register(mdev, THIS_MODULE)
Laurent Pinchart176fb0d2009-12-09 08:39:58 -0300104void media_device_unregister(struct media_device *mdev);
105
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300106int __must_check media_device_register_entity(struct media_device *mdev,
107 struct media_entity *entity);
108void media_device_unregister_entity(struct media_entity *entity);
Shuah Khand062f912015-06-03 12:12:53 -0300109struct media_device *media_device_get_devres(struct device *dev);
110struct media_device *media_device_find_devres(struct device *dev);
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300111
112/* Iterate over all entities. */
113#define media_device_for_each_entity(entity, mdev) \
114 list_for_each_entry(entity, &(mdev)->entities, list)
115
Shuah Khane576d602015-06-05 17:11:54 -0300116#else
117static inline int media_device_register(struct media_device *mdev)
118{
119 return 0;
120}
121static inline void media_device_unregister(struct media_device *mdev)
122{
123}
124static inline int media_device_register_entity(struct media_device *mdev,
125 struct media_entity *entity)
126{
127 return 0;
128}
129static inline void media_device_unregister_entity(struct media_entity *entity)
130{
131}
132static inline struct media_device *media_device_get_devres(struct device *dev)
133{
134 return NULL;
135}
136static inline struct media_device *media_device_find_devres(struct device *dev)
137{
138 return NULL;
139}
140#endif /* CONFIG_MEDIA_CONTROLLER */
Laurent Pinchart176fb0d2009-12-09 08:39:58 -0300141#endif