All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/3] IOCTLs in ddbridge
@ 2018-05-12 11:24 Daniel Scheller
  2018-05-12 11:24   ` Daniel Scheller
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Daniel Scheller @ 2018-05-12 11:24 UTC (permalink / raw)
  To: linux-media, mchehab, mchehab, mchehab+samsung

From: Daniel Scheller <d.scheller@gmx.net>

Third iteration of the IOCTL patches for ddbridge, split into multiple
patches:

Patch 1 just adds the reservation/information of the used IOCTLs into
ioctl-numbers.txt in the Docs dir. Doc, s390 and LKML are Cc'ed on
this patch.

Patch 2 adds the header which defines the IOCTLs in include/uapi/ so
userspace applications can directly reuse the IOCTL definitions by
including this file.

Patch 3 (re)implements the IOCTL handling into ddbridge. This is
basically code that was there since literally forever, but had to be
removed along with the initial ddbridge-0.9.x bump.

The whole functionality gets more important these days since ie. the
new MaxSX8 cards may require updating from time to time since these
cards implement the demod/tuner communication in their FPGA (which
normally I2C drivers exist for). Also, the CineS2v7 and derivatives
received some important updates and the possibility to receive higher
bitrate transponders these days, so users should be able to update
their cards.

Changes since the last versions:
- Docs, headers and code split apart and sent out separately to
  the subsystems.
- Only the two absolutely necessary IOCTLs (DDB_FLASHIO and DDB_ID)
  are implemented for now.

Daniel Scheller (3):
  Documentation: ioctl-number: add ddbridge IOCTLs
  [media] ddbridge: uAPI header for IOCTL definitions and related data
    structs
  [media] ddbridge: implement IOCTL handling

 Documentation/ioctl/ioctl-number.txt        |   1 +
 MAINTAINERS                                 |   1 +
 drivers/media/pci/ddbridge/Makefile         |   3 +-
 drivers/media/pci/ddbridge/ddbridge-core.c  | 111 +----------------
 drivers/media/pci/ddbridge/ddbridge-ioctl.c | 179 ++++++++++++++++++++++++++++
 drivers/media/pci/ddbridge/ddbridge-ioctl.h |  32 +++++
 include/uapi/linux/ddbridge-ioctl.h         |  61 ++++++++++
 7 files changed, 278 insertions(+), 110 deletions(-)
 create mode 100644 drivers/media/pci/ddbridge/ddbridge-ioctl.c
 create mode 100644 drivers/media/pci/ddbridge/ddbridge-ioctl.h
 create mode 100644 include/uapi/linux/ddbridge-ioctl.h

-- 
2.16.1

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v3 1/3] Documentation: ioctl-number: add ddbridge IOCTLs
  2018-05-12 11:24 [PATCH v3 0/3] IOCTLs in ddbridge Daniel Scheller
@ 2018-05-12 11:24   ` Daniel Scheller
  2018-05-12 11:24 ` [PATCH v3 2/3] [media] ddbridge: uAPI header for IOCTL definitions and related data structs Daniel Scheller
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 8+ messages in thread
From: Daniel Scheller @ 2018-05-12 11:24 UTC (permalink / raw)
  To: linux-media, mchehab, mchehab, mchehab+samsung
  Cc: linux-doc, linux-s390, linux-kernel

From: Daniel Scheller <d.scheller@gmx.net>

drivers/media/pci/ddbridge exposes a few IOCTLs which are used by userspace
utilities to ie. update PCIe card's FPGA firmware.

The IOCTLs chosen are in the range 0xDD/0xE0 up to 0xDD/0xFF, with 0xDD as
sort of gimmick for "Digital Devices". To not conflict with the zfpc driver
the upper range (0xE0-0xFF) is used. It is not clear if and which IOCTL
numbers the zfpc driver really uses, from reading the sources at
drivers/s390/scsi/ I couldn't really determine if IOCTLs are in use at all.
Maybe the S390 maintainers can double-check or comment, thus Cc linux-s390.

The upstream dddvb driver currently exposes 12 IOCTLs from which we're
going to handle two at the moment (DDB_FLASHIO and DDB_ID), which is all
that's required to perform the FPGA update on this hardware. The
"reservation" of 32 IDs may seem way too much in this regard, however,
we'd like to be able to stay compatible with the upstream out-of-tree
driver as much as possible, so should any of the remaining 10 IOCTLs be
required at any time (or even more, should upstream add more in the
future), we can just add them into this range without any hassles or
without creating conflicts anywhere.

Cc: linux-doc@vger.kernel.org
Cc: linux-s390@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Daniel Scheller <d.scheller@gmx.net>
---
 Documentation/ioctl/ioctl-number.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/ioctl/ioctl-number.txt b/Documentation/ioctl/ioctl-number.txt
index 84bb74dcae12..feac1b56900b 100644
--- a/Documentation/ioctl/ioctl-number.txt
+++ b/Documentation/ioctl/ioctl-number.txt
@@ -334,6 +334,7 @@ Code  Seq#(hex)	Include File		Comments
 0xDB	00-0F	drivers/char/mwave/mwavepub.h
 0xDD	00-3F	ZFCP device driver	see drivers/s390/scsi/
 					<mailto:aherrman@de.ibm.com>
+0xDD	E0-FF	linux/ddbridge-ioctl.h
 0xE5	00-3F	linux/fuse.h
 0xEC	00-01	drivers/platform/chrome/cros_ec_dev.h	ChromeOS EC driver
 0xF3	00-3F	drivers/usb/misc/sisusbvga/sisusb.h	sisfb (in development)
-- 
2.16.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v3 1/3] Documentation: ioctl-number: add ddbridge IOCTLs
@ 2018-05-12 11:24   ` Daniel Scheller
  0 siblings, 0 replies; 8+ messages in thread
