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