Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2183364rdb; Thu, 21 Sep 2023 10:46:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHgB/NMYwo+VDKbJ8u67/2e46sOeGW9Bb+ulQKthQgVwsLrJ9ngHXqQNEOmFwTTGNsVw1E9 X-Received: by 2002:a05:6a20:3c9f:b0:15d:a69e:2503 with SMTP id b31-20020a056a203c9f00b0015da69e2503mr136181pzj.5.1695318395112; Thu, 21 Sep 2023 10:46:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695318395; cv=none; d=google.com; s=arc-20160816; b=nfBpmm1OLkPVMVp14deYl0gO1WvCT1aoRTBqwqb9zoUEg6O4cV7Jd02cNdmfu9yBTB yhwaR2alN/bILVtcwRQn6+Ig/w3IEd8FR1cltbhTnJXjDC90OC3HIoXaa2veMu5BiMMM 8GXxxpJhX7CHhFtXjrTGXQ7XZoSvajz/19HFZabU9RD7OuHL/TgoCqehcPCHLJusL1m7 WerTOmgGoblbBoAHAKdv7zDk6Yy6bqgWFGX0iBxPQEdg5ShhFa8n1E0NI38hHxtg4uQb hAm4YjbCunlgXX7UZXsJ1NuFF2SKShldDp+eShAeUVuFbZVZMWRLET6Dm7v/lEVyw6eA fBIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=QJGZKycqeO81h0an4yJH5UKT1PuWznR4HKhQVLdz6c0=; fh=ejZKMPXw/wpgIkBgg4R8fhS2jsJTspCs9srLwjcCwrU=; b=eikwOrpwq9vgysmhypJIHBPNJRtQDE49dY53fdq0M/b6QU8UPAHupZSCtsHz2ispN8 MV0VWxFBpABy7GISYK6vCPV9WjfgQ4pmozqKU+x0H9rOltezKpTKC35wxy4pVyIMWdRG yjKHE702r/aQO3c9SmFknp0qfHFRJo4QoLgsrMc1gVB/YYBNXIlrrtPkkHYD4ELnBWLM 8WVZlKnG1eGLv17+dWKPpHbqqV7nnyRo5dVgF7zv4XlhjasQhmEf52IW8djXyAo81ruE bu0fM/6tKFFfN3EuQgMFCeLxsAi+L3NAKRqluvD5BLg/W0x5LJBM0StjYvBS06Dy7UDn g+zw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xs4all.nl Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id 63-20020a630142000000b005775a4a2961si1870441pgb.657.2023.09.21.10.46.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 10:46:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xs4all.nl Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 4916280E6589; Thu, 21 Sep 2023 10:12:07 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229545AbjIURL7 (ORCPT + 99 others); Thu, 21 Sep 2023 13:11:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230288AbjIURFF (ORCPT ); Thu, 21 Sep 2023 13:05:05 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3DE2CE2; Thu, 21 Sep 2023 10:04:38 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ADC25C433BA; Thu, 21 Sep 2023 07:28:45 +0000 (UTC) Message-ID: <84ecbf4e-79eb-4ab4-851d-cdd998201534@xs4all.nl> Date: Thu, 21 Sep 2023 09:28:44 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v10 1/2] Added Digiteq Automotive MGB4 driver Content-Language: en-US, nl To: tumic@gpxsee.org, Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, =?UTF-8?Q?Martin_T=C5=AFma?= References: <20230919165923.2509-1-tumic@gpxsee.org> <20230919165923.2509-2-tumic@gpxsee.org> From: Hans Verkuil In-Reply-To: <20230919165923.2509-2-tumic@gpxsee.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 21 Sep 2023 10:12:07 -0700 (PDT) On 19/09/2023 18:59, tumic@gpxsee.org wrote: > From: Martin Tůma > > Digiteq Automotive MGB4 is a modular frame grabber PCIe card for automotive > video interfaces. As for now, two modules - FPD-Link and GMSL - are > available and supported by the driver. The card has two inputs and two > outputs (FPD-Link only). > > In addition to the video interfaces it also provides a trigger signal > interface and a MTD interface for FPGA firmware upload. > > Signed-off-by: Martin Tůma > --- > MAINTAINERS | 7 + > drivers/media/pci/Kconfig | 1 + > drivers/media/pci/Makefile | 1 + > drivers/media/pci/mgb4/Kconfig | 17 + > drivers/media/pci/mgb4/Makefile | 6 + > drivers/media/pci/mgb4/mgb4_cmt.c | 244 +++++++ > drivers/media/pci/mgb4/mgb4_cmt.h | 17 + > drivers/media/pci/mgb4/mgb4_core.c | 686 +++++++++++++++++ > drivers/media/pci/mgb4/mgb4_core.h | 74 ++ > drivers/media/pci/mgb4/mgb4_dma.c | 123 ++++ > drivers/media/pci/mgb4/mgb4_dma.h | 18 + > drivers/media/pci/mgb4/mgb4_i2c.c | 140 ++++ > drivers/media/pci/mgb4/mgb4_i2c.h | 35 + > drivers/media/pci/mgb4/mgb4_io.h | 33 + > drivers/media/pci/mgb4/mgb4_regs.c | 30 + > drivers/media/pci/mgb4/mgb4_regs.h | 35 + > drivers/media/pci/mgb4/mgb4_sysfs.h | 18 + > drivers/media/pci/mgb4/mgb4_sysfs_in.c | 744 +++++++++++++++++++ > drivers/media/pci/mgb4/mgb4_sysfs_out.c | 681 +++++++++++++++++ > drivers/media/pci/mgb4/mgb4_sysfs_pci.c | 71 ++ > drivers/media/pci/mgb4/mgb4_trigger.c | 208 ++++++ > drivers/media/pci/mgb4/mgb4_trigger.h | 8 + > drivers/media/pci/mgb4/mgb4_vin.c | 934 ++++++++++++++++++++++++ > drivers/media/pci/mgb4/mgb4_vin.h | 69 ++ > drivers/media/pci/mgb4/mgb4_vout.c | 597 +++++++++++++++ > drivers/media/pci/mgb4/mgb4_vout.h | 65 ++ > 26 files changed, 4862 insertions(+) > create mode 100644 drivers/media/pci/mgb4/Kconfig > create mode 100644 drivers/media/pci/mgb4/Makefile > create mode 100644 drivers/media/pci/mgb4/mgb4_cmt.c > create mode 100644 drivers/media/pci/mgb4/mgb4_cmt.h > create mode 100644 drivers/media/pci/mgb4/mgb4_core.c > create mode 100644 drivers/media/pci/mgb4/mgb4_core.h > create mode 100644 drivers/media/pci/mgb4/mgb4_dma.c > create mode 100644 drivers/media/pci/mgb4/mgb4_dma.h > create mode 100644 drivers/media/pci/mgb4/mgb4_i2c.c > create mode 100644 drivers/media/pci/mgb4/mgb4_i2c.h > create mode 100644 drivers/media/pci/mgb4/mgb4_io.h > create mode 100644 drivers/media/pci/mgb4/mgb4_regs.c > create mode 100644 drivers/media/pci/mgb4/mgb4_regs.h > create mode 100644 drivers/media/pci/mgb4/mgb4_sysfs.h > create mode 100644 drivers/media/pci/mgb4/mgb4_sysfs_in.c > create mode 100644 drivers/media/pci/mgb4/mgb4_sysfs_out.c > create mode 100644 drivers/media/pci/mgb4/mgb4_sysfs_pci.c > create mode 100644 drivers/media/pci/mgb4/mgb4_trigger.c > create mode 100644 drivers/media/pci/mgb4/mgb4_trigger.h > create mode 100644 drivers/media/pci/mgb4/mgb4_vin.c > create mode 100644 drivers/media/pci/mgb4/mgb4_vin.h > create mode 100644 drivers/media/pci/mgb4/mgb4_vout.c > create mode 100644 drivers/media/pci/mgb4/mgb4_vout.h > > diff --git a/drivers/media/pci/mgb4/mgb4_sysfs_in.c b/drivers/media/pci/mgb4/mgb4_sysfs_in.c > new file mode 100644 > index 000000000000..61b1ee969ed0 > --- /dev/null > +++ b/drivers/media/pci/mgb4/mgb4_sysfs_in.c > @@ -0,0 +1,744 @@ > +// SPDX-License-Identifier: GPL-2.0-only > +/* > + * Copyright (C) 2021-2023 Digiteq Automotive > + * author: Martin Tuma > + * > + * This module handles all the sysfs info/configuration that is related to the > + * v4l2 input devices. > + */ > + > +#include > +#include "mgb4_core.h" > +#include "mgb4_i2c.h" > +#include "mgb4_vin.h" > +#include "mgb4_cmt.h" > +#include "mgb4_sysfs.h" > + > +/* Common for both FPDL3 and GMSL */ > + > +static ssize_t input_id_show(struct device *dev, > + struct device_attribute *attr, char *buf) > +{ > + struct video_device *vdev = to_video_device(dev); > + struct mgb4_vin_dev *vindev = video_get_drvdata(vdev); > + > + return sprintf(buf, "%d\n", vindev->config->id); > +} > + > +static ssize_t oldi_lane_width_show(struct device *dev, > + struct device_attribute *attr, char *buf) > +{ > + struct video_device *vdev = to_video_device(dev); > + struct mgb4_vin_dev *vindev = video_get_drvdata(vdev); > + struct mgb4_dev *mgbdev = vindev->mgbdev; > + u16 i2c_reg; > + u8 i2c_mask, i2c_single_val, i2c_dual_val; > + u32 config; > + int ret; > + > + i2c_reg = MGB4_IS_GMSL(mgbdev) ? 0x1CE : 0x49; > + i2c_mask = MGB4_IS_GMSL(mgbdev) ? 0x0E : 0x03; > + i2c_single_val = MGB4_IS_GMSL(mgbdev) ? 0x00 : 0x02; > + i2c_dual_val = MGB4_IS_GMSL(mgbdev) ? 0x0E : 0x00; > + > + mutex_lock(&mgbdev->i2c_lock); > + ret = mgb4_i2c_read_byte(&vindev->deser, i2c_reg); > + mutex_unlock(&mgbdev->i2c_lock); > + if (ret < 0) > + return -EIO; > + > + config = mgb4_read_reg(&mgbdev->video, vindev->config->regs.config); > + > + if (((config & (1U << 9)) && ((ret & i2c_mask) != i2c_dual_val)) || > + (!(config & (1U << 9)) && ((ret & i2c_mask) != i2c_single_val))) { > + dev_err(dev, "I2C/FPGA register value mismatch\n"); > + return -EINVAL; > + } > + > + return sprintf(buf, "%s\n", config & (1U << 9) ? "1" : "0"); > +} > + > +static ssize_t oldi_lane_width_store(struct device *dev, > + struct device_attribute *attr, > + const char *buf, size_t count) > +{ > + struct video_device *vdev = to_video_device(dev); > + struct mgb4_vin_dev *vindev = video_get_drvdata(vdev); > + struct mgb4_dev *mgbdev = vindev->mgbdev; > + u32 fpga_data; > + u16 i2c_reg; > + u8 i2c_mask, i2c_data; > + unsigned long val; > + int ret; > + > + ret = kstrtoul(buf, 10, &val); > + if (ret) > + return ret; > + > + switch (val) { > + case 0: /* single */ > + fpga_data = 0; > + i2c_data = MGB4_IS_GMSL(mgbdev) ? 0x00 : 0x02; > + break; > + case 1: /* dual */ > + fpga_data = 1U << 9; > + i2c_data = MGB4_IS_GMSL(mgbdev) ? 0x0E : 0x00; > + break; > + default: > + return -EINVAL; > + } > + > + i2c_reg = MGB4_IS_GMSL(mgbdev) ? 0x1CE : 0x49; > + i2c_mask = MGB4_IS_GMSL(mgbdev) ? 0x0E : 0x03; Isn't this sequence needed as well? mutex_lock(vindev->vdev.lock); if (vb2_is_busy(vindev->vdev.queue)) { mutex_unlock(vindev->vdev.lock); return -EBUSY; } I would expect this to be present in almost all store functions. You don't want to change a setting like this when the queue is busy. If a store function doesn't need the lock, then perhaps add a comment like: 'This can be changed at any time, even if vb2_is_busy() is true.' Can you go through all the store functions and verify this? Basically any store function that changes timings/video source/buffer size needs this check. Similar to VIDIOC_S_FMT and VIDIOC_S_DV_TIMINGS ioctls: you can't change those while buffers are allocated. > + > + mutex_lock(&mgbdev->i2c_lock); > + ret = mgb4_i2c_mask_byte(&vindev->deser, i2c_reg, i2c_mask, i2c_data); > + mutex_unlock(&mgbdev->i2c_lock); > + if (ret < 0) > + return -EIO; > + mgb4_mask_reg(&mgbdev->video, vindev->config->regs.config, 1U << 9, > + fpga_data); > + if (MGB4_IS_GMSL(mgbdev)) { > + /* reset input link */ > + mutex_lock(&mgbdev->i2c_lock); > + ret = mgb4_i2c_mask_byte(&vindev->deser, 0x10, 1U << 5, 1U << 5); > + mutex_unlock(&mgbdev->i2c_lock); > + if (ret < 0) > + return -EIO; > + } > + > + return count; > +} > + > +static ssize_t color_mapping_show(struct device *dev, > + struct device_attribute *attr, char *buf) > +{ > + struct video_device *vdev = to_video_device(dev); > + struct mgb4_vin_dev *vindev = video_get_drvdata(vdev); > + u32 config = mgb4_read_reg(&vindev->mgbdev->video, > + vindev->config->regs.config); > + > + return sprintf(buf, "%s\n", config & (1U << 8) ? "0" : "1"); > +} > + > +static ssize_t color_mapping_store(struct device *dev, > + struct device_attribute *attr, > + const char *buf, size_t count) > +{ > + struct video_device *vdev = to_video_device(dev); > + struct mgb4_vin_dev *vindev = video_get_drvdata(vdev); > + u32 fpga_data; > + unsigned long val; > + int ret; > + > + ret = kstrtoul(buf, 10, &val); > + if (ret) > + return ret; > + > + switch (val) { > + case 0: /* OLDI/JEIDA */ > + fpga_data = (1U << 8); > + break; > + case 1: /* SPWG/VESA */ > + fpga_data = 0; > + break; > + default: > + return -EINVAL; > + } > + > + mgb4_mask_reg(&vindev->mgbdev->video, vindev->config->regs.config, > + 1U << 8, fpga_data); This is likely a store function that can be called at any time as this doesn't interrupt video streaming or changes buffer sizes. > + > + return count; > +} > + Regards, Hans