Re: [PATCH v2 15/19] [media] ddbridge: initial support for MCI-based MaxSX8 cards

2018-05-04 Thread Mauro Carvalho Chehab
Em Mon,  9 Apr 2018 18:47:48 +0200
Daniel Scheller  escreveu:

> From: Daniel Scheller 
> 
> This adds initial support for the new MCI-based (micro-code interface)
> DD cards, with the first one being the MaxSX8 eight-tuner DVB-S/S2/S2X
> PCIe card. The MCI is basically a generalized interface implemented in
> the card's FPGA firmware and usable for all kind of cards, without the
> need to implement any demod/tuner drivers as this interface "hides" any
> I2C interface to the actual ICs, in other words any required driver is
> implemented in the card firmware.
> 
> At this stage, the MCI interface is quite rudimentary with things like
> signal statistics reporting missing, but is already working to serve
> DVB streams to DVB applications. Missing functionality will be enabled
> over time.
> 
> This implements only the ddbridge-mci sub-object and hooks it up to the
> Makefile so the object gets build. The upcoming commits hook this module
> into all other ddbridge parts where required, including device IDs etc.
> 
> Picked up from the upstream dddvb-0.9.33 release.

There are three checkpatch issues to be handled here:

WARNING: function definition argument 'int' should also have an identifier name
#764: FILE: drivers/media/pci/ddbridge/ddbridge-mci.h:147:
+struct dvb_frontend

WARNING: function definition argument 'struct dvb_frontend *' should also have 
an identifier name
#764: FILE: drivers/media/pci/ddbridge/ddbridge-mci.h:147:
+struct dvb_frontend

WARNING: function definition argument 'int' should also have an identifier name
#764: FILE: drivers/media/pci/ddbridge/ddbridge-mci.h:147:
+struct dvb_frontend

Please submit a patch later addressing it.

