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