From: Daniel Scheller @ 2018-05-12 11:24 UTC (permalink / raw)
  To: linux-media, mchehab, mchehab, mchehab+samsung
  Cc: linux-doc, linux-s390, linux-kernel

From: Daniel Scheller <d.scheller@gmx.net>

drivers/media/pci/ddbridge exposes a few IOCTLs which are used by userspace
utilities to ie. update PCIe card's FPGA firmware.

The IOCTLs chosen are in the range 0xDD/0xE0 up to 0xDD/0xFF, with 0xDD as
sort of gimmick for "Digital Devices". To not conflict with the zfpc driver
the upper range (0xE0-0xFF) is used. It is not clear if and which IOCTL
numbers the zfpc driver really uses, from reading the sources at
drivers/s390/scsi/ I couldn't really determine if IOCTLs are in use at all.
Maybe the S390 maintainers can double-check or comment, thus Cc linux-s390.

The upstream dddvb driver currently exposes 12 IOCTLs from which we're
going to handle two at the moment (DDB_FLASHIO and DDB_ID), which is all
that's required to perform the FPGA update on this hardware. The
"reservation" of 32 IDs may seem way too much in this regard, however,
we'd like to be able to stay compatible with the upstream out-of-tree
driver as much as possible, so should any of the remaining 10 IOCTLs be
required at any time (or even more, should upstream add more in the
future), we can just add them into this range without any hassles or
without creating conflicts anywhere.

Cc: linux-doc@vger.kernel.org
Cc: linux-s390@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Daniel Scheller <d.scheller@gmx.net>
---
 Documentation/ioctl/ioctl-number.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/ioctl/ioctl-number.txt b/Documentation/ioctl/ioctl-number.txt
index 84bb74dcae12..feac1b56900b 100644
--- a/Documentation/ioctl/ioctl-number.txt
+++ b/Documentation/ioctl/ioctl-number.txt
@@ -334,6 +334,7 @@ Code  Seq#(hex)	Include File		Comments
 0xDB	00-0F	drivers/char/mwave/mwavepub.h
 0xDD	00-3F	ZFCP device driver	see drivers/s390/scsi/
 					<mailto:aherrman@de.ibm.com>
+0xDD	E0-FF	linux/ddbridge-ioctl.h
 0xE5	00-3F	linux/fuse.h
 0xEC	00-01	drivers/platform/chrome/cros_ec_dev.h	ChromeOS EC driver
 0xF3	00-3F	drivers/usb/misc/sisusbvga/sisusb.h	sisfb (in development)
-- 
2.16.1

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v3 2/3] [media] ddbridge: uAPI header for IOCTL definitions and related data structs
  2018-05-12 11:24 [PATCH v3 0/3] IOCTLs in ddbridge Daniel Scheller
  2018-05-12 11:24   ` Daniel Scheller
@ 2018-05-12 11:24 ` Daniel Scheller
  2018-05-12 11:24 ` [PATCH v3 3/3] [media] ddbridge: implement IOCTL handling Daniel Scheller
  2018-07-04 16:08 ` [PATCH v3 0/3] IOCTLs in ddbridge Mauro Carvalho Chehab
  3 siblings, 0 replies; 8+ messages in thread
From: Daniel Scheller @ 2018-05-12 11:24 UTC (permalink / raw)
  To: linux-media, mchehab, mchehab, mchehab+samsung

From: Daniel Scheller <d.scheller@gmx.net>

