From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.3 required=3.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8BAD0C433E2 for ; Fri, 15 May 2020 21:49:03 +0000 (UTC) Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5E3642070A for ; Fri, 15 May 2020 21:49:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UfspDq1N" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5E3642070A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linux-kernel-mentees-bounces@lists.linuxfoundation.org Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 3C4A0204A3; Fri, 15 May 2020 21:49:03 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id lrKWjabF1Lfq; Fri, 15 May 2020 21:49:01 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by silver.osuosl.org (Postfix) with ESMTP id 3C18620390; Fri, 15 May 2020 21:49:01 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 3871BC0859; Fri, 15 May 2020 21:49:01 +0000 (UTC) Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 09484C016F for ; Fri, 15 May 2020 21:49:00 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id E35A5204A3 for ; Fri, 15 May 2020 21:48:59 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id DRd0W4BUUBxN for ; Fri, 15 May 2020 21:48:58 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail-qt1-f194.google.com (mail-qt1-f194.google.com [209.85.160.194]) by silver.osuosl.org (Postfix) with ESMTPS id 43A1520390 for ; Fri, 15 May 2020 21:48:58 +0000 (UTC) Received: by mail-qt1-f194.google.com with SMTP id b1so3337602qtt.1 for ; Fri, 15 May 2020 14:48:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QTgxjgP7ni5FQZNgtx5Ofdb6xnD87mdiS6TCPHM45aE=; b=UfspDq1NN19JqgY2PKdJ1hgyfLj6tTu7/iTIMov99cpFR83/Lq2+oW19awTc2u7W/R 2RFhB0KoTN6GopGNSx0iIcejYooAiwAaCNqmAfdJ3aS+IFbmVV/MEqAldX3Sk8aftSdn jMpTuR1CW9aJdMtwut6sitp5c7x0GGgyv830Nl1WwIBmOj3jmUGpKK/QAxqu1bIwhAG6 KWMvPfACbIXwtPOyXTWXUzj1oiMX4VoI2wfqq9/p4mbFl0+eop0wA8Iz9EGtidIeS+7Q rklMGREaZhlQJm9D8xRx1m98jd2FrhKJOIkZO+nekbksyMiXyHlB5+3GnpCL60o8ktyt 62lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QTgxjgP7ni5FQZNgtx5Ofdb6xnD87mdiS6TCPHM45aE=; b=kT+i4fGNwU67OxLpXmTOueHkGHdD+ZGIQ0YJjUuRtp9Sfqvz3zfl6AskFTZBEATG3Q CHNfLsGRo2Ok7hliswoWfVyHJDAHyf5Ha88GVtcm7wvLZO0xWdsj0GiLIjFDNoeVfDxW nCK/Rzxp89Cm0ZwJ013T67jnGImdEJLgriHZu/mGN/pqAoKCNJEQy2EXDvEBER8tOkED MAPH+mfcjrJjy4ls/NZdvMG8nTR6+e89szhyERJ/uXAE3uYlPX7cW+8E0mHBLXj2xx9C Iu7NMmA9cxgphNowj0ad/KdcgAz0Q/8K8vGNDLKoBQg6WY1z4jJvwszQAeK78bGUXAnq ZeuA== X-Gm-Message-State: AOAM532Ropj9QXfeTaoMjG1Pq/MWcrRHu43o5Ms7xQe/kJ0XBrVnxZgk m3vOlqjwZb4AOLHJ3nIAZyY= X-Google-Smtp-Source: ABdhPJw7dBNVRXZ+av8gRw+36fCxay3apM0XPLTkerHg6iGAX9FoFbZYByje837MykjtvL4I3+3biQ== X-Received: by 2002:ac8:4e38:: with SMTP id d24mr5675797qtw.343.1589579337091; Fri, 15 May 2020 14:48:57 -0700 (PDT) Received: from localhost.localdomain ([2804:18:700e:2692:8980:dd13:6be6:4050]) by smtp.gmail.com with ESMTPSA id m21sm2495019qkh.50.2020.05.15.14.48.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2020 14:48:56 -0700 (PDT) From: "Daniel W. S. Almeida" X-Google-Original-From: Daniel W. S. Almeida To: mchehab+huawei@kernel.org, sean@mess.org, kstewart@linuxfoundation.org, allison@lohutok.net, tglx@linutronix.de Date: Fri, 15 May 2020 18:48:09 -0300 Message-Id: <20200515214815.15514-5-dwlsalmeida@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200515214815.15514-1-dwlsalmeida@gmail.com> References: <20200515214815.15514-1-dwlsalmeida@gmail.com> MIME-Version: 1.0 Cc: linux-kernel@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org, "Daniel W. S. Almeida" , linux-media@vger.kernel.org Subject: [Linux-kernel-mentees] [RFC, WIP, v5 04/10] media: vidtv: add a bridge driver X-BeenThere: linux-kernel-mentees@lists.linuxfoundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-kernel-mentees-bounces@lists.linuxfoundation.org Sender: "Linux-kernel-mentees" From: "Daniel W. S. Almeida" Digital TV devices consist of several independent hardware components which are controlled by different drivers. Each media device is controlled by a group of cooperating drivers with the bridge driver as the main driver. This patch adds a bridge driver for the Virtual Digital TV driver [vidtv]. The bridge driver binds to the other drivers, that is, vidtv_tuner and vidtv_demod and implements the digital demux logic, providing userspace with a MPEG Transport Stream. Move config structs to a common header so they can be used by the bridge driver and by their respective drivers. Signed-off-by: Daniel W. S. Almeida --- drivers/media/test-drivers/vidtv/Makefile | 4 +- .../media/test-drivers/vidtv/vidtv_bridg.c | 380 ++++++++++++++++++ .../media/test-drivers/vidtv/vidtv_bridg.h | 37 ++ 3 files changed, 420 insertions(+), 1 deletion(-) create mode 100644 drivers/media/test-drivers/vidtv/vidtv_bridg.c create mode 100644 drivers/media/test-drivers/vidtv/vidtv_bridg.h diff --git a/drivers/media/test-drivers/vidtv/Makefile b/drivers/media/test-drivers/vidtv/Makefile index 36ba00ddc0d1e..e0bb1b3bedad6 100644 --- a/drivers/media/test-drivers/vidtv/Makefile +++ b/drivers/media/test-drivers/vidtv/Makefile @@ -1,3 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -obj-$(CONFIG_DVB_VIDTV) += vidtv_tuner.o vidtv_demod.o +vidtv_bridge-objs = vidtv_bridg.o + +obj-$(CONFIG_DVB_VIDTV) += vidtv_tuner.o vidtv_demod.o vidtv_bridge.o diff --git a/drivers/media/test-drivers/vidtv/vidtv_bridg.c b/drivers/media/test-drivers/vidtv/vidtv_bridg.c new file mode 100644 index 0000000000000..95e564b91d4d1 --- /dev/null +++ b/drivers/media/test-drivers/vidtv/vidtv_bridg.c @@ -0,0 +1,380 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * The Virtual DTV test driver serves as a reference DVB driver and helps + * validate the existing APIs in the media subsystem. It can also aid + * developers working on userspace applications. + * + * Written by Daniel W. S. Almeida + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ":%s, %d: " fmt, __func__, __LINE__ + +#include +#include +#include +#include +#include +#include "linux/printk.h" + +#include "vidtv_bridg.h" +#include "vidtv_tuner.h" +#include "vidtv_demod.h" + +#define TUNER_DEFAULT_ADDR 0x68 +#define DEMOD_DEFAULT_ADDR 0x60 + +MODULE_AUTHOR("Daniel W. S. Almeida"); +MODULE_LICENSE("GPL"); + +static unsigned int drop_tslock_prob_on_low_snr; +module_param(drop_tslock_prob_on_low_snr, uint, 0); +MODULE_PARM_DESC(drop_tslock_prob_on_low_snr, + "Probability of losing the TS lock if the signal quality is bad"); + +static unsigned int recover_tslock_prob_on_good_snr; +module_param(recover_tslock_prob_on_good_snr, uint, 0); +MODULE_PARM_DESC(recover_tslock_prob_on_good_snr, + "Probability recovering the TS lock when the signal improves"); + +static unsigned int mock_power_up_delay_msec; +module_param(mock_power_up_delay_msec, uint, 0); +MODULE_PARM_DESC(mock_power_up_delay_msec, "Simulate a power up delay"); + +static unsigned int mock_tune_delay_msec; +module_param(mock_tune_delay_msec, uint, 0); +MODULE_PARM_DESC(mock_tune_delay_msec, "Simulate a tune delay"); + +static unsigned int vidtv_valid_dvb_t_freqs[8]; +module_param_array(vidtv_valid_dvb_t_freqs, uint, NULL, 0); +MODULE_PARM_DESC(vidtv_valid_dvb_t_freqs, + "Valid DVB-T frequencies to simulate"); + +static unsigned int vidtv_valid_dvb_c_freqs[8]; +module_param_array(vidtv_valid_dvb_c_freqs, uint, NULL, 0); +MODULE_PARM_DESC(vidtv_valid_dvb_c_freqs, + "Valid DVB-C frequencies to simulate"); + +static unsigned int vidtv_valid_dvb_s_freqs[8]; +module_param_array(vidtv_valid_dvb_s_freqs, uint, NULL, 0); +MODULE_PARM_DESC(vidtv_valid_dvb_s_freqs, + "Valid DVB-C frequencies to simulate"); + +static unsigned int max_frequency_shift_hz; +module_param(max_frequency_shift_hz, uint, 0); +MODULE_PARM_DESC(max_frequency_shift_hz, + "Maximum shift in HZ allowed when tuning in a channel"); + +DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nums); + +static int vidtv_start_streaming(struct vidtv_dvb *dvb) +{ + if (dvb->streaming) { + pr_warn_ratelimited("Already streaming. Skipping.\n"); + return 0; + } + + dvb->streaming = true; + return 0; +} + +static int vidtv_stop_streaming(struct vidtv_dvb *dvb) +{ + dvb->streaming = false; + + return 0; +} + +static int vidtv_start_feed(struct dvb_demux_feed *feed) +{ + struct dvb_demux *demux = feed->demux; + struct vidtv_dvb *dvb = demux->priv; + int rc; + int ret; + + if (!demux->dmx.frontend) + return -EINVAL; + + mutex_lock(&dvb->feed_lock); + + dvb->nfeeds++; + rc = dvb->nfeeds; + + if (dvb->nfeeds == 1) { + ret = vidtv_start_streaming(dvb); + if (ret < 0) + rc = ret; + } + + mutex_unlock(&dvb->feed_lock); + return rc; +} + +static int vidtv_stop_feed(struct dvb_demux_feed *feed) +{ + struct dvb_demux *demux = feed->demux; + struct vidtv_dvb *dvb = demux->priv; + int err = 0; + + mutex_lock(&dvb->feed_lock); + dvb->nfeeds--; + + if (!dvb->nfeeds) + err = vidtv_stop_streaming(dvb); + + mutex_unlock(&dvb->feed_lock); + return err; +} + +static int vidtv_master_xfer(struct i2c_adapter *i2c_adap, + struct i2c_msg msgs[], + int num) +{ + return 0; +} + +static u32 vidtv_i2c_func(struct i2c_adapter *adapter) +{ + return I2C_FUNC_I2C; +} + +static struct i2c_algorithm vidtv_i2c_algorithm = { + .master_xfer = vidtv_master_xfer, + .functionality = vidtv_i2c_func, +}; + +static int vidtv_bridge_i2c_register_adap(struct vidtv_dvb *dvb) +{ + struct i2c_adapter *i2c_adapter = dvb->i2c_adapter; + + strscpy(i2c_adapter->name, "vidtv_i2c", sizeof(i2c_adapter->name)); + i2c_adapter->owner = THIS_MODULE; + i2c_adapter->algo = &vidtv_i2c_algorithm; + i2c_adapter->algo_data = NULL; + i2c_adapter->timeout = 500; + i2c_adapter->retries = 3; + i2c_adapter->dev.parent = NULL; + + i2c_set_adapdata(i2c_adapter, dvb); + return i2c_add_adapter(dvb->i2c_adapter); +} + +static int vidtv_bridge_register_adap(struct vidtv_dvb *dvb) +{ + int ret = 0; + + ret = dvb_register_adapter(&dvb->adapter, + KBUILD_MODNAME, + THIS_MODULE, + &dvb->i2c_adapter->dev, + adapter_nums); + + return ret; +} + +static int vidtv_bridge_dmx_init(struct vidtv_dvb *dvb) +{ + dvb->demux.dmx.capabilities = DMX_TS_FILTERING | + DMX_SECTION_FILTERING; + + dvb->demux.priv = dvb; + dvb->demux.filternum = 256; + dvb->demux.feednum = 256; + dvb->demux.start_feed = vidtv_start_feed; + dvb->demux.stop_feed = vidtv_stop_feed; + + return dvb_dmx_init(&dvb->demux); +} + +static int vidtv_bridge_dmxdev_init(struct vidtv_dvb *dvb) +{ + dvb->dmx_dev.filternum = 256; + dvb->dmx_dev.demux = &dvb->demux.dmx; + dvb->dmx_dev.capabilities = 0; + + return dvb_dmxdev_init(&dvb->dmx_dev, &dvb->adapter); +} + +static void vidtv_bridge_probe_demod(struct vidtv_dvb *dvb, u32 n) +{ + struct vidtv_demod_config cfg = {0}; + struct dvb_frontend *fe = NULL; + + cfg.frontend = &fe; + cfg.drop_tslock_prob_on_low_snr = drop_tslock_prob_on_low_snr; + cfg.recover_tslock_prob_on_good_snr = recover_tslock_prob_on_good_snr; + + dvb->i2c_client_demod[n] = dvb_module_probe("vidtv_demod", + NULL, + dvb->i2c_adapter, + DEMOD_DEFAULT_ADDR, + &cfg); + + /* retrieve a pointer to struct dvb_frontend */ + dvb->fe[n] = *cfg.frontend; +} + +static void vidtv_bridge_probe_tuner(struct vidtv_dvb *dvb, u32 n) +{ + struct vidtv_tuner_config cfg = {0}; + + cfg.fe = dvb->fe[n]; + cfg.mock_power_up_delay_msec = mock_power_up_delay_msec; + cfg.mock_tune_delay_msec = mock_tune_delay_msec; + + memcpy(cfg.vidtv_valid_dvb_t_freqs, + vidtv_valid_dvb_t_freqs, + sizeof(vidtv_valid_dvb_t_freqs)); + + memcpy(cfg.vidtv_valid_dvb_c_freqs, + vidtv_valid_dvb_c_freqs, + sizeof(vidtv_valid_dvb_c_freqs)); + + memcpy(cfg.vidtv_valid_dvb_s_freqs, + vidtv_valid_dvb_s_freqs, + sizeof(vidtv_valid_dvb_s_freqs)); + + cfg.max_frequency_shift_hz = max_frequency_shift_hz; + + dvb->i2c_client_tuner[n] = dvb_module_probe("vidtv_tuner", + NULL, + dvb->i2c_adapter, + TUNER_DEFAULT_ADDR, + &cfg); +} + +static int vidtv_bridge_dvb_init(struct vidtv_dvb *dvb) +{ + int ret; + int i; + int j; + + ret = vidtv_bridge_i2c_register_adap(dvb); + if (ret < 0) + goto fail_i2c; + + ret = vidtv_bridge_register_adap(dvb); + if (ret < 0) + goto fail_adapter; + + vidtv_bridge_probe_demod(dvb, 0); + vidtv_bridge_probe_tuner(dvb, 0); + + for (i = 0; i < NUM_FE; ++i) { + ret = dvb_register_frontend(&dvb->adapter, dvb->fe[i]); + if (ret < 0) + goto fail_fe; + } + + ret = vidtv_bridge_dmx_init(dvb); + if (ret < 0) + goto fail_dmx; + + ret = vidtv_bridge_dmxdev_init(dvb); + if (ret < 0) + goto fail_dmx_dev; + + for (j = 0; j < NUM_FE; ++j) { + ret = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, + &dvb->dmx_fe[j]); + if (ret < 0) + goto fail_dmx_conn; + + /* + * The source of the demux is a frontend connected + * to the demux. + */ + dvb->dmx_fe[j].source = DMX_FRONTEND_0; + } + + return ret; + +fail_dmx_conn: + for (j = j - 1; j >= 0; --j) + dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, + &dvb->dmx_fe[j]); +fail_dmx_dev: + dvb_dmxdev_release(&dvb->dmx_dev); +fail_dmx: + dvb_dmx_release(&dvb->demux); +fail_fe: + for (i = i - 1; i >= 0; --i) + dvb_unregister_frontend(dvb->fe[i]); + +fail_adapter: + dvb_unregister_adapter(&dvb->adapter); + +fail_i2c: + i2c_del_adapter(dvb->i2c_adapter); + + return ret; +} + +static int vidtv_bridge_i2c_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + int ret; + struct vidtv_dvb *dvb; + + dvb = kzalloc(sizeof(*dvb), GFP_KERNEL); + if (!dvb) + return -ENOMEM; + + ret = vidtv_bridge_dvb_init(dvb); + if (ret < 0) + goto err_dvb; + + mutex_init(&dvb->feed_lock); + + i2c_set_clientdata(client, dvb); + + return ret; + +err_dvb: + kfree(dvb); + return ret; +} + +static int vidtv_bridge_i2c_remove(struct i2c_client *client) +{ + struct vidtv_dvb *dvb; + u32 i; + + dvb = i2c_get_clientdata(client); + + mutex_destroy(&dvb->feed_lock); + + for (i = 0; i < NUM_FE; ++i) + dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, + &dvb->dmx_fe[i]); + + dvb_dmxdev_release(&dvb->dmx_dev); + dvb_dmx_release(&dvb->demux); + + for (i = 0; i < NUM_FE; ++i) { + dvb_unregister_frontend(dvb->fe[i]); + dvb_frontend_detach(dvb->fe[i]); + } + + dvb_unregister_adapter(&dvb->adapter); + + return 0; +} + +static const struct i2c_device_id vidtv_bridge_id_table[] = { + {"vidtv_bridge", 0}, + {} +}; + +MODULE_DEVICE_TABLE(i2c, vidtv_bridge_id_table); + +static struct i2c_driver vidtv_bridge_driver = { + .driver = { + .name = "vidtv_bridge", + .suppress_bind_attrs = true, + }, + .probe = vidtv_bridge_i2c_probe, + .remove = vidtv_bridge_i2c_remove, + .id_table = vidtv_bridge_id_table, +}; + +module_i2c_driver(vidtv_bridge_driver); diff --git a/drivers/media/test-drivers/vidtv/vidtv_bridg.h b/drivers/media/test-drivers/vidtv/vidtv_bridg.h new file mode 100644 index 0000000000000..dead155c2735c --- /dev/null +++ b/drivers/media/test-drivers/vidtv/vidtv_bridg.h @@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * The Virtual DTV test driver serves as a reference DVB driver and helps + * validate the existing APIs in the media subsystem. It can also aid + * developers working on userspace applications. + * + * Written by Daniel W. S. Almeida + */ + +#ifndef VIDTV_BRIDG_H +#define VIDTV_BRIDG_H + +#define NUM_FE 1 + +#include +#include +#include +#include +#include + +struct vidtv_dvb { + struct dvb_frontend *fe[NUM_FE]; + struct dvb_adapter adapter; + struct dvb_demux demux; + struct dmxdev dmx_dev; + struct dmx_frontend dmx_fe[NUM_FE]; + struct i2c_adapter *i2c_adapter; + struct i2c_client *i2c_client_demod[NUM_FE]; + struct i2c_client *i2c_client_tuner[NUM_FE]; + + u32 nfeeds; + struct mutex feed_lock; /* start/stop feed */ + + bool streaming; +}; + +#endif // VIDTV_BRIDG_H -- 2.26.2 _______________________________________________ Linux-kernel-mentees mailing list Linux-kernel-mentees@lists.linuxfoundation.org https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees