Skip to contentSkip to conversation

media: dvb_dummy_tuner: implement driver skeleton

PATCH Superseded Daniel W. S. Almeida 3 participants 5 messages Jan 9, 2020 – Jan 13, 2020 Media (V4L/DVB)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 media: dvb_dummy_tuner: implement driver skeleton

From: "Daniel W. S. Almeida" <[email protected]>

Implement a dummy DVB tuner as part of ongoing work on a virtual DVB test driver under the 2020 Spring Linux Kernel Mentorship Program.

The virtual DVB 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.

This dummy tuner should support common TV standards such as DVB-T/T2/S/S2, ISDB-T and ATSC when completed.

For now, only a basic skeleton is available, most functions do nothing whatsoever.

-----------------------------------------------------------

Changes in v2:
Commit message was rewritten
Added better description in KConfig
Added better description in .h and .c
Added copyright notice in .h and .c
Kconfig dummy tuner option now defaults to 'n'
Removed calls to pr_err, pr_debug
Not addressed in v2:
attach()/release() calls:
I would appreciate some clarification on this, since some tuners implement only probe()/remove(), some implement only attach()/release() and some implement both (e.g. mt2060.c). Furthermore, in mt2060.c, both attach() and probe() copy struct dvb_tuner_ops into fe->ops->tuner_ops.

-------------------------------------------------------------

 drivers/media/tuners/Kconfig           |   9 ++
 drivers/media/tuners/Makefile          |   1 +
 drivers/media/tuners/dvb_dummy_tuner.c | 160 +++++++++++++++++++++++++
 drivers/media/tuners/dvb_dummy_tuner.h |  31 +++++
 4 files changed, 201 insertions(+)
 create mode 100644 drivers/media/tuners/dvb_dummy_tuner.c
 create mode 100644 drivers/media/tuners/dvb_dummy_tuner.h
drivers/media/tuners/Kconfig +9 -0
index e104bb7766e1..d433dc7e68b1 100644
@@ -296,4 +296,13 @@ config MEDIA_TUNER_QM1D1B0004
 	default m if !MEDIA_SUBDRV_AUTOSELECT
 	help
 	  Sharp QM1D1B0004 ISDB-S tuner driver.
+
+config MEDIA_TUNER_DVB_DUMMY_TUNER
+	tristate "Dummy tuner"
+	depends on MEDIA_SUPPORT && I2C
+	default n
+	help
+	  The virtual DVB 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.
 endmenu
drivers/media/tuners/Makefile +1 -0
index 7b4f8423501e..f98de1cf2e19 100644
@@ -44,5 +44,6 @@ obj-$(CONFIG_MEDIA_TUNER_QM1D1C0042) += qm1d1c0042.o
 obj-$(CONFIG_MEDIA_TUNER_QM1D1B0004) += qm1d1b0004.o
 obj-$(CONFIG_MEDIA_TUNER_M88RS6000T) += m88rs6000t.o
 obj-$(CONFIG_MEDIA_TUNER_TDA18250) += tda18250.o
+obj-$(CONFIG_MEDIA_TUNER_DVB_DUMMY_TUNER) += dvb_dummy_tuner.o
 
 ccflags-y += -I$(srctree)/drivers/media/dvb-frontends
drivers/media/tuners/dvb_dummy_tuner.c new file +160 -0

160 lines not on this page · raw message

drivers/media/tuners/dvb_dummy_tuner.h new file +31 -0
new file mode 100644
index 000000000000..3569bbc3716e
@@ -0,0 +1,31 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * A dummy DVB tuner as part of ongoing work
+ * on a virtual DVB test driver under the 2020 Spring Linux
+ * Kernel Mentorship Program.
+ *
+ * The virtual DVB 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.
+ *
+ * This dummy tuner should support common TV standards such as DVB-T/T2/S/S2,
+ * ISDB-T and ATSC when completed.
+ *
+ * Copyright (c) 2020 Daniel W. S. Almeida <[email protected]>
+ */
+
+#ifndef __TUNER_DVB_DUMMY_TUNER_H__
+#define __TUNER_DVB_DUMMY_TUNER_H__
+
+#include <media/dvb_frontend.h>
+/**
+ * struct dvb_dummy_tuner_config - configuration parameters for the dummy tuner
+ *
+ * @fe:
+ *	frontend returned by driver
+ */
+struct dvb_dummy_tuner_config {
+	struct dvb_frontend *fe;
+};
+
+#endif /*__TUNER_DVB_DUMMY_TUNER_H__ */
Signature · 1 line
2.24.1
#1 lore raw
Quoted 7 lines · Daniel W. S. Almeida