Add a uAPI header to define the IOCTLs and the related data structs used by
ddbridge, which currently are IOCTL_DDB_FLASHIO and IOCTL_DDB_IO. The
header can be included by userspace applications directly to make use of
the IOCTLs, and they even should use this header to keep things matching
with the kernel driver.

Signed-off-by: Daniel Scheller <d.scheller@gmx.net>
---
 MAINTAINERS                         |  1 +
 include/uapi/linux/ddbridge-ioctl.h | 61 +++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+)
 create mode 100644 include/uapi/linux/ddbridge-ioctl.h

diff --git a/MAINTAINERS b/MAINTAINERS
index 0a919a84d344..6b7da989fbed 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -8710,6 +8710,7 @@ W:	https://linuxtv.org
 T:	git git://linuxtv.org/media_tree.git
 S:	Maintained
 F:	drivers/media/pci/ddbridge/*
+F:	include/uapi/linux/ddbridge-ioctl.h
 
 MEDIA DRIVERS FOR FREESCALE IMX
 M:	Steve Longerbeam <slongerbeam@gmail.com>
diff --git a/include/uapi/linux/ddbridge-ioctl.h b/include/uapi/linux/ddbridge-ioctl.h
new file mode 100644
index 000000000000..5b28a797da41
--- /dev/null
+++ b/include/uapi/linux/ddbridge-ioctl.h
@@ -0,0 +1,61 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * ddbridge-ioctl.h: Digital Devices bridge IOCTL API
+ *
+ * Copyright (C) 2010-2017 Digital Devices GmbH
+ *                         Ralph Metzler <rjkm@metzlerbros.de>
+ *                         Marcus Metzler <mocm@metzlerbros.de>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 only, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef __LINUX_DDBRIDGE_IOCTL_H__
+#define __LINUX_DDBRIDGE_IOCTL_H__
+
+#include <linux/compiler.h>
+#include <linux/types.h>
+
+/******************************************************************************/
+
+#define DDB_IOCTL_MAGIC		0xDD
+#define DDB_IOCTL_SEQIDX	0xE0
+
+/* DDB_IOCTL_FLASHIO */
+struct ddb_flashio {
+	/* write_*: userspace -> flash */
+	__user __u8 *write_buf;
+	__u32        write_len;
+	/* read_*: flash -> userspace */
+	__user __u8 *read_buf;
+	__u32        read_len;
+	/* card/addon link */
+	__u32        link;
+};
+
+/* DDB_IOCTL_ID */
+struct ddb_id {
+	/* card/PCI device data, FPGA/regmap info */
+	__u16 vendor;
+	__u16 device;
+	__u16 subvendor;
+	__u16 subdevice;
+	__u32 hw;
+	__u32 regmap;
+};
+
+/* IOCTLs */
+#define DDB_IOCTL_FLASHIO \
+	_IOWR(DDB_IOCTL_MAGIC, (DDB_IOCTL_SEQIDX + 0x00), struct ddb_flashio)
+#define DDB_IOCTL_ID \
+	_IOR(DDB_IOCTL_MAGIC,  (DDB_IOCTL_SEQIDX + 0x03), struct ddb_id)
+
+/******************************************************************************/
+
+#endif /* __LINUX_DDBRIDGE_IOCTL_H__ */
-- 
2.16.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v3 3/3] [media] ddbridge: implement IOCTL handling
  2018-05-12 11:24 [PATCH v3 0/3] IOCTLs in ddbridge Daniel Scheller
  2018-05-12 11:24   ` Daniel Scheller
  2018-05-12 11:24 ` [PATCH v3 2/3] [media] ddbridge: uAPI header for IOCTL definitions and related data structs Daniel Scheller
@ 2018-05-12 11:24 ` Daniel Scheller
  2018-07-04 16:08 ` [PATCH v3 0/3] IOCTLs in ddbridge Mauro Carvalho Chehab
  3 siblings, 0 replies; 8+ messages in thread
From: Daniel Scheller @ 2018-05-12 11:24 UTC (permalink / raw)
  To: linux-media, mchehab, mchehab, mchehab+samsung

From: Daniel Scheller <d.scheller@gmx.net>

This patch adds back the IOCTL API/functionality which is present in the
upstream dddvb driver package. In comparison, the IOCTL handler has been
factored to a separate object (and with that, some functionality from
-core, such as reg_wait() and ddb_flashio() has been moved there aswell).
The IOCTLs were defined in an include in include/uapi/linux/ previously
and being reused here.

The main purpose at the moment is to enable the mainline driver to handle
FPGA firmware updates of all cards supported by the ddbridge driver, which
gets even more important since the introduction of the MaxSX8 support
(this card basically implements the I2C demod/tuner drivers which are used
normally in FPGA, so any fixes need to be flashed into the card), and
the recent firmware releases for the CineS2v7 and Octopus CI S2 series
that not only carry bugfixes, but also enables support for higher
bandwidth transponders.

