aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/pvrusb2/pvrusb2-hdw.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/video/pvrusb2/pvrusb2-hdw.c')
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-hdw.c648
1 files changed, 542 insertions, 106 deletions
diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw.c b/drivers/media/video/pvrusb2/pvrusb2-hdw.c
index fa304e5f252a..7a65b42a4f53 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-hdw.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw.c
@@ -24,17 +24,22 @@
24#include <linux/firmware.h> 24#include <linux/firmware.h>
25#include <linux/videodev2.h> 25#include <linux/videodev2.h>
26#include <media/v4l2-common.h> 26#include <media/v4l2-common.h>
27#include <media/tuner.h>
27#include "pvrusb2.h" 28#include "pvrusb2.h"
28#include "pvrusb2-std.h" 29#include "pvrusb2-std.h"
29#include "pvrusb2-util.h" 30#include "pvrusb2-util.h"
30#include "pvrusb2-hdw.h" 31#include "pvrusb2-hdw.h"
31#include "pvrusb2-i2c-core.h" 32#include "pvrusb2-i2c-core.h"
32#include "pvrusb2-tuner.h"
33#include "pvrusb2-eeprom.h" 33#include "pvrusb2-eeprom.h"
34#include "pvrusb2-hdw-internal.h" 34#include "pvrusb2-hdw-internal.h"
35#include "pvrusb2-encoder.h" 35#include "pvrusb2-encoder.h"
36#include "pvrusb2-debug.h" 36#include "pvrusb2-debug.h"
37#include "pvrusb2-fx2-cmd.h" 37#include "pvrusb2-fx2-cmd.h"
38#include "pvrusb2-wm8775.h"
39#include "pvrusb2-video-v4l.h"
40#include "pvrusb2-cx2584x-v4l.h"
41#include "pvrusb2-cs53l32a.h"
42#include "pvrusb2-audio.h"
38 43
39#define TV_MIN_FREQ 55250000L 44#define TV_MIN_FREQ 55250000L
40#define TV_MAX_FREQ 850000000L 45#define TV_MAX_FREQ 850000000L
@@ -104,6 +109,39 @@ MODULE_PARM_DESC(radio_freq, "specify initial radio frequency");
104/* size of a firmware chunk */ 109/* size of a firmware chunk */
105#define FIRMWARE_CHUNK_SIZE 0x2000 110#define FIRMWARE_CHUNK_SIZE 0x2000
106 111
112typedef void (*pvr2_subdev_update_func)(struct pvr2_hdw *,
113 struct v4l2_subdev *);
114
115static const pvr2_subdev_update_func pvr2_module_update_functions[] = {
116 [PVR2_CLIENT_ID_WM8775] = pvr2_wm8775_subdev_update,
117 [PVR2_CLIENT_ID_SAA7115] = pvr2_saa7115_subdev_update,
118 [PVR2_CLIENT_ID_MSP3400] = pvr2_msp3400_subdev_update,
119 [PVR2_CLIENT_ID_CX25840] = pvr2_cx25840_subdev_update,
120 [PVR2_CLIENT_ID_CS53L32A] = pvr2_cs53l32a_subdev_update,
121};
122
123static const char *module_names[] = {
124 [PVR2_CLIENT_ID_MSP3400] = "msp3400",
125 [PVR2_CLIENT_ID_CX25840] = "cx25840",
126 [PVR2_CLIENT_ID_SAA7115] = "saa7115",
127 [PVR2_CLIENT_ID_TUNER] = "tuner",
128 [PVR2_CLIENT_ID_DEMOD] = "tuner",
129 [PVR2_CLIENT_ID_CS53L32A] = "cs53l32a",
130 [PVR2_CLIENT_ID_WM8775] = "wm8775",
131};
132
133
134static const unsigned char *module_i2c_addresses[] = {
135 [PVR2_CLIENT_ID_TUNER] = "\x60\x61\x62\x63",
136 [PVR2_CLIENT_ID_DEMOD] = "\x43",
137 [PVR2_CLIENT_ID_MSP3400] = "\x40",
138 [PVR2_CLIENT_ID_SAA7115] = "\x21",
139 [PVR2_CLIENT_ID_WM8775] = "\x1b",
140 [PVR2_CLIENT_ID_CX25840] = "\x44",
141 [PVR2_CLIENT_ID_CS53L32A] = "\x11",
142};
143
144
107/* Define the list of additional controls we'll dynamically construct based 145/* Define the list of additional controls we'll dynamically construct based
108 on query of the cx2341x module. */ 146 on query of the cx2341x module. */
109struct pvr2_mpeg_ids { 147struct pvr2_mpeg_ids {
@@ -277,7 +315,6 @@ static int pvr2_hdw_set_input(struct pvr2_hdw *hdw,int v);
277static void pvr2_hdw_state_sched(struct pvr2_hdw *); 315static void pvr2_hdw_state_sched(struct pvr2_hdw *);
278static int pvr2_hdw_state_eval(struct pvr2_hdw *); 316static int pvr2_hdw_state_eval(struct pvr2_hdw *);
279static void pvr2_hdw_set_cur_freq(struct pvr2_hdw *,unsigned long); 317static void pvr2_hdw_set_cur_freq(struct pvr2_hdw *,unsigned long);
280static void pvr2_hdw_worker_i2c(struct work_struct *work);
281static void pvr2_hdw_worker_poll(struct work_struct *work); 318static void pvr2_hdw_worker_poll(struct work_struct *work);
282static int pvr2_hdw_wait(struct pvr2_hdw *,int state); 319static int pvr2_hdw_wait(struct pvr2_hdw *,int state);
283static int pvr2_hdw_untrip_unlocked(struct pvr2_hdw *); 320static int pvr2_hdw_untrip_unlocked(struct pvr2_hdw *);
@@ -642,7 +679,7 @@ static int ctrl_freq_max_get(struct pvr2_ctrl *cptr, int *vp)
642 unsigned long fv; 679 unsigned long fv;
643 struct pvr2_hdw *hdw = cptr->hdw; 680 struct pvr2_hdw *hdw = cptr->hdw;
644 if (hdw->tuner_signal_stale) { 681 if (hdw->tuner_signal_stale) {
645 pvr2_i2c_core_status_poll(hdw); 682 pvr2_hdw_status_poll(hdw);
646 } 683 }
647 fv = hdw->tuner_signal_info.rangehigh; 684 fv = hdw->tuner_signal_info.rangehigh;
648 if (!fv) { 685 if (!fv) {
@@ -664,7 +701,7 @@ static int ctrl_freq_min_get(struct pvr2_ctrl *cptr, int *vp)
664 unsigned long fv; 701 unsigned long fv;
665 struct pvr2_hdw *hdw = cptr->hdw; 702 struct pvr2_hdw *hdw = cptr->hdw;
666 if (hdw->tuner_signal_stale) { 703 if (hdw->tuner_signal_stale) {
667 pvr2_i2c_core_status_poll(hdw); 704 pvr2_hdw_status_poll(hdw);
668 } 705 }
669 fv = hdw->tuner_signal_info.rangelow; 706 fv = hdw->tuner_signal_info.rangelow;
670 if (!fv) { 707 if (!fv) {
@@ -858,7 +895,7 @@ static void ctrl_stdcur_clear_dirty(struct pvr2_ctrl *cptr)
858static int ctrl_signal_get(struct pvr2_ctrl *cptr,int *vp) 895static int ctrl_signal_get(struct pvr2_ctrl *cptr,int *vp)
859{ 896{
860 struct pvr2_hdw *hdw = cptr->hdw; 897 struct pvr2_hdw *hdw = cptr->hdw;
861 pvr2_i2c_core_status_poll(hdw); 898 pvr2_hdw_status_poll(hdw);
862 *vp = hdw->tuner_signal_info.signal; 899 *vp = hdw->tuner_signal_info.signal;
863 return 0; 900 return 0;
864} 901}
@@ -868,7 +905,7 @@ static int ctrl_audio_modes_present_get(struct pvr2_ctrl *cptr,int *vp)
868 int val = 0; 905 int val = 0;
869 unsigned int subchan; 906 unsigned int subchan;
870 struct pvr2_hdw *hdw = cptr->hdw; 907 struct pvr2_hdw *hdw = cptr->hdw;
871 pvr2_i2c_core_status_poll(hdw); 908 pvr2_hdw_status_poll(hdw);
872 subchan = hdw->tuner_signal_info.rxsubchans; 909 subchan = hdw->tuner_signal_info.rxsubchans;
873 if (subchan & V4L2_TUNER_SUB_MONO) { 910 if (subchan & V4L2_TUNER_SUB_MONO) {
874 val |= (1 << V4L2_TUNER_MODE_MONO); 911 val |= (1 << V4L2_TUNER_MODE_MONO);
@@ -1283,6 +1320,12 @@ const char *pvr2_hdw_get_bus_info(struct pvr2_hdw *hdw)
1283} 1320}
1284 1321
1285 1322
1323const char *pvr2_hdw_get_device_identifier(struct pvr2_hdw *hdw)
1324{
1325 return hdw->identifier;
1326}
1327
1328
1286unsigned long pvr2_hdw_get_cur_freq(struct pvr2_hdw *hdw) 1329unsigned long pvr2_hdw_get_cur_freq(struct pvr2_hdw *hdw)
1287{ 1330{
1288 return hdw->freqSelector ? hdw->freqValTelevision : hdw->freqValRadio; 1331 return hdw->freqSelector ? hdw->freqValTelevision : hdw->freqValRadio;
@@ -1634,33 +1677,27 @@ static const char *pvr2_get_state_name(unsigned int st)
1634 1677
1635static int pvr2_decoder_enable(struct pvr2_hdw *hdw,int enablefl) 1678static int pvr2_decoder_enable(struct pvr2_hdw *hdw,int enablefl)
1636{ 1679{
1637 if (!hdw->decoder_ctrl) { 1680 /* Even though we really only care about the video decoder chip at
1638 if (!hdw->flag_decoder_missed) { 1681 this point, we'll broadcast stream on/off to all sub-devices
1639 pvr2_trace(PVR2_TRACE_ERROR_LEGS, 1682 anyway, just in case somebody else wants to hear the
1640 "WARNING: No decoder present"); 1683 command... */
1641 hdw->flag_decoder_missed = !0; 1684 pvr2_trace(PVR2_TRACE_CHIPS, "subdev v4l2 stream=%s",
1642 trace_stbit("flag_decoder_missed", 1685 (enablefl ? "on" : "off"));
1643 hdw->flag_decoder_missed); 1686 v4l2_device_call_all(&hdw->v4l2_dev, 0, video, s_stream, enablefl);
1644 } 1687 if (hdw->decoder_client_id) {
1645 return -EIO; 1688 /* We get here if the encoder has been noticed. Otherwise
1689 we'll issue a warning to the user (which should
1690 normally never happen). */
1691 return 0;
1646 } 1692 }
1647 hdw->decoder_ctrl->enable(hdw->decoder_ctrl->ctxt,enablefl); 1693 if (!hdw->flag_decoder_missed) {
1648 return 0; 1694 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
1649} 1695 "WARNING: No decoder present");
1650 1696 hdw->flag_decoder_missed = !0;
1651
1652void pvr2_hdw_set_decoder(struct pvr2_hdw *hdw,struct pvr2_decoder_ctrl *ptr)
1653{
1654 if (hdw->decoder_ctrl == ptr) return;
1655 hdw->decoder_ctrl = ptr;
1656 if (hdw->decoder_ctrl && hdw->flag_decoder_missed) {
1657 hdw->flag_decoder_missed = 0;
1658 trace_stbit("flag_decoder_missed", 1697 trace_stbit("flag_decoder_missed",
1659 hdw->flag_decoder_missed); 1698 hdw->flag_decoder_missed);
1660 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
1661 "Decoder has appeared");
1662 pvr2_hdw_state_sched(hdw);
1663 } 1699 }
1700 return -EIO;
1664} 1701}
1665 1702
1666 1703
@@ -1927,6 +1964,166 @@ static void pvr2_hdw_setup_std(struct pvr2_hdw *hdw)
1927} 1964}
1928 1965
1929 1966
1967static unsigned int pvr2_copy_i2c_addr_list(
1968 unsigned short *dst, const unsigned char *src,
1969 unsigned int dst_max)
1970{
1971 unsigned int cnt = 0;
1972 if (!src) return 0;
1973 while (src[cnt] && (cnt + 1) < dst_max) {
1974 dst[cnt] = src[cnt];
1975 cnt++;
1976 }
1977 dst[cnt] = I2C_CLIENT_END;
1978 return cnt;
1979}
1980
1981
1982static int pvr2_hdw_load_subdev(struct pvr2_hdw *hdw,
1983 const struct pvr2_device_client_desc *cd)
1984{
1985 const char *fname;
1986 unsigned char mid;
1987 struct v4l2_subdev *sd;
1988 unsigned int i2ccnt;
1989 const unsigned char *p;
1990 /* Arbitrary count - max # i2c addresses we will probe */
1991 unsigned short i2caddr[25];
1992
1993 mid = cd->module_id;
1994 fname = (mid < ARRAY_SIZE(module_names)) ? module_names[mid] : NULL;
1995 if (!fname) {
1996 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
1997 "Module ID %u for device %s has no name",
1998 mid,
1999 hdw->hdw_desc->description);
2000 return -EINVAL;
2001 }
2002 pvr2_trace(PVR2_TRACE_INIT,
2003 "Module ID %u (%s) for device %s being loaded...",
2004 mid, fname,
2005 hdw->hdw_desc->description);
2006
2007 i2ccnt = pvr2_copy_i2c_addr_list(i2caddr, cd->i2c_address_list,
2008 ARRAY_SIZE(i2caddr));
2009 if (!i2ccnt && ((p = (mid < ARRAY_SIZE(module_i2c_addresses)) ?
2010 module_i2c_addresses[mid] : NULL) != NULL)) {
2011 /* Second chance: Try default i2c address list */
2012 i2ccnt = pvr2_copy_i2c_addr_list(i2caddr, p,
2013 ARRAY_SIZE(i2caddr));
2014 if (i2ccnt) {
2015 pvr2_trace(PVR2_TRACE_INIT,
2016 "Module ID %u:"
2017 " Using default i2c address list",
2018 mid);
2019 }
2020 }
2021
2022 if (!i2ccnt) {
2023 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
2024 "Module ID %u (%s) for device %s:"
2025 " No i2c addresses",
2026 mid, fname, hdw->hdw_desc->description);
2027 return -EINVAL;
2028 }
2029
2030 /* Note how the 2nd and 3rd arguments are the same for both
2031 * v4l2_i2c_new_subdev() and v4l2_i2c_new_probed_subdev(). Why?
2032 * Well the 2nd argument is the module name to load, while the 3rd
2033 * argument is documented in the framework as being the "chipid" -
2034 * and every other place where I can find examples of this, the
2035 * "chipid" appears to just be the module name again. So here we
2036 * just do the same thing. */
2037 if (i2ccnt == 1) {
2038 pvr2_trace(PVR2_TRACE_INIT,
2039 "Module ID %u:"
2040 " Setting up with specified i2c address 0x%x",
2041 mid, i2caddr[0]);
2042 sd = v4l2_i2c_new_subdev(&hdw->i2c_adap,
2043 fname, fname,
2044 i2caddr[0]);
2045 } else {
2046 pvr2_trace(PVR2_TRACE_INIT,
2047 "Module ID %u:"
2048 " Setting up with address probe list",
2049 mid);
2050 sd = v4l2_i2c_new_probed_subdev(&hdw->i2c_adap,
2051 fname, fname,
2052 i2caddr);
2053 }
2054
2055 if (!sd) {
2056 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
2057 "Module ID %u (%s) for device %s failed to load",
2058 mid, fname, hdw->hdw_desc->description);
2059 return -EIO;
2060 }
2061
2062 /* Tag this sub-device instance with the module ID we know about.
2063 In other places we'll use that tag to determine if the instance
2064 requires special handling. */
2065 sd->grp_id = mid;
2066
2067 pvr2_trace(PVR2_TRACE_INFO, "Attached sub-driver %s", fname);
2068
2069
2070 /* client-specific setup... */
2071 switch (mid) {
2072 case PVR2_CLIENT_ID_CX25840:
2073 hdw->decoder_client_id = mid;
2074 {
2075 /*
2076 Mike Isely <isely@pobox.com> 19-Nov-2006 - This
2077 bit of nuttiness for cx25840 causes that module
2078 to correctly set up its video scaling. This is
2079 really a problem in the cx25840 module itself,
2080 but we work around it here. The problem has not
2081 been seen in ivtv because there VBI is supported
2082 and set up. We don't do VBI here (at least not
2083 yet) and thus we never attempted to even set it
2084 up.
2085 */
2086 struct v4l2_format fmt;
2087 pvr2_trace(PVR2_TRACE_INIT,
2088 "Module ID %u:"
2089 " Executing cx25840 VBI hack",
2090 mid);
2091 memset(&fmt, 0, sizeof(fmt));
2092 fmt.type = V4L2_BUF_TYPE_SLICED_VBI_CAPTURE;
2093 v4l2_device_call_all(&hdw->v4l2_dev, mid,
2094 video, s_fmt, &fmt);
2095 }
2096 break;
2097 case PVR2_CLIENT_ID_SAA7115:
2098 hdw->decoder_client_id = mid;
2099 break;
2100 default: break;
2101 }
2102
2103 return 0;
2104}
2105
2106
2107static void pvr2_hdw_load_modules(struct pvr2_hdw *hdw)
2108{
2109 unsigned int idx;
2110 const struct pvr2_string_table *cm;
2111 const struct pvr2_device_client_table *ct;
2112 int okFl = !0;
2113
2114 cm = &hdw->hdw_desc->client_modules;
2115 for (idx = 0; idx < cm->cnt; idx++) {
2116 request_module(cm->lst[idx]);
2117 }
2118
2119 ct = &hdw->hdw_desc->client_table;
2120 for (idx = 0; idx < ct->cnt; idx++) {
2121 if (pvr2_hdw_load_subdev(hdw, &ct->lst[idx]) < 0) okFl = 0;
2122 }
2123 if (!okFl) pvr2_hdw_render_useless(hdw);
2124}
2125
2126
1930static void pvr2_hdw_setup_low(struct pvr2_hdw *hdw) 2127static void pvr2_hdw_setup_low(struct pvr2_hdw *hdw)
1931{ 2128{
1932 int ret; 2129 int ret;
@@ -1966,9 +2163,7 @@ static void pvr2_hdw_setup_low(struct pvr2_hdw *hdw)
1966 2163
1967 if (!pvr2_hdw_dev_ok(hdw)) return; 2164 if (!pvr2_hdw_dev_ok(hdw)) return;
1968 2165
1969 for (idx = 0; idx < hdw->hdw_desc->client_modules.cnt; idx++) { 2166 hdw->force_dirty = !0;
1970 request_module(hdw->hdw_desc->client_modules.lst[idx]);
1971 }
1972 2167
1973 if (!hdw->hdw_desc->flag_no_powerup) { 2168 if (!hdw->hdw_desc->flag_no_powerup) {
1974 pvr2_hdw_cmd_powerup(hdw); 2169 pvr2_hdw_cmd_powerup(hdw);
@@ -1987,6 +2182,11 @@ static void pvr2_hdw_setup_low(struct pvr2_hdw *hdw)
1987 pvr2_i2c_core_init(hdw); 2182 pvr2_i2c_core_init(hdw);
1988 if (!pvr2_hdw_dev_ok(hdw)) return; 2183 if (!pvr2_hdw_dev_ok(hdw)) return;
1989 2184
2185 pvr2_hdw_load_modules(hdw);
2186 if (!pvr2_hdw_dev_ok(hdw)) return;
2187
2188 v4l2_device_call_all(&hdw->v4l2_dev, 0, core, init, 0);
2189
1990 for (idx = 0; idx < CTRLDEF_COUNT; idx++) { 2190 for (idx = 0; idx < CTRLDEF_COUNT; idx++) {
1991 cptr = hdw->controls + idx; 2191 cptr = hdw->controls + idx;
1992 if (cptr->info->skip_init) continue; 2192 if (cptr->info->skip_init) continue;
@@ -2024,6 +2224,19 @@ static void pvr2_hdw_setup_low(struct pvr2_hdw *hdw)
2024 hdw->std_mask_eeprom = V4L2_STD_ALL; 2224 hdw->std_mask_eeprom = V4L2_STD_ALL;
2025 } 2225 }
2026 2226
2227 if (hdw->serial_number) {
2228 idx = scnprintf(hdw->identifier, sizeof(hdw->identifier) - 1,
2229 "sn-%lu", hdw->serial_number);
2230 } else if (hdw->unit_number >= 0) {
2231 idx = scnprintf(hdw->identifier, sizeof(hdw->identifier) - 1,
2232 "unit-%c",
2233 hdw->unit_number + 'a');
2234 } else {
2235 idx = scnprintf(hdw->identifier, sizeof(hdw->identifier) - 1,
2236 "unit-??");
2237 }
2238 hdw->identifier[idx] = 0;
2239
2027 pvr2_hdw_setup_std(hdw); 2240 pvr2_hdw_setup_std(hdw);
2028 2241
2029 if (!get_default_tuner_type(hdw)) { 2242 if (!get_default_tuner_type(hdw)) {
@@ -2032,8 +2245,6 @@ static void pvr2_hdw_setup_low(struct pvr2_hdw *hdw)
2032 hdw->tuner_type); 2245 hdw->tuner_type);
2033 } 2246 }
2034 2247
2035 pvr2_i2c_core_check_stale(hdw);
2036 hdw->tuner_updated = 0;
2037 2248
2038 if (!pvr2_hdw_dev_ok(hdw)) return; 2249 if (!pvr2_hdw_dev_ok(hdw)) return;
2039 2250
@@ -2171,11 +2382,14 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
2171 struct pvr2_hdw *hdw = NULL; 2382 struct pvr2_hdw *hdw = NULL;
2172 int valid_std_mask; 2383 int valid_std_mask;
2173 struct pvr2_ctrl *cptr; 2384 struct pvr2_ctrl *cptr;
2385 struct usb_device *usb_dev;
2174 const struct pvr2_device_desc *hdw_desc; 2386 const struct pvr2_device_desc *hdw_desc;
2175 __u8 ifnum; 2387 __u8 ifnum;
2176 struct v4l2_queryctrl qctrl; 2388 struct v4l2_queryctrl qctrl;
2177 struct pvr2_ctl_info *ciptr; 2389 struct pvr2_ctl_info *ciptr;
2178 2390
2391 usb_dev = interface_to_usbdev(intf);
2392
2179 hdw_desc = (const struct pvr2_device_desc *)(devid->driver_info); 2393 hdw_desc = (const struct pvr2_device_desc *)(devid->driver_info);
2180 2394
2181 if (hdw_desc == NULL) { 2395 if (hdw_desc == NULL) {
@@ -2360,6 +2574,11 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
2360 hdw->ctl_read_urb = usb_alloc_urb(0,GFP_KERNEL); 2574 hdw->ctl_read_urb = usb_alloc_urb(0,GFP_KERNEL);
2361 if (!hdw->ctl_read_urb) goto fail; 2575 if (!hdw->ctl_read_urb) goto fail;
2362 2576
2577 if (v4l2_device_register(&usb_dev->dev, &hdw->v4l2_dev) != 0) {
2578 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
2579 "Error registering with v4l core, giving up");
2580 goto fail;
2581 }
2363 mutex_lock(&pvr2_unit_mtx); do { 2582 mutex_lock(&pvr2_unit_mtx); do {
2364 for (idx = 0; idx < PVR_NUM; idx++) { 2583 for (idx = 0; idx < PVR_NUM; idx++) {
2365 if (unit_pointers[idx]) continue; 2584 if (unit_pointers[idx]) continue;
@@ -2382,7 +2601,6 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
2382 2601
2383 hdw->workqueue = create_singlethread_workqueue(hdw->name); 2602 hdw->workqueue = create_singlethread_workqueue(hdw->name);
2384 INIT_WORK(&hdw->workpoll,pvr2_hdw_worker_poll); 2603 INIT_WORK(&hdw->workpoll,pvr2_hdw_worker_poll);
2385 INIT_WORK(&hdw->worki2csync,pvr2_hdw_worker_i2c);
2386 2604
2387 pvr2_trace(PVR2_TRACE_INIT,"Driver unit number is %d, name is %s", 2605 pvr2_trace(PVR2_TRACE_INIT,"Driver unit number is %d, name is %s",
2388 hdw->unit_number,hdw->name); 2606 hdw->unit_number,hdw->name);
@@ -2391,12 +2609,9 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
2391 hdw->flag_ok = !0; 2609 hdw->flag_ok = !0;
2392 2610
2393 hdw->usb_intf = intf; 2611 hdw->usb_intf = intf;
2394 hdw->usb_dev = interface_to_usbdev(intf); 2612 hdw->usb_dev = usb_dev;
2395 2613
2396 scnprintf(hdw->bus_info,sizeof(hdw->bus_info), 2614 usb_make_path(hdw->usb_dev, hdw->bus_info, sizeof(hdw->bus_info));
2397 "usb %s address %d",
2398 dev_name(&hdw->usb_dev->dev),
2399 hdw->usb_dev->devnum);
2400 2615
2401 ifnum = hdw->usb_intf->cur_altsetting->desc.bInterfaceNumber; 2616 ifnum = hdw->usb_intf->cur_altsetting->desc.bInterfaceNumber;
2402 usb_set_interface(hdw->usb_dev,ifnum,0); 2617 usb_set_interface(hdw->usb_dev,ifnum,0);
@@ -2454,6 +2669,10 @@ static void pvr2_hdw_remove_usb_stuff(struct pvr2_hdw *hdw)
2454 hdw->ctl_write_buffer = NULL; 2669 hdw->ctl_write_buffer = NULL;
2455 } 2670 }
2456 hdw->flag_disconnected = !0; 2671 hdw->flag_disconnected = !0;
2672 /* If we don't do this, then there will be a dangling struct device
2673 reference to our disappearing device persisting inside the V4L
2674 core... */
2675 v4l2_device_disconnect(&hdw->v4l2_dev);
2457 hdw->usb_dev = NULL; 2676 hdw->usb_dev = NULL;
2458 hdw->usb_intf = NULL; 2677 hdw->usb_intf = NULL;
2459 pvr2_hdw_render_useless(hdw); 2678 pvr2_hdw_render_useless(hdw);
@@ -2481,10 +2700,8 @@ void pvr2_hdw_destroy(struct pvr2_hdw *hdw)
2481 pvr2_stream_destroy(hdw->vid_stream); 2700 pvr2_stream_destroy(hdw->vid_stream);
2482 hdw->vid_stream = NULL; 2701 hdw->vid_stream = NULL;
2483 } 2702 }
2484 if (hdw->decoder_ctrl) {
2485 hdw->decoder_ctrl->detach(hdw->decoder_ctrl->ctxt);
2486 }
2487 pvr2_i2c_core_done(hdw); 2703 pvr2_i2c_core_done(hdw);
2704 v4l2_device_unregister(&hdw->v4l2_dev);
2488 pvr2_hdw_remove_usb_stuff(hdw); 2705 pvr2_hdw_remove_usb_stuff(hdw);
2489 mutex_lock(&pvr2_unit_mtx); do { 2706 mutex_lock(&pvr2_unit_mtx); do {
2490 if ((hdw->unit_number >= 0) && 2707 if ((hdw->unit_number >= 0) &&
@@ -2678,6 +2895,150 @@ static const char *get_ctrl_typename(enum pvr2_ctl_type tp)
2678} 2895}
2679 2896
2680 2897
2898static void pvr2_subdev_set_control(struct pvr2_hdw *hdw, int id,
2899 const char *name, int val)
2900{
2901 struct v4l2_control ctrl;
2902 pvr2_trace(PVR2_TRACE_CHIPS, "subdev v4l2 %s=%d", name, val);
2903 memset(&ctrl, 0, sizeof(ctrl));
2904 ctrl.id = id;
2905 ctrl.value = val;
2906 v4l2_device_call_all(&hdw->v4l2_dev, 0, core, s_ctrl, &ctrl);
2907}
2908
2909#define PVR2_SUBDEV_SET_CONTROL(hdw, id, lab) \
2910 if ((hdw)->lab##_dirty || (hdw)->force_dirty) { \
2911 pvr2_subdev_set_control(hdw, id, #lab, (hdw)->lab##_val); \
2912 }
2913
2914/* Execute whatever commands are required to update the state of all the
2915 sub-devices so that they match our current control values. */
2916static void pvr2_subdev_update(struct pvr2_hdw *hdw)
2917{
2918 struct v4l2_subdev *sd;
2919 unsigned int id;
2920 pvr2_subdev_update_func fp;
2921
2922 pvr2_trace(PVR2_TRACE_CHIPS, "subdev update...");
2923
2924 if (hdw->tuner_updated || hdw->force_dirty) {
2925 struct tuner_setup setup;
2926 pvr2_trace(PVR2_TRACE_CHIPS, "subdev tuner set_type(%d)",
2927 hdw->tuner_type);
2928 if (((int)(hdw->tuner_type)) >= 0) {
2929 setup.addr = ADDR_UNSET;
2930 setup.type = hdw->tuner_type;
2931 setup.mode_mask = T_RADIO | T_ANALOG_TV;
2932 v4l2_device_call_all(&hdw->v4l2_dev, 0,
2933 tuner, s_type_addr, &setup);
2934 }
2935 }
2936
2937 if (hdw->input_dirty || hdw->std_dirty || hdw->force_dirty) {
2938 pvr2_trace(PVR2_TRACE_CHIPS, "subdev v4l2 set_standard");
2939 if (hdw->input_val == PVR2_CVAL_INPUT_RADIO) {
2940 v4l2_device_call_all(&hdw->v4l2_dev, 0,
2941 tuner, s_radio);
2942 } else {
2943 v4l2_std_id vs;
2944 vs = hdw->std_mask_cur;
2945 v4l2_device_call_all(&hdw->v4l2_dev, 0,
2946 tuner, s_std, vs);
2947 }
2948 hdw->tuner_signal_stale = !0;
2949 hdw->cropcap_stale = !0;
2950 }
2951
2952 PVR2_SUBDEV_SET_CONTROL(hdw, V4L2_CID_BRIGHTNESS, brightness);
2953 PVR2_SUBDEV_SET_CONTROL(hdw, V4L2_CID_CONTRAST, contrast);
2954 PVR2_SUBDEV_SET_CONTROL(hdw, V4L2_CID_SATURATION, saturation);
2955 PVR2_SUBDEV_SET_CONTROL(hdw, V4L2_CID_HUE, hue);
2956 PVR2_SUBDEV_SET_CONTROL(hdw, V4L2_CID_AUDIO_MUTE, mute);
2957 PVR2_SUBDEV_SET_CONTROL(hdw, V4L2_CID_AUDIO_VOLUME, volume);
2958 PVR2_SUBDEV_SET_CONTROL(hdw, V4L2_CID_AUDIO_BALANCE, balance);
2959 PVR2_SUBDEV_SET_CONTROL(hdw, V4L2_CID_AUDIO_BASS, bass);
2960 PVR2_SUBDEV_SET_CONTROL(hdw, V4L2_CID_AUDIO_TREBLE, treble);
2961
2962 if (hdw->input_dirty || hdw->audiomode_dirty || hdw->force_dirty) {
2963 struct v4l2_tuner vt;
2964 memset(&vt, 0, sizeof(vt));
2965 vt.audmode = hdw->audiomode_val;
2966 v4l2_device_call_all(&hdw->v4l2_dev, 0, tuner, s_tuner, &vt);
2967 }
2968
2969 if (hdw->freqDirty || hdw->force_dirty) {
2970 unsigned long fv;
2971 struct v4l2_frequency freq;
2972 fv = pvr2_hdw_get_cur_freq(hdw);
2973 pvr2_trace(PVR2_TRACE_CHIPS, "subdev v4l2 set_freq(%lu)", fv);
2974 if (hdw->tuner_signal_stale) pvr2_hdw_status_poll(hdw);
2975 memset(&freq, 0, sizeof(freq));
2976 if (hdw->tuner_signal_info.capability & V4L2_TUNER_CAP_LOW) {
2977 /* ((fv * 1000) / 62500) */
2978 freq.frequency = (fv * 2) / 125;
2979 } else {
2980 freq.frequency = fv / 62500;
2981 }
2982 /* tuner-core currently doesn't seem to care about this, but
2983 let's set it anyway for completeness. */
2984 if (hdw->input_val == PVR2_CVAL_INPUT_RADIO) {
2985 freq.type = V4L2_TUNER_RADIO;
2986 } else {
2987 freq.type = V4L2_TUNER_ANALOG_TV;
2988 }
2989 freq.tuner = 0;
2990 v4l2_device_call_all(&hdw->v4l2_dev, 0, tuner,
2991 s_frequency, &freq);
2992 }
2993
2994 if (hdw->res_hor_dirty || hdw->res_ver_dirty || hdw->force_dirty) {
2995 struct v4l2_format fmt;
2996 memset(&fmt, 0, sizeof(fmt));
2997 fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
2998 fmt.fmt.pix.width = hdw->res_hor_val;
2999 fmt.fmt.pix.height = hdw->res_ver_val;
3000 pvr2_trace(PVR2_TRACE_CHIPS, "subdev v4l2 set_size(%dx%d)",
3001 fmt.fmt.pix.width, fmt.fmt.pix.height);
3002 v4l2_device_call_all(&hdw->v4l2_dev, 0, video, s_fmt, &fmt);
3003 }
3004
3005 if (hdw->srate_dirty || hdw->force_dirty) {
3006 u32 val;
3007 pvr2_trace(PVR2_TRACE_CHIPS, "subdev v4l2 set_audio %d",
3008 hdw->srate_val);
3009 switch (hdw->srate_val) {
3010 default:
3011 case V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000:
3012 val = 48000;
3013 break;
3014 case V4L2_MPEG_AUDIO_SAMPLING_FREQ_44100:
3015 val = 44100;
3016 break;
3017 case V4L2_MPEG_AUDIO_SAMPLING_FREQ_32000:
3018 val = 32000;
3019 break;
3020 }
3021 v4l2_device_call_all(&hdw->v4l2_dev, 0,
3022 audio, s_clock_freq, val);
3023 }
3024
3025 /* Unable to set crop parameters; there is apparently no equivalent
3026 for VIDIOC_S_CROP */
3027
3028 v4l2_device_for_each_subdev(sd, &hdw->v4l2_dev) {
3029 id = sd->grp_id;
3030 if (id >= ARRAY_SIZE(pvr2_module_update_functions)) continue;
3031 fp = pvr2_module_update_functions[id];
3032 if (!fp) continue;
3033 (*fp)(hdw, sd);
3034 }
3035
3036 if (hdw->tuner_signal_stale || hdw->cropcap_stale) {
3037 pvr2_hdw_status_poll(hdw);
3038 }
3039}
3040
3041
2681/* Figure out if we need to commit control changes. If so, mark internal 3042/* Figure out if we need to commit control changes. If so, mark internal
2682 state flags to indicate this fact and return true. Otherwise do nothing 3043 state flags to indicate this fact and return true. Otherwise do nothing
2683 else and return false. */ 3044 else and return false. */
@@ -2686,7 +3047,7 @@ static int pvr2_hdw_commit_setup(struct pvr2_hdw *hdw)
2686 unsigned int idx; 3047 unsigned int idx;
2687 struct pvr2_ctrl *cptr; 3048 struct pvr2_ctrl *cptr;
2688 int value; 3049 int value;
2689 int commit_flag = 0; 3050 int commit_flag = hdw->force_dirty;
2690 char buf[100]; 3051 char buf[100];
2691 unsigned int bcnt,ccnt; 3052 unsigned int bcnt,ccnt;
2692 3053
@@ -2842,18 +3203,6 @@ static int pvr2_hdw_commit_execute(struct pvr2_hdw *hdw)
2842 cx2341x_ext_ctrls(&hdw->enc_ctl_state, 0, &cs,VIDIOC_S_EXT_CTRLS); 3203 cx2341x_ext_ctrls(&hdw->enc_ctl_state, 0, &cs,VIDIOC_S_EXT_CTRLS);
2843 } 3204 }
2844 3205
2845 /* Scan i2c core at this point - before we clear all the dirty
2846 bits. Various parts of the i2c core will notice dirty bits as
2847 appropriate and arrange to broadcast or directly send updates to
2848 the client drivers in order to keep everything in sync */
2849 pvr2_i2c_core_check_stale(hdw);
2850
2851 for (idx = 0; idx < hdw->control_cnt; idx++) {
2852 cptr = hdw->controls + idx;
2853 if (!cptr->info->clear_dirty) continue;
2854 cptr->info->clear_dirty(cptr);
2855 }
2856
2857 if (hdw->active_stream_type != hdw->desired_stream_type) { 3206 if (hdw->active_stream_type != hdw->desired_stream_type) {
2858 /* Handle any side effects of stream config here */ 3207 /* Handle any side effects of stream config here */
2859 hdw->active_stream_type = hdw->desired_stream_type; 3208 hdw->active_stream_type = hdw->desired_stream_type;
@@ -2873,8 +3222,16 @@ static int pvr2_hdw_commit_execute(struct pvr2_hdw *hdw)
2873 } 3222 }
2874 } 3223 }
2875 3224
2876 /* Now execute i2c core update */ 3225 /* Check and update state for all sub-devices. */
2877 pvr2_i2c_core_sync(hdw); 3226 pvr2_subdev_update(hdw);
3227
3228 hdw->tuner_updated = 0;
3229 hdw->force_dirty = 0;
3230 for (idx = 0; idx < hdw->control_cnt; idx++) {
3231 cptr = hdw->controls + idx;
3232 if (!cptr->info->clear_dirty) continue;
3233 cptr->info->clear_dirty(cptr);
3234 }
2878 3235
2879 if ((hdw->pathway_state == PVR2_PATHWAY_ANALOG) && 3236 if ((hdw->pathway_state == PVR2_PATHWAY_ANALOG) &&
2880 hdw->state_encoder_run) { 3237 hdw->state_encoder_run) {
@@ -2904,15 +3261,6 @@ int pvr2_hdw_commit_ctl(struct pvr2_hdw *hdw)
2904} 3261}
2905 3262
2906 3263
2907static void pvr2_hdw_worker_i2c(struct work_struct *work)
2908{
2909 struct pvr2_hdw *hdw = container_of(work,struct pvr2_hdw,worki2csync);
2910 LOCK_TAKE(hdw->big_lock); do {
2911 pvr2_i2c_core_sync(hdw);
2912 } while (0); LOCK_GIVE(hdw->big_lock);
2913}
2914
2915
2916static void pvr2_hdw_worker_poll(struct work_struct *work) 3264static void pvr2_hdw_worker_poll(struct work_struct *work)
2917{ 3265{
2918 int fl = 0; 3266 int fl = 0;
@@ -2973,7 +3321,7 @@ int pvr2_hdw_is_hsm(struct pvr2_hdw *hdw)
2973void pvr2_hdw_execute_tuner_poll(struct pvr2_hdw *hdw) 3321void pvr2_hdw_execute_tuner_poll(struct pvr2_hdw *hdw)
2974{ 3322{
2975 LOCK_TAKE(hdw->big_lock); do { 3323 LOCK_TAKE(hdw->big_lock); do {
2976 pvr2_i2c_core_status_poll(hdw); 3324 pvr2_hdw_status_poll(hdw);
2977 } while (0); LOCK_GIVE(hdw->big_lock); 3325 } while (0); LOCK_GIVE(hdw->big_lock);
2978} 3326}
2979 3327
@@ -2983,7 +3331,7 @@ static int pvr2_hdw_check_cropcap(struct pvr2_hdw *hdw)
2983 if (!hdw->cropcap_stale) { 3331 if (!hdw->cropcap_stale) {
2984 return 0; 3332 return 0;
2985 } 3333 }
2986 pvr2_i2c_core_status_poll(hdw); 3334 pvr2_hdw_status_poll(hdw);
2987 if (hdw->cropcap_stale) { 3335 if (hdw->cropcap_stale) {
2988 return -EIO; 3336 return -EIO;
2989 } 3337 }
@@ -3010,7 +3358,7 @@ int pvr2_hdw_get_tuner_status(struct pvr2_hdw *hdw,struct v4l2_tuner *vtp)
3010{ 3358{
3011 LOCK_TAKE(hdw->big_lock); do { 3359 LOCK_TAKE(hdw->big_lock); do {
3012 if (hdw->tuner_signal_stale) { 3360 if (hdw->tuner_signal_stale) {
3013 pvr2_i2c_core_status_poll(hdw); 3361 pvr2_hdw_status_poll(hdw);
3014 } 3362 }
3015 memcpy(vtp,&hdw->tuner_signal_info,sizeof(struct v4l2_tuner)); 3363 memcpy(vtp,&hdw->tuner_signal_info,sizeof(struct v4l2_tuner));
3016 } while (0); LOCK_GIVE(hdw->big_lock); 3364 } while (0); LOCK_GIVE(hdw->big_lock);
@@ -3029,11 +3377,8 @@ void pvr2_hdw_trigger_module_log(struct pvr2_hdw *hdw)
3029{ 3377{
3030 int nr = pvr2_hdw_get_unit_number(hdw); 3378 int nr = pvr2_hdw_get_unit_number(hdw);
3031 LOCK_TAKE(hdw->big_lock); do { 3379 LOCK_TAKE(hdw->big_lock); do {
3032 hdw->log_requested = !0;
3033 printk(KERN_INFO "pvrusb2: ================= START STATUS CARD #%d =================\n", nr); 3380 printk(KERN_INFO "pvrusb2: ================= START STATUS CARD #%d =================\n", nr);
3034 pvr2_i2c_core_check_stale(hdw); 3381 v4l2_device_call_all(&hdw->v4l2_dev, 0, core, log_status);
3035 hdw->log_requested = 0;
3036 pvr2_i2c_core_sync(hdw);
3037 pvr2_trace(PVR2_TRACE_INFO,"cx2341x config:"); 3382 pvr2_trace(PVR2_TRACE_INFO,"cx2341x config:");
3038 cx2341x_log_status(&hdw->enc_ctl_state, "pvrusb2"); 3383 cx2341x_log_status(&hdw->enc_ctl_state, "pvrusb2");
3039 pvr2_hdw_state_log_state(hdw); 3384 pvr2_hdw_state_log_state(hdw);
@@ -3716,22 +4061,16 @@ int pvr2_hdw_cmd_powerdown(struct pvr2_hdw *hdw)
3716 4061
3717int pvr2_hdw_cmd_decoder_reset(struct pvr2_hdw *hdw) 4062int pvr2_hdw_cmd_decoder_reset(struct pvr2_hdw *hdw)
3718{ 4063{
3719 if (!hdw->decoder_ctrl) {
3720 pvr2_trace(PVR2_TRACE_INIT,
3721 "Unable to reset decoder: nothing attached");
3722 return -ENOTTY;
3723 }
3724
3725 if (!hdw->decoder_ctrl->force_reset) {
3726 pvr2_trace(PVR2_TRACE_INIT,
3727 "Unable to reset decoder: not implemented");
3728 return -ENOTTY;
3729 }
3730
3731 pvr2_trace(PVR2_TRACE_INIT, 4064 pvr2_trace(PVR2_TRACE_INIT,
3732 "Requesting decoder reset"); 4065 "Requesting decoder reset");
3733 hdw->decoder_ctrl->force_reset(hdw->decoder_ctrl->ctxt); 4066 if (hdw->decoder_client_id) {
3734 return 0; 4067 v4l2_device_call_all(&hdw->v4l2_dev, hdw->decoder_client_id,
4068 core, reset, 0);
4069 return 0;
4070 }
4071 pvr2_trace(PVR2_TRACE_INIT,
4072 "Unable to reset decoder: nothing attached");
4073 return -ENOTTY;
3735} 4074}
3736 4075
3737 4076
@@ -4476,6 +4815,79 @@ static unsigned int pvr2_hdw_report_unlocked(struct pvr2_hdw *hdw,int which,
4476} 4815}
4477 4816
4478 4817
4818/* Generate report containing info about attached sub-devices and attached
4819 i2c clients, including an indication of which attached i2c clients are
4820 actually sub-devices. */
4821static unsigned int pvr2_hdw_report_clients(struct pvr2_hdw *hdw,
4822 char *buf, unsigned int acnt)
4823{
4824 struct v4l2_subdev *sd;
4825 unsigned int tcnt = 0;
4826 unsigned int ccnt;
4827 struct i2c_client *client;
4828 struct list_head *item;
4829 void *cd;
4830 const char *p;
4831 unsigned int id;
4832
4833 ccnt = scnprintf(buf, acnt, "Associated v4l2-subdev drivers:");
4834 tcnt += ccnt;
4835 v4l2_device_for_each_subdev(sd, &hdw->v4l2_dev) {
4836 id = sd->grp_id;
4837 p = NULL;
4838 if (id < ARRAY_SIZE(module_names)) p = module_names[id];
4839 if (p) {
4840 ccnt = scnprintf(buf + tcnt, acnt - tcnt, " %s", p);
4841 tcnt += ccnt;
4842 } else {
4843 ccnt = scnprintf(buf + tcnt, acnt - tcnt,
4844 " (unknown id=%u)", id);
4845 tcnt += ccnt;
4846 }
4847 }
4848 ccnt = scnprintf(buf + tcnt, acnt - tcnt, "\n");
4849 tcnt += ccnt;
4850
4851 ccnt = scnprintf(buf + tcnt, acnt - tcnt, "I2C clients:\n");
4852 tcnt += ccnt;
4853
4854 mutex_lock(&hdw->i2c_adap.clist_lock);
4855 list_for_each(item, &hdw->i2c_adap.clients) {
4856 client = list_entry(item, struct i2c_client, list);
4857 ccnt = scnprintf(buf + tcnt, acnt - tcnt,
4858 " %s: i2c=%02x", client->name, client->addr);
4859 tcnt += ccnt;
4860 cd = i2c_get_clientdata(client);
4861 v4l2_device_for_each_subdev(sd, &hdw->v4l2_dev) {
4862 if (cd == sd) {
4863 id = sd->grp_id;
4864 p = NULL;
4865 if (id < ARRAY_SIZE(module_names)) {
4866 p = module_names[id];
4867 }
4868 if (p) {
4869 ccnt = scnprintf(buf + tcnt,
4870 acnt - tcnt,
4871 " subdev=%s", p);
4872 tcnt += ccnt;
4873 } else {
4874 ccnt = scnprintf(buf + tcnt,
4875 acnt - tcnt,
4876 " subdev= id %u)",
4877 id);
4878 tcnt += ccnt;
4879 }
4880 break;
4881 }
4882 }
4883 ccnt = scnprintf(buf + tcnt, acnt - tcnt, "\n");
4884 tcnt += ccnt;
4885 }
4886 mutex_unlock(&hdw->i2c_adap.clist_lock);
4887 return tcnt;
4888}
4889
4890
4479unsigned int pvr2_hdw_state_report(struct pvr2_hdw *hdw, 4891unsigned int pvr2_hdw_state_report(struct pvr2_hdw *hdw,
4480 char *buf,unsigned int acnt) 4892 char *buf,unsigned int acnt)
4481{ 4893{
@@ -4490,6 +4902,8 @@ unsigned int pvr2_hdw_state_report(struct pvr2_hdw *hdw,
4490 buf[0] = '\n'; ccnt = 1; 4902 buf[0] = '\n'; ccnt = 1;
4491 bcnt += ccnt; acnt -= ccnt; buf += ccnt; 4903 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
4492 } 4904 }
4905 ccnt = pvr2_hdw_report_clients(hdw, buf, acnt);
4906 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
4493 LOCK_GIVE(hdw->big_lock); 4907 LOCK_GIVE(hdw->big_lock);
4494 return bcnt; 4908 return bcnt;
4495} 4909}
@@ -4497,14 +4911,25 @@ unsigned int pvr2_hdw_state_report(struct pvr2_hdw *hdw,
4497 4911
4498static void pvr2_hdw_state_log_state(struct pvr2_hdw *hdw) 4912static void pvr2_hdw_state_log_state(struct pvr2_hdw *hdw)
4499{ 4913{
4500 char buf[128]; 4914 char buf[256];
4501 unsigned int idx,ccnt; 4915 unsigned int idx, ccnt;
4916 unsigned int lcnt, ucnt;
4502 4917
4503 for (idx = 0; ; idx++) { 4918 for (idx = 0; ; idx++) {
4504 ccnt = pvr2_hdw_report_unlocked(hdw,idx,buf,sizeof(buf)); 4919 ccnt = pvr2_hdw_report_unlocked(hdw,idx,buf,sizeof(buf));
4505 if (!ccnt) break; 4920 if (!ccnt) break;
4506 printk(KERN_INFO "%s %.*s\n",hdw->name,ccnt,buf); 4921 printk(KERN_INFO "%s %.*s\n",hdw->name,ccnt,buf);
4507 } 4922 }
4923 ccnt = pvr2_hdw_report_clients(hdw, buf, sizeof(buf));
4924 ucnt = 0;
4925 while (ucnt < ccnt) {
4926 lcnt = 0;
4927 while ((lcnt + ucnt < ccnt) && (buf[lcnt + ucnt] != '\n')) {
4928 lcnt++;
4929 }
4930 printk(KERN_INFO "%s %.*s\n", hdw->name, lcnt, buf + ucnt);
4931 ucnt += lcnt + 1;
4932 }
4508} 4933}
4509 4934
4510 4935
@@ -4641,6 +5066,30 @@ int pvr2_hdw_gpio_chg_out(struct pvr2_hdw *hdw,u32 msk,u32 val)
4641} 5066}
4642 5067
4643 5068
5069void pvr2_hdw_status_poll(struct pvr2_hdw *hdw)
5070{
5071 struct v4l2_tuner *vtp = &hdw->tuner_signal_info;
5072 memset(vtp, 0, sizeof(*vtp));
5073 hdw->tuner_signal_stale = 0;
5074 /* Note: There apparently is no replacement for VIDIOC_CROPCAP
5075 using v4l2-subdev - therefore we can't support that AT ALL right
5076 now. (Of course, no sub-drivers seem to implement it either.
5077 But now it's a a chicken and egg problem...) */
5078 v4l2_device_call_all(&hdw->v4l2_dev, 0, tuner, g_tuner,
5079 &hdw->tuner_signal_info);
5080 pvr2_trace(PVR2_TRACE_CHIPS, "subdev status poll"
5081 " type=%u strength=%u audio=0x%x cap=0x%x"
5082 " low=%u hi=%u",
5083 vtp->type,
5084 vtp->signal, vtp->rxsubchans, vtp->capability,
5085 vtp->rangelow, vtp->rangehigh);
5086
5087 /* We have to do this to avoid getting into constant polling if
5088 there's nobody to answer a poll of cropcap info. */
5089 hdw->cropcap_stale = 0;
5090}
5091
5092
4644unsigned int pvr2_hdw_get_input_available(struct pvr2_hdw *hdw) 5093unsigned int pvr2_hdw_get_input_available(struct pvr2_hdw *hdw)
4645{ 5094{
4646 return hdw->input_avail_mask; 5095 return hdw->input_avail_mask;
@@ -4736,7 +5185,6 @@ int pvr2_hdw_register_access(struct pvr2_hdw *hdw,
4736 int setFl, u64 *val_ptr) 5185 int setFl, u64 *val_ptr)
4737{ 5186{
4738#ifdef CONFIG_VIDEO_ADV_DEBUG 5187#ifdef CONFIG_VIDEO_ADV_DEBUG
4739 struct pvr2_i2c_client *cp;
4740 struct v4l2_dbg_register req; 5188 struct v4l2_dbg_register req;
4741 int stat = 0; 5189 int stat = 0;
4742 int okFl = 0; 5190 int okFl = 0;
@@ -4746,21 +5194,9 @@ int pvr2_hdw_register_access(struct pvr2_hdw *hdw,
4746 req.match = *match; 5194 req.match = *match;
4747 req.reg = reg_id; 5195 req.reg = reg_id;
4748 if (setFl) req.val = *val_ptr; 5196 if (setFl) req.val = *val_ptr;
4749 mutex_lock(&hdw->i2c_list_lock); do { 5197 /* It would be nice to know if a sub-device answered the request */
4750 list_for_each_entry(cp, &hdw->i2c_clients, list) { 5198 v4l2_device_call_all(&hdw->v4l2_dev, 0, core, g_register, &req);
4751 if (!v4l2_chip_match_i2c_client( 5199 if (!setFl) *val_ptr = req.val;
4752 cp->client,
4753 &req.match)) {
4754 continue;
4755 }
4756 stat = pvr2_i2c_client_cmd(
4757 cp,(setFl ? VIDIOC_DBG_S_REGISTER :
4758 VIDIOC_DBG_G_REGISTER),&req);
4759 if (!setFl) *val_ptr = req.val;
4760 okFl = !0;
4761 break;
4762 }
4763 } while (0); mutex_unlock(&hdw->i2c_list_lock);
4764 if (okFl) { 5200 if (okFl) {
4765 return stat; 5201 return stat;
4766 } 5202 }