summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Isely <isely@pobox.com>2006-03-26 15:45:31 -0600
committerMike Isely <isely@pobox.com>2006-03-26 15:45:31 -0600
commitf44c0bc49cbb5ee3bd7d89c602873840d40c8b25 (patch)
tree2baee998534b27b4cdd2aa2c1b073b0746c5bc01
parent2fc29f23f48a916f556d40ce8498ed27a0b1f0fc (diff)
downloadmediapointer-dvb-s2-f44c0bc49cbb5ee3bd7d89c602873840d40c8b25.tar.gz
mediapointer-dvb-s2-f44c0bc49cbb5ee3bd7d89c602873840d40c8b25.tar.bz2
Get rid of static PVR2_CID_COUNT in pvrusb2
From: Mike Isely <isely@pobox.com> Eliminate the need to track the number pvrusb2 CIDs at compile time from within the pvrusb2 driver. This is part of a control structure cleanup. Signed-off-by: Mike Isely <isely@pobox.com>
-rw-r--r--linux/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h2
-rw-r--r--linux/drivers/media/video/pvrusb2/pvrusb2-hdw.c80
-rw-r--r--linux/drivers/media/video/pvrusb2/pvrusb2-hdw.h6
-rw-r--r--linux/drivers/media/video/pvrusb2/pvrusb2-sysfs.c2
4 files changed, 73 insertions, 17 deletions
diff --git a/linux/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/linux/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
index 05e44385b..25854375b 100644
--- a/linux/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
+++ b/linux/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
@@ -211,7 +211,7 @@ struct pvr2_hdw {
struct pvr2_audio_stat *audio_stat;
/* Every last bit of controllable state */
- struct pvr2_ctl_state controls[PVR2_CID_COUNT];
+ struct pvr2_ctl_state *controls;
};
int pvr2_hdw_set_ctl_value_internal(struct pvr2_hdw *hdw,
diff --git a/linux/drivers/media/video/pvrusb2/pvrusb2-hdw.c b/linux/drivers/media/video/pvrusb2/pvrusb2-hdw.c
index ec2b5eeae..81a35a8e2 100644
--- a/linux/drivers/media/video/pvrusb2/pvrusb2-hdw.c
+++ b/linux/drivers/media/video/pvrusb2/pvrusb2-hdw.c
@@ -97,6 +97,7 @@ struct pvr2_ctl_def {
int min_value;
int skip_init;
int default_value;
+ int is_valid;
const char **value_defs_ptr;
unsigned int value_defs_count;
};
@@ -184,63 +185,73 @@ static int pvr2_ctl_get_subsys_stream_mask(struct pvr2_hdw *hdw,int ctl_id);
static int pvr2_ctl_set_subsys_stream_mask(struct pvr2_hdw *hdw,int ctl_id,
int val);
-static struct pvr2_ctl_def control_defs[PVR2_CID_COUNT] =
+static struct pvr2_ctl_def control_defs[] =
{
[PVR2_CID_BRIGHTNESS] = {
+ .is_valid = !0,
.name = "Brightness",
.min_value = 0,
.max_value = 255,
.default_value = 128,
},
[PVR2_CID_CONTRAST] = {
+ .is_valid = !0,
.name = "Contrast",
.min_value = 0,
.max_value = 127,
.default_value = 68,
},
[PVR2_CID_SATURATION] = {
+ .is_valid = !0,
.name = "Saturation",
.min_value = 0,
.max_value = 127,
.default_value = 64,
},
[PVR2_CID_HUE] = {
+ .is_valid = !0,
.name = "Hue",
.min_value = -128,
.max_value = 127,
.default_value = 0,
},
[PVR2_CID_VOLUME] = {
+ .is_valid = !0,
.name = "Volume",
.min_value = 0,
.max_value = 65535,
.default_value = 65535,
},
[PVR2_CID_BALANCE] = {
+ .is_valid = !0,
.name = "Balance",
.min_value = -32768,
.max_value = 32767,
.default_value = 0,
},
[PVR2_CID_BASS] = {
+ .is_valid = !0,
.name = "Bass",
.min_value = -32768,
.max_value = 32767,
.default_value = 0,
},
[PVR2_CID_TREBLE] = {
+ .is_valid = !0,
.name = "Treble",
.min_value = -32768,
.max_value = 32767,
.default_value = 0,
},
[PVR2_CID_MUTE] = {
+ .is_valid = !0,
.name = "Mute",
.min_value = 0,
.max_value = 1,
.default_value = 0,
},
[PVR2_CID_SRATE] = {
+ .is_valid = !0,
.name = "Sample rate",
.min_value = PVR2_CVAL_SRATE_MIN,
.max_value = PVR2_CVAL_SRATE_MAX,
@@ -248,6 +259,7 @@ static struct pvr2_ctl_def control_defs[PVR2_CID_COUNT] =
VDEF(control_values_srate),
},
[PVR2_CID_AUDIOBITRATE] = {
+ .is_valid = !0,
.name = "Audio Bitrate",
.min_value = PVR2_CVAL_AUDIOBITRATE_MIN,
.max_value = PVR2_CVAL_AUDIOBITRATE_MAX,
@@ -255,12 +267,14 @@ static struct pvr2_ctl_def control_defs[PVR2_CID_COUNT] =
VDEF(control_values_audiobitrate),
},
[PVR2_CID_AUDIOCRC] = {
+ .is_valid = !0,
.name = "Audio CRC",
.min_value = 0,
.max_value = 1,
.default_value = 1,
},
[PVR2_CID_AUDIOEMPHASIS] = {
+ .is_valid = !0,
.name = "Audio Emphasis",
.min_value = PVR2_CVAL_AUDIOEMPHASIS_MIN,
.max_value = PVR2_CVAL_AUDIOEMPHASIS_MAX,
@@ -268,24 +282,28 @@ static struct pvr2_ctl_def control_defs[PVR2_CID_COUNT] =
VDEF(control_values_audioemphasis),
},
[PVR2_CID_VBR] = {
+ .is_valid = !0,
.name = "Variable video bitrate",
.min_value = 0,
.max_value = 1,
.default_value = 0,
},
[PVR2_CID_AVERAGEVIDEOBITRATE] = {
+ .is_valid = !0,
.name = "Average video bitrate",
.min_value = 1,
.max_value = 20000000,
.default_value = 6000000,
},
[PVR2_CID_PEAKVIDEOBITRATE] = {
+ .is_valid = !0,
.name = "Peak video bitrate",
.min_value = 1,
.max_value = 20000000,
.default_value = 6000000,
},
[PVR2_CID_VIDEOSTANDARD] = {
+ .is_valid = !0,
.name = "Video Standard",
.min_value = PVR2_CVAL_VIDEOSTANDARD_MIN,
.max_value = PVR2_CVAL_VIDEOSTANDARD_MAX,
@@ -293,6 +311,7 @@ static struct pvr2_ctl_def control_defs[PVR2_CID_COUNT] =
VDEF(control_values_videostandard),
},
[PVR2_CID_INPUT] = {
+ .is_valid = !0,
.name = "Video Source",
.min_value = PVR2_CVAL_INPUT_MIN,
.max_value = PVR2_CVAL_INPUT_MAX,
@@ -300,6 +319,7 @@ static struct pvr2_ctl_def control_defs[PVR2_CID_COUNT] =
VDEF(control_values_input),
},
[PVR2_CID_AUDIOMODE] = {
+ .is_valid = !0,
.name = "Audio Mode",
.min_value = PVR2_CVAL_AUDIOMODE_MIN,
.max_value = PVR2_CVAL_AUDIOMODE_MAX,
@@ -307,48 +327,56 @@ static struct pvr2_ctl_def control_defs[PVR2_CID_COUNT] =
VDEF(control_values_audiomode),
},
[PVR2_CID_FREQUENCY] = {
+ .is_valid = !0,
.name = "Tuner Frequency (Hz)",
.min_value = 55250000L,
.max_value = 850000000L,
.default_value = 175250000L,
},
[PVR2_CID_HRES] = {
+ .is_valid = !0,
.name = "Horizontal capture resolution",
.min_value = 320,
.max_value = 720,
.default_value = 720,
},
[PVR2_CID_VRES] = {
+ .is_valid = !0,
.name = "Vertical capture resolution",
.min_value = 200,
.max_value = 625,
.default_value = 480,
},
[PVR2_CID_INTERLACE] = {
+ .is_valid = !0,
.name = "Interlace mode",
.min_value = 0,
.max_value = 1,
.default_value = 0,
},
[PVR2_CID_AUDIOLAYER] = {
+ .is_valid = !0,
.name = "Audio Layer",
.min_value = 0, /* This is all a wild guess */
.max_value = 3,
.default_value = 2, /* Appears to be all that is supported */
},
[PVR2_CID_CHANNEL] = {
+ .is_valid = !0,
.name = "Channel",
.min_value = 0,
.max_value = FREQTABLE_SIZE,
.default_value = 0,
},
[PVR2_CID_CHANPROG_ID] = {
+ .is_valid = !0,
.name = "Channel Program ID",
.min_value = 0,
.max_value = FREQTABLE_SIZE,
.default_value = 0,
},
[PVR2_CID_CHANPROG_FREQ] = {
+ .is_valid = !0,
.name = "Channel Program Frequency",
.min_value = 55250000L,
.max_value = 850000000L,
@@ -357,18 +385,21 @@ static struct pvr2_ctl_def control_defs[PVR2_CID_COUNT] =
.get_func = pvr2_ctl_get_chanprog_id,
},
[PVR2_CID_SIGNAL_PRESENT] = {
+ .is_valid = !0,
.name = "Signal Present",
.min_value = 0,
.max_value = 1,
.get_func = pvr2_ctl_get_signal,
},
[PVR2_CID_STREAMING_ENABLED] = {
+ .is_valid = !0,
.name = "Streaming Enabled",
.min_value = 0,
.max_value = 1,
.get_func = pvr2_ctl_get_streaming,
},
[PVR2_CID_HSM] = {
+ .is_valid = !0,
.name = "USB Speed",
.min_value = PVR2_CVAL_HSM_MIN,
.max_value = PVR2_CVAL_HSM_MAX,
@@ -376,6 +407,7 @@ static struct pvr2_ctl_def control_defs[PVR2_CID_COUNT] =
VDEF(control_values_hsm),
},
[PVR2_CID_SUBSYS_MASK] = {
+ .is_valid = !0,
.name = "Subsystem enabled mask",
.min_value = 0,
.max_value = 0x7fffffff,
@@ -384,6 +416,7 @@ static struct pvr2_ctl_def control_defs[PVR2_CID_COUNT] =
.set_func = pvr2_ctl_set_subsys_mask,
},
[PVR2_CID_SUBSYS_STREAM_MASK] = {
+ .is_valid = !0,
.name = "Subsystem stream mask",
.min_value = 0,
.max_value = 0x7fffffff,
@@ -395,6 +428,7 @@ static struct pvr2_ctl_def control_defs[PVR2_CID_COUNT] =
#undef VDEF
+#define CTRL_COUNT (sizeof(control_defs)/sizeof(control_defs[0]))
const char *pvr2_config_get_name(enum pvr2_config cfg)
{
@@ -1106,7 +1140,7 @@ static void pvr2_hdw_setup_low(struct pvr2_hdw *hdw)
pvr2_i2c_core_init(hdw);
if (!pvr2_hdw_dev_ok(hdw)) return;
- for (idx = 0; idx < PVR2_CID_COUNT; idx++) {
+ for (idx = 0; idx < CTRL_COUNT; idx++) {
if (control_defs[idx].skip_init) continue;
pvr2_hdw_set_ctl_value_internal(
hdw,idx,control_defs[idx].default_value);
@@ -1259,6 +1293,9 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
hdw,pvr2_device_names[hdw_type]);
if (!hdw) goto fail;
memset(hdw,0,sizeof(*hdw));
+ hdw->controls = kmalloc(sizeof(struct pvr2_ctl_state) * CTRL_COUNT,
+ GFP_KERNEL);
+ if (!hdw->controls) goto fail;
hdw->hdw_type = hdw_type;
hdw->eeprom_addr = -1;
@@ -1322,6 +1359,7 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
if (hdw->ctl_write_urb) usb_free_urb(hdw->ctl_write_urb);
if (hdw->ctl_read_buffer) kfree(hdw->ctl_read_buffer);
if (hdw->ctl_write_buffer) kfree(hdw->ctl_write_buffer);
+ if (hdw->controls) kfree(hdw->controls);
kfree(hdw);
}
return 0;
@@ -1386,6 +1424,7 @@ void pvr2_hdw_destroy(struct pvr2_hdw *hdw)
unit_pointers[hdw->unit_number] = 0;
}
} while (0); up(&pvr2_unit_sem);
+ kfree(hdw->controls);
kfree(hdw);
}
@@ -1447,7 +1486,9 @@ int pvr2_hdw_get_ctl_value(struct pvr2_hdw *hdw,unsigned int ctl_id)
{
int ret = 0;
- if (ctl_id >= PVR2_CID_COUNT) return 0;
+ if (ctl_id >= CTRL_COUNT) return 0;
+ if (!control_defs[ctl_id].is_valid) return 0;
+
LOCK_TAKE(hdw->big_lock); do {
if (control_defs[ctl_id].get_func) {
ret = control_defs[ctl_id].get_func(hdw,ctl_id);
@@ -1462,7 +1503,8 @@ int pvr2_hdw_get_ctl_value(struct pvr2_hdw *hdw,unsigned int ctl_id)
/* Return true if control is writable */
int pvr2_hdw_get_ctl_rw(struct pvr2_hdw *hdw,unsigned int ctl_id)
{
- if (ctl_id >= PVR2_CID_COUNT) return 0;
+ if (ctl_id >= CTRL_COUNT) return 0;
+ if (!control_defs[ctl_id].is_valid) return 0;
if (control_defs[ctl_id].get_func && !control_defs[ctl_id].set_func) {
return 0;
}
@@ -1473,7 +1515,8 @@ int pvr2_hdw_get_ctl_rw(struct pvr2_hdw *hdw,unsigned int ctl_id)
/* Retrieve legal minimum value for a given control */
int pvr2_hdw_get_ctl_min_value(struct pvr2_hdw *hdw,unsigned int ctl_id)
{
- if (ctl_id >= PVR2_CID_COUNT) return 0;
+ if (ctl_id >= CTRL_COUNT) return 0;
+ if (!control_defs[ctl_id].is_valid) return 0;
return control_defs[ctl_id].min_value;
}
@@ -1481,7 +1524,8 @@ int pvr2_hdw_get_ctl_min_value(struct pvr2_hdw *hdw,unsigned int ctl_id)
/* Retrieve legal maximum value for a given control */
int pvr2_hdw_get_ctl_max_value(struct pvr2_hdw *hdw,unsigned int ctl_id)
{
- if (ctl_id >= PVR2_CID_COUNT) return 0;
+ if (ctl_id >= CTRL_COUNT) return 0;
+ if (!control_defs[ctl_id].is_valid) return 0;
return control_defs[ctl_id].max_value;
}
@@ -1492,7 +1536,8 @@ int pvr2_hdw_set_ctl_value_internal(struct pvr2_hdw *hdw,
unsigned int ctl_id,int value)
{
int ret;
- if (ctl_id >= PVR2_CID_COUNT) return -EINVAL;
+ if (ctl_id >= CTRL_COUNT) return -EINVAL;
+ if (!control_defs[ctl_id].is_valid) return -EINVAL;
if (value < control_defs[ctl_id].min_value) return -EINVAL;
if (value > control_defs[ctl_id].max_value) return -EINVAL;
if (control_defs[ctl_id].set_func) {
@@ -1532,7 +1577,8 @@ const char *pvr2_hdw_get_ctl_value_name(struct pvr2_hdw *hdw,
int value)
{
struct pvr2_ctl_def *cdef;
- if (ctl_id >= PVR2_CID_COUNT) return 0;
+ if (ctl_id >= CTRL_COUNT) return 0;
+ if (!control_defs[ctl_id].is_valid) return 0;
cdef = control_defs + ctl_id;
if (! cdef->value_defs_ptr) return 0;
if (value >= cdef->value_defs_count) return 0;
@@ -1543,11 +1589,21 @@ const char *pvr2_hdw_get_ctl_value_name(struct pvr2_hdw *hdw,
/* Retrieve string name for given control */
const char *pvr2_hdw_get_ctl_name(struct pvr2_hdw *hdw,unsigned int ctl_id)
{
- if (ctl_id >= PVR2_CID_COUNT) return 0;
+ if (ctl_id >= CTRL_COUNT) return 0;
+ if (!control_defs[ctl_id].is_valid) return 0;
return control_defs[ctl_id].name;
}
+/* Return true if control ID is a valid id */
+int pvr2_hdw_get_ctl_valid(struct pvr2_hdw *hdw,unsigned int ctl_id)
+{
+ if (ctl_id >= CTRL_COUNT) return 0;
+ if (!control_defs[ctl_id].is_valid) return 0;
+ return !0;
+}
+
+
/* Commit all control changes made up to this point. Subsystems can be
indirectly affected by these changes. For a given set of things being
committed, we'll clear the affected subsystem bits and then once we're
@@ -1595,7 +1651,7 @@ int pvr2_hdw_commit_ctl_internal(struct pvr2_hdw *hdw)
}
}
- for (idx = 0; idx < PVR2_CID_COUNT; idx++) {
+ for (idx = 0; idx < CTRL_COUNT; idx++) {
if (!hdw->controls[idx].dirty) continue;
if (!commit_flag) {
commit_flag = !0;
@@ -1671,7 +1727,7 @@ int pvr2_hdw_commit_ctl_internal(struct pvr2_hdw *hdw)
the client drivers in order to keep everything in sync */
pvr2_i2c_core_check_stale(hdw);
- for (idx = 0; idx < PVR2_CID_COUNT; idx++) {
+ for (idx = 0; idx < CTRL_COUNT; idx++) {
hdw->controls[idx].dirty = 0;
}
@@ -1733,7 +1789,7 @@ void pvr2_hdw_poll_trigger(struct pvr2_hdw *hdw)
through this value. */
unsigned int pvr2_hdw_get_ctl_count(struct pvr2_hdw *hdw)
{
- return PVR2_CID_COUNT;
+ return CTRL_COUNT;
}
diff --git a/linux/drivers/media/video/pvrusb2/pvrusb2-hdw.h b/linux/drivers/media/video/pvrusb2/pvrusb2-hdw.h
index aa6d9029a..6cc841b56 100644
--- a/linux/drivers/media/video/pvrusb2/pvrusb2-hdw.h
+++ b/linux/drivers/media/video/pvrusb2/pvrusb2-hdw.h
@@ -59,9 +59,6 @@
#define PVR2_CID_SUBSYS_MASK 30
#define PVR2_CID_SUBSYS_STREAM_MASK 31
-/* Number of state variables */
-#define PVR2_CID_COUNT 32
-
/* Legal values for the SRATE state variable */
#define PVR2_CVAL_SRATE_48 0
#define PVR2_CVAL_SRATE_44_1 1
@@ -234,6 +231,9 @@ int pvr2_hdw_set_ctl_value(struct pvr2_hdw *,unsigned int ctl_id,int value);
/* Retrieve string name for given control */
const char *pvr2_hdw_get_ctl_name(struct pvr2_hdw *,unsigned int ctl_id);
+/* Return true if control id is a valid id */
+int pvr2_hdw_get_ctl_valid(struct pvr2_hdw *,unsigned int ctl_id);
+
/* Retrieve string name for a given control value (returns a null pointer
for any invalid combinations). */
const char *pvr2_hdw_get_ctl_value_name(struct pvr2_hdw *,
diff --git a/linux/drivers/media/video/pvrusb2/pvrusb2-sysfs.c b/linux/drivers/media/video/pvrusb2/pvrusb2-sysfs.c
index f82fd643c..6b81def26 100644
--- a/linux/drivers/media/video/pvrusb2/pvrusb2-sysfs.c
+++ b/linux/drivers/media/video/pvrusb2/pvrusb2-sysfs.c
@@ -30,7 +30,7 @@
#define pvr2_sysfs_trace(...) pvr2_trace(PVR2_TRACE_SYSFS,__VA_ARGS__)
-static char *item_names[PVR2_CID_COUNT] = {
+static char *item_names[] = {
[PVR2_CID_BRIGHTNESS] = "ctl_brightness",
[PVR2_CID_CONTRAST] = "ctl_contrast",
[PVR2_CID_SATURATION] = "ctl_saturation",