Signed-off-by: Daniel Scheller <d.scheller@gmx.net>
---
 drivers/media/pci/ddbridge/Makefile         |   3 +-
 drivers/media/pci/ddbridge/ddbridge-core.c  | 111 +----------------
 drivers/media/pci/ddbridge/ddbridge-ioctl.c | 179 ++++++++++++++++++++++++++++
 drivers/media/pci/ddbridge/ddbridge-ioctl.h |  32 +++++
 4 files changed, 215 insertions(+), 110 deletions(-)
 create mode 100644 drivers/media/pci/ddbridge/ddbridge-ioctl.c
 create mode 100644 drivers/media/pci/ddbridge/ddbridge-ioctl.h

diff --git a/drivers/media/pci/ddbridge/Makefile b/drivers/media/pci/ddbridge/Makefile
index 9b9e35f171b7..3563a3e3d7f9 100644
--- a/drivers/media/pci/ddbridge/Makefile
+++ b/drivers/media/pci/ddbridge/Makefile
@@ -4,7 +4,8 @@
 #
 
 ddbridge-objs := ddbridge-main.o ddbridge-core.o ddbridge-ci.o \
-		ddbridge-hw.o ddbridge-i2c.o ddbridge-max.o ddbridge-mci.o
+		ddbridge-hw.o ddbridge-i2c.o ddbridge-ioctl.o ddbridge-max.o \
+		ddbridge-mci.o
 
 obj-$(CONFIG_DVB_DDBRIDGE) += ddbridge.o
 
diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c b/drivers/media/pci/ddbridge/ddbridge-core.c
index 377269c64449..cc0db7b718b1 100644
--- a/drivers/media/pci/ddbridge/ddbridge-core.c
+++ b/drivers/media/pci/ddbridge/ddbridge-core.c
@@ -40,6 +40,7 @@
 #include "ddbridge-max.h"
 #include "ddbridge-ci.h"
 #include "ddbridge-io.h"
+#include "ddbridge-ioctl.h"
 
 #include "tda18271c2dd.h"
 #include "stv6110x.h"
@@ -2547,112 +2548,14 @@ irqreturn_t ddb_irq_handler(int irq, void *dev_id)
 /****************************************************************************/
 /****************************************************************************/
 
-static int reg_wait(struct ddb *dev, u32 reg, u32 bit)
-{
-	u32 count = 0;
-
-	while (safe_ddbreadl(dev, reg) & bit) {
-		ndelay(10);
-		if (++count == 100)
-			return -1;
-	}
-	return 0;
-}
-
-static int flashio(struct ddb *dev, u32 lnr, u8 *wbuf, u32 wlen, u8 *rbuf,
-		   u32 rlen)
-{
-	u32 data, shift;
-	u32 tag = DDB_LINK_TAG(lnr);
-	struct ddb_link *link = &dev->link[lnr];
-
-	mutex_lock(&link->flash_mutex);
-	if (wlen > 4)
-		ddbwritel(dev, 1, tag | SPI_CONTROL);
-	while (wlen > 4) {
-		/* FIXME: check for big-endian */
-		data = swab32(*(u32 *)wbuf);
-		wbuf += 4;
-		wlen -= 4;
-		ddbwritel(dev, data, tag | SPI_DATA);
-		if (reg_wait(dev, tag | SPI_CONTROL, 4))
-			goto fail;
-	}
-	if (rlen)
-		ddbwritel(dev, 0x0001 | ((wlen << (8 + 3)) & 0x1f00),
-			  tag | SPI_CONTROL);
-	else
-		ddbwritel(dev, 0x0003 | ((wlen << (8 + 3)) & 0x1f00),
-			  tag | SPI_CONTROL);
-
-	data = 0;
-	shift = ((4 - wlen) * 8);
-	while (wlen) {
-		data <<= 8;
-		data |= *wbuf;
-		wlen--;
-		wbuf++;
-	}
-	if (shift)
-		data <<= shift;
-	ddbwritel(dev, data, tag | SPI_DATA);
-	if (reg_wait(dev, tag | SPI_CONTROL, 4))
-		goto fail;
-
-	if (!rlen) {
-		ddbwritel(dev, 0, tag | SPI_CONTROL);
-		goto exit;
-	}
-	if (rlen > 4)
-		ddbwritel(dev, 1, tag | SPI_CONTROL);
-
-	while (rlen > 4) {
-		ddbwritel(dev, 0xffffffff, tag | SPI_DATA);
-		if (reg_wait(dev, tag | SPI_CONTROL, 4))
-			goto fail;
-		data = ddbreadl(dev, tag | SPI_DATA);
-		*(u32 *)rbuf = swab32(data);
-		rbuf += 4;
-		rlen -= 4;
-	}
-	ddbwritel(dev, 0x0003 | ((rlen << (8 + 3)) & 0x1F00),
-		  tag | SPI_CONTROL);
-	ddbwritel(dev, 0xffffffff, tag | SPI_DATA);
-	if (reg_wait(dev, tag | SPI_CONTROL, 4))
-		goto fail;
-
-	data = ddbreadl(dev, tag | SPI_DATA);
-	ddbwritel(dev, 0, tag | SPI_CONTROL);
-
-	if (rlen < 4)
-		data <<= ((4 - rlen) * 8);
-
-	while (rlen > 0) {
-		*rbuf = ((data >> 24) & 0xff);
-		data <<= 8;
-		rbuf++;
-		rlen--;
-	}
-exit:
-	mutex_unlock(&link->flash_mutex);
-	return 0;
-fail:
-	mutex_unlock(&link->flash_mutex);
-	return -1;
-}
-
 int ddbridge_flashread(struct ddb *dev, u32 link, u8 *buf, u32 addr, u32 len)
 {
 	u8 cmd[4] = {0x03, (addr >> 16) & 0xff,
 		     (addr >> 8) & 0xff, addr & 0xff};
 
-	return flashio(dev, link, cmd, 4, buf, len);
+	return ddb_do_flashio(dev, link, cmd, 4, buf, len);
 }
 
