Skip to content

Commit

Permalink
Staging: easycap: Replace some global variables
Browse files Browse the repository at this point in the history
New members of struct easycap take the place of undesirable global variables.

Signed-off-by: Mike Thomas <rmthomas@sciolus.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Mike Thomas authored and Greg Kroah-Hartman committed Jul 22, 2010
1 parent 4d6ea9c commit 3d423e9
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 114 deletions.
150 changes: 80 additions & 70 deletions drivers/staging/easycap/easycap.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
#define USB_EASYCAP_VENDOR_ID 0x05e1
#define USB_EASYCAP_PRODUCT_ID 0x0408

#define EASYCAP_DRIVER_VERSION "0.8"
#define EASYCAP_DRIVER_VERSION "0.8.2"
#define EASYCAP_DRIVER_DESCRIPTION "easycapdc60"

#define USB_SKEL_MINOR_BASE 192
Expand Down Expand Up @@ -188,6 +188,65 @@
/*---------------------------------------------------------------------------*/
#define AUDIO_FRAGMENT_MANY 32
/*---------------------------------------------------------------------------*/
/*
* IT IS ESSENTIAL THAT EVEN-NUMBERED STANDARDS ARE 25 FRAMES PER SECOND,
* ODD-NUMBERED STANDARDS ARE 30 FRAMES PER SECOND.
* THE NUMBERING OF STANDARDS MUST NOT BE CHANGED WITHOUT DUE CARE. NOT
* ONLY MUST THE PARAMETER
* STANDARD_MANY
* BE CHANGED TO CORRESPOND TO THE NEW NUMBER OF STANDARDS, BUT ALSO THE
* NUMBERING MUST REMAIN AN UNBROKEN ASCENDING SEQUENCE: DUMMY STANDARDS
* MAY NEED TO BE ADDED. APPROPRIATE CHANGES WILL ALWAYS BE REQUIRED IN
* ROUTINE fillin_formats() AND POSSIBLY ELSEWHERE. BEWARE.
*/
/*---------------------------------------------------------------------------*/
#define PAL_BGHIN 0
#define PAL_Nc 2
#define SECAM 4
#define NTSC_N 6
#define NTSC_N_443 8
#define NTSC_M 1
#define NTSC_443 3
#define NTSC_M_JP 5
#define PAL_60 7
#define PAL_M 9
#define STANDARD_MANY 10
/*---------------------------------------------------------------------------*/
/*
* ENUMS
*/
/*---------------------------------------------------------------------------*/
enum {
AT_720x576,
AT_704x576,
AT_640x480,
AT_720x480,
AT_360x288,
AT_320x240,
AT_360x240,
RESOLUTION_MANY
};
enum {
FMT_UYVY,
FMT_YUY2,
FMT_RGB24,
FMT_RGB32,
FMT_BGR24,
FMT_BGR32,
PIXELFORMAT_MANY
};
enum {
FIELD_NONE,
FIELD_INTERLACED,
FIELD_ALTERNATE,
INTERLACE_MANY
};
#define SETTINGS_MANY (STANDARD_MANY * \
RESOLUTION_MANY * \
2 * \
PIXELFORMAT_MANY * \
INTERLACE_MANY)
/*---------------------------------------------------------------------------*/
/*
* STRUCTURE DEFINITIONS
*/
Expand All @@ -206,13 +265,33 @@ int isbuf;
int length;
};
/*---------------------------------------------------------------------------*/
struct easycap_standard {
__u16 mask;
struct v4l2_standard v4l2_standard;
};
struct easycap_format {
__u16 mask;
char name[128];
struct v4l2_format v4l2_format;
};
/*---------------------------------------------------------------------------*/
/*
* easycap.ilk == 0 => CVBS+S-VIDEO HARDWARE, AUDIO wMaxPacketSize=256
* easycap.ilk == 2 => CVBS+S-VIDEO HARDWARE, AUDIO wMaxPacketSize=9
* easycap.ilk == 3 => FOUR-CVBS HARDWARE, AUDIO wMaxPacketSize=9
*/
/*---------------------------------------------------------------------------*/
struct easycap {
unsigned int audio_pages_per_fragment;
unsigned int audio_bytes_per_fragment;
unsigned int audio_buffer_page_many;

#define UPSAMPLE
#if defined(UPSAMPLE)
__s16 oldaudio;
#endif /*UPSAMPLE*/

struct easycap_format easycap_format[1 + SETTINGS_MANY];

int ilk;
bool microphone;
Expand Down Expand Up @@ -377,16 +456,6 @@ long long int audio_square;
struct data_buffer audio_buffer[];
};
/*---------------------------------------------------------------------------*/
struct easycap_standard {
__u16 mask;
struct v4l2_standard v4l2_standard;
};
struct easycap_format {
__u16 mask;
char name[128];
struct v4l2_format v4l2_format;
};
/*---------------------------------------------------------------------------*/
/*
* VIDEO FUNCTION PROTOTYPES
*/
Expand Down Expand Up @@ -501,65 +570,6 @@ long long int quotient;
unsigned long long int remainder;
} signed_div(long long int, long long int);
/*---------------------------------------------------------------------------*/
/*
* IT IS ESSENTIAL THAT EVEN-NUMBERED STANDARDS ARE 25 FRAMES PER SECOND,
* ODD-NUMBERED STANDARDS ARE 30 FRAMES PER SECOND.
* THE NUMBERING OF STANDARDS MUST NOT BE CHANGED WITHOUT DUE CARE. NOT
* ONLY MUST THE PARAMETER
* STANDARD_MANY
* BE CHANGED TO CORRESPOND TO THE NEW NUMBER OF STANDARDS, BUT ALSO THE
* NUMBERING MUST REMAIN AN UNBROKEN ASCENDING SEQUENCE: DUMMY STANDARDS
* MAY NEED TO BE ADDED. APPROPRIATE CHANGES WILL ALWAYS BE REQUIRED IN
* ROUTINE fillin_formats() AND POSSIBLY ELSEWHERE. BEWARE.
*/
/*---------------------------------------------------------------------------*/
#define PAL_BGHIN 0
#define PAL_Nc 2
#define SECAM 4
#define NTSC_N 6
#define NTSC_N_443 8
#define NTSC_M 1
#define NTSC_443 3
#define NTSC_M_JP 5
#define PAL_60 7
#define PAL_M 9
#define STANDARD_MANY 10
/*---------------------------------------------------------------------------*/
/*
* ENUMS
*/
/*---------------------------------------------------------------------------*/
enum {
AT_720x576,
AT_704x576,
AT_640x480,
AT_720x480,
AT_360x288,
AT_320x240,
AT_360x240,
RESOLUTION_MANY
};
enum {
FMT_UYVY,
FMT_YUY2,
FMT_RGB24,
FMT_RGB32,
FMT_BGR24,
FMT_BGR32,
PIXELFORMAT_MANY
};
enum {
FIELD_NONE,
FIELD_INTERLACED,
FIELD_ALTERNATE,
INTERLACE_MANY
};
#define SETTINGS_MANY (STANDARD_MANY * \
RESOLUTION_MANY * \
2 * \
PIXELFORMAT_MANY * \
INTERLACE_MANY)
/*---------------------------------------------------------------------------*/
/*
* MACROS
*/
Expand Down
17 changes: 9 additions & 8 deletions drivers/staging/easycap/easycap_ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
/*---------------------------------------------------------------------------*/
int adjust_standard(struct easycap *peasycap, v4l2_std_id std_id)
{
struct easycap_standard *peasycap_standard;
struct easycap_standard const *peasycap_standard;
__u16 reg, set;
int ir, rc, need;
unsigned int itwas, isnow;
Expand Down Expand Up @@ -1447,7 +1447,7 @@ case VIDIOC_ENUMSTD: {
static int last0 = -1, last1 = -1, last2 = -1, last3 = -1;
static struct v4l2_standard v4l2_standard;
static __u32 index;
static struct easycap_standard *peasycap_standard;
static struct easycap_standard const *peasycap_standard;

JOT(8, "VIDIOC_ENUMSTD\n");

Expand Down Expand Up @@ -1479,11 +1479,12 @@ case VIDIOC_ENUMSTD: {
}
JOT(8, "%i=index: %s\n", index, \
&(peasycap_standard->v4l2_standard.name[0]));
peasycap_standard->v4l2_standard.index = index;
memcpy(&v4l2_standard, &(peasycap_standard->v4l2_standard), \
sizeof(struct v4l2_standard));

v4l2_standard.index = index;

if (0 != copy_to_user((void __user *)arg, \
&(peasycap_standard->v4l2_standard), \
if (0 != copy_to_user((void __user *)arg, &v4l2_standard, \
sizeof(struct v4l2_standard))) {
POUT;
return -EFAULT;
Expand All @@ -1493,7 +1494,7 @@ case VIDIOC_ENUMSTD: {
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
case VIDIOC_G_STD: {
static v4l2_std_id std_id;
static struct easycap_standard *peasycap_standard;
static struct easycap_standard const *peasycap_standard;

JOT(8, "VIDIOC_G_STD\n");

Expand Down Expand Up @@ -2094,7 +2095,7 @@ case SNDCTL_DSP_GETBLKSIZE: {
if (0 != copy_from_user(&incoming, (void __user *)arg, sizeof(int)))
return -EFAULT;
JOT(8, "........... %i=incoming\n", incoming);
incoming = audio_bytes_per_fragment;
incoming = peasycap->audio_bytes_per_fragment;
if (0 != copy_to_user((void __user *)arg, &incoming, sizeof(int)))
return -EFAULT;
break;
Expand All @@ -2104,7 +2105,7 @@ case SNDCTL_DSP_GETISPACE: {

JOT(8, "SNDCTL_DSP_GETISPACE\n");

audio_buf_info.bytes = audio_bytes_per_fragment;
audio_buf_info.bytes = peasycap->audio_bytes_per_fragment;
audio_buf_info.fragments = 1;
audio_buf_info.fragsize = 0;
audio_buf_info.fragstotal = 0;
Expand Down
1 change: 0 additions & 1 deletion drivers/staging/easycap/easycap_ioctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,3 @@
/*****************************************************************************/
extern struct easycap_format easycap_format[];
extern struct v4l2_queryctrl easycap_control[];
extern unsigned int audio_bytes_per_fragment;
31 changes: 15 additions & 16 deletions drivers/staging/easycap/easycap_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@
int easycap_debug;
module_param(easycap_debug, int, S_IRUGO | S_IWUSR);

unsigned int audio_pages_per_fragment;
unsigned int audio_bytes_per_fragment;
unsigned int audio_buffer_page_many;

/*---------------------------------------------------------------------------*/
/*
* PARAMETERS APPLICABLE TO ENTIRE DRIVER, I.E. BOTH VIDEO AND AUDIO
Expand Down Expand Up @@ -86,7 +82,7 @@ struct usb_class_driver easycap_class = {
/*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
#if defined(EASYCAP_IS_VIDEODEV_CLIENT)
#if defined(EASYCAP_NEEDS_V4L2_FOPS)
struct v4l2_file_operations v4l2_fops = {
const struct v4l2_file_operations v4l2_fops = {
.owner = THIS_MODULE,
.open = easycap_open_noinode,
.release = easycap_release_noinode,
Expand Down Expand Up @@ -770,7 +766,7 @@ JOT(4, "easysnd_delete(): isoc audio buffers freed: %i pages\n", \
/*---------------------------------------------------------------------------*/
JOT(4, "freeing audio buffers.\n");
lost = 0;
for (k = 0; k < audio_buffer_page_many; k++) {
for (k = 0; k < peasycap->audio_buffer_page_many; k++) {
if ((void *)NULL != peasycap->audio_buffer[k].pgo) {
free_page((unsigned long)(peasycap->audio_buffer[k].pgo));
peasycap->audio_buffer[k].pgo = (void *)NULL;
Expand Down Expand Up @@ -3865,30 +3861,32 @@ case 2: {
peasycap->ilk |= 0x02;
SAY("hardware is FOUR-CVBS\n");
peasycap->microphone = true;
audio_pages_per_fragment = 2;
peasycap->audio_pages_per_fragment = 2;
} else if (256 == peasycap->audio_isoc_maxframesize) {
peasycap->ilk &= ~0x02;
SAY("hardware is CVBS+S-VIDEO\n");
peasycap->microphone = false;
audio_pages_per_fragment = 4;
peasycap->audio_pages_per_fragment = 4;
} else {
SAY("hardware is unidentified:\n");
SAY("%i=audio_isoc_maxframesize\n", \
peasycap->audio_isoc_maxframesize);
return -ENOENT;
}

audio_bytes_per_fragment = audio_pages_per_fragment * \
peasycap->audio_bytes_per_fragment = \
peasycap->audio_pages_per_fragment * \
PAGE_SIZE ;
audio_buffer_page_many = (AUDIO_FRAGMENT_MANY * \
audio_pages_per_fragment);
peasycap->audio_buffer_page_many = (AUDIO_FRAGMENT_MANY * \
peasycap->audio_pages_per_fragment);

JOT(4, "%6i=AUDIO_FRAGMENT_MANY\n", AUDIO_FRAGMENT_MANY);
JOT(4, "%6i=audio_pages_per_fragment\n", \
audio_pages_per_fragment);
peasycap->audio_pages_per_fragment);
JOT(4, "%6i=audio_bytes_per_fragment\n", \
audio_bytes_per_fragment);
JOT(4, "%6i=audio_buffer_page_many\n", audio_buffer_page_many);
peasycap->audio_bytes_per_fragment);
JOT(4, "%6i=audio_buffer_page_many\n", \
peasycap->audio_buffer_page_many);

peasycap->audio_isoc_framesperdesc = 128;

Expand Down Expand Up @@ -3946,9 +3944,10 @@ case 2: {
peasycap->purb_audio_head = &(peasycap->urb_audio_head);

JOT(4, "allocating an audio buffer\n");
JOT(4, ".... scattered over %i pages\n", audio_buffer_page_many);
JOT(4, ".... scattered over %i pages\n", \
peasycap->audio_buffer_page_many);

for (k = 0; k < audio_buffer_page_many; k++) {
for (k = 0; k < peasycap->audio_buffer_page_many; k++) {
if ((void *)NULL != peasycap->audio_buffer[k].pgo) {
SAY("ERROR: attempting to reallocate audio buffers\n");
} else {
Expand Down
2 changes: 1 addition & 1 deletion drivers/staging/easycap/easycap_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* 1 => 30 fps
*/
/*---------------------------------------------------------------------------*/
struct easycap_standard easycap_standard[] = {
const struct easycap_standard easycap_standard[] = {
{
.mask = 0x000F & PAL_BGHIN ,
.v4l2_standard = {
Expand Down
Loading

0 comments on commit 3d423e9

Please sign in to comment.