aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/em28xx
diff options
context:
space:
mode:
authorDouglas Schilling Landgraf <dougsland@redhat.com>2009-03-31 16:10:58 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2009-04-06 20:43:50 -0400
commitf2cf250af156bef127433efd255abfae6aab02f6 (patch)
tree806656ca13f3a6278224f92b3ee1adc77dcbf148 /drivers/media/video/em28xx
parent9fc4d219b93ca0222f342fb3ca75bb62cc8be05c (diff)
V4L/DVB (11331): em28xx: convert to v4l2_subdev
Converted em28xx driver to v4l2_subdev. Thanks to Hans Verkuil <hverkuil@xs4all.nl> for helping this conversion. Signed-off-by: Douglas Schilling Landgraf <dougsland@redhat.com> Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video/em28xx')
-rw-r--r--drivers/media/video/em28xx/em28xx-cards.c145
-rw-r--r--drivers/media/video/em28xx/em28xx-core.c9
-rw-r--r--drivers/media/video/em28xx/em28xx-i2c.c71
-rw-r--r--drivers/media/video/em28xx/em28xx-video.c78
-rw-r--r--drivers/media/video/em28xx/em28xx.h10
5 files changed, 172 insertions, 141 deletions
diff --git a/drivers/media/video/em28xx/em28xx-cards.c b/drivers/media/video/em28xx/em28xx-cards.c
index 0f48c0ff5ac3..fe96da0d54ef 100644
--- a/drivers/media/video/em28xx/em28xx-cards.c
+++ b/drivers/media/video/em28xx/em28xx-cards.c
@@ -31,6 +31,8 @@
31#include <media/msp3400.h> 31#include <media/msp3400.h>
32#include <media/saa7115.h> 32#include <media/saa7115.h>
33#include <media/tvp5150.h> 33#include <media/tvp5150.h>
34#include <media/tvaudio.h>
35#include <media/i2c-addr.h>
34#include <media/tveeprom.h> 36#include <media/tveeprom.h>
35#include <media/v4l2-common.h> 37#include <media/v4l2-common.h>
36#include <media/v4l2-chip-ident.h> 38#include <media/v4l2-chip-ident.h>
@@ -1240,6 +1242,7 @@ struct em28xx_board em28xx_boards[] = {
1240 [EM2820_BOARD_COMPRO_VIDEOMATE_FORYOU] = { 1242 [EM2820_BOARD_COMPRO_VIDEOMATE_FORYOU] = {
1241 .name = "Compro VideoMate ForYou/Stereo", 1243 .name = "Compro VideoMate ForYou/Stereo",
1242 .tuner_type = TUNER_LG_PAL_NEW_TAPC, 1244 .tuner_type = TUNER_LG_PAL_NEW_TAPC,
1245 .tvaudio_addr = 0xb0,
1243 .tda9887_conf = TDA9887_PRESENT, 1246 .tda9887_conf = TDA9887_PRESENT,
1244 .decoder = EM28XX_TVP5150, 1247 .decoder = EM28XX_TVP5150,
1245 .adecoder = EM28XX_TVAUDIO, 1248 .adecoder = EM28XX_TVAUDIO,
@@ -1444,6 +1447,24 @@ static struct em28xx_hash_table em28xx_i2c_hash[] = {
1444 {0xc51200e3, EM2820_BOARD_GADMEI_TVR200, TUNER_LG_PAL_NEW_TAPC}, 1447 {0xc51200e3, EM2820_BOARD_GADMEI_TVR200, TUNER_LG_PAL_NEW_TAPC},
1445}; 1448};
1446 1449
1450/* I2C possible address to saa7115, tvp5150, msp3400, tvaudio */
1451static unsigned short saa711x_addrs[] = {
1452 0x4a >> 1, 0x48 >> 1, /* SAA7111, SAA7111A and SAA7113 */
1453 0x42 >> 1, 0x40 >> 1, /* SAA7114, SAA7115 and SAA7118 */
1454 I2C_CLIENT_END };
1455
1456static unsigned short tvp5150_addrs[] = {
1457 0xb8 >> 1,
1458 0xba >> 1,
1459 I2C_CLIENT_END
1460};
1461
1462static unsigned short msp3400_addrs[] = {
1463 0x80 >> 1,
1464 0x88 >> 1,
1465 I2C_CLIENT_END
1466};
1467
1447int em28xx_tuner_callback(void *ptr, int component, int command, int arg) 1468int em28xx_tuner_callback(void *ptr, int component, int command, int arg)
1448{ 1469{
1449 int rc = 0; 1470 int rc = 0;
@@ -1672,31 +1693,55 @@ static void em28xx_setup_xc3028(struct em28xx *dev, struct xc2028_ctrl *ctl)
1672 } 1693 }
1673} 1694}
1674 1695
1675static void em28xx_config_tuner(struct em28xx *dev) 1696static void em28xx_tuner_setup(struct em28xx *dev)
1676{ 1697{
1677 struct v4l2_priv_tun_config xc2028_cfg;
1678 struct tuner_setup tun_setup; 1698 struct tuner_setup tun_setup;
1679 struct v4l2_frequency f; 1699 struct v4l2_frequency f;
1680 1700
1681 if (dev->tuner_type == TUNER_ABSENT) 1701 if (dev->tuner_type == TUNER_ABSENT)
1682 return; 1702 return;
1683 1703
1704 memset(&tun_setup, 0, sizeof(tun_setup));
1705
1684 tun_setup.mode_mask = T_ANALOG_TV | T_RADIO; 1706 tun_setup.mode_mask = T_ANALOG_TV | T_RADIO;
1685 tun_setup.type = dev->tuner_type;
1686 tun_setup.addr = dev->tuner_addr;
1687 tun_setup.tuner_callback = em28xx_tuner_callback; 1707 tun_setup.tuner_callback = em28xx_tuner_callback;
1688 1708
1689 em28xx_i2c_call_clients(dev, TUNER_SET_TYPE_ADDR, &tun_setup); 1709 if (dev->board.radio.type) {
1710 tun_setup.type = dev->board.radio.type;
1711 tun_setup.addr = dev->board.radio_addr;
1712
1713 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_type_addr, &tun_setup);
1714 }
1715
1716 if ((dev->tuner_type != TUNER_ABSENT) && (dev->tuner_type)) {
1717 tun_setup.type = dev->tuner_type;
1718 tun_setup.addr = dev->tuner_addr;
1719
1720 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_type_addr, &tun_setup);
1721 }
1722
1723 if (dev->tda9887_conf) {
1724 struct v4l2_priv_tun_config tda9887_cfg;
1725
1726 tda9887_cfg.tuner = TUNER_TDA9887;
1727 tda9887_cfg.priv = &dev->tda9887_conf;
1728
1729 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_config, &tda9887_cfg);
1730 }
1690 1731
1691 if (dev->tuner_type == TUNER_XC2028) { 1732 if (dev->tuner_type == TUNER_XC2028) {
1733 struct v4l2_priv_tun_config xc2028_cfg;
1692 struct xc2028_ctrl ctl; 1734 struct xc2028_ctrl ctl;
1693 1735
1736 memset(&xc2028_cfg, 0, sizeof(xc2028_cfg));
1737 memset(&ctl, 0, sizeof(ctl));
1738
1694 em28xx_setup_xc3028(dev, &ctl); 1739 em28xx_setup_xc3028(dev, &ctl);
1695 1740
1696 xc2028_cfg.tuner = TUNER_XC2028; 1741 xc2028_cfg.tuner = TUNER_XC2028;
1697 xc2028_cfg.priv = &ctl; 1742 xc2028_cfg.priv = &ctl;
1698 1743
1699 em28xx_i2c_call_clients(dev, TUNER_SET_CONFIG, &xc2028_cfg); 1744 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_config, &xc2028_cfg);
1700 } 1745 }
1701 1746
1702 /* configure tuner */ 1747 /* configure tuner */
@@ -1704,7 +1749,7 @@ static void em28xx_config_tuner(struct em28xx *dev)
1704 f.type = V4L2_TUNER_ANALOG_TV; 1749 f.type = V4L2_TUNER_ANALOG_TV;
1705 f.frequency = 9076; /* just a magic number */ 1750 f.frequency = 9076; /* just a magic number */
1706 dev->ctl_freq = f.frequency; 1751 dev->ctl_freq = f.frequency;
1707 em28xx_i2c_call_clients(dev, VIDIOC_S_FREQUENCY, &f); 1752 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, &f);
1708} 1753}
1709 1754
1710static int em28xx_hint_board(struct em28xx *dev) 1755static int em28xx_hint_board(struct em28xx *dev)
@@ -1911,22 +1956,50 @@ void em28xx_card_setup(struct em28xx *dev)
1911 if (tuner >= 0) 1956 if (tuner >= 0)
1912 dev->tuner_type = tuner; 1957 dev->tuner_type = tuner;
1913 1958
1914#ifdef CONFIG_MODULES
1915 /* request some modules */ 1959 /* request some modules */
1916 if (dev->board.has_msp34xx) 1960 if (dev->board.has_msp34xx)
1917 request_module("msp3400"); 1961 v4l2_i2c_new_probed_subdev(&dev->i2c_adap, "msp3400",
1962 "msp3400", msp3400_addrs);
1963
1918 if (dev->board.decoder == EM28XX_SAA711X) 1964 if (dev->board.decoder == EM28XX_SAA711X)
1919 request_module("saa7115"); 1965 v4l2_i2c_new_probed_subdev(&dev->i2c_adap, "saa7115",
1966 "saa7115_auto", saa711x_addrs);
1967
1920 if (dev->board.decoder == EM28XX_TVP5150) 1968 if (dev->board.decoder == EM28XX_TVP5150)
1921 request_module("tvp5150"); 1969 v4l2_i2c_new_probed_subdev(&dev->i2c_adap, "tvp5150",
1922 if (dev->board.tuner_type != TUNER_ABSENT) 1970 "tvp5150", tvp5150_addrs);
1923 request_module("tuner");
1924 if (dev->board.adecoder == EM28XX_TVAUDIO)
1925 request_module("tvaudio");
1926#endif
1927 1971
1928 em28xx_config_tuner(dev); 1972 if (dev->board.adecoder == EM28XX_TVAUDIO)
1973 v4l2_i2c_new_subdev(&dev->i2c_adap, "tvaudio",
1974 "tvaudio", dev->board.tvaudio_addr);
1975
1976 if (dev->board.tuner_type != TUNER_ABSENT) {
1977 int has_demod = (dev->tda9887_conf & TDA9887_PRESENT);
1978
1979 if (dev->board.radio.type)
1980 v4l2_i2c_new_subdev(&dev->i2c_adap, "tuner", "tuner",
1981 dev->board.radio_addr);
1982
1983 if (has_demod)
1984 v4l2_i2c_new_probed_subdev(&dev->i2c_adap, "tuner",
1985 "tuner", v4l2_i2c_tuner_addrs(ADDRS_DEMOD));
1986 if (dev->tuner_addr == 0) {
1987 enum v4l2_i2c_tuner_type type =
1988 has_demod ? ADDRS_TV_WITH_DEMOD : ADDRS_TV;
1989 struct v4l2_subdev *sd;
1990
1991 sd = v4l2_i2c_new_probed_subdev(&dev->i2c_adap, "tuner",
1992 "tuner", v4l2_i2c_tuner_addrs(type));
1993
1994 if (sd)
1995 dev->tuner_addr = v4l2_i2c_subdev_addr(sd);
1996 } else {
1997 v4l2_i2c_new_subdev(&dev->i2c_adap, "tuner",
1998 "tuner", dev->tuner_addr);
1999 }
2000 }
1929 2001
2002 em28xx_tuner_setup(dev);
1930 em28xx_ir_init(dev); 2003 em28xx_ir_init(dev);
1931} 2004}
1932 2005
@@ -1975,6 +2048,9 @@ void em28xx_release_resources(struct em28xx *dev)
1975 em28xx_remove_from_devlist(dev); 2048 em28xx_remove_from_devlist(dev);
1976 2049
1977 em28xx_i2c_unregister(dev); 2050 em28xx_i2c_unregister(dev);
2051
2052 v4l2_device_unregister(&dev->v4l2_dev);
2053
1978 usb_put_dev(dev->udev); 2054 usb_put_dev(dev->udev);
1979 2055
1980 /* Mark device as unused */ 2056 /* Mark device as unused */
@@ -2019,9 +2095,16 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
2019 } 2095 }
2020 } 2096 }
2021 2097
2098 retval = v4l2_device_register(&dev->udev->dev, &dev->v4l2_dev);
2099 if (retval < 0) {
2100 em28xx_errdev("Call to v4l2_device_register() failed!\n");
2101 return retval;
2102 }
2103
2022 /* register i2c bus */ 2104 /* register i2c bus */
2023 errCode = em28xx_i2c_register(dev); 2105 errCode = em28xx_i2c_register(dev);
2024 if (errCode < 0) { 2106 if (errCode < 0) {
2107 v4l2_device_unregister(&dev->v4l2_dev);
2025 em28xx_errdev("%s: em28xx_i2c_register - errCode [%d]!\n", 2108 em28xx_errdev("%s: em28xx_i2c_register - errCode [%d]!\n",
2026 __func__, errCode); 2109 __func__, errCode);
2027 return errCode; 2110 return errCode;
@@ -2033,6 +2116,7 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
2033 /* Configure audio */ 2116 /* Configure audio */
2034 errCode = em28xx_audio_setup(dev); 2117 errCode = em28xx_audio_setup(dev);
2035 if (errCode < 0) { 2118 if (errCode < 0) {
2119 v4l2_device_unregister(&dev->v4l2_dev);
2036 em28xx_errdev("%s: Error while setting audio - errCode [%d]!\n", 2120 em28xx_errdev("%s: Error while setting audio - errCode [%d]!\n",
2037 __func__, errCode); 2121 __func__, errCode);
2038 } 2122 }
@@ -2077,7 +2161,7 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
2077 em28xx_init_extension(dev); 2161 em28xx_init_extension(dev);
2078 2162
2079 /* Save some power by putting tuner to sleep */ 2163 /* Save some power by putting tuner to sleep */
2080 em28xx_i2c_call_clients(dev, TUNER_SET_STANDBY, NULL); 2164 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_standby, 0);
2081 2165
2082 return 0; 2166 return 0;
2083 2167
@@ -2096,7 +2180,7 @@ static int em28xx_usb_probe(struct usb_interface *interface,
2096 struct usb_device *udev; 2180 struct usb_device *udev;
2097 struct usb_interface *uif; 2181 struct usb_interface *uif;
2098 struct em28xx *dev = NULL; 2182 struct em28xx *dev = NULL;
2099 int retval = -ENODEV; 2183 int retval;
2100 int i, nr, ifnum, isoc_pipe; 2184 int i, nr, ifnum, isoc_pipe;
2101 char *speed; 2185 char *speed;
2102 char descr[255] = ""; 2186 char descr[255] = "";
@@ -2118,7 +2202,8 @@ static int em28xx_usb_probe(struct usb_interface *interface,
2118 interface->altsetting[0].desc.bInterfaceClass); 2202 interface->altsetting[0].desc.bInterfaceClass);
2119 2203
2120 em28xx_devused &= ~(1<<nr); 2204 em28xx_devused &= ~(1<<nr);
2121 return -ENODEV; 2205 retval = -ENODEV;
2206 goto err;
2122 } 2207 }
2123 2208
2124 endpoint = &interface->cur_altsetting->endpoint[0].desc; 2209 endpoint = &interface->cur_altsetting->endpoint[0].desc;
@@ -2151,7 +2236,8 @@ static int em28xx_usb_probe(struct usb_interface *interface,
2151 "interface not used by the driver\n"); 2236 "interface not used by the driver\n");
2152 2237
2153 em28xx_devused &= ~(1<<nr); 2238 em28xx_devused &= ~(1<<nr);
2154 return -ENODEV; 2239 retval = -ENODEV;
2240 goto err;
2155 } 2241 }
2156 } 2242 }
2157 2243
@@ -2194,7 +2280,8 @@ static int em28xx_usb_probe(struct usb_interface *interface,
2194 printk(DRIVER_NAME ": Supports only %i em28xx boards.\n", 2280 printk(DRIVER_NAME ": Supports only %i em28xx boards.\n",
2195 EM28XX_MAXBOARDS); 2281 EM28XX_MAXBOARDS);
2196 em28xx_devused &= ~(1<<nr); 2282 em28xx_devused &= ~(1<<nr);
2197 return -ENOMEM; 2283 retval = -ENOMEM;
2284 goto err;
2198 } 2285 }
2199 2286
2200 /* allocate memory for our device state and initialize it */ 2287 /* allocate memory for our device state and initialize it */
@@ -2202,7 +2289,8 @@ static int em28xx_usb_probe(struct usb_interface *interface,
2202 if (dev == NULL) { 2289 if (dev == NULL) {
2203 em28xx_err(DRIVER_NAME ": out of memory!\n"); 2290 em28xx_err(DRIVER_NAME ": out of memory!\n");
2204 em28xx_devused &= ~(1<<nr); 2291 em28xx_devused &= ~(1<<nr);
2205 return -ENOMEM; 2292 retval = -ENOMEM;
2293 goto err;
2206 } 2294 }
2207 2295
2208 snprintf(dev->name, 29, "em28xx #%d", nr); 2296 snprintf(dev->name, 29, "em28xx #%d", nr);
@@ -2229,7 +2317,8 @@ static int em28xx_usb_probe(struct usb_interface *interface,
2229 em28xx_errdev("out of memory!\n"); 2317 em28xx_errdev("out of memory!\n");
2230 em28xx_devused &= ~(1<<nr); 2318 em28xx_devused &= ~(1<<nr);
2231 kfree(dev); 2319 kfree(dev);
2232 return -ENOMEM; 2320 retval = -ENOMEM;
2321 goto err;
2233 } 2322 }
2234 2323
2235 for (i = 0; i < dev->num_alt ; i++) { 2324 for (i = 0; i < dev->num_alt ; i++) {
@@ -2248,8 +2337,7 @@ static int em28xx_usb_probe(struct usb_interface *interface,
2248 if (retval) { 2337 if (retval) {
2249 em28xx_devused &= ~(1<<dev->devno); 2338 em28xx_devused &= ~(1<<dev->devno);
2250 kfree(dev); 2339 kfree(dev);
2251 2340 goto err;
2252 return retval;
2253 } 2341 }
2254 2342
2255 /* save our data pointer in this interface device */ 2343 /* save our data pointer in this interface device */
@@ -2263,6 +2351,9 @@ static int em28xx_usb_probe(struct usb_interface *interface,
2263 mutex_unlock(&dev->lock); 2351 mutex_unlock(&dev->lock);
2264 2352
2265 return 0; 2353 return 0;
2354
2355err:
2356 return retval;
2266} 2357}
2267 2358
2268/* 2359/*
@@ -2288,6 +2379,8 @@ static void em28xx_usb_disconnect(struct usb_interface *interface)
2288 2379
2289 wake_up_interruptible_all(&dev->open); 2380 wake_up_interruptible_all(&dev->open);
2290 2381
2382 v4l2_device_disconnect(&dev->v4l2_dev);
2383
2291 if (dev->users) { 2384 if (dev->users) {
2292 em28xx_warn 2385 em28xx_warn
2293 ("device /dev/video%d is open! Deregistration and memory " 2386 ("device /dev/video%d is open! Deregistration and memory "
diff --git a/drivers/media/video/em28xx/em28xx-core.c b/drivers/media/video/em28xx/em28xx-core.c
index 8f1999ca4803..8f8f20e14713 100644
--- a/drivers/media/video/em28xx/em28xx-core.c
+++ b/drivers/media/video/em28xx/em28xx-core.c
@@ -1021,11 +1021,12 @@ void em28xx_wake_i2c(struct em28xx *dev)
1021 struct v4l2_routing route; 1021 struct v4l2_routing route;
1022 int zero = 0; 1022 int zero = 0;
1023 1023
1024 route.input = INPUT(dev->ctl_input)->vmux; 1024 route.input = INPUT(dev->ctl_input)->vmux;
1025 route.output = 0; 1025 route.output = 0;
1026 em28xx_i2c_call_clients(dev, VIDIOC_INT_RESET, &zero); 1026
1027 em28xx_i2c_call_clients(dev, VIDIOC_INT_S_VIDEO_ROUTING, &route); 1027 v4l2_device_call_all(&dev->v4l2_dev, 0, core, reset, zero);
1028 em28xx_i2c_call_clients(dev, VIDIOC_STREAMON, NULL); 1028 v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_routing, &route);
1029 v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_stream, 0);
1029} 1030}
1030 1031
1031/* 1032/*
diff --git a/drivers/media/video/em28xx/em28xx-i2c.c b/drivers/media/video/em28xx/em28xx-i2c.c
index 02c12fe6361b..f0bf1d960c75 100644
--- a/drivers/media/video/em28xx/em28xx-i2c.c
+++ b/drivers/media/video/em28xx/em28xx-i2c.c
@@ -459,70 +459,15 @@ static u32 functionality(struct i2c_adapter *adap)
459static int attach_inform(struct i2c_client *client) 459static int attach_inform(struct i2c_client *client)
460{ 460{
461 struct em28xx *dev = client->adapter->algo_data; 461 struct em28xx *dev = client->adapter->algo_data;
462 struct IR_i2c *ir = i2c_get_clientdata(client);
462 463
463 switch (client->addr << 1) { 464 switch (client->addr << 1) {
464 case 0x86:
465 case 0x84:
466 case 0x96:
467 case 0x94:
468 {
469 struct v4l2_priv_tun_config tda9887_cfg;
470
471 struct tuner_setup tun_setup;
472
473 tun_setup.mode_mask = T_ANALOG_TV | T_RADIO;
474 tun_setup.type = TUNER_TDA9887;
475 tun_setup.addr = client->addr;
476
477 em28xx_i2c_call_clients(dev, TUNER_SET_TYPE_ADDR,
478 &tun_setup);
479
480 tda9887_cfg.tuner = TUNER_TDA9887;
481 tda9887_cfg.priv = &dev->tda9887_conf;
482 em28xx_i2c_call_clients(dev, TUNER_SET_CONFIG,
483 &tda9887_cfg);
484 break;
485 }
486 case 0x42:
487 dprintk1(1, "attach_inform: saa7114 detected.\n");
488 break;
489 case 0x4a:
490 dprintk1(1, "attach_inform: saa7113 detected.\n");
491 break;
492 case 0xa0:
493 dprintk1(1, "attach_inform: eeprom detected.\n");
494 break;
495 case 0x60: 465 case 0x60:
496 case 0x8e: 466 case 0x8e:
497 { 467 dprintk1(1, "attach_inform: IR detected (%s).\n", ir->phys);
498 struct IR_i2c *ir = i2c_get_clientdata(client);
499 dprintk1(1, "attach_inform: IR detected (%s).\n",
500 ir->phys);
501 em28xx_set_ir(dev, ir); 468 em28xx_set_ir(dev, ir);
502 break; 469 break;
503 } 470 }
504 case 0x80:
505 case 0x88:
506 dprintk1(1, "attach_inform: msp34xx detected.\n");
507 break;
508 case 0xb8:
509 case 0xba:
510 dprintk1(1, "attach_inform: tvp5150 detected.\n");
511 break;
512
513 case 0xb0:
514 dprintk1(1, "attach_inform: tda9874 detected\n");
515 break;
516
517 default:
518 if (!dev->tuner_addr)
519 dev->tuner_addr = client->addr;
520
521 dprintk1(1, "attach inform: detected I2C address %x\n",
522 client->addr << 1);
523 dprintk1(1, "driver id %d\n", client->driver->id);
524
525 }
526 471
527 return 0; 472 return 0;
528} 473}
@@ -534,7 +479,6 @@ static struct i2c_algorithm em28xx_algo = {
534 479
535static struct i2c_adapter em28xx_adap_template = { 480static struct i2c_adapter em28xx_adap_template = {
536 .owner = THIS_MODULE, 481 .owner = THIS_MODULE,
537 .class = I2C_CLASS_TV_ANALOG,
538 .name = "em28xx", 482 .name = "em28xx",
539 .id = I2C_HW_B_EM28XX, 483 .id = I2C_HW_B_EM28XX,
540 .algo = &em28xx_algo, 484 .algo = &em28xx_algo,
@@ -595,16 +539,6 @@ void em28xx_do_i2c_scan(struct em28xx *dev)
595} 539}
596 540
597/* 541/*
598 * em28xx_i2c_call_clients()
599 * send commands to all attached i2c devices
600 */
601void em28xx_i2c_call_clients(struct em28xx *dev, unsigned int cmd, void *arg)
602{
603 BUG_ON(NULL == dev->i2c_adap.algo_data);
604 i2c_clients_command(&dev->i2c_adap, cmd, arg);
605}
606
607/*
608 * em28xx_i2c_register() 542 * em28xx_i2c_register()
609 * register i2c bus 543 * register i2c bus
610 */ 544 */
@@ -618,6 +552,7 @@ int em28xx_i2c_register(struct em28xx *dev)
618 dev->i2c_adap.dev.parent = &dev->udev->dev; 552 dev->i2c_adap.dev.parent = &dev->udev->dev;
619 strcpy(dev->i2c_adap.name, dev->name); 553 strcpy(dev->i2c_adap.name, dev->name);
620 dev->i2c_adap.algo_data = dev; 554 dev->i2c_adap.algo_data = dev;
555 i2c_set_adapdata(&dev->i2c_adap, &dev->v4l2_dev);
621 556
622 retval = i2c_add_adapter(&dev->i2c_adap); 557 retval = i2c_add_adapter(&dev->i2c_adap);
623 if (retval < 0) { 558 if (retval < 0) {
diff --git a/drivers/media/video/em28xx/em28xx-video.c b/drivers/media/video/em28xx/em28xx-video.c
index 575472f1e702..6c09a37e4048 100644
--- a/drivers/media/video/em28xx/em28xx-video.c
+++ b/drivers/media/video/em28xx/em28xx-video.c
@@ -49,7 +49,7 @@
49 "Sascha Sommer <saschasommer@freenet.de>" 49 "Sascha Sommer <saschasommer@freenet.de>"
50 50
51#define DRIVER_DESC "Empia em28xx based USB video device driver" 51#define DRIVER_DESC "Empia em28xx based USB video device driver"
52#define EM28XX_VERSION_CODE KERNEL_VERSION(0, 1, 1) 52#define EM28XX_VERSION_CODE KERNEL_VERSION(0, 1, 2)
53 53
54#define em28xx_videodbg(fmt, arg...) do {\ 54#define em28xx_videodbg(fmt, arg...) do {\
55 if (video_debug) \ 55 if (video_debug) \
@@ -400,7 +400,7 @@ buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size)
400 f.frequency = dev->ctl_freq; 400 f.frequency = dev->ctl_freq;
401 f.type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; 401 f.type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
402 402
403 em28xx_i2c_call_clients(dev, VIDIOC_S_FREQUENCY, &f); 403 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, &f);
404 404
405 return 0; 405 return 0;
406} 406}
@@ -526,25 +526,25 @@ static void video_mux(struct em28xx *dev, int index)
526 if (!dev->ctl_aoutput) 526 if (!dev->ctl_aoutput)
527 dev->ctl_aoutput = EM28XX_AOUT_MASTER; 527 dev->ctl_aoutput = EM28XX_AOUT_MASTER;
528 528
529 em28xx_i2c_call_clients(dev, VIDIOC_INT_S_VIDEO_ROUTING, &route); 529 v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_routing, &route);
530 530
531 if (dev->board.has_msp34xx) { 531 if (dev->board.has_msp34xx) {
532 if (dev->i2s_speed) { 532 if (dev->i2s_speed) {
533 em28xx_i2c_call_clients(dev, VIDIOC_INT_I2S_CLOCK_FREQ, 533 v4l2_device_call_all(&dev->v4l2_dev, 0, audio,
534 &dev->i2s_speed); 534 s_i2s_clock_freq, dev->i2s_speed);
535 } 535 }
536 route.input = dev->ctl_ainput; 536 route.input = dev->ctl_ainput;
537 route.output = MSP_OUTPUT(MSP_SC_IN_DSP_SCART1); 537 route.output = MSP_OUTPUT(MSP_SC_IN_DSP_SCART1);
538
538 /* Note: this is msp3400 specific */ 539 /* Note: this is msp3400 specific */
539 em28xx_i2c_call_clients(dev, VIDIOC_INT_S_AUDIO_ROUTING, 540 v4l2_device_call_all(&dev->v4l2_dev, 0, audio, s_routing, &route);
540 &route);
541 } 541 }
542 542
543 if (dev->board.adecoder != EM28XX_NOADECODER) { 543 if (dev->board.adecoder != EM28XX_NOADECODER) {
544 route.input = dev->ctl_ainput; 544 route.input = dev->ctl_ainput;
545 route.output = dev->ctl_aoutput; 545 route.output = dev->ctl_aoutput;
546 em28xx_i2c_call_clients(dev, VIDIOC_INT_S_AUDIO_ROUTING, 546
547 &route); 547 v4l2_device_call_all(&dev->v4l2_dev, 0, audio, s_routing, &route);
548 } 548 }
549 549
550 em28xx_audio_analog_set(dev); 550 em28xx_audio_analog_set(dev);
@@ -829,7 +829,7 @@ static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *norm)
829 get_scale(dev, dev->width, dev->height, &dev->hscale, &dev->vscale); 829 get_scale(dev, dev->width, dev->height, &dev->hscale, &dev->vscale);
830 830
831 em28xx_resolution_set(dev); 831 em28xx_resolution_set(dev);
832 em28xx_i2c_call_clients(dev, VIDIOC_S_STD, &dev->norm); 832 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_std, dev->norm);
833 833
834 mutex_unlock(&dev->lock); 834 mutex_unlock(&dev->lock);
835 return 0; 835 return 0;
@@ -995,8 +995,9 @@ static int vidioc_queryctrl(struct file *file, void *priv,
995 } 995 }
996 } 996 }
997 } 997 }
998
998 mutex_lock(&dev->lock); 999 mutex_lock(&dev->lock);
999 em28xx_i2c_call_clients(dev, VIDIOC_QUERYCTRL, qc); 1000 v4l2_device_call_all(&dev->v4l2_dev, 0, core, queryctrl, qc);
1000 mutex_unlock(&dev->lock); 1001 mutex_unlock(&dev->lock);
1001 1002
1002 if (qc->type) 1003 if (qc->type)
@@ -1020,11 +1021,11 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
1020 mutex_lock(&dev->lock); 1021 mutex_lock(&dev->lock);
1021 1022
1022 if (dev->board.has_msp34xx) 1023 if (dev->board.has_msp34xx)
1023 em28xx_i2c_call_clients(dev, VIDIOC_G_CTRL, ctrl); 1024 v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_ctrl, ctrl);
1024 else { 1025 else {
1025 rc = em28xx_get_ctrl(dev, ctrl); 1026 rc = em28xx_get_ctrl(dev, ctrl);
1026 if (rc < 0) { 1027 if (rc < 0) {
1027 em28xx_i2c_call_clients(dev, VIDIOC_G_CTRL, ctrl); 1028 v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_ctrl, ctrl);
1028 rc = 0; 1029 rc = 0;
1029 } 1030 }
1030 } 1031 }
@@ -1048,7 +1049,7 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
1048 mutex_lock(&dev->lock); 1049 mutex_lock(&dev->lock);
1049 1050
1050 if (dev->board.has_msp34xx) 1051 if (dev->board.has_msp34xx)
1051 em28xx_i2c_call_clients(dev, VIDIOC_S_CTRL, ctrl); 1052 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_ctrl, ctrl);
1052 else { 1053 else {
1053 rc = 1; 1054 rc = 1;
1054 for (i = 0; i < ARRAY_SIZE(em28xx_qctrl); i++) { 1055 for (i = 0; i < ARRAY_SIZE(em28xx_qctrl); i++) {
@@ -1067,7 +1068,7 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
1067 1068
1068 /* Control not found - try to send it to the attached devices */ 1069 /* Control not found - try to send it to the attached devices */
1069 if (rc == 1) { 1070 if (rc == 1) {
1070 em28xx_i2c_call_clients(dev, VIDIOC_S_CTRL, ctrl); 1071 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_ctrl, ctrl);
1071 rc = 0; 1072 rc = 0;
1072 } 1073 }
1073 1074
@@ -1092,10 +1093,9 @@ static int vidioc_g_tuner(struct file *file, void *priv,
1092 strcpy(t->name, "Tuner"); 1093 strcpy(t->name, "Tuner");
1093 1094
1094 mutex_lock(&dev->lock); 1095 mutex_lock(&dev->lock);
1095 1096 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_tuner, t);
1096 em28xx_i2c_call_clients(dev, VIDIOC_G_TUNER, t);
1097
1098 mutex_unlock(&dev->lock); 1097 mutex_unlock(&dev->lock);
1098
1099 return 0; 1099 return 0;
1100} 1100}
1101 1101
@@ -1114,10 +1114,9 @@ static int vidioc_s_tuner(struct file *file, void *priv,
1114 return -EINVAL; 1114 return -EINVAL;
1115 1115
1116 mutex_lock(&dev->lock); 1116 mutex_lock(&dev->lock);
1117 1117 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_tuner, t);
1118 em28xx_i2c_call_clients(dev, VIDIOC_S_TUNER, t);
1119
1120 mutex_unlock(&dev->lock); 1118 mutex_unlock(&dev->lock);
1119
1121 return 0; 1120 return 0;
1122} 1121}
1123 1122
@@ -1157,7 +1156,7 @@ static int vidioc_s_frequency(struct file *file, void *priv,
1157 mutex_lock(&dev->lock); 1156 mutex_lock(&dev->lock);
1158 1157
1159 dev->ctl_freq = f->frequency; 1158 dev->ctl_freq = f->frequency;
1160 em28xx_i2c_call_clients(dev, VIDIOC_S_FREQUENCY, f); 1159 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, f);
1161 1160
1162 mutex_unlock(&dev->lock); 1161 mutex_unlock(&dev->lock);
1163 1162
@@ -1186,7 +1185,7 @@ static int vidioc_g_chip_ident(struct file *file, void *priv,
1186 chip->ident = V4L2_IDENT_NONE; 1185 chip->ident = V4L2_IDENT_NONE;
1187 chip->revision = 0; 1186 chip->revision = 0;
1188 1187
1189 em28xx_i2c_call_clients(dev, VIDIOC_DBG_G_CHIP_IDENT, chip); 1188 v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_chip_ident, chip);
1190 1189
1191 return 0; 1190 return 0;
1192} 1191}
@@ -1211,7 +1210,7 @@ static int vidioc_g_register(struct file *file, void *priv,
1211 reg->size = 1; 1210 reg->size = 1;
1212 return 0; 1211 return 0;
1213 case V4L2_CHIP_MATCH_I2C_DRIVER: 1212 case V4L2_CHIP_MATCH_I2C_DRIVER:
1214 em28xx_i2c_call_clients(dev, VIDIOC_DBG_G_REGISTER, reg); 1213 v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_register, reg);
1215 return 0; 1214 return 0;
1216 case V4L2_CHIP_MATCH_I2C_ADDR: 1215 case V4L2_CHIP_MATCH_I2C_ADDR:
1217 /* Not supported yet */ 1216 /* Not supported yet */
@@ -1263,7 +1262,7 @@ static int vidioc_s_register(struct file *file, void *priv,
1263 1262
1264 return rc; 1263 return rc;
1265 case V4L2_CHIP_MATCH_I2C_DRIVER: 1264 case V4L2_CHIP_MATCH_I2C_DRIVER:
1266 em28xx_i2c_call_clients(dev, VIDIOC_DBG_S_REGISTER, reg); 1265 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_register, reg);
1267 return 0; 1266 return 0;
1268 case V4L2_CHIP_MATCH_I2C_ADDR: 1267 case V4L2_CHIP_MATCH_I2C_ADDR:
1269 /* Not supported yet */ 1268 /* Not supported yet */
@@ -1406,13 +1405,13 @@ static int vidioc_g_fmt_sliced_vbi_cap(struct file *file, void *priv,
1406 mutex_lock(&dev->lock); 1405 mutex_lock(&dev->lock);
1407 1406
1408 f->fmt.sliced.service_set = 0; 1407 f->fmt.sliced.service_set = 0;
1409 1408 v4l2_device_call_all(&dev->v4l2_dev, 0, video, g_fmt, f);
1410 em28xx_i2c_call_clients(dev, VIDIOC_G_FMT, f);
1411 1409
1412 if (f->fmt.sliced.service_set == 0) 1410 if (f->fmt.sliced.service_set == 0)
1413 rc = -EINVAL; 1411 rc = -EINVAL;
1414 1412
1415 mutex_unlock(&dev->lock); 1413 mutex_unlock(&dev->lock);
1414
1416 return rc; 1415 return rc;
1417} 1416}
1418 1417
@@ -1428,7 +1427,7 @@ static int vidioc_try_set_sliced_vbi_cap(struct file *file, void *priv,
1428 return rc; 1427 return rc;
1429 1428
1430 mutex_lock(&dev->lock); 1429 mutex_lock(&dev->lock);
1431 em28xx_i2c_call_clients(dev, VIDIOC_G_FMT, f); 1430 v4l2_device_call_all(&dev->v4l2_dev, 0, video, g_fmt, f);
1432 mutex_unlock(&dev->lock); 1431 mutex_unlock(&dev->lock);
1433 1432
1434 if (f->fmt.sliced.service_set == 0) 1433 if (f->fmt.sliced.service_set == 0)
@@ -1532,7 +1531,7 @@ static int radio_g_tuner(struct file *file, void *priv,
1532 t->type = V4L2_TUNER_RADIO; 1531 t->type = V4L2_TUNER_RADIO;
1533 1532
1534 mutex_lock(&dev->lock); 1533 mutex_lock(&dev->lock);
1535 em28xx_i2c_call_clients(dev, VIDIOC_G_TUNER, t); 1534 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_tuner, t);
1536 mutex_unlock(&dev->lock); 1535 mutex_unlock(&dev->lock);
1537 1536
1538 return 0; 1537 return 0;
@@ -1567,7 +1566,7 @@ static int radio_s_tuner(struct file *file, void *priv,
1567 return -EINVAL; 1566 return -EINVAL;
1568 1567
1569 mutex_lock(&dev->lock); 1568 mutex_lock(&dev->lock);
1570 em28xx_i2c_call_clients(dev, VIDIOC_S_TUNER, t); 1569 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_tuner, t);
1571 mutex_unlock(&dev->lock); 1570 mutex_unlock(&dev->lock);
1572 1571
1573 return 0; 1572 return 0;
@@ -1655,7 +1654,7 @@ static int em28xx_v4l2_open(struct file *filp)
1655 } 1654 }
1656 if (fh->radio) { 1655 if (fh->radio) {
1657 em28xx_videodbg("video_open: setting radio device\n"); 1656 em28xx_videodbg("video_open: setting radio device\n");
1658 em28xx_i2c_call_clients(dev, AUDC_SET_RADIO, NULL); 1657 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_radio);
1659 } 1658 }
1660 1659
1661 dev->users++; 1660 dev->users++;
@@ -1738,7 +1737,7 @@ static int em28xx_v4l2_close(struct file *filp)
1738 } 1737 }
1739 1738
1740 /* Save some power by putting tuner to sleep */ 1739 /* Save some power by putting tuner to sleep */
1741 em28xx_i2c_call_clients(dev, TUNER_SET_STANDBY, NULL); 1740 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_standby, 0);
1742 1741
1743 /* do this before setting alternate! */ 1742 /* do this before setting alternate! */
1744 em28xx_uninit_isoc(dev); 1743 em28xx_uninit_isoc(dev);
@@ -1959,11 +1958,12 @@ static struct video_device *em28xx_vdev_init(struct em28xx *dev,
1959 vfd = video_device_alloc(); 1958 vfd = video_device_alloc();
1960 if (NULL == vfd) 1959 if (NULL == vfd)
1961 return NULL; 1960 return NULL;
1962 *vfd = *template; 1961
1963 vfd->minor = -1; 1962 *vfd = *template;
1964 vfd->parent = &dev->udev->dev; 1963 vfd->minor = -1;
1965 vfd->release = video_device_release; 1964 vfd->v4l2_dev = &dev->v4l2_dev;
1966 vfd->debug = video_debug; 1965 vfd->release = video_device_release;
1966 vfd->debug = video_debug;
1967 1967
1968 snprintf(vfd->name, sizeof(vfd->name), "%s %s", 1968 snprintf(vfd->name, sizeof(vfd->name), "%s %s",
1969 dev->name, type_name); 1969 dev->name, type_name);
diff --git a/drivers/media/video/em28xx/em28xx.h b/drivers/media/video/em28xx/em28xx.h
index a33a58da016e..4c4e58004f54 100644
--- a/drivers/media/video/em28xx/em28xx.h
+++ b/drivers/media/video/em28xx/em28xx.h
@@ -27,6 +27,7 @@
27 27
28#include <linux/videodev2.h> 28#include <linux/videodev2.h>
29#include <media/videobuf-vmalloc.h> 29#include <media/videobuf-vmalloc.h>
30#include <media/v4l2-device.h>
30 31
31#include <linux/i2c.h> 32#include <linux/i2c.h>
32#include <linux/mutex.h> 33#include <linux/mutex.h>
@@ -385,6 +386,8 @@ struct em28xx_board {
385 unsigned int valid:1; 386 unsigned int valid:1;
386 387
387 unsigned char xclk, i2c_speed; 388 unsigned char xclk, i2c_speed;
389 unsigned char radio_addr;
390 unsigned short tvaudio_addr;
388 391
389 enum em28xx_decoder decoder; 392 enum em28xx_decoder decoder;
390 enum em28xx_adecoder adecoder; 393 enum em28xx_adecoder adecoder;
@@ -460,6 +463,7 @@ struct em28xx {
460 int devno; /* marks the number of this device */ 463 int devno; /* marks the number of this device */
461 enum em28xx_chip_id chip_id; 464 enum em28xx_chip_id chip_id;
462 465
466 struct v4l2_device v4l2_dev;
463 struct em28xx_board board; 467 struct em28xx_board board;
464 468
465 unsigned int stream_on:1; /* Locks streams */ 469 unsigned int stream_on:1; /* Locks streams */
@@ -577,11 +581,9 @@ struct em28xx_ops {
577}; 581};
578 582
579/* Provided by em28xx-i2c.c */ 583/* Provided by em28xx-i2c.c */
580
581void em28xx_i2c_call_clients(struct em28xx *dev, unsigned int cmd, void *arg);
582void em28xx_do_i2c_scan(struct em28xx *dev); 584void em28xx_do_i2c_scan(struct em28xx *dev);
583int em28xx_i2c_register(struct em28xx *dev); 585int em28xx_i2c_register(struct em28xx *dev);
584int em28xx_i2c_unregister(struct em28xx *dev); 586int em28xx_i2c_unregister(struct em28xx *dev);
585 587
586/* Provided by em28xx-core.c */ 588/* Provided by em28xx-core.c */
587 589