-/*
- * TODO/FIXME: add/implement IOCTLs from upstream driver
- */
-
 #define DDB_NAME "ddbridge"
 
 static u32 ddb_num;
@@ -2678,16 +2581,6 @@ static int ddb_open(struct inode *inode, struct file *file)
 	return 0;
 }
 
-static long ddb_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
-{
-	struct ddb *dev = file->private_data;
-
-	dev_warn(dev->dev, "DDB IOCTLs unsupported (cmd: %d, arg: %lu)\n",
-		 cmd, arg);
-
-	return -ENOTTY;
-}
-
 static const struct file_operations ddb_fops = {
 	.unlocked_ioctl = ddb_ioctl,
 	.open           = ddb_open,
diff --git a/drivers/media/pci/ddbridge/ddbridge-ioctl.c b/drivers/media/pci/ddbridge/ddbridge-ioctl.c
new file mode 100644
index 000000000000..f0431b468383
--- /dev/null
+++ b/drivers/media/pci/ddbridge/ddbridge-ioctl.c
@@ -0,0 +1,179 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * ddbridge-ioctl.c: Digital Devices bridge IOCTL handler
+ *
+ * Copyright (C) 2010-2017 Digital Devices GmbH
+ *                         Ralph Metzler <rjkm@metzlerbros.de>
+ *                         Marcus Metzler <mocm@metzlerbros.de>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 only, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/module.h>
+#include <linux/i2c.h>
+#include <linux/vmalloc.h>
+
+#include "ddbridge.h"
+#include "ddbridge-i2c.h"
+#include "ddbridge-regs.h"
+#include "ddbridge-io.h"
+#include "ddbridge-ioctl.h"
+
+/******************************************************************************/
+
+static int reg_wait(struct ddb *dev, u32 reg, u32 bit)
+{
+	u32 count = 0;
+
+	while (safe_ddbreadl(dev, reg) & bit) {
+		ndelay(10);
+		if (++count == 100)
+			return -1;
+	}
+	return 0;
+}
+
+/******************************************************************************/
+
+int ddb_do_flashio(struct ddb *dev, u32 lnr, u8 *wbuf, u32 wlen,
+		   u8 *rbuf, u32 rlen)
+{
+	u32 data, shift;
+	u32 tag = DDB_LINK_TAG(lnr);
+	struct ddb_link *link = &dev->link[lnr];
+
+	mutex_lock(&link->flash_mutex);
+	if (wlen > 4)
+		ddbwritel(dev, 1, tag | SPI_CONTROL);
+	while (wlen > 4) {
+		/* FIXME: check for big-endian */
+		data = swab32(*(u32 *)wbuf);
+		wbuf += 4;
+		wlen -= 4;
+		ddbwritel(dev, data, tag | SPI_DATA);
+		if (reg_wait(dev, tag | SPI_CONTROL, 4))
+			goto fail;
+	}
+	if (rlen)
+		ddbwritel(dev, 0x0001 | ((wlen << (8 + 3)) & 0x1f00),
+			  tag | SPI_CONTROL);
+	else
+		ddbwritel(dev, 0x0003 | ((wlen << (8 + 3)) & 0x1f00),
+			  tag | SPI_CONTROL);
+
+	data = 0;
+	shift = ((4 - wlen) * 8);
+	while (wlen) {
+		data <<= 8;
+		data |= *wbuf;
+		wlen--;
+		wbuf++;
+	}
+	if (shift)
+		data <<= shift;
+	ddbwritel(dev, data, tag | SPI_DATA);
+	if (reg_wait(dev, tag | SPI_CONTROL, 4))
+		goto fail;
+
+	if (!rlen) {
+		ddbwritel(dev, 0, tag | SPI_CONTROL);
+		goto exit;
+	}
+	if (rlen > 4)
+		ddbwritel(dev, 1, tag | SPI_CONTROL);
+
+	while (rlen > 4) {
+		ddbwritel(dev, 0xffffffff, tag | SPI_DATA);
+		if (reg_wait(dev, tag | SPI_CONTROL, 4))
+			goto fail;
+		data = ddbreadl(dev, tag | SPI_DATA);
+		*(u32 *)rbuf = swab32(data);
+		rbuf += 4;
+		rlen -= 4;
+	}
+	ddbwritel(dev, 0x0003 | ((rlen << (8 + 3)) & 0x1F00),
+		  tag | SPI_CONTROL);
+	ddbwritel(dev, 0xffffffff, tag | SPI_DATA);
+	if (reg_wait(dev, tag | SPI_CONTROL, 4))
+		goto fail;
+
+	data = ddbreadl(dev, tag | SPI_DATA);
+	ddbwritel(dev, 0, tag | SPI_CONTROL);
+
+	if (rlen < 4)
+		data <<= ((4 - rlen) * 8);
+
+	while (rlen > 0) {
+		*rbuf = ((data >> 24) & 0xff);
+		data <<= 8;
+		rbuf++;
+		rlen--;
+	}
+exit:
+	mutex_unlock(&link->flash_mutex);
+	return 0;
+fail:
+	mutex_unlock(&link->flash_mutex);
+	return -1;
+}
+
+long ddb_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
+{
+	struct ddb *dev = file->private_data;
+	__user void *parg = (__user void *)arg;
+	int res;
+
+	switch (cmd) {
+	case DDB_IOCTL_FLASHIO:
+	{
+		struct ddb_flashio fio;
+		u8 *rbuf, *wbuf;
+
+		if (copy_from_user(&fio, parg, sizeof(fio)))
+			return -EFAULT;
+		if (fio.write_len > 1028 || fio.read_len > 1028)
+			return -EINVAL;
+		if (fio.write_len + fio.read_len > 1028)
+			return -EINVAL;
+		if (fio.link > 3)
+			return -EINVAL;
+
+		wbuf = dev->iobuf;
+		rbuf = wbuf + fio.write_len;
+
+		if (copy_from_user(wbuf, fio.write_buf, fio.write_len))
+			return -EFAULT;
+		res = ddb_do_flashio(dev, fio.link, wbuf, fio.write_len,
+				     rbuf, fio.read_len);
+		if (res)
+			return res;
+		if (copy_to_user(fio.read_buf, rbuf, fio.read_len))
+			return -EFAULT;
+		break;
+	}
+	case DDB_IOCTL_ID:
+	{
+		struct ddb_id ddbid;
+
+		ddbid.vendor = dev->link[0].ids.vendor;
+		ddbid.device = dev->link[0].ids.device;
+		ddbid.subvendor = dev->link[0].ids.subvendor;
+		ddbid.subdevice = dev->link[0].ids.subdevice;
+		ddbid.hw = ddbreadl(dev, 0);
+		ddbid.regmap = ddbreadl(dev, 4);
+		if (copy_to_user(parg, &ddbid, sizeof(ddbid)))
+			return -EFAULT;
+		break;
+	}
+	default:
+		return -ENOTTY;
+	}
+	return 0;
+}
diff --git a/drivers/media/pci/ddbridge/ddbridge-ioctl.h b/drivers/media/pci/ddbridge/ddbridge-ioctl.h
new file mode 100644
index 000000000000..4865e98482ef
--- /dev/null
+++ b/drivers/media/pci/ddbridge/ddbridge-ioctl.h
@@ -0,0 +1,32 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * ddbridge-ioctl.h: Digital Devices bridge IOCTL handler
+ *
+ * Copyright (C) 2010-2017 Digital Devices GmbH
+ *                         Ralph Metzler <rjkm@metzlerbros.de>
+ *                         Marcus Metzler <mocm@metzlerbros.de>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 only, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef __DDBRIDGE_IOCTL_H__
+#define __DDBRIDGE_IOCTL_H__
+
+#include <linux/ddbridge-ioctl.h>
+
+#include "ddbridge.h"
+
+/******************************************************************************/
+
+int ddb_do_flashio(struct ddb *dev, u32 lnr, u8 *wbuf, u32 wlen, u8 *rbuf,
+		   u32 rlen);
+long ddb_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
+
+#endif /* __DDBRIDGE_IOCTL_H__ */
-- 
2.16.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v3 0/3] IOCTLs in ddbridge.
  2018-05-12 11:24 [PATCH v3 0/3] IOCTLs in ddbridge Daniel Scheller
                   ` (2 preceding siblings ...)
  2018-05-12 11:24 ` [PATCH v3 3/3] [media] ddbridge: implement IOCTL handling Daniel Scheller