> 
> Signed-off-by: Daniel Scheller 
> ---
>  drivers/media/pci/ddbridge/Makefile   |   2 +-
>  drivers/media/pci/ddbridge/ddbridge-mci.c | 550 
> ++
>  drivers/media/pci/ddbridge/ddbridge-mci.h | 152 +
>  3 files changed, 703 insertions(+), 1 deletion(-)
>  create mode 100644 drivers/media/pci/ddbridge/ddbridge-mci.c
>  create mode 100644 drivers/media/pci/ddbridge/ddbridge-mci.h
> 
> diff --git a/drivers/media/pci/ddbridge/Makefile 
> b/drivers/media/pci/ddbridge/Makefile
> index 745b37d07558..9b9e35f171b7 100644
> --- a/drivers/media/pci/ddbridge/Makefile
> +++ b/drivers/media/pci/ddbridge/Makefile
> @@ -4,7 +4,7 @@
>  #
>  
>  ddbridge-objs := ddbridge-main.o ddbridge-core.o ddbridge-ci.o \
> - ddbridge-hw.o ddbridge-i2c.o ddbridge-max.o
> + ddbridge-hw.o ddbridge-i2c.o ddbridge-max.o ddbridge-mci.o
>  
>  obj-$(CONFIG_DVB_DDBRIDGE) += ddbridge.o
>  
> diff --git a/drivers/media/pci/ddbridge/ddbridge-mci.c 
> b/drivers/media/pci/ddbridge/ddbridge-mci.c
> new file mode 100644
> index ..214b301f30a5
> --- /dev/null
> +++ b/drivers/media/pci/ddbridge/ddbridge-mci.c
> @@ -0,0 +1,550 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * ddbridge-mci.c: Digital Devices microcode interface
> + *
> + * Copyright (C) 2017 Digital Devices GmbH
> + *Ralph Metzler 
> + *Marcus Metzler 
> + *
> + * 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 "ddbridge.h"
> +#include "ddbridge-io.h"
> +#include "ddbridge-mci.h"
> +
> +static LIST_HEAD(mci_list);
> +
> +static const u32 MCLK = (155000 / 12);
> +static const u32 MAX_DEMOD_LDPC_BITRATE = (155000 / 6);
> +static const u32 MAX_LDPC_BITRATE = (72000);
> +
> +struct mci_base {
> + struct list_head mci_list;
> + void*key;
> + struct ddb_link *link;
> + struct completioncompletion;
> +
> + struct device   *dev;
> + struct mutex tuner_lock; /* concurrent tuner access lock */
> + u8   adr;
> + struct mutex mci_lock; /* concurrent MCI access lock */
> + int  count;
> +
> + u8   tuner_use_count[4];
> + u8   assigned_demod[8];
> + u32  used_ldpc_bitrate[8];
> + u8   demod_in_use[8];
> + u32  iq_mode;
> +};
> +
> +struct mci {
> + struct mci_base *base;
> + struct dvb_frontend  fe;
> + int  nr;
> + int  demod;
> + int  tuner;
> + int  first_time_lock;
> + int  started;
> + struct mci_resultsignal_info;
> +
> + u32  

[PATCH v2 15/19] [media] ddbridge: initial support for MCI-based MaxSX8 cards

2018-04-09 Thread Daniel Scheller
From: Daniel Scheller 

This adds initial support for the new MCI-based (micro-code interface)
DD cards, with the first one being the MaxSX8 eight-tuner DVB-S/S2/S2X
PCIe card. The MCI is basically a generalized interface implemented in
the card's FPGA firmware and usable for all kind of cards, without the
need to implement any demod/tuner drivers as this interface "hides" any
I2C interface to the actual ICs, in other words any required driver is
implemented in the card firmware.

At this stage, the MCI interface is quite rudimentary with things like
signal statistics reporting missing, but is already working to serve
DVB streams to DVB applications. Missing functionality will be enabled
over time.

This implements only the ddbridge-mci sub-object and hooks it up to the
Makefile so the object gets build. The upcoming commits hook this module
into all other ddbridge parts where required, including device IDs etc.

Picked up from the upstream dddvb-0.9.33 release.

Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ddbridge/Makefile   |   2 +-
 drivers/media/pci/ddbridge/ddbridge-mci.c | 550 ++
 drivers/media/pci/ddbridge/ddbridge-mci.h | 152 +
 3 files changed, 703 insertions(+), 1 deletion(-)
 create mode 100644 drivers/media/pci/ddbridge/ddbridge-mci.c
 create mode 100644 drivers/media/pci/ddbridge/ddbridge-mci.h

diff --git a/drivers/media/pci/ddbridge/Makefile 
b/drivers/media/pci/ddbridge/Makefile
index 745b37d07558..9b9e35f171b7 100644
--- a/drivers/media/pci/ddbridge/Makefile
+++ b/drivers/media/pci/ddbridge/Makefile
@@ -4,7 +4,7 @@
 #
 
 ddbridge-objs := ddbridge-main.o ddbridge-core.o ddbridge-ci.o \
-   ddbridge-hw.o ddbridge-i2c.o ddbridge-max.o
+   ddbridge-hw.o ddbridge-i2c.o ddbridge-max.o ddbridge-mci.o
 
 obj-$(CONFIG_DVB_DDBRIDGE) += ddbridge.o
 
diff --git a/drivers/media/pci/ddbridge/ddbridge-mci.c 
b/drivers/media/pci/ddbridge/ddbridge-mci.c
new file mode 100644
index ..214b301f30a5
--- /dev/null
+++ b/drivers/media/pci/ddbridge/ddbridge-mci.c
@@ -0,0 +1,550 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * ddbridge-mci.c: Digital Devices microcode interface
+ *
+ * Copyright (C) 2017 Digital Devices GmbH
+ *Ralph Metzler 
+ *Marcus Metzler 
+ *
+ * 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 "ddbridge.h"
+#include "ddbridge-io.h"
+#include "ddbridge-mci.h"
+
+static LIST_HEAD(mci_list);
+
+static const u32 MCLK = (155000 / 12);
+static const u32 MAX_DEMOD_LDPC_BITRATE = (155000 / 6);
+static const u32 MAX_LDPC_BITRATE = (72000);
+
+struct mci_base {
+   struct list_head mci_list;
+   void*key;
+   struct ddb_link *link;
+   struct completioncompletion;
+
+   struct device   *dev;
+   struct mutex tuner_lock; /* concurrent tuner access lock */
+   u8   adr;
+   struct mutex mci_lock; /* concurrent MCI access lock */
+   int  count;
+
+   u8   tuner_use_count[4];
+   u8   assigned_demod[8];
+   u32  used_ldpc_bitrate[8];
+   u8   demod_in_use[8];
+   u32  iq_mode;
+};
+
+struct mci {
+   struct mci_base *base;
+   struct dvb_frontend  fe;
+   int  nr;
+   int  demod;
+   int  tuner;
+   int  first_time_lock;
+   int  started;
+   struct mci_resultsignal_info;
+
+   u32  bb_mode;
+};
+
+static int mci_reset(struct mci *state)
+{
+   struct ddb_link *link = state->base->link;
+   u32 status = 0;
+   u32 timeout = 40;
+
+   ddblwritel(link, MCI_CONTROL_RESET, MCI_CONTROL);
+   ddblwritel(link, 0, MCI_CONTROL + 4); /* 1= no internal init */
+   msleep(300);
+   ddblwritel(link, 0, MCI_CONTROL);
+
+   while (1) {
+   status = ddblreadl(link, MCI_CONTROL);
+   if ((status & MCI_CONTROL_READY) == MCI_CONTROL_READY)
+   break;
+   if (--timeout == 0)
+   break;
+   msleep(50);
+   }
+   if ((status & MCI_CONTROL_READY) == 0)
+   return -1;
+   if (link->ids.device == 0x0009)
+   ddblwritel(link, SX8_TSCONFIG_MODE_NORMAL, SX8_TSCONFIG);
+   return 0;
+}
+
+static int