18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Mars-Semi MR97311A library 48c2ecf20Sopenharmony_ci * Copyright (C) 2005 <bradlch@hotmail.com> 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * V4L2 by Jean-Francois Moine <http://moinejf.free.fr> 78c2ecf20Sopenharmony_ci */ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#define MODULE_NAME "mars" 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#include "gspca.h" 148c2ecf20Sopenharmony_ci#include "jpeg.h" 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ciMODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>"); 178c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("GSPCA/Mars USB Camera Driver"); 188c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci#define QUALITY 50 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci/* specific webcam descriptor */ 238c2ecf20Sopenharmony_cistruct sd { 248c2ecf20Sopenharmony_ci struct gspca_dev gspca_dev; /* !! must be the first item */ 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci struct v4l2_ctrl *brightness; 278c2ecf20Sopenharmony_ci struct v4l2_ctrl *saturation; 288c2ecf20Sopenharmony_ci struct v4l2_ctrl *sharpness; 298c2ecf20Sopenharmony_ci struct v4l2_ctrl *gamma; 308c2ecf20Sopenharmony_ci struct { /* illuminator control cluster */ 318c2ecf20Sopenharmony_ci struct v4l2_ctrl *illum_top; 328c2ecf20Sopenharmony_ci struct v4l2_ctrl *illum_bottom; 338c2ecf20Sopenharmony_ci }; 348c2ecf20Sopenharmony_ci u8 jpeg_hdr[JPEG_HDR_SZ]; 358c2ecf20Sopenharmony_ci}; 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci/* V4L2 controls supported by the driver */ 388c2ecf20Sopenharmony_cistatic void setbrightness(struct gspca_dev *gspca_dev, s32 val); 398c2ecf20Sopenharmony_cistatic void setcolors(struct gspca_dev *gspca_dev, s32 val); 408c2ecf20Sopenharmony_cistatic void setgamma(struct gspca_dev *gspca_dev, s32 val); 418c2ecf20Sopenharmony_cistatic void setsharpness(struct gspca_dev *gspca_dev, s32 val); 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_cistatic const struct v4l2_pix_format vga_mode[] = { 448c2ecf20Sopenharmony_ci {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, 458c2ecf20Sopenharmony_ci .bytesperline = 320, 468c2ecf20Sopenharmony_ci .sizeimage = 320 * 240 * 3 / 8 + 590, 478c2ecf20Sopenharmony_ci .colorspace = V4L2_COLORSPACE_JPEG, 488c2ecf20Sopenharmony_ci .priv = 2}, 498c2ecf20Sopenharmony_ci {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, 508c2ecf20Sopenharmony_ci .bytesperline = 640, 518c2ecf20Sopenharmony_ci .sizeimage = 640 * 480 * 3 / 8 + 590, 528c2ecf20Sopenharmony_ci .colorspace = V4L2_COLORSPACE_JPEG, 538c2ecf20Sopenharmony_ci .priv = 1}, 548c2ecf20Sopenharmony_ci}; 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_cistatic const __u8 mi_data[0x20] = { 578c2ecf20Sopenharmony_ci/* 01 02 03 04 05 06 07 08 */ 588c2ecf20Sopenharmony_ci 0x48, 0x22, 0x01, 0x47, 0x10, 0x00, 0x00, 0x00, 598c2ecf20Sopenharmony_ci/* 09 0a 0b 0c 0d 0e 0f 10 */ 608c2ecf20Sopenharmony_ci 0x00, 0x01, 0x30, 0x01, 0x30, 0x01, 0x30, 0x01, 618c2ecf20Sopenharmony_ci/* 11 12 13 14 15 16 17 18 */ 628c2ecf20Sopenharmony_ci 0x30, 0x00, 0x04, 0x00, 0x06, 0x01, 0xe2, 0x02, 638c2ecf20Sopenharmony_ci/* 19 1a 1b 1c 1d 1e 1f 20 */ 648c2ecf20Sopenharmony_ci 0x82, 0x00, 0x20, 0x17, 0x80, 0x08, 0x0c, 0x00 658c2ecf20Sopenharmony_ci}; 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci/* write <len> bytes from gspca_dev->usb_buf */ 688c2ecf20Sopenharmony_cistatic void reg_w(struct gspca_dev *gspca_dev, 698c2ecf20Sopenharmony_ci int len) 708c2ecf20Sopenharmony_ci{ 718c2ecf20Sopenharmony_ci int alen, ret; 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci if (gspca_dev->usb_err < 0) 748c2ecf20Sopenharmony_ci return; 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci ret = usb_bulk_msg(gspca_dev->dev, 778c2ecf20Sopenharmony_ci usb_sndbulkpipe(gspca_dev->dev, 4), 788c2ecf20Sopenharmony_ci gspca_dev->usb_buf, 798c2ecf20Sopenharmony_ci len, 808c2ecf20Sopenharmony_ci &alen, 818c2ecf20Sopenharmony_ci 500); /* timeout in milliseconds */ 828c2ecf20Sopenharmony_ci if (ret < 0) { 838c2ecf20Sopenharmony_ci pr_err("reg write [%02x] error %d\n", 848c2ecf20Sopenharmony_ci gspca_dev->usb_buf[0], ret); 858c2ecf20Sopenharmony_ci gspca_dev->usb_err = ret; 868c2ecf20Sopenharmony_ci } 878c2ecf20Sopenharmony_ci} 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_cistatic void mi_w(struct gspca_dev *gspca_dev, 908c2ecf20Sopenharmony_ci u8 addr, 918c2ecf20Sopenharmony_ci u8 value) 928c2ecf20Sopenharmony_ci{ 938c2ecf20Sopenharmony_ci gspca_dev->usb_buf[0] = 0x1f; 948c2ecf20Sopenharmony_ci gspca_dev->usb_buf[1] = 0; /* control byte */ 958c2ecf20Sopenharmony_ci gspca_dev->usb_buf[2] = addr; 968c2ecf20Sopenharmony_ci gspca_dev->usb_buf[3] = value; 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci reg_w(gspca_dev, 4); 998c2ecf20Sopenharmony_ci} 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_cistatic void setbrightness(struct gspca_dev *gspca_dev, s32 val) 1028c2ecf20Sopenharmony_ci{ 1038c2ecf20Sopenharmony_ci gspca_dev->usb_buf[0] = 0x61; 1048c2ecf20Sopenharmony_ci gspca_dev->usb_buf[1] = val; 1058c2ecf20Sopenharmony_ci reg_w(gspca_dev, 2); 1068c2ecf20Sopenharmony_ci} 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_cistatic void setcolors(struct gspca_dev *gspca_dev, s32 val) 1098c2ecf20Sopenharmony_ci{ 1108c2ecf20Sopenharmony_ci gspca_dev->usb_buf[0] = 0x5f; 1118c2ecf20Sopenharmony_ci gspca_dev->usb_buf[1] = val << 3; 1128c2ecf20Sopenharmony_ci gspca_dev->usb_buf[2] = ((val >> 2) & 0xf8) | 0x04; 1138c2ecf20Sopenharmony_ci reg_w(gspca_dev, 3); 1148c2ecf20Sopenharmony_ci} 1158c2ecf20Sopenharmony_ci 1168c2ecf20Sopenharmony_cistatic void setgamma(struct gspca_dev *gspca_dev, s32 val) 1178c2ecf20Sopenharmony_ci{ 1188c2ecf20Sopenharmony_ci gspca_dev->usb_buf[0] = 0x06; 1198c2ecf20Sopenharmony_ci gspca_dev->usb_buf[1] = val * 0x40; 1208c2ecf20Sopenharmony_ci reg_w(gspca_dev, 2); 1218c2ecf20Sopenharmony_ci} 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_cistatic void setsharpness(struct gspca_dev *gspca_dev, s32 val) 1248c2ecf20Sopenharmony_ci{ 1258c2ecf20Sopenharmony_ci gspca_dev->usb_buf[0] = 0x67; 1268c2ecf20Sopenharmony_ci gspca_dev->usb_buf[1] = val * 4 + 3; 1278c2ecf20Sopenharmony_ci reg_w(gspca_dev, 2); 1288c2ecf20Sopenharmony_ci} 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_cistatic void setilluminators(struct gspca_dev *gspca_dev, bool top, bool bottom) 1318c2ecf20Sopenharmony_ci{ 1328c2ecf20Sopenharmony_ci /* both are off if not streaming */ 1338c2ecf20Sopenharmony_ci gspca_dev->usb_buf[0] = 0x22; 1348c2ecf20Sopenharmony_ci if (top) 1358c2ecf20Sopenharmony_ci gspca_dev->usb_buf[1] = 0x76; 1368c2ecf20Sopenharmony_ci else if (bottom) 1378c2ecf20Sopenharmony_ci gspca_dev->usb_buf[1] = 0x7a; 1388c2ecf20Sopenharmony_ci else 1398c2ecf20Sopenharmony_ci gspca_dev->usb_buf[1] = 0x7e; 1408c2ecf20Sopenharmony_ci reg_w(gspca_dev, 2); 1418c2ecf20Sopenharmony_ci} 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_cistatic int mars_s_ctrl(struct v4l2_ctrl *ctrl) 1448c2ecf20Sopenharmony_ci{ 1458c2ecf20Sopenharmony_ci struct gspca_dev *gspca_dev = 1468c2ecf20Sopenharmony_ci container_of(ctrl->handler, struct gspca_dev, ctrl_handler); 1478c2ecf20Sopenharmony_ci struct sd *sd = (struct sd *)gspca_dev; 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_ci gspca_dev->usb_err = 0; 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_ci if (ctrl->id == V4L2_CID_ILLUMINATORS_1) { 1528c2ecf20Sopenharmony_ci /* only one can be on at a time */ 1538c2ecf20Sopenharmony_ci if (ctrl->is_new && ctrl->val) 1548c2ecf20Sopenharmony_ci sd->illum_bottom->val = 0; 1558c2ecf20Sopenharmony_ci if (sd->illum_bottom->is_new && sd->illum_bottom->val) 1568c2ecf20Sopenharmony_ci sd->illum_top->val = 0; 1578c2ecf20Sopenharmony_ci } 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ci if (!gspca_dev->streaming) 1608c2ecf20Sopenharmony_ci return 0; 1618c2ecf20Sopenharmony_ci 1628c2ecf20Sopenharmony_ci switch (ctrl->id) { 1638c2ecf20Sopenharmony_ci case V4L2_CID_BRIGHTNESS: 1648c2ecf20Sopenharmony_ci setbrightness(gspca_dev, ctrl->val); 1658c2ecf20Sopenharmony_ci break; 1668c2ecf20Sopenharmony_ci case V4L2_CID_SATURATION: 1678c2ecf20Sopenharmony_ci setcolors(gspca_dev, ctrl->val); 1688c2ecf20Sopenharmony_ci break; 1698c2ecf20Sopenharmony_ci case V4L2_CID_GAMMA: 1708c2ecf20Sopenharmony_ci setgamma(gspca_dev, ctrl->val); 1718c2ecf20Sopenharmony_ci break; 1728c2ecf20Sopenharmony_ci case V4L2_CID_ILLUMINATORS_1: 1738c2ecf20Sopenharmony_ci setilluminators(gspca_dev, sd->illum_top->val, 1748c2ecf20Sopenharmony_ci sd->illum_bottom->val); 1758c2ecf20Sopenharmony_ci break; 1768c2ecf20Sopenharmony_ci case V4L2_CID_SHARPNESS: 1778c2ecf20Sopenharmony_ci setsharpness(gspca_dev, ctrl->val); 1788c2ecf20Sopenharmony_ci break; 1798c2ecf20Sopenharmony_ci default: 1808c2ecf20Sopenharmony_ci return -EINVAL; 1818c2ecf20Sopenharmony_ci } 1828c2ecf20Sopenharmony_ci return gspca_dev->usb_err; 1838c2ecf20Sopenharmony_ci} 1848c2ecf20Sopenharmony_ci 1858c2ecf20Sopenharmony_cistatic const struct v4l2_ctrl_ops mars_ctrl_ops = { 1868c2ecf20Sopenharmony_ci .s_ctrl = mars_s_ctrl, 1878c2ecf20Sopenharmony_ci}; 1888c2ecf20Sopenharmony_ci 1898c2ecf20Sopenharmony_ci/* this function is called at probe time */ 1908c2ecf20Sopenharmony_cistatic int sd_init_controls(struct gspca_dev *gspca_dev) 1918c2ecf20Sopenharmony_ci{ 1928c2ecf20Sopenharmony_ci struct sd *sd = (struct sd *) gspca_dev; 1938c2ecf20Sopenharmony_ci struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler; 1948c2ecf20Sopenharmony_ci 1958c2ecf20Sopenharmony_ci gspca_dev->vdev.ctrl_handler = hdl; 1968c2ecf20Sopenharmony_ci v4l2_ctrl_handler_init(hdl, 6); 1978c2ecf20Sopenharmony_ci sd->brightness = v4l2_ctrl_new_std(hdl, &mars_ctrl_ops, 1988c2ecf20Sopenharmony_ci V4L2_CID_BRIGHTNESS, 0, 30, 1, 15); 1998c2ecf20Sopenharmony_ci sd->saturation = v4l2_ctrl_new_std(hdl, &mars_ctrl_ops, 2008c2ecf20Sopenharmony_ci V4L2_CID_SATURATION, 0, 255, 1, 200); 2018c2ecf20Sopenharmony_ci sd->gamma = v4l2_ctrl_new_std(hdl, &mars_ctrl_ops, 2028c2ecf20Sopenharmony_ci V4L2_CID_GAMMA, 0, 3, 1, 1); 2038c2ecf20Sopenharmony_ci sd->sharpness = v4l2_ctrl_new_std(hdl, &mars_ctrl_ops, 2048c2ecf20Sopenharmony_ci V4L2_CID_SHARPNESS, 0, 2, 1, 1); 2058c2ecf20Sopenharmony_ci sd->illum_top = v4l2_ctrl_new_std(hdl, &mars_ctrl_ops, 2068c2ecf20Sopenharmony_ci V4L2_CID_ILLUMINATORS_1, 0, 1, 1, 0); 2078c2ecf20Sopenharmony_ci sd->illum_top->flags |= V4L2_CTRL_FLAG_UPDATE; 2088c2ecf20Sopenharmony_ci sd->illum_bottom = v4l2_ctrl_new_std(hdl, &mars_ctrl_ops, 2098c2ecf20Sopenharmony_ci V4L2_CID_ILLUMINATORS_2, 0, 1, 1, 0); 2108c2ecf20Sopenharmony_ci sd->illum_bottom->flags |= V4L2_CTRL_FLAG_UPDATE; 2118c2ecf20Sopenharmony_ci if (hdl->error) { 2128c2ecf20Sopenharmony_ci pr_err("Could not initialize controls\n"); 2138c2ecf20Sopenharmony_ci return hdl->error; 2148c2ecf20Sopenharmony_ci } 2158c2ecf20Sopenharmony_ci v4l2_ctrl_cluster(2, &sd->illum_top); 2168c2ecf20Sopenharmony_ci return 0; 2178c2ecf20Sopenharmony_ci} 2188c2ecf20Sopenharmony_ci 2198c2ecf20Sopenharmony_ci/* this function is called at probe time */ 2208c2ecf20Sopenharmony_cistatic int sd_config(struct gspca_dev *gspca_dev, 2218c2ecf20Sopenharmony_ci const struct usb_device_id *id) 2228c2ecf20Sopenharmony_ci{ 2238c2ecf20Sopenharmony_ci struct cam *cam; 2248c2ecf20Sopenharmony_ci 2258c2ecf20Sopenharmony_ci cam = &gspca_dev->cam; 2268c2ecf20Sopenharmony_ci cam->cam_mode = vga_mode; 2278c2ecf20Sopenharmony_ci cam->nmodes = ARRAY_SIZE(vga_mode); 2288c2ecf20Sopenharmony_ci return 0; 2298c2ecf20Sopenharmony_ci} 2308c2ecf20Sopenharmony_ci 2318c2ecf20Sopenharmony_ci/* this function is called at probe and resume time */ 2328c2ecf20Sopenharmony_cistatic int sd_init(struct gspca_dev *gspca_dev) 2338c2ecf20Sopenharmony_ci{ 2348c2ecf20Sopenharmony_ci return 0; 2358c2ecf20Sopenharmony_ci} 2368c2ecf20Sopenharmony_ci 2378c2ecf20Sopenharmony_cistatic int sd_start(struct gspca_dev *gspca_dev) 2388c2ecf20Sopenharmony_ci{ 2398c2ecf20Sopenharmony_ci struct sd *sd = (struct sd *) gspca_dev; 2408c2ecf20Sopenharmony_ci u8 *data; 2418c2ecf20Sopenharmony_ci int i; 2428c2ecf20Sopenharmony_ci 2438c2ecf20Sopenharmony_ci /* create the JPEG header */ 2448c2ecf20Sopenharmony_ci jpeg_define(sd->jpeg_hdr, gspca_dev->pixfmt.height, 2458c2ecf20Sopenharmony_ci gspca_dev->pixfmt.width, 2468c2ecf20Sopenharmony_ci 0x21); /* JPEG 422 */ 2478c2ecf20Sopenharmony_ci jpeg_set_qual(sd->jpeg_hdr, QUALITY); 2488c2ecf20Sopenharmony_ci 2498c2ecf20Sopenharmony_ci data = gspca_dev->usb_buf; 2508c2ecf20Sopenharmony_ci 2518c2ecf20Sopenharmony_ci data[0] = 0x01; /* address */ 2528c2ecf20Sopenharmony_ci data[1] = 0x01; 2538c2ecf20Sopenharmony_ci reg_w(gspca_dev, 2); 2548c2ecf20Sopenharmony_ci 2558c2ecf20Sopenharmony_ci /* 2568c2ecf20Sopenharmony_ci Initialize the MR97113 chip register 2578c2ecf20Sopenharmony_ci */ 2588c2ecf20Sopenharmony_ci data[0] = 0x00; /* address */ 2598c2ecf20Sopenharmony_ci data[1] = 0x0c | 0x01; /* reg 0 */ 2608c2ecf20Sopenharmony_ci data[2] = 0x01; /* reg 1 */ 2618c2ecf20Sopenharmony_ci data[3] = gspca_dev->pixfmt.width / 8; /* h_size , reg 2 */ 2628c2ecf20Sopenharmony_ci data[4] = gspca_dev->pixfmt.height / 8; /* v_size , reg 3 */ 2638c2ecf20Sopenharmony_ci data[5] = 0x30; /* reg 4, MI, PAS5101 : 2648c2ecf20Sopenharmony_ci * 0x30 for 24mhz , 0x28 for 12mhz */ 2658c2ecf20Sopenharmony_ci data[6] = 0x02; /* reg 5, H start - was 0x04 */ 2668c2ecf20Sopenharmony_ci data[7] = v4l2_ctrl_g_ctrl(sd->gamma) * 0x40; /* reg 0x06: gamma */ 2678c2ecf20Sopenharmony_ci data[8] = 0x01; /* reg 7, V start - was 0x03 */ 2688c2ecf20Sopenharmony_ci/* if (h_size == 320 ) */ 2698c2ecf20Sopenharmony_ci/* data[9]= 0x56; * reg 8, 24MHz, 2:1 scale down */ 2708c2ecf20Sopenharmony_ci/* else */ 2718c2ecf20Sopenharmony_ci data[9] = 0x52; /* reg 8, 24MHz, no scale down */ 2728c2ecf20Sopenharmony_ci/*jfm: from win trace*/ 2738c2ecf20Sopenharmony_ci data[10] = 0x18; 2748c2ecf20Sopenharmony_ci 2758c2ecf20Sopenharmony_ci reg_w(gspca_dev, 11); 2768c2ecf20Sopenharmony_ci 2778c2ecf20Sopenharmony_ci data[0] = 0x23; /* address */ 2788c2ecf20Sopenharmony_ci data[1] = 0x09; /* reg 35, append frame header */ 2798c2ecf20Sopenharmony_ci 2808c2ecf20Sopenharmony_ci reg_w(gspca_dev, 2); 2818c2ecf20Sopenharmony_ci 2828c2ecf20Sopenharmony_ci data[0] = 0x3c; /* address */ 2838c2ecf20Sopenharmony_ci/* if (gspca_dev->width == 1280) */ 2848c2ecf20Sopenharmony_ci/* data[1] = 200; * reg 60, pc-cam frame size 2858c2ecf20Sopenharmony_ci * (unit: 4KB) 800KB */ 2868c2ecf20Sopenharmony_ci/* else */ 2878c2ecf20Sopenharmony_ci data[1] = 50; /* 50 reg 60, pc-cam frame size 2888c2ecf20Sopenharmony_ci * (unit: 4KB) 200KB */ 2898c2ecf20Sopenharmony_ci reg_w(gspca_dev, 2); 2908c2ecf20Sopenharmony_ci 2918c2ecf20Sopenharmony_ci /* auto dark-gain */ 2928c2ecf20Sopenharmony_ci data[0] = 0x5e; /* address */ 2938c2ecf20Sopenharmony_ci data[1] = 0; /* reg 94, Y Gain (auto) */ 2948c2ecf20Sopenharmony_ci/*jfm: from win trace*/ 2958c2ecf20Sopenharmony_ci /* reg 0x5f/0x60 (LE) = saturation */ 2968c2ecf20Sopenharmony_ci /* h (60): xxxx x100 2978c2ecf20Sopenharmony_ci * l (5f): xxxx x000 */ 2988c2ecf20Sopenharmony_ci data[2] = v4l2_ctrl_g_ctrl(sd->saturation) << 3; 2998c2ecf20Sopenharmony_ci data[3] = ((v4l2_ctrl_g_ctrl(sd->saturation) >> 2) & 0xf8) | 0x04; 3008c2ecf20Sopenharmony_ci data[4] = v4l2_ctrl_g_ctrl(sd->brightness); /* reg 0x61 = brightness */ 3018c2ecf20Sopenharmony_ci data[5] = 0x00; 3028c2ecf20Sopenharmony_ci 3038c2ecf20Sopenharmony_ci reg_w(gspca_dev, 6); 3048c2ecf20Sopenharmony_ci 3058c2ecf20Sopenharmony_ci data[0] = 0x67; 3068c2ecf20Sopenharmony_ci/*jfm: from win trace*/ 3078c2ecf20Sopenharmony_ci data[1] = v4l2_ctrl_g_ctrl(sd->sharpness) * 4 + 3; 3088c2ecf20Sopenharmony_ci data[2] = 0x14; 3098c2ecf20Sopenharmony_ci reg_w(gspca_dev, 3); 3108c2ecf20Sopenharmony_ci 3118c2ecf20Sopenharmony_ci data[0] = 0x69; 3128c2ecf20Sopenharmony_ci data[1] = 0x2f; 3138c2ecf20Sopenharmony_ci data[2] = 0x28; 3148c2ecf20Sopenharmony_ci data[3] = 0x42; 3158c2ecf20Sopenharmony_ci reg_w(gspca_dev, 4); 3168c2ecf20Sopenharmony_ci 3178c2ecf20Sopenharmony_ci data[0] = 0x63; 3188c2ecf20Sopenharmony_ci data[1] = 0x07; 3198c2ecf20Sopenharmony_ci reg_w(gspca_dev, 2); 3208c2ecf20Sopenharmony_ci/*jfm: win trace - many writes here to reg 0x64*/ 3218c2ecf20Sopenharmony_ci 3228c2ecf20Sopenharmony_ci /* initialize the MI sensor */ 3238c2ecf20Sopenharmony_ci for (i = 0; i < sizeof mi_data; i++) 3248c2ecf20Sopenharmony_ci mi_w(gspca_dev, i + 1, mi_data[i]); 3258c2ecf20Sopenharmony_ci 3268c2ecf20Sopenharmony_ci data[0] = 0x00; 3278c2ecf20Sopenharmony_ci data[1] = 0x4d; /* ISOC transferring enable... */ 3288c2ecf20Sopenharmony_ci reg_w(gspca_dev, 2); 3298c2ecf20Sopenharmony_ci 3308c2ecf20Sopenharmony_ci setilluminators(gspca_dev, v4l2_ctrl_g_ctrl(sd->illum_top), 3318c2ecf20Sopenharmony_ci v4l2_ctrl_g_ctrl(sd->illum_bottom)); 3328c2ecf20Sopenharmony_ci 3338c2ecf20Sopenharmony_ci return gspca_dev->usb_err; 3348c2ecf20Sopenharmony_ci} 3358c2ecf20Sopenharmony_ci 3368c2ecf20Sopenharmony_cistatic void sd_stopN(struct gspca_dev *gspca_dev) 3378c2ecf20Sopenharmony_ci{ 3388c2ecf20Sopenharmony_ci struct sd *sd = (struct sd *) gspca_dev; 3398c2ecf20Sopenharmony_ci 3408c2ecf20Sopenharmony_ci if (v4l2_ctrl_g_ctrl(sd->illum_top) || 3418c2ecf20Sopenharmony_ci v4l2_ctrl_g_ctrl(sd->illum_bottom)) { 3428c2ecf20Sopenharmony_ci setilluminators(gspca_dev, false, false); 3438c2ecf20Sopenharmony_ci msleep(20); 3448c2ecf20Sopenharmony_ci } 3458c2ecf20Sopenharmony_ci 3468c2ecf20Sopenharmony_ci gspca_dev->usb_buf[0] = 1; 3478c2ecf20Sopenharmony_ci gspca_dev->usb_buf[1] = 0; 3488c2ecf20Sopenharmony_ci reg_w(gspca_dev, 2); 3498c2ecf20Sopenharmony_ci} 3508c2ecf20Sopenharmony_ci 3518c2ecf20Sopenharmony_cistatic void sd_pkt_scan(struct gspca_dev *gspca_dev, 3528c2ecf20Sopenharmony_ci u8 *data, /* isoc packet */ 3538c2ecf20Sopenharmony_ci int len) /* iso packet length */ 3548c2ecf20Sopenharmony_ci{ 3558c2ecf20Sopenharmony_ci struct sd *sd = (struct sd *) gspca_dev; 3568c2ecf20Sopenharmony_ci int p; 3578c2ecf20Sopenharmony_ci 3588c2ecf20Sopenharmony_ci if (len < 6) { 3598c2ecf20Sopenharmony_ci/* gspca_dev->last_packet_type = DISCARD_PACKET; */ 3608c2ecf20Sopenharmony_ci return; 3618c2ecf20Sopenharmony_ci } 3628c2ecf20Sopenharmony_ci for (p = 0; p < len - 6; p++) { 3638c2ecf20Sopenharmony_ci if (data[0 + p] == 0xff 3648c2ecf20Sopenharmony_ci && data[1 + p] == 0xff 3658c2ecf20Sopenharmony_ci && data[2 + p] == 0x00 3668c2ecf20Sopenharmony_ci && data[3 + p] == 0xff 3678c2ecf20Sopenharmony_ci && data[4 + p] == 0x96) { 3688c2ecf20Sopenharmony_ci if (data[5 + p] == 0x64 3698c2ecf20Sopenharmony_ci || data[5 + p] == 0x65 3708c2ecf20Sopenharmony_ci || data[5 + p] == 0x66 3718c2ecf20Sopenharmony_ci || data[5 + p] == 0x67) { 3728c2ecf20Sopenharmony_ci gspca_dbg(gspca_dev, D_PACK, "sof offset: %d len: %d\n", 3738c2ecf20Sopenharmony_ci p, len); 3748c2ecf20Sopenharmony_ci gspca_frame_add(gspca_dev, LAST_PACKET, 3758c2ecf20Sopenharmony_ci data, p); 3768c2ecf20Sopenharmony_ci 3778c2ecf20Sopenharmony_ci /* put the JPEG header */ 3788c2ecf20Sopenharmony_ci gspca_frame_add(gspca_dev, FIRST_PACKET, 3798c2ecf20Sopenharmony_ci sd->jpeg_hdr, JPEG_HDR_SZ); 3808c2ecf20Sopenharmony_ci data += p + 16; 3818c2ecf20Sopenharmony_ci len -= p + 16; 3828c2ecf20Sopenharmony_ci break; 3838c2ecf20Sopenharmony_ci } 3848c2ecf20Sopenharmony_ci } 3858c2ecf20Sopenharmony_ci } 3868c2ecf20Sopenharmony_ci gspca_frame_add(gspca_dev, INTER_PACKET, data, len); 3878c2ecf20Sopenharmony_ci} 3888c2ecf20Sopenharmony_ci 3898c2ecf20Sopenharmony_ci/* sub-driver description */ 3908c2ecf20Sopenharmony_cistatic const struct sd_desc sd_desc = { 3918c2ecf20Sopenharmony_ci .name = MODULE_NAME, 3928c2ecf20Sopenharmony_ci .config = sd_config, 3938c2ecf20Sopenharmony_ci .init = sd_init, 3948c2ecf20Sopenharmony_ci .init_controls = sd_init_controls, 3958c2ecf20Sopenharmony_ci .start = sd_start, 3968c2ecf20Sopenharmony_ci .stopN = sd_stopN, 3978c2ecf20Sopenharmony_ci .pkt_scan = sd_pkt_scan, 3988c2ecf20Sopenharmony_ci}; 3998c2ecf20Sopenharmony_ci 4008c2ecf20Sopenharmony_ci/* -- module initialisation -- */ 4018c2ecf20Sopenharmony_cistatic const struct usb_device_id device_table[] = { 4028c2ecf20Sopenharmony_ci {USB_DEVICE(0x093a, 0x050f)}, 4038c2ecf20Sopenharmony_ci {} 4048c2ecf20Sopenharmony_ci}; 4058c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(usb, device_table); 4068c2ecf20Sopenharmony_ci 4078c2ecf20Sopenharmony_ci/* -- device connect -- */ 4088c2ecf20Sopenharmony_cistatic int sd_probe(struct usb_interface *intf, 4098c2ecf20Sopenharmony_ci const struct usb_device_id *id) 4108c2ecf20Sopenharmony_ci{ 4118c2ecf20Sopenharmony_ci return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd), 4128c2ecf20Sopenharmony_ci THIS_MODULE); 4138c2ecf20Sopenharmony_ci} 4148c2ecf20Sopenharmony_ci 4158c2ecf20Sopenharmony_cistatic struct usb_driver sd_driver = { 4168c2ecf20Sopenharmony_ci .name = MODULE_NAME, 4178c2ecf20Sopenharmony_ci .id_table = device_table, 4188c2ecf20Sopenharmony_ci .probe = sd_probe, 4198c2ecf20Sopenharmony_ci .disconnect = gspca_disconnect, 4208c2ecf20Sopenharmony_ci#ifdef CONFIG_PM 4218c2ecf20Sopenharmony_ci .suspend = gspca_suspend, 4228c2ecf20Sopenharmony_ci .resume = gspca_resume, 4238c2ecf20Sopenharmony_ci .reset_resume = gspca_resume, 4248c2ecf20Sopenharmony_ci#endif 4258c2ecf20Sopenharmony_ci}; 4268c2ecf20Sopenharmony_ci 4278c2ecf20Sopenharmony_cimodule_usb_driver(sd_driver); 428