@ 2018-07-04 16:08 ` Mauro Carvalho Chehab
  2018-07-04 17:08   ` Daniel Scheller
  3 siblings, 1 reply; 8+ messages in thread
From: Mauro Carvalho Chehab @ 2018-07-04 16:08 UTC (permalink / raw)
  To: Daniel Scheller
  Cc: linux-media, mchehab, mchehab, Jonathan Corbet, Andrew Morton

Hi Daniel,

Em Sat, 12 May 2018 13:24:29 +0200
Daniel Scheller <d.scheller.oss@gmail.com> escreveu:

> From: Daniel Scheller <d.scheller@gmx.net>
> 
> Third iteration of the IOCTL patches for ddbridge, split into multiple
> patches:
> 
> Patch 1 just adds the reservation/information of the used IOCTLs into
> ioctl-numbers.txt in the Docs dir. Doc, s390 and LKML are Cc'ed on
> this patch.

Patch looks ok, although it would be great to get some acks there.
I don't know who currently maintains Documentation/ioctl/ioctl-number.txt.

Just in case, I would explicitly c/c LKML, Andrew Morton and Jonathan Corbet.
Please c/c them on a next respin.

> Patch 2 adds the header which defines the IOCTLs in include/uapi/ so
> userspace applications can directly reuse the IOCTL definitions by
> including this file.
> 
> Patch 3 (re)implements the IOCTL handling into ddbridge. This is
> basically code that was there since literally forever, but had to be
> removed along with the initial ddbridge-0.9.x bump.

