diff options
author | Mauro Carvalho Chehab <mchehab@redhat.com> | 2008-12-28 20:18:14 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2008-12-30 06:39:37 -0500 |
commit | 1a23f81b7dc3115b29cff0e4f58b5dd04a6242ad (patch) | |
tree | 643b900aae78870a53fec3fdf1e15b400ae960c0 /drivers/media/video/em28xx/em28xx-video.c | |
parent | 126be90f720d9b23e89c68519022fb806882f42d (diff) |
V4L/DVB (9979): em28xx: move usb probe code to a proper place
em28xx-video were holding several code that are not specific to V4L2
interface.
This patch moves the core code for em28xx-core, and usb probing code
into em28xx-cards.
This opens the possibility of breaking em28xx into a core module and a
V4L2 module, loaded only on devices that have analog interfaces.
Some cleanup may be done at em28xx-cards to optimize the config code.
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video/em28xx/em28xx-video.c')
-rw-r--r-- | drivers/media/video/em28xx/em28xx-video.c | 619 |
1 files changed, 46 insertions, 573 deletions
diff --git a/drivers/media/video/em28xx/em28xx-video.c b/drivers/media/video/em28xx/em28xx-video.c index b5ea18e12290..4c0986920970 100644 --- a/drivers/media/video/em28xx/em28xx-video.c +++ b/drivers/media/video/em28xx/em28xx-video.c | |||
@@ -48,9 +48,8 @@ | |||
48 | "Mauro Carvalho Chehab <mchehab@infradead.org>, " \ | 48 | "Mauro Carvalho Chehab <mchehab@infradead.org>, " \ |
49 | "Sascha Sommer <saschasommer@freenet.de>" | 49 | "Sascha Sommer <saschasommer@freenet.de>" |
50 | 50 | ||
51 | #define DRIVER_NAME "em28xx" | ||
52 | #define DRIVER_DESC "Empia em28xx based USB video device driver" | 51 | #define DRIVER_DESC "Empia em28xx based USB video device driver" |
53 | #define EM28XX_VERSION_CODE KERNEL_VERSION(0, 1, 0) | 52 | #define EM28XX_VERSION_CODE KERNEL_VERSION(0, 1, 1) |
54 | 53 | ||
55 | #define em28xx_videodbg(fmt, arg...) do {\ | 54 | #define em28xx_videodbg(fmt, arg...) do {\ |
56 | if (video_debug) \ | 55 | if (video_debug) \ |
@@ -73,19 +72,13 @@ MODULE_AUTHOR(DRIVER_AUTHOR); | |||
73 | MODULE_DESCRIPTION(DRIVER_DESC); | 72 | MODULE_DESCRIPTION(DRIVER_DESC); |
74 | MODULE_LICENSE("GPL"); | 73 | MODULE_LICENSE("GPL"); |
75 | 74 | ||
76 | static LIST_HEAD(em28xx_devlist); | ||
77 | static DEFINE_MUTEX(em28xx_devlist_mutex); | ||
78 | |||
79 | static unsigned int card[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET }; | ||
80 | static unsigned int video_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET }; | 75 | static unsigned int video_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET }; |
81 | static unsigned int vbi_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET }; | 76 | static unsigned int vbi_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET }; |
82 | static unsigned int radio_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET }; | 77 | static unsigned int radio_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET }; |
83 | 78 | ||
84 | module_param_array(card, int, NULL, 0444); | ||
85 | module_param_array(video_nr, int, NULL, 0444); | 79 | module_param_array(video_nr, int, NULL, 0444); |
86 | module_param_array(vbi_nr, int, NULL, 0444); | 80 | module_param_array(vbi_nr, int, NULL, 0444); |
87 | module_param_array(radio_nr, int, NULL, 0444); | 81 | module_param_array(radio_nr, int, NULL, 0444); |
88 | MODULE_PARM_DESC(card, "card type"); | ||
89 | MODULE_PARM_DESC(video_nr, "video device numbers"); | 82 | MODULE_PARM_DESC(video_nr, "video device numbers"); |
90 | MODULE_PARM_DESC(vbi_nr, "vbi device numbers"); | 83 | MODULE_PARM_DESC(vbi_nr, "vbi device numbers"); |
91 | MODULE_PARM_DESC(radio_nr, "radio device numbers"); | 84 | MODULE_PARM_DESC(radio_nr, "radio device numbers"); |
@@ -94,9 +87,6 @@ static unsigned int video_debug; | |||
94 | module_param(video_debug, int, 0644); | 87 | module_param(video_debug, int, 0644); |
95 | MODULE_PARM_DESC(video_debug, "enable debug messages [video]"); | 88 | MODULE_PARM_DESC(video_debug, "enable debug messages [video]"); |
96 | 89 | ||
97 | /* Bitmask marking allocated devices from 0 to EM28XX_MAXBOARDS */ | ||
98 | static unsigned long em28xx_devused; | ||
99 | |||
100 | /* supported video standards */ | 90 | /* supported video standards */ |
101 | static struct em28xx_fmt format[] = { | 91 | static struct em28xx_fmt format[] = { |
102 | { | 92 | { |
@@ -131,8 +121,6 @@ static struct v4l2_queryctrl em28xx_qctrl[] = { | |||
131 | } | 121 | } |
132 | }; | 122 | }; |
133 | 123 | ||
134 | static struct usb_driver em28xx_usb_driver; | ||
135 | |||
136 | /* ------------------------------------------------------------------ | 124 | /* ------------------------------------------------------------------ |
137 | DMA and thread functions | 125 | DMA and thread functions |
138 | ------------------------------------------------------------------*/ | 126 | ------------------------------------------------------------------*/ |
@@ -519,56 +507,6 @@ static struct videobuf_queue_ops em28xx_video_qops = { | |||
519 | 507 | ||
520 | /********************* v4l2 interface **************************************/ | 508 | /********************* v4l2 interface **************************************/ |
521 | 509 | ||
522 | /* | ||
523 | * em28xx_config() | ||
524 | * inits registers with sane defaults | ||
525 | */ | ||
526 | static int em28xx_config(struct em28xx *dev) | ||
527 | { | ||
528 | int retval; | ||
529 | |||
530 | /* Sets I2C speed to 100 KHz */ | ||
531 | if (!dev->board.is_em2800) { | ||
532 | retval = em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40); | ||
533 | if (retval < 0) { | ||
534 | em28xx_errdev("%s: em28xx_write_regs_req failed! retval [%d]\n", | ||
535 | __func__, retval); | ||
536 | return retval; | ||
537 | } | ||
538 | } | ||
539 | |||
540 | /* enable vbi capturing */ | ||
541 | |||
542 | /* em28xx_write_reg(dev, EM28XX_R0E_AUDIOSRC, 0xc0); audio register */ | ||
543 | /* em28xx_write_reg(dev, EM28XX_R0F_XCLK, 0x80); clk register */ | ||
544 | em28xx_write_reg(dev, EM28XX_R11_VINCTRL, 0x51); | ||
545 | |||
546 | dev->mute = 1; /* maybe not the right place... */ | ||
547 | dev->volume = 0x1f; | ||
548 | |||
549 | em28xx_set_outfmt(dev); | ||
550 | em28xx_colorlevels_set_default(dev); | ||
551 | em28xx_compression_disable(dev); | ||
552 | |||
553 | return 0; | ||
554 | } | ||
555 | |||
556 | /* | ||
557 | * em28xx_config_i2c() | ||
558 | * configure i2c attached devices | ||
559 | */ | ||
560 | static void em28xx_config_i2c(struct em28xx *dev) | ||
561 | { | ||
562 | struct v4l2_routing route; | ||
563 | int zero = 0; | ||
564 | |||
565 | route.input = INPUT(dev->ctl_input)->vmux; | ||
566 | route.output = 0; | ||
567 | em28xx_i2c_call_clients(dev, VIDIOC_INT_RESET, &zero); | ||
568 | em28xx_i2c_call_clients(dev, VIDIOC_INT_S_VIDEO_ROUTING, &route); | ||
569 | em28xx_i2c_call_clients(dev, VIDIOC_STREAMON, NULL); | ||
570 | } | ||
571 | |||
572 | static void video_mux(struct em28xx *dev, int index) | 510 | static void video_mux(struct em28xx *dev, int index) |
573 | { | 511 | { |
574 | struct v4l2_routing route; | 512 | struct v4l2_routing route; |
@@ -1647,28 +1585,12 @@ static int radio_queryctrl(struct file *file, void *priv, | |||
1647 | static int em28xx_v4l2_open(struct inode *inode, struct file *filp) | 1585 | static int em28xx_v4l2_open(struct inode *inode, struct file *filp) |
1648 | { | 1586 | { |
1649 | int minor = iminor(inode); | 1587 | int minor = iminor(inode); |
1650 | int errCode = 0, radio = 0; | 1588 | int errCode = 0, radio; |
1651 | struct em28xx *h, *dev = NULL; | 1589 | struct em28xx *dev; |
1590 | enum v4l2_buf_type fh_type; | ||
1652 | struct em28xx_fh *fh; | 1591 | struct em28xx_fh *fh; |
1653 | enum v4l2_buf_type fh_type = 0; | ||
1654 | 1592 | ||
1655 | mutex_lock(&em28xx_devlist_mutex); | 1593 | dev = em28xx_get_device(inode, &fh_type, &radio); |
1656 | list_for_each_entry(h, &em28xx_devlist, devlist) { | ||
1657 | if (h->vdev->minor == minor) { | ||
1658 | dev = h; | ||
1659 | fh_type = V4L2_BUF_TYPE_VIDEO_CAPTURE; | ||
1660 | } | ||
1661 | if (h->vbi_dev->minor == minor) { | ||
1662 | dev = h; | ||
1663 | fh_type = V4L2_BUF_TYPE_VBI_CAPTURE; | ||
1664 | } | ||
1665 | if (h->radio_dev && | ||
1666 | h->radio_dev->minor == minor) { | ||
1667 | radio = 1; | ||
1668 | dev = h; | ||
1669 | } | ||
1670 | } | ||
1671 | mutex_unlock(&em28xx_devlist_mutex); | ||
1672 | 1594 | ||
1673 | if (NULL == dev) | 1595 | if (NULL == dev) |
1674 | return -ENODEV; | 1596 | return -ENODEV; |
@@ -1703,7 +1625,7 @@ static int em28xx_v4l2_open(struct inode *inode, struct file *filp) | |||
1703 | /* Needed, since GPIO might have disabled power of | 1625 | /* Needed, since GPIO might have disabled power of |
1704 | some i2c device | 1626 | some i2c device |
1705 | */ | 1627 | */ |
1706 | em28xx_config_i2c(dev); | 1628 | em28xx_wake_i2c(dev); |
1707 | 1629 | ||
1708 | } | 1630 | } |
1709 | if (fh->radio) { | 1631 | if (fh->radio) { |
@@ -1727,18 +1649,11 @@ static int em28xx_v4l2_open(struct inode *inode, struct file *filp) | |||
1727 | * unregisters the v4l2,i2c and usb devices | 1649 | * unregisters the v4l2,i2c and usb devices |
1728 | * called when the device gets disconected or at module unload | 1650 | * called when the device gets disconected or at module unload |
1729 | */ | 1651 | */ |
1730 | static void em28xx_release_resources(struct em28xx *dev) | 1652 | void em28xx_release_analog_resources(struct em28xx *dev) |
1731 | { | 1653 | { |
1732 | 1654 | ||
1733 | /*FIXME: I2C IR should be disconnected */ | 1655 | /*FIXME: I2C IR should be disconnected */ |
1734 | 1656 | ||
1735 | list_del(&dev->devlist); | ||
1736 | if (dev->sbutton_input_dev) | ||
1737 | em28xx_deregister_snapshot_button(dev); | ||
1738 | |||
1739 | if (dev->ir) | ||
1740 | em28xx_ir_fini(dev); | ||
1741 | |||
1742 | if (dev->radio_dev) { | 1657 | if (dev->radio_dev) { |
1743 | if (-1 != dev->radio_dev->minor) | 1658 | if (-1 != dev->radio_dev->minor) |
1744 | video_unregister_device(dev->radio_dev); | 1659 | video_unregister_device(dev->radio_dev); |
@@ -1764,11 +1679,6 @@ static void em28xx_release_resources(struct em28xx *dev) | |||
1764 | video_device_release(dev->vdev); | 1679 | video_device_release(dev->vdev); |
1765 | dev->vdev = NULL; | 1680 | dev->vdev = NULL; |
1766 | } | 1681 | } |
1767 | em28xx_i2c_unregister(dev); | ||
1768 | usb_put_dev(dev->udev); | ||
1769 | |||
1770 | /* Mark device as unused */ | ||
1771 | em28xx_devused &= ~(1<<dev->devno); | ||
1772 | } | 1682 | } |
1773 | 1683 | ||
1774 | /* | 1684 | /* |
@@ -2018,44 +1928,6 @@ static struct video_device em28xx_radio_template = { | |||
2018 | /******************************** usb interface ******************************/ | 1928 | /******************************** usb interface ******************************/ |
2019 | 1929 | ||
2020 | 1930 | ||
2021 | static LIST_HEAD(em28xx_extension_devlist); | ||
2022 | static DEFINE_MUTEX(em28xx_extension_devlist_lock); | ||
2023 | |||
2024 | int em28xx_register_extension(struct em28xx_ops *ops) | ||
2025 | { | ||
2026 | struct em28xx *dev = NULL; | ||
2027 | |||
2028 | mutex_lock(&em28xx_devlist_mutex); | ||
2029 | mutex_lock(&em28xx_extension_devlist_lock); | ||
2030 | list_add_tail(&ops->next, &em28xx_extension_devlist); | ||
2031 | list_for_each_entry(dev, &em28xx_devlist, devlist) { | ||
2032 | if (dev) | ||
2033 | ops->init(dev); | ||
2034 | } | ||
2035 | printk(KERN_INFO "Em28xx: Initialized (%s) extension\n", ops->name); | ||
2036 | mutex_unlock(&em28xx_extension_devlist_lock); | ||
2037 | mutex_unlock(&em28xx_devlist_mutex); | ||
2038 | return 0; | ||
2039 | } | ||
2040 | EXPORT_SYMBOL(em28xx_register_extension); | ||
2041 | |||
2042 | void em28xx_unregister_extension(struct em28xx_ops *ops) | ||
2043 | { | ||
2044 | struct em28xx *dev = NULL; | ||
2045 | |||
2046 | mutex_lock(&em28xx_devlist_mutex); | ||
2047 | list_for_each_entry(dev, &em28xx_devlist, devlist) { | ||
2048 | if (dev) | ||
2049 | ops->fini(dev); | ||
2050 | } | ||
2051 | |||
2052 | mutex_lock(&em28xx_extension_devlist_lock); | ||
2053 | printk(KERN_INFO "Em28xx: Removed (%s) extension\n", ops->name); | ||
2054 | list_del(&ops->next); | ||
2055 | mutex_unlock(&em28xx_extension_devlist_lock); | ||
2056 | mutex_unlock(&em28xx_devlist_mutex); | ||
2057 | } | ||
2058 | EXPORT_SYMBOL(em28xx_unregister_extension); | ||
2059 | 1931 | ||
2060 | static struct video_device *em28xx_vdev_init(struct em28xx *dev, | 1932 | static struct video_device *em28xx_vdev_init(struct em28xx *dev, |
2061 | const struct video_device *template, | 1933 | const struct video_device *template, |
@@ -2078,7 +1950,45 @@ static struct video_device *em28xx_vdev_init(struct em28xx *dev, | |||
2078 | return vfd; | 1950 | return vfd; |
2079 | } | 1951 | } |
2080 | 1952 | ||
2081 | static int register_analog_devices(struct em28xx *dev) | 1953 | int em28xx_analog_config(struct em28xx *dev) |
1954 | { | ||
1955 | printk(KERN_INFO "%s: v4l2 driver version %d.%d.%d\n", | ||
1956 | dev->name, | ||
1957 | (EM28XX_VERSION_CODE >> 16) & 0xff, | ||
1958 | (EM28XX_VERSION_CODE >> 8) & 0xff, EM28XX_VERSION_CODE & 0xff); | ||
1959 | |||
1960 | /* Analog specific initialization */ | ||
1961 | dev->format = &format[0]; | ||
1962 | video_mux(dev, 0); | ||
1963 | |||
1964 | /* enable vbi capturing */ | ||
1965 | |||
1966 | /* em28xx_write_reg(dev, EM28XX_R0E_AUDIOSRC, 0xc0); audio register */ | ||
1967 | /* em28xx_write_reg(dev, EM28XX_R0F_XCLK, 0x80); clk register */ | ||
1968 | em28xx_write_reg(dev, EM28XX_R11_VINCTRL, 0x51); | ||
1969 | |||
1970 | dev->mute = 1; /* maybe not the right place... */ | ||
1971 | dev->volume = 0x1f; | ||
1972 | |||
1973 | em28xx_set_outfmt(dev); | ||
1974 | em28xx_colorlevels_set_default(dev); | ||
1975 | em28xx_compression_disable(dev); | ||
1976 | |||
1977 | /* set default norm */ | ||
1978 | dev->norm = em28xx_video_template.current_norm; | ||
1979 | dev->width = norm_maxw(dev); | ||
1980 | dev->height = norm_maxh(dev); | ||
1981 | dev->interlaced = EM28XX_INTERLACED_DEFAULT; | ||
1982 | dev->hscale = 0; | ||
1983 | dev->vscale = 0; | ||
1984 | |||
1985 | /* FIXME: This is a very bad hack! Not all devices have TV on input 2 */ | ||
1986 | dev->ctl_input = 2; | ||
1987 | |||
1988 | return 0; | ||
1989 | } | ||
1990 | |||
1991 | int em28xx_register_analog_devices(struct em28xx *dev) | ||
2082 | { | 1992 | { |
2083 | int ret; | 1993 | int ret; |
2084 | 1994 | ||
@@ -2130,440 +2040,3 @@ static int register_analog_devices(struct em28xx *dev) | |||
2130 | 2040 | ||
2131 | return 0; | 2041 | return 0; |
2132 | } | 2042 | } |
2133 | |||
2134 | |||
2135 | /* | ||
2136 | * em28xx_init_dev() | ||
2137 | * allocates and inits the device structs, registers i2c bus and v4l device | ||
2138 | */ | ||
2139 | static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev, | ||
2140 | int minor) | ||
2141 | { | ||
2142 | struct em28xx_ops *ops = NULL; | ||
2143 | struct em28xx *dev = *devhandle; | ||
2144 | int retval = -ENOMEM; | ||
2145 | int errCode; | ||
2146 | unsigned int maxh, maxw; | ||
2147 | |||
2148 | dev->udev = udev; | ||
2149 | mutex_init(&dev->ctrl_urb_lock); | ||
2150 | spin_lock_init(&dev->slock); | ||
2151 | init_waitqueue_head(&dev->open); | ||
2152 | init_waitqueue_head(&dev->wait_frame); | ||
2153 | init_waitqueue_head(&dev->wait_stream); | ||
2154 | |||
2155 | dev->em28xx_write_regs = em28xx_write_regs; | ||
2156 | dev->em28xx_read_reg = em28xx_read_reg; | ||
2157 | dev->em28xx_read_reg_req_len = em28xx_read_reg_req_len; | ||
2158 | dev->em28xx_write_regs_req = em28xx_write_regs_req; | ||
2159 | dev->em28xx_read_reg_req = em28xx_read_reg_req; | ||
2160 | dev->board.is_em2800 = em28xx_boards[dev->model].is_em2800; | ||
2161 | dev->format = &format[0]; | ||
2162 | |||
2163 | em28xx_pre_card_setup(dev); | ||
2164 | |||
2165 | errCode = em28xx_config(dev); | ||
2166 | if (errCode) { | ||
2167 | em28xx_errdev("error configuring device\n"); | ||
2168 | return -ENOMEM; | ||
2169 | } | ||
2170 | |||
2171 | /* register i2c bus */ | ||
2172 | errCode = em28xx_i2c_register(dev); | ||
2173 | if (errCode < 0) { | ||
2174 | em28xx_errdev("%s: em28xx_i2c_register - errCode [%d]!\n", | ||
2175 | __func__, errCode); | ||
2176 | return errCode; | ||
2177 | } | ||
2178 | |||
2179 | /* Do board specific init and eeprom reading */ | ||
2180 | em28xx_card_setup(dev); | ||
2181 | |||
2182 | /* Configure audio */ | ||
2183 | errCode = em28xx_audio_setup(dev); | ||
2184 | if (errCode < 0) { | ||
2185 | em28xx_errdev("%s: Error while setting audio - errCode [%d]!\n", | ||
2186 | __func__, errCode); | ||
2187 | } | ||
2188 | |||
2189 | /* configure the device */ | ||
2190 | em28xx_config_i2c(dev); | ||
2191 | |||
2192 | /* set default norm */ | ||
2193 | dev->norm = em28xx_video_template.current_norm; | ||
2194 | |||
2195 | maxw = norm_maxw(dev); | ||
2196 | maxh = norm_maxh(dev); | ||
2197 | |||
2198 | /* set default image size */ | ||
2199 | dev->width = maxw; | ||
2200 | dev->height = maxh; | ||
2201 | dev->interlaced = EM28XX_INTERLACED_DEFAULT; | ||
2202 | dev->hscale = 0; | ||
2203 | dev->vscale = 0; | ||
2204 | dev->ctl_input = 2; | ||
2205 | |||
2206 | errCode = em28xx_config(dev); | ||
2207 | if (errCode < 0) { | ||
2208 | em28xx_errdev("%s: em28xx_config - errCode [%d]!\n", | ||
2209 | __func__, errCode); | ||
2210 | return errCode; | ||
2211 | } | ||
2212 | |||
2213 | /* init video dma queues */ | ||
2214 | INIT_LIST_HEAD(&dev->vidq.active); | ||
2215 | INIT_LIST_HEAD(&dev->vidq.queued); | ||
2216 | |||
2217 | |||
2218 | if (dev->board.has_msp34xx) { | ||
2219 | /* Send a reset to other chips via gpio */ | ||
2220 | errCode = em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xf7); | ||
2221 | if (errCode < 0) { | ||
2222 | em28xx_errdev("%s: em28xx_write_regs_req - msp34xx(1) failed! errCode [%d]\n", | ||
2223 | __func__, errCode); | ||
2224 | return errCode; | ||
2225 | } | ||
2226 | msleep(3); | ||
2227 | |||
2228 | errCode = em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xff); | ||
2229 | if (errCode < 0) { | ||
2230 | em28xx_errdev("%s: em28xx_write_regs_req - msp34xx(2) failed! errCode [%d]\n", | ||
2231 | __func__, errCode); | ||
2232 | return errCode; | ||
2233 | } | ||
2234 | msleep(3); | ||
2235 | } | ||
2236 | |||
2237 | video_mux(dev, 0); | ||
2238 | |||
2239 | mutex_lock(&em28xx_devlist_mutex); | ||
2240 | list_add_tail(&dev->devlist, &em28xx_devlist); | ||
2241 | retval = register_analog_devices(dev); | ||
2242 | if (retval < 0) { | ||
2243 | em28xx_release_resources(dev); | ||
2244 | mutex_unlock(&em28xx_devlist_mutex); | ||
2245 | goto fail_reg_devices; | ||
2246 | } | ||
2247 | |||
2248 | mutex_lock(&em28xx_extension_devlist_lock); | ||
2249 | if (!list_empty(&em28xx_extension_devlist)) { | ||
2250 | list_for_each_entry(ops, &em28xx_extension_devlist, next) { | ||
2251 | if (ops->id) | ||
2252 | ops->init(dev); | ||
2253 | } | ||
2254 | } | ||
2255 | mutex_unlock(&em28xx_extension_devlist_lock); | ||
2256 | mutex_unlock(&em28xx_devlist_mutex); | ||
2257 | |||
2258 | /* Save some power by putting tuner to sleep */ | ||
2259 | em28xx_i2c_call_clients(dev, TUNER_SET_STANDBY, NULL); | ||
2260 | |||
2261 | return 0; | ||
2262 | |||
2263 | fail_reg_devices: | ||
2264 | return retval; | ||
2265 | } | ||
2266 | |||
2267 | #if defined(CONFIG_MODULES) && defined(MODULE) | ||
2268 | static void request_module_async(struct work_struct *work) | ||
2269 | { | ||
2270 | struct em28xx *dev = container_of(work, | ||
2271 | struct em28xx, request_module_wk); | ||
2272 | |||
2273 | if (dev->has_audio_class) | ||
2274 | request_module("snd-usb-audio"); | ||
2275 | else if (dev->has_alsa_audio) | ||
2276 | request_module("em28xx-alsa"); | ||
2277 | |||
2278 | if (dev->board.has_dvb) | ||
2279 | request_module("em28xx-dvb"); | ||
2280 | } | ||
2281 | |||
2282 | static void request_modules(struct em28xx *dev) | ||
2283 | { | ||
2284 | INIT_WORK(&dev->request_module_wk, request_module_async); | ||
2285 | schedule_work(&dev->request_module_wk); | ||
2286 | } | ||
2287 | #else | ||
2288 | #define request_modules(dev) | ||
2289 | #endif /* CONFIG_MODULES */ | ||
2290 | |||
2291 | /* | ||
2292 | * em28xx_usb_probe() | ||
2293 | * checks for supported devices | ||
2294 | */ | ||
2295 | static int em28xx_usb_probe(struct usb_interface *interface, | ||
2296 | const struct usb_device_id *id) | ||
2297 | { | ||
2298 | const struct usb_endpoint_descriptor *endpoint; | ||
2299 | struct usb_device *udev; | ||
2300 | struct usb_interface *uif; | ||
2301 | struct em28xx *dev = NULL; | ||
2302 | int retval = -ENODEV; | ||
2303 | int i, nr, ifnum, isoc_pipe; | ||
2304 | char *speed; | ||
2305 | char descr[255] = ""; | ||
2306 | |||
2307 | udev = usb_get_dev(interface_to_usbdev(interface)); | ||
2308 | ifnum = interface->altsetting[0].desc.bInterfaceNumber; | ||
2309 | |||
2310 | /* Check to see next free device and mark as used */ | ||
2311 | nr = find_first_zero_bit(&em28xx_devused, EM28XX_MAXBOARDS); | ||
2312 | em28xx_devused |= 1<<nr; | ||
2313 | |||
2314 | /* Don't register audio interfaces */ | ||
2315 | if (interface->altsetting[0].desc.bInterfaceClass == USB_CLASS_AUDIO) { | ||
2316 | em28xx_err(DRIVER_NAME " audio device (%04x:%04x): " | ||
2317 | "interface %i, class %i\n", | ||
2318 | le16_to_cpu(udev->descriptor.idVendor), | ||
2319 | le16_to_cpu(udev->descriptor.idProduct), | ||
2320 | ifnum, | ||
2321 | interface->altsetting[0].desc.bInterfaceClass); | ||
2322 | |||
2323 | em28xx_devused &= ~(1<<nr); | ||
2324 | return -ENODEV; | ||
2325 | } | ||
2326 | |||
2327 | endpoint = &interface->cur_altsetting->endpoint[0].desc; | ||
2328 | |||
2329 | /* check if the device has the iso in endpoint at the correct place */ | ||
2330 | if ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == | ||
2331 | USB_ENDPOINT_XFER_ISOC && | ||
2332 | (interface->altsetting[1].endpoint[0].desc.wMaxPacketSize == 940)) | ||
2333 | { | ||
2334 | /* It's a newer em2874/em2875 device */ | ||
2335 | isoc_pipe = 0; | ||
2336 | } else { | ||
2337 | int check_interface = 1; | ||
2338 | isoc_pipe = 1; | ||
2339 | endpoint = &interface->cur_altsetting->endpoint[1].desc; | ||
2340 | if ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != | ||
2341 | USB_ENDPOINT_XFER_ISOC) | ||
2342 | check_interface = 0; | ||
2343 | |||
2344 | if ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT) | ||
2345 | check_interface = 0; | ||
2346 | |||
2347 | if (!check_interface) { | ||
2348 | em28xx_err(DRIVER_NAME " video device (%04x:%04x): " | ||
2349 | "interface %i, class %i found.\n", | ||
2350 | le16_to_cpu(udev->descriptor.idVendor), | ||
2351 | le16_to_cpu(udev->descriptor.idProduct), | ||
2352 | ifnum, | ||
2353 | interface->altsetting[0].desc.bInterfaceClass); | ||
2354 | |||
2355 | em28xx_err(DRIVER_NAME " This is an anciliary " | ||
2356 | "interface not used by the driver\n"); | ||
2357 | |||
2358 | em28xx_devused &= ~(1<<nr); | ||
2359 | return -ENODEV; | ||
2360 | } | ||
2361 | } | ||
2362 | |||
2363 | switch (udev->speed) { | ||
2364 | case USB_SPEED_LOW: | ||
2365 | speed = "1.5"; | ||
2366 | break; | ||
2367 | case USB_SPEED_UNKNOWN: | ||
2368 | case USB_SPEED_FULL: | ||
2369 | speed = "12"; | ||
2370 | break; | ||
2371 | case USB_SPEED_HIGH: | ||
2372 | speed = "480"; | ||
2373 | break; | ||
2374 | default: | ||
2375 | speed = "unknown"; | ||
2376 | } | ||
2377 | |||
2378 | if (udev->manufacturer) | ||
2379 | strlcpy(descr, udev->manufacturer, sizeof(descr)); | ||
2380 | |||
2381 | if (udev->product) { | ||
2382 | if (*descr) | ||
2383 | strlcat(descr, " ", sizeof(descr)); | ||
2384 | strlcat(descr, udev->product, sizeof(descr)); | ||
2385 | } | ||
2386 | if (*descr) | ||
2387 | strlcat(descr, " ", sizeof(descr)); | ||
2388 | |||
2389 | printk(DRIVER_NAME ": New device %s@ %s Mbps " | ||
2390 | "(%04x:%04x, interface %d, class %d)\n", | ||
2391 | descr, | ||
2392 | speed, | ||
2393 | le16_to_cpu(udev->descriptor.idVendor), | ||
2394 | le16_to_cpu(udev->descriptor.idProduct), | ||
2395 | ifnum, | ||
2396 | interface->altsetting->desc.bInterfaceNumber); | ||
2397 | |||
2398 | if (nr >= EM28XX_MAXBOARDS) { | ||
2399 | printk(DRIVER_NAME ": Supports only %i em28xx boards.\n", | ||
2400 | EM28XX_MAXBOARDS); | ||
2401 | em28xx_devused &= ~(1<<nr); | ||
2402 | return -ENOMEM; | ||
2403 | } | ||
2404 | |||
2405 | /* allocate memory for our device state and initialize it */ | ||
2406 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); | ||
2407 | if (dev == NULL) { | ||
2408 | em28xx_err(DRIVER_NAME ": out of memory!\n"); | ||
2409 | em28xx_devused &= ~(1<<nr); | ||
2410 | return -ENOMEM; | ||
2411 | } | ||
2412 | |||
2413 | snprintf(dev->name, 29, "em28xx #%d", nr); | ||
2414 | dev->devno = nr; | ||
2415 | dev->model = id->driver_info; | ||
2416 | dev->alt = -1; | ||
2417 | |||
2418 | /* Checks if audio is provided by some interface */ | ||
2419 | for (i = 0; i < udev->config->desc.bNumInterfaces; i++) { | ||
2420 | uif = udev->config->interface[i]; | ||
2421 | if (uif->altsetting[0].desc.bInterfaceClass == USB_CLASS_AUDIO) { | ||
2422 | dev->has_audio_class = 1; | ||
2423 | break; | ||
2424 | } | ||
2425 | } | ||
2426 | |||
2427 | /* compute alternate max packet sizes */ | ||
2428 | uif = udev->actconfig->interface[0]; | ||
2429 | |||
2430 | dev->num_alt = uif->num_altsetting; | ||
2431 | em28xx_videodbg("Alternate settings: %i\n", dev->num_alt); | ||
2432 | /* dev->alt_max_pkt_size = kmalloc(sizeof(*dev->alt_max_pkt_size)* */ | ||
2433 | dev->alt_max_pkt_size = kmalloc(32 * dev->num_alt, GFP_KERNEL); | ||
2434 | |||
2435 | if (dev->alt_max_pkt_size == NULL) { | ||
2436 | em28xx_errdev("out of memory!\n"); | ||
2437 | em28xx_devused &= ~(1<<nr); | ||
2438 | kfree(dev); | ||
2439 | return -ENOMEM; | ||
2440 | } | ||
2441 | |||
2442 | for (i = 0; i < dev->num_alt ; i++) { | ||
2443 | u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].desc. | ||
2444 | wMaxPacketSize); | ||
2445 | dev->alt_max_pkt_size[i] = | ||
2446 | (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1); | ||
2447 | em28xx_videodbg("Alternate setting %i, max size= %i\n", i, | ||
2448 | dev->alt_max_pkt_size[i]); | ||
2449 | } | ||
2450 | |||
2451 | if ((card[nr] >= 0) && (card[nr] < em28xx_bcount)) | ||
2452 | dev->model = card[nr]; | ||
2453 | |||
2454 | /* allocate device struct */ | ||
2455 | mutex_init(&dev->lock); | ||
2456 | mutex_lock(&dev->lock); | ||
2457 | retval = em28xx_init_dev(&dev, udev, nr); | ||
2458 | if (retval) { | ||
2459 | em28xx_devused &= ~(1<<dev->devno); | ||
2460 | kfree(dev); | ||
2461 | |||
2462 | return retval; | ||
2463 | } | ||
2464 | |||
2465 | /* save our data pointer in this interface device */ | ||
2466 | usb_set_intfdata(interface, dev); | ||
2467 | |||
2468 | request_modules(dev); | ||
2469 | |||
2470 | /* Should be the last thing to do, to avoid newer udev's to | ||
2471 | open the device before fully initializing it | ||
2472 | */ | ||
2473 | mutex_unlock(&dev->lock); | ||
2474 | |||
2475 | return 0; | ||
2476 | } | ||
2477 | |||
2478 | /* | ||
2479 | * em28xx_usb_disconnect() | ||
2480 | * called when the device gets diconencted | ||
2481 | * video device will be unregistered on v4l2_close in case it is still open | ||
2482 | */ | ||
2483 | static void em28xx_usb_disconnect(struct usb_interface *interface) | ||
2484 | { | ||
2485 | struct em28xx *dev; | ||
2486 | struct em28xx_ops *ops = NULL; | ||
2487 | |||
2488 | dev = usb_get_intfdata(interface); | ||
2489 | usb_set_intfdata(interface, NULL); | ||
2490 | |||
2491 | if (!dev) | ||
2492 | return; | ||
2493 | |||
2494 | em28xx_info("disconnecting %s\n", dev->vdev->name); | ||
2495 | |||
2496 | /* wait until all current v4l2 io is finished then deallocate | ||
2497 | resources */ | ||
2498 | mutex_lock(&dev->lock); | ||
2499 | |||
2500 | wake_up_interruptible_all(&dev->open); | ||
2501 | |||
2502 | if (dev->users) { | ||
2503 | em28xx_warn | ||
2504 | ("device /dev/video%d is open! Deregistration and memory " | ||
2505 | "deallocation are deferred on close.\n", | ||
2506 | dev->vdev->num); | ||
2507 | |||
2508 | dev->state |= DEV_MISCONFIGURED; | ||
2509 | em28xx_uninit_isoc(dev); | ||
2510 | dev->state |= DEV_DISCONNECTED; | ||
2511 | wake_up_interruptible(&dev->wait_frame); | ||
2512 | wake_up_interruptible(&dev->wait_stream); | ||
2513 | } else { | ||
2514 | dev->state |= DEV_DISCONNECTED; | ||
2515 | em28xx_release_resources(dev); | ||
2516 | } | ||
2517 | mutex_unlock(&dev->lock); | ||
2518 | |||
2519 | mutex_lock(&em28xx_extension_devlist_lock); | ||
2520 | if (!list_empty(&em28xx_extension_devlist)) { | ||
2521 | list_for_each_entry(ops, &em28xx_extension_devlist, next) { | ||
2522 | ops->fini(dev); | ||
2523 | } | ||
2524 | } | ||
2525 | mutex_unlock(&em28xx_extension_devlist_lock); | ||
2526 | |||
2527 | if (!dev->users) { | ||
2528 | kfree(dev->alt_max_pkt_size); | ||
2529 | kfree(dev); | ||
2530 | } | ||
2531 | } | ||
2532 | |||
2533 | static struct usb_driver em28xx_usb_driver = { | ||
2534 | .name = "em28xx", | ||
2535 | .probe = em28xx_usb_probe, | ||
2536 | .disconnect = em28xx_usb_disconnect, | ||
2537 | .id_table = em28xx_id_table, | ||
2538 | }; | ||
2539 | |||
2540 | static int __init em28xx_module_init(void) | ||
2541 | { | ||
2542 | int result; | ||
2543 | |||
2544 | printk(KERN_INFO DRIVER_NAME " v4l2 driver version %d.%d.%d loaded\n", | ||
2545 | (EM28XX_VERSION_CODE >> 16) & 0xff, | ||
2546 | (EM28XX_VERSION_CODE >> 8) & 0xff, EM28XX_VERSION_CODE & 0xff); | ||
2547 | #ifdef SNAPSHOT | ||
2548 | printk(KERN_INFO DRIVER_NAME " snapshot date %04d-%02d-%02d\n", | ||
2549 | SNAPSHOT / 10000, (SNAPSHOT / 100) % 100, SNAPSHOT % 100); | ||
2550 | #endif | ||
2551 | |||
2552 | /* register this driver with the USB subsystem */ | ||
2553 | result = usb_register(&em28xx_usb_driver); | ||
2554 | if (result) | ||
2555 | em28xx_err(DRIVER_NAME | ||
2556 | " usb_register failed. Error number %d.\n", result); | ||
2557 | |||
2558 | return result; | ||
2559 | } | ||
2560 | |||
2561 | static void __exit em28xx_module_exit(void) | ||
2562 | { | ||
2563 | /* deregister this driver with the USB subsystem */ | ||
2564 | usb_deregister(&em28xx_usb_driver); | ||
2565 | } | ||
2566 | |||
2567 | module_init(em28xx_module_init); | ||
2568 | module_exit(em28xx_module_exit); | ||
2569 | |||