31 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
33 #define MODULE_NAME "konica"
35 #include <linux/input.h>
42 #define WHITEBAL_REG 0x01
43 #define BRIGHTNESS_REG 0x02
44 #define SHARPNESS_REG 0x03
45 #define CONTRAST_REG 0x04
46 #define SATURATION_REG 0x05
73 .sizeimage = 160 * 136 * 3 / 2 + 960,
78 .sizeimage = 176 * 144 * 3 / 2 + 960,
83 .sizeimage = 320 * 240 * 3 / 2 + 960,
88 static void sd_isoc_irq(
struct urb *
urb);
92 struct usb_device *
dev = gspca_dev->
dev;
106 pr_err(
"reg_w err writing %02x to %02x: %d\n",
112 static void reg_r(
struct gspca_dev *gspca_dev,
u16 value,
u16 index)
114 struct usb_device *dev = gspca_dev->
dev;
128 pr_err(
"reg_r err %d\n", ret);
133 static void konica_stream_on(
struct gspca_dev *gspca_dev)
135 reg_w(gspca_dev, 1, 0x0b);
138 static void konica_stream_off(
struct gspca_dev *gspca_dev)
140 reg_w(gspca_dev, 0, 0x0b);
144 static int sd_config(
struct gspca_dev *gspca_dev,
147 gspca_dev->
cam.cam_mode = vga_mode;
149 gspca_dev->
cam.no_urb_create = 1;
155 static int sd_init(
struct gspca_dev *gspca_dev)
165 for (i = 0; i < 20; i++) {
166 reg_r(gspca_dev, 0, 0x10);
167 if (gspca_dev->
usb_buf[0] == 3)
171 reg_w(gspca_dev, 0, 0x0d);
176 static int sd_start(
struct gspca_dev *gspca_dev)
178 struct sd *
sd = (
struct sd *) gspca_dev;
180 int i,
n, packet_size;
181 struct usb_host_interface *alt;
187 pr_err(
"Couldn't get altsetting\n");
191 packet_size =
le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize);
194 reg_w(gspca_dev, n, 0x08);
196 konica_stream_on(gspca_dev);
203 #error "Not enough URBs in the gspca table"
206 for (n = 0; n < 4; n++) {
212 pr_err(
"usb_alloc_urb failed\n");
217 packet_size * SD_NPKT,
220 if (urb->transfer_buffer ==
NULL) {
221 pr_err(
"usb_buffer_alloc failed\n");
225 urb->dev = gspca_dev->
dev;
226 urb->context = gspca_dev;
227 urb->transfer_buffer_length = packet_size *
SD_NPKT;
228 urb->pipe = usb_rcvisocpipe(gspca_dev->
dev,
229 n & 1 ? 0x81 : 0x82);
230 urb->transfer_flags = URB_ISO_ASAP
231 | URB_NO_TRANSFER_DMA_MAP;
233 urb->complete = sd_isoc_irq;
234 urb->number_of_packets = SD_NPKT;
235 for (i = 0; i < SD_NPKT; i++) {
236 urb->iso_frame_desc[
i].length = packet_size;
237 urb->iso_frame_desc[
i].offset = packet_size *
i;
244 static void sd_stopN(
struct gspca_dev *gspca_dev)
246 struct sd *sd = (
struct sd *) gspca_dev;
248 konica_stream_off(gspca_dev);
249 #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
253 input_report_key(gspca_dev->input_dev,
KEY_CAMERA, 0);
254 input_sync(gspca_dev->input_dev);
261 static void sd_isoc_irq(
struct urb *urb)
263 struct gspca_dev *gspca_dev = (
struct gspca_dev *) urb->context;
264 struct sd *sd = (
struct sd *) gspca_dev;
265 struct urb *data_urb, *status_urb;
269 PDEBUG(D_PACK,
"sd isoc irq");
273 if (urb->status != 0) {
277 if (gspca_dev->frozen)
283 pr_err(
"resubmit urb error %d\n", st);
288 if (urb->transfer_buffer_length > 32) {
297 if (!data_urb || data_urb->start_frame != status_urb->start_frame) {
302 if (data_urb->number_of_packets != status_urb->number_of_packets) {
304 "no packets does not match, data: %d, status: %d",
305 data_urb->number_of_packets,
306 status_urb->number_of_packets);
310 for (i = 0; i < status_urb->number_of_packets; i++) {
311 if (data_urb->iso_frame_desc[i].status ||
312 status_urb->iso_frame_desc[i].status) {
314 "pkt %d data-status %d, status-status %d", i,
315 data_urb->iso_frame_desc[i].status,
316 status_urb->iso_frame_desc[i].status);
321 if (status_urb->iso_frame_desc[i].actual_length != 1) {
323 "bad status packet length %d",
324 status_urb->iso_frame_desc[i].actual_length);
329 st = *((
u8 *)status_urb->transfer_buffer
330 + status_urb->iso_frame_desc[i].offset);
332 data = (
u8 *)data_urb->transfer_buffer
333 + data_urb->iso_frame_desc[i].offset;
348 #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
349 u8 button_state = st & 0x40 ? 1 : 0;
351 input_report_key(gspca_dev->input_dev,
354 input_sync(gspca_dev->input_dev);
362 data_urb->iso_frame_desc[i].actual_length);
370 "usb_submit_urb(data_urb) ret %d", st);
374 pr_err(
"usb_submit_urb(status_urb) ret %d\n", st);
379 struct gspca_dev *gspca_dev =
389 konica_stream_off(gspca_dev);
391 konica_stream_on(gspca_dev);
394 konica_stream_off(gspca_dev);
396 konica_stream_on(gspca_dev);
399 konica_stream_off(gspca_dev);
401 konica_stream_on(gspca_dev);
404 konica_stream_off(gspca_dev);
406 konica_stream_on(gspca_dev);
409 konica_stream_off(gspca_dev);
411 konica_stream_on(gspca_dev);
421 static int sd_init_controls(
struct gspca_dev *gspca_dev)
425 gspca_dev->
vdev.ctrl_handler = hdl;
441 pr_err(
"Could not initialize controls\n");
452 .init_controls = sd_init_controls,
455 #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
462 {USB_DEVICE(0x04c8, 0x0720)},
475 static struct usb_driver sd_driver = {
477 .id_table = device_table,
481 .suspend = gspca_suspend,
482 .resume = gspca_resume,
483 .reset_resume = gspca_resume,