From: "Daniel W. S. Almeida" <[email protected]>

Implement a dummy DVB tuner as part of ongoing work on a virtual DVB test driver under the 2020 Spring Linux Kernel Mentorship Program.

Get rid of the above. Not relevant for the patch. No need to spin v3 just for this change and you can make the with other changes as you get comments from others.

Quoted 11 lines

The virtual DVB 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.

This dummy tuner should support common TV standards such as DVB-T/T2/S/S2, ISDB-T and ATSC when completed.

For now, only a basic skeleton is available, most functions do nothing whatsoever.

thanks,
-- Shuah

#2 lore raw
In reply to Daniel W. S. Almeida

drivers/media/tuners/Kconfig config MEDIA_TUNER_QM1D1B0004 · line 301

Quoted 2 lines · Daniel W. S. Almeida
drivers/media/tuners/Kconfig +2 -0
+config MEDIA_TUNER_DVB_DUMMY_TUNER
+	tristate "Dummy tuner"

"Dummy DVB Media Tuner" perhaps?

drivers/media/tuners/Kconfig config MEDIA_TUNER_QM1D1B0004 · line 303

Quoted 2 lines
drivers/media/tuners/Kconfig +2 -0
+	depends on MEDIA_SUPPORT && I2C
+	default n

"default n" is always the default, no need to list it again here.

drivers/media/tuners/Kconfig config MEDIA_TUNER_QM1D1B0004 · line 307

Quoted 4 lines
drivers/media/tuners/Kconfig +4 -0
+	help
+	  The virtual DVB 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.

A bit of text here saying what the module name would be is always nice, see other Kconfig entries for the normal text needed.

Quoted 18 lines

endmenu

drivers/media/tuners/Makefile +1 -0
index 7b4f8423501e..f98de1cf2e19 100644
@@ -44,5 +44,6 @@ obj-$(CONFIG_MEDIA_TUNER_QM1D1C0042) += qm1d1c0042.o
 obj-$(CONFIG_MEDIA_TUNER_QM1D1B0004) += qm1d1b0004.o
 obj-$(CONFIG_MEDIA_TUNER_M88RS6000T) += m88rs6000t.o
 obj-$(CONFIG_MEDIA_TUNER_TDA18250) += tda18250.o
+obj-$(CONFIG_MEDIA_TUNER_DVB_DUMMY_TUNER) += dvb_dummy_tuner.o
 
 ccflags-y += -I$(srctree)/drivers/media/dvb-frontends
drivers/media/tuners/dvb_dummy_tuner.c new file +0 -0
new file mode 100644
index 000000000000..8aed5d583eeb

drivers/media/tuners/dvb_dummy_tuner.c line 1

Quoted 1 line
drivers/media/tuners/dvb_dummy_tuner.c new file +1 -0
@@ -0,0 +1,160 @@
+// SPDX-License-Identifier: GPL-2.0-or-later

I have to ask, are you _SURE_ you want "GPL 2+" here?

drivers/media/tuners/dvb_dummy_tuner.c line 5