Also looked ok.

What I miss here is a forth patch to Documentation/media/dvb-drivers/,
adding a documentation for ddbridge, in special explaining those new
ioctls.

> The whole functionality gets more important these days since ie. the
> new MaxSX8 cards may require updating from time to time since these
> cards implement the demod/tuner communication in their FPGA (which
> normally I2C drivers exist for). Also, the CineS2v7 and derivatives
> received some important updates and the possibility to receive higher
> bitrate transponders these days, so users should be able to update
> their cards.
> 
> Changes since the last versions:
> - Docs, headers and code split apart and sent out separately to
>   the subsystems.
> - Only the two absolutely necessary IOCTLs (DDB_FLASHIO and DDB_ID)
>   are implemented for now.
> 
> Daniel Scheller (3):
>   Documentation: ioctl-number: add ddbridge IOCTLs
>   [media] ddbridge: uAPI header for IOCTL definitions and related data
>     structs
>   [media] ddbridge: implement IOCTL handling
> 
>  Documentation/ioctl/ioctl-number.txt        |   1 +
>  MAINTAINERS                                 |   1 +
>  drivers/media/pci/ddbridge/Makefile         |   3 +-
>  drivers/media/pci/ddbridge/ddbridge-core.c  | 111 +----------------
>  drivers/media/pci/ddbridge/ddbridge-ioctl.c | 179 ++++++++++++++++++++++++++++
>  drivers/media/pci/ddbridge/ddbridge-ioctl.h |  32 +++++
>  include/uapi/linux/ddbridge-ioctl.h         |  61 ++++++++++
>  7 files changed, 278 insertions(+), 110 deletions(-)
>  create mode 100644 drivers/media/pci/ddbridge/ddbridge-ioctl.c
>  create mode 100644 drivers/media/pci/ddbridge/ddbridge-ioctl.h
>  create mode 100644 include/uapi/linux/ddbridge-ioctl.h

