aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/media/media-device.c74
-rw-r--r--drivers/media/pci/saa7134/saa7134-core.c2
-rw-r--r--drivers/media/usb/au0828/au0828-core.c4
-rw-r--r--drivers/media/usb/cx231xx/cx231xx-cards.c2
-rw-r--r--drivers/media/usb/dvb-usb-v2/dvb_usb_core.c4
-rw-r--r--drivers/media/usb/dvb-usb/dvb-usb-dvb.c4
-rw-r--r--drivers/media/usb/em28xx/em28xx-cards.c6
-rw-r--r--drivers/media/usb/siano/smsusb.c4
-rw-r--r--drivers/media/v4l2-core/v4l2-mc.c76
-rw-r--r--include/media/media-device.h53
-rw-r--r--include/media/v4l2-mc.h46
11 files changed, 141 insertions, 134 deletions
diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 5ebb3cd31345..fe376b6b5244 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -27,6 +27,8 @@
27#include <linux/media.h> 27#include <linux/media.h>
28#include <linux/slab.h> 28#include <linux/slab.h>
29#include <linux/types.h> 29#include <linux/types.h>
30#include <linux/pci.h>
31#include <linux/usb.h>
30 32
31#include <media/media-device.h> 33#include <media/media-device.h>
32#include <media/media-devnode.h> 34#include <media/media-devnode.h>
@@ -753,4 +755,76 @@ struct media_device *media_device_find_devres(struct device *dev)
753} 755}
754EXPORT_SYMBOL_GPL(media_device_find_devres); 756EXPORT_SYMBOL_GPL(media_device_find_devres);
755 757
758struct media_device *media_device_pci_init(struct pci_dev *pci_dev,
759 const char *name)
760{
761#ifdef CONFIG_PCI
762 struct media_device *mdev;
763
764 mdev = kzalloc(sizeof(*mdev), GFP_KERNEL);
765 if (!mdev)
766 return NULL;
767
768 mdev->dev = &pci_dev->dev;
769
770 if (name)
771 strlcpy(mdev->model, name, sizeof(mdev->model));
772 else
773 strlcpy(mdev->model, pci_name(pci_dev), sizeof(mdev->model));
774
775 sprintf(mdev->bus_info, "PCI:%s", pci_name(pci_dev));
776
777 mdev->hw_revision = (pci_dev->subsystem_vendor << 16)
778 | pci_dev->subsystem_device;
779
780 mdev->driver_version = LINUX_VERSION_CODE;
781
782 media_device_init(mdev);
783
784 return mdev;
785#else
786 return NULL;
787#endif
788}
789EXPORT_SYMBOL_GPL(media_device_pci_init);
790
791struct media_device *__media_device_usb_init(struct usb_device *udev,
792 const char *board_name,
793 const char *driver_name)
794{
795#ifdef CONFIG_USB
796 struct media_device *mdev;
797
798 mdev = kzalloc(sizeof(*mdev), GFP_KERNEL);
799 if (!mdev)
800 return NULL;
801
802 mdev->dev = &udev->dev;
803
804 if (driver_name)
805 strlcpy(mdev->driver_name, driver_name,
806 sizeof(mdev->driver_name));
807
808 if (board_name)
809 strlcpy(mdev->model, board_name, sizeof(mdev->model));
810 else if (udev->product)
811 strlcpy(mdev->model, udev->product, sizeof(mdev->model));
812 else
813 strlcpy(mdev->model, "unknown model", sizeof(mdev->model));
814 if (udev->serial)
815 strlcpy(mdev->serial, udev->serial, sizeof(mdev->serial));
816 usb_make_path(udev, mdev->bus_info, sizeof(mdev->bus_info));
817 mdev->hw_revision = le16_to_cpu(udev->descriptor.bcdDevice);
818 mdev->driver_version = LINUX_VERSION_CODE;
819
820 media_device_init(mdev);
821
822 return mdev;
823#else
824 return NULL;
825#endif
826}
827EXPORT_SYMBOL_GPL(__media_device_usb_init);
828
829
756#endif /* CONFIG_MEDIA_CONTROLLER */ 830#endif /* CONFIG_MEDIA_CONTROLLER */
diff --git a/drivers/media/pci/saa7134/saa7134-core.c b/drivers/media/pci/saa7134/saa7134-core.c
index 8f3ba4077130..8ae65bb320a3 100644
--- a/drivers/media/pci/saa7134/saa7134-core.c
+++ b/drivers/media/pci/saa7134/saa7134-core.c
@@ -1043,7 +1043,7 @@ static int saa7134_initdev(struct pci_dev *pci_dev,
1043 sprintf(dev->name, "saa%x[%d]", pci_dev->device, dev->nr); 1043 sprintf(dev->name, "saa%x[%d]", pci_dev->device, dev->nr);
1044 1044
1045#ifdef CONFIG_MEDIA_CONTROLLER 1045#ifdef CONFIG_MEDIA_CONTROLLER
1046 dev->media_dev = v4l2_mc_pci_media_device_init(pci_dev, dev->name); 1046 dev->media_dev = media_device_pci_init(pci_dev, dev->name);
1047 if (!dev->media_dev) { 1047 if (!dev->media_dev) {
1048 err = -ENOMEM; 1048 err = -ENOMEM;
1049 goto fail0; 1049 goto fail0;
diff --git a/drivers/media/usb/au0828/au0828-core.c b/drivers/media/usb/au0828/au0828-core.c
index 7cafe4dd5fd1..cfcd08ec388f 100644
--- a/drivers/media/usb/au0828/au0828-core.c
+++ b/drivers/media/usb/au0828/au0828-core.c
@@ -192,9 +192,9 @@ static int au0828_media_device_init(struct au0828_dev *dev,
192 struct media_device *mdev; 192 struct media_device *mdev;
193 193
194 if (!dev->board.name) 194 if (!dev->board.name)
195 mdev = v4l2_mc_usb_media_device_init(udev, "unknown au0828"); 195 mdev = media_device_usb_init(udev, "unknown au0828");
196 else 196 else
197 mdev = v4l2_mc_usb_media_device_init(udev, dev->board.name); 197 mdev = media_device_usb_init(udev, dev->board.name);
198 if (!mdev) 198 if (!mdev)
199 return -ENOMEM; 199 return -ENOMEM;
200 200
diff --git a/drivers/media/usb/cx231xx/cx231xx-cards.c b/drivers/media/usb/cx231xx/cx231xx-cards.c
index 9e3a5d2038c2..29bd7536feed 100644
--- a/drivers/media/usb/cx231xx/cx231xx-cards.c
+++ b/drivers/media/usb/cx231xx/cx231xx-cards.c
@@ -1212,7 +1212,7 @@ static int cx231xx_media_device_init(struct cx231xx *dev,
1212#ifdef CONFIG_MEDIA_CONTROLLER 1212#ifdef CONFIG_MEDIA_CONTROLLER
1213 struct media_device *mdev; 1213 struct media_device *mdev;
1214 1214
1215 mdev = v4l2_mc_usb_media_device_init(udev, dev->board.name); 1215 mdev = media_device_usb_init(udev, dev->board.name);
1216 if (!mdev) 1216 if (!mdev)
1217 return -ENOMEM; 1217 return -ENOMEM;
1218 1218
diff --git a/drivers/media/usb/dvb-usb-v2/dvb_usb_core.c b/drivers/media/usb/dvb-usb-v2/dvb_usb_core.c
index 4a8769781cea..58250250a443 100644
--- a/drivers/media/usb/dvb-usb-v2/dvb_usb_core.c
+++ b/drivers/media/usb/dvb-usb-v2/dvb_usb_core.c
@@ -20,7 +20,7 @@
20 */ 20 */
21 21
22#include "dvb_usb_common.h" 22#include "dvb_usb_common.h"
23#include <media/v4l2-mc.h> 23#include <media/media-device.h>
24 24
25static int dvb_usbv2_disable_rc_polling; 25static int dvb_usbv2_disable_rc_polling;
26module_param_named(disable_rc_polling, dvb_usbv2_disable_rc_polling, int, 0644); 26module_param_named(disable_rc_polling, dvb_usbv2_disable_rc_polling, int, 0644);
@@ -408,7 +408,7 @@ static int dvb_usbv2_media_device_init(struct dvb_usb_adapter *adap)
408 struct dvb_usb_device *d = adap_to_d(adap); 408 struct dvb_usb_device *d = adap_to_d(adap);
409 struct usb_device *udev = d->udev; 409 struct usb_device *udev = d->udev;
410 410
411 mdev = v4l2_mc_usb_media_device_init(udev, d->name); 411 mdev = media_device_usb_init(udev, d->name);
412 if (!mdev) 412 if (!mdev)
413 return -ENOMEM; 413 return -ENOMEM;
414 414
diff --git a/drivers/media/usb/dvb-usb/dvb-usb-dvb.c b/drivers/media/usb/dvb-usb/dvb-usb-dvb.c
index 513b0c14e4f0..7509408b0b8e 100644
--- a/drivers/media/usb/dvb-usb/dvb-usb-dvb.c
+++ b/drivers/media/usb/dvb-usb/dvb-usb-dvb.c
@@ -7,7 +7,7 @@
7 * linux-dvb API. 7 * linux-dvb API.
8 */ 8 */
9#include "dvb-usb-common.h" 9#include "dvb-usb-common.h"
10#include <media/v4l2-mc.h> 10#include <media/media-device.h>
11 11
12/* does the complete input transfer handling */ 12/* does the complete input transfer handling */
13static int dvb_usb_ctrl_feed(struct dvb_demux_feed *dvbdmxfeed, int onoff) 13static int dvb_usb_ctrl_feed(struct dvb_demux_feed *dvbdmxfeed, int onoff)
@@ -103,7 +103,7 @@ static int dvb_usb_media_device_init(struct dvb_usb_adapter *adap)
103 struct dvb_usb_device *d = adap->dev; 103 struct dvb_usb_device *d = adap->dev;
104 struct usb_device *udev = d->udev; 104 struct usb_device *udev = d->udev;
105 105
106 mdev = v4l2_mc_usb_media_device_init(udev, d->desc->name); 106 mdev = media_device_usb_init(udev, d->desc->name);
107 107
108 dvb_register_media_controller(&adap->dvb_adap, mdev); 108 dvb_register_media_controller(&adap->dvb_adap, mdev);
109 109
diff --git a/drivers/media/usb/em28xx/em28xx-cards.c b/drivers/media/usb/em28xx/em28xx-cards.c
index 389e95fb0211..0bae26325253 100644
--- a/drivers/media/usb/em28xx/em28xx-cards.c
+++ b/drivers/media/usb/em28xx/em28xx-cards.c
@@ -3020,11 +3020,11 @@ static int em28xx_media_device_init(struct em28xx *dev,
3020 struct media_device *mdev; 3020 struct media_device *mdev;
3021 3021
3022 if (udev->product) { 3022 if (udev->product) {
3023 mdev = v4l2_mc_usb_media_device_init(udev, udev->product); 3023 mdev = media_device_usb_init(udev, udev->product);
3024 } else if (udev->manufacturer) { 3024 } else if (udev->manufacturer) {
3025 mdev = v4l2_mc_usb_media_device_init(udev, udev->manufacturer); 3025 mdev = media_device_usb_init(udev, udev->manufacturer);
3026 } else { 3026 } else {
3027 mdev = v4l2_mc_usb_media_device_init(udev, dev->name); 3027 mdev = media_device_usb_init(udev, dev->name);
3028 } 3028 }
3029 3029
3030 if (!mdev) 3030 if (!mdev)
diff --git a/drivers/media/usb/siano/smsusb.c b/drivers/media/usb/siano/smsusb.c
index 4dac499ed28e..4a0def1e1528 100644
--- a/drivers/media/usb/siano/smsusb.c
+++ b/drivers/media/usb/siano/smsusb.c
@@ -27,7 +27,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
27#include <linux/firmware.h> 27#include <linux/firmware.h>
28#include <linux/slab.h> 28#include <linux/slab.h>
29#include <linux/module.h> 29#include <linux/module.h>
30#include <media/v4l2-mc.h> 30#include <media/media-device.h>
31 31
32#include "sms-cards.h" 32#include "sms-cards.h"
33#include "smsendian.h" 33#include "smsendian.h"
@@ -367,7 +367,7 @@ static void *siano_media_device_register(struct smsusb_device_t *dev,
367 struct sms_board *board = sms_get_board(board_id); 367 struct sms_board *board = sms_get_board(board_id);
368 int ret; 368 int ret;
369 369
370 mdev = v4l2_mc_usb_media_device_init(udev, board->name); 370 mdev = media_device_usb_init(udev, board->name);
371 if (!mdev) 371 if (!mdev)
372 return NULL; 372 return NULL;
373 373
diff --git a/drivers/media/v4l2-core/v4l2-mc.c b/drivers/media/v4l2-core/v4l2-mc.c
index 64eefb9ffb7e..4a1efa827fe2 100644
--- a/drivers/media/v4l2-core/v4l2-mc.c
+++ b/drivers/media/v4l2-core/v4l2-mc.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Media Controller ancillary functions 2 * Media Controller ancillary functions
3 * 3 *
4 * (c) 2016 Mauro Carvalho Chehab <mchehab@osg.samsung.com> 4 * Copyright (c) 2016 Mauro Carvalho Chehab <mchehab@osg.samsung.com>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
@@ -15,83 +15,9 @@
15 */ 15 */
16 16
17#include <linux/module.h> 17#include <linux/module.h>
18#include <linux/pci.h>
19#include <linux/usb.h>
20#include <media/media-entity.h> 18#include <media/media-entity.h>
21#include <media/v4l2-mc.h> 19#include <media/v4l2-mc.h>
22 20
23
24struct media_device *v4l2_mc_pci_media_device_init(struct pci_dev *pci_dev,
25 const char *name)
26{
27#ifdef CONFIG_PCI
28 struct media_device *mdev;
29
30 mdev = kzalloc(sizeof(*mdev), GFP_KERNEL);
31 if (!mdev)
32 return NULL;
33
34 mdev->dev = &pci_dev->dev;
35
36 if (name)
37 strlcpy(mdev->model, name, sizeof(mdev->model));
38 else
39 strlcpy(mdev->model, pci_name(pci_dev), sizeof(mdev->model));
40
41 sprintf(mdev->bus_info, "PCI:%s", pci_name(pci_dev));
42
43 mdev->hw_revision = (pci_dev->subsystem_vendor << 16)
44 | pci_dev->subsystem_device;
45
46 mdev->driver_version = LINUX_VERSION_CODE;
47
48 media_device_init(mdev);
49
50 return mdev;
51#else
52 return NULL;
53#endif
54}
55EXPORT_SYMBOL_GPL(v4l2_mc_pci_media_device_init);
56
57struct media_device *__v4l2_mc_usb_media_device_init(struct usb_device *udev,
58 const char *board_name,
59 const char *driver_name)
60{
61#ifdef CONFIG_USB
62 struct media_device *mdev;
63
64 mdev = kzalloc(sizeof(*mdev), GFP_KERNEL);
65 if (!mdev)
66 return NULL;
67
68 mdev->dev = &udev->dev;
69
70 if (driver_name)
71 strlcpy(mdev->driver_name, driver_name,
72 sizeof(mdev->driver_name));
73
74 if (board_name)
75 strlcpy(mdev->model, board_name, sizeof(mdev->model));
76 else if (udev->product)
77 strlcpy(mdev->model, udev->product, sizeof(mdev->model));
78 else
79 strlcpy(mdev->model, "unknown model", sizeof(mdev->model));
80 if (udev->serial)
81 strlcpy(mdev->serial, udev->serial, sizeof(mdev->serial));
82 usb_make_path(udev, mdev->bus_info, sizeof(mdev->bus_info));
83 mdev->hw_revision = le16_to_cpu(udev->descriptor.bcdDevice);
84 mdev->driver_version = LINUX_VERSION_CODE;
85
86 media_device_init(mdev);
87
88 return mdev;
89#else
90 return NULL;
91#endif
92}
93EXPORT_SYMBOL_GPL(__v4l2_mc_usb_media_device_init);
94
95int v4l2_mc_create_media_graph(struct media_device *mdev) 21int v4l2_mc_create_media_graph(struct media_device *mdev)
96 22
97{ 23{
diff --git a/include/media/media-device.h b/include/media/media-device.h
index 165451bc3985..2d144fed936e 100644
--- a/include/media/media-device.h
+++ b/include/media/media-device.h
@@ -333,6 +333,10 @@ struct media_device {
333 unsigned int notification); 333 unsigned int notification);
334}; 334};
335 335
336/* We don't need to include pci.h or usb.h here */
337struct pci_dev;
338struct usb_device;
339
336#ifdef CONFIG_MEDIA_CONTROLLER 340#ifdef CONFIG_MEDIA_CONTROLLER
337 341
338/* Supported link_notify @notification values. */ 342/* Supported link_notify @notification values. */
@@ -541,6 +545,35 @@ struct media_device *media_device_find_devres(struct device *dev);
541/* Iterate over all links. */ 545/* Iterate over all links. */
542#define media_device_for_each_link(link, mdev) \ 546#define media_device_for_each_link(link, mdev) \
543 list_for_each_entry(link, &(mdev)->links, graph_obj.list) 547 list_for_each_entry(link, &(mdev)->links, graph_obj.list)
548
549/**
550 * media_device_pci_init() - create and initialize a
551 * struct &media_device from a PCI device.
552 *
553 * @pci_dev: pointer to struct pci_dev
554 * @name: media device name. If %NULL, the routine will use the default
555 * name for the pci device, given by pci_name() macro.
556 */
557struct media_device *media_device_pci_init(struct pci_dev *pci_dev,
558 const char *name);
559/**
560 * __media_device_usb_init() - create and initialize a
561 * struct &media_device from a PCI device.
562 *
563 * @udev: pointer to struct usb_device
564 * @board_name: media device name. If %NULL, the routine will use the usb
565 * product name, if available.
566 * @driver_name: name of the driver. if %NULL, the routine will use the name
567 * given by udev->dev->driver->name, with is usually the wrong
568 * thing to do.
569 *
570 * NOTE: It is better to call media_device_usb_init() instead, as
571 * such macro fills driver_name with %KBUILD_MODNAME.
572 */
573struct media_device *__media_device_usb_init(struct usb_device *udev,
574 const char *board_name,
575 const char *driver_name);
576
544#else 577#else
545static inline int media_device_register(struct media_device *mdev) 578static inline int media_device_register(struct media_device *mdev)
546{ 579{
@@ -565,5 +598,25 @@ static inline struct media_device *media_device_find_devres(struct device *dev)
565{ 598{
566 return NULL; 599 return NULL;
567} 600}
601
602static inline
603struct media_device *media_device_pci_init(struct pci_dev *pci_dev,
604 char *name)
605{
606 return NULL;
607}
608
609static inline
610struct media_device *__media_device_usb_init(struct usb_device *udev,
611 char *board_name,
612 char *driver_name)
613{
614 return NULL;
615}
616
568#endif /* CONFIG_MEDIA_CONTROLLER */ 617#endif /* CONFIG_MEDIA_CONTROLLER */
618
619#define media_device_usb_init(udev, name) \
620 __media_device_usb_init(udev, name, KBUILD_MODNAME)
621
569#endif 622#endif
diff --git a/include/media/v4l2-mc.h b/include/media/v4l2-mc.h
index 79d84bb3573c..431380eb408b 100644
--- a/include/media/v4l2-mc.h
+++ b/include/media/v4l2-mc.h
@@ -116,57 +116,11 @@ struct usb_device;
116 */ 116 */
117int v4l2_mc_create_media_graph(struct media_device *mdev); 117int v4l2_mc_create_media_graph(struct media_device *mdev);
118 118
119/**
120 * v4l2_mc_pci_media_device_init() - create and initialize a
121 * struct &media_device from a PCI device.
122 *
123 * @pci_dev: pointer to struct pci_dev
124 * @name: media device name. If %NULL, the routine will use the default
125 * name for the pci device, given by pci_name() macro.
126 */
127struct media_device *v4l2_mc_pci_media_device_init(struct pci_dev *pci_dev,
128 const char *name);
129/**
130 * __v4l2_mc_usb_media_device_init() - create and initialize a
131 * struct &media_device from a PCI device.
132 *
133 * @udev: pointer to struct usb_device
134 * @board_name: media device name. If %NULL, the routine will use the usb
135 * product name, if available.
136 * @driver_name: name of the driver. if %NULL, the routine will use the name
137 * given by udev->dev->driver->name, with is usually the wrong
138 * thing to do.
139 *
140 * NOTE: It is better to call v4l2_mc_usb_media_device_init() instead, as
141 * such macro fills driver_name with %KBUILD_MODNAME.
142 */
143struct media_device *__v4l2_mc_usb_media_device_init(struct usb_device *udev,
144 const char *board_name,
145 const char *driver_name);
146
147#else 119#else
148static inline int v4l2_mc_create_media_graph(struct media_device *mdev) 120static inline int v4l2_mc_create_media_graph(struct media_device *mdev)
149{ 121{
150 return 0; 122 return 0;
151} 123}
152 124
153static inline
154struct media_device *v4l2_mc_pci_media_device_init(struct pci_dev *pci_dev,
155 char *name)
156{
157 return NULL;
158}
159
160static inline
161struct media_device *__v4l2_mc_usb_media_device_init(struct usb_device *udev,
162 char *board_name,
163 char *driver_name)
164{
165 return NULL;
166}
167#endif 125#endif
168
169#define v4l2_mc_usb_media_device_init(udev, name) \
170 __v4l2_mc_usb_media_device_init(udev, name, KBUILD_MODNAME)
171
172#endif 126#endif