Quoted 4 lines
drivers/media/tuners/dvb_dummy_tuner.c new file +4 -0
+/*
+ * A dummy DVB tuner as part of ongoing work
+ * on a virtual DVB test driver under the 2020 Spring Linux
+ * Kernel Mentorship Program.

No need for saying why it was written in the file like this :)

drivers/media/tuners/dvb_dummy_tuner.c line 14

Quoted 9 lines
drivers/media/tuners/dvb_dummy_tuner.c new file +9 -0
+ *
+ * The virtual DVB 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.
+ *
+ * This dummy tuner should support common TV standards such as DVB-T/T2/S/S2,
+ * ISDB-T and ATSC when completed.
+ *
+ * Copyright (c) 2020 Daniel W. S. Almeida <[email protected]>

Normally this is the first comment line above in this block.

Quoted 93 lines
drivers/media/tuners/dvb_dummy_tuner.c new file +93 -0
+ */
+
+#include <linux/errno.h>
+#include <linux/i2c.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/types.h>
+#include <media/dvb_frontend.h>
+#include "dvb_dummy_tuner.h"
+
+struct dvb_dummy_tuner_dev {
+	struct dvb_frontend *fe;
+};
+
+static void dvb_dummy_tuner_release(struct dvb_frontend *fe)
+{
+}
+
+static int dvb_dummy_tuner_init(struct dvb_frontend *fe)
+{
+	return 0;
+}
+
+static int dvb_dummy_tuner_sleep(struct dvb_frontend *fe)
+{
+	return 0;
+}
+
+static int dvb_dummy_tuner_suspend(struct dvb_frontend *fe)
+{
+	return 0;
+}
+
+static int dvb_dummy_tuner_resume(struct dvb_frontend *fe)
+{
+	return 0;
+}
+
+static int dvb_dummy_tuner_set_params(struct dvb_frontend *fe)
+{
+	return 0;
+}
+
+static int dvb_dummy_tuner_set_config(struct dvb_frontend *fe, void *priv_cfg)
+{
+	return 0;
+}
+
+static int dvb_dummy_tuner_get_frequency(struct dvb_frontend *fe,
+					 u32 *frequency)
+{
+	return 0;
+}
+
+static int dvb_dummy_tuner_get_bandwidth(struct dvb_frontend *fe,
+					 u32 *bandwidth)
+{
+	return 0;
+}
+
+static int dvb_dummy_tuner_get_if_frequency(struct dvb_frontend *fe,
+					    u32 *frequency)
+{
+	return 0;
+}
+
+static int dvb_dummy_tuner_get_status(struct dvb_frontend *fe, u32 *status)
+{
+	return 0;
+}
+
+static const struct dvb_tuner_ops dvb_dummy_tuner_ops = {
+	.release = dvb_dummy_tuner_release,
+	.init = dvb_dummy_tuner_init,
+	.sleep = dvb_dummy_tuner_sleep,
+	.suspend = dvb_dummy_tuner_suspend,
+	.resume = dvb_dummy_tuner_resume,
+	.set_params = dvb_dummy_tuner_set_params,
+	.set_config = dvb_dummy_tuner_set_config,
+	.get_bandwidth = dvb_dummy_tuner_get_bandwidth,
+	.get_frequency = dvb_dummy_tuner_get_frequency,
+	.get_if_frequency = dvb_dummy_tuner_get_if_frequency,
+	.get_status = dvb_dummy_tuner_get_status,
+};
+
+static const struct i2c_device_id dvb_dummy_tuner_i2c_id_table[] = {
+	{"dvb_dummy_tuner", 0},
+	{}
+};
+MODULE_DEVICE_TABLE(i2c, dvb_dummy_tuner_i2c_id_table);
+
+static int dvb_dummy_tuner_i2c_probe(struct i2c_client *client,
+				     const struct i2c_device_id *id)

drivers/media/tuners/dvb_dummy_tuner.c line 117