Thanks,
Mauro

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v3 0/3] IOCTLs in ddbridge.
  2018-07-04 16:08 ` [PATCH v3 0/3] IOCTLs in ddbridge Mauro Carvalho Chehab
@ 2018-07-04 17:08   ` Daniel Scheller
  2018-07-04 20:20     ` Jasmin J.
  0 siblings, 1 reply; 8+ messages in thread
From: Daniel Scheller @ 2018-07-04 17:08 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linux-media, mchehab, mchehab, Jonathan Corbet, Andrew Morton

Am Wed, 4 Jul 2018 13:08:31 -0300
schrieb Mauro Carvalho Chehab <mchehab+samsung@kernel.org>:

> Em Sat, 12 May 2018 13:24:29 +0200
> Daniel Scheller <d.scheller.oss@gmail.com> escreveu:
> 
> > From: Daniel Scheller <d.scheller@gmx.net>
> > 
> > Third iteration of the IOCTL patches for ddbridge, split into multiple
> > patches:
> > 
> > Patch 1 just adds the reservation/information of the used IOCTLs into
> > ioctl-numbers.txt in the Docs dir. Doc, s390 and LKML are Cc'ed on
> > this patch.  
> 
> Patch looks ok, although it would be great to get some acks there.
> I don't know who currently maintains Documentation/ioctl/ioctl-number.txt.
> 
> Just in case, I would explicitly c/c LKML, Andrew Morton and Jonathan Corbet.
> Please c/c them [...]

I did in patch 1 explicitly asking esp. the s390 guys since they're on
0xDD too but at a lower range, no response in two months, from anyone.

> on a next respin. [...] What I miss here is a forth patch to Documentation/media/dvb-drivers/,
> adding a documentation for ddbridge, in special explaining those new
> ioctls.

If you're fine with anything else in this series, please be so kind and
pick this stuff up and I'll shove such doc up afterwards as a separate
patch. This whole thing is being posted for over a year now, I waited
another two months, and I'm not interested in waiting for another such
long time (or even more) regarding this (remember I even asked for
review for the 4.18 merge window).

Best regards,
Daniel Scheller
-- 
https://github.com/herrnst

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v3 0/3] IOCTLs in ddbridge.
  2018-07-04 17:08   ` Daniel Scheller
@ 2018-07-04 20:20     ` Jasmin J.
  0 siblings, 0 replies; 8+ messages in thread
From: Jasmin J. @ 2018-07-04 20:20 UTC (permalink / raw)
  To: Daniel Scheller, Mauro Carvalho Chehab
  Cc: linux-media, mchehab, mchehab, Jonathan Corbet, Andrew Morton

Hello Mauro!

> Patch looks ok, although it would be great to get some acks there.
I have no time to test this, but I know Daniel does all this tests and in fact
he is currently adapting changes done by DD in their repo, modifying them to
work in the current media-tree version and submits them to the list. So this
is more or less work to keep the kernel driver in sync with the DD repo.

Please remember this from Daniels patch submit message:
  Patch 3 (re)implements the IOCTL handling into ddbridge. This is
  basically code that was there since literally forever, but had to be
  removed along with the initial ddbridge-0.9.x bump.
So he is adding back the original ioctl's, which are nowadays more used because
of (also from the patch submit message):
  The whole functionality gets more important these days since ie. the
  new MaxSX8 cards may require updating from time to time since these
  cards implement the demod/tuner communication in their FPGA

So if you need an ack:
Acked-by: Jasmin Jessich <jasmin@anw.at>

> If you're fine with anything else in this series, please be so kind and
> pick this stuff up and I'll shove such doc up afterwards as a separate
> patch. This whole thing is being posted for over a year now, ...
Please Mauro, merge this now and I am sure Daniel will add the missing
documentation!
Keep also in mind, that we all do this in our spare time and we do this because
DD was and is not willing to submit their own drivers!
Do your really believe that it is helpful when patches are rodding months for
no reason? This is often demotivating and thus some maintainers may give up
only because of that.
I am extremely happy, that Daniel took over and made it happen, that we get the
DD drivers into the Kernel and thus, we can use DD HW and also other HW in
parallel. This would be not possible with the drivers from DD.

BR,
   Jasmin

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2018-07-04 20:20 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-12 11:24 [PATCH v3 0/3] IOCTLs in ddbridge Daniel Scheller
2018-05-12 11:24 ` [PATCH v3 1/3] Documentation: ioctl-number: add ddbridge IOCTLs Daniel Scheller
2018-05-12 11:24   ` Daniel Scheller
2018-05-12 11:24 ` [PATCH v3 2/3] [media] ddbridge: uAPI header for IOCTL definitions and related data structs Daniel Scheller
2018-05-12 11:24 ` [PATCH v3 3/3] [media] ddbridge: implement IOCTL handling Daniel Scheller
2018-07-04 16:08 ` [PATCH v3 0/3] IOCTLs in ddbridge Mauro Carvalho Chehab
2018-07-04 17:08   ` Daniel Scheller
2018-07-04 20:20     ` Jasmin J.

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.