// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Subdriver for Scopium astro-camera (DTCS033, 0547:7303)
*
* Copyright (C) 2014 Robert Butora (robert.butora.fi@gmail.com)
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#define MODULE_NAME "dtcs033"
#include "gspca.h"
MODULE_AUTHOR("Robert Butora <robert.butora.fi@gmail.com>" );
MODULE_DESCRIPTION("Scopium DTCS033 astro-cam USB Camera Driver" );
MODULE_LICENSE("GPL" );
struct dtcs033_usb_requests {
u8 bRequestType;
u8 bRequest;
u16 wValue;
u16 wIndex;
u16 wLength;
};
/* send a usb request */
static void reg_rw(struct gspca_dev *gspca_dev,
u8 bRequestType, u8 bRequest,
u16 wValue, u16 wIndex, u16 wLength)
{
struct usb_device *udev = gspca_dev->dev;
int ret;
if (gspca_dev->usb_err < 0 )
return ;
ret = usb_control_msg(udev,
usb_rcvctrlpipe(udev, 0 ),
bRequest,
bRequestType,
wValue, wIndex,
gspca_dev->usb_buf, wLength, 500 );
if (ret < 0 ) {
gspca_dev->usb_err = ret;
pr_err("usb_control_msg error %d\n" , ret);
}
return ;
}
/* send several usb in/out requests */
static int reg_reqs(struct gspca_dev *gspca_dev,
const struct dtcs033_usb_requests *preqs, int n_reqs)
{
int i = 0 ;
const struct dtcs033_usb_requests *preq;
while ((i < n_reqs) && (gspca_dev->usb_err >= 0 )) {
preq = &preqs[i];
reg_rw(gspca_dev, preq->bRequestType, preq->bRequest,
preq->wValue, preq->wIndex, preq->wLength);
if (gspca_dev->usb_err < 0 ) {
gspca_err(gspca_dev, "usb error request no: %d / %d\n" ,
i, n_reqs);
} else if (preq->bRequestType & USB_DIR_IN) {
gspca_dbg(gspca_dev, D_STREAM,
"USB IN (%d) returned[%d] %3ph %s" ,
i,
preq->wLength,
gspca_dev->usb_buf,
preq->wLength > 3 ? "...\n" : "\n" );
}
i++;
}
return gspca_dev->usb_err;
}
/* -- subdriver interface implementation -- */
#define DT_COLS (640 )
static const struct v4l2_pix_format dtcs033_mode[] = {
/* raw Bayer patterned output */
{DT_COLS, 480 , V4L2_PIX_FMT_GREY, V4L2_FIELD_NONE,
.bytesperline = DT_COLS,
.sizeimage = DT_COLS*480 ,
.colorspace = V4L2_COLORSPACE_SRGB,
},
/* this mode will demosaic the Bayer pattern */
{DT_COLS, 480 , V4L2_PIX_FMT_SRGGB8, V4L2_FIELD_NONE,
.bytesperline = DT_COLS,
.sizeimage = DT_COLS*480 ,
.colorspace = V4L2_COLORSPACE_SRGB,
}
};
/* config called at probe time */
static int sd_config(struct gspca_dev *gspca_dev,
const struct usb_device_id *id)
{
gspca_dev->cam.cam_mode = dtcs033_mode;
gspca_dev->cam.nmodes = ARRAY_SIZE(dtcs033_mode);
gspca_dev->cam.bulk = 1 ;
gspca_dev->cam.bulk_nurbs = 1 ;
gspca_dev->cam.bulk_size = DT_COLS*512 ;
return 0 ;
}
/* init called at probe and resume time */
static int sd_init(struct gspca_dev *gspca_dev)
{
return 0 ;
}
/* start stop the camera */
static int dtcs033_start(struct gspca_dev *gspca_dev);
static void dtcs033_stopN(struct gspca_dev *gspca_dev);
/* intercept camera image data */
static void dtcs033_pkt_scan(struct gspca_dev *gspca_dev,
u8 *data, /* packet data */
int len) /* packet data length */
{
/* drop incomplete frames */
if (len != DT_COLS*512 ) {
gspca_dev->last_packet_type = DISCARD_PACKET;
/* gspca.c: discard invalidates the whole frame. */
return ;
}
/* forward complete frames */
gspca_frame_add(gspca_dev, FIRST_PACKET, NULL, 0 );
gspca_frame_add(gspca_dev, INTER_PACKET,
data + 16 *DT_COLS,
len - 32 *DT_COLS); /* skip first & last 16 lines */
gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0 );
return ;
}
/* -- controls: exposure and gain -- */
static void dtcs033_setexposure(struct gspca_dev *gspca_dev,
s32 expo, s32 gain)
{
/* gain [dB] encoding */
u16 sGain = (u16)gain;
u16 gainVal = 224 +(sGain-14 )*(768 -224 )/(33 -14 );
u16 wIndex = 0 x0100|(0 x00FF&gainVal);
u16 wValue = (0 xFF00&gainVal)>>8 ;
/* exposure time [msec] encoding */
u16 sXTime = (u16)expo;
u16 xtimeVal = (524 *(150 -(sXTime-1 )))/150 ;
const u8 bRequestType =
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE;
const u8 bRequest = 0 x18;
reg_rw(gspca_dev,
bRequestType, bRequest, wValue, wIndex, 0 );
if (gspca_dev->usb_err < 0 )
gspca_err(gspca_dev, "usb error in setexposure(gain) sequence\n" );
reg_rw(gspca_dev,
bRequestType, bRequest, (xtimeVal<<4 ), 0 x6300, 0 );
if (gspca_dev->usb_err < 0 )
gspca_err(gspca_dev, "usb error in setexposure(time) sequence\n" );
}
/* specific webcam descriptor */
struct sd {
struct gspca_dev gspca_dev;/* !! must be the first item */
/* exposure & gain controls */
struct {
struct v4l2_ctrl *exposure;
struct v4l2_ctrl *gain;
};
};
static int sd_s_ctrl(struct v4l2_ctrl *ctrl)
{
struct gspca_dev *gspca_dev =
container_of(ctrl->handler,
struct gspca_dev, ctrl_handler);
struct sd *sd = (struct sd *) gspca_dev;
gspca_dev->usb_err = 0 ;
if (!gspca_dev->streaming)
return 0 ;
switch (ctrl->id) {
case V4L2_CID_EXPOSURE:
dtcs033_setexposure(gspca_dev,
ctrl->val, sd->gain->val);
break ;
case V4L2_CID_GAIN:
dtcs033_setexposure(gspca_dev,
sd->exposure->val, ctrl->val);
break ;
}
return gspca_dev->usb_err;
}
static const struct v4l2_ctrl_ops sd_ctrl_ops = {
.s_ctrl = sd_s_ctrl,
};
static int dtcs033_init_controls(struct gspca_dev *gspca_dev)
{
struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler;
struct sd *sd = (struct sd *) gspca_dev;
gspca_dev->vdev.ctrl_handler = hdl;
v4l2_ctrl_handler_init(hdl, 2 );
/* min max step default */
sd->exposure = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
V4L2_CID_EXPOSURE,
1 , 150 , 1 , 75 );/* [msec] */
sd->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
V4L2_CID_GAIN,
14 , 33 , 1 , 24 );/* [dB] */
if (hdl->error) {
gspca_err(gspca_dev, "Could not initialize controls: %d\n" ,
hdl->error);
return hdl->error;
}
v4l2_ctrl_cluster(2 , &sd->exposure);
return 0 ;
}
/* sub-driver description */
static const struct sd_desc sd_desc = {
.name = MODULE_NAME,
.config = sd_config,
.init = sd_init,
.start = dtcs033_start,
.stopN = dtcs033_stopN,
.pkt_scan = dtcs033_pkt_scan,
.init_controls = dtcs033_init_controls,
};
/* -- module initialisation -- */
static const struct usb_device_id device_table[] = {
{USB_DEVICE(0 x0547, 0 x7303)},
{}
};
MODULE_DEVICE_TABLE(usb, device_table);
/* device connect */
static int sd_probe(struct usb_interface *intf,
const struct usb_device_id *id)
{
return gspca_dev_probe(intf, id,
&sd_desc, sizeof (struct sd),
THIS_MODULE);
}
static struct usb_driver sd_driver = {
.name = MODULE_NAME,
.id_table = device_table,
.probe = sd_probe,
.disconnect = gspca_disconnect,
#ifdef CONFIG_PM
.suspend = gspca_suspend,
.resume = gspca_resume,
.reset_resume = gspca_resume,
#endif
};
module_usb_driver(sd_driver);
/* ---------------------------------------------------------
USB requests to start/stop the camera [USB 2.0 spec Ch.9].
bRequestType :
0x40 = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
0xC0 = USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
*/
static const struct dtcs033_usb_requests dtcs033_start_reqs[] = {
/* -- bRequest,wValue,wIndex,wLength */
{ 0 x40, 0 x01, 0 x0001, 0 x000F, 0 x0000 },
{ 0 x40, 0 x01, 0 x0000, 0 x000F, 0 x0000 },
{ 0 x40, 0 x01, 0 x0001, 0 x000F, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x7F00, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x1001, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x0004, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x7F01, 0 x0000 },
{ 0 x40, 0 x18, 0 x30E0, 0 x0009, 0 x0000 },
{ 0 x40, 0 x18, 0 x0500, 0 x012C, 0 x0000 },
{ 0 x40, 0 x18, 0 x0380, 0 x0200, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x035C, 0 x0000 },
{ 0 x40, 0 x18, 0 x05C0, 0 x0438, 0 x0000 },
{ 0 x40, 0 x18, 0 x0440, 0 x0500, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x0668, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x0700, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x0800, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x0900, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x0A00, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x0B00, 0 x0000 },
{ 0 x40, 0 x18, 0 x30E0, 0 x6009, 0 x0000 },
{ 0 x40, 0 x18, 0 x0500, 0 x612C, 0 x0000 },
{ 0 x40, 0 x18, 0 x2090, 0 x6274, 0 x0000 },
{ 0 x40, 0 x18, 0 x05C0, 0 x6338, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x6400, 0 x0000 },
{ 0 x40, 0 x18, 0 x05C0, 0 x6538, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x6600, 0 x0000 },
{ 0 x40, 0 x18, 0 x0680, 0 x6744, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x6800, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x6900, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x6A00, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x6B00, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x6C00, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x6D00, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x6E00, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x808C, 0 x0000 },
{ 0 x40, 0 x18, 0 x0010, 0 x8101, 0 x0000 },
{ 0 x40, 0 x18, 0 x30E0, 0 x8200, 0 x0000 },
{ 0 x40, 0 x18, 0 x0810, 0 x832C, 0 x0000 },
{ 0 x40, 0 x18, 0 x0680, 0 x842B, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x8500, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x8600, 0 x0000 },
{ 0 x40, 0 x18, 0 x0280, 0 x8715, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x880C, 0 x0000 },
{ 0 x40, 0 x18, 0 x0010, 0 x8901, 0 x0000 },
{ 0 x40, 0 x18, 0 x30E0, 0 x8A00, 0 x0000 },
{ 0 x40, 0 x18, 0 x0810, 0 x8B2C, 0 x0000 },
{ 0 x40, 0 x18, 0 x0680, 0 x8C2B, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x8D00, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x8E00, 0 x0000 },
{ 0 x40, 0 x18, 0 x0280, 0 x8F15, 0 x0000 },
{ 0 x40, 0 x18, 0 x0010, 0 xD040, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 xD100, 0 x0000 },
{ 0 x40, 0 x18, 0 x00B0, 0 xD20A, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 xD300, 0 x0000 },
{ 0 x40, 0 x18, 0 x30E2, 0 xD40D, 0 x0000 },
{ 0 x40, 0 x18, 0 x0001, 0 xD5C0, 0 x0000 },
{ 0 x40, 0 x18, 0 x00A0, 0 xD60A, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 xD700, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x7F00, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x1501, 0 x0000 },
{ 0 x40, 0 x18, 0 x0001, 0 x01FF, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x0200, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x0304, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x1101, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x1201, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x1300, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x1400, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x1601, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x1800, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x1900, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x1A00, 0 x0000 },
{ 0 x40, 0 x18, 0 x2000, 0 x1B00, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x1C00, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x2100, 0 x0000 },
{ 0 x40, 0 x18, 0 x00C0, 0 x228E, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x3001, 0 x0000 },
{ 0 x40, 0 x18, 0 x0010, 0 x3101, 0 x0000 },
{ 0 x40, 0 x18, 0 x0008, 0 x3301, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x3400, 0 x0000 },
{ 0 x40, 0 x18, 0 x0012, 0 x3549, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x3620, 0 x0000 },
{ 0 x40, 0 x18, 0 x0001, 0 x3700, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x4000, 0 x0000 },
{ 0 x40, 0 x18, 0 xFFFF, 0 x41FF, 0 x0000 },
{ 0 x40, 0 x18, 0 xFFFF, 0 x42FF, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x500F, 0 x0000 },
{ 0 x40, 0 x18, 0 x2272, 0 x5108, 0 x0000 },
{ 0 x40, 0 x18, 0 x2272, 0 x5208, 0 x0000 },
{ 0 x40, 0 x18, 0 xFFFF, 0 x53FF, 0 x0000 },
{ 0 x40, 0 x18, 0 xFFFF, 0 x54FF, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x6000, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x6102, 0 x0000 },
{ 0 x40, 0 x18, 0 x0010, 0 x6214, 0 x0000 },
{ 0 x40, 0 x18, 0 x0C80, 0 x6300, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x6401, 0 x0000 },
{ 0 x40, 0 x18, 0 x0680, 0 x6551, 0 x0000 },
{ 0 x40, 0 x18, 0 xFFFF, 0 x66FF, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x6702, 0 x0000 },
{ 0 x40, 0 x18, 0 x0010, 0 x6800, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x6900, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x6A00, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x6B00, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x6C00, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x6D01, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x6E00, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x6F00, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x7000, 0 x0000 },
{ 0 x40, 0 x18, 0 x0001, 0 x7118, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x2001, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x1101, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x1301, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x1300, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x1501, 0 x0000 },
{ 0 xC0, 0 x11, 0 x0000, 0 x24C0, 0 x0003 },
{ 0 x40, 0 x18, 0 x0000, 0 x3000, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x3620, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x1501, 0 x0000 },
{ 0 x40, 0 x18, 0 x0010, 0 x6300, 0 x0000 },
{ 0 x40, 0 x18, 0 x0002, 0 x01F0, 0 x0000 },
{ 0 x40, 0 x01, 0 x0003, 0 x000F, 0 x0000 }
};
static const struct dtcs033_usb_requests dtcs033_stop_reqs[] = {
/* -- bRequest,wValue,wIndex,wLength */
{ 0 x40, 0 x01, 0 x0001, 0 x000F, 0 x0000 },
{ 0 x40, 0 x01, 0 x0000, 0 x000F, 0 x0000 },
{ 0 x40, 0 x18, 0 x0000, 0 x0003, 0 x0000 }
};
static int dtcs033_start(struct gspca_dev *gspca_dev)
{
return reg_reqs(gspca_dev, dtcs033_start_reqs,
ARRAY_SIZE(dtcs033_start_reqs));
}
static void dtcs033_stopN(struct gspca_dev *gspca_dev)
{
reg_reqs(gspca_dev, dtcs033_stop_reqs,
ARRAY_SIZE(dtcs033_stop_reqs));
return ;
}
Messung V0.5 in Prozent C=96 H=92 G=93
¤ Dauer der Verarbeitung: 0.21 Sekunden
(vorverarbeitet am 2026-06-08)
¤
*© Formatika GbR, Deutschland