Quoted 10 lines
drivers/media/tuners/dvb_dummy_tuner.c new file +10 -0
+{
+	int ret = 0;
+	struct dvb_dummy_tuner_config *config = client->dev.platform_data;
+	struct dvb_frontend *fe = config->fe;
+	struct dvb_dummy_tuner_dev *tuner_dev = NULL;
+
+	tuner_dev = kzalloc(sizeof(*tuner_dev), GFP_KERNEL);
+	if (!tuner_dev) {
+		ret = -ENOMEM;
+		goto err;

Simplify this by just doing:

	return -ENOMEM;

No need to jump around the function for no actual cleanup.

drivers/media/tuners/dvb_dummy_tuner.c line 121

Quoted 4 lines
drivers/media/tuners/dvb_dummy_tuner.c new file +4 -0
+	}
+
+	i2c_set_clientdata(client, tuner_dev);
+	tuner_dev->fe = config->fe;

Normal "pattern" is to set up the variable and after it's all ready, then save the pointer off. In other words, reverse these two lines :)

drivers/media/tuners/dvb_dummy_tuner.h

Quoted 44 lines
drivers/media/tuners/dvb_dummy_tuner.c new file +39 -0
+
+	memcpy(&fe->ops.tuner_ops,
+	       &dvb_dummy_tuner_ops,
+	       sizeof(struct dvb_tuner_ops));
+
+	fe->tuner_priv = client;
+
+	return ret;
+
+err:
+	return ret;
+}
+
+static int dvb_dummy_tuner_i2c_remove(struct i2c_client *client)
+{
+	struct dvb_dummy_tuner_dev *tuner_dev = i2c_get_clientdata(client);
+	struct dvb_frontend *fe = tuner_dev->fe;
+
+	memset(&fe->ops.tuner_ops, 0, sizeof(struct dvb_tuner_ops));
+	fe->tuner_priv = NULL;
+	kfree(tuner_dev);
+
+	return 0;
+}
+
+static struct i2c_driver dvb_dummy_tuner_i2c_driver = {
+	.driver = {
+		.name = "dvb_dummy_tuner",
+		.suppress_bind_attrs = true,
+	},
+	.probe		= dvb_dummy_tuner_i2c_probe,
+	.remove		= dvb_dummy_tuner_i2c_remove,
+	.id_table	= dvb_dummy_tuner_i2c_id_table,
+};
+module_i2c_driver(dvb_dummy_tuner_i2c_driver);
+
+MODULE_DESCRIPTION("DVB Dummy Tuner");
+MODULE_AUTHOR("Daniel W. S. Almeida");
+MODULE_LICENSE("GPL");
drivers/media/tuners/dvb_dummy_tuner.h new file +0 -0
new file mode 100644
index 000000000000..3569bbc3716e

Why do you need a .h file for a simple driver that does not export anything to anyone else?

drivers/media/tuners/dvb_dummy_tuner.h line 1

Quoted 2 lines
drivers/media/tuners/dvb_dummy_tuner.h new file +1 -0
@@ -0,0 +1,31 @@
+/* SPDX-License-Identifier: GPL-2.0 */

Not the same license as your .c file? Odd :(

drivers/media/tuners/dvb_dummy_tuner.h line 14

Quoted 13 lines
drivers/media/tuners/dvb_dummy_tuner.h new file +13 -0
+/*
+ * A dummy DVB tuner as part of ongoing work
+ * on a virtual DVB test driver under the 2020 Spring Linux
+ * Kernel Mentorship Program.
+ *
+ * The virtual DVB 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.
+ *
+ * This dummy tuner should support common TV standards such as DVB-T/T2/S/S2,
+ * ISDB-T and ATSC when completed.
+ *
+ * Copyright (c) 2020 Daniel W. S. Almeida <[email protected]>

If you keep this file, same comments as above for the comment block, but really, you don't need this .h file at all, just drop it.

thanks,

greg k-h

#3 lore raw

Hi Greg,

I am working on v3. Would you mind clarifying this?

Quoted 11 lines
Quoted 9 lines

+ *
+ * The virtual DVB 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.
+ *
+ * This dummy tuner should support common TV standards such as DVB-T/T2/S/S2,
+ * ISDB-T and ATSC when completed.
+ *
+ * Copyright (c) 2020 Daniel W. S. Almeida <[email protected]>

Normally this is the first comment line above in this block.

Just so we're clear, do you mean this? e.g.:

+ * Copyright (c) 2020 Daniel W. S. Almeida <[email protected]>
+ *
+ * The virtual DVB 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.
+ *
+ * This dummy tuner should support common TV standards such as DVB-T/T2/S/S2,
+ * ISDB-T and ATSC when completed.
+ *

Quoted 1 line

Not the same license as your .c file? Odd :(

Oops! :(

Quoted 2 lines

If you keep this file, same comments as above for the comment block, but really, you don't need this .h file at all, just drop it.

OK.

- Daniel

#4 lore raw
Quoted 14 lines · Daniel W. S. Almeida

Hi Greg,

I am working on v3. Would you mind clarifying this?

Quoted 9 lines
Quoted 9 lines

+ *
+ * The virtual DVB 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.
+ *
+ * This dummy tuner should support common TV standards such as DVB-T/T2/S/S2,
+ * ISDB-T and ATSC when completed.
+ *
+ * Copyright (c) 2020 Daniel W. S. Almeida <[email protected]>

Quoted 6 lines
Quoted 2 lines

Normally this is the first comment line above in this block.

Just so we're clear, do you mean this? e.g.:

+ * Copyright (c) 2020 Daniel W. S. Almeida <[email protected]>

Yes.
_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees