MODULE_AUTHOR("Adam Baker <linux@baker-net.org.uk>, Theodore Kilgore <kilgota@auburn.edu>");
MODULE_DESCRIPTION("GSPCA/SQ905 USB Camera Driver");
MODULE_LICENSE("GPL");
/* Default timeouts, in ms */ #define SQ905_CMD_TIMEOUT 500 #define SQ905_DATA_TIMEOUT 1000
/* Maximum transfer size to use. */ #define SQ905_MAX_TRANSFER 0x8000 #define FRAME_HEADER_LEN 64
/* The known modes, or registers. These go in the "value" slot. */
/* 00 is "none" obviously */
#define SQ905_BULK_READ 0x03 /* precedes any bulk read */ #define SQ905_COMMAND 0x06 /* precedes the command codes below */ #define SQ905_PING 0x07 /* when reading an "idling" command */ #define SQ905_READ_DONE 0xc0 /* ack bulk read completed */
/* Any non-zero value in the bottom 2 bits of the 2nd byte of *theIDappearstoindicatethecameracando640*480.Ifthe *LSBofthatbyteissettheimageisjustupsidedown,otherwise
* it is rotated 180 degrees. */ #define SQ905_HIRES_MASK 0x00000300 #define SQ905_ORIENTATION_MASK 0x00000100
/* Some command codes. These go in the "index" slot. */
#define SQ905_ID 0xf0 /* asks for model string */ #define SQ905_CONFIG 0x20 /* gets photo alloc. table, not used here */ #define SQ905_DATA 0x30 /* accesses photo data, not used here */ #define SQ905_CLEAR 0xa0 /* clear everything */ #define SQ905_CAPTURE_LOW 0x60 /* Starts capture at 160x120 */ #define SQ905_CAPTURE_MED 0x61 /* Starts capture at 320x240 */ #define SQ905_CAPTURE_HIGH 0x62 /* Starts capture at 640x480 (some cams only) */ /* note that the capture command also controls the output dimensions */
/* Structure to hold all of our device specific stuff */ struct sd { struct gspca_dev gspca_dev; /* !! must be the first item */
/* *requestandreadablockofdata-seewarningonsq905_command.
*/ staticint
sq905_read_data(struct gspca_dev *gspca_dev, u8 *data, int size, int need_lock)
{ int ret; int act_len = 0;
/* *Thisfunctioniscalledasaworkqueuefunctionandrunswheneverthecamera *isstreamingdata.Becauseitisaworkqueuefunctionitisallowedtosleep *sowecanusesynchronousUSBcalls.Toavoidpossiblecollisionswithother *threadsattemptingtousegspca_dev->usb_bufwetaketheusb_lockwhen *performingUSBoperationsusingit.Inpracticewedon'treallyneedthis *asthecameradoesn'tprovideanycontrols.
*/ staticvoid sq905_dostream(struct work_struct *work)
{ struct sd *dev = container_of(work, struct sd, work_struct); struct gspca_dev *gspca_dev = &dev->gspca_dev; int bytes_left; /* bytes remaining in current frame. */ int data_len; /* size to use for the next read. */ int header_read; /* true if we have already read the frame header. */ int packet_type; int frame_sz; int ret;
u8 *data;
u8 *buffer;
buffer = kmalloc(SQ905_MAX_TRANSFER, GFP_KERNEL); if (!buffer) {
pr_err("Couldn't allocate USB buffer\n"); goto quit_stream;
}
while (gspca_dev->present && gspca_dev->streaming) { #ifdef CONFIG_PM if (gspca_dev->frozen) break; #endif /* request some data and then read it until we have
* a complete frame. */
bytes_left = frame_sz;
header_read = 0;
/* Note we do not check for gspca_dev->streaming here, as wemustfinishreadinganentireframe,otherwisethe nexttimewestreamwestartreadinginthemiddleofa
frame. */ while (bytes_left > 0 && gspca_dev->present) {
data_len = bytes_left > SQ905_MAX_TRANSFER ?
SQ905_MAX_TRANSFER : bytes_left;
ret = sq905_read_data(gspca_dev, buffer, data_len, 1); if (ret < 0) goto quit_stream;
gspca_dbg(gspca_dev, D_PACK, "Got %d bytes out of %d for frame\n",
data_len, bytes_left);
bytes_left -= data_len;
data = buffer; if (!header_read) {
packet_type = FIRST_PACKET; /* The first 64 bytes of each frame are
* a header full of FF 00 bytes */
data += FRAME_HEADER_LEN;
data_len -= FRAME_HEADER_LEN;
header_read = 1;
} elseif (bytes_left == 0) {
packet_type = LAST_PACKET;
} else {
packet_type = INTER_PACKET;
}
gspca_frame_add(gspca_dev, packet_type,
data, data_len); /* If entire frame fits in one packet we still
need to add a LAST_PACKET */ if (packet_type == FIRST_PACKET &&
bytes_left == 0)
gspca_frame_add(gspca_dev, LAST_PACKET,
NULL, 0);
} if (gspca_dev->present) { /* acknowledge the frame */
mutex_lock(&gspca_dev->usb_lock);
ret = sq905_ack_frame(gspca_dev);
mutex_unlock(&gspca_dev->usb_lock); if (ret < 0) goto quit_stream;
}
}
quit_stream: if (gspca_dev->present) {
mutex_lock(&gspca_dev->usb_lock);
sq905_command(gspca_dev, SQ905_CLEAR);
mutex_unlock(&gspca_dev->usb_lock);
}
kfree(buffer);
}
/* This function is called at probe time just before sd_init */ staticint sd_config(struct gspca_dev *gspca_dev, conststruct usb_device_id *id)
{ struct cam *cam = &gspca_dev->cam; struct sd *dev = (struct sd *) gspca_dev;
/* We don't use the buffer gspca allocates so make it small. */
cam->bulk = 1;
cam->bulk_size = 64;
INIT_WORK(&dev->work_struct, sq905_dostream);
return0;
}
/* called on streamoff with alt==0 and on disconnect */ /* the usb_lock is held at entry - restore on exit */ staticvoid sd_stop0(struct gspca_dev *gspca_dev)
{ struct sd *dev = (struct sd *) gspca_dev;
/* wait for the work queue to terminate */
mutex_unlock(&gspca_dev->usb_lock); /* This waits for sq905_dostream to finish */
destroy_workqueue(dev->work_thread);
dev->work_thread = NULL;
mutex_lock(&gspca_dev->usb_lock);
}
/* this function is called at probe and resume time */ staticint sd_init(struct gspca_dev *gspca_dev)
{
u32 ident; int ret;
/* connect to the camera and read *themodelIDandprocessthatandputitaway.
*/
ret = sq905_command(gspca_dev, SQ905_CLEAR); if (ret < 0) return ret;
ret = sq905_command(gspca_dev, SQ905_ID); if (ret < 0) return ret;
ret = sq905_read_data(gspca_dev, gspca_dev->usb_buf, 4, 0); if (ret < 0) return ret; /* usb_buf is allocated with kmalloc so is aligned. *Cameramodelnumberistherightwayroundifweassumethis
* reverse engineered ID is supposed to be big endian. */
ident = be32_to_cpup((__be32 *)gspca_dev->usb_buf);
ret = sq905_command(gspca_dev, SQ905_CLEAR); if (ret < 0) return ret;
gspca_dbg(gspca_dev, D_CONF, "SQ905 camera ID %08x detected\n", ident);
gspca_dev->cam.cam_mode = sq905_mode;
gspca_dev->cam.nmodes = ARRAY_SIZE(sq905_mode); if (!(ident & SQ905_HIRES_MASK))
gspca_dev->cam.nmodes--;
/* Set up for getting frames. */ staticint sd_start(struct gspca_dev *gspca_dev)
{ struct sd *dev = (struct sd *) gspca_dev; int ret;
/* "Open the shutter" and set size, to start capture */ switch (gspca_dev->curr_mode) { default: /* case 2: */
gspca_dbg(gspca_dev, D_STREAM, "Start streaming at high resolution\n");
ret = sq905_command(&dev->gspca_dev, SQ905_CAPTURE_HIGH); break; case1:
gspca_dbg(gspca_dev, D_STREAM, "Start streaming at medium resolution\n");
ret = sq905_command(&dev->gspca_dev, SQ905_CAPTURE_MED); break; case0:
gspca_dbg(gspca_dev, D_STREAM, "Start streaming at low resolution\n");
ret = sq905_command(&dev->gspca_dev, SQ905_CAPTURE_LOW);
}
if (ret < 0) {
gspca_err(gspca_dev, "Start streaming command failed\n"); return ret;
} /* Start the workqueue function to do the streaming */
dev->work_thread = create_singlethread_workqueue(MODULE_NAME); if (!dev->work_thread) return -ENOMEM;
queue_work(dev->work_thread, &dev->work_struct);
return0;
}
/* Table of supported USB devices */ staticconststruct usb_device_id device_table[] = {
{USB_DEVICE(0x2770, 0x9120)},
{}
};
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.18Bemerkung:
(vorverarbeitet am 2026-10-02)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.