Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2644880yba; Mon, 15 Apr 2019 16:41:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqxRxBlBFvMbLUBmFdjNkClzUlC3KvjyDare2AHFGZKMGj/PxQ7tK8gZee5w2OaifezrxFDX X-Received: by 2002:a17:902:e391:: with SMTP id ch17mr80216172plb.196.1555371667025; Mon, 15 Apr 2019 16:41:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555371667; cv=none; d=google.com; s=arc-20160816; b=tQ9x1vpOmPC5Qf+jwM7dhtbhcWrPTCQEHF5zGxcvCpw+k7sOpWWRBTTkhJZPsck+jL TZhclVd5Bn2uZfAA9to6Y1SWrjbIlz8rvUos5g8J2V3K4WM96sEMSowgrZ/5JIYf1RF8 kkz4EXUisu9NGnyXYe882OZEkIvdNbuIuc0NWQ4RlS56zdqRFWyE1N2U/yxibLvhXr+1 Ri3nPU3lEiWYm0WmnR5g7JA42Nj26dpK9GxJhKH5eNpvy4iEmlsdDDVo6ZqWYsQpZuxT 4N9wMhzeZeRswP67eHvmOXwXeOYYu7f81lJk2IX3nujqGxSCiMUWUF9tuvQApQZ/eFut ggrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:openpgp:from:references:cc:to:subject; bh=OlXEoaYszxIDoWX0BwpsFvTUhR/tiHFCxc89Po4GoVM=; b=Mr850kOZjHxs29TBp0HA9xbyh1hHoBsbcIQnZRl3b8365wCfzhba9JVVFxzBFCPr5v FcrqnltJaNEeOimP7CurQpUfQGxunlJNbI02IfpHUpl276YZbb/e2IzGEYwAL59CNIGi +G0omKwWKmfoN7D4epXr6dLvi08/pCg2eOZECuCSO/JjOgBePJYATLQ+6MN+TSmJ1zTq 5KArt+cJtspyRp/Uk5ePgfdJzJk9SFrQclO7OII58u+GpCk8OwNpRWnFprvo8B51rGD8 f5O3HnKEXWqXbyNCXlZIHwHXrEGM1E/ycENnAm4noLrvOKbvEHjiAbn+96wlGaDE0GDz Htsw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j64si28829003pge.398.2019.04.15.16.40.50; Mon, 15 Apr 2019 16:41:07 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728111AbfDOXkL (ORCPT + 99 others); Mon, 15 Apr 2019 19:40:11 -0400 Received: from vps-vb.mhejs.net ([37.28.154.113]:48850 "EHLO vps-vb.mhejs.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727012AbfDOXkK (ORCPT ); Mon, 15 Apr 2019 19:40:10 -0400 Received: from MUA by vps-vb.mhejs.net with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.90_1) (envelope-from ) id 1hGBCn-0006su-Mj; Tue, 16 Apr 2019 01:40:05 +0200 Subject: Re: [PATCH v9 3/4] [media] cxusb: add analog mode support for Medion MD95700 To: Hans Verkuil Cc: Michael Krufky , Mauro Carvalho Chehab , Andy Walls , linux-kernel , linux-media@vger.kernel.org References: <0c30210a0d946cac6b17755e7d255541ff535023.1553903063.git.mail@maciej.szmigiero.name> From: "Maciej S. Szmigiero" Openpgp: preference=signencrypt Autocrypt: addr=mail@maciej.szmigiero.name; prefer-encrypt=mutual; keydata= mQINBFpGusUBEAD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MtmbP/DnpQpjAlgVmDgMgYTBW1W9etU 36YW0pTqEYuv6cmRgSAKEDaYHhFLTR1+lLJkp5fFo3Sjm7XqmXzfSv9JGJGMKzoFOMBoLYv+ VFnMoLX5UJAs0JyFqFY2YxGyLd4J103NI/ocqQeU0TVvOZGVkENPSxIESnbxPghsEC0MWEbG svqA8FwvU7XfGhZPYzTRf7CndDnezEA69EhwpZXKs4CvxbXo5PDTv0OWzVaAWqq8s8aTMJWW AhvobFozJ63zafYHkuEjMo0Xps3o3uvKg7coooH521nNsv4ci+KeBq3mgMCRAy0g/Ef+Ql7m t900RCBHu4tktOhPc3J1ep/e2WAJ4ngUqJhilzyCJnzVJ4cT79VK/uPtlfUCZdUz+jTC88Tm P1p5wlucS31kThy/CV4cqDFB8yzEujTSiRzd7neG3sH0vcxBd69uvSxLZPLGID840k0v5sft PA== Message-ID: <3927f261-9052-0b89-62c2-6fe8b4876ba1@maciej.szmigiero.name> Date: Tue, 16 Apr 2019 01:40:00 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 12.04.2019 11:22, Hans Verkuil wrote: > On 3/30/19 12:51 AM, Maciej S. Szmigiero wrote: >> This patch adds support for analog part of Medion 95700 in the cxusb >> driver. >> >> What works: >> * Video capture at various sizes with sequential fields, >> * Input switching (TV Tuner, Composite, S-Video), >> * TV and radio tuning, >> * Video standard switching and auto detection, >> * Radio mode switching (stereo / mono), >> * Unplugging while capturing, >> * DVB / analog coexistence. >> >> What does not work yet: >> * Audio, >> * VBI, >> * Picture controls. >> >> Signed-off-by: Maciej S. Szmigiero >> --- (..) >> +static int cxusb_medion_try_s_fmt_vid_cap(struct file *file, >> + struct v4l2_format *f, >> + bool isset) >> +{ >> + struct dvb_usb_device *dvbdev = video_drvdata(file); >> + struct cxusb_medion_dev *cxdev = dvbdev->priv; >> + struct v4l2_subdev_format subfmt; >> + int ret; >> + >> + if (isset && (vb2_start_streaming_called(&cxdev->videoqueue) || >> + cxdev->stop_streaming)) > > This should be: > > if (isset && vb2_is_busy(&cxdev->videoqueue)) > > As long as buffers are allocated you can no longer change the format. > >> + return -EBUSY; >> + >> + memset(&subfmt, 0, sizeof(subfmt)); >> + subfmt.which = isset ? V4L2_SUBDEV_FORMAT_ACTIVE : >> + V4L2_SUBDEV_FORMAT_TRY; >> + subfmt.format.width = f->fmt.pix.width & ~1; >> + subfmt.format.height = f->fmt.pix.height & ~1; >> + subfmt.format.code = MEDIA_BUS_FMT_FIXED; >> + subfmt.format.field = V4L2_FIELD_SEQ_TB; > > Why FIELD_SEQ_TB? If memory serves the cx25840 always uses FIELD_INTERLACED. It looks like all the existing cx25840 users use an intelligent bridge chip (or a MPEG encoder), which normalize the video data received to a nice V4L2_FIELD_INTERLACED. However, this device uses a "dumb" USB bridge chip which does not do any video processing (other than dropping parts of it if the host PC is not receiving it fast enough), so the output data matches what the cx25840 chip produces - and it produces a sequential fields format. >> + subfmt.format.colorspace = V4L2_COLORSPACE_SMPTE170M; >> + >> + ret = v4l2_subdev_call(cxdev->cx25840, pad, set_fmt, NULL, &subfmt); >> + if (ret != 0) { >> + if (ret != -ERANGE) >> + return ret; >> + >> + /* try some common formats */ >> + subfmt.format.width = 720; >> + subfmt.format.height = 576; >> + ret = v4l2_subdev_call(cxdev->cx25840, pad, set_fmt, NULL, >> + &subfmt); >> + if (ret != 0) { >> + if (ret != -ERANGE) >> + return ret; >> + >> + subfmt.format.width = 640; >> + subfmt.format.height = 480; >> + ret = v4l2_subdev_call(cxdev->cx25840, pad, set_fmt, >> + NULL, &subfmt); >> + if (ret != 0) >> + return ret; >> + } > > Why these fallbacks? Is this really needed? V4L2 docs say that VIDIOC_{S,TRY}_FMT ioctls "should not return an error code unless the type field is invalid", that is, they should not return an error for invalid or unsupported image widths or heights. They should instead return something sensible for these image parameters. However, cx25840 driver set_fmt callback simply returns -ERANGE if it does not like the provided width or height. In this case the code above simply tries first the bigger PAL capture resolution then the smaller NTSC one. Which one will be accepted by the cx25840 depends on the currently set broadcast standard and parameters of the last signal that was received, at least one of these resolutions seem to work even without any signal being received since the chip was powered up. This way the API guarantees should be kept by the driver. >> +int cxusb_medion_analog_init(struct dvb_usb_device *dvbdev) >> +{ >> + struct cxusb_medion_dev *cxdev = dvbdev->priv; >> + u8 tuner_analog_msg_data[] = { 0x9c, 0x60, 0x85, 0x54 }; >> + struct i2c_msg tuner_analog_msg = { .addr = 0x61, .flags = 0, >> + .buf = tuner_analog_msg_data, >> + .len = >> + sizeof(tuner_analog_msg_data) }; >> + struct v4l2_subdev_format subfmt; >> + int ret; >> + >> + /* switch tuner to analog mode so IF demod will become accessible */ >> + ret = i2c_transfer(&dvbdev->i2c_adap, &tuner_analog_msg, 1); >> + if (ret != 1) >> + dev_warn(&dvbdev->udev->dev, >> + "tuner analog switch failed (%d)\n", ret); >> + >> + /* >> + * cx25840 might have lost power during mode switching so we need >> + * to set it again >> + */ >> + ret = v4l2_subdev_call(cxdev->cx25840, core, reset, 0); >> + if (ret != 0) >> + dev_warn(&dvbdev->udev->dev, >> + "cx25840 reset failed (%d)\n", ret); >> + >> + ret = v4l2_subdev_call(cxdev->cx25840, video, s_routing, >> + CX25840_COMPOSITE1, 0, 0); >> + if (ret != 0) >> + dev_warn(&dvbdev->udev->dev, >> + "cx25840 initial input setting failed (%d)\n", ret); >> + >> + /* composite */ >> + cxdev->input = 1; >> + cxdev->norm = 0; >> + >> + /* TODO: setup audio samples insertion */ >> + >> + ret = v4l2_subdev_call(cxdev->cx25840, core, s_io_pin_config, >> + sizeof(cxusub_medion_pin_config) / >> + sizeof(cxusub_medion_pin_config[0]), >> + cxusub_medion_pin_config); >> + if (ret != 0) >> + dev_warn(&dvbdev->udev->dev, >> + "cx25840 pin config failed (%d)\n", ret); >> + >> + /* make sure that we aren't in radio mode */ >> + v4l2_subdev_call(cxdev->tda9887, video, s_std, V4L2_STD_PAL); >> + v4l2_subdev_call(cxdev->tuner, video, s_std, V4L2_STD_PAL); >> + v4l2_subdev_call(cxdev->cx25840, video, s_std, cxdev->norm); >> + >> + memset(&subfmt, 0, sizeof(subfmt)); >> + subfmt.which = V4L2_SUBDEV_FORMAT_ACTIVE; >> + subfmt.format.width = cxdev->width; >> + subfmt.format.height = cxdev->height; >> + subfmt.format.code = MEDIA_BUS_FMT_FIXED; >> + subfmt.format.field = V4L2_FIELD_SEQ_TB; >> + subfmt.format.colorspace = V4L2_COLORSPACE_SMPTE170M; >> + >> + ret = v4l2_subdev_call(cxdev->cx25840, pad, set_fmt, NULL, &subfmt); >> + if (ret != 0) { >> + subfmt.format.width = 640; >> + subfmt.format.height = 480; > > Why the fallback to 640x480? This resolution seems to work even without any signal being received, and it is a sensible NTSC-like resolution so it makes a good fallback if restoring the previously used resolution has failed. >> + ret = v4l2_subdev_call(cxdev->cx25840, pad, set_fmt, NULL, >> + &subfmt); >> + if (ret != 0) >> + dev_warn(&dvbdev->udev->dev, >> + "cx25840 format set failed (%d)\n", ret); >> + } >> + >> + if (ret == 0) { >> + cxdev->width = subfmt.format.width; >> + cxdev->height = subfmt.format.height; >> + } >> + >> + return 0; >> +} >> + > > Regards, > > Hans > Thanks and best regards, Maciej