~ubuntu-branches/debian/wheezy/linux-2.6/wheezy

« back to all changes in this revision

Viewing changes to drivers/media/video/gspca/pac_common.h

  • Committer: Bazaar Package Importer
  • Author(s): Ben Hutchings, Ben Hutchings, Aurelien Jarno, Martin Michlmayr
  • Date: 2011-04-06 13:53:30 UTC
  • mfrom: (43.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20110406135330-wjufxhd0tvn3zx4z
Tags: 2.6.38-3
[ Ben Hutchings ]
* [ppc64] Add to linux-tools package architectures (Closes: #620124)
* [amd64] Save cr4 to mmu_cr4_features at boot time (Closes: #620284)
* appletalk: Fix bugs introduced when removing use of BKL
* ALSA: Fix yet another race in disconnection
* cciss: Fix lost command issue
* ath9k: Fix kernel panic in AR2427
* ses: Avoid kernel panic when lun 0 is not mapped
* PCI/ACPI: Report ASPM support to BIOS if not disabled from command line

[ Aurelien Jarno ]
* rtlwifi: fix build when PCI is not enabled.

[ Martin Michlmayr ]
* rtlwifi: Eliminate udelay calls with too large values (Closes: #620204)

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 */
25
25
 
26
26
/* We calculate the autogain at the end of the transfer of a frame, at this
27
 
   moment a frame with the old settings is being transmitted, and a frame is
28
 
   being captured with the old settings. So if we adjust the autogain we must
29
 
   ignore atleast the 2 next frames for the new settings to come into effect
30
 
   before doing any other adjustments */
31
 
#define PAC_AUTOGAIN_IGNORE_FRAMES      3
 
27
   moment a frame with the old settings is being captured and transmitted. So
 
28
   if we adjust the gain or exposure we must ignore atleast the next frame for
 
29
   the new settings to come into effect before doing any other adjustments. */
 
30
#define PAC_AUTOGAIN_IGNORE_FRAMES      2
32
31
 
33
32
static const unsigned char pac_sof_marker[5] =
34
33
                { 0xff, 0xff, 0x00, 0xff, 0x96 };
35
34
 
36
 
static unsigned char *pac_find_sof(struct gspca_dev *gspca_dev,
 
35
/*
 
36
   The following state machine finds the SOF marker sequence
 
37
   0xff, 0xff, 0x00, 0xff, 0x96 in a byte stream.
 
38
 
 
39
           +----------+
 
40
           | 0: START |<---------------\
 
41
           +----------+<-\             |
 
42
             |       \---/otherwise    |
 
43
             v 0xff                    |
 
44
           +----------+ otherwise      |
 
45
           |     1    |--------------->*
 
46
           |          |                ^
 
47
           +----------+                |
 
48
             |                         |
 
49
             v 0xff                    |
 
50
           +----------+<-\0xff         |
 
51
        /->|          |--/             |
 
52
        |  |     2    |--------------->*
 
53
        |  |          | otherwise      ^
 
54
        |  +----------+                |
 
55
        |    |                         |
 
56
        |    v 0x00                    |
 
57
        |  +----------+                |
 
58
        |  |     3    |                |
 
59
        |  |          |--------------->*
 
60
        |  +----------+ otherwise      ^
 
61
        |    |                         |
 
62
   0xff |    v 0xff                    |
 
63
        |  +----------+                |
 
64
        \--|     4    |                |
 
65
           |          |----------------/
 
66
           +----------+ otherwise
 
67
             |
 
68
             v 0x96
 
69
           +----------+
 
70
           |  FOUND   |
 
71
           +----------+
 
72
*/
 
73
 
 
74
static unsigned char *pac_find_sof(u8 *sof_read,
37
75
                                        unsigned char *m, int len)
38
76
{
39
 
        struct sd *sd = (struct sd *) gspca_dev;
40
77
        int i;
41
78
 
42
79
        /* Search for the SOF marker (fixed part) in the header */
43
80
        for (i = 0; i < len; i++) {
44
 
                if (m[i] == pac_sof_marker[sd->sof_read]) {
45
 
                        sd->sof_read++;
46
 
                        if (sd->sof_read == sizeof(pac_sof_marker)) {
 
81
                switch (*sof_read) {
 
82
                case 0:
 
83
                        if (m[i] == 0xff)
 
84
                                *sof_read = 1;
 
85
                        break;
 
86
                case 1:
 
87
                        if (m[i] == 0xff)
 
88
                                *sof_read = 2;
 
89
                        else
 
90
                                *sof_read = 0;
 
91
                        break;
 
92
                case 2:
 
93
                        switch (m[i]) {
 
94
                        case 0x00:
 
95
                                *sof_read = 3;
 
96
                                break;
 
97
                        case 0xff:
 
98
                                /* stay in this state */
 
99
                                break;
 
100
                        default:
 
101
                                *sof_read = 0;
 
102
                        }
 
103
                        break;
 
104
                case 3:
 
105
                        if (m[i] == 0xff)
 
106
                                *sof_read = 4;
 
107
                        else
 
108
                                *sof_read = 0;
 
109
                        break;
 
110
                case 4:
 
111
                        switch (m[i]) {
 
112
                        case 0x96:
 
113
                                /* Pattern found */
47
114
                                PDEBUG(D_FRAM,
48
115
                                        "SOF found, bytes to analyze: %u."
49
116
                                        " Frame starts at byte #%u",
50
117
                                        len, i + 1);
51
 
                                sd->sof_read = 0;
 
118
                                *sof_read = 0;
52
119
                                return m + i + 1;
 
120
                                break;
 
121
                        case 0xff:
 
122
                                *sof_read = 2;
 
123
                                break;
 
124
                        default:
 
125
                                *sof_read = 0;
53
126
                        }
54
 
                } else {
55
 
                        sd->sof_read = 0;
 
127
                        break;
 
128
                default:
 
129
                        *sof_read = 0;
56
130
                }
57
131
        }
58
132