This source file includes following definitions.
- command
- dostream
- sd_config
- sd_init
- sd_start
- sd_stop0
- sd_probe
1
2
3
4
5
6
7
8 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
9
10 #define MODULE_NAME "finepix"
11
12 #include "gspca.h"
13
14 MODULE_AUTHOR("Frank Zago <frank@zago.net>");
15 MODULE_DESCRIPTION("Fujifilm FinePix USB V4L2 driver");
16 MODULE_LICENSE("GPL");
17
18
19 #define FPIX_TIMEOUT 250
20
21
22
23
24 #define FPIX_MAX_TRANSFER 0x2000
25
26
27 struct usb_fpix {
28 struct gspca_dev gspca_dev;
29
30 struct work_struct work_struct;
31 };
32
33
34
35
36
37 #define NEXT_FRAME_DELAY 35
38
39
40 static const struct v4l2_pix_format fpix_mode[1] = {
41 { 320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
42 .bytesperline = 320,
43 .sizeimage = 320 * 240 * 3 / 8 + 590,
44 .colorspace = V4L2_COLORSPACE_SRGB,
45 .priv = 0}
46 };
47
48
49 static int command(struct gspca_dev *gspca_dev,
50 int order)
51 {
52 static u8 order_values[2][12] = {
53 {0xc6, 0, 0, 0, 0, 0, 0, 0, 0x20, 0, 0, 0},
54 {0xd3, 0, 0, 0, 0, 0, 0, 0x01, 0, 0, 0, 0},
55 };
56
57 memcpy(gspca_dev->usb_buf, order_values[order], 12);
58 return usb_control_msg(gspca_dev->dev,
59 usb_sndctrlpipe(gspca_dev->dev, 0),
60 USB_REQ_GET_STATUS,
61 USB_DIR_OUT | USB_TYPE_CLASS |
62 USB_RECIP_INTERFACE, 0, 0, gspca_dev->usb_buf,
63 12, FPIX_TIMEOUT);
64 }
65
66
67
68
69
70
71
72
73
74 static void dostream(struct work_struct *work)
75 {
76 struct usb_fpix *dev = container_of(work, struct usb_fpix, work_struct);
77 struct gspca_dev *gspca_dev = &dev->gspca_dev;
78 struct urb *urb = gspca_dev->urb[0];
79 u8 *data = urb->transfer_buffer;
80 int ret = 0;
81 int len;
82
83 gspca_dbg(gspca_dev, D_STREAM, "dostream started\n");
84
85
86 again:
87 while (gspca_dev->present && gspca_dev->streaming) {
88 #ifdef CONFIG_PM
89 if (gspca_dev->frozen)
90 break;
91 #endif
92
93
94 mutex_lock(&gspca_dev->usb_lock);
95 ret = command(gspca_dev, 1);
96 mutex_unlock(&gspca_dev->usb_lock);
97 if (ret < 0)
98 break;
99 #ifdef CONFIG_PM
100 if (gspca_dev->frozen)
101 break;
102 #endif
103 if (!gspca_dev->present || !gspca_dev->streaming)
104 break;
105
106
107 for (;;) {
108 ret = usb_bulk_msg(gspca_dev->dev,
109 urb->pipe,
110 data,
111 FPIX_MAX_TRANSFER,
112 &len, FPIX_TIMEOUT);
113 if (ret < 0) {
114
115
116 goto again;
117 }
118 #ifdef CONFIG_PM
119 if (gspca_dev->frozen)
120 goto out;
121 #endif
122 if (!gspca_dev->present || !gspca_dev->streaming)
123 goto out;
124 if (len < FPIX_MAX_TRANSFER ||
125 (data[len - 2] == 0xff &&
126 data[len - 1] == 0xd9)) {
127
128
129
130
131
132
133
134 gspca_frame_add(gspca_dev, LAST_PACKET,
135 data, len);
136 break;
137 }
138
139
140 gspca_frame_add(gspca_dev,
141 gspca_dev->last_packet_type
142 == LAST_PACKET
143 ? FIRST_PACKET : INTER_PACKET,
144 data, len);
145 }
146
147
148
149
150 msleep(NEXT_FRAME_DELAY);
151 }
152
153 out:
154 gspca_dbg(gspca_dev, D_STREAM, "dostream stopped\n");
155 }
156
157
158 static int sd_config(struct gspca_dev *gspca_dev,
159 const struct usb_device_id *id)
160 {
161 struct usb_fpix *dev = (struct usb_fpix *) gspca_dev;
162 struct cam *cam = &gspca_dev->cam;
163
164 cam->cam_mode = fpix_mode;
165 cam->nmodes = 1;
166 cam->bulk = 1;
167 cam->bulk_size = FPIX_MAX_TRANSFER;
168
169 INIT_WORK(&dev->work_struct, dostream);
170
171 return 0;
172 }
173
174
175 static int sd_init(struct gspca_dev *gspca_dev)
176 {
177 return 0;
178 }
179
180
181 static int sd_start(struct gspca_dev *gspca_dev)
182 {
183 struct usb_fpix *dev = (struct usb_fpix *) gspca_dev;
184 int ret, len;
185
186
187 ret = command(gspca_dev, 0);
188 if (ret < 0) {
189 pr_err("init failed %d\n", ret);
190 return ret;
191 }
192
193
194
195 ret = usb_bulk_msg(gspca_dev->dev,
196 gspca_dev->urb[0]->pipe,
197 gspca_dev->urb[0]->transfer_buffer,
198 FPIX_MAX_TRANSFER, &len,
199 FPIX_TIMEOUT);
200 if (ret < 0) {
201 pr_err("usb_bulk_msg failed %d\n", ret);
202 return ret;
203 }
204
205
206 ret = command(gspca_dev, 1);
207 if (ret < 0) {
208 pr_err("frame request failed %d\n", ret);
209 return ret;
210 }
211
212
213 usb_clear_halt(gspca_dev->dev, gspca_dev->urb[0]->pipe);
214
215 schedule_work(&dev->work_struct);
216
217 return 0;
218 }
219
220
221
222 static void sd_stop0(struct gspca_dev *gspca_dev)
223 {
224 struct usb_fpix *dev = (struct usb_fpix *) gspca_dev;
225
226
227 mutex_unlock(&gspca_dev->usb_lock);
228 flush_work(&dev->work_struct);
229 mutex_lock(&gspca_dev->usb_lock);
230 }
231
232
233 static const struct usb_device_id device_table[] = {
234 {USB_DEVICE(0x04cb, 0x0104)},
235 {USB_DEVICE(0x04cb, 0x0109)},
236 {USB_DEVICE(0x04cb, 0x010b)},
237 {USB_DEVICE(0x04cb, 0x010f)},
238 {USB_DEVICE(0x04cb, 0x0111)},
239 {USB_DEVICE(0x04cb, 0x0113)},
240 {USB_DEVICE(0x04cb, 0x0115)},
241 {USB_DEVICE(0x04cb, 0x0117)},
242 {USB_DEVICE(0x04cb, 0x0119)},
243 {USB_DEVICE(0x04cb, 0x011b)},
244 {USB_DEVICE(0x04cb, 0x011d)},
245 {USB_DEVICE(0x04cb, 0x0121)},
246 {USB_DEVICE(0x04cb, 0x0123)},
247 {USB_DEVICE(0x04cb, 0x0125)},
248 {USB_DEVICE(0x04cb, 0x0127)},
249 {USB_DEVICE(0x04cb, 0x0129)},
250 {USB_DEVICE(0x04cb, 0x012b)},
251 {USB_DEVICE(0x04cb, 0x012d)},
252 {USB_DEVICE(0x04cb, 0x012f)},
253 {USB_DEVICE(0x04cb, 0x0131)},
254 {USB_DEVICE(0x04cb, 0x013b)},
255 {USB_DEVICE(0x04cb, 0x013d)},
256 {USB_DEVICE(0x04cb, 0x013f)},
257 {}
258 };
259
260 MODULE_DEVICE_TABLE(usb, device_table);
261
262
263 static const struct sd_desc sd_desc = {
264 .name = MODULE_NAME,
265 .config = sd_config,
266 .init = sd_init,
267 .start = sd_start,
268 .stop0 = sd_stop0,
269 };
270
271
272 static int sd_probe(struct usb_interface *intf,
273 const struct usb_device_id *id)
274 {
275 return gspca_dev_probe(intf, id,
276 &sd_desc,
277 sizeof(struct usb_fpix),
278 THIS_MODULE);
279 }
280
281 static struct usb_driver sd_driver = {
282 .name = MODULE_NAME,
283 .id_table = device_table,
284 .probe = sd_probe,
285 .disconnect = gspca_disconnect,
286 #ifdef CONFIG_PM
287 .suspend = gspca_suspend,
288 .resume = gspca_resume,
289 .reset_resume = gspca_resume,
290 #endif
291 };
292
293 module_usb_driver